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 Miniport generic portion header file
35 -------- ---------- ----------------------------------------------
36 Paul Lin 2002-08-01 created
37 John Chang 2004-08-20 RT2561/2661 use scatter-gather scheme
38 Jan Lee 2006-09-15 RT2860. Change for 802.11n , EEPROM, Led, BA, HT.
40 #include "../rt_config.h"
44 #include <linux/bitrev.h>
47 #include "../../rt2870/common/firmware.h"
51 #include "../../rt3070/firmware.h"
54 UCHAR BIT8
[] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80};
55 ULONG BIT32
[] = {0x00000001, 0x00000002, 0x00000004, 0x00000008,
56 0x00000010, 0x00000020, 0x00000040, 0x00000080,
57 0x00000100, 0x00000200, 0x00000400, 0x00000800,
58 0x00001000, 0x00002000, 0x00004000, 0x00008000,
59 0x00010000, 0x00020000, 0x00040000, 0x00080000,
60 0x00100000, 0x00200000, 0x00400000, 0x00800000,
61 0x01000000, 0x02000000, 0x04000000, 0x08000000,
62 0x10000000, 0x20000000, 0x40000000, 0x80000000};
64 char* CipherName
[] = {"none","wep64","wep128","TKIP","AES","CKIP64","CKIP128"};
66 const unsigned short ccitt_16Table
[] = {
67 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50A5, 0x60C6, 0x70E7,
68 0x8108, 0x9129, 0xA14A, 0xB16B, 0xC18C, 0xD1AD, 0xE1CE, 0xF1EF,
69 0x1231, 0x0210, 0x3273, 0x2252, 0x52B5, 0x4294, 0x72F7, 0x62D6,
70 0x9339, 0x8318, 0xB37B, 0xA35A, 0xD3BD, 0xC39C, 0xF3FF, 0xE3DE,
71 0x2462, 0x3443, 0x0420, 0x1401, 0x64E6, 0x74C7, 0x44A4, 0x5485,
72 0xA56A, 0xB54B, 0x8528, 0x9509, 0xE5EE, 0xF5CF, 0xC5AC, 0xD58D,
73 0x3653, 0x2672, 0x1611, 0x0630, 0x76D7, 0x66F6, 0x5695, 0x46B4,
74 0xB75B, 0xA77A, 0x9719, 0x8738, 0xF7DF, 0xE7FE, 0xD79D, 0xC7BC,
75 0x48C4, 0x58E5, 0x6886, 0x78A7, 0x0840, 0x1861, 0x2802, 0x3823,
76 0xC9CC, 0xD9ED, 0xE98E, 0xF9AF, 0x8948, 0x9969, 0xA90A, 0xB92B,
77 0x5AF5, 0x4AD4, 0x7AB7, 0x6A96, 0x1A71, 0x0A50, 0x3A33, 0x2A12,
78 0xDBFD, 0xCBDC, 0xFBBF, 0xEB9E, 0x9B79, 0x8B58, 0xBB3B, 0xAB1A,
79 0x6CA6, 0x7C87, 0x4CE4, 0x5CC5, 0x2C22, 0x3C03, 0x0C60, 0x1C41,
80 0xEDAE, 0xFD8F, 0xCDEC, 0xDDCD, 0xAD2A, 0xBD0B, 0x8D68, 0x9D49,
81 0x7E97, 0x6EB6, 0x5ED5, 0x4EF4, 0x3E13, 0x2E32, 0x1E51, 0x0E70,
82 0xFF9F, 0xEFBE, 0xDFDD, 0xCFFC, 0xBF1B, 0xAF3A, 0x9F59, 0x8F78,
83 0x9188, 0x81A9, 0xB1CA, 0xA1EB, 0xD10C, 0xC12D, 0xF14E, 0xE16F,
84 0x1080, 0x00A1, 0x30C2, 0x20E3, 0x5004, 0x4025, 0x7046, 0x6067,
85 0x83B9, 0x9398, 0xA3FB, 0xB3DA, 0xC33D, 0xD31C, 0xE37F, 0xF35E,
86 0x02B1, 0x1290, 0x22F3, 0x32D2, 0x4235, 0x5214, 0x6277, 0x7256,
87 0xB5EA, 0xA5CB, 0x95A8, 0x8589, 0xF56E, 0xE54F, 0xD52C, 0xC50D,
88 0x34E2, 0x24C3, 0x14A0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405,
89 0xA7DB, 0xB7FA, 0x8799, 0x97B8, 0xE75F, 0xF77E, 0xC71D, 0xD73C,
90 0x26D3, 0x36F2, 0x0691, 0x16B0, 0x6657, 0x7676, 0x4615, 0x5634,
91 0xD94C, 0xC96D, 0xF90E, 0xE92F, 0x99C8, 0x89E9, 0xB98A, 0xA9AB,
92 0x5844, 0x4865, 0x7806, 0x6827, 0x18C0, 0x08E1, 0x3882, 0x28A3,
93 0xCB7D, 0xDB5C, 0xEB3F, 0xFB1E, 0x8BF9, 0x9BD8, 0xABBB, 0xBB9A,
94 0x4A75, 0x5A54, 0x6A37, 0x7A16, 0x0AF1, 0x1AD0, 0x2AB3, 0x3A92,
95 0xFD2E, 0xED0F, 0xDD6C, 0xCD4D, 0xBDAA, 0xAD8B, 0x9DE8, 0x8DC9,
96 0x7C26, 0x6C07, 0x5C64, 0x4C45, 0x3CA2, 0x2C83, 0x1CE0, 0x0CC1,
97 0xEF1F, 0xFF3E, 0xCF5D, 0xDF7C, 0xAF9B, 0xBFBA, 0x8FD9, 0x9FF8,
98 0x6E17, 0x7E36, 0x4E55, 0x5E74, 0x2E93, 0x3EB2, 0x0ED1, 0x1EF0
100 #define ByteCRC16(v, crc) \
101 (unsigned short)((crc << 8) ^ ccitt_16Table[((crc >> 8) ^ (v)) & 255])
104 unsigned char BitReverse(unsigned char x
)
107 unsigned char Temp
=0;
110 if(x
& 0x80) Temp
|= 0x80;
120 // BBP register initialization set
122 REG_PAIR BBPRegTable
[] = {
123 {BBP_R65
, 0x2C}, // fix rssi issue
124 {BBP_R66
, 0x38}, // Also set this default value to pAd->BbpTuning.R66CurrentValue at initial
126 {BBP_R70
, 0xa}, // BBP_R70 will change to 0x8 in ApStartUp and LinkUp for rt2860C, otherwise value is 0xa
131 {BBP_R84
, 0x99}, // 0x19 is for rt2860E and after. This is for extension channel overlapping IOT. 0x99 is for rt2860D and before
132 {BBP_R86
, 0x00}, // middle range issue, Rory @2008-01-28
133 {BBP_R91
, 0x04}, // middle range issue, Rory @2008-01-28
134 {BBP_R92
, 0x00}, // middle range issue, Rory @2008-01-28
135 {BBP_R103
, 0x00}, // near range high-power issue, requested from Gary @2008-0528
136 {BBP_R105
, 0x05}, // 0x05 is for rt2860E to turn on FEQ control. It is safe for rt2860D and before, because Bit 7:2 are reserved in rt2860D and before.
138 #define NUM_BBP_REG_PARMS (sizeof(BBPRegTable) / sizeof(REG_PAIR))
141 // RF register initialization set
144 REG_PAIR RT30xx_RFRegTable
[] = {
173 #define NUM_RF_REG_PARMS (sizeof(RT30xx_RFRegTable) / sizeof(REG_PAIR))
177 // ASIC register initialization sets
180 RTMP_REG_PAIR MACRegTable
[] = {
181 #if defined(HW_BEACON_OFFSET) && (HW_BEACON_OFFSET == 0x200)
182 {BCN_OFFSET0
, 0xf8f0e8e0}, /* 0x3800(e0), 0x3A00(e8), 0x3C00(f0), 0x3E00(f8), 512B for each beacon */
183 {BCN_OFFSET1
, 0x6f77d0c8}, /* 0x3200(c8), 0x3400(d0), 0x1DC0(77), 0x1BC0(6f), 512B for each beacon */
184 #elif defined(HW_BEACON_OFFSET) && (HW_BEACON_OFFSET == 0x100)
185 {BCN_OFFSET0
, 0xece8e4e0}, /* 0x3800, 0x3A00, 0x3C00, 0x3E00, 512B for each beacon */
186 {BCN_OFFSET1
, 0xfcf8f4f0}, /* 0x3800, 0x3A00, 0x3C00, 0x3E00, 512B for each beacon */
188 #error You must re-calculate new value for BCN_OFFSET0 & BCN_OFFSET1 in MACRegTable[]!!!
189 #endif // HW_BEACON_OFFSET //
191 {LEGACY_BASIC_RATE
, 0x0000013f}, // Basic rate set bitmap
192 {HT_BASIC_RATE
, 0x00008003}, // Basic HT rate set , 20M, MCS=3, MM. Format is the same as in TXWI.
193 {MAC_SYS_CTRL
, 0x00}, // 0x1004, , default Disable RX
194 {RX_FILTR_CFG
, 0x17f97}, //0x1400 , RX filter control,
195 {BKOFF_SLOT_CFG
, 0x209}, // default set short slot time, CC_DELAY_TIME should be 2
196 {TX_SW_CFG0
, 0x0}, // Gary,2008-05-21 for CWC test
197 {TX_SW_CFG1
, 0x80606}, // Gary,2006-08-23
198 {TX_LINK_CFG
, 0x1020}, // Gary,2006-08-23
199 {TX_TIMEOUT_CFG
, 0x000a2090}, // CCK has some problem. So increase timieout value. 2006-10-09// MArvek RT , Modify for 2860E ,2007-08-01
200 {MAX_LEN_CFG
, MAX_AGGREGATION_SIZE
| 0x00001000}, // 0x3018, MAX frame length. Max PSDU = 16kbytes.
201 {LED_CFG
, 0x7f031e46}, // Gary, 2006-08-23
202 {PBF_MAX_PCNT
, 0x1F3FBF9F}, //0x1F3f7f9f}, //Jan, 2006/04/20
203 {TX_RTY_CFG
, 0x47d01f0f}, // Jan, 2006/11/16, Set TxWI->ACK =0 in Probe Rsp Modify for 2860E ,2007-08-03
204 {AUTO_RSP_CFG
, 0x00000013}, // Initial Auto_Responder, because QA will turn off Auto-Responder
205 {CCK_PROT_CFG
, 0x05740003 /*0x01740003*/}, // Initial Auto_Responder, because QA will turn off Auto-Responder. And RTS threshold is enabled.
206 {OFDM_PROT_CFG
, 0x05740003 /*0x01740003*/}, // Initial Auto_Responder, because QA will turn off Auto-Responder. And RTS threshold is enabled.
207 //PS packets use Tx1Q (for HCCA) when dequeue from PS unicast queue (WiFi WPA2 MA9_DT1 for Marvell B STA)
209 {PBF_CFG
, 0xf40006}, // Only enable Queue 2
210 {MM40_PROT_CFG
, 0x3F44084}, // Initial Auto_Responder, because QA will turn off Auto-Responder
211 {WPDMA_GLO_CFG
, 0x00000030},
213 {GF20_PROT_CFG
, 0x01744004}, // set 19:18 --> Short NAV for MIMO PS
214 {GF40_PROT_CFG
, 0x03F44084},
215 {MM20_PROT_CFG
, 0x01744004},
217 {MM40_PROT_CFG
, 0x03F54084},
219 {TXOP_CTRL_CFG
, 0x0000583f, /*0x0000243f*/ /*0x000024bf*/}, //Extension channel backoff.
220 {TX_RTS_CFG
, 0x00092b20},
221 {EXP_ACK_TIME
, 0x002400ca}, // default value
222 {TXOP_HLDR_ET
, 0x00000002},
224 /* Jerry comments 2008/01/16: we use SIFS = 10us in CCK defaultly, but it seems that 10us
225 is too small for INTEL 2200bg card, so in MBSS mode, the delta time between beacon0
226 and beacon1 is SIFS (10us), so if INTEL 2200bg card connects to BSS0, the ping
227 will always lost. So we change the SIFS of CCK from 10us to 16us. */
228 {XIFS_TIME_CFG
, 0x33a41010},
229 {PWR_PIN_CFG
, 0x00000003}, // patch for 2880-E
232 RTMP_REG_PAIR STAMACRegTable
[] = {
233 {WMM_AIFSN_CFG
, 0x00002273},
234 {WMM_CWMIN_CFG
, 0x00002344},
235 {WMM_CWMAX_CFG
, 0x000034aa},
238 #define NUM_MAC_REG_PARMS (sizeof(MACRegTable) / sizeof(RTMP_REG_PAIR))
239 #define NUM_STA_MAC_REG_PARMS (sizeof(STAMACRegTable) / sizeof(RTMP_REG_PAIR))
243 // RT2870 Firmware Spec only used 1 oct for version expression
245 #define FIRMWARE_MINOR_VERSION 7
249 // New 8k byte firmware size for RT3071/RT3072
250 #define FIRMWAREIMAGE_MAX_LENGTH 0x2000
251 #define FIRMWAREIMAGE_LENGTH (sizeof (FirmwareImage) / sizeof(UCHAR))
252 #define FIRMWARE_MAJOR_VERSION 0
254 #define FIRMWAREIMAGEV1_LENGTH 0x1000
255 #define FIRMWAREIMAGEV2_LENGTH 0x1000
258 #define FIRMWARE_MINOR_VERSION 2
263 ========================================================================
266 Allocate RTMP_ADAPTER data block and do some initialization
269 Adapter Pointer to our adapter
279 ========================================================================
281 NDIS_STATUS
RTMPAllocAdapterBlock(
283 OUT PRTMP_ADAPTER
*ppAdapter
)
288 UCHAR
*pBeaconBuf
= NULL
;
290 DBGPRINT(RT_DEBUG_TRACE
, ("--> RTMPAllocAdapterBlock\n"));
296 // Allocate RTMP_ADAPTER memory block
297 pBeaconBuf
= kmalloc(MAX_BEACON_SIZE
, MEM_ALLOC_FLAG
);
298 if (pBeaconBuf
== NULL
)
300 Status
= NDIS_STATUS_FAILURE
;
301 DBGPRINT_ERR(("Failed to allocate memory - BeaconBuf!\n"));
305 Status
= AdapterBlockAllocateMemory(handle
, (PVOID
*)&pAd
);
306 if (Status
!= NDIS_STATUS_SUCCESS
)
308 DBGPRINT_ERR(("Failed to allocate memory - ADAPTER\n"));
311 pAd
->BeaconBuf
= pBeaconBuf
;
312 printk("\n\n=== pAd = %p, size = %d ===\n\n", pAd
, (UINT32
)sizeof(RTMP_ADAPTER
));
316 NdisAllocateSpinLock(&pAd
->MgmtRingLock
);
318 NdisAllocateSpinLock(&pAd
->RxRingLock
);
321 for (index
=0 ; index
< NUM_OF_TX_RING
; index
++)
323 NdisAllocateSpinLock(&pAd
->TxSwQueueLock
[index
]);
324 NdisAllocateSpinLock(&pAd
->DeQueueLock
[index
]);
325 pAd
->DeQueueRunning
[index
] = FALSE
;
328 NdisAllocateSpinLock(&pAd
->irq_lock
);
332 if ((Status
!= NDIS_STATUS_SUCCESS
) && (pBeaconBuf
))
337 DBGPRINT_S(Status
, ("<-- RTMPAllocAdapterBlock, Status=%x\n", Status
));
342 ========================================================================
345 Read initial Tx power per MCS and BW from EEPROM
348 Adapter Pointer to our adapter
357 ========================================================================
359 VOID
RTMPReadTxPwrPerRate(
360 IN PRTMP_ADAPTER pAd
)
362 ULONG data
, Adata
, Gdata
;
363 USHORT i
, value
, value2
;
364 INT Apwrdelta
, Gpwrdelta
;
366 BOOLEAN bValid
, bApwrdeltaMinus
= TRUE
, bGpwrdeltaMinus
= TRUE
;
369 // Get power delta for 20MHz and 40MHz.
371 DBGPRINT(RT_DEBUG_TRACE
, ("Txpower per Rate\n"));
372 RT28xx_EEPROM_READ16(pAd
, EEPROM_TXPOWER_DELTA
, value2
);
376 if ((value2
& 0xff) != 0xff)
379 Gpwrdelta
= (value2
&0xf);
382 bGpwrdeltaMinus
= FALSE
;
384 bGpwrdeltaMinus
= TRUE
;
386 if ((value2
& 0xff00) != 0xff00)
388 if ((value2
& 0x8000))
389 Apwrdelta
= ((value2
&0xf00)>>8);
391 if ((value2
& 0x4000))
392 bApwrdeltaMinus
= FALSE
;
394 bApwrdeltaMinus
= TRUE
;
396 DBGPRINT(RT_DEBUG_TRACE
, ("Gpwrdelta = %x, Apwrdelta = %x .\n", Gpwrdelta
, Apwrdelta
));
399 // Get Txpower per MCS for 20MHz in 2.4G.
403 RT28xx_EEPROM_READ16(pAd
, EEPROM_TXPOWER_BYRATE_20MHZ_2_4G
+ i
*4, value
);
405 if (bApwrdeltaMinus
== FALSE
)
407 t1
= (value
&0xf)+(Apwrdelta
);
410 t2
= ((value
&0xf0)>>4)+(Apwrdelta
);
413 t3
= ((value
&0xf00)>>8)+(Apwrdelta
);
416 t4
= ((value
&0xf000)>>12)+(Apwrdelta
);
422 if ((value
&0xf) > Apwrdelta
)
423 t1
= (value
&0xf)-(Apwrdelta
);
426 if (((value
&0xf0)>>4) > Apwrdelta
)
427 t2
= ((value
&0xf0)>>4)-(Apwrdelta
);
430 if (((value
&0xf00)>>8) > Apwrdelta
)
431 t3
= ((value
&0xf00)>>8)-(Apwrdelta
);
434 if (((value
&0xf000)>>12) > Apwrdelta
)
435 t4
= ((value
&0xf000)>>12)-(Apwrdelta
);
439 Adata
= t1
+ (t2
<<4) + (t3
<<8) + (t4
<<12);
440 if (bGpwrdeltaMinus
== FALSE
)
442 t1
= (value
&0xf)+(Gpwrdelta
);
445 t2
= ((value
&0xf0)>>4)+(Gpwrdelta
);
448 t3
= ((value
&0xf00)>>8)+(Gpwrdelta
);
451 t4
= ((value
&0xf000)>>12)+(Gpwrdelta
);
457 if ((value
&0xf) > Gpwrdelta
)
458 t1
= (value
&0xf)-(Gpwrdelta
);
461 if (((value
&0xf0)>>4) > Gpwrdelta
)
462 t2
= ((value
&0xf0)>>4)-(Gpwrdelta
);
465 if (((value
&0xf00)>>8) > Gpwrdelta
)
466 t3
= ((value
&0xf00)>>8)-(Gpwrdelta
);
469 if (((value
&0xf000)>>12) > Gpwrdelta
)
470 t4
= ((value
&0xf000)>>12)-(Gpwrdelta
);
474 Gdata
= t1
+ (t2
<<4) + (t3
<<8) + (t4
<<12);
476 RT28xx_EEPROM_READ16(pAd
, EEPROM_TXPOWER_BYRATE_20MHZ_2_4G
+ i
*4 + 2, value
);
477 if (bApwrdeltaMinus
== FALSE
)
479 t1
= (value
&0xf)+(Apwrdelta
);
482 t2
= ((value
&0xf0)>>4)+(Apwrdelta
);
485 t3
= ((value
&0xf00)>>8)+(Apwrdelta
);
488 t4
= ((value
&0xf000)>>12)+(Apwrdelta
);
494 if ((value
&0xf) > Apwrdelta
)
495 t1
= (value
&0xf)-(Apwrdelta
);
498 if (((value
&0xf0)>>4) > Apwrdelta
)
499 t2
= ((value
&0xf0)>>4)-(Apwrdelta
);
502 if (((value
&0xf00)>>8) > Apwrdelta
)
503 t3
= ((value
&0xf00)>>8)-(Apwrdelta
);
506 if (((value
&0xf000)>>12) > Apwrdelta
)
507 t4
= ((value
&0xf000)>>12)-(Apwrdelta
);
511 Adata
|= ((t1
<<16) + (t2
<<20) + (t3
<<24) + (t4
<<28));
512 if (bGpwrdeltaMinus
== FALSE
)
514 t1
= (value
&0xf)+(Gpwrdelta
);
517 t2
= ((value
&0xf0)>>4)+(Gpwrdelta
);
520 t3
= ((value
&0xf00)>>8)+(Gpwrdelta
);
523 t4
= ((value
&0xf000)>>12)+(Gpwrdelta
);
529 if ((value
&0xf) > Gpwrdelta
)
530 t1
= (value
&0xf)-(Gpwrdelta
);
533 if (((value
&0xf0)>>4) > Gpwrdelta
)
534 t2
= ((value
&0xf0)>>4)-(Gpwrdelta
);
537 if (((value
&0xf00)>>8) > Gpwrdelta
)
538 t3
= ((value
&0xf00)>>8)-(Gpwrdelta
);
541 if (((value
&0xf000)>>12) > Gpwrdelta
)
542 t4
= ((value
&0xf000)>>12)-(Gpwrdelta
);
546 Gdata
|= ((t1
<<16) + (t2
<<20) + (t3
<<24) + (t4
<<28));
549 pAd
->Tx20MPwrCfgABand
[i
] = pAd
->Tx40MPwrCfgABand
[i
] = Adata
;
550 pAd
->Tx20MPwrCfgGBand
[i
] = pAd
->Tx40MPwrCfgGBand
[i
] = Gdata
;
552 if (data
!= 0xffffffff)
553 RTMP_IO_WRITE32(pAd
, TX_PWR_CFG_0
+ i
*4, data
);
554 DBGPRINT_RAW(RT_DEBUG_TRACE
, ("20MHz BW, 2.4G band-%lx, Adata = %lx, Gdata = %lx \n", data
, Adata
, Gdata
));
558 // Check this block is valid for 40MHz in 2.4G. If invalid, use parameter for 20MHz in 2.4G
563 RT28xx_EEPROM_READ16(pAd
, EEPROM_TXPOWER_BYRATE_40MHZ_2_4G
+ 2 + i
*2, value
);
564 if (((value
& 0x00FF) == 0x00FF) || ((value
& 0xFF00) == 0xFF00))
572 // Get Txpower per MCS for 40MHz in 2.4G.
578 RT28xx_EEPROM_READ16(pAd
, EEPROM_TXPOWER_BYRATE_40MHZ_2_4G
+ i
*4, value
);
579 if (bGpwrdeltaMinus
== FALSE
)
581 t1
= (value
&0xf)+(Gpwrdelta
);
584 t2
= ((value
&0xf0)>>4)+(Gpwrdelta
);
587 t3
= ((value
&0xf00)>>8)+(Gpwrdelta
);
590 t4
= ((value
&0xf000)>>12)+(Gpwrdelta
);
596 if ((value
&0xf) > Gpwrdelta
)
597 t1
= (value
&0xf)-(Gpwrdelta
);
600 if (((value
&0xf0)>>4) > Gpwrdelta
)
601 t2
= ((value
&0xf0)>>4)-(Gpwrdelta
);
604 if (((value
&0xf00)>>8) > Gpwrdelta
)
605 t3
= ((value
&0xf00)>>8)-(Gpwrdelta
);
608 if (((value
&0xf000)>>12) > Gpwrdelta
)
609 t4
= ((value
&0xf000)>>12)-(Gpwrdelta
);
613 Gdata
= t1
+ (t2
<<4) + (t3
<<8) + (t4
<<12);
615 RT28xx_EEPROM_READ16(pAd
, EEPROM_TXPOWER_BYRATE_40MHZ_2_4G
+ i
*4 + 2, value
);
616 if (bGpwrdeltaMinus
== FALSE
)
618 t1
= (value
&0xf)+(Gpwrdelta
);
621 t2
= ((value
&0xf0)>>4)+(Gpwrdelta
);
624 t3
= ((value
&0xf00)>>8)+(Gpwrdelta
);
627 t4
= ((value
&0xf000)>>12)+(Gpwrdelta
);
633 if ((value
&0xf) > Gpwrdelta
)
634 t1
= (value
&0xf)-(Gpwrdelta
);
637 if (((value
&0xf0)>>4) > Gpwrdelta
)
638 t2
= ((value
&0xf0)>>4)-(Gpwrdelta
);
641 if (((value
&0xf00)>>8) > Gpwrdelta
)
642 t3
= ((value
&0xf00)>>8)-(Gpwrdelta
);
645 if (((value
&0xf000)>>12) > Gpwrdelta
)
646 t4
= ((value
&0xf000)>>12)-(Gpwrdelta
);
650 Gdata
|= ((t1
<<16) + (t2
<<20) + (t3
<<24) + (t4
<<28));
653 pAd
->Tx40MPwrCfgGBand
[i
+1] = (pAd
->Tx40MPwrCfgGBand
[i
+1] & 0x0000FFFF) | (Gdata
& 0xFFFF0000);
655 pAd
->Tx40MPwrCfgGBand
[i
+1] = Gdata
;
657 DBGPRINT_RAW(RT_DEBUG_TRACE
, ("40MHz BW, 2.4G band, Gdata = %lx \n", Gdata
));
662 // Check this block is valid for 20MHz in 5G. If invalid, use parameter for 20MHz in 2.4G
667 RT28xx_EEPROM_READ16(pAd
, EEPROM_TXPOWER_BYRATE_20MHZ_5G
+ 2 + i
*2, value
);
668 if (((value
& 0x00FF) == 0x00FF) || ((value
& 0xFF00) == 0xFF00))
676 // Get Txpower per MCS for 20MHz in 5G.
682 RT28xx_EEPROM_READ16(pAd
, EEPROM_TXPOWER_BYRATE_20MHZ_5G
+ i
*4, value
);
683 if (bApwrdeltaMinus
== FALSE
)
685 t1
= (value
&0xf)+(Apwrdelta
);
688 t2
= ((value
&0xf0)>>4)+(Apwrdelta
);
691 t3
= ((value
&0xf00)>>8)+(Apwrdelta
);
694 t4
= ((value
&0xf000)>>12)+(Apwrdelta
);
700 if ((value
&0xf) > Apwrdelta
)
701 t1
= (value
&0xf)-(Apwrdelta
);
704 if (((value
&0xf0)>>4) > Apwrdelta
)
705 t2
= ((value
&0xf0)>>4)-(Apwrdelta
);
708 if (((value
&0xf00)>>8) > Apwrdelta
)
709 t3
= ((value
&0xf00)>>8)-(Apwrdelta
);
712 if (((value
&0xf000)>>12) > Apwrdelta
)
713 t4
= ((value
&0xf000)>>12)-(Apwrdelta
);
717 Adata
= t1
+ (t2
<<4) + (t3
<<8) + (t4
<<12);
719 RT28xx_EEPROM_READ16(pAd
, EEPROM_TXPOWER_BYRATE_20MHZ_5G
+ i
*4 + 2, value
);
720 if (bApwrdeltaMinus
== FALSE
)
722 t1
= (value
&0xf)+(Apwrdelta
);
725 t2
= ((value
&0xf0)>>4)+(Apwrdelta
);
728 t3
= ((value
&0xf00)>>8)+(Apwrdelta
);
731 t4
= ((value
&0xf000)>>12)+(Apwrdelta
);
737 if ((value
&0xf) > Apwrdelta
)
738 t1
= (value
&0xf)-(Apwrdelta
);
741 if (((value
&0xf0)>>4) > Apwrdelta
)
742 t2
= ((value
&0xf0)>>4)-(Apwrdelta
);
745 if (((value
&0xf00)>>8) > Apwrdelta
)
746 t3
= ((value
&0xf00)>>8)-(Apwrdelta
);
749 if (((value
&0xf000)>>12) > Apwrdelta
)
750 t4
= ((value
&0xf000)>>12)-(Apwrdelta
);
754 Adata
|= ((t1
<<16) + (t2
<<20) + (t3
<<24) + (t4
<<28));
757 pAd
->Tx20MPwrCfgABand
[i
] = (pAd
->Tx20MPwrCfgABand
[i
] & 0x0000FFFF) | (Adata
& 0xFFFF0000);
759 pAd
->Tx20MPwrCfgABand
[i
] = Adata
;
761 DBGPRINT_RAW(RT_DEBUG_TRACE
, ("20MHz BW, 5GHz band, Adata = %lx \n", Adata
));
766 // Check this block is valid for 40MHz in 5G. If invalid, use parameter for 20MHz in 2.4G
771 RT28xx_EEPROM_READ16(pAd
, EEPROM_TXPOWER_BYRATE_40MHZ_5G
+ 2 + i
*2, value
);
772 if (((value
& 0x00FF) == 0x00FF) || ((value
& 0xFF00) == 0xFF00))
780 // Get Txpower per MCS for 40MHz in 5G.
786 RT28xx_EEPROM_READ16(pAd
, EEPROM_TXPOWER_BYRATE_40MHZ_5G
+ i
*4, value
);
787 if (bApwrdeltaMinus
== FALSE
)
789 t1
= (value
&0xf)+(Apwrdelta
);
792 t2
= ((value
&0xf0)>>4)+(Apwrdelta
);
795 t3
= ((value
&0xf00)>>8)+(Apwrdelta
);
798 t4
= ((value
&0xf000)>>12)+(Apwrdelta
);
804 if ((value
&0xf) > Apwrdelta
)
805 t1
= (value
&0xf)-(Apwrdelta
);
808 if (((value
&0xf0)>>4) > Apwrdelta
)
809 t2
= ((value
&0xf0)>>4)-(Apwrdelta
);
812 if (((value
&0xf00)>>8) > Apwrdelta
)
813 t3
= ((value
&0xf00)>>8)-(Apwrdelta
);
816 if (((value
&0xf000)>>12) > Apwrdelta
)
817 t4
= ((value
&0xf000)>>12)-(Apwrdelta
);
821 Adata
= t1
+ (t2
<<4) + (t3
<<8) + (t4
<<12);
823 RT28xx_EEPROM_READ16(pAd
, EEPROM_TXPOWER_BYRATE_40MHZ_5G
+ i
*4 + 2, value
);
824 if (bApwrdeltaMinus
== FALSE
)
826 t1
= (value
&0xf)+(Apwrdelta
);
829 t2
= ((value
&0xf0)>>4)+(Apwrdelta
);
832 t3
= ((value
&0xf00)>>8)+(Apwrdelta
);
835 t4
= ((value
&0xf000)>>12)+(Apwrdelta
);
841 if ((value
&0xf) > Apwrdelta
)
842 t1
= (value
&0xf)-(Apwrdelta
);
845 if (((value
&0xf0)>>4) > Apwrdelta
)
846 t2
= ((value
&0xf0)>>4)-(Apwrdelta
);
849 if (((value
&0xf00)>>8) > Apwrdelta
)
850 t3
= ((value
&0xf00)>>8)-(Apwrdelta
);
853 if (((value
&0xf000)>>12) > Apwrdelta
)
854 t4
= ((value
&0xf000)>>12)-(Apwrdelta
);
858 Adata
|= ((t1
<<16) + (t2
<<20) + (t3
<<24) + (t4
<<28));
861 pAd
->Tx40MPwrCfgABand
[i
+1] = (pAd
->Tx40MPwrCfgABand
[i
+1] & 0x0000FFFF) | (Adata
& 0xFFFF0000);
863 pAd
->Tx40MPwrCfgABand
[i
+1] = Adata
;
865 DBGPRINT_RAW(RT_DEBUG_TRACE
, ("40MHz BW, 5GHz band, Adata = %lx \n", Adata
));
872 ========================================================================
875 Read initial channel power parameters from EEPROM
878 Adapter Pointer to our adapter
887 ========================================================================
889 VOID
RTMPReadChannelPwr(
890 IN PRTMP_ADAPTER pAd
)
893 EEPROM_TX_PWR_STRUC Power
;
894 EEPROM_TX_PWR_STRUC Power2
;
896 // Read Tx power value for all channels
897 // Value from 1 - 0x7f. Default value is 24.
898 // Power value : 2.4G 0x00 (0) ~ 0x1F (31)
899 // : 5.5G 0xF9 (-7) ~ 0x0F (15)
901 // 0. 11b/g, ch1 - ch 14
902 for (i
= 0; i
< 7; i
++)
904 RT28xx_EEPROM_READ16(pAd
, EEPROM_G_TX_PWR_OFFSET
+ i
* 2, Power
.word
);
905 RT28xx_EEPROM_READ16(pAd
, EEPROM_G_TX2_PWR_OFFSET
+ i
* 2, Power2
.word
);
906 pAd
->TxPower
[i
* 2].Channel
= i
* 2 + 1;
907 pAd
->TxPower
[i
* 2 + 1].Channel
= i
* 2 + 2;
909 if ((Power
.field
.Byte0
> 31) || (Power
.field
.Byte0
< 0))
910 pAd
->TxPower
[i
* 2].Power
= DEFAULT_RF_TX_POWER
;
912 pAd
->TxPower
[i
* 2].Power
= Power
.field
.Byte0
;
914 if ((Power
.field
.Byte1
> 31) || (Power
.field
.Byte1
< 0))
915 pAd
->TxPower
[i
* 2 + 1].Power
= DEFAULT_RF_TX_POWER
;
917 pAd
->TxPower
[i
* 2 + 1].Power
= Power
.field
.Byte1
;
919 if ((Power2
.field
.Byte0
> 31) || (Power2
.field
.Byte0
< 0))
920 pAd
->TxPower
[i
* 2].Power2
= DEFAULT_RF_TX_POWER
;
922 pAd
->TxPower
[i
* 2].Power2
= Power2
.field
.Byte0
;
924 if ((Power2
.field
.Byte1
> 31) || (Power2
.field
.Byte1
< 0))
925 pAd
->TxPower
[i
* 2 + 1].Power2
= DEFAULT_RF_TX_POWER
;
927 pAd
->TxPower
[i
* 2 + 1].Power2
= Power2
.field
.Byte1
;
930 // 1. U-NII lower/middle band: 36, 38, 40; 44, 46, 48; 52, 54, 56; 60, 62, 64 (including central frequency in BW 40MHz)
931 // 1.1 Fill up channel
933 for (i
= 0; i
< 4; i
++)
935 pAd
->TxPower
[3 * i
+ choffset
+ 0].Channel
= 36 + i
* 8 + 0;
936 pAd
->TxPower
[3 * i
+ choffset
+ 0].Power
= DEFAULT_RF_TX_POWER
;
937 pAd
->TxPower
[3 * i
+ choffset
+ 0].Power2
= DEFAULT_RF_TX_POWER
;
939 pAd
->TxPower
[3 * i
+ choffset
+ 1].Channel
= 36 + i
* 8 + 2;
940 pAd
->TxPower
[3 * i
+ choffset
+ 1].Power
= DEFAULT_RF_TX_POWER
;
941 pAd
->TxPower
[3 * i
+ choffset
+ 1].Power2
= DEFAULT_RF_TX_POWER
;
943 pAd
->TxPower
[3 * i
+ choffset
+ 2].Channel
= 36 + i
* 8 + 4;
944 pAd
->TxPower
[3 * i
+ choffset
+ 2].Power
= DEFAULT_RF_TX_POWER
;
945 pAd
->TxPower
[3 * i
+ choffset
+ 2].Power2
= DEFAULT_RF_TX_POWER
;
949 for (i
= 0; i
< 6; i
++)
951 RT28xx_EEPROM_READ16(pAd
, EEPROM_A_TX_PWR_OFFSET
+ i
* 2, Power
.word
);
952 RT28xx_EEPROM_READ16(pAd
, EEPROM_A_TX2_PWR_OFFSET
+ i
* 2, Power2
.word
);
954 if ((Power
.field
.Byte0
< 16) && (Power
.field
.Byte0
>= -7))
955 pAd
->TxPower
[i
* 2 + choffset
+ 0].Power
= Power
.field
.Byte0
;
957 if ((Power
.field
.Byte1
< 16) && (Power
.field
.Byte1
>= -7))
958 pAd
->TxPower
[i
* 2 + choffset
+ 1].Power
= Power
.field
.Byte1
;
960 if ((Power2
.field
.Byte0
< 16) && (Power2
.field
.Byte0
>= -7))
961 pAd
->TxPower
[i
* 2 + choffset
+ 0].Power2
= Power2
.field
.Byte0
;
963 if ((Power2
.field
.Byte1
< 16) && (Power2
.field
.Byte1
>= -7))
964 pAd
->TxPower
[i
* 2 + choffset
+ 1].Power2
= Power2
.field
.Byte1
;
967 // 2. HipperLAN 2 100, 102 ,104; 108, 110, 112; 116, 118, 120; 124, 126, 128; 132, 134, 136; 140 (including central frequency in BW 40MHz)
968 // 2.1 Fill up channel
970 for (i
= 0; i
< 5; i
++)
972 pAd
->TxPower
[3 * i
+ choffset
+ 0].Channel
= 100 + i
* 8 + 0;
973 pAd
->TxPower
[3 * i
+ choffset
+ 0].Power
= DEFAULT_RF_TX_POWER
;
974 pAd
->TxPower
[3 * i
+ choffset
+ 0].Power2
= DEFAULT_RF_TX_POWER
;
976 pAd
->TxPower
[3 * i
+ choffset
+ 1].Channel
= 100 + i
* 8 + 2;
977 pAd
->TxPower
[3 * i
+ choffset
+ 1].Power
= DEFAULT_RF_TX_POWER
;
978 pAd
->TxPower
[3 * i
+ choffset
+ 1].Power2
= DEFAULT_RF_TX_POWER
;
980 pAd
->TxPower
[3 * i
+ choffset
+ 2].Channel
= 100 + i
* 8 + 4;
981 pAd
->TxPower
[3 * i
+ choffset
+ 2].Power
= DEFAULT_RF_TX_POWER
;
982 pAd
->TxPower
[3 * i
+ choffset
+ 2].Power2
= DEFAULT_RF_TX_POWER
;
984 pAd
->TxPower
[3 * 5 + choffset
+ 0].Channel
= 140;
985 pAd
->TxPower
[3 * 5 + choffset
+ 0].Power
= DEFAULT_RF_TX_POWER
;
986 pAd
->TxPower
[3 * 5 + choffset
+ 0].Power2
= DEFAULT_RF_TX_POWER
;
989 for (i
= 0; i
< 8; i
++)
991 RT28xx_EEPROM_READ16(pAd
, EEPROM_A_TX_PWR_OFFSET
+ (choffset
- 14) + i
* 2, Power
.word
);
992 RT28xx_EEPROM_READ16(pAd
, EEPROM_A_TX2_PWR_OFFSET
+ (choffset
- 14) + i
* 2, Power2
.word
);
994 if ((Power
.field
.Byte0
< 16) && (Power
.field
.Byte0
>= -7))
995 pAd
->TxPower
[i
* 2 + choffset
+ 0].Power
= Power
.field
.Byte0
;
997 if ((Power
.field
.Byte1
< 16) && (Power
.field
.Byte1
>= -7))
998 pAd
->TxPower
[i
* 2 + choffset
+ 1].Power
= Power
.field
.Byte1
;
1000 if ((Power2
.field
.Byte0
< 16) && (Power2
.field
.Byte0
>= -7))
1001 pAd
->TxPower
[i
* 2 + choffset
+ 0].Power2
= Power2
.field
.Byte0
;
1003 if ((Power2
.field
.Byte1
< 16) && (Power2
.field
.Byte1
>= -7))
1004 pAd
->TxPower
[i
* 2 + choffset
+ 1].Power2
= Power2
.field
.Byte1
;
1007 // 3. U-NII upper band: 149, 151, 153; 157, 159, 161; 165 (including central frequency in BW 40MHz)
1008 // 3.1 Fill up channel
1009 choffset
= 14 + 12 + 16;
1010 for (i
= 0; i
< 2; i
++)
1012 pAd
->TxPower
[3 * i
+ choffset
+ 0].Channel
= 149 + i
* 8 + 0;
1013 pAd
->TxPower
[3 * i
+ choffset
+ 0].Power
= DEFAULT_RF_TX_POWER
;
1014 pAd
->TxPower
[3 * i
+ choffset
+ 0].Power2
= DEFAULT_RF_TX_POWER
;
1016 pAd
->TxPower
[3 * i
+ choffset
+ 1].Channel
= 149 + i
* 8 + 2;
1017 pAd
->TxPower
[3 * i
+ choffset
+ 1].Power
= DEFAULT_RF_TX_POWER
;
1018 pAd
->TxPower
[3 * i
+ choffset
+ 1].Power2
= DEFAULT_RF_TX_POWER
;
1020 pAd
->TxPower
[3 * i
+ choffset
+ 2].Channel
= 149 + i
* 8 + 4;
1021 pAd
->TxPower
[3 * i
+ choffset
+ 2].Power
= DEFAULT_RF_TX_POWER
;
1022 pAd
->TxPower
[3 * i
+ choffset
+ 2].Power2
= DEFAULT_RF_TX_POWER
;
1024 pAd
->TxPower
[3 * 2 + choffset
+ 0].Channel
= 165;
1025 pAd
->TxPower
[3 * 2 + choffset
+ 0].Power
= DEFAULT_RF_TX_POWER
;
1026 pAd
->TxPower
[3 * 2 + choffset
+ 0].Power2
= DEFAULT_RF_TX_POWER
;
1028 // 3.2 Fill up power
1029 for (i
= 0; i
< 4; i
++)
1031 RT28xx_EEPROM_READ16(pAd
, EEPROM_A_TX_PWR_OFFSET
+ (choffset
- 14) + i
* 2, Power
.word
);
1032 RT28xx_EEPROM_READ16(pAd
, EEPROM_A_TX2_PWR_OFFSET
+ (choffset
- 14) + i
* 2, Power2
.word
);
1034 if ((Power
.field
.Byte0
< 16) && (Power
.field
.Byte0
>= -7))
1035 pAd
->TxPower
[i
* 2 + choffset
+ 0].Power
= Power
.field
.Byte0
;
1037 if ((Power
.field
.Byte1
< 16) && (Power
.field
.Byte1
>= -7))
1038 pAd
->TxPower
[i
* 2 + choffset
+ 1].Power
= Power
.field
.Byte1
;
1040 if ((Power2
.field
.Byte0
< 16) && (Power2
.field
.Byte0
>= -7))
1041 pAd
->TxPower
[i
* 2 + choffset
+ 0].Power2
= Power2
.field
.Byte0
;
1043 if ((Power2
.field
.Byte1
< 16) && (Power2
.field
.Byte1
>= -7))
1044 pAd
->TxPower
[i
* 2 + choffset
+ 1].Power2
= Power2
.field
.Byte1
;
1047 // 4. Print and Debug
1048 choffset
= 14 + 12 + 16 + 7;
1052 ========================================================================
1054 Routine Description:
1055 Read the following from the registry
1056 1. All the parameters
1060 Adapter Pointer to our adapter
1061 WrapperConfigurationContext For use by NdisOpenConfiguration
1066 NDIS_STATUS_RESOURCES
1068 IRQL = PASSIVE_LEVEL
1072 ========================================================================
1074 NDIS_STATUS
NICReadRegParameters(
1075 IN PRTMP_ADAPTER pAd
,
1076 IN NDIS_HANDLE WrapperConfigurationContext
1079 NDIS_STATUS Status
= NDIS_STATUS_SUCCESS
;
1080 DBGPRINT_S(Status
, ("<-- NICReadRegParameters, Status=%x\n", Status
));
1087 ========================================================================
1089 Routine Description:
1090 For RF filter calibration purpose
1093 pAd Pointer to our adapter
1098 IRQL = PASSIVE_LEVEL
1100 ========================================================================
1102 VOID
RTMPFilterCalibration(
1103 IN PRTMP_ADAPTER pAd
)
1105 UCHAR R55x
= 0, value
, FilterTarget
= 0x1E, BBPValue
=0;
1106 UINT loop
= 0, count
= 0, loopcnt
= 0, ReTry
= 0;
1107 UCHAR RF_R24_Value
= 0;
1109 // Give bbp filter initial value
1111 pAd
->Mlme
.CaliBW20RfR24
= 0x16;
1112 pAd
->Mlme
.CaliBW40RfR24
= 0x36; //Bit[5] must be 1 for BW 40
1114 pAd
->Mlme
.CaliBW20RfR24
= 0x1F;
1115 pAd
->Mlme
.CaliBW40RfR24
= 0x2F; //Bit[5] must be 1 for BW 40
1119 if (loop
== 1) //BandWidth = 40 MHz
1121 // Write 0x27 to RF_R24 to program filter
1122 RF_R24_Value
= 0x27;
1123 RT30xxWriteRFRegister(pAd
, RF_R24
, RF_R24_Value
);
1125 FilterTarget
= 0x15;
1127 FilterTarget
= 0x19;
1129 // when calibrate BW40, BBP mask must set to BW40.
1130 RTMP_BBP_IO_READ8_BY_REG_ID(pAd
, BBP_R4
, &BBPValue
);
1133 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd
, BBP_R4
, BBPValue
);
1136 RT30xxReadRFRegister(pAd
, RF_R31
, &value
);
1138 RT30xxWriteRFRegister(pAd
, RF_R31
, value
);
1141 else //BandWidth = 20 MHz
1143 // Write 0x07 to RF_R24 to program filter
1144 RF_R24_Value
= 0x07;
1145 RT30xxWriteRFRegister(pAd
, RF_R24
, RF_R24_Value
);
1147 FilterTarget
= 0x13;
1149 FilterTarget
= 0x16;
1152 RT30xxReadRFRegister(pAd
, RF_R31
, &value
);
1154 RT30xxWriteRFRegister(pAd
, RF_R31
, value
);
1158 // Write 0x01 to RF_R22 to enable baseband loopback mode
1159 RT30xxReadRFRegister(pAd
, RF_R22
, &value
);
1161 RT30xxWriteRFRegister(pAd
, RF_R22
, value
);
1163 // Write 0x00 to BBP_R24 to set power & frequency of passband test tone
1164 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd
, BBP_R24
, 0);
1168 // Write 0x90 to BBP_R25 to transmit test tone
1169 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd
, BBP_R25
, 0x90);
1171 RTMPusecDelay(1000);
1172 // Read BBP_R55[6:0] for received power, set R55x = BBP_R55[6:0]
1173 RTMP_BBP_IO_READ8_BY_REG_ID(pAd
, BBP_R55
, &value
);
1174 R55x
= value
& 0xFF;
1176 } while ((ReTry
++ < 100) && (R55x
== 0));
1178 // Write 0x06 to BBP_R24 to set power & frequency of stopband test tone
1179 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd
, BBP_R24
, 0x06);
1183 // Write 0x90 to BBP_R25 to transmit test tone
1184 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd
, BBP_R25
, 0x90);
1186 //We need to wait for calibration
1187 RTMPusecDelay(1000);
1188 RTMP_BBP_IO_READ8_BY_REG_ID(pAd
, BBP_R55
, &value
);
1190 if ((R55x
- value
) < FilterTarget
)
1194 else if ((R55x
- value
) == FilterTarget
)
1204 // prevent infinite loop cause driver hang.
1205 if (loopcnt
++ > 100)
1207 DBGPRINT(RT_DEBUG_ERROR
, ("RTMPFilterCalibration - can't find a valid value, loopcnt=%d stop calibrating", loopcnt
));
1211 // Write RF_R24 to program filter
1212 RT30xxWriteRFRegister(pAd
, RF_R24
, RF_R24_Value
);
1217 RF_R24_Value
= RF_R24_Value
- ((count
) ? (1) : (0));
1220 // Store for future usage
1225 //BandWidth = 20 MHz
1226 pAd
->Mlme
.CaliBW20RfR24
= (UCHAR
)RF_R24_Value
;
1230 //BandWidth = 40 MHz
1231 pAd
->Mlme
.CaliBW40RfR24
= (UCHAR
)RF_R24_Value
;
1238 RT30xxWriteRFRegister(pAd
, RF_R24
, RF_R24_Value
);
1245 // Set back to initial state
1247 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd
, BBP_R24
, 0);
1249 RT30xxReadRFRegister(pAd
, RF_R22
, &value
);
1251 RT30xxWriteRFRegister(pAd
, RF_R22
, value
);
1253 // set BBP back to BW20
1254 RTMP_BBP_IO_READ8_BY_REG_ID(pAd
, BBP_R4
, &BBPValue
);
1256 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd
, BBP_R4
, BBPValue
);
1258 DBGPRINT(RT_DEBUG_TRACE
, ("RTMPFilterCalibration - CaliBW20RfR24=0x%x, CaliBW40RfR24=0x%x\n", pAd
->Mlme
.CaliBW20RfR24
, pAd
->Mlme
.CaliBW40RfR24
));
1261 VOID
NICInitRT30xxRFRegisters(IN PRTMP_ADAPTER pAd
)
1264 // Driver must read EEPROM to get RfIcType before initial RF registers
1265 // Initialize RF register to default value
1270 && (pAd
->RfIcType
== RFIC_3020
|| pAd
->RfIcType
== RFIC_2020
)
1274 // Init RF calibration
1275 // Driver should toggle RF R30 bit7 before init RF registers
1280 RT30xxReadRFRegister(pAd
, RF_R30
, (PUCHAR
)&RfReg
);
1282 RT30xxWriteRFRegister(pAd
, RF_R30
, (UCHAR
)RfReg
);
1283 RTMPusecDelay(1000);
1285 RT30xxWriteRFRegister(pAd
, RF_R30
, (UCHAR
)RfReg
);
1287 // Initialize RF register to default value
1288 for (i
= 0; i
< NUM_RF_REG_PARMS
; i
++)
1290 RT30xxWriteRFRegister(pAd
, RT30xx_RFRegTable
[i
].Register
, RT30xx_RFRegTable
[i
].Value
);
1296 // Update MAC 0x05D4 from 01xxxxxx to 0Dxxxxxx (voltage 1.2V to 1.35V) for RT3070 to improve yield rate
1297 RTUSBReadMACRegister(pAd
, LDO_CFG0
, &data
);
1298 data
= ((data
& 0xF0FFFFFF) | 0x0D000000);
1299 RTUSBWriteMACRegister(pAd
, LDO_CFG0
, data
);
1301 else if (IS_RT3071(pAd
))
1303 // Driver should set RF R6 bit6 on before init RF registers
1304 RT30xxReadRFRegister(pAd
, RF_R06
, (PUCHAR
)&RfReg
);
1306 RT30xxWriteRFRegister(pAd
, RF_R06
, (UCHAR
)RfReg
);
1309 RT30xxWriteRFRegister(pAd
, RF_R31
, 0x14);
1311 // RT3071 version E has fixed this issue
1312 if ((pAd
->NicConfig2
.field
.DACTestBit
== 1) && ((pAd
->MACVersion
& 0xffff) < 0x0211))
1314 // patch tx EVM issue temporarily
1315 RTUSBReadMACRegister(pAd
, LDO_CFG0
, &data
);
1316 data
= ((data
& 0xE0FFFFFF) | 0x0D000000);
1317 RTUSBWriteMACRegister(pAd
, LDO_CFG0
, data
);
1321 RTMP_IO_READ32(pAd
, LDO_CFG0
, &data
);
1322 data
= ((data
& 0xE0FFFFFF) | 0x01000000);
1323 RTMP_IO_WRITE32(pAd
, LDO_CFG0
, data
);
1326 // patch LNA_PE_G1 failed issue
1327 RTUSBReadMACRegister(pAd
, GPIO_SWITCH
, &data
);
1329 RTUSBWriteMACRegister(pAd
, GPIO_SWITCH
, data
);
1332 //For RF filter Calibration
1333 RTMPFilterCalibration(pAd
);
1335 // Initialize RF R27 register, set RF R27 must be behind RTMPFilterCalibration()
1336 if ((pAd
->MACVersion
& 0xffff) < 0x0211)
1337 RT30xxWriteRFRegister(pAd
, RF_R27
, 0x3);
1339 // set led open drain enable
1340 RTUSBReadMACRegister(pAd
, OPT_14
, &data
);
1342 RTUSBWriteMACRegister(pAd
, OPT_14
, data
);
1346 // add by johnli, RF power sequence setup, load RF normal operation-mode setup
1347 RT30xxLoadRFNormalModeSetup(pAd
);
1356 ========================================================================
1358 Routine Description:
1359 Read initial parameters from EEPROM
1362 Adapter Pointer to our adapter
1367 IRQL = PASSIVE_LEVEL
1371 ========================================================================
1373 VOID
NICReadEEPROMParameters(
1374 IN PRTMP_ADAPTER pAd
,
1378 USHORT i
, value
, value2
;
1380 EEPROM_TX_PWR_STRUC Power
;
1381 EEPROM_VERSION_STRUC Version
;
1382 EEPROM_ANTENNA_STRUC Antenna
;
1383 EEPROM_NIC_CONFIG2_STRUC NicConfig2
;
1385 DBGPRINT(RT_DEBUG_TRACE
, ("--> NICReadEEPROMParameters\n"));
1387 // Init EEPROM Address Number, before access EEPROM; if 93c46, EEPROMAddressNum=6, else if 93c66, EEPROMAddressNum=8
1388 RTMP_IO_READ32(pAd
, E2PROM_CSR
, &data
);
1389 DBGPRINT(RT_DEBUG_TRACE
, ("--> E2PROM_CSR = 0x%x\n", data
));
1391 if((data
& 0x30) == 0)
1392 pAd
->EEPROMAddressNum
= 6; // 93C46
1393 else if((data
& 0x30) == 0x10)
1394 pAd
->EEPROMAddressNum
= 8; // 93C66
1396 pAd
->EEPROMAddressNum
= 8; // 93C86
1397 DBGPRINT(RT_DEBUG_TRACE
, ("--> EEPROMAddressNum = %d\n", pAd
->EEPROMAddressNum
));
1399 // RT2860 MAC no longer auto load MAC address from E2PROM. Driver has to intialize
1400 // MAC address registers according to E2PROM setting
1401 if (mac_addr
== NULL
||
1402 strlen(mac_addr
) != 17 ||
1403 mac_addr
[2] != ':' || mac_addr
[5] != ':' || mac_addr
[8] != ':' ||
1404 mac_addr
[11] != ':' || mac_addr
[14] != ':')
1406 USHORT Addr01
,Addr23
,Addr45
;
1408 RT28xx_EEPROM_READ16(pAd
, 0x04, Addr01
);
1409 RT28xx_EEPROM_READ16(pAd
, 0x06, Addr23
);
1410 RT28xx_EEPROM_READ16(pAd
, 0x08, Addr45
);
1412 pAd
->PermanentAddress
[0] = (UCHAR
)(Addr01
& 0xff);
1413 pAd
->PermanentAddress
[1] = (UCHAR
)(Addr01
>> 8);
1414 pAd
->PermanentAddress
[2] = (UCHAR
)(Addr23
& 0xff);
1415 pAd
->PermanentAddress
[3] = (UCHAR
)(Addr23
>> 8);
1416 pAd
->PermanentAddress
[4] = (UCHAR
)(Addr45
& 0xff);
1417 pAd
->PermanentAddress
[5] = (UCHAR
)(Addr45
>> 8);
1419 DBGPRINT(RT_DEBUG_TRACE
, ("Initialize MAC Address from E2PROM \n"));
1428 for (j
=0; j
<MAC_ADDR_LEN
; j
++)
1430 AtoH(macptr
, &pAd
->PermanentAddress
[j
], 1);
1434 DBGPRINT(RT_DEBUG_TRACE
, ("Initialize MAC Address from module parameter \n"));
1439 //more conveninet to test mbssid, so ap's bssid &0xf1
1440 if (pAd
->PermanentAddress
[0] == 0xff)
1441 pAd
->PermanentAddress
[0] = RandomByte(pAd
)&0xf8;
1443 //if (pAd->PermanentAddress[5] == 0xff)
1444 // pAd->PermanentAddress[5] = RandomByte(pAd)&0xf8;
1446 DBGPRINT_RAW(RT_DEBUG_TRACE
,("E2PROM MAC: =%02x:%02x:%02x:%02x:%02x:%02x\n",
1447 pAd
->PermanentAddress
[0], pAd
->PermanentAddress
[1],
1448 pAd
->PermanentAddress
[2], pAd
->PermanentAddress
[3],
1449 pAd
->PermanentAddress
[4], pAd
->PermanentAddress
[5]));
1450 if (pAd
->bLocalAdminMAC
== FALSE
)
1454 COPY_MAC_ADDR(pAd
->CurrentAddress
, pAd
->PermanentAddress
);
1455 csr2
.field
.Byte0
= pAd
->CurrentAddress
[0];
1456 csr2
.field
.Byte1
= pAd
->CurrentAddress
[1];
1457 csr2
.field
.Byte2
= pAd
->CurrentAddress
[2];
1458 csr2
.field
.Byte3
= pAd
->CurrentAddress
[3];
1459 RTMP_IO_WRITE32(pAd
, MAC_ADDR_DW0
, csr2
.word
);
1461 csr3
.field
.Byte4
= pAd
->CurrentAddress
[4];
1462 csr3
.field
.Byte5
= pAd
->CurrentAddress
[5];
1463 csr3
.field
.U2MeMask
= 0xff;
1464 RTMP_IO_WRITE32(pAd
, MAC_ADDR_DW1
, csr3
.word
);
1465 DBGPRINT_RAW(RT_DEBUG_TRACE
,("E2PROM MAC: =%02x:%02x:%02x:%02x:%02x:%02x\n",
1466 pAd
->PermanentAddress
[0], pAd
->PermanentAddress
[1],
1467 pAd
->PermanentAddress
[2], pAd
->PermanentAddress
[3],
1468 pAd
->PermanentAddress
[4], pAd
->PermanentAddress
[5]));
1472 // if not return early. cause fail at emulation.
1473 // Init the channel number for TX channel power
1474 RTMPReadChannelPwr(pAd
);
1476 // if E2PROM version mismatch with driver's expectation, then skip
1477 // all subsequent E2RPOM retieval and set a system error bit to notify GUI
1478 RT28xx_EEPROM_READ16(pAd
, EEPROM_VERSION_OFFSET
, Version
.word
);
1479 pAd
->EepromVersion
= Version
.field
.Version
+ Version
.field
.FaeReleaseNumber
* 256;
1480 DBGPRINT(RT_DEBUG_TRACE
, ("E2PROM: Version = %d, FAE release #%d\n", Version
.field
.Version
, Version
.field
.FaeReleaseNumber
));
1482 if (Version
.field
.Version
> VALID_EEPROM_VERSION
)
1484 DBGPRINT_ERR(("E2PROM: WRONG VERSION 0x%x, should be %d\n",Version
.field
.Version
, VALID_EEPROM_VERSION
));
1485 /*pAd->SystemErrorBitmap |= 0x00000001;
1487 // hard-code default value when no proper E2PROM installed
1488 pAd->bAutoTxAgcA = FALSE;
1489 pAd->bAutoTxAgcG = FALSE;
1491 // Default the channel power
1492 for (i = 0; i < MAX_NUM_OF_CHANNELS; i++)
1493 pAd->TxPower[i].Power = DEFAULT_RF_TX_POWER;
1495 // Default the channel power
1496 for (i = 0; i < MAX_NUM_OF_11JCHANNELS; i++)
1497 pAd->TxPower11J[i].Power = DEFAULT_RF_TX_POWER;
1499 for(i = 0; i < NUM_EEPROM_BBP_PARMS; i++)
1500 pAd->EEPROMDefaultValue[i] = 0xffff;
1504 // Read BBP default value from EEPROM and store to array(EEPROMDefaultValue) in pAd
1505 RT28xx_EEPROM_READ16(pAd
, EEPROM_NIC1_OFFSET
, value
);
1506 pAd
->EEPROMDefaultValue
[0] = value
;
1508 RT28xx_EEPROM_READ16(pAd
, EEPROM_NIC2_OFFSET
, value
);
1509 pAd
->EEPROMDefaultValue
[1] = value
;
1511 RT28xx_EEPROM_READ16(pAd
, 0x38, value
); // Country Region
1512 pAd
->EEPROMDefaultValue
[2] = value
;
1514 for(i
= 0; i
< 8; i
++)
1516 RT28xx_EEPROM_READ16(pAd
, EEPROM_BBP_BASE_OFFSET
+ i
*2, value
);
1517 pAd
->EEPROMDefaultValue
[i
+3] = value
;
1520 // We have to parse NIC configuration 0 at here.
1521 // If TSSI did not have preloaded value, it should reset the TxAutoAgc to false
1522 // Therefore, we have to read TxAutoAgc control beforehand.
1523 // Read Tx AGC control bit
1524 Antenna
.word
= pAd
->EEPROMDefaultValue
[0];
1525 if (Antenna
.word
== 0xFFFF)
1530 Antenna
.field
.RfIcType
= RFIC_3020
;
1531 Antenna
.field
.TxPath
= 1;
1532 Antenna
.field
.RxPath
= 1;
1537 Antenna
.field
.RfIcType
= RFIC_2820
;
1538 Antenna
.field
.TxPath
= 1;
1539 Antenna
.field
.RxPath
= 2;
1540 DBGPRINT(RT_DEBUG_WARN
, ("E2PROM error, hard code as 0x%04x\n", Antenna
.word
));
1544 // Choose the desired Tx&Rx stream.
1545 if ((pAd
->CommonCfg
.TxStream
== 0) || (pAd
->CommonCfg
.TxStream
> Antenna
.field
.TxPath
))
1546 pAd
->CommonCfg
.TxStream
= Antenna
.field
.TxPath
;
1548 if ((pAd
->CommonCfg
.RxStream
== 0) || (pAd
->CommonCfg
.RxStream
> Antenna
.field
.RxPath
))
1550 pAd
->CommonCfg
.RxStream
= Antenna
.field
.RxPath
;
1552 if ((pAd
->MACVersion
< RALINK_2883_VERSION
) &&
1553 (pAd
->CommonCfg
.RxStream
> 2))
1555 // only 2 Rx streams for RT2860 series
1556 pAd
->CommonCfg
.RxStream
= 2;
1561 // read value from EEPROM and set them to CSR174 ~ 177 in chain0 ~ chain2
1567 NicConfig2
.word
= pAd
->EEPROMDefaultValue
[1];
1571 NicConfig2
.word
= 0;
1573 if ((NicConfig2
.word
& 0x00ff) == 0xff)
1575 NicConfig2
.word
&= 0xff00;
1578 if ((NicConfig2
.word
>> 8) == 0xff)
1580 NicConfig2
.word
&= 0x00ff;
1584 if (NicConfig2
.field
.DynamicTxAgcControl
== 1)
1585 pAd
->bAutoTxAgcA
= pAd
->bAutoTxAgcG
= TRUE
;
1587 pAd
->bAutoTxAgcA
= pAd
->bAutoTxAgcG
= FALSE
;
1589 DBGPRINT_RAW(RT_DEBUG_TRACE
, ("NICReadEEPROMParameters: RxPath = %d, TxPath = %d\n", Antenna
.field
.RxPath
, Antenna
.field
.TxPath
));
1591 // Save the antenna for future use
1592 pAd
->Antenna
.word
= Antenna
.word
;
1595 // Reset PhyMode if we don't support 802.11a
1596 // Only RFIC_2850 & RFIC_2750 support 802.11a
1598 if ((Antenna
.field
.RfIcType
!= RFIC_2850
) && (Antenna
.field
.RfIcType
!= RFIC_2750
))
1600 if ((pAd
->CommonCfg
.PhyMode
== PHY_11ABG_MIXED
) ||
1601 (pAd
->CommonCfg
.PhyMode
== PHY_11A
))
1602 pAd
->CommonCfg
.PhyMode
= PHY_11BG_MIXED
;
1603 else if ((pAd
->CommonCfg
.PhyMode
== PHY_11ABGN_MIXED
) ||
1604 (pAd
->CommonCfg
.PhyMode
== PHY_11AN_MIXED
) ||
1605 (pAd
->CommonCfg
.PhyMode
== PHY_11AGN_MIXED
) ||
1606 (pAd
->CommonCfg
.PhyMode
== PHY_11N_5G
))
1607 pAd
->CommonCfg
.PhyMode
= PHY_11BGN_MIXED
;
1610 // Read TSSI reference and TSSI boundary for temperature compensation. This is ugly
1613 /* these are tempature reference value (0x00 ~ 0xFE)
1614 ex: 0x00 0x15 0x25 0x45 0x88 0xA0 0xB5 0xD0 0xF0
1615 TssiPlusBoundaryG [4] [3] [2] [1] [0] (smaller) +
1616 TssiMinusBoundaryG[0] [1] [2] [3] [4] (larger) */
1617 RT28xx_EEPROM_READ16(pAd
, 0x6E, Power
.word
);
1618 pAd
->TssiMinusBoundaryG
[4] = Power
.field
.Byte0
;
1619 pAd
->TssiMinusBoundaryG
[3] = Power
.field
.Byte1
;
1620 RT28xx_EEPROM_READ16(pAd
, 0x70, Power
.word
);
1621 pAd
->TssiMinusBoundaryG
[2] = Power
.field
.Byte0
;
1622 pAd
->TssiMinusBoundaryG
[1] = Power
.field
.Byte1
;
1623 RT28xx_EEPROM_READ16(pAd
, 0x72, Power
.word
);
1624 pAd
->TssiRefG
= Power
.field
.Byte0
; /* reference value [0] */
1625 pAd
->TssiPlusBoundaryG
[1] = Power
.field
.Byte1
;
1626 RT28xx_EEPROM_READ16(pAd
, 0x74, Power
.word
);
1627 pAd
->TssiPlusBoundaryG
[2] = Power
.field
.Byte0
;
1628 pAd
->TssiPlusBoundaryG
[3] = Power
.field
.Byte1
;
1629 RT28xx_EEPROM_READ16(pAd
, 0x76, Power
.word
);
1630 pAd
->TssiPlusBoundaryG
[4] = Power
.field
.Byte0
;
1631 pAd
->TxAgcStepG
= Power
.field
.Byte1
;
1632 pAd
->TxAgcCompensateG
= 0;
1633 pAd
->TssiMinusBoundaryG
[0] = pAd
->TssiRefG
;
1634 pAd
->TssiPlusBoundaryG
[0] = pAd
->TssiRefG
;
1636 // Disable TxAgc if the based value is not right
1637 if (pAd
->TssiRefG
== 0xff)
1638 pAd
->bAutoTxAgcG
= FALSE
;
1640 DBGPRINT(RT_DEBUG_TRACE
,("E2PROM: G Tssi[-4 .. +4] = %d %d %d %d - %d -%d %d %d %d, step=%d, tuning=%d\n",
1641 pAd
->TssiMinusBoundaryG
[4], pAd
->TssiMinusBoundaryG
[3], pAd
->TssiMinusBoundaryG
[2], pAd
->TssiMinusBoundaryG
[1],
1643 pAd
->TssiPlusBoundaryG
[1], pAd
->TssiPlusBoundaryG
[2], pAd
->TssiPlusBoundaryG
[3], pAd
->TssiPlusBoundaryG
[4],
1644 pAd
->TxAgcStepG
, pAd
->bAutoTxAgcG
));
1648 RT28xx_EEPROM_READ16(pAd
, 0xD4, Power
.word
);
1649 pAd
->TssiMinusBoundaryA
[4] = Power
.field
.Byte0
;
1650 pAd
->TssiMinusBoundaryA
[3] = Power
.field
.Byte1
;
1651 RT28xx_EEPROM_READ16(pAd
, 0xD6, Power
.word
);
1652 pAd
->TssiMinusBoundaryA
[2] = Power
.field
.Byte0
;
1653 pAd
->TssiMinusBoundaryA
[1] = Power
.field
.Byte1
;
1654 RT28xx_EEPROM_READ16(pAd
, 0xD8, Power
.word
);
1655 pAd
->TssiRefA
= Power
.field
.Byte0
;
1656 pAd
->TssiPlusBoundaryA
[1] = Power
.field
.Byte1
;
1657 RT28xx_EEPROM_READ16(pAd
, 0xDA, Power
.word
);
1658 pAd
->TssiPlusBoundaryA
[2] = Power
.field
.Byte0
;
1659 pAd
->TssiPlusBoundaryA
[3] = Power
.field
.Byte1
;
1660 RT28xx_EEPROM_READ16(pAd
, 0xDC, Power
.word
);
1661 pAd
->TssiPlusBoundaryA
[4] = Power
.field
.Byte0
;
1662 pAd
->TxAgcStepA
= Power
.field
.Byte1
;
1663 pAd
->TxAgcCompensateA
= 0;
1664 pAd
->TssiMinusBoundaryA
[0] = pAd
->TssiRefA
;
1665 pAd
->TssiPlusBoundaryA
[0] = pAd
->TssiRefA
;
1667 // Disable TxAgc if the based value is not right
1668 if (pAd
->TssiRefA
== 0xff)
1669 pAd
->bAutoTxAgcA
= FALSE
;
1671 DBGPRINT(RT_DEBUG_TRACE
,("E2PROM: A Tssi[-4 .. +4] = %d %d %d %d - %d -%d %d %d %d, step=%d, tuning=%d\n",
1672 pAd
->TssiMinusBoundaryA
[4], pAd
->TssiMinusBoundaryA
[3], pAd
->TssiMinusBoundaryA
[2], pAd
->TssiMinusBoundaryA
[1],
1674 pAd
->TssiPlusBoundaryA
[1], pAd
->TssiPlusBoundaryA
[2], pAd
->TssiPlusBoundaryA
[3], pAd
->TssiPlusBoundaryA
[4],
1675 pAd
->TxAgcStepA
, pAd
->bAutoTxAgcA
));
1677 pAd
->BbpRssiToDbmDelta
= 0x0;
1679 // Read frequency offset setting for RF
1680 RT28xx_EEPROM_READ16(pAd
, EEPROM_FREQ_OFFSET
, value
);
1681 if ((value
& 0x00FF) != 0x00FF)
1682 pAd
->RfFreqOffset
= (ULONG
) (value
& 0x00FF);
1684 pAd
->RfFreqOffset
= 0;
1685 DBGPRINT(RT_DEBUG_TRACE
, ("E2PROM: RF FreqOffset=0x%lx \n", pAd
->RfFreqOffset
));
1687 //CountryRegion byte offset (38h)
1688 value
= pAd
->EEPROMDefaultValue
[2] >> 8; // 2.4G band
1689 value2
= pAd
->EEPROMDefaultValue
[2] & 0x00FF; // 5G band
1691 if ((value
<= REGION_MAXIMUM_BG_BAND
) && (value2
<= REGION_MAXIMUM_A_BAND
))
1693 pAd
->CommonCfg
.CountryRegion
= ((UCHAR
) value
) | 0x80;
1694 pAd
->CommonCfg
.CountryRegionForABand
= ((UCHAR
) value2
) | 0x80;
1695 TmpPhy
= pAd
->CommonCfg
.PhyMode
;
1696 pAd
->CommonCfg
.PhyMode
= 0xff;
1697 RTMPSetPhyMode(pAd
, TmpPhy
);
1702 // Get RSSI Offset on EEPROM 0x9Ah & 0x9Ch.
1703 // The valid value are (-10 ~ 10)
1705 RT28xx_EEPROM_READ16(pAd
, EEPROM_RSSI_BG_OFFSET
, value
);
1706 pAd
->BGRssiOffset0
= value
& 0x00ff;
1707 pAd
->BGRssiOffset1
= (value
>> 8);
1708 RT28xx_EEPROM_READ16(pAd
, EEPROM_RSSI_BG_OFFSET
+2, value
);
1709 pAd
->BGRssiOffset2
= value
& 0x00ff;
1710 pAd
->ALNAGain1
= (value
>> 8);
1711 RT28xx_EEPROM_READ16(pAd
, EEPROM_LNA_OFFSET
, value
);
1712 pAd
->BLNAGain
= value
& 0x00ff;
1713 pAd
->ALNAGain0
= (value
>> 8);
1715 // Validate 11b/g RSSI_0 offset.
1716 if ((pAd
->BGRssiOffset0
< -10) || (pAd
->BGRssiOffset0
> 10))
1717 pAd
->BGRssiOffset0
= 0;
1719 // Validate 11b/g RSSI_1 offset.
1720 if ((pAd
->BGRssiOffset1
< -10) || (pAd
->BGRssiOffset1
> 10))
1721 pAd
->BGRssiOffset1
= 0;
1723 // Validate 11b/g RSSI_2 offset.
1724 if ((pAd
->BGRssiOffset2
< -10) || (pAd
->BGRssiOffset2
> 10))
1725 pAd
->BGRssiOffset2
= 0;
1727 RT28xx_EEPROM_READ16(pAd
, EEPROM_RSSI_A_OFFSET
, value
);
1728 pAd
->ARssiOffset0
= value
& 0x00ff;
1729 pAd
->ARssiOffset1
= (value
>> 8);
1730 RT28xx_EEPROM_READ16(pAd
, (EEPROM_RSSI_A_OFFSET
+2), value
);
1731 pAd
->ARssiOffset2
= value
& 0x00ff;
1732 pAd
->ALNAGain2
= (value
>> 8);
1734 if (((UCHAR
)pAd
->ALNAGain1
== 0xFF) || (pAd
->ALNAGain1
== 0x00))
1735 pAd
->ALNAGain1
= pAd
->ALNAGain0
;
1736 if (((UCHAR
)pAd
->ALNAGain2
== 0xFF) || (pAd
->ALNAGain2
== 0x00))
1737 pAd
->ALNAGain2
= pAd
->ALNAGain0
;
1739 // Validate 11a RSSI_0 offset.
1740 if ((pAd
->ARssiOffset0
< -10) || (pAd
->ARssiOffset0
> 10))
1741 pAd
->ARssiOffset0
= 0;
1743 // Validate 11a RSSI_1 offset.
1744 if ((pAd
->ARssiOffset1
< -10) || (pAd
->ARssiOffset1
> 10))
1745 pAd
->ARssiOffset1
= 0;
1747 //Validate 11a RSSI_2 offset.
1748 if ((pAd
->ARssiOffset2
< -10) || (pAd
->ARssiOffset2
> 10))
1749 pAd
->ARssiOffset2
= 0;
1754 RT28xx_EEPROM_READ16(pAd
, 0x3a, value
);
1755 pAd
->LedCntl
.word
= (value
&0xff00) >> 8;
1756 RT28xx_EEPROM_READ16(pAd
, EEPROM_LED1_OFFSET
, value
);
1758 RT28xx_EEPROM_READ16(pAd
, EEPROM_LED2_OFFSET
, value
);
1760 RT28xx_EEPROM_READ16(pAd
, EEPROM_LED3_OFFSET
, value
);
1763 RTMPReadTxPwrPerRate(pAd
);
1765 DBGPRINT(RT_DEBUG_TRACE
, ("<-- NICReadEEPROMParameters\n"));
1769 ========================================================================
1771 Routine Description:
1772 Set default value from EEPROM
1775 Adapter Pointer to our adapter
1780 IRQL = PASSIVE_LEVEL
1784 ========================================================================
1786 VOID
NICInitAsicFromEEPROM(
1787 IN PRTMP_ADAPTER pAd
)
1792 EEPROM_ANTENNA_STRUC Antenna
;
1793 EEPROM_NIC_CONFIG2_STRUC NicConfig2
;
1796 DBGPRINT(RT_DEBUG_TRACE
, ("--> NICInitAsicFromEEPROM\n"));
1797 for(i
= 3; i
< NUM_EEPROM_BBP_PARMS
; i
++)
1799 UCHAR BbpRegIdx
, BbpValue
;
1801 if ((pAd
->EEPROMDefaultValue
[i
] != 0xFFFF) && (pAd
->EEPROMDefaultValue
[i
] != 0))
1803 BbpRegIdx
= (UCHAR
)(pAd
->EEPROMDefaultValue
[i
] >> 8);
1804 BbpValue
= (UCHAR
)(pAd
->EEPROMDefaultValue
[i
] & 0xff);
1805 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd
, BbpRegIdx
, BbpValue
);
1810 Antenna
.word
= pAd
->Antenna
.word
;
1813 Antenna
.word
= pAd
->EEPROMDefaultValue
[0];
1814 if (Antenna
.word
== 0xFFFF)
1816 DBGPRINT(RT_DEBUG_ERROR
, ("E2PROM error, hard code as 0x%04x\n", Antenna
.word
));
1817 BUG_ON(Antenna
.word
== 0xFFFF);
1820 pAd
->Mlme
.RealRxPath
= (UCHAR
) Antenna
.field
.RxPath
;
1821 pAd
->RfIcType
= (UCHAR
) Antenna
.field
.RfIcType
;
1824 DBGPRINT(RT_DEBUG_WARN
, ("pAd->RfIcType = %d, RealRxPath=%d, TxPath = %d\n", pAd
->RfIcType
, pAd
->Mlme
.RealRxPath
,Antenna
.field
.TxPath
));
1826 // Save the antenna for future use
1827 pAd
->Antenna
.word
= Antenna
.word
;
1829 NicConfig2
.word
= pAd
->EEPROMDefaultValue
[1];
1833 if ((NicConfig2
.word
& 0x00ff) == 0xff)
1835 NicConfig2
.word
&= 0xff00;
1838 if ((NicConfig2
.word
>> 8) == 0xff)
1840 NicConfig2
.word
&= 0x00ff;
1844 // Save the antenna for future use
1845 pAd
->NicConfig2
.word
= NicConfig2
.word
;
1848 // set default antenna as main
1849 if (pAd
->RfIcType
== RFIC_3020
)
1850 AsicSetRxAnt(pAd
, pAd
->RxAnt
.Pair1PrimaryRxAnt
);
1853 // Send LED Setting to MCU.
1855 if (pAd
->LedCntl
.word
== 0xFF)
1857 pAd
->LedCntl
.word
= 0x01;
1869 AsicSendCommandToMcu(pAd
, 0x52, 0xff, (UCHAR
)pAd
->Led1
, (UCHAR
)(pAd
->Led1
>> 8));
1870 AsicSendCommandToMcu(pAd
, 0x53, 0xff, (UCHAR
)pAd
->Led2
, (UCHAR
)(pAd
->Led2
>> 8));
1871 AsicSendCommandToMcu(pAd
, 0x54, 0xff, (UCHAR
)pAd
->Led3
, (UCHAR
)(pAd
->Led3
>> 8));
1872 pAd
->LedIndicatorStregth
= 0xFF;
1873 RTMPSetSignalLED(pAd
, -100); // Force signal strength Led to be turned off, before link up
1876 // Read Hardware controlled Radio state enable bit
1877 if (NicConfig2
.field
.HardwareRadioControl
== 1)
1879 pAd
->StaCfg
.bHardwareRadio
= TRUE
;
1881 // Read GPIO pin2 as Hardware controlled radio state
1882 RTMP_IO_READ32(pAd
, GPIO_CTRL_CFG
, &data
);
1883 if ((data
& 0x04) == 0)
1885 pAd
->StaCfg
.bHwRadio
= FALSE
;
1886 pAd
->StaCfg
.bRadio
= FALSE
;
1887 RTMP_SET_FLAG(pAd
, fRTMP_ADAPTER_RADIO_OFF
);
1891 pAd
->StaCfg
.bHardwareRadio
= FALSE
;
1893 if (pAd
->StaCfg
.bRadio
== FALSE
)
1895 RTMPSetLED(pAd
, LED_RADIO_OFF
);
1899 RTMPSetLED(pAd
, LED_RADIO_ON
);
1901 AsicSendCommandToMcu(pAd
, 0x30, 0xff, 0xff, 0x02);
1902 AsicSendCommandToMcu(pAd
, 0x31, PowerWakeCID
, 0x00, 0x00);
1903 // 2-1. wait command ok.
1904 AsicCheckCommanOk(pAd
, PowerWakeCID
);
1909 // Turn off patching for cardbus controller
1910 if (NicConfig2
.field
.CardbusAcceleration
== 1)
1914 if (NicConfig2
.field
.DynamicTxAgcControl
== 1)
1915 pAd
->bAutoTxAgcA
= pAd
->bAutoTxAgcG
= TRUE
;
1917 pAd
->bAutoTxAgcA
= pAd
->bAutoTxAgcG
= FALSE
;
1919 /* BBP has been programmed so reset to UNKNOWN_BAND */
1920 pAd
->CommonCfg
.BandState
= UNKNOWN_BAND
;
1922 RTMP_BBP_IO_READ8_BY_REG_ID(pAd
, BBP_R3
, &BBPR3
);
1924 if(pAd
->Antenna
.field
.RxPath
== 3)
1928 else if(pAd
->Antenna
.field
.RxPath
== 2)
1932 else if(pAd
->Antenna
.field
.RxPath
== 1)
1936 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd
, BBP_R3
, BBPR3
);
1939 // Handle the difference when 1T
1940 RTMP_BBP_IO_READ8_BY_REG_ID(pAd
, BBP_R1
, &BBPR1
);
1941 if(pAd
->Antenna
.field
.TxPath
== 1)
1945 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd
, BBP_R1
, BBPR1
);
1947 DBGPRINT(RT_DEBUG_TRACE
, ("Use Hw Radio Control Pin=%d; if used Pin=%d;\n", pAd
->CommonCfg
.bHardwareRadio
, pAd
->CommonCfg
.bHardwareRadio
));
1950 DBGPRINT(RT_DEBUG_TRACE
, ("TxPath = %d, RxPath = %d, RFIC=%d, Polar+LED mode=%x\n", pAd
->Antenna
.field
.TxPath
, pAd
->Antenna
.field
.RxPath
, pAd
->RfIcType
, pAd
->LedCntl
.word
));
1951 DBGPRINT(RT_DEBUG_TRACE
, ("<-- NICInitAsicFromEEPROM\n"));
1955 ========================================================================
1957 Routine Description:
1958 Initialize NIC hardware
1961 Adapter Pointer to our adapter
1966 IRQL = PASSIVE_LEVEL
1970 ========================================================================
1972 NDIS_STATUS
NICInitializeAdapter(
1973 IN PRTMP_ADAPTER pAd
,
1974 IN BOOLEAN bHardReset
)
1976 NDIS_STATUS Status
= NDIS_STATUS_SUCCESS
;
1977 WPDMA_GLO_CFG_STRUC GloCfg
;
1980 DELAY_INT_CFG_STRUC IntCfg
;
1983 AC_TXOP_CSR0_STRUC csr0
;
1985 DBGPRINT(RT_DEBUG_TRACE
, ("--> NICInitializeAdapter\n"));
1987 // 3. Set DMA global configuration except TX_DMA_EN and RX_DMA_EN bits:
1992 RTMP_IO_READ32(pAd
, WPDMA_GLO_CFG
, &GloCfg
.word
);
1993 if ((GloCfg
.field
.TxDMABusy
== 0) && (GloCfg
.field
.RxDMABusy
== 0))
1996 RTMPusecDelay(1000);
1999 DBGPRINT(RT_DEBUG_TRACE
, ("<== DMA offset 0x208 = 0x%x\n", GloCfg
.word
));
2000 GloCfg
.word
&= 0xff0;
2001 GloCfg
.field
.EnTXWriteBackDDONE
=1;
2002 RTMP_IO_WRITE32(pAd
, WPDMA_GLO_CFG
, GloCfg
.word
);
2004 // Record HW Beacon offset
2005 pAd
->BeaconOffset
[0] = HW_BEACON_BASE0
;
2006 pAd
->BeaconOffset
[1] = HW_BEACON_BASE1
;
2007 pAd
->BeaconOffset
[2] = HW_BEACON_BASE2
;
2008 pAd
->BeaconOffset
[3] = HW_BEACON_BASE3
;
2009 pAd
->BeaconOffset
[4] = HW_BEACON_BASE4
;
2010 pAd
->BeaconOffset
[5] = HW_BEACON_BASE5
;
2011 pAd
->BeaconOffset
[6] = HW_BEACON_BASE6
;
2012 pAd
->BeaconOffset
[7] = HW_BEACON_BASE7
;
2015 // write all shared Ring's base address into ASIC
2018 // asic simulation sequence put this ahead before loading firmware.
2019 // pbf hardware reset
2021 RTMP_IO_WRITE32(pAd
, WPDMA_RST_IDX
, 0x1003f); // 0x10000 for reset rx, 0x3f resets all 6 tx rings.
2022 RTMP_IO_WRITE32(pAd
, PBF_SYS_CTRL
, 0xe1f);
2023 RTMP_IO_WRITE32(pAd
, PBF_SYS_CTRL
, 0xe00);
2026 // Initialze ASIC for TX & Rx operation
2027 if (NICInitializeAsic(pAd
, bHardReset
) != NDIS_STATUS_SUCCESS
)
2031 NICLoadFirmware(pAd
);
2034 return NDIS_STATUS_FAILURE
;
2039 // Write AC_BK base address register
2040 Value
= RTMP_GetPhysicalAddressLow(pAd
->TxRing
[QID_AC_BK
].Cell
[0].AllocPa
);
2041 RTMP_IO_WRITE32(pAd
, TX_BASE_PTR1
, Value
);
2042 DBGPRINT(RT_DEBUG_TRACE
, ("--> TX_BASE_PTR1 : 0x%x\n", Value
));
2044 // Write AC_BE base address register
2045 Value
= RTMP_GetPhysicalAddressLow(pAd
->TxRing
[QID_AC_BE
].Cell
[0].AllocPa
);
2046 RTMP_IO_WRITE32(pAd
, TX_BASE_PTR0
, Value
);
2047 DBGPRINT(RT_DEBUG_TRACE
, ("--> TX_BASE_PTR0 : 0x%x\n", Value
));
2049 // Write AC_VI base address register
2050 Value
= RTMP_GetPhysicalAddressLow(pAd
->TxRing
[QID_AC_VI
].Cell
[0].AllocPa
);
2051 RTMP_IO_WRITE32(pAd
, TX_BASE_PTR2
, Value
);
2052 DBGPRINT(RT_DEBUG_TRACE
, ("--> TX_BASE_PTR2 : 0x%x\n", Value
));
2054 // Write AC_VO base address register
2055 Value
= RTMP_GetPhysicalAddressLow(pAd
->TxRing
[QID_AC_VO
].Cell
[0].AllocPa
);
2056 RTMP_IO_WRITE32(pAd
, TX_BASE_PTR3
, Value
);
2057 DBGPRINT(RT_DEBUG_TRACE
, ("--> TX_BASE_PTR3 : 0x%x\n", Value
));
2059 // Write HCCA base address register
2060 Value
= RTMP_GetPhysicalAddressLow(pAd
->TxRing
[QID_HCCA
].Cell
[0].AllocPa
);
2061 RTMP_IO_WRITE32(pAd
, TX_BASE_PTR4
, Value
);
2062 DBGPRINT(RT_DEBUG_TRACE
, ("--> TX_BASE_PTR4 : 0x%x\n", Value
));
2064 // Write MGMT_BASE_CSR register
2065 Value
= RTMP_GetPhysicalAddressLow(pAd
->MgmtRing
.Cell
[0].AllocPa
);
2066 RTMP_IO_WRITE32(pAd
, TX_BASE_PTR5
, Value
);
2067 DBGPRINT(RT_DEBUG_TRACE
, ("--> TX_BASE_PTR5 : 0x%x\n", Value
));
2069 // Write RX_BASE_CSR register
2070 Value
= RTMP_GetPhysicalAddressLow(pAd
->RxRing
.Cell
[0].AllocPa
);
2071 RTMP_IO_WRITE32(pAd
, RX_BASE_PTR
, Value
);
2072 DBGPRINT(RT_DEBUG_TRACE
, ("--> RX_BASE_PTR : 0x%x\n", Value
));
2074 // Init RX Ring index pointer
2075 pAd
->RxRing
.RxSwReadIdx
= 0;
2076 pAd
->RxRing
.RxCpuIdx
= RX_RING_SIZE
-1;
2077 RTMP_IO_WRITE32(pAd
, RX_CRX_IDX
, pAd
->RxRing
.RxCpuIdx
);
2079 // Init TX rings index pointer
2081 for (i
=0; i
<NUM_OF_TX_RING
; i
++)
2083 pAd
->TxRing
[i
].TxSwFreeIdx
= 0;
2084 pAd
->TxRing
[i
].TxCpuIdx
= 0;
2085 RTMP_IO_WRITE32(pAd
, (TX_CTX_IDX0
+ i
* 0x10) , pAd
->TxRing
[i
].TxCpuIdx
);
2089 // init MGMT ring index pointer
2090 pAd
->MgmtRing
.TxSwFreeIdx
= 0;
2091 pAd
->MgmtRing
.TxCpuIdx
= 0;
2092 RTMP_IO_WRITE32(pAd
, TX_MGMTCTX_IDX
, pAd
->MgmtRing
.TxCpuIdx
);
2095 // set each Ring's SIZE into ASIC. Descriptor Size is fixed by design.
2098 // Write TX_RING_CSR0 register
2099 Value
= TX_RING_SIZE
;
2100 RTMP_IO_WRITE32(pAd
, TX_MAX_CNT0
, Value
);
2101 RTMP_IO_WRITE32(pAd
, TX_MAX_CNT1
, Value
);
2102 RTMP_IO_WRITE32(pAd
, TX_MAX_CNT2
, Value
);
2103 RTMP_IO_WRITE32(pAd
, TX_MAX_CNT3
, Value
);
2104 RTMP_IO_WRITE32(pAd
, TX_MAX_CNT4
, Value
);
2105 Value
= MGMT_RING_SIZE
;
2106 RTMP_IO_WRITE32(pAd
, TX_MGMTMAX_CNT
, Value
);
2108 // Write RX_RING_CSR register
2109 Value
= RX_RING_SIZE
;
2110 RTMP_IO_WRITE32(pAd
, RX_MAX_CNT
, Value
);
2116 RTMP_IO_WRITE32(pAd
, WMM_TXOP0_CFG
, csr0
.word
);
2117 if (pAd
->CommonCfg
.PhyMode
== PHY_11B
)
2119 csr0
.field
.Ac0Txop
= 192; // AC_VI: 192*32us ~= 6ms
2120 csr0
.field
.Ac1Txop
= 96; // AC_VO: 96*32us ~= 3ms
2124 csr0
.field
.Ac0Txop
= 96; // AC_VI: 96*32us ~= 3ms
2125 csr0
.field
.Ac1Txop
= 48; // AC_VO: 48*32us ~= 1.5ms
2127 RTMP_IO_WRITE32(pAd
, WMM_TXOP1_CFG
, csr0
.word
);
2131 // 3. Set DMA global configuration except TX_DMA_EN and RX_DMA_EN bits:
2135 RTMP_IO_READ32(pAd
, WPDMA_GLO_CFG
, &GloCfg
.word
);
2136 if ((GloCfg
.field
.TxDMABusy
== 0) && (GloCfg
.field
.RxDMABusy
== 0))
2139 RTMPusecDelay(1000);
2143 GloCfg
.word
&= 0xff0;
2144 GloCfg
.field
.EnTXWriteBackDDONE
=1;
2145 RTMP_IO_WRITE32(pAd
, WPDMA_GLO_CFG
, GloCfg
.word
);
2148 RTMP_IO_WRITE32(pAd
, DELAY_INT_CFG
, IntCfg
.word
);
2154 // Status = NICLoadFirmware(pAd);
2156 DBGPRINT(RT_DEBUG_TRACE
, ("<-- NICInitializeAdapter\n"));
2161 ========================================================================
2163 Routine Description:
2167 Adapter Pointer to our adapter
2172 IRQL = PASSIVE_LEVEL
2176 ========================================================================
2178 NDIS_STATUS
NICInitializeAsic(
2179 IN PRTMP_ADAPTER pAd
,
2180 IN BOOLEAN bHardReset
)
2184 UINT32 MacCsr12
= 0, Counter
= 0;
2194 DBGPRINT(RT_DEBUG_TRACE
, ("--> NICInitializeAsic\n"));
2197 if (bHardReset
== TRUE
)
2199 RTMP_IO_WRITE32(pAd
, MAC_SYS_CTRL
, 0x3);
2202 RTMP_IO_WRITE32(pAd
, MAC_SYS_CTRL
, 0x1);
2206 // Make sure MAC gets ready after NICLoadFirmware().
2210 //To avoid hang-on issue when interface up in kernel 2.4,
2211 //we use a local variable "MacCsr0" instead of using "pAd->MACVersion" directly.
2214 RTMP_IO_READ32(pAd
, MAC_CSR0
, &MacCsr0
);
2216 if ((MacCsr0
!= 0x00) && (MacCsr0
!= 0xFFFFFFFF))
2220 } while (Index
++ < 100);
2222 pAd
->MACVersion
= MacCsr0
;
2223 DBGPRINT(RT_DEBUG_TRACE
, ("MAC_CSR0 [ Ver:Rev=0x%08x]\n", pAd
->MACVersion
));
2224 // turn on bit13 (set to zero) after rt2860D. This is to solve high-current issue.
2225 RTMP_IO_READ32(pAd
, PBF_SYS_CTRL
, &MacCsr12
);
2226 MacCsr12
&= (~0x2000);
2227 RTMP_IO_WRITE32(pAd
, PBF_SYS_CTRL
, MacCsr12
);
2229 RTMP_IO_WRITE32(pAd
, MAC_SYS_CTRL
, 0x3);
2230 RTMP_IO_WRITE32(pAd
, USB_DMA_CFG
, 0x0);
2231 Status
= RTUSBVenderReset(pAd
);
2234 RTMP_IO_WRITE32(pAd
, MAC_SYS_CTRL
, 0x0);
2236 // Initialize MAC register to default value
2238 for (Index
= 0; Index
< NUM_MAC_REG_PARMS
; Index
++)
2240 RTMP_IO_WRITE32(pAd
, MACRegTable
[Index
].Register
, MACRegTable
[Index
].Value
);
2244 for(Index
=0; Index
<NUM_MAC_REG_PARMS
; Index
++)
2247 if ((MACRegTable
[Index
].Register
== TX_SW_CFG0
) && (IS_RT3070(pAd
) || IS_RT3071(pAd
)))
2249 MACRegTable
[Index
].Value
= 0x00000400;
2252 RTMP_IO_WRITE32(pAd
, (USHORT
)MACRegTable
[Index
].Register
, MACRegTable
[Index
].Value
);
2258 // According to Frank Hsu (from Gary Tsao)
2259 RTMP_IO_WRITE32(pAd
, (USHORT
)TX_SW_CFG0
, 0x00000400);
2261 // Initialize RT3070 serial MAC registers which is different from RT2870 serial
2262 RTUSBWriteMACRegister(pAd
, TX_SW_CFG1
, 0);
2263 RTUSBWriteMACRegister(pAd
, TX_SW_CFG2
, 0);
2270 for (Index
= 0; Index
< NUM_STA_MAC_REG_PARMS
; Index
++)
2273 RTMP_IO_WRITE32(pAd
, STAMACRegTable
[Index
].Register
, STAMACRegTable
[Index
].Value
);
2276 RTMP_IO_WRITE32(pAd
, (USHORT
)STAMACRegTable
[Index
].Register
, STAMACRegTable
[Index
].Value
);
2281 // Initialize RT3070 serial MAc registers which is different from RT2870 serial
2284 RTMP_IO_WRITE32(pAd
, TX_SW_CFG1
, 0);
2286 // RT3071 version E has fixed this issue
2287 if ((pAd
->MACVersion
& 0xffff) < 0x0211)
2289 if (pAd
->NicConfig2
.field
.DACTestBit
== 1)
2291 RTMP_IO_WRITE32(pAd
, TX_SW_CFG2
, 0x1F); // To fix throughput drop drastically
2295 RTMP_IO_WRITE32(pAd
, TX_SW_CFG2
, 0x0F); // To fix throughput drop drastically
2300 RTMP_IO_WRITE32(pAd
, TX_SW_CFG2
, 0x0);
2304 else if (IS_RT3070(pAd
))
2306 RTMP_IO_WRITE32(pAd
, TX_SW_CFG1
, 0);
2307 RTMP_IO_WRITE32(pAd
, TX_SW_CFG2
, 0x1F); // To fix throughput drop drastically
2312 // Before program BBP, we need to wait BBP/RF get wake up.
2317 RTMP_IO_READ32(pAd
, MAC_STATUS_CFG
, &MacCsr12
);
2319 if ((MacCsr12
& 0x03) == 0) // if BB.RF is stable
2322 DBGPRINT(RT_DEBUG_TRACE
, ("Check MAC_STATUS_CFG = Busy = %x\n", MacCsr12
));
2323 RTMPusecDelay(1000);
2324 } while (Index
++ < 100);
2326 // The commands to firmware should be after these commands, these commands will init firmware
2327 // PCI and USB are not the same because PCI driver needs to wait for PCI bus ready
2328 RTMP_IO_WRITE32(pAd
, H2M_BBP_AGENT
, 0); // initialize BBP R/W access agent
2329 RTMP_IO_WRITE32(pAd
, H2M_MAILBOX_CSR
, 0);
2330 RTMPusecDelay(1000);
2332 // Read BBP register, make sure BBP is up and running before write new data
2336 RTMP_BBP_IO_READ8_BY_REG_ID(pAd
, BBP_R0
, &R0
);
2337 DBGPRINT(RT_DEBUG_TRACE
, ("BBP version = %x\n", R0
));
2338 } while ((++Index
< 20) && ((R0
== 0xff) || (R0
== 0x00)));
2339 //ASSERT(Index < 20); //this will cause BSOD on Check-build driver
2341 if ((R0
== 0xff) || (R0
== 0x00))
2342 return NDIS_STATUS_FAILURE
;
2344 // Initialize BBP register to default value
2345 for (Index
= 0; Index
< NUM_BBP_REG_PARMS
; Index
++)
2347 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd
, BBPRegTable
[Index
].Register
, BBPRegTable
[Index
].Value
);
2351 // for rt2860E and after, init BBP_R84 with 0x19. This is for extension channel overlapping IOT.
2352 if ((pAd
->MACVersion
&0xffff) != 0x0101)
2353 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd
, BBP_R84
, 0x19);
2356 //write RT3070 BBP wchich different with 2870 after write RT2870 BBP
2359 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd
, BBP_R70
, 0x0a);
2360 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd
, BBP_R84
, 0x99);
2361 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd
, BBP_R105
, 0x05);
2366 // for rt2860E and after, init BBP_R84 with 0x19. This is for extension channel overlapping IOT.
2367 // RT3090 should not program BBP R84 to 0x19, otherwise TX will block.
2368 if (((pAd
->MACVersion
&0xffff) != 0x0101) && (!IS_RT30xx(pAd
)))
2369 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd
, BBP_R84
, 0x19);
2371 // add by johnli, RF power sequence setup
2373 { //update for RT3070/71/72/90/91/92.
2374 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd
, BBP_R79
, 0x13);
2375 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd
, BBP_R80
, 0x05);
2376 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd
, BBP_R81
, 0x33);
2384 if ((pAd
->MACVersion
& 0xffff) >= 0x0211)
2386 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd
, BBP_R103
, 0xc0);
2389 // improve power consumption
2390 RTMP_BBP_IO_READ8_BY_REG_ID(pAd
, BBP_R138
, &bbpreg
);
2391 if (pAd
->Antenna
.field
.TxPath
== 1)
2393 // turn off tx DAC_1
2394 bbpreg
= (bbpreg
| 0x20);
2397 if (pAd
->Antenna
.field
.RxPath
== 1)
2399 // turn off tx ADC_1
2402 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd
, BBP_R138
, bbpreg
);
2404 // improve power consumption in RT3071 Ver.E
2405 if ((pAd
->MACVersion
& 0xffff) >= 0x0211)
2407 RTMP_BBP_IO_READ8_BY_REG_ID(pAd
, BBP_R31
, &bbpreg
);
2409 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd
, BBP_R31
, bbpreg
);
2413 if (pAd
->MACVersion
== 0x28600100)
2415 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd
, BBP_R69
, 0x16);
2416 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd
, BBP_R73
, 0x12);
2419 if (pAd
->MACVersion
>= RALINK_2880E_VERSION
&& pAd
->MACVersion
< RALINK_3070_VERSION
) // 3*3
2421 // enlarge MAX_LEN_CFG
2423 RTMP_IO_READ32(pAd
, MAX_LEN_CFG
, &csr
);
2426 RTMP_IO_WRITE32(pAd
, MAX_LEN_CFG
, csr
);
2431 UCHAR MAC_Value
[]={0xff,0xff,0xff,0xff,0xff,0xff,0xff,0,0};
2433 //Initialize WCID table
2435 for(Index
=0 ;Index
< 254;Index
++)
2437 RTUSBMultiWrite(pAd
, (USHORT
)(MAC_WCID_BASE
+ Index
* 8), MAC_Value
, 8);
2442 // Add radio off control
2444 if (pAd
->StaCfg
.bRadio
== FALSE
)
2446 // RTMP_IO_WRITE32(pAd, PWR_PIN_CFG, 0x00001818);
2447 RTMP_SET_FLAG(pAd
, fRTMP_ADAPTER_RADIO_OFF
);
2448 DBGPRINT(RT_DEBUG_TRACE
, ("Set Radio Off\n"));
2452 // Clear raw counters
2453 RTMP_IO_READ32(pAd
, RX_STA_CNT0
, &Counter
);
2454 RTMP_IO_READ32(pAd
, RX_STA_CNT1
, &Counter
);
2455 RTMP_IO_READ32(pAd
, RX_STA_CNT2
, &Counter
);
2456 RTMP_IO_READ32(pAd
, TX_STA_CNT0
, &Counter
);
2457 RTMP_IO_READ32(pAd
, TX_STA_CNT1
, &Counter
);
2458 RTMP_IO_READ32(pAd
, TX_STA_CNT2
, &Counter
);
2460 // ASIC will keep garbage value after boot
2461 // Clear all seared key table when initial
2462 // This routine can be ignored in radio-ON/OFF operation.
2465 for (KeyIdx
= 0; KeyIdx
< 4; KeyIdx
++)
2467 RTMP_IO_WRITE32(pAd
, SHARED_KEY_MODE_BASE
+ 4*KeyIdx
, 0);
2470 // Clear all pairwise key table when initial
2471 for (KeyIdx
= 0; KeyIdx
< 256; KeyIdx
++)
2473 RTMP_IO_WRITE32(pAd
, MAC_WCID_ATTRIBUTE_BASE
+ (KeyIdx
* HW_WCID_ATTRI_SIZE
), 1);
2478 // It isn't necessary to clear this space when not hard reset.
2479 if (bHardReset
== TRUE
)
2481 // clear all on-chip BEACON frame space
2482 for (apidx
= 0; apidx
< HW_BEACON_MAX_COUNT
; apidx
++)
2484 for (i
= 0; i
< HW_BEACON_OFFSET
>>2; i
+=4)
2485 RTMP_IO_WRITE32(pAd
, pAd
->BeaconOffset
[apidx
] + i
, 0x00);
2489 AsicDisableSync(pAd
);
2490 // Clear raw counters
2491 RTMP_IO_READ32(pAd
, RX_STA_CNT0
, &Counter
);
2492 RTMP_IO_READ32(pAd
, RX_STA_CNT1
, &Counter
);
2493 RTMP_IO_READ32(pAd
, RX_STA_CNT2
, &Counter
);
2494 RTMP_IO_READ32(pAd
, TX_STA_CNT0
, &Counter
);
2495 RTMP_IO_READ32(pAd
, TX_STA_CNT1
, &Counter
);
2496 RTMP_IO_READ32(pAd
, TX_STA_CNT2
, &Counter
);
2497 // Default PCI clock cycle per ms is different as default setting, which is based on PCI.
2498 RTMP_IO_READ32(pAd
, USB_CYC_CFG
, &Counter
);
2499 Counter
&=0xffffff00;
2501 RTMP_IO_WRITE32(pAd
, USB_CYC_CFG
, Counter
);
2503 pAd
->bUseEfuse
=FALSE
;
2504 RTMP_IO_READ32(pAd
, EFUSE_CTRL
, &eFuseCtrl
);
2505 pAd
->bUseEfuse
= ( (eFuseCtrl
& 0x80000000) == 0x80000000) ? 1 : 0;
2508 DBGPRINT(RT_DEBUG_TRACE
, ("NVM is Efuse\n"));
2512 DBGPRINT(RT_DEBUG_TRACE
, ("NVM is EEPROM\n"));
2517 // for rt2860E and after, init TXOP_CTRL_CFG with 0x583f. This is for extension channel overlapping IOT.
2518 if ((pAd
->MACVersion
&0xffff) != 0x0101)
2519 RTMP_IO_WRITE32(pAd
, TXOP_CTRL_CFG
, 0x583f);
2522 DBGPRINT(RT_DEBUG_TRACE
, ("<-- NICInitializeAsic\n"));
2523 return NDIS_STATUS_SUCCESS
;
2528 VOID
NICRestoreBBPValue(
2529 IN PRTMP_ADAPTER pAd
)
2535 DBGPRINT(RT_DEBUG_TRACE
, ("---> NICRestoreBBPValue !!!!!!!!!!!!!!!!!!!!!!! \n"));
2536 // Initialize BBP register to default value (rtmp_init.c)
2537 for (index
= 0; index
< NUM_BBP_REG_PARMS
; index
++)
2539 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd
, BBPRegTable
[index
].Register
, BBPRegTable
[index
].Value
);
2541 // copy from (rtmp_init.c)
2542 if (pAd
->MACVersion
== 0x28600100)
2544 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd
, BBP_R69
, 0x16);
2545 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd
, BBP_R73
, 0x12);
2548 // copy from (connect.c LinkUp function)
2551 // Change to AP channel
2552 if ((pAd
->CommonCfg
.CentralChannel
> pAd
->CommonCfg
.Channel
) && (pAd
->MlmeAux
.HtCapability
.HtCapInfo
.ChannelWidth
== BW_40
))
2554 // Must using 40MHz.
2555 pAd
->CommonCfg
.BBPCurrentBW
= BW_40
;
2556 AsicSwitchChannel(pAd
, pAd
->CommonCfg
.CentralChannel
, FALSE
);
2557 AsicLockChannel(pAd
, pAd
->CommonCfg
.CentralChannel
);
2559 RTMP_BBP_IO_READ8_BY_REG_ID(pAd
, BBP_R4
, &Value
);
2562 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd
, BBP_R4
, Value
);
2564 // RX : control channel at lower
2565 RTMP_BBP_IO_READ8_BY_REG_ID(pAd
, BBP_R3
, &Value
);
2567 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd
, BBP_R3
, Value
);
2568 // Record BBPR3 setting, But don't keep R Antenna # information.
2569 pAd
->StaCfg
.BBPR3
= Value
;
2571 RTMP_IO_READ32(pAd
, TX_BAND_CFG
, &Data
);
2573 RTMP_IO_WRITE32(pAd
, TX_BAND_CFG
, Data
);
2575 if (pAd
->MACVersion
== 0x28600100)
2577 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd
, BBP_R69
, 0x1A);
2578 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd
, BBP_R70
, 0x0A);
2579 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd
, BBP_R73
, 0x16);
2580 DBGPRINT(RT_DEBUG_TRACE
, ("!!!rt2860C !!! \n" ));
2583 DBGPRINT(RT_DEBUG_TRACE
, ("!!!40MHz Lower LINK UP !!! Control Channel at Below. Central = %d \n", pAd
->CommonCfg
.CentralChannel
));
2585 else if ((pAd
->CommonCfg
.CentralChannel
< pAd
->CommonCfg
.Channel
) && (pAd
->MlmeAux
.HtCapability
.HtCapInfo
.ChannelWidth
== BW_40
))
2587 // Must using 40MHz.
2588 pAd
->CommonCfg
.BBPCurrentBW
= BW_40
;
2589 AsicSwitchChannel(pAd
, pAd
->CommonCfg
.CentralChannel
, FALSE
);
2590 AsicLockChannel(pAd
, pAd
->CommonCfg
.CentralChannel
);
2592 RTMP_BBP_IO_READ8_BY_REG_ID(pAd
, BBP_R4
, &Value
);
2595 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd
, BBP_R4
, Value
);
2597 RTMP_IO_READ32(pAd
, TX_BAND_CFG
, &Data
);
2599 RTMP_IO_WRITE32(pAd
, TX_BAND_CFG
, Data
);
2601 RTMP_BBP_IO_READ8_BY_REG_ID(pAd
, BBP_R3
, &Value
);
2603 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd
, BBP_R3
, Value
);
2604 // Record BBPR3 setting, But don't keep R Antenna # information.
2605 pAd
->StaCfg
.BBPR3
= Value
;
2607 if (pAd
->MACVersion
== 0x28600100)
2609 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd
, BBP_R69
, 0x1A);
2610 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd
, BBP_R70
, 0x0A);
2611 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd
, BBP_R73
, 0x16);
2612 DBGPRINT(RT_DEBUG_TRACE
, ("!!!rt2860C !!! \n" ));
2615 DBGPRINT(RT_DEBUG_TRACE
, ("!!!40MHz Upper LINK UP !!! Control Channel at UpperCentral = %d \n", pAd
->CommonCfg
.CentralChannel
));
2619 pAd
->CommonCfg
.BBPCurrentBW
= BW_20
;
2620 AsicSwitchChannel(pAd
, pAd
->CommonCfg
.Channel
, FALSE
);
2621 AsicLockChannel(pAd
, pAd
->CommonCfg
.Channel
);
2623 RTMP_BBP_IO_READ8_BY_REG_ID(pAd
, BBP_R4
, &Value
);
2625 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd
, BBP_R4
, Value
);
2627 RTMP_IO_READ32(pAd
, TX_BAND_CFG
, &Data
);
2629 RTMP_IO_WRITE32(pAd
, TX_BAND_CFG
, Data
);
2631 RTMP_BBP_IO_READ8_BY_REG_ID(pAd
, BBP_R3
, &Value
);
2633 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd
, BBP_R3
, Value
);
2634 // Record BBPR3 setting, But don't keep R Antenna # information.
2635 pAd
->StaCfg
.BBPR3
= Value
;
2637 if (pAd
->MACVersion
== 0x28600100)
2639 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd
, BBP_R69
, 0x16);
2640 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd
, BBP_R70
, 0x08);
2641 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd
, BBP_R73
, 0x11);
2642 DBGPRINT(RT_DEBUG_TRACE
, ("!!!rt2860C !!! \n" ));
2645 DBGPRINT(RT_DEBUG_TRACE
, ("!!!20MHz LINK UP !!! \n" ));
2649 DBGPRINT(RT_DEBUG_TRACE
, ("<--- NICRestoreBBPValue !!!!!!!!!!!!!!!!!!!!!!! \n"));
2654 ========================================================================
2656 Routine Description:
2660 Adapter Pointer to our adapter
2665 IRQL = PASSIVE_LEVEL
2668 Reset NIC to initial state AS IS system boot up time.
2670 ========================================================================
2673 IN PRTMP_ADAPTER pAd
)
2676 DBGPRINT(RT_DEBUG_TRACE
, ("--> NICIssueReset\n"));
2678 // Disable Rx, register value supposed will remain after reset
2679 RTMP_IO_READ32(pAd
, MAC_SYS_CTRL
, &Value
);
2680 Value
&= (0xfffffff3);
2681 RTMP_IO_WRITE32(pAd
, MAC_SYS_CTRL
, Value
);
2683 // Issue reset and clear from reset state
2684 RTMP_IO_WRITE32(pAd
, MAC_SYS_CTRL
, 0x03); // 2004-09-17 change from 0x01
2685 RTMP_IO_WRITE32(pAd
, MAC_SYS_CTRL
, 0x00);
2687 DBGPRINT(RT_DEBUG_TRACE
, ("<-- NICIssueReset\n"));
2691 ========================================================================
2693 Routine Description:
2694 Check ASIC registers and find any reason the system might hang
2697 Adapter Pointer to our adapter
2702 IRQL = DISPATCH_LEVEL
2704 ========================================================================
2706 BOOLEAN
NICCheckForHang(
2707 IN PRTMP_ADAPTER pAd
)
2712 VOID
NICUpdateFifoStaCounters(
2713 IN PRTMP_ADAPTER pAd
)
2715 TX_STA_FIFO_STRUC StaFifo
;
2716 MAC_TABLE_ENTRY
*pEntry
;
2718 UCHAR pid
= 0, wcid
= 0;
2724 RTMP_IO_READ32(pAd
, TX_STA_FIFO
, &StaFifo
.word
);
2726 if (StaFifo
.field
.bValid
== 0)
2729 wcid
= (UCHAR
)StaFifo
.field
.wcid
;
2732 /* ignore NoACK and MGMT frame use 0xFF as WCID */
2733 if ((StaFifo
.field
.TxAckRequired
== 0) || (wcid
>= MAX_LEN_OF_MAC_TABLE
))
2739 /* PID store Tx MCS Rate */
2740 pid
= (UCHAR
)StaFifo
.field
.PidType
;
2742 pEntry
= &pAd
->MacTab
.Content
[wcid
];
2744 pEntry
->DebugFIFOCount
++;
2746 if (StaFifo
.field
.TxBF
) // 3*3
2747 pEntry
->TxBFCount
++;
2749 #ifdef UAPSD_AP_SUPPORT
2750 UAPSD_SP_AUE_Handle(pAd
, pEntry
, StaFifo
.field
.TxSuccess
);
2751 #endif // UAPSD_AP_SUPPORT //
2753 if (!StaFifo
.field
.TxSuccess
)
2755 pEntry
->FIFOCount
++;
2756 pEntry
->OneSecTxFailCount
++;
2758 if (pEntry
->FIFOCount
>= 1)
2760 DBGPRINT(RT_DEBUG_TRACE
, ("#"));
2761 pEntry
->NoBADataCountDown
= 64;
2763 if(pEntry
->PsMode
== PWR_ACTIVE
)
2766 for (tid
=0; tid
<NUM_OF_TID
; tid
++)
2768 BAOriSessionTearDown(pAd
, pEntry
->Aid
, tid
, FALSE
, FALSE
);
2771 // Update the continuous transmission counter except PS mode
2772 pEntry
->ContinueTxFailCnt
++;
2776 // Clear the FIFOCount when sta in Power Save mode. Basically we assume
2777 // this tx error happened due to sta just go to sleep.
2778 pEntry
->FIFOCount
= 0;
2779 pEntry
->ContinueTxFailCnt
= 0;
2785 if ((pEntry
->PsMode
!= PWR_SAVE
) && (pEntry
->NoBADataCountDown
> 0))
2787 pEntry
->NoBADataCountDown
--;
2788 if (pEntry
->NoBADataCountDown
==0)
2790 DBGPRINT(RT_DEBUG_TRACE
, ("@\n"));
2794 pEntry
->FIFOCount
= 0;
2795 pEntry
->OneSecTxNoRetryOkCount
++;
2796 // update NoDataIdleCount when sucessful send packet to STA.
2797 pEntry
->NoDataIdleCount
= 0;
2798 pEntry
->ContinueTxFailCnt
= 0;
2801 succMCS
= StaFifo
.field
.SuccessRate
& 0x7F;
2803 reTry
= pid
- succMCS
;
2805 if (StaFifo
.field
.TxSuccess
)
2807 pEntry
->TXMCSExpected
[pid
]++;
2810 pEntry
->TXMCSSuccessful
[pid
]++;
2814 pEntry
->TXMCSAutoFallBack
[pid
][succMCS
]++;
2819 pEntry
->TXMCSFailed
[pid
]++;
2824 if ((pid
>= 12) && succMCS
<=7)
2828 pEntry
->OneSecTxRetryOkCount
+= reTry
;
2832 // ASIC store 16 stack
2833 } while ( i
< (2*TX_RING_SIZE
) );
2838 ========================================================================
2840 Routine Description:
2841 Read statistical counters from hardware registers and record them
2842 in software variables for later on query
2845 pAd Pointer to our adapter
2850 IRQL = DISPATCH_LEVEL
2852 ========================================================================
2854 VOID
NICUpdateRawCounters(
2855 IN PRTMP_ADAPTER pAd
)
2858 RX_STA_CNT0_STRUC RxStaCnt0
;
2859 RX_STA_CNT1_STRUC RxStaCnt1
;
2860 RX_STA_CNT2_STRUC RxStaCnt2
;
2861 TX_STA_CNT0_STRUC TxStaCnt0
;
2862 TX_STA_CNT1_STRUC StaTx1
;
2863 TX_STA_CNT2_STRUC StaTx2
;
2864 TX_AGG_CNT_STRUC TxAggCnt
;
2865 TX_AGG_CNT0_STRUC TxAggCnt0
;
2866 TX_AGG_CNT1_STRUC TxAggCnt1
;
2867 TX_AGG_CNT2_STRUC TxAggCnt2
;
2868 TX_AGG_CNT3_STRUC TxAggCnt3
;
2869 TX_AGG_CNT4_STRUC TxAggCnt4
;
2870 TX_AGG_CNT5_STRUC TxAggCnt5
;
2871 TX_AGG_CNT6_STRUC TxAggCnt6
;
2872 TX_AGG_CNT7_STRUC TxAggCnt7
;
2874 RTMP_IO_READ32(pAd
, RX_STA_CNT0
, &RxStaCnt0
.word
);
2875 RTMP_IO_READ32(pAd
, RX_STA_CNT2
, &RxStaCnt2
.word
);
2878 RTMP_IO_READ32(pAd
, RX_STA_CNT1
, &RxStaCnt1
.word
);
2879 // Update RX PLCP error counter
2880 pAd
->PrivateInfo
.PhyRxErrCnt
+= RxStaCnt1
.field
.PlcpErr
;
2881 // Update False CCA counter
2882 pAd
->RalinkCounters
.OneSecFalseCCACnt
+= RxStaCnt1
.field
.FalseCca
;
2885 // Update FCS counters
2886 OldValue
= pAd
->WlanCounters
.FCSErrorCount
.u
.LowPart
;
2887 pAd
->WlanCounters
.FCSErrorCount
.u
.LowPart
+= (RxStaCnt0
.field
.CrcErr
); // >> 7);
2888 if (pAd
->WlanCounters
.FCSErrorCount
.u
.LowPart
< OldValue
)
2889 pAd
->WlanCounters
.FCSErrorCount
.u
.HighPart
++;
2891 // Add FCS error count to private counters
2892 pAd
->RalinkCounters
.OneSecRxFcsErrCnt
+= RxStaCnt0
.field
.CrcErr
;
2893 OldValue
= pAd
->RalinkCounters
.RealFcsErrCount
.u
.LowPart
;
2894 pAd
->RalinkCounters
.RealFcsErrCount
.u
.LowPart
+= RxStaCnt0
.field
.CrcErr
;
2895 if (pAd
->RalinkCounters
.RealFcsErrCount
.u
.LowPart
< OldValue
)
2896 pAd
->RalinkCounters
.RealFcsErrCount
.u
.HighPart
++;
2898 // Update Duplicate Rcv check
2899 pAd
->RalinkCounters
.DuplicateRcv
+= RxStaCnt2
.field
.RxDupliCount
;
2900 pAd
->WlanCounters
.FrameDuplicateCount
.u
.LowPart
+= RxStaCnt2
.field
.RxDupliCount
;
2901 // Update RX Overflow counter
2902 pAd
->Counters8023
.RxNoBuffer
+= (RxStaCnt2
.field
.RxFifoOverflowCount
);
2905 if (pAd
->RalinkCounters
.RxCount
!= pAd
->watchDogRxCnt
)
2907 pAd
->watchDogRxCnt
= pAd
->RalinkCounters
.RxCount
;
2908 pAd
->watchDogRxOverFlowCnt
= 0;
2912 if (RxStaCnt2
.field
.RxFifoOverflowCount
)
2913 pAd
->watchDogRxOverFlowCnt
++;
2915 pAd
->watchDogRxOverFlowCnt
= 0;
2920 if (!pAd
->bUpdateBcnCntDone
)
2922 // Update BEACON sent count
2923 RTMP_IO_READ32(pAd
, TX_STA_CNT0
, &TxStaCnt0
.word
);
2924 RTMP_IO_READ32(pAd
, TX_STA_CNT1
, &StaTx1
.word
);
2925 RTMP_IO_READ32(pAd
, TX_STA_CNT2
, &StaTx2
.word
);
2926 pAd
->RalinkCounters
.OneSecBeaconSentCnt
+= TxStaCnt0
.field
.TxBeaconCount
;
2927 pAd
->RalinkCounters
.OneSecTxRetryOkCount
+= StaTx1
.field
.TxRetransmit
;
2928 pAd
->RalinkCounters
.OneSecTxNoRetryOkCount
+= StaTx1
.field
.TxSuccess
;
2929 pAd
->RalinkCounters
.OneSecTxFailCount
+= TxStaCnt0
.field
.TxFailCount
;
2930 pAd
->WlanCounters
.TransmittedFragmentCount
.u
.LowPart
+= StaTx1
.field
.TxSuccess
;
2931 pAd
->WlanCounters
.RetryCount
.u
.LowPart
+= StaTx1
.field
.TxRetransmit
;
2932 pAd
->WlanCounters
.FailedCount
.u
.LowPart
+= TxStaCnt0
.field
.TxFailCount
;
2936 RTMP_IO_READ32(pAd
, TX_AGG_CNT
, &TxAggCnt
.word
);
2937 RTMP_IO_READ32(pAd
, TX_AGG_CNT0
, &TxAggCnt0
.word
);
2938 RTMP_IO_READ32(pAd
, TX_AGG_CNT1
, &TxAggCnt1
.word
);
2939 RTMP_IO_READ32(pAd
, TX_AGG_CNT2
, &TxAggCnt2
.word
);
2940 RTMP_IO_READ32(pAd
, TX_AGG_CNT3
, &TxAggCnt3
.word
);
2941 RTMP_IO_READ32(pAd
, TX_AGG_CNT4
, &TxAggCnt4
.word
);
2942 RTMP_IO_READ32(pAd
, TX_AGG_CNT5
, &TxAggCnt5
.word
);
2943 RTMP_IO_READ32(pAd
, TX_AGG_CNT6
, &TxAggCnt6
.word
);
2944 RTMP_IO_READ32(pAd
, TX_AGG_CNT7
, &TxAggCnt7
.word
);
2945 pAd
->RalinkCounters
.TxAggCount
+= TxAggCnt
.field
.AggTxCount
;
2946 pAd
->RalinkCounters
.TxNonAggCount
+= TxAggCnt
.field
.NonAggTxCount
;
2947 pAd
->RalinkCounters
.TxAgg1MPDUCount
+= TxAggCnt0
.field
.AggSize1Count
;
2948 pAd
->RalinkCounters
.TxAgg2MPDUCount
+= TxAggCnt0
.field
.AggSize2Count
;
2950 pAd
->RalinkCounters
.TxAgg3MPDUCount
+= TxAggCnt1
.field
.AggSize3Count
;
2951 pAd
->RalinkCounters
.TxAgg4MPDUCount
+= TxAggCnt1
.field
.AggSize4Count
;
2952 pAd
->RalinkCounters
.TxAgg5MPDUCount
+= TxAggCnt2
.field
.AggSize5Count
;
2953 pAd
->RalinkCounters
.TxAgg6MPDUCount
+= TxAggCnt2
.field
.AggSize6Count
;
2955 pAd
->RalinkCounters
.TxAgg7MPDUCount
+= TxAggCnt3
.field
.AggSize7Count
;
2956 pAd
->RalinkCounters
.TxAgg8MPDUCount
+= TxAggCnt3
.field
.AggSize8Count
;
2957 pAd
->RalinkCounters
.TxAgg9MPDUCount
+= TxAggCnt4
.field
.AggSize9Count
;
2958 pAd
->RalinkCounters
.TxAgg10MPDUCount
+= TxAggCnt4
.field
.AggSize10Count
;
2960 pAd
->RalinkCounters
.TxAgg11MPDUCount
+= TxAggCnt5
.field
.AggSize11Count
;
2961 pAd
->RalinkCounters
.TxAgg12MPDUCount
+= TxAggCnt5
.field
.AggSize12Count
;
2962 pAd
->RalinkCounters
.TxAgg13MPDUCount
+= TxAggCnt6
.field
.AggSize13Count
;
2963 pAd
->RalinkCounters
.TxAgg14MPDUCount
+= TxAggCnt6
.field
.AggSize14Count
;
2965 pAd
->RalinkCounters
.TxAgg15MPDUCount
+= TxAggCnt7
.field
.AggSize15Count
;
2966 pAd
->RalinkCounters
.TxAgg16MPDUCount
+= TxAggCnt7
.field
.AggSize16Count
;
2968 // Calculate the transmitted A-MPDU count
2969 pAd
->RalinkCounters
.TransmittedAMPDUCount
.u
.LowPart
+= TxAggCnt0
.field
.AggSize1Count
;
2970 pAd
->RalinkCounters
.TransmittedAMPDUCount
.u
.LowPart
+= (TxAggCnt0
.field
.AggSize2Count
/ 2);
2972 pAd
->RalinkCounters
.TransmittedAMPDUCount
.u
.LowPart
+= (TxAggCnt1
.field
.AggSize3Count
/ 3);
2973 pAd
->RalinkCounters
.TransmittedAMPDUCount
.u
.LowPart
+= (TxAggCnt1
.field
.AggSize4Count
/ 4);
2975 pAd
->RalinkCounters
.TransmittedAMPDUCount
.u
.LowPart
+= (TxAggCnt2
.field
.AggSize5Count
/ 5);
2976 pAd
->RalinkCounters
.TransmittedAMPDUCount
.u
.LowPart
+= (TxAggCnt2
.field
.AggSize6Count
/ 6);
2978 pAd
->RalinkCounters
.TransmittedAMPDUCount
.u
.LowPart
+= (TxAggCnt3
.field
.AggSize7Count
/ 7);
2979 pAd
->RalinkCounters
.TransmittedAMPDUCount
.u
.LowPart
+= (TxAggCnt3
.field
.AggSize8Count
/ 8);
2981 pAd
->RalinkCounters
.TransmittedAMPDUCount
.u
.LowPart
+= (TxAggCnt4
.field
.AggSize9Count
/ 9);
2982 pAd
->RalinkCounters
.TransmittedAMPDUCount
.u
.LowPart
+= (TxAggCnt4
.field
.AggSize10Count
/ 10);
2984 pAd
->RalinkCounters
.TransmittedAMPDUCount
.u
.LowPart
+= (TxAggCnt5
.field
.AggSize11Count
/ 11);
2985 pAd
->RalinkCounters
.TransmittedAMPDUCount
.u
.LowPart
+= (TxAggCnt5
.field
.AggSize12Count
/ 12);
2987 pAd
->RalinkCounters
.TransmittedAMPDUCount
.u
.LowPart
+= (TxAggCnt6
.field
.AggSize13Count
/ 13);
2988 pAd
->RalinkCounters
.TransmittedAMPDUCount
.u
.LowPart
+= (TxAggCnt6
.field
.AggSize14Count
/ 14);
2990 pAd
->RalinkCounters
.TransmittedAMPDUCount
.u
.LowPart
+= (TxAggCnt7
.field
.AggSize15Count
/ 15);
2991 pAd
->RalinkCounters
.TransmittedAMPDUCount
.u
.LowPart
+= (TxAggCnt7
.field
.AggSize16Count
/ 16);
3000 ========================================================================
3002 Routine Description:
3003 Reset NIC from error
3006 Adapter Pointer to our adapter
3011 IRQL = PASSIVE_LEVEL
3014 Reset NIC from error state
3016 ========================================================================
3018 VOID
NICResetFromError(
3019 IN PRTMP_ADAPTER pAd
)
3021 // Reset BBP (according to alex, reset ASIC will force reset BBP
3022 // Therefore, skip the reset BBP
3023 // RTMP_IO_WRITE32(pAd, MAC_CSR1, 0x2);
3025 RTMP_IO_WRITE32(pAd
, MAC_SYS_CTRL
, 0x1);
3026 // Remove ASIC from reset state
3027 RTMP_IO_WRITE32(pAd
, MAC_SYS_CTRL
, 0x0);
3029 NICInitializeAdapter(pAd
, FALSE
);
3030 NICInitAsicFromEEPROM(pAd
);
3032 // Switch to current channel, since during reset process, the connection should remains on.
3033 AsicSwitchChannel(pAd
, pAd
->CommonCfg
.CentralChannel
, FALSE
);
3034 AsicLockChannel(pAd
, pAd
->CommonCfg
.CentralChannel
);
3038 ========================================================================
3040 Routine Description:
3041 erase 8051 firmware image in MAC ASIC
3044 Adapter Pointer to our adapter
3046 IRQL = PASSIVE_LEVEL
3048 ========================================================================
3050 VOID
NICEraseFirmware(
3051 IN PRTMP_ADAPTER pAd
)
3055 for(i
=0; i
<MAX_FIRMWARE_IMAGE_SIZE
; i
+=4)
3056 RTMP_IO_WRITE32(pAd
, FIRMWARE_IMAGE_BASE
+ i
, 0);
3058 }/* End of NICEraseFirmware */
3061 ========================================================================
3063 Routine Description:
3064 Load 8051 firmware RT2561.BIN file into MAC ASIC
3067 Adapter Pointer to our adapter
3070 NDIS_STATUS_SUCCESS firmware image load ok
3071 NDIS_STATUS_FAILURE image not found
3073 IRQL = PASSIVE_LEVEL
3075 ========================================================================
3077 NDIS_STATUS
NICLoadFirmware(
3078 IN PRTMP_ADAPTER pAd
)
3080 NDIS_STATUS Status
= NDIS_STATUS_SUCCESS
;
3081 PUCHAR pFirmwareImage
;
3082 ULONG FileLength
, Index
;
3086 UINT32 Version
= (pAd
->MACVersion
>> 16);
3089 pFirmwareImage
= FirmwareImage
;
3090 FileLength
= sizeof(FirmwareImage
);
3092 // New 8k byte firmware size for RT3071/RT3072
3093 //printk("Usb Chip\n");
3094 if (FIRMWAREIMAGE_LENGTH
== FIRMWAREIMAGE_MAX_LENGTH
)
3095 //The firmware image consists of two parts. One is the origianl and the other is the new.
3098 if ((Version
!= 0x2860) && (Version
!= 0x2872) && (Version
!= 0x3070))
3099 { // Use Firmware V2.
3100 //printk("KH:Use New Version,part2\n");
3101 pFirmwareImage
= (PUCHAR
)&FirmwareImage
[FIRMWAREIMAGEV1_LENGTH
];
3102 FileLength
= FIRMWAREIMAGEV2_LENGTH
;
3106 //printk("KH:Use New Version,part1\n");
3107 pFirmwareImage
= FirmwareImage
;
3108 FileLength
= FIRMWAREIMAGEV1_LENGTH
;
3113 DBGPRINT(RT_DEBUG_ERROR
, ("KH: bin file should be 8KB.\n"));
3114 Status
= NDIS_STATUS_FAILURE
;
3119 RT28XX_WRITE_FIRMWARE(pAd
, pFirmwareImage
, FileLength
);
3121 /* check if MCU is ready */
3125 RTMP_IO_READ32(pAd
, PBF_SYS_CTRL
, &MacReg
);
3130 RTMPusecDelay(1000);
3131 } while (Index
++ < 1000);
3135 Status
= NDIS_STATUS_FAILURE
;
3136 DBGPRINT(RT_DEBUG_ERROR
, ("NICLoadFirmware: MCU is not ready\n\n\n"));
3139 DBGPRINT(RT_DEBUG_TRACE
,
3140 ("<=== %s (status=%d)\n", __func__
, Status
));
3142 } /* End of NICLoadFirmware */
3146 ========================================================================
3148 Routine Description:
3149 Load Tx rate switching parameters
3152 Adapter Pointer to our adapter
3155 NDIS_STATUS_SUCCESS firmware image load ok
3156 NDIS_STATUS_FAILURE image not found
3158 IRQL = PASSIVE_LEVEL
3161 1. (B0: Valid Item number) (B1:Initial item from zero)
3162 2. Item Number(Dec) Mode(Hex) Current MCS(Dec) TrainUp(Dec) TrainDown(Dec)
3164 ========================================================================
3166 NDIS_STATUS
NICLoadRateSwitchingParams(
3167 IN PRTMP_ADAPTER pAd
)
3169 return NDIS_STATUS_SUCCESS
;
3173 ========================================================================
3175 Routine Description:
3176 if pSrc1 all zero with length Length, return 0.
3177 If not all zero, return 1
3186 IRQL = DISPATCH_LEVEL
3190 ========================================================================
3192 ULONG
RTMPNotAllZero(
3199 pMem1
= (PUCHAR
) pSrc1
;
3201 for (Index
= 0; Index
< Length
; Index
++)
3203 if (pMem1
[Index
] != 0x0)
3209 if (Index
== Length
)
3220 ========================================================================
3222 Routine Description:
3223 Compare two memory block
3226 pSrc1 Pointer to first memory address
3227 pSrc2 Pointer to second memory address
3231 1: pSrc1 memory is larger
3232 2: pSrc2 memory is larger
3234 IRQL = DISPATCH_LEVEL
3238 ========================================================================
3240 ULONG
RTMPCompareMemory(
3249 pMem1
= (PUCHAR
) pSrc1
;
3250 pMem2
= (PUCHAR
) pSrc2
;
3252 for (Index
= 0; Index
< Length
; Index
++)
3254 if (pMem1
[Index
] > pMem2
[Index
])
3256 else if (pMem1
[Index
] < pMem2
[Index
])
3265 ========================================================================
3267 Routine Description:
3268 Zero out memory block
3271 pSrc1 Pointer to memory address
3277 IRQL = PASSIVE_LEVEL
3278 IRQL = DISPATCH_LEVEL
3282 ========================================================================
3284 VOID
RTMPZeroMemory(
3291 pMem
= (PUCHAR
) pSrc
;
3293 for (Index
= 0; Index
< Length
; Index
++)
3299 VOID
RTMPFillMemory(
3307 pMem
= (PUCHAR
) pSrc
;
3309 for (Index
= 0; Index
< Length
; Index
++)
3316 ========================================================================
3318 Routine Description:
3319 Copy data from memory block 1 to memory block 2
3322 pDest Pointer to destination memory address
3323 pSrc Pointer to source memory address
3329 IRQL = PASSIVE_LEVEL
3330 IRQL = DISPATCH_LEVEL
3334 ========================================================================
3336 VOID
RTMPMoveMemory(
3345 ASSERT((Length
==0) || (pDest
&& pSrc
));
3347 pMem1
= (PUCHAR
) pDest
;
3348 pMem2
= (PUCHAR
) pSrc
;
3350 for (Index
= 0; Index
< Length
; Index
++)
3352 pMem1
[Index
] = pMem2
[Index
];
3357 ========================================================================
3359 Routine Description:
3360 Initialize port configuration structure
3363 Adapter Pointer to our adapter
3368 IRQL = PASSIVE_LEVEL
3372 ========================================================================
3375 IN PRTMP_ADAPTER pAd
)
3377 UINT key_index
, bss_index
;
3379 DBGPRINT(RT_DEBUG_TRACE
, ("--> UserCfgInit\n"));
3382 // part I. intialize common configuration
3385 pAd
->BulkOutReq
= 0;
3387 pAd
->BulkOutComplete
= 0;
3388 pAd
->BulkOutCompleteOther
= 0;
3389 pAd
->BulkOutCompleteCancel
= 0;
3391 pAd
->BulkInComplete
= 0;
3392 pAd
->BulkInCompleteFail
= 0;
3394 //pAd->QuickTimerP = 100;
3395 //pAd->TurnAggrBulkInCount = 0;
3396 pAd
->bUsbTxBulkAggre
= 0;
3398 // init as unsed value to ensure driver will set to MCU once.
3399 pAd
->LedIndicatorStregth
= 0xFF;
3401 pAd
->CommonCfg
.MaxPktOneTxBulk
= 2;
3402 pAd
->CommonCfg
.TxBulkFactor
= 1;
3403 pAd
->CommonCfg
.RxBulkFactor
=1;
3405 pAd
->CommonCfg
.TxPower
= 100; //mW
3407 NdisZeroMemory(&pAd
->CommonCfg
.IOTestParm
, sizeof(pAd
->CommonCfg
.IOTestParm
));
3410 for(key_index
=0; key_index
<SHARE_KEY_NUM
; key_index
++)
3412 for(bss_index
= 0; bss_index
< MAX_MBSSID_NUM
; bss_index
++)
3414 pAd
->SharedKey
[bss_index
][key_index
].KeyLen
= 0;
3415 pAd
->SharedKey
[bss_index
][key_index
].CipherAlg
= CIPHER_NONE
;
3420 pAd
->EepromAccess
= FALSE
;
3422 pAd
->Antenna
.word
= 0;
3423 pAd
->CommonCfg
.BBPCurrentBW
= BW_20
;
3425 pAd
->LedCntl
.word
= 0;
3427 pAd
->LedIndicatorStregth
= 0;
3428 pAd
->RLnkCtrlOffset
= 0;
3429 pAd
->HostLnkCtrlOffset
= 0;
3430 pAd
->CheckDmaBusyCount
= 0;
3433 pAd
->bAutoTxAgcA
= FALSE
; // Default is OFF
3434 pAd
->bAutoTxAgcG
= FALSE
; // Default is OFF
3435 pAd
->RfIcType
= RFIC_2820
;
3437 // Init timer for reset complete event
3438 pAd
->CommonCfg
.CentralChannel
= 1;
3439 pAd
->bForcePrintTX
= FALSE
;
3440 pAd
->bForcePrintRX
= FALSE
;
3441 pAd
->bStaFifoTest
= FALSE
;
3442 pAd
->bProtectionTest
= FALSE
;
3443 pAd
->bHCCATest
= FALSE
;
3444 pAd
->bGenOneHCCA
= FALSE
;
3445 pAd
->CommonCfg
.Dsifs
= 10; // in units of usec
3446 pAd
->CommonCfg
.TxPower
= 100; //mW
3447 pAd
->CommonCfg
.TxPowerPercentage
= 0xffffffff; // AUTO
3448 pAd
->CommonCfg
.TxPowerDefault
= 0xffffffff; // AUTO
3449 pAd
->CommonCfg
.TxPreamble
= Rt802_11PreambleAuto
; // use Long preamble on TX by defaut
3450 pAd
->CommonCfg
.bUseZeroToDisableFragment
= FALSE
;
3451 pAd
->CommonCfg
.RtsThreshold
= 2347;
3452 pAd
->CommonCfg
.FragmentThreshold
= 2346;
3453 pAd
->CommonCfg
.UseBGProtection
= 0; // 0: AUTO
3454 pAd
->CommonCfg
.bEnableTxBurst
= TRUE
; //0;
3455 pAd
->CommonCfg
.PhyMode
= 0xff; // unknown
3456 pAd
->CommonCfg
.BandState
= UNKNOWN_BAND
;
3457 pAd
->CommonCfg
.RadarDetect
.CSPeriod
= 10;
3458 pAd
->CommonCfg
.RadarDetect
.CSCount
= 0;
3459 pAd
->CommonCfg
.RadarDetect
.RDMode
= RD_NORMAL_MODE
;
3460 pAd
->CommonCfg
.RadarDetect
.ChMovingTime
= 65;
3461 pAd
->CommonCfg
.RadarDetect
.LongPulseRadarTh
= 3;
3462 pAd
->CommonCfg
.bAPSDCapable
= FALSE
;
3463 pAd
->CommonCfg
.bNeedSendTriggerFrame
= FALSE
;
3464 pAd
->CommonCfg
.TriggerTimerCount
= 0;
3465 pAd
->CommonCfg
.bAPSDForcePowerSave
= FALSE
;
3466 pAd
->CommonCfg
.bCountryFlag
= FALSE
;
3467 pAd
->CommonCfg
.TxStream
= 0;
3468 pAd
->CommonCfg
.RxStream
= 0;
3470 NdisZeroMemory(&pAd
->BeaconTxWI
, sizeof(pAd
->BeaconTxWI
));
3472 NdisZeroMemory(&pAd
->CommonCfg
.HtCapability
, sizeof(pAd
->CommonCfg
.HtCapability
));
3473 pAd
->HTCEnable
= FALSE
;
3474 pAd
->bBroadComHT
= FALSE
;
3475 pAd
->CommonCfg
.bRdg
= FALSE
;
3477 NdisZeroMemory(&pAd
->CommonCfg
.AddHTInfo
, sizeof(pAd
->CommonCfg
.AddHTInfo
));
3478 pAd
->CommonCfg
.BACapability
.field
.MMPSmode
= MMPS_ENABLE
;
3479 pAd
->CommonCfg
.BACapability
.field
.MpduDensity
= 0;
3480 pAd
->CommonCfg
.BACapability
.field
.Policy
= IMMED_BA
;
3481 pAd
->CommonCfg
.BACapability
.field
.RxBAWinLimit
= 64; //32;
3482 pAd
->CommonCfg
.BACapability
.field
.TxBAWinLimit
= 64; //32;
3483 DBGPRINT(RT_DEBUG_TRACE
, ("--> UserCfgInit. BACapability = 0x%x\n", pAd
->CommonCfg
.BACapability
.word
));
3485 pAd
->CommonCfg
.BACapability
.field
.AutoBA
= FALSE
;
3486 BATableInit(pAd
, &pAd
->BATable
);
3488 pAd
->CommonCfg
.bExtChannelSwitchAnnouncement
= 1;
3489 pAd
->CommonCfg
.bHTProtect
= 1;
3490 pAd
->CommonCfg
.bMIMOPSEnable
= TRUE
;
3491 pAd
->CommonCfg
.bBADecline
= FALSE
;
3492 pAd
->CommonCfg
.bDisableReordering
= FALSE
;
3494 pAd
->CommonCfg
.TxBASize
= 7;
3496 pAd
->CommonCfg
.REGBACapability
.word
= pAd
->CommonCfg
.BACapability
.word
;
3498 //pAd->CommonCfg.HTPhyMode.field.BW = BW_20;
3499 //pAd->CommonCfg.HTPhyMode.field.MCS = MCS_AUTO;
3500 //pAd->CommonCfg.HTPhyMode.field.ShortGI = GI_800;
3501 //pAd->CommonCfg.HTPhyMode.field.STBC = STBC_NONE;
3502 pAd
->CommonCfg
.TxRate
= RATE_6
;
3504 pAd
->CommonCfg
.MlmeTransmit
.field
.MCS
= MCS_RATE_6
;
3505 pAd
->CommonCfg
.MlmeTransmit
.field
.BW
= BW_20
;
3506 pAd
->CommonCfg
.MlmeTransmit
.field
.MODE
= MODE_OFDM
;
3508 pAd
->CommonCfg
.BeaconPeriod
= 100; // in mSec
3511 // part II. intialize STA specific configuration
3514 RX_FILTER_SET_FLAG(pAd
, fRX_FILTER_ACCEPT_DIRECT
);
3515 RX_FILTER_CLEAR_FLAG(pAd
, fRX_FILTER_ACCEPT_MULTICAST
);
3516 RX_FILTER_SET_FLAG(pAd
, fRX_FILTER_ACCEPT_BROADCAST
);
3517 RX_FILTER_SET_FLAG(pAd
, fRX_FILTER_ACCEPT_ALL_MULTICAST
);
3519 pAd
->StaCfg
.Psm
= PWR_ACTIVE
;
3521 pAd
->StaCfg
.OrigWepStatus
= Ndis802_11EncryptionDisabled
;
3522 pAd
->StaCfg
.PairCipher
= Ndis802_11EncryptionDisabled
;
3523 pAd
->StaCfg
.GroupCipher
= Ndis802_11EncryptionDisabled
;
3524 pAd
->StaCfg
.bMixCipher
= FALSE
;
3525 pAd
->StaCfg
.DefaultKeyId
= 0;
3527 // 802.1x port control
3528 pAd
->StaCfg
.PrivacyFilter
= Ndis802_11PrivFilter8021xWEP
;
3529 pAd
->StaCfg
.PortSecured
= WPA_802_1X_PORT_NOT_SECURED
;
3530 pAd
->StaCfg
.LastMicErrorTime
= 0;
3531 pAd
->StaCfg
.MicErrCnt
= 0;
3532 pAd
->StaCfg
.bBlockAssoc
= FALSE
;
3533 pAd
->StaCfg
.WpaState
= SS_NOTUSE
;
3535 pAd
->CommonCfg
.NdisRadioStateOff
= FALSE
; // New to support microsoft disable radio with OID command
3537 pAd
->StaCfg
.RssiTrigger
= 0;
3538 NdisZeroMemory(&pAd
->StaCfg
.RssiSample
, sizeof(RSSI_SAMPLE
));
3539 pAd
->StaCfg
.RssiTriggerMode
= RSSI_TRIGGERED_UPON_BELOW_THRESHOLD
;
3540 pAd
->StaCfg
.AtimWin
= 0;
3541 pAd
->StaCfg
.DefaultListenCount
= 3;//default listen count;
3542 pAd
->StaCfg
.BssType
= BSS_INFRA
; // BSS_INFRA or BSS_ADHOC or BSS_MONITOR
3543 pAd
->StaCfg
.bScanReqIsFromWebUI
= FALSE
;
3544 OPSTATUS_CLEAR_FLAG(pAd
, fOP_STATUS_DOZE
);
3545 OPSTATUS_CLEAR_FLAG(pAd
, fOP_STATUS_WAKEUP_NOW
);
3547 pAd
->StaCfg
.bAutoTxRateSwitch
= TRUE
;
3548 pAd
->StaCfg
.DesiredTransmitSetting
.field
.MCS
= MCS_AUTO
;
3551 // global variables mXXXX used in MAC protocol state machines
3552 OPSTATUS_SET_FLAG(pAd
, fOP_STATUS_RECEIVE_DTIM
);
3553 OPSTATUS_CLEAR_FLAG(pAd
, fOP_STATUS_ADHOC_ON
);
3554 OPSTATUS_CLEAR_FLAG(pAd
, fOP_STATUS_INFRA_ON
);
3556 // PHY specification
3557 pAd
->CommonCfg
.PhyMode
= PHY_11BG_MIXED
; // default PHY mode
3558 OPSTATUS_CLEAR_FLAG(pAd
, fOP_STATUS_SHORT_PREAMBLE_INUSED
); // CCK use LONG preamble
3561 // user desired power mode
3562 pAd
->StaCfg
.WindowsPowerMode
= Ndis802_11PowerModeCAM
;
3563 pAd
->StaCfg
.WindowsBatteryPowerMode
= Ndis802_11PowerModeCAM
;
3564 pAd
->StaCfg
.bWindowsACCAMEnable
= FALSE
;
3566 RTMPInitTimer(pAd
, &pAd
->StaCfg
.StaQuickResponeForRateUpTimer
, GET_TIMER_FUNCTION(StaQuickResponeForRateUpExec
), pAd
, FALSE
);
3567 pAd
->StaCfg
.StaQuickResponeForRateUpTimerRunning
= FALSE
;
3570 pAd
->StaCfg
.ScanCnt
= 0;
3572 // CCX 2.0 control flag init
3573 pAd
->StaCfg
.CCXEnable
= FALSE
;
3574 pAd
->StaCfg
.CCXReqType
= MSRN_TYPE_UNUSED
;
3575 pAd
->StaCfg
.CCXQosECWMin
= 4;
3576 pAd
->StaCfg
.CCXQosECWMax
= 10;
3578 pAd
->StaCfg
.bHwRadio
= TRUE
; // Default Hardware Radio status is On
3579 pAd
->StaCfg
.bSwRadio
= TRUE
; // Default Software Radio status is On
3580 pAd
->StaCfg
.bRadio
= TRUE
; // bHwRadio && bSwRadio
3581 pAd
->StaCfg
.bHardwareRadio
= FALSE
; // Default is OFF
3582 pAd
->StaCfg
.bShowHiddenSSID
= FALSE
; // Default no show
3584 // Nitro mode control
3585 pAd
->StaCfg
.bAutoReconnect
= TRUE
;
3587 // Save the init time as last scan time, the system should do scan after 2 seconds.
3588 // This patch is for driver wake up from standby mode, system will do scan right away.
3589 pAd
->StaCfg
.LastScanTime
= 0;
3590 NdisZeroMemory(pAd
->nickname
, IW_ESSID_MAX_SIZE
+1);
3591 sprintf(pAd
->nickname
, "%s", STA_NIC_DEVICE_NAME
);
3592 RTMPInitTimer(pAd
, &pAd
->StaCfg
.WpaDisassocAndBlockAssocTimer
, GET_TIMER_FUNCTION(WpaDisassocApAndBlockAssoc
), pAd
, FALSE
);
3593 pAd
->StaCfg
.IEEE8021X
= FALSE
;
3594 pAd
->StaCfg
.IEEE8021x_required_keys
= FALSE
;
3595 pAd
->StaCfg
.WpaSupplicantUP
= WPA_SUPPLICANT_DISABLE
;
3596 pAd
->StaCfg
.WpaSupplicantUP
= WPA_SUPPLICANT_ENABLE
;
3599 // Default for extra information is not valid
3600 pAd
->ExtraInfo
= EXTRA_INFO_CLEAR
;
3602 // Default Config change flag
3603 pAd
->bConfigChanged
= FALSE
;
3606 // part III. AP configurations
3613 // dynamic BBP R66:sensibity tuning to overcome background noise
3614 pAd
->BbpTuning
.bEnable
= TRUE
;
3615 pAd
->BbpTuning
.FalseCcaLowerThreshold
= 100;
3616 pAd
->BbpTuning
.FalseCcaUpperThreshold
= 512;
3617 pAd
->BbpTuning
.R66Delta
= 4;
3618 pAd
->Mlme
.bEnableAutoAntennaCheck
= TRUE
;
3621 // Also initial R66CurrentValue, RTUSBResumeMsduTransmission might use this value.
3622 // if not initial this value, the default value will be 0.
3624 pAd
->BbpTuning
.R66CurrentValue
= 0x38;
3626 pAd
->Bbp94
= BBPR94_DEFAULT
;
3627 pAd
->BbpForCCK
= FALSE
;
3629 // initialize MAC table and allocate spin lock
3630 NdisZeroMemory(&pAd
->MacTab
, sizeof(MAC_TABLE
));
3631 InitializeQueueHeader(&pAd
->MacTab
.McastPsQueue
);
3632 NdisAllocateSpinLock(&pAd
->MacTabLock
);
3634 pAd
->CommonCfg
.bWiFiTest
= FALSE
;
3636 pAd
->bPCIclkOff
= FALSE
;
3638 RTMP_SET_PSFLAG(pAd
, fRTMP_PS_CAN_GO_SLEEP
);
3640 DBGPRINT(RT_DEBUG_TRACE
, ("<-- UserCfgInit\n"));
3643 // IRQL = PASSIVE_LEVEL
3646 if (ch
>= '0' && ch
<= '9') return (ch
- '0'); // Handle numerals
3647 if (ch
>= 'A' && ch
<= 'F') return (ch
- 'A' + 0xA); // Handle capitol hex digits
3648 if (ch
>= 'a' && ch
<= 'f') return (ch
- 'a' + 0xA); // Handle small hex digits
3653 // FUNCTION: AtoH(char *, UCHAR *, int)
3655 // PURPOSE: Converts ascii string to network order hex
3658 // src - pointer to input ascii string
3659 // dest - pointer to output hex
3660 // destlen - size of dest
3664 // 2 ascii bytes make a hex byte so must put 1st ascii byte of pair
3665 // into upper nibble and 2nd ascii byte of pair into lower nibble.
3667 // IRQL = PASSIVE_LEVEL
3669 void AtoH(char * src
, UCHAR
* dest
, int destlen
)
3675 destTemp
= (PUCHAR
) dest
;
3679 *destTemp
= BtoH(*srcptr
++) << 4; // Put 1st ascii byte in upper nibble.
3680 *destTemp
+= BtoH(*srcptr
++); // Add 2nd ascii byte to above.
3685 VOID
RTMPPatchMacBbpBug(
3686 IN PRTMP_ADAPTER pAd
)
3690 // Initialize BBP register to default value
3691 for (Index
= 0; Index
< NUM_BBP_REG_PARMS
; Index
++)
3693 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd
, BBPRegTable
[Index
].Register
, (UCHAR
)BBPRegTable
[Index
].Value
);
3696 // Initialize RF register to default value
3697 AsicSwitchChannel(pAd
, pAd
->CommonCfg
.Channel
, FALSE
);
3698 AsicLockChannel(pAd
, pAd
->CommonCfg
.Channel
);
3700 // Re-init BBP register from EEPROM value
3701 NICInitAsicFromEEPROM(pAd
);
3705 ========================================================================
3707 Routine Description:
3711 pAd Pointer to our adapter
3712 pTimer Timer structure
3713 pTimerFunc Function to execute when timer expired
3714 Repeat Ture for period timer
3721 ========================================================================
3724 IN PRTMP_ADAPTER pAd
,
3725 IN PRALINK_TIMER_STRUCT pTimer
,
3726 IN PVOID pTimerFunc
,
3731 // Set Valid to TRUE for later used.
3732 // It will crash if we cancel a timer or set a timer
3733 // that we haven't initialize before.
3735 pTimer
->Valid
= TRUE
;
3737 pTimer
->PeriodicType
= Repeat
;
3738 pTimer
->State
= FALSE
;
3739 pTimer
->cookie
= (ULONG
) pData
;
3745 RTMP_OS_Init_Timer(pAd
, &pTimer
->TimerObj
, pTimerFunc
, (PVOID
) pTimer
);
3749 ========================================================================
3751 Routine Description:
3755 pTimer Timer structure
3756 Value Timer value in milliseconds
3762 To use this routine, must call RTMPInitTimer before.
3764 ========================================================================
3767 IN PRALINK_TIMER_STRUCT pTimer
,
3772 pTimer
->TimerValue
= Value
;
3773 pTimer
->State
= FALSE
;
3774 if (pTimer
->PeriodicType
== TRUE
)
3776 pTimer
->Repeat
= TRUE
;
3777 RTMP_SetPeriodicTimer(&pTimer
->TimerObj
, Value
);
3781 pTimer
->Repeat
= FALSE
;
3782 RTMP_OS_Add_Timer(&pTimer
->TimerObj
, Value
);
3787 DBGPRINT_ERR(("RTMPSetTimer failed, Timer hasn't been initialize!\n"));
3793 ========================================================================
3795 Routine Description:
3799 pTimer Timer structure
3800 Value Timer value in milliseconds
3806 To use this routine, must call RTMPInitTimer before.
3808 ========================================================================
3811 IN PRALINK_TIMER_STRUCT pTimer
,
3818 pTimer
->TimerValue
= Value
;
3819 pTimer
->State
= FALSE
;
3820 if (pTimer
->PeriodicType
== TRUE
)
3822 RTMPCancelTimer(pTimer
, &Cancel
);
3823 RTMPSetTimer(pTimer
, Value
);
3827 RTMP_OS_Mod_Timer(&pTimer
->TimerObj
, Value
);
3832 DBGPRINT_ERR(("RTMPModTimer failed, Timer hasn't been initialize!\n"));
3837 ========================================================================
3839 Routine Description:
3840 Cancel timer objects
3843 Adapter Pointer to our adapter
3848 IRQL = PASSIVE_LEVEL
3849 IRQL = DISPATCH_LEVEL
3852 1.) To use this routine, must call RTMPInitTimer before.
3853 2.) Reset NIC to initial state AS IS system boot up time.
3855 ========================================================================
3857 VOID
RTMPCancelTimer(
3858 IN PRALINK_TIMER_STRUCT pTimer
,
3859 OUT BOOLEAN
*pCancelled
)
3863 if (pTimer
->State
== FALSE
)
3864 pTimer
->Repeat
= FALSE
;
3865 RTMP_OS_Del_Timer(&pTimer
->TimerObj
, pCancelled
);
3867 if (*pCancelled
== TRUE
)
3868 pTimer
->State
= TRUE
;
3871 // We need to go-through the TimerQ to findout this timer handler and remove it if
3872 // it's still waiting for execution.
3874 RT2870_TimerQ_Remove(pTimer
->pAd
, pTimer
);
3880 // NdisMCancelTimer just canced the timer and not mean release the timer.
3881 // And don't set the "Valid" to False. So that we can use this timer again.
3883 DBGPRINT_ERR(("RTMPCancelTimer failed, Timer hasn't been initialize!\n"));
3888 ========================================================================
3890 Routine Description:
3894 pAd Pointer to our adapter
3900 IRQL = PASSIVE_LEVEL
3901 IRQL = DISPATCH_LEVEL
3905 ========================================================================
3908 IN PRTMP_ADAPTER pAd
,
3915 LowByte
= pAd
->LedCntl
.field
.LedMode
&0x7f;
3920 AsicSendCommandToMcu(pAd
, 0x50, 0xff, LowByte
, HighByte
);
3921 pAd
->LedIndicatorStregth
= 0;
3924 if (pAd
->CommonCfg
.Channel
> 14)
3928 AsicSendCommandToMcu(pAd
, 0x50, 0xff, LowByte
, HighByte
);
3932 AsicSendCommandToMcu(pAd
, 0x50, 0xff, LowByte
, HighByte
);
3935 LowByte
= 0; // Driver sets MAC register and MAC controls LED
3938 AsicSendCommandToMcu(pAd
, 0x50, 0xff, LowByte
, HighByte
);
3942 AsicSendCommandToMcu(pAd
, 0x50, 0xff, LowByte
, HighByte
);
3944 case LED_ON_SITE_SURVEY
:
3946 AsicSendCommandToMcu(pAd
, 0x50, 0xff, LowByte
, HighByte
);
3950 AsicSendCommandToMcu(pAd
, 0x50, 0xff, LowByte
, HighByte
);
3953 DBGPRINT(RT_DEBUG_WARN
, ("RTMPSetLED::Unknown Status %d\n", Status
));
3958 // Keep LED status for LED SiteSurvey mode.
3959 // After SiteSurvey, we will set the LED mode to previous status.
3961 if ((Status
!= LED_ON_SITE_SURVEY
) && (Status
!= LED_POWER_UP
))
3962 pAd
->LedStatus
= Status
;
3964 DBGPRINT(RT_DEBUG_TRACE
, ("RTMPSetLED::Mode=%d,HighByte=0x%02x,LowByte=0x%02x\n", pAd
->LedCntl
.field
.LedMode
, HighByte
, LowByte
));
3968 ========================================================================
3970 Routine Description:
3971 Set LED Signal Stregth
3974 pAd Pointer to our adapter
3980 IRQL = PASSIVE_LEVEL
3983 Can be run on any IRQL level.
3985 According to Microsoft Zero Config Wireless Signal Stregth definition as belows.
3992 ========================================================================
3994 VOID
RTMPSetSignalLED(
3995 IN PRTMP_ADAPTER pAd
,
3996 IN NDIS_802_11_RSSI Dbm
)
4001 // if not Signal Stregth, then do nothing.
4003 if (pAd
->LedCntl
.field
.LedMode
!= LED_MODE_SIGNAL_STREGTH
)
4010 else if (Dbm
<= -81)
4012 else if (Dbm
<= -71)
4014 else if (Dbm
<= -67)
4016 else if (Dbm
<= -57)
4022 // Update Signal Stregth to firmware if changed.
4024 if (pAd
->LedIndicatorStregth
!= nLed
)
4026 AsicSendCommandToMcu(pAd
, 0x51, 0xff, nLed
, pAd
->LedCntl
.field
.Polarity
);
4027 pAd
->LedIndicatorStregth
= nLed
;
4032 ========================================================================
4034 Routine Description:
4038 pAd Pointer to our adapter
4043 IRQL <= DISPATCH_LEVEL
4046 Before Enable RX, make sure you have enabled Interrupt.
4047 ========================================================================
4049 VOID
RTMPEnableRxTx(
4050 IN PRTMP_ADAPTER pAd
)
4052 DBGPRINT(RT_DEBUG_TRACE
, ("==> RTMPEnableRxTx\n"));
4055 RT28XXDMAEnable(pAd
);
4057 // enable RX of MAC block
4058 if (pAd
->OpMode
== OPMODE_AP
)
4060 UINT32 rx_filter_flag
= APNORMAL
;
4063 RTMP_IO_WRITE32(pAd
, RX_FILTR_CFG
, rx_filter_flag
); // enable RX of DMA block
4067 RTMP_IO_WRITE32(pAd
, RX_FILTR_CFG
, STANORMAL
); // Staion not drop control frame will fail WiFi Certification.
4070 RTMP_IO_WRITE32(pAd
, MAC_SYS_CTRL
, 0xc);
4071 DBGPRINT(RT_DEBUG_TRACE
, ("<== RTMPEnableRxTx\n"));