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"
30 #define ATE_BBP_REG_NUM 168
31 UCHAR restore_BBP[ATE_BBP_REG_NUM]={0};
34 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
35 extern RTMP_RF_REGS RF2850RegTable[];
36 extern UCHAR NUM_OF_2850_CHNL;
39 extern UCHAR EpToQueue[];
40 extern VOID RTUSBRejectPendingPackets( IN PRTMP_ADAPTER pAd);
44 //2008/07/10:KH adds to support 3070 ATE<--
45 extern FREQUENCY_ITEM FreqItems3020[];
46 extern UCHAR NUM_OF_3020_CHNL;
47 //2008/07/10:KH adds to support 3070 ATE-->
50 static CHAR CCKRateTable[] = {0, 1, 2, 3, 8, 9, 10, 11, -1}; /* CCK Mode. */
51 static CHAR OFDMRateTable[] = {0, 1, 2, 3, 4, 5, 6, 7, -1}; /* OFDM Mode. */
52 static CHAR HTMIXRateTable[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, -1}; /* HT Mix Mode. */
55 IN PRTMP_ADAPTER pAd);
58 IN PRTMP_ADAPTER pAd);
60 static VOID RtmpDmaEnable(
64 static VOID BbpSoftReset(
65 IN PRTMP_ADAPTER pAd);
67 static VOID RtmpRfIoWrite(
68 IN PRTMP_ADAPTER pAd);
70 static INT ATESetUpFrame(
74 static INT ATETxPwrHandler(
78 static INT ATECmdHandler(
82 static int CheckMCSValid(
88 static VOID ATEWriteTxInfo(
90 IN PTXINFO_STRUC pTxInfo,
91 IN USHORT USBDMApktLen,
97 static VOID ATEWriteTxWI(
101 IN BOOLEAN InsTimestamp,
104 IN BOOLEAN NSeq, // HW new a sequence.
112 IN HTTRANSMIT_SETTING Transmit);
116 static VOID SetJapanFilter(
117 IN PRTMP_ADAPTER pAd);
119 /*=========================end of prototype=========================*/
123 static INT TxDmaBusy(
124 IN PRTMP_ADAPTER pAd)
127 USB_DMA_CFG_STRUC UsbCfg;
129 RTMP_IO_READ32(pAd, USB_DMA_CFG, &UsbCfg.word); // disable DMA
130 if (UsbCfg.field.TxBusy)
138 static INT RxDmaBusy(
139 IN PRTMP_ADAPTER pAd)
142 USB_DMA_CFG_STRUC UsbCfg;
144 RTMP_IO_READ32(pAd, USB_DMA_CFG, &UsbCfg.word); // disable DMA
145 if (UsbCfg.field.RxBusy)
153 static VOID RtmpDmaEnable(
154 IN PRTMP_ADAPTER pAd,
159 USB_DMA_CFG_STRUC UsbCfg;
161 value = Enable > 0 ? 1 : 0;
163 // check DMA is in busy mode.
165 while (TxDmaBusy(pAd) || RxDmaBusy(pAd))
172 //Why not to clear USB DMA TX path first ???
173 RTMP_IO_READ32(pAd, USB_DMA_CFG, &UsbCfg.word); // disable DMA
174 UsbCfg.field.TxBulkEn = value;
175 UsbCfg.field.RxBulkEn = value;
176 RTMP_IO_WRITE32(pAd, USB_DMA_CFG, UsbCfg.word); // abort all TX rings
183 static VOID BbpSoftReset(
184 IN PRTMP_ADAPTER pAd)
188 // Soft reset, set BBP R21 bit0=1->0
189 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R21, &BbpData);
190 BbpData |= 0x00000001; //set bit0=1
191 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R21, BbpData);
193 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R21, &BbpData);
194 BbpData &= ~(0x00000001); //set bit0=0
195 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R21, BbpData);
200 static VOID RtmpRfIoWrite(
201 IN PRTMP_ADAPTER pAd)
203 // Set RF value 1's set R3[bit2] = [0]
204 RTMP_RF_IO_WRITE32(pAd, pAd->LatchRfRegs.R1);
205 RTMP_RF_IO_WRITE32(pAd, pAd->LatchRfRegs.R2);
206 RTMP_RF_IO_WRITE32(pAd, (pAd->LatchRfRegs.R3 & (~0x04)));
207 RTMP_RF_IO_WRITE32(pAd, pAd->LatchRfRegs.R4);
211 // Set RF value 2's set R3[bit2] = [1]
212 RTMP_RF_IO_WRITE32(pAd, pAd->LatchRfRegs.R1);
213 RTMP_RF_IO_WRITE32(pAd, pAd->LatchRfRegs.R2);
214 RTMP_RF_IO_WRITE32(pAd, (pAd->LatchRfRegs.R3 | 0x04));
215 RTMP_RF_IO_WRITE32(pAd, pAd->LatchRfRegs.R4);
219 // Set RF value 3's set R3[bit2] = [0]
220 RTMP_RF_IO_WRITE32(pAd, pAd->LatchRfRegs.R1);
221 RTMP_RF_IO_WRITE32(pAd, pAd->LatchRfRegs.R2);
222 RTMP_RF_IO_WRITE32(pAd, (pAd->LatchRfRegs.R3 & (~0x04)));
223 RTMP_RF_IO_WRITE32(pAd, pAd->LatchRfRegs.R4);
228 static int CheckMCSValid(
238 pRateTab = CCKRateTable;
241 pRateTab = OFDMRateTable;
245 pRateTab = HTMIXRateTable;
248 ATEDBGPRINT(RT_DEBUG_ERROR, ("unrecognizable Tx Mode %d\n", Mode));
254 while(pRateTab[i] != -1)
256 if (pRateTab[i] == Mcs)
265 static INT ATETxPwrHandler(
266 IN PRTMP_ADAPTER pAd,
272 BOOLEAN bPowerReduce = FALSE;
276 #ifdef RALINK_28xx_QA
277 if ((pAd->ate.bQATxStart == TRUE) || (pAd->ate.bQARxStart == TRUE))
279 /* When QA is used for Tx, pAd->ate.TxPower0/1 and real tx power
280 ** are not synchronized.
283 pAd->ate.TxPower0 = pAd->LatchRfRegs.xxx;
284 pAd->ate.TxPower1 = pAd->LatchRfRegs.xxx;
289 #endif // RALINK_28xx_QA //
291 TxPower = index == 0 ? pAd->ate.TxPower0 : pAd->ate.TxPower1;
293 if (pAd->ate.Channel <= 14)
298 // R3, R4 can't large than 31 (0x24), 31 ~ 36 used by BBP 94
302 Bbp94 = BBPR94_DEFAULT + (UCHAR)(TxPower - 31);
304 else if (TxPower < 0)
307 // R3, R4 can't less than 0, -1 ~ -6 used by BBP 94
311 Bbp94 = BBPR94_DEFAULT + TxPower;
317 Bbp94 = BBPR94_DEFAULT;
320 ATEDBGPRINT(RT_DEBUG_TRACE, ("%s (TxPower=%d, R=%ld, BBP_R94=%d)\n", __func__, TxPower, R, Bbp94));
327 // R3, R4 can't large than 15 (0x0F)
331 else if (TxPower < 0)
334 // R3, R4 can't less than 0
337 ASSERT((TxPower >= -7));
338 R = (ULONG)(TxPower + 7);
347 ATEDBGPRINT(RT_DEBUG_TRACE, ("%s (TxPower=%d, R=%lu)\n", __func__, TxPower, R));
349 //2008/09/10:KH adds to support 3070 ATE TX Power tunning real time<--
355 RT30xxReadRFRegister(pAd, RF_R12, (PUCHAR)&RFValue);
356 RFValue = (RFValue & 0xE0) | TxPower;
357 RT30xxWriteRFRegister(pAd, RF_R12, (UCHAR)RFValue);
358 ATEDBGPRINT(RT_DEBUG_TRACE, ("3070 or 2070:%s (TxPower=%d, RFValue=%x)\n", __func__, TxPower, RFValue));
364 if (pAd->ate.Channel <= 14)
368 R = R << 9; // shift TX power control to correct RF(R3) register bit position
369 R |= (pAd->LatchRfRegs.R3 & 0xffffc1ff);
370 pAd->LatchRfRegs.R3 = R;
374 R = R << 6; // shift TX power control to correct RF(R4) register bit position
375 R |= (pAd->LatchRfRegs.R4 & 0xfffff83f);
376 pAd->LatchRfRegs.R4 = R;
381 if (bPowerReduce == FALSE)
385 R = (R << 10) | (1 << 9); // shift TX power control to correct RF(R3) register bit position
386 R |= (pAd->LatchRfRegs.R3 & 0xffffc1ff);
387 pAd->LatchRfRegs.R3 = R;
391 R = (R << 7) | (1 << 6); // shift TX power control to correct RF(R4) register bit position
392 R |= (pAd->LatchRfRegs.R4 & 0xfffff83f);
393 pAd->LatchRfRegs.R4 = R;
400 R = (R << 10); // shift TX power control to correct RF(R3) register bit position
401 R |= (pAd->LatchRfRegs.R3 & 0xffffc1ff);
403 /* Clear bit 9 of R3 to reduce 7dB. */
404 pAd->LatchRfRegs.R3 = (R & (~(1 << 9)));
408 R = (R << 7); // shift TX power control to correct RF(R4) register bit position
409 R |= (pAd->LatchRfRegs.R4 & 0xfffff83f);
411 /* Clear bit 6 of R4 to reduce 7dB. */
412 pAd->LatchRfRegs.R4 = (R & (~(1 << 6)));
418 //2008/09/10:KH adds to support 3070 ATE TX Power tunning real time-->
424 static INT ATETxPwrHandler(
425 IN PRTMP_ADAPTER pAd,
432 #ifdef RALINK_28xx_QA
433 if ((pAd->ate.bQATxStart == TRUE) || (pAd->ate.bQARxStart == TRUE))
435 // TODO: how to get current TxPower0/1 from pAd->LatchRfRegs ?
436 /* When QA is used for Tx, pAd->ate.TxPower0/1 and real tx power
437 ** are not synchronized.
440 pAd->ate.TxPower0 = pAd->LatchRfRegs.xxx;
441 pAd->ate.TxPower1 = pAd->LatchRfRegs.xxx;
446 #endif // RALINK_28xx_QA //
448 TxPower = index == 0 ? pAd->ate.TxPower0 : pAd->ate.TxPower1;
453 // R3, R4 can't large than 36 (0x24), 31 ~ 36 used by BBP 94
457 Bbp94 = BBPR94_DEFAULT + (UCHAR)(TxPower - 31);
459 else if (TxPower < 0)
462 // R3, R4 can't less than 0, -1 ~ -6 used by BBP 94
466 Bbp94 = BBPR94_DEFAULT + TxPower;
472 Bbp94 = BBPR94_DEFAULT;
475 ATEDBGPRINT(RT_DEBUG_TRACE, ("%s (TxPower=%d, R3=%ld, BBP_R94=%d)\n", __func__, TxPower, R, Bbp94));
477 if (pAd->ate.Channel <= 14)
481 R = R << 9; // shift TX power control to correct RF(R3) register bit position
482 R |= (pAd->LatchRfRegs.R3 & 0xffffc1ff);
483 pAd->LatchRfRegs.R3 = R;
487 R = R << 6; // shift TX power control to correct RF(R4) register bit position
488 R |= (pAd->LatchRfRegs.R4 & 0xfffff83f);
489 pAd->LatchRfRegs.R4 = R;
496 R = (R << 10) | (1 << 9); // shift TX power control to correct RF(R3) register bit position
497 R |= (pAd->LatchRfRegs.R3 & 0xffffc1ff);
498 pAd->LatchRfRegs.R3 = R;
502 R = (R << 7) | (1 << 6); // shift TX power control to correct RF(R4) register bit position
503 R |= (pAd->LatchRfRegs.R4 & 0xfffff83f);
504 pAd->LatchRfRegs.R4 = R;
515 ==========================================================================
517 Set ATE operation mode to
518 0. ATESTART = Start ATE Mode
519 1. ATESTOP = Stop ATE Mode
520 2. TXCONT = Continuous Transmit
521 3. TXCARR = Transmit Carrier
522 4. TXFRAME = Transmit Frames
523 5. RXFRAME = Receive Frames
524 #ifdef RALINK_28xx_QA
525 6. TXSTOP = Stop Any Type of Transmition
526 7. RXSTOP = Stop Receiving Frames
527 #endif // RALINK_28xx_QA //
529 TRUE if all parameters are OK, FALSE otherwise
530 ==========================================================================
534 /*=======================End of RT2860=======================*/
537 /*======================Start of RT2870======================*/
542 static INT ATECmdHandler(
543 IN PRTMP_ADAPTER pAd,
550 //NDIS_STATUS Status = NDIS_STATUS_SUCCESS;
555 ATEDBGPRINT(RT_DEBUG_TRACE, ("===> ATECmdHandler()\n"));
556 ATEAsicSwitchChannel(pAd);
557 /* AsicLockChannel() is empty function so far in fact */
558 AsicLockChannel(pAd, pAd->ate.Channel);
562 // Default value in BBP R22 is 0x0.
565 /* Enter ATE mode and set Tx/Rx Idle */
566 if (!strcmp(arg, "ATESTART"))
568 #ifdef CONFIG_STA_SUPPORT
570 #endif // CONFIG_STA_SUPPORT //
571 ATEDBGPRINT(RT_DEBUG_TRACE, ("ATE: ATESTART\n"));
573 netif_stop_queue(pAd->net_dev);
575 atemode = pAd->ate.Mode;
576 pAd->ate.Mode = ATE_START;
577 // pAd->ate.TxDoneCount = pAd->ate.TxCount;
579 RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &Value);
581 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, Value);
583 // Disable auto responder
584 RTMP_IO_READ32(pAd, AUTO_RSP_CFG, &temp);
585 temp = temp & 0xFFFFFFFE;
586 RTMP_IO_WRITE32(pAd, AUTO_RSP_CFG, temp);
588 // read MAC_SYS_CTRL and backup MAC_SYS_CTRL value.
589 RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &MacData);
590 // clean bit4 to stop continuous Tx production test.
591 MacData &= 0xFFFFFFEF;
592 // Stop continuous TX production test.
593 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, MacData);//disable or cancel pending irp first ???
595 if (atemode & ATE_TXCARR
597 || atemode & ATE_TXCONT
603 RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &temp);
604 temp = temp |0x00000002;
605 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, temp);
606 RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &temp);
607 temp = temp & ~(0x00000002);
608 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, temp);
609 //Restore All BBP Value
610 for(i=0;i<ATE_BBP_REG_NUM;i++)
611 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd,i,restore_BBP[i]);
614 // No Carrier Test set BBP R22 bit7=0, bit6=0, bit[5~0]=0x0
615 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R22, &BbpData);
616 BbpData &= 0xFFFFFF00; //clear bit7, bit6, bit[5~0]
617 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R22, BbpData);
619 else if (atemode & ATE_TXCARRSUPP)
623 RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &temp);
624 temp = temp |0x00000002;
625 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, temp);
626 RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &temp);
627 temp = temp & ~(0x00000002);
628 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, temp);
629 //Restore All BBP Value
630 for(i=0;i<ATE_BBP_REG_NUM;i++)
631 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd,i,restore_BBP[i]);
634 // No Cont. TX set BBP R22 bit7=0
635 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R22, &BbpData);
636 BbpData &= ~(1 << 7); //set bit7=0
637 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R22, BbpData);
639 // No Carrier Suppression set BBP R24 bit0=0
640 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R24, &BbpData);
641 BbpData &= 0xFFFFFFFE; //clear bit0
642 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R24, BbpData);
644 // We should free some resource which allocate when ATE_TXFRAME , ATE_STOP, and ATE_TXCONT.
645 // TODO:Should we free some resource which was allocated when LoopBack and ATE_STOP ?
646 else if ((atemode & ATE_TXFRAME) || (atemode == ATE_STOP))
648 if (atemode & ATE_TXCONT)
650 // Not Cont. TX anymore, so set BBP R22 bit7=0
651 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R22, &BbpData);
652 BbpData &= ~(1 << 7); //set bit7=0
653 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R22, BbpData);
656 RtmpDmaEnable(pAd, 0);
659 // It seems nothing to free,
660 // because we didn't allocate any resource when we entered ATE_TXFRAME mode latestly.
664 RtmpDmaEnable(pAd, 1);
667 RTUSBRejectPendingPackets(pAd);
668 RTUSBCleanUpDataBulkOutQueue(pAd);
670 #ifdef CONFIG_STA_SUPPORT
672 // It will be called in MlmeSuspend().
674 // Cancel pending timers
675 RTMPCancelTimer(&pAd->MlmeAux.AssocTimer, &Cancelled);
676 RTMPCancelTimer(&pAd->MlmeAux.ReassocTimer, &Cancelled);
677 RTMPCancelTimer(&pAd->MlmeAux.DisassocTimer, &Cancelled);
678 RTMPCancelTimer(&pAd->MlmeAux.AuthTimer, &Cancelled);
679 RTMPCancelTimer(&pAd->MlmeAux.BeaconTimer, &Cancelled);
680 RTMPCancelTimer(&pAd->MlmeAux.ScanTimer, &Cancelled);
681 #endif // CONFIG_STA_SUPPORT //
683 //RTUSBCleanUpMLMEWaitQueue(pAd); /* not used in RT28xx */
684 RTUSBCleanUpMLMEBulkOutQueue(pAd);
686 // Sometimes kernel will hang on, so we avoid calling MlmeSuspend().
687 // MlmeSuspend(pAd, TRUE);
688 //RTMPCancelTimer(&pAd->Mlme.PeriodicTimer, &Cancelled);
691 RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &Value);
693 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, Value);
696 RtmpDmaEnable(pAd, 0);
699 RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &Value);
701 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, Value);
703 // Make sure there are no pending bulk in/out IRPs before we go on.
704 /*=========================================================================*/
705 /* pAd->PendingRx is not of type atomic_t anymore in 28xx */
706 // while ((atomic_read(&pAd->PendingRx) > 0)) //pAd->BulkFlags != 0 wait bulk out finish
707 while ((pAd->PendingRx > 0)) //pAd->BulkFlags != 0 wait bulk out finish
710 ATE_RTUSBCancelPendingBulkInIRP(pAd);
712 NdisInterlockedDecrement(&pAd->PendingRx);
714 /* delay 0.5 seconds */
715 RTMPusecDelay(500000);
718 /* peter : why don't we have to get BulkOutLock first ? */
719 while (((pAd->BulkOutPending[0] == TRUE) ||
720 (pAd->BulkOutPending[1] == TRUE) ||
721 (pAd->BulkOutPending[2] == TRUE) ||
722 (pAd->BulkOutPending[3] == TRUE)) && (pAd->BulkFlags != 0)) //pAd->BulkFlags != 0 wait bulk out finish
726 /* pAd->BulkOutPending[y] will be set to FALSE in RTUSBCancelPendingBulkOutIRP(pAd) */
727 RTUSBCancelPendingBulkOutIRP(pAd);
730 /* we have enough time delay in RTUSBCancelPendingBulkOutIRP(pAd)
731 ** so this is not necessary
733 // RTMPusecDelay(500000);
736 /* pAd->PendingRx is not of type atomic_t anymore in 28xx */
737 // ASSERT(atomic_read(&pAd->PendingRx) == 0);
738 ASSERT(pAd->PendingRx == 0);
739 /*=========================================================================*/
741 // reset Rx statistics.
742 pAd->ate.LastSNR0 = 0;
743 pAd->ate.LastSNR1 = 0;
744 pAd->ate.LastRssi0 = 0;
745 pAd->ate.LastRssi1 = 0;
746 pAd->ate.LastRssi2 = 0;
747 pAd->ate.AvgRssi0 = 0;
748 pAd->ate.AvgRssi1 = 0;
749 pAd->ate.AvgRssi2 = 0;
750 pAd->ate.AvgRssi0X8 = 0;
751 pAd->ate.AvgRssi1X8 = 0;
752 pAd->ate.AvgRssi2X8 = 0;
753 pAd->ate.NumOfAvgRssiSample = 0;
755 #ifdef RALINK_28xx_QA
757 pAd->ate.bQATxStart = FALSE;
758 pAd->ate.bQARxStart = FALSE;
763 pAd->ate.OtherData = 0;
765 pAd->ate.OtherCount = 0;
779 pAd->ate.TxDoneCount = 0;
780 pAd->ate.TxStatus = 0; // task Tx status // 0 --> task is idle, 1 --> task is running
781 #endif // RALINK_28xx_QA //
787 #ifdef CONFIG_STA_SUPPORT
788 AsicDisableSync(pAd);
791 ** If we skip "LinkDown()", we should disable protection
792 ** to prevent from sending out RTS or CTS-to-self.
794 ATEDisableAsicProtect(pAd);
795 RTMPStationStop(pAd);
796 #endif // CONFIG_STA_SUPPORT //
798 // Default value in BBP R22 is 0x0.
800 RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &MacData);
802 // Clean bit4 to stop continuous Tx production test.
803 MacData &= 0xFFFFFFEF;
804 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R22, BbpData);
805 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, MacData);
806 //Clean ATE Bulk in/out counter and continue setup
807 InterlockedExchange(&pAd->BulkOutRemained, 0);
809 /* NdisAcquireSpinLock()/NdisReleaseSpinLock() need only one argument in RT28xx */
810 NdisAcquireSpinLock(&pAd->GenericLock);
811 pAd->ContinBulkOut = FALSE;
812 pAd->ContinBulkIn = FALSE;
813 NdisReleaseSpinLock(&pAd->GenericLock);
815 RTUSB_CLEAR_BULK_FLAG(pAd, fRTUSB_BULK_OUT_DATA_ATE);
817 else if (!strcmp(arg, "ATESTOP"))
819 ATEDBGPRINT(RT_DEBUG_TRACE, ("ATE : ATESTOP ===>\n"));
821 // Default value in BBP R22 is 0x0.
823 RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &MacData);//0820
824 // Clean bit4 to stop continuous Tx production test.
825 MacData &= 0xFFFFFFEF;
826 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R22, BbpData);
827 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, MacData); // recover the MAC_SYS_CTRL register back.
830 RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &Value);
832 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, Value);
836 ** Q : How to do the following I/O if Tx, Rx DMA is aborted ?
837 ** Ans : Bulk endpoints are aborted, while the control endpoint is not.
839 RtmpDmaEnable(pAd, 0);
842 RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &Value);
844 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, Value);
846 /* Make sure there are no pending bulk in/out IRPs before we go on. */
847 /*=========================================================================*/
848 // while ((atomic_read(&pAd->PendingRx) > 0)) //pAd->BulkFlags != 0 wait bulk out finish
849 while (pAd->PendingRx > 0)
852 ATE_RTUSBCancelPendingBulkInIRP(pAd);
854 // NdisInterlockedDecrement(&pAd->PendingRx);
857 RTMPusecDelay(500000);
860 while (((pAd->BulkOutPending[0] == TRUE) ||
861 (pAd->BulkOutPending[1] == TRUE) ||
862 (pAd->BulkOutPending[2] == TRUE) ||
863 (pAd->BulkOutPending[3] == TRUE)) && (pAd->BulkFlags != 0)) //pAd->BulkFlags != 0 wait bulk out finish
867 RTUSBCancelPendingBulkOutIRP(pAd);
870 RTMPusecDelay(500000);
873 // ASSERT(atomic_read(&pAd->PendingRx) == 0);
874 ASSERT(pAd->PendingRx == 0);
875 /*=========================================================================*/
877 /*=========================================================================*/
878 // InterlockedExchange(&pAd->PendingRx, 0);
880 pAd->NextRxBulkInReadIndex = 0; // Next Rx Read index
881 pAd->NextRxBulkInIndex = RX_RING_SIZE - 1; // Rx Bulk pointer
882 pAd->NextRxBulkInPosition = 0;
883 for (i = 0; i < (RX_RING_SIZE); i++)
885 PRX_CONTEXT pRxContext = &(pAd->RxContext[i]);
886 NdisZeroMemory(pRxContext->TransferBuffer, MAX_RXBULK_SIZE);
887 /* peter : why don't we have to get BulkInLock first ? */
888 pRxContext->pAd = pAd;
889 pRxContext->pIrp = NULL;
891 pRxContext->BulkInOffset = 0;
892 pRxContext->bRxHandling = FALSE;
894 pRxContext->InUse = FALSE;
895 pRxContext->IRPPending = FALSE;
896 pRxContext->Readable = FALSE;
897 // pRxContext->ReorderInUse = FALSE;
898 // pRxContext->ReadPosOffset = 0;
901 /*=========================================================================*/
903 /*=========================================================================*/
906 RTUSBCancelPendingBulkOutIRP(pAd);
909 /*=========================================================================*/
910 // Enable auto responder.
911 RTMP_IO_READ32(pAd, AUTO_RSP_CFG, &temp);
912 temp = temp | (0x01);
913 RTMP_IO_WRITE32(pAd, AUTO_RSP_CFG, temp);
915 /*================================================*/
916 AsicEnableBssSync(pAd);
919 /* In 2870 chipset, ATE_BBP_IO_READ8_BY_REG_ID() == RTMP_BBP_IO_READ8_BY_REG_ID() */
920 /* Both rt2870ap and rt2870sta use BbpSoftReset(pAd) to do BBP soft reset */
922 /*================================================*/
924 #ifdef CONFIG_STA_SUPPORT
925 // Set all state machines back IDLE
926 pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
927 pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
928 pAd->Mlme.AuthMachine.CurrState = AUTH_REQ_IDLE;
929 pAd->Mlme.AuthRspMachine.CurrState = AUTH_RSP_IDLE;
930 pAd->Mlme.SyncMachine.CurrState = SYNC_IDLE;
931 pAd->Mlme.ActMachine.CurrState = ACT_IDLE;
932 #endif // CONFIG_STA_SUPPORT //
935 // ===> refer to MlmeRestartStateMachine().
936 // When we entered ATE_START mode, PeriodicTimer was not cancelled.
937 // So we don't have to set it here.
939 //RTMPSetTimer(pAd, &pAd->Mlme.PeriodicTimer, MLME_TASK_EXEC_INTV);
941 ASSERT(pAd->CommonCfg.Channel != 0);
943 AsicSwitchChannel(pAd, pAd->CommonCfg.Channel, FALSE);
944 AsicLockChannel(pAd, pAd->CommonCfg.Channel);
947 #ifdef CONFIG_STA_SUPPORT
948 RTMPStationStart(pAd);
949 #endif // CONFIG_STA_SUPPORT //
952 // These two steps have been done when entering ATE_STOP mode.
954 // Clean ATE Bulk in/out counter and continue setup.
955 InterlockedExchange(&pAd->BulkOutRemained, 0);
956 NdisAcquireSpinLock(&pAd->GenericLock);
957 pAd->ContinBulkOut = FALSE;
958 pAd->ContinBulkIn = FALSE;
959 NdisReleaseSpinLock(&pAd->GenericLock);
961 /* Wait 50ms to prevent next URB to bulkout during HW reset. */
962 /* todo : remove this if not necessary */
965 pAd->ate.Mode = ATE_STOP;
968 RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &Value);
970 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, Value);
972 /*=========================================================================*/
973 /* restore RX_FILTR_CFG */
974 #ifdef CONFIG_STA_SUPPORT
975 /* restore RX_FILTR_CFG in order that QA maybe set it to 0x3 */
976 RTMP_IO_WRITE32(pAd, RX_FILTR_CFG, STANORMAL);
977 #endif // CONFIG_STA_SUPPORT //
978 /*=========================================================================*/
980 // Enable Tx, RX DMA.
981 RtmpDmaEnable(pAd, 1);
984 RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &Value);
986 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, Value);
988 // Wait 10ms to wait all of the bulk-in URBs to complete.
989 /* todo : remove this if not necessary */
992 // Everything is ready to start normal Tx/Rx.
993 RTUSBBulkReceive(pAd);
994 netif_start_queue(pAd->net_dev);
996 ATEDBGPRINT(RT_DEBUG_TRACE, ("<=== ATE : ATESTOP \n"));
998 else if (!strcmp(arg, "TXCARR")) // Tx Carrier
1000 ATEDBGPRINT(RT_DEBUG_TRACE, ("ATE: TXCARR\n"));
1001 pAd->ate.Mode |= ATE_TXCARR;
1004 for(i=0;i<ATE_BBP_REG_NUM;i++)
1006 //Record All BBP Value
1007 for(i=0;i<ATE_BBP_REG_NUM;i++)
1008 ATE_BBP_IO_READ8_BY_REG_ID(pAd,i,&restore_BBP[i]);
1012 // May be we need not to do this, because these have been done in ATE_START mode ???
1013 RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &Value);
1015 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, Value);
1017 // QA has done the following steps if it is used.
1018 if (pAd->ate.bQATxStart == FALSE)
1023 // Carrier Test set BBP R22 bit7=1, bit6=1, bit[5~0]=0x01
1024 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R22, &BbpData);
1025 BbpData &= 0xFFFFFF00; //clear bit7, bit6, bit[5~0]
1026 BbpData |= 0x000000C1; //set bit7=1, bit6=1, bit[5~0]=0x01
1027 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R22, BbpData);
1029 // set MAC_SYS_CTRL(0x1004) Continuous Tx Production Test (bit4) = 1
1030 RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &Value);
1031 Value = Value | 0x00000010;
1032 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, Value);
1035 else if (!strcmp(arg, "TXCONT")) // Tx Continue
1037 if (pAd->ate.bQATxStart == TRUE)
1039 /* set MAC_SYS_CTRL(0x1004) bit4(Continuous Tx Production Test)
1040 and bit2(MAC TX enable) back to zero. */
1041 RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &MacData);
1042 MacData &= 0xFFFFFFEB;
1043 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, MacData);
1045 // set BBP R22 bit7=0
1046 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R22, &BbpData);
1047 BbpData &= 0xFFFFFF7F; //set bit7=0
1048 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R22, BbpData);
1052 ** Step 1: Send 50 packets first then wait for a moment.
1053 ** Step 2: Send more 50 packet then start continue mode.
1055 ATEDBGPRINT(RT_DEBUG_TRACE, ("ATE: TXCONT\n"));
1058 for(i=0;i<ATE_BBP_REG_NUM;i++)
1060 //Record All BBP Value
1061 for(i=0;i<ATE_BBP_REG_NUM;i++)
1062 ATE_BBP_IO_READ8_BY_REG_ID(pAd,i,&restore_BBP[i]);
1065 // Step 1: send 50 packets first.
1066 pAd->ate.Mode |= ATE_TXCONT;
1067 pAd->ate.TxCount = 50;
1068 pAd->ate.TxDoneCount = 0;
1073 // Abort Tx, RX DMA.
1074 RtmpDmaEnable(pAd, 0);
1077 /* Only needed if we have to send some normal frames. */
1078 SetJapanFilter(pAd);
1080 // Setup frame format.
1081 ATESetUpFrame(pAd, 0);
1084 RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &Value);
1086 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, Value);
1089 RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &Value);
1091 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, Value);
1093 // Start Tx, RX DMA.
1094 RtmpDmaEnable(pAd, 1);
1096 InterlockedExchange(&pAd->BulkOutRemained, pAd->ate.TxCount);
1098 #ifdef RALINK_28xx_QA
1099 if (pAd->ate.bQATxStart == TRUE)
1101 pAd->ate.TxStatus = 1;
1102 //pAd->ate.Repeat = 0;
1104 #endif // RALINK_28xx_QA //
1106 NdisAcquireSpinLock(&pAd->GenericLock);//0820
1107 pAd->ContinBulkOut = FALSE;
1108 NdisReleaseSpinLock(&pAd->GenericLock);
1110 RTUSB_SET_BULK_FLAG(pAd, fRTUSB_BULK_OUT_DATA_ATE);
1113 RTUSBKickBulkOut(pAd);
1115 /* To make sure all the 50 frames have been bulk out before executing step 2 */
1116 while (atomic_read(&pAd->BulkOutRemained) > 0)
1118 RTMPusecDelay(5000);
1121 // Step 2: send more 50 packets then start continue mode.
1122 // Abort Tx, RX DMA.
1123 RtmpDmaEnable(pAd, 0);
1125 // Cont. TX set BBP R22 bit7=1
1126 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R22, &BbpData);
1127 BbpData |= 0x00000080; //set bit7=1
1128 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R22, BbpData);
1130 pAd->ate.TxCount = 50;
1131 pAd->ate.TxDoneCount = 0;
1133 SetJapanFilter(pAd);
1135 // Setup frame format.
1136 ATESetUpFrame(pAd, 0);
1139 RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &Value);
1141 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, Value);
1144 RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &Value);
1147 // Start Tx, RX DMA.
1148 RtmpDmaEnable(pAd, 1);
1150 InterlockedExchange(&pAd->BulkOutRemained, pAd->ate.TxCount);
1152 #ifdef RALINK_28xx_QA
1153 if (pAd->ate.bQATxStart == TRUE)
1155 pAd->ate.TxStatus = 1;
1156 //pAd->ate.Repeat = 0;
1158 #endif // RALINK_28xx_QA //
1160 NdisAcquireSpinLock(&pAd->GenericLock);//0820
1161 pAd->ContinBulkOut = FALSE;
1162 NdisReleaseSpinLock(&pAd->GenericLock);
1164 RTUSB_SET_BULK_FLAG(pAd, fRTUSB_BULK_OUT_DATA_ATE);
1166 RTUSBKickBulkOut(pAd);
1171 while (atomic_read(&pAd->BulkOutRemained) > 0)
1173 RTMPusecDelay(5000);
1177 // Set MAC_SYS_CTRL(0x1004) Continuous Tx Production Test (bit4) = 1.
1178 RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &MacData);
1179 MacData |= 0x00000010;
1180 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, MacData);
1182 else if (!strcmp(arg, "TXFRAME")) // Tx Frames
1184 ATEDBGPRINT(RT_DEBUG_TRACE, ("ATE: TXFRAME(Count=0x%08x)\n", pAd->ate.TxCount));
1185 pAd->ate.Mode |= ATE_TXFRAME;
1190 // Default value in BBP R22 is 0x0.
1193 RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &MacData);
1195 // Clean bit4 to stop continuous Tx production test.
1196 MacData &= 0xFFFFFFEF;
1198 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R22, BbpData);
1199 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, MacData);
1201 #ifdef RALINK_28xx_QA
1202 // add this for LoopBack mode
1203 if (pAd->ate.bQARxStart == FALSE)
1206 RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &Value);
1208 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, Value);
1211 if (pAd->ate.bQATxStart == TRUE)
1213 pAd->ate.TxStatus = 1;
1214 //pAd->ate.Repeat = 0;
1218 RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &Value);
1220 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, Value);
1221 #endif // RALINK_28xx_QA //
1224 RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &Value);
1226 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, Value);
1228 SetJapanFilter(pAd);
1230 // Abort Tx, RX DMA.
1231 RtmpDmaEnable(pAd, 0);
1233 pAd->ate.TxDoneCount = 0;
1235 // Setup frame format
1236 ATESetUpFrame(pAd, 0);
1238 // Start Tx, RX DMA.
1239 RtmpDmaEnable(pAd, 1);
1241 // Check count is continuous or not yet.
1243 // Due to the type mismatch between "pAd->BulkOutRemained"(atomic_t) and "pAd->ate.TxCount"(UINT32)
1245 if (pAd->ate.TxCount == 0)
1247 InterlockedExchange(&pAd->BulkOutRemained, 0);
1251 InterlockedExchange(&pAd->BulkOutRemained, pAd->ate.TxCount);
1253 ATEDBGPRINT(RT_DEBUG_TRACE, ("bulk out count = %d\n", atomic_read(&pAd->BulkOutRemained)));
1254 ASSERT((atomic_read(&pAd->BulkOutRemained) >= 0));
1256 if (atomic_read(&pAd->BulkOutRemained) == 0)
1258 ATEDBGPRINT(RT_DEBUG_TRACE, ("Send packet countinuously\n"));
1260 /* In 28xx, NdisAcquireSpinLock() == spin_lock_bh() */
1261 /* NdisAcquireSpinLock only need one argument in 28xx. */
1262 NdisAcquireSpinLock(&pAd->GenericLock);
1263 pAd->ContinBulkOut = TRUE;
1264 NdisReleaseSpinLock(&pAd->GenericLock);
1266 /* In 28xx, BULK_OUT_LOCK() == spin_lock_irqsave() */
1267 BULK_OUT_LOCK(&pAd->BulkOutLock[0], IrqFlags);// peter : NdisAcquireSpinLock ==> BULK_OUT_LOCK
1268 pAd->BulkOutPending[0] = FALSE;
1269 BULK_OUT_UNLOCK(&pAd->BulkOutLock[0], IrqFlags);// peter : NdisAcquireSpinLock ==> BULK_OUT_LOCK
1273 ATEDBGPRINT(RT_DEBUG_TRACE, ("Send packets depend on counter\n"));
1275 NdisAcquireSpinLock(&pAd->GenericLock);
1276 pAd->ContinBulkOut = FALSE;
1277 NdisReleaseSpinLock(&pAd->GenericLock);
1279 BULK_OUT_LOCK(&pAd->BulkOutLock[0], IrqFlags);
1280 pAd->BulkOutPending[0] = FALSE;
1281 BULK_OUT_UNLOCK(&pAd->BulkOutLock[0], IrqFlags);
1284 RTUSB_SET_BULK_FLAG(pAd, fRTUSB_BULK_OUT_DATA_ATE);
1287 RTUSBKickBulkOut(pAd);
1289 #ifdef RALINK_28xx_QA
1290 else if (!strcmp(arg, "TXSTOP")) //Enter ATE mode and set Tx/Rx Idle
1292 ATEDBGPRINT(RT_DEBUG_TRACE, ("ATE: TXSTOP\n"));
1294 atemode = pAd->ate.Mode;
1295 pAd->ate.Mode &= ATE_TXSTOP;
1296 pAd->ate.bQATxStart = FALSE;
1297 // pAd->ate.TxDoneCount = pAd->ate.TxCount;
1299 /*=========================================================================*/
1300 if (atemode & ATE_TXCARR)
1302 // No Carrier Test set BBP R22 bit7=0, bit6=0, bit[5~0]=0x0
1303 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R22, &BbpData);
1304 BbpData &= 0xFFFFFF00; //clear bit7, bit6, bit[5~0]
1305 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R22, BbpData);
1307 else if (atemode & ATE_TXCARRSUPP)
1309 // No Cont. TX set BBP R22 bit7=0
1310 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R22, &BbpData);
1311 BbpData &= ~(1 << 7); //set bit7=0
1312 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R22, BbpData);
1314 // No Carrier Suppression set BBP R24 bit0=0
1315 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R24, &BbpData);
1316 BbpData &= 0xFFFFFFFE; //clear bit0
1317 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R24, BbpData);
1319 else if ((atemode & ATE_TXFRAME) || (atemode == ATE_STOP))
1321 if (atemode & ATE_TXCONT)
1323 // No Cont. TX set BBP R22 bit7=0
1324 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R22, &BbpData);
1325 BbpData &= ~(1 << 7); //set bit7=0
1326 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R22, BbpData);
1330 /*=========================================================================*/
1331 RTUSBRejectPendingPackets(pAd);
1332 RTUSBCleanUpDataBulkOutQueue(pAd);
1334 /* not used in RT28xx */
1335 //RTUSBCleanUpMLMEWaitQueue(pAd);
1336 /* empty function so far */
1337 RTUSBCleanUpMLMEBulkOutQueue(pAd);
1338 /*=========================================================================*/
1339 // Abort Tx, RX DMA.
1340 RtmpDmaEnable(pAd, 0);
1341 /*=========================================================================*/
1343 /* In 28xx, pAd->PendingRx is not of type atomic_t anymore */
1344 // while ((atomic_read(&pAd->PendingRx) > 0)) //pAd->BulkFlags != 0 wait bulk out finish
1345 /* peter todo : BulkInLock */
1346 while (pAd->PendingRx > 0)
1349 ATE_RTUSBCancelPendingBulkInIRP(pAd);
1351 // NdisInterlockedDecrement(&pAd->PendingRx);
1354 RTMPusecDelay(500000);
1357 while (((pAd->BulkOutPending[0] == TRUE) ||
1358 (pAd->BulkOutPending[1] == TRUE) ||
1359 (pAd->BulkOutPending[2] == TRUE) ||
1360 (pAd->BulkOutPending[3] == TRUE)) && (pAd->BulkFlags != 0)) //pAd->BulkFlags != 0 wait bulk out finish
1364 RTUSBCancelPendingBulkOutIRP(pAd);
1367 RTMPusecDelay(500000);
1370 ASSERT(pAd->PendingRx == 0);
1371 /*=========================================================================*/
1372 // Enable Tx, Rx DMA.
1373 RtmpDmaEnable(pAd, 1);
1375 /* task Tx status : 0 --> task is idle, 1 --> task is running */
1376 pAd->ate.TxStatus = 0;
1382 RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &MacData);
1383 MacData &= (0xfffffffb);
1384 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, MacData);
1386 //Clean ATE Bulk in/out counter and continue setup
1387 InterlockedExchange(&pAd->BulkOutRemained, 0);
1389 pAd->ContinBulkOut = FALSE;
1391 else if (!strcmp(arg, "RXSTOP"))
1393 ATEDBGPRINT(RT_DEBUG_TRACE, ("ATE: RXSTOP\n"));
1394 atemode = pAd->ate.Mode;
1397 RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &Value);
1399 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, Value);
1401 pAd->ate.Mode &= ATE_RXSTOP;
1402 pAd->ate.bQARxStart = FALSE;
1403 // pAd->ate.TxDoneCount = pAd->ate.TxCount;
1405 /*=========================================================================*/
1406 RTUSBRejectPendingPackets(pAd);
1407 RTUSBCleanUpDataBulkOutQueue(pAd);
1409 /* not used in RT28xx */
1410 //RTUSBCleanUpMLMEWaitQueue(pAd);
1411 RTUSBCleanUpMLMEBulkOutQueue(pAd);
1412 /*=========================================================================*/
1414 // Abort Tx, RX DMA.
1415 RtmpDmaEnable(pAd, 0);
1416 /*=========================================================================*/
1417 // while ((atomic_read(&pAd->PendingRx) > 0))
1418 while (pAd->PendingRx > 0)
1421 ATE_RTUSBCancelPendingBulkInIRP(pAd);
1423 // NdisInterlockedDecrement(&pAd->PendingRx);
1426 RTMPusecDelay(500000);
1429 while (((pAd->BulkOutPending[0] == TRUE) ||
1430 (pAd->BulkOutPending[1] == TRUE) ||
1431 (pAd->BulkOutPending[2] == TRUE) ||
1432 (pAd->BulkOutPending[3] == TRUE)) && (pAd->BulkFlags != 0)) //pAd->BulkFlags != 0 wait bulk out finish
1436 RTUSBCancelPendingBulkOutIRP(pAd);
1439 RTMPusecDelay(500000);
1442 ASSERT(pAd->PendingRx == 0);
1443 /*=========================================================================*/
1447 pAd->ContinBulkIn = FALSE;
1449 #endif // RALINK_28xx_QA //
1450 else if (!strcmp(arg, "RXFRAME")) // Rx Frames
1452 ATEDBGPRINT(RT_DEBUG_TRACE, ("ATE: RXFRAME\n"));
1454 // Disable Rx of MAC block
1455 RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &Value);
1457 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, Value);
1459 // Default value in BBP R22 is 0x0.
1462 RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &MacData);
1463 // Clean bit4 to stop continuous Tx production test.
1464 MacData &= 0xFFFFFFEF;
1466 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R22, BbpData);
1467 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, MacData);
1469 pAd->ate.Mode |= ATE_RXFRAME;
1471 // Abort Tx, RX DMA.
1472 RtmpDmaEnable(pAd, 0);
1474 // Disable TX of MAC block
1475 RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &Value);
1477 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, Value);
1480 for ( i = 0; i < (RX_RING_SIZE); i++)
1482 PRX_CONTEXT pRxContext = &(pAd->RxContext[i]);
1484 pRxContext->InUse = FALSE;
1485 pRxContext->IRPPending = FALSE;
1486 pRxContext->Readable = FALSE;
1489 // Get the urb from kernel back to driver.
1491 RTUSB_UNLINK_URB(pRxContext->pUrb);
1493 /* Sleep 200 microsecs to give cancellation time to work. */
1497 // InterlockedExchange(&pAd->PendingRx, 0);
1499 pAd->NextRxBulkInReadIndex = 0; // Next Rx Read index
1500 pAd->NextRxBulkInIndex = RX_RING_SIZE - 1; // Rx Bulk pointer
1501 pAd->NextRxBulkInPosition = 0;
1504 // read to clear counters
1505 RTUSBReadMACRegister(pAd, RX_STA_CNT0, &temp); //RX PHY & RX CRC count
1506 RTUSBReadMACRegister(pAd, RX_STA_CNT1, &temp); //RX PLCP error count & CCA false alarm count
1507 RTUSBReadMACRegister(pAd, RX_STA_CNT2, &temp); //RX FIFO overflow frame count & RX duplicated filtered frame count
1509 pAd->ContinBulkIn = TRUE;
1511 // Enable Tx, RX DMA.
1512 RtmpDmaEnable(pAd, 1);
1514 // Enable RX of MAC block
1515 RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &Value);
1517 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, Value);
1520 RTUSBBulkReceive(pAd);
1524 ATEDBGPRINT(RT_DEBUG_TRACE, ("ATE: Invalid arg!\n"));
1527 RTMPusecDelay(5000);
1529 ATEDBGPRINT(RT_DEBUG_TRACE, ("<=== ATECmdHandler()\n"));
1536 IN PRTMP_ADAPTER pAd,
1539 if (ATECmdHandler(pAd, arg))
1541 ATEDBGPRINT(RT_DEBUG_TRACE, ("Ralink: Set_ATE_Proc Success\n"));
1548 ATEDBGPRINT(RT_DEBUG_TRACE, ("Ralink: Set_ATE_Proc Failed\n"));
1554 ==========================================================================
1556 Set ATE ADDR1=DA for TxFrame(AP : To DS = 0 ; From DS = 1)
1558 Set ATE ADDR3=DA for TxFrame(STA : To DS = 1 ; From DS = 0)
1561 TRUE if all parameters are OK, FALSE otherwise
1562 ==========================================================================
1564 INT Set_ATE_DA_Proc(
1565 IN PRTMP_ADAPTER pAd,
1571 if(strlen(arg) != 17) //Mac address acceptable format 01:02:03:04:05:06 length 17
1574 for (i=0, value = rstrtok(arg, ":"); value; value = rstrtok(NULL, ":"))
1576 if((strlen(value) != 2) || (!isxdigit(*value)) || (!isxdigit(*(value+1))) )
1577 return FALSE; //Invalid
1580 #ifdef CONFIG_STA_SUPPORT
1581 AtoH(value, &pAd->ate.Addr3[i++], 1);
1582 #endif // CONFIG_STA_SUPPORT //
1586 return FALSE; //Invalid
1589 #ifdef CONFIG_STA_SUPPORT
1590 ATEDBGPRINT(RT_DEBUG_TRACE, ("Set_ATE_DA_Proc (DA = %2X:%2X:%2X:%2X:%2X:%2X)\n", pAd->ate.Addr3[0],
1591 pAd->ate.Addr3[1], pAd->ate.Addr3[2], pAd->ate.Addr3[3], pAd->ate.Addr3[4], pAd->ate.Addr3[5]));
1592 #endif // CONFIG_STA_SUPPORT //
1594 ATEDBGPRINT(RT_DEBUG_TRACE, ("Ralink: Set_ATE_DA_Proc Success\n"));
1600 ==========================================================================
1602 Set ATE ADDR3=SA for TxFrame(AP : To DS = 0 ; From DS = 1)
1604 Set ATE ADDR2=SA for TxFrame(STA : To DS = 1 ; From DS = 0)
1607 TRUE if all parameters are OK, FALSE otherwise
1608 ==========================================================================
1610 INT Set_ATE_SA_Proc(
1611 IN PRTMP_ADAPTER pAd,
1617 if(strlen(arg) != 17) //Mac address acceptable format 01:02:03:04:05:06 length 17
1620 for (i=0, value = rstrtok(arg, ":"); value; value = rstrtok(NULL, ":"))
1622 if((strlen(value) != 2) || (!isxdigit(*value)) || (!isxdigit(*(value+1))) )
1623 return FALSE; //Invalid
1626 #ifdef CONFIG_STA_SUPPORT
1627 AtoH(value, &pAd->ate.Addr2[i++], 1);
1628 #endif // CONFIG_STA_SUPPORT //
1632 return FALSE; //Invalid
1635 #ifdef CONFIG_STA_SUPPORT
1636 ATEDBGPRINT(RT_DEBUG_TRACE, ("Set_ATE_SA_Proc (SA = %2X:%2X:%2X:%2X:%2X:%2X)\n", pAd->ate.Addr2[0],
1637 pAd->ate.Addr2[1], pAd->ate.Addr2[2], pAd->ate.Addr2[3], pAd->ate.Addr2[4], pAd->ate.Addr2[5]));
1638 #endif // CONFIG_STA_SUPPORT //
1640 ATEDBGPRINT(RT_DEBUG_TRACE, ("Ralink: Set_ATE_SA_Proc Success\n"));
1646 ==========================================================================
1648 Set ATE ADDR2=BSSID for TxFrame(AP : To DS = 0 ; From DS = 1)
1650 Set ATE ADDR1=BSSID for TxFrame(STA : To DS = 1 ; From DS = 0)
1653 TRUE if all parameters are OK, FALSE otherwise
1654 ==========================================================================
1656 INT Set_ATE_BSSID_Proc(
1657 IN PRTMP_ADAPTER pAd,
1663 if(strlen(arg) != 17) //Mac address acceptable format 01:02:03:04:05:06 length 17
1666 for (i=0, value = rstrtok(arg, ":"); value; value = rstrtok(NULL, ":"))
1668 if((strlen(value) != 2) || (!isxdigit(*value)) || (!isxdigit(*(value+1))) )
1669 return FALSE; //Invalid
1672 #ifdef CONFIG_STA_SUPPORT
1673 AtoH(value, &pAd->ate.Addr1[i++], 1);
1674 #endif // CONFIG_STA_SUPPORT //
1678 return FALSE; //Invalid
1681 #ifdef CONFIG_STA_SUPPORT
1682 ATEDBGPRINT(RT_DEBUG_TRACE, ("Set_ATE_BSSID_Proc (BSSID = %2X:%2X:%2X:%2X:%2X:%2X)\n", pAd->ate.Addr1[0],
1683 pAd->ate.Addr1[1], pAd->ate.Addr1[2], pAd->ate.Addr1[3], pAd->ate.Addr1[4], pAd->ate.Addr1[5]));
1684 #endif // CONFIG_STA_SUPPORT //
1686 ATEDBGPRINT(RT_DEBUG_TRACE, ("Ralink: Set_ATE_BSSID_Proc Success\n"));
1692 ==========================================================================
1697 TRUE if all parameters are OK, FALSE otherwise
1698 ==========================================================================
1700 INT Set_ATE_CHANNEL_Proc(
1701 IN PRTMP_ADAPTER pAd,
1706 channel = simple_strtol(arg, 0, 10);
1708 if ((channel < 1) || (channel > 216))// to allow A band channel : ((channel < 1) || (channel > 14))
1710 ATEDBGPRINT(RT_DEBUG_ERROR, ("Set_ATE_CHANNEL_Proc::Out of range, it should be in range of 1~14.\n"));
1713 pAd->ate.Channel = channel;
1715 ATEDBGPRINT(RT_DEBUG_TRACE, ("Set_ATE_CHANNEL_Proc (ATE Channel = %d)\n", pAd->ate.Channel));
1716 ATEDBGPRINT(RT_DEBUG_TRACE, ("Ralink: Set_ATE_CHANNEL_Proc Success\n"));
1723 ==========================================================================
1728 TRUE if all parameters are OK, FALSE otherwise
1729 ==========================================================================
1731 INT Set_ATE_TX_POWER0_Proc(
1732 IN PRTMP_ADAPTER pAd,
1737 TxPower = simple_strtol(arg, 0, 10);
1739 if (pAd->ate.Channel <= 14)
1741 if ((TxPower > 31) || (TxPower < 0))
1743 ATEDBGPRINT(RT_DEBUG_ERROR, ("Set_ATE_TX_POWER0_Proc::Out of range (Value=%d)\n", TxPower));
1749 if ((TxPower > 15) || (TxPower < -7))
1751 ATEDBGPRINT(RT_DEBUG_ERROR, ("Set_ATE_TX_POWER0_Proc::Out of range (Value=%d)\n", TxPower));
1756 pAd->ate.TxPower0 = TxPower;
1757 ATETxPwrHandler(pAd, 0);
1758 ATEDBGPRINT(RT_DEBUG_TRACE, ("Ralink: Set_ATE_TX_POWER0_Proc Success\n"));
1765 ==========================================================================
1770 TRUE if all parameters are OK, FALSE otherwise
1771 ==========================================================================
1773 INT Set_ATE_TX_POWER1_Proc(
1774 IN PRTMP_ADAPTER pAd,
1779 TxPower = simple_strtol(arg, 0, 10);
1781 if (pAd->ate.Channel <= 14)
1783 if ((TxPower > 31) || (TxPower < 0))
1785 ATEDBGPRINT(RT_DEBUG_ERROR, ("Set_ATE_TX_POWER1_Proc::Out of range (Value=%d)\n", TxPower));
1791 if ((TxPower > 15) || (TxPower < -7))
1793 ATEDBGPRINT(RT_DEBUG_ERROR, ("Set_ATE_TX_POWER1_Proc::Out of range (Value=%d)\n", TxPower));
1798 pAd->ate.TxPower1 = TxPower;
1799 ATETxPwrHandler(pAd, 1);
1800 ATEDBGPRINT(RT_DEBUG_TRACE, ("Ralink: Set_ATE_TX_POWER1_Proc Success\n"));
1807 ==========================================================================
1812 TRUE if all parameters are OK, FALSE otherwise
1813 ==========================================================================
1815 INT Set_ATE_TX_Antenna_Proc(
1816 IN PRTMP_ADAPTER pAd,
1821 value = simple_strtol(arg, 0, 10);
1823 if ((value > 2) || (value < 0))
1825 ATEDBGPRINT(RT_DEBUG_ERROR, ("Set_ATE_TX_Antenna_Proc::Out of range (Value=%d)\n", value));
1829 pAd->ate.TxAntennaSel = value;
1831 ATEDBGPRINT(RT_DEBUG_TRACE, ("Set_ATE_TX_Antenna_Proc (Antenna = %d)\n", pAd->ate.TxAntennaSel));
1832 ATEDBGPRINT(RT_DEBUG_TRACE,("Ralink: Set_ATE_TX_Antenna_Proc Success\n"));
1839 ==========================================================================
1844 TRUE if all parameters are OK, FALSE otherwise
1845 ==========================================================================
1847 INT Set_ATE_RX_Antenna_Proc(
1848 IN PRTMP_ADAPTER pAd,
1853 value = simple_strtol(arg, 0, 10);
1855 if ((value > 3) || (value < 0))
1857 ATEDBGPRINT(RT_DEBUG_ERROR, ("Set_ATE_RX_Antenna_Proc::Out of range (Value=%d)\n", value));
1861 pAd->ate.RxAntennaSel = value;
1863 ATEDBGPRINT(RT_DEBUG_TRACE, ("Set_ATE_RX_Antenna_Proc (Antenna = %d)\n", pAd->ate.RxAntennaSel));
1864 ATEDBGPRINT(RT_DEBUG_TRACE, ("Ralink: Set_ATE_RX_Antenna_Proc Success\n"));
1871 ==========================================================================
1873 Set ATE RF frequence offset
1876 TRUE if all parameters are OK, FALSE otherwise
1877 ==========================================================================
1879 INT Set_ATE_TX_FREQOFFSET_Proc(
1880 IN PRTMP_ADAPTER pAd,
1886 RFFreqOffset = simple_strtol(arg, 0, 10);
1888 if(RFFreqOffset >= 64)
1891 //2008/08/06: KH modified the limit of offset value from 65 to 95(0x5F)
1892 if(RFFreqOffset >= 95)
1895 ATEDBGPRINT(RT_DEBUG_ERROR, ("Set_ATE_TX_FREQOFFSET_Proc::Out of range, it should be in range of 0~63.\n"));
1899 pAd->ate.RFFreqOffset = RFFreqOffset;
1905 RT30xxReadRFRegister(pAd, RF_R23, (PUCHAR)&RFValue);
1906 //2008/08/06: KH modified "pAd->RFFreqOffset" to "pAd->ate.RFFreqOffset"
1907 RFValue = (RFValue & 0x80) | pAd->ate.RFFreqOffset;
1908 RT30xxWriteRFRegister(pAd, RF_R23, (UCHAR)RFValue);
1914 R4 = pAd->ate.RFFreqOffset << 15; // shift TX power control to correct RF register bit position
1915 R4 |= (pAd->LatchRfRegs.R4 & ((~0x001f8000)));
1916 pAd->LatchRfRegs.R4 = R4;
1920 ATEDBGPRINT(RT_DEBUG_TRACE, ("Set_ATE_TX_FREQOFFSET_Proc (RFFreqOffset = %d)\n", pAd->ate.RFFreqOffset));
1921 ATEDBGPRINT(RT_DEBUG_TRACE, ("Ralink: Set_ATE_TX_FREQOFFSET_Proc Success\n"));
1928 ==========================================================================
1933 TRUE if all parameters are OK, FALSE otherwise
1934 ==========================================================================
1936 INT Set_ATE_TX_BW_Proc(
1937 IN PRTMP_ADAPTER pAd,
1944 BBPCurrentBW = simple_strtol(arg, 0, 10);
1946 if(BBPCurrentBW == 0)
1947 pAd->ate.TxWI.BW = BW_20;
1949 pAd->ate.TxWI.BW = BW_40;
1951 if(pAd->ate.TxWI.BW == BW_20)
1953 if(pAd->ate.Channel <= 14)
1957 if (pAd->Tx20MPwrCfgGBand[i] != 0xffffffff)
1959 RTMP_IO_WRITE32(pAd, TX_PWR_CFG_0 + i*4, pAd->Tx20MPwrCfgGBand[i]);
1960 RTMPusecDelay(5000);
1968 if (pAd->Tx20MPwrCfgABand[i] != 0xffffffff)
1970 RTMP_IO_WRITE32(pAd, TX_PWR_CFG_0 + i*4, pAd->Tx20MPwrCfgABand[i]);
1971 RTMPusecDelay(5000);
1976 //Set BBP R4 bit[4:3]=0:0
1977 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &value);
1979 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, value);
1983 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R66, value);
1985 //to improve Rx sensitivity.
1987 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R68, value);
1990 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R69, value);
1993 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R70, value);
1996 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R73, value);
1998 // If Channel=14, Bandwidth=20M and Mode=CCK, Set BBP R4 bit5=1
1999 // (Japan filter coefficients)
2000 // This segment of code will only works when ATETXMODE and ATECHANNEL
2001 // were set to MODE_CCK and 14 respectively before ATETXBW is set to 0.
2002 //=====================================================================
2003 if (pAd->ate.Channel == 14)
2005 int TxMode = pAd->ate.TxWI.PHYMODE;
2006 if (TxMode == MODE_CCK)
2008 // when Channel==14 && Mode==CCK && BandWidth==20M, BBP R4 bit5=1
2009 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &value);
2010 value |= 0x20; //set bit5=1
2011 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, value);
2015 //=====================================================================
2016 // If bandwidth != 40M, RF Reg4 bit 21 = 0.
2020 RT30xxWriteRFRegister(pAd, RF_R24, (UCHAR) pAd->Mlme.CaliBW20RfR24);
2024 pAd->LatchRfRegs.R4 &= ~0x00200000;
2029 else if(pAd->ate.TxWI.BW == BW_40)
2031 if(pAd->ate.Channel <= 14)
2035 if (pAd->Tx40MPwrCfgGBand[i] != 0xffffffff)
2037 RTMP_IO_WRITE32(pAd, TX_PWR_CFG_0 + i*4, pAd->Tx40MPwrCfgGBand[i]);
2038 RTMPusecDelay(5000);
2046 if (pAd->Tx40MPwrCfgABand[i] != 0xffffffff)
2048 RTMP_IO_WRITE32(pAd, TX_PWR_CFG_0 + i*4, pAd->Tx40MPwrCfgABand[i]);
2049 RTMPusecDelay(5000);
2052 #ifdef DOT11_N_SUPPORT
2053 if ((pAd->ate.TxWI.PHYMODE >= MODE_HTMIX) && (pAd->ate.TxWI.MCS == 7))
2056 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R67, value);
2058 #endif // DOT11_N_SUPPORT //
2061 //Set BBP R4 bit[4:3]=1:0
2062 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &value);
2065 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, value);
2069 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R66, value);
2071 //to improve Rx sensitivity.
2073 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R68, value);
2076 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R69, value);
2079 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R70, value);
2082 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R73, value);
2084 // If bandwidth = 40M, set RF Reg4 bit 21 = 1.
2088 RT30xxWriteRFRegister(pAd, RF_R24, (UCHAR) pAd->Mlme.CaliBW40RfR24);
2092 pAd->LatchRfRegs.R4 |= 0x00200000;
2097 ATEDBGPRINT(RT_DEBUG_TRACE, ("Set_ATE_TX_BW_Proc (BBPCurrentBW = %d)\n", pAd->ate.TxWI.BW));
2098 ATEDBGPRINT(RT_DEBUG_TRACE, ("Ralink: Set_ATE_TX_BW_Proc Success\n"));
2105 ==========================================================================
2107 Set ATE Tx frame length
2110 TRUE if all parameters are OK, FALSE otherwise
2111 ==========================================================================
2113 INT Set_ATE_TX_LENGTH_Proc(
2114 IN PRTMP_ADAPTER pAd,
2117 pAd->ate.TxLength = simple_strtol(arg, 0, 10);
2119 if((pAd->ate.TxLength < 24) || (pAd->ate.TxLength > (MAX_FRAME_SIZE - 34/* == 2312 */)))
2121 pAd->ate.TxLength = (MAX_FRAME_SIZE - 34/* == 2312 */);
2122 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 */)));
2126 ATEDBGPRINT(RT_DEBUG_TRACE, ("Set_ATE_TX_LENGTH_Proc (TxLength = %d)\n", pAd->ate.TxLength));
2127 ATEDBGPRINT(RT_DEBUG_TRACE, ("Ralink: Set_ATE_TX_LENGTH_Proc Success\n"));
2134 ==========================================================================
2136 Set ATE Tx frame count
2139 TRUE if all parameters are OK, FALSE otherwise
2140 ==========================================================================
2142 INT Set_ATE_TX_COUNT_Proc(
2143 IN PRTMP_ADAPTER pAd,
2146 pAd->ate.TxCount = simple_strtol(arg, 0, 10);
2148 ATEDBGPRINT(RT_DEBUG_TRACE, ("Set_ATE_TX_COUNT_Proc (TxCount = %d)\n", pAd->ate.TxCount));
2149 ATEDBGPRINT(RT_DEBUG_TRACE, ("Ralink: Set_ATE_TX_COUNT_Proc Success\n"));
2156 ==========================================================================
2158 Set ATE Tx frame MCS
2161 TRUE if all parameters are OK, FALSE otherwise
2162 ==========================================================================
2164 INT Set_ATE_TX_MCS_Proc(
2165 IN PRTMP_ADAPTER pAd,
2171 MCS = simple_strtol(arg, 0, 10);
2172 result = CheckMCSValid(pAd->ate.TxWI.PHYMODE, MCS);
2176 pAd->ate.TxWI.MCS = (UCHAR)MCS;
2180 ATEDBGPRINT(RT_DEBUG_ERROR, ("Set_ATE_TX_MCS_Proc::Out of range, refer to rate table.\n"));
2184 ATEDBGPRINT(RT_DEBUG_TRACE, ("Set_ATE_TX_MCS_Proc (MCS = %d)\n", pAd->ate.TxWI.MCS));
2185 ATEDBGPRINT(RT_DEBUG_TRACE, ("Ralink: Set_ATE_TX_MCS_Proc Success\n"));
2192 ==========================================================================
2194 Set ATE Tx frame Mode
2198 3: MODE_HTGREENFIELD
2201 TRUE if all parameters are OK, FALSE otherwise
2202 ==========================================================================
2204 INT Set_ATE_TX_MODE_Proc(
2205 IN PRTMP_ADAPTER pAd,
2208 pAd->ate.TxWI.PHYMODE = simple_strtol(arg, 0, 10);
2210 if(pAd->ate.TxWI.PHYMODE > 3)
2212 pAd->ate.TxWI.PHYMODE = 0;
2213 ATEDBGPRINT(RT_DEBUG_ERROR, ("Set_ATE_TX_MODE_Proc::Out of range. it should be in range of 0~3\n"));
2214 ATEDBGPRINT(RT_DEBUG_ERROR, ("0: CCK, 1: OFDM, 2: HT_MIX, 3: HT_GREEN_FIELD.\n"));
2218 ATEDBGPRINT(RT_DEBUG_TRACE, ("Set_ATE_TX_MODE_Proc (TxMode = %d)\n", pAd->ate.TxWI.PHYMODE));
2219 ATEDBGPRINT(RT_DEBUG_TRACE, ("Ralink: Set_ATE_TX_MODE_Proc Success\n"));
2226 ==========================================================================
2231 TRUE if all parameters are OK, FALSE otherwise
2232 ==========================================================================
2234 INT Set_ATE_TX_GI_Proc(
2235 IN PRTMP_ADAPTER pAd,
2238 pAd->ate.TxWI.ShortGI = simple_strtol(arg, 0, 10);
2240 if(pAd->ate.TxWI.ShortGI > 1)
2242 pAd->ate.TxWI.ShortGI = 0;
2243 ATEDBGPRINT(RT_DEBUG_ERROR, ("Set_ATE_TX_GI_Proc::Out of range\n"));
2247 ATEDBGPRINT(RT_DEBUG_TRACE, ("Set_ATE_TX_GI_Proc (GI = %d)\n", pAd->ate.TxWI.ShortGI));
2248 ATEDBGPRINT(RT_DEBUG_TRACE, ("Ralink: Set_ATE_TX_GI_Proc Success\n"));
2255 ==========================================================================
2257 ==========================================================================
2259 INT Set_ATE_RX_FER_Proc(
2260 IN PRTMP_ADAPTER pAd,
2263 pAd->ate.bRxFer = simple_strtol(arg, 0, 10);
2265 if (pAd->ate.bRxFer == 1)
2267 pAd->ate.RxCntPerSec = 0;
2268 pAd->ate.RxTotalCnt = 0;
2271 ATEDBGPRINT(RT_DEBUG_TRACE, ("Set_ATE_RX_FER_Proc (bRxFer = %d)\n", pAd->ate.bRxFer));
2272 ATEDBGPRINT(RT_DEBUG_TRACE, ("Ralink: Set_ATE_RX_FER_Proc Success\n"));
2278 INT Set_ATE_Read_RF_Proc(
2279 IN PRTMP_ADAPTER pAd,
2283 //2008/07/10:KH add to support RT30xx ATE<--
2286 /* modify by WY for Read RF Reg. error */
2289 for (index = 0; index < 32; index++)
2291 RT30xxReadRFRegister(pAd, index, (PUCHAR)&RFValue);
2292 printk("R%d=%d\n",index,RFValue);
2296 //2008/07/10:KH add to support RT30xx ATE-->
2299 ate_print(KERN_EMERG "R1 = %lx\n", pAd->LatchRfRegs.R1);
2300 ate_print(KERN_EMERG "R2 = %lx\n", pAd->LatchRfRegs.R2);
2301 ate_print(KERN_EMERG "R3 = %lx\n", pAd->LatchRfRegs.R3);
2302 ate_print(KERN_EMERG "R4 = %lx\n", pAd->LatchRfRegs.R4);
2307 INT Set_ATE_Write_RF1_Proc(
2308 IN PRTMP_ADAPTER pAd,
2312 //2008/07/10:KH add to support 3070 ATE<--
2315 printk("Warning!! RT30xx Don't Support\n");
2320 //2008/07/10:KH add to support 3070 ATE-->
2323 UINT32 value = simple_strtol(arg, 0, 16);
2325 pAd->LatchRfRegs.R1 = value;
2332 INT Set_ATE_Write_RF2_Proc(
2333 IN PRTMP_ADAPTER pAd,
2337 //2008/07/10:KH add to support 3070 ATE<--
2340 printk("Warning!! RT30xx Don't Support\n");
2345 //2008/07/10:KH add to support 3070 ATE-->
2348 UINT32 value = simple_strtol(arg, 0, 16);
2350 pAd->LatchRfRegs.R2 = value;
2356 INT Set_ATE_Write_RF3_Proc(
2357 IN PRTMP_ADAPTER pAd,
2361 //2008/07/10:KH add to support 3070 ATE<--
2364 printk("Warning!! RT30xx Don't Support\n");
2369 //2008/07/10:KH add to support 3070 ATE-->
2372 UINT32 value = simple_strtol(arg, 0, 16);
2374 pAd->LatchRfRegs.R3 = value;
2380 INT Set_ATE_Write_RF4_Proc(
2381 IN PRTMP_ADAPTER pAd,
2385 //2008/07/10:KH add to support 3070 ATE<--
2388 printk("Warning!! RT30xx Don't Support\n");
2393 //2008/07/10:KH add to support 3070 ATE-->
2396 UINT32 value = simple_strtol(arg, 0, 16);
2398 pAd->LatchRfRegs.R4 = value;
2404 //2008/07/10:KH add to support 3070 ATE<--
2405 INT SET_ATE_3070RF_Proc(
2406 IN PRTMP_ADAPTER pAd,
2414 printk("SET_ATE_3070RF_Proc=%s\n",arg);
2416 if ((value = strchr(this_char, ':')) != NULL)
2418 Reg= simple_strtol(this_char, 0, 16);
2419 RFValue= simple_strtol(value, 0, 16);
2420 printk("RF Reg[%d]=%d\n",Reg,RFValue);
2421 RT30xxWriteRFRegister(pAd, Reg,RFValue);
2424 printk("Warning!! Only 3070 Support\n");
2427 //2008/07/10:KH add to support 3070 ATE-->
2430 ==========================================================================
2432 Load and Write EEPROM from a binary file prepared in advance.
2435 TRUE if all parameters are OK, FALSE otherwise
2436 ==========================================================================
2438 INT Set_ATE_Load_E2P_Proc(
2439 IN PRTMP_ADAPTER pAd,
2442 BOOLEAN ret = FALSE;
2443 PUCHAR src = EEPROM_BIN_FILE_NAME;
2445 INT32 retval, orgfsuid, orgfsgid;
2447 USHORT WriteEEPROM[(EEPROM_SIZE/2)];
2448 UINT32 FileLength = 0;
2449 UINT32 value = simple_strtol(arg, 0, 10);
2451 ATEDBGPRINT(RT_DEBUG_ERROR, ("===> %s (value=%d)\n\n", __func__, value));
2455 /* zero the e2p buffer */
2456 NdisZeroMemory((PUCHAR)WriteEEPROM, EEPROM_SIZE);
2458 /* save uid and gid used for filesystem access.
2459 ** set user and group to 0 (root)
2461 orgfsuid = current->fsuid;
2462 orgfsgid = current->fsgid;
2464 current->fsuid = current->fsgid = 0;
2470 /* open the bin file */
2471 srcf = filp_open(src, O_RDONLY, 0);
2475 ate_print("%s - Error %ld opening %s\n", __func__, -PTR_ERR(srcf), src);
2479 /* the object must have a read method */
2480 if ((srcf->f_op == NULL) || (srcf->f_op->read == NULL))
2482 ate_print("%s - %s does not have a read method\n", __func__, src);
2486 /* read the firmware from the file *.bin */
2487 FileLength = srcf->f_op->read(srcf,
2488 (PUCHAR)WriteEEPROM,
2492 if (FileLength != EEPROM_SIZE)
2494 ate_print("%s: error file length (=%d) in e2p.bin\n",
2495 __func__, FileLength);
2500 /* write the content of .bin file to EEPROM */
2501 rt_ee_write_all(pAd, WriteEEPROM);
2507 /* close firmware file */
2514 retval = filp_close(srcf, NULL);
2517 ATEDBGPRINT(RT_DEBUG_ERROR, ("--> Error %d closing %s\n", -retval, src));
2524 current->fsuid = orgfsuid;
2525 current->fsgid = orgfsgid;
2527 ATEDBGPRINT(RT_DEBUG_ERROR, ("<=== %s (ret=%d)\n", __func__, ret));
2533 INT Set_ATE_Read_E2P_Proc(
2534 IN PRTMP_ADAPTER pAd,
2537 USHORT buffer[EEPROM_SIZE/2];
2541 rt_ee_read_all(pAd, (USHORT *)buffer);
2543 for (i = 0; i < (EEPROM_SIZE/2); i++)
2545 ate_print("%4.4x ", *p);
2546 if (((i+1) % 16) == 0)
2553 INT Set_ATE_Show_Proc(
2554 IN PRTMP_ADAPTER pAd,
2557 ate_print("Mode=%d\n", pAd->ate.Mode);
2558 ate_print("TxPower0=%d\n", pAd->ate.TxPower0);
2559 ate_print("TxPower1=%d\n", pAd->ate.TxPower1);
2560 ate_print("TxAntennaSel=%d\n", pAd->ate.TxAntennaSel);
2561 ate_print("RxAntennaSel=%d\n", pAd->ate.RxAntennaSel);
2562 ate_print("BBPCurrentBW=%d\n", pAd->ate.TxWI.BW);
2563 ate_print("GI=%d\n", pAd->ate.TxWI.ShortGI);
2564 ate_print("MCS=%d\n", pAd->ate.TxWI.MCS);
2565 ate_print("TxMode=%d\n", pAd->ate.TxWI.PHYMODE);
2566 ate_print("Addr1=%02x:%02x:%02x:%02x:%02x:%02x\n",
2567 pAd->ate.Addr1[0], pAd->ate.Addr1[1], pAd->ate.Addr1[2], pAd->ate.Addr1[3], pAd->ate.Addr1[4], pAd->ate.Addr1[5]);
2568 ate_print("Addr2=%02x:%02x:%02x:%02x:%02x:%02x\n",
2569 pAd->ate.Addr2[0], pAd->ate.Addr2[1], pAd->ate.Addr2[2], pAd->ate.Addr2[3], pAd->ate.Addr2[4], pAd->ate.Addr2[5]);
2570 ate_print("Addr3=%02x:%02x:%02x:%02x:%02x:%02x\n",
2571 pAd->ate.Addr3[0], pAd->ate.Addr3[1], pAd->ate.Addr3[2], pAd->ate.Addr3[3], pAd->ate.Addr3[4], pAd->ate.Addr3[5]);
2572 ate_print("Channel=%d\n", pAd->ate.Channel);
2573 ate_print("TxLength=%d\n", pAd->ate.TxLength);
2574 ate_print("TxCount=%u\n", pAd->ate.TxCount);
2575 ate_print("RFFreqOffset=%d\n", pAd->ate.RFFreqOffset);
2576 ate_print(KERN_EMERG "Set_ATE_Show_Proc Success\n");
2580 INT Set_ATE_Help_Proc(
2581 IN PRTMP_ADAPTER pAd,
2584 ate_print("ATE=ATESTART, ATESTOP, TXCONT, TXCARR, TXFRAME, RXFRAME\n");
2585 ate_print("ATEDA\n");
2586 ate_print("ATESA\n");
2587 ate_print("ATEBSSID\n");
2588 ate_print("ATECHANNEL, range:0~14(unless A band !)\n");
2589 ate_print("ATETXPOW0, set power level of antenna 1.\n");
2590 ate_print("ATETXPOW1, set power level of antenna 2.\n");
2591 ate_print("ATETXANT, set TX antenna. 0:all, 1:antenna one, 2:antenna two.\n");
2592 ate_print("ATERXANT, set RX antenna.0:all, 1:antenna one, 2:antenna two, 3:antenna three.\n");
2593 ate_print("ATETXFREQOFFSET, set frequency offset, range 0~63\n");
2594 ate_print("ATETXBW, set BandWidth, 0:20MHz, 1:40MHz.\n");
2595 ate_print("ATETXLEN, set Frame length, range 24~%d\n", (MAX_FRAME_SIZE - 34/* == 2312 */));
2596 ate_print("ATETXCNT, set how many frame going to transmit.\n");
2597 ate_print("ATETXMCS, set MCS, reference to rate table.\n");
2598 ate_print("ATETXMODE, set Mode 0:CCK, 1:OFDM, 2:HT-Mix, 3:GreenField, reference to rate table.\n");
2599 ate_print("ATETXGI, set GI interval, 0:Long, 1:Short\n");
2600 ate_print("ATERXFER, 0:disable Rx Frame error rate. 1:enable Rx Frame error rate.\n");
2601 ate_print("ATERRF, show all RF registers.\n");
2602 ate_print("ATEWRF1, set RF1 register.\n");
2603 ate_print("ATEWRF2, set RF2 register.\n");
2604 ate_print("ATEWRF3, set RF3 register.\n");
2605 ate_print("ATEWRF4, set RF4 register.\n");
2606 ate_print("ATELDE2P, load EEPROM from .bin file.\n");
2607 ate_print("ATERE2P, display all EEPROM content.\n");
2608 ate_print("ATESHOW, display all parameters of ATE.\n");
2609 ate_print("ATEHELP, online help.\n");
2615 ==========================================================================
2618 AsicSwitchChannel() dedicated for ATE.
2620 ==========================================================================
2622 VOID ATEAsicSwitchChannel(
2623 IN PRTMP_ADAPTER pAd)
2625 UINT32 R2 = 0, R3 = DEFAULT_RF_TX_POWER, R4 = 0, Value = 0;
2626 CHAR TxPwer = 0, TxPwer2 = 0;
2627 UCHAR index, BbpValue = 0, R66 = 0x30;
2628 RTMP_RF_REGS *RFRegTable;
2631 #ifdef RALINK_28xx_QA
2632 if ((pAd->ate.bQATxStart == TRUE) || (pAd->ate.bQARxStart == TRUE))
2634 if (pAd->ate.Channel != pAd->LatchRfRegs.Channel)
2636 pAd->ate.Channel = pAd->LatchRfRegs.Channel;
2641 #endif // RALINK_28xx_QA //
2642 Channel = pAd->ate.Channel;
2645 AsicAntennaSelect(pAd, Channel);
2647 // fill Tx power value
2648 TxPwer = pAd->ate.TxPower0;
2649 TxPwer2 = pAd->ate.TxPower1;
2651 //2008/07/10:KH add to support 3070 ATE<--
2653 // The RF programming sequence is difference between 3xxx and 2xxx
2654 // 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.
2655 if (IS_RT30xx(pAd) && ((pAd->RfIcType == RFIC_3020) ||
2656 (pAd->RfIcType == RFIC_3021) || (pAd->RfIcType == RFIC_3022) ||
2657 (pAd->RfIcType == RFIC_2020)))
2659 /* modify by WY for Read RF Reg. error */
2662 for (index = 0; index < NUM_OF_3020_CHNL; index++)
2664 if (Channel == FreqItems3020[index].Channel)
2666 // Programming channel parameters
2667 RT30xxWriteRFRegister(pAd, RF_R02, FreqItems3020[index].N);
2668 RT30xxWriteRFRegister(pAd, RF_R03, FreqItems3020[index].K);
2670 RT30xxReadRFRegister(pAd, RF_R06, (PUCHAR)&RFValue);
2671 RFValue = (RFValue & 0xFC) | FreqItems3020[index].R;
2672 RT30xxWriteRFRegister(pAd, RF_R06, (UCHAR)RFValue);
2675 RT30xxReadRFRegister(pAd, RF_R12, (PUCHAR)&RFValue);
2676 RFValue = (RFValue & 0xE0) | TxPwer;
2677 RT30xxWriteRFRegister(pAd, RF_R12, (UCHAR)RFValue);
2680 RT30xxReadRFRegister(pAd, RF_R23, (PUCHAR)&RFValue);
2681 //2008/08/06: KH modified "pAd->RFFreqOffset" to "pAd->ate.RFFreqOffset"
2682 RFValue = (RFValue & 0x80) | pAd->ate.RFFreqOffset;
2683 RT30xxWriteRFRegister(pAd, RF_R23, (UCHAR)RFValue);
2686 if (pAd->ate.TxWI.BW == BW_40)
2688 RFValue = pAd->Mlme.CaliBW40RfR24;
2689 //DISABLE_11N_CHECK(pAd);
2693 RFValue = pAd->Mlme.CaliBW20RfR24;
2695 RT30xxWriteRFRegister(pAd, RF_R24, (UCHAR)RFValue);
2698 RT30xxReadRFRegister(pAd, RF_R07, (PUCHAR)&RFValue);
2699 RFValue = RFValue | 0x1;
2700 RT30xxWriteRFRegister(pAd, RF_R07, (UCHAR)RFValue);
2702 // latch channel for future usage.
2703 pAd->LatchRfRegs.Channel = Channel;
2709 DBGPRINT(RT_DEBUG_TRACE, ("SwitchChannel#%d(RF=%d, Pwr0=%d, Pwr1=%d, %dT), N=0x%02X, K=0x%02X, R=0x%02X\n",
2714 pAd->Antenna.field.TxPath,
2715 FreqItems3020[index].N,
2716 FreqItems3020[index].K,
2717 FreqItems3020[index].R));
2720 //2008/07/10:KH add to support 3070 ATE-->
2723 RFRegTable = RF2850RegTable;
2725 switch (pAd->RfIcType)
2727 /* But only 2850 and 2750 support 5.5GHz band... */
2733 for (index = 0; index < NUM_OF_2850_CHNL; index++)
2735 if (Channel == RFRegTable[index].Channel)
2737 R2 = RFRegTable[index].R2;
2738 if (pAd->Antenna.field.TxPath == 1)
2740 R2 |= 0x4000; // If TXpath is 1, bit 14 = 1;
2743 if (pAd->Antenna.field.RxPath == 2)
2745 switch (pAd->ate.RxAntennaSel)
2749 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R3, &BbpValue);
2752 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, BbpValue);
2756 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R3, &BbpValue);
2759 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, BbpValue);
2763 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R3, &BbpValue);
2765 /* Only enable two Antenna to receive. */
2767 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, BbpValue);
2771 else if (pAd->Antenna.field.RxPath == 1)
2773 R2 |= 0x20040; // write 1 to off RxPath
2776 if (pAd->Antenna.field.TxPath == 2)
2778 if (pAd->ate.TxAntennaSel == 1)
2780 R2 |= 0x4000; // If TX Antenna select is 1 , bit 14 = 1; Disable Ant 2
2781 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R1, &BbpValue);
2782 BbpValue &= 0xE7; //11100111B
2783 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R1, BbpValue);
2785 else if (pAd->ate.TxAntennaSel == 2)
2787 R2 |= 0x8000; // If TX Antenna select is 2 , bit 15 = 1; Disable Ant 1
2788 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R1, &BbpValue);
2791 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R1, BbpValue);
2795 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R1, &BbpValue);
2798 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R1, BbpValue);
2801 if (pAd->Antenna.field.RxPath == 3)
2803 switch (pAd->ate.RxAntennaSel)
2807 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R3, &BbpValue);
2810 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, BbpValue);
2814 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R3, &BbpValue);
2817 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, BbpValue);
2821 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R3, &BbpValue);
2824 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, BbpValue);
2827 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R3, &BbpValue);
2830 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, BbpValue);
2837 // initialize R3, R4
2838 R3 = (RFRegTable[index].R3 & 0xffffc1ff);
2839 R4 = (RFRegTable[index].R4 & (~0x001f87c0)) | (pAd->ate.RFFreqOffset << 15);
2841 // According the Rory's suggestion to solve the middle range issue.
2842 // 5.5G band power range: 0xF9~0X0F, TX0 Reg3 bit9/TX1 Reg4 bit6="0" means the TX power reduce 7dB
2844 if ((TxPwer >= -7) && (TxPwer < 0))
2846 TxPwer = (7+TxPwer);
2847 TxPwer = (TxPwer > 0xF) ? (0xF) : (TxPwer);
2848 R3 |= (TxPwer << 10);
2849 ATEDBGPRINT(RT_DEBUG_TRACE, ("ATEAsicSwitchChannel: TxPwer=%d \n", TxPwer));
2853 TxPwer = (TxPwer > 0xF) ? (0xF) : (TxPwer);
2854 R3 |= (TxPwer << 10) | (1 << 9);
2858 if ((TxPwer2 >= -7) && (TxPwer2 < 0))
2860 TxPwer2 = (7+TxPwer2);
2861 TxPwer2 = (TxPwer2 > 0xF) ? (0xF) : (TxPwer2);
2862 R4 |= (TxPwer2 << 7);
2863 ATEDBGPRINT(RT_DEBUG_TRACE, ("ATEAsicSwitchChannel: TxPwer2=%d \n", TxPwer2));
2867 TxPwer2 = (TxPwer2 > 0xF) ? (0xF) : (TxPwer2);
2868 R4 |= (TxPwer2 << 7) | (1 << 6);
2873 R3 = (RFRegTable[index].R3 & 0xffffc1ff) | (TxPwer << 9); // set TX power0
2874 R4 = (RFRegTable[index].R4 & (~0x001f87c0)) | (pAd->ate.RFFreqOffset << 15) | (TxPwer2 <<6);// Set freq offset & TxPwr1
2877 // Based on BBP current mode before changing RF channel.
2878 if (pAd->ate.TxWI.BW == BW_40)
2884 pAd->LatchRfRegs.Channel = Channel;
2885 pAd->LatchRfRegs.R1 = RFRegTable[index].R1;
2886 pAd->LatchRfRegs.R2 = R2;
2887 pAd->LatchRfRegs.R3 = R3;
2888 pAd->LatchRfRegs.R4 = R4;
2901 // Change BBP setting during switch from a->g, g->a
2904 ULONG TxPinCfg = 0x00050F0A;// 2007.10.09 by Brian : 0x0005050A ==> 0x00050F0A
2906 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R62, (0x37 - GET_LNA_GAIN(pAd)));
2907 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R63, (0x37 - GET_LNA_GAIN(pAd)));
2908 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R64, (0x37 - GET_LNA_GAIN(pAd)));
2910 /* For 1T/2R chip only... */
2911 if (pAd->NicConfig2.field.ExternalLNAForG)
2913 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R82, 0x62);
2917 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R82, 0x84);
2920 // According the Rory's suggestion to solve the middle range issue.
2921 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R86, &BbpValue);
2922 ASSERT((BbpValue == 0x00));
2923 if ((BbpValue != 0x00))
2925 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R86, 0x00);
2928 // 5.5GHz band selection PIN, bit1 and bit2 are complement
2929 RTMP_IO_READ32(pAd, TX_BAND_CFG, &Value);
2932 RTMP_IO_WRITE32(pAd, TX_BAND_CFG, Value);
2934 // Turn off unused PA or LNA when only 1T or 1R.
2935 if (pAd->Antenna.field.TxPath == 1)
2937 TxPinCfg &= 0xFFFFFFF3;
2939 if (pAd->Antenna.field.RxPath == 1)
2941 TxPinCfg &= 0xFFFFF3FF;
2944 RTMP_IO_WRITE32(pAd, TX_PIN_CFG, TxPinCfg);
2948 ULONG TxPinCfg = 0x00050F05;//2007.10.09 by Brian : 0x00050505 ==> 0x00050F05
2950 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R62, (0x37 - GET_LNA_GAIN(pAd)));
2951 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R63, (0x37 - GET_LNA_GAIN(pAd)));
2952 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R64, (0x37 - GET_LNA_GAIN(pAd)));
2953 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R82, 0xF2);
2955 // According the Rory's suggestion to solve the middle range issue.
2956 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R86, &BbpValue);
2957 ASSERT((BbpValue == 0x00));
2958 if ((BbpValue != 0x00))
2960 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R86, 0x00);
2962 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R91, &BbpValue);
2963 ASSERT((BbpValue == 0x04));
2965 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R92, &BbpValue);
2966 ASSERT((BbpValue == 0x00));
2968 // 5.5GHz band selection PIN, bit1 and bit2 are complement
2969 RTMP_IO_READ32(pAd, TX_BAND_CFG, &Value);
2972 RTMP_IO_WRITE32(pAd, TX_BAND_CFG, Value);
2974 // Turn off unused PA or LNA when only 1T or 1R.
2975 if (pAd->Antenna.field.TxPath == 1)
2977 TxPinCfg &= 0xFFFFFFF3;
2979 if (pAd->Antenna.field.RxPath == 1)
2981 TxPinCfg &= 0xFFFFF3FF;
2984 RTMP_IO_WRITE32(pAd, TX_PIN_CFG, TxPinCfg);
2987 // R66 should be set according to Channel and use 20MHz when scanning
2991 R66 = 0x2E + GET_LNA_GAIN(pAd);
2992 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R66, R66);
2997 if (pAd->ate.TxWI.BW == BW_20)
2999 R66 = (UCHAR)(0x32 + (GET_LNA_GAIN(pAd)*5)/3);
3000 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R66, R66);
3004 R66 = (UCHAR)(0x3A + (GET_LNA_GAIN(pAd)*5)/3);
3005 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R66, R66);
3010 // On 11A, We should delay and wait RF/BBP to be stable
3011 // and the appropriate time should be 1000 micro seconds
3012 // 2005/06/05 - On 11G, We also need this delay time. Otherwise it's difficult to pass the WHQL.
3014 RTMPusecDelay(1000);
3018 // When 5.5GHz band the LSB of TxPwr will be used to reduced 7dB or not.
3019 ATEDBGPRINT(RT_DEBUG_TRACE, ("SwitchChannel#%d(RF=%d, %dT) to , R1=0x%08lx, R2=0x%08lx, R3=0x%08lx, R4=0x%08lx\n",
3022 pAd->Antenna.field.TxPath,
3023 pAd->LatchRfRegs.R1,
3024 pAd->LatchRfRegs.R2,
3025 pAd->LatchRfRegs.R3,
3026 pAd->LatchRfRegs.R4));
3030 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",
3033 (R3 & 0x00003e00) >> 9,
3034 (R4 & 0x000007c0) >> 6,
3035 pAd->Antenna.field.TxPath,
3036 pAd->LatchRfRegs.R1,
3037 pAd->LatchRfRegs.R2,
3038 pAd->LatchRfRegs.R3,
3039 pAd->LatchRfRegs.R4));
3044 // In fact, no one will call this routine so far !
3047 ==========================================================================
3049 Gives CCK TX rate 2 more dB TX power.
3050 This routine works only in ATE mode.
3052 calculate desired Tx power in RF R3.Tx0~5, should consider -
3053 0. if current radio is a noisy environment (pAd->DrsCounters.fNoisyEnvironment)
3054 1. TxPowerPercentage
3055 2. auto calibration based on TSSI feedback
3056 3. extra 2 db for CCK
3057 4. -10 db upon very-short distance (AvgRSSI >= -40db) to AP
3059 NOTE: Since this routine requires the value of (pAd->DrsCounters.fNoisyEnvironment),
3060 it should be called AFTER MlmeDynamicTxRateSwitching()
3061 ==========================================================================
3063 VOID ATEAsicAdjustTxPower(
3064 IN PRTMP_ADAPTER pAd)
3068 BOOLEAN bAutoTxAgc = FALSE;
3069 UCHAR TssiRef, *pTssiMinusBoundary, *pTssiPlusBoundary, TxAgcStep;
3070 UCHAR BbpR49 = 0, idx;
3071 PCHAR pTxAgcCompensate;
3075 /* no one calls this procedure so far */
3076 if (pAd->ate.TxWI.BW == BW_40)
3078 if (pAd->ate.Channel > 14)
3080 TxPwr[0] = pAd->Tx40MPwrCfgABand[0];
3081 TxPwr[1] = pAd->Tx40MPwrCfgABand[1];
3082 TxPwr[2] = pAd->Tx40MPwrCfgABand[2];
3083 TxPwr[3] = pAd->Tx40MPwrCfgABand[3];
3084 TxPwr[4] = pAd->Tx40MPwrCfgABand[4];
3088 TxPwr[0] = pAd->Tx40MPwrCfgGBand[0];
3089 TxPwr[1] = pAd->Tx40MPwrCfgGBand[1];
3090 TxPwr[2] = pAd->Tx40MPwrCfgGBand[2];
3091 TxPwr[3] = pAd->Tx40MPwrCfgGBand[3];
3092 TxPwr[4] = pAd->Tx40MPwrCfgGBand[4];
3097 if (pAd->ate.Channel > 14)
3099 TxPwr[0] = pAd->Tx20MPwrCfgABand[0];
3100 TxPwr[1] = pAd->Tx20MPwrCfgABand[1];
3101 TxPwr[2] = pAd->Tx20MPwrCfgABand[2];
3102 TxPwr[3] = pAd->Tx20MPwrCfgABand[3];
3103 TxPwr[4] = pAd->Tx20MPwrCfgABand[4];
3107 TxPwr[0] = pAd->Tx20MPwrCfgGBand[0];
3108 TxPwr[1] = pAd->Tx20MPwrCfgGBand[1];
3109 TxPwr[2] = pAd->Tx20MPwrCfgGBand[2];
3110 TxPwr[3] = pAd->Tx20MPwrCfgGBand[3];
3111 TxPwr[4] = pAd->Tx20MPwrCfgGBand[4];
3115 // TX power compensation for temperature variation based on TSSI.
3116 // Do it per 4 seconds.
3117 if (pAd->Mlme.OneSecPeriodicRound % 4 == 0)
3119 if (pAd->ate.Channel <= 14)
3122 bAutoTxAgc = pAd->bAutoTxAgcG;
3123 TssiRef = pAd->TssiRefG;
3124 pTssiMinusBoundary = &pAd->TssiMinusBoundaryG[0];
3125 pTssiPlusBoundary = &pAd->TssiPlusBoundaryG[0];
3126 TxAgcStep = pAd->TxAgcStepG;
3127 pTxAgcCompensate = &pAd->TxAgcCompensateG;
3132 bAutoTxAgc = pAd->bAutoTxAgcA;
3133 TssiRef = pAd->TssiRefA;
3134 pTssiMinusBoundary = &pAd->TssiMinusBoundaryA[0];
3135 pTssiPlusBoundary = &pAd->TssiPlusBoundaryA[0];
3136 TxAgcStep = pAd->TxAgcStepA;
3137 pTxAgcCompensate = &pAd->TxAgcCompensateA;
3142 /* BbpR49 is unsigned char */
3143 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R49, &BbpR49);
3145 /* (p) TssiPlusBoundaryG[0] = 0 = (m) TssiMinusBoundaryG[0] */
3146 /* compensate: +4 +3 +2 +1 0 -1 -2 -3 -4 * steps */
3147 /* step value is defined in pAd->TxAgcStepG for tx power value */
3149 /* [4]+1+[4] p4 p3 p2 p1 o1 m1 m2 m3 m4 */
3150 /* ex: 0x00 0x15 0x25 0x45 0x88 0xA0 0xB5 0xD0 0xF0
3151 above value are examined in mass factory production */
3152 /* [4] [3] [2] [1] [0] [1] [2] [3] [4] */
3154 /* plus is 0x10 ~ 0x40, minus is 0x60 ~ 0x90 */
3155 /* if value is between p1 ~ o1 or o1 ~ s1, no need to adjust tx power */
3156 /* if value is 0x65, tx power will be -= TxAgcStep*(2-1) */
3158 if (BbpR49 > pTssiMinusBoundary[1])
3160 // Reading is larger than the reference value.
3161 // Check for how large we need to decrease the Tx power.
3162 for (idx = 1; idx < 5; idx++)
3164 if (BbpR49 <= pTssiMinusBoundary[idx]) // Found the range
3167 // The index is the step we should decrease, idx = 0 means there is nothing to compensate
3168 // if (R3 > (ULONG) (TxAgcStep * (idx-1)))
3169 *pTxAgcCompensate = -(TxAgcStep * (idx-1));
3171 // *pTxAgcCompensate = -((UCHAR)R3);
3173 DeltaPwr += (*pTxAgcCompensate);
3174 ATEDBGPRINT(RT_DEBUG_TRACE, ("-- Tx Power, BBP R1=%x, TssiRef=%x, TxAgcStep=%x, step = -%d\n",
3175 BbpR49, TssiRef, TxAgcStep, idx-1));
3177 else if (BbpR49 < pTssiPlusBoundary[1])
3179 // Reading is smaller than the reference value
3180 // check for how large we need to increase the Tx power
3181 for (idx = 1; idx < 5; idx++)
3183 if (BbpR49 >= pTssiPlusBoundary[idx]) // Found the range
3186 // The index is the step we should increase, idx = 0 means there is nothing to compensate
3187 *pTxAgcCompensate = TxAgcStep * (idx-1);
3188 DeltaPwr += (*pTxAgcCompensate);
3189 ATEDBGPRINT(RT_DEBUG_TRACE, ("++ Tx Power, BBP R1=%x, TssiRef=%x, TxAgcStep=%x, step = +%d\n",
3190 BbpR49, TssiRef, TxAgcStep, idx-1));
3194 *pTxAgcCompensate = 0;
3195 ATEDBGPRINT(RT_DEBUG_TRACE, (" Tx Power, BBP R1=%x, TssiRef=%x, TxAgcStep=%x, step = +%d\n",
3196 BbpR49, TssiRef, TxAgcStep, 0));
3202 if (pAd->ate.Channel <= 14)
3204 bAutoTxAgc = pAd->bAutoTxAgcG;
3205 pTxAgcCompensate = &pAd->TxAgcCompensateG;
3209 bAutoTxAgc = pAd->bAutoTxAgcA;
3210 pTxAgcCompensate = &pAd->TxAgcCompensateA;
3214 DeltaPwr += (*pTxAgcCompensate);
3217 /* calculate delta power based on the percentage specified from UI */
3218 // E2PROM setting is calibrated for maximum TX power (i.e. 100%)
3219 // We lower TX power here according to the percentage specified from UI
3220 if (pAd->CommonCfg.TxPowerPercentage == 0xffffffff) // AUTO TX POWER control
3222 else if (pAd->CommonCfg.TxPowerPercentage > 90) // 91 ~ 100% & AUTO, treat as 100% in terms of mW
3224 else if (pAd->CommonCfg.TxPowerPercentage > 60) // 61 ~ 90%, treat as 75% in terms of mW
3228 else if (pAd->CommonCfg.TxPowerPercentage > 30) // 31 ~ 60%, treat as 50% in terms of mW
3232 else if (pAd->CommonCfg.TxPowerPercentage > 15) // 16 ~ 30%, treat as 25% in terms of mW
3236 else if (pAd->CommonCfg.TxPowerPercentage > 9) // 10 ~ 15%, treat as 12.5% in terms of mW
3240 else // 0 ~ 9 %, treat as MIN(~3%) in terms of mW
3245 /* reset different new tx power for different TX rate */
3248 if (TxPwr[i] != 0xffffffff)
3252 Value = (CHAR)((TxPwr[i] >> j*4) & 0x0F); /* 0 ~ 15 */
3254 if ((Value + DeltaPwr) < 0)
3256 Value = 0; /* min */
3258 else if ((Value + DeltaPwr) > 0xF)
3260 Value = 0xF; /* max */
3264 Value += DeltaPwr; /* temperature compensation */
3267 /* fill new value to CSR offset */
3268 TxPwr[i] = (TxPwr[i] & ~(0x0000000F << j*4)) | (Value << j*4);
3271 /* write tx power value to CSR */
3272 /* TX_PWR_CFG_0 (8 tx rate) for TX power for OFDM 12M/18M
3273 TX power for OFDM 6M/9M
3274 TX power for CCK5.5M/11M
3275 TX power for CCK1M/2M */
3276 /* TX_PWR_CFG_1 ~ TX_PWR_CFG_4 */
3277 RTMP_IO_WRITE32(pAd, TX_PWR_CFG_0 + i*4, TxPwr[i]);
3286 ========================================================================
3287 Routine Description:
3288 Write TxWI for ATE mode.
3292 ========================================================================
3296 static VOID ATEWriteTxWI(
3297 IN PRTMP_ADAPTER pAd,
3298 IN PTXWI_STRUC pTxWI,
3300 IN BOOLEAN InsTimestamp,
3303 IN BOOLEAN NSeq, // HW new a sequence.
3311 IN HTTRANSMIT_SETTING Transmit)
3314 // Always use Long preamble before verifiation short preamble functionality works well.
3315 // Todo: remove the following line if short preamble functionality works
3317 OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_SHORT_PREAMBLE_INUSED);
3319 pTxWI->TS= InsTimestamp;
3320 pTxWI->AMPDU = AMPDU;
3322 pTxWI->MIMOps = PWR_ACTIVE;
3323 pTxWI->MpduDensity = 4;
3325 pTxWI->txop = Txopmode;
3327 pTxWI->BAWinSize = BASize;
3329 pTxWI->WirelessCliID = WCID;
3330 pTxWI->MPDUtotalByteCount = Length;
3331 pTxWI->PacketId = PID;
3333 pTxWI->BW = Transmit.field.BW;
3334 pTxWI->ShortGI = Transmit.field.ShortGI;
3335 pTxWI->STBC= Transmit.field.STBC;
3337 pTxWI->MCS = Transmit.field.MCS;
3338 pTxWI->PHYMODE= Transmit.field.MODE;
3340 #ifdef DOT11_N_SUPPORT
3342 // MMPS is 802.11n features. Because TxWI->MCS > 7 must be HT mode,
3343 // so need not check if it's HT rate.
3345 if ((MIMOps == MMPS_STATIC) && (pTxWI->MCS > 7))
3348 if ((MIMOps == MMPS_DYNAMIC) && (pTxWI->MCS > 7)) // SMPS protect 2 spatial.
3350 #endif // DOT11_N_SUPPORT //
3352 pTxWI->CFACK = CfAck;
3358 ========================================================================
3360 Routine Description:
3361 Disable protection for ATE.
3362 ========================================================================
3364 VOID ATEDisableAsicProtect(
3365 IN PRTMP_ADAPTER pAd)
3367 PROT_CFG_STRUC ProtCfg, ProtCfg4;
3373 // Config ASIC RTS threshold register
3374 RTMP_IO_READ32(pAd, TX_RTS_CFG, &MacReg);
3375 MacReg &= 0xFF0000FF;
3376 MacReg |= (pAd->CommonCfg.RtsThreshold << 8);
3377 RTMP_IO_WRITE32(pAd, TX_RTS_CFG, MacReg);
3379 // Initial common protection settings
3380 RTMPZeroMemory(Protect, sizeof(Protect));
3383 ProtCfg.field.TxopAllowGF40 = 1;
3384 ProtCfg.field.TxopAllowGF20 = 1;
3385 ProtCfg.field.TxopAllowMM40 = 1;
3386 ProtCfg.field.TxopAllowMM20 = 1;
3387 ProtCfg.field.TxopAllowOfdm = 1;
3388 ProtCfg.field.TxopAllowCck = 1;
3389 ProtCfg.field.RTSThEn = 1;
3390 ProtCfg.field.ProtectNav = ASIC_SHORTNAV;
3392 // Handle legacy(B/G) protection
3393 ProtCfg.field.ProtectRate = pAd->CommonCfg.RtsRate;
3394 ProtCfg.field.ProtectCtrl = 0;
3395 Protect[0] = ProtCfg.word;
3396 Protect[1] = ProtCfg.word;
3399 // 1.All STAs in the BSS are 20/40 MHz HT
3400 // 2. in ai 20/40MHz BSS
3401 // 3. all STAs are 20MHz in a 20MHz BSS
3402 // Pure HT. no protection.
3406 // PROT_TXOP(25:20) -- 010111
3407 // PROT_NAV(19:18) -- 01 (Short NAV protection)
3408 // PROT_CTRL(17:16) -- 00 (None)
3409 // PROT_RATE(15:0) -- 0x4004 (OFDM 24M)
3410 Protect[2] = 0x01744004;
3414 // PROT_TXOP(25:20) -- 111111
3415 // PROT_NAV(19:18) -- 01 (Short NAV protection)
3416 // PROT_CTRL(17:16) -- 00 (None)
3417 // PROT_RATE(15:0) -- 0x4084 (duplicate OFDM 24M)
3418 Protect[3] = 0x03f44084;
3422 // PROT_TXOP(25:20) -- 010111
3423 // PROT_NAV(19:18) -- 01 (Short NAV protection)
3424 // PROT_CTRL(17:16) -- 00 (None)
3425 // PROT_RATE(15:0) -- 0x4004 (OFDM 24M)
3426 Protect[4] = 0x01744004;
3430 // PROT_TXOP(25:20) -- 111111
3431 // PROT_NAV(19:18) -- 01 (Short NAV protection)
3432 // PROT_CTRL(17:16) -- 00 (None)
3433 // PROT_RATE(15:0) -- 0x4084 (duplicate OFDM 24M)
3434 Protect[5] = 0x03f44084;
3436 pAd->CommonCfg.IOTestParm.bRTSLongProtOn = FALSE;
3438 offset = CCK_PROT_CFG;
3439 for (i = 0;i < 6;i++)
3440 RTMP_IO_WRITE32(pAd, offset + i*4, Protect[i]);
3446 ========================================================================
3447 Routine Description:
3448 Write TxInfo for ATE mode.
3452 ========================================================================
3454 static VOID ATEWriteTxInfo(
3455 IN PRTMP_ADAPTER pAd,
3456 IN PTXINFO_STRUC pTxInfo,
3457 IN USHORT USBDMApktLen,
3463 pTxInfo->USBDMATxPktLen = USBDMApktLen;
3464 pTxInfo->QSEL = QueueSel;
3466 if (QueueSel != FIFO_EDCA)
3467 ATEDBGPRINT(RT_DEBUG_TRACE, ("=======> QueueSel != FIFO_EDCA<=======\n"));
3469 pTxInfo->USBDMANextVLD = NextValid;
3470 pTxInfo->USBDMATxburst = TxBurst;
3471 pTxInfo->WIV = bWiv;
3472 pTxInfo->SwUseLastRound = 0;
3480 /* There are two ways to convert Rssi */
3483 // The way used with GET_LNA_GAIN().
3485 CHAR ATEConvertToRssi(
3486 IN PRTMP_ADAPTER pAd,
3488 IN UCHAR RssiNumber)
3490 UCHAR RssiOffset, LNAGain;
3492 // Rssi equals to zero should be an invalid value
3496 LNAGain = GET_LNA_GAIN(pAd);
3497 if (pAd->LatchRfRegs.Channel > 14)
3499 if (RssiNumber == 0)
3500 RssiOffset = pAd->ARssiOffset0;
3501 else if (RssiNumber == 1)
3502 RssiOffset = pAd->ARssiOffset1;
3504 RssiOffset = pAd->ARssiOffset2;
3508 if (RssiNumber == 0)
3509 RssiOffset = pAd->BGRssiOffset0;
3510 else if (RssiNumber == 1)
3511 RssiOffset = pAd->BGRssiOffset1;
3513 RssiOffset = pAd->BGRssiOffset2;
3516 return (-12 - RssiOffset - LNAGain - Rssi);
3520 // The way originally used in ATE of rt2860ap.
3522 CHAR ATEConvertToRssi(
3523 IN PRTMP_ADAPTER pAd,
3525 IN UCHAR RssiNumber)
3527 UCHAR RssiOffset, LNAGain;
3529 // Rssi equals to zero should be an invalid value
3533 if (pAd->LatchRfRegs.Channel > 14)
3535 LNAGain = pAd->ALNAGain;
3536 if (RssiNumber == 0)
3537 RssiOffset = pAd->ARssiOffset0;
3538 else if (RssiNumber == 1)
3539 RssiOffset = pAd->ARssiOffset1;
3541 RssiOffset = pAd->ARssiOffset2;
3545 LNAGain = pAd->BLNAGain;
3546 if (RssiNumber == 0)
3547 RssiOffset = pAd->BGRssiOffset0;
3548 else if (RssiNumber == 1)
3549 RssiOffset = pAd->BGRssiOffset1;
3551 RssiOffset = pAd->BGRssiOffset2;
3554 return (-32 - RssiOffset + LNAGain - Rssi);
3556 #endif /* end of #if 1 */
3559 ========================================================================
3561 Routine Description:
3562 Set Japan filter coefficients if needed.
3564 This routine should only be called when
3565 entering TXFRAME mode or TXCONT mode.
3567 ========================================================================
3569 static VOID SetJapanFilter(
3570 IN PRTMP_ADAPTER pAd)
3575 // If Channel=14 and Bandwidth=20M and Mode=CCK, set BBP R4 bit5=1
3576 // (Japan Tx filter coefficients)when (TXFRAME or TXCONT).
3578 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &BbpData);
3580 if ((pAd->ate.TxWI.PHYMODE == MODE_CCK) && (pAd->ate.Channel == 14) && (pAd->ate.TxWI.BW == BW_20))
3582 BbpData |= 0x20; // turn on
3583 ATEDBGPRINT(RT_DEBUG_TRACE, ("SetJapanFilter!!!\n"));
3587 BbpData &= 0xdf; // turn off
3588 ATEDBGPRINT(RT_DEBUG_TRACE, ("ClearJapanFilter!!!\n"));
3591 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, BbpData);
3595 IN PRTMP_ADAPTER pAd,
3596 IN PRXWI_STRUC pRxWI)
3598 /* There are two ways to collect RSSI. */
3600 //pAd->LastRxRate = (USHORT)((pRxWI->MCS) + (pRxWI->BW <<7) + (pRxWI->ShortGI <<8)+ (pRxWI->PHYMODE <<14)) ;
3601 if (pRxWI->RSSI0 != 0)
3603 pAd->ate.LastRssi0 = ATEConvertToRssi(pAd, (CHAR) pRxWI->RSSI0, RSSI_0);
3604 pAd->ate.AvgRssi0X8 = (pAd->ate.AvgRssi0X8 - pAd->ate.AvgRssi0) + pAd->ate.LastRssi0;
3605 pAd->ate.AvgRssi0 = pAd->ate.AvgRssi0X8 >> 3;
3607 if (pRxWI->RSSI1 != 0)
3609 pAd->ate.LastRssi1 = ATEConvertToRssi(pAd, (CHAR) pRxWI->RSSI1, RSSI_1);
3610 pAd->ate.AvgRssi1X8 = (pAd->ate.AvgRssi1X8 - pAd->ate.AvgRssi1) + pAd->ate.LastRssi1;
3611 pAd->ate.AvgRssi1 = pAd->ate.AvgRssi1X8 >> 3;
3613 if (pRxWI->RSSI2 != 0)
3615 pAd->ate.LastRssi2 = ATEConvertToRssi(pAd, (CHAR) pRxWI->RSSI2, RSSI_2);
3616 pAd->ate.AvgRssi2X8 = (pAd->ate.AvgRssi2X8 - pAd->ate.AvgRssi2) + pAd->ate.LastRssi2;
3617 pAd->ate.AvgRssi2 = pAd->ate.AvgRssi2X8 >> 3;
3620 pAd->ate.LastSNR0 = (CHAR)(pRxWI->SNR0);// CHAR ==> UCHAR ?
3621 pAd->ate.LastSNR1 = (CHAR)(pRxWI->SNR1);// CHAR ==> UCHAR ?
3623 pAd->ate.NumOfAvgRssiSample ++;
3625 pAd->ate.LastSNR0 = (CHAR)(pRxWI->SNR0);
3626 pAd->ate.LastSNR1 = (CHAR)(pRxWI->SNR1);
3627 pAd->ate.RxCntPerSec++;
3628 pAd->ate.LastRssi0 = ATEConvertToRssi(pAd, (CHAR) pRxWI->RSSI0, RSSI_0);
3629 pAd->ate.LastRssi1 = ATEConvertToRssi(pAd, (CHAR) pRxWI->RSSI1, RSSI_1);
3630 pAd->ate.LastRssi2 = ATEConvertToRssi(pAd, (CHAR) pRxWI->RSSI2, RSSI_2);
3631 pAd->ate.AvgRssi0X8 = (pAd->ate.AvgRssi0X8 - pAd->ate.AvgRssi0) + pAd->ate.LastRssi0;
3632 pAd->ate.AvgRssi0 = pAd->ate.AvgRssi0X8 >> 3;
3633 pAd->ate.AvgRssi1X8 = (pAd->ate.AvgRssi1X8 - pAd->ate.AvgRssi1) + pAd->ate.LastRssi1;
3634 pAd->ate.AvgRssi1 = pAd->ate.AvgRssi1X8 >> 3;
3635 pAd->ate.AvgRssi2X8 = (pAd->ate.AvgRssi2X8 - pAd->ate.AvgRssi2) + pAd->ate.LastRssi2;
3636 pAd->ate.AvgRssi2 = pAd->ate.AvgRssi2X8 >> 3;
3637 pAd->ate.NumOfAvgRssiSample ++;
3641 #ifdef CONFIG_STA_SUPPORT
3642 VOID RTMPStationStop(
3643 IN PRTMP_ADAPTER pAd)
3645 // BOOLEAN Cancelled;
3647 ATEDBGPRINT(RT_DEBUG_TRACE, ("==> RTMPStationStop\n"));
3649 // For rx statistics, we need to keep this timer running.
3650 // RTMPCancelTimer(&pAd->Mlme.PeriodicTimer, &Cancelled);
3652 ATEDBGPRINT(RT_DEBUG_TRACE, ("<== RTMPStationStop\n"));
3655 VOID RTMPStationStart(
3656 IN PRTMP_ADAPTER pAd)
3658 ATEDBGPRINT(RT_DEBUG_TRACE, ("==> RTMPStationStart\n"));
3659 ATEDBGPRINT(RT_DEBUG_TRACE, ("<== RTMPStationStart\n"));
3661 #endif // CONFIG_STA_SUPPORT //
3664 ==========================================================================
3668 This routine should only be used in ATE mode.
3669 ==========================================================================
3673 /*======================Start of RT2870======================*/
3676 static INT ATESetUpFrame(
3677 IN PRTMP_ADAPTER pAd,
3681 PTX_CONTEXT pNullContext;
3683 HTTRANSMIT_SETTING TxHTPhyMode;
3685 PTXINFO_STRUC pTxInfo;
3686 UINT32 TransferBufferLength, OrgBufferLength = 0;
3688 #ifdef RALINK_28xx_QA
3689 PHEADER_802_11 pHeader80211 = NULL;
3690 #endif // RALINK_28xx_QA //
3692 if ((RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RESET_IN_PROGRESS)) ||
3693 (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BULKOUT_RESET)) ||
3694 (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS)) ||
3695 (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)))
3700 /* We always use QID_AC_BE and FIFO_EDCA in ATE mode. */
3702 pNullContext = &(pAd->NullContext);
3703 ASSERT(pNullContext != NULL);
3705 if (pNullContext->InUse == FALSE)
3707 // Set the in use bit
3708 pNullContext->InUse = TRUE;
3709 NdisZeroMemory(&(pAd->NullFrame), sizeof(HEADER_802_11));
3711 // Fill 802.11 header.
3712 #ifdef RALINK_28xx_QA
3713 if (pAd->ate.bQATxStart == TRUE)
3715 pHeader80211 = NdisMoveMemory(&(pAd->NullFrame), pAd->ate.Header, pAd->ate.HLen);
3716 // pDest = NdisMoveMemory(&(pAd->NullFrame), pAd->ate.Header, pAd->ate.HLen);
3717 // pHeader80211 = (PHEADER_802_11)pDest;
3720 #endif // RALINK_28xx_QA //
3722 // Fill 802.11 header.
3723 NdisMoveMemory(&(pAd->NullFrame), TemplateFrame, sizeof(HEADER_802_11));
3725 #ifdef RT_BIG_ENDIAN
3726 RTMPFrameEndianChange(pAd, (PUCHAR)&(pAd->NullFrame), DIR_READ, FALSE);
3727 #endif // RT_BIG_ENDIAN //
3729 #ifdef RALINK_28xx_QA
3730 if (pAd->ate.bQATxStart == TRUE)
3732 /* modify sequence number.... */
3733 if (pAd->ate.TxDoneCount == 0)
3735 pAd->ate.seq = pHeader80211->Sequence;
3739 pHeader80211->Sequence = ++pAd->ate.seq;
3741 /* We already got all the addr. fields from QA GUI. */
3744 #endif // RALINK_28xx_QA //
3746 COPY_MAC_ADDR(pAd->NullFrame.Addr1, pAd->ate.Addr1);
3747 COPY_MAC_ADDR(pAd->NullFrame.Addr2, pAd->ate.Addr2);
3748 COPY_MAC_ADDR(pAd->NullFrame.Addr3, pAd->ate.Addr3);
3751 RTMPZeroMemory(&pAd->NullContext.TransferBuffer->field.WirelessPacket[0], TX_BUFFER_NORMSIZE);//???
3752 pTxInfo = (PTXINFO_STRUC)&pAd->NullContext.TransferBuffer->field.WirelessPacket[0];
3754 #ifdef RALINK_28xx_QA
3755 if (pAd->ate.bQATxStart == TRUE)
3757 // Avoid to exceed the range of WirelessPacket[].
3758 ASSERT(pAd->ate.TxInfo.USBDMATxPktLen <= (MAX_FRAME_SIZE - 34/* == 2312 */));
3759 NdisMoveMemory(pTxInfo, &(pAd->ate.TxInfo), sizeof(pAd->ate.TxInfo));
3762 #endif // RALINK_28xx_QA //
3764 // Avoid to exceed the range of WirelessPacket[].
3765 ASSERT(pAd->ate.TxLength <= (MAX_FRAME_SIZE - 34/* == 2312 */));
3767 // pTxInfo->USBDMATxPktLen will be updated to include padding later.
3768 ATEWriteTxInfo(pAd, pTxInfo, (USHORT)(TXWI_SIZE + pAd->ate.TxLength), TRUE, EpToQueue[MGMTPIPEIDX], FALSE, FALSE);
3769 pTxInfo->QSEL = FIFO_EDCA;
3772 pTxWI = (PTXWI_STRUC)&pAd->NullContext.TransferBuffer->field.WirelessPacket[TXINFO_SIZE];
3775 if (pAd->ate.bQATxStart == TRUE)
3777 TxHTPhyMode.field.BW = pAd->ate.TxWI.BW;
3778 TxHTPhyMode.field.ShortGI = pAd->ate.TxWI.ShortGI;
3779 TxHTPhyMode.field.STBC = pAd->ate.TxWI.STBC;
3780 TxHTPhyMode.field.MCS = pAd->ate.TxWI.MCS;
3781 TxHTPhyMode.field.MODE = pAd->ate.TxWI.PHYMODE;
3782 ATEWriteTxWI(pAd, pTxWI, pAd->ate.TxWI.FRAG, pAd->ate.TxWI.TS, pAd->ate.TxWI.AMPDU, pAd->ate.TxWI.ACK, pAd->ate.TxWI.NSEQ,
3783 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);
3787 TxHTPhyMode.field.BW = pAd->ate.TxWI.BW;
3788 TxHTPhyMode.field.ShortGI = pAd->ate.TxWI.ShortGI;
3789 TxHTPhyMode.field.STBC = 0;
3790 TxHTPhyMode.field.MCS = pAd->ate.TxWI.MCS;
3791 TxHTPhyMode.field.MODE = pAd->ate.TxWI.PHYMODE;
3793 ATEWriteTxWI(pAd, pTxWI, FALSE, FALSE, FALSE, FALSE/* No ack required. */, FALSE, 0, BSSID_WCID, pAd->ate.TxLength,
3794 0, 0, IFS_HTTXOP, FALSE, TxHTPhyMode);// "MMPS_STATIC" instead of "MMPS_DYNAMIC" ???
3797 RTMPMoveMemory(&pAd->NullContext.TransferBuffer->field.WirelessPacket[TXINFO_SIZE+TXWI_SIZE], &pAd->NullFrame, sizeof(HEADER_802_11));
3799 pDest = &(pAd->NullContext.TransferBuffer->field.WirelessPacket[TXINFO_SIZE+TXWI_SIZE+sizeof(HEADER_802_11)]);
3801 // Prepare frame payload
3802 #ifdef RALINK_28xx_QA
3803 if (pAd->ate.bQATxStart == TRUE)
3806 if ((pAd->ate.PLen != 0))
3808 for (j = 0; j < pAd->ate.DLen; j+=pAd->ate.PLen)
3810 RTMPMoveMemory(pDest, pAd->ate.Pattern, pAd->ate.PLen);
3811 pDest += pAd->ate.PLen;
3814 TransferBufferLength = TXINFO_SIZE + TXWI_SIZE + pAd->ate.TxWI.MPDUtotalByteCount;
3817 #endif // RALINK_28xx_QA //
3819 for (j = 0; j < (pAd->ate.TxLength - sizeof(HEADER_802_11)); j++)
3824 TransferBufferLength = TXINFO_SIZE + TXWI_SIZE + pAd->ate.TxLength;
3828 OrgBufferLength = TransferBufferLength;
3829 TransferBufferLength = (TransferBufferLength + 3) & (~3);
3831 // Always add 4 extra bytes at every packet.
3832 padLen = TransferBufferLength - OrgBufferLength + 4;/* 4 == last packet padding */
3833 ASSERT((padLen <= (RTMP_PKT_TAIL_PADDING - 4/* 4 == MaxBulkOutsize alignment padding */)));
3835 /* Now memzero all extra padding bytes. */
3836 NdisZeroMemory(pDest, padLen);
3839 if ((TransferBufferLength % 4) == 1)
3841 NdisZeroMemory(pDest, 7);
3843 TransferBufferLength += 3;
3845 else if ((TransferBufferLength % 4) == 2)
3847 NdisZeroMemory(pDest, 6);
3849 TransferBufferLength += 2;
3851 else if ((TransferBufferLength % 4) == 3)
3853 NdisZeroMemory(pDest, 5);
3855 TransferBufferLength += 1;
3859 // Update pTxInfo->USBDMATxPktLen to include padding.
3860 pTxInfo->USBDMATxPktLen = TransferBufferLength - TXINFO_SIZE;
3862 TransferBufferLength += 4;
3864 // If TransferBufferLength is multiple of 64, add extra 4 bytes again.
3865 if ((TransferBufferLength % pAd->BulkOutMaxPacketSize) == 0)
3867 NdisZeroMemory(pDest, 4);
3868 TransferBufferLength += 4;
3871 // Fill out frame length information for global Bulk out arbitor
3872 pAd->NullContext.BulkOutSize = TransferBufferLength;
3874 #ifdef RT_BIG_ENDIAN
3875 RTMPWIEndianChange((PUCHAR)pTxWI, TYPE_TXWI);
3876 RTMPFrameEndianChange(pAd, (((PUCHAR)pTxInfo)+TXWI_SIZE+TXINFO_SIZE), DIR_WRITE, FALSE);
3877 RTMPDescriptorEndianChange((PUCHAR)pTxInfo, TYPE_TXINFO);
3878 #endif // RT_BIG_ENDIAN //
3882 VOID ATE_RTUSBBulkOutDataPacketComplete(purbb_t pUrb, struct pt_regs *pt_regs)
3885 PTX_CONTEXT pNullContext;
3886 UCHAR BulkOutPipeId;
3888 unsigned long IrqFlags;
3891 pNullContext = (PTX_CONTEXT)pUrb->context;
3892 pAd = pNullContext->pAd;
3895 // Reset Null frame context flags
3896 pNullContext->IRPPending = FALSE;
3897 pNullContext->InUse = FALSE;
3898 Status = pUrb->status;
3900 // Store BulkOut PipeId
3901 BulkOutPipeId = pNullContext->BulkOutPipeId;
3902 pAd->BulkOutDataOneSecCount++;
3904 if (Status == USB_ST_NOERROR)
3906 #ifdef RALINK_28xx_QA
3907 if ((ATE_ON(pAd)) && (pAd->ate.bQATxStart == TRUE))
3909 if (pAd->ate.QID == BulkOutPipeId)
3911 // Let Rx can have a chance to break in during Tx process,
3912 // especially for loopback mode in QA ATE.
3913 // To trade off between tx performance and loopback mode integrity.
3914 /* Q : Now Rx is handled by tasklet, do we still need this delay ? */
3915 /* Ans : Even tasklet is used, Rx/Tx < 1 if we do not delay for a while right here. */
3917 pAd->ate.TxDoneCount++;
3918 pAd->RalinkCounters.KickTxCount++;
3919 ASSERT(pAd->ate.QID == 0);
3923 #endif // RALINK_28xx_QA //
3924 pAd->BulkOutComplete++;
3926 pAd->Counters8023.GoodTransmits++;
3928 /* Don't worry about the queue is empty or not. This function will check itself. */
3929 RTMPDeQueuePacket(pAd, TRUE, BulkOutPipeId, MAX_TX_PROCESS);
3931 /* In 28xx, SendTxWaitQueue ==> TxSwQueue */
3933 if (pAd->SendTxWaitQueue[BulkOutPipeId].Number > 0)
3935 RTMPDeQueuePacket(pAd, BulkOutPipeId);
3939 else // STATUS_OTHER
3941 pAd->BulkOutCompleteOther++;
3943 ATEDBGPRINT(RT_DEBUG_ERROR, ("BulkOutDataPacket Failed STATUS_OTHER = 0x%x . \n", Status));
3944 ATEDBGPRINT(RT_DEBUG_ERROR, (">>BulkOutReq=0x%lx, BulkOutComplete=0x%lx\n", pAd->BulkOutReq, pAd->BulkOutComplete));
3946 if ((!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RESET_IN_PROGRESS)) &&
3947 (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS)) &&
3948 (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)) &&
3949 (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BULKOUT_RESET)))
3951 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_BULKOUT_RESET);
3952 /* In 28xx, RT_OID_USB_RESET_BULK_OUT ==> CMDTHREAD_RESET_BULK_OUT */
3953 RTUSBEnqueueInternalCmd(pAd, CMDTHREAD_RESET_BULK_OUT, NULL, 0);
3955 BULK_OUT_LOCK(&pAd->BulkOutLock[BulkOutPipeId], IrqFlags);
3956 pAd->BulkOutPending[BulkOutPipeId] = FALSE;
3957 pAd->bulkResetPipeid = BulkOutPipeId;
3958 BULK_OUT_UNLOCK(&pAd->BulkOutLock[BulkOutPipeId], IrqFlags);
3965 if (atomic_read(&pAd->BulkOutRemained) > 0)
3967 atomic_dec(&pAd->BulkOutRemained);
3970 // 1st - Transmit Success
3971 OldValue = pAd->WlanCounters.TransmittedFragmentCount.u.LowPart;
3972 pAd->WlanCounters.TransmittedFragmentCount.u.LowPart++;
3974 if (pAd->WlanCounters.TransmittedFragmentCount.u.LowPart < OldValue)
3976 pAd->WlanCounters.TransmittedFragmentCount.u.HighPart++;
3979 if(((pAd->ContinBulkOut == TRUE ) ||(atomic_read(&pAd->BulkOutRemained) > 0)) && (pAd->ate.Mode & ATE_TXFRAME))
3981 RTUSB_SET_BULK_FLAG(pAd, fRTUSB_BULK_OUT_DATA_ATE);
3985 RTUSB_CLEAR_BULK_FLAG(pAd, fRTUSB_BULK_OUT_DATA_ATE);
3986 #ifdef RALINK_28xx_QA
3987 pAd->ate.TxStatus = 0;
3988 #endif // RALINK_28xx_QA //
3991 BULK_OUT_LOCK(&pAd->BulkOutLock[BulkOutPipeId], IrqFlags);
3992 pAd->BulkOutPending[BulkOutPipeId] = FALSE;
3993 BULK_OUT_UNLOCK(&pAd->BulkOutLock[BulkOutPipeId], IrqFlags);
3995 // Always call Bulk routine, even reset bulk.
3996 // The protection of rest bulk should be in BulkOut routine.
3997 RTUSBKickBulkOut(pAd);
4001 ========================================================================
4003 Routine Description:
4011 ========================================================================
4013 VOID ATE_RTUSBBulkOutDataPacket(
4014 IN PRTMP_ADAPTER pAd,
4015 IN UCHAR BulkOutPipeId)
4017 PTX_CONTEXT pNullContext = &(pAd->NullContext);
4020 unsigned long IrqFlags;
4023 ASSERT(BulkOutPipeId == 0);
4025 /* Build up the frame first. */
4026 // ATESetUpFrame(pAd, 0);
4028 BULK_OUT_LOCK(&pAd->BulkOutLock[BulkOutPipeId], IrqFlags);
4030 if (pAd->BulkOutPending[BulkOutPipeId] == TRUE)
4032 BULK_OUT_UNLOCK(&pAd->BulkOutLock[BulkOutPipeId], IrqFlags);
4036 pAd->BulkOutPending[BulkOutPipeId] = TRUE;
4037 BULK_OUT_UNLOCK(&pAd->BulkOutLock[BulkOutPipeId], IrqFlags);
4039 // Increase Total transmit byte counter
4040 pAd->RalinkCounters.OneSecTransmittedByteCount += pNullContext->BulkOutSize;
4041 pAd->RalinkCounters.TransmittedByteCount += pNullContext->BulkOutSize;
4043 // Clear ATE frame bulk out flag
4044 RTUSB_CLEAR_BULK_FLAG(pAd, fRTUSB_BULK_OUT_DATA_ATE);
4046 // Init Tx context descriptor
4047 pNullContext->IRPPending = TRUE;
4048 RTUSBInitTxDesc(pAd, pNullContext, BulkOutPipeId, (usb_complete_t)ATE_RTUSBBulkOutDataPacketComplete);
4049 pUrb = pNullContext->pUrb;
4051 if((ret = RTUSB_SUBMIT_URB(pUrb))!=0)
4053 ATEDBGPRINT(RT_DEBUG_ERROR, ("ATE_RTUSBBulkOutDataPacket: Submit Tx URB failed %d\n", ret));
4063 ========================================================================
4065 Routine Description:
4073 ========================================================================
4075 VOID ATE_RTUSBCancelPendingBulkInIRP(
4076 IN PRTMP_ADAPTER pAd)
4078 PRX_CONTEXT pRxContext;
4081 ATEDBGPRINT(RT_DEBUG_TRACE, ("--->ATE_RTUSBCancelPendingBulkInIRP\n"));
4083 for ( i = 0; i < (RX_RING_SIZE); i++)
4085 pRxContext = &(pAd->RxContext[i]);
4086 if(pRxContext->IRPPending == TRUE)
4088 RTUSB_UNLINK_URB(pRxContext->pUrb);
4089 pRxContext->IRPPending = FALSE;
4090 pRxContext->InUse = FALSE;
4091 //NdisInterlockedDecrement(&pAd->PendingRx);
4096 for ( i = 0; i < (RX_RING_SIZE); i++)
4098 pRxContext = &(pAd->RxContext[i]);
4099 if(atomic_read(&pRxContext->IrpLock) == IRPLOCK_CANCELABLE)
4101 RTUSB_UNLINK_URB(pRxContext->pUrb);
4103 InterlockedExchange(&pRxContext->IrpLock, IRPLOCK_CANCE_START);
4106 ATEDBGPRINT(RT_DEBUG_TRACE, ("<---ATE_RTUSBCancelPendingBulkInIRP\n"));
4111 VOID rt_ee_read_all(PRTMP_ADAPTER pAd, USHORT *Data)
4116 for (i = 0 ; i < EEPROM_SIZE/2 ; )
4118 /* "value" is expecially for some compilers... */
4119 RT28xx_EEPROM_READ16(pAd, i*2, value);
4125 VOID rt_ee_write_all(PRTMP_ADAPTER pAd, USHORT *Data)
4130 for (i = 0 ; i < EEPROM_SIZE/2 ; )
4132 /* "value" is expecially for some compilers... */
4134 RT28xx_EEPROM_WRITE16(pAd, i*2, value);
4138 #ifdef RALINK_28xx_QA
4139 VOID ATE_QA_Statistics(
4140 IN PRTMP_ADAPTER pAd,
4141 IN PRXWI_STRUC pRxWI,
4142 IN PRT28XX_RXD_STRUC pRxD,
4143 IN PHEADER_802_11 pHeader)
4145 // update counter first
4146 if (pHeader != NULL)
4148 if (pHeader->FC.Type == BTYPE_DATA)
4153 pAd->ate.OtherData++;
4155 else if (pHeader->FC.Type == BTYPE_MGMT)
4157 if (pHeader->FC.SubType == SUBTYPE_BEACON)
4160 pAd->ate.OtherCount++;
4162 else if (pHeader->FC.Type == BTYPE_CNTL)
4164 pAd->ate.OtherCount++;
4167 pAd->ate.RSSI0 = pRxWI->RSSI0;
4168 pAd->ate.RSSI1 = pRxWI->RSSI1;
4169 pAd->ate.RSSI2 = pRxWI->RSSI2;
4170 pAd->ate.SNR0 = pRxWI->SNR0;
4171 pAd->ate.SNR1 = pRxWI->SNR1;
4174 /* command id with Cmd Type == 0x0008(for 28xx)/0x0005(for iNIC) */
4175 #define RACFG_CMD_RF_WRITE_ALL 0x0000
4176 #define RACFG_CMD_E2PROM_READ16 0x0001
4177 #define RACFG_CMD_E2PROM_WRITE16 0x0002
4178 #define RACFG_CMD_E2PROM_READ_ALL 0x0003
4179 #define RACFG_CMD_E2PROM_WRITE_ALL 0x0004
4180 #define RACFG_CMD_IO_READ 0x0005
4181 #define RACFG_CMD_IO_WRITE 0x0006
4182 #define RACFG_CMD_IO_READ_BULK 0x0007
4183 #define RACFG_CMD_BBP_READ8 0x0008
4184 #define RACFG_CMD_BBP_WRITE8 0x0009
4185 #define RACFG_CMD_BBP_READ_ALL 0x000a
4186 #define RACFG_CMD_GET_COUNTER 0x000b
4187 #define RACFG_CMD_CLEAR_COUNTER 0x000c
4189 #define RACFG_CMD_RSV1 0x000d
4190 #define RACFG_CMD_RSV2 0x000e
4191 #define RACFG_CMD_RSV3 0x000f
4193 #define RACFG_CMD_TX_START 0x0010
4194 #define RACFG_CMD_GET_TX_STATUS 0x0011
4195 #define RACFG_CMD_TX_STOP 0x0012
4196 #define RACFG_CMD_RX_START 0x0013
4197 #define RACFG_CMD_RX_STOP 0x0014
4198 #define RACFG_CMD_GET_NOISE_LEVEL 0x0015
4200 #define RACFG_CMD_ATE_START 0x0080
4201 #define RACFG_CMD_ATE_STOP 0x0081
4203 #define RACFG_CMD_ATE_START_TX_CARRIER 0x0100
4204 #define RACFG_CMD_ATE_START_TX_CONT 0x0101
4205 #define RACFG_CMD_ATE_START_TX_FRAME 0x0102
4206 #define RACFG_CMD_ATE_SET_BW 0x0103
4207 #define RACFG_CMD_ATE_SET_TX_POWER0 0x0104
4208 #define RACFG_CMD_ATE_SET_TX_POWER1 0x0105
4209 #define RACFG_CMD_ATE_SET_FREQ_OFFSET 0x0106
4210 #define RACFG_CMD_ATE_GET_STATISTICS 0x0107
4211 #define RACFG_CMD_ATE_RESET_COUNTER 0x0108
4212 #define RACFG_CMD_ATE_SEL_TX_ANTENNA 0x0109
4213 #define RACFG_CMD_ATE_SEL_RX_ANTENNA 0x010a
4214 #define RACFG_CMD_ATE_SET_PREAMBLE 0x010b
4215 #define RACFG_CMD_ATE_SET_CHANNEL 0x010c
4216 #define RACFG_CMD_ATE_SET_ADDR1 0x010d
4217 #define RACFG_CMD_ATE_SET_ADDR2 0x010e
4218 #define RACFG_CMD_ATE_SET_ADDR3 0x010f
4219 #define RACFG_CMD_ATE_SET_RATE 0x0110
4220 #define RACFG_CMD_ATE_SET_TX_FRAME_LEN 0x0111
4221 #define RACFG_CMD_ATE_SET_TX_FRAME_COUNT 0x0112
4222 #define RACFG_CMD_ATE_START_RX_FRAME 0x0113
4223 #define RACFG_CMD_ATE_E2PROM_READ_BULK 0x0114
4224 #define RACFG_CMD_ATE_E2PROM_WRITE_BULK 0x0115
4225 #define RACFG_CMD_ATE_IO_WRITE_BULK 0x0116
4226 #define RACFG_CMD_ATE_BBP_READ_BULK 0x0117
4227 #define RACFG_CMD_ATE_BBP_WRITE_BULK 0x0118
4228 #define RACFG_CMD_ATE_RF_READ_BULK 0x0119
4229 #define RACFG_CMD_ATE_RF_WRITE_BULK 0x011a
4233 #define A2Hex(_X, _p) \
4238 while (((*p >= 'a') && (*p <= 'f')) || ((*p >= 'A') && (*p <= 'F')) || ((*p >= '0') && (*p <= '9'))) \
4240 if ((*p >= 'a') && (*p <= 'f')) \
4241 _X = _X * 16 + *p - 87; \
4242 else if ((*p >= 'A') && (*p <= 'F')) \
4243 _X = _X * 16 + *p - 55; \
4244 else if ((*p >= '0') && (*p <= '9')) \
4245 _X = _X * 16 + *p - 48; \
4251 static VOID memcpy_exl(PRTMP_ADAPTER pAd, UCHAR *dst, UCHAR *src, ULONG len);
4252 static VOID memcpy_exs(PRTMP_ADAPTER pAd, UCHAR *dst, UCHAR *src, ULONG len);
4253 static VOID RTMP_IO_READ_BULK(PRTMP_ADAPTER pAd, UCHAR *dst, UCHAR *src, UINT32 len);
4255 #define LEN_OF_ARG 16
4258 IN PRTMP_ADAPTER pAdapter,
4259 IN struct iwreq *wrq)
4261 unsigned short Command_Id;
4262 struct ate_racfghdr *pRaCfg;
4263 INT Status = NDIS_STATUS_SUCCESS;
4267 if((pRaCfg = kmalloc(sizeof(struct ate_racfghdr), GFP_KERNEL)) == NULL)
4273 NdisZeroMemory(pRaCfg, sizeof(struct ate_racfghdr));
4275 if (copy_from_user((PUCHAR)pRaCfg, wrq->u.data.pointer, wrq->u.data.length))
4283 Command_Id = ntohs(pRaCfg->command_id);
4285 ATEDBGPRINT(RT_DEBUG_TRACE,("\n%s: Command_Id = 0x%04x !\n", __func__, Command_Id));
4289 // We will get this command when QA starts.
4290 case RACFG_CMD_ATE_START:
4292 ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_ATE_START\n"));
4294 // prepare feedback as soon as we can to avoid QA timeout.
4295 pRaCfg->length = htons(2);
4296 pRaCfg->status = htons(0);
4298 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
4299 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
4300 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
4302 ATEDBGPRINT(RT_DEBUG_TRACE, ("wrq->u.data.length = %d\n", wrq->u.data.length));
4304 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
4306 ATEDBGPRINT(RT_DEBUG_TRACE, ("copy_to_user() fail in case RACFG_CMD_ATE_START\n"));
4311 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_START is done !\n"));
4313 Set_ATE_Proc(pAdapter, "ATESTART");
4317 // We will get this command either QA is closed or ated is killed by user.
4318 case RACFG_CMD_ATE_STOP:
4322 ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_ATE_STOP\n"));
4324 // Distinguish this command came from QA(via ated)
4325 // or ate daemon according to the existence of pid in payload.
4326 // No need to prepare feedback if this cmd came directly from ate daemon.
4327 pRaCfg->length = ntohs(pRaCfg->length);
4329 if (pRaCfg->length == sizeof(pAdapter->ate.AtePid))
4331 // This command came from QA.
4332 // Get the pid of ATE daemon.
4333 memcpy((UCHAR *)&pAdapter->ate.AtePid,
4334 (&pRaCfg->data[0]) - 2/* == &(pRaCfg->status) */,
4335 sizeof(pAdapter->ate.AtePid));
4337 // prepare feedback as soon as we can to avoid QA timeout.
4338 pRaCfg->length = htons(2);
4339 pRaCfg->status = htons(0);
4341 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
4342 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
4343 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
4345 ATEDBGPRINT(RT_DEBUG_TRACE, ("wrq->u.data.length = %d\n", wrq->u.data.length));
4347 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
4349 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_STOP\n"));
4354 // kill ATE daemon when leaving ATE mode.
4355 // We must kill ATE daemon first before setting ATESTOP,
4356 // or Microsoft will report sth. wrong.
4357 ret = kill_proc(pAdapter->ate.AtePid, SIGTERM, 1);
4360 ATEDBGPRINT(RT_DEBUG_ERROR, ("%s: unable to signal thread\n", pAdapter->net_dev->name));
4364 // AP might have in ATE_STOP mode due to cmd from QA.
4365 if (ATE_ON(pAdapter))
4367 // Someone has killed ate daemon while QA GUI is still open.
4368 Set_ATE_Proc(pAdapter, "ATESTOP");
4369 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_AP_START is done !\n"));
4374 case RACFG_CMD_RF_WRITE_ALL:
4376 UINT32 R1, R2, R3, R4;
4379 memcpy(&R1, pRaCfg->data-2, 4);
4380 memcpy(&R2, pRaCfg->data+2, 4);
4381 memcpy(&R3, pRaCfg->data+6, 4);
4382 memcpy(&R4, pRaCfg->data+10, 4);
4383 memcpy(&channel, pRaCfg->data+14, 2);
4385 pAdapter->LatchRfRegs.R1 = ntohl(R1);
4386 pAdapter->LatchRfRegs.R2 = ntohl(R2);
4387 pAdapter->LatchRfRegs.R3 = ntohl(R3);
4388 pAdapter->LatchRfRegs.R4 = ntohl(R4);
4389 pAdapter->LatchRfRegs.Channel = ntohs(channel);
4391 RTMP_RF_IO_WRITE32(pAdapter, pAdapter->LatchRfRegs.R1);
4392 RTMP_RF_IO_WRITE32(pAdapter, pAdapter->LatchRfRegs.R2);
4393 RTMP_RF_IO_WRITE32(pAdapter, pAdapter->LatchRfRegs.R3);
4394 RTMP_RF_IO_WRITE32(pAdapter, pAdapter->LatchRfRegs.R4);
4397 pRaCfg->length = htons(2);
4398 pRaCfg->status = htons(0);
4400 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
4401 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
4402 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
4404 ATEDBGPRINT(RT_DEBUG_TRACE, ("wrq->u.data.length = %d\n", wrq->u.data.length));
4405 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
4407 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_RF_WRITE_ALL\n"));
4412 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_RF_WRITE_ALL is done !\n"));
4417 case RACFG_CMD_E2PROM_READ16:
4419 USHORT offset, value, tmp;
4421 offset = ntohs(pRaCfg->status);
4422 /* "tmp" is expecially for some compilers... */
4423 RT28xx_EEPROM_READ16(pAdapter, offset, tmp);
4425 value = htons(value);
4427 ATEDBGPRINT(RT_DEBUG_TRACE,("EEPROM Read offset = 0x%04x, value = 0x%04x\n", offset, value));
4430 pRaCfg->length = htons(4);
4431 pRaCfg->status = htons(0);
4432 memcpy(pRaCfg->data, &value, 2);
4434 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
4435 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
4436 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
4438 ATEDBGPRINT(RT_DEBUG_TRACE, ("sizeof(struct ate_racfghdr) = %d\n", sizeof(struct ate_racfghdr)));
4439 ATEDBGPRINT(RT_DEBUG_TRACE, ("wrq->u.data.length = %d\n", wrq->u.data.length));
4441 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
4443 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_E2PROM_READ16\n"));
4448 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_E2PROM_READ16 is done !\n"));
4453 case RACFG_CMD_E2PROM_WRITE16:
4455 USHORT offset, value;
4457 offset = ntohs(pRaCfg->status);
4458 memcpy(&value, pRaCfg->data, 2);
4459 value = ntohs(value);
4460 RT28xx_EEPROM_WRITE16(pAdapter, offset, value);
4463 pRaCfg->length = htons(2);
4464 pRaCfg->status = htons(0);
4465 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
4466 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
4467 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
4469 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
4471 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_E2PROM_WRITE16\n"));
4476 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_E2PROM_WRITE16 is done !\n"));
4481 case RACFG_CMD_E2PROM_READ_ALL:
4483 USHORT buffer[EEPROM_SIZE/2];
4485 rt_ee_read_all(pAdapter,(USHORT *)buffer);
4486 memcpy_exs(pAdapter, pRaCfg->data, (UCHAR *)buffer, EEPROM_SIZE);
4489 pRaCfg->length = htons(2+EEPROM_SIZE);
4490 pRaCfg->status = htons(0);
4491 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
4492 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
4493 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
4495 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
4497 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_E2PROM_READ_ALL\n"));
4502 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_E2PROM_READ_ALL is done !\n"));
4507 case RACFG_CMD_E2PROM_WRITE_ALL:
4509 USHORT buffer[EEPROM_SIZE/2];
4511 NdisZeroMemory((UCHAR *)buffer, EEPROM_SIZE);
4512 memcpy_exs(pAdapter, (UCHAR *)buffer, (UCHAR *)&pRaCfg->status, EEPROM_SIZE);
4513 rt_ee_write_all(pAdapter,(USHORT *)buffer);
4516 pRaCfg->length = htons(2);
4517 pRaCfg->status = htons(0);
4518 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
4519 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
4520 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
4522 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
4524 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_E2PROM_WRITE_ALL\n"));
4529 ATEDBGPRINT(RT_DEBUG_ERROR, ("RACFG_CMD_E2PROM_WRITE_ALL is done !\n"));
4535 case RACFG_CMD_IO_READ:
4540 memcpy(&offset, &pRaCfg->status, 4);
4541 offset = ntohl(offset);
4543 // We do not need the base address.
4544 // So just extract the offset out.
4545 offset &= 0x0000FFFF;
4546 RTMP_IO_READ32(pAdapter, offset, &value);
4547 value = htonl(value);
4550 pRaCfg->length = htons(6);
4551 pRaCfg->status = htons(0);
4552 memcpy(pRaCfg->data, &value, 4);
4554 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
4555 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
4556 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
4558 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
4560 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_IO_READ\n"));
4565 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_IO_READ is done !\n"));
4570 case RACFG_CMD_IO_WRITE:
4572 UINT32 offset, value;
4574 memcpy(&offset, pRaCfg->data-2, 4);
4575 memcpy(&value, pRaCfg->data+2, 4);
4577 offset = ntohl(offset);
4579 // We do not need the base address.
4580 // So just extract out the offset.
4581 offset &= 0x0000FFFF;
4582 value = ntohl(value);
4583 ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_IO_WRITE: offset = %x, value = %x\n", offset, value));
4584 RTMP_IO_WRITE32(pAdapter, offset, value);
4587 pRaCfg->length = htons(2);
4588 pRaCfg->status = htons(0);
4589 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
4590 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
4591 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
4593 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
4595 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_IO_WRITE\n"));
4600 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_IO_WRITE is done !\n"));
4605 case RACFG_CMD_IO_READ_BULK:
4610 memcpy(&offset, &pRaCfg->status, 4);
4611 offset = ntohl(offset);
4613 // We do not need the base address.
4614 // So just extract the offset.
4615 offset &= 0x0000FFFF;
4616 memcpy(&len, pRaCfg->data+2, 2);
4621 ATEDBGPRINT(RT_DEBUG_TRACE,("len is too large, make it smaller\n"));
4622 pRaCfg->length = htons(2);
4623 pRaCfg->status = htons(1);
4627 RTMP_IO_READ_BULK(pAdapter, pRaCfg->data, (UCHAR *)offset, len*4);// unit in four bytes
4630 pRaCfg->length = htons(2+len*4);// unit in four bytes
4631 pRaCfg->status = htons(0);
4632 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
4633 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
4634 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
4636 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
4638 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_IO_READ_BULK\n"));
4643 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_IO_READ_BULK is done !\n"));
4648 case RACFG_CMD_BBP_READ8:
4654 offset = ntohs(pRaCfg->status);
4656 if (ATE_ON(pAdapter))
4658 ATE_BBP_IO_READ8_BY_REG_ID(pAdapter, offset, &value);
4662 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, offset, &value);
4665 pRaCfg->length = htons(3);
4666 pRaCfg->status = htons(0);
4667 pRaCfg->data[0] = value;
4669 ATEDBGPRINT(RT_DEBUG_TRACE,("BBP value = %x\n", value));
4671 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
4672 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
4673 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
4675 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
4677 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_BBP_READ8\n"));
4682 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_BBP_READ8 is done !\n"));
4686 case RACFG_CMD_BBP_WRITE8:
4691 offset = ntohs(pRaCfg->status);
4692 memcpy(&value, pRaCfg->data, 1);
4694 if (ATE_ON(pAdapter))
4696 ATE_BBP_IO_WRITE8_BY_REG_ID(pAdapter, offset, value);
4700 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, offset, value);
4703 if ((offset == BBP_R1) || (offset == BBP_R3))
4705 SyncTxRxConfig(pAdapter, offset, value);
4709 pRaCfg->length = htons(2);
4710 pRaCfg->status = htons(0);
4711 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
4712 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
4713 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
4715 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
4717 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_BBP_WRITE8\n"));
4722 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_BBP_WRITE8 is done !\n"));
4727 case RACFG_CMD_BBP_READ_ALL:
4731 for (j = 0; j < 137; j++)
4733 pRaCfg->data[j] = 0;
4735 if (ATE_ON(pAdapter))
4737 ATE_BBP_IO_READ8_BY_REG_ID(pAdapter, j, &pRaCfg->data[j]);
4741 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, j, &pRaCfg->data[j]);
4746 pRaCfg->length = htons(2+137);
4747 pRaCfg->status = htons(0);
4749 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
4750 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
4751 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
4753 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
4755 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_BBP_READ_ALL\n"));
4760 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_BBP_READ_ALL is done !\n"));
4766 case RACFG_CMD_ATE_E2PROM_READ_BULK:
4770 USHORT buffer[EEPROM_SIZE/2];
4772 offset = ntohs(pRaCfg->status);
4773 memcpy(&len, pRaCfg->data, 2);
4776 rt_ee_read_all(pAdapter,(USHORT *)buffer);
4777 if (offset + len <= EEPROM_SIZE)
4778 memcpy_exs(pAdapter, pRaCfg->data, (UCHAR *)buffer+offset, len);
4780 ATEDBGPRINT(RT_DEBUG_ERROR, ("exceed EEPROM size\n"));
4783 pRaCfg->length = htons(2+len);
4784 pRaCfg->status = htons(0);
4785 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
4786 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
4787 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
4789 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
4791 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_E2PROM_READ_BULK\n"));
4796 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_E2PROM_READ_BULK is done !\n"));
4802 case RACFG_CMD_ATE_E2PROM_WRITE_BULK:
4806 USHORT buffer[EEPROM_SIZE/2];
4808 offset = ntohs(pRaCfg->status);
4809 memcpy(&len, pRaCfg->data, 2);
4812 rt_ee_read_all(pAdapter,(USHORT *)buffer);
4813 memcpy_exs(pAdapter, (UCHAR *)buffer + offset, (UCHAR *)pRaCfg->data + 2, len);
4814 rt_ee_write_all(pAdapter,(USHORT *)buffer);
4817 pRaCfg->length = htons(2);
4818 pRaCfg->status = htons(0);
4819 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
4820 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
4821 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
4822 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
4824 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_E2PROM_WRITE_BULK\n"));
4829 ATEDBGPRINT(RT_DEBUG_ERROR, ("RACFG_CMD_ATE_E2PROM_WRITE_BULK is done !\n"));
4835 case RACFG_CMD_ATE_IO_WRITE_BULK:
4837 UINT32 offset, i, value;
4840 memcpy(&offset, &pRaCfg->status, 4);
4841 offset = ntohl(offset);
4842 memcpy(&len, pRaCfg->data+2, 2);
4845 for (i = 0; i < len; i += 4)
4847 memcpy_exl(pAdapter, (UCHAR *)&value, pRaCfg->data+4+i, 4);
4848 printk("Write %x %x\n", offset + i, value);
4849 RTMP_IO_WRITE32(pAdapter, (offset +i) & 0xffff, value);
4853 pRaCfg->length = htons(2);
4854 pRaCfg->status = htons(0);
4855 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
4856 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
4857 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
4858 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
4860 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_IO_WRITE_BULK\n"));
4865 ATEDBGPRINT(RT_DEBUG_ERROR, ("RACFG_CMD_ATE_IO_WRITE_BULK is done !\n"));
4871 case RACFG_CMD_ATE_BBP_READ_BULK:
4877 offset = ntohs(pRaCfg->status);
4878 memcpy(&len, pRaCfg->data, 2);
4882 for (j = offset; j < (offset+len); j++)
4884 pRaCfg->data[j - offset] = 0;
4886 if (pAdapter->ate.Mode == ATE_STOP)
4888 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, j, &pRaCfg->data[j - offset]);
4892 ATE_BBP_IO_READ8_BY_REG_ID(pAdapter, j, &pRaCfg->data[j - offset]);
4897 pRaCfg->length = htons(2+len);
4898 pRaCfg->status = htons(0);
4899 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
4900 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
4901 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
4903 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
4905 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_BBP_READ_BULK\n"));
4910 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_BBP_READ_BULK is done !\n"));
4916 case RACFG_CMD_ATE_BBP_WRITE_BULK:
4923 offset = ntohs(pRaCfg->status);
4924 memcpy(&len, pRaCfg->data, 2);
4927 for (j = offset; j < (offset+len); j++)
4929 value = pRaCfg->data + 2 + (j - offset);
4930 if (pAdapter->ate.Mode == ATE_STOP)
4932 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, j, *value);
4936 ATE_BBP_IO_WRITE8_BY_REG_ID(pAdapter, j, *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);
4947 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
4949 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_BBP_WRITE_BULK\n"));
4954 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_BBP_WRITE_BULK is done !\n"));
4959 #ifdef CONFIG_RALINK_RT3052
4960 case RACFG_CMD_ATE_RF_READ_BULK:
4966 offset = ntohs(pRaCfg->status);
4967 memcpy(&len, pRaCfg->data, 2);
4970 for (j = offset; j < (offset+len); j++)
4972 pRaCfg->data[j - offset] = 0;
4973 RT30xxReadRFRegister(pAdapter, j, &pRaCfg->data[j - offset]);
4977 pRaCfg->length = htons(2+len);
4978 pRaCfg->status = htons(0);
4979 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
4980 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
4981 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
4983 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
4985 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_RF_READ_BULK\n"));
4990 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_RF_READ_BULK is done !\n"));
4996 case RACFG_CMD_ATE_RF_WRITE_BULK:
5003 offset = ntohs(pRaCfg->status);
5004 memcpy(&len, pRaCfg->data, 2);
5007 for (j = offset; j < (offset+len); j++)
5009 value = pRaCfg->data + 2 + (j - offset);
5010 RT30xxWriteRFRegister(pAdapter, j, *value);
5014 pRaCfg->length = htons(2);
5015 pRaCfg->status = htons(0);
5016 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
5017 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
5018 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
5020 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
5022 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_RF_WRITE_BULK\n"));
5027 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_RF_WRITE_BULK is done !\n"));
5035 case RACFG_CMD_GET_NOISE_LEVEL:
5038 INT32 buffer[3][10];/* 3 : RxPath ; 10 : no. of per rssi samples */
5040 channel = (ntohs(pRaCfg->status) & 0x00FF);
5041 CalNoiseLevel(pAdapter, channel, buffer);
5042 memcpy_exl(pAdapter, (UCHAR *)pRaCfg->data, (UCHAR *)&(buffer[0][0]), (sizeof(INT32)*3*10));
5045 pRaCfg->length = htons(2 + (sizeof(INT32)*3*10));
5046 pRaCfg->status = htons(0);
5047 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
5048 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
5049 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
5051 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
5053 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_GET_NOISE_LEVEL\n"));
5058 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_GET_NOISE_LEVEL is done !\n"));
5063 case RACFG_CMD_GET_COUNTER:
5065 memcpy_exl(pAdapter, &pRaCfg->data[0], (UCHAR *)&pAdapter->ate.U2M, 4);
5066 memcpy_exl(pAdapter, &pRaCfg->data[4], (UCHAR *)&pAdapter->ate.OtherData, 4);
5067 memcpy_exl(pAdapter, &pRaCfg->data[8], (UCHAR *)&pAdapter->ate.Beacon, 4);
5068 memcpy_exl(pAdapter, &pRaCfg->data[12], (UCHAR *)&pAdapter->ate.OtherCount, 4);
5069 memcpy_exl(pAdapter, &pRaCfg->data[16], (UCHAR *)&pAdapter->ate.TxAc0, 4);
5070 memcpy_exl(pAdapter, &pRaCfg->data[20], (UCHAR *)&pAdapter->ate.TxAc1, 4);
5071 memcpy_exl(pAdapter, &pRaCfg->data[24], (UCHAR *)&pAdapter->ate.TxAc2, 4);
5072 memcpy_exl(pAdapter, &pRaCfg->data[28], (UCHAR *)&pAdapter->ate.TxAc3, 4);
5073 memcpy_exl(pAdapter, &pRaCfg->data[32], (UCHAR *)&pAdapter->ate.TxHCCA, 4);
5074 memcpy_exl(pAdapter, &pRaCfg->data[36], (UCHAR *)&pAdapter->ate.TxMgmt, 4);
5075 memcpy_exl(pAdapter, &pRaCfg->data[40], (UCHAR *)&pAdapter->ate.RSSI0, 4);
5076 memcpy_exl(pAdapter, &pRaCfg->data[44], (UCHAR *)&pAdapter->ate.RSSI1, 4);
5077 memcpy_exl(pAdapter, &pRaCfg->data[48], (UCHAR *)&pAdapter->ate.RSSI2, 4);
5078 memcpy_exl(pAdapter, &pRaCfg->data[52], (UCHAR *)&pAdapter->ate.SNR0, 4);
5079 memcpy_exl(pAdapter, &pRaCfg->data[56], (UCHAR *)&pAdapter->ate.SNR1, 4);
5081 pRaCfg->length = htons(2+60);
5082 pRaCfg->status = htons(0);
5083 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
5084 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
5085 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
5087 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
5089 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_GET_COUNTER\n"));
5094 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_GET_COUNTER is done !\n"));
5099 case RACFG_CMD_CLEAR_COUNTER:
5101 pAdapter->ate.U2M = 0;
5102 pAdapter->ate.OtherData = 0;
5103 pAdapter->ate.Beacon = 0;
5104 pAdapter->ate.OtherCount = 0;
5105 pAdapter->ate.TxAc0 = 0;
5106 pAdapter->ate.TxAc1 = 0;
5107 pAdapter->ate.TxAc2 = 0;
5108 pAdapter->ate.TxAc3 = 0;
5109 pAdapter->ate.TxHCCA = 0;
5110 pAdapter->ate.TxMgmt = 0;
5111 pAdapter->ate.TxDoneCount = 0;
5113 pRaCfg->length = htons(2);
5114 pRaCfg->status = htons(0);
5116 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
5117 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
5118 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
5120 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
5122 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_CLEAR_COUNTER\n"));
5127 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_CLEAR_COUNTER is done !\n"));
5133 case RACFG_CMD_TX_START:
5137 UCHAR Bbp22Value = 0, Bbp24Value = 0;
5139 if ((pAdapter->ate.TxStatus != 0) && (pAdapter->ate.Mode & ATE_TXFRAME))
5141 ATEDBGPRINT(RT_DEBUG_TRACE,("Ate Tx is already running, to run next Tx, you must stop it first\n"));
5143 goto TX_START_ERROR;
5145 else if ((pAdapter->ate.TxStatus != 0) && !(pAdapter->ate.Mode & ATE_TXFRAME))
5149 while ((i++ < 10) && (pAdapter->ate.TxStatus != 0))
5151 RTMPusecDelay(5000);
5155 pAdapter->ate.TxStatus = 0;
5156 pAdapter->ate.TxDoneCount = 0;
5157 //pAdapter->ate.Repeat = 0;
5158 pAdapter->ate.bQATxStart = FALSE;
5161 // If pRaCfg->length == 0, this "RACFG_CMD_TX_START" is for Carrier test or Carrier Suppression.
5162 if (ntohs(pRaCfg->length) != 0)
5166 NdisMoveMemory(&pAdapter->ate.TxInfo, pRaCfg->data - 2, 4);
5167 #ifdef RT_BIG_ENDIAN
5168 RTMPDescriptorEndianChange((PUCHAR) &pAdapter->ate.TxInfo, TYPE_TXINFO);
5169 #endif // RT_BIG_ENDIAN //
5172 NdisMoveMemory(&pAdapter->ate.TxWI, pRaCfg->data + 2, 16);
5173 #ifdef RT_BIG_ENDIAN
5174 RTMPWIEndianChange((PUCHAR)&pAdapter->ate.TxWI, TYPE_TXWI);
5175 #endif // RT_BIG_ENDIAN //
5177 NdisMoveMemory(&pAdapter->ate.TxCount, pRaCfg->data + 18, 4);
5178 pAdapter->ate.TxCount = ntohl(pAdapter->ate.TxCount);
5180 p = (USHORT *)(&pRaCfg->data[22]);
5181 //p = pRaCfg->data + 22;
5182 // always use QID_AC_BE
5183 pAdapter->ate.QID = 0;
5184 p = (USHORT *)(&pRaCfg->data[24]);
5185 //p = pRaCfg->data + 24;
5186 pAdapter->ate.HLen = ntohs(*p);
5188 if (pAdapter->ate.HLen > 32)
5190 ATEDBGPRINT(RT_DEBUG_ERROR,("pAdapter->ate.HLen > 32\n"));
5192 goto TX_START_ERROR;
5195 NdisMoveMemory(&pAdapter->ate.Header, pRaCfg->data + 26, pAdapter->ate.HLen);
5198 pAdapter->ate.PLen = ntohs(pRaCfg->length) - (pAdapter->ate.HLen + 28);
5200 if (pAdapter->ate.PLen > 32)
5202 ATEDBGPRINT(RT_DEBUG_ERROR,("pAdapter->ate.PLen > 32\n"));
5204 goto TX_START_ERROR;
5207 NdisMoveMemory(&pAdapter->ate.Pattern, pRaCfg->data + 26 + pAdapter->ate.HLen, pAdapter->ate.PLen);
5208 pAdapter->ate.DLen = pAdapter->ate.TxWI.MPDUtotalByteCount - pAdapter->ate.HLen;
5211 ATE_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R22, &Bbp22Value);
5217 if (pAdapter->ate.TxCount == 0)
5220 ATEDBGPRINT(RT_DEBUG_TRACE,("START TXFRAME\n"));
5221 pAdapter->ate.bQATxStart = TRUE;
5222 Set_ATE_Proc(pAdapter, "TXFRAME");
5226 case BBP22_TXCONT_OR_CARRSUPP:
5228 ATEDBGPRINT(RT_DEBUG_TRACE,("BBP22_TXCONT_OR_CARRSUPP\n"));
5229 ATE_BBP_IO_READ8_BY_REG_ID(pAdapter, 24, &Bbp24Value);
5235 ATEDBGPRINT(RT_DEBUG_TRACE,("START TXCONT\n"));
5236 pAdapter->ate.bQATxStart = TRUE;
5237 Set_ATE_Proc(pAdapter, "TXCONT");
5241 case BBP24_CARRSUPP:
5243 ATEDBGPRINT(RT_DEBUG_TRACE,("START TXCARRSUPP\n"));
5244 pAdapter->ate.bQATxStart = TRUE;
5245 pAdapter->ate.Mode |= ATE_TXCARRSUPP;
5251 ATEDBGPRINT(RT_DEBUG_ERROR,("Unknown Start TX subtype !"));
5260 ATEDBGPRINT(RT_DEBUG_TRACE,("START TXCARR\n"));
5261 pAdapter->ate.bQATxStart = TRUE;
5262 Set_ATE_Proc(pAdapter, "TXCARR");
5268 ATEDBGPRINT(RT_DEBUG_ERROR,("Unknown Start TX subtype !"));
5273 if (pAdapter->ate.bQATxStart == TRUE)
5276 pRaCfg->length = htons(2);
5277 pRaCfg->status = htons(0);
5279 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
5280 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
5281 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
5283 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
5285 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() was failed in case RACFG_CMD_TX_START\n"));
5290 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_TX_START is done !\n"));
5297 pRaCfg->length = htons(2);
5298 pRaCfg->status = htons(err);
5300 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
5301 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
5302 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
5303 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
5305 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_TX_START\n"));
5310 ATEDBGPRINT(RT_DEBUG_TRACE, ("feedback of TX_START_ERROR is done !\n"));
5315 case RACFG_CMD_GET_TX_STATUS:
5320 pRaCfg->length = htons(6);
5321 pRaCfg->status = htons(0);
5322 count = htonl(pAdapter->ate.TxDoneCount);
5323 NdisMoveMemory(pRaCfg->data, &count, 4);
5324 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
5325 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
5326 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
5328 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
5330 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_GET_TX_STATUS\n"));
5335 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_GET_TX_STATUS is done !\n"));
5340 case RACFG_CMD_TX_STOP:
5342 ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_TX_STOP\n"));
5344 Set_ATE_Proc(pAdapter, "TXSTOP");
5347 pRaCfg->length = htons(2);
5348 pRaCfg->status = htons(0);
5349 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
5350 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
5351 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
5353 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
5355 ATEDBGPRINT(RT_DEBUG_TRACE, ("copy_to_user() fail in case RACFG_CMD_TX_STOP\n"));
5360 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_TX_STOP is done !\n"));
5365 case RACFG_CMD_RX_START:
5367 ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_RX_START\n"));
5369 pAdapter->ate.bQARxStart = TRUE;
5370 Set_ATE_Proc(pAdapter, "RXFRAME");
5373 pRaCfg->length = htons(2);
5374 pRaCfg->status = htons(0);
5375 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
5376 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
5377 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
5379 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
5381 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_RX_START\n"));
5386 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_RX_START is done !\n"));
5391 case RACFG_CMD_RX_STOP:
5393 ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_RX_STOP\n"));
5395 Set_ATE_Proc(pAdapter, "RXSTOP");
5398 pRaCfg->length = htons(2);
5399 pRaCfg->status = htons(0);
5400 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
5401 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
5402 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
5404 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
5406 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_RX_STOP\n"));
5411 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_RX_STOP is done !\n"));
5416 /* The following cases are for new ATE GUI(not QA). */
5417 /*==================================================*/
5418 case RACFG_CMD_ATE_START_TX_CARRIER:
5420 ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_ATE_START_TX_CARRIER\n"));
5422 Set_ATE_Proc(pAdapter, "TXCARR");
5424 pRaCfg->length = htons(2);
5425 pRaCfg->status = htons(0);
5427 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
5428 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
5429 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
5431 ATEDBGPRINT(RT_DEBUG_TRACE, ("wrq->u.data.length = %d\n", wrq->u.data.length));
5433 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
5435 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_START_TX_CARRIER\n"));
5440 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_START_TX_CARRIER is done !\n"));
5445 case RACFG_CMD_ATE_START_TX_CONT:
5447 ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_ATE_START_TX_CONT\n"));
5449 Set_ATE_Proc(pAdapter, "TXCONT");
5451 pRaCfg->length = htons(2);
5452 pRaCfg->status = htons(0);
5454 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
5455 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
5456 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
5458 ATEDBGPRINT(RT_DEBUG_TRACE, ("wrq->u.data.length = %d\n", wrq->u.data.length));
5460 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
5462 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_START_TX_CONT\n"));
5467 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_START_TX_CONT is done !\n"));
5472 case RACFG_CMD_ATE_START_TX_FRAME:
5474 ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_ATE_START_TX_FRAME\n"));
5476 Set_ATE_Proc(pAdapter, "TXFRAME");
5478 pRaCfg->length = htons(2);
5479 pRaCfg->status = htons(0);
5481 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
5482 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
5483 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
5485 ATEDBGPRINT(RT_DEBUG_TRACE, ("wrq->u.data.length = %d\n", wrq->u.data.length));
5487 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
5489 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_START_TX_FRAME\n"));
5494 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_START_TX_FRAME is done !\n"));
5499 case RACFG_CMD_ATE_SET_BW:
5502 UCHAR str[LEN_OF_ARG];
5504 NdisZeroMemory(str, LEN_OF_ARG);
5506 ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_ATE_SET_BW\n"));
5508 memcpy((PUCHAR)&value, (PUCHAR)&(pRaCfg->status), 2);
5509 value = ntohs(value);
5510 sprintf((PCHAR)str, "%d", value);
5512 Set_ATE_TX_BW_Proc(pAdapter, str);
5515 pRaCfg->length = htons(2);
5516 pRaCfg->status = htons(0);
5517 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
5518 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
5519 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->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_SET_BW\n"));
5528 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_SET_BW is done !\n"));
5533 case RACFG_CMD_ATE_SET_TX_POWER0:
5536 UCHAR str[LEN_OF_ARG];
5538 NdisZeroMemory(str, LEN_OF_ARG);
5540 ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_ATE_SET_TX_POWER0\n"));
5542 memcpy((PUCHAR)&value, (PUCHAR)&(pRaCfg->status), 2);
5543 value = ntohs(value);
5544 sprintf((PCHAR)str, "%d", value);
5545 Set_ATE_TX_POWER0_Proc(pAdapter, str);
5548 pRaCfg->length = htons(2);
5549 pRaCfg->status = htons(0);
5550 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
5551 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
5552 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
5554 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
5556 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_SET_TX_POWER0\n"));
5561 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_SET_TX_POWER0 is done !\n"));
5566 case RACFG_CMD_ATE_SET_TX_POWER1:
5569 UCHAR str[LEN_OF_ARG];
5571 NdisZeroMemory(str, LEN_OF_ARG);
5573 ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_ATE_SET_TX_POWER1\n"));
5575 memcpy((PUCHAR)&value, (PUCHAR)&(pRaCfg->status), 2);
5576 value = ntohs(value);
5577 sprintf((PCHAR)str, "%d", value);
5578 Set_ATE_TX_POWER1_Proc(pAdapter, str);
5581 pRaCfg->length = htons(2);
5582 pRaCfg->status = htons(0);
5583 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
5584 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
5585 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
5587 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
5589 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_SET_TX_POWER1\n"));
5594 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_SET_TX_POWER1 is done !\n"));
5599 case RACFG_CMD_ATE_SET_FREQ_OFFSET:
5602 UCHAR str[LEN_OF_ARG];
5604 NdisZeroMemory(str, LEN_OF_ARG);
5606 ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_ATE_SET_FREQ_OFFSET\n"));
5608 memcpy((PUCHAR)&value, (PUCHAR)&(pRaCfg->status), 2);
5609 value = ntohs(value);
5610 sprintf((PCHAR)str, "%d", value);
5611 Set_ATE_TX_FREQOFFSET_Proc(pAdapter, str);
5614 pRaCfg->length = htons(2);
5615 pRaCfg->status = htons(0);
5616 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
5617 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
5618 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
5620 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
5622 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_SET_FREQ_OFFSET\n"));
5627 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_SET_FREQ_OFFSET is done !\n"));
5632 case RACFG_CMD_ATE_GET_STATISTICS:
5634 ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_ATE_GET_STATISTICS\n"));
5636 memcpy_exl(pAdapter, &pRaCfg->data[0], (UCHAR *)&pAdapter->ate.TxDoneCount, 4);
5637 memcpy_exl(pAdapter, &pRaCfg->data[4], (UCHAR *)&pAdapter->WlanCounters.RetryCount.u.LowPart, 4);
5638 memcpy_exl(pAdapter, &pRaCfg->data[8], (UCHAR *)&pAdapter->WlanCounters.FailedCount.u.LowPart, 4);
5639 memcpy_exl(pAdapter, &pRaCfg->data[12], (UCHAR *)&pAdapter->WlanCounters.RTSSuccessCount.u.LowPart, 4);
5640 memcpy_exl(pAdapter, &pRaCfg->data[16], (UCHAR *)&pAdapter->WlanCounters.RTSFailureCount.u.LowPart, 4);
5641 memcpy_exl(pAdapter, &pRaCfg->data[20], (UCHAR *)&pAdapter->WlanCounters.ReceivedFragmentCount.QuadPart, 4);
5642 memcpy_exl(pAdapter, &pRaCfg->data[24], (UCHAR *)&pAdapter->WlanCounters.FCSErrorCount.u.LowPart, 4);
5643 memcpy_exl(pAdapter, &pRaCfg->data[28], (UCHAR *)&pAdapter->Counters8023.RxNoBuffer, 4);
5644 memcpy_exl(pAdapter, &pRaCfg->data[32], (UCHAR *)&pAdapter->WlanCounters.FrameDuplicateCount.u.LowPart, 4);
5645 memcpy_exl(pAdapter, &pRaCfg->data[36], (UCHAR *)&pAdapter->RalinkCounters.OneSecFalseCCACnt, 4);
5647 if (pAdapter->ate.RxAntennaSel == 0)
5653 RSSI0 = (INT32)(pAdapter->ate.LastRssi0 - pAdapter->BbpRssiToDbmDelta);
5654 RSSI1 = (INT32)(pAdapter->ate.LastRssi1 - pAdapter->BbpRssiToDbmDelta);
5655 RSSI2 = (INT32)(pAdapter->ate.LastRssi2 - pAdapter->BbpRssiToDbmDelta);
5656 memcpy_exl(pAdapter, &pRaCfg->data[40], (UCHAR *)&RSSI0, 4);
5657 memcpy_exl(pAdapter, &pRaCfg->data[44], (UCHAR *)&RSSI1, 4);
5658 memcpy_exl(pAdapter, &pRaCfg->data[48], (UCHAR *)&RSSI2, 4);
5659 pRaCfg->length = htons(2+52);
5665 RSSI0 = (INT32)(pAdapter->ate.LastRssi0 - pAdapter->BbpRssiToDbmDelta);
5666 memcpy_exl(pAdapter, &pRaCfg->data[40], (UCHAR *)&RSSI0, 4);
5667 pRaCfg->length = htons(2+44);
5669 pRaCfg->status = htons(0);
5670 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
5671 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
5672 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
5674 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
5676 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_GET_STATISTICS\n"));
5681 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_GET_STATISTICS is done !\n"));
5686 case RACFG_CMD_ATE_RESET_COUNTER:
5689 UCHAR str[LEN_OF_ARG];
5691 NdisZeroMemory(str, LEN_OF_ARG);
5693 ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_ATE_RESET_COUNTER\n"));
5695 sprintf((PCHAR)str, "%d", value);
5696 Set_ResetStatCounter_Proc(pAdapter, str);
5698 pAdapter->ate.TxDoneCount = 0;
5700 pRaCfg->length = htons(2);
5701 pRaCfg->status = htons(0);
5703 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
5704 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
5705 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
5707 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
5709 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_RESET_COUNTER\n"));
5714 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_RESET_COUNTER is done !\n"));
5720 case RACFG_CMD_ATE_SEL_TX_ANTENNA:
5723 UCHAR str[LEN_OF_ARG];
5725 NdisZeroMemory(str, LEN_OF_ARG);
5727 ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_ATE_SEL_TX_ANTENNA\n"));
5729 memcpy((PUCHAR)&value, (PUCHAR)&(pRaCfg->status), 2);
5730 value = ntohs(value);
5731 sprintf((PCHAR)str, "%d", value);
5732 Set_ATE_TX_Antenna_Proc(pAdapter, str);
5735 pRaCfg->length = htons(2);
5736 pRaCfg->status = htons(0);
5737 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
5738 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
5739 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
5741 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
5743 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_SEL_TX_ANTENNA\n"));
5748 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_SEL_TX_ANTENNA is done !\n"));
5753 case RACFG_CMD_ATE_SEL_RX_ANTENNA:
5756 UCHAR str[LEN_OF_ARG];
5758 NdisZeroMemory(str, LEN_OF_ARG);
5760 ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_ATE_SEL_RX_ANTENNA\n"));
5762 memcpy((PUCHAR)&value, (PUCHAR)&(pRaCfg->status), 2);
5763 value = ntohs(value);
5764 sprintf((PCHAR)str, "%d", value);
5765 Set_ATE_RX_Antenna_Proc(pAdapter, str);
5768 pRaCfg->length = htons(2);
5769 pRaCfg->status = htons(0);
5770 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
5771 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
5772 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
5774 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
5776 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_SEL_RX_ANTENNA\n"));
5781 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_SEL_RX_ANTENNA is done !\n"));
5786 case RACFG_CMD_ATE_SET_PREAMBLE:
5789 UCHAR str[LEN_OF_ARG];
5791 NdisZeroMemory(str, LEN_OF_ARG);
5793 ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_ATE_SET_PREAMBLE\n"));
5795 memcpy((PUCHAR)&value, (PUCHAR)&(pRaCfg->status), 2);
5796 value = ntohs(value);
5797 sprintf((PCHAR)str, "%d", value);
5798 Set_ATE_TX_MODE_Proc(pAdapter, str);
5801 pRaCfg->length = htons(2);
5802 pRaCfg->status = htons(0);
5803 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
5804 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
5805 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
5807 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
5809 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_SET_PREAMBLE\n"));
5814 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_SET_PREAMBLE is done !\n"));
5819 case RACFG_CMD_ATE_SET_CHANNEL:
5822 UCHAR str[LEN_OF_ARG];
5824 NdisZeroMemory(str, LEN_OF_ARG);
5826 ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_ATE_SET_CHANNEL\n"));
5828 memcpy((PUCHAR)&value, (PUCHAR)&(pRaCfg->status), 2);
5829 value = ntohs(value);
5830 sprintf((PCHAR)str, "%d", value);
5831 Set_ATE_CHANNEL_Proc(pAdapter, str);
5834 pRaCfg->length = htons(2);
5835 pRaCfg->status = htons(0);
5836 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
5837 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
5838 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
5840 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
5842 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_SET_CHANNEL\n"));
5847 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_SET_CHANNEL is done !\n"));
5852 case RACFG_CMD_ATE_SET_ADDR1:
5854 ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_ATE_SET_ADDR1\n"));
5856 // Addr is an array of UCHAR,
5857 // so no need to perform endian swap.
5858 memcpy(pAdapter->ate.Addr1, (PUCHAR)(pRaCfg->data - 2), MAC_ADDR_LEN);
5861 pRaCfg->length = htons(2);
5862 pRaCfg->status = htons(0);
5863 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
5864 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
5865 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
5867 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
5869 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_SET_ADDR1\n"));
5874 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_SET_ADDR1 is done !\n (ADDR1 = %2X:%2X:%2X:%2X:%2X:%2X)\n", pAdapter->ate.Addr1[0],
5875 pAdapter->ate.Addr1[1], pAdapter->ate.Addr1[2], pAdapter->ate.Addr1[3], pAdapter->ate.Addr1[4], pAdapter->ate.Addr1[5]));
5880 case RACFG_CMD_ATE_SET_ADDR2:
5882 ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_ATE_SET_ADDR2\n"));
5884 // Addr is an array of UCHAR,
5885 // so no need to perform endian swap.
5886 memcpy(pAdapter->ate.Addr2, (PUCHAR)(pRaCfg->data - 2), MAC_ADDR_LEN);
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_ADDR2\n"));
5902 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_SET_ADDR2 is done !\n (ADDR2 = %2X:%2X:%2X:%2X:%2X:%2X)\n", pAdapter->ate.Addr2[0],
5903 pAdapter->ate.Addr2[1], pAdapter->ate.Addr2[2], pAdapter->ate.Addr2[3], pAdapter->ate.Addr2[4], pAdapter->ate.Addr2[5]));
5908 case RACFG_CMD_ATE_SET_ADDR3:
5910 ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_ATE_SET_ADDR3\n"));
5912 // Addr is an array of UCHAR,
5913 // so no need to perform endian swap.
5914 memcpy(pAdapter->ate.Addr3, (PUCHAR)(pRaCfg->data - 2), MAC_ADDR_LEN);
5917 pRaCfg->length = htons(2);
5918 pRaCfg->status = htons(0);
5919 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
5920 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
5921 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
5923 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
5925 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_SET_ADDR3\n"));
5930 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_SET_ADDR3 is done !\n (ADDR3 = %2X:%2X:%2X:%2X:%2X:%2X)\n", pAdapter->ate.Addr3[0],
5931 pAdapter->ate.Addr3[1], pAdapter->ate.Addr3[2], pAdapter->ate.Addr3[3], pAdapter->ate.Addr3[4], pAdapter->ate.Addr3[5]));
5936 case RACFG_CMD_ATE_SET_RATE:
5939 UCHAR str[LEN_OF_ARG];
5941 NdisZeroMemory(str, LEN_OF_ARG);
5943 ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_ATE_SET_RATE\n"));
5945 memcpy((PUCHAR)&value, (PUCHAR)&(pRaCfg->status), 2);
5946 value = ntohs(value);
5947 sprintf((PCHAR)str, "%d", value);
5948 Set_ATE_TX_MCS_Proc(pAdapter, str);
5951 pRaCfg->length = htons(2);
5952 pRaCfg->status = htons(0);
5953 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
5954 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
5955 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
5957 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
5959 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_SET_RATE\n"));
5964 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_SET_RATE is done !\n"));
5969 case RACFG_CMD_ATE_SET_TX_FRAME_LEN:
5972 UCHAR str[LEN_OF_ARG];
5974 NdisZeroMemory(str, LEN_OF_ARG);
5976 ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_ATE_SET_TX_FRAME_LEN\n"));
5978 memcpy((PUCHAR)&value, (PUCHAR)&(pRaCfg->status), 2);
5979 value = ntohs(value);
5980 sprintf((PCHAR)str, "%d", value);
5981 Set_ATE_TX_LENGTH_Proc(pAdapter, str);
5984 pRaCfg->length = htons(2);
5985 pRaCfg->status = htons(0);
5986 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
5987 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
5988 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
5990 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
5992 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_SET_TX_FRAME_LEN\n"));
5997 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_SET_TX_FRAME_LEN is done !\n"));
6002 case RACFG_CMD_ATE_SET_TX_FRAME_COUNT:
6005 UCHAR str[LEN_OF_ARG];
6007 NdisZeroMemory(str, LEN_OF_ARG);
6009 ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_ATE_SET_TX_FRAME_COUNT\n"));
6011 memcpy((PUCHAR)&value, (PUCHAR)&(pRaCfg->status), 2);
6012 value = ntohs(value);
6014 sprintf((PCHAR)str, "%d", value);
6015 Set_ATE_TX_COUNT_Proc(pAdapter, str);
6019 pRaCfg->length = htons(2);
6020 pRaCfg->status = htons(0);
6021 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
6022 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
6023 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
6025 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
6027 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_SET_TX_FRAME_COUNT\n"));
6032 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_SET_TX_FRAME_COUNT is done !\n"));
6037 case RACFG_CMD_ATE_START_RX_FRAME:
6039 ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_RX_START\n"));
6041 Set_ATE_Proc(pAdapter, "RXFRAME");
6044 pRaCfg->length = htons(2);
6045 pRaCfg->status = htons(0);
6046 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
6047 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
6048 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
6050 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
6052 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_RX_START\n"));
6057 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_RX_START is done !\n"));
6064 ASSERT(pRaCfg != NULL);
6072 VOID BubbleSort(INT32 n, INT32 a[])
6076 for (k = n-1; k>0; k--)
6078 for (j = 0; j<k; j++)
6090 VOID CalNoiseLevel(PRTMP_ADAPTER pAd, UCHAR channel, INT32 RSSI[3][10])
6092 INT32 RSSI0, RSSI1, RSSI2;
6093 CHAR Rssi0Offset, Rssi1Offset, Rssi2Offset;
6094 UCHAR BbpR50Rssi0 = 0, BbpR51Rssi1 = 0, BbpR52Rssi2 = 0;
6095 UCHAR Org_BBP66value = 0, Org_BBP69value = 0, Org_BBP70value = 0, data = 0;
6096 USHORT LNA_Gain = 0;
6098 UCHAR Org_Channel = pAd->ate.Channel;
6099 USHORT GainValue = 0, OffsetValue = 0;
6101 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R66, &Org_BBP66value);
6102 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R69, &Org_BBP69value);
6103 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R70, &Org_BBP70value);
6105 //**********************************************************************
6106 // Read the value of LNA gain and Rssi offset
6107 //**********************************************************************
6108 RT28xx_EEPROM_READ16(pAd, EEPROM_LNA_OFFSET, GainValue);
6113 LNA_Gain = GainValue & 0x00FF;
6115 RT28xx_EEPROM_READ16(pAd, EEPROM_RSSI_BG_OFFSET, OffsetValue);
6116 Rssi0Offset = OffsetValue & 0x00FF;
6117 Rssi1Offset = (OffsetValue & 0xFF00) >> 8;
6118 RT28xx_EEPROM_READ16(pAd, (EEPROM_RSSI_BG_OFFSET + 2)/* 0x48 */, OffsetValue);
6119 Rssi2Offset = OffsetValue & 0x00FF;
6123 LNA_Gain = (GainValue & 0xFF00) >> 8;
6125 RT28xx_EEPROM_READ16(pAd, EEPROM_RSSI_A_OFFSET, OffsetValue);
6126 Rssi0Offset = OffsetValue & 0x00FF;
6127 Rssi1Offset = (OffsetValue & 0xFF00) >> 8;
6128 RT28xx_EEPROM_READ16(pAd, (EEPROM_RSSI_A_OFFSET + 2)/* 0x4C */, OffsetValue);
6129 Rssi2Offset = OffsetValue & 0x00FF;
6131 //**********************************************************************
6133 pAd->ate.Channel = channel;
6134 ATEAsicSwitchChannel(pAd);
6138 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R66, data);
6140 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R69, data);
6142 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R70, data);
6146 pAd->ate.bQARxStart = TRUE;
6147 Set_ATE_Proc(pAd, "RXFRAME");
6151 for (j = 0; j < 10; j++)
6153 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R50, &BbpR50Rssi0);
6154 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R51, &BbpR51Rssi1);
6155 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R52, &BbpR52Rssi2);
6160 if (BbpR50Rssi0 == 0)
6166 RSSI0 = (INT32)(-12 - BbpR50Rssi0 - LNA_Gain - Rssi0Offset);
6170 if ( pAd->Antenna.field.RxPath >= 2 ) // 2R
6173 if (BbpR51Rssi1 == 0)
6179 RSSI1 = (INT32)(-12 - BbpR51Rssi1 - LNA_Gain - Rssi1Offset);
6184 if ( pAd->Antenna.field.RxPath >= 3 ) // 3R
6187 if (BbpR52Rssi2 == 0)
6190 RSSI2 = (INT32)(-12 - BbpR52Rssi2 - LNA_Gain - Rssi2Offset);
6197 Set_ATE_Proc(pAd, "RXSTOP");
6201 BubbleSort(10, RSSI[0]); // 1R
6203 if ( pAd->Antenna.field.RxPath >= 2 ) // 2R
6205 BubbleSort(10, RSSI[1]);
6208 if ( pAd->Antenna.field.RxPath >= 3 ) // 3R
6210 BubbleSort(10, RSSI[2]);
6215 pAd->ate.Channel = Org_Channel;
6216 ATEAsicSwitchChannel(pAd);
6218 // Restore original value
6219 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R66, Org_BBP66value);
6220 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R69, Org_BBP69value);
6221 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R70, Org_BBP70value);
6226 BOOLEAN SyncTxRxConfig(PRTMP_ADAPTER pAd, USHORT offset, UCHAR value)
6228 UCHAR tmp = 0, bbp_data = 0;
6232 ATE_BBP_IO_READ8_BY_REG_ID(pAd, offset, &bbp_data);
6236 RTMP_BBP_IO_READ8_BY_REG_ID(pAd, offset, &bbp_data);
6240 ASSERT(bbp_data == value);
6245 /* Need to sync. tx configuration with legacy ATE. */
6246 tmp = (bbp_data & ((1 << 4) | (1 << 3))/* 0x18 */) >> 3;
6249 /* The BBP R1 bit[4:3] = 2 :: Both DACs will be used by QA. */
6252 pAd->ate.TxAntennaSel = 0;
6254 /* The BBP R1 bit[4:3] = 0 :: DAC 0 will be used by QA. */
6257 pAd->ate.TxAntennaSel = 1;
6259 /* The BBP R1 bit[4:3] = 1 :: DAC 1 will be used by QA. */
6262 pAd->ate.TxAntennaSel = 2;
6265 DBGPRINT(RT_DEBUG_TRACE, ("%s -- Sth. wrong! : return FALSE; \n", __func__));
6268 break;/* case BBP_R1 */
6271 /* Need to sync. rx configuration with legacy ATE. */
6272 tmp = (bbp_data & ((1 << 1) | (1 << 0))/* 0x03 */);
6275 /* The BBP R3 bit[1:0] = 3 :: All ADCs will be used by QA. */
6278 pAd->ate.RxAntennaSel = 0;
6280 /* The BBP R3 bit[1:0] = 0 :: ADC 0 will be used by QA, */
6281 /* unless the BBP R3 bit[4:3] = 2 */
6284 pAd->ate.RxAntennaSel = 1;
6285 tmp = ((bbp_data & ((1 << 4) | (1 << 3))/* 0x03 */) >> 3);
6288 /* Default : All ADCs will be used by QA */
6289 pAd->ate.RxAntennaSel = 0;
6292 /* The BBP R3 bit[1:0] = 1 :: ADC 1 will be used by QA. */
6295 pAd->ate.RxAntennaSel = 2;
6297 /* The BBP R3 bit[1:0] = 2 :: ADC 2 will be used by QA. */
6300 pAd->ate.RxAntennaSel = 3;
6303 DBGPRINT(RT_DEBUG_ERROR, ("%s -- Impossible! : return FALSE; \n", __func__));
6306 break;/* case BBP_R3 */
6309 DBGPRINT(RT_DEBUG_ERROR, ("%s -- Sth. wrong! : return FALSE; \n", __func__));
6316 static VOID memcpy_exl(PRTMP_ADAPTER pAd, UCHAR *dst, UCHAR *src, ULONG len)
6323 pDst = (ULONG *) dst;
6324 pSrc = (ULONG *) src;
6326 for (i = 0 ; i < (len/4); i++)
6328 /* For alignment issue, we need a variable "Value". */
6329 memmove(&Value, pSrc, 4);
6330 Value = htonl(Value);
6331 memmove(pDst, &Value, 4);
6337 /* wish that it will never reach here */
6338 memmove(&Value, pSrc, (len % 4));
6339 Value = htonl(Value);
6340 memmove(pDst, &Value, (len % 4));
6344 static VOID memcpy_exs(PRTMP_ADAPTER pAd, UCHAR *dst, UCHAR *src, ULONG len)
6352 for (i = 0; i < (len/2); i++)
6354 memmove(pDst, pSrc, 2);
6355 *((USHORT *)pDst) = htons(*((USHORT *)pDst));
6362 memmove(pDst, pSrc, 1);
6366 static VOID RTMP_IO_READ_BULK(PRTMP_ADAPTER pAd, UCHAR *dst, UCHAR *src, UINT32 len)
6369 UINT32 *pDst, *pSrc;
6371 pDst = (UINT32 *) dst;
6372 pSrc = (UINT32 *) src;
6374 for (i = 0 ; i < (len/4); i++)
6376 RTMP_IO_READ32(pAd, (ULONG)pSrc, &Value);
6377 Value = htonl(Value);
6378 memmove(pDst, &Value, 4);
6385 INT Set_TxStop_Proc(
6386 IN PRTMP_ADAPTER pAd,
6389 ATEDBGPRINT(RT_DEBUG_TRACE,("Set_TxStop_Proc\n"));
6391 if (Set_ATE_Proc(pAd, "TXSTOP"))
6401 INT Set_RxStop_Proc(
6402 IN PRTMP_ADAPTER pAd,
6405 ATEDBGPRINT(RT_DEBUG_TRACE,("Set_RxStop_Proc\n"));
6407 if (Set_ATE_Proc(pAd, "RXSTOP"))
6416 #endif // RALINK_28xx_QA //
6417 #endif // RALINK_ATE //