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

📄 axnet_cs.c

📁 内核linux2.4.20,可跟rtlinux3.2打补丁 组成实时linux系统,编译内核
💻 C
📖 第 1 页 / 共 4 页
字号:
    ei_status.block_input = &block_input;    ei_status.block_output = &block_output;    strcpy(info->node.dev_name, dev->name);    link->dev = &info->node;    link->state &= ~DEV_CONFIG_PENDING;    printk(KERN_INFO "%s: Asix AX88190: io %#3lx, irq %d, hw_addr ",	   dev->name, dev->base_addr, dev->irq);    for (i = 0; i < 6; i++)	printk("%02X%s", dev->dev_addr[i], ((i<5) ? ":" : "\n"));    for (i = 0; i < 32; i++) {	j = mdio_read(dev->base_addr + AXNET_MII_EEP, i, 1);	if ((j != 0) && (j != 0xffff)) break;    }    info->phy_id = (i < 32) ? i : -1;    if (i < 32) {	DEBUG(0, "  MII transceiver at index %d, status %x.\n", i, j);    } else {	printk(KERN_NOTICE "  No MII transceivers found!\n");    }    return;cs_failed:    cs_error(link->handle, last_fn, last_ret);failed:    axnet_release((u_long)link);    return;} /* axnet_config *//*======================================================================    After a card is removed, axnet_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 axnet_release(u_long arg){    dev_link_t *link = (dev_link_t *)arg;    DEBUG(0, "axnet_release(0x%p)\n", link);    if (link->open) {	DEBUG(1, "axnet_cs: release postponed, '%s' still open\n",	      ((axnet_dev_t *)(link->priv))->node.dev_name);	link->state |= DEV_STALE_CONFIG;	return;    }    CardServices(ReleaseConfiguration, link->handle);    CardServices(ReleaseIO, link->handle, &link->io);    CardServices(ReleaseIRQ, link->handle, &link->irq);    link->state &= ~DEV_CONFIG;} /* axnet_release *//*======================================================================    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.======================================================================*/static int axnet_event(event_t event, int priority,		       event_callback_args_t *args){    dev_link_t *link = args->client_data;    axnet_dev_t *info = link->priv;    DEBUG(2, "axnet_event(0x%06x)\n", event);    switch (event) {    case CS_EVENT_CARD_REMOVAL:	link->state &= ~DEV_PRESENT;	if (link->state & DEV_CONFIG) {	    netif_device_detach(&info->dev);	    mod_timer(&link->release, jiffies + HZ/20);	}	break;    case CS_EVENT_CARD_INSERTION:	link->state |= DEV_PRESENT;	axnet_config(link);	break;    case CS_EVENT_PM_SUSPEND:	link->state |= DEV_SUSPEND;	/* Fall through... */    case CS_EVENT_RESET_PHYSICAL:	if (link->state & DEV_CONFIG) {	    if (link->open)		netif_device_detach(&info->dev);	    CardServices(ReleaseConfiguration, link->handle);	}	break;    case CS_EVENT_PM_RESUME:	link->state &= ~DEV_SUSPEND;	/* Fall through... */    case CS_EVENT_CARD_RESET:	if (link->state & DEV_CONFIG) {	    CardServices(RequestConfiguration, link->handle, &link->conf);	    if (link->open) {		axnet_reset_8390(&info->dev);		AX88190_init(&info->dev, 1);		netif_device_attach(&info->dev);	    }	}	break;    }    return 0;} /* axnet_event *//*======================================================================    MII interface support======================================================================*/#define MDIO_SHIFT_CLK		0x01#define MDIO_DATA_WRITE0	0x00#define MDIO_DATA_WRITE1	0x08#define MDIO_DATA_READ		0x04#define MDIO_MASK		0x0f#define MDIO_ENB_IN		0x02static void mdio_sync(ioaddr_t addr){    int bits;    for (bits = 0; bits < 32; bits++) {	outb_p(MDIO_DATA_WRITE1, addr);	outb_p(MDIO_DATA_WRITE1 | MDIO_SHIFT_CLK, addr);    }}static int mdio_read(ioaddr_t addr, int phy_id, int loc){    u_int cmd = (0xf6<<10)|(phy_id<<5)|loc;    int i, retval = 0;    mdio_sync(addr);    for (i = 14; i >= 0; i--) {	int dat = (cmd&(1<<i)) ? MDIO_DATA_WRITE1 : MDIO_DATA_WRITE0;	outb_p(dat, addr);	outb_p(dat | MDIO_SHIFT_CLK, addr);    }    for (i = 19; i > 0; i--) {	outb_p(MDIO_ENB_IN, addr);	retval = (retval << 1) | ((inb_p(addr) & MDIO_DATA_READ) != 0);	outb_p(MDIO_ENB_IN | MDIO_SHIFT_CLK, addr);    }    return (retval>>1) & 0xffff;}static void mdio_write(ioaddr_t addr, int phy_id, int loc, int value){    u_int cmd = (0x05<<28)|(phy_id<<23)|(loc<<18)|(1<<17)|value;    int i;    mdio_sync(addr);    for (i = 31; i >= 0; i--) {	int dat = (cmd&(1<<i)) ? MDIO_DATA_WRITE1 : MDIO_DATA_WRITE0;	outb_p(dat, addr);	outb_p(dat | MDIO_SHIFT_CLK, addr);    }    for (i = 1; i >= 0; i--) {	outb_p(MDIO_ENB_IN, addr);	outb_p(MDIO_ENB_IN | MDIO_SHIFT_CLK, addr);    }}/*====================================================================*/static int axnet_open(struct net_device *dev){    axnet_dev_t *info = (axnet_dev_t *)dev;    dev_link_t *link = &info->link;        DEBUG(2, "axnet_open('%s')\n", dev->name);    if (!DEV_OK(link))	return -ENODEV;    link->open++;    MOD_INC_USE_COUNT;    request_irq(dev->irq, ei_irq_wrapper, SA_SHIRQ, dev_info, dev);    info->link_status = 0x00;    info->watchdog.function = &ei_watchdog;    info->watchdog.data = (u_long)info;    info->watchdog.expires = jiffies + HZ;    add_timer(&info->watchdog);    return ax_open(dev);} /* axnet_open *//*====================================================================*/static int axnet_close(struct net_device *dev){    axnet_dev_t *info = (axnet_dev_t *)dev;    dev_link_t *link = &info->link;    DEBUG(2, "axnet_close('%s')\n", dev->name);    free_irq(dev->irq, dev);        link->open--;    netif_stop_queue(dev);    del_timer(&info->watchdog);    if (link->state & DEV_STALE_CONFIG)	mod_timer(&link->release, jiffies + HZ/20);    MOD_DEC_USE_COUNT;    return 0;} /* axnet_close *//*======================================================================    Hard reset the card.  This used to pause for the same period that    a 8390 reset command required, but that shouldn't be necessary.======================================================================*/static void axnet_reset_8390(struct net_device *dev){    ioaddr_t nic_base = dev->base_addr;    int i;    ei_status.txing = ei_status.dmaing = 0;    outb_p(E8390_NODMA+E8390_PAGE0+E8390_STOP, nic_base + E8390_CMD);    outb(inb(nic_base + AXNET_RESET), nic_base + AXNET_RESET);    for (i = 0; i < 100; i++) {	if ((inb_p(nic_base+EN0_ISR) & ENISR_RESET) != 0)	    break;	udelay(100);    }    outb_p(ENISR_RESET, nic_base + EN0_ISR); /* Ack intr. */        if (i == 100)	printk(KERN_ERR "%s: axnet_reset_8390() did not complete.\n",	       dev->name);    } /* axnet_reset_8390 *//*====================================================================*/static void ei_irq_wrapper(int irq, void *dev_id, struct pt_regs *regs){    axnet_dev_t *info = dev_id;    info->stale = 0;    ax_interrupt(irq, dev_id, regs);}static void ei_watchdog(u_long arg){    axnet_dev_t *info = (axnet_dev_t *)(arg);    struct net_device *dev = &info->dev;    ioaddr_t nic_base = dev->base_addr;    ioaddr_t mii_addr = nic_base + AXNET_MII_EEP;    u_short link;    if (!netif_device_present(dev)) goto reschedule;    /* Check for pending interrupt with expired latency timer: with       this, we can limp along even if the interrupt is blocked */    if (info->stale++ && (inb_p(nic_base + EN0_ISR) & ENISR_ALL)) {	if (!info->fast_poll)	    printk(KERN_INFO "%s: interrupt(s) dropped!\n", dev->name);	ei_irq_wrapper(dev->irq, dev, NULL);	info->fast_poll = HZ;    }    if (info->fast_poll) {	info->fast_poll--;	info->watchdog.expires = jiffies + 1;	add_timer(&info->watchdog);	return;    }    if (info->phy_id < 0)	goto reschedule;    link = mdio_read(mii_addr, info->phy_id, 1);    if (!link || (link == 0xffff)) {	printk(KERN_INFO "%s: MII is missing!\n", dev->name);	info->phy_id = -1;	goto reschedule;    }    link &= 0x0004;    if (link != info->link_status) {	u_short p = mdio_read(mii_addr, info->phy_id, 5);	printk(KERN_INFO "%s: %s link beat\n", dev->name,	       (link) ? "found" : "lost");	if (link) {	    info->duplex_flag = (p & 0x0140) ? 0x80 : 0x00;	    if (p)		printk(KERN_INFO "%s: autonegotiation complete: "		       "%sbaseT-%cD selected\n", dev->name,		       ((p & 0x0180) ? "100" : "10"),		       ((p & 0x0140) ? 'F' : 'H'));	    else		printk(KERN_INFO "%s: link partner did not autonegotiate\n",		       dev->name);	    AX88190_init(dev, 1);	}	info->link_status = link;    }reschedule:    info->watchdog.expires = jiffies + HZ;    add_timer(&info->watchdog);}/*====================================================================*/static int axnet_ioctl(struct net_device *dev, struct ifreq *rq, int cmd){    axnet_dev_t *info = (axnet_dev_t *)dev;    u16 *data = (u16 *)&rq->ifr_data;    ioaddr_t mii_addr = dev->base_addr + AXNET_MII_EEP;    switch (cmd) {    case SIOCDEVPRIVATE:	data[0] = info->phy_id;    case SIOCDEVPRIVATE+1:	data[3] = mdio_read(mii_addr, data[0], data[1] & 0x1f);	return 0;    case SIOCDEVPRIVATE+2:	if (!capable(CAP_NET_ADMIN))	    return -EPERM;	mdio_write(mii_addr, data[0], data[1] & 0x1f, data[2]);	return 0;    }    return -EOPNOTSUPP;}/*====================================================================*/static void get_8390_hdr(struct net_device *dev,			 struct e8390_pkt_hdr *hdr,			 int ring_page){    ioaddr_t nic_base = dev->base_addr;    outb_p(0, nic_base + EN0_RSARLO);		/* On page boundary */    outb_p(ring_page, nic_base + EN0_RSARHI);    outb_p(E8390_RREAD+E8390_START, nic_base + AXNET_CMD);    insw(nic_base + AXNET_DATAPORT, hdr,	    sizeof(struct e8390_pkt_hdr)>>1);    /* Fix for big endian systems */    hdr->count = le16_to_cpu(hdr->count);}/*====================================================================*/static void block_input(struct net_device *dev, int count,			struct sk_buff *skb, int ring_offset){    ioaddr_t nic_base = dev->base_addr;    int xfer_count = count;    char *buf = skb->data;#ifdef PCMCIA_DEBUG    if ((ei_debug > 4) && (count != 4))	printk(KERN_DEBUG "%s: [bi=%d]\n", dev->name, count+4);#endif    outb_p(ring_offset & 0xff, nic_base + EN0_RSARLO);    outb_p(ring_offset >> 8, nic_base + EN0_RSARHI);    outb_p(E8390_RREAD+E8390_START, nic_base + AXNET_CMD);    insw(nic_base + AXNET_DATAPORT,buf,count>>1);    if (count & 0x01)	buf[count-1] = inb(nic_base + AXNET_DATAPORT), xfer_count++;}/*====================================================================*/static void block_output(struct net_device *dev, int count,			 const u_char *buf, const int start_page){    ioaddr_t nic_base = dev->base_addr;#ifdef PCMCIA_DEBUG    if (ei_debug > 4)	printk(KERN_DEBUG "%s: [bo=%d]\n", dev->name, count);#endif    /* Round the count up for word writes.  Do we need to do this?       What effect will an odd byte count have on the 8390?       I should check someday. */    if (count & 0x01)	count++;    outb_p(0x00, nic_base + EN0_RSARLO);    outb_p(start_page, nic_base + EN0_RSARHI);    outb_p(E8390_RWRITE+E8390_START, nic_base + AXNET_CMD);    outsw(nic_base + AXNET_DATAPORT, buf, count>>1);}/*====================================================================*/static int __init init_axnet_cs(void){    servinfo_t serv;    DEBUG(0, "%s\n", version);    CardServices(GetCardServicesInfo, &serv);    if (serv.Revision != CS_RELEASE_CODE) {	printk(KERN_NOTICE "axnet_cs: Card Services release "	       "does not match!\n");	return -1;    }    register_pccard_driver(&dev_info, &axnet_attach, &axnet_detach);    return 0;}static void __exit exit_axnet_cs(void){    DEBUG(0, "axnet_cs: unloading\n");    unregister_pccard_driver(&dev_info);    while (dev_list != NULL)	axnet_detach(dev_list);}module_init(init_axnet_cs);module_exit(exit_axnet_cs);/*====================================================================*//* 8390.c: A general NS8390 ethernet driver core for linux. *//*	Written 1992-94 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.	The author may be reached as becker@scyld.com, or C/O	Scyld Computing Corporation	410 Severn Ave., Suite 210	Annapolis MD 21403  This is the chip-specific code for many 8390-based ethernet adaptors.  This is not a complete driver, it must be combined with board-specific  code such as ne.c, wd.c, 3c503.c, etc.  Seeing how at least eight drivers use this code, (not counting the  PCMCIA ones either) it is easy to break some card by what seems like  a simple innocent change. Please contact me or Donald if you think  you have found something that needs changing. -- PG  Changelog:  Paul Gortmaker	: remove set_bit lock, other cleanups.  Paul Gortmaker	: add ei_get_8390_hdr() so we can pass skb's to 			  ei_block_input() for eth_io_copy_and_sum().  Paul Gortmaker	: exchange static int ei_pingpong for a #define,			  also add better Tx error handling.

⌨️ 快捷键说明

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