2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* Linux ARCnet driver - device-independent routines
|
2015-05-06 01:05:47 +08:00
|
|
|
*
|
2005-04-17 06:20:36 +08:00
|
|
|
* Written 1997 by David Woodhouse.
|
|
|
|
* Written 1994-1999 by Avery Pennarun.
|
|
|
|
* Written 1999-2000 by Martin Mares <mj@ucw.cz>.
|
|
|
|
* Derived from skeleton.c by Donald Becker.
|
|
|
|
*
|
|
|
|
* Special thanks to Contemporary Controls, Inc. (www.ccontrols.com)
|
|
|
|
* for sponsoring the further development of this driver.
|
|
|
|
*
|
|
|
|
* **********************
|
|
|
|
*
|
|
|
|
* The original copyright was as follows:
|
|
|
|
*
|
|
|
|
* skeleton.c Written 1993 by Donald Becker.
|
|
|
|
* Copyright 1993 United States Government as represented by the
|
|
|
|
* Director, National Security Agency. This software may only be used
|
|
|
|
* and distributed according to the terms of the GNU General Public License as
|
|
|
|
* modified by SRC, incorporated herein by reference.
|
|
|
|
*
|
|
|
|
* **********************
|
2015-05-06 01:05:47 +08:00
|
|
|
*
|
2005-04-17 06:20:36 +08:00
|
|
|
* The change log is now in a file called ChangeLog in this directory.
|
|
|
|
*
|
|
|
|
* Sources:
|
|
|
|
* - Crynwr arcnet.com/arcether.com packet drivers.
|
2015-05-06 01:05:47 +08:00
|
|
|
* - arcnet.c v0.00 dated 1/1/94 and apparently by
|
2005-04-17 06:20:36 +08:00
|
|
|
* Donald Becker - it didn't work :)
|
|
|
|
* - skeleton.c v0.05 dated 11/16/93 by Donald Becker
|
|
|
|
* (from Linux Kernel 1.1.45)
|
|
|
|
* - RFC's 1201 and 1051 - re: TCP/IP over ARCnet
|
|
|
|
* - The official ARCnet COM9026 data sheets (!) thanks to
|
|
|
|
* Ken Cornetet <kcornete@nyx10.cs.du.edu>
|
|
|
|
* - The official ARCnet COM20020 data sheets.
|
|
|
|
* - Information on some more obscure ARCnet controller chips, thanks
|
|
|
|
* to the nice people at SMSC.
|
|
|
|
* - net/inet/eth.c (from kernel 1.1.50) for header-building info.
|
|
|
|
* - Alternate Linux ARCnet source by V.Shergin <vsher@sao.stavropol.su>
|
|
|
|
* - Textual information and more alternate source from Joachim Koenig
|
|
|
|
* <jojo@repas.de>
|
|
|
|
*/
|
|
|
|
|
2015-05-06 01:05:56 +08:00
|
|
|
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/netdevice.h>
|
|
|
|
#include <linux/if_arp.h>
|
|
|
|
#include <net/arp.h>
|
|
|
|
#include <linux/init.h>
|
2006-01-10 10:37:15 +08:00
|
|
|
#include <linux/jiffies.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2014-09-18 06:12:50 +08:00
|
|
|
#include <linux/leds.h>
|
|
|
|
|
2015-05-06 01:06:03 +08:00
|
|
|
#include "arcdevice.h"
|
2015-05-06 01:06:13 +08:00
|
|
|
#include "com9026.h"
|
2015-05-06 01:06:03 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* "do nothing" functions for protocol drivers */
|
|
|
|
static void null_rx(struct net_device *dev, int bufnum,
|
|
|
|
struct archdr *pkthdr, int length);
|
|
|
|
static int null_build_header(struct sk_buff *skb, struct net_device *dev,
|
|
|
|
unsigned short type, uint8_t daddr);
|
|
|
|
static int null_prepare_tx(struct net_device *dev, struct archdr *pkt,
|
|
|
|
int length, int bufnum);
|
|
|
|
|
2006-01-14 10:10:22 +08:00
|
|
|
static void arcnet_rx(struct net_device *dev, int bufnum);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2015-05-06 01:05:52 +08:00
|
|
|
/* one ArcProto per possible proto ID. None of the elements of
|
2005-04-17 06:20:36 +08:00
|
|
|
* arc_proto_map are allowed to be NULL; they will get set to
|
|
|
|
* arc_proto_default instead. It also must not be NULL; if you would like
|
|
|
|
* to set it to NULL, set it to &arc_proto_null instead.
|
|
|
|
*/
|
2015-05-06 01:05:57 +08:00
|
|
|
struct ArcProto *arc_proto_map[256];
|
|
|
|
EXPORT_SYMBOL(arc_proto_map);
|
|
|
|
|
|
|
|
struct ArcProto *arc_proto_default;
|
|
|
|
EXPORT_SYMBOL(arc_proto_default);
|
|
|
|
|
|
|
|
struct ArcProto *arc_bcast_proto;
|
|
|
|
EXPORT_SYMBOL(arc_bcast_proto);
|
|
|
|
|
|
|
|
struct ArcProto *arc_raw_proto;
|
|
|
|
EXPORT_SYMBOL(arc_raw_proto);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2015-05-06 01:05:49 +08:00
|
|
|
static struct ArcProto arc_proto_null = {
|
2005-04-17 06:20:36 +08:00
|
|
|
.suffix = '?',
|
|
|
|
.mtu = XMTU,
|
|
|
|
.is_ip = 0,
|
|
|
|
.rx = null_rx,
|
|
|
|
.build_header = null_build_header,
|
|
|
|
.prepare_tx = null_prepare_tx,
|
|
|
|
.continue_tx = NULL,
|
|
|
|
.ack_tx = NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Exported function prototypes */
|
|
|
|
int arcnet_debug = ARCNET_DEBUG;
|
|
|
|
EXPORT_SYMBOL(arcnet_debug);
|
|
|
|
|
|
|
|
/* Internal function prototypes */
|
|
|
|
static int arcnet_header(struct sk_buff *skb, struct net_device *dev,
|
2007-10-09 16:40:57 +08:00
|
|
|
unsigned short type, const void *daddr,
|
|
|
|
const void *saddr, unsigned len);
|
2005-04-17 06:20:36 +08:00
|
|
|
static int go_tx(struct net_device *dev);
|
|
|
|
|
|
|
|
static int debug = ARCNET_DEBUG;
|
|
|
|
module_param(debug, int, 0);
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
|
|
|
|
static int __init arcnet_init(void)
|
|
|
|
{
|
|
|
|
int count;
|
|
|
|
|
|
|
|
arcnet_debug = debug;
|
|
|
|
|
2015-05-06 01:05:56 +08:00
|
|
|
pr_info("arcnet loaded\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* initialize the protocol map */
|
|
|
|
arc_raw_proto = arc_proto_default = arc_bcast_proto = &arc_proto_null;
|
|
|
|
for (count = 0; count < 256; count++)
|
|
|
|
arc_proto_map[count] = arc_proto_default;
|
|
|
|
|
2015-05-06 01:05:54 +08:00
|
|
|
if (BUGLVL(D_DURING))
|
2017-02-28 06:30:02 +08:00
|
|
|
pr_info("struct sizes: %zd %zd %zd %zd %zd\n",
|
2015-05-06 01:05:56 +08:00
|
|
|
sizeof(struct arc_hardware),
|
|
|
|
sizeof(struct arc_rfc1201),
|
|
|
|
sizeof(struct arc_rfc1051),
|
|
|
|
sizeof(struct arc_eth_encap),
|
|
|
|
sizeof(struct archdr));
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit arcnet_exit(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
module_init(arcnet_init);
|
|
|
|
module_exit(arcnet_exit);
|
|
|
|
|
2015-05-06 01:05:52 +08:00
|
|
|
/* Dump the contents of an sk_buff */
|
2005-04-17 06:20:36 +08:00
|
|
|
#if ARCNET_DEBUG_MAX & D_SKB
|
|
|
|
void arcnet_dump_skb(struct net_device *dev,
|
|
|
|
struct sk_buff *skb, char *desc)
|
|
|
|
{
|
2009-07-07 04:05:40 +08:00
|
|
|
char hdr[32];
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-07-07 04:05:40 +08:00
|
|
|
/* dump the packet */
|
|
|
|
snprintf(hdr, sizeof(hdr), "%6s:%s skb->data:", dev->name, desc);
|
|
|
|
print_hex_dump(KERN_DEBUG, hdr, DUMP_PREFIX_OFFSET,
|
|
|
|
16, 1, skb->data, skb->len, true);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(arcnet_dump_skb);
|
|
|
|
#endif
|
|
|
|
|
2015-05-06 01:05:52 +08:00
|
|
|
/* Dump the contents of an ARCnet buffer */
|
2005-04-17 06:20:36 +08:00
|
|
|
#if (ARCNET_DEBUG_MAX & (D_RX | D_TX))
|
2006-01-14 10:10:22 +08:00
|
|
|
static void arcnet_dump_packet(struct net_device *dev, int bufnum,
|
|
|
|
char *desc, int take_arcnet_lock)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2008-11-13 15:37:49 +08:00
|
|
|
struct arcnet_local *lp = netdev_priv(dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
int i, length;
|
|
|
|
unsigned long flags = 0;
|
|
|
|
static uint8_t buf[512];
|
2009-07-07 04:05:40 +08:00
|
|
|
char hdr[32];
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* hw.copy_from_card expects IRQ context so take the IRQ lock
|
2015-05-06 01:05:52 +08:00
|
|
|
* to keep it single threaded
|
|
|
|
*/
|
2015-05-06 01:05:47 +08:00
|
|
|
if (take_arcnet_lock)
|
2005-04-17 06:20:36 +08:00
|
|
|
spin_lock_irqsave(&lp->lock, flags);
|
|
|
|
|
|
|
|
lp->hw.copy_from_card(dev, bufnum, 0, buf, 512);
|
2015-05-06 01:05:47 +08:00
|
|
|
if (take_arcnet_lock)
|
2005-04-17 06:20:36 +08:00
|
|
|
spin_unlock_irqrestore(&lp->lock, flags);
|
|
|
|
|
|
|
|
/* if the offset[0] byte is nonzero, this is a 256-byte packet */
|
|
|
|
length = (buf[2] ? 256 : 512);
|
|
|
|
|
2009-07-07 04:05:40 +08:00
|
|
|
/* dump the packet */
|
|
|
|
snprintf(hdr, sizeof(hdr), "%6s:%s packet dump:", dev->name, desc);
|
|
|
|
print_hex_dump(KERN_DEBUG, hdr, DUMP_PREFIX_OFFSET,
|
|
|
|
16, 1, buf, length, true);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2006-01-14 10:10:22 +08:00
|
|
|
#else
|
|
|
|
|
2015-05-06 01:05:47 +08:00
|
|
|
#define arcnet_dump_packet(dev, bufnum, desc, take_arcnet_lock) do { } while (0)
|
2006-01-14 10:10:22 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
#endif
|
|
|
|
|
2014-09-18 06:12:50 +08:00
|
|
|
/* Trigger a LED event in response to a ARCNET device event */
|
|
|
|
void arcnet_led_event(struct net_device *dev, enum arcnet_led_event event)
|
|
|
|
{
|
|
|
|
struct arcnet_local *lp = netdev_priv(dev);
|
|
|
|
unsigned long led_delay = 350;
|
|
|
|
unsigned long tx_delay = 50;
|
|
|
|
|
|
|
|
switch (event) {
|
|
|
|
case ARCNET_LED_EVENT_RECON:
|
|
|
|
led_trigger_blink_oneshot(lp->recon_led_trig,
|
|
|
|
&led_delay, &led_delay, 0);
|
|
|
|
break;
|
|
|
|
case ARCNET_LED_EVENT_OPEN:
|
|
|
|
led_trigger_event(lp->tx_led_trig, LED_OFF);
|
|
|
|
led_trigger_event(lp->recon_led_trig, LED_OFF);
|
|
|
|
break;
|
|
|
|
case ARCNET_LED_EVENT_STOP:
|
|
|
|
led_trigger_event(lp->tx_led_trig, LED_OFF);
|
|
|
|
led_trigger_event(lp->recon_led_trig, LED_OFF);
|
|
|
|
break;
|
|
|
|
case ARCNET_LED_EVENT_TX:
|
|
|
|
led_trigger_blink_oneshot(lp->tx_led_trig,
|
|
|
|
&tx_delay, &tx_delay, 0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(arcnet_led_event);
|
|
|
|
|
|
|
|
static void arcnet_led_release(struct device *gendev, void *res)
|
|
|
|
{
|
|
|
|
struct arcnet_local *lp = netdev_priv(to_net_dev(gendev));
|
|
|
|
|
|
|
|
led_trigger_unregister_simple(lp->tx_led_trig);
|
|
|
|
led_trigger_unregister_simple(lp->recon_led_trig);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Register ARCNET LED triggers for a arcnet device
|
|
|
|
*
|
|
|
|
* This is normally called from a driver's probe function
|
|
|
|
*/
|
|
|
|
void devm_arcnet_led_init(struct net_device *netdev, int index, int subid)
|
|
|
|
{
|
|
|
|
struct arcnet_local *lp = netdev_priv(netdev);
|
|
|
|
void *res;
|
|
|
|
|
|
|
|
res = devres_alloc(arcnet_led_release, 0, GFP_KERNEL);
|
|
|
|
if (!res) {
|
|
|
|
netdev_err(netdev, "cannot register LED triggers\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
snprintf(lp->tx_led_trig_name, sizeof(lp->tx_led_trig_name),
|
|
|
|
"arc%d-%d-tx", index, subid);
|
|
|
|
snprintf(lp->recon_led_trig_name, sizeof(lp->recon_led_trig_name),
|
|
|
|
"arc%d-%d-recon", index, subid);
|
|
|
|
|
|
|
|
led_trigger_register_simple(lp->tx_led_trig_name,
|
|
|
|
&lp->tx_led_trig);
|
|
|
|
led_trigger_register_simple(lp->recon_led_trig_name,
|
|
|
|
&lp->recon_led_trig);
|
|
|
|
|
|
|
|
devres_add(&netdev->dev, res);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(devm_arcnet_led_init);
|
|
|
|
|
2015-05-06 01:05:52 +08:00
|
|
|
/* Unregister a protocol driver from the arc_proto_map. Protocol drivers
|
2005-04-17 06:20:36 +08:00
|
|
|
* are responsible for registering themselves, but the unregister routine
|
|
|
|
* is pretty generic so we'll do it here.
|
|
|
|
*/
|
|
|
|
void arcnet_unregister_proto(struct ArcProto *proto)
|
|
|
|
{
|
|
|
|
int count;
|
|
|
|
|
|
|
|
if (arc_proto_default == proto)
|
|
|
|
arc_proto_default = &arc_proto_null;
|
|
|
|
if (arc_bcast_proto == proto)
|
|
|
|
arc_bcast_proto = arc_proto_default;
|
|
|
|
if (arc_raw_proto == proto)
|
|
|
|
arc_raw_proto = arc_proto_default;
|
|
|
|
|
|
|
|
for (count = 0; count < 256; count++) {
|
|
|
|
if (arc_proto_map[count] == proto)
|
|
|
|
arc_proto_map[count] = arc_proto_default;
|
|
|
|
}
|
|
|
|
}
|
2015-05-06 01:05:57 +08:00
|
|
|
EXPORT_SYMBOL(arcnet_unregister_proto);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2015-05-06 01:05:52 +08:00
|
|
|
/* Add a buffer to the queue. Only the interrupt handler is allowed to do
|
2005-04-17 06:20:36 +08:00
|
|
|
* this, unless interrupts are disabled.
|
2015-05-06 01:05:47 +08:00
|
|
|
*
|
2005-04-17 06:20:36 +08:00
|
|
|
* Note: we don't check for a full queue, since there aren't enough buffers
|
|
|
|
* to more than fill it.
|
|
|
|
*/
|
|
|
|
static void release_arcbuf(struct net_device *dev, int bufnum)
|
|
|
|
{
|
2008-11-13 15:37:49 +08:00
|
|
|
struct arcnet_local *lp = netdev_priv(dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
int i;
|
|
|
|
|
|
|
|
lp->buf_queue[lp->first_free_buf++] = bufnum;
|
|
|
|
lp->first_free_buf %= 5;
|
|
|
|
|
2015-05-06 01:05:54 +08:00
|
|
|
if (BUGLVL(D_DURING)) {
|
2015-05-06 01:05:55 +08:00
|
|
|
arc_printk(D_DURING, dev, "release_arcbuf: freed #%d; buffer queue is now: ",
|
|
|
|
bufnum);
|
2015-05-06 01:05:47 +08:00
|
|
|
for (i = lp->next_buf; i != lp->first_free_buf; i = (i + 1) % 5)
|
2015-05-06 01:05:55 +08:00
|
|
|
arc_cont(D_DURING, "#%d ", lp->buf_queue[i]);
|
|
|
|
arc_cont(D_DURING, "\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-06 01:05:52 +08:00
|
|
|
/* Get a buffer from the queue.
|
|
|
|
* If this returns -1, there are no buffers available.
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
|
|
|
static int get_arcbuf(struct net_device *dev)
|
|
|
|
{
|
2008-11-13 15:37:49 +08:00
|
|
|
struct arcnet_local *lp = netdev_priv(dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
int buf = -1, i;
|
|
|
|
|
|
|
|
if (!atomic_dec_and_test(&lp->buf_lock)) {
|
|
|
|
/* already in this function */
|
2015-05-06 01:05:55 +08:00
|
|
|
arc_printk(D_NORMAL, dev, "get_arcbuf: overlap (%d)!\n",
|
|
|
|
lp->buf_lock.counter);
|
2015-05-06 01:05:49 +08:00
|
|
|
} else { /* we can continue */
|
2005-04-17 06:20:36 +08:00
|
|
|
if (lp->next_buf >= 5)
|
|
|
|
lp->next_buf -= 5;
|
|
|
|
|
2015-05-06 01:05:49 +08:00
|
|
|
if (lp->next_buf == lp->first_free_buf) {
|
2015-05-06 01:05:55 +08:00
|
|
|
arc_printk(D_NORMAL, dev, "get_arcbuf: BUG: no buffers are available??\n");
|
2015-05-06 01:05:49 +08:00
|
|
|
} else {
|
2005-04-17 06:20:36 +08:00
|
|
|
buf = lp->buf_queue[lp->next_buf++];
|
|
|
|
lp->next_buf %= 5;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-06 01:05:54 +08:00
|
|
|
if (BUGLVL(D_DURING)) {
|
2015-05-06 01:05:55 +08:00
|
|
|
arc_printk(D_DURING, dev, "get_arcbuf: got #%d; buffer queue is now: ",
|
|
|
|
buf);
|
2015-05-06 01:05:47 +08:00
|
|
|
for (i = lp->next_buf; i != lp->first_free_buf; i = (i + 1) % 5)
|
2015-05-06 01:05:55 +08:00
|
|
|
arc_cont(D_DURING, "#%d ", lp->buf_queue[i]);
|
|
|
|
arc_cont(D_DURING, "\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
atomic_inc(&lp->buf_lock);
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int choose_mtu(void)
|
|
|
|
{
|
|
|
|
int count, mtu = 65535;
|
|
|
|
|
|
|
|
/* choose the smallest MTU of all available encaps */
|
|
|
|
for (count = 0; count < 256; count++) {
|
2009-12-03 15:58:21 +08:00
|
|
|
if (arc_proto_map[count] != &arc_proto_null &&
|
|
|
|
arc_proto_map[count]->mtu < mtu) {
|
2005-04-17 06:20:36 +08:00
|
|
|
mtu = arc_proto_map[count]->mtu;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return mtu == 65535 ? XMTU : mtu;
|
|
|
|
}
|
|
|
|
|
2007-10-09 16:40:57 +08:00
|
|
|
static const struct header_ops arcnet_header_ops = {
|
|
|
|
.create = arcnet_header,
|
|
|
|
};
|
|
|
|
|
2009-01-09 21:01:09 +08:00
|
|
|
static const struct net_device_ops arcnet_netdev_ops = {
|
|
|
|
.ndo_open = arcnet_open,
|
|
|
|
.ndo_stop = arcnet_close,
|
|
|
|
.ndo_start_xmit = arcnet_send_packet,
|
|
|
|
.ndo_tx_timeout = arcnet_timeout,
|
|
|
|
};
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* Setup a struct device for ARCnet. */
|
|
|
|
static void arcdev_setup(struct net_device *dev)
|
|
|
|
{
|
|
|
|
dev->type = ARPHRD_ARCNET;
|
2009-01-09 21:01:09 +08:00
|
|
|
dev->netdev_ops = &arcnet_netdev_ops;
|
2007-10-09 16:40:57 +08:00
|
|
|
dev->header_ops = &arcnet_header_ops;
|
2015-09-17 21:18:34 +08:00
|
|
|
dev->hard_header_len = sizeof(struct arc_hardware);
|
2005-04-17 06:20:36 +08:00
|
|
|
dev->mtu = choose_mtu();
|
|
|
|
|
|
|
|
dev->addr_len = ARCNET_ALEN;
|
|
|
|
dev->tx_queue_len = 100;
|
|
|
|
dev->broadcast[0] = 0x00; /* for us, broadcasts are address 0 */
|
|
|
|
dev->watchdog_timeo = TX_TIMEOUT;
|
|
|
|
|
|
|
|
/* New-style flags. */
|
|
|
|
dev->flags = IFF_BROADCAST;
|
|
|
|
}
|
|
|
|
|
2015-09-16 16:15:45 +08:00
|
|
|
static void arcnet_timer(unsigned long data)
|
|
|
|
{
|
|
|
|
struct net_device *dev = (struct net_device *)data;
|
|
|
|
|
|
|
|
if (!netif_carrier_ok(dev)) {
|
|
|
|
netif_carrier_on(dev);
|
|
|
|
netdev_info(dev, "link up\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-09 21:01:09 +08:00
|
|
|
struct net_device *alloc_arcdev(const char *name)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct net_device *dev;
|
|
|
|
|
|
|
|
dev = alloc_netdev(sizeof(struct arcnet_local),
|
net: set name_assign_type in alloc_netdev()
Extend alloc_netdev{,_mq{,s}}() to take name_assign_type as argument, and convert
all users to pass NET_NAME_UNKNOWN.
Coccinelle patch:
@@
expression sizeof_priv, name, setup, txqs, rxqs, count;
@@
(
-alloc_netdev_mqs(sizeof_priv, name, setup, txqs, rxqs)
+alloc_netdev_mqs(sizeof_priv, name, NET_NAME_UNKNOWN, setup, txqs, rxqs)
|
-alloc_netdev_mq(sizeof_priv, name, setup, count)
+alloc_netdev_mq(sizeof_priv, name, NET_NAME_UNKNOWN, setup, count)
|
-alloc_netdev(sizeof_priv, name, setup)
+alloc_netdev(sizeof_priv, name, NET_NAME_UNKNOWN, setup)
)
v9: move comments here from the wrong commit
Signed-off-by: Tom Gundersen <teg@jklm.no>
Reviewed-by: David Herrmann <dh.herrmann@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2014-07-14 22:37:24 +08:00
|
|
|
name && *name ? name : "arc%d", NET_NAME_UNKNOWN,
|
|
|
|
arcdev_setup);
|
2015-05-06 01:05:47 +08:00
|
|
|
if (dev) {
|
2008-11-13 15:37:49 +08:00
|
|
|
struct arcnet_local *lp = netdev_priv(dev);
|
2015-05-06 01:05:48 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
spin_lock_init(&lp->lock);
|
2015-09-16 16:15:45 +08:00
|
|
|
init_timer(&lp->timer);
|
|
|
|
lp->timer.data = (unsigned long) dev;
|
|
|
|
lp->timer.function = arcnet_timer;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return dev;
|
|
|
|
}
|
2015-05-06 01:05:57 +08:00
|
|
|
EXPORT_SYMBOL(alloc_arcdev);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2015-05-06 01:05:52 +08:00
|
|
|
/* Open/initialize the board. This is called sometime after booting when
|
2005-04-17 06:20:36 +08:00
|
|
|
* the 'ifconfig' program is run.
|
|
|
|
*
|
|
|
|
* This routine should set everything up anew at each open, even registers
|
|
|
|
* that "should" only need to be set once at boot, so that there is
|
|
|
|
* non-reboot way to recover if something goes wrong.
|
|
|
|
*/
|
2009-01-09 21:01:09 +08:00
|
|
|
int arcnet_open(struct net_device *dev)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2008-11-13 15:37:49 +08:00
|
|
|
struct arcnet_local *lp = netdev_priv(dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
int count, newmtu, error;
|
|
|
|
|
2015-05-06 01:05:55 +08:00
|
|
|
arc_printk(D_INIT, dev, "opened.");
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (!try_module_get(lp->hw.owner))
|
|
|
|
return -ENODEV;
|
|
|
|
|
2015-05-06 01:05:54 +08:00
|
|
|
if (BUGLVL(D_PROTO)) {
|
2015-05-06 01:05:55 +08:00
|
|
|
arc_printk(D_PROTO, dev, "protocol map (default is '%c'): ",
|
|
|
|
arc_proto_default->suffix);
|
2005-04-17 06:20:36 +08:00
|
|
|
for (count = 0; count < 256; count++)
|
2015-05-06 01:05:55 +08:00
|
|
|
arc_cont(D_PROTO, "%c", arc_proto_map[count]->suffix);
|
|
|
|
arc_cont(D_PROTO, "\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2015-05-06 01:05:55 +08:00
|
|
|
arc_printk(D_INIT, dev, "arcnet_open: resetting card.\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* try to put the card in a defined state - if it fails the first
|
|
|
|
* time, actually reset it.
|
|
|
|
*/
|
|
|
|
error = -ENODEV;
|
2015-05-06 01:06:12 +08:00
|
|
|
if (lp->hw.reset(dev, 0) && lp->hw.reset(dev, 1))
|
2005-04-17 06:20:36 +08:00
|
|
|
goto out_module_put;
|
|
|
|
|
|
|
|
newmtu = choose_mtu();
|
|
|
|
if (newmtu < dev->mtu)
|
|
|
|
dev->mtu = newmtu;
|
|
|
|
|
2015-05-06 01:05:55 +08:00
|
|
|
arc_printk(D_INIT, dev, "arcnet_open: mtu: %d.\n", dev->mtu);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* autodetect the encapsulation for each host. */
|
|
|
|
memset(lp->default_proto, 0, sizeof(lp->default_proto));
|
|
|
|
|
|
|
|
/* the broadcast address is special - use the 'bcast' protocol */
|
|
|
|
for (count = 0; count < 256; count++) {
|
|
|
|
if (arc_proto_map[count] == arc_bcast_proto) {
|
|
|
|
lp->default_proto[0] = count;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* initialize buffers */
|
|
|
|
atomic_set(&lp->buf_lock, 1);
|
|
|
|
|
|
|
|
lp->next_buf = lp->first_free_buf = 0;
|
|
|
|
release_arcbuf(dev, 0);
|
|
|
|
release_arcbuf(dev, 1);
|
|
|
|
release_arcbuf(dev, 2);
|
|
|
|
release_arcbuf(dev, 3);
|
|
|
|
lp->cur_tx = lp->next_tx = -1;
|
|
|
|
lp->cur_rx = -1;
|
|
|
|
|
|
|
|
lp->rfc1201.sequence = 1;
|
|
|
|
|
|
|
|
/* bring up the hardware driver */
|
|
|
|
if (lp->hw.open)
|
|
|
|
lp->hw.open(dev);
|
|
|
|
|
|
|
|
if (dev->dev_addr[0] == 0)
|
2015-05-06 01:05:55 +08:00
|
|
|
arc_printk(D_NORMAL, dev, "WARNING! Station address 00 is reserved for broadcasts!\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
else if (dev->dev_addr[0] == 255)
|
2015-05-06 01:05:55 +08:00
|
|
|
arc_printk(D_NORMAL, dev, "WARNING! Station address FF may confuse DOS networking programs!\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2015-05-06 01:05:55 +08:00
|
|
|
arc_printk(D_DEBUG, dev, "%s: %d: %s\n", __FILE__, __LINE__, __func__);
|
2015-05-06 01:06:12 +08:00
|
|
|
if (lp->hw.status(dev) & RESETflag) {
|
2015-05-06 01:05:55 +08:00
|
|
|
arc_printk(D_DEBUG, dev, "%s: %d: %s\n",
|
|
|
|
__FILE__, __LINE__, __func__);
|
2015-05-06 01:06:12 +08:00
|
|
|
lp->hw.command(dev, CFLAGScmd | RESETclear);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2015-05-06 01:05:55 +08:00
|
|
|
arc_printk(D_DEBUG, dev, "%s: %d: %s\n", __FILE__, __LINE__, __func__);
|
2005-04-17 06:20:36 +08:00
|
|
|
/* make sure we're ready to receive IRQ's. */
|
2015-05-06 01:06:12 +08:00
|
|
|
lp->hw.intmask(dev, 0);
|
2005-04-17 06:20:36 +08:00
|
|
|
udelay(1); /* give it time to set the mask before
|
|
|
|
* we reset it again. (may not even be
|
|
|
|
* necessary)
|
|
|
|
*/
|
2015-05-06 01:05:55 +08:00
|
|
|
arc_printk(D_DEBUG, dev, "%s: %d: %s\n", __FILE__, __LINE__, __func__);
|
2005-04-17 06:20:36 +08:00
|
|
|
lp->intmask = NORXflag | RECONflag;
|
2015-05-06 01:06:12 +08:00
|
|
|
lp->hw.intmask(dev, lp->intmask);
|
2015-05-06 01:05:55 +08:00
|
|
|
arc_printk(D_DEBUG, dev, "%s: %d: %s\n", __FILE__, __LINE__, __func__);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2015-09-16 16:15:45 +08:00
|
|
|
netif_carrier_off(dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
netif_start_queue(dev);
|
2015-09-16 16:15:45 +08:00
|
|
|
mod_timer(&lp->timer, jiffies + msecs_to_jiffies(1000));
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2014-09-18 06:12:50 +08:00
|
|
|
arcnet_led_event(dev, ARCNET_LED_EVENT_OPEN);
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
out_module_put:
|
|
|
|
module_put(lp->hw.owner);
|
|
|
|
return error;
|
|
|
|
}
|
2015-05-06 01:05:57 +08:00
|
|
|
EXPORT_SYMBOL(arcnet_open);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* The inverse routine to arcnet_open - shuts down the card. */
|
2009-01-09 21:01:09 +08:00
|
|
|
int arcnet_close(struct net_device *dev)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2008-11-13 15:37:49 +08:00
|
|
|
struct arcnet_local *lp = netdev_priv(dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2014-09-18 06:12:50 +08:00
|
|
|
arcnet_led_event(dev, ARCNET_LED_EVENT_STOP);
|
2015-09-16 16:15:45 +08:00
|
|
|
del_timer_sync(&lp->timer);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
netif_stop_queue(dev);
|
2015-09-16 16:15:45 +08:00
|
|
|
netif_carrier_off(dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* flush TX and disable RX */
|
2015-05-06 01:06:12 +08:00
|
|
|
lp->hw.intmask(dev, 0);
|
|
|
|
lp->hw.command(dev, NOTXcmd); /* stop transmit */
|
|
|
|
lp->hw.command(dev, NORXcmd); /* disable receive */
|
2005-04-17 06:20:36 +08:00
|
|
|
mdelay(1);
|
|
|
|
|
|
|
|
/* shut down the card */
|
|
|
|
lp->hw.close(dev);
|
|
|
|
module_put(lp->hw.owner);
|
|
|
|
return 0;
|
|
|
|
}
|
2015-05-06 01:05:57 +08:00
|
|
|
EXPORT_SYMBOL(arcnet_close);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
static int arcnet_header(struct sk_buff *skb, struct net_device *dev,
|
2007-10-09 16:40:57 +08:00
|
|
|
unsigned short type, const void *daddr,
|
|
|
|
const void *saddr, unsigned len)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2007-10-09 16:40:57 +08:00
|
|
|
const struct arcnet_local *lp = netdev_priv(dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
uint8_t _daddr, proto_num;
|
|
|
|
struct ArcProto *proto;
|
|
|
|
|
2015-05-06 01:05:55 +08:00
|
|
|
arc_printk(D_DURING, dev,
|
|
|
|
"create header from %d to %d; protocol %d (%Xh); size %u.\n",
|
|
|
|
saddr ? *(uint8_t *)saddr : -1,
|
|
|
|
daddr ? *(uint8_t *)daddr : -1,
|
|
|
|
type, type, len);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2015-05-06 01:05:47 +08:00
|
|
|
if (skb->len != 0 && len != skb->len)
|
2015-05-06 01:05:55 +08:00
|
|
|
arc_printk(D_NORMAL, dev, "arcnet_header: Yikes! skb->len(%d) != len(%d)!\n",
|
|
|
|
skb->len, len);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2015-05-06 01:05:47 +08:00
|
|
|
/* Type is host order - ? */
|
|
|
|
if (type == ETH_P_ARCNET) {
|
|
|
|
proto = arc_raw_proto;
|
2015-05-06 01:05:55 +08:00
|
|
|
arc_printk(D_DEBUG, dev, "arc_raw_proto used. proto='%c'\n",
|
|
|
|
proto->suffix);
|
2015-05-06 01:05:47 +08:00
|
|
|
_daddr = daddr ? *(uint8_t *)daddr : 0;
|
2015-05-06 01:05:49 +08:00
|
|
|
} else if (!daddr) {
|
2015-05-06 01:05:52 +08:00
|
|
|
/* if the dest addr isn't provided, we can't choose an
|
|
|
|
* encapsulation! Store the packet type (eg. ETH_P_IP)
|
|
|
|
* for now, and we'll push on a real header when we do
|
|
|
|
* rebuild_header.
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
2015-05-06 01:05:47 +08:00
|
|
|
*(uint16_t *)skb_push(skb, 2) = type;
|
2015-05-06 01:05:52 +08:00
|
|
|
/* XXX: Why not use skb->mac_len? */
|
2007-04-11 12:21:55 +08:00
|
|
|
if (skb->network_header - skb->mac_header != 2)
|
2015-05-06 01:05:55 +08:00
|
|
|
arc_printk(D_NORMAL, dev, "arcnet_header: Yikes! diff (%u) is not 2!\n",
|
|
|
|
skb->network_header - skb->mac_header);
|
2005-04-17 06:20:36 +08:00
|
|
|
return -2; /* return error -- can't transmit yet! */
|
2015-05-06 01:05:49 +08:00
|
|
|
} else {
|
2005-04-17 06:20:36 +08:00
|
|
|
/* otherwise, we can just add the header as usual. */
|
2015-05-06 01:05:47 +08:00
|
|
|
_daddr = *(uint8_t *)daddr;
|
2005-04-17 06:20:36 +08:00
|
|
|
proto_num = lp->default_proto[_daddr];
|
|
|
|
proto = arc_proto_map[proto_num];
|
2015-05-06 01:05:55 +08:00
|
|
|
arc_printk(D_DURING, dev, "building header for %02Xh using protocol '%c'\n",
|
|
|
|
proto_num, proto->suffix);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (proto == &arc_proto_null && arc_bcast_proto != proto) {
|
2015-05-06 01:05:55 +08:00
|
|
|
arc_printk(D_DURING, dev, "actually, let's use '%c' instead.\n",
|
|
|
|
arc_bcast_proto->suffix);
|
2005-04-17 06:20:36 +08:00
|
|
|
proto = arc_bcast_proto;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return proto->build_header(skb, dev, type, _daddr);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Called by the kernel in order to transmit a packet. */
|
2009-09-01 03:50:58 +08:00
|
|
|
netdev_tx_t arcnet_send_packet(struct sk_buff *skb,
|
2015-05-06 01:05:47 +08:00
|
|
|
struct net_device *dev)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2008-11-13 15:37:49 +08:00
|
|
|
struct arcnet_local *lp = netdev_priv(dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
struct archdr *pkt;
|
|
|
|
struct arc_rfc1201 *soft;
|
|
|
|
struct ArcProto *proto;
|
|
|
|
int txbuf;
|
|
|
|
unsigned long flags;
|
2015-04-22 22:41:46 +08:00
|
|
|
int retval;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2015-05-06 01:05:55 +08:00
|
|
|
arc_printk(D_DURING, dev,
|
|
|
|
"transmit requested (status=%Xh, txbufs=%d/%d, len=%d, protocol %x)\n",
|
2015-05-06 01:06:12 +08:00
|
|
|
lp->hw.status(dev), lp->cur_tx, lp->next_tx, skb->len, skb->protocol);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2015-05-06 01:05:47 +08:00
|
|
|
pkt = (struct archdr *)skb->data;
|
2005-04-17 06:20:36 +08:00
|
|
|
soft = &pkt->soft.rfc1201;
|
|
|
|
proto = arc_proto_map[soft->proto];
|
|
|
|
|
2015-05-06 01:05:55 +08:00
|
|
|
arc_printk(D_SKB_SIZE, dev, "skb: transmitting %d bytes to %02X\n",
|
|
|
|
skb->len, pkt->hard.dest);
|
2015-05-06 01:05:54 +08:00
|
|
|
if (BUGLVL(D_SKB))
|
|
|
|
arcnet_dump_skb(dev, skb, "tx");
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* fits in one packet? */
|
|
|
|
if (skb->len - ARC_HDR_SIZE > XMTU && !proto->continue_tx) {
|
2015-05-06 01:05:55 +08:00
|
|
|
arc_printk(D_NORMAL, dev, "fixme: packet too large: compensating badly!\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
dev_kfree_skb(skb);
|
2005-09-07 10:54:48 +08:00
|
|
|
return NETDEV_TX_OK; /* don't try again */
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* We're busy transmitting a packet... */
|
|
|
|
netif_stop_queue(dev);
|
|
|
|
|
|
|
|
spin_lock_irqsave(&lp->lock, flags);
|
2015-05-06 01:06:12 +08:00
|
|
|
lp->hw.intmask(dev, 0);
|
2015-05-06 01:05:47 +08:00
|
|
|
if (lp->next_tx == -1)
|
2005-09-07 10:54:48 +08:00
|
|
|
txbuf = get_arcbuf(dev);
|
2015-05-06 01:05:49 +08:00
|
|
|
else
|
2005-09-07 10:54:48 +08:00
|
|
|
txbuf = -1;
|
2015-05-06 01:05:49 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (txbuf != -1) {
|
|
|
|
if (proto->prepare_tx(dev, pkt, skb->len, txbuf) &&
|
|
|
|
!proto->ack_tx) {
|
|
|
|
/* done right away and we don't want to acknowledge
|
2015-05-06 01:05:52 +08:00
|
|
|
* the package later - forget about it now
|
|
|
|
*/
|
2009-01-09 21:01:08 +08:00
|
|
|
dev->stats.tx_bytes += skb->len;
|
2015-04-22 22:41:46 +08:00
|
|
|
dev_kfree_skb(skb);
|
2005-04-17 06:20:36 +08:00
|
|
|
} else {
|
|
|
|
/* do it the 'split' way */
|
|
|
|
lp->outgoing.proto = proto;
|
|
|
|
lp->outgoing.skb = skb;
|
|
|
|
lp->outgoing.pkt = pkt;
|
|
|
|
|
|
|
|
if (proto->continue_tx &&
|
|
|
|
proto->continue_tx(dev, txbuf)) {
|
2015-05-06 01:05:55 +08:00
|
|
|
arc_printk(D_NORMAL, dev,
|
|
|
|
"bug! continue_tx finished the first time! (proto='%c')\n",
|
|
|
|
proto->suffix);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
2005-09-07 10:54:48 +08:00
|
|
|
retval = NETDEV_TX_OK;
|
2005-04-17 06:20:36 +08:00
|
|
|
lp->next_tx = txbuf;
|
|
|
|
} else {
|
2005-09-07 10:54:48 +08:00
|
|
|
retval = NETDEV_TX_BUSY;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2015-05-06 01:05:55 +08:00
|
|
|
arc_printk(D_DEBUG, dev, "%s: %d: %s, status: %x\n",
|
2015-05-06 01:06:12 +08:00
|
|
|
__FILE__, __LINE__, __func__, lp->hw.status(dev));
|
2005-04-17 06:20:36 +08:00
|
|
|
/* make sure we didn't ignore a TX IRQ while we were in here */
|
2015-05-06 01:06:12 +08:00
|
|
|
lp->hw.intmask(dev, 0);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2015-05-06 01:05:55 +08:00
|
|
|
arc_printk(D_DEBUG, dev, "%s: %d: %s\n", __FILE__, __LINE__, __func__);
|
2015-05-06 01:05:47 +08:00
|
|
|
lp->intmask |= TXFREEflag | EXCNAKflag;
|
2015-05-06 01:06:12 +08:00
|
|
|
lp->hw.intmask(dev, lp->intmask);
|
2015-05-06 01:05:55 +08:00
|
|
|
arc_printk(D_DEBUG, dev, "%s: %d: %s, status: %x\n",
|
2015-05-06 01:06:12 +08:00
|
|
|
__FILE__, __LINE__, __func__, lp->hw.status(dev));
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2014-09-18 06:12:50 +08:00
|
|
|
arcnet_led_event(dev, ARCNET_LED_EVENT_TX);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
spin_unlock_irqrestore(&lp->lock, flags);
|
2005-09-07 10:54:48 +08:00
|
|
|
return retval; /* no need to try again */
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2015-05-06 01:05:57 +08:00
|
|
|
EXPORT_SYMBOL(arcnet_send_packet);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2015-05-06 01:05:52 +08:00
|
|
|
/* Actually start transmitting a packet that was loaded into a buffer
|
2005-04-17 06:20:36 +08:00
|
|
|
* by prepare_tx. This should _only_ be called by the interrupt handler.
|
|
|
|
*/
|
|
|
|
static int go_tx(struct net_device *dev)
|
|
|
|
{
|
2008-11-13 15:37:49 +08:00
|
|
|
struct arcnet_local *lp = netdev_priv(dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2015-05-06 01:05:55 +08:00
|
|
|
arc_printk(D_DURING, dev, "go_tx: status=%Xh, intmask=%Xh, next_tx=%d, cur_tx=%d\n",
|
2015-05-06 01:06:12 +08:00
|
|
|
lp->hw.status(dev), lp->intmask, lp->next_tx, lp->cur_tx);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (lp->cur_tx != -1 || lp->next_tx == -1)
|
|
|
|
return 0;
|
|
|
|
|
2015-05-06 01:05:54 +08:00
|
|
|
if (BUGLVL(D_TX))
|
|
|
|
arcnet_dump_packet(dev, lp->next_tx, "go_tx", 0);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
lp->cur_tx = lp->next_tx;
|
|
|
|
lp->next_tx = -1;
|
|
|
|
|
|
|
|
/* start sending */
|
2015-05-06 01:06:12 +08:00
|
|
|
lp->hw.command(dev, TXcmd | (lp->cur_tx << 3));
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-01-09 21:01:08 +08:00
|
|
|
dev->stats.tx_packets++;
|
2005-04-17 06:20:36 +08:00
|
|
|
lp->lasttrans_dest = lp->lastload_dest;
|
|
|
|
lp->lastload_dest = 0;
|
|
|
|
lp->excnak_pending = 0;
|
2015-05-06 01:05:47 +08:00
|
|
|
lp->intmask |= TXFREEflag | EXCNAKflag;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Called by the kernel when transmit times out */
|
2009-01-09 21:01:09 +08:00
|
|
|
void arcnet_timeout(struct net_device *dev)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
unsigned long flags;
|
2008-11-13 15:37:49 +08:00
|
|
|
struct arcnet_local *lp = netdev_priv(dev);
|
2015-05-06 01:06:12 +08:00
|
|
|
int status = lp->hw.status(dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
char *msg;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&lp->lock, flags);
|
|
|
|
if (status & TXFREEflag) { /* transmit _DID_ finish */
|
|
|
|
msg = " - missed IRQ?";
|
|
|
|
} else {
|
|
|
|
msg = "";
|
2009-01-09 21:01:08 +08:00
|
|
|
dev->stats.tx_aborted_errors++;
|
2005-04-17 06:20:36 +08:00
|
|
|
lp->timed_out = 1;
|
2015-05-06 01:06:12 +08:00
|
|
|
lp->hw.command(dev, NOTXcmd | (lp->cur_tx << 3));
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2009-01-09 21:01:08 +08:00
|
|
|
dev->stats.tx_errors++;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* make sure we didn't miss a TX or a EXC NAK IRQ */
|
2015-05-06 01:06:12 +08:00
|
|
|
lp->hw.intmask(dev, 0);
|
2015-05-06 01:05:47 +08:00
|
|
|
lp->intmask |= TXFREEflag | EXCNAKflag;
|
2015-05-06 01:06:12 +08:00
|
|
|
lp->hw.intmask(dev, lp->intmask);
|
2015-05-06 01:05:47 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
spin_unlock_irqrestore(&lp->lock, flags);
|
|
|
|
|
2015-05-06 01:05:47 +08:00
|
|
|
if (time_after(jiffies, lp->last_timeout + 10 * HZ)) {
|
2015-05-06 01:05:55 +08:00
|
|
|
arc_printk(D_EXTRA, dev, "tx timed out%s (status=%Xh, intmask=%Xh, dest=%02Xh)\n",
|
|
|
|
msg, status, lp->intmask, lp->lasttrans_dest);
|
2005-04-17 06:20:36 +08:00
|
|
|
lp->last_timeout = jiffies;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lp->cur_tx == -1)
|
|
|
|
netif_wake_queue(dev);
|
|
|
|
}
|
2015-05-06 01:05:57 +08:00
|
|
|
EXPORT_SYMBOL(arcnet_timeout);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2015-05-06 01:05:52 +08:00
|
|
|
/* The typical workload of the driver: Handle the network interface
|
2005-04-17 06:20:36 +08:00
|
|
|
* interrupts. Establish which device needs attention, and call the correct
|
|
|
|
* chipset interrupt handler.
|
|
|
|
*/
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 21:55:46 +08:00
|
|
|
irqreturn_t arcnet_interrupt(int irq, void *dev_id)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct net_device *dev = dev_id;
|
|
|
|
struct arcnet_local *lp;
|
|
|
|
int recbuf, status, diagstatus, didsomething, boguscount;
|
|
|
|
int retval = IRQ_NONE;
|
|
|
|
|
2015-05-06 01:05:55 +08:00
|
|
|
arc_printk(D_DURING, dev, "\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2015-05-06 01:05:55 +08:00
|
|
|
arc_printk(D_DURING, dev, "in arcnet_interrupt\n");
|
2008-11-13 15:37:49 +08:00
|
|
|
|
|
|
|
lp = netdev_priv(dev);
|
2006-04-02 19:52:48 +08:00
|
|
|
BUG_ON(!lp);
|
2015-05-06 01:05:47 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
spin_lock(&lp->lock);
|
|
|
|
|
2015-05-06 01:05:52 +08:00
|
|
|
/* RESET flag was enabled - if device is not running, we must
|
|
|
|
* clear it right away (but nothing else).
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
|
|
|
if (!netif_running(dev)) {
|
2015-05-06 01:06:12 +08:00
|
|
|
if (lp->hw.status(dev) & RESETflag)
|
|
|
|
lp->hw.command(dev, CFLAGScmd | RESETclear);
|
|
|
|
lp->hw.intmask(dev, 0);
|
2005-04-17 06:20:36 +08:00
|
|
|
spin_unlock(&lp->lock);
|
2014-09-29 17:55:34 +08:00
|
|
|
return retval;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2015-05-06 01:05:55 +08:00
|
|
|
arc_printk(D_DURING, dev, "in arcnet_inthandler (status=%Xh, intmask=%Xh)\n",
|
2015-05-06 01:06:12 +08:00
|
|
|
lp->hw.status(dev), lp->intmask);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
boguscount = 5;
|
|
|
|
do {
|
2015-05-06 01:06:12 +08:00
|
|
|
status = lp->hw.status(dev);
|
2015-05-06 01:05:47 +08:00
|
|
|
diagstatus = (status >> 8) & 0xFF;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2015-05-06 01:05:55 +08:00
|
|
|
arc_printk(D_DEBUG, dev, "%s: %d: %s: status=%x\n",
|
|
|
|
__FILE__, __LINE__, __func__, status);
|
2005-04-17 06:20:36 +08:00
|
|
|
didsomething = 0;
|
|
|
|
|
2015-05-06 01:05:52 +08:00
|
|
|
/* RESET flag was enabled - card is resetting and if RX is
|
2005-04-17 06:20:36 +08:00
|
|
|
* disabled, it's NOT because we just got a packet.
|
2015-05-06 01:05:47 +08:00
|
|
|
*
|
2015-05-06 01:05:52 +08:00
|
|
|
* The card is in an undefined state.
|
|
|
|
* Clear it out and start over.
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
|
|
|
if (status & RESETflag) {
|
2015-05-06 01:05:55 +08:00
|
|
|
arc_printk(D_NORMAL, dev, "spurious reset (status=%Xh)\n",
|
|
|
|
status);
|
2005-04-17 06:20:36 +08:00
|
|
|
arcnet_close(dev);
|
|
|
|
arcnet_open(dev);
|
|
|
|
|
|
|
|
/* get out of the interrupt handler! */
|
|
|
|
break;
|
|
|
|
}
|
2015-05-06 01:05:52 +08:00
|
|
|
/* RX is inhibited - we must have received something.
|
|
|
|
* Prepare to receive into the next buffer.
|
2015-05-06 01:05:47 +08:00
|
|
|
*
|
2015-05-06 01:05:52 +08:00
|
|
|
* We don't actually copy the received packet from the card
|
|
|
|
* until after the transmit handler runs (and possibly
|
|
|
|
* launches the next tx); this should improve latency slightly
|
|
|
|
* if we get both types of interrupts at once.
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
|
|
|
recbuf = -1;
|
|
|
|
if (status & lp->intmask & NORXflag) {
|
|
|
|
recbuf = lp->cur_rx;
|
2015-05-06 01:05:55 +08:00
|
|
|
arc_printk(D_DURING, dev, "Buffer #%d: receive irq (status=%Xh)\n",
|
|
|
|
recbuf, status);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
lp->cur_rx = get_arcbuf(dev);
|
|
|
|
if (lp->cur_rx != -1) {
|
2015-05-06 01:05:55 +08:00
|
|
|
arc_printk(D_DURING, dev, "enabling receive to buffer #%d\n",
|
|
|
|
lp->cur_rx);
|
2015-05-06 01:06:12 +08:00
|
|
|
lp->hw.command(dev, RXcmd | (lp->cur_rx << 3) | RXbcasts);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
didsomething++;
|
|
|
|
}
|
|
|
|
|
2015-05-06 01:05:47 +08:00
|
|
|
if ((diagstatus & EXCNAKflag)) {
|
2015-05-06 01:05:55 +08:00
|
|
|
arc_printk(D_DURING, dev, "EXCNAK IRQ (diagstat=%Xh)\n",
|
|
|
|
diagstatus);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2015-05-06 01:06:12 +08:00
|
|
|
lp->hw.command(dev, NOTXcmd); /* disable transmit */
|
2015-05-06 01:05:47 +08:00
|
|
|
lp->excnak_pending = 1;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2015-05-06 01:06:12 +08:00
|
|
|
lp->hw.command(dev, EXCNAKclear);
|
2005-04-17 06:20:36 +08:00
|
|
|
lp->intmask &= ~(EXCNAKflag);
|
2015-05-06 01:05:47 +08:00
|
|
|
didsomething++;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* a transmit finished, and we're interested in it. */
|
|
|
|
if ((status & lp->intmask & TXFREEflag) || lp->timed_out) {
|
2015-05-06 01:05:47 +08:00
|
|
|
lp->intmask &= ~(TXFREEflag | EXCNAKflag);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2015-05-06 01:06:02 +08:00
|
|
|
arc_printk(D_DURING, dev, "TX IRQ (stat=%Xh)\n",
|
|
|
|
status);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (lp->cur_tx != -1 && !lp->timed_out) {
|
2015-05-06 01:05:47 +08:00
|
|
|
if (!(status & TXACKflag)) {
|
2005-04-17 06:20:36 +08:00
|
|
|
if (lp->lasttrans_dest != 0) {
|
2015-05-06 01:05:55 +08:00
|
|
|
arc_printk(D_EXTRA, dev,
|
|
|
|
"transmit was not acknowledged! (status=%Xh, dest=%02Xh)\n",
|
|
|
|
status,
|
|
|
|
lp->lasttrans_dest);
|
2009-01-09 21:01:08 +08:00
|
|
|
dev->stats.tx_errors++;
|
|
|
|
dev->stats.tx_carrier_errors++;
|
2005-04-17 06:20:36 +08:00
|
|
|
} else {
|
2015-05-06 01:05:55 +08:00
|
|
|
arc_printk(D_DURING, dev,
|
|
|
|
"broadcast was not acknowledged; that's normal (status=%Xh, dest=%02Xh)\n",
|
|
|
|
status,
|
|
|
|
lp->lasttrans_dest);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lp->outgoing.proto &&
|
|
|
|
lp->outgoing.proto->ack_tx) {
|
2015-05-06 01:05:47 +08:00
|
|
|
int ackstatus;
|
2015-05-06 01:05:48 +08:00
|
|
|
|
2015-05-06 01:05:47 +08:00
|
|
|
if (status & TXACKflag)
|
|
|
|
ackstatus = 2;
|
|
|
|
else if (lp->excnak_pending)
|
|
|
|
ackstatus = 1;
|
|
|
|
else
|
|
|
|
ackstatus = 0;
|
|
|
|
|
|
|
|
lp->outgoing.proto
|
|
|
|
->ack_tx(dev, ackstatus);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (lp->cur_tx != -1)
|
|
|
|
release_arcbuf(dev, lp->cur_tx);
|
|
|
|
|
|
|
|
lp->cur_tx = -1;
|
|
|
|
lp->timed_out = 0;
|
|
|
|
didsomething++;
|
|
|
|
|
|
|
|
/* send another packet if there is one */
|
|
|
|
go_tx(dev);
|
|
|
|
|
|
|
|
/* continue a split packet, if any */
|
2015-05-06 01:06:02 +08:00
|
|
|
if (lp->outgoing.proto &&
|
|
|
|
lp->outgoing.proto->continue_tx) {
|
2005-04-17 06:20:36 +08:00
|
|
|
int txbuf = get_arcbuf(dev);
|
2015-05-06 01:05:48 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (txbuf != -1) {
|
|
|
|
if (lp->outgoing.proto->continue_tx(dev, txbuf)) {
|
|
|
|
/* that was the last segment */
|
2009-01-09 21:01:08 +08:00
|
|
|
dev->stats.tx_bytes += lp->outgoing.skb->len;
|
2015-05-06 01:05:49 +08:00
|
|
|
if (!lp->outgoing.proto->ack_tx) {
|
2015-05-06 01:05:47 +08:00
|
|
|
dev_kfree_skb_irq(lp->outgoing.skb);
|
|
|
|
lp->outgoing.proto = NULL;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
lp->next_tx = txbuf;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* inform upper layers of idleness, if necessary */
|
|
|
|
if (lp->cur_tx == -1)
|
|
|
|
netif_wake_queue(dev);
|
|
|
|
}
|
|
|
|
/* now process the received packet, if any */
|
|
|
|
if (recbuf != -1) {
|
2015-05-06 01:05:54 +08:00
|
|
|
if (BUGLVL(D_RX))
|
|
|
|
arcnet_dump_packet(dev, recbuf, "rx irq", 0);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
arcnet_rx(dev, recbuf);
|
|
|
|
release_arcbuf(dev, recbuf);
|
|
|
|
|
|
|
|
didsomething++;
|
|
|
|
}
|
|
|
|
if (status & lp->intmask & RECONflag) {
|
2015-05-06 01:06:12 +08:00
|
|
|
lp->hw.command(dev, CFLAGScmd | CONFIGclear);
|
2009-01-09 21:01:08 +08:00
|
|
|
dev->stats.tx_carrier_errors++;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2015-05-06 01:05:55 +08:00
|
|
|
arc_printk(D_RECON, dev, "Network reconfiguration detected (status=%Xh)\n",
|
|
|
|
status);
|
2015-09-16 16:15:45 +08:00
|
|
|
if (netif_carrier_ok(dev)) {
|
|
|
|
netif_carrier_off(dev);
|
|
|
|
netdev_info(dev, "link down\n");
|
|
|
|
}
|
|
|
|
mod_timer(&lp->timer, jiffies + msecs_to_jiffies(1000));
|
|
|
|
|
2014-09-18 06:12:50 +08:00
|
|
|
arcnet_led_event(dev, ARCNET_LED_EVENT_RECON);
|
2005-09-07 10:54:48 +08:00
|
|
|
/* MYRECON bit is at bit 7 of diagstatus */
|
2015-05-06 01:05:47 +08:00
|
|
|
if (diagstatus & 0x80)
|
2015-05-06 01:05:55 +08:00
|
|
|
arc_printk(D_RECON, dev, "Put out that recon myself\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* is the RECON info empty or old? */
|
|
|
|
if (!lp->first_recon || !lp->last_recon ||
|
2008-03-29 05:41:24 +08:00
|
|
|
time_after(jiffies, lp->last_recon + HZ * 10)) {
|
2005-04-17 06:20:36 +08:00
|
|
|
if (lp->network_down)
|
2015-05-06 01:05:55 +08:00
|
|
|
arc_printk(D_NORMAL, dev, "reconfiguration detected: cabling restored?\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
lp->first_recon = lp->last_recon = jiffies;
|
|
|
|
lp->num_recons = lp->network_down = 0;
|
|
|
|
|
2015-05-06 01:05:55 +08:00
|
|
|
arc_printk(D_DURING, dev, "recon: clearing counters.\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
} else { /* add to current RECON counter */
|
|
|
|
lp->last_recon = jiffies;
|
|
|
|
lp->num_recons++;
|
|
|
|
|
2015-05-06 01:05:55 +08:00
|
|
|
arc_printk(D_DURING, dev, "recon: counter=%d, time=%lds, net=%d\n",
|
|
|
|
lp->num_recons,
|
|
|
|
(lp->last_recon - lp->first_recon) / HZ,
|
|
|
|
lp->network_down);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* if network is marked up;
|
|
|
|
* and first_recon and last_recon are 60+ apart;
|
|
|
|
* and the average no. of recons counted is
|
|
|
|
* > RECON_THRESHOLD/min;
|
|
|
|
* then print a warning message.
|
|
|
|
*/
|
2009-12-03 15:58:21 +08:00
|
|
|
if (!lp->network_down &&
|
|
|
|
(lp->last_recon - lp->first_recon) <= HZ * 60 &&
|
|
|
|
lp->num_recons >= RECON_THRESHOLD) {
|
2005-04-17 06:20:36 +08:00
|
|
|
lp->network_down = 1;
|
2015-05-06 01:05:55 +08:00
|
|
|
arc_printk(D_NORMAL, dev, "many reconfigurations detected: cabling problem?\n");
|
2009-12-03 15:58:21 +08:00
|
|
|
} else if (!lp->network_down &&
|
|
|
|
lp->last_recon - lp->first_recon > HZ * 60) {
|
2015-05-06 01:06:02 +08:00
|
|
|
/* reset counters if we've gone for
|
|
|
|
* over a minute.
|
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
lp->first_recon = lp->last_recon;
|
|
|
|
lp->num_recons = 1;
|
|
|
|
}
|
|
|
|
}
|
2008-03-29 05:41:24 +08:00
|
|
|
} else if (lp->network_down &&
|
2015-05-06 01:05:47 +08:00
|
|
|
time_after(jiffies, lp->last_recon + HZ * 10)) {
|
2005-04-17 06:20:36 +08:00
|
|
|
if (lp->network_down)
|
2015-05-06 01:05:55 +08:00
|
|
|
arc_printk(D_NORMAL, dev, "cabling restored?\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
lp->first_recon = lp->last_recon = 0;
|
|
|
|
lp->num_recons = lp->network_down = 0;
|
|
|
|
|
2015-05-06 01:05:55 +08:00
|
|
|
arc_printk(D_DURING, dev, "not recon: clearing counters anyway.\n");
|
2015-09-16 16:15:45 +08:00
|
|
|
netif_carrier_on(dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2015-05-06 01:05:49 +08:00
|
|
|
if (didsomething)
|
2005-04-17 06:20:36 +08:00
|
|
|
retval |= IRQ_HANDLED;
|
2015-05-06 01:05:49 +08:00
|
|
|
} while (--boguscount && didsomething);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2015-05-06 01:05:55 +08:00
|
|
|
arc_printk(D_DURING, dev, "arcnet_interrupt complete (status=%Xh, count=%d)\n",
|
2015-05-06 01:06:12 +08:00
|
|
|
lp->hw.status(dev), boguscount);
|
2015-05-06 01:05:55 +08:00
|
|
|
arc_printk(D_DURING, dev, "\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2015-05-06 01:06:12 +08:00
|
|
|
lp->hw.intmask(dev, 0);
|
2005-04-17 06:20:36 +08:00
|
|
|
udelay(1);
|
2015-05-06 01:06:12 +08:00
|
|
|
lp->hw.intmask(dev, lp->intmask);
|
2015-05-06 01:05:47 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
spin_unlock(&lp->lock);
|
|
|
|
return retval;
|
|
|
|
}
|
2015-05-06 01:05:57 +08:00
|
|
|
EXPORT_SYMBOL(arcnet_interrupt);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2015-05-06 01:05:52 +08:00
|
|
|
/* This is a generic packet receiver that calls arcnet??_rx depending on the
|
2005-04-17 06:20:36 +08:00
|
|
|
* protocol ID found.
|
|
|
|
*/
|
2006-01-14 10:10:22 +08:00
|
|
|
static void arcnet_rx(struct net_device *dev, int bufnum)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2008-11-13 15:37:49 +08:00
|
|
|
struct arcnet_local *lp = netdev_priv(dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
struct archdr pkt;
|
|
|
|
struct arc_rfc1201 *soft;
|
|
|
|
int length, ofs;
|
|
|
|
|
|
|
|
soft = &pkt.soft.rfc1201;
|
|
|
|
|
2013-07-19 13:48:05 +08:00
|
|
|
lp->hw.copy_from_card(dev, bufnum, 0, &pkt, ARC_HDR_SIZE);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (pkt.hard.offset[0]) {
|
|
|
|
ofs = pkt.hard.offset[0];
|
|
|
|
length = 256 - ofs;
|
|
|
|
} else {
|
|
|
|
ofs = pkt.hard.offset[1];
|
|
|
|
length = 512 - ofs;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get the full header, if possible */
|
2015-05-06 01:05:49 +08:00
|
|
|
if (sizeof(pkt.soft) <= length) {
|
2005-04-17 06:20:36 +08:00
|
|
|
lp->hw.copy_from_card(dev, bufnum, ofs, soft, sizeof(pkt.soft));
|
2015-05-06 01:05:49 +08:00
|
|
|
} else {
|
2005-04-17 06:20:36 +08:00
|
|
|
memset(&pkt.soft, 0, sizeof(pkt.soft));
|
|
|
|
lp->hw.copy_from_card(dev, bufnum, ofs, soft, length);
|
|
|
|
}
|
|
|
|
|
2015-05-06 01:05:55 +08:00
|
|
|
arc_printk(D_DURING, dev, "Buffer #%d: received packet from %02Xh to %02Xh (%d+4 bytes)\n",
|
|
|
|
bufnum, pkt.hard.source, pkt.hard.dest, length);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-01-09 21:01:08 +08:00
|
|
|
dev->stats.rx_packets++;
|
|
|
|
dev->stats.rx_bytes += length + ARC_HDR_SIZE;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* call the right receiver for the protocol */
|
|
|
|
if (arc_proto_map[soft->proto]->is_ip) {
|
2015-05-06 01:05:54 +08:00
|
|
|
if (BUGLVL(D_PROTO)) {
|
2005-04-17 06:20:36 +08:00
|
|
|
struct ArcProto
|
|
|
|
*oldp = arc_proto_map[lp->default_proto[pkt.hard.source]],
|
|
|
|
*newp = arc_proto_map[soft->proto];
|
|
|
|
|
|
|
|
if (oldp != newp) {
|
2015-05-06 01:05:55 +08:00
|
|
|
arc_printk(D_PROTO, dev,
|
|
|
|
"got protocol %02Xh; encap for host %02Xh is now '%c' (was '%c')\n",
|
|
|
|
soft->proto, pkt.hard.source,
|
|
|
|
newp->suffix, oldp->suffix);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* broadcasts will always be done with the last-used encap. */
|
|
|
|
lp->default_proto[0] = soft->proto;
|
|
|
|
|
|
|
|
/* in striking contrast, the following isn't a hack. */
|
|
|
|
lp->default_proto[pkt.hard.source] = soft->proto;
|
|
|
|
}
|
|
|
|
/* call the protocol-specific receiver. */
|
|
|
|
arc_proto_map[soft->proto]->rx(dev, bufnum, &pkt, length);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void null_rx(struct net_device *dev, int bufnum,
|
|
|
|
struct archdr *pkthdr, int length)
|
|
|
|
{
|
2015-05-06 01:05:55 +08:00
|
|
|
arc_printk(D_PROTO, dev,
|
|
|
|
"rx: don't know how to deal with proto %02Xh from host %02Xh.\n",
|
|
|
|
pkthdr->soft.rfc1201.proto, pkthdr->hard.source);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int null_build_header(struct sk_buff *skb, struct net_device *dev,
|
|
|
|
unsigned short type, uint8_t daddr)
|
|
|
|
{
|
2008-11-13 15:37:49 +08:00
|
|
|
struct arcnet_local *lp = netdev_priv(dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2015-05-06 01:05:55 +08:00
|
|
|
arc_printk(D_PROTO, dev,
|
|
|
|
"tx: can't build header for encap %02Xh; load a protocol driver.\n",
|
|
|
|
lp->default_proto[daddr]);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* always fails */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* the "do nothing" prepare_tx function warns that there's nothing to do. */
|
|
|
|
static int null_prepare_tx(struct net_device *dev, struct archdr *pkt,
|
|
|
|
int length, int bufnum)
|
|
|
|
{
|
2008-11-13 15:37:49 +08:00
|
|
|
struct arcnet_local *lp = netdev_priv(dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
struct arc_hardware newpkt;
|
|
|
|
|
2015-05-06 01:05:55 +08:00
|
|
|
arc_printk(D_PROTO, dev, "tx: no encap for this host; load a protocol driver.\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* send a packet to myself -- will never get received, of course */
|
|
|
|
newpkt.source = newpkt.dest = dev->dev_addr[0];
|
|
|
|
|
|
|
|
/* only one byte of actual data (and it's random) */
|
|
|
|
newpkt.offset[0] = 0xFF;
|
|
|
|
|
|
|
|
lp->hw.copy_to_card(dev, bufnum, 0, &newpkt, ARC_HDR_SIZE);
|
|
|
|
|
|
|
|
return 1; /* done */
|
|
|
|
}
|