⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 com20020_cs.c

📁 内核linux2.4.20,可跟rtlinux3.2打补丁 组成实时linux系统,编译内核
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * Linux ARCnet driver - COM20020 PCMCIA support *  * Written 1994-1999 by Avery Pennarun, *    based on an ISA version by David Woodhouse. * Derived from ibmtr_cs.c by Steve Kipisz (pcmcia-cs 3.1.4) *    which was derived from pcnet_cs.c by David Hinds. * Some additional portions derived from skeleton.c by Donald Becker. * * Special thanks to Contemporary Controls, Inc. (www.ccontrols.com) *  for sponsoring the further development of this driver. * * ********************** * * The original copyright of skeleton.c was as follows: * * skeleton.c Written 1993 by Donald Becker. * Copyright 1993 United States Government as represented by the * Director, National Security Agency.  This software may only be used * and distributed according to the terms of the GNU General Public License as * modified by SRC, incorporated herein by reference. *  * ********************** * Changes: * Arnaldo Carvalho de Melo <acme@conectiva.com.br> - 08/08/2000 * - reorganize kmallocs in com20020_attach, checking all for failure *   and releasing the previous allocations if one fails * ********************** *  * For more details, see drivers/net/arcnet.c * * ********************** */#include <linux/kernel.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/module.h>#include <asm/io.h>#include <asm/system.h>#include <linux/netdevice.h>#include <linux/arcdevice.h>#include <linux/com20020.h>#include <pcmcia/version.h>#include <pcmcia/cs_types.h>#include <pcmcia/cs.h>#include <pcmcia/cistpl.h>#include <pcmcia/ds.h>#define VERSION "arcnet: COM20020 PCMCIA support loaded.\n"#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 void regdump(struct net_device *dev){    int ioaddr = dev->base_addr;    int count;        printk("com20020 register dump:\n");    for (count = ioaddr; count < ioaddr + 16; count++)    {	if (!(count % 16))	    printk("\n%04X: ", count);	printk("%02X ", inb(count));    }    printk("\n");        printk("buffer0 dump:\n");	/* set up the address register */        count = 0;	outb((count >> 8) | RDDATAflag | AUTOINCflag, _ADDR_HI);	outb(count & 0xff, _ADDR_LO);        for (count = 0; count < 256+32; count++)    {	if (!(count % 16))	    printk("\n%04X: ", count);		/* copy the data */	printk("%02X ", inb(_MEMDATA));    }    printk("\n");}#else#define DEBUG(n, args...) do { } while (0)static inline void regdump(struct net_device *dev) { }#endif/*====================================================================*//* Parameters that can be set with 'insmod' */static int node;static int timeout = 3;static int backplane;static int clockp;static int clockm;MODULE_PARM(node, "i");MODULE_PARM(timeout, "i");MODULE_PARM(backplane, "i");MODULE_PARM(clockp, "i");MODULE_PARM(clockm, "i");/* Bit map of interrupts to choose from */static u_int irq_mask = 0xdeb8;static int irq_list[4] = { -1 };MODULE_PARM(irq_mask, "i");MODULE_PARM(irq_list, "1-4i");/*====================================================================*/static void com20020_config(dev_link_t *link);static void com20020_release(u_long arg);static int com20020_event(event_t event, int priority,                       event_callback_args_t *args);static dev_info_t dev_info = "com20020_cs";static dev_link_t *com20020_attach(void);static void com20020_detach(dev_link_t *);static dev_link_t *dev_list;/*====================================================================*/typedef struct com20020_dev_t {    struct net_device       *dev;    int dev_configured;    dev_node_t          node;} com20020_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)	    com20020_detach(link);    }}/*====================================================================*/static void cs_error(client_handle_t handle, int func, int ret){    error_info_t err = { func, ret };    CardServices(ReportError, handle, &err);}/*======================================================================    com20020_attach() creates an "instance" of the driver, allocating    local data structures for one device.  The device is registered    with Card Services.======================================================================*/static void com20020cs_open_close(struct net_device *dev, bool open){    if (open)	MOD_INC_USE_COUNT;    else	MOD_DEC_USE_COUNT;}static dev_link_t *com20020_attach(void){    client_reg_t client_reg;    dev_link_t *link;    com20020_dev_t *info;    struct net_device *dev;    int i, ret;    struct arcnet_local *lp;        DEBUG(0, "com20020_attach()\n");    flush_stale_links();    /* Create new network device */    link = kmalloc(sizeof(struct dev_link_t), GFP_KERNEL);    if (!link)	return NULL;    info = kmalloc(sizeof(struct com20020_dev_t), GFP_KERNEL);    if (!info)	goto fail_alloc_info;    lp =  kmalloc(sizeof(struct arcnet_local), GFP_KERNEL);    if (!lp)	goto fail_alloc_lp;    dev = dev_alloc("arc%d", &ret);    if (!dev)	goto fail_alloc_dev;    memset(info, 0, sizeof(struct com20020_dev_t));    memset(lp, 0, sizeof(struct arcnet_local));    memset(link, 0, sizeof(struct dev_link_t));    dev->priv = lp;    link->release.function = &com20020_release;    link->release.data = (u_long)link;    link->io.Attributes1 = IO_DATA_PATH_WIDTH_8;    link->io.NumPorts1 = 16;    link->io.IOAddrLines = 16;    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.Vcc = 50;    link->conf.IntType = INT_MEMORY_AND_IO;    link->conf.Present = PRESENT_OPTION;    /* fill in our module parameters as defaults */    dev->dev_addr[0] = node;    lp->timeout = timeout;    lp->backplane = backplane;    lp->clockp = clockp;    lp->clockm = clockm & 3;    lp->hw.open_close_ll = com20020cs_open_close;    link->irq.Instance = info->dev = dev;    link->priv = info;    /* 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 = &com20020_event;    client_reg.Version = 0x0210;    client_reg.event_callback_args.client_data = link;    ret = CardServices(RegisterClient, &link->handle, &client_reg);    if (ret != 0) {        cs_error(link->handle, RegisterClient, ret);        com20020_detach(link);        return NULL;    }    return link;fail_alloc_dev:    kfree(lp);fail_alloc_lp:    kfree(info);fail_alloc_info:    kfree(link);    return NULL;} /* com20020_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 com20020_detach(dev_link_t *link){    struct com20020_dev_t *info = link->priv;    dev_link_t **linkp;    struct net_device *dev;         DEBUG(1,"detach...\n");

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -