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

📄 skge.c

📁 linux嵌入式课程实践中的一个关于声卡驱动程序 。
💻 C
📖 第 1 页 / 共 5 页
字号:
 *	The interrupt routine is called when the network adapter *	generates an interrupt. It may also be called if another device *	shares this interrupt vector with the driver. *	This is the same as above, but handles only one port. * * Returns: N/A * */static void SkGeIsrOnePort(int irq, void *dev_id, struct pt_regs *ptregs){struct net_device *dev = (struct net_device *)dev_id;DEV_NET		*pNet;SK_AC		*pAC;SK_U32		IntSrc;		/* interrupts source register contents */		pNet = (DEV_NET*) dev->priv;	pAC = pNet->pAC;		/*	 * Check and process if its our interrupt	 */	SK_IN32(pAC->IoBase, B0_SP_ISRC, &IntSrc);	if (IntSrc == 0) {		return;	}	while (((IntSrc & IRQ_MASK) & ~SPECIAL_IRQS) != 0) {#if 0 /* software irq currently not used */		if (IntSrc & IRQ_SW) {			SK_DBG_MSG(NULL, SK_DBGMOD_DRV,				SK_DBGCAT_DRV_INT_SRC,				("Software IRQ\n"));		}#endif		if (IntSrc & IRQ_EOF_RX1) {			SK_DBG_MSG(NULL, SK_DBGMOD_DRV,				SK_DBGCAT_DRV_INT_SRC,				("EOF RX1 IRQ\n"));			ReceiveIrq(pAC, &pAC->RxPort[0]);			SK_PNMI_CNT_RX_INTR(pAC,0);		}#ifdef USE_TX_COMPLETE /* only if tx complete interrupt used */		if (IntSrc & IRQ_EOF_AS_TX1) {			SK_DBG_MSG(NULL, SK_DBGMOD_DRV,				SK_DBGCAT_DRV_INT_SRC,				("EOF AS TX1 IRQ\n"));			SK_PNMI_CNT_TX_INTR(pAC,0);			spin_lock(&pAC->TxPort[0][TX_PRIO_LOW].TxDesRingLock);			FreeTxDescriptors(pAC, &pAC->TxPort[0][TX_PRIO_LOW]);			spin_unlock(&pAC->TxPort[0][TX_PRIO_LOW].TxDesRingLock);		}#if 0 /* only if sync. queues used */		if (IntSrc & IRQ_EOF_SY_TX1) {			SK_DBG_MSG(NULL, SK_DBGMOD_DRV,				SK_DBGCAT_DRV_INT_SRC,				("EOF SY TX1 IRQ\n"));			SK_PNMI_CNT_TX_INTR(pAC,1);			spin_lock(&pAC->TxPort[0][TX_PRIO_HIGH].TxDesRingLock);			FreeTxDescriptors(pAC, 0, TX_PRIO_HIGH);			spin_unlock(&pAC->TxPort[0][TX_PRIO_HIGH].TxDesRingLock);			ClearTxIrq(pAC, 0, TX_PRIO_HIGH);		}#endif /* 0 */#endif /* USE_TX_COMPLETE */		/* do all IO at once */		if (IntSrc & IRQ_EOF_RX1)			ClearAndStartRx(pAC, 0);#ifdef USE_TX_COMPLETE /* only if tx complete interrupt used */		if (IntSrc & IRQ_EOF_AS_TX1)			ClearTxIrq(pAC, 0, TX_PRIO_LOW);#endif		SK_IN32(pAC->IoBase, B0_ISRC, &IntSrc);	} /* while (IntSrc & IRQ_MASK != 0) */		if ((IntSrc & SPECIAL_IRQS) || pAC->CheckQueue) {		SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_INT_SRC,			("SPECIAL IRQ\n"));		pAC->CheckQueue = SK_FALSE;		spin_lock(&pAC->SlowPathLock);		if (IntSrc & SPECIAL_IRQS)			SkGeSirqIsr(pAC, pAC->IoBase, IntSrc);		SkEventDispatcher(pAC, pAC->IoBase);		spin_unlock(&pAC->SlowPathLock);	}	/*	 * do it all again is case we cleared an interrupt that 	 * came in after handling the ring (OUTs may be delayed	 * in hardware buffers, but are through after IN)	 */	ReceiveIrq(pAC, &pAC->RxPort[0]);#if 0// #ifdef USE_TX_COMPLETE /* only if tx complete interrupt used */	spin_lock(&pAC->TxPort[0][TX_PRIO_LOW].TxDesRingLock);	FreeTxDescriptors(pAC, &pAC->TxPort[0][TX_PRIO_LOW]);	spin_unlock(&pAC->TxPort[0][TX_PRIO_LOW].TxDesRingLock);#if 0	/* only if sync. queues used */	spin_lock(&pAC->TxPort[0][TX_PRIO_HIGH].TxDesRingLock);	FreeTxDescriptors(pAC, 0, TX_PRIO_HIGH);	spin_unlock(&pAC->TxPort[0][TX_PRIO_HIGH].TxDesRingLock);	#endif /* 0 */#endif /* USE_TX_COMPLETE */	/* IRQ is processed - Enable IRQs again*/	SK_OUT32(pAC->IoBase, B0_IMSK, IRQ_MASK);	return;} /* SkGeIsrOnePort *//**************************************************************************** * *	SkGeOpen - handle start of initialized adapter * * Description: *	This function starts the initialized adapter. *	The board level variable is set and the adapter is *	brought to full functionality. *	The device flags are set for operation. *	Do all necessary level 2 initialization, enable interrupts and *	give start command to RLMT. * * Returns: *	0 on success *	!= 0 on error */static int SkGeOpen(struct net_device	*dev){DEV_NET			*pNet;SK_AC			*pAC;unsigned long	Flags;		/* for spin lock */int		i;SK_EVPARA		EvPara;		/* an event parameter union */	pNet = (DEV_NET*) dev->priv;	pAC = pNet->pAC;		SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,		("SkGeOpen: pAC=0x%lX:\n", (unsigned long)pAC));	if (pAC->BoardLevel == 0) {		/* level 1 init common modules here */		if (SkGeInit(pAC, pAC->IoBase, 1) != 0) {			printk("%s: HWInit(1) failed\n", pAC->dev[pNet->PortNr]->name);			return (-1);		}		SkI2cInit	(pAC, pAC->IoBase, 1);		SkEventInit	(pAC, pAC->IoBase, 1);		SkPnmiInit	(pAC, pAC->IoBase, 1);		SkAddrInit	(pAC, pAC->IoBase, 1);		SkRlmtInit	(pAC, pAC->IoBase, 1);		SkTimerInit	(pAC, pAC->IoBase, 1);		pAC->BoardLevel = 1;	}	if (pAC->BoardLevel != 2) {		/* level 2 init modules here */		SkGeInit	(pAC, pAC->IoBase, 2);		SkI2cInit	(pAC, pAC->IoBase, 2);		SkEventInit	(pAC, pAC->IoBase, 2);		SkPnmiInit	(pAC, pAC->IoBase, 2);		SkAddrInit	(pAC, pAC->IoBase, 2);		SkRlmtInit	(pAC, pAC->IoBase, 2);		SkTimerInit	(pAC, pAC->IoBase, 2);		pAC->BoardLevel = 2;	}	for (i=0; i<pAC->GIni.GIMacsFound; i++) {		/* Enable transmit descriptor polling. */		SkGePollTxD(pAC, pAC->IoBase, i, SK_TRUE);		FillRxRing(pAC, &pAC->RxPort[i]);	}	SkGeYellowLED(pAC, pAC->IoBase, 1);#ifdef USE_INT_MOD/* moderate only TX complete interrupts (these are not time critical) */#define IRQ_MOD_MASK (IRQ_EOF_AS_TX1 | IRQ_EOF_AS_TX2)	{		unsigned long ModBase;		ModBase = 53125000 / INTS_PER_SEC;		SK_OUT32(pAC->IoBase, B2_IRQM_INI, ModBase);		SK_OUT32(pAC->IoBase, B2_IRQM_MSK, IRQ_MOD_MASK);		SK_OUT32(pAC->IoBase, B2_IRQM_CTRL, TIM_START);	}#endif	/* enable Interrupts */	SK_OUT32(pAC->IoBase, B0_IMSK, IRQ_MASK);	SK_OUT32(pAC->IoBase, B0_HWE_IMSK, IRQ_HWE_MASK);	spin_lock_irqsave(&pAC->SlowPathLock, Flags);	if ((pAC->RlmtMode != 0) && (pAC->MaxPorts == 0)) {		EvPara.Para32[0] = pAC->RlmtNets;		EvPara.Para32[1] = -1;		SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_SET_NETS,			EvPara);		EvPara.Para32[0] = pAC->RlmtMode;		EvPara.Para32[1] = 0;		SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_MODE_CHANGE,			EvPara);	}	EvPara.Para32[0] = pNet->NetNr;	EvPara.Para32[1] = -1;	SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_START, EvPara);	SkEventDispatcher(pAC, pAC->IoBase);	spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);	pAC->MaxPorts++;	pNet->Up = 1;	MOD_INC_USE_COUNT;	SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,		("SkGeOpen suceeded\n"));	return (0);} /* SkGeOpen *//**************************************************************************** * *	SkGeClose - Stop initialized adapter * * Description: *	Close initialized adapter. * * Returns: *	0 - on success *	error code - on error */static int SkGeClose(struct net_device	*dev){DEV_NET		*pNet;SK_AC		*pAC;unsigned long	Flags;		/* for spin lock */int				i;int				PortIdx;SK_EVPARA		EvPara;	netif_stop_queue(dev);	pNet = (DEV_NET*) dev->priv;	pAC = pNet->pAC;	if (pAC->RlmtNets == 1)		PortIdx = pAC->ActivePort;	else		PortIdx = pNet->NetNr;	SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,		("SkGeClose: pAC=0x%lX ", (unsigned long)pAC));	/* 	 * Clear multicast table, promiscuous mode ....	 */	 	SkAddrMcClear(pAC, pAC->IoBase, PortIdx, 0);	SkAddrPromiscuousChange(pAC, pAC->IoBase, PortIdx,		SK_PROM_MODE_NONE);	if (pAC->MaxPorts == 1) {		spin_lock_irqsave(&pAC->SlowPathLock, Flags);		/* disable interrupts */		SK_OUT32(pAC->IoBase, B0_IMSK, 0);		EvPara.Para32[0] = pNet->NetNr;		EvPara.Para32[1] = -1;		SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);		SkEventDispatcher(pAC, pAC->IoBase);		SK_OUT32(pAC->IoBase, B0_IMSK, 0);		/* stop the hardware */		SkGeDeInit(pAC, pAC->IoBase);		pAC->BoardLevel = 0;		spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);	} else {		spin_lock_irqsave(&pAC->SlowPathLock, Flags);		EvPara.Para32[0] = pNet->NetNr;		EvPara.Para32[1] = -1;		SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);		SkEventDispatcher(pAC, pAC->IoBase);		spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);				/* Stop port */		spin_lock_irqsave(&pAC->TxPort[pNet->PortNr]			[TX_PRIO_LOW].TxDesRingLock, Flags);		SkGeStopPort(pAC, pAC->IoBase, pNet->PortNr, 			SK_STOP_ALL, SK_HARD_RST);		spin_unlock_irqrestore(&pAC->TxPort[pNet->PortNr]			[TX_PRIO_LOW].TxDesRingLock, Flags);	}	if (pAC->RlmtNets == 1) {		/* clear all descriptor rings */		for (i=0; i<pAC->GIni.GIMacsFound; i++) {			ReceiveIrq(pAC, &pAC->RxPort[i]);			ClearRxRing(pAC, &pAC->RxPort[i]);			ClearTxRing(pAC, &pAC->TxPort[i][TX_PRIO_LOW]);		}	} else {		/* clear port descriptor rings */		ReceiveIrq(pAC, &pAC->RxPort[pNet->PortNr]);		ClearRxRing(pAC, &pAC->RxPort[pNet->PortNr]);		ClearTxRing(pAC, &pAC->TxPort[pNet->PortNr][TX_PRIO_LOW]);	}	SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,		("SkGeClose: done "));	pAC->MaxPorts--;	pNet->Up = 0;	MOD_DEC_USE_COUNT;		return (0);} /* SkGeClose *//***************************************************************************** * * 	SkGeXmit - Linux frame transmit function * * Description: *	The system calls this function to send frames onto the wire. *	It puts the frame in the tx descriptor ring. If the ring is *	full then, the 'tbusy' flag is set. * * Returns: *	0, if everything is ok *	!=0, on error * WARNING: returning 1 in 'tbusy' case caused system crashes (double *	allocated skb's) !!! */static int SkGeXmit(struct sk_buff *skb, struct net_device *dev){DEV_NET		*pNet;SK_AC		*pAC;int			Rc;	/* return code of XmitFrame */		pNet = (DEV_NET*) dev->priv;	pAC = pNet->pAC;	if (pAC->RlmtNets == 2)		Rc = XmitFrame(pAC, &pAC->TxPort[pNet->PortNr][TX_PRIO_LOW], skb);	else		Rc = XmitFrame(pAC, &pAC->TxPort[pAC->ActivePort][TX_PRIO_LOW], skb);	/* Transmitter out of resources? */	if (Rc <= 0)		netif_stop_queue(dev);	/* If not taken, give buffer ownership back to the	 * queueing layer.	 */	if (Rc < 0)		return (1);	dev->trans_start = jiffies;	return (0);} /* SkGeXmit *//***************************************************************************** * * 	XmitFrame - fill one socket buffer into the transmit ring * * Description: *	This function puts a message into the transmit descriptor ring *	if there is a descriptors left. *	Linux skb's consist of only one continuous buffer. *	The first step locks the ring. It is held locked *	all time to avoid problems with SWITCH_../PORT_RESET. *	Then the descriptoris allocated. *	The second part is linking the buffer to the descriptor. *	At the very last, the Control field of the descriptor *	is made valid for the BMU and a start TX command is given *	if necessary. * * Returns: *  > 0 - on succes: the number of bytes in the message *  = 0 - on resource shortage: this frame sent or dropped, now *        the ring is full ( -> set tbusy) *  < 0 - on failure: other problems ( -> return failure to upper layers) */static int XmitFrame(SK_AC 		*pAC,		/* pointer to adapter context */TX_PORT		*pTxPort,	/* pointer to struct of port to send to */struct sk_buff	*pMessage)	/* pointer to send-message */{TXD		*pTxd;		/* the rxd to fill */unsigned long	Flags;SK_U64		PhysAddr;int		BytesSend;	SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_TX_PROGRESS,		("X"));	spin_lock_irqsave(&pTxPort->TxDesRingLock, Flags);	if (pTxPort->TxdRingFree == 0) {		/* no enough free descriptors in ring at the moment */		FreeTxDescriptors(pAC, pTxPort);		if (pTxPort->TxdRingFree == 0) {			spin_unlock_irqrestore(&pTxPort->TxDesRingLock, Flags);			SK_PNMI_CNT_NO_TX_BUF(pAC, pTxPort->PortIndex);			SK_DBG_MSG(NULL, SK_DBGMOD_DRV,				SK_DBGCAT_DRV_TX_PROGRESS,				("XmitFrame failed\n"));			/* this message can not be sent now */			return (-1);		}	}	/* advance head counter behind descriptor needed for this frame */	pTxd = pTxPort->pTxdRingHead;	pTxPort->pTxdRingHead = pTxd->pNextTxd;	pTxPort->TxdRingFree--;	/* the needed descriptor is reserved now */		/* 	 * everything allocated ok, so add buffer to descriptor	 */#ifdef SK_DUMP_TX	DumpMsg(pMessage, "XmitFrame");#endif	/* set up descriptor and CONTROL dword */	PhysAddr = (SK_U64) pci_map_page(&pAC->PciDev,					 virt_to_page(pMessage->data),					 ((unsigned long) pMessage->data &					  ~PAGE_MASK),					 pMessage->len,					 PCI_DMA_TODEVICE);	pTxd->VDataLow = (SK_U32)  (PhysAddr & 0xffffffff);	pTxd->VDataHigh = (SK_U32) (PhysAddr >> 32);	pTxd->pMBuf = pMessage;	pTxd->TBControl = TX_CTRL_OWN_BMU | TX_CTRL_STF |		TX_CTRL_CHECK_DEFAULT | TX_CTRL_SOFTWARE |#ifdef USE_TX_COMPLETE		TX_CTRL_EOF | TX_CTRL_EOF_IRQ | pMessage->len;#else		TX_CTRL_EOF | pMessage->len;#endif		if ((pTxPort->pTxdRingPrev->TBControl & TX_CTRL_OWN_BMU) == 0) {		/* previous descriptor already done, so give tx start cmd */

⌨️ 快捷键说明

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