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

📄 xircom_cb.c

📁 linux-2.6.15.6
💻 C
📖 第 1 页 / 共 3 页
字号:
			card->tx_buffer[4*desc] = 0x80000000;			trigger_transmit(card);			if (((int)card->tx_buffer[nextdescriptor*4])<0) {	/* next descriptor is occupied... */				netif_stop_queue(dev);			}			card->transmit_used = nextdescriptor;			leave("xircom-start_xmit - sent");				spin_unlock_irqrestore(&card->lock,flags);			return 0;	}		/* Uh oh... no free descriptor... drop the packet */	netif_stop_queue(dev);	spin_unlock_irqrestore(&card->lock,flags);	trigger_transmit(card);		return -EIO;}static int xircom_open(struct net_device *dev){	struct xircom_private *xp = netdev_priv(dev);	int retval;	enter("xircom_open");	printk(KERN_INFO "xircom cardbus adaptor found, registering as %s, using irq %i \n",dev->name,dev->irq);	retval = request_irq(dev->irq, &xircom_interrupt, SA_SHIRQ, dev->name, dev);	if (retval) {		leave("xircom_open - No IRQ");		return retval;	}		xircom_up(xp);	xp->open = 1;	leave("xircom_open");	return 0;}static int xircom_close(struct net_device *dev){	struct xircom_private *card;	unsigned long flags;		enter("xircom_close");	card = netdev_priv(dev);	netif_stop_queue(dev); /* we don't want new packets */		spin_lock_irqsave(&card->lock,flags);		disable_all_interrupts(card);#if 0		/* We can enable this again once we send dummy packets on ifconfig ethX up */	deactivate_receiver(card);	deactivate_transmitter(card);#endif		remove_descriptors(card);		spin_unlock_irqrestore(&card->lock,flags);		card->open = 0;	free_irq(dev->irq,dev);		leave("xircom_close");		return 0;	}static struct net_device_stats *xircom_get_stats(struct net_device *dev){        struct xircom_private *card = netdev_priv(dev);        return &card->stats;}                                                  #ifdef CONFIG_NET_POLL_CONTROLLERstatic void xircom_poll_controller(struct net_device *dev){	disable_irq(dev->irq);	xircom_interrupt(dev->irq, dev, NULL);	enable_irq(dev->irq);}#endifstatic void initialize_card(struct xircom_private *card){	unsigned int val;	unsigned long flags;	enter("initialize_card");	spin_lock_irqsave(&card->lock, flags);	/* First: reset the card */	val = inl(card->io_port + CSR0);	val |= 0x01;		/* Software reset */	outl(val, card->io_port + CSR0);	udelay(100);		/* give the card some time to reset */	val = inl(card->io_port + CSR0);	val &= ~0x01;		/* disable Software reset */	outl(val, card->io_port + CSR0);	val = 0;		/* Value 0x00 is a safe and conservative value 				   for the PCI configuration settings */	outl(val, card->io_port + CSR0);	disable_all_interrupts(card);	deactivate_receiver(card);	deactivate_transmitter(card);	spin_unlock_irqrestore(&card->lock, flags);	leave("initialize_card");}/*trigger_transmit causes the card to check for frames to be transmitted.This is accomplished by writing to the CSR1 port. The documentationclaims that the act of writing is sufficient and that the value isignored; I chose zero.*/static void trigger_transmit(struct xircom_private *card){	unsigned int val;	enter("trigger_transmit");	val = 0;	outl(val, card->io_port + CSR1);	leave("trigger_transmit");}/*trigger_receive causes the card to check for empty frames in thedescriptor list in which packets can be received.This is accomplished by writing to the CSR2 port. The documentationclaims that the act of writing is sufficient and that the value isignored; I chose zero.*/static void trigger_receive(struct xircom_private *card){	unsigned int val;	enter("trigger_receive");	val = 0;	outl(val, card->io_port + CSR2);	leave("trigger_receive");}/*setup_descriptors initializes the send and receive buffers to be validdescriptors and programs the addresses into the card.*/static void setup_descriptors(struct xircom_private *card){	unsigned int val;	unsigned int address;	int i;	enter("setup_descriptors");	if (card->rx_buffer == NULL)		BUG();	if (card->tx_buffer == NULL)		BUG();	/* Receive descriptors */	memset(card->rx_buffer, 0, 128);	/* clear the descriptors */	for (i=0;i<NUMDESCRIPTORS;i++ ) {		/* Rx Descr0: It's empty, let the card own it, no errors -> 0x80000000 */		card->rx_buffer[i*4 + 0] = 0x80000000;		/* Rx Descr1: buffer 1 is 1536 bytes, buffer 2 is 0 bytes */		card->rx_buffer[i*4 + 1] = 1536;		if (i==NUMDESCRIPTORS-1)			card->rx_buffer[i*4 + 1] |= (1 << 25); /* bit 25 is "last descriptor" */		/* Rx Descr2: address of the buffer		   we store the buffer at the 2nd half of the page */			address = (unsigned long) card->rx_dma_handle;		card->rx_buffer[i*4 + 2] = cpu_to_le32(address + bufferoffsets[i]);		/* Rx Desc3: address of 2nd buffer -> 0 */		card->rx_buffer[i*4 + 3] = 0;	}		wmb();	/* Write the receive descriptor ring address to the card */	address = (unsigned long) card->rx_dma_handle;	val = cpu_to_le32(address); 	outl(val, card->io_port + CSR3);	/* Receive descr list address */	/* transmit descriptors */	memset(card->tx_buffer, 0, 128);	/* clear the descriptors */		for (i=0;i<NUMDESCRIPTORS;i++ ) {		/* Tx Descr0: Empty, we own it, no errors -> 0x00000000 */		card->tx_buffer[i*4 + 0] = 0x00000000;		/* Tx Descr1: buffer 1 is 1536 bytes, buffer 2 is 0 bytes */		card->tx_buffer[i*4 + 1] = 1536;		if (i==NUMDESCRIPTORS-1)			card->tx_buffer[i*4 + 1] |= (1 << 25); /* bit 25 is "last descriptor" */				/* Tx Descr2: address of the buffer		   we store the buffer at the 2nd half of the page */		address = (unsigned long) card->tx_dma_handle;		card->tx_buffer[i*4 + 2] = cpu_to_le32(address + bufferoffsets[i]);		/* Tx Desc3: address of 2nd buffer -> 0 */		card->tx_buffer[i*4 + 3] = 0;	}	wmb();	/* wite the transmit descriptor ring to the card */	address = (unsigned long) card->tx_dma_handle;	val =cpu_to_le32(address);	outl(val, card->io_port + CSR4);	/* xmit descr list address */	leave("setup_descriptors");}/*remove_descriptors informs the card the descriptors are no longervalid by setting the address in the card to 0x00.*/static void remove_descriptors(struct xircom_private *card){	unsigned int val;	enter("remove_descriptors");	val = 0;	outl(val, card->io_port + CSR3);	/* Receive descriptor address */	outl(val, card->io_port + CSR4);	/* Send descriptor address */	leave("remove_descriptors");}/*link_status_changed returns 1 if the card has indicated thatthe link status has changed. The new link status has to be read from CSR12.This function also clears the status-bit.*/static int link_status_changed(struct xircom_private *card){	unsigned int val;	enter("link_status_changed");	val = inl(card->io_port + CSR5);	/* Status register */	if ((val & (1 << 27)) == 0) {	/* no change */		leave("link_status_changed - nochange");		return 0;	}	/* clear the event by writing a 1 to the bit in the	   status register. */	val = (1 << 27);	outl(val, card->io_port + CSR5);	leave("link_status_changed - changed");	return 1;}/*transmit_active returns 1 if the transmitter on the card isin a non-stopped state.*/static int transmit_active(struct xircom_private *card){	unsigned int val;	enter("transmit_active");	val = inl(card->io_port + CSR5);	/* Status register */	if ((val & (7 << 20)) == 0) {	/* transmitter disabled */		leave("transmit_active - inactive");		return 0;	}	leave("transmit_active - active");	return 1;}/*receive_active returns 1 if the receiver on the card isin a non-stopped state.*/static int receive_active(struct xircom_private *card){	unsigned int val;	enter("receive_active");	val = inl(card->io_port + CSR5);	/* Status register */	if ((val & (7 << 17)) == 0) {	/* receiver disabled */		leave("receive_active - inactive");		return 0;	}	leave("receive_active - active");	return 1;}/*activate_receiver enables the receiver on the card.Before being allowed to active the receiver, the receivermust be completely de-activated. To achieve this,this code actually disables the receiver first; then it waits for the receiver to become inactive, then it activates the receiver and thenit waits for the receiver to be active.must be called with the lock held and interrupts disabled.*/static void activate_receiver(struct xircom_private *card){	unsigned int val;	int counter;	enter("activate_receiver");	val = inl(card->io_port + CSR6);	/* Operation mode */		/* If the "active" bit is set and the receiver is already	   active, no need to do the expensive thing */	if ((val&2) && (receive_active(card)))		return;			val = val & ~2;		/* disable the receiver */	outl(val, card->io_port + CSR6);	counter = 10;	while (counter > 0) {		if (!receive_active(card))			break;		/* wait a while */		udelay(50);		counter--;		if (counter <= 0)			printk(KERN_ERR "xircom_cb: Receiver failed to deactivate\n");	}	/* enable the receiver */	val = inl(card->io_port + CSR6);	/* Operation mode */	val = val | 2;				/* enable the receiver */	outl(val, card->io_port + CSR6);	/* now wait for the card to activate again */	counter = 10;	while (counter > 0) {		if (receive_active(card))			break;		/* wait a while */		udelay(50);		counter--;		if (counter <= 0)			printk(KERN_ERR "xircom_cb: Receiver failed to re-activate\n");	}	leave("activate_receiver");}/*deactivate_receiver disables the receiver on the card.To achieve this this code disables the receiver first; then it waits for the receiver to become inactive.must be called with the lock held and interrupts disabled.*/static void deactivate_receiver(struct xircom_private *card){	unsigned int val;	int counter;	enter("deactivate_receiver");	val = inl(card->io_port + CSR6);	/* Operation mode */	val = val & ~2;				/* disable the receiver */	outl(val, card->io_port + CSR6);	counter = 10;	while (counter > 0) {		if (!receive_active(card))			break;		/* wait a while */		udelay(50);		counter--;		if (counter <= 0)			printk(KERN_ERR "xircom_cb: Receiver failed to deactivate\n");	}	leave("deactivate_receiver");}/*activate_transmitter enables the transmitter on the card.Before being allowed to active the transmitter, the transmittermust be completely de-activated. To achieve this,this code actually disables the transmitter first; then it waits for the transmitter to become inactive, then it activates the transmitter and thenit waits for the transmitter to be active again.must be called with the lock held and interrupts disabled.*/static void activate_transmitter(struct xircom_private *card){	unsigned int val;	int counter;	enter("activate_transmitter");

⌨️ 快捷键说明

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