📄 3c589_cs.c
字号:
/*====================================================================== 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@redhat.com>======================================================================*/#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 <pcmcia/version.h>#include <pcmcia/cs_types.h>#include <pcmcia/cs.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>#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 { 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 { dev_link_t link; dev_node_t node; struct net_device_stats stats; /* For transceiver monitoring */ struct timer_list media; u16 media_status; u16 fast_poll; unsigned long last_irq; spinlock_t lock;};static 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);#ifdef PCMCIA_DEBUGINT_MODULE_PARM(pc_debug, PCMCIA_DEBUG);#define DEBUG(n, args...) if (pc_debug>(n)) printk(KERN_DEBUG args)static char *version =DRV_NAME ".c " DRV_VERSION " 2001/10/13 00:08:50 (David Hinds)";#else#define DEBUG(n, args...)#endif/*====================================================================*/static void tc589_config(dev_link_t *link);static void tc589_release(dev_link_t *link);static int tc589_event(event_t event, int priority, event_callback_args_t *args);static u16 read_eeprom(kio_addr_t 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 int el3_start_xmit(struct sk_buff *skb, struct net_device *dev);static irqreturn_t el3_interrupt(int irq, void *dev_id, struct pt_regs *regs);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_multicast_list(struct net_device *dev);static struct ethtool_ops netdev_ethtool_ops;static dev_info_t dev_info = "3c589_cs";static dev_link_t *tc589_attach(void);static void tc589_detach(dev_link_t *);static dev_link_t *dev_list;/*====================================================================== tc589_attach() creates an "instance" of the driver, allocating local data structures for one device. The device is registered with Card Services.======================================================================*/static dev_link_t *tc589_attach(void){ struct el3_private *lp; client_reg_t client_reg; dev_link_t *link; struct net_device *dev; int ret; DEBUG(0, "3c589_attach()\n"); /* Create new ethernet device */ dev = alloc_etherdev(sizeof(struct el3_private)); if (!dev) return NULL; lp = netdev_priv(dev); link = &lp->link; link->priv = dev; spin_lock_init(&lp->lock); link->io.NumPorts1 = 16; link->io.Attributes1 = IO_DATA_PATH_WIDTH_16; link->irq.Attributes = IRQ_TYPE_EXCLUSIVE | IRQ_HANDLE_PRESENT; link->irq.IRQInfo1 = IRQ_LEVEL_ID; link->irq.Handler = &el3_interrupt; link->irq.Instance = dev; link->conf.Attributes = CONF_ENABLE_IRQ; link->conf.Vcc = 50; link->conf.IntType = INT_MEMORY_AND_IO; link->conf.ConfigIndex = 1; link->conf.Present = PRESENT_OPTION; /* The EL3-specific entries in the device structure. */ SET_MODULE_OWNER(dev); dev->hard_start_xmit = &el3_start_xmit; dev->set_config = &el3_config; dev->get_stats = &el3_get_stats; dev->set_multicast_list = &set_multicast_list; dev->open = &el3_open; dev->stop = &el3_close;#ifdef HAVE_TX_TIMEOUT dev->tx_timeout = el3_tx_timeout; dev->watchdog_timeo = TX_TIMEOUT;#endif SET_ETHTOOL_OPS(dev, &netdev_ethtool_ops); /* Register with Card Services */ link->next = dev_list; dev_list = link; client_reg.dev_info = &dev_info; client_reg.EventMask = CS_EVENT_CARD_INSERTION | CS_EVENT_CARD_REMOVAL | CS_EVENT_RESET_PHYSICAL | CS_EVENT_CARD_RESET | CS_EVENT_PM_SUSPEND | CS_EVENT_PM_RESUME; client_reg.event_handler = &tc589_event; client_reg.Version = 0x0210; client_reg.event_callback_args.client_data = link; ret = pcmcia_register_client(&link->handle, &client_reg); if (ret != 0) { cs_error(link->handle, RegisterClient, ret); tc589_detach(link); return NULL; } return link;} /* tc589_attach *//*====================================================================== This deletes a driver "instance". The device is de-registered with Card Services. If it has been released, all local data structures are freed. Otherwise, the structures will be freed when the device is released.======================================================================*/static void tc589_detach(dev_link_t *link){ struct net_device *dev = link->priv; dev_link_t **linkp; DEBUG(0, "3c589_detach(0x%p)\n", link); /* Locate device structure */ for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next) if (*linkp == link) break; if (*linkp == NULL) return; if (link->dev) unregister_netdev(dev); if (link->state & DEV_CONFIG) tc589_release(link); if (link->handle) pcmcia_deregister_client(link->handle); /* Unlink device structure, free bits */ *linkp = link->next; free_netdev(dev);} /* tc589_detach *//*====================================================================== tc589_config() is scheduled to run after a CARD_INSERTION event is received, to configure the PCMCIA socket, and to make the ethernet device available to the system. ======================================================================*/#define CS_CHECK(fn, ret) \do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)static void tc589_config(dev_link_t *link){ client_handle_t handle = link->handle; struct net_device *dev = link->priv; struct el3_private *lp = netdev_priv(dev); tuple_t tuple; cisparse_t parse; u16 buf[32], *phys_addr; int last_fn, last_ret, i, j, multi = 0, fifo; kio_addr_t ioaddr; char *ram_split[] = {"5:3", "3:1", "1:1", "3:5"}; DEBUG(0, "3c589_config(0x%p)\n", link); phys_addr = (u16 *)dev->dev_addr; tuple.Attributes = 0; tuple.DesiredTuple = CISTPL_CONFIG; CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); tuple.TupleData = (cisdata_t *)buf; tuple.TupleDataMax = sizeof(buf); tuple.TupleOffset = 0; CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple)); CS_CHECK(ParseTuple, pcmcia_parse_tuple(handle, &tuple, &parse)); link->conf.ConfigBase = parse.config.base; link->conf.Present = parse.config.rmask[0]; /* Is this a 3c562? */ tuple.DesiredTuple = CISTPL_MANFID; tuple.Attributes = TUPLE_RETURN_COMMON; if ((pcmcia_get_first_tuple(handle, &tuple) == CS_SUCCESS) && (pcmcia_get_tuple_data(handle, &tuple) == CS_SUCCESS)) { if (le16_to_cpu(buf[0]) != MANFID_3COM) printk(KERN_INFO "3c589_cs: hmmm, is this really a " "3Com card??\n"); multi = (le16_to_cpu(buf[1]) == PRODID_3COM_3C562); } /* Configure card */ link->state |= DEV_CONFIG; /* For the 3c562, the base address must be xx00-xx7f */ link->io.IOAddrLines = 16; for (i = j = 0; j < 0x400; j += 0x10) { if (multi && (j & 0x80)) continue; link->io.BasePort1 = j ^ 0x300; i = pcmcia_request_io(link->handle, &link->io); if (i == CS_SUCCESS) break; } if (i != CS_SUCCESS) { cs_error(link->handle, RequestIO, i); goto failed; } CS_CHECK(RequestIRQ, pcmcia_request_irq(link->handle, &link->irq)); CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link->handle, &link->conf)); dev->irq = link->irq.AssignedIRQ; dev->base_addr = link->io.BasePort1; 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. */ tuple.DesiredTuple = 0x88; if (pcmcia_get_first_tuple(handle, &tuple) == CS_SUCCESS) { pcmcia_get_tuple_data(handle, &tuple); for (i = 0; i < 3; i++) phys_addr[i] = htons(buf[i]); } else { for (i = 0; i < 3; i++)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -