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

📄 pcnet_cs.c

📁 ARM S3C2410 linux2.4 内核源码
💻 C
📖 第 1 页 / 共 4 页
字号:
    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));    }        iounmap(virt);    j = CardServices(ReleaseWindow, link->win);    if (j != CS_SUCCESS)	cs_error(link->handle, 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(dev_link_t *link){    struct net_device *dev = link->priv;    ioaddr_t ioaddr = dev->base_addr;    u_char prom[32];    int i, j;    /* This is lifted straight from drivers/net/ne.c */    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(dev_link_t *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(dev_link_t *link){    struct net_device *dev = link->priv;    ioaddr_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(dev_link_t *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, args...) \while ((last_ret=CardServices(last_fn=(fn), args))!=0) goto cs_failed#define CFG_CHECK(fn, args...) \if (CardServices(fn, args) != 0) goto next_entrystatic int try_io_port(dev_link_t *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 = CardServices(RequestIO, link->handle, &link->io);	    if (ret == CS_SUCCESS) return ret;	}	return ret;    } else {	return CardServices(RequestIO, link->handle, &link->io);    }}static void pcnet_config(dev_link_t *link){    client_handle_t handle = link->handle;    pcnet_dev_t *info = link->priv;    struct net_device *dev = &info->dev;    tuple_t tuple;    cisparse_t parse;    int i, last_ret, last_fn, start_pg, stop_pg, cm_offset;    int manfid = 0, prodid = 0, has_shmem = 0;    u_short buf[64];    config_info_t conf;    hw_info_t *hw_info;    DEBUG(0, "pcnet_config(0x%p)\n", link);    tuple.Attributes = 0;    tuple.TupleData = (cisdata_t *)buf;    tuple.TupleDataMax = sizeof(buf);    tuple.TupleOffset = 0;    tuple.DesiredTuple = CISTPL_CONFIG;    CS_CHECK(GetFirstTuple, handle, &tuple);    CS_CHECK(GetTupleData, handle, &tuple);    CS_CHECK(ParseTuple, handle, &tuple, &parse);    link->conf.ConfigBase = parse.config.base;    link->conf.Present = parse.config.rmask[0];    /* Configure card */    link->state |= DEV_CONFIG;    /* Look up current Vcc */    CS_CHECK(GetConfigurationInfo, handle, &conf);    link->conf.Vcc = conf.Vcc;    tuple.DesiredTuple = CISTPL_MANFID;    tuple.Attributes = TUPLE_RETURN_COMMON;    if ((CardServices(GetFirstTuple, handle, &tuple) == CS_SUCCESS) && 	(CardServices(GetTupleData, handle, &tuple) == CS_SUCCESS)) {	manfid = le16_to_cpu(buf[0]);	prodid = le16_to_cpu(buf[1]);    }        tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;    tuple.Attributes = 0;    CS_CHECK(GetFirstTuple, handle, &tuple);    while (last_ret == CS_SUCCESS) {	cistpl_cftable_entry_t *cfg = &(parse.cftable_entry);	cistpl_io_t *io = &(parse.cftable_entry.io);		CFG_CHECK(GetTupleData, handle, &tuple);	CFG_CHECK(ParseTuple, handle, &tuple, &parse);	if ((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 = CardServices(GetNextTuple, handle, &tuple);    }    if (last_ret != CS_SUCCESS) {	cs_error(handle, RequestIO, last_ret);	goto failed;    }    CS_CHECK(RequestIRQ, handle, &link->irq);        if (link->io.NumPorts2 == 8) {	link->conf.Attributes |= CONF_ENABLE_SPKR;	link->conf.Status = CCSR_AUDIO_ENA;    }    if ((manfid == MANFID_IBM) &&	(prodid == PRODID_IBM_HOME_AND_AWAY))	link->conf.ConfigIndex |= 0x10;        CS_CHECK(RequestConfiguration, handle, &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;    }    if (register_netdev(dev) != 0) {	printk(KERN_NOTICE "pcnet_cs: register_netdev() failed\n");	goto failed;    }    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);	unregister_netdev(dev);	goto failed;    }    info->flags = hw_info->flags;    /* Check for user overrides */    info->flags |= (delay_output) ? DELAY_OUTPUT : 0;    if ((manfid == MANFID_SOCKET) &&	((prodid == PRODID_SOCKET_LPE) ||	 (prodid == PRODID_SOCKET_LPE_CF) ||	 (prodid == 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;    strcpy(info->node.dev_name, dev->name);    link->dev = &info->node;    link->state &= ~DEV_CONFIG_PENDING;    if (info->flags & (IS_DL10019|IS_DL10022)) {	u_char id = inb(dev->base_addr + 0x1a);	dev->do_ioctl = &ei_ioctl;	mii_phy_probe(dev);	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;cs_failed:    cs_error(link->handle, last_fn, last_ret);failed:    pcnet_release((u_long)link);    return;} /* 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.======================================================================*/

⌨️ 快捷键说明

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