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>
5405fcd31cSMichael Grzeschik #include <linux/errqueue.h>
551da177e4SLinus Torvalds
568890624aSMichael Grzeschik #include <linux/leds.h>
578890624aSMichael Grzeschik
5826c6d281SJoe Perches #include "arcdevice.h"
598e0f295eSJoe Perches #include "com9026.h"
6026c6d281SJoe Perches
611da177e4SLinus Torvalds /* "do nothing" functions for protocol drivers */
621da177e4SLinus Torvalds static void null_rx(struct net_device *dev, int bufnum,
631da177e4SLinus Torvalds struct archdr *pkthdr, int length);
641da177e4SLinus Torvalds static int null_build_header(struct sk_buff *skb, struct net_device *dev,
651da177e4SLinus Torvalds unsigned short type, uint8_t daddr);
661da177e4SLinus Torvalds static int null_prepare_tx(struct net_device *dev, struct archdr *pkt,
671da177e4SLinus Torvalds int length, int bufnum);
681da177e4SLinus Torvalds
69f03aa2d8SAdrian Bunk static void arcnet_rx(struct net_device *dev, int bufnum);
701da177e4SLinus Torvalds
71f2f0a16bSJoe Perches /* one ArcProto per possible proto ID. None of the elements of
721da177e4SLinus Torvalds * arc_proto_map are allowed to be NULL; they will get set to
731da177e4SLinus Torvalds * arc_proto_default instead. It also must not be NULL; if you would like
741da177e4SLinus Torvalds * to set it to NULL, set it to &arc_proto_null instead.
751da177e4SLinus Torvalds */
76811eafc0SJoe Perches struct ArcProto *arc_proto_map[256];
77811eafc0SJoe Perches EXPORT_SYMBOL(arc_proto_map);
78811eafc0SJoe Perches
79811eafc0SJoe Perches struct ArcProto *arc_proto_default;
80811eafc0SJoe Perches EXPORT_SYMBOL(arc_proto_default);
81811eafc0SJoe Perches
82811eafc0SJoe Perches struct ArcProto *arc_bcast_proto;
83811eafc0SJoe Perches EXPORT_SYMBOL(arc_bcast_proto);
84811eafc0SJoe Perches
85811eafc0SJoe Perches struct ArcProto *arc_raw_proto;
86811eafc0SJoe Perches EXPORT_SYMBOL(arc_raw_proto);
871da177e4SLinus Torvalds
887f5e760cSJoe Perches static struct ArcProto arc_proto_null = {
891da177e4SLinus Torvalds .suffix = '?',
901da177e4SLinus Torvalds .mtu = XMTU,
911da177e4SLinus Torvalds .is_ip = 0,
921da177e4SLinus Torvalds .rx = null_rx,
931da177e4SLinus Torvalds .build_header = null_build_header,
941da177e4SLinus Torvalds .prepare_tx = null_prepare_tx,
951da177e4SLinus Torvalds .continue_tx = NULL,
961da177e4SLinus Torvalds .ack_tx = NULL
971da177e4SLinus Torvalds };
981da177e4SLinus Torvalds
991da177e4SLinus Torvalds /* Exported function prototypes */
1001da177e4SLinus Torvalds int arcnet_debug = ARCNET_DEBUG;
1011da177e4SLinus Torvalds EXPORT_SYMBOL(arcnet_debug);
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 go_tx(struct net_device *dev);
1081da177e4SLinus Torvalds
1091da177e4SLinus Torvalds static int debug = ARCNET_DEBUG;
1101da177e4SLinus Torvalds module_param(debug, int, 0);
1111da177e4SLinus Torvalds MODULE_LICENSE("GPL");
1121da177e4SLinus Torvalds
arcnet_init(void)1131da177e4SLinus Torvalds static int __init arcnet_init(void)
1141da177e4SLinus Torvalds {
1151da177e4SLinus Torvalds int count;
1161da177e4SLinus Torvalds
1171da177e4SLinus Torvalds arcnet_debug = debug;
1181da177e4SLinus Torvalds
11905a24b23SJoe Perches pr_info("arcnet loaded\n");
1201da177e4SLinus Torvalds
1211da177e4SLinus Torvalds /* initialize the protocol map */
1221da177e4SLinus Torvalds arc_raw_proto = arc_proto_default = arc_bcast_proto = &arc_proto_null;
1231da177e4SLinus Torvalds for (count = 0; count < 256; count++)
1241da177e4SLinus Torvalds arc_proto_map[count] = arc_proto_default;
1251da177e4SLinus Torvalds
12672aeea48SJoe Perches if (BUGLVL(D_DURING))
1275b5e0928SAlexey Dobriyan pr_info("struct sizes: %zd %zd %zd %zd %zd\n",
12805a24b23SJoe Perches sizeof(struct arc_hardware),
12905a24b23SJoe Perches sizeof(struct arc_rfc1201),
13005a24b23SJoe Perches sizeof(struct arc_rfc1051),
13105a24b23SJoe Perches sizeof(struct arc_eth_encap),
1321da177e4SLinus Torvalds sizeof(struct archdr));
1331da177e4SLinus Torvalds
1341da177e4SLinus Torvalds return 0;
1351da177e4SLinus Torvalds }
1361da177e4SLinus Torvalds
arcnet_exit(void)1371da177e4SLinus Torvalds static void __exit arcnet_exit(void)
1381da177e4SLinus Torvalds {
1391da177e4SLinus Torvalds }
1401da177e4SLinus Torvalds
1411da177e4SLinus Torvalds module_init(arcnet_init);
1421da177e4SLinus Torvalds module_exit(arcnet_exit);
1431da177e4SLinus Torvalds
144f2f0a16bSJoe Perches /* Dump the contents of an sk_buff */
1451da177e4SLinus Torvalds #if ARCNET_DEBUG_MAX & D_SKB
arcnet_dump_skb(struct net_device * dev,struct sk_buff * skb,char * desc)1461da177e4SLinus Torvalds void arcnet_dump_skb(struct net_device *dev,
1471da177e4SLinus Torvalds struct sk_buff *skb, char *desc)
1481da177e4SLinus Torvalds {
149ad361c98SJoe Perches char hdr[32];
1501da177e4SLinus Torvalds
151ad361c98SJoe Perches /* dump the packet */
152ad361c98SJoe Perches snprintf(hdr, sizeof(hdr), "%6s:%s skb->data:", dev->name, desc);
153ad361c98SJoe Perches print_hex_dump(KERN_DEBUG, hdr, DUMP_PREFIX_OFFSET,
154ad361c98SJoe Perches 16, 1, skb->data, skb->len, true);
1551da177e4SLinus Torvalds }
1561da177e4SLinus Torvalds EXPORT_SYMBOL(arcnet_dump_skb);
1571da177e4SLinus Torvalds #endif
1581da177e4SLinus Torvalds
159f2f0a16bSJoe Perches /* Dump the contents of an ARCnet buffer */
1601da177e4SLinus Torvalds #if (ARCNET_DEBUG_MAX & (D_RX | D_TX))
arcnet_dump_packet(struct net_device * dev,int bufnum,char * desc,int take_arcnet_lock)161f03aa2d8SAdrian Bunk static void arcnet_dump_packet(struct net_device *dev, int bufnum,
162f03aa2d8SAdrian Bunk char *desc, int take_arcnet_lock)
1631da177e4SLinus Torvalds {
164454d7c9bSWang Chen struct arcnet_local *lp = netdev_priv(dev);
1651da177e4SLinus Torvalds int i, length;
1661da177e4SLinus Torvalds unsigned long flags = 0;
1671da177e4SLinus Torvalds static uint8_t buf[512];
168ad361c98SJoe Perches char hdr[32];
1691da177e4SLinus Torvalds
1701da177e4SLinus Torvalds /* hw.copy_from_card expects IRQ context so take the IRQ lock
171f2f0a16bSJoe Perches * to keep it single threaded
172f2f0a16bSJoe Perches */
1731da177e4SLinus Torvalds if (take_arcnet_lock)
1741da177e4SLinus Torvalds spin_lock_irqsave(&lp->lock, flags);
1751da177e4SLinus Torvalds
1761da177e4SLinus Torvalds lp->hw.copy_from_card(dev, bufnum, 0, buf, 512);
1771da177e4SLinus Torvalds if (take_arcnet_lock)
1781da177e4SLinus Torvalds spin_unlock_irqrestore(&lp->lock, flags);
1791da177e4SLinus Torvalds
1801da177e4SLinus Torvalds /* if the offset[0] byte is nonzero, this is a 256-byte packet */
1811da177e4SLinus Torvalds length = (buf[2] ? 256 : 512);
1821da177e4SLinus Torvalds
183ad361c98SJoe Perches /* dump the packet */
184ad361c98SJoe Perches snprintf(hdr, sizeof(hdr), "%6s:%s packet dump:", dev->name, desc);
185ad361c98SJoe Perches print_hex_dump(KERN_DEBUG, hdr, DUMP_PREFIX_OFFSET,
186ad361c98SJoe Perches 16, 1, buf, length, true);
1871da177e4SLinus Torvalds }
1881da177e4SLinus Torvalds
189f03aa2d8SAdrian Bunk #else
190f03aa2d8SAdrian Bunk
191f03aa2d8SAdrian Bunk #define arcnet_dump_packet(dev, bufnum, desc, take_arcnet_lock) do { } while (0)
192f03aa2d8SAdrian Bunk
1931da177e4SLinus Torvalds #endif
1941da177e4SLinus Torvalds
1958890624aSMichael Grzeschik /* Trigger a LED event in response to a ARCNET device event */
arcnet_led_event(struct net_device * dev,enum arcnet_led_event event)1968890624aSMichael Grzeschik void arcnet_led_event(struct net_device *dev, enum arcnet_led_event event)
1978890624aSMichael Grzeschik {
1988890624aSMichael Grzeschik struct arcnet_local *lp = netdev_priv(dev);
1998890624aSMichael Grzeschik
2008890624aSMichael Grzeschik switch (event) {
2018890624aSMichael Grzeschik case ARCNET_LED_EVENT_RECON:
202e298d8a3SHans de Goede led_trigger_blink_oneshot(lp->recon_led_trig, 350, 350, 0);
2038890624aSMichael Grzeschik break;
2048890624aSMichael Grzeschik case ARCNET_LED_EVENT_OPEN:
2058890624aSMichael Grzeschik led_trigger_event(lp->tx_led_trig, LED_OFF);
2068890624aSMichael Grzeschik led_trigger_event(lp->recon_led_trig, LED_OFF);
2078890624aSMichael Grzeschik break;
2088890624aSMichael Grzeschik case ARCNET_LED_EVENT_STOP:
2098890624aSMichael Grzeschik led_trigger_event(lp->tx_led_trig, LED_OFF);
2108890624aSMichael Grzeschik led_trigger_event(lp->recon_led_trig, LED_OFF);
2118890624aSMichael Grzeschik break;
2128890624aSMichael Grzeschik case ARCNET_LED_EVENT_TX:
213e298d8a3SHans de Goede led_trigger_blink_oneshot(lp->tx_led_trig, 50, 50, 0);
2148890624aSMichael Grzeschik break;
2158890624aSMichael Grzeschik }
2168890624aSMichael Grzeschik }
2178890624aSMichael Grzeschik EXPORT_SYMBOL_GPL(arcnet_led_event);
2188890624aSMichael Grzeschik
arcnet_led_release(struct device * gendev,void * res)2198890624aSMichael Grzeschik static void arcnet_led_release(struct device *gendev, void *res)
2208890624aSMichael Grzeschik {
2218890624aSMichael Grzeschik struct arcnet_local *lp = netdev_priv(to_net_dev(gendev));
2228890624aSMichael Grzeschik
2238890624aSMichael Grzeschik led_trigger_unregister_simple(lp->tx_led_trig);
2248890624aSMichael Grzeschik led_trigger_unregister_simple(lp->recon_led_trig);
2258890624aSMichael Grzeschik }
2268890624aSMichael Grzeschik
2278890624aSMichael Grzeschik /* Register ARCNET LED triggers for a arcnet device
2288890624aSMichael Grzeschik *
2298890624aSMichael Grzeschik * This is normally called from a driver's probe function
2308890624aSMichael Grzeschik */
devm_arcnet_led_init(struct net_device * netdev,int index,int subid)2318890624aSMichael Grzeschik void devm_arcnet_led_init(struct net_device *netdev, int index, int subid)
2328890624aSMichael Grzeschik {
2338890624aSMichael Grzeschik struct arcnet_local *lp = netdev_priv(netdev);
2348890624aSMichael Grzeschik void *res;
2358890624aSMichael Grzeschik
2368890624aSMichael Grzeschik res = devres_alloc(arcnet_led_release, 0, GFP_KERNEL);
2378890624aSMichael Grzeschik if (!res) {
2388890624aSMichael Grzeschik netdev_err(netdev, "cannot register LED triggers\n");
2398890624aSMichael Grzeschik return;
2408890624aSMichael Grzeschik }
2418890624aSMichael Grzeschik
2428890624aSMichael Grzeschik snprintf(lp->tx_led_trig_name, sizeof(lp->tx_led_trig_name),
2438890624aSMichael Grzeschik "arc%d-%d-tx", index, subid);
2448890624aSMichael Grzeschik snprintf(lp->recon_led_trig_name, sizeof(lp->recon_led_trig_name),
2458890624aSMichael Grzeschik "arc%d-%d-recon", index, subid);
2468890624aSMichael Grzeschik
2478890624aSMichael Grzeschik led_trigger_register_simple(lp->tx_led_trig_name,
2488890624aSMichael Grzeschik &lp->tx_led_trig);
2498890624aSMichael Grzeschik led_trigger_register_simple(lp->recon_led_trig_name,
2508890624aSMichael Grzeschik &lp->recon_led_trig);
2518890624aSMichael Grzeschik
2528890624aSMichael Grzeschik devres_add(&netdev->dev, res);
2538890624aSMichael Grzeschik }
2548890624aSMichael Grzeschik EXPORT_SYMBOL_GPL(devm_arcnet_led_init);
2558890624aSMichael Grzeschik
256f2f0a16bSJoe Perches /* Unregister a protocol driver from the arc_proto_map. Protocol drivers
2571da177e4SLinus Torvalds * are responsible for registering themselves, but the unregister routine
2581da177e4SLinus Torvalds * is pretty generic so we'll do it here.
2591da177e4SLinus Torvalds */
arcnet_unregister_proto(struct ArcProto * proto)2601da177e4SLinus Torvalds void arcnet_unregister_proto(struct ArcProto *proto)
2611da177e4SLinus Torvalds {
2621da177e4SLinus Torvalds int count;
2631da177e4SLinus Torvalds
2641da177e4SLinus Torvalds if (arc_proto_default == proto)
2651da177e4SLinus Torvalds arc_proto_default = &arc_proto_null;
2661da177e4SLinus Torvalds if (arc_bcast_proto == proto)
2671da177e4SLinus Torvalds arc_bcast_proto = arc_proto_default;
2681da177e4SLinus Torvalds if (arc_raw_proto == proto)
2691da177e4SLinus Torvalds arc_raw_proto = arc_proto_default;
2701da177e4SLinus Torvalds
2711da177e4SLinus Torvalds for (count = 0; count < 256; count++) {
2721da177e4SLinus Torvalds if (arc_proto_map[count] == proto)
2731da177e4SLinus Torvalds arc_proto_map[count] = arc_proto_default;
2741da177e4SLinus Torvalds }
2751da177e4SLinus Torvalds }
276811eafc0SJoe Perches EXPORT_SYMBOL(arcnet_unregister_proto);
2771da177e4SLinus Torvalds
278f2f0a16bSJoe Perches /* Add a buffer to the queue. Only the interrupt handler is allowed to do
2791da177e4SLinus Torvalds * this, unless interrupts are disabled.
2801da177e4SLinus Torvalds *
2811da177e4SLinus Torvalds * Note: we don't check for a full queue, since there aren't enough buffers
2821da177e4SLinus Torvalds * to more than fill it.
2831da177e4SLinus Torvalds */
release_arcbuf(struct net_device * dev,int bufnum)2841da177e4SLinus Torvalds static void release_arcbuf(struct net_device *dev, int bufnum)
2851da177e4SLinus Torvalds {
286454d7c9bSWang Chen struct arcnet_local *lp = netdev_priv(dev);
2871da177e4SLinus Torvalds int i;
2881da177e4SLinus Torvalds
2891da177e4SLinus Torvalds lp->buf_queue[lp->first_free_buf++] = bufnum;
2901da177e4SLinus Torvalds lp->first_free_buf %= 5;
2911da177e4SLinus Torvalds
29272aeea48SJoe Perches if (BUGLVL(D_DURING)) {
293a34c0932SJoe Perches arc_printk(D_DURING, dev, "release_arcbuf: freed #%d; buffer queue is now: ",
2941da177e4SLinus Torvalds bufnum);
2951da177e4SLinus Torvalds for (i = lp->next_buf; i != lp->first_free_buf; i = (i + 1) % 5)
296a34c0932SJoe Perches arc_cont(D_DURING, "#%d ", lp->buf_queue[i]);
297a34c0932SJoe Perches arc_cont(D_DURING, "\n");
2981da177e4SLinus Torvalds }
2991da177e4SLinus Torvalds }
3001da177e4SLinus Torvalds
301f2f0a16bSJoe Perches /* Get a buffer from the queue.
302f2f0a16bSJoe Perches * If this returns -1, there are no buffers available.
3031da177e4SLinus Torvalds */
get_arcbuf(struct net_device * dev)3041da177e4SLinus Torvalds static int get_arcbuf(struct net_device *dev)
3051da177e4SLinus Torvalds {
306454d7c9bSWang Chen struct arcnet_local *lp = netdev_priv(dev);
3071da177e4SLinus Torvalds int buf = -1, i;
3081da177e4SLinus Torvalds
3091da177e4SLinus Torvalds if (!atomic_dec_and_test(&lp->buf_lock)) {
3101da177e4SLinus Torvalds /* already in this function */
311a34c0932SJoe Perches arc_printk(D_NORMAL, dev, "get_arcbuf: overlap (%d)!\n",
3121da177e4SLinus Torvalds lp->buf_lock.counter);
3137f5e760cSJoe Perches } else { /* we can continue */
3141da177e4SLinus Torvalds if (lp->next_buf >= 5)
3151da177e4SLinus Torvalds lp->next_buf -= 5;
3161da177e4SLinus Torvalds
3177f5e760cSJoe Perches if (lp->next_buf == lp->first_free_buf) {
318a34c0932SJoe Perches arc_printk(D_NORMAL, dev, "get_arcbuf: BUG: no buffers are available??\n");
3197f5e760cSJoe Perches } else {
3201da177e4SLinus Torvalds buf = lp->buf_queue[lp->next_buf++];
3211da177e4SLinus Torvalds lp->next_buf %= 5;
3221da177e4SLinus Torvalds }
3231da177e4SLinus Torvalds }
3241da177e4SLinus Torvalds
32572aeea48SJoe Perches if (BUGLVL(D_DURING)) {
326a34c0932SJoe Perches arc_printk(D_DURING, dev, "get_arcbuf: got #%d; buffer queue is now: ",
327a34c0932SJoe Perches buf);
3281da177e4SLinus Torvalds for (i = lp->next_buf; i != lp->first_free_buf; i = (i + 1) % 5)
329a34c0932SJoe Perches arc_cont(D_DURING, "#%d ", lp->buf_queue[i]);
330a34c0932SJoe Perches arc_cont(D_DURING, "\n");
3311da177e4SLinus Torvalds }
3321da177e4SLinus Torvalds
3331da177e4SLinus Torvalds atomic_inc(&lp->buf_lock);
3341da177e4SLinus Torvalds return buf;
3351da177e4SLinus Torvalds }
3361da177e4SLinus Torvalds
choose_mtu(void)3371da177e4SLinus Torvalds static int choose_mtu(void)
3381da177e4SLinus Torvalds {
3391da177e4SLinus Torvalds int count, mtu = 65535;
3401da177e4SLinus Torvalds
3411da177e4SLinus Torvalds /* choose the smallest MTU of all available encaps */
3421da177e4SLinus Torvalds for (count = 0; count < 256; count++) {
3438e95a202SJoe Perches if (arc_proto_map[count] != &arc_proto_null &&
3448e95a202SJoe Perches arc_proto_map[count]->mtu < mtu) {
3451da177e4SLinus Torvalds mtu = arc_proto_map[count]->mtu;
3461da177e4SLinus Torvalds }
3471da177e4SLinus Torvalds }
3481da177e4SLinus Torvalds
3491da177e4SLinus Torvalds return mtu == 65535 ? XMTU : mtu;
3501da177e4SLinus Torvalds }
3511da177e4SLinus Torvalds
3523b04dddeSStephen Hemminger static const struct header_ops arcnet_header_ops = {
3533b04dddeSStephen Hemminger .create = arcnet_header,
3543b04dddeSStephen Hemminger };
3553b04dddeSStephen Hemminger
356bca5b893SStephen Hemminger static const struct net_device_ops arcnet_netdev_ops = {
357bca5b893SStephen Hemminger .ndo_open = arcnet_open,
358bca5b893SStephen Hemminger .ndo_stop = arcnet_close,
359bca5b893SStephen Hemminger .ndo_start_xmit = arcnet_send_packet,
360bca5b893SStephen Hemminger .ndo_tx_timeout = arcnet_timeout,
361bca5b893SStephen Hemminger };
3621da177e4SLinus Torvalds
3631da177e4SLinus Torvalds /* Setup a struct device for ARCnet. */
arcdev_setup(struct net_device * dev)3641da177e4SLinus Torvalds static void arcdev_setup(struct net_device *dev)
3651da177e4SLinus Torvalds {
3661da177e4SLinus Torvalds dev->type = ARPHRD_ARCNET;
367bca5b893SStephen Hemminger dev->netdev_ops = &arcnet_netdev_ops;
3683b04dddeSStephen Hemminger dev->header_ops = &arcnet_header_ops;
369980137a2SMichael Grzeschik dev->hard_header_len = sizeof(struct arc_hardware);
3701da177e4SLinus Torvalds dev->mtu = choose_mtu();
3711da177e4SLinus Torvalds
3721da177e4SLinus Torvalds dev->addr_len = ARCNET_ALEN;
3731da177e4SLinus Torvalds dev->tx_queue_len = 100;
3741da177e4SLinus Torvalds dev->broadcast[0] = 0x00; /* for us, broadcasts are address 0 */
3751da177e4SLinus Torvalds dev->watchdog_timeo = TX_TIMEOUT;
3761da177e4SLinus Torvalds
3771da177e4SLinus Torvalds /* New-style flags. */
3781da177e4SLinus Torvalds dev->flags = IFF_BROADCAST;
3791da177e4SLinus Torvalds }
3801da177e4SLinus Torvalds
arcnet_timer(struct timer_list * t)381c58320deSKees Cook static void arcnet_timer(struct timer_list *t)
38259fbcbc6SMichael Grzeschik {
383c58320deSKees Cook struct arcnet_local *lp = from_timer(lp, t, timer);
384c58320deSKees Cook struct net_device *dev = lp->dev;
38559fbcbc6SMichael Grzeschik
38601365633SAhmed S. Darwish spin_lock_irq(&lp->lock);
38701365633SAhmed S. Darwish
38801365633SAhmed S. Darwish if (!lp->reset_in_progress && !netif_carrier_ok(dev)) {
38959fbcbc6SMichael Grzeschik netif_carrier_on(dev);
39059fbcbc6SMichael Grzeschik netdev_info(dev, "link up\n");
39159fbcbc6SMichael Grzeschik }
39201365633SAhmed S. Darwish
39301365633SAhmed S. Darwish spin_unlock_irq(&lp->lock);
39401365633SAhmed S. Darwish }
39501365633SAhmed S. Darwish
reset_device_work(struct work_struct * work)39601365633SAhmed S. Darwish static void reset_device_work(struct work_struct *work)
39701365633SAhmed S. Darwish {
39801365633SAhmed S. Darwish struct arcnet_local *lp;
39901365633SAhmed S. Darwish struct net_device *dev;
40001365633SAhmed S. Darwish
40101365633SAhmed S. Darwish lp = container_of(work, struct arcnet_local, reset_work);
40201365633SAhmed S. Darwish dev = lp->dev;
40301365633SAhmed S. Darwish
40401365633SAhmed S. Darwish /* Do not bring the network interface back up if an ifdown
40501365633SAhmed S. Darwish * was already done.
40601365633SAhmed S. Darwish */
40701365633SAhmed S. Darwish if (!netif_running(dev) || !lp->reset_in_progress)
40801365633SAhmed S. Darwish return;
40901365633SAhmed S. Darwish
41001365633SAhmed S. Darwish rtnl_lock();
41101365633SAhmed S. Darwish
41201365633SAhmed S. Darwish /* Do another check, in case of an ifdown that was triggered in
41301365633SAhmed S. Darwish * the small race window between the exit condition above and
41401365633SAhmed S. Darwish * acquiring RTNL.
41501365633SAhmed S. Darwish */
41601365633SAhmed S. Darwish if (!netif_running(dev) || !lp->reset_in_progress)
41701365633SAhmed S. Darwish goto out;
41801365633SAhmed S. Darwish
41901365633SAhmed S. Darwish dev_close(dev);
42001365633SAhmed S. Darwish dev_open(dev, NULL);
42101365633SAhmed S. Darwish
42201365633SAhmed S. Darwish out:
42301365633SAhmed S. Darwish rtnl_unlock();
42459fbcbc6SMichael Grzeschik }
42559fbcbc6SMichael Grzeschik
arcnet_reply_tasklet(struct tasklet_struct * t)4265bb98b2cSEmil Renner Berthing static void arcnet_reply_tasklet(struct tasklet_struct *t)
42705fcd31cSMichael Grzeschik {
4285bb98b2cSEmil Renner Berthing struct arcnet_local *lp = from_tasklet(lp, t, reply_tasklet);
42905fcd31cSMichael Grzeschik
43005fcd31cSMichael Grzeschik struct sk_buff *ackskb, *skb;
43105fcd31cSMichael Grzeschik struct sock_exterr_skb *serr;
43205fcd31cSMichael Grzeschik struct sock *sk;
43305fcd31cSMichael Grzeschik int ret;
43405fcd31cSMichael Grzeschik
43505fcd31cSMichael Grzeschik local_irq_disable();
43605fcd31cSMichael Grzeschik skb = lp->outgoing.skb;
43705fcd31cSMichael Grzeschik if (!skb || !skb->sk) {
43805fcd31cSMichael Grzeschik local_irq_enable();
43905fcd31cSMichael Grzeschik return;
44005fcd31cSMichael Grzeschik }
44105fcd31cSMichael Grzeschik
44205fcd31cSMichael Grzeschik sock_hold(skb->sk);
44305fcd31cSMichael Grzeschik sk = skb->sk;
44405fcd31cSMichael Grzeschik ackskb = skb_clone_sk(skb);
44505fcd31cSMichael Grzeschik sock_put(skb->sk);
44605fcd31cSMichael Grzeschik
44705fcd31cSMichael Grzeschik if (!ackskb) {
44805fcd31cSMichael Grzeschik local_irq_enable();
44905fcd31cSMichael Grzeschik return;
45005fcd31cSMichael Grzeschik }
45105fcd31cSMichael Grzeschik
45205fcd31cSMichael Grzeschik serr = SKB_EXT_ERR(ackskb);
45305fcd31cSMichael Grzeschik memset(serr, 0, sizeof(*serr));
45405fcd31cSMichael Grzeschik serr->ee.ee_errno = ENOMSG;
45505fcd31cSMichael Grzeschik serr->ee.ee_origin = SO_EE_ORIGIN_TXSTATUS;
45605fcd31cSMichael Grzeschik serr->ee.ee_data = skb_shinfo(skb)->tskey;
45705fcd31cSMichael Grzeschik serr->ee.ee_info = lp->reply_status;
45805fcd31cSMichael Grzeschik
45905fcd31cSMichael Grzeschik /* finally erasing outgoing skb */
46005fcd31cSMichael Grzeschik dev_kfree_skb(lp->outgoing.skb);
46105fcd31cSMichael Grzeschik lp->outgoing.skb = NULL;
46205fcd31cSMichael Grzeschik
46305fcd31cSMichael Grzeschik ackskb->dev = lp->dev;
46405fcd31cSMichael Grzeschik
46505fcd31cSMichael Grzeschik ret = sock_queue_err_skb(sk, ackskb);
46605fcd31cSMichael Grzeschik if (ret)
467*786c96e9SJinjie Ruan dev_kfree_skb_irq(ackskb);
46805fcd31cSMichael Grzeschik
46905fcd31cSMichael Grzeschik local_irq_enable();
47005fcd31cSMichael Grzeschik };
47105fcd31cSMichael Grzeschik
alloc_arcdev(const char * name)472bca5b893SStephen Hemminger struct net_device *alloc_arcdev(const char *name)
4731da177e4SLinus Torvalds {
4741da177e4SLinus Torvalds struct net_device *dev;
4751da177e4SLinus Torvalds
4761da177e4SLinus Torvalds dev = alloc_netdev(sizeof(struct arcnet_local),
477c835a677STom Gundersen name && *name ? name : "arc%d", NET_NAME_UNKNOWN,
478c835a677STom Gundersen arcdev_setup);
4791da177e4SLinus Torvalds if (dev) {
480454d7c9bSWang Chen struct arcnet_local *lp = netdev_priv(dev);
48101a1d5acSJoe Perches
48205fcd31cSMichael Grzeschik lp->dev = dev;
4831da177e4SLinus Torvalds spin_lock_init(&lp->lock);
484c58320deSKees Cook timer_setup(&lp->timer, arcnet_timer, 0);
48501365633SAhmed S. Darwish INIT_WORK(&lp->reset_work, reset_device_work);
4861da177e4SLinus Torvalds }
4871da177e4SLinus Torvalds
4881da177e4SLinus Torvalds return dev;
4891da177e4SLinus Torvalds }
490811eafc0SJoe Perches EXPORT_SYMBOL(alloc_arcdev);
4911da177e4SLinus Torvalds
free_arcdev(struct net_device * dev)49201365633SAhmed S. Darwish void free_arcdev(struct net_device *dev)
49301365633SAhmed S. Darwish {
49401365633SAhmed S. Darwish struct arcnet_local *lp = netdev_priv(dev);
49501365633SAhmed S. Darwish
49601365633SAhmed S. Darwish /* Do not cancel this at ->ndo_close(), as the workqueue itself
49701365633SAhmed S. Darwish * indirectly calls the ifdown path through dev_close().
49801365633SAhmed S. Darwish */
49901365633SAhmed S. Darwish cancel_work_sync(&lp->reset_work);
50001365633SAhmed S. Darwish free_netdev(dev);
50101365633SAhmed S. Darwish }
50201365633SAhmed S. Darwish EXPORT_SYMBOL(free_arcdev);
50301365633SAhmed S. Darwish
504f2f0a16bSJoe Perches /* Open/initialize the board. This is called sometime after booting when
5051da177e4SLinus Torvalds * the 'ifconfig' program is run.
5061da177e4SLinus Torvalds *
5071da177e4SLinus Torvalds * This routine should set everything up anew at each open, even registers
5081da177e4SLinus Torvalds * that "should" only need to be set once at boot, so that there is
5091da177e4SLinus Torvalds * non-reboot way to recover if something goes wrong.
5101da177e4SLinus Torvalds */
arcnet_open(struct net_device * dev)511bca5b893SStephen Hemminger int arcnet_open(struct net_device *dev)
5121da177e4SLinus Torvalds {
513454d7c9bSWang Chen struct arcnet_local *lp = netdev_priv(dev);
5141da177e4SLinus Torvalds int count, newmtu, error;
5151da177e4SLinus Torvalds
516a34c0932SJoe Perches arc_printk(D_INIT, dev, "opened.");
5171da177e4SLinus Torvalds
5181da177e4SLinus Torvalds if (!try_module_get(lp->hw.owner))
5191da177e4SLinus Torvalds return -ENODEV;
5201da177e4SLinus Torvalds
52172aeea48SJoe Perches if (BUGLVL(D_PROTO)) {
522a34c0932SJoe Perches arc_printk(D_PROTO, dev, "protocol map (default is '%c'): ",
5231da177e4SLinus Torvalds arc_proto_default->suffix);
5241da177e4SLinus Torvalds for (count = 0; count < 256; count++)
525a34c0932SJoe Perches arc_cont(D_PROTO, "%c", arc_proto_map[count]->suffix);
526a34c0932SJoe Perches arc_cont(D_PROTO, "\n");
5271da177e4SLinus Torvalds }
5281da177e4SLinus Torvalds
5295bb98b2cSEmil Renner Berthing tasklet_setup(&lp->reply_tasklet, arcnet_reply_tasklet);
53005fcd31cSMichael Grzeschik
531a34c0932SJoe Perches arc_printk(D_INIT, dev, "arcnet_open: resetting card.\n");
5321da177e4SLinus Torvalds
5331da177e4SLinus Torvalds /* try to put the card in a defined state - if it fails the first
5341da177e4SLinus Torvalds * time, actually reset it.
5351da177e4SLinus Torvalds */
5361da177e4SLinus Torvalds error = -ENODEV;
537e15b0362SJoe Perches if (lp->hw.reset(dev, 0) && lp->hw.reset(dev, 1))
5381da177e4SLinus Torvalds goto out_module_put;
5391da177e4SLinus Torvalds
5401da177e4SLinus Torvalds newmtu = choose_mtu();
5411da177e4SLinus Torvalds if (newmtu < dev->mtu)
5421da177e4SLinus Torvalds dev->mtu = newmtu;
5431da177e4SLinus Torvalds
544a34c0932SJoe Perches arc_printk(D_INIT, dev, "arcnet_open: mtu: %d.\n", dev->mtu);
5451da177e4SLinus Torvalds
5461da177e4SLinus Torvalds /* autodetect the encapsulation for each host. */
5471da177e4SLinus Torvalds memset(lp->default_proto, 0, sizeof(lp->default_proto));
5481da177e4SLinus Torvalds
5491da177e4SLinus Torvalds /* the broadcast address is special - use the 'bcast' protocol */
5501da177e4SLinus Torvalds for (count = 0; count < 256; count++) {
5511da177e4SLinus Torvalds if (arc_proto_map[count] == arc_bcast_proto) {
5521da177e4SLinus Torvalds lp->default_proto[0] = count;
5531da177e4SLinus Torvalds break;
5541da177e4SLinus Torvalds }
5551da177e4SLinus Torvalds }
5561da177e4SLinus Torvalds
5571da177e4SLinus Torvalds /* initialize buffers */
5581da177e4SLinus Torvalds atomic_set(&lp->buf_lock, 1);
5591da177e4SLinus Torvalds
5601da177e4SLinus Torvalds lp->next_buf = lp->first_free_buf = 0;
5611da177e4SLinus Torvalds release_arcbuf(dev, 0);
5621da177e4SLinus Torvalds release_arcbuf(dev, 1);
5631da177e4SLinus Torvalds release_arcbuf(dev, 2);
5641da177e4SLinus Torvalds release_arcbuf(dev, 3);
5651da177e4SLinus Torvalds lp->cur_tx = lp->next_tx = -1;
5661da177e4SLinus Torvalds lp->cur_rx = -1;
5671da177e4SLinus Torvalds
5681da177e4SLinus Torvalds lp->rfc1201.sequence = 1;
5691da177e4SLinus Torvalds
5701da177e4SLinus Torvalds /* bring up the hardware driver */
5711da177e4SLinus Torvalds if (lp->hw.open)
5721da177e4SLinus Torvalds lp->hw.open(dev);
5731da177e4SLinus Torvalds
5741da177e4SLinus Torvalds if (dev->dev_addr[0] == 0)
575a34c0932SJoe Perches arc_printk(D_NORMAL, dev, "WARNING! Station address 00 is reserved for broadcasts!\n");
5761da177e4SLinus Torvalds else if (dev->dev_addr[0] == 255)
577a34c0932SJoe Perches arc_printk(D_NORMAL, dev, "WARNING! Station address FF may confuse DOS networking programs!\n");
5781da177e4SLinus Torvalds
579a34c0932SJoe Perches arc_printk(D_DEBUG, dev, "%s: %d: %s\n", __FILE__, __LINE__, __func__);
580e15b0362SJoe Perches if (lp->hw.status(dev) & RESETflag) {
581a34c0932SJoe Perches arc_printk(D_DEBUG, dev, "%s: %d: %s\n",
582a34c0932SJoe Perches __FILE__, __LINE__, __func__);
583e15b0362SJoe Perches lp->hw.command(dev, CFLAGScmd | RESETclear);
5841da177e4SLinus Torvalds }
5851da177e4SLinus Torvalds
586a34c0932SJoe Perches arc_printk(D_DEBUG, dev, "%s: %d: %s\n", __FILE__, __LINE__, __func__);
5871da177e4SLinus Torvalds /* make sure we're ready to receive IRQ's. */
588e15b0362SJoe Perches lp->hw.intmask(dev, 0);
5891da177e4SLinus Torvalds udelay(1); /* give it time to set the mask before
5901da177e4SLinus Torvalds * we reset it again. (may not even be
5911da177e4SLinus Torvalds * necessary)
5921da177e4SLinus Torvalds */
593a34c0932SJoe Perches arc_printk(D_DEBUG, dev, "%s: %d: %s\n", __FILE__, __LINE__, __func__);
5941da177e4SLinus Torvalds lp->intmask = NORXflag | RECONflag;
595e15b0362SJoe Perches lp->hw.intmask(dev, lp->intmask);
596a34c0932SJoe Perches arc_printk(D_DEBUG, dev, "%s: %d: %s\n", __FILE__, __LINE__, __func__);
5971da177e4SLinus Torvalds
59859fbcbc6SMichael Grzeschik netif_carrier_off(dev);
5991da177e4SLinus Torvalds netif_start_queue(dev);
60059fbcbc6SMichael Grzeschik mod_timer(&lp->timer, jiffies + msecs_to_jiffies(1000));
6011da177e4SLinus Torvalds
6028890624aSMichael Grzeschik arcnet_led_event(dev, ARCNET_LED_EVENT_OPEN);
6031da177e4SLinus Torvalds return 0;
6041da177e4SLinus Torvalds
6051da177e4SLinus Torvalds out_module_put:
6061da177e4SLinus Torvalds module_put(lp->hw.owner);
6071da177e4SLinus Torvalds return error;
6081da177e4SLinus Torvalds }
609811eafc0SJoe Perches EXPORT_SYMBOL(arcnet_open);
6101da177e4SLinus Torvalds
6111da177e4SLinus Torvalds /* The inverse routine to arcnet_open - shuts down the card. */
arcnet_close(struct net_device * dev)612bca5b893SStephen Hemminger int arcnet_close(struct net_device *dev)
6131da177e4SLinus Torvalds {
614454d7c9bSWang Chen struct arcnet_local *lp = netdev_priv(dev);
6151da177e4SLinus Torvalds
6168890624aSMichael Grzeschik arcnet_led_event(dev, ARCNET_LED_EVENT_STOP);
61759fbcbc6SMichael Grzeschik del_timer_sync(&lp->timer);
61859fbcbc6SMichael Grzeschik
6191da177e4SLinus Torvalds netif_stop_queue(dev);
62059fbcbc6SMichael Grzeschik netif_carrier_off(dev);
6211da177e4SLinus Torvalds
62205fcd31cSMichael Grzeschik tasklet_kill(&lp->reply_tasklet);
62305fcd31cSMichael Grzeschik
6241da177e4SLinus Torvalds /* flush TX and disable RX */
625e15b0362SJoe Perches lp->hw.intmask(dev, 0);
626e15b0362SJoe Perches lp->hw.command(dev, NOTXcmd); /* stop transmit */
627e15b0362SJoe Perches lp->hw.command(dev, NORXcmd); /* disable receive */
6281da177e4SLinus Torvalds mdelay(1);
6291da177e4SLinus Torvalds
6301da177e4SLinus Torvalds /* shut down the card */
6311da177e4SLinus Torvalds lp->hw.close(dev);
63201365633SAhmed S. Darwish
63301365633SAhmed S. Darwish /* reset counters */
63401365633SAhmed S. Darwish lp->reset_in_progress = 0;
63501365633SAhmed S. Darwish
6361da177e4SLinus Torvalds module_put(lp->hw.owner);
6371da177e4SLinus Torvalds return 0;
6381da177e4SLinus Torvalds }
639811eafc0SJoe Perches EXPORT_SYMBOL(arcnet_close);
6401da177e4SLinus Torvalds
arcnet_header(struct sk_buff * skb,struct net_device * dev,unsigned short type,const void * daddr,const void * saddr,unsigned len)6411da177e4SLinus Torvalds static int arcnet_header(struct sk_buff *skb, struct net_device *dev,
6423b04dddeSStephen Hemminger unsigned short type, const void *daddr,
6433b04dddeSStephen Hemminger const void *saddr, unsigned len)
6441da177e4SLinus Torvalds {
6453b04dddeSStephen Hemminger const struct arcnet_local *lp = netdev_priv(dev);
6461da177e4SLinus Torvalds uint8_t _daddr, proto_num;
6471da177e4SLinus Torvalds struct ArcProto *proto;
6481da177e4SLinus Torvalds
649a34c0932SJoe Perches arc_printk(D_DURING, dev,
6501da177e4SLinus Torvalds "create header from %d to %d; protocol %d (%Xh); size %u.\n",
6511da177e4SLinus Torvalds saddr ? *(uint8_t *)saddr : -1,
6521da177e4SLinus Torvalds daddr ? *(uint8_t *)daddr : -1,
6531da177e4SLinus Torvalds type, type, len);
6541da177e4SLinus Torvalds
6551da177e4SLinus Torvalds if (skb->len != 0 && len != skb->len)
656a34c0932SJoe Perches arc_printk(D_NORMAL, dev, "arcnet_header: Yikes! skb->len(%d) != len(%d)!\n",
6571da177e4SLinus Torvalds skb->len, len);
6581da177e4SLinus Torvalds
6591da177e4SLinus Torvalds /* Type is host order - ? */
6601da177e4SLinus Torvalds if (type == ETH_P_ARCNET) {
6611da177e4SLinus Torvalds proto = arc_raw_proto;
662a34c0932SJoe Perches arc_printk(D_DEBUG, dev, "arc_raw_proto used. proto='%c'\n",
663a34c0932SJoe Perches proto->suffix);
6641da177e4SLinus Torvalds _daddr = daddr ? *(uint8_t *)daddr : 0;
6657f5e760cSJoe Perches } else if (!daddr) {
666f2f0a16bSJoe Perches /* if the dest addr isn't provided, we can't choose an
667f2f0a16bSJoe Perches * encapsulation! Store the packet type (eg. ETH_P_IP)
668f2f0a16bSJoe Perches * for now, and we'll push on a real header when we do
669f2f0a16bSJoe Perches * rebuild_header.
6701da177e4SLinus Torvalds */
6711da177e4SLinus Torvalds *(uint16_t *)skb_push(skb, 2) = type;
672f2f0a16bSJoe Perches /* XXX: Why not use skb->mac_len? */
673b0e380b1SArnaldo Carvalho de Melo if (skb->network_header - skb->mac_header != 2)
674a34c0932SJoe Perches arc_printk(D_NORMAL, dev, "arcnet_header: Yikes! diff (%u) is not 2!\n",
675a34c0932SJoe Perches skb->network_header - skb->mac_header);
6761da177e4SLinus Torvalds return -2; /* return error -- can't transmit yet! */
6777f5e760cSJoe Perches } else {
6781da177e4SLinus Torvalds /* otherwise, we can just add the header as usual. */
6791da177e4SLinus Torvalds _daddr = *(uint8_t *)daddr;
6801da177e4SLinus Torvalds proto_num = lp->default_proto[_daddr];
6811da177e4SLinus Torvalds proto = arc_proto_map[proto_num];
682a34c0932SJoe Perches arc_printk(D_DURING, dev, "building header for %02Xh using protocol '%c'\n",
6831da177e4SLinus Torvalds proto_num, proto->suffix);
6841da177e4SLinus Torvalds if (proto == &arc_proto_null && arc_bcast_proto != proto) {
685a34c0932SJoe Perches arc_printk(D_DURING, dev, "actually, let's use '%c' instead.\n",
6861da177e4SLinus Torvalds arc_bcast_proto->suffix);
6871da177e4SLinus Torvalds proto = arc_bcast_proto;
6881da177e4SLinus Torvalds }
6891da177e4SLinus Torvalds }
6901da177e4SLinus Torvalds return proto->build_header(skb, dev, type, _daddr);
6911da177e4SLinus Torvalds }
6921da177e4SLinus Torvalds
6931da177e4SLinus Torvalds /* Called by the kernel in order to transmit a packet. */
arcnet_send_packet(struct sk_buff * skb,struct net_device * dev)69461357325SStephen Hemminger netdev_tx_t arcnet_send_packet(struct sk_buff *skb,
69561357325SStephen Hemminger struct net_device *dev)
6961da177e4SLinus Torvalds {
697454d7c9bSWang Chen struct arcnet_local *lp = netdev_priv(dev);
6981da177e4SLinus Torvalds struct archdr *pkt;
6991da177e4SLinus Torvalds struct arc_rfc1201 *soft;
7001da177e4SLinus Torvalds struct ArcProto *proto;
7011da177e4SLinus Torvalds int txbuf;
7021da177e4SLinus Torvalds unsigned long flags;
703b82de0e2SMichael Grzeschik int retval;
7041da177e4SLinus Torvalds
705a34c0932SJoe Perches arc_printk(D_DURING, dev,
7061da177e4SLinus Torvalds "transmit requested (status=%Xh, txbufs=%d/%d, len=%d, protocol %x)\n",
707e15b0362SJoe Perches lp->hw.status(dev), lp->cur_tx, lp->next_tx, skb->len, skb->protocol);
7081da177e4SLinus Torvalds
7091da177e4SLinus Torvalds pkt = (struct archdr *)skb->data;
7101da177e4SLinus Torvalds soft = &pkt->soft.rfc1201;
7111da177e4SLinus Torvalds proto = arc_proto_map[soft->proto];
7121da177e4SLinus Torvalds
713a34c0932SJoe Perches arc_printk(D_SKB_SIZE, dev, "skb: transmitting %d bytes to %02X\n",
7141da177e4SLinus Torvalds skb->len, pkt->hard.dest);
71572aeea48SJoe Perches if (BUGLVL(D_SKB))
71672aeea48SJoe Perches arcnet_dump_skb(dev, skb, "tx");
7171da177e4SLinus Torvalds
7181da177e4SLinus Torvalds /* fits in one packet? */
7191da177e4SLinus Torvalds if (skb->len - ARC_HDR_SIZE > XMTU && !proto->continue_tx) {
720a34c0932SJoe Perches arc_printk(D_NORMAL, dev, "fixme: packet too large: compensating badly!\n");
7211da177e4SLinus Torvalds dev_kfree_skb(skb);
722c6bb15a0SPieter Dejaeghere return NETDEV_TX_OK; /* don't try again */
7231da177e4SLinus Torvalds }
7241da177e4SLinus Torvalds
7251da177e4SLinus Torvalds /* We're busy transmitting a packet... */
7261da177e4SLinus Torvalds netif_stop_queue(dev);
7271da177e4SLinus Torvalds
7281da177e4SLinus Torvalds spin_lock_irqsave(&lp->lock, flags);
729e15b0362SJoe Perches lp->hw.intmask(dev, 0);
730c6bb15a0SPieter Dejaeghere if (lp->next_tx == -1)
7311da177e4SLinus Torvalds txbuf = get_arcbuf(dev);
7327f5e760cSJoe Perches else
733c6bb15a0SPieter Dejaeghere txbuf = -1;
7347f5e760cSJoe Perches
7351da177e4SLinus Torvalds if (txbuf != -1) {
73605fcd31cSMichael Grzeschik lp->outgoing.skb = skb;
7371da177e4SLinus Torvalds if (proto->prepare_tx(dev, pkt, skb->len, txbuf) &&
7381da177e4SLinus Torvalds !proto->ack_tx) {
7391da177e4SLinus Torvalds /* done right away and we don't want to acknowledge
740f2f0a16bSJoe Perches * the package later - forget about it now
741f2f0a16bSJoe Perches */
7425803c512SStephen Hemminger dev->stats.tx_bytes += skb->len;
7431da177e4SLinus Torvalds } else {
7441da177e4SLinus Torvalds /* do it the 'split' way */
7451da177e4SLinus Torvalds lp->outgoing.proto = proto;
7461da177e4SLinus Torvalds lp->outgoing.skb = skb;
7471da177e4SLinus Torvalds lp->outgoing.pkt = pkt;
7481da177e4SLinus Torvalds
7491da177e4SLinus Torvalds if (proto->continue_tx &&
7501da177e4SLinus Torvalds proto->continue_tx(dev, txbuf)) {
751a34c0932SJoe Perches arc_printk(D_NORMAL, dev,
7523b4e5551SJoe Perches "bug! continue_tx finished the first time! (proto='%c')\n",
7533b4e5551SJoe Perches proto->suffix);
7541da177e4SLinus Torvalds }
7551da177e4SLinus Torvalds }
756c6bb15a0SPieter Dejaeghere retval = NETDEV_TX_OK;
7571da177e4SLinus Torvalds lp->next_tx = txbuf;
7581da177e4SLinus Torvalds } else {
759c6bb15a0SPieter Dejaeghere retval = NETDEV_TX_BUSY;
7601da177e4SLinus Torvalds }
7611da177e4SLinus Torvalds
762a34c0932SJoe Perches arc_printk(D_DEBUG, dev, "%s: %d: %s, status: %x\n",
763e15b0362SJoe Perches __FILE__, __LINE__, __func__, lp->hw.status(dev));
7641da177e4SLinus Torvalds /* make sure we didn't ignore a TX IRQ while we were in here */
765e15b0362SJoe Perches lp->hw.intmask(dev, 0);
7661da177e4SLinus Torvalds
767a34c0932SJoe Perches arc_printk(D_DEBUG, dev, "%s: %d: %s\n", __FILE__, __LINE__, __func__);
7681da177e4SLinus Torvalds lp->intmask |= TXFREEflag | EXCNAKflag;
769e15b0362SJoe Perches lp->hw.intmask(dev, lp->intmask);
770a34c0932SJoe Perches arc_printk(D_DEBUG, dev, "%s: %d: %s, status: %x\n",
771e15b0362SJoe Perches __FILE__, __LINE__, __func__, lp->hw.status(dev));
7721da177e4SLinus Torvalds
7738890624aSMichael Grzeschik arcnet_led_event(dev, ARCNET_LED_EVENT_TX);
7748890624aSMichael Grzeschik
7751da177e4SLinus Torvalds spin_unlock_irqrestore(&lp->lock, flags);
776c6bb15a0SPieter Dejaeghere return retval; /* no need to try again */
7771da177e4SLinus Torvalds }
778811eafc0SJoe Perches EXPORT_SYMBOL(arcnet_send_packet);
7791da177e4SLinus Torvalds
780f2f0a16bSJoe Perches /* Actually start transmitting a packet that was loaded into a buffer
7811da177e4SLinus Torvalds * by prepare_tx. This should _only_ be called by the interrupt handler.
7821da177e4SLinus Torvalds */
go_tx(struct net_device * dev)7831da177e4SLinus Torvalds static int go_tx(struct net_device *dev)
7841da177e4SLinus Torvalds {
785454d7c9bSWang Chen struct arcnet_local *lp = netdev_priv(dev);
7861da177e4SLinus Torvalds
787a34c0932SJoe Perches arc_printk(D_DURING, dev, "go_tx: status=%Xh, intmask=%Xh, next_tx=%d, cur_tx=%d\n",
788e15b0362SJoe Perches lp->hw.status(dev), lp->intmask, lp->next_tx, lp->cur_tx);
7891da177e4SLinus Torvalds
7901da177e4SLinus Torvalds if (lp->cur_tx != -1 || lp->next_tx == -1)
7911da177e4SLinus Torvalds return 0;
7921da177e4SLinus Torvalds
79372aeea48SJoe Perches if (BUGLVL(D_TX))
79472aeea48SJoe Perches arcnet_dump_packet(dev, lp->next_tx, "go_tx", 0);
7951da177e4SLinus Torvalds
7961da177e4SLinus Torvalds lp->cur_tx = lp->next_tx;
7971da177e4SLinus Torvalds lp->next_tx = -1;
7981da177e4SLinus Torvalds
7991da177e4SLinus Torvalds /* start sending */
800e15b0362SJoe Perches lp->hw.command(dev, TXcmd | (lp->cur_tx << 3));
8011da177e4SLinus Torvalds
8025803c512SStephen Hemminger dev->stats.tx_packets++;
8031da177e4SLinus Torvalds lp->lasttrans_dest = lp->lastload_dest;
8041da177e4SLinus Torvalds lp->lastload_dest = 0;
8051da177e4SLinus Torvalds lp->excnak_pending = 0;
8061da177e4SLinus Torvalds lp->intmask |= TXFREEflag | EXCNAKflag;
8071da177e4SLinus Torvalds
8081da177e4SLinus Torvalds return 1;
8091da177e4SLinus Torvalds }
8101da177e4SLinus Torvalds
8111da177e4SLinus Torvalds /* Called by the kernel when transmit times out */
arcnet_timeout(struct net_device * dev,unsigned int txqueue)8120290bd29SMichael S. Tsirkin void arcnet_timeout(struct net_device *dev, unsigned int txqueue)
8131da177e4SLinus Torvalds {
8141da177e4SLinus Torvalds unsigned long flags;
815454d7c9bSWang Chen struct arcnet_local *lp = netdev_priv(dev);
816e15b0362SJoe Perches int status = lp->hw.status(dev);
8171da177e4SLinus Torvalds char *msg;
8181da177e4SLinus Torvalds
8191da177e4SLinus Torvalds spin_lock_irqsave(&lp->lock, flags);
8201da177e4SLinus Torvalds if (status & TXFREEflag) { /* transmit _DID_ finish */
8211da177e4SLinus Torvalds msg = " - missed IRQ?";
8221da177e4SLinus Torvalds } else {
8231da177e4SLinus Torvalds msg = "";
8245803c512SStephen Hemminger dev->stats.tx_aborted_errors++;
8251da177e4SLinus Torvalds lp->timed_out = 1;
826e15b0362SJoe Perches lp->hw.command(dev, NOTXcmd | (lp->cur_tx << 3));
8271da177e4SLinus Torvalds }
8285803c512SStephen Hemminger dev->stats.tx_errors++;
8291da177e4SLinus Torvalds
8301da177e4SLinus Torvalds /* make sure we didn't miss a TX or a EXC NAK IRQ */
831e15b0362SJoe Perches lp->hw.intmask(dev, 0);
8321da177e4SLinus Torvalds lp->intmask |= TXFREEflag | EXCNAKflag;
833e15b0362SJoe Perches lp->hw.intmask(dev, lp->intmask);
8341da177e4SLinus Torvalds
8351da177e4SLinus Torvalds spin_unlock_irqrestore(&lp->lock, flags);
8361da177e4SLinus Torvalds
837ff5688aeSMarcelo Feitoza Parisi if (time_after(jiffies, lp->last_timeout + 10 * HZ)) {
838a34c0932SJoe Perches arc_printk(D_EXTRA, dev, "tx timed out%s (status=%Xh, intmask=%Xh, dest=%02Xh)\n",
8391da177e4SLinus Torvalds msg, status, lp->intmask, lp->lasttrans_dest);
8401da177e4SLinus Torvalds lp->last_timeout = jiffies;
8411da177e4SLinus Torvalds }
8421da177e4SLinus Torvalds
8431da177e4SLinus Torvalds if (lp->cur_tx == -1)
8441da177e4SLinus Torvalds netif_wake_queue(dev);
8451da177e4SLinus Torvalds }
846811eafc0SJoe Perches EXPORT_SYMBOL(arcnet_timeout);
8471da177e4SLinus Torvalds
848f2f0a16bSJoe Perches /* The typical workload of the driver: Handle the network interface
8491da177e4SLinus Torvalds * interrupts. Establish which device needs attention, and call the correct
8501da177e4SLinus Torvalds * chipset interrupt handler.
8511da177e4SLinus Torvalds */
arcnet_interrupt(int irq,void * dev_id)8527d12e780SDavid Howells irqreturn_t arcnet_interrupt(int irq, void *dev_id)
8531da177e4SLinus Torvalds {
8541da177e4SLinus Torvalds struct net_device *dev = dev_id;
8551da177e4SLinus Torvalds struct arcnet_local *lp;
8561da177e4SLinus Torvalds int recbuf, status, diagstatus, didsomething, boguscount;
8575b858403SMichael Grzeschik unsigned long flags;
8581da177e4SLinus Torvalds int retval = IRQ_NONE;
8591da177e4SLinus Torvalds
860a34c0932SJoe Perches arc_printk(D_DURING, dev, "\n");
8611da177e4SLinus Torvalds
862a34c0932SJoe Perches arc_printk(D_DURING, dev, "in arcnet_interrupt\n");
8631da177e4SLinus Torvalds
864454d7c9bSWang Chen lp = netdev_priv(dev);
8655d9428deSEric Sesterhenn BUG_ON(!lp);
8661da177e4SLinus Torvalds
8675b858403SMichael Grzeschik spin_lock_irqsave(&lp->lock, flags);
8681da177e4SLinus Torvalds
86901365633SAhmed S. Darwish if (lp->reset_in_progress)
87001365633SAhmed S. Darwish goto out;
87101365633SAhmed S. Darwish
872f2f0a16bSJoe Perches /* RESET flag was enabled - if device is not running, we must
873f2f0a16bSJoe Perches * clear it right away (but nothing else).
8741da177e4SLinus Torvalds */
8751da177e4SLinus Torvalds if (!netif_running(dev)) {
876e15b0362SJoe Perches if (lp->hw.status(dev) & RESETflag)
877e15b0362SJoe Perches lp->hw.command(dev, CFLAGScmd | RESETclear);
878e15b0362SJoe Perches lp->hw.intmask(dev, 0);
8795b858403SMichael Grzeschik spin_unlock_irqrestore(&lp->lock, flags);
880226ee675SMichael Grzeschik return retval;
8811da177e4SLinus Torvalds }
8821da177e4SLinus Torvalds
883a34c0932SJoe Perches arc_printk(D_DURING, dev, "in arcnet_inthandler (status=%Xh, intmask=%Xh)\n",
884e15b0362SJoe Perches lp->hw.status(dev), lp->intmask);
8851da177e4SLinus Torvalds
8861da177e4SLinus Torvalds boguscount = 5;
8871da177e4SLinus Torvalds do {
888e15b0362SJoe Perches status = lp->hw.status(dev);
8891da177e4SLinus Torvalds diagstatus = (status >> 8) & 0xFF;
8901da177e4SLinus Torvalds
891a34c0932SJoe Perches arc_printk(D_DEBUG, dev, "%s: %d: %s: status=%x\n",
892b39d66a8SHarvey Harrison __FILE__, __LINE__, __func__, status);
8931da177e4SLinus Torvalds didsomething = 0;
8941da177e4SLinus Torvalds
895f2f0a16bSJoe Perches /* RESET flag was enabled - card is resetting and if RX is
8961da177e4SLinus Torvalds * disabled, it's NOT because we just got a packet.
8971da177e4SLinus Torvalds *
898f2f0a16bSJoe Perches * The card is in an undefined state.
899f2f0a16bSJoe Perches * Clear it out and start over.
9001da177e4SLinus Torvalds */
9011da177e4SLinus Torvalds if (status & RESETflag) {
902a34c0932SJoe Perches arc_printk(D_NORMAL, dev, "spurious reset (status=%Xh)\n",
903a34c0932SJoe Perches status);
90401365633SAhmed S. Darwish
90501365633SAhmed S. Darwish lp->reset_in_progress = 1;
90601365633SAhmed S. Darwish netif_stop_queue(dev);
90701365633SAhmed S. Darwish netif_carrier_off(dev);
90801365633SAhmed S. Darwish schedule_work(&lp->reset_work);
9091da177e4SLinus Torvalds
9101da177e4SLinus Torvalds /* get out of the interrupt handler! */
91101365633SAhmed S. Darwish goto out;
9121da177e4SLinus Torvalds }
913f2f0a16bSJoe Perches /* RX is inhibited - we must have received something.
914f2f0a16bSJoe Perches * Prepare to receive into the next buffer.
9151da177e4SLinus Torvalds *
916f2f0a16bSJoe Perches * We don't actually copy the received packet from the card
917f2f0a16bSJoe Perches * until after the transmit handler runs (and possibly
918f2f0a16bSJoe Perches * launches the next tx); this should improve latency slightly
919f2f0a16bSJoe Perches * if we get both types of interrupts at once.
9201da177e4SLinus Torvalds */
9211da177e4SLinus Torvalds recbuf = -1;
9221da177e4SLinus Torvalds if (status & lp->intmask & NORXflag) {
9231da177e4SLinus Torvalds recbuf = lp->cur_rx;
924a34c0932SJoe Perches arc_printk(D_DURING, dev, "Buffer #%d: receive irq (status=%Xh)\n",
9251da177e4SLinus Torvalds recbuf, status);
9261da177e4SLinus Torvalds
9271da177e4SLinus Torvalds lp->cur_rx = get_arcbuf(dev);
9281da177e4SLinus Torvalds if (lp->cur_rx != -1) {
929a34c0932SJoe Perches arc_printk(D_DURING, dev, "enabling receive to buffer #%d\n",
9301da177e4SLinus Torvalds lp->cur_rx);
931e15b0362SJoe Perches lp->hw.command(dev, RXcmd | (lp->cur_rx << 3) | RXbcasts);
9321da177e4SLinus Torvalds }
9331da177e4SLinus Torvalds didsomething++;
9341da177e4SLinus Torvalds }
9351da177e4SLinus Torvalds
9361da177e4SLinus Torvalds if ((diagstatus & EXCNAKflag)) {
937a34c0932SJoe Perches arc_printk(D_DURING, dev, "EXCNAK IRQ (diagstat=%Xh)\n",
9381da177e4SLinus Torvalds diagstatus);
9391da177e4SLinus Torvalds
940e15b0362SJoe Perches lp->hw.command(dev, NOTXcmd); /* disable transmit */
9411da177e4SLinus Torvalds lp->excnak_pending = 1;
9421da177e4SLinus Torvalds
943e15b0362SJoe Perches lp->hw.command(dev, EXCNAKclear);
9441da177e4SLinus Torvalds lp->intmask &= ~(EXCNAKflag);
9451da177e4SLinus Torvalds didsomething++;
9461da177e4SLinus Torvalds }
9471da177e4SLinus Torvalds
9481da177e4SLinus Torvalds /* a transmit finished, and we're interested in it. */
9491da177e4SLinus Torvalds if ((status & lp->intmask & TXFREEflag) || lp->timed_out) {
95005fcd31cSMichael Grzeschik int ackstatus;
9511da177e4SLinus Torvalds lp->intmask &= ~(TXFREEflag | EXCNAKflag);
9521da177e4SLinus Torvalds
95305fcd31cSMichael Grzeschik if (status & TXACKflag)
95405fcd31cSMichael Grzeschik ackstatus = 2;
95505fcd31cSMichael Grzeschik else if (lp->excnak_pending)
95605fcd31cSMichael Grzeschik ackstatus = 1;
95705fcd31cSMichael Grzeschik else
95805fcd31cSMichael Grzeschik ackstatus = 0;
95905fcd31cSMichael Grzeschik
960d6d7d3edSJoe Perches arc_printk(D_DURING, dev, "TX IRQ (stat=%Xh)\n",
961d6d7d3edSJoe Perches status);
9621da177e4SLinus Torvalds
9631da177e4SLinus Torvalds if (lp->cur_tx != -1 && !lp->timed_out) {
9641da177e4SLinus Torvalds if (!(status & TXACKflag)) {
9651da177e4SLinus Torvalds if (lp->lasttrans_dest != 0) {
966a34c0932SJoe Perches arc_printk(D_EXTRA, dev,
9673b4e5551SJoe Perches "transmit was not acknowledged! (status=%Xh, dest=%02Xh)\n",
968a34c0932SJoe Perches status,
969a34c0932SJoe Perches lp->lasttrans_dest);
9705803c512SStephen Hemminger dev->stats.tx_errors++;
9715803c512SStephen Hemminger dev->stats.tx_carrier_errors++;
9721da177e4SLinus Torvalds } else {
973a34c0932SJoe Perches arc_printk(D_DURING, dev,
9743b4e5551SJoe Perches "broadcast was not acknowledged; that's normal (status=%Xh, dest=%02Xh)\n",
975a34c0932SJoe Perches status,
976a34c0932SJoe Perches lp->lasttrans_dest);
9771da177e4SLinus Torvalds }
9781da177e4SLinus Torvalds }
9791da177e4SLinus Torvalds
9801da177e4SLinus Torvalds if (lp->outgoing.proto &&
9811da177e4SLinus Torvalds lp->outgoing.proto->ack_tx) {
9821da177e4SLinus Torvalds lp->outgoing.proto
9831da177e4SLinus Torvalds ->ack_tx(dev, ackstatus);
9841da177e4SLinus Torvalds }
98505fcd31cSMichael Grzeschik lp->reply_status = ackstatus;
98605fcd31cSMichael Grzeschik tasklet_hi_schedule(&lp->reply_tasklet);
9871da177e4SLinus Torvalds }
9881da177e4SLinus Torvalds if (lp->cur_tx != -1)
9891da177e4SLinus Torvalds release_arcbuf(dev, lp->cur_tx);
9901da177e4SLinus Torvalds
9911da177e4SLinus Torvalds lp->cur_tx = -1;
9921da177e4SLinus Torvalds lp->timed_out = 0;
9931da177e4SLinus Torvalds didsomething++;
9941da177e4SLinus Torvalds
9951da177e4SLinus Torvalds /* send another packet if there is one */
9961da177e4SLinus Torvalds go_tx(dev);
9971da177e4SLinus Torvalds
9981da177e4SLinus Torvalds /* continue a split packet, if any */
999d6d7d3edSJoe Perches if (lp->outgoing.proto &&
1000d6d7d3edSJoe Perches lp->outgoing.proto->continue_tx) {
10011da177e4SLinus Torvalds int txbuf = get_arcbuf(dev);
100201a1d5acSJoe Perches
10031da177e4SLinus Torvalds if (txbuf != -1) {
10041da177e4SLinus Torvalds if (lp->outgoing.proto->continue_tx(dev, txbuf)) {
10051da177e4SLinus Torvalds /* that was the last segment */
10065803c512SStephen Hemminger dev->stats.tx_bytes += lp->outgoing.skb->len;
10077f5e760cSJoe Perches if (!lp->outgoing.proto->ack_tx) {
10081da177e4SLinus Torvalds dev_kfree_skb_irq(lp->outgoing.skb);
10091da177e4SLinus Torvalds lp->outgoing.proto = NULL;
10101da177e4SLinus Torvalds }
10111da177e4SLinus Torvalds }
10121da177e4SLinus Torvalds lp->next_tx = txbuf;
10131da177e4SLinus Torvalds }
10141da177e4SLinus Torvalds }
10151da177e4SLinus Torvalds /* inform upper layers of idleness, if necessary */
10161da177e4SLinus Torvalds if (lp->cur_tx == -1)
10171da177e4SLinus Torvalds netif_wake_queue(dev);
10181da177e4SLinus Torvalds }
10191da177e4SLinus Torvalds /* now process the received packet, if any */
10201da177e4SLinus Torvalds if (recbuf != -1) {
102172aeea48SJoe Perches if (BUGLVL(D_RX))
102272aeea48SJoe Perches arcnet_dump_packet(dev, recbuf, "rx irq", 0);
10231da177e4SLinus Torvalds
10241da177e4SLinus Torvalds arcnet_rx(dev, recbuf);
10251da177e4SLinus Torvalds release_arcbuf(dev, recbuf);
10261da177e4SLinus Torvalds
10271da177e4SLinus Torvalds didsomething++;
10281da177e4SLinus Torvalds }
10291da177e4SLinus Torvalds if (status & lp->intmask & RECONflag) {
1030e15b0362SJoe Perches lp->hw.command(dev, CFLAGScmd | CONFIGclear);
10315803c512SStephen Hemminger dev->stats.tx_carrier_errors++;
10321da177e4SLinus Torvalds
1033a34c0932SJoe Perches arc_printk(D_RECON, dev, "Network reconfiguration detected (status=%Xh)\n",
10341da177e4SLinus Torvalds status);
103559fbcbc6SMichael Grzeschik if (netif_carrier_ok(dev)) {
103659fbcbc6SMichael Grzeschik netif_carrier_off(dev);
103759fbcbc6SMichael Grzeschik netdev_info(dev, "link down\n");
103859fbcbc6SMichael Grzeschik }
103959fbcbc6SMichael Grzeschik mod_timer(&lp->timer, jiffies + msecs_to_jiffies(1000));
104059fbcbc6SMichael Grzeschik
10418890624aSMichael Grzeschik arcnet_led_event(dev, ARCNET_LED_EVENT_RECON);
1042c6bb15a0SPieter Dejaeghere /* MYRECON bit is at bit 7 of diagstatus */
1043c6bb15a0SPieter Dejaeghere if (diagstatus & 0x80)
1044a34c0932SJoe Perches arc_printk(D_RECON, dev, "Put out that recon myself\n");
10451da177e4SLinus Torvalds
10461da177e4SLinus Torvalds /* is the RECON info empty or old? */
10471da177e4SLinus Torvalds if (!lp->first_recon || !lp->last_recon ||
10489307b570SS.Caglar Onur time_after(jiffies, lp->last_recon + HZ * 10)) {
10491da177e4SLinus Torvalds if (lp->network_down)
1050a34c0932SJoe Perches arc_printk(D_NORMAL, dev, "reconfiguration detected: cabling restored?\n");
10511da177e4SLinus Torvalds lp->first_recon = lp->last_recon = jiffies;
10521da177e4SLinus Torvalds lp->num_recons = lp->network_down = 0;
10531da177e4SLinus Torvalds
1054a34c0932SJoe Perches arc_printk(D_DURING, dev, "recon: clearing counters.\n");
10551da177e4SLinus Torvalds } else { /* add to current RECON counter */
10561da177e4SLinus Torvalds lp->last_recon = jiffies;
10571da177e4SLinus Torvalds lp->num_recons++;
10581da177e4SLinus Torvalds
1059a34c0932SJoe Perches arc_printk(D_DURING, dev, "recon: counter=%d, time=%lds, net=%d\n",
10601da177e4SLinus Torvalds lp->num_recons,
10611da177e4SLinus Torvalds (lp->last_recon - lp->first_recon) / HZ,
10621da177e4SLinus Torvalds lp->network_down);
10631da177e4SLinus Torvalds
10641da177e4SLinus Torvalds /* if network is marked up;
10651da177e4SLinus Torvalds * and first_recon and last_recon are 60+ apart;
10661da177e4SLinus Torvalds * and the average no. of recons counted is
10671da177e4SLinus Torvalds * > RECON_THRESHOLD/min;
10681da177e4SLinus Torvalds * then print a warning message.
10691da177e4SLinus Torvalds */
10708e95a202SJoe Perches if (!lp->network_down &&
10718e95a202SJoe Perches (lp->last_recon - lp->first_recon) <= HZ * 60 &&
10728e95a202SJoe Perches lp->num_recons >= RECON_THRESHOLD) {
10731da177e4SLinus Torvalds lp->network_down = 1;
1074a34c0932SJoe Perches arc_printk(D_NORMAL, dev, "many reconfigurations detected: cabling problem?\n");
10758e95a202SJoe Perches } else if (!lp->network_down &&
10768e95a202SJoe Perches lp->last_recon - lp->first_recon > HZ * 60) {
1077d6d7d3edSJoe Perches /* reset counters if we've gone for
1078d6d7d3edSJoe Perches * over a minute.
1079d6d7d3edSJoe Perches */
10801da177e4SLinus Torvalds lp->first_recon = lp->last_recon;
10811da177e4SLinus Torvalds lp->num_recons = 1;
10821da177e4SLinus Torvalds }
10831da177e4SLinus Torvalds }
10849307b570SS.Caglar Onur } else if (lp->network_down &&
10859307b570SS.Caglar Onur time_after(jiffies, lp->last_recon + HZ * 10)) {
10861da177e4SLinus Torvalds if (lp->network_down)
1087a34c0932SJoe Perches arc_printk(D_NORMAL, dev, "cabling restored?\n");
10881da177e4SLinus Torvalds lp->first_recon = lp->last_recon = 0;
10891da177e4SLinus Torvalds lp->num_recons = lp->network_down = 0;
10901da177e4SLinus Torvalds
1091a34c0932SJoe Perches arc_printk(D_DURING, dev, "not recon: clearing counters anyway.\n");
109259fbcbc6SMichael Grzeschik netif_carrier_on(dev);
10931da177e4SLinus Torvalds }
10941da177e4SLinus Torvalds
10957f5e760cSJoe Perches if (didsomething)
10961da177e4SLinus Torvalds retval |= IRQ_HANDLED;
10977f5e760cSJoe Perches } while (--boguscount && didsomething);
10981da177e4SLinus Torvalds
1099a34c0932SJoe Perches arc_printk(D_DURING, dev, "arcnet_interrupt complete (status=%Xh, count=%d)\n",
1100e15b0362SJoe Perches lp->hw.status(dev), boguscount);
1101a34c0932SJoe Perches arc_printk(D_DURING, dev, "\n");
11021da177e4SLinus Torvalds
1103e15b0362SJoe Perches lp->hw.intmask(dev, 0);
11041da177e4SLinus Torvalds udelay(1);
1105e15b0362SJoe Perches lp->hw.intmask(dev, lp->intmask);
11061da177e4SLinus Torvalds
110701365633SAhmed S. Darwish out:
11085b858403SMichael Grzeschik spin_unlock_irqrestore(&lp->lock, flags);
11091da177e4SLinus Torvalds return retval;
11101da177e4SLinus Torvalds }
1111811eafc0SJoe Perches EXPORT_SYMBOL(arcnet_interrupt);
11121da177e4SLinus Torvalds
1113f2f0a16bSJoe Perches /* This is a generic packet receiver that calls arcnet??_rx depending on the
11141da177e4SLinus Torvalds * protocol ID found.
11151da177e4SLinus Torvalds */
arcnet_rx(struct net_device * dev,int bufnum)1116f03aa2d8SAdrian Bunk static void arcnet_rx(struct net_device *dev, int bufnum)
11171da177e4SLinus Torvalds {
1118454d7c9bSWang Chen struct arcnet_local *lp = netdev_priv(dev);
111902a07046SUwe Kleine-König union {
11201da177e4SLinus Torvalds struct archdr pkt;
112102a07046SUwe Kleine-König char buf[512];
112202a07046SUwe Kleine-König } rxdata;
11231da177e4SLinus Torvalds struct arc_rfc1201 *soft;
11241da177e4SLinus Torvalds int length, ofs;
11251da177e4SLinus Torvalds
112602a07046SUwe Kleine-König soft = &rxdata.pkt.soft.rfc1201;
11271da177e4SLinus Torvalds
112802a07046SUwe Kleine-König lp->hw.copy_from_card(dev, bufnum, 0, &rxdata.pkt, ARC_HDR_SIZE);
112902a07046SUwe Kleine-König if (rxdata.pkt.hard.offset[0]) {
113002a07046SUwe Kleine-König ofs = rxdata.pkt.hard.offset[0];
11311da177e4SLinus Torvalds length = 256 - ofs;
11321da177e4SLinus Torvalds } else {
113302a07046SUwe Kleine-König ofs = rxdata.pkt.hard.offset[1];
11341da177e4SLinus Torvalds length = 512 - ofs;
11351da177e4SLinus Torvalds }
11361da177e4SLinus Torvalds
11371da177e4SLinus Torvalds /* get the full header, if possible */
113802a07046SUwe Kleine-König if (sizeof(rxdata.pkt.soft) <= length) {
113902a07046SUwe Kleine-König lp->hw.copy_from_card(dev, bufnum, ofs, soft, sizeof(rxdata.pkt.soft));
11407f5e760cSJoe Perches } else {
114102a07046SUwe Kleine-König memset(&rxdata.pkt.soft, 0, sizeof(rxdata.pkt.soft));
11421da177e4SLinus Torvalds lp->hw.copy_from_card(dev, bufnum, ofs, soft, length);
11431da177e4SLinus Torvalds }
11441da177e4SLinus Torvalds
1145a34c0932SJoe Perches arc_printk(D_DURING, dev, "Buffer #%d: received packet from %02Xh to %02Xh (%d+4 bytes)\n",
114602a07046SUwe Kleine-König bufnum, rxdata.pkt.hard.source, rxdata.pkt.hard.dest, length);
11471da177e4SLinus Torvalds
11485803c512SStephen Hemminger dev->stats.rx_packets++;
11495803c512SStephen Hemminger dev->stats.rx_bytes += length + ARC_HDR_SIZE;
11501da177e4SLinus Torvalds
11511da177e4SLinus Torvalds /* call the right receiver for the protocol */
11521da177e4SLinus Torvalds if (arc_proto_map[soft->proto]->is_ip) {
115372aeea48SJoe Perches if (BUGLVL(D_PROTO)) {
11541da177e4SLinus Torvalds struct ArcProto
115502a07046SUwe Kleine-König *oldp = arc_proto_map[lp->default_proto[rxdata.pkt.hard.source]],
11561da177e4SLinus Torvalds *newp = arc_proto_map[soft->proto];
11571da177e4SLinus Torvalds
11581da177e4SLinus Torvalds if (oldp != newp) {
1159a34c0932SJoe Perches arc_printk(D_PROTO, dev,
11603b4e5551SJoe Perches "got protocol %02Xh; encap for host %02Xh is now '%c' (was '%c')\n",
116102a07046SUwe Kleine-König soft->proto, rxdata.pkt.hard.source,
11621da177e4SLinus Torvalds newp->suffix, oldp->suffix);
11631da177e4SLinus Torvalds }
11641da177e4SLinus Torvalds }
11651da177e4SLinus Torvalds
11661da177e4SLinus Torvalds /* broadcasts will always be done with the last-used encap. */
11671da177e4SLinus Torvalds lp->default_proto[0] = soft->proto;
11681da177e4SLinus Torvalds
11691da177e4SLinus Torvalds /* in striking contrast, the following isn't a hack. */
117002a07046SUwe Kleine-König lp->default_proto[rxdata.pkt.hard.source] = soft->proto;
11711da177e4SLinus Torvalds }
11721da177e4SLinus Torvalds /* call the protocol-specific receiver. */
117302a07046SUwe Kleine-König arc_proto_map[soft->proto]->rx(dev, bufnum, &rxdata.pkt, length);
11741da177e4SLinus Torvalds }
11751da177e4SLinus Torvalds
null_rx(struct net_device * dev,int bufnum,struct archdr * pkthdr,int length)11761da177e4SLinus Torvalds static void null_rx(struct net_device *dev, int bufnum,
11771da177e4SLinus Torvalds struct archdr *pkthdr, int length)
11781da177e4SLinus Torvalds {
1179a34c0932SJoe Perches arc_printk(D_PROTO, dev,
11801da177e4SLinus Torvalds "rx: don't know how to deal with proto %02Xh from host %02Xh.\n",
11811da177e4SLinus Torvalds pkthdr->soft.rfc1201.proto, pkthdr->hard.source);
11821da177e4SLinus Torvalds }
11831da177e4SLinus Torvalds
null_build_header(struct sk_buff * skb,struct net_device * dev,unsigned short type,uint8_t daddr)11841da177e4SLinus Torvalds static int null_build_header(struct sk_buff *skb, struct net_device *dev,
11851da177e4SLinus Torvalds unsigned short type, uint8_t daddr)
11861da177e4SLinus Torvalds {
1187454d7c9bSWang Chen struct arcnet_local *lp = netdev_priv(dev);
11881da177e4SLinus Torvalds
1189a34c0932SJoe Perches arc_printk(D_PROTO, dev,
11901da177e4SLinus Torvalds "tx: can't build header for encap %02Xh; load a protocol driver.\n",
11911da177e4SLinus Torvalds lp->default_proto[daddr]);
11921da177e4SLinus Torvalds
11931da177e4SLinus Torvalds /* always fails */
11941da177e4SLinus Torvalds return 0;
11951da177e4SLinus Torvalds }
11961da177e4SLinus Torvalds
11971da177e4SLinus Torvalds /* the "do nothing" prepare_tx function warns that there's nothing to do. */
null_prepare_tx(struct net_device * dev,struct archdr * pkt,int length,int bufnum)11981da177e4SLinus Torvalds static int null_prepare_tx(struct net_device *dev, struct archdr *pkt,
11991da177e4SLinus Torvalds int length, int bufnum)
12001da177e4SLinus Torvalds {
1201454d7c9bSWang Chen struct arcnet_local *lp = netdev_priv(dev);
12021da177e4SLinus Torvalds struct arc_hardware newpkt;
12031da177e4SLinus Torvalds
1204a34c0932SJoe Perches arc_printk(D_PROTO, dev, "tx: no encap for this host; load a protocol driver.\n");
12051da177e4SLinus Torvalds
12061da177e4SLinus Torvalds /* send a packet to myself -- will never get received, of course */
12071da177e4SLinus Torvalds newpkt.source = newpkt.dest = dev->dev_addr[0];
12081da177e4SLinus Torvalds
12091da177e4SLinus Torvalds /* only one byte of actual data (and it's random) */
12101da177e4SLinus Torvalds newpkt.offset[0] = 0xFF;
12111da177e4SLinus Torvalds
12121da177e4SLinus Torvalds lp->hw.copy_to_card(dev, bufnum, 0, &newpkt, ARC_HDR_SIZE);
12131da177e4SLinus Torvalds
12141da177e4SLinus Torvalds return 1; /* done */
12151da177e4SLinus Torvalds }
1216