Initial commit; kernel source import

This commit is contained in:
Nathan
2025-04-06 23:50:55 -05:00
commit 25c6d769f4
45093 changed files with 18199410 additions and 0 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,931 @@
/*======================================================================
A PCMCIA ethernet driver for the 3com 3c589 card.
Copyright (C) 1999 David A. Hinds -- dahinds@users.sourceforge.net
3c589_cs.c 1.162 2001/10/13 00:08:50
The network driver code is based on Donald Becker's 3c589 code:
Written 1994 by Donald Becker.
Copyright 1993 United States Government as represented by the
Director, National Security Agency. This software may be used and
distributed according to the terms of the GNU General Public License,
incorporated herein by reference.
Donald Becker may be reached at becker@scyld.com
Updated for 2.5.x by Alan Cox <alan@lxorguk.ukuu.org.uk>
======================================================================*/
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#define DRV_NAME "3c589_cs"
#define DRV_VERSION "1.162-ac"
#include <linux/module.h>
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/ptrace.h>
#include <linux/slab.h>
#include <linux/string.h>
#include <linux/timer.h>
#include <linux/interrupt.h>
#include <linux/in.h>
#include <linux/delay.h>
#include <linux/ethtool.h>
#include <linux/netdevice.h>
#include <linux/etherdevice.h>
#include <linux/skbuff.h>
#include <linux/if_arp.h>
#include <linux/ioport.h>
#include <linux/bitops.h>
#include <linux/jiffies.h>
#include <pcmcia/cistpl.h>
#include <pcmcia/cisreg.h>
#include <pcmcia/ciscode.h>
#include <pcmcia/ds.h>
#include <asm/uaccess.h>
#include <asm/io.h>
/* To minimize the size of the driver source I only define operating
constants if they are used several times. You'll need the manual
if you want to understand driver details. */
/* Offsets from base I/O address. */
#define EL3_DATA 0x00
#define EL3_TIMER 0x0a
#define EL3_CMD 0x0e
#define EL3_STATUS 0x0e
#define EEPROM_READ 0x0080
#define EEPROM_BUSY 0x8000
#define EL3WINDOW(win_num) outw(SelectWindow + (win_num), ioaddr + EL3_CMD)
/* The top five bits written to EL3_CMD are a command, the lower
11 bits are the parameter, if applicable. */
enum c509cmd {
TotalReset = 0<<11,
SelectWindow = 1<<11,
StartCoax = 2<<11,
RxDisable = 3<<11,
RxEnable = 4<<11,
RxReset = 5<<11,
RxDiscard = 8<<11,
TxEnable = 9<<11,
TxDisable = 10<<11,
TxReset = 11<<11,
FakeIntr = 12<<11,
AckIntr = 13<<11,
SetIntrEnb = 14<<11,
SetStatusEnb = 15<<11,
SetRxFilter = 16<<11,
SetRxThreshold = 17<<11,
SetTxThreshold = 18<<11,
SetTxStart = 19<<11,
StatsEnable = 21<<11,
StatsDisable = 22<<11,
StopCoax = 23<<11
};
enum c509status {
IntLatch = 0x0001,
AdapterFailure = 0x0002,
TxComplete = 0x0004,
TxAvailable = 0x0008,
RxComplete = 0x0010,
RxEarly = 0x0020,
IntReq = 0x0040,
StatsFull = 0x0080,
CmdBusy = 0x1000
};
/* The SetRxFilter command accepts the following classes: */
enum RxFilter {
RxStation = 1,
RxMulticast = 2,
RxBroadcast = 4,
RxProm = 8
};
/* Register window 1 offsets, the window used in normal operation. */
#define TX_FIFO 0x00
#define RX_FIFO 0x00
#define RX_STATUS 0x08
#define TX_STATUS 0x0B
#define TX_FREE 0x0C /* Remaining free bytes in Tx buffer. */
#define WN0_IRQ 0x08 /* Window 0: Set IRQ line in bits 12-15. */
#define WN4_MEDIA 0x0A /* Window 4: Various transcvr/media bits. */
#define MEDIA_TP 0x00C0 /* Enable link beat and jabber for 10baseT. */
#define MEDIA_LED 0x0001 /* Enable link light on 3C589E cards. */
/* Time in jiffies before concluding Tx hung */
#define TX_TIMEOUT ((400*HZ)/1000)
struct el3_private {
struct pcmcia_device *p_dev;
/* For transceiver monitoring */
struct timer_list media;
u16 media_status;
u16 fast_poll;
unsigned long last_irq;
spinlock_t lock;
};
static const char *if_names[] = { "auto", "10baseT", "10base2", "AUI" };
/*====================================================================*/
/* Module parameters */
MODULE_AUTHOR("David Hinds <dahinds@users.sourceforge.net>");
MODULE_DESCRIPTION("3Com 3c589 series PCMCIA ethernet driver");
MODULE_LICENSE("GPL");
#define INT_MODULE_PARM(n, v) static int n = v; module_param(n, int, 0)
/* Special hook for setting if_port when module is loaded */
INT_MODULE_PARM(if_port, 0);
/*====================================================================*/
static int tc589_config(struct pcmcia_device *link);
static void tc589_release(struct pcmcia_device *link);
static u16 read_eeprom(unsigned int ioaddr, int index);
static void tc589_reset(struct net_device *dev);
static void media_check(unsigned long arg);
static int el3_config(struct net_device *dev, struct ifmap *map);
static int el3_open(struct net_device *dev);
static netdev_tx_t el3_start_xmit(struct sk_buff *skb,
struct net_device *dev);
static irqreturn_t el3_interrupt(int irq, void *dev_id);
static void update_stats(struct net_device *dev);
static struct net_device_stats *el3_get_stats(struct net_device *dev);
static int el3_rx(struct net_device *dev);
static int el3_close(struct net_device *dev);
static void el3_tx_timeout(struct net_device *dev);
static void set_rx_mode(struct net_device *dev);
static void set_multicast_list(struct net_device *dev);
static const struct ethtool_ops netdev_ethtool_ops;
static void tc589_detach(struct pcmcia_device *p_dev);
static const struct net_device_ops el3_netdev_ops = {
.ndo_open = el3_open,
.ndo_stop = el3_close,
.ndo_start_xmit = el3_start_xmit,
.ndo_tx_timeout = el3_tx_timeout,
.ndo_set_config = el3_config,
.ndo_get_stats = el3_get_stats,
.ndo_set_rx_mode = set_multicast_list,
.ndo_change_mtu = eth_change_mtu,
.ndo_set_mac_address = eth_mac_addr,
.ndo_validate_addr = eth_validate_addr,
};
static int tc589_probe(struct pcmcia_device *link)
{
struct el3_private *lp;
struct net_device *dev;
dev_dbg(&link->dev, "3c589_attach()\n");
/* Create new ethernet device */
dev = alloc_etherdev(sizeof(struct el3_private));
if (!dev)
return -ENOMEM;
lp = netdev_priv(dev);
link->priv = dev;
lp->p_dev = link;
spin_lock_init(&lp->lock);
link->resource[0]->end = 16;
link->resource[0]->flags |= IO_DATA_PATH_WIDTH_16;
link->config_flags |= CONF_ENABLE_IRQ;
link->config_index = 1;
dev->netdev_ops = &el3_netdev_ops;
dev->watchdog_timeo = TX_TIMEOUT;
SET_ETHTOOL_OPS(dev, &netdev_ethtool_ops);
return tc589_config(link);
}
static void tc589_detach(struct pcmcia_device *link)
{
struct net_device *dev = link->priv;
dev_dbg(&link->dev, "3c589_detach\n");
unregister_netdev(dev);
tc589_release(link);
free_netdev(dev);
} /* tc589_detach */
static int tc589_config(struct pcmcia_device *link)
{
struct net_device *dev = link->priv;
__be16 *phys_addr;
int ret, i, j, multi = 0, fifo;
unsigned int ioaddr;
static const char * const ram_split[] = {"5:3", "3:1", "1:1", "3:5"};
u8 *buf;
size_t len;
dev_dbg(&link->dev, "3c589_config\n");
phys_addr = (__be16 *)dev->dev_addr;
/* Is this a 3c562? */
if (link->manf_id != MANFID_3COM)
dev_info(&link->dev, "hmmm, is this really a 3Com card??\n");
multi = (link->card_id == PRODID_3COM_3C562);
link->io_lines = 16;
/* For the 3c562, the base address must be xx00-xx7f */
for (i = j = 0; j < 0x400; j += 0x10) {
if (multi && (j & 0x80)) continue;
link->resource[0]->start = j ^ 0x300;
i = pcmcia_request_io(link);
if (i == 0)
break;
}
if (i != 0)
goto failed;
ret = pcmcia_request_irq(link, el3_interrupt);
if (ret)
goto failed;
ret = pcmcia_enable_device(link);
if (ret)
goto failed;
dev->irq = link->irq;
dev->base_addr = link->resource[0]->start;
ioaddr = dev->base_addr;
EL3WINDOW(0);
/* The 3c589 has an extra EEPROM for configuration info, including
the hardware address. The 3c562 puts the address in the CIS. */
len = pcmcia_get_tuple(link, 0x88, &buf);
if (buf && len >= 6) {
for (i = 0; i < 3; i++)
phys_addr[i] = htons(le16_to_cpu(buf[i*2]));
kfree(buf);
} else {
kfree(buf); /* 0 < len < 6 */
for (i = 0; i < 3; i++)
phys_addr[i] = htons(read_eeprom(ioaddr, i));
if (phys_addr[0] == htons(0x6060)) {
dev_err(&link->dev, "IO port conflict at 0x%03lx-0x%03lx\n",
dev->base_addr, dev->base_addr+15);
goto failed;
}
}
/* The address and resource configuration register aren't loaded from
the EEPROM and *must* be set to 0 and IRQ3 for the PCMCIA version. */
outw(0x3f00, ioaddr + 8);
fifo = inl(ioaddr);
/* The if_port symbol can be set when the module is loaded */
if ((if_port >= 0) && (if_port <= 3))
dev->if_port = if_port;
else
dev_err(&link->dev, "invalid if_port requested\n");
SET_NETDEV_DEV(dev, &link->dev);
if (register_netdev(dev) != 0) {
dev_err(&link->dev, "register_netdev() failed\n");
goto failed;
}
netdev_info(dev, "3Com 3c%s, io %#3lx, irq %d, hw_addr %pM\n",
(multi ? "562" : "589"), dev->base_addr, dev->irq,
dev->dev_addr);
netdev_info(dev, " %dK FIFO split %s Rx:Tx, %s xcvr\n",
(fifo & 7) ? 32 : 8, ram_split[(fifo >> 16) & 3],
if_names[dev->if_port]);
return 0;
failed:
tc589_release(link);
return -ENODEV;
} /* tc589_config */
static void tc589_release(struct pcmcia_device *link)
{
pcmcia_disable_device(link);
}
static int tc589_suspend(struct pcmcia_device *link)
{
struct net_device *dev = link->priv;
if (link->open)
netif_device_detach(dev);
return 0;
}
static int tc589_resume(struct pcmcia_device *link)
{
struct net_device *dev = link->priv;
if (link->open) {
tc589_reset(dev);
netif_device_attach(dev);
}
return 0;
}
/*====================================================================*/
/*
Use this for commands that may take time to finish
*/
static void tc589_wait_for_completion(struct net_device *dev, int cmd)
{
int i = 100;
outw(cmd, dev->base_addr + EL3_CMD);
while (--i > 0)
if (!(inw(dev->base_addr + EL3_STATUS) & 0x1000)) break;
if (i == 0)
netdev_warn(dev, "command 0x%04x did not complete!\n", cmd);
}
/*
Read a word from the EEPROM using the regular EEPROM access register.
Assume that we are in register window zero.
*/
static u16 read_eeprom(unsigned int ioaddr, int index)
{
int i;
outw(EEPROM_READ + index, ioaddr + 10);
/* Reading the eeprom takes 162 us */
for (i = 1620; i >= 0; i--)
if ((inw(ioaddr + 10) & EEPROM_BUSY) == 0)
break;
return inw(ioaddr + 12);
}
/*
Set transceiver type, perhaps to something other than what the user
specified in dev->if_port.
*/
static void tc589_set_xcvr(struct net_device *dev, int if_port)
{
struct el3_private *lp = netdev_priv(dev);
unsigned int ioaddr = dev->base_addr;
EL3WINDOW(0);
switch (if_port) {
case 0: case 1: outw(0, ioaddr + 6); break;
case 2: outw(3<<14, ioaddr + 6); break;
case 3: outw(1<<14, ioaddr + 6); break;
}
/* On PCMCIA, this just turns on the LED */
outw((if_port == 2) ? StartCoax : StopCoax, ioaddr + EL3_CMD);
/* 10baseT interface, enable link beat and jabber check. */
EL3WINDOW(4);
outw(MEDIA_LED | ((if_port < 2) ? MEDIA_TP : 0), ioaddr + WN4_MEDIA);
EL3WINDOW(1);
if (if_port == 2)
lp->media_status = ((dev->if_port == 0) ? 0x8000 : 0x4000);
else
lp->media_status = ((dev->if_port == 0) ? 0x4010 : 0x8800);
}
static void dump_status(struct net_device *dev)
{
unsigned int ioaddr = dev->base_addr;
EL3WINDOW(1);
netdev_info(dev, " irq status %04x, rx status %04x, tx status %02x tx free %04x\n",
inw(ioaddr+EL3_STATUS), inw(ioaddr+RX_STATUS),
inb(ioaddr+TX_STATUS), inw(ioaddr+TX_FREE));
EL3WINDOW(4);
netdev_info(dev, " diagnostics: fifo %04x net %04x ethernet %04x media %04x\n",
inw(ioaddr+0x04), inw(ioaddr+0x06), inw(ioaddr+0x08),
inw(ioaddr+0x0a));
EL3WINDOW(1);
}
/* Reset and restore all of the 3c589 registers. */
static void tc589_reset(struct net_device *dev)
{
unsigned int ioaddr = dev->base_addr;
int i;
EL3WINDOW(0);
outw(0x0001, ioaddr + 4); /* Activate board. */
outw(0x3f00, ioaddr + 8); /* Set the IRQ line. */
/* Set the station address in window 2. */
EL3WINDOW(2);
for (i = 0; i < 6; i++)
outb(dev->dev_addr[i], ioaddr + i);
tc589_set_xcvr(dev, dev->if_port);
/* Switch to the stats window, and clear all stats by reading. */
outw(StatsDisable, ioaddr + EL3_CMD);
EL3WINDOW(6);
for (i = 0; i < 9; i++)
inb(ioaddr+i);
inw(ioaddr + 10);
inw(ioaddr + 12);
/* Switch to register set 1 for normal use. */
EL3WINDOW(1);
set_rx_mode(dev);
outw(StatsEnable, ioaddr + EL3_CMD); /* Turn on statistics. */
outw(RxEnable, ioaddr + EL3_CMD); /* Enable the receiver. */
outw(TxEnable, ioaddr + EL3_CMD); /* Enable transmitter. */
/* Allow status bits to be seen. */
outw(SetStatusEnb | 0xff, ioaddr + EL3_CMD);
/* Ack all pending events, and set active indicator mask. */
outw(AckIntr | IntLatch | TxAvailable | RxEarly | IntReq,
ioaddr + EL3_CMD);
outw(SetIntrEnb | IntLatch | TxAvailable | RxComplete | StatsFull
| AdapterFailure, ioaddr + EL3_CMD);
}
static void netdev_get_drvinfo(struct net_device *dev,
struct ethtool_drvinfo *info)
{
strlcpy(info->driver, DRV_NAME, sizeof(info->driver));
strlcpy(info->version, DRV_VERSION, sizeof(info->version));
snprintf(info->bus_info, sizeof(info->bus_info),
"PCMCIA 0x%lx", dev->base_addr);
}
static const struct ethtool_ops netdev_ethtool_ops = {
.get_drvinfo = netdev_get_drvinfo,
};
static int el3_config(struct net_device *dev, struct ifmap *map)
{
if ((map->port != (u_char)(-1)) && (map->port != dev->if_port)) {
if (map->port <= 3) {
dev->if_port = map->port;
netdev_info(dev, "switched to %s port\n", if_names[dev->if_port]);
tc589_set_xcvr(dev, dev->if_port);
} else
return -EINVAL;
}
return 0;
}
static int el3_open(struct net_device *dev)
{
struct el3_private *lp = netdev_priv(dev);
struct pcmcia_device *link = lp->p_dev;
if (!pcmcia_dev_present(link))
return -ENODEV;
link->open++;
netif_start_queue(dev);
tc589_reset(dev);
init_timer(&lp->media);
lp->media.function = media_check;
lp->media.data = (unsigned long) dev;
lp->media.expires = jiffies + HZ;
add_timer(&lp->media);
dev_dbg(&link->dev, "%s: opened, status %4.4x.\n",
dev->name, inw(dev->base_addr + EL3_STATUS));
return 0;
}
static void el3_tx_timeout(struct net_device *dev)
{
unsigned int ioaddr = dev->base_addr;
netdev_warn(dev, "Transmit timed out!\n");
dump_status(dev);
dev->stats.tx_errors++;
dev->trans_start = jiffies; /* prevent tx timeout */
/* Issue TX_RESET and TX_START commands. */
tc589_wait_for_completion(dev, TxReset);
outw(TxEnable, ioaddr + EL3_CMD);
netif_wake_queue(dev);
}
static void pop_tx_status(struct net_device *dev)
{
unsigned int ioaddr = dev->base_addr;
int i;
/* Clear the Tx status stack. */
for (i = 32; i > 0; i--) {
u_char tx_status = inb(ioaddr + TX_STATUS);
if (!(tx_status & 0x84)) break;
/* reset transmitter on jabber error or underrun */
if (tx_status & 0x30)
tc589_wait_for_completion(dev, TxReset);
if (tx_status & 0x38) {
netdev_dbg(dev, "transmit error: status 0x%02x\n", tx_status);
outw(TxEnable, ioaddr + EL3_CMD);
dev->stats.tx_aborted_errors++;
}
outb(0x00, ioaddr + TX_STATUS); /* Pop the status stack. */
}
}
static netdev_tx_t el3_start_xmit(struct sk_buff *skb,
struct net_device *dev)
{
unsigned int ioaddr = dev->base_addr;
struct el3_private *priv = netdev_priv(dev);
unsigned long flags;
netdev_dbg(dev, "el3_start_xmit(length = %ld) called, status %4.4x.\n",
(long)skb->len, inw(ioaddr + EL3_STATUS));
spin_lock_irqsave(&priv->lock, flags);
dev->stats.tx_bytes += skb->len;
/* Put out the doubleword header... */
outw(skb->len, ioaddr + TX_FIFO);
outw(0x00, ioaddr + TX_FIFO);
/* ... and the packet rounded to a doubleword. */
outsl(ioaddr + TX_FIFO, skb->data, (skb->len + 3) >> 2);
if (inw(ioaddr + TX_FREE) <= 1536) {
netif_stop_queue(dev);
/* Interrupt us when the FIFO has room for max-sized packet. */
outw(SetTxThreshold + 1536, ioaddr + EL3_CMD);
}
pop_tx_status(dev);
spin_unlock_irqrestore(&priv->lock, flags);
dev_kfree_skb(skb);
return NETDEV_TX_OK;
}
/* The EL3 interrupt handler. */
static irqreturn_t el3_interrupt(int irq, void *dev_id)
{
struct net_device *dev = (struct net_device *) dev_id;
struct el3_private *lp = netdev_priv(dev);
unsigned int ioaddr;
__u16 status;
int i = 0, handled = 1;
if (!netif_device_present(dev))
return IRQ_NONE;
ioaddr = dev->base_addr;
netdev_dbg(dev, "interrupt, status %4.4x.\n", inw(ioaddr + EL3_STATUS));
spin_lock(&lp->lock);
while ((status = inw(ioaddr + EL3_STATUS)) &
(IntLatch | RxComplete | StatsFull)) {
if ((status & 0xe000) != 0x2000) {
netdev_dbg(dev, "interrupt from dead card\n");
handled = 0;
break;
}
if (status & RxComplete)
el3_rx(dev);
if (status & TxAvailable) {
netdev_dbg(dev, " TX room bit was handled.\n");
/* There's room in the FIFO for a full-sized packet. */
outw(AckIntr | TxAvailable, ioaddr + EL3_CMD);
netif_wake_queue(dev);
}
if (status & TxComplete)
pop_tx_status(dev);
if (status & (AdapterFailure | RxEarly | StatsFull)) {
/* Handle all uncommon interrupts. */
if (status & StatsFull) /* Empty statistics. */
update_stats(dev);
if (status & RxEarly) { /* Rx early is unused. */
el3_rx(dev);
outw(AckIntr | RxEarly, ioaddr + EL3_CMD);
}
if (status & AdapterFailure) {
u16 fifo_diag;
EL3WINDOW(4);
fifo_diag = inw(ioaddr + 4);
EL3WINDOW(1);
netdev_warn(dev, "adapter failure, FIFO diagnostic register %04x.\n",
fifo_diag);
if (fifo_diag & 0x0400) {
/* Tx overrun */
tc589_wait_for_completion(dev, TxReset);
outw(TxEnable, ioaddr + EL3_CMD);
}
if (fifo_diag & 0x2000) {
/* Rx underrun */
tc589_wait_for_completion(dev, RxReset);
set_rx_mode(dev);
outw(RxEnable, ioaddr + EL3_CMD);
}
outw(AckIntr | AdapterFailure, ioaddr + EL3_CMD);
}
}
if (++i > 10) {
netdev_err(dev, "infinite loop in interrupt, status %4.4x.\n",
status);
/* Clear all interrupts */
outw(AckIntr | 0xFF, ioaddr + EL3_CMD);
break;
}
/* Acknowledge the IRQ. */
outw(AckIntr | IntReq | IntLatch, ioaddr + EL3_CMD);
}
lp->last_irq = jiffies;
spin_unlock(&lp->lock);
netdev_dbg(dev, "exiting interrupt, status %4.4x.\n",
inw(ioaddr + EL3_STATUS));
return IRQ_RETVAL(handled);
}
static void media_check(unsigned long arg)
{
struct net_device *dev = (struct net_device *)(arg);
struct el3_private *lp = netdev_priv(dev);
unsigned int ioaddr = dev->base_addr;
u16 media, errs;
unsigned long flags;
if (!netif_device_present(dev)) goto reschedule;
/* Check for pending interrupt with expired latency timer: with
this, we can limp along even if the interrupt is blocked */
if ((inw(ioaddr + EL3_STATUS) & IntLatch) &&
(inb(ioaddr + EL3_TIMER) == 0xff)) {
if (!lp->fast_poll)
netdev_warn(dev, "interrupt(s) dropped!\n");
local_irq_save(flags);
el3_interrupt(dev->irq, dev);
local_irq_restore(flags);
lp->fast_poll = HZ;
}
if (lp->fast_poll) {
lp->fast_poll--;
lp->media.expires = jiffies + HZ/100;
add_timer(&lp->media);
return;
}
/* lp->lock guards the EL3 window. Window should always be 1 except
when the lock is held */
spin_lock_irqsave(&lp->lock, flags);
EL3WINDOW(4);
media = inw(ioaddr+WN4_MEDIA) & 0xc810;
/* Ignore collisions unless we've had no irq's recently */
if (time_before(jiffies, lp->last_irq + HZ)) {
media &= ~0x0010;
} else {
/* Try harder to detect carrier errors */
EL3WINDOW(6);
outw(StatsDisable, ioaddr + EL3_CMD);
errs = inb(ioaddr + 0);
outw(StatsEnable, ioaddr + EL3_CMD);
dev->stats.tx_carrier_errors += errs;
if (errs || (lp->media_status & 0x0010)) media |= 0x0010;
}
if (media != lp->media_status) {
if ((media & lp->media_status & 0x8000) &&
((lp->media_status ^ media) & 0x0800))
netdev_info(dev, "%s link beat\n",
(lp->media_status & 0x0800 ? "lost" : "found"));
else if ((media & lp->media_status & 0x4000) &&
((lp->media_status ^ media) & 0x0010))
netdev_info(dev, "coax cable %s\n",
(lp->media_status & 0x0010 ? "ok" : "problem"));
if (dev->if_port == 0) {
if (media & 0x8000) {
if (media & 0x0800)
netdev_info(dev, "flipped to 10baseT\n");
else
tc589_set_xcvr(dev, 2);
} else if (media & 0x4000) {
if (media & 0x0010)
tc589_set_xcvr(dev, 1);
else
netdev_info(dev, "flipped to 10base2\n");
}
}
lp->media_status = media;
}
EL3WINDOW(1);
spin_unlock_irqrestore(&lp->lock, flags);
reschedule:
lp->media.expires = jiffies + HZ;
add_timer(&lp->media);
}
static struct net_device_stats *el3_get_stats(struct net_device *dev)
{
struct el3_private *lp = netdev_priv(dev);
unsigned long flags;
struct pcmcia_device *link = lp->p_dev;
if (pcmcia_dev_present(link)) {
spin_lock_irqsave(&lp->lock, flags);
update_stats(dev);
spin_unlock_irqrestore(&lp->lock, flags);
}
return &dev->stats;
}
/*
Update statistics. We change to register window 6, so this should be run
single-threaded if the device is active. This is expected to be a rare
operation, and it's simpler for the rest of the driver to assume that
window 1 is always valid rather than use a special window-state variable.
Caller must hold the lock for this
*/
static void update_stats(struct net_device *dev)
{
unsigned int ioaddr = dev->base_addr;
netdev_dbg(dev, "updating the statistics.\n");
/* Turn off statistics updates while reading. */
outw(StatsDisable, ioaddr + EL3_CMD);
/* Switch to the stats window, and read everything. */
EL3WINDOW(6);
dev->stats.tx_carrier_errors += inb(ioaddr + 0);
dev->stats.tx_heartbeat_errors += inb(ioaddr + 1);
/* Multiple collisions. */ inb(ioaddr + 2);
dev->stats.collisions += inb(ioaddr + 3);
dev->stats.tx_window_errors += inb(ioaddr + 4);
dev->stats.rx_fifo_errors += inb(ioaddr + 5);
dev->stats.tx_packets += inb(ioaddr + 6);
/* Rx packets */ inb(ioaddr + 7);
/* Tx deferrals */ inb(ioaddr + 8);
/* Rx octets */ inw(ioaddr + 10);
/* Tx octets */ inw(ioaddr + 12);
/* Back to window 1, and turn statistics back on. */
EL3WINDOW(1);
outw(StatsEnable, ioaddr + EL3_CMD);
}
static int el3_rx(struct net_device *dev)
{
unsigned int ioaddr = dev->base_addr;
int worklimit = 32;
short rx_status;
netdev_dbg(dev, "in rx_packet(), status %4.4x, rx_status %4.4x.\n",
inw(ioaddr+EL3_STATUS), inw(ioaddr+RX_STATUS));
while (!((rx_status = inw(ioaddr + RX_STATUS)) & 0x8000) &&
worklimit > 0) {
worklimit--;
if (rx_status & 0x4000) { /* Error, update stats. */
short error = rx_status & 0x3800;
dev->stats.rx_errors++;
switch (error) {
case 0x0000: dev->stats.rx_over_errors++; break;
case 0x0800: dev->stats.rx_length_errors++; break;
case 0x1000: dev->stats.rx_frame_errors++; break;
case 0x1800: dev->stats.rx_length_errors++; break;
case 0x2000: dev->stats.rx_frame_errors++; break;
case 0x2800: dev->stats.rx_crc_errors++; break;
}
} else {
short pkt_len = rx_status & 0x7ff;
struct sk_buff *skb;
skb = netdev_alloc_skb(dev, pkt_len + 5);
netdev_dbg(dev, " Receiving packet size %d status %4.4x.\n",
pkt_len, rx_status);
if (skb != NULL) {
skb_reserve(skb, 2);
insl(ioaddr+RX_FIFO, skb_put(skb, pkt_len),
(pkt_len+3)>>2);
skb->protocol = eth_type_trans(skb, dev);
netif_rx(skb);
dev->stats.rx_packets++;
dev->stats.rx_bytes += pkt_len;
} else {
netdev_dbg(dev, "couldn't allocate a sk_buff of size %d.\n",
pkt_len);
dev->stats.rx_dropped++;
}
}
/* Pop the top of the Rx FIFO */
tc589_wait_for_completion(dev, RxDiscard);
}
if (worklimit == 0)
netdev_warn(dev, "too much work in el3_rx!\n");
return 0;
}
static void set_rx_mode(struct net_device *dev)
{
unsigned int ioaddr = dev->base_addr;
u16 opts = SetRxFilter | RxStation | RxBroadcast;
if (dev->flags & IFF_PROMISC)
opts |= RxMulticast | RxProm;
else if (!netdev_mc_empty(dev) || (dev->flags & IFF_ALLMULTI))
opts |= RxMulticast;
outw(opts, ioaddr + EL3_CMD);
}
static void set_multicast_list(struct net_device *dev)
{
struct el3_private *priv = netdev_priv(dev);
unsigned long flags;
spin_lock_irqsave(&priv->lock, flags);
set_rx_mode(dev);
spin_unlock_irqrestore(&priv->lock, flags);
}
static int el3_close(struct net_device *dev)
{
struct el3_private *lp = netdev_priv(dev);
struct pcmcia_device *link = lp->p_dev;
unsigned int ioaddr = dev->base_addr;
dev_dbg(&link->dev, "%s: shutting down ethercard.\n", dev->name);
if (pcmcia_dev_present(link)) {
/* Turn off statistics ASAP. We update dev->stats below. */
outw(StatsDisable, ioaddr + EL3_CMD);
/* Disable the receiver and transmitter. */
outw(RxDisable, ioaddr + EL3_CMD);
outw(TxDisable, ioaddr + EL3_CMD);
if (dev->if_port == 2)
/* Turn off thinnet power. Green! */
outw(StopCoax, ioaddr + EL3_CMD);
else if (dev->if_port == 1) {
/* Disable link beat and jabber */
EL3WINDOW(4);
outw(0, ioaddr + WN4_MEDIA);
}
/* Switching back to window 0 disables the IRQ. */
EL3WINDOW(0);
/* But we explicitly zero the IRQ line select anyway. */
outw(0x0f00, ioaddr + WN0_IRQ);
/* Check if the card still exists */
if ((inw(ioaddr+EL3_STATUS) & 0xe000) == 0x2000)
update_stats(dev);
}
link->open--;
netif_stop_queue(dev);
del_timer_sync(&lp->media);
return 0;
}
static const struct pcmcia_device_id tc589_ids[] = {
PCMCIA_MFC_DEVICE_MANF_CARD(0, 0x0101, 0x0562),
PCMCIA_MFC_DEVICE_PROD_ID1(0, "Motorola MARQUIS", 0xf03e4e77),
PCMCIA_DEVICE_MANF_CARD(0x0101, 0x0589),
PCMCIA_DEVICE_PROD_ID12("Farallon", "ENet", 0x58d93fc4, 0x992c2202),
PCMCIA_MFC_DEVICE_CIS_MANF_CARD(0, 0x0101, 0x0035, "cis/3CXEM556.cis"),
PCMCIA_MFC_DEVICE_CIS_MANF_CARD(0, 0x0101, 0x003d, "cis/3CXEM556.cis"),
PCMCIA_DEVICE_NULL,
};
MODULE_DEVICE_TABLE(pcmcia, tc589_ids);
static struct pcmcia_driver tc589_driver = {
.owner = THIS_MODULE,
.name = "3c589_cs",
.probe = tc589_probe,
.remove = tc589_detach,
.id_table = tc589_ids,
.suspend = tc589_suspend,
.resume = tc589_resume,
};
module_pcmcia_driver(tc589_driver);

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,108 @@
#
# 3Com Ethernet device configuration
#
config NET_VENDOR_3COM
bool "3Com devices"
default y
depends on ISA || EISA || PCI || PCMCIA
---help---
If you have a network (Ethernet) card belonging to this class, say Y
and read the Ethernet-HOWTO, available from
<http://www.tldp.org/docs.html#howto>.
Note that the answer to this question doesn't directly affect the
kernel: saying N will just cause the configurator to skip all
the questions about 3Com cards. If you say Y, you will be asked for
your specific card in the following questions.
if NET_VENDOR_3COM
config EL3
tristate "3c509/3c579 \"EtherLink III\" support"
depends on (ISA || EISA)
---help---
If you have a network (Ethernet) card belonging to the 3Com
EtherLinkIII series, say Y and read the Ethernet-HOWTO, available
from <http://www.tldp.org/docs.html#howto>.
If your card is not working you may need to use the DOS
setup disk to disable Plug & Play mode, and to select the default
media type.
To compile this driver as a module, choose M here. The module
will be called 3c509.
config 3C515
tristate "3c515 ISA \"Fast EtherLink\""
depends on (ISA || EISA) && ISA_DMA_API
---help---
If you have a 3Com ISA EtherLink XL "Corkscrew" 3c515 Fast Ethernet
network card, say Y and read the Ethernet-HOWTO, available from
<http://www.tldp.org/docs.html#howto>.
To compile this driver as a module, choose M here. The module
will be called 3c515.
config PCMCIA_3C574
tristate "3Com 3c574 PCMCIA support"
depends on PCMCIA
---help---
Say Y here if you intend to attach a 3Com 3c574 or compatible PCMCIA
(PC-card) Fast Ethernet card to your computer.
To compile this driver as a module, choose M here: the module will be
called 3c574_cs. If unsure, say N.
config PCMCIA_3C589
tristate "3Com 3c589 PCMCIA support"
depends on PCMCIA
---help---
Say Y here if you intend to attach a 3Com 3c589 or compatible PCMCIA
(PC-card) Ethernet card to your computer.
To compile this driver as a module, choose M here: the module will be
called 3c589_cs. If unsure, say N.
config VORTEX
tristate "3c590/3c900 series (592/595/597) \"Vortex/Boomerang\" support"
depends on (PCI || EISA) && HAS_IOPORT
select NET_CORE
select MII
---help---
This option enables driver support for a large number of 10Mbps and
10/100Mbps EISA, PCI and PCMCIA 3Com network cards:
"Vortex" (Fast EtherLink 3c590/3c592/3c595/3c597) EISA and PCI
"Boomerang" (EtherLink XL 3c900 or 3c905) PCI
"Cyclone" (3c540/3c900/3c905/3c980/3c575/3c656) PCI and Cardbus
"Tornado" (3c905) PCI
"Hurricane" (3c555/3cSOHO) PCI
If you have such a card, say Y and read the Ethernet-HOWTO,
available from <http://www.tldp.org/docs.html#howto>. More
specific information is in
<file:Documentation/networking/vortex.txt> and in the comments at
the beginning of <file:drivers/net/ethernet/3com/3c59x.c>.
To compile this support as a module, choose M here.
config TYPHOON
tristate "3cr990 series \"Typhoon\" support"
depends on PCI
select CRC32
---help---
This option enables driver support for the 3cr990 series of cards:
3C990-TX, 3CR990-TX-95, 3CR990-TX-97, 3CR990-FX-95, 3CR990-FX-97,
3CR990SVR, 3CR990SVR95, 3CR990SVR97, 3CR990-FX-95 Server,
3CR990-FX-97 Server, 3C990B-TX-M, 3C990BSVR
If you have a network (Ethernet) card of this type, say Y and read
the Ethernet-HOWTO, available from
<http://www.tldp.org/docs.html#howto>.
To compile this driver as a module, choose M here. The module
will be called typhoon.
endif # NET_VENDOR_3COM

