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

📄 rtusb_io.c

📁 TP Link 321 Linux Driver
💻 C
📖 第 1 页 / 共 4 页
字号:
/* *************************************************************************** * Ralink Tech Inc. * 4F, No. 2 Technology	5th	Rd. * Science-based Industrial	Park * Hsin-chu, Taiwan, R.O.C. * * (c) Copyright 2002-2006, Ralink Technology, Inc. * * All rights reserved.	Ralink's source	code is	an unpublished work	and	the * use of a	copyright notice does not imply	otherwise. This	source code * contains	confidential trade secret material of Ralink Tech. Any attemp * or participation	in deciphering,	decoding, reverse engineering or in	any * way altering	the	source code	is stricitly prohibited, unless	the	prior * written consent of Ralink Technology, Inc. is obtained. ***************************************************************************  	Module Name:	rtusb_io.c	Abstract:	Revision History:	Who			When	    What	--------	----------  ----------------------------------------------	Name		Date	    Modification logs	Paul Lin    06-25-2004  created*/#include	"rt_config.h"/*	========================================================================		Routine Description: NIC initialization complete	Arguments:	Return Value:	Note:		========================================================================*/NTSTATUS	RTUSBFirmwareRun(	IN	PRTMP_ADAPTER	pAd){	NTSTATUS	Status;	Status = RTUSB_VendorRequest(		pAd,		0,		DEVICE_VENDOR_REQUEST_OUT,		0x01,		0x8,		0,		NULL,		0);		return Status;}/*	========================================================================		Routine Description: Read various length data from RT2573	Arguments:	Return Value:	Note:		========================================================================*/NTSTATUS	RTUSBMultiRead(	IN	PRTMP_ADAPTER	pAd,	IN	USHORT			Offset,	OUT	PUCHAR			pData,	IN	USHORT			length){	NTSTATUS	Status;//2008/01/07:KH add to solve the racing condition of Mac Registers	wait_queue_head_t wait;	init_waitqueue_head(&wait);			for(;pAd->MacRegWrite_Processing==1;)		wait_event_interruptible_timeout(wait,0,1);	RTUSBMacRegDown(pAd);	Status = RTUSB_VendorRequest(		pAd,		0,		DEVICE_VENDOR_REQUEST_IN,		0x7,		0,		Offset,		pData,		length);	RTUSBMacRegUp(pAd);		return Status;}//iverson 2007 1109NTSTATUS RTUSBSingleWrite(    IN     PRTMP_ADAPTER   pAd,    IN  USHORT                   Offset,    IN  USHORT                   Value){        NTSTATUS        status;        status = RTUSB_VendorRequest(pAd,                0,                DEVICE_VENDOR_REQUEST_OUT,                0x2,                Value,                Offset,                NULL,                0);        return status;}/*	========================================================================		Routine Description: Write various length data to RT2573	Arguments:	Return Value:	Note:		========================================================================*/NTSTATUS	RTUSBMultiWrite(	IN	PRTMP_ADAPTER	pAd,	IN	USHORT			Offset,	IN	PUCHAR			pData,	IN	USHORT			length){	NTSTATUS	Status;        USHORT          index = 0,Value;        PUCHAR          pSrc = pData;        USHORT          resude = 0;//2008/01/07:KH add to solve the racing condition of Mac Registers 	wait_queue_head_t wait;	init_waitqueue_head(&wait);	for(;pAd->MacRegWrite_Processing==1;)		wait_event_interruptible_timeout(wait,0,HZ/1000); 	RTUSBMacRegDown(pAd);        resude = length % 2;        length  += resude ;        do        {                Value =(USHORT)( *pSrc  | (*(pSrc + 1) << 8));                Status = RTUSBSingleWrite(pAd,Offset + index,Value);                index +=2;                length -= 2;                pSrc = pSrc + 2;        }while(length > 0);			RTUSBMacRegUp(pAd);	return Status;}/*	========================================================================		Routine Description: Read 32-bit MAC register	Arguments:	Return Value:	Note:		========================================================================*/NTSTATUS	RTUSBReadMACRegister(	IN	PRTMP_ADAPTER	pAd,	IN	USHORT			Offset,	OUT	PULONG			pValue){	NTSTATUS	Status;#ifdef BIG_ENDIAN			ULONG		Value_Big;#endif//2008/01/07:KH add to solve the racing condition of Mac Registers        wait_queue_head_t wait;	init_waitqueue_head(&wait);			for(;pAd->MacRegWrite_Processing==1;)		wait_event_interruptible_timeout(wait,0,1);		RTUSBMacRegDown(pAd);#ifdef BIG_ENDIAN	Status = RTUSB_VendorRequest(		pAd,		0,		DEVICE_VENDOR_REQUEST_IN,		0x7,		0,		Offset,		&Value_Big,		4);		*pValue = SWAP32(Value_Big);#else	Status = RTUSB_VendorRequest(		pAd,		0,		DEVICE_VENDOR_REQUEST_IN,		0x7,		0,		Offset,		pValue,		4);#endifRTUSBMacRegUp(pAd);	return Status;}/*	========================================================================		Routine Description: Write 32-bit MAC register	Arguments:	Return Value:	Note:		========================================================================*/NTSTATUS	RTUSBWriteMACRegister(	IN	PRTMP_ADAPTER	pAd,	IN	USHORT			Offset,	IN	ULONG			Value){	NTSTATUS	Status;	USHORT	va1;	USHORT	va2;//2008/01/07:KH add to solve the racing condition of Mac Registers	wait_queue_head_t wait;	init_waitqueue_head(&wait);			for(;pAd->MacRegWrite_Processing==1;)		wait_event_interruptible_timeout(wait,0,1);		RTUSBMacRegDown(pAd);		va1=(USHORT)(Value & 0xffff);	va2=(USHORT)((Value & 0xffff0000) >> 16);	Status = RTUSBSingleWrite(pAd, Offset, va1);	Status = RTUSBSingleWrite(pAd, Offset + 2, va2);        RTUSBMacRegUp(pAd);	return Status;}/*	========================================================================		Routine Description: Write 32-bit MAC register	Arguments:	Return Value:	Note:		========================================================================*/NTSTATUS    RTUSBSetLED(	IN	PRTMP_ADAPTER		pAd,	IN	MCU_LEDCS_STRUC		LedStatus,	IN	USHORT				LedIndicatorStrength){	NTSTATUS	Status;//2008/01/07:KH add to solve the racing condition of Mac Registers        wait_queue_head_t wait;	init_waitqueue_head(&wait);	for(;pAd->MacRegWrite_Processing==1;)		wait_event_interruptible_timeout(wait,0,1);		RTUSBMacRegDown(pAd);		Status = RTUSB_VendorRequest(		pAd,		0,		DEVICE_VENDOR_REQUEST_OUT,		0x0a,		LedStatus.word,		LedIndicatorStrength,		NULL,		0);	RTUSBMacRegUp(pAd);	return Status;}/*	========================================================================		Routine Description: Read 8-bit BBP register	Arguments:	Return Value:	Note:		========================================================================*/NTSTATUS	RTUSBReadBBPRegister(	IN	PRTMP_ADAPTER	pAd,	IN	UCHAR			Id,	IN	PUCHAR			pValue){	PHY_CSR3_STRUC	PhyCsr3;	UINT			i = 0;	// Verify the busy condition	do	{		RTUSBReadMACRegister(pAd, PHY_CSR3, &PhyCsr3.word);		if (!(PhyCsr3.field.Busy == BUSY))			break;		i++;	}	while ((i < RETRY_LIMIT) && (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)));		if ((i == RETRY_LIMIT) || (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)))	{		//		// Read failed then Return Default value.		//		*pValue = pAd->BbpWriteLatch[Id];			DBGPRINT_RAW(RT_DEBUG_ERROR, "Retry count exhausted or device removed!!!\n");		return STATUS_UNSUCCESSFUL;	}	// Prepare for write material	PhyCsr3.word 				= 0;	PhyCsr3.field.fRead			= 1;	PhyCsr3.field.Busy			= 1;	PhyCsr3.field.RegNum 		= Id;	RTUSBWriteMACRegister(pAd, PHY_CSR3, PhyCsr3.word);	i = 0;		// Verify the busy condition	do	{		RTUSBReadMACRegister(pAd, PHY_CSR3, &PhyCsr3.word);		if (!(PhyCsr3.field.Busy == BUSY))		{			*pValue = (UCHAR)PhyCsr3.field.Value;			break;		}		i++;	}	while ((i < RETRY_LIMIT) && (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)));		if ((i == RETRY_LIMIT) || (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)))	{		//		// Read failed then Return Default value.		//		*pValue = pAd->BbpWriteLatch[Id];		DBGPRINT_RAW(RT_DEBUG_ERROR, "Retry count exhausted or device removed!!!\n");		return STATUS_UNSUCCESSFUL;	}		return STATUS_SUCCESS;}/*	========================================================================		Routine Description: Write 8-bit BBP register	Arguments:	Return Value:		Note:		========================================================================*/NTSTATUS	RTUSBWriteBBPRegister(	IN	PRTMP_ADAPTER	pAd,	IN	UCHAR			Id,	IN	UCHAR			Value){	PHY_CSR3_STRUC	PhyCsr3;	UINT			i = 0;	// Verify the busy condition	do	{		RTUSBReadMACRegister(pAd, PHY_CSR3, &PhyCsr3.word);		if (!(PhyCsr3.field.Busy == BUSY))			break;		i++;	}	while ((i < RETRY_LIMIT) && (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)));		if ((i == RETRY_LIMIT) || (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)))	{		DBGPRINT_RAW(RT_DEBUG_ERROR, "Retry count exhausted or device removed!!!\n");		return STATUS_UNSUCCESSFUL;	}	// Prepare for write material	PhyCsr3.word 				= 0;	PhyCsr3.field.fRead			= 0;	PhyCsr3.field.Value			= Value;	PhyCsr3.field.Busy			= 1;	PhyCsr3.field.RegNum 		= Id;	RTUSBWriteMACRegister(pAd, PHY_CSR3, PhyCsr3.word);		pAd->BbpWriteLatch[Id] = Value;	return STATUS_SUCCESS;}/*	========================================================================		Routine Description: Write RF register through MAC	Arguments:	Return Value:		Note:		========================================================================*/NTSTATUS	RTUSBWriteRFRegister(	IN	PRTMP_ADAPTER	pAd,	IN	ULONG			Value){	PHY_CSR4_STRUC	PhyCsr4;	UINT			i = 0;	do	{		RTUSBReadMACRegister(pAd, PHY_CSR4, &PhyCsr4.word);		if (!(PhyCsr4.field.Busy))			break;		i++;	}	while ((i < RETRY_LIMIT) && (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)));	if ((i == RETRY_LIMIT) || (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)))	{		DBGPRINT_RAW(RT_DEBUG_ERROR, "Retry count exhausted or device removed!!!\n");		return STATUS_UNSUCCESSFUL;	}	RTUSBWriteMACRegister(pAd, PHY_CSR4, Value);		return STATUS_SUCCESS;}/*	========================================================================		Routine Description:	Arguments:	Return Value:	Note:		========================================================================*/NTSTATUS	RTUSBReadEEPROM(	IN	PRTMP_ADAPTER	pAd,	IN	USHORT			Offset,	OUT	PUCHAR			pData,	IN	USHORT			length){	NTSTATUS	Status;	Status = RTUSB_VendorRequest(		pAd,		0,		DEVICE_VENDOR_REQUEST_IN,		0x9,		0,		Offset,		pData,		length);		return Status;}/*	========================================================================		Routine Description:	Arguments:	Return Value:		Note:		========================================================================*/NTSTATUS	RTUSBWriteEEPROM(	IN	PRTMP_ADAPTER	pAd,	IN	USHORT			Offset,	IN	PUCHAR			pData,	IN	USHORT			length){	NTSTATUS	Status;//2008/01/07:KH add to solve the racing condition of Mac Registers	wait_queue_head_t wait;	init_waitqueue_head(&wait);			for(;pAd->MacRegWrite_Processing==1;)		wait_event_interruptible_timeout(wait,0,1);		RTUSBMacRegDown(pAd);		Status = RTUSB_VendorRequest(		pAd,		0,		DEVICE_VENDOR_REQUEST_OUT,		0x8,		0,		Offset,		pData,

⌨️ 快捷键说明

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