?? pcnet_cs.c
字號:
/*====================================================================== A PCMCIA ethernet driver for NS8390-based cards This driver supports the D-Link DE-650 and Linksys EthernetCard cards, the newer D-Link and Linksys combo cards, Accton EN2212 cards, the RPTI EP400, and the PreMax PE-200 in non-shared-memory mode, and the IBM Credit Card Adapter, the NE4100, the Thomas Conrad ethernet card, and the Kingston KNE-PCM/x in shared-memory mode. It will also handle the Socket EA card in either mode. Copyright (C) 1999 David A. Hinds -- dahinds@users.sourceforge.net pcnet_cs.c 1.153 2003/11/09 18:53:09 The network driver code is based on Donald Becker's NE2000 code: Written 1992,1993 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 Based also on Keith Moore's changes to Don Becker's code, for IBM CCAE support. Drivers merged back together, and shared-memory Socket EA support added, by Ken Raeburn, September 1995.======================================================================*/#include <linux/kernel.h>#include <linux/module.h>#include <linux/init.h>#include <linux/sched.h>#include <linux/ptrace.h>#include <linux/slab.h>#include <linux/string.h>#include <linux/timer.h>#include <linux/delay.h>#include <linux/ethtool.h>#include <asm/io.h>#include <asm/system.h>#include <asm/byteorder.h>#include <asm/uaccess.h>#include <linux/netdevice.h>#include <../drivers/net/8390.h>#include <pcmcia/version.h>#include <pcmcia/cs_types.h>#include <pcmcia/cs.h>#include <pcmcia/cistpl.h>#include <pcmcia/ciscode.h>#include <pcmcia/ds.h>#include <pcmcia/cisreg.h>#define PCNET_CMD 0x00#define PCNET_DATAPORT 0x10 /* NatSemi-defined port window offset. */#define PCNET_RESET 0x1f /* Issue a read to reset, a write to clear. */#define PCNET_MISC 0x18 /* For IBM CCAE and Socket EA cards */#define PCNET_START_PG 0x40 /* First page of TX buffer */#define PCNET_STOP_PG 0x80 /* Last page +1 of RX ring *//* Socket EA cards have a larger packet buffer */#define SOCKET_START_PG 0x01#define SOCKET_STOP_PG 0xff#define PCNET_RDC_TIMEOUT (2*HZ/100) /* Max wait in jiffies for Tx RDC */static char *if_names[] = { "auto", "10baseT", "10base2"};#ifdef PCMCIA_DEBUGstatic int pc_debug = PCMCIA_DEBUG;MODULE_PARM(pc_debug, "i");#define DEBUG(n, args...) if (pc_debug>(n)) printk(KERN_DEBUG args)static char *version ="pcnet_cs.c 1.153 2003/11/09 18:53:09 (David Hinds)";#else#define DEBUG(n, args...)#endif/*====================================================================*//* Module parameters */MODULE_AUTHOR("David Hinds <dahinds@users.sourceforge.net>");MODULE_DESCRIPTION("NE2000 compatible PCMCIA ethernet driver");MODULE_LICENSE("GPL");#define INT_MODULE_PARM(n, v) static int n = v; MODULE_PARM(n, "i")/* Bit map of interrupts to choose from */INT_MODULE_PARM(irq_mask, 0xdeb8);static int irq_list[4] = { -1 };MODULE_PARM(irq_list, "1-4i");INT_MODULE_PARM(if_port, 1); /* Transceiver type */INT_MODULE_PARM(use_big_buf, 1); /* use 64K packet buffer? */INT_MODULE_PARM(mem_speed, 0); /* shared mem speed, in ns */INT_MODULE_PARM(delay_output, 0); /* pause after xmit? */INT_MODULE_PARM(delay_time, 4); /* in usec */INT_MODULE_PARM(use_shmem, -1); /* use shared memory? */INT_MODULE_PARM(full_duplex, 0); /* full duplex? *//* Ugh! Let the user hardwire the hardware address for queer cards */static int hw_addr[6] = { 0, /* ... */ };MODULE_PARM(hw_addr, "6i");/*====================================================================*/static void mii_phy_probe(struct net_device *dev);static void pcnet_config(dev_link_t *link);static void pcnet_release(u_long arg);static int pcnet_event(event_t event, int priority, event_callback_args_t *args);static int pcnet_open(struct net_device *dev);static int pcnet_close(struct net_device *dev);static int ei_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);static struct ethtool_ops netdev_ethtool_ops;static void ei_irq_wrapper(int irq, void *dev_id, struct pt_regs *regs);static void ei_watchdog(u_long arg);static void pcnet_reset_8390(struct net_device *dev);static int set_config(struct net_device *dev, struct ifmap *map);static int setup_shmem_window(dev_link_t *link, int start_pg, int stop_pg, int cm_offset);static int setup_dma_config(dev_link_t *link, int start_pg, int stop_pg);static dev_link_t *pcnet_attach(void);static void pcnet_detach(dev_link_t *);static dev_info_t dev_info = "pcnet_cs";static dev_link_t *dev_list;/*====================================================================*/typedef struct hw_info_t { u_int offset; u_char a0, a1, a2; u_int flags;} hw_info_t;#define DELAY_OUTPUT 0x01#define HAS_MISC_REG 0x02#define USE_BIG_BUF 0x04#define HAS_IBM_MISC 0x08#define IS_DL10019 0x10#define IS_DL10022 0x20#define HAS_MII 0x40#define USE_SHMEM 0x80 /* autodetected */#define AM79C9XX_HOME_PHY 0x00006B90 /* HomePNA PHY */#define AM79C9XX_ETH_PHY 0x00006B70 /* 10baseT PHY */#define MII_PHYID_REV_MASK 0xfffffff0#define MII_PHYID_REG1 0x02#define MII_PHYID_REG2 0x03static hw_info_t hw_info[] = { { /* Accton EN2212 */ 0x0ff0, 0x00, 0x00, 0xe8, DELAY_OUTPUT }, { /* Allied Telesis LA-PCM */ 0x0ff0, 0x00, 0x00, 0xf4, 0 }, { /* APEX MultiCard */ 0x03f4, 0x00, 0x20, 0xe5, 0 }, { /* ASANTE FriendlyNet */ 0x4910, 0x00, 0x00, 0x94, DELAY_OUTPUT | HAS_IBM_MISC }, { /* Danpex EN-6200P2 */ 0x0110, 0x00, 0x40, 0xc7, 0 }, { /* DataTrek NetCard */ 0x0ff0, 0x00, 0x20, 0xe8, 0 }, { /* Dayna CommuniCard E */ 0x0110, 0x00, 0x80, 0x19, 0 }, { /* D-Link DE-650 */ 0x0040, 0x00, 0x80, 0xc8, 0 }, { /* EP-210 Ethernet */ 0x0110, 0x00, 0x40, 0x33, 0 }, { /* EP4000 Ethernet */ 0x01c0, 0x00, 0x00, 0xb4, 0 }, { /* Epson EEN10B */ 0x0ff0, 0x00, 0x00, 0x48, HAS_MISC_REG | HAS_IBM_MISC }, { /* ELECOM Laneed LD-CDWA */ 0xb8, 0x08, 0x00, 0x42, 0 }, { /* Hypertec Ethernet */ 0x01c0, 0x00, 0x40, 0x4c, 0 }, { /* IBM CCAE */ 0x0ff0, 0x08, 0x00, 0x5a, HAS_MISC_REG | HAS_IBM_MISC }, { /* IBM CCAE */ 0x0ff0, 0x00, 0x04, 0xac, HAS_MISC_REG | HAS_IBM_MISC }, { /* IBM CCAE */ 0x0ff0, 0x00, 0x06, 0x29, HAS_MISC_REG | HAS_IBM_MISC }, { /* IBM FME */ 0x0374, 0x08, 0x00, 0x5a, HAS_MISC_REG | HAS_IBM_MISC }, { /* IBM FME */ 0x0374, 0x00, 0x04, 0xac, HAS_MISC_REG | HAS_IBM_MISC }, { /* Kansai KLA-PCM/T */ 0x0ff0, 0x00, 0x60, 0x87, HAS_MISC_REG | HAS_IBM_MISC }, { /* NSC DP83903 */ 0x0374, 0x08, 0x00, 0x17, HAS_MISC_REG | HAS_IBM_MISC }, { /* NSC DP83903 */ 0x0374, 0x00, 0xc0, 0xa8, HAS_MISC_REG | HAS_IBM_MISC }, { /* NSC DP83903 */ 0x0374, 0x00, 0xa0, 0xb0, HAS_MISC_REG | HAS_IBM_MISC }, { /* NSC DP83903 */ 0x0198, 0x00, 0x20, 0xe0, HAS_MISC_REG | HAS_IBM_MISC }, { /* I-O DATA PCLA/T */ 0x0ff0, 0x00, 0xa0, 0xb0, 0 }, { /* Katron PE-520 */ 0x0110, 0x00, 0x40, 0xf6, 0 }, { /* Kingston KNE-PCM/x */ 0x0ff0, 0x00, 0xc0, 0xf0, HAS_MISC_REG | HAS_IBM_MISC }, { /* Kingston KNE-PCM/x */ 0x0ff0, 0xe2, 0x0c, 0x0f, HAS_MISC_REG | HAS_IBM_MISC }, { /* Kingston KNE-PC2 */ 0x0180, 0x00, 0xc0, 0xf0, 0 }, { /* Maxtech PCN2000 */ 0x5000, 0x00, 0x00, 0xe8, 0 }, { /* NDC Instant-Link */ 0x003a, 0x00, 0x80, 0xc6, 0 }, { /* NE2000 Compatible */ 0x0ff0, 0x00, 0xa0, 0x0c, 0 }, { /* Network General Sniffer */ 0x0ff0, 0x00, 0x00, 0x65, HAS_MISC_REG | HAS_IBM_MISC }, { /* Panasonic VEL211 */ 0x0ff0, 0x00, 0x80, 0x45, HAS_MISC_REG | HAS_IBM_MISC }, { /* PreMax PE-200 */ 0x07f0, 0x00, 0x20, 0xe0, 0 }, { /* RPTI EP400 */ 0x0110, 0x00, 0x40, 0x95, 0 }, { /* SCM Ethernet */ 0x0ff0, 0x00, 0x20, 0xcb, 0 }, { /* Socket EA */ 0x4000, 0x00, 0xc0, 0x1b, DELAY_OUTPUT | HAS_MISC_REG | USE_BIG_BUF }, { /* Socket LP-E CF+ */ 0x01c0, 0x00, 0xc0, 0x1b, 0 }, { /* SuperSocket RE450T */ 0x0110, 0x00, 0xe0, 0x98, 0 }, { /* Volktek NPL-402CT */ 0x0060, 0x00, 0x40, 0x05, 0 }, { /* NEC PC-9801N-J12 */ 0x0ff0, 0x00, 0x00, 0x4c, 0 }, { /* PCMCIA Technology OEM */ 0x01c8, 0x00, 0xa0, 0x0c, 0 }};#define NR_INFO (sizeof(hw_info)/sizeof(hw_info_t))static hw_info_t default_info = { 0, 0, 0, 0, 0 };static hw_info_t dl10019_info = { 0, 0, 0, 0, IS_DL10019|HAS_MII };static hw_info_t dl10022_info = { 0, 0, 0, 0, IS_DL10022|HAS_MII };typedef struct pcnet_dev_t { struct net_device dev; /* so &dev == &pcnet_dev_t */ dev_link_t link; dev_node_t node; u_int flags; caddr_t base; struct timer_list watchdog; int stale, fast_poll; u_char phy_id; u_char eth_phy, pna_phy; u_short link_status; u_long mii_reset;} pcnet_dev_t;/*====================================================================== This bit of code is used to avoid unregistering network devices at inappropriate times. 2.2 and later kernels are fairly picky about when this can happen. ======================================================================*/static void flush_stale_links(void){ dev_link_t *link, *next; for (link = dev_list; link; link = next) { next = link->next; if (link->state & DEV_STALE_LINK) pcnet_detach(link); }}/*====================================================================*/static void cs_error(client_handle_t handle, int func, int ret){ error_info_t err = { func, ret }; CardServices(ReportError, handle, &err);}/*====================================================================== We never need to do anything when a pcnet device is "initialized" by the net software, because we only register already-found cards.======================================================================*/static int pcnet_init(struct net_device *dev){ return 0;}/*====================================================================== pcnet_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 *pcnet_attach(void){ pcnet_dev_t *info; dev_link_t *link; struct net_device *dev; client_reg_t client_reg; int i, ret; DEBUG(0, "pcnet_attach()\n"); flush_stale_links(); /* Create new ethernet device */ info = kmalloc(sizeof(*info), GFP_KERNEL); if (!info) return NULL; memset(info, 0, sizeof(*info)); link = &info->link; dev = &info->dev; link->priv = info; init_timer(&link->release); link->release.function = &pcnet_release; link->release.data = (u_long)link; link->irq.Attributes = IRQ_TYPE_EXCLUSIVE; link->irq.IRQInfo1 = IRQ_INFO2_VALID|IRQ_LEVEL_ID; if (irq_list[0] == -1) link->irq.IRQInfo2 = irq_mask; else for (i = 0; i < 4; i++) link->irq.IRQInfo2 |= 1 << irq_list[i]; link->conf.Attributes = CONF_ENABLE_IRQ; link->conf.IntType = INT_MEMORY_AND_IO; ethdev_init(dev); dev->init = &pcnet_init; dev->open = &pcnet_open; dev->stop = &pcnet_close; dev->set_config = &set_config; /* Register with Card Services */ link->next = dev_list; dev_list = link; client_reg.dev_info = &dev_info; client_reg.Attributes = INFO_IO_CLIENT | INFO_CARD_SHARE; 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 = &pcnet_event; client_reg.Version = 0x0210; client_reg.event_callback_args.client_data = link; ret = CardServices(RegisterClient, &link->handle, &client_reg); if (ret != CS_SUCCESS) { cs_error(link->handle, RegisterClient, ret); pcnet_detach(link); return NULL; } return link;} /* pcnet_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 pcnet_detach(dev_link_t *link){ pcnet_dev_t *info = link->priv; dev_link_t **linkp; DEBUG(0, "pcnet_detach(0x%p)\n", link); /* Locate device structure */ for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next) if (*linkp == link) break; if (*linkp == NULL) return; del_timer(&link->release); if (link->state & DEV_CONFIG) { pcnet_release((u_long)link); if (link->state & DEV_STALE_CONFIG) { link->state |= DEV_STALE_LINK; return; } } if (link->handle) CardServices(DeregisterClient, link->handle); /* Unlink device structure, free bits */ *linkp = link->next; if (link->dev) unregister_netdev(&info->dev); kfree(info);} /* pcnet_detach *//*====================================================================== This probes for a card's hardware address, for card types that encode this information in their CIS.======================================================================*/static hw_info_t *get_hwinfo(dev_link_t *link){ struct net_device *dev = link->priv; win_req_t req; memreq_t mem; u_char *base, *virt; int i, j; /* Allocate a small memory window */ req.Attributes = WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_AM|WIN_ENABLE; req.Base = 0; req.Size = 0; req.AccessSpeed = 0; link->win = (window_handle_t)link->handle; i = CardServices(RequestWindow, &link->win, &req); if (i != CS_SUCCESS) { cs_error(link->handle, RequestWindow, i); return NULL; } virt = ioremap(req.Base, req.Size); mem.Page = 0; for (i = 0; i < NR_INFO; i++) { mem.CardOffset = hw_info[i].offset & ~(req.Size-1); CardServices(MapMemPage, link->win, &mem); base = &virt[hw_info[i].offset & (req.Size-1)]; if ((readb(base+0) == hw_info[i].a0) && (readb(base+2) == hw_info[i].a1) && (readb(base+4) == hw_info[i].a2)) break; } if (i < NR_INFO) { for (j = 0; j < 6; j++) dev->dev_addr[j] = readb(base + (j<<1)); }
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -