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 *************************************************************************
28 #include "rt_config.h"
31 INT IoctlResponse(PUCHAR payload, PUCHAR msg, INT len);
34 #define ATE_BBP_REG_NUM 168
35 UCHAR restore_BBP[ATE_BBP_REG_NUM]={0};
38 UCHAR TemplateFrame[24] = {0x08/* Data type */,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0xAA,0xBB,0x12,0x34,0x56,0x00,0x11,0x22,0xAA,0xBB,0xCC,0x00,0x00}; // 802.11 MAC Header, Type:Data, Length:24bytes
39 extern RTMP_RF_REGS RF2850RegTable[];
40 extern UCHAR NUM_OF_2850_CHNL;
43 extern UCHAR EpToQueue[];
44 extern VOID RTUSBRejectPendingPackets( IN PRTMP_ADAPTER pAd);
48 //2008/07/10:KH adds to support 3070 ATE<--
49 extern FREQUENCY_ITEM FreqItems3020[];
50 extern UCHAR NUM_OF_3020_CHNL;
51 //2008/07/10:KH adds to support 3070 ATE-->
55 extern INT ConsoleResponse(IN PUCHAR buff);
56 extern int (*remote_display)(char *);
59 static CHAR CCKRateTable[] = {0, 1, 2, 3, 8, 9, 10, 11, -1}; /* CCK Mode. */
60 static CHAR OFDMRateTable[] = {0, 1, 2, 3, 4, 5, 6, 7, -1}; /* OFDM Mode. */
61 static CHAR HTMIXRateTable[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, -1}; /* HT Mix Mode. */
64 IN PRTMP_ADAPTER pAd);
67 IN PRTMP_ADAPTER pAd);
69 static VOID RtmpDmaEnable(
73 static VOID BbpSoftReset(
74 IN PRTMP_ADAPTER pAd);
76 static VOID RtmpRfIoWrite(
77 IN PRTMP_ADAPTER pAd);
79 static INT ATESetUpFrame(
83 static INT ATETxPwrHandler(
87 static INT ATECmdHandler(
91 static int CheckMCSValid(
97 static VOID ATEWriteTxInfo(
99 IN PTXINFO_STRUC pTxInfo,
100 IN USHORT USBDMApktLen,
106 static VOID ATEWriteTxWI(
107 IN PRTMP_ADAPTER pAd,
108 IN PTXWI_STRUC pTxWI,
110 IN BOOLEAN InsTimestamp,
113 IN BOOLEAN NSeq, // HW new a sequence.
121 IN HTTRANSMIT_SETTING Transmit);
125 static VOID SetJapanFilter(
126 IN PRTMP_ADAPTER pAd);
128 /*=========================end of prototype=========================*/
132 static INT TxDmaBusy(
133 IN PRTMP_ADAPTER pAd)
136 USB_DMA_CFG_STRUC UsbCfg;
138 RTMP_IO_READ32(pAd, USB_DMA_CFG, &UsbCfg.word); // disable DMA
139 if (UsbCfg.field.TxBusy)
147 static INT RxDmaBusy(
148 IN PRTMP_ADAPTER pAd)
151 USB_DMA_CFG_STRUC UsbCfg;
153 RTMP_IO_READ32(pAd, USB_DMA_CFG, &UsbCfg.word); // disable DMA
154 if (UsbCfg.field.RxBusy)
162 static VOID RtmpDmaEnable(
163 IN PRTMP_ADAPTER pAd,
168 USB_DMA_CFG_STRUC UsbCfg;
170 value = Enable > 0 ? 1 : 0;
172 // check DMA is in busy mode.
174 while (TxDmaBusy(pAd) || RxDmaBusy(pAd))
181 //Why not to clear USB DMA TX path first ???
182 RTMP_IO_READ32(pAd, USB_DMA_CFG, &UsbCfg.word); // disable DMA
183 UsbCfg.field.TxBulkEn = value;
184 UsbCfg.field.RxBulkEn = value;
185 RTMP_IO_WRITE32(pAd, USB_DMA_CFG, UsbCfg.word); // abort all TX rings
192 static VOID BbpSoftReset(
193 IN PRTMP_ADAPTER pAd)
197 // Soft reset, set BBP R21 bit0=1->0
198 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R21, &BbpData);
199 BbpData |= 0x00000001; //set bit0=1
200 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R21, BbpData);
202 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R21, &BbpData);
203 BbpData &= ~(0x00000001); //set bit0=0
204 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R21, BbpData);
209 static VOID RtmpRfIoWrite(
210 IN PRTMP_ADAPTER pAd)
212 // Set RF value 1's set R3[bit2] = [0]
213 RTMP_RF_IO_WRITE32(pAd, pAd->LatchRfRegs.R1);
214 RTMP_RF_IO_WRITE32(pAd, pAd->LatchRfRegs.R2);
215 RTMP_RF_IO_WRITE32(pAd, (pAd->LatchRfRegs.R3 & (~0x04)));
216 RTMP_RF_IO_WRITE32(pAd, pAd->LatchRfRegs.R4);
220 // Set RF value 2's set R3[bit2] = [1]
221 RTMP_RF_IO_WRITE32(pAd, pAd->LatchRfRegs.R1);
222 RTMP_RF_IO_WRITE32(pAd, pAd->LatchRfRegs.R2);
223 RTMP_RF_IO_WRITE32(pAd, (pAd->LatchRfRegs.R3 | 0x04));
224 RTMP_RF_IO_WRITE32(pAd, pAd->LatchRfRegs.R4);
228 // Set RF value 3's set R3[bit2] = [0]
229 RTMP_RF_IO_WRITE32(pAd, pAd->LatchRfRegs.R1);
230 RTMP_RF_IO_WRITE32(pAd, pAd->LatchRfRegs.R2);
231 RTMP_RF_IO_WRITE32(pAd, (pAd->LatchRfRegs.R3 & (~0x04)));
232 RTMP_RF_IO_WRITE32(pAd, pAd->LatchRfRegs.R4);
237 static int CheckMCSValid(
247 pRateTab = CCKRateTable;
250 pRateTab = OFDMRateTable;
254 pRateTab = HTMIXRateTable;
257 ATEDBGPRINT(RT_DEBUG_ERROR, ("unrecognizable Tx Mode %d\n", Mode));
263 while(pRateTab[i] != -1)
265 if (pRateTab[i] == Mcs)
274 static INT ATETxPwrHandler(
275 IN PRTMP_ADAPTER pAd,
281 BOOLEAN bPowerReduce = FALSE;
285 #ifdef RALINK_28xx_QA
286 if ((pAd->ate.bQATxStart == TRUE) || (pAd->ate.bQARxStart == TRUE))
288 /* When QA is used for Tx, pAd->ate.TxPower0/1 and real tx power
289 ** are not synchronized.
292 pAd->ate.TxPower0 = pAd->LatchRfRegs.xxx;
293 pAd->ate.TxPower1 = pAd->LatchRfRegs.xxx;
298 #endif // RALINK_28xx_QA //
300 TxPower = index == 0 ? pAd->ate.TxPower0 : pAd->ate.TxPower1;
302 if (pAd->ate.Channel <= 14)
307 // R3, R4 can't large than 31 (0x24), 31 ~ 36 used by BBP 94
311 Bbp94 = BBPR94_DEFAULT + (UCHAR)(TxPower - 31);
313 else if (TxPower < 0)
316 // R3, R4 can't less than 0, -1 ~ -6 used by BBP 94
320 Bbp94 = BBPR94_DEFAULT + TxPower;
326 Bbp94 = BBPR94_DEFAULT;
329 ATEDBGPRINT(RT_DEBUG_TRACE, ("%s (TxPower=%d, R=%ld, BBP_R94=%d)\n", __FUNCTION__, TxPower, R, Bbp94));
336 // R3, R4 can't large than 15 (0x0F)
340 else if (TxPower < 0)
343 // R3, R4 can't less than 0
346 ASSERT((TxPower >= -7));
347 R = (ULONG)(TxPower + 7);
356 ATEDBGPRINT(RT_DEBUG_TRACE, ("%s (TxPower=%d, R=%lu)\n", __FUNCTION__, TxPower, R));
358 //2008/09/10:KH adds to support 3070 ATE TX Power tunning real time<--
364 RT30xxReadRFRegister(pAd, RF_R12, (PUCHAR)&RFValue);
365 RFValue = (RFValue & 0xE0) | TxPower;
366 RT30xxWriteRFRegister(pAd, RF_R12, (UCHAR)RFValue);
367 ATEDBGPRINT(RT_DEBUG_TRACE, ("3070 or 2070:%s (TxPower=%d, RFValue=%x)\n", __FUNCTION__, TxPower, RFValue));
373 if (pAd->ate.Channel <= 14)
377 R = R << 9; // shift TX power control to correct RF(R3) register bit position
378 R |= (pAd->LatchRfRegs.R3 & 0xffffc1ff);
379 pAd->LatchRfRegs.R3 = R;
383 R = R << 6; // shift TX power control to correct RF(R4) register bit position
384 R |= (pAd->LatchRfRegs.R4 & 0xfffff83f);
385 pAd->LatchRfRegs.R4 = R;
390 if (bPowerReduce == FALSE)
394 R = (R << 10) | (1 << 9); // shift TX power control to correct RF(R3) register bit position
395 R |= (pAd->LatchRfRegs.R3 & 0xffffc1ff);
396 pAd->LatchRfRegs.R3 = R;
400 R = (R << 7) | (1 << 6); // shift TX power control to correct RF(R4) register bit position
401 R |= (pAd->LatchRfRegs.R4 & 0xfffff83f);
402 pAd->LatchRfRegs.R4 = R;
409 R = (R << 10); // shift TX power control to correct RF(R3) register bit position
410 R |= (pAd->LatchRfRegs.R3 & 0xffffc1ff);
412 /* Clear bit 9 of R3 to reduce 7dB. */
413 pAd->LatchRfRegs.R3 = (R & (~(1 << 9)));
417 R = (R << 7); // shift TX power control to correct RF(R4) register bit position
418 R |= (pAd->LatchRfRegs.R4 & 0xfffff83f);
420 /* Clear bit 6 of R4 to reduce 7dB. */
421 pAd->LatchRfRegs.R4 = (R & (~(1 << 6)));
427 //2008/09/10:KH adds to support 3070 ATE TX Power tunning real time-->
433 static INT ATETxPwrHandler(
434 IN PRTMP_ADAPTER pAd,
441 #ifdef RALINK_28xx_QA
442 if ((pAd->ate.bQATxStart == TRUE) || (pAd->ate.bQARxStart == TRUE))
444 // TODO: how to get current TxPower0/1 from pAd->LatchRfRegs ?
445 /* When QA is used for Tx, pAd->ate.TxPower0/1 and real tx power
446 ** are not synchronized.
449 pAd->ate.TxPower0 = pAd->LatchRfRegs.xxx;
450 pAd->ate.TxPower1 = pAd->LatchRfRegs.xxx;
455 #endif // RALINK_28xx_QA //
457 TxPower = index == 0 ? pAd->ate.TxPower0 : pAd->ate.TxPower1;
462 // R3, R4 can't large than 36 (0x24), 31 ~ 36 used by BBP 94
466 Bbp94 = BBPR94_DEFAULT + (UCHAR)(TxPower - 31);
468 else if (TxPower < 0)
471 // R3, R4 can't less than 0, -1 ~ -6 used by BBP 94
475 Bbp94 = BBPR94_DEFAULT + TxPower;
481 Bbp94 = BBPR94_DEFAULT;
484 ATEDBGPRINT(RT_DEBUG_TRACE, ("%s (TxPower=%d, R3=%ld, BBP_R94=%d)\n", __FUNCTION__, TxPower, R, Bbp94));
486 if (pAd->ate.Channel <= 14)
490 R = R << 9; // shift TX power control to correct RF(R3) register bit position
491 R |= (pAd->LatchRfRegs.R3 & 0xffffc1ff);
492 pAd->LatchRfRegs.R3 = R;
496 R = R << 6; // shift TX power control to correct RF(R4) register bit position
497 R |= (pAd->LatchRfRegs.R4 & 0xfffff83f);
498 pAd->LatchRfRegs.R4 = R;
505 R = (R << 10) | (1 << 9); // shift TX power control to correct RF(R3) register bit position
506 R |= (pAd->LatchRfRegs.R3 & 0xffffc1ff);
507 pAd->LatchRfRegs.R3 = R;
511 R = (R << 7) | (1 << 6); // shift TX power control to correct RF(R4) register bit position
512 R |= (pAd->LatchRfRegs.R4 & 0xfffff83f);
513 pAd->LatchRfRegs.R4 = R;
524 ==========================================================================
526 Set ATE operation mode to
527 0. ATESTART = Start ATE Mode
528 1. ATESTOP = Stop ATE Mode
529 2. TXCONT = Continuous Transmit
530 3. TXCARR = Transmit Carrier
531 4. TXFRAME = Transmit Frames
532 5. RXFRAME = Receive Frames
533 #ifdef RALINK_28xx_QA
534 6. TXSTOP = Stop Any Type of Transmition
535 7. RXSTOP = Stop Receiving Frames
536 #endif // RALINK_28xx_QA //
538 TRUE if all parameters are OK, FALSE otherwise
539 ==========================================================================
543 /*=======================End of RT2860=======================*/
546 /*======================Start of RT2870======================*/
551 static INT ATECmdHandler(
552 IN PRTMP_ADAPTER pAd,
559 //NDIS_STATUS Status = NDIS_STATUS_SUCCESS;
564 ATEDBGPRINT(RT_DEBUG_TRACE, ("===> ATECmdHandler()\n"));
565 ATEAsicSwitchChannel(pAd);
566 /* AsicLockChannel() is empty function so far in fact */
567 AsicLockChannel(pAd, pAd->ate.Channel);
571 // Default value in BBP R22 is 0x0.
574 /* Enter ATE mode and set Tx/Rx Idle */
575 if (!strcmp(arg, "ATESTART"))
577 #ifdef CONFIG_STA_SUPPORT
579 #endif // CONFIG_STA_SUPPORT //
580 ATEDBGPRINT(RT_DEBUG_TRACE, ("ATE: ATESTART\n"));
582 netif_stop_queue(pAd->net_dev);
584 atemode = pAd->ate.Mode;
585 pAd->ate.Mode = ATE_START;
586 // pAd->ate.TxDoneCount = pAd->ate.TxCount;
588 RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &Value);
590 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, Value);
592 // Disable auto responder
593 RTMP_IO_READ32(pAd, AUTO_RSP_CFG, &temp);
594 temp = temp & 0xFFFFFFFE;
595 RTMP_IO_WRITE32(pAd, AUTO_RSP_CFG, temp);
597 // read MAC_SYS_CTRL and backup MAC_SYS_CTRL value.
598 RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &MacData);
599 // clean bit4 to stop continuous Tx production test.
600 MacData &= 0xFFFFFFEF;
601 // Stop continuous TX production test.
602 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, MacData);//disable or cancel pending irp first ???
604 if (atemode & ATE_TXCARR
606 || atemode & ATE_TXCONT
612 RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &temp);
613 temp = temp |0x00000002;
614 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, temp);
615 RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &temp);
616 temp = temp & ~(0x00000002);
617 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, temp);
618 //Restore All BBP Value
619 for(i=0;i<ATE_BBP_REG_NUM;i++)
620 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd,i,restore_BBP[i]);
623 // No Carrier Test set BBP R22 bit7=0, bit6=0, bit[5~0]=0x0
624 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R22, &BbpData);
625 BbpData &= 0xFFFFFF00; //clear bit7, bit6, bit[5~0]
626 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R22, BbpData);
628 else if (atemode & ATE_TXCARRSUPP)
632 RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &temp);
633 temp = temp |0x00000002;
634 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, temp);
635 RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &temp);
636 temp = temp & ~(0x00000002);
637 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, temp);
638 //Restore All BBP Value
639 for(i=0;i<ATE_BBP_REG_NUM;i++)
640 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd,i,restore_BBP[i]);
643 // No Cont. TX set BBP R22 bit7=0
644 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R22, &BbpData);
645 BbpData &= ~(1 << 7); //set bit7=0
646 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R22, BbpData);
648 // No Carrier Suppression set BBP R24 bit0=0
649 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R24, &BbpData);
650 BbpData &= 0xFFFFFFFE; //clear bit0
651 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R24, BbpData);
653 // We should free some resource which allocate when ATE_TXFRAME , ATE_STOP, and ATE_TXCONT.
654 // TODO:Should we free some resource which was allocated when LoopBack and ATE_STOP ?
655 else if ((atemode & ATE_TXFRAME) || (atemode == ATE_STOP))
657 if (atemode & ATE_TXCONT)
659 // Not Cont. TX anymore, so set BBP R22 bit7=0
660 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R22, &BbpData);
661 BbpData &= ~(1 << 7); //set bit7=0
662 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R22, BbpData);
665 RtmpDmaEnable(pAd, 0);
668 // It seems nothing to free,
669 // because we didn't allocate any resource when we entered ATE_TXFRAME mode latestly.
673 RtmpDmaEnable(pAd, 1);
676 RTUSBRejectPendingPackets(pAd);
677 RTUSBCleanUpDataBulkOutQueue(pAd);
679 #ifdef CONFIG_STA_SUPPORT
681 // It will be called in MlmeSuspend().
683 // Cancel pending timers
684 RTMPCancelTimer(&pAd->MlmeAux.AssocTimer, &Cancelled);
685 RTMPCancelTimer(&pAd->MlmeAux.ReassocTimer, &Cancelled);
686 RTMPCancelTimer(&pAd->MlmeAux.DisassocTimer, &Cancelled);
687 RTMPCancelTimer(&pAd->MlmeAux.AuthTimer, &Cancelled);
688 RTMPCancelTimer(&pAd->MlmeAux.BeaconTimer, &Cancelled);
689 RTMPCancelTimer(&pAd->MlmeAux.ScanTimer, &Cancelled);
690 #endif // CONFIG_STA_SUPPORT //
692 //RTUSBCleanUpMLMEWaitQueue(pAd); /* not used in RT28xx */
693 RTUSBCleanUpMLMEBulkOutQueue(pAd);
695 // Sometimes kernel will hang on, so we avoid calling MlmeSuspend().
696 // MlmeSuspend(pAd, TRUE);
697 //RTMPCancelTimer(&pAd->Mlme.PeriodicTimer, &Cancelled);
700 RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &Value);
702 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, Value);
705 RtmpDmaEnable(pAd, 0);
708 RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &Value);
710 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, Value);
712 // Make sure there are no pending bulk in/out IRPs before we go on.
713 /*=========================================================================*/
714 /* pAd->PendingRx is not of type atomic_t anymore in 28xx */
715 // while ((atomic_read(&pAd->PendingRx) > 0)) //pAd->BulkFlags != 0 wait bulk out finish
716 while ((pAd->PendingRx > 0)) //pAd->BulkFlags != 0 wait bulk out finish
719 ATE_RTUSBCancelPendingBulkInIRP(pAd);
721 NdisInterlockedDecrement(&pAd->PendingRx);
723 /* delay 0.5 seconds */
724 RTMPusecDelay(500000);
727 /* peter : why don't we have to get BulkOutLock first ? */
728 while (((pAd->BulkOutPending[0] == TRUE) ||
729 (pAd->BulkOutPending[1] == TRUE) ||
730 (pAd->BulkOutPending[2] == TRUE) ||
731 (pAd->BulkOutPending[3] == TRUE)) && (pAd->BulkFlags != 0)) //pAd->BulkFlags != 0 wait bulk out finish
735 /* pAd->BulkOutPending[y] will be set to FALSE in RTUSBCancelPendingBulkOutIRP(pAd) */
736 RTUSBCancelPendingBulkOutIRP(pAd);
739 /* we have enough time delay in RTUSBCancelPendingBulkOutIRP(pAd)
740 ** so this is not necessary
742 // RTMPusecDelay(500000);
745 /* pAd->PendingRx is not of type atomic_t anymore in 28xx */
746 // ASSERT(atomic_read(&pAd->PendingRx) == 0);
747 ASSERT(pAd->PendingRx == 0);
748 /*=========================================================================*/
750 // reset Rx statistics.
751 pAd->ate.LastSNR0 = 0;
752 pAd->ate.LastSNR1 = 0;
753 pAd->ate.LastRssi0 = 0;
754 pAd->ate.LastRssi1 = 0;
755 pAd->ate.LastRssi2 = 0;
756 pAd->ate.AvgRssi0 = 0;
757 pAd->ate.AvgRssi1 = 0;
758 pAd->ate.AvgRssi2 = 0;
759 pAd->ate.AvgRssi0X8 = 0;
760 pAd->ate.AvgRssi1X8 = 0;
761 pAd->ate.AvgRssi2X8 = 0;
762 pAd->ate.NumOfAvgRssiSample = 0;
764 #ifdef RALINK_28xx_QA
766 pAd->ate.bQATxStart = FALSE;
767 pAd->ate.bQARxStart = FALSE;
772 pAd->ate.OtherData = 0;
774 pAd->ate.OtherCount = 0;
788 pAd->ate.TxDoneCount = 0;
789 pAd->ate.TxStatus = 0; // task Tx status // 0 --> task is idle, 1 --> task is running
790 #endif // RALINK_28xx_QA //
796 #ifdef CONFIG_STA_SUPPORT
797 AsicDisableSync(pAd);
800 ** If we skip "LinkDown()", we should disable protection
801 ** to prevent from sending out RTS or CTS-to-self.
803 ATEDisableAsicProtect(pAd);
804 RTMPStationStop(pAd);
805 #endif // CONFIG_STA_SUPPORT //
807 // Default value in BBP R22 is 0x0.
809 RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &MacData);
811 // Clean bit4 to stop continuous Tx production test.
812 MacData &= 0xFFFFFFEF;
813 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R22, BbpData);
814 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, MacData);
815 //Clean ATE Bulk in/out counter and continue setup
816 InterlockedExchange(&pAd->BulkOutRemained, 0);
818 /* NdisAcquireSpinLock()/NdisReleaseSpinLock() need only one argument in RT28xx */
819 NdisAcquireSpinLock(&pAd->GenericLock);
820 pAd->ContinBulkOut = FALSE;
821 pAd->ContinBulkIn = FALSE;
822 NdisReleaseSpinLock(&pAd->GenericLock);
824 RTUSB_CLEAR_BULK_FLAG(pAd, fRTUSB_BULK_OUT_DATA_ATE);
826 else if (!strcmp(arg, "ATESTOP"))
828 ATEDBGPRINT(RT_DEBUG_TRACE, ("ATE : ATESTOP ===>\n"));
830 // Default value in BBP R22 is 0x0.
832 RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &MacData);//0820
833 // Clean bit4 to stop continuous Tx production test.
834 MacData &= 0xFFFFFFEF;
835 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R22, BbpData);
836 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, MacData); // recover the MAC_SYS_CTRL register back.
839 RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &Value);
841 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, Value);
845 ** Q : How to do the following I/O if Tx, Rx DMA is aborted ?
846 ** Ans : Bulk endpoints are aborted, while the control endpoint is not.
848 RtmpDmaEnable(pAd, 0);
851 RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &Value);
853 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, Value);
855 /* Make sure there are no pending bulk in/out IRPs before we go on. */
856 /*=========================================================================*/
857 // while ((atomic_read(&pAd->PendingRx) > 0)) //pAd->BulkFlags != 0 wait bulk out finish
858 while (pAd->PendingRx > 0)
861 ATE_RTUSBCancelPendingBulkInIRP(pAd);
863 // NdisInterlockedDecrement(&pAd->PendingRx);
866 RTMPusecDelay(500000);
869 while (((pAd->BulkOutPending[0] == TRUE) ||
870 (pAd->BulkOutPending[1] == TRUE) ||
871 (pAd->BulkOutPending[2] == TRUE) ||
872 (pAd->BulkOutPending[3] == TRUE)) && (pAd->BulkFlags != 0)) //pAd->BulkFlags != 0 wait bulk out finish
876 RTUSBCancelPendingBulkOutIRP(pAd);
879 RTMPusecDelay(500000);
882 // ASSERT(atomic_read(&pAd->PendingRx) == 0);
883 ASSERT(pAd->PendingRx == 0);
884 /*=========================================================================*/
886 /*=========================================================================*/
887 // InterlockedExchange(&pAd->PendingRx, 0);
889 pAd->NextRxBulkInReadIndex = 0; // Next Rx Read index
890 pAd->NextRxBulkInIndex = RX_RING_SIZE - 1; // Rx Bulk pointer
891 pAd->NextRxBulkInPosition = 0;
892 for (i = 0; i < (RX_RING_SIZE); i++)
894 PRX_CONTEXT pRxContext = &(pAd->RxContext[i]);
895 NdisZeroMemory(pRxContext->TransferBuffer, MAX_RXBULK_SIZE);
896 /* peter : why don't we have to get BulkInLock first ? */
897 pRxContext->pAd = pAd;
898 pRxContext->pIrp = NULL;
900 pRxContext->BulkInOffset = 0;
901 pRxContext->bRxHandling = FALSE;
903 pRxContext->InUse = FALSE;
904 pRxContext->IRPPending = FALSE;
905 pRxContext->Readable = FALSE;
906 // pRxContext->ReorderInUse = FALSE;
907 // pRxContext->ReadPosOffset = 0;
910 /*=========================================================================*/
912 /*=========================================================================*/
915 RTUSBCancelPendingBulkOutIRP(pAd);
918 /*=========================================================================*/
919 // Enable auto responder.
920 RTMP_IO_READ32(pAd, AUTO_RSP_CFG, &temp);
921 temp = temp | (0x01);
922 RTMP_IO_WRITE32(pAd, AUTO_RSP_CFG, temp);
924 /*================================================*/
925 AsicEnableBssSync(pAd);
928 /* In 2870 chipset, ATE_BBP_IO_READ8_BY_REG_ID() == RTMP_BBP_IO_READ8_BY_REG_ID() */
929 /* Both rt2870ap and rt2870sta use BbpSoftReset(pAd) to do BBP soft reset */
931 /*================================================*/
933 #ifdef CONFIG_STA_SUPPORT
934 // Set all state machines back IDLE
935 pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
936 pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
937 pAd->Mlme.AuthMachine.CurrState = AUTH_REQ_IDLE;
938 pAd->Mlme.AuthRspMachine.CurrState = AUTH_RSP_IDLE;
939 pAd->Mlme.SyncMachine.CurrState = SYNC_IDLE;
940 pAd->Mlme.ActMachine.CurrState = ACT_IDLE;
941 #endif // CONFIG_STA_SUPPORT //
944 // ===> refer to MlmeRestartStateMachine().
945 // When we entered ATE_START mode, PeriodicTimer was not cancelled.
946 // So we don't have to set it here.
948 //RTMPSetTimer(pAd, &pAd->Mlme.PeriodicTimer, MLME_TASK_EXEC_INTV);
950 ASSERT(pAd->CommonCfg.Channel != 0);
952 AsicSwitchChannel(pAd, pAd->CommonCfg.Channel, FALSE);
953 AsicLockChannel(pAd, pAd->CommonCfg.Channel);
956 #ifdef CONFIG_STA_SUPPORT
957 RTMPStationStart(pAd);
958 #endif // CONFIG_STA_SUPPORT //
961 // These two steps have been done when entering ATE_STOP mode.
963 // Clean ATE Bulk in/out counter and continue setup.
964 InterlockedExchange(&pAd->BulkOutRemained, 0);
965 NdisAcquireSpinLock(&pAd->GenericLock);
966 pAd->ContinBulkOut = FALSE;
967 pAd->ContinBulkIn = FALSE;
968 NdisReleaseSpinLock(&pAd->GenericLock);
970 /* Wait 50ms to prevent next URB to bulkout during HW reset. */
971 /* todo : remove this if not necessary */
974 pAd->ate.Mode = ATE_STOP;
977 RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &Value);
979 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, Value);
981 /*=========================================================================*/
982 /* restore RX_FILTR_CFG */
983 #ifdef CONFIG_STA_SUPPORT
984 /* restore RX_FILTR_CFG in order that QA maybe set it to 0x3 */
985 RTMP_IO_WRITE32(pAd, RX_FILTR_CFG, STANORMAL);
986 #endif // CONFIG_STA_SUPPORT //
987 /*=========================================================================*/
989 // Enable Tx, RX DMA.
990 RtmpDmaEnable(pAd, 1);
993 RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &Value);
995 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, Value);
997 // Wait 10ms to wait all of the bulk-in URBs to complete.
998 /* todo : remove this if not necessary */
1001 // Everything is ready to start normal Tx/Rx.
1002 RTUSBBulkReceive(pAd);
1003 netif_start_queue(pAd->net_dev);
1005 ATEDBGPRINT(RT_DEBUG_TRACE, ("<=== ATE : ATESTOP \n"));
1007 else if (!strcmp(arg, "TXCARR")) // Tx Carrier
1009 ATEDBGPRINT(RT_DEBUG_TRACE, ("ATE: TXCARR\n"));
1010 pAd->ate.Mode |= ATE_TXCARR;
1013 for(i=0;i<ATE_BBP_REG_NUM;i++)
1015 //Record All BBP Value
1016 for(i=0;i<ATE_BBP_REG_NUM;i++)
1017 ATE_BBP_IO_READ8_BY_REG_ID(pAd,i,&restore_BBP[i]);
1021 // May be we need not to do this, because these have been done in ATE_START mode ???
1022 RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &Value);
1024 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, Value);
1026 // QA has done the following steps if it is used.
1027 if (pAd->ate.bQATxStart == FALSE)
1032 // Carrier Test set BBP R22 bit7=1, bit6=1, bit[5~0]=0x01
1033 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R22, &BbpData);
1034 BbpData &= 0xFFFFFF00; //clear bit7, bit6, bit[5~0]
1035 BbpData |= 0x000000C1; //set bit7=1, bit6=1, bit[5~0]=0x01
1036 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R22, BbpData);
1038 // set MAC_SYS_CTRL(0x1004) Continuous Tx Production Test (bit4) = 1
1039 RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &Value);
1040 Value = Value | 0x00000010;
1041 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, Value);
1044 else if (!strcmp(arg, "TXCONT")) // Tx Continue
1046 if (pAd->ate.bQATxStart == TRUE)
1048 /* set MAC_SYS_CTRL(0x1004) bit4(Continuous Tx Production Test)
1049 and bit2(MAC TX enable) back to zero. */
1050 RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &MacData);
1051 MacData &= 0xFFFFFFEB;
1052 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, MacData);
1054 // set BBP R22 bit7=0
1055 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R22, &BbpData);
1056 BbpData &= 0xFFFFFF7F; //set bit7=0
1057 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R22, BbpData);
1061 ** Step 1: Send 50 packets first then wait for a moment.
1062 ** Step 2: Send more 50 packet then start continue mode.
1064 ATEDBGPRINT(RT_DEBUG_TRACE, ("ATE: TXCONT\n"));
1067 for(i=0;i<ATE_BBP_REG_NUM;i++)
1069 //Record All BBP Value
1070 for(i=0;i<ATE_BBP_REG_NUM;i++)
1071 ATE_BBP_IO_READ8_BY_REG_ID(pAd,i,&restore_BBP[i]);
1074 // Step 1: send 50 packets first.
1075 pAd->ate.Mode |= ATE_TXCONT;
1076 pAd->ate.TxCount = 50;
1077 pAd->ate.TxDoneCount = 0;
1082 // Abort Tx, RX DMA.
1083 RtmpDmaEnable(pAd, 0);
1086 /* Only needed if we have to send some normal frames. */
1087 SetJapanFilter(pAd);
1089 // Setup frame format.
1090 ATESetUpFrame(pAd, 0);
1093 RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &Value);
1095 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, Value);
1098 RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &Value);
1100 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, Value);
1102 // Start Tx, RX DMA.
1103 RtmpDmaEnable(pAd, 1);
1105 InterlockedExchange(&pAd->BulkOutRemained, pAd->ate.TxCount);
1107 #ifdef RALINK_28xx_QA
1108 if (pAd->ate.bQATxStart == TRUE)
1110 pAd->ate.TxStatus = 1;
1111 //pAd->ate.Repeat = 0;
1113 #endif // RALINK_28xx_QA //
1115 NdisAcquireSpinLock(&pAd->GenericLock);//0820
1116 pAd->ContinBulkOut = FALSE;
1117 NdisReleaseSpinLock(&pAd->GenericLock);
1119 RTUSB_SET_BULK_FLAG(pAd, fRTUSB_BULK_OUT_DATA_ATE);
1122 RTUSBKickBulkOut(pAd);
1124 /* To make sure all the 50 frames have been bulk out before executing step 2 */
1125 while (atomic_read(&pAd->BulkOutRemained) > 0)
1127 RTMPusecDelay(5000);
1130 // Step 2: send more 50 packets then start continue mode.
1131 // Abort Tx, RX DMA.
1132 RtmpDmaEnable(pAd, 0);
1134 // Cont. TX set BBP R22 bit7=1
1135 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R22, &BbpData);
1136 BbpData |= 0x00000080; //set bit7=1
1137 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R22, BbpData);
1139 pAd->ate.TxCount = 50;
1140 pAd->ate.TxDoneCount = 0;
1142 SetJapanFilter(pAd);
1144 // Setup frame format.
1145 ATESetUpFrame(pAd, 0);
1148 RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &Value);
1150 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, Value);
1153 RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &Value);
1156 // Start Tx, RX DMA.
1157 RtmpDmaEnable(pAd, 1);
1159 InterlockedExchange(&pAd->BulkOutRemained, pAd->ate.TxCount);
1161 #ifdef RALINK_28xx_QA
1162 if (pAd->ate.bQATxStart == TRUE)
1164 pAd->ate.TxStatus = 1;
1165 //pAd->ate.Repeat = 0;
1167 #endif // RALINK_28xx_QA //
1169 NdisAcquireSpinLock(&pAd->GenericLock);//0820
1170 pAd->ContinBulkOut = FALSE;
1171 NdisReleaseSpinLock(&pAd->GenericLock);
1173 RTUSB_SET_BULK_FLAG(pAd, fRTUSB_BULK_OUT_DATA_ATE);
1175 RTUSBKickBulkOut(pAd);
1180 while (atomic_read(&pAd->BulkOutRemained) > 0)
1182 RTMPusecDelay(5000);
1186 // Set MAC_SYS_CTRL(0x1004) Continuous Tx Production Test (bit4) = 1.
1187 RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &MacData);
1188 MacData |= 0x00000010;
1189 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, MacData);
1191 else if (!strcmp(arg, "TXFRAME")) // Tx Frames
1193 ATEDBGPRINT(RT_DEBUG_TRACE, ("ATE: TXFRAME(Count=0x%08x)\n", pAd->ate.TxCount));
1194 pAd->ate.Mode |= ATE_TXFRAME;
1199 // Default value in BBP R22 is 0x0.
1202 RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &MacData);
1204 // Clean bit4 to stop continuous Tx production test.
1205 MacData &= 0xFFFFFFEF;
1207 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R22, BbpData);
1208 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, MacData);
1210 #ifdef RALINK_28xx_QA
1211 // add this for LoopBack mode
1212 if (pAd->ate.bQARxStart == FALSE)
1215 RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &Value);
1217 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, Value);
1220 if (pAd->ate.bQATxStart == TRUE)
1222 pAd->ate.TxStatus = 1;
1223 //pAd->ate.Repeat = 0;
1227 RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &Value);
1229 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, Value);
1230 #endif // RALINK_28xx_QA //
1233 RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &Value);
1235 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, Value);
1237 SetJapanFilter(pAd);
1239 // Abort Tx, RX DMA.
1240 RtmpDmaEnable(pAd, 0);
1242 pAd->ate.TxDoneCount = 0;
1244 // Setup frame format
1245 ATESetUpFrame(pAd, 0);
1247 // Start Tx, RX DMA.
1248 RtmpDmaEnable(pAd, 1);
1250 // Check count is continuous or not yet.
1252 // Due to the type mismatch between "pAd->BulkOutRemained"(atomic_t) and "pAd->ate.TxCount"(UINT32)
1254 if (pAd->ate.TxCount == 0)
1256 InterlockedExchange(&pAd->BulkOutRemained, 0);
1260 InterlockedExchange(&pAd->BulkOutRemained, pAd->ate.TxCount);
1262 ATEDBGPRINT(RT_DEBUG_TRACE, ("bulk out count = %d\n", atomic_read(&pAd->BulkOutRemained)));
1263 ASSERT((atomic_read(&pAd->BulkOutRemained) >= 0));
1265 if (atomic_read(&pAd->BulkOutRemained) == 0)
1267 ATEDBGPRINT(RT_DEBUG_TRACE, ("Send packet countinuously\n"));
1269 /* In 28xx, NdisAcquireSpinLock() == spin_lock_bh() */
1270 /* NdisAcquireSpinLock only need one argument in 28xx. */
1271 NdisAcquireSpinLock(&pAd->GenericLock);
1272 pAd->ContinBulkOut = TRUE;
1273 NdisReleaseSpinLock(&pAd->GenericLock);
1275 /* In 28xx, BULK_OUT_LOCK() == spin_lock_irqsave() */
1276 BULK_OUT_LOCK(&pAd->BulkOutLock[0], IrqFlags);// peter : NdisAcquireSpinLock ==> BULK_OUT_LOCK
1277 pAd->BulkOutPending[0] = FALSE;
1278 BULK_OUT_UNLOCK(&pAd->BulkOutLock[0], IrqFlags);// peter : NdisAcquireSpinLock ==> BULK_OUT_LOCK
1282 ATEDBGPRINT(RT_DEBUG_TRACE, ("Send packets depend on counter\n"));
1284 NdisAcquireSpinLock(&pAd->GenericLock);
1285 pAd->ContinBulkOut = FALSE;
1286 NdisReleaseSpinLock(&pAd->GenericLock);
1288 BULK_OUT_LOCK(&pAd->BulkOutLock[0], IrqFlags);
1289 pAd->BulkOutPending[0] = FALSE;
1290 BULK_OUT_UNLOCK(&pAd->BulkOutLock[0], IrqFlags);
1293 RTUSB_SET_BULK_FLAG(pAd, fRTUSB_BULK_OUT_DATA_ATE);
1296 RTUSBKickBulkOut(pAd);
1298 #ifdef RALINK_28xx_QA
1299 else if (!strcmp(arg, "TXSTOP")) //Enter ATE mode and set Tx/Rx Idle
1301 ATEDBGPRINT(RT_DEBUG_TRACE, ("ATE: TXSTOP\n"));
1303 atemode = pAd->ate.Mode;
1304 pAd->ate.Mode &= ATE_TXSTOP;
1305 pAd->ate.bQATxStart = FALSE;
1306 // pAd->ate.TxDoneCount = pAd->ate.TxCount;
1308 /*=========================================================================*/
1309 if (atemode & ATE_TXCARR)
1311 // No Carrier Test set BBP R22 bit7=0, bit6=0, bit[5~0]=0x0
1312 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R22, &BbpData);
1313 BbpData &= 0xFFFFFF00; //clear bit7, bit6, bit[5~0]
1314 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R22, BbpData);
1316 else if (atemode & ATE_TXCARRSUPP)
1318 // No Cont. TX set BBP R22 bit7=0
1319 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R22, &BbpData);
1320 BbpData &= ~(1 << 7); //set bit7=0
1321 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R22, BbpData);
1323 // No Carrier Suppression set BBP R24 bit0=0
1324 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R24, &BbpData);
1325 BbpData &= 0xFFFFFFFE; //clear bit0
1326 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R24, BbpData);
1328 else if ((atemode & ATE_TXFRAME) || (atemode == ATE_STOP))
1330 if (atemode & ATE_TXCONT)
1332 // No Cont. TX set BBP R22 bit7=0
1333 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R22, &BbpData);
1334 BbpData &= ~(1 << 7); //set bit7=0
1335 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R22, BbpData);
1339 /*=========================================================================*/
1340 RTUSBRejectPendingPackets(pAd);
1341 RTUSBCleanUpDataBulkOutQueue(pAd);
1343 /* not used in RT28xx */
1344 //RTUSBCleanUpMLMEWaitQueue(pAd);
1345 /* empty function so far */
1346 RTUSBCleanUpMLMEBulkOutQueue(pAd);
1347 /*=========================================================================*/
1348 // Abort Tx, RX DMA.
1349 RtmpDmaEnable(pAd, 0);
1350 /*=========================================================================*/
1352 /* In 28xx, pAd->PendingRx is not of type atomic_t anymore */
1353 // while ((atomic_read(&pAd->PendingRx) > 0)) //pAd->BulkFlags != 0 wait bulk out finish
1354 /* peter todo : BulkInLock */
1355 while (pAd->PendingRx > 0)
1358 ATE_RTUSBCancelPendingBulkInIRP(pAd);
1360 // NdisInterlockedDecrement(&pAd->PendingRx);
1363 RTMPusecDelay(500000);
1366 while (((pAd->BulkOutPending[0] == TRUE) ||
1367 (pAd->BulkOutPending[1] == TRUE) ||
1368 (pAd->BulkOutPending[2] == TRUE) ||
1369 (pAd->BulkOutPending[3] == TRUE)) && (pAd->BulkFlags != 0)) //pAd->BulkFlags != 0 wait bulk out finish
1373 RTUSBCancelPendingBulkOutIRP(pAd);
1376 RTMPusecDelay(500000);
1379 ASSERT(pAd->PendingRx == 0);
1380 /*=========================================================================*/
1381 // Enable Tx, Rx DMA.
1382 RtmpDmaEnable(pAd, 1);
1384 /* task Tx status : 0 --> task is idle, 1 --> task is running */
1385 pAd->ate.TxStatus = 0;
1391 RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &MacData);
1392 MacData &= (0xfffffffb);
1393 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, MacData);
1395 //Clean ATE Bulk in/out counter and continue setup
1396 InterlockedExchange(&pAd->BulkOutRemained, 0);
1398 pAd->ContinBulkOut = FALSE;
1400 else if (!strcmp(arg, "RXSTOP"))
1402 ATEDBGPRINT(RT_DEBUG_TRACE, ("ATE: RXSTOP\n"));
1403 atemode = pAd->ate.Mode;
1406 RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &Value);
1408 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, Value);
1410 pAd->ate.Mode &= ATE_RXSTOP;
1411 pAd->ate.bQARxStart = FALSE;
1412 // pAd->ate.TxDoneCount = pAd->ate.TxCount;
1414 /*=========================================================================*/
1415 RTUSBRejectPendingPackets(pAd);
1416 RTUSBCleanUpDataBulkOutQueue(pAd);
1418 /* not used in RT28xx */
1419 //RTUSBCleanUpMLMEWaitQueue(pAd);
1420 RTUSBCleanUpMLMEBulkOutQueue(pAd);
1421 /*=========================================================================*/
1423 // Abort Tx, RX DMA.
1424 RtmpDmaEnable(pAd, 0);
1425 /*=========================================================================*/
1426 // while ((atomic_read(&pAd->PendingRx) > 0))
1427 while (pAd->PendingRx > 0)
1430 ATE_RTUSBCancelPendingBulkInIRP(pAd);
1432 // NdisInterlockedDecrement(&pAd->PendingRx);
1435 RTMPusecDelay(500000);
1438 while (((pAd->BulkOutPending[0] == TRUE) ||
1439 (pAd->BulkOutPending[1] == TRUE) ||
1440 (pAd->BulkOutPending[2] == TRUE) ||
1441 (pAd->BulkOutPending[3] == TRUE)) && (pAd->BulkFlags != 0)) //pAd->BulkFlags != 0 wait bulk out finish
1445 RTUSBCancelPendingBulkOutIRP(pAd);
1448 RTMPusecDelay(500000);
1451 ASSERT(pAd->PendingRx == 0);
1452 /*=========================================================================*/
1456 pAd->ContinBulkIn = FALSE;
1458 #endif // RALINK_28xx_QA //
1459 else if (!strcmp(arg, "RXFRAME")) // Rx Frames
1461 ATEDBGPRINT(RT_DEBUG_TRACE, ("ATE: RXFRAME\n"));
1463 // Disable Rx of MAC block
1464 RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &Value);
1466 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, Value);
1468 // Default value in BBP R22 is 0x0.
1471 RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &MacData);
1472 // Clean bit4 to stop continuous Tx production test.
1473 MacData &= 0xFFFFFFEF;
1475 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R22, BbpData);
1476 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, MacData);
1478 pAd->ate.Mode |= ATE_RXFRAME;
1480 // Abort Tx, RX DMA.
1481 RtmpDmaEnable(pAd, 0);
1483 // Disable TX of MAC block
1484 RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &Value);
1486 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, Value);
1489 for ( i = 0; i < (RX_RING_SIZE); i++)
1491 PRX_CONTEXT pRxContext = &(pAd->RxContext[i]);
1493 pRxContext->InUse = FALSE;
1494 pRxContext->IRPPending = FALSE;
1495 pRxContext->Readable = FALSE;
1498 // Get the urb from kernel back to driver.
1500 RTUSB_UNLINK_URB(pRxContext->pUrb);
1502 /* Sleep 200 microsecs to give cancellation time to work. */
1506 // InterlockedExchange(&pAd->PendingRx, 0);
1508 pAd->NextRxBulkInReadIndex = 0; // Next Rx Read index
1509 pAd->NextRxBulkInIndex = RX_RING_SIZE - 1; // Rx Bulk pointer
1510 pAd->NextRxBulkInPosition = 0;
1513 // read to clear counters
1514 RTUSBReadMACRegister(pAd, RX_STA_CNT0, &temp); //RX PHY & RX CRC count
1515 RTUSBReadMACRegister(pAd, RX_STA_CNT1, &temp); //RX PLCP error count & CCA false alarm count
1516 RTUSBReadMACRegister(pAd, RX_STA_CNT2, &temp); //RX FIFO overflow frame count & RX duplicated filtered frame count
1518 pAd->ContinBulkIn = TRUE;
1520 // Enable Tx, RX DMA.
1521 RtmpDmaEnable(pAd, 1);
1523 // Enable RX of MAC block
1524 RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &Value);
1526 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, Value);
1529 RTUSBBulkReceive(pAd);
1533 ATEDBGPRINT(RT_DEBUG_TRACE, ("ATE: Invalid arg!\n"));
1536 RTMPusecDelay(5000);
1538 ATEDBGPRINT(RT_DEBUG_TRACE, ("<=== ATECmdHandler()\n"));
1545 IN PRTMP_ADAPTER pAd,
1548 if (ATECmdHandler(pAd, arg))
1550 ATEDBGPRINT(RT_DEBUG_TRACE, ("Ralink: Set_ATE_Proc Success\n"));
1557 ATEDBGPRINT(RT_DEBUG_TRACE, ("Ralink: Set_ATE_Proc Failed\n"));
1563 ==========================================================================
1565 Set ATE ADDR1=DA for TxFrame(AP : To DS = 0 ; From DS = 1)
1567 Set ATE ADDR3=DA for TxFrame(STA : To DS = 1 ; From DS = 0)
1570 TRUE if all parameters are OK, FALSE otherwise
1571 ==========================================================================
1573 INT Set_ATE_DA_Proc(
1574 IN PRTMP_ADAPTER pAd,
1580 if(strlen(arg) != 17) //Mac address acceptable format 01:02:03:04:05:06 length 17
1583 for (i=0, value = rstrtok(arg, ":"); value; value = rstrtok(NULL, ":"))
1585 if((strlen(value) != 2) || (!isxdigit(*value)) || (!isxdigit(*(value+1))) )
1586 return FALSE; //Invalid
1589 #ifdef CONFIG_STA_SUPPORT
1590 AtoH(value, &pAd->ate.Addr3[i++], 1);
1591 #endif // CONFIG_STA_SUPPORT //
1595 return FALSE; //Invalid
1598 #ifdef CONFIG_STA_SUPPORT
1599 ATEDBGPRINT(RT_DEBUG_TRACE, ("Set_ATE_DA_Proc (DA = %2X:%2X:%2X:%2X:%2X:%2X)\n", pAd->ate.Addr3[0],
1600 pAd->ate.Addr3[1], pAd->ate.Addr3[2], pAd->ate.Addr3[3], pAd->ate.Addr3[4], pAd->ate.Addr3[5]));
1601 #endif // CONFIG_STA_SUPPORT //
1603 ATEDBGPRINT(RT_DEBUG_TRACE, ("Ralink: Set_ATE_DA_Proc Success\n"));
1609 ==========================================================================
1611 Set ATE ADDR3=SA for TxFrame(AP : To DS = 0 ; From DS = 1)
1613 Set ATE ADDR2=SA for TxFrame(STA : To DS = 1 ; From DS = 0)
1616 TRUE if all parameters are OK, FALSE otherwise
1617 ==========================================================================
1619 INT Set_ATE_SA_Proc(
1620 IN PRTMP_ADAPTER pAd,
1626 if(strlen(arg) != 17) //Mac address acceptable format 01:02:03:04:05:06 length 17
1629 for (i=0, value = rstrtok(arg, ":"); value; value = rstrtok(NULL, ":"))
1631 if((strlen(value) != 2) || (!isxdigit(*value)) || (!isxdigit(*(value+1))) )
1632 return FALSE; //Invalid
1635 #ifdef CONFIG_STA_SUPPORT
1636 AtoH(value, &pAd->ate.Addr2[i++], 1);
1637 #endif // CONFIG_STA_SUPPORT //
1641 return FALSE; //Invalid
1644 #ifdef CONFIG_STA_SUPPORT
1645 ATEDBGPRINT(RT_DEBUG_TRACE, ("Set_ATE_SA_Proc (SA = %2X:%2X:%2X:%2X:%2X:%2X)\n", pAd->ate.Addr2[0],
1646 pAd->ate.Addr2[1], pAd->ate.Addr2[2], pAd->ate.Addr2[3], pAd->ate.Addr2[4], pAd->ate.Addr2[5]));
1647 #endif // CONFIG_STA_SUPPORT //
1649 ATEDBGPRINT(RT_DEBUG_TRACE, ("Ralink: Set_ATE_SA_Proc Success\n"));
1655 ==========================================================================
1657 Set ATE ADDR2=BSSID for TxFrame(AP : To DS = 0 ; From DS = 1)
1659 Set ATE ADDR1=BSSID for TxFrame(STA : To DS = 1 ; From DS = 0)
1662 TRUE if all parameters are OK, FALSE otherwise
1663 ==========================================================================
1665 INT Set_ATE_BSSID_Proc(
1666 IN PRTMP_ADAPTER pAd,
1672 if(strlen(arg) != 17) //Mac address acceptable format 01:02:03:04:05:06 length 17
1675 for (i=0, value = rstrtok(arg, ":"); value; value = rstrtok(NULL, ":"))
1677 if((strlen(value) != 2) || (!isxdigit(*value)) || (!isxdigit(*(value+1))) )
1678 return FALSE; //Invalid
1681 #ifdef CONFIG_STA_SUPPORT
1682 AtoH(value, &pAd->ate.Addr1[i++], 1);
1683 #endif // CONFIG_STA_SUPPORT //
1687 return FALSE; //Invalid
1690 #ifdef CONFIG_STA_SUPPORT
1691 ATEDBGPRINT(RT_DEBUG_TRACE, ("Set_ATE_BSSID_Proc (BSSID = %2X:%2X:%2X:%2X:%2X:%2X)\n", pAd->ate.Addr1[0],
1692 pAd->ate.Addr1[1], pAd->ate.Addr1[2], pAd->ate.Addr1[3], pAd->ate.Addr1[4], pAd->ate.Addr1[5]));
1693 #endif // CONFIG_STA_SUPPORT //
1695 ATEDBGPRINT(RT_DEBUG_TRACE, ("Ralink: Set_ATE_BSSID_Proc Success\n"));
1701 ==========================================================================
1706 TRUE if all parameters are OK, FALSE otherwise
1707 ==========================================================================
1709 INT Set_ATE_CHANNEL_Proc(
1710 IN PRTMP_ADAPTER pAd,
1715 channel = simple_strtol(arg, 0, 10);
1717 if ((channel < 1) || (channel > 216))// to allow A band channel : ((channel < 1) || (channel > 14))
1719 ATEDBGPRINT(RT_DEBUG_ERROR, ("Set_ATE_CHANNEL_Proc::Out of range, it should be in range of 1~14.\n"));
1722 pAd->ate.Channel = channel;
1724 ATEDBGPRINT(RT_DEBUG_TRACE, ("Set_ATE_CHANNEL_Proc (ATE Channel = %d)\n", pAd->ate.Channel));
1725 ATEDBGPRINT(RT_DEBUG_TRACE, ("Ralink: Set_ATE_CHANNEL_Proc Success\n"));
1732 ==========================================================================
1737 TRUE if all parameters are OK, FALSE otherwise
1738 ==========================================================================
1740 INT Set_ATE_TX_POWER0_Proc(
1741 IN PRTMP_ADAPTER pAd,
1746 TxPower = simple_strtol(arg, 0, 10);
1748 if (pAd->ate.Channel <= 14)
1750 if ((TxPower > 31) || (TxPower < 0))
1752 ATEDBGPRINT(RT_DEBUG_ERROR, ("Set_ATE_TX_POWER0_Proc::Out of range (Value=%d)\n", TxPower));
1758 if ((TxPower > 15) || (TxPower < -7))
1760 ATEDBGPRINT(RT_DEBUG_ERROR, ("Set_ATE_TX_POWER0_Proc::Out of range (Value=%d)\n", TxPower));
1765 pAd->ate.TxPower0 = TxPower;
1766 ATETxPwrHandler(pAd, 0);
1767 ATEDBGPRINT(RT_DEBUG_TRACE, ("Ralink: Set_ATE_TX_POWER0_Proc Success\n"));
1774 ==========================================================================
1779 TRUE if all parameters are OK, FALSE otherwise
1780 ==========================================================================
1782 INT Set_ATE_TX_POWER1_Proc(
1783 IN PRTMP_ADAPTER pAd,
1788 TxPower = simple_strtol(arg, 0, 10);
1790 if (pAd->ate.Channel <= 14)
1792 if ((TxPower > 31) || (TxPower < 0))
1794 ATEDBGPRINT(RT_DEBUG_ERROR, ("Set_ATE_TX_POWER1_Proc::Out of range (Value=%d)\n", TxPower));
1800 if ((TxPower > 15) || (TxPower < -7))
1802 ATEDBGPRINT(RT_DEBUG_ERROR, ("Set_ATE_TX_POWER1_Proc::Out of range (Value=%d)\n", TxPower));
1807 pAd->ate.TxPower1 = TxPower;
1808 ATETxPwrHandler(pAd, 1);
1809 ATEDBGPRINT(RT_DEBUG_TRACE, ("Ralink: Set_ATE_TX_POWER1_Proc Success\n"));
1816 ==========================================================================
1821 TRUE if all parameters are OK, FALSE otherwise
1822 ==========================================================================
1824 INT Set_ATE_TX_Antenna_Proc(
1825 IN PRTMP_ADAPTER pAd,
1830 value = simple_strtol(arg, 0, 10);
1832 if ((value > 2) || (value < 0))
1834 ATEDBGPRINT(RT_DEBUG_ERROR, ("Set_ATE_TX_Antenna_Proc::Out of range (Value=%d)\n", value));
1838 pAd->ate.TxAntennaSel = value;
1840 ATEDBGPRINT(RT_DEBUG_TRACE, ("Set_ATE_TX_Antenna_Proc (Antenna = %d)\n", pAd->ate.TxAntennaSel));
1841 ATEDBGPRINT(RT_DEBUG_TRACE,("Ralink: Set_ATE_TX_Antenna_Proc Success\n"));
1848 ==========================================================================
1853 TRUE if all parameters are OK, FALSE otherwise
1854 ==========================================================================
1856 INT Set_ATE_RX_Antenna_Proc(
1857 IN PRTMP_ADAPTER pAd,
1862 value = simple_strtol(arg, 0, 10);
1864 if ((value > 3) || (value < 0))
1866 ATEDBGPRINT(RT_DEBUG_ERROR, ("Set_ATE_RX_Antenna_Proc::Out of range (Value=%d)\n", value));
1870 pAd->ate.RxAntennaSel = value;
1872 ATEDBGPRINT(RT_DEBUG_TRACE, ("Set_ATE_RX_Antenna_Proc (Antenna = %d)\n", pAd->ate.RxAntennaSel));
1873 ATEDBGPRINT(RT_DEBUG_TRACE, ("Ralink: Set_ATE_RX_Antenna_Proc Success\n"));
1880 ==========================================================================
1882 Set ATE RF frequence offset
1885 TRUE if all parameters are OK, FALSE otherwise
1886 ==========================================================================
1888 INT Set_ATE_TX_FREQOFFSET_Proc(
1889 IN PRTMP_ADAPTER pAd,
1895 RFFreqOffset = simple_strtol(arg, 0, 10);
1897 if(RFFreqOffset >= 64)
1900 //2008/08/06: KH modified the limit of offset value from 65 to 95(0x5F)
1901 if(RFFreqOffset >= 95)
1904 ATEDBGPRINT(RT_DEBUG_ERROR, ("Set_ATE_TX_FREQOFFSET_Proc::Out of range, it should be in range of 0~63.\n"));
1908 pAd->ate.RFFreqOffset = RFFreqOffset;
1914 RT30xxReadRFRegister(pAd, RF_R23, (PUCHAR)&RFValue);
1915 //2008/08/06: KH modified "pAd->RFFreqOffset" to "pAd->ate.RFFreqOffset"
1916 RFValue = (RFValue & 0x80) | pAd->ate.RFFreqOffset;
1917 RT30xxWriteRFRegister(pAd, RF_R23, (UCHAR)RFValue);
1923 R4 = pAd->ate.RFFreqOffset << 15; // shift TX power control to correct RF register bit position
1924 R4 |= (pAd->LatchRfRegs.R4 & ((~0x001f8000)));
1925 pAd->LatchRfRegs.R4 = R4;
1929 ATEDBGPRINT(RT_DEBUG_TRACE, ("Set_ATE_TX_FREQOFFSET_Proc (RFFreqOffset = %d)\n", pAd->ate.RFFreqOffset));
1930 ATEDBGPRINT(RT_DEBUG_TRACE, ("Ralink: Set_ATE_TX_FREQOFFSET_Proc Success\n"));
1937 ==========================================================================
1942 TRUE if all parameters are OK, FALSE otherwise
1943 ==========================================================================
1945 INT Set_ATE_TX_BW_Proc(
1946 IN PRTMP_ADAPTER pAd,
1953 BBPCurrentBW = simple_strtol(arg, 0, 10);
1955 if(BBPCurrentBW == 0)
1956 pAd->ate.TxWI.BW = BW_20;
1958 pAd->ate.TxWI.BW = BW_40;
1960 if(pAd->ate.TxWI.BW == BW_20)
1962 if(pAd->ate.Channel <= 14)
1966 if (pAd->Tx20MPwrCfgGBand[i] != 0xffffffff)
1968 RTMP_IO_WRITE32(pAd, TX_PWR_CFG_0 + i*4, pAd->Tx20MPwrCfgGBand[i]);
1969 RTMPusecDelay(5000);
1977 if (pAd->Tx20MPwrCfgABand[i] != 0xffffffff)
1979 RTMP_IO_WRITE32(pAd, TX_PWR_CFG_0 + i*4, pAd->Tx20MPwrCfgABand[i]);
1980 RTMPusecDelay(5000);
1985 //Set BBP R4 bit[4:3]=0:0
1986 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &value);
1988 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, value);
1992 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R66, value);
1994 //to improve Rx sensitivity.
1996 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R68, value);
1999 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R69, value);
2002 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R70, value);
2005 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R73, value);
2007 // If Channel=14, Bandwidth=20M and Mode=CCK, Set BBP R4 bit5=1
2008 // (Japan filter coefficients)
2009 // This segment of code will only works when ATETXMODE and ATECHANNEL
2010 // were set to MODE_CCK and 14 respectively before ATETXBW is set to 0.
2011 //=====================================================================
2012 if (pAd->ate.Channel == 14)
2014 int TxMode = pAd->ate.TxWI.PHYMODE;
2015 if (TxMode == MODE_CCK)
2017 // when Channel==14 && Mode==CCK && BandWidth==20M, BBP R4 bit5=1
2018 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &value);
2019 value |= 0x20; //set bit5=1
2020 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, value);
2024 //=====================================================================
2025 // If bandwidth != 40M, RF Reg4 bit 21 = 0.
2029 RT30xxWriteRFRegister(pAd, RF_R24, (UCHAR) pAd->Mlme.CaliBW20RfR24);
2033 pAd->LatchRfRegs.R4 &= ~0x00200000;
2038 else if(pAd->ate.TxWI.BW == BW_40)
2040 if(pAd->ate.Channel <= 14)
2044 if (pAd->Tx40MPwrCfgGBand[i] != 0xffffffff)
2046 RTMP_IO_WRITE32(pAd, TX_PWR_CFG_0 + i*4, pAd->Tx40MPwrCfgGBand[i]);
2047 RTMPusecDelay(5000);
2055 if (pAd->Tx40MPwrCfgABand[i] != 0xffffffff)
2057 RTMP_IO_WRITE32(pAd, TX_PWR_CFG_0 + i*4, pAd->Tx40MPwrCfgABand[i]);
2058 RTMPusecDelay(5000);
2061 #ifdef DOT11_N_SUPPORT
2062 if ((pAd->ate.TxWI.PHYMODE >= MODE_HTMIX) && (pAd->ate.TxWI.MCS == 7))
2065 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R67, value);
2067 #endif // DOT11_N_SUPPORT //
2070 //Set BBP R4 bit[4:3]=1:0
2071 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &value);
2074 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, value);
2078 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R66, value);
2080 //to improve Rx sensitivity.
2082 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R68, value);
2085 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R69, value);
2088 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R70, value);
2091 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R73, value);
2093 // If bandwidth = 40M, set RF Reg4 bit 21 = 1.
2097 RT30xxWriteRFRegister(pAd, RF_R24, (UCHAR) pAd->Mlme.CaliBW40RfR24);
2101 pAd->LatchRfRegs.R4 |= 0x00200000;
2106 ATEDBGPRINT(RT_DEBUG_TRACE, ("Set_ATE_TX_BW_Proc (BBPCurrentBW = %d)\n", pAd->ate.TxWI.BW));
2107 ATEDBGPRINT(RT_DEBUG_TRACE, ("Ralink: Set_ATE_TX_BW_Proc Success\n"));
2114 ==========================================================================
2116 Set ATE Tx frame length
2119 TRUE if all parameters are OK, FALSE otherwise
2120 ==========================================================================
2122 INT Set_ATE_TX_LENGTH_Proc(
2123 IN PRTMP_ADAPTER pAd,
2126 pAd->ate.TxLength = simple_strtol(arg, 0, 10);
2128 if((pAd->ate.TxLength < 24) || (pAd->ate.TxLength > (MAX_FRAME_SIZE - 34/* == 2312 */)))
2130 pAd->ate.TxLength = (MAX_FRAME_SIZE - 34/* == 2312 */);
2131 ATEDBGPRINT(RT_DEBUG_ERROR, ("Set_ATE_TX_LENGTH_Proc::Out of range, it should be in range of 24~%d.\n", (MAX_FRAME_SIZE - 34/* == 2312 */)));
2135 ATEDBGPRINT(RT_DEBUG_TRACE, ("Set_ATE_TX_LENGTH_Proc (TxLength = %d)\n", pAd->ate.TxLength));
2136 ATEDBGPRINT(RT_DEBUG_TRACE, ("Ralink: Set_ATE_TX_LENGTH_Proc Success\n"));
2143 ==========================================================================
2145 Set ATE Tx frame count
2148 TRUE if all parameters are OK, FALSE otherwise
2149 ==========================================================================
2151 INT Set_ATE_TX_COUNT_Proc(
2152 IN PRTMP_ADAPTER pAd,
2155 pAd->ate.TxCount = simple_strtol(arg, 0, 10);
2157 ATEDBGPRINT(RT_DEBUG_TRACE, ("Set_ATE_TX_COUNT_Proc (TxCount = %d)\n", pAd->ate.TxCount));
2158 ATEDBGPRINT(RT_DEBUG_TRACE, ("Ralink: Set_ATE_TX_COUNT_Proc Success\n"));
2165 ==========================================================================
2167 Set ATE Tx frame MCS
2170 TRUE if all parameters are OK, FALSE otherwise
2171 ==========================================================================
2173 INT Set_ATE_TX_MCS_Proc(
2174 IN PRTMP_ADAPTER pAd,
2180 MCS = simple_strtol(arg, 0, 10);
2181 result = CheckMCSValid(pAd->ate.TxWI.PHYMODE, MCS);
2185 pAd->ate.TxWI.MCS = (UCHAR)MCS;
2189 ATEDBGPRINT(RT_DEBUG_ERROR, ("Set_ATE_TX_MCS_Proc::Out of range, refer to rate table.\n"));
2193 ATEDBGPRINT(RT_DEBUG_TRACE, ("Set_ATE_TX_MCS_Proc (MCS = %d)\n", pAd->ate.TxWI.MCS));
2194 ATEDBGPRINT(RT_DEBUG_TRACE, ("Ralink: Set_ATE_TX_MCS_Proc Success\n"));
2201 ==========================================================================
2203 Set ATE Tx frame Mode
2207 3: MODE_HTGREENFIELD
2210 TRUE if all parameters are OK, FALSE otherwise
2211 ==========================================================================
2213 INT Set_ATE_TX_MODE_Proc(
2214 IN PRTMP_ADAPTER pAd,
2217 pAd->ate.TxWI.PHYMODE = simple_strtol(arg, 0, 10);
2219 if(pAd->ate.TxWI.PHYMODE > 3)
2221 pAd->ate.TxWI.PHYMODE = 0;
2222 ATEDBGPRINT(RT_DEBUG_ERROR, ("Set_ATE_TX_MODE_Proc::Out of range. it should be in range of 0~3\n"));
2223 ATEDBGPRINT(RT_DEBUG_ERROR, ("0: CCK, 1: OFDM, 2: HT_MIX, 3: HT_GREEN_FIELD.\n"));
2227 ATEDBGPRINT(RT_DEBUG_TRACE, ("Set_ATE_TX_MODE_Proc (TxMode = %d)\n", pAd->ate.TxWI.PHYMODE));
2228 ATEDBGPRINT(RT_DEBUG_TRACE, ("Ralink: Set_ATE_TX_MODE_Proc Success\n"));
2235 ==========================================================================
2240 TRUE if all parameters are OK, FALSE otherwise
2241 ==========================================================================
2243 INT Set_ATE_TX_GI_Proc(
2244 IN PRTMP_ADAPTER pAd,
2247 pAd->ate.TxWI.ShortGI = simple_strtol(arg, 0, 10);
2249 if(pAd->ate.TxWI.ShortGI > 1)
2251 pAd->ate.TxWI.ShortGI = 0;
2252 ATEDBGPRINT(RT_DEBUG_ERROR, ("Set_ATE_TX_GI_Proc::Out of range\n"));
2256 ATEDBGPRINT(RT_DEBUG_TRACE, ("Set_ATE_TX_GI_Proc (GI = %d)\n", pAd->ate.TxWI.ShortGI));
2257 ATEDBGPRINT(RT_DEBUG_TRACE, ("Ralink: Set_ATE_TX_GI_Proc Success\n"));
2264 ==========================================================================
2266 ==========================================================================
2268 INT Set_ATE_RX_FER_Proc(
2269 IN PRTMP_ADAPTER pAd,
2272 pAd->ate.bRxFer = simple_strtol(arg, 0, 10);
2274 if (pAd->ate.bRxFer == 1)
2276 pAd->ate.RxCntPerSec = 0;
2277 pAd->ate.RxTotalCnt = 0;
2280 ATEDBGPRINT(RT_DEBUG_TRACE, ("Set_ATE_RX_FER_Proc (bRxFer = %d)\n", pAd->ate.bRxFer));
2281 ATEDBGPRINT(RT_DEBUG_TRACE, ("Ralink: Set_ATE_RX_FER_Proc Success\n"));
2287 INT Set_ATE_Read_RF_Proc(
2288 IN PRTMP_ADAPTER pAd,
2292 //2008/07/10:KH add to support RT30xx ATE<--
2295 /* modify by WY for Read RF Reg. error */
2298 for (index = 0; index < 32; index++)
2300 RT30xxReadRFRegister(pAd, index, (PUCHAR)&RFValue);
2301 printk("R%d=%d\n",index,RFValue);
2305 //2008/07/10:KH add to support RT30xx ATE-->
2308 ate_print(KERN_EMERG "R1 = %lx\n", pAd->LatchRfRegs.R1);
2309 ate_print(KERN_EMERG "R2 = %lx\n", pAd->LatchRfRegs.R2);
2310 ate_print(KERN_EMERG "R3 = %lx\n", pAd->LatchRfRegs.R3);
2311 ate_print(KERN_EMERG "R4 = %lx\n", pAd->LatchRfRegs.R4);
2316 INT Set_ATE_Write_RF1_Proc(
2317 IN PRTMP_ADAPTER pAd,
2321 //2008/07/10:KH add to support 3070 ATE<--
2324 printk("Warning!! RT30xx Don't Support\n");
2329 //2008/07/10:KH add to support 3070 ATE-->
2332 UINT32 value = simple_strtol(arg, 0, 16);
2334 pAd->LatchRfRegs.R1 = value;
2341 INT Set_ATE_Write_RF2_Proc(
2342 IN PRTMP_ADAPTER pAd,
2346 //2008/07/10:KH add to support 3070 ATE<--
2349 printk("Warning!! RT30xx Don't Support\n");
2354 //2008/07/10:KH add to support 3070 ATE-->
2357 UINT32 value = simple_strtol(arg, 0, 16);
2359 pAd->LatchRfRegs.R2 = value;
2365 INT Set_ATE_Write_RF3_Proc(
2366 IN PRTMP_ADAPTER pAd,
2370 //2008/07/10:KH add to support 3070 ATE<--
2373 printk("Warning!! RT30xx Don't Support\n");
2378 //2008/07/10:KH add to support 3070 ATE-->
2381 UINT32 value = simple_strtol(arg, 0, 16);
2383 pAd->LatchRfRegs.R3 = value;
2389 INT Set_ATE_Write_RF4_Proc(
2390 IN PRTMP_ADAPTER pAd,
2394 //2008/07/10:KH add to support 3070 ATE<--
2397 printk("Warning!! RT30xx Don't Support\n");
2402 //2008/07/10:KH add to support 3070 ATE-->
2405 UINT32 value = simple_strtol(arg, 0, 16);
2407 pAd->LatchRfRegs.R4 = value;
2413 //2008/07/10:KH add to support 3070 ATE<--
2414 INT SET_ATE_3070RF_Proc(
2415 IN PRTMP_ADAPTER pAd,
2423 printk("SET_ATE_3070RF_Proc=%s\n",arg);
2425 if ((value = strchr(this_char, ':')) != NULL)
2427 Reg= simple_strtol(this_char, 0, 16);
2428 RFValue= simple_strtol(value, 0, 16);
2429 printk("RF Reg[%d]=%d\n",Reg,RFValue);
2430 RT30xxWriteRFRegister(pAd, Reg,RFValue);
2433 printk("Warning!! Only 3070 Support\n");
2436 //2008/07/10:KH add to support 3070 ATE-->
2439 ==========================================================================
2441 Load and Write EEPROM from a binary file prepared in advance.
2444 TRUE if all parameters are OK, FALSE otherwise
2445 ==========================================================================
2448 INT Set_ATE_Load_E2P_Proc(
2449 IN PRTMP_ADAPTER pAd,
2452 BOOLEAN ret = FALSE;
2453 PUCHAR src = EEPROM_BIN_FILE_NAME;
2455 INT32 retval, orgfsuid, orgfsgid;
2457 USHORT WriteEEPROM[(EEPROM_SIZE/2)];
2458 UINT32 FileLength = 0;
2459 UINT32 value = simple_strtol(arg, 0, 10);
2461 ATEDBGPRINT(RT_DEBUG_ERROR, ("===> %s (value=%d)\n\n", __FUNCTION__, value));
2465 /* zero the e2p buffer */
2466 NdisZeroMemory((PUCHAR)WriteEEPROM, EEPROM_SIZE);
2468 /* save uid and gid used for filesystem access.
2469 ** set user and group to 0 (root)
2471 orgfsuid = current->fsuid;
2472 orgfsgid = current->fsgid;
2474 current->fsuid = current->fsgid = 0;
2480 /* open the bin file */
2481 srcf = filp_open(src, O_RDONLY, 0);
2485 ate_print("%s - Error %ld opening %s\n", __FUNCTION__, -PTR_ERR(srcf), src);
2489 /* the object must have a read method */
2490 if ((srcf->f_op == NULL) || (srcf->f_op->read == NULL))
2492 ate_print("%s - %s does not have a read method\n", __FUNCTION__, src);
2496 /* read the firmware from the file *.bin */
2497 FileLength = srcf->f_op->read(srcf,
2498 (PUCHAR)WriteEEPROM,
2502 if (FileLength != EEPROM_SIZE)
2504 ate_print("%s: error file length (=%d) in e2p.bin\n",
2505 __FUNCTION__, FileLength);
2510 /* write the content of .bin file to EEPROM */
2511 rt_ee_write_all(pAd, WriteEEPROM);
2517 /* close firmware file */
2524 retval = filp_close(srcf, NULL);
2527 ATEDBGPRINT(RT_DEBUG_ERROR, ("--> Error %d closing %s\n", -retval, src));
2534 current->fsuid = orgfsuid;
2535 current->fsgid = orgfsgid;
2537 ATEDBGPRINT(RT_DEBUG_ERROR, ("<=== %s (ret=%d)\n", __FUNCTION__, ret));
2543 INT Set_ATE_Load_E2P_Proc(
2544 IN PRTMP_ADAPTER pAd,
2547 USHORT WriteEEPROM[(EEPROM_SIZE/2)];
2548 struct iwreq *wrq = (struct iwreq *)arg;
2550 ATEDBGPRINT(RT_DEBUG_TRACE, ("===> %s (wrq->u.data.length = %d)\n\n", __FUNCTION__, wrq->u.data.length));
2552 if (wrq->u.data.length != EEPROM_SIZE)
2554 ate_print("%s: error length (=%d) from host\n",
2555 __FUNCTION__, wrq->u.data.length);
2558 else/* (wrq->u.data.length == EEPROM_SIZE) */
2560 /* zero the e2p buffer */
2561 NdisZeroMemory((PUCHAR)WriteEEPROM, EEPROM_SIZE);
2563 /* fill the local buffer */
2564 NdisMoveMemory((PUCHAR)WriteEEPROM, wrq->u.data.pointer, wrq->u.data.length);
2568 /* write the content of .bin file to EEPROM */
2569 rt_ee_write_all(pAd, WriteEEPROM);
2574 ATEDBGPRINT(RT_DEBUG_TRACE, ("<=== %s\n", __FUNCTION__));
2581 INT Set_ATE_Read_E2P_Proc(
2582 IN PRTMP_ADAPTER pAd,
2585 USHORT buffer[EEPROM_SIZE/2];
2589 rt_ee_read_all(pAd, (USHORT *)buffer);
2591 for (i = 0; i < (EEPROM_SIZE/2); i++)
2593 ate_print("%4.4x ", *p);
2594 if (((i+1) % 16) == 0)
2601 INT Set_ATE_Show_Proc(
2602 IN PRTMP_ADAPTER pAd,
2605 ate_print("Mode=%d\n", pAd->ate.Mode);
2606 ate_print("TxPower0=%d\n", pAd->ate.TxPower0);
2607 ate_print("TxPower1=%d\n", pAd->ate.TxPower1);
2608 ate_print("TxAntennaSel=%d\n", pAd->ate.TxAntennaSel);
2609 ate_print("RxAntennaSel=%d\n", pAd->ate.RxAntennaSel);
2610 ate_print("BBPCurrentBW=%d\n", pAd->ate.TxWI.BW);
2611 ate_print("GI=%d\n", pAd->ate.TxWI.ShortGI);
2612 ate_print("MCS=%d\n", pAd->ate.TxWI.MCS);
2613 ate_print("TxMode=%d\n", pAd->ate.TxWI.PHYMODE);
2614 ate_print("Addr1=%02x:%02x:%02x:%02x:%02x:%02x\n",
2615 pAd->ate.Addr1[0], pAd->ate.Addr1[1], pAd->ate.Addr1[2], pAd->ate.Addr1[3], pAd->ate.Addr1[4], pAd->ate.Addr1[5]);
2616 ate_print("Addr2=%02x:%02x:%02x:%02x:%02x:%02x\n",
2617 pAd->ate.Addr2[0], pAd->ate.Addr2[1], pAd->ate.Addr2[2], pAd->ate.Addr2[3], pAd->ate.Addr2[4], pAd->ate.Addr2[5]);
2618 ate_print("Addr3=%02x:%02x:%02x:%02x:%02x:%02x\n",
2619 pAd->ate.Addr3[0], pAd->ate.Addr3[1], pAd->ate.Addr3[2], pAd->ate.Addr3[3], pAd->ate.Addr3[4], pAd->ate.Addr3[5]);
2620 ate_print("Channel=%d\n", pAd->ate.Channel);
2621 ate_print("TxLength=%d\n", pAd->ate.TxLength);
2622 ate_print("TxCount=%u\n", pAd->ate.TxCount);
2623 ate_print("RFFreqOffset=%d\n", pAd->ate.RFFreqOffset);
2624 ate_print(KERN_EMERG "Set_ATE_Show_Proc Success\n");
2628 INT Set_ATE_Help_Proc(
2629 IN PRTMP_ADAPTER pAd,
2632 ate_print("ATE=ATESTART, ATESTOP, TXCONT, TXCARR, TXFRAME, RXFRAME\n");
2633 ate_print("ATEDA\n");
2634 ate_print("ATESA\n");
2635 ate_print("ATEBSSID\n");
2636 ate_print("ATECHANNEL, range:0~14(unless A band !)\n");
2637 ate_print("ATETXPOW0, set power level of antenna 1.\n");
2638 ate_print("ATETXPOW1, set power level of antenna 2.\n");
2639 ate_print("ATETXANT, set TX antenna. 0:all, 1:antenna one, 2:antenna two.\n");
2640 ate_print("ATERXANT, set RX antenna.0:all, 1:antenna one, 2:antenna two, 3:antenna three.\n");
2641 ate_print("ATETXFREQOFFSET, set frequency offset, range 0~63\n");
2642 ate_print("ATETXBW, set BandWidth, 0:20MHz, 1:40MHz.\n");
2643 ate_print("ATETXLEN, set Frame length, range 24~%d\n", (MAX_FRAME_SIZE - 34/* == 2312 */));
2644 ate_print("ATETXCNT, set how many frame going to transmit.\n");
2645 ate_print("ATETXMCS, set MCS, reference to rate table.\n");
2646 ate_print("ATETXMODE, set Mode 0:CCK, 1:OFDM, 2:HT-Mix, 3:GreenField, reference to rate table.\n");
2647 ate_print("ATETXGI, set GI interval, 0:Long, 1:Short\n");
2648 ate_print("ATERXFER, 0:disable Rx Frame error rate. 1:enable Rx Frame error rate.\n");
2649 ate_print("ATERRF, show all RF registers.\n");
2650 ate_print("ATEWRF1, set RF1 register.\n");
2651 ate_print("ATEWRF2, set RF2 register.\n");
2652 ate_print("ATEWRF3, set RF3 register.\n");
2653 ate_print("ATEWRF4, set RF4 register.\n");
2654 ate_print("ATELDE2P, load EEPROM from .bin file.\n");
2655 ate_print("ATERE2P, display all EEPROM content.\n");
2656 ate_print("ATESHOW, display all parameters of ATE.\n");
2657 ate_print("ATEHELP, online help.\n");
2663 ==========================================================================
2666 AsicSwitchChannel() dedicated for ATE.
2668 ==========================================================================
2670 VOID ATEAsicSwitchChannel(
2671 IN PRTMP_ADAPTER pAd)
2673 UINT32 R2 = 0, R3 = DEFAULT_RF_TX_POWER, R4 = 0, Value = 0;
2674 CHAR TxPwer = 0, TxPwer2 = 0;
2675 UCHAR index, BbpValue = 0, R66 = 0x30;
2676 RTMP_RF_REGS *RFRegTable;
2679 #ifdef RALINK_28xx_QA
2680 if ((pAd->ate.bQATxStart == TRUE) || (pAd->ate.bQARxStart == TRUE))
2682 if (pAd->ate.Channel != pAd->LatchRfRegs.Channel)
2684 pAd->ate.Channel = pAd->LatchRfRegs.Channel;
2689 #endif // RALINK_28xx_QA //
2690 Channel = pAd->ate.Channel;
2693 AsicAntennaSelect(pAd, Channel);
2695 // fill Tx power value
2696 TxPwer = pAd->ate.TxPower0;
2697 TxPwer2 = pAd->ate.TxPower1;
2699 //2008/07/10:KH add to support 3070 ATE<--
2701 // The RF programming sequence is difference between 3xxx and 2xxx
2702 // The 3070 is 1T1R. Therefore, we don't need to set the number of Tx/Rx path and the only job is to set the parameters of channels.
2703 if (IS_RT30xx(pAd) && ((pAd->RfIcType == RFIC_3020) ||
2704 (pAd->RfIcType == RFIC_3021) || (pAd->RfIcType == RFIC_3022) ||
2705 (pAd->RfIcType == RFIC_2020)))
2707 /* modify by WY for Read RF Reg. error */
2710 for (index = 0; index < NUM_OF_3020_CHNL; index++)
2712 if (Channel == FreqItems3020[index].Channel)
2714 // Programming channel parameters
2715 RT30xxWriteRFRegister(pAd, RF_R02, FreqItems3020[index].N);
2716 RT30xxWriteRFRegister(pAd, RF_R03, FreqItems3020[index].K);
2718 RT30xxReadRFRegister(pAd, RF_R06, (PUCHAR)&RFValue);
2719 RFValue = (RFValue & 0xFC) | FreqItems3020[index].R;
2720 RT30xxWriteRFRegister(pAd, RF_R06, (UCHAR)RFValue);
2723 RT30xxReadRFRegister(pAd, RF_R12, (PUCHAR)&RFValue);
2724 RFValue = (RFValue & 0xE0) | TxPwer;
2725 RT30xxWriteRFRegister(pAd, RF_R12, (UCHAR)RFValue);
2728 RT30xxReadRFRegister(pAd, RF_R23, (PUCHAR)&RFValue);
2729 //2008/08/06: KH modified "pAd->RFFreqOffset" to "pAd->ate.RFFreqOffset"
2730 RFValue = (RFValue & 0x80) | pAd->ate.RFFreqOffset;
2731 RT30xxWriteRFRegister(pAd, RF_R23, (UCHAR)RFValue);
2734 if (pAd->ate.TxWI.BW == BW_40)
2736 RFValue = pAd->Mlme.CaliBW40RfR24;
2737 //DISABLE_11N_CHECK(pAd);
2741 RFValue = pAd->Mlme.CaliBW20RfR24;
2743 RT30xxWriteRFRegister(pAd, RF_R24, (UCHAR)RFValue);
2746 RT30xxReadRFRegister(pAd, RF_R07, (PUCHAR)&RFValue);
2747 RFValue = RFValue | 0x1;
2748 RT30xxWriteRFRegister(pAd, RF_R07, (UCHAR)RFValue);
2750 // latch channel for future usage.
2751 pAd->LatchRfRegs.Channel = Channel;
2757 DBGPRINT(RT_DEBUG_TRACE, ("SwitchChannel#%d(RF=%d, Pwr0=%d, Pwr1=%d, %dT), N=0x%02X, K=0x%02X, R=0x%02X\n",
2762 pAd->Antenna.field.TxPath,
2763 FreqItems3020[index].N,
2764 FreqItems3020[index].K,
2765 FreqItems3020[index].R));
2768 //2008/07/10:KH add to support 3070 ATE-->
2771 RFRegTable = RF2850RegTable;
2773 switch (pAd->RfIcType)
2775 /* But only 2850 and 2750 support 5.5GHz band... */
2781 for (index = 0; index < NUM_OF_2850_CHNL; index++)
2783 if (Channel == RFRegTable[index].Channel)
2785 R2 = RFRegTable[index].R2;
2786 if (pAd->Antenna.field.TxPath == 1)
2788 R2 |= 0x4000; // If TXpath is 1, bit 14 = 1;
2791 if (pAd->Antenna.field.RxPath == 2)
2793 switch (pAd->ate.RxAntennaSel)
2797 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R3, &BbpValue);
2800 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, BbpValue);
2804 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R3, &BbpValue);
2807 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, BbpValue);
2811 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R3, &BbpValue);
2813 /* Only enable two Antenna to receive. */
2815 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, BbpValue);
2819 else if (pAd->Antenna.field.RxPath == 1)
2821 R2 |= 0x20040; // write 1 to off RxPath
2824 if (pAd->Antenna.field.TxPath == 2)
2826 if (pAd->ate.TxAntennaSel == 1)
2828 R2 |= 0x4000; // If TX Antenna select is 1 , bit 14 = 1; Disable Ant 2
2829 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R1, &BbpValue);
2830 BbpValue &= 0xE7; //11100111B
2831 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R1, BbpValue);
2833 else if (pAd->ate.TxAntennaSel == 2)
2835 R2 |= 0x8000; // If TX Antenna select is 2 , bit 15 = 1; Disable Ant 1
2836 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R1, &BbpValue);
2839 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R1, BbpValue);
2843 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R1, &BbpValue);
2846 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R1, BbpValue);
2849 if (pAd->Antenna.field.RxPath == 3)
2851 switch (pAd->ate.RxAntennaSel)
2855 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R3, &BbpValue);
2858 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, BbpValue);
2862 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R3, &BbpValue);
2865 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, BbpValue);
2869 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R3, &BbpValue);
2872 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, BbpValue);
2875 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R3, &BbpValue);
2878 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, BbpValue);
2885 // initialize R3, R4
2886 R3 = (RFRegTable[index].R3 & 0xffffc1ff);
2887 R4 = (RFRegTable[index].R4 & (~0x001f87c0)) | (pAd->ate.RFFreqOffset << 15);
2889 // According the Rory's suggestion to solve the middle range issue.
2890 // 5.5G band power range: 0xF9~0X0F, TX0 Reg3 bit9/TX1 Reg4 bit6="0" means the TX power reduce 7dB
2892 if ((TxPwer >= -7) && (TxPwer < 0))
2894 TxPwer = (7+TxPwer);
2895 TxPwer = (TxPwer > 0xF) ? (0xF) : (TxPwer);
2896 R3 |= (TxPwer << 10);
2897 ATEDBGPRINT(RT_DEBUG_TRACE, ("ATEAsicSwitchChannel: TxPwer=%d \n", TxPwer));
2901 TxPwer = (TxPwer > 0xF) ? (0xF) : (TxPwer);
2902 R3 |= (TxPwer << 10) | (1 << 9);
2906 if ((TxPwer2 >= -7) && (TxPwer2 < 0))
2908 TxPwer2 = (7+TxPwer2);
2909 TxPwer2 = (TxPwer2 > 0xF) ? (0xF) : (TxPwer2);
2910 R4 |= (TxPwer2 << 7);
2911 ATEDBGPRINT(RT_DEBUG_TRACE, ("ATEAsicSwitchChannel: TxPwer2=%d \n", TxPwer2));
2915 TxPwer2 = (TxPwer2 > 0xF) ? (0xF) : (TxPwer2);
2916 R4 |= (TxPwer2 << 7) | (1 << 6);
2921 R3 = (RFRegTable[index].R3 & 0xffffc1ff) | (TxPwer << 9); // set TX power0
2922 R4 = (RFRegTable[index].R4 & (~0x001f87c0)) | (pAd->ate.RFFreqOffset << 15) | (TxPwer2 <<6);// Set freq offset & TxPwr1
2925 // Based on BBP current mode before changing RF channel.
2926 if (pAd->ate.TxWI.BW == BW_40)
2932 pAd->LatchRfRegs.Channel = Channel;
2933 pAd->LatchRfRegs.R1 = RFRegTable[index].R1;
2934 pAd->LatchRfRegs.R2 = R2;
2935 pAd->LatchRfRegs.R3 = R3;
2936 pAd->LatchRfRegs.R4 = R4;
2949 // Change BBP setting during switch from a->g, g->a
2952 ULONG TxPinCfg = 0x00050F0A;// 2007.10.09 by Brian : 0x0005050A ==> 0x00050F0A
2954 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R62, (0x37 - GET_LNA_GAIN(pAd)));
2955 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R63, (0x37 - GET_LNA_GAIN(pAd)));
2956 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R64, (0x37 - GET_LNA_GAIN(pAd)));
2958 /* For 1T/2R chip only... */
2959 if (pAd->NicConfig2.field.ExternalLNAForG)
2961 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R82, 0x62);
2965 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R82, 0x84);
2968 // According the Rory's suggestion to solve the middle range issue.
2969 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R86, &BbpValue);
2970 ASSERT((BbpValue == 0x00));
2971 if ((BbpValue != 0x00))
2973 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R86, 0x00);
2976 // 5.5GHz band selection PIN, bit1 and bit2 are complement
2977 RTMP_IO_READ32(pAd, TX_BAND_CFG, &Value);
2980 RTMP_IO_WRITE32(pAd, TX_BAND_CFG, Value);
2982 // Turn off unused PA or LNA when only 1T or 1R.
2983 if (pAd->Antenna.field.TxPath == 1)
2985 TxPinCfg &= 0xFFFFFFF3;
2987 if (pAd->Antenna.field.RxPath == 1)
2989 TxPinCfg &= 0xFFFFF3FF;
2992 RTMP_IO_WRITE32(pAd, TX_PIN_CFG, TxPinCfg);
2996 ULONG TxPinCfg = 0x00050F05;//2007.10.09 by Brian : 0x00050505 ==> 0x00050F05
2998 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R62, (0x37 - GET_LNA_GAIN(pAd)));
2999 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R63, (0x37 - GET_LNA_GAIN(pAd)));
3000 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R64, (0x37 - GET_LNA_GAIN(pAd)));
3001 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R82, 0xF2);
3003 // According the Rory's suggestion to solve the middle range issue.
3004 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R86, &BbpValue);
3005 ASSERT((BbpValue == 0x00));
3006 if ((BbpValue != 0x00))
3008 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R86, 0x00);
3010 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R91, &BbpValue);
3011 ASSERT((BbpValue == 0x04));
3013 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R92, &BbpValue);
3014 ASSERT((BbpValue == 0x00));
3016 // 5.5GHz band selection PIN, bit1 and bit2 are complement
3017 RTMP_IO_READ32(pAd, TX_BAND_CFG, &Value);
3020 RTMP_IO_WRITE32(pAd, TX_BAND_CFG, Value);
3022 // Turn off unused PA or LNA when only 1T or 1R.
3023 if (pAd->Antenna.field.TxPath == 1)
3025 TxPinCfg &= 0xFFFFFFF3;
3027 if (pAd->Antenna.field.RxPath == 1)
3029 TxPinCfg &= 0xFFFFF3FF;
3032 RTMP_IO_WRITE32(pAd, TX_PIN_CFG, TxPinCfg);
3035 // R66 should be set according to Channel and use 20MHz when scanning
3039 R66 = 0x2E + GET_LNA_GAIN(pAd);
3040 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R66, R66);
3045 if (pAd->ate.TxWI.BW == BW_20)
3047 R66 = (UCHAR)(0x32 + (GET_LNA_GAIN(pAd)*5)/3);
3048 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R66, R66);
3052 R66 = (UCHAR)(0x3A + (GET_LNA_GAIN(pAd)*5)/3);
3053 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R66, R66);
3058 // On 11A, We should delay and wait RF/BBP to be stable
3059 // and the appropriate time should be 1000 micro seconds
3060 // 2005/06/05 - On 11G, We also need this delay time. Otherwise it's difficult to pass the WHQL.
3062 RTMPusecDelay(1000);
3066 // When 5.5GHz band the LSB of TxPwr will be used to reduced 7dB or not.
3067 ATEDBGPRINT(RT_DEBUG_TRACE, ("SwitchChannel#%d(RF=%d, %dT) to , R1=0x%08lx, R2=0x%08lx, R3=0x%08lx, R4=0x%08lx\n",
3070 pAd->Antenna.field.TxPath,
3071 pAd->LatchRfRegs.R1,
3072 pAd->LatchRfRegs.R2,
3073 pAd->LatchRfRegs.R3,
3074 pAd->LatchRfRegs.R4));
3078 ATEDBGPRINT(RT_DEBUG_TRACE, ("SwitchChannel#%d(RF=%d, Pwr0=%u, Pwr1=%u, %dT) to , R1=0x%08lx, R2=0x%08lx, R3=0x%08lx, R4=0x%08lx\n",
3081 (R3 & 0x00003e00) >> 9,
3082 (R4 & 0x000007c0) >> 6,
3083 pAd->Antenna.field.TxPath,
3084 pAd->LatchRfRegs.R1,
3085 pAd->LatchRfRegs.R2,
3086 pAd->LatchRfRegs.R3,
3087 pAd->LatchRfRegs.R4));
3092 // In fact, no one will call this routine so far !
3095 ==========================================================================
3097 Gives CCK TX rate 2 more dB TX power.
3098 This routine works only in ATE mode.
3100 calculate desired Tx power in RF R3.Tx0~5, should consider -
3101 0. if current radio is a noisy environment (pAd->DrsCounters.fNoisyEnvironment)
3102 1. TxPowerPercentage
3103 2. auto calibration based on TSSI feedback
3104 3. extra 2 db for CCK
3105 4. -10 db upon very-short distance (AvgRSSI >= -40db) to AP
3107 NOTE: Since this routine requires the value of (pAd->DrsCounters.fNoisyEnvironment),
3108 it should be called AFTER MlmeDynamicTxRateSwitching()
3109 ==========================================================================
3111 VOID ATEAsicAdjustTxPower(
3112 IN PRTMP_ADAPTER pAd)
3116 BOOLEAN bAutoTxAgc = FALSE;
3117 UCHAR TssiRef, *pTssiMinusBoundary, *pTssiPlusBoundary, TxAgcStep;
3118 UCHAR BbpR49 = 0, idx;
3119 PCHAR pTxAgcCompensate;
3123 /* no one calls this procedure so far */
3124 if (pAd->ate.TxWI.BW == BW_40)
3126 if (pAd->ate.Channel > 14)
3128 TxPwr[0] = pAd->Tx40MPwrCfgABand[0];
3129 TxPwr[1] = pAd->Tx40MPwrCfgABand[1];
3130 TxPwr[2] = pAd->Tx40MPwrCfgABand[2];
3131 TxPwr[3] = pAd->Tx40MPwrCfgABand[3];
3132 TxPwr[4] = pAd->Tx40MPwrCfgABand[4];
3136 TxPwr[0] = pAd->Tx40MPwrCfgGBand[0];
3137 TxPwr[1] = pAd->Tx40MPwrCfgGBand[1];
3138 TxPwr[2] = pAd->Tx40MPwrCfgGBand[2];
3139 TxPwr[3] = pAd->Tx40MPwrCfgGBand[3];
3140 TxPwr[4] = pAd->Tx40MPwrCfgGBand[4];
3145 if (pAd->ate.Channel > 14)
3147 TxPwr[0] = pAd->Tx20MPwrCfgABand[0];
3148 TxPwr[1] = pAd->Tx20MPwrCfgABand[1];
3149 TxPwr[2] = pAd->Tx20MPwrCfgABand[2];
3150 TxPwr[3] = pAd->Tx20MPwrCfgABand[3];
3151 TxPwr[4] = pAd->Tx20MPwrCfgABand[4];
3155 TxPwr[0] = pAd->Tx20MPwrCfgGBand[0];
3156 TxPwr[1] = pAd->Tx20MPwrCfgGBand[1];
3157 TxPwr[2] = pAd->Tx20MPwrCfgGBand[2];
3158 TxPwr[3] = pAd->Tx20MPwrCfgGBand[3];
3159 TxPwr[4] = pAd->Tx20MPwrCfgGBand[4];
3163 // TX power compensation for temperature variation based on TSSI.
3164 // Do it per 4 seconds.
3165 if (pAd->Mlme.OneSecPeriodicRound % 4 == 0)
3167 if (pAd->ate.Channel <= 14)
3170 bAutoTxAgc = pAd->bAutoTxAgcG;
3171 TssiRef = pAd->TssiRefG;
3172 pTssiMinusBoundary = &pAd->TssiMinusBoundaryG[0];
3173 pTssiPlusBoundary = &pAd->TssiPlusBoundaryG[0];
3174 TxAgcStep = pAd->TxAgcStepG;
3175 pTxAgcCompensate = &pAd->TxAgcCompensateG;
3180 bAutoTxAgc = pAd->bAutoTxAgcA;
3181 TssiRef = pAd->TssiRefA;
3182 pTssiMinusBoundary = &pAd->TssiMinusBoundaryA[0];
3183 pTssiPlusBoundary = &pAd->TssiPlusBoundaryA[0];
3184 TxAgcStep = pAd->TxAgcStepA;
3185 pTxAgcCompensate = &pAd->TxAgcCompensateA;
3190 /* BbpR49 is unsigned char */
3191 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R49, &BbpR49);
3193 /* (p) TssiPlusBoundaryG[0] = 0 = (m) TssiMinusBoundaryG[0] */
3194 /* compensate: +4 +3 +2 +1 0 -1 -2 -3 -4 * steps */
3195 /* step value is defined in pAd->TxAgcStepG for tx power value */
3197 /* [4]+1+[4] p4 p3 p2 p1 o1 m1 m2 m3 m4 */
3198 /* ex: 0x00 0x15 0x25 0x45 0x88 0xA0 0xB5 0xD0 0xF0
3199 above value are examined in mass factory production */
3200 /* [4] [3] [2] [1] [0] [1] [2] [3] [4] */
3202 /* plus is 0x10 ~ 0x40, minus is 0x60 ~ 0x90 */
3203 /* if value is between p1 ~ o1 or o1 ~ s1, no need to adjust tx power */
3204 /* if value is 0x65, tx power will be -= TxAgcStep*(2-1) */
3206 if (BbpR49 > pTssiMinusBoundary[1])
3208 // Reading is larger than the reference value.
3209 // Check for how large we need to decrease the Tx power.
3210 for (idx = 1; idx < 5; idx++)
3212 if (BbpR49 <= pTssiMinusBoundary[idx]) // Found the range
3215 // The index is the step we should decrease, idx = 0 means there is nothing to compensate
3216 // if (R3 > (ULONG) (TxAgcStep * (idx-1)))
3217 *pTxAgcCompensate = -(TxAgcStep * (idx-1));
3219 // *pTxAgcCompensate = -((UCHAR)R3);
3221 DeltaPwr += (*pTxAgcCompensate);
3222 ATEDBGPRINT(RT_DEBUG_TRACE, ("-- Tx Power, BBP R1=%x, TssiRef=%x, TxAgcStep=%x, step = -%d\n",
3223 BbpR49, TssiRef, TxAgcStep, idx-1));
3225 else if (BbpR49 < pTssiPlusBoundary[1])
3227 // Reading is smaller than the reference value
3228 // check for how large we need to increase the Tx power
3229 for (idx = 1; idx < 5; idx++)
3231 if (BbpR49 >= pTssiPlusBoundary[idx]) // Found the range
3234 // The index is the step we should increase, idx = 0 means there is nothing to compensate
3235 *pTxAgcCompensate = TxAgcStep * (idx-1);
3236 DeltaPwr += (*pTxAgcCompensate);
3237 ATEDBGPRINT(RT_DEBUG_TRACE, ("++ Tx Power, BBP R1=%x, TssiRef=%x, TxAgcStep=%x, step = +%d\n",
3238 BbpR49, TssiRef, TxAgcStep, idx-1));
3242 *pTxAgcCompensate = 0;
3243 ATEDBGPRINT(RT_DEBUG_TRACE, (" Tx Power, BBP R1=%x, TssiRef=%x, TxAgcStep=%x, step = +%d\n",
3244 BbpR49, TssiRef, TxAgcStep, 0));
3250 if (pAd->ate.Channel <= 14)
3252 bAutoTxAgc = pAd->bAutoTxAgcG;
3253 pTxAgcCompensate = &pAd->TxAgcCompensateG;
3257 bAutoTxAgc = pAd->bAutoTxAgcA;
3258 pTxAgcCompensate = &pAd->TxAgcCompensateA;
3262 DeltaPwr += (*pTxAgcCompensate);
3265 /* calculate delta power based on the percentage specified from UI */
3266 // E2PROM setting is calibrated for maximum TX power (i.e. 100%)
3267 // We lower TX power here according to the percentage specified from UI
3268 if (pAd->CommonCfg.TxPowerPercentage == 0xffffffff) // AUTO TX POWER control
3270 else if (pAd->CommonCfg.TxPowerPercentage > 90) // 91 ~ 100% & AUTO, treat as 100% in terms of mW
3272 else if (pAd->CommonCfg.TxPowerPercentage > 60) // 61 ~ 90%, treat as 75% in terms of mW
3276 else if (pAd->CommonCfg.TxPowerPercentage > 30) // 31 ~ 60%, treat as 50% in terms of mW
3280 else if (pAd->CommonCfg.TxPowerPercentage > 15) // 16 ~ 30%, treat as 25% in terms of mW
3284 else if (pAd->CommonCfg.TxPowerPercentage > 9) // 10 ~ 15%, treat as 12.5% in terms of mW
3288 else // 0 ~ 9 %, treat as MIN(~3%) in terms of mW
3293 /* reset different new tx power for different TX rate */
3296 if (TxPwr[i] != 0xffffffff)
3300 Value = (CHAR)((TxPwr[i] >> j*4) & 0x0F); /* 0 ~ 15 */
3302 if ((Value + DeltaPwr) < 0)
3304 Value = 0; /* min */
3306 else if ((Value + DeltaPwr) > 0xF)
3308 Value = 0xF; /* max */
3312 Value += DeltaPwr; /* temperature compensation */
3315 /* fill new value to CSR offset */
3316 TxPwr[i] = (TxPwr[i] & ~(0x0000000F << j*4)) | (Value << j*4);
3319 /* write tx power value to CSR */
3320 /* TX_PWR_CFG_0 (8 tx rate) for TX power for OFDM 12M/18M
3321 TX power for OFDM 6M/9M
3322 TX power for CCK5.5M/11M
3323 TX power for CCK1M/2M */
3324 /* TX_PWR_CFG_1 ~ TX_PWR_CFG_4 */
3325 RTMP_IO_WRITE32(pAd, TX_PWR_CFG_0 + i*4, TxPwr[i]);
3334 ========================================================================
3335 Routine Description:
3336 Write TxWI for ATE mode.
3340 ========================================================================
3344 static VOID ATEWriteTxWI(
3345 IN PRTMP_ADAPTER pAd,
3346 IN PTXWI_STRUC pTxWI,
3348 IN BOOLEAN InsTimestamp,
3351 IN BOOLEAN NSeq, // HW new a sequence.
3359 IN HTTRANSMIT_SETTING Transmit)
3362 // Always use Long preamble before verifiation short preamble functionality works well.
3363 // Todo: remove the following line if short preamble functionality works
3365 OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_SHORT_PREAMBLE_INUSED);
3367 pTxWI->TS= InsTimestamp;
3368 pTxWI->AMPDU = AMPDU;
3370 pTxWI->MIMOps = PWR_ACTIVE;
3371 pTxWI->MpduDensity = 4;
3373 pTxWI->txop = Txopmode;
3375 pTxWI->BAWinSize = BASize;
3377 pTxWI->WirelessCliID = WCID;
3378 pTxWI->MPDUtotalByteCount = Length;
3379 pTxWI->PacketId = PID;
3381 pTxWI->BW = Transmit.field.BW;
3382 pTxWI->ShortGI = Transmit.field.ShortGI;
3383 pTxWI->STBC= Transmit.field.STBC;
3385 pTxWI->MCS = Transmit.field.MCS;
3386 pTxWI->PHYMODE= Transmit.field.MODE;
3388 #ifdef DOT11_N_SUPPORT
3390 // MMPS is 802.11n features. Because TxWI->MCS > 7 must be HT mode,
3391 // so need not check if it's HT rate.
3393 if ((MIMOps == MMPS_STATIC) && (pTxWI->MCS > 7))
3396 if ((MIMOps == MMPS_DYNAMIC) && (pTxWI->MCS > 7)) // SMPS protect 2 spatial.
3398 #endif // DOT11_N_SUPPORT //
3400 pTxWI->CFACK = CfAck;
3406 ========================================================================
3408 Routine Description:
3409 Disable protection for ATE.
3410 ========================================================================
3412 VOID ATEDisableAsicProtect(
3413 IN PRTMP_ADAPTER pAd)
3415 PROT_CFG_STRUC ProtCfg, ProtCfg4;
3421 // Config ASIC RTS threshold register
3422 RTMP_IO_READ32(pAd, TX_RTS_CFG, &MacReg);
3423 MacReg &= 0xFF0000FF;
3424 MacReg |= (pAd->CommonCfg.RtsThreshold << 8);
3425 RTMP_IO_WRITE32(pAd, TX_RTS_CFG, MacReg);
3427 // Initial common protection settings
3428 RTMPZeroMemory(Protect, sizeof(Protect));
3431 ProtCfg.field.TxopAllowGF40 = 1;
3432 ProtCfg.field.TxopAllowGF20 = 1;
3433 ProtCfg.field.TxopAllowMM40 = 1;
3434 ProtCfg.field.TxopAllowMM20 = 1;
3435 ProtCfg.field.TxopAllowOfdm = 1;
3436 ProtCfg.field.TxopAllowCck = 1;
3437 ProtCfg.field.RTSThEn = 1;
3438 ProtCfg.field.ProtectNav = ASIC_SHORTNAV;
3440 // Handle legacy(B/G) protection
3441 ProtCfg.field.ProtectRate = pAd->CommonCfg.RtsRate;
3442 ProtCfg.field.ProtectCtrl = 0;
3443 Protect[0] = ProtCfg.word;
3444 Protect[1] = ProtCfg.word;
3447 // 1.All STAs in the BSS are 20/40 MHz HT
3448 // 2. in ai 20/40MHz BSS
3449 // 3. all STAs are 20MHz in a 20MHz BSS
3450 // Pure HT. no protection.
3454 // PROT_TXOP(25:20) -- 010111
3455 // PROT_NAV(19:18) -- 01 (Short NAV protection)
3456 // PROT_CTRL(17:16) -- 00 (None)
3457 // PROT_RATE(15:0) -- 0x4004 (OFDM 24M)
3458 Protect[2] = 0x01744004;
3462 // PROT_TXOP(25:20) -- 111111
3463 // PROT_NAV(19:18) -- 01 (Short NAV protection)
3464 // PROT_CTRL(17:16) -- 00 (None)
3465 // PROT_RATE(15:0) -- 0x4084 (duplicate OFDM 24M)
3466 Protect[3] = 0x03f44084;
3470 // PROT_TXOP(25:20) -- 010111
3471 // PROT_NAV(19:18) -- 01 (Short NAV protection)
3472 // PROT_CTRL(17:16) -- 00 (None)
3473 // PROT_RATE(15:0) -- 0x4004 (OFDM 24M)
3474 Protect[4] = 0x01744004;
3478 // PROT_TXOP(25:20) -- 111111
3479 // PROT_NAV(19:18) -- 01 (Short NAV protection)
3480 // PROT_CTRL(17:16) -- 00 (None)
3481 // PROT_RATE(15:0) -- 0x4084 (duplicate OFDM 24M)
3482 Protect[5] = 0x03f44084;
3484 pAd->CommonCfg.IOTestParm.bRTSLongProtOn = FALSE;
3486 offset = CCK_PROT_CFG;
3487 for (i = 0;i < 6;i++)
3488 RTMP_IO_WRITE32(pAd, offset + i*4, Protect[i]);
3494 ========================================================================
3495 Routine Description:
3496 Write TxInfo for ATE mode.
3500 ========================================================================
3502 static VOID ATEWriteTxInfo(
3503 IN PRTMP_ADAPTER pAd,
3504 IN PTXINFO_STRUC pTxInfo,
3505 IN USHORT USBDMApktLen,
3511 pTxInfo->USBDMATxPktLen = USBDMApktLen;
3512 pTxInfo->QSEL = QueueSel;
3514 if (QueueSel != FIFO_EDCA)
3515 ATEDBGPRINT(RT_DEBUG_TRACE, ("=======> QueueSel != FIFO_EDCA<=======\n"));
3517 pTxInfo->USBDMANextVLD = NextValid;
3518 pTxInfo->USBDMATxburst = TxBurst;
3519 pTxInfo->WIV = bWiv;
3520 pTxInfo->SwUseLastRound = 0;
3528 /* There are two ways to convert Rssi */
3531 // The way used with GET_LNA_GAIN().
3533 CHAR ATEConvertToRssi(
3534 IN PRTMP_ADAPTER pAd,
3536 IN UCHAR RssiNumber)
3538 UCHAR RssiOffset, LNAGain;
3540 // Rssi equals to zero should be an invalid value
3544 LNAGain = GET_LNA_GAIN(pAd);
3545 if (pAd->LatchRfRegs.Channel > 14)
3547 if (RssiNumber == 0)
3548 RssiOffset = pAd->ARssiOffset0;
3549 else if (RssiNumber == 1)
3550 RssiOffset = pAd->ARssiOffset1;
3552 RssiOffset = pAd->ARssiOffset2;
3556 if (RssiNumber == 0)
3557 RssiOffset = pAd->BGRssiOffset0;
3558 else if (RssiNumber == 1)
3559 RssiOffset = pAd->BGRssiOffset1;
3561 RssiOffset = pAd->BGRssiOffset2;
3564 return (-12 - RssiOffset - LNAGain - Rssi);
3568 // The way originally used in ATE of rt2860ap.
3570 CHAR ATEConvertToRssi(
3571 IN PRTMP_ADAPTER pAd,
3573 IN UCHAR RssiNumber)
3575 UCHAR RssiOffset, LNAGain;
3577 // Rssi equals to zero should be an invalid value
3581 if (pAd->LatchRfRegs.Channel > 14)
3583 LNAGain = pAd->ALNAGain;
3584 if (RssiNumber == 0)
3585 RssiOffset = pAd->ARssiOffset0;
3586 else if (RssiNumber == 1)
3587 RssiOffset = pAd->ARssiOffset1;
3589 RssiOffset = pAd->ARssiOffset2;
3593 LNAGain = pAd->BLNAGain;
3594 if (RssiNumber == 0)
3595 RssiOffset = pAd->BGRssiOffset0;
3596 else if (RssiNumber == 1)
3597 RssiOffset = pAd->BGRssiOffset1;
3599 RssiOffset = pAd->BGRssiOffset2;
3602 return (-32 - RssiOffset + LNAGain - Rssi);
3604 #endif /* end of #if 1 */
3607 ========================================================================
3609 Routine Description:
3610 Set Japan filter coefficients if needed.
3612 This routine should only be called when
3613 entering TXFRAME mode or TXCONT mode.
3615 ========================================================================
3617 static VOID SetJapanFilter(
3618 IN PRTMP_ADAPTER pAd)
3623 // If Channel=14 and Bandwidth=20M and Mode=CCK, set BBP R4 bit5=1
3624 // (Japan Tx filter coefficients)when (TXFRAME or TXCONT).
3626 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &BbpData);
3628 if ((pAd->ate.TxWI.PHYMODE == MODE_CCK) && (pAd->ate.Channel == 14) && (pAd->ate.TxWI.BW == BW_20))
3630 BbpData |= 0x20; // turn on
3631 ATEDBGPRINT(RT_DEBUG_TRACE, ("SetJapanFilter!!!\n"));
3635 BbpData &= 0xdf; // turn off
3636 ATEDBGPRINT(RT_DEBUG_TRACE, ("ClearJapanFilter!!!\n"));
3639 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, BbpData);
3643 IN PRTMP_ADAPTER pAd,
3644 IN PRXWI_STRUC pRxWI)
3646 /* There are two ways to collect RSSI. */
3648 //pAd->LastRxRate = (USHORT)((pRxWI->MCS) + (pRxWI->BW <<7) + (pRxWI->ShortGI <<8)+ (pRxWI->PHYMODE <<14)) ;
3649 if (pRxWI->RSSI0 != 0)
3651 pAd->ate.LastRssi0 = ATEConvertToRssi(pAd, (CHAR) pRxWI->RSSI0, RSSI_0);
3652 pAd->ate.AvgRssi0X8 = (pAd->ate.AvgRssi0X8 - pAd->ate.AvgRssi0) + pAd->ate.LastRssi0;
3653 pAd->ate.AvgRssi0 = pAd->ate.AvgRssi0X8 >> 3;
3655 if (pRxWI->RSSI1 != 0)
3657 pAd->ate.LastRssi1 = ATEConvertToRssi(pAd, (CHAR) pRxWI->RSSI1, RSSI_1);
3658 pAd->ate.AvgRssi1X8 = (pAd->ate.AvgRssi1X8 - pAd->ate.AvgRssi1) + pAd->ate.LastRssi1;
3659 pAd->ate.AvgRssi1 = pAd->ate.AvgRssi1X8 >> 3;
3661 if (pRxWI->RSSI2 != 0)
3663 pAd->ate.LastRssi2 = ATEConvertToRssi(pAd, (CHAR) pRxWI->RSSI2, RSSI_2);
3664 pAd->ate.AvgRssi2X8 = (pAd->ate.AvgRssi2X8 - pAd->ate.AvgRssi2) + pAd->ate.LastRssi2;
3665 pAd->ate.AvgRssi2 = pAd->ate.AvgRssi2X8 >> 3;
3668 pAd->ate.LastSNR0 = (CHAR)(pRxWI->SNR0);// CHAR ==> UCHAR ?
3669 pAd->ate.LastSNR1 = (CHAR)(pRxWI->SNR1);// CHAR ==> UCHAR ?
3671 pAd->ate.NumOfAvgRssiSample ++;
3673 pAd->ate.LastSNR0 = (CHAR)(pRxWI->SNR0);
3674 pAd->ate.LastSNR1 = (CHAR)(pRxWI->SNR1);
3675 pAd->ate.RxCntPerSec++;
3676 pAd->ate.LastRssi0 = ATEConvertToRssi(pAd, (CHAR) pRxWI->RSSI0, RSSI_0);
3677 pAd->ate.LastRssi1 = ATEConvertToRssi(pAd, (CHAR) pRxWI->RSSI1, RSSI_1);
3678 pAd->ate.LastRssi2 = ATEConvertToRssi(pAd, (CHAR) pRxWI->RSSI2, RSSI_2);
3679 pAd->ate.AvgRssi0X8 = (pAd->ate.AvgRssi0X8 - pAd->ate.AvgRssi0) + pAd->ate.LastRssi0;
3680 pAd->ate.AvgRssi0 = pAd->ate.AvgRssi0X8 >> 3;
3681 pAd->ate.AvgRssi1X8 = (pAd->ate.AvgRssi1X8 - pAd->ate.AvgRssi1) + pAd->ate.LastRssi1;
3682 pAd->ate.AvgRssi1 = pAd->ate.AvgRssi1X8 >> 3;
3683 pAd->ate.AvgRssi2X8 = (pAd->ate.AvgRssi2X8 - pAd->ate.AvgRssi2) + pAd->ate.LastRssi2;
3684 pAd->ate.AvgRssi2 = pAd->ate.AvgRssi2X8 >> 3;
3685 pAd->ate.NumOfAvgRssiSample ++;
3689 #ifdef CONFIG_STA_SUPPORT
3690 VOID RTMPStationStop(
3691 IN PRTMP_ADAPTER pAd)
3693 // BOOLEAN Cancelled;
3695 ATEDBGPRINT(RT_DEBUG_TRACE, ("==> RTMPStationStop\n"));
3697 // For rx statistics, we need to keep this timer running.
3698 // RTMPCancelTimer(&pAd->Mlme.PeriodicTimer, &Cancelled);
3700 ATEDBGPRINT(RT_DEBUG_TRACE, ("<== RTMPStationStop\n"));
3703 VOID RTMPStationStart(
3704 IN PRTMP_ADAPTER pAd)
3706 ATEDBGPRINT(RT_DEBUG_TRACE, ("==> RTMPStationStart\n"));
3707 ATEDBGPRINT(RT_DEBUG_TRACE, ("<== RTMPStationStart\n"));
3709 #endif // CONFIG_STA_SUPPORT //
3712 ==========================================================================
3716 This routine should only be used in ATE mode.
3717 ==========================================================================
3721 /*======================Start of RT2870======================*/
3724 static INT ATESetUpFrame(
3725 IN PRTMP_ADAPTER pAd,
3729 PTX_CONTEXT pNullContext;
3731 HTTRANSMIT_SETTING TxHTPhyMode;
3733 PTXINFO_STRUC pTxInfo;
3734 UINT32 TransferBufferLength, OrgBufferLength = 0;
3736 #ifdef RALINK_28xx_QA
3737 PHEADER_802_11 pHeader80211 = NULL;
3738 #endif // RALINK_28xx_QA //
3740 if ((RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RESET_IN_PROGRESS)) ||
3741 (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BULKOUT_RESET)) ||
3742 (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS)) ||
3743 (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)))
3748 /* We always use QID_AC_BE and FIFO_EDCA in ATE mode. */
3750 pNullContext = &(pAd->NullContext);
3751 ASSERT(pNullContext != NULL);
3753 if (pNullContext->InUse == FALSE)
3755 // Set the in use bit
3756 pNullContext->InUse = TRUE;
3757 NdisZeroMemory(&(pAd->NullFrame), sizeof(HEADER_802_11));
3759 // Fill 802.11 header.
3760 #ifdef RALINK_28xx_QA
3761 if (pAd->ate.bQATxStart == TRUE)
3763 pHeader80211 = NdisMoveMemory(&(pAd->NullFrame), pAd->ate.Header, pAd->ate.HLen);
3764 // pDest = NdisMoveMemory(&(pAd->NullFrame), pAd->ate.Header, pAd->ate.HLen);
3765 // pHeader80211 = (PHEADER_802_11)pDest;
3768 #endif // RALINK_28xx_QA //
3770 // Fill 802.11 header.
3771 NdisMoveMemory(&(pAd->NullFrame), TemplateFrame, sizeof(HEADER_802_11));
3773 #ifdef RT_BIG_ENDIAN
3774 RTMPFrameEndianChange(pAd, (PUCHAR)&(pAd->NullFrame), DIR_READ, FALSE);
3775 #endif // RT_BIG_ENDIAN //
3777 #ifdef RALINK_28xx_QA
3778 if (pAd->ate.bQATxStart == TRUE)
3780 /* modify sequence number.... */
3781 if (pAd->ate.TxDoneCount == 0)
3783 pAd->ate.seq = pHeader80211->Sequence;
3787 pHeader80211->Sequence = ++pAd->ate.seq;
3789 /* We already got all the addr. fields from QA GUI. */
3792 #endif // RALINK_28xx_QA //
3794 COPY_MAC_ADDR(pAd->NullFrame.Addr1, pAd->ate.Addr1);
3795 COPY_MAC_ADDR(pAd->NullFrame.Addr2, pAd->ate.Addr2);
3796 COPY_MAC_ADDR(pAd->NullFrame.Addr3, pAd->ate.Addr3);
3799 RTMPZeroMemory(&pAd->NullContext.TransferBuffer->field.WirelessPacket[0], TX_BUFFER_NORMSIZE);//???
3800 pTxInfo = (PTXINFO_STRUC)&pAd->NullContext.TransferBuffer->field.WirelessPacket[0];
3802 #ifdef RALINK_28xx_QA
3803 if (pAd->ate.bQATxStart == TRUE)
3805 // Avoid to exceed the range of WirelessPacket[].
3806 ASSERT(pAd->ate.TxInfo.USBDMATxPktLen <= (MAX_FRAME_SIZE - 34/* == 2312 */));
3807 NdisMoveMemory(pTxInfo, &(pAd->ate.TxInfo), sizeof(pAd->ate.TxInfo));
3810 #endif // RALINK_28xx_QA //
3812 // Avoid to exceed the range of WirelessPacket[].
3813 ASSERT(pAd->ate.TxLength <= (MAX_FRAME_SIZE - 34/* == 2312 */));
3815 // pTxInfo->USBDMATxPktLen will be updated to include padding later.
3816 ATEWriteTxInfo(pAd, pTxInfo, (USHORT)(TXWI_SIZE + pAd->ate.TxLength), TRUE, EpToQueue[MGMTPIPEIDX], FALSE, FALSE);
3817 pTxInfo->QSEL = FIFO_EDCA;
3820 pTxWI = (PTXWI_STRUC)&pAd->NullContext.TransferBuffer->field.WirelessPacket[TXINFO_SIZE];
3823 if (pAd->ate.bQATxStart == TRUE)
3825 TxHTPhyMode.field.BW = pAd->ate.TxWI.BW;
3826 TxHTPhyMode.field.ShortGI = pAd->ate.TxWI.ShortGI;
3827 TxHTPhyMode.field.STBC = pAd->ate.TxWI.STBC;
3828 TxHTPhyMode.field.MCS = pAd->ate.TxWI.MCS;
3829 TxHTPhyMode.field.MODE = pAd->ate.TxWI.PHYMODE;
3830 ATEWriteTxWI(pAd, pTxWI, pAd->ate.TxWI.FRAG, pAd->ate.TxWI.TS, pAd->ate.TxWI.AMPDU, pAd->ate.TxWI.ACK, pAd->ate.TxWI.NSEQ,
3831 pAd->ate.TxWI.BAWinSize, BSSID_WCID, pAd->ate.TxWI.MPDUtotalByteCount/* include 802.11 header */, pAd->ate.TxWI.PacketId, 0, pAd->ate.TxWI.txop/*IFS_HTTXOP*/, pAd->ate.TxWI.CFACK/*FALSE*/, TxHTPhyMode);
3835 TxHTPhyMode.field.BW = pAd->ate.TxWI.BW;
3836 TxHTPhyMode.field.ShortGI = pAd->ate.TxWI.ShortGI;
3837 TxHTPhyMode.field.STBC = 0;
3838 TxHTPhyMode.field.MCS = pAd->ate.TxWI.MCS;
3839 TxHTPhyMode.field.MODE = pAd->ate.TxWI.PHYMODE;
3841 ATEWriteTxWI(pAd, pTxWI, FALSE, FALSE, FALSE, FALSE/* No ack required. */, FALSE, 0, BSSID_WCID, pAd->ate.TxLength,
3842 0, 0, IFS_HTTXOP, FALSE, TxHTPhyMode);// "MMPS_STATIC" instead of "MMPS_DYNAMIC" ???
3845 RTMPMoveMemory(&pAd->NullContext.TransferBuffer->field.WirelessPacket[TXINFO_SIZE+TXWI_SIZE], &pAd->NullFrame, sizeof(HEADER_802_11));
3847 pDest = &(pAd->NullContext.TransferBuffer->field.WirelessPacket[TXINFO_SIZE+TXWI_SIZE+sizeof(HEADER_802_11)]);
3849 // Prepare frame payload
3850 #ifdef RALINK_28xx_QA
3851 if (pAd->ate.bQATxStart == TRUE)
3854 if ((pAd->ate.PLen != 0))
3856 for (j = 0; j < pAd->ate.DLen; j+=pAd->ate.PLen)
3858 RTMPMoveMemory(pDest, pAd->ate.Pattern, pAd->ate.PLen);
3859 pDest += pAd->ate.PLen;
3862 TransferBufferLength = TXINFO_SIZE + TXWI_SIZE + pAd->ate.TxWI.MPDUtotalByteCount;
3865 #endif // RALINK_28xx_QA //
3867 for (j = 0; j < (pAd->ate.TxLength - sizeof(HEADER_802_11)); j++)
3872 TransferBufferLength = TXINFO_SIZE + TXWI_SIZE + pAd->ate.TxLength;
3876 OrgBufferLength = TransferBufferLength;
3877 TransferBufferLength = (TransferBufferLength + 3) & (~3);
3879 // Always add 4 extra bytes at every packet.
3880 padLen = TransferBufferLength - OrgBufferLength + 4;/* 4 == last packet padding */
3881 ASSERT((padLen <= (RTMP_PKT_TAIL_PADDING - 4/* 4 == MaxBulkOutsize alignment padding */)));
3883 /* Now memzero all extra padding bytes. */
3884 NdisZeroMemory(pDest, padLen);
3887 if ((TransferBufferLength % 4) == 1)
3889 NdisZeroMemory(pDest, 7);
3891 TransferBufferLength += 3;
3893 else if ((TransferBufferLength % 4) == 2)
3895 NdisZeroMemory(pDest, 6);
3897 TransferBufferLength += 2;
3899 else if ((TransferBufferLength % 4) == 3)
3901 NdisZeroMemory(pDest, 5);
3903 TransferBufferLength += 1;
3907 // Update pTxInfo->USBDMATxPktLen to include padding.
3908 pTxInfo->USBDMATxPktLen = TransferBufferLength - TXINFO_SIZE;
3910 TransferBufferLength += 4;
3912 // If TransferBufferLength is multiple of 64, add extra 4 bytes again.
3913 if ((TransferBufferLength % pAd->BulkOutMaxPacketSize) == 0)
3915 NdisZeroMemory(pDest, 4);
3916 TransferBufferLength += 4;
3919 // Fill out frame length information for global Bulk out arbitor
3920 pAd->NullContext.BulkOutSize = TransferBufferLength;
3922 #ifdef RT_BIG_ENDIAN
3923 RTMPWIEndianChange((PUCHAR)pTxWI, TYPE_TXWI);
3924 RTMPFrameEndianChange(pAd, (((PUCHAR)pTxInfo)+TXWI_SIZE+TXINFO_SIZE), DIR_WRITE, FALSE);
3925 RTMPDescriptorEndianChange((PUCHAR)pTxInfo, TYPE_TXINFO);
3926 #endif // RT_BIG_ENDIAN //
3930 VOID ATE_RTUSBBulkOutDataPacketComplete(purbb_t pUrb, struct pt_regs *pt_regs)
3933 PTX_CONTEXT pNullContext;
3934 UCHAR BulkOutPipeId;
3936 unsigned long IrqFlags;
3939 pNullContext = (PTX_CONTEXT)pUrb->context;
3940 pAd = pNullContext->pAd;
3943 // Reset Null frame context flags
3944 pNullContext->IRPPending = FALSE;
3945 pNullContext->InUse = FALSE;
3946 Status = pUrb->status;
3948 // Store BulkOut PipeId
3949 BulkOutPipeId = pNullContext->BulkOutPipeId;
3950 pAd->BulkOutDataOneSecCount++;
3952 if (Status == USB_ST_NOERROR)
3954 #ifdef RALINK_28xx_QA
3955 if ((ATE_ON(pAd)) && (pAd->ate.bQATxStart == TRUE))
3957 if (pAd->ate.QID == BulkOutPipeId)
3959 // Let Rx can have a chance to break in during Tx process,
3960 // especially for loopback mode in QA ATE.
3961 // To trade off between tx performance and loopback mode integrity.
3962 /* Q : Now Rx is handled by tasklet, do we still need this delay ? */
3963 /* Ans : Even tasklet is used, Rx/Tx < 1 if we do not delay for a while right here. */
3965 pAd->ate.TxDoneCount++;
3966 pAd->RalinkCounters.KickTxCount++;
3967 ASSERT(pAd->ate.QID == 0);
3971 #endif // RALINK_28xx_QA //
3972 pAd->BulkOutComplete++;
3974 pAd->Counters8023.GoodTransmits++;
3976 /* Don't worry about the queue is empty or not. This function will check itself. */
3977 RTMPDeQueuePacket(pAd, TRUE, BulkOutPipeId, MAX_TX_PROCESS);
3979 /* In 28xx, SendTxWaitQueue ==> TxSwQueue */
3981 if (pAd->SendTxWaitQueue[BulkOutPipeId].Number > 0)
3983 RTMPDeQueuePacket(pAd, BulkOutPipeId);
3987 else // STATUS_OTHER
3989 pAd->BulkOutCompleteOther++;
3991 ATEDBGPRINT(RT_DEBUG_ERROR, ("BulkOutDataPacket Failed STATUS_OTHER = 0x%x . \n", Status));
3992 ATEDBGPRINT(RT_DEBUG_ERROR, (">>BulkOutReq=0x%lx, BulkOutComplete=0x%lx\n", pAd->BulkOutReq, pAd->BulkOutComplete));
3994 if ((!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RESET_IN_PROGRESS)) &&
3995 (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS)) &&
3996 (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)) &&
3997 (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BULKOUT_RESET)))
3999 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_BULKOUT_RESET);
4000 /* In 28xx, RT_OID_USB_RESET_BULK_OUT ==> CMDTHREAD_RESET_BULK_OUT */
4001 RTUSBEnqueueInternalCmd(pAd, CMDTHREAD_RESET_BULK_OUT, NULL, 0);
4003 BULK_OUT_LOCK(&pAd->BulkOutLock[BulkOutPipeId], IrqFlags);
4004 pAd->BulkOutPending[BulkOutPipeId] = FALSE;
4005 pAd->bulkResetPipeid = BulkOutPipeId;
4006 BULK_OUT_UNLOCK(&pAd->BulkOutLock[BulkOutPipeId], IrqFlags);
4013 if (atomic_read(&pAd->BulkOutRemained) > 0)
4015 atomic_dec(&pAd->BulkOutRemained);
4018 // 1st - Transmit Success
4019 OldValue = pAd->WlanCounters.TransmittedFragmentCount.u.LowPart;
4020 pAd->WlanCounters.TransmittedFragmentCount.u.LowPart++;
4022 if (pAd->WlanCounters.TransmittedFragmentCount.u.LowPart < OldValue)
4024 pAd->WlanCounters.TransmittedFragmentCount.u.HighPart++;
4027 if(((pAd->ContinBulkOut == TRUE ) ||(atomic_read(&pAd->BulkOutRemained) > 0)) && (pAd->ate.Mode & ATE_TXFRAME))
4029 RTUSB_SET_BULK_FLAG(pAd, fRTUSB_BULK_OUT_DATA_ATE);
4033 RTUSB_CLEAR_BULK_FLAG(pAd, fRTUSB_BULK_OUT_DATA_ATE);
4034 #ifdef RALINK_28xx_QA
4035 pAd->ate.TxStatus = 0;
4036 #endif // RALINK_28xx_QA //
4039 BULK_OUT_LOCK(&pAd->BulkOutLock[BulkOutPipeId], IrqFlags);
4040 pAd->BulkOutPending[BulkOutPipeId] = FALSE;
4041 BULK_OUT_UNLOCK(&pAd->BulkOutLock[BulkOutPipeId], IrqFlags);
4043 // Always call Bulk routine, even reset bulk.
4044 // The protection of rest bulk should be in BulkOut routine.
4045 RTUSBKickBulkOut(pAd);
4049 ========================================================================
4051 Routine Description:
4059 ========================================================================
4061 VOID ATE_RTUSBBulkOutDataPacket(
4062 IN PRTMP_ADAPTER pAd,
4063 IN UCHAR BulkOutPipeId)
4065 PTX_CONTEXT pNullContext = &(pAd->NullContext);
4068 unsigned long IrqFlags;
4071 ASSERT(BulkOutPipeId == 0);
4073 /* Build up the frame first. */
4074 // ATESetUpFrame(pAd, 0);
4076 BULK_OUT_LOCK(&pAd->BulkOutLock[BulkOutPipeId], IrqFlags);
4078 if (pAd->BulkOutPending[BulkOutPipeId] == TRUE)
4080 BULK_OUT_UNLOCK(&pAd->BulkOutLock[BulkOutPipeId], IrqFlags);
4084 pAd->BulkOutPending[BulkOutPipeId] = TRUE;
4085 BULK_OUT_UNLOCK(&pAd->BulkOutLock[BulkOutPipeId], IrqFlags);
4087 // Increase Total transmit byte counter
4088 pAd->RalinkCounters.OneSecTransmittedByteCount += pNullContext->BulkOutSize;
4089 pAd->RalinkCounters.TransmittedByteCount += pNullContext->BulkOutSize;
4091 // Clear ATE frame bulk out flag
4092 RTUSB_CLEAR_BULK_FLAG(pAd, fRTUSB_BULK_OUT_DATA_ATE);
4094 // Init Tx context descriptor
4095 pNullContext->IRPPending = TRUE;
4096 RTUSBInitTxDesc(pAd, pNullContext, BulkOutPipeId, (usb_complete_t)ATE_RTUSBBulkOutDataPacketComplete);
4097 pUrb = pNullContext->pUrb;
4099 if((ret = RTUSB_SUBMIT_URB(pUrb))!=0)
4101 ATEDBGPRINT(RT_DEBUG_ERROR, ("ATE_RTUSBBulkOutDataPacket: Submit Tx URB failed %d\n", ret));
4111 ========================================================================
4113 Routine Description:
4121 ========================================================================
4123 VOID ATE_RTUSBCancelPendingBulkInIRP(
4124 IN PRTMP_ADAPTER pAd)
4126 PRX_CONTEXT pRxContext;
4129 ATEDBGPRINT(RT_DEBUG_TRACE, ("--->ATE_RTUSBCancelPendingBulkInIRP\n"));
4131 for ( i = 0; i < (RX_RING_SIZE); i++)
4133 pRxContext = &(pAd->RxContext[i]);
4134 if(pRxContext->IRPPending == TRUE)
4136 RTUSB_UNLINK_URB(pRxContext->pUrb);
4137 pRxContext->IRPPending = FALSE;
4138 pRxContext->InUse = FALSE;
4139 //NdisInterlockedDecrement(&pAd->PendingRx);
4144 for ( i = 0; i < (RX_RING_SIZE); i++)
4146 pRxContext = &(pAd->RxContext[i]);
4147 if(atomic_read(&pRxContext->IrpLock) == IRPLOCK_CANCELABLE)
4149 RTUSB_UNLINK_URB(pRxContext->pUrb);
4151 InterlockedExchange(&pRxContext->IrpLock, IRPLOCK_CANCE_START);
4154 ATEDBGPRINT(RT_DEBUG_TRACE, ("<---ATE_RTUSBCancelPendingBulkInIRP\n"));
4159 VOID rt_ee_read_all(PRTMP_ADAPTER pAd, USHORT *Data)
4164 for (i = 0 ; i < EEPROM_SIZE/2 ; )
4166 /* "value" is expecially for some compilers... */
4167 RT28xx_EEPROM_READ16(pAd, i*2, value);
4173 VOID rt_ee_write_all(PRTMP_ADAPTER pAd, USHORT *Data)
4178 for (i = 0 ; i < EEPROM_SIZE/2 ; )
4180 /* "value" is expecially for some compilers... */
4182 RT28xx_EEPROM_WRITE16(pAd, i*2, value);
4186 #ifdef RALINK_28xx_QA
4187 VOID ATE_QA_Statistics(
4188 IN PRTMP_ADAPTER pAd,
4189 IN PRXWI_STRUC pRxWI,
4190 IN PRT28XX_RXD_STRUC pRxD,
4191 IN PHEADER_802_11 pHeader)
4193 // update counter first
4194 if (pHeader != NULL)
4196 if (pHeader->FC.Type == BTYPE_DATA)
4201 pAd->ate.OtherData++;
4203 else if (pHeader->FC.Type == BTYPE_MGMT)
4205 if (pHeader->FC.SubType == SUBTYPE_BEACON)
4208 pAd->ate.OtherCount++;
4210 else if (pHeader->FC.Type == BTYPE_CNTL)
4212 pAd->ate.OtherCount++;
4215 pAd->ate.RSSI0 = pRxWI->RSSI0;
4216 pAd->ate.RSSI1 = pRxWI->RSSI1;
4217 pAd->ate.RSSI2 = pRxWI->RSSI2;
4218 pAd->ate.SNR0 = pRxWI->SNR0;
4219 pAd->ate.SNR1 = pRxWI->SNR1;
4222 /* command id with Cmd Type == 0x0008(for 28xx)/0x0005(for iNIC) */
4223 #define RACFG_CMD_RF_WRITE_ALL 0x0000
4224 #define RACFG_CMD_E2PROM_READ16 0x0001
4225 #define RACFG_CMD_E2PROM_WRITE16 0x0002
4226 #define RACFG_CMD_E2PROM_READ_ALL 0x0003
4227 #define RACFG_CMD_E2PROM_WRITE_ALL 0x0004
4228 #define RACFG_CMD_IO_READ 0x0005
4229 #define RACFG_CMD_IO_WRITE 0x0006
4230 #define RACFG_CMD_IO_READ_BULK 0x0007
4231 #define RACFG_CMD_BBP_READ8 0x0008
4232 #define RACFG_CMD_BBP_WRITE8 0x0009
4233 #define RACFG_CMD_BBP_READ_ALL 0x000a
4234 #define RACFG_CMD_GET_COUNTER 0x000b
4235 #define RACFG_CMD_CLEAR_COUNTER 0x000c
4237 #define RACFG_CMD_RSV1 0x000d
4238 #define RACFG_CMD_RSV2 0x000e
4239 #define RACFG_CMD_RSV3 0x000f
4241 #define RACFG_CMD_TX_START 0x0010
4242 #define RACFG_CMD_GET_TX_STATUS 0x0011
4243 #define RACFG_CMD_TX_STOP 0x0012
4244 #define RACFG_CMD_RX_START 0x0013
4245 #define RACFG_CMD_RX_STOP 0x0014
4246 #define RACFG_CMD_GET_NOISE_LEVEL 0x0015
4248 #define RACFG_CMD_ATE_START 0x0080
4249 #define RACFG_CMD_ATE_STOP 0x0081
4251 #define RACFG_CMD_ATE_START_TX_CARRIER 0x0100
4252 #define RACFG_CMD_ATE_START_TX_CONT 0x0101
4253 #define RACFG_CMD_ATE_START_TX_FRAME 0x0102
4254 #define RACFG_CMD_ATE_SET_BW 0x0103
4255 #define RACFG_CMD_ATE_SET_TX_POWER0 0x0104
4256 #define RACFG_CMD_ATE_SET_TX_POWER1 0x0105
4257 #define RACFG_CMD_ATE_SET_FREQ_OFFSET 0x0106
4258 #define RACFG_CMD_ATE_GET_STATISTICS 0x0107
4259 #define RACFG_CMD_ATE_RESET_COUNTER 0x0108
4260 #define RACFG_CMD_ATE_SEL_TX_ANTENNA 0x0109
4261 #define RACFG_CMD_ATE_SEL_RX_ANTENNA 0x010a
4262 #define RACFG_CMD_ATE_SET_PREAMBLE 0x010b
4263 #define RACFG_CMD_ATE_SET_CHANNEL 0x010c
4264 #define RACFG_CMD_ATE_SET_ADDR1 0x010d
4265 #define RACFG_CMD_ATE_SET_ADDR2 0x010e
4266 #define RACFG_CMD_ATE_SET_ADDR3 0x010f
4267 #define RACFG_CMD_ATE_SET_RATE 0x0110
4268 #define RACFG_CMD_ATE_SET_TX_FRAME_LEN 0x0111
4269 #define RACFG_CMD_ATE_SET_TX_FRAME_COUNT 0x0112
4270 #define RACFG_CMD_ATE_START_RX_FRAME 0x0113
4271 #define RACFG_CMD_ATE_E2PROM_READ_BULK 0x0114
4272 #define RACFG_CMD_ATE_E2PROM_WRITE_BULK 0x0115
4273 #define RACFG_CMD_ATE_IO_WRITE_BULK 0x0116
4274 #define RACFG_CMD_ATE_BBP_READ_BULK 0x0117
4275 #define RACFG_CMD_ATE_BBP_WRITE_BULK 0x0118
4276 #define RACFG_CMD_ATE_RF_READ_BULK 0x0119
4277 #define RACFG_CMD_ATE_RF_WRITE_BULK 0x011a
4281 #define A2Hex(_X, _p) \
4286 while (((*p >= 'a') && (*p <= 'f')) || ((*p >= 'A') && (*p <= 'F')) || ((*p >= '0') && (*p <= '9'))) \
4288 if ((*p >= 'a') && (*p <= 'f')) \
4289 _X = _X * 16 + *p - 87; \
4290 else if ((*p >= 'A') && (*p <= 'F')) \
4291 _X = _X * 16 + *p - 55; \
4292 else if ((*p >= '0') && (*p <= '9')) \
4293 _X = _X * 16 + *p - 48; \
4299 static VOID memcpy_exl(PRTMP_ADAPTER pAd, UCHAR *dst, UCHAR *src, ULONG len);
4300 static VOID memcpy_exs(PRTMP_ADAPTER pAd, UCHAR *dst, UCHAR *src, ULONG len);
4301 static VOID RTMP_IO_READ_BULK(PRTMP_ADAPTER pAd, UCHAR *dst, UCHAR *src, UINT32 len);
4304 int ate_copy_to_user(
4309 memmove(payload, msg, len);
4314 #define copy_to_user(x,y,z) ate_copy_to_user((PUCHAR)x, (PUCHAR)y, z)
4317 #define LEN_OF_ARG 16
4320 IN PRTMP_ADAPTER pAdapter,
4321 IN struct iwreq *wrq)
4323 unsigned short Command_Id;
4324 struct ate_racfghdr *pRaCfg;
4325 INT Status = NDIS_STATUS_SUCCESS;
4329 if((pRaCfg = kmalloc(sizeof(struct ate_racfghdr), GFP_KERNEL)) == NULL)
4335 NdisZeroMemory(pRaCfg, sizeof(struct ate_racfghdr));
4337 if (copy_from_user((PUCHAR)pRaCfg, wrq->u.data.pointer, wrq->u.data.length))
4345 Command_Id = ntohs(pRaCfg->command_id);
4347 ATEDBGPRINT(RT_DEBUG_TRACE,("\n%s: Command_Id = 0x%04x !\n", __FUNCTION__, Command_Id));
4351 // We will get this command when QA starts.
4352 case RACFG_CMD_ATE_START:
4354 ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_ATE_START\n"));
4356 // prepare feedback as soon as we can to avoid QA timeout.
4357 pRaCfg->length = htons(2);
4358 pRaCfg->status = htons(0);
4360 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
4361 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
4362 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
4364 ATEDBGPRINT(RT_DEBUG_TRACE, ("wrq->u.data.length = %d\n", wrq->u.data.length));
4366 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
4368 ATEDBGPRINT(RT_DEBUG_TRACE, ("copy_to_user() fail in case RACFG_CMD_ATE_START\n"));
4373 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_START is done !\n"));
4375 Set_ATE_Proc(pAdapter, "ATESTART");
4379 // We will get this command either QA is closed or ated is killed by user.
4380 case RACFG_CMD_ATE_STOP:
4386 ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_ATE_STOP\n"));
4388 // Distinguish this command came from QA(via ated)
4389 // or ate daemon according to the existence of pid in payload.
4390 // No need to prepare feedback if this cmd came directly from ate daemon.
4391 pRaCfg->length = ntohs(pRaCfg->length);
4393 if (pRaCfg->length == sizeof(pAdapter->ate.AtePid))
4395 // This command came from QA.
4396 // Get the pid of ATE daemon.
4397 memcpy((UCHAR *)&pAdapter->ate.AtePid,
4398 (&pRaCfg->data[0]) - 2/* == &(pRaCfg->status) */,
4399 sizeof(pAdapter->ate.AtePid));
4401 // prepare feedback as soon as we can to avoid QA timeout.
4402 pRaCfg->length = htons(2);
4403 pRaCfg->status = htons(0);
4405 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
4406 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
4407 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
4409 ATEDBGPRINT(RT_DEBUG_TRACE, ("wrq->u.data.length = %d\n", wrq->u.data.length));
4411 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
4413 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_STOP\n"));
4418 // kill ATE daemon when leaving ATE mode.
4419 // We must kill ATE daemon first before setting ATESTOP,
4420 // or Microsoft will report sth. wrong.
4422 ret = kill_proc(pAdapter->ate.AtePid, SIGTERM, 1);
4425 ATEDBGPRINT(RT_DEBUG_ERROR, ("%s: unable to signal thread\n", pAdapter->net_dev->name));
4431 // Roger add to avoid error message after close QA
4432 if (pAdapter->CSRBaseAddress == RT2860_CSR_ADDR)
4435 // prepare feedback as soon as we can to avoid QA timeout.
4436 pRaCfg->length = htons(2);
4437 pRaCfg->status = htons(0);
4439 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
4440 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
4441 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
4443 ATEDBGPRINT(RT_DEBUG_TRACE, ("wrq->u.data.length = %d\n", wrq->u.data.length));
4444 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
4446 ATEDBGPRINT(RT_DEBUG_TRACE, ("copy_to_user() fail in case RACFG_CMD_AP_START\n"));
4452 // AP might have in ATE_STOP mode due to cmd from QA.
4453 if (ATE_ON(pAdapter))
4455 // Someone has killed ate daemon while QA GUI is still open.
4456 Set_ATE_Proc(pAdapter, "ATESTOP");
4457 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_AP_START is done !\n"));
4462 case RACFG_CMD_RF_WRITE_ALL:
4464 UINT32 R1, R2, R3, R4;
4467 memcpy(&R1, pRaCfg->data-2, 4);
4468 memcpy(&R2, pRaCfg->data+2, 4);
4469 memcpy(&R3, pRaCfg->data+6, 4);
4470 memcpy(&R4, pRaCfg->data+10, 4);
4471 memcpy(&channel, pRaCfg->data+14, 2);
4473 pAdapter->LatchRfRegs.R1 = ntohl(R1);
4474 pAdapter->LatchRfRegs.R2 = ntohl(R2);
4475 pAdapter->LatchRfRegs.R3 = ntohl(R3);
4476 pAdapter->LatchRfRegs.R4 = ntohl(R4);
4477 pAdapter->LatchRfRegs.Channel = ntohs(channel);
4479 RTMP_RF_IO_WRITE32(pAdapter, pAdapter->LatchRfRegs.R1);
4480 RTMP_RF_IO_WRITE32(pAdapter, pAdapter->LatchRfRegs.R2);
4481 RTMP_RF_IO_WRITE32(pAdapter, pAdapter->LatchRfRegs.R3);
4482 RTMP_RF_IO_WRITE32(pAdapter, pAdapter->LatchRfRegs.R4);
4485 pRaCfg->length = htons(2);
4486 pRaCfg->status = htons(0);
4488 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
4489 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
4490 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
4492 ATEDBGPRINT(RT_DEBUG_TRACE, ("wrq->u.data.length = %d\n", wrq->u.data.length));
4493 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
4495 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_RF_WRITE_ALL\n"));
4500 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_RF_WRITE_ALL is done !\n"));
4505 case RACFG_CMD_E2PROM_READ16:
4507 USHORT offset, value, tmp;
4509 offset = ntohs(pRaCfg->status);
4510 /* "tmp" is expecially for some compilers... */
4511 RT28xx_EEPROM_READ16(pAdapter, offset, tmp);
4513 value = htons(value);
4515 ATEDBGPRINT(RT_DEBUG_TRACE,("EEPROM Read offset = 0x%04x, value = 0x%04x\n", offset, value));
4518 pRaCfg->length = htons(4);
4519 pRaCfg->status = htons(0);
4520 memcpy(pRaCfg->data, &value, 2);
4522 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
4523 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
4524 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
4526 ATEDBGPRINT(RT_DEBUG_TRACE, ("sizeof(struct ate_racfghdr) = %d\n", sizeof(struct ate_racfghdr)));
4527 ATEDBGPRINT(RT_DEBUG_TRACE, ("wrq->u.data.length = %d\n", wrq->u.data.length));
4529 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
4531 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_E2PROM_READ16\n"));
4536 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_E2PROM_READ16 is done !\n"));
4541 case RACFG_CMD_E2PROM_WRITE16:
4543 USHORT offset, value;
4545 offset = ntohs(pRaCfg->status);
4546 memcpy(&value, pRaCfg->data, 2);
4547 value = ntohs(value);
4548 RT28xx_EEPROM_WRITE16(pAdapter, offset, value);
4551 pRaCfg->length = htons(2);
4552 pRaCfg->status = htons(0);
4553 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
4554 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
4555 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
4557 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
4559 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_E2PROM_WRITE16\n"));
4564 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_E2PROM_WRITE16 is done !\n"));
4569 case RACFG_CMD_E2PROM_READ_ALL:
4571 USHORT buffer[EEPROM_SIZE/2];
4573 rt_ee_read_all(pAdapter,(USHORT *)buffer);
4574 memcpy_exs(pAdapter, pRaCfg->data, (UCHAR *)buffer, EEPROM_SIZE);
4577 pRaCfg->length = htons(2+EEPROM_SIZE);
4578 pRaCfg->status = htons(0);
4579 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
4580 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
4581 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
4583 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
4585 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_E2PROM_READ_ALL\n"));
4590 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_E2PROM_READ_ALL is done !\n"));
4595 case RACFG_CMD_E2PROM_WRITE_ALL:
4597 USHORT buffer[EEPROM_SIZE/2];
4599 NdisZeroMemory((UCHAR *)buffer, EEPROM_SIZE);
4600 memcpy_exs(pAdapter, (UCHAR *)buffer, (UCHAR *)&pRaCfg->status, EEPROM_SIZE);
4601 rt_ee_write_all(pAdapter,(USHORT *)buffer);
4604 pRaCfg->length = htons(2);
4605 pRaCfg->status = htons(0);
4606 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
4607 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
4608 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
4610 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
4612 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_E2PROM_WRITE_ALL\n"));
4617 ATEDBGPRINT(RT_DEBUG_ERROR, ("RACFG_CMD_E2PROM_WRITE_ALL is done !\n"));
4623 case RACFG_CMD_IO_READ:
4628 memcpy(&offset, &pRaCfg->status, 4);
4629 offset = ntohl(offset);
4631 // We do not need the base address.
4632 // So just extract the offset out.
4633 offset &= 0x0000FFFF;
4634 RTMP_IO_READ32(pAdapter, offset, &value);
4635 value = htonl(value);
4638 pRaCfg->length = htons(6);
4639 pRaCfg->status = htons(0);
4640 memcpy(pRaCfg->data, &value, 4);
4642 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
4643 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
4644 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
4646 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
4648 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_IO_READ\n"));
4653 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_IO_READ is done !\n"));
4658 case RACFG_CMD_IO_WRITE:
4660 UINT32 offset, value;
4662 memcpy(&offset, pRaCfg->data-2, 4);
4663 memcpy(&value, pRaCfg->data+2, 4);
4665 offset = ntohl(offset);
4667 // We do not need the base address.
4668 // So just extract out the offset.
4669 offset &= 0x0000FFFF;
4670 value = ntohl(value);
4671 ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_IO_WRITE: offset = %x, value = %x\n", offset, value));
4672 RTMP_IO_WRITE32(pAdapter, offset, value);
4675 pRaCfg->length = htons(2);
4676 pRaCfg->status = htons(0);
4677 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
4678 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
4679 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
4681 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
4683 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_IO_WRITE\n"));
4688 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_IO_WRITE is done !\n"));
4693 case RACFG_CMD_IO_READ_BULK:
4698 memcpy(&offset, &pRaCfg->status, 4);
4699 offset = ntohl(offset);
4701 // We do not need the base address.
4702 // So just extract the offset.
4703 offset &= 0x0000FFFF;
4704 memcpy(&len, pRaCfg->data+2, 2);
4709 ATEDBGPRINT(RT_DEBUG_TRACE,("len is too large, make it smaller\n"));
4710 pRaCfg->length = htons(2);
4711 pRaCfg->status = htons(1);
4715 RTMP_IO_READ_BULK(pAdapter, pRaCfg->data, (UCHAR *)offset, len*4);// unit in four bytes
4718 pRaCfg->length = htons(2+len*4);// unit in four bytes
4719 pRaCfg->status = htons(0);
4720 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
4721 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
4722 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
4724 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
4726 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_IO_READ_BULK\n"));
4731 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_IO_READ_BULK is done !\n"));
4736 case RACFG_CMD_BBP_READ8:
4742 offset = ntohs(pRaCfg->status);
4744 if (ATE_ON(pAdapter))
4746 ATE_BBP_IO_READ8_BY_REG_ID(pAdapter, offset, &value);
4750 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, offset, &value);
4753 pRaCfg->length = htons(3);
4754 pRaCfg->status = htons(0);
4755 pRaCfg->data[0] = value;
4757 ATEDBGPRINT(RT_DEBUG_TRACE,("BBP value = %x\n", value));
4759 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
4760 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
4761 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
4763 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
4765 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_BBP_READ8\n"));
4770 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_BBP_READ8 is done !\n"));
4774 case RACFG_CMD_BBP_WRITE8:
4779 offset = ntohs(pRaCfg->status);
4780 memcpy(&value, pRaCfg->data, 1);
4782 if (ATE_ON(pAdapter))
4784 ATE_BBP_IO_WRITE8_BY_REG_ID(pAdapter, offset, value);
4788 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, offset, value);
4791 if ((offset == BBP_R1) || (offset == BBP_R3))
4793 SyncTxRxConfig(pAdapter, offset, value);
4797 pRaCfg->length = htons(2);
4798 pRaCfg->status = htons(0);
4799 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
4800 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
4801 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
4803 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
4805 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_BBP_WRITE8\n"));
4810 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_BBP_WRITE8 is done !\n"));
4815 case RACFG_CMD_BBP_READ_ALL:
4819 for (j = 0; j < 137; j++)
4821 pRaCfg->data[j] = 0;
4823 if (ATE_ON(pAdapter))
4825 ATE_BBP_IO_READ8_BY_REG_ID(pAdapter, j, &pRaCfg->data[j]);
4829 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, j, &pRaCfg->data[j]);
4834 pRaCfg->length = htons(2+137);
4835 pRaCfg->status = htons(0);
4837 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
4838 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
4839 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
4841 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
4843 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_BBP_READ_ALL\n"));
4848 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_BBP_READ_ALL is done !\n"));
4854 case RACFG_CMD_ATE_E2PROM_READ_BULK:
4858 USHORT buffer[EEPROM_SIZE/2];
4860 offset = ntohs(pRaCfg->status);
4861 memcpy(&len, pRaCfg->data, 2);
4864 rt_ee_read_all(pAdapter,(USHORT *)buffer);
4865 if (offset + len <= EEPROM_SIZE)
4866 memcpy_exs(pAdapter, pRaCfg->data, (UCHAR *)buffer+offset, len);
4868 ATEDBGPRINT(RT_DEBUG_ERROR, ("exceed EEPROM size\n"));
4871 pRaCfg->length = htons(2+len);
4872 pRaCfg->status = htons(0);
4873 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
4874 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
4875 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
4877 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
4879 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_E2PROM_READ_BULK\n"));
4884 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_E2PROM_READ_BULK is done !\n"));
4890 case RACFG_CMD_ATE_E2PROM_WRITE_BULK:
4894 USHORT buffer[EEPROM_SIZE/2];
4896 offset = ntohs(pRaCfg->status);
4897 memcpy(&len, pRaCfg->data, 2);
4900 rt_ee_read_all(pAdapter,(USHORT *)buffer);
4901 memcpy_exs(pAdapter, (UCHAR *)buffer + offset, (UCHAR *)pRaCfg->data + 2, len);
4902 rt_ee_write_all(pAdapter,(USHORT *)buffer);
4905 pRaCfg->length = htons(2);
4906 pRaCfg->status = htons(0);
4907 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
4908 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
4909 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
4910 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
4912 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_E2PROM_WRITE_BULK\n"));
4917 ATEDBGPRINT(RT_DEBUG_ERROR, ("RACFG_CMD_ATE_E2PROM_WRITE_BULK is done !\n"));
4923 case RACFG_CMD_ATE_IO_WRITE_BULK:
4925 UINT32 offset, i, value;
4928 memcpy(&offset, &pRaCfg->status, 4);
4929 offset = ntohl(offset);
4930 memcpy(&len, pRaCfg->data+2, 2);
4933 for (i = 0; i < len; i += 4)
4935 memcpy_exl(pAdapter, (UCHAR *)&value, pRaCfg->data+4+i, 4);
4936 printk("Write %x %x\n", offset + i, value);
4937 RTMP_IO_WRITE32(pAdapter, (offset +i) & 0xffff, value);
4941 pRaCfg->length = htons(2);
4942 pRaCfg->status = htons(0);
4943 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
4944 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
4945 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
4946 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
4948 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_IO_WRITE_BULK\n"));
4953 ATEDBGPRINT(RT_DEBUG_ERROR, ("RACFG_CMD_ATE_IO_WRITE_BULK is done !\n"));
4959 case RACFG_CMD_ATE_BBP_READ_BULK:
4965 offset = ntohs(pRaCfg->status);
4966 memcpy(&len, pRaCfg->data, 2);
4970 for (j = offset; j < (offset+len); j++)
4972 pRaCfg->data[j - offset] = 0;
4974 if (pAdapter->ate.Mode == ATE_STOP)
4976 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, j, &pRaCfg->data[j - offset]);
4980 ATE_BBP_IO_READ8_BY_REG_ID(pAdapter, j, &pRaCfg->data[j - offset]);
4985 pRaCfg->length = htons(2+len);
4986 pRaCfg->status = htons(0);
4987 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
4988 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
4989 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
4991 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
4993 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_BBP_READ_BULK\n"));
4998 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_BBP_READ_BULK is done !\n"));
5004 case RACFG_CMD_ATE_BBP_WRITE_BULK:
5011 offset = ntohs(pRaCfg->status);
5012 memcpy(&len, pRaCfg->data, 2);
5015 for (j = offset; j < (offset+len); j++)
5017 value = pRaCfg->data + 2 + (j - offset);
5018 if (pAdapter->ate.Mode == ATE_STOP)
5020 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, j, *value);
5024 ATE_BBP_IO_WRITE8_BY_REG_ID(pAdapter, j, *value);
5029 pRaCfg->length = htons(2);
5030 pRaCfg->status = htons(0);
5031 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
5032 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
5033 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
5035 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
5037 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_BBP_WRITE_BULK\n"));
5042 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_BBP_WRITE_BULK is done !\n"));
5047 #ifdef CONFIG_RALINK_RT3052
5048 case RACFG_CMD_ATE_RF_READ_BULK:
5054 offset = ntohs(pRaCfg->status);
5055 memcpy(&len, pRaCfg->data, 2);
5058 for (j = offset; j < (offset+len); j++)
5060 pRaCfg->data[j - offset] = 0;
5061 RT30xxReadRFRegister(pAdapter, j, &pRaCfg->data[j - offset]);
5065 pRaCfg->length = htons(2+len);
5066 pRaCfg->status = htons(0);
5067 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
5068 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
5069 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
5071 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
5073 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_RF_READ_BULK\n"));
5078 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_RF_READ_BULK is done !\n"));
5084 case RACFG_CMD_ATE_RF_WRITE_BULK:
5091 offset = ntohs(pRaCfg->status);
5092 memcpy(&len, pRaCfg->data, 2);
5095 for (j = offset; j < (offset+len); j++)
5097 value = pRaCfg->data + 2 + (j - offset);
5098 RT30xxWriteRFRegister(pAdapter, j, *value);
5102 pRaCfg->length = htons(2);
5103 pRaCfg->status = htons(0);
5104 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
5105 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
5106 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
5108 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
5110 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_RF_WRITE_BULK\n"));
5115 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_RF_WRITE_BULK is done !\n"));
5123 case RACFG_CMD_GET_NOISE_LEVEL:
5126 INT32 buffer[3][10];/* 3 : RxPath ; 10 : no. of per rssi samples */
5128 channel = (ntohs(pRaCfg->status) & 0x00FF);
5129 CalNoiseLevel(pAdapter, channel, buffer);
5130 memcpy_exl(pAdapter, (UCHAR *)pRaCfg->data, (UCHAR *)&(buffer[0][0]), (sizeof(INT32)*3*10));
5133 pRaCfg->length = htons(2 + (sizeof(INT32)*3*10));
5134 pRaCfg->status = htons(0);
5135 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
5136 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
5137 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
5139 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
5141 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_GET_NOISE_LEVEL\n"));
5146 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_GET_NOISE_LEVEL is done !\n"));
5151 case RACFG_CMD_GET_COUNTER:
5153 memcpy_exl(pAdapter, &pRaCfg->data[0], (UCHAR *)&pAdapter->ate.U2M, 4);
5154 memcpy_exl(pAdapter, &pRaCfg->data[4], (UCHAR *)&pAdapter->ate.OtherData, 4);
5155 memcpy_exl(pAdapter, &pRaCfg->data[8], (UCHAR *)&pAdapter->ate.Beacon, 4);
5156 memcpy_exl(pAdapter, &pRaCfg->data[12], (UCHAR *)&pAdapter->ate.OtherCount, 4);
5157 memcpy_exl(pAdapter, &pRaCfg->data[16], (UCHAR *)&pAdapter->ate.TxAc0, 4);
5158 memcpy_exl(pAdapter, &pRaCfg->data[20], (UCHAR *)&pAdapter->ate.TxAc1, 4);
5159 memcpy_exl(pAdapter, &pRaCfg->data[24], (UCHAR *)&pAdapter->ate.TxAc2, 4);
5160 memcpy_exl(pAdapter, &pRaCfg->data[28], (UCHAR *)&pAdapter->ate.TxAc3, 4);
5161 memcpy_exl(pAdapter, &pRaCfg->data[32], (UCHAR *)&pAdapter->ate.TxHCCA, 4);
5162 memcpy_exl(pAdapter, &pRaCfg->data[36], (UCHAR *)&pAdapter->ate.TxMgmt, 4);
5163 memcpy_exl(pAdapter, &pRaCfg->data[40], (UCHAR *)&pAdapter->ate.RSSI0, 4);
5164 memcpy_exl(pAdapter, &pRaCfg->data[44], (UCHAR *)&pAdapter->ate.RSSI1, 4);
5165 memcpy_exl(pAdapter, &pRaCfg->data[48], (UCHAR *)&pAdapter->ate.RSSI2, 4);
5166 memcpy_exl(pAdapter, &pRaCfg->data[52], (UCHAR *)&pAdapter->ate.SNR0, 4);
5167 memcpy_exl(pAdapter, &pRaCfg->data[56], (UCHAR *)&pAdapter->ate.SNR1, 4);
5169 pRaCfg->length = htons(2+60);
5170 pRaCfg->status = htons(0);
5171 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
5172 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
5173 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
5175 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
5177 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_GET_COUNTER\n"));
5182 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_GET_COUNTER is done !\n"));
5187 case RACFG_CMD_CLEAR_COUNTER:
5189 pAdapter->ate.U2M = 0;
5190 pAdapter->ate.OtherData = 0;
5191 pAdapter->ate.Beacon = 0;
5192 pAdapter->ate.OtherCount = 0;
5193 pAdapter->ate.TxAc0 = 0;
5194 pAdapter->ate.TxAc1 = 0;
5195 pAdapter->ate.TxAc2 = 0;
5196 pAdapter->ate.TxAc3 = 0;
5197 pAdapter->ate.TxHCCA = 0;
5198 pAdapter->ate.TxMgmt = 0;
5199 pAdapter->ate.TxDoneCount = 0;
5201 pRaCfg->length = htons(2);
5202 pRaCfg->status = htons(0);
5204 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
5205 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
5206 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
5208 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
5210 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_CLEAR_COUNTER\n"));
5215 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_CLEAR_COUNTER is done !\n"));
5221 case RACFG_CMD_TX_START:
5225 UCHAR Bbp22Value = 0, Bbp24Value = 0;
5227 if ((pAdapter->ate.TxStatus != 0) && (pAdapter->ate.Mode & ATE_TXFRAME))
5229 ATEDBGPRINT(RT_DEBUG_TRACE,("Ate Tx is already running, to run next Tx, you must stop it first\n"));
5231 goto TX_START_ERROR;
5233 else if ((pAdapter->ate.TxStatus != 0) && !(pAdapter->ate.Mode & ATE_TXFRAME))
5237 while ((i++ < 10) && (pAdapter->ate.TxStatus != 0))
5239 RTMPusecDelay(5000);
5243 pAdapter->ate.TxStatus = 0;
5244 pAdapter->ate.TxDoneCount = 0;
5245 //pAdapter->ate.Repeat = 0;
5246 pAdapter->ate.bQATxStart = FALSE;
5249 // If pRaCfg->length == 0, this "RACFG_CMD_TX_START" is for Carrier test or Carrier Suppression.
5250 if (ntohs(pRaCfg->length) != 0)
5254 NdisMoveMemory(&pAdapter->ate.TxInfo, pRaCfg->data - 2, 4);
5255 #ifdef RT_BIG_ENDIAN
5256 RTMPDescriptorEndianChange((PUCHAR) &pAdapter->ate.TxInfo, TYPE_TXINFO);
5257 #endif // RT_BIG_ENDIAN //
5260 NdisMoveMemory(&pAdapter->ate.TxWI, pRaCfg->data + 2, 16);
5261 #ifdef RT_BIG_ENDIAN
5262 RTMPWIEndianChange((PUCHAR)&pAdapter->ate.TxWI, TYPE_TXWI);
5263 #endif // RT_BIG_ENDIAN //
5265 NdisMoveMemory(&pAdapter->ate.TxCount, pRaCfg->data + 18, 4);
5266 pAdapter->ate.TxCount = ntohl(pAdapter->ate.TxCount);
5268 p = (USHORT *)(&pRaCfg->data[22]);
5269 //p = pRaCfg->data + 22;
5270 // always use QID_AC_BE
5271 pAdapter->ate.QID = 0;
5272 p = (USHORT *)(&pRaCfg->data[24]);
5273 //p = pRaCfg->data + 24;
5274 pAdapter->ate.HLen = ntohs(*p);
5276 if (pAdapter->ate.HLen > 32)
5278 ATEDBGPRINT(RT_DEBUG_ERROR,("pAdapter->ate.HLen > 32\n"));
5280 goto TX_START_ERROR;
5283 NdisMoveMemory(&pAdapter->ate.Header, pRaCfg->data + 26, pAdapter->ate.HLen);
5286 pAdapter->ate.PLen = ntohs(pRaCfg->length) - (pAdapter->ate.HLen + 28);
5288 if (pAdapter->ate.PLen > 32)
5290 ATEDBGPRINT(RT_DEBUG_ERROR,("pAdapter->ate.PLen > 32\n"));
5292 goto TX_START_ERROR;
5295 NdisMoveMemory(&pAdapter->ate.Pattern, pRaCfg->data + 26 + pAdapter->ate.HLen, pAdapter->ate.PLen);
5296 pAdapter->ate.DLen = pAdapter->ate.TxWI.MPDUtotalByteCount - pAdapter->ate.HLen;
5299 ATE_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R22, &Bbp22Value);
5305 if (pAdapter->ate.TxCount == 0)
5308 ATEDBGPRINT(RT_DEBUG_TRACE,("START TXFRAME\n"));
5309 pAdapter->ate.bQATxStart = TRUE;
5310 Set_ATE_Proc(pAdapter, "TXFRAME");
5314 case BBP22_TXCONT_OR_CARRSUPP:
5316 ATEDBGPRINT(RT_DEBUG_TRACE,("BBP22_TXCONT_OR_CARRSUPP\n"));
5317 ATE_BBP_IO_READ8_BY_REG_ID(pAdapter, 24, &Bbp24Value);
5323 ATEDBGPRINT(RT_DEBUG_TRACE,("START TXCONT\n"));
5324 pAdapter->ate.bQATxStart = TRUE;
5325 Set_ATE_Proc(pAdapter, "TXCONT");
5329 case BBP24_CARRSUPP:
5331 ATEDBGPRINT(RT_DEBUG_TRACE,("START TXCARRSUPP\n"));
5332 pAdapter->ate.bQATxStart = TRUE;
5333 pAdapter->ate.Mode |= ATE_TXCARRSUPP;
5339 ATEDBGPRINT(RT_DEBUG_ERROR,("Unknown Start TX subtype !"));
5348 ATEDBGPRINT(RT_DEBUG_TRACE,("START TXCARR\n"));
5349 pAdapter->ate.bQATxStart = TRUE;
5350 Set_ATE_Proc(pAdapter, "TXCARR");
5356 ATEDBGPRINT(RT_DEBUG_ERROR,("Unknown Start TX subtype !"));
5361 if (pAdapter->ate.bQATxStart == TRUE)
5364 pRaCfg->length = htons(2);
5365 pRaCfg->status = htons(0);
5367 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
5368 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
5369 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
5371 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
5373 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() was failed in case RACFG_CMD_TX_START\n"));
5378 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_TX_START is done !\n"));
5385 pRaCfg->length = htons(2);
5386 pRaCfg->status = htons(err);
5388 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
5389 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
5390 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
5391 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
5393 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_TX_START\n"));
5398 ATEDBGPRINT(RT_DEBUG_TRACE, ("feedback of TX_START_ERROR is done !\n"));
5403 case RACFG_CMD_GET_TX_STATUS:
5408 pRaCfg->length = htons(6);
5409 pRaCfg->status = htons(0);
5410 count = htonl(pAdapter->ate.TxDoneCount);
5411 NdisMoveMemory(pRaCfg->data, &count, 4);
5412 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
5413 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
5414 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
5416 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
5418 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_GET_TX_STATUS\n"));
5423 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_GET_TX_STATUS is done !\n"));
5428 case RACFG_CMD_TX_STOP:
5430 ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_TX_STOP\n"));
5432 Set_ATE_Proc(pAdapter, "TXSTOP");
5435 pRaCfg->length = htons(2);
5436 pRaCfg->status = htons(0);
5437 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
5438 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
5439 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
5441 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
5443 ATEDBGPRINT(RT_DEBUG_TRACE, ("copy_to_user() fail in case RACFG_CMD_TX_STOP\n"));
5448 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_TX_STOP is done !\n"));
5453 case RACFG_CMD_RX_START:
5455 ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_RX_START\n"));
5457 pAdapter->ate.bQARxStart = TRUE;
5458 Set_ATE_Proc(pAdapter, "RXFRAME");
5461 pRaCfg->length = htons(2);
5462 pRaCfg->status = htons(0);
5463 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
5464 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
5465 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
5467 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
5469 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_RX_START\n"));
5474 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_RX_START is done !\n"));
5479 case RACFG_CMD_RX_STOP:
5481 ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_RX_STOP\n"));
5483 Set_ATE_Proc(pAdapter, "RXSTOP");
5486 pRaCfg->length = htons(2);
5487 pRaCfg->status = htons(0);
5488 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
5489 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
5490 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
5492 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
5494 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_RX_STOP\n"));
5499 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_RX_STOP is done !\n"));
5504 /* The following cases are for new ATE GUI(not QA). */
5505 /*==================================================*/
5506 case RACFG_CMD_ATE_START_TX_CARRIER:
5508 ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_ATE_START_TX_CARRIER\n"));
5510 Set_ATE_Proc(pAdapter, "TXCARR");
5512 pRaCfg->length = htons(2);
5513 pRaCfg->status = htons(0);
5515 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
5516 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
5517 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
5519 ATEDBGPRINT(RT_DEBUG_TRACE, ("wrq->u.data.length = %d\n", wrq->u.data.length));
5521 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
5523 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_START_TX_CARRIER\n"));
5528 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_START_TX_CARRIER is done !\n"));
5533 case RACFG_CMD_ATE_START_TX_CONT:
5535 ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_ATE_START_TX_CONT\n"));
5537 Set_ATE_Proc(pAdapter, "TXCONT");
5539 pRaCfg->length = htons(2);
5540 pRaCfg->status = htons(0);
5542 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
5543 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
5544 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
5546 ATEDBGPRINT(RT_DEBUG_TRACE, ("wrq->u.data.length = %d\n", wrq->u.data.length));
5548 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
5550 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_START_TX_CONT\n"));
5555 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_START_TX_CONT is done !\n"));
5560 case RACFG_CMD_ATE_START_TX_FRAME:
5562 ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_ATE_START_TX_FRAME\n"));
5564 Set_ATE_Proc(pAdapter, "TXFRAME");
5566 pRaCfg->length = htons(2);
5567 pRaCfg->status = htons(0);
5569 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
5570 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
5571 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
5573 ATEDBGPRINT(RT_DEBUG_TRACE, ("wrq->u.data.length = %d\n", wrq->u.data.length));
5575 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
5577 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_START_TX_FRAME\n"));
5582 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_START_TX_FRAME is done !\n"));
5587 case RACFG_CMD_ATE_SET_BW:
5590 UCHAR str[LEN_OF_ARG];
5592 NdisZeroMemory(str, LEN_OF_ARG);
5594 ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_ATE_SET_BW\n"));
5596 memcpy((PUCHAR)&value, (PUCHAR)&(pRaCfg->status), 2);
5597 value = ntohs(value);
5598 sprintf((PCHAR)str, "%d", value);
5600 Set_ATE_TX_BW_Proc(pAdapter, str);
5603 pRaCfg->length = htons(2);
5604 pRaCfg->status = htons(0);
5605 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
5606 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
5607 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
5609 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
5611 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_SET_BW\n"));
5616 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_SET_BW is done !\n"));
5621 case RACFG_CMD_ATE_SET_TX_POWER0:
5624 UCHAR str[LEN_OF_ARG];
5626 NdisZeroMemory(str, LEN_OF_ARG);
5628 ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_ATE_SET_TX_POWER0\n"));
5630 memcpy((PUCHAR)&value, (PUCHAR)&(pRaCfg->status), 2);
5631 value = ntohs(value);
5632 sprintf((PCHAR)str, "%d", value);
5633 Set_ATE_TX_POWER0_Proc(pAdapter, str);
5636 pRaCfg->length = htons(2);
5637 pRaCfg->status = htons(0);
5638 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
5639 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
5640 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
5642 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
5644 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_SET_TX_POWER0\n"));
5649 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_SET_TX_POWER0 is done !\n"));
5654 case RACFG_CMD_ATE_SET_TX_POWER1:
5657 UCHAR str[LEN_OF_ARG];
5659 NdisZeroMemory(str, LEN_OF_ARG);
5661 ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_ATE_SET_TX_POWER1\n"));
5663 memcpy((PUCHAR)&value, (PUCHAR)&(pRaCfg->status), 2);
5664 value = ntohs(value);
5665 sprintf((PCHAR)str, "%d", value);
5666 Set_ATE_TX_POWER1_Proc(pAdapter, str);
5669 pRaCfg->length = htons(2);
5670 pRaCfg->status = htons(0);
5671 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
5672 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
5673 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
5675 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
5677 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_SET_TX_POWER1\n"));
5682 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_SET_TX_POWER1 is done !\n"));
5687 case RACFG_CMD_ATE_SET_FREQ_OFFSET:
5690 UCHAR str[LEN_OF_ARG];
5692 NdisZeroMemory(str, LEN_OF_ARG);
5694 ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_ATE_SET_FREQ_OFFSET\n"));
5696 memcpy((PUCHAR)&value, (PUCHAR)&(pRaCfg->status), 2);
5697 value = ntohs(value);
5698 sprintf((PCHAR)str, "%d", value);
5699 Set_ATE_TX_FREQOFFSET_Proc(pAdapter, str);
5702 pRaCfg->length = htons(2);
5703 pRaCfg->status = htons(0);
5704 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
5705 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
5706 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
5708 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
5710 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_SET_FREQ_OFFSET\n"));
5715 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_SET_FREQ_OFFSET is done !\n"));
5720 case RACFG_CMD_ATE_GET_STATISTICS:
5722 ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_ATE_GET_STATISTICS\n"));
5724 memcpy_exl(pAdapter, &pRaCfg->data[0], (UCHAR *)&pAdapter->ate.TxDoneCount, 4);
5725 memcpy_exl(pAdapter, &pRaCfg->data[4], (UCHAR *)&pAdapter->WlanCounters.RetryCount.u.LowPart, 4);
5726 memcpy_exl(pAdapter, &pRaCfg->data[8], (UCHAR *)&pAdapter->WlanCounters.FailedCount.u.LowPart, 4);
5727 memcpy_exl(pAdapter, &pRaCfg->data[12], (UCHAR *)&pAdapter->WlanCounters.RTSSuccessCount.u.LowPart, 4);
5728 memcpy_exl(pAdapter, &pRaCfg->data[16], (UCHAR *)&pAdapter->WlanCounters.RTSFailureCount.u.LowPart, 4);
5729 memcpy_exl(pAdapter, &pRaCfg->data[20], (UCHAR *)&pAdapter->WlanCounters.ReceivedFragmentCount.QuadPart, 4);
5730 memcpy_exl(pAdapter, &pRaCfg->data[24], (UCHAR *)&pAdapter->WlanCounters.FCSErrorCount.u.LowPart, 4);
5731 memcpy_exl(pAdapter, &pRaCfg->data[28], (UCHAR *)&pAdapter->Counters8023.RxNoBuffer, 4);
5732 memcpy_exl(pAdapter, &pRaCfg->data[32], (UCHAR *)&pAdapter->WlanCounters.FrameDuplicateCount.u.LowPart, 4);
5733 memcpy_exl(pAdapter, &pRaCfg->data[36], (UCHAR *)&pAdapter->RalinkCounters.OneSecFalseCCACnt, 4);
5735 if (pAdapter->ate.RxAntennaSel == 0)
5741 RSSI0 = (INT32)(pAdapter->ate.LastRssi0 - pAdapter->BbpRssiToDbmDelta);
5742 RSSI1 = (INT32)(pAdapter->ate.LastRssi1 - pAdapter->BbpRssiToDbmDelta);
5743 RSSI2 = (INT32)(pAdapter->ate.LastRssi2 - pAdapter->BbpRssiToDbmDelta);
5744 memcpy_exl(pAdapter, &pRaCfg->data[40], (UCHAR *)&RSSI0, 4);
5745 memcpy_exl(pAdapter, &pRaCfg->data[44], (UCHAR *)&RSSI1, 4);
5746 memcpy_exl(pAdapter, &pRaCfg->data[48], (UCHAR *)&RSSI2, 4);
5747 pRaCfg->length = htons(2+52);
5753 RSSI0 = (INT32)(pAdapter->ate.LastRssi0 - pAdapter->BbpRssiToDbmDelta);
5754 memcpy_exl(pAdapter, &pRaCfg->data[40], (UCHAR *)&RSSI0, 4);
5755 pRaCfg->length = htons(2+44);
5757 pRaCfg->status = htons(0);
5758 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
5759 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
5760 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
5762 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
5764 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_GET_STATISTICS\n"));
5769 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_GET_STATISTICS is done !\n"));
5774 case RACFG_CMD_ATE_RESET_COUNTER:
5777 UCHAR str[LEN_OF_ARG];
5779 NdisZeroMemory(str, LEN_OF_ARG);
5781 ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_ATE_RESET_COUNTER\n"));
5783 sprintf((PCHAR)str, "%d", value);
5784 Set_ResetStatCounter_Proc(pAdapter, str);
5786 pAdapter->ate.TxDoneCount = 0;
5788 pRaCfg->length = htons(2);
5789 pRaCfg->status = htons(0);
5791 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
5792 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
5793 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
5795 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
5797 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_RESET_COUNTER\n"));
5802 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_RESET_COUNTER is done !\n"));
5808 case RACFG_CMD_ATE_SEL_TX_ANTENNA:
5811 UCHAR str[LEN_OF_ARG];
5813 NdisZeroMemory(str, LEN_OF_ARG);
5815 ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_ATE_SEL_TX_ANTENNA\n"));
5817 memcpy((PUCHAR)&value, (PUCHAR)&(pRaCfg->status), 2);
5818 value = ntohs(value);
5819 sprintf((PCHAR)str, "%d", value);
5820 Set_ATE_TX_Antenna_Proc(pAdapter, str);
5823 pRaCfg->length = htons(2);
5824 pRaCfg->status = htons(0);
5825 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
5826 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
5827 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
5829 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
5831 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_SEL_TX_ANTENNA\n"));
5836 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_SEL_TX_ANTENNA is done !\n"));
5841 case RACFG_CMD_ATE_SEL_RX_ANTENNA:
5844 UCHAR str[LEN_OF_ARG];
5846 NdisZeroMemory(str, LEN_OF_ARG);
5848 ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_ATE_SEL_RX_ANTENNA\n"));
5850 memcpy((PUCHAR)&value, (PUCHAR)&(pRaCfg->status), 2);
5851 value = ntohs(value);
5852 sprintf((PCHAR)str, "%d", value);
5853 Set_ATE_RX_Antenna_Proc(pAdapter, str);
5856 pRaCfg->length = htons(2);
5857 pRaCfg->status = htons(0);
5858 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
5859 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
5860 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
5862 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
5864 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_SEL_RX_ANTENNA\n"));
5869 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_SEL_RX_ANTENNA is done !\n"));
5874 case RACFG_CMD_ATE_SET_PREAMBLE:
5877 UCHAR str[LEN_OF_ARG];
5879 NdisZeroMemory(str, LEN_OF_ARG);
5881 ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_ATE_SET_PREAMBLE\n"));
5883 memcpy((PUCHAR)&value, (PUCHAR)&(pRaCfg->status), 2);
5884 value = ntohs(value);
5885 sprintf((PCHAR)str, "%d", value);
5886 Set_ATE_TX_MODE_Proc(pAdapter, str);
5889 pRaCfg->length = htons(2);
5890 pRaCfg->status = htons(0);
5891 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
5892 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
5893 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
5895 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
5897 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_SET_PREAMBLE\n"));
5902 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_SET_PREAMBLE is done !\n"));
5907 case RACFG_CMD_ATE_SET_CHANNEL:
5910 UCHAR str[LEN_OF_ARG];
5912 NdisZeroMemory(str, LEN_OF_ARG);
5914 ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_ATE_SET_CHANNEL\n"));
5916 memcpy((PUCHAR)&value, (PUCHAR)&(pRaCfg->status), 2);
5917 value = ntohs(value);
5918 sprintf((PCHAR)str, "%d", value);
5919 Set_ATE_CHANNEL_Proc(pAdapter, str);
5922 pRaCfg->length = htons(2);
5923 pRaCfg->status = htons(0);
5924 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
5925 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
5926 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
5928 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
5930 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_SET_CHANNEL\n"));
5935 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_SET_CHANNEL is done !\n"));
5940 case RACFG_CMD_ATE_SET_ADDR1:
5942 ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_ATE_SET_ADDR1\n"));
5944 // Addr is an array of UCHAR,
5945 // so no need to perform endian swap.
5946 memcpy(pAdapter->ate.Addr1, (PUCHAR)(pRaCfg->data - 2), MAC_ADDR_LEN);
5949 pRaCfg->length = htons(2);
5950 pRaCfg->status = htons(0);
5951 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
5952 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
5953 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
5955 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
5957 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_SET_ADDR1\n"));
5962 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_SET_ADDR1 is done !\n (ADDR1 = %2X:%2X:%2X:%2X:%2X:%2X)\n", pAdapter->ate.Addr1[0],
5963 pAdapter->ate.Addr1[1], pAdapter->ate.Addr1[2], pAdapter->ate.Addr1[3], pAdapter->ate.Addr1[4], pAdapter->ate.Addr1[5]));
5968 case RACFG_CMD_ATE_SET_ADDR2:
5970 ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_ATE_SET_ADDR2\n"));
5972 // Addr is an array of UCHAR,
5973 // so no need to perform endian swap.
5974 memcpy(pAdapter->ate.Addr2, (PUCHAR)(pRaCfg->data - 2), MAC_ADDR_LEN);
5977 pRaCfg->length = htons(2);
5978 pRaCfg->status = htons(0);
5979 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
5980 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
5981 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
5983 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
5985 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_SET_ADDR2\n"));
5990 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_SET_ADDR2 is done !\n (ADDR2 = %2X:%2X:%2X:%2X:%2X:%2X)\n", pAdapter->ate.Addr2[0],
5991 pAdapter->ate.Addr2[1], pAdapter->ate.Addr2[2], pAdapter->ate.Addr2[3], pAdapter->ate.Addr2[4], pAdapter->ate.Addr2[5]));
5996 case RACFG_CMD_ATE_SET_ADDR3:
5998 ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_ATE_SET_ADDR3\n"));
6000 // Addr is an array of UCHAR,
6001 // so no need to perform endian swap.
6002 memcpy(pAdapter->ate.Addr3, (PUCHAR)(pRaCfg->data - 2), MAC_ADDR_LEN);
6005 pRaCfg->length = htons(2);
6006 pRaCfg->status = htons(0);
6007 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
6008 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
6009 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
6011 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
6013 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_SET_ADDR3\n"));
6018 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_SET_ADDR3 is done !\n (ADDR3 = %2X:%2X:%2X:%2X:%2X:%2X)\n", pAdapter->ate.Addr3[0],
6019 pAdapter->ate.Addr3[1], pAdapter->ate.Addr3[2], pAdapter->ate.Addr3[3], pAdapter->ate.Addr3[4], pAdapter->ate.Addr3[5]));
6024 case RACFG_CMD_ATE_SET_RATE:
6027 UCHAR str[LEN_OF_ARG];
6029 NdisZeroMemory(str, LEN_OF_ARG);
6031 ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_ATE_SET_RATE\n"));
6033 memcpy((PUCHAR)&value, (PUCHAR)&(pRaCfg->status), 2);
6034 value = ntohs(value);
6035 sprintf((PCHAR)str, "%d", value);
6036 Set_ATE_TX_MCS_Proc(pAdapter, str);
6039 pRaCfg->length = htons(2);
6040 pRaCfg->status = htons(0);
6041 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
6042 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
6043 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
6045 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
6047 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_SET_RATE\n"));
6052 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_SET_RATE is done !\n"));
6057 case RACFG_CMD_ATE_SET_TX_FRAME_LEN:
6060 UCHAR str[LEN_OF_ARG];
6062 NdisZeroMemory(str, LEN_OF_ARG);
6064 ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_ATE_SET_TX_FRAME_LEN\n"));
6066 memcpy((PUCHAR)&value, (PUCHAR)&(pRaCfg->status), 2);
6067 value = ntohs(value);
6068 sprintf((PCHAR)str, "%d", value);
6069 Set_ATE_TX_LENGTH_Proc(pAdapter, str);
6072 pRaCfg->length = htons(2);
6073 pRaCfg->status = htons(0);
6074 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
6075 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
6076 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
6078 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
6080 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_SET_TX_FRAME_LEN\n"));
6085 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_SET_TX_FRAME_LEN is done !\n"));
6090 case RACFG_CMD_ATE_SET_TX_FRAME_COUNT:
6093 UCHAR str[LEN_OF_ARG];
6095 NdisZeroMemory(str, LEN_OF_ARG);
6097 ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_ATE_SET_TX_FRAME_COUNT\n"));
6099 memcpy((PUCHAR)&value, (PUCHAR)&(pRaCfg->status), 2);
6100 value = ntohs(value);
6102 sprintf((PCHAR)str, "%d", value);
6103 Set_ATE_TX_COUNT_Proc(pAdapter, str);
6107 pRaCfg->length = htons(2);
6108 pRaCfg->status = htons(0);
6109 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
6110 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
6111 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
6113 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
6115 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_SET_TX_FRAME_COUNT\n"));
6120 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_SET_TX_FRAME_COUNT is done !\n"));
6125 case RACFG_CMD_ATE_START_RX_FRAME:
6127 ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_RX_START\n"));
6129 Set_ATE_Proc(pAdapter, "RXFRAME");
6132 pRaCfg->length = htons(2);
6133 pRaCfg->status = htons(0);
6134 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
6135 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
6136 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
6138 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
6140 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_RX_START\n"));
6145 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_RX_START is done !\n"));
6152 ASSERT(pRaCfg != NULL);
6160 VOID BubbleSort(INT32 n, INT32 a[])
6164 for (k = n-1; k>0; k--)
6166 for (j = 0; j<k; j++)
6178 VOID CalNoiseLevel(PRTMP_ADAPTER pAd, UCHAR channel, INT32 RSSI[3][10])
6180 INT32 RSSI0, RSSI1, RSSI2;
6181 CHAR Rssi0Offset, Rssi1Offset, Rssi2Offset;
6182 UCHAR BbpR50Rssi0 = 0, BbpR51Rssi1 = 0, BbpR52Rssi2 = 0;
6183 UCHAR Org_BBP66value = 0, Org_BBP69value = 0, Org_BBP70value = 0, data = 0;
6184 USHORT LNA_Gain = 0;
6186 UCHAR Org_Channel = pAd->ate.Channel;
6187 USHORT GainValue = 0, OffsetValue = 0;
6189 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R66, &Org_BBP66value);
6190 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R69, &Org_BBP69value);
6191 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R70, &Org_BBP70value);
6193 //**********************************************************************
6194 // Read the value of LNA gain and Rssi offset
6195 //**********************************************************************
6196 RT28xx_EEPROM_READ16(pAd, EEPROM_LNA_OFFSET, GainValue);
6201 LNA_Gain = GainValue & 0x00FF;
6203 RT28xx_EEPROM_READ16(pAd, EEPROM_RSSI_BG_OFFSET, OffsetValue);
6204 Rssi0Offset = OffsetValue & 0x00FF;
6205 Rssi1Offset = (OffsetValue & 0xFF00) >> 8;
6206 RT28xx_EEPROM_READ16(pAd, (EEPROM_RSSI_BG_OFFSET + 2)/* 0x48 */, OffsetValue);
6207 Rssi2Offset = OffsetValue & 0x00FF;
6211 LNA_Gain = (GainValue & 0xFF00) >> 8;
6213 RT28xx_EEPROM_READ16(pAd, EEPROM_RSSI_A_OFFSET, OffsetValue);
6214 Rssi0Offset = OffsetValue & 0x00FF;
6215 Rssi1Offset = (OffsetValue & 0xFF00) >> 8;
6216 RT28xx_EEPROM_READ16(pAd, (EEPROM_RSSI_A_OFFSET + 2)/* 0x4C */, OffsetValue);
6217 Rssi2Offset = OffsetValue & 0x00FF;
6219 //**********************************************************************
6221 pAd->ate.Channel = channel;
6222 ATEAsicSwitchChannel(pAd);
6226 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R66, data);
6228 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R69, data);
6230 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R70, data);
6234 pAd->ate.bQARxStart = TRUE;
6235 Set_ATE_Proc(pAd, "RXFRAME");
6239 for (j = 0; j < 10; j++)
6241 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R50, &BbpR50Rssi0);
6242 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R51, &BbpR51Rssi1);
6243 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R52, &BbpR52Rssi2);
6248 if (BbpR50Rssi0 == 0)
6254 RSSI0 = (INT32)(-12 - BbpR50Rssi0 - LNA_Gain - Rssi0Offset);
6258 if ( pAd->Antenna.field.RxPath >= 2 ) // 2R
6261 if (BbpR51Rssi1 == 0)
6267 RSSI1 = (INT32)(-12 - BbpR51Rssi1 - LNA_Gain - Rssi1Offset);
6272 if ( pAd->Antenna.field.RxPath >= 3 ) // 3R
6275 if (BbpR52Rssi2 == 0)
6278 RSSI2 = (INT32)(-12 - BbpR52Rssi2 - LNA_Gain - Rssi2Offset);
6285 Set_ATE_Proc(pAd, "RXSTOP");
6289 BubbleSort(10, RSSI[0]); // 1R
6291 if ( pAd->Antenna.field.RxPath >= 2 ) // 2R
6293 BubbleSort(10, RSSI[1]);
6296 if ( pAd->Antenna.field.RxPath >= 3 ) // 3R
6298 BubbleSort(10, RSSI[2]);
6303 pAd->ate.Channel = Org_Channel;
6304 ATEAsicSwitchChannel(pAd);
6306 // Restore original value
6307 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R66, Org_BBP66value);
6308 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R69, Org_BBP69value);
6309 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R70, Org_BBP70value);
6314 BOOLEAN SyncTxRxConfig(PRTMP_ADAPTER pAd, USHORT offset, UCHAR value)
6316 UCHAR tmp = 0, bbp_data = 0;
6320 ATE_BBP_IO_READ8_BY_REG_ID(pAd, offset, &bbp_data);
6324 RTMP_BBP_IO_READ8_BY_REG_ID(pAd, offset, &bbp_data);
6328 ASSERT(bbp_data == value);
6333 /* Need to sync. tx configuration with legacy ATE. */
6334 tmp = (bbp_data & ((1 << 4) | (1 << 3))/* 0x18 */) >> 3;
6337 /* The BBP R1 bit[4:3] = 2 :: Both DACs will be used by QA. */
6340 pAd->ate.TxAntennaSel = 0;
6342 /* The BBP R1 bit[4:3] = 0 :: DAC 0 will be used by QA. */
6345 pAd->ate.TxAntennaSel = 1;
6347 /* The BBP R1 bit[4:3] = 1 :: DAC 1 will be used by QA. */
6350 pAd->ate.TxAntennaSel = 2;
6353 DBGPRINT(RT_DEBUG_TRACE, ("%s -- Sth. wrong! : return FALSE; \n", __FUNCTION__));
6356 break;/* case BBP_R1 */
6359 /* Need to sync. rx configuration with legacy ATE. */
6360 tmp = (bbp_data & ((1 << 1) | (1 << 0))/* 0x03 */);
6363 /* The BBP R3 bit[1:0] = 3 :: All ADCs will be used by QA. */
6366 pAd->ate.RxAntennaSel = 0;
6368 /* The BBP R3 bit[1:0] = 0 :: ADC 0 will be used by QA, */
6369 /* unless the BBP R3 bit[4:3] = 2 */
6372 pAd->ate.RxAntennaSel = 1;
6373 tmp = ((bbp_data & ((1 << 4) | (1 << 3))/* 0x03 */) >> 3);
6376 /* Default : All ADCs will be used by QA */
6377 pAd->ate.RxAntennaSel = 0;
6380 /* The BBP R3 bit[1:0] = 1 :: ADC 1 will be used by QA. */
6383 pAd->ate.RxAntennaSel = 2;
6385 /* The BBP R3 bit[1:0] = 2 :: ADC 2 will be used by QA. */
6388 pAd->ate.RxAntennaSel = 3;
6391 DBGPRINT(RT_DEBUG_ERROR, ("%s -- Impossible! : return FALSE; \n", __FUNCTION__));
6394 break;/* case BBP_R3 */
6397 DBGPRINT(RT_DEBUG_ERROR, ("%s -- Sth. wrong! : return FALSE; \n", __FUNCTION__));
6404 static VOID memcpy_exl(PRTMP_ADAPTER pAd, UCHAR *dst, UCHAR *src, ULONG len)
6411 pDst = (ULONG *) dst;
6412 pSrc = (ULONG *) src;
6414 for (i = 0 ; i < (len/4); i++)
6416 /* For alignment issue, we need a variable "Value". */
6417 memmove(&Value, pSrc, 4);
6418 Value = htonl(Value);
6419 memmove(pDst, &Value, 4);
6425 /* wish that it will never reach here */
6426 memmove(&Value, pSrc, (len % 4));
6427 Value = htonl(Value);
6428 memmove(pDst, &Value, (len % 4));
6432 static VOID memcpy_exs(PRTMP_ADAPTER pAd, UCHAR *dst, UCHAR *src, ULONG len)
6440 for (i = 0; i < (len/2); i++)
6442 memmove(pDst, pSrc, 2);
6443 *((USHORT *)pDst) = htons(*((USHORT *)pDst));
6450 memmove(pDst, pSrc, 1);
6454 static VOID RTMP_IO_READ_BULK(PRTMP_ADAPTER pAd, UCHAR *dst, UCHAR *src, UINT32 len)
6457 UINT32 *pDst, *pSrc;
6459 pDst = (UINT32 *) dst;
6460 pSrc = (UINT32 *) src;
6462 for (i = 0 ; i < (len/4); i++)
6464 RTMP_IO_READ32(pAd, (ULONG)pSrc, &Value);
6465 Value = htonl(Value);
6466 memmove(pDst, &Value, 4);
6473 INT Set_TxStop_Proc(
6474 IN PRTMP_ADAPTER pAd,
6477 ATEDBGPRINT(RT_DEBUG_TRACE,("Set_TxStop_Proc\n"));
6479 if (Set_ATE_Proc(pAd, "TXSTOP"))
6489 INT Set_RxStop_Proc(
6490 IN PRTMP_ADAPTER pAd,
6493 ATEDBGPRINT(RT_DEBUG_TRACE,("Set_RxStop_Proc\n"));
6495 if (Set_ATE_Proc(pAd, "RXSTOP"))
6504 #endif // RALINK_28xx_QA //
6505 #endif // RALINK_ATE //