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

📄 pcnet_cs.c

📁 pcmcia驱动源代码,直接可以在linux2.6下使用 !
💻 C
📖 第 1 页 / 共 5 页
字号:
    struct {	u_char value, offset;    } program_seq[] = {	{E8390_NODMA+E8390_PAGE0+E8390_STOP, E8390_CMD}, /* Select page 0*/	{0x48,	EN0_DCFG},	/* Set byte-wide (0x48) access. */	{0x00,	EN0_RCNTLO},	/* Clear the count regs. */	{0x00,	EN0_RCNTHI},	{0x00,	EN0_IMR},	/* Mask completion irq. */	{0xFF,	EN0_ISR},	{E8390_RXOFF, EN0_RXCR},	/* 0x20  Set to monitor */	{E8390_TXOFF, EN0_TXCR},	/* 0x02  and loopback mode. */	{32,	EN0_RCNTLO},	{0x00,	EN0_RCNTHI},	{0x00,	EN0_RSARLO},	/* DMA starting at 0x0000. */	{0x00,	EN0_RSARHI},	{E8390_RREAD+E8390_START, E8390_CMD},    };    pcnet_reset_8390(dev);    mdelay(10);    for (i = 0; i < sizeof(program_seq)/sizeof(program_seq[0]); i++)	outb_p(program_seq[i].value, ioaddr + program_seq[i].offset);    for (i = 0; i < 32; i++)	prom[i] = inb(ioaddr + PCNET_DATAPORT);    for (i = 0; i < NR_INFO; i++) {	if ((prom[0] == hw_info[i].a0) &&	    (prom[2] == hw_info[i].a1) &&	    (prom[4] == hw_info[i].a2))	    break;    }    if ((i < NR_INFO) || ((prom[28] == 0x57) && (prom[30] == 0x57))) {	for (j = 0; j < 6; j++)	    dev->dev_addr[j] = prom[j<<1];	return (i < NR_INFO) ? hw_info+i : &default_info;    }    return NULL;} /* get_prom *//*======================================================================    For DL10019 based cards, like the Linksys EtherFast======================================================================*/static hw_info_t *get_dl10019(struct pcmcia_device *link){    struct net_device *dev = link->priv;    int i;    u_char sum;    for (sum = 0, i = 0x14; i < 0x1c; i++)	sum += inb_p(dev->base_addr + i);    if (sum != 0xff)	return NULL;    for (i = 0; i < 6; i++)	dev->dev_addr[i] = inb_p(dev->base_addr + 0x14 + i);    i = inb(dev->base_addr + 0x1f);    return ((i == 0x91)||(i == 0x99)) ? &dl10022_info : &dl10019_info;}/*======================================================================    For Asix AX88190 based cards======================================================================*/static hw_info_t *get_ax88190(struct pcmcia_device *link){    struct net_device *dev = link->priv;    kio_addr_t ioaddr = dev->base_addr;    int i, j;    /* Not much of a test, but the alternatives are messy */    if (link->conf.ConfigBase != 0x03c0)	return NULL;    outb_p(0x01, ioaddr + EN0_DCFG);	/* Set word-wide access. */    outb_p(0x00, ioaddr + EN0_RSARLO);	/* DMA starting at 0x0400. */    outb_p(0x04, ioaddr + EN0_RSARHI);    outb_p(E8390_RREAD+E8390_START, ioaddr + E8390_CMD);    for (i = 0; i < 6; i += 2) {	j = inw(ioaddr + PCNET_DATAPORT);	dev->dev_addr[i] = j & 0xff;	dev->dev_addr[i+1] = j >> 8;    }    printk(KERN_NOTICE "pcnet_cs: this is an AX88190 card!\n");    printk(KERN_NOTICE "pcnet_cs: use axnet_cs instead.\n");    return NULL;}/*======================================================================    This should be totally unnecessary... but when we can't figure    out the hardware address any other way, we'll let the user hard    wire it when the module is initialized.======================================================================*/static hw_info_t *get_hwired(struct pcmcia_device *link){    struct net_device *dev = link->priv;    int i;    for (i = 0; i < 6; i++)	if (hw_addr[i] != 0) break;    if (i == 6)	return NULL;    for (i = 0; i < 6; i++)	dev->dev_addr[i] = hw_addr[i];    return &default_info;} /* get_hwired *//*======================================================================    pcnet_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 int try_io_port(struct pcmcia_device *link){    int j, ret;    if (link->io.NumPorts1 == 32) {	link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;	if (link->io.NumPorts2 > 0) {	    /* for master/slave multifunction cards */	    link->io.Attributes2 = IO_DATA_PATH_WIDTH_8;	    link->irq.Attributes =		IRQ_TYPE_DYNAMIC_SHARING|IRQ_FIRST_SHARED;	}    } else {	/* This should be two 16-port windows */	link->io.Attributes1 = IO_DATA_PATH_WIDTH_8;	link->io.Attributes2 = IO_DATA_PATH_WIDTH_16;    }    if (link->io.BasePort1 == 0) {	link->io.IOAddrLines = 16;	for (j = 0; j < 0x400; j += 0x20) {	    link->io.BasePort1 = j ^ 0x300;	    link->io.BasePort2 = (j ^ 0x300) + 0x10;	    ret = pcmcia_request_io(link, &link->io);	    if (ret == CS_SUCCESS) return ret;	}	return ret;    } else {	return pcmcia_request_io(link, &link->io);    }}static int pcnet_config(struct pcmcia_device *link){    struct net_device *dev = link->priv;    pcnet_dev_t *info = PRIV(dev);    tuple_t tuple;    cisparse_t parse;    int i, last_ret, last_fn, start_pg, stop_pg, cm_offset;    int has_shmem = 0;    u_short buf[64];    hw_info_t *hw_info;    DEBUG(0, "pcnet_config(0x%p)\n", link);    tuple.TupleData = (cisdata_t *)buf;    tuple.TupleDataMax = sizeof(buf);    tuple.TupleOffset = 0;    tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;    tuple.Attributes = 0;    CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));    while (last_ret == CS_SUCCESS) {	cistpl_cftable_entry_t *cfg = &(parse.cftable_entry);	cistpl_io_t *io = &(parse.cftable_entry.io);	if (pcmcia_get_tuple_data(link, &tuple) != 0 ||			pcmcia_parse_tuple(link, &tuple, &parse) != 0 ||			cfg->index == 0 || cfg->io.nwin == 0)		goto next_entry;	link->conf.ConfigIndex = cfg->index;	/* For multifunction cards, by convention, we configure the	   network function with window 0, and serial with window 1 */	if (io->nwin > 1) {	    i = (io->win[1].len > io->win[0].len);	    link->io.BasePort2 = io->win[1-i].base;	    link->io.NumPorts2 = io->win[1-i].len;	} else {	    i = link->io.NumPorts2 = 0;	}	has_shmem = ((cfg->mem.nwin == 1) &&		     (cfg->mem.win[0].len >= 0x4000));	link->io.BasePort1 = io->win[i].base;	link->io.NumPorts1 = io->win[i].len;	link->io.IOAddrLines = io->flags & CISTPL_IO_LINES_MASK;	if (link->io.NumPorts1 + link->io.NumPorts2 >= 32) {	    last_ret = try_io_port(link);	    if (last_ret == CS_SUCCESS) break;	}    next_entry:	last_ret = pcmcia_get_next_tuple(link, &tuple);    }    if (last_ret != CS_SUCCESS) {	cs_error(link, RequestIO, last_ret);	goto failed;    }    CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq));    if (link->io.NumPorts2 == 8) {	link->conf.Attributes |= CONF_ENABLE_SPKR;	link->conf.Status = CCSR_AUDIO_ENA;    }    if ((link->manf_id == MANFID_IBM) &&	(link->card_id == PRODID_IBM_HOME_AND_AWAY))	link->conf.ConfigIndex |= 0x10;    CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf));    dev->irq = link->irq.AssignedIRQ;    dev->base_addr = link->io.BasePort1;    if (info->flags & HAS_MISC_REG) {	if ((if_port == 1) || (if_port == 2))	    dev->if_port = if_port;	else	    printk(KERN_NOTICE "pcnet_cs: invalid if_port requested\n");    } else {	dev->if_port = 0;    }    hw_info = get_hwinfo(link);    if (hw_info == NULL)	hw_info = get_prom(link);    if (hw_info == NULL)	hw_info = get_dl10019(link);    if (hw_info == NULL)	hw_info = get_ax88190(link);    if (hw_info == NULL)	hw_info = get_hwired(link);    if (hw_info == NULL) {	printk(KERN_NOTICE "pcnet_cs: unable to read hardware net"	       " address for io base %#3lx\n", dev->base_addr);	goto failed;    }    info->flags = hw_info->flags;    /* Check for user overrides */    info->flags |= (delay_output) ? DELAY_OUTPUT : 0;    if ((link->manf_id == MANFID_SOCKET) &&	((link->card_id == PRODID_SOCKET_LPE) ||	 (link->card_id == PRODID_SOCKET_LPE_CF) ||	 (link->card_id == PRODID_SOCKET_EIO)))	info->flags &= ~USE_BIG_BUF;    if (!use_big_buf)	info->flags &= ~USE_BIG_BUF;    if (info->flags & USE_BIG_BUF) {	start_pg = SOCKET_START_PG;	stop_pg = SOCKET_STOP_PG;	cm_offset = 0x10000;    } else {	start_pg = PCNET_START_PG;	stop_pg = PCNET_STOP_PG;	cm_offset = 0;    }    /* has_shmem is ignored if use_shmem != -1 */    if ((use_shmem == 0) || (!has_shmem && (use_shmem == -1)) ||	(setup_shmem_window(link, start_pg, stop_pg, cm_offset) != 0))	setup_dma_config(link, start_pg, stop_pg);    ei_status.name = "NE2000";    ei_status.word16 = 1;    ei_status.reset_8390 = &pcnet_reset_8390;    SET_ETHTOOL_OPS(dev, &netdev_ethtool_ops);    if (info->flags & (IS_DL10019|IS_DL10022)) {	dev->do_ioctl = &ei_ioctl;	mii_phy_probe(dev);    }    link->dev_node = &info->node;    SET_NETDEV_DEV(dev, &handle_to_dev(link));#ifdef CONFIG_NET_POLL_CONTROLLER    dev->poll_controller = ei_poll;#endif    if (register_netdev(dev) != 0) {	printk(KERN_NOTICE "pcnet_cs: register_netdev() failed\n");	link->dev_node = NULL;	goto failed;    }    strcpy(info->node.dev_name, dev->name);    if (info->flags & (IS_DL10019|IS_DL10022)) {	u_char id = inb(dev->base_addr + 0x1a);	printk(KERN_INFO "%s: NE2000 (DL100%d rev %02x): ",	       dev->name, ((info->flags & IS_DL10022) ? 22 : 19), id);	if (info->pna_phy)	    printk("PNA, ");    } else {	printk(KERN_INFO "%s: NE2000 Compatible: ", dev->name);    }    printk("io %#3lx, irq %d,", dev->base_addr, dev->irq);    if (info->flags & USE_SHMEM)	printk (" mem %#5lx,", dev->mem_start);    if (info->flags & HAS_MISC_REG)	printk(" %s xcvr,", if_names[dev->if_port]);    printk(" hw_addr ");    for (i = 0; i < 6; i++)	printk("%02X%s", dev->dev_addr[i], ((i<5) ? ":" : "\n"));    return 0;cs_failed:    cs_error(link, last_fn, last_ret);failed:    pcnet_release(link);    return -ENODEV;} /* pcnet_config *//*======================================================================    After a card is removed, pcnet_release() will unregister the net    device, and release the PCMCIA configuration.  If the device is    still open, this will be postponed until it is closed.======================================================================*/static void pcnet_release(struct pcmcia_device *link){	pcnet_dev_t *info = PRIV(link->priv);	DEBUG(0, "pcnet_release(0x%p)\n", link);	if (info->flags & USE_SHMEM)		iounmap(info->base);	pcmcia_disable_device(link);}/*======================================================================    The card status event handler.  Mostly, this schedules other    stuff to run after an event is received.  A CARD_REMOVAL event    also sets some flags to discourage the net drivers from trying    to talk to the card any more.

⌨️ 快捷键说明

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