2 *************************************************************************
4 * 5F., No.36, Taiyuan St., Jhubei City,
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
25 *************************************************************************
28 #include "rt_config.h"
31 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
32 extern RTMP_RF_REGS RF2850RegTable[];
33 extern UCHAR NUM_OF_2850_CHNL;
35 static CHAR CCKRateTable[] = {0, 1, 2, 3, 8, 9, 10, 11, -1}; /* CCK Mode. */
36 static CHAR OFDMRateTable[] = {0, 1, 2, 3, 4, 5, 6, 7, -1}; /* OFDM Mode. */
37 static CHAR HTMIXRateTable[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, -1}; /* HT Mix Mode. */
40 IN PRTMP_ADAPTER pAd);
43 IN PRTMP_ADAPTER pAd);
45 static VOID RtmpDmaEnable(
49 static VOID BbpSoftReset(
50 IN PRTMP_ADAPTER pAd);
52 static VOID RtmpRfIoWrite(
53 IN PRTMP_ADAPTER pAd);
55 static INT ATESetUpFrame(
59 static INT ATETxPwrHandler(
63 static INT ATECmdHandler(
67 static int CheckMCSValid(
72 static VOID ATEWriteTxWI(
74 IN PTXWI_STRUC pOutTxWI,
77 IN BOOLEAN InsTimestamp,
80 IN BOOLEAN NSeq, // HW new a sequence.
89 IN HTTRANSMIT_SETTING *pTransmit);
93 static VOID SetJapanFilter(
94 IN PRTMP_ADAPTER pAd);
96 /*=========================end of prototype=========================*/
100 IN PRTMP_ADAPTER pAd)
103 WPDMA_GLO_CFG_STRUC GloCfg;
105 RTMP_IO_READ32(pAd, WPDMA_GLO_CFG, &GloCfg.word); // disable DMA
106 if (GloCfg.field.TxDMABusy)
114 static INT RxDmaBusy(
115 IN PRTMP_ADAPTER pAd)
118 WPDMA_GLO_CFG_STRUC GloCfg;
120 RTMP_IO_READ32(pAd, WPDMA_GLO_CFG, &GloCfg.word); // disable DMA
121 if (GloCfg.field.RxDMABusy)
129 static VOID RtmpDmaEnable(
130 IN PRTMP_ADAPTER pAd,
135 WPDMA_GLO_CFG_STRUC GloCfg;
137 value = Enable > 0 ? 1 : 0;
139 // check DMA is in busy mode.
141 while (TxDmaBusy(pAd) || RxDmaBusy(pAd))
148 RTMP_IO_READ32(pAd, WPDMA_GLO_CFG, &GloCfg.word); // disable DMA
149 GloCfg.field.EnableTxDMA = value;
150 GloCfg.field.EnableRxDMA = value;
151 RTMP_IO_WRITE32(pAd, WPDMA_GLO_CFG, GloCfg.word); // abort all TX rings
159 static VOID BbpSoftReset(
160 IN PRTMP_ADAPTER pAd)
164 // Soft reset, set BBP R21 bit0=1->0
165 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R21, &BbpData);
166 BbpData |= 0x00000001; //set bit0=1
167 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R21, BbpData);
169 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R21, &BbpData);
170 BbpData &= ~(0x00000001); //set bit0=0
171 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R21, BbpData);
176 static VOID RtmpRfIoWrite(
177 IN PRTMP_ADAPTER pAd)
179 // Set RF value 1's set R3[bit2] = [0]
180 RTMP_RF_IO_WRITE32(pAd, pAd->LatchRfRegs.R1);
181 RTMP_RF_IO_WRITE32(pAd, pAd->LatchRfRegs.R2);
182 RTMP_RF_IO_WRITE32(pAd, (pAd->LatchRfRegs.R3 & (~0x04)));
183 RTMP_RF_IO_WRITE32(pAd, pAd->LatchRfRegs.R4);
187 // Set RF value 2's set R3[bit2] = [1]
188 RTMP_RF_IO_WRITE32(pAd, pAd->LatchRfRegs.R1);
189 RTMP_RF_IO_WRITE32(pAd, pAd->LatchRfRegs.R2);
190 RTMP_RF_IO_WRITE32(pAd, (pAd->LatchRfRegs.R3 | 0x04));
191 RTMP_RF_IO_WRITE32(pAd, pAd->LatchRfRegs.R4);
195 // Set RF value 3's set R3[bit2] = [0]
196 RTMP_RF_IO_WRITE32(pAd, pAd->LatchRfRegs.R1);
197 RTMP_RF_IO_WRITE32(pAd, pAd->LatchRfRegs.R2);
198 RTMP_RF_IO_WRITE32(pAd, (pAd->LatchRfRegs.R3 & (~0x04)));
199 RTMP_RF_IO_WRITE32(pAd, pAd->LatchRfRegs.R4);
204 static int CheckMCSValid(
214 pRateTab = CCKRateTable;
217 pRateTab = OFDMRateTable;
221 pRateTab = HTMIXRateTable;
224 ATEDBGPRINT(RT_DEBUG_ERROR, ("unrecognizable Tx Mode %d\n", Mode));
230 while(pRateTab[i] != -1)
232 if (pRateTab[i] == Mcs)
241 static INT ATETxPwrHandler(
242 IN PRTMP_ADAPTER pAd,
248 BOOLEAN bPowerReduce = FALSE;
250 #ifdef RALINK_28xx_QA
251 if ((pAd->ate.bQATxStart == TRUE) || (pAd->ate.bQARxStart == TRUE))
253 /* When QA is used for Tx, pAd->ate.TxPower0/1 and real tx power
254 ** are not synchronized.
257 pAd->ate.TxPower0 = pAd->LatchRfRegs.xxx;
258 pAd->ate.TxPower1 = pAd->LatchRfRegs.xxx;
263 #endif // RALINK_28xx_QA //
265 TxPower = index == 0 ? pAd->ate.TxPower0 : pAd->ate.TxPower1;
267 if (pAd->ate.Channel <= 14)
272 // R3, R4 can't large than 31 (0x24), 31 ~ 36 used by BBP 94
276 Bbp94 = BBPR94_DEFAULT + (UCHAR)(TxPower - 31);
278 else if (TxPower < 0)
281 // R3, R4 can't less than 0, -1 ~ -6 used by BBP 94
285 Bbp94 = BBPR94_DEFAULT + TxPower;
291 Bbp94 = BBPR94_DEFAULT;
294 ATEDBGPRINT(RT_DEBUG_TRACE, ("%s (TxPower=%d, R=%ld, BBP_R94=%d)\n", __func__, TxPower, R, Bbp94));
301 // R3, R4 can't large than 15 (0x0F)
305 else if (TxPower < 0)
308 // R3, R4 can't less than 0
311 ASSERT((TxPower >= -7));
312 R = (ULONG)(TxPower + 7);
321 ATEDBGPRINT(RT_DEBUG_TRACE, ("%s (TxPower=%d, R=%lu)\n", __func__, TxPower, R));
324 if (pAd->ate.Channel <= 14)
328 R = R << 9; // shift TX power control to correct RF(R3) register bit position
329 R |= (pAd->LatchRfRegs.R3 & 0xffffc1ff);
330 pAd->LatchRfRegs.R3 = R;
334 R = R << 6; // shift TX power control to correct RF(R4) register bit position
335 R |= (pAd->LatchRfRegs.R4 & 0xfffff83f);
336 pAd->LatchRfRegs.R4 = R;
341 if (bPowerReduce == FALSE)
345 R = (R << 10) | (1 << 9); // shift TX power control to correct RF(R3) register bit position
346 R |= (pAd->LatchRfRegs.R3 & 0xffffc1ff);
347 pAd->LatchRfRegs.R3 = R;
351 R = (R << 7) | (1 << 6); // shift TX power control to correct RF(R4) register bit position
352 R |= (pAd->LatchRfRegs.R4 & 0xfffff83f);
353 pAd->LatchRfRegs.R4 = R;
360 R = (R << 10); // shift TX power control to correct RF(R3) register bit position
361 R |= (pAd->LatchRfRegs.R3 & 0xffffc1ff);
363 /* Clear bit 9 of R3 to reduce 7dB. */
364 pAd->LatchRfRegs.R3 = (R & (~(1 << 9)));
368 R = (R << 7); // shift TX power control to correct RF(R4) register bit position
369 R |= (pAd->LatchRfRegs.R4 & 0xfffff83f);
371 /* Clear bit 6 of R4 to reduce 7dB. */
372 pAd->LatchRfRegs.R4 = (R & (~(1 << 6)));
383 static INT ATETxPwrHandler(
384 IN PRTMP_ADAPTER pAd,
391 #ifdef RALINK_28xx_QA
392 if ((pAd->ate.bQATxStart == TRUE) || (pAd->ate.bQARxStart == TRUE))
394 // TODO: how to get current TxPower0/1 from pAd->LatchRfRegs ?
395 /* When QA is used for Tx, pAd->ate.TxPower0/1 and real tx power
396 ** are not synchronized.
399 pAd->ate.TxPower0 = pAd->LatchRfRegs.xxx;
400 pAd->ate.TxPower1 = pAd->LatchRfRegs.xxx;
405 #endif // RALINK_28xx_QA //
407 TxPower = index == 0 ? pAd->ate.TxPower0 : pAd->ate.TxPower1;
412 // R3, R4 can't large than 36 (0x24), 31 ~ 36 used by BBP 94
416 Bbp94 = BBPR94_DEFAULT + (UCHAR)(TxPower - 31);
418 else if (TxPower < 0)
421 // R3, R4 can't less than 0, -1 ~ -6 used by BBP 94
425 Bbp94 = BBPR94_DEFAULT + TxPower;
431 Bbp94 = BBPR94_DEFAULT;
434 ATEDBGPRINT(RT_DEBUG_TRACE, ("%s (TxPower=%d, R3=%ld, BBP_R94=%d)\n", __func__, TxPower, R, Bbp94));
436 if (pAd->ate.Channel <= 14)
440 R = R << 9; // shift TX power control to correct RF(R3) register bit position
441 R |= (pAd->LatchRfRegs.R3 & 0xffffc1ff);
442 pAd->LatchRfRegs.R3 = R;
446 R = R << 6; // shift TX power control to correct RF(R4) register bit position
447 R |= (pAd->LatchRfRegs.R4 & 0xfffff83f);
448 pAd->LatchRfRegs.R4 = R;
455 R = (R << 10) | (1 << 9); // shift TX power control to correct RF(R3) register bit position
456 R |= (pAd->LatchRfRegs.R3 & 0xffffc1ff);
457 pAd->LatchRfRegs.R3 = R;
461 R = (R << 7) | (1 << 6); // shift TX power control to correct RF(R4) register bit position
462 R |= (pAd->LatchRfRegs.R4 & 0xfffff83f);
463 pAd->LatchRfRegs.R4 = R;
474 ==========================================================================
476 Set ATE operation mode to
477 0. ATESTART = Start ATE Mode
478 1. ATESTOP = Stop ATE Mode
479 2. TXCONT = Continuous Transmit
480 3. TXCARR = Transmit Carrier
481 4. TXFRAME = Transmit Frames
482 5. RXFRAME = Receive Frames
483 #ifdef RALINK_28xx_QA
484 6. TXSTOP = Stop Any Type of Transmition
485 7. RXSTOP = Stop Receiving Frames
486 #endif // RALINK_28xx_QA //
488 TRUE if all parameters are OK, FALSE otherwise
489 ==========================================================================
492 static INT ATECmdHandler(
493 IN PRTMP_ADAPTER pAd,
503 PRTMP_TX_RING pTxRing = &pAd->TxRing[QID_AC_BE];
505 NDIS_STATUS Status = NDIS_STATUS_SUCCESS;
511 ATEDBGPRINT(RT_DEBUG_TRACE, ("===> ATECmdHandler()\n"));
513 ATEAsicSwitchChannel(pAd);
514 AsicLockChannel(pAd, pAd->ate.Channel);
518 // read MAC_SYS_CTRL and backup MAC_SYS_CTRL value.
519 RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &MacData);
521 // Default value in BBP R22 is 0x0.
524 // clean bit4 to stop continuous Tx production test.
525 MacData &= 0xFFFFFFEF;
527 if (!strcmp(arg, "ATESTART")) //Enter ATE mode and set Tx/Rx Idle
529 ATEDBGPRINT(RT_DEBUG_TRACE, ("ATE: ATESTART\n"));
532 // check if we have removed the firmware
535 NICEraseFirmware(pAd);
538 atemode = pAd->ate.Mode;
539 pAd->ate.Mode = ATE_START;
540 // pAd->ate.TxDoneCount = pAd->ate.TxCount;
541 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, MacData);
543 if (atemode & ATE_TXCARR)
545 // No Carrier Test set BBP R22 bit7=0, bit6=0, bit[5~0]=0x0
546 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R22, &BbpData);
547 BbpData &= 0xFFFFFF00; //clear bit7, bit6, bit[5~0]
548 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R22, BbpData);
550 else if (atemode & ATE_TXCARRSUPP)
552 // No Cont. TX set BBP R22 bit7=0
553 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R22, &BbpData);
554 BbpData &= ~(1 << 7); //set bit7=0
555 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R22, BbpData);
557 // No Carrier Suppression set BBP R24 bit0=0
558 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R24, &BbpData);
559 BbpData &= 0xFFFFFFFE; //clear bit0
560 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R24, BbpData);
562 // We should free some resource which was allocated when ATE_TXFRAME , ATE_STOP, and ATE_TXCONT.
563 else if ((atemode & ATE_TXFRAME) || (atemode == ATE_STOP))
565 PRTMP_TX_RING pTxRing = &pAd->TxRing[QID_AC_BE];
567 if (atemode & ATE_TXCONT)
569 // No Cont. TX set BBP R22 bit7=0
570 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R22, &BbpData);
571 BbpData &= ~(1 << 7); //set bit7=0
572 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R22, BbpData);
575 RtmpDmaEnable(pAd, 0);
576 for (i=0; i<TX_RING_SIZE; i++)
578 PNDIS_PACKET pPacket;
580 #ifndef RT_BIG_ENDIAN
581 pTxD = (PTXD_STRUC)pAd->TxRing[QID_AC_BE].Cell[i].AllocVa;
583 pDestTxD = (PTXD_STRUC)pAd->TxRing[QID_AC_BE].Cell[i].AllocVa;
586 RTMPDescriptorEndianChange((PUCHAR)pTxD, TYPE_TXD);
589 pPacket = pTxRing->Cell[i].pNdisPacket;
592 PCI_UNMAP_SINGLE(pAd, pTxD->SDPtr0, pTxD->SDLen0, PCI_DMA_TODEVICE);
593 RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_SUCCESS);
595 //Always assign pNdisPacket as NULL after clear
596 pTxRing->Cell[i].pNdisPacket = NULL;
598 pPacket = pTxRing->Cell[i].pNextNdisPacket;
601 PCI_UNMAP_SINGLE(pAd, pTxD->SDPtr1, pTxD->SDLen1, PCI_DMA_TODEVICE);
602 RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_SUCCESS);
604 //Always assign pNextNdisPacket as NULL after clear
605 pTxRing->Cell[i].pNextNdisPacket = NULL;
607 RTMPDescriptorEndianChange((PUCHAR)pTxD, TYPE_TXD);
608 WriteBackToDescriptor((PUCHAR)pDestTxD, (PUCHAR)pTxD, FALSE, TYPE_TXD);
612 RtmpDmaEnable(pAd, 1);
614 // reset Rx statistics.
615 pAd->ate.LastSNR0 = 0;
616 pAd->ate.LastSNR1 = 0;
617 pAd->ate.LastRssi0 = 0;
618 pAd->ate.LastRssi1 = 0;
619 pAd->ate.LastRssi2 = 0;
620 pAd->ate.AvgRssi0 = 0;
621 pAd->ate.AvgRssi1 = 0;
622 pAd->ate.AvgRssi2 = 0;
623 pAd->ate.AvgRssi0X8 = 0;
624 pAd->ate.AvgRssi1X8 = 0;
625 pAd->ate.AvgRssi2X8 = 0;
626 pAd->ate.NumOfAvgRssiSample = 0;
628 #ifdef RALINK_28xx_QA
630 pAd->ate.bQATxStart = FALSE;
631 pAd->ate.bQARxStart = FALSE;
636 pAd->ate.OtherData = 0;
638 pAd->ate.OtherCount = 0;
652 pAd->ate.TxDoneCount = 0;
653 pAd->ate.TxStatus = 0; // task Tx status // 0 --> task is idle, 1 --> task is running
654 #endif // RALINK_28xx_QA //
660 #ifdef CONFIG_STA_SUPPORT
662 // LinkDown() has "AsicDisableSync();" and "RTMP_BBP_IO_R/W8_BY_REG_ID();" inside.
664 // LinkDown(pAd, FALSE);
665 // AsicEnableBssSync(pAd);
667 netif_stop_queue(pAd->net_dev);
670 // If we skip "LinkDown()", we should disable protection
671 // to prevent from sending out RTS or CTS-to-self.
673 ATEDisableAsicProtect(pAd);
674 RTMPStationStop(pAd);
675 #endif // CONFIG_STA_SUPPORT //
678 RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &Value);
680 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, Value);
683 RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &Value);
685 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, Value);
687 else if (!strcmp(arg, "ATESTOP"))
689 ATEDBGPRINT(RT_DEBUG_TRACE, ("ATE: ATESTOP\n"));
691 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R22, BbpData);
692 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, MacData); // recover the MAC_SYS_CTRL register back.
695 RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &Value);
696 Value &= (0xfffffff3);
697 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, Value);
700 RtmpDmaEnable(pAd, 0);
703 pAd->ate.bFWLoading = TRUE;
704 Status = NICLoadFirmware(pAd);
705 if (Status != NDIS_STATUS_SUCCESS)
707 ATEDBGPRINT(RT_DEBUG_ERROR, ("NICLoadFirmware failed, Status[=0x%08x]\n", Status));
711 pAd->ate.Mode = ATE_STOP;
714 #ifdef CONFIG_STA_SUPPORT
716 // Even the firmware has been loaded,
717 // we still could use ATE_BBP_IO_READ8_BY_REG_ID().
718 // But this is not suggested.
721 #endif // CONFIG_STA_SUPPORT //
723 NICDisableInterrupt(pAd);
725 NICInitializeAdapter(pAd, TRUE);
728 // Reinitialize Rx Ring before Rx DMA is enabled.
729 // The nightmare of >>>RxCoherent<<< was gone !
730 for (index = 0; index < RX_RING_SIZE; index++)
732 pRxD = (PRXD_STRUC) pAd->RxRing.Cell[index].AllocVa;
736 // We should read EEPROM for all cases.
737 NICReadEEPROMParameters(pAd, NULL);
738 NICInitAsicFromEEPROM(pAd);
740 AsicSwitchChannel(pAd, pAd->CommonCfg.Channel, FALSE);
741 AsicLockChannel(pAd, pAd->CommonCfg.Channel);
748 // These steps are only for APAutoSelectChannel().
751 //pAd->bStaFifoTest = TRUE;
752 pAd->int_enable_reg = ((DELAYINTMASK) | (RxINT|TxDataInt|TxMgmtInt)) & ~(0x03);
753 pAd->int_disable_mask = 0;
754 pAd->int_pending = 0;
756 RTMP_IO_WRITE32(pAd, INT_SOURCE_CSR, 0xffffffff); // clear garbage interrupts
757 NICEnableInterrupt(pAd);
760 /*=========================================================================*/
761 /* restore RX_FILTR_CFG */
762 #ifdef CONFIG_STA_SUPPORT
763 /* restore RX_FILTR_CFG due to that QA maybe set it to 0x3 */
764 RTMP_IO_WRITE32(pAd, RX_FILTR_CFG, STANORMAL);
765 #endif // CONFIG_STA_SUPPORT //
766 /*=========================================================================*/
769 RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &Value);
771 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, Value);
773 // Enable Tx, Rx DMA.
774 RtmpDmaEnable(pAd, 1);
777 RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &Value);
779 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, Value);
782 #ifdef CONFIG_STA_SUPPORT
783 RTMPStationStart(pAd);
784 #endif // CONFIG_STA_SUPPORT //
786 netif_start_queue(pAd->net_dev);
789 else if (!strcmp(arg, "TXCARR")) // Tx Carrier
791 ATEDBGPRINT(RT_DEBUG_TRACE, ("ATE: TXCARR\n"));
792 pAd->ate.Mode |= ATE_TXCARR;
794 // QA has done the following steps if it is used.
795 if (pAd->ate.bQATxStart == FALSE)
800 // Carrier Test set BBP R22 bit7=1, bit6=1, bit[5~0]=0x01
801 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R22, &BbpData);
802 BbpData &= 0xFFFFFF00; //clear bit7, bit6, bit[5~0]
803 BbpData |= 0x000000C1; //set bit7=1, bit6=1, bit[5~0]=0x01
804 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R22, BbpData);
806 // set MAC_SYS_CTRL(0x1004) Continuous Tx Production Test (bit4) = 1
807 RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &Value);
808 Value = Value | 0x00000010;
809 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, Value);
812 else if (!strcmp(arg, "TXCONT")) // Tx Continue
814 if (pAd->ate.bQATxStart == TRUE)
816 /* set MAC_SYS_CTRL(0x1004) bit4(Continuous Tx Production Test)
817 and bit2(MAC TX enable) back to zero. */
818 RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &MacData);
819 MacData &= 0xFFFFFFEB;
820 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, MacData);
822 // set BBP R22 bit7=0
823 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R22, &BbpData);
824 BbpData &= 0xFFFFFF7F; //set bit7=0
825 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R22, BbpData);
829 ** Step 1: Send 50 packets first then wait for a moment.
830 ** Step 2: Send more 50 packet then start continue mode.
832 ATEDBGPRINT(RT_DEBUG_TRACE, ("ATE: TXCONT\n"));
833 // Step 1: send 50 packets first.
834 pAd->ate.Mode |= ATE_TXCONT;
835 pAd->ate.TxCount = 50;
836 /* Do it after Tx/Rx DMA is aborted. */
837 // pAd->ate.TxDoneCount = 0;
843 RtmpDmaEnable(pAd, 0);
845 // Fix can't smooth kick
847 RTMP_IO_READ32(pAd, TX_DTX_IDX0 + QID_AC_BE * 0x10, &pTxRing->TxDmaIdx);
848 pTxRing->TxSwFreeIdx = pTxRing->TxDmaIdx;
849 pTxRing->TxCpuIdx = pTxRing->TxDmaIdx;
850 RTMP_IO_WRITE32(pAd, TX_CTX_IDX0 + QID_AC_BE * 0x10, pTxRing->TxCpuIdx);
853 pAd->ate.TxDoneCount = 0;
855 /* Only needed if we have to send some normal frames. */
858 for (i = 0; (i < TX_RING_SIZE-1) && (i < pAd->ate.TxCount); i++)
860 PNDIS_PACKET pPacket;
861 UINT32 TxIdx = pTxRing->TxCpuIdx;
863 #ifndef RT_BIG_ENDIAN
864 pTxD = (PTXD_STRUC)pTxRing->Cell[TxIdx].AllocVa;
866 pDestTxD = (PTXD_STRUC)pTxRing->Cell[TxIdx].AllocVa;
869 RTMPDescriptorEndianChange((PUCHAR)pTxD, TYPE_TXD);
871 // Clean current cell.
872 pPacket = pTxRing->Cell[TxIdx].pNdisPacket;
875 PCI_UNMAP_SINGLE(pAd, pTxD->SDPtr0, pTxD->SDLen0, PCI_DMA_TODEVICE);
876 RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_SUCCESS);
878 //Always assign pNdisPacket as NULL after clear
879 pTxRing->Cell[TxIdx].pNdisPacket = NULL;
881 pPacket = pTxRing->Cell[TxIdx].pNextNdisPacket;
884 PCI_UNMAP_SINGLE(pAd, pTxD->SDPtr1, pTxD->SDLen1, PCI_DMA_TODEVICE);
885 RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_SUCCESS);
887 //Always assign pNextNdisPacket as NULL after clear
888 pTxRing->Cell[TxIdx].pNextNdisPacket = NULL;
891 RTMPDescriptorEndianChange((PUCHAR)pTxD, TYPE_TXD);
892 WriteBackToDescriptor((PUCHAR)pDestTxD, (PUCHAR)pTxD, FALSE, TYPE_TXD);
895 if (ATESetUpFrame(pAd, TxIdx) != 0)
898 INC_RING_INDEX(pTxRing->TxCpuIdx, TX_RING_SIZE);
901 // Setup frame format.
902 ATESetUpFrame(pAd, pTxRing->TxCpuIdx);
905 RtmpDmaEnable(pAd, 1);
908 RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &Value);
910 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, Value);
913 RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &Value);
915 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, Value);
917 #ifdef RALINK_28xx_QA
918 if (pAd->ate.bQATxStart == TRUE)
920 pAd->ate.TxStatus = 1;
921 //pAd->ate.Repeat = 0;
923 #endif // RALINK_28xx_QA //
926 RTMP_IO_WRITE32(pAd, TX_CTX_IDX0 + QID_AC_BE * RINGREG_DIFF, pAd->TxRing[QID_AC_BE].TxCpuIdx);
931 // Step 2: send more 50 packets then start continue mode.
933 RtmpDmaEnable(pAd, 0);
935 // Cont. TX set BBP R22 bit7=1
936 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R22, &BbpData);
937 BbpData |= 0x00000080; //set bit7=1
938 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R22, BbpData);
940 pAd->ate.TxCount = 50;
942 // Fix can't smooth kick
944 RTMP_IO_READ32(pAd, TX_DTX_IDX0 + QID_AC_BE * 0x10, &pTxRing->TxDmaIdx);
945 pTxRing->TxSwFreeIdx = pTxRing->TxDmaIdx;
946 pTxRing->TxCpuIdx = pTxRing->TxDmaIdx;
947 RTMP_IO_WRITE32(pAd, TX_CTX_IDX0 + QID_AC_BE * 0x10, pTxRing->TxCpuIdx);
950 pAd->ate.TxDoneCount = 0;
954 for (i = 0; (i < TX_RING_SIZE-1) && (i < pAd->ate.TxCount); i++)
956 PNDIS_PACKET pPacket;
957 UINT32 TxIdx = pTxRing->TxCpuIdx;
959 #ifndef RT_BIG_ENDIAN
960 pTxD = (PTXD_STRUC)pTxRing->Cell[TxIdx].AllocVa;
962 pDestTxD = (PTXD_STRUC)pTxRing->Cell[TxIdx].AllocVa;
965 RTMPDescriptorEndianChange((PUCHAR)pTxD, TYPE_TXD);
967 // clean current cell.
968 pPacket = pTxRing->Cell[TxIdx].pNdisPacket;
971 PCI_UNMAP_SINGLE(pAd, pTxD->SDPtr0, pTxD->SDLen0, PCI_DMA_TODEVICE);
972 RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_SUCCESS);
974 //Always assign pNdisPacket as NULL after clear
975 pTxRing->Cell[TxIdx].pNdisPacket = NULL;
977 pPacket = pTxRing->Cell[TxIdx].pNextNdisPacket;
980 PCI_UNMAP_SINGLE(pAd, pTxD->SDPtr1, pTxD->SDLen1, PCI_DMA_TODEVICE);
981 RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_SUCCESS);
983 //Always assign pNextNdisPacket as NULL after clear
984 pTxRing->Cell[TxIdx].pNextNdisPacket = NULL;
987 RTMPDescriptorEndianChange((PUCHAR)pTxD, TYPE_TXD);
988 WriteBackToDescriptor((PUCHAR)pDestTxD, (PUCHAR)pTxD, FALSE, TYPE_TXD);
991 if (ATESetUpFrame(pAd, TxIdx) != 0)
994 INC_RING_INDEX(pTxRing->TxCpuIdx, TX_RING_SIZE);
997 ATESetUpFrame(pAd, pTxRing->TxCpuIdx);
1000 RtmpDmaEnable(pAd, 1);
1003 RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &Value);
1005 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, Value);
1008 RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &Value);
1010 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, Value);
1012 #ifdef RALINK_28xx_QA
1013 if (pAd->ate.bQATxStart == TRUE)
1015 pAd->ate.TxStatus = 1;
1016 //pAd->ate.Repeat = 0;
1018 #endif // RALINK_28xx_QA //
1021 RTMP_IO_WRITE32(pAd, TX_CTX_IDX0 + QID_AC_BE * RINGREG_DIFF, pAd->TxRing[QID_AC_BE].TxCpuIdx);
1025 RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &MacData);
1026 MacData |= 0x00000010;
1027 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, MacData);
1029 else if (!strcmp(arg, "TXFRAME")) // Tx Frames
1031 ATEDBGPRINT(RT_DEBUG_TRACE, ("ATE: TXFRAME(Count=%d)\n", pAd->ate.TxCount));
1032 pAd->ate.Mode |= ATE_TXFRAME;
1033 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R22, BbpData);
1037 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, MacData);
1039 // Abort Tx, RX DMA.
1040 RtmpDmaEnable(pAd, 0);
1042 // Fix can't smooth kick
1044 RTMP_IO_READ32(pAd, TX_DTX_IDX0 + QID_AC_BE * 0x10, &pTxRing->TxDmaIdx);
1045 pTxRing->TxSwFreeIdx = pTxRing->TxDmaIdx;
1046 pTxRing->TxCpuIdx = pTxRing->TxDmaIdx;
1047 RTMP_IO_WRITE32(pAd, TX_CTX_IDX0 + QID_AC_BE * 0x10, pTxRing->TxCpuIdx);
1050 pAd->ate.TxDoneCount = 0;
1052 SetJapanFilter(pAd);
1054 for (i = 0; (i < TX_RING_SIZE-1) && (i < pAd->ate.TxCount); i++)
1056 PNDIS_PACKET pPacket;
1057 UINT32 TxIdx = pTxRing->TxCpuIdx;
1059 #ifndef RT_BIG_ENDIAN
1060 pTxD = (PTXD_STRUC)pTxRing->Cell[TxIdx].AllocVa;
1062 pDestTxD = (PTXD_STRUC)pTxRing->Cell[TxIdx].AllocVa;
1065 RTMPDescriptorEndianChange((PUCHAR)pTxD, TYPE_TXD);
1067 // Clean current cell.
1068 pPacket = pTxRing->Cell[TxIdx].pNdisPacket;
1071 PCI_UNMAP_SINGLE(pAd, pTxD->SDPtr0, pTxD->SDLen0, PCI_DMA_TODEVICE);
1072 RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_SUCCESS);
1074 //Always assign pNdisPacket as NULL after clear
1075 pTxRing->Cell[TxIdx].pNdisPacket = NULL;
1077 pPacket = pTxRing->Cell[TxIdx].pNextNdisPacket;
1080 PCI_UNMAP_SINGLE(pAd, pTxD->SDPtr1, pTxD->SDLen1, PCI_DMA_TODEVICE);
1081 RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_SUCCESS);
1083 //Always assign pNextNdisPacket as NULL after clear
1084 pTxRing->Cell[TxIdx].pNextNdisPacket = NULL;
1086 #ifdef RT_BIG_ENDIAN
1087 RTMPDescriptorEndianChange((PUCHAR)pTxD, TYPE_TXD);
1088 WriteBackToDescriptor((PUCHAR)pDestTxD, (PUCHAR)pTxD, FALSE, TYPE_TXD);
1091 if (ATESetUpFrame(pAd, TxIdx) != 0)
1094 INC_RING_INDEX(pTxRing->TxCpuIdx, TX_RING_SIZE);
1098 ATESetUpFrame(pAd, pTxRing->TxCpuIdx);
1100 // Start Tx, Rx DMA.
1101 RtmpDmaEnable(pAd, 1);
1104 RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &Value);
1106 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, Value);
1107 #ifdef RALINK_28xx_QA
1108 // add this for LoopBack mode
1109 if (pAd->ate.bQARxStart == FALSE)
1112 RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &Value);
1114 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, Value);
1117 if (pAd->ate.bQATxStart == TRUE)
1119 pAd->ate.TxStatus = 1;
1120 //pAd->ate.Repeat = 0;
1124 RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &Value);
1126 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, Value);
1127 #endif // RALINK_28xx_QA //
1129 RTMP_IO_READ32(pAd, TX_DTX_IDX0 + QID_AC_BE * RINGREG_DIFF, &pAd->TxRing[QID_AC_BE].TxDmaIdx);
1131 RTMP_IO_WRITE32(pAd, TX_CTX_IDX0 + QID_AC_BE * RINGREG_DIFF, pAd->TxRing[QID_AC_BE].TxCpuIdx);
1133 pAd->RalinkCounters.KickTxCount++;
1135 #ifdef RALINK_28xx_QA
1136 else if (!strcmp(arg, "TXSTOP"))
1138 ATEDBGPRINT(RT_DEBUG_TRACE, ("ATE: TXSTOP\n"));
1139 atemode = pAd->ate.Mode;
1140 pAd->ate.Mode &= ATE_TXSTOP;
1141 pAd->ate.bQATxStart = FALSE;
1142 // pAd->ate.TxDoneCount = pAd->ate.TxCount;
1144 if (atemode & ATE_TXCARR)
1146 // No Carrier Test set BBP R22 bit7=0, bit6=0, bit[5~0]=0x0
1147 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R22, &BbpData);
1148 BbpData &= 0xFFFFFF00; //clear bit7, bit6, bit[5~0]
1149 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R22, BbpData);
1151 else if (atemode & ATE_TXCARRSUPP)
1153 // No Cont. TX set BBP R22 bit7=0
1154 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R22, &BbpData);
1155 BbpData &= ~(1 << 7); //set bit7=0
1156 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R22, BbpData);
1158 // No Carrier Suppression set BBP R24 bit0=0
1159 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R24, &BbpData);
1160 BbpData &= 0xFFFFFFFE; //clear bit0
1161 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R24, BbpData);
1163 // We should free some resource which allocate when ATE_TXFRAME , ATE_STOP, and ATE_TXCONT.
1164 else if ((atemode & ATE_TXFRAME) || (atemode == ATE_STOP))
1167 PRTMP_TX_RING pTxRing = &pAd->TxRing[QID_AC_BE];
1169 if (atemode & ATE_TXCONT)
1171 // No Cont. TX set BBP R22 bit7=0
1172 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R22, &BbpData);
1173 BbpData &= ~(1 << 7); //set bit7=0
1174 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R22, BbpData);
1177 // Abort Tx, Rx DMA.
1178 RtmpDmaEnable(pAd, 0);
1179 for (i=0; i<TX_RING_SIZE; i++)
1181 PNDIS_PACKET pPacket;
1183 #ifndef RT_BIG_ENDIAN
1184 pTxD = (PTXD_STRUC)pAd->TxRing[QID_AC_BE].Cell[i].AllocVa;
1186 pDestTxD = (PTXD_STRUC)pAd->TxRing[QID_AC_BE].Cell[i].AllocVa;
1189 RTMPDescriptorEndianChange((PUCHAR)pTxD, TYPE_TXD);
1192 pPacket = pTxRing->Cell[i].pNdisPacket;
1195 PCI_UNMAP_SINGLE(pAd, pTxD->SDPtr0, pTxD->SDLen0, PCI_DMA_TODEVICE);
1196 RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_SUCCESS);
1198 //Always assign pNdisPacket as NULL after clear
1199 pTxRing->Cell[i].pNdisPacket = NULL;
1201 pPacket = pTxRing->Cell[i].pNextNdisPacket;
1204 PCI_UNMAP_SINGLE(pAd, pTxD->SDPtr1, pTxD->SDLen1, PCI_DMA_TODEVICE);
1205 RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_SUCCESS);
1207 //Always assign pNextNdisPacket as NULL after clear
1208 pTxRing->Cell[i].pNextNdisPacket = NULL;
1209 #ifdef RT_BIG_ENDIAN
1210 RTMPDescriptorEndianChange((PUCHAR)pTxD, TYPE_TXD);
1211 WriteBackToDescriptor((PUCHAR)pDestTxD, (PUCHAR)pTxD, FALSE, TYPE_TXD);
1214 // Enable Tx, Rx DMA
1215 RtmpDmaEnable(pAd, 1);
1220 // pAd->ate.TxDoneCount = 0;
1221 pAd->ate.TxStatus = 0; // task Tx status // 0 --> task is idle, 1 --> task is running
1227 RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &Value);
1229 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, Value);
1231 else if (!strcmp(arg, "RXSTOP"))
1233 ATEDBGPRINT(RT_DEBUG_TRACE, ("ATE: RXSTOP\n"));
1234 atemode = pAd->ate.Mode;
1235 pAd->ate.Mode &= ATE_RXSTOP;
1236 pAd->ate.bQARxStart = FALSE;
1237 // pAd->ate.TxDoneCount = pAd->ate.TxCount;
1239 if (atemode & ATE_TXCARR)
1243 else if (atemode & ATE_TXCARRSUPP)
1248 // We should free some resource which was allocated when ATE_TXFRAME , ATE_STOP, and ATE_TXCONT.
1249 else if ((atemode & ATE_TXFRAME) || (atemode == ATE_STOP))
1251 if (atemode & ATE_TXCONT)
1258 // pAd->ate.TxDoneCount = 0;
1259 // pAd->ate.TxStatus = 0; // task Tx status // 0 --> task is idle, 1 --> task is running
1265 RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &Value);
1267 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, Value);
1269 #endif // RALINK_28xx_QA //
1270 else if (!strcmp(arg, "RXFRAME")) // Rx Frames
1272 ATEDBGPRINT(RT_DEBUG_TRACE, ("ATE: RXFRAME\n"));
1274 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R22, BbpData);
1275 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, MacData);
1277 pAd->ate.Mode |= ATE_RXFRAME;
1279 // Disable Tx of MAC block.
1280 RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &Value);
1282 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, Value);
1284 // Enable Rx of MAC block.
1285 RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &Value);
1287 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, Value);
1291 ATEDBGPRINT(RT_DEBUG_TRACE, ("ATE: Invalid arg!\n"));
1294 RTMPusecDelay(5000);
1296 ATEDBGPRINT(RT_DEBUG_TRACE, ("<=== ATECmdHandler()\n"));
1303 /*=======================End of RT2860=======================*/
1306 /*======================Start of RT2870======================*/
1312 IN PRTMP_ADAPTER pAd,
1315 if (ATECmdHandler(pAd, arg))
1317 ATEDBGPRINT(RT_DEBUG_TRACE, ("Ralink: Set_ATE_Proc Success\n"));
1324 ATEDBGPRINT(RT_DEBUG_TRACE, ("Ralink: Set_ATE_Proc Failed\n"));
1330 ==========================================================================
1332 Set ATE ADDR1=DA for TxFrame(AP : To DS = 0 ; From DS = 1)
1334 Set ATE ADDR3=DA for TxFrame(STA : To DS = 1 ; From DS = 0)
1337 TRUE if all parameters are OK, FALSE otherwise
1338 ==========================================================================
1340 INT Set_ATE_DA_Proc(
1341 IN PRTMP_ADAPTER pAd,
1347 if(strlen(arg) != 17) //Mac address acceptable format 01:02:03:04:05:06 length 17
1350 for (i=0, value = rstrtok(arg, ":"); value; value = rstrtok(NULL, ":"))
1352 if((strlen(value) != 2) || (!isxdigit(*value)) || (!isxdigit(*(value+1))) )
1353 return FALSE; //Invalid
1356 #ifdef CONFIG_STA_SUPPORT
1357 AtoH(value, &pAd->ate.Addr3[i++], 1);
1358 #endif // CONFIG_STA_SUPPORT //
1362 return FALSE; //Invalid
1365 #ifdef CONFIG_STA_SUPPORT
1366 ATEDBGPRINT(RT_DEBUG_TRACE, ("Set_ATE_DA_Proc (DA = %2X:%2X:%2X:%2X:%2X:%2X)\n", pAd->ate.Addr3[0],
1367 pAd->ate.Addr3[1], pAd->ate.Addr3[2], pAd->ate.Addr3[3], pAd->ate.Addr3[4], pAd->ate.Addr3[5]));
1368 #endif // CONFIG_STA_SUPPORT //
1370 ATEDBGPRINT(RT_DEBUG_TRACE, ("Ralink: Set_ATE_DA_Proc Success\n"));
1376 ==========================================================================
1378 Set ATE ADDR3=SA for TxFrame(AP : To DS = 0 ; From DS = 1)
1380 Set ATE ADDR2=SA for TxFrame(STA : To DS = 1 ; From DS = 0)
1383 TRUE if all parameters are OK, FALSE otherwise
1384 ==========================================================================
1386 INT Set_ATE_SA_Proc(
1387 IN PRTMP_ADAPTER pAd,
1393 if(strlen(arg) != 17) //Mac address acceptable format 01:02:03:04:05:06 length 17
1396 for (i=0, value = rstrtok(arg, ":"); value; value = rstrtok(NULL, ":"))
1398 if((strlen(value) != 2) || (!isxdigit(*value)) || (!isxdigit(*(value+1))) )
1399 return FALSE; //Invalid
1402 #ifdef CONFIG_STA_SUPPORT
1403 AtoH(value, &pAd->ate.Addr2[i++], 1);
1404 #endif // CONFIG_STA_SUPPORT //
1408 return FALSE; //Invalid
1411 #ifdef CONFIG_STA_SUPPORT
1412 ATEDBGPRINT(RT_DEBUG_TRACE, ("Set_ATE_SA_Proc (SA = %2X:%2X:%2X:%2X:%2X:%2X)\n", pAd->ate.Addr2[0],
1413 pAd->ate.Addr2[1], pAd->ate.Addr2[2], pAd->ate.Addr2[3], pAd->ate.Addr2[4], pAd->ate.Addr2[5]));
1414 #endif // CONFIG_STA_SUPPORT //
1416 ATEDBGPRINT(RT_DEBUG_TRACE, ("Ralink: Set_ATE_SA_Proc Success\n"));
1422 ==========================================================================
1424 Set ATE ADDR2=BSSID for TxFrame(AP : To DS = 0 ; From DS = 1)
1426 Set ATE ADDR1=BSSID for TxFrame(STA : To DS = 1 ; From DS = 0)
1429 TRUE if all parameters are OK, FALSE otherwise
1430 ==========================================================================
1432 INT Set_ATE_BSSID_Proc(
1433 IN PRTMP_ADAPTER pAd,
1439 if(strlen(arg) != 17) //Mac address acceptable format 01:02:03:04:05:06 length 17
1442 for (i=0, value = rstrtok(arg, ":"); value; value = rstrtok(NULL, ":"))
1444 if((strlen(value) != 2) || (!isxdigit(*value)) || (!isxdigit(*(value+1))) )
1445 return FALSE; //Invalid
1448 #ifdef CONFIG_STA_SUPPORT
1449 AtoH(value, &pAd->ate.Addr1[i++], 1);
1450 #endif // CONFIG_STA_SUPPORT //
1454 return FALSE; //Invalid
1457 #ifdef CONFIG_STA_SUPPORT
1458 ATEDBGPRINT(RT_DEBUG_TRACE, ("Set_ATE_BSSID_Proc (BSSID = %2X:%2X:%2X:%2X:%2X:%2X)\n", pAd->ate.Addr1[0],
1459 pAd->ate.Addr1[1], pAd->ate.Addr1[2], pAd->ate.Addr1[3], pAd->ate.Addr1[4], pAd->ate.Addr1[5]));
1460 #endif // CONFIG_STA_SUPPORT //
1462 ATEDBGPRINT(RT_DEBUG_TRACE, ("Ralink: Set_ATE_BSSID_Proc Success\n"));
1468 ==========================================================================
1473 TRUE if all parameters are OK, FALSE otherwise
1474 ==========================================================================
1476 INT Set_ATE_CHANNEL_Proc(
1477 IN PRTMP_ADAPTER pAd,
1482 channel = simple_strtol(arg, 0, 10);
1484 if ((channel < 1) || (channel > 216))// to allow A band channel : ((channel < 1) || (channel > 14))
1486 ATEDBGPRINT(RT_DEBUG_ERROR, ("Set_ATE_CHANNEL_Proc::Out of range, it should be in range of 1~14.\n"));
1489 pAd->ate.Channel = channel;
1491 ATEDBGPRINT(RT_DEBUG_TRACE, ("Set_ATE_CHANNEL_Proc (ATE Channel = %d)\n", pAd->ate.Channel));
1492 ATEDBGPRINT(RT_DEBUG_TRACE, ("Ralink: Set_ATE_CHANNEL_Proc Success\n"));
1499 ==========================================================================
1504 TRUE if all parameters are OK, FALSE otherwise
1505 ==========================================================================
1507 INT Set_ATE_TX_POWER0_Proc(
1508 IN PRTMP_ADAPTER pAd,
1513 TxPower = simple_strtol(arg, 0, 10);
1515 if (pAd->ate.Channel <= 14)
1517 if ((TxPower > 31) || (TxPower < 0))
1519 ATEDBGPRINT(RT_DEBUG_ERROR, ("Set_ATE_TX_POWER0_Proc::Out of range (Value=%d)\n", TxPower));
1525 if ((TxPower > 15) || (TxPower < -7))
1527 ATEDBGPRINT(RT_DEBUG_ERROR, ("Set_ATE_TX_POWER0_Proc::Out of range (Value=%d)\n", TxPower));
1532 pAd->ate.TxPower0 = TxPower;
1533 ATETxPwrHandler(pAd, 0);
1534 ATEDBGPRINT(RT_DEBUG_TRACE, ("Ralink: Set_ATE_TX_POWER0_Proc Success\n"));
1541 ==========================================================================
1546 TRUE if all parameters are OK, FALSE otherwise
1547 ==========================================================================
1549 INT Set_ATE_TX_POWER1_Proc(
1550 IN PRTMP_ADAPTER pAd,
1555 TxPower = simple_strtol(arg, 0, 10);
1557 if (pAd->ate.Channel <= 14)
1559 if ((TxPower > 31) || (TxPower < 0))
1561 ATEDBGPRINT(RT_DEBUG_ERROR, ("Set_ATE_TX_POWER1_Proc::Out of range (Value=%d)\n", TxPower));
1567 if ((TxPower > 15) || (TxPower < -7))
1569 ATEDBGPRINT(RT_DEBUG_ERROR, ("Set_ATE_TX_POWER1_Proc::Out of range (Value=%d)\n", TxPower));
1574 pAd->ate.TxPower1 = TxPower;
1575 ATETxPwrHandler(pAd, 1);
1576 ATEDBGPRINT(RT_DEBUG_TRACE, ("Ralink: Set_ATE_TX_POWER1_Proc Success\n"));
1583 ==========================================================================
1588 TRUE if all parameters are OK, FALSE otherwise
1589 ==========================================================================
1591 INT Set_ATE_TX_Antenna_Proc(
1592 IN PRTMP_ADAPTER pAd,
1597 value = simple_strtol(arg, 0, 10);
1599 if ((value > 2) || (value < 0))
1601 ATEDBGPRINT(RT_DEBUG_ERROR, ("Set_ATE_TX_Antenna_Proc::Out of range (Value=%d)\n", value));
1605 pAd->ate.TxAntennaSel = value;
1607 ATEDBGPRINT(RT_DEBUG_TRACE, ("Set_ATE_TX_Antenna_Proc (Antenna = %d)\n", pAd->ate.TxAntennaSel));
1608 ATEDBGPRINT(RT_DEBUG_TRACE,("Ralink: Set_ATE_TX_Antenna_Proc Success\n"));
1615 ==========================================================================
1620 TRUE if all parameters are OK, FALSE otherwise
1621 ==========================================================================
1623 INT Set_ATE_RX_Antenna_Proc(
1624 IN PRTMP_ADAPTER pAd,
1629 value = simple_strtol(arg, 0, 10);
1631 if ((value > 3) || (value < 0))
1633 ATEDBGPRINT(RT_DEBUG_ERROR, ("Set_ATE_RX_Antenna_Proc::Out of range (Value=%d)\n", value));
1637 pAd->ate.RxAntennaSel = value;
1639 ATEDBGPRINT(RT_DEBUG_TRACE, ("Set_ATE_RX_Antenna_Proc (Antenna = %d)\n", pAd->ate.RxAntennaSel));
1640 ATEDBGPRINT(RT_DEBUG_TRACE, ("Ralink: Set_ATE_RX_Antenna_Proc Success\n"));
1647 ==========================================================================
1649 Set ATE RF frequence offset
1652 TRUE if all parameters are OK, FALSE otherwise
1653 ==========================================================================
1655 INT Set_ATE_TX_FREQOFFSET_Proc(
1656 IN PRTMP_ADAPTER pAd,
1662 RFFreqOffset = simple_strtol(arg, 0, 10);
1664 if(RFFreqOffset >= 64)
1666 ATEDBGPRINT(RT_DEBUG_ERROR, ("Set_ATE_TX_FREQOFFSET_Proc::Out of range, it should be in range of 0~63.\n"));
1670 pAd->ate.RFFreqOffset = RFFreqOffset;
1671 R4 = pAd->ate.RFFreqOffset << 15; // shift TX power control to correct RF register bit position
1672 R4 |= (pAd->LatchRfRegs.R4 & ((~0x001f8000)));
1673 pAd->LatchRfRegs.R4 = R4;
1677 ATEDBGPRINT(RT_DEBUG_TRACE, ("Set_ATE_TX_FREQOFFSET_Proc (RFFreqOffset = %d)\n", pAd->ate.RFFreqOffset));
1678 ATEDBGPRINT(RT_DEBUG_TRACE, ("Ralink: Set_ATE_TX_FREQOFFSET_Proc Success\n"));
1685 ==========================================================================
1690 TRUE if all parameters are OK, FALSE otherwise
1691 ==========================================================================
1693 INT Set_ATE_TX_BW_Proc(
1694 IN PRTMP_ADAPTER pAd,
1701 BBPCurrentBW = simple_strtol(arg, 0, 10);
1703 if(BBPCurrentBW == 0)
1704 pAd->ate.TxWI.BW = BW_20;
1706 pAd->ate.TxWI.BW = BW_40;
1708 if(pAd->ate.TxWI.BW == BW_20)
1710 if(pAd->ate.Channel <= 14)
1714 if (pAd->Tx20MPwrCfgGBand[i] != 0xffffffff)
1716 RTMP_IO_WRITE32(pAd, TX_PWR_CFG_0 + i*4, pAd->Tx20MPwrCfgGBand[i]);
1717 RTMPusecDelay(5000);
1725 if (pAd->Tx20MPwrCfgABand[i] != 0xffffffff)
1727 RTMP_IO_WRITE32(pAd, TX_PWR_CFG_0 + i*4, pAd->Tx20MPwrCfgABand[i]);
1728 RTMPusecDelay(5000);
1733 //Set BBP R4 bit[4:3]=0:0
1734 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &value);
1736 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, value);
1740 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R66, value);
1742 //to improve Rx sensitivity.
1744 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R68, value);
1747 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R69, value);
1750 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R70, value);
1753 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R73, value);
1755 // If Channel=14, Bandwidth=20M and Mode=CCK, Set BBP R4 bit5=1
1756 // (Japan filter coefficients)
1757 // This segment of code will only works when ATETXMODE and ATECHANNEL
1758 // were set to MODE_CCK and 14 respectively before ATETXBW is set to 0.
1759 //=====================================================================
1760 if (pAd->ate.Channel == 14)
1762 int TxMode = pAd->ate.TxWI.PHYMODE;
1763 if (TxMode == MODE_CCK)
1765 // when Channel==14 && Mode==CCK && BandWidth==20M, BBP R4 bit5=1
1766 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &value);
1767 value |= 0x20; //set bit5=1
1768 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, value);
1772 //=====================================================================
1773 // If bandwidth != 40M, RF Reg4 bit 21 = 0.
1774 pAd->LatchRfRegs.R4 &= ~0x00200000;
1777 else if(pAd->ate.TxWI.BW == BW_40)
1779 if(pAd->ate.Channel <= 14)
1783 if (pAd->Tx40MPwrCfgGBand[i] != 0xffffffff)
1785 RTMP_IO_WRITE32(pAd, TX_PWR_CFG_0 + i*4, pAd->Tx40MPwrCfgGBand[i]);
1786 RTMPusecDelay(5000);
1794 if (pAd->Tx40MPwrCfgABand[i] != 0xffffffff)
1796 RTMP_IO_WRITE32(pAd, TX_PWR_CFG_0 + i*4, pAd->Tx40MPwrCfgABand[i]);
1797 RTMPusecDelay(5000);
1800 #ifdef DOT11_N_SUPPORT
1801 if ((pAd->ate.TxWI.PHYMODE >= MODE_HTMIX) && (pAd->ate.TxWI.MCS == 7))
1804 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R67, value);
1806 #endif // DOT11_N_SUPPORT //
1809 //Set BBP R4 bit[4:3]=1:0
1810 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &value);
1813 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, value);
1817 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R66, value);
1819 //to improve Rx sensitivity.
1821 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R68, value);
1824 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R69, value);
1827 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R70, value);
1830 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R73, value);
1832 // If bandwidth = 40M, set RF Reg4 bit 21 = 1.
1833 pAd->LatchRfRegs.R4 |= 0x00200000;
1837 ATEDBGPRINT(RT_DEBUG_TRACE, ("Set_ATE_TX_BW_Proc (BBPCurrentBW = %d)\n", pAd->ate.TxWI.BW));
1838 ATEDBGPRINT(RT_DEBUG_TRACE, ("Ralink: Set_ATE_TX_BW_Proc Success\n"));
1845 ==========================================================================
1847 Set ATE Tx frame length
1850 TRUE if all parameters are OK, FALSE otherwise
1851 ==========================================================================
1853 INT Set_ATE_TX_LENGTH_Proc(
1854 IN PRTMP_ADAPTER pAd,
1857 pAd->ate.TxLength = simple_strtol(arg, 0, 10);
1859 if((pAd->ate.TxLength < 24) || (pAd->ate.TxLength > (MAX_FRAME_SIZE - 34/* == 2312 */)))
1861 pAd->ate.TxLength = (MAX_FRAME_SIZE - 34/* == 2312 */);
1862 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 */)));
1866 ATEDBGPRINT(RT_DEBUG_TRACE, ("Set_ATE_TX_LENGTH_Proc (TxLength = %d)\n", pAd->ate.TxLength));
1867 ATEDBGPRINT(RT_DEBUG_TRACE, ("Ralink: Set_ATE_TX_LENGTH_Proc Success\n"));
1874 ==========================================================================
1876 Set ATE Tx frame count
1879 TRUE if all parameters are OK, FALSE otherwise
1880 ==========================================================================
1882 INT Set_ATE_TX_COUNT_Proc(
1883 IN PRTMP_ADAPTER pAd,
1886 pAd->ate.TxCount = simple_strtol(arg, 0, 10);
1888 ATEDBGPRINT(RT_DEBUG_TRACE, ("Set_ATE_TX_COUNT_Proc (TxCount = %d)\n", pAd->ate.TxCount));
1889 ATEDBGPRINT(RT_DEBUG_TRACE, ("Ralink: Set_ATE_TX_COUNT_Proc Success\n"));
1896 ==========================================================================
1898 Set ATE Tx frame MCS
1901 TRUE if all parameters are OK, FALSE otherwise
1902 ==========================================================================
1904 INT Set_ATE_TX_MCS_Proc(
1905 IN PRTMP_ADAPTER pAd,
1911 MCS = simple_strtol(arg, 0, 10);
1912 result = CheckMCSValid(pAd->ate.TxWI.PHYMODE, MCS);
1916 pAd->ate.TxWI.MCS = (UCHAR)MCS;
1920 ATEDBGPRINT(RT_DEBUG_ERROR, ("Set_ATE_TX_MCS_Proc::Out of range, refer to rate table.\n"));
1924 ATEDBGPRINT(RT_DEBUG_TRACE, ("Set_ATE_TX_MCS_Proc (MCS = %d)\n", pAd->ate.TxWI.MCS));
1925 ATEDBGPRINT(RT_DEBUG_TRACE, ("Ralink: Set_ATE_TX_MCS_Proc Success\n"));
1932 ==========================================================================
1934 Set ATE Tx frame Mode
1938 3: MODE_HTGREENFIELD
1941 TRUE if all parameters are OK, FALSE otherwise
1942 ==========================================================================
1944 INT Set_ATE_TX_MODE_Proc(
1945 IN PRTMP_ADAPTER pAd,
1948 pAd->ate.TxWI.PHYMODE = simple_strtol(arg, 0, 10);
1950 if(pAd->ate.TxWI.PHYMODE > 3)
1952 pAd->ate.TxWI.PHYMODE = 0;
1953 ATEDBGPRINT(RT_DEBUG_ERROR, ("Set_ATE_TX_MODE_Proc::Out of range. it should be in range of 0~3\n"));
1954 ATEDBGPRINT(RT_DEBUG_ERROR, ("0: CCK, 1: OFDM, 2: HT_MIX, 3: HT_GREEN_FIELD.\n"));
1958 ATEDBGPRINT(RT_DEBUG_TRACE, ("Set_ATE_TX_MODE_Proc (TxMode = %d)\n", pAd->ate.TxWI.PHYMODE));
1959 ATEDBGPRINT(RT_DEBUG_TRACE, ("Ralink: Set_ATE_TX_MODE_Proc Success\n"));
1966 ==========================================================================
1971 TRUE if all parameters are OK, FALSE otherwise
1972 ==========================================================================
1974 INT Set_ATE_TX_GI_Proc(
1975 IN PRTMP_ADAPTER pAd,
1978 pAd->ate.TxWI.ShortGI = simple_strtol(arg, 0, 10);
1980 if(pAd->ate.TxWI.ShortGI > 1)
1982 pAd->ate.TxWI.ShortGI = 0;
1983 ATEDBGPRINT(RT_DEBUG_ERROR, ("Set_ATE_TX_GI_Proc::Out of range\n"));
1987 ATEDBGPRINT(RT_DEBUG_TRACE, ("Set_ATE_TX_GI_Proc (GI = %d)\n", pAd->ate.TxWI.ShortGI));
1988 ATEDBGPRINT(RT_DEBUG_TRACE, ("Ralink: Set_ATE_TX_GI_Proc Success\n"));
1995 ==========================================================================
1997 ==========================================================================
1999 INT Set_ATE_RX_FER_Proc(
2000 IN PRTMP_ADAPTER pAd,
2003 pAd->ate.bRxFer = simple_strtol(arg, 0, 10);
2005 if (pAd->ate.bRxFer == 1)
2007 pAd->ate.RxCntPerSec = 0;
2008 pAd->ate.RxTotalCnt = 0;
2011 ATEDBGPRINT(RT_DEBUG_TRACE, ("Set_ATE_RX_FER_Proc (bRxFer = %d)\n", pAd->ate.bRxFer));
2012 ATEDBGPRINT(RT_DEBUG_TRACE, ("Ralink: Set_ATE_RX_FER_Proc Success\n"));
2018 INT Set_ATE_Read_RF_Proc(
2019 IN PRTMP_ADAPTER pAd,
2022 ate_print(KERN_EMERG "R1 = %lx\n", pAd->LatchRfRegs.R1);
2023 ate_print(KERN_EMERG "R2 = %lx\n", pAd->LatchRfRegs.R2);
2024 ate_print(KERN_EMERG "R3 = %lx\n", pAd->LatchRfRegs.R3);
2025 ate_print(KERN_EMERG "R4 = %lx\n", pAd->LatchRfRegs.R4);
2030 INT Set_ATE_Write_RF1_Proc(
2031 IN PRTMP_ADAPTER pAd,
2034 UINT32 value = simple_strtol(arg, 0, 16);
2036 pAd->LatchRfRegs.R1 = value;
2042 INT Set_ATE_Write_RF2_Proc(
2043 IN PRTMP_ADAPTER pAd,
2046 UINT32 value = simple_strtol(arg, 0, 16);
2048 pAd->LatchRfRegs.R2 = value;
2054 INT Set_ATE_Write_RF3_Proc(
2055 IN PRTMP_ADAPTER pAd,
2058 UINT32 value = simple_strtol(arg, 0, 16);
2060 pAd->LatchRfRegs.R3 = value;
2066 INT Set_ATE_Write_RF4_Proc(
2067 IN PRTMP_ADAPTER pAd,
2070 UINT32 value = simple_strtol(arg, 0, 16);
2072 pAd->LatchRfRegs.R4 = value;
2079 ==========================================================================
2081 Load and Write EEPROM from a binary file prepared in advance.
2084 TRUE if all parameters are OK, FALSE otherwise
2085 ==========================================================================
2088 INT Set_ATE_Load_E2P_Proc(
2089 IN PRTMP_ADAPTER pAd,
2092 BOOLEAN ret = FALSE;
2093 PUCHAR src = EEPROM_BIN_FILE_NAME;
2095 INT32 retval, orgfsuid, orgfsgid;
2097 USHORT WriteEEPROM[(EEPROM_SIZE/2)];
2098 UINT32 FileLength = 0;
2099 UINT32 value = simple_strtol(arg, 0, 10);
2101 ATEDBGPRINT(RT_DEBUG_ERROR, ("===> %s (value=%d)\n\n", __func__, value));
2105 /* zero the e2p buffer */
2106 NdisZeroMemory((PUCHAR)WriteEEPROM, EEPROM_SIZE);
2108 /* save uid and gid used for filesystem access.
2109 ** set user and group to 0 (root)
2111 orgfsuid = current->fsuid;
2112 orgfsgid = current->fsgid;
2114 current->fsuid = current->fsgid = 0;
2120 /* open the bin file */
2121 srcf = filp_open(src, O_RDONLY, 0);
2125 ate_print("%s - Error %ld opening %s\n", __func__, -PTR_ERR(srcf), src);
2129 /* the object must have a read method */
2130 if ((srcf->f_op == NULL) || (srcf->f_op->read == NULL))
2132 ate_print("%s - %s does not have a read method\n", __func__, src);
2136 /* read the firmware from the file *.bin */
2137 FileLength = srcf->f_op->read(srcf,
2138 (PUCHAR)WriteEEPROM,
2142 if (FileLength != EEPROM_SIZE)
2144 ate_print("%s: error file length (=%d) in e2p.bin\n",
2145 __func__, FileLength);
2150 /* write the content of .bin file to EEPROM */
2151 rt_ee_write_all(pAd, WriteEEPROM);
2157 /* close firmware file */
2164 retval = filp_close(srcf, NULL);
2167 ATEDBGPRINT(RT_DEBUG_ERROR, ("--> Error %d closing %s\n", -retval, src));
2174 current->fsuid = orgfsuid;
2175 current->fsgid = orgfsgid;
2177 ATEDBGPRINT(RT_DEBUG_ERROR, ("<=== %s (ret=%d)\n", __func__, ret));
2183 INT Set_ATE_Load_E2P_Proc(
2184 IN PRTMP_ADAPTER pAd,
2187 USHORT WriteEEPROM[(EEPROM_SIZE/2)];
2188 struct iwreq *wrq = (struct iwreq *)arg;
2190 ATEDBGPRINT(RT_DEBUG_TRACE, ("===> %s (wrq->u.data.length = %d)\n\n", __func__, wrq->u.data.length));
2192 if (wrq->u.data.length != EEPROM_SIZE)
2194 ate_print("%s: error length (=%d) from host\n",
2195 __func__, wrq->u.data.length);
2198 else/* (wrq->u.data.length == EEPROM_SIZE) */
2200 /* zero the e2p buffer */
2201 NdisZeroMemory((PUCHAR)WriteEEPROM, EEPROM_SIZE);
2203 /* fill the local buffer */
2204 NdisMoveMemory((PUCHAR)WriteEEPROM, wrq->u.data.pointer, wrq->u.data.length);
2208 /* write the content of .bin file to EEPROM */
2209 rt_ee_write_all(pAd, WriteEEPROM);
2214 ATEDBGPRINT(RT_DEBUG_TRACE, ("<=== %s\n", __func__));
2221 INT Set_ATE_Read_E2P_Proc(
2222 IN PRTMP_ADAPTER pAd,
2225 USHORT buffer[EEPROM_SIZE/2];
2229 rt_ee_read_all(pAd, (USHORT *)buffer);
2231 for (i = 0; i < (EEPROM_SIZE/2); i++)
2233 ate_print("%4.4x ", *p);
2234 if (((i+1) % 16) == 0)
2241 INT Set_ATE_Show_Proc(
2242 IN PRTMP_ADAPTER pAd,
2245 ate_print("Mode=%d\n", pAd->ate.Mode);
2246 ate_print("TxPower0=%d\n", pAd->ate.TxPower0);
2247 ate_print("TxPower1=%d\n", pAd->ate.TxPower1);
2248 ate_print("TxAntennaSel=%d\n", pAd->ate.TxAntennaSel);
2249 ate_print("RxAntennaSel=%d\n", pAd->ate.RxAntennaSel);
2250 ate_print("BBPCurrentBW=%d\n", pAd->ate.TxWI.BW);
2251 ate_print("GI=%d\n", pAd->ate.TxWI.ShortGI);
2252 ate_print("MCS=%d\n", pAd->ate.TxWI.MCS);
2253 ate_print("TxMode=%d\n", pAd->ate.TxWI.PHYMODE);
2254 ate_print("Addr1=%02x:%02x:%02x:%02x:%02x:%02x\n",
2255 pAd->ate.Addr1[0], pAd->ate.Addr1[1], pAd->ate.Addr1[2], pAd->ate.Addr1[3], pAd->ate.Addr1[4], pAd->ate.Addr1[5]);
2256 ate_print("Addr2=%02x:%02x:%02x:%02x:%02x:%02x\n",
2257 pAd->ate.Addr2[0], pAd->ate.Addr2[1], pAd->ate.Addr2[2], pAd->ate.Addr2[3], pAd->ate.Addr2[4], pAd->ate.Addr2[5]);
2258 ate_print("Addr3=%02x:%02x:%02x:%02x:%02x:%02x\n",
2259 pAd->ate.Addr3[0], pAd->ate.Addr3[1], pAd->ate.Addr3[2], pAd->ate.Addr3[3], pAd->ate.Addr3[4], pAd->ate.Addr3[5]);
2260 ate_print("Channel=%d\n", pAd->ate.Channel);
2261 ate_print("TxLength=%d\n", pAd->ate.TxLength);
2262 ate_print("TxCount=%u\n", pAd->ate.TxCount);
2263 ate_print("RFFreqOffset=%d\n", pAd->ate.RFFreqOffset);
2264 ate_print(KERN_EMERG "Set_ATE_Show_Proc Success\n");
2268 INT Set_ATE_Help_Proc(
2269 IN PRTMP_ADAPTER pAd,
2272 ate_print("ATE=ATESTART, ATESTOP, TXCONT, TXCARR, TXFRAME, RXFRAME\n");
2273 ate_print("ATEDA\n");
2274 ate_print("ATESA\n");
2275 ate_print("ATEBSSID\n");
2276 ate_print("ATECHANNEL, range:0~14(unless A band !)\n");
2277 ate_print("ATETXPOW0, set power level of antenna 1.\n");
2278 ate_print("ATETXPOW1, set power level of antenna 2.\n");
2279 ate_print("ATETXANT, set TX antenna. 0:all, 1:antenna one, 2:antenna two.\n");
2280 ate_print("ATERXANT, set RX antenna.0:all, 1:antenna one, 2:antenna two, 3:antenna three.\n");
2281 ate_print("ATETXFREQOFFSET, set frequency offset, range 0~63\n");
2282 ate_print("ATETXBW, set BandWidth, 0:20MHz, 1:40MHz.\n");
2283 ate_print("ATETXLEN, set Frame length, range 24~%d\n", (MAX_FRAME_SIZE - 34/* == 2312 */));
2284 ate_print("ATETXCNT, set how many frame going to transmit.\n");
2285 ate_print("ATETXMCS, set MCS, reference to rate table.\n");
2286 ate_print("ATETXMODE, set Mode 0:CCK, 1:OFDM, 2:HT-Mix, 3:GreenField, reference to rate table.\n");
2287 ate_print("ATETXGI, set GI interval, 0:Long, 1:Short\n");
2288 ate_print("ATERXFER, 0:disable Rx Frame error rate. 1:enable Rx Frame error rate.\n");
2289 ate_print("ATERRF, show all RF registers.\n");
2290 ate_print("ATEWRF1, set RF1 register.\n");
2291 ate_print("ATEWRF2, set RF2 register.\n");
2292 ate_print("ATEWRF3, set RF3 register.\n");
2293 ate_print("ATEWRF4, set RF4 register.\n");
2294 ate_print("ATELDE2P, load EEPROM from .bin file.\n");
2295 ate_print("ATERE2P, display all EEPROM content.\n");
2296 ate_print("ATESHOW, display all parameters of ATE.\n");
2297 ate_print("ATEHELP, online help.\n");
2303 ==========================================================================
2306 AsicSwitchChannel() dedicated for ATE.
2308 ==========================================================================
2310 VOID ATEAsicSwitchChannel(
2311 IN PRTMP_ADAPTER pAd)
2313 UINT32 R2 = 0, R3 = DEFAULT_RF_TX_POWER, R4 = 0, Value = 0;
2314 CHAR TxPwer = 0, TxPwer2 = 0;
2315 UCHAR index, BbpValue = 0, R66 = 0x30;
2316 RTMP_RF_REGS *RFRegTable;
2319 #ifdef RALINK_28xx_QA
2320 if ((pAd->ate.bQATxStart == TRUE) || (pAd->ate.bQARxStart == TRUE))
2322 if (pAd->ate.Channel != pAd->LatchRfRegs.Channel)
2324 pAd->ate.Channel = pAd->LatchRfRegs.Channel;
2329 #endif // RALINK_28xx_QA //
2330 Channel = pAd->ate.Channel;
2333 AsicAntennaSelect(pAd, Channel);
2335 // fill Tx power value
2336 TxPwer = pAd->ate.TxPower0;
2337 TxPwer2 = pAd->ate.TxPower1;
2339 RFRegTable = RF2850RegTable;
2341 switch (pAd->RfIcType)
2343 /* But only 2850 and 2750 support 5.5GHz band... */
2349 for (index = 0; index < NUM_OF_2850_CHNL; index++)
2351 if (Channel == RFRegTable[index].Channel)
2353 R2 = RFRegTable[index].R2;
2354 if (pAd->Antenna.field.TxPath == 1)
2356 R2 |= 0x4000; // If TXpath is 1, bit 14 = 1;
2359 if (pAd->Antenna.field.RxPath == 2)
2361 switch (pAd->ate.RxAntennaSel)
2365 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R3, &BbpValue);
2368 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, BbpValue);
2372 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R3, &BbpValue);
2375 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, BbpValue);
2379 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R3, &BbpValue);
2381 /* Only enable two Antenna to receive. */
2383 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, BbpValue);
2387 else if (pAd->Antenna.field.RxPath == 1)
2389 R2 |= 0x20040; // write 1 to off RxPath
2392 if (pAd->Antenna.field.TxPath == 2)
2394 if (pAd->ate.TxAntennaSel == 1)
2396 R2 |= 0x4000; // If TX Antenna select is 1 , bit 14 = 1; Disable Ant 2
2397 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R1, &BbpValue);
2398 BbpValue &= 0xE7; //11100111B
2399 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R1, BbpValue);
2401 else if (pAd->ate.TxAntennaSel == 2)
2403 R2 |= 0x8000; // If TX Antenna select is 2 , bit 15 = 1; Disable Ant 1
2404 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R1, &BbpValue);
2407 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R1, BbpValue);
2411 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R1, &BbpValue);
2414 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R1, BbpValue);
2417 if (pAd->Antenna.field.RxPath == 3)
2419 switch (pAd->ate.RxAntennaSel)
2423 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R3, &BbpValue);
2426 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, BbpValue);
2430 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R3, &BbpValue);
2433 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, BbpValue);
2437 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R3, &BbpValue);
2440 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, BbpValue);
2443 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R3, &BbpValue);
2446 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, BbpValue);
2453 // initialize R3, R4
2454 R3 = (RFRegTable[index].R3 & 0xffffc1ff);
2455 R4 = (RFRegTable[index].R4 & (~0x001f87c0)) | (pAd->ate.RFFreqOffset << 15);
2457 // According the Rory's suggestion to solve the middle range issue.
2458 // 5.5G band power range: 0xF9~0X0F, TX0 Reg3 bit9/TX1 Reg4 bit6="0" means the TX power reduce 7dB
2460 if ((TxPwer >= -7) && (TxPwer < 0))
2462 TxPwer = (7+TxPwer);
2463 TxPwer = (TxPwer > 0xF) ? (0xF) : (TxPwer);
2464 R3 |= (TxPwer << 10);
2465 ATEDBGPRINT(RT_DEBUG_TRACE, ("ATEAsicSwitchChannel: TxPwer=%d \n", TxPwer));
2469 TxPwer = (TxPwer > 0xF) ? (0xF) : (TxPwer);
2470 R3 |= (TxPwer << 10) | (1 << 9);
2474 if ((TxPwer2 >= -7) && (TxPwer2 < 0))
2476 TxPwer2 = (7+TxPwer2);
2477 TxPwer2 = (TxPwer2 > 0xF) ? (0xF) : (TxPwer2);
2478 R4 |= (TxPwer2 << 7);
2479 ATEDBGPRINT(RT_DEBUG_TRACE, ("ATEAsicSwitchChannel: TxPwer2=%d \n", TxPwer2));
2483 TxPwer2 = (TxPwer2 > 0xF) ? (0xF) : (TxPwer2);
2484 R4 |= (TxPwer2 << 7) | (1 << 6);
2489 R3 = (RFRegTable[index].R3 & 0xffffc1ff) | (TxPwer << 9); // set TX power0
2490 R4 = (RFRegTable[index].R4 & (~0x001f87c0)) | (pAd->ate.RFFreqOffset << 15) | (TxPwer2 <<6);// Set freq offset & TxPwr1
2493 // Based on BBP current mode before changing RF channel.
2494 if (pAd->ate.TxWI.BW == BW_40)
2500 pAd->LatchRfRegs.Channel = Channel;
2501 pAd->LatchRfRegs.R1 = RFRegTable[index].R1;
2502 pAd->LatchRfRegs.R2 = R2;
2503 pAd->LatchRfRegs.R3 = R3;
2504 pAd->LatchRfRegs.R4 = R4;
2517 // Change BBP setting during switch from a->g, g->a
2520 ULONG TxPinCfg = 0x00050F0A;// 2007.10.09 by Brian : 0x0005050A ==> 0x00050F0A
2522 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R62, (0x37 - GET_LNA_GAIN(pAd)));
2523 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R63, (0x37 - GET_LNA_GAIN(pAd)));
2524 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R64, (0x37 - GET_LNA_GAIN(pAd)));
2526 /* For 1T/2R chip only... */
2527 if (pAd->NicConfig2.field.ExternalLNAForG)
2529 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R82, 0x62);
2533 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R82, 0x84);
2536 // According the Rory's suggestion to solve the middle range issue.
2537 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R86, &BbpValue);
2538 ASSERT((BbpValue == 0x00));
2539 if ((BbpValue != 0x00))
2541 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R86, 0x00);
2544 // 5.5GHz band selection PIN, bit1 and bit2 are complement
2545 RTMP_IO_READ32(pAd, TX_BAND_CFG, &Value);
2548 RTMP_IO_WRITE32(pAd, TX_BAND_CFG, Value);
2550 // Turn off unused PA or LNA when only 1T or 1R.
2551 if (pAd->Antenna.field.TxPath == 1)
2553 TxPinCfg &= 0xFFFFFFF3;
2555 if (pAd->Antenna.field.RxPath == 1)
2557 TxPinCfg &= 0xFFFFF3FF;
2560 RTMP_IO_WRITE32(pAd, TX_PIN_CFG, TxPinCfg);
2564 ULONG TxPinCfg = 0x00050F05;//2007.10.09 by Brian : 0x00050505 ==> 0x00050F05
2566 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R62, (0x37 - GET_LNA_GAIN(pAd)));
2567 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R63, (0x37 - GET_LNA_GAIN(pAd)));
2568 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R64, (0x37 - GET_LNA_GAIN(pAd)));
2569 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R82, 0xF2);
2571 // According the Rory's suggestion to solve the middle range issue.
2572 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R86, &BbpValue);
2573 ASSERT((BbpValue == 0x00));
2574 if ((BbpValue != 0x00))
2576 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R86, 0x00);
2578 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R91, &BbpValue);
2579 ASSERT((BbpValue == 0x04));
2581 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R92, &BbpValue);
2582 ASSERT((BbpValue == 0x00));
2584 // 5.5GHz band selection PIN, bit1 and bit2 are complement
2585 RTMP_IO_READ32(pAd, TX_BAND_CFG, &Value);
2588 RTMP_IO_WRITE32(pAd, TX_BAND_CFG, Value);
2590 // Turn off unused PA or LNA when only 1T or 1R.
2591 if (pAd->Antenna.field.TxPath == 1)
2593 TxPinCfg &= 0xFFFFFFF3;
2595 if (pAd->Antenna.field.RxPath == 1)
2597 TxPinCfg &= 0xFFFFF3FF;
2600 RTMP_IO_WRITE32(pAd, TX_PIN_CFG, TxPinCfg);
2603 // R66 should be set according to Channel and use 20MHz when scanning
2607 R66 = 0x2E + GET_LNA_GAIN(pAd);
2608 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R66, R66);
2613 if (pAd->ate.TxWI.BW == BW_20)
2615 R66 = (UCHAR)(0x32 + (GET_LNA_GAIN(pAd)*5)/3);
2616 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R66, R66);
2620 R66 = (UCHAR)(0x3A + (GET_LNA_GAIN(pAd)*5)/3);
2621 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R66, R66);
2626 // On 11A, We should delay and wait RF/BBP to be stable
2627 // and the appropriate time should be 1000 micro seconds
2628 // 2005/06/05 - On 11G, We also need this delay time. Otherwise it's difficult to pass the WHQL.
2630 RTMPusecDelay(1000);
2634 // When 5.5GHz band the LSB of TxPwr will be used to reduced 7dB or not.
2635 ATEDBGPRINT(RT_DEBUG_TRACE, ("SwitchChannel#%d(RF=%d, %dT) to , R1=0x%08lx, R2=0x%08lx, R3=0x%08lx, R4=0x%08lx\n",
2638 pAd->Antenna.field.TxPath,
2639 pAd->LatchRfRegs.R1,
2640 pAd->LatchRfRegs.R2,
2641 pAd->LatchRfRegs.R3,
2642 pAd->LatchRfRegs.R4));
2646 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",
2649 (R3 & 0x00003e00) >> 9,
2650 (R4 & 0x000007c0) >> 6,
2651 pAd->Antenna.field.TxPath,
2652 pAd->LatchRfRegs.R1,
2653 pAd->LatchRfRegs.R2,
2654 pAd->LatchRfRegs.R3,
2655 pAd->LatchRfRegs.R4));
2660 // In fact, no one will call this routine so far !
2663 ==========================================================================
2665 Gives CCK TX rate 2 more dB TX power.
2666 This routine works only in ATE mode.
2668 calculate desired Tx power in RF R3.Tx0~5, should consider -
2669 0. if current radio is a noisy environment (pAd->DrsCounters.fNoisyEnvironment)
2670 1. TxPowerPercentage
2671 2. auto calibration based on TSSI feedback
2672 3. extra 2 db for CCK
2673 4. -10 db upon very-short distance (AvgRSSI >= -40db) to AP
2675 NOTE: Since this routine requires the value of (pAd->DrsCounters.fNoisyEnvironment),
2676 it should be called AFTER MlmeDynamicTxRateSwitching()
2677 ==========================================================================
2679 VOID ATEAsicAdjustTxPower(
2680 IN PRTMP_ADAPTER pAd)
2684 BOOLEAN bAutoTxAgc = FALSE;
2685 UCHAR TssiRef, *pTssiMinusBoundary, *pTssiPlusBoundary, TxAgcStep;
2686 UCHAR BbpR49 = 0, idx;
2687 PCHAR pTxAgcCompensate;
2691 /* no one calls this procedure so far */
2692 if (pAd->ate.TxWI.BW == BW_40)
2694 if (pAd->ate.Channel > 14)
2696 TxPwr[0] = pAd->Tx40MPwrCfgABand[0];
2697 TxPwr[1] = pAd->Tx40MPwrCfgABand[1];
2698 TxPwr[2] = pAd->Tx40MPwrCfgABand[2];
2699 TxPwr[3] = pAd->Tx40MPwrCfgABand[3];
2700 TxPwr[4] = pAd->Tx40MPwrCfgABand[4];
2704 TxPwr[0] = pAd->Tx40MPwrCfgGBand[0];
2705 TxPwr[1] = pAd->Tx40MPwrCfgGBand[1];
2706 TxPwr[2] = pAd->Tx40MPwrCfgGBand[2];
2707 TxPwr[3] = pAd->Tx40MPwrCfgGBand[3];
2708 TxPwr[4] = pAd->Tx40MPwrCfgGBand[4];
2713 if (pAd->ate.Channel > 14)
2715 TxPwr[0] = pAd->Tx20MPwrCfgABand[0];
2716 TxPwr[1] = pAd->Tx20MPwrCfgABand[1];
2717 TxPwr[2] = pAd->Tx20MPwrCfgABand[2];
2718 TxPwr[3] = pAd->Tx20MPwrCfgABand[3];
2719 TxPwr[4] = pAd->Tx20MPwrCfgABand[4];
2723 TxPwr[0] = pAd->Tx20MPwrCfgGBand[0];
2724 TxPwr[1] = pAd->Tx20MPwrCfgGBand[1];
2725 TxPwr[2] = pAd->Tx20MPwrCfgGBand[2];
2726 TxPwr[3] = pAd->Tx20MPwrCfgGBand[3];
2727 TxPwr[4] = pAd->Tx20MPwrCfgGBand[4];
2731 // TX power compensation for temperature variation based on TSSI.
2732 // Do it per 4 seconds.
2733 if (pAd->Mlme.OneSecPeriodicRound % 4 == 0)
2735 if (pAd->ate.Channel <= 14)
2738 bAutoTxAgc = pAd->bAutoTxAgcG;
2739 TssiRef = pAd->TssiRefG;
2740 pTssiMinusBoundary = &pAd->TssiMinusBoundaryG[0];
2741 pTssiPlusBoundary = &pAd->TssiPlusBoundaryG[0];
2742 TxAgcStep = pAd->TxAgcStepG;
2743 pTxAgcCompensate = &pAd->TxAgcCompensateG;
2748 bAutoTxAgc = pAd->bAutoTxAgcA;
2749 TssiRef = pAd->TssiRefA;
2750 pTssiMinusBoundary = &pAd->TssiMinusBoundaryA[0];
2751 pTssiPlusBoundary = &pAd->TssiPlusBoundaryA[0];
2752 TxAgcStep = pAd->TxAgcStepA;
2753 pTxAgcCompensate = &pAd->TxAgcCompensateA;
2758 /* BbpR49 is unsigned char */
2759 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R49, &BbpR49);
2761 /* (p) TssiPlusBoundaryG[0] = 0 = (m) TssiMinusBoundaryG[0] */
2762 /* compensate: +4 +3 +2 +1 0 -1 -2 -3 -4 * steps */
2763 /* step value is defined in pAd->TxAgcStepG for tx power value */
2765 /* [4]+1+[4] p4 p3 p2 p1 o1 m1 m2 m3 m4 */
2766 /* ex: 0x00 0x15 0x25 0x45 0x88 0xA0 0xB5 0xD0 0xF0
2767 above value are examined in mass factory production */
2768 /* [4] [3] [2] [1] [0] [1] [2] [3] [4] */
2770 /* plus is 0x10 ~ 0x40, minus is 0x60 ~ 0x90 */
2771 /* if value is between p1 ~ o1 or o1 ~ s1, no need to adjust tx power */
2772 /* if value is 0x65, tx power will be -= TxAgcStep*(2-1) */
2774 if (BbpR49 > pTssiMinusBoundary[1])
2776 // Reading is larger than the reference value.
2777 // Check for how large we need to decrease the Tx power.
2778 for (idx = 1; idx < 5; idx++)
2780 if (BbpR49 <= pTssiMinusBoundary[idx]) // Found the range
2783 // The index is the step we should decrease, idx = 0 means there is nothing to compensate
2784 // if (R3 > (ULONG) (TxAgcStep * (idx-1)))
2785 *pTxAgcCompensate = -(TxAgcStep * (idx-1));
2787 // *pTxAgcCompensate = -((UCHAR)R3);
2789 DeltaPwr += (*pTxAgcCompensate);
2790 ATEDBGPRINT(RT_DEBUG_TRACE, ("-- Tx Power, BBP R1=%x, TssiRef=%x, TxAgcStep=%x, step = -%d\n",
2791 BbpR49, TssiRef, TxAgcStep, idx-1));
2793 else if (BbpR49 < pTssiPlusBoundary[1])
2795 // Reading is smaller than the reference value
2796 // check for how large we need to increase the Tx power
2797 for (idx = 1; idx < 5; idx++)
2799 if (BbpR49 >= pTssiPlusBoundary[idx]) // Found the range
2802 // The index is the step we should increase, idx = 0 means there is nothing to compensate
2803 *pTxAgcCompensate = TxAgcStep * (idx-1);
2804 DeltaPwr += (*pTxAgcCompensate);
2805 ATEDBGPRINT(RT_DEBUG_TRACE, ("++ Tx Power, BBP R1=%x, TssiRef=%x, TxAgcStep=%x, step = +%d\n",
2806 BbpR49, TssiRef, TxAgcStep, idx-1));
2810 *pTxAgcCompensate = 0;
2811 ATEDBGPRINT(RT_DEBUG_TRACE, (" Tx Power, BBP R1=%x, TssiRef=%x, TxAgcStep=%x, step = +%d\n",
2812 BbpR49, TssiRef, TxAgcStep, 0));
2818 if (pAd->ate.Channel <= 14)
2820 bAutoTxAgc = pAd->bAutoTxAgcG;
2821 pTxAgcCompensate = &pAd->TxAgcCompensateG;
2825 bAutoTxAgc = pAd->bAutoTxAgcA;
2826 pTxAgcCompensate = &pAd->TxAgcCompensateA;
2830 DeltaPwr += (*pTxAgcCompensate);
2833 /* calculate delta power based on the percentage specified from UI */
2834 // E2PROM setting is calibrated for maximum TX power (i.e. 100%)
2835 // We lower TX power here according to the percentage specified from UI
2836 if (pAd->CommonCfg.TxPowerPercentage == 0xffffffff) // AUTO TX POWER control
2838 else if (pAd->CommonCfg.TxPowerPercentage > 90) // 91 ~ 100% & AUTO, treat as 100% in terms of mW
2840 else if (pAd->CommonCfg.TxPowerPercentage > 60) // 61 ~ 90%, treat as 75% in terms of mW
2844 else if (pAd->CommonCfg.TxPowerPercentage > 30) // 31 ~ 60%, treat as 50% in terms of mW
2848 else if (pAd->CommonCfg.TxPowerPercentage > 15) // 16 ~ 30%, treat as 25% in terms of mW
2852 else if (pAd->CommonCfg.TxPowerPercentage > 9) // 10 ~ 15%, treat as 12.5% in terms of mW
2856 else // 0 ~ 9 %, treat as MIN(~3%) in terms of mW
2861 /* reset different new tx power for different TX rate */
2864 if (TxPwr[i] != 0xffffffff)
2868 Value = (CHAR)((TxPwr[i] >> j*4) & 0x0F); /* 0 ~ 15 */
2870 if ((Value + DeltaPwr) < 0)
2872 Value = 0; /* min */
2874 else if ((Value + DeltaPwr) > 0xF)
2876 Value = 0xF; /* max */
2880 Value += DeltaPwr; /* temperature compensation */
2883 /* fill new value to CSR offset */
2884 TxPwr[i] = (TxPwr[i] & ~(0x0000000F << j*4)) | (Value << j*4);
2887 /* write tx power value to CSR */
2888 /* TX_PWR_CFG_0 (8 tx rate) for TX power for OFDM 12M/18M
2889 TX power for OFDM 6M/9M
2890 TX power for CCK5.5M/11M
2891 TX power for CCK1M/2M */
2892 /* TX_PWR_CFG_1 ~ TX_PWR_CFG_4 */
2893 RTMP_IO_WRITE32(pAd, TX_PWR_CFG_0 + i*4, TxPwr[i]);
2902 ========================================================================
2903 Routine Description:
2904 Write TxWI for ATE mode.
2908 ========================================================================
2911 static VOID ATEWriteTxWI(
2912 IN PRTMP_ADAPTER pAd,
2913 IN PTXWI_STRUC pOutTxWI,
2916 IN BOOLEAN InsTimestamp,
2919 IN BOOLEAN NSeq, // HW new a sequence.
2928 IN HTTRANSMIT_SETTING *pTransmit)
2934 // Always use Long preamble before verifiation short preamble functionality works well.
2935 // Todo: remove the following line if short preamble functionality works
2937 OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_SHORT_PREAMBLE_INUSED);
2938 NdisZeroMemory(&TxWI, TXWI_SIZE);
2943 pTxWI->CFACK = CFACK;
2944 pTxWI->TS= InsTimestamp;
2945 pTxWI->AMPDU = AMPDU;
2947 pTxWI->txop= Txopmode;
2950 // John tune the performace with Intel Client in 20 MHz performance
2954 pTxWI->BAWinSize = BASize;
2955 pTxWI->WirelessCliID = WCID;
2956 pTxWI->MPDUtotalByteCount = Length;
2957 pTxWI->PacketId = PID;
2959 // If CCK or OFDM, BW must be 20
2960 pTxWI->BW = (pTransmit->field.MODE <= MODE_OFDM) ? (BW_20) : (pTransmit->field.BW);
2961 pTxWI->ShortGI = pTransmit->field.ShortGI;
2962 pTxWI->STBC = pTransmit->field.STBC;
2964 pTxWI->MCS = pTransmit->field.MCS;
2965 pTxWI->PHYMODE = pTransmit->field.MODE;
2966 pTxWI->CFACK = CfAck;
2968 pTxWI->MpduDensity = 0;
2970 pTxWI->PacketId = pTxWI->MCS;
2971 NdisMoveMemory(pOutTxWI, &TxWI, sizeof(TXWI_STRUC));
2978 ========================================================================
2980 Routine Description:
2981 Disable protection for ATE.
2982 ========================================================================
2984 VOID ATEDisableAsicProtect(
2985 IN PRTMP_ADAPTER pAd)
2987 PROT_CFG_STRUC ProtCfg, ProtCfg4;
2993 // Config ASIC RTS threshold register
2994 RTMP_IO_READ32(pAd, TX_RTS_CFG, &MacReg);
2995 MacReg &= 0xFF0000FF;
2996 MacReg |= (pAd->CommonCfg.RtsThreshold << 8);
2997 RTMP_IO_WRITE32(pAd, TX_RTS_CFG, MacReg);
2999 // Initial common protection settings
3000 RTMPZeroMemory(Protect, sizeof(Protect));
3003 ProtCfg.field.TxopAllowGF40 = 1;
3004 ProtCfg.field.TxopAllowGF20 = 1;
3005 ProtCfg.field.TxopAllowMM40 = 1;
3006 ProtCfg.field.TxopAllowMM20 = 1;
3007 ProtCfg.field.TxopAllowOfdm = 1;
3008 ProtCfg.field.TxopAllowCck = 1;
3009 ProtCfg.field.RTSThEn = 1;
3010 ProtCfg.field.ProtectNav = ASIC_SHORTNAV;
3012 // Handle legacy(B/G) protection
3013 ProtCfg.field.ProtectRate = pAd->CommonCfg.RtsRate;
3014 ProtCfg.field.ProtectCtrl = 0;
3015 Protect[0] = ProtCfg.word;
3016 Protect[1] = ProtCfg.word;
3019 // 1.All STAs in the BSS are 20/40 MHz HT
3020 // 2. in ai 20/40MHz BSS
3021 // 3. all STAs are 20MHz in a 20MHz BSS
3022 // Pure HT. no protection.
3026 // PROT_TXOP(25:20) -- 010111
3027 // PROT_NAV(19:18) -- 01 (Short NAV protection)
3028 // PROT_CTRL(17:16) -- 00 (None)
3029 // PROT_RATE(15:0) -- 0x4004 (OFDM 24M)
3030 Protect[2] = 0x01744004;
3034 // PROT_TXOP(25:20) -- 111111
3035 // PROT_NAV(19:18) -- 01 (Short NAV protection)
3036 // PROT_CTRL(17:16) -- 00 (None)
3037 // PROT_RATE(15:0) -- 0x4084 (duplicate OFDM 24M)
3038 Protect[3] = 0x03f44084;
3042 // PROT_TXOP(25:20) -- 010111
3043 // PROT_NAV(19:18) -- 01 (Short NAV protection)
3044 // PROT_CTRL(17:16) -- 00 (None)
3045 // PROT_RATE(15:0) -- 0x4004 (OFDM 24M)
3046 Protect[4] = 0x01744004;
3050 // PROT_TXOP(25:20) -- 111111
3051 // PROT_NAV(19:18) -- 01 (Short NAV protection)
3052 // PROT_CTRL(17:16) -- 00 (None)
3053 // PROT_RATE(15:0) -- 0x4084 (duplicate OFDM 24M)
3054 Protect[5] = 0x03f44084;
3056 pAd->CommonCfg.IOTestParm.bRTSLongProtOn = FALSE;
3058 offset = CCK_PROT_CFG;
3059 for (i = 0;i < 6;i++)
3060 RTMP_IO_WRITE32(pAd, offset + i*4, Protect[i]);
3065 /* There are two ways to convert Rssi */
3068 // The way used with GET_LNA_GAIN().
3070 CHAR ATEConvertToRssi(
3071 IN PRTMP_ADAPTER pAd,
3073 IN UCHAR RssiNumber)
3075 UCHAR RssiOffset, LNAGain;
3077 // Rssi equals to zero should be an invalid value
3081 LNAGain = GET_LNA_GAIN(pAd);
3082 if (pAd->LatchRfRegs.Channel > 14)
3084 if (RssiNumber == 0)
3085 RssiOffset = pAd->ARssiOffset0;
3086 else if (RssiNumber == 1)
3087 RssiOffset = pAd->ARssiOffset1;
3089 RssiOffset = pAd->ARssiOffset2;
3093 if (RssiNumber == 0)
3094 RssiOffset = pAd->BGRssiOffset0;
3095 else if (RssiNumber == 1)
3096 RssiOffset = pAd->BGRssiOffset1;
3098 RssiOffset = pAd->BGRssiOffset2;
3101 return (-12 - RssiOffset - LNAGain - Rssi);
3105 // The way originally used in ATE of rt2860ap.
3107 CHAR ATEConvertToRssi(
3108 IN PRTMP_ADAPTER pAd,
3110 IN UCHAR RssiNumber)
3112 UCHAR RssiOffset, LNAGain;
3114 // Rssi equals to zero should be an invalid value
3118 if (pAd->LatchRfRegs.Channel > 14)
3120 LNAGain = pAd->ALNAGain;
3121 if (RssiNumber == 0)
3122 RssiOffset = pAd->ARssiOffset0;
3123 else if (RssiNumber == 1)
3124 RssiOffset = pAd->ARssiOffset1;
3126 RssiOffset = pAd->ARssiOffset2;
3130 LNAGain = pAd->BLNAGain;
3131 if (RssiNumber == 0)
3132 RssiOffset = pAd->BGRssiOffset0;
3133 else if (RssiNumber == 1)
3134 RssiOffset = pAd->BGRssiOffset1;
3136 RssiOffset = pAd->BGRssiOffset2;
3139 return (-32 - RssiOffset + LNAGain - Rssi);
3141 #endif /* end of #if 1 */
3144 ========================================================================
3146 Routine Description:
3147 Set Japan filter coefficients if needed.
3149 This routine should only be called when
3150 entering TXFRAME mode or TXCONT mode.
3152 ========================================================================
3154 static VOID SetJapanFilter(
3155 IN PRTMP_ADAPTER pAd)
3160 // If Channel=14 and Bandwidth=20M and Mode=CCK, set BBP R4 bit5=1
3161 // (Japan Tx filter coefficients)when (TXFRAME or TXCONT).
3163 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &BbpData);
3165 if ((pAd->ate.TxWI.PHYMODE == MODE_CCK) && (pAd->ate.Channel == 14) && (pAd->ate.TxWI.BW == BW_20))
3167 BbpData |= 0x20; // turn on
3168 ATEDBGPRINT(RT_DEBUG_TRACE, ("SetJapanFilter!!!\n"));
3172 BbpData &= 0xdf; // turn off
3173 ATEDBGPRINT(RT_DEBUG_TRACE, ("ClearJapanFilter!!!\n"));
3176 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, BbpData);
3180 IN PRTMP_ADAPTER pAd,
3181 IN PRXWI_STRUC pRxWI)
3183 /* There are two ways to collect RSSI. */
3185 //pAd->LastRxRate = (USHORT)((pRxWI->MCS) + (pRxWI->BW <<7) + (pRxWI->ShortGI <<8)+ (pRxWI->PHYMODE <<14)) ;
3186 if (pRxWI->RSSI0 != 0)
3188 pAd->ate.LastRssi0 = ATEConvertToRssi(pAd, (CHAR) pRxWI->RSSI0, RSSI_0);
3189 pAd->ate.AvgRssi0X8 = (pAd->ate.AvgRssi0X8 - pAd->ate.AvgRssi0) + pAd->ate.LastRssi0;
3190 pAd->ate.AvgRssi0 = pAd->ate.AvgRssi0X8 >> 3;
3192 if (pRxWI->RSSI1 != 0)
3194 pAd->ate.LastRssi1 = ATEConvertToRssi(pAd, (CHAR) pRxWI->RSSI1, RSSI_1);
3195 pAd->ate.AvgRssi1X8 = (pAd->ate.AvgRssi1X8 - pAd->ate.AvgRssi1) + pAd->ate.LastRssi1;
3196 pAd->ate.AvgRssi1 = pAd->ate.AvgRssi1X8 >> 3;
3198 if (pRxWI->RSSI2 != 0)
3200 pAd->ate.LastRssi2 = ATEConvertToRssi(pAd, (CHAR) pRxWI->RSSI2, RSSI_2);
3201 pAd->ate.AvgRssi2X8 = (pAd->ate.AvgRssi2X8 - pAd->ate.AvgRssi2) + pAd->ate.LastRssi2;
3202 pAd->ate.AvgRssi2 = pAd->ate.AvgRssi2X8 >> 3;
3205 pAd->ate.LastSNR0 = (CHAR)(pRxWI->SNR0);// CHAR ==> UCHAR ?
3206 pAd->ate.LastSNR1 = (CHAR)(pRxWI->SNR1);// CHAR ==> UCHAR ?
3208 pAd->ate.NumOfAvgRssiSample ++;
3210 pAd->ate.LastSNR0 = (CHAR)(pRxWI->SNR0);
3211 pAd->ate.LastSNR1 = (CHAR)(pRxWI->SNR1);
3212 pAd->ate.RxCntPerSec++;
3213 pAd->ate.LastRssi0 = ATEConvertToRssi(pAd, (CHAR) pRxWI->RSSI0, RSSI_0);
3214 pAd->ate.LastRssi1 = ATEConvertToRssi(pAd, (CHAR) pRxWI->RSSI1, RSSI_1);
3215 pAd->ate.LastRssi2 = ATEConvertToRssi(pAd, (CHAR) pRxWI->RSSI2, RSSI_2);
3216 pAd->ate.AvgRssi0X8 = (pAd->ate.AvgRssi0X8 - pAd->ate.AvgRssi0) + pAd->ate.LastRssi0;
3217 pAd->ate.AvgRssi0 = pAd->ate.AvgRssi0X8 >> 3;
3218 pAd->ate.AvgRssi1X8 = (pAd->ate.AvgRssi1X8 - pAd->ate.AvgRssi1) + pAd->ate.LastRssi1;
3219 pAd->ate.AvgRssi1 = pAd->ate.AvgRssi1X8 >> 3;
3220 pAd->ate.AvgRssi2X8 = (pAd->ate.AvgRssi2X8 - pAd->ate.AvgRssi2) + pAd->ate.LastRssi2;
3221 pAd->ate.AvgRssi2 = pAd->ate.AvgRssi2X8 >> 3;
3222 pAd->ate.NumOfAvgRssiSample ++;
3226 #ifdef CONFIG_STA_SUPPORT
3227 VOID RTMPStationStop(
3228 IN PRTMP_ADAPTER pAd)
3230 // BOOLEAN Cancelled;
3232 ATEDBGPRINT(RT_DEBUG_TRACE, ("==> RTMPStationStop\n"));
3235 RTMPCancelTimer(&pAd->MlmeAux.AssocTimer, &Cancelled);
3236 RTMPCancelTimer(&pAd->MlmeAux.ReassocTimer, &Cancelled);
3237 RTMPCancelTimer(&pAd->MlmeAux.DisassocTimer, &Cancelled);
3238 RTMPCancelTimer(&pAd->MlmeAux.AuthTimer, &Cancelled);
3239 RTMPCancelTimer(&pAd->MlmeAux.BeaconTimer, &Cancelled);
3240 RTMPCancelTimer(&pAd->MlmeAux.ScanTimer, &Cancelled);
3242 // For rx statistics, we need to keep this timer running.
3243 // RTMPCancelTimer(&pAd->Mlme.PeriodicTimer, &Cancelled);
3245 ATEDBGPRINT(RT_DEBUG_TRACE, ("<== RTMPStationStop\n"));
3248 VOID RTMPStationStart(
3249 IN PRTMP_ADAPTER pAd)
3251 ATEDBGPRINT(RT_DEBUG_TRACE, ("==> RTMPStationStart\n"));
3253 pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
3255 // We did not cancel this timer when entering ATE mode.
3257 // RTMPSetTimer(&pAd->Mlme.PeriodicTimer, MLME_TASK_EXEC_INTV);
3259 ATEDBGPRINT(RT_DEBUG_TRACE, ("<== RTMPStationStart\n"));
3261 #endif // CONFIG_STA_SUPPORT //
3264 ==========================================================================
3268 This routine should only be used in ATE mode.
3269 ==========================================================================
3272 static INT ATESetUpFrame(
3273 IN PRTMP_ADAPTER pAd,
3278 #ifdef RT_BIG_ENDIAN
3279 PTXD_STRUC pDestTxD;
3282 PNDIS_PACKET pPacket;
3285 NDIS_PHYSICAL_ADDRESS AllocPa;
3286 HTTRANSMIT_SETTING TxHTPhyMode;
3288 PRTMP_TX_RING pTxRing = &pAd->TxRing[QID_AC_BE];
3289 PTXWI_STRUC pTxWI = (PTXWI_STRUC) pTxRing->Cell[TxIdx].DmaBuf.AllocVa;
3290 PUCHAR pDMAHeaderBufVA = (PUCHAR) pTxRing->Cell[TxIdx].DmaBuf.AllocVa;
3292 #ifdef RALINK_28xx_QA
3293 PHEADER_802_11 pHeader80211;
3294 #endif // RALINK_28xx_QA //
3296 if (pAd->ate.bQATxStart == TRUE)
3298 // always use QID_AC_BE and FIFO_EDCA
3301 TxHTPhyMode.field.BW = pAd->ate.TxWI.BW;
3302 TxHTPhyMode.field.ShortGI = pAd->ate.TxWI.ShortGI;
3303 TxHTPhyMode.field.STBC = 0;
3304 TxHTPhyMode.field.MCS = pAd->ate.TxWI.MCS;
3305 TxHTPhyMode.field.MODE = pAd->ate.TxWI.PHYMODE;
3306 ATEWriteTxWI(pAd, pTxWI, pAd->ate.TxWI.FRAG, pAd->ate.TxWI.CFACK, pAd->ate.TxWI.TS, pAd->ate.TxWI.AMPDU, pAd->ate.TxWI.ACK, pAd->ate.TxWI.NSEQ,
3307 pAd->ate.TxWI.BAWinSize, 0, pAd->ate.TxWI.MPDUtotalByteCount, pAd->ate.TxWI.PacketId, 0, 0, pAd->ate.TxWI.txop/*IFS_HTTXOP*/, pAd->ate.TxWI.CFACK/*FALSE*/, &TxHTPhyMode);
3311 TxHTPhyMode.field.BW = pAd->ate.TxWI.BW;
3312 TxHTPhyMode.field.ShortGI = pAd->ate.TxWI.ShortGI;
3313 TxHTPhyMode.field.STBC = 0;
3314 TxHTPhyMode.field.MCS = pAd->ate.TxWI.MCS;
3315 TxHTPhyMode.field.MODE = pAd->ate.TxWI.PHYMODE;
3316 ATEWriteTxWI(pAd, pTxWI, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
3317 4, 0, pAd->ate.TxLength, 0, 0, 0, IFS_HTTXOP, FALSE, &TxHTPhyMode);
3320 // fill 802.11 header.
3321 #ifdef RALINK_28xx_QA
3322 if (pAd->ate.bQATxStart == TRUE)
3324 NdisMoveMemory(pDMAHeaderBufVA+TXWI_SIZE, pAd->ate.Header, pAd->ate.HLen);
3327 #endif // RALINK_28xx_QA //
3329 NdisMoveMemory(pDMAHeaderBufVA+TXWI_SIZE, TemplateFrame, LENGTH_802_11);
3330 NdisMoveMemory(pDMAHeaderBufVA+TXWI_SIZE+4, pAd->ate.Addr1, ETH_LENGTH_OF_ADDRESS);
3331 NdisMoveMemory(pDMAHeaderBufVA+TXWI_SIZE+10, pAd->ate.Addr2, ETH_LENGTH_OF_ADDRESS);
3332 NdisMoveMemory(pDMAHeaderBufVA+TXWI_SIZE+16, pAd->ate.Addr3, ETH_LENGTH_OF_ADDRESS);
3335 #ifdef RT_BIG_ENDIAN
3336 RTMPFrameEndianChange(pAd, (((PUCHAR)pDMAHeaderBufVA)+TXWI_SIZE), DIR_READ, FALSE);
3337 #endif // RT_BIG_ENDIAN //
3339 /* alloc buffer for payload */
3340 #ifdef RALINK_28xx_QA
3341 if (pAd->ate.bQATxStart == TRUE)
3343 /* Why not use RTMP_AllocateTxPacketBuffer() instead of RTMP_AllocateRxPacketBuffer()? */
3344 pPacket = RTMP_AllocateRxPacketBuffer(pAd, pAd->ate.DLen + 0x100, FALSE, &AllocVa, &AllocPa);
3347 #endif // RALINK_28xx_QA //
3349 /* Why not use RTMP_AllocateTxPacketBuffer() instead of RTMP_AllocateRxPacketBuffer()? */
3350 pPacket = RTMP_AllocateRxPacketBuffer(pAd, pAd->ate.TxLength, FALSE, &AllocVa, &AllocPa);
3353 if (pPacket == NULL)
3355 pAd->ate.TxCount = 0;
3356 ATEDBGPRINT(RT_DEBUG_TRACE, ("%s fail to alloc packet space.\n", __func__));
3359 pTxRing->Cell[TxIdx].pNextNdisPacket = pPacket;
3361 pDest = (PUCHAR) AllocVa;
3363 #ifdef RALINK_28xx_QA
3364 if (pAd->ate.bQATxStart == TRUE)
3366 RTPKT_TO_OSPKT(pPacket)->len = pAd->ate.DLen;
3369 #endif // RALINK_28xx_QA //
3371 RTPKT_TO_OSPKT(pPacket)->len = pAd->ate.TxLength - LENGTH_802_11;
3374 // Prepare frame payload
3375 #ifdef RALINK_28xx_QA
3376 if (pAd->ate.bQATxStart == TRUE)
3379 if ((pAd->ate.PLen != 0))
3383 for (j = 0; j < pAd->ate.DLen; j+=pAd->ate.PLen)
3385 memcpy(RTPKT_TO_OSPKT(pPacket)->data + j, pAd->ate.Pattern, pAd->ate.PLen);
3390 #endif // RALINK_28xx_QA //
3392 for(j = 0; j < RTPKT_TO_OSPKT(pPacket)->len; j++)
3397 // build Tx Descriptor
3399 #ifndef RT_BIG_ENDIAN
3400 pTxD = (PTXD_STRUC) pTxRing->Cell[TxIdx].AllocVa;
3402 pDestTxD = (PTXD_STRUC)pTxRing->Cell[TxIdx].AllocVa;
3405 #endif // !RT_BIG_ENDIAN //
3407 #ifdef RALINK_28xx_QA
3408 if (pAd->ate.bQATxStart == TRUE)
3411 NdisZeroMemory(pTxD, TXD_SIZE);
3412 RTMPWriteTxDescriptor(pAd, pTxD, FALSE, FIFO_EDCA);
3414 pTxD->SDPtr0 = RTMP_GetPhysicalAddressLow(pTxRing->Cell[TxIdx].DmaBuf.AllocPa);
3415 pTxD->SDLen0 = TXWI_SIZE + pAd->ate.HLen;
3417 pTxD->SDPtr1 = AllocPa;
3418 pTxD->SDLen1 = RTPKT_TO_OSPKT(pPacket)->len;
3421 pDest = (PUCHAR)pTxWI;
3423 pHeader80211 = (PHEADER_802_11)pDest;
3425 // modify sequence number....
3426 if (pAd->ate.TxDoneCount == 0)
3428 pAd->ate.seq = pHeader80211->Sequence;
3431 pHeader80211->Sequence = ++pAd->ate.seq;
3434 #endif // RALINK_28xx_QA //
3436 NdisZeroMemory(pTxD, TXD_SIZE);
3437 RTMPWriteTxDescriptor(pAd, pTxD, FALSE, FIFO_EDCA);
3439 pTxD->SDPtr0 = RTMP_GetPhysicalAddressLow (pTxRing->Cell[TxIdx].DmaBuf.AllocPa);
3440 pTxD->SDLen0 = TXWI_SIZE + LENGTH_802_11;
3442 pTxD->SDPtr1 = AllocPa;
3443 pTxD->SDLen1 = RTPKT_TO_OSPKT(pPacket)->len;
3447 #ifdef RT_BIG_ENDIAN
3448 RTMPWIEndianChange((PUCHAR)pTxWI, TYPE_TXWI);
3449 RTMPFrameEndianChange(pAd, (((PUCHAR)pDMAHeaderBufVA)+TXWI_SIZE), DIR_WRITE, FALSE);
3450 RTMPDescriptorEndianChange((PUCHAR)pTxD, TYPE_TXD);
3451 WriteBackToDescriptor((PUCHAR)pDestTxD, (PUCHAR)pTxD, FALSE, TYPE_TXD);
3452 #endif // RT_BIG_ENDIAN //
3457 /*=======================End of RT2860=======================*/
3461 VOID rt_ee_read_all(PRTMP_ADAPTER pAd, USHORT *Data)
3466 for (i = 0 ; i < EEPROM_SIZE/2 ; )
3468 /* "value" is expecially for some compilers... */
3469 RT28xx_EEPROM_READ16(pAd, i*2, value);
3475 VOID rt_ee_write_all(PRTMP_ADAPTER pAd, USHORT *Data)
3480 for (i = 0 ; i < EEPROM_SIZE/2 ; )
3482 /* "value" is expecially for some compilers... */
3484 RT28xx_EEPROM_WRITE16(pAd, i*2, value);
3488 #ifdef RALINK_28xx_QA
3489 VOID ATE_QA_Statistics(
3490 IN PRTMP_ADAPTER pAd,
3491 IN PRXWI_STRUC pRxWI,
3492 IN PRT28XX_RXD_STRUC pRxD,
3493 IN PHEADER_802_11 pHeader)
3495 // update counter first
3496 if (pHeader != NULL)
3498 if (pHeader->FC.Type == BTYPE_DATA)
3503 pAd->ate.OtherData++;
3505 else if (pHeader->FC.Type == BTYPE_MGMT)
3507 if (pHeader->FC.SubType == SUBTYPE_BEACON)
3510 pAd->ate.OtherCount++;
3512 else if (pHeader->FC.Type == BTYPE_CNTL)
3514 pAd->ate.OtherCount++;
3517 pAd->ate.RSSI0 = pRxWI->RSSI0;
3518 pAd->ate.RSSI1 = pRxWI->RSSI1;
3519 pAd->ate.RSSI2 = pRxWI->RSSI2;
3520 pAd->ate.SNR0 = pRxWI->SNR0;
3521 pAd->ate.SNR1 = pRxWI->SNR1;
3524 /* command id with Cmd Type == 0x0008(for 28xx)/0x0005(for iNIC) */
3525 #define RACFG_CMD_RF_WRITE_ALL 0x0000
3526 #define RACFG_CMD_E2PROM_READ16 0x0001
3527 #define RACFG_CMD_E2PROM_WRITE16 0x0002
3528 #define RACFG_CMD_E2PROM_READ_ALL 0x0003
3529 #define RACFG_CMD_E2PROM_WRITE_ALL 0x0004
3530 #define RACFG_CMD_IO_READ 0x0005
3531 #define RACFG_CMD_IO_WRITE 0x0006
3532 #define RACFG_CMD_IO_READ_BULK 0x0007
3533 #define RACFG_CMD_BBP_READ8 0x0008
3534 #define RACFG_CMD_BBP_WRITE8 0x0009
3535 #define RACFG_CMD_BBP_READ_ALL 0x000a
3536 #define RACFG_CMD_GET_COUNTER 0x000b
3537 #define RACFG_CMD_CLEAR_COUNTER 0x000c
3539 #define RACFG_CMD_RSV1 0x000d
3540 #define RACFG_CMD_RSV2 0x000e
3541 #define RACFG_CMD_RSV3 0x000f
3543 #define RACFG_CMD_TX_START 0x0010
3544 #define RACFG_CMD_GET_TX_STATUS 0x0011
3545 #define RACFG_CMD_TX_STOP 0x0012
3546 #define RACFG_CMD_RX_START 0x0013
3547 #define RACFG_CMD_RX_STOP 0x0014
3548 #define RACFG_CMD_GET_NOISE_LEVEL 0x0015
3550 #define RACFG_CMD_ATE_START 0x0080
3551 #define RACFG_CMD_ATE_STOP 0x0081
3553 #define RACFG_CMD_ATE_START_TX_CARRIER 0x0100
3554 #define RACFG_CMD_ATE_START_TX_CONT 0x0101
3555 #define RACFG_CMD_ATE_START_TX_FRAME 0x0102
3556 #define RACFG_CMD_ATE_SET_BW 0x0103
3557 #define RACFG_CMD_ATE_SET_TX_POWER0 0x0104
3558 #define RACFG_CMD_ATE_SET_TX_POWER1 0x0105
3559 #define RACFG_CMD_ATE_SET_FREQ_OFFSET 0x0106
3560 #define RACFG_CMD_ATE_GET_STATISTICS 0x0107
3561 #define RACFG_CMD_ATE_RESET_COUNTER 0x0108
3562 #define RACFG_CMD_ATE_SEL_TX_ANTENNA 0x0109
3563 #define RACFG_CMD_ATE_SEL_RX_ANTENNA 0x010a
3564 #define RACFG_CMD_ATE_SET_PREAMBLE 0x010b
3565 #define RACFG_CMD_ATE_SET_CHANNEL 0x010c
3566 #define RACFG_CMD_ATE_SET_ADDR1 0x010d
3567 #define RACFG_CMD_ATE_SET_ADDR2 0x010e
3568 #define RACFG_CMD_ATE_SET_ADDR3 0x010f
3569 #define RACFG_CMD_ATE_SET_RATE 0x0110
3570 #define RACFG_CMD_ATE_SET_TX_FRAME_LEN 0x0111
3571 #define RACFG_CMD_ATE_SET_TX_FRAME_COUNT 0x0112
3572 #define RACFG_CMD_ATE_START_RX_FRAME 0x0113
3573 #define RACFG_CMD_ATE_E2PROM_READ_BULK 0x0114
3574 #define RACFG_CMD_ATE_E2PROM_WRITE_BULK 0x0115
3575 #define RACFG_CMD_ATE_IO_WRITE_BULK 0x0116
3576 #define RACFG_CMD_ATE_BBP_READ_BULK 0x0117
3577 #define RACFG_CMD_ATE_BBP_WRITE_BULK 0x0118
3578 #define RACFG_CMD_ATE_RF_READ_BULK 0x0119
3579 #define RACFG_CMD_ATE_RF_WRITE_BULK 0x011a
3583 #define A2Hex(_X, _p) \
3588 while (((*p >= 'a') && (*p <= 'f')) || ((*p >= 'A') && (*p <= 'F')) || ((*p >= '0') && (*p <= '9'))) \
3590 if ((*p >= 'a') && (*p <= 'f')) \
3591 _X = _X * 16 + *p - 87; \
3592 else if ((*p >= 'A') && (*p <= 'F')) \
3593 _X = _X * 16 + *p - 55; \
3594 else if ((*p >= '0') && (*p <= '9')) \
3595 _X = _X * 16 + *p - 48; \
3601 static VOID memcpy_exl(PRTMP_ADAPTER pAd, UCHAR *dst, UCHAR *src, ULONG len);
3602 static VOID memcpy_exs(PRTMP_ADAPTER pAd, UCHAR *dst, UCHAR *src, ULONG len);
3603 static VOID RTMP_IO_READ_BULK(PRTMP_ADAPTER pAd, UCHAR *dst, UCHAR *src, UINT32 len);
3606 int ate_copy_to_user(
3611 memmove(payload, msg, len);
3616 #define copy_to_user(x,y,z) ate_copy_to_user((PUCHAR)x, (PUCHAR)y, z)
3619 #define LEN_OF_ARG 16
3622 IN PRTMP_ADAPTER pAdapter,
3623 IN struct iwreq *wrq)
3625 unsigned short Command_Id;
3626 struct ate_racfghdr *pRaCfg;
3627 INT Status = NDIS_STATUS_SUCCESS;
3631 if((pRaCfg = kmalloc(sizeof(struct ate_racfghdr), GFP_KERNEL)) == NULL)
3637 NdisZeroMemory(pRaCfg, sizeof(struct ate_racfghdr));
3639 if (copy_from_user((PUCHAR)pRaCfg, wrq->u.data.pointer, wrq->u.data.length))
3647 Command_Id = ntohs(pRaCfg->command_id);
3649 ATEDBGPRINT(RT_DEBUG_TRACE,("\n%s: Command_Id = 0x%04x !\n", __func__, Command_Id));
3653 // We will get this command when QA starts.
3654 case RACFG_CMD_ATE_START:
3656 ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_ATE_START\n"));
3658 // prepare feedback as soon as we can to avoid QA timeout.
3659 pRaCfg->length = htons(2);
3660 pRaCfg->status = htons(0);
3662 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
3663 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
3664 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
3666 ATEDBGPRINT(RT_DEBUG_TRACE, ("wrq->u.data.length = %d\n", wrq->u.data.length));
3668 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
3670 ATEDBGPRINT(RT_DEBUG_TRACE, ("copy_to_user() fail in case RACFG_CMD_ATE_START\n"));
3675 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_START is done !\n"));
3677 Set_ATE_Proc(pAdapter, "ATESTART");
3681 // We will get this command either QA is closed or ated is killed by user.
3682 case RACFG_CMD_ATE_STOP:
3688 ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_ATE_STOP\n"));
3690 // Distinguish this command came from QA(via ated)
3691 // or ate daemon according to the existence of pid in payload.
3692 // No need to prepare feedback if this cmd came directly from ate daemon.
3693 pRaCfg->length = ntohs(pRaCfg->length);
3695 if (pRaCfg->length == sizeof(pAdapter->ate.AtePid))
3697 // This command came from QA.
3698 // Get the pid of ATE daemon.
3699 memcpy((UCHAR *)&pAdapter->ate.AtePid,
3700 (&pRaCfg->data[0]) - 2/* == &(pRaCfg->status) */,
3701 sizeof(pAdapter->ate.AtePid));
3703 // prepare feedback as soon as we can to avoid QA timeout.
3704 pRaCfg->length = htons(2);
3705 pRaCfg->status = htons(0);
3707 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
3708 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
3709 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
3711 ATEDBGPRINT(RT_DEBUG_TRACE, ("wrq->u.data.length = %d\n", wrq->u.data.length));
3713 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
3715 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_STOP\n"));
3720 // kill ATE daemon when leaving ATE mode.
3721 // We must kill ATE daemon first before setting ATESTOP,
3722 // or Microsoft will report sth. wrong.
3724 ret = KILL_THREAD_PID(pAdapter->ate.AtePid, SIGTERM, 1);
3727 ATEDBGPRINT(RT_DEBUG_ERROR, ("%s: unable to signal thread\n", pAdapter->net_dev->name));
3732 // AP might have in ATE_STOP mode due to cmd from QA.
3733 if (ATE_ON(pAdapter))
3735 // Someone has killed ate daemon while QA GUI is still open.
3736 Set_ATE_Proc(pAdapter, "ATESTOP");
3737 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_AP_START is done !\n"));
3742 case RACFG_CMD_RF_WRITE_ALL:
3744 UINT32 R1, R2, R3, R4;
3747 memcpy(&R1, pRaCfg->data-2, 4);
3748 memcpy(&R2, pRaCfg->data+2, 4);
3749 memcpy(&R3, pRaCfg->data+6, 4);
3750 memcpy(&R4, pRaCfg->data+10, 4);
3751 memcpy(&channel, pRaCfg->data+14, 2);
3753 pAdapter->LatchRfRegs.R1 = ntohl(R1);
3754 pAdapter->LatchRfRegs.R2 = ntohl(R2);
3755 pAdapter->LatchRfRegs.R3 = ntohl(R3);
3756 pAdapter->LatchRfRegs.R4 = ntohl(R4);
3757 pAdapter->LatchRfRegs.Channel = ntohs(channel);
3759 RTMP_RF_IO_WRITE32(pAdapter, pAdapter->LatchRfRegs.R1);
3760 RTMP_RF_IO_WRITE32(pAdapter, pAdapter->LatchRfRegs.R2);
3761 RTMP_RF_IO_WRITE32(pAdapter, pAdapter->LatchRfRegs.R3);
3762 RTMP_RF_IO_WRITE32(pAdapter, pAdapter->LatchRfRegs.R4);
3765 pRaCfg->length = htons(2);
3766 pRaCfg->status = htons(0);
3768 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
3769 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
3770 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
3772 ATEDBGPRINT(RT_DEBUG_TRACE, ("wrq->u.data.length = %d\n", wrq->u.data.length));
3773 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
3775 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_RF_WRITE_ALL\n"));
3780 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_RF_WRITE_ALL is done !\n"));
3785 case RACFG_CMD_E2PROM_READ16:
3787 USHORT offset, value, tmp;
3789 offset = ntohs(pRaCfg->status);
3790 /* "tmp" is expecially for some compilers... */
3791 RT28xx_EEPROM_READ16(pAdapter, offset, tmp);
3793 value = htons(value);
3795 ATEDBGPRINT(RT_DEBUG_TRACE,("EEPROM Read offset = 0x%04x, value = 0x%04x\n", offset, value));
3798 pRaCfg->length = htons(4);
3799 pRaCfg->status = htons(0);
3800 memcpy(pRaCfg->data, &value, 2);
3802 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
3803 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
3804 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
3806 ATEDBGPRINT(RT_DEBUG_TRACE, ("sizeof(struct ate_racfghdr) = %d\n", sizeof(struct ate_racfghdr)));
3807 ATEDBGPRINT(RT_DEBUG_TRACE, ("wrq->u.data.length = %d\n", wrq->u.data.length));
3809 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
3811 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_E2PROM_READ16\n"));
3816 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_E2PROM_READ16 is done !\n"));
3821 case RACFG_CMD_E2PROM_WRITE16:
3823 USHORT offset, value;
3825 offset = ntohs(pRaCfg->status);
3826 memcpy(&value, pRaCfg->data, 2);
3827 value = ntohs(value);
3828 RT28xx_EEPROM_WRITE16(pAdapter, offset, value);
3831 pRaCfg->length = htons(2);
3832 pRaCfg->status = htons(0);
3833 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
3834 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
3835 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
3837 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
3839 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_E2PROM_WRITE16\n"));
3844 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_E2PROM_WRITE16 is done !\n"));
3849 case RACFG_CMD_E2PROM_READ_ALL:
3851 USHORT buffer[EEPROM_SIZE/2];
3853 rt_ee_read_all(pAdapter,(USHORT *)buffer);
3854 memcpy_exs(pAdapter, pRaCfg->data, (UCHAR *)buffer, EEPROM_SIZE);
3857 pRaCfg->length = htons(2+EEPROM_SIZE);
3858 pRaCfg->status = htons(0);
3859 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
3860 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
3861 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
3863 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
3865 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_E2PROM_READ_ALL\n"));
3870 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_E2PROM_READ_ALL is done !\n"));
3875 case RACFG_CMD_E2PROM_WRITE_ALL:
3877 USHORT buffer[EEPROM_SIZE/2];
3879 NdisZeroMemory((UCHAR *)buffer, EEPROM_SIZE);
3880 memcpy_exs(pAdapter, (UCHAR *)buffer, (UCHAR *)&pRaCfg->status, EEPROM_SIZE);
3881 rt_ee_write_all(pAdapter,(USHORT *)buffer);
3884 pRaCfg->length = htons(2);
3885 pRaCfg->status = htons(0);
3886 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
3887 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
3888 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
3890 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
3892 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_E2PROM_WRITE_ALL\n"));
3897 ATEDBGPRINT(RT_DEBUG_ERROR, ("RACFG_CMD_E2PROM_WRITE_ALL is done !\n"));
3903 case RACFG_CMD_IO_READ:
3908 memcpy(&offset, &pRaCfg->status, 4);
3909 offset = ntohl(offset);
3911 // We do not need the base address.
3912 // So just extract the offset out.
3913 offset &= 0x0000FFFF;
3914 RTMP_IO_READ32(pAdapter, offset, &value);
3915 value = htonl(value);
3918 pRaCfg->length = htons(6);
3919 pRaCfg->status = htons(0);
3920 memcpy(pRaCfg->data, &value, 4);
3922 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
3923 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
3924 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
3926 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
3928 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_IO_READ\n"));
3933 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_IO_READ is done !\n"));
3938 case RACFG_CMD_IO_WRITE:
3940 UINT32 offset, value;
3942 memcpy(&offset, pRaCfg->data-2, 4);
3943 memcpy(&value, pRaCfg->data+2, 4);
3945 offset = ntohl(offset);
3947 // We do not need the base address.
3948 // So just extract out the offset.
3949 offset &= 0x0000FFFF;
3950 value = ntohl(value);
3951 ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_IO_WRITE: offset = %x, value = %x\n", offset, value));
3952 RTMP_IO_WRITE32(pAdapter, offset, value);
3955 pRaCfg->length = htons(2);
3956 pRaCfg->status = htons(0);
3957 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
3958 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
3959 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
3961 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
3963 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_IO_WRITE\n"));
3968 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_IO_WRITE is done !\n"));
3973 case RACFG_CMD_IO_READ_BULK:
3978 memcpy(&offset, &pRaCfg->status, 4);
3979 offset = ntohl(offset);
3981 // We do not need the base address.
3982 // So just extract the offset.
3983 offset &= 0x0000FFFF;
3984 memcpy(&len, pRaCfg->data+2, 2);
3989 ATEDBGPRINT(RT_DEBUG_TRACE,("len is too large, make it smaller\n"));
3990 pRaCfg->length = htons(2);
3991 pRaCfg->status = htons(1);
3995 RTMP_IO_READ_BULK(pAdapter, pRaCfg->data, (UCHAR *)offset, len*4);// unit in four bytes
3998 pRaCfg->length = htons(2+len*4);// unit in four bytes
3999 pRaCfg->status = htons(0);
4000 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
4001 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
4002 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
4004 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
4006 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_IO_READ_BULK\n"));
4011 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_IO_READ_BULK is done !\n"));
4016 case RACFG_CMD_BBP_READ8:
4022 offset = ntohs(pRaCfg->status);
4024 if (ATE_ON(pAdapter))
4026 ATE_BBP_IO_READ8_BY_REG_ID(pAdapter, offset, &value);
4030 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, offset, &value);
4033 pRaCfg->length = htons(3);
4034 pRaCfg->status = htons(0);
4035 pRaCfg->data[0] = value;
4037 ATEDBGPRINT(RT_DEBUG_TRACE,("BBP value = %x\n", value));
4039 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
4040 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
4041 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
4043 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
4045 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_BBP_READ8\n"));
4050 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_BBP_READ8 is done !\n"));
4054 case RACFG_CMD_BBP_WRITE8:
4059 offset = ntohs(pRaCfg->status);
4060 memcpy(&value, pRaCfg->data, 1);
4062 if (ATE_ON(pAdapter))
4064 ATE_BBP_IO_WRITE8_BY_REG_ID(pAdapter, offset, value);
4068 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, offset, value);
4071 if ((offset == BBP_R1) || (offset == BBP_R3))
4073 SyncTxRxConfig(pAdapter, offset, value);
4077 pRaCfg->length = htons(2);
4078 pRaCfg->status = htons(0);
4079 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
4080 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
4081 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
4083 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
4085 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_BBP_WRITE8\n"));
4090 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_BBP_WRITE8 is done !\n"));
4095 case RACFG_CMD_BBP_READ_ALL:
4099 for (j = 0; j < 137; j++)
4101 pRaCfg->data[j] = 0;
4103 if (ATE_ON(pAdapter))
4105 ATE_BBP_IO_READ8_BY_REG_ID(pAdapter, j, &pRaCfg->data[j]);
4109 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, j, &pRaCfg->data[j]);
4114 pRaCfg->length = htons(2+137);
4115 pRaCfg->status = htons(0);
4117 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
4118 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
4119 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
4121 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
4123 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_BBP_READ_ALL\n"));
4128 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_BBP_READ_ALL is done !\n"));
4134 case RACFG_CMD_ATE_E2PROM_READ_BULK:
4138 USHORT buffer[EEPROM_SIZE/2];
4140 offset = ntohs(pRaCfg->status);
4141 memcpy(&len, pRaCfg->data, 2);
4144 rt_ee_read_all(pAdapter,(USHORT *)buffer);
4145 if (offset + len <= EEPROM_SIZE)
4146 memcpy_exs(pAdapter, pRaCfg->data, (UCHAR *)buffer+offset, len);
4148 ATEDBGPRINT(RT_DEBUG_ERROR, ("exceed EEPROM size\n"));
4151 pRaCfg->length = htons(2+len);
4152 pRaCfg->status = htons(0);
4153 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
4154 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
4155 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
4157 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
4159 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_E2PROM_READ_BULK\n"));
4164 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_E2PROM_READ_BULK is done !\n"));
4170 case RACFG_CMD_ATE_E2PROM_WRITE_BULK:
4174 USHORT buffer[EEPROM_SIZE/2];
4176 offset = ntohs(pRaCfg->status);
4177 memcpy(&len, pRaCfg->data, 2);
4180 rt_ee_read_all(pAdapter,(USHORT *)buffer);
4181 memcpy_exs(pAdapter, (UCHAR *)buffer + offset, (UCHAR *)pRaCfg->data + 2, len);
4182 rt_ee_write_all(pAdapter,(USHORT *)buffer);
4185 pRaCfg->length = htons(2);
4186 pRaCfg->status = htons(0);
4187 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
4188 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
4189 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
4190 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
4192 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_E2PROM_WRITE_BULK\n"));
4197 ATEDBGPRINT(RT_DEBUG_ERROR, ("RACFG_CMD_ATE_E2PROM_WRITE_BULK is done !\n"));
4203 case RACFG_CMD_ATE_IO_WRITE_BULK:
4205 UINT32 offset, i, value;
4208 memcpy(&offset, &pRaCfg->status, 4);
4209 offset = ntohl(offset);
4210 memcpy(&len, pRaCfg->data+2, 2);
4213 for (i = 0; i < len; i += 4)
4215 memcpy_exl(pAdapter, (UCHAR *)&value, pRaCfg->data+4+i, 4);
4216 printk("Write %x %x\n", offset + i, value);
4217 RTMP_IO_WRITE32(pAdapter, (offset +i) & 0xffff, value);
4221 pRaCfg->length = htons(2);
4222 pRaCfg->status = htons(0);
4223 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
4224 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
4225 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
4226 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
4228 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_IO_WRITE_BULK\n"));
4233 ATEDBGPRINT(RT_DEBUG_ERROR, ("RACFG_CMD_ATE_IO_WRITE_BULK is done !\n"));
4239 case RACFG_CMD_ATE_BBP_READ_BULK:
4245 offset = ntohs(pRaCfg->status);
4246 memcpy(&len, pRaCfg->data, 2);
4250 for (j = offset; j < (offset+len); j++)
4252 pRaCfg->data[j - offset] = 0;
4254 if (pAdapter->ate.Mode == ATE_STOP)
4256 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, j, &pRaCfg->data[j - offset]);
4260 ATE_BBP_IO_READ8_BY_REG_ID(pAdapter, j, &pRaCfg->data[j - offset]);
4265 pRaCfg->length = htons(2+len);
4266 pRaCfg->status = htons(0);
4267 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
4268 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
4269 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
4271 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
4273 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_BBP_READ_BULK\n"));
4278 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_BBP_READ_BULK is done !\n"));
4284 case RACFG_CMD_ATE_BBP_WRITE_BULK:
4291 offset = ntohs(pRaCfg->status);
4292 memcpy(&len, pRaCfg->data, 2);
4295 for (j = offset; j < (offset+len); j++)
4297 value = pRaCfg->data + 2 + (j - offset);
4298 if (pAdapter->ate.Mode == ATE_STOP)
4300 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, j, *value);
4304 ATE_BBP_IO_WRITE8_BY_REG_ID(pAdapter, j, *value);
4309 pRaCfg->length = htons(2);
4310 pRaCfg->status = htons(0);
4311 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
4312 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
4313 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
4315 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
4317 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_BBP_WRITE_BULK\n"));
4322 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_BBP_WRITE_BULK is done !\n"));
4327 #ifdef CONFIG_RALINK_RT3052
4328 case RACFG_CMD_ATE_RF_READ_BULK:
4334 offset = ntohs(pRaCfg->status);
4335 memcpy(&len, pRaCfg->data, 2);
4338 for (j = offset; j < (offset+len); j++)
4340 pRaCfg->data[j - offset] = 0;
4341 RT30xxReadRFRegister(pAdapter, j, &pRaCfg->data[j - offset]);
4345 pRaCfg->length = htons(2+len);
4346 pRaCfg->status = htons(0);
4347 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
4348 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
4349 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
4351 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
4353 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_RF_READ_BULK\n"));
4358 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_RF_READ_BULK is done !\n"));
4364 case RACFG_CMD_ATE_RF_WRITE_BULK:
4371 offset = ntohs(pRaCfg->status);
4372 memcpy(&len, pRaCfg->data, 2);
4375 for (j = offset; j < (offset+len); j++)
4377 value = pRaCfg->data + 2 + (j - offset);
4378 RT30xxWriteRFRegister(pAdapter, j, *value);
4382 pRaCfg->length = htons(2);
4383 pRaCfg->status = htons(0);
4384 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
4385 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
4386 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
4388 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
4390 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_RF_WRITE_BULK\n"));
4395 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_RF_WRITE_BULK is done !\n"));
4403 case RACFG_CMD_GET_NOISE_LEVEL:
4406 INT32 buffer[3][10];/* 3 : RxPath ; 10 : no. of per rssi samples */
4408 channel = (ntohs(pRaCfg->status) & 0x00FF);
4409 CalNoiseLevel(pAdapter, channel, buffer);
4410 memcpy_exl(pAdapter, (UCHAR *)pRaCfg->data, (UCHAR *)&(buffer[0][0]), (sizeof(INT32)*3*10));
4413 pRaCfg->length = htons(2 + (sizeof(INT32)*3*10));
4414 pRaCfg->status = htons(0);
4415 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
4416 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
4417 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
4419 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
4421 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_GET_NOISE_LEVEL\n"));
4426 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_GET_NOISE_LEVEL is done !\n"));
4431 case RACFG_CMD_GET_COUNTER:
4433 memcpy_exl(pAdapter, &pRaCfg->data[0], (UCHAR *)&pAdapter->ate.U2M, 4);
4434 memcpy_exl(pAdapter, &pRaCfg->data[4], (UCHAR *)&pAdapter->ate.OtherData, 4);
4435 memcpy_exl(pAdapter, &pRaCfg->data[8], (UCHAR *)&pAdapter->ate.Beacon, 4);
4436 memcpy_exl(pAdapter, &pRaCfg->data[12], (UCHAR *)&pAdapter->ate.OtherCount, 4);
4437 memcpy_exl(pAdapter, &pRaCfg->data[16], (UCHAR *)&pAdapter->ate.TxAc0, 4);
4438 memcpy_exl(pAdapter, &pRaCfg->data[20], (UCHAR *)&pAdapter->ate.TxAc1, 4);
4439 memcpy_exl(pAdapter, &pRaCfg->data[24], (UCHAR *)&pAdapter->ate.TxAc2, 4);
4440 memcpy_exl(pAdapter, &pRaCfg->data[28], (UCHAR *)&pAdapter->ate.TxAc3, 4);
4441 memcpy_exl(pAdapter, &pRaCfg->data[32], (UCHAR *)&pAdapter->ate.TxHCCA, 4);
4442 memcpy_exl(pAdapter, &pRaCfg->data[36], (UCHAR *)&pAdapter->ate.TxMgmt, 4);
4443 memcpy_exl(pAdapter, &pRaCfg->data[40], (UCHAR *)&pAdapter->ate.RSSI0, 4);
4444 memcpy_exl(pAdapter, &pRaCfg->data[44], (UCHAR *)&pAdapter->ate.RSSI1, 4);
4445 memcpy_exl(pAdapter, &pRaCfg->data[48], (UCHAR *)&pAdapter->ate.RSSI2, 4);
4446 memcpy_exl(pAdapter, &pRaCfg->data[52], (UCHAR *)&pAdapter->ate.SNR0, 4);
4447 memcpy_exl(pAdapter, &pRaCfg->data[56], (UCHAR *)&pAdapter->ate.SNR1, 4);
4449 pRaCfg->length = htons(2+60);
4450 pRaCfg->status = htons(0);
4451 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
4452 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
4453 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
4455 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
4457 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_GET_COUNTER\n"));
4462 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_GET_COUNTER is done !\n"));
4467 case RACFG_CMD_CLEAR_COUNTER:
4469 pAdapter->ate.U2M = 0;
4470 pAdapter->ate.OtherData = 0;
4471 pAdapter->ate.Beacon = 0;
4472 pAdapter->ate.OtherCount = 0;
4473 pAdapter->ate.TxAc0 = 0;
4474 pAdapter->ate.TxAc1 = 0;
4475 pAdapter->ate.TxAc2 = 0;
4476 pAdapter->ate.TxAc3 = 0;
4477 pAdapter->ate.TxHCCA = 0;
4478 pAdapter->ate.TxMgmt = 0;
4479 pAdapter->ate.TxDoneCount = 0;
4481 pRaCfg->length = htons(2);
4482 pRaCfg->status = htons(0);
4484 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
4485 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
4486 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
4488 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
4490 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_CLEAR_COUNTER\n"));
4495 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_CLEAR_COUNTER is done !\n"));
4501 case RACFG_CMD_TX_START:
4505 UCHAR Bbp22Value = 0, Bbp24Value = 0;
4507 if ((pAdapter->ate.TxStatus != 0) && (pAdapter->ate.Mode & ATE_TXFRAME))
4509 ATEDBGPRINT(RT_DEBUG_TRACE,("Ate Tx is already running, to run next Tx, you must stop it first\n"));
4511 goto TX_START_ERROR;
4513 else if ((pAdapter->ate.TxStatus != 0) && !(pAdapter->ate.Mode & ATE_TXFRAME))
4517 while ((i++ < 10) && (pAdapter->ate.TxStatus != 0))
4519 RTMPusecDelay(5000);
4523 pAdapter->ate.TxStatus = 0;
4524 pAdapter->ate.TxDoneCount = 0;
4525 //pAdapter->ate.Repeat = 0;
4526 pAdapter->ate.bQATxStart = FALSE;
4529 // If pRaCfg->length == 0, this "RACFG_CMD_TX_START" is for Carrier test or Carrier Suppression.
4530 if (ntohs(pRaCfg->length) != 0)
4534 NdisMoveMemory(&pAdapter->ate.TxWI, pRaCfg->data + 2, 16);
4535 #ifdef RT_BIG_ENDIAN
4536 RTMPWIEndianChange((PUCHAR)&pAdapter->ate.TxWI, TYPE_TXWI);
4537 #endif // RT_BIG_ENDIAN //
4539 NdisMoveMemory(&pAdapter->ate.TxCount, pRaCfg->data + 18, 4);
4540 pAdapter->ate.TxCount = ntohl(pAdapter->ate.TxCount);
4542 p = (USHORT *)(&pRaCfg->data[22]);
4543 //p = pRaCfg->data + 22;
4544 // always use QID_AC_BE
4545 pAdapter->ate.QID = 0;
4546 p = (USHORT *)(&pRaCfg->data[24]);
4547 //p = pRaCfg->data + 24;
4548 pAdapter->ate.HLen = ntohs(*p);
4550 if (pAdapter->ate.HLen > 32)
4552 ATEDBGPRINT(RT_DEBUG_ERROR,("pAdapter->ate.HLen > 32\n"));
4554 goto TX_START_ERROR;
4557 NdisMoveMemory(&pAdapter->ate.Header, pRaCfg->data + 26, pAdapter->ate.HLen);
4560 pAdapter->ate.PLen = ntohs(pRaCfg->length) - (pAdapter->ate.HLen + 28);
4562 if (pAdapter->ate.PLen > 32)
4564 ATEDBGPRINT(RT_DEBUG_ERROR,("pAdapter->ate.PLen > 32\n"));
4566 goto TX_START_ERROR;
4569 NdisMoveMemory(&pAdapter->ate.Pattern, pRaCfg->data + 26 + pAdapter->ate.HLen, pAdapter->ate.PLen);
4570 pAdapter->ate.DLen = pAdapter->ate.TxWI.MPDUtotalByteCount - pAdapter->ate.HLen;
4573 ATE_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R22, &Bbp22Value);
4579 if (pAdapter->ate.TxCount == 0)
4582 pAdapter->ate.TxCount = 0xFFFFFFFF;
4585 ATEDBGPRINT(RT_DEBUG_TRACE,("START TXFRAME\n"));
4586 pAdapter->ate.bQATxStart = TRUE;
4587 Set_ATE_Proc(pAdapter, "TXFRAME");
4591 case BBP22_TXCONT_OR_CARRSUPP:
4593 ATEDBGPRINT(RT_DEBUG_TRACE,("BBP22_TXCONT_OR_CARRSUPP\n"));
4594 ATE_BBP_IO_READ8_BY_REG_ID(pAdapter, 24, &Bbp24Value);
4600 ATEDBGPRINT(RT_DEBUG_TRACE,("START TXCONT\n"));
4601 pAdapter->ate.bQATxStart = TRUE;
4602 Set_ATE_Proc(pAdapter, "TXCONT");
4606 case BBP24_CARRSUPP:
4608 ATEDBGPRINT(RT_DEBUG_TRACE,("START TXCARRSUPP\n"));
4609 pAdapter->ate.bQATxStart = TRUE;
4610 pAdapter->ate.Mode |= ATE_TXCARRSUPP;
4616 ATEDBGPRINT(RT_DEBUG_ERROR,("Unknown Start TX subtype !"));
4625 ATEDBGPRINT(RT_DEBUG_TRACE,("START TXCARR\n"));
4626 pAdapter->ate.bQATxStart = TRUE;
4627 Set_ATE_Proc(pAdapter, "TXCARR");
4633 ATEDBGPRINT(RT_DEBUG_ERROR,("Unknown Start TX subtype !"));
4638 if (pAdapter->ate.bQATxStart == TRUE)
4641 pRaCfg->length = htons(2);
4642 pRaCfg->status = htons(0);
4644 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
4645 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
4646 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
4648 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
4650 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() was failed in case RACFG_CMD_TX_START\n"));
4655 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_TX_START is done !\n"));
4662 pRaCfg->length = htons(2);
4663 pRaCfg->status = htons(err);
4665 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
4666 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
4667 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
4668 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
4670 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_TX_START\n"));
4675 ATEDBGPRINT(RT_DEBUG_TRACE, ("feedback of TX_START_ERROR is done !\n"));
4680 case RACFG_CMD_GET_TX_STATUS:
4685 pRaCfg->length = htons(6);
4686 pRaCfg->status = htons(0);
4687 count = htonl(pAdapter->ate.TxDoneCount);
4688 NdisMoveMemory(pRaCfg->data, &count, 4);
4689 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
4690 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
4691 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
4693 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
4695 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_GET_TX_STATUS\n"));
4700 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_GET_TX_STATUS is done !\n"));
4705 case RACFG_CMD_TX_STOP:
4707 ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_TX_STOP\n"));
4709 Set_ATE_Proc(pAdapter, "TXSTOP");
4712 pRaCfg->length = htons(2);
4713 pRaCfg->status = htons(0);
4714 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
4715 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
4716 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
4718 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
4720 ATEDBGPRINT(RT_DEBUG_TRACE, ("copy_to_user() fail in case RACFG_CMD_TX_STOP\n"));
4725 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_TX_STOP is done !\n"));
4730 case RACFG_CMD_RX_START:
4732 ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_RX_START\n"));
4734 pAdapter->ate.bQARxStart = TRUE;
4735 Set_ATE_Proc(pAdapter, "RXFRAME");
4738 pRaCfg->length = htons(2);
4739 pRaCfg->status = htons(0);
4740 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
4741 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
4742 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
4744 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
4746 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_RX_START\n"));
4751 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_RX_START is done !\n"));
4756 case RACFG_CMD_RX_STOP:
4758 ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_RX_STOP\n"));
4760 Set_ATE_Proc(pAdapter, "RXSTOP");
4763 pRaCfg->length = htons(2);
4764 pRaCfg->status = htons(0);
4765 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
4766 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
4767 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
4769 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
4771 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_RX_STOP\n"));
4776 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_RX_STOP is done !\n"));
4781 /* The following cases are for new ATE GUI(not QA). */
4782 /*==================================================*/
4783 case RACFG_CMD_ATE_START_TX_CARRIER:
4785 ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_ATE_START_TX_CARRIER\n"));
4787 Set_ATE_Proc(pAdapter, "TXCARR");
4789 pRaCfg->length = htons(2);
4790 pRaCfg->status = htons(0);
4792 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
4793 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
4794 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
4796 ATEDBGPRINT(RT_DEBUG_TRACE, ("wrq->u.data.length = %d\n", wrq->u.data.length));
4798 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
4800 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_START_TX_CARRIER\n"));
4805 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_START_TX_CARRIER is done !\n"));
4810 case RACFG_CMD_ATE_START_TX_CONT:
4812 ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_ATE_START_TX_CONT\n"));
4814 Set_ATE_Proc(pAdapter, "TXCONT");
4816 pRaCfg->length = htons(2);
4817 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);
4823 ATEDBGPRINT(RT_DEBUG_TRACE, ("wrq->u.data.length = %d\n", wrq->u.data.length));
4825 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
4827 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_START_TX_CONT\n"));
4832 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_START_TX_CONT is done !\n"));
4837 case RACFG_CMD_ATE_START_TX_FRAME:
4839 ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_ATE_START_TX_FRAME\n"));
4841 Set_ATE_Proc(pAdapter, "TXFRAME");
4843 pRaCfg->length = htons(2);
4844 pRaCfg->status = htons(0);
4846 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
4847 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
4848 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
4850 ATEDBGPRINT(RT_DEBUG_TRACE, ("wrq->u.data.length = %d\n", wrq->u.data.length));
4852 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
4854 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_START_TX_FRAME\n"));
4859 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_START_TX_FRAME is done !\n"));
4864 case RACFG_CMD_ATE_SET_BW:
4867 UCHAR str[LEN_OF_ARG];
4869 NdisZeroMemory(str, LEN_OF_ARG);
4871 ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_ATE_SET_BW\n"));
4873 memcpy((PUCHAR)&value, (PUCHAR)&(pRaCfg->status), 2);
4874 value = ntohs(value);
4875 sprintf((PCHAR)str, "%d", value);
4877 Set_ATE_TX_BW_Proc(pAdapter, str);
4880 pRaCfg->length = htons(2);
4881 pRaCfg->status = htons(0);
4882 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
4883 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
4884 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
4886 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
4888 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_SET_BW\n"));
4893 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_SET_BW is done !\n"));
4898 case RACFG_CMD_ATE_SET_TX_POWER0:
4901 UCHAR str[LEN_OF_ARG];
4903 NdisZeroMemory(str, LEN_OF_ARG);
4905 ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_ATE_SET_TX_POWER0\n"));
4907 memcpy((PUCHAR)&value, (PUCHAR)&(pRaCfg->status), 2);
4908 value = ntohs(value);
4909 sprintf((PCHAR)str, "%d", value);
4910 Set_ATE_TX_POWER0_Proc(pAdapter, str);
4913 pRaCfg->length = htons(2);
4914 pRaCfg->status = htons(0);
4915 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
4916 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
4917 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
4919 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
4921 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_SET_TX_POWER0\n"));
4926 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_SET_TX_POWER0 is done !\n"));
4931 case RACFG_CMD_ATE_SET_TX_POWER1:
4934 UCHAR str[LEN_OF_ARG];
4936 NdisZeroMemory(str, LEN_OF_ARG);
4938 ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_ATE_SET_TX_POWER1\n"));
4940 memcpy((PUCHAR)&value, (PUCHAR)&(pRaCfg->status), 2);
4941 value = ntohs(value);
4942 sprintf((PCHAR)str, "%d", value);
4943 Set_ATE_TX_POWER1_Proc(pAdapter, str);
4946 pRaCfg->length = htons(2);
4947 pRaCfg->status = htons(0);
4948 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
4949 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
4950 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
4952 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
4954 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_SET_TX_POWER1\n"));
4959 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_SET_TX_POWER1 is done !\n"));
4964 case RACFG_CMD_ATE_SET_FREQ_OFFSET:
4967 UCHAR str[LEN_OF_ARG];
4969 NdisZeroMemory(str, LEN_OF_ARG);
4971 ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_ATE_SET_FREQ_OFFSET\n"));
4973 memcpy((PUCHAR)&value, (PUCHAR)&(pRaCfg->status), 2);
4974 value = ntohs(value);
4975 sprintf((PCHAR)str, "%d", value);
4976 Set_ATE_TX_FREQOFFSET_Proc(pAdapter, str);
4979 pRaCfg->length = htons(2);
4980 pRaCfg->status = htons(0);
4981 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
4982 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
4983 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
4985 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
4987 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_SET_FREQ_OFFSET\n"));
4992 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_SET_FREQ_OFFSET is done !\n"));
4997 case RACFG_CMD_ATE_GET_STATISTICS:
4999 ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_ATE_GET_STATISTICS\n"));
5001 memcpy_exl(pAdapter, &pRaCfg->data[0], (UCHAR *)&pAdapter->ate.TxDoneCount, 4);
5002 memcpy_exl(pAdapter, &pRaCfg->data[4], (UCHAR *)&pAdapter->WlanCounters.RetryCount.u.LowPart, 4);
5003 memcpy_exl(pAdapter, &pRaCfg->data[8], (UCHAR *)&pAdapter->WlanCounters.FailedCount.u.LowPart, 4);
5004 memcpy_exl(pAdapter, &pRaCfg->data[12], (UCHAR *)&pAdapter->WlanCounters.RTSSuccessCount.u.LowPart, 4);
5005 memcpy_exl(pAdapter, &pRaCfg->data[16], (UCHAR *)&pAdapter->WlanCounters.RTSFailureCount.u.LowPart, 4);
5006 memcpy_exl(pAdapter, &pRaCfg->data[20], (UCHAR *)&pAdapter->WlanCounters.ReceivedFragmentCount.QuadPart, 4);
5007 memcpy_exl(pAdapter, &pRaCfg->data[24], (UCHAR *)&pAdapter->WlanCounters.FCSErrorCount.u.LowPart, 4);
5008 memcpy_exl(pAdapter, &pRaCfg->data[28], (UCHAR *)&pAdapter->Counters8023.RxNoBuffer, 4);
5009 memcpy_exl(pAdapter, &pRaCfg->data[32], (UCHAR *)&pAdapter->WlanCounters.FrameDuplicateCount.u.LowPart, 4);
5010 memcpy_exl(pAdapter, &pRaCfg->data[36], (UCHAR *)&pAdapter->RalinkCounters.OneSecFalseCCACnt, 4);
5012 if (pAdapter->ate.RxAntennaSel == 0)
5018 RSSI0 = (INT32)(pAdapter->ate.LastRssi0 - pAdapter->BbpRssiToDbmDelta);
5019 RSSI1 = (INT32)(pAdapter->ate.LastRssi1 - pAdapter->BbpRssiToDbmDelta);
5020 RSSI2 = (INT32)(pAdapter->ate.LastRssi2 - pAdapter->BbpRssiToDbmDelta);
5021 memcpy_exl(pAdapter, &pRaCfg->data[40], (UCHAR *)&RSSI0, 4);
5022 memcpy_exl(pAdapter, &pRaCfg->data[44], (UCHAR *)&RSSI1, 4);
5023 memcpy_exl(pAdapter, &pRaCfg->data[48], (UCHAR *)&RSSI2, 4);
5024 pRaCfg->length = htons(2+52);
5030 RSSI0 = (INT32)(pAdapter->ate.LastRssi0 - pAdapter->BbpRssiToDbmDelta);
5031 memcpy_exl(pAdapter, &pRaCfg->data[40], (UCHAR *)&RSSI0, 4);
5032 pRaCfg->length = htons(2+44);
5034 pRaCfg->status = htons(0);
5035 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
5036 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
5037 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
5039 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
5041 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_GET_STATISTICS\n"));
5046 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_GET_STATISTICS is done !\n"));
5051 case RACFG_CMD_ATE_RESET_COUNTER:
5054 UCHAR str[LEN_OF_ARG];
5056 NdisZeroMemory(str, LEN_OF_ARG);
5058 ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_ATE_RESET_COUNTER\n"));
5060 sprintf((PCHAR)str, "%d", value);
5061 Set_ResetStatCounter_Proc(pAdapter, str);
5063 pAdapter->ate.TxDoneCount = 0;
5065 pRaCfg->length = htons(2);
5066 pRaCfg->status = htons(0);
5068 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
5069 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
5070 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
5072 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
5074 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_RESET_COUNTER\n"));
5079 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_RESET_COUNTER is done !\n"));
5085 case RACFG_CMD_ATE_SEL_TX_ANTENNA:
5088 UCHAR str[LEN_OF_ARG];
5090 NdisZeroMemory(str, LEN_OF_ARG);
5092 ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_ATE_SEL_TX_ANTENNA\n"));
5094 memcpy((PUCHAR)&value, (PUCHAR)&(pRaCfg->status), 2);
5095 value = ntohs(value);
5096 sprintf((PCHAR)str, "%d", value);
5097 Set_ATE_TX_Antenna_Proc(pAdapter, str);
5100 pRaCfg->length = htons(2);
5101 pRaCfg->status = htons(0);
5102 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
5103 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
5104 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
5106 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
5108 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_SEL_TX_ANTENNA\n"));
5113 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_SEL_TX_ANTENNA is done !\n"));
5118 case RACFG_CMD_ATE_SEL_RX_ANTENNA:
5121 UCHAR str[LEN_OF_ARG];
5123 NdisZeroMemory(str, LEN_OF_ARG);
5125 ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_ATE_SEL_RX_ANTENNA\n"));
5127 memcpy((PUCHAR)&value, (PUCHAR)&(pRaCfg->status), 2);
5128 value = ntohs(value);
5129 sprintf((PCHAR)str, "%d", value);
5130 Set_ATE_RX_Antenna_Proc(pAdapter, str);
5133 pRaCfg->length = htons(2);
5134 pRaCfg->status = htons(0);
5135 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
5136 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
5137 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
5139 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
5141 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_SEL_RX_ANTENNA\n"));
5146 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_SEL_RX_ANTENNA is done !\n"));
5151 case RACFG_CMD_ATE_SET_PREAMBLE:
5154 UCHAR str[LEN_OF_ARG];
5156 NdisZeroMemory(str, LEN_OF_ARG);
5158 ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_ATE_SET_PREAMBLE\n"));
5160 memcpy((PUCHAR)&value, (PUCHAR)&(pRaCfg->status), 2);
5161 value = ntohs(value);
5162 sprintf((PCHAR)str, "%d", value);
5163 Set_ATE_TX_MODE_Proc(pAdapter, str);
5166 pRaCfg->length = htons(2);
5167 pRaCfg->status = htons(0);
5168 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
5169 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
5170 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
5172 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
5174 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_SET_PREAMBLE\n"));
5179 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_SET_PREAMBLE is done !\n"));
5184 case RACFG_CMD_ATE_SET_CHANNEL:
5187 UCHAR str[LEN_OF_ARG];
5189 NdisZeroMemory(str, LEN_OF_ARG);
5191 ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_ATE_SET_CHANNEL\n"));
5193 memcpy((PUCHAR)&value, (PUCHAR)&(pRaCfg->status), 2);
5194 value = ntohs(value);
5195 sprintf((PCHAR)str, "%d", value);
5196 Set_ATE_CHANNEL_Proc(pAdapter, str);
5199 pRaCfg->length = htons(2);
5200 pRaCfg->status = htons(0);
5201 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
5202 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
5203 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
5205 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
5207 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_SET_CHANNEL\n"));
5212 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_SET_CHANNEL is done !\n"));
5217 case RACFG_CMD_ATE_SET_ADDR1:
5219 ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_ATE_SET_ADDR1\n"));
5221 // Addr is an array of UCHAR,
5222 // so no need to perform endian swap.
5223 memcpy(pAdapter->ate.Addr1, (PUCHAR)(pRaCfg->data - 2), MAC_ADDR_LEN);
5226 pRaCfg->length = htons(2);
5227 pRaCfg->status = htons(0);
5228 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
5229 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
5230 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
5232 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
5234 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_SET_ADDR1\n"));
5239 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_SET_ADDR1 is done !\n (ADDR1 = %2X:%2X:%2X:%2X:%2X:%2X)\n", pAdapter->ate.Addr1[0],
5240 pAdapter->ate.Addr1[1], pAdapter->ate.Addr1[2], pAdapter->ate.Addr1[3], pAdapter->ate.Addr1[4], pAdapter->ate.Addr1[5]));
5245 case RACFG_CMD_ATE_SET_ADDR2:
5247 ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_ATE_SET_ADDR2\n"));
5249 // Addr is an array of UCHAR,
5250 // so no need to perform endian swap.
5251 memcpy(pAdapter->ate.Addr2, (PUCHAR)(pRaCfg->data - 2), MAC_ADDR_LEN);
5254 pRaCfg->length = htons(2);
5255 pRaCfg->status = htons(0);
5256 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
5257 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
5258 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
5260 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
5262 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_SET_ADDR2\n"));
5267 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_SET_ADDR2 is done !\n (ADDR2 = %2X:%2X:%2X:%2X:%2X:%2X)\n", pAdapter->ate.Addr2[0],
5268 pAdapter->ate.Addr2[1], pAdapter->ate.Addr2[2], pAdapter->ate.Addr2[3], pAdapter->ate.Addr2[4], pAdapter->ate.Addr2[5]));
5273 case RACFG_CMD_ATE_SET_ADDR3:
5275 ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_ATE_SET_ADDR3\n"));
5277 // Addr is an array of UCHAR,
5278 // so no need to perform endian swap.
5279 memcpy(pAdapter->ate.Addr3, (PUCHAR)(pRaCfg->data - 2), MAC_ADDR_LEN);
5282 pRaCfg->length = htons(2);
5283 pRaCfg->status = htons(0);
5284 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
5285 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
5286 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
5288 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
5290 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_SET_ADDR3\n"));
5295 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_SET_ADDR3 is done !\n (ADDR3 = %2X:%2X:%2X:%2X:%2X:%2X)\n", pAdapter->ate.Addr3[0],
5296 pAdapter->ate.Addr3[1], pAdapter->ate.Addr3[2], pAdapter->ate.Addr3[3], pAdapter->ate.Addr3[4], pAdapter->ate.Addr3[5]));
5301 case RACFG_CMD_ATE_SET_RATE:
5304 UCHAR str[LEN_OF_ARG];
5306 NdisZeroMemory(str, LEN_OF_ARG);
5308 ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_ATE_SET_RATE\n"));
5310 memcpy((PUCHAR)&value, (PUCHAR)&(pRaCfg->status), 2);
5311 value = ntohs(value);
5312 sprintf((PCHAR)str, "%d", value);
5313 Set_ATE_TX_MCS_Proc(pAdapter, str);
5316 pRaCfg->length = htons(2);
5317 pRaCfg->status = htons(0);
5318 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
5319 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
5320 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
5322 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
5324 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_SET_RATE\n"));
5329 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_SET_RATE is done !\n"));
5334 case RACFG_CMD_ATE_SET_TX_FRAME_LEN:
5337 UCHAR str[LEN_OF_ARG];
5339 NdisZeroMemory(str, LEN_OF_ARG);
5341 ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_ATE_SET_TX_FRAME_LEN\n"));
5343 memcpy((PUCHAR)&value, (PUCHAR)&(pRaCfg->status), 2);
5344 value = ntohs(value);
5345 sprintf((PCHAR)str, "%d", value);
5346 Set_ATE_TX_LENGTH_Proc(pAdapter, str);
5349 pRaCfg->length = htons(2);
5350 pRaCfg->status = htons(0);
5351 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
5352 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
5353 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
5355 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
5357 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_SET_TX_FRAME_LEN\n"));
5362 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_SET_TX_FRAME_LEN is done !\n"));
5367 case RACFG_CMD_ATE_SET_TX_FRAME_COUNT:
5370 UCHAR str[LEN_OF_ARG];
5372 NdisZeroMemory(str, LEN_OF_ARG);
5374 ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_ATE_SET_TX_FRAME_COUNT\n"));
5376 memcpy((PUCHAR)&value, (PUCHAR)&(pRaCfg->status), 2);
5377 value = ntohs(value);
5379 /* TX_FRAME_COUNT == 0 means tx infinitely */
5382 /* Use TxCount = 0xFFFFFFFF to approximate the infinity. */
5383 pAdapter->ate.TxCount = 0xFFFFFFFF;
5384 ATEDBGPRINT(RT_DEBUG_TRACE, ("Set_ATE_TX_COUNT_Proc (TxCount = %d)\n", pAdapter->ate.TxCount));
5385 ATEDBGPRINT(RT_DEBUG_TRACE, ("Ralink: Set_ATE_TX_COUNT_Proc Success\n"));
5392 sprintf((PCHAR)str, "%d", value);
5393 Set_ATE_TX_COUNT_Proc(pAdapter, str);
5397 pRaCfg->length = htons(2);
5398 pRaCfg->status = htons(0);
5399 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
5400 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
5401 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
5403 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
5405 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_ATE_SET_TX_FRAME_COUNT\n"));
5410 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_ATE_SET_TX_FRAME_COUNT is done !\n"));
5415 case RACFG_CMD_ATE_START_RX_FRAME:
5417 ATEDBGPRINT(RT_DEBUG_TRACE,("RACFG_CMD_RX_START\n"));
5419 Set_ATE_Proc(pAdapter, "RXFRAME");
5422 pRaCfg->length = htons(2);
5423 pRaCfg->status = htons(0);
5424 wrq->u.data.length = sizeof(pRaCfg->magic_no) + sizeof(pRaCfg->command_type)
5425 + sizeof(pRaCfg->command_id) + sizeof(pRaCfg->length)
5426 + sizeof(pRaCfg->sequence) + ntohs(pRaCfg->length);
5428 if (copy_to_user(wrq->u.data.pointer, pRaCfg, wrq->u.data.length))
5430 ATEDBGPRINT(RT_DEBUG_ERROR, ("copy_to_user() fail in case RACFG_CMD_RX_START\n"));
5435 ATEDBGPRINT(RT_DEBUG_TRACE, ("RACFG_CMD_RX_START is done !\n"));
5442 ASSERT(pRaCfg != NULL);
5450 VOID BubbleSort(INT32 n, INT32 a[])
5454 for (k = n-1; k>0; k--)
5456 for (j = 0; j<k; j++)
5468 VOID CalNoiseLevel(PRTMP_ADAPTER pAd, UCHAR channel, INT32 RSSI[3][10])
5470 INT32 RSSI0, RSSI1, RSSI2;
5471 CHAR Rssi0Offset, Rssi1Offset, Rssi2Offset;
5472 UCHAR BbpR50Rssi0 = 0, BbpR51Rssi1 = 0, BbpR52Rssi2 = 0;
5473 UCHAR Org_BBP66value = 0, Org_BBP69value = 0, Org_BBP70value = 0, data = 0;
5474 USHORT LNA_Gain = 0;
5476 UCHAR Org_Channel = pAd->ate.Channel;
5477 USHORT GainValue = 0, OffsetValue = 0;
5479 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R66, &Org_BBP66value);
5480 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R69, &Org_BBP69value);
5481 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R70, &Org_BBP70value);
5483 //**********************************************************************
5484 // Read the value of LNA gain and Rssi offset
5485 //**********************************************************************
5486 RT28xx_EEPROM_READ16(pAd, EEPROM_LNA_OFFSET, GainValue);
5491 LNA_Gain = GainValue & 0x00FF;
5493 RT28xx_EEPROM_READ16(pAd, EEPROM_RSSI_BG_OFFSET, OffsetValue);
5494 Rssi0Offset = OffsetValue & 0x00FF;
5495 Rssi1Offset = (OffsetValue & 0xFF00) >> 8;
5496 RT28xx_EEPROM_READ16(pAd, (EEPROM_RSSI_BG_OFFSET + 2)/* 0x48 */, OffsetValue);
5497 Rssi2Offset = OffsetValue & 0x00FF;
5501 LNA_Gain = (GainValue & 0xFF00) >> 8;
5503 RT28xx_EEPROM_READ16(pAd, EEPROM_RSSI_A_OFFSET, OffsetValue);
5504 Rssi0Offset = OffsetValue & 0x00FF;
5505 Rssi1Offset = (OffsetValue & 0xFF00) >> 8;
5506 RT28xx_EEPROM_READ16(pAd, (EEPROM_RSSI_A_OFFSET + 2)/* 0x4C */, OffsetValue);
5507 Rssi2Offset = OffsetValue & 0x00FF;
5509 //**********************************************************************
5511 pAd->ate.Channel = channel;
5512 ATEAsicSwitchChannel(pAd);
5516 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R66, data);
5518 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R69, data);
5520 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R70, data);
5524 pAd->ate.bQARxStart = TRUE;
5525 Set_ATE_Proc(pAd, "RXFRAME");
5529 for (j = 0; j < 10; j++)
5531 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R50, &BbpR50Rssi0);
5532 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R51, &BbpR51Rssi1);
5533 ATE_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R52, &BbpR52Rssi2);
5538 if (BbpR50Rssi0 == 0)
5544 RSSI0 = (INT32)(-12 - BbpR50Rssi0 - LNA_Gain - Rssi0Offset);
5548 if ( pAd->Antenna.field.RxPath >= 2 ) // 2R
5551 if (BbpR51Rssi1 == 0)
5557 RSSI1 = (INT32)(-12 - BbpR51Rssi1 - LNA_Gain - Rssi1Offset);
5562 if ( pAd->Antenna.field.RxPath >= 3 ) // 3R
5565 if (BbpR52Rssi2 == 0)
5568 RSSI2 = (INT32)(-12 - BbpR52Rssi2 - LNA_Gain - Rssi2Offset);
5575 Set_ATE_Proc(pAd, "RXSTOP");
5579 #if 0// Debug Message................
5580 ate_print("\n**********************************************************\n");
5581 ate_print("Noise Level: Channel %d\n", channel);
5582 ate_print("RSSI0 = %d, %d, %d, %d, %d, %d, %d, %d, %d, %d\n",
5583 RSSI[0][0], RSSI[0][1], RSSI[0][2],
5584 RSSI[0][3], RSSI[0][4], RSSI[0][5],
5585 RSSI[0][6], RSSI[0][7], RSSI[0][8],
5587 if ( pAd->Antenna.field.RxPath >= 2 ) // 2R
5589 ate_print("RSSI1 = %d, %d, %d, %d, %d, %d, %d, %d, %d, %d\n",
5590 RSSI[1][0], RSSI[1][1], RSSI[1][2],
5591 RSSI[1][3], RSSI[1][4], RSSI[1][5],
5592 RSSI[1][6], RSSI[1][7], RSSI[1][8],
5595 if ( pAd->Antenna.field.RxPath >= 3 ) // 3R
5597 ate_print("RSSI2 = %d, %d, %d, %d, %d, %d, %d, %d, %d, %d\n",
5598 RSSI[2][0], RSSI[2][1], RSSI[2][2],
5599 RSSI[2][3], RSSI[2][4], RSSI[2][5],
5600 RSSI[2][6], RSSI[2][7], RSSI[2][8],
5604 BubbleSort(10, RSSI[0]); // 1R
5606 if ( pAd->Antenna.field.RxPath >= 2 ) // 2R
5608 BubbleSort(10, RSSI[1]);
5611 if ( pAd->Antenna.field.RxPath >= 3 ) // 3R
5613 BubbleSort(10, RSSI[2]);
5616 #if 0// Debug Message................
5617 ate_print("\nAfter Sorting....Channel %d\n", channel);
5618 ate_print("RSSI0 = %d, %d, %d, %d, %d, %d, %d, %d, %d, %d\n",
5619 RSSI[0][0], RSSI[0][1], RSSI[0][2],
5620 RSSI[0][3], RSSI[0][4], RSSI[0][5],
5621 RSSI[0][6], RSSI[0][7], RSSI[0][8],
5623 if ( pAd->Antenna.field.RxPath >= 2 ) // 2R
5625 ate_print("RSSI1 = %d, %d, %d, %d, %d, %d, %d, %d, %d, %d\n",
5626 RSSI[1][0], RSSI[1][1], RSSI[1][2],
5627 RSSI[1][3], RSSI[1][4], RSSI[1][5],
5628 RSSI[1][6], RSSI[1][7], RSSI[1][8],
5631 if ( pAd->Antenna.field.RxPath >= 3 ) // 3R
5633 ate_print("RSSI2 = %d, %d, %d, %d, %d, %d, %d, %d, %d, %d\n",
5634 RSSI[2][0], RSSI[2][1], RSSI[2][2],
5635 RSSI[2][3], RSSI[2][4], RSSI[2][5],
5636 RSSI[2][6], RSSI[2][7], RSSI[2][8],
5639 ate_print("**********************************************************\n");
5643 pAd->ate.Channel = Org_Channel;
5644 ATEAsicSwitchChannel(pAd);
5646 // Restore original value
5647 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R66, Org_BBP66value);
5648 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R69, Org_BBP69value);
5649 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R70, Org_BBP70value);
5654 BOOLEAN SyncTxRxConfig(PRTMP_ADAPTER pAd, USHORT offset, UCHAR value)
5656 UCHAR tmp = 0, bbp_data = 0;
5660 ATE_BBP_IO_READ8_BY_REG_ID(pAd, offset, &bbp_data);
5664 RTMP_BBP_IO_READ8_BY_REG_ID(pAd, offset, &bbp_data);
5668 ASSERT(bbp_data == value);
5673 /* Need to sync. tx configuration with legacy ATE. */
5674 tmp = (bbp_data & ((1 << 4) | (1 << 3))/* 0x18 */) >> 3;
5677 /* The BBP R1 bit[4:3] = 2 :: Both DACs will be used by QA. */
5680 pAd->ate.TxAntennaSel = 0;
5682 /* The BBP R1 bit[4:3] = 0 :: DAC 0 will be used by QA. */
5685 pAd->ate.TxAntennaSel = 1;
5687 /* The BBP R1 bit[4:3] = 1 :: DAC 1 will be used by QA. */
5690 pAd->ate.TxAntennaSel = 2;
5693 DBGPRINT(RT_DEBUG_TRACE, ("%s -- Sth. wrong! : return FALSE; \n", __func__));
5696 break;/* case BBP_R1 */
5699 /* Need to sync. rx configuration with legacy ATE. */
5700 tmp = (bbp_data & ((1 << 1) | (1 << 0))/* 0x03 */);
5703 /* The BBP R3 bit[1:0] = 3 :: All ADCs will be used by QA. */
5706 pAd->ate.RxAntennaSel = 0;
5708 /* The BBP R3 bit[1:0] = 0 :: ADC 0 will be used by QA, */
5709 /* unless the BBP R3 bit[4:3] = 2 */
5712 pAd->ate.RxAntennaSel = 1;
5713 tmp = ((bbp_data & ((1 << 4) | (1 << 3))/* 0x03 */) >> 3);
5716 /* Default : All ADCs will be used by QA */
5717 pAd->ate.RxAntennaSel = 0;
5720 /* The BBP R3 bit[1:0] = 1 :: ADC 1 will be used by QA. */
5723 pAd->ate.RxAntennaSel = 2;
5725 /* The BBP R3 bit[1:0] = 2 :: ADC 2 will be used by QA. */
5728 pAd->ate.RxAntennaSel = 3;
5731 DBGPRINT(RT_DEBUG_ERROR, ("%s -- Impossible! : return FALSE; \n", __func__));
5734 break;/* case BBP_R3 */
5737 DBGPRINT(RT_DEBUG_ERROR, ("%s -- Sth. wrong! : return FALSE; \n", __func__));
5744 static VOID memcpy_exl(PRTMP_ADAPTER pAd, UCHAR *dst, UCHAR *src, ULONG len)
5751 pDst = (ULONG *) dst;
5752 pSrc = (ULONG *) src;
5754 for (i = 0 ; i < (len/4); i++)
5756 /* For alignment issue, we need a variable "Value". */
5757 memmove(&Value, pSrc, 4);
5758 Value = htonl(Value);
5759 memmove(pDst, &Value, 4);
5765 /* wish that it will never reach here */
5766 memmove(&Value, pSrc, (len % 4));
5767 Value = htonl(Value);
5768 memmove(pDst, &Value, (len % 4));
5772 static VOID memcpy_exs(PRTMP_ADAPTER pAd, UCHAR *dst, UCHAR *src, ULONG len)
5780 for (i = 0; i < (len/2); i++)
5782 memmove(pDst, pSrc, 2);
5783 *((USHORT *)pDst) = htons(*((USHORT *)pDst));
5790 memmove(pDst, pSrc, 1);
5794 static VOID RTMP_IO_READ_BULK(PRTMP_ADAPTER pAd, UCHAR *dst, UCHAR *src, UINT32 len)
5797 UINT32 *pDst, *pSrc;
5799 pDst = (UINT32 *) dst;
5800 pSrc = (UINT32 *) src;
5802 for (i = 0 ; i < (len/4); i++)
5804 RTMP_IO_READ32(pAd, (ULONG)pSrc, &Value);
5805 Value = htonl(Value);
5806 memmove(pDst, &Value, 4);
5815 /* These work only when RALINK_ATE is defined */
5816 INT Set_TxStart_Proc(
5817 IN PRTMP_ADAPTER pAd,
5820 ULONG value = simple_strtol(arg, 0, 10);
5821 UCHAR buffer[26] = {0x88, 0x02, 0x2c, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x00, 0x55, 0x44, 0x33, 0x22, 0x11, 0xc0, 0x22, 0x00, 0x00};
5824 if (pAd->ate.TxStatus != 0)
5827 pAd->ate.TxInfo = 0x04000000;
5828 bzero(&pAd->ate.TxWI, sizeof(TXWI_STRUC));
5829 pAd->ate.TxWI.PHYMODE = 0;// MODE_CCK
5830 pAd->ate.TxWI.MPDUtotalByteCount = 1226;
5831 pAd->ate.TxWI.MCS = 3;
5832 //pAd->ate.Mode = ATE_START;
5833 pAd->ate.Mode |= ATE_TXFRAME;
5834 pAd->ate.TxCount = value;
5838 pAd->ate.DLen = 1200;
5839 memcpy(pAd->ate.Header, buffer, 26);
5840 pAd->ate.bQATxStart = TRUE;
5841 //pObj = (POS_COOKIE) pAd->OS_Cookie;
5842 //tasklet_hi_schedule(&pObj->AteTxTask);
5845 #endif /* end of #if 0 */
5847 INT Set_TxStop_Proc(
5848 IN PRTMP_ADAPTER pAd,
5851 ATEDBGPRINT(RT_DEBUG_TRACE,("Set_TxStop_Proc\n"));
5853 if (Set_ATE_Proc(pAd, "TXSTOP"))
5863 INT Set_RxStop_Proc(
5864 IN PRTMP_ADAPTER pAd,
5867 ATEDBGPRINT(RT_DEBUG_TRACE,("Set_RxStop_Proc\n"));
5869 if (Set_ATE_Proc(pAd, "RXSTOP"))
5880 INT Set_EEWrite_Proc(
5881 IN PRTMP_ADAPTER pAd,
5884 USHORT offset = 0, value;
5887 while((*p2 != ':') && (*p2 != '\0'))
5895 A2Hex(value, p2+ 1);
5902 if (offset >= EEPROM_SIZE)
5904 ate_print("Offset can not exceed EEPROM_SIZE( == 0x%04x)\n", EEPROM_SIZE);
5908 RTMP_EEPROM_WRITE16(pAd, offset, value);
5913 INT Set_BBPRead_Proc(
5914 IN PRTMP_ADAPTER pAd,
5917 UCHAR value = 0, offset;
5923 ATE_BBP_IO_READ8_BY_REG_ID(pAd, offset, &value);
5927 RTMP_BBP_IO_READ8_BY_REG_ID(pAd, offset, &value);
5930 ate_print("%x\n", value);
5936 INT Set_BBPWrite_Proc(
5937 IN PRTMP_ADAPTER pAd,
5944 while((*p2 != ':') && (*p2 != '\0'))
5952 A2Hex(value, p2+ 1);
5961 ATE_BBP_IO_WRITE8_BY_REG_ID(pAd, offset, value);
5965 RTNP_BBP_IO_WRITE8_BY_REG_ID(pAd, offset, value);
5971 INT Set_RFWrite_Proc(
5972 IN PRTMP_ADAPTER pAd,
5976 ULONG R1, R2, R3, R4;
5980 while((*p2 != ':') && (*p2 != '\0'))
5990 while((*p3 != ':') && (*p3 != '\0'))
6000 while((*p4 != ':') && (*p4 != '\0'))
6014 RTMP_RF_IO_WRITE32(pAd, R1);
6015 RTMP_RF_IO_WRITE32(pAd, R2);
6016 RTMP_RF_IO_WRITE32(pAd, R3);
6017 RTMP_RF_IO_WRITE32(pAd, R4);
6021 #endif // end of #if 0 //
6022 #endif // RALINK_28xx_QA //
6024 #endif // RALINK_ATE //