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

📄 rtmp_init.c

📁 Linux下的RT系列无线网卡驱动,可以直接在x86平台上编译
💻 C
📖 第 1 页 / 共 5 页
字号:
#ifdef BIG_ENDIAN			RTMPDescriptorEndianChange((PUCHAR)pTxD, TYPE_TXD);#endif			// no pre-allocated buffer required in MgmtRing for scatter-gather case		}		DBGPRINT(RT_DEBUG_TRACE, ("MGMT Ring: total %d entry allocated\n", index));		//		// Allocate RX ring descriptor's memory except Tx ring which allocated eariler		//		pAd->RxDescRing.AllocSize = RX_RING_SIZE * RXD_SIZE;		RTMP_AllocateRxDescMemory(			pAd,			pAd->RxDescRing.AllocSize,			FALSE,			&pAd->RxDescRing.AllocVa,			&pAd->RxDescRing.AllocPa);		if (pAd->RxDescRing.AllocVa == NULL)		{			ErrorValue = ERRLOG_OUT_OF_SHARED_MEMORY;			DBGPRINT_ERR(("Failed to allocate a big buffer\n"));			Status = NDIS_STATUS_RESOURCES;			break;		}		// Zero init this memory block		NdisZeroMemory(pAd->RxDescRing.AllocVa, pAd->RxDescRing.AllocSize);		printk("RX DESC %p  size = %ld\n", pAd->RxDescRing.AllocVa,					pAd->RxDescRing.AllocSize);		// Save PA & VA for further operation		RingBasePaHigh = RTMP_GetPhysicalAddressHigh(pAd->RxDescRing.AllocPa);		RingBasePaLow  = RTMP_GetPhysicalAddressLow (pAd->RxDescRing.AllocPa);		RingBaseVa     = pAd->RxDescRing.AllocVa;		//		// Initialize Rx Ring and associated buffer memory		//		for (index = 0; index < RX_RING_SIZE; index++)		{			// Init RX Ring Size, Va, Pa variables			pAd->RxRing.Cell[index].AllocSize = RXD_SIZE;			pAd->RxRing.Cell[index].AllocVa = RingBaseVa;			RTMP_SetPhysicalAddressHigh(pAd->RxRing.Cell[index].AllocPa, RingBasePaHigh);			RTMP_SetPhysicalAddressLow (pAd->RxRing.Cell[index].AllocPa, RingBasePaLow);			//NdisZeroMemory(RingBaseVa, RXD_SIZE);			// Offset to next ring descriptor address			RingBasePaLow += RXD_SIZE;			RingBaseVa = (PUCHAR) RingBaseVa + RXD_SIZE;			// Setup Rx associated Buffer size & allocate share memory			pDmaBuf = &pAd->RxRing.Cell[index].DmaBuf;			pDmaBuf->AllocSize = RX_BUFFER_AGGRESIZE;			pPacket = RTMP_AllocateRxPacketBuffer(				pAd,				pDmaBuf->AllocSize,				FALSE,				&pDmaBuf->AllocVa,				&pDmaBuf->AllocPa);						/* keep allocated rx packet */			pAd->RxRing.Cell[index].pNdisPacket = pPacket;			// Error handling			if (pDmaBuf->AllocVa == NULL)			{				ErrorValue = ERRLOG_OUT_OF_SHARED_MEMORY;				DBGPRINT_ERR(("Failed to allocate RxRing's 1st buffer\n"));				Status = NDIS_STATUS_RESOURCES;				break;			}			// Zero init this memory block			NdisZeroMemory(pDmaBuf->AllocVa, pDmaBuf->AllocSize);			// Write RxD buffer address & allocated buffer length			pRxD = (PRXD_STRUC) pAd->RxRing.Cell[index].AllocVa;			pRxD->SDP0 = RTMP_GetPhysicalAddressLow(pDmaBuf->AllocPa);			pRxD->DDONE = 0;#ifdef RX_SCATTERED			// Setup Rx associated Buffer size & allocate share memory			pDmaBuf = &pAd->RxRing.Cell[index].NextDmaBuf;			pDmaBuf->AllocSize = 2048;			pPacket = RTMP_AllocateRxPacketBuffer(				pAd,				pDmaBuf->AllocSize,				FALSE,				&pDmaBuf->AllocVa,				&pDmaBuf->AllocPa);			pAd->RxRing.Cell[index].pNextNdisPacket = pPacket;			// Error handling			if (pDmaBuf->AllocVa == NULL)			{				ErrorValue = ERRLOG_OUT_OF_SHARED_MEMORY;				DBGPRINT_ERR(("Failed to allocate RxRing's 2nd buffer\n"));				Status = NDIS_STATUS_RESOURCES;				break;			}			// Zero init this memory block			NdisZeroMemory(pDmaBuf->AllocVa, pDmaBuf->AllocSize);			pRxD->SDP1 = RTMP_GetPhysicalAddressLow(pDmaBuf->AllocPa);#endif 						#ifdef BIG_ENDIAN			RTMPDescriptorEndianChange((PUCHAR)pRxD, TYPE_RXD);#endif		}		DBGPRINT(RT_DEBUG_TRACE, ("Rx Ring: total %d entry allocated\n", index));	}	while (FALSE);	NdisZeroMemory(&pAd->FragFrame, sizeof(FRAGMENT_FRAME));	pAd->FragFrame.pFragPacket =  RTMP_AllocateFragPacketBuffer(pAd, RX_BUFFER_NORMSIZE);	if (pAd->FragFrame.pFragPacket == NULL)	{		Status = NDIS_STATUS_RESOURCES;	}	if (Status != NDIS_STATUS_SUCCESS)	{		// Log error inforamtion		NdisWriteErrorLogEntry(			pAd->AdapterHandle,			NDIS_ERROR_CODE_OUT_OF_RESOURCES,			1,			ErrorValue);	}	DBGPRINT_S(Status, ("<-- RTMPAllocDMAMemory, Status=%x\n", Status));	return Status;}/*	========================================================================		Routine Description:		Read initial channel power parameters from EEPROM			Arguments:		Adapter						Pointer to our adapter	Return Value:		None	IRQL = PASSIVE_LEVEL	Note:			========================================================================*/VOID	RTMPReadChannelPwr(	IN	PRTMP_ADAPTER	pAd){	UCHAR				i, choffset;	EEPROM_TX_PWR_STRUC	    Power;	EEPROM_TX_PWR_STRUC	    Power2;		// Read Tx power value for all channels	// Value from 1 - 0x7f. Default value is 24.	// Power value 0xFA (-6) ~ 0x24 (36)		// 0. 11b/g, ch1 - ch 14	for (i = 0; i < 7; i++)	{		Power.word = RTMP_EEPROM_READ16(pAd, EEPROM_G_TX_PWR_OFFSET + i * 2);		Power2.word = RTMP_EEPROM_READ16(pAd, EEPROM_G_TX2_PWR_OFFSET + i * 2);		pAd->TxPower[i * 2].Channel = i * 2 + 1;		pAd->TxPower[i * 2 + 1].Channel = i * 2 + 2;		if ((Power.field.Byte0 > 36) || (Power.field.Byte0 < -6))			pAd->TxPower[i * 2].Power = DEFAULT_RF_TX_POWER;		else			pAd->TxPower[i * 2].Power = Power.field.Byte0;		if ((Power.field.Byte1 > 36) || (Power.field.Byte1 < -6))			pAd->TxPower[i * 2 + 1].Power = DEFAULT_RF_TX_POWER;		else			pAd->TxPower[i * 2 + 1].Power = Power.field.Byte1;		if ((Power2.field.Byte0 > 36) || (Power2.field.Byte0 < -6))			pAd->TxPower[i * 2].Power2 = DEFAULT_RF_TX_POWER;		else			pAd->TxPower[i * 2].Power2 = Power2.field.Byte0;		if ((Power2.field.Byte1 > 36) || (Power2.field.Byte1 < -6))			pAd->TxPower[i * 2 + 1].Power2 = DEFAULT_RF_TX_POWER;		else			pAd->TxPower[i * 2 + 1].Power2 = Power2.field.Byte1;	}		// 1. U-NII lower/middle band: 36, 38, 40; 44, 46, 48; 52, 54, 56; 60, 62, 64 (including central frequency in BW 40MHz)	// 1.1 Fill up channel	choffset = 14;	for (i = 0; i < 4; i++)	{		pAd->TxPower[3 * i + choffset + 0].Channel	= 36 + i * 8 + 0;		pAd->TxPower[3 * i + choffset + 0].Power	= DEFAULT_RF_TX_POWER;		pAd->TxPower[3 * i + choffset + 0].Power2	= DEFAULT_RF_TX_POWER;		pAd->TxPower[3 * i + choffset + 1].Channel	= 36 + i * 8 + 2;		pAd->TxPower[3 * i + choffset + 1].Power	= DEFAULT_RF_TX_POWER;		pAd->TxPower[3 * i + choffset + 1].Power2	= DEFAULT_RF_TX_POWER;		pAd->TxPower[3 * i + choffset + 2].Channel	= 36 + i * 8 + 4;		pAd->TxPower[3 * i + choffset + 2].Power	= DEFAULT_RF_TX_POWER;		pAd->TxPower[3 * i + choffset + 2].Power2	= DEFAULT_RF_TX_POWER;	}	// 1.2 Fill up power	for (i = 0; i < 6; i++)	{		Power.word = RTMP_EEPROM_READ16(pAd, EEPROM_A_TX_PWR_OFFSET + i * 2);		Power2.word = RTMP_EEPROM_READ16(pAd, EEPROM_A_TX2_PWR_OFFSET + i * 2);		if ((Power.field.Byte0 < 36) && (Power.field.Byte0 > -6))			pAd->TxPower[i * 2 + choffset + 0].Power = Power.field.Byte0;		if ((Power.field.Byte1 < 36) && (Power.field.Byte1 > -6))			pAd->TxPower[i * 2 + choffset + 1].Power = Power.field.Byte1;					if ((Power2.field.Byte0 < 36) && (Power2.field.Byte0 > -6))			pAd->TxPower[i * 2 + choffset + 0].Power2 = Power2.field.Byte0;		if ((Power2.field.Byte1 < 36) && (Power2.field.Byte1 > -6))			pAd->TxPower[i * 2 + choffset + 1].Power2 = Power2.field.Byte1;				}		// 2. HipperLAN 2 100, 102 ,104; 108, 110, 112; 116, 118, 120; 124, 126, 128; 132, 134, 136; 140 (including central frequency in BW 40MHz)	// 2.1 Fill up channel	choffset = 14 + 12;	for (i = 0; i < 5; i++)	{		pAd->TxPower[3 * i + choffset + 0].Channel	= 100 + i * 8 + 0;		pAd->TxPower[3 * i + choffset + 0].Power	= DEFAULT_RF_TX_POWER;		pAd->TxPower[3 * i + choffset + 0].Power2	= DEFAULT_RF_TX_POWER;		pAd->TxPower[3 * i + choffset + 1].Channel	= 100 + i * 8 + 2;		pAd->TxPower[3 * i + choffset + 1].Power	= DEFAULT_RF_TX_POWER;		pAd->TxPower[3 * i + choffset + 1].Power2	= DEFAULT_RF_TX_POWER;		pAd->TxPower[3 * i + choffset + 2].Channel	= 100 + i * 8 + 4;		pAd->TxPower[3 * i + choffset + 2].Power	= DEFAULT_RF_TX_POWER;		pAd->TxPower[3 * i + choffset + 2].Power2	= DEFAULT_RF_TX_POWER;	}	pAd->TxPower[3 * 5 + choffset + 0].Channel		= 140;	pAd->TxPower[3 * 5 + choffset + 0].Power		= DEFAULT_RF_TX_POWER;	pAd->TxPower[3 * 5 + choffset + 0].Power2		= DEFAULT_RF_TX_POWER;	// 2.2 Fill up power	for (i = 0; i < 8; i++)	{		Power.word = RTMP_EEPROM_READ16(pAd, EEPROM_A_TX_PWR_OFFSET + (choffset - 14) + i * 2);		Power2.word = RTMP_EEPROM_READ16(pAd, EEPROM_A_TX2_PWR_OFFSET + (choffset - 14) + i * 2);		if ((Power.field.Byte0 < 36) && (Power.field.Byte0 > -6))			pAd->TxPower[i * 2 + choffset + 0].Power = Power.field.Byte0;		if ((Power.field.Byte1 < 36) && (Power.field.Byte1 > -6))			pAd->TxPower[i * 2 + choffset + 1].Power = Power.field.Byte1;					if ((Power2.field.Byte0 < 36) && (Power2.field.Byte0 > -6))			pAd->TxPower[i * 2 + choffset + 0].Power2 = Power2.field.Byte0;		if ((Power2.field.Byte1 < 36) && (Power2.field.Byte1 > -6))			pAd->TxPower[i * 2 + choffset + 1].Power2 = Power2.field.Byte1;				}	// 3. U-NII upper band: 149, 151, 153; 157, 159, 161; 165 (including central frequency in BW 40MHz)	// 3.1 Fill up channel	choffset = 14 + 12 + 16;	for (i = 0; i < 2; i++)	{		pAd->TxPower[3 * i + choffset + 0].Channel	= 149 + i * 8 + 0;		pAd->TxPower[3 * i + choffset + 0].Power	= DEFAULT_RF_TX_POWER;		pAd->TxPower[3 * i + choffset + 0].Power2	= DEFAULT_RF_TX_POWER;		pAd->TxPower[3 * i + choffset + 1].Channel	= 149 + i * 8 + 2;		pAd->TxPower[3 * i + choffset + 1].Power	= DEFAULT_RF_TX_POWER;		pAd->TxPower[3 * i + choffset + 1].Power2	= DEFAULT_RF_TX_POWER;		pAd->TxPower[3 * i + choffset + 2].Channel	= 149 + i * 8 + 4;		pAd->TxPower[3 * i + choffset + 2].Power	= DEFAULT_RF_TX_POWER;		pAd->TxPower[3 * i + choffset + 2].Power2	= DEFAULT_RF_TX_POWER;	}	pAd->TxPower[3 * 2 + choffset + 0].Channel		= 165;	pAd->TxPower[3 * 2 + choffset + 0].Power		= DEFAULT_RF_TX_POWER;	pAd->TxPower[3 * 2 + choffset + 0].Power2		= DEFAULT_RF_TX_POWER;	// 3.2 Fill up power	for (i = 0; i < 4; i++)	{		Power.word = RTMP_EEPROM_READ16(pAd, EEPROM_A_TX_PWR_OFFSET + (choffset - 14) + i * 2);		Power2.word = RTMP_EEPROM_READ16(pAd, EEPROM_A_TX2_PWR_OFFSET + (choffset - 14) + i * 2);		if ((Power.field.Byte0 < 36) && (Power.field.Byte0 > -6))			pAd->TxPower[i * 2 + choffset + 0].Power = Power.field.Byte0;		if ((Power.field.Byte1 < 36) && (Power.field.Byte1 > -6))			pAd->TxPower[i * 2 + choffset + 1].Power = Power.field.Byte1;					if ((Power2.field.Byte0 < 36) && (Power2.field.Byte0 > -6))			pAd->TxPower[i * 2 + choffset + 0].Power2 = Power2.field.Byte0;		if ((Power2.field.Byte1 < 36) && (Power2.field.Byte1 > -6))			pAd->TxPower[i * 2 + choffset + 1].Power2 = Power2.field.Byte1;				}	// 4. Print and Debug	choffset = 14 + 12 + 16 + 7;	for (i = 0; i < choffset; i++)	{		DBGPRINT(RT_DEBUG_INFO, ("E2PROM: TxPower[%03d], Channel = %d, Power = %d, Power2 = %d\n", i, pAd->TxPower[i].Channel, pAd->TxPower[i].Power, pAd->TxPower[i].Power2 ));	}}/*	========================================================================		Routine Description:		Read the following from the registry		1. All the parameters		2. NetworkAddres	Arguments:		Adapter						Pointer to our adapter		WrapperConfigurationContext	For use by NdisOpenConfiguration	Return Value:		NDIS_STATUS_SUCCESS		NDIS_STATUS_FAILURE		NDIS_STATUS_RESOURCES	IRQL = PASSIVE_LEVEL	Note:		========================================================================*/NDIS_STATUS	NICReadRegParameters(	IN	PRTMP_ADAPTER		pAd,	IN	NDIS_HANDLE			WrapperConfigurationContext	){	NDIS_STATUS						Status = NDIS_STATUS_SUCCESS;	DBGPRINT_S(Status, ("<-- NICReadRegParameters, Status=%x\n", Status));	return Status;}/*	========================================================================		Routine Description:		Initialize transmit data structures	Arguments:		Adapter						Pointer to our adapter	Return Value:		None	IRQL = PASSIVE_LEVEL	Note:		Initialize all transmit releated private buffer, include those define		in RTMP_ADAPTER structure and all private data structures.			========================================================================*/VOID	NICInitTxRxRingAndBacklogQueue(	IN	PRTMP_ADAPTER	pAd){	//WPDMA_GLO_CFG_STRUC	GloCfg;	int i;		DBGPRINT(RT_DEBUG_TRACE, ("<--> NICInitTxRxRingAndBacklogQueue\n"));	// Initialize all transmit related software queues	InitializeQueueHeader(&pAd->TxSwQueue[QID_AC_BE]);	InitializeQueueHeader(&pAd->TxSwQueue[QID_AC_BK]);	InitializeQueueHeader(&pAd->TxSwQueue[QID_AC_VI]);	InitializeQueueHeader(&pAd->TxSwQueue[QID_AC_VO]);	InitializeQueueHeader(&pAd->TxSwQueue[QID_HCCA]);	// Disable DMA./*	RTMP_IO_READ32(pAd, WPDMA_GLO_CFG, &GloCfg.word);	GloCfg.word &= 0xff0;	GloCfg.field.EnTXWriteBackDDONE =1;	RTMP_IO_WRITE32(pAd, WPDMA_GLO_CFG, GloCfg.word);*/	// Init RX Ring index pointer	pAd->RxRing.RxSwReadIdx = 0;	pAd->RxRing.RxCpuIdx = RX_RING_SIZE - 1;	//RTMP_IO_WRITE32(pAd, RX_CRX_IDX, pAd->RxRing.RX_CRX_IDX0);		// Init TX rings index pointer		for (i=0; i<NUM_OF_TX_RING; i++)		{			pAd->TxRing[i].TxSwFreeIdx = 0;			pAd->TxRing[i].TxCpuIdx = 0;			//RTMP_IO_WRITE32(pAd, (TX_CTX_IDX0 + i * 0x10) ,  pAd->TxRing[i].TX_CTX_IDX);		}	// init MGMT ring index pointer	pAd->MgmtRing.TxSwFreeIdx = 0;	pAd->MgmtRing.TxCpuIdx = 0;	//RTMP_IO_WRITE32(pAd, TX_MGMTCTX_IDX,  pAd->MgmtRing.TX_CTX_IDX);	pAd->PrivateInfo.TxRingFullCnt       = 0;}/*	========================================================================		Routine Description:		Read initial parameters from EEPROM		

⌨️ 快捷键说明

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