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 *************************************************************************
31 Functions used to communicate with ASIC
35 -------- ---------- ----------------------------------------------
38 #include "../rt_config.h"
40 /* Reset the RFIC setting to new series */
41 struct rt_rtmp_rf_regs RF2850RegTable[] = {
42 /* ch R1 R2 R3(TX0~4=0) R4 */
43 {1, 0x98402ecc, 0x984c0786, 0x9816b455, 0x9800510b}
45 {2, 0x98402ecc, 0x984c0786, 0x98168a55, 0x9800519f}
47 {3, 0x98402ecc, 0x984c078a, 0x98168a55, 0x9800518b}
49 {4, 0x98402ecc, 0x984c078a, 0x98168a55, 0x9800519f}
51 {5, 0x98402ecc, 0x984c078e, 0x98168a55, 0x9800518b}
53 {6, 0x98402ecc, 0x984c078e, 0x98168a55, 0x9800519f}
55 {7, 0x98402ecc, 0x984c0792, 0x98168a55, 0x9800518b}
57 {8, 0x98402ecc, 0x984c0792, 0x98168a55, 0x9800519f}
59 {9, 0x98402ecc, 0x984c0796, 0x98168a55, 0x9800518b}
61 {10, 0x98402ecc, 0x984c0796, 0x98168a55, 0x9800519f}
63 {11, 0x98402ecc, 0x984c079a, 0x98168a55, 0x9800518b}
65 {12, 0x98402ecc, 0x984c079a, 0x98168a55, 0x9800519f}
67 {13, 0x98402ecc, 0x984c079e, 0x98168a55, 0x9800518b}
69 {14, 0x98402ecc, 0x984c07a2, 0x98168a55, 0x98005193}
72 /* 802.11 UNI / HyperLan 2 */
73 {36, 0x98402ecc, 0x984c099a, 0x98158a55, 0x980ed1a3}
75 {38, 0x98402ecc, 0x984c099e, 0x98158a55, 0x980ed193}
77 {40, 0x98402ec8, 0x984c0682, 0x98158a55, 0x980ed183}
79 {44, 0x98402ec8, 0x984c0682, 0x98158a55, 0x980ed1a3}
81 {46, 0x98402ec8, 0x984c0686, 0x98158a55, 0x980ed18b}
83 {48, 0x98402ec8, 0x984c0686, 0x98158a55, 0x980ed19b}
85 {52, 0x98402ec8, 0x984c068a, 0x98158a55, 0x980ed193}
87 {54, 0x98402ec8, 0x984c068a, 0x98158a55, 0x980ed1a3}
89 {56, 0x98402ec8, 0x984c068e, 0x98158a55, 0x980ed18b}
91 {60, 0x98402ec8, 0x984c0692, 0x98158a55, 0x980ed183}
93 {62, 0x98402ec8, 0x984c0692, 0x98158a55, 0x980ed193}
95 {64, 0x98402ec8, 0x984c0692, 0x98158a55, 0x980ed1a3}
96 , /* Plugfest#4, Day4, change RFR3 left4th 9->5. */
98 /* 802.11 HyperLan 2 */
99 {100, 0x98402ec8, 0x984c06b2, 0x98178a55, 0x980ed783}
102 /* 2008.04.30 modified */
103 /* The system team has AN to improve the EVM value */
104 /* for channel 102 to 108 for the RT2850/RT2750 dual band solution. */
105 {102, 0x98402ec8, 0x985c06b2, 0x98578a55, 0x980ed793}
107 {104, 0x98402ec8, 0x985c06b2, 0x98578a55, 0x980ed1a3}
109 {108, 0x98402ecc, 0x985c0a32, 0x98578a55, 0x980ed193}
112 {110, 0x98402ecc, 0x984c0a36, 0x98178a55, 0x980ed183}
114 {112, 0x98402ecc, 0x984c0a36, 0x98178a55, 0x980ed19b}
116 {116, 0x98402ecc, 0x984c0a3a, 0x98178a55, 0x980ed1a3}
118 {118, 0x98402ecc, 0x984c0a3e, 0x98178a55, 0x980ed193}
120 {120, 0x98402ec4, 0x984c0382, 0x98178a55, 0x980ed183}
122 {124, 0x98402ec4, 0x984c0382, 0x98178a55, 0x980ed193}
124 {126, 0x98402ec4, 0x984c0382, 0x98178a55, 0x980ed15b}
125 , /* 0x980ed1bb->0x980ed15b required by Rory 20070927 */
126 {128, 0x98402ec4, 0x984c0382, 0x98178a55, 0x980ed1a3}
128 {132, 0x98402ec4, 0x984c0386, 0x98178a55, 0x980ed18b}
130 {134, 0x98402ec4, 0x984c0386, 0x98178a55, 0x980ed193}
132 {136, 0x98402ec4, 0x984c0386, 0x98178a55, 0x980ed19b}
134 {140, 0x98402ec4, 0x984c038a, 0x98178a55, 0x980ed183}
138 {149, 0x98402ec4, 0x984c038a, 0x98178a55, 0x980ed1a7}
140 {151, 0x98402ec4, 0x984c038e, 0x98178a55, 0x980ed187}
142 {153, 0x98402ec4, 0x984c038e, 0x98178a55, 0x980ed18f}
144 {157, 0x98402ec4, 0x984c038e, 0x98178a55, 0x980ed19f}
146 {159, 0x98402ec4, 0x984c038e, 0x98178a55, 0x980ed1a7}
148 {161, 0x98402ec4, 0x984c0392, 0x98178a55, 0x980ed187}
150 {165, 0x98402ec4, 0x984c0392, 0x98178a55, 0x980ed197}
152 {167, 0x98402ec4, 0x984c03d2, 0x98179855, 0x9815531f}
154 {169, 0x98402ec4, 0x984c03d2, 0x98179855, 0x98155327}
156 {171, 0x98402ec4, 0x984c03d6, 0x98179855, 0x98155307}
158 {173, 0x98402ec4, 0x984c03d6, 0x98179855, 0x9815530f}
162 {184, 0x95002ccc, 0x9500491e, 0x9509be55, 0x950c0a0b}
164 {188, 0x95002ccc, 0x95004922, 0x9509be55, 0x950c0a13}
166 {192, 0x95002ccc, 0x95004926, 0x9509be55, 0x950c0a1b}
168 {196, 0x95002ccc, 0x9500492a, 0x9509be55, 0x950c0a23}
170 {208, 0x95002ccc, 0x9500493a, 0x9509be55, 0x950c0a13}
172 {212, 0x95002ccc, 0x9500493e, 0x9509be55, 0x950c0a1b}
174 {216, 0x95002ccc, 0x95004982, 0x9509be55, 0x950c0a23}
177 /* still lack of MMAC(Japan) ch 34,38,42,46 */
180 u8 NUM_OF_2850_CHNL = (sizeof(RF2850RegTable) / sizeof(struct rt_rtmp_rf_regs));
182 struct rt_frequency_item FreqItems3020[] = {
183 /**************************************************/
184 /* ISM : 2.4 to 2.483 GHz // */
185 /**************************************************/
187 /**************************************************/
188 /*-CH---N-------R---K----------- */
219 u8 NUM_OF_3020_CHNL = (sizeof(FreqItems3020) / sizeof(struct rt_frequency_item));
221 void AsicUpdateAutoFallBackTable(struct rt_rtmp_adapter *pAd, u8 *pRateTable)
224 HT_FBK_CFG0_STRUC HtCfg0;
225 HT_FBK_CFG1_STRUC HtCfg1;
226 LG_FBK_CFG0_STRUC LgCfg0;
227 LG_FBK_CFG1_STRUC LgCfg1;
228 struct rt_rtmp_tx_rate_switch *pCurrTxRate, *pNextTxRate;
230 /* set to initial value */
231 HtCfg0.word = 0x65432100;
232 HtCfg1.word = 0xedcba988;
233 LgCfg0.word = 0xedcba988;
234 LgCfg1.word = 0x00002100;
236 pNextTxRate = (struct rt_rtmp_tx_rate_switch *) pRateTable + 1;
237 for (i = 1; i < *((u8 *)pRateTable); i++) {
238 pCurrTxRate = (struct rt_rtmp_tx_rate_switch *) pRateTable + 1 + i;
239 switch (pCurrTxRate->Mode) {
244 switch (pCurrTxRate->CurrMCS) {
246 LgCfg0.field.OFDMMCS0FBK =
247 (pNextTxRate->Mode ==
248 MODE_OFDM) ? (pNextTxRate->
254 LgCfg0.field.OFDMMCS1FBK =
255 (pNextTxRate->Mode ==
256 MODE_OFDM) ? (pNextTxRate->
262 LgCfg0.field.OFDMMCS2FBK =
263 (pNextTxRate->Mode ==
264 MODE_OFDM) ? (pNextTxRate->
270 LgCfg0.field.OFDMMCS3FBK =
271 (pNextTxRate->Mode ==
272 MODE_OFDM) ? (pNextTxRate->
278 LgCfg0.field.OFDMMCS4FBK =
279 (pNextTxRate->Mode ==
280 MODE_OFDM) ? (pNextTxRate->
286 LgCfg0.field.OFDMMCS5FBK =
287 (pNextTxRate->Mode ==
288 MODE_OFDM) ? (pNextTxRate->
294 LgCfg0.field.OFDMMCS6FBK =
295 (pNextTxRate->Mode ==
296 MODE_OFDM) ? (pNextTxRate->
302 LgCfg0.field.OFDMMCS7FBK =
303 (pNextTxRate->Mode ==
304 MODE_OFDM) ? (pNextTxRate->
315 if ((pNextTxRate->Mode >= MODE_HTMIX)
316 && (pCurrTxRate->CurrMCS !=
317 pNextTxRate->CurrMCS)) {
318 switch (pCurrTxRate->CurrMCS) {
320 HtCfg0.field.HTMCS0FBK =
321 pNextTxRate->CurrMCS;
324 HtCfg0.field.HTMCS1FBK =
325 pNextTxRate->CurrMCS;
328 HtCfg0.field.HTMCS2FBK =
329 pNextTxRate->CurrMCS;
332 HtCfg0.field.HTMCS3FBK =
333 pNextTxRate->CurrMCS;
336 HtCfg0.field.HTMCS4FBK =
337 pNextTxRate->CurrMCS;
340 HtCfg0.field.HTMCS5FBK =
341 pNextTxRate->CurrMCS;
344 HtCfg0.field.HTMCS6FBK =
345 pNextTxRate->CurrMCS;
348 HtCfg0.field.HTMCS7FBK =
349 pNextTxRate->CurrMCS;
352 HtCfg1.field.HTMCS8FBK =
353 pNextTxRate->CurrMCS;
356 HtCfg1.field.HTMCS9FBK =
357 pNextTxRate->CurrMCS;
360 HtCfg1.field.HTMCS10FBK =
361 pNextTxRate->CurrMCS;
364 HtCfg1.field.HTMCS11FBK =
365 pNextTxRate->CurrMCS;
368 HtCfg1.field.HTMCS12FBK =
369 pNextTxRate->CurrMCS;
372 HtCfg1.field.HTMCS13FBK =
373 pNextTxRate->CurrMCS;
376 HtCfg1.field.HTMCS14FBK =
377 pNextTxRate->CurrMCS;
380 HtCfg1.field.HTMCS15FBK =
381 pNextTxRate->CurrMCS;
384 DBGPRINT(RT_DEBUG_ERROR,
385 ("AsicUpdateAutoFallBackTable: not support CurrMCS=%d\n",
394 pNextTxRate = pCurrTxRate;
397 RTMP_IO_WRITE32(pAd, HT_FBK_CFG0, HtCfg0.word);
398 RTMP_IO_WRITE32(pAd, HT_FBK_CFG1, HtCfg1.word);
399 RTMP_IO_WRITE32(pAd, LG_FBK_CFG0, LgCfg0.word);
400 RTMP_IO_WRITE32(pAd, LG_FBK_CFG1, LgCfg1.word);
404 ========================================================================
407 Set MAC register value according operation mode.
408 OperationMode AND bNonGFExist are for MM and GF Proteciton.
409 If MM or GF mask is not set, those passing argument doesn't not take effect.
411 Operation mode meaning:
412 = 0 : Pure HT, no preotection.
413 = 0x01; there may be non-HT devices in both the control and extension channel, protection is optional in BSS.
414 = 0x10: No Transmission in 40M is protected.
415 = 0x11: Transmission in both 40M and 20M shall be protected
417 we should choose not to use GF. But still set correct ASIC registers.
418 ========================================================================
420 void AsicUpdateProtect(struct rt_rtmp_adapter *pAd,
423 IN BOOLEAN bDisableBGProtect, IN BOOLEAN bNonGFExist)
425 PROT_CFG_STRUC ProtCfg, ProtCfg4;
431 if (!(pAd->CommonCfg.bHTProtect) && (OperationMode != 8)) {
435 if (pAd->BATable.numDoneOriginator) {
437 /* enable the RTS/CTS to avoid channel collision */
439 SetMask = ALLN_SETPROTECT;
442 /* Config ASIC RTS threshold register */
443 RTMP_IO_READ32(pAd, TX_RTS_CFG, &MacReg);
444 MacReg &= 0xFF0000FF;
445 /* If the user want disable RtsThreshold and enable Amsdu/Ralink-Aggregation, set the RtsThreshold as 4096 */
446 if (((pAd->CommonCfg.BACapability.field.AmsduEnable) ||
447 (pAd->CommonCfg.bAggregationCapable == TRUE))
448 && pAd->CommonCfg.RtsThreshold == MAX_RTS_THRESHOLD) {
449 MacReg |= (0x1000 << 8);
451 MacReg |= (pAd->CommonCfg.RtsThreshold << 8);
454 RTMP_IO_WRITE32(pAd, TX_RTS_CFG, MacReg);
456 /* Initial common protection settings */
457 RTMPZeroMemory(Protect, sizeof(Protect));
460 ProtCfg.field.TxopAllowGF40 = 1;
461 ProtCfg.field.TxopAllowGF20 = 1;
462 ProtCfg.field.TxopAllowMM40 = 1;
463 ProtCfg.field.TxopAllowMM20 = 1;
464 ProtCfg.field.TxopAllowOfdm = 1;
465 ProtCfg.field.TxopAllowCck = 1;
466 ProtCfg.field.RTSThEn = 1;
467 ProtCfg.field.ProtectNav = ASIC_SHORTNAV;
469 /* update PHY mode and rate */
470 if (pAd->CommonCfg.Channel > 14)
471 ProtCfg.field.ProtectRate = 0x4000;
472 ProtCfg.field.ProtectRate |= pAd->CommonCfg.RtsRate;
474 /* Handle legacy(B/G) protection */
475 if (bDisableBGProtect) {
476 /*ProtCfg.field.ProtectRate = pAd->CommonCfg.RtsRate; */
477 ProtCfg.field.ProtectCtrl = 0;
478 Protect[0] = ProtCfg.word;
479 Protect[1] = ProtCfg.word;
480 pAd->FlgCtsEnabled = 0; /* CTS-self is not used */
482 /*ProtCfg.field.ProtectRate = pAd->CommonCfg.RtsRate; */
483 ProtCfg.field.ProtectCtrl = 0; /* CCK do not need to be protected */
484 Protect[0] = ProtCfg.word;
485 ProtCfg.field.ProtectCtrl = ASIC_CTS; /* OFDM needs using CCK to protect */
486 Protect[1] = ProtCfg.word;
487 pAd->FlgCtsEnabled = 1; /* CTS-self is used */
490 /* Decide HT frame protection. */
491 if ((SetMask & ALLN_SETPROTECT) != 0) {
492 switch (OperationMode) {
495 /* 1.All STAs in the BSS are 20/40 MHz HT */
496 /* 2. in ai 20/40MHz BSS */
497 /* 3. all STAs are 20MHz in a 20MHz BSS */
498 /* Pure HT. no protection. */
501 /* Reserved (31:27) */
502 /* PROT_TXOP(25:20) -- 010111 */
503 /* PROT_NAV(19:18) -- 01 (Short NAV protection) */
504 /* PROT_CTRL(17:16) -- 00 (None) */
505 /* PROT_RATE(15:0) -- 0x4004 (OFDM 24M) */
506 Protect[2] = 0x01744004;
509 /* Reserved (31:27) */
510 /* PROT_TXOP(25:20) -- 111111 */
511 /* PROT_NAV(19:18) -- 01 (Short NAV protection) */
512 /* PROT_CTRL(17:16) -- 00 (None) */
513 /* PROT_RATE(15:0) -- 0x4084 (duplicate OFDM 24M) */
514 Protect[3] = 0x03f44084;
517 /* Reserved (31:27) */
518 /* PROT_TXOP(25:20) -- 010111 */
519 /* PROT_NAV(19:18) -- 01 (Short NAV protection) */
520 /* PROT_CTRL(17:16) -- 00 (None) */
521 /* PROT_RATE(15:0) -- 0x4004 (OFDM 24M) */
522 Protect[4] = 0x01744004;
525 /* Reserved (31:27) */
526 /* PROT_TXOP(25:20) -- 111111 */
527 /* PROT_NAV(19:18) -- 01 (Short NAV protection) */
528 /* PROT_CTRL(17:16) -- 00 (None) */
529 /* PROT_RATE(15:0) -- 0x4084 (duplicate OFDM 24M) */
530 Protect[5] = 0x03f44084;
533 /* PROT_NAV(19:18) -- 01 (Short NAV protectiion) */
534 /* PROT_CTRL(17:16) -- 01 (RTS/CTS) */
535 Protect[4] = 0x01754004;
536 Protect[5] = 0x03f54084;
538 pAd->CommonCfg.IOTestParm.bRTSLongProtOn = FALSE;
542 /* This is "HT non-member protection mode." */
543 /* If there may be non-HT STAs my BSS */
544 ProtCfg.word = 0x01744004; /* PROT_CTRL(17:16) : 0 (None) */
545 ProtCfg4.word = 0x03f44084; /* duplicaet legacy 24M. BW set 1. */
546 if (OPSTATUS_TEST_FLAG
547 (pAd, fOP_STATUS_BG_PROTECTION_INUSED)) {
548 ProtCfg.word = 0x01740003; /*ERP use Protection bit is set, use protection rate at Clause 18.. */
549 ProtCfg4.word = 0x03f40003; /* Don't duplicate RTS/CTS in CCK mode. 0x03f40083; */
551 /*Assign Protection method for 20&40 MHz packets */
552 ProtCfg.field.ProtectCtrl = ASIC_RTS;
553 ProtCfg.field.ProtectNav = ASIC_SHORTNAV;
554 ProtCfg4.field.ProtectCtrl = ASIC_RTS;
555 ProtCfg4.field.ProtectNav = ASIC_SHORTNAV;
556 Protect[2] = ProtCfg.word;
557 Protect[3] = ProtCfg4.word;
558 Protect[4] = ProtCfg.word;
559 Protect[5] = ProtCfg4.word;
560 pAd->CommonCfg.IOTestParm.bRTSLongProtOn = TRUE;
564 /* If only HT STAs are in BSS. at least one is 20MHz. Only protect 40MHz packets */
565 ProtCfg.word = 0x01744004; /* PROT_CTRL(17:16) : 0 (None) */
566 ProtCfg4.word = 0x03f44084; /* duplicaet legacy 24M. BW set 1. */
568 /*Assign Protection method for 40MHz packets */
569 ProtCfg4.field.ProtectCtrl = ASIC_RTS;
570 ProtCfg4.field.ProtectNav = ASIC_SHORTNAV;
571 Protect[2] = ProtCfg.word;
572 Protect[3] = ProtCfg4.word;
574 ProtCfg.field.ProtectCtrl = ASIC_RTS;
575 ProtCfg.field.ProtectNav = ASIC_SHORTNAV;
577 Protect[4] = ProtCfg.word;
578 Protect[5] = ProtCfg4.word;
580 pAd->CommonCfg.IOTestParm.bRTSLongProtOn = FALSE;
584 /* HT mixed mode. PROTECT ALL! */
586 ProtCfg.word = 0x01744004; /*duplicaet legacy 24M. BW set 1. */
587 ProtCfg4.word = 0x03f44084;
588 /* both 20MHz and 40MHz are protected. Whether use RTS or CTS-to-self depends on the */
589 if (OPSTATUS_TEST_FLAG
590 (pAd, fOP_STATUS_BG_PROTECTION_INUSED)) {
591 ProtCfg.word = 0x01740003; /*ERP use Protection bit is set, use protection rate at Clause 18.. */
592 ProtCfg4.word = 0x03f40003; /* Don't duplicate RTS/CTS in CCK mode. 0x03f40083 */
594 /*Assign Protection method for 20&40 MHz packets */
595 ProtCfg.field.ProtectCtrl = ASIC_RTS;
596 ProtCfg.field.ProtectNav = ASIC_SHORTNAV;
597 ProtCfg4.field.ProtectCtrl = ASIC_RTS;
598 ProtCfg4.field.ProtectNav = ASIC_SHORTNAV;
599 Protect[2] = ProtCfg.word;
600 Protect[3] = ProtCfg4.word;
601 Protect[4] = ProtCfg.word;
602 Protect[5] = ProtCfg4.word;
603 pAd->CommonCfg.IOTestParm.bRTSLongProtOn = TRUE;
607 /* Special on for Atheros problem n chip. */
608 Protect[2] = 0x01754004;
609 Protect[3] = 0x03f54084;
610 Protect[4] = 0x01754004;
611 Protect[5] = 0x03f54084;
612 pAd->CommonCfg.IOTestParm.bRTSLongProtOn = TRUE;
617 offset = CCK_PROT_CFG;
618 for (i = 0; i < 6; i++) {
619 if ((SetMask & (1 << i))) {
620 RTMP_IO_WRITE32(pAd, offset + i * 4, Protect[i]);
626 ==========================================================================
630 IRQL = DISPATCH_LEVEL
632 ==========================================================================
634 void AsicSwitchChannel(struct rt_rtmp_adapter *pAd, u8 Channel, IN BOOLEAN bScan)
636 unsigned long R2 = 0, R3 = DEFAULT_RF_TX_POWER, R4 = 0;
637 char TxPwer = 0, TxPwer2 = DEFAULT_RF_TX_POWER; /*Bbp94 = BBPR94_DEFAULT, TxPwer2 = DEFAULT_RF_TX_POWER; */
639 u32 Value = 0; /*BbpReg, Value; */
640 struct rt_rtmp_rf_regs *RFRegTable;
644 /* Search Tx power value */
645 /* We can't use ChannelList to search channel, since some central channl's txpowr doesn't list */
646 /* in ChannelList, so use TxPower array instead. */
648 for (index = 0; index < MAX_NUM_OF_CHANNELS; index++) {
649 if (Channel == pAd->TxPower[index].Channel) {
650 TxPwer = pAd->TxPower[index].Power;
651 TxPwer2 = pAd->TxPower[index].Power2;
656 if (index == MAX_NUM_OF_CHANNELS) {
657 DBGPRINT(RT_DEBUG_ERROR,
658 ("AsicSwitchChannel: Can't find the Channel#%d \n",
662 /* The RF programming sequence is difference between 3xxx and 2xxx */
663 if ((IS_RT3070(pAd) || IS_RT3090(pAd) || IS_RT3390(pAd))
664 && ((pAd->RfIcType == RFIC_3020) || (pAd->RfIcType == RFIC_2020)
665 || (pAd->RfIcType == RFIC_3021)
666 || (pAd->RfIcType == RFIC_3022))) {
667 /* modify by WY for Read RF Reg. error */
669 for (index = 0; index < NUM_OF_3020_CHNL; index++) {
670 if (Channel == FreqItems3020[index].Channel) {
671 /* Programming channel parameters */
672 RT30xxWriteRFRegister(pAd, RF_R02,
673 FreqItems3020[index].N);
674 RT30xxWriteRFRegister(pAd, RF_R03,
675 FreqItems3020[index].K);
676 RT30xxReadRFRegister(pAd, RF_R06, &RFValue);
678 (RFValue & 0xFC) | FreqItems3020[index].R;
679 RT30xxWriteRFRegister(pAd, RF_R06, RFValue);
682 RT30xxReadRFRegister(pAd, RF_R12, &RFValue);
683 RFValue = (RFValue & 0xE0) | TxPwer;
684 RT30xxWriteRFRegister(pAd, RF_R12, RFValue);
687 RT30xxReadRFRegister(pAd, RF_R13, &RFValue);
688 RFValue = (RFValue & 0xE0) | TxPwer2;
689 RT30xxWriteRFRegister(pAd, RF_R13, RFValue);
691 /* Tx/Rx Stream setting */
692 RT30xxReadRFRegister(pAd, RF_R01, &RFValue);
693 /*if (IS_RT3090(pAd)) */
694 /* RFValue |= 0x01; // Enable RF block. */
695 RFValue &= 0x03; /*clear bit[7~2] */
696 if (pAd->Antenna.field.TxPath == 1)
698 else if (pAd->Antenna.field.TxPath == 2)
700 if (pAd->Antenna.field.RxPath == 1)
702 else if (pAd->Antenna.field.RxPath == 2)
704 RT30xxWriteRFRegister(pAd, RF_R01, RFValue);
707 RT30xxReadRFRegister(pAd, RF_R23, &RFValue);
708 RFValue = (RFValue & 0x80) | pAd->RfFreqOffset;
709 RT30xxWriteRFRegister(pAd, RF_R23, RFValue);
713 && (pAd->CommonCfg.BBPCurrentBW == BW_40)) {
714 RFValue = pAd->Mlme.CaliBW40RfR24;
715 /*DISABLE_11N_CHECK(pAd); */
717 RFValue = pAd->Mlme.CaliBW20RfR24;
719 RT30xxWriteRFRegister(pAd, RF_R24, RFValue);
720 RT30xxWriteRFRegister(pAd, RF_R31, RFValue);
722 /* Enable RF tuning */
723 RT30xxReadRFRegister(pAd, RF_R07, &RFValue);
724 RFValue = RFValue | 0x1;
725 RT30xxWriteRFRegister(pAd, RF_R07, RFValue);
727 /* latch channel for future usage. */
728 pAd->LatchRfRegs.Channel = Channel;
730 DBGPRINT(RT_DEBUG_TRACE,
731 ("SwitchChannel#%d(RF=%d, Pwr0=%d, Pwr1=%d, %dT), N=0x%02X, K=0x%02X, R=0x%02X\n",
732 Channel, pAd->RfIcType, TxPwer,
733 TxPwer2, pAd->Antenna.field.TxPath,
734 FreqItems3020[index].N,
735 FreqItems3020[index].K,
736 FreqItems3020[index].R));
742 #endif /* RT30xx // */
744 RFRegTable = RF2850RegTable;
745 switch (pAd->RfIcType) {
751 for (index = 0; index < NUM_OF_2850_CHNL; index++) {
752 if (Channel == RFRegTable[index].Channel) {
753 R2 = RFRegTable[index].R2;
754 if (pAd->Antenna.field.TxPath == 1) {
755 R2 |= 0x4000; /* If TXpath is 1, bit 14 = 1; */
758 if (pAd->Antenna.field.RxPath == 2) {
759 R2 |= 0x40; /* write 1 to off Rxpath. */
760 } else if (pAd->Antenna.field.RxPath ==
762 R2 |= 0x20040; /* write 1 to off RxPath */
766 /* initialize R3, R4 */
767 R3 = (RFRegTable[index].
769 R4 = (RFRegTable[index].
770 R4 & (~0x001f87c0)) |
771 (pAd->RfFreqOffset << 15);
773 /* 5G band power range: 0xF9~0X0F, TX0 Reg3 bit9/TX1 Reg4 bit6="0" means the TX power reduce 7dB */
777 TxPwer = (7 + TxPwer);
782 R3 |= (TxPwer << 10);
783 DBGPRINT(RT_DEBUG_ERROR,
784 ("AsicSwitchChannel: TxPwer=%d \n",
800 TxPwer2 = (7 + TxPwer2);
805 R4 |= (TxPwer2 << 7);
806 DBGPRINT(RT_DEBUG_ERROR,
807 ("AsicSwitchChannel: TxPwer2=%d \n",
820 R3 = (RFRegTable[index].R3 & 0xffffc1ff) | (TxPwer << 9); /* set TX power0 */
821 R4 = (RFRegTable[index].R4 & (~0x001f87c0)) | (pAd->RfFreqOffset << 15) | (TxPwer2 << 6); /* Set freq Offset & TxPwr1 */
824 /* Based on BBP current mode before changing RF channel. */
826 && (pAd->CommonCfg.BBPCurrentBW ==
830 /* Update variables */
831 pAd->LatchRfRegs.Channel = Channel;
832 pAd->LatchRfRegs.R1 =
833 RFRegTable[index].R1;
834 pAd->LatchRfRegs.R2 = R2;
835 pAd->LatchRfRegs.R3 = R3;
836 pAd->LatchRfRegs.R4 = R4;
838 /* Set RF value 1's set R3[bit2] = [0] */
839 RTMP_RF_IO_WRITE32(pAd,
840 pAd->LatchRfRegs.R1);
841 RTMP_RF_IO_WRITE32(pAd,
842 pAd->LatchRfRegs.R2);
843 RTMP_RF_IO_WRITE32(pAd,
846 RTMP_RF_IO_WRITE32(pAd,
847 pAd->LatchRfRegs.R4);
851 /* Set RF value 2's set R3[bit2] = [1] */
852 RTMP_RF_IO_WRITE32(pAd,
853 pAd->LatchRfRegs.R1);
854 RTMP_RF_IO_WRITE32(pAd,
855 pAd->LatchRfRegs.R2);
856 RTMP_RF_IO_WRITE32(pAd,
859 RTMP_RF_IO_WRITE32(pAd,
860 pAd->LatchRfRegs.R4);
864 /* Set RF value 3's set R3[bit2] = [0] */
865 RTMP_RF_IO_WRITE32(pAd,
866 pAd->LatchRfRegs.R1);
867 RTMP_RF_IO_WRITE32(pAd,
868 pAd->LatchRfRegs.R2);
869 RTMP_RF_IO_WRITE32(pAd,
872 RTMP_RF_IO_WRITE32(pAd,
873 pAd->LatchRfRegs.R4);
884 DBGPRINT(RT_DEBUG_TRACE,
885 ("SwitchChannel#%d(RF=%d, Pwr0=%lu, Pwr1=%lu, %dT) to , R1=0x%08lx, R2=0x%08lx, R3=0x%08lx, R4=0x%08lx\n",
886 Channel, pAd->RfIcType, (R3 & 0x00003e00) >> 9,
887 (R4 & 0x000007c0) >> 6, pAd->Antenna.field.TxPath,
888 pAd->LatchRfRegs.R1, pAd->LatchRfRegs.R2,
889 pAd->LatchRfRegs.R3, pAd->LatchRfRegs.R4));
892 /* Change BBP setting during siwtch from a->g, g->a */
894 unsigned long TxPinCfg = 0x00050F0A; /*Gary 2007/08/09 0x050A0A */
896 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R62,
897 (0x37 - GET_LNA_GAIN(pAd)));
898 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R63,
899 (0x37 - GET_LNA_GAIN(pAd)));
900 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R64,
901 (0x37 - GET_LNA_GAIN(pAd)));
902 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R86, 0); /*(0x44 - GET_LNA_GAIN(pAd))); // According the Rory's suggestion to solve the middle range issue. */
903 /*RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R82, 0x62); */
905 /* Rx High power VGA offset for LNA select */
906 if (pAd->NicConfig2.field.ExternalLNAForG) {
907 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R82, 0x62);
908 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R75, 0x46);
910 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R82, 0x84);
911 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R75, 0x50);
914 /* 5G band selection PIN, bit1 and bit2 are complement */
915 RTMP_IO_READ32(pAd, TX_BAND_CFG, &Value);
918 RTMP_IO_WRITE32(pAd, TX_BAND_CFG, Value);
920 /* Turn off unused PA or LNA when only 1T or 1R */
921 if (pAd->Antenna.field.TxPath == 1) {
922 TxPinCfg &= 0xFFFFFFF3;
924 if (pAd->Antenna.field.RxPath == 1) {
925 TxPinCfg &= 0xFFFFF3FF;
928 RTMP_IO_WRITE32(pAd, TX_PIN_CFG, TxPinCfg);
930 #if defined(RT3090) || defined(RT3390)
931 /* PCIe PHY Transmit attenuation adjustment */
932 if (IS_RT3090A(pAd) || IS_RT3390(pAd)) {
933 TX_ATTENUATION_CTRL_STRUC TxAttenuationCtrl = {
936 RTMP_IO_READ32(pAd, PCIE_PHY_TX_ATTENUATION_CTRL,
937 &TxAttenuationCtrl.word);
939 if (Channel == 14) /* Channel #14 */
941 TxAttenuationCtrl.field.PCIE_PHY_TX_ATTEN_EN = 1; /* Enable PCIe PHY Tx attenuation */
942 TxAttenuationCtrl.field.PCIE_PHY_TX_ATTEN_VALUE = 4; /* 9/16 full drive level */
943 } else /* Channel #1~#13 */
945 TxAttenuationCtrl.field.PCIE_PHY_TX_ATTEN_EN = 0; /* Disable PCIe PHY Tx attenuation */
946 TxAttenuationCtrl.field.PCIE_PHY_TX_ATTEN_VALUE = 0; /* n/a */
949 RTMP_IO_WRITE32(pAd, PCIE_PHY_TX_ATTENUATION_CTRL,
950 TxAttenuationCtrl.word);
954 unsigned long TxPinCfg = 0x00050F05; /*Gary 2007/8/9 0x050505 */
956 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R62,
957 (0x37 - GET_LNA_GAIN(pAd)));
958 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R63,
959 (0x37 - GET_LNA_GAIN(pAd)));
960 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R64,
961 (0x37 - GET_LNA_GAIN(pAd)));
962 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R86, 0); /*(0x44 - GET_LNA_GAIN(pAd))); // According the Rory's suggestion to solve the middle range issue. */
963 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R82, 0xF2);
965 /* Rx High power VGA offset for LNA select */
966 if (pAd->NicConfig2.field.ExternalLNAForA) {
967 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R75, 0x46);
969 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R75, 0x50);
972 /* 5G band selection PIN, bit1 and bit2 are complement */
973 RTMP_IO_READ32(pAd, TX_BAND_CFG, &Value);
976 RTMP_IO_WRITE32(pAd, TX_BAND_CFG, Value);
978 /* Turn off unused PA or LNA when only 1T or 1R */
979 if (pAd->Antenna.field.TxPath == 1) {
980 TxPinCfg &= 0xFFFFFFF3;
982 if (pAd->Antenna.field.RxPath == 1) {
983 TxPinCfg &= 0xFFFFF3FF;
986 RTMP_IO_WRITE32(pAd, TX_PIN_CFG, TxPinCfg);
990 /* R66 should be set according to Channel and use 20MHz when scanning */
991 /*RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R66, (0x2E + GET_LNA_GAIN(pAd))); */
993 RTMPSetAGCInitValue(pAd, BW_20);
995 RTMPSetAGCInitValue(pAd, pAd->CommonCfg.BBPCurrentBW);
998 /* On 11A, We should delay and wait RF/BBP to be stable */
999 /* and the appropriate time should be 1000 micro seconds */
1000 /* 2005/06/05 - On 11G, We also need this delay time. Otherwise it's difficult to pass the WHQL. */
1002 RTMPusecDelay(1000);
1005 void AsicResetBBPAgent(struct rt_rtmp_adapter *pAd)
1007 BBP_CSR_CFG_STRUC BbpCsr;
1008 DBGPRINT(RT_DEBUG_ERROR, ("Reset BBP Agent busy bit!\n"));
1009 /* Still need to find why BBP agent keeps busy, but in fact, hardware still function ok. Now clear busy first. */
1010 RTMP_IO_READ32(pAd, H2M_BBP_AGENT, &BbpCsr.word);
1011 BbpCsr.field.Busy = 0;
1012 RTMP_IO_WRITE32(pAd, H2M_BBP_AGENT, BbpCsr.word);
1016 ==========================================================================
1018 This function is required for 2421 only, and should not be used during
1019 site survey. It's only required after NIC decided to stay at a channel
1020 for a longer period.
1021 When this function is called, it's always after AsicSwitchChannel().
1023 IRQL = PASSIVE_LEVEL
1024 IRQL = DISPATCH_LEVEL
1026 ==========================================================================
1028 void AsicLockChannel(struct rt_rtmp_adapter *pAd, u8 Channel)
1032 void AsicRfTuningExec(void *SystemSpecific1,
1033 void *FunctionContext,
1034 void *SystemSpecific2, void *SystemSpecific3)
1039 ==========================================================================
1041 Gives CCK TX rate 2 more dB TX power.
1042 This routine works only in LINK UP in INFRASTRUCTURE mode.
1044 calculate desired Tx power in RF R3.Tx0~5, should consider -
1045 0. if current radio is a noisy environment (pAd->DrsCounters.fNoisyEnvironment)
1046 1. TxPowerPercentage
1047 2. auto calibration based on TSSI feedback
1048 3. extra 2 db for CCK
1049 4. -10 db upon very-short distance (AvgRSSI >= -40db) to AP
1051 NOTE: Since this routine requires the value of (pAd->DrsCounters.fNoisyEnvironment),
1052 it should be called AFTER MlmeDynamicTxRatSwitching()
1053 ==========================================================================
1055 void AsicAdjustTxPower(struct rt_rtmp_adapter *pAd)
1059 BOOLEAN bAutoTxAgc = FALSE;
1060 u8 TssiRef, *pTssiMinusBoundary, *pTssiPlusBoundary, TxAgcStep;
1061 u8 BbpR1 = 0, BbpR49 = 0, idx;
1062 char *pTxAgcCompensate;
1063 unsigned long TxPwr[5];
1067 if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_DOZE) ||
1069 (pAd->bPCIclkOff == TRUE) ||
1070 #endif /* RTMP_MAC_PCI // */
1071 RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_IDLE_RADIO_OFF) ||
1072 RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
1075 Rssi = RTMPMaxRssi(pAd,
1076 pAd->StaCfg.RssiSample.AvgRssi0,
1077 pAd->StaCfg.RssiSample.AvgRssi1,
1078 pAd->StaCfg.RssiSample.AvgRssi2);
1080 if (pAd->CommonCfg.BBPCurrentBW == BW_40) {
1081 if (pAd->CommonCfg.CentralChannel > 14) {
1082 TxPwr[0] = pAd->Tx40MPwrCfgABand[0];
1083 TxPwr[1] = pAd->Tx40MPwrCfgABand[1];
1084 TxPwr[2] = pAd->Tx40MPwrCfgABand[2];
1085 TxPwr[3] = pAd->Tx40MPwrCfgABand[3];
1086 TxPwr[4] = pAd->Tx40MPwrCfgABand[4];
1088 TxPwr[0] = pAd->Tx40MPwrCfgGBand[0];
1089 TxPwr[1] = pAd->Tx40MPwrCfgGBand[1];
1090 TxPwr[2] = pAd->Tx40MPwrCfgGBand[2];
1091 TxPwr[3] = pAd->Tx40MPwrCfgGBand[3];
1092 TxPwr[4] = pAd->Tx40MPwrCfgGBand[4];
1095 if (pAd->CommonCfg.Channel > 14) {
1096 TxPwr[0] = pAd->Tx20MPwrCfgABand[0];
1097 TxPwr[1] = pAd->Tx20MPwrCfgABand[1];
1098 TxPwr[2] = pAd->Tx20MPwrCfgABand[2];
1099 TxPwr[3] = pAd->Tx20MPwrCfgABand[3];
1100 TxPwr[4] = pAd->Tx20MPwrCfgABand[4];
1102 TxPwr[0] = pAd->Tx20MPwrCfgGBand[0];
1103 TxPwr[1] = pAd->Tx20MPwrCfgGBand[1];
1104 TxPwr[2] = pAd->Tx20MPwrCfgGBand[2];
1105 TxPwr[3] = pAd->Tx20MPwrCfgGBand[3];
1106 TxPwr[4] = pAd->Tx20MPwrCfgGBand[4];
1110 /* TX power compensation for temperature variation based on TSSI. try every 4 second */
1111 if (pAd->Mlme.OneSecPeriodicRound % 4 == 0) {
1112 if (pAd->CommonCfg.Channel <= 14) {
1114 bAutoTxAgc = pAd->bAutoTxAgcG;
1115 TssiRef = pAd->TssiRefG;
1116 pTssiMinusBoundary = &pAd->TssiMinusBoundaryG[0];
1117 pTssiPlusBoundary = &pAd->TssiPlusBoundaryG[0];
1118 TxAgcStep = pAd->TxAgcStepG;
1119 pTxAgcCompensate = &pAd->TxAgcCompensateG;
1122 bAutoTxAgc = pAd->bAutoTxAgcA;
1123 TssiRef = pAd->TssiRefA;
1124 pTssiMinusBoundary = &pAd->TssiMinusBoundaryA[0];
1125 pTssiPlusBoundary = &pAd->TssiPlusBoundaryA[0];
1126 TxAgcStep = pAd->TxAgcStepA;
1127 pTxAgcCompensate = &pAd->TxAgcCompensateA;
1131 /* BbpR1 is unsigned char */
1132 RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R49, &BbpR49);
1134 /* (p) TssiPlusBoundaryG[0] = 0 = (m) TssiMinusBoundaryG[0] */
1135 /* compensate: +4 +3 +2 +1 0 -1 -2 -3 -4 * steps */
1136 /* step value is defined in pAd->TxAgcStepG for tx power value */
1138 /* [4]+1+[4] p4 p3 p2 p1 o1 m1 m2 m3 m4 */
1139 /* ex: 0x00 0x15 0x25 0x45 0x88 0xA0 0xB5 0xD0 0xF0
1140 above value are examined in mass factory production */
1141 /* [4] [3] [2] [1] [0] [1] [2] [3] [4] */
1143 /* plus (+) is 0x00 ~ 0x45, minus (-) is 0xa0 ~ 0xf0 */
1144 /* if value is between p1 ~ o1 or o1 ~ s1, no need to adjust tx power */
1145 /* if value is 0xa5, tx power will be -= TxAgcStep*(2-1) */
1147 if (BbpR49 > pTssiMinusBoundary[1]) {
1148 /* Reading is larger than the reference value */
1149 /* check for how large we need to decrease the Tx power */
1150 for (idx = 1; idx < 5; idx++) {
1151 if (BbpR49 <= pTssiMinusBoundary[idx]) /* Found the range */
1154 /* The index is the step we should decrease, idx = 0 means there is nothing to compensate */
1155 /* if (R3 > (unsigned long)(TxAgcStep * (idx-1))) */
1156 *pTxAgcCompensate = -(TxAgcStep * (idx - 1));
1158 /* *pTxAgcCompensate = -((u8)R3); */
1160 DeltaPwr += (*pTxAgcCompensate);
1161 DBGPRINT(RT_DEBUG_TRACE,
1162 ("-- Tx Power, BBP R1=%x, TssiRef=%x, TxAgcStep=%x, step = -%d\n",
1163 BbpR49, TssiRef, TxAgcStep, idx - 1));
1164 } else if (BbpR49 < pTssiPlusBoundary[1]) {
1165 /* Reading is smaller than the reference value */
1166 /* check for how large we need to increase the Tx power */
1167 for (idx = 1; idx < 5; idx++) {
1168 if (BbpR49 >= pTssiPlusBoundary[idx]) /* Found the range */
1171 /* The index is the step we should increase, idx = 0 means there is nothing to compensate */
1172 *pTxAgcCompensate = TxAgcStep * (idx - 1);
1173 DeltaPwr += (*pTxAgcCompensate);
1174 DBGPRINT(RT_DEBUG_TRACE,
1175 ("++ Tx Power, BBP R1=%x, TssiRef=%x, TxAgcStep=%x, step = +%d\n",
1176 BbpR49, TssiRef, TxAgcStep, idx - 1));
1178 *pTxAgcCompensate = 0;
1179 DBGPRINT(RT_DEBUG_TRACE,
1180 (" Tx Power, BBP R49=%x, TssiRef=%x, TxAgcStep=%x, step = +%d\n",
1181 BbpR49, TssiRef, TxAgcStep, 0));
1185 if (pAd->CommonCfg.Channel <= 14) {
1186 bAutoTxAgc = pAd->bAutoTxAgcG;
1187 pTxAgcCompensate = &pAd->TxAgcCompensateG;
1189 bAutoTxAgc = pAd->bAutoTxAgcA;
1190 pTxAgcCompensate = &pAd->TxAgcCompensateA;
1194 DeltaPwr += (*pTxAgcCompensate);
1197 RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R1, &BbpR1);
1200 /* calculate delta power based on the percentage specified from UI */
1201 /* E2PROM setting is calibrated for maximum TX power (i.e. 100%) */
1202 /* We lower TX power here according to the percentage specified from UI */
1203 if (pAd->CommonCfg.TxPowerPercentage == 0xffffffff) /* AUTO TX POWER control */
1206 /* to patch high power issue with some APs, like Belkin N1. */
1208 BbpR1 |= 0x02; /* DeltaPwr -= 12; */
1209 } else if (Rssi > -40) {
1210 BbpR1 |= 0x01; /* DeltaPwr -= 6; */
1213 } else if (pAd->CommonCfg.TxPowerPercentage > 90) /* 91 ~ 100% & AUTO, treat as 100% in terms of mW */
1215 else if (pAd->CommonCfg.TxPowerPercentage > 60) /* 61 ~ 90%, treat as 75% in terms of mW // DeltaPwr -= 1; */
1218 } else if (pAd->CommonCfg.TxPowerPercentage > 30) /* 31 ~ 60%, treat as 50% in terms of mW // DeltaPwr -= 3; */
1221 } else if (pAd->CommonCfg.TxPowerPercentage > 15) /* 16 ~ 30%, treat as 25% in terms of mW // DeltaPwr -= 6; */
1224 } else if (pAd->CommonCfg.TxPowerPercentage > 9) /* 10 ~ 15%, treat as 12.5% in terms of mW // DeltaPwr -= 9; */
1228 } else /* 0 ~ 9 %, treat as MIN(~3%) in terms of mW // DeltaPwr -= 12; */
1233 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R1, BbpR1);
1235 /* reset different new tx power for different TX rate */
1236 for (i = 0; i < 5; i++) {
1237 if (TxPwr[i] != 0xffffffff) {
1238 for (j = 0; j < 8; j++) {
1239 Value = (char)((TxPwr[i] >> j * 4) & 0x0F); /* 0 ~ 15 */
1241 if ((Value + DeltaPwr) < 0) {
1242 Value = 0; /* min */
1243 } else if ((Value + DeltaPwr) > 0xF) {
1244 Value = 0xF; /* max */
1246 Value += DeltaPwr; /* temperature compensation */
1249 /* fill new value to CSR offset */
1251 (TxPwr[i] & ~(0x0000000F << j * 4)) | (Value
1256 /* write tx power value to CSR */
1257 /* TX_PWR_CFG_0 (8 tx rate) for TX power for OFDM 12M/18M
1258 TX power for OFDM 6M/9M
1259 TX power for CCK5.5M/11M
1260 TX power for CCK1M/2M */
1261 /* TX_PWR_CFG_1 ~ TX_PWR_CFG_4 */
1262 RTMP_IO_WRITE32(pAd, TX_PWR_CFG_0 + i * 4, TxPwr[i]);
1269 ==========================================================================
1271 put PHY to sleep here, and set next wakeup timer. PHY doesn't not wakeup
1272 automatically. Instead, MCU will issue a TwakeUpInterrupt to host after
1273 the wakeup timer timeout. Driver has to issue a separate command to wake
1276 IRQL = DISPATCH_LEVEL
1278 ==========================================================================
1280 void AsicSleepThenAutoWakeup(struct rt_rtmp_adapter *pAd,
1281 u16 TbttNumToNextWakeUp)
1283 RTMP_STA_SLEEP_THEN_AUTO_WAKEUP(pAd, TbttNumToNextWakeUp);
1287 ==========================================================================
1289 AsicForceWakeup() is used whenever manual wakeup is required
1290 AsicForceSleep() should only be used when not in INFRA BSS. When
1291 in INFRA BSS, we should use AsicSleepThenAutoWakeup() instead.
1292 ==========================================================================
1294 void AsicForceSleep(struct rt_rtmp_adapter *pAd)
1300 ==========================================================================
1302 AsicForceWakeup() is used whenever Twakeup timer (set via AsicSleepThenAutoWakeup)
1305 IRQL = PASSIVE_LEVEL
1306 IRQL = DISPATCH_LEVEL
1307 ==========================================================================
1309 void AsicForceWakeup(struct rt_rtmp_adapter *pAd, IN BOOLEAN bFromTx)
1311 DBGPRINT(RT_DEBUG_INFO, ("--> AsicForceWakeup \n"));
1312 RTMP_STA_FORCE_WAKEUP(pAd, bFromTx);
1316 ==========================================================================
1320 IRQL = DISPATCH_LEVEL
1322 ==========================================================================
1324 void AsicSetBssid(struct rt_rtmp_adapter *pAd, u8 *pBssid)
1326 unsigned long Addr4;
1327 DBGPRINT(RT_DEBUG_TRACE,
1328 ("==============> AsicSetBssid %x:%x:%x:%x:%x:%x\n", pBssid[0],
1329 pBssid[1], pBssid[2], pBssid[3], pBssid[4], pBssid[5]));
1331 Addr4 = (unsigned long)(pBssid[0]) |
1332 (unsigned long)(pBssid[1] << 8) |
1333 (unsigned long)(pBssid[2] << 16) | (unsigned long)(pBssid[3] << 24);
1334 RTMP_IO_WRITE32(pAd, MAC_BSSID_DW0, Addr4);
1337 /* always one BSSID in STA mode */
1338 Addr4 = (unsigned long)(pBssid[4]) | (unsigned long)(pBssid[5] << 8);
1340 RTMP_IO_WRITE32(pAd, MAC_BSSID_DW1, Addr4);
1343 void AsicSetMcastWC(struct rt_rtmp_adapter *pAd)
1345 struct rt_mac_table_entry *pEntry = &pAd->MacTab.Content[MCAST_WCID];
1348 pEntry->Sst = SST_ASSOC;
1349 pEntry->Aid = MCAST_WCID; /* Softap supports 1 BSSID and use WCID=0 as multicast Wcid index */
1350 pEntry->PsMode = PWR_ACTIVE;
1351 pEntry->CurrTxRate = pAd->CommonCfg.MlmeRate;
1352 offset = MAC_WCID_BASE + BSS0Mcast_WCID * HW_WCID_ENTRY_SIZE;
1356 ==========================================================================
1359 IRQL = DISPATCH_LEVEL
1361 ==========================================================================
1363 void AsicDelWcidTab(struct rt_rtmp_adapter *pAd, u8 Wcid)
1365 unsigned long Addr0 = 0x0, Addr1 = 0x0;
1366 unsigned long offset;
1368 DBGPRINT(RT_DEBUG_TRACE, ("AsicDelWcidTab==>Wcid = 0x%x\n", Wcid));
1369 offset = MAC_WCID_BASE + Wcid * HW_WCID_ENTRY_SIZE;
1370 RTMP_IO_WRITE32(pAd, offset, Addr0);
1372 RTMP_IO_WRITE32(pAd, offset, Addr1);
1376 ==========================================================================
1379 IRQL = DISPATCH_LEVEL
1381 ==========================================================================
1383 void AsicEnableRDG(struct rt_rtmp_adapter *pAd)
1385 TX_LINK_CFG_STRUC TxLinkCfg;
1388 RTMP_IO_READ32(pAd, TX_LINK_CFG, &TxLinkCfg.word);
1389 TxLinkCfg.field.TxRDGEn = 1;
1390 RTMP_IO_WRITE32(pAd, TX_LINK_CFG, TxLinkCfg.word);
1392 RTMP_IO_READ32(pAd, EDCA_AC0_CFG, &Data);
1395 RTMP_IO_WRITE32(pAd, EDCA_AC0_CFG, Data);
1397 /*OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_AGGREGATION_INUSED); */
1401 ==========================================================================
1404 IRQL = DISPATCH_LEVEL
1406 ==========================================================================
1408 void AsicDisableRDG(struct rt_rtmp_adapter *pAd)
1410 TX_LINK_CFG_STRUC TxLinkCfg;
1413 RTMP_IO_READ32(pAd, TX_LINK_CFG, &TxLinkCfg.word);
1414 TxLinkCfg.field.TxRDGEn = 0;
1415 RTMP_IO_WRITE32(pAd, TX_LINK_CFG, TxLinkCfg.word);
1417 RTMP_IO_READ32(pAd, EDCA_AC0_CFG, &Data);
1422 /*if ( pAd->CommonCfg.bEnableTxBurst ) */
1423 /* Data |= 0x60; // for performance issue not set the TXOP to 0 */
1425 if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_DYNAMIC_BE_TXOP_ACTIVE)
1426 && (pAd->MacTab.fAnyStationMIMOPSDynamic == FALSE)
1428 /* For CWC test, change txop from 0x30 to 0x20 in TxBurst mode */
1429 if (pAd->CommonCfg.bEnableTxBurst)
1432 RTMP_IO_WRITE32(pAd, EDCA_AC0_CFG, Data);
1436 ==========================================================================
1439 IRQL = PASSIVE_LEVEL
1440 IRQL = DISPATCH_LEVEL
1442 ==========================================================================
1444 void AsicDisableSync(struct rt_rtmp_adapter *pAd)
1446 BCN_TIME_CFG_STRUC csr;
1448 DBGPRINT(RT_DEBUG_TRACE, ("--->Disable TSF synchronization\n"));
1450 /* 2003-12-20 disable TSF and TBTT while NIC in power-saving have side effect */
1451 /* that NIC will never wakes up because TSF stops and no more */
1452 /* TBTT interrupts */
1453 pAd->TbttTickCount = 0;
1454 RTMP_IO_READ32(pAd, BCN_TIME_CFG, &csr.word);
1455 csr.field.bBeaconGen = 0;
1456 csr.field.bTBTTEnable = 0;
1457 csr.field.TsfSyncMode = 0;
1458 csr.field.bTsfTicking = 0;
1459 RTMP_IO_WRITE32(pAd, BCN_TIME_CFG, csr.word);
1464 ==========================================================================
1467 IRQL = DISPATCH_LEVEL
1469 ==========================================================================
1471 void AsicEnableBssSync(struct rt_rtmp_adapter *pAd)
1473 BCN_TIME_CFG_STRUC csr;
1475 DBGPRINT(RT_DEBUG_TRACE, ("--->AsicEnableBssSync(INFRA mode)\n"));
1477 RTMP_IO_READ32(pAd, BCN_TIME_CFG, &csr.word);
1478 /* RTMP_IO_WRITE32(pAd, BCN_TIME_CFG, 0x00000000); */
1480 csr.field.BeaconInterval = pAd->CommonCfg.BeaconPeriod << 4; /* ASIC register in units of 1/16 TU */
1481 csr.field.bTsfTicking = 1;
1482 csr.field.TsfSyncMode = 1; /* sync TSF in INFRASTRUCTURE mode */
1483 csr.field.bBeaconGen = 0; /* do NOT generate BEACON */
1484 csr.field.bTBTTEnable = 1;
1486 RTMP_IO_WRITE32(pAd, BCN_TIME_CFG, csr.word);
1490 ==========================================================================
1493 BEACON frame in shared memory should be built ok before this routine
1494 can be called. Otherwise, a garbage frame maybe transmitted out every
1497 IRQL = DISPATCH_LEVEL
1499 ==========================================================================
1501 void AsicEnableIbssSync(struct rt_rtmp_adapter *pAd)
1503 BCN_TIME_CFG_STRUC csr9;
1507 DBGPRINT(RT_DEBUG_TRACE,
1508 ("--->AsicEnableIbssSync(ADHOC mode. MPDUtotalByteCount = %d)\n",
1509 pAd->BeaconTxWI.MPDUtotalByteCount));
1511 RTMP_IO_READ32(pAd, BCN_TIME_CFG, &csr9.word);
1512 csr9.field.bBeaconGen = 0;
1513 csr9.field.bTBTTEnable = 0;
1514 csr9.field.bTsfTicking = 0;
1515 RTMP_IO_WRITE32(pAd, BCN_TIME_CFG, csr9.word);
1518 /* move BEACON TXD and frame content to on-chip memory */
1519 ptr = (u8 *)& pAd->BeaconTxWI;
1520 for (i = 0; i < TXWI_SIZE; i += 4) /* 16-byte TXWI field */
1523 *ptr + (*(ptr + 1) << 8) + (*(ptr + 2) << 16) +
1525 RTMP_IO_WRITE32(pAd, HW_BEACON_BASE0 + i, longptr);
1529 /* start right after the 16-byte TXWI field */
1530 ptr = pAd->BeaconBuf;
1531 for (i = 0; i < pAd->BeaconTxWI.MPDUtotalByteCount; i += 4) {
1533 *ptr + (*(ptr + 1) << 8) + (*(ptr + 2) << 16) +
1535 RTMP_IO_WRITE32(pAd, HW_BEACON_BASE0 + TXWI_SIZE + i, longptr);
1538 #endif /* RTMP_MAC_PCI // */
1540 /* move BEACON TXD and frame content to on-chip memory */
1541 ptr = (u8 *)& pAd->BeaconTxWI;
1542 for (i = 0; i < TXWI_SIZE; i += 2) /* 16-byte TXWI field */
1544 /*u32 longptr = *ptr + (*(ptr+1)<<8) + (*(ptr+2)<<16) + (*(ptr+3)<<24); */
1545 /*RTMP_IO_WRITE32(pAd, HW_BEACON_BASE0 + i, longptr); */
1546 RTUSBMultiWrite(pAd, HW_BEACON_BASE0 + i, ptr, 2);
1550 /* start right after the 16-byte TXWI field */
1551 ptr = pAd->BeaconBuf;
1552 for (i = 0; i < pAd->BeaconTxWI.MPDUtotalByteCount; i += 2) {
1553 /*u32 longptr = *ptr + (*(ptr+1)<<8) + (*(ptr+2)<<16) + (*(ptr+3)<<24); */
1554 /*RTMP_IO_WRITE32(pAd, HW_BEACON_BASE0 + TXWI_SIZE + i, longptr); */
1555 RTUSBMultiWrite(pAd, HW_BEACON_BASE0 + TXWI_SIZE + i, ptr, 2);
1558 #endif /* RTMP_MAC_USB // */
1561 /* For Wi-Fi faily generated beacons between participating stations. */
1562 /* Set TBTT phase adaptive adjustment step to 8us (default 16us) */
1563 /* don't change settings 2006-5- by Jerry */
1564 /*RTMP_IO_WRITE32(pAd, TBTT_SYNC_CFG, 0x00001010); */
1566 /* start sending BEACON */
1567 csr9.field.BeaconInterval = pAd->CommonCfg.BeaconPeriod << 4; /* ASIC register in units of 1/16 TU */
1568 csr9.field.bTsfTicking = 1;
1569 csr9.field.TsfSyncMode = 2; /* sync TSF in IBSS mode */
1570 csr9.field.bTBTTEnable = 1;
1571 csr9.field.bBeaconGen = 1;
1572 RTMP_IO_WRITE32(pAd, BCN_TIME_CFG, csr9.word);
1576 ==========================================================================
1579 IRQL = PASSIVE_LEVEL
1580 IRQL = DISPATCH_LEVEL
1582 ==========================================================================
1584 void AsicSetEdcaParm(struct rt_rtmp_adapter *pAd, struct rt_edca_parm *pEdcaParm)
1586 EDCA_AC_CFG_STRUC Ac0Cfg, Ac1Cfg, Ac2Cfg, Ac3Cfg;
1587 AC_TXOP_CSR0_STRUC csr0;
1588 AC_TXOP_CSR1_STRUC csr1;
1589 AIFSN_CSR_STRUC AifsnCsr;
1590 CWMIN_CSR_STRUC CwminCsr;
1591 CWMAX_CSR_STRUC CwmaxCsr;
1598 if ((pEdcaParm == NULL) || (pEdcaParm->bValid == FALSE)) {
1599 DBGPRINT(RT_DEBUG_TRACE, ("AsicSetEdcaParm\n"));
1600 OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_WMM_INUSED);
1601 for (i = 0; i < MAX_LEN_OF_MAC_TABLE; i++) {
1602 if (pAd->MacTab.Content[i].ValidAsCLI
1603 || pAd->MacTab.Content[i].ValidAsApCli)
1604 CLIENT_STATUS_CLEAR_FLAG(&pAd->MacTab.
1606 fCLIENT_STATUS_WMM_CAPABLE);
1609 /*======================================================== */
1610 /* MAC Register has a copy . */
1611 /*======================================================== */
1612 /*#ifndef WIFI_TEST */
1613 if (pAd->CommonCfg.bEnableTxBurst) {
1614 /* For CWC test, change txop from 0x30 to 0x20 in TxBurst mode */
1615 Ac0Cfg.field.AcTxop = 0x20; /* Suggest by John for TxBurst in HT Mode */
1617 Ac0Cfg.field.AcTxop = 0; /* QID_AC_BE */
1619 /* Ac0Cfg.field.AcTxop = 0; // QID_AC_BE */
1621 Ac0Cfg.field.Cwmin = CW_MIN_IN_BITS;
1622 Ac0Cfg.field.Cwmax = CW_MAX_IN_BITS;
1623 Ac0Cfg.field.Aifsn = 2;
1624 RTMP_IO_WRITE32(pAd, EDCA_AC0_CFG, Ac0Cfg.word);
1626 Ac1Cfg.field.AcTxop = 0; /* QID_AC_BK */
1627 Ac1Cfg.field.Cwmin = CW_MIN_IN_BITS;
1628 Ac1Cfg.field.Cwmax = CW_MAX_IN_BITS;
1629 Ac1Cfg.field.Aifsn = 2;
1630 RTMP_IO_WRITE32(pAd, EDCA_AC1_CFG, Ac1Cfg.word);
1632 if (pAd->CommonCfg.PhyMode == PHY_11B) {
1633 Ac2Cfg.field.AcTxop = 192; /* AC_VI: 192*32us ~= 6ms */
1634 Ac3Cfg.field.AcTxop = 96; /* AC_VO: 96*32us ~= 3ms */
1636 Ac2Cfg.field.AcTxop = 96; /* AC_VI: 96*32us ~= 3ms */
1637 Ac3Cfg.field.AcTxop = 48; /* AC_VO: 48*32us ~= 1.5ms */
1639 Ac2Cfg.field.Cwmin = CW_MIN_IN_BITS;
1640 Ac2Cfg.field.Cwmax = CW_MAX_IN_BITS;
1641 Ac2Cfg.field.Aifsn = 2;
1642 RTMP_IO_WRITE32(pAd, EDCA_AC2_CFG, Ac2Cfg.word);
1643 Ac3Cfg.field.Cwmin = CW_MIN_IN_BITS;
1644 Ac3Cfg.field.Cwmax = CW_MAX_IN_BITS;
1645 Ac3Cfg.field.Aifsn = 2;
1646 RTMP_IO_WRITE32(pAd, EDCA_AC3_CFG, Ac3Cfg.word);
1648 /*======================================================== */
1649 /* DMA Register has a copy too. */
1650 /*======================================================== */
1651 csr0.field.Ac0Txop = 0; /* QID_AC_BE */
1652 csr0.field.Ac1Txop = 0; /* QID_AC_BK */
1653 RTMP_IO_WRITE32(pAd, WMM_TXOP0_CFG, csr0.word);
1654 if (pAd->CommonCfg.PhyMode == PHY_11B) {
1655 csr1.field.Ac2Txop = 192; /* AC_VI: 192*32us ~= 6ms */
1656 csr1.field.Ac3Txop = 96; /* AC_VO: 96*32us ~= 3ms */
1658 csr1.field.Ac2Txop = 96; /* AC_VI: 96*32us ~= 3ms */
1659 csr1.field.Ac3Txop = 48; /* AC_VO: 48*32us ~= 1.5ms */
1661 RTMP_IO_WRITE32(pAd, WMM_TXOP1_CFG, csr1.word);
1664 CwminCsr.field.Cwmin0 = CW_MIN_IN_BITS;
1665 CwminCsr.field.Cwmin1 = CW_MIN_IN_BITS;
1666 CwminCsr.field.Cwmin2 = CW_MIN_IN_BITS;
1667 CwminCsr.field.Cwmin3 = CW_MIN_IN_BITS;
1668 RTMP_IO_WRITE32(pAd, WMM_CWMIN_CFG, CwminCsr.word);
1671 CwmaxCsr.field.Cwmax0 = CW_MAX_IN_BITS;
1672 CwmaxCsr.field.Cwmax1 = CW_MAX_IN_BITS;
1673 CwmaxCsr.field.Cwmax2 = CW_MAX_IN_BITS;
1674 CwmaxCsr.field.Cwmax3 = CW_MAX_IN_BITS;
1675 RTMP_IO_WRITE32(pAd, WMM_CWMAX_CFG, CwmaxCsr.word);
1677 RTMP_IO_WRITE32(pAd, WMM_AIFSN_CFG, 0x00002222);
1679 NdisZeroMemory(&pAd->CommonCfg.APEdcaParm, sizeof(struct rt_edca_parm));
1681 OPSTATUS_SET_FLAG(pAd, fOP_STATUS_WMM_INUSED);
1682 /*======================================================== */
1683 /* MAC Register has a copy. */
1684 /*======================================================== */
1686 /* Modify Cwmin/Cwmax/Txop on queue[QID_AC_VI], Recommend by Jerry 2005/07/27 */
1687 /* To degrade our VIDO Queue's throughput for WiFi WMM S3T07 Issue. */
1689 /*pEdcaParm->Txop[QID_AC_VI] = pEdcaParm->Txop[QID_AC_VI] * 7 / 10; // rt2860c need this */
1691 Ac0Cfg.field.AcTxop = pEdcaParm->Txop[QID_AC_BE];
1692 Ac0Cfg.field.Cwmin = pEdcaParm->Cwmin[QID_AC_BE];
1693 Ac0Cfg.field.Cwmax = pEdcaParm->Cwmax[QID_AC_BE];
1694 Ac0Cfg.field.Aifsn = pEdcaParm->Aifsn[QID_AC_BE]; /*+1; */
1696 Ac1Cfg.field.AcTxop = pEdcaParm->Txop[QID_AC_BK];
1697 Ac1Cfg.field.Cwmin = pEdcaParm->Cwmin[QID_AC_BK]; /*+2; */
1698 Ac1Cfg.field.Cwmax = pEdcaParm->Cwmax[QID_AC_BK];
1699 Ac1Cfg.field.Aifsn = pEdcaParm->Aifsn[QID_AC_BK]; /*+1; */
1701 Ac2Cfg.field.AcTxop = (pEdcaParm->Txop[QID_AC_VI] * 6) / 10;
1702 if (pAd->Antenna.field.TxPath == 1) {
1703 Ac2Cfg.field.Cwmin = pEdcaParm->Cwmin[QID_AC_VI] + 1;
1704 Ac2Cfg.field.Cwmax = pEdcaParm->Cwmax[QID_AC_VI] + 1;
1706 Ac2Cfg.field.Cwmin = pEdcaParm->Cwmin[QID_AC_VI];
1707 Ac2Cfg.field.Cwmax = pEdcaParm->Cwmax[QID_AC_VI];
1709 Ac2Cfg.field.Aifsn = pEdcaParm->Aifsn[QID_AC_VI] + 1;
1711 Ac2Cfg.field.Aifsn = pEdcaParm->Aifsn[QID_AC_VI] + 3;
1712 #endif /* RTMP_MAC_USB // */
1715 /* Tuning for Wi-Fi WMM S06 */
1716 if (pAd->CommonCfg.bWiFiTest &&
1717 pEdcaParm->Aifsn[QID_AC_VI] == 10)
1718 Ac2Cfg.field.Aifsn -= 1;
1720 /* Tuning for TGn Wi-Fi 5.2.32 */
1721 /* STA TestBed changes in this item: conexant legacy sta ==> broadcom 11n sta */
1722 if (STA_TGN_WIFI_ON(pAd) &&
1723 pEdcaParm->Aifsn[QID_AC_VI] == 10) {
1724 Ac0Cfg.field.Aifsn = 3;
1725 Ac2Cfg.field.AcTxop = 5;
1728 if (pAd->RfIcType == RFIC_3020
1729 || pAd->RfIcType == RFIC_2020) {
1730 /* Tuning for WiFi WMM S3-T07: connexant legacy sta ==> broadcom 11n sta. */
1731 Ac2Cfg.field.Aifsn = 5;
1733 #endif /* RT30xx // */
1736 Ac3Cfg.field.AcTxop = pEdcaParm->Txop[QID_AC_VO];
1737 Ac3Cfg.field.Cwmin = pEdcaParm->Cwmin[QID_AC_VO];
1738 Ac3Cfg.field.Cwmax = pEdcaParm->Cwmax[QID_AC_VO];
1739 Ac3Cfg.field.Aifsn = pEdcaParm->Aifsn[QID_AC_VO];
1741 /*#ifdef WIFI_TEST */
1742 if (pAd->CommonCfg.bWiFiTest) {
1743 if (Ac3Cfg.field.AcTxop == 102) {
1744 Ac0Cfg.field.AcTxop =
1745 pEdcaParm->Txop[QID_AC_BE] ? pEdcaParm->
1746 Txop[QID_AC_BE] : 10;
1747 Ac0Cfg.field.Aifsn = pEdcaParm->Aifsn[QID_AC_BE] - 1; /* AIFSN must >= 1 */
1748 Ac1Cfg.field.AcTxop =
1749 pEdcaParm->Txop[QID_AC_BK];
1750 Ac1Cfg.field.Aifsn =
1751 pEdcaParm->Aifsn[QID_AC_BK];
1752 Ac2Cfg.field.AcTxop =
1753 pEdcaParm->Txop[QID_AC_VI];
1756 /*#endif // WIFI_TEST // */
1758 RTMP_IO_WRITE32(pAd, EDCA_AC0_CFG, Ac0Cfg.word);
1759 RTMP_IO_WRITE32(pAd, EDCA_AC1_CFG, Ac1Cfg.word);
1760 RTMP_IO_WRITE32(pAd, EDCA_AC2_CFG, Ac2Cfg.word);
1761 RTMP_IO_WRITE32(pAd, EDCA_AC3_CFG, Ac3Cfg.word);
1763 /*======================================================== */
1764 /* DMA Register has a copy too. */
1765 /*======================================================== */
1766 csr0.field.Ac0Txop = Ac0Cfg.field.AcTxop;
1767 csr0.field.Ac1Txop = Ac1Cfg.field.AcTxop;
1768 RTMP_IO_WRITE32(pAd, WMM_TXOP0_CFG, csr0.word);
1770 csr1.field.Ac2Txop = Ac2Cfg.field.AcTxop;
1771 csr1.field.Ac3Txop = Ac3Cfg.field.AcTxop;
1772 RTMP_IO_WRITE32(pAd, WMM_TXOP1_CFG, csr1.word);
1775 CwminCsr.field.Cwmin0 = pEdcaParm->Cwmin[QID_AC_BE];
1776 CwminCsr.field.Cwmin1 = pEdcaParm->Cwmin[QID_AC_BK];
1777 CwminCsr.field.Cwmin2 = pEdcaParm->Cwmin[QID_AC_VI];
1778 CwminCsr.field.Cwmin3 = pEdcaParm->Cwmin[QID_AC_VO] - 1; /*for TGn wifi test */
1779 RTMP_IO_WRITE32(pAd, WMM_CWMIN_CFG, CwminCsr.word);
1782 CwmaxCsr.field.Cwmax0 = pEdcaParm->Cwmax[QID_AC_BE];
1783 CwmaxCsr.field.Cwmax1 = pEdcaParm->Cwmax[QID_AC_BK];
1784 CwmaxCsr.field.Cwmax2 = pEdcaParm->Cwmax[QID_AC_VI];
1785 CwmaxCsr.field.Cwmax3 = pEdcaParm->Cwmax[QID_AC_VO];
1786 RTMP_IO_WRITE32(pAd, WMM_CWMAX_CFG, CwmaxCsr.word);
1789 AifsnCsr.field.Aifsn0 = Ac0Cfg.field.Aifsn; /*pEdcaParm->Aifsn[QID_AC_BE]; */
1790 AifsnCsr.field.Aifsn1 = Ac1Cfg.field.Aifsn; /*pEdcaParm->Aifsn[QID_AC_BK]; */
1791 AifsnCsr.field.Aifsn2 = Ac2Cfg.field.Aifsn; /*pEdcaParm->Aifsn[QID_AC_VI]; */
1794 /* Tuning for Wi-Fi WMM S06 */
1795 if (pAd->CommonCfg.bWiFiTest &&
1796 pEdcaParm->Aifsn[QID_AC_VI] == 10)
1797 AifsnCsr.field.Aifsn2 = Ac2Cfg.field.Aifsn - 4;
1799 /* Tuning for TGn Wi-Fi 5.2.32 */
1800 /* STA TestBed changes in this item: connexant legacy sta ==> broadcom 11n sta */
1801 if (STA_TGN_WIFI_ON(pAd) &&
1802 pEdcaParm->Aifsn[QID_AC_VI] == 10) {
1803 AifsnCsr.field.Aifsn0 = 3;
1804 AifsnCsr.field.Aifsn2 = 7;
1808 CLIENT_STATUS_SET_FLAG(&pAd->MacTab.
1809 Content[BSSID_WCID],
1810 fCLIENT_STATUS_WMM_CAPABLE);
1814 AifsnCsr.field.Aifsn3 = Ac3Cfg.field.Aifsn - 1; /*pEdcaParm->Aifsn[QID_AC_VO]; //for TGn wifi test */
1816 /* TODO: Shiang, this modification also suitable for RT3052/RT3050 ??? */
1817 if (pAd->RfIcType == RFIC_3020
1818 || pAd->RfIcType == RFIC_2020) {
1819 AifsnCsr.field.Aifsn2 = 0x2; /*pEdcaParm->Aifsn[QID_AC_VI]; //for WiFi WMM S4-T04. */
1821 #endif /* RT30xx // */
1823 RTMP_IO_WRITE32(pAd, WMM_AIFSN_CFG, AifsnCsr.word);
1825 NdisMoveMemory(&pAd->CommonCfg.APEdcaParm, pEdcaParm,
1826 sizeof(struct rt_edca_parm));
1827 if (!ADHOC_ON(pAd)) {
1828 DBGPRINT(RT_DEBUG_TRACE,
1829 ("EDCA [#%d]: AIFSN CWmin CWmax TXOP(us) ACM\n",
1830 pEdcaParm->EdcaUpdateCount));
1831 DBGPRINT(RT_DEBUG_TRACE,
1832 (" AC_BE %2d %2d %2d %4d %d\n",
1833 pEdcaParm->Aifsn[0], pEdcaParm->Cwmin[0],
1834 pEdcaParm->Cwmax[0], pEdcaParm->Txop[0] << 5,
1835 pEdcaParm->bACM[0]));
1836 DBGPRINT(RT_DEBUG_TRACE,
1837 (" AC_BK %2d %2d %2d %4d %d\n",
1838 pEdcaParm->Aifsn[1], pEdcaParm->Cwmin[1],
1839 pEdcaParm->Cwmax[1], pEdcaParm->Txop[1] << 5,
1840 pEdcaParm->bACM[1]));
1841 DBGPRINT(RT_DEBUG_TRACE,
1842 (" AC_VI %2d %2d %2d %4d %d\n",
1843 pEdcaParm->Aifsn[2], pEdcaParm->Cwmin[2],
1844 pEdcaParm->Cwmax[2], pEdcaParm->Txop[2] << 5,
1845 pEdcaParm->bACM[2]));
1846 DBGPRINT(RT_DEBUG_TRACE,
1847 (" AC_VO %2d %2d %2d %4d %d\n",
1848 pEdcaParm->Aifsn[3], pEdcaParm->Cwmin[3],
1849 pEdcaParm->Cwmax[3], pEdcaParm->Txop[3] << 5,
1850 pEdcaParm->bACM[3]));
1857 ==========================================================================
1860 IRQL = PASSIVE_LEVEL
1861 IRQL = DISPATCH_LEVEL
1863 ==========================================================================
1865 void AsicSetSlotTime(struct rt_rtmp_adapter *pAd, IN BOOLEAN bUseShortSlotTime)
1867 unsigned long SlotTime;
1870 if (pAd->CommonCfg.Channel > 14)
1871 bUseShortSlotTime = TRUE;
1873 if (bUseShortSlotTime
1874 && OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_SHORT_SLOT_INUSED))
1876 else if ((!bUseShortSlotTime)
1877 && (!OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_SHORT_SLOT_INUSED)))
1880 if (bUseShortSlotTime)
1881 OPSTATUS_SET_FLAG(pAd, fOP_STATUS_SHORT_SLOT_INUSED);
1883 OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_SHORT_SLOT_INUSED);
1885 SlotTime = (bUseShortSlotTime) ? 9 : 20;
1888 /* force using short SLOT time for FAE to demo performance when TxBurst is ON */
1889 if (((pAd->StaActive.SupportedPhyInfo.bHtEnable == FALSE)
1890 && (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_WMM_INUSED)))
1891 || ((pAd->StaActive.SupportedPhyInfo.bHtEnable == TRUE)
1892 && (pAd->CommonCfg.BACapability.field.Policy ==
1895 /* In this case, we will think it is doing Wi-Fi test */
1896 /* And we will not set to short slot when bEnableTxBurst is TRUE. */
1897 } else if (pAd->CommonCfg.bEnableTxBurst) {
1898 OPSTATUS_SET_FLAG(pAd, fOP_STATUS_SHORT_SLOT_INUSED);
1904 /* For some reasons, always set it to short slot time. */
1906 /* ToDo: Should consider capability with 11B */
1909 if (pAd->StaCfg.BssType == BSS_ADHOC) {
1910 OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_SHORT_SLOT_INUSED);
1915 RTMP_IO_READ32(pAd, BKOFF_SLOT_CFG, &RegValue);
1916 RegValue = RegValue & 0xFFFFFF00;
1918 RegValue |= SlotTime;
1920 RTMP_IO_WRITE32(pAd, BKOFF_SLOT_CFG, RegValue);
1924 ========================================================================
1926 Add Shared key information into ASIC.
1927 Update shared key, TxMic and RxMic to Asic Shared key table
1928 Update its cipherAlg to Asic Shared key Mode.
1931 ========================================================================
1933 void AsicAddSharedKeyEntry(struct rt_rtmp_adapter *pAd,
1937 u8 *pKey, u8 *pTxMic, u8 *pRxMic)
1939 unsigned long offset; /*, csr0; */
1940 SHAREDKEY_MODE_STRUC csr1;
1943 #endif /* RTMP_MAC_PCI // */
1945 DBGPRINT(RT_DEBUG_TRACE,
1946 ("AsicAddSharedKeyEntry BssIndex=%d, KeyIdx=%d\n", BssIndex,
1948 /*============================================================================================ */
1950 DBGPRINT(RT_DEBUG_TRACE,
1951 ("AsicAddSharedKeyEntry: %s key #%d\n", CipherName[CipherAlg],
1952 BssIndex * 4 + KeyIdx));
1953 DBGPRINT_RAW(RT_DEBUG_TRACE,
1954 (" Key = %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
1955 pKey[0], pKey[1], pKey[2], pKey[3], pKey[4],
1956 pKey[5], pKey[6], pKey[7], pKey[8], pKey[9],
1957 pKey[10], pKey[11], pKey[12], pKey[13], pKey[14],
1960 DBGPRINT_RAW(RT_DEBUG_TRACE,
1961 (" Rx MIC Key = %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
1962 pRxMic[0], pRxMic[1], pRxMic[2], pRxMic[3],
1963 pRxMic[4], pRxMic[5], pRxMic[6], pRxMic[7]));
1966 DBGPRINT_RAW(RT_DEBUG_TRACE,
1967 (" Tx MIC Key = %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
1968 pTxMic[0], pTxMic[1], pTxMic[2], pTxMic[3],
1969 pTxMic[4], pTxMic[5], pTxMic[6], pTxMic[7]));
1971 /*============================================================================================ */
1973 /* fill key material - key + TX MIC + RX MIC */
1977 SHARED_KEY_TABLE_BASE + (4 * BssIndex + KeyIdx) * HW_KEY_ENTRY_SIZE;
1978 for (i = 0; i < MAX_LEN_OF_SHARE_KEY; i++) {
1979 RTMP_IO_WRITE8(pAd, offset + i, pKey[i]);
1982 offset += MAX_LEN_OF_SHARE_KEY;
1984 for (i = 0; i < 8; i++) {
1985 RTMP_IO_WRITE8(pAd, offset + i, pTxMic[i]);
1991 for (i = 0; i < 8; i++) {
1992 RTMP_IO_WRITE8(pAd, offset + i, pRxMic[i]);
1995 #endif /* RTMP_MAC_PCI // */
1999 SHARED_KEY_TABLE_BASE + (4 * BssIndex +
2000 KeyIdx) * HW_KEY_ENTRY_SIZE;
2001 RTUSBMultiWrite(pAd, offset, pKey, MAX_LEN_OF_SHARE_KEY);
2003 offset += MAX_LEN_OF_SHARE_KEY;
2005 RTUSBMultiWrite(pAd, offset, pTxMic, 8);
2010 RTUSBMultiWrite(pAd, offset, pRxMic, 8);
2013 #endif /* RTMP_MAC_USB // */
2016 /* Update cipher algorithm. WSTA always use BSS0 */
2018 RTMP_IO_READ32(pAd, SHARED_KEY_MODE_BASE + 4 * (BssIndex / 2),
2020 DBGPRINT(RT_DEBUG_TRACE,
2021 ("Read: SHARED_KEY_MODE_BASE at this Bss[%d] KeyIdx[%d]= 0x%x \n",
2022 BssIndex, KeyIdx, csr1.word));
2023 if ((BssIndex % 2) == 0) {
2025 csr1.field.Bss0Key0CipherAlg = CipherAlg;
2026 else if (KeyIdx == 1)
2027 csr1.field.Bss0Key1CipherAlg = CipherAlg;
2028 else if (KeyIdx == 2)
2029 csr1.field.Bss0Key2CipherAlg = CipherAlg;
2031 csr1.field.Bss0Key3CipherAlg = CipherAlg;
2034 csr1.field.Bss1Key0CipherAlg = CipherAlg;
2035 else if (KeyIdx == 1)
2036 csr1.field.Bss1Key1CipherAlg = CipherAlg;
2037 else if (KeyIdx == 2)
2038 csr1.field.Bss1Key2CipherAlg = CipherAlg;
2040 csr1.field.Bss1Key3CipherAlg = CipherAlg;
2042 DBGPRINT(RT_DEBUG_TRACE,
2043 ("Write: SHARED_KEY_MODE_BASE at this Bss[%d] = 0x%x \n",
2044 BssIndex, csr1.word));
2045 RTMP_IO_WRITE32(pAd, SHARED_KEY_MODE_BASE + 4 * (BssIndex / 2),
2050 /* IRQL = DISPATCH_LEVEL */
2051 void AsicRemoveSharedKeyEntry(struct rt_rtmp_adapter *pAd,
2052 u8 BssIndex, u8 KeyIdx)
2054 /*unsigned long SecCsr0; */
2055 SHAREDKEY_MODE_STRUC csr1;
2057 DBGPRINT(RT_DEBUG_TRACE,
2058 ("AsicRemoveSharedKeyEntry: #%d \n", BssIndex * 4 + KeyIdx));
2060 RTMP_IO_READ32(pAd, SHARED_KEY_MODE_BASE + 4 * (BssIndex / 2),
2062 if ((BssIndex % 2) == 0) {
2064 csr1.field.Bss0Key0CipherAlg = 0;
2065 else if (KeyIdx == 1)
2066 csr1.field.Bss0Key1CipherAlg = 0;
2067 else if (KeyIdx == 2)
2068 csr1.field.Bss0Key2CipherAlg = 0;
2070 csr1.field.Bss0Key3CipherAlg = 0;
2073 csr1.field.Bss1Key0CipherAlg = 0;
2074 else if (KeyIdx == 1)
2075 csr1.field.Bss1Key1CipherAlg = 0;
2076 else if (KeyIdx == 2)
2077 csr1.field.Bss1Key2CipherAlg = 0;
2079 csr1.field.Bss1Key3CipherAlg = 0;
2081 DBGPRINT(RT_DEBUG_TRACE,
2082 ("Write: SHARED_KEY_MODE_BASE at this Bss[%d] = 0x%x \n",
2083 BssIndex, csr1.word));
2084 RTMP_IO_WRITE32(pAd, SHARED_KEY_MODE_BASE + 4 * (BssIndex / 2),
2086 ASSERT(BssIndex < 4);
2091 void AsicUpdateWCIDAttribute(struct rt_rtmp_adapter *pAd,
2095 IN BOOLEAN bUsePairewiseKeyTable)
2097 unsigned long WCIDAttri = 0, offset;
2100 /* Update WCID attribute. */
2101 /* Only TxKey could update WCID attribute. */
2103 offset = MAC_WCID_ATTRIBUTE_BASE + (WCID * HW_WCID_ATTRI_SIZE);
2105 (BssIndex << 4) | (CipherAlg << 1) | (bUsePairewiseKeyTable);
2106 RTMP_IO_WRITE32(pAd, offset, WCIDAttri);
2109 void AsicUpdateWCIDIVEIV(struct rt_rtmp_adapter *pAd,
2110 u16 WCID, unsigned long uIV, unsigned long uEIV)
2112 unsigned long offset;
2114 offset = MAC_IVEIV_TABLE_BASE + (WCID * HW_IVEIV_ENTRY_SIZE);
2116 RTMP_IO_WRITE32(pAd, offset, uIV);
2117 RTMP_IO_WRITE32(pAd, offset + 4, uEIV);
2120 void AsicUpdateRxWCIDTable(struct rt_rtmp_adapter *pAd,
2121 u16 WCID, u8 *pAddr)
2123 unsigned long offset;
2126 offset = MAC_WCID_BASE + (WCID * HW_WCID_ENTRY_SIZE);
2127 Addr = pAddr[0] + (pAddr[1] << 8) + (pAddr[2] << 16) + (pAddr[3] << 24);
2128 RTMP_IO_WRITE32(pAd, offset, Addr);
2129 Addr = pAddr[4] + (pAddr[5] << 8);
2130 RTMP_IO_WRITE32(pAd, offset + 4, Addr);
2134 ========================================================================
2136 Routine Description:
2137 Set Cipher Key, Cipher algorithm, IV/EIV to Asic
2140 pAd Pointer to our adapter
2141 WCID WCID Entry number.
2142 BssIndex BSSID index, station or none multiple BSSID support
2143 this value should be 0.
2144 KeyIdx This KeyIdx will set to IV's KeyID if bTxKey enabled
2145 pCipherKey Pointer to Cipher Key.
2146 bUsePairewiseKeyTable TRUE means saved the key in SharedKey table,
2147 otherwise PairewiseKey table
2148 bTxKey This is the transmit key if enabled.
2154 This routine will set the relative key stuff to Asic including WCID attribute,
2155 Cipher Key, Cipher algorithm and IV/EIV.
2157 IV/EIV will be update if this CipherKey is the transmission key because
2158 ASIC will base on IV's KeyID value to select Cipher Key.
2160 If bTxKey sets to FALSE, this is not the TX key, but it could be
2163 For AP mode bTxKey must be always set to TRUE.
2164 ========================================================================
2166 void AsicAddKeyEntry(struct rt_rtmp_adapter *pAd,
2170 struct rt_cipher_key *pCipherKey,
2171 IN BOOLEAN bUsePairewiseKeyTable, IN BOOLEAN bTxKey)
2173 unsigned long offset;
2174 /* unsigned long WCIDAttri = 0; */
2176 u8 *pKey = pCipherKey->Key;
2177 /* unsigned long KeyLen = pCipherKey->KeyLen; */
2178 u8 *pTxMic = pCipherKey->TxMic;
2179 u8 *pRxMic = pCipherKey->RxMic;
2180 u8 *pTxtsc = pCipherKey->TxTsc;
2181 u8 CipherAlg = pCipherKey->CipherAlg;
2182 SHAREDKEY_MODE_STRUC csr1;
2185 #endif /* RTMP_MAC_PCI // */
2187 /* ASSERT(KeyLen <= MAX_LEN_OF_PEER_KEY); */
2189 DBGPRINT(RT_DEBUG_TRACE, ("==> AsicAddKeyEntry\n"));
2191 /* 1.) decide key table offset */
2193 if (bUsePairewiseKeyTable)
2194 offset = PAIRWISE_KEY_TABLE_BASE + (WCID * HW_KEY_ENTRY_SIZE);
2197 SHARED_KEY_TABLE_BASE + (4 * BssIndex +
2198 KeyIdx) * HW_KEY_ENTRY_SIZE;
2201 /* 2.) Set Key to Asic */
2203 /*for (i = 0; i < KeyLen; i++) */
2205 for (i = 0; i < MAX_LEN_OF_PEER_KEY; i++) {
2206 RTMP_IO_WRITE8(pAd, offset + i, pKey[i]);
2208 offset += MAX_LEN_OF_PEER_KEY;
2211 /* 3.) Set MIC key if available */
2214 for (i = 0; i < 8; i++) {
2215 RTMP_IO_WRITE8(pAd, offset + i, pTxMic[i]);
2218 offset += LEN_TKIP_TXMICK;
2221 for (i = 0; i < 8; i++) {
2222 RTMP_IO_WRITE8(pAd, offset + i, pRxMic[i]);
2225 #endif /* RTMP_MAC_PCI // */
2227 RTUSBMultiWrite(pAd, offset, pKey, MAX_LEN_OF_PEER_KEY);
2228 offset += MAX_LEN_OF_PEER_KEY;
2231 /* 3.) Set MIC key if available */
2234 RTUSBMultiWrite(pAd, offset, pTxMic, 8);
2236 offset += LEN_TKIP_TXMICK;
2239 RTUSBMultiWrite(pAd, offset, pRxMic, 8);
2241 #endif /* RTMP_MAC_USB // */
2244 /* 4.) Modify IV/EIV if needs */
2245 /* This will force Asic to use this key ID by setting IV. */
2249 offset = MAC_IVEIV_TABLE_BASE + (WCID * HW_IVEIV_ENTRY_SIZE);
2253 RTMP_IO_WRITE8(pAd, offset, pTxtsc[1]);
2254 RTMP_IO_WRITE8(pAd, offset + 1, ((pTxtsc[1] | 0x20) & 0x7f));
2255 RTMP_IO_WRITE8(pAd, offset + 2, pTxtsc[0]);
2257 IV4 = (KeyIdx << 6);
2258 if ((CipherAlg == CIPHER_TKIP)
2259 || (CipherAlg == CIPHER_TKIP_NO_MIC)
2260 || (CipherAlg == CIPHER_AES))
2261 IV4 |= 0x20; /* turn on extension bit means EIV existence */
2263 RTMP_IO_WRITE8(pAd, offset + 3, IV4);
2269 for (i = 0; i < 4; i++) {
2270 RTMP_IO_WRITE8(pAd, offset + i, pTxtsc[i + 2]);
2272 #endif /* RTMP_MAC_PCI // */
2279 IV4 = (KeyIdx << 6);
2280 if ((CipherAlg == CIPHER_TKIP)
2281 || (CipherAlg == CIPHER_TKIP_NO_MIC)
2282 || (CipherAlg == CIPHER_AES))
2283 IV4 |= 0x20; /* turn on extension bit means EIV existence */
2286 pTxtsc[1] + (((pTxtsc[1] | 0x20) & 0x7f) << 8) +
2287 (pTxtsc[0] << 16) + (IV4 << 24);
2288 RTMP_IO_WRITE32(pAd, offset, tmpVal);
2294 RTMP_IO_WRITE32(pAd, offset, *(u32 *)& pCipherKey->TxTsc[2]);
2295 #endif /* RTMP_MAC_USB // */
2297 AsicUpdateWCIDAttribute(pAd, WCID, BssIndex, CipherAlg,
2298 bUsePairewiseKeyTable);
2301 if (!bUsePairewiseKeyTable) {
2303 /* Only update the shared key security mode */
2305 RTMP_IO_READ32(pAd, SHARED_KEY_MODE_BASE + 4 * (BssIndex / 2),
2307 if ((BssIndex % 2) == 0) {
2309 csr1.field.Bss0Key0CipherAlg = CipherAlg;
2310 else if (KeyIdx == 1)
2311 csr1.field.Bss0Key1CipherAlg = CipherAlg;
2312 else if (KeyIdx == 2)
2313 csr1.field.Bss0Key2CipherAlg = CipherAlg;
2315 csr1.field.Bss0Key3CipherAlg = CipherAlg;
2318 csr1.field.Bss1Key0CipherAlg = CipherAlg;
2319 else if (KeyIdx == 1)
2320 csr1.field.Bss1Key1CipherAlg = CipherAlg;
2321 else if (KeyIdx == 2)
2322 csr1.field.Bss1Key2CipherAlg = CipherAlg;
2324 csr1.field.Bss1Key3CipherAlg = CipherAlg;
2326 RTMP_IO_WRITE32(pAd, SHARED_KEY_MODE_BASE + 4 * (BssIndex / 2),
2330 DBGPRINT(RT_DEBUG_TRACE, ("<== AsicAddKeyEntry\n"));
2334 ========================================================================
2336 Add Pair-wise key material into ASIC.
2337 Update pairwise key, TxMic and RxMic to Asic Pair-wise key table
2340 ========================================================================
2342 void AsicAddPairwiseKeyEntry(struct rt_rtmp_adapter *pAd,
2344 u8 WCID, struct rt_cipher_key *pCipherKey)
2347 unsigned long offset;
2348 u8 *pKey = pCipherKey->Key;
2349 u8 *pTxMic = pCipherKey->TxMic;
2350 u8 *pRxMic = pCipherKey->RxMic;
2352 u8 CipherAlg = pCipherKey->CipherAlg;
2356 offset = PAIRWISE_KEY_TABLE_BASE + (WCID * HW_KEY_ENTRY_SIZE);
2358 for (i = 0; i < MAX_LEN_OF_PEER_KEY; i++) {
2359 RTMP_IO_WRITE8(pAd, offset + i, pKey[i]);
2361 #endif /* RTMP_MAC_PCI // */
2363 RTUSBMultiWrite(pAd, offset, &pCipherKey->Key[0], MAX_LEN_OF_PEER_KEY);
2364 #endif /* RTMP_MAC_USB // */
2365 for (i = 0; i < MAX_LEN_OF_PEER_KEY; i += 4) {
2367 RTMP_IO_READ32(pAd, offset + i, &Value);
2370 offset += MAX_LEN_OF_PEER_KEY;
2375 for (i = 0; i < 8; i++) {
2376 RTMP_IO_WRITE8(pAd, offset + i, pTxMic[i]);
2378 #endif /* RTMP_MAC_PCI // */
2380 RTUSBMultiWrite(pAd, offset, &pCipherKey->TxMic[0], 8);
2381 #endif /* RTMP_MAC_USB // */
2386 for (i = 0; i < 8; i++) {
2387 RTMP_IO_WRITE8(pAd, offset + i, pRxMic[i]);
2389 #endif /* RTMP_MAC_PCI // */
2391 RTUSBMultiWrite(pAd, offset, &pCipherKey->RxMic[0], 8);
2392 #endif /* RTMP_MAC_USB // */
2395 DBGPRINT(RT_DEBUG_TRACE,
2396 ("AsicAddPairwiseKeyEntry: WCID #%d Alg=%s\n", WCID,
2397 CipherName[CipherAlg]));
2398 DBGPRINT(RT_DEBUG_TRACE,
2399 (" Key = %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
2400 pKey[0], pKey[1], pKey[2], pKey[3], pKey[4], pKey[5],
2401 pKey[6], pKey[7], pKey[8], pKey[9], pKey[10], pKey[11],
2402 pKey[12], pKey[13], pKey[14], pKey[15]));
2404 DBGPRINT(RT_DEBUG_TRACE,
2405 (" Rx MIC Key = %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
2406 pRxMic[0], pRxMic[1], pRxMic[2], pRxMic[3],
2407 pRxMic[4], pRxMic[5], pRxMic[6], pRxMic[7]));
2410 DBGPRINT(RT_DEBUG_TRACE,
2411 (" Tx MIC Key = %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
2412 pTxMic[0], pTxMic[1], pTxMic[2], pTxMic[3],
2413 pTxMic[4], pTxMic[5], pTxMic[6], pTxMic[7]));
2418 ========================================================================
2420 Remove Pair-wise key material from ASIC.
2423 ========================================================================
2425 void AsicRemovePairwiseKeyEntry(struct rt_rtmp_adapter *pAd,
2428 unsigned long WCIDAttri;
2431 /* re-set the entry's WCID attribute as OPEN-NONE. */
2432 offset = MAC_WCID_ATTRIBUTE_BASE + (Wcid * HW_WCID_ATTRI_SIZE);
2433 WCIDAttri = (BssIdx << 4) | PAIRWISEKEYTABLE;
2434 RTMP_IO_WRITE32(pAd, offset, WCIDAttri);
2437 BOOLEAN AsicSendCommandToMcu(struct rt_rtmp_adapter *pAd,
2439 u8 Token, u8 Arg0, u8 Arg1)
2442 if (pAd->chipOps.sendCommandToMcu)
2443 pAd->chipOps.sendCommandToMcu(pAd, Command, Token, Arg0, Arg1);
2448 void AsicSetRxAnt(struct rt_rtmp_adapter *pAd, u8 Ant)
2451 /* RT3572 ATE need not to do this. */
2452 RT30xxSetRxAnt(pAd, Ant);
2453 #endif /* RT30xx // */
2456 void AsicTurnOffRFClk(struct rt_rtmp_adapter *pAd, u8 Channel)
2458 if (pAd->chipOps.AsicRfTurnOff) {
2459 pAd->chipOps.AsicRfTurnOff(pAd);
2461 /* RF R2 bit 18 = 0 */
2462 u32 R1 = 0, R2 = 0, R3 = 0;
2464 struct rt_rtmp_rf_regs *RFRegTable;
2466 RFRegTable = RF2850RegTable;
2468 switch (pAd->RfIcType) {
2474 for (index = 0; index < NUM_OF_2850_CHNL; index++) {
2475 if (Channel == RFRegTable[index].Channel) {
2476 R1 = RFRegTable[index].R1 & 0xffffdfff;
2477 R2 = RFRegTable[index].R2 & 0xfffbffff;
2478 R3 = RFRegTable[index].R3 & 0xfff3ffff;
2480 RTMP_RF_IO_WRITE32(pAd, R1);
2481 RTMP_RF_IO_WRITE32(pAd, R2);
2483 /* Program R1b13 to 1, R3/b18,19 to 0, R2b18 to 0. */
2484 /* Set RF R2 bit18=0, R3 bit[18:19]=0 */
2485 /*if (pAd->StaCfg.bRadio == FALSE) */
2487 RTMP_RF_IO_WRITE32(pAd, R3);
2489 DBGPRINT(RT_DEBUG_TRACE,
2490 ("AsicTurnOffRFClk#%d(RF=%d, ) , R2=0x%08x, R3 = 0x%08x \n",
2495 DBGPRINT(RT_DEBUG_TRACE,
2496 ("AsicTurnOffRFClk#%d(RF=%d, ) , R2=0x%08x \n",
2498 pAd->RfIcType, R2));
2510 void AsicTurnOnRFClk(struct rt_rtmp_adapter *pAd, u8 Channel)
2512 /* RF R2 bit 18 = 0 */
2513 u32 R1 = 0, R2 = 0, R3 = 0;
2515 struct rt_rtmp_rf_regs *RFRegTable;
2517 #ifdef PCIE_PS_SUPPORT
2518 /* The RF programming sequence is difference between 3xxx and 2xxx */
2519 if ((IS_RT3090(pAd) || IS_RT3572(pAd) || IS_RT3390(pAd))) {
2522 #endif /* PCIE_PS_SUPPORT // */
2524 RFRegTable = RF2850RegTable;
2526 switch (pAd->RfIcType) {
2532 for (index = 0; index < NUM_OF_2850_CHNL; index++) {
2533 if (Channel == RFRegTable[index].Channel) {
2534 R3 = pAd->LatchRfRegs.R3;
2537 RTMP_RF_IO_WRITE32(pAd, R3);
2539 R1 = RFRegTable[index].R1;
2540 RTMP_RF_IO_WRITE32(pAd, R1);
2542 R2 = RFRegTable[index].R2;
2543 if (pAd->Antenna.field.TxPath == 1) {
2544 R2 |= 0x4000; /* If TXpath is 1, bit 14 = 1; */
2547 if (pAd->Antenna.field.RxPath == 2) {
2548 R2 |= 0x40; /* write 1 to off Rxpath. */
2549 } else if (pAd->Antenna.field.RxPath == 1) {
2550 R2 |= 0x20040; /* write 1 to off RxPath */
2552 RTMP_RF_IO_WRITE32(pAd, R2);
2563 DBGPRINT(RT_DEBUG_TRACE, ("AsicTurnOnRFClk#%d(RF=%d, ) , R2=0x%08x\n",
2564 Channel, pAd->RfIcType, R2));