Commit e1ffc0cd authored by David S. Miller's avatar David S. Miller

Merge tag 'arcnet-cleanup-v4.3-rc2' of git://git.pengutronix.de/git/mgr/linux

Michael Grzeschik says:

====================
ARCNET: refactoring and cleanup

This series cleans up the code in drivers/net/arcnet
and include/uapi/linux/if_arcnet.h . It doesn't change
the runtime behaviour of the code. Its only purpose
is to improve the code maintenance and readability.
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 927ab1d7 834c952a
...@@ -7292,7 +7292,6 @@ S: Odd Fixes ...@@ -7292,7 +7292,6 @@ S: Odd Fixes
F: drivers/net/ F: drivers/net/
F: include/linux/if_* F: include/linux/if_*
F: include/linux/netdevice.h F: include/linux/netdevice.h
F: include/linux/arcdevice.h
F: include/linux/etherdevice.h F: include/linux/etherdevice.h
F: include/linux/fcdevice.h F: include/linux/fcdevice.h
F: include/linux/fddidevice.h F: include/linux/fddidevice.h
......
/* /*
* Linux ARCnet driver - "raw mode" packet encapsulation (no soft headers) * Linux ARCnet driver - "raw mode" packet encapsulation (no soft headers)
* *
* Written 1994-1999 by Avery Pennarun. * Written 1994-1999 by Avery Pennarun.
* Derived from skeleton.c by Donald Becker. * Derived from skeleton.c by Donald Becker.
* *
...@@ -24,6 +24,8 @@ ...@@ -24,6 +24,8 @@
* ********************** * **********************
*/ */
#define pr_fmt(fmt) "arcnet:" KBUILD_MODNAME ": " fmt
#include <linux/module.h> #include <linux/module.h>
#include <linux/gfp.h> #include <linux/gfp.h>
#include <linux/init.h> #include <linux/init.h>
...@@ -31,58 +33,7 @@ ...@@ -31,58 +33,7 @@
#include <net/arp.h> #include <net/arp.h>
#include <linux/netdevice.h> #include <linux/netdevice.h>
#include <linux/skbuff.h> #include <linux/skbuff.h>
#include <linux/arcdevice.h> #include "arcdevice.h"
#define VERSION "arcnet: raw mode (`r') encapsulation support loaded.\n"
static void rx(struct net_device *dev, int bufnum,
struct archdr *pkthdr, int length);
static int build_header(struct sk_buff *skb, struct net_device *dev,
unsigned short type, uint8_t daddr);
static int prepare_tx(struct net_device *dev, struct archdr *pkt, int length,
int bufnum);
static struct ArcProto rawmode_proto =
{
.suffix = 'r',
.mtu = XMTU,
.rx = rx,
.build_header = build_header,
.prepare_tx = prepare_tx,
.continue_tx = NULL,
.ack_tx = NULL
};
static int __init arcnet_raw_init(void)
{
int count;
printk(VERSION);
for (count = 0; count < 256; count++)
if (arc_proto_map[count] == arc_proto_default)
arc_proto_map[count] = &rawmode_proto;
/* for raw mode, we only set the bcast proto if there's no better one */
if (arc_bcast_proto == arc_proto_default)
arc_bcast_proto = &rawmode_proto;
arc_proto_default = &rawmode_proto;
return 0;
}
static void __exit arcnet_raw_exit(void)
{
arcnet_unregister_proto(&rawmode_proto);
}
module_init(arcnet_raw_init);
module_exit(arcnet_raw_exit);
MODULE_LICENSE("GPL");
/* packet receiver */ /* packet receiver */
static void rx(struct net_device *dev, int bufnum, static void rx(struct net_device *dev, int bufnum,
...@@ -93,7 +44,7 @@ static void rx(struct net_device *dev, int bufnum, ...@@ -93,7 +44,7 @@ static void rx(struct net_device *dev, int bufnum,
struct archdr *pkt = pkthdr; struct archdr *pkt = pkthdr;
int ofs; int ofs;
BUGMSG(D_DURING, "it's a raw packet (length=%d)\n", length); arc_printk(D_DURING, dev, "it's a raw packet (length=%d)\n", length);
if (length > MTU) if (length > MTU)
ofs = 512 - length; ofs = 512 - length;
...@@ -101,15 +52,14 @@ static void rx(struct net_device *dev, int bufnum, ...@@ -101,15 +52,14 @@ static void rx(struct net_device *dev, int bufnum,
ofs = 256 - length; ofs = 256 - length;
skb = alloc_skb(length + ARC_HDR_SIZE, GFP_ATOMIC); skb = alloc_skb(length + ARC_HDR_SIZE, GFP_ATOMIC);
if (skb == NULL) { if (!skb) {
BUGMSG(D_NORMAL, "Memory squeeze, dropping packet.\n");
dev->stats.rx_dropped++; dev->stats.rx_dropped++;
return; return;
} }
skb_put(skb, length + ARC_HDR_SIZE); skb_put(skb, length + ARC_HDR_SIZE);
skb->dev = dev; skb->dev = dev;
pkt = (struct archdr *) skb->data; pkt = (struct archdr *)skb->data;
skb_reset_mac_header(skb); skb_reset_mac_header(skb);
skb_pull(skb, ARC_HDR_SIZE); skb_pull(skb, ARC_HDR_SIZE);
...@@ -121,38 +71,35 @@ static void rx(struct net_device *dev, int bufnum, ...@@ -121,38 +71,35 @@ static void rx(struct net_device *dev, int bufnum,
pkt->soft.raw + sizeof(pkt->soft), pkt->soft.raw + sizeof(pkt->soft),
length - sizeof(pkt->soft)); length - sizeof(pkt->soft));
BUGLVL(D_SKB) arcnet_dump_skb(dev, skb, "rx"); if (BUGLVL(D_SKB))
arcnet_dump_skb(dev, skb, "rx");
skb->protocol = cpu_to_be16(ETH_P_ARCNET); skb->protocol = cpu_to_be16(ETH_P_ARCNET);
netif_rx(skb); netif_rx(skb);
} }
/* Create the ARCnet hard/soft headers for raw mode.
/*
* Create the ARCnet hard/soft headers for raw mode.
* There aren't any soft headers in raw mode - not even the protocol id. * There aren't any soft headers in raw mode - not even the protocol id.
*/ */
static int build_header(struct sk_buff *skb, struct net_device *dev, static int build_header(struct sk_buff *skb, struct net_device *dev,
unsigned short type, uint8_t daddr) unsigned short type, uint8_t daddr)
{ {
int hdr_size = ARC_HDR_SIZE; int hdr_size = ARC_HDR_SIZE;
struct archdr *pkt = (struct archdr *) skb_push(skb, hdr_size); struct archdr *pkt = (struct archdr *)skb_push(skb, hdr_size);
/* /* Set the source hardware address.
* Set the source hardware address.
* *
* This is pretty pointless for most purposes, but it can help in * This is pretty pointless for most purposes, but it can help in
* debugging. ARCnet does not allow us to change the source address in * debugging. ARCnet does not allow us to change the source address
* the actual packet sent) * in the actual packet sent.
*/ */
pkt->hard.source = *dev->dev_addr; pkt->hard.source = *dev->dev_addr;
/* see linux/net/ethernet/eth.c to see where I got the following */ /* see linux/net/ethernet/eth.c to see where I got the following */
if (dev->flags & (IFF_LOOPBACK | IFF_NOARP)) { if (dev->flags & (IFF_LOOPBACK | IFF_NOARP)) {
/* /* FIXME: fill in the last byte of the dest ipaddr here
* FIXME: fill in the last byte of the dest ipaddr here to better * to better comply with RFC1051 in "noarp" mode.
* comply with RFC1051 in "noarp" mode.
*/ */
pkt->hard.dest = 0; pkt->hard.dest = 0;
return hdr_size; return hdr_size;
...@@ -163,7 +110,6 @@ static int build_header(struct sk_buff *skb, struct net_device *dev, ...@@ -163,7 +110,6 @@ static int build_header(struct sk_buff *skb, struct net_device *dev,
return hdr_size; /* success */ return hdr_size; /* success */
} }
static int prepare_tx(struct net_device *dev, struct archdr *pkt, int length, static int prepare_tx(struct net_device *dev, struct archdr *pkt, int length,
int bufnum) int bufnum)
{ {
...@@ -171,15 +117,16 @@ static int prepare_tx(struct net_device *dev, struct archdr *pkt, int length, ...@@ -171,15 +117,16 @@ static int prepare_tx(struct net_device *dev, struct archdr *pkt, int length,
struct arc_hardware *hard = &pkt->hard; struct arc_hardware *hard = &pkt->hard;
int ofs; int ofs;
BUGMSG(D_DURING, "prepare_tx: txbufs=%d/%d/%d\n", arc_printk(D_DURING, dev, "prepare_tx: txbufs=%d/%d/%d\n",
lp->next_tx, lp->cur_tx, bufnum); lp->next_tx, lp->cur_tx, bufnum);
length -= ARC_HDR_SIZE; /* hard header is not included in packet length */ /* hard header is not included in packet length */
length -= ARC_HDR_SIZE;
if (length > XMTU) { if (length > XMTU) {
/* should never happen! other people already check for this. */ /* should never happen! other people already check for this. */
BUGMSG(D_NORMAL, "Bug! prepare_tx with size %d (> %d)\n", arc_printk(D_NORMAL, dev, "Bug! prepare_tx with size %d (> %d)\n",
length, XMTU); length, XMTU);
length = XMTU; length = XMTU;
} }
if (length >= MinTU) { if (length >= MinTU) {
...@@ -188,11 +135,12 @@ static int prepare_tx(struct net_device *dev, struct archdr *pkt, int length, ...@@ -188,11 +135,12 @@ static int prepare_tx(struct net_device *dev, struct archdr *pkt, int length,
} else if (length > MTU) { } else if (length > MTU) {
hard->offset[0] = 0; hard->offset[0] = 0;
hard->offset[1] = ofs = 512 - length - 3; hard->offset[1] = ofs = 512 - length - 3;
} else } else {
hard->offset[0] = ofs = 256 - length; hard->offset[0] = ofs = 256 - length;
}
BUGMSG(D_DURING, "prepare_tx: length=%d ofs=%d\n", arc_printk(D_DURING, dev, "prepare_tx: length=%d ofs=%d\n",
length,ofs); length, ofs);
lp->hw.copy_to_card(dev, bufnum, 0, hard, ARC_HDR_SIZE); lp->hw.copy_to_card(dev, bufnum, 0, hard, ARC_HDR_SIZE);
lp->hw.copy_to_card(dev, bufnum, ofs, &pkt->soft, length); lp->hw.copy_to_card(dev, bufnum, ofs, &pkt->soft, length);
...@@ -201,3 +149,41 @@ static int prepare_tx(struct net_device *dev, struct archdr *pkt, int length, ...@@ -201,3 +149,41 @@ static int prepare_tx(struct net_device *dev, struct archdr *pkt, int length,
return 1; /* done */ return 1; /* done */
} }
static struct ArcProto rawmode_proto = {
.suffix = 'r',
.mtu = XMTU,
.rx = rx,
.build_header = build_header,
.prepare_tx = prepare_tx,
.continue_tx = NULL,
.ack_tx = NULL
};
static int __init arcnet_raw_init(void)
{
int count;
pr_info("raw mode (`r') encapsulation support loaded\n");
for (count = 0; count < 256; count++)
if (arc_proto_map[count] == arc_proto_default)
arc_proto_map[count] = &rawmode_proto;
/* for raw mode, we only set the bcast proto if there's no better one */
if (arc_bcast_proto == arc_proto_default)
arc_bcast_proto = &rawmode_proto;
arc_proto_default = &rawmode_proto;
return 0;
}
static void __exit arcnet_raw_exit(void)
{
arcnet_unregister_proto(&rawmode_proto);
}
module_init(arcnet_raw_init);
module_exit(arcnet_raw_exit);
MODULE_LICENSE("GPL");
/* /*
* Linux ARCnet driver - "RIM I" (entirely mem-mapped) cards * Linux ARCnet driver - "RIM I" (entirely mem-mapped) cards
* *
* Written 1994-1999 by Avery Pennarun. * Written 1994-1999 by Avery Pennarun.
* Written 1999-2000 by Martin Mares <mj@ucw.cz>. * Written 1999-2000 by Martin Mares <mj@ucw.cz>.
* Derived from skeleton.c by Donald Becker. * Derived from skeleton.c by Donald Becker.
...@@ -24,6 +24,9 @@ ...@@ -24,6 +24,9 @@
* *
* ********************** * **********************
*/ */
#define pr_fmt(fmt) "arcnet:" KBUILD_MODNAME ": " fmt
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/moduleparam.h> #include <linux/moduleparam.h>
...@@ -33,12 +36,10 @@ ...@@ -33,12 +36,10 @@
#include <linux/bootmem.h> #include <linux/bootmem.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/interrupt.h> #include <linux/interrupt.h>
#include <asm/io.h> #include <linux/io.h>
#include <linux/arcdevice.h>
#define VERSION "arcnet: RIM I (entirely mem-mapped) support\n"
#include "arcdevice.h"
#include "com9026.h"
/* Internal function declarations */ /* Internal function declarations */
...@@ -50,66 +51,46 @@ static void arcrimi_setmask(struct net_device *dev, int mask); ...@@ -50,66 +51,46 @@ static void arcrimi_setmask(struct net_device *dev, int mask);
static int arcrimi_reset(struct net_device *dev, int really_reset); static int arcrimi_reset(struct net_device *dev, int really_reset);
static void arcrimi_copy_to_card(struct net_device *dev, int bufnum, int offset, static void arcrimi_copy_to_card(struct net_device *dev, int bufnum, int offset,
void *buf, int count); void *buf, int count);
static void arcrimi_copy_from_card(struct net_device *dev, int bufnum, int offset, static void arcrimi_copy_from_card(struct net_device *dev, int bufnum,
void *buf, int count); int offset, void *buf, int count);
/* Handy defines for ARCnet specific stuff */ /* Handy defines for ARCnet specific stuff */
/* Amount of I/O memory used by the card */ /* Amount of I/O memory used by the card */
#define BUFFER_SIZE (512) #define BUFFER_SIZE (512)
#define MIRROR_SIZE (BUFFER_SIZE*4) #define MIRROR_SIZE (BUFFER_SIZE * 4)
/* COM 9026 controller chip --> ARCnet register addresses */ /* We cannot probe for a RIM I card; one reason is I don't know how to reset
#define _INTMASK (ioaddr+0) /* writable */
#define _STATUS (ioaddr+0) /* readable */
#define _COMMAND (ioaddr+1) /* writable, returns random vals on read (?) */
#define _RESET (ioaddr+8) /* software reset (on read) */
#define _MEMDATA (ioaddr+12) /* Data port for IO-mapped memory */
#define _ADDR_HI (ioaddr+15) /* Control registers for said */
#define _ADDR_LO (ioaddr+14)
#define _CONFIG (ioaddr+2) /* Configuration register */
#undef ASTATUS
#undef ACOMMAND
#undef AINTMASK
#define ASTATUS() readb(_STATUS)
#define ACOMMAND(cmd) writeb((cmd),_COMMAND)
#define AINTMASK(msk) writeb((msk),_INTMASK)
#define SETCONF() writeb(lp->config,_CONFIG)
/*
* We cannot probe for a RIM I card; one reason is I don't know how to reset
* them. In fact, we can't even get their node ID automatically. So, we * them. In fact, we can't even get their node ID automatically. So, we
* need to be passed a specific shmem address, IRQ, and node ID. * need to be passed a specific shmem address, IRQ, and node ID.
*/ */
static int __init arcrimi_probe(struct net_device *dev) static int __init arcrimi_probe(struct net_device *dev)
{ {
BUGLVL(D_NORMAL) printk(VERSION); if (BUGLVL(D_NORMAL)) {
BUGLVL(D_NORMAL) printk("E-mail me if you actually test the RIM I driver, please!\n"); pr_info("%s\n", "RIM I (entirely mem-mapped) support");
pr_info("E-mail me if you actually test the RIM I driver, please!\n");
BUGLVL(D_NORMAL) printk("Given: node %02Xh, shmem %lXh, irq %d\n", pr_info("Given: node %02Xh, shmem %lXh, irq %d\n",
dev->dev_addr[0], dev->mem_start, dev->irq); dev->dev_addr[0], dev->mem_start, dev->irq);
}
if (dev->mem_start <= 0 || dev->irq <= 0) { if (dev->mem_start <= 0 || dev->irq <= 0) {
BUGLVL(D_NORMAL) printk("No autoprobe for RIM I; you " if (BUGLVL(D_NORMAL))
"must specify the shmem and irq!\n"); pr_err("No autoprobe for RIM I; you must specify the shmem and irq!\n");
return -ENODEV; return -ENODEV;
} }
if (dev->dev_addr[0] == 0) { if (dev->dev_addr[0] == 0) {
BUGLVL(D_NORMAL) printk("You need to specify your card's station " if (BUGLVL(D_NORMAL))
"ID!\n"); pr_err("You need to specify your card's station ID!\n");
return -ENODEV; return -ENODEV;
} }
/* /* Grab the memory region at mem_start for MIRROR_SIZE bytes.
* Grab the memory region at mem_start for MIRROR_SIZE bytes.
* Later in arcrimi_found() the real size will be determined * Later in arcrimi_found() the real size will be determined
* and this reserve will be released and the correct size * and this reserve will be released and the correct size
* will be taken. * will be taken.
*/ */
if (!request_mem_region(dev->mem_start, MIRROR_SIZE, "arcnet (90xx)")) { if (!request_mem_region(dev->mem_start, MIRROR_SIZE, "arcnet (90xx)")) {
BUGLVL(D_NORMAL) printk("Card memory already allocated\n"); if (BUGLVL(D_NORMAL))
pr_notice("Card memory already allocated\n");
return -ENODEV; return -ENODEV;
} }
return arcrimi_found(dev); return arcrimi_found(dev);
...@@ -125,7 +106,7 @@ static int check_mirror(unsigned long addr, size_t size) ...@@ -125,7 +106,7 @@ static int check_mirror(unsigned long addr, size_t size)
p = ioremap(addr, size); p = ioremap(addr, size);
if (p) { if (p) {
if (readb(p) == TESTvalue) if (arcnet_readb(p, COM9026_REG_R_STATUS) == TESTvalue)
res = 1; res = 1;
else else
res = 0; res = 0;
...@@ -136,9 +117,8 @@ static int check_mirror(unsigned long addr, size_t size) ...@@ -136,9 +117,8 @@ static int check_mirror(unsigned long addr, size_t size)
return res; return res;
} }
/* /* Set up the struct net_device associated with this card.
* Set up the struct net_device associated with this card. Called after * Called after probing succeeds.
* probing succeeds.
*/ */
static int __init arcrimi_found(struct net_device *dev) static int __init arcrimi_found(struct net_device *dev)
{ {
...@@ -151,7 +131,7 @@ static int __init arcrimi_found(struct net_device *dev) ...@@ -151,7 +131,7 @@ static int __init arcrimi_found(struct net_device *dev)
p = ioremap(dev->mem_start, MIRROR_SIZE); p = ioremap(dev->mem_start, MIRROR_SIZE);
if (!p) { if (!p) {
release_mem_region(dev->mem_start, MIRROR_SIZE); release_mem_region(dev->mem_start, MIRROR_SIZE);
BUGMSG(D_NORMAL, "Can't ioremap\n"); arc_printk(D_NORMAL, dev, "Can't ioremap\n");
return -ENODEV; return -ENODEV;
} }
...@@ -159,13 +139,14 @@ static int __init arcrimi_found(struct net_device *dev) ...@@ -159,13 +139,14 @@ static int __init arcrimi_found(struct net_device *dev)
if (request_irq(dev->irq, arcnet_interrupt, 0, "arcnet (RIM I)", dev)) { if (request_irq(dev->irq, arcnet_interrupt, 0, "arcnet (RIM I)", dev)) {
iounmap(p); iounmap(p);
release_mem_region(dev->mem_start, MIRROR_SIZE); release_mem_region(dev->mem_start, MIRROR_SIZE);
BUGMSG(D_NORMAL, "Can't get IRQ %d!\n", dev->irq); arc_printk(D_NORMAL, dev, "Can't get IRQ %d!\n", dev->irq);
return -ENODEV; return -ENODEV;
} }
shmem = dev->mem_start; shmem = dev->mem_start;
writeb(TESTvalue, p); arcnet_writeb(TESTvalue, p, COM9026_REG_W_INTMASK);
writeb(dev->dev_addr[0], p + 1); /* actually the node ID */ arcnet_writeb(TESTvalue, p, COM9026_REG_W_COMMAND);
/* actually the station/node ID */
/* find the real shared memory start/end points, including mirrors */ /* find the real shared memory start/end points, including mirrors */
...@@ -174,7 +155,7 @@ static int __init arcrimi_found(struct net_device *dev) ...@@ -174,7 +155,7 @@ static int __init arcrimi_found(struct net_device *dev)
* 2k (or there are no mirrors at all) but on some, it's 4k. * 2k (or there are no mirrors at all) but on some, it's 4k.
*/ */
mirror_size = MIRROR_SIZE; mirror_size = MIRROR_SIZE;
if (readb(p) == TESTvalue && if (arcnet_readb(p, COM9026_REG_R_STATUS) == TESTvalue &&
check_mirror(shmem - MIRROR_SIZE, MIRROR_SIZE) == 0 && check_mirror(shmem - MIRROR_SIZE, MIRROR_SIZE) == 0 &&
check_mirror(shmem - 2 * MIRROR_SIZE, MIRROR_SIZE) == 1) check_mirror(shmem - 2 * MIRROR_SIZE, MIRROR_SIZE) == 1)
mirror_size = 2 * MIRROR_SIZE; mirror_size = 2 * MIRROR_SIZE;
...@@ -204,8 +185,7 @@ static int __init arcrimi_found(struct net_device *dev) ...@@ -204,8 +185,7 @@ static int __init arcrimi_found(struct net_device *dev)
lp->hw.copy_to_card = arcrimi_copy_to_card; lp->hw.copy_to_card = arcrimi_copy_to_card;
lp->hw.copy_from_card = arcrimi_copy_from_card; lp->hw.copy_from_card = arcrimi_copy_from_card;
/* /* re-reserve the memory region - arcrimi_probe() alloced this reqion
* re-reserve the memory region - arcrimi_probe() alloced this reqion
* but didn't know the real size. Free that region and then re-get * but didn't know the real size. Free that region and then re-get
* with the correct size. There is a VERY slim chance this could * with the correct size. There is a VERY slim chance this could
* fail. * fail.
...@@ -215,24 +195,25 @@ static int __init arcrimi_found(struct net_device *dev) ...@@ -215,24 +195,25 @@ static int __init arcrimi_found(struct net_device *dev)
if (!request_mem_region(dev->mem_start, if (!request_mem_region(dev->mem_start,
dev->mem_end - dev->mem_start + 1, dev->mem_end - dev->mem_start + 1,
"arcnet (90xx)")) { "arcnet (90xx)")) {
BUGMSG(D_NORMAL, "Card memory already allocated\n"); arc_printk(D_NORMAL, dev, "Card memory already allocated\n");
goto err_free_irq; goto err_free_irq;
} }
lp->mem_start = ioremap(dev->mem_start, dev->mem_end - dev->mem_start + 1); lp->mem_start = ioremap(dev->mem_start,
dev->mem_end - dev->mem_start + 1);
if (!lp->mem_start) { if (!lp->mem_start) {
BUGMSG(D_NORMAL, "Can't remap device memory!\n"); arc_printk(D_NORMAL, dev, "Can't remap device memory!\n");
goto err_release_mem; goto err_release_mem;
} }
/* get and check the station ID from offset 1 in shmem */ /* get and check the station ID from offset 1 in shmem */
dev->dev_addr[0] = readb(lp->mem_start + 1); dev->dev_addr[0] = arcnet_readb(lp->mem_start, COM9026_REG_R_STATION);
BUGMSG(D_NORMAL, "ARCnet RIM I: station %02Xh found at IRQ %d, " arc_printk(D_NORMAL, dev, "ARCnet RIM I: station %02Xh found at IRQ %d, ShMem %lXh (%ld*%d bytes)\n",
"ShMem %lXh (%ld*%d bytes).\n", dev->dev_addr[0],
dev->dev_addr[0], dev->irq, dev->mem_start,
dev->irq, dev->mem_start, (dev->mem_end - dev->mem_start + 1) / mirror_size,
(dev->mem_end - dev->mem_start + 1) / mirror_size, mirror_size); mirror_size);
err = register_netdev(dev); err = register_netdev(dev);
if (err) if (err)
...@@ -249,9 +230,7 @@ static int __init arcrimi_found(struct net_device *dev) ...@@ -249,9 +230,7 @@ static int __init arcrimi_found(struct net_device *dev)
return -EIO; return -EIO;
} }
/* Do a hardware reset on the card, and set up necessary registers.
/*
* Do a hardware reset on the card, and set up necessary registers.
* *
* This should be called as little as possible, because it disrupts the * This should be called as little as possible, because it disrupts the
* token on the network (causes a RECON) and requires a significant delay. * token on the network (causes a RECON) and requires a significant delay.
...@@ -263,17 +242,19 @@ static int arcrimi_reset(struct net_device *dev, int really_reset) ...@@ -263,17 +242,19 @@ static int arcrimi_reset(struct net_device *dev, int really_reset)
struct arcnet_local *lp = netdev_priv(dev); struct arcnet_local *lp = netdev_priv(dev);
void __iomem *ioaddr = lp->mem_start + 0x800; void __iomem *ioaddr = lp->mem_start + 0x800;
BUGMSG(D_INIT, "Resetting %s (status=%02Xh)\n", dev->name, ASTATUS()); arc_printk(D_INIT, dev, "Resetting %s (status=%02Xh)\n",
dev->name, arcnet_readb(ioaddr, COM9026_REG_R_STATUS));
if (really_reset) { if (really_reset) {
writeb(TESTvalue, ioaddr - 0x800); /* fake reset */ arcnet_writeb(TESTvalue, ioaddr, -0x800); /* fake reset */
return 0; return 0;
} }
ACOMMAND(CFLAGScmd | RESETclear); /* clear flags & end reset */ /* clear flags & end reset */
ACOMMAND(CFLAGScmd | CONFIGclear); arcnet_writeb(CFLAGScmd | RESETclear, ioaddr, COM9026_REG_W_COMMAND);
arcnet_writeb(CFLAGScmd | CONFIGclear, ioaddr, COM9026_REG_W_COMMAND);
/* enable extended (512-byte) packets */ /* enable extended (512-byte) packets */
ACOMMAND(CONFIGcmd | EXTconf); arcnet_writeb(CONFIGcmd | EXTconf, ioaddr, COM9026_REG_W_COMMAND);
/* done! return success. */ /* done! return success. */
return 0; return 0;
...@@ -284,7 +265,7 @@ static void arcrimi_setmask(struct net_device *dev, int mask) ...@@ -284,7 +265,7 @@ static void arcrimi_setmask(struct net_device *dev, int mask)
struct arcnet_local *lp = netdev_priv(dev); struct arcnet_local *lp = netdev_priv(dev);
void __iomem *ioaddr = lp->mem_start + 0x800; void __iomem *ioaddr = lp->mem_start + 0x800;
AINTMASK(mask); arcnet_writeb(mask, ioaddr, COM9026_REG_W_INTMASK);
} }
static int arcrimi_status(struct net_device *dev) static int arcrimi_status(struct net_device *dev)
...@@ -292,7 +273,7 @@ static int arcrimi_status(struct net_device *dev) ...@@ -292,7 +273,7 @@ static int arcrimi_status(struct net_device *dev)
struct arcnet_local *lp = netdev_priv(dev); struct arcnet_local *lp = netdev_priv(dev);
void __iomem *ioaddr = lp->mem_start + 0x800; void __iomem *ioaddr = lp->mem_start + 0x800;
return ASTATUS(); return arcnet_readb(ioaddr, COM9026_REG_R_STATUS);
} }
static void arcrimi_command(struct net_device *dev, int cmd) static void arcrimi_command(struct net_device *dev, int cmd)
...@@ -300,7 +281,7 @@ static void arcrimi_command(struct net_device *dev, int cmd) ...@@ -300,7 +281,7 @@ static void arcrimi_command(struct net_device *dev, int cmd)
struct arcnet_local *lp = netdev_priv(dev); struct arcnet_local *lp = netdev_priv(dev);
void __iomem *ioaddr = lp->mem_start + 0x800; void __iomem *ioaddr = lp->mem_start + 0x800;
ACOMMAND(cmd); arcnet_writeb(cmd, ioaddr, COM9026_REG_W_COMMAND);
} }
static void arcrimi_copy_to_card(struct net_device *dev, int bufnum, int offset, static void arcrimi_copy_to_card(struct net_device *dev, int bufnum, int offset,
...@@ -308,16 +289,17 @@ static void arcrimi_copy_to_card(struct net_device *dev, int bufnum, int offset, ...@@ -308,16 +289,17 @@ static void arcrimi_copy_to_card(struct net_device *dev, int bufnum, int offset,
{ {
struct arcnet_local *lp = netdev_priv(dev); struct arcnet_local *lp = netdev_priv(dev);
void __iomem *memaddr = lp->mem_start + 0x800 + bufnum * 512 + offset; void __iomem *memaddr = lp->mem_start + 0x800 + bufnum * 512 + offset;
TIME("memcpy_toio", count, memcpy_toio(memaddr, buf, count));
}
TIME(dev, "memcpy_toio", count, memcpy_toio(memaddr, buf, count));
}
static void arcrimi_copy_from_card(struct net_device *dev, int bufnum, int offset, static void arcrimi_copy_from_card(struct net_device *dev, int bufnum,
void *buf, int count) int offset, void *buf, int count)
{ {
struct arcnet_local *lp = netdev_priv(dev); struct arcnet_local *lp = netdev_priv(dev);
void __iomem *memaddr = lp->mem_start + 0x800 + bufnum * 512 + offset; void __iomem *memaddr = lp->mem_start + 0x800 + bufnum * 512 + offset;
TIME("memcpy_fromio", count, memcpy_fromio(buf, memaddr, count));
TIME(dev, "memcpy_fromio", count, memcpy_fromio(buf, memaddr, count));
} }
static int node; static int node;
...@@ -374,12 +356,13 @@ static void __exit arc_rimi_exit(void) ...@@ -374,12 +356,13 @@ static void __exit arc_rimi_exit(void)
static int __init arcrimi_setup(char *s) static int __init arcrimi_setup(char *s)
{ {
int ints[8]; int ints[8];
s = get_options(s, 8, ints); s = get_options(s, 8, ints);
if (!ints[0]) if (!ints[0])
return 1; return 1;
switch (ints[0]) { switch (ints[0]) {
default: /* ERROR */ default: /* ERROR */
printk("arcrimi: Too many arguments.\n"); pr_err("Too many arguments\n");
case 3: /* Node ID */ case 3: /* Node ID */
node = ints[3]; node = ints[3];
case 2: /* IRQ */ case 2: /* IRQ */
......
...@@ -34,7 +34,6 @@ ...@@ -34,7 +34,6 @@
*/ */
#define RECON_THRESHOLD 30 #define RECON_THRESHOLD 30
/* /*
* Define this to the minimum "timeout" value. If a transmit takes longer * Define this to the minimum "timeout" value. If a transmit takes longer
* than TX_TIMEOUT jiffies, Linux will abort the TX and retry. On a large * than TX_TIMEOUT jiffies, Linux will abort the TX and retry. On a large
...@@ -44,14 +43,12 @@ ...@@ -44,14 +43,12 @@
*/ */
#define TX_TIMEOUT (HZ * 200 / 1000) #define TX_TIMEOUT (HZ * 200 / 1000)
/* Display warnings about the driver being an ALPHA version. */ /* Display warnings about the driver being an ALPHA version. */
#undef ALPHA_WARNING #undef ALPHA_WARNING
/* /*
* Debugging bitflags: each option can be enabled individually. * Debugging bitflags: each option can be enabled individually.
* *
* Note: only debug flags included in the ARCNET_DEBUG_MAX define will * Note: only debug flags included in the ARCNET_DEBUG_MAX define will
* actually be available. GCC will (at least, GCC 2.7.0 will) notice * actually be available. GCC will (at least, GCC 2.7.0 will) notice
* lines using a BUGLVL not in ARCNET_DEBUG_MAX and automatically optimize * lines using a BUGLVL not in ARCNET_DEBUG_MAX and automatically optimize
...@@ -77,35 +74,47 @@ ...@@ -77,35 +74,47 @@
#endif #endif
#ifndef ARCNET_DEBUG #ifndef ARCNET_DEBUG
#define ARCNET_DEBUG (D_NORMAL|D_EXTRA) #define ARCNET_DEBUG (D_NORMAL | D_EXTRA)
#endif #endif
extern int arcnet_debug; extern int arcnet_debug;
#define BUGLVL(x) ((x) & ARCNET_DEBUG_MAX & arcnet_debug)
/* macros to simplify debug checking */ /* macros to simplify debug checking */
#define BUGLVL(x) if ((ARCNET_DEBUG_MAX)&arcnet_debug&(x)) #define arc_printk(x, dev, fmt, ...) \
#define BUGMSG2(x,msg,args...) do { BUGLVL(x) printk(msg, ## args); } while (0) do { \
#define BUGMSG(x,msg,args...) \ if (BUGLVL(x)) { \
BUGMSG2(x, "%s%6s: " msg, \ if ((x) == D_NORMAL) \
x==D_NORMAL ? KERN_WARNING \ netdev_warn(dev, fmt, ##__VA_ARGS__); \
: x < D_DURING ? KERN_INFO : KERN_DEBUG, \ else if ((x) < D_DURING) \
dev->name , ## args) netdev_info(dev, fmt, ##__VA_ARGS__); \
else \
netdev_dbg(dev, fmt, ##__VA_ARGS__); \
} \
} while (0)
#define arc_cont(x, fmt, ...) \
do { \
if (BUGLVL(x)) \
pr_cont(fmt, ##__VA_ARGS__); \
} while (0)
/* see how long a function call takes to run, expressed in CPU cycles */ /* see how long a function call takes to run, expressed in CPU cycles */
#define TIME(name, bytes, call) BUGLVL(D_TIMING) { \ #define TIME(dev, name, bytes, call) \
unsigned long _x, _y; \ do { \
_x = get_cycles(); \ if (BUGLVL(D_TIMING)) { \
call; \ unsigned long _x, _y; \
_y = get_cycles(); \ _x = get_cycles(); \
BUGMSG(D_TIMING, \ call; \
"%s: %d bytes in %lu cycles == " \ _y = get_cycles(); \
"%lu Kbytes/100Mcycle\n",\ arc_printk(D_TIMING, dev, \
name, bytes, _y - _x, \ "%s: %d bytes in %lu cycles == %lu Kbytes/100Mcycle\n", \
100000000 / 1024 * bytes / (_y - _x + 1));\ name, bytes, _y - _x, \
} \ 100000000 / 1024 * bytes / (_y - _x + 1)); \
else { \ } else { \
call;\ call; \
} } \
} while (0)
/* /*
* Time needed to reset the card - in ms (milliseconds). This works on my * Time needed to reset the card - in ms (milliseconds). This works on my
...@@ -155,6 +164,7 @@ extern int arcnet_debug; ...@@ -155,6 +164,7 @@ extern int arcnet_debug;
#define CONFIGcmd 0x05 /* define configuration */ #define CONFIGcmd 0x05 /* define configuration */
#define CFLAGScmd 0x06 /* clear flags */ #define CFLAGScmd 0x06 /* clear flags */
#define TESTcmd 0x07 /* load test flags */ #define TESTcmd 0x07 /* load test flags */
#define STARTIOcmd 0x18 /* start internal operation */
/* flags for "clear flags" command */ /* flags for "clear flags" command */
#define RESETclear 0x08 /* power-on-reset */ #define RESETclear 0x08 /* power-on-reset */
...@@ -182,29 +192,27 @@ extern int arcnet_debug; ...@@ -182,29 +192,27 @@ extern int arcnet_debug;
#define ARC_CAN_10MBIT 2 /* card uses COM20022, supporting 10MBit, #define ARC_CAN_10MBIT 2 /* card uses COM20022, supporting 10MBit,
but default is 2.5MBit. */ but default is 2.5MBit. */
/* information needed to define an encapsulation driver */ /* information needed to define an encapsulation driver */
struct ArcProto { struct ArcProto {
char suffix; /* a for RFC1201, e for ether-encap, etc. */ char suffix; /* a for RFC1201, e for ether-encap, etc. */
int mtu; /* largest possible packet */ int mtu; /* largest possible packet */
int is_ip; /* This is a ip plugin - not a raw thing */ int is_ip; /* This is a ip plugin - not a raw thing */
void (*rx) (struct net_device * dev, int bufnum, void (*rx)(struct net_device *dev, int bufnum,
struct archdr * pkthdr, int length); struct archdr *pkthdr, int length);
int (*build_header) (struct sk_buff * skb, struct net_device *dev, int (*build_header)(struct sk_buff *skb, struct net_device *dev,
unsigned short ethproto, uint8_t daddr); unsigned short ethproto, uint8_t daddr);
/* these functions return '1' if the skb can now be freed */ /* these functions return '1' if the skb can now be freed */
int (*prepare_tx) (struct net_device * dev, struct archdr * pkt, int length, int (*prepare_tx)(struct net_device *dev, struct archdr *pkt,
int bufnum); int length, int bufnum);
int (*continue_tx) (struct net_device * dev, int bufnum); int (*continue_tx)(struct net_device *dev, int bufnum);
int (*ack_tx) (struct net_device * dev, int acked); int (*ack_tx)(struct net_device *dev, int acked);
}; };
extern struct ArcProto *arc_proto_map[256], *arc_proto_default, extern struct ArcProto *arc_proto_map[256], *arc_proto_default,
*arc_bcast_proto, *arc_raw_proto; *arc_bcast_proto, *arc_raw_proto;
/* /*
* "Incoming" is information needed for each address that could be sending * "Incoming" is information needed for each address that could be sending
* to us. Mostly for partially-received split packets. * to us. Mostly for partially-received split packets.
...@@ -216,7 +224,6 @@ struct Incoming { ...@@ -216,7 +224,6 @@ struct Incoming {
numpackets; /* number of packets in split */ numpackets; /* number of packets in split */
}; };
/* only needed for RFC1201 */ /* only needed for RFC1201 */
struct Outgoing { struct Outgoing {
struct ArcProto *proto; /* protocol driver that owns this: struct ArcProto *proto; /* protocol driver that owns this:
...@@ -230,7 +237,6 @@ struct Outgoing { ...@@ -230,7 +237,6 @@ struct Outgoing {
numsegs; /* number of segments */ numsegs; /* number of segments */
}; };
struct arcnet_local { struct arcnet_local {
uint8_t config, /* current value of CONFIG register */ uint8_t config, /* current value of CONFIG register */
timeout, /* Extended timeout for COM20020 */ timeout, /* Extended timeout for COM20020 */
...@@ -251,7 +257,6 @@ struct arcnet_local { ...@@ -251,7 +257,6 @@ struct arcnet_local {
char *card_name; /* card ident string */ char *card_name; /* card ident string */
int card_flags; /* special card features */ int card_flags; /* special card features */
/* On preemtive and SMB a lock is needed */ /* On preemtive and SMB a lock is needed */
spinlock_t lock; spinlock_t lock;
...@@ -263,13 +268,13 @@ struct arcnet_local { ...@@ -263,13 +268,13 @@ struct arcnet_local {
* situations in which we (for example) want to pre-load a transmit * situations in which we (for example) want to pre-load a transmit
* buffer, or start receiving while we copy a received packet to * buffer, or start receiving while we copy a received packet to
* memory. * memory.
* *
* The rules: only the interrupt handler is allowed to _add_ buffers to * The rules: only the interrupt handler is allowed to _add_ buffers to
* the queue; thus, this doesn't require a lock. Both the interrupt * the queue; thus, this doesn't require a lock. Both the interrupt
* handler and the transmit function will want to _remove_ buffers, so * handler and the transmit function will want to _remove_ buffers, so
* we need to handle the situation where they try to do it at the same * we need to handle the situation where they try to do it at the same
* time. * time.
* *
* If next_buf == first_free_buf, the queue is empty. Since there are * If next_buf == first_free_buf, the queue is empty. Since there are
* only four possible buffers, the queue should never be full. * only four possible buffers, the queue should never be full.
*/ */
...@@ -298,34 +303,29 @@ struct arcnet_local { ...@@ -298,34 +303,29 @@ struct arcnet_local {
/* hardware-specific functions */ /* hardware-specific functions */
struct { struct {
struct module *owner; struct module *owner;
void (*command) (struct net_device * dev, int cmd); void (*command)(struct net_device *dev, int cmd);
int (*status) (struct net_device * dev); int (*status)(struct net_device *dev);
void (*intmask) (struct net_device * dev, int mask); void (*intmask)(struct net_device *dev, int mask);
int (*reset) (struct net_device * dev, int really_reset); int (*reset)(struct net_device *dev, int really_reset);
void (*open) (struct net_device * dev); void (*open)(struct net_device *dev);
void (*close) (struct net_device * dev); void (*close)(struct net_device *dev);
void (*copy_to_card) (struct net_device * dev, int bufnum, int offset, void (*copy_to_card)(struct net_device *dev, int bufnum,
void *buf, int count); int offset, void *buf, int count);
void (*copy_from_card) (struct net_device * dev, int bufnum, int offset, void (*copy_from_card)(struct net_device *dev, int bufnum,
void *buf, int count); int offset, void *buf, int count);
} hw; } hw;
void __iomem *mem_start; /* pointer to ioremap'ed MMIO */ void __iomem *mem_start; /* pointer to ioremap'ed MMIO */
}; };
#define ARCRESET(x) (lp->hw.reset(dev, (x)))
#define ACOMMAND(x) (lp->hw.command(dev, (x)))
#define ASTATUS() (lp->hw.status(dev))
#define AINTMASK(x) (lp->hw.intmask(dev, (x)))
#if ARCNET_DEBUG_MAX & D_SKB #if ARCNET_DEBUG_MAX & D_SKB
void arcnet_dump_skb(struct net_device *dev, struct sk_buff *skb, char *desc); void arcnet_dump_skb(struct net_device *dev, struct sk_buff *skb, char *desc);
#else #else
#define arcnet_dump_skb(dev,skb,desc) ; static inline
void arcnet_dump_skb(struct net_device *dev, struct sk_buff *skb, char *desc)
{
}
#endif #endif
void arcnet_unregister_proto(struct ArcProto *proto); void arcnet_unregister_proto(struct ArcProto *proto);
...@@ -335,8 +335,34 @@ struct net_device *alloc_arcdev(const char *name); ...@@ -335,8 +335,34 @@ struct net_device *alloc_arcdev(const char *name);
int arcnet_open(struct net_device *dev); int arcnet_open(struct net_device *dev);
int arcnet_close(struct net_device *dev); int arcnet_close(struct net_device *dev);
netdev_tx_t arcnet_send_packet(struct sk_buff *skb, netdev_tx_t arcnet_send_packet(struct sk_buff *skb,
struct net_device *dev); struct net_device *dev);
void arcnet_timeout(struct net_device *dev); void arcnet_timeout(struct net_device *dev);
/* I/O equivalents */
#ifdef CONFIG_SA1100_CT6001
#define BUS_ALIGN 2 /* 8 bit device on a 16 bit bus - needs padding */
#else
#define BUS_ALIGN 1
#endif
/* addr and offset allow register like names to define the actual IO address.
* A configuration option multiplies the offset for alignment.
*/
#define arcnet_inb(addr, offset) \
inb((addr) + BUS_ALIGN * (offset))
#define arcnet_outb(value, addr, offset) \
outb(value, (addr) + BUS_ALIGN * (offset))
#define arcnet_insb(addr, offset, buffer, count) \
insb((addr) + BUS_ALIGN * (offset), buffer, count)
#define arcnet_outsb(addr, offset, buffer, count) \
outsb((addr) + BUS_ALIGN * (offset), buffer, count)
#define arcnet_readb(addr, offset) \
readb((addr) + (offset))
#define arcnet_writeb(value, addr, offset) \
writeb(value, (addr) + (offset))
#endif /* __KERNEL__ */ #endif /* __KERNEL__ */
#endif /* _LINUX_ARCDEVICE_H */ #endif /* _LINUX_ARCDEVICE_H */
/* /*
* Linux ARCnet driver - device-independent routines * Linux ARCnet driver - device-independent routines
* *
* Written 1997 by David Woodhouse. * Written 1997 by David Woodhouse.
* Written 1994-1999 by Avery Pennarun. * Written 1994-1999 by Avery Pennarun.
* Written 1999-2000 by Martin Mares <mj@ucw.cz>. * Written 1999-2000 by Martin Mares <mj@ucw.cz>.
...@@ -20,12 +20,12 @@ ...@@ -20,12 +20,12 @@
* modified by SRC, incorporated herein by reference. * modified by SRC, incorporated herein by reference.
* *
* ********************** * **********************
* *
* The change log is now in a file called ChangeLog in this directory. * The change log is now in a file called ChangeLog in this directory.
* *
* Sources: * Sources:
* - Crynwr arcnet.com/arcether.com packet drivers. * - Crynwr arcnet.com/arcether.com packet drivers.
* - arcnet.c v0.00 dated 1/1/94 and apparently by * - arcnet.c v0.00 dated 1/1/94 and apparently by
* Donald Becker - it didn't work :) * Donald Becker - it didn't work :)
* - skeleton.c v0.05 dated 11/16/93 by Donald Becker * - skeleton.c v0.05 dated 11/16/93 by Donald Becker
* (from Linux Kernel 1.1.45) * (from Linux Kernel 1.1.45)
...@@ -41,7 +41,7 @@ ...@@ -41,7 +41,7 @@
* <jojo@repas.de> * <jojo@repas.de>
*/ */
#define VERSION "arcnet: v3.94 BETA 2007/02/08 - by Avery Pennarun et al.\n" #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#include <linux/module.h> #include <linux/module.h>
#include <linux/types.h> #include <linux/types.h>
...@@ -50,9 +50,11 @@ ...@@ -50,9 +50,11 @@
#include <linux/if_arp.h> #include <linux/if_arp.h>
#include <net/arp.h> #include <net/arp.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/arcdevice.h>
#include <linux/jiffies.h> #include <linux/jiffies.h>
#include "arcdevice.h"
#include "com9026.h"
/* "do nothing" functions for protocol drivers */ /* "do nothing" functions for protocol drivers */
static void null_rx(struct net_device *dev, int bufnum, static void null_rx(struct net_device *dev, int bufnum,
struct archdr *pkthdr, int length); struct archdr *pkthdr, int length);
...@@ -63,17 +65,24 @@ static int null_prepare_tx(struct net_device *dev, struct archdr *pkt, ...@@ -63,17 +65,24 @@ static int null_prepare_tx(struct net_device *dev, struct archdr *pkt,
static void arcnet_rx(struct net_device *dev, int bufnum); static void arcnet_rx(struct net_device *dev, int bufnum);
/* /* one ArcProto per possible proto ID. None of the elements of
* one ArcProto per possible proto ID. None of the elements of
* arc_proto_map are allowed to be NULL; they will get set to * 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 * 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. * to set it to NULL, set it to &arc_proto_null instead.
*/ */
struct ArcProto *arc_proto_map[256], *arc_proto_default, struct ArcProto *arc_proto_map[256];
*arc_bcast_proto, *arc_raw_proto; EXPORT_SYMBOL(arc_proto_map);
static struct ArcProto arc_proto_null = 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);
static struct ArcProto arc_proto_null = {
.suffix = '?', .suffix = '?',
.mtu = XMTU, .mtu = XMTU,
.is_ip = 0, .is_ip = 0,
...@@ -86,19 +95,7 @@ static struct ArcProto arc_proto_null = ...@@ -86,19 +95,7 @@ static struct ArcProto arc_proto_null =
/* Exported function prototypes */ /* Exported function prototypes */
int arcnet_debug = ARCNET_DEBUG; int arcnet_debug = ARCNET_DEBUG;
EXPORT_SYMBOL(arc_proto_map);
EXPORT_SYMBOL(arc_proto_default);
EXPORT_SYMBOL(arc_bcast_proto);
EXPORT_SYMBOL(arc_raw_proto);
EXPORT_SYMBOL(arcnet_unregister_proto);
EXPORT_SYMBOL(arcnet_debug); EXPORT_SYMBOL(arcnet_debug);
EXPORT_SYMBOL(alloc_arcdev);
EXPORT_SYMBOL(arcnet_interrupt);
EXPORT_SYMBOL(arcnet_open);
EXPORT_SYMBOL(arcnet_close);
EXPORT_SYMBOL(arcnet_send_packet);
EXPORT_SYMBOL(arcnet_timeout);
/* Internal function prototypes */ /* Internal function prototypes */
static int arcnet_header(struct sk_buff *skb, struct net_device *dev, static int arcnet_header(struct sk_buff *skb, struct net_device *dev,
...@@ -116,29 +113,20 @@ static int __init arcnet_init(void) ...@@ -116,29 +113,20 @@ static int __init arcnet_init(void)
arcnet_debug = debug; arcnet_debug = debug;
printk("arcnet loaded.\n"); pr_info("arcnet loaded\n");
#ifdef ALPHA_WARNING
BUGLVL(D_EXTRA) {
printk("arcnet: ***\n"
"arcnet: * Read arcnet.txt for important release notes!\n"
"arcnet: *\n"
"arcnet: * This is an ALPHA version! (Last stable release: v3.02) E-mail\n"
"arcnet: * me if you have any questions, comments, or bug reports.\n"
"arcnet: ***\n");
}
#endif
/* initialize the protocol map */ /* initialize the protocol map */
arc_raw_proto = arc_proto_default = arc_bcast_proto = &arc_proto_null; arc_raw_proto = arc_proto_default = arc_bcast_proto = &arc_proto_null;
for (count = 0; count < 256; count++) for (count = 0; count < 256; count++)
arc_proto_map[count] = arc_proto_default; arc_proto_map[count] = arc_proto_default;
BUGLVL(D_DURING) if (BUGLVL(D_DURING))
printk("arcnet: struct sizes: %Zd %Zd %Zd %Zd %Zd\n", pr_info("struct sizes: %Zd %Zd %Zd %Zd %Zd\n",
sizeof(struct arc_hardware), sizeof(struct arc_rfc1201), sizeof(struct arc_hardware),
sizeof(struct arc_rfc1051), sizeof(struct arc_eth_encap), sizeof(struct arc_rfc1201),
sizeof(struct archdr)); sizeof(struct arc_rfc1051),
sizeof(struct arc_eth_encap),
sizeof(struct archdr));
return 0; return 0;
} }
...@@ -150,9 +138,7 @@ static void __exit arcnet_exit(void) ...@@ -150,9 +138,7 @@ static void __exit arcnet_exit(void)
module_init(arcnet_init); module_init(arcnet_init);
module_exit(arcnet_exit); module_exit(arcnet_exit);
/* /* Dump the contents of an sk_buff */
* Dump the contents of an sk_buff
*/
#if ARCNET_DEBUG_MAX & D_SKB #if ARCNET_DEBUG_MAX & D_SKB
void arcnet_dump_skb(struct net_device *dev, void arcnet_dump_skb(struct net_device *dev,
struct sk_buff *skb, char *desc) struct sk_buff *skb, char *desc)
...@@ -164,14 +150,10 @@ void arcnet_dump_skb(struct net_device *dev, ...@@ -164,14 +150,10 @@ void arcnet_dump_skb(struct net_device *dev,
print_hex_dump(KERN_DEBUG, hdr, DUMP_PREFIX_OFFSET, print_hex_dump(KERN_DEBUG, hdr, DUMP_PREFIX_OFFSET,
16, 1, skb->data, skb->len, true); 16, 1, skb->data, skb->len, true);
} }
EXPORT_SYMBOL(arcnet_dump_skb); EXPORT_SYMBOL(arcnet_dump_skb);
#endif #endif
/* Dump the contents of an ARCnet buffer */
/*
* Dump the contents of an ARCnet buffer
*/
#if (ARCNET_DEBUG_MAX & (D_RX | D_TX)) #if (ARCNET_DEBUG_MAX & (D_RX | D_TX))
static void arcnet_dump_packet(struct net_device *dev, int bufnum, static void arcnet_dump_packet(struct net_device *dev, int bufnum,
char *desc, int take_arcnet_lock) char *desc, int take_arcnet_lock)
...@@ -183,12 +165,13 @@ static void arcnet_dump_packet(struct net_device *dev, int bufnum, ...@@ -183,12 +165,13 @@ static void arcnet_dump_packet(struct net_device *dev, int bufnum,
char hdr[32]; char hdr[32];
/* hw.copy_from_card expects IRQ context so take the IRQ lock /* hw.copy_from_card expects IRQ context so take the IRQ lock
to keep it single threaded */ * to keep it single threaded
if(take_arcnet_lock) */
if (take_arcnet_lock)
spin_lock_irqsave(&lp->lock, flags); spin_lock_irqsave(&lp->lock, flags);
lp->hw.copy_from_card(dev, bufnum, 0, buf, 512); lp->hw.copy_from_card(dev, bufnum, 0, buf, 512);
if(take_arcnet_lock) if (take_arcnet_lock)
spin_unlock_irqrestore(&lp->lock, flags); spin_unlock_irqrestore(&lp->lock, flags);
/* if the offset[0] byte is nonzero, this is a 256-byte packet */ /* if the offset[0] byte is nonzero, this is a 256-byte packet */
...@@ -202,13 +185,11 @@ static void arcnet_dump_packet(struct net_device *dev, int bufnum, ...@@ -202,13 +185,11 @@ static void arcnet_dump_packet(struct net_device *dev, int bufnum,
#else #else
#define arcnet_dump_packet(dev, bufnum, desc,take_arcnet_lock) do { } while (0) #define arcnet_dump_packet(dev, bufnum, desc, take_arcnet_lock) do { } while (0)
#endif #endif
/* Unregister a protocol driver from the arc_proto_map. Protocol drivers
/*
* Unregister a protocol driver from the arc_proto_map. Protocol drivers
* are responsible for registering themselves, but the unregister routine * are responsible for registering themselves, but the unregister routine
* is pretty generic so we'll do it here. * is pretty generic so we'll do it here.
*/ */
...@@ -228,12 +209,11 @@ void arcnet_unregister_proto(struct ArcProto *proto) ...@@ -228,12 +209,11 @@ void arcnet_unregister_proto(struct ArcProto *proto)
arc_proto_map[count] = arc_proto_default; arc_proto_map[count] = arc_proto_default;
} }
} }
EXPORT_SYMBOL(arcnet_unregister_proto);
/* Add a buffer to the queue. Only the interrupt handler is allowed to do
/*
* Add a buffer to the queue. Only the interrupt handler is allowed to do
* this, unless interrupts are disabled. * this, unless interrupts are disabled.
* *
* Note: we don't check for a full queue, since there aren't enough buffers * Note: we don't check for a full queue, since there aren't enough buffers
* to more than fill it. * to more than fill it.
*/ */
...@@ -245,19 +225,17 @@ static void release_arcbuf(struct net_device *dev, int bufnum) ...@@ -245,19 +225,17 @@ static void release_arcbuf(struct net_device *dev, int bufnum)
lp->buf_queue[lp->first_free_buf++] = bufnum; lp->buf_queue[lp->first_free_buf++] = bufnum;
lp->first_free_buf %= 5; lp->first_free_buf %= 5;
BUGLVL(D_DURING) { if (BUGLVL(D_DURING)) {
BUGMSG(D_DURING, "release_arcbuf: freed #%d; buffer queue is now: ", arc_printk(D_DURING, dev, "release_arcbuf: freed #%d; buffer queue is now: ",
bufnum); bufnum);
for (i = lp->next_buf; i != lp->first_free_buf; i = (i+1) % 5) for (i = lp->next_buf; i != lp->first_free_buf; i = (i + 1) % 5)
BUGMSG2(D_DURING, "#%d ", lp->buf_queue[i]); arc_cont(D_DURING, "#%d ", lp->buf_queue[i]);
BUGMSG2(D_DURING, "\n"); arc_cont(D_DURING, "\n");
} }
} }
/* Get a buffer from the queue.
/* * If this returns -1, there are no buffers available.
* Get a buffer from the queue. If this returns -1, there are no buffers
* available.
*/ */
static int get_arcbuf(struct net_device *dev) static int get_arcbuf(struct net_device *dev)
{ {
...@@ -266,34 +244,32 @@ static int get_arcbuf(struct net_device *dev) ...@@ -266,34 +244,32 @@ static int get_arcbuf(struct net_device *dev)
if (!atomic_dec_and_test(&lp->buf_lock)) { if (!atomic_dec_and_test(&lp->buf_lock)) {
/* already in this function */ /* already in this function */
BUGMSG(D_NORMAL, "get_arcbuf: overlap (%d)!\n", arc_printk(D_NORMAL, dev, "get_arcbuf: overlap (%d)!\n",
lp->buf_lock.counter); lp->buf_lock.counter);
} } else { /* we can continue */
else { /* we can continue */
if (lp->next_buf >= 5) if (lp->next_buf >= 5)
lp->next_buf -= 5; lp->next_buf -= 5;
if (lp->next_buf == lp->first_free_buf) if (lp->next_buf == lp->first_free_buf) {
BUGMSG(D_NORMAL, "get_arcbuf: BUG: no buffers are available??\n"); arc_printk(D_NORMAL, dev, "get_arcbuf: BUG: no buffers are available??\n");
else { } else {
buf = lp->buf_queue[lp->next_buf++]; buf = lp->buf_queue[lp->next_buf++];
lp->next_buf %= 5; lp->next_buf %= 5;
} }
} }
if (BUGLVL(D_DURING)) {
BUGLVL(D_DURING) { arc_printk(D_DURING, dev, "get_arcbuf: got #%d; buffer queue is now: ",
BUGMSG(D_DURING, "get_arcbuf: got #%d; buffer queue is now: ", buf); buf);
for (i = lp->next_buf; i != lp->first_free_buf; i = (i+1) % 5) for (i = lp->next_buf; i != lp->first_free_buf; i = (i + 1) % 5)
BUGMSG2(D_DURING, "#%d ", lp->buf_queue[i]); arc_cont(D_DURING, "#%d ", lp->buf_queue[i]);
BUGMSG2(D_DURING, "\n"); arc_cont(D_DURING, "\n");
} }
atomic_inc(&lp->buf_lock); atomic_inc(&lp->buf_lock);
return buf; return buf;
} }
static int choose_mtu(void) static int choose_mtu(void)
{ {
int count, mtu = 65535; int count, mtu = 65535;
...@@ -336,7 +312,6 @@ static void arcdev_setup(struct net_device *dev) ...@@ -336,7 +312,6 @@ static void arcdev_setup(struct net_device *dev)
/* New-style flags. */ /* New-style flags. */
dev->flags = IFF_BROADCAST; dev->flags = IFF_BROADCAST;
} }
struct net_device *alloc_arcdev(const char *name) struct net_device *alloc_arcdev(const char *name)
...@@ -346,16 +321,17 @@ struct net_device *alloc_arcdev(const char *name) ...@@ -346,16 +321,17 @@ struct net_device *alloc_arcdev(const char *name)
dev = alloc_netdev(sizeof(struct arcnet_local), dev = alloc_netdev(sizeof(struct arcnet_local),
name && *name ? name : "arc%d", NET_NAME_UNKNOWN, name && *name ? name : "arc%d", NET_NAME_UNKNOWN,
arcdev_setup); arcdev_setup);
if(dev) { if (dev) {
struct arcnet_local *lp = netdev_priv(dev); struct arcnet_local *lp = netdev_priv(dev);
spin_lock_init(&lp->lock); spin_lock_init(&lp->lock);
} }
return dev; return dev;
} }
EXPORT_SYMBOL(alloc_arcdev);
/* /* Open/initialize the board. This is called sometime after booting when
* Open/initialize the board. This is called sometime after booting when
* the 'ifconfig' program is run. * the 'ifconfig' program is run.
* *
* This routine should set everything up anew at each open, even registers * This routine should set everything up anew at each open, even registers
...@@ -367,34 +343,33 @@ int arcnet_open(struct net_device *dev) ...@@ -367,34 +343,33 @@ int arcnet_open(struct net_device *dev)
struct arcnet_local *lp = netdev_priv(dev); struct arcnet_local *lp = netdev_priv(dev);
int count, newmtu, error; int count, newmtu, error;
BUGMSG(D_INIT,"opened."); arc_printk(D_INIT, dev, "opened.");
if (!try_module_get(lp->hw.owner)) if (!try_module_get(lp->hw.owner))
return -ENODEV; return -ENODEV;
BUGLVL(D_PROTO) { if (BUGLVL(D_PROTO)) {
BUGMSG(D_PROTO, "protocol map (default is '%c'): ", arc_printk(D_PROTO, dev, "protocol map (default is '%c'): ",
arc_proto_default->suffix); arc_proto_default->suffix);
for (count = 0; count < 256; count++) for (count = 0; count < 256; count++)
BUGMSG2(D_PROTO, "%c", arc_proto_map[count]->suffix); arc_cont(D_PROTO, "%c", arc_proto_map[count]->suffix);
BUGMSG2(D_PROTO, "\n"); arc_cont(D_PROTO, "\n");
} }
arc_printk(D_INIT, dev, "arcnet_open: resetting card.\n");
BUGMSG(D_INIT, "arcnet_open: resetting card.\n");
/* try to put the card in a defined state - if it fails the first /* try to put the card in a defined state - if it fails the first
* time, actually reset it. * time, actually reset it.
*/ */
error = -ENODEV; error = -ENODEV;
if (ARCRESET(0) && ARCRESET(1)) if (lp->hw.reset(dev, 0) && lp->hw.reset(dev, 1))
goto out_module_put; goto out_module_put;
newmtu = choose_mtu(); newmtu = choose_mtu();
if (newmtu < dev->mtu) if (newmtu < dev->mtu)
dev->mtu = newmtu; dev->mtu = newmtu;
BUGMSG(D_INIT, "arcnet_open: mtu: %d.\n", dev->mtu); arc_printk(D_INIT, dev, "arcnet_open: mtu: %d.\n", dev->mtu);
/* autodetect the encapsulation for each host. */ /* autodetect the encapsulation for each host. */
memset(lp->default_proto, 0, sizeof(lp->default_proto)); memset(lp->default_proto, 0, sizeof(lp->default_proto));
...@@ -425,30 +400,28 @@ int arcnet_open(struct net_device *dev) ...@@ -425,30 +400,28 @@ int arcnet_open(struct net_device *dev)
lp->hw.open(dev); lp->hw.open(dev);
if (dev->dev_addr[0] == 0) if (dev->dev_addr[0] == 0)
BUGMSG(D_NORMAL, "WARNING! Station address 00 is reserved " arc_printk(D_NORMAL, dev, "WARNING! Station address 00 is reserved for broadcasts!\n");
"for broadcasts!\n");
else if (dev->dev_addr[0] == 255) else if (dev->dev_addr[0] == 255)
BUGMSG(D_NORMAL, "WARNING! Station address FF may confuse " arc_printk(D_NORMAL, dev, "WARNING! Station address FF may confuse DOS networking programs!\n");
"DOS networking programs!\n");
BUGMSG(D_DEBUG, "%s: %d: %s\n",__FILE__,__LINE__,__func__); arc_printk(D_DEBUG, dev, "%s: %d: %s\n", __FILE__, __LINE__, __func__);
if (ASTATUS() & RESETflag) { if (lp->hw.status(dev) & RESETflag) {
BUGMSG(D_DEBUG, "%s: %d: %s\n",__FILE__,__LINE__,__func__); arc_printk(D_DEBUG, dev, "%s: %d: %s\n",
ACOMMAND(CFLAGScmd | RESETclear); __FILE__, __LINE__, __func__);
lp->hw.command(dev, CFLAGScmd | RESETclear);
} }
arc_printk(D_DEBUG, dev, "%s: %d: %s\n", __FILE__, __LINE__, __func__);
BUGMSG(D_DEBUG, "%s: %d: %s\n",__FILE__,__LINE__,__func__);
/* make sure we're ready to receive IRQ's. */ /* make sure we're ready to receive IRQ's. */
AINTMASK(0); lp->hw.intmask(dev, 0);
udelay(1); /* give it time to set the mask before udelay(1); /* give it time to set the mask before
* we reset it again. (may not even be * we reset it again. (may not even be
* necessary) * necessary)
*/ */
BUGMSG(D_DEBUG, "%s: %d: %s\n",__FILE__,__LINE__,__func__); arc_printk(D_DEBUG, dev, "%s: %d: %s\n", __FILE__, __LINE__, __func__);
lp->intmask = NORXflag | RECONflag; lp->intmask = NORXflag | RECONflag;
AINTMASK(lp->intmask); lp->hw.intmask(dev, lp->intmask);
BUGMSG(D_DEBUG, "%s: %d: %s\n",__FILE__,__LINE__,__func__); arc_printk(D_DEBUG, dev, "%s: %d: %s\n", __FILE__, __LINE__, __func__);
netif_start_queue(dev); netif_start_queue(dev);
...@@ -458,7 +431,7 @@ int arcnet_open(struct net_device *dev) ...@@ -458,7 +431,7 @@ int arcnet_open(struct net_device *dev)
module_put(lp->hw.owner); module_put(lp->hw.owner);
return error; return error;
} }
EXPORT_SYMBOL(arcnet_open);
/* The inverse routine to arcnet_open - shuts down the card. */ /* The inverse routine to arcnet_open - shuts down the card. */
int arcnet_close(struct net_device *dev) int arcnet_close(struct net_device *dev)
...@@ -468,9 +441,9 @@ int arcnet_close(struct net_device *dev) ...@@ -468,9 +441,9 @@ int arcnet_close(struct net_device *dev)
netif_stop_queue(dev); netif_stop_queue(dev);
/* flush TX and disable RX */ /* flush TX and disable RX */
AINTMASK(0); lp->hw.intmask(dev, 0);
ACOMMAND(NOTXcmd); /* stop transmit */ lp->hw.command(dev, NOTXcmd); /* stop transmit */
ACOMMAND(NORXcmd); /* disable receive */ lp->hw.command(dev, NORXcmd); /* disable receive */
mdelay(1); mdelay(1);
/* shut down the card */ /* shut down the card */
...@@ -478,7 +451,7 @@ int arcnet_close(struct net_device *dev) ...@@ -478,7 +451,7 @@ int arcnet_close(struct net_device *dev)
module_put(lp->hw.owner); module_put(lp->hw.owner);
return 0; return 0;
} }
EXPORT_SYMBOL(arcnet_close);
static int arcnet_header(struct sk_buff *skb, struct net_device *dev, static int arcnet_header(struct sk_buff *skb, struct net_device *dev,
unsigned short type, const void *daddr, unsigned short type, const void *daddr,
...@@ -488,48 +461,44 @@ static int arcnet_header(struct sk_buff *skb, struct net_device *dev, ...@@ -488,48 +461,44 @@ static int arcnet_header(struct sk_buff *skb, struct net_device *dev,
uint8_t _daddr, proto_num; uint8_t _daddr, proto_num;
struct ArcProto *proto; struct ArcProto *proto;
BUGMSG(D_DURING, arc_printk(D_DURING, dev,
"create header from %d to %d; protocol %d (%Xh); size %u.\n", "create header from %d to %d; protocol %d (%Xh); size %u.\n",
saddr ? *(uint8_t *) saddr : -1, saddr ? *(uint8_t *)saddr : -1,
daddr ? *(uint8_t *) daddr : -1, daddr ? *(uint8_t *)daddr : -1,
type, type, len); type, type, len);
if (skb->len!=0 && len != skb->len) if (skb->len != 0 && len != skb->len)
BUGMSG(D_NORMAL, "arcnet_header: Yikes! skb->len(%d) != len(%d)!\n", arc_printk(D_NORMAL, dev, "arcnet_header: Yikes! skb->len(%d) != len(%d)!\n",
skb->len, len); skb->len, len);
/* Type is host order - ? */
/* Type is host order - ? */ if (type == ETH_P_ARCNET) {
if(type == ETH_P_ARCNET) { proto = arc_raw_proto;
proto = arc_raw_proto; arc_printk(D_DEBUG, dev, "arc_raw_proto used. proto='%c'\n",
BUGMSG(D_DEBUG, "arc_raw_proto used. proto='%c'\n",proto->suffix); proto->suffix);
_daddr = daddr ? *(uint8_t *) daddr : 0; _daddr = daddr ? *(uint8_t *)daddr : 0;
} } else if (!daddr) {
else if (!daddr) { /* if the dest addr isn't provided, we can't choose an
/* * encapsulation! Store the packet type (eg. ETH_P_IP)
* if the dest addr isn't provided, we can't choose an encapsulation! * for now, and we'll push on a real header when we do
* Store the packet type (eg. ETH_P_IP) for now, and we'll push on a * rebuild_header.
* real header when we do rebuild_header.
*/
*(uint16_t *) skb_push(skb, 2) = type;
/*
* XXX: Why not use skb->mac_len?
*/ */
*(uint16_t *)skb_push(skb, 2) = type;
/* XXX: Why not use skb->mac_len? */
if (skb->network_header - skb->mac_header != 2) if (skb->network_header - skb->mac_header != 2)
BUGMSG(D_NORMAL, "arcnet_header: Yikes! diff (%d) is not 2!\n", arc_printk(D_NORMAL, dev, "arcnet_header: Yikes! diff (%u) is not 2!\n",
(int)(skb->network_header - skb->mac_header)); skb->network_header - skb->mac_header);
return -2; /* return error -- can't transmit yet! */ return -2; /* return error -- can't transmit yet! */
} } else {
else {
/* otherwise, we can just add the header as usual. */ /* otherwise, we can just add the header as usual. */
_daddr = *(uint8_t *) daddr; _daddr = *(uint8_t *)daddr;
proto_num = lp->default_proto[_daddr]; proto_num = lp->default_proto[_daddr];
proto = arc_proto_map[proto_num]; proto = arc_proto_map[proto_num];
BUGMSG(D_DURING, "building header for %02Xh using protocol '%c'\n", arc_printk(D_DURING, dev, "building header for %02Xh using protocol '%c'\n",
proto_num, proto->suffix); proto_num, proto->suffix);
if (proto == &arc_proto_null && arc_bcast_proto != proto) { if (proto == &arc_proto_null && arc_bcast_proto != proto) {
BUGMSG(D_DURING, "actually, let's use '%c' instead.\n", arc_printk(D_DURING, dev, "actually, let's use '%c' instead.\n",
arc_bcast_proto->suffix); arc_bcast_proto->suffix);
proto = arc_bcast_proto; proto = arc_bcast_proto;
} }
} }
...@@ -538,7 +507,7 @@ static int arcnet_header(struct sk_buff *skb, struct net_device *dev, ...@@ -538,7 +507,7 @@ static int arcnet_header(struct sk_buff *skb, struct net_device *dev,
/* Called by the kernel in order to transmit a packet. */ /* Called by the kernel in order to transmit a packet. */
netdev_tx_t arcnet_send_packet(struct sk_buff *skb, netdev_tx_t arcnet_send_packet(struct sk_buff *skb,
struct net_device *dev) struct net_device *dev)
{ {
struct arcnet_local *lp = netdev_priv(dev); struct arcnet_local *lp = netdev_priv(dev);
struct archdr *pkt; struct archdr *pkt;
...@@ -548,21 +517,22 @@ netdev_tx_t arcnet_send_packet(struct sk_buff *skb, ...@@ -548,21 +517,22 @@ netdev_tx_t arcnet_send_packet(struct sk_buff *skb,
unsigned long flags; unsigned long flags;
int freeskb, retval; int freeskb, retval;
BUGMSG(D_DURING, arc_printk(D_DURING, dev,
"transmit requested (status=%Xh, txbufs=%d/%d, len=%d, protocol %x)\n", "transmit requested (status=%Xh, txbufs=%d/%d, len=%d, protocol %x)\n",
ASTATUS(), lp->cur_tx, lp->next_tx, skb->len,skb->protocol); lp->hw.status(dev), lp->cur_tx, lp->next_tx, skb->len, skb->protocol);
pkt = (struct archdr *) skb->data; pkt = (struct archdr *)skb->data;
soft = &pkt->soft.rfc1201; soft = &pkt->soft.rfc1201;
proto = arc_proto_map[soft->proto]; proto = arc_proto_map[soft->proto];
BUGMSG(D_SKB_SIZE, "skb: transmitting %d bytes to %02X\n", arc_printk(D_SKB_SIZE, dev, "skb: transmitting %d bytes to %02X\n",
skb->len, pkt->hard.dest); skb->len, pkt->hard.dest);
BUGLVL(D_SKB) arcnet_dump_skb(dev, skb, "tx"); if (BUGLVL(D_SKB))
arcnet_dump_skb(dev, skb, "tx");
/* fits in one packet? */ /* fits in one packet? */
if (skb->len - ARC_HDR_SIZE > XMTU && !proto->continue_tx) { if (skb->len - ARC_HDR_SIZE > XMTU && !proto->continue_tx) {
BUGMSG(D_NORMAL, "fixme: packet too large: compensating badly!\n"); arc_printk(D_NORMAL, dev, "fixme: packet too large: compensating badly!\n");
dev_kfree_skb(skb); dev_kfree_skb(skb);
return NETDEV_TX_OK; /* don't try again */ return NETDEV_TX_OK; /* don't try again */
} }
...@@ -571,17 +541,18 @@ netdev_tx_t arcnet_send_packet(struct sk_buff *skb, ...@@ -571,17 +541,18 @@ netdev_tx_t arcnet_send_packet(struct sk_buff *skb,
netif_stop_queue(dev); netif_stop_queue(dev);
spin_lock_irqsave(&lp->lock, flags); spin_lock_irqsave(&lp->lock, flags);
AINTMASK(0); lp->hw.intmask(dev, 0);
if(lp->next_tx == -1) if (lp->next_tx == -1)
txbuf = get_arcbuf(dev); txbuf = get_arcbuf(dev);
else { else
txbuf = -1; txbuf = -1;
}
if (txbuf != -1) { if (txbuf != -1) {
if (proto->prepare_tx(dev, pkt, skb->len, txbuf) && if (proto->prepare_tx(dev, pkt, skb->len, txbuf) &&
!proto->ack_tx) { !proto->ack_tx) {
/* done right away and we don't want to acknowledge /* done right away and we don't want to acknowledge
the package later - forget about it now */ * the package later - forget about it now
*/
dev->stats.tx_bytes += skb->len; dev->stats.tx_bytes += skb->len;
freeskb = 1; freeskb = 1;
} else { } else {
...@@ -594,9 +565,9 @@ netdev_tx_t arcnet_send_packet(struct sk_buff *skb, ...@@ -594,9 +565,9 @@ netdev_tx_t arcnet_send_packet(struct sk_buff *skb,
if (proto->continue_tx && if (proto->continue_tx &&
proto->continue_tx(dev, txbuf)) { proto->continue_tx(dev, txbuf)) {
BUGMSG(D_NORMAL, arc_printk(D_NORMAL, dev,
"bug! continue_tx finished the first time! " "bug! continue_tx finished the first time! (proto='%c')\n",
"(proto='%c')\n", proto->suffix); proto->suffix);
} }
} }
retval = NETDEV_TX_OK; retval = NETDEV_TX_OK;
...@@ -606,61 +577,62 @@ netdev_tx_t arcnet_send_packet(struct sk_buff *skb, ...@@ -606,61 +577,62 @@ netdev_tx_t arcnet_send_packet(struct sk_buff *skb,
freeskb = 0; freeskb = 0;
} }
BUGMSG(D_DEBUG, "%s: %d: %s, status: %x\n",__FILE__,__LINE__,__func__,ASTATUS()); arc_printk(D_DEBUG, dev, "%s: %d: %s, status: %x\n",
__FILE__, __LINE__, __func__, lp->hw.status(dev));
/* make sure we didn't ignore a TX IRQ while we were in here */ /* make sure we didn't ignore a TX IRQ while we were in here */
AINTMASK(0); lp->hw.intmask(dev, 0);
BUGMSG(D_DEBUG, "%s: %d: %s\n",__FILE__,__LINE__,__func__); arc_printk(D_DEBUG, dev, "%s: %d: %s\n", __FILE__, __LINE__, __func__);
lp->intmask |= TXFREEflag|EXCNAKflag; lp->intmask |= TXFREEflag | EXCNAKflag;
AINTMASK(lp->intmask); lp->hw.intmask(dev, lp->intmask);
BUGMSG(D_DEBUG, "%s: %d: %s, status: %x\n",__FILE__,__LINE__,__func__,ASTATUS()); arc_printk(D_DEBUG, dev, "%s: %d: %s, status: %x\n",
__FILE__, __LINE__, __func__, lp->hw.status(dev));
spin_unlock_irqrestore(&lp->lock, flags); spin_unlock_irqrestore(&lp->lock, flags);
if (freeskb) { if (freeskb)
dev_kfree_skb(skb); dev_kfree_skb(skb);
}
return retval; /* no need to try again */ return retval; /* no need to try again */
} }
EXPORT_SYMBOL(arcnet_send_packet);
/* Actually start transmitting a packet that was loaded into a buffer
/*
* Actually start transmitting a packet that was loaded into a buffer
* by prepare_tx. This should _only_ be called by the interrupt handler. * by prepare_tx. This should _only_ be called by the interrupt handler.
*/ */
static int go_tx(struct net_device *dev) static int go_tx(struct net_device *dev)
{ {
struct arcnet_local *lp = netdev_priv(dev); struct arcnet_local *lp = netdev_priv(dev);
BUGMSG(D_DURING, "go_tx: status=%Xh, intmask=%Xh, next_tx=%d, cur_tx=%d\n", arc_printk(D_DURING, dev, "go_tx: status=%Xh, intmask=%Xh, next_tx=%d, cur_tx=%d\n",
ASTATUS(), lp->intmask, lp->next_tx, lp->cur_tx); lp->hw.status(dev), lp->intmask, lp->next_tx, lp->cur_tx);
if (lp->cur_tx != -1 || lp->next_tx == -1) if (lp->cur_tx != -1 || lp->next_tx == -1)
return 0; return 0;
BUGLVL(D_TX) arcnet_dump_packet(dev, lp->next_tx, "go_tx", 0); if (BUGLVL(D_TX))
arcnet_dump_packet(dev, lp->next_tx, "go_tx", 0);
lp->cur_tx = lp->next_tx; lp->cur_tx = lp->next_tx;
lp->next_tx = -1; lp->next_tx = -1;
/* start sending */ /* start sending */
ACOMMAND(TXcmd | (lp->cur_tx << 3)); lp->hw.command(dev, TXcmd | (lp->cur_tx << 3));
dev->stats.tx_packets++; dev->stats.tx_packets++;
lp->lasttrans_dest = lp->lastload_dest; lp->lasttrans_dest = lp->lastload_dest;
lp->lastload_dest = 0; lp->lastload_dest = 0;
lp->excnak_pending = 0; lp->excnak_pending = 0;
lp->intmask |= TXFREEflag|EXCNAKflag; lp->intmask |= TXFREEflag | EXCNAKflag;
return 1; return 1;
} }
/* Called by the kernel when transmit times out */ /* Called by the kernel when transmit times out */
void arcnet_timeout(struct net_device *dev) void arcnet_timeout(struct net_device *dev)
{ {
unsigned long flags; unsigned long flags;
struct arcnet_local *lp = netdev_priv(dev); struct arcnet_local *lp = netdev_priv(dev);
int status = ASTATUS(); int status = lp->hw.status(dev);
char *msg; char *msg;
spin_lock_irqsave(&lp->lock, flags); spin_lock_irqsave(&lp->lock, flags);
...@@ -670,30 +642,29 @@ void arcnet_timeout(struct net_device *dev) ...@@ -670,30 +642,29 @@ void arcnet_timeout(struct net_device *dev)
msg = ""; msg = "";
dev->stats.tx_aborted_errors++; dev->stats.tx_aborted_errors++;
lp->timed_out = 1; lp->timed_out = 1;
ACOMMAND(NOTXcmd | (lp->cur_tx << 3)); lp->hw.command(dev, NOTXcmd | (lp->cur_tx << 3));
} }
dev->stats.tx_errors++; dev->stats.tx_errors++;
/* make sure we didn't miss a TX or a EXC NAK IRQ */ /* make sure we didn't miss a TX or a EXC NAK IRQ */
AINTMASK(0); lp->hw.intmask(dev, 0);
lp->intmask |= TXFREEflag|EXCNAKflag; lp->intmask |= TXFREEflag | EXCNAKflag;
AINTMASK(lp->intmask); lp->hw.intmask(dev, lp->intmask);
spin_unlock_irqrestore(&lp->lock, flags); spin_unlock_irqrestore(&lp->lock, flags);
if (time_after(jiffies, lp->last_timeout + 10*HZ)) { if (time_after(jiffies, lp->last_timeout + 10 * HZ)) {
BUGMSG(D_EXTRA, "tx timed out%s (status=%Xh, intmask=%Xh, dest=%02Xh)\n", arc_printk(D_EXTRA, dev, "tx timed out%s (status=%Xh, intmask=%Xh, dest=%02Xh)\n",
msg, status, lp->intmask, lp->lasttrans_dest); msg, status, lp->intmask, lp->lasttrans_dest);
lp->last_timeout = jiffies; lp->last_timeout = jiffies;
} }
if (lp->cur_tx == -1) if (lp->cur_tx == -1)
netif_wake_queue(dev); netif_wake_queue(dev);
} }
EXPORT_SYMBOL(arcnet_timeout);
/* The typical workload of the driver: Handle the network interface
/*
* The typical workload of the driver: Handle the network interface
* interrupts. Establish which device needs attention, and call the correct * interrupts. Establish which device needs attention, and call the correct
* chipset interrupt handler. * chipset interrupt handler.
*/ */
...@@ -704,125 +675,125 @@ irqreturn_t arcnet_interrupt(int irq, void *dev_id) ...@@ -704,125 +675,125 @@ irqreturn_t arcnet_interrupt(int irq, void *dev_id)
int recbuf, status, diagstatus, didsomething, boguscount; int recbuf, status, diagstatus, didsomething, boguscount;
int retval = IRQ_NONE; int retval = IRQ_NONE;
BUGMSG(D_DURING, "\n"); arc_printk(D_DURING, dev, "\n");
BUGMSG(D_DURING, "in arcnet_interrupt\n"); arc_printk(D_DURING, dev, "in arcnet_interrupt\n");
lp = netdev_priv(dev); lp = netdev_priv(dev);
BUG_ON(!lp); BUG_ON(!lp);
spin_lock(&lp->lock); spin_lock(&lp->lock);
/* /* RESET flag was enabled - if device is not running, we must
* RESET flag was enabled - if device is not running, we must clear it right * clear it right away (but nothing else).
* away (but nothing else).
*/ */
if (!netif_running(dev)) { if (!netif_running(dev)) {
if (ASTATUS() & RESETflag) if (lp->hw.status(dev) & RESETflag)
ACOMMAND(CFLAGScmd | RESETclear); lp->hw.command(dev, CFLAGScmd | RESETclear);
AINTMASK(0); lp->hw.intmask(dev, 0);
spin_unlock(&lp->lock); spin_unlock(&lp->lock);
return retval; return retval;
} }
BUGMSG(D_DURING, "in arcnet_inthandler (status=%Xh, intmask=%Xh)\n", arc_printk(D_DURING, dev, "in arcnet_inthandler (status=%Xh, intmask=%Xh)\n",
ASTATUS(), lp->intmask); lp->hw.status(dev), lp->intmask);
boguscount = 5; boguscount = 5;
do { do {
status = ASTATUS(); status = lp->hw.status(dev);
diagstatus = (status >> 8) & 0xFF; diagstatus = (status >> 8) & 0xFF;
BUGMSG(D_DEBUG, "%s: %d: %s: status=%x\n", arc_printk(D_DEBUG, dev, "%s: %d: %s: status=%x\n",
__FILE__,__LINE__,__func__,status); __FILE__, __LINE__, __func__, status);
didsomething = 0; didsomething = 0;
/* /* RESET flag was enabled - card is resetting and if RX is
* RESET flag was enabled - card is resetting and if RX is
* disabled, it's NOT because we just got a packet. * disabled, it's NOT because we just got a packet.
* *
* The card is in an undefined state. Clear it out and start over. * The card is in an undefined state.
* Clear it out and start over.
*/ */
if (status & RESETflag) { if (status & RESETflag) {
BUGMSG(D_NORMAL, "spurious reset (status=%Xh)\n", status); arc_printk(D_NORMAL, dev, "spurious reset (status=%Xh)\n",
status);
arcnet_close(dev); arcnet_close(dev);
arcnet_open(dev); arcnet_open(dev);
/* get out of the interrupt handler! */ /* get out of the interrupt handler! */
break; break;
} }
/* /* RX is inhibited - we must have received something.
* RX is inhibited - we must have received something. Prepare to * Prepare to receive into the next buffer.
* receive into the next buffer. *
* * We don't actually copy the received packet from the card
* We don't actually copy the received packet from the card until * until after the transmit handler runs (and possibly
* after the transmit handler runs (and possibly launches the next * launches the next tx); this should improve latency slightly
* tx); this should improve latency slightly if we get both types * if we get both types of interrupts at once.
* of interrupts at once.
*/ */
recbuf = -1; recbuf = -1;
if (status & lp->intmask & NORXflag) { if (status & lp->intmask & NORXflag) {
recbuf = lp->cur_rx; recbuf = lp->cur_rx;
BUGMSG(D_DURING, "Buffer #%d: receive irq (status=%Xh)\n", arc_printk(D_DURING, dev, "Buffer #%d: receive irq (status=%Xh)\n",
recbuf, status); recbuf, status);
lp->cur_rx = get_arcbuf(dev); lp->cur_rx = get_arcbuf(dev);
if (lp->cur_rx != -1) { if (lp->cur_rx != -1) {
BUGMSG(D_DURING, "enabling receive to buffer #%d\n", arc_printk(D_DURING, dev, "enabling receive to buffer #%d\n",
lp->cur_rx); lp->cur_rx);
ACOMMAND(RXcmd | (lp->cur_rx << 3) | RXbcasts); lp->hw.command(dev, RXcmd | (lp->cur_rx << 3) | RXbcasts);
} }
didsomething++; didsomething++;
} }
if((diagstatus & EXCNAKflag)) { if ((diagstatus & EXCNAKflag)) {
BUGMSG(D_DURING, "EXCNAK IRQ (diagstat=%Xh)\n", arc_printk(D_DURING, dev, "EXCNAK IRQ (diagstat=%Xh)\n",
diagstatus); diagstatus);
ACOMMAND(NOTXcmd); /* disable transmit */ lp->hw.command(dev, NOTXcmd); /* disable transmit */
lp->excnak_pending = 1; lp->excnak_pending = 1;
ACOMMAND(EXCNAKclear); lp->hw.command(dev, EXCNAKclear);
lp->intmask &= ~(EXCNAKflag); lp->intmask &= ~(EXCNAKflag);
didsomething++; didsomething++;
} }
/* a transmit finished, and we're interested in it. */ /* a transmit finished, and we're interested in it. */
if ((status & lp->intmask & TXFREEflag) || lp->timed_out) { if ((status & lp->intmask & TXFREEflag) || lp->timed_out) {
lp->intmask &= ~(TXFREEflag|EXCNAKflag); lp->intmask &= ~(TXFREEflag | EXCNAKflag);
BUGMSG(D_DURING, "TX IRQ (stat=%Xh)\n", status); arc_printk(D_DURING, dev, "TX IRQ (stat=%Xh)\n",
status);
if (lp->cur_tx != -1 && !lp->timed_out) { if (lp->cur_tx != -1 && !lp->timed_out) {
if(!(status & TXACKflag)) { if (!(status & TXACKflag)) {
if (lp->lasttrans_dest != 0) { if (lp->lasttrans_dest != 0) {
BUGMSG(D_EXTRA, arc_printk(D_EXTRA, dev,
"transmit was not acknowledged! " "transmit was not acknowledged! (status=%Xh, dest=%02Xh)\n",
"(status=%Xh, dest=%02Xh)\n", status,
status, lp->lasttrans_dest); lp->lasttrans_dest);
dev->stats.tx_errors++; dev->stats.tx_errors++;
dev->stats.tx_carrier_errors++; dev->stats.tx_carrier_errors++;
} else { } else {
BUGMSG(D_DURING, arc_printk(D_DURING, dev,
"broadcast was not acknowledged; that's normal " "broadcast was not acknowledged; that's normal (status=%Xh, dest=%02Xh)\n",
"(status=%Xh, dest=%02Xh)\n", status,
status, lp->lasttrans_dest); lp->lasttrans_dest);
} }
} }
if (lp->outgoing.proto && if (lp->outgoing.proto &&
lp->outgoing.proto->ack_tx) { lp->outgoing.proto->ack_tx) {
int ackstatus; int ackstatus;
if(status & TXACKflag)
ackstatus=2; if (status & TXACKflag)
else if(lp->excnak_pending) ackstatus = 2;
ackstatus=1; else if (lp->excnak_pending)
else ackstatus = 1;
ackstatus=0; else
ackstatus = 0;
lp->outgoing.proto
->ack_tx(dev, ackstatus); lp->outgoing.proto
->ack_tx(dev, ackstatus);
} }
} }
if (lp->cur_tx != -1) if (lp->cur_tx != -1)
...@@ -836,17 +807,18 @@ irqreturn_t arcnet_interrupt(int irq, void *dev_id) ...@@ -836,17 +807,18 @@ irqreturn_t arcnet_interrupt(int irq, void *dev_id)
go_tx(dev); go_tx(dev);
/* continue a split packet, if any */ /* continue a split packet, if any */
if (lp->outgoing.proto && lp->outgoing.proto->continue_tx) { if (lp->outgoing.proto &&
lp->outgoing.proto->continue_tx) {
int txbuf = get_arcbuf(dev); int txbuf = get_arcbuf(dev);
if (txbuf != -1) { if (txbuf != -1) {
if (lp->outgoing.proto->continue_tx(dev, txbuf)) { if (lp->outgoing.proto->continue_tx(dev, txbuf)) {
/* that was the last segment */ /* that was the last segment */
dev->stats.tx_bytes += lp->outgoing.skb->len; dev->stats.tx_bytes += lp->outgoing.skb->len;
if(!lp->outgoing.proto->ack_tx) if (!lp->outgoing.proto->ack_tx) {
{ dev_kfree_skb_irq(lp->outgoing.skb);
dev_kfree_skb_irq(lp->outgoing.skb); lp->outgoing.proto = NULL;
lp->outgoing.proto = NULL; }
}
} }
lp->next_tx = txbuf; lp->next_tx = txbuf;
} }
...@@ -857,7 +829,8 @@ irqreturn_t arcnet_interrupt(int irq, void *dev_id) ...@@ -857,7 +829,8 @@ irqreturn_t arcnet_interrupt(int irq, void *dev_id)
} }
/* now process the received packet, if any */ /* now process the received packet, if any */
if (recbuf != -1) { if (recbuf != -1) {
BUGLVL(D_RX) arcnet_dump_packet(dev, recbuf, "rx irq", 0); if (BUGLVL(D_RX))
arcnet_dump_packet(dev, recbuf, "rx irq", 0);
arcnet_rx(dev, recbuf); arcnet_rx(dev, recbuf);
release_arcbuf(dev, recbuf); release_arcbuf(dev, recbuf);
...@@ -865,32 +838,32 @@ irqreturn_t arcnet_interrupt(int irq, void *dev_id) ...@@ -865,32 +838,32 @@ irqreturn_t arcnet_interrupt(int irq, void *dev_id)
didsomething++; didsomething++;
} }
if (status & lp->intmask & RECONflag) { if (status & lp->intmask & RECONflag) {
ACOMMAND(CFLAGScmd | CONFIGclear); lp->hw.command(dev, CFLAGScmd | CONFIGclear);
dev->stats.tx_carrier_errors++; dev->stats.tx_carrier_errors++;
BUGMSG(D_RECON, "Network reconfiguration detected (status=%Xh)\n", arc_printk(D_RECON, dev, "Network reconfiguration detected (status=%Xh)\n",
status); status);
/* MYRECON bit is at bit 7 of diagstatus */ /* MYRECON bit is at bit 7 of diagstatus */
if(diagstatus & 0x80) if (diagstatus & 0x80)
BUGMSG(D_RECON,"Put out that recon myself\n"); arc_printk(D_RECON, dev, "Put out that recon myself\n");
/* is the RECON info empty or old? */ /* is the RECON info empty or old? */
if (!lp->first_recon || !lp->last_recon || if (!lp->first_recon || !lp->last_recon ||
time_after(jiffies, lp->last_recon + HZ * 10)) { time_after(jiffies, lp->last_recon + HZ * 10)) {
if (lp->network_down) if (lp->network_down)
BUGMSG(D_NORMAL, "reconfiguration detected: cabling restored?\n"); arc_printk(D_NORMAL, dev, "reconfiguration detected: cabling restored?\n");
lp->first_recon = lp->last_recon = jiffies; lp->first_recon = lp->last_recon = jiffies;
lp->num_recons = lp->network_down = 0; lp->num_recons = lp->network_down = 0;
BUGMSG(D_DURING, "recon: clearing counters.\n"); arc_printk(D_DURING, dev, "recon: clearing counters.\n");
} else { /* add to current RECON counter */ } else { /* add to current RECON counter */
lp->last_recon = jiffies; lp->last_recon = jiffies;
lp->num_recons++; lp->num_recons++;
BUGMSG(D_DURING, "recon: counter=%d, time=%lds, net=%d\n", arc_printk(D_DURING, dev, "recon: counter=%d, time=%lds, net=%d\n",
lp->num_recons, lp->num_recons,
(lp->last_recon - lp->first_recon) / HZ, (lp->last_recon - lp->first_recon) / HZ,
lp->network_down); lp->network_down);
/* if network is marked up; /* if network is marked up;
* and first_recon and last_recon are 60+ apart; * and first_recon and last_recon are 60+ apart;
...@@ -902,46 +875,44 @@ irqreturn_t arcnet_interrupt(int irq, void *dev_id) ...@@ -902,46 +875,44 @@ irqreturn_t arcnet_interrupt(int irq, void *dev_id)
(lp->last_recon - lp->first_recon) <= HZ * 60 && (lp->last_recon - lp->first_recon) <= HZ * 60 &&
lp->num_recons >= RECON_THRESHOLD) { lp->num_recons >= RECON_THRESHOLD) {
lp->network_down = 1; lp->network_down = 1;
BUGMSG(D_NORMAL, "many reconfigurations detected: cabling problem?\n"); arc_printk(D_NORMAL, dev, "many reconfigurations detected: cabling problem?\n");
} else if (!lp->network_down && } else if (!lp->network_down &&
lp->last_recon - lp->first_recon > HZ * 60) { lp->last_recon - lp->first_recon > HZ * 60) {
/* reset counters if we've gone for over a minute. */ /* reset counters if we've gone for
* over a minute.
*/
lp->first_recon = lp->last_recon; lp->first_recon = lp->last_recon;
lp->num_recons = 1; lp->num_recons = 1;
} }
} }
} else if (lp->network_down && } else if (lp->network_down &&
time_after(jiffies, lp->last_recon + HZ * 10)) { time_after(jiffies, lp->last_recon + HZ * 10)) {
if (lp->network_down) if (lp->network_down)
BUGMSG(D_NORMAL, "cabling restored?\n"); arc_printk(D_NORMAL, dev, "cabling restored?\n");
lp->first_recon = lp->last_recon = 0; lp->first_recon = lp->last_recon = 0;
lp->num_recons = lp->network_down = 0; lp->num_recons = lp->network_down = 0;
BUGMSG(D_DURING, "not recon: clearing counters anyway.\n"); arc_printk(D_DURING, dev, "not recon: clearing counters anyway.\n");
} }
if(didsomething) { if (didsomething)
retval |= IRQ_HANDLED; retval |= IRQ_HANDLED;
} } while (--boguscount && didsomething);
}
while (--boguscount && didsomething);
BUGMSG(D_DURING, "arcnet_interrupt complete (status=%Xh, count=%d)\n",
ASTATUS(), boguscount);
BUGMSG(D_DURING, "\n");
arc_printk(D_DURING, dev, "arcnet_interrupt complete (status=%Xh, count=%d)\n",
lp->hw.status(dev), boguscount);
arc_printk(D_DURING, dev, "\n");
AINTMASK(0); lp->hw.intmask(dev, 0);
udelay(1); udelay(1);
AINTMASK(lp->intmask); lp->hw.intmask(dev, lp->intmask);
spin_unlock(&lp->lock); spin_unlock(&lp->lock);
return retval; return retval;
} }
EXPORT_SYMBOL(arcnet_interrupt);
/* This is a generic packet receiver that calls arcnet??_rx depending on the
/*
* This is a generic packet receiver that calls arcnet??_rx depending on the
* protocol ID found. * protocol ID found.
*/ */
static void arcnet_rx(struct net_device *dev, int bufnum) static void arcnet_rx(struct net_device *dev, int bufnum)
...@@ -963,32 +934,31 @@ static void arcnet_rx(struct net_device *dev, int bufnum) ...@@ -963,32 +934,31 @@ static void arcnet_rx(struct net_device *dev, int bufnum)
} }
/* get the full header, if possible */ /* get the full header, if possible */
if (sizeof(pkt.soft) <= length) if (sizeof(pkt.soft) <= length) {
lp->hw.copy_from_card(dev, bufnum, ofs, soft, sizeof(pkt.soft)); lp->hw.copy_from_card(dev, bufnum, ofs, soft, sizeof(pkt.soft));
else { } else {
memset(&pkt.soft, 0, sizeof(pkt.soft)); memset(&pkt.soft, 0, sizeof(pkt.soft));
lp->hw.copy_from_card(dev, bufnum, ofs, soft, length); lp->hw.copy_from_card(dev, bufnum, ofs, soft, length);
} }
BUGMSG(D_DURING, "Buffer #%d: received packet from %02Xh to %02Xh " arc_printk(D_DURING, dev, "Buffer #%d: received packet from %02Xh to %02Xh (%d+4 bytes)\n",
"(%d+4 bytes)\n", bufnum, pkt.hard.source, pkt.hard.dest, length);
bufnum, pkt.hard.source, pkt.hard.dest, length);
dev->stats.rx_packets++; dev->stats.rx_packets++;
dev->stats.rx_bytes += length + ARC_HDR_SIZE; dev->stats.rx_bytes += length + ARC_HDR_SIZE;
/* call the right receiver for the protocol */ /* call the right receiver for the protocol */
if (arc_proto_map[soft->proto]->is_ip) { if (arc_proto_map[soft->proto]->is_ip) {
BUGLVL(D_PROTO) { if (BUGLVL(D_PROTO)) {
struct ArcProto struct ArcProto
*oldp = arc_proto_map[lp->default_proto[pkt.hard.source]], *oldp = arc_proto_map[lp->default_proto[pkt.hard.source]],
*newp = arc_proto_map[soft->proto]; *newp = arc_proto_map[soft->proto];
if (oldp != newp) { if (oldp != newp) {
BUGMSG(D_PROTO, arc_printk(D_PROTO, dev,
"got protocol %02Xh; encap for host %02Xh is now '%c'" "got protocol %02Xh; encap for host %02Xh is now '%c' (was '%c')\n",
" (was '%c')\n", soft->proto, pkt.hard.source, soft->proto, pkt.hard.source,
newp->suffix, oldp->suffix); newp->suffix, oldp->suffix);
} }
} }
...@@ -1002,30 +972,27 @@ static void arcnet_rx(struct net_device *dev, int bufnum) ...@@ -1002,30 +972,27 @@ static void arcnet_rx(struct net_device *dev, int bufnum)
arc_proto_map[soft->proto]->rx(dev, bufnum, &pkt, length); arc_proto_map[soft->proto]->rx(dev, bufnum, &pkt, length);
} }
static void null_rx(struct net_device *dev, int bufnum, static void null_rx(struct net_device *dev, int bufnum,
struct archdr *pkthdr, int length) struct archdr *pkthdr, int length)
{ {
BUGMSG(D_PROTO, arc_printk(D_PROTO, dev,
"rx: don't know how to deal with proto %02Xh from host %02Xh.\n", "rx: don't know how to deal with proto %02Xh from host %02Xh.\n",
pkthdr->soft.rfc1201.proto, pkthdr->hard.source); pkthdr->soft.rfc1201.proto, pkthdr->hard.source);
} }
static int null_build_header(struct sk_buff *skb, struct net_device *dev, static int null_build_header(struct sk_buff *skb, struct net_device *dev,
unsigned short type, uint8_t daddr) unsigned short type, uint8_t daddr)
{ {
struct arcnet_local *lp = netdev_priv(dev); struct arcnet_local *lp = netdev_priv(dev);
BUGMSG(D_PROTO, arc_printk(D_PROTO, dev,
"tx: can't build header for encap %02Xh; load a protocol driver.\n", "tx: can't build header for encap %02Xh; load a protocol driver.\n",
lp->default_proto[daddr]); lp->default_proto[daddr]);
/* always fails */ /* always fails */
return 0; return 0;
} }
/* the "do nothing" prepare_tx function warns that there's nothing to do. */ /* 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, static int null_prepare_tx(struct net_device *dev, struct archdr *pkt,
int length, int bufnum) int length, int bufnum)
...@@ -1033,7 +1000,7 @@ static int null_prepare_tx(struct net_device *dev, struct archdr *pkt, ...@@ -1033,7 +1000,7 @@ static int null_prepare_tx(struct net_device *dev, struct archdr *pkt,
struct arcnet_local *lp = netdev_priv(dev); struct arcnet_local *lp = netdev_priv(dev);
struct arc_hardware newpkt; struct arc_hardware newpkt;
BUGMSG(D_PROTO, "tx: no encap for this host; load a protocol driver.\n"); arc_printk(D_PROTO, dev, "tx: no encap for this host; load a protocol driver.\n");
/* send a packet to myself -- will never get received, of course */ /* send a packet to myself -- will never get received, of course */
newpkt.source = newpkt.dest = dev->dev_addr[0]; newpkt.source = newpkt.dest = dev->dev_addr[0];
......
...@@ -26,6 +26,8 @@ ...@@ -26,6 +26,8 @@
* ********************** * **********************
*/ */
#define pr_fmt(fmt) "arcnet:" KBUILD_MODNAME ": " fmt
#include <linux/module.h> #include <linux/module.h>
#include <linux/gfp.h> #include <linux/gfp.h>
#include <linux/init.h> #include <linux/init.h>
...@@ -33,9 +35,8 @@ ...@@ -33,9 +35,8 @@
#include <net/arp.h> #include <net/arp.h>
#include <linux/netdevice.h> #include <linux/netdevice.h>
#include <linux/skbuff.h> #include <linux/skbuff.h>
#include <linux/arcdevice.h>
#define VERSION "arcnet: cap mode (`c') encapsulation support loaded.\n" #include "arcdevice.h"
/* packet receiver */ /* packet receiver */
static void rx(struct net_device *dev, int bufnum, static void rx(struct net_device *dev, int bufnum,
...@@ -47,7 +48,8 @@ static void rx(struct net_device *dev, int bufnum, ...@@ -47,7 +48,8 @@ static void rx(struct net_device *dev, int bufnum,
char *pktbuf, *pkthdrbuf; char *pktbuf, *pkthdrbuf;
int ofs; int ofs;
BUGMSG(D_DURING, "it's a raw(cap) packet (length=%d)\n", length); arc_printk(D_DURING, dev, "it's a raw(cap) packet (length=%d)\n",
length);
if (length >= MinTU) if (length >= MinTU)
ofs = 512 - length; ofs = 512 - length;
...@@ -55,8 +57,7 @@ static void rx(struct net_device *dev, int bufnum, ...@@ -55,8 +57,7 @@ static void rx(struct net_device *dev, int bufnum,
ofs = 256 - length; ofs = 256 - length;
skb = alloc_skb(length + ARC_HDR_SIZE + sizeof(int), GFP_ATOMIC); skb = alloc_skb(length + ARC_HDR_SIZE + sizeof(int), GFP_ATOMIC);
if (skb == NULL) { if (!skb) {
BUGMSG(D_NORMAL, "Memory squeeze, dropping packet.\n");
dev->stats.rx_dropped++; dev->stats.rx_dropped++;
return; return;
} }
...@@ -66,17 +67,17 @@ static void rx(struct net_device *dev, int bufnum, ...@@ -66,17 +67,17 @@ static void rx(struct net_device *dev, int bufnum,
pkt = (struct archdr *)skb_mac_header(skb); pkt = (struct archdr *)skb_mac_header(skb);
skb_pull(skb, ARC_HDR_SIZE); skb_pull(skb, ARC_HDR_SIZE);
/* up to sizeof(pkt->soft) has already been copied from the card */ /* up to sizeof(pkt->soft) has already been copied from the card
/* squeeze in an int for the cap encapsulation */ * squeeze in an int for the cap encapsulation
* use these variables to be sure we count in bytes, not in
/* use these variables to be sure we count in bytes, not in * sizeof(struct archdr)
sizeof(struct archdr) */ */
pktbuf=(char*)pkt; pktbuf = (char *)pkt;
pkthdrbuf=(char*)pkthdr; pkthdrbuf = (char *)pkthdr;
memcpy(pktbuf, pkthdrbuf, ARC_HDR_SIZE+sizeof(pkt->soft.cap.proto)); memcpy(pktbuf, pkthdrbuf, ARC_HDR_SIZE + sizeof(pkt->soft.cap.proto));
memcpy(pktbuf+ARC_HDR_SIZE+sizeof(pkt->soft.cap.proto)+sizeof(int), memcpy(pktbuf + ARC_HDR_SIZE + sizeof(pkt->soft.cap.proto) + sizeof(int),
pkthdrbuf+ARC_HDR_SIZE+sizeof(pkt->soft.cap.proto), pkthdrbuf + ARC_HDR_SIZE + sizeof(pkt->soft.cap.proto),
sizeof(struct archdr)-ARC_HDR_SIZE-sizeof(pkt->soft.cap.proto)); sizeof(struct archdr) - ARC_HDR_SIZE - sizeof(pkt->soft.cap.proto));
if (length > sizeof(pkt->soft)) if (length > sizeof(pkt->soft))
lp->hw.copy_from_card(dev, bufnum, ofs + sizeof(pkt->soft), lp->hw.copy_from_card(dev, bufnum, ofs + sizeof(pkt->soft),
...@@ -84,15 +85,14 @@ static void rx(struct net_device *dev, int bufnum, ...@@ -84,15 +85,14 @@ static void rx(struct net_device *dev, int bufnum,
+ sizeof(int), + sizeof(int),
length - sizeof(pkt->soft)); length - sizeof(pkt->soft));
BUGLVL(D_SKB) arcnet_dump_skb(dev, skb, "rx"); if (BUGLVL(D_SKB))
arcnet_dump_skb(dev, skb, "rx");
skb->protocol = cpu_to_be16(ETH_P_ARCNET); skb->protocol = cpu_to_be16(ETH_P_ARCNET);
netif_rx(skb); netif_rx(skb);
} }
/* Create the ARCnet hard/soft headers for cap mode.
/*
* Create the ARCnet hard/soft headers for cap mode.
* There aren't any soft headers in cap mode - not even the protocol id. * There aren't any soft headers in cap mode - not even the protocol id.
*/ */
static int build_header(struct sk_buff *skb, static int build_header(struct sk_buff *skb,
...@@ -101,12 +101,12 @@ static int build_header(struct sk_buff *skb, ...@@ -101,12 +101,12 @@ static int build_header(struct sk_buff *skb,
uint8_t daddr) uint8_t daddr)
{ {
int hdr_size = ARC_HDR_SIZE; int hdr_size = ARC_HDR_SIZE;
struct archdr *pkt = (struct archdr *) skb_push(skb, hdr_size); struct archdr *pkt = (struct archdr *)skb_push(skb, hdr_size);
BUGMSG(D_PROTO, "Preparing header for cap packet %x.\n", arc_printk(D_PROTO, dev, "Preparing header for cap packet %x.\n",
*((int*)&pkt->soft.cap.cookie[0])); *((int *)&pkt->soft.cap.cookie[0]));
/*
* Set the source hardware address. /* Set the source hardware address.
* *
* This is pretty pointless for most purposes, but it can help in * This is pretty pointless for most purposes, but it can help in
* debugging. ARCnet does not allow us to change the source address in * debugging. ARCnet does not allow us to change the source address in
...@@ -117,9 +117,8 @@ static int build_header(struct sk_buff *skb, ...@@ -117,9 +117,8 @@ static int build_header(struct sk_buff *skb,
/* see linux/net/ethernet/eth.c to see where I got the following */ /* see linux/net/ethernet/eth.c to see where I got the following */
if (dev->flags & (IFF_LOOPBACK | IFF_NOARP)) { if (dev->flags & (IFF_LOOPBACK | IFF_NOARP)) {
/* /* FIXME: fill in the last byte of the dest ipaddr here to
* FIXME: fill in the last byte of the dest ipaddr here to better * better comply with RFC1051 in "noarp" mode.
* comply with RFC1051 in "noarp" mode.
*/ */
pkt->hard.dest = 0; pkt->hard.dest = 0;
return hdr_size; return hdr_size;
...@@ -130,7 +129,6 @@ static int build_header(struct sk_buff *skb, ...@@ -130,7 +129,6 @@ static int build_header(struct sk_buff *skb,
return hdr_size; /* success */ return hdr_size; /* success */
} }
static int prepare_tx(struct net_device *dev, struct archdr *pkt, int length, static int prepare_tx(struct net_device *dev, struct archdr *pkt, int length,
int bufnum) int bufnum)
{ {
...@@ -138,22 +136,21 @@ static int prepare_tx(struct net_device *dev, struct archdr *pkt, int length, ...@@ -138,22 +136,21 @@ static int prepare_tx(struct net_device *dev, struct archdr *pkt, int length,
struct arc_hardware *hard = &pkt->hard; struct arc_hardware *hard = &pkt->hard;
int ofs; int ofs;
/* hard header is not included in packet length */ /* hard header is not included in packet length */
length -= ARC_HDR_SIZE; length -= ARC_HDR_SIZE;
/* And neither is the cookie field */ /* And neither is the cookie field */
length -= sizeof(int); length -= sizeof(int);
BUGMSG(D_DURING, "prepare_tx: txbufs=%d/%d/%d\n", arc_printk(D_DURING, dev, "prepare_tx: txbufs=%d/%d/%d\n",
lp->next_tx, lp->cur_tx, bufnum); lp->next_tx, lp->cur_tx, bufnum);
BUGMSG(D_PROTO, "Sending for cap packet %x.\n", arc_printk(D_PROTO, dev, "Sending for cap packet %x.\n",
*((int*)&pkt->soft.cap.cookie[0])); *((int *)&pkt->soft.cap.cookie[0]));
if (length > XMTU) { if (length > XMTU) {
/* should never happen! other people already check for this. */ /* should never happen! other people already check for this. */
BUGMSG(D_NORMAL, "Bug! prepare_tx with size %d (> %d)\n", arc_printk(D_NORMAL, dev, "Bug! prepare_tx with size %d (> %d)\n",
length, XMTU); length, XMTU);
length = XMTU; length = XMTU;
} }
if (length > MinTU) { if (length > MinTU) {
...@@ -162,11 +159,12 @@ static int prepare_tx(struct net_device *dev, struct archdr *pkt, int length, ...@@ -162,11 +159,12 @@ static int prepare_tx(struct net_device *dev, struct archdr *pkt, int length,
} else if (length > MTU) { } else if (length > MTU) {
hard->offset[0] = 0; hard->offset[0] = 0;
hard->offset[1] = ofs = 512 - length - 3; hard->offset[1] = ofs = 512 - length - 3;
} else } else {
hard->offset[0] = ofs = 256 - length; hard->offset[0] = ofs = 256 - length;
}
BUGMSG(D_DURING, "prepare_tx: length=%d ofs=%d\n", arc_printk(D_DURING, dev, "prepare_tx: length=%d ofs=%d\n",
length,ofs); length, ofs);
/* Copy the arcnet-header + the protocol byte down: */ /* Copy the arcnet-header + the protocol byte down: */
lp->hw.copy_to_card(dev, bufnum, 0, hard, ARC_HDR_SIZE); lp->hw.copy_to_card(dev, bufnum, 0, hard, ARC_HDR_SIZE);
...@@ -174,9 +172,10 @@ static int prepare_tx(struct net_device *dev, struct archdr *pkt, int length, ...@@ -174,9 +172,10 @@ static int prepare_tx(struct net_device *dev, struct archdr *pkt, int length,
sizeof(pkt->soft.cap.proto)); sizeof(pkt->soft.cap.proto));
/* Skip the extra integer we have written into it as a cookie /* Skip the extra integer we have written into it as a cookie
but write the rest of the message: */ * but write the rest of the message:
lp->hw.copy_to_card(dev, bufnum, ofs+1, */
((unsigned char*)&pkt->soft.cap.mes),length-1); lp->hw.copy_to_card(dev, bufnum, ofs + 1,
((unsigned char *)&pkt->soft.cap.mes), length - 1);
lp->lastload_dest = hard->dest; lp->lastload_dest = hard->dest;
...@@ -188,21 +187,20 @@ static int ack_tx(struct net_device *dev, int acked) ...@@ -188,21 +187,20 @@ static int ack_tx(struct net_device *dev, int acked)
struct arcnet_local *lp = netdev_priv(dev); struct arcnet_local *lp = netdev_priv(dev);
struct sk_buff *ackskb; struct sk_buff *ackskb;
struct archdr *ackpkt; struct archdr *ackpkt;
int length=sizeof(struct arc_cap); int length = sizeof(struct arc_cap);
BUGMSG(D_DURING, "capmode: ack_tx: protocol: %x: result: %d\n", arc_printk(D_DURING, dev, "capmode: ack_tx: protocol: %x: result: %d\n",
lp->outgoing.skb->protocol, acked); lp->outgoing.skb->protocol, acked);
BUGLVL(D_SKB) arcnet_dump_skb(dev, lp->outgoing.skb, "ack_tx"); if (BUGLVL(D_SKB))
arcnet_dump_skb(dev, lp->outgoing.skb, "ack_tx");
/* Now alloc a skb to send back up through the layers: */ /* Now alloc a skb to send back up through the layers: */
ackskb = alloc_skb(length + ARC_HDR_SIZE , GFP_ATOMIC); ackskb = alloc_skb(length + ARC_HDR_SIZE, GFP_ATOMIC);
if (ackskb == NULL) { if (!ackskb)
BUGMSG(D_NORMAL, "Memory squeeze, can't acknowledge.\n");
goto free_outskb; goto free_outskb;
}
skb_put(ackskb, length + ARC_HDR_SIZE ); skb_put(ackskb, length + ARC_HDR_SIZE);
ackskb->dev = dev; ackskb->dev = dev;
skb_reset_mac_header(ackskb); skb_reset_mac_header(ackskb);
...@@ -212,39 +210,40 @@ static int ack_tx(struct net_device *dev, int acked) ...@@ -212,39 +210,40 @@ static int ack_tx(struct net_device *dev, int acked)
skb_copy_from_linear_data(lp->outgoing.skb, ackpkt, skb_copy_from_linear_data(lp->outgoing.skb, ackpkt,
ARC_HDR_SIZE + sizeof(struct arc_cap)); ARC_HDR_SIZE + sizeof(struct arc_cap));
ackpkt->soft.cap.proto = 0; /* using protocol 0 for acknowledge */ ackpkt->soft.cap.proto = 0; /* using protocol 0 for acknowledge */
ackpkt->soft.cap.mes.ack=acked; ackpkt->soft.cap.mes.ack = acked;
BUGMSG(D_PROTO, "Ackknowledge for cap packet %x.\n", arc_printk(D_PROTO, dev, "Ackknowledge for cap packet %x.\n",
*((int*)&ackpkt->soft.cap.cookie[0])); *((int *)&ackpkt->soft.cap.cookie[0]));
ackskb->protocol = cpu_to_be16(ETH_P_ARCNET); ackskb->protocol = cpu_to_be16(ETH_P_ARCNET);
BUGLVL(D_SKB) arcnet_dump_skb(dev, ackskb, "ack_tx_recv"); if (BUGLVL(D_SKB))
arcnet_dump_skb(dev, ackskb, "ack_tx_recv");
netif_rx(ackskb); netif_rx(ackskb);
free_outskb: free_outskb:
dev_kfree_skb_irq(lp->outgoing.skb); dev_kfree_skb_irq(lp->outgoing.skb);
lp->outgoing.proto = NULL; /* We are always finished when in this protocol */ lp->outgoing.proto = NULL;
/* We are always finished when in this protocol */
return 0; return 0;
} }
static struct ArcProto capmode_proto = static struct ArcProto capmode_proto = {
{ .suffix = 'r',
'r', .mtu = XMTU,
XMTU, .rx = rx,
0, .build_header = build_header,
rx, .prepare_tx = prepare_tx,
build_header, .ack_tx = ack_tx
prepare_tx,
NULL,
ack_tx
}; };
static void arcnet_cap_init(void) static int __init capmode_module_init(void)
{ {
int count; int count;
pr_info("cap mode (`c') encapsulation support loaded\n");
for (count = 1; count <= 8; count++) for (count = 1; count <= 8; count++)
if (arc_proto_map[count] == arc_proto_default) if (arc_proto_map[count] == arc_proto_default)
arc_proto_map[count] = &capmode_proto; arc_proto_map[count] = &capmode_proto;
...@@ -255,12 +254,7 @@ static void arcnet_cap_init(void) ...@@ -255,12 +254,7 @@ static void arcnet_cap_init(void)
arc_proto_default = &capmode_proto; arc_proto_default = &capmode_proto;
arc_raw_proto = &capmode_proto; arc_raw_proto = &capmode_proto;
}
static int __init capmode_module_init(void)
{
printk(VERSION);
arcnet_cap_init();
return 0; return 0;
} }
......
/* /*
* Linux ARCnet driver - COM20020 chipset support * Linux ARCnet driver - COM20020 chipset support
* *
* Written 1997 by David Woodhouse. * Written 1997 by David Woodhouse.
* Written 1994-1999 by Avery Pennarun. * Written 1994-1999 by Avery Pennarun.
* Written 1999-2000 by Martin Mares <mj@ucw.cz>. * Written 1999-2000 by Martin Mares <mj@ucw.cz>.
...@@ -25,6 +25,9 @@ ...@@ -25,6 +25,9 @@
* *
* ********************** * **********************
*/ */
#define pr_fmt(fmt) "arcnet:" KBUILD_MODNAME ": " fmt
#include <linux/module.h> #include <linux/module.h>
#include <linux/moduleparam.h> #include <linux/moduleparam.h>
#include <linux/kernel.h> #include <linux/kernel.h>
...@@ -36,16 +39,12 @@ ...@@ -36,16 +39,12 @@
#include <linux/init.h> #include <linux/init.h>
#include <linux/interrupt.h> #include <linux/interrupt.h>
#include <linux/bootmem.h> #include <linux/bootmem.h>
#include <linux/arcdevice.h> #include <linux/io.h>
#include <linux/com20020.h>
#include <asm/io.h>
#define VERSION "arcnet: COM20020 ISA support (by David Woodhouse et al.)\n" #include "arcdevice.h"
#include "com20020.h"
/* We cannot (yet) probe for an IO mapped card, although we can check that
/*
* We cannot (yet) probe for an IO mapped card, although we can check that
* it's where we were told it was, and even do autoirq. * it's where we were told it was, and even do autoirq.
*/ */
static int __init com20020isa_probe(struct net_device *dev) static int __init com20020isa_probe(struct net_device *dev)
...@@ -55,21 +54,21 @@ static int __init com20020isa_probe(struct net_device *dev) ...@@ -55,21 +54,21 @@ static int __init com20020isa_probe(struct net_device *dev)
struct arcnet_local *lp = netdev_priv(dev); struct arcnet_local *lp = netdev_priv(dev);
int err; int err;
BUGLVL(D_NORMAL) printk(VERSION); if (BUGLVL(D_NORMAL))
pr_info("%s\n", "COM20020 ISA support (by David Woodhouse et al.)");
ioaddr = dev->base_addr; ioaddr = dev->base_addr;
if (!ioaddr) { if (!ioaddr) {
BUGMSG(D_NORMAL, "No autoprobe (yet) for IO mapped cards; you " arc_printk(D_NORMAL, dev, "No autoprobe (yet) for IO mapped cards; you must specify the base address!\n");
"must specify the base address!\n");
return -ENODEV; return -ENODEV;
} }
if (!request_region(ioaddr, ARCNET_TOTAL_SIZE, "arcnet (COM20020)")) { if (!request_region(ioaddr, ARCNET_TOTAL_SIZE, "arcnet (COM20020)")) {
BUGMSG(D_NORMAL, "IO region %xh-%xh already allocated.\n", arc_printk(D_NORMAL, dev, "IO region %xh-%xh already allocated.\n",
ioaddr, ioaddr + ARCNET_TOTAL_SIZE - 1); ioaddr, ioaddr + ARCNET_TOTAL_SIZE - 1);
return -ENXIO; return -ENXIO;
} }
if (ASTATUS() == 0xFF) { if (arcnet_inb(ioaddr, COM20020_REG_R_STATUS) == 0xFF) {
BUGMSG(D_NORMAL, "IO address %x empty\n", ioaddr); arc_printk(D_NORMAL, dev, "IO address %x empty\n", ioaddr);
err = -ENODEV; err = -ENODEV;
goto out; goto out;
} }
...@@ -83,23 +82,24 @@ static int __init com20020isa_probe(struct net_device *dev) ...@@ -83,23 +82,24 @@ static int __init com20020isa_probe(struct net_device *dev)
* card has just reset and the NORXflag is on until * card has just reset and the NORXflag is on until
* we tell it to start receiving. * we tell it to start receiving.
*/ */
BUGMSG(D_INIT_REASONS, "intmask was %02Xh\n", inb(_INTMASK)); arc_printk(D_INIT_REASONS, dev, "intmask was %02Xh\n",
outb(0, _INTMASK); arcnet_inb(ioaddr, COM20020_REG_R_STATUS));
arcnet_outb(0, ioaddr, COM20020_REG_W_INTMASK);
airqmask = probe_irq_on(); airqmask = probe_irq_on();
outb(NORXflag, _INTMASK); arcnet_outb(NORXflag, ioaddr, COM20020_REG_W_INTMASK);
udelay(1); udelay(1);
outb(0, _INTMASK); arcnet_outb(0, ioaddr, COM20020_REG_W_INTMASK);
dev->irq = probe_irq_off(airqmask); dev->irq = probe_irq_off(airqmask);
if ((int)dev->irq <= 0) { if ((int)dev->irq <= 0) {
BUGMSG(D_INIT_REASONS, "Autoprobe IRQ failed first time\n"); arc_printk(D_INIT_REASONS, dev, "Autoprobe IRQ failed first time\n");
airqmask = probe_irq_on(); airqmask = probe_irq_on();
outb(NORXflag, _INTMASK); arcnet_outb(NORXflag, ioaddr, COM20020_REG_W_INTMASK);
udelay(5); udelay(5);
outb(0, _INTMASK); arcnet_outb(0, ioaddr, COM20020_REG_W_INTMASK);
dev->irq = probe_irq_off(airqmask); dev->irq = probe_irq_off(airqmask);
if ((int)dev->irq <= 0) { if ((int)dev->irq <= 0) {
BUGMSG(D_NORMAL, "Autoprobe IRQ failed.\n"); arc_printk(D_NORMAL, dev, "Autoprobe IRQ failed.\n");
err = -ENODEV; err = -ENODEV;
goto out; goto out;
} }
...@@ -107,7 +107,9 @@ static int __init com20020isa_probe(struct net_device *dev) ...@@ -107,7 +107,9 @@ static int __init com20020isa_probe(struct net_device *dev)
} }
lp->card_name = "ISA COM20020"; lp->card_name = "ISA COM20020";
if ((err = com20020_found(dev, 0)) != 0)
err = com20020_found(dev, 0);
if (err != 0)
goto out; goto out;
return 0; return 0;
...@@ -194,7 +196,7 @@ static int __init com20020isa_setup(char *s) ...@@ -194,7 +196,7 @@ static int __init com20020isa_setup(char *s)
switch (ints[0]) { switch (ints[0]) {
default: /* ERROR */ default: /* ERROR */
printk("com90xx: Too many arguments.\n"); pr_info("Too many arguments\n");
case 6: /* Timeout */ case 6: /* Timeout */
timeout = ints[6]; timeout = ints[6];
case 5: /* CKP value */ case 5: /* CKP value */
......
/* /*
* Linux ARCnet driver - COM20020 PCI support * Linux ARCnet driver - COM20020 PCI support
* Contemporary Controls PCI20 and SOHARD SH-ARC PCI * Contemporary Controls PCI20 and SOHARD SH-ARC PCI
* *
* Written 1994-1999 by Avery Pennarun, * Written 1994-1999 by Avery Pennarun,
* based on an ISA version by David Woodhouse. * based on an ISA version by David Woodhouse.
* Written 1999-2000 by Martin Mares <mj@ucw.cz>. * Written 1999-2000 by Martin Mares <mj@ucw.cz>.
...@@ -26,6 +26,9 @@ ...@@ -26,6 +26,9 @@
* *
* ********************** * **********************
*/ */
#define pr_fmt(fmt) "arcnet:" KBUILD_MODNAME ": " fmt
#include <linux/module.h> #include <linux/module.h>
#include <linux/moduleparam.h> #include <linux/moduleparam.h>
#include <linux/kernel.h> #include <linux/kernel.h>
...@@ -36,14 +39,11 @@ ...@@ -36,14 +39,11 @@
#include <linux/init.h> #include <linux/init.h>
#include <linux/interrupt.h> #include <linux/interrupt.h>
#include <linux/pci.h> #include <linux/pci.h>
#include <linux/arcdevice.h>
#include <linux/com20020.h>
#include <linux/list.h> #include <linux/list.h>
#include <linux/io.h>
#include <asm/io.h> #include "arcdevice.h"
#include "com20020.h"
#define VERSION "arcnet: COM20020 PCI support\n"
/* Module parameters */ /* Module parameters */
...@@ -64,7 +64,8 @@ MODULE_LICENSE("GPL"); ...@@ -64,7 +64,8 @@ MODULE_LICENSE("GPL");
static void com20020pci_remove(struct pci_dev *pdev); static void com20020pci_remove(struct pci_dev *pdev);
static int com20020pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) static int com20020pci_probe(struct pci_dev *pdev,
const struct pci_device_id *id)
{ {
struct com20020_pci_card_info *ci; struct com20020_pci_card_info *ci;
struct net_device *dev; struct net_device *dev;
...@@ -86,7 +87,6 @@ static int com20020pci_probe(struct pci_dev *pdev, const struct pci_device_id *i ...@@ -86,7 +87,6 @@ static int com20020pci_probe(struct pci_dev *pdev, const struct pci_device_id *i
INIT_LIST_HEAD(&priv->list_dev); INIT_LIST_HEAD(&priv->list_dev);
for (i = 0; i < ci->devcount; i++) { for (i = 0; i < ci->devcount; i++) {
struct com20020_pci_channel_map *cm = &ci->chan_map_tbl[i]; struct com20020_pci_channel_map *cm = &ci->chan_map_tbl[i];
struct com20020_dev *card; struct com20020_dev *card;
...@@ -101,13 +101,13 @@ static int com20020pci_probe(struct pci_dev *pdev, const struct pci_device_id *i ...@@ -101,13 +101,13 @@ static int com20020pci_probe(struct pci_dev *pdev, const struct pci_device_id *i
lp = netdev_priv(dev); lp = netdev_priv(dev);
BUGMSG(D_NORMAL, "%s Controls\n", ci->name); arc_printk(D_NORMAL, dev, "%s Controls\n", ci->name);
ioaddr = pci_resource_start(pdev, cm->bar) + cm->offset; ioaddr = pci_resource_start(pdev, cm->bar) + cm->offset;
r = devm_request_region(&pdev->dev, ioaddr, cm->size, r = devm_request_region(&pdev->dev, ioaddr, cm->size,
"com20020-pci"); "com20020-pci");
if (!r) { if (!r) {
pr_err("IO region %xh-%xh already allocated.\n", pr_err("IO region %xh-%xh already allocated\n",
ioaddr, ioaddr + cm->size - 1); ioaddr, ioaddr + cm->size - 1);
ret = -EBUSY; ret = -EBUSY;
goto out_port; goto out_port;
...@@ -117,8 +117,8 @@ static int com20020pci_probe(struct pci_dev *pdev, const struct pci_device_id *i ...@@ -117,8 +117,8 @@ static int com20020pci_probe(struct pci_dev *pdev, const struct pci_device_id *i
* ARCNET controller needs * ARCNET controller needs
* this access to detect bustype * this access to detect bustype
*/ */
outb(0x00, ioaddr + 1); arcnet_outb(0x00, ioaddr, COM20020_REG_W_COMMAND);
inb(ioaddr + 1); arcnet_inb(ioaddr, COM20020_REG_R_DIAGSTAT);
dev->base_addr = ioaddr; dev->base_addr = ioaddr;
dev->dev_addr[0] = node; dev->dev_addr[0] = node;
...@@ -131,7 +131,7 @@ static int com20020pci_probe(struct pci_dev *pdev, const struct pci_device_id *i ...@@ -131,7 +131,7 @@ static int com20020pci_probe(struct pci_dev *pdev, const struct pci_device_id *i
lp->timeout = timeout; lp->timeout = timeout;
lp->hw.owner = THIS_MODULE; lp->hw.owner = THIS_MODULE;
if (ASTATUS() == 0xFF) { if (arcnet_inb(ioaddr, COM20020_REG_R_STATUS) == 0xFF) {
pr_err("IO address %Xh is empty!\n", ioaddr); pr_err("IO address %Xh is empty!\n", ioaddr);
ret = -EIO; ret = -EIO;
goto out_port; goto out_port;
...@@ -143,10 +143,8 @@ static int com20020pci_probe(struct pci_dev *pdev, const struct pci_device_id *i ...@@ -143,10 +143,8 @@ static int com20020pci_probe(struct pci_dev *pdev, const struct pci_device_id *i
card = devm_kzalloc(&pdev->dev, sizeof(struct com20020_dev), card = devm_kzalloc(&pdev->dev, sizeof(struct com20020_dev),
GFP_KERNEL); GFP_KERNEL);
if (!card) { if (!card)
pr_err("%s out of memory!\n", __func__);
return -ENOMEM; return -ENOMEM;
}
card->index = i; card->index = i;
card->pci_priv = priv; card->pci_priv = priv;
...@@ -190,7 +188,11 @@ static struct com20020_pci_card_info card_info_10mbit = { ...@@ -190,7 +188,11 @@ static struct com20020_pci_card_info card_info_10mbit = {
.name = "ARC-PCI", .name = "ARC-PCI",
.devcount = 1, .devcount = 1,
.chan_map_tbl = { .chan_map_tbl = {
{ 2, 0x00, 0x08 }, {
.bar = 2,
.offset = 0x00,
.size = 0x08,
},
}, },
.flags = ARC_CAN_10MBIT, .flags = ARC_CAN_10MBIT,
}; };
...@@ -199,7 +201,11 @@ static struct com20020_pci_card_info card_info_5mbit = { ...@@ -199,7 +201,11 @@ static struct com20020_pci_card_info card_info_5mbit = {
.name = "ARC-PCI", .name = "ARC-PCI",
.devcount = 1, .devcount = 1,
.chan_map_tbl = { .chan_map_tbl = {
{ 2, 0x00, 0x08 }, {
.bar = 2,
.offset = 0x00,
.size = 0x08,
},
}, },
.flags = ARC_IS_5MBIT, .flags = ARC_IS_5MBIT,
}; };
...@@ -209,7 +215,11 @@ static struct com20020_pci_card_info card_info_sohard = { ...@@ -209,7 +215,11 @@ static struct com20020_pci_card_info card_info_sohard = {
.devcount = 1, .devcount = 1,
/* SOHARD needs PCI base addr 4 */ /* SOHARD needs PCI base addr 4 */
.chan_map_tbl = { .chan_map_tbl = {
{4, 0x00, 0x08}, {
.bar = 4,
.offset = 0x00,
.size = 0x08
},
}, },
.flags = ARC_CAN_10MBIT, .flags = ARC_CAN_10MBIT,
}; };
...@@ -218,7 +228,11 @@ static struct com20020_pci_card_info card_info_eae_arc1 = { ...@@ -218,7 +228,11 @@ static struct com20020_pci_card_info card_info_eae_arc1 = {
.name = "EAE PLX-PCI ARC1", .name = "EAE PLX-PCI ARC1",
.devcount = 1, .devcount = 1,
.chan_map_tbl = { .chan_map_tbl = {
{ 2, 0x00, 0x08 }, {
.bar = 2,
.offset = 0x00,
.size = 0x08,
},
}, },
.flags = ARC_CAN_10MBIT, .flags = ARC_CAN_10MBIT,
}; };
...@@ -227,8 +241,15 @@ static struct com20020_pci_card_info card_info_eae_ma1 = { ...@@ -227,8 +241,15 @@ static struct com20020_pci_card_info card_info_eae_ma1 = {
.name = "EAE PLX-PCI MA1", .name = "EAE PLX-PCI MA1",
.devcount = 2, .devcount = 2,
.chan_map_tbl = { .chan_map_tbl = {
{ 2, 0x00, 0x08 }, {
{ 2, 0x08, 0x08 } .bar = 2,
.offset = 0x00,
.size = 0x08,
}, {
.bar = 2,
.offset = 0x08,
.size = 0x08,
}
}, },
.flags = ARC_CAN_10MBIT, .flags = ARC_CAN_10MBIT,
}; };
...@@ -404,7 +425,8 @@ static struct pci_driver com20020pci_driver = { ...@@ -404,7 +425,8 @@ static struct pci_driver com20020pci_driver = {
static int __init com20020pci_init(void) static int __init com20020pci_init(void)
{ {
BUGLVL(D_NORMAL) printk(VERSION); if (BUGLVL(D_NORMAL))
pr_info("%s\n", "COM20020 PCI support");
return pci_register_driver(&com20020pci_driver); return pci_register_driver(&com20020pci_driver);
} }
......
/* /*
* Linux ARCnet driver - COM20020 chipset support * Linux ARCnet driver - COM20020 chipset support
* *
* Written 1997 by David Woodhouse. * Written 1997 by David Woodhouse.
* Written 1994-1999 by Avery Pennarun. * Written 1994-1999 by Avery Pennarun.
* Written 1999 by Martin Mares <mj@ucw.cz>. * Written 1999 by Martin Mares <mj@ucw.cz>.
...@@ -25,6 +25,9 @@ ...@@ -25,6 +25,9 @@
* *
* ********************** * **********************
*/ */
#define pr_fmt(fmt) "arcnet:" KBUILD_MODNAME ": " fmt
#include <linux/module.h> #include <linux/module.h>
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/types.h> #include <linux/types.h>
...@@ -34,17 +37,16 @@ ...@@ -34,17 +37,16 @@
#include <linux/netdevice.h> #include <linux/netdevice.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/interrupt.h> #include <linux/interrupt.h>
#include <linux/arcdevice.h> #include <linux/io.h>
#include <linux/com20020.h>
#include <asm/io.h> #include "arcdevice.h"
#include "com20020.h"
#define VERSION "arcnet: COM20020 chipset support (by David Woodhouse et al.)\n" static const char * const clockrates[] = {
"XXXXXXX", "XXXXXXXX", "XXXXXX", "2.5 Mb/s",
static char *clockrates[] = "1.25Mb/s", "625 Kb/s", "312.5 Kb/s", "156.25 Kb/s",
{"10 Mb/s", "Reserved", "5 Mb/s", "Reserved", "Reserved", "Reserved"
"2.5 Mb/s", "1.25Mb/s", "625 Kb/s", "312.5 Kb/s", };
"156.25 Kb/s", "Reserved", "Reserved", "Reserved"};
static void com20020_command(struct net_device *dev, int command); static void com20020_command(struct net_device *dev, int command);
static int com20020_status(struct net_device *dev); static int com20020_status(struct net_device *dev);
...@@ -63,35 +65,38 @@ static void com20020_copy_from_card(struct net_device *dev, int bufnum, ...@@ -63,35 +65,38 @@ static void com20020_copy_from_card(struct net_device *dev, int bufnum,
int ioaddr = dev->base_addr, ofs = 512 * bufnum + offset; int ioaddr = dev->base_addr, ofs = 512 * bufnum + offset;
/* set up the address register */ /* set up the address register */
outb((ofs >> 8) | RDDATAflag | AUTOINCflag, _ADDR_HI); arcnet_outb((ofs >> 8) | RDDATAflag | AUTOINCflag,
outb(ofs & 0xff, _ADDR_LO); ioaddr, COM20020_REG_W_ADDR_HI);
arcnet_outb(ofs & 0xff, ioaddr, COM20020_REG_W_ADDR_LO);
/* copy the data */ /* copy the data */
TIME("insb", count, insb(_MEMDATA, buf, count)); TIME(dev, "insb", count,
arcnet_insb(ioaddr, COM20020_REG_RW_MEMDATA, buf, count));
} }
static void com20020_copy_to_card(struct net_device *dev, int bufnum, static void com20020_copy_to_card(struct net_device *dev, int bufnum,
int offset, void *buf, int count) int offset, void *buf, int count)
{ {
int ioaddr = dev->base_addr, ofs = 512 * bufnum + offset; int ioaddr = dev->base_addr, ofs = 512 * bufnum + offset;
/* set up the address register */ /* set up the address register */
outb((ofs >> 8) | AUTOINCflag, _ADDR_HI); arcnet_outb((ofs >> 8) | AUTOINCflag, ioaddr, COM20020_REG_W_ADDR_HI);
outb(ofs & 0xff, _ADDR_LO); arcnet_outb(ofs & 0xff, ioaddr, COM20020_REG_W_ADDR_LO);
/* copy the data */ /* copy the data */
TIME("outsb", count, outsb(_MEMDATA, buf, count)); TIME(dev, "outsb", count,
arcnet_outsb(ioaddr, COM20020_REG_RW_MEMDATA, buf, count));
} }
/* Reset the card and check some basic stuff during the detection stage. */ /* Reset the card and check some basic stuff during the detection stage. */
int com20020_check(struct net_device *dev) int com20020_check(struct net_device *dev)
{ {
int ioaddr = dev->base_addr, status; int ioaddr = dev->base_addr, status;
struct arcnet_local *lp = netdev_priv(dev); struct arcnet_local *lp = netdev_priv(dev);
ARCRESET0; arcnet_outb(XTOcfg(3) | RESETcfg, ioaddr, COM20020_REG_W_CONFIG);
udelay(5);
arcnet_outb(XTOcfg(3), ioaddr, COM20020_REG_W_CONFIG);
mdelay(RESETtime); mdelay(RESETtime);
lp->setup = lp->clockm ? 0 : (lp->clockp << 1); lp->setup = lp->clockm ? 0 : (lp->clockp << 1);
...@@ -101,49 +106,51 @@ int com20020_check(struct net_device *dev) ...@@ -101,49 +106,51 @@ int com20020_check(struct net_device *dev)
/* Enable P1Mode for backplane mode */ /* Enable P1Mode for backplane mode */
lp->setup = lp->setup | P1MODE; lp->setup = lp->setup | P1MODE;
SET_SUBADR(SUB_SETUP1); com20020_set_subaddress(lp, ioaddr, SUB_SETUP1);
outb(lp->setup, _XREG); arcnet_outb(lp->setup, ioaddr, COM20020_REG_W_XREG);
if (lp->clockm != 0) {
com20020_set_subaddress(lp, ioaddr, SUB_SETUP2);
arcnet_outb(lp->setup2, ioaddr, COM20020_REG_W_XREG);
if (lp->clockm != 0)
{
SET_SUBADR(SUB_SETUP2);
outb(lp->setup2, _XREG);
/* must now write the magic "restart operation" command */ /* must now write the magic "restart operation" command */
mdelay(1); mdelay(1);
outb(0x18, _COMMAND); arcnet_outb(STARTIOcmd, ioaddr, COM20020_REG_W_COMMAND);
} }
lp->config = 0x21 | (lp->timeout << 3) | (lp->backplane << 2); lp->config = TXENcfg | (lp->timeout << 3) | (lp->backplane << 2) | SUB_NODE;
/* set node ID to 0x42 (but transmitter is disabled, so it's okay) */ /* set node ID to 0x42 (but transmitter is disabled, so it's okay) */
SETCONF; arcnet_outb(lp->config, ioaddr, COM20020_REG_W_CONFIG);
outb(0x42, ioaddr + BUS_ALIGN*7); arcnet_outb(0x42, ioaddr, COM20020_REG_W_XREG);
status = ASTATUS(); status = arcnet_inb(ioaddr, COM20020_REG_R_STATUS);
if ((status & 0x99) != (NORXflag | TXFREEflag | RESETflag)) { if ((status & 0x99) != (NORXflag | TXFREEflag | RESETflag)) {
BUGMSG(D_NORMAL, "status invalid (%Xh).\n", status); arc_printk(D_NORMAL, dev, "status invalid (%Xh).\n", status);
return -ENODEV; return -ENODEV;
} }
BUGMSG(D_INIT_REASONS, "status after reset: %X\n", status); arc_printk(D_INIT_REASONS, dev, "status after reset: %X\n", status);
/* Enable TX */ /* Enable TX */
outb(0x39, _CONFIG); lp->config |= TXENcfg;
outb(inb(ioaddr + BUS_ALIGN*8), ioaddr + BUS_ALIGN*7); arcnet_outb(lp->config, ioaddr, COM20020_REG_W_CONFIG);
arcnet_outb(arcnet_inb(ioaddr, 8), ioaddr, COM20020_REG_W_XREG);
ACOMMAND(CFLAGScmd | RESETclear | CONFIGclear); arcnet_outb(CFLAGScmd | RESETclear | CONFIGclear,
ioaddr, COM20020_REG_W_COMMAND);
status = ASTATUS(); status = arcnet_inb(ioaddr, COM20020_REG_R_STATUS);
BUGMSG(D_INIT_REASONS, "status after reset acknowledged: %X\n", arc_printk(D_INIT_REASONS, dev, "status after reset acknowledged: %X\n",
status); status);
/* Read first location of memory */ /* Read first location of memory */
outb(0 | RDDATAflag | AUTOINCflag, _ADDR_HI); arcnet_outb(0 | RDDATAflag | AUTOINCflag,
outb(0, _ADDR_LO); ioaddr, COM20020_REG_W_ADDR_HI);
arcnet_outb(0, ioaddr, COM20020_REG_W_ADDR_LO);
if ((status = inb(_MEMDATA)) != TESTvalue) {
BUGMSG(D_NORMAL, "Signature byte not found (%02Xh != D1h).\n", status = arcnet_inb(ioaddr, COM20020_REG_RW_MEMDATA);
status); if (status != TESTvalue) {
arc_printk(D_NORMAL, dev, "Signature byte not found (%02Xh != D1h).\n",
status);
return -ENODEV; return -ENODEV;
} }
return 0; return 0;
...@@ -156,8 +163,8 @@ static int com20020_set_hwaddr(struct net_device *dev, void *addr) ...@@ -156,8 +163,8 @@ static int com20020_set_hwaddr(struct net_device *dev, void *addr)
struct sockaddr *hwaddr = addr; struct sockaddr *hwaddr = addr;
memcpy(dev->dev_addr, hwaddr->sa_data, 1); memcpy(dev->dev_addr, hwaddr->sa_data, 1);
SET_SUBADR(SUB_NODE); com20020_set_subaddress(lp, ioaddr, SUB_NODE);
outb(dev->dev_addr[0], _XREG); arcnet_outb(dev->dev_addr[0], ioaddr, COM20020_REG_W_XREG);
return 0; return 0;
} }
...@@ -192,48 +199,54 @@ int com20020_found(struct net_device *dev, int shared) ...@@ -192,48 +199,54 @@ int com20020_found(struct net_device *dev, int shared)
lp->hw.copy_from_card = com20020_copy_from_card; lp->hw.copy_from_card = com20020_copy_from_card;
lp->hw.close = com20020_close; lp->hw.close = com20020_close;
/* FIXME: do this some other way! */
if (!dev->dev_addr[0]) if (!dev->dev_addr[0])
dev->dev_addr[0] = inb(ioaddr + BUS_ALIGN*8); /* FIXME: do this some other way! */ dev->dev_addr[0] = arcnet_inb(ioaddr, 8);
SET_SUBADR(SUB_SETUP1); com20020_set_subaddress(lp, ioaddr, SUB_SETUP1);
outb(lp->setup, _XREG); arcnet_outb(lp->setup, ioaddr, COM20020_REG_W_XREG);
if (lp->card_flags & ARC_CAN_10MBIT) {
com20020_set_subaddress(lp, ioaddr, SUB_SETUP2);
arcnet_outb(lp->setup2, ioaddr, COM20020_REG_W_XREG);
if (lp->card_flags & ARC_CAN_10MBIT)
{
SET_SUBADR(SUB_SETUP2);
outb(lp->setup2, _XREG);
/* must now write the magic "restart operation" command */ /* must now write the magic "restart operation" command */
mdelay(1); mdelay(1);
outb(0x18, _COMMAND); arcnet_outb(STARTIOcmd, ioaddr, COM20020_REG_W_COMMAND);
} }
lp->config = 0x20 | (lp->timeout << 3) | (lp->backplane << 2) | 1; lp->config = TXENcfg | (lp->timeout << 3) | (lp->backplane << 2) | SUB_NODE;
/* Default 0x38 + register: Node ID */ /* Default 0x38 + register: Node ID */
SETCONF; arcnet_outb(lp->config, ioaddr, COM20020_REG_W_CONFIG);
outb(dev->dev_addr[0], _XREG); arcnet_outb(dev->dev_addr[0], ioaddr, COM20020_REG_W_XREG);
/* reserve the irq */ /* reserve the irq */
if (request_irq(dev->irq, arcnet_interrupt, shared, if (request_irq(dev->irq, arcnet_interrupt, shared,
"arcnet (COM20020)", dev)) { "arcnet (COM20020)", dev)) {
BUGMSG(D_NORMAL, "Can't get IRQ %d!\n", dev->irq); arc_printk(D_NORMAL, dev, "Can't get IRQ %d!\n", dev->irq);
return -ENODEV; return -ENODEV;
} }
dev->base_addr = ioaddr; dev->base_addr = ioaddr;
BUGMSG(D_NORMAL, "%s: station %02Xh found at %03lXh, IRQ %d.\n", arc_printk(D_NORMAL, dev, "%s: station %02Xh found at %03lXh, IRQ %d.\n",
lp->card_name, dev->dev_addr[0], dev->base_addr, dev->irq); lp->card_name, dev->dev_addr[0], dev->base_addr, dev->irq);
if (lp->backplane) if (lp->backplane)
BUGMSG(D_NORMAL, "Using backplane mode.\n"); arc_printk(D_NORMAL, dev, "Using backplane mode.\n");
if (lp->timeout != 3) if (lp->timeout != 3)
BUGMSG(D_NORMAL, "Using extended timeout value of %d.\n", lp->timeout); arc_printk(D_NORMAL, dev, "Using extended timeout value of %d\n",
lp->timeout);
BUGMSG(D_NORMAL, "Using CKP %d - data rate %s.\n",
lp->setup >> 1, arc_printk(D_NORMAL, dev, "Using CKP %d - data rate %s\n",
clockrates[3 - ((lp->setup2 & 0xF0) >> 4) + ((lp->setup & 0x0F) >> 1)]); lp->setup >> 1,
clockrates[3 -
((lp->setup2 & 0xF0) >> 4) +
((lp->setup & 0x0F) >> 1)]);
/* The clockrates array index looks very fragile.
* It seems like it could have negative indexing.
*/
if (register_netdev(dev)) { if (register_netdev(dev)) {
free_irq(dev->irq, dev); free_irq(dev->irq, dev);
...@@ -242,10 +255,8 @@ int com20020_found(struct net_device *dev, int shared) ...@@ -242,10 +255,8 @@ int com20020_found(struct net_device *dev, int shared)
return 0; return 0;
} }
/* Do a hardware reset on the card, and set up necessary registers.
/* *
* Do a hardware reset on the card, and set up necessary registers.
*
* This should be called as little as possible, because it disrupts the * This should be called as little as possible, because it disrupts the
* token on the network (causes a RECON) and requires a significant delay. * token on the network (causes a RECON) and requires a significant delay.
* *
...@@ -257,65 +268,71 @@ static int com20020_reset(struct net_device *dev, int really_reset) ...@@ -257,65 +268,71 @@ static int com20020_reset(struct net_device *dev, int really_reset)
u_int ioaddr = dev->base_addr; u_int ioaddr = dev->base_addr;
u_char inbyte; u_char inbyte;
BUGMSG(D_DEBUG, "%s: %d: %s: dev: %p, lp: %p, dev->name: %s\n", arc_printk(D_DEBUG, dev, "%s: %d: %s: dev: %p, lp: %p, dev->name: %s\n",
__FILE__,__LINE__,__func__,dev,lp,dev->name); __FILE__, __LINE__, __func__, dev, lp, dev->name);
BUGMSG(D_INIT, "Resetting %s (status=%02Xh)\n", arc_printk(D_INIT, dev, "Resetting %s (status=%02Xh)\n",
dev->name, ASTATUS()); dev->name, arcnet_inb(ioaddr, COM20020_REG_R_STATUS));
BUGMSG(D_DEBUG, "%s: %d: %s\n",__FILE__,__LINE__,__func__); arc_printk(D_DEBUG, dev, "%s: %d: %s\n", __FILE__, __LINE__, __func__);
lp->config = TXENcfg | (lp->timeout << 3) | (lp->backplane << 2); lp->config = TXENcfg | (lp->timeout << 3) | (lp->backplane << 2);
/* power-up defaults */ /* power-up defaults */
SETCONF; arcnet_outb(lp->config, ioaddr, COM20020_REG_W_CONFIG);
BUGMSG(D_DEBUG, "%s: %d: %s\n",__FILE__,__LINE__,__func__); arc_printk(D_DEBUG, dev, "%s: %d: %s\n", __FILE__, __LINE__, __func__);
if (really_reset) { if (really_reset) {
/* reset the card */ /* reset the card */
ARCRESET; arcnet_outb(lp->config | RESETcfg, ioaddr, COM20020_REG_W_CONFIG);
mdelay(RESETtime * 2); /* COM20020 seems to be slower sometimes */ udelay(5);
arcnet_outb(lp->config, ioaddr, COM20020_REG_W_CONFIG);
mdelay(RESETtime * 2);
/* COM20020 seems to be slower sometimes */
} }
/* clear flags & end reset */ /* clear flags & end reset */
BUGMSG(D_DEBUG, "%s: %d: %s\n",__FILE__,__LINE__,__func__); arc_printk(D_DEBUG, dev, "%s: %d: %s\n", __FILE__, __LINE__, __func__);
ACOMMAND(CFLAGScmd | RESETclear | CONFIGclear); arcnet_outb(CFLAGScmd | RESETclear | CONFIGclear,
ioaddr, COM20020_REG_W_COMMAND);
/* verify that the ARCnet signature byte is present */ /* verify that the ARCnet signature byte is present */
BUGMSG(D_DEBUG, "%s: %d: %s\n",__FILE__,__LINE__,__func__); arc_printk(D_DEBUG, dev, "%s: %d: %s\n", __FILE__, __LINE__, __func__);
com20020_copy_from_card(dev, 0, 0, &inbyte, 1); com20020_copy_from_card(dev, 0, 0, &inbyte, 1);
BUGMSG(D_DEBUG, "%s: %d: %s\n",__FILE__,__LINE__,__func__); arc_printk(D_DEBUG, dev, "%s: %d: %s\n", __FILE__, __LINE__, __func__);
if (inbyte != TESTvalue) { if (inbyte != TESTvalue) {
BUGMSG(D_DEBUG, "%s: %d: %s\n",__FILE__,__LINE__,__func__); arc_printk(D_DEBUG, dev, "%s: %d: %s\n",
BUGMSG(D_NORMAL, "reset failed: TESTvalue not present.\n"); __FILE__, __LINE__, __func__);
arc_printk(D_NORMAL, dev, "reset failed: TESTvalue not present.\n");
return 1; return 1;
} }
/* enable extended (512-byte) packets */ /* enable extended (512-byte) packets */
ACOMMAND(CONFIGcmd | EXTconf); arcnet_outb(CONFIGcmd | EXTconf, ioaddr, COM20020_REG_W_COMMAND);
BUGMSG(D_DEBUG, "%s: %d: %s\n",__FILE__,__LINE__,__func__);
arc_printk(D_DEBUG, dev, "%s: %d: %s\n", __FILE__, __LINE__, __func__);
/* done! return success. */ /* done! return success. */
return 0; return 0;
} }
static void com20020_setmask(struct net_device *dev, int mask) static void com20020_setmask(struct net_device *dev, int mask)
{ {
u_int ioaddr = dev->base_addr; u_int ioaddr = dev->base_addr;
BUGMSG(D_DURING, "Setting mask to %x at %x\n",mask,ioaddr);
AINTMASK(mask);
}
arc_printk(D_DURING, dev, "Setting mask to %x at %x\n", mask, ioaddr);
arcnet_outb(mask, ioaddr, COM20020_REG_W_INTMASK);
}
static void com20020_command(struct net_device *dev, int cmd) static void com20020_command(struct net_device *dev, int cmd)
{ {
u_int ioaddr = dev->base_addr; u_int ioaddr = dev->base_addr;
ACOMMAND(cmd);
}
arcnet_outb(cmd, ioaddr, COM20020_REG_W_COMMAND);
}
static int com20020_status(struct net_device *dev) static int com20020_status(struct net_device *dev)
{ {
u_int ioaddr = dev->base_addr; u_int ioaddr = dev->base_addr;
return ASTATUS() + (ADIAGSTATUS()<<8); return arcnet_inb(ioaddr, COM20020_REG_R_STATUS) +
(arcnet_inb(ioaddr, COM20020_REG_R_DIAGSTAT) << 8);
} }
static void com20020_close(struct net_device *dev) static void com20020_close(struct net_device *dev)
...@@ -325,7 +342,7 @@ static void com20020_close(struct net_device *dev) ...@@ -325,7 +342,7 @@ static void com20020_close(struct net_device *dev)
/* disable transmitter */ /* disable transmitter */
lp->config &= ~TXENcfg; lp->config &= ~TXENcfg;
SETCONF; arcnet_outb(lp->config, ioaddr, COM20020_REG_W_CONFIG);
} }
/* Set or clear the multicast filter for this adaptor. /* Set or clear the multicast filter for this adaptor.
...@@ -340,20 +357,20 @@ static void com20020_set_mc_list(struct net_device *dev) ...@@ -340,20 +357,20 @@ static void com20020_set_mc_list(struct net_device *dev)
struct arcnet_local *lp = netdev_priv(dev); struct arcnet_local *lp = netdev_priv(dev);
int ioaddr = dev->base_addr; int ioaddr = dev->base_addr;
if ((dev->flags & IFF_PROMISC) && (dev->flags & IFF_UP)) { /* Enable promiscuous mode */ if ((dev->flags & IFF_PROMISC) && (dev->flags & IFF_UP)) {
/* Enable promiscuous mode */
if (!(lp->setup & PROMISCset)) if (!(lp->setup & PROMISCset))
BUGMSG(D_NORMAL, "Setting promiscuous flag...\n"); arc_printk(D_NORMAL, dev, "Setting promiscuous flag...\n");
SET_SUBADR(SUB_SETUP1); com20020_set_subaddress(lp, ioaddr, SUB_SETUP1);
lp->setup |= PROMISCset; lp->setup |= PROMISCset;
outb(lp->setup, _XREG); arcnet_outb(lp->setup, ioaddr, COM20020_REG_W_XREG);
} else } else {
/* Disable promiscuous mode, use normal mode */ /* Disable promiscuous mode, use normal mode */
{
if ((lp->setup & PROMISCset)) if ((lp->setup & PROMISCset))
BUGMSG(D_NORMAL, "Resetting promiscuous flag...\n"); arc_printk(D_NORMAL, dev, "Resetting promiscuous flag...\n");
SET_SUBADR(SUB_SETUP1); com20020_set_subaddress(lp, ioaddr, SUB_SETUP1);
lp->setup &= ~PROMISCset; lp->setup &= ~PROMISCset;
outb(lp->setup, _XREG); arcnet_outb(lp->setup, ioaddr, COM20020_REG_W_XREG);
} }
} }
...@@ -371,7 +388,8 @@ MODULE_LICENSE("GPL"); ...@@ -371,7 +388,8 @@ MODULE_LICENSE("GPL");
static int __init com20020_module_init(void) static int __init com20020_module_init(void)
{ {
BUGLVL(D_NORMAL) printk(VERSION); if (BUGLVL(D_NORMAL))
pr_info("%s\n", "COM20020 chipset support (by David Woodhouse et al.)");
return 0; return 0;
} }
......
/* /*
* Linux ARCnet driver - COM20020 chipset support - function declarations * Linux ARCnet driver - COM20020 chipset support - function declarations
* *
* Written 1997 by David Woodhouse. * Written 1997 by David Woodhouse.
* Written 1994-1999 by Avery Pennarun. * Written 1994-1999 by Avery Pennarun.
* Derived from skeleton.c by Donald Becker. * Derived from skeleton.c by Donald Becker.
...@@ -34,13 +34,6 @@ extern const struct net_device_ops com20020_netdev_ops; ...@@ -34,13 +34,6 @@ extern const struct net_device_ops com20020_netdev_ops;
/* The number of low I/O ports used by the card. */ /* The number of low I/O ports used by the card. */
#define ARCNET_TOTAL_SIZE 8 #define ARCNET_TOTAL_SIZE 8
/* various register addresses */
#ifdef CONFIG_SA1100_CT6001
#define BUS_ALIGN 2 /* 8 bit device on a 16 bit bus - needs padding */
#else
#define BUS_ALIGN 1
#endif
#define PLX_PCI_MAX_CARDS 2 #define PLX_PCI_MAX_CARDS 2
struct com20020_pci_channel_map { struct com20020_pci_channel_map {
...@@ -71,17 +64,18 @@ struct com20020_dev { ...@@ -71,17 +64,18 @@ struct com20020_dev {
int index; int index;
}; };
#define _INTMASK (ioaddr+BUS_ALIGN*0) /* writable */ #define COM20020_REG_W_INTMASK 0 /* writable */
#define _STATUS (ioaddr+BUS_ALIGN*0) /* readable */ #define COM20020_REG_R_STATUS 0 /* readable */
#define _COMMAND (ioaddr+BUS_ALIGN*1) /* standard arcnet commands */ #define COM20020_REG_W_COMMAND 1 /* standard arcnet commands */
#define _DIAGSTAT (ioaddr+BUS_ALIGN*1) /* diagnostic status register */ #define COM20020_REG_R_DIAGSTAT 1 /* diagnostic status */
#define _ADDR_HI (ioaddr+BUS_ALIGN*2) /* control registers for IO-mapped memory */ #define COM20020_REG_W_ADDR_HI 2 /* control for IO-mapped memory */
#define _ADDR_LO (ioaddr+BUS_ALIGN*3) #define COM20020_REG_W_ADDR_LO 3
#define _MEMDATA (ioaddr+BUS_ALIGN*4) /* data port for IO-mapped memory */ #define COM20020_REG_RW_MEMDATA 4 /* data port for IO-mapped memory */
#define _SUBADR (ioaddr+BUS_ALIGN*5) /* the extended port _XREG refers to */ #define COM20020_REG_W_SUBADR 5 /* the extended port _XREG refers to */
#define _CONFIG (ioaddr+BUS_ALIGN*6) /* configuration register */ #define COM20020_REG_W_CONFIG 6 /* configuration */
#define _XREG (ioaddr+BUS_ALIGN*7) /* extra registers (indexed by _CONFIG #define COM20020_REG_W_XREG 7 /* extra
or _SUBADR) */ * (indexed by _CONFIG or _SUBADDR)
*/
/* in the ADDR_HI register */ /* in the ADDR_HI register */
#define RDDATAflag 0x80 /* next access is a read (not a write) */ #define RDDATAflag 0x80 /* next access is a read (not a write) */
...@@ -92,6 +86,7 @@ struct com20020_dev { ...@@ -92,6 +86,7 @@ struct com20020_dev {
/* in the CONFIG register */ /* in the CONFIG register */
#define RESETcfg 0x80 /* put card in reset state */ #define RESETcfg 0x80 /* put card in reset state */
#define TXENcfg 0x20 /* enable TX */ #define TXENcfg 0x20 /* enable TX */
#define XTOcfg(x) ((x) << 3) /* extended timeout */
/* in SETUP register */ /* in SETUP register */
#define PROMISCset 0x10 /* enable RCV_ALL */ #define PROMISCset 0x10 /* enable RCV_ALL */
...@@ -109,37 +104,15 @@ struct com20020_dev { ...@@ -109,37 +104,15 @@ struct com20020_dev {
#define SUB_BUSCTL 5 /* bus control options */ #define SUB_BUSCTL 5 /* bus control options */
#define SUB_DMACOUNT 6 /* DMA count options */ #define SUB_DMACOUNT 6 /* DMA count options */
#define SET_SUBADR(x) do { \ static inline void com20020_set_subaddress(struct arcnet_local *lp,
if ((x) < 4) \ int ioaddr, int val)
{ \ {
lp->config = (lp->config & ~0x03) | (x); \ if (val < 4) {
SETCONF; \ lp->config = (lp->config & ~0x03) | val;
} \ arcnet_outb(lp->config, ioaddr, COM20020_REG_W_CONFIG);
else \ } else {
{ \ arcnet_outb(val, ioaddr, COM20020_REG_W_SUBADR);
outb(x, _SUBADR); \ }
} \ }
} while (0)
#undef ARCRESET
#undef ASTATUS
#undef ACOMMAND
#undef AINTMASK
#define ARCRESET { outb(lp->config | 0x80, _CONFIG); \
udelay(5); \
outb(lp->config , _CONFIG); \
}
#define ARCRESET0 { outb(0x18 | 0x80, _CONFIG); \
udelay(5); \
outb(0x18 , _CONFIG); \
}
#define ASTATUS() inb(_STATUS)
#define ADIAGSTATUS() inb(_DIAGSTAT)
#define ACOMMAND(cmd) outb((cmd),_COMMAND)
#define AINTMASK(msk) outb((msk),_INTMASK)
#define SETCONF outb(lp->config, _CONFIG)
#endif /* __COM20020_H */ #endif /* __COM20020_H */
/* /*
* Linux ARCnet driver - COM20020 PCMCIA support * Linux ARCnet driver - COM20020 PCMCIA support
* *
* Written 1994-1999 by Avery Pennarun, * Written 1994-1999 by Avery Pennarun,
* based on an ISA version by David Woodhouse. * based on an ISA version by David Woodhouse.
* Derived from ibmtr_cs.c by Steve Kipisz (pcmcia-cs 3.1.4) * Derived from ibmtr_cs.c by Steve Kipisz (pcmcia-cs 3.1.4)
...@@ -19,18 +19,21 @@ ...@@ -19,18 +19,21 @@
* Director, National Security Agency. This software may only be used * Director, National Security Agency. This software may only be used
* and distributed according to the terms of the GNU General Public License as * and distributed according to the terms of the GNU General Public License as
* modified by SRC, incorporated herein by reference. * modified by SRC, incorporated herein by reference.
* *
* ********************** * **********************
* Changes: * Changes:
* Arnaldo Carvalho de Melo <acme@conectiva.com.br> - 08/08/2000 * Arnaldo Carvalho de Melo <acme@conectiva.com.br> - 08/08/2000
* - reorganize kmallocs in com20020_attach, checking all for failure * - reorganize kmallocs in com20020_attach, checking all for failure
* and releasing the previous allocations if one fails * and releasing the previous allocations if one fails
* ********************** * **********************
* *
* For more details, see drivers/net/arcnet.c * For more details, see drivers/net/arcnet.c
* *
* ********************** * **********************
*/ */
#define pr_fmt(fmt) "arcnet:" KBUILD_MODNAME ": " fmt
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/ptrace.h> #include <linux/ptrace.h>
#include <linux/slab.h> #include <linux/slab.h>
...@@ -39,51 +42,44 @@ ...@@ -39,51 +42,44 @@
#include <linux/delay.h> #include <linux/delay.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/netdevice.h> #include <linux/netdevice.h>
#include <linux/arcdevice.h> #include <linux/io.h>
#include <linux/com20020.h>
#include <pcmcia/cistpl.h> #include <pcmcia/cistpl.h>
#include <pcmcia/ds.h> #include <pcmcia/ds.h>
#include <asm/io.h> #include "arcdevice.h"
#include "com20020.h"
#define VERSION "arcnet: COM20020 PCMCIA support loaded.\n"
static void regdump(struct net_device *dev) static void regdump(struct net_device *dev)
{ {
#ifdef DEBUG #ifdef DEBUG
int ioaddr = dev->base_addr; int ioaddr = dev->base_addr;
int count; int count;
netdev_dbg(dev, "register dump:\n"); netdev_dbg(dev, "register dump:\n");
for (count = ioaddr; count < ioaddr + 16; count++) for (count = 0; count < 16; count++) {
{ if (!(count % 16))
if (!(count % 16)) pr_cont("%04X:", ioaddr + count);
pr_cont("%04X:", count); pr_cont(" %02X", arcnet_inb(ioaddr, count));
pr_cont(" %02X", inb(count)); }
} pr_cont("\n");
pr_cont("\n");
netdev_dbg(dev, "buffer0 dump:\n");
netdev_dbg(dev, "buffer0 dump:\n");
/* set up the address register */ /* set up the address register */
count = 0; count = 0;
outb((count >> 8) | RDDATAflag | AUTOINCflag, _ADDR_HI); arcnet_outb((count >> 8) | RDDATAflag | AUTOINCflag,
outb(count & 0xff, _ADDR_LO); ioaddr, com20020_REG_W_ADDR_HI);
arcnet_outb(count & 0xff, ioaddr, COM20020_REG_W_ADDR_LO);
for (count = 0; count < 256+32; count++)
{
if (!(count % 16))
pr_cont("%04X:", count);
/* copy the data */
pr_cont(" %02X", inb(_MEMDATA));
}
pr_cont("\n");
#endif
}
for (count = 0; count < 256 + 32; count++) {
if (!(count % 16))
pr_cont("%04X:", count);
/* copy the data */
pr_cont(" %02X", arcnet_inb(ioaddr, COM20020_REG_RW_MEMDATA));
}
pr_cont("\n");
#endif
}
/*====================================================================*/ /*====================================================================*/
...@@ -114,169 +110,161 @@ static void com20020_detach(struct pcmcia_device *p_dev); ...@@ -114,169 +110,161 @@ static void com20020_detach(struct pcmcia_device *p_dev);
static int com20020_probe(struct pcmcia_device *p_dev) static int com20020_probe(struct pcmcia_device *p_dev)
{ {
struct com20020_dev *info; struct com20020_dev *info;
struct net_device *dev; struct net_device *dev;
struct arcnet_local *lp; struct arcnet_local *lp;
dev_dbg(&p_dev->dev, "com20020_attach()\n"); dev_dbg(&p_dev->dev, "com20020_attach()\n");
/* Create new network device */ /* Create new network device */
info = kzalloc(sizeof(*info), GFP_KERNEL); info = kzalloc(sizeof(*info), GFP_KERNEL);
if (!info) if (!info)
goto fail_alloc_info; goto fail_alloc_info;
dev = alloc_arcdev(""); dev = alloc_arcdev("");
if (!dev) if (!dev)
goto fail_alloc_dev; goto fail_alloc_dev;
lp = netdev_priv(dev); lp = netdev_priv(dev);
lp->timeout = timeout; lp->timeout = timeout;
lp->backplane = backplane; lp->backplane = backplane;
lp->clockp = clockp; lp->clockp = clockp;
lp->clockm = clockm & 3; lp->clockm = clockm & 3;
lp->hw.owner = THIS_MODULE; lp->hw.owner = THIS_MODULE;
/* fill in our module parameters as defaults */ /* fill in our module parameters as defaults */
dev->dev_addr[0] = node; dev->dev_addr[0] = node;
p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_8; p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_8;
p_dev->resource[0]->end = 16; p_dev->resource[0]->end = 16;
p_dev->config_flags |= CONF_ENABLE_IRQ; p_dev->config_flags |= CONF_ENABLE_IRQ;
info->dev = dev; info->dev = dev;
p_dev->priv = info; p_dev->priv = info;
return com20020_config(p_dev); return com20020_config(p_dev);
fail_alloc_dev: fail_alloc_dev:
kfree(info); kfree(info);
fail_alloc_info: fail_alloc_info:
return -ENOMEM; return -ENOMEM;
} /* com20020_attach */ } /* com20020_attach */
static void com20020_detach(struct pcmcia_device *link) static void com20020_detach(struct pcmcia_device *link)
{ {
struct com20020_dev *info = link->priv; struct com20020_dev *info = link->priv;
struct net_device *dev = info->dev; struct net_device *dev = info->dev;
dev_dbg(&link->dev, "detach...\n"); dev_dbg(&link->dev, "detach...\n");
dev_dbg(&link->dev, "com20020_detach\n"); dev_dbg(&link->dev, "com20020_detach\n");
dev_dbg(&link->dev, "unregister...\n"); dev_dbg(&link->dev, "unregister...\n");
unregister_netdev(dev); unregister_netdev(dev);
/* /* this is necessary because we register our IRQ separately
* this is necessary because we register our IRQ separately * from card services.
* from card services. */
*/ if (dev->irq)
if (dev->irq) free_irq(dev->irq, dev);
free_irq(dev->irq, dev);
com20020_release(link); com20020_release(link);
/* Unlink device structure, free bits */ /* Unlink device structure, free bits */
dev_dbg(&link->dev, "unlinking...\n"); dev_dbg(&link->dev, "unlinking...\n");
if (link->priv) if (link->priv) {
{ dev = info->dev;
dev = info->dev; if (dev) {
if (dev) dev_dbg(&link->dev, "kfree...\n");
{ free_netdev(dev);
dev_dbg(&link->dev, "kfree...\n"); }
free_netdev(dev); dev_dbg(&link->dev, "kfree2...\n");
kfree(info);
} }
dev_dbg(&link->dev, "kfree2...\n");
kfree(info);
}
} /* com20020_detach */ } /* com20020_detach */
static int com20020_config(struct pcmcia_device *link) static int com20020_config(struct pcmcia_device *link)
{ {
struct arcnet_local *lp; struct arcnet_local *lp;
struct com20020_dev *info; struct com20020_dev *info;
struct net_device *dev; struct net_device *dev;
int i, ret; int i, ret;
int ioaddr; int ioaddr;
info = link->priv;
dev = info->dev;
dev_dbg(&link->dev, "config...\n");
dev_dbg(&link->dev, "com20020_config\n");
info = link->priv; dev_dbg(&link->dev, "baseport1 is %Xh\n",
dev = info->dev; (unsigned int)link->resource[0]->start);
dev_dbg(&link->dev, "config...\n"); i = -ENODEV;
link->io_lines = 16;
dev_dbg(&link->dev, "com20020_config\n"); if (!link->resource[0]->start) {
for (ioaddr = 0x100; ioaddr < 0x400; ioaddr += 0x10) {
link->resource[0]->start = ioaddr;
i = pcmcia_request_io(link);
if (i == 0)
break;
}
} else {
i = pcmcia_request_io(link);
}
dev_dbg(&link->dev, "baseport1 is %Xh\n", if (i != 0) {
(unsigned int) link->resource[0]->start); dev_dbg(&link->dev, "requestIO failed totally!\n");
goto failed;
}
i = -ENODEV; ioaddr = dev->base_addr = link->resource[0]->start;
link->io_lines = 16; dev_dbg(&link->dev, "got ioaddr %Xh\n", ioaddr);
if (!link->resource[0]->start) dev_dbg(&link->dev, "request IRQ %d\n",
{ link->irq);
for (ioaddr = 0x100; ioaddr < 0x400; ioaddr += 0x10) if (!link->irq) {
{ dev_dbg(&link->dev, "requestIRQ failed totally!\n");
link->resource[0]->start = ioaddr; goto failed;
i = pcmcia_request_io(link);
if (i == 0)
break;
} }
}
else dev->irq = link->irq;
i = pcmcia_request_io(link);
ret = pcmcia_enable_device(link);
if (i != 0) if (ret)
{ goto failed;
dev_dbg(&link->dev, "requestIO failed totally!\n");
goto failed; if (com20020_check(dev)) {
} regdump(dev);
goto failed;
ioaddr = dev->base_addr = link->resource[0]->start; }
dev_dbg(&link->dev, "got ioaddr %Xh\n", ioaddr);
lp = netdev_priv(dev);
dev_dbg(&link->dev, "request IRQ %d\n", lp->card_name = "PCMCIA COM20020";
link->irq); lp->card_flags = ARC_CAN_10MBIT; /* pretend all of them can 10Mbit */
if (!link->irq)
{ SET_NETDEV_DEV(dev, &link->dev);
dev_dbg(&link->dev, "requestIRQ failed totally!\n");
goto failed; i = com20020_found(dev, 0); /* calls register_netdev */
}
if (i != 0) {
dev->irq = link->irq; dev_notice(&link->dev,
"com20020_found() failed\n");
ret = pcmcia_enable_device(link); goto failed;
if (ret) }
goto failed;
netdev_dbg(dev, "port %#3lx, irq %d\n",
if (com20020_check(dev)) dev->base_addr, dev->irq);
{ return 0;
regdump(dev);
goto failed;
}
lp = netdev_priv(dev);
lp->card_name = "PCMCIA COM20020";
lp->card_flags = ARC_CAN_10MBIT; /* pretend all of them can 10Mbit */
SET_NETDEV_DEV(dev, &link->dev);
i = com20020_found(dev, 0); /* calls register_netdev */
if (i != 0) {
dev_notice(&link->dev,
"com20020_found() failed\n");
goto failed;
}
netdev_dbg(dev, "port %#3lx, irq %d\n",
dev->base_addr, dev->irq);
return 0;
failed: failed:
dev_dbg(&link->dev, "com20020_config failed...\n"); dev_dbg(&link->dev, "com20020_config failed...\n");
com20020_release(link); com20020_release(link);
return -ENODEV; return -ENODEV;
} /* com20020_config */ } /* com20020_config */
static void com20020_release(struct pcmcia_device *link) static void com20020_release(struct pcmcia_device *link)
...@@ -304,7 +292,10 @@ static int com20020_resume(struct pcmcia_device *link) ...@@ -304,7 +292,10 @@ static int com20020_resume(struct pcmcia_device *link)
if (link->open) { if (link->open) {
int ioaddr = dev->base_addr; int ioaddr = dev->base_addr;
struct arcnet_local *lp = netdev_priv(dev); struct arcnet_local *lp = netdev_priv(dev);
ARCRESET;
arcnet_outb(lp->config | 0x80, ioaddr, COM20020_REG_W_CONFIG);
udelay(5);
arcnet_outb(lp->config, ioaddr, COM20020_REG_W_CONFIG);
} }
return 0; return 0;
...@@ -312,9 +303,9 @@ static int com20020_resume(struct pcmcia_device *link) ...@@ -312,9 +303,9 @@ static int com20020_resume(struct pcmcia_device *link)
static const struct pcmcia_device_id com20020_ids[] = { static const struct pcmcia_device_id com20020_ids[] = {
PCMCIA_DEVICE_PROD_ID12("Contemporary Control Systems, Inc.", PCMCIA_DEVICE_PROD_ID12("Contemporary Control Systems, Inc.",
"PCM20 Arcnet Adapter", 0x59991666, 0x95dfffaf), "PCM20 Arcnet Adapter", 0x59991666, 0x95dfffaf),
PCMCIA_DEVICE_PROD_ID12("SoHard AG", PCMCIA_DEVICE_PROD_ID12("SoHard AG",
"SH ARC PCMCIA", 0xf8991729, 0x69dff0c7), "SH ARC PCMCIA", 0xf8991729, 0x69dff0c7),
PCMCIA_DEVICE_NULL PCMCIA_DEVICE_NULL
}; };
MODULE_DEVICE_TABLE(pcmcia, com20020_ids); MODULE_DEVICE_TABLE(pcmcia, com20020_ids);
......
#ifndef __COM9026_H
#define __COM9026_H
/* COM 9026 controller chip --> ARCnet register addresses */
#define COM9026_REG_W_INTMASK 0 /* writable */
#define COM9026_REG_R_STATUS 0 /* readable */
#define COM9026_REG_W_COMMAND 1 /* writable, returns random vals on read (?) */
#define COM9026_REG_RW_CONFIG 2 /* Configuration register */
#define COM9026_REG_R_RESET 8 /* software reset (on read) */
#define COM9026_REG_RW_MEMDATA 12 /* Data port for IO-mapped memory */
#define COM9026_REG_W_ADDR_LO 14 /* Control registers for said */
#define COM9026_REG_W_ADDR_HI 15
#define COM9026_REG_R_STATION 1 /* Station ID */
#endif
/* /*
* Linux ARCnet driver - COM90xx chipset (IO-mapped buffers) * Linux ARCnet driver - COM90xx chipset (IO-mapped buffers)
* *
* Written 1997 by David Woodhouse. * Written 1997 by David Woodhouse.
* Written 1994-1999 by Avery Pennarun. * Written 1994-1999 by Avery Pennarun.
* Written 1999-2000 by Martin Mares <mj@ucw.cz>. * Written 1999-2000 by Martin Mares <mj@ucw.cz>.
...@@ -25,6 +25,9 @@ ...@@ -25,6 +25,9 @@
* *
* ********************** * **********************
*/ */
#define pr_fmt(fmt) "arcnet:" KBUILD_MODNAME ": " fmt
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/moduleparam.h> #include <linux/moduleparam.h>
...@@ -34,12 +37,10 @@ ...@@ -34,12 +37,10 @@
#include <linux/bootmem.h> #include <linux/bootmem.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/interrupt.h> #include <linux/interrupt.h>
#include <asm/io.h> #include <linux/io.h>
#include <linux/arcdevice.h>
#define VERSION "arcnet: COM90xx IO-mapped mode support (by David Woodhouse et el.)\n"
#include "arcdevice.h"
#include "com9026.h"
/* Internal function declarations */ /* Internal function declarations */
...@@ -50,35 +51,14 @@ static void com90io_setmask(struct net_device *dev, int mask); ...@@ -50,35 +51,14 @@ static void com90io_setmask(struct net_device *dev, int mask);
static int com90io_reset(struct net_device *dev, int really_reset); static int com90io_reset(struct net_device *dev, int really_reset);
static void com90io_copy_to_card(struct net_device *dev, int bufnum, int offset, static void com90io_copy_to_card(struct net_device *dev, int bufnum, int offset,
void *buf, int count); void *buf, int count);
static void com90io_copy_from_card(struct net_device *dev, int bufnum, int offset, static void com90io_copy_from_card(struct net_device *dev, int bufnum,
void *buf, int count); int offset, void *buf, int count);
/* Handy defines for ARCnet specific stuff */ /* Handy defines for ARCnet specific stuff */
/* The number of low I/O ports used by the card. */ /* The number of low I/O ports used by the card. */
#define ARCNET_TOTAL_SIZE 16 #define ARCNET_TOTAL_SIZE 16
/* COM 9026 controller chip --> ARCnet register addresses */
#define _INTMASK (ioaddr+0) /* writable */
#define _STATUS (ioaddr+0) /* readable */
#define _COMMAND (ioaddr+1) /* writable, returns random vals on read (?) */
#define _RESET (ioaddr+8) /* software reset (on read) */
#define _MEMDATA (ioaddr+12) /* Data port for IO-mapped memory */
#define _ADDR_HI (ioaddr+15) /* Control registers for said */
#define _ADDR_LO (ioaddr+14)
#define _CONFIG (ioaddr+2) /* Configuration register */
#undef ASTATUS
#undef ACOMMAND
#undef AINTMASK
#define ASTATUS() inb(_STATUS)
#define ACOMMAND(cmd) outb((cmd),_COMMAND)
#define AINTMASK(msk) outb((msk),_INTMASK)
#define SETCONF() outb((lp->config),_CONFIG)
/**************************************************************************** /****************************************************************************
* * * *
* IO-mapped operation routines * * IO-mapped operation routines *
...@@ -92,58 +72,59 @@ static u_char get_buffer_byte(struct net_device *dev, unsigned offset) ...@@ -92,58 +72,59 @@ static u_char get_buffer_byte(struct net_device *dev, unsigned offset)
{ {
int ioaddr = dev->base_addr; int ioaddr = dev->base_addr;
outb(offset >> 8, _ADDR_HI); arcnet_outb(offset >> 8, ioaddr, COM9026_REG_W_ADDR_HI);
outb(offset & 0xff, _ADDR_LO); arcnet_outb(offset & 0xff, ioaddr, COM9026_REG_W_ADDR_LO);
return inb(_MEMDATA); return arcnet_inb(ioaddr, COM9026_REG_RW_MEMDATA);
} }
#ifdef ONE_AT_A_TIME_TX #ifdef ONE_AT_A_TIME_TX
static void put_buffer_byte(struct net_device *dev, unsigned offset, u_char datum) static void put_buffer_byte(struct net_device *dev, unsigned offset,
u_char datum)
{ {
int ioaddr = dev->base_addr; int ioaddr = dev->base_addr;
outb(offset >> 8, _ADDR_HI); arcnet_outb(offset >> 8, ioaddr, COM9026_REG_W_ADDR_HI);
outb(offset & 0xff, _ADDR_LO); arcnet_outb(offset & 0xff, ioaddr, COM9026_REG_W_ADDR_LO);
outb(datum, _MEMDATA); arcnet_outb(datum, ioaddr, COM9026_REG_RW_MEMDATA);
} }
#endif #endif
static void get_whole_buffer(struct net_device *dev, unsigned offset,
static void get_whole_buffer(struct net_device *dev, unsigned offset, unsigned length, char *dest) unsigned length, char *dest)
{ {
int ioaddr = dev->base_addr; int ioaddr = dev->base_addr;
outb((offset >> 8) | AUTOINCflag, _ADDR_HI); arcnet_outb((offset >> 8) | AUTOINCflag, ioaddr, COM9026_REG_W_ADDR_HI);
outb(offset & 0xff, _ADDR_LO); arcnet_outb(offset & 0xff, ioaddr, COM9026_REG_W_ADDR_LO);
while (length--) while (length--)
#ifdef ONE_AT_A_TIME_RX #ifdef ONE_AT_A_TIME_RX
*(dest++) = get_buffer_byte(dev, offset++); *(dest++) = get_buffer_byte(dev, offset++);
#else #else
*(dest++) = inb(_MEMDATA); *(dest++) = arcnet_inb(ioaddr, COM9026_REG_RW_MEMDATA);
#endif #endif
} }
static void put_whole_buffer(struct net_device *dev, unsigned offset, unsigned length, char *dest) static void put_whole_buffer(struct net_device *dev, unsigned offset,
unsigned length, char *dest)
{ {
int ioaddr = dev->base_addr; int ioaddr = dev->base_addr;
outb((offset >> 8) | AUTOINCflag, _ADDR_HI); arcnet_outb((offset >> 8) | AUTOINCflag, ioaddr, COM9026_REG_W_ADDR_HI);
outb(offset & 0xff, _ADDR_LO); arcnet_outb(offset & 0xff, ioaddr,COM9026_REG_W_ADDR_LO);
while (length--) while (length--)
#ifdef ONE_AT_A_TIME_TX #ifdef ONE_AT_A_TIME_TX
put_buffer_byte(dev, offset++, *(dest++)); put_buffer_byte(dev, offset++, *(dest++));
#else #else
outb(*(dest++), _MEMDATA); arcnet_outb(*(dest++), ioaddr, COM9026_REG_RW_MEMDATA);
#endif #endif
} }
/* /* We cannot probe for an IO mapped card either, although we can check that
* We cannot probe for an IO mapped card either, although we can check that
* it's where we were told it was, and even autoirq * it's where we were told it was, and even autoirq
*/ */
static int __init com90io_probe(struct net_device *dev) static int __init com90io_probe(struct net_device *dev)
...@@ -151,71 +132,78 @@ static int __init com90io_probe(struct net_device *dev) ...@@ -151,71 +132,78 @@ static int __init com90io_probe(struct net_device *dev)
int ioaddr = dev->base_addr, status; int ioaddr = dev->base_addr, status;
unsigned long airqmask; unsigned long airqmask;
BUGLVL(D_NORMAL) printk(VERSION); if (BUGLVL(D_NORMAL)) {
BUGLVL(D_NORMAL) printk("E-mail me if you actually test this driver, please!\n"); pr_info("%s\n", "COM90xx IO-mapped mode support (by David Woodhouse et el.)");
pr_info("E-mail me if you actually test this driver, please!\n");
}
if (!ioaddr) { if (!ioaddr) {
BUGMSG(D_NORMAL, "No autoprobe for IO mapped cards; you " arc_printk(D_NORMAL, dev, "No autoprobe for IO mapped cards; you must specify the base address!\n");
"must specify the base address!\n");
return -ENODEV; return -ENODEV;
} }
if (!request_region(ioaddr, ARCNET_TOTAL_SIZE, "com90io probe")) { if (!request_region(ioaddr, ARCNET_TOTAL_SIZE, "com90io probe")) {
BUGMSG(D_INIT_REASONS, "IO request_region %x-%x failed.\n", arc_printk(D_INIT_REASONS, dev, "IO request_region %x-%x failed\n",
ioaddr, ioaddr + ARCNET_TOTAL_SIZE - 1); ioaddr, ioaddr + ARCNET_TOTAL_SIZE - 1);
return -ENXIO; return -ENXIO;
} }
if (ASTATUS() == 0xFF) { if (arcnet_inb(ioaddr, COM9026_REG_R_STATUS) == 0xFF) {
BUGMSG(D_INIT_REASONS, "IO address %x empty\n", ioaddr); arc_printk(D_INIT_REASONS, dev, "IO address %x empty\n",
ioaddr);
goto err_out; goto err_out;
} }
inb(_RESET); arcnet_inb(ioaddr, COM9026_REG_R_RESET);
mdelay(RESETtime); mdelay(RESETtime);
status = ASTATUS(); status = arcnet_inb(ioaddr, COM9026_REG_R_STATUS);
if ((status & 0x9D) != (NORXflag | RECONflag | TXFREEflag | RESETflag)) { if ((status & 0x9D) != (NORXflag | RECONflag | TXFREEflag | RESETflag)) {
BUGMSG(D_INIT_REASONS, "Status invalid (%Xh).\n", status); arc_printk(D_INIT_REASONS, dev, "Status invalid (%Xh)\n",
status);
goto err_out; goto err_out;
} }
BUGMSG(D_INIT_REASONS, "Status after reset: %X\n", status); arc_printk(D_INIT_REASONS, dev, "Status after reset: %X\n", status);
ACOMMAND(CFLAGScmd | RESETclear | CONFIGclear); arcnet_outb(CFLAGScmd | RESETclear | CONFIGclear,
ioaddr, COM9026_REG_W_COMMAND);
BUGMSG(D_INIT_REASONS, "Status after reset acknowledged: %X\n", status); arc_printk(D_INIT_REASONS, dev, "Status after reset acknowledged: %X\n",
status);
status = ASTATUS(); status = arcnet_inb(ioaddr, COM9026_REG_R_STATUS);
if (status & RESETflag) { if (status & RESETflag) {
BUGMSG(D_INIT_REASONS, "Eternal reset (status=%Xh)\n", status); arc_printk(D_INIT_REASONS, dev, "Eternal reset (status=%Xh)\n",
status);
goto err_out; goto err_out;
} }
outb((0x16 | IOMAPflag) & ~ENABLE16flag, _CONFIG); arcnet_outb((0x16 | IOMAPflag) & ~ENABLE16flag,
ioaddr, COM9026_REG_RW_CONFIG);
/* Read first loc'n of memory */ /* Read first loc'n of memory */
outb(AUTOINCflag, _ADDR_HI); arcnet_outb(AUTOINCflag, ioaddr, COM9026_REG_W_ADDR_HI);
outb(0, _ADDR_LO); arcnet_outb(0, ioaddr, COM9026_REG_W_ADDR_LO);
if ((status = inb(_MEMDATA)) != 0xd1) { status = arcnet_inb(ioaddr, COM9026_REG_RW_MEMDATA);
BUGMSG(D_INIT_REASONS, "Signature byte not found" if (status != 0xd1) {
" (%Xh instead).\n", status); arc_printk(D_INIT_REASONS, dev, "Signature byte not found (%Xh instead).\n",
status);
goto err_out; goto err_out;
} }
if (!dev->irq) { if (!dev->irq) {
/* /* if we do this, we're sure to get an IRQ since the
* if we do this, we're sure to get an IRQ since the
* card has just reset and the NORXflag is on until * card has just reset and the NORXflag is on until
* we tell it to start receiving. * we tell it to start receiving.
*/ */
airqmask = probe_irq_on(); airqmask = probe_irq_on();
outb(NORXflag, _INTMASK); arcnet_outb(NORXflag, ioaddr, COM9026_REG_W_INTMASK);
udelay(1); udelay(1);
outb(0, _INTMASK); arcnet_outb(0, ioaddr, COM9026_REG_W_INTMASK);
dev->irq = probe_irq_off(airqmask); dev->irq = probe_irq_off(airqmask);
if ((int)dev->irq <= 0) { if ((int)dev->irq <= 0) {
BUGMSG(D_INIT_REASONS, "Autoprobe IRQ failed\n"); arc_printk(D_INIT_REASONS, dev, "Autoprobe IRQ failed\n");
goto err_out; goto err_out;
} }
} }
...@@ -227,7 +215,6 @@ static int __init com90io_probe(struct net_device *dev) ...@@ -227,7 +215,6 @@ static int __init com90io_probe(struct net_device *dev)
return -ENODEV; return -ENODEV;
} }
/* Set up the struct net_device associated with this card. Called after /* Set up the struct net_device associated with this card. Called after
* probing succeeds. * probing succeeds.
*/ */
...@@ -238,12 +225,14 @@ static int __init com90io_found(struct net_device *dev) ...@@ -238,12 +225,14 @@ static int __init com90io_found(struct net_device *dev)
int err; int err;
/* Reserve the irq */ /* Reserve the irq */
if (request_irq(dev->irq, arcnet_interrupt, 0, "arcnet (COM90xx-IO)", dev)) { if (request_irq(dev->irq, arcnet_interrupt, 0,
BUGMSG(D_NORMAL, "Can't get IRQ %d!\n", dev->irq); "arcnet (COM90xx-IO)", dev)) {
arc_printk(D_NORMAL, dev, "Can't get IRQ %d!\n", dev->irq);
return -ENODEV; return -ENODEV;
} }
/* Reserve the I/O region */ /* Reserve the I/O region */
if (!request_region(dev->base_addr, ARCNET_TOTAL_SIZE, "arcnet (COM90xx-IO)")) { if (!request_region(dev->base_addr, ARCNET_TOTAL_SIZE,
"arcnet (COM90xx-IO)")) {
free_irq(dev->irq, dev); free_irq(dev->irq, dev);
return -EBUSY; return -EBUSY;
} }
...@@ -259,7 +248,7 @@ static int __init com90io_found(struct net_device *dev) ...@@ -259,7 +248,7 @@ static int __init com90io_found(struct net_device *dev)
lp->hw.copy_from_card = com90io_copy_from_card; lp->hw.copy_from_card = com90io_copy_from_card;
lp->config = (0x16 | IOMAPflag) & ~ENABLE16flag; lp->config = (0x16 | IOMAPflag) & ~ENABLE16flag;
SETCONF(); arcnet_outb(lp->config, ioaddr, COM9026_REG_RW_CONFIG);
/* get and check the station ID from offset 1 in shmem */ /* get and check the station ID from offset 1 in shmem */
...@@ -267,21 +256,20 @@ static int __init com90io_found(struct net_device *dev) ...@@ -267,21 +256,20 @@ static int __init com90io_found(struct net_device *dev)
err = register_netdev(dev); err = register_netdev(dev);
if (err) { if (err) {
outb((inb(_CONFIG) & ~IOMAPflag), _CONFIG); arcnet_outb(arcnet_inb(ioaddr, COM9026_REG_RW_CONFIG) & ~IOMAPflag,
ioaddr, COM9026_REG_RW_CONFIG);
free_irq(dev->irq, dev); free_irq(dev->irq, dev);
release_region(dev->base_addr, ARCNET_TOTAL_SIZE); release_region(dev->base_addr, ARCNET_TOTAL_SIZE);
return err; return err;
} }
BUGMSG(D_NORMAL, "COM90IO: station %02Xh found at %03lXh, IRQ %d.\n", arc_printk(D_NORMAL, dev, "COM90IO: station %02Xh found at %03lXh, IRQ %d.\n",
dev->dev_addr[0], dev->base_addr, dev->irq); dev->dev_addr[0], dev->base_addr, dev->irq);
return 0; return 0;
} }
/* Do a hardware reset on the card, and set up necessary registers.
/*
* Do a hardware reset on the card, and set up necessary registers.
* *
* This should be called as little as possible, because it disrupts the * This should be called as little as possible, because it disrupts the
* token on the network (causes a RECON) and requires a significant delay. * token on the network (causes a RECON) and requires a significant delay.
...@@ -293,67 +281,66 @@ static int com90io_reset(struct net_device *dev, int really_reset) ...@@ -293,67 +281,66 @@ static int com90io_reset(struct net_device *dev, int really_reset)
struct arcnet_local *lp = netdev_priv(dev); struct arcnet_local *lp = netdev_priv(dev);
short ioaddr = dev->base_addr; short ioaddr = dev->base_addr;
BUGMSG(D_INIT, "Resetting %s (status=%02Xh)\n", dev->name, ASTATUS()); arc_printk(D_INIT, dev, "Resetting %s (status=%02Xh)\n",
dev->name, arcnet_inb(ioaddr, COM9026_REG_R_STATUS));
if (really_reset) { if (really_reset) {
/* reset the card */ /* reset the card */
inb(_RESET); arcnet_inb(ioaddr, COM9026_REG_R_RESET);
mdelay(RESETtime); mdelay(RESETtime);
} }
/* Set the thing to IO-mapped, 8-bit mode */ /* Set the thing to IO-mapped, 8-bit mode */
lp->config = (0x1C | IOMAPflag) & ~ENABLE16flag; lp->config = (0x1C | IOMAPflag) & ~ENABLE16flag;
SETCONF(); arcnet_outb(lp->config, ioaddr, COM9026_REG_RW_CONFIG);
ACOMMAND(CFLAGScmd | RESETclear); /* clear flags & end reset */ arcnet_outb(CFLAGScmd | RESETclear, ioaddr, COM9026_REG_W_COMMAND);
ACOMMAND(CFLAGScmd | CONFIGclear); /* clear flags & end reset */
arcnet_outb(CFLAGScmd | CONFIGclear, ioaddr, COM9026_REG_W_COMMAND);
/* verify that the ARCnet signature byte is present */ /* verify that the ARCnet signature byte is present */
if (get_buffer_byte(dev, 0) != TESTvalue) { if (get_buffer_byte(dev, 0) != TESTvalue) {
BUGMSG(D_NORMAL, "reset failed: TESTvalue not present.\n"); arc_printk(D_NORMAL, dev, "reset failed: TESTvalue not present.\n");
return 1; return 1;
} }
/* enable extended (512-byte) packets */ /* enable extended (512-byte) packets */
ACOMMAND(CONFIGcmd | EXTconf); arcnet_outb(CONFIGcmd | EXTconf, ioaddr, COM9026_REG_W_COMMAND);
/* done! return success. */ /* done! return success. */
return 0; return 0;
} }
static void com90io_command(struct net_device *dev, int cmd) static void com90io_command(struct net_device *dev, int cmd)
{ {
short ioaddr = dev->base_addr; short ioaddr = dev->base_addr;
ACOMMAND(cmd); arcnet_outb(cmd, ioaddr, COM9026_REG_W_COMMAND);
} }
static int com90io_status(struct net_device *dev) static int com90io_status(struct net_device *dev)
{ {
short ioaddr = dev->base_addr; short ioaddr = dev->base_addr;
return ASTATUS(); return arcnet_inb(ioaddr, COM9026_REG_R_STATUS);
} }
static void com90io_setmask(struct net_device *dev, int mask) static void com90io_setmask(struct net_device *dev, int mask)
{ {
short ioaddr = dev->base_addr; short ioaddr = dev->base_addr;
AINTMASK(mask); arcnet_outb(mask, ioaddr, COM9026_REG_W_INTMASK);
} }
static void com90io_copy_to_card(struct net_device *dev, int bufnum, int offset, static void com90io_copy_to_card(struct net_device *dev, int bufnum,
void *buf, int count) int offset, void *buf, int count)
{ {
TIME("put_whole_buffer", count, put_whole_buffer(dev, bufnum * 512 + offset, count, buf)); TIME(dev, "put_whole_buffer", count,
put_whole_buffer(dev, bufnum * 512 + offset, count, buf));
} }
static void com90io_copy_from_card(struct net_device *dev, int bufnum,
static void com90io_copy_from_card(struct net_device *dev, int bufnum, int offset, int offset, void *buf, int count)
void *buf, int count)
{ {
TIME("get_whole_buffer", count, get_whole_buffer(dev, bufnum * 512 + offset, count, buf)); TIME(dev, "get_whole_buffer", count,
get_whole_buffer(dev, bufnum * 512 + offset, count, buf));
} }
static int io; /* use the insmod io= irq= shmem= options */ static int io; /* use the insmod io= irq= shmem= options */
...@@ -369,12 +356,13 @@ MODULE_LICENSE("GPL"); ...@@ -369,12 +356,13 @@ MODULE_LICENSE("GPL");
static int __init com90io_setup(char *s) static int __init com90io_setup(char *s)
{ {
int ints[4]; int ints[4];
s = get_options(s, 4, ints); s = get_options(s, 4, ints);
if (!ints[0]) if (!ints[0])
return 0; return 0;
switch (ints[0]) { switch (ints[0]) {
default: /* ERROR */ default: /* ERROR */
printk("com90io: Too many arguments.\n"); pr_err("Too many arguments\n");
case 2: /* IRQ */ case 2: /* IRQ */
irq = ints[2]; irq = ints[2];
case 1: /* IO address */ case 1: /* IO address */
...@@ -421,8 +409,11 @@ static void __exit com90io_exit(void) ...@@ -421,8 +409,11 @@ static void __exit com90io_exit(void)
unregister_netdev(dev); unregister_netdev(dev);
/* Set the thing back to MMAP mode, in case the old driver is loaded later */ /* In case the old driver is loaded later,
outb((inb(_CONFIG) & ~IOMAPflag), _CONFIG); * set the thing back to MMAP mode
*/
arcnet_outb(arcnet_inb(ioaddr, COM9026_REG_RW_CONFIG) & ~IOMAPflag,
ioaddr, COM9026_REG_RW_CONFIG);
free_irq(dev->irq, dev); free_irq(dev->irq, dev);
release_region(dev->base_addr, ARCNET_TOTAL_SIZE); release_region(dev->base_addr, ARCNET_TOTAL_SIZE);
......
/* /*
* Linux ARCnet driver - COM90xx chipset (memory-mapped buffers) * Linux ARCnet driver - COM90xx chipset (memory-mapped buffers)
* *
* Written 1994-1999 by Avery Pennarun. * Written 1994-1999 by Avery Pennarun.
* Written 1999 by Martin Mares <mj@ucw.cz>. * Written 1999 by Martin Mares <mj@ucw.cz>.
* Derived from skeleton.c by Donald Becker. * Derived from skeleton.c by Donald Becker.
...@@ -24,6 +24,9 @@ ...@@ -24,6 +24,9 @@
* *
* ********************** * **********************
*/ */
#define pr_fmt(fmt) "arcnet:" KBUILD_MODNAME ": " fmt
#include <linux/module.h> #include <linux/module.h>
#include <linux/moduleparam.h> #include <linux/moduleparam.h>
#include <linux/init.h> #include <linux/init.h>
...@@ -32,12 +35,10 @@ ...@@ -32,12 +35,10 @@
#include <linux/delay.h> #include <linux/delay.h>
#include <linux/netdevice.h> #include <linux/netdevice.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <asm/io.h> #include <linux/io.h>
#include <linux/arcdevice.h>
#define VERSION "arcnet: COM90xx chipset support\n"
#include "arcdevice.h"
#include "com9026.h"
/* Define this to speed up the autoprobe by assuming if only one io port and /* Define this to speed up the autoprobe by assuming if only one io port and
* shmem are left in the list at Stage 5, they must correspond to each * shmem are left in the list at Stage 5, they must correspond to each
...@@ -53,7 +54,6 @@ ...@@ -53,7 +54,6 @@
*/ */
#undef FAST_PROBE #undef FAST_PROBE
/* Internal function declarations */ /* Internal function declarations */
static int com90xx_found(int ioaddr, int airq, u_long shmem, void __iomem *); static int com90xx_found(int ioaddr, int airq, u_long shmem, void __iomem *);
static void com90xx_command(struct net_device *dev, int command); static void com90xx_command(struct net_device *dev, int command);
...@@ -62,8 +62,8 @@ static void com90xx_setmask(struct net_device *dev, int mask); ...@@ -62,8 +62,8 @@ static void com90xx_setmask(struct net_device *dev, int mask);
static int com90xx_reset(struct net_device *dev, int really_reset); static int com90xx_reset(struct net_device *dev, int really_reset);
static void com90xx_copy_to_card(struct net_device *dev, int bufnum, int offset, static void com90xx_copy_to_card(struct net_device *dev, int bufnum, int offset,
void *buf, int count); void *buf, int count);
static void com90xx_copy_from_card(struct net_device *dev, int bufnum, int offset, static void com90xx_copy_from_card(struct net_device *dev, int bufnum,
void *buf, int count); int offset, void *buf, int count);
/* Known ARCnet cards */ /* Known ARCnet cards */
...@@ -77,26 +77,7 @@ static int numcards; ...@@ -77,26 +77,7 @@ static int numcards;
/* Amount of I/O memory used by the card */ /* Amount of I/O memory used by the card */
#define BUFFER_SIZE (512) #define BUFFER_SIZE (512)
#define MIRROR_SIZE (BUFFER_SIZE*4) #define MIRROR_SIZE (BUFFER_SIZE * 4)
/* COM 9026 controller chip --> ARCnet register addresses */
#define _INTMASK (ioaddr+0) /* writable */
#define _STATUS (ioaddr+0) /* readable */
#define _COMMAND (ioaddr+1) /* writable, returns random vals on read (?) */
#define _CONFIG (ioaddr+2) /* Configuration register */
#define _RESET (ioaddr+8) /* software reset (on read) */
#define _MEMDATA (ioaddr+12) /* Data port for IO-mapped memory */
#define _ADDR_HI (ioaddr+15) /* Control registers for said */
#define _ADDR_LO (ioaddr+14)
#undef ASTATUS
#undef ACOMMAND
#undef AINTMASK
#define ASTATUS() inb(_STATUS)
#define ACOMMAND(cmd) outb((cmd),_COMMAND)
#define AINTMASK(msk) outb((msk),_INTMASK)
static int com90xx_skip_probe __initdata = 0; static int com90xx_skip_probe __initdata = 0;
...@@ -116,8 +97,7 @@ static void __init com90xx_probe(void) ...@@ -116,8 +97,7 @@ static void __init com90xx_probe(void)
{ {
int count, status, ioaddr, numprint, airq, openparen = 0; int count, status, ioaddr, numprint, airq, openparen = 0;
unsigned long airqmask; unsigned long airqmask;
int ports[(0x3f0 - 0x200) / 16 + 1] = int ports[(0x3f0 - 0x200) / 16 + 1] = { 0 };
{0};
unsigned long *shmems; unsigned long *shmems;
void __iomem **iomem; void __iomem **iomem;
int numports, numshmems, *port; int numports, numshmems, *port;
...@@ -127,18 +107,19 @@ static void __init com90xx_probe(void) ...@@ -127,18 +107,19 @@ static void __init com90xx_probe(void)
if (!io && !irq && !shmem && !*device && com90xx_skip_probe) if (!io && !irq && !shmem && !*device && com90xx_skip_probe)
return; return;
shmems = kzalloc(((0x100000-0xa0000) / 0x800) * sizeof(unsigned long), shmems = kzalloc(((0x100000 - 0xa0000) / 0x800) * sizeof(unsigned long),
GFP_KERNEL); GFP_KERNEL);
if (!shmems) if (!shmems)
return; return;
iomem = kzalloc(((0x100000-0xa0000) / 0x800) * sizeof(void __iomem *), iomem = kzalloc(((0x100000 - 0xa0000) / 0x800) * sizeof(void __iomem *),
GFP_KERNEL); GFP_KERNEL);
if (!iomem) { if (!iomem) {
kfree(shmems); kfree(shmems);
return; return;
} }
BUGLVL(D_NORMAL) printk(VERSION); if (BUGLVL(D_NORMAL))
pr_info("%s\n", "COM90xx chipset support");
/* set up the arrays where we'll store the possible probe addresses */ /* set up the arrays where we'll store the possible probe addresses */
numports = numshmems = 0; numports = numshmems = 0;
...@@ -161,38 +142,43 @@ static void __init com90xx_probe(void) ...@@ -161,38 +142,43 @@ static void __init com90xx_probe(void)
numprint++; numprint++;
numprint %= 8; numprint %= 8;
if (!numprint) { if (!numprint) {
BUGMSG2(D_INIT, "\n"); arc_cont(D_INIT, "\n");
BUGMSG2(D_INIT, "S1: "); arc_cont(D_INIT, "S1: ");
} }
BUGMSG2(D_INIT, "%Xh ", *port); arc_cont(D_INIT, "%Xh ", *port);
ioaddr = *port; ioaddr = *port;
if (!request_region(*port, ARCNET_TOTAL_SIZE, "arcnet (90xx)")) { if (!request_region(*port, ARCNET_TOTAL_SIZE,
BUGMSG2(D_INIT_REASONS, "(request_region)\n"); "arcnet (90xx)")) {
BUGMSG2(D_INIT_REASONS, "S1: "); arc_cont(D_INIT_REASONS, "(request_region)\n");
BUGLVL(D_INIT_REASONS) numprint = 0; arc_cont(D_INIT_REASONS, "S1: ");
if (BUGLVL(D_INIT_REASONS))
numprint = 0;
*port-- = ports[--numports]; *port-- = ports[--numports];
continue; continue;
} }
if (ASTATUS() == 0xFF) { if (arcnet_inb(ioaddr, COM9026_REG_R_STATUS) == 0xFF) {
BUGMSG2(D_INIT_REASONS, "(empty)\n"); arc_cont(D_INIT_REASONS, "(empty)\n");
BUGMSG2(D_INIT_REASONS, "S1: "); arc_cont(D_INIT_REASONS, "S1: ");
BUGLVL(D_INIT_REASONS) numprint = 0; if (BUGLVL(D_INIT_REASONS))
numprint = 0;
release_region(*port, ARCNET_TOTAL_SIZE); release_region(*port, ARCNET_TOTAL_SIZE);
*port-- = ports[--numports]; *port-- = ports[--numports];
continue; continue;
} }
inb(_RESET); /* begin resetting card */ /* begin resetting card */
arcnet_inb(ioaddr, COM9026_REG_R_RESET);
BUGMSG2(D_INIT_REASONS, "\n"); arc_cont(D_INIT_REASONS, "\n");
BUGMSG2(D_INIT_REASONS, "S1: "); arc_cont(D_INIT_REASONS, "S1: ");
BUGLVL(D_INIT_REASONS) numprint = 0; if (BUGLVL(D_INIT_REASONS))
numprint = 0;
} }
BUGMSG2(D_INIT, "\n"); arc_cont(D_INIT, "\n");
if (!numports) { if (!numports) {
BUGMSG2(D_NORMAL, "S1: No ARCnet cards found.\n"); arc_cont(D_NORMAL, "S1: No ARCnet cards found.\n");
kfree(shmems); kfree(shmems);
kfree(iomem); kfree(iomem);
return; return;
...@@ -206,12 +192,12 @@ static void __init com90xx_probe(void) ...@@ -206,12 +192,12 @@ static void __init com90xx_probe(void)
numprint++; numprint++;
numprint %= 8; numprint %= 8;
if (!numprint) { if (!numprint) {
BUGMSG2(D_INIT, "\n"); arc_cont(D_INIT, "\n");
BUGMSG2(D_INIT, "S2: "); arc_cont(D_INIT, "S2: ");
} }
BUGMSG2(D_INIT, "%Xh ", *port); arc_cont(D_INIT, "%Xh ", *port);
} }
BUGMSG2(D_INIT, "\n"); arc_cont(D_INIT, "\n");
mdelay(RESETtime); mdelay(RESETtime);
/* Stage 3: abandon any shmem addresses that don't have the signature /* Stage 3: abandon any shmem addresses that don't have the signature
...@@ -224,29 +210,33 @@ static void __init com90xx_probe(void) ...@@ -224,29 +210,33 @@ static void __init com90xx_probe(void)
numprint++; numprint++;
numprint %= 8; numprint %= 8;
if (!numprint) { if (!numprint) {
BUGMSG2(D_INIT, "\n"); arc_cont(D_INIT, "\n");
BUGMSG2(D_INIT, "S3: "); arc_cont(D_INIT, "S3: ");
} }
BUGMSG2(D_INIT, "%lXh ", *p); arc_cont(D_INIT, "%lXh ", *p);
if (!request_mem_region(*p, MIRROR_SIZE, "arcnet (90xx)")) { if (!request_mem_region(*p, MIRROR_SIZE, "arcnet (90xx)")) {
BUGMSG2(D_INIT_REASONS, "(request_mem_region)\n"); arc_cont(D_INIT_REASONS, "(request_mem_region)\n");
BUGMSG2(D_INIT_REASONS, "Stage 3: "); arc_cont(D_INIT_REASONS, "Stage 3: ");
BUGLVL(D_INIT_REASONS) numprint = 0; if (BUGLVL(D_INIT_REASONS))
numprint = 0;
goto out; goto out;
} }
base = ioremap(*p, MIRROR_SIZE); base = ioremap(*p, MIRROR_SIZE);
if (!base) { if (!base) {
BUGMSG2(D_INIT_REASONS, "(ioremap)\n"); arc_cont(D_INIT_REASONS, "(ioremap)\n");
BUGMSG2(D_INIT_REASONS, "Stage 3: "); arc_cont(D_INIT_REASONS, "Stage 3: ");
BUGLVL(D_INIT_REASONS) numprint = 0; if (BUGLVL(D_INIT_REASONS))
numprint = 0;
goto out1; goto out1;
} }
if (readb(base) != TESTvalue) { if (arcnet_readb(base, COM9026_REG_R_STATUS) != TESTvalue) {
BUGMSG2(D_INIT_REASONS, "(%02Xh != %02Xh)\n", arc_cont(D_INIT_REASONS, "(%02Xh != %02Xh)\n",
readb(base), TESTvalue); arcnet_readb(base, COM9026_REG_R_STATUS),
BUGMSG2(D_INIT_REASONS, "S3: "); TESTvalue);
BUGLVL(D_INIT_REASONS) numprint = 0; arc_cont(D_INIT_REASONS, "S3: ");
if (BUGLVL(D_INIT_REASONS))
numprint = 0;
goto out2; goto out2;
} }
/* By writing 0x42 to the TESTvalue location, we also make /* By writing 0x42 to the TESTvalue location, we also make
...@@ -254,15 +244,16 @@ static void __init com90xx_probe(void) ...@@ -254,15 +244,16 @@ static void __init com90xx_probe(void)
* in another pass through this loop, they will be discarded * in another pass through this loop, they will be discarded
* because *cptr != TESTvalue. * because *cptr != TESTvalue.
*/ */
writeb(0x42, base); arcnet_writeb(0x42, base, COM9026_REG_W_INTMASK);
if (readb(base) != 0x42) { if (arcnet_readb(base, COM9026_REG_R_STATUS) != 0x42) {
BUGMSG2(D_INIT_REASONS, "(read only)\n"); arc_cont(D_INIT_REASONS, "(read only)\n");
BUGMSG2(D_INIT_REASONS, "S3: "); arc_cont(D_INIT_REASONS, "S3: ");
goto out2; goto out2;
} }
BUGMSG2(D_INIT_REASONS, "\n"); arc_cont(D_INIT_REASONS, "\n");
BUGMSG2(D_INIT_REASONS, "S3: "); arc_cont(D_INIT_REASONS, "S3: ");
BUGLVL(D_INIT_REASONS) numprint = 0; if (BUGLVL(D_INIT_REASONS))
numprint = 0;
iomem[index] = base; iomem[index] = base;
continue; continue;
out2: out2:
...@@ -273,10 +264,10 @@ static void __init com90xx_probe(void) ...@@ -273,10 +264,10 @@ static void __init com90xx_probe(void)
*p-- = shmems[--numshmems]; *p-- = shmems[--numshmems];
index--; index--;
} }
BUGMSG2(D_INIT, "\n"); arc_cont(D_INIT, "\n");
if (!numshmems) { if (!numshmems) {
BUGMSG2(D_NORMAL, "S3: No ARCnet cards found.\n"); arc_cont(D_NORMAL, "S3: No ARCnet cards found.\n");
for (port = &ports[0]; port < ports + numports; port++) for (port = &ports[0]; port < ports + numports; port++)
release_region(*port, ARCNET_TOTAL_SIZE); release_region(*port, ARCNET_TOTAL_SIZE);
kfree(shmems); kfree(shmems);
...@@ -291,12 +282,12 @@ static void __init com90xx_probe(void) ...@@ -291,12 +282,12 @@ static void __init com90xx_probe(void)
numprint++; numprint++;
numprint %= 8; numprint %= 8;
if (!numprint) { if (!numprint) {
BUGMSG2(D_INIT, "\n"); arc_cont(D_INIT, "\n");
BUGMSG2(D_INIT, "S4: "); arc_cont(D_INIT, "S4: ");
} }
BUGMSG2(D_INIT, "%lXh ", *p); arc_cont(D_INIT, "%lXh ", *p);
} }
BUGMSG2(D_INIT, "\n"); arc_cont(D_INIT, "\n");
/* Stage 5: for any ports that have the correct status, can disable /* Stage 5: for any ports that have the correct status, can disable
* the RESET flag, and (if no irq is given) generate an autoirq, * the RESET flag, and (if no irq is given) generate an autoirq,
...@@ -308,33 +299,37 @@ static void __init com90xx_probe(void) ...@@ -308,33 +299,37 @@ static void __init com90xx_probe(void)
numprint = -1; numprint = -1;
for (port = &ports[0]; port < ports + numports; port++) { for (port = &ports[0]; port < ports + numports; port++) {
int found = 0; int found = 0;
numprint++; numprint++;
numprint %= 8; numprint %= 8;
if (!numprint) { if (!numprint) {
BUGMSG2(D_INIT, "\n"); arc_cont(D_INIT, "\n");
BUGMSG2(D_INIT, "S5: "); arc_cont(D_INIT, "S5: ");
} }
BUGMSG2(D_INIT, "%Xh ", *port); arc_cont(D_INIT, "%Xh ", *port);
ioaddr = *port; ioaddr = *port;
status = ASTATUS(); status = arcnet_inb(ioaddr, COM9026_REG_R_STATUS);
if ((status & 0x9D) if ((status & 0x9D)
!= (NORXflag | RECONflag | TXFREEflag | RESETflag)) { != (NORXflag | RECONflag | TXFREEflag | RESETflag)) {
BUGMSG2(D_INIT_REASONS, "(status=%Xh)\n", status); arc_cont(D_INIT_REASONS, "(status=%Xh)\n", status);
BUGMSG2(D_INIT_REASONS, "S5: "); arc_cont(D_INIT_REASONS, "S5: ");
BUGLVL(D_INIT_REASONS) numprint = 0; if (BUGLVL(D_INIT_REASONS))
numprint = 0;
release_region(*port, ARCNET_TOTAL_SIZE); release_region(*port, ARCNET_TOTAL_SIZE);
*port-- = ports[--numports]; *port-- = ports[--numports];
continue; continue;
} }
ACOMMAND(CFLAGScmd | RESETclear | CONFIGclear); arcnet_outb(CFLAGScmd | RESETclear | CONFIGclear,
status = ASTATUS(); ioaddr, COM9026_REG_W_COMMAND);
status = arcnet_inb(ioaddr, COM9026_REG_R_STATUS);
if (status & RESETflag) { if (status & RESETflag) {
BUGMSG2(D_INIT_REASONS, " (eternal reset, status=%Xh)\n", arc_cont(D_INIT_REASONS, " (eternal reset, status=%Xh)\n",
status); status);
BUGMSG2(D_INIT_REASONS, "S5: "); arc_cont(D_INIT_REASONS, "S5: ");
BUGLVL(D_INIT_REASONS) numprint = 0; if (BUGLVL(D_INIT_REASONS))
numprint = 0;
release_region(*port, ARCNET_TOTAL_SIZE); release_region(*port, ARCNET_TOTAL_SIZE);
*port-- = ports[--numports]; *port-- = ports[--numports];
continue; continue;
...@@ -348,15 +343,16 @@ static void __init com90xx_probe(void) ...@@ -348,15 +343,16 @@ static void __init com90xx_probe(void)
* we tell it to start receiving. * we tell it to start receiving.
*/ */
airqmask = probe_irq_on(); airqmask = probe_irq_on();
AINTMASK(NORXflag); arcnet_outb(NORXflag, ioaddr, COM9026_REG_W_INTMASK);
udelay(1); udelay(1);
AINTMASK(0); arcnet_outb(0, ioaddr, COM9026_REG_W_INTMASK);
airq = probe_irq_off(airqmask); airq = probe_irq_off(airqmask);
if (airq <= 0) { if (airq <= 0) {
BUGMSG2(D_INIT_REASONS, "(airq=%d)\n", airq); arc_cont(D_INIT_REASONS, "(airq=%d)\n", airq);
BUGMSG2(D_INIT_REASONS, "S5: "); arc_cont(D_INIT_REASONS, "S5: ");
BUGLVL(D_INIT_REASONS) numprint = 0; if (BUGLVL(D_INIT_REASONS))
numprint = 0;
release_region(*port, ARCNET_TOTAL_SIZE); release_region(*port, ARCNET_TOTAL_SIZE);
*port-- = ports[--numports]; *port-- = ports[--numports];
continue; continue;
...@@ -365,7 +361,7 @@ static void __init com90xx_probe(void) ...@@ -365,7 +361,7 @@ static void __init com90xx_probe(void)
airq = irq; airq = irq;
} }
BUGMSG2(D_INIT, "(%d,", airq); arc_cont(D_INIT, "(%d,", airq);
openparen = 1; openparen = 1;
/* Everything seems okay. But which shmem, if any, puts /* Everything seems okay. But which shmem, if any, puts
...@@ -376,14 +372,15 @@ static void __init com90xx_probe(void) ...@@ -376,14 +372,15 @@ static void __init com90xx_probe(void)
*/ */
#ifdef FAST_PROBE #ifdef FAST_PROBE
if (numports > 1 || numshmems > 1) { if (numports > 1 || numshmems > 1) {
inb(_RESET); arcnet_inb(ioaddr, COM9026_REG_R_RESET);
mdelay(RESETtime); mdelay(RESETtime);
} else { } else {
/* just one shmem and port, assume they match */ /* just one shmem and port, assume they match */
writeb(TESTvalue, iomem[0]); arcnet_writeb(TESTvalue, iomem[0],
COM9026_REG_W_INTMASK);
} }
#else #else
inb(_RESET); arcnet_inb(ioaddr, COM9026_REG_R_RESET);
mdelay(RESETtime); mdelay(RESETtime);
#endif #endif
...@@ -391,8 +388,8 @@ static void __init com90xx_probe(void) ...@@ -391,8 +388,8 @@ static void __init com90xx_probe(void)
u_long ptr = shmems[index]; u_long ptr = shmems[index];
void __iomem *base = iomem[index]; void __iomem *base = iomem[index];
if (readb(base) == TESTvalue) { /* found one */ if (arcnet_readb(base, COM9026_REG_R_STATUS) == TESTvalue) { /* found one */
BUGMSG2(D_INIT, "%lXh)\n", *p); arc_cont(D_INIT, "%lXh)\n", *p);
openparen = 0; openparen = 0;
/* register the card */ /* register the card */
...@@ -405,25 +402,30 @@ static void __init com90xx_probe(void) ...@@ -405,25 +402,30 @@ static void __init com90xx_probe(void)
iomem[index] = iomem[numshmems]; iomem[index] = iomem[numshmems];
break; /* go to the next I/O port */ break; /* go to the next I/O port */
} else { } else {
BUGMSG2(D_INIT_REASONS, "%Xh-", readb(base)); arc_cont(D_INIT_REASONS, "%Xh-",
arcnet_readb(base, COM9026_REG_R_STATUS));
} }
} }
if (openparen) { if (openparen) {
BUGLVL(D_INIT) printk("no matching shmem)\n"); if (BUGLVL(D_INIT))
BUGLVL(D_INIT_REASONS) printk("S5: "); pr_cont("no matching shmem)\n");
BUGLVL(D_INIT_REASONS) numprint = 0; if (BUGLVL(D_INIT_REASONS)) {
pr_cont("S5: ");
numprint = 0;
}
} }
if (!found) if (!found)
release_region(*port, ARCNET_TOTAL_SIZE); release_region(*port, ARCNET_TOTAL_SIZE);
*port-- = ports[--numports]; *port-- = ports[--numports];
} }
BUGLVL(D_INIT_REASONS) printk("\n"); if (BUGLVL(D_INIT_REASONS))
pr_cont("\n");
/* Now put back TESTvalue on all leftover shmems. */ /* Now put back TESTvalue on all leftover shmems. */
for (index = 0; index < numshmems; index++) { for (index = 0; index < numshmems; index++) {
writeb(TESTvalue, iomem[index]); arcnet_writeb(TESTvalue, iomem[index], COM9026_REG_W_INTMASK);
iounmap(iomem[index]); iounmap(iomem[index]);
release_mem_region(shmems[index], MIRROR_SIZE); release_mem_region(shmems[index], MIRROR_SIZE);
} }
...@@ -441,7 +443,7 @@ static int check_mirror(unsigned long addr, size_t size) ...@@ -441,7 +443,7 @@ static int check_mirror(unsigned long addr, size_t size)
p = ioremap(addr, size); p = ioremap(addr, size);
if (p) { if (p) {
if (readb(p) == TESTvalue) if (arcnet_readb(p, COM9026_REG_R_STATUS) == TESTvalue)
res = 1; res = 1;
else else
res = 0; res = 0;
...@@ -455,7 +457,8 @@ static int check_mirror(unsigned long addr, size_t size) ...@@ -455,7 +457,8 @@ static int check_mirror(unsigned long addr, size_t size)
/* Set up the struct net_device associated with this card. Called after /* Set up the struct net_device associated with this card. Called after
* probing succeeds. * probing succeeds.
*/ */
static int __init com90xx_found(int ioaddr, int airq, u_long shmem, void __iomem *p) static int __init com90xx_found(int ioaddr, int airq, u_long shmem,
void __iomem *p)
{ {
struct net_device *dev = NULL; struct net_device *dev = NULL;
struct arcnet_local *lp; struct arcnet_local *lp;
...@@ -465,7 +468,7 @@ static int __init com90xx_found(int ioaddr, int airq, u_long shmem, void __iomem ...@@ -465,7 +468,7 @@ static int __init com90xx_found(int ioaddr, int airq, u_long shmem, void __iomem
/* allocate struct net_device */ /* allocate struct net_device */
dev = alloc_arcdev(device); dev = alloc_arcdev(device);
if (!dev) { if (!dev) {
BUGMSG2(D_NORMAL, "com90xx: Can't allocate device!\n"); arc_cont(D_NORMAL, "com90xx: Can't allocate device!\n");
iounmap(p); iounmap(p);
release_mem_region(shmem, MIRROR_SIZE); release_mem_region(shmem, MIRROR_SIZE);
return -ENOMEM; return -ENOMEM;
...@@ -478,7 +481,7 @@ static int __init com90xx_found(int ioaddr, int airq, u_long shmem, void __iomem ...@@ -478,7 +481,7 @@ static int __init com90xx_found(int ioaddr, int airq, u_long shmem, void __iomem
* 2k (or there are no mirrors at all) but on some, it's 4k. * 2k (or there are no mirrors at all) but on some, it's 4k.
*/ */
mirror_size = MIRROR_SIZE; mirror_size = MIRROR_SIZE;
if (readb(p) == TESTvalue && if (arcnet_readb(p, COM9026_REG_R_STATUS) == TESTvalue &&
check_mirror(shmem - MIRROR_SIZE, MIRROR_SIZE) == 0 && check_mirror(shmem - MIRROR_SIZE, MIRROR_SIZE) == 0 &&
check_mirror(shmem - 2 * MIRROR_SIZE, MIRROR_SIZE) == 1) check_mirror(shmem - 2 * MIRROR_SIZE, MIRROR_SIZE) == 1)
mirror_size = 2 * MIRROR_SIZE; mirror_size = 2 * MIRROR_SIZE;
...@@ -499,12 +502,14 @@ static int __init com90xx_found(int ioaddr, int airq, u_long shmem, void __iomem ...@@ -499,12 +502,14 @@ static int __init com90xx_found(int ioaddr, int airq, u_long shmem, void __iomem
iounmap(p); iounmap(p);
release_mem_region(shmem, MIRROR_SIZE); release_mem_region(shmem, MIRROR_SIZE);
if (!request_mem_region(dev->mem_start, dev->mem_end - dev->mem_start + 1, "arcnet (90xx)")) if (!request_mem_region(dev->mem_start,
dev->mem_end - dev->mem_start + 1,
"arcnet (90xx)"))
goto err_free_dev; goto err_free_dev;
/* reserve the irq */ /* reserve the irq */
if (request_irq(airq, arcnet_interrupt, 0, "arcnet (90xx)", dev)) { if (request_irq(airq, arcnet_interrupt, 0, "arcnet (90xx)", dev)) {
BUGMSG(D_NORMAL, "Can't get IRQ %d!\n", airq); arc_printk(D_NORMAL, dev, "Can't get IRQ %d!\n", airq);
goto err_release_mem; goto err_release_mem;
} }
dev->irq = airq; dev->irq = airq;
...@@ -518,22 +523,23 @@ static int __init com90xx_found(int ioaddr, int airq, u_long shmem, void __iomem ...@@ -518,22 +523,23 @@ static int __init com90xx_found(int ioaddr, int airq, u_long shmem, void __iomem
lp->hw.owner = THIS_MODULE; lp->hw.owner = THIS_MODULE;
lp->hw.copy_to_card = com90xx_copy_to_card; lp->hw.copy_to_card = com90xx_copy_to_card;
lp->hw.copy_from_card = com90xx_copy_from_card; lp->hw.copy_from_card = com90xx_copy_from_card;
lp->mem_start = ioremap(dev->mem_start, dev->mem_end - dev->mem_start + 1); lp->mem_start = ioremap(dev->mem_start,
dev->mem_end - dev->mem_start + 1);
if (!lp->mem_start) { if (!lp->mem_start) {
BUGMSG(D_NORMAL, "Can't remap device memory!\n"); arc_printk(D_NORMAL, dev, "Can't remap device memory!\n");
goto err_free_irq; goto err_free_irq;
} }
/* get and check the station ID from offset 1 in shmem */ /* get and check the station ID from offset 1 in shmem */
dev->dev_addr[0] = readb(lp->mem_start + 1); dev->dev_addr[0] = arcnet_readb(lp->mem_start, COM9026_REG_R_STATION);
dev->base_addr = ioaddr; dev->base_addr = ioaddr;
BUGMSG(D_NORMAL, "COM90xx station %02Xh found at %03lXh, IRQ %d, " arc_printk(D_NORMAL, dev, "COM90xx station %02Xh found at %03lXh, IRQ %d, ShMem %lXh (%ld*%xh).\n",
"ShMem %lXh (%ld*%xh).\n", dev->dev_addr[0],
dev->dev_addr[0], dev->base_addr, dev->irq, dev->mem_start,
dev->base_addr, dev->irq, dev->mem_start, (dev->mem_end - dev->mem_start + 1) / mirror_size,
(dev->mem_end - dev->mem_start + 1) / mirror_size, mirror_size); mirror_size);
if (register_netdev(dev)) if (register_netdev(dev))
goto err_unmap; goto err_unmap;
...@@ -552,34 +558,29 @@ static int __init com90xx_found(int ioaddr, int airq, u_long shmem, void __iomem ...@@ -552,34 +558,29 @@ static int __init com90xx_found(int ioaddr, int airq, u_long shmem, void __iomem
return -EIO; return -EIO;
} }
static void com90xx_command(struct net_device *dev, int cmd) static void com90xx_command(struct net_device *dev, int cmd)
{ {
short ioaddr = dev->base_addr; short ioaddr = dev->base_addr;
ACOMMAND(cmd); arcnet_outb(cmd, ioaddr, COM9026_REG_W_COMMAND);
} }
static int com90xx_status(struct net_device *dev) static int com90xx_status(struct net_device *dev)
{ {
short ioaddr = dev->base_addr; short ioaddr = dev->base_addr;
return ASTATUS(); return arcnet_inb(ioaddr, COM9026_REG_R_STATUS);
} }
static void com90xx_setmask(struct net_device *dev, int mask) static void com90xx_setmask(struct net_device *dev, int mask)
{ {
short ioaddr = dev->base_addr; short ioaddr = dev->base_addr;
AINTMASK(mask); arcnet_outb(mask, ioaddr, COM9026_REG_W_INTMASK);
} }
/* Do a hardware reset on the card, and set up necessary registers.
/* *
* Do a hardware reset on the card, and set up necessary registers.
*
* This should be called as little as possible, because it disrupts the * This should be called as little as possible, because it disrupts the
* token on the network (causes a RECON) and requires a significant delay. * token on the network (causes a RECON) and requires a significant delay.
* *
...@@ -590,53 +591,58 @@ static int com90xx_reset(struct net_device *dev, int really_reset) ...@@ -590,53 +591,58 @@ static int com90xx_reset(struct net_device *dev, int really_reset)
struct arcnet_local *lp = netdev_priv(dev); struct arcnet_local *lp = netdev_priv(dev);
short ioaddr = dev->base_addr; short ioaddr = dev->base_addr;
BUGMSG(D_INIT, "Resetting (status=%02Xh)\n", ASTATUS()); arc_printk(D_INIT, dev, "Resetting (status=%02Xh)\n",
arcnet_inb(ioaddr, COM9026_REG_R_STATUS));
if (really_reset) { if (really_reset) {
/* reset the card */ /* reset the card */
inb(_RESET); arcnet_inb(ioaddr, COM9026_REG_R_RESET);
mdelay(RESETtime); mdelay(RESETtime);
} }
ACOMMAND(CFLAGScmd | RESETclear); /* clear flags & end reset */ /* clear flags & end reset */
ACOMMAND(CFLAGScmd | CONFIGclear); arcnet_outb(CFLAGScmd | RESETclear, ioaddr, COM9026_REG_W_COMMAND);
arcnet_outb(CFLAGScmd | CONFIGclear, ioaddr, COM9026_REG_W_COMMAND);
#if 0
/* don't do this until we verify that it doesn't hurt older cards! */ /* don't do this until we verify that it doesn't hurt older cards! */
/* outb(inb(_CONFIG) | ENABLE16flag, _CONFIG); */ arcnet_outb(arcnet_inb(ioaddr, COM9026_REG_RW_CONFIG) | ENABLE16flag,
ioaddr, COM9026_REG_RW_CONFIG);
#endif
/* verify that the ARCnet signature byte is present */ /* verify that the ARCnet signature byte is present */
if (readb(lp->mem_start) != TESTvalue) { if (arcnet_readb(lp->mem_start, COM9026_REG_R_STATUS) != TESTvalue) {
if (really_reset) if (really_reset)
BUGMSG(D_NORMAL, "reset failed: TESTvalue not present.\n"); arc_printk(D_NORMAL, dev, "reset failed: TESTvalue not present.\n");
return 1; return 1;
} }
/* enable extended (512-byte) packets */ /* enable extended (512-byte) packets */
ACOMMAND(CONFIGcmd | EXTconf); arcnet_outb(CONFIGcmd | EXTconf, ioaddr, COM9026_REG_W_COMMAND);
/* clean out all the memory to make debugging make more sense :) */ /* clean out all the memory to make debugging make more sense :) */
BUGLVL(D_DURING) if (BUGLVL(D_DURING))
memset_io(lp->mem_start, 0x42, 2048); memset_io(lp->mem_start, 0x42, 2048);
/* done! return success. */ /* done! return success. */
return 0; return 0;
} }
static void com90xx_copy_to_card(struct net_device *dev, int bufnum, int offset, static void com90xx_copy_to_card(struct net_device *dev, int bufnum,
void *buf, int count) int offset, void *buf, int count)
{ {
struct arcnet_local *lp = netdev_priv(dev); struct arcnet_local *lp = netdev_priv(dev);
void __iomem *memaddr = lp->mem_start + bufnum * 512 + offset; void __iomem *memaddr = lp->mem_start + bufnum * 512 + offset;
TIME("memcpy_toio", count, memcpy_toio(memaddr, buf, count));
}
TIME(dev, "memcpy_toio", count, memcpy_toio(memaddr, buf, count));
}
static void com90xx_copy_from_card(struct net_device *dev, int bufnum, int offset, static void com90xx_copy_from_card(struct net_device *dev, int bufnum,
void *buf, int count) int offset, void *buf, int count)
{ {
struct arcnet_local *lp = netdev_priv(dev); struct arcnet_local *lp = netdev_priv(dev);
void __iomem *memaddr = lp->mem_start + bufnum * 512 + offset; void __iomem *memaddr = lp->mem_start + bufnum * 512 + offset;
TIME("memcpy_fromio", count, memcpy_fromio(buf, memaddr, count));
}
TIME(dev, "memcpy_fromio", count, memcpy_fromio(buf, memaddr, count));
}
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
...@@ -664,7 +670,8 @@ static void __exit com90xx_exit(void) ...@@ -664,7 +670,8 @@ static void __exit com90xx_exit(void)
free_irq(dev->irq, dev); free_irq(dev->irq, dev);
iounmap(lp->mem_start); iounmap(lp->mem_start);
release_region(dev->base_addr, ARCNET_TOTAL_SIZE); release_region(dev->base_addr, ARCNET_TOTAL_SIZE);
release_mem_region(dev->mem_start, dev->mem_end - dev->mem_start + 1); release_mem_region(dev->mem_start,
dev->mem_end - dev->mem_start + 1);
free_netdev(dev); free_netdev(dev);
} }
} }
...@@ -679,13 +686,13 @@ static int __init com90xx_setup(char *s) ...@@ -679,13 +686,13 @@ static int __init com90xx_setup(char *s)
s = get_options(s, 8, ints); s = get_options(s, 8, ints);
if (!ints[0] && !*s) { if (!ints[0] && !*s) {
printk("com90xx: Disabled.\n"); pr_notice("Disabled\n");
return 1; return 1;
} }
switch (ints[0]) { switch (ints[0]) {
default: /* ERROR */ default: /* ERROR */
printk("com90xx: Too many arguments.\n"); pr_err("Too many arguments\n");
case 3: /* Mem address */ case 3: /* Mem address */
shmem = ints[3]; shmem = ints[3];
case 2: /* IRQ */ case 2: /* IRQ */
......
/* /*
* Linux ARCnet driver - RFC1051 ("simple" standard) packet encapsulation * Linux ARCnet driver - RFC1051 ("simple" standard) packet encapsulation
* *
* Written 1994-1999 by Avery Pennarun. * Written 1994-1999 by Avery Pennarun.
* Derived from skeleton.c by Donald Becker. * Derived from skeleton.c by Donald Becker.
* *
...@@ -23,6 +23,9 @@ ...@@ -23,6 +23,9 @@
* *
* ********************** * **********************
*/ */
#define pr_fmt(fmt) "arcnet:" KBUILD_MODNAME ": " fmt
#include <linux/module.h> #include <linux/module.h>
#include <linux/gfp.h> #include <linux/gfp.h>
#include <linux/init.h> #include <linux/init.h>
...@@ -30,10 +33,8 @@ ...@@ -30,10 +33,8 @@
#include <net/arp.h> #include <net/arp.h>
#include <linux/netdevice.h> #include <linux/netdevice.h>
#include <linux/skbuff.h> #include <linux/skbuff.h>
#include <linux/arcdevice.h>
#define VERSION "arcnet: RFC1051 \"simple standard\" (`s') encapsulation support loaded.\n"
#include "arcdevice.h"
static __be16 type_trans(struct sk_buff *skb, struct net_device *dev); static __be16 type_trans(struct sk_buff *skb, struct net_device *dev);
static void rx(struct net_device *dev, int bufnum, static void rx(struct net_device *dev, int bufnum,
...@@ -43,9 +44,7 @@ static int build_header(struct sk_buff *skb, struct net_device *dev, ...@@ -43,9 +44,7 @@ static int build_header(struct sk_buff *skb, struct net_device *dev,
static int prepare_tx(struct net_device *dev, struct archdr *pkt, int length, static int prepare_tx(struct net_device *dev, struct archdr *pkt, int length,
int bufnum); int bufnum);
static struct ArcProto rfc1051_proto = {
static struct ArcProto rfc1051_proto =
{
.suffix = 's', .suffix = 's',
.mtu = XMTU - RFC1051_HDR_SIZE, .mtu = XMTU - RFC1051_HDR_SIZE,
.is_ip = 1, .is_ip = 1,
...@@ -56,10 +55,9 @@ static struct ArcProto rfc1051_proto = ...@@ -56,10 +55,9 @@ static struct ArcProto rfc1051_proto =
.ack_tx = NULL .ack_tx = NULL
}; };
static int __init arcnet_rfc1051_init(void) static int __init arcnet_rfc1051_init(void)
{ {
printk(VERSION); pr_info("%s\n", "RFC1051 \"simple standard\" (`s') encapsulation support loaded");
arc_proto_map[ARC_P_IP_RFC1051] arc_proto_map[ARC_P_IP_RFC1051]
= arc_proto_map[ARC_P_ARP_RFC1051] = arc_proto_map[ARC_P_ARP_RFC1051]
...@@ -82,14 +80,13 @@ module_exit(arcnet_rfc1051_exit); ...@@ -82,14 +80,13 @@ module_exit(arcnet_rfc1051_exit);
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
/* /* Determine a packet's protocol ID.
* Determine a packet's protocol ID. *
*
* With ARCnet we have to convert everything to Ethernet-style stuff. * With ARCnet we have to convert everything to Ethernet-style stuff.
*/ */
static __be16 type_trans(struct sk_buff *skb, struct net_device *dev) static __be16 type_trans(struct sk_buff *skb, struct net_device *dev)
{ {
struct archdr *pkt = (struct archdr *) skb->data; struct archdr *pkt = (struct archdr *)skb->data;
struct arc_rfc1051 *soft = &pkt->soft.rfc1051; struct arc_rfc1051 *soft = &pkt->soft.rfc1051;
int hdr_size = ARC_HDR_SIZE + RFC1051_HDR_SIZE; int hdr_size = ARC_HDR_SIZE + RFC1051_HDR_SIZE;
...@@ -97,9 +94,9 @@ static __be16 type_trans(struct sk_buff *skb, struct net_device *dev) ...@@ -97,9 +94,9 @@ static __be16 type_trans(struct sk_buff *skb, struct net_device *dev)
skb_reset_mac_header(skb); skb_reset_mac_header(skb);
skb_pull(skb, hdr_size); skb_pull(skb, hdr_size);
if (pkt->hard.dest == 0) if (pkt->hard.dest == 0) {
skb->pkt_type = PACKET_BROADCAST; skb->pkt_type = PACKET_BROADCAST;
else if (dev->flags & IFF_PROMISC) { } else if (dev->flags & IFF_PROMISC) {
/* if we're not sending to ourselves :) */ /* if we're not sending to ourselves :) */
if (pkt->hard.dest != dev->dev_addr[0]) if (pkt->hard.dest != dev->dev_addr[0])
skb->pkt_type = PACKET_OTHERHOST; skb->pkt_type = PACKET_OTHERHOST;
...@@ -120,7 +117,6 @@ static __be16 type_trans(struct sk_buff *skb, struct net_device *dev) ...@@ -120,7 +117,6 @@ static __be16 type_trans(struct sk_buff *skb, struct net_device *dev)
return htons(ETH_P_IP); return htons(ETH_P_IP);
} }
/* packet receiver */ /* packet receiver */
static void rx(struct net_device *dev, int bufnum, static void rx(struct net_device *dev, int bufnum,
struct archdr *pkthdr, int length) struct archdr *pkthdr, int length)
...@@ -130,7 +126,7 @@ static void rx(struct net_device *dev, int bufnum, ...@@ -130,7 +126,7 @@ static void rx(struct net_device *dev, int bufnum,
struct archdr *pkt = pkthdr; struct archdr *pkt = pkthdr;
int ofs; int ofs;
BUGMSG(D_DURING, "it's a raw packet (length=%d)\n", length); arc_printk(D_DURING, dev, "it's a raw packet (length=%d)\n", length);
if (length >= MinTU) if (length >= MinTU)
ofs = 512 - length; ofs = 512 - length;
...@@ -138,15 +134,14 @@ static void rx(struct net_device *dev, int bufnum, ...@@ -138,15 +134,14 @@ static void rx(struct net_device *dev, int bufnum,
ofs = 256 - length; ofs = 256 - length;
skb = alloc_skb(length + ARC_HDR_SIZE, GFP_ATOMIC); skb = alloc_skb(length + ARC_HDR_SIZE, GFP_ATOMIC);
if (skb == NULL) { if (!skb) {
BUGMSG(D_NORMAL, "Memory squeeze, dropping packet.\n");
dev->stats.rx_dropped++; dev->stats.rx_dropped++;
return; return;
} }
skb_put(skb, length + ARC_HDR_SIZE); skb_put(skb, length + ARC_HDR_SIZE);
skb->dev = dev; skb->dev = dev;
pkt = (struct archdr *) skb->data; pkt = (struct archdr *)skb->data;
/* up to sizeof(pkt->soft) has already been copied from the card */ /* up to sizeof(pkt->soft) has already been copied from the card */
memcpy(pkt, pkthdr, sizeof(struct archdr)); memcpy(pkt, pkthdr, sizeof(struct archdr));
...@@ -155,21 +150,19 @@ static void rx(struct net_device *dev, int bufnum, ...@@ -155,21 +150,19 @@ static void rx(struct net_device *dev, int bufnum,
pkt->soft.raw + sizeof(pkt->soft), pkt->soft.raw + sizeof(pkt->soft),
length - sizeof(pkt->soft)); length - sizeof(pkt->soft));
BUGLVL(D_SKB) arcnet_dump_skb(dev, skb, "rx"); if (BUGLVL(D_SKB))
arcnet_dump_skb(dev, skb, "rx");
skb->protocol = type_trans(skb, dev); skb->protocol = type_trans(skb, dev);
netif_rx(skb); netif_rx(skb);
} }
/* Create the ARCnet hard/soft headers for RFC1051 */
/*
* Create the ARCnet hard/soft headers for RFC1051.
*/
static int build_header(struct sk_buff *skb, struct net_device *dev, static int build_header(struct sk_buff *skb, struct net_device *dev,
unsigned short type, uint8_t daddr) unsigned short type, uint8_t daddr)
{ {
int hdr_size = ARC_HDR_SIZE + RFC1051_HDR_SIZE; int hdr_size = ARC_HDR_SIZE + RFC1051_HDR_SIZE;
struct archdr *pkt = (struct archdr *) skb_push(skb, hdr_size); struct archdr *pkt = (struct archdr *)skb_push(skb, hdr_size);
struct arc_rfc1051 *soft = &pkt->soft.rfc1051; struct arc_rfc1051 *soft = &pkt->soft.rfc1051;
/* set the protocol ID according to RFC1051 */ /* set the protocol ID according to RFC1051 */
...@@ -181,29 +174,26 @@ static int build_header(struct sk_buff *skb, struct net_device *dev, ...@@ -181,29 +174,26 @@ static int build_header(struct sk_buff *skb, struct net_device *dev,
soft->proto = ARC_P_ARP_RFC1051; soft->proto = ARC_P_ARP_RFC1051;
break; break;
default: default:
BUGMSG(D_NORMAL, "RFC1051: I don't understand protocol %d (%Xh)\n", arc_printk(D_NORMAL, dev, "RFC1051: I don't understand protocol %d (%Xh)\n",
type, type); type, type);
dev->stats.tx_errors++; dev->stats.tx_errors++;
dev->stats.tx_aborted_errors++; dev->stats.tx_aborted_errors++;
return 0; return 0;
} }
/* Set the source hardware address.
/*
* Set the source hardware address.
* *
* This is pretty pointless for most purposes, but it can help in * This is pretty pointless for most purposes, but it can help in
* debugging. ARCnet does not allow us to change the source address in * debugging. ARCnet does not allow us to change the source address
* the actual packet sent) * in the actual packet sent.
*/ */
pkt->hard.source = *dev->dev_addr; pkt->hard.source = *dev->dev_addr;
/* see linux/net/ethernet/eth.c to see where I got the following */ /* see linux/net/ethernet/eth.c to see where I got the following */
if (dev->flags & (IFF_LOOPBACK | IFF_NOARP)) { if (dev->flags & (IFF_LOOPBACK | IFF_NOARP)) {
/* /* FIXME: fill in the last byte of the dest ipaddr here to
* FIXME: fill in the last byte of the dest ipaddr here to better * better comply with RFC1051 in "noarp" mode.
* comply with RFC1051 in "noarp" mode.
*/ */
pkt->hard.dest = 0; pkt->hard.dest = 0;
return hdr_size; return hdr_size;
...@@ -214,7 +204,6 @@ static int build_header(struct sk_buff *skb, struct net_device *dev, ...@@ -214,7 +204,6 @@ static int build_header(struct sk_buff *skb, struct net_device *dev,
return hdr_size; /* success */ return hdr_size; /* success */
} }
static int prepare_tx(struct net_device *dev, struct archdr *pkt, int length, static int prepare_tx(struct net_device *dev, struct archdr *pkt, int length,
int bufnum) int bufnum)
{ {
...@@ -222,15 +211,16 @@ static int prepare_tx(struct net_device *dev, struct archdr *pkt, int length, ...@@ -222,15 +211,16 @@ static int prepare_tx(struct net_device *dev, struct archdr *pkt, int length,
struct arc_hardware *hard = &pkt->hard; struct arc_hardware *hard = &pkt->hard;
int ofs; int ofs;
BUGMSG(D_DURING, "prepare_tx: txbufs=%d/%d/%d\n", arc_printk(D_DURING, dev, "prepare_tx: txbufs=%d/%d/%d\n",
lp->next_tx, lp->cur_tx, bufnum); lp->next_tx, lp->cur_tx, bufnum);
length -= ARC_HDR_SIZE; /* hard header is not included in packet length */ /* hard header is not included in packet length */
length -= ARC_HDR_SIZE;
if (length > XMTU) { if (length > XMTU) {
/* should never happen! other people already check for this. */ /* should never happen! other people already check for this. */
BUGMSG(D_NORMAL, "Bug! prepare_tx with size %d (> %d)\n", arc_printk(D_NORMAL, dev, "Bug! prepare_tx with size %d (> %d)\n",
length, XMTU); length, XMTU);
length = XMTU; length = XMTU;
} }
if (length > MinTU) { if (length > MinTU) {
...@@ -239,8 +229,9 @@ static int prepare_tx(struct net_device *dev, struct archdr *pkt, int length, ...@@ -239,8 +229,9 @@ static int prepare_tx(struct net_device *dev, struct archdr *pkt, int length,
} else if (length > MTU) { } else if (length > MTU) {
hard->offset[0] = 0; hard->offset[0] = 0;
hard->offset[1] = ofs = 512 - length - 3; hard->offset[1] = ofs = 512 - length - 3;
} else } else {
hard->offset[0] = ofs = 256 - length; hard->offset[0] = ofs = 256 - length;
}
lp->hw.copy_to_card(dev, bufnum, 0, hard, ARC_HDR_SIZE); lp->hw.copy_to_card(dev, bufnum, 0, hard, ARC_HDR_SIZE);
lp->hw.copy_to_card(dev, bufnum, ofs, &pkt->soft, length); lp->hw.copy_to_card(dev, bufnum, ofs, &pkt->soft, length);
......
/* /*
* Linux ARCnet driver - RFC1201 (standard) packet encapsulation * Linux ARCnet driver - RFC1201 (standard) packet encapsulation
* *
* Written 1994-1999 by Avery Pennarun. * Written 1994-1999 by Avery Pennarun.
* Derived from skeleton.c by Donald Becker. * Derived from skeleton.c by Donald Becker.
* *
...@@ -23,17 +23,19 @@ ...@@ -23,17 +23,19 @@
* *
* ********************** * **********************
*/ */
#define pr_fmt(fmt) "arcnet:" KBUILD_MODNAME ": " fmt
#include <linux/gfp.h> #include <linux/gfp.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/if_arp.h> #include <linux/if_arp.h>
#include <linux/netdevice.h> #include <linux/netdevice.h>
#include <linux/skbuff.h> #include <linux/skbuff.h>
#include <linux/arcdevice.h>
MODULE_LICENSE("GPL"); #include "arcdevice.h"
#define VERSION "arcnet: RFC1201 \"standard\" (`a') encapsulation support loaded.\n"
MODULE_LICENSE("GPL");
static __be16 type_trans(struct sk_buff *skb, struct net_device *dev); static __be16 type_trans(struct sk_buff *skb, struct net_device *dev);
static void rx(struct net_device *dev, int bufnum, static void rx(struct net_device *dev, int bufnum,
...@@ -44,8 +46,7 @@ static int prepare_tx(struct net_device *dev, struct archdr *pkt, int length, ...@@ -44,8 +46,7 @@ static int prepare_tx(struct net_device *dev, struct archdr *pkt, int length,
int bufnum); int bufnum);
static int continue_tx(struct net_device *dev, int bufnum); static int continue_tx(struct net_device *dev, int bufnum);
static struct ArcProto rfc1201_proto = static struct ArcProto rfc1201_proto = {
{
.suffix = 'a', .suffix = 'a',
.mtu = 1500, /* could be more, but some receivers can't handle it... */ .mtu = 1500, /* could be more, but some receivers can't handle it... */
.is_ip = 1, /* This is for sending IP and ARP packages */ .is_ip = 1, /* This is for sending IP and ARP packages */
...@@ -56,10 +57,9 @@ static struct ArcProto rfc1201_proto = ...@@ -56,10 +57,9 @@ static struct ArcProto rfc1201_proto =
.ack_tx = NULL .ack_tx = NULL
}; };
static int __init arcnet_rfc1201_init(void) static int __init arcnet_rfc1201_init(void)
{ {
printk(VERSION); pr_info("%s\n", "RFC1201 \"standard\" (`a') encapsulation support loaded");
arc_proto_map[ARC_P_IP] arc_proto_map[ARC_P_IP]
= arc_proto_map[ARC_P_IPV6] = arc_proto_map[ARC_P_IPV6]
...@@ -84,14 +84,13 @@ static void __exit arcnet_rfc1201_exit(void) ...@@ -84,14 +84,13 @@ static void __exit arcnet_rfc1201_exit(void)
module_init(arcnet_rfc1201_init); module_init(arcnet_rfc1201_init);
module_exit(arcnet_rfc1201_exit); module_exit(arcnet_rfc1201_exit);
/* /* Determine a packet's protocol ID.
* Determine a packet's protocol ID. *
*
* With ARCnet we have to convert everything to Ethernet-style stuff. * With ARCnet we have to convert everything to Ethernet-style stuff.
*/ */
static __be16 type_trans(struct sk_buff *skb, struct net_device *dev) static __be16 type_trans(struct sk_buff *skb, struct net_device *dev)
{ {
struct archdr *pkt = (struct archdr *) skb->data; struct archdr *pkt = (struct archdr *)skb->data;
struct arc_rfc1201 *soft = &pkt->soft.rfc1201; struct arc_rfc1201 *soft = &pkt->soft.rfc1201;
int hdr_size = ARC_HDR_SIZE + RFC1201_HDR_SIZE; int hdr_size = ARC_HDR_SIZE + RFC1201_HDR_SIZE;
...@@ -99,9 +98,9 @@ static __be16 type_trans(struct sk_buff *skb, struct net_device *dev) ...@@ -99,9 +98,9 @@ static __be16 type_trans(struct sk_buff *skb, struct net_device *dev)
skb_reset_mac_header(skb); skb_reset_mac_header(skb);
skb_pull(skb, hdr_size); skb_pull(skb, hdr_size);
if (pkt->hard.dest == 0) if (pkt->hard.dest == 0) {
skb->pkt_type = PACKET_BROADCAST; skb->pkt_type = PACKET_BROADCAST;
else if (dev->flags & IFF_PROMISC) { } else if (dev->flags & IFF_PROMISC) {
/* if we're not sending to ourselves :) */ /* if we're not sending to ourselves :) */
if (pkt->hard.dest != dev->dev_addr[0]) if (pkt->hard.dest != dev->dev_addr[0])
skb->pkt_type = PACKET_OTHERHOST; skb->pkt_type = PACKET_OTHERHOST;
...@@ -129,7 +128,6 @@ static __be16 type_trans(struct sk_buff *skb, struct net_device *dev) ...@@ -129,7 +128,6 @@ static __be16 type_trans(struct sk_buff *skb, struct net_device *dev)
return htons(ETH_P_IP); return htons(ETH_P_IP);
} }
/* packet receiver */ /* packet receiver */
static void rx(struct net_device *dev, int bufnum, static void rx(struct net_device *dev, int bufnum,
struct archdr *pkthdr, int length) struct archdr *pkthdr, int length)
...@@ -141,7 +139,8 @@ static void rx(struct net_device *dev, int bufnum, ...@@ -141,7 +139,8 @@ static void rx(struct net_device *dev, int bufnum,
int saddr = pkt->hard.source, ofs; int saddr = pkt->hard.source, ofs;
struct Incoming *in = &lp->rfc1201.incoming[saddr]; struct Incoming *in = &lp->rfc1201.incoming[saddr];
BUGMSG(D_DURING, "it's an RFC1201 packet (length=%d)\n", length); arc_printk(D_DURING, dev, "it's an RFC1201 packet (length=%d)\n",
length);
if (length >= MinTU) if (length >= MinTU)
ofs = 512 - length; ofs = 512 - length;
...@@ -149,11 +148,11 @@ static void rx(struct net_device *dev, int bufnum, ...@@ -149,11 +148,11 @@ static void rx(struct net_device *dev, int bufnum,
ofs = 256 - length; ofs = 256 - length;
if (soft->split_flag == 0xFF) { /* Exception Packet */ if (soft->split_flag == 0xFF) { /* Exception Packet */
if (length >= 4 + RFC1201_HDR_SIZE) if (length >= 4 + RFC1201_HDR_SIZE) {
BUGMSG(D_DURING, "compensating for exception packet\n"); arc_printk(D_DURING, dev, "compensating for exception packet\n");
else { } else {
BUGMSG(D_EXTRA, "short RFC1201 exception packet from %02Xh", arc_printk(D_EXTRA, dev, "short RFC1201 exception packet from %02Xh",
saddr); saddr);
return; return;
} }
...@@ -164,12 +163,13 @@ static void rx(struct net_device *dev, int bufnum, ...@@ -164,12 +163,13 @@ static void rx(struct net_device *dev, int bufnum,
soft, sizeof(pkt->soft)); soft, sizeof(pkt->soft));
} }
if (!soft->split_flag) { /* not split */ if (!soft->split_flag) { /* not split */
BUGMSG(D_RX, "incoming is not split (splitflag=%d)\n", arc_printk(D_RX, dev, "incoming is not split (splitflag=%d)\n",
soft->split_flag); soft->split_flag);
if (in->skb) { /* already assembling one! */ if (in->skb) { /* already assembling one! */
BUGMSG(D_EXTRA, "aborting assembly (seq=%d) for unsplit packet (splitflag=%d, seq=%d)\n", arc_printk(D_EXTRA, dev, "aborting assembly (seq=%d) for unsplit packet (splitflag=%d, seq=%d)\n",
in->sequence, soft->split_flag, soft->sequence); in->sequence, soft->split_flag,
soft->sequence);
lp->rfc1201.aborted_seq = soft->sequence; lp->rfc1201.aborted_seq = soft->sequence;
dev_kfree_skb_irq(in->skb); dev_kfree_skb_irq(in->skb);
dev->stats.rx_errors++; dev->stats.rx_errors++;
...@@ -179,82 +179,86 @@ static void rx(struct net_device *dev, int bufnum, ...@@ -179,82 +179,86 @@ static void rx(struct net_device *dev, int bufnum,
in->sequence = soft->sequence; in->sequence = soft->sequence;
skb = alloc_skb(length + ARC_HDR_SIZE, GFP_ATOMIC); skb = alloc_skb(length + ARC_HDR_SIZE, GFP_ATOMIC);
if (skb == NULL) { if (!skb) {
BUGMSG(D_NORMAL, "Memory squeeze, dropping packet.\n");
dev->stats.rx_dropped++; dev->stats.rx_dropped++;
return; return;
} }
skb_put(skb, length + ARC_HDR_SIZE); skb_put(skb, length + ARC_HDR_SIZE);
skb->dev = dev; skb->dev = dev;
pkt = (struct archdr *) skb->data; pkt = (struct archdr *)skb->data;
soft = &pkt->soft.rfc1201; soft = &pkt->soft.rfc1201;
/* up to sizeof(pkt->soft) has already been copied from the card */ /* up to sizeof(pkt->soft) has already
* been copied from the card
*/
memcpy(pkt, pkthdr, sizeof(struct archdr)); memcpy(pkt, pkthdr, sizeof(struct archdr));
if (length > sizeof(pkt->soft)) if (length > sizeof(pkt->soft))
lp->hw.copy_from_card(dev, bufnum, ofs + sizeof(pkt->soft), lp->hw.copy_from_card(dev, bufnum,
pkt->soft.raw + sizeof(pkt->soft), ofs + sizeof(pkt->soft),
pkt->soft.raw + sizeof(pkt->soft),
length - sizeof(pkt->soft)); length - sizeof(pkt->soft));
/* /* ARP packets have problems when sent from some DOS systems:
* ARP packets have problems when sent from some DOS systems: the * the source address is always 0!
* source address is always 0! So we take the hardware source addr * So we take the hardware source addr (which is impossible
* (which is impossible to fumble) and insert it ourselves. * to fumble) and insert it ourselves.
*/ */
if (soft->proto == ARC_P_ARP) { if (soft->proto == ARC_P_ARP) {
struct arphdr *arp = (struct arphdr *) soft->payload; struct arphdr *arp = (struct arphdr *)soft->payload;
/* make sure addresses are the right length */ /* make sure addresses are the right length */
if (arp->ar_hln == 1 && arp->ar_pln == 4) { if (arp->ar_hln == 1 && arp->ar_pln == 4) {
uint8_t *cptr = (uint8_t *) arp + sizeof(struct arphdr); uint8_t *cptr = (uint8_t *)arp + sizeof(struct arphdr);
if (!*cptr) { /* is saddr = 00? */ if (!*cptr) { /* is saddr = 00? */
BUGMSG(D_EXTRA, arc_printk(D_EXTRA, dev,
"ARP source address was 00h, set to %02Xh.\n", "ARP source address was 00h, set to %02Xh\n",
saddr); saddr);
dev->stats.rx_crc_errors++; dev->stats.rx_crc_errors++;
*cptr = saddr; *cptr = saddr;
} else { } else {
BUGMSG(D_DURING, "ARP source address (%Xh) is fine.\n", arc_printk(D_DURING, dev, "ARP source address (%Xh) is fine.\n",
*cptr); *cptr);
} }
} else { } else {
BUGMSG(D_NORMAL, "funny-shaped ARP packet. (%Xh, %Xh)\n", arc_printk(D_NORMAL, dev, "funny-shaped ARP packet. (%Xh, %Xh)\n",
arp->ar_hln, arp->ar_pln); arp->ar_hln, arp->ar_pln);
dev->stats.rx_errors++; dev->stats.rx_errors++;
dev->stats.rx_crc_errors++; dev->stats.rx_crc_errors++;
} }
} }
BUGLVL(D_SKB) arcnet_dump_skb(dev, skb, "rx"); if (BUGLVL(D_SKB))
arcnet_dump_skb(dev, skb, "rx");
skb->protocol = type_trans(skb, dev); skb->protocol = type_trans(skb, dev);
netif_rx(skb); netif_rx(skb);
} else { /* split packet */ } else { /* split packet */
/* /* NOTE: MSDOS ARP packet correction should only need to
* NOTE: MSDOS ARP packet correction should only need to apply to * apply to unsplit packets, since ARP packets are so short.
* unsplit packets, since ARP packets are so short.
* *
* My interpretation of the RFC1201 document is that if a packet is * My interpretation of the RFC1201 document is that if a
* received out of order, the entire assembly process should be * packet is received out of order, the entire assembly
* aborted. * process should be aborted.
* *
* The RFC also mentions "it is possible for successfully received * The RFC also mentions "it is possible for successfully
* packets to be retransmitted." As of 0.40 all previously received * received packets to be retransmitted." As of 0.40 all
* packets are allowed, not just the most recent one. * previously received packets are allowed, not just the
* most recent one.
* *
* We allow multiple assembly processes, one for each ARCnet card * We allow multiple assembly processes, one for each
* possible on the network. Seems rather like a waste of memory, * ARCnet card possible on the network.
* but there's no other way to be reliable. * Seems rather like a waste of memory, but there's no
* other way to be reliable.
*/ */
BUGMSG(D_RX, "packet is split (splitflag=%d, seq=%d)\n", arc_printk(D_RX, dev, "packet is split (splitflag=%d, seq=%d)\n",
soft->split_flag, in->sequence); soft->split_flag, in->sequence);
if (in->skb && in->sequence != soft->sequence) { if (in->skb && in->sequence != soft->sequence) {
BUGMSG(D_EXTRA, "wrong seq number (saddr=%d, expected=%d, seq=%d, splitflag=%d)\n", arc_printk(D_EXTRA, dev, "wrong seq number (saddr=%d, expected=%d, seq=%d, splitflag=%d)\n",
saddr, in->sequence, soft->sequence, saddr, in->sequence, soft->sequence,
soft->split_flag); soft->split_flag);
dev_kfree_skb_irq(in->skb); dev_kfree_skb_irq(in->skb);
in->skb = NULL; in->skb = NULL;
dev->stats.rx_errors++; dev->stats.rx_errors++;
...@@ -262,24 +266,23 @@ static void rx(struct net_device *dev, int bufnum, ...@@ -262,24 +266,23 @@ static void rx(struct net_device *dev, int bufnum,
in->lastpacket = in->numpackets = 0; in->lastpacket = in->numpackets = 0;
} }
if (soft->split_flag & 1) { /* first packet in split */ if (soft->split_flag & 1) { /* first packet in split */
BUGMSG(D_RX, "brand new splitpacket (splitflag=%d)\n", arc_printk(D_RX, dev, "brand new splitpacket (splitflag=%d)\n",
soft->split_flag); soft->split_flag);
if (in->skb) { /* already assembling one! */ if (in->skb) { /* already assembling one! */
BUGMSG(D_EXTRA, "aborting previous (seq=%d) assembly " arc_printk(D_EXTRA, dev, "aborting previous (seq=%d) assembly (splitflag=%d, seq=%d)\n",
"(splitflag=%d, seq=%d)\n", in->sequence, soft->split_flag,
in->sequence, soft->split_flag, soft->sequence);
soft->sequence);
dev->stats.rx_errors++; dev->stats.rx_errors++;
dev->stats.rx_missed_errors++; dev->stats.rx_missed_errors++;
dev_kfree_skb_irq(in->skb); dev_kfree_skb_irq(in->skb);
} }
in->sequence = soft->sequence; in->sequence = soft->sequence;
in->numpackets = ((unsigned) soft->split_flag >> 1) + 2; in->numpackets = ((unsigned)soft->split_flag >> 1) + 2;
in->lastpacket = 1; in->lastpacket = 1;
if (in->numpackets > 16) { if (in->numpackets > 16) {
BUGMSG(D_EXTRA, "incoming packet more than 16 segments; dropping. (splitflag=%d)\n", arc_printk(D_EXTRA, dev, "incoming packet more than 16 segments; dropping. (splitflag=%d)\n",
soft->split_flag); soft->split_flag);
lp->rfc1201.aborted_seq = soft->sequence; lp->rfc1201.aborted_seq = soft->sequence;
dev->stats.rx_errors++; dev->stats.rx_errors++;
dev->stats.rx_length_errors++; dev->stats.rx_length_errors++;
...@@ -287,14 +290,14 @@ static void rx(struct net_device *dev, int bufnum, ...@@ -287,14 +290,14 @@ static void rx(struct net_device *dev, int bufnum,
} }
in->skb = skb = alloc_skb(508 * in->numpackets + ARC_HDR_SIZE, in->skb = skb = alloc_skb(508 * in->numpackets + ARC_HDR_SIZE,
GFP_ATOMIC); GFP_ATOMIC);
if (skb == NULL) { if (!skb) {
BUGMSG(D_NORMAL, "(split) memory squeeze, dropping packet.\n"); arc_printk(D_NORMAL, dev, "(split) memory squeeze, dropping packet.\n");
lp->rfc1201.aborted_seq = soft->sequence; lp->rfc1201.aborted_seq = soft->sequence;
dev->stats.rx_dropped++; dev->stats.rx_dropped++;
return; return;
} }
skb->dev = dev; skb->dev = dev;
pkt = (struct archdr *) skb->data; pkt = (struct archdr *)skb->data;
soft = &pkt->soft.rfc1201; soft = &pkt->soft.rfc1201;
memcpy(pkt, pkthdr, ARC_HDR_SIZE + RFC1201_HDR_SIZE); memcpy(pkt, pkthdr, ARC_HDR_SIZE + RFC1201_HDR_SIZE);
...@@ -302,37 +305,37 @@ static void rx(struct net_device *dev, int bufnum, ...@@ -302,37 +305,37 @@ static void rx(struct net_device *dev, int bufnum,
soft->split_flag = 0; /* end result won't be split */ soft->split_flag = 0; /* end result won't be split */
} else { /* not first packet */ } else { /* not first packet */
int packetnum = ((unsigned) soft->split_flag >> 1) + 1; int packetnum = ((unsigned)soft->split_flag >> 1) + 1;
/* /* if we're not assembling, there's no point trying to
* if we're not assembling, there's no point trying to
* continue. * continue.
*/ */
if (!in->skb) { if (!in->skb) {
if (lp->rfc1201.aborted_seq != soft->sequence) { if (lp->rfc1201.aborted_seq != soft->sequence) {
BUGMSG(D_EXTRA, "can't continue split without starting " arc_printk(D_EXTRA, dev, "can't continue split without starting first! (splitflag=%d, seq=%d, aborted=%d)\n",
"first! (splitflag=%d, seq=%d, aborted=%d)\n", soft->split_flag,
soft->split_flag, soft->sequence, soft->sequence,
lp->rfc1201.aborted_seq); lp->rfc1201.aborted_seq);
dev->stats.rx_errors++; dev->stats.rx_errors++;
dev->stats.rx_missed_errors++; dev->stats.rx_missed_errors++;
} }
return; return;
} }
in->lastpacket++; in->lastpacket++;
if (packetnum != in->lastpacket) { /* not the right flag! */ /* if not the right flag */
if (packetnum != in->lastpacket) {
/* harmless duplicate? ignore. */ /* harmless duplicate? ignore. */
if (packetnum <= in->lastpacket - 1) { if (packetnum <= in->lastpacket - 1) {
BUGMSG(D_EXTRA, "duplicate splitpacket ignored! (splitflag=%d)\n", arc_printk(D_EXTRA, dev, "duplicate splitpacket ignored! (splitflag=%d)\n",
soft->split_flag); soft->split_flag);
dev->stats.rx_errors++; dev->stats.rx_errors++;
dev->stats.rx_frame_errors++; dev->stats.rx_frame_errors++;
return; return;
} }
/* "bad" duplicate, kill reassembly */ /* "bad" duplicate, kill reassembly */
BUGMSG(D_EXTRA, "out-of-order splitpacket, reassembly " arc_printk(D_EXTRA, dev, "out-of-order splitpacket, reassembly (seq=%d) aborted (splitflag=%d, seq=%d)\n",
"(seq=%d) aborted (splitflag=%d, seq=%d)\n", in->sequence, soft->split_flag,
in->sequence, soft->split_flag, soft->sequence); soft->sequence);
lp->rfc1201.aborted_seq = soft->sequence; lp->rfc1201.aborted_seq = soft->sequence;
dev_kfree_skb_irq(in->skb); dev_kfree_skb_irq(in->skb);
in->skb = NULL; in->skb = NULL;
...@@ -341,7 +344,7 @@ static void rx(struct net_device *dev, int bufnum, ...@@ -341,7 +344,7 @@ static void rx(struct net_device *dev, int bufnum,
in->lastpacket = in->numpackets = 0; in->lastpacket = in->numpackets = 0;
return; return;
} }
pkt = (struct archdr *) in->skb->data; pkt = (struct archdr *)in->skb->data;
soft = &pkt->soft.rfc1201; soft = &pkt->soft.rfc1201;
} }
...@@ -357,11 +360,12 @@ static void rx(struct net_device *dev, int bufnum, ...@@ -357,11 +360,12 @@ static void rx(struct net_device *dev, int bufnum,
in->skb = NULL; in->skb = NULL;
in->lastpacket = in->numpackets = 0; in->lastpacket = in->numpackets = 0;
BUGMSG(D_SKB_SIZE, "skb: received %d bytes from %02X (unsplit)\n", arc_printk(D_SKB_SIZE, dev, "skb: received %d bytes from %02X (unsplit)\n",
skb->len, pkt->hard.source); skb->len, pkt->hard.source);
BUGMSG(D_SKB_SIZE, "skb: received %d bytes from %02X (split)\n", arc_printk(D_SKB_SIZE, dev, "skb: received %d bytes from %02X (split)\n",
skb->len, pkt->hard.source); skb->len, pkt->hard.source);
BUGLVL(D_SKB) arcnet_dump_skb(dev, skb, "rx"); if (BUGLVL(D_SKB))
arcnet_dump_skb(dev, skb, "rx");
skb->protocol = type_trans(skb, dev); skb->protocol = type_trans(skb, dev);
netif_rx(skb); netif_rx(skb);
...@@ -369,14 +373,13 @@ static void rx(struct net_device *dev, int bufnum, ...@@ -369,14 +373,13 @@ static void rx(struct net_device *dev, int bufnum,
} }
} }
/* Create the ARCnet hard/soft headers for RFC1201. */ /* Create the ARCnet hard/soft headers for RFC1201. */
static int build_header(struct sk_buff *skb, struct net_device *dev, static int build_header(struct sk_buff *skb, struct net_device *dev,
unsigned short type, uint8_t daddr) unsigned short type, uint8_t daddr)
{ {
struct arcnet_local *lp = netdev_priv(dev); struct arcnet_local *lp = netdev_priv(dev);
int hdr_size = ARC_HDR_SIZE + RFC1201_HDR_SIZE; int hdr_size = ARC_HDR_SIZE + RFC1201_HDR_SIZE;
struct archdr *pkt = (struct archdr *) skb_push(skb, hdr_size); struct archdr *pkt = (struct archdr *)skb_push(skb, hdr_size);
struct arc_rfc1201 *soft = &pkt->soft.rfc1201; struct arc_rfc1201 *soft = &pkt->soft.rfc1201;
/* set the protocol ID according to RFC1201 */ /* set the protocol ID according to RFC1201 */
...@@ -402,19 +405,18 @@ static int build_header(struct sk_buff *skb, struct net_device *dev, ...@@ -402,19 +405,18 @@ static int build_header(struct sk_buff *skb, struct net_device *dev,
soft->proto = ARC_P_ATALK; soft->proto = ARC_P_ATALK;
break; break;
default: default:
BUGMSG(D_NORMAL, "RFC1201: I don't understand protocol %d (%Xh)\n", arc_printk(D_NORMAL, dev, "RFC1201: I don't understand protocol %d (%Xh)\n",
type, type); type, type);
dev->stats.tx_errors++; dev->stats.tx_errors++;
dev->stats.tx_aborted_errors++; dev->stats.tx_aborted_errors++;
return 0; return 0;
} }
/* /* Set the source hardware address.
* Set the source hardware address.
* *
* This is pretty pointless for most purposes, but it can help in * This is pretty pointless for most purposes, but it can help in
* debugging. ARCnet does not allow us to change the source address in * debugging. ARCnet does not allow us to change the source address
* the actual packet sent) * in the actual packet sent.
*/ */
pkt->hard.source = *dev->dev_addr; pkt->hard.source = *dev->dev_addr;
...@@ -424,10 +426,10 @@ static int build_header(struct sk_buff *skb, struct net_device *dev, ...@@ -424,10 +426,10 @@ static int build_header(struct sk_buff *skb, struct net_device *dev,
/* see linux/net/ethernet/eth.c to see where I got the following */ /* see linux/net/ethernet/eth.c to see where I got the following */
if (dev->flags & (IFF_LOOPBACK | IFF_NOARP)) { if (dev->flags & (IFF_LOOPBACK | IFF_NOARP)) {
/* /* FIXME: fill in the last byte of the dest ipaddr here
* FIXME: fill in the last byte of the dest ipaddr here to better * to better comply with RFC1051 in "noarp" mode.
* comply with RFC1051 in "noarp" mode. For now, always broadcasting * For now, always broadcasting will probably at least get
* will probably at least get packets sent out :) * packets sent out :)
*/ */
pkt->hard.dest = 0; pkt->hard.dest = 0;
return hdr_size; return hdr_size;
...@@ -437,7 +439,6 @@ static int build_header(struct sk_buff *skb, struct net_device *dev, ...@@ -437,7 +439,6 @@ static int build_header(struct sk_buff *skb, struct net_device *dev,
return hdr_size; return hdr_size;
} }
static void load_pkt(struct net_device *dev, struct arc_hardware *hard, static void load_pkt(struct net_device *dev, struct arc_hardware *hard,
struct arc_rfc1201 *soft, int softlen, int bufnum) struct arc_rfc1201 *soft, int softlen, int bufnum)
{ {
...@@ -461,8 +462,9 @@ static void load_pkt(struct net_device *dev, struct arc_hardware *hard, ...@@ -461,8 +462,9 @@ static void load_pkt(struct net_device *dev, struct arc_hardware *hard,
hard->offset[1] = ofs - RFC1201_HDR_SIZE; hard->offset[1] = ofs - RFC1201_HDR_SIZE;
lp->hw.copy_to_card(dev, bufnum, ofs - RFC1201_HDR_SIZE, lp->hw.copy_to_card(dev, bufnum, ofs - RFC1201_HDR_SIZE,
&excsoft, RFC1201_HDR_SIZE); &excsoft, RFC1201_HDR_SIZE);
} else } else {
hard->offset[0] = ofs = 256 - softlen; hard->offset[0] = ofs = 256 - softlen;
}
lp->hw.copy_to_card(dev, bufnum, 0, hard, ARC_HDR_SIZE); lp->hw.copy_to_card(dev, bufnum, 0, hard, ARC_HDR_SIZE);
lp->hw.copy_to_card(dev, bufnum, ofs, soft, softlen); lp->hw.copy_to_card(dev, bufnum, ofs, soft, softlen);
...@@ -470,7 +472,6 @@ static void load_pkt(struct net_device *dev, struct arc_hardware *hard, ...@@ -470,7 +472,6 @@ static void load_pkt(struct net_device *dev, struct arc_hardware *hard,
lp->lastload_dest = hard->dest; lp->lastload_dest = hard->dest;
} }
static int prepare_tx(struct net_device *dev, struct archdr *pkt, int length, static int prepare_tx(struct net_device *dev, struct archdr *pkt, int length,
int bufnum) int bufnum)
{ {
...@@ -478,11 +479,11 @@ static int prepare_tx(struct net_device *dev, struct archdr *pkt, int length, ...@@ -478,11 +479,11 @@ static int prepare_tx(struct net_device *dev, struct archdr *pkt, int length,
const int maxsegsize = XMTU - RFC1201_HDR_SIZE; const int maxsegsize = XMTU - RFC1201_HDR_SIZE;
struct Outgoing *out; struct Outgoing *out;
arc_printk(D_DURING, dev, "prepare_tx: txbufs=%d/%d/%d\n",
lp->next_tx, lp->cur_tx, bufnum);
BUGMSG(D_DURING, "prepare_tx: txbufs=%d/%d/%d\n", /* hard header is not included in packet length */
lp->next_tx, lp->cur_tx, bufnum); length -= ARC_HDR_SIZE;
length -= ARC_HDR_SIZE; /* hard header is not included in packet length */
pkt->soft.rfc1201.split_flag = 0; pkt->soft.rfc1201.split_flag = 0;
/* need to do a split packet? */ /* need to do a split packet? */
...@@ -494,9 +495,9 @@ static int prepare_tx(struct net_device *dev, struct archdr *pkt, int length, ...@@ -494,9 +495,9 @@ static int prepare_tx(struct net_device *dev, struct archdr *pkt, int length,
out->numsegs = (out->dataleft + maxsegsize - 1) / maxsegsize; out->numsegs = (out->dataleft + maxsegsize - 1) / maxsegsize;
out->segnum = 0; out->segnum = 0;
BUGMSG(D_DURING, "rfc1201 prep_tx: ready for %d-segment split " arc_printk(D_DURING, dev, "rfc1201 prep_tx: ready for %d-segment split (%d bytes, seq=%d)\n",
"(%d bytes, seq=%d)\n", out->numsegs, out->length, out->numsegs, out->length,
pkt->soft.rfc1201.sequence); pkt->soft.rfc1201.sequence);
return 0; /* not done */ return 0; /* not done */
} }
...@@ -506,7 +507,6 @@ static int prepare_tx(struct net_device *dev, struct archdr *pkt, int length, ...@@ -506,7 +507,6 @@ static int prepare_tx(struct net_device *dev, struct archdr *pkt, int length,
return 1; /* done */ return 1; /* done */
} }
static int continue_tx(struct net_device *dev, int bufnum) static int continue_tx(struct net_device *dev, int bufnum)
{ {
struct arcnet_local *lp = netdev_priv(dev); struct arcnet_local *lp = netdev_priv(dev);
...@@ -516,9 +516,9 @@ static int continue_tx(struct net_device *dev, int bufnum) ...@@ -516,9 +516,9 @@ static int continue_tx(struct net_device *dev, int bufnum)
int maxsegsize = XMTU - RFC1201_HDR_SIZE; int maxsegsize = XMTU - RFC1201_HDR_SIZE;
int seglen; int seglen;
BUGMSG(D_DURING, arc_printk(D_DURING, dev,
"rfc1201 continue_tx: loading segment %d(+1) of %d (seq=%d)\n", "rfc1201 continue_tx: loading segment %d(+1) of %d (seq=%d)\n",
out->segnum, out->numsegs, soft->sequence); out->segnum, out->numsegs, soft->sequence);
/* the "new" soft header comes right before the data chunk */ /* the "new" soft header comes right before the data chunk */
newsoft = (struct arc_rfc1201 *) newsoft = (struct arc_rfc1201 *)
......
...@@ -19,7 +19,6 @@ ...@@ -19,7 +19,6 @@
#include <linux/types.h> #include <linux/types.h>
#include <linux/if_ether.h> #include <linux/if_ether.h>
/* /*
* These are the defined ARCnet Protocol ID's. * These are the defined ARCnet Protocol ID's.
*/ */
...@@ -57,42 +56,40 @@ ...@@ -57,42 +56,40 @@
* The RFC1201-specific components of an arcnet packet header. * The RFC1201-specific components of an arcnet packet header.
*/ */
struct arc_rfc1201 { struct arc_rfc1201 {
__u8 proto; /* protocol ID field - varies */ __u8 proto; /* protocol ID field - varies */
__u8 split_flag; /* for use with split packets */ __u8 split_flag; /* for use with split packets */
__be16 sequence; /* sequence number */ __be16 sequence; /* sequence number */
__u8 payload[0]; /* space remaining in packet (504 bytes)*/ __u8 payload[0]; /* space remaining in packet (504 bytes)*/
}; };
#define RFC1201_HDR_SIZE 4 #define RFC1201_HDR_SIZE 4
/* /*
* The RFC1051-specific components. * The RFC1051-specific components.
*/ */
struct arc_rfc1051 { struct arc_rfc1051 {
__u8 proto; /* ARC_P_RFC1051_ARP/RFC1051_IP */ __u8 proto; /* ARC_P_RFC1051_ARP/RFC1051_IP */
__u8 payload[0]; /* 507 bytes */ __u8 payload[0]; /* 507 bytes */
}; };
#define RFC1051_HDR_SIZE 1 #define RFC1051_HDR_SIZE 1
/* /*
* The ethernet-encap-specific components. We have a real ethernet header * The ethernet-encap-specific components. We have a real ethernet header
* and some data. * and some data.
*/ */
struct arc_eth_encap { struct arc_eth_encap {
__u8 proto; /* Always ARC_P_ETHER */ __u8 proto; /* Always ARC_P_ETHER */
struct ethhdr eth; /* standard ethernet header (yuck!) */ struct ethhdr eth; /* standard ethernet header (yuck!) */
__u8 payload[0]; /* 493 bytes */ __u8 payload[0]; /* 493 bytes */
}; };
#define ETH_ENCAP_HDR_SIZE 14 #define ETH_ENCAP_HDR_SIZE 14
struct arc_cap { struct arc_cap {
__u8 proto; __u8 proto;
__u8 cookie[sizeof(int)]; /* Actually NOT sent over the network */ __u8 cookie[sizeof(int)];
/* Actually NOT sent over the network */
union { union {
__u8 ack; __u8 ack;
__u8 raw[0]; /* 507 bytes */ __u8 raw[0]; /* 507 bytes */
} mes; } mes;
}; };
...@@ -105,9 +102,9 @@ struct arc_cap { ...@@ -105,9 +102,9 @@ struct arc_cap {
* driver. * driver.
*/ */
struct arc_hardware { struct arc_hardware {
__u8 source, /* source ARCnet - filled in automagically */ __u8 source; /* source ARCnet - filled in automagically */
dest, /* destination ARCnet - 0 for broadcast */ __u8 dest; /* destination ARCnet - 0 for broadcast */
offset[2]; /* offset bytes (some weird semantics) */ __u8 offset[2]; /* offset bytes (some weird semantics) */
}; };
#define ARC_HDR_SIZE 4 #define ARC_HDR_SIZE 4
...@@ -116,17 +113,17 @@ struct arc_hardware { ...@@ -116,17 +113,17 @@ struct arc_hardware {
* when you do a raw packet capture). * when you do a raw packet capture).
*/ */
struct archdr { struct archdr {
/* hardware requirements */ /* hardware requirements */
struct arc_hardware hard; struct arc_hardware hard;
/* arcnet encapsulation-specific bits */ /* arcnet encapsulation-specific bits */
union { union {
struct arc_rfc1201 rfc1201; struct arc_rfc1201 rfc1201;
struct arc_rfc1051 rfc1051; struct arc_rfc1051 rfc1051;
struct arc_eth_encap eth_encap; struct arc_eth_encap eth_encap;
struct arc_cap cap; struct arc_cap cap;
__u8 raw[0]; /* 508 bytes */ __u8 raw[0]; /* 508 bytes */
} soft; } soft;
}; };
#endif /* _LINUX_IF_ARCNET_H */ #endif /* _LINUX_IF_ARCNET_H */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment