import PULS_20180308
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / misc / mediatek / connectivity / conn_soc / drv_wlan / mt_wifi / wlan / common / wlan_lib.c
CommitLineData
6fa3eb70
S
1/*
2** $Id: //Department/DaVinci/BRANCHES/MT6620_WIFI_DRIVER_V2_3/common/wlan_lib.c#2 $
3*/
4/*! \file wlan_lib.c
5 \brief Internal driver stack will export the required procedures here for GLUE Layer.
6
7 This file contains all routines which are exported from MediaTek 802.11 Wireless
8 LAN driver stack to GLUE Layer.
9*/
10
11
12/*
13** $Log: wlan_lib.c $
14**
15** 08 15 2012 eason.tsai
16** [ALPS00338170] [Need Patch] [Volunteer Patch] modify build warning
17** fix build waring for codechange
18 *
19 * 07 13 2012 cp.wu
20 * [WCXRP00001259] [MT6620 Wi-Fi][Driver][Firmware] Send a signal to firmware for termination after SDIO error has happened
21 * [driver domain] add force reset by host-to-device interrupt mechanism
22 *
23 * 06 11 2012 cp.wu
24 * [WCXRP00001252] [MT6620 Wi-Fi][Driver] Add debug message while encountering firmware response timeout
25 * output message while timeout event occurs
26 *
27 * 06 11 2012 eason.tsai
28 * NULL
29 * change from binay to hex code
30 *
31 * 06 08 2012 eason.tsai
32 * NULL
33 * Nvram context covert from 6620 to 6628 for old 6620 meta tool
34 *
35 * 05 11 2012 cp.wu
36 * [WCXRP00001237] [MT6620 Wi-Fi][Driver] Show MAC address and MAC address source for ACS's convenience
37 * show MAC address & source while initiliazation
38 *
39 * 03 29 2012 eason.tsai
40 * [WCXRP00001216] [MT6628 Wi-Fi][Driver]add conditional define
41 * add conditional define.
42 *
43 * 03 04 2012 eason.tsai
44 * NULL
45 * modify the cal fail report code.
46 *
47 * 03 02 2012 terry.wu
48 * NULL
49 * Sync CFG80211 modification from branch 2,2.
50 *
51 * 01 16 2012 cp.wu
52 * [WCXRP00001169] [MT6620 Wi-Fi][Driver] API and behavior modification for preferred band configuration with corresponding network configuration
53 * correct scan result removing policy.
54 *
55 * 01 16 2012 cp.wu
56 * [MT6620 Wi-Fi][Driver] API and behavior modification for preferred band configuration with corresponding network configuration
57 * add wlanSetPreferBandByNetwork() for glue layer to invoke for setting preferred band configuration corresponding to network type.
58 *
59 * 01 05 2012 wh.su
60 * [WCXRP00001153] [MT6620 Wi-Fi][Driver] Adding the get_ch_list and set_tx_power proto type function
61 * Adding the related ioctl / wlan oid function to set the Tx power cfg.
62 *
63 * 11 28 2011 cp.wu
64 * [WCXRP00001125] [MT6620 Wi-Fi][Firmware] Strengthen Wi-Fi power off sequence to have a clearroom environment when returining to ROM code
65 * 1. Due to firmware now stops HIF DMA for powering off, do not try to receive any packet from firmware
66 * 2. Take use of prAdapter->fgIsEnterD3ReqIssued for tracking whether it is powering off or not
67 *
68 * 11 14 2011 cm.chang
69 * [WCXRP00001104] [All Wi-Fi][FW] Show init process by HW mail-box register
70 * Show FW initial ID when timeout to wait for ready bit
71 *
72 * 11 11 2011 wh.su
73 * [WCXRP00001078] [MT6620 Wi-Fi][Driver] Adding the mediatek log improment support : XLOG
74 * modify the xlog related code.
75 *
76 * 10 18 2011 cp.wu
77 * [WCXRP00001022] [MT6628 Driver][Firmware Download] Add multi section independent download functionality
78 * when powering off, always clear pending interrupts, then wait for RDY to be de-asserted
79 *
80 * 10 14 2011 cp.wu
81 * [WCXRP00001022] [MT6628 Driver][Firmware Download] Add multi section independent download functionality
82 * shorten the packet length for firmware download if no more than 2048 bytes.
83 *
84 * 10 03 2011 cp.wu
85 * [WCXRP00001022] [MT6628 Driver][Firmware Download] Add multi section independent download functionality
86 * add firmware download path in divided scatters.
87 *
88 * 10 03 2011 cp.wu
89 * [MT6628 Driver][Firmware Download] Add multi section independent download functionality
90 * add firmware downloading aggregated path.
91 *
92 * 09 30 2011 cm.chang
93 * [WCXRP00001020] [MT6620 Wi-Fi][Driver] Handle secondary channel offset of AP in 5GHz band
94 * .
95 *
96 * 09 20 2011 cp.wu
97 * [WCXRP00000994] [MT6620 Wi-Fi][Driver] dump message for bus error and reset bus error flag while re-initialized
98 * 1. always show error message for SDIO bus errors.
99 * 2. reset bus error flag when re-initialization
100 *
101 * 08 26 2011 cm.chang
102 * [WCXRP00000952] [MT5931 Wi-Fi][FW] Handshake with BWCS before DPD/TX power calibration
103 * Fix compiling error for WinXP MT5931 driver
104 *
105 * 08 25 2011 chinghwa.yu
106 * [WCXRP00000063] Update BCM CoEx design and settings
107 * Add BWCS Sync ready for WinXP.
108 *
109 * 08 25 2011 chinghwa.yu
110 * [WCXRP00000612] [MT6620 Wi-Fi] [FW] CSD update SWRDD algorithm
111 * Add DFS switch.
112 *
113 * 08 24 2011 chinghwa.yu
114 * [WCXRP00000612] [MT6620 Wi-Fi] [FW] CSD update SWRDD algorithm
115 * Update RDD test mode cases.
116 *
117 * 08 19 2011 cp.wu
118 * [WCXRP00000702] [MT5931][Driver] Modify initialization sequence for E1 ASIC
119 * escape from normal path if any error is occured.
120 *
121 * 08 15 2011 cp.wu
122 * [WCXRP00000851] [MT6628 Wi-Fi][Driver] Add HIFSYS related definition to driver source tree
123 * reuse firmware download logic of MT6620 for MT6628.
124 *
125 * 08 15 2011 cp.wu
126 * [WCXRP00000913] [MT6620 Wi-Fi] create repository of source code dedicated for MT6620 E6 ASIC
127 * support to load different firmware image for E3/E4/E5 and E6 ASIC on win32 platforms.
128 *
129 * 08 02 2011 yuche.tsai
130 * [WCXRP00000896] [Volunteer Patch][WiFi Direct][Driver] GO with multiple client, TX deauth to a disconnecting device issue.
131 * Fix GO send deauth frame issue.
132 *
133 * 07 22 2011 jeffrey.chang
134 * [WCXRP00000864] [MT5931] Add command to adjust OSC stable time
135 * modify driver to set OSC stable time after f/w download
136 *
137 * 07 18 2011 chinghwa.yu
138 * [WCXRP00000063] Update BCM CoEx design and settings[WCXRP00000612] [MT6620 Wi-Fi] [FW] CSD update SWRDD algorithm
139 * Add CMD/Event for RDD and BWCS.
140 *
141 * 06 24 2011 cp.wu
142 * [WCXRP00000812] [MT6620 Wi-Fi][Driver] not show NVRAM when there is no valid MAC address in NVRAM content
143 * if there is no valid address in chip, generate a new one from driver domain instead of firmware domain due to sufficient randomness
144 *
145 * 06 23 2011 cp.wu
146 * [WCXRP00000812] [MT6620 Wi-Fi][Driver] not show NVRAM when there is no valid MAC address in NVRAM content
147 * check with firmware for valid MAC address.
148 *
149 * 06 20 2011 cp.wu
150 * [WCXRP00000702] [MT5931][Driver] Modify initialization sequence for E1 ASIC
151 * disable whole-chip resetting mechanism due to the need of further ECO to work as expected.
152 *
153 * 05 31 2011 cp.wu
154 * [WCXRP00000749] [MT6620 Wi-Fi][Driver] Add band edge tx power control to Wi-Fi NVRAM
155 * changed to use non-zero checking for valid bit in NVRAM content
156 *
157 * 05 27 2011 cp.wu
158 * [WCXRP00000749] [MT6620 Wi-Fi][Driver] Add band edge tx power control to Wi-Fi NVRAM
159 * invoke CMD_ID_SET_EDGE_TXPWR_LIMIT when there is valid data exist in NVRAM content.
160 *
161 * 05 18 2011 cp.wu
162 * [WCXRP00000734] [MT6620 Wi-Fi][Driver] Pass PHY_PARAM in NVRAM to firmware domain
163 * pass PHY_PARAM in NVRAM from driver to firmware.
164 *
165 * 05 11 2011 cp.wu
166 * [WCXRP00000718] [MT6620 Wi-Fi] modify the behavior of setting tx power
167 * correct assertion.
168 *
169 * 05 11 2011 cp.wu
170 * [WCXRP00000718] [MT6620 Wi-Fi] modify the behavior of setting tx power
171 * ACPI APIs migrate to wlan_lib.c for glue layer to invoke.
172 *
173 * 05 11 2011 cm.chang
174 * [WCXRP00000717] [MT5931 Wi-Fi][Driver] Handle wrong NVRAM content about AP bandwidth setting
175 * .
176 *
177 * 05 05 2011 cp.wu
178 * [WCXRP00000702] [MT5931][Driver] Modify initialization sequence for E1 ASIC
179 * change delay from 100ms to 120ms upon DE's suggestion.
180 *
181 * 05 05 2011 cp.wu
182 * [WCXRP00000702] [MT5931][Driver] Modify initialization sequence for E1 ASIC
183 * add delay after whole-chip resetting for MT5931 E1 ASIC.
184 *
185 * 04 22 2011 cp.wu
186 * [WCXRP00000598] [MT6620 Wi-Fi][Driver] Implementation of interface for communicating with user space process for RESET_START and RESET_END events
187 * skip power-off handshaking when RESET indication is received.
188 *
189 * 04 22 2011 george.huang
190 * [WCXRP00000621] [MT6620 Wi-Fi][Driver] Support P2P supplicant to set power mode
191 * .
192 *
193 * 04 18 2011 cp.wu
194 * [WCXRP00000636] [WHQL][MT5931 Driver] 2c_PMHibernate (hang on 2h)
195 * 1) add API for glue layer to query ACPI state
196 * 2) Windows glue should not access to hardware after switched into D3 state
197 *
198 * 04 15 2011 cp.wu
199 * [WCXRP00000654] [MT6620 Wi-Fi][Driver] Add loop termination criterion for wlanAdapterStop().
200 * add loop termination criteria for wlanAdapterStop().
201 *
202 * 04 12 2011 eddie.chen
203 * [WCXRP00000617] [MT6620 Wi-Fi][DRV/FW] Fix for sigma
204 * Fix the sta index in processing security frame
205 * Simple flow control for TC4 to avoid mgt frames for PS STA to occupy the TC4
206 * Add debug message.
207 *
208 * 04 12 2011 cp.wu
209 * [WCXRP00000631] [MT6620 Wi-Fi][Driver] Add an API for QM to retrieve current TC counter value and processing frame dropping cases for TC4 path
210 * 1. add nicTxGetResource() API for QM to make decisions.
211 * 2. if management frames is decided by QM for dropping, the call back is invoked to indicate such a case.
212 *
213 * 04 06 2011 cp.wu
214 * [WCXRP00000616] [MT6620 Wi-Fi][Driver] Free memory to pool and kernel in case any unexpected failure happend inside wlanAdapterStart
215 * invoke nicReleaseAdapterMemory() as failure handling in case wlanAdapterStart() failed unexpectedly
216 *
217 * 03 29 2011 wh.su
218 * [WCXRP00000248] [MT6620 Wi-Fi][FW]Fixed the Klockwork error
219 * fixed the kclocwork error.
220 *
221 * 03 15 2011 cp.wu
222 * [WCXRP00000559] [MT6620 Wi-Fi][Driver] Combine TX/RX DMA buffers into a single one to reduce physically continuous memory consumption
223 * 1. deprecate CFG_HANDLE_IST_IN_SDIO_CALLBACK
224 * 2. Use common coalescing buffer for both TX/RX directions
225 *
226 *
227 * 03 10 2011 cp.wu
228 * [WCXRP00000532] [MT6620 Wi-Fi][Driver] Migrate NVRAM configuration procedures from MT6620 E2 to MT6620 E3
229 * deprecate configuration used by MT6620 E2
230 *
231 * 03 07 2011 terry.wu
232 * [WCXRP00000521] [MT6620 Wi-Fi][Driver] Remove non-standard debug message
233 * Toggle non-standard debug messages to comments.
234 *
235 * 02 25 2011 cp.wu
236 * [WCXRP00000496] [MT5931][Driver] Apply host-triggered chip reset before initializing firmware download procedures
237 * apply host-triggered chip reset mechanism before initializing firmware download procedures.
238 *
239 * 02 17 2011 eddie.chen
240 * [WCXRP00000458] [MT6620 Wi-Fi][Driver] BOW Concurrent - ProbeResp was exist in other channel
241 * 1) Chnage GetFrameAction decision when BSS is absent.
242 * 2) Check channel and resource in processing ProbeRequest
243 *
244 * 02 16 2011 cm.chang
245 * [WCXRP00000447] [MT6620 Wi-Fi][FW] Support new NVRAM update mechanism
246 * .
247 *
248 * 02 01 2011 george.huang
249 * [WCXRP00000333] [MT5931][FW] support SRAM power control drivers
250 * init variable for CTIA.
251 *
252 * 01 27 2011 george.huang
253 * [WCXRP00000355] [MT6620 Wi-Fi] Set WMM-PS related setting with qualifying AP capability
254 * Support current measure mode, assigned by registry (XP only).
255 *
256 * 01 24 2011 cp.wu
257 * [WCXRP00000382] [MT6620 Wi-Fi][Driver] Track forwarding packet number with notifying tx thread for serving
258 * 1. add an extra counter for tracking pending forward frames.
259 * 2. notify TX service thread as well when there is pending forward frame
260 * 3. correct build errors leaded by introduction of Wi-Fi direct separation module
261 *
262 * 01 12 2011 cm.chang
263 * [WCXRP00000354] [MT6620 Wi-Fi][Driver][FW] Follow NVRAM bandwidth setting
264 * User-defined bandwidth is for 2.4G and 5G individually
265 *
266 * 01 10 2011 cp.wu
267 * [WCXRP00000351] [MT6620 Wi-Fi][Driver] remove from scanning result in OID handling layer when the corresponding BSS is disconnected due to beacon timeout
268 * remove from scanning result when the BSS is disconnected due to beacon timeout.
269 *
270 * 01 04 2011 cp.wu
271 * [WCXRP00000338] [MT6620 Wi-Fi][Driver] Separate kalMemAlloc into kmalloc and vmalloc implementations to ease physically continous memory demands
272 * separate kalMemAlloc() into virtually-continous and physically-continous type to ease slab system pressure
273 *
274 * 12 31 2010 cp.wu
275 * [WCXRP00000327] [MT6620 Wi-Fi][Driver] Improve HEC WHQA 6972 workaround coverage in driver side
276 * while being unloaded, clear all pending interrupt then set LP-own to firmware
277 *
278 * 12 31 2010 cp.wu
279 * [WCXRP00000335] [MT6620 Wi-Fi][Driver] change to use milliseconds sleep instead of delay to avoid blocking to system scheduling
280 * change to use msleep() and shorten waiting interval to reduce blocking to other task while Wi-Fi driver is being loaded
281 *
282 * 12 28 2010 cp.wu
283 * [WCXRP00000269] [MT6620 Wi-Fi][Driver][Firmware] Prepare for v1.1 branch release
284 * report EEPROM used flag via NIC_CAPABILITY
285 *
286 * 12 28 2010 cp.wu
287 * [WCXRP00000269] [MT6620 Wi-Fi][Driver][Firmware] Prepare for v1.1 branch release
288 * integrate with 'EEPROM used' flag for reporting correct capability to Engineer Mode/META and other tools
289 *
290 * 12 22 2010 eddie.chen
291 * [WCXRP00000218] [MT6620 Wi-Fi][Driver] Add auto rate window control in registry
292 * Remove controling auto rate from initial setting. The initial setting is defined by FW code.
293 *
294 * 12 15 2010 cp.wu
295 * NULL
296 * sync. with ALPS code by enabling interrupt just before leaving wlanAdapterStart()
297 *
298 * 12 08 2010 yuche.tsai
299 * [WCXRP00000245] [MT6620][Driver] Invitation & Provision Discovery Feature Check-in
300 * Change Param name for invitation connection.
301 *
302 * 12 07 2010 cm.chang
303 * [WCXRP00000238] MT6620 Wi-Fi][Driver][FW] Support regulation domain setting from NVRAM and supplicant
304 * 1. Country code is from NVRAM or supplicant
305 * 2. Change band definition in CMD/EVENT.
306 *
307 * 11 03 2010 cp.wu
308 * [WCXRP00000083] [MT5931][Driver][FW] Add necessary logic for MT5931 first connection
309 * 1) use 8 buffers for MT5931 which is equipped with less memory
310 * 2) modify MT5931 debug level to TRACE when download is successful
311 *
312 * 11 02 2010 cp.wu
313 * [WCXRP00000083] [MT5931][Driver][FW] Add necessary logic for MT5931 first connection
314 * for MT5931, adapter initialization is done *after* firmware is downloaded.
315 *
316 * 11 02 2010 cp.wu
317 * [WCXRP00000083] [MT5931][Driver][FW] Add necessary logic for MT5931 first connection
318 * correct MT5931 firmware download procedure:
319 * MT5931 will download firmware first then acquire LP-OWN
320 *
321 * 11 02 2010 cp.wu
322 * [WCXRP00000083] [MT5931][Driver][FW] Add necessary logic for MT5931 first connection
323 * 1) update MT5931 firmware encryption tool. (using 64-bytes unit)
324 * 2) update MT5931 firmware download procedure
325 *
326 * 11 01 2010 cp.wu
327 * [WCXRP00000056] [MT6620 Wi-Fi][Driver] NVRAM implementation with Version Check[WCXRP00000150] [MT6620 Wi-Fi][Driver] Add implementation for querying current TX rate from firmware auto rate module
328 * 1) Query link speed (TX rate) from firmware directly with buffering mechanism to reduce overhead
329 * 2) Remove CNM CH-RECOVER event handling
330 * 3) cfg read/write API renamed with kal prefix for unified naming rules.
331 *
332 * 11 01 2010 yarco.yang
333 * [WCXRP00000149] [MT6620 WI-Fi][Driver]Fine tune performance on MT6516 platform
334 * Add code to run WlanIST in SDIO callback.
335 *
336 * 10 27 2010 george.huang
337 * [WCXRP00000127] [MT6620 Wi-Fi][Driver] Add a registry to disable Beacon Timeout function for SQA test by using E1 EVB
338 * Support registry option for disable beacon lost detection.
339 *
340 * 10 26 2010 cp.wu
341 * [WCXRP00000056] [MT6620 Wi-Fi][Driver] NVRAM implementation with Version Check[WCXRP00000137] [MT6620 Wi-Fi] [FW] Support NIC capability query command
342 * 1) update NVRAM content template to ver 1.02
343 * 2) add compile option for querying NIC capability (default: off)
344 * 3) modify AIS 5GHz support to run-time option, which could be turned on by registry or NVRAM setting
345 * 4) correct auto-rate compiler error under linux (treat warning as error)
346 * 5) simplify usage of NVRAM and REG_INFO_T
347 * 6) add version checking between driver and firmware
348 *
349 * 10 26 2010 eddie.chen
350 * [WCXRP00000134] [MT6620 Wi-Fi][Driver] Add a registry to enable auto rate for SQA test by using E1 EVB
351 * Add auto rate parameter in registry.
352 *
353 * 10 25 2010 cp.wu
354 * [WCXRP00000056] [MT6620 Wi-Fi][Driver] NVRAM implementation with Version Check
355 * add option for enable/disable TX PWR gain adjustment (default: off)
356 *
357 * 10 18 2010 cp.wu
358 * [WCXRP00000117] [MT6620 Wi-Fi][Driver] Add logic for suspending driver when MT6620 is not responding anymore
359 * 1. when wlanAdapterStop() failed to send POWER CTRL command to firmware, do not poll for ready bit dis-assertion
360 * 2. shorten polling count for shorter response time
361 * 3. if bad I/O operation is detected during TX resource polling, then further operation is aborted as well
362 *
363 * 10 18 2010 cp.wu
364 * [WCXRP00000056] [MT6620 Wi-Fi][Driver] NVRAM implementation with Version Check[WCXRP00000086] [MT6620 Wi-Fi][Driver] The mac address is all zero at android
365 * complete implementation of Android NVRAM access
366 *
367 * 10 15 2010 cp.wu
368 * [WCXRP00000103] [MT6620 Wi-Fi][Driver] Driver crashed when using WZC to connect to AP#B with connection with AP#A
369 * bugfix: always reset pointer to IEbuf to zero when keeping scanning result for the connected AP
370 *
371 * 10 08 2010 cp.wu
372 * [WCXRP00000084] [MT6620 Wi-Fi][Driver][FW] Add fixed rate support for distance test
373 * adding fixed rate support for distance test. (from registry setting)
374 *
375 * 10 07 2010 cp.wu
376 * [WCXRP00000083] [MT5931][Driver][FW] Add necessary logic for MT5931 first connection
377 * add firmware download for MT5931.
378 *
379 * 10 06 2010 cp.wu
380 * [WCXRP00000052] [MT6620 Wi-Fi][Driver] Eliminate Linux Compile Warning
381 * divide a single function into 2 part to surpress a weird compiler warning from gcc-4.4.0
382 *
383 * 10 06 2010 cp.wu
384 * [WCXRP00000052] [MT6620 Wi-Fi][Driver] Eliminate Linux Compile Warning
385 * code reorganization to improve isolation between GLUE and CORE layers.
386 *
387 * 10 05 2010 cp.wu
388 * [WCXRP00000056] [MT6620 Wi-Fi][Driver] NVRAM implementation with Version Check
389 * load manufacture data when CFG_SUPPORT_NVRAM is set to 1
390 *
391 * 10 04 2010 cp.wu
392 * [WCXRP00000077] [MT6620 Wi-Fi][Driver][FW] Eliminate use of ENUM_NETWORK_TYPE_T and replaced by ENUM_NETWORK_TYPE_INDEX_T only
393 * remove ENUM_NETWORK_TYPE_T definitions
394 *
395 * 09 29 2010 wh.su
396 * [WCXRP00000072] [MT6620 Wi-Fi][Driver] Fix TKIP Counter Measure EAPoL callback register issue
397 * [MT6620 Wi-Fi][Driver] Fix TKIP Counter Measure EAPoL callback register issue.
398 *
399 * 09 24 2010 cp.wu
400 * [WCXRP00000052] [MT6620 Wi-Fi][Driver] Eliminate Linux Compile Warning
401 * eliminate unused variables which lead gcc to argue
402 *
403 * 09 24 2010 cp.wu
404 * [WCXRP00000057] [MT6620 Wi-Fi][Driver] Modify online scan to a run-time switchable feature
405 * Modify online scan as a run-time adjustable option (for Windows, in registry)
406 *
407 * 09 23 2010 cp.wu
408 * [WCXRP00000051] [MT6620 Wi-Fi][Driver] WHQL test fail in MAC address changed item
409 * use firmware reported mac address right after wlanAdapterStart() as permanent address
410 *
411 * 09 23 2010 cp.wu
412 * [WCXRP00000052] [MT6620 Wi-Fi][Driver] Eliminate Linux Compile Warning
413 * eliminate reference of CFG_RESPONSE_MAX_PKT_SIZE
414 *
415 * 09 21 2010 cp.wu
416 * [WCXRP00000053] [MT6620 Wi-Fi][Driver] Reset incomplete and might leads to BSOD when entering RF test with AIS associated
417 * Do a complete reset with STA-REC null checking for RF test re-entry
418 *
419 * 09 21 2010 kevin.huang
420 * [WCXRP00000052] [MT6620 Wi-Fi][Driver] Eliminate Linux Compile Warning
421 * Eliminate Linux Compile Warning
422 *
423 * 09 13 2010 cp.wu
424 * NULL
425 * acquire & release power control in oid handing wrapper.
426 *
427 * 09 09 2010 cp.wu
428 * NULL
429 * move IE to buffer head when the IE pointer is not pointed at head.
430 *
431 * 09 08 2010 cp.wu
432 * NULL
433 * use static memory pool for storing IEs of scanning result.
434 *
435 * 09 01 2010 cp.wu
436 * NULL
437 * HIFSYS Clock Source Workaround
438 *
439 * 09 01 2010 wh.su
440 * NULL
441 * adding the wapi support for integration test.
442 *
443 * 09 01 2010 cp.wu
444 * NULL
445 * move HIF CR initialization from where after sdioSetupCardFeature() to wlanAdapterStart()
446 *
447 * 08 30 2010 cp.wu
448 * NULL
449 * eliminate klockwork errors
450 *
451 * 08 26 2010 yuche.tsai
452 * NULL
453 * Add AT GO test configure mode under WinXP.
454 * Please enable 1. CFG_ENABLE_WIFI_DIRECT, 2. CFG_TEST_WIFI_DIRECT_GO, 3. CFG_SUPPORT_AAA
455 *
456 * 08 25 2010 george.huang
457 * NULL
458 * update OID/ registry control path for PM related settings
459 *
460 * 08 24 2010 cp.wu
461 * NULL
462 * 1) initialize variable for enabling short premable/short time slot.
463 * 2) add compile option for disabling online scan
464 *
465 * 08 13 2010 cp.wu
466 * NULL
467 * correction issue: desired phy type not initialized as ABGN mode.
468 *
469 * 08 12 2010 cp.wu
470 * NULL
471 * [AIS-FSM] honor registry setting for adhoc running mode. (A/B/G)
472 *
473 * 08 10 2010 cm.chang
474 * NULL
475 * Support EEPROM read/write in RF test mode
476 *
477 * 08 03 2010 cp.wu
478 * NULL
479 * surpress compilation warning.
480 *
481 * 08 03 2010 cp.wu
482 * NULL
483 * Centralize mgmt/system service procedures into independent calls.
484 *
485 * 07 30 2010 cp.wu
486 * NULL
487 * 1) BoW wrapper: use definitions instead of hard-coded constant for error code
488 * 2) AIS-FSM: eliminate use of desired RF parameters, use prTargetBssDesc instead
489 * 3) add handling for RX_PKT_DESTINATION_HOST_WITH_FORWARD for GO-broadcast frames
490 *
491 * 07 29 2010 cp.wu
492 * NULL
493 * eliminate u4FreqInKHz usage, combined into rConnections.ucAdHoc*
494 *
495 * 07 28 2010 cp.wu
496 * NULL
497 * 1) eliminate redundant variable eOPMode in prAdapter->rWlanInfo
498 * 2) change nicMediaStateChange() API prototype
499 *
500 * 07 21 2010 cp.wu
501 *
502 * 1) change BG_SCAN to ONLINE_SCAN for consistent term
503 * 2) only clear scanning result when scan is permitted to do
504 *
505 * 07 19 2010 cm.chang
506 *
507 * Set RLM parameters and enable CNM channel manager
508 *
509 * 07 19 2010 jeffrey.chang
510 *
511 * Linux port modification
512 *
513 * 07 13 2010 cp.wu
514 *
515 * [WPD00003833] [MT6620 and MT5931] Driver migration.
516 * Reduce unnecessary type casting
517 *
518 * 07 13 2010 cp.wu
519 *
520 * use multiple queues to keep 1x/MMPDU/CMD's strict order even when there is incoming 1x frames.
521 *
522 * 07 13 2010 cp.wu
523 *
524 * 1) MMPDUs are now sent to MT6620 by CMD queue for keeping strict order of 1X/MMPDU/CMD packets
525 * 2) integrate with qmGetFrameAction() for deciding which MMPDU/1X could pass checking for sending
526 * 2) enhance CMD_INFO_T descriptor number from 10 to 32 to avoid descriptor underflow under concurrent network operation
527 *
528 * 07 08 2010 cp.wu
529 *
530 * [WPD00003833] [MT6620 and MT5931] Driver migration - move to new repository.
531 *
532 * 07 05 2010 cp.wu
533 * [WPD00003833][MT6620 and MT5931] Driver migration
534 * 1) ignore RSN checking when RSN is not turned on.
535 * 2) set STA-REC deactivation callback as NULL
536 * 3) add variable initialization API based on PHY configuration
537 *
538 * 07 02 2010 cp.wu
539 * [WPD00003833][MT6620 and MT5931] Driver migration
540 * 1) for event packet, no need to fill RFB.
541 * 2) when wlanAdapterStart() failed, no need to initialize state machines
542 * 3) after Beacon/ProbeResp parsing, corresponding BSS_DESC_T should be marked as IE-parsed
543 *
544 * 07 01 2010 cm.chang
545 * [WPD00003841][LITE Driver] Migrate RLM/CNM to host driver
546 * Support sync command of STA_REC
547 *
548 * 07 01 2010 cp.wu
549 * [WPD00003833][MT6620 and MT5931] Driver migration
550 * add scan uninitialization procedure
551 *
552 * 06 25 2010 cp.wu
553 * [WPD00003833][MT6620 and MT5931] Driver migration
554 * add API in que_mgt to retrieve sta-rec index for security frames.
555 *
556 * 06 24 2010 cp.wu
557 * [WPD00003833][MT6620 and MT5931] Driver migration
558 * 802.1x and bluetooth-over-Wi-Fi security frames are now delievered to firmware via command path instead of data path.
559 *
560 * 06 23 2010 yarco.yang
561 * [WPD00003837][MT6620]Data Path Refine
562 * Merge g_arStaRec[] into adapter->arStaRec[]
563 *
564 * 06 21 2010 cp.wu
565 * [WPD00003833][MT6620 and MT5931] Driver migration
566 * initialize mbox & ais_fsm in wlanAdapterStart()
567 *
568 * 06 21 2010 cp.wu
569 * [WPD00003833][MT6620 and MT5931] Driver migration
570 * change MAC address updating logic.
571 *
572 * 06 21 2010 cp.wu
573 * [WPD00003833][MT6620 and MT5931] Driver migration
574 * simplify timer usage.
575 *
576 * 06 11 2010 cp.wu
577 * [WPD00003833][MT6620 and MT5931] Driver migration
578 * 1) migrate assoc.c.
579 * 2) add ucTxSeqNum for tracking frames which needs TX-DONE awareness
580 * 3) add configuration options for CNM_MEM and RSN modules
581 * 4) add data path for management frames
582 * 5) eliminate rPacketInfo of MSDU_INFO_T
583 *
584 * 06 10 2010 cp.wu
585 * [WPD00003833][MT6620 and MT5931] Driver migration
586 * 1) eliminate CFG_CMD_EVENT_VERSION_0_9
587 * 2) when disconnected, indicate nic directly (no event is needed)
588 *
589 * 06 08 2010 cp.wu
590 * [WPD00003833][MT6620 and MT5931] Driver migration
591 * cnm_timer has been migrated.
592 *
593 * 06 06 2010 kevin.huang
594 * [WPD00003832][MT6620 5931] Create driver base
595 * [MT6620 5931] Create driver base
596 *
597 * 05 28 2010 cp.wu
598 * [WPD00001943]Create WiFi test driver framework on WinXP
599 * disable interrupt then send power control command packet.
600 *
601 * 05 24 2010 cp.wu
602 * [WPD00001943]Create WiFi test driver framework on WinXP
603 * 1) when stopping adapter, wait til RDY bit has been cleaerd.
604 * 2) set TASK_OFFLOAD as driver-core OIDs
605 *
606 * 05 20 2010 cp.wu
607 * [WPD00001943]Create WiFi test driver framework on WinXP
608 * 1) integrate OID_GEN_NETWORK_LAYER_ADDRESSES with CMD_ID_SET_IP_ADDRESS
609 * 2) buffer statistics data for 2 seconds
610 * 3) use default value for adhoc parameters instead of 0
611 *
612 * 05 19 2010 cp.wu
613 * [WPD00001943]Create WiFi test driver framework on WinXP
614 * 1) do not take timeout mechanism for power mode oids
615 * 2) retrieve network type from connection status
616 * 3) after disassciation, set radio state to off
617 * 4) TCP option over IPv6 is supported
618 *
619 * 05 17 2010 cp.wu
620 * [WPD00001943]Create WiFi test driver framework on WinXP
621 * add CFG_STARTUP_DEBUG for debugging starting up issue.
622 *
623 * 05 17 2010 cp.wu
624 * [WPD00003831][MT6620 Wi-Fi] Add framework for Wi-Fi Direct support
625 * 1) add timeout handler mechanism for pending command packets
626 * 2) add p2p add/removal key
627 *
628 * 04 23 2010 cp.wu
629 * [WPD00001943]Create WiFi test driver framework on WinXP
630 * surpress compiler warning
631 *
632 * 04 20 2010 cp.wu
633 * [WPD00001943]Create WiFi test driver framework on WinXP
634 * roll-back to rev.60.
635 *
636 * 04 20 2010 cp.wu
637 * [WPD00001943]Create WiFi test driver framework on WinXP
638 * 1) remove redundant firmware image unloading
639 * 2) use compile-time macros to separate logic related to accquiring own
640 *
641 * 04 16 2010 cp.wu
642 * [WPD00001943]Create WiFi test driver framework on WinXP
643 * treat BUS access failure as kind of card removal.
644 *
645 * 04 14 2010 cp.wu
646 * [WPD00001943]Create WiFi test driver framework on WinXP
647 * always set fw-own before driver is unloaded.
648 *
649 * 04 13 2010 cp.wu
650 * [WPD00003823][MT6620 Wi-Fi] Add Bluetooth-over-Wi-Fi support
651 * add framework for BT-over-Wi-Fi support.
652 * * * 1) prPendingCmdInfo is replaced by queue for multiple handler capability
653 * * * 2) command sequence number is now increased atomically
654 * * * 3) private data could be hold and taken use for other purpose
655 *
656 * 04 07 2010 cp.wu
657 * [WPD00001943]Create WiFi test driver framework on WinXP
658 * finish non-glue layer access to glue variables
659 *
660 * 04 07 2010 cp.wu
661 * [WPD00001943]Create WiFi test driver framework on WinXP
662 * rWlanInfo should be placed at adapter rather than glue due to most operations
663 * are done in adapter layer.
664 *
665 * 04 06 2010 cp.wu
666 * [WPD00001943]Create WiFi test driver framework on WinXP
667 * ePowerCtrl is not necessary as a glue variable.
668 *
669 * 04 06 2010 jeffrey.chang
670 * [WPD00003826]Initial import for Linux port
671 * add timeout check in the kalOidComplete
672 *
673 * 04 06 2010 jeffrey.chang
674 * [WPD00003826]Initial import for Linux port
675 * improve none-glue code portability
676 *
677 * 04 06 2010 jeffrey.chang
678 * [WPD00003826]Initial import for Linux port
679 * improve none-glue code portability
680 *
681 * 04 06 2010 cp.wu
682 * [WPD00001943]Create WiFi test driver framework on WinXP
683 * code refine: fgTestMode should be at adapter rather than glue due to the device/fw is also involved
684 *
685 * 04 06 2010 cp.wu
686 * [WPD00001943]Create WiFi test driver framework on WinXP
687 * eliminate direct access for prGlueInfo->fgIsCardRemoved in non-glue layer
688 *
689 * 04 06 2010 cp.wu
690 * [WPD00001943]Create WiFi test driver framework on WinXP
691 * 1) for some OID, never do timeout expiration
692 * 2) add 2 kal API for later integration
693 *
694 * 04 06 2010 cp.wu
695 * [WPD00001943]Create WiFi test driver framework on WinXP
696 * 1) eliminate unused definitions
697 * 2) ready bit will be polled for limited iteration
698 *
699 * 04 06 2010 jeffrey.chang
700 * [WPD00003826]Initial import for Linux port
701 * kalOidComplete is not necessary in linux
702 *
703 * 04 01 2010 cp.wu
704 * [WPD00001943]Create WiFi test driver framework on WinXP
705 * change to use pass-in prRegInfo instead of accessing prGlueInfo directly
706 *
707 * 04 01 2010 cp.wu
708 * [WPD00001943]Create WiFi test driver framework on WinXP
709 * change to use WIFI_TCM_ALWAYS_ON as firmware image
710 *
711 * 04 01 2010 cp.wu
712 * [WPD00001943]Create WiFi test driver framework on WinXP
713 * .
714 *
715 * 03 31 2010 wh.su
716 * [WPD00003816][MT6620 Wi-Fi] Adding the security support
717 * modify the wapi related code for new driver's design.
718 *
719 * 03 30 2010 jeffrey.chang
720 * [WPD00003826]Initial import for Linux port
721 * adding none-glue code portability
722 *
723 * 03 30 2010 jeffrey.chang
724 * [WPD00003826]Initial import for Linux port
725 * adding non-glue code portability
726 *
727 * 03 29 2010 jeffrey.chang
728 * [WPD00003826]Initial import for Linux port
729 * improve non-glue code portability
730 *
731 * 03 25 2010 cp.wu
732 * [WPD00001943]Create WiFi test driver framework on WinXP
733 * firmware download load adress & start address are now configured from config.h
734 * due to the different configurations on FPGA and ASIC
735 *
736 * 03 24 2010 jeffrey.chang
737 * [WPD00003826]Initial import for Linux port
738 * [WPD00003826] Initial import for Linux port
739 * initial import for Linux port
740 *
741 * 03 24 2010 jeffrey.chang
742 * [WPD00003826]Initial import for Linux port
743 * initial import for Linux port
744 *
745 * 03 22 2010 cp.wu
746 * [WPD00001943]Create WiFi test driver framework on WinXP
747 * only send CMD_NIC_POWER_CTRL in wlanAdapterStop() when card is not removed and is not in D3 state
748 *
749 * 03 22 2010 cp.wu
750 * [WPD00001943]Create WiFi test driver framework on WinXP
751 * always send CMD_NIC_POWER_CTRL packet when nic is being halted
752 *
753 * 03 19 2010 cp.wu
754 * [WPD00001943]Create WiFi test driver framework on WinXP
755 * 1) add ACPI D0/D3 state switching support
756 * 2) use more formal way to handle interrupt when the status is retrieved from enhanced RX response
757 *
758* 03 12 2010 cp.wu
759 * [WPD00001943]Create WiFi test driver framework on WinXP
760 * add two option for ACK and ENCRYPTION for firmware download
761 *
762 * 03 11 2010 cp.wu
763 * [WPD00003821][BUG] Host driver stops processing RX packets from HIF RX0
764 * add RX starvation warning debug message controlled by CFG_HIF_RX_STARVATION_WARNING
765 *
766 * 03 08 2010 cp.wu
767 * [WPD00001943]Create WiFi test driver framework on WinXP
768 * 1) add another spin-lock to protect MsduInfoList due to it might be accessed by different thread.
769 * 2) change own-back acquiring procedure to wait for up to 16.67 seconds
770 *
771 * 03 03 2010 cp.wu
772 * [WPD00001943]Create WiFi test driver framework on WinXP
773 * when starting adapter, read local adminsitrated address from registry and send to firmware via CMD_BASIC_CONFIG.
774 *
775 * 03 02 2010 cp.wu
776 * [WPD00001943]Create WiFi test driver framework on WinXP
777 * 1) the use of prPendingOid revised, all accessing are now protected by spin lock
778 * 2) ensure wlanReleasePendingOid will clear all command queues
779 *
780 * 03 02 2010 cp.wu
781 * [WPD00001943]Create WiFi test driver framework on WinXP
782 * add mutex to avoid multiple access to qmTxQueue simultaneously.
783 *
784 * 03 01 2010 cp.wu
785 * [WPD00001943]Create WiFi test driver framework on WinXP
786 * add command/event definitions for initial states
787 *
788 * 02 24 2010 tehuang.liu
789 * [WPD00001943]Create WiFi test driver framework on WinXP
790 * Added code for QM_TEST_MODE
791 *
792 * 02 24 2010 cp.wu
793 * [WPD00001943]Create WiFi test driver framework on WinXP
794 * correct function name ..
795 *
796 * 02 24 2010 cp.wu
797 * [WPD00001943]Create WiFi test driver framework on WinXP
798 * separate wlanProcesQueuePacket() into 2 APIs upon request
799 *
800 * 02 23 2010 cp.wu
801 * [WPD00001943]Create WiFi test driver framework on WinXP
802 * add new API: wlanProcessQueuedPackets()
803 *
804 * 02 11 2010 cp.wu
805 * [WPD00001943]Create WiFi test driver framework on WinXP
806 * correct wlanAdapterStart
807 *
808 * 02 11 2010 cp.wu
809 * [WPD00001943]Create WiFi test driver framework on WinXP
810 * 1. add logic for firmware download
811 * 2. firmware image filename and start/load address are now retrieved from registry
812 *
813 * 02 10 2010 cp.wu
814 * [WPD00001943]Create WiFi test driver framework on WinXP
815 * implement host-side firmware download logic
816 *
817 * 02 10 2010 cp.wu
818 * [WPD00001943]Create WiFi test driver framework on WinXP
819 * 1) remove unused function in nic_rx.c [which has been handled in que_mgt.c]
820 * 2) firmware image length is now retrieved via NdisFileOpen
821 * 3) firmware image is not structured by (P_IMG_SEC_HDR_T) anymore
822 * 4) nicRxWaitResponse() revised
823 * 5) another set of TQ counter default value is added for fw-download state
824 * 6) Wi-Fi load address is now retrieved from registry too
825 *
826 * 02 09 2010 cp.wu
827 * [WPD00001943]Create WiFi test driver framework on WinXP
828 * 1. Permanent and current MAC address are now retrieved by CMD/EVENT packets instead of hard-coded address
829 * 2. follow MSDN defined behavior when associates to another AP
830 * 3. for firmware download, packet size could be up to 2048 bytes
831 *
832 * 02 08 2010 cp.wu
833 * [WPD00001943]Create WiFi test driver framework on WinXP
834 * prepare for implementing fw download logic
835 *
836 * 02 03 2010 cp.wu
837 * [WPD00001943]Create WiFi test driver framework on WinXP
838 * wlanoidSetFrequency is now implemented by RF test command.
839 *
840 * 02 03 2010 cp.wu
841 * [WPD00001943]Create WiFi test driver framework on WinXP
842 * QueryRssi is no longer w/o hardware access, it is now implemented by command/event handling loop
843 *
844 * 02 03 2010 cp.wu
845 * [WPD00001943]Create WiFi test driver framework on WinXP
846 * 1. clear prPendingCmdInfo properly
847 * 2. while allocating memory for cmdinfo, no need to add extra 4 bytes.
848 *
849 * 01 28 2010 cp.wu
850 * [WPD00001943]Create WiFi test driver framework on WinXP
851 * allow MCR read/write OIDs in RF test mode
852 *
853 * 01 27 2010 cp.wu
854 * [WPD00001943]Create WiFi test driver framework on WinXP
855 * 1) implement timeout mechanism when OID is pending for longer than 1 second
856 * 2) allow OID_802_11_CONFIGURATION to be executed when RF test mode is turned on
857 *
858 * 01 27 2010 cp.wu
859 * [WPD00001943]Create WiFi test driver framework on WinXP
860 * 1. eliminate improper variable in rHifInfo
861 * 2. block TX/ordinary OID when RF test mode is engaged
862 * 3. wait until firmware finish operation when entering into and leaving from RF test mode
863 * 4. correct some HAL implementation
864 *
865 * 01 26 2010 cp.wu
866 * [WPD00001943]Create WiFi test driver framework on WinXP
867 * Under WinXP with SDIO, use prGlueInfo->rHifInfo.pvInformationBuffer instead of prGlueInfo->pvInformationBuffer
868** \main\maintrunk.MT6620WiFiDriver_Prj\36 2009-12-10 16:54:36 GMT mtk02752
869** code clean
870** \main\maintrunk.MT6620WiFiDriver_Prj\35 2009-12-09 20:04:59 GMT mtk02752
871** only report as connected when CFG_HIF_EMULATION_TEST is set to 1
872** \main\maintrunk.MT6620WiFiDriver_Prj\34 2009-12-08 17:39:41 GMT mtk02752
873** wlanoidRftestQueryAutoTest could be executed without touching hardware
874** \main\maintrunk.MT6620WiFiDriver_Prj\33 2009-12-03 16:10:26 GMT mtk01461
875** Add debug message
876** \main\maintrunk.MT6620WiFiDriver_Prj\32 2009-12-02 22:05:33 GMT mtk02752
877** kalOidComplete() will decrease i4OidPendingCount
878** \main\maintrunk.MT6620WiFiDriver_Prj\31 2009-12-01 23:02:36 GMT mtk02752
879** remove unnecessary spinlock
880** \main\maintrunk.MT6620WiFiDriver_Prj\30 2009-12-01 22:50:38 GMT mtk02752
881** use TC4 for command, maintein i4OidPendingCount
882** \main\maintrunk.MT6620WiFiDriver_Prj\29 2009-11-27 12:45:34 GMT mtk02752
883** prCmdInfo should be freed when invoking wlanReleasePendingOid() to clear pending oid
884** \main\maintrunk.MT6620WiFiDriver_Prj\28 2009-11-24 19:55:51 GMT mtk02752
885** wlanSendPacket & wlanRetransmitOfPendingFrames is only used in old data path
886** \main\maintrunk.MT6620WiFiDriver_Prj\27 2009-11-23 17:59:55 GMT mtk02752
887** clear prPendingOID inside wlanSendCommand() when the OID didn't need to be replied.
888** \main\maintrunk.MT6620WiFiDriver_Prj\26 2009-11-23 14:45:29 GMT mtk02752
889** add another version of wlanSendCommand() for command-sending only without blocking for response
890** \main\maintrunk.MT6620WiFiDriver_Prj\25 2009-11-17 22:40:44 GMT mtk01084
891** \main\maintrunk.MT6620WiFiDriver_Prj\24 2009-11-11 10:14:56 GMT mtk01084
892** modify place to invoke wlanIst
893** \main\maintrunk.MT6620WiFiDriver_Prj\23 2009-10-30 18:17:07 GMT mtk01084
894** fix compiler warning
895** \main\maintrunk.MT6620WiFiDriver_Prj\22 2009-10-29 19:46:15 GMT mtk01084
896** invoke interrupt process routine
897** \main\maintrunk.MT6620WiFiDriver_Prj\21 2009-10-13 21:58:24 GMT mtk01084
898** modify for new HW architecture
899** \main\maintrunk.MT6620WiFiDriver_Prj\20 2009-09-09 17:26:01 GMT mtk01084
900** \main\maintrunk.MT6620WiFiDriver_Prj\19 2009-05-20 12:21:27 GMT mtk01461
901** Add SeqNum check when process Event Packet
902** \main\maintrunk.MT6620WiFiDriver_Prj\18 2009-05-19 10:38:44 GMT mtk01461
903** Add wlanReleasePendingOid() for mpReset() if there is a pending OID and no available TX resource to send it.
904** \main\maintrunk.MT6620WiFiDriver_Prj\17 2009-04-29 15:41:34 GMT mtk01461
905** Add handle of EVENT of CMD Result in wlanSendCommand()
906** \main\maintrunk.MT6620WiFiDriver_Prj\16 2009-04-22 09:11:23 GMT mtk01461
907** Fix wlanSendCommand() for Driver Domain CR
908** \main\maintrunk.MT6620WiFiDriver_Prj\15 2009-04-21 09:33:56 GMT mtk01461
909** Update wlanSendCommand() for Driver Domain Response and handle Event Packet, wlanQuery/SetInformation() for enqueue CMD_INFO_T
910** \main\maintrunk.MT6620WiFiDriver_Prj\14 2009-04-17 20:00:08 GMT mtk01461
911** Update wlanImageSectionDownload for optimized CMD process
912** \main\maintrunk.MT6620WiFiDriver_Prj\13 2009-04-14 20:50:51 GMT mtk01426
913** Fixed compile error
914** \main\maintrunk.MT6620WiFiDriver_Prj\12 2009-04-13 16:38:40 GMT mtk01084
915** add wifi start function
916** \main\maintrunk.MT6620WiFiDriver_Prj\11 2009-04-13 14:26:44 GMT mtk01084
917** modify a parameter about FW download length
918** \main\maintrunk.MT6620WiFiDriver_Prj\10 2009-04-10 21:53:42 GMT mtk01461
919** Update wlanSendCommand()
920** \main\maintrunk.MT6620WiFiDriver_Prj\9 2009-04-08 16:51:04 GMT mtk01084
921** Update for the image download part
922** \main\maintrunk.MT6620WiFiDriver_Prj\8 2009-04-01 10:32:47 GMT mtk01461
923** Add wlanSendLeftClusteredFrames() for SDIO_TX_ENHANCE
924** \main\maintrunk.MT6620WiFiDriver_Prj\7 2009-03-23 21:44:13 GMT mtk01461
925** Refine TC assignment for WmmAssoc flag
926** \main\maintrunk.MT6620WiFiDriver_Prj\6 2009-03-23 16:51:57 GMT mtk01084
927** modify the input argument of caller to RECLAIM_POWER_CONTROL_TO_PM()
928** \main\maintrunk.MT6620WiFiDriver_Prj\5 2009-03-23 00:27:13 GMT mtk01461
929** Add reference code of FW Image Download
930** \main\maintrunk.MT6620WiFiDriver_Prj\4 2009-03-19 18:32:37 GMT mtk01084
931** update for basic power management functions
932** \main\maintrunk.MT6620WiFiDriver_Prj\3 2009-03-16 09:09:08 GMT mtk01461
933** Update TX PATH API
934** \main\maintrunk.MT6620WiFiDriver_Prj\2 2009-03-10 16:28:45 GMT mtk01426
935** Init develop
936**
937*/
938
939/*******************************************************************************
940* C O M P I L E R F L A G S
941********************************************************************************
942*/
943
944/*******************************************************************************
945* E X T E R N A L R E F E R E N C E S
946********************************************************************************
947*/
948#include "precomp.h"
949#include "mgmt/ais_fsm.h"
950
951/*******************************************************************************
952* C O N S T A N T S
953********************************************************************************
954*/
955/* 6.1.1.2 Interpretation of priority parameter in MAC service primitives */
956/* Static convert the Priority Parameter/TID(User Priority/TS Identifier) to Traffic Class */
957const UINT_8 aucPriorityParam2TC[] = {
958 TC1_INDEX,
959 TC0_INDEX,
960 TC0_INDEX,
961 TC1_INDEX,
962 TC2_INDEX,
963 TC2_INDEX,
964 TC3_INDEX,
965 TC3_INDEX
966};
967
968#if QM_TEST_MODE
969extern QUE_MGT_T g_rQM;
970#endif
971/*******************************************************************************
972* D A T A T Y P E S
973********************************************************************************
974*/
975typedef struct _CODE_MAPPING_T {
976 UINT_32 u4RegisterValue;
977 INT_32 i4TxpowerOffset;
978} CODE_MAPPING_T, *P_CODE_MAPPING_T;
979
980/*******************************************************************************
981* P U B L I C D A T A
982********************************************************************************
983*/
984BOOLEAN fgIsBusAccessFailed = FALSE;
985
986/*******************************************************************************
987* P R I V A T E D A T A
988********************************************************************************
989*/
990
991
992/*******************************************************************************
993* M A C R O S
994********************************************************************************
995*/
996#define SIGNED_EXTEND(n, _sValue) \
997 (((_sValue) & BIT((n)-1)) ? ((_sValue) | BITS(n,31)) : \
998 ((_sValue) & ~BITS(n,31)))
999
1000// TODO: Check
1001/* OID set handlers without the need to access HW register */
1002PFN_OID_HANDLER_FUNC apfnOidSetHandlerWOHwAccess[] = {
1003 wlanoidSetChannel,
1004 wlanoidSetBeaconInterval,
1005 wlanoidSetAtimWindow,
1006 wlanoidSetFrequency,
1007};
1008
1009// TODO: Check
1010/* OID query handlers without the need to access HW register */
1011PFN_OID_HANDLER_FUNC apfnOidQueryHandlerWOHwAccess[] = {
1012 wlanoidQueryBssid,
1013 wlanoidQuerySsid,
1014 wlanoidQueryInfrastructureMode,
1015 wlanoidQueryAuthMode,
1016 wlanoidQueryEncryptionStatus,
1017 wlanoidQueryPmkid,
1018 wlanoidQueryNetworkTypeInUse,
1019 wlanoidQueryBssidList,
1020 wlanoidQueryAcpiDevicePowerState,
1021 wlanoidQuerySupportedRates,
1022 wlanoidQueryDesiredRates,
1023 wlanoidQuery802dot11PowerSaveProfile,
1024 wlanoidQueryBeaconInterval,
1025 wlanoidQueryAtimWindow,
1026 wlanoidQueryFrequency,
1027};
1028
1029/* OID set handlers allowed in RF test mode */
1030PFN_OID_HANDLER_FUNC apfnOidSetHandlerAllowedInRFTest[] = {
1031 wlanoidRftestSetTestMode,
1032 wlanoidRftestSetAbortTestMode,
1033 wlanoidRftestSetAutoTest,
1034 wlanoidSetMcrWrite,
1035 wlanoidSetEepromWrite
1036};
1037
1038/* OID query handlers allowed in RF test mode */
1039PFN_OID_HANDLER_FUNC apfnOidQueryHandlerAllowedInRFTest[] = {
1040 wlanoidRftestQueryAutoTest,
1041 wlanoidQueryMcrRead,
1042 wlanoidQueryEepromRead
1043}
1044;
1045
1046PFN_OID_HANDLER_FUNC apfnOidWOTimeoutCheck[] = {
1047 wlanoidRftestSetTestMode,
1048 wlanoidRftestSetAbortTestMode,
1049 wlanoidSetAcpiDevicePowerState,
1050};
1051
1052
1053/*******************************************************************************
1054* M A C R O S
1055********************************************************************************
1056*/
1057
1058/*******************************************************************************
1059* F U N C T I O N D E C L A R A T I O N S
1060********************************************************************************
1061*/
1062
1063/*******************************************************************************
1064* F U N C T I O N S
1065********************************************************************************
1066*/
1067#if 0 /* no use */
1068/*----------------------------------------------------------------------------*/
1069/*!
1070* \brief This is a private routine, which is used to check if HW access is needed
1071* for the OID query/ set handlers.
1072*
1073* \param[IN] pfnOidHandler Pointer to the OID handler.
1074* \param[IN] fgSetInfo It is a Set information handler.
1075*
1076* \retval TRUE This function needs HW access
1077* \retval FALSE This function does not need HW access
1078*/
1079/*----------------------------------------------------------------------------*/
1080BOOLEAN
1081wlanIsHandlerNeedHwAccess (
1082 IN PFN_OID_HANDLER_FUNC pfnOidHandler,
1083 IN BOOLEAN fgSetInfo
1084 )
1085{
1086 PFN_OID_HANDLER_FUNC* apfnOidHandlerWOHwAccess;
1087 UINT_32 i;
1088 UINT_32 u4NumOfElem;
1089
1090 if (fgSetInfo) {
1091 apfnOidHandlerWOHwAccess = apfnOidSetHandlerWOHwAccess;
1092 u4NumOfElem = sizeof(apfnOidSetHandlerWOHwAccess) / sizeof(PFN_OID_HANDLER_FUNC);
1093 }
1094 else {
1095 apfnOidHandlerWOHwAccess = apfnOidQueryHandlerWOHwAccess;
1096 u4NumOfElem = sizeof(apfnOidQueryHandlerWOHwAccess) / sizeof(PFN_OID_HANDLER_FUNC);
1097 }
1098
1099 for (i = 0; i < u4NumOfElem; i++) {
1100 if (apfnOidHandlerWOHwAccess[i] == pfnOidHandler) {
1101 return FALSE;
1102 }
1103 }
1104
1105 return TRUE;
1106} /* wlanIsHandlerNeedHwAccess */
1107
1108
1109/*----------------------------------------------------------------------------*/
1110/*!
1111* \brief This routine is called to set flag for later handling card
1112* ejected event.
1113*
1114* \param[in] prAdapter Pointer to the Adapter structure.
1115*
1116* \return (none)
1117*
1118* \note When surprised removal happens, Glue layer should invoke this
1119* function to notify WPDD not to do any hw access.
1120*/
1121/*----------------------------------------------------------------------------*/
1122VOID
1123wlanCardEjected (
1124 IN P_ADAPTER_T prAdapter
1125 )
1126{
1127 DEBUGFUNC("wlanCardEjected");
1128 //INITLOG(("\n"));
1129
1130 ASSERT(prAdapter);
1131
1132 /* mark that the card is being ejected, NDIS will shut us down soon */
1133 nicTxRelease(prAdapter);
1134
1135} /* wlanCardEjected */
1136#endif
1137
1138
1139/*----------------------------------------------------------------------------*/
1140/*!
1141* \brief Create adapter object
1142*
1143* \param prAdapter This routine is call to allocate the driver software objects.
1144* If fails, return NULL.
1145* \retval NULL If it fails, NULL is returned.
1146* \retval NOT NULL If the adapter was initialized successfully.
1147*/
1148/*----------------------------------------------------------------------------*/
1149P_ADAPTER_T
1150wlanAdapterCreate (
1151 IN P_GLUE_INFO_T prGlueInfo
1152 )
1153{
1154 P_ADAPTER_T prAdpater = (P_ADAPTER_T)NULL;
1155
1156 DEBUGFUNC("wlanAdapterCreate");
1157
1158 do {
1159 prAdpater = (P_ADAPTER_T) kalMemAlloc(sizeof(ADAPTER_T), VIR_MEM_TYPE);
1160
1161 if (!prAdpater) {
1162 DBGLOG(INIT, ERROR, ("Allocate ADAPTER memory ==> FAILED\n"));
1163 break;
1164 }
1165
1166#if QM_TEST_MODE
1167 g_rQM.prAdapter = prAdpater;
1168#endif
1169 kalMemZero(prAdpater, sizeof(ADAPTER_T));
1170 prAdpater->prGlueInfo = prGlueInfo;
1171
1172 } while(FALSE);
1173
1174 return prAdpater;
1175} /* wlanAdapterCreate */
1176
1177
1178/*----------------------------------------------------------------------------*/
1179/*!
1180* \brief Destroy adapter object
1181*
1182* \param prAdapter This routine is call to destroy the driver software objects.
1183* If fails, return NULL.
1184* \return (none)
1185*/
1186/*----------------------------------------------------------------------------*/
1187VOID
1188wlanAdapterDestroy (
1189 IN P_ADAPTER_T prAdapter
1190 )
1191{
1192
1193 if (!prAdapter) {
1194 return;
1195 }
1196
1197 kalMemFree(prAdapter, VIR_MEM_TYPE, sizeof(ADAPTER_T));
1198
1199 return;
1200}
1201
1202/*----------------------------------------------------------------------------*/
1203/*!
1204* \brief Initialize the adapter. The sequence is
1205* 1. Disable interrupt
1206* 2. Read adapter configuration from EEPROM and registry, verify chip ID.
1207* 3. Create NIC Tx/Rx resource.
1208* 4. Initialize the chip
1209* 5. Initialize the protocol
1210* 6. Enable Interrupt
1211*
1212* \param prAdapter Pointer of Adapter Data Structure
1213*
1214* \retval WLAN_STATUS_SUCCESS: Success
1215* \retval WLAN_STATUS_FAILURE: Failed
1216*/
1217/*----------------------------------------------------------------------------*/
1218WLAN_STATUS
1219wlanAdapterStart (
1220 IN P_ADAPTER_T prAdapter,
1221 IN P_REG_INFO_T prRegInfo,
1222 IN PVOID pvFwImageMapFile,
1223 IN UINT_32 u4FwImageFileLength
1224 )
1225{
1226 extern BOOLEAN fgIsResetting;
1227 WLAN_STATUS u4Status = WLAN_STATUS_SUCCESS;
1228 UINT_32 i, u4Value = 0;
1229 UINT_32 u4WHISR = 0;
1230 UINT_8 aucTxCount[8];
1231#if CFG_ENABLE_FW_DOWNLOAD
1232 UINT_32 u4FwLoadAddr, u4ImgSecSize;
1233 #if CFG_ENABLE_FW_DIVIDED_DOWNLOAD
1234 UINT_32 j;
1235 P_FIRMWARE_DIVIDED_DOWNLOAD_T prFwHead;
1236 BOOLEAN fgValidHead;
1237 const UINT_32 u4CRCOffset = offsetof(FIRMWARE_DIVIDED_DOWNLOAD_T, u4NumOfEntries);
1238 #endif
1239#endif
1240#if (defined(MT5931) && (!CFG_SUPPORT_BCM_BWCS))
1241 PARAM_PTA_IPC_T rBwcsPta;
1242 UINT_32 u4SetInfoLen;
1243#endif
1244
4b9e9796
S
1245 enum Adapter_Start_Fail_Reason {
1246 ALLOC_ADAPTER_MEM_FAIL,
1247 DRIVER_OWN_FAIL,
1248 INIT_ADAPTER_FAIL,
1249 RAM_CODE_DOWNLOAD_FAIL,
1250 WAIT_FIRMWARE_READY_FAIL,
1251 FAIL_REASON_MAX
1252 } eFailReason;
6fa3eb70
S
1253 ASSERT(prAdapter);
1254
1255 DEBUGFUNC("wlanAdapterStart");
1256
4b9e9796 1257 eFailReason = FAIL_REASON_MAX;
6fa3eb70
S
1258 //4 <0> Reset variables in ADAPTER_T
1259 prAdapter->fgIsFwOwn = TRUE;
1260 prAdapter->fgIsEnterD3ReqIssued = FALSE;
1261
1262 QUEUE_INITIALIZE(&(prAdapter->rPendingCmdQueue));
1263
1264 /* Initialize rWlanInfo */
1265 kalMemSet(&(prAdapter->rWlanInfo), 0, sizeof(WLAN_INFO_T));
1266
1267 //4 <0.1> reset fgIsBusAccessFailed
1268 fgIsBusAccessFailed = FALSE;
1269
1270 do {
1271 if ( (u4Status = nicAllocateAdapterMemory(prAdapter)) != WLAN_STATUS_SUCCESS ) {
1272 DBGLOG(INIT, ERROR, ("nicAllocateAdapterMemory Error!\n"));
1273 u4Status = WLAN_STATUS_FAILURE;
4b9e9796 1274 eFailReason = ALLOC_ADAPTER_MEM_FAIL;
6fa3eb70
S
1275 break;
1276 }
1277
1278 prAdapter->u4OsPacketFilter = PARAM_PACKET_FILTER_SUPPORTED;
1279
1280#if defined(MT6620) || defined(MT6628)
1281 DBGLOG(INIT, TRACE, ("wlanAdapterStart(): Acquiring LP-OWN %d\n", fgIsResetting));
1282 ACQUIRE_POWER_CONTROL_FROM_PM(prAdapter);
1283
1284 #if !CFG_ENABLE_FULL_PM
1285 nicpmSetDriverOwn(prAdapter);
1286 #endif
1287
1288 if(prAdapter->fgIsFwOwn == TRUE) {
1289 DBGLOG(INIT, ERROR, ("nicpmSetDriverOwn() failed!\n"));
1290 u4Status = WLAN_STATUS_FAILURE;
4b9e9796 1291 eFailReason = DRIVER_OWN_FAIL;
6fa3eb70
S
1292 break;
1293 }
1294
1295 //4 <1> Initialize the Adapter
1296 if ( (u4Status = nicInitializeAdapter(prAdapter)) != WLAN_STATUS_SUCCESS ) {
1297 DBGLOG(INIT, ERROR, ("nicInitializeAdapter failed!\n"));
1298 u4Status = WLAN_STATUS_FAILURE;
4b9e9796 1299 eFailReason = INIT_ADAPTER_FAIL;
6fa3eb70
S
1300 break;
1301 }
1302#endif
1303
1304 /* init wake lock before interrupt enable and tx thread */
1305 KAL_WAKE_LOCK_INIT(prAdapter, &prAdapter->rTxThreadWakeLock, "WLAN TX THREAD");
1306
1307 //4 <2> Initialize System Service (MGMT Memory pool and STA_REC)
1308 nicInitSystemService(prAdapter);
1309
1310 //4 <3> Initialize Tx
1311 nicTxInitialize(prAdapter);
1312 wlanDefTxPowerCfg(prAdapter);
1313
1314 //4 <4> Initialize Rx
1315 nicRxInitialize(prAdapter);
1316
1317#if CFG_ENABLE_FW_DOWNLOAD
1318 #if defined(MT6620) || defined(MT6628)
1319 if (pvFwImageMapFile) {
1320 /* 1. disable interrupt, download is done by polling mode only */
1321 nicDisableInterrupt(prAdapter);
1322
1323 /* 2. Initialize Tx Resource to fw download state */
1324 nicTxInitResetResource(prAdapter);
1325
1326 /* 3. FW download here */
1327 u4FwLoadAddr = prRegInfo->u4LoadAddress;
1328
1329 #if CFG_ENABLE_FW_DIVIDED_DOWNLOAD
1330 // 3a. parse file header for decision of divided firmware download or not
1331 prFwHead = (P_FIRMWARE_DIVIDED_DOWNLOAD_T)pvFwImageMapFile;
1332
1333 if(prFwHead->u4Signature == MTK_WIFI_SIGNATURE &&
1334 prFwHead->u4CRC == wlanCRC32((PUINT_8)pvFwImageMapFile + u4CRCOffset, u4FwImageFileLength - u4CRCOffset)) {
1335 fgValidHead = TRUE;
1336 }
1337 else {
1338 fgValidHead = FALSE;
1339 }
1340
1341 /* 3b. engage divided firmware downloading */
1342 if(fgValidHead == TRUE) {
1343 DBGLOG(INIT, TRACE, ("wlanAdapterStart(): fgValidHead == TRUE\n"));
1344
1345 for(i = 0 ; i < prFwHead->u4NumOfEntries ; i++) {
1346
1347#if CFG_START_ADDRESS_IS_1ST_SECTION_ADDR
1348 if (i==0) {
1349 prRegInfo->u4StartAddress = prFwHead->arSection[i].u4DestAddr;
1350 DBGLOG(INIT, TRACE, ("wlanAdapterStart(): FW start address 0x%08x\n", prRegInfo->u4StartAddress));
1351 }
1352#endif
1353
1354 #if CFG_ENABLE_FW_DOWNLOAD_AGGREGATION
1355 if(wlanImageSectionDownloadAggregated(prAdapter,
1356 prFwHead->arSection[i].u4DestAddr,
1357 prFwHead->arSection[i].u4Length,
1358 (PUINT_8)pvFwImageMapFile + prFwHead->arSection[i].u4Offset) != WLAN_STATUS_SUCCESS) {
1359 DBGLOG(INIT, ERROR, ("Firmware scatter download failed!\n"));
1360 u4Status = WLAN_STATUS_FAILURE;
1361 }
1362 #else
1363 for(j = 0 ; j < prFwHead->arSection[i].u4Length ; j += CMD_PKT_SIZE_FOR_IMAGE) {
1364 if(j + CMD_PKT_SIZE_FOR_IMAGE < prFwHead->arSection[i].u4Length)
1365 u4ImgSecSize = CMD_PKT_SIZE_FOR_IMAGE;
1366 else
1367 u4ImgSecSize = prFwHead->arSection[i].u4Length - j;
1368
1369 if(wlanImageSectionDownload(prAdapter,
1370 prFwHead->arSection[i].u4DestAddr + j,
1371 u4ImgSecSize,
1372 (PUINT_8)pvFwImageMapFile + prFwHead->arSection[i].u4Offset + j) != WLAN_STATUS_SUCCESS) {
1373 DBGLOG(INIT, ERROR, ("Firmware scatter download failed %d!\n", (int)i));
1374 u4Status = WLAN_STATUS_FAILURE;
1375 break;
1376 }
1377 }
1378 #endif
1379
1380 /* escape from loop if any pending error occurs */
1381 if(u4Status == WLAN_STATUS_FAILURE) {
1382 break;
1383 }
1384 }
1385 }
1386 else
1387 #endif
1388 #if CFG_ENABLE_FW_DOWNLOAD_AGGREGATION
1389 if(wlanImageSectionDownloadAggregated(prAdapter,
1390 u4FwLoadAddr,
1391 u4FwImageFileLength,
1392 (PUINT_8)pvFwImageMapFile) != WLAN_STATUS_SUCCESS) {
1393 DBGLOG(INIT, ERROR, ("Firmware scatter download failed!\n"));
1394 u4Status = WLAN_STATUS_FAILURE;
1395 }
1396 #else
1397 for (i = 0; i < u4FwImageFileLength ; i += CMD_PKT_SIZE_FOR_IMAGE) {
1398 if(i + CMD_PKT_SIZE_FOR_IMAGE < u4FwImageFileLength)
1399 u4ImgSecSize = CMD_PKT_SIZE_FOR_IMAGE;
1400 else
1401 u4ImgSecSize = u4FwImageFileLength - i;
1402
1403 if(wlanImageSectionDownload(prAdapter,
1404 u4FwLoadAddr + i,
1405 u4ImgSecSize,
1406 (PUINT_8)pvFwImageMapFile + i) != WLAN_STATUS_SUCCESS) {
1407 DBGLOG(INIT, ERROR, ("Firmware scatter download failed!\n"));
1408 u4Status = WLAN_STATUS_FAILURE;
1409 break;
1410 }
1411 }
1412 #endif
1413
1414 if(u4Status != WLAN_STATUS_SUCCESS) {
4b9e9796 1415 eFailReason = RAM_CODE_DOWNLOAD_FAIL;
6fa3eb70
S
1416 break;
1417 }
1418
1419 #if !CFG_ENABLE_FW_DOWNLOAD_ACK
1420 // Send INIT_CMD_ID_QUERY_PENDING_ERROR command and wait for response
1421 if(wlanImageQueryStatus(prAdapter) != WLAN_STATUS_SUCCESS) {
1422 DBGLOG(INIT, ERROR, ("Firmware download failed!\n"));
1423 u4Status = WLAN_STATUS_FAILURE;
1424 break;
1425 }
1426 #endif
1427 }
1428 else {
1429 DBGLOG(INIT, ERROR, ("No Firmware found!\n"));
1430 u4Status = WLAN_STATUS_FAILURE;
4b9e9796 1431 eFailReason = RAM_CODE_DOWNLOAD_FAIL;
6fa3eb70
S
1432 break;
1433 }
1434
1435 /* 4. send Wi-Fi Start command */
1436 printk("<wifi> send Wi-Fi Start command\n");
1437 #if CFG_OVERRIDE_FW_START_ADDRESS
1438 wlanConfigWifiFunc(prAdapter,
1439 TRUE,
1440 prRegInfo->u4StartAddress);
1441 #else
1442 wlanConfigWifiFunc(prAdapter,
1443 FALSE,
1444 0);
1445 #endif
1446 #elif defined(MT5931)
1447 if (pvFwImageMapFile) {
1448 DBGLOG(INIT, TRACE, ("Download Address: 0x%08X\n", prRegInfo->u4LoadAddress));
1449 DBGLOG(INIT, TRACE, ("Firmware Length: 0x%08X\n", u4FwImageFileLength));
1450
1451 do {
1452#if CFG_SUPPORT_WHOLE_CHIP_RESET
1453#define RESET_RDY_INTERVAL (120)
1454
1455 /* 1.0 whole-chip reset except HIFSYS */
1456 HAL_MCR_WR(prAdapter, MCR_WMCSR, WMCSR_CHIP_RST);
1457 HAL_MCR_WR(prAdapter, MCR_WMCSR, 0);
1458
1459 /* 1.0.1 delay for EEIF ready */
1460 kalMsleep(RESET_RDY_INTERVAL);
1461#endif
1462
1463 /* 1.1 wait for INIT_RDY */
1464 i = 0;
1465 while(1) {
1466 HAL_MCR_RD(prAdapter, MCR_WMCSR, &u4Value);
1467
1468 if (u4Value & WMCSR_INI_RDY) {
1469 DBGLOG(INIT, TRACE, ("INIT-RDY detected\n"));
1470 break;
1471 }
1472 else if(kalIsCardRemoved(prAdapter->prGlueInfo) == TRUE
1473 || fgIsBusAccessFailed == TRUE) {
1474 u4Status = WLAN_STATUS_FAILURE;
1475 break;
1476 }
1477 else if(i >= CFG_RESPONSE_POLLING_TIMEOUT) {
1478 DBGLOG(INIT, ERROR, ("Waiting for Init Ready bit: Timeout\n"));
1479 u4Status = WLAN_STATUS_FAILURE;
1480 break;
1481 }
1482 else {
1483 i++;
1484 kalMsleep(10);
1485 }
1486 }
1487
1488 if(u4Status != WLAN_STATUS_SUCCESS) {
1489 break;
1490 }
1491
1492 /* 1.2 set KSEL/FLEN */
1493 HAL_MCR_WR(prAdapter, MCR_FWCFG, u4FwImageFileLength >> 6);
1494
1495 /* 1.3 enable FWDL_EN */
1496 HAL_MCR_WR(prAdapter, MCR_WMCSR, WMCSR_FWDLEN);
1497
1498 /* 1.4 wait for PLL_RDY */
1499 i = 0;
1500 while(1) {
1501 HAL_MCR_RD(prAdapter, MCR_WMCSR, &u4Value);
1502
1503 if (u4Value & WMCSR_PLLRDY) {
1504 DBGLOG(INIT, TRACE, ("PLL-RDY detected\n"));
1505 break;
1506 }
1507 else if(kalIsCardRemoved(prAdapter->prGlueInfo) == TRUE
1508 || fgIsBusAccessFailed == TRUE) {
1509 u4Status = WLAN_STATUS_FAILURE;
1510 break;
1511 }
1512 else if(i >= CFG_RESPONSE_POLLING_TIMEOUT) {
1513 DBGLOG(INIT, ERROR, ("Waiting for PLL Ready bit: Timeout\n"));
1514 u4Status = WLAN_STATUS_FAILURE;
1515 break;
1516 }
1517 else {
1518 i++;
1519 kalMsleep(10);
1520 }
1521 }
1522
1523 if(u4Status != WLAN_STATUS_SUCCESS) {
1524 break;
1525 }
1526
1527 /* 2.1 turn on HIFSYS firmware download mode */
1528 HAL_MCR_WR(prAdapter, MCR_FWDLSR, FWDLSR_FWDL_MODE);
1529
1530 /* 2.2 set starting address */
1531 u4FwLoadAddr = prRegInfo->u4LoadAddress;
1532 HAL_MCR_WR(prAdapter, MCR_FWDLDSAR, u4FwLoadAddr);
1533
1534 /* 3. upload firmware */
1535 for (i = 0; i < u4FwImageFileLength ; i += CMD_PKT_SIZE_FOR_IMAGE) {
1536 if(i + CMD_PKT_SIZE_FOR_IMAGE < u4FwImageFileLength)
1537 u4ImgSecSize = CMD_PKT_SIZE_FOR_IMAGE;
1538 else
1539 u4ImgSecSize = u4FwImageFileLength - i;
1540
1541 if(wlanImageSectionDownload(prAdapter,
1542 u4FwLoadAddr + i,
1543 u4ImgSecSize,
1544 (PUINT_8)pvFwImageMapFile + i) != WLAN_STATUS_SUCCESS) {
1545 DBGLOG(INIT, ERROR, ("Firmware scatter download failed!\n"));
1546 u4Status = WLAN_STATUS_FAILURE;
1547 break;
1548 }
1549 }
1550
1551 if(u4Status != WLAN_STATUS_SUCCESS) {
1552 break;
1553 }
1554
1555 /* 4.1 poll FWDL_OK & FWDL_FAIL bits */
1556 i = 0;
1557 while(1) {
1558 HAL_MCR_RD(prAdapter, MCR_WMCSR, &u4Value);
1559
1560 if (u4Value & WMCSR_DL_OK) {
1561 DBGLOG(INIT, TRACE, ("DL_OK detected\n"));
1562 break;
1563 }
1564 else if(kalIsCardRemoved(prAdapter->prGlueInfo) == TRUE
1565 || fgIsBusAccessFailed == TRUE
1566 || (u4Value & WMCSR_DL_FAIL)) {
1567 DBGLOG(INIT, ERROR, ("DL_FAIL detected: 0x%08X\n", u4Value));
1568 u4Status = WLAN_STATUS_FAILURE;
1569 break;
1570 }
1571 else if(i >= CFG_RESPONSE_POLLING_TIMEOUT) {
1572 DBGLOG(INIT, ERROR, ("Waiting for DL_OK/DL_FAIL bit: Timeout\n"));
1573 u4Status = WLAN_STATUS_FAILURE;
1574 break;
1575 }
1576 else {
1577 i++;
1578 kalMsleep(10);
1579 }
1580 }
1581
1582 if(u4Status != WLAN_STATUS_SUCCESS) {
1583 break;
1584 }
1585
1586 /* 4.2 turn off HIFSYS download mode */
1587 HAL_MCR_WR(prAdapter, MCR_FWDLSR, 0);
1588
1589 } while (FALSE);
1590
1591 if(u4Status != WLAN_STATUS_SUCCESS) {
1592 break;
1593 }
1594
1595 /* 5. disable interrupt */
1596 nicDisableInterrupt(prAdapter);
1597 }
1598 else {
1599 DBGLOG(INIT, ERROR, ("No Firmware found!\n"));
1600 u4Status = WLAN_STATUS_FAILURE;
1601 break;
1602 }
1603 #endif
1604#endif
1605
1606 DBGLOG(INIT, TRACE, ("wlanAdapterStart(): Waiting for Ready bit..\n"));
1607 //4 <5> check Wi-Fi FW asserts ready bit
1608 i = 0;
1609 while(1) {
1610 HAL_MCR_RD(prAdapter, MCR_WCIR, &u4Value);
1611
1612 if (u4Value & WCIR_WLAN_READY) {
1613 DBGLOG(INIT, TRACE, ("Ready bit asserted\n"));
1614 break;
1615 }
1616 else if(kalIsCardRemoved(prAdapter->prGlueInfo) == TRUE
1617 || fgIsBusAccessFailed == TRUE) {
1618 u4Status = WLAN_STATUS_FAILURE;
4b9e9796 1619 eFailReason = WAIT_FIRMWARE_READY_FAIL;
6fa3eb70
S
1620 break;
1621 }
1622 else if(i >= CFG_RESPONSE_POLLING_TIMEOUT) {
1623 UINT_32 u4MailBox0;
1624
1625 nicGetMailbox(prAdapter, 0, &u4MailBox0);
1626 DBGLOG(INIT, ERROR, ("Waiting for Ready bit: Timeout, ID=%u\n",
1627 (u4MailBox0 & 0x0000FFFF)));
1628 u4Status = WLAN_STATUS_FAILURE;
4b9e9796 1629 eFailReason = WAIT_FIRMWARE_READY_FAIL;
6fa3eb70
S
1630 break;
1631 }
1632 else {
1633 i++;
1634 kalMsleep(10);
1635 }
1636 }
1637
1638#if defined(MT5931)
1639 // Acquire LP-OWN
1640 DBGLOG(INIT, TRACE, ("wlanAdapterStart(): Acquiring LP-OWN\n"));
1641 ACQUIRE_POWER_CONTROL_FROM_PM(prAdapter);
1642 #if !CFG_ENABLE_FULL_PM
1643 nicpmSetDriverOwn(prAdapter);
1644 #endif
1645
1646 if(prAdapter->fgIsFwOwn == TRUE) {
1647 DBGLOG(INIT, ERROR, ("nicpmSetDriverOwn() failed!\n"));
1648 u4Status = WLAN_STATUS_FAILURE;
1649 break;
1650 }
1651
1652 //4 <1> Initialize the Adapter
1653 if ( (u4Status = nicInitializeAdapter(prAdapter)) != WLAN_STATUS_SUCCESS ) {
1654 DBGLOG(INIT, ERROR, ("nicInitializeAdapter failed!\n"));
1655 u4Status = WLAN_STATUS_FAILURE;
1656 break;
1657 }
1658
1659 /* post initialization for MT5931 due to some CR is only accessible after driver own */
1660 nicRxPostInitialize(prAdapter);
1661#endif
1662
1663 if(u4Status == WLAN_STATUS_SUCCESS) {
1664 // 1. reset interrupt status
1665 HAL_READ_INTR_STATUS(prAdapter, 4, (PUINT_8)&u4WHISR);
1666 if(HAL_IS_TX_DONE_INTR(u4WHISR)) {
1667 HAL_READ_TX_RELEASED_COUNT(prAdapter, aucTxCount);
1668 }
1669
1670 /* 2. reset TX Resource for normal operation */
1671 nicTxResetResource(prAdapter);
1672
1673#if CFG_SUPPORT_OSC_SETTING && defined(MT5931)
1674 wlanSetMcuOscStableTime(prAdapter, 0);
1675#endif
1676
1677 /* 3. query for permanent address by polling */
1678 wlanQueryPermanentAddress(prAdapter);
1679
1680#if (CFG_SUPPORT_NIC_CAPABILITY == 1)
1681 /* 4. query for NIC capability */
1682 wlanQueryNicCapability(prAdapter);
1683#endif
1684 /* 4.1 query for compiler flags */
1685 wlanQueryCompileFlags(prAdapter);
1686
1687 /* 5. Override network address */
1688 wlanUpdateNetworkAddress(prAdapter);
1689
1690 /* 6. indicate disconnection as default status */
1691 kalIndicateStatusAndComplete(prAdapter->prGlueInfo,
1692 WLAN_STATUS_MEDIA_DISCONNECT,
1693 NULL,
1694 0);
1695 }
1696
1697 RECLAIM_POWER_CONTROL_TO_PM(prAdapter, FALSE);
1698
1699 if(u4Status != WLAN_STATUS_SUCCESS) {
4b9e9796 1700 eFailReason = WAIT_FIRMWARE_READY_FAIL;
6fa3eb70
S
1701 break;
1702 }
1703
1704 /* OID timeout timer initialize */
1705 cnmTimerInitTimer(prAdapter,
1706 &prAdapter->rOidTimeoutTimer,
1707 (PFN_MGMT_TIMEOUT_FUNC)wlanReleasePendingOid,
1708 (ULONG)NULL);
1709
1710 /* Return Indicated Rfb list timer */
1711 cnmTimerInitTimer(prAdapter,
1712 &prAdapter->rReturnIndicatedRfbListTimer,
1713 (PFN_MGMT_TIMEOUT_FUNC)wlanReturnIndicatedPacketsTimeOut,
1714 (ULONG)NULL);
1715
1716 /* Power state initialization */
1717 prAdapter->fgWiFiInSleepyState = FALSE;
1718 prAdapter->rAcpiState = ACPI_STATE_D0;
1719
1720 /* Online scan option */
1721 if(prRegInfo->fgDisOnlineScan == 0) {
1722 prAdapter->fgEnOnlineScan = TRUE;
1723 }
1724 else {
1725 prAdapter->fgEnOnlineScan = FALSE;
1726 }
1727
1728 /* Beacon lost detection option */
1729 if(prRegInfo->fgDisBcnLostDetection != 0) {
1730 prAdapter->fgDisBcnLostDetection = TRUE;
1731 }
1732
1733 /* Load compile time constant */
1734 prAdapter->rWlanInfo.u2BeaconPeriod = CFG_INIT_ADHOC_BEACON_INTERVAL;
1735 prAdapter->rWlanInfo.u2AtimWindow = CFG_INIT_ADHOC_ATIM_WINDOW;
1736
1737#if 1// set PM parameters
1738 prAdapter->fgEnArpFilter = prRegInfo->fgEnArpFilter;
1739 prAdapter->u4PsCurrentMeasureEn = prRegInfo->u4PsCurrentMeasureEn;
1740
1741 prAdapter->u4UapsdAcBmp = prRegInfo->u4UapsdAcBmp;
1742
1743 prAdapter->u4MaxSpLen = prRegInfo->u4MaxSpLen;
1744
1745 DBGLOG(INIT, TRACE, ("[1] fgEnArpFilter:0x%x, u4UapsdAcBmp:0x%x, u4MaxSpLen:0x%x",
1746 prAdapter->fgEnArpFilter,
1747 prAdapter->u4UapsdAcBmp,
1748 prAdapter->u4MaxSpLen));
1749
1750 prAdapter->fgEnCtiaPowerMode = FALSE;
1751
1752#if CFG_SUPPORT_DBG_POWERMODE
1753 prAdapter->fgEnDbgPowerMode = FALSE;
1754#endif
1755
1756#endif
1757
1758 /* MGMT Initialization */
1759 nicInitMGMT(prAdapter, prRegInfo);
1760
1761 /* Enable WZC Disassociation */
1762 prAdapter->rWifiVar.fgSupportWZCDisassociation = TRUE;
1763
1764 /* Apply Rate Setting */
1765 if((ENUM_REGISTRY_FIXED_RATE_T)(prRegInfo->u4FixedRate) < FIXED_RATE_NUM) {
1766 prAdapter->rWifiVar.eRateSetting = (ENUM_REGISTRY_FIXED_RATE_T)(prRegInfo->u4FixedRate);
1767 }
1768 else {
1769 prAdapter->rWifiVar.eRateSetting = FIXED_RATE_NONE;
1770 }
1771
1772 if(prAdapter->rWifiVar.eRateSetting == FIXED_RATE_NONE) {
1773 /* Enable Auto (Long/Short) Preamble */
1774 prAdapter->rWifiVar.ePreambleType = PREAMBLE_TYPE_AUTO;
1775 }
1776 else if((prAdapter->rWifiVar.eRateSetting >= FIXED_RATE_MCS0_20M_400NS &&
1777 prAdapter->rWifiVar.eRateSetting <= FIXED_RATE_MCS7_20M_400NS)
1778 || (prAdapter->rWifiVar.eRateSetting >= FIXED_RATE_MCS0_40M_400NS &&
1779 prAdapter->rWifiVar.eRateSetting <= FIXED_RATE_MCS32_400NS)) {
1780 /* Force Short Preamble */
1781 prAdapter->rWifiVar.ePreambleType = PREAMBLE_TYPE_SHORT;
1782 }
1783 else {
1784 /* Force Long Preamble */
1785 prAdapter->rWifiVar.ePreambleType = PREAMBLE_TYPE_LONG;
1786 }
1787
1788 /* Disable Hidden SSID Join */
1789 prAdapter->rWifiVar.fgEnableJoinToHiddenSSID = FALSE;
1790
1791 /* Enable Short Slot Time */
1792 prAdapter->rWifiVar.fgIsShortSlotTimeOptionEnable = TRUE;
1793
1794 /* configure available PHY type set */
1795 nicSetAvailablePhyTypeSet(prAdapter);
1796
1797#if 1// set PM parameters
1798 {
1799#if CFG_SUPPORT_PWR_MGT
1800 prAdapter->u4PowerMode = prRegInfo->u4PowerMode;
1801 prAdapter->rWlanInfo.arPowerSaveMode[NETWORK_TYPE_P2P_INDEX].ucNetTypeIndex = NETWORK_TYPE_P2P_INDEX;
1802 prAdapter->rWlanInfo.arPowerSaveMode[NETWORK_TYPE_P2P_INDEX].ucPsProfile = ENUM_PSP_FAST_SWITCH;
1803#else
1804 prAdapter->u4PowerMode = ENUM_PSP_CONTINUOUS_ACTIVE;
1805#endif
1806
1807 nicConfigPowerSaveProfile(
1808 prAdapter,
1809 NETWORK_TYPE_AIS_INDEX, //FIXIT
1810 prAdapter->u4PowerMode,
1811 FALSE);
1812 }
1813
1814#endif
1815
1816#if CFG_SUPPORT_NVRAM
1817 /* load manufacture data */
1818 wlanLoadManufactureData(prAdapter, prRegInfo);
1819#endif
1820
1821#ifdef CONFIG_MTK_TC1_FEATURE// 1 //keep alive packet time change from default 30secs to 20secs. //TC01//
1822{
1823 CMD_SW_DBG_CTRL_T rCmdSwCtrl;
1824 rCmdSwCtrl.u4Id = 0x90100000;
1825 rCmdSwCtrl.u4Data = 30;
1826 printk( "wlanAdapterStart Keepaliveapcket 0x%x, %d\n", rCmdSwCtrl.u4Id, rCmdSwCtrl.u4Data);
1827 wlanSendSetQueryCmd(prAdapter,
1828 CMD_ID_SW_DBG_CTRL,
1829 TRUE,
1830 FALSE,
1831 FALSE,
1832 NULL,
1833 NULL,
1834 sizeof(CMD_SW_DBG_CTRL_T),
1835 (PUINT_8)(&rCmdSwCtrl),
1836 NULL,
1837 0);
1838}
1839#endif
1840
1841#if (defined(MT5931) && (!CFG_SUPPORT_BCM_BWCS))
1842 //Enable DPD calibration.
1843 rBwcsPta.u.aucBTPParams[0] = 0x00;
1844 rBwcsPta.u.aucBTPParams[1] = 0x01;
1845 rBwcsPta.u.aucBTPParams[2] = 0x00;
1846 rBwcsPta.u.aucBTPParams[3] = 0x80;
1847
1848 wlanoidSetBT(prAdapter,
1849 (PVOID)&rBwcsPta,
1850 sizeof(PARAM_PTA_IPC_T),
1851 &u4SetInfoLen);
1852#endif
1853
1854#if 0
1855 /* Update Auto rate parameters in FW */
1856 nicRlmArUpdateParms(prAdapter,
1857 prRegInfo->u4ArSysParam0,
1858 prRegInfo->u4ArSysParam1,
1859 prRegInfo->u4ArSysParam2,
1860 prRegInfo->u4ArSysParam3);
1861#endif
1862
1863
1864#if (MT6620_E1_ASIC_HIFSYS_WORKAROUND == 1)
1865 /* clock gating workaround */
1866 prAdapter->fgIsClockGatingEnabled = FALSE;
1867#endif
1868
1869 } while(FALSE);
1870
1871 if(u4Status == WLAN_STATUS_SUCCESS) {
1872 // restore to hardware default
1873 HAL_SET_INTR_STATUS_READ_CLEAR(prAdapter);
1874 HAL_SET_MAILBOX_READ_CLEAR(prAdapter, FALSE);
1875
1876 /* Enable interrupt */
1877 nicEnableInterrupt(prAdapter);
1878
1879 }
1880 else {
1881 // release allocated memory
4b9e9796
S
1882 switch (eFailReason)
1883 {
1884 case WAIT_FIRMWARE_READY_FAIL:
1885 case RAM_CODE_DOWNLOAD_FAIL:
1886 DBGLOG(INIT, ERROR, ("Wait firmware ready fail or ram code download fail, FailReason: %d\n",
1887 eFailReason));
1888 KAL_WAKE_LOCK_DESTROY(prAdapter, &prAdapter->rTxThreadWakeLock);
1889 nicRxUninitialize(prAdapter);
1890 nicTxRelease(prAdapter);
1891 /* System Service Uninitialization */
1892 nicUninitSystemService(prAdapter);
1893 case INIT_ADAPTER_FAIL:
1894 case DRIVER_OWN_FAIL:
1895 nicReleaseAdapterMemory(prAdapter);
1896 case ALLOC_ADAPTER_MEM_FAIL:
1897 break;
1898 default:
1899 break;
1900 }
1901 }
6fa3eb70
S
1902
1903 return u4Status;
1904} /* wlanAdapterStart */
1905
1906
1907/*----------------------------------------------------------------------------*/
1908/*!
1909* \brief Uninitialize the adapter
1910*
1911* \param prAdapter Pointer of Adapter Data Structure
1912*
1913* \retval WLAN_STATUS_SUCCESS: Success
1914* \retval WLAN_STATUS_FAILURE: Failed
1915*/
1916/*----------------------------------------------------------------------------*/
1917WLAN_STATUS
1918wlanAdapterStop (
1919 IN P_ADAPTER_T prAdapter
1920 )
1921{
1922 UINT_32 i, u4Value = 0;
1923 WLAN_STATUS u4Status = WLAN_STATUS_SUCCESS;
1924
1925 ASSERT(prAdapter);
1926
1927#if (MT6620_E1_ASIC_HIFSYS_WORKAROUND == 1)
1928 if(prAdapter->fgIsClockGatingEnabled == TRUE) {
1929 nicDisableClockGating(prAdapter);
1930 }
1931#endif
1932
1933 /* MGMT - unitialization */
1934 nicUninitMGMT(prAdapter);
1935
1936 if(prAdapter->rAcpiState == ACPI_STATE_D0 &&
1937#if (CFG_CHIP_RESET_SUPPORT == 1)
1938 kalIsResetting() == FALSE &&
1939#endif
1940 kalIsCardRemoved(prAdapter->prGlueInfo) == FALSE) {
1941
1942 /* 0. Disable interrupt, this can be done without Driver own */
1943 nicDisableInterrupt(prAdapter);
1944
1945 ACQUIRE_POWER_CONTROL_FROM_PM(prAdapter);
1946
1947 /* 1. Set CMD to FW to tell WIFI to stop (enter power off state) */
1948 /* the command must be issue to firmware even in wlanRemove() */
1949 if(prAdapter->fgIsFwOwn == FALSE &&
1950 wlanSendNicPowerCtrlCmd(prAdapter, 1) == WLAN_STATUS_SUCCESS) {
1951 /* 2. Clear pending interrupt */
1952 i = 0;
1953 while(i < CFG_IST_LOOP_COUNT && nicProcessIST(prAdapter) != WLAN_STATUS_NOT_INDICATING) {
1954 i++;
1955 };
1956
1957 /* 3. Wait til RDY bit has been cleaerd */
1958 i = 0;
1959 while(1) {
1960 HAL_MCR_RD(prAdapter, MCR_WCIR, &u4Value);
1961
1962 if ((u4Value & WCIR_WLAN_READY) == 0)
1963 break;
1964 else if(kalIsCardRemoved(prAdapter->prGlueInfo) == TRUE
1965 || fgIsBusAccessFailed == TRUE
1966 || i >= CFG_RESPONSE_POLLING_TIMEOUT) {
1967 break;
1968 }
1969 else {
1970 i++;
1971 kalMsleep(10);
1972 }
1973 }
1974 }
1975
1976 /* 4. Set Onwership to F/W */
1977 nicpmSetFWOwn(prAdapter, FALSE);
1978
1979#if CFG_FORCE_RESET_UNDER_BUS_ERROR
1980 if(HAL_TEST_FLAG(prAdapter, ADAPTER_FLAG_HW_ERR) == TRUE) {
1981 /* force acquire firmware own */
1982 kalDevRegWrite(prAdapter->prGlueInfo, MCR_WHLPCR, WHLPCR_FW_OWN_REQ_CLR);
1983
1984 /* delay for 10ms */
1985 kalMdelay(10);
1986
1987 /* force firmware reset via software interrupt */
1988 kalDevRegWrite(prAdapter->prGlueInfo, MCR_WSICR, WSICR_H2D_SW_INT_SET);
1989
1990 /* force release firmware own */
1991 kalDevRegWrite(prAdapter->prGlueInfo, MCR_WHLPCR, WHLPCR_FW_OWN_REQ_SET);
1992 }
1993#endif
1994
1995 RECLAIM_POWER_CONTROL_TO_PM(prAdapter, FALSE);
1996 }
1997
1998 nicRxUninitialize(prAdapter);
1999
2000 nicTxRelease(prAdapter);
2001
2002 /* System Service Uninitialization */
2003 nicUninitSystemService(prAdapter);
2004
2005 nicReleaseAdapterMemory(prAdapter);
2006
2007#if defined(_HIF_SPI)
2008 /* Note: restore the SPI Mode Select from 32 bit to default */
2009 nicRestoreSpiDefMode(prAdapter);
2010#endif
2011
2012 return u4Status;
2013} /* wlanAdapterStop */
2014
2015
2016#if 0
2017/*----------------------------------------------------------------------------*/
2018/*!
2019* \brief This function is called by ISR (interrupt).
2020*
2021* \param prAdapter Pointer of Adapter Data Structure
2022*
2023* \retval TRUE: NIC's interrupt
2024* \retval FALSE: Not NIC's interrupt
2025*/
2026/*----------------------------------------------------------------------------*/
2027BOOLEAN
2028wlanISR (
2029 IN P_ADAPTER_T prAdapter,
2030 IN BOOLEAN fgGlobalIntrCtrl
2031 )
2032{
2033 ASSERT(prAdapter);
2034
2035 if (fgGlobalIntrCtrl) {
2036 nicDisableInterrupt(prAdapter);
2037
2038 //wlanIST(prAdapter);
2039 }
2040
2041 return TRUE;
2042}
2043#endif
2044
2045/*----------------------------------------------------------------------------*/
2046/*!
2047* \brief This function is called by IST (task_let).
2048*
2049* \param prAdapter Pointer of Adapter Data Structure
2050*
2051* \return (none)
2052*/
2053/*----------------------------------------------------------------------------*/
2054VOID
2055wlanIST (
2056 IN P_ADAPTER_T prAdapter
2057 )
2058{
2059 ASSERT(prAdapter);
2060
2061 /* wake up CONNSYS */
2062 ACQUIRE_POWER_CONTROL_FROM_PM(prAdapter);
2063
2064 /* handle interrupts */
2065 nicProcessIST(prAdapter);
2066
2067 /* re-enable HIF interrupts */
2068 nicEnableInterrupt(prAdapter);
2069
2070 /* CONNSYS can decide to sleep */
2071 RECLAIM_POWER_CONTROL_TO_PM(prAdapter, FALSE);
2072
2073 return;
2074}
2075
2076
2077/*----------------------------------------------------------------------------*/
2078/*!
2079* \brief This function will check command queue to find out if any could be dequeued
2080* and/or send to HIF to MT6620
2081*
2082* \param prAdapter Pointer of Adapter Data Structure
2083* \param prCmdQue Pointer of Command Queue (in Glue Layer)
2084*
2085* \retval WLAN_STATUS_SUCCESS
2086*/
2087/*----------------------------------------------------------------------------*/
2088WLAN_STATUS
2089wlanProcessCommandQueue (
2090 IN P_ADAPTER_T prAdapter,
2091 IN P_QUE_T prCmdQue
2092 )
2093{
2094 WLAN_STATUS rStatus;
2095 QUE_T rTempCmdQue, rMergeCmdQue, rStandInCmdQue;
2096 P_QUE_T prTempCmdQue, prMergeCmdQue, prStandInCmdQue;
2097 P_QUE_ENTRY_T prQueueEntry;
2098 P_CMD_INFO_T prCmdInfo;
2099 P_MSDU_INFO_T prMsduInfo;
2100 ENUM_FRAME_ACTION_T eFrameAction = FRAME_ACTION_DROP_PKT;
2101
2102 KAL_SPIN_LOCK_DECLARATION();
2103
2104 /* sanity check */
2105 ASSERT(prAdapter);
2106 ASSERT(prCmdQue);
2107
2108 /* init */
2109 prTempCmdQue = &rTempCmdQue;
2110 prMergeCmdQue = &rMergeCmdQue;
2111 prStandInCmdQue = &rStandInCmdQue;
2112
2113 QUEUE_INITIALIZE(prTempCmdQue);
2114 QUEUE_INITIALIZE(prMergeCmdQue);
2115 QUEUE_INITIALIZE(prStandInCmdQue);
2116
2117 //4 <1> Move whole list of CMD_INFO to the temp queue
2118 /* copy all commands to prTempCmdQue and empty prCmdQue */
2119 KAL_ACQUIRE_SPIN_LOCK(prAdapter, SPIN_LOCK_CMD_QUE);
2120 QUEUE_MOVE_ALL(prTempCmdQue, prCmdQue);
2121 KAL_RELEASE_SPIN_LOCK(prAdapter, SPIN_LOCK_CMD_QUE);
2122
2123 //4 <2> Dequeue from head and check it is able to be sent
2124 /* remove the first one */
2125 QUEUE_REMOVE_HEAD(prTempCmdQue, prQueueEntry, P_QUE_ENTRY_T);
2126
2127 while(prQueueEntry) {
2128 prCmdInfo = (P_CMD_INFO_T)prQueueEntry;
2129
2130 /* check how to handle the command: drop, queue, or tx */
2131 switch(prCmdInfo->eCmdType) {
2132 case COMMAND_TYPE_GENERAL_IOCTL:
2133 case COMMAND_TYPE_NETWORK_IOCTL:
2134 /* command packet will be always sent */
2135 eFrameAction = FRAME_ACTION_TX_PKT;
2136 break;
2137
2138 case COMMAND_TYPE_SECURITY_FRAME:
2139 /* inquire with QM */
2140 eFrameAction = qmGetFrameAction(prAdapter,
2141 prCmdInfo->eNetworkType,
2142 prCmdInfo->ucStaRecIndex,
2143 NULL,
2144 FRAME_TYPE_802_1X);
2145 break;
2146
2147 case COMMAND_TYPE_MANAGEMENT_FRAME:
2148 /* inquire with QM */
2149 prMsduInfo = (P_MSDU_INFO_T)(prCmdInfo->prPacket);
2150
2151 eFrameAction = qmGetFrameAction(prAdapter,
2152 prMsduInfo->ucNetworkType,
2153 prMsduInfo->ucStaRecIndex,
2154 prMsduInfo,
2155 FRAME_TYPE_MMPDU);
2156 break;
2157
2158 default:
2159 ASSERT(0);
2160 break;
2161 }
2162
2163 //4 <3> handling upon dequeue result
2164 if(eFrameAction == FRAME_ACTION_DROP_PKT) {
2165 wlanReleaseCommand(prAdapter, prCmdInfo);
2166 }
2167 else if(eFrameAction == FRAME_ACTION_QUEUE_PKT) {
2168 QUEUE_INSERT_TAIL(prMergeCmdQue, prQueueEntry);
2169 }
2170 else if(eFrameAction == FRAME_ACTION_TX_PKT) {
2171 //4 <4> Send the command
2172 rStatus = wlanSendCommand(prAdapter, prCmdInfo);
2173
2174 if(rStatus == WLAN_STATUS_RESOURCES) {
2175 // no more TC4 resource for further transmission
2176 QUEUE_INSERT_TAIL(prMergeCmdQue, prQueueEntry);
2177 break;
2178 }
2179 else if(rStatus == WLAN_STATUS_PENDING) {
2180 // command packet which needs further handling upon response
2181 // i.e. we need to wait for FW's response
2182 KAL_ACQUIRE_SPIN_LOCK(prAdapter, SPIN_LOCK_CMD_PENDING);
2183 QUEUE_INSERT_TAIL(&(prAdapter->rPendingCmdQueue), prQueueEntry);
2184 KAL_RELEASE_SPIN_LOCK(prAdapter, SPIN_LOCK_CMD_PENDING);
2185 }
2186 else {
2187 /* send success or fail */
2188 P_CMD_INFO_T prCmdInfo = (P_CMD_INFO_T)prQueueEntry;
2189
2190 if (rStatus == WLAN_STATUS_SUCCESS) {
2191 /* send success */
2192 if (prCmdInfo->pfCmdDoneHandler) {
2193 prCmdInfo->pfCmdDoneHandler(prAdapter, prCmdInfo, prCmdInfo->pucInfoBuffer);
2194 }
2195 }
2196 else {
2197 /* send fail */
2198 if (prCmdInfo->fgIsOid) {
2199 kalOidComplete(prAdapter->prGlueInfo, prCmdInfo->fgSetQuery, prCmdInfo->u4SetInfoLen, rStatus);
2200 }
2201 }
2202
2203 /* free the command memory */
2204 cmdBufFreeCmdInfo(prAdapter, prCmdInfo);
2205 }
2206 }
2207 else {
2208
2209 /* impossible, wrong eFrameAction */
2210 ASSERT(0);
2211 }
2212
2213 QUEUE_REMOVE_HEAD(prTempCmdQue, prQueueEntry, P_QUE_ENTRY_T);
2214 }
2215
2216 //4 <3> Merge back to original queue
2217 //4 <3.1> Merge prMergeCmdQue & prTempCmdQue
2218 QUEUE_CONCATENATE_QUEUES(prMergeCmdQue, prTempCmdQue);
2219
2220 //4 <3.2> Move prCmdQue to prStandInQue, due to prCmdQue might differ due to incoming 802.1X frames
2221 KAL_ACQUIRE_SPIN_LOCK(prAdapter, SPIN_LOCK_CMD_QUE);
2222
2223 /* ??? here, prCmdQue shall be empty, why QUEUE_MOVE_ALL ??? */
2224 QUEUE_MOVE_ALL(prStandInCmdQue, prCmdQue);
2225
2226 //4 <3.3> concatenate prStandInQue to prMergeCmdQue
2227 QUEUE_CONCATENATE_QUEUES(prMergeCmdQue, prStandInCmdQue);
2228
2229 //4 <3.4> then move prMergeCmdQue to prCmdQue
2230 QUEUE_MOVE_ALL(prCmdQue, prMergeCmdQue);
2231 KAL_RELEASE_SPIN_LOCK(prAdapter, SPIN_LOCK_CMD_QUE);
2232
2233 return WLAN_STATUS_SUCCESS;
2234} /* end of wlanProcessCommandQueue() */
2235
2236
2237/*----------------------------------------------------------------------------*/
2238/*!
2239* \brief This function will take CMD_INFO_T which carry some informations of
2240* incoming OID and notify the NIC_TX to send CMD.
2241*
2242* \param prAdapter Pointer of Adapter Data Structure
2243* \param prCmdInfo Pointer of P_CMD_INFO_T
2244*
2245* \retval WLAN_STATUS_SUCCESS : CMD was written to HIF and be freed(CMD Done) immediately.
2246* \retval WLAN_STATUS_RESOURCE : No resource for current command, need to wait for previous
2247* frame finishing their transmission.
2248* \retval WLAN_STATUS_FAILURE : Get failure while access HIF or been rejected.
2249*/
2250/*----------------------------------------------------------------------------*/
2251WLAN_STATUS
2252wlanSendCommand (
2253 IN P_ADAPTER_T prAdapter,
2254 IN P_CMD_INFO_T prCmdInfo
2255 )
2256{
2257 P_TX_CTRL_T prTxCtrl;
2258 UINT_8 ucTC; /* "Traffic Class" SW(Driver) resource classification */
2259 WLAN_STATUS rStatus = WLAN_STATUS_SUCCESS;
2260
2261 /* sanity check */
2262 ASSERT(prAdapter);
2263 ASSERT(prCmdInfo);
2264
2265 /* init */
2266 prTxCtrl = &prAdapter->rTxCtrl;
2267
2268 //DbgPrint("wlanSendCommand()\n");
2269 //
2270 //
2271#if DBG && 0
2272 LOG_FUNC("wlanSendCommand()\n");
2273 LOG_FUNC("CmdType %u NetworkType %u StaRecIndex %u Oid %u CID 0x%x SetQuery %u NeedResp %u CmdSeqNum %u\n",
2274 prCmdInfo->eCmdType,
2275 prCmdInfo->eNetworkType,
2276 prCmdInfo->ucStaRecIndex,
2277 prCmdInfo->fgIsOid,
2278 prCmdInfo->ucCID,
2279 prCmdInfo->fgSetQuery,
2280 prCmdInfo->fgNeedResp,
2281 prCmdInfo->ucCmdSeqNum);
2282#endif
2283
2284
2285#if (MT6620_E1_ASIC_HIFSYS_WORKAROUND == 1)
2286 if(prAdapter->fgIsClockGatingEnabled == TRUE) {
2287 nicDisableClockGating(prAdapter);
2288 }
2289#endif
2290
2291 do {
2292 // <0> card removal check
2293 if(kalIsCardRemoved(prAdapter->prGlueInfo) == TRUE
2294 || fgIsBusAccessFailed == TRUE) {
2295 rStatus = WLAN_STATUS_FAILURE;
2296 break;
2297 }
2298
2299 // <1> Normal case of sending CMD Packet
2300 if (!prCmdInfo->fgDriverDomainMCR) {
2301 // <1.1> Assign Traffic Class(TC) = TC4.
2302 ucTC = TC4_INDEX;
2303
2304 // <1.2> Check if pending packet or resource was exhausted
2305 if ((rStatus = nicTxAcquireResource(prAdapter, ucTC)) == WLAN_STATUS_RESOURCES) {
2306 DbgPrint("NO Resource:%d\n", ucTC);
2307 break;
2308 }
2309
2310 // <1.3> Forward CMD_INFO_T to NIC Layer
2311 rStatus = nicTxCmd(prAdapter, prCmdInfo, ucTC);
2312
2313 // <1.4> Set Pending in response to Query Command/Need Response
2314 if (rStatus == WLAN_STATUS_SUCCESS) {
2315 if ((!prCmdInfo->fgSetQuery) || (prCmdInfo->fgNeedResp)) {
2316 rStatus = WLAN_STATUS_PENDING;
2317 }
2318 }
2319 }
2320 // <2> "Special case" for access Driver Domain MCR
2321 else {
2322
2323 P_CMD_ACCESS_REG prCmdAccessReg;
2324 prCmdAccessReg = (P_CMD_ACCESS_REG)(prCmdInfo->pucInfoBuffer + CMD_HDR_SIZE);
2325
2326 if (prCmdInfo->fgSetQuery) {
2327 HAL_MCR_WR(prAdapter,
2328 (prCmdAccessReg->u4Address & BITS(2,31)), //address is in DWORD unit
2329 prCmdAccessReg->u4Data);
2330 }
2331 else {
2332 P_CMD_ACCESS_REG prEventAccessReg;
2333 UINT_32 u4Address;
2334
2335 u4Address = prCmdAccessReg->u4Address;
2336 prEventAccessReg = (P_CMD_ACCESS_REG)prCmdInfo->pucInfoBuffer;
2337 prEventAccessReg->u4Address = u4Address;
2338
2339 HAL_MCR_RD(prAdapter,
2340 prEventAccessReg->u4Address & BITS(2,31), //address is in DWORD unit
2341 &prEventAccessReg->u4Data);
2342 }
2343 }
2344
2345 }
2346 while (FALSE);
2347
2348#if (MT6620_E1_ASIC_HIFSYS_WORKAROUND == 1)
2349 if(prAdapter->fgIsClockGatingEnabled == FALSE) {
2350 nicEnableClockGating(prAdapter);
2351 }
2352#endif
2353
2354 return rStatus;
2355} /* end of wlanSendCommand() */
2356
2357
2358/*----------------------------------------------------------------------------*/
2359/*!
2360 * \brief This function will release thd CMD_INFO upon its attribution
2361 *
2362 * \param prAdapter Pointer of Adapter Data Structure
2363 * \param prCmdInfo Pointer of CMD_INFO_T
2364 *
2365 * \return (none)
2366 */
2367/*----------------------------------------------------------------------------*/
2368VOID
2369wlanReleaseCommand (
2370 IN P_ADAPTER_T prAdapter,
2371 IN P_CMD_INFO_T prCmdInfo
2372 )
2373{
2374 P_TX_CTRL_T prTxCtrl;
2375 P_MSDU_INFO_T prMsduInfo;
2376
2377 ASSERT(prAdapter);
2378 ASSERT(prCmdInfo);
2379
2380 prTxCtrl = &prAdapter->rTxCtrl;
2381
2382 switch(prCmdInfo->eCmdType) {
2383 case COMMAND_TYPE_GENERAL_IOCTL:
2384 case COMMAND_TYPE_NETWORK_IOCTL:
2385 if (prCmdInfo->fgIsOid) {
2386 /* for OID command, we need to do complete() to wake up kalIoctl() */
2387 kalOidComplete(prAdapter->prGlueInfo,
2388 prCmdInfo->fgSetQuery,
2389 prCmdInfo->u4SetInfoLen,
2390 WLAN_STATUS_FAILURE);
2391 }
2392 break;
2393
2394 case COMMAND_TYPE_SECURITY_FRAME:
2395 /* free packets in kalSecurityFrameSendComplete() */
2396 kalSecurityFrameSendComplete(prAdapter->prGlueInfo,
2397 prCmdInfo->prPacket,
2398 WLAN_STATUS_FAILURE);
2399 break;
2400
2401 case COMMAND_TYPE_MANAGEMENT_FRAME:
2402 prMsduInfo = (P_MSDU_INFO_T)prCmdInfo->prPacket;
2403
2404 /* invoke callbacks */
2405 if(prMsduInfo->pfTxDoneHandler != NULL) {
2406 prMsduInfo->pfTxDoneHandler(prAdapter, prMsduInfo, TX_RESULT_DROPPED_IN_DRIVER);
2407 }
2408
2409 GLUE_DEC_REF_CNT(prTxCtrl->i4TxMgmtPendingNum);
2410 cnmMgtPktFree(prAdapter, prMsduInfo);
2411 break;
2412
2413 default:
2414 /* impossible, shall not be here */
2415 ASSERT(0);
2416 break;
2417 }
2418
2419 /* free command buffer and return the command header to command pool */
2420 cmdBufFreeCmdInfo(prAdapter, prCmdInfo);
2421
2422} /* end of wlanReleaseCommand() */
2423
2424
2425/*----------------------------------------------------------------------------*/
2426/*!
2427* \brief This function will search the CMD Queue to look for the pending OID and
2428* compelete it immediately when system request a reset.
2429*
2430* \param prAdapter ointer of Adapter Data Structure
2431*
2432* \return (none)
2433*/
2434/*----------------------------------------------------------------------------*/
2435VOID
2436wlanReleasePendingOid (
2437 IN P_ADAPTER_T prAdapter,
2438 IN ULONG ulData
2439 )
2440{
2441 P_QUE_T prCmdQue;
2442 QUE_T rTempCmdQue;
2443 P_QUE_T prTempCmdQue = &rTempCmdQue;
2444 P_QUE_ENTRY_T prQueueEntry = (P_QUE_ENTRY_T)NULL;
2445 P_CMD_INFO_T prCmdInfo = (P_CMD_INFO_T)NULL;
2446
2447 KAL_SPIN_LOCK_DECLARATION();
2448
2449 DEBUGFUNC("wlanReleasePendingOid");
2450
2451 ASSERT(prAdapter);
2452
2453 DBGLOG(INIT, ERROR, ("OID Timeout! Releasing pending OIDs ..\n"));
2454
2455 do {
2456 // 1: Handle OID commands in pending queue
2457 /* Clear Pending OID in prAdapter->rPendingCmdQueue */
2458 KAL_ACQUIRE_SPIN_LOCK(prAdapter, SPIN_LOCK_CMD_PENDING);
2459
2460 /* move all pending commands to prTempCmdQue and empty prCmdQue */
2461 prCmdQue = &prAdapter->rPendingCmdQueue;
2462 QUEUE_MOVE_ALL(prTempCmdQue, prCmdQue);
2463
2464 /* get first pending command */
2465 QUEUE_REMOVE_HEAD(prTempCmdQue, prQueueEntry, P_QUE_ENTRY_T);
2466
2467 while (prQueueEntry) {
2468 prCmdInfo = (P_CMD_INFO_T)prQueueEntry;
2469
2470 if (prCmdInfo->fgIsOid) {
2471 if (prCmdInfo->pfCmdTimeoutHandler) {
2472 prCmdInfo->pfCmdTimeoutHandler(prAdapter, prCmdInfo);
2473 }
2474 else
2475 {
2476 /* send complete() to wake up kalIoctl() */
2477 kalOidComplete(prAdapter->prGlueInfo,
2478 prCmdInfo->fgSetQuery,
2479 0,
2480 WLAN_STATUS_FAILURE);
2481 }
2482
2483 /* free command memory */
2484 cmdBufFreeCmdInfo(prAdapter, prCmdInfo);
2485 }
2486 else {
2487 /* nothing to do so re-queue it to prCmdQue */
2488 QUEUE_INSERT_TAIL(prCmdQue, prQueueEntry);
2489 }
2490
2491 QUEUE_REMOVE_HEAD(prTempCmdQue, prQueueEntry, P_QUE_ENTRY_T);
2492 }
2493
2494 KAL_RELEASE_SPIN_LOCK(prAdapter, SPIN_LOCK_CMD_PENDING);
2495
2496
2497 // 2: Clear pending OID staying in command queue
2498 kalOidCmdClearance(prAdapter->prGlueInfo);
2499
2500 // 3: Do complete(), do we need this? because we have completed in kalOidComplete
2501 kalOidClearance(prAdapter->prGlueInfo);
2502
2503 } while(FALSE);
2504
2505 return;
2506}
2507
2508
2509/*----------------------------------------------------------------------------*/
2510/*!
2511* \brief This function will search the CMD Queue to look for the pending CMD/OID for specific
2512* NETWORK TYPE and compelete it immediately when system request a reset.
2513*
2514* \param prAdapter ointer of Adapter Data Structure
2515*
2516* \return (none)
2517*/
2518/*----------------------------------------------------------------------------*/
2519VOID
2520wlanReleasePendingCMDbyNetwork (
2521 IN P_ADAPTER_T prAdapter,
2522 IN ENUM_NETWORK_TYPE_INDEX_T eNetworkType
2523 )
2524{
2525 P_QUE_T prCmdQue;
2526 QUE_T rTempCmdQue;
2527 P_QUE_T prTempCmdQue = &rTempCmdQue;
2528 P_QUE_ENTRY_T prQueueEntry = (P_QUE_ENTRY_T)NULL;
2529 P_CMD_INFO_T prCmdInfo = (P_CMD_INFO_T)NULL;
2530
2531 KAL_SPIN_LOCK_DECLARATION();
2532
2533 ASSERT(prAdapter);
2534
2535 /* only free commands from the network interface, AIS, P2P, or BOW */
2536
2537 do {
2538 // 1: Clear Pending OID in prAdapter->rPendingCmdQueue
2539 KAL_ACQUIRE_SPIN_LOCK(prAdapter, SPIN_LOCK_CMD_PENDING);
2540
2541 prCmdQue = &prAdapter->rPendingCmdQueue;
2542 QUEUE_MOVE_ALL(prTempCmdQue, prCmdQue);
2543
2544 QUEUE_REMOVE_HEAD(prTempCmdQue, prQueueEntry, P_QUE_ENTRY_T);
2545 while (prQueueEntry) {
2546 prCmdInfo = (P_CMD_INFO_T)prQueueEntry;
2547
2548 DBGLOG(P2P, TRACE, ("Pending CMD for Network Type:%d \n", prCmdInfo->eNetworkType));
2549
2550 if (prCmdInfo->eNetworkType == eNetworkType) {
2551 if (prCmdInfo->pfCmdTimeoutHandler) {
2552 prCmdInfo->pfCmdTimeoutHandler(prAdapter, prCmdInfo);
2553 }
2554 else
2555 kalOidComplete(prAdapter->prGlueInfo,
2556 prCmdInfo->fgSetQuery,
2557 0,
2558 WLAN_STATUS_FAILURE);
2559
2560 cmdBufFreeCmdInfo(prAdapter, prCmdInfo);
2561 }
2562 else {
2563 QUEUE_INSERT_TAIL(prCmdQue, prQueueEntry);
2564 }
2565
2566 QUEUE_REMOVE_HEAD(prTempCmdQue, prQueueEntry, P_QUE_ENTRY_T);
2567 }
2568
2569 KAL_RELEASE_SPIN_LOCK(prAdapter, SPIN_LOCK_CMD_PENDING);
2570
2571
2572 } while(FALSE);
2573
2574 return;
2575} /* wlanReleasePendingCMDbyNetwork */
2576
2577
2578
2579/*----------------------------------------------------------------------------*/
2580/*!
2581* \brief Return the packet buffer and reallocate one to the RFB
2582*
2583* \param prAdapter Pointer of Adapter Data Structure
2584* \param pvPacket Pointer of returned packet
2585*
2586* \retval WLAN_STATUS_SUCCESS: Success
2587* \retval WLAN_STATUS_FAILURE: Failed
2588*/
2589/*----------------------------------------------------------------------------*/
2590VOID
2591wlanReturnPacket (
2592 IN P_ADAPTER_T prAdapter,
2593 IN PVOID pvPacket
2594 )
2595{
2596 P_RX_CTRL_T prRxCtrl;
2597 P_SW_RFB_T prSwRfb = NULL;
2598 KAL_SPIN_LOCK_DECLARATION();
2599
2600 DEBUGFUNC("wlanReturnPacket");
2601
2602 ASSERT(prAdapter);
2603
2604 prRxCtrl = &prAdapter->rRxCtrl;
2605 ASSERT(prRxCtrl);
2606
2607 /* free the packet */
2608 if (pvPacket) {
2609 kalPacketFree(prAdapter->prGlueInfo, pvPacket);
2610 RX_ADD_CNT(prRxCtrl, RX_DATA_RETURNED_COUNT, 1);
2611#if CFG_NATIVE_802_11
2612 if (GLUE_TEST_FLAG(prAdapter->prGlueInfo, GLUE_FLAG_HALT)) {
2613 }
2614#endif
2615 }
2616
2617 /* free the packet control block */
2618 KAL_ACQUIRE_SPIN_LOCK(prAdapter, SPIN_LOCK_RX_QUE);
2619 QUEUE_REMOVE_HEAD(&prRxCtrl->rIndicatedRfbList, prSwRfb, P_SW_RFB_T);
2620 KAL_RELEASE_SPIN_LOCK(prAdapter, SPIN_LOCK_RX_QUE);
2621 if (!prSwRfb){
2622 ASSERT(0);
2623 return;
2624 }
2625
2626 if (nicRxSetupRFB(prAdapter, prSwRfb)){
2627 ASSERT(0);
2628 //return; // Don't return here or it would lost SwRfb --kc
2629 if (!timerPendingTimer(&prAdapter->rReturnIndicatedRfbListTimer)) {
2630 DBGLOG(INIT, WARN, ("wlanReturnPacket, Start ReturnIndicatedRfbList Timer (%ds)\n", RX_RETURN_INDICATED_RFB_TIMEOUT_SEC));
2631 cnmTimerStartTimer(prAdapter,
2632 &prAdapter->rReturnIndicatedRfbListTimer,
2633 SEC_TO_MSEC(RX_RETURN_INDICATED_RFB_TIMEOUT_SEC));
2634 }
2635 }
2636 nicRxReturnRFB(prAdapter, prSwRfb);
2637}
2638
2639/*----------------------------------------------------------------------------*/
2640/*!
2641* \brief Return the indicated packet buffer and reallocate one to the RFB
2642*
2643* \param prAdapter Pointer of Adapter Data Structure
2644* \param pvPacket Pointer of returned packet
2645*
2646* \retval WLAN_STATUS_SUCCESS: Success
2647* \retval WLAN_STATUS_FAILURE: Failed
2648*/
2649/*----------------------------------------------------------------------------*/
2650VOID
2651wlanReturnIndicatedPacketsTimeOut (
2652 IN P_ADAPTER_T prAdapter,
2653 IN ULONG ulData
2654 )
2655{
2656 P_RX_CTRL_T prRxCtrl;
2657 P_SW_RFB_T prSwRfb = NULL;
2658 KAL_SPIN_LOCK_DECLARATION();
2659 WLAN_STATUS status = WLAN_STATUS_SUCCESS;
2660 P_QUE_T prQueList;
2661
2662 DEBUGFUNC("wlanReturnIndicatedPacketsTimeOut");
2663 DBGLOG(INIT, WARN, ("wlanReturnIndicatedPacketsTimeOut"));
2664
2665 ASSERT(prAdapter);
2666
2667 prRxCtrl = &prAdapter->rRxCtrl;
2668 ASSERT(prRxCtrl);
2669
2670 prQueList = &prRxCtrl->rIndicatedRfbList;
2671 DBGLOG(INIT, WARN, ("IndicatedRfbList num = %u\n", (unsigned int)prQueList->u4NumElem));
2672
2673 while (QUEUE_IS_NOT_EMPTY(&prRxCtrl->rIndicatedRfbList)) {
2674 KAL_ACQUIRE_SPIN_LOCK(prAdapter, SPIN_LOCK_RX_QUE);
2675 QUEUE_REMOVE_HEAD(&prRxCtrl->rIndicatedRfbList, prSwRfb, P_SW_RFB_T);
2676 KAL_RELEASE_SPIN_LOCK(prAdapter, SPIN_LOCK_RX_QUE);
2677
2678 if (nicRxSetupRFB(prAdapter, prSwRfb)){
2679 status = WLAN_STATUS_RESOURCES;
2680 ASSERT(0);
2681 }
2682 nicRxReturnRFB(prAdapter, prSwRfb);
2683 if (status == WLAN_STATUS_RESOURCES)
2684 break;
2685 }
2686 if (status == WLAN_STATUS_RESOURCES) {
2687 DBGLOG(INIT, WARN, ("Start ReturnIndicatedRfbList Timer (%ds)\n", RX_RETURN_INDICATED_RFB_TIMEOUT_SEC));
2688 // restart timer
2689 cnmTimerStartTimer(prAdapter,
2690 &prAdapter->rReturnIndicatedRfbListTimer,
2691 SEC_TO_MSEC(RX_RETURN_INDICATED_RFB_TIMEOUT_SEC));
2692 }
2693}
2694
2695/*----------------------------------------------------------------------------*/
2696/*!
2697* \brief This function is a required function that returns information about
2698* the capabilities and status of the driver and/or its network adapter.
2699*
2700* \param[IN] prAdapter Pointer to the Adapter structure.
2701* \param[IN] pfnOidQryHandler Function pointer for the OID query handler.
2702* \param[IN] pvInfoBuf Points to a buffer for return the query information.
2703* \param[IN] u4QueryBufferLen Specifies the number of bytes at pvInfoBuf.
2704* \param[OUT] pu4QueryInfoLen Points to the number of bytes it written or is needed.
2705*
2706* \retval WLAN_STATUS_xxx Different WLAN_STATUS code returned by different handlers.
2707*
2708*/
2709/*----------------------------------------------------------------------------*/
2710WLAN_STATUS
2711wlanQueryInformation (
2712 IN P_ADAPTER_T prAdapter,
2713 IN PFN_OID_HANDLER_FUNC pfnOidQryHandler,
2714 IN PVOID pvInfoBuf,
2715 IN UINT_32 u4InfoBufLen,
2716 OUT PUINT_32 pu4QryInfoLen
2717 )
2718{
2719 WLAN_STATUS status = WLAN_STATUS_FAILURE;
2720
2721 ASSERT(prAdapter);
2722 ASSERT(pu4QryInfoLen);
2723
2724 // ignore any OID request after connected, under PS current measurement mode
2725 if (prAdapter->u4PsCurrentMeasureEn &&
2726 (prAdapter->prGlueInfo->eParamMediaStateIndicated == PARAM_MEDIA_STATE_CONNECTED)) {
2727 return WLAN_STATUS_SUCCESS; // note: return WLAN_STATUS_FAILURE or WLAN_STATUS_SUCCESS for blocking OIDs during current measurement ??
2728 }
2729
2730#if 1
2731 /* most OID handler will just queue a command packet */
2732 status = pfnOidQryHandler(prAdapter,
2733 pvInfoBuf,
2734 u4InfoBufLen,
2735 pu4QryInfoLen);
2736#else
2737 if (wlanIsHandlerNeedHwAccess(pfnOidQryHandler, FALSE)) {
2738 ACQUIRE_POWER_CONTROL_FROM_PM(prAdapter);
2739
2740 /* Reset sleepy state */
2741 if(prAdapter->fgWiFiInSleepyState == TRUE) {
2742 prAdapter->fgWiFiInSleepyState = FALSE;
2743 }
2744
2745 status = pfnOidQryHandler(prAdapter,
2746 pvInfoBuf,
2747 u4InfoBufLen,
2748 pu4QryInfoLen);
2749
2750 RECLAIM_POWER_CONTROL_TO_PM(prAdapter, FALSE);
2751 }
2752 else {
2753 status = pfnOidQryHandler(prAdapter,
2754 pvInfoBuf,
2755 u4InfoBufLen,
2756 pu4QryInfoLen);
2757 }
2758#endif
2759
2760 return status;
2761
2762}
2763
2764/*----------------------------------------------------------------------------*/
2765/*!
2766* \brief This function is a required function that allows bound protocol drivers,
2767* or NDIS, to request changes in the state information that the miniport
2768* maintains for particular object identifiers, such as changes in multicast
2769* addresses.
2770*
2771* \param[IN] prAdapter Pointer to the Glue info structure.
2772* \param[IN] pfnOidSetHandler Points to the OID set handlers.
2773* \param[IN] pvInfoBuf Points to a buffer containing the OID-specific data for the set.
2774* \param[IN] u4InfoBufLen Specifies the number of bytes at prSetBuffer.
2775* \param[OUT] pu4SetInfoLen Points to the number of bytes it read or is needed.
2776*
2777* \retval WLAN_STATUS_xxx Different WLAN_STATUS code returned by different handlers.
2778*
2779*/
2780/*----------------------------------------------------------------------------*/
2781WLAN_STATUS
2782wlanSetInformation (
2783 IN P_ADAPTER_T prAdapter,
2784 IN PFN_OID_HANDLER_FUNC pfnOidSetHandler,
2785 IN PVOID pvInfoBuf,
2786 IN UINT_32 u4InfoBufLen,
2787 OUT PUINT_32 pu4SetInfoLen
2788 )
2789{
2790 WLAN_STATUS status = WLAN_STATUS_FAILURE;
2791
2792 ASSERT(prAdapter);
2793 ASSERT(pu4SetInfoLen);
2794
2795 // ignore any OID request after connected, under PS current measurement mode
2796 if (prAdapter->u4PsCurrentMeasureEn &&
2797 (prAdapter->prGlueInfo->eParamMediaStateIndicated == PARAM_MEDIA_STATE_CONNECTED)) {
2798 return WLAN_STATUS_SUCCESS; // note: return WLAN_STATUS_FAILURE or WLAN_STATUS_SUCCESS for blocking OIDs during current measurement ??
2799 }
2800
2801#if 1
2802 /* most OID handler will just queue a command packet
2803 * for power state transition OIDs, handler will acquire power control by itself
2804 */
2805 status = pfnOidSetHandler(prAdapter,
2806 pvInfoBuf,
2807 u4InfoBufLen,
2808 pu4SetInfoLen);
2809#else
2810 if (wlanIsHandlerNeedHwAccess(pfnOidSetHandler, TRUE)) {
2811 ACQUIRE_POWER_CONTROL_FROM_PM(prAdapter);
2812
2813 /* Reset sleepy state */
2814 if(prAdapter->fgWiFiInSleepyState == TRUE) {
2815 prAdapter->fgWiFiInSleepyState = FALSE;
2816 }
2817
2818 status = pfnOidSetHandler(prAdapter,
2819 pvInfoBuf,
2820 u4InfoBufLen,
2821 pu4SetInfoLen);
2822
2823 RECLAIM_POWER_CONTROL_TO_PM(prAdapter, FALSE);
2824 }
2825 else {
2826 status = pfnOidSetHandler(prAdapter,
2827 pvInfoBuf,
2828 u4InfoBufLen,
2829 pu4SetInfoLen);
2830 }
2831#endif
2832
2833 return status;
2834}
2835
2836
2837#if CFG_SUPPORT_WAPI
2838/*----------------------------------------------------------------------------*/
2839/*!
2840* \brief This function is a used to query driver's config wapi mode or not
2841*
2842* \param[IN] prAdapter Pointer to the Glue info structure.
2843*
2844* \retval TRUE for use wapi mode
2845*
2846*/
2847/*----------------------------------------------------------------------------*/
2848BOOLEAN
2849wlanQueryWapiMode (
2850 IN P_ADAPTER_T prAdapter
2851 )
2852{
2853 ASSERT(prAdapter);
2854
2855 return prAdapter->rWifiVar.rConnSettings.fgWapiMode;
2856}
2857#endif
2858
2859
2860/*----------------------------------------------------------------------------*/
2861/*!
2862* \brief This function is called to set RX filter to Promiscuous Mode.
2863*
2864* \param[IN] prAdapter Pointer to the Adapter structure.
2865* \param[IN] fgEnablePromiscuousMode Enable/ disable RX Promiscuous Mode.
2866*
2867* \return (none)
2868*/
2869/*----------------------------------------------------------------------------*/
2870VOID
2871wlanSetPromiscuousMode (
2872 IN P_ADAPTER_T prAdapter,
2873 IN BOOLEAN fgEnablePromiscuousMode
2874 )
2875{
2876 ASSERT(prAdapter);
2877
2878}
2879
2880/*----------------------------------------------------------------------------*/
2881/*!
2882* \brief This function is called to set RX filter to allow to receive
2883* broadcast address packets.
2884*
2885* \param[IN] prAdapter Pointer to the Adapter structure.
2886* \param[IN] fgEnableBroadcast Enable/ disable broadcast packet to be received.
2887*
2888* \return (none)
2889*/
2890/*----------------------------------------------------------------------------*/
2891VOID
2892wlanRxSetBroadcast (
2893 IN P_ADAPTER_T prAdapter,
2894 IN BOOLEAN fgEnableBroadcast
2895 )
2896{
2897 ASSERT(prAdapter);
2898}
2899
2900/*----------------------------------------------------------------------------*/
2901/*!
2902* \brief This function is called to send out CMD_NIC_POWER_CTRL command packet
2903*
2904* \param[IN] prAdapter Pointer to the Adapter structure.
2905* \param[IN] ucPowerMode refer to CMD/EVENT document
2906*
2907* \return WLAN_STATUS_SUCCESS
2908* \return WLAN_STATUS_FAILURE
2909*/
2910/*----------------------------------------------------------------------------*/
2911WLAN_STATUS
2912wlanSendNicPowerCtrlCmd (
2913 IN P_ADAPTER_T prAdapter,
2914 IN UINT_8 ucPowerMode
2915 )
2916{
2917 WLAN_STATUS status = WLAN_STATUS_SUCCESS;
2918 P_GLUE_INFO_T prGlueInfo;
2919 P_CMD_INFO_T prCmdInfo;
2920 P_WIFI_CMD_T prWifiCmd;
2921 UINT_8 ucTC, ucCmdSeqNum;
2922
2923 ASSERT(prAdapter);
2924
2925 prGlueInfo = prAdapter->prGlueInfo;
2926
2927 /* 1. Prepare CMD */
2928 prCmdInfo = cmdBufAllocateCmdInfo(prAdapter, (CMD_HDR_SIZE + sizeof(CMD_NIC_POWER_CTRL)));
2929 if (!prCmdInfo) {
2930 DBGLOG(INIT, ERROR, ("Allocate CMD_INFO_T ==> FAILED.\n"));
2931 return WLAN_STATUS_FAILURE;
2932 }
2933
2934 /* 2.1 increase command sequence number */
2935 ucCmdSeqNum = nicIncreaseCmdSeqNum(prAdapter);
2936 DBGLOG(REQ, TRACE, ("ucCmdSeqNum =%d\n", ucCmdSeqNum));
2937
2938 /* 2.2 Setup common CMD Info Packet */
2939 prCmdInfo->eCmdType = COMMAND_TYPE_GENERAL_IOCTL;
2940 prCmdInfo->u2InfoBufLen = (UINT_16)(CMD_HDR_SIZE + sizeof(CMD_NIC_POWER_CTRL));
2941 prCmdInfo->pfCmdDoneHandler = NULL;
2942 prCmdInfo->pfCmdTimeoutHandler = NULL;
2943 prCmdInfo->fgIsOid = TRUE;
2944 prCmdInfo->ucCID = CMD_ID_NIC_POWER_CTRL;
2945 prCmdInfo->fgSetQuery = TRUE;
2946 prCmdInfo->fgNeedResp = FALSE;
2947 prCmdInfo->fgDriverDomainMCR = FALSE;
2948 prCmdInfo->ucCmdSeqNum = ucCmdSeqNum;
2949 prCmdInfo->u4SetInfoLen = sizeof(CMD_NIC_POWER_CTRL);
2950
2951 /* 2.3 Setup WIFI_CMD_T */
2952 prWifiCmd = (P_WIFI_CMD_T)(prCmdInfo->pucInfoBuffer);
2953 prWifiCmd->u2TxByteCount_UserPriority = prCmdInfo->u2InfoBufLen;
2954 prWifiCmd->ucCID = prCmdInfo->ucCID;
2955 prWifiCmd->ucSetQuery = prCmdInfo->fgSetQuery;
2956 prWifiCmd->ucSeqNum = prCmdInfo->ucCmdSeqNum;
2957
2958 kalMemZero(prWifiCmd->aucBuffer, sizeof(CMD_NIC_POWER_CTRL));
2959 ((P_CMD_NIC_POWER_CTRL)(prWifiCmd->aucBuffer))->ucPowerMode = ucPowerMode;
2960
2961 /* 3. Issue CMD for entering specific power mode */
2962 ucTC = TC4_INDEX;
2963
2964 while(1) {
2965 // 3.0 Removal check
2966 if(kalIsCardRemoved(prAdapter->prGlueInfo) == TRUE
2967 || fgIsBusAccessFailed == TRUE) {
2968 status = WLAN_STATUS_FAILURE;
2969 break;
2970 }
2971
2972 // 3.1 Acquire TX Resource
2973 if (nicTxAcquireResource(prAdapter, ucTC) == WLAN_STATUS_RESOURCES) {
2974
2975 /* wait and poll tx resource */
2976 if (nicTxPollingResource(prAdapter, ucTC) != WLAN_STATUS_SUCCESS) {
2977 DBGLOG(INIT, ERROR,("Fail to get TX resource return within timeout\n"));
2978 status = WLAN_STATUS_FAILURE;
2979 break;
2980 }
2981 else {
2982 continue;
2983 }
2984 }
2985
2986 // 3.2 Send CMD Info Packet
2987 if (nicTxCmd(prAdapter, prCmdInfo, ucTC) != WLAN_STATUS_SUCCESS) {
2988 DBGLOG(INIT, ERROR,("Fail to transmit CMD_NIC_POWER_CTRL command\n"));
2989 status = WLAN_STATUS_FAILURE;
2990 }
2991
2992 break;
2993 };
2994
2995 // 4. Free CMD Info Packet.
2996 cmdBufFreeCmdInfo(prAdapter, prCmdInfo);
2997
2998 // 5. Add flag
2999 if(ucPowerMode == 1) {
3000 prAdapter->fgIsEnterD3ReqIssued = TRUE;
3001 }
3002
3003 return status;
3004}
3005
3006
3007/*----------------------------------------------------------------------------*/
3008/*!
3009* \brief This function is called to check if it is RF test mode and
3010* the OID is allowed to be called or not
3011*
3012* \param[IN] prAdapter Pointer to the Adapter structure.
3013* \param[IN] fgEnableBroadcast Enable/ disable broadcast packet to be received.
3014*
3015* \return (none)
3016*/
3017/*----------------------------------------------------------------------------*/
3018BOOLEAN
3019wlanIsHandlerAllowedInRFTest (
3020 IN PFN_OID_HANDLER_FUNC pfnOidHandler,
3021 IN BOOLEAN fgSetInfo
3022 )
3023{
3024 PFN_OID_HANDLER_FUNC* apfnOidHandlerAllowedInRFTest;
3025 UINT_32 i;
3026 UINT_32 u4NumOfElem;
3027
3028 if (fgSetInfo) {
3029 apfnOidHandlerAllowedInRFTest = apfnOidSetHandlerAllowedInRFTest;
3030 u4NumOfElem = sizeof(apfnOidSetHandlerAllowedInRFTest) / sizeof(PFN_OID_HANDLER_FUNC);
3031 }
3032 else {
3033 apfnOidHandlerAllowedInRFTest = apfnOidQueryHandlerAllowedInRFTest;
3034 u4NumOfElem = sizeof(apfnOidQueryHandlerAllowedInRFTest) / sizeof(PFN_OID_HANDLER_FUNC);
3035 }
3036
3037 for (i = 0; i < u4NumOfElem; i++) {
3038 if (apfnOidHandlerAllowedInRFTest[i] == pfnOidHandler) {
3039 return TRUE;
3040 }
3041 }
3042
3043 return FALSE;
3044}
3045
3046#if CFG_ENABLE_FW_DOWNLOAD
3047 #if CFG_ENABLE_FW_DOWNLOAD_AGGREGATION
3048/*----------------------------------------------------------------------------*/
3049/*!
3050* @brief This function is called to download FW image in an aggregated way
3051*
3052* @param prAdapter Pointer to the Adapter structure.
3053*
3054* @return (none)
3055*/
3056/*----------------------------------------------------------------------------*/
3057WLAN_STATUS
3058wlanImageSectionDownloadAggregated (
3059 IN P_ADAPTER_T prAdapter,
3060 IN UINT_32 u4DestAddr,
3061 IN UINT_32 u4ImgSecSize,
3062 IN PUINT_8 pucImgSecBuf
3063 )
3064{
3065 #if defined(MT6620) || defined(MT6628)
3066 P_CMD_INFO_T prCmdInfo;
3067 P_INIT_HIF_TX_HEADER_T prInitHifTxHeader;
3068 P_INIT_CMD_DOWNLOAD_BUF prInitCmdDownloadBuf;
3069 UINT_8 ucTC, ucCmdSeqNum;
3070 WLAN_STATUS u4Status = WLAN_STATUS_SUCCESS;
3071 PUINT_8 pucOutputBuf = (PUINT_8)NULL; /* Pointer to Transmit Data Structure Frame */
3072 UINT_32 u4PktCnt, u4Offset, u4Length;
3073 UINT_32 u4TotalLength;
3074
3075 ASSERT(prAdapter);
3076 ASSERT(pucImgSecBuf);
3077
3078 pucOutputBuf = prAdapter->rTxCtrl.pucTxCoalescingBufPtr;
3079
3080 DEBUGFUNC("wlanImageSectionDownloadAggregated");
3081
3082 if (u4ImgSecSize == 0) {
3083 return WLAN_STATUS_SUCCESS;
3084 }
3085
3086 // 1. Allocate CMD Info Packet and Pre-fill Headers
3087 prCmdInfo = cmdBufAllocateCmdInfo(prAdapter,
3088 sizeof(INIT_HIF_TX_HEADER_T) + sizeof(INIT_CMD_DOWNLOAD_BUF) + CMD_PKT_SIZE_FOR_IMAGE);
3089
3090 if (!prCmdInfo) {
3091 DBGLOG(INIT, ERROR, ("Allocate CMD_INFO_T ==> FAILED.\n"));
3092 return WLAN_STATUS_FAILURE;
3093 }
3094
3095 prCmdInfo->u2InfoBufLen =
3096 sizeof(INIT_HIF_TX_HEADER_T) + sizeof(INIT_CMD_DOWNLOAD_BUF) + CMD_PKT_SIZE_FOR_IMAGE;
3097
3098 // 2. Use TC0's resource to download image. (only TC0 is allowed)
3099 ucTC = TC0_INDEX;
3100
3101 // 3. Setup common CMD Info Packet
3102 prInitHifTxHeader = (P_INIT_HIF_TX_HEADER_T)(prCmdInfo->pucInfoBuffer);
3103 prInitHifTxHeader->ucEtherTypeOffset = 0;
3104 prInitHifTxHeader->ucCSflags = 0;
3105 prInitHifTxHeader->rInitWifiCmd.ucCID = INIT_CMD_ID_DOWNLOAD_BUF;
3106
3107 // 4. Setup CMD_DOWNLOAD_BUF
3108 prInitCmdDownloadBuf = (P_INIT_CMD_DOWNLOAD_BUF)(prInitHifTxHeader->rInitWifiCmd.aucBuffer);
3109 prInitCmdDownloadBuf->u4DataMode = 0
3110 #if CFG_ENABLE_FW_ENCRYPTION
3111 | DOWNLOAD_BUF_ENCRYPTION_MODE
3112 #endif
3113 ;
3114
3115 // 5.0 reset loop control variable
3116 u4TotalLength = 0;
3117 u4Offset = u4PktCnt = 0;
3118
3119 // 5.1 main loop for maximize transmission count per access
3120 while(u4Offset < u4ImgSecSize) {
3121 if(nicTxAcquireResource(prAdapter, ucTC) == WLAN_STATUS_SUCCESS) {
3122 // 5.1.1 calculate u4Length
3123 if(u4Offset + CMD_PKT_SIZE_FOR_IMAGE < u4ImgSecSize) {
3124 u4Length = CMD_PKT_SIZE_FOR_IMAGE;
3125 }
3126 else {
3127 u4Length = u4ImgSecSize - u4Offset;
3128 }
3129
3130 // 5.1.1 increase command sequence number
3131 ucCmdSeqNum = nicIncreaseCmdSeqNum(prAdapter);
3132 prInitHifTxHeader->rInitWifiCmd.ucSeqNum = ucCmdSeqNum;
3133
3134 // 5.1.2 update HIF TX hardware header
3135 prInitHifTxHeader->u2TxByteCount = ALIGN_4(sizeof(INIT_HIF_TX_HEADER_T) + sizeof(INIT_CMD_DOWNLOAD_BUF) + (UINT_16)u4Length);
3136
3137 // 5.1.3 fill command header
3138 prInitCmdDownloadBuf->u4Address = u4DestAddr + u4Offset;
3139 prInitCmdDownloadBuf->u4Length = u4Length;
3140 prInitCmdDownloadBuf->u4CRC32 = wlanCRC32(pucImgSecBuf + u4Offset, u4Length);
3141
3142 // 5.1.4.1 copy header to coalescing buffer
3143 kalMemCopy(pucOutputBuf + u4TotalLength,
3144 (PVOID)prCmdInfo->pucInfoBuffer,
3145 sizeof(INIT_HIF_TX_HEADER_T) + sizeof(INIT_CMD_DOWNLOAD_BUF));
3146
3147 // 5.1.4.2 copy payload to coalescing buffer
3148 kalMemCopy(pucOutputBuf + u4TotalLength + sizeof(INIT_HIF_TX_HEADER_T) + sizeof(INIT_CMD_DOWNLOAD_BUF),
3149 pucImgSecBuf + u4Offset,
3150 u4Length);
3151
3152 // 5.1.4.3 update length and other variables
3153 u4TotalLength += ALIGN_4(sizeof(INIT_HIF_TX_HEADER_T) + sizeof(INIT_CMD_DOWNLOAD_BUF) + u4Length);
3154 u4Offset += u4Length;
3155 u4PktCnt++;
3156
3157 if(u4Offset < u4ImgSecSize) {
3158 continue;
3159 }
3160 }
3161 else if(u4PktCnt == 0) {
3162 /* no resource, so get some back */
3163 if (nicTxPollingResource(prAdapter, ucTC) != WLAN_STATUS_SUCCESS) {
3164 u4Status = WLAN_STATUS_FAILURE;
3165 DBGLOG(INIT, ERROR,("Fail to get TX resource return within timeout\n"));
3166 break;
3167 }
3168 }
3169
3170 if(u4PktCnt != 0) {
3171 // start transmission
3172 HAL_WRITE_TX_PORT(prAdapter,
3173 0,
3174 u4TotalLength,
3175 (PUINT_8)pucOutputBuf,
3176 prAdapter->u4CoalescingBufCachedSize);
3177
3178 // reset varaibles
3179 u4PktCnt = 0;
3180 u4TotalLength = 0;
3181 }
3182 }
3183
3184 // 8. Free CMD Info Packet.
3185 cmdBufFreeCmdInfo(prAdapter, prCmdInfo);
3186
3187 return u4Status;
3188
3189 #else
3190 #error "Only MT6620/MT6628/MT6582 supports firmware download in an aggregated way"
3191
3192 return WLAN_STATUS_FAILURE;
3193
3194 #endif
3195}
3196
3197 #endif
3198/*----------------------------------------------------------------------------*/
3199/*!
3200* @brief This function is called to download FW image.
3201*
3202* @param prAdapter Pointer to the Adapter structure.
3203*
3204* @return (none)
3205*/
3206/*----------------------------------------------------------------------------*/
3207WLAN_STATUS
3208wlanImageSectionDownload (
3209 IN P_ADAPTER_T prAdapter,
3210 IN UINT_32 u4DestAddr,
3211 IN UINT_32 u4ImgSecSize,
3212 IN PUINT_8 pucImgSecBuf
3213 )
3214{
3215 #if defined(MT6620) || defined(MT6628)
3216
3217 P_CMD_INFO_T prCmdInfo;
3218 P_INIT_HIF_TX_HEADER_T prInitHifTxHeader;
3219 P_INIT_CMD_DOWNLOAD_BUF prInitCmdDownloadBuf;
3220 UINT_8 ucTC, ucCmdSeqNum;
3221 WLAN_STATUS u4Status = WLAN_STATUS_SUCCESS;
3222
3223 ASSERT(prAdapter);
3224 ASSERT(pucImgSecBuf);
3225 ASSERT(u4ImgSecSize <= CMD_PKT_SIZE_FOR_IMAGE);
3226
3227 DEBUGFUNC("wlanImageSectionDownload");
3228
3229 if (u4ImgSecSize == 0) {
3230 return WLAN_STATUS_SUCCESS;
3231 }
3232
3233 // 1. Allocate CMD Info Packet and its Buffer.
3234 prCmdInfo = cmdBufAllocateCmdInfo(prAdapter,
3235 sizeof(INIT_HIF_TX_HEADER_T) + sizeof(INIT_CMD_DOWNLOAD_BUF) + u4ImgSecSize);
3236
3237 if (!prCmdInfo) {
3238 DBGLOG(INIT, ERROR, ("Allocate CMD_INFO_T ==> FAILED.\n"));
3239 return WLAN_STATUS_FAILURE;
3240 }
3241
3242 prCmdInfo->u2InfoBufLen =
3243 sizeof(INIT_HIF_TX_HEADER_T) + sizeof(INIT_CMD_DOWNLOAD_BUF) + (UINT_16)u4ImgSecSize;
3244
3245 // 2. Use TC0's resource to download image. (only TC0 is allowed)
3246 ucTC = TC0_INDEX;
3247
3248 // 3. increase command sequence number
3249 ucCmdSeqNum = nicIncreaseCmdSeqNum(prAdapter);
3250
3251 // 4. Setup common CMD Info Packet
3252 prInitHifTxHeader = (P_INIT_HIF_TX_HEADER_T)(prCmdInfo->pucInfoBuffer);
3253 prInitHifTxHeader->rInitWifiCmd.ucCID = INIT_CMD_ID_DOWNLOAD_BUF;
3254 prInitHifTxHeader->rInitWifiCmd.ucSeqNum = ucCmdSeqNum;
3255
3256 // 5. Setup CMD_DOWNLOAD_BUF
3257 prInitCmdDownloadBuf = (P_INIT_CMD_DOWNLOAD_BUF)(prInitHifTxHeader->rInitWifiCmd.aucBuffer);
3258 prInitCmdDownloadBuf->u4Address = u4DestAddr;
3259 prInitCmdDownloadBuf->u4Length = u4ImgSecSize;
3260 prInitCmdDownloadBuf->u4CRC32 = wlanCRC32(pucImgSecBuf, u4ImgSecSize);
3261
3262 prInitCmdDownloadBuf->u4DataMode = 0
3263#if CFG_ENABLE_FW_DOWNLOAD_ACK
3264 | DOWNLOAD_BUF_ACK_OPTION // ACK needed
3265#endif
3266#if CFG_ENABLE_FW_ENCRYPTION
3267 | DOWNLOAD_BUF_ENCRYPTION_MODE
3268#endif
3269 ;
3270
3271 kalMemCopy(prInitCmdDownloadBuf->aucBuffer, pucImgSecBuf, u4ImgSecSize);
3272
3273 // 6. Send FW_Download command
3274 while(1) {
3275 // 6.1 Acquire TX Resource
3276 if (nicTxAcquireResource(prAdapter, ucTC) == WLAN_STATUS_RESOURCES) {
3277 if (nicTxPollingResource(prAdapter, ucTC) != WLAN_STATUS_SUCCESS) {
3278 u4Status = WLAN_STATUS_FAILURE;
3279 DBGLOG(INIT, ERROR,("Fail to get TX resource return within timeout\n"));
3280 break;
3281 }
3282 else {
3283 continue;
3284 }
3285 }
3286
3287 // 6.2 Send CMD Info Packet
3288 if (nicTxInitCmd(prAdapter, prCmdInfo, ucTC) != WLAN_STATUS_SUCCESS) {
3289 u4Status = WLAN_STATUS_FAILURE;
3290 DBGLOG(INIT, ERROR,("Fail to transmit image download command\n"));
3291 }
3292
3293 break;
3294 };
3295
3296#if CFG_ENABLE_FW_DOWNLOAD_ACK
3297 // 7. Wait for INIT_EVENT_ID_CMD_RESULT
3298 u4Status = wlanImageSectionDownloadStatus(prAdapter, ucCmdSeqNum);
3299#endif
3300
3301 // 8. Free CMD Info Packet.
3302 cmdBufFreeCmdInfo(prAdapter, prCmdInfo);
3303
3304 return u4Status;
3305
3306#elif defined(MT5931)
3307
3308 UINT_32 i, u4Value;
3309 P_HIF_HW_TX_HEADER_T prHifTxHeader;
3310
3311 WLAN_STATUS u4Status = WLAN_STATUS_SUCCESS;
3312
3313 ASSERT(prAdapter);
3314 ASSERT(pucImgSecBuf);
3315 ASSERT(u4ImgSecSize <= CMD_PKT_SIZE_FOR_IMAGE);
3316
3317 DEBUGFUNC("wlanImageSectionDownload");
3318 DBGLOG(INIT, TRACE, ("Destination: 0x%08X / Length: 0x%08X\n", u4DestAddr, u4ImgSecSize));
3319
3320 if (u4ImgSecSize == 0) {
3321 return WLAN_STATUS_SUCCESS;
3322 }
3323
3324 // 1. Use TX coalescing buffer
3325 prHifTxHeader = (P_HIF_HW_TX_HEADER_T) prAdapter->pucCoalescingBufCached;
3326
3327 // 2. Setup HIF_TX_HEADER
3328 prHifTxHeader->u2TxByteCount = (UINT_16)(ALIGN_4(sizeof(HIF_HW_TX_HEADER_T) + u4ImgSecSize));
3329 prHifTxHeader->ucEtherTypeOffset = 0;
3330 prHifTxHeader->ucCSflags = 0;
3331
3332 // 3. Copy payload
3333 kalMemCopy(prHifTxHeader->aucBuffer, pucImgSecBuf, u4ImgSecSize);
3334
3335 // 3.1 add 4-bytes zero tail
3336 kalMemZero(&(prHifTxHeader->aucBuffer[ALIGN_4(u4ImgSecSize)]), sizeof(HIF_HW_TX_HEADER_T));
3337
3338 // 4. Poll til FWDL_RDY = 1
3339 i = 0;
3340 while(1) {
3341 HAL_MCR_RD(prAdapter, MCR_FWDLSR, &u4Value);
3342
3343 if (u4Value & FWDLSR_FWDL_RDY) {
3344 DBGLOG(INIT, TRACE, ("FWDL_RDY detected\n"));
3345 break;
3346 }
3347 else if(kalIsCardRemoved(prAdapter->prGlueInfo) == TRUE
3348 || fgIsBusAccessFailed == TRUE) {
3349 u4Status = WLAN_STATUS_FAILURE;
3350 break;
3351 }
3352 else if(i >= CFG_RESPONSE_POLLING_TIMEOUT) {
3353 DBGLOG(INIT, ERROR, ("Waiting for FWDL_RDY: Timeout (0x%08X)\n", u4Value));
3354 u4Status = WLAN_STATUS_FAILURE;
3355 break;
3356 }
3357 else {
3358 i++;
3359 kalMsleep(10);
3360 }
3361 }
3362
3363 // 5. Send firmware
3364 HAL_PORT_WR(prAdapter,
3365 MCR_FWDLDR,
3366 prHifTxHeader->u2TxByteCount,
3367 (PUINT_8)prHifTxHeader,
3368 prAdapter->u4CoalescingBufCachedSize);
3369
3370 return u4Status;
3371
3372 #endif
3373}
3374
3375#if !CFG_ENABLE_FW_DOWNLOAD_ACK
3376/*----------------------------------------------------------------------------*/
3377/*!
3378* @brief This function is called to confirm previously firmware download is done without error
3379*
3380* @param prAdapter Pointer to the Adapter structure.
3381*
3382* @return (none)
3383*/
3384/*----------------------------------------------------------------------------*/
3385WLAN_STATUS
3386wlanImageQueryStatus(
3387 IN P_ADAPTER_T prAdapter
3388 )
3389{
3390 P_CMD_INFO_T prCmdInfo;
3391 P_INIT_HIF_TX_HEADER_T prInitHifTxHeader;
3392 UINT_8 aucBuffer[sizeof(INIT_HIF_RX_HEADER_T) + sizeof(INIT_EVENT_PENDING_ERROR)];
3393 UINT_32 u4RxPktLength;
3394 P_INIT_HIF_RX_HEADER_T prInitHifRxHeader;
3395 P_INIT_EVENT_PENDING_ERROR prEventPendingError;
3396 WLAN_STATUS u4Status = WLAN_STATUS_SUCCESS;
3397 UINT_8 ucTC, ucCmdSeqNum;
3398
3399 ASSERT(prAdapter);
3400
3401 DEBUGFUNC("wlanImageQueryStatus");
3402
3403 // 1. Allocate CMD Info Packet and it Buffer.
3404 prCmdInfo = cmdBufAllocateCmdInfo(prAdapter, sizeof(INIT_HIF_TX_HEADER_T));
3405
3406 if (!prCmdInfo) {
3407 DBGLOG(INIT, ERROR, ("Allocate CMD_INFO_T ==> FAILED.\n"));
3408 return WLAN_STATUS_FAILURE;
3409 }
3410
3411 kalMemZero(prCmdInfo, sizeof(INIT_HIF_TX_HEADER_T));
3412 prCmdInfo->u2InfoBufLen = sizeof(INIT_HIF_TX_HEADER_T);
3413
3414 // 2. Use TC0's resource to download image. (only TC0 is allowed)
3415 ucTC = TC0_INDEX;
3416
3417 // 3. increase command sequence number
3418 ucCmdSeqNum = nicIncreaseCmdSeqNum(prAdapter);
3419
3420 // 4. Setup common CMD Info Packet
3421 prInitHifTxHeader = (P_INIT_HIF_TX_HEADER_T)(prCmdInfo->pucInfoBuffer);
3422 prInitHifTxHeader->rInitWifiCmd.ucCID = INIT_CMD_ID_QUERY_PENDING_ERROR;
3423 prInitHifTxHeader->rInitWifiCmd.ucSeqNum = ucCmdSeqNum;
3424
3425 // 5. Send command
3426 while(1) {
3427 // 5.1 Acquire TX Resource
3428 if (nicTxAcquireResource(prAdapter, ucTC) == WLAN_STATUS_RESOURCES) {
3429 if (nicTxPollingResource(prAdapter, ucTC) != WLAN_STATUS_SUCCESS) {
3430 u4Status = WLAN_STATUS_FAILURE;
3431 DBGLOG(INIT, ERROR,("Fail to get TX resource return within timeout\n"));
3432 break;
3433 }
3434 else {
3435 continue;
3436 }
3437 }
3438
3439 // 5.2 Send CMD Info Packet
3440 if (nicTxInitCmd(prAdapter, prCmdInfo, ucTC) != WLAN_STATUS_SUCCESS) {
3441 u4Status = WLAN_STATUS_FAILURE;
3442 DBGLOG(INIT, ERROR,("Fail to transmit image download command\n"));
3443 }
3444
3445 break;
3446 };
3447
3448 // 6. Wait for INIT_EVENT_ID_PENDING_ERROR
3449 do {
3450 if(kalIsCardRemoved(prAdapter->prGlueInfo) == TRUE
3451 || fgIsBusAccessFailed == TRUE) {
3452 u4Status = WLAN_STATUS_FAILURE;
3453 }
3454 else if(nicRxWaitResponse(prAdapter,
3455 0,
3456 aucBuffer,
3457 sizeof(INIT_HIF_RX_HEADER_T) + sizeof(INIT_EVENT_PENDING_ERROR),
3458 &u4RxPktLength) != WLAN_STATUS_SUCCESS) {
3459 u4Status = WLAN_STATUS_FAILURE;
3460 }
3461 else {
3462 prInitHifRxHeader = (P_INIT_HIF_RX_HEADER_T) aucBuffer;
3463
3464 // EID / SeqNum check
3465 if(prInitHifRxHeader->rInitWifiEvent.ucEID != INIT_EVENT_ID_PENDING_ERROR) {
3466 u4Status = WLAN_STATUS_FAILURE;
3467 }
3468 else if(prInitHifRxHeader->rInitWifiEvent.ucSeqNum != ucCmdSeqNum) {
3469 u4Status = WLAN_STATUS_FAILURE;
3470 }
3471 else {
3472 prEventPendingError = (P_INIT_EVENT_PENDING_ERROR) (prInitHifRxHeader->rInitWifiEvent.aucBuffer);
3473 if(prEventPendingError->ucStatus != 0) { // 0 for download success
3474 u4Status = WLAN_STATUS_FAILURE;
3475 }
3476 else {
3477 u4Status = WLAN_STATUS_SUCCESS;
3478 }
3479 }
3480 }
3481 } while (FALSE);
3482
3483 // 7. Free CMD Info Packet.
3484 cmdBufFreeCmdInfo(prAdapter, prCmdInfo);
3485
3486 return u4Status;
3487}
3488
3489
3490#else
3491/*----------------------------------------------------------------------------*/
3492/*!
3493* @brief This function is called to confirm the status of
3494* previously downloaded firmware scatter
3495*
3496* @param prAdapter Pointer to the Adapter structure.
3497* ucCmdSeqNum Sequence number of previous firmware scatter
3498*
3499* @return WLAN_STATUS_SUCCESS
3500* WLAN_STATUS_FAILURE
3501*/
3502/*----------------------------------------------------------------------------*/
3503WLAN_STATUS
3504wlanImageSectionDownloadStatus (
3505 IN P_ADAPTER_T prAdapter,
3506 IN UINT_8 ucCmdSeqNum
3507 )
3508{
3509 UINT_8 aucBuffer[sizeof(INIT_HIF_RX_HEADER_T) + sizeof(INIT_EVENT_CMD_RESULT)];
3510 P_INIT_HIF_RX_HEADER_T prInitHifRxHeader;
3511 P_INIT_EVENT_CMD_RESULT prEventCmdResult;
3512 UINT_32 u4RxPktLength;
3513 WLAN_STATUS u4Status;
3514
3515 ASSERT(prAdapter);
3516
3517 do {
3518 if(kalIsCardRemoved(prAdapter->prGlueInfo) == TRUE
3519 || fgIsBusAccessFailed == TRUE) {
3520 DBGLOG(INIT, ERROR,("kalIsCardRemoved or fgIsBusAccessFailed\n"));
3521 u4Status = WLAN_STATUS_FAILURE;
3522 }
3523 else if(nicRxWaitResponse(prAdapter,
3524 0,
3525 aucBuffer,
3526 sizeof(INIT_HIF_RX_HEADER_T) + sizeof(INIT_EVENT_CMD_RESULT), /* 4B + 4B */
3527 &u4RxPktLength) != WLAN_STATUS_SUCCESS) {
3528
3529 DBGLOG(INIT, ERROR,("nicRxWaitResponse fail\n"));
3530 u4Status = WLAN_STATUS_FAILURE;
3531 }
3532 else {
3533 prInitHifRxHeader = (P_INIT_HIF_RX_HEADER_T) aucBuffer;
3534
3535 // EID / SeqNum check
3536 if(prInitHifRxHeader->rInitWifiEvent.ucEID != INIT_EVENT_ID_CMD_RESULT) {
3537 DBGLOG(INIT, ERROR,("rInitWifiEvent.ucEID != INIT_EVENT_ID_CMD_RESULT\n"));
3538 u4Status = WLAN_STATUS_FAILURE;
3539 }
3540 else if(prInitHifRxHeader->rInitWifiEvent.ucSeqNum != ucCmdSeqNum) {
3541 DBGLOG(INIT, ERROR,("rInitWifiEvent.ucSeqNum != ucCmdSeqNum\n"));
3542 u4Status = WLAN_STATUS_FAILURE;
3543 }
3544 else {
3545 prEventCmdResult = (P_INIT_EVENT_CMD_RESULT) (prInitHifRxHeader->rInitWifiEvent.aucBuffer);
3546 if(prEventCmdResult->ucStatus != 0) { // 0 for download success
3547 /*
3548 0: success
3549 1: rejected by invalid param
3550 2: rejected by incorrect CRC
3551 3: rejected by decryption failure
3552 4: unknown CMD
3553 */
3554 DBGLOG(INIT, ERROR, ("Read Response status error = %d\n",
3555 prEventCmdResult->ucStatus));
3556 u4Status = WLAN_STATUS_FAILURE;
3557 }
3558 else {
3559 u4Status = WLAN_STATUS_SUCCESS;
3560 }
3561 }
3562 }
3563 } while (FALSE);
3564
3565 return u4Status;
3566}
3567
3568
3569#endif
3570/*----------------------------------------------------------------------------*/
3571/*!
3572* @brief This function is called to start FW normal operation.
3573*
3574* @param prAdapter Pointer to the Adapter structure.
3575*
3576* @return (none)
3577*/
3578/*----------------------------------------------------------------------------*/
3579WLAN_STATUS
3580wlanConfigWifiFunc (
3581 IN P_ADAPTER_T prAdapter,
3582 IN BOOLEAN fgEnable,
3583 IN UINT_32 u4StartAddress
3584 )
3585{
3586 P_CMD_INFO_T prCmdInfo;
3587 P_INIT_HIF_TX_HEADER_T prInitHifTxHeader;
3588 P_INIT_CMD_WIFI_START prInitCmdWifiStart;
3589 UINT_8 ucTC, ucCmdSeqNum;
3590 WLAN_STATUS u4Status = WLAN_STATUS_SUCCESS;
3591
3592 ASSERT(prAdapter);
3593
3594 DEBUGFUNC("wlanConfigWifiFunc");
3595
3596 // 1. Allocate CMD Info Packet and its Buffer.
3597 prCmdInfo = cmdBufAllocateCmdInfo(prAdapter,
3598 sizeof(INIT_HIF_TX_HEADER_T) + sizeof(INIT_CMD_WIFI_START));
3599
3600 if (!prCmdInfo) {
3601 DBGLOG(INIT, ERROR, ("Allocate CMD_INFO_T ==> FAILED.\n"));
3602 return WLAN_STATUS_FAILURE;
3603 }
3604
3605 kalMemZero(prCmdInfo, sizeof(INIT_HIF_TX_HEADER_T) + sizeof(INIT_CMD_WIFI_START));
3606 prCmdInfo->u2InfoBufLen =
3607 sizeof(INIT_HIF_TX_HEADER_T) + sizeof(INIT_CMD_WIFI_START);
3608
3609 // 2. Always use TC0
3610 ucTC = TC0_INDEX;
3611
3612 // 3. increase command sequence number
3613 ucCmdSeqNum = nicIncreaseCmdSeqNum(prAdapter);
3614
3615 // 4. Setup common CMD Info Packet
3616 prInitHifTxHeader = (P_INIT_HIF_TX_HEADER_T)(prCmdInfo->pucInfoBuffer);
3617 prInitHifTxHeader->rInitWifiCmd.ucCID = INIT_CMD_ID_WIFI_START;
3618 prInitHifTxHeader->rInitWifiCmd.ucSeqNum = ucCmdSeqNum;
3619
3620 prInitCmdWifiStart = (P_INIT_CMD_WIFI_START)(prInitHifTxHeader->rInitWifiCmd.aucBuffer);
3621 prInitCmdWifiStart->u4Override = (fgEnable == TRUE ? 1 : 0);
3622 prInitCmdWifiStart->u4Address = u4StartAddress;
3623
3624 // 5. Seend WIFI start command
3625 while(1) {
3626 // 5.1 Acquire TX Resource
3627 if (nicTxAcquireResource(prAdapter, ucTC) == WLAN_STATUS_RESOURCES) {
3628
3629 /* wait and poll tx resource */
3630 if (nicTxPollingResource(prAdapter, ucTC) != WLAN_STATUS_SUCCESS) {
3631 u4Status = WLAN_STATUS_FAILURE;
3632 DBGLOG(INIT, ERROR,("Fail to get TX resource return within timeout\n"));
3633 break;
3634 }
3635 else {
3636 continue;
3637 }
3638 }
3639
3640 // 5.2 Send CMD Info Packet
3641 if (nicTxInitCmd(prAdapter, prCmdInfo, ucTC) != WLAN_STATUS_SUCCESS) {
3642 u4Status = WLAN_STATUS_FAILURE;
3643 DBGLOG(INIT, ERROR,("Fail to transmit WIFI start command\n"));
3644 }
3645
3646 break;
3647 };
3648
3649 // 6. Free CMD Info Packet.
3650 cmdBufFreeCmdInfo(prAdapter, prCmdInfo);
3651
3652 return u4Status;
3653}
3654
3655
3656/*----------------------------------------------------------------------------*/
3657/*!
3658* @brief This function is used to generate CRC32 checksum
3659*
3660* @param buf Pointer to the data.
3661* @param len data length
3662*
3663* @return crc32 value
3664*/
3665/*----------------------------------------------------------------------------*/
3666UINT_32 wlanCRC32(
3667 PUINT_8 buf,
3668 UINT_32 len)
3669{
3670 UINT_32 i, crc32 = 0xFFFFFFFF;
3671 const UINT_32 crc32_ccitt_table[256] = {
3672 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
3673 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
3674 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
3675 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
3676 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
3677 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
3678 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
3679 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
3680 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
3681 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
3682 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
3683 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
3684 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
3685 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
3686 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
3687 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
3688 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
3689 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
3690 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
3691 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
3692 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
3693 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
3694 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
3695 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
3696 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
3697 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
3698 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
3699 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
3700 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
3701 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
3702 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
3703 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
3704 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
3705 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
3706 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
3707 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
3708 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
3709 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
3710 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
3711 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
3712 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
3713 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
3714 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
3715 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
3716 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
3717 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
3718 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
3719 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
3720 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
3721 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
3722 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
3723 0x2d02ef8d };
3724
3725 for (i = 0; i < len; i++)
3726 crc32 = crc32_ccitt_table[(crc32 ^ buf[i]) & 0xff] ^ (crc32 >> 8);
3727
3728 return ( ~crc32 );
3729}
3730#endif
3731
3732
3733/*----------------------------------------------------------------------------*/
3734/*!
3735* @brief This function is called to process queued RX packets
3736*
3737* @param prAdapter Pointer to the Adapter structure.
3738* prSwRfbListHead Pointer to head of RX packets link list
3739*
3740* @return (none)
3741*/
3742/*----------------------------------------------------------------------------*/
3743WLAN_STATUS
3744wlanProcessQueuedSwRfb (
3745 IN P_ADAPTER_T prAdapter,
3746 IN P_SW_RFB_T prSwRfbListHead
3747 )
3748{
3749 P_SW_RFB_T prSwRfb, prNextSwRfb;
3750 P_TX_CTRL_T prTxCtrl;
3751 P_RX_CTRL_T prRxCtrl;
3752
3753 ASSERT(prAdapter);
3754 ASSERT(prSwRfbListHead);
3755
3756 prTxCtrl = &prAdapter->rTxCtrl;
3757 prRxCtrl = &prAdapter->rRxCtrl;
3758
3759 prSwRfb = prSwRfbListHead;
3760
3761 do {
3762 // save next first
3763 prNextSwRfb = (P_SW_RFB_T)QUEUE_GET_NEXT_ENTRY((P_QUE_ENTRY_T)prSwRfb);
3764
3765 switch(prSwRfb->eDst) {
3766 case RX_PKT_DESTINATION_HOST:
3767 /* to host */
3768 nicRxProcessPktWithoutReorder(prAdapter, prSwRfb);
3769 break;
3770
3771 case RX_PKT_DESTINATION_FORWARD:
3772 /* need ot forward */
3773 nicRxProcessForwardPkt(prAdapter, prSwRfb);
3774 break;
3775
3776 case RX_PKT_DESTINATION_HOST_WITH_FORWARD:
3777 /* to host and forward */
3778 nicRxProcessGOBroadcastPkt(prAdapter, prSwRfb);
3779 break;
3780
3781 case RX_PKT_DESTINATION_NULL:
3782 /* free it */
3783 nicRxReturnRFB(prAdapter, prSwRfb);
3784 break;
3785
3786 default:
3787 break;
3788 }
3789
3790#if CFG_HIF_RX_STARVATION_WARNING
3791 prRxCtrl->u4DequeuedCnt++;
3792#endif
3793
3794 /* check next queued packet */
3795 prSwRfb = prNextSwRfb;
3796 } while(prSwRfb);
3797
3798 return WLAN_STATUS_SUCCESS;
3799}
3800
3801
3802/*----------------------------------------------------------------------------*/
3803/*!
3804* @brief This function is called to purge queued TX packets
3805* by indicating failure to OS and returned to free list
3806*
3807* @param prAdapter Pointer to the Adapter structure.
3808* prMsduInfoListHead Pointer to head of TX packets link list
3809*
3810* @return (none)
3811*/
3812/*----------------------------------------------------------------------------*/
3813WLAN_STATUS
3814wlanProcessQueuedMsduInfo (
3815 IN P_ADAPTER_T prAdapter,
3816 IN P_MSDU_INFO_T prMsduInfoListHead
3817 )
3818{
3819 ASSERT(prAdapter);
3820 ASSERT(prMsduInfoListHead);
3821
3822 nicTxFreeMsduInfoPacket(prAdapter, prMsduInfoListHead);
3823 nicTxReturnMsduInfo(prAdapter, prMsduInfoListHead);
3824
3825 return WLAN_STATUS_SUCCESS;
3826}
3827
3828
3829/*----------------------------------------------------------------------------*/
3830/*!
3831* @brief This function is called to check if the OID handler needs timeout
3832*
3833* @param prAdapter Pointer to the Adapter structure.
3834* pfnOidHandler Pointer to the OID handler
3835*
3836* @return TRUE
3837* FALSE
3838*/
3839/*----------------------------------------------------------------------------*/
3840BOOLEAN
3841wlanoidTimeoutCheck (
3842 IN P_ADAPTER_T prAdapter,
3843 IN PFN_OID_HANDLER_FUNC pfnOidHandler
3844 )
3845{
3846 PFN_OID_HANDLER_FUNC* apfnOidHandlerWOTimeoutCheck;
3847 UINT_32 i;
3848 UINT_32 u4NumOfElem;
3849
3850 apfnOidHandlerWOTimeoutCheck = apfnOidWOTimeoutCheck;
3851 u4NumOfElem = sizeof(apfnOidWOTimeoutCheck) / sizeof(PFN_OID_HANDLER_FUNC);
3852
3853 /* skip some OID timeout checks ? */
3854 for (i = 0; i < u4NumOfElem; i++) {
3855 if (apfnOidHandlerWOTimeoutCheck[i] == pfnOidHandler) {
3856 return FALSE;
3857 }
3858 }
3859
3860 // set timer if need timeout check
3861 //cnmTimerStartTimer(prAdapter,
3862 // &(prAdapter->rOidTimeoutTimer),
3863 // 1000);
3864 cnmTimerStartTimer(prAdapter,
3865 &(prAdapter->rOidTimeoutTimer),
3866 2000);
3867
3868 return TRUE;
3869}
3870
3871
3872/*----------------------------------------------------------------------------*/
3873/*!
3874* @brief This function is called to clear any pending OID timeout check
3875*
3876* @param prAdapter Pointer to the Adapter structure.
3877*
3878* @return none
3879*/
3880/*----------------------------------------------------------------------------*/
3881VOID
3882wlanoidClearTimeoutCheck (
3883 IN P_ADAPTER_T prAdapter
3884 )
3885{
3886 ASSERT(prAdapter);
3887
3888 cnmTimerStopTimer(prAdapter, &(prAdapter->rOidTimeoutTimer));
3889}
3890
3891
3892/*----------------------------------------------------------------------------*/
3893/*!
3894* @brief This function is called to set up the MCUSYS's OSC stable time
3895*
3896* @param prAdapter Pointer to the Adapter structure.
3897*
3898* @return none
3899*/
3900/*----------------------------------------------------------------------------*/
3901
3902#if CFG_SUPPORT_OSC_SETTING && defined(MT5931)
3903WLAN_STATUS
3904wlanSetMcuOscStableTime (
3905 IN P_ADAPTER_T prAdapter,
3906 IN UINT_16 u2OscStableTime
3907 )
3908{
3909 UINT_8 ucCmdSeqNum = 0;
3910 P_CMD_INFO_T prCmdInfo = NULL;
3911 P_WIFI_CMD_T prWifiCmd = NULL;
3912 P_CMD_MCU_LP_PARAM_T prMcuSetOscCmd = NULL;
3913 WLAN_STATUS status = WLAN_STATUS_SUCCESS;
3914
3915 ASSERT(prAdapter);
3916
3917 prCmdInfo = cmdBufAllocateCmdInfo(prAdapter,
3918 CMD_HDR_SIZE + sizeof(CMD_MCU_LP_PARAM_T));
3919
3920 if (!prCmdInfo) {
3921 DBGLOG(INIT, ERROR, ("Allocate CMD_INFO_T ==> FAILED.\n"));
3922 return WLAN_STATUS_FAILURE;
3923 }
3924
3925 // increase command sequence number
3926 ucCmdSeqNum = nicIncreaseCmdSeqNum(prAdapter);
3927
3928 // compose CMD_MCU_LP_PARAM_T cmd pkt
3929 prCmdInfo->eCmdType = COMMAND_TYPE_GENERAL_IOCTL;
3930 prCmdInfo->u2InfoBufLen = CMD_HDR_SIZE + sizeof(CMD_MCU_LP_PARAM_T);
3931 prCmdInfo->pfCmdDoneHandler = NULL;
3932 prCmdInfo->pfCmdTimeoutHandler = NULL;
3933 prCmdInfo->fgIsOid = FALSE;
3934 prCmdInfo->ucCID = CMD_ID_SET_OSC;
3935 prCmdInfo->fgSetQuery = TRUE;
3936 prCmdInfo->fgNeedResp = FALSE;
3937 prCmdInfo->fgDriverDomainMCR = FALSE;
3938 prCmdInfo->ucCmdSeqNum = ucCmdSeqNum;
3939 prCmdInfo->u4SetInfoLen = sizeof(CMD_MCU_LP_PARAM_T);
3940
3941 // Setup WIFI_CMD_T
3942 prWifiCmd = (P_WIFI_CMD_T)(prCmdInfo->pucInfoBuffer);
3943 prWifiCmd->u2TxByteCount_UserPriority = prCmdInfo->u2InfoBufLen;
3944 prWifiCmd->ucCID = prCmdInfo->ucCID;
3945 prWifiCmd->ucSetQuery = prCmdInfo->fgSetQuery;
3946 prWifiCmd->ucSeqNum = prCmdInfo->ucCmdSeqNum;
3947
3948 // configure CMD_MCU_LP_PARAM_T
3949 prMcuSetOscCmd = (P_CMD_MCU_LP_PARAM_T)(prWifiCmd->aucBuffer);
3950 prMcuSetOscCmd->u2OscStableTime = u2OscStableTime;
3951
3952 status = wlanSendCommand(prAdapter, prCmdInfo);
3953 cmdBufFreeCmdInfo(prAdapter, prCmdInfo);
3954
3955 return status;
3956}
3957#endif
3958
3959/*----------------------------------------------------------------------------*/
3960/*!
3961* @brief This function is called to update network address in firmware domain
3962*
3963* @param prAdapter Pointer to the Adapter structure.
3964*
3965* @return WLAN_STATUS_FAILURE The request could not be processed
3966* WLAN_STATUS_PENDING The request has been queued for later processing
3967* WLAN_STATUS_SUCCESS The request has been processed
3968*/
3969/*----------------------------------------------------------------------------*/
3970WLAN_STATUS
3971wlanUpdateNetworkAddress (
3972 IN P_ADAPTER_T prAdapter
3973 )
3974{
3975 const UINT_8 aucZeroMacAddr[] = NULL_MAC_ADDR;
3976 PARAM_MAC_ADDRESS rMacAddr;
3977 UINT_8 ucCmdSeqNum;
3978 P_CMD_INFO_T prCmdInfo;
3979 P_WIFI_CMD_T prWifiCmd;
3980 P_CMD_BASIC_CONFIG prCmdBasicConfig;
3981 UINT_32 u4SysTime;
3982
3983 DEBUGFUNC("wlanUpdateNetworkAddress");
3984
3985 ASSERT(prAdapter);
3986
3987 if(kalRetrieveNetworkAddress(prAdapter->prGlueInfo, &rMacAddr) == FALSE
3988 || IS_BMCAST_MAC_ADDR(rMacAddr)
3989 || EQUAL_MAC_ADDR(aucZeroMacAddr, rMacAddr)) {
3990 // eFUSE has a valid address, don't do anything
3991 if(prAdapter->fgIsEmbbededMacAddrValid == TRUE) {
3992#if CFG_SHOW_MACADDR_SOURCE
3993 DBGLOG(INIT, INFO, ("Using embedded MAC address"));
3994#endif
3995 return WLAN_STATUS_SUCCESS;
3996 }
3997 else {
3998#if CFG_SHOW_MACADDR_SOURCE
3999 DBGLOG(INIT, INFO, ("Using dynamically generated MAC address"));
4000#endif
4001 // dynamic generate
4002 u4SysTime = kalGetTimeTick();
4003
4004 rMacAddr[0] = 0x00;
4005 rMacAddr[1] = 0x08;
4006 rMacAddr[2] = 0x22;
4007
4008 kalMemCopy(&rMacAddr[3], &u4SysTime, 3);
4009 }
4010 }
4011 else {
4012#if CFG_SHOW_MACADDR_SOURCE
4013 DBGLOG(INIT, INFO, ("Using host-supplied MAC address"));
4014#endif
4015 }
4016
4017 /* allocate command memory */
4018 prCmdInfo = cmdBufAllocateCmdInfo(prAdapter,
4019 CMD_HDR_SIZE + sizeof(CMD_BASIC_CONFIG));
4020
4021 if (!prCmdInfo) {
4022 DBGLOG(INIT, ERROR, ("Allocate CMD_INFO_T ==> FAILED.\n"));
4023 return WLAN_STATUS_FAILURE;
4024 }
4025
4026 // increase command sequence number
4027 ucCmdSeqNum = nicIncreaseCmdSeqNum(prAdapter);
4028
4029 // compose CMD_BUILD_CONNECTION cmd pkt
4030 prCmdInfo->eCmdType = COMMAND_TYPE_GENERAL_IOCTL;
4031 prCmdInfo->u2InfoBufLen = CMD_HDR_SIZE + sizeof(CMD_BASIC_CONFIG);
4032 prCmdInfo->pfCmdDoneHandler = NULL;
4033 prCmdInfo->pfCmdTimeoutHandler = NULL;
4034 prCmdInfo->fgIsOid = FALSE;
4035 prCmdInfo->ucCID = CMD_ID_BASIC_CONFIG;
4036 prCmdInfo->fgSetQuery = TRUE;
4037 prCmdInfo->fgNeedResp = FALSE;
4038 prCmdInfo->fgDriverDomainMCR = FALSE;
4039 prCmdInfo->ucCmdSeqNum = ucCmdSeqNum;
4040 prCmdInfo->u4SetInfoLen = sizeof(CMD_BASIC_CONFIG);
4041
4042 // Setup WIFI_CMD_T
4043 prWifiCmd = (P_WIFI_CMD_T)(prCmdInfo->pucInfoBuffer);
4044 prWifiCmd->u2TxByteCount_UserPriority = prCmdInfo->u2InfoBufLen;
4045 prWifiCmd->ucCID = prCmdInfo->ucCID;
4046 prWifiCmd->ucSetQuery = prCmdInfo->fgSetQuery;
4047 prWifiCmd->ucSeqNum = prCmdInfo->ucCmdSeqNum;
4048
4049 // configure CMD_BASIC_CONFIG
4050 prCmdBasicConfig = (P_CMD_BASIC_CONFIG)(prWifiCmd->aucBuffer);
4051 kalMemCopy(&(prCmdBasicConfig->rMyMacAddr), &rMacAddr, PARAM_MAC_ADDR_LEN);
4052 prCmdBasicConfig->ucNative80211 = 0;
4053 prCmdBasicConfig->rCsumOffload.u2RxChecksum = 0;
4054 prCmdBasicConfig->rCsumOffload.u2TxChecksum = 0;
4055
4056#if CFG_TCP_IP_CHKSUM_OFFLOAD
4057 if(prAdapter->u4CSUMFlags & CSUM_OFFLOAD_EN_TX_TCP)
4058 prCmdBasicConfig->rCsumOffload.u2TxChecksum |= BIT(2);
4059
4060 if(prAdapter->u4CSUMFlags & CSUM_OFFLOAD_EN_TX_UDP)
4061 prCmdBasicConfig->rCsumOffload.u2TxChecksum |= BIT(1);
4062
4063 if(prAdapter->u4CSUMFlags & CSUM_OFFLOAD_EN_TX_IP)
4064 prCmdBasicConfig->rCsumOffload.u2TxChecksum |= BIT(0);
4065
4066 if(prAdapter->u4CSUMFlags & CSUM_OFFLOAD_EN_RX_TCP)
4067 prCmdBasicConfig->rCsumOffload.u2RxChecksum |= BIT(2);
4068
4069 if(prAdapter->u4CSUMFlags & CSUM_OFFLOAD_EN_RX_UDP)
4070 prCmdBasicConfig->rCsumOffload.u2RxChecksum |= BIT(1);
4071
4072 if(prAdapter->u4CSUMFlags & (CSUM_OFFLOAD_EN_RX_IPv4 | CSUM_OFFLOAD_EN_RX_IPv6))
4073 prCmdBasicConfig->rCsumOffload.u2RxChecksum |= BIT(0);
4074#endif
4075
4076 /* send the command to FW */
4077 if(wlanSendCommand(prAdapter, prCmdInfo) == WLAN_STATUS_RESOURCES) {
4078
4079 /* backup the command to wait response */
4080 prCmdInfo->pfCmdDoneHandler = nicCmdEventQueryAddress;
4081 kalEnqueueCommand(prAdapter->prGlueInfo, (P_QUE_ENTRY_T)prCmdInfo);
4082
4083 return WLAN_STATUS_PENDING;
4084 }
4085 else {
4086 /* send ok without response */
4087 nicCmdEventQueryAddress(prAdapter, prCmdInfo, (PUINT_8)prCmdBasicConfig);
4088 cmdBufFreeCmdInfo(prAdapter, prCmdInfo);
4089
4090 return WLAN_STATUS_SUCCESS;
4091 }
4092}
4093
4094/*----------------------------------------------------------------------------*/
4095/*!
4096* @brief This function is called to check if the device is in RF test mode
4097*
4098* @param pfnOidHandler Pointer to the OID handler
4099*
4100* @return TRUE
4101* FALSE
4102*/
4103/*----------------------------------------------------------------------------*/
4104BOOLEAN
4105wlanQueryTestMode(
4106 IN P_ADAPTER_T prAdapter
4107 )
4108{
4109 ASSERT(prAdapter);
4110
4111 return prAdapter->fgTestMode;
4112}
4113
4114
4115/*----------------------------------------------------------------------------*/
4116/*!
4117* @brief This function is called to identify 802.1x and Bluetooth-over-Wi-Fi
4118* security frames, and queued into command queue for strict ordering
4119* due to 802.1x frames before add-key OIDs are not to be encrypted
4120*
4121* @param prAdapter Pointer of Adapter Data Structure
4122* @param prPacket Pointer of native packet
4123*
4124* @return TRUE
4125* FALSE
4126*/
4127/*----------------------------------------------------------------------------*/
4128BOOLEAN
4129wlanProcessSecurityFrame(
4130 IN P_ADAPTER_T prAdapter,
4131 IN P_NATIVE_PACKET prPacket
4132 )
4133{
4134 UINT_8 ucPriorityParam;
4135 UINT_8 aucEthDestAddr[PARAM_MAC_ADDR_LEN];
4136 BOOLEAN fgIs1x = FALSE;
4137 BOOLEAN fgIsPAL = FALSE;
4138 UINT_32 u4PacketLen;
4139 ULONG u4SysTime;
4140 UINT_8 ucNetworkType;
4141 P_CMD_INFO_T prCmdInfo;
4142
4143 ASSERT(prAdapter);
4144 ASSERT(prPacket);
4145
4146 /* retrieve some informations for packet classification */
4147 if (kalQoSFrameClassifierAndPacketInfo(prAdapter->prGlueInfo,
4148 prPacket,
4149 &ucPriorityParam,
4150 &u4PacketLen,
4151 aucEthDestAddr,
4152 &fgIs1x,
4153 &fgIsPAL,
4154 &ucNetworkType) == TRUE) { /* almost TRUE except frame length < 14B */
4155
4156 if(fgIs1x == FALSE) {
4157 return FALSE;
4158 }
4159 else {
4160 /* 1x data packets */
4161 KAL_SPIN_LOCK_DECLARATION();
4162
4163 /* get a free command entry */
4164 KAL_ACQUIRE_SPIN_LOCK(prAdapter, SPIN_LOCK_CMD_RESOURCE);
4165 QUEUE_REMOVE_HEAD(&prAdapter->rFreeCmdList, prCmdInfo, P_CMD_INFO_T);
4166 KAL_RELEASE_SPIN_LOCK(prAdapter, SPIN_LOCK_CMD_RESOURCE);
4167
4168 DBGLOG(RSN, INFO, ("T1X len=%u\n", u4PacketLen));
4169
4170 if (prCmdInfo) {
4171 P_STA_RECORD_T prStaRec;
4172
4173 // fill arrival time
4174 u4SysTime = (OS_SYSTIME)kalGetTimeTick();
4175 GLUE_SET_PKT_ARRIVAL_TIME(prPacket, u4SysTime);
4176
4177 kalMemZero(prCmdInfo, sizeof(CMD_INFO_T));
4178
4179 prCmdInfo->eCmdType = COMMAND_TYPE_SECURITY_FRAME;
4180 prCmdInfo->u2InfoBufLen = (UINT_16)u4PacketLen;
4181 prCmdInfo->pucInfoBuffer = NULL;
4182 prCmdInfo->prPacket = prPacket;
4183#if 0
4184 prCmdInfo->ucStaRecIndex = qmGetStaRecIdx(prAdapter,
4185 aucEthDestAddr,
4186 (ENUM_NETWORK_TYPE_INDEX_T)ucNetworkType);
4187#endif
4188 prStaRec = cnmGetStaRecByAddress(prAdapter,
4189 (ENUM_NETWORK_TYPE_INDEX_T)ucNetworkType,
4190 aucEthDestAddr);
4191 if(prStaRec) {
4192 prCmdInfo->ucStaRecIndex = prStaRec->ucIndex;
4193 }
4194 else {
4195 prCmdInfo->ucStaRecIndex = STA_REC_INDEX_NOT_FOUND;
4196 }
4197
4198 prCmdInfo->eNetworkType = (ENUM_NETWORK_TYPE_INDEX_T)ucNetworkType;
4199 prCmdInfo->pfCmdDoneHandler = wlanSecurityFrameTxDone;
4200 prCmdInfo->pfCmdTimeoutHandler = wlanSecurityFrameTxTimeout;
4201 prCmdInfo->fgIsOid = FALSE;
4202 prCmdInfo->fgSetQuery = TRUE;
4203 prCmdInfo->fgNeedResp = FALSE;
4204
4205 /*
4206 queue the 1x packet and we will send the packet to CONNSYS by
4207 using command queue
4208 */
4209 kalEnqueueCommand(prAdapter->prGlueInfo, (P_QUE_ENTRY_T)prCmdInfo);
4210
4211 /* TRUE: means we have already handled it in the function */
4212 return TRUE;
4213 }
4214 else {
4215
4216 /* no memory, why assert ? can skip the packet ? */
4217 ASSERT(0);
4218 return FALSE;
4219 }
4220 }
4221 }
4222 else {
4223 return FALSE;
4224 }
4225}
4226
4227
4228/*----------------------------------------------------------------------------*/
4229/*!
4230* @brief This function is called when 802.1x or Bluetooth-over-Wi-Fi
4231* security frames has been sent to firmware
4232*
4233* @param prAdapter Pointer of Adapter Data Structure
4234* @param prCmdInfo Pointer of CMD_INFO_T
4235* @param pucEventBuf meaningless, only for API compatibility
4236*
4237* @return none
4238*/
4239/*----------------------------------------------------------------------------*/
4240VOID
4241wlanSecurityFrameTxDone(
4242 IN P_ADAPTER_T prAdapter,
4243 IN P_CMD_INFO_T prCmdInfo,
4244 IN PUINT_8 pucEventBuf
4245 )
4246{
4247 ASSERT(prAdapter);
4248 ASSERT(prCmdInfo);
4249
4250 if (prCmdInfo->eNetworkType == NETWORK_TYPE_AIS_INDEX &&
4251 prAdapter->rWifiVar.rAisSpecificBssInfo.fgCounterMeasure) {
4252
4253 /* AIS counter measure so change RSN FSM to SEND_DEAUTH state */
4254 P_STA_RECORD_T prSta = cnmGetStaRecByIndex(prAdapter, prCmdInfo->ucStaRecIndex);
4255 if (prSta) {
4256 kalMsleep(10);
4257 secFsmEventEapolTxDone(prAdapter, prSta, TX_RESULT_SUCCESS);
4258 }
4259 }
4260
4261 /* free the packet */
4262 kalSecurityFrameSendComplete(prAdapter->prGlueInfo,
4263 prCmdInfo->prPacket,
4264 WLAN_STATUS_SUCCESS);
4265}
4266
4267
4268/*----------------------------------------------------------------------------*/
4269/*!
4270* @brief This function is called when 802.1x or Bluetooth-over-Wi-Fi
4271* security frames has failed sending to firmware
4272*
4273* @param prAdapter Pointer of Adapter Data Structure
4274* @param prCmdInfo Pointer of CMD_INFO_T
4275*
4276* @return none
4277*/
4278/*----------------------------------------------------------------------------*/
4279VOID
4280wlanSecurityFrameTxTimeout(
4281 IN P_ADAPTER_T prAdapter,
4282 IN P_CMD_INFO_T prCmdInfo
4283 )
4284{
4285 ASSERT(prAdapter);
4286 ASSERT(prCmdInfo);
4287
4288 /* free the packet */
4289 kalSecurityFrameSendComplete(prAdapter->prGlueInfo,
4290 prCmdInfo->prPacket,
4291 WLAN_STATUS_FAILURE);
4292}
4293
4294
4295/*----------------------------------------------------------------------------*/
4296/*!
4297* @brief This function is called before AIS is starting a new scan
4298*
4299* @param prAdapter Pointer of Adapter Data Structure
4300*
4301* @return none
4302*/
4303/*----------------------------------------------------------------------------*/
4304VOID
4305wlanClearScanningResult(
4306 IN P_ADAPTER_T prAdapter
4307 )
4308{
4309 BOOLEAN fgKeepCurrOne = FALSE;
4310 UINT_32 i;
4311
4312 ASSERT(prAdapter);
4313
4314 // clear scanning result except current one
4315 /* copy current one to prAdapter->rWlanInfo.arScanResult[0] */
4316 if(kalGetMediaStateIndicated(prAdapter->prGlueInfo) == PARAM_MEDIA_STATE_CONNECTED) {
4317 for(i = 0 ; i < prAdapter->rWlanInfo.u4ScanResultNum ; i++) {
4318
4319 if(EQUAL_MAC_ADDR(prAdapter->rWlanInfo.rCurrBssId.arMacAddress,
4320 prAdapter->rWlanInfo.arScanResult[i].arMacAddress)) {
4321 fgKeepCurrOne = TRUE;
4322
4323 if(i != 0) {
4324 // copy structure
4325 kalMemCopy(&(prAdapter->rWlanInfo.arScanResult[0]),
4326 &(prAdapter->rWlanInfo.arScanResult[i]),
4327 OFFSET_OF(PARAM_BSSID_EX_T, aucIEs));
4328 }
4329
4330 if(prAdapter->rWlanInfo.arScanResult[i].u4IELength > 0) {
4331 if(prAdapter->rWlanInfo.apucScanResultIEs[i] != &(prAdapter->rWlanInfo.aucScanIEBuf[0])) {
4332 // move IEs to head
4333 kalMemCopy(prAdapter->rWlanInfo.aucScanIEBuf,
4334 prAdapter->rWlanInfo.apucScanResultIEs[i],
4335 prAdapter->rWlanInfo.arScanResult[i].u4IELength);
4336 }
4337
4338 // modify IE pointer
4339 prAdapter->rWlanInfo.apucScanResultIEs[0] = &(prAdapter->rWlanInfo.aucScanIEBuf[0]);
4340 }
4341 else {
4342 prAdapter->rWlanInfo.apucScanResultIEs[0] = NULL;
4343 }
4344
4345 break;
4346 }
4347 }
4348 }
4349
4350 if(fgKeepCurrOne == TRUE) {
4351 prAdapter->rWlanInfo.u4ScanResultNum = 1;
4352 prAdapter->rWlanInfo.u4ScanIEBufferUsage =
4353 ALIGN_4(prAdapter->rWlanInfo.arScanResult[0].u4IELength);
4354 }
4355 else {
4356 prAdapter->rWlanInfo.u4ScanResultNum = 0;
4357 prAdapter->rWlanInfo.u4ScanIEBufferUsage = 0;
4358 }
4359
4360 return;
4361}
4362
4363
4364/*----------------------------------------------------------------------------*/
4365/*!
4366* @brief This function is called when AIS received a beacon timeout event
4367*
4368* @param prAdapter Pointer of Adapter Data Structure
4369* @param arBSSID MAC address of the specified BSS
4370*
4371* @return none
4372*/
4373/*----------------------------------------------------------------------------*/
4374VOID
4375wlanClearBssInScanningResult(
4376 IN P_ADAPTER_T prAdapter,
4377 IN PUINT_8 arBSSID
4378 )
4379{
4380 UINT_32 i, j, u4IELength = 0, u4IEMoveLength;
4381 PUINT_8 pucIEPtr;
4382
4383 ASSERT(prAdapter);
4384
4385 // clear the scanning result for arBSSID
4386 i = 0;
4387 while(1) {
4388 if(i >= prAdapter->rWlanInfo.u4ScanResultNum) {
4389 break;
4390 }
4391
4392 if(EQUAL_MAC_ADDR(arBSSID, prAdapter->rWlanInfo.arScanResult[i].arMacAddress)) {
4393
4394 // backup current IE length
4395 u4IELength = ALIGN_4(prAdapter->rWlanInfo.arScanResult[i].u4IELength);
4396 pucIEPtr = prAdapter->rWlanInfo.apucScanResultIEs[i];
4397
4398 // removed from middle
4399 for(j = i + 1 ; j < prAdapter->rWlanInfo.u4ScanResultNum ; j++) {
4400 kalMemCopy(&(prAdapter->rWlanInfo.arScanResult[j-1]),
4401 &(prAdapter->rWlanInfo.arScanResult[j]),
4402 OFFSET_OF(PARAM_BSSID_EX_T, aucIEs));
4403
4404 prAdapter->rWlanInfo.apucScanResultIEs[j-1] =
4405 prAdapter->rWlanInfo.apucScanResultIEs[j];
4406 }
4407
4408 prAdapter->rWlanInfo.u4ScanResultNum--;
4409
4410 // remove IE buffer if needed := move rest of IE buffer
4411 if(u4IELength > 0) {
4412 u4IEMoveLength = prAdapter->rWlanInfo.u4ScanIEBufferUsage -
4413 (((ULONG)pucIEPtr) + (ULONG)u4IELength - ((ULONG)(&(prAdapter->rWlanInfo.aucScanIEBuf[0]))));
4414
4415 kalMemCopy(pucIEPtr,
4416 pucIEPtr + u4IELength,
4417 u4IEMoveLength);
4418
4419 prAdapter->rWlanInfo.u4ScanIEBufferUsage -= u4IELength;
4420
4421 // correction of pointers to IE buffer
4422 for(j = 0 ; j < prAdapter->rWlanInfo.u4ScanResultNum ; j++) {
4423 if(prAdapter->rWlanInfo.apucScanResultIEs[j] > pucIEPtr) {
4424 prAdapter->rWlanInfo.apucScanResultIEs[j] =
4425 (PUINT_8)((ULONG)(prAdapter->rWlanInfo.apucScanResultIEs[j]) - u4IELength);
4426 }
4427 }
4428 }
4429 }
4430
4431 i++;
4432 }
4433
4434 return;
4435}
4436
4437
4438#if CFG_TEST_WIFI_DIRECT_GO
4439VOID
4440wlanEnableP2pFunction (
4441 IN P_ADAPTER_T prAdapter
4442 )
4443{
4444#if 0
4445 P_MSG_P2P_FUNCTION_SWITCH_T prMsgFuncSwitch = (P_MSG_P2P_FUNCTION_SWITCH_T)NULL;
4446
4447 prMsgFuncSwitch = (P_MSG_P2P_FUNCTION_SWITCH_T)cnmMemAlloc(prAdapter, RAM_TYPE_MSG, sizeof(MSG_P2P_FUNCTION_SWITCH_T));
4448 if (!prMsgFuncSwitch) {
4449 ASSERT(FALSE);
4450 return;
4451 }
4452
4453
4454 prMsgFuncSwitch->rMsgHdr.eMsgId = MID_MNY_P2P_FUN_SWITCH;
4455 prMsgFuncSwitch->fgIsFuncOn = TRUE;
4456
4457
4458 mboxSendMsg(prAdapter,
4459 MBOX_ID_0,
4460 (P_MSG_HDR_T)prMsgFuncSwitch,
4461 MSG_SEND_METHOD_BUF);
4462#endif
4463 return;
4464}
4465
4466VOID
4467wlanEnableATGO (
4468 IN P_ADAPTER_T prAdapter
4469 )
4470{
4471
4472 P_MSG_P2P_CONNECTION_REQUEST_T prMsgConnReq = (P_MSG_P2P_CONNECTION_REQUEST_T)NULL;
4473 UINT_8 aucTargetDeviceID[MAC_ADDR_LEN] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
4474
4475 prMsgConnReq = (P_MSG_P2P_CONNECTION_REQUEST_T)cnmMemAlloc(prAdapter, RAM_TYPE_MSG, sizeof(MSG_P2P_CONNECTION_REQUEST_T));
4476 if (!prMsgConnReq) {
4477 ASSERT(FALSE);
4478 return;
4479 }
4480
4481 prMsgConnReq->rMsgHdr.eMsgId = MID_MNY_P2P_CONNECTION_REQ;
4482
4483 /*=====Param Modified for test=====*/
4484 COPY_MAC_ADDR(prMsgConnReq->aucDeviceID, aucTargetDeviceID);
4485 prMsgConnReq->fgIsTobeGO = TRUE;
4486 prMsgConnReq->fgIsPersistentGroup = FALSE;
4487
4488 /*=====Param Modified for test=====*/
4489
4490 mboxSendMsg(prAdapter,
4491 MBOX_ID_0,
4492 (P_MSG_HDR_T)prMsgConnReq,
4493 MSG_SEND_METHOD_BUF);
4494
4495 return;
4496}
4497#endif
4498
4499
4500/*----------------------------------------------------------------------------*/
4501/*!
4502* @brief This function is called to retrieve permanent address from firmware
4503*
4504* @param prAdapter Pointer of Adapter Data Structure
4505*
4506* @return WLAN_STATUS_SUCCESS
4507* WLAN_STATUS_FAILURE
4508*/
4509/*----------------------------------------------------------------------------*/
4510WLAN_STATUS
4511wlanQueryPermanentAddress(
4512 IN P_ADAPTER_T prAdapter
4513 )
4514{
4515 UINT_8 ucCmdSeqNum;
4516 P_CMD_INFO_T prCmdInfo;
4517 P_WIFI_CMD_T prWifiCmd;
4518 UINT_32 u4RxPktLength;
4519 UINT_8 aucBuffer[sizeof(WIFI_EVENT_T) + sizeof(EVENT_BASIC_CONFIG)];
4520 P_HIF_RX_HEADER_T prHifRxHdr;
4521 P_WIFI_EVENT_T prEvent;
4522 P_EVENT_BASIC_CONFIG prEventBasicConfig;
4523
4524 ASSERT(prAdapter);
4525
4526 DEBUGFUNC("wlanQueryPermanentAddress");
4527
4528 // 1. Allocate CMD Info Packet and its Buffer
4529 prCmdInfo = cmdBufAllocateCmdInfo(prAdapter, CMD_HDR_SIZE + sizeof(CMD_BASIC_CONFIG));
4530 if (!prCmdInfo) {
4531 DBGLOG(INIT, ERROR, ("Allocate CMD_INFO_T ==> FAILED.\n"));
4532 return WLAN_STATUS_FAILURE;
4533 }
4534
4535 // increase command sequence number
4536 ucCmdSeqNum = nicIncreaseCmdSeqNum(prAdapter);
4537
4538 // compose CMD_BUILD_CONNECTION cmd pkt
4539 prCmdInfo->eCmdType = COMMAND_TYPE_GENERAL_IOCTL;
4540 prCmdInfo->u2InfoBufLen = CMD_HDR_SIZE + sizeof(CMD_BASIC_CONFIG);
4541 prCmdInfo->pfCmdDoneHandler = NULL;
4542 prCmdInfo->fgIsOid = FALSE;
4543 prCmdInfo->ucCID = CMD_ID_BASIC_CONFIG;
4544 prCmdInfo->fgSetQuery = FALSE;
4545 prCmdInfo->fgNeedResp = TRUE;
4546 prCmdInfo->fgDriverDomainMCR = FALSE;
4547 prCmdInfo->ucCmdSeqNum = ucCmdSeqNum;
4548 prCmdInfo->u4SetInfoLen = sizeof(CMD_BASIC_CONFIG);
4549
4550 // Setup WIFI_CMD_T
4551 prWifiCmd = (P_WIFI_CMD_T)(prCmdInfo->pucInfoBuffer);
4552 prWifiCmd->u2TxByteCount_UserPriority = prCmdInfo->u2InfoBufLen;
4553 prWifiCmd->ucCID = prCmdInfo->ucCID;
4554 prWifiCmd->ucSetQuery = prCmdInfo->fgSetQuery;
4555 prWifiCmd->ucSeqNum = prCmdInfo->ucCmdSeqNum;
4556
4557 /* send the command */
4558 wlanSendCommand(prAdapter, prCmdInfo);
4559 cmdBufFreeCmdInfo(prAdapter, prCmdInfo);
4560
4561 /* wait for response */
4562 if(nicRxWaitResponse(prAdapter,
4563 1,
4564 aucBuffer,
4565 sizeof(WIFI_EVENT_T) + sizeof(EVENT_BASIC_CONFIG), /* 8B + 12B */
4566 &u4RxPktLength) != WLAN_STATUS_SUCCESS) {
4567 return WLAN_STATUS_FAILURE;
4568 }
4569
4570 // header checking ..
4571 prHifRxHdr = (P_HIF_RX_HEADER_T)aucBuffer;
4b9e9796 4572 if ((prHifRxHdr->u2PacketType & HIF_RX_HDR_PACKET_TYPE_MASK) != HIF_RX_PKT_TYPE_EVENT) {
6fa3eb70
S
4573 return WLAN_STATUS_FAILURE;
4574 }
4575
4576 prEvent = (P_WIFI_EVENT_T)aucBuffer;
4577 if(prEvent->ucEID != EVENT_ID_BASIC_CONFIG) {
4578 return WLAN_STATUS_FAILURE;
4579 }
4580
4581 prEventBasicConfig = (P_EVENT_BASIC_CONFIG)(prEvent->aucBuffer);
4582
4583 COPY_MAC_ADDR(prAdapter->rWifiVar.aucPermanentAddress, &(prEventBasicConfig->rMyMacAddr));
4584 COPY_MAC_ADDR(prAdapter->rWifiVar.aucMacAddress, &(prEventBasicConfig->rMyMacAddr));
4585
4586 return WLAN_STATUS_SUCCESS;
4587}
4588
4589
4590/*----------------------------------------------------------------------------*/
4591/*!
4592* @brief This function is called to retrieve NIC capability from firmware
4593*
4594* @param prAdapter Pointer of Adapter Data Structure
4595*
4596* @return WLAN_STATUS_SUCCESS
4597* WLAN_STATUS_FAILURE
4598*/
4599/*----------------------------------------------------------------------------*/
4600WLAN_STATUS
4601wlanQueryNicCapability(
4602 IN P_ADAPTER_T prAdapter
4603 )
4604{
4605 UINT_8 ucCmdSeqNum;
4606 P_CMD_INFO_T prCmdInfo;
4607 P_WIFI_CMD_T prWifiCmd;
4608 UINT_32 u4RxPktLength;
4609 UINT_8 aucBuffer[sizeof(WIFI_EVENT_T) + sizeof(EVENT_NIC_CAPABILITY)];
4610 P_HIF_RX_HEADER_T prHifRxHdr;
4611 P_WIFI_EVENT_T prEvent;
4612 P_EVENT_NIC_CAPABILITY prEventNicCapability;
4613
4614 ASSERT(prAdapter);
4615
4616 DEBUGFUNC("wlanQueryNicCapability");
4617
4618 // 1. Allocate CMD Info Packet and its Buffer
4619 prCmdInfo = cmdBufAllocateCmdInfo(prAdapter, CMD_HDR_SIZE + sizeof(EVENT_NIC_CAPABILITY));
4620 if (!prCmdInfo) {
4621 DBGLOG(INIT, ERROR, ("Allocate CMD_INFO_T ==> FAILED.\n"));
4622 return WLAN_STATUS_FAILURE;
4623 }
4624
4625 // increase command sequence number
4626 ucCmdSeqNum = nicIncreaseCmdSeqNum(prAdapter);
4627
4628 // compose CMD_BUILD_CONNECTION cmd pkt
4629 prCmdInfo->eCmdType = COMMAND_TYPE_GENERAL_IOCTL;
4630 prCmdInfo->u2InfoBufLen = CMD_HDR_SIZE + sizeof(EVENT_NIC_CAPABILITY);
4631 prCmdInfo->pfCmdDoneHandler = NULL;
4632 prCmdInfo->fgIsOid = FALSE;
4633 prCmdInfo->ucCID = CMD_ID_GET_NIC_CAPABILITY;
4634 prCmdInfo->fgSetQuery = FALSE;
4635 prCmdInfo->fgNeedResp = TRUE;
4636 prCmdInfo->fgDriverDomainMCR = FALSE;
4637 prCmdInfo->ucCmdSeqNum = ucCmdSeqNum;
4638 prCmdInfo->u4SetInfoLen = 0;
4639
4640 // Setup WIFI_CMD_T
4641 prWifiCmd = (P_WIFI_CMD_T)(prCmdInfo->pucInfoBuffer);
4642 prWifiCmd->u2TxByteCount_UserPriority = prCmdInfo->u2InfoBufLen;
4643 prWifiCmd->ucCID = prCmdInfo->ucCID;
4644 prWifiCmd->ucSetQuery = prCmdInfo->fgSetQuery;
4645 prWifiCmd->ucSeqNum = prCmdInfo->ucCmdSeqNum;
4646
4647 /* send the command */
4648 wlanSendCommand(prAdapter, prCmdInfo);
4649 cmdBufFreeCmdInfo(prAdapter, prCmdInfo);
4650
4651 /* wait for FW response */
4652 if(nicRxWaitResponse(prAdapter,
4653 1,
4654 aucBuffer,
4655 sizeof(WIFI_EVENT_T) + sizeof(EVENT_NIC_CAPABILITY),
4656 &u4RxPktLength) != WLAN_STATUS_SUCCESS) {
4657 return WLAN_STATUS_FAILURE;
4658 }
4659
4660 // header checking ..
4661 prHifRxHdr = (P_HIF_RX_HEADER_T)aucBuffer;
4b9e9796 4662 if ((prHifRxHdr->u2PacketType & HIF_RX_HDR_PACKET_TYPE_MASK) != HIF_RX_PKT_TYPE_EVENT) {
6fa3eb70
S
4663 return WLAN_STATUS_FAILURE;
4664 }
4665
4666 prEvent = (P_WIFI_EVENT_T)aucBuffer;
4667 if(prEvent->ucEID != EVENT_ID_NIC_CAPABILITY) {
4668 return WLAN_STATUS_FAILURE;
4669 }
4670
4671 prEventNicCapability = (P_EVENT_NIC_CAPABILITY)(prEvent->aucBuffer);
4672
4673 prAdapter->rVerInfo.u2FwProductID = prEventNicCapability->u2ProductID;
4674 prAdapter->rVerInfo.u2FwOwnVersion = prEventNicCapability->u2FwVersion;
4675 prAdapter->rVerInfo.u2FwPeerVersion = prEventNicCapability->u2DriverVersion;
4676 prAdapter->fgIsHw5GBandDisabled = (BOOLEAN)prEventNicCapability->ucHw5GBandDisabled;
4677 prAdapter->fgIsEepromUsed = (BOOLEAN)prEventNicCapability->ucEepromUsed;
4678 prAdapter->fgIsEfuseValid = (BOOLEAN)prEventNicCapability->ucEfuseValid;
4679 prAdapter->fgIsEmbbededMacAddrValid = (BOOLEAN)prEventNicCapability->ucMacAddrValid;
4680
4681#if (CFG_SUPPORT_TDLS == 1)
4682 if (prEventNicCapability->ucFeatureSet & (1 << FEATURE_SET_OFFSET_TDLS))
4683 prAdapter->fgTdlsIsSup = TRUE;
4684 DBGLOG(TDLS, TRACE, ("<wifi> support flag: 0x%x\n",
4685 prEventNicCapability->ucFeatureSet));
4686#else
4687 prAdapter->fgTdlsIsSup = 0;
4688#endif /* CFG_SUPPORT_TDLS */
4689
4690 if (!(prEventNicCapability->ucFeatureSet & (1 << FEATURE_SET_OFFSET_5G_SUPPORT)))
4691 prAdapter->fgEnable5GBand = FALSE; /* firmware does not support */
4692
4693#if CFG_ENABLE_CAL_LOG
4694 DBGLOG(INIT, INFO, (" RF CAL FAIL = (%d),BB CAL FAIL = (%d)\n",
4695 prEventNicCapability->ucRfCalFail ,prEventNicCapability->ucBbCalFail ));
4696#endif
4697 return WLAN_STATUS_SUCCESS;
4698}
4699
4700
4701/*----------------------------------------------------------------------------*/
4702/*!
4703* @brief This function is called to retrieve NIC capability from firmware
4704*
4705* @param prAdapter Pointer of Adapter Data Structure
4706*
4707* @return WLAN_STATUS_SUCCESS
4708* WLAN_STATUS_FAILURE
4709*/
4710/*----------------------------------------------------------------------------*/
4711WLAN_STATUS
4712wlanQueryDebugCode(
4713 IN P_ADAPTER_T prAdapter
4714 )
4715{
4716 UINT_8 ucCmdSeqNum;
4717 P_CMD_INFO_T prCmdInfo;
4718 P_WIFI_CMD_T prWifiCmd;
4719
4720 ASSERT(prAdapter);
4721
4722 DEBUGFUNC("wlanQueryDebugCode");
4723
4724 // 1. Allocate CMD Info Packet and its Buffer
4725 prCmdInfo = cmdBufAllocateCmdInfo(prAdapter, CMD_HDR_SIZE);
4726 if (!prCmdInfo) {
4727 DBGLOG(INIT, ERROR, ("Allocate CMD_INFO_T ==> FAILED.\n"));
4728 return WLAN_STATUS_FAILURE;
4729 }
4730
4731 // increase command sequence number
4732 ucCmdSeqNum = nicIncreaseCmdSeqNum(prAdapter);
4733
4734 // compose CMD_BUILD_CONNECTION cmd pkt
4735 prCmdInfo->eCmdType = COMMAND_TYPE_GENERAL_IOCTL;
4736 prCmdInfo->u2InfoBufLen = CMD_HDR_SIZE;
4737 prCmdInfo->pfCmdDoneHandler = NULL;
4738 prCmdInfo->fgIsOid = FALSE;
4739 prCmdInfo->ucCID = CMD_ID_GET_DEBUG_CODE;
4740 prCmdInfo->fgSetQuery = FALSE;
4741 prCmdInfo->fgNeedResp = FALSE;
4742 prCmdInfo->fgDriverDomainMCR = FALSE;
4743 prCmdInfo->ucCmdSeqNum = ucCmdSeqNum;
4744 prCmdInfo->u4SetInfoLen = 0;
4745
4746 // Setup WIFI_CMD_T
4747 prWifiCmd = (P_WIFI_CMD_T)(prCmdInfo->pucInfoBuffer);
4748 prWifiCmd->u2TxByteCount_UserPriority = prCmdInfo->u2InfoBufLen;
4749 prWifiCmd->ucCID = prCmdInfo->ucCID;
4750 prWifiCmd->ucSetQuery = prCmdInfo->fgSetQuery;
4751 prWifiCmd->ucSeqNum = prCmdInfo->ucCmdSeqNum;
4752
4753 /* send the command */
4754 wlanSendCommand(prAdapter, prCmdInfo);
4755 cmdBufFreeCmdInfo(prAdapter, prCmdInfo);
4756
4757 return WLAN_STATUS_SUCCESS;
4758}
4759
4760
4761/*----------------------------------------------------------------------------*/
4762/*!
4763* @brief This function is called to retrieve compiler flag from firmware
4764*
4765* @param prAdapter Pointer of Adapter Data Structure
4766*
4767* @return WLAN_STATUS_SUCCESS
4768* WLAN_STATUS_FAILURE
4769*/
4770/*----------------------------------------------------------------------------*/
4771WLAN_STATUS
4772wlanQueryCompileFlag(
4773 IN P_ADAPTER_T prAdapter,
4774 IN UINT_32 u4QueryID,
4775 OUT PUINT_32 pu4CompilerFlag
4776 )
4777{
4778 UINT_8 ucCmdSeqNum;
4779 P_CMD_INFO_T prCmdInfo;
4780 P_WIFI_CMD_T prWifiCmd;
4781 UINT_32 u4RxPktLength;
4782 UINT_8 aucBuffer[sizeof(WIFI_EVENT_T) + sizeof(CMD_SW_DBG_CTRL_T)];
4783 P_HIF_RX_HEADER_T prHifRxHdr;
4784 P_WIFI_EVENT_T prEvent;
4785 P_CMD_SW_DBG_CTRL_T prCmdNicCompileFlag, prEventNicCompileFlag;
4786
4787 ASSERT(prAdapter);
4788
4789 DEBUGFUNC(__FUNCTION__);
4790
4791 // 1. Allocate CMD Info Packet and its Buffer
4792 prCmdInfo = cmdBufAllocateCmdInfo(prAdapter, CMD_HDR_SIZE + sizeof(CMD_SW_DBG_CTRL_T));
4793 if (!prCmdInfo) {
4794 DBGLOG(INIT, ERROR, ("Allocate CMD_INFO_T ==> FAILED.\n"));
4795 return WLAN_STATUS_FAILURE;
4796 }
4797
4798 // increase command sequence number
4799 ucCmdSeqNum = nicIncreaseCmdSeqNum(prAdapter);
4800
4801 // compose CMD_BUILD_CONNECTION cmd pkt
4802 prCmdInfo->eCmdType = COMMAND_TYPE_GENERAL_IOCTL;
4803 prCmdInfo->u2InfoBufLen = CMD_HDR_SIZE + sizeof(CMD_SW_DBG_CTRL_T);
4804 prCmdInfo->pfCmdDoneHandler = NULL;
4805 prCmdInfo->fgIsOid = FALSE;
4806 prCmdInfo->ucCID = CMD_ID_SW_DBG_CTRL;
4807 prCmdInfo->fgSetQuery = FALSE;
4808 prCmdInfo->fgNeedResp = TRUE;
4809 prCmdInfo->fgDriverDomainMCR = FALSE;
4810 prCmdInfo->ucCmdSeqNum = ucCmdSeqNum;
4811 prCmdInfo->u4SetInfoLen = 0;
4812
4813 // Setup WIFI_CMD_T
4814 prWifiCmd = (P_WIFI_CMD_T)(prCmdInfo->pucInfoBuffer);
4815 prWifiCmd->u2TxByteCount_UserPriority = prCmdInfo->u2InfoBufLen;
4816 prWifiCmd->ucCID = prCmdInfo->ucCID;
4817 prWifiCmd->ucSetQuery = prCmdInfo->fgSetQuery;
4818 prWifiCmd->ucSeqNum = prCmdInfo->ucCmdSeqNum;
4819
4820 // Fill up SW CR
4821 prCmdNicCompileFlag = (P_CMD_SW_DBG_CTRL_T)(prWifiCmd->aucBuffer);
4822
4823 prCmdNicCompileFlag->u4Id = u4QueryID;
4824
4825 wlanSendCommand(prAdapter, prCmdInfo);
4826 cmdBufFreeCmdInfo(prAdapter, prCmdInfo);
4827
4828 if(nicRxWaitResponse(prAdapter,
4829 1,
4830 aucBuffer,
4831 sizeof(WIFI_EVENT_T) + sizeof(CMD_SW_DBG_CTRL_T),
4832 &u4RxPktLength) != WLAN_STATUS_SUCCESS) {
4833 return WLAN_STATUS_FAILURE;
4834 }
4835
4836 // header checking ..
4837 prHifRxHdr = (P_HIF_RX_HEADER_T)aucBuffer;
4838 if(prHifRxHdr->u2PacketType != HIF_RX_PKT_TYPE_EVENT) {
4839 return WLAN_STATUS_FAILURE;
4840 }
4841
4842 prEvent = (P_WIFI_EVENT_T)aucBuffer;
4843 if(prEvent->ucEID != EVENT_ID_SW_DBG_CTRL) {
4844 return WLAN_STATUS_FAILURE;
4845 }
4846
4847 prEventNicCompileFlag = (P_CMD_SW_DBG_CTRL_T)(prEvent->aucBuffer);
4848
4849 *pu4CompilerFlag = prEventNicCompileFlag->u4Data;
4850
4851 return WLAN_STATUS_SUCCESS;
4852}
4853
4854WLAN_STATUS
4855wlanQueryCompileFlags(
4856 IN P_ADAPTER_T prAdapter
4857 )
4858{
4859 wlanQueryCompileFlag(prAdapter, 0xA0240000, &prAdapter->u4FwCompileFlag0);
4860 wlanQueryCompileFlag(prAdapter, 0xA0240001, &prAdapter->u4FwCompileFlag1);
4861
4862 DBGLOG(INIT, TRACE, ("Compile Flags: 0x%08x 0x%08x\n", prAdapter->u4FwCompileFlag0, prAdapter->u4FwCompileFlag1));
4863
4864 return WLAN_STATUS_SUCCESS;
4865}
4866
4867#if defined(MT6628)
4868static INT_32 wlanChangeCodeWord(INT_32 au4Input){
4869
4870 UINT_16 i;
4871#if TXPWR_USE_PDSLOPE
4872 CODE_MAPPING_T arCodeTable[] = {
4873 {0X100, -40},
4874 {0X104, -35},
4875 {0X128, -30},
4876 {0X14C, -25},
4877 {0X170, -20},
4878 {0X194, -15},
4879 {0X1B8, -10},
4880 {0X1DC, - 5},
4881 {0 , 0},
4882 {0X24 , 5},
4883 {0X48 , 10},
4884 {0X6C , 15},
4885 {0X90 , 20},
4886 {0XB4 , 25},
4887 {0XD8 , 30},
4888 {0XFC , 35},
4889 {0XFF , 40},
4890
4891 };
4892#else
4893 CODE_MAPPING_T arCodeTable[] = {
4894 {0X100, 0x80},
4895 {0X104, 0x80},
4896 {0X128, 0x80},
4897 {0X14C, 0x80},
4898 {0X170, 0x80},
4899 {0X194, 0x94},
4900 {0X1B8, 0XB8},
4901 {0X1DC, 0xDC},
4902 {0 , 0},
4903 {0X24 , 0x24},
4904 {0X48 , 0x48},
4905 {0X6C , 0x6c},
4906 {0X90 , 0x7F},
4907 {0XB4 , 0x7F},
4908 {0XD8 , 0x7F},
4909 {0XFC , 0x7F},
4910 {0XFF , 0x7F},
4911
4912 };
4913#endif
4914
4915 for (i = 0; i < sizeof(arCodeTable) / sizeof(CODE_MAPPING_T); i++) {
4916
4917 if (arCodeTable[i].u4RegisterValue == au4Input){
4918 return arCodeTable[i].i4TxpowerOffset;
4919 }
4920 }
4921
4922
4923 return 0;
4924}
4925#endif
4926
4927
4928#if TXPWR_USE_PDSLOPE
4929
4930/*----------------------------------------------------------------------------*/
4931/*!
4932* @brief
4933*
4934* @param prAdapter Pointer of Adapter Data Structure
4935*
4936* @return WLAN_STATUS_SUCCESS
4937* WLAN_STATUS_FAILURE
4938*/
4939/*----------------------------------------------------------------------------*/
4940WLAN_STATUS
4941wlanQueryPdMcr(
4942 IN P_ADAPTER_T prAdapter,
4943 P_PARAM_MCR_RW_STRUC_T prMcrRdInfo
4944 )
4945{
4946 UINT_8 ucCmdSeqNum;
4947 P_CMD_INFO_T prCmdInfo;
4948 P_WIFI_CMD_T prWifiCmd;
4949 UINT_32 u4RxPktLength;
4950 UINT_8 aucBuffer[sizeof(WIFI_EVENT_T) + sizeof(CMD_ACCESS_REG)];
4951 P_HIF_RX_HEADER_T prHifRxHdr;
4952 P_WIFI_EVENT_T prEvent;
4953 P_CMD_ACCESS_REG prCmdMcrQuery;
4954 ASSERT(prAdapter);
4955
4956
4957 // 1. Allocate CMD Info Packet and its Buffer
4958 prCmdInfo = cmdBufAllocateCmdInfo(prAdapter, CMD_HDR_SIZE + sizeof(CMD_ACCESS_REG));
4959
4960 if (!prCmdInfo) {
4961 DBGLOG(INIT, ERROR, ("Allocate CMD_INFO_T ==> FAILED.\n"));
4962 return WLAN_STATUS_FAILURE;
4963 }
4964 // increase command sequence number
4965 ucCmdSeqNum = nicIncreaseCmdSeqNum(prAdapter);
4966
4967 // compose CMD_BUILD_CONNECTION cmd pkt
4968 prCmdInfo->eCmdType = COMMAND_TYPE_GENERAL_IOCTL;
4969 prCmdInfo->u2InfoBufLen = (UINT_16)(CMD_HDR_SIZE + sizeof(CMD_ACCESS_REG));
4970 prCmdInfo->pfCmdDoneHandler = NULL;
4971 prCmdInfo->pfCmdTimeoutHandler = nicOidCmdTimeoutCommon;
4972 prCmdInfo->fgIsOid = FALSE;
4973 prCmdInfo->ucCID = CMD_ID_ACCESS_REG;
4974 prCmdInfo->fgSetQuery = FALSE;
4975 prCmdInfo->fgNeedResp = TRUE;
4976 prCmdInfo->fgDriverDomainMCR = FALSE;
4977 prCmdInfo->ucCmdSeqNum = ucCmdSeqNum;
4978 prCmdInfo->u4SetInfoLen = sizeof(CMD_ACCESS_REG);
4979
4980 // Setup WIFI_CMD_T
4981 prWifiCmd = (P_WIFI_CMD_T)(prCmdInfo->pucInfoBuffer);
4982 prWifiCmd->u2TxByteCount_UserPriority = prCmdInfo->u2InfoBufLen;
4983 prWifiCmd->ucCID = prCmdInfo->ucCID;
4984 prWifiCmd->ucSetQuery = prCmdInfo->fgSetQuery;
4985 prWifiCmd->ucSeqNum = prCmdInfo->ucCmdSeqNum;
4986 kalMemCopy(prWifiCmd->aucBuffer, prMcrRdInfo, sizeof(CMD_ACCESS_REG));
4987
4988 wlanSendCommand(prAdapter, prCmdInfo);
4989 cmdBufFreeCmdInfo(prAdapter, prCmdInfo);
4990
4991 if(nicRxWaitResponse(prAdapter,
4992 1,
4993 aucBuffer,
4994 sizeof(WIFI_EVENT_T) + sizeof(CMD_ACCESS_REG),
4995 &u4RxPktLength) != WLAN_STATUS_SUCCESS) {
4996 return WLAN_STATUS_FAILURE;
4997 }
4998
4999 // header checking ..
5000 prHifRxHdr = (P_HIF_RX_HEADER_T)aucBuffer;
4b9e9796 5001 if ((prHifRxHdr->u2PacketType & HIF_RX_HDR_PACKET_TYPE_MASK) != HIF_RX_PKT_TYPE_EVENT) {
6fa3eb70
S
5002 return WLAN_STATUS_FAILURE;
5003 }
5004
5005
5006 prEvent = (P_WIFI_EVENT_T)aucBuffer;
5007
5008 if(prEvent->ucEID != EVENT_ID_ACCESS_REG) {
5009 return WLAN_STATUS_FAILURE;
5010 }
5011
5012 prCmdMcrQuery = (P_CMD_ACCESS_REG)(prEvent->aucBuffer);
5013 prMcrRdInfo->u4McrOffset = prCmdMcrQuery->u4Address;
5014 prMcrRdInfo->u4McrData = prCmdMcrQuery->u4Data;
5015
5016 return WLAN_STATUS_SUCCESS;
5017}
5018
5019static INT_32 wlanIntRound(INT_32 au4Input)
5020{
5021
5022
5023 if (au4Input >= 0){
5024 if((au4Input%10) == 5){
5025 au4Input = au4Input + 5;
5026 return au4Input;
5027 }
5028 }
5029
5030 if (au4Input < 0){
5031 if((au4Input%10) == -5){
5032 au4Input = au4Input - 5;
5033 return au4Input;
5034 }
5035 }
5036
5037 return au4Input;
5038}
5039
5040static INT_32 wlanCal6628EfuseForm(IN P_ADAPTER_T prAdapter,INT_32 au4Input){
5041
5042 PARAM_MCR_RW_STRUC_T rMcrRdInfo;
5043 INT_32 au4PdSlope,au4TxPwrOffset,au4TxPwrOffset_Round;
5044 INT_8 auTxPwrOffset_Round;
5045
5046 rMcrRdInfo.u4McrOffset = 0x60205c68;
5047 rMcrRdInfo.u4McrData = 0;
5048 au4TxPwrOffset = au4Input;
5049 wlanQueryPdMcr(prAdapter,&rMcrRdInfo);
5050
5051 au4PdSlope = (rMcrRdInfo.u4McrData) & BITS(0,6);
5052 au4TxPwrOffset_Round = wlanIntRound((au4TxPwrOffset*au4PdSlope))/10;
5053
5054 au4TxPwrOffset_Round = -au4TxPwrOffset_Round;
5055
5056 if(au4TxPwrOffset_Round < -128) {
5057 au4TxPwrOffset_Round = 128;
5058 }
5059 else if (au4TxPwrOffset_Round < 0){
5060 au4TxPwrOffset_Round += 256;
5061 }
5062 else if (au4TxPwrOffset_Round > 127){
5063 au4TxPwrOffset_Round = 127;
5064 }
5065
5066 auTxPwrOffset_Round = (UINT8) au4TxPwrOffset_Round ;
5067
5068 return au4TxPwrOffset_Round;
5069}
5070
5071#endif
5072
5073
5074#if defined(MT6628)
5075static VOID wlanChangeNvram6620to6628(PUINT_8 pucEFUSE){
5076
5077
5078 #define EFUSE_CH_OFFSET1_L_MASK_6620 BITS(0,8)
5079 #define EFUSE_CH_OFFSET1_L_SHIFT_6620 0
5080 #define EFUSE_CH_OFFSET1_M_MASK_6620 BITS(9,17)
5081 #define EFUSE_CH_OFFSET1_M_SHIFT_6620 9
5082 #define EFUSE_CH_OFFSET1_H_MASK_6620 BITS(18,26)
5083 #define EFUSE_CH_OFFSET1_H_SHIFT_6620 18
5084 #define EFUSE_CH_OFFSET1_VLD_MASK_6620 BIT(27)
5085 #define EFUSE_CH_OFFSET1_VLD_SHIFT_6620 27
5086
5087 #define EFUSE_CH_OFFSET1_L_MASK_5931 BITS(0,7)
5088 #define EFUSE_CH_OFFSET1_L_SHIFT_5931 0
5089 #define EFUSE_CH_OFFSET1_M_MASK_5931 BITS(8,15)
5090 #define EFUSE_CH_OFFSET1_M_SHIFT_5931 8
5091 #define EFUSE_CH_OFFSET1_H_MASK_5931 BITS(16,23)
5092 #define EFUSE_CH_OFFSET1_H_SHIFT_5931 16
5093 #define EFUSE_CH_OFFSET1_VLD_MASK_5931 BIT(24)
5094 #define EFUSE_CH_OFFSET1_VLD_SHIFT_5931 24
5095 #define EFUSE_ALL_CH_OFFSET1_MASK_5931 BITS(25,27)
5096 #define EFUSE_ALL_CH_OFFSET1_SHIFT_5931 25
5097
5098
5099
5100
5101 INT_32 au4ChOffset;
5102 INT_16 au2ChOffsetL,au2ChOffsetM,au2ChOffsetH;
5103
5104
5105 au4ChOffset = *(UINT_32*)(pucEFUSE + 72);
5106
5107 if((au4ChOffset & EFUSE_CH_OFFSET1_VLD_MASK_6620) && ((*(UINT_32*)(pucEFUSE + 28)) == 0)) {
5108
5109
5110 au2ChOffsetL = ((au4ChOffset & EFUSE_CH_OFFSET1_L_MASK_6620) >>
5111 EFUSE_CH_OFFSET1_L_SHIFT_6620);
5112
5113 au2ChOffsetM = ((au4ChOffset & EFUSE_CH_OFFSET1_M_MASK_6620) >>
5114 EFUSE_CH_OFFSET1_M_SHIFT_6620);
5115
5116 au2ChOffsetH = ((au4ChOffset & EFUSE_CH_OFFSET1_H_MASK_6620) >>
5117 EFUSE_CH_OFFSET1_H_SHIFT_6620);
5118
5119 au2ChOffsetL = wlanChangeCodeWord(au2ChOffsetL);
5120 au2ChOffsetM = wlanChangeCodeWord(au2ChOffsetM);
5121 au2ChOffsetH = wlanChangeCodeWord(au2ChOffsetH);
5122
5123 au4ChOffset = 0;
5124 au4ChOffset |= *(UINT_32*)(pucEFUSE + 72)
5125 >> (EFUSE_CH_OFFSET1_VLD_SHIFT_6620 - EFUSE_CH_OFFSET1_VLD_SHIFT_5931 )& EFUSE_CH_OFFSET1_VLD_MASK_5931 ;
5126
5127
5128
5129 au4ChOffset |= ((((UINT_32)au2ChOffsetL) << EFUSE_CH_OFFSET1_L_SHIFT_5931) & EFUSE_CH_OFFSET1_L_MASK_5931);
5130 au4ChOffset |= ((((UINT_32)au2ChOffsetM) << EFUSE_CH_OFFSET1_M_SHIFT_5931) & EFUSE_CH_OFFSET1_M_MASK_5931);
5131 au4ChOffset |= ((((UINT_32)au2ChOffsetH) << EFUSE_CH_OFFSET1_H_SHIFT_5931) & EFUSE_CH_OFFSET1_H_MASK_5931);
5132
5133 *((INT_32 *)((pucEFUSE + 28))) = au4ChOffset ;
5134
5135
5136
5137 }
5138
5139}
5140#endif
5141
5142/*----------------------------------------------------------------------------*/
5143/*!
5144* @brief This function is called to load manufacture data from NVRAM
5145* if available and valid
5146*
5147* @param prAdapter Pointer of Adapter Data Structure
5148* @param prRegInfo Pointer of REG_INFO_T
5149*
5150* @return WLAN_STATUS_SUCCESS
5151* WLAN_STATUS_FAILURE
5152*/
5153/*----------------------------------------------------------------------------*/
5154WLAN_STATUS
5155wlanLoadManufactureData (
5156 IN P_ADAPTER_T prAdapter,
5157 IN P_REG_INFO_T prRegInfo
5158 )
5159{
5160#if CFG_SUPPORT_RDD_TEST_MODE
5161 CMD_RDD_CH_T rRddParam;
5162#endif
5163
5164 ASSERT(prAdapter);
5165
5166 /* 1. Version Check */
5167 kalGetConfigurationVersion(prAdapter->prGlueInfo,
5168 &(prAdapter->rVerInfo.u2Part1CfgOwnVersion),
5169 &(prAdapter->rVerInfo.u2Part1CfgPeerVersion),
5170 &(prAdapter->rVerInfo.u2Part2CfgOwnVersion),
5171 &(prAdapter->rVerInfo.u2Part2CfgPeerVersion));
5172
5173#if (CFG_SW_NVRAM_VERSION_CHECK == 1)
5174 if(CFG_DRV_OWN_VERSION < prAdapter->rVerInfo.u2Part1CfgPeerVersion
5175 || CFG_DRV_OWN_VERSION < prAdapter->rVerInfo.u2Part2CfgPeerVersion
5176 || prAdapter->rVerInfo.u2Part1CfgOwnVersion < CFG_DRV_PEER_VERSION
5177 || prAdapter->rVerInfo.u2Part2CfgOwnVersion < CFG_DRV_PEER_VERSION) {
5178 return WLAN_STATUS_FAILURE;
5179 }
5180#endif
5181
5182 // MT6620 E1/E2 would be ignored directly
5183 if(prAdapter->rVerInfo.u2Part1CfgOwnVersion == 0x0001) {
5184 prRegInfo->ucTxPwrValid = 1;
5185 }
5186 else {
5187 /* 2. Load TX power gain parameters if valid */
5188 if(prRegInfo->ucTxPwrValid != 0) {
5189 // send to F/W
5190 nicUpdateTxPower(prAdapter, (P_CMD_TX_PWR_T)(&(prRegInfo->rTxPwr)));
5191 }
5192 }
5193
5194 /* 3. Check if needs to support 5GHz */
5195 //if(prRegInfo->ucEnable5GBand) { // Frank workaround
5196 if(1) {
5197 // check if it is disabled by hardware
5198 if(prAdapter->fgIsHw5GBandDisabled
5199 || prRegInfo->ucSupport5GBand == 0) {
5200 prAdapter->fgEnable5GBand = FALSE;
5201 }
5202 else {
5203 prAdapter->fgEnable5GBand = TRUE;
5204 }
5205 }
5206 else {
5207 prAdapter->fgEnable5GBand = FALSE;
5208 }
5209
5210 printk("NVRAM 5G Enable(%d) SW_En(%d) HW_Dis(%d)\n",
5211 prRegInfo->ucEnable5GBand,
5212 prRegInfo->ucSupport5GBand,
5213 prAdapter->fgIsHw5GBandDisabled
5214 );
5215
5216
5217 /* 4. Send EFUSE data */
5218#if defined(MT6628)
5219 wlanChangeNvram6620to6628(prRegInfo->aucEFUSE);
5220#endif
5221
5222 wlanSendSetQueryCmd(prAdapter,
5223 CMD_ID_SET_PHY_PARAM,
5224 TRUE,
5225 FALSE,
5226 FALSE,
5227 NULL,
5228 NULL,
5229 sizeof(CMD_PHY_PARAM_T),
5230 (PUINT_8)(prRegInfo->aucEFUSE),
5231 NULL,
5232 0);
5233
5234#if CFG_SUPPORT_RDD_TEST_MODE
5235 rRddParam.ucRddTestMode = (UINT_8) prRegInfo->u4RddTestMode;
5236 rRddParam.ucRddShutCh = (UINT_8) prRegInfo->u4RddShutFreq;
5237 rRddParam.ucRddStartCh = (UINT_8) nicFreq2ChannelNum(prRegInfo->u4RddStartFreq);
5238 rRddParam.ucRddStopCh = (UINT_8) nicFreq2ChannelNum(prRegInfo->u4RddStopFreq);
5239 rRddParam.ucRddDfs = (UINT_8) prRegInfo->u4RddDfs;
5240 prAdapter->ucRddStatus = 0;
5241 nicUpdateRddTestMode(prAdapter, (P_CMD_RDD_CH_T)(&rRddParam));
5242#endif
5243
5244 /* 5. Get 16-bits Country Code and Bandwidth */
5245 prAdapter->rWifiVar.rConnSettings.u2CountryCode =
5246 (((UINT_16) prRegInfo->au2CountryCode[0]) << 8) |
5247 (((UINT_16) prRegInfo->au2CountryCode[1]) & BITS(0,7));
5248
5249 printk("NVRAM CountryCode(0x%x 0x%x)\n",
5250 prRegInfo->au2CountryCode[0],
5251 prRegInfo->au2CountryCode[1]
5252 );
5253
5254#if 0 /* Bandwidth control will be controlled by GUI. 20110930
5255 * So ignore the setting from registry/NVRAM
5256 */
5257 prAdapter->rWifiVar.rConnSettings.uc2G4BandwidthMode =
5258 prRegInfo->uc2G4BwFixed20M ? CONFIG_BW_20M : CONFIG_BW_20_40M;
5259 prAdapter->rWifiVar.rConnSettings.uc5GBandwidthMode =
5260 prRegInfo->uc5GBwFixed20M ? CONFIG_BW_20M : CONFIG_BW_20_40M;
5261#endif
5262
5263 /* 6. Set domain and channel information to chip */
5264 rlmDomainSendCmd(prAdapter, FALSE);
5265
5266 /* 7. set band edge tx power if available */
5267 if(prRegInfo->fg2G4BandEdgePwrUsed) {
5268 CMD_EDGE_TXPWR_LIMIT_T rCmdEdgeTxPwrLimit;
5269
5270 rCmdEdgeTxPwrLimit.cBandEdgeMaxPwrCCK
5271 = prRegInfo->cBandEdgeMaxPwrCCK;
5272 rCmdEdgeTxPwrLimit.cBandEdgeMaxPwrOFDM20
5273 = prRegInfo->cBandEdgeMaxPwrOFDM20;
5274 rCmdEdgeTxPwrLimit.cBandEdgeMaxPwrOFDM40
5275 = prRegInfo->cBandEdgeMaxPwrOFDM40;
5276
5277 printk("NVRAM 2G Bandedge CCK(%d) HT20(%d)HT40(%d)\n",
5278 rCmdEdgeTxPwrLimit.cBandEdgeMaxPwrCCK,
5279 rCmdEdgeTxPwrLimit.cBandEdgeMaxPwrOFDM20,
5280 rCmdEdgeTxPwrLimit.cBandEdgeMaxPwrOFDM40
5281 );
5282
5283 wlanSendSetQueryCmd(prAdapter,
5284 CMD_ID_SET_EDGE_TXPWR_LIMIT,
5285 TRUE,
5286 FALSE,
5287 FALSE,
5288 NULL,
5289 NULL,
5290 sizeof(CMD_EDGE_TXPWR_LIMIT_T),
5291 (PUINT_8)&rCmdEdgeTxPwrLimit,
5292 NULL,
5293 0);
5294 }
5295 /* 8. set 5G band edge tx power if available (add for 6625) */
5296 if (prAdapter->fgEnable5GBand){
5297#define NVRAM_5G_TX_BANDEDGE_VALID_OFFSET 10
5298#define NVRAM_5G_TX_BANDEDGE_OFDM20_OFFSET 11
5299#define NVRAM_5G_TX_BANDEDGE_OFDM40_OFFSET 12
5300
5301 if(prRegInfo->aucEFUSE[NVRAM_5G_TX_BANDEDGE_VALID_OFFSET]) {
5302 CMD_EDGE_TXPWR_LIMIT_T rCmdEdgeTxPwrLimit;
5303
5304 rCmdEdgeTxPwrLimit.cBandEdgeMaxPwrOFDM20
5305 = prRegInfo->aucEFUSE[NVRAM_5G_TX_BANDEDGE_OFDM20_OFFSET];
5306 rCmdEdgeTxPwrLimit.cBandEdgeMaxPwrOFDM40
5307 = prRegInfo->aucEFUSE[NVRAM_5G_TX_BANDEDGE_OFDM40_OFFSET];
5308
5309 printk("NVRAM 5G Bandedge HT20(%d)HT40(%d)\n",
5310 rCmdEdgeTxPwrLimit.cBandEdgeMaxPwrOFDM20,
5311 rCmdEdgeTxPwrLimit.cBandEdgeMaxPwrOFDM40
5312 );
5313
5314 wlanSendSetQueryCmd(prAdapter,
5315 CMD_ID_SET_5G_EDGE_TXPWR_LIMIT,
5316 TRUE,
5317 FALSE,
5318 FALSE,
5319 NULL,
5320 NULL,
5321 sizeof(CMD_EDGE_TXPWR_LIMIT_T),
5322 (PUINT_8)&rCmdEdgeTxPwrLimit,
5323 NULL,
5324 0);
5325 }
5326 }
5327 /* 9. set RSSI compensation */
5328 //printk("[frank] RSSI valid(%d) 2G(%d) 5G(%d)",prRegInfo->fgRssiCompensationValidbit,prRegInfo->uc2GRssiCompensation,prRegInfo->uc5GRssiCompensation);
5329 if (prRegInfo->fgRssiCompensationValidbit){
5330 CMD_RSSI_COMPENSATE_T rCmdRssiCompensate;
5331 rCmdRssiCompensate.uc2GRssiCompensation = prRegInfo->uc2GRssiCompensation;
5332 rCmdRssiCompensate.uc5GRssiCompensation = prRegInfo->uc5GRssiCompensation;
5333
5334 printk("NVRAM RSSI Comp. 2G(%d)5G(%d)\n",
5335 rCmdRssiCompensate.uc2GRssiCompensation,
5336 rCmdRssiCompensate.uc5GRssiCompensation
5337 );
5338 wlanSendSetQueryCmd(prAdapter,
5339 CMD_ID_SET_RSSI_COMPENSATE,
5340 TRUE,
5341 FALSE,
5342 FALSE,
5343 NULL,
5344 NULL,
5345 sizeof(CMD_RSSI_COMPENSATE_T),
5346 (PUINT_8)&rCmdRssiCompensate,
5347 NULL,
5348 0);
5349 }
5350 /* 10. notify FW Band Support 5G */
5351 if (prAdapter->fgEnable5GBand){
5352 CMD_BAND_SUPPORT_T rCmdBandSupport;
5353 rCmdBandSupport.uc5GBandSupport = TRUE;
5354 printk("NVRAM 5G BandSupport\n");
5355 wlanSendSetQueryCmd(prAdapter,
5356 CMD_ID_SET_BAND_SUPPORT,
5357 TRUE,
5358 FALSE,
5359 FALSE,
5360 NULL,
5361 NULL,
5362 sizeof(CMD_BAND_SUPPORT_T),
5363 (PUINT_8)&rCmdBandSupport,
5364 NULL,
5365 0);
5366
5367 }
5368
5369 return WLAN_STATUS_SUCCESS;
5370}
5371
5372
5373/*----------------------------------------------------------------------------*/
5374/*!
5375* @brief This function is called to check
5376* Media Stream Mode is set to non-default value or not,
5377* and clear to default value if above criteria is met
5378*
5379* @param prAdapter Pointer of Adapter Data Structure
5380*
5381* @return TRUE
5382* The media stream mode was non-default value and has been reset
5383* FALSE
5384* The media stream mode is default value
5385*/
5386/*----------------------------------------------------------------------------*/
5387BOOLEAN
5388wlanResetMediaStreamMode(
5389 IN P_ADAPTER_T prAdapter
5390 )
5391{
5392 ASSERT(prAdapter);
5393
5394 if(prAdapter->rWlanInfo.eLinkAttr.ucMediaStreamMode != 0) {
5395 prAdapter->rWlanInfo.eLinkAttr.ucMediaStreamMode = 0;
5396
5397 return TRUE;
5398 }
5399 else {
5400 return FALSE;
5401 }
5402}
5403
5404
5405/*----------------------------------------------------------------------------*/
5406/*!
5407* @brief This function is called to check if any pending timer has expired
5408*
5409* @param prAdapter Pointer of Adapter Data Structure
5410*
5411* @return WLAN_STATUS_SUCCESS
5412*/
5413/*----------------------------------------------------------------------------*/
5414WLAN_STATUS
5415wlanTimerTimeoutCheck(
5416 IN P_ADAPTER_T prAdapter
5417 )
5418{
5419 ASSERT(prAdapter);
5420
5421 /* check timer status */
5422 cnmTimerDoTimeOutCheck(prAdapter);
5423
5424 return WLAN_STATUS_SUCCESS;
5425}
5426
5427
5428/*----------------------------------------------------------------------------*/
5429/*!
5430* @brief This function is called to check if any pending mailbox message
5431* to be handled
5432*
5433* @param prAdapter Pointer of Adapter Data Structure
5434*
5435* @return WLAN_STATUS_SUCCESS
5436*/
5437/*----------------------------------------------------------------------------*/
5438WLAN_STATUS
5439wlanProcessMboxMessage(
5440 IN P_ADAPTER_T prAdapter
5441 )
5442{
5443 UINT_32 i;
5444
5445 ASSERT(prAdapter);
5446
5447 for(i = 0 ; i < MBOX_ID_TOTAL_NUM ; i++) { /* MBOX_ID_TOTAL_NUM = 1 */
5448 mboxRcvAllMsg(prAdapter , (ENUM_MBOX_ID_T)i);
5449 }
5450
5451 return WLAN_STATUS_SUCCESS;
5452}
5453
5454
5455/*----------------------------------------------------------------------------*/
5456/*!
5457* @brief This function is called to enqueue a single TX packet into CORE
5458*
5459* @param prAdapter Pointer of Adapter Data Structure
5460* prNativePacket Pointer of Native Packet
5461*
5462* @return WLAN_STATUS_SUCCESS
5463* WLAN_STATUS_RESOURCES
5464* WLAN_STATUS_INVALID_PACKET
5465*/
5466/*----------------------------------------------------------------------------*/
5467WLAN_STATUS
5468wlanEnqueueTxPacket (
5469 IN P_ADAPTER_T prAdapter,
5470 IN P_NATIVE_PACKET prNativePacket
5471 )
5472{
5473 P_TX_CTRL_T prTxCtrl;
5474 P_MSDU_INFO_T prMsduInfo;
5475
5476 KAL_SPIN_LOCK_DECLARATION();
5477
5478 ASSERT(prAdapter);
5479
5480 prTxCtrl = &prAdapter->rTxCtrl;
5481
5482 /* get a free packet header */
5483 KAL_ACQUIRE_SPIN_LOCK(prAdapter, SPIN_LOCK_TX_MSDU_INFO_LIST);
5484 QUEUE_REMOVE_HEAD(&prTxCtrl->rFreeMsduInfoList, prMsduInfo, P_MSDU_INFO_T);
5485 KAL_RELEASE_SPIN_LOCK(prAdapter, SPIN_LOCK_TX_MSDU_INFO_LIST);
5486
5487 if(prMsduInfo == NULL) {
5488 return WLAN_STATUS_RESOURCES;
5489 }
5490 else {
5491 prMsduInfo->eSrc = TX_PACKET_OS;
5492
5493 if(nicTxFillMsduInfo(prAdapter,
5494 prMsduInfo,
5495 prNativePacket) == FALSE) { // packet is not extractable
5496
5497 /* fill fails */
5498 kalSendComplete(prAdapter->prGlueInfo,
5499 prNativePacket,
5500 WLAN_STATUS_INVALID_PACKET);
5501
5502 nicTxReturnMsduInfo(prAdapter, prMsduInfo);
5503
5504 return WLAN_STATUS_INVALID_PACKET;
5505 }
5506 else {
5507 // enqueue to QM
5508 nicTxEnqueueMsdu(prAdapter, prMsduInfo);
5509
5510 return WLAN_STATUS_SUCCESS;
5511 }
5512 }
5513}
5514
5515
5516/*----------------------------------------------------------------------------*/
5517/*!
5518* @brief This function is called to flush pending TX packets in CORE
5519*
5520* @param prAdapter Pointer of Adapter Data Structure
5521*
5522* @return WLAN_STATUS_SUCCESS
5523*/
5524/*----------------------------------------------------------------------------*/
5525WLAN_STATUS
5526wlanFlushTxPendingPackets(
5527 IN P_ADAPTER_T prAdapter
5528 )
5529{
5530 ASSERT(prAdapter);
5531
5532 return nicTxFlush(prAdapter);
5533}
5534
5535
5536/*----------------------------------------------------------------------------*/
5537/*!
5538* \brief this function sends pending MSDU_INFO_T to MT6620
5539*
5540* @param prAdapter Pointer to the Adapter structure.
5541* @param pfgHwAccess Pointer for tracking LP-OWN status
5542*
5543* @retval WLAN_STATUS_SUCCESS Reset is done successfully.
5544*/
5545/*----------------------------------------------------------------------------*/
5546WLAN_STATUS
5547wlanTxPendingPackets (
5548 IN P_ADAPTER_T prAdapter,
5549 IN OUT PBOOLEAN pfgHwAccess
5550 )
5551{
5552 P_TX_CTRL_T prTxCtrl;
5553 P_MSDU_INFO_T prMsduInfo;
5554
5555 KAL_SPIN_LOCK_DECLARATION();
5556
5557 ASSERT(prAdapter);
5558 prTxCtrl = &prAdapter->rTxCtrl;
5559
5560 ASSERT(pfgHwAccess);
5561
5562 // <1> dequeue packets by txDequeuTxPackets()
5563 /* Note: prMsduInfo is a packet list queue */
5564 KAL_ACQUIRE_SPIN_LOCK(prAdapter, SPIN_LOCK_QM_TX_QUEUE);
5565 prMsduInfo = qmDequeueTxPackets(prAdapter, &prTxCtrl->rTc);
5566 KAL_RELEASE_SPIN_LOCK(prAdapter, SPIN_LOCK_QM_TX_QUEUE);
5567
5568 if(prMsduInfo != NULL) {
5569 if(kalIsCardRemoved(prAdapter->prGlueInfo) == FALSE) {
5570 /* <2> Acquire LP-OWN if necessary */
5571 if(*pfgHwAccess == FALSE) {
5572 *pfgHwAccess = TRUE;
5573
5574 wlanAcquirePowerControl(prAdapter);
5575 }
5576
5577#if (MT6620_E1_ASIC_HIFSYS_WORKAROUND == 1)
5578 if(prAdapter->fgIsClockGatingEnabled == TRUE) {
5579 nicDisableClockGating(prAdapter);
5580 }
5581#endif
5582 // <3> send packet"s" to HIF
5583 nicTxMsduInfoList(prAdapter, prMsduInfo);
5584
5585 // <4> update TC by txAdjustTcQuotas()
5586 nicTxAdjustTcq(prAdapter);
5587 }
5588 else {
5589
5590 /* free the packet */
5591 wlanProcessQueuedMsduInfo(prAdapter, prMsduInfo);
5592 }
5593 }
5594
5595#if (MT6620_E1_ASIC_HIFSYS_WORKAROUND == 1)
5596 if(prAdapter->fgIsClockGatingEnabled == FALSE) {
5597 nicEnableClockGating(prAdapter);
5598 }
5599#endif
5600
5601 return WLAN_STATUS_SUCCESS;
5602}
5603
5604
5605/*----------------------------------------------------------------------------*/
5606/*!
5607* @brief This function is called to acquire power control from firmware
5608*
5609* @param prAdapter Pointer of Adapter Data Structure
5610*
5611* @return WLAN_STATUS_SUCCESS
5612*/
5613/*----------------------------------------------------------------------------*/
5614WLAN_STATUS
5615wlanAcquirePowerControl(
5616 IN P_ADAPTER_T prAdapter
5617 )
5618{
5619 ASSERT(prAdapter);
5620
5621 /* do driver own */
5622 ACQUIRE_POWER_CONTROL_FROM_PM(prAdapter);
5623
5624 /* Reset sleepy state */ /* no use */
5625 if(prAdapter->fgWiFiInSleepyState == TRUE) {
5626 prAdapter->fgWiFiInSleepyState = FALSE;
5627 }
5628
5629 return WLAN_STATUS_SUCCESS;
5630}
5631
5632
5633/*----------------------------------------------------------------------------*/
5634/*!
5635* @brief This function is called to release power control to firmware
5636*
5637* @param prAdapter Pointer of Adapter Data Structure
5638*
5639* @return WLAN_STATUS_SUCCESS
5640*/
5641/*----------------------------------------------------------------------------*/
5642WLAN_STATUS
5643wlanReleasePowerControl(
5644 IN P_ADAPTER_T prAdapter
5645 )
5646{
5647 ASSERT(prAdapter);
5648
5649 /* do FW own */
5650 RECLAIM_POWER_CONTROL_TO_PM(prAdapter, FALSE);
5651
5652 return WLAN_STATUS_SUCCESS;
5653}
5654
5655
5656/*----------------------------------------------------------------------------*/
5657/*!
5658* @brief This function is called to report currently pending TX frames count
5659* (command packets are not included)
5660*
5661* @param prAdapter Pointer of Adapter Data Structure
5662*
5663* @return number of pending TX frames
5664*/
5665/*----------------------------------------------------------------------------*/
5666UINT_32
5667wlanGetTxPendingFrameCount (
5668 IN P_ADAPTER_T prAdapter
5669 )
5670{
5671 P_TX_CTRL_T prTxCtrl;
5672 UINT_32 u4Num;
5673
5674 ASSERT(prAdapter);
5675 prTxCtrl = &prAdapter->rTxCtrl;
5676
5677 /* number in prTxQueue + number in RX forward */
5678 u4Num = kalGetTxPendingFrameCount(prAdapter->prGlueInfo) + (UINT_32)(prTxCtrl->i4PendingFwdFrameCount);
5679
5680 return u4Num;
5681}
5682
5683
5684/*----------------------------------------------------------------------------*/
5685/*!
5686* @brief This function is to report current ACPI state
5687*
5688* @param prAdapter Pointer of Adapter Data Structure
5689*
5690* @return ACPI_STATE_D0 Normal Operation Mode
5691* ACPI_STATE_D3 Suspend Mode
5692*/
5693/*----------------------------------------------------------------------------*/
5694ENUM_ACPI_STATE_T
5695wlanGetAcpiState (
5696 IN P_ADAPTER_T prAdapter
5697 )
5698{
5699 ASSERT(prAdapter);
5700
5701 return prAdapter->rAcpiState;
5702}
5703
5704
5705/*----------------------------------------------------------------------------*/
5706/*!
5707* @brief This function is to update current ACPI state only
5708*
5709* @param prAdapter Pointer of Adapter Data Structure
5710* @param ePowerState ACPI_STATE_D0 Normal Operation Mode
5711* ACPI_STATE_D3 Suspend Mode
5712*
5713* @return none
5714*/
5715/*----------------------------------------------------------------------------*/
5716VOID
5717wlanSetAcpiState (
5718 IN P_ADAPTER_T prAdapter,
5719 IN ENUM_ACPI_STATE_T ePowerState
5720 )
5721{
5722 ASSERT(prAdapter);
5723 ASSERT(ePowerState <= ACPI_STATE_D3);
5724
5725 prAdapter->rAcpiState = ePowerState;
5726
5727 return;
5728}
5729
5730
5731/*----------------------------------------------------------------------------*/
5732/*!
5733* @brief This function is to query ECO version from HIFSYS CR
5734*
5735* @param prAdapter Pointer of Adapter Data Structure
5736*
5737* @return zero Unable to retrieve ECO version information
5738* non-zero ECO version (1-based)
5739*/
5740/*----------------------------------------------------------------------------*/
5741UINT_8
5742wlanGetEcoVersion(
5743 IN P_ADAPTER_T prAdapter
5744 )
5745{
5746 ASSERT(prAdapter);
5747
5748 if(nicVerifyChipID(prAdapter) == TRUE) {
5749 return (prAdapter->ucRevID + 1);
5750 }
5751 else {
5752 return 0;
5753 }
5754}
5755
5756
5757/*----------------------------------------------------------------------------*/
5758/*!
5759* @brief This function is to setting the default Tx Power configuration
5760*
5761* @param prAdapter Pointer of Adapter Data Structure
5762*
5763* @return zero Unable to retrieve ECO version information
5764* non-zero ECO version (1-based)
5765*/
5766/*----------------------------------------------------------------------------*/
5767VOID
5768wlanDefTxPowerCfg (
5769 IN P_ADAPTER_T prAdapter
5770 )
5771{
5772 UINT_8 i;
5773 P_GLUE_INFO_T prGlueInfo = prAdapter->prGlueInfo;
5774 P_SET_TXPWR_CTRL_T prTxpwr;
5775
5776 ASSERT(prGlueInfo);
5777
5778 prTxpwr = &prGlueInfo->rTxPwr;
5779
5780 prTxpwr->c2GLegacyStaPwrOffset = 0;
5781 prTxpwr->c2GHotspotPwrOffset = 0;
5782 prTxpwr->c2GP2pPwrOffset = 0;
5783 prTxpwr->c2GBowPwrOffset = 0;
5784 prTxpwr->c5GLegacyStaPwrOffset = 0;
5785 prTxpwr->c5GHotspotPwrOffset = 0;
5786 prTxpwr->c5GP2pPwrOffset = 0;
5787 prTxpwr->c5GBowPwrOffset = 0;
5788 prTxpwr->ucConcurrencePolicy = 0;
5789 for (i=0; i<3;i++)
5790 prTxpwr->acReserved1[i] = 0;
5791
5792 for (i=0; i<14;i++)
5793 prTxpwr->acTxPwrLimit2G[i] = 63;
5794
5795 for (i=0; i<4;i++)
5796 prTxpwr->acTxPwrLimit5G[i] = 63;
5797
5798 for (i=0; i<2;i++)
5799 prTxpwr->acReserved2[i] = 0;
5800
5801}
5802
5803
5804/*----------------------------------------------------------------------------*/
5805/*!
5806* @brief This function is to
5807* set preferred band configuration corresponding to network type
5808*
5809* @param prAdapter Pointer of Adapter Data Structure
5810* @param eBand Given band
5811* @param eNetTypeIndex Given Network Type
5812*
5813* @return none
5814*/
5815/*----------------------------------------------------------------------------*/
5816VOID
5817wlanSetPreferBandByNetwork (
5818 IN P_ADAPTER_T prAdapter,
5819 IN ENUM_BAND_T eBand,
5820 IN ENUM_NETWORK_TYPE_INDEX_T eNetTypeIndex
5821 )
5822{
5823 ASSERT(prAdapter);
5824 ASSERT(eBand <= BAND_NUM);
5825 ASSERT(eNetTypeIndex <= NETWORK_TYPE_INDEX_NUM);
5826
5827 /* 1. set prefer band according to network type */
5828 prAdapter->aePreferBand[eNetTypeIndex] = eBand;
5829
5830 /* 2. remove buffered BSS descriptors correspondingly */
5831 if(eBand == BAND_2G4) {
5832 scanRemoveBssDescByBandAndNetwork(prAdapter, BAND_5G, eNetTypeIndex);
5833 }
5834 else if(eBand == BAND_5G) {
5835 scanRemoveBssDescByBandAndNetwork(prAdapter, BAND_2G4, eNetTypeIndex);
5836 }
5837
5838 return;
5839}
5840
5841
5842/*----------------------------------------------------------------------------*/
5843/*!
5844* @brief This function is to
5845* get channel information corresponding to specified network type
5846*
5847* @param prAdapter Pointer of Adapter Data Structure
5848* @param eNetTypeIndex Given Network Type
5849*
5850* @return channel number
5851*/
5852/*----------------------------------------------------------------------------*/
5853UINT_8
5854wlanGetChannelNumberByNetwork (
5855 IN P_ADAPTER_T prAdapter,
5856 IN ENUM_NETWORK_TYPE_INDEX_T eNetTypeIndex
5857 )
5858{
5859 P_BSS_INFO_T prBssInfo;
5860
5861 ASSERT(prAdapter);
5862 ASSERT(eNetTypeIndex <= NETWORK_TYPE_INDEX_NUM);
5863
5864 prBssInfo = &(prAdapter->rWifiVar.arBssInfo[eNetTypeIndex]);
5865
5866 return prBssInfo->ucPrimaryChannel;
5867}
5868
5869
5870/*----------------------------------------------------------------------------*/
5871/*!
5872* @brief This function is to
5873* get BSS descriptor information corresponding to specified network type
5874*
5875* @param prAdapter Pointer of Adapter Data Structure
5876* @param eNetTypeIndex Given Network Type
5877*
5878* @return pointer to BSS_DESC_T
5879*/
5880/*----------------------------------------------------------------------------*/
5881P_BSS_DESC_T
5882wlanGetTargetBssDescByNetwork (
5883 IN P_ADAPTER_T prAdapter,
5884 IN ENUM_NETWORK_TYPE_INDEX_T eNetTypeIndex
5885 )
5886{
5887 ASSERT(prAdapter);
5888 ASSERT(eNetTypeIndex <= NETWORK_TYPE_INDEX_NUM);
5889
5890 switch(eNetTypeIndex) {
5891 case NETWORK_TYPE_AIS_INDEX:
5892 return prAdapter->rWifiVar.rAisFsmInfo.prTargetBssDesc;
5893
5894 case NETWORK_TYPE_P2P_INDEX:
5895 return NULL;
5896
5897 case NETWORK_TYPE_BOW_INDEX:
5898 return prAdapter->rWifiVar.rBowFsmInfo.prTargetBssDesc;
5899
5900 default:
5901 return NULL;
5902 }
5903}
5904
5905
5906/*----------------------------------------------------------------------------*/
5907/*!
5908* @brief This function is to
5909* check unconfigured system properties and generate related message on
5910* scan list to notify users
5911*
5912* @param prAdapter Pointer of Adapter Data Structure
5913*
5914* @return WLAN_STATUS_SUCCESS
5915*/
5916/*----------------------------------------------------------------------------*/
5917WLAN_STATUS
5918wlanCheckSystemConfiguration (
5919 IN P_ADAPTER_T prAdapter
5920 )
5921{
5922#if (CFG_NVRAM_EXISTENCE_CHECK == 1) || (CFG_SW_NVRAM_VERSION_CHECK == 1)
5923 const UINT_8 aucZeroMacAddr[] = NULL_MAC_ADDR;
5924 const UINT_8 aucBCAddr[] = BC_MAC_ADDR;
5925 BOOLEAN fgIsConfExist = TRUE;
5926 BOOLEAN fgGenErrMsg = FALSE;
5927 P_REG_INFO_T prRegInfo = NULL;
5928 P_WLAN_BEACON_FRAME_T prBeacon = NULL;
5929 P_IE_SSID_T prSsid = NULL;
5930 UINT_32 u4ErrCode = 0;
5931 UINT_8 aucErrMsg[32];
5932 PARAM_SSID_T rSsid;
5933 PARAM_802_11_CONFIG_T rConfiguration;
5934 PARAM_RATES_EX rSupportedRates;
5935#endif
5936
5937 DEBUGFUNC("wlanCheckSystemConfiguration");
5938
5939 ASSERT(prAdapter);
5940
5941#if (CFG_NVRAM_EXISTENCE_CHECK == 1)
5942 if(kalIsConfigurationExist(prAdapter->prGlueInfo) == FALSE) {
5943 fgIsConfExist = FALSE;
5944 fgGenErrMsg = TRUE;
5945 }
5946#endif
5947
5948#if (CFG_SW_NVRAM_VERSION_CHECK == 1)
5949 prRegInfo = kalGetConfiguration(prAdapter->prGlueInfo);
5950
5951 if(fgIsConfExist == TRUE &&
5952 (CFG_DRV_OWN_VERSION < prAdapter->rVerInfo.u2Part1CfgPeerVersion
5953 || CFG_DRV_OWN_VERSION < prAdapter->rVerInfo.u2Part2CfgPeerVersion
5954 || prAdapter->rVerInfo.u2Part1CfgOwnVersion < CFG_DRV_PEER_VERSION
5955 || prAdapter->rVerInfo.u2Part2CfgOwnVersion < CFG_DRV_PEER_VERSION /* NVRAM */
5956 || CFG_DRV_OWN_VERSION < prAdapter->rVerInfo.u2FwPeerVersion
5957 || prAdapter->rVerInfo.u2FwOwnVersion < CFG_DRV_PEER_VERSION
5958 || (prAdapter->fgIsEmbbededMacAddrValid == FALSE &&
5959 (IS_BMCAST_MAC_ADDR(prRegInfo->aucMacAddr)
5960 || EQUAL_MAC_ADDR(aucZeroMacAddr, prRegInfo->aucMacAddr)))
5961 || prRegInfo->ucTxPwrValid == 0)) {
5962 fgGenErrMsg = TRUE;
5963 }
5964#endif
5965
5966 if(fgGenErrMsg == TRUE) {
5967 prBeacon = cnmMemAlloc(prAdapter, RAM_TYPE_BUF, sizeof(WLAN_BEACON_FRAME_T) + sizeof(IE_SSID_T));
5968
5969 // initialization
5970 kalMemZero(prBeacon, sizeof(WLAN_BEACON_FRAME_T) + sizeof(IE_SSID_T));
5971
5972 // prBeacon initialization
5973 prBeacon->u2FrameCtrl = MAC_FRAME_BEACON;
5974 COPY_MAC_ADDR(prBeacon->aucDestAddr, aucBCAddr);
5975 COPY_MAC_ADDR(prBeacon->aucSrcAddr, aucZeroMacAddr);
5976 COPY_MAC_ADDR(prBeacon->aucBSSID, aucZeroMacAddr);
5977 prBeacon->u2BeaconInterval = 100;
5978 prBeacon->u2CapInfo = CAP_INFO_ESS;
5979
5980 // prSSID initialization
5981 prSsid = (P_IE_SSID_T)(&prBeacon->aucInfoElem[0]);
5982 prSsid->ucId = ELEM_ID_SSID;
5983
5984 // rConfiguration initialization
5985 rConfiguration.u4Length = sizeof(PARAM_802_11_CONFIG_T);
5986 rConfiguration.u4BeaconPeriod = 100;
5987 rConfiguration.u4ATIMWindow = 1;
5988 rConfiguration.u4DSConfig = 2412;
5989 rConfiguration.rFHConfig.u4Length = sizeof(PARAM_802_11_CONFIG_FH_T);
5990
5991 // rSupportedRates initialization
5992 kalMemZero(rSupportedRates, sizeof(PARAM_RATES_EX));
5993 }
5994
5995#if (CFG_NVRAM_EXISTENCE_CHECK == 1)
5996 #define NVRAM_ERR_MSG "NVRAM WARNING: Err = 0x01"
5997 if(kalIsConfigurationExist(prAdapter->prGlueInfo) == FALSE) {
5998 COPY_SSID(prSsid->aucSSID,
5999 prSsid->ucLength,
6000 NVRAM_ERR_MSG,
6001 strlen(NVRAM_ERR_MSG));
6002
6003 kalIndicateBssInfo(prAdapter->prGlueInfo,
6004 (PUINT_8)prBeacon,
6005 OFFSET_OF(WLAN_BEACON_FRAME_T, aucInfoElem) + OFFSET_OF(IE_SSID_T, aucSSID) + prSsid->ucLength,
6006 1,
6007 0);
6008 COPY_SSID(rSsid.aucSsid, rSsid.u4SsidLen, NVRAM_ERR_MSG, strlen(NVRAM_ERR_MSG));
6009 nicAddScanResult(prAdapter,
6010 prBeacon->aucBSSID,
6011 &rSsid,
6012 0,
6013 0,
6014 PARAM_NETWORK_TYPE_FH,
6015 &rConfiguration,
6016 NET_TYPE_INFRA,
6017 rSupportedRates,
6018 OFFSET_OF(WLAN_BEACON_FRAME_T, aucInfoElem) + OFFSET_OF(IE_SSID_T, aucSSID) + prSsid->ucLength - WLAN_MAC_MGMT_HEADER_LEN,
6019 (PUINT_8)((ULONG)(prBeacon) + WLAN_MAC_MGMT_HEADER_LEN));
6020 }
6021#endif
6022
6023#if (CFG_SW_NVRAM_VERSION_CHECK == 1)
6024 #define VER_ERR_MSG "NVRAM WARNING: Err = 0x%02X"
6025 if(fgIsConfExist == TRUE) {
6026 if((CFG_DRV_OWN_VERSION < prAdapter->rVerInfo.u2Part1CfgPeerVersion
6027 || CFG_DRV_OWN_VERSION < prAdapter->rVerInfo.u2Part2CfgPeerVersion
6028 || prAdapter->rVerInfo.u2Part1CfgOwnVersion < CFG_DRV_PEER_VERSION
6029 || prAdapter->rVerInfo.u2Part2CfgOwnVersion < CFG_DRV_PEER_VERSION /* NVRAM */
6030 || CFG_DRV_OWN_VERSION < prAdapter->rVerInfo.u2FwPeerVersion
6031 || prAdapter->rVerInfo.u2FwOwnVersion < CFG_DRV_PEER_VERSION)) {
6032 u4ErrCode |= NVRAM_ERROR_VERSION_MISMATCH;
6033 }
6034
6035
6036 if(prRegInfo->ucTxPwrValid == 0) {
6037 u4ErrCode |= NVRAM_ERROR_INVALID_TXPWR;
6038 }
6039
6040 if(prAdapter->fgIsEmbbededMacAddrValid == FALSE &&
6041 (IS_BMCAST_MAC_ADDR(prRegInfo->aucMacAddr) || EQUAL_MAC_ADDR(aucZeroMacAddr, prRegInfo->aucMacAddr))) {
6042 u4ErrCode |= NVRAM_ERROR_INVALID_MAC_ADDR;
6043 }
6044
6045 if(u4ErrCode != 0) {
6046 sprintf(aucErrMsg, VER_ERR_MSG, (unsigned int)u4ErrCode);
6047 COPY_SSID(prSsid->aucSSID,
6048 prSsid->ucLength,
6049 aucErrMsg,
6050 strlen(aucErrMsg));
6051
6052 kalIndicateBssInfo(prAdapter->prGlueInfo,
6053 (PUINT_8)prBeacon,
6054 OFFSET_OF(WLAN_BEACON_FRAME_T, aucInfoElem) + OFFSET_OF(IE_SSID_T, aucSSID) + prSsid->ucLength,
6055 1,
6056 0);
6057
6058 COPY_SSID(rSsid.aucSsid, rSsid.u4SsidLen, NVRAM_ERR_MSG, strlen(NVRAM_ERR_MSG));
6059 nicAddScanResult(prAdapter,
6060 prBeacon->aucBSSID,
6061 &rSsid,
6062 0,
6063 0,
6064 PARAM_NETWORK_TYPE_FH,
6065 &rConfiguration,
6066 NET_TYPE_INFRA,
6067 rSupportedRates,
6068 OFFSET_OF(WLAN_BEACON_FRAME_T, aucInfoElem) + OFFSET_OF(IE_SSID_T, aucSSID) + prSsid->ucLength - WLAN_MAC_MGMT_HEADER_LEN,
6069 (PUINT_8)((ULONG)(prBeacon) + WLAN_MAC_MGMT_HEADER_LEN));
6070 }
6071 }
6072#endif
6073
6074 if(fgGenErrMsg == TRUE) {
6075 cnmMemFree(prAdapter, prBeacon);
6076 }
6077
6078 return WLAN_STATUS_SUCCESS;
6079}
6080
6081
6082WLAN_STATUS
6083wlanoidQueryStaStatistics (
6084 IN P_ADAPTER_T prAdapter,
6085 IN PVOID pvQueryBuffer,
6086 IN UINT_32 u4QueryBufferLen,
6087 OUT PUINT_32 pu4QueryInfoLen
6088 )
6089{
6090 WLAN_STATUS rResult = WLAN_STATUS_FAILURE;
6091 P_STA_RECORD_T prStaRec, prTempStaRec;
6092 P_PARAM_GET_STA_STATISTICS prQueryStaStatistics;
6093 UINT_8 ucStaRecIdx;
6094 P_QUE_MGT_T prQM = &prAdapter->rQM;
6095 CMD_GET_STA_STATISTICS_T rQueryCmdStaStatistics;
6096 UINT_8 ucIdx;
6097
6098 do {
6099 ASSERT(pvQueryBuffer);
6100
6101 //4 1. Sanity test
6102 if ((prAdapter == NULL) || (pu4QueryInfoLen == NULL)) {
6103 break;
6104 }
6105
6106 if ((u4QueryBufferLen) && (pvQueryBuffer == NULL)) {
6107 break;
6108 }
6109
6110 if (u4QueryBufferLen < sizeof(PARAM_GET_STA_STA_STATISTICS)) {
6111 *pu4QueryInfoLen = sizeof(PARAM_GET_STA_STA_STATISTICS);
6112 rResult = WLAN_STATUS_BUFFER_TOO_SHORT;
6113 break;
6114 }
6115
6116 prQueryStaStatistics = (P_PARAM_GET_STA_STATISTICS)pvQueryBuffer;
6117 *pu4QueryInfoLen = sizeof(PARAM_GET_STA_STA_STATISTICS);
6118
6119 //4 5. Get driver global QM counter
6120 for(ucIdx = TC0_INDEX; ucIdx <= TC3_INDEX; ucIdx++) {
6121 prQueryStaStatistics->au4TcAverageQueLen[ucIdx] = prQM->au4AverageQueLen[ucIdx];
6122 prQueryStaStatistics->au4TcCurrentQueLen[ucIdx] = prQM->au4CurrentTcResource[ucIdx];
6123 }
6124
6125 //4 2. Get StaRec by MAC address
6126 prStaRec = NULL;
6127
6128 for(ucStaRecIdx = 0; ucStaRecIdx < CFG_NUM_OF_STA_RECORD; ucStaRecIdx++){
6129 prTempStaRec = &(prAdapter->arStaRec[ucStaRecIdx]);
6130 if(prTempStaRec->fgIsValid && prTempStaRec->fgIsInUse){
6131 if(EQUAL_MAC_ADDR(prTempStaRec->aucMacAddr, prQueryStaStatistics->aucMacAddr)){
6132 prStaRec = prTempStaRec;
6133 break;
6134 }
6135 }
6136 }
6137
6138 if(!prStaRec) {
6139 rResult = WLAN_STATUS_INVALID_DATA;
6140 break;
6141 }
6142
6143 prQueryStaStatistics->u4Flag |= BIT(0);
6144
6145 #if CFG_ENABLE_PER_STA_STATISTICS
6146 //4 3. Get driver statistics
6147 prQueryStaStatistics->u4TxTotalCount = prStaRec->u4TotalTxPktsNumber;
6148 prQueryStaStatistics->u4TxExceedThresholdCount = prStaRec->u4ThresholdCounter;
6149 prQueryStaStatistics->u4TxMaxTime = prStaRec->u4MaxTxPktsTime;
6150 if(prStaRec->u4TotalTxPktsNumber) {
6151 prQueryStaStatistics->u4TxAverageProcessTime = (prStaRec->u4TotalTxPktsTime / prStaRec->u4TotalTxPktsNumber);
6152 }
6153 else {
6154 prQueryStaStatistics->u4TxAverageProcessTime = 0;
6155 }
6156
6157 for(ucIdx = TC0_INDEX; ucIdx <= TC3_INDEX; ucIdx++) {
6158 prQueryStaStatistics->au4TcResourceEmptyCount[ucIdx] = prQM->au4QmTcResourceEmptyCounter[prStaRec->ucNetTypeIndex][ucIdx];
6159 /* Reset */
6160 prQM->au4QmTcResourceEmptyCounter[prStaRec->ucNetTypeIndex][ucIdx] = 0;
6161 }
6162
6163 //4 4.1 Reset statistics
6164 prStaRec->u4ThresholdCounter = 0;
6165 prStaRec->u4TotalTxPktsNumber = 0;
6166 prStaRec->u4TotalTxPktsTime = 0;
6167 prStaRec->u4MaxTxPktsTime = 0;
6168 #endif
6169
6170 for(ucIdx = TC0_INDEX; ucIdx <= TC3_INDEX; ucIdx++) {
6171 prQueryStaStatistics->au4TcQueLen[ucIdx] = prStaRec->arTxQueue[ucIdx].u4NumElem;
6172 }
6173
6174 rResult = WLAN_STATUS_SUCCESS;
6175
6176 //4 6. Ensure FW supports get station link status
6177 if(prAdapter->u4FwCompileFlag0 & COMPILE_FLAG0_GET_STA_LINK_STATUS) {
6178
6179 rQueryCmdStaStatistics.ucIndex = prStaRec->ucIndex;
6180 COPY_MAC_ADDR(rQueryCmdStaStatistics.aucMacAddr, prQueryStaStatistics->aucMacAddr);
6181 rQueryCmdStaStatistics.ucReadClear = TRUE;
6182
6183 rResult = wlanSendSetQueryCmd(prAdapter,
6184 CMD_ID_GET_STA_STATISTICS,
6185 FALSE,
6186 TRUE,
6187 TRUE,
6188 nicCmdEventQueryStaStatistics,
6189 nicOidCmdTimeoutCommon,
6190 sizeof(CMD_GET_STA_STATISTICS_T),
6191 (PUINT_8)&rQueryCmdStaStatistics,
6192 pvQueryBuffer,
6193 u4QueryBufferLen
6194 );
6195
6196 prQueryStaStatistics->u4Flag |= BIT(1);
6197 }
6198 else {
6199 rResult = WLAN_STATUS_NOT_SUPPORTED;
6200 }
6201
6202 } while (FALSE);
6203
6204 return rResult;
6205} /* wlanoidQueryP2pVersion */
6206#if CFG_AUTO_CHANNEL_SEL_SUPPORT
6207
6208//4 Auto Channel Selection
6209WLAN_STATUS
6210wlanoidQueryACSChannelList (
6211 IN P_ADAPTER_T prAdapter,
6212 IN PVOID pvQueryBuffer,
6213 IN UINT_32 u4QueryBufferLen,
6214 OUT PUINT_32 pu4QueryInfoLen
6215 )
6216{
6217 WLAN_STATUS rResult = WLAN_STATUS_FAILURE;
6218 P_STA_RECORD_T prStaRec, prTempStaRec;
6219 P_PARAM_GET_CHN_LOAD prQueryChnLoad;
6220 P_PARAM_GET_LTE_MODE prLteMode;
6221 UINT_8 ucStaRecIdx;
6222 P_QUE_MGT_T prQM = &prAdapter->rQM;
6223 CMD_GET_CHN_LOAD_T rQueryCmdStaStatistics;
6224 UINT_8 ucIdx;
6225
6226 P_PARAM_CHN_LOAD_INFO prChnLoad;
6227
6228 DBGLOG(P2P, INFO,("[Auto Channel]wlanoidQueryACSChannelList\n"));
6229 do {
6230 ASSERT(pvQueryBuffer);
6231
6232 //4 1. Sanity test
6233 if ((prAdapter == NULL) || (pu4QueryInfoLen == NULL)) {
6234 break;
6235 }
6236
6237 if ((u4QueryBufferLen) && (pvQueryBuffer == NULL)) {
6238 break;
6239 }
6240
6241 prLteMode = (P_PARAM_GET_LTE_MODE)pvQueryBuffer;
6242 //4 2.Check AP Numbers
6243 for(ucIdx=0;ucIdx<MAX_AUTO_CHAL_NUM;ucIdx++)
6244 {
6245 prChnLoad= (P_PARAM_CHN_LOAD_INFO)&(prAdapter->rWifiVar.rChnLoadInfo.rEachChnLoad[ucIdx]);
6246
6247 DBGLOG(P2P, INFO,("[Auto Channel] AP Num: Chn[%d]=%d\n",ucIdx+1,prChnLoad->u2APNum));
6248 }
6249 //4 3. Ensure FW supports get station link status
6250#if 0
6251 if(prAdapter->u4FwCompileFlag0 & COMPILE_FLAG0_GET_STA_LINK_STATUS) {
6252 printk("wlanoidQueryACSChannelList\n");
6253 CMD_ACCESS_REG rCmdAccessReg;
6254 rCmdAccessReg.u4Address = 0xFFFFFFFF;
6255 rCmdAccessReg.u4Data = ELEM_RM_TYPE_ACS_CHN;
6256
6257 rResult =wlanSendSetQueryCmd(prAdapter,
6258 CMD_ID_ACCESS_REG,
6259 TRUE,
6260 TRUE,
6261 TRUE,
6262 nicCmdEventQueryChannelLoad,//The handler to receive firmware notification
6263 nicOidCmdTimeoutCommon,
6264 sizeof(CMD_ACCESS_REG),
6265 (PUINT_8)&rCmdAccessReg,
6266 pvQueryBuffer,
6267 u4QueryBufferLen
6268 );
6269
6270 prQueryChnLoad->u4Flag |= BIT(1);
6271 }
6272 else {
6273 rResult = WLAN_STATUS_NOT_SUPPORTED;
6274 }
6275#endif
6276 //4 4.Avoid LTE Channels
6277 prLteMode->u4Flags &= BIT(0);
6278 /*if(prAdapter->u4FwCompileFlag0 & COMPILE_FLAG0_GET_STA_LINK_STATUS)*/ {
6279
6280
6281 CMD_GET_LTE_SAFE_CHN_T rQuery_LTE_SAFE_CHN;
6282 rResult =wlanSendSetQueryCmd(prAdapter,
6283 CMD_ID_GET_LTE_CHN,
6284 FALSE,
6285 TRUE,
6286 TRUE,//Query ID
6287 nicCmdEventQueryLTESafeChn,//The handler to receive firmware notification
6288 nicOidCmdTimeoutCommon,
6289 sizeof(CMD_GET_LTE_SAFE_CHN_T),
6290 (PUINT_8)&rQuery_LTE_SAFE_CHN,
6291 pvQueryBuffer,
6292 u4QueryBufferLen
6293 );
6294
6295 DBGLOG(P2P, INFO,("[Auto Channel] Get LTE Channels\n"));
6296 prLteMode->u4Flags |= BIT(1);
6297 }
6298
6299 /*
6300 else {
6301 rResult = WLAN_STATUS_NOT_SUPPORTED;
6302 }
6303 */
6304
6305 //4 5. Calc the value
6306
6307 DBGLOG(P2P, INFO,("[Auto Channel] Candidated Channels\n"));
6308 } while (FALSE);
6309
6310 return rResult;
6311} /* wlanoidQueryP2pVersion */
6312#endif
6313
6314P_WLAN_CFG_ENTRY_T wlanCfgGetEntry(IN P_ADAPTER_T prAdapter, const PCHAR pucKey)
6315{
6316
6317 P_WLAN_CFG_ENTRY_T prWlanCfgEntry;
6318 P_WLAN_CFG_T prWlanCfg;
6319 UINT_32 i;
6320 prWlanCfg = prAdapter->prWlanCfg;
6321
6322 ASSERT(prWlanCfg);
6323 ASSERT(pucKey);
6324
6325 prWlanCfgEntry = NULL;
6326
6327 for (i = 0; i < WLAN_CFG_ENTRY_NUM_MAX; i++) {
6328 prWlanCfgEntry = &prWlanCfg->arWlanCfgBuf[i];
6329 if (prWlanCfgEntry->aucKey[0] != '\0') {
6330 DBGLOG(INIT, LOUD,
6331 ("compare key %s saved key %s\n", pucKey, prWlanCfgEntry->aucKey));
6332 if (kalStrniCmp(pucKey, prWlanCfgEntry->aucKey, WLAN_CFG_KEY_LEN_MAX - 1) ==
6333 0) {
6334 return prWlanCfgEntry;
6335 }
6336 }
6337 }
6338
6339 DBGLOG(INIT, TRACE, ("wifi config there is no entry \'%s\'\n", pucKey));
6340 return NULL;
6341
6342}
6343
6344WLAN_STATUS
6345wlanCfgGet(IN P_ADAPTER_T prAdapter,
6346 const PCHAR pucKey, PCHAR pucValue, PCHAR pucValueDef, UINT_32 u4Flags)
6347{
6348
6349 P_WLAN_CFG_ENTRY_T prWlanCfgEntry;
6350 P_WLAN_CFG_T prWlanCfg;
6351 prWlanCfg = prAdapter->prWlanCfg;
6352
6353 ASSERT(prWlanCfg);
6354 ASSERT(pucValue);
6355
6356 /* Find the exist */
6357 prWlanCfgEntry = wlanCfgGetEntry(prAdapter, pucKey);
6358
6359 if (prWlanCfgEntry) {
6360 kalStrnCpy(pucValue, prWlanCfgEntry->aucValue, WLAN_CFG_VALUE_LEN_MAX - 1);
6361 return WLAN_STATUS_SUCCESS;
6362 } else {
6363 if (pucValueDef)
6364 kalStrnCpy(pucValue, pucValueDef, WLAN_CFG_VALUE_LEN_MAX - 1);
6365 return WLAN_STATUS_FAILURE;
6366 }
6367
6368}
6369
6370UINT_32 wlanCfgGetUint32(IN P_ADAPTER_T prAdapter, const PCHAR pucKey, UINT_32 u4ValueDef)
6371{
6372 P_WLAN_CFG_ENTRY_T prWlanCfgEntry;
6373 P_WLAN_CFG_T prWlanCfg;
6374 UINT_32 u4Ret;
6375 prWlanCfg = prAdapter->prWlanCfg;
6376
6377 ASSERT(prWlanCfg);
6378
6379 u4Ret = u4ValueDef;
6380 /* Find the exist */
6381 prWlanCfgEntry = wlanCfgGetEntry(prAdapter, pucKey);
6382
6383 if (prWlanCfgEntry) {
6384 u4Ret = kalStrtoul(prWlanCfgEntry->aucValue, NULL, 0);
6385 }
6386 return u4Ret;
6387}
6388
6389INT_32 wlanCfgGetInt32(IN P_ADAPTER_T prAdapter, const PCHAR pucKey, INT_32 i4ValueDef)
6390{
6391 P_WLAN_CFG_ENTRY_T prWlanCfgEntry;
6392 P_WLAN_CFG_T prWlanCfg;
6393 INT_32 i4Ret;
6394 prWlanCfg = prAdapter->prWlanCfg;
6395
6396 ASSERT(prWlanCfg);
6397
6398 i4Ret = i4ValueDef;
6399 /* Find the exist */
6400 prWlanCfgEntry = wlanCfgGetEntry(prAdapter, pucKey);
6401
6402 if (prWlanCfgEntry) {
6403 i4Ret = kalStrtol(prWlanCfgEntry->aucValue, NULL, 0);
6404 }
6405 return i4Ret;
6406}
6407
6408
6409
6410WLAN_STATUS
6411wlanCfgSet(IN P_ADAPTER_T prAdapter, const PCHAR pucKey, PCHAR pucValue, UINT_32 u4Flags)
6412{
6413
6414 P_WLAN_CFG_ENTRY_T prWlanCfgEntry;
6415 P_WLAN_CFG_T prWlanCfg;
6416 UINT_32 u4EntryIndex;
6417 UINT_32 i;
6418 UINT_8 ucExist;
6419
6420 prWlanCfg = prAdapter->prWlanCfg;
6421 ASSERT(prWlanCfg);
6422 ASSERT(pucKey);
6423
6424 /* Find the exist */
6425 ucExist = 0;
6426 prWlanCfgEntry = wlanCfgGetEntry(prAdapter, pucKey);
6427
6428 if (!prWlanCfgEntry) {
6429 /* Find the empty */
6430 for (i = 0; i < WLAN_CFG_ENTRY_NUM_MAX; i++) {
6431 prWlanCfgEntry = &prWlanCfg->arWlanCfgBuf[i];
6432 if (prWlanCfgEntry->aucKey[0] == '\0') {
6433 break;
6434 }
6435 }
6436
6437 u4EntryIndex = i;
6438 if (u4EntryIndex < WLAN_CFG_ENTRY_NUM_MAX) {
6439 prWlanCfgEntry = &prWlanCfg->arWlanCfgBuf[u4EntryIndex];
6440 kalMemZero(prWlanCfgEntry, sizeof(WLAN_CFG_ENTRY_T));
6441 } else {
6442 prWlanCfgEntry = NULL;
6443 DBGLOG(INIT, ERROR, ("wifi config there is no empty entry\n"));
6444 }
6445 } /* !prWlanCfgEntry */
6446 else {
6447 ucExist = 1;
6448 }
6449
6450 if (prWlanCfgEntry) {
6451 if (ucExist == 0) {
6452 kalStrnCpy(prWlanCfgEntry->aucKey, pucKey, WLAN_CFG_KEY_LEN_MAX - 1);
6453 prWlanCfgEntry->aucKey[WLAN_CFG_KEY_LEN_MAX - 1] = '\0';
6454 }
6455
6456 if (pucValue && pucValue[0] != '\0') {
6457 kalStrnCpy(prWlanCfgEntry->aucValue, pucValue, WLAN_CFG_VALUE_LEN_MAX - 1);
6458 prWlanCfgEntry->aucValue[WLAN_CFG_VALUE_LEN_MAX - 1] = '\0';
6459
6460 if (ucExist) {
6461 if (prWlanCfgEntry->pfSetCb)
6462 prWlanCfgEntry->pfSetCb(prAdapter,
6463 prWlanCfgEntry->aucKey,
6464 prWlanCfgEntry->aucValue,
6465 prWlanCfgEntry->pPrivate, 0);
6466 }
6467 } else {
6468 /* Call the pfSetCb if value is empty ? */
6469 /* remove the entry if value is empty */
6470 kalMemZero(prWlanCfgEntry, sizeof(WLAN_CFG_ENTRY_T));
6471 }
6472
6473 }
6474 /* prWlanCfgEntry */
6475 if (prWlanCfgEntry) {
6476 DBGLOG(INIT, INFO, ("Set wifi config exist %u \'%s\' \'%s\'\n",
6477 ucExist, prWlanCfgEntry->aucKey, prWlanCfgEntry->aucValue));
6478 return WLAN_STATUS_SUCCESS;
6479 } else {
6480 if (pucKey) {
6481 DBGLOG(INIT, ERROR, ("Set wifi config error key \'%s\'\n", pucKey));
6482 }
6483 if (pucValue) {
6484 DBGLOG(INIT, ERROR, ("Set wifi config error value \'%s\'\n", pucValue));
6485 }
6486 return WLAN_STATUS_FAILURE;
6487 }
6488
6489}
6490
6491WLAN_STATUS
6492wlanCfgSetCb(IN P_ADAPTER_T prAdapter,
6493 const PCHAR pucKey, WLAN_CFG_SET_CB pfSetCb, void *pPrivate, UINT_32 u4Flags)
6494{
6495
6496 P_WLAN_CFG_ENTRY_T prWlanCfgEntry;
6497 P_WLAN_CFG_T prWlanCfg;
6498
6499 prWlanCfg = prAdapter->prWlanCfg;
6500 ASSERT(prWlanCfg);
6501
6502 /* Find the exist */
6503 prWlanCfgEntry = wlanCfgGetEntry(prAdapter, pucKey);
6504
6505 if (prWlanCfgEntry) {
6506 prWlanCfgEntry->pfSetCb = pfSetCb;
6507 prWlanCfgEntry->pPrivate = pPrivate;
6508 }
6509
6510 if (prWlanCfgEntry) {
6511 return WLAN_STATUS_SUCCESS;
6512 } else {
6513 return WLAN_STATUS_FAILURE;
6514 }
6515
6516}
6517
6518WLAN_STATUS wlanCfgSetUint32(IN P_ADAPTER_T prAdapter, const PCHAR pucKey, UINT_32 u4Value)
6519{
6520
6521 P_WLAN_CFG_T prWlanCfg;
6522 UINT_8 aucBuf[WLAN_CFG_VALUE_LEN_MAX];
6523
6524 prWlanCfg = prAdapter->prWlanCfg;
6525
6526 ASSERT(prWlanCfg);
6527
6528 kalMemZero(aucBuf, sizeof(aucBuf));
6529
6530 kalSnprintf(aucBuf, WLAN_CFG_VALUE_LEN_MAX, "0x%x", (unsigned int)u4Value);
6531
6532 return wlanCfgSet(prAdapter, pucKey, aucBuf, 0);
6533}
6534
6535
6536enum {
6537 STATE_EOF = 0,
6538 STATE_TEXT = 1,
6539 STATE_NEWLINE = 2
6540};
6541
6542struct WLAN_CFG_PARSE_STATE_S {
6543 CHAR *ptr;
6544 CHAR *text;
6545 INT_32 nexttoken;
6546 UINT_32 maxSize;
6547};
6548
6549INT_32 wlanCfgFindNextToken(struct WLAN_CFG_PARSE_STATE_S *state)
6550{
6551 CHAR *x = state->ptr;
6552 CHAR *s;
6553
6554 if (state->nexttoken) {
6555 INT_32 t = state->nexttoken;
6556 state->nexttoken = 0;
6557 return t;
6558 }
6559
6560 for (;;) {
6561 switch (*x) {
6562 case 0:
6563 state->ptr = x;
6564 return STATE_EOF;
6565 case '\n':
6566 x++;
6567 state->ptr = x;
6568 return STATE_NEWLINE;
6569 case ' ':
6570 case '\t':
6571 case '\r':
6572 x++;
6573 continue;
6574 case '#':
6575 while (*x && (*x != '\n'))
6576 x++;
6577 if (*x == '\n') {
6578 state->ptr = x + 1;
6579 return STATE_NEWLINE;
6580 } else {
6581 state->ptr = x;
6582 return STATE_EOF;
6583 }
6584 default:
6585 goto text;
6586 }
6587 }
6588
6589textdone:
6590 state->ptr = x;
6591 *s = 0;
6592 return STATE_TEXT;
6593text:
6594 state->text = s = x;
6595textresume:
6596 for (;;) {
6597 switch (*x) {
6598 case 0:
6599 goto textdone;
6600 case ' ':
6601 case '\t':
6602 case '\r':
6603 x++;
6604 goto textdone;
6605 case '\n':
6606 state->nexttoken = STATE_NEWLINE;
6607 x++;
6608 goto textdone;
6609 case '"':
6610 x++;
6611 for (;;) {
6612 switch (*x) {
6613 case 0:
6614 /* unterminated quoted thing */
6615 state->ptr = x;
6616 return STATE_EOF;
6617 case '"':
6618 x++;
6619 goto textresume;
6620 default:
6621 *s++ = *x++;
6622 }
6623 }
6624 break;
6625 case '\\':
6626 x++;
6627 switch (*x) {
6628 case 0:
6629 goto textdone;
6630 case 'n':
6631 *s++ = '\n';
6632 break;
6633 case 'r':
6634 *s++ = '\r';
6635 break;
6636 case 't':
6637 *s++ = '\t';
6638 break;
6639 case '\\':
6640 *s++ = '\\';
6641 break;
6642 case '\r':
6643 /* \ <cr> <lf> -> line continuation */
6644 if (x[1] != '\n') {
6645 x++;
6646 continue;
6647 }
6648 case '\n':
6649 /* \ <lf> -> line continuation */
6650 x++;
6651 /* eat any extra whitespace */
6652 while ((*x == ' ') || (*x == '\t'))
6653 x++;
6654 continue;
6655 default:
6656 /* unknown escape -- just copy */
6657 *s++ = *x++;
6658 }
6659 continue;
6660 default:
6661 *s++ = *x++;
6662 }
6663 }
6664 return STATE_EOF;
6665}
6666
6667WLAN_STATUS wlanCfgParseArgument(CHAR *cmdLine, INT_32 *argc, CHAR *argv[]
6668 )
6669{
6670 struct WLAN_CFG_PARSE_STATE_S state;
6671 CHAR **args;
6672 INT_32 nargs;
6673
6674 if (cmdLine == NULL || argc == NULL || argv == NULL) {
6675 ASSERT(0);
6676 return WLAN_STATUS_FAILURE;
6677 }
6678 args = argv;
6679 nargs = 0;
6680 state.ptr = cmdLine;
6681 state.nexttoken = 0;
6682 state.maxSize = 0;
6683
6684 if (kalStrnLen(cmdLine, 512) >= 512) {
6685 ASSERT(0);
6686 return WLAN_STATUS_FAILURE;
6687 }
6688
6689 for (;;) {
6690 switch (wlanCfgFindNextToken(&state)) {
6691 case STATE_EOF:
6692 goto exit;
6693 case STATE_NEWLINE:
6694 goto exit;
6695 case STATE_TEXT:
6696 if (nargs < WLAN_CFG_ARGV_MAX) {
6697 args[nargs++] = state.text;
6698 }
6699 break;
6700 }
6701 }
6702
6703exit:
6704 *argc = nargs;
6705 return WLAN_STATUS_SUCCESS;
6706}
6707
6708
6709
6710WLAN_STATUS
6711wlanCfgParseAddEntry(IN P_ADAPTER_T prAdapter,
6712 PUINT_8 pucKeyHead,
6713 PUINT_8 pucKeyTail, PUINT_8 pucValueHead, PUINT_8 pucValueTail)
6714{
6715
6716 UINT_8 aucKey[WLAN_CFG_KEY_LEN_MAX];
6717 UINT_8 aucValue[WLAN_CFG_VALUE_LEN_MAX];
6718 UINT_32 u4Len;
6719
6720 kalMemZero(aucKey, sizeof(aucKey));
6721 kalMemZero(aucValue, sizeof(aucValue));
6722
6723 if ((pucKeyHead == NULL)
6724 || (pucValueHead == NULL)
6725 ) {
6726 return WLAN_STATUS_FAILURE;
6727 }
6728
6729 if (pucKeyTail) {
6730 if (pucKeyHead > pucKeyTail)
6731 return WLAN_STATUS_FAILURE;
6732 u4Len = pucKeyTail - pucKeyHead + 1;
6733 } else {
6734 u4Len = kalStrnLen(pucKeyHead, WLAN_CFG_KEY_LEN_MAX - 1);
6735 }
6736
6737 if (u4Len >= WLAN_CFG_KEY_LEN_MAX) {
6738 u4Len = WLAN_CFG_KEY_LEN_MAX - 1;
6739 }
6740 kalStrnCpy(aucKey, pucKeyHead, u4Len);
6741
6742 if (pucValueTail) {
6743 if (pucValueHead > pucValueTail)
6744 return WLAN_STATUS_FAILURE;
6745 u4Len = pucValueTail - pucValueHead + 1;
6746 } else {
6747 u4Len = kalStrnLen(pucValueHead, WLAN_CFG_VALUE_LEN_MAX - 1);
6748 }
6749
6750 if (u4Len >= WLAN_CFG_VALUE_LEN_MAX) {
6751 u4Len = WLAN_CFG_VALUE_LEN_MAX - 1;
6752 }
6753 kalStrnCpy(aucValue, pucValueHead, u4Len);
6754
6755 return wlanCfgSet(prAdapter, aucKey, aucValue, 0);
6756}
6757
6758enum {
6759 WAIT_KEY_HEAD = 0,
6760 WAIT_KEY_TAIL,
6761 WAIT_VALUE_HEAD,
6762 WAIT_VALUE_TAIL,
6763 WAIT_COMMENT_TAIL
6764};
6765
6766
6767WLAN_STATUS wlanCfgParse(IN P_ADAPTER_T prAdapter, PUINT_8 pucConfigBuf, UINT_32 u4ConfigBufLen)
6768{
6769
6770 struct WLAN_CFG_PARSE_STATE_S state;
6771 PCHAR apcArgv[WLAN_CFG_ARGV_MAX];
6772 CHAR **args;
6773 INT_32 nargs;
6774
6775
6776 if (pucConfigBuf == NULL) {
6777 ASSERT(0);
6778 return WLAN_STATUS_FAILURE;
6779 }
6780 if (kalStrnLen(pucConfigBuf, 4000) >= 4000) {
6781 ASSERT(0);
6782 return WLAN_STATUS_FAILURE;
6783 }
6784 if (u4ConfigBufLen == 0) {
6785 return WLAN_STATUS_FAILURE;
6786 }
6787 args = apcArgv;
6788 nargs = 0;
6789 state.ptr = pucConfigBuf;
6790 state.nexttoken = 0;
6791 state.maxSize = u4ConfigBufLen;
6792
6793 for (;;) {
6794 switch (wlanCfgFindNextToken(&state)) {
6795 case STATE_EOF:
6796 if (nargs > 1) {
6797 wlanCfgParseAddEntry(prAdapter, args[0], NULL, args[1], NULL);
6798 }
6799 goto exit;
6800 case STATE_NEWLINE:
6801 if (nargs > 1) {
6802 wlanCfgParseAddEntry(prAdapter, args[0], NULL, args[1], NULL);
6803 }
6804 nargs = 0;
6805 break;
6806 case STATE_TEXT:
6807 if (nargs < WLAN_CFG_ARGV_MAX) {
6808 args[nargs++] = state.text;
6809 }
6810 break;
6811 }
6812 }
6813
6814exit:
6815 return WLAN_STATUS_SUCCESS;
6816
6817#if 0
6818 /* Old version */
6819 UINT_32 i;
6820 UINT_8 c;
6821 PUINT_8 pbuf;
6822 UINT_8 ucState;
6823 PUINT_8 pucKeyTail = NULL;
6824 PUINT_8 pucKeyHead = NULL;
6825 PUINT_8 pucValueHead = NULL;
6826 PUINT_8 pucValueTail = NULL;
6827
6828 ucState = WAIT_KEY_HEAD;
6829 pbuf = pucConfigBuf;
6830
6831 for (i = 0; i < u4ConfigBufLen; i++) {
6832 c = pbuf[i];
6833 if (c == '\r' || c == '\n') {
6834
6835 if (ucState == WAIT_VALUE_TAIL) {
6836 /* Entry found */
6837 if (pucValueHead) {
6838 wlanCfgParseAddEntry(prAdapter, pucKeyHead, pucKeyTail,
6839 pucValueHead, pucValueTail);
6840 }
6841 }
6842 ucState = WAIT_KEY_HEAD;
6843 pucKeyTail = NULL;
6844 pucKeyHead = NULL;
6845 pucValueHead = NULL;
6846 pucValueTail = NULL;
6847
6848 } else if (c == '=') {
6849 if (ucState == WAIT_KEY_TAIL) {
6850 pucKeyTail = &pbuf[i - 1];
6851 ucState = WAIT_VALUE_HEAD;
6852 }
6853 } else if (c == ' ' || c == '\t') {
6854 if (ucState == WAIT_KEY_HEAD) {
6855
6856
6857 } else if (ucState == WAIT_KEY_TAIL) {
6858 pucKeyTail = &pbuf[i - 1];
6859 ucState = WAIT_VALUE_HEAD;
6860 }
6861 } else {
6862
6863 if (c == '#') {
6864 /* comments */
6865 if (ucState == WAIT_KEY_HEAD) {
6866 ucState = WAIT_COMMENT_TAIL;
6867 } else if (ucState == WAIT_VALUE_TAIL) {
6868 pucValueTail = &pbuf[i];
6869 }
6870
6871 } else {
6872 if (ucState == WAIT_KEY_HEAD) {
6873 pucKeyHead = &pbuf[i];
6874 pucKeyTail = &pbuf[i];
6875 ucState = WAIT_KEY_TAIL;
6876 } else if (ucState == WAIT_VALUE_HEAD) {
6877 pucValueHead = &pbuf[i];
6878 pucValueTail = &pbuf[i];
6879 ucState = WAIT_VALUE_TAIL;
6880 } else if (ucState == WAIT_VALUE_TAIL) {
6881 pucValueTail = &pbuf[i];
6882 }
6883 }
6884 }
6885
6886 } /* for */
6887
6888 if (ucState == WAIT_VALUE_TAIL) {
6889 /* Entry found */
6890 if (pucValueTail) {
6891 wlanCfgParseAddEntry(prAdapter, pucKeyHead, pucKeyTail, pucValueHead,
6892 pucValueTail);
6893 }
6894 }
6895#endif
6896
6897 return WLAN_STATUS_SUCCESS;
6898}
6899#if CFG_SUPPORT_CFG_FILE
6900WLAN_STATUS
6901wlanCfgInit(
6902 IN P_ADAPTER_T prAdapter,
6903 PUINT_8 pucConfigBuf,
6904 UINT_32 u4ConfigBufLen,
6905 UINT_32 u4Flags
6906 )
6907{
6908 P_WLAN_CFG_T prWlanCfg;
6909 //P_WLAN_CFG_ENTRY_T prWlanCfgEntry;
6910 prAdapter->prWlanCfg = &prAdapter->rWlanCfg;
6911 prWlanCfg = prAdapter->prWlanCfg;
6912
6913 kalMemZero(prWlanCfg, sizeof(WLAN_CFG_T));
6914 ASSERT(prWlanCfg);
6915 prWlanCfg->u4WlanCfgEntryNumMax = WLAN_CFG_ENTRY_NUM_MAX;
6916 prWlanCfg->u4WlanCfgKeyLenMax = WLAN_CFG_KEY_LEN_MAX;
6917 prWlanCfg->u4WlanCfgValueLenMax = WLAN_CFG_VALUE_LEN_MAX;
6918#if 0
6919 DBGLOG(INIT, INFO, ("Init wifi config len %u max entry %u\n",
6920 u4ConfigBufLen, prWlanCfg->u4WlanCfgEntryNumMax));
6921#endif
6922 /* self test */
6923 wlanCfgSet(prAdapter, "ConfigValid","0x123", 0);
6924 if(wlanCfgGetUint32(prAdapter,"ConfigValid",0) != 0x123) {
6925 DBGLOG(INIT, INFO, ("wifi config error %u\n",__LINE__));
6926 }
6927 wlanCfgSet(prAdapter, "ConfigValid","1", 0);
6928 if(wlanCfgGetUint32(prAdapter,"ConfigValid",0) != 1) {
6929 DBGLOG(INIT, INFO, ("wifi config error %u\n",__LINE__));
6930 }
6931#if 0 /* soc chip didn't support these parameters now */
6932 /* Add initil config */
6933 /* use g,wlan,p2p,ap as prefix */
6934 /* Don't set cb here , overwrite by another api */
6935 wlanCfgSet(prAdapter, "TxLdpc","1", 0);
6936 wlanCfgSet(prAdapter, "RxLdpc","1", 0);
6937 wlanCfgSet(prAdapter, "RxBeamformee","1",0);
6938 wlanCfgSet(prAdapter, "RoamTh1","100",0);
6939 wlanCfgSet(prAdapter, "RoamTh2","150",0);
6940 wlanCfgSet(prAdapter, "wlanRxLdpc","1", 0);
6941 wlanCfgSet(prAdapter, "apRxLdpc","1", 0);
6942 wlanCfgSet(prAdapter, "p2pRxLdpc","1", 0);
6943#endif
6944 /* Parse the pucConfigBuff */
6945
6946 if(pucConfigBuf && (u4ConfigBufLen>0)) {
6947 wlanCfgParse(prAdapter, pucConfigBuf,u4ConfigBufLen);
6948 }
6949
6950
6951 return WLAN_STATUS_SUCCESS;
6952}
6953/*----------------------------------------------------------------------------*/
6954/*!
6955* @brief This function is to initialize WLAN feature options
6956*
6957* @param prAdapter Pointer of ADAPTER_T
6958*
6959* @return none
6960*/
6961/*----------------------------------------------------------------------------*/
6962VOID
6963wlanCfgApply(
6964 IN P_ADAPTER_T prAdapter
6965 )
6966{
6967#define STR2BYTE(s) (((((PUINT_8)s)[0]-'0')*10)+(((PUINT_8)s)[1]-'0'))
6968 CHAR aucValue[WLAN_CFG_VALUE_LEN_MAX];
6969 INT_32 i4Cfg = 0;
6970 UINT_8 i = 0;
6971 P_WIFI_VAR_T prWifiVar = &prAdapter->rWifiVar;
6972 P_REG_INFO_T prRegInfo = &prAdapter->prGlueInfo->rRegInfo;
6973 P_TX_PWR_PARAM_T prTxPwr = &prRegInfo->rTxPwr;
6974 printk(KERN_ERR "CFG_FILE: Apply Config File\n");
6975 /* Apply COUNTRY Config */
6976 if(wlanCfgGet(prAdapter, "country", aucValue, "",0) == WLAN_STATUS_SUCCESS) {
6977 printk(KERN_ERR "CFG_FILE: Found Country Key, Vaule=%s\n", aucValue);
6978 prAdapter->rWifiVar.rConnSettings.u2CountryCode =
6979 (((UINT_16) aucValue[0]) << 8) | ((UINT_16) aucValue[1]) ;
6980 }
6981 prWifiVar->ucApWpsMode = (UINT_8)wlanCfgGetUint32(prAdapter,"ApWpsMode", 0);
6982 printk(KERN_ERR "CFG_FILE: ucApWpsMode = %u\n", prWifiVar->ucApWpsMode);
6983
6984 if (wlanCfgGet(prAdapter, "5G_support", aucValue, "", 0) == WLAN_STATUS_SUCCESS) {
6985 prRegInfo->ucSupport5GBand = (*aucValue == 'y') ? 1:0;
6986 }
6987 if (wlanCfgGet(prAdapter, "TxPower2G4CCK", aucValue, "", 0) == WLAN_STATUS_SUCCESS &&
6988 kalStrLen(aucValue) == 2) {
6989 prTxPwr->cTxPwr2G4Cck = STR2BYTE(aucValue);
6990 printk("2.4G cck=%d\n", prTxPwr->cTxPwr2G4Cck);
6991 }
6992 if (wlanCfgGet(prAdapter, "TxPower2G4OFDM", aucValue, "", 0) == WLAN_STATUS_SUCCESS &&
6993 kalStrLen(aucValue) == 10) {
6994 prTxPwr->cTxPwr2G4OFDM_BPSK = STR2BYTE(aucValue);
6995 prTxPwr->cTxPwr2G4OFDM_QPSK = STR2BYTE(aucValue+2);
6996 prTxPwr->cTxPwr2G4OFDM_16QAM = STR2BYTE(aucValue+4);
6997 prTxPwr->cTxPwr2G4OFDM_48Mbps = STR2BYTE(aucValue+6);
6998 prTxPwr->cTxPwr2G4OFDM_54Mbps = STR2BYTE(aucValue+8);
6999 printk("2.4G OFDM=%d,%d,%d,%d,%d\n", prTxPwr->cTxPwr2G4OFDM_BPSK, prTxPwr->cTxPwr2G4OFDM_QPSK,
7000 prTxPwr->cTxPwr2G4OFDM_16QAM,prTxPwr->cTxPwr2G4OFDM_48Mbps,prTxPwr->cTxPwr2G4OFDM_54Mbps);
7001 }
7002 if (wlanCfgGet(prAdapter, "TxPower2G4HT20", aucValue, "", 0) == WLAN_STATUS_SUCCESS &&
7003 kalStrLen(aucValue) == 12) {
7004 prTxPwr->cTxPwr2G4HT20_BPSK = STR2BYTE(aucValue);
7005 prTxPwr->cTxPwr2G4HT20_QPSK = STR2BYTE(aucValue+2);
7006 prTxPwr->cTxPwr2G4HT20_16QAM = STR2BYTE(aucValue+4);
7007 prTxPwr->cTxPwr2G4HT20_MCS5 = STR2BYTE(aucValue+6);
7008 prTxPwr->cTxPwr2G4HT20_MCS6 = STR2BYTE(aucValue+8);
7009 prTxPwr->cTxPwr2G4HT20_MCS7 = STR2BYTE(aucValue+10);
7010 printk("2.4G HT20=%d,%d,%d,%d,%d,%d\n", prTxPwr->cTxPwr2G4HT20_BPSK, prTxPwr->cTxPwr2G4HT20_QPSK,
7011 prTxPwr->cTxPwr2G4HT20_16QAM, prTxPwr->cTxPwr2G4HT20_MCS5, prTxPwr->cTxPwr2G4HT20_MCS6,
7012 prTxPwr->cTxPwr2G4HT20_MCS7);
7013 }
7014 if (wlanCfgGet(prAdapter, "TxPower2G4HT40", aucValue, "", 0) == WLAN_STATUS_SUCCESS &&
7015 kalStrLen(aucValue) == 12) {
7016 prTxPwr->cTxPwr2G4HT40_BPSK = STR2BYTE(aucValue);
7017 prTxPwr->cTxPwr2G4HT40_QPSK = STR2BYTE(aucValue+2);
7018 prTxPwr->cTxPwr2G4HT40_16QAM = STR2BYTE(aucValue+4);
7019 prTxPwr->cTxPwr2G4HT40_MCS5 = STR2BYTE(aucValue+6);
7020 prTxPwr->cTxPwr2G4HT40_MCS6 = STR2BYTE(aucValue+8);
7021 prTxPwr->cTxPwr2G4HT40_MCS7 = STR2BYTE(aucValue+10);
7022 printk("2.4G HT40=%d,%d,%d,%d,%d,%d\n", prTxPwr->cTxPwr2G4HT40_BPSK, prTxPwr->cTxPwr2G4HT40_QPSK,
7023 prTxPwr->cTxPwr2G4HT40_16QAM, prTxPwr->cTxPwr2G4HT40_MCS5, prTxPwr->cTxPwr2G4HT40_MCS6,
7024 prTxPwr->cTxPwr2G4HT40_MCS7);
7025 }
7026 if (wlanCfgGet(prAdapter, "TxPower5GOFDM", aucValue, "", 0) == WLAN_STATUS_SUCCESS &&
7027 kalStrLen(aucValue) == 10) {
7028 prTxPwr->cTxPwr5GOFDM_BPSK = STR2BYTE(aucValue);
7029 prTxPwr->cTxPwr5GOFDM_QPSK = STR2BYTE(aucValue+2);
7030 prTxPwr->cTxPwr5GOFDM_16QAM = STR2BYTE(aucValue+4);
7031 prTxPwr->cTxPwr5GOFDM_48Mbps = STR2BYTE(aucValue+6);
7032 prTxPwr->cTxPwr5GOFDM_54Mbps = STR2BYTE(aucValue+8);
7033 printk("5G OFDM=%d,%d,%d,%d,%d\n", prTxPwr->cTxPwr5GOFDM_BPSK, prTxPwr->cTxPwr5GOFDM_QPSK,
7034 prTxPwr->cTxPwr5GOFDM_16QAM,prTxPwr->cTxPwr5GOFDM_48Mbps,prTxPwr->cTxPwr5GOFDM_54Mbps);
7035 }
7036 if (wlanCfgGet(prAdapter, "TxPower5GHT20", aucValue, "", 0) == WLAN_STATUS_SUCCESS &&
7037 kalStrLen(aucValue) == 12) {
7038 prTxPwr->cTxPwr5GHT20_BPSK = STR2BYTE(aucValue);
7039 prTxPwr->cTxPwr5GHT20_QPSK = STR2BYTE(aucValue+2);
7040 prTxPwr->cTxPwr5GHT20_16QAM = STR2BYTE(aucValue+4);
7041 prTxPwr->cTxPwr5GHT20_MCS5 = STR2BYTE(aucValue+6);
7042 prTxPwr->cTxPwr5GHT20_MCS6 = STR2BYTE(aucValue+8);
7043 prTxPwr->cTxPwr5GHT20_MCS7 = STR2BYTE(aucValue+10);
7044 printk("5G HT20=%d,%d,%d,%d,%d,%d\n", prTxPwr->cTxPwr5GHT20_BPSK, prTxPwr->cTxPwr5GHT20_QPSK,
7045 prTxPwr->cTxPwr5GHT20_16QAM, prTxPwr->cTxPwr5GHT20_MCS5, prTxPwr->cTxPwr5GHT20_MCS6,
7046 prTxPwr->cTxPwr5GHT20_MCS7);
7047 }
7048 if (wlanCfgGet(prAdapter, "TxPower5GHT40", aucValue, "", 0) == WLAN_STATUS_SUCCESS &&
7049 kalStrLen(aucValue) == 12) {
7050 prTxPwr->cTxPwr5GHT40_BPSK = STR2BYTE(aucValue);
7051 prTxPwr->cTxPwr5GHT40_QPSK = STR2BYTE(aucValue+2);
7052 prTxPwr->cTxPwr5GHT40_16QAM = STR2BYTE(aucValue+4);
7053 prTxPwr->cTxPwr5GHT40_MCS5 = STR2BYTE(aucValue+6);
7054 prTxPwr->cTxPwr5GHT40_MCS6 = STR2BYTE(aucValue+8);
7055 prTxPwr->cTxPwr5GHT40_MCS7 = STR2BYTE(aucValue+10);
7056 printk("5G HT40=%d,%d,%d,%d,%d,%d\n", prTxPwr->cTxPwr5GHT40_BPSK, prTxPwr->cTxPwr5GHT40_QPSK,
7057 prTxPwr->cTxPwr5GHT40_16QAM, prTxPwr->cTxPwr5GHT40_MCS5, prTxPwr->cTxPwr5GHT40_MCS6,
7058 prTxPwr->cTxPwr5GHT40_MCS7);
7059 }
7060 /* TODO: Apply other Config */
7061}
7062#endif /* CFG_SUPPORT_CFG_FILE */