?? 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/ptrace.h>#include <linux/slab.h>#include <linux/string.h>#include <linux/timer.h>#include <linux/delay.h>#include <linux/ethtool.h>#include <linux/netdevice.h>#include <../drivers/net/8390.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>#include <asm/io.h>#include <asm/system.h>#include <asm/byteorder.h>#include <asm/uaccess.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 const char *if_names[] = { "auto", "10baseT", "10base2"};#ifdef PCMCIA_DEBUGstatic int pc_debug = PCMCIA_DEBUG;module_param(pc_debug, int, 0);#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_param(n, int, 0)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_param_array(hw_addr, int, NULL, 0);/*====================================================================*/static void mii_phy_probe(struct net_device *dev);static int pcnet_config(struct pcmcia_device *link);static void pcnet_release(struct pcmcia_device *link);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 const struct ethtool_ops netdev_ethtool_ops;static irqreturn_t ei_irq_wrapper(int irq, void *dev_id);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(struct pcmcia_device *link, int start_pg, int stop_pg, int cm_offset);static int setup_dma_config(struct pcmcia_device *link, int start_pg, int stop_pg);static void pcnet_detach(struct pcmcia_device *p_dev);static dev_info_t dev_info = "pcnet_cs";/*====================================================================*/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 pcmcia_device *p_dev; dev_node_t node; u_int flags; void __iomem *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;static inline pcnet_dev_t *PRIV(struct net_device *dev){ char *p = netdev_priv(dev); return (pcnet_dev_t *)(p + sizeof(struct ei_device));}/*====================================================================== pcnet_attach() creates an "instance" of the driver, allocating local data structures for one device. The device is registered with Card Services.======================================================================*/static int pcnet_probe(struct pcmcia_device *link){ pcnet_dev_t *info; struct net_device *dev; DEBUG(0, "pcnet_attach()\n"); /* Create new ethernet device */ dev = __alloc_ei_netdev(sizeof(pcnet_dev_t)); if (!dev) return -ENOMEM; info = PRIV(dev); info->p_dev = link; link->priv = dev; link->irq.Attributes = IRQ_TYPE_EXCLUSIVE; link->irq.IRQInfo1 = IRQ_LEVEL_ID; link->conf.Attributes = CONF_ENABLE_IRQ; link->conf.IntType = INT_MEMORY_AND_IO; SET_MODULE_OWNER(dev); dev->open = &pcnet_open; dev->stop = &pcnet_close; dev->set_config = &set_config; return pcnet_config(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(struct pcmcia_device *link){ struct net_device *dev = link->priv; DEBUG(0, "pcnet_detach(0x%p)\n", link); if (link->dev_node) unregister_netdev(dev); pcnet_release(link); free_netdev(dev);} /* 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(struct pcmcia_device *link){ struct net_device *dev = link->priv; win_req_t req; memreq_t mem; u_char __iomem *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; i = pcmcia_request_window(&link, &req, &link->win); if (i != CS_SUCCESS) { cs_error(link, 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); pcmcia_map_mem_page(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)); } iounmap(virt); j = pcmcia_release_window(link->win); if (j != CS_SUCCESS) cs_error(link, ReleaseWindow, j); return (i < NR_INFO) ? hw_info+i : NULL;} /* get_hwinfo *//*====================================================================== This probes for a card's hardware address by reading the PROM. It checks the address against a list of known types, then falls back to a simple NE2000 clone signature check.======================================================================*/static hw_info_t *get_prom(struct pcmcia_device *link){ struct net_device *dev = link->priv; kio_addr_t ioaddr = dev->base_addr; u_char prom[32]; int i, j; /* This is lifted straight from drivers/net/ne.c */
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -