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

📄 smc91c92_cs.c

📁 该文件是rt_linux
💻 C
📖 第 1 页 / 共 5 页
字号:
/*====================================================================*/static struct net_device_stats *smc91c92_get_stats(struct net_device *dev){    struct smc_private *smc = (struct smc_private *)dev->priv;    /* Nothing to update - the 91c92 is a pretty primative chip. */    return &smc->stats;}/*======================================================================      Calculate values for the hardware multicast filter hash table.    ======================================================================*/static void fill_multicast_tbl(int count, struct dev_mc_list *addrs,			       u_char *multicast_table){    struct dev_mc_list	*mc_addr;        for (mc_addr = addrs;  mc_addr && --count > 0;  mc_addr = mc_addr->next) {	u_int position = ether_crc(6, mc_addr->dmi_addr);#ifndef final_version		/* Verify multicast address. */	if ((mc_addr->dmi_addr[0] & 1) == 0)	    continue;#endif	multicast_table[position >> 29] |= 1 << ((position >> 26) & 7);    }}/*======================================================================      Set the receive mode.        This routine is used by both the protocol level to notify us of    promiscuous/multicast mode changes, and by the open/reset code to    initialize the Rx registers.  We always set the multicast list and    leave the receiver running.    ======================================================================*/static void set_rx_mode(struct net_device *dev){    ioaddr_t ioaddr = dev->base_addr;    struct smc_private *smc = dev->priv;    u_int multicast_table[ 2 ] = { 0, };    unsigned long flags;    u_short rx_cfg_setting;        if (dev->flags & IFF_PROMISC) {	printk(KERN_NOTICE "%s: setting Rx mode to promiscuous.\n", dev->name);	rx_cfg_setting = RxStripCRC | RxEnable | RxPromisc | RxAllMulti;    } else if (dev->flags & IFF_ALLMULTI)	rx_cfg_setting = RxStripCRC | RxEnable | RxAllMulti;    else {	if (dev->mc_count)  {	    fill_multicast_tbl(dev->mc_count, dev->mc_list,			       (u_char *)multicast_table);	}	rx_cfg_setting = RxStripCRC | RxEnable;    }        /* Load MC table and Rx setting into the chip without interrupts. */    spin_lock_irqsave(&smc->lock, flags);    SMC_SELECT_BANK(3);    outl(multicast_table[0], ioaddr + MULTICAST0);    outl(multicast_table[1], ioaddr + MULTICAST4);    SMC_SELECT_BANK(0);    outw(rx_cfg_setting, ioaddr + RCR);    SMC_SELECT_BANK(2);    spin_unlock_irqrestore(&smc->lock, flags);     return;}/*======================================================================    Senses when a card's config changes. Here, it's coax or TP. ======================================================================*/static int s9k_config(struct net_device *dev, struct ifmap *map){    struct smc_private *smc = dev->priv;    if ((map->port != (u_char)(-1)) && (map->port != dev->if_port)) {	if (smc->cfg & CFG_MII_SELECT)	    return -EOPNOTSUPP;	else if (map->port > 2)	    return -EINVAL;	dev->if_port = map->port;	printk(KERN_INFO "%s: switched to %s port\n",	       dev->name, if_names[dev->if_port]);	smc_reset(dev);    }    return 0;}/*======================================================================    Reset the chip, reloading every register that might be corrupted.======================================================================*//*  Set transceiver type, perhaps to something other than what the user  specified in dev->if_port.*/static void smc_set_xcvr(struct net_device *dev, int if_port){    struct smc_private *smc = (struct smc_private *)dev->priv;    ioaddr_t ioaddr = dev->base_addr;    u_short saved_bank;    saved_bank = inw(ioaddr + BANK_SELECT);    SMC_SELECT_BANK(1);    if (if_port == 2) {	outw(smc->cfg | CFG_AUI_SELECT, ioaddr + CONFIG);	if ((smc->manfid == MANFID_OSITECH) &&	    (smc->cardid != PRODID_OSITECH_SEVEN))	    set_bits(OSI_AUI_PWR, ioaddr - 0x10 + OSITECH_AUI_PWR);	smc->media_status = ((dev->if_port == 0) ? 0x0001 : 0x0002);    } else {	outw(smc->cfg, ioaddr + CONFIG);	if ((smc->manfid == MANFID_OSITECH) &&	    (smc->cardid != PRODID_OSITECH_SEVEN))	    mask_bits(~OSI_AUI_PWR, ioaddr - 0x10 + OSITECH_AUI_PWR);	smc->media_status = ((dev->if_port == 0) ? 0x0012 : 0x4001);    }    SMC_SELECT_BANK(saved_bank);}static void smc_reset(struct net_device *dev){    ioaddr_t ioaddr = dev->base_addr;    struct smc_private *smc = dev->priv;    int i;    DEBUG(0, "%s: smc91c92 reset called.\n", dev->name);        /* The first interaction must be a write to bring the chip out       of sleep mode. */    SMC_SELECT_BANK(0);    /* Reset the chip. */    outw(RCR_SOFTRESET, ioaddr + RCR);    udelay(10);        /* Clear the transmit and receive configuration registers. */    outw(RCR_CLEAR, ioaddr + RCR);    outw(TCR_CLEAR, ioaddr + TCR);        /* Set the Window 1 control, configuration and station addr registers.       No point in writing the I/O base register ;-> */    SMC_SELECT_BANK(1);    /* Automatically release succesfully transmitted packets,       Accept link errors, counter and Tx error interrupts. */    outw(CTL_AUTO_RELEASE | CTL_TE_ENABLE | CTL_CR_ENABLE,	 ioaddr + CONTROL);    smc_set_xcvr(dev, dev->if_port);    if ((smc->manfid == MANFID_OSITECH) &&	(smc->cardid != PRODID_OSITECH_SEVEN))	outw((dev->if_port == 2 ? OSI_AUI_PWR : 0) |	     (inw(ioaddr-0x10+OSITECH_AUI_PWR) & 0xff00),	     ioaddr - 0x10 + OSITECH_AUI_PWR);        /* Fill in the physical address.  The databook is wrong about the order! */    for (i = 0; i < 6; i += 2)	outw((dev->dev_addr[i+1]<<8)+dev->dev_addr[i],	     ioaddr + ADDR0 + i);        /* Reset the MMU */    SMC_SELECT_BANK(2);    outw(MC_RESET, ioaddr + MMU_CMD);    outw(0, ioaddr + INTERRUPT);        /* Re-enable the chip. */    SMC_SELECT_BANK(0);    outw(((smc->cfg & CFG_MII_SELECT) ? 0 : TCR_MONCSN) |	 TCR_ENABLE | TCR_PAD_EN, ioaddr + TCR);    set_rx_mode(dev);    if (smc->cfg & CFG_MII_SELECT) {	SMC_SELECT_BANK(3);	/* Reset MII */	smc_mdio_write(dev, smc->mii_if.phy_id, 0, 0x8000);	/* Restart MII autonegotiation */	smc_mdio_write(dev, smc->mii_if.phy_id, 0, 0x0000);	smc_mdio_write(dev, smc->mii_if.phy_id, 0, 0x1200);    }    /* Enable interrupts. */    SMC_SELECT_BANK(2);    outw((IM_EPH_INT | IM_RX_OVRN_INT | IM_RCV_INT) << 8,	 ioaddr + INTERRUPT);}/*======================================================================    Media selection timer routine    ======================================================================*/static void media_check(u_long arg){    struct smc_private *smc = (struct smc_private *)(arg);    struct net_device *dev = &smc->dev;    ioaddr_t ioaddr = dev->base_addr;    u_short i, media, saved_bank;    u_short link;    saved_bank = inw(ioaddr + BANK_SELECT);    if (!netif_device_present(dev))	goto reschedule;    SMC_SELECT_BANK(2);    i = inw(ioaddr + INTERRUPT);    SMC_SELECT_BANK(0);    media = inw(ioaddr + EPH) & EPH_LINK_OK;    SMC_SELECT_BANK(1);    media |= (inw(ioaddr + CONFIG) & CFG_AUI_SELECT) ? 2 : 1;        /* Check for pending interrupt with watchdog flag set: with       this, we can limp along even if the interrupt is blocked */    if (smc->watchdog++ && ((i>>8) & i)) {	if (!smc->fast_poll)	    printk(KERN_INFO "%s: interrupt(s) dropped!\n", dev->name);	smc_interrupt(dev->irq, smc, NULL);	smc->fast_poll = HZ;    }    if (smc->fast_poll) {	smc->fast_poll--;	smc->media.expires = jiffies + 1;	add_timer(&smc->media);	SMC_SELECT_BANK(saved_bank);	return;    }    if (smc->cfg & CFG_MII_SELECT) {	if (smc->mii_if.phy_id < 0)	    goto reschedule;	SMC_SELECT_BANK(3);	link = smc_mdio_read(dev, smc->mii_if.phy_id, 1);	if (!link || (link == 0xffff)) {  	    printk(KERN_INFO "%s: MII is missing!\n", dev->name);	    smc->mii_if.phy_id = -1;	    goto reschedule;	}	link &= 0x0004;	if (link != smc->link_status) {	    u_short p = smc_mdio_read(dev, smc->mii_if.phy_id, 5);	    printk(KERN_INFO "%s: %s link beat\n", dev->name,		(link) ? "found" : "lost");	    if (link) {	        printk(KERN_INFO "%s: autonegotiation complete: "	   	    "%sbaseT-%cD selected\n", dev->name,		    ((p & 0x0180) ? "100" : "10"),		    (((p & 0x0100) || ((p & 0x1c0) == 0x40)) ? 'F' : 'H'));	    }	    smc->link_status = link;	}    }    if (smc->cfg & CFG_MII_SELECT)	goto reschedule;    /* Ignore collisions unless we've had no rx's recently */    if (jiffies - dev->last_rx > HZ) {	if (smc->tx_err || (smc->media_status & EPH_16COL))	    media |= EPH_16COL;    }    smc->tx_err = 0;    if (media != smc->media_status) {	if ((media & smc->media_status & 1) &&	    ((smc->media_status ^ media) & EPH_LINK_OK))	    printk(KERN_INFO "%s: %s link beat\n", dev->name,		   (smc->media_status & EPH_LINK_OK ? "lost" : "found"));	else if ((media & smc->media_status & 2) &&		 ((smc->media_status ^ media) & EPH_16COL))	    printk(KERN_INFO "%s: coax cable %s\n", dev->name,		   (media & EPH_16COL ? "problem" : "ok"));	if (dev->if_port == 0) {	    if (media & 1) {		if (media & EPH_LINK_OK)		    printk(KERN_INFO "%s: flipped to 10baseT\n",			   dev->name);		else		    smc_set_xcvr(dev, 2);	    } else {		if (media & EPH_16COL)		    smc_set_xcvr(dev, 1);		else		    printk(KERN_INFO "%s: flipped to 10base2\n",			   dev->name);	    }	}	smc->media_status = media;    }    reschedule:    smc->media.expires = jiffies + HZ;    add_timer(&smc->media);    SMC_SELECT_BANK(saved_bank);}static int smc_link_ok(struct net_device *dev){    ioaddr_t ioaddr = dev->base_addr;    struct smc_private *smc = dev->priv;    if (smc->cfg & CFG_MII_SELECT) {	return mii_link_ok(&smc->mii_if);    } else {        SMC_SELECT_BANK(0);	return inw(ioaddr + EPH) & EPH_LINK_OK;    }}static int smc_netdev_get_ecmd(struct net_device *dev, struct ethtool_cmd *ecmd){    u16 tmp;    ioaddr_t ioaddr = dev->base_addr;    ecmd->supported = (SUPPORTED_TP | SUPPORTED_AUI |	SUPPORTED_10baseT_Half | SUPPORTED_10baseT_Full);		    SMC_SELECT_BANK(1);    tmp = inw(ioaddr + CONFIG);    ecmd->port = (tmp & CFG_AUI_SELECT) ? PORT_AUI : PORT_TP;    ecmd->transceiver = XCVR_INTERNAL;    ecmd->speed = SPEED_10;    ecmd->phy_address = ioaddr + MGMT;    SMC_SELECT_BANK(0);    tmp = inw(ioaddr + TCR);    ecmd->duplex = (tmp & TCR_FDUPLX) ? DUPLEX_FULL : DUPLEX_HALF;    return 0;}static int smc_netdev_set_ecmd(struct net_device *dev, struct ethtool_cmd *ecmd){    u16 tmp;    ioaddr_t ioaddr = dev->base_addr;    if (ecmd->speed != SPEED_10)    	return -EINVAL;    if (ecmd->duplex != DUPLEX_HALF && ecmd->duplex != DUPLEX_FULL)    	return -EINVAL;    if (ecmd->port != PORT_TP && ecmd->port != PORT_AUI)	return -EINVAL;    if (ecmd->transceiver != XCVR_INTERNAL)    	return -EINVAL;    if (ecmd->port == PORT_AUI)	smc_set_xcvr(dev, 1);    else	smc_set_xcvr(dev, 0);    SMC_SELECT_BANK(0);    tmp = inw(ioaddr + TCR);    if (ecmd->duplex == DUPLEX_FULL)	tmp |= TCR_FDUPLX;    else	tmp &= ~TCR_FDUPLX;    outw(ioaddr + TCR, tmp);	    return 0;}static int smc_ethtool_ioctl (struct net_device *dev, void *useraddr){    u32 ethcmd;    struct smc_private *smc = dev->priv;    if (get_user(ethcmd, (u32 *)useraddr))	return -EFAULT;    switch (ethcmd) {    case ETHTOOL_GDRVINFO: {	struct ethtool_drvinfo info = { ETHTOOL_GDRVINFO };	strcpy(info.driver, DRV_NAME);	strcpy(info.version, DRV_VERSION);	if (copy_to_user(useraddr, &info, sizeof(info)))	    return -EFAULT;	return 0;    }    /* get settings */    case ETHTOOL_GSET: {	int ret;	struct ethtool_cmd ecmd = { ETHTOOL_GSET };	spin_lock_irq(&smc->lock);	if (smc->cfg & CFG_MII_SELECT)	    ret = mii_ethtool_gset(&smc->mii_if, &ecmd);	else	    ret = smc_netdev_get_ecmd(dev, &ecmd);	spin_unlock_irq(&smc->lock);	if (copy_to_user(useraddr, &ecmd, sizeof(ecmd)))	    return -EFAULT;	return ret;    }    /* set settings */    case ETHTOOL_SSET: {	int ret;	struct ethtool_cmd ecmd;	if (copy_from_user(&ecmd, useraddr, sizeof(ecmd)))	    return -EFAULT;	spin_lock_irq(&smc->lock);	if (smc->cfg & CFG_MII_SELECT)	    ret = mii_ethtool_sset(&smc->mii_if, &ecmd);    	else	    ret = smc_netdev_set_ecmd(dev, &ecmd);	spin_unlock_irq(&smc->lock);	return ret;    }    /* get link status */    case ETHTOOL_GLINK: {	struct ethtool_value edata = { ETHTOOL_GLINK };	spin_lock_irq(&smc->lock);	edata.data = smc_link_ok(dev);	spin_unlock_irq(&smc->lock);	if (copy_to_user(useraddr, &edata, sizeof(edata)))	    return -EFAULT;	return 0;    }#ifdef PCMCIA_DEBUG    /

⌨️ 快捷键说明

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