View File

@@ -0,0 +1,10 @@
#
# Makefile for the 3Com Ethernet device drivers
#
obj-$(CONFIG_EL3) += 3c509.o
obj-$(CONFIG_3C515) += 3c515.o
obj-$(CONFIG_PCMCIA_3C589) += 3c589_cs.o
obj-$(CONFIG_PCMCIA_3C574) += 3c574_cs.o
obj-$(CONFIG_VORTEX) += 3c59x.o
obj-$(CONFIG_TYPHOON) += typhoon.o

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,624 @@
/* typhoon.h: chip info for the 3Com 3CR990 family of controllers */
/*
Written 2002-2003 by David Dillow <dave@thedillows.org>
This software may be used and distributed according to the terms of
the GNU General Public License (GPL), incorporated herein by reference.
Drivers based on or derived from this code fall under the GPL and must
retain the authorship, copyright and license notice. This file is not
a complete program and may only be used when the entire operating
system is licensed under the GPL.
This software is available on a public web site. It may enable
cryptographic capabilities of the 3Com hardware, and may be
exported from the United States under License Exception "TSU"
pursuant to 15 C.F.R. Section 740.13(e).
This work was funded by the National Library of Medicine under
the Department of Energy project number 0274DD06D1 and NLM project
number Y1-LM-2015-01.
*/
/* All Typhoon ring positions are specificed in bytes, and point to the
* first "clean" entry in the ring -- ie the next entry we use for whatever
* purpose.
*/
/* The Typhoon basic ring
* ringBase: where this ring lives (our virtual address)
* lastWrite: the next entry we'll use
*/
struct basic_ring {
u8 *ringBase;
u32 lastWrite;
};
/* The Typoon transmit ring -- same as a basic ring, plus:
* lastRead: where we're at in regard to cleaning up the ring
* writeRegister: register to use for writing (different for Hi & Lo rings)
*/
struct transmit_ring {
u8 *ringBase;
u32 lastWrite;
u32 lastRead;
int writeRegister;
};
/* The host<->Typhoon ring index structure
* This indicates the current positions in the rings
*
* All values must be in little endian format for the 3XP
*
* rxHiCleared: entry we've cleared to in the Hi receive ring
* rxLoCleared: entry we've cleared to in the Lo receive ring
* rxBuffReady: next entry we'll put a free buffer in
* respCleared: entry we've cleared to in the response ring
*
* txLoCleared: entry the NIC has cleared to in the Lo transmit ring
* txHiCleared: entry the NIC has cleared to in the Hi transmit ring
* rxLoReady: entry the NIC has filled to in the Lo receive ring
* rxBuffCleared: entry the NIC has cleared in the free buffer ring
* cmdCleared: entry the NIC has cleared in the command ring
* respReady: entry the NIC has filled to in the response ring
* rxHiReady: entry the NIC has filled to in the Hi receive ring
*/
struct typhoon_indexes {
/* The first four are written by the host, and read by the NIC */
volatile __le32 rxHiCleared;
volatile __le32 rxLoCleared;
volatile __le32 rxBuffReady;
volatile __le32 respCleared;
/* The remaining are written by the NIC, and read by the host */
volatile __le32 txLoCleared;
volatile __le32 txHiCleared;
volatile __le32 rxLoReady;
volatile __le32 rxBuffCleared;
volatile __le32 cmdCleared;
volatile __le32 respReady;
volatile __le32 rxHiReady;
} __packed;
/* The host<->Typhoon interface
* Our means of communicating where things are
*
* All values must be in little endian format for the 3XP
*
* ringIndex: 64 bit bus address of the index structure
* txLoAddr: 64 bit bus address of the Lo transmit ring
* txLoSize: size (in bytes) of the Lo transmit ring
* txHi*: as above for the Hi priority transmit ring
* rxLo*: as above for the Lo priority receive ring
* rxBuff*: as above for the free buffer ring
* cmd*: as above for the command ring
* resp*: as above for the response ring
* zeroAddr: 64 bit bus address of a zero word (for DMA)
* rxHi*: as above for the Hi Priority receive ring
*
* While there is room for 64 bit addresses, current versions of the 3XP
* only do 32 bit addresses, so the *Hi for each of the above will always
* be zero.
*/
struct typhoon_interface {
__le32 ringIndex;
__le32 ringIndexHi;
__le32 txLoAddr;
__le32 txLoAddrHi;
__le32 txLoSize;
__le32 txHiAddr;
__le32 txHiAddrHi;
__le32 txHiSize;
__le32 rxLoAddr;
__le32 rxLoAddrHi;
__le32 rxLoSize;
__le32 rxBuffAddr;
__le32 rxBuffAddrHi;
__le32 rxBuffSize;
__le32 cmdAddr;
__le32 cmdAddrHi;
__le32 cmdSize;
__le32 respAddr;
__le32 respAddrHi;
__le32 respSize;
__le32 zeroAddr;
__le32 zeroAddrHi;
__le32 rxHiAddr;
__le32 rxHiAddrHi;
__le32 rxHiSize;
} __packed;
/* The Typhoon transmit/fragment descriptor
*
* A packet is described by a packet descriptor, followed by option descriptors,
* if any, then one or more fragment descriptors.
*
* Packet descriptor:
* flags: Descriptor type
* len:i zero, or length of this packet
* addr*: 8 bytes of opaque data to the firmware -- for skb pointer
* processFlags: Determine offload tasks to perform on this packet.
*
* Fragment descriptor:
* flags: Descriptor type
* len:i length of this fragment
* addr: low bytes of DMA address for this part of the packet
* addrHi: hi bytes of DMA address for this part of the packet
* processFlags: must be zero
*
* TYPHOON_DESC_VALID is not mentioned in their docs, but their Linux
* driver uses it.
*/
struct tx_desc {
u8 flags;
#define TYPHOON_TYPE_MASK 0x07
#define TYPHOON_FRAG_DESC 0x00
#define TYPHOON_TX_DESC 0x01
#define TYPHOON_CMD_DESC 0x02
#define TYPHOON_OPT_DESC 0x03
#define TYPHOON_RX_DESC 0x04
#define TYPHOON_RESP_DESC 0x05
#define TYPHOON_OPT_TYPE_MASK 0xf0
#define TYPHOON_OPT_IPSEC 0x00
#define TYPHOON_OPT_TCP_SEG 0x10
#define TYPHOON_CMD_RESPOND 0x40
#define TYPHOON_RESP_ERROR 0x40
#define TYPHOON_RX_ERROR 0x40
#define TYPHOON_DESC_VALID 0x80
u8 numDesc;
__le16 len;
union {
struct {
__le32 addr;
__le32 addrHi;
} frag;
u64 tx_addr; /* opaque for hardware, for TX_DESC */
};
__le32 processFlags;
#define TYPHOON_TX_PF_NO_CRC cpu_to_le32(0x00000001)
#define TYPHOON_TX_PF_IP_CHKSUM cpu_to_le32(0x00000002)
#define TYPHOON_TX_PF_TCP_CHKSUM cpu_to_le32(0x00000004)
#define TYPHOON_TX_PF_TCP_SEGMENT cpu_to_le32(0x00000008)
#define TYPHOON_TX_PF_INSERT_VLAN cpu_to_le32(0x00000010)
#define TYPHOON_TX_PF_IPSEC cpu_to_le32(0x00000020)
#define TYPHOON_TX_PF_VLAN_PRIORITY cpu_to_le32(0x00000040)
#define TYPHOON_TX_PF_UDP_CHKSUM cpu_to_le32(0x00000080)
#define TYPHOON_TX_PF_PAD_FRAME cpu_to_le32(0x00000100)
#define TYPHOON_TX_PF_RESERVED cpu_to_le32(0x00000e00)
#define TYPHOON_TX_PF_VLAN_MASK cpu_to_le32(0x0ffff000)
#define TYPHOON_TX_PF_INTERNAL cpu_to_le32(0xf0000000)
#define TYPHOON_TX_PF_VLAN_TAG_SHIFT 12
} __packed;
/* The TCP Segmentation offload option descriptor
*
* flags: descriptor type
* numDesc: must be 1
* mss_flags: bits 0-11 (little endian) are MSS, 12 is first TSO descriptor
* 13 is list TSO descriptor, set both if only one TSO
* respAddrLo: low bytes of address of the bytesTx field of this descriptor
* bytesTx: total number of bytes in this TSO request
* status: 0 on completion
*/
struct tcpopt_desc {
u8 flags;
u8 numDesc;
__le16 mss_flags;
#define TYPHOON_TSO_FIRST cpu_to_le16(0x1000)
#define TYPHOON_TSO_LAST cpu_to_le16(0x2000)
__le32 respAddrLo;
__le32 bytesTx;
__le32 status;
} __packed;
/* The IPSEC Offload descriptor
*
* flags: descriptor type
* numDesc: must be 1
* ipsecFlags: bit 0: 0 -- generate IV, 1 -- use supplied IV
* sa1, sa2: Security Association IDs for this packet
* reserved: set to 0
*/
struct ipsec_desc {
u8 flags;
u8 numDesc;
__le16 ipsecFlags;
#define TYPHOON_IPSEC_GEN_IV cpu_to_le16(0x0000)
#define TYPHOON_IPSEC_USE_IV cpu_to_le16(0x0001)
__le32 sa1;
__le32 sa2;
__le32 reserved;
} __packed;
/* The Typhoon receive descriptor (Updated by NIC)
*
* flags: Descriptor type, error indication
* numDesc: Always zero
* frameLen: the size of the packet received
* addr: low 32 bytes of the virtual addr passed in for this buffer
* addrHi: high 32 bytes of the virtual addr passed in for this buffer
* rxStatus: Error if set in flags, otherwise result of offload processing
* filterResults: results of filtering on packet, not used
* ipsecResults: Results of IPSEC processing
* vlanTag: the 801.2q TCI from the packet
*/
struct rx_desc {
u8 flags;
u8 numDesc;
__le16 frameLen;
u32 addr; /* opaque, comes from virtAddr */
u32 addrHi; /* opaque, comes from virtAddrHi */
__le32 rxStatus;
#define TYPHOON_RX_ERR_INTERNAL cpu_to_le32(0x00000000)
#define TYPHOON_RX_ERR_FIFO_UNDERRUN cpu_to_le32(0x00000001)
#define TYPHOON_RX_ERR_BAD_SSD cpu_to_le32(0x00000002)
#define TYPHOON_RX_ERR_RUNT cpu_to_le32(0x00000003)
#define TYPHOON_RX_ERR_CRC cpu_to_le32(0x00000004)
#define TYPHOON_RX_ERR_OVERSIZE cpu_to_le32(0x00000005)
#define TYPHOON_RX_ERR_ALIGN cpu_to_le32(0x00000006)
#define TYPHOON_RX_ERR_DRIBBLE cpu_to_le32(0x00000007)
#define TYPHOON_RX_PROTO_MASK cpu_to_le32(0x00000003)
#define TYPHOON_RX_PROTO_UNKNOWN cpu_to_le32(0x00000000)
#define TYPHOON_RX_PROTO_IP cpu_to_le32(0x00000001)
#define TYPHOON_RX_PROTO_IPX cpu_to_le32(0x00000002)
#define TYPHOON_RX_VLAN cpu_to_le32(0x00000004)
#define TYPHOON_RX_IP_FRAG cpu_to_le32(0x00000008)
#define TYPHOON_RX_IPSEC cpu_to_le32(0x00000010)
#define TYPHOON_RX_IP_CHK_FAIL cpu_to_le32(0x00000020)
#define TYPHOON_RX_TCP_CHK_FAIL cpu_to_le32(0x00000040)
#define TYPHOON_RX_UDP_CHK_FAIL cpu_to_le32(0x00000080)
#define TYPHOON_RX_IP_CHK_GOOD cpu_to_le32(0x00000100)
#define TYPHOON_RX_TCP_CHK_GOOD cpu_to_le32(0x00000200)
#define TYPHOON_RX_UDP_CHK_GOOD cpu_to_le32(0x00000400)
__le16 filterResults;
#define TYPHOON_RX_FILTER_MASK cpu_to_le16(0x7fff)
#define TYPHOON_RX_FILTERED cpu_to_le16(0x8000)
__le16 ipsecResults;
#define TYPHOON_RX_OUTER_AH_GOOD cpu_to_le16(0x0001)
#define TYPHOON_RX_OUTER_ESP_GOOD cpu_to_le16(0x0002)
#define TYPHOON_RX_INNER_AH_GOOD cpu_to_le16(0x0004)
#define TYPHOON_RX_INNER_ESP_GOOD cpu_to_le16(0x0008)
#define TYPHOON_RX_OUTER_AH_FAIL cpu_to_le16(0x0010)
#define TYPHOON_RX_OUTER_ESP_FAIL cpu_to_le16(0x0020)
#define TYPHOON_RX_INNER_AH_FAIL cpu_to_le16(0x0040)
#define TYPHOON_RX_INNER_ESP_FAIL cpu_to_le16(0x0080)
#define TYPHOON_RX_UNKNOWN_SA cpu_to_le16(0x0100)
#define TYPHOON_RX_ESP_FORMAT_ERR cpu_to_le16(0x0200)
__be32 vlanTag;
} __packed;
/* The Typhoon free buffer descriptor, used to give a buffer to the NIC
*
* physAddr: low 32 bits of the bus address of the buffer
* physAddrHi: high 32 bits of the bus address of the buffer, always zero
* virtAddr: low 32 bits of the skb address
* virtAddrHi: high 32 bits of the skb address, always zero
*
* the virt* address is basically two 32 bit cookies, just passed back
* from the NIC
*/
struct rx_free {
__le32 physAddr;
__le32 physAddrHi;
u32 virtAddr;
u32 virtAddrHi;
} __packed;
/* The Typhoon command descriptor, used for commands and responses
*
* flags: descriptor type
* numDesc: number of descriptors following in this command/response,
* ie, zero for a one descriptor command
* cmd: the command
* seqNo: sequence number (unused)
* parm1: use varies by command
* parm2: use varies by command
* parm3: use varies by command
*/
struct cmd_desc {
u8 flags;
u8 numDesc;
__le16 cmd;
#define TYPHOON_CMD_TX_ENABLE cpu_to_le16(0x0001)
#define TYPHOON_CMD_TX_DISABLE cpu_to_le16(0x0002)
#define TYPHOON_CMD_RX_ENABLE cpu_to_le16(0x0003)
#define TYPHOON_CMD_RX_DISABLE cpu_to_le16(0x0004)
#define TYPHOON_CMD_SET_RX_FILTER cpu_to_le16(0x0005)
#define TYPHOON_CMD_READ_STATS cpu_to_le16(0x0007)
#define TYPHOON_CMD_XCVR_SELECT cpu_to_le16(0x0013)
#define TYPHOON_CMD_SET_MAX_PKT_SIZE cpu_to_le16(0x001a)
#define TYPHOON_CMD_READ_MEDIA_STATUS cpu_to_le16(0x001b)
#define TYPHOON_CMD_GOTO_SLEEP cpu_to_le16(0x0023)
#define TYPHOON_CMD_SET_MULTICAST_HASH cpu_to_le16(0x0025)
#define TYPHOON_CMD_SET_MAC_ADDRESS cpu_to_le16(0x0026)
#define TYPHOON_CMD_READ_MAC_ADDRESS cpu_to_le16(0x0027)
#define TYPHOON_CMD_VLAN_TYPE_WRITE cpu_to_le16(0x002b)
#define TYPHOON_CMD_CREATE_SA cpu_to_le16(0x0034)
#define TYPHOON_CMD_DELETE_SA cpu_to_le16(0x0035)
#define TYPHOON_CMD_READ_VERSIONS cpu_to_le16(0x0043)
#define TYPHOON_CMD_IRQ_COALESCE_CTRL cpu_to_le16(0x0045)
#define TYPHOON_CMD_ENABLE_WAKE_EVENTS cpu_to_le16(0x0049)
#define TYPHOON_CMD_SET_OFFLOAD_TASKS cpu_to_le16(0x004f)
#define TYPHOON_CMD_HELLO_RESP cpu_to_le16(0x0057)
#define TYPHOON_CMD_HALT cpu_to_le16(0x005d)
#define TYPHOON_CMD_READ_IPSEC_INFO cpu_to_le16(0x005e)
#define TYPHOON_CMD_GET_IPSEC_ENABLE cpu_to_le16(0x0067)
#define TYPHOON_CMD_GET_CMD_LVL cpu_to_le16(0x0069)
u16 seqNo;
__le16 parm1;
__le32 parm2;
__le32 parm3;
} __packed;
/* The Typhoon response descriptor, see command descriptor for details
*/
struct resp_desc {
u8 flags;
u8 numDesc;
__le16 cmd;
__le16 seqNo;
__le16 parm1;
__le32 parm2;
__le32 parm3;
} __packed;
#define INIT_COMMAND_NO_RESPONSE(x, command) \
do { struct cmd_desc *_ptr = (x); \
memset(_ptr, 0, sizeof(struct cmd_desc)); \
_ptr->flags = TYPHOON_CMD_DESC | TYPHOON_DESC_VALID; \
_ptr->cmd = command; \
} while(0)
/* We set seqNo to 1 if we're expecting a response from this command */
#define INIT_COMMAND_WITH_RESPONSE(x, command) \
do { struct cmd_desc *_ptr = (x); \
memset(_ptr, 0, sizeof(struct cmd_desc)); \
_ptr->flags = TYPHOON_CMD_RESPOND | TYPHOON_CMD_DESC; \
_ptr->flags |= TYPHOON_DESC_VALID; \
_ptr->cmd = command; \
_ptr->seqNo = 1; \
} while(0)
/* TYPHOON_CMD_SET_RX_FILTER filter bits (cmd.parm1)
*/
#define TYPHOON_RX_FILTER_DIRECTED cpu_to_le16(0x0001)
#define TYPHOON_RX_FILTER_ALL_MCAST cpu_to_le16(0x0002)
#define TYPHOON_RX_FILTER_BROADCAST cpu_to_le16(0x0004)
#define TYPHOON_RX_FILTER_PROMISCOUS cpu_to_le16(0x0008)
#define TYPHOON_RX_FILTER_MCAST_HASH cpu_to_le16(0x0010)
/* TYPHOON_CMD_READ_STATS response format
*/
struct stats_resp {
u8 flags;
u8 numDesc;
__le16 cmd;
__le16 seqNo;
__le16 unused;
__le32 txPackets;
__le64 txBytes;
__le32 txDeferred;
__le32 txLateCollisions;
__le32 txCollisions;
__le32 txCarrierLost;
__le32 txMultipleCollisions;
__le32 txExcessiveCollisions;
__le32 txFifoUnderruns;
__le32 txMulticastTxOverflows;
__le32 txFiltered;
__le32 rxPacketsGood;
__le64 rxBytesGood;
__le32 rxFifoOverruns;
__le32 BadSSD;
__le32 rxCrcErrors;
__le32 rxOversized;
__le32 rxBroadcast;
__le32 rxMulticast;
__le32 rxOverflow;
__le32 rxFiltered;
__le32 linkStatus;
#define TYPHOON_LINK_STAT_MASK cpu_to_le32(0x00000001)
#define TYPHOON_LINK_GOOD cpu_to_le32(0x00000001)
#define TYPHOON_LINK_BAD cpu_to_le32(0x00000000)
#define TYPHOON_LINK_SPEED_MASK cpu_to_le32(0x00000002)
#define TYPHOON_LINK_100MBPS cpu_to_le32(0x00000002)
#define TYPHOON_LINK_10MBPS cpu_to_le32(0x00000000)
#define TYPHOON_LINK_DUPLEX_MASK cpu_to_le32(0x00000004)
#define TYPHOON_LINK_FULL_DUPLEX cpu_to_le32(0x00000004)
#define TYPHOON_LINK_HALF_DUPLEX cpu_to_le32(0x00000000)
__le32 unused2;
__le32 unused3;
} __packed;
/* TYPHOON_CMD_XCVR_SELECT xcvr values (resp.parm1)
*/
#define TYPHOON_XCVR_10HALF cpu_to_le16(0x0000)
#define TYPHOON_XCVR_10FULL cpu_to_le16(0x0001)
#define TYPHOON_XCVR_100HALF cpu_to_le16(0x0002)
#define TYPHOON_XCVR_100FULL cpu_to_le16(0x0003)
#define TYPHOON_XCVR_AUTONEG cpu_to_le16(0x0004)
/* TYPHOON_CMD_READ_MEDIA_STATUS (resp.parm1)
*/
#define TYPHOON_MEDIA_STAT_CRC_STRIP_DISABLE cpu_to_le16(0x0004)
#define TYPHOON_MEDIA_STAT_COLLISION_DETECT cpu_to_le16(0x0010)
#define TYPHOON_MEDIA_STAT_CARRIER_SENSE cpu_to_le16(0x0020)
#define TYPHOON_MEDIA_STAT_POLARITY_REV cpu_to_le16(0x0400)
#define TYPHOON_MEDIA_STAT_NO_LINK cpu_to_le16(0x0800)
/* TYPHOON_CMD_SET_MULTICAST_HASH enable values (cmd.parm1)
*/
#define TYPHOON_MCAST_HASH_DISABLE cpu_to_le16(0x0000)
#define TYPHOON_MCAST_HASH_ENABLE cpu_to_le16(0x0001)
#define TYPHOON_MCAST_HASH_SET cpu_to_le16(0x0002)
/* TYPHOON_CMD_CREATE_SA descriptor and settings
*/
struct sa_descriptor {
u8 flags;
u8 numDesc;
u16 cmd;
u16 seqNo;
u16 mode;
#define TYPHOON_SA_MODE_NULL cpu_to_le16(0x0000)
#define TYPHOON_SA_MODE_AH cpu_to_le16(0x0001)
#define TYPHOON_SA_MODE_ESP cpu_to_le16(0x0002)
u8 hashFlags;
#define TYPHOON_SA_HASH_ENABLE 0x01
#define TYPHOON_SA_HASH_SHA1 0x02
#define TYPHOON_SA_HASH_MD5 0x04
u8 direction;
#define TYPHOON_SA_DIR_RX 0x00
#define TYPHOON_SA_DIR_TX 0x01
u8 encryptionFlags;
#define TYPHOON_SA_ENCRYPT_ENABLE 0x01
#define TYPHOON_SA_ENCRYPT_DES 0x02
#define TYPHOON_SA_ENCRYPT_3DES 0x00
#define TYPHOON_SA_ENCRYPT_3DES_2KEY 0x00
#define TYPHOON_SA_ENCRYPT_3DES_3KEY 0x04
#define TYPHOON_SA_ENCRYPT_CBC 0x08
#define TYPHOON_SA_ENCRYPT_ECB 0x00
u8 specifyIndex;
#define TYPHOON_SA_SPECIFY_INDEX 0x01
#define TYPHOON_SA_GENERATE_INDEX 0x00
u32 SPI;
u32 destAddr;
u32 destMask;
u8 integKey[20];
u8 confKey[24];
u32 index;
u32 unused;
u32 unused2;
} __packed;
/* TYPHOON_CMD_SET_OFFLOAD_TASKS bits (cmd.parm2 (Tx) & cmd.parm3 (Rx))
* This is all for IPv4.
*/
#define TYPHOON_OFFLOAD_TCP_CHKSUM cpu_to_le32(0x00000002)
#define TYPHOON_OFFLOAD_UDP_CHKSUM cpu_to_le32(0x00000004)
#define TYPHOON_OFFLOAD_IP_CHKSUM cpu_to_le32(0x00000008)
#define TYPHOON_OFFLOAD_IPSEC cpu_to_le32(0x00000010)
#define TYPHOON_OFFLOAD_BCAST_THROTTLE cpu_to_le32(0x00000020)
#define TYPHOON_OFFLOAD_DHCP_PREVENT cpu_to_le32(0x00000040)
#define TYPHOON_OFFLOAD_VLAN cpu_to_le32(0x00000080)
#define TYPHOON_OFFLOAD_FILTERING cpu_to_le32(0x00000100)
#define TYPHOON_OFFLOAD_TCP_SEGMENT cpu_to_le32(0x00000200)
/* TYPHOON_CMD_ENABLE_WAKE_EVENTS bits (cmd.parm1)
*/
#define TYPHOON_WAKE_MAGIC_PKT cpu_to_le16(0x01)
#define TYPHOON_WAKE_LINK_EVENT cpu_to_le16(0x02)
#define TYPHOON_WAKE_ICMP_ECHO cpu_to_le16(0x04)
#define TYPHOON_WAKE_ARP cpu_to_le16(0x08)
/* These are used to load the firmware image on the NIC
*/
struct typhoon_file_header {
u8 tag[8];
__le32 version;
__le32 numSections;
__le32 startAddr;
__le32 hmacDigest[5];
} __packed;
struct typhoon_section_header {
__le32 len;
u16 checksum;
u16 reserved;
__le32 startAddr;
} __packed;
/* The Typhoon Register offsets
*/
#define TYPHOON_REG_SOFT_RESET 0x00
#define TYPHOON_REG_INTR_STATUS 0x04
#define TYPHOON_REG_INTR_ENABLE 0x08
#define TYPHOON_REG_INTR_MASK 0x0c
#define TYPHOON_REG_SELF_INTERRUPT 0x10
#define TYPHOON_REG_HOST2ARM7 0x14
#define TYPHOON_REG_HOST2ARM6 0x18
#define TYPHOON_REG_HOST2ARM5 0x1c
#define TYPHOON_REG_HOST2ARM4 0x20
#define TYPHOON_REG_HOST2ARM3 0x24
#define TYPHOON_REG_HOST2ARM2 0x28
#define TYPHOON_REG_HOST2ARM1 0x2c
#define TYPHOON_REG_HOST2ARM0 0x30
#define TYPHOON_REG_ARM2HOST3 0x34
#define TYPHOON_REG_ARM2HOST2 0x38
#define TYPHOON_REG_ARM2HOST1 0x3c
#define TYPHOON_REG_ARM2HOST0 0x40
#define TYPHOON_REG_BOOT_DATA_LO TYPHOON_REG_HOST2ARM5
#define TYPHOON_REG_BOOT_DATA_HI TYPHOON_REG_HOST2ARM4
#define TYPHOON_REG_BOOT_DEST_ADDR TYPHOON_REG_HOST2ARM3
#define TYPHOON_REG_BOOT_CHECKSUM TYPHOON_REG_HOST2ARM2
#define TYPHOON_REG_BOOT_LENGTH TYPHOON_REG_HOST2ARM1
#define TYPHOON_REG_DOWNLOAD_BOOT_ADDR TYPHOON_REG_HOST2ARM1
#define TYPHOON_REG_DOWNLOAD_HMAC_0 TYPHOON_REG_HOST2ARM2
#define TYPHOON_REG_DOWNLOAD_HMAC_1 TYPHOON_REG_HOST2ARM3
#define TYPHOON_REG_DOWNLOAD_HMAC_2 TYPHOON_REG_HOST2ARM4
#define TYPHOON_REG_DOWNLOAD_HMAC_3 TYPHOON_REG_HOST2ARM5
#define TYPHOON_REG_DOWNLOAD_HMAC_4 TYPHOON_REG_HOST2ARM6
#define TYPHOON_REG_BOOT_RECORD_ADDR_HI TYPHOON_REG_HOST2ARM2
#define TYPHOON_REG_BOOT_RECORD_ADDR_LO TYPHOON_REG_HOST2ARM1
#define TYPHOON_REG_TX_LO_READY TYPHOON_REG_HOST2ARM3
#define TYPHOON_REG_CMD_READY TYPHOON_REG_HOST2ARM2
#define TYPHOON_REG_TX_HI_READY TYPHOON_REG_HOST2ARM1
#define TYPHOON_REG_COMMAND TYPHOON_REG_HOST2ARM0
#define TYPHOON_REG_HEARTBEAT TYPHOON_REG_ARM2HOST3
#define TYPHOON_REG_STATUS TYPHOON_REG_ARM2HOST0
/* 3XP Reset values (TYPHOON_REG_SOFT_RESET)
*/
#define TYPHOON_RESET_ALL 0x7f
#define TYPHOON_RESET_NONE 0x00
/* 3XP irq bits (TYPHOON_REG_INTR{STATUS,ENABLE,MASK})
*
* Some of these came from OpenBSD, as the 3Com docs have it wrong
* (INTR_SELF) or don't list it at all (INTR_*_ABORT)
*
* Enabling irqs on the Heartbeat reg (ArmToHost3) gets you an irq
* about every 8ms, so don't do it.
*/
#define TYPHOON_INTR_HOST_INT 0x00000001
#define TYPHOON_INTR_ARM2HOST0 0x00000002
#define TYPHOON_INTR_ARM2HOST1 0x00000004
#define TYPHOON_INTR_ARM2HOST2 0x00000008
#define TYPHOON_INTR_ARM2HOST3 0x00000010
#define TYPHOON_INTR_DMA0 0x00000020
#define TYPHOON_INTR_DMA1 0x00000040
#define TYPHOON_INTR_DMA2 0x00000080
#define TYPHOON_INTR_DMA3 0x00000100
#define TYPHOON_INTR_MASTER_ABORT 0x00000200
#define TYPHOON_INTR_TARGET_ABORT 0x00000400
#define TYPHOON_INTR_SELF 0x00000800
#define TYPHOON_INTR_RESERVED 0xfffff000
#define TYPHOON_INTR_BOOTCMD TYPHOON_INTR_ARM2HOST0
#define TYPHOON_INTR_ENABLE_ALL 0xffffffef
#define TYPHOON_INTR_ALL 0xffffffff
#define TYPHOON_INTR_NONE 0x00000000
/* The commands for the 3XP chip (TYPHOON_REG_COMMAND)
*/
#define TYPHOON_BOOTCMD_BOOT 0x00
#define TYPHOON_BOOTCMD_WAKEUP 0xfa
#define TYPHOON_BOOTCMD_DNLD_COMPLETE 0xfb
#define TYPHOON_BOOTCMD_SEG_AVAILABLE 0xfc
#define TYPHOON_BOOTCMD_RUNTIME_IMAGE 0xfd
#define TYPHOON_BOOTCMD_REG_BOOT_RECORD 0xff
/* 3XP Status values (TYPHOON_REG_STATUS)
*/
#define TYPHOON_STATUS_WAITING_FOR_BOOT 0x07
#define TYPHOON_STATUS_SECOND_INIT 0x08
#define TYPHOON_STATUS_RUNNING 0x09
#define TYPHOON_STATUS_WAITING_FOR_HOST 0x0d
#define TYPHOON_STATUS_WAITING_FOR_SEGMENT 0x10
#define TYPHOON_STATUS_SLEEPING 0x11
#define TYPHOON_STATUS_HALTED 0x14