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

📄 3c59x.c

📁 Linux内核源代码 为压缩文件 是<<Linux内核>>一书中的源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
			   (vp->info2 & 1) ? "early" : "whole-frame" );		vp->full_bus_master_rx = (vp->info2 & 1) ? 1 : 2;		vp->bus_master = 0;		/* AKPM: vortex only */	}	/* The 3c59x-specific entries in the device structure. */	dev->open = vortex_open;	dev->hard_start_xmit = vp->full_bus_master_tx ?					boomerang_start_xmit : vortex_start_xmit;	dev->stop = vortex_close;	dev->get_stats = vortex_get_stats;	dev->do_ioctl = vortex_ioctl;	dev->set_multicast_list = set_rx_mode;	dev->tx_timeout = vortex_tx_timeout;	dev->watchdog_timeo = (watchdog * HZ) / 1000;	return 0;free_region:	if (vp->must_free_region)		release_region(ioaddr, vci->io_size);	unregister_netdev(dev);	kfree (dev);	printk(KERN_ERR PFX "vortex_probe1 fails.  Returns %d\n", retval);out:	return retval;}static void wait_for_completion(struct net_device *dev, int cmd){	int i = 4000;	outw(cmd, dev->base_addr + EL3_CMD);	while (--i > 0) {		if (!(inw(dev->base_addr + EL3_STATUS) & CmdInProgress))			return;	}	printk(KERN_ERR "%s: command 0x%04x did not complete! Status=0x%x\n",			   dev->name, cmd, inw(dev->base_addr + EL3_STATUS));}static voidvortex_up(struct net_device *dev){	long ioaddr = dev->base_addr;	struct vortex_private *vp = (struct vortex_private *)dev->priv;	unsigned int config;	int i, device_id;	if (vp->pdev)		device_id = vp->pdev->device;	else		device_id = 0x5900; /* EISA */		/* Before initializing select the active media port. */	EL3WINDOW(3);	config = inl(ioaddr + Wn3_Config);	if (vp->media_override != 7) {		if (vortex_debug > 1)			printk(KERN_INFO "%s: Media override to transceiver %d (%s).\n",				   dev->name, vp->media_override,				   media_tbl[vp->media_override].name);		dev->if_port = vp->media_override;	} else if (vp->autoselect) {		if (vp->has_nway) {			printk(KERN_INFO "%s: using NWAY autonegotiation\n", dev->name);			dev->if_port = XCVR_NWAY;		} else {			/* Find first available media type, starting with 100baseTx. */			dev->if_port = XCVR_100baseTx;			while (! (vp->available_media & media_tbl[dev->if_port].mask))				dev->if_port = media_tbl[dev->if_port].next;			printk(KERN_INFO "%s: first available media type: %s\n",					dev->name,					media_tbl[dev->if_port].name);		}	} else {		dev->if_port = vp->default_media;		printk(KERN_INFO "%s: using default media %s\n",				dev->name, media_tbl[dev->if_port].name);	}	init_timer(&vp->timer);	vp->timer.expires = RUN_AT(media_tbl[dev->if_port].wait);	vp->timer.data = (unsigned long)dev;	vp->timer.function = vortex_timer;		/* timer handler */	add_timer(&vp->timer);	init_timer(&vp->rx_oom_timer);	vp->rx_oom_timer.data = (unsigned long)dev;	vp->rx_oom_timer.function = rx_oom_timer;	if (vortex_debug > 1)		printk(KERN_DEBUG "%s: Initial media type %s.\n",			   dev->name, media_tbl[dev->if_port].name);	vp->full_duplex = vp->force_fd;	config = BFINS(config, dev->if_port, 20, 4);//AKPM	if (!vp->has_nway)	{		if (vortex_debug > 6)			printk(KERN_DEBUG "vortex_up(): writing 0x%x to InternalConfig\n",				config);		outl(config, ioaddr + Wn3_Config);	}	if (dev->if_port == XCVR_MII || dev->if_port == XCVR_NWAY) {		int mii_reg1, mii_reg5;		EL3WINDOW(4);		/* Read BMSR (reg1) only to clear old status. */		mii_reg1 = mdio_read(dev, vp->phys[0], 1);		mii_reg5 = mdio_read(dev, vp->phys[0], 5);		if (mii_reg5 == 0xffff  ||  mii_reg5 == 0x0000)			;					/* No MII device or no link partner report */		else if ((mii_reg5 & 0x0100) != 0	/* 100baseTx-FD */				 || (mii_reg5 & 0x00C0) == 0x0040) /* 10T-FD, but not 100-HD */			vp->full_duplex = 1;		vp->partner_flow_ctrl = ((mii_reg5 & 0x0400) != 0);		if (vortex_debug > 1)			printk(KERN_INFO "%s: MII #%d status %4.4x, link partner capability %4.4x,"				   " setting %s-duplex.\n", dev->name, vp->phys[0],				   mii_reg1, mii_reg5, vp->full_duplex ? "full" : "half");		EL3WINDOW(3);	}	/* Set the full-duplex bit. */	outw(	((vp->info1 & 0x8000) || vp->full_duplex ? 0x20 : 0) |		 	(dev->mtu > 1500 ? 0x40 : 0) |			((vp->full_duplex && vp->flow_ctrl && vp->partner_flow_ctrl) ? 0x100 : 0),			ioaddr + Wn3_MAC_Ctrl);	if (vortex_debug > 1) {		printk(KERN_DEBUG "%s: vortex_up() InternalConfig %8.8x.\n",			dev->name, config);	}	wait_for_completion(dev, TxReset);	wait_for_completion(dev, RxReset);	outw(SetStatusEnb | 0x00, ioaddr + EL3_CMD);	if (vortex_debug > 1) {		EL3WINDOW(4);		printk(KERN_DEBUG "%s: vortex_up() irq %d media status %4.4x.\n",			   dev->name, dev->irq, inw(ioaddr + Wn4_Media));	}	/* Set the station address and mask in window 2 each time opened. */	EL3WINDOW(2);	for (i = 0; i < 6; i++)		outb(dev->dev_addr[i], ioaddr + i);	for (; i < 12; i+=2)		outw(0, ioaddr + i);	if (vp->cb_fn_base) {		unsigned short n = inw(ioaddr + Wn2_ResetOptions) & ~0x4010;		if (vp->drv_flags & INVERT_LED_PWR)			n |= 0x10;		if (vp->drv_flags & INVERT_MII_PWR)			n |= 0x4000;		outw(n, ioaddr + Wn2_ResetOptions);	}	if (dev->if_port == XCVR_10base2)		/* Start the thinnet transceiver. We should really wait 50ms...*/		outw(StartCoax, ioaddr + EL3_CMD);	if (dev->if_port != XCVR_NWAY) {		EL3WINDOW(4);		outw((inw(ioaddr + Wn4_Media) & ~(Media_10TP|Media_SQE)) |			 media_tbl[dev->if_port].media_bits, ioaddr + Wn4_Media);	}	/* Switch to the stats window, and clear all stats by reading. */	outw(StatsDisable, ioaddr + EL3_CMD);	EL3WINDOW(6);	for (i = 0; i < 10; i++)		inb(ioaddr + i);	inw(ioaddr + 10);	inw(ioaddr + 12);	/* New: On the Vortex we must also clear the BadSSD counter. */	EL3WINDOW(4);	inb(ioaddr + 12);	/* ..and on the Boomerang we enable the extra statistics bits. */	outw(0x0040, ioaddr + Wn4_NetDiag);	/* Switch to register set 7 for normal use. */	EL3WINDOW(7);	if (vp->full_bus_master_rx) { /* Boomerang bus master. */		vp->cur_rx = vp->dirty_rx = 0;		/* Initialize the RxEarly register as recommended. */		outw(SetRxThreshold + (1536>>2), ioaddr + EL3_CMD);		outl(0x0020, ioaddr + PktStatus);		outl(vp->rx_ring_dma, ioaddr + UpListPtr);	}	if (vp->full_bus_master_tx) { 		/* Boomerang bus master Tx. */		vp->cur_tx = vp->dirty_tx = 0;		if (vp->drv_flags & IS_BOOMERANG)			outb(PKT_BUF_SZ>>8, ioaddr + TxFreeThreshold); /* Room for a packet. */		/* Clear the Rx, Tx rings. */		for (i = 0; i < RX_RING_SIZE; i++)	/* AKPM: this is done in vortex_open, too */			vp->rx_ring[i].status = 0;		for (i = 0; i < TX_RING_SIZE; i++)			vp->tx_skbuff[i] = 0;		outl(0, ioaddr + DownListPtr);	}	/* Set receiver mode: presumably accept b-case and phys addr only. */	set_rx_mode(dev);	outw(StatsEnable, ioaddr + EL3_CMD); /* Turn on statistics. */	outw(RxEnable, ioaddr + EL3_CMD); /* Enable the receiver. */	outw(TxEnable, ioaddr + EL3_CMD); /* Enable transmitter. */	/* Allow status bits to be seen. */	vp->status_enable = SetStatusEnb | HostError|IntReq|StatsFull|TxComplete|		(vp->full_bus_master_tx ? DownComplete : TxAvailable) |		(vp->full_bus_master_rx ? UpComplete : RxComplete) |		(vp->bus_master ? DMADone : 0);	vp->intr_enable = SetIntrEnb | IntLatch | TxAvailable |		(vp->full_bus_master_rx ? 0 : RxComplete) |		StatsFull | HostError | TxComplete | IntReq		| (vp->bus_master ? DMADone : 0) | UpComplete | DownComplete;	outw(vp->status_enable, ioaddr + EL3_CMD);	/* Ack all pending events, and set active indicator mask. */	outw(AckIntr | IntLatch | TxAvailable | RxEarly | IntReq,		 ioaddr + EL3_CMD);	outw(vp->intr_enable, ioaddr + EL3_CMD);	if (vp->cb_fn_base)			/* The PCMCIA people are idiots.  */		writel(0x8000, vp->cb_fn_base + 4);	netif_start_queue (dev);}static intvortex_open(struct net_device *dev){	struct vortex_private *vp = (struct vortex_private *)dev->priv;	int i;	int retval;	/* Use the now-standard shared IRQ implementation. */	if ((retval = request_irq(dev->irq, vp->full_bus_master_rx ?				&boomerang_interrupt : &vortex_interrupt, SA_SHIRQ, dev->name, dev))) {		printk(KERN_ERR "%s: Could not reserve IRQ %d\n", dev->name, dev->irq);		goto out;	}	if (vp->full_bus_master_rx) { /* Boomerang bus master. */		if (vortex_debug > 2)			printk(KERN_DEBUG "%s:  Filling in the Rx ring.\n", dev->name);		for (i = 0; i < RX_RING_SIZE; i++) {			struct sk_buff *skb;			vp->rx_ring[i].next = cpu_to_le32(vp->rx_ring_dma + sizeof(struct boom_rx_desc) * (i+1));			vp->rx_ring[i].status = 0;	/* Clear complete bit. */			vp->rx_ring[i].length = cpu_to_le32(PKT_BUF_SZ | LAST_FRAG);			skb = dev_alloc_skb(PKT_BUF_SZ);			vp->rx_skbuff[i] = skb;			if (skb == NULL)				break;			/* Bad news!  */			skb->dev = dev;			/* Mark as being used by this device. */			skb_reserve(skb, 2);	/* Align IP on 16 byte boundaries */			vp->rx_ring[i].addr = cpu_to_le32(pci_map_single(vp->pdev, skb->tail, PKT_BUF_SZ, PCI_DMA_FROMDEVICE));		}		if (i != RX_RING_SIZE) {			int j;			for (j = 0; j < RX_RING_SIZE; j++) {				if (vp->rx_skbuff[j]) {					dev_kfree_skb(vp->rx_skbuff[j]);					vp->rx_skbuff[j] = 0;				}			}			retval = -ENOMEM;			goto out_free_irq;		}		/* Wrap the ring. */		vp->rx_ring[i-1].next = cpu_to_le32(vp->rx_ring_dma);	}	vortex_up(dev);	vp->open = 1;	vp->tx_full = 0;	return 0;out_free_irq:	free_irq(dev->irq, dev);out:	if (vortex_debug > 1)		printk(KERN_ERR "%s: vortex_open() fails: returning %d\n", dev->name, retval);	return retval;}static void vortex_timer(unsigned long data){	struct net_device *dev = (struct net_device *)data;	struct vortex_private *vp = (struct vortex_private *)dev->priv;	long ioaddr = dev->base_addr;	int next_tick = 60*HZ;	int ok = 0;	int media_status, mii_status, old_window;	if (vortex_debug > 2) {		printk(KERN_DEBUG "%s: Media selection timer tick happened, %s.\n",			   dev->name, media_tbl[dev->if_port].name);		printk(KERN_DEBUG "dev->watchdog_timeo=%d\n", dev->watchdog_timeo);	}	disable_irq(dev->irq);	old_window = inw(ioaddr + EL3_CMD) >> 13;	EL3WINDOW(4);	media_status = inw(ioaddr + Wn4_Media);	switch (dev->if_port) {	case XCVR_10baseT:  case XCVR_100baseTx:  case XCVR_100baseFx:		if (media_status & Media_LnkBeat) {			ok = 1;			if (vortex_debug > 1)				printk(KERN_DEBUG "%s: Media %s has link beat, %x.\n",					   dev->name, media_tbl[dev->if_port].name, media_status);		} else if (vortex_debug > 1)			printk(KERN_DEBUG "%s: Media %s has no link beat, %x.\n",				   dev->name, media_tbl[dev->if_port].name, media_status);		break;	case XCVR_MII: case XCVR_NWAY:		{			mii_status = mdio_read(dev, vp->phys[0], 1);			ok = 1;			if (vortex_debug > 2)				printk(KERN_DEBUG "%s: MII transceiver has status %4.4x.\n",					dev->name, mii_status);			if (mii_status & 0x0004) {				int mii_reg5 = mdio_read(dev, vp->phys[0], 5);				if (! vp->force_fd  &&  mii_reg5 != 0xffff) {					int duplex = (mii_reg5&0x0100) ||						(mii_reg5 & 0x01C0) == 0x0040;					if (vp->full_duplex != duplex) {						vp->full_duplex = duplex;						printk(KERN_INFO "%s: Setting %s-duplex based on MII "							"#%d link partner capability of %4.4x.\n",							dev->name, vp->full_duplex ? "full" : "half",							vp->phys[0], mii_reg5);						/* Set the full-duplex bit. */						EL3WINDOW(3);	/* AKPM: this was missing from 2.3.99 3c59x.c! */						outw(	(vp->full_duplex ? 0x20 : 0) |								(dev->mtu > 1500 ? 0x40 : 0) |								((vp->full_duplex && vp->flow_ctrl && vp->partner_flow_ctrl) ? 0x100 : 0),								ioaddr + Wn3_MAC_Ctrl);						if (vortex_debug > 1)							printk(KERN_DEBUG "Setting duplex in Wn3_MAC_Ctrl\n");						/* AKPM: bug: should reset Tx and Rx after setting Duplex.  Page 180 */					}				}			}		}		break;	  default:					/* Other media types handled by Tx timeouts. */		if (vortex_debug > 1)		  printk(KERN_DEBUG "%s: Media %s has no indication, %x.\n",				 dev->name, media_tbl[dev->if_port].name, media_status);		ok = 1;	}	if ( ! ok) {		unsigned int config;		do {			dev->if_port = media_tbl[dev->if_port].next;		} while ( ! (vp->available_media & media_tbl[dev->if_port].mask));		if (dev->if_port == XCVR_Default) { /* Go back to default. */		  dev->if_port = vp->default_media;		  if (vortex_debug > 1)			printk(KERN_DEBUG "%s: Media selection failing, using default "				   "%s port.\n",				   dev->name, media_tbl[dev->if_port].name);		} else {			if (vortex_debug > 1)				printk(KERN_DEBUG "%s: Media selection failed, now trying "					   "%s port.\n",

⌨️ 快捷键说明

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