2005-04-17 06:20:36 +08:00
|
|
|
/*======================================================================
|
|
|
|
|
|
|
|
A PCMCIA ethernet driver for the 3com 3c589 card.
|
2010-03-31 10:42:10 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
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:
|
2010-03-31 10:42:10 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
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
|
2010-03-31 10:42:10 +08:00
|
|
|
|
2008-10-14 10:01:08 +08:00
|
|
|
Updated for 2.5.x by Alan Cox <alan@lxorguk.ukuu.org.uk>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
======================================================================*/
|
|
|
|
|
2010-08-12 20:22:51 +08:00
|
|
|
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
#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>
|
2006-01-10 10:37:15 +08:00
|
|
|
#include <linux/jiffies.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
#include <pcmcia/cistpl.h>
|
|
|
|
#include <pcmcia/cisreg.h>
|
|
|
|
#include <pcmcia/ciscode.h>
|
|
|
|
#include <pcmcia/ds.h>
|
|
|
|
|
|
|
|
#include <asm/uaccess.h>
|
|
|
|
#include <asm/io.h>
|
|
|
|
#include <asm/system.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 {
|
2010-03-31 10:42:10 +08:00
|
|
|
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
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
enum c509status {
|
2010-03-31 10:42:10 +08:00
|
|
|
IntLatch = 0x0001,
|
|
|
|
AdapterFailure = 0x0002,
|
|
|
|
TxComplete = 0x0004,
|
|
|
|
TxAvailable = 0x0008,
|
|
|
|
RxComplete = 0x0010,
|
|
|
|
RxEarly = 0x0020,
|
|
|
|
IntReq = 0x0040,
|
|
|
|
StatsFull = 0x0080,
|
|
|
|
CmdBusy = 0x1000
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/* The SetRxFilter command accepts the following classes: */
|
|
|
|
enum RxFilter {
|
2010-03-31 10:42:10 +08:00
|
|
|
RxStation = 1,
|
|
|
|
RxMulticast = 2,
|
|
|
|
RxBroadcast = 4,
|
|
|
|
RxProm = 8
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Register window 1 offsets, the window used in normal operation. */
|
|
|
|
#define TX_FIFO 0x00
|
|
|
|
#define RX_FIFO 0x00
|
2010-03-31 10:42:10 +08:00
|
|
|
#define RX_STATUS 0x08
|
|
|
|
#define TX_STATUS 0x0B
|
2005-04-17 06:20:36 +08:00
|
|
|
#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 {
|
2006-03-05 17:45:09 +08:00
|
|
|
struct pcmcia_device *p_dev;
|
2010-03-31 10:42:10 +08:00
|
|
|
/* For transceiver monitoring */
|
|
|
|
struct timer_list media;
|
|
|
|
u16 media_status;
|
|
|
|
u16 fast_poll;
|
|
|
|
unsigned long last_irq;
|
|
|
|
spinlock_t lock;
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
2007-09-25 12:11:34 +08:00
|
|
|
static const char *if_names[] = { "auto", "10baseT", "10base2", "AUI" };
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*====================================================================*/
|
|
|
|
|
|
|
|
/* 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);
|
|
|
|
|
|
|
|
|
|
|
|
/*====================================================================*/
|
|
|
|
|
2006-03-31 23:26:06 +08:00
|
|
|
static int tc589_config(struct pcmcia_device *link);
|
2006-03-31 23:21:06 +08:00
|
|
|
static void tc589_release(struct pcmcia_device *link);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-02-05 14:27:35 +08:00
|
|
|
static u16 read_eeprom(unsigned int ioaddr, int index);
|
2005-04-17 06:20:36 +08:00
|
|
|
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);
|
2009-09-01 03:50:49 +08:00
|
|
|
static netdev_tx_t el3_start_xmit(struct sk_buff *skb,
|
|
|
|
struct net_device *dev);
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 21:55:46 +08:00
|
|
|
static irqreturn_t el3_interrupt(int irq, void *dev_id);
|
2005-04-17 06:20:36 +08:00
|
|
|
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);
|
2009-07-19 21:08:12 +08:00
|
|
|
static void set_rx_mode(struct net_device *dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
static void set_multicast_list(struct net_device *dev);
|
2006-09-14 02:30:00 +08:00
|
|
|
static const struct ethtool_ops netdev_ethtool_ops;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-11-15 04:23:14 +08:00
|
|
|
static void tc589_detach(struct pcmcia_device *p_dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-03-21 03:36:01 +08:00
|
|
|
static const struct net_device_ops el3_netdev_ops = {
|
2010-03-31 10:42:10 +08:00
|
|
|
.ndo_open = el3_open,
|
|
|
|
.ndo_stop = el3_close,
|
2009-03-21 03:36:01 +08:00
|
|
|
.ndo_start_xmit = el3_start_xmit,
|
2010-03-31 10:42:10 +08:00
|
|
|
.ndo_tx_timeout = el3_tx_timeout,
|
2009-03-21 03:36:01 +08:00
|
|
|
.ndo_set_config = el3_config,
|
|
|
|
.ndo_get_stats = el3_get_stats,
|
|
|
|
.ndo_set_multicast_list = set_multicast_list,
|
|
|
|
.ndo_change_mtu = eth_change_mtu,
|
2010-03-31 10:42:10 +08:00
|
|
|
.ndo_set_mac_address = eth_mac_addr,
|
2009-03-21 03:36:01 +08:00
|
|
|
.ndo_validate_addr = eth_validate_addr,
|
|
|
|
};
|
|
|
|
|
2006-03-31 23:26:06 +08:00
|
|
|
static int tc589_probe(struct pcmcia_device *link)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct el3_private *lp;
|
|
|
|
struct net_device *dev;
|
|
|
|
|
2009-10-24 21:51:05 +08:00
|
|
|
dev_dbg(&link->dev, "3c589_attach()\n");
|
2005-11-15 04:25:51 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Create new ethernet device */
|
|
|
|
dev = alloc_etherdev(sizeof(struct el3_private));
|
|
|
|
if (!dev)
|
2005-11-15 04:25:51 +08:00
|
|
|
return -ENOMEM;
|
2005-04-17 06:20:36 +08:00
|
|
|
lp = netdev_priv(dev);
|
|
|
|
link->priv = dev;
|
2006-03-31 23:21:06 +08:00
|
|
|
lp->p_dev = link;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
spin_lock_init(&lp->lock);
|
2010-07-24 23:23:51 +08:00
|
|
|
link->resource[0]->end = 16;
|
|
|
|
link->resource[0]->flags |= IO_DATA_PATH_WIDTH_16;
|
2010-03-07 19:21:16 +08:00
|
|
|
|
2010-07-30 01:27:09 +08:00
|
|
|
link->config_flags |= CONF_ENABLE_IRQ;
|
2010-07-30 00:35:47 +08:00
|
|
|
link->config_index = 1;
|
2005-11-15 04:25:51 +08:00
|
|
|
|
2009-03-21 03:36:01 +08:00
|
|
|
dev->netdev_ops = &el3_netdev_ops;
|
2005-04-17 06:20:36 +08:00
|
|
|
dev->watchdog_timeo = TX_TIMEOUT;
|
2009-03-21 03:36:01 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
SET_ETHTOOL_OPS(dev, &netdev_ethtool_ops);
|
|
|
|
|
2006-03-31 23:26:06 +08:00
|
|
|
return tc589_config(link);
|
2010-08-15 14:38:38 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-03-31 23:21:06 +08:00
|
|
|
static void tc589_detach(struct pcmcia_device *link)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct net_device *dev = link->priv;
|
2005-11-15 04:25:35 +08:00
|
|
|
|
2009-10-24 21:51:05 +08:00
|
|
|
dev_dbg(&link->dev, "3c589_detach\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2010-03-21 02:39:26 +08:00
|
|
|
unregister_netdev(dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-03-02 07:09:29 +08:00
|
|
|
tc589_release(link);
|
2005-11-15 04:23:14 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
free_netdev(dev);
|
|
|
|
} /* tc589_detach */
|
|
|
|
|
2006-03-31 23:26:06 +08:00
|
|
|
static int tc589_config(struct pcmcia_device *link)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct net_device *dev = link->priv;
|
2007-12-23 02:56:13 +08:00
|
|
|
__be16 *phys_addr;
|
2009-10-24 21:51:05 +08:00
|
|
|
int ret, i, j, multi = 0, fifo;
|
2008-02-05 14:27:35 +08:00
|
|
|
unsigned int ioaddr;
|
2010-09-14 02:23:54 +08:00
|
|
|
static const char * const ram_split[] = {"5:3", "3:1", "1:1", "3:5"};
|
2009-10-19 05:54:24 +08:00
|
|
|
u8 *buf;
|
|
|
|
size_t len;
|
2010-03-31 10:42:10 +08:00
|
|
|
|
2009-10-24 21:51:05 +08:00
|
|
|
dev_dbg(&link->dev, "3c589_config\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-12-23 02:56:13 +08:00
|
|
|
phys_addr = (__be16 *)dev->dev_addr;
|
2006-10-26 09:28:53 +08:00
|
|
|
/* Is this a 3c562? */
|
|
|
|
if (link->manf_id != MANFID_3COM)
|
2010-08-12 20:22:51 +08:00
|
|
|
dev_info(&link->dev, "hmmm, is this really a 3Com card??\n");
|
2006-10-26 09:28:53 +08:00
|
|
|
multi = (link->card_id == PRODID_3COM_3C562);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2010-07-24 23:23:51 +08:00
|
|
|
link->io_lines = 16;
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* For the 3c562, the base address must be xx00-xx7f */
|
|
|
|
for (i = j = 0; j < 0x400; j += 0x10) {
|
|
|
|
if (multi && (j & 0x80)) continue;
|
2010-07-24 23:23:51 +08:00
|
|
|
link->resource[0]->start = j ^ 0x300;
|
|
|
|
i = pcmcia_request_io(link);
|
2008-08-03 16:07:45 +08:00
|
|
|
if (i == 0)
|
|
|
|
break;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2009-10-24 21:51:05 +08:00
|
|
|
if (i != 0)
|
2005-04-17 06:20:36 +08:00
|
|
|
goto failed;
|
2009-10-24 21:51:05 +08:00
|
|
|
|
2010-03-07 19:21:16 +08:00
|
|
|
ret = pcmcia_request_irq(link, el3_interrupt);
|
2009-10-24 21:51:05 +08:00
|
|
|
if (ret)
|
|
|
|
goto failed;
|
|
|
|
|
2010-07-30 01:27:09 +08:00
|
|
|
ret = pcmcia_enable_device(link);
|
2009-10-24 21:51:05 +08:00
|
|
|
if (ret)
|
|
|
|
goto failed;
|
2010-03-31 10:42:10 +08:00
|
|
|
|
2010-03-07 19:21:16 +08:00
|
|
|
dev->irq = link->irq;
|
2010-07-24 21:58:54 +08:00
|
|
|
dev->base_addr = link->resource[0]->start;
|
2005-04-17 06:20:36 +08:00
|
|
|
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. */
|
2009-10-19 05:54:24 +08:00
|
|
|
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);
|
2005-04-17 06:20:36 +08:00
|
|
|
} else {
|
2009-10-19 05:54:24 +08:00
|
|
|
kfree(buf); /* 0 < len < 6 */
|
2005-04-17 06:20:36 +08:00
|
|
|
for (i = 0; i < 3; i++)
|
|
|
|
phys_addr[i] = htons(read_eeprom(ioaddr, i));
|
2007-12-23 02:56:13 +08:00
|
|
|
if (phys_addr[0] == htons(0x6060)) {
|
2010-08-12 20:22:51 +08:00
|
|
|
dev_err(&link->dev, "IO port conflict at 0x%03lx-0x%03lx\n",
|
|
|
|
dev->base_addr, dev->base_addr+15);
|
2005-04-17 06:20:36 +08:00
|
|
|
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
|
2010-08-12 20:22:51 +08:00
|
|
|
dev_err(&link->dev, "invalid if_port requested\n");
|
2010-03-31 10:42:10 +08:00
|
|
|
|
2009-11-03 17:27:34 +08:00
|
|
|
SET_NETDEV_DEV(dev, &link->dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (register_netdev(dev) != 0) {
|
2010-08-12 20:22:51 +08:00
|
|
|
dev_err(&link->dev, "register_netdev() failed\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
goto failed;
|
|
|
|
}
|
|
|
|
|
2010-03-31 10:42:10 +08:00
|
|
|
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]);
|
2006-03-31 23:26:06 +08:00
|
|
|
return 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
failed:
|
|
|
|
tc589_release(link);
|
2006-03-31 23:26:06 +08:00
|
|
|
return -ENODEV;
|
2005-04-17 06:20:36 +08:00
|
|
|
} /* tc589_config */
|
|
|
|
|
2006-03-31 23:21:06 +08:00
|
|
|
static void tc589_release(struct pcmcia_device *link)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2006-03-31 23:21:06 +08:00
|
|
|
pcmcia_disable_device(link);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2006-03-31 23:21:06 +08:00
|
|
|
static int tc589_suspend(struct pcmcia_device *link)
|
2005-11-15 04:21:18 +08:00
|
|
|
{
|
|
|
|
struct net_device *dev = link->priv;
|
|
|
|
|
2006-03-02 07:09:29 +08:00
|
|
|
if (link->open)
|
2006-03-02 07:02:33 +08:00
|
|
|
netif_device_detach(dev);
|
2005-11-15 04:21:18 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-03-31 23:21:06 +08:00
|
|
|
static int tc589_resume(struct pcmcia_device *link)
|
2005-11-15 04:21:18 +08:00
|
|
|
{
|
|
|
|
struct net_device *dev = link->priv;
|
|
|
|
|
2010-03-31 10:42:10 +08:00
|
|
|
if (link->open) {
|
2006-03-02 07:02:33 +08:00
|
|
|
tc589_reset(dev);
|
|
|
|
netif_device_attach(dev);
|
2005-11-15 04:21:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*====================================================================*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
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)
|
2010-03-31 10:42:10 +08:00
|
|
|
netdev_warn(dev, "command 0x%04x did not complete!\n", cmd);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
Read a word from the EEPROM using the regular EEPROM access register.
|
|
|
|
Assume that we are in register window zero.
|
|
|
|
*/
|
2008-02-05 14:27:35 +08:00
|
|
|
static u16 read_eeprom(unsigned int ioaddr, int index)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
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);
|
2008-02-05 14:27:35 +08:00
|
|
|
unsigned int ioaddr = dev->base_addr;
|
2010-03-31 10:42:10 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
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)
|
|
|
|
{
|
2008-02-05 14:27:35 +08:00
|
|
|
unsigned int ioaddr = dev->base_addr;
|
2005-04-17 06:20:36 +08:00
|
|
|
EL3WINDOW(1);
|
2010-03-31 10:42:10 +08:00
|
|
|
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));
|
2005-04-17 06:20:36 +08:00
|
|
|
EL3WINDOW(4);
|
2010-03-31 10:42:10 +08:00
|
|
|
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));
|
2005-04-17 06:20:36 +08:00
|
|
|
EL3WINDOW(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Reset and restore all of the 3c589 registers. */
|
|
|
|
static void tc589_reset(struct net_device *dev)
|
|
|
|
{
|
2008-02-05 14:27:35 +08:00
|
|
|
unsigned int ioaddr = dev->base_addr;
|
2005-04-17 06:20:36 +08:00
|
|
|
int i;
|
2010-03-31 10:42:10 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
EL3WINDOW(0);
|
2010-03-31 10:42:10 +08:00
|
|
|
outw(0x0001, ioaddr + 4); /* Activate board. */
|
2005-04-17 06:20:36 +08:00
|
|
|
outw(0x3f00, ioaddr + 8); /* Set the IRQ line. */
|
2010-03-31 10:42:10 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* 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);
|
2010-03-31 10:42:10 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* 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);
|
2010-03-31 10:42:10 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Switch to register set 1 for normal use. */
|
|
|
|
EL3WINDOW(1);
|
|
|
|
|
2009-07-19 21:08:12 +08:00
|
|
|
set_rx_mode(dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
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)
|
|
|
|
{
|
|
|
|
strcpy(info->driver, DRV_NAME);
|
|
|
|
strcpy(info->version, DRV_VERSION);
|
|
|
|
sprintf(info->bus_info, "PCMCIA 0x%lx", dev->base_addr);
|
|
|
|
}
|
|
|
|
|
2006-09-14 02:30:00 +08:00
|
|
|
static const struct ethtool_ops netdev_ethtool_ops = {
|
2005-04-17 06:20:36 +08:00
|
|
|
.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;
|
2010-03-31 10:42:10 +08:00
|
|
|
netdev_info(dev, "switched to %s port\n", if_names[dev->if_port]);
|
2005-04-17 06:20:36 +08:00
|
|
|
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);
|
2006-03-31 23:21:06 +08:00
|
|
|
struct pcmcia_device *link = lp->p_dev;
|
2010-03-31 10:42:10 +08:00
|
|
|
|
2006-03-05 18:04:33 +08:00
|
|
|
if (!pcmcia_dev_present(link))
|
2005-04-17 06:20:36 +08:00
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
link->open++;
|
|
|
|
netif_start_queue(dev);
|
2010-03-31 10:42:10 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
tc589_reset(dev);
|
|
|
|
init_timer(&lp->media);
|
2010-08-24 02:20:03 +08:00
|
|
|
lp->media.function = media_check;
|
2005-04-17 06:20:36 +08:00
|
|
|
lp->media.data = (unsigned long) dev;
|
|
|
|
lp->media.expires = jiffies + HZ;
|
|
|
|
add_timer(&lp->media);
|
|
|
|
|
2009-10-24 21:51:05 +08:00
|
|
|
dev_dbg(&link->dev, "%s: opened, status %4.4x.\n",
|
2005-04-17 06:20:36 +08:00
|
|
|
dev->name, inw(dev->base_addr + EL3_STATUS));
|
2010-03-31 10:42:10 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void el3_tx_timeout(struct net_device *dev)
|
|
|
|
{
|
2008-02-05 14:27:35 +08:00
|
|
|
unsigned int ioaddr = dev->base_addr;
|
2010-03-31 10:42:10 +08:00
|
|
|
|
|
|
|
netdev_warn(dev, "Transmit timed out!\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
dump_status(dev);
|
2008-04-30 06:20:20 +08:00
|
|
|
dev->stats.tx_errors++;
|
2010-05-10 20:01:31 +08:00
|
|
|
dev->trans_start = jiffies; /* prevent tx timeout */
|
2005-04-17 06:20:36 +08:00
|
|
|
/* 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)
|
|
|
|
{
|
2008-02-05 14:27:35 +08:00
|
|
|
unsigned int ioaddr = dev->base_addr;
|
2005-04-17 06:20:36 +08:00
|
|
|
int i;
|
2010-03-31 10:42:10 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* 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)
|
2010-03-31 10:42:10 +08:00
|
|
|
tc589_wait_for_completion(dev, TxReset);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (tx_status & 0x38) {
|
2010-03-31 10:42:10 +08:00
|
|
|
netdev_dbg(dev, "transmit error: status 0x%02x\n", tx_status);
|
|
|
|
outw(TxEnable, ioaddr + EL3_CMD);
|
|
|
|
dev->stats.tx_aborted_errors++;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
outb(0x00, ioaddr + TX_STATUS); /* Pop the status stack. */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-01 03:50:49 +08:00
|
|
|
static netdev_tx_t el3_start_xmit(struct sk_buff *skb,
|
|
|
|
struct net_device *dev)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2008-02-05 14:27:35 +08:00
|
|
|
unsigned int ioaddr = dev->base_addr;
|
2005-04-17 06:20:36 +08:00
|
|
|
struct el3_private *priv = netdev_priv(dev);
|
2006-12-02 10:53:27 +08:00
|
|
|
unsigned long flags;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2010-03-31 10:42:10 +08:00
|
|
|
netdev_dbg(dev, "el3_start_xmit(length = %ld) called, status %4.4x.\n",
|
|
|
|
(long)skb->len, inw(ioaddr + EL3_STATUS));
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2010-03-31 10:42:10 +08:00
|
|
|
spin_lock_irqsave(&priv->lock, flags);
|
2006-12-02 10:53:27 +08:00
|
|
|
|
2008-04-30 06:20:20 +08:00
|
|
|
dev->stats.tx_bytes += skb->len;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* 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);
|
2010-03-31 10:42:10 +08:00
|
|
|
spin_unlock_irqrestore(&priv->lock, flags);
|
2007-07-02 22:08:28 +08:00
|
|
|
dev_kfree_skb(skb);
|
2010-03-31 10:42:10 +08:00
|
|
|
|
2009-06-23 14:03:08 +08:00
|
|
|
return NETDEV_TX_OK;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* The EL3 interrupt handler. */
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 21:55:46 +08:00
|
|
|
static irqreturn_t el3_interrupt(int irq, void *dev_id)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct net_device *dev = (struct net_device *) dev_id;
|
|
|
|
struct el3_private *lp = netdev_priv(dev);
|
2008-02-05 14:27:35 +08:00
|
|
|
unsigned int ioaddr;
|
2005-04-17 06:20:36 +08:00
|
|
|
__u16 status;
|
|
|
|
int i = 0, handled = 1;
|
2010-03-31 10:42:10 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!netif_device_present(dev))
|
|
|
|
return IRQ_NONE;
|
|
|
|
|
|
|
|
ioaddr = dev->base_addr;
|
|
|
|
|
2010-03-31 10:42:10 +08:00
|
|
|
netdev_dbg(dev, "interrupt, status %4.4x.\n", inw(ioaddr + EL3_STATUS));
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2010-03-31 10:42:10 +08:00
|
|
|
spin_lock(&lp->lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
while ((status = inw(ioaddr + EL3_STATUS)) &
|
|
|
|
(IntLatch | RxComplete | StatsFull)) {
|
|
|
|
if ((status & 0xe000) != 0x2000) {
|
2010-03-31 10:42:10 +08:00
|
|
|
netdev_dbg(dev, "interrupt from dead card\n");
|
|
|
|
handled = 0;
|
|
|
|
break;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
if (status & RxComplete)
|
2010-03-31 10:42:10 +08:00
|
|
|
el3_rx(dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (status & TxAvailable) {
|
2010-03-31 10:42:10 +08:00
|
|
|
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);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
if (status & TxComplete)
|
2010-03-31 10:42:10 +08:00
|
|
|
pop_tx_status(dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
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);
|
2010-03-31 10:42:10 +08:00
|
|
|
netdev_warn(dev, "adapter failure, FIFO diagnostic register %04x.\n",
|
|
|
|
fifo_diag);
|
2005-04-17 06:20:36 +08:00
|
|
|
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);
|
2009-07-19 21:08:12 +08:00
|
|
|
set_rx_mode(dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
outw(RxEnable, ioaddr + EL3_CMD);
|
|
|
|
}
|
|
|
|
outw(AckIntr | AdapterFailure, ioaddr + EL3_CMD);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (++i > 10) {
|
2010-03-31 10:42:10 +08:00
|
|
|
netdev_err(dev, "infinite loop in interrupt, status %4.4x.\n",
|
|
|
|
status);
|
|
|
|
/* Clear all interrupts */
|
|
|
|
outw(AckIntr | 0xFF, ioaddr + EL3_CMD);
|
|
|
|
break;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
/* Acknowledge the IRQ. */
|
|
|
|
outw(AckIntr | IntReq | IntLatch, ioaddr + EL3_CMD);
|
|
|
|
}
|
|
|
|
lp->last_irq = jiffies;
|
2010-03-31 10:42:10 +08:00
|
|
|
spin_unlock(&lp->lock);
|
|
|
|
netdev_dbg(dev, "exiting interrupt, status %4.4x.\n",
|
|
|
|
inw(ioaddr + EL3_STATUS));
|
2005-04-17 06:20:36 +08:00
|
|
|
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);
|
2008-02-05 14:27:35 +08:00
|
|
|
unsigned int ioaddr = dev->base_addr;
|
2005-04-17 06:20:36 +08:00
|
|
|
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)
|
2010-03-31 10:42:10 +08:00
|
|
|
netdev_warn(dev, "interrupt(s) dropped!\n");
|
2009-12-12 22:44:11 +08:00
|
|
|
|
|
|
|
local_irq_save(flags);
|
2006-12-02 10:53:27 +08:00
|
|
|
el3_interrupt(dev->irq, dev);
|
2009-12-12 22:44:11 +08:00
|
|
|
local_irq_restore(flags);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
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 */
|
2010-03-31 10:42:10 +08:00
|
|
|
spin_lock_irqsave(&lp->lock, flags);
|
2005-04-17 06:20:36 +08:00
|
|
|
EL3WINDOW(4);
|
|
|
|
media = inw(ioaddr+WN4_MEDIA) & 0xc810;
|
|
|
|
|
|
|
|
/* Ignore collisions unless we've had no irq's recently */
|
2006-01-10 10:37:15 +08:00
|
|
|
if (time_before(jiffies, lp->last_irq + HZ)) {
|
2005-04-17 06:20:36 +08:00
|
|
|
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);
|
2008-04-30 06:20:20 +08:00
|
|
|
dev->stats.tx_carrier_errors += errs;
|
2005-04-17 06:20:36 +08:00
|
|
|
if (errs || (lp->media_status & 0x0010)) media |= 0x0010;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (media != lp->media_status) {
|
|
|
|
if ((media & lp->media_status & 0x8000) &&
|
|
|
|
((lp->media_status ^ media) & 0x0800))
|
2010-03-31 10:42:10 +08:00
|
|
|
netdev_info(dev, "%s link beat\n",
|
|
|
|
(lp->media_status & 0x0800 ? "lost" : "found"));
|
2005-04-17 06:20:36 +08:00
|
|
|
else if ((media & lp->media_status & 0x4000) &&
|
|
|
|
((lp->media_status ^ media) & 0x0010))
|
2010-03-31 10:42:10 +08:00
|
|
|
netdev_info(dev, "coax cable %s\n",
|
|
|
|
(lp->media_status & 0x0010 ? "ok" : "problem"));
|
2005-04-17 06:20:36 +08:00
|
|
|
if (dev->if_port == 0) {
|
|
|
|
if (media & 0x8000) {
|
|
|
|
if (media & 0x0800)
|
2010-03-31 10:42:10 +08:00
|
|
|
netdev_info(dev, "flipped to 10baseT\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
else
|
2010-03-31 10:42:10 +08:00
|
|
|
tc589_set_xcvr(dev, 2);
|
2005-04-17 06:20:36 +08:00
|
|
|
} else if (media & 0x4000) {
|
|
|
|
if (media & 0x0010)
|
|
|
|
tc589_set_xcvr(dev, 1);
|
|
|
|
else
|
2010-03-31 10:42:10 +08:00
|
|
|
netdev_info(dev, "flipped to 10base2\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
lp->media_status = media;
|
|
|
|
}
|
2010-03-31 10:42:10 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
EL3WINDOW(1);
|
2010-03-31 10:42:10 +08:00
|
|
|
spin_unlock_irqrestore(&lp->lock, flags);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
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;
|
2006-03-31 23:21:06 +08:00
|
|
|
struct pcmcia_device *link = lp->p_dev;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-03-05 18:04:33 +08:00
|
|
|
if (pcmcia_dev_present(link)) {
|
2010-03-31 10:42:10 +08:00
|
|
|
spin_lock_irqsave(&lp->lock, flags);
|
2005-04-17 06:20:36 +08:00
|
|
|
update_stats(dev);
|
|
|
|
spin_unlock_irqrestore(&lp->lock, flags);
|
|
|
|
}
|
2008-04-30 06:20:20 +08:00
|
|
|
return &dev->stats;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
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.
|
2010-03-31 10:42:10 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
Caller must hold the lock for this
|
|
|
|
*/
|
|
|
|
static void update_stats(struct net_device *dev)
|
|
|
|
{
|
2008-02-05 14:27:35 +08:00
|
|
|
unsigned int ioaddr = dev->base_addr;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2010-03-31 10:42:10 +08:00
|
|
|
netdev_dbg(dev, "updating the statistics.\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Turn off statistics updates while reading. */
|
|
|
|
outw(StatsDisable, ioaddr + EL3_CMD);
|
|
|
|
/* Switch to the stats window, and read everything. */
|
|
|
|
EL3WINDOW(6);
|
2010-03-31 10:42:10 +08:00
|
|
|
dev->stats.tx_carrier_errors += inb(ioaddr + 0);
|
2008-04-30 06:20:20 +08:00
|
|
|
dev->stats.tx_heartbeat_errors += inb(ioaddr + 1);
|
2010-03-31 10:42:10 +08:00
|
|
|
/* Multiple collisions. */ inb(ioaddr + 2);
|
2008-04-30 06:20:20 +08:00
|
|
|
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);
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Rx packets */ inb(ioaddr + 7);
|
|
|
|
/* Tx deferrals */ inb(ioaddr + 8);
|
|
|
|
/* Rx octets */ inw(ioaddr + 10);
|
|
|
|
/* Tx octets */ inw(ioaddr + 12);
|
2010-03-31 10:42:10 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Back to window 1, and turn statistics back on. */
|
|
|
|
EL3WINDOW(1);
|
|
|
|
outw(StatsEnable, ioaddr + EL3_CMD);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int el3_rx(struct net_device *dev)
|
|
|
|
{
|
2008-02-05 14:27:35 +08:00
|
|
|
unsigned int ioaddr = dev->base_addr;
|
2005-04-17 06:20:36 +08:00
|
|
|
int worklimit = 32;
|
|
|
|
short rx_status;
|
2010-03-31 10:42:10 +08:00
|
|
|
|
|
|
|
netdev_dbg(dev, "in rx_packet(), status %4.4x, rx_status %4.4x.\n",
|
|
|
|
inw(ioaddr+EL3_STATUS), inw(ioaddr+RX_STATUS));
|
2005-04-17 06:20:36 +08:00
|
|
|
while (!((rx_status = inw(ioaddr + RX_STATUS)) & 0x8000) &&
|
2009-03-04 16:05:56 +08:00
|
|
|
worklimit > 0) {
|
|
|
|
worklimit--;
|
2005-04-17 06:20:36 +08:00
|
|
|
if (rx_status & 0x4000) { /* Error, update stats. */
|
|
|
|
short error = rx_status & 0x3800;
|
2008-04-30 06:20:20 +08:00
|
|
|
dev->stats.rx_errors++;
|
2005-04-17 06:20:36 +08:00
|
|
|
switch (error) {
|
2008-04-30 06:20:20 +08:00
|
|
|
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;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
short pkt_len = rx_status & 0x7ff;
|
|
|
|
struct sk_buff *skb;
|
2010-03-31 10:42:10 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
skb = dev_alloc_skb(pkt_len+5);
|
2010-03-31 10:42:10 +08:00
|
|
|
|
|
|
|
netdev_dbg(dev, " Receiving packet size %d status %4.4x.\n",
|
|
|
|
pkt_len, rx_status);
|
2005-04-17 06:20:36 +08:00
|
|
|
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);
|
2008-04-30 06:20:20 +08:00
|
|
|
dev->stats.rx_packets++;
|
|
|
|
dev->stats.rx_bytes += pkt_len;
|
2005-04-17 06:20:36 +08:00
|
|
|
} else {
|
2010-03-31 10:42:10 +08:00
|
|
|
netdev_dbg(dev, "couldn't allocate a sk_buff of size %d.\n",
|
|
|
|
pkt_len);
|
2008-04-30 06:20:20 +08:00
|
|
|
dev->stats.rx_dropped++;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Pop the top of the Rx FIFO */
|
|
|
|
tc589_wait_for_completion(dev, RxDiscard);
|
|
|
|
}
|
|
|
|
if (worklimit == 0)
|
2010-03-31 10:42:10 +08:00
|
|
|
netdev_warn(dev, "too much work in el3_rx!\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-07-19 21:08:12 +08:00
|
|
|
static void set_rx_mode(struct net_device *dev)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2008-02-05 14:27:35 +08:00
|
|
|
unsigned int ioaddr = dev->base_addr;
|
2005-04-17 06:20:36 +08:00
|
|
|
u16 opts = SetRxFilter | RxStation | RxBroadcast;
|
|
|
|
|
|
|
|
if (dev->flags & IFF_PROMISC)
|
|
|
|
opts |= RxMulticast | RxProm;
|
2010-02-08 12:30:35 +08:00
|
|
|
else if (!netdev_mc_empty(dev) || (dev->flags & IFF_ALLMULTI))
|
2005-04-17 06:20:36 +08:00
|
|
|
opts |= RxMulticast;
|
|
|
|
outw(opts, ioaddr + EL3_CMD);
|
|
|
|
}
|
|
|
|
|
2009-07-19 21:08:12 +08:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
static int el3_close(struct net_device *dev)
|
|
|
|
{
|
|
|
|
struct el3_private *lp = netdev_priv(dev);
|
2006-03-31 23:21:06 +08:00
|
|
|
struct pcmcia_device *link = lp->p_dev;
|
2008-02-05 14:27:35 +08:00
|
|
|
unsigned int ioaddr = dev->base_addr;
|
2010-03-31 10:42:10 +08:00
|
|
|
|
2009-10-24 21:51:05 +08:00
|
|
|
dev_dbg(&link->dev, "%s: shutting down ethercard.\n", dev->name);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-03-05 18:04:33 +08:00
|
|
|
if (pcmcia_dev_present(link)) {
|
2008-04-30 06:20:20 +08:00
|
|
|
/* Turn off statistics ASAP. We update dev->stats below. */
|
2005-04-17 06:20:36 +08:00
|
|
|
outw(StatsDisable, ioaddr + EL3_CMD);
|
2010-03-31 10:42:10 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Disable the receiver and transmitter. */
|
|
|
|
outw(RxDisable, ioaddr + EL3_CMD);
|
|
|
|
outw(TxDisable, ioaddr + EL3_CMD);
|
2010-03-31 10:42:10 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
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);
|
|
|
|
}
|
2010-03-31 10:42:10 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Switching back to window 0 disables the IRQ. */
|
|
|
|
EL3WINDOW(0);
|
|
|
|
/* But we explicitly zero the IRQ line select anyway. */
|
|
|
|
outw(0x0f00, ioaddr + WN0_IRQ);
|
2010-03-31 10:42:10 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* 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);
|
2010-03-31 10:42:10 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-06-28 07:28:19 +08:00
|
|
|
static 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),
|
2009-05-02 10:21:26 +08:00
|
|
|
PCMCIA_MFC_DEVICE_CIS_MANF_CARD(0, 0x0101, 0x0035, "cis/3CXEM556.cis"),
|
|
|
|
PCMCIA_MFC_DEVICE_CIS_MANF_CARD(0, 0x0101, 0x003d, "cis/3CXEM556.cis"),
|
2005-06-28 07:28:19 +08:00
|
|
|
PCMCIA_DEVICE_NULL,
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(pcmcia, tc589_ids);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
static struct pcmcia_driver tc589_driver = {
|
|
|
|
.owner = THIS_MODULE,
|
2010-08-08 17:36:26 +08:00
|
|
|
.name = "3c589_cs",
|
2006-03-31 23:26:06 +08:00
|
|
|
.probe = tc589_probe,
|
2005-11-15 04:23:14 +08:00
|
|
|
.remove = tc589_detach,
|
2010-03-31 10:42:10 +08:00
|
|
|
.id_table = tc589_ids,
|
2005-11-15 04:21:18 +08:00
|
|
|
.suspend = tc589_suspend,
|
|
|
|
.resume = tc589_resume,
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static int __init init_tc589(void)
|
|
|
|
{
|
|
|
|
return pcmcia_register_driver(&tc589_driver);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit exit_tc589(void)
|
|
|
|
{
|
|
|
|
pcmcia_unregister_driver(&tc589_driver);
|
|
|
|
}
|
|
|
|
|
|
|
|
module_init(init_tc589);
|
|
|
|
module_exit(exit_tc589);
|