blob: 701eb894d2b648848fc0e7a4a8c8a56120a80bf7 [file] [log] [blame]
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001/*
2 *************************************************************************
3 * Ralink Tech Inc.
4 * 5F., No.36, Taiyuan St., Jhubei City,
5 * Hsinchu County 302,
6 * Taiwan, R.O.C.
7 *
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
9 *
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. *
14 * *
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. *
19 * *
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. *
24 * *
25 *************************************************************************
26
27 Module Name:
28 rtmp_init.c
29
30 Abstract:
31 Miniport generic portion header file
32
33 Revision History:
34 Who When What
35 -------- ---------- ----------------------------------------------
Greg Kroah-Hartman91980992008-10-28 14:48:09 -070036*/
37#include "../rt_config.h"
Greg Kroah-Hartman91980992008-10-28 14:48:09 -070038
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -080039u8 BIT8[] = { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 };
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -080040char *CipherName[] =
41 { "none", "wep64", "wep128", "TKIP", "AES", "CKIP64", "CKIP128" };
Greg Kroah-Hartman91980992008-10-28 14:48:09 -070042
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -080043/* */
44/* BBP register initialization set */
45/* */
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -080046struct rt_reg_pair BBPRegTable[] = {
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -080047 {BBP_R65, 0x2C}, /* fix rssi issue */
48 {BBP_R66, 0x38}, /* Also set this default value to pAd->BbpTuning.R66CurrentValue at initial */
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -080049 {BBP_R69, 0x12},
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -080050 {BBP_R70, 0xa}, /* BBP_R70 will change to 0x8 in ApStartUp and LinkUp for rt2860C, otherwise value is 0xa */
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -080051 {BBP_R73, 0x10},
52 {BBP_R81, 0x37},
53 {BBP_R82, 0x62},
54 {BBP_R83, 0x6A},
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -080055 {BBP_R84, 0x99}, /* 0x19 is for rt2860E and after. This is for extension channel overlapping IOT. 0x99 is for rt2860D and before */
56 {BBP_R86, 0x00}, /* middle range issue, Rory @2008-01-28 */
57 {BBP_R91, 0x04}, /* middle range issue, Rory @2008-01-28 */
58 {BBP_R92, 0x00}, /* middle range issue, Rory @2008-01-28 */
59 {BBP_R103, 0x00}, /* near range high-power issue, requested from Gary @2008-0528 */
60 {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. */
61 {BBP_R106, 0x35}, /* for ShortGI throughput */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -070062};
Greg Kroah-Hartman91980992008-10-28 14:48:09 -070063
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -080064#define NUM_BBP_REG_PARMS (sizeof(BBPRegTable) / sizeof(struct rt_reg_pair))
Greg Kroah-Hartman91980992008-10-28 14:48:09 -070065
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -080066/* */
67/* ASIC register initialization sets */
68/* */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -070069
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -080070struct rt_rtmp_reg_pair MACRegTable[] = {
Greg Kroah-Hartman91980992008-10-28 14:48:09 -070071#if defined(HW_BEACON_OFFSET) && (HW_BEACON_OFFSET == 0x200)
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -080072 {BCN_OFFSET0, 0xf8f0e8e0}, /* 0x3800(e0), 0x3A00(e8), 0x3C00(f0), 0x3E00(f8), 512B for each beacon */
73 {BCN_OFFSET1, 0x6f77d0c8}, /* 0x3200(c8), 0x3400(d0), 0x1DC0(77), 0x1BC0(6f), 512B for each beacon */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -070074#elif defined(HW_BEACON_OFFSET) && (HW_BEACON_OFFSET == 0x100)
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -080075 {BCN_OFFSET0, 0xece8e4e0}, /* 0x3800, 0x3A00, 0x3C00, 0x3E00, 512B for each beacon */
76 {BCN_OFFSET1, 0xfcf8f4f0}, /* 0x3800, 0x3A00, 0x3C00, 0x3E00, 512B for each beacon */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -070077#else
Sebastian Dalfuß06aea992009-11-07 17:31:12 +010078#error You must re-calculate new value for BCN_OFFSET0 & BCN_OFFSET1 in MACRegTable[]!
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -080079#endif /* HW_BEACON_OFFSET // */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -070080
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -080081 {LEGACY_BASIC_RATE, 0x0000013f}, /* Basic rate set bitmap */
82 {HT_BASIC_RATE, 0x00008003}, /* Basic HT rate set , 20M, MCS=3, MM. Format is the same as in TXWI. */
83 {MAC_SYS_CTRL, 0x00}, /* 0x1004, , default Disable RX */
84 {RX_FILTR_CFG, 0x17f97}, /*0x1400 , RX filter control, */
85 {BKOFF_SLOT_CFG, 0x209}, /* default set short slot time, CC_DELAY_TIME should be 2 */
86 /*{TX_SW_CFG0, 0x40a06}, // Gary,2006-08-23 */
87 {TX_SW_CFG0, 0x0}, /* Gary,2008-05-21 for CWC test */
88 {TX_SW_CFG1, 0x80606}, /* Gary,2006-08-23 */
89 {TX_LINK_CFG, 0x1020}, /* Gary,2006-08-23 */
90 /*{TX_TIMEOUT_CFG, 0x00182090}, // CCK has some problem. So increase timieout value. 2006-10-09// MArvek RT */
91 {TX_TIMEOUT_CFG, 0x000a2090}, /* CCK has some problem. So increase timieout value. 2006-10-09// MArvek RT , Modify for 2860E ,2007-08-01 */
92 {MAX_LEN_CFG, MAX_AGGREGATION_SIZE | 0x00001000}, /* 0x3018, MAX frame length. Max PSDU = 16kbytes. */
93 {LED_CFG, 0x7f031e46}, /* Gary, 2006-08-23 */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +020094
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -080095 {PBF_MAX_PCNT, 0x1F3FBF9F}, /*0x1F3f7f9f}, //Jan, 2006/04/20 */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +020096
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -080097 {TX_RTY_CFG, 0x47d01f0f}, /* Jan, 2006/11/16, Set TxWI->ACK =0 in Probe Rsp Modify for 2860E ,2007-08-03 */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +020098
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -080099 {AUTO_RSP_CFG, 0x00000013}, /* Initial Auto_Responder, because QA will turn off Auto-Responder */
100 {CCK_PROT_CFG, 0x05740003 /*0x01740003 */ }, /* Initial Auto_Responder, because QA will turn off Auto-Responder. And RTS threshold is enabled. */
101 {OFDM_PROT_CFG, 0x05740003 /*0x01740003 */ }, /* Initial Auto_Responder, because QA will turn off Auto-Responder. And RTS threshold is enabled. */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200102#ifdef RTMP_MAC_USB
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -0800103 {PBF_CFG, 0xf40006}, /* Only enable Queue 2 */
104 {MM40_PROT_CFG, 0x3F44084}, /* Initial Auto_Responder, because QA will turn off Auto-Responder */
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800105 {WPDMA_GLO_CFG, 0x00000030},
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -0800106#endif /* RTMP_MAC_USB // */
107 {GF20_PROT_CFG, 0x01744004}, /* set 19:18 --> Short NAV for MIMO PS */
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800108 {GF40_PROT_CFG, 0x03F44084},
109 {MM20_PROT_CFG, 0x01744004},
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200110#ifdef RTMP_MAC_PCI
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800111 {MM40_PROT_CFG, 0x03F54084},
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -0800112#endif /* RTMP_MAC_PCI // */
113 {TXOP_CTRL_CFG, 0x0000583f, /*0x0000243f *//*0x000024bf */ }, /*Extension channel backoff. */
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800114 {TX_RTS_CFG, 0x00092b20},
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -0800115 {EXP_ACK_TIME, 0x002400ca}, /* default value */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200116
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800117 {TXOP_HLDR_ET, 0x00000002},
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700118
119 /* Jerry comments 2008/01/16: we use SIFS = 10us in CCK defaultly, but it seems that 10us
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800120 is too small for INTEL 2200bg card, so in MBSS mode, the delta time between beacon0
121 and beacon1 is SIFS (10us), so if INTEL 2200bg card connects to BSS0, the ping
122 will always lost. So we change the SIFS of CCK from 10us to 16us. */
123 {XIFS_TIME_CFG, 0x33a41010},
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -0800124 {PWR_PIN_CFG, 0x00000003}, /* patch for 2880-E */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700125};
126
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -0800127struct rt_rtmp_reg_pair STAMACRegTable[] = {
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800128 {WMM_AIFSN_CFG, 0x00002273},
129 {WMM_CWMIN_CFG, 0x00002344},
130 {WMM_CWMAX_CFG, 0x000034aa},
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700131};
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700132
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -0800133#define NUM_MAC_REG_PARMS (sizeof(MACRegTable) / sizeof(struct rt_rtmp_reg_pair))
134#define NUM_STA_MAC_REG_PARMS (sizeof(STAMACRegTable) / sizeof(struct rt_rtmp_reg_pair))
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700135
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700136/*
137 ========================================================================
138
139 Routine Description:
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -0800140 Allocate struct rt_rtmp_adapter data block and do some initialization
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700141
142 Arguments:
143 Adapter Pointer to our adapter
144
145 Return Value:
146 NDIS_STATUS_SUCCESS
147 NDIS_STATUS_FAILURE
148
149 IRQL = PASSIVE_LEVEL
150
151 Note:
152
153 ========================================================================
154*/
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -0800155int RTMPAllocAdapterBlock(void *handle,
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -0800156 struct rt_rtmp_adapter * * ppAdapter)
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700157{
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -0800158 struct rt_rtmp_adapter *pAd;
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -0800159 int Status;
160 int index;
161 u8 *pBeaconBuf = NULL;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700162
163 DBGPRINT(RT_DEBUG_TRACE, ("--> RTMPAllocAdapterBlock\n"));
164
165 *ppAdapter = NULL;
166
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800167 do {
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -0800168 /* Allocate struct rt_rtmp_adapter memory block */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700169 pBeaconBuf = kmalloc(MAX_BEACON_SIZE, MEM_ALLOC_FLAG);
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800170 if (pBeaconBuf == NULL) {
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700171 Status = NDIS_STATUS_FAILURE;
172 DBGPRINT_ERR(("Failed to allocate memory - BeaconBuf!\n"));
173 break;
174 }
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200175 NdisZeroMemory(pBeaconBuf, MAX_BEACON_SIZE);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700176
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -0800177 Status = AdapterBlockAllocateMemory(handle, (void **) & pAd);
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800178 if (Status != NDIS_STATUS_SUCCESS) {
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700179 DBGPRINT_ERR(("Failed to allocate memory - ADAPTER\n"));
180 break;
181 }
182 pAd->BeaconBuf = pBeaconBuf;
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800183 DBGPRINT(RT_DEBUG_OFF,
Sebastian Dalfußd6dbc012009-11-06 14:49:28 +0100184 ("=== pAd = %p, size = %d ===\n", pAd,
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -0800185 (u32)sizeof(struct rt_rtmp_adapter)));
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700186
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -0800187 /* Init spin locks */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700188 NdisAllocateSpinLock(&pAd->MgmtRingLock);
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200189#ifdef RTMP_MAC_PCI
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700190 NdisAllocateSpinLock(&pAd->RxRingLock);
Bartlomiej Zolnierkiewicze44fd1c2009-09-22 20:44:24 +0200191#ifdef RT3090
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800192 NdisAllocateSpinLock(&pAd->McuCmdLock);
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -0800193#endif /* RT3090 // */
194#endif /* RTMP_MAC_PCI // */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700195
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800196 for (index = 0; index < NUM_OF_TX_RING; index++) {
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700197 NdisAllocateSpinLock(&pAd->TxSwQueueLock[index]);
198 NdisAllocateSpinLock(&pAd->DeQueueLock[index]);
199 pAd->DeQueueRunning[index] = FALSE;
200 }
201
202 NdisAllocateSpinLock(&pAd->irq_lock);
203
204 } while (FALSE);
205
206 if ((Status != NDIS_STATUS_SUCCESS) && (pBeaconBuf))
207 kfree(pBeaconBuf);
208
209 *ppAdapter = pAd;
210
211 DBGPRINT_S(Status, ("<-- RTMPAllocAdapterBlock, Status=%x\n", Status));
212 return Status;
213}
214
215/*
216 ========================================================================
217
218 Routine Description:
219 Read initial Tx power per MCS and BW from EEPROM
220
221 Arguments:
222 Adapter Pointer to our adapter
223
224 Return Value:
225 None
226
227 IRQL = PASSIVE_LEVEL
228
229 Note:
230
231 ========================================================================
232*/
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -0800233void RTMPReadTxPwrPerRate(struct rt_rtmp_adapter *pAd)
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700234{
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -0800235 unsigned long data, Adata, Gdata;
236 u16 i, value, value2;
237 int Apwrdelta, Gpwrdelta;
238 u8 t1, t2, t3, t4;
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800239 BOOLEAN bApwrdeltaMinus = TRUE, bGpwrdeltaMinus = TRUE;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700240
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -0800241 /* */
242 /* Get power delta for 20MHz and 40MHz. */
243 /* */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700244 DBGPRINT(RT_DEBUG_TRACE, ("Txpower per Rate\n"));
245 RT28xx_EEPROM_READ16(pAd, EEPROM_TXPOWER_DELTA, value2);
246 Apwrdelta = 0;
247 Gpwrdelta = 0;
248
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800249 if ((value2 & 0xff) != 0xff) {
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700250 if ((value2 & 0x80))
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800251 Gpwrdelta = (value2 & 0xf);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700252
253 if ((value2 & 0x40))
254 bGpwrdeltaMinus = FALSE;
255 else
256 bGpwrdeltaMinus = TRUE;
257 }
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800258 if ((value2 & 0xff00) != 0xff00) {
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700259 if ((value2 & 0x8000))
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800260 Apwrdelta = ((value2 & 0xf00) >> 8);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700261
262 if ((value2 & 0x4000))
263 bApwrdeltaMinus = FALSE;
264 else
265 bApwrdeltaMinus = TRUE;
266 }
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800267 DBGPRINT(RT_DEBUG_TRACE,
268 ("Gpwrdelta = %x, Apwrdelta = %x .\n", Gpwrdelta, Apwrdelta));
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700269
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -0800270 /* */
271 /* Get Txpower per MCS for 20MHz in 2.4G. */
272 /* */
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800273 for (i = 0; i < 5; i++) {
274 RT28xx_EEPROM_READ16(pAd,
275 EEPROM_TXPOWER_BYRATE_20MHZ_2_4G + i * 4,
276 value);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700277 data = value;
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800278 if (bApwrdeltaMinus == FALSE) {
279 t1 = (value & 0xf) + (Apwrdelta);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700280 if (t1 > 0xf)
281 t1 = 0xf;
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800282 t2 = ((value & 0xf0) >> 4) + (Apwrdelta);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700283 if (t2 > 0xf)
284 t2 = 0xf;
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800285 t3 = ((value & 0xf00) >> 8) + (Apwrdelta);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700286 if (t3 > 0xf)
287 t3 = 0xf;
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800288 t4 = ((value & 0xf000) >> 12) + (Apwrdelta);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700289 if (t4 > 0xf)
290 t4 = 0xf;
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800291 } else {
292 if ((value & 0xf) > Apwrdelta)
293 t1 = (value & 0xf) - (Apwrdelta);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700294 else
295 t1 = 0;
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800296 if (((value & 0xf0) >> 4) > Apwrdelta)
297 t2 = ((value & 0xf0) >> 4) - (Apwrdelta);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700298 else
299 t2 = 0;
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800300 if (((value & 0xf00) >> 8) > Apwrdelta)
301 t3 = ((value & 0xf00) >> 8) - (Apwrdelta);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700302 else
303 t3 = 0;
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800304 if (((value & 0xf000) >> 12) > Apwrdelta)
305 t4 = ((value & 0xf000) >> 12) - (Apwrdelta);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700306 else
307 t4 = 0;
308 }
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800309 Adata = t1 + (t2 << 4) + (t3 << 8) + (t4 << 12);
310 if (bGpwrdeltaMinus == FALSE) {
311 t1 = (value & 0xf) + (Gpwrdelta);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700312 if (t1 > 0xf)
313 t1 = 0xf;
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800314 t2 = ((value & 0xf0) >> 4) + (Gpwrdelta);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700315 if (t2 > 0xf)
316 t2 = 0xf;
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800317 t3 = ((value & 0xf00) >> 8) + (Gpwrdelta);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700318 if (t3 > 0xf)
319 t3 = 0xf;
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800320 t4 = ((value & 0xf000) >> 12) + (Gpwrdelta);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700321 if (t4 > 0xf)
322 t4 = 0xf;
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800323 } else {
324 if ((value & 0xf) > Gpwrdelta)
325 t1 = (value & 0xf) - (Gpwrdelta);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700326 else
327 t1 = 0;
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800328 if (((value & 0xf0) >> 4) > Gpwrdelta)
329 t2 = ((value & 0xf0) >> 4) - (Gpwrdelta);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700330 else
331 t2 = 0;
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800332 if (((value & 0xf00) >> 8) > Gpwrdelta)
333 t3 = ((value & 0xf00) >> 8) - (Gpwrdelta);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700334 else
335 t3 = 0;
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800336 if (((value & 0xf000) >> 12) > Gpwrdelta)
337 t4 = ((value & 0xf000) >> 12) - (Gpwrdelta);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700338 else
339 t4 = 0;
340 }
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800341 Gdata = t1 + (t2 << 4) + (t3 << 8) + (t4 << 12);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700342
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800343 RT28xx_EEPROM_READ16(pAd,
344 EEPROM_TXPOWER_BYRATE_20MHZ_2_4G + i * 4 +
345 2, value);
346 if (bApwrdeltaMinus == FALSE) {
347 t1 = (value & 0xf) + (Apwrdelta);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700348 if (t1 > 0xf)
349 t1 = 0xf;
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800350 t2 = ((value & 0xf0) >> 4) + (Apwrdelta);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700351 if (t2 > 0xf)
352 t2 = 0xf;
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800353 t3 = ((value & 0xf00) >> 8) + (Apwrdelta);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700354 if (t3 > 0xf)
355 t3 = 0xf;
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800356 t4 = ((value & 0xf000) >> 12) + (Apwrdelta);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700357 if (t4 > 0xf)
358 t4 = 0xf;
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800359 } else {
360 if ((value & 0xf) > Apwrdelta)
361 t1 = (value & 0xf) - (Apwrdelta);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700362 else
363 t1 = 0;
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800364 if (((value & 0xf0) >> 4) > Apwrdelta)
365 t2 = ((value & 0xf0) >> 4) - (Apwrdelta);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700366 else
367 t2 = 0;
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800368 if (((value & 0xf00) >> 8) > Apwrdelta)
369 t3 = ((value & 0xf00) >> 8) - (Apwrdelta);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700370 else
371 t3 = 0;
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800372 if (((value & 0xf000) >> 12) > Apwrdelta)
373 t4 = ((value & 0xf000) >> 12) - (Apwrdelta);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700374 else
375 t4 = 0;
376 }
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800377 Adata |= ((t1 << 16) + (t2 << 20) + (t3 << 24) + (t4 << 28));
378 if (bGpwrdeltaMinus == FALSE) {
379 t1 = (value & 0xf) + (Gpwrdelta);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700380 if (t1 > 0xf)
381 t1 = 0xf;
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800382 t2 = ((value & 0xf0) >> 4) + (Gpwrdelta);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700383 if (t2 > 0xf)
384 t2 = 0xf;
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800385 t3 = ((value & 0xf00) >> 8) + (Gpwrdelta);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700386 if (t3 > 0xf)
387 t3 = 0xf;
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800388 t4 = ((value & 0xf000) >> 12) + (Gpwrdelta);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700389 if (t4 > 0xf)
390 t4 = 0xf;
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800391 } else {
392 if ((value & 0xf) > Gpwrdelta)
393 t1 = (value & 0xf) - (Gpwrdelta);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700394 else
395 t1 = 0;
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800396 if (((value & 0xf0) >> 4) > Gpwrdelta)
397 t2 = ((value & 0xf0) >> 4) - (Gpwrdelta);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700398 else
399 t2 = 0;
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800400 if (((value & 0xf00) >> 8) > Gpwrdelta)
401 t3 = ((value & 0xf00) >> 8) - (Gpwrdelta);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700402 else
403 t3 = 0;
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800404 if (((value & 0xf000) >> 12) > Gpwrdelta)
405 t4 = ((value & 0xf000) >> 12) - (Gpwrdelta);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700406 else
407 t4 = 0;
408 }
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800409 Gdata |= ((t1 << 16) + (t2 << 20) + (t3 << 24) + (t4 << 28));
410 data |= (value << 16);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700411
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200412 /* For 20M/40M Power Delta issue */
413 pAd->Tx20MPwrCfgABand[i] = data;
414 pAd->Tx20MPwrCfgGBand[i] = data;
415 pAd->Tx40MPwrCfgABand[i] = Adata;
416 pAd->Tx40MPwrCfgGBand[i] = Gdata;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700417
418 if (data != 0xffffffff)
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800419 RTMP_IO_WRITE32(pAd, TX_PWR_CFG_0 + i * 4, data);
420 DBGPRINT_RAW(RT_DEBUG_TRACE,
421 ("20MHz BW, 2.4G band-%lx, Adata = %lx, Gdata = %lx \n",
422 data, Adata, Gdata));
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700423 }
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700424}
425
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700426/*
427 ========================================================================
428
429 Routine Description:
430 Read initial channel power parameters from EEPROM
431
432 Arguments:
433 Adapter Pointer to our adapter
434
435 Return Value:
436 None
437
438 IRQL = PASSIVE_LEVEL
439
440 Note:
441
442 ========================================================================
443*/
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -0800444void RTMPReadChannelPwr(struct rt_rtmp_adapter *pAd)
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700445{
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -0800446 u8 i, choffset;
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800447 EEPROM_TX_PWR_STRUC Power;
448 EEPROM_TX_PWR_STRUC Power2;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700449
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -0800450 /* Read Tx power value for all channels */
451 /* Value from 1 - 0x7f. Default value is 24. */
452 /* Power value : 2.4G 0x00 (0) ~ 0x1F (31) */
453 /* : 5.5G 0xF9 (-7) ~ 0x0F (15) */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700454
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -0800455 /* 0. 11b/g, ch1 - ch 14 */
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800456 for (i = 0; i < 7; i++) {
457 RT28xx_EEPROM_READ16(pAd, EEPROM_G_TX_PWR_OFFSET + i * 2,
458 Power.word);
459 RT28xx_EEPROM_READ16(pAd, EEPROM_G_TX2_PWR_OFFSET + i * 2,
460 Power2.word);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700461 pAd->TxPower[i * 2].Channel = i * 2 + 1;
462 pAd->TxPower[i * 2 + 1].Channel = i * 2 + 2;
463
464 if ((Power.field.Byte0 > 31) || (Power.field.Byte0 < 0))
465 pAd->TxPower[i * 2].Power = DEFAULT_RF_TX_POWER;
466 else
467 pAd->TxPower[i * 2].Power = Power.field.Byte0;
468
469 if ((Power.field.Byte1 > 31) || (Power.field.Byte1 < 0))
470 pAd->TxPower[i * 2 + 1].Power = DEFAULT_RF_TX_POWER;
471 else
472 pAd->TxPower[i * 2 + 1].Power = Power.field.Byte1;
473
474 if ((Power2.field.Byte0 > 31) || (Power2.field.Byte0 < 0))
475 pAd->TxPower[i * 2].Power2 = DEFAULT_RF_TX_POWER;
476 else
477 pAd->TxPower[i * 2].Power2 = Power2.field.Byte0;
478
479 if ((Power2.field.Byte1 > 31) || (Power2.field.Byte1 < 0))
480 pAd->TxPower[i * 2 + 1].Power2 = DEFAULT_RF_TX_POWER;
481 else
482 pAd->TxPower[i * 2 + 1].Power2 = Power2.field.Byte1;
483 }
484
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -0800485 /* 1. U-NII lower/middle band: 36, 38, 40; 44, 46, 48; 52, 54, 56; 60, 62, 64 (including central frequency in BW 40MHz) */
486 /* 1.1 Fill up channel */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700487 choffset = 14;
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800488 for (i = 0; i < 4; i++) {
489 pAd->TxPower[3 * i + choffset + 0].Channel = 36 + i * 8 + 0;
490 pAd->TxPower[3 * i + choffset + 0].Power = DEFAULT_RF_TX_POWER;
491 pAd->TxPower[3 * i + choffset + 0].Power2 = DEFAULT_RF_TX_POWER;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700492
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800493 pAd->TxPower[3 * i + choffset + 1].Channel = 36 + i * 8 + 2;
494 pAd->TxPower[3 * i + choffset + 1].Power = DEFAULT_RF_TX_POWER;
495 pAd->TxPower[3 * i + choffset + 1].Power2 = DEFAULT_RF_TX_POWER;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700496
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800497 pAd->TxPower[3 * i + choffset + 2].Channel = 36 + i * 8 + 4;
498 pAd->TxPower[3 * i + choffset + 2].Power = DEFAULT_RF_TX_POWER;
499 pAd->TxPower[3 * i + choffset + 2].Power2 = DEFAULT_RF_TX_POWER;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700500 }
501
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -0800502 /* 1.2 Fill up power */
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800503 for (i = 0; i < 6; i++) {
504 RT28xx_EEPROM_READ16(pAd, EEPROM_A_TX_PWR_OFFSET + i * 2,
505 Power.word);
506 RT28xx_EEPROM_READ16(pAd, EEPROM_A_TX2_PWR_OFFSET + i * 2,
507 Power2.word);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700508
509 if ((Power.field.Byte0 < 16) && (Power.field.Byte0 >= -7))
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800510 pAd->TxPower[i * 2 + choffset + 0].Power =
511 Power.field.Byte0;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700512
513 if ((Power.field.Byte1 < 16) && (Power.field.Byte1 >= -7))
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800514 pAd->TxPower[i * 2 + choffset + 1].Power =
515 Power.field.Byte1;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700516
517 if ((Power2.field.Byte0 < 16) && (Power2.field.Byte0 >= -7))
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800518 pAd->TxPower[i * 2 + choffset + 0].Power2 =
519 Power2.field.Byte0;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700520
521 if ((Power2.field.Byte1 < 16) && (Power2.field.Byte1 >= -7))
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800522 pAd->TxPower[i * 2 + choffset + 1].Power2 =
523 Power2.field.Byte1;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700524 }
525
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -0800526 /* 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) */
527 /* 2.1 Fill up channel */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700528 choffset = 14 + 12;
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800529 for (i = 0; i < 5; i++) {
530 pAd->TxPower[3 * i + choffset + 0].Channel = 100 + i * 8 + 0;
531 pAd->TxPower[3 * i + choffset + 0].Power = DEFAULT_RF_TX_POWER;
532 pAd->TxPower[3 * i + choffset + 0].Power2 = DEFAULT_RF_TX_POWER;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700533
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800534 pAd->TxPower[3 * i + choffset + 1].Channel = 100 + i * 8 + 2;
535 pAd->TxPower[3 * i + choffset + 1].Power = DEFAULT_RF_TX_POWER;
536 pAd->TxPower[3 * i + choffset + 1].Power2 = DEFAULT_RF_TX_POWER;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700537
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800538 pAd->TxPower[3 * i + choffset + 2].Channel = 100 + i * 8 + 4;
539 pAd->TxPower[3 * i + choffset + 2].Power = DEFAULT_RF_TX_POWER;
540 pAd->TxPower[3 * i + choffset + 2].Power2 = DEFAULT_RF_TX_POWER;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700541 }
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800542 pAd->TxPower[3 * 5 + choffset + 0].Channel = 140;
543 pAd->TxPower[3 * 5 + choffset + 0].Power = DEFAULT_RF_TX_POWER;
544 pAd->TxPower[3 * 5 + choffset + 0].Power2 = DEFAULT_RF_TX_POWER;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700545
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -0800546 /* 2.2 Fill up power */
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800547 for (i = 0; i < 8; i++) {
548 RT28xx_EEPROM_READ16(pAd,
549 EEPROM_A_TX_PWR_OFFSET + (choffset - 14) +
550 i * 2, Power.word);
551 RT28xx_EEPROM_READ16(pAd,
552 EEPROM_A_TX2_PWR_OFFSET + (choffset - 14) +
553 i * 2, Power2.word);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700554
555 if ((Power.field.Byte0 < 16) && (Power.field.Byte0 >= -7))
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800556 pAd->TxPower[i * 2 + choffset + 0].Power =
557 Power.field.Byte0;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700558
559 if ((Power.field.Byte1 < 16) && (Power.field.Byte1 >= -7))
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800560 pAd->TxPower[i * 2 + choffset + 1].Power =
561 Power.field.Byte1;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700562
563 if ((Power2.field.Byte0 < 16) && (Power2.field.Byte0 >= -7))
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800564 pAd->TxPower[i * 2 + choffset + 0].Power2 =
565 Power2.field.Byte0;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700566
567 if ((Power2.field.Byte1 < 16) && (Power2.field.Byte1 >= -7))
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800568 pAd->TxPower[i * 2 + choffset + 1].Power2 =
569 Power2.field.Byte1;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700570 }
571
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -0800572 /* 3. U-NII upper band: 149, 151, 153; 157, 159, 161; 165, 167, 169; 171, 173 (including central frequency in BW 40MHz) */
573 /* 3.1 Fill up channel */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700574 choffset = 14 + 12 + 16;
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800575 /*for (i = 0; i < 2; i++) */
576 for (i = 0; i < 3; i++) {
577 pAd->TxPower[3 * i + choffset + 0].Channel = 149 + i * 8 + 0;
578 pAd->TxPower[3 * i + choffset + 0].Power = DEFAULT_RF_TX_POWER;
579 pAd->TxPower[3 * i + choffset + 0].Power2 = DEFAULT_RF_TX_POWER;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700580
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800581 pAd->TxPower[3 * i + choffset + 1].Channel = 149 + i * 8 + 2;
582 pAd->TxPower[3 * i + choffset + 1].Power = DEFAULT_RF_TX_POWER;
583 pAd->TxPower[3 * i + choffset + 1].Power2 = DEFAULT_RF_TX_POWER;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700584
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800585 pAd->TxPower[3 * i + choffset + 2].Channel = 149 + i * 8 + 4;
586 pAd->TxPower[3 * i + choffset + 2].Power = DEFAULT_RF_TX_POWER;
587 pAd->TxPower[3 * i + choffset + 2].Power2 = DEFAULT_RF_TX_POWER;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700588 }
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800589 pAd->TxPower[3 * 3 + choffset + 0].Channel = 171;
590 pAd->TxPower[3 * 3 + choffset + 0].Power = DEFAULT_RF_TX_POWER;
591 pAd->TxPower[3 * 3 + choffset + 0].Power2 = DEFAULT_RF_TX_POWER;
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200592
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800593 pAd->TxPower[3 * 3 + choffset + 1].Channel = 173;
594 pAd->TxPower[3 * 3 + choffset + 1].Power = DEFAULT_RF_TX_POWER;
595 pAd->TxPower[3 * 3 + choffset + 1].Power2 = DEFAULT_RF_TX_POWER;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700596
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -0800597 /* 3.2 Fill up power */
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800598 /*for (i = 0; i < 4; i++) */
599 for (i = 0; i < 6; i++) {
600 RT28xx_EEPROM_READ16(pAd,
601 EEPROM_A_TX_PWR_OFFSET + (choffset - 14) +
602 i * 2, Power.word);
603 RT28xx_EEPROM_READ16(pAd,
604 EEPROM_A_TX2_PWR_OFFSET + (choffset - 14) +
605 i * 2, Power2.word);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700606
607 if ((Power.field.Byte0 < 16) && (Power.field.Byte0 >= -7))
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800608 pAd->TxPower[i * 2 + choffset + 0].Power =
609 Power.field.Byte0;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700610
611 if ((Power.field.Byte1 < 16) && (Power.field.Byte1 >= -7))
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800612 pAd->TxPower[i * 2 + choffset + 1].Power =
613 Power.field.Byte1;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700614
615 if ((Power2.field.Byte0 < 16) && (Power2.field.Byte0 >= -7))
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800616 pAd->TxPower[i * 2 + choffset + 0].Power2 =
617 Power2.field.Byte0;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700618
619 if ((Power2.field.Byte1 < 16) && (Power2.field.Byte1 >= -7))
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800620 pAd->TxPower[i * 2 + choffset + 1].Power2 =
621 Power2.field.Byte1;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700622 }
623
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -0800624 /* 4. Print and Debug */
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800625 /*choffset = 14 + 12 + 16 + 7; */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200626 choffset = 14 + 12 + 16 + 11;
627
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700628}
629
630/*
631 ========================================================================
632
633 Routine Description:
634 Read the following from the registry
635 1. All the parameters
636 2. NetworkAddres
637
638 Arguments:
639 Adapter Pointer to our adapter
640 WrapperConfigurationContext For use by NdisOpenConfiguration
641
642 Return Value:
643 NDIS_STATUS_SUCCESS
644 NDIS_STATUS_FAILURE
645 NDIS_STATUS_RESOURCES
646
647 IRQL = PASSIVE_LEVEL
648
649 Note:
650
651 ========================================================================
652*/
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -0800653int NICReadRegParameters(struct rt_rtmp_adapter *pAd,
Bartlomiej Zolnierkiewicz8a10a542009-12-11 12:23:15 -0800654 void *WrapperConfigurationContext)
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700655{
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -0800656 int Status = NDIS_STATUS_SUCCESS;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700657 DBGPRINT_S(Status, ("<-- NICReadRegParameters, Status=%x\n", Status));
658 return Status;
659}
660
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700661/*
662 ========================================================================
663
664 Routine Description:
665 Read initial parameters from EEPROM
666
667 Arguments:
668 Adapter Pointer to our adapter
669
670 Return Value:
671 None
672
673 IRQL = PASSIVE_LEVEL
674
675 Note:
676
677 ========================================================================
678*/
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -0800679void NICReadEEPROMParameters(struct rt_rtmp_adapter *pAd, u8 *mac_addr)
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700680{
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -0800681 u32 data = 0;
682 u16 i, value, value2;
683 u8 TmpPhy;
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800684 EEPROM_TX_PWR_STRUC Power;
685 EEPROM_VERSION_STRUC Version;
686 EEPROM_ANTENNA_STRUC Antenna;
687 EEPROM_NIC_CONFIG2_STRUC NicConfig2;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700688
689 DBGPRINT(RT_DEBUG_TRACE, ("--> NICReadEEPROMParameters\n"));
690
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200691 if (pAd->chipOps.eeinit)
692 pAd->chipOps.eeinit(pAd);
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200693
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -0800694 /* Init EEPROM Address Number, before access EEPROM; if 93c46, EEPROMAddressNum=6, else if 93c66, EEPROMAddressNum=8 */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700695 RTMP_IO_READ32(pAd, E2PROM_CSR, &data);
696 DBGPRINT(RT_DEBUG_TRACE, ("--> E2PROM_CSR = 0x%x\n", data));
697
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800698 if ((data & 0x30) == 0)
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -0800699 pAd->EEPROMAddressNum = 6; /* 93C46 */
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800700 else if ((data & 0x30) == 0x10)
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -0800701 pAd->EEPROMAddressNum = 8; /* 93C66 */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700702 else
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -0800703 pAd->EEPROMAddressNum = 8; /* 93C86 */
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800704 DBGPRINT(RT_DEBUG_TRACE,
705 ("--> EEPROMAddressNum = %d\n", pAd->EEPROMAddressNum));
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700706
Uwe Kleine-König9b0131c2010-09-01 15:40:25 +0200707 /* RT2860 MAC no longer auto load MAC address from E2PROM. Driver has to initialize */
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -0800708 /* MAC address registers according to E2PROM setting */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700709 if (mac_addr == NULL ||
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -0800710 strlen((char *)mac_addr) != 17 ||
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800711 mac_addr[2] != ':' || mac_addr[5] != ':' || mac_addr[8] != ':' ||
712 mac_addr[11] != ':' || mac_addr[14] != ':') {
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -0800713 u16 Addr01, Addr23, Addr45;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700714
715 RT28xx_EEPROM_READ16(pAd, 0x04, Addr01);
716 RT28xx_EEPROM_READ16(pAd, 0x06, Addr23);
717 RT28xx_EEPROM_READ16(pAd, 0x08, Addr45);
718
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -0800719 pAd->PermanentAddress[0] = (u8)(Addr01 & 0xff);
720 pAd->PermanentAddress[1] = (u8)(Addr01 >> 8);
721 pAd->PermanentAddress[2] = (u8)(Addr23 & 0xff);
722 pAd->PermanentAddress[3] = (u8)(Addr23 >> 8);
723 pAd->PermanentAddress[4] = (u8)(Addr45 & 0xff);
724 pAd->PermanentAddress[5] = (u8)(Addr45 >> 8);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700725
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800726 DBGPRINT(RT_DEBUG_TRACE,
727 ("Initialize MAC Address from E2PROM \n"));
728 } else {
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -0800729 int j;
730 char *macptr;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700731
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -0800732 macptr = (char *)mac_addr;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700733
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800734 for (j = 0; j < MAC_ADDR_LEN; j++) {
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700735 AtoH(macptr, &pAd->PermanentAddress[j], 1);
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800736 macptr = macptr + 3;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700737 }
738
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800739 DBGPRINT(RT_DEBUG_TRACE,
740 ("Initialize MAC Address from module parameter \n"));
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700741 }
742
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700743 {
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -0800744 /*more conveninet to test mbssid, so ap's bssid &0xf1 */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700745 if (pAd->PermanentAddress[0] == 0xff)
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800746 pAd->PermanentAddress[0] = RandomByte(pAd) & 0xf8;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700747
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -0800748 /*if (pAd->PermanentAddress[5] == 0xff) */
749 /* pAd->PermanentAddress[5] = RandomByte(pAd)&0xf8; */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700750
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800751 DBGPRINT_RAW(RT_DEBUG_TRACE,
752 ("E2PROM MAC: =%02x:%02x:%02x:%02x:%02x:%02x\n",
753 pAd->PermanentAddress[0],
754 pAd->PermanentAddress[1],
755 pAd->PermanentAddress[2],
756 pAd->PermanentAddress[3],
757 pAd->PermanentAddress[4],
758 pAd->PermanentAddress[5]));
759 if (pAd->bLocalAdminMAC == FALSE) {
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700760 MAC_DW0_STRUC csr2;
761 MAC_DW1_STRUC csr3;
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800762 COPY_MAC_ADDR(pAd->CurrentAddress,
763 pAd->PermanentAddress);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700764 csr2.field.Byte0 = pAd->CurrentAddress[0];
765 csr2.field.Byte1 = pAd->CurrentAddress[1];
766 csr2.field.Byte2 = pAd->CurrentAddress[2];
767 csr2.field.Byte3 = pAd->CurrentAddress[3];
768 RTMP_IO_WRITE32(pAd, MAC_ADDR_DW0, csr2.word);
769 csr3.word = 0;
770 csr3.field.Byte4 = pAd->CurrentAddress[4];
771 csr3.field.Byte5 = pAd->CurrentAddress[5];
772 csr3.field.U2MeMask = 0xff;
773 RTMP_IO_WRITE32(pAd, MAC_ADDR_DW1, csr3.word);
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800774 DBGPRINT_RAW(RT_DEBUG_TRACE,
775 ("E2PROM MAC: =%02x:%02x:%02x:%02x:%02x:%02x\n",
776 PRINT_MAC(pAd->PermanentAddress)));
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700777 }
778 }
779
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -0800780 /* if not return early. cause fail at emulation. */
781 /* Init the channel number for TX channel power */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700782 RTMPReadChannelPwr(pAd);
783
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -0800784 /* if E2PROM version mismatch with driver's expectation, then skip */
785 /* all subsequent E2RPOM retieval and set a system error bit to notify GUI */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700786 RT28xx_EEPROM_READ16(pAd, EEPROM_VERSION_OFFSET, Version.word);
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800787 pAd->EepromVersion =
788 Version.field.Version + Version.field.FaeReleaseNumber * 256;
789 DBGPRINT(RT_DEBUG_TRACE,
790 ("E2PROM: Version = %d, FAE release #%d\n",
791 Version.field.Version, Version.field.FaeReleaseNumber));
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700792
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800793 if (Version.field.Version > VALID_EEPROM_VERSION) {
794 DBGPRINT_ERR(("E2PROM: WRONG VERSION 0x%x, should be %d\n",
795 Version.field.Version, VALID_EEPROM_VERSION));
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700796 /*pAd->SystemErrorBitmap |= 0x00000001;
797
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800798 // hard-code default value when no proper E2PROM installed
799 pAd->bAutoTxAgcA = FALSE;
800 pAd->bAutoTxAgcG = FALSE;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700801
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800802 // Default the channel power
803 for (i = 0; i < MAX_NUM_OF_CHANNELS; i++)
804 pAd->TxPower[i].Power = DEFAULT_RF_TX_POWER;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700805
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800806 // Default the channel power
807 for (i = 0; i < MAX_NUM_OF_11JCHANNELS; i++)
808 pAd->TxPower11J[i].Power = DEFAULT_RF_TX_POWER;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700809
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800810 for(i = 0; i < NUM_EEPROM_BBP_PARMS; i++)
811 pAd->EEPROMDefaultValue[i] = 0xffff;
812 return; */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700813 }
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -0800814 /* Read BBP default value from EEPROM and store to array(EEPROMDefaultValue) in pAd */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700815 RT28xx_EEPROM_READ16(pAd, EEPROM_NIC1_OFFSET, value);
816 pAd->EEPROMDefaultValue[0] = value;
817
818 RT28xx_EEPROM_READ16(pAd, EEPROM_NIC2_OFFSET, value);
819 pAd->EEPROMDefaultValue[1] = value;
820
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -0800821 RT28xx_EEPROM_READ16(pAd, 0x38, value); /* Country Region */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700822 pAd->EEPROMDefaultValue[2] = value;
823
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800824 for (i = 0; i < 8; i++) {
825 RT28xx_EEPROM_READ16(pAd, EEPROM_BBP_BASE_OFFSET + i * 2,
826 value);
827 pAd->EEPROMDefaultValue[i + 3] = value;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700828 }
829
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -0800830 /* We have to parse NIC configuration 0 at here. */
831 /* If TSSI did not have preloaded value, it should reset the TxAutoAgc to false */
832 /* Therefore, we have to read TxAutoAgc control beforehand. */
833 /* Read Tx AGC control bit */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700834 Antenna.word = pAd->EEPROMDefaultValue[0];
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800835 if (Antenna.word == 0xFFFF) {
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200836#ifdef RT30xx
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800837 if (IS_RT3090(pAd) || IS_RT3390(pAd)) {
Bartlomiej Zolnierkiewicz59fe2d82009-04-26 16:06:28 +0200838 Antenna.word = 0;
839 Antenna.field.RfIcType = RFIC_3020;
840 Antenna.field.TxPath = 1;
841 Antenna.field.RxPath = 1;
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800842 } else
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -0800843#endif /* RT30xx // */
Bartlomiej Zolnierkiewicz59fe2d82009-04-26 16:06:28 +0200844 {
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200845
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800846 Antenna.word = 0;
847 Antenna.field.RfIcType = RFIC_2820;
848 Antenna.field.TxPath = 1;
849 Antenna.field.RxPath = 2;
850 DBGPRINT(RT_DEBUG_WARN,
851 ("E2PROM error, hard code as 0x%04x\n",
852 Antenna.word));
Bartlomiej Zolnierkiewicz59fe2d82009-04-26 16:06:28 +0200853 }
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700854 }
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -0800855 /* Choose the desired Tx&Rx stream. */
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800856 if ((pAd->CommonCfg.TxStream == 0)
857 || (pAd->CommonCfg.TxStream > Antenna.field.TxPath))
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700858 pAd->CommonCfg.TxStream = Antenna.field.TxPath;
859
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800860 if ((pAd->CommonCfg.RxStream == 0)
861 || (pAd->CommonCfg.RxStream > Antenna.field.RxPath)) {
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700862 pAd->CommonCfg.RxStream = Antenna.field.RxPath;
863
864 if ((pAd->MACVersion < RALINK_2883_VERSION) &&
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800865 (pAd->CommonCfg.RxStream > 2)) {
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -0800866 /* only 2 Rx streams for RT2860 series */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700867 pAd->CommonCfg.RxStream = 2;
868 }
869 }
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -0800870 /* 3*3 */
871 /* read value from EEPROM and set them to CSR174 ~ 177 in chain0 ~ chain2 */
872 /* yet implement */
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800873 for (i = 0; i < 3; i++) {
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700874 }
875
876 NicConfig2.word = pAd->EEPROMDefaultValue[1];
877
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700878 {
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800879 if ((NicConfig2.word & 0x00ff) == 0xff) {
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700880 NicConfig2.word &= 0xff00;
881 }
882
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800883 if ((NicConfig2.word >> 8) == 0xff) {
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700884 NicConfig2.word &= 0x00ff;
885 }
886 }
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700887
888 if (NicConfig2.field.DynamicTxAgcControl == 1)
889 pAd->bAutoTxAgcA = pAd->bAutoTxAgcG = TRUE;
890 else
891 pAd->bAutoTxAgcA = pAd->bAutoTxAgcG = FALSE;
892
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800893 DBGPRINT_RAW(RT_DEBUG_TRACE,
894 ("NICReadEEPROMParameters: RxPath = %d, TxPath = %d\n",
895 Antenna.field.RxPath, Antenna.field.TxPath));
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700896
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -0800897 /* Save the antenna for future use */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700898 pAd->Antenna.word = Antenna.word;
899
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -0800900 /* Set the RfICType here, then we can initialize RFIC related operation callbacks */
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -0800901 pAd->Mlme.RealRxPath = (u8)Antenna.field.RxPath;
902 pAd->RfIcType = (u8)Antenna.field.RfIcType;
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200903
904#ifdef RTMP_RF_RW_SUPPORT
905 RtmpChipOpsRFHook(pAd);
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -0800906#endif /* RTMP_RF_RW_SUPPORT // */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200907
908#ifdef RTMP_MAC_PCI
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -0800909 sprintf((char *)pAd->nickname, "RT2860STA");
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -0800910#endif /* RTMP_MAC_PCI // */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200911
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -0800912 /* */
913 /* Reset PhyMode if we don't support 802.11a */
914 /* Only RFIC_2850 & RFIC_2750 support 802.11a */
915 /* */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200916 if ((Antenna.field.RfIcType != RFIC_2850)
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800917 && (Antenna.field.RfIcType != RFIC_2750)
918 && (Antenna.field.RfIcType != RFIC_3052)) {
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700919 if ((pAd->CommonCfg.PhyMode == PHY_11ABG_MIXED) ||
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800920 (pAd->CommonCfg.PhyMode == PHY_11A))
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700921 pAd->CommonCfg.PhyMode = PHY_11BG_MIXED;
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800922 else if ((pAd->CommonCfg.PhyMode == PHY_11ABGN_MIXED) ||
923 (pAd->CommonCfg.PhyMode == PHY_11AN_MIXED) ||
924 (pAd->CommonCfg.PhyMode == PHY_11AGN_MIXED) ||
925 (pAd->CommonCfg.PhyMode == PHY_11N_5G))
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700926 pAd->CommonCfg.PhyMode = PHY_11BGN_MIXED;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700927 }
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -0800928 /* Read TSSI reference and TSSI boundary for temperature compensation. This is ugly */
929 /* 0. 11b/g */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700930 {
931 /* these are tempature reference value (0x00 ~ 0xFE)
932 ex: 0x00 0x15 0x25 0x45 0x88 0xA0 0xB5 0xD0 0xF0
933 TssiPlusBoundaryG [4] [3] [2] [1] [0] (smaller) +
934 TssiMinusBoundaryG[0] [1] [2] [3] [4] (larger) */
935 RT28xx_EEPROM_READ16(pAd, 0x6E, Power.word);
936 pAd->TssiMinusBoundaryG[4] = Power.field.Byte0;
937 pAd->TssiMinusBoundaryG[3] = Power.field.Byte1;
938 RT28xx_EEPROM_READ16(pAd, 0x70, Power.word);
939 pAd->TssiMinusBoundaryG[2] = Power.field.Byte0;
940 pAd->TssiMinusBoundaryG[1] = Power.field.Byte1;
941 RT28xx_EEPROM_READ16(pAd, 0x72, Power.word);
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800942 pAd->TssiRefG = Power.field.Byte0; /* reference value [0] */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700943 pAd->TssiPlusBoundaryG[1] = Power.field.Byte1;
944 RT28xx_EEPROM_READ16(pAd, 0x74, Power.word);
945 pAd->TssiPlusBoundaryG[2] = Power.field.Byte0;
946 pAd->TssiPlusBoundaryG[3] = Power.field.Byte1;
947 RT28xx_EEPROM_READ16(pAd, 0x76, Power.word);
948 pAd->TssiPlusBoundaryG[4] = Power.field.Byte0;
949 pAd->TxAgcStepG = Power.field.Byte1;
950 pAd->TxAgcCompensateG = 0;
951 pAd->TssiMinusBoundaryG[0] = pAd->TssiRefG;
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800952 pAd->TssiPlusBoundaryG[0] = pAd->TssiRefG;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700953
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -0800954 /* Disable TxAgc if the based value is not right */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700955 if (pAd->TssiRefG == 0xff)
956 pAd->bAutoTxAgcG = FALSE;
957
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800958 DBGPRINT(RT_DEBUG_TRACE,
959 ("E2PROM: G Tssi[-4 .. +4] = %d %d %d %d - %d -%d %d %d %d, step=%d, tuning=%d\n",
960 pAd->TssiMinusBoundaryG[4],
961 pAd->TssiMinusBoundaryG[3],
962 pAd->TssiMinusBoundaryG[2],
963 pAd->TssiMinusBoundaryG[1], pAd->TssiRefG,
964 pAd->TssiPlusBoundaryG[1], pAd->TssiPlusBoundaryG[2],
965 pAd->TssiPlusBoundaryG[3], pAd->TssiPlusBoundaryG[4],
966 pAd->TxAgcStepG, pAd->bAutoTxAgcG));
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700967 }
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -0800968 /* 1. 11a */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700969 {
970 RT28xx_EEPROM_READ16(pAd, 0xD4, Power.word);
971 pAd->TssiMinusBoundaryA[4] = Power.field.Byte0;
972 pAd->TssiMinusBoundaryA[3] = Power.field.Byte1;
973 RT28xx_EEPROM_READ16(pAd, 0xD6, Power.word);
974 pAd->TssiMinusBoundaryA[2] = Power.field.Byte0;
975 pAd->TssiMinusBoundaryA[1] = Power.field.Byte1;
976 RT28xx_EEPROM_READ16(pAd, 0xD8, Power.word);
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800977 pAd->TssiRefA = Power.field.Byte0;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700978 pAd->TssiPlusBoundaryA[1] = Power.field.Byte1;
979 RT28xx_EEPROM_READ16(pAd, 0xDA, Power.word);
980 pAd->TssiPlusBoundaryA[2] = Power.field.Byte0;
981 pAd->TssiPlusBoundaryA[3] = Power.field.Byte1;
982 RT28xx_EEPROM_READ16(pAd, 0xDC, Power.word);
983 pAd->TssiPlusBoundaryA[4] = Power.field.Byte0;
984 pAd->TxAgcStepA = Power.field.Byte1;
985 pAd->TxAgcCompensateA = 0;
986 pAd->TssiMinusBoundaryA[0] = pAd->TssiRefA;
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800987 pAd->TssiPlusBoundaryA[0] = pAd->TssiRefA;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700988
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -0800989 /* Disable TxAgc if the based value is not right */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700990 if (pAd->TssiRefA == 0xff)
991 pAd->bAutoTxAgcA = FALSE;
992
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -0800993 DBGPRINT(RT_DEBUG_TRACE,
994 ("E2PROM: A Tssi[-4 .. +4] = %d %d %d %d - %d -%d %d %d %d, step=%d, tuning=%d\n",
995 pAd->TssiMinusBoundaryA[4],
996 pAd->TssiMinusBoundaryA[3],
997 pAd->TssiMinusBoundaryA[2],
998 pAd->TssiMinusBoundaryA[1], pAd->TssiRefA,
999 pAd->TssiPlusBoundaryA[1], pAd->TssiPlusBoundaryA[2],
1000 pAd->TssiPlusBoundaryA[3], pAd->TssiPlusBoundaryA[4],
1001 pAd->TxAgcStepA, pAd->bAutoTxAgcA));
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001002 }
1003 pAd->BbpRssiToDbmDelta = 0x0;
1004
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001005 /* Read frequency offset setting for RF */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001006 RT28xx_EEPROM_READ16(pAd, EEPROM_FREQ_OFFSET, value);
1007 if ((value & 0x00FF) != 0x00FF)
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -08001008 pAd->RfFreqOffset = (unsigned long)(value & 0x00FF);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001009 else
1010 pAd->RfFreqOffset = 0;
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08001011 DBGPRINT(RT_DEBUG_TRACE,
1012 ("E2PROM: RF FreqOffset=0x%lx \n", pAd->RfFreqOffset));
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001013
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001014 /*CountryRegion byte offset (38h) */
1015 value = pAd->EEPROMDefaultValue[2] >> 8; /* 2.4G band */
1016 value2 = pAd->EEPROMDefaultValue[2] & 0x00FF; /* 5G band */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001017
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08001018 if ((value <= REGION_MAXIMUM_BG_BAND)
1019 && (value2 <= REGION_MAXIMUM_A_BAND)) {
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -08001020 pAd->CommonCfg.CountryRegion = ((u8)value) | 0x80;
1021 pAd->CommonCfg.CountryRegionForABand = ((u8)value2) | 0x80;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001022 TmpPhy = pAd->CommonCfg.PhyMode;
1023 pAd->CommonCfg.PhyMode = 0xff;
1024 RTMPSetPhyMode(pAd, TmpPhy);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001025 SetCommonHT(pAd);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001026 }
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001027 /* */
1028 /* Get RSSI Offset on EEPROM 0x9Ah & 0x9Ch. */
1029 /* The valid value are (-10 ~ 10) */
1030 /* */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001031 RT28xx_EEPROM_READ16(pAd, EEPROM_RSSI_BG_OFFSET, value);
1032 pAd->BGRssiOffset0 = value & 0x00ff;
1033 pAd->BGRssiOffset1 = (value >> 8);
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08001034 RT28xx_EEPROM_READ16(pAd, EEPROM_RSSI_BG_OFFSET + 2, value);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001035 pAd->BGRssiOffset2 = value & 0x00ff;
1036 pAd->ALNAGain1 = (value >> 8);
1037 RT28xx_EEPROM_READ16(pAd, EEPROM_LNA_OFFSET, value);
1038 pAd->BLNAGain = value & 0x00ff;
1039 pAd->ALNAGain0 = (value >> 8);
1040
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001041 /* Validate 11b/g RSSI_0 offset. */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001042 if ((pAd->BGRssiOffset0 < -10) || (pAd->BGRssiOffset0 > 10))
1043 pAd->BGRssiOffset0 = 0;
1044
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001045 /* Validate 11b/g RSSI_1 offset. */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001046 if ((pAd->BGRssiOffset1 < -10) || (pAd->BGRssiOffset1 > 10))
1047 pAd->BGRssiOffset1 = 0;
1048
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001049 /* Validate 11b/g RSSI_2 offset. */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001050 if ((pAd->BGRssiOffset2 < -10) || (pAd->BGRssiOffset2 > 10))
1051 pAd->BGRssiOffset2 = 0;
1052
1053 RT28xx_EEPROM_READ16(pAd, EEPROM_RSSI_A_OFFSET, value);
1054 pAd->ARssiOffset0 = value & 0x00ff;
1055 pAd->ARssiOffset1 = (value >> 8);
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08001056 RT28xx_EEPROM_READ16(pAd, (EEPROM_RSSI_A_OFFSET + 2), value);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001057 pAd->ARssiOffset2 = value & 0x00ff;
1058 pAd->ALNAGain2 = (value >> 8);
1059
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -08001060 if (((u8)pAd->ALNAGain1 == 0xFF) || (pAd->ALNAGain1 == 0x00))
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001061 pAd->ALNAGain1 = pAd->ALNAGain0;
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -08001062 if (((u8)pAd->ALNAGain2 == 0xFF) || (pAd->ALNAGain2 == 0x00))
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001063 pAd->ALNAGain2 = pAd->ALNAGain0;
1064
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001065 /* Validate 11a RSSI_0 offset. */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001066 if ((pAd->ARssiOffset0 < -10) || (pAd->ARssiOffset0 > 10))
1067 pAd->ARssiOffset0 = 0;
1068
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001069 /* Validate 11a RSSI_1 offset. */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001070 if ((pAd->ARssiOffset1 < -10) || (pAd->ARssiOffset1 > 10))
1071 pAd->ARssiOffset1 = 0;
1072
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001073 /*Validate 11a RSSI_2 offset. */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001074 if ((pAd->ARssiOffset2 < -10) || (pAd->ARssiOffset2 > 10))
1075 pAd->ARssiOffset2 = 0;
1076
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02001077#ifdef RT30xx
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001078 /* */
1079 /* Get TX mixer gain setting */
1080 /* 0xff are invalid value */
1081 /* Note: RT30xX default value is 0x00 and will program to RF_R17 only when this value is not zero. */
1082 /* RT359X default value is 0x02 */
1083 /* */
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08001084 if (IS_RT30xx(pAd) || IS_RT3572(pAd)) {
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02001085 RT28xx_EEPROM_READ16(pAd, EEPROM_TXMIXER_GAIN_2_4G, value);
1086 pAd->TxMixerGain24G = 0;
1087 value &= 0x00ff;
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08001088 if (value != 0xff) {
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02001089 value &= 0x07;
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -08001090 pAd->TxMixerGain24G = (u8)value;
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02001091 }
1092 }
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001093#endif /* RT30xx // */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02001094
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001095 /* */
1096 /* Get LED Setting. */
1097 /* */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001098 RT28xx_EEPROM_READ16(pAd, 0x3a, value);
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08001099 pAd->LedCntl.word = (value >> 8);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001100 RT28xx_EEPROM_READ16(pAd, EEPROM_LED1_OFFSET, value);
1101 pAd->Led1 = value;
1102 RT28xx_EEPROM_READ16(pAd, EEPROM_LED2_OFFSET, value);
1103 pAd->Led2 = value;
1104 RT28xx_EEPROM_READ16(pAd, EEPROM_LED3_OFFSET, value);
1105 pAd->Led3 = value;
1106
1107 RTMPReadTxPwrPerRate(pAd);
1108
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02001109#ifdef RT30xx
1110#ifdef RTMP_EFUSE_SUPPORT
1111 RtmpEfuseSupportCheck(pAd);
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001112#endif /* RTMP_EFUSE_SUPPORT // */
1113#endif /* RT30xx // */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02001114
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001115 DBGPRINT(RT_DEBUG_TRACE, ("<-- NICReadEEPROMParameters\n"));
1116}
1117
1118/*
1119 ========================================================================
1120
1121 Routine Description:
1122 Set default value from EEPROM
1123
1124 Arguments:
1125 Adapter Pointer to our adapter
1126
1127 Return Value:
1128 None
1129
1130 IRQL = PASSIVE_LEVEL
1131
1132 Note:
1133
1134 ========================================================================
1135*/
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -08001136void NICInitAsicFromEEPROM(struct rt_rtmp_adapter *pAd)
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001137{
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -08001138 u32 data = 0;
1139 u8 BBPR1 = 0;
1140 u16 i;
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001141/* EEPROM_ANTENNA_STRUC Antenna; */
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08001142 EEPROM_NIC_CONFIG2_STRUC NicConfig2;
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -08001143 u8 BBPR3 = 0;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001144
1145 DBGPRINT(RT_DEBUG_TRACE, ("--> NICInitAsicFromEEPROM\n"));
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08001146 for (i = 3; i < NUM_EEPROM_BBP_PARMS; i++) {
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -08001147 u8 BbpRegIdx, BbpValue;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001148
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08001149 if ((pAd->EEPROMDefaultValue[i] != 0xFFFF)
1150 && (pAd->EEPROMDefaultValue[i] != 0)) {
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -08001151 BbpRegIdx = (u8)(pAd->EEPROMDefaultValue[i] >> 8);
1152 BbpValue = (u8)(pAd->EEPROMDefaultValue[i] & 0xff);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001153 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BbpRegIdx, BbpValue);
1154 }
1155 }
1156
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001157 NicConfig2.word = pAd->EEPROMDefaultValue[1];
1158
Bartlomiej Zolnierkiewicz59fe2d82009-04-26 16:06:28 +02001159 {
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08001160 if ((NicConfig2.word & 0x00ff) == 0xff) {
Bartlomiej Zolnierkiewicz59fe2d82009-04-26 16:06:28 +02001161 NicConfig2.word &= 0xff00;
1162 }
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001163
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08001164 if ((NicConfig2.word >> 8) == 0xff) {
Bartlomiej Zolnierkiewicz59fe2d82009-04-26 16:06:28 +02001165 NicConfig2.word &= 0x00ff;
1166 }
1167 }
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02001168
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001169 /* Save the antenna for future use */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001170 pAd->NicConfig2.word = NicConfig2.word;
1171
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02001172#ifdef RT30xx
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001173 /* set default antenna as main */
Bartlomiej Zolnierkiewicz59fe2d82009-04-26 16:06:28 +02001174 if (pAd->RfIcType == RFIC_3020)
1175 AsicSetRxAnt(pAd, pAd->RxAnt.Pair1PrimaryRxAnt);
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001176#endif /* RT30xx // */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02001177
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001178 /* */
1179 /* Send LED Setting to MCU. */
1180 /* */
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08001181 if (pAd->LedCntl.word == 0xFF) {
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001182 pAd->LedCntl.word = 0x01;
1183 pAd->Led1 = 0x5555;
1184 pAd->Led2 = 0x2221;
Bartlomiej Zolnierkiewicz59fe2d82009-04-26 16:06:28 +02001185
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02001186#ifdef RTMP_MAC_PCI
1187 pAd->Led3 = 0xA9F8;
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001188#endif /* RTMP_MAC_PCI // */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02001189#ifdef RTMP_MAC_USB
Bartlomiej Zolnierkiewicz59fe2d82009-04-26 16:06:28 +02001190 pAd->Led3 = 0x5627;
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001191#endif /* RTMP_MAC_USB // */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001192 }
1193
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -08001194 AsicSendCommandToMcu(pAd, 0x52, 0xff, (u8)pAd->Led1,
1195 (u8)(pAd->Led1 >> 8));
1196 AsicSendCommandToMcu(pAd, 0x53, 0xff, (u8)pAd->Led2,
1197 (u8)(pAd->Led2 >> 8));
1198 AsicSendCommandToMcu(pAd, 0x54, 0xff, (u8)pAd->Led3,
1199 (u8)(pAd->Led3 >> 8));
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02001200 AsicSendCommandToMcu(pAd, 0x51, 0xff, 0, pAd->LedCntl.field.Polarity);
1201
1202 pAd->LedIndicatorStrength = 0xFF;
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001203 RTMPSetSignalLED(pAd, -100); /* Force signal strength Led to be turned off, before link up */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001204
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001205 {
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001206 /* Read Hardware controlled Radio state enable bit */
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08001207 if (NicConfig2.field.HardwareRadioControl == 1) {
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001208 pAd->StaCfg.bHardwareRadio = TRUE;
1209
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001210 /* Read GPIO pin2 as Hardware controlled radio state */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001211 RTMP_IO_READ32(pAd, GPIO_CTRL_CFG, &data);
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08001212 if ((data & 0x04) == 0) {
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001213 pAd->StaCfg.bHwRadio = FALSE;
1214 pAd->StaCfg.bRadio = FALSE;
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001215/* RTMP_IO_WRITE32(pAd, PWR_PIN_CFG, 0x00001818); */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001216 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_RADIO_OFF);
1217 }
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08001218 } else
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001219 pAd->StaCfg.bHardwareRadio = FALSE;
1220
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08001221 if (pAd->StaCfg.bRadio == FALSE) {
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001222 RTMPSetLED(pAd, LED_RADIO_OFF);
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08001223 } else {
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001224 RTMPSetLED(pAd, LED_RADIO_ON);
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02001225#ifdef RTMP_MAC_PCI
Bartlomiej Zolnierkiewicze44fd1c2009-09-22 20:44:24 +02001226#ifdef RT3090
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08001227 AsicSendCommandToMcu(pAd, 0x30, PowerRadioOffCID, 0xff,
1228 0x02);
Bartlomiej Zolnierkiewicze44fd1c2009-09-22 20:44:24 +02001229 AsicCheckCommanOk(pAd, PowerRadioOffCID);
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001230#endif /* RT3090 // */
Bartlomiej Zolnierkiewicze44fd1c2009-09-22 20:44:24 +02001231#ifndef RT3090
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001232 AsicSendCommandToMcu(pAd, 0x30, 0xff, 0xff, 0x02);
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001233#endif /* RT3090 // */
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08001234 AsicSendCommandToMcu(pAd, 0x31, PowerWakeCID, 0x00,
1235 0x00);
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001236 /* 2-1. wait command ok. */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001237 AsicCheckCommanOk(pAd, PowerWakeCID);
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001238#endif /* RTMP_MAC_PCI // */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001239 }
1240 }
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001241
Bartlomiej Zolnierkiewicze44fd1c2009-09-22 20:44:24 +02001242#ifdef RTMP_MAC_PCI
1243#ifdef RT30xx
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08001244 if (IS_RT3090(pAd) || IS_RT3572(pAd) || IS_RT3390(pAd)) {
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -08001245 struct rt_rtmp_chip_op *pChipOps = &pAd->chipOps;
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08001246 if (pChipOps->AsicReverseRfFromSleepMode)
1247 pChipOps->AsicReverseRfFromSleepMode(pAd);
1248 }
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001249 /* 3090 MCU Wakeup command needs more time to be stable. */
1250 /* Before stable, don't issue other MCU command to prevent from firmware error. */
Bartlomiej Zolnierkiewicze44fd1c2009-09-22 20:44:24 +02001251
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08001252 if ((IS_RT3090(pAd) || IS_RT3572(pAd) || IS_RT3390(pAd))
1253 && IS_VERSION_AFTER_F(pAd)
1254 && (pAd->StaCfg.PSControl.field.rt30xxPowerMode == 3)
1255 && (pAd->StaCfg.PSControl.field.EnableNewPS == TRUE)) {
1256 DBGPRINT(RT_DEBUG_TRACE, ("%s, release Mcu Lock\n", __func__));
1257 RTMP_SEM_LOCK(&pAd->McuCmdLock);
1258 pAd->brt30xxBanMcuCmd = FALSE;
1259 RTMP_SEM_UNLOCK(&pAd->McuCmdLock);
1260 }
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001261#endif /* RT30xx // */
1262#endif /* RTMP_MAC_PCI // */
Bartlomiej Zolnierkiewicze44fd1c2009-09-22 20:44:24 +02001263
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001264 /* Turn off patching for cardbus controller */
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08001265 if (NicConfig2.field.CardbusAcceleration == 1) {
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001266/* pAd->bTest1 = TRUE; */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001267 }
1268
1269 if (NicConfig2.field.DynamicTxAgcControl == 1)
1270 pAd->bAutoTxAgcA = pAd->bAutoTxAgcG = TRUE;
1271 else
1272 pAd->bAutoTxAgcA = pAd->bAutoTxAgcG = FALSE;
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001273 /* */
1274 /* Since BBP has been progamed, to make sure BBP setting will be */
Sebastian Dalfuß06aea992009-11-07 17:31:12 +01001275 /* upate inside of AsicAntennaSelect, so reset to UNKNOWN_BAND! */
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001276 /* */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001277 pAd->CommonCfg.BandState = UNKNOWN_BAND;
1278
1279 RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R3, &BBPR3);
1280 BBPR3 &= (~0x18);
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08001281 if (pAd->Antenna.field.RxPath == 3) {
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001282 BBPR3 |= (0x10);
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08001283 } else if (pAd->Antenna.field.RxPath == 2) {
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001284 BBPR3 |= (0x8);
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08001285 } else if (pAd->Antenna.field.RxPath == 1) {
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001286 BBPR3 |= (0x0);
1287 }
1288 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, BBPR3);
1289
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001290 {
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001291 /* Handle the difference when 1T */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001292 RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R1, &BBPR1);
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08001293 if (pAd->Antenna.field.TxPath == 1) {
1294 BBPR1 &= (~0x18);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001295 }
1296 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R1, BBPR1);
1297
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08001298 DBGPRINT(RT_DEBUG_TRACE,
1299 ("Use Hw Radio Control Pin=%d; if used Pin=%d;\n",
1300 pAd->CommonCfg.bHardwareRadio,
1301 pAd->CommonCfg.bHardwareRadio));
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001302 }
Bartlomiej Zolnierkiewicz6a28a69a2009-04-26 16:05:46 +02001303
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02001304#ifdef RTMP_MAC_USB
1305#ifdef RT30xx
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001306 /* update registers from EEPROM for RT3071 or later(3572/3592). */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02001307
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08001308 if (IS_RT3090(pAd) || IS_RT3572(pAd) || IS_RT3390(pAd)) {
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -08001309 u8 RegIdx, RegValue;
1310 u16 value;
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02001311
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001312 /* after RT3071, write BBP from EEPROM 0xF0 to 0x102 */
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08001313 for (i = 0xF0; i <= 0x102; i = i + 2) {
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02001314 value = 0xFFFF;
1315 RT28xx_EEPROM_READ16(pAd, i, value);
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08001316 if ((value != 0xFFFF) && (value != 0)) {
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -08001317 RegIdx = (u8)(value >> 8);
1318 RegValue = (u8)(value & 0xff);
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08001319 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, RegIdx,
1320 RegValue);
1321 DBGPRINT(RT_DEBUG_TRACE,
1322 ("Update BBP Registers from EEPROM(0x%0x), BBP(0x%x) = 0x%x\n",
1323 i, RegIdx, RegValue));
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02001324 }
1325 }
1326
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001327 /* after RT3071, write RF from EEPROM 0x104 to 0x116 */
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08001328 for (i = 0x104; i <= 0x116; i = i + 2) {
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02001329 value = 0xFFFF;
1330 RT28xx_EEPROM_READ16(pAd, i, value);
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08001331 if ((value != 0xFFFF) && (value != 0)) {
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -08001332 RegIdx = (u8)(value >> 8);
1333 RegValue = (u8)(value & 0xff);
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02001334 RT30xxWriteRFRegister(pAd, RegIdx, RegValue);
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08001335 DBGPRINT(RT_DEBUG_TRACE,
1336 ("Update RF Registers from EEPROM0x%x), BBP(0x%x) = 0x%x\n",
1337 i, RegIdx, RegValue));
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02001338 }
1339 }
1340 }
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001341#endif /* RT30xx // */
1342#endif /* RTMP_MAC_USB // */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02001343
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08001344 DBGPRINT(RT_DEBUG_TRACE,
1345 ("TxPath = %d, RxPath = %d, RFIC=%d, Polar+LED mode=%x\n",
1346 pAd->Antenna.field.TxPath, pAd->Antenna.field.RxPath,
1347 pAd->RfIcType, pAd->LedCntl.word));
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001348 DBGPRINT(RT_DEBUG_TRACE, ("<-- NICInitAsicFromEEPROM\n"));
1349}
1350
1351/*
1352 ========================================================================
1353
1354 Routine Description:
1355 Initialize NIC hardware
1356
1357 Arguments:
1358 Adapter Pointer to our adapter
1359
1360 Return Value:
1361 None
1362
1363 IRQL = PASSIVE_LEVEL
1364
1365 Note:
1366
1367 ========================================================================
1368*/
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -08001369int NICInitializeAdapter(struct rt_rtmp_adapter *pAd, IN BOOLEAN bHardReset)
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001370{
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -08001371 int Status = NDIS_STATUS_SUCCESS;
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08001372 WPDMA_GLO_CFG_STRUC GloCfg;
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02001373#ifdef RTMP_MAC_PCI
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -08001374 u32 Value;
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08001375 DELAY_INT_CFG_STRUC IntCfg;
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001376#endif /* RTMP_MAC_PCI // */
1377/* INT_MASK_CSR_STRUC IntMask; */
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -08001378 unsigned long i = 0, j = 0;
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08001379 AC_TXOP_CSR0_STRUC csr0;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001380
1381 DBGPRINT(RT_DEBUG_TRACE, ("--> NICInitializeAdapter\n"));
1382
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001383 /* 3. Set DMA global configuration except TX_DMA_EN and RX_DMA_EN bits: */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001384retry:
1385 i = 0;
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08001386 do {
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001387 RTMP_IO_READ32(pAd, WPDMA_GLO_CFG, &GloCfg.word);
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08001388 if ((GloCfg.field.TxDMABusy == 0)
1389 && (GloCfg.field.RxDMABusy == 0))
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001390 break;
1391
1392 RTMPusecDelay(1000);
1393 i++;
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08001394 } while (i < 100);
1395 DBGPRINT(RT_DEBUG_TRACE,
1396 ("<== DMA offset 0x208 = 0x%x\n", GloCfg.word));
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001397 GloCfg.word &= 0xff0;
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08001398 GloCfg.field.EnTXWriteBackDDONE = 1;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001399 RTMP_IO_WRITE32(pAd, WPDMA_GLO_CFG, GloCfg.word);
1400
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001401 /* Record HW Beacon offset */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001402 pAd->BeaconOffset[0] = HW_BEACON_BASE0;
1403 pAd->BeaconOffset[1] = HW_BEACON_BASE1;
1404 pAd->BeaconOffset[2] = HW_BEACON_BASE2;
1405 pAd->BeaconOffset[3] = HW_BEACON_BASE3;
1406 pAd->BeaconOffset[4] = HW_BEACON_BASE4;
1407 pAd->BeaconOffset[5] = HW_BEACON_BASE5;
1408 pAd->BeaconOffset[6] = HW_BEACON_BASE6;
1409 pAd->BeaconOffset[7] = HW_BEACON_BASE7;
1410
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001411 /* */
1412 /* write all shared Ring's base address into ASIC */
1413 /* */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001414
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001415 /* asic simulation sequence put this ahead before loading firmware. */
1416 /* pbf hardware reset */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02001417#ifdef RTMP_MAC_PCI
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001418 RTMP_IO_WRITE32(pAd, WPDMA_RST_IDX, 0x1003f); /* 0x10000 for reset rx, 0x3f resets all 6 tx rings. */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001419 RTMP_IO_WRITE32(pAd, PBF_SYS_CTRL, 0xe1f);
1420 RTMP_IO_WRITE32(pAd, PBF_SYS_CTRL, 0xe00);
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001421#endif /* RTMP_MAC_PCI // */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001422
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001423 /* Initialze ASIC for TX & Rx operation */
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08001424 if (NICInitializeAsic(pAd, bHardReset) != NDIS_STATUS_SUCCESS) {
1425 if (j++ == 0) {
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001426 NICLoadFirmware(pAd);
1427 goto retry;
1428 }
1429 return NDIS_STATUS_FAILURE;
1430 }
1431
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02001432#ifdef RTMP_MAC_PCI
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001433 /* Write AC_BK base address register */
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08001434 Value =
1435 RTMP_GetPhysicalAddressLow(pAd->TxRing[QID_AC_BK].Cell[0].AllocPa);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001436 RTMP_IO_WRITE32(pAd, TX_BASE_PTR1, Value);
1437 DBGPRINT(RT_DEBUG_TRACE, ("--> TX_BASE_PTR1 : 0x%x\n", Value));
1438
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001439 /* Write AC_BE base address register */
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08001440 Value =
1441 RTMP_GetPhysicalAddressLow(pAd->TxRing[QID_AC_BE].Cell[0].AllocPa);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001442 RTMP_IO_WRITE32(pAd, TX_BASE_PTR0, Value);
1443 DBGPRINT(RT_DEBUG_TRACE, ("--> TX_BASE_PTR0 : 0x%x\n", Value));
1444
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001445 /* Write AC_VI base address register */
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08001446 Value =
1447 RTMP_GetPhysicalAddressLow(pAd->TxRing[QID_AC_VI].Cell[0].AllocPa);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001448 RTMP_IO_WRITE32(pAd, TX_BASE_PTR2, Value);
1449 DBGPRINT(RT_DEBUG_TRACE, ("--> TX_BASE_PTR2 : 0x%x\n", Value));
1450
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001451 /* Write AC_VO base address register */
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08001452 Value =
1453 RTMP_GetPhysicalAddressLow(pAd->TxRing[QID_AC_VO].Cell[0].AllocPa);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001454 RTMP_IO_WRITE32(pAd, TX_BASE_PTR3, Value);
1455 DBGPRINT(RT_DEBUG_TRACE, ("--> TX_BASE_PTR3 : 0x%x\n", Value));
1456
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001457 /* Write MGMT_BASE_CSR register */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001458 Value = RTMP_GetPhysicalAddressLow(pAd->MgmtRing.Cell[0].AllocPa);
1459 RTMP_IO_WRITE32(pAd, TX_BASE_PTR5, Value);
1460 DBGPRINT(RT_DEBUG_TRACE, ("--> TX_BASE_PTR5 : 0x%x\n", Value));
1461
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001462 /* Write RX_BASE_CSR register */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001463 Value = RTMP_GetPhysicalAddressLow(pAd->RxRing.Cell[0].AllocPa);
1464 RTMP_IO_WRITE32(pAd, RX_BASE_PTR, Value);
1465 DBGPRINT(RT_DEBUG_TRACE, ("--> RX_BASE_PTR : 0x%x\n", Value));
1466
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001467 /* Init RX Ring index pointer */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001468 pAd->RxRing.RxSwReadIdx = 0;
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08001469 pAd->RxRing.RxCpuIdx = RX_RING_SIZE - 1;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001470 RTMP_IO_WRITE32(pAd, RX_CRX_IDX, pAd->RxRing.RxCpuIdx);
1471
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001472 /* Init TX rings index pointer */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001473 {
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08001474 for (i = 0; i < NUM_OF_TX_RING; i++) {
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001475 pAd->TxRing[i].TxSwFreeIdx = 0;
1476 pAd->TxRing[i].TxCpuIdx = 0;
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08001477 RTMP_IO_WRITE32(pAd, (TX_CTX_IDX0 + i * 0x10),
1478 pAd->TxRing[i].TxCpuIdx);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001479 }
1480 }
1481
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001482 /* init MGMT ring index pointer */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001483 pAd->MgmtRing.TxSwFreeIdx = 0;
1484 pAd->MgmtRing.TxCpuIdx = 0;
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08001485 RTMP_IO_WRITE32(pAd, TX_MGMTCTX_IDX, pAd->MgmtRing.TxCpuIdx);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001486
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001487 /* */
1488 /* set each Ring's SIZE into ASIC. Descriptor Size is fixed by design. */
1489 /* */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001490
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001491 /* Write TX_RING_CSR0 register */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001492 Value = TX_RING_SIZE;
1493 RTMP_IO_WRITE32(pAd, TX_MAX_CNT0, Value);
1494 RTMP_IO_WRITE32(pAd, TX_MAX_CNT1, Value);
1495 RTMP_IO_WRITE32(pAd, TX_MAX_CNT2, Value);
1496 RTMP_IO_WRITE32(pAd, TX_MAX_CNT3, Value);
1497 RTMP_IO_WRITE32(pAd, TX_MAX_CNT4, Value);
1498 Value = MGMT_RING_SIZE;
1499 RTMP_IO_WRITE32(pAd, TX_MGMTMAX_CNT, Value);
1500
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001501 /* Write RX_RING_CSR register */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001502 Value = RX_RING_SIZE;
1503 RTMP_IO_WRITE32(pAd, RX_MAX_CNT, Value);
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001504#endif /* RTMP_MAC_PCI // */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001505
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001506 /* WMM parameter */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001507 csr0.word = 0;
1508 RTMP_IO_WRITE32(pAd, WMM_TXOP0_CFG, csr0.word);
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08001509 if (pAd->CommonCfg.PhyMode == PHY_11B) {
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001510 csr0.field.Ac0Txop = 192; /* AC_VI: 192*32us ~= 6ms */
1511 csr0.field.Ac1Txop = 96; /* AC_VO: 96*32us ~= 3ms */
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08001512 } else {
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001513 csr0.field.Ac0Txop = 96; /* AC_VI: 96*32us ~= 3ms */
1514 csr0.field.Ac1Txop = 48; /* AC_VO: 48*32us ~= 1.5ms */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001515 }
1516 RTMP_IO_WRITE32(pAd, WMM_TXOP1_CFG, csr0.word);
1517
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02001518#ifdef RTMP_MAC_PCI
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001519 /* 3. Set DMA global configuration except TX_DMA_EN and RX_DMA_EN bits: */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001520 i = 0;
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08001521 do {
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001522 RTMP_IO_READ32(pAd, WPDMA_GLO_CFG, &GloCfg.word);
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08001523 if ((GloCfg.field.TxDMABusy == 0)
1524 && (GloCfg.field.RxDMABusy == 0))
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001525 break;
1526
1527 RTMPusecDelay(1000);
1528 i++;
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08001529 } while (i < 100);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001530
1531 GloCfg.word &= 0xff0;
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08001532 GloCfg.field.EnTXWriteBackDDONE = 1;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001533 RTMP_IO_WRITE32(pAd, WPDMA_GLO_CFG, GloCfg.word);
1534
1535 IntCfg.word = 0;
1536 RTMP_IO_WRITE32(pAd, DELAY_INT_CFG, IntCfg.word);
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001537#endif /* RTMP_MAC_PCI // */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001538
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001539 /* reset action */
1540 /* Load firmware */
1541 /* Status = NICLoadFirmware(pAd); */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001542
1543 DBGPRINT(RT_DEBUG_TRACE, ("<-- NICInitializeAdapter\n"));
1544 return Status;
1545}
1546
1547/*
1548 ========================================================================
1549
1550 Routine Description:
1551 Initialize ASIC
1552
1553 Arguments:
1554 Adapter Pointer to our adapter
1555
1556 Return Value:
1557 None
1558
1559 IRQL = PASSIVE_LEVEL
1560
1561 Note:
1562
1563 ========================================================================
1564*/
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -08001565int NICInitializeAsic(struct rt_rtmp_adapter *pAd, IN BOOLEAN bHardReset)
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001566{
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -08001567 unsigned long Index = 0;
1568 u8 R0 = 0xff;
1569 u32 MacCsr12 = 0, Counter = 0;
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02001570#ifdef RTMP_MAC_USB
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -08001571 u32 MacCsr0 = 0;
1572 int Status;
1573 u8 Value = 0xff;
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001574#endif /* RTMP_MAC_USB // */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02001575#ifdef RT30xx
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -08001576 u8 bbpreg = 0;
1577 u8 RFValue = 0;
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001578#endif /* RT30xx // */
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -08001579 u16 KeyIdx;
1580 int i, apidx;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001581
1582 DBGPRINT(RT_DEBUG_TRACE, ("--> NICInitializeAsic\n"));
1583
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02001584#ifdef RTMP_MAC_PCI
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001585 RTMP_IO_WRITE32(pAd, PWR_PIN_CFG, 0x3); /* To fix driver disable/enable hang issue when radio off */
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08001586 if (bHardReset == TRUE) {
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001587 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, 0x3);
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08001588 } else
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001589 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, 0x1);
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02001590
1591 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, 0x0);
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001592 /* Initialize MAC register to default value */
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08001593 for (Index = 0; Index < NUM_MAC_REG_PARMS; Index++) {
1594 RTMP_IO_WRITE32(pAd, MACRegTable[Index].Register,
1595 MACRegTable[Index].Value);
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02001596 }
1597
1598 {
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08001599 for (Index = 0; Index < NUM_STA_MAC_REG_PARMS; Index++) {
1600 RTMP_IO_WRITE32(pAd, STAMACRegTable[Index].Register,
1601 STAMACRegTable[Index].Value);
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02001602 }
1603 }
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001604#endif /* RTMP_MAC_PCI // */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02001605#ifdef RTMP_MAC_USB
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001606 /* */
1607 /* Make sure MAC gets ready after NICLoadFirmware(). */
1608 /* */
Bartlomiej Zolnierkiewicz59fe2d82009-04-26 16:06:28 +02001609 Index = 0;
1610
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001611 /*To avoid hang-on issue when interface up in kernel 2.4, */
1612 /*we use a local variable "MacCsr0" instead of using "pAd->MACVersion" directly. */
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08001613 do {
Bartlomiej Zolnierkiewicz59fe2d82009-04-26 16:06:28 +02001614 RTMP_IO_READ32(pAd, MAC_CSR0, &MacCsr0);
1615
1616 if ((MacCsr0 != 0x00) && (MacCsr0 != 0xFFFFFFFF))
1617 break;
1618
1619 RTMPusecDelay(10);
1620 } while (Index++ < 100);
1621
1622 pAd->MACVersion = MacCsr0;
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08001623 DBGPRINT(RT_DEBUG_TRACE,
1624 ("MAC_CSR0 [ Ver:Rev=0x%08x]\n", pAd->MACVersion));
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001625 /* turn on bit13 (set to zero) after rt2860D. This is to solve high-current issue. */
Bartlomiej Zolnierkiewicz59fe2d82009-04-26 16:06:28 +02001626 RTMP_IO_READ32(pAd, PBF_SYS_CTRL, &MacCsr12);
1627 MacCsr12 &= (~0x2000);
1628 RTMP_IO_WRITE32(pAd, PBF_SYS_CTRL, MacCsr12);
1629
1630 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, 0x3);
1631 RTMP_IO_WRITE32(pAd, USB_DMA_CFG, 0x0);
1632 Status = RTUSBVenderReset(pAd);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001633
1634 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, 0x0);
Bartlomiej Zolnierkiewicz59fe2d82009-04-26 16:06:28 +02001635
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001636 /* Initialize MAC register to default value */
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08001637 for (Index = 0; Index < NUM_MAC_REG_PARMS; Index++) {
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02001638#ifdef RT30xx
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08001639 if ((MACRegTable[Index].Register == TX_SW_CFG0)
1640 && (IS_RT3070(pAd) || IS_RT3071(pAd) || IS_RT3572(pAd)
1641 || IS_RT3090(pAd) || IS_RT3390(pAd))) {
Bartlomiej Zolnierkiewicz59fe2d82009-04-26 16:06:28 +02001642 MACRegTable[Index].Value = 0x00000400;
1643 }
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001644#endif /* RT30xx // */
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -08001645 RTMP_IO_WRITE32(pAd, (u16)MACRegTable[Index].Register,
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08001646 MACRegTable[Index].Value);
Bartlomiej Zolnierkiewicz59fe2d82009-04-26 16:06:28 +02001647 }
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001648
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001649 {
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08001650 for (Index = 0; Index < NUM_STA_MAC_REG_PARMS; Index++) {
1651 RTMP_IO_WRITE32(pAd,
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -08001652 (u16)STAMACRegTable[Index].Register,
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08001653 STAMACRegTable[Index].Value);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001654 }
1655 }
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001656#endif /* RTMP_MAC_USB // */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001657
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02001658#ifdef RT30xx
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001659 /* Initialize RT3070 serial MAC registers which is different from RT2870 serial */
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08001660 if (IS_RT3090(pAd) || IS_RT3572(pAd) || IS_RT3390(pAd)) {
Bartlomiej Zolnierkiewicz59fe2d82009-04-26 16:06:28 +02001661 RTMP_IO_WRITE32(pAd, TX_SW_CFG1, 0);
1662
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001663 /* RT3071 version E has fixed this issue */
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08001664 if ((pAd->MACVersion & 0xffff) < 0x0211) {
1665 if (pAd->NicConfig2.field.DACTestBit == 1) {
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001666 RTMP_IO_WRITE32(pAd, TX_SW_CFG2, 0x2C); /* To fix throughput drop drastically */
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08001667 } else {
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001668 RTMP_IO_WRITE32(pAd, TX_SW_CFG2, 0x0F); /* To fix throughput drop drastically */
Bartlomiej Zolnierkiewicz59fe2d82009-04-26 16:06:28 +02001669 }
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08001670 } else {
Bartlomiej Zolnierkiewicz59fe2d82009-04-26 16:06:28 +02001671 RTMP_IO_WRITE32(pAd, TX_SW_CFG2, 0x0);
1672 }
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08001673 } else if (IS_RT3070(pAd)) {
1674 if (((pAd->MACVersion & 0xffff) < 0x0201)) {
1675 RTMP_IO_WRITE32(pAd, TX_SW_CFG1, 0);
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001676 RTMP_IO_WRITE32(pAd, TX_SW_CFG2, 0x2C); /* To fix throughput drop drastically */
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08001677 } else {
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02001678 RTMP_IO_WRITE32(pAd, TX_SW_CFG2, 0);
1679 }
Bartlomiej Zolnierkiewicz59fe2d82009-04-26 16:06:28 +02001680 }
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001681#endif /* RT30xx // */
Bartlomiej Zolnierkiewicz59fe2d82009-04-26 16:06:28 +02001682
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001683 /* */
1684 /* Before program BBP, we need to wait BBP/RF get wake up. */
1685 /* */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001686 Index = 0;
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08001687 do {
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001688 RTMP_IO_READ32(pAd, MAC_STATUS_CFG, &MacCsr12);
1689
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001690 if ((MacCsr12 & 0x03) == 0) /* if BB.RF is stable */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001691 break;
1692
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08001693 DBGPRINT(RT_DEBUG_TRACE,
1694 ("Check MAC_STATUS_CFG = Busy = %x\n", MacCsr12));
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001695 RTMPusecDelay(1000);
1696 } while (Index++ < 100);
1697
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001698 /* The commands to firmware should be after these commands, these commands will init firmware */
1699 /* PCI and USB are not the same because PCI driver needs to wait for PCI bus ready */
1700 RTMP_IO_WRITE32(pAd, H2M_BBP_AGENT, 0); /* initialize BBP R/W access agent */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001701 RTMP_IO_WRITE32(pAd, H2M_MAILBOX_CSR, 0);
Bartlomiej Zolnierkiewicze44fd1c2009-09-22 20:44:24 +02001702#ifdef RT3090
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001703 /*2008/11/28:KH add to fix the dead rf frequency offset bug<-- */
Bartlomiej Zolnierkiewicze44fd1c2009-09-22 20:44:24 +02001704 AsicSendCommandToMcu(pAd, 0x72, 0, 0, 0);
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001705 /*2008/11/28:KH add to fix the dead rf frequency offset bug--> */
1706#endif /* RT3090 // */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001707 RTMPusecDelay(1000);
1708
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001709 /* Read BBP register, make sure BBP is up and running before write new data */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001710 Index = 0;
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08001711 do {
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001712 RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R0, &R0);
1713 DBGPRINT(RT_DEBUG_TRACE, ("BBP version = %x\n", R0));
1714 } while ((++Index < 20) && ((R0 == 0xff) || (R0 == 0x00)));
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001715 /*ASSERT(Index < 20); //this will cause BSOD on Check-build driver */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001716
1717 if ((R0 == 0xff) || (R0 == 0x00))
1718 return NDIS_STATUS_FAILURE;
1719
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001720 /* Initialize BBP register to default value */
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08001721 for (Index = 0; Index < NUM_BBP_REG_PARMS; Index++) {
1722 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBPRegTable[Index].Register,
1723 BBPRegTable[Index].Value);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001724 }
1725
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02001726#ifdef RTMP_MAC_PCI
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001727 /* TODO: shiang, check MACVersion, currently, rbus-based chip use this. */
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08001728 if (pAd->MACVersion == 0x28720200) {
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -08001729 /*u8 value; */
1730 unsigned long value2;
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02001731
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001732 /*disable MLD by Bruce 20080704 */
1733 /*BBP_IO_READ8_BY_REG_ID(pAd, BBP_R105, &value); */
1734 /*BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R105, value | 4); */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02001735
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001736 /*Maximum PSDU length from 16K to 32K bytes */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02001737 RTMP_IO_READ32(pAd, MAX_LEN_CFG, &value2);
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08001738 value2 &= ~(0x3 << 12);
1739 value2 |= (0x2 << 12);
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02001740 RTMP_IO_WRITE32(pAd, MAX_LEN_CFG, value2);
1741 }
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001742#endif /* RTMP_MAC_PCI // */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02001743
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001744 /* for rt2860E and after, init BBP_R84 with 0x19. This is for extension channel overlapping IOT. */
1745 /* RT3090 should not program BBP R84 to 0x19, otherwise TX will block. */
1746 /*3070/71/72,3090,3090A( are included in RT30xx),3572,3390 */
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08001747 if (((pAd->MACVersion & 0xffff) != 0x0101)
1748 && !(IS_RT30xx(pAd) || IS_RT3572(pAd) || IS_RT3390(pAd)))
Bartlomiej Zolnierkiewicz59fe2d82009-04-26 16:06:28 +02001749 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R84, 0x19);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001750
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02001751#ifdef RT30xx
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001752/* add by johnli, RF power sequence setup */
1753 if (IS_RT30xx(pAd) || IS_RT3572(pAd) || IS_RT3390(pAd)) { /*update for RT3070/71/72/90/91/92,3572,3390. */
Bartlomiej Zolnierkiewicz59fe2d82009-04-26 16:06:28 +02001754 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R79, 0x13);
1755 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R80, 0x05);
1756 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R81, 0x33);
1757 }
1758
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001759 if (IS_RT3090(pAd) || IS_RT3390(pAd)) /* RT309x, RT3071/72 */
Bartlomiej Zolnierkiewicz59fe2d82009-04-26 16:06:28 +02001760 {
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001761 /* enable DC filter */
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08001762 if ((pAd->MACVersion & 0xffff) >= 0x0211) {
Bartlomiej Zolnierkiewicz59fe2d82009-04-26 16:06:28 +02001763 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R103, 0xc0);
1764 }
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001765 /* improve power consumption */
Bartlomiej Zolnierkiewicz59fe2d82009-04-26 16:06:28 +02001766 RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R138, &bbpreg);
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08001767 if (pAd->Antenna.field.TxPath == 1) {
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001768 /* turn off tx DAC_1 */
Bartlomiej Zolnierkiewicz59fe2d82009-04-26 16:06:28 +02001769 bbpreg = (bbpreg | 0x20);
1770 }
1771
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08001772 if (pAd->Antenna.field.RxPath == 1) {
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001773 /* turn off tx ADC_1 */
Bartlomiej Zolnierkiewicz59fe2d82009-04-26 16:06:28 +02001774 bbpreg &= (~0x2);
1775 }
1776 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R138, bbpreg);
1777
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001778 /* improve power consumption in RT3071 Ver.E */
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08001779 if ((pAd->MACVersion & 0xffff) >= 0x0211) {
Bartlomiej Zolnierkiewicz59fe2d82009-04-26 16:06:28 +02001780 RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R31, &bbpreg);
1781 bbpreg &= (~0x3);
1782 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R31, bbpreg);
1783 }
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08001784 } else if (IS_RT3070(pAd)) {
1785 if ((pAd->MACVersion & 0xffff) >= 0x0201) {
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001786 /* enable DC filter */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02001787 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R103, 0xc0);
1788
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001789 /* improve power consumption in RT3070 Ver.F */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02001790 RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R31, &bbpreg);
1791 bbpreg &= (~0x3);
1792 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R31, bbpreg);
1793 }
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001794 /* TX_LO1_en, RF R17 register Bit 3 to 0 */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02001795 RT30xxReadRFRegister(pAd, RF_R17, &RFValue);
1796 RFValue &= (~0x08);
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001797 /* to fix rx long range issue */
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08001798 if (pAd->NicConfig2.field.ExternalLNAForG == 0) {
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02001799 RFValue |= 0x20;
1800 }
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001801 /* set RF_R17_bit[2:0] equal to EEPROM setting at 0x48h */
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08001802 if (pAd->TxMixerGain24G >= 1) {
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001803 RFValue &= (~0x7); /* clean bit [2:0] */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02001804 RFValue |= pAd->TxMixerGain24G;
1805 }
1806 RT30xxWriteRFRegister(pAd, RF_R17, RFValue);
1807 }
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001808/* end johnli */
1809#endif /* RT30xx // */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02001810
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08001811 if (pAd->MACVersion == 0x28600100) {
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001812 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R69, 0x16);
1813 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R73, 0x12);
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08001814 }
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001815
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001816 if (pAd->MACVersion >= RALINK_2880E_VERSION && pAd->MACVersion < RALINK_3070_VERSION) /* 3*3 */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001817 {
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001818 /* enlarge MAX_LEN_CFG */
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -08001819 u32 csr;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001820 RTMP_IO_READ32(pAd, MAX_LEN_CFG, &csr);
1821 csr &= 0xFFF;
1822 csr |= 0x2000;
1823 RTMP_IO_WRITE32(pAd, MAX_LEN_CFG, csr);
1824 }
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02001825#ifdef RTMP_MAC_USB
Bartlomiej Zolnierkiewicz59fe2d82009-04-26 16:06:28 +02001826 {
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -08001827 u8 MAC_Value[] =
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08001828 { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0, 0 };
1829
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001830 /*Initialize WCID table */
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08001831 Value = 0xff;
1832 for (Index = 0; Index < 254; Index++) {
1833 RTUSBMultiWrite(pAd,
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -08001834 (u16)(MAC_WCID_BASE + Index * 8),
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08001835 MAC_Value, 8);
1836 }
Bartlomiej Zolnierkiewicz59fe2d82009-04-26 16:06:28 +02001837 }
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001838#endif /* RTMP_MAC_USB // */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001839
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001840 /* Add radio off control */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001841 {
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08001842 if (pAd->StaCfg.bRadio == FALSE) {
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001843/* RTMP_IO_WRITE32(pAd, PWR_PIN_CFG, 0x00001818); */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001844 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_RADIO_OFF);
1845 DBGPRINT(RT_DEBUG_TRACE, ("Set Radio Off\n"));
1846 }
1847 }
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001848
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001849 /* Clear raw counters */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001850 RTMP_IO_READ32(pAd, RX_STA_CNT0, &Counter);
1851 RTMP_IO_READ32(pAd, RX_STA_CNT1, &Counter);
1852 RTMP_IO_READ32(pAd, RX_STA_CNT2, &Counter);
1853 RTMP_IO_READ32(pAd, TX_STA_CNT0, &Counter);
1854 RTMP_IO_READ32(pAd, TX_STA_CNT1, &Counter);
1855 RTMP_IO_READ32(pAd, TX_STA_CNT2, &Counter);
1856
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001857 /* ASIC will keep garbage value after boot */
1858 /* Clear all shared key table when initial */
1859 /* This routine can be ignored in radio-ON/OFF operation. */
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08001860 if (bHardReset) {
1861 for (KeyIdx = 0; KeyIdx < 4; KeyIdx++) {
1862 RTMP_IO_WRITE32(pAd, SHARED_KEY_MODE_BASE + 4 * KeyIdx,
1863 0);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001864 }
1865
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001866 /* Clear all pairwise key table when initial */
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08001867 for (KeyIdx = 0; KeyIdx < 256; KeyIdx++) {
1868 RTMP_IO_WRITE32(pAd,
1869 MAC_WCID_ATTRIBUTE_BASE +
1870 (KeyIdx * HW_WCID_ATTRI_SIZE), 1);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001871 }
1872 }
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001873 /* assert HOST ready bit */
1874/* RTMP_IO_WRITE32(pAd, MAC_CSR1, 0x0); // 2004-09-14 asked by Mark */
1875/* RTMP_IO_WRITE32(pAd, MAC_CSR1, 0x4); */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001876
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001877 /* It isn't necessary to clear this space when not hard reset. */
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08001878 if (bHardReset == TRUE) {
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001879 /* clear all on-chip BEACON frame space */
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08001880 for (apidx = 0; apidx < HW_BEACON_MAX_COUNT; apidx++) {
1881 for (i = 0; i < HW_BEACON_OFFSET >> 2; i += 4)
1882 RTMP_IO_WRITE32(pAd,
1883 pAd->BeaconOffset[apidx] + i,
1884 0x00);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001885 }
1886 }
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02001887#ifdef RTMP_MAC_USB
Bartlomiej Zolnierkiewicz59fe2d82009-04-26 16:06:28 +02001888 AsicDisableSync(pAd);
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001889 /* Clear raw counters */
Bartlomiej Zolnierkiewicz59fe2d82009-04-26 16:06:28 +02001890 RTMP_IO_READ32(pAd, RX_STA_CNT0, &Counter);
1891 RTMP_IO_READ32(pAd, RX_STA_CNT1, &Counter);
1892 RTMP_IO_READ32(pAd, RX_STA_CNT2, &Counter);
1893 RTMP_IO_READ32(pAd, TX_STA_CNT0, &Counter);
1894 RTMP_IO_READ32(pAd, TX_STA_CNT1, &Counter);
1895 RTMP_IO_READ32(pAd, TX_STA_CNT2, &Counter);
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001896 /* Default PCI clock cycle per ms is different as default setting, which is based on PCI. */
Bartlomiej Zolnierkiewicz59fe2d82009-04-26 16:06:28 +02001897 RTMP_IO_READ32(pAd, USB_CYC_CFG, &Counter);
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08001898 Counter &= 0xffffff00;
1899 Counter |= 0x000001e;
Bartlomiej Zolnierkiewicz59fe2d82009-04-26 16:06:28 +02001900 RTMP_IO_WRITE32(pAd, USB_CYC_CFG, Counter);
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001901#endif /* RTMP_MAC_USB // */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001902
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001903 {
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001904 /* for rt2860E and after, init TXOP_CTRL_CFG with 0x583f. This is for extension channel overlapping IOT. */
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08001905 if ((pAd->MACVersion & 0xffff) != 0x0101)
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001906 RTMP_IO_WRITE32(pAd, TXOP_CTRL_CFG, 0x583f);
1907 }
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001908
1909 DBGPRINT(RT_DEBUG_TRACE, ("<-- NICInitializeAsic\n"));
1910 return NDIS_STATUS_SUCCESS;
1911}
1912
1913/*
1914 ========================================================================
1915
1916 Routine Description:
1917 Reset NIC Asics
1918
1919 Arguments:
1920 Adapter Pointer to our adapter
1921
1922 Return Value:
1923 None
1924
1925 IRQL = PASSIVE_LEVEL
1926
1927 Note:
1928 Reset NIC to initial state AS IS system boot up time.
1929
1930 ========================================================================
1931*/
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -08001932void NICIssueReset(struct rt_rtmp_adapter *pAd)
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001933{
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -08001934 u32 Value = 0;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001935 DBGPRINT(RT_DEBUG_TRACE, ("--> NICIssueReset\n"));
1936
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001937 /* Abort Tx, prevent ASIC from writing to Host memory */
1938 /*RTMP_IO_WRITE32(pAd, TX_CNTL_CSR, 0x001f0000); */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02001939
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001940 /* Disable Rx, register value supposed will remain after reset */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001941 RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &Value);
1942 Value &= (0xfffffff3);
1943 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, Value);
1944
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08001945 /* Issue reset and clear from reset state */
1946 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, 0x03); /* 2004-09-17 change from 0x01 */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001947 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, 0x00);
1948
1949 DBGPRINT(RT_DEBUG_TRACE, ("<-- NICIssueReset\n"));
1950}
1951
1952/*
1953 ========================================================================
1954
1955 Routine Description:
1956 Check ASIC registers and find any reason the system might hang
1957
1958 Arguments:
1959 Adapter Pointer to our adapter
1960
1961 Return Value:
1962 None
1963
1964 IRQL = DISPATCH_LEVEL
1965
1966 ========================================================================
1967*/
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -08001968BOOLEAN NICCheckForHang(struct rt_rtmp_adapter *pAd)
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001969{
1970 return (FALSE);
1971}
1972
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -08001973void NICUpdateFifoStaCounters(struct rt_rtmp_adapter *pAd)
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001974{
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08001975 TX_STA_FIFO_STRUC StaFifo;
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -08001976 struct rt_mac_table_entry *pEntry;
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -08001977 u8 i = 0;
1978 u8 pid = 0, wcid = 0;
1979 char reTry;
1980 u8 succMCS;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001981
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08001982 do {
1983 RTMP_IO_READ32(pAd, TX_STA_FIFO, &StaFifo.word);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001984
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08001985 if (StaFifo.field.bValid == 0)
1986 break;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001987
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -08001988 wcid = (u8)StaFifo.field.wcid;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001989
1990 /* ignore NoACK and MGMT frame use 0xFF as WCID */
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08001991 if ((StaFifo.field.TxAckRequired == 0)
1992 || (wcid >= MAX_LEN_OF_MAC_TABLE)) {
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001993 i++;
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08001994 continue;
1995 }
1996
1997 /* PID store Tx MCS Rate */
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -08001998 pid = (u8)StaFifo.field.PidType;
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08001999
2000 pEntry = &pAd->MacTab.Content[wcid];
2001
2002 pEntry->DebugFIFOCount++;
2003
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08002004 if (StaFifo.field.TxBF) /* 3*3 */
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08002005 pEntry->TxBFCount++;
2006
2007 if (!StaFifo.field.TxSuccess) {
2008 pEntry->FIFOCount++;
2009 pEntry->OneSecTxFailCount++;
2010
2011 if (pEntry->FIFOCount >= 1) {
2012 DBGPRINT(RT_DEBUG_TRACE, ("#"));
2013 pEntry->NoBADataCountDown = 64;
2014
2015 if (pEntry->PsMode == PWR_ACTIVE) {
2016 int tid;
2017 for (tid = 0; tid < NUM_OF_TID; tid++) {
2018 BAOriSessionTearDown(pAd,
2019 pEntry->
2020 Aid, tid,
2021 FALSE,
2022 FALSE);
2023 }
2024
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08002025 /* Update the continuous transmission counter except PS mode */
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08002026 pEntry->ContinueTxFailCnt++;
2027 } else {
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08002028 /* Clear the FIFOCount when sta in Power Save mode. Basically we assume */
2029 /* this tx error happened due to sta just go to sleep. */
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08002030 pEntry->FIFOCount = 0;
2031 pEntry->ContinueTxFailCnt = 0;
2032 }
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08002033 /*pEntry->FIFOCount = 0; */
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08002034 }
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08002035 /*pEntry->bSendBAR = TRUE; */
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08002036 } else {
2037 if ((pEntry->PsMode != PWR_SAVE)
2038 && (pEntry->NoBADataCountDown > 0)) {
2039 pEntry->NoBADataCountDown--;
2040 if (pEntry->NoBADataCountDown == 0) {
2041 DBGPRINT(RT_DEBUG_TRACE, ("@\n"));
2042 }
2043 }
2044
2045 pEntry->FIFOCount = 0;
2046 pEntry->OneSecTxNoRetryOkCount++;
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08002047 /* update NoDataIdleCount when sucessful send packet to STA. */
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08002048 pEntry->NoDataIdleCount = 0;
2049 pEntry->ContinueTxFailCnt = 0;
2050 }
2051
2052 succMCS = StaFifo.field.SuccessRate & 0x7F;
2053
2054 reTry = pid - succMCS;
2055
2056 if (StaFifo.field.TxSuccess) {
2057 pEntry->TXMCSExpected[pid]++;
2058 if (pid == succMCS) {
2059 pEntry->TXMCSSuccessful[pid]++;
2060 } else {
2061 pEntry->TXMCSAutoFallBack[pid][succMCS]++;
2062 }
2063 } else {
2064 pEntry->TXMCSFailed[pid]++;
2065 }
2066
2067 if (reTry > 0) {
2068 if ((pid >= 12) && succMCS <= 7) {
2069 reTry -= 4;
2070 }
2071 pEntry->OneSecTxRetryOkCount += reTry;
2072 }
2073
2074 i++;
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08002075 /* ASIC store 16 stack */
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08002076 } while (i < (2 * TX_RING_SIZE));
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002077
2078}
2079
2080/*
2081 ========================================================================
2082
2083 Routine Description:
2084 Read statistical counters from hardware registers and record them
2085 in software variables for later on query
2086
2087 Arguments:
2088 pAd Pointer to our adapter
2089
2090 Return Value:
2091 None
2092
2093 IRQL = DISPATCH_LEVEL
2094
2095 ========================================================================
2096*/
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -08002097void NICUpdateRawCounters(struct rt_rtmp_adapter *pAd)
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002098{
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -08002099 u32 OldValue; /*, Value2; */
2100 /*unsigned long PageSum, OneSecTransmitCount; */
2101 /*unsigned long TxErrorRatio, Retry, Fail; */
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08002102 RX_STA_CNT0_STRUC RxStaCnt0;
2103 RX_STA_CNT1_STRUC RxStaCnt1;
2104 RX_STA_CNT2_STRUC RxStaCnt2;
2105 TX_STA_CNT0_STRUC TxStaCnt0;
2106 TX_STA_CNT1_STRUC StaTx1;
2107 TX_STA_CNT2_STRUC StaTx2;
2108 TX_AGG_CNT_STRUC TxAggCnt;
2109 TX_AGG_CNT0_STRUC TxAggCnt0;
2110 TX_AGG_CNT1_STRUC TxAggCnt1;
2111 TX_AGG_CNT2_STRUC TxAggCnt2;
2112 TX_AGG_CNT3_STRUC TxAggCnt3;
2113 TX_AGG_CNT4_STRUC TxAggCnt4;
2114 TX_AGG_CNT5_STRUC TxAggCnt5;
2115 TX_AGG_CNT6_STRUC TxAggCnt6;
2116 TX_AGG_CNT7_STRUC TxAggCnt7;
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -08002117 struct rt_counter_ralink *pRalinkCounters;
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02002118
2119 pRalinkCounters = &pAd->RalinkCounters;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002120
2121 RTMP_IO_READ32(pAd, RX_STA_CNT0, &RxStaCnt0.word);
2122 RTMP_IO_READ32(pAd, RX_STA_CNT2, &RxStaCnt2.word);
2123
2124 {
2125 RTMP_IO_READ32(pAd, RX_STA_CNT1, &RxStaCnt1.word);
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08002126 /* Update RX PLCP error counter */
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08002127 pAd->PrivateInfo.PhyRxErrCnt += RxStaCnt1.field.PlcpErr;
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08002128 /* Update False CCA counter */
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08002129 pAd->RalinkCounters.OneSecFalseCCACnt +=
2130 RxStaCnt1.field.FalseCca;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002131 }
2132
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08002133 /* Update FCS counters */
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08002134 OldValue = pAd->WlanCounters.FCSErrorCount.u.LowPart;
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08002135 pAd->WlanCounters.FCSErrorCount.u.LowPart += (RxStaCnt0.field.CrcErr); /* >> 7); */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002136 if (pAd->WlanCounters.FCSErrorCount.u.LowPart < OldValue)
2137 pAd->WlanCounters.FCSErrorCount.u.HighPart++;
2138
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08002139 /* Add FCS error count to private counters */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02002140 pRalinkCounters->OneSecRxFcsErrCnt += RxStaCnt0.field.CrcErr;
2141 OldValue = pRalinkCounters->RealFcsErrCount.u.LowPart;
2142 pRalinkCounters->RealFcsErrCount.u.LowPart += RxStaCnt0.field.CrcErr;
2143 if (pRalinkCounters->RealFcsErrCount.u.LowPart < OldValue)
2144 pRalinkCounters->RealFcsErrCount.u.HighPart++;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002145
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08002146 /* Update Duplicate Rcv check */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02002147 pRalinkCounters->DuplicateRcv += RxStaCnt2.field.RxDupliCount;
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08002148 pAd->WlanCounters.FrameDuplicateCount.u.LowPart +=
2149 RxStaCnt2.field.RxDupliCount;
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08002150 /* Update RX Overflow counter */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002151 pAd->Counters8023.RxNoBuffer += (RxStaCnt2.field.RxFifoOverflowCount);
2152
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08002153 /*pAd->RalinkCounters.RxCount = 0; */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02002154#ifdef RTMP_MAC_USB
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08002155 if (pRalinkCounters->RxCount != pAd->watchDogRxCnt) {
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02002156 pAd->watchDogRxCnt = pRalinkCounters->RxCount;
Bartlomiej Zolnierkiewicz59fe2d82009-04-26 16:06:28 +02002157 pAd->watchDogRxOverFlowCnt = 0;
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08002158 } else {
Bartlomiej Zolnierkiewicz59fe2d82009-04-26 16:06:28 +02002159 if (RxStaCnt2.field.RxFifoOverflowCount)
2160 pAd->watchDogRxOverFlowCnt++;
2161 else
2162 pAd->watchDogRxOverFlowCnt = 0;
2163 }
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08002164#endif /* RTMP_MAC_USB // */
Bartlomiej Zolnierkiewicz59fe2d82009-04-26 16:06:28 +02002165
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08002166 /*if (!OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_TX_RATE_SWITCH_ENABLED) || */
2167 /* (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_TX_RATE_SWITCH_ENABLED) && (pAd->MacTab.Size != 1))) */
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08002168 if (!pAd->bUpdateBcnCntDone) {
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08002169 /* Update BEACON sent count */
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08002170 RTMP_IO_READ32(pAd, TX_STA_CNT0, &TxStaCnt0.word);
2171 RTMP_IO_READ32(pAd, TX_STA_CNT1, &StaTx1.word);
2172 RTMP_IO_READ32(pAd, TX_STA_CNT2, &StaTx2.word);
2173 pRalinkCounters->OneSecBeaconSentCnt +=
2174 TxStaCnt0.field.TxBeaconCount;
2175 pRalinkCounters->OneSecTxRetryOkCount +=
2176 StaTx1.field.TxRetransmit;
2177 pRalinkCounters->OneSecTxNoRetryOkCount +=
2178 StaTx1.field.TxSuccess;
2179 pRalinkCounters->OneSecTxFailCount +=
2180 TxStaCnt0.field.TxFailCount;
2181 pAd->WlanCounters.TransmittedFragmentCount.u.LowPart +=
2182 StaTx1.field.TxSuccess;
2183 pAd->WlanCounters.RetryCount.u.LowPart +=
2184 StaTx1.field.TxRetransmit;
2185 pAd->WlanCounters.FailedCount.u.LowPart +=
2186 TxStaCnt0.field.TxFailCount;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002187 }
2188
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08002189 /*if (pAd->bStaFifoTest == TRUE) */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002190 {
2191 RTMP_IO_READ32(pAd, TX_AGG_CNT, &TxAggCnt.word);
2192 RTMP_IO_READ32(pAd, TX_AGG_CNT0, &TxAggCnt0.word);
2193 RTMP_IO_READ32(pAd, TX_AGG_CNT1, &TxAggCnt1.word);
2194 RTMP_IO_READ32(pAd, TX_AGG_CNT2, &TxAggCnt2.word);
2195 RTMP_IO_READ32(pAd, TX_AGG_CNT3, &TxAggCnt3.word);
2196 RTMP_IO_READ32(pAd, TX_AGG_CNT4, &TxAggCnt4.word);
2197 RTMP_IO_READ32(pAd, TX_AGG_CNT5, &TxAggCnt5.word);
2198 RTMP_IO_READ32(pAd, TX_AGG_CNT6, &TxAggCnt6.word);
2199 RTMP_IO_READ32(pAd, TX_AGG_CNT7, &TxAggCnt7.word);
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02002200 pRalinkCounters->TxAggCount += TxAggCnt.field.AggTxCount;
2201 pRalinkCounters->TxNonAggCount += TxAggCnt.field.NonAggTxCount;
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08002202 pRalinkCounters->TxAgg1MPDUCount +=
2203 TxAggCnt0.field.AggSize1Count;
2204 pRalinkCounters->TxAgg2MPDUCount +=
2205 TxAggCnt0.field.AggSize2Count;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002206
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08002207 pRalinkCounters->TxAgg3MPDUCount +=
2208 TxAggCnt1.field.AggSize3Count;
2209 pRalinkCounters->TxAgg4MPDUCount +=
2210 TxAggCnt1.field.AggSize4Count;
2211 pRalinkCounters->TxAgg5MPDUCount +=
2212 TxAggCnt2.field.AggSize5Count;
2213 pRalinkCounters->TxAgg6MPDUCount +=
2214 TxAggCnt2.field.AggSize6Count;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002215
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08002216 pRalinkCounters->TxAgg7MPDUCount +=
2217 TxAggCnt3.field.AggSize7Count;
2218 pRalinkCounters->TxAgg8MPDUCount +=
2219 TxAggCnt3.field.AggSize8Count;
2220 pRalinkCounters->TxAgg9MPDUCount +=
2221 TxAggCnt4.field.AggSize9Count;
2222 pRalinkCounters->TxAgg10MPDUCount +=
2223 TxAggCnt4.field.AggSize10Count;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002224
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08002225 pRalinkCounters->TxAgg11MPDUCount +=
2226 TxAggCnt5.field.AggSize11Count;
2227 pRalinkCounters->TxAgg12MPDUCount +=
2228 TxAggCnt5.field.AggSize12Count;
2229 pRalinkCounters->TxAgg13MPDUCount +=
2230 TxAggCnt6.field.AggSize13Count;
2231 pRalinkCounters->TxAgg14MPDUCount +=
2232 TxAggCnt6.field.AggSize14Count;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002233
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08002234 pRalinkCounters->TxAgg15MPDUCount +=
2235 TxAggCnt7.field.AggSize15Count;
2236 pRalinkCounters->TxAgg16MPDUCount +=
2237 TxAggCnt7.field.AggSize16Count;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002238
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08002239 /* Calculate the transmitted A-MPDU count */
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08002240 pRalinkCounters->TransmittedAMPDUCount.u.LowPart +=
2241 TxAggCnt0.field.AggSize1Count;
2242 pRalinkCounters->TransmittedAMPDUCount.u.LowPart +=
2243 (TxAggCnt0.field.AggSize2Count / 2);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002244
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08002245 pRalinkCounters->TransmittedAMPDUCount.u.LowPart +=
2246 (TxAggCnt1.field.AggSize3Count / 3);
2247 pRalinkCounters->TransmittedAMPDUCount.u.LowPart +=
2248 (TxAggCnt1.field.AggSize4Count / 4);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002249
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08002250 pRalinkCounters->TransmittedAMPDUCount.u.LowPart +=
2251 (TxAggCnt2.field.AggSize5Count / 5);
2252 pRalinkCounters->TransmittedAMPDUCount.u.LowPart +=
2253 (TxAggCnt2.field.AggSize6Count / 6);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002254
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08002255 pRalinkCounters->TransmittedAMPDUCount.u.LowPart +=
2256 (TxAggCnt3.field.AggSize7Count / 7);
2257 pRalinkCounters->TransmittedAMPDUCount.u.LowPart +=
2258 (TxAggCnt3.field.AggSize8Count / 8);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002259
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08002260 pRalinkCounters->TransmittedAMPDUCount.u.LowPart +=
2261 (TxAggCnt4.field.AggSize9Count / 9);
2262 pRalinkCounters->TransmittedAMPDUCount.u.LowPart +=
2263 (TxAggCnt4.field.AggSize10Count / 10);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002264
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08002265 pRalinkCounters->TransmittedAMPDUCount.u.LowPart +=
2266 (TxAggCnt5.field.AggSize11Count / 11);
2267 pRalinkCounters->TransmittedAMPDUCount.u.LowPart +=
2268 (TxAggCnt5.field.AggSize12Count / 12);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002269
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08002270 pRalinkCounters->TransmittedAMPDUCount.u.LowPart +=
2271 (TxAggCnt6.field.AggSize13Count / 13);
2272 pRalinkCounters->TransmittedAMPDUCount.u.LowPart +=
2273 (TxAggCnt6.field.AggSize14Count / 14);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002274
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08002275 pRalinkCounters->TransmittedAMPDUCount.u.LowPart +=
2276 (TxAggCnt7.field.AggSize15Count / 15);
2277 pRalinkCounters->TransmittedAMPDUCount.u.LowPart +=
2278 (TxAggCnt7.field.AggSize16Count / 16);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002279 }
2280
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002281}
2282
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002283/*
2284 ========================================================================
2285
2286 Routine Description:
2287 Reset NIC from error
2288
2289 Arguments:
2290 Adapter Pointer to our adapter
2291
2292 Return Value:
2293 None
2294
2295 IRQL = PASSIVE_LEVEL
2296
2297 Note:
2298 Reset NIC from error state
2299
2300 ========================================================================
2301*/
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -08002302void NICResetFromError(struct rt_rtmp_adapter *pAd)
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002303{
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08002304 /* Reset BBP (according to alex, reset ASIC will force reset BBP */
2305 /* Therefore, skip the reset BBP */
2306 /* RTMP_IO_WRITE32(pAd, MAC_CSR1, 0x2); */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002307
2308 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, 0x1);
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08002309 /* Remove ASIC from reset state */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002310 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, 0x0);
2311
2312 NICInitializeAdapter(pAd, FALSE);
2313 NICInitAsicFromEEPROM(pAd);
2314
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08002315 /* Switch to current channel, since during reset process, the connection should remains on. */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002316 AsicSwitchChannel(pAd, pAd->CommonCfg.CentralChannel, FALSE);
2317 AsicLockChannel(pAd, pAd->CommonCfg.CentralChannel);
2318}
2319
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -08002320int NICLoadFirmware(struct rt_rtmp_adapter *pAd)
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02002321{
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -08002322 int status = NDIS_STATUS_SUCCESS;
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02002323 if (pAd->chipOps.loadFirmware)
2324 status = pAd->chipOps.loadFirmware(pAd);
2325
2326 return status;
2327}
2328
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002329/*
2330 ========================================================================
2331
2332 Routine Description:
2333 erase 8051 firmware image in MAC ASIC
2334
2335 Arguments:
2336 Adapter Pointer to our adapter
2337
2338 IRQL = PASSIVE_LEVEL
2339
2340 ========================================================================
2341*/
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -08002342void NICEraseFirmware(struct rt_rtmp_adapter *pAd)
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002343{
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02002344 if (pAd->chipOps.eraseFirmware)
2345 pAd->chipOps.eraseFirmware(pAd);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002346
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08002347} /* End of NICEraseFirmware */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002348
2349/*
2350 ========================================================================
2351
2352 Routine Description:
2353 Load Tx rate switching parameters
2354
2355 Arguments:
2356 Adapter Pointer to our adapter
2357
2358 Return Value:
2359 NDIS_STATUS_SUCCESS firmware image load ok
2360 NDIS_STATUS_FAILURE image not found
2361
2362 IRQL = PASSIVE_LEVEL
2363
2364 Rate Table Format:
2365 1. (B0: Valid Item number) (B1:Initial item from zero)
2366 2. Item Number(Dec) Mode(Hex) Current MCS(Dec) TrainUp(Dec) TrainDown(Dec)
2367
2368 ========================================================================
2369*/
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -08002370int NICLoadRateSwitchingParams(struct rt_rtmp_adapter *pAd)
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002371{
2372 return NDIS_STATUS_SUCCESS;
2373}
2374
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002375/*
2376 ========================================================================
2377
2378 Routine Description:
2379 Compare two memory block
2380
2381 Arguments:
2382 pSrc1 Pointer to first memory address
2383 pSrc2 Pointer to second memory address
2384
2385 Return Value:
2386 0: memory is equal
2387 1: pSrc1 memory is larger
2388 2: pSrc2 memory is larger
2389
2390 IRQL = DISPATCH_LEVEL
2391
2392 Note:
2393
2394 ========================================================================
2395*/
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -08002396unsigned long RTMPCompareMemory(void *pSrc1, void *pSrc2, unsigned long Length)
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002397{
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -08002398 u8 *pMem1;
2399 u8 *pMem2;
2400 unsigned long Index = 0;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002401
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -08002402 pMem1 = (u8 *)pSrc1;
2403 pMem2 = (u8 *)pSrc2;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002404
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08002405 for (Index = 0; Index < Length; Index++) {
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002406 if (pMem1[Index] > pMem2[Index])
2407 return (1);
2408 else if (pMem1[Index] < pMem2[Index])
2409 return (2);
2410 }
2411
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08002412 /* Equal */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002413 return (0);
2414}
2415
2416/*
2417 ========================================================================
2418
2419 Routine Description:
2420 Zero out memory block
2421
2422 Arguments:
2423 pSrc1 Pointer to memory address
2424 Length Size
2425
2426 Return Value:
2427 None
2428
2429 IRQL = PASSIVE_LEVEL
2430 IRQL = DISPATCH_LEVEL
2431
2432 Note:
2433
2434 ========================================================================
2435*/
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -08002436void RTMPZeroMemory(void *pSrc, unsigned long Length)
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002437{
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -08002438 u8 *pMem;
2439 unsigned long Index = 0;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002440
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -08002441 pMem = (u8 *)pSrc;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002442
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08002443 for (Index = 0; Index < Length; Index++) {
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002444 pMem[Index] = 0x00;
2445 }
2446}
2447
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002448/*
2449 ========================================================================
2450
2451 Routine Description:
2452 Copy data from memory block 1 to memory block 2
2453
2454 Arguments:
2455 pDest Pointer to destination memory address
2456 pSrc Pointer to source memory address
2457 Length Copy size
2458
2459 Return Value:
2460 None
2461
2462 IRQL = PASSIVE_LEVEL
2463 IRQL = DISPATCH_LEVEL
2464
2465 Note:
2466
2467 ========================================================================
2468*/
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -08002469void RTMPMoveMemory(void *pDest, void *pSrc, unsigned long Length)
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002470{
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -08002471 u8 *pMem1;
2472 u8 *pMem2;
2473 u32 Index;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002474
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08002475 ASSERT((Length == 0) || (pDest && pSrc));
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002476
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -08002477 pMem1 = (u8 *)pDest;
2478 pMem2 = (u8 *)pSrc;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002479
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08002480 for (Index = 0; Index < Length; Index++) {
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002481 pMem1[Index] = pMem2[Index];
2482 }
2483}
2484
2485/*
2486 ========================================================================
2487
2488 Routine Description:
2489 Initialize port configuration structure
2490
2491 Arguments:
2492 Adapter Pointer to our adapter
2493
2494 Return Value:
2495 None
2496
2497 IRQL = PASSIVE_LEVEL
2498
2499 Note:
2500
2501 ========================================================================
2502*/
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -08002503void UserCfgInit(struct rt_rtmp_adapter *pAd)
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002504{
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -08002505 u32 key_index, bss_index;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002506
2507 DBGPRINT(RT_DEBUG_TRACE, ("--> UserCfgInit\n"));
2508
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08002509 /* */
Uwe Kleine-König9b0131c2010-09-01 15:40:25 +02002510 /* part I. initialize common configuration */
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08002511 /* */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02002512#ifdef RTMP_MAC_USB
Bartlomiej Zolnierkiewicz59fe2d82009-04-26 16:06:28 +02002513 pAd->BulkOutReq = 0;
2514
2515 pAd->BulkOutComplete = 0;
2516 pAd->BulkOutCompleteOther = 0;
2517 pAd->BulkOutCompleteCancel = 0;
2518 pAd->BulkInReq = 0;
2519 pAd->BulkInComplete = 0;
2520 pAd->BulkInCompleteFail = 0;
2521
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08002522 /*pAd->QuickTimerP = 100; */
2523 /*pAd->TurnAggrBulkInCount = 0; */
Bartlomiej Zolnierkiewicz59fe2d82009-04-26 16:06:28 +02002524 pAd->bUsbTxBulkAggre = 0;
2525
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08002526 /* init as unsed value to ensure driver will set to MCU once. */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02002527 pAd->LedIndicatorStrength = 0xFF;
Bartlomiej Zolnierkiewicz59fe2d82009-04-26 16:06:28 +02002528
2529 pAd->CommonCfg.MaxPktOneTxBulk = 2;
2530 pAd->CommonCfg.TxBulkFactor = 1;
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08002531 pAd->CommonCfg.RxBulkFactor = 1;
Bartlomiej Zolnierkiewicz59fe2d82009-04-26 16:06:28 +02002532
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08002533 pAd->CommonCfg.TxPower = 100; /*mW */
Bartlomiej Zolnierkiewicz59fe2d82009-04-26 16:06:28 +02002534
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08002535 NdisZeroMemory(&pAd->CommonCfg.IOTestParm,
2536 sizeof(pAd->CommonCfg.IOTestParm));
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08002537#endif /* RTMP_MAC_USB // */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002538
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08002539 for (key_index = 0; key_index < SHARE_KEY_NUM; key_index++) {
2540 for (bss_index = 0; bss_index < MAX_MBSSID_NUM; bss_index++) {
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002541 pAd->SharedKey[bss_index][key_index].KeyLen = 0;
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08002542 pAd->SharedKey[bss_index][key_index].CipherAlg =
2543 CIPHER_NONE;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002544 }
2545 }
2546
Bartlomiej Zolnierkiewicz59fe2d82009-04-26 16:06:28 +02002547 pAd->EepromAccess = FALSE;
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02002548
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002549 pAd->Antenna.word = 0;
2550 pAd->CommonCfg.BBPCurrentBW = BW_20;
2551
2552 pAd->LedCntl.word = 0;
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02002553#ifdef RTMP_MAC_PCI
2554 pAd->LedIndicatorStrength = 0;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002555 pAd->RLnkCtrlOffset = 0;
2556 pAd->HostLnkCtrlOffset = 0;
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08002557 pAd->StaCfg.PSControl.field.EnableNewPS = TRUE;
Bartlomiej Zolnierkiewicze44fd1c2009-09-22 20:44:24 +02002558 pAd->CheckDmaBusyCount = 0;
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08002559#endif /* RTMP_MAC_PCI // */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002560
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08002561 pAd->bAutoTxAgcA = FALSE; /* Default is OFF */
2562 pAd->bAutoTxAgcG = FALSE; /* Default is OFF */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002563 pAd->RfIcType = RFIC_2820;
2564
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08002565 /* Init timer for reset complete event */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002566 pAd->CommonCfg.CentralChannel = 1;
2567 pAd->bForcePrintTX = FALSE;
2568 pAd->bForcePrintRX = FALSE;
2569 pAd->bStaFifoTest = FALSE;
2570 pAd->bProtectionTest = FALSE;
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08002571 pAd->CommonCfg.Dsifs = 10; /* in units of usec */
2572 pAd->CommonCfg.TxPower = 100; /*mW */
2573 pAd->CommonCfg.TxPowerPercentage = 0xffffffff; /* AUTO */
2574 pAd->CommonCfg.TxPowerDefault = 0xffffffff; /* AUTO */
2575 pAd->CommonCfg.TxPreamble = Rt802_11PreambleAuto; /* use Long preamble on TX by defaut */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002576 pAd->CommonCfg.bUseZeroToDisableFragment = FALSE;
2577 pAd->CommonCfg.RtsThreshold = 2347;
2578 pAd->CommonCfg.FragmentThreshold = 2346;
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08002579 pAd->CommonCfg.UseBGProtection = 0; /* 0: AUTO */
2580 pAd->CommonCfg.bEnableTxBurst = TRUE; /*0; */
2581 pAd->CommonCfg.PhyMode = 0xff; /* unknown */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002582 pAd->CommonCfg.BandState = UNKNOWN_BAND;
2583 pAd->CommonCfg.RadarDetect.CSPeriod = 10;
2584 pAd->CommonCfg.RadarDetect.CSCount = 0;
2585 pAd->CommonCfg.RadarDetect.RDMode = RD_NORMAL_MODE;
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02002586
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002587 pAd->CommonCfg.RadarDetect.ChMovingTime = 65;
2588 pAd->CommonCfg.RadarDetect.LongPulseRadarTh = 3;
2589 pAd->CommonCfg.bAPSDCapable = FALSE;
2590 pAd->CommonCfg.bNeedSendTriggerFrame = FALSE;
2591 pAd->CommonCfg.TriggerTimerCount = 0;
2592 pAd->CommonCfg.bAPSDForcePowerSave = FALSE;
2593 pAd->CommonCfg.bCountryFlag = FALSE;
2594 pAd->CommonCfg.TxStream = 0;
2595 pAd->CommonCfg.RxStream = 0;
2596
2597 NdisZeroMemory(&pAd->BeaconTxWI, sizeof(pAd->BeaconTxWI));
2598
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08002599 NdisZeroMemory(&pAd->CommonCfg.HtCapability,
2600 sizeof(pAd->CommonCfg.HtCapability));
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002601 pAd->HTCEnable = FALSE;
2602 pAd->bBroadComHT = FALSE;
2603 pAd->CommonCfg.bRdg = FALSE;
2604
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08002605 NdisZeroMemory(&pAd->CommonCfg.AddHTInfo,
2606 sizeof(pAd->CommonCfg.AddHTInfo));
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002607 pAd->CommonCfg.BACapability.field.MMPSmode = MMPS_ENABLE;
2608 pAd->CommonCfg.BACapability.field.MpduDensity = 0;
2609 pAd->CommonCfg.BACapability.field.Policy = IMMED_BA;
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08002610 pAd->CommonCfg.BACapability.field.RxBAWinLimit = 64; /*32; */
2611 pAd->CommonCfg.BACapability.field.TxBAWinLimit = 64; /*32; */
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08002612 DBGPRINT(RT_DEBUG_TRACE,
2613 ("--> UserCfgInit. BACapability = 0x%x\n",
2614 pAd->CommonCfg.BACapability.word));
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002615
2616 pAd->CommonCfg.BACapability.field.AutoBA = FALSE;
2617 BATableInit(pAd, &pAd->BATable);
2618
2619 pAd->CommonCfg.bExtChannelSwitchAnnouncement = 1;
2620 pAd->CommonCfg.bHTProtect = 1;
2621 pAd->CommonCfg.bMIMOPSEnable = TRUE;
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08002622 /*2008/11/05:KH add to support Antenna power-saving of AP<-- */
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08002623 pAd->CommonCfg.bGreenAPEnable = FALSE;
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08002624 /*2008/11/05:KH add to support Antenna power-saving of AP--> */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002625 pAd->CommonCfg.bBADecline = FALSE;
2626 pAd->CommonCfg.bDisableReordering = FALSE;
2627
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08002628 if (pAd->MACVersion == 0x28720200) {
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08002629 pAd->CommonCfg.TxBASize = 13; /*by Jerry recommend */
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08002630 } else {
2631 pAd->CommonCfg.TxBASize = 7;
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02002632 }
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002633
2634 pAd->CommonCfg.REGBACapability.word = pAd->CommonCfg.BACapability.word;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002635
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08002636 /*pAd->CommonCfg.HTPhyMode.field.BW = BW_20; */
2637 /*pAd->CommonCfg.HTPhyMode.field.MCS = MCS_AUTO; */
2638 /*pAd->CommonCfg.HTPhyMode.field.ShortGI = GI_800; */
2639 /*pAd->CommonCfg.HTPhyMode.field.STBC = STBC_NONE; */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002640 pAd->CommonCfg.TxRate = RATE_6;
2641
2642 pAd->CommonCfg.MlmeTransmit.field.MCS = MCS_RATE_6;
2643 pAd->CommonCfg.MlmeTransmit.field.BW = BW_20;
2644 pAd->CommonCfg.MlmeTransmit.field.MODE = MODE_OFDM;
2645
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08002646 pAd->CommonCfg.BeaconPeriod = 100; /* in mSec */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002647
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08002648 /* */
Uwe Kleine-König9b0131c2010-09-01 15:40:25 +02002649 /* part II. initialize STA specific configuration */
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08002650 /* */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002651 {
2652 RX_FILTER_SET_FLAG(pAd, fRX_FILTER_ACCEPT_DIRECT);
2653 RX_FILTER_CLEAR_FLAG(pAd, fRX_FILTER_ACCEPT_MULTICAST);
2654 RX_FILTER_SET_FLAG(pAd, fRX_FILTER_ACCEPT_BROADCAST);
2655 RX_FILTER_SET_FLAG(pAd, fRX_FILTER_ACCEPT_ALL_MULTICAST);
2656
2657 pAd->StaCfg.Psm = PWR_ACTIVE;
2658
2659 pAd->StaCfg.OrigWepStatus = Ndis802_11EncryptionDisabled;
2660 pAd->StaCfg.PairCipher = Ndis802_11EncryptionDisabled;
2661 pAd->StaCfg.GroupCipher = Ndis802_11EncryptionDisabled;
2662 pAd->StaCfg.bMixCipher = FALSE;
2663 pAd->StaCfg.DefaultKeyId = 0;
2664
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08002665 /* 802.1x port control */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002666 pAd->StaCfg.PrivacyFilter = Ndis802_11PrivFilter8021xWEP;
2667 pAd->StaCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
2668 pAd->StaCfg.LastMicErrorTime = 0;
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08002669 pAd->StaCfg.MicErrCnt = 0;
2670 pAd->StaCfg.bBlockAssoc = FALSE;
2671 pAd->StaCfg.WpaState = SS_NOTUSE;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002672
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08002673 pAd->CommonCfg.NdisRadioStateOff = FALSE; /* New to support microsoft disable radio with OID command */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002674
2675 pAd->StaCfg.RssiTrigger = 0;
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -08002676 NdisZeroMemory(&pAd->StaCfg.RssiSample, sizeof(struct rt_rssi_sample));
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08002677 pAd->StaCfg.RssiTriggerMode =
2678 RSSI_TRIGGERED_UPON_BELOW_THRESHOLD;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002679 pAd->StaCfg.AtimWin = 0;
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08002680 pAd->StaCfg.DefaultListenCount = 3; /*default listen count; */
2681 pAd->StaCfg.BssType = BSS_INFRA; /* BSS_INFRA or BSS_ADHOC or BSS_MONITOR */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002682 pAd->StaCfg.bScanReqIsFromWebUI = FALSE;
2683 OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_DOZE);
2684 OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_WAKEUP_NOW);
2685
2686 pAd->StaCfg.bAutoTxRateSwitch = TRUE;
2687 pAd->StaCfg.DesiredTransmitSetting.field.MCS = MCS_AUTO;
2688 }
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002689
Bartlomiej Zolnierkiewicze44fd1c2009-09-22 20:44:24 +02002690#ifdef PCIE_PS_SUPPORT
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08002691 pAd->brt30xxBanMcuCmd = FALSE;
2692 pAd->b3090ESpecialChip = FALSE;
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08002693/*KH Debug:the following must be removed */
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08002694 pAd->StaCfg.PSControl.field.rt30xxPowerMode = 3;
2695 pAd->StaCfg.PSControl.field.rt30xxForceASPMTest = 0;
2696 pAd->StaCfg.PSControl.field.rt30xxFollowHostASPM = 1;
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08002697#endif /* PCIE_PS_SUPPORT // */
Bartlomiej Zolnierkiewicze44fd1c2009-09-22 20:44:24 +02002698
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08002699 /* global variables mXXXX used in MAC protocol state machines */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002700 OPSTATUS_SET_FLAG(pAd, fOP_STATUS_RECEIVE_DTIM);
2701 OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_ADHOC_ON);
2702 OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_INFRA_ON);
2703
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08002704 /* PHY specification */
2705 pAd->CommonCfg.PhyMode = PHY_11BG_MIXED; /* default PHY mode */
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -08002706 OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_SHORT_PREAMBLE_INUSED); /* CCK use long preamble */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002707
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002708 {
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08002709 /* user desired power mode */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002710 pAd->StaCfg.WindowsPowerMode = Ndis802_11PowerModeCAM;
2711 pAd->StaCfg.WindowsBatteryPowerMode = Ndis802_11PowerModeCAM;
2712 pAd->StaCfg.bWindowsACCAMEnable = FALSE;
2713
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08002714 RTMPInitTimer(pAd, &pAd->StaCfg.StaQuickResponeForRateUpTimer,
2715 GET_TIMER_FUNCTION(StaQuickResponeForRateUpExec),
2716 pAd, FALSE);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002717 pAd->StaCfg.StaQuickResponeForRateUpTimerRunning = FALSE;
2718
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08002719 /* Patch for Ndtest */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002720 pAd->StaCfg.ScanCnt = 0;
2721
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08002722 pAd->StaCfg.bHwRadio = TRUE; /* Default Hardware Radio status is On */
2723 pAd->StaCfg.bSwRadio = TRUE; /* Default Software Radio status is On */
2724 pAd->StaCfg.bRadio = TRUE; /* bHwRadio && bSwRadio */
2725 pAd->StaCfg.bHardwareRadio = FALSE; /* Default is OFF */
2726 pAd->StaCfg.bShowHiddenSSID = FALSE; /* Default no show */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002727
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08002728 /* Nitro mode control */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002729 pAd->StaCfg.bAutoReconnect = TRUE;
2730
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08002731 /* Save the init time as last scan time, the system should do scan after 2 seconds. */
2732 /* This patch is for driver wake up from standby mode, system will do scan right away. */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02002733 NdisGetSystemUpTime(&pAd->StaCfg.LastScanTime);
2734 if (pAd->StaCfg.LastScanTime > 10 * OS_HZ)
2735 pAd->StaCfg.LastScanTime -= (10 * OS_HZ);
2736
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08002737 NdisZeroMemory(pAd->nickname, IW_ESSID_MAX_SIZE + 1);
Bartlomiej Zolnierkiewicze44fd1c2009-09-22 20:44:24 +02002738#ifdef RTMP_MAC_PCI
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -08002739 sprintf((char *)pAd->nickname, "RT2860STA");
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08002740#endif /* RTMP_MAC_PCI // */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02002741#ifdef RTMP_MAC_USB
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -08002742 sprintf((char *)pAd->nickname, "RT2870STA");
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08002743#endif /* RTMP_MAC_USB // */
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08002744 RTMPInitTimer(pAd, &pAd->StaCfg.WpaDisassocAndBlockAssocTimer,
2745 GET_TIMER_FUNCTION(WpaDisassocApAndBlockAssoc),
2746 pAd, FALSE);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002747 pAd->StaCfg.IEEE8021X = FALSE;
2748 pAd->StaCfg.IEEE8021x_required_keys = FALSE;
2749 pAd->StaCfg.WpaSupplicantUP = WPA_SUPPLICANT_DISABLE;
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02002750 pAd->StaCfg.bRSN_IE_FromWpaSupplicant = FALSE;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002751 pAd->StaCfg.WpaSupplicantUP = WPA_SUPPLICANT_ENABLE;
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02002752
2753 NdisZeroMemory(pAd->StaCfg.ReplayCounter, 8);
2754
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02002755 pAd->StaCfg.bAutoConnectByBssid = FALSE;
2756 pAd->StaCfg.BeaconLostTime = BEACON_LOST_TIME;
2757 NdisZeroMemory(pAd->StaCfg.WpaPassPhrase, 64);
2758 pAd->StaCfg.WpaPassPhraseLen = 0;
2759 pAd->StaCfg.bAutoRoaming = FALSE;
2760 pAd->StaCfg.bForceTxBurst = FALSE;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002761 }
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002762
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08002763 /* Default for extra information is not valid */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002764 pAd->ExtraInfo = EXTRA_INFO_CLEAR;
2765
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08002766 /* Default Config change flag */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002767 pAd->bConfigChanged = FALSE;
2768
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08002769 /* */
2770 /* part III. AP configurations */
2771 /* */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002772
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08002773 /* */
2774 /* part IV. others */
2775 /* */
2776 /* dynamic BBP R66:sensibity tuning to overcome background noise */
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08002777 pAd->BbpTuning.bEnable = TRUE;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002778 pAd->BbpTuning.FalseCcaLowerThreshold = 100;
2779 pAd->BbpTuning.FalseCcaUpperThreshold = 512;
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08002780 pAd->BbpTuning.R66Delta = 4;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002781 pAd->Mlme.bEnableAutoAntennaCheck = TRUE;
2782
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08002783 /* */
2784 /* Also initial R66CurrentValue, RTUSBResumeMsduTransmission might use this value. */
2785 /* if not initial this value, the default value will be 0. */
2786 /* */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002787 pAd->BbpTuning.R66CurrentValue = 0x38;
2788
2789 pAd->Bbp94 = BBPR94_DEFAULT;
2790 pAd->BbpForCCK = FALSE;
2791
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08002792 /* Default is FALSE for test bit 1 */
2793 /*pAd->bTest1 = FALSE; */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02002794
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08002795 /* initialize MAC table and allocate spin lock */
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -08002796 NdisZeroMemory(&pAd->MacTab, sizeof(struct rt_mac_table));
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002797 InitializeQueueHeader(&pAd->MacTab.McastPsQueue);
2798 NdisAllocateSpinLock(&pAd->MacTabLock);
2799
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08002800 /*RTMPInitTimer(pAd, &pAd->RECBATimer, RECBATimerTimeout, pAd, TRUE); */
2801 /*RTMPSetTimer(&pAd->RECBATimer, REORDER_EXEC_INTV); */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002802
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02002803 pAd->CommonCfg.bWiFiTest = FALSE;
2804#ifdef RTMP_MAC_PCI
2805 pAd->bPCIclkOff = FALSE;
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08002806#endif /* RTMP_MAC_PCI // */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02002807
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08002808 RTMP_SET_PSFLAG(pAd, fRTMP_PS_CAN_GO_SLEEP);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002809 DBGPRINT(RT_DEBUG_TRACE, ("<-- UserCfgInit\n"));
2810}
2811
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08002812/* IRQL = PASSIVE_LEVEL */
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08002813/* */
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -08002814/* FUNCTION: AtoH(char *, u8 *, int) */
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08002815/* */
2816/* PURPOSE: Converts ascii string to network order hex */
2817/* */
2818/* PARAMETERS: */
2819/* src - pointer to input ascii string */
2820/* dest - pointer to output hex */
2821/* destlen - size of dest */
2822/* */
2823/* COMMENTS: */
2824/* */
2825/* 2 ascii bytes make a hex byte so must put 1st ascii byte of pair */
2826/* into upper nibble and 2nd ascii byte of pair into lower nibble. */
2827/* */
2828/* IRQL = PASSIVE_LEVEL */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002829
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -08002830void AtoH(char *src, u8 *dest, int destlen)
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002831{
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -08002832 char *srcptr;
2833 u8 *destTemp;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002834
2835 srcptr = src;
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -08002836 destTemp = (u8 *)dest;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002837
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08002838 while (destlen--) {
Andy Shevchenko1356de02010-05-24 14:33:27 -07002839 *destTemp = hex_to_bin(*srcptr++) << 4; /* Put 1st ascii byte in upper nibble. */
2840 *destTemp += hex_to_bin(*srcptr++); /* Add 2nd ascii byte to above. */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002841 destTemp++;
2842 }
2843}
2844
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08002845/*+++Mark by shiang, not use now, need to remove after confirm */
2846/*---Mark by shiang, not use now, need to remove after confirm */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002847
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002848/*
2849 ========================================================================
2850
2851 Routine Description:
2852 Init timer objects
2853
2854 Arguments:
2855 pAd Pointer to our adapter
2856 pTimer Timer structure
2857 pTimerFunc Function to execute when timer expired
2858 Repeat Ture for period timer
2859
2860 Return Value:
2861 None
2862
2863 Note:
2864
2865 ========================================================================
2866*/
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -08002867void RTMPInitTimer(struct rt_rtmp_adapter *pAd,
2868 struct rt_ralink_timer *pTimer,
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -08002869 void *pTimerFunc, void *pData, IN BOOLEAN Repeat)
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002870{
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08002871 /* */
2872 /* Set Valid to TRUE for later used. */
2873 /* It will crash if we cancel a timer or set a timer */
2874 /* that we haven't initialize before. */
2875 /* */
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08002876 pTimer->Valid = TRUE;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002877
2878 pTimer->PeriodicType = Repeat;
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08002879 pTimer->State = FALSE;
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -08002880 pTimer->cookie = (unsigned long)pData;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002881
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02002882#ifdef RTMP_TIMER_TASK_SUPPORT
Bartlomiej Zolnierkiewicz59fe2d82009-04-26 16:06:28 +02002883 pTimer->pAd = pAd;
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08002884#endif /* RTMP_TIMER_TASK_SUPPORT // */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002885
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -08002886 RTMP_OS_Init_Timer(pAd, &pTimer->TimerObj, pTimerFunc, (void *)pTimer);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002887}
2888
2889/*
2890 ========================================================================
2891
2892 Routine Description:
2893 Init timer objects
2894
2895 Arguments:
2896 pTimer Timer structure
2897 Value Timer value in milliseconds
2898
2899 Return Value:
2900 None
2901
2902 Note:
2903 To use this routine, must call RTMPInitTimer before.
2904
2905 ========================================================================
2906*/
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -08002907void RTMPSetTimer(struct rt_ralink_timer *pTimer, unsigned long Value)
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002908{
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08002909 if (pTimer->Valid) {
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002910 pTimer->TimerValue = Value;
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08002911 pTimer->State = FALSE;
2912 if (pTimer->PeriodicType == TRUE) {
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002913 pTimer->Repeat = TRUE;
2914 RTMP_SetPeriodicTimer(&pTimer->TimerObj, Value);
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08002915 } else {
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002916 pTimer->Repeat = FALSE;
2917 RTMP_OS_Add_Timer(&pTimer->TimerObj, Value);
2918 }
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08002919 } else {
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002920 DBGPRINT_ERR(("RTMPSetTimer failed, Timer hasn't been initialize!\n"));
2921 }
2922}
2923
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002924/*
2925 ========================================================================
2926
2927 Routine Description:
2928 Init timer objects
2929
2930 Arguments:
2931 pTimer Timer structure
2932 Value Timer value in milliseconds
2933
2934 Return Value:
2935 None
2936
2937 Note:
2938 To use this routine, must call RTMPInitTimer before.
2939
2940 ========================================================================
2941*/
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -08002942void RTMPModTimer(struct rt_ralink_timer *pTimer, unsigned long Value)
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002943{
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08002944 BOOLEAN Cancel;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002945
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08002946 if (pTimer->Valid) {
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002947 pTimer->TimerValue = Value;
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08002948 pTimer->State = FALSE;
2949 if (pTimer->PeriodicType == TRUE) {
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002950 RTMPCancelTimer(pTimer, &Cancel);
2951 RTMPSetTimer(pTimer, Value);
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08002952 } else {
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002953 RTMP_OS_Mod_Timer(&pTimer->TimerObj, Value);
2954 }
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08002955 } else {
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002956 DBGPRINT_ERR(("RTMPModTimer failed, Timer hasn't been initialize!\n"));
2957 }
2958}
2959
2960/*
2961 ========================================================================
2962
2963 Routine Description:
2964 Cancel timer objects
2965
2966 Arguments:
2967 Adapter Pointer to our adapter
2968
2969 Return Value:
2970 None
2971
2972 IRQL = PASSIVE_LEVEL
2973 IRQL = DISPATCH_LEVEL
2974
2975 Note:
2976 1.) To use this routine, must call RTMPInitTimer before.
2977 2.) Reset NIC to initial state AS IS system boot up time.
2978
2979 ========================================================================
2980*/
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -08002981void RTMPCancelTimer(struct rt_ralink_timer *pTimer, OUT BOOLEAN * pCancelled)
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002982{
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08002983 if (pTimer->Valid) {
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002984 if (pTimer->State == FALSE)
2985 pTimer->Repeat = FALSE;
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02002986
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08002987 RTMP_OS_Del_Timer(&pTimer->TimerObj, pCancelled);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002988
2989 if (*pCancelled == TRUE)
2990 pTimer->State = TRUE;
2991
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02002992#ifdef RTMP_TIMER_TASK_SUPPORT
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08002993 /* We need to go-through the TimerQ to findout this timer handler and remove it if */
2994 /* it's still waiting for execution. */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02002995 RtmpTimerQRemove(pTimer->pAd, pTimer);
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08002996#endif /* RTMP_TIMER_TASK_SUPPORT // */
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08002997 } else {
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002998 DBGPRINT_ERR(("RTMPCancelTimer failed, Timer hasn't been initialize!\n"));
2999 }
3000}
3001
3002/*
3003 ========================================================================
3004
3005 Routine Description:
3006 Set LED Status
3007
3008 Arguments:
3009 pAd Pointer to our adapter
3010 Status LED Status
3011
3012 Return Value:
3013 None
3014
3015 IRQL = PASSIVE_LEVEL
3016 IRQL = DISPATCH_LEVEL
3017
3018 Note:
3019
3020 ========================================================================
3021*/
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -08003022void RTMPSetLED(struct rt_rtmp_adapter *pAd, u8 Status)
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07003023{
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -08003024 /*unsigned long data; */
3025 u8 HighByte = 0;
3026 u8 LowByte;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07003027
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08003028 LowByte = pAd->LedCntl.field.LedMode & 0x7f;
3029 switch (Status) {
3030 case LED_LINK_DOWN:
3031 HighByte = 0x20;
3032 AsicSendCommandToMcu(pAd, 0x50, 0xff, LowByte, HighByte);
3033 pAd->LedIndicatorStrength = 0;
3034 break;
3035 case LED_LINK_UP:
3036 if (pAd->CommonCfg.Channel > 14)
3037 HighByte = 0xa0;
3038 else
3039 HighByte = 0x60;
3040 AsicSendCommandToMcu(pAd, 0x50, 0xff, LowByte, HighByte);
3041 break;
3042 case LED_RADIO_ON:
3043 HighByte = 0x20;
3044 AsicSendCommandToMcu(pAd, 0x50, 0xff, LowByte, HighByte);
3045 break;
3046 case LED_HALT:
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08003047 LowByte = 0; /* Driver sets MAC register and MAC controls LED */
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08003048 case LED_RADIO_OFF:
3049 HighByte = 0;
3050 AsicSendCommandToMcu(pAd, 0x50, 0xff, LowByte, HighByte);
3051 break;
3052 case LED_WPS:
3053 HighByte = 0x10;
3054 AsicSendCommandToMcu(pAd, 0x50, 0xff, LowByte, HighByte);
3055 break;
3056 case LED_ON_SITE_SURVEY:
3057 HighByte = 0x08;
3058 AsicSendCommandToMcu(pAd, 0x50, 0xff, LowByte, HighByte);
3059 break;
3060 case LED_POWER_UP:
3061 HighByte = 0x04;
3062 AsicSendCommandToMcu(pAd, 0x50, 0xff, LowByte, HighByte);
3063 break;
3064 default:
3065 DBGPRINT(RT_DEBUG_WARN,
3066 ("RTMPSetLED::Unknown Status %d\n", Status));
3067 break;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07003068 }
3069
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08003070 /* */
3071 /* Keep LED status for LED SiteSurvey mode. */
3072 /* After SiteSurvey, we will set the LED mode to previous status. */
3073 /* */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07003074 if ((Status != LED_ON_SITE_SURVEY) && (Status != LED_POWER_UP))
3075 pAd->LedStatus = Status;
3076
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08003077 DBGPRINT(RT_DEBUG_TRACE,
3078 ("RTMPSetLED::Mode=%d,HighByte=0x%02x,LowByte=0x%02x\n",
3079 pAd->LedCntl.field.LedMode, HighByte, LowByte));
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07003080}
3081
3082/*
3083 ========================================================================
3084
3085 Routine Description:
3086 Set LED Signal Stregth
3087
3088 Arguments:
3089 pAd Pointer to our adapter
3090 Dbm Signal Stregth
3091
3092 Return Value:
3093 None
3094
3095 IRQL = PASSIVE_LEVEL
3096
3097 Note:
3098 Can be run on any IRQL level.
3099
3100 According to Microsoft Zero Config Wireless Signal Stregth definition as belows.
3101 <= -90 No Signal
3102 <= -81 Very Low
3103 <= -71 Low
3104 <= -67 Good
3105 <= -57 Very Good
3106 > -57 Excellent
3107 ========================================================================
3108*/
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -08003109void RTMPSetSignalLED(struct rt_rtmp_adapter *pAd, IN NDIS_802_11_RSSI Dbm)
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07003110{
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -08003111 u8 nLed = 0;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07003112
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08003113 if (pAd->LedCntl.field.LedMode == LED_MODE_SIGNAL_STREGTH) {
3114 if (Dbm <= -90)
3115 nLed = 0;
3116 else if (Dbm <= -81)
3117 nLed = 1;
3118 else if (Dbm <= -71)
3119 nLed = 3;
3120 else if (Dbm <= -67)
3121 nLed = 7;
3122 else if (Dbm <= -57)
3123 nLed = 15;
3124 else
3125 nLed = 31;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07003126
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08003127 /* */
3128 /* Update Signal Stregth to firmware if changed. */
3129 /* */
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08003130 if (pAd->LedIndicatorStrength != nLed) {
3131 AsicSendCommandToMcu(pAd, 0x51, 0xff, nLed,
3132 pAd->LedCntl.field.Polarity);
3133 pAd->LedIndicatorStrength = nLed;
3134 }
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07003135 }
3136}
3137
3138/*
3139 ========================================================================
3140
3141 Routine Description:
3142 Enable RX
3143
3144 Arguments:
3145 pAd Pointer to our adapter
3146
3147 Return Value:
3148 None
3149
3150 IRQL <= DISPATCH_LEVEL
3151
3152 Note:
3153 Before Enable RX, make sure you have enabled Interrupt.
3154 ========================================================================
3155*/
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -08003156void RTMPEnableRxTx(struct rt_rtmp_adapter *pAd)
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07003157{
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08003158/* WPDMA_GLO_CFG_STRUC GloCfg; */
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -08003159/* unsigned long i = 0; */
3160 u32 rx_filter_flag;
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02003161
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07003162 DBGPRINT(RT_DEBUG_TRACE, ("==> RTMPEnableRxTx\n"));
3163
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08003164 /* Enable Rx DMA. */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07003165 RT28XXDMAEnable(pAd);
3166
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08003167 /* enable RX of MAC block */
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08003168 if (pAd->OpMode == OPMODE_AP) {
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02003169 rx_filter_flag = APNORMAL;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07003170
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08003171 RTMP_IO_WRITE32(pAd, RX_FILTR_CFG, rx_filter_flag); /* enable RX of DMA block */
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08003172 } else {
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02003173 if (pAd->CommonCfg.PSPXlink)
3174 rx_filter_flag = PSPXLINK;
3175 else
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08003176 rx_filter_flag = STANORMAL; /* Staion not drop control frame will fail WiFi Certification. */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02003177 RTMP_IO_WRITE32(pAd, RX_FILTR_CFG, rx_filter_flag);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07003178 }
3179
3180 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, 0xc);
3181 DBGPRINT(RT_DEBUG_TRACE, ("<== RTMPEnableRxTx\n"));
3182}
3183
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08003184/*+++Add by shiang, move from os/linux/rt_main_dev.c */
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -08003185void CfgInitHook(struct rt_rtmp_adapter *pAd)
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02003186{
3187 pAd->bBroadComHT = TRUE;
3188}
3189
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -08003190int rt28xx_init(struct rt_rtmp_adapter *pAd,
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -08003191 char *pDefaultMac, char *pHostName)
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02003192{
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -08003193 u32 index;
3194 u8 TmpPhy;
3195 int Status;
3196 u32 MacCsr0 = 0;
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02003197
3198#ifdef RTMP_MAC_PCI
3199 {
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08003200 /* If dirver doesn't wake up firmware here, */
3201 /* NICLoadFirmware will hang forever when interface is up again. */
3202 /* RT2860 PCI */
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08003203 if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_DOZE) &&
3204 OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_PCIE_DEVICE)) {
3205 AUTO_WAKEUP_STRUC AutoWakeupCfg;
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02003206 AsicForceWakeup(pAd, TRUE);
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08003207 AutoWakeupCfg.word = 0;
3208 RTMP_IO_WRITE32(pAd, AUTO_WAKEUP_CFG,
3209 AutoWakeupCfg.word);
3210 OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_DOZE);
3211 }
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02003212 }
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08003213#endif /* RTMP_MAC_PCI // */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02003214
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08003215 /* reset Adapter flags */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02003216 RTMP_CLEAR_FLAGS(pAd);
3217
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08003218 /* Init BssTab & ChannelInfo tabbles for auto channel select. */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02003219
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08003220 /* Allocate BA Reordering memory */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02003221 ba_reordering_resource_init(pAd, MAX_REORDERING_MPDU_NUM);
3222
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08003223 /* Make sure MAC gets ready. */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02003224 index = 0;
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08003225 do {
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02003226 RTMP_IO_READ32(pAd, MAC_CSR0, &MacCsr0);
3227 pAd->MACVersion = MacCsr0;
3228
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08003229 if ((pAd->MACVersion != 0x00)
3230 && (pAd->MACVersion != 0xFFFFFFFF))
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02003231 break;
3232
3233 RTMPusecDelay(10);
3234 } while (index++ < 100);
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08003235 DBGPRINT(RT_DEBUG_TRACE,
3236 ("MAC_CSR0 [ Ver:Rev=0x%08x]\n", pAd->MACVersion));
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02003237
3238#ifdef RTMP_MAC_PCI
Bartlomiej Zolnierkiewicze44fd1c2009-09-22 20:44:24 +02003239#ifdef PCIE_PS_SUPPORT
3240 /*Iverson patch PCIE L1 issue to make sure that driver can be read,write ,BBP and RF register at pcie L.1 level */
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08003241 if ((IS_RT3090(pAd) || IS_RT3572(pAd) || IS_RT3390(pAd))
3242 && OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_PCIE_DEVICE)) {
Bartlomiej Zolnierkiewicze44fd1c2009-09-22 20:44:24 +02003243 RTMP_IO_READ32(pAd, AUX_CTRL, &MacCsr0);
3244 MacCsr0 |= 0x402;
3245 RTMP_IO_WRITE32(pAd, AUX_CTRL, MacCsr0);
3246 DBGPRINT(RT_DEBUG_TRACE, ("AUX_CTRL = 0x%x\n", MacCsr0));
3247 }
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08003248#endif /* PCIE_PS_SUPPORT // */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02003249
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08003250 /* To fix driver disable/enable hang issue when radio off */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02003251 RTMP_IO_WRITE32(pAd, PWR_PIN_CFG, 0x2);
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08003252#endif /* RTMP_MAC_PCI // */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02003253
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08003254 /* Disable DMA */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02003255 RT28XXDMADisable(pAd);
3256
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08003257 /* Load 8051 firmware */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02003258 Status = NICLoadFirmware(pAd);
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08003259 if (Status != NDIS_STATUS_SUCCESS) {
3260 DBGPRINT_ERR(("NICLoadFirmware failed, Status[=0x%08x]\n",
3261 Status));
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02003262 goto err1;
3263 }
3264
3265 NICLoadRateSwitchingParams(pAd);
3266
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08003267 /* Disable interrupts here which is as soon as possible */
3268 /* This statement should never be true. We might consider to remove it later */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02003269#ifdef RTMP_MAC_PCI
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08003270 if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_ACTIVE)) {
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02003271 RTMP_ASIC_INTERRUPT_DISABLE(pAd);
3272 }
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08003273#endif /* RTMP_MAC_PCI // */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02003274
3275 Status = RTMPAllocTxRxRingMemory(pAd);
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08003276 if (Status != NDIS_STATUS_SUCCESS) {
3277 DBGPRINT_ERR(("RTMPAllocDMAMemory failed, Status[=0x%08x]\n",
3278 Status));
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02003279 goto err1;
3280 }
3281
3282 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE);
3283
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08003284 /* initialize MLME */
3285 /* */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02003286
3287 Status = RtmpMgmtTaskInit(pAd);
3288 if (Status != NDIS_STATUS_SUCCESS)
3289 goto err2;
3290
3291 Status = MlmeInit(pAd);
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08003292 if (Status != NDIS_STATUS_SUCCESS) {
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02003293 DBGPRINT_ERR(("MlmeInit failed, Status[=0x%08x]\n", Status));
3294 goto err2;
3295 }
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08003296 /* Initialize pAd->StaCfg, pAd->ApCfg, pAd->CommonCfg to manufacture default */
3297 /* */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02003298 UserCfgInit(pAd);
3299 Status = RtmpNetTaskInit(pAd);
3300 if (Status != NDIS_STATUS_SUCCESS)
3301 goto err3;
3302
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08003303/* COPY_MAC_ADDR(pAd->ApCfg.MBSSID[apidx].Bssid, netif->hwaddr); */
3304/* pAd->bForcePrintTX = TRUE; */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02003305
3306 CfgInitHook(pAd);
3307
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08003308 NdisAllocateSpinLock(&pAd->MacTabLock);
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02003309
3310 MeasureReqTabInit(pAd);
3311 TpcReqTabInit(pAd);
3312
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08003313 /* */
3314 /* Init the hardware, we need to init asic before read registry, otherwise mac register will be reset */
3315 /* */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02003316 Status = NICInitializeAdapter(pAd, TRUE);
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08003317 if (Status != NDIS_STATUS_SUCCESS) {
3318 DBGPRINT_ERR(("NICInitializeAdapter failed, Status[=0x%08x]\n",
3319 Status));
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02003320 if (Status != NDIS_STATUS_SUCCESS)
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08003321 goto err3;
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02003322 }
3323
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02003324 DBGPRINT(RT_DEBUG_OFF, ("1. Phy Mode = %d\n", pAd->CommonCfg.PhyMode));
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02003325
3326#ifdef RTMP_MAC_USB
3327 pAd->CommonCfg.bMultipleIRP = FALSE;
3328
3329 if (pAd->CommonCfg.bMultipleIRP)
3330 pAd->CommonCfg.NumOfBulkInIRP = RX_RING_SIZE;
3331 else
3332 pAd->CommonCfg.NumOfBulkInIRP = 1;
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08003333#endif /* RTMP_MAC_USB // */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02003334
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08003335 /*Init Ba Capability parameters. */
3336/* RT28XX_BA_INIT(pAd); */
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08003337 pAd->CommonCfg.DesiredHtPhy.MpduDensity =
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -08003338 (u8)pAd->CommonCfg.BACapability.field.MpduDensity;
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08003339 pAd->CommonCfg.DesiredHtPhy.AmsduEnable =
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -08003340 (u16)pAd->CommonCfg.BACapability.field.AmsduEnable;
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08003341 pAd->CommonCfg.DesiredHtPhy.AmsduSize =
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -08003342 (u16)pAd->CommonCfg.BACapability.field.AmsduSize;
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08003343 pAd->CommonCfg.DesiredHtPhy.MimoPs =
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -08003344 (u16)pAd->CommonCfg.BACapability.field.MMPSmode;
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08003345 /* UPdata to HT IE */
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08003346 pAd->CommonCfg.HtCapability.HtCapInfo.MimoPs =
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -08003347 (u16)pAd->CommonCfg.BACapability.field.MMPSmode;
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08003348 pAd->CommonCfg.HtCapability.HtCapInfo.AMsduSize =
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -08003349 (u16)pAd->CommonCfg.BACapability.field.AmsduSize;
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08003350 pAd->CommonCfg.HtCapability.HtCapParm.MpduDensity =
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -08003351 (u8)pAd->CommonCfg.BACapability.field.MpduDensity;
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02003352
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08003353 /* after reading Registry, we now know if in AP mode or STA mode */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02003354
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08003355 /* Load 8051 firmware; crash when FW image not existent */
3356 /* Status = NICLoadFirmware(pAd); */
3357 /* if (Status != NDIS_STATUS_SUCCESS) */
3358 /* break; */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02003359
3360 DBGPRINT(RT_DEBUG_OFF, ("2. Phy Mode = %d\n", pAd->CommonCfg.PhyMode));
3361
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08003362 /* We should read EEPROM for all cases. rt2860b */
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -08003363 NICReadEEPROMParameters(pAd, (u8 *)pDefaultMac);
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02003364
3365 DBGPRINT(RT_DEBUG_OFF, ("3. Phy Mode = %d\n", pAd->CommonCfg.PhyMode));
3366
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08003367 NICInitAsicFromEEPROM(pAd); /*rt2860b */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02003368
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08003369 /* Set PHY to appropriate mode */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02003370 TmpPhy = pAd->CommonCfg.PhyMode;
3371 pAd->CommonCfg.PhyMode = 0xff;
3372 RTMPSetPhyMode(pAd, TmpPhy);
3373 SetCommonHT(pAd);
3374
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08003375 /* No valid channels. */
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08003376 if (pAd->ChannelListNum == 0) {
3377 DBGPRINT(RT_DEBUG_ERROR,
3378 ("Wrong configuration. No valid channel found. Check \"ContryCode\" and \"ChannelGeography\" setting.\n"));
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02003379 goto err4;
3380 }
3381
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08003382 DBGPRINT(RT_DEBUG_OFF,
3383 ("MCS Set = %02x %02x %02x %02x %02x\n",
3384 pAd->CommonCfg.HtCapability.MCSSet[0],
3385 pAd->CommonCfg.HtCapability.MCSSet[1],
3386 pAd->CommonCfg.HtCapability.MCSSet[2],
3387 pAd->CommonCfg.HtCapability.MCSSet[3],
3388 pAd->CommonCfg.HtCapability.MCSSet[4]));
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02003389
3390#ifdef RTMP_RF_RW_SUPPORT
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08003391 /*Init RT30xx RFRegisters after read RFIC type from EEPROM */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02003392 NICInitRFRegisters(pAd);
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08003393#endif /* RTMP_RF_RW_SUPPORT // */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02003394
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08003395/* APInitialize(pAd); */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02003396
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08003397 /* */
3398 /* Initialize RF register to default value */
3399 /* */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02003400 AsicSwitchChannel(pAd, pAd->CommonCfg.Channel, FALSE);
3401 AsicLockChannel(pAd, pAd->CommonCfg.Channel);
3402
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08003403 /* 8051 firmware require the signal during booting time. */
3404 /*2008/11/28:KH marked the following codes to patch Frequency offset bug */
3405 /*AsicSendCommandToMcu(pAd, 0x72, 0xFF, 0x00, 0x00); */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02003406
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08003407 if (pAd && (Status != NDIS_STATUS_SUCCESS)) {
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08003408 /* */
3409 /* Undo everything if it failed */
3410 /* */
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08003411 if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE)) {
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08003412/* NdisMDeregisterInterrupt(&pAd->Interrupt); */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02003413 RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE);
3414 }
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08003415/* RTMPFreeAdapter(pAd); // we will free it in disconnect() */
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08003416 } else if (pAd) {
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08003417 /* Microsoft HCT require driver send a disconnect event after driver initialization. */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02003418 OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED);
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08003419/* pAd->IndicateMediaState = NdisMediaStateDisconnected; */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02003420 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_MEDIA_STATE_CHANGE);
3421
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08003422 DBGPRINT(RT_DEBUG_TRACE,
3423 ("NDIS_STATUS_MEDIA_DISCONNECT Event B!\n"));
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02003424
3425#ifdef RTMP_MAC_USB
3426 RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_RESET_IN_PROGRESS);
3427 RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_REMOVE_IN_PROGRESS);
3428
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08003429 /* */
3430 /* Support multiple BulkIn IRP, */
3431 /* the value on pAd->CommonCfg.NumOfBulkInIRP may be large than 1. */
3432 /* */
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08003433 for (index = 0; index < pAd->CommonCfg.NumOfBulkInIRP; index++) {
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02003434 RTUSBBulkReceive(pAd);
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08003435 DBGPRINT(RT_DEBUG_TRACE, ("RTUSBBulkReceive!\n"));
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02003436 }
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08003437#endif /* RTMP_MAC_USB // */
3438 } /* end of else */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02003439
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08003440 /* Set up the Mac address */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02003441 RtmpOSNetDevAddrSet(pAd->net_dev, &pAd->CurrentAddress[0]);
3442
3443 DBGPRINT_S(Status, ("<==== rt28xx_init, Status=%x\n", Status));
3444
3445 return TRUE;
3446
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02003447err4:
3448err3:
3449 MlmeHalt(pAd);
3450err2:
3451 RTMPFreeTxRxRingMemory(pAd);
3452err1:
3453
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08003454 os_free_mem(pAd, pAd->mpdu_blk_pool.mem); /* free BA pool */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02003455
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08003456 /* shall not set priv to NULL here because the priv didn't been free yet. */
3457 /*net_dev->ml_priv = 0; */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02003458#ifdef ST
3459err0:
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08003460#endif /* ST // */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02003461
Sebastian Dalfuß06aea992009-11-07 17:31:12 +01003462 DBGPRINT(RT_DEBUG_ERROR, ("rt28xx Initialized fail!\n"));
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02003463 return FALSE;
3464}
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08003465
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08003466/*---Add by shiang, move from os/linux/rt_main_dev.c */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02003467
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -08003468static int RtmpChipOpsRegister(struct rt_rtmp_adapter *pAd, int infType)
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02003469{
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -08003470 struct rt_rtmp_chip_op *pChipOps = &pAd->chipOps;
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02003471 int status;
3472
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -08003473 memset(pChipOps, 0, sizeof(struct rt_rtmp_chip_op));
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02003474
3475 /* set eeprom related hook functions */
3476 status = RtmpChipOpsEepromHook(pAd, infType);
3477
3478 /* set mcu related hook functions */
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08003479 switch (infType) {
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02003480#ifdef RTMP_PCI_SUPPORT
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08003481 case RTMP_DEV_INF_PCI:
3482 pChipOps->loadFirmware = RtmpAsicLoadFirmware;
3483 pChipOps->eraseFirmware = RtmpAsicEraseFirmware;
3484 pChipOps->sendCommandToMcu = RtmpAsicSendCommandToMcu;
3485 break;
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08003486#endif /* RTMP_PCI_SUPPORT // */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02003487#ifdef RTMP_USB_SUPPORT
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08003488 case RTMP_DEV_INF_USB:
3489 pChipOps->loadFirmware = RtmpAsicLoadFirmware;
3490 pChipOps->sendCommandToMcu = RtmpAsicSendCommandToMcu;
3491 break;
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08003492#endif /* RTMP_USB_SUPPORT // */
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08003493 default:
3494 break;
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02003495 }
3496
3497 return status;
3498}
3499
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -08003500int RtmpRaDevCtrlInit(struct rt_rtmp_adapter *pAd, IN RTMP_INF_TYPE infType)
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02003501{
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -08003502 /*void *handle; */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02003503
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08003504 /* Assign the interface type. We need use it when do register/EEPROM access. */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02003505 pAd->infType = infType;
3506
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02003507 pAd->OpMode = OPMODE_STA;
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08003508 DBGPRINT(RT_DEBUG_TRACE,
3509 ("STA Driver version-%s\n", STA_DRIVER_VERSION));
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02003510
3511#ifdef RTMP_MAC_USB
3512 init_MUTEX(&(pAd->UsbVendorReq_semaphore));
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -08003513 os_alloc_mem(pAd, (u8 **) & pAd->UsbVendorReqBuf,
Bartlomiej Zolnierkiewiczca58fb32009-10-21 22:44:42 +02003514 MAX_PARAM_BUFFER_SIZE - 1);
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08003515 if (pAd->UsbVendorReqBuf == NULL) {
3516 DBGPRINT(RT_DEBUG_ERROR,
3517 ("Allocate vendor request temp buffer failed!\n"));
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02003518 return FALSE;
3519 }
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08003520#endif /* RTMP_MAC_USB // */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02003521
3522 RtmpChipOpsRegister(pAd, infType);
3523
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02003524 return 0;
3525}
3526
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -08003527BOOLEAN RtmpRaDevCtrlExit(struct rt_rtmp_adapter *pAd)
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02003528{
3529
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02003530 RTMPFreeAdapter(pAd);
3531
3532 return TRUE;
3533}
3534
Bartlomiej Zolnierkiewiczec278fa2009-12-11 12:23:15 -08003535/* not yet support MBSS */
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -08003536struct net_device *get_netdev_from_bssid(struct rt_rtmp_adapter *pAd, u8 FromWhichBSSID)
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02003537{
Bartlomiej Zolnierkiewicz8a10a542009-12-11 12:23:15 -08003538 struct net_device *dev_p = NULL;
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02003539
3540 {
3541 dev_p = pAd->net_dev;
3542 }
3543
3544 ASSERT(dev_p);
Bartlomiej Zolnierkiewicz96b3c83d2009-12-11 12:23:13 -08003545 return dev_p; /* return one of MBSS */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02003546}