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

📄 rtmp_init.c.bak

📁 Linux下的RT系列无线网卡驱动,可以直接在x86平台上编译
💻 BAK
📖 第 1 页 / 共 5 页
字号:
/* ************************************************************************* * Ralink Tech Inc. * 4F, No. 2 Technology 5th Rd. * Science-based Industrial Park * Hsin-chu, Taiwan, R.O.C. * * (c) Copyright 2002-2007, Ralink Technology, Inc. * * This program is free software; you can redistribute it and/or modify  *  * it under the terms of the GNU General Public License as published by  *  * the Free Software Foundation; either version 2 of the License, or     *  * (at your option) any later version.                                   *  *                                                                       *  * This program is distributed in the hope that it will be useful,       *  * but WITHOUT ANY WARRANTY; without even the implied warranty of        *  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *  * GNU General Public License for more details.                          *  *                                                                       *  * You should have received a copy of the GNU General Public License     *  * along with this program; if not, write to the                         *  * Free Software Foundation, Inc.,                                       *  * 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *  *                                                                       *  ************************************************************************* 	Module Name:	rtmp_init.c	Abstract:	Miniport generic portion header file	Revision History:	Who         When          What	--------    ----------    ----------------------------------------------	Paul Lin    2002-08-01    created    John Chang  2004-08-20    RT2561/2661 use scatter-gather scheme    Jan Lee  2006-09-15    RT2860. Change for 802.11n , EEPROM, Led, BA, HT.*/#include	"rt_config.h"#include 	"firmware.h"//#define BIN_IN_FILE /* use *.bin firmware */UCHAR    BIT8[] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80};ULONG    BIT32[] = {0x00000001, 0x00000002, 0x00000004, 0x00000008,					0x00000010, 0x00000020, 0x00000040, 0x00000080,					0x00000100, 0x00000200, 0x00000400, 0x00000800,					0x00001000, 0x00002000, 0x00004000, 0x00008000,					0x00010000, 0x00020000, 0x00040000, 0x00080000,					0x00100000, 0x00200000, 0x00400000, 0x00800000,					0x01000000, 0x02000000, 0x04000000, 0x08000000,					0x10000000, 0x20000000, 0x40000000, 0x80000000};char*   CipherName[] = {"none","wep64","wep128","TKIP","AES","CKIP64","CKIP128"};const unsigned short ccitt_16Table[] = {	0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50A5, 0x60C6, 0x70E7,	0x8108, 0x9129, 0xA14A, 0xB16B, 0xC18C, 0xD1AD, 0xE1CE, 0xF1EF,	0x1231, 0x0210, 0x3273, 0x2252, 0x52B5, 0x4294, 0x72F7, 0x62D6,	0x9339, 0x8318, 0xB37B, 0xA35A, 0xD3BD, 0xC39C, 0xF3FF, 0xE3DE,	0x2462, 0x3443, 0x0420, 0x1401, 0x64E6, 0x74C7, 0x44A4, 0x5485,	0xA56A, 0xB54B, 0x8528, 0x9509, 0xE5EE, 0xF5CF, 0xC5AC, 0xD58D,	0x3653, 0x2672, 0x1611, 0x0630, 0x76D7, 0x66F6, 0x5695, 0x46B4,	0xB75B, 0xA77A, 0x9719, 0x8738, 0xF7DF, 0xE7FE, 0xD79D, 0xC7BC,	0x48C4, 0x58E5, 0x6886, 0x78A7, 0x0840, 0x1861, 0x2802, 0x3823,	0xC9CC, 0xD9ED, 0xE98E, 0xF9AF, 0x8948, 0x9969, 0xA90A, 0xB92B,	0x5AF5, 0x4AD4, 0x7AB7, 0x6A96, 0x1A71, 0x0A50, 0x3A33, 0x2A12,	0xDBFD, 0xCBDC, 0xFBBF, 0xEB9E, 0x9B79, 0x8B58, 0xBB3B, 0xAB1A,	0x6CA6, 0x7C87, 0x4CE4, 0x5CC5, 0x2C22, 0x3C03, 0x0C60, 0x1C41,	0xEDAE, 0xFD8F, 0xCDEC, 0xDDCD, 0xAD2A, 0xBD0B, 0x8D68, 0x9D49,	0x7E97, 0x6EB6, 0x5ED5, 0x4EF4, 0x3E13, 0x2E32, 0x1E51, 0x0E70,	0xFF9F, 0xEFBE, 0xDFDD, 0xCFFC, 0xBF1B, 0xAF3A, 0x9F59, 0x8F78,	0x9188, 0x81A9, 0xB1CA, 0xA1EB, 0xD10C, 0xC12D, 0xF14E, 0xE16F,	0x1080, 0x00A1, 0x30C2, 0x20E3, 0x5004, 0x4025, 0x7046, 0x6067,	0x83B9, 0x9398, 0xA3FB, 0xB3DA, 0xC33D, 0xD31C, 0xE37F, 0xF35E,	0x02B1, 0x1290, 0x22F3, 0x32D2, 0x4235, 0x5214, 0x6277, 0x7256,	0xB5EA, 0xA5CB, 0x95A8, 0x8589, 0xF56E, 0xE54F, 0xD52C, 0xC50D,	0x34E2, 0x24C3, 0x14A0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405,	0xA7DB, 0xB7FA, 0x8799, 0x97B8, 0xE75F, 0xF77E, 0xC71D, 0xD73C,	0x26D3, 0x36F2, 0x0691, 0x16B0, 0x6657, 0x7676, 0x4615, 0x5634,	0xD94C, 0xC96D, 0xF90E, 0xE92F, 0x99C8, 0x89E9, 0xB98A, 0xA9AB,	0x5844, 0x4865, 0x7806, 0x6827, 0x18C0, 0x08E1, 0x3882, 0x28A3,	0xCB7D, 0xDB5C, 0xEB3F, 0xFB1E, 0x8BF9, 0x9BD8, 0xABBB, 0xBB9A,	0x4A75, 0x5A54, 0x6A37, 0x7A16, 0x0AF1, 0x1AD0, 0x2AB3, 0x3A92,	0xFD2E, 0xED0F, 0xDD6C, 0xCD4D, 0xBDAA, 0xAD8B, 0x9DE8, 0x8DC9,	0x7C26, 0x6C07, 0x5C64, 0x4C45, 0x3CA2, 0x2C83, 0x1CE0, 0x0CC1,	0xEF1F, 0xFF3E, 0xCF5D, 0xDF7C, 0xAF9B, 0xBFBA, 0x8FD9, 0x9FF8,	0x6E17, 0x7E36, 0x4E55, 0x5E74, 0x2E93, 0x3EB2, 0x0ED1, 0x1EF0};#define ByteCRC16(v, crc) \	(unsigned short)((crc << 8) ^  ccitt_16Table[((crc >> 8) ^ (v)) & 255])unsigned char BitReverse(unsigned char x){	int i;	unsigned char Temp=0;	for(i=0; ; i++)	{		if(x & 0x80)	Temp |= 0x80;		if(i==7)		break;		x	<<= 1;		Temp >>= 1;	}	return Temp;}//// BBP register initialization set//BBP_REG_PAIR   BBPRegTable[] = {	{BBP_R65,		0x2C},		// fix rssi issue	{BBP_R66,		0x38},	{BBP_R69,		0x12},	{BBP_R73,		0x10},	{BBP_R81,		0x37},	{BBP_R82,		0x62},	{BBP_R83,		0x6A},	{BBP_R84,		0x99},	{BBP_R105,		0x01},};#define	NUM_BBP_REG_PARMS	(sizeof(BBPRegTable) / sizeof(BBP_REG_PAIR))//// ASIC register initialization sets//RTMP_REG_PAIR	MACRegTable[] =	{#if defined(HW_BEACON_OFFSET) && (HW_BEACON_OFFSET == 0x200)	{BCN_OFFSET0,			0xf8f0e8e0}, /* 0x3800, 0x3A00, 0x3C00, 0x3E00, 512B for each beacon */#elif defined(HW_BEACON_OFFSET) && (HW_BEACON_OFFSET == 0x100)	{BCN_OFFSET0,			0xece8e4e0}, /* 0x3800, 0x3A00, 0x3C00, 0x3E00, 512B for each beacon */	{BCN_OFFSET1,			0xfcf8f4f0}, /* 0x3800, 0x3A00, 0x3C00, 0x3E00, 512B for each beacon */#else    #error You must re-calculate new value for BCN_OFFSET0 & BCN_OFFSET1 in MACRegTable[]!!!#endif // HW_BEACON_OFFSET //	{LEGACY_BASIC_RATE,		0x0000013f}, //  Basic rate set bitmap	{HT_BASIC_RATE,		0x00008003}, // Basic HT rate set , 20M, MCS=3, MM. Format is the same as in TXWI.	{MAC_SYS_CTRL,		0x00}, // 0x1004, , default Disable RX	{RX_FILTR_CFG,		0x17f97}, //0x1400  , RX filter control,  	{BKOFF_SLOT_CFG,	0x209}, // default set short slot time, CC_DELAY_TIME should be 2	 	{TX_SW_CFG0,		0x40a06}, // Gary,2006-08-23 	{TX_SW_CFG1,		0x80606}, // Gary,2006-08-23 	{TX_LINK_CFG,		0x1020},		// Gary,2006-08-23 	{TX_TIMEOUT_CFG,	0x00182090},	// CCK has some problem. So increase timieout value. 2006-10-09// MArvek RT	{MAX_LEN_CFG,		MAX_AGGREGATION_SIZE | 0x00001000},	// 0x3018, MAX frame length. Max PSDU = 16kbytes.	{LED_CFG,		0x7f031e46}, // Gary, 2006-08-23#ifdef CONFIG_STA_SUPPORT	{WMM_AIFSN_CFG,		0x00002273},	{WMM_CWMIN_CFG,		0x00002344},	{WMM_CWMAX_CFG,		0x000034aa},#endif // CONFIG_STA_SUPPORT //	{PBF_MAX_PCNT,			0x1F3FBF9F}, 	//0x1F3f7f9f},		//Jan, 2006/04/20	{TX_RTY_CFG,			0x6bb80408},	// Jan, 2006/11/16	{AUTO_RSP_CFG,			0x00000013},	// Initial Auto_Responder, because QA will turn off Auto-Responder	{CCK_PROT_CFG,			0x05740003 /*0x01740003*/},	// Initial Auto_Responder, because QA will turn off Auto-Responder. And RTS threshold is enabled. 	{OFDM_PROT_CFG,			0x05740003 /*0x01740003*/},	// Initial Auto_Responder, because QA will turn off Auto-Responder. And RTS threshold is enabled. 	{GF20_PROT_CFG,			0x01744004},    // set 19:18 --> Short NAV for MIMO PS	{GF40_PROT_CFG,			0x03F44084},    	{MM20_PROT_CFG,			0x01744004},    	{MM40_PROT_CFG,			0x03F54084},		{TXOP_CTRL_CFG,			0x000024bf},	//Extension channel backoff.	{TX_RTS_CFG,			0x00092b20},	//#ifdef WIFI_TEST	{EXP_ACK_TIME,			0x002400ca},	// default value//#else//	{EXP_ACK_TIME,			0x005400ca},	// suggested by Gray @ 20070323 for 11n intel-sta throughput//#endif // end - WIFI_TEST //};#define	NUM_MAC_REG_PARMS	(sizeof(MACRegTable) / sizeof(RTMP_REG_PAIR))#define FIRMWAREIMAGE_LENGTH		(sizeof (FirmwareImage) / sizeof(UCHAR))#define FIRMWARE_MAJOR_VERSION	0#define FIRMWARE_MINOR_VERSION	2/*	========================================================================		Routine Description:		Allocate RTMP_ADAPTER data block and do some initialization	Arguments:		Adapter		Pointer to our adapter	Return Value:		NDIS_STATUS_SUCCESS		NDIS_STATUS_FAILURE	IRQL = PASSIVE_LEVEL	Note:		========================================================================*/NDIS_STATUS	RTMPAllocAdapterBlock(	IN  PVOID	handle,	OUT	PRTMP_ADAPTER	*ppAdapter){	PRTMP_ADAPTER	pAd;	NDIS_STATUS		Status;	DBGPRINT(RT_DEBUG_TRACE, ("--> RTMPAllocAdapterBlock\n"));	*ppAdapter = NULL;	do	{		// Allocate RTMP_ADAPTER memory block		Status = AdapterBlockAllocateMemory(handle, (PVOID *)&pAd);		if (Status != NDIS_STATUS_SUCCESS)		{			DBGPRINT_ERR(("Failed to allocate memory - ADAPTER\n"));			break;		}		printk("\n\n=== pAd = %p, size = %d ===\n\n", pAd, (UINT32)sizeof(RTMP_ADAPTER));		// Init spin locks		NdisAllocateSpinLock(&pAd->TxRingLock);		NdisAllocateSpinLock(&pAd->MgmtRingLock);		NdisAllocateSpinLock(&pAd->RxRingLock);		NdisAllocateSpinLock(&pAd->TxSwQueueLock);		NdisAllocateSpinLock(&pAd->LocalTxBufQueueLock);		NdisAllocateSpinLock(&pAd->irq_lock);	} while (FALSE);	*ppAdapter = pAd;	DBGPRINT_S(Status, ("<-- RTMPAllocAdapterBlock, Status=%x\n", Status));	return Status;}/*	========================================================================		Routine Description:		Allocate DMA memory blocks for send, receive	Arguments:		Adapter		Pointer to our adapter	Return Value:		NDIS_STATUS_SUCCESS		NDIS_STATUS_FAILURE		NDIS_STATUS_RESOURCES	IRQL = PASSIVE_LEVEL	Note:		========================================================================*/NDIS_STATUS	RTMPAllocDMAMemory(	IN	PRTMP_ADAPTER	pAd){	NDIS_STATUS		Status = NDIS_STATUS_SUCCESS;	ULONG			RingBasePaHigh;	ULONG			RingBasePaLow;	PVOID			RingBaseVa;	INT				index, num;	PTXD_STRUC		pTxD;	PRXD_STRUC		pRxD;	ULONG			ErrorValue = 0;	PRTMP_TX_RING	pTxRing;	PRTMP_DMABUF	pDmaBuf;	PNDIS_PACKET	pPacket;//	PRTMP_REORDERBUF	pReorderBuf;	DBGPRINT(RT_DEBUG_TRACE, ("--> RTMPAllocDMAMemory\n"));	do	{		//		// Allocate all ring descriptors, include TxD, RxD, MgmtD.		// Although each size is different, to prevent cacheline and alignment		// issue, I intentional set them all to 64 bytes.		//		for (num=0; num<NUM_OF_TX_RING; num++)		{			ULONG  BufBasePaHigh;			ULONG  BufBasePaLow;			PVOID  BufBaseVa;						// 			// Allocate Tx ring descriptor's memory (5 TX rings = 4 ACs + 1 HCCA)			//			pAd->TxDescRing[num].AllocSize = TX_RING_SIZE * TXD_SIZE;			RTMP_AllocateTxDescMemory(				pAd,				num,				pAd->TxDescRing[num].AllocSize,				FALSE,				&pAd->TxDescRing[num].AllocVa,				&pAd->TxDescRing[num].AllocPa);			if (pAd->TxDescRing[num].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->TxDescRing[num].AllocVa, pAd->TxDescRing[num].AllocSize);			// Save PA & VA for further operation			RingBasePaHigh = RTMP_GetPhysicalAddressHigh(pAd->TxDescRing[num].AllocPa);			RingBasePaLow  = RTMP_GetPhysicalAddressLow (pAd->TxDescRing[num].AllocPa);			RingBaseVa     = pAd->TxDescRing[num].AllocVa;			// 			// Allocate all 1st TXBuf's memory for this TxRing			//			pAd->TxBufSpace[num].AllocSize = TX_RING_SIZE * TX_DMA_1ST_BUFFER_SIZE;			RTMP_AllocateFirstTxBuffer(				pAd,				num,				pAd->TxBufSpace[num].AllocSize,				FALSE,				&pAd->TxBufSpace[num].AllocVa,				&pAd->TxBufSpace[num].AllocPa);			if (pAd->TxBufSpace[num].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->TxBufSpace[num].AllocVa, pAd->TxBufSpace[num].AllocSize);			// Save PA & VA for further operation			BufBasePaHigh = RTMP_GetPhysicalAddressHigh(pAd->TxBufSpace[num].AllocPa);			BufBasePaLow  = RTMP_GetPhysicalAddressLow (pAd->TxBufSpace[num].AllocPa);			BufBaseVa     = pAd->TxBufSpace[num].AllocVa;			//			// Initialize Tx Ring Descriptor and associated buffer memory			//			pTxRing = &pAd->TxRing[num];			for (index = 0; index < TX_RING_SIZE; index++)			{				pTxRing->Cell[index].pNdisPacket = NULL;				pTxRing->Cell[index].pNextNdisPacket = NULL;				// Init Tx Ring Size, Va, Pa variables				pTxRing->Cell[index].AllocSize = TXD_SIZE;				pTxRing->Cell[index].AllocVa = RingBaseVa;				RTMP_SetPhysicalAddressHigh(pTxRing->Cell[index].AllocPa, RingBasePaHigh);				RTMP_SetPhysicalAddressLow (pTxRing->Cell[index].AllocPa, RingBasePaLow);				// Setup Tx Buffer size & address. only 802.11 header will store in this space				pDmaBuf = &pTxRing->Cell[index].DmaBuf;				pDmaBuf->AllocSize = TX_DMA_1ST_BUFFER_SIZE;				pDmaBuf->AllocVa = BufBaseVa;				RTMP_SetPhysicalAddressHigh(pDmaBuf->AllocPa, BufBasePaHigh);				RTMP_SetPhysicalAddressLow(pDmaBuf->AllocPa, BufBasePaLow);				// link the pre-allocated TxBuf to TXD				pTxD = (PTXD_STRUC) pTxRing->Cell[index].AllocVa;				pTxD->SDPtr0 = BufBasePaLow;				// advance to next ring descriptor address				pTxD->DMADONE = 1;#ifdef BIG_ENDIAN				RTMPDescriptorEndianChange((PUCHAR)pTxD, TYPE_TXD);#endif				RingBasePaLow += TXD_SIZE;				RingBaseVa = (PUCHAR) RingBaseVa + TXD_SIZE;				// advance to next TxBuf address				BufBasePaLow += TX_DMA_1ST_BUFFER_SIZE;				BufBaseVa = (PUCHAR) BufBaseVa + TX_DMA_1ST_BUFFER_SIZE;			}			DBGPRINT(RT_DEBUG_TRACE, ("TxRing[%d]: total %d entry allocated\n", num, index));		}		if (Status == NDIS_STATUS_RESOURCES)			break;		//		// Allocate MGMT ring descriptor's memory except Tx ring which allocated eariler		//		pAd->MgmtDescRing.AllocSize = MGMT_RING_SIZE * TXD_SIZE;		RTMP_AllocateMgmtDescMemory(			pAd,			pAd->MgmtDescRing.AllocSize,			FALSE,			&pAd->MgmtDescRing.AllocVa,			&pAd->MgmtDescRing.AllocPa);		if (pAd->MgmtDescRing.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->MgmtDescRing.AllocVa, pAd->MgmtDescRing.AllocSize);		// Save PA & VA for further operation		RingBasePaHigh = RTMP_GetPhysicalAddressHigh(pAd->MgmtDescRing.AllocPa);		RingBasePaLow  = RTMP_GetPhysicalAddressLow (pAd->MgmtDescRing.AllocPa);		RingBaseVa     = pAd->MgmtDescRing.AllocVa;		//		// Initialize MGMT Ring and associated buffer memory		//		for (index = 0; index < MGMT_RING_SIZE; index++)		{			pAd->MgmtRing.Cell[index].pNdisPacket = NULL;			pAd->MgmtRing.Cell[index].pNextNdisPacket = NULL;			// Init MGMT Ring Size, Va, Pa variables			pAd->MgmtRing.Cell[index].AllocSize = TXD_SIZE;			pAd->MgmtRing.Cell[index].AllocVa = RingBaseVa;			RTMP_SetPhysicalAddressHigh(pAd->MgmtRing.Cell[index].AllocPa, RingBasePaHigh);			RTMP_SetPhysicalAddressLow (pAd->MgmtRing.Cell[index].AllocPa, RingBasePaLow);			// Offset to next ring descriptor address			RingBasePaLow += TXD_SIZE;			RingBaseVa = (PUCHAR) RingBaseVa + TXD_SIZE;			// link the pre-allocated TxBuf to TXD			pTxD = (PTXD_STRUC) pAd->MgmtRing.Cell[index].AllocVa;			pTxD->DMADONE = 1;

⌨️ 快捷键说明

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