2 *************************************************************************
4 * 5F., No.36, Taiyuan St., Jhubei City,
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
25 *************************************************************************
34 -------- ---------- ----------------------------------------------
35 Name Date Modification logs
36 Paul Lin 06-25-2004 created
39 #include "../rt_config.h"
43 ========================================================================
45 Routine Description: NIC initialization complete
55 ========================================================================
58 NTSTATUS
RTUSBFirmwareRun(
63 Status
= RTUSB_VendorRequest(
65 USBD_TRANSFER_DIRECTION_OUT
,
66 DEVICE_VENDOR_REQUEST_OUT
,
79 ========================================================================
81 Routine Description: Write Firmware to NIC.
91 ========================================================================
93 NTSTATUS
RTUSBFirmwareWrite(
103 Status
= RTUSBReadMACRegister(pAd
, MAC_CSR0
, &MacReg
);
107 RTUSBMultiWrite(pAd
, FIRMWARE_IMAGE_BASE
, pFwImage
, writeLen
);
109 Status
= RTUSBWriteMACRegister(pAd
, 0x7014, 0xffffffff);
110 Status
= RTUSBWriteMACRegister(pAd
, 0x701c, 0xffffffff);
111 Status
= RTUSBFirmwareRun(pAd
);
118 ========================================================================
120 Routine Description: Get current firmware operation mode (Return Value)
125 0 or 1 = Downloaded by host driver
126 others = Driver doesn't download firmware
132 ========================================================================
134 NTSTATUS
RTUSBFirmwareOpmode(
135 IN PRTMP_ADAPTER pAd
,
140 Status
= RTUSB_VendorRequest(
142 (USBD_TRANSFER_DIRECTION_IN
| USBD_SHORT_TRANSFER_OK
),
143 DEVICE_VENDOR_REQUEST_IN
,
151 NTSTATUS
RTUSBVenderReset(
152 IN PRTMP_ADAPTER pAd
)
155 DBGPRINT_RAW(RT_DEBUG_ERROR
, ("-->RTUSBVenderReset\n"));
156 Status
= RTUSB_VendorRequest(
158 USBD_TRANSFER_DIRECTION_OUT
,
159 DEVICE_VENDOR_REQUEST_OUT
,
166 DBGPRINT_RAW(RT_DEBUG_ERROR
, ("<--RTUSBVenderReset\n"));
170 ========================================================================
172 Routine Description: Read various length data from RT2573
182 ========================================================================
184 NTSTATUS
RTUSBMultiRead(
185 IN PRTMP_ADAPTER pAd
,
192 Status
= RTUSB_VendorRequest(
194 (USBD_TRANSFER_DIRECTION_IN
| USBD_SHORT_TRANSFER_OK
),
195 DEVICE_VENDOR_REQUEST_IN
,
206 ========================================================================
208 Routine Description: Write various length data to RT2573
218 ========================================================================
220 NTSTATUS
RTUSBMultiWrite_OneByte(
221 IN PRTMP_ADAPTER pAd
,
227 // TODO: In 2870, use this funciton carefully cause it's not stable.
228 Status
= RTUSB_VendorRequest(
230 USBD_TRANSFER_DIRECTION_OUT
,
231 DEVICE_VENDOR_REQUEST_OUT
,
241 NTSTATUS
RTUSBMultiWrite(
242 IN PRTMP_ADAPTER pAd
,
250 USHORT index
= 0,Value
;
258 Value
=(USHORT
)( *pSrc
| (*(pSrc
+ 1) << 8));
259 Status
= RTUSBSingleWrite(pAd
,Offset
+ index
,Value
);
269 NTSTATUS
RTUSBSingleWrite(
270 IN RTMP_ADAPTER
*pAd
,
276 Status
= RTUSB_VendorRequest(
278 USBD_TRANSFER_DIRECTION_OUT
,
279 DEVICE_VENDOR_REQUEST_OUT
,
292 ========================================================================
294 Routine Description: Read 32-bit MAC register
304 ========================================================================
306 NTSTATUS
RTUSBReadMACRegister(
307 IN PRTMP_ADAPTER pAd
,
314 Status
= RTUSB_VendorRequest(
316 (USBD_TRANSFER_DIRECTION_IN
| USBD_SHORT_TRANSFER_OK
),
317 DEVICE_VENDOR_REQUEST_IN
,
324 *pValue
= le2cpu32(localVal
);
328 *pValue
= 0xffffffff;
335 ========================================================================
337 Routine Description: Write 32-bit MAC register
347 ========================================================================
349 NTSTATUS
RTUSBWriteMACRegister(
350 IN PRTMP_ADAPTER pAd
,
359 Status
= RTUSBSingleWrite(pAd
, Offset
, (USHORT
)(localVal
& 0xffff));
360 Status
= RTUSBSingleWrite(pAd
, Offset
+ 2, (USHORT
)((localVal
& 0xffff0000) >> 16));
369 ========================================================================
371 Routine Description: Read 8-bit BBP register
381 ========================================================================
383 NTSTATUS
RTUSBReadBBPRegister(
384 IN PRTMP_ADAPTER pAd
,
388 BBP_CSR_CFG_STRUC BbpCsr
;
392 // Verify the busy condition
395 status
= RTUSBReadMACRegister(pAd
, BBP_CSR_CFG
, &BbpCsr
.word
);
398 if (!(BbpCsr
.field
.Busy
== BUSY
))
401 printk("RTUSBReadBBPRegister(BBP_CSR_CFG_1):retry count=%d!\n", i
);
404 while ((i
< RETRY_LIMIT
) && (!RTMP_TEST_FLAG(pAd
, fRTMP_ADAPTER_NIC_NOT_EXIST
)));
406 if ((i
== RETRY_LIMIT
) || (RTMP_TEST_FLAG(pAd
, fRTMP_ADAPTER_NIC_NOT_EXIST
)))
409 // Read failed then Return Default value.
411 *pValue
= pAd
->BbpWriteLatch
[Id
];
413 DBGPRINT_RAW(RT_DEBUG_ERROR
, ("Retry count exhausted or device removed!!!\n"));
414 return STATUS_UNSUCCESSFUL
;
417 // Prepare for write material
419 BbpCsr
.field
.fRead
= 1;
420 BbpCsr
.field
.Busy
= 1;
421 BbpCsr
.field
.RegNum
= Id
;
422 RTUSBWriteMACRegister(pAd
, BBP_CSR_CFG
, BbpCsr
.word
);
425 // Verify the busy condition
428 status
= RTUSBReadMACRegister(pAd
, BBP_CSR_CFG
, &BbpCsr
.word
);
431 if (!(BbpCsr
.field
.Busy
== BUSY
))
433 *pValue
= (UCHAR
)BbpCsr
.field
.Value
;
437 printk("RTUSBReadBBPRegister(BBP_CSR_CFG_2):retry count=%d!\n", i
);
440 while ((i
< RETRY_LIMIT
) && (!RTMP_TEST_FLAG(pAd
, fRTMP_ADAPTER_NIC_NOT_EXIST
)));
442 if ((i
== RETRY_LIMIT
) || (RTMP_TEST_FLAG(pAd
, fRTMP_ADAPTER_NIC_NOT_EXIST
)))
445 // Read failed then Return Default value.
447 *pValue
= pAd
->BbpWriteLatch
[Id
];
449 DBGPRINT_RAW(RT_DEBUG_ERROR
, ("Retry count exhausted or device removed!!!\n"));
450 return STATUS_UNSUCCESSFUL
;
453 return STATUS_SUCCESS
;
457 ========================================================================
459 Routine Description: Read 8-bit BBP register via firmware
469 ========================================================================
471 NTSTATUS
RTUSBReadBBPRegister(
472 IN PRTMP_ADAPTER pAd
,
476 BBP_CSR_CFG_STRUC BbpCsr
;
478 for (i
=0; i
<MAX_BUSY_COUNT
; i
++)
480 RTUSBReadMACRegister(pAd
, H2M_BBP_AGENT
, &BbpCsr
.word
);
481 if (BbpCsr
.field
.Busy
== BUSY
)
486 BbpCsr
.field
.fRead
= 1;
487 BbpCsr
.field
.BBP_RW_MODE
= 1;
488 BbpCsr
.field
.Busy
= 1;
489 BbpCsr
.field
.RegNum
= Id
;
490 RTUSBWriteMACRegister(pAd
, H2M_BBP_AGENT
, BbpCsr
.word
);
491 AsicSendCommandToMcu(pAd
, 0x80, 0xff, 0x0, 0x0);
492 for (k
=0; k
<MAX_BUSY_COUNT
; k
++)
494 RTUSBReadMACRegister(pAd
, H2M_BBP_AGENT
, &BbpCsr
.word
);
495 if (BbpCsr
.field
.Busy
== IDLE
)
498 if ((BbpCsr
.field
.Busy
== IDLE
) &&
499 (BbpCsr
.field
.RegNum
== Id
))
501 *pValue
= (UCHAR
)BbpCsr
.field
.Value
;
505 if (BbpCsr
.field
.Busy
== BUSY
)
507 DBGPRINT_ERR(("BBP read R%d=0x%x fail\n", Id
, BbpCsr
.word
));
508 *pValue
= pAd
->BbpWriteLatch
[Id
];
509 return STATUS_UNSUCCESSFUL
;
511 return STATUS_SUCCESS
;
517 ========================================================================
519 Routine Description: Write 8-bit BBP register
529 ========================================================================
531 NTSTATUS
RTUSBWriteBBPRegister(
532 IN PRTMP_ADAPTER pAd
,
536 BBP_CSR_CFG_STRUC BbpCsr
;
539 // Verify the busy condition
542 status
= RTUSBReadMACRegister(pAd
, BBP_CSR_CFG
, &BbpCsr
.word
);
545 if (!(BbpCsr
.field
.Busy
== BUSY
))
548 printk("RTUSBWriteBBPRegister(BBP_CSR_CFG):retry count=%d!\n", i
);
551 while ((i
< RETRY_LIMIT
) && (!RTMP_TEST_FLAG(pAd
, fRTMP_ADAPTER_NIC_NOT_EXIST
)));
553 if ((i
== RETRY_LIMIT
) || (RTMP_TEST_FLAG(pAd
, fRTMP_ADAPTER_NIC_NOT_EXIST
)))
555 DBGPRINT_RAW(RT_DEBUG_ERROR
, ("Retry count exhausted or device removed!!!\n"));
556 return STATUS_UNSUCCESSFUL
;
559 // Prepare for write material
561 BbpCsr
.field
.fRead
= 0;
562 BbpCsr
.field
.Value
= Value
;
563 BbpCsr
.field
.Busy
= 1;
564 BbpCsr
.field
.RegNum
= Id
;
565 RTUSBWriteMACRegister(pAd
, BBP_CSR_CFG
, BbpCsr
.word
);
567 pAd
->BbpWriteLatch
[Id
] = Value
;
569 return STATUS_SUCCESS
;
573 ========================================================================
575 Routine Description: Write 8-bit BBP register via firmware
585 ========================================================================
588 NTSTATUS
RTUSBWriteBBPRegister(
589 IN PRTMP_ADAPTER pAd
,
594 BBP_CSR_CFG_STRUC BbpCsr
;
596 for (BusyCnt
=0; BusyCnt
<MAX_BUSY_COUNT
; BusyCnt
++)
598 RTMP_IO_READ32(pAd
, H2M_BBP_AGENT
, &BbpCsr
.word
);
599 if (BbpCsr
.field
.Busy
== BUSY
)
602 BbpCsr
.field
.fRead
= 0;
603 BbpCsr
.field
.BBP_RW_MODE
= 1;
604 BbpCsr
.field
.Busy
= 1;
605 BbpCsr
.field
.Value
= Value
;
606 BbpCsr
.field
.RegNum
= Id
;
607 RTMP_IO_WRITE32(pAd
, H2M_BBP_AGENT
, BbpCsr
.word
);
608 AsicSendCommandToMcu(pAd
, 0x80, 0xff, 0x0, 0x0);
609 pAd
->BbpWriteLatch
[Id
] = Value
;
612 if (BusyCnt
== MAX_BUSY_COUNT
)
614 DBGPRINT_ERR(("BBP write R%d=0x%x fail\n", Id
, BbpCsr
.word
));
615 return STATUS_UNSUCCESSFUL
;
617 return STATUS_SUCCESS
;
621 ========================================================================
623 Routine Description: Write RF register through MAC
633 ========================================================================
635 NTSTATUS
RTUSBWriteRFRegister(
636 IN PRTMP_ADAPTER pAd
,
639 PHY_CSR4_STRUC PhyCsr4
;
643 NdisZeroMemory(&PhyCsr4
, sizeof(PHY_CSR4_STRUC
));
646 status
= RTUSBReadMACRegister(pAd
, RF_CSR_CFG0
, &PhyCsr4
.word
);
649 if (!(PhyCsr4
.field
.Busy
))
652 printk("RTUSBWriteRFRegister(RF_CSR_CFG0):retry count=%d!\n", i
);
655 while ((i
< RETRY_LIMIT
) && (!RTMP_TEST_FLAG(pAd
, fRTMP_ADAPTER_NIC_NOT_EXIST
)));
657 if ((i
== RETRY_LIMIT
) || (RTMP_TEST_FLAG(pAd
, fRTMP_ADAPTER_NIC_NOT_EXIST
)))
659 DBGPRINT_RAW(RT_DEBUG_ERROR
, ("Retry count exhausted or device removed!!!\n"));
660 return STATUS_UNSUCCESSFUL
;
663 RTUSBWriteMACRegister(pAd
, RF_CSR_CFG0
, Value
);
665 return STATUS_SUCCESS
;
669 ========================================================================
671 Routine Description: Write RT3070 RF register through MAC
681 ========================================================================
683 NTSTATUS
RT30xxWriteRFRegister(
684 IN PRTMP_ADAPTER pAd
,
688 RF_CSR_CFG_STRUC rfcsr
;
693 RTUSBReadMACRegister(pAd
, RF_CSR_CFG
, &rfcsr
.word
);
695 if (!rfcsr
.field
.RF_CSR_KICK
)
699 while ((i
< RETRY_LIMIT
) && (!RTMP_TEST_FLAG(pAd
, fRTMP_ADAPTER_NIC_NOT_EXIST
)));
701 if ((i
== RETRY_LIMIT
) || (RTMP_TEST_FLAG(pAd
, fRTMP_ADAPTER_NIC_NOT_EXIST
)))
703 DBGPRINT_RAW(RT_DEBUG_ERROR
, ("Retry count exhausted or device removed!!!\n"));
704 return STATUS_UNSUCCESSFUL
;
707 rfcsr
.field
.RF_CSR_WR
= 1;
708 rfcsr
.field
.RF_CSR_KICK
= 1;
709 rfcsr
.field
.TESTCSR_RFACC_REGNUM
= RegID
;
710 rfcsr
.field
.RF_CSR_DATA
= Value
;
712 RTUSBWriteMACRegister(pAd
, RF_CSR_CFG
, rfcsr
.word
);
714 return STATUS_SUCCESS
;
718 ========================================================================
720 Routine Description: Read RT3070 RF register through MAC
730 ========================================================================
732 NTSTATUS
RT30xxReadRFRegister(
733 IN PRTMP_ADAPTER pAd
,
737 RF_CSR_CFG_STRUC rfcsr
;
740 for (i
=0; i
<MAX_BUSY_COUNT
; i
++)
742 RTUSBReadMACRegister(pAd
, RF_CSR_CFG
, &rfcsr
.word
);
744 if (rfcsr
.field
.RF_CSR_KICK
== BUSY
)
749 rfcsr
.field
.RF_CSR_WR
= 0;
750 rfcsr
.field
.RF_CSR_KICK
= 1;
751 rfcsr
.field
.TESTCSR_RFACC_REGNUM
= RegID
;
752 RTUSBWriteMACRegister(pAd
, RF_CSR_CFG
, rfcsr
.word
);
753 for (k
=0; k
<MAX_BUSY_COUNT
; k
++)
755 RTUSBReadMACRegister(pAd
, RF_CSR_CFG
, &rfcsr
.word
);
757 if (rfcsr
.field
.RF_CSR_KICK
== IDLE
)
760 if ((rfcsr
.field
.RF_CSR_KICK
== IDLE
) &&
761 (rfcsr
.field
.TESTCSR_RFACC_REGNUM
== RegID
))
763 *pValue
= (UCHAR
)rfcsr
.field
.RF_CSR_DATA
;
767 if (rfcsr
.field
.RF_CSR_KICK
== BUSY
)
769 DBGPRINT_ERR(("RF read R%d=0x%x fail\n", RegID
, rfcsr
.word
));
770 return STATUS_UNSUCCESSFUL
;
773 return STATUS_SUCCESS
;
777 ========================================================================
789 ========================================================================
791 NTSTATUS
RTUSBReadEEPROM(
792 IN PRTMP_ADAPTER pAd
,
797 NTSTATUS Status
= STATUS_SUCCESS
;
799 Status
= RTUSB_VendorRequest(
801 (USBD_TRANSFER_DIRECTION_IN
| USBD_SHORT_TRANSFER_OK
),
802 DEVICE_VENDOR_REQUEST_IN
,
813 ========================================================================
825 ========================================================================
827 NTSTATUS
RTUSBWriteEEPROM(
828 IN PRTMP_ADAPTER pAd
,
833 NTSTATUS Status
= STATUS_SUCCESS
;
835 Status
= RTUSB_VendorRequest(
837 USBD_TRANSFER_DIRECTION_OUT
,
838 DEVICE_VENDOR_REQUEST_OUT
,
849 ========================================================================
861 ========================================================================
863 VOID
RTUSBPutToSleep(
864 IN PRTMP_ADAPTER pAd
)
868 // Timeout 0x40 x 50us
869 value
= (SLEEPCID
<<16)+(OWNERMCU
<<24)+ (0x40<<8)+1;
870 RTUSBWriteMACRegister(pAd
, 0x7010, value
);
871 RTUSBWriteMACRegister(pAd
, 0x404, 0x30);
872 //RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS);
873 DBGPRINT_RAW(RT_DEBUG_ERROR
, ("Sleep Mailbox testvalue %x\n", value
));
878 ========================================================================
890 ========================================================================
892 NTSTATUS
RTUSBWakeUp(
893 IN PRTMP_ADAPTER pAd
)
897 Status
= RTUSB_VendorRequest(
899 USBD_TRANSFER_DIRECTION_OUT
,
900 DEVICE_VENDOR_REQUEST_OUT
,
911 ========================================================================
923 ========================================================================
925 VOID
RTUSBInitializeCmdQ(
931 cmdq
->CmdQState
= RT2870_THREAD_INITED
;
935 ========================================================================
947 ========================================================================
949 NDIS_STATUS
RTUSBEnqueueCmdFromNdis(
950 IN PRTMP_ADAPTER pAd
,
952 IN BOOLEAN SetInformation
,
953 IN PVOID pInformationBuffer
,
954 IN UINT32 InformationBufferLength
)
957 PCmdQElmt cmdqelmt
= NULL
;
958 POS_COOKIE pObj
= (POS_COOKIE
) pAd
->OS_Cookie
;
961 CHECK_PID_LEGALITY(pObj
->RTUSBCmdThr_pid
)
962 return (NDIS_STATUS_RESOURCES
);
964 status
= RTMPAllocateMemory((PVOID
*)&cmdqelmt
, sizeof(CmdQElmt
));
965 if ((status
!= NDIS_STATUS_SUCCESS
) || (cmdqelmt
== NULL
))
966 return (NDIS_STATUS_RESOURCES
);
968 cmdqelmt
->buffer
= NULL
;
969 if (pInformationBuffer
!= NULL
)
971 status
= RTMPAllocateMemory((PVOID
*)&cmdqelmt
->buffer
, InformationBufferLength
);
972 if ((status
!= NDIS_STATUS_SUCCESS
) || (cmdqelmt
->buffer
== NULL
))
975 return (NDIS_STATUS_RESOURCES
);
979 NdisMoveMemory(cmdqelmt
->buffer
, pInformationBuffer
, InformationBufferLength
);
980 cmdqelmt
->bufferlength
= InformationBufferLength
;
984 cmdqelmt
->bufferlength
= 0;
986 cmdqelmt
->command
= Oid
;
987 cmdqelmt
->CmdFromNdis
= TRUE
;
988 if (SetInformation
== TRUE
)
989 cmdqelmt
->SetOperation
= TRUE
;
991 cmdqelmt
->SetOperation
= FALSE
;
993 NdisAcquireSpinLock(&pAd
->CmdQLock
);
994 if (pAd
->CmdQ
.CmdQState
& RT2870_THREAD_CAN_DO_INSERT
)
996 EnqueueCmd((&pAd
->CmdQ
), cmdqelmt
);
997 status
= NDIS_STATUS_SUCCESS
;
1001 status
= NDIS_STATUS_FAILURE
;
1003 NdisReleaseSpinLock(&pAd
->CmdQLock
);
1005 if (status
== NDIS_STATUS_FAILURE
)
1007 if (cmdqelmt
->buffer
)
1008 NdisFreeMemory(cmdqelmt
->buffer
, cmdqelmt
->bufferlength
, 0);
1009 NdisFreeMemory(cmdqelmt
, sizeof(CmdQElmt
), 0);
1015 return(NDIS_STATUS_SUCCESS
);
1019 ========================================================================
1021 Routine Description:
1031 ========================================================================
1033 NDIS_STATUS
RTUSBEnqueueInternalCmd(
1034 IN PRTMP_ADAPTER pAd
,
1036 IN PVOID pInformationBuffer
,
1037 IN UINT32 InformationBufferLength
)
1040 PCmdQElmt cmdqelmt
= NULL
;
1043 status
= RTMPAllocateMemory((PVOID
*)&cmdqelmt
, sizeof(CmdQElmt
));
1044 if ((status
!= NDIS_STATUS_SUCCESS
) || (cmdqelmt
== NULL
))
1045 return (NDIS_STATUS_RESOURCES
);
1046 NdisZeroMemory(cmdqelmt
, sizeof(CmdQElmt
));
1048 if(InformationBufferLength
> 0)
1050 status
= RTMPAllocateMemory((PVOID
*)&cmdqelmt
->buffer
, InformationBufferLength
);
1051 if ((status
!= NDIS_STATUS_SUCCESS
) || (cmdqelmt
->buffer
== NULL
))
1053 NdisFreeMemory(cmdqelmt
, sizeof(CmdQElmt
), 0);
1054 return (NDIS_STATUS_RESOURCES
);
1058 NdisMoveMemory(cmdqelmt
->buffer
, pInformationBuffer
, InformationBufferLength
);
1059 cmdqelmt
->bufferlength
= InformationBufferLength
;
1064 cmdqelmt
->buffer
= NULL
;
1065 cmdqelmt
->bufferlength
= 0;
1068 cmdqelmt
->command
= Oid
;
1069 cmdqelmt
->CmdFromNdis
= FALSE
;
1071 if (cmdqelmt
!= NULL
)
1073 NdisAcquireSpinLock(&pAd
->CmdQLock
);
1074 if (pAd
->CmdQ
.CmdQState
& RT2870_THREAD_CAN_DO_INSERT
)
1076 EnqueueCmd((&pAd
->CmdQ
), cmdqelmt
);
1077 status
= NDIS_STATUS_SUCCESS
;
1081 status
= NDIS_STATUS_FAILURE
;
1083 NdisReleaseSpinLock(&pAd
->CmdQLock
);
1085 if (status
== NDIS_STATUS_FAILURE
)
1087 if (cmdqelmt
->buffer
)
1088 NdisFreeMemory(cmdqelmt
->buffer
, cmdqelmt
->bufferlength
, 0);
1089 NdisFreeMemory(cmdqelmt
, sizeof(CmdQElmt
), 0);
1094 return(NDIS_STATUS_SUCCESS
);
1098 ========================================================================
1100 Routine Description:
1110 ========================================================================
1112 VOID
RTUSBDequeueCmd(
1114 OUT PCmdQElmt
*pcmdqelmt
)
1116 *pcmdqelmt
= cmdq
->head
;
1118 if (*pcmdqelmt
!= NULL
)
1120 cmdq
->head
= cmdq
->head
->next
;
1122 if (cmdq
->size
== 0)
1128 ========================================================================
1129 usb_control_msg - Builds a control urb, sends it off and waits for completion
1130 @dev: pointer to the usb device to send the message to
1131 @pipe: endpoint "pipe" to send the message to
1132 @request: USB message request value
1133 @requesttype: USB message request type value
1134 @value: USB message value
1135 @index: USB message index value
1136 @data: pointer to the data to send
1137 @size: length in bytes of the data to send
1138 @timeout: time in jiffies to wait for the message to complete before
1139 timing out (if 0 the wait is forever)
1140 Context: !in_interrupt ()
1142 This function sends a simple control message to a specified endpoint
1143 and waits for the message to complete, or timeout.
1144 If successful, it returns the number of bytes transferred, otherwise a negative error number.
1146 Don't use this function from within an interrupt context, like a
1147 bottom half handler. If you need an asynchronous message, or need to send
1148 a message from within interrupt context, use usb_submit_urb()
1149 If a thread in your driver uses this call, make sure your disconnect()
1150 method can wait for it to complete. Since you don't have a handle on
1151 the URB used, you can't cancel the request.
1154 Routine Description:
1162 ========================================================================
1164 NTSTATUS
RTUSB_VendorRequest(
1165 IN PRTMP_ADAPTER pAd
,
1166 IN UINT32 TransferFlags
,
1167 IN UCHAR RequestType
,
1171 IN PVOID TransferBuffer
,
1172 IN UINT32 TransferBufferLength
)
1175 POS_COOKIE pObj
= (POS_COOKIE
) pAd
->OS_Cookie
;
1177 if (RTMP_TEST_FLAG(pAd
, fRTMP_ADAPTER_NIC_NOT_EXIST
))
1179 DBGPRINT(RT_DEBUG_ERROR
, ("device disconnected\n"));
1182 else if (in_interrupt())
1184 DBGPRINT(RT_DEBUG_ERROR
, ("in_interrupt, RTUSB_VendorRequest Request%02x Value%04x Offset%04x\n",Request
,Value
,Index
));
1190 #define MAX_RETRY_COUNT 10
1193 void *tmpBuf
= TransferBuffer
;
1195 // Acquire Control token
1196 #ifdef INF_AMAZON_SE
1197 //Semaphore fix INF_AMAZON_SE hang
1198 //pAd->UsbVendorReqBuf is the swap for DEVICE_VENDOR_REQUEST_IN to fix dma bug.
1199 ret
= down_interruptible(&(pAd
->UsbVendorReq_semaphore
));
1200 if (pAd
->UsbVendorReqBuf
)
1202 ASSERT(TransferBufferLength
<MAX_PARAM_BUFFER_SIZE
);
1204 tmpBuf
= (void *)pAd
->UsbVendorReqBuf
;
1205 NdisZeroMemory(pAd
->UsbVendorReqBuf
, TransferBufferLength
);
1207 if (RequestType
== DEVICE_VENDOR_REQUEST_OUT
)
1208 NdisMoveMemory(tmpBuf
, TransferBuffer
, TransferBufferLength
);
1210 #endif // INF_AMAZON_SE //
1212 if( RequestType
== DEVICE_VENDOR_REQUEST_OUT
)
1213 ret
=usb_control_msg(pObj
->pUsb_Dev
, usb_sndctrlpipe( pObj
->pUsb_Dev
, 0 ), Request
, RequestType
, Value
,Index
, tmpBuf
, TransferBufferLength
, CONTROL_TIMEOUT_JIFFIES
);
1214 else if(RequestType
== DEVICE_VENDOR_REQUEST_IN
)
1215 ret
=usb_control_msg(pObj
->pUsb_Dev
, usb_rcvctrlpipe( pObj
->pUsb_Dev
, 0 ), Request
, RequestType
, Value
,Index
, tmpBuf
, TransferBufferLength
, CONTROL_TIMEOUT_JIFFIES
);
1218 DBGPRINT(RT_DEBUG_ERROR
, ("vendor request direction is failed\n"));
1225 RTMPusecDelay(5000);
1227 } while((ret
< 0) && (retryCount
< MAX_RETRY_COUNT
));
1229 #ifdef INF_AMAZON_SE
1230 if ((pAd
->UsbVendorReqBuf
) && (RequestType
== DEVICE_VENDOR_REQUEST_IN
))
1231 NdisMoveMemory(TransferBuffer
, tmpBuf
, TransferBufferLength
);
1232 up(&(pAd
->UsbVendorReq_semaphore
));
1233 #endif // INF_AMAZON_SE //
1236 // DBGPRINT(RT_DEBUG_ERROR, ("USBVendorRequest failed ret=%d \n",ret));
1237 DBGPRINT(RT_DEBUG_ERROR
, ("RTUSB_VendorRequest failed(%d),TxFlags=0x%x, ReqType=%s, Req=0x%x, Index=0x%x\n",
1238 ret
, TransferFlags
, (RequestType
== DEVICE_VENDOR_REQUEST_OUT
? "OUT" : "IN"), Request
, Index
));
1240 DBGPRINT(RT_DEBUG_ERROR
, ("\tRequest Value=0x%04x!\n", Value
));
1242 if ((TransferBuffer
!= NULL
) && (TransferBufferLength
> 0))
1243 hex_dump("Failed TransferBuffer value", TransferBuffer
, TransferBufferLength
);
1250 DBGPRINT(RT_DEBUG_ERROR
, ("USBVendorRequest failed ret=%d, \n",ret
));
1254 if( RequestType
== DEVICE_VENDOR_REQUEST_OUT
)
1255 ret
=usb_control_msg(pObj
->pUsb_Dev
, usb_sndctrlpipe( pObj
->pUsb_Dev
, 0 ), Request
, RequestType
, Value
,Index
, TransferBuffer
, TransferBufferLength
, CONTROL_TIMEOUT_JIFFIES
);
1256 else if(RequestType
== DEVICE_VENDOR_REQUEST_IN
)
1257 ret
=usb_control_msg(pObj
->pUsb_Dev
, usb_rcvctrlpipe( pObj
->pUsb_Dev
, 0 ), Request
, RequestType
, Value
,Index
, TransferBuffer
, TransferBufferLength
, CONTROL_TIMEOUT_JIFFIES
);
1259 } while( (ret
< 0) && (temp_i
<= 1) );
1272 ========================================================================
1274 Routine Description:
1275 Creates an IRP to submite an IOCTL_INTERNAL_USB_RESET_PORT
1276 synchronously. Callers of this function must be running at
1285 ========================================================================
1287 NTSTATUS
RTUSB_ResetDevice(
1288 IN PRTMP_ADAPTER pAd
)
1290 NTSTATUS Status
= TRUE
;
1292 DBGPRINT_RAW(RT_DEBUG_TRACE
, ("--->USB_ResetDevice\n"));
1293 //RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_RESET_IN_PROGRESS);
1298 IN PRTMP_ADAPTER pAd
)
1302 NDIS_STATUS NdisStatus
= NDIS_STATUS_SUCCESS
;
1305 // unsigned long IrqFlags;
1307 while (pAd
->CmdQ
.size
> 0)
1309 NdisStatus
= NDIS_STATUS_SUCCESS
;
1311 NdisAcquireSpinLock(&pAd
->CmdQLock
);
1312 RTUSBDequeueCmd(&pAd
->CmdQ
, &cmdqelmt
);
1313 NdisReleaseSpinLock(&pAd
->CmdQLock
);
1315 if (cmdqelmt
== NULL
)
1318 pData
= cmdqelmt
->buffer
;
1320 if(!(RTMP_TEST_FLAG(pAd
, fRTMP_ADAPTER_NIC_NOT_EXIST
) || RTMP_TEST_FLAG(pAd
, fRTMP_ADAPTER_HALT_IN_PROGRESS
)))
1322 switch (cmdqelmt
->command
)
1324 case CMDTHREAD_CHECK_GPIO
:
1326 #ifdef CONFIG_STA_SUPPORT
1328 #endif // CONFIG_STA_SUPPORT //
1332 DBGPRINT(RT_DEBUG_TRACE
, ("The driver is in ATE mode now\n"));
1335 #endif // RALINK_ATE //
1337 #ifdef CONFIG_STA_SUPPORT
1340 IF_DEV_CONFIG_OPMODE_ON_STA(pAd
)
1342 // Read GPIO pin2 as Hardware controlled radio state
1344 RTUSBReadMACRegister( pAd
, GPIO_CTRL_CFG
, &data
);
1348 pAd
->StaCfg
.bHwRadio
= TRUE
;
1352 pAd
->StaCfg
.bHwRadio
= FALSE
;
1355 if(pAd
->StaCfg
.bRadio
!= (pAd
->StaCfg
.bHwRadio
&& pAd
->StaCfg
.bSwRadio
))
1357 pAd
->StaCfg
.bRadio
= (pAd
->StaCfg
.bHwRadio
&& pAd
->StaCfg
.bSwRadio
);
1358 if(pAd
->StaCfg
.bRadio
== TRUE
)
1360 DBGPRINT_RAW(RT_DEBUG_ERROR
, ("!!! Radio On !!!\n"));
1363 // Update extra information
1364 pAd
->ExtraInfo
= EXTRA_INFO_CLEAR
;
1368 DBGPRINT_RAW(RT_DEBUG_ERROR
, ("!!! Radio Off !!!\n"));
1371 // Update extra information
1372 pAd
->ExtraInfo
= HW_RADIO_OFF
;
1376 #endif // CONFIG_STA_SUPPORT //
1380 #ifdef CONFIG_STA_SUPPORT
1381 case CMDTHREAD_QKERIODIC_EXECUT
:
1383 StaQuickResponeForRateUpExec(NULL
, pAd
, NULL
, NULL
);
1386 #endif // CONFIG_STA_SUPPORT //
1388 case CMDTHREAD_RESET_BULK_OUT
:
1393 PHT_TX_CONTEXT pHTTXContext
;
1394 // RTMP_TX_RING *pTxRing;
1395 unsigned long IrqFlags
;
1397 PTX_CONTEXT pNullContext
= &(pAd
->NullContext
);
1398 #endif // RALINK_ATE //
1399 DBGPRINT_RAW(RT_DEBUG_TRACE
, ("CmdThread : CMDTHREAD_RESET_BULK_OUT(ResetPipeid=0x%0x)===>\n", pAd
->bulkResetPipeid
));
1400 // All transfers must be aborted or cancelled before attempting to reset the pipe.
1401 //RTUSBCancelPendingBulkOutIRP(pAd);
1402 // Wait 10ms to let previous packet that are already in HW FIFO to clear. by MAXLEE 12-25-2007
1406 RTUSBReadMACRegister(pAd
, TXRXQ_PCNT
, &MACValue
);
1407 if ((MACValue
& 0xf00000/*0x800000*/) == 0)
1410 RTMPusecDelay(10000);
1411 }while(Index
< 100);
1413 RTUSBReadMACRegister(pAd
, USB_DMA_CFG
, &MACValue
);
1414 // To prevent Read Register error, we 2nd check the validity.
1415 if ((MACValue
& 0xc00000) == 0)
1416 RTUSBReadMACRegister(pAd
, USB_DMA_CFG
, &MACValue
);
1417 // To prevent Read Register error, we 3rd check the validity.
1418 if ((MACValue
& 0xc00000) == 0)
1419 RTUSBReadMACRegister(pAd
, USB_DMA_CFG
, &MACValue
);
1420 MACValue
|= 0x80000;
1421 RTUSBWriteMACRegister(pAd
, USB_DMA_CFG
, MACValue
);
1423 // Wait 1ms to prevent next URB to bulkout before HW reset. by MAXLEE 12-25-2007
1424 RTMPusecDelay(1000);
1426 MACValue
&= (~0x80000);
1427 RTUSBWriteMACRegister(pAd
, USB_DMA_CFG
, MACValue
);
1428 DBGPRINT_RAW(RT_DEBUG_TRACE
, ("\tSet 0x2a0 bit19. Clear USB DMA TX path\n"));
1430 // Wait 5ms to prevent next URB to bulkout before HW reset. by MAXLEE 12-25-2007
1431 //RTMPusecDelay(5000);
1433 if ((pAd
->bulkResetPipeid
& BULKOUT_MGMT_RESET_FLAG
) == BULKOUT_MGMT_RESET_FLAG
)
1435 RTMP_CLEAR_FLAG(pAd
, fRTMP_ADAPTER_BULKOUT_RESET
);
1436 if (pAd
->MgmtRing
.TxSwFreeIdx
< MGMT_RING_SIZE
/* pMLMEContext->bWaitingBulkOut == TRUE */)
1438 RTUSB_SET_BULK_FLAG(pAd
, fRTUSB_BULK_OUT_MLME
);
1440 RTUSBKickBulkOut(pAd
);
1442 DBGPRINT_RAW(RT_DEBUG_TRACE
, ("\tTX MGMT RECOVER Done!\n"));
1446 pHTTXContext
= &(pAd
->TxContext
[pAd
->bulkResetPipeid
]);
1447 //NdisAcquireSpinLock(&pAd->BulkOutLock[pAd->bulkResetPipeid]);
1448 RTMP_INT_LOCK(&pAd
->BulkOutLock
[pAd
->bulkResetPipeid
], IrqFlags
);
1449 if ( pAd
->BulkOutPending
[pAd
->bulkResetPipeid
] == FALSE
)
1451 pAd
->BulkOutPending
[pAd
->bulkResetPipeid
] = TRUE
;
1452 pHTTXContext
->IRPPending
= TRUE
;
1453 pAd
->watchDogTxPendingCnt
[pAd
->bulkResetPipeid
] = 1;
1455 // no matter what, clean the flag
1456 RTMP_CLEAR_FLAG(pAd
, fRTMP_ADAPTER_BULKOUT_RESET
);
1458 //NdisReleaseSpinLock(&pAd->BulkOutLock[pAd->bulkResetPipeid]);
1459 RTMP_INT_UNLOCK(&pAd
->BulkOutLock
[pAd
->bulkResetPipeid
], IrqFlags
);
1460 /*-----------------------------------------------------------------------------------------------*/
1464 pNullContext
->IRPPending
= TRUE
;
1466 // If driver is still in ATE TXFRAME mode,
1467 // keep on transmitting ATE frames.
1469 DBGPRINT_RAW(RT_DEBUG_TRACE
, ("pAd->ate.Mode == %d\npAd->ContinBulkOut == %d\npAd->BulkOutRemained == %d\n", pAd
->ate
.Mode
, pAd
->ContinBulkOut
, atomic_read(&pAd
->BulkOutRemained
)));
1470 if((pAd
->ate
.Mode
== ATE_TXFRAME
) && ((pAd
->ContinBulkOut
== TRUE
) || (atomic_read(&pAd
->BulkOutRemained
) > 0)))
1472 DBGPRINT_RAW(RT_DEBUG_TRACE
, ("After CMDTHREAD_RESET_BULK_OUT, continue to bulk out frames !\n"));
1474 // Init Tx context descriptor
1475 RTUSBInitTxDesc(pAd
, pNullContext
, 0/* pAd->bulkResetPipeid */, (usb_complete_t
)ATE_RTUSBBulkOutDataPacketComplete
);
1477 if((ret
= RTUSB_SUBMIT_URB(pNullContext
->pUrb
))!=0)
1479 DBGPRINT(RT_DEBUG_ERROR
, ("ATE_RTUSBBulkOutDataPacket: Submit Tx URB failed %d\n", ret
));
1486 #endif // RALINK_ATE //
1487 /*-----------------------------------------------------------------------------------------------*/
1489 RTUSBInitHTTxDesc(pAd
, pHTTXContext
, pAd
->bulkResetPipeid
, pHTTXContext
->BulkOutSize
, (usb_complete_t
)RTUSBBulkOutDataPacketComplete
);
1491 if((ret
= RTUSB_SUBMIT_URB(pHTTXContext
->pUrb
))!=0)
1493 RTMP_INT_LOCK(&pAd
->BulkOutLock
[pAd
->bulkResetPipeid
], IrqFlags
);
1494 pAd
->BulkOutPending
[pAd
->bulkResetPipeid
] = FALSE
;
1495 pHTTXContext
->IRPPending
= FALSE
;
1496 pAd
->watchDogTxPendingCnt
[pAd
->bulkResetPipeid
] = 0;
1497 RTMP_INT_UNLOCK(&pAd
->BulkOutLock
[pAd
->bulkResetPipeid
], IrqFlags
);
1499 DBGPRINT(RT_DEBUG_ERROR
, ("CmdThread : CMDTHREAD_RESET_BULK_OUT: Submit Tx URB failed %d\n", ret
));
1503 RTMP_IRQ_LOCK(&pAd
->BulkOutLock
[pAd
->bulkResetPipeid
], IrqFlags
);
1504 DBGPRINT_RAW(RT_DEBUG_TRACE
,("\tCMDTHREAD_RESET_BULK_OUT: TxContext[%d]:CWPos=%ld, NBPos=%ld, ENBPos=%ld, bCopy=%d, pending=%d!\n",
1505 pAd
->bulkResetPipeid
, pHTTXContext
->CurWritePosition
, pHTTXContext
->NextBulkOutPosition
,
1506 pHTTXContext
->ENextBulkOutPosition
, pHTTXContext
->bCopySavePad
, pAd
->BulkOutPending
[pAd
->bulkResetPipeid
]));
1507 DBGPRINT_RAW(RT_DEBUG_TRACE
,("\t\tBulkOut Req=0x%lx, Complete=0x%lx, Other=0x%lx\n",
1508 pAd
->BulkOutReq
, pAd
->BulkOutComplete
, pAd
->BulkOutCompleteOther
));
1509 RTMP_IRQ_UNLOCK(&pAd
->BulkOutLock
[pAd
->bulkResetPipeid
], IrqFlags
);
1510 DBGPRINT_RAW(RT_DEBUG_TRACE
, ("\tCMDTHREAD_RESET_BULK_OUT: Submit Tx DATA URB for failed BulkReq(0x%lx) Done, status=%d!\n", pAd
->bulkResetReq
[pAd
->bulkResetPipeid
], pHTTXContext
->pUrb
->status
));
1517 //NdisReleaseSpinLock(&pAd->BulkOutLock[pAd->bulkResetPipeid]);
1518 //RTMP_INT_UNLOCK(&pAd->BulkOutLock[pAd->bulkResetPipeid], IrqFlags);
1520 DBGPRINT_RAW(RT_DEBUG_ERROR
, ("CmdThread : TX DATA RECOVER FAIL for BulkReq(0x%lx) because BulkOutPending[%d] is TRUE!\n", pAd
->bulkResetReq
[pAd
->bulkResetPipeid
], pAd
->bulkResetPipeid
));
1521 if (pAd
->bulkResetPipeid
== 0)
1523 UCHAR pendingContext
= 0;
1524 PHT_TX_CONTEXT pHTTXContext
= (PHT_TX_CONTEXT
)(&pAd
->TxContext
[pAd
->bulkResetPipeid
]);
1525 PTX_CONTEXT pMLMEContext
= (PTX_CONTEXT
)(pAd
->MgmtRing
.Cell
[pAd
->MgmtRing
.TxDmaIdx
].AllocVa
);
1526 PTX_CONTEXT pNULLContext
= (PTX_CONTEXT
)(&pAd
->PsPollContext
);
1527 PTX_CONTEXT pPsPollContext
= (PTX_CONTEXT
)(&pAd
->NullContext
);
1529 if (pHTTXContext
->IRPPending
)
1530 pendingContext
|= 1;
1531 else if (pMLMEContext
->IRPPending
)
1532 pendingContext
|= 2;
1533 else if (pNULLContext
->IRPPending
)
1534 pendingContext
|= 4;
1535 else if (pPsPollContext
->IRPPending
)
1536 pendingContext
|= 8;
1540 DBGPRINT_RAW(RT_DEBUG_ERROR
, ("\tTX Occupied by %d!\n", pendingContext
));
1543 // no matter what, clean the flag
1544 RTMP_CLEAR_FLAG(pAd
, fRTMP_ADAPTER_BULKOUT_RESET
);
1546 RTMP_INT_UNLOCK(&pAd
->BulkOutLock
[pAd
->bulkResetPipeid
], IrqFlags
);
1548 RTUSB_SET_BULK_FLAG(pAd
, (fRTUSB_BULK_OUT_DATA_NORMAL
<< pAd
->bulkResetPipeid
));
1551 RTMPDeQueuePacket(pAd
, FALSE
, NUM_OF_TX_RING
, MAX_TX_PROCESS
);
1552 //RTUSBKickBulkOut(pAd);
1557 // Don't cancel BULKIN.
1558 while ((atomic_read(&pAd->PendingRx) > 0) &&
1559 (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)))
1561 if (atomic_read(&pAd->PendingRx) > 0)
1563 DBGPRINT_RAW(RT_DEBUG_ERROR, ("BulkIn IRP Pending!!cancel it!\n"));
1564 RTUSBCancelPendingBulkInIRP(pAd);
1566 RTMPusecDelay(100000);
1569 if ((atomic_read(&pAd->PendingRx) == 0) && (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS)))
1573 pAd->NextRxBulkInReadIndex = 0; // Next Rx Read index
1574 pAd->NextRxBulkInIndex = 0; // Rx Bulk pointer
1575 for (i = 0; i < (RX_RING_SIZE); i++)
1577 PRX_CONTEXT pRxContext = &(pAd->RxContext[i]);
1579 pRxContext->pAd = pAd;
1580 pRxContext->InUse = FALSE;
1581 pRxContext->IRPPending = FALSE;
1582 pRxContext->Readable = FALSE;
1583 pRxContext->ReorderInUse = FALSE;
1586 RTUSBBulkReceive(pAd);
1587 DBGPRINT_RAW(RT_DEBUG_ERROR, ("RTUSBBulkReceive\n"));
1589 DBGPRINT_RAW(RT_DEBUG_TRACE
, ("CmdThread : CMDTHREAD_RESET_BULK_OUT<===\n"));
1592 case CMDTHREAD_RESET_BULK_IN
:
1593 DBGPRINT_RAW(RT_DEBUG_TRACE
, ("CmdThread : CMDTHREAD_RESET_BULK_IN === >\n"));
1595 // All transfers must be aborted or cancelled before attempting to reset the pipe.
1598 /*-----------------------------------------------------------------------------------------------*/
1602 if((pAd
->PendingRx
> 0) && (!RTMP_TEST_FLAG(pAd
, fRTMP_ADAPTER_NIC_NOT_EXIST
)))
1604 DBGPRINT_RAW(RT_DEBUG_ERROR
, ("ATE : BulkIn IRP Pending!!!\n"));
1605 ATE_RTUSBCancelPendingBulkInIRP(pAd
);
1606 RTMPusecDelay(100000);
1611 #endif // RALINK_ATE //
1612 /*-----------------------------------------------------------------------------------------------*/
1614 //while ((atomic_read(&pAd->PendingRx) > 0) && (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)))
1615 if((pAd
->PendingRx
> 0) && (!RTMP_TEST_FLAG(pAd
, fRTMP_ADAPTER_NIC_NOT_EXIST
)))
1617 DBGPRINT_RAW(RT_DEBUG_ERROR
, ("BulkIn IRP Pending!!!\n"));
1618 RTUSBCancelPendingBulkInIRP(pAd
);
1619 RTMPusecDelay(100000);
1624 // Wait 10ms before reading register.
1625 RTMPusecDelay(10000);
1626 ntStatus
= RTUSBReadMACRegister(pAd
, MAC_CSR0
, &MACValue
);
1628 if ((NT_SUCCESS(ntStatus
) == TRUE
) &&
1629 (!(RTMP_TEST_FLAG(pAd
, (fRTMP_ADAPTER_RESET_IN_PROGRESS
| fRTMP_ADAPTER_RADIO_OFF
|
1630 fRTMP_ADAPTER_HALT_IN_PROGRESS
| fRTMP_ADAPTER_NIC_NOT_EXIST
)))))
1634 if (RTMP_TEST_FLAG(pAd
, (fRTMP_ADAPTER_RESET_IN_PROGRESS
| fRTMP_ADAPTER_RADIO_OFF
|
1635 fRTMP_ADAPTER_HALT_IN_PROGRESS
| fRTMP_ADAPTER_NIC_NOT_EXIST
)))
1637 pAd
->NextRxBulkInPosition
= pAd
->RxContext
[pAd
->NextRxBulkInIndex
].BulkInOffset
;
1638 DBGPRINT(RT_DEBUG_TRACE
, ("BULK_IN_RESET: NBIIdx=0x%x,NBIRIdx=0x%x, BIRPos=0x%lx. BIReq=x%lx, BIComplete=0x%lx, BICFail0x%lx\n",
1639 pAd
->NextRxBulkInIndex
, pAd
->NextRxBulkInReadIndex
, pAd
->NextRxBulkInPosition
, pAd
->BulkInReq
, pAd
->BulkInComplete
, pAd
->BulkInCompleteFail
));
1640 for (i
= 0; i
< RX_RING_SIZE
; i
++)
1642 DBGPRINT(RT_DEBUG_TRACE
, ("\tRxContext[%d]: IRPPending=%d, InUse=%d, Readable=%d!\n"
1643 , i
, pAd
->RxContext
[i
].IRPPending
, pAd
->RxContext
[i
].InUse
, pAd
->RxContext
[i
].Readable
));
1647 DBGPRINT_RAW(RT_DEBUG_ERROR, ("==========================================\n"));
1649 pAd->NextRxBulkInReadIndex = 0; // Next Rx Read index
1650 pAd->NextRxBulkInIndex = 0; // Rx Bulk pointer
1651 for (i = 0; i < (RX_RING_SIZE); i++)
1653 PRX_CONTEXT pRxContext = &(pAd->RxContext[i]);
1655 pRxContext->pAd = pAd;
1656 pRxContext->InUse = FALSE;
1657 pRxContext->IRPPending = FALSE;
1658 pRxContext->Readable = FALSE;
1659 pRxContext->ReorderInUse = FALSE;
1662 RTMP_CLEAR_FLAG(pAd
, fRTMP_ADAPTER_BULKIN_RESET
);
1663 for (i
= 0; i
< pAd
->CommonCfg
.NumOfBulkInIRP
; i
++)
1665 //RTUSBBulkReceive(pAd);
1666 PRX_CONTEXT pRxContext
;
1669 unsigned long IrqFlags
;
1672 RTMP_IRQ_LOCK(&pAd
->BulkInLock
, IrqFlags
);
1673 pRxContext
= &(pAd
->RxContext
[pAd
->NextRxBulkInIndex
]);
1674 if ((pAd
->PendingRx
> 0) || (pRxContext
->Readable
== TRUE
) || (pRxContext
->InUse
== TRUE
))
1676 RTMP_IRQ_UNLOCK(&pAd
->BulkInLock
, IrqFlags
);
1679 pRxContext
->InUse
= TRUE
;
1680 pRxContext
->IRPPending
= TRUE
;
1683 RTMP_IRQ_UNLOCK(&pAd
->BulkInLock
, IrqFlags
);
1685 // Init Rx context descriptor
1686 RTUSBInitRxDesc(pAd
, pRxContext
);
1687 pUrb
= pRxContext
->pUrb
;
1688 if ((ret
= RTUSB_SUBMIT_URB(pUrb
))!=0)
1691 RTMP_IRQ_LOCK(&pAd
->BulkInLock
, IrqFlags
);
1692 pRxContext
->InUse
= FALSE
;
1693 pRxContext
->IRPPending
= FALSE
;
1696 RTMP_IRQ_UNLOCK(&pAd
->BulkInLock
, IrqFlags
);
1697 DBGPRINT(RT_DEBUG_ERROR
, ("CMDTHREAD_RESET_BULK_IN: Submit Rx URB failed(%d), status=%d\n", ret
, pUrb
->status
));
1702 RTMP_IRQ_LOCK(&pAd
->BulkInLock
, IrqFlags
);
1703 pRxContext
->IRPPending
= TRUE
;
1704 //NdisInterlockedIncrement(&pAd->PendingRx);
1706 RTMP_IRQ_UNLOCK(&pAd
->BulkInLock
, IrqFlags
);
1709 //printk("BIDone, Pend=%d,BIIdx=%d,BIRIdx=%d!\n", pAd->PendingRx, pAd->NextRxBulkInIndex, pAd->NextRxBulkInReadIndex);
1710 DBGPRINT_RAW(RT_DEBUG_TRACE
, ("CMDTHREAD_RESET_BULK_IN: Submit Rx URB Done, status=%d!\n", pUrb
->status
));
1711 ASSERT((pRxContext
->InUse
== pRxContext
->IRPPending
));
1718 // Card must be removed
1719 if (NT_SUCCESS(ntStatus
) != TRUE
)
1721 RTMP_SET_FLAG(pAd
, fRTMP_ADAPTER_NIC_NOT_EXIST
);
1722 DBGPRINT_RAW(RT_DEBUG_ERROR
, ("CMDTHREAD_RESET_BULK_IN: Read Register Failed!Card must be removed!!\n\n"));
1726 DBGPRINT_RAW(RT_DEBUG_ERROR
, ("CMDTHREAD_RESET_BULK_IN: Cannot do bulk in because flags(0x%lx) on !\n", pAd
->Flags
));
1730 DBGPRINT_RAW(RT_DEBUG_TRACE
, ("CmdThread : CMDTHREAD_RESET_BULK_IN <===\n"));
1733 case CMDTHREAD_SET_ASIC_WCID
:
1735 RT_SET_ASIC_WCID SetAsicWcid
;
1737 UINT32 MACValue
, MACRValue
= 0;
1738 SetAsicWcid
= *((PRT_SET_ASIC_WCID
)(pData
));
1740 if (SetAsicWcid
.WCID
>= MAX_LEN_OF_MAC_TABLE
)
1743 offset
= MAC_WCID_BASE
+ ((UCHAR
)SetAsicWcid
.WCID
)*HW_WCID_ENTRY_SIZE
;
1745 DBGPRINT_RAW(RT_DEBUG_TRACE
, ("CmdThread : CMDTHREAD_SET_ASIC_WCID : WCID = %ld, SetTid = %lx, DeleteTid = %lx.\n", SetAsicWcid
.WCID
, SetAsicWcid
.SetTid
, SetAsicWcid
.DeleteTid
));
1746 MACValue
= (pAd
->MacTab
.Content
[SetAsicWcid
.WCID
].Addr
[3]<<24)+(pAd
->MacTab
.Content
[SetAsicWcid
.WCID
].Addr
[2]<<16)+(pAd
->MacTab
.Content
[SetAsicWcid
.WCID
].Addr
[1]<<8)+(pAd
->MacTab
.Content
[SetAsicWcid
.WCID
].Addr
[0]);
1747 DBGPRINT_RAW(RT_DEBUG_TRACE
, ("1-MACValue= %x,\n", MACValue
));
1748 RTUSBWriteMACRegister(pAd
, offset
, MACValue
);
1750 RTUSBReadMACRegister(pAd
, offset
+4, &MACRValue
);
1751 if ( SetAsicWcid
.DeleteTid
!= 0xffffffff)
1752 MACRValue
&= (~SetAsicWcid
.DeleteTid
);
1753 if (SetAsicWcid
.SetTid
!= 0xffffffff)
1754 MACRValue
|= (SetAsicWcid
.SetTid
);
1755 MACRValue
&= 0xffff0000;
1757 MACValue
= (pAd
->MacTab
.Content
[SetAsicWcid
.WCID
].Addr
[5]<<8)+pAd
->MacTab
.Content
[SetAsicWcid
.WCID
].Addr
[4];
1758 MACValue
|= MACRValue
;
1759 RTUSBWriteMACRegister(pAd
, offset
+4, MACValue
);
1761 DBGPRINT_RAW(RT_DEBUG_TRACE
, ("2-MACValue= %x,\n", MACValue
));
1765 case CMDTHREAD_SET_ASIC_WCID_CIPHER
:
1767 #ifdef CONFIG_STA_SUPPORT
1768 RT_SET_ASIC_WCID_ATTRI SetAsicWcidAttri
;
1770 UINT32 MACRValue
= 0;
1771 SHAREDKEY_MODE_STRUC csr1
;
1772 SetAsicWcidAttri
= *((PRT_SET_ASIC_WCID_ATTRI
)(pData
));
1774 if (SetAsicWcidAttri
.WCID
>= MAX_LEN_OF_MAC_TABLE
)
1777 offset
= MAC_WCID_ATTRIBUTE_BASE
+ ((UCHAR
)SetAsicWcidAttri
.WCID
)*HW_WCID_ATTRI_SIZE
;
1779 DBGPRINT_RAW(RT_DEBUG_TRACE
, ("Cmd : CMDTHREAD_SET_ASIC_WCID_CIPHER : WCID = %ld, Cipher = %lx.\n", SetAsicWcidAttri
.WCID
, SetAsicWcidAttri
.Cipher
));
1781 RTUSBReadMACRegister(pAd
, offset
, &MACRValue
);
1783 MACRValue
|= (((UCHAR
)SetAsicWcidAttri
.Cipher
) << 1);
1785 RTUSBWriteMACRegister(pAd
, offset
, MACRValue
);
1786 DBGPRINT_RAW(RT_DEBUG_TRACE
, ("2-offset = %x , MACValue= %x,\n", offset
, MACRValue
));
1788 offset
= PAIRWISE_IVEIV_TABLE_BASE
+ ((UCHAR
)SetAsicWcidAttri
.WCID
)*HW_IVEIV_ENTRY_SIZE
;
1790 if ( (SetAsicWcidAttri
.Cipher
<= CIPHER_WEP128
))
1791 MACRValue
|= ( pAd
->StaCfg
.DefaultKeyId
<< 30);
1793 MACRValue
|= (0x20000000);
1794 RTUSBWriteMACRegister(pAd
, offset
, MACRValue
);
1795 DBGPRINT_RAW(RT_DEBUG_TRACE
, ("2-offset = %x , MACValue= %x,\n", offset
, MACRValue
));
1798 // Update cipher algorithm. WSTA always use BSS0
1800 // for adhoc mode only ,because wep status slow than add key, when use zero config
1801 if (pAd
->StaCfg
.BssType
== BSS_ADHOC
)
1803 offset
= MAC_WCID_ATTRIBUTE_BASE
;
1805 RTUSBReadMACRegister(pAd
, offset
, &MACRValue
);
1806 MACRValue
&= (~0xe);
1807 MACRValue
|= (((UCHAR
)SetAsicWcidAttri
.Cipher
) << 1);
1809 RTUSBWriteMACRegister(pAd
, offset
, MACRValue
);
1811 //Update group key cipher,,because wep status slow than add key, when use zero config
1812 RTUSBReadMACRegister(pAd
, SHARED_KEY_MODE_BASE
+4*(0/2), &csr1
.word
);
1814 csr1
.field
.Bss0Key0CipherAlg
= SetAsicWcidAttri
.Cipher
;
1815 csr1
.field
.Bss0Key1CipherAlg
= SetAsicWcidAttri
.Cipher
;
1817 RTUSBWriteMACRegister(pAd
, SHARED_KEY_MODE_BASE
+4*(0/2), csr1
.word
);
1819 #endif // CONFIG_STA_SUPPORT //
1823 #ifdef CONFIG_STA_SUPPORT
1824 #ifdef QOS_DLS_SUPPORT
1825 // avoid in interrupt when write key
1826 case RT_CMD_SET_KEY_TABLE
: //General call for AsicAddPairwiseKeyEntry()
1828 RT_ADD_PAIRWISE_KEY_ENTRY KeyInfo
;
1829 KeyInfo
= *((PRT_ADD_PAIRWISE_KEY_ENTRY
)(pData
));
1830 AsicAddPairwiseKeyEntry(pAd
,
1832 (UCHAR
)KeyInfo
.MacTabMatchWCID
,
1833 &KeyInfo
.CipherKey
);
1837 case RT_CMD_SET_RX_WCID_TABLE
: //General call for RTMPAddWcidAttributeEntry()
1839 PMAC_TABLE_ENTRY pEntry
;
1840 pEntry
= (PMAC_TABLE_ENTRY
)(pData
);
1841 RTMPAddWcidAttributeEntry(pAd
,
1844 pEntry
->PairwiseKey
.CipherAlg
,
1848 #endif // QOS_DLS_SUPPORT //
1849 #endif // CONFIG_STA_SUPPORT //
1851 case CMDTHREAD_SET_CLIENT_MAC_ENTRY
:
1853 MAC_TABLE_ENTRY
*pEntry
;
1854 pEntry
= (MAC_TABLE_ENTRY
*)pData
;
1857 #ifdef CONFIG_STA_SUPPORT
1858 IF_DEV_CONFIG_OPMODE_ON_STA(pAd
)
1860 AsicRemovePairwiseKeyEntry(pAd
, pEntry
->apidx
, (UCHAR
)pEntry
->Aid
);
1861 if ((pEntry
->AuthMode
<= Ndis802_11AuthModeAutoSwitch
) && (pEntry
->WepStatus
== Ndis802_11Encryption1Enabled
))
1866 ptr
= (PUCHAR
) &uIV
;
1867 *(ptr
+ 3) = (pAd
->StaCfg
.DefaultKeyId
<< 6);
1868 AsicUpdateWCIDIVEIV(pAd
, pEntry
->Aid
, uIV
, 0);
1869 AsicUpdateWCIDAttribute(pAd
, pEntry
->Aid
, BSS0
, pAd
->SharedKey
[BSS0
][pAd
->StaCfg
.DefaultKeyId
].CipherAlg
, FALSE
);
1871 else if (pEntry
->AuthMode
== Ndis802_11AuthModeWPANone
)
1876 ptr
= (PUCHAR
) &uIV
;
1877 *(ptr
+ 3) = (pAd
->StaCfg
.DefaultKeyId
<< 6);
1878 AsicUpdateWCIDIVEIV(pAd
, pEntry
->Aid
, uIV
, 0);
1879 AsicUpdateWCIDAttribute(pAd
, pEntry
->Aid
, BSS0
, pAd
->SharedKey
[BSS0
][pAd
->StaCfg
.DefaultKeyId
].CipherAlg
, FALSE
);
1884 // Other case, disable engine.
1885 // Don't worry WPA key, we will add WPA Key after 4-Way handshaking.
1888 offset
= MAC_WCID_ATTRIBUTE_BASE
+ (pEntry
->Aid
* HW_WCID_ATTRI_SIZE
);
1889 // RX_PKEY_MODE:0 for no security; RX_KEY_TAB:0 for shared key table; BSS_IDX:0
1890 RTUSBWriteMACRegister(pAd
, offset
, 0);
1893 #endif // CONFIG_STA_SUPPORT //
1895 AsicUpdateRxWCIDTable(pAd
, pEntry
->Aid
, pEntry
->Addr
);
1896 printk("UpdateRxWCIDTable(): Aid=%d, Addr=%02x:%02x:%02x:%02x:%02x:%02x!\n", pEntry
->Aid
,
1897 pEntry
->Addr
[0], pEntry
->Addr
[1], pEntry
->Addr
[2], pEntry
->Addr
[3], pEntry
->Addr
[4], pEntry
->Addr
[5]);
1901 case OID_802_11_ADD_WEP
:
1903 #ifdef CONFIG_STA_SUPPORT
1906 PNDIS_802_11_WEP pWepKey
;
1908 DBGPRINT(RT_DEBUG_TRACE
, ("CmdThread::OID_802_11_ADD_WEP \n"));
1910 pWepKey
= (PNDIS_802_11_WEP
)pData
;
1911 KeyIdx
= pWepKey
->KeyIndex
& 0x0fffffff;
1913 // it is a shared key
1914 if ((KeyIdx
>= 4) || ((pWepKey
->KeyLength
!= 5) && (pWepKey
->KeyLength
!= 13)))
1916 NdisStatus
= NDIS_STATUS_INVALID_DATA
;
1917 DBGPRINT(RT_DEBUG_ERROR
, ("CmdThread::OID_802_11_ADD_WEP, INVALID_DATA!!\n"));
1922 pAd
->SharedKey
[BSS0
][KeyIdx
].KeyLen
= (UCHAR
) pWepKey
->KeyLength
;
1923 NdisMoveMemory(pAd
->SharedKey
[BSS0
][KeyIdx
].Key
, &pWepKey
->KeyMaterial
, pWepKey
->KeyLength
);
1924 CipherAlg
= (pAd
->SharedKey
[BSS0
][KeyIdx
].KeyLen
== 5)? CIPHER_WEP64
: CIPHER_WEP128
;
1927 // Change the WEP cipher to CKIP cipher if CKIP KP on.
1928 // Funk UI or Meetinghouse UI will add ckip key from this path.
1931 if (pAd
->OpMode
== OPMODE_STA
)
1933 pAd
->MacTab
.Content
[BSSID_WCID
].PairwiseKey
.CipherAlg
= pAd
->SharedKey
[BSS0
][KeyIdx
].CipherAlg
;
1934 pAd
->MacTab
.Content
[BSSID_WCID
].PairwiseKey
.KeyLen
= pAd
->SharedKey
[BSS0
][KeyIdx
].KeyLen
;
1936 pAd
->SharedKey
[BSS0
][KeyIdx
].CipherAlg
= CipherAlg
;
1937 if (pWepKey
->KeyIndex
& 0x80000000)
1939 // Default key for tx (shared key)
1941 UINT32 WCIDAttri
, Value
;
1942 USHORT offset
, offset2
;
1943 NdisZeroMemory(IVEIV
, 8);
1944 pAd
->StaCfg
.DefaultKeyId
= (UCHAR
) KeyIdx
;
1945 // Add BSSID to WCTable. because this is Tx wep key.
1946 // WCID Attribute UDF:3, BSSIdx:3, Alg:3, Keytable:1=PAIRWISE KEY, BSSIdx is 0
1947 WCIDAttri
= (CipherAlg
<<1)|SHAREDKEYTABLE
;
1949 offset
= MAC_WCID_ATTRIBUTE_BASE
+ (BSSID_WCID
* HW_WCID_ATTRI_SIZE
);
1950 RTUSBWriteMACRegister(pAd
, offset
, WCIDAttri
);
1952 // Specify key index to find shared key.
1953 IVEIV
[3] = (UCHAR
)(KeyIdx
<< 6); //WEP Eiv bit off. groupkey index is not 0
1954 offset
= PAIRWISE_IVEIV_TABLE_BASE
+ (BSS0Mcast_WCID
* HW_IVEIV_ENTRY_SIZE
);
1955 offset2
= PAIRWISE_IVEIV_TABLE_BASE
+ (BSSID_WCID
* HW_IVEIV_ENTRY_SIZE
);
1959 Value
+= (IVEIV
[i
+1]<<8);
1960 Value
+= (IVEIV
[i
+2]<<16);
1961 Value
+= (IVEIV
[i
+3]<<24);
1962 RTUSBWriteMACRegister(pAd
, offset
+i
, Value
);
1963 RTUSBWriteMACRegister(pAd
, offset2
+i
, Value
);
1967 // 2. WCID Attribute UDF:3, BSSIdx:3, Alg:3, Keytable:use share key, BSSIdx is 0
1968 WCIDAttri
= (pAd
->SharedKey
[BSS0
][KeyIdx
].CipherAlg
<<1)|SHAREDKEYTABLE
;
1969 offset
= MAC_WCID_ATTRIBUTE_BASE
+ (BSS0Mcast_WCID
* HW_WCID_ATTRI_SIZE
);
1970 DBGPRINT(RT_DEBUG_TRACE
, ("BSS0Mcast_WCID : offset = %x, WCIDAttri = %x\n", offset
, WCIDAttri
));
1971 RTUSBWriteMACRegister(pAd
, offset
, WCIDAttri
);
1974 AsicAddSharedKeyEntry(pAd
, BSS0
, (UCHAR
)KeyIdx
, CipherAlg
, pWepKey
->KeyMaterial
, NULL
, NULL
);
1975 DBGPRINT(RT_DEBUG_TRACE
, ("CmdThread::OID_802_11_ADD_WEP (KeyIdx=%d, Len=%d-byte)\n", KeyIdx
, pWepKey
->KeyLength
));
1977 #endif // CONFIG_STA_SUPPORT //
1981 case CMDTHREAD_802_11_COUNTER_MEASURE
:
1984 DBGPRINT(RT_DEBUG_ERROR
, ("--> Control Thread !! ERROR !! Unknown(cmdqelmt->command=0x%x) !! \n", cmdqelmt
->command
));
1989 if (cmdqelmt
->CmdFromNdis
== TRUE
)
1991 if (cmdqelmt
->buffer
!= NULL
)
1992 NdisFreeMemory(cmdqelmt
->buffer
, cmdqelmt
->bufferlength
, 0);
1994 NdisFreeMemory(cmdqelmt
, sizeof(CmdQElmt
), 0);
1998 if ((cmdqelmt
->buffer
!= NULL
) && (cmdqelmt
->bufferlength
!= 0))
1999 NdisFreeMemory(cmdqelmt
->buffer
, cmdqelmt
->bufferlength
, 0);
2001 NdisFreeMemory(cmdqelmt
, sizeof(CmdQElmt
), 0);
2004 } /* end of while */