Merge tag 'lsk-v3.10-android-14.11'
[firefly-linux-kernel-4.4.55.git] / drivers / mtk_wcn_combo / drv_wlan / mt6620 / wlan / common / wlan_lib.c
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 */
957 const 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
969 extern QUE_MGT_T g_rQM;
970 #endif
971 /*******************************************************************************
972 *                             D A T A   T Y P E S
973 ********************************************************************************
974 */
975 typedef struct _CODE_MAPPING_T {
976     UINT_32         u4RegisterValue;
977     INT_32         u4TxpowerOffset;
978 } CODE_MAPPING_T, *P_CODE_MAPPING_T;
979
980 /*******************************************************************************
981 *                            P U B L I C   D A T A
982 ********************************************************************************
983 */
984 BOOLEAN 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 */
1002 PFN_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 */
1011 PFN_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 */
1030 PFN_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 */
1039 PFN_OID_HANDLER_FUNC apfnOidQueryHandlerAllowedInRFTest[] = {
1040     wlanoidRftestQueryAutoTest,
1041     wlanoidQueryMcrRead,
1042     wlanoidQueryEepromRead
1043 }
1044 ;
1045
1046 PFN_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 /*----------------------------------------------------------------------------*/
1068 /*!
1069 * \brief This is a private routine, which is used to check if HW access is needed
1070 *        for the OID query/ set handlers.
1071 *
1072 * \param[IN] pfnOidHandler Pointer to the OID handler.
1073 * \param[IN] fgSetInfo     It is a Set information handler.
1074 *
1075 * \retval TRUE This function needs HW access
1076 * \retval FALSE This function does not need HW access
1077 */
1078 /*----------------------------------------------------------------------------*/
1079 BOOLEAN
1080 wlanIsHandlerNeedHwAccess (
1081     IN PFN_OID_HANDLER_FUNC pfnOidHandler,
1082     IN BOOLEAN              fgSetInfo
1083     )
1084 {
1085     PFN_OID_HANDLER_FUNC* apfnOidHandlerWOHwAccess;
1086     UINT_32 i;
1087     UINT_32 u4NumOfElem;
1088
1089     if (fgSetInfo) {
1090         apfnOidHandlerWOHwAccess = apfnOidSetHandlerWOHwAccess;
1091         u4NumOfElem = sizeof(apfnOidSetHandlerWOHwAccess) / sizeof(PFN_OID_HANDLER_FUNC);
1092     }
1093     else {
1094         apfnOidHandlerWOHwAccess = apfnOidQueryHandlerWOHwAccess;
1095         u4NumOfElem = sizeof(apfnOidQueryHandlerWOHwAccess) / sizeof(PFN_OID_HANDLER_FUNC);
1096     }
1097
1098     for (i = 0; i < u4NumOfElem; i++) {
1099         if (apfnOidHandlerWOHwAccess[i] == pfnOidHandler) {
1100             return FALSE;
1101         }
1102     }
1103
1104     return TRUE;
1105 }   /* wlanIsHandlerNeedHwAccess */
1106
1107
1108 /*----------------------------------------------------------------------------*/
1109 /*!
1110 * \brief This routine is called to set flag for later handling card
1111 *        ejected event.
1112 *
1113 * \param[in] prAdapter Pointer to the Adapter structure.
1114 *
1115 * \return (none)
1116 *
1117 * \note When surprised removal happens, Glue layer should invoke this
1118 *       function to notify WPDD not to do any hw access.
1119 */
1120 /*----------------------------------------------------------------------------*/
1121 VOID
1122 wlanCardEjected (
1123     IN P_ADAPTER_T         prAdapter
1124     )
1125 {
1126     DEBUGFUNC("wlanCardEjected");
1127     //INITLOG(("\n"));
1128
1129     ASSERT(prAdapter);
1130
1131      /* mark that the card is being ejected, NDIS will shut us down soon */
1132     nicTxRelease(prAdapter);
1133
1134 } /* wlanCardEjected */
1135
1136
1137 /*----------------------------------------------------------------------------*/
1138 /*!
1139 * \brief Create adapter object
1140 *
1141 * \param prAdapter This routine is call to allocate the driver software objects.
1142 *                  If fails, return NULL.
1143 * \retval NULL If it fails, NULL is returned.
1144 * \retval NOT NULL If the adapter was initialized successfully.
1145 */
1146 /*----------------------------------------------------------------------------*/
1147 P_ADAPTER_T
1148 wlanAdapterCreate (
1149     IN P_GLUE_INFO_T prGlueInfo
1150     )
1151 {
1152     P_ADAPTER_T prAdpater = (P_ADAPTER_T)NULL;
1153
1154     DEBUGFUNC("wlanAdapterCreate");
1155
1156     do {
1157         prAdpater = (P_ADAPTER_T) kalMemAlloc(sizeof(ADAPTER_T), VIR_MEM_TYPE);
1158
1159         if (!prAdpater) {
1160             DBGLOG(INIT, ERROR, ("Allocate ADAPTER memory ==> FAILED\n"));
1161             break;
1162         }
1163
1164 #if QM_TEST_MODE
1165         g_rQM.prAdapter = prAdpater;
1166 #endif
1167         kalMemZero(prAdpater, sizeof(ADAPTER_T));
1168         prAdpater->prGlueInfo = prGlueInfo;
1169
1170     } while(FALSE);
1171
1172     return prAdpater;
1173 } /* wlanAdapterCreate */
1174
1175
1176 /*----------------------------------------------------------------------------*/
1177 /*!
1178 * \brief Destroy adapter object
1179 *
1180 * \param prAdapter This routine is call to destroy the driver software objects.
1181 *                  If fails, return NULL.
1182 * \return (none)
1183 */
1184 /*----------------------------------------------------------------------------*/
1185 VOID
1186 wlanAdapterDestroy (
1187     IN P_ADAPTER_T prAdapter
1188     )
1189 {
1190
1191     if (!prAdapter) {
1192         return;
1193     }
1194
1195     kalMemFree(prAdapter, VIR_MEM_TYPE, sizeof(ADAPTER_T));
1196
1197     return;
1198 }
1199
1200 /*----------------------------------------------------------------------------*/
1201 /*!
1202 * \brief Initialize the adapter. The sequence is
1203 *        1. Disable interrupt
1204 *        2. Read adapter configuration from EEPROM and registry, verify chip ID.
1205 *        3. Create NIC Tx/Rx resource.
1206 *        4. Initialize the chip
1207 *        5. Initialize the protocol
1208 *        6. Enable Interrupt
1209 *
1210 * \param prAdapter      Pointer of Adapter Data Structure
1211 *
1212 * \retval WLAN_STATUS_SUCCESS: Success
1213 * \retval WLAN_STATUS_FAILURE: Failed
1214 */
1215 /*----------------------------------------------------------------------------*/
1216 WLAN_STATUS
1217 wlanAdapterStart (
1218     IN P_ADAPTER_T  prAdapter,
1219     IN P_REG_INFO_T prRegInfo,
1220     IN PVOID        pvFwImageMapFile,
1221     IN UINT_32      u4FwImageFileLength
1222     )
1223 {
1224     WLAN_STATUS u4Status = WLAN_STATUS_SUCCESS;
1225     UINT_32     i, u4Value = 0;
1226     UINT_32     u4WHISR = 0;
1227     UINT_8      aucTxCount[8];
1228 #if CFG_ENABLE_FW_DOWNLOAD
1229     UINT_32     u4FwLoadAddr, u4ImgSecSize;
1230     #if CFG_ENABLE_FW_DIVIDED_DOWNLOAD
1231     UINT_32     j;
1232     P_FIRMWARE_DIVIDED_DOWNLOAD_T prFwHead;
1233     BOOLEAN fgValidHead;
1234     const UINT_32 u4CRCOffset = offsetof(FIRMWARE_DIVIDED_DOWNLOAD_T, u4NumOfEntries);
1235     #endif
1236 #endif
1237 #if (defined(MT5931) && (!CFG_SUPPORT_BCM_BWCS))
1238     PARAM_PTA_IPC_T rBwcsPta;
1239     UINT_32 u4SetInfoLen;
1240 #endif
1241
1242     ASSERT(prAdapter);
1243
1244     DEBUGFUNC("wlanAdapterStart");
1245
1246     //4 <0> Reset variables in ADAPTER_T
1247     prAdapter->fgIsFwOwn = TRUE;
1248     prAdapter->fgIsEnterD3ReqIssued = FALSE;
1249
1250     QUEUE_INITIALIZE(&(prAdapter->rPendingCmdQueue));
1251
1252     /* Initialize rWlanInfo */
1253     kalMemSet(&(prAdapter->rWlanInfo), 0, sizeof(WLAN_INFO_T));
1254
1255     //4 <0.1> reset fgIsBusAccessFailed
1256     fgIsBusAccessFailed = FALSE;
1257
1258     do {
1259         if ( (u4Status = nicAllocateAdapterMemory(prAdapter)) != WLAN_STATUS_SUCCESS ) {
1260             DBGLOG(INIT, ERROR, ("nicAllocateAdapterMemory Error!\n"));
1261             u4Status = WLAN_STATUS_FAILURE;
1262             break;
1263         }
1264
1265         prAdapter->u4OsPacketFilter = PARAM_PACKET_FILTER_SUPPORTED;
1266
1267 #if defined(MT6620) || defined(MT6628)
1268         DBGLOG(INIT, TRACE, ("wlanAdapterStart(): Acquiring LP-OWN\n"));
1269         ACQUIRE_POWER_CONTROL_FROM_PM(prAdapter);
1270     #if !CFG_ENABLE_FULL_PM
1271         nicpmSetDriverOwn(prAdapter);
1272     #endif
1273
1274         if(prAdapter->fgIsFwOwn == TRUE) {
1275             DBGLOG(INIT, ERROR, ("nicpmSetDriverOwn() failed!\n"));
1276             u4Status = WLAN_STATUS_FAILURE;
1277             break;
1278         }
1279
1280         //4 <1> Initialize the Adapter
1281         if ( (u4Status = nicInitializeAdapter(prAdapter)) != WLAN_STATUS_SUCCESS ) {
1282             DBGLOG(INIT, ERROR, ("nicInitializeAdapter failed!\n"));
1283             u4Status = WLAN_STATUS_FAILURE;
1284             break;
1285         }
1286 #endif
1287
1288         //4 <2> Initialize System Service (MGMT Memory pool and STA_REC)
1289         nicInitSystemService(prAdapter);
1290
1291         //4 <3> Initialize Tx
1292         nicTxInitialize(prAdapter);
1293         wlanDefTxPowerCfg(prAdapter);
1294
1295         //4 <4> Initialize Rx
1296         nicRxInitialize(prAdapter);
1297
1298 #if CFG_ENABLE_FW_DOWNLOAD
1299     #if defined(MT6620) || defined(MT6628)
1300         if (pvFwImageMapFile) {
1301             /* 1. disable interrupt, download is done by polling mode only */
1302             nicDisableInterrupt(prAdapter);
1303
1304             /* 2. Initialize Tx Resource to fw download state */
1305             nicTxInitResetResource(prAdapter);
1306
1307             /* 3. FW download here */
1308             u4FwLoadAddr = prRegInfo->u4LoadAddress;
1309
1310         #if CFG_ENABLE_FW_DIVIDED_DOWNLOAD
1311             // 3a. parse file header for decision of divided firmware download or not
1312             prFwHead = (P_FIRMWARE_DIVIDED_DOWNLOAD_T)pvFwImageMapFile;
1313
1314             if(prFwHead->u4Signature == MTK_WIFI_SIGNATURE &&
1315                     prFwHead->u4CRC == wlanCRC32((PUINT_8)pvFwImageMapFile + u4CRCOffset, u4FwImageFileLength - u4CRCOffset)) {
1316                 fgValidHead = TRUE;
1317             }
1318             else {
1319                 fgValidHead = FALSE;
1320             }
1321
1322             /* 3b. engage divided firmware downloading */
1323             if(fgValidHead == TRUE) {
1324                 for(i = 0 ; i < prFwHead->u4NumOfEntries ; i++) {
1325             #if CFG_ENABLE_FW_DOWNLOAD_AGGREGATION
1326                     if(wlanImageSectionDownloadAggregated(prAdapter,
1327                                 prFwHead->arSection[i].u4DestAddr,
1328                                 prFwHead->arSection[i].u4Length,
1329                                 (PUINT_8)pvFwImageMapFile + prFwHead->arSection[i].u4Offset) != WLAN_STATUS_SUCCESS) {
1330                         DBGLOG(INIT, ERROR, ("Firmware scatter download failed!\n"));
1331                         u4Status = WLAN_STATUS_FAILURE;
1332                     }
1333             #else
1334                     for(j = 0 ; j < prFwHead->arSection[i].u4Length ; j += CMD_PKT_SIZE_FOR_IMAGE) {
1335                         if(j + CMD_PKT_SIZE_FOR_IMAGE < prFwHead->arSection[i].u4Length)
1336                             u4ImgSecSize = CMD_PKT_SIZE_FOR_IMAGE;
1337                         else
1338                             u4ImgSecSize = prFwHead->arSection[i].u4Length - j;
1339
1340                         if(wlanImageSectionDownload(prAdapter,
1341                                     prFwHead->arSection[i].u4DestAddr + j,
1342                                     u4ImgSecSize,
1343                                     (PUINT_8)pvFwImageMapFile + prFwHead->arSection[i].u4Offset + j) != WLAN_STATUS_SUCCESS) {
1344                             DBGLOG(INIT, ERROR, ("Firmware scatter download failed!\n"));
1345                             u4Status = WLAN_STATUS_FAILURE;
1346                             break;
1347                         }
1348                     }
1349             #endif
1350
1351                     /* escape from loop if any pending error occurs */
1352                     if(u4Status == WLAN_STATUS_FAILURE) {
1353                         break;
1354                     }
1355                 }
1356             }
1357             else
1358         #endif
1359         #if CFG_ENABLE_FW_DOWNLOAD_AGGREGATION
1360             if(wlanImageSectionDownloadAggregated(prAdapter,
1361                         u4FwLoadAddr,
1362                         u4FwImageFileLength,
1363                         (PUINT_8)pvFwImageMapFile) != WLAN_STATUS_SUCCESS) {
1364                 DBGLOG(INIT, ERROR, ("Firmware scatter download failed!\n"));
1365                 u4Status = WLAN_STATUS_FAILURE;
1366             }
1367         #else
1368             for (i = 0; i < u4FwImageFileLength ; i += CMD_PKT_SIZE_FOR_IMAGE) {
1369                 if(i + CMD_PKT_SIZE_FOR_IMAGE < u4FwImageFileLength)
1370                     u4ImgSecSize = CMD_PKT_SIZE_FOR_IMAGE;
1371                 else
1372                     u4ImgSecSize = u4FwImageFileLength - i;
1373
1374                 if(wlanImageSectionDownload(prAdapter,
1375                         u4FwLoadAddr + i,
1376                         u4ImgSecSize,
1377                         (PUINT_8)pvFwImageMapFile + i) != WLAN_STATUS_SUCCESS) {
1378                     DBGLOG(INIT, ERROR, ("Firmware scatter download failed!\n"));
1379                     u4Status = WLAN_STATUS_FAILURE;
1380                     break;
1381                 }
1382             }
1383         #endif
1384
1385             if(u4Status != WLAN_STATUS_SUCCESS) {
1386                 break;
1387             }
1388
1389         #if !CFG_ENABLE_FW_DOWNLOAD_ACK
1390             // Send INIT_CMD_ID_QUERY_PENDING_ERROR command and wait for response
1391             if(wlanImageQueryStatus(prAdapter) != WLAN_STATUS_SUCCESS) {
1392                 DBGLOG(INIT, ERROR, ("Firmware download failed!\n"));
1393                 u4Status = WLAN_STATUS_FAILURE;
1394                 break;
1395             }
1396         #endif
1397         }
1398         else {
1399             DBGLOG(INIT, ERROR, ("No Firmware found!\n"));
1400             u4Status = WLAN_STATUS_FAILURE;
1401             break;
1402         }
1403
1404         /* 4. send Wi-Fi Start command */
1405         #if CFG_OVERRIDE_FW_START_ADDRESS
1406         wlanConfigWifiFunc(prAdapter,
1407                 TRUE,
1408                 prRegInfo->u4StartAddress);
1409         #else
1410         wlanConfigWifiFunc(prAdapter,
1411                 FALSE,
1412                 0);
1413         #endif
1414     #elif defined(MT5931)
1415         if (pvFwImageMapFile) {
1416             DBGLOG(INIT, TRACE, ("Download Address: 0x%08X\n", prRegInfo->u4LoadAddress));
1417             DBGLOG(INIT, TRACE, ("Firmware Length:  0x%08X\n", u4FwImageFileLength));
1418
1419             do {
1420 #if CFG_SUPPORT_WHOLE_CHIP_RESET
1421 #define RESET_RDY_INTERVAL (120)
1422
1423                 /* 1.0 whole-chip reset except HIFSYS */
1424                 HAL_MCR_WR(prAdapter, MCR_WMCSR, WMCSR_CHIP_RST);
1425                 HAL_MCR_WR(prAdapter, MCR_WMCSR, 0);
1426
1427                 /* 1.0.1 delay for EEIF ready */
1428                 kalMsleep(RESET_RDY_INTERVAL);
1429 #endif
1430
1431                 /* 1.1 wait for INIT_RDY */
1432                 i = 0;
1433                 while(1) {
1434                     HAL_MCR_RD(prAdapter, MCR_WMCSR, &u4Value);
1435
1436                     if (u4Value & WMCSR_INI_RDY) {
1437                         DBGLOG(INIT, TRACE, ("INIT-RDY detected\n"));
1438                         break;
1439                     }
1440                     else if(kalIsCardRemoved(prAdapter->prGlueInfo) == TRUE
1441                             || fgIsBusAccessFailed == TRUE) {
1442                         u4Status = WLAN_STATUS_FAILURE;
1443                         break;
1444                     }
1445                     else if(i >= CFG_RESPONSE_POLLING_TIMEOUT) {
1446                         DBGLOG(INIT, ERROR, ("Waiting for Init Ready bit: Timeout\n"));
1447                         u4Status = WLAN_STATUS_FAILURE;
1448                         break;
1449                     }
1450                     else {
1451                         i++;
1452                         kalMsleep(10);
1453                     }
1454                 }
1455
1456                 if(u4Status != WLAN_STATUS_SUCCESS) {
1457                     break;
1458                 }
1459
1460                 /* 1.2 set KSEL/FLEN */
1461                 HAL_MCR_WR(prAdapter, MCR_FWCFG, u4FwImageFileLength >> 6);
1462
1463                 /* 1.3 enable FWDL_EN */
1464                 HAL_MCR_WR(prAdapter, MCR_WMCSR, WMCSR_FWDLEN);
1465
1466                 /* 1.4 wait for PLL_RDY */
1467                 i = 0;
1468                 while(1) {
1469                     HAL_MCR_RD(prAdapter, MCR_WMCSR, &u4Value);
1470
1471                     if (u4Value & WMCSR_PLLRDY) {
1472                         DBGLOG(INIT, TRACE, ("PLL-RDY detected\n"));
1473                         break;
1474                     }
1475                     else if(kalIsCardRemoved(prAdapter->prGlueInfo) == TRUE
1476                             || fgIsBusAccessFailed == TRUE) {
1477                         u4Status = WLAN_STATUS_FAILURE;
1478                         break;
1479                     }
1480                     else if(i >= CFG_RESPONSE_POLLING_TIMEOUT) {
1481                         DBGLOG(INIT, ERROR, ("Waiting for PLL Ready bit: Timeout\n"));
1482                         u4Status = WLAN_STATUS_FAILURE;
1483                         break;
1484                     }
1485                     else {
1486                         i++;
1487                         kalMsleep(10);
1488                     }
1489                 }
1490
1491                 if(u4Status != WLAN_STATUS_SUCCESS) {
1492                     break;
1493                 }
1494
1495                 /* 2.1 turn on HIFSYS firmware download mode */
1496                 HAL_MCR_WR(prAdapter, MCR_FWDLSR, FWDLSR_FWDL_MODE);
1497
1498                 /* 2.2 set starting address */
1499                 u4FwLoadAddr = prRegInfo->u4LoadAddress;
1500                 HAL_MCR_WR(prAdapter, MCR_FWDLDSAR, u4FwLoadAddr);
1501
1502                 /* 3. upload firmware */
1503                 for (i = 0; i < u4FwImageFileLength ; i += CMD_PKT_SIZE_FOR_IMAGE) {
1504                     if(i + CMD_PKT_SIZE_FOR_IMAGE < u4FwImageFileLength)
1505                         u4ImgSecSize = CMD_PKT_SIZE_FOR_IMAGE;
1506                     else
1507                         u4ImgSecSize = u4FwImageFileLength - i;
1508
1509                     if(wlanImageSectionDownload(prAdapter,
1510                                 u4FwLoadAddr + i,
1511                                 u4ImgSecSize,
1512                                 (PUINT_8)pvFwImageMapFile + i) != WLAN_STATUS_SUCCESS) {
1513                         DBGLOG(INIT, ERROR, ("Firmware scatter download failed!\n"));
1514                         u4Status = WLAN_STATUS_FAILURE;
1515                         break;
1516                     }
1517                 }
1518
1519                 if(u4Status != WLAN_STATUS_SUCCESS) {
1520                     break;
1521                 }
1522
1523                 /* 4.1 poll FWDL_OK & FWDL_FAIL bits */
1524                 i = 0;
1525                 while(1) {
1526                     HAL_MCR_RD(prAdapter, MCR_WMCSR, &u4Value);
1527
1528                     if (u4Value & WMCSR_DL_OK) {
1529                          DBGLOG(INIT, TRACE, ("DL_OK detected\n"));
1530                         break;
1531                     }
1532                     else if(kalIsCardRemoved(prAdapter->prGlueInfo) == TRUE
1533                             || fgIsBusAccessFailed == TRUE
1534                             || (u4Value & WMCSR_DL_FAIL)) {
1535                         DBGLOG(INIT, ERROR, ("DL_FAIL detected: 0x%08X\n", u4Value));
1536                         u4Status = WLAN_STATUS_FAILURE;
1537                         break;
1538                     }
1539                     else if(i >= CFG_RESPONSE_POLLING_TIMEOUT) {
1540                         DBGLOG(INIT, ERROR, ("Waiting for DL_OK/DL_FAIL bit: Timeout\n"));
1541                         u4Status = WLAN_STATUS_FAILURE;
1542                         break;
1543                     }
1544                     else {
1545                         i++;
1546                         kalMsleep(10);
1547                     }
1548                 }
1549
1550                 if(u4Status != WLAN_STATUS_SUCCESS) {
1551                     break;
1552                 }
1553
1554                 /* 4.2 turn off HIFSYS download mode */
1555                 HAL_MCR_WR(prAdapter, MCR_FWDLSR, 0);
1556
1557             } while (FALSE);
1558
1559             if(u4Status != WLAN_STATUS_SUCCESS) {
1560                 break;
1561             }
1562
1563             /* 5. disable interrupt */
1564             nicDisableInterrupt(prAdapter);
1565         }
1566         else {
1567             DBGLOG(INIT, ERROR, ("No Firmware found!\n"));
1568             u4Status = WLAN_STATUS_FAILURE;
1569             break;
1570         }
1571     #endif
1572 #endif
1573
1574         DBGLOG(INIT, TRACE, ("wlanAdapterStart(): Waiting for Ready bit..\n"));
1575         //4 <5> check Wi-Fi FW asserts ready bit
1576         i = 0;
1577         while(1) {
1578             HAL_MCR_RD(prAdapter, MCR_WCIR, &u4Value);
1579
1580             if (u4Value & WCIR_WLAN_READY) {
1581                 DBGLOG(INIT, TRACE, ("Ready bit asserted\n"));
1582                 break;
1583             }
1584             else if(kalIsCardRemoved(prAdapter->prGlueInfo) == TRUE
1585                     || fgIsBusAccessFailed == TRUE) {
1586                 u4Status = WLAN_STATUS_FAILURE;
1587                 break;
1588             }
1589             else if(i >= CFG_RESPONSE_POLLING_TIMEOUT) {
1590                 UINT_32     u4MailBox0;
1591
1592                 nicGetMailbox(prAdapter, 0, &u4MailBox0);
1593                 DBGLOG(INIT, ERROR, ("Waiting for Ready bit: Timeout, ID=%d\n",
1594                         (u4MailBox0 & 0x0000FFFF)));
1595                 u4Status = WLAN_STATUS_FAILURE;
1596                 break;
1597             }
1598             else {
1599                 i++;
1600                 kalMsleep(10);
1601             }
1602         }
1603
1604 #if defined(MT5931)
1605         // Acquire LP-OWN
1606         DBGLOG(INIT, TRACE, ("wlanAdapterStart(): Acquiring LP-OWN\n"));
1607         ACQUIRE_POWER_CONTROL_FROM_PM(prAdapter);
1608     #if !CFG_ENABLE_FULL_PM
1609         nicpmSetDriverOwn(prAdapter);
1610     #endif
1611
1612         if(prAdapter->fgIsFwOwn == TRUE) {
1613             DBGLOG(INIT, ERROR, ("nicpmSetDriverOwn() failed!\n"));
1614             u4Status = WLAN_STATUS_FAILURE;
1615             break;
1616         }
1617
1618         //4 <1> Initialize the Adapter
1619         if ( (u4Status = nicInitializeAdapter(prAdapter)) != WLAN_STATUS_SUCCESS ) {
1620             DBGLOG(INIT, ERROR, ("nicInitializeAdapter failed!\n"));
1621             u4Status = WLAN_STATUS_FAILURE;
1622             break;
1623         }
1624
1625         /* post initialization for MT5931 due to some CR is only accessible after driver own */
1626         nicRxPostInitialize(prAdapter);
1627 #endif
1628
1629         if(u4Status == WLAN_STATUS_SUCCESS) {
1630             // 1. reset interrupt status
1631             HAL_READ_INTR_STATUS(prAdapter, 4, (PUINT_8)&u4WHISR);
1632             if(HAL_IS_TX_DONE_INTR(u4WHISR)) {
1633                 HAL_READ_TX_RELEASED_COUNT(prAdapter, aucTxCount);
1634             }
1635
1636             /* 2. reset TX Resource for normal operation */
1637             nicTxResetResource(prAdapter);
1638
1639 #if CFG_SUPPORT_OSC_SETTING && defined(MT5931)
1640             wlanSetMcuOscStableTime(prAdapter, 0);
1641 #endif
1642
1643             /* 3. query for permanent address by polling */
1644             wlanQueryPermanentAddress(prAdapter);
1645
1646 #if (CFG_SUPPORT_NIC_CAPABILITY == 1)
1647             /* 4. query for NIC capability */
1648             wlanQueryNicCapability(prAdapter);
1649 #endif
1650
1651             /* 5. Override network address */
1652             wlanUpdateNetworkAddress(prAdapter);
1653
1654             /* 6. indicate disconnection as default status */
1655             kalIndicateStatusAndComplete(prAdapter->prGlueInfo,
1656                     WLAN_STATUS_MEDIA_DISCONNECT,
1657                     NULL,
1658                     0);
1659         }
1660
1661         RECLAIM_POWER_CONTROL_TO_PM(prAdapter, FALSE);
1662
1663         if(u4Status != WLAN_STATUS_SUCCESS) {
1664             break;
1665         }
1666
1667         /* OID timeout timer initialize */
1668         cnmTimerInitTimer(prAdapter,
1669                 &prAdapter->rOidTimeoutTimer,
1670                 (PFN_MGMT_TIMEOUT_FUNC)wlanReleasePendingOid,
1671                 (UINT_32)NULL);
1672
1673         /* Power state initialization */
1674         prAdapter->fgWiFiInSleepyState = FALSE;
1675         prAdapter->rAcpiState = ACPI_STATE_D0;
1676
1677         /* Online scan option */
1678         if(prRegInfo->fgDisOnlineScan == 0) {
1679             prAdapter->fgEnOnlineScan = TRUE;
1680         }
1681         else {
1682             prAdapter->fgEnOnlineScan = FALSE;
1683         }
1684
1685         /* Beacon lost detection option */
1686         if(prRegInfo->fgDisBcnLostDetection != 0) {
1687             prAdapter->fgDisBcnLostDetection = TRUE;
1688         }
1689
1690         /* Load compile time constant */
1691         prAdapter->rWlanInfo.u2BeaconPeriod = CFG_INIT_ADHOC_BEACON_INTERVAL;
1692         prAdapter->rWlanInfo.u2AtimWindow = CFG_INIT_ADHOC_ATIM_WINDOW;
1693
1694 #if 1// set PM parameters
1695         prAdapter->fgEnArpFilter = prRegInfo->fgEnArpFilter;
1696         prAdapter->u4PsCurrentMeasureEn = prRegInfo->u4PsCurrentMeasureEn;
1697
1698         prAdapter->u4UapsdAcBmp = prRegInfo->u4UapsdAcBmp;
1699
1700         prAdapter->u4MaxSpLen = prRegInfo->u4MaxSpLen;
1701
1702         DBGLOG(INIT, TRACE, ("[1] fgEnArpFilter:0x%x, u4UapsdAcBmp:0x%x, u4MaxSpLen:0x%x",
1703                 prAdapter->fgEnArpFilter,
1704                 prAdapter->u4UapsdAcBmp,
1705                 prAdapter->u4MaxSpLen));
1706
1707         prAdapter->fgEnCtiaPowerMode = FALSE;
1708
1709 #endif
1710
1711         /* MGMT Initialization */
1712         nicInitMGMT(prAdapter, prRegInfo);
1713
1714         /* Enable WZC Disassociation */
1715         prAdapter->rWifiVar.fgSupportWZCDisassociation = TRUE;
1716
1717         /* Apply Rate Setting */
1718         if((ENUM_REGISTRY_FIXED_RATE_T)(prRegInfo->u4FixedRate) < FIXED_RATE_NUM) {
1719             prAdapter->rWifiVar.eRateSetting = (ENUM_REGISTRY_FIXED_RATE_T)(prRegInfo->u4FixedRate);
1720         }
1721         else {
1722             prAdapter->rWifiVar.eRateSetting = FIXED_RATE_NONE;
1723         }
1724
1725         if(prAdapter->rWifiVar.eRateSetting == FIXED_RATE_NONE) {
1726             /* Enable Auto (Long/Short) Preamble */
1727             prAdapter->rWifiVar.ePreambleType = PREAMBLE_TYPE_AUTO;
1728         }
1729         else if((prAdapter->rWifiVar.eRateSetting >= FIXED_RATE_MCS0_20M_400NS &&
1730                     prAdapter->rWifiVar.eRateSetting <= FIXED_RATE_MCS7_20M_400NS)
1731                 || (prAdapter->rWifiVar.eRateSetting >= FIXED_RATE_MCS0_40M_400NS &&
1732                         prAdapter->rWifiVar.eRateSetting <= FIXED_RATE_MCS32_400NS)) {
1733             /* Force Short Preamble */
1734             prAdapter->rWifiVar.ePreambleType = PREAMBLE_TYPE_SHORT;
1735         }
1736         else {
1737             /* Force Long Preamble */
1738             prAdapter->rWifiVar.ePreambleType = PREAMBLE_TYPE_LONG;
1739         }
1740
1741         /* Disable Hidden SSID Join */
1742         prAdapter->rWifiVar.fgEnableJoinToHiddenSSID = FALSE;
1743
1744         /* Enable Short Slot Time */
1745         prAdapter->rWifiVar.fgIsShortSlotTimeOptionEnable = TRUE;
1746
1747         /* configure available PHY type set */
1748         nicSetAvailablePhyTypeSet(prAdapter);
1749
1750 #if 1// set PM parameters
1751         {
1752 #if  CFG_SUPPORT_PWR_MGT
1753         prAdapter->u4PowerMode = prRegInfo->u4PowerMode;
1754         prAdapter->rWlanInfo.arPowerSaveMode[NETWORK_TYPE_P2P_INDEX].ucNetTypeIndex = NETWORK_TYPE_P2P_INDEX;
1755         prAdapter->rWlanInfo.arPowerSaveMode[NETWORK_TYPE_P2P_INDEX].ucPsProfile = ENUM_PSP_FAST_SWITCH;
1756 #else
1757         prAdapter->u4PowerMode = ENUM_PSP_CONTINUOUS_ACTIVE;
1758 #endif
1759         {/*CR:WCNAE00007101*/
1760             struct net_device *prDev = prAdapter->prGlueInfo->prDevHandler;
1761
1762             if (prDev != NULL) {
1763                 glBusSetIrq(prDev, NULL, prAdapter->prGlueInfo );
1764             }
1765             else {
1766                 printk(KERN_INFO "Skip glBusSetIrq because of the prDev\n");
1767             }
1768         }
1769         nicConfigPowerSaveProfile(
1770             prAdapter,
1771             NETWORK_TYPE_AIS_INDEX, //FIXIT
1772             prAdapter->u4PowerMode,
1773             FALSE);
1774         }
1775
1776 #endif
1777
1778 #if CFG_SUPPORT_NVRAM
1779         /* load manufacture data */
1780         wlanLoadManufactureData(prAdapter, prRegInfo);
1781 #endif
1782
1783 #if (defined(MT5931) && (!CFG_SUPPORT_BCM_BWCS))
1784         //Enable DPD calibration.
1785         rBwcsPta.u.aucBTPParams[0] = 0x00;
1786         rBwcsPta.u.aucBTPParams[1] = 0x01;
1787         rBwcsPta.u.aucBTPParams[2] = 0x00;
1788         rBwcsPta.u.aucBTPParams[3] = 0x80;
1789
1790         wlanoidSetBT(prAdapter,
1791             (PVOID)&rBwcsPta,
1792             sizeof(PARAM_PTA_IPC_T),
1793             &u4SetInfoLen);
1794 #endif
1795
1796 #if 0
1797     /* Update Auto rate parameters in FW */
1798     nicRlmArUpdateParms(prAdapter,
1799         prRegInfo->u4ArSysParam0,
1800         prRegInfo->u4ArSysParam1,
1801         prRegInfo->u4ArSysParam2,
1802         prRegInfo->u4ArSysParam3);
1803 #endif
1804
1805
1806 #if (MT6620_E1_ASIC_HIFSYS_WORKAROUND == 1)
1807         /* clock gating workaround */
1808         prAdapter->fgIsClockGatingEnabled = FALSE;
1809 #endif
1810
1811     } while(FALSE);
1812
1813     if(u4Status == WLAN_STATUS_SUCCESS) {
1814         // restore to hardware default
1815         HAL_SET_INTR_STATUS_READ_CLEAR(prAdapter);
1816         HAL_SET_MAILBOX_READ_CLEAR(prAdapter, FALSE);
1817
1818         /* Enable interrupt */
1819         nicEnableInterrupt(prAdapter);
1820
1821     }
1822     else {
1823         // release allocated memory
1824         nicReleaseAdapterMemory(prAdapter);
1825     }
1826
1827     return u4Status;
1828 } /* wlanAdapterStart */
1829
1830
1831 /*----------------------------------------------------------------------------*/
1832 /*!
1833 * \brief Uninitialize the adapter
1834 *
1835 * \param prAdapter      Pointer of Adapter Data Structure
1836 *
1837 * \retval WLAN_STATUS_SUCCESS: Success
1838 * \retval WLAN_STATUS_FAILURE: Failed
1839 */
1840 /*----------------------------------------------------------------------------*/
1841 WLAN_STATUS
1842 wlanAdapterStop (
1843     IN P_ADAPTER_T prAdapter
1844     )
1845 {
1846     UINT_32 i, u4Value = 0;
1847     WLAN_STATUS u4Status = WLAN_STATUS_SUCCESS;
1848
1849     ASSERT(prAdapter);
1850
1851 #if (MT6620_E1_ASIC_HIFSYS_WORKAROUND == 1)
1852     if(prAdapter->fgIsClockGatingEnabled == TRUE) {
1853         nicDisableClockGating(prAdapter);
1854     }
1855 #endif
1856
1857     /* MGMT - unitialization */
1858     nicUninitMGMT(prAdapter);
1859
1860     if(prAdapter->rAcpiState == ACPI_STATE_D0 &&
1861 #if (CFG_CHIP_RESET_SUPPORT == 1)
1862             kalIsResetting() == FALSE &&
1863 #endif
1864             kalIsCardRemoved(prAdapter->prGlueInfo) == FALSE) {
1865
1866         /* 0. Disable interrupt, this can be done without Driver own */
1867         nicDisableInterrupt(prAdapter);
1868
1869         ACQUIRE_POWER_CONTROL_FROM_PM(prAdapter);
1870
1871         /* 1. Set CMD to FW to tell WIFI to stop (enter power off state) */
1872         if(prAdapter->fgIsFwOwn == FALSE &&
1873                 wlanSendNicPowerCtrlCmd(prAdapter, 1) == WLAN_STATUS_SUCCESS) {
1874             /* 2. Clear pending interrupt */
1875             i = 0;
1876             while(i < CFG_IST_LOOP_COUNT && nicProcessIST(prAdapter) != WLAN_STATUS_NOT_INDICATING) {
1877                 i++;
1878             };
1879
1880             /* 3. Wait til RDY bit has been cleaerd */
1881             i = 0;
1882             while(1) {
1883                 HAL_MCR_RD(prAdapter, MCR_WCIR, &u4Value);
1884
1885                 if ((u4Value & WCIR_WLAN_READY) == 0)
1886                     break;
1887                 else if(kalIsCardRemoved(prAdapter->prGlueInfo) == TRUE
1888                         || fgIsBusAccessFailed == TRUE
1889                         || i >= CFG_RESPONSE_POLLING_TIMEOUT) {
1890                     break;
1891                 }
1892                 else {
1893                     i++;
1894                     kalMsleep(10);
1895                 }
1896             }
1897         }
1898
1899         /* 4. Set Onwership to F/W */
1900         nicpmSetFWOwn(prAdapter, FALSE);
1901
1902 #if CFG_FORCE_RESET_UNDER_BUS_ERROR
1903         if(HAL_TEST_FLAG(prAdapter, ADAPTER_FLAG_HW_ERR) == TRUE) {
1904             /* force acquire firmware own */
1905             kalDevRegWrite(prAdapter->prGlueInfo, MCR_WHLPCR, WHLPCR_FW_OWN_REQ_CLR);
1906
1907             /* delay for 10ms */
1908             kalMdelay(10);
1909
1910             /* force firmware reset via software interrupt */
1911             kalDevRegWrite(prAdapter->prGlueInfo, MCR_WSICR, WSICR_H2D_SW_INT_SET);
1912
1913             /* force release firmware own */
1914             kalDevRegWrite(prAdapter->prGlueInfo, MCR_WHLPCR, WHLPCR_FW_OWN_REQ_SET);
1915         }
1916 #endif
1917
1918         RECLAIM_POWER_CONTROL_TO_PM(prAdapter, FALSE);
1919     }
1920
1921     nicRxUninitialize(prAdapter);
1922
1923     nicTxRelease(prAdapter);
1924
1925     /* System Service Uninitialization */
1926     nicUninitSystemService(prAdapter);
1927
1928     nicReleaseAdapterMemory(prAdapter);
1929
1930 #if defined(_HIF_SPI)
1931     /* Note: restore the SPI Mode Select from 32 bit to default */
1932     nicRestoreSpiDefMode(prAdapter);
1933 #endif
1934
1935     return u4Status;
1936 } /* wlanAdapterStop */
1937
1938
1939 /*----------------------------------------------------------------------------*/
1940 /*!
1941 * \brief This function is called by ISR (interrupt).
1942 *
1943 * \param prAdapter      Pointer of Adapter Data Structure
1944 *
1945 * \retval TRUE: NIC's interrupt
1946 * \retval FALSE: Not NIC's interrupt
1947 */
1948 /*----------------------------------------------------------------------------*/
1949 BOOL
1950 wlanISR (
1951     IN P_ADAPTER_T prAdapter,
1952     IN BOOLEAN fgGlobalIntrCtrl
1953     )
1954 {
1955     ASSERT(prAdapter);
1956
1957     if (fgGlobalIntrCtrl) {
1958         nicDisableInterrupt(prAdapter);
1959
1960         //wlanIST(prAdapter);
1961     }
1962
1963     return TRUE;
1964 }
1965
1966 /*----------------------------------------------------------------------------*/
1967 /*!
1968 * \brief This function is called by IST (task_let).
1969 *
1970 * \param prAdapter      Pointer of Adapter Data Structure
1971 *
1972 * \return (none)
1973 */
1974 /*----------------------------------------------------------------------------*/
1975 VOID
1976 wlanIST (
1977     IN P_ADAPTER_T prAdapter
1978     )
1979 {
1980     ASSERT(prAdapter);
1981
1982     ACQUIRE_POWER_CONTROL_FROM_PM(prAdapter);
1983
1984     nicProcessIST(prAdapter);
1985
1986     nicEnableInterrupt(prAdapter);
1987
1988     RECLAIM_POWER_CONTROL_TO_PM(prAdapter, FALSE);
1989
1990     return;
1991 }
1992
1993
1994 /*----------------------------------------------------------------------------*/
1995 /*!
1996 * \brief This function will check command queue to find out if any could be dequeued
1997 *        and/or send to HIF to MT6620
1998 *
1999 * \param prAdapter      Pointer of Adapter Data Structure
2000 * \param prCmdQue       Pointer of Command Queue (in Glue Layer)
2001 *
2002 * \retval WLAN_STATUS_SUCCESS
2003 */
2004 /*----------------------------------------------------------------------------*/
2005 WLAN_STATUS
2006 wlanProcessCommandQueue (
2007     IN P_ADAPTER_T  prAdapter,
2008     IN P_QUE_T      prCmdQue
2009     )
2010 {
2011     WLAN_STATUS rStatus;
2012     QUE_T rTempCmdQue, rMergeCmdQue, rStandInCmdQue;
2013     P_QUE_T prTempCmdQue, prMergeCmdQue, prStandInCmdQue;
2014     P_QUE_ENTRY_T prQueueEntry;
2015     P_CMD_INFO_T prCmdInfo;
2016     P_MSDU_INFO_T prMsduInfo;
2017     ENUM_FRAME_ACTION_T eFrameAction = FRAME_ACTION_DROP_PKT;
2018
2019     KAL_SPIN_LOCK_DECLARATION();
2020
2021     ASSERT(prAdapter);
2022     ASSERT(prCmdQue);
2023
2024     prTempCmdQue = &rTempCmdQue;
2025     prMergeCmdQue = &rMergeCmdQue;
2026     prStandInCmdQue = &rStandInCmdQue;
2027
2028     QUEUE_INITIALIZE(prTempCmdQue);
2029     QUEUE_INITIALIZE(prMergeCmdQue);
2030     QUEUE_INITIALIZE(prStandInCmdQue);
2031
2032     //4 <1> Move whole list of CMD_INFO to temp queue
2033     KAL_ACQUIRE_SPIN_LOCK(prAdapter, SPIN_LOCK_CMD_QUE);
2034     QUEUE_MOVE_ALL(prTempCmdQue, prCmdQue);
2035     KAL_RELEASE_SPIN_LOCK(prAdapter, SPIN_LOCK_CMD_QUE);
2036
2037     //4 <2> Dequeue from head and check it is able to be sent
2038     QUEUE_REMOVE_HEAD(prTempCmdQue, prQueueEntry, P_QUE_ENTRY_T);
2039     while(prQueueEntry) {
2040         prCmdInfo = (P_CMD_INFO_T)prQueueEntry;
2041
2042         switch(prCmdInfo->eCmdType) {
2043         case COMMAND_TYPE_GENERAL_IOCTL:
2044         case COMMAND_TYPE_NETWORK_IOCTL:
2045             /* command packet will be always sent */
2046             eFrameAction = FRAME_ACTION_TX_PKT;
2047             break;
2048
2049         case COMMAND_TYPE_SECURITY_FRAME:
2050             /* inquire with QM */
2051             eFrameAction = qmGetFrameAction(prAdapter,
2052                     prCmdInfo->eNetworkType,
2053                     prCmdInfo->ucStaRecIndex,
2054                     NULL,
2055                     FRAME_TYPE_802_1X);
2056             break;
2057
2058         case COMMAND_TYPE_MANAGEMENT_FRAME:
2059             /* inquire with QM */
2060             prMsduInfo = (P_MSDU_INFO_T)(prCmdInfo->prPacket);
2061
2062             eFrameAction = qmGetFrameAction(prAdapter,
2063                     prMsduInfo->ucNetworkType,
2064                     prMsduInfo->ucStaRecIndex,
2065                     prMsduInfo,
2066                     FRAME_TYPE_MMPDU);
2067             break;
2068
2069         default:
2070             ASSERT(0);
2071             break;
2072         }
2073
2074         //4 <3> handling upon dequeue result
2075         if(eFrameAction == FRAME_ACTION_DROP_PKT) {
2076             wlanReleaseCommand(prAdapter, prCmdInfo);
2077         }
2078         else if(eFrameAction == FRAME_ACTION_QUEUE_PKT) {
2079             QUEUE_INSERT_TAIL(prMergeCmdQue, prQueueEntry);
2080         }
2081         else if(eFrameAction == FRAME_ACTION_TX_PKT) {
2082             //4 <4> Send the command
2083             rStatus = wlanSendCommand(prAdapter, prCmdInfo);
2084
2085             if(rStatus == WLAN_STATUS_RESOURCES) {
2086                 // no more TC4 resource for further transmission
2087                 QUEUE_INSERT_TAIL(prMergeCmdQue, prQueueEntry);
2088                 break;
2089             }
2090             else if(rStatus == WLAN_STATUS_PENDING) {
2091                 // command packet which needs further handling upon response
2092                 KAL_ACQUIRE_SPIN_LOCK(prAdapter, SPIN_LOCK_CMD_PENDING);
2093                 QUEUE_INSERT_TAIL(&(prAdapter->rPendingCmdQueue), prQueueEntry);
2094                 KAL_RELEASE_SPIN_LOCK(prAdapter, SPIN_LOCK_CMD_PENDING);
2095             }
2096             else {
2097                 P_CMD_INFO_T prCmdInfo = (P_CMD_INFO_T)prQueueEntry;
2098
2099                 if (rStatus == WLAN_STATUS_SUCCESS) {
2100                     if (prCmdInfo->pfCmdDoneHandler) {
2101                         prCmdInfo->pfCmdDoneHandler(prAdapter, prCmdInfo, prCmdInfo->pucInfoBuffer);
2102                     }
2103                 }
2104                 else {
2105                     if (prCmdInfo->fgIsOid) {
2106                         kalOidComplete(prAdapter->prGlueInfo, prCmdInfo->fgSetQuery, prCmdInfo->u4SetInfoLen, rStatus);
2107                     }
2108                 }
2109
2110                 cmdBufFreeCmdInfo(prAdapter, prCmdInfo);
2111             }
2112         }
2113         else {
2114             ASSERT(0);
2115         }
2116
2117         QUEUE_REMOVE_HEAD(prTempCmdQue, prQueueEntry, P_QUE_ENTRY_T);
2118     }
2119
2120     //4 <3> Merge back to original queue
2121     //4 <3.1> Merge prMergeCmdQue & prTempCmdQue
2122     QUEUE_CONCATENATE_QUEUES(prMergeCmdQue, prTempCmdQue);
2123
2124     //4 <3.2> Move prCmdQue to prStandInQue, due to prCmdQue might differ due to incoming 802.1X frames
2125     KAL_ACQUIRE_SPIN_LOCK(prAdapter, SPIN_LOCK_CMD_QUE);
2126     QUEUE_MOVE_ALL(prStandInCmdQue, prCmdQue);
2127
2128     //4 <3.3> concatenate prStandInQue to prMergeCmdQue
2129     QUEUE_CONCATENATE_QUEUES(prMergeCmdQue, prStandInCmdQue);
2130
2131     //4 <3.4> then move prMergeCmdQue to prCmdQue
2132     QUEUE_MOVE_ALL(prCmdQue, prMergeCmdQue);
2133     KAL_RELEASE_SPIN_LOCK(prAdapter, SPIN_LOCK_CMD_QUE);
2134
2135     return WLAN_STATUS_SUCCESS;
2136 } /* end of wlanProcessCommandQueue() */
2137
2138
2139 /*----------------------------------------------------------------------------*/
2140 /*!
2141 * \brief This function will take CMD_INFO_T which carry some informations of
2142 *        incoming OID and notify the NIC_TX to send CMD.
2143 *
2144 * \param prAdapter      Pointer of Adapter Data Structure
2145 * \param prCmdInfo      Pointer of P_CMD_INFO_T
2146 *
2147 * \retval WLAN_STATUS_SUCCESS   : CMD was written to HIF and be freed(CMD Done) immediately.
2148 * \retval WLAN_STATUS_RESOURCE  : No resource for current command, need to wait for previous
2149 *                                 frame finishing their transmission.
2150 * \retval WLAN_STATUS_FAILURE   : Get failure while access HIF or been rejected.
2151 */
2152 /*----------------------------------------------------------------------------*/
2153 WLAN_STATUS
2154 wlanSendCommand (
2155     IN P_ADAPTER_T  prAdapter,
2156     IN P_CMD_INFO_T prCmdInfo
2157     )
2158 {
2159     P_TX_CTRL_T prTxCtrl;
2160     UINT_8 ucTC; /* "Traffic Class" SW(Driver) resource classification */
2161     WLAN_STATUS rStatus = WLAN_STATUS_SUCCESS;
2162
2163     ASSERT(prAdapter);
2164     ASSERT(prCmdInfo);
2165     prTxCtrl = &prAdapter->rTxCtrl;
2166
2167     //DbgPrint("wlanSendCommand()\n");
2168     //
2169     //
2170 #if DBG && 0
2171     LOG_FUNC("wlanSendCommand()\n");
2172     LOG_FUNC("CmdType %u NetworkType %u StaRecIndex %u Oid %u CID 0x%x SetQuery %u NeedResp %u CmdSeqNum %u\n",
2173             prCmdInfo->eCmdType,
2174             prCmdInfo->eNetworkType,
2175             prCmdInfo->ucStaRecIndex,
2176             prCmdInfo->fgIsOid,
2177             prCmdInfo->ucCID,
2178             prCmdInfo->fgSetQuery,
2179             prCmdInfo->fgNeedResp,
2180             prCmdInfo->ucCmdSeqNum);
2181 #endif
2182
2183 #if (MT6620_E1_ASIC_HIFSYS_WORKAROUND == 1)
2184     if(prAdapter->fgIsClockGatingEnabled == TRUE) {
2185         nicDisableClockGating(prAdapter);
2186     }
2187 #endif
2188
2189     do {
2190         // <0> card removal check
2191         if(kalIsCardRemoved(prAdapter->prGlueInfo) == TRUE
2192                 || fgIsBusAccessFailed == TRUE) {
2193             rStatus = WLAN_STATUS_FAILURE;
2194             break;
2195         }
2196
2197         // <1> Normal case of sending CMD Packet
2198         if (!prCmdInfo->fgDriverDomainMCR) {
2199             // <1.1> Assign Traffic Class(TC) = TC4.
2200             ucTC = TC4_INDEX;
2201
2202             // <1.2> Check if pending packet or resource was exhausted
2203             if ((rStatus = nicTxAcquireResource(prAdapter, ucTC)) == WLAN_STATUS_RESOURCES) {
2204                 DbgPrint("NO Resource:%d\n", ucTC);
2205                 break;
2206             }
2207
2208             // <1.3> Forward CMD_INFO_T to NIC Layer
2209             rStatus = nicTxCmd(prAdapter, prCmdInfo, ucTC);
2210
2211             // <1.4> Set Pending in response to Query Command/Need Response
2212             if (rStatus == WLAN_STATUS_SUCCESS) {
2213                 if ((!prCmdInfo->fgSetQuery) || (prCmdInfo->fgNeedResp)) {
2214                     rStatus = WLAN_STATUS_PENDING;
2215                 }
2216             }
2217         }
2218         // <2> Special case for access Driver Domain MCR
2219         else {
2220             P_CMD_ACCESS_REG prCmdAccessReg;
2221             prCmdAccessReg = (P_CMD_ACCESS_REG)(prCmdInfo->pucInfoBuffer + CMD_HDR_SIZE);
2222
2223             if (prCmdInfo->fgSetQuery) {
2224                 HAL_MCR_WR(prAdapter,
2225                         (prCmdAccessReg->u4Address & BITS(2,31)), //address is in DWORD unit
2226                         prCmdAccessReg->u4Data);
2227             }
2228             else {
2229                 P_CMD_ACCESS_REG prEventAccessReg;
2230                 UINT_32 u4Address;
2231
2232                 u4Address = prCmdAccessReg->u4Address;
2233                 prEventAccessReg = (P_CMD_ACCESS_REG)prCmdInfo->pucInfoBuffer;
2234                 prEventAccessReg->u4Address = u4Address;
2235
2236                 HAL_MCR_RD(prAdapter,
2237                        prEventAccessReg->u4Address & BITS(2,31), //address is in DWORD unit
2238                        &prEventAccessReg->u4Data);
2239             }
2240         }
2241
2242     }
2243     while (FALSE);
2244
2245 #if (MT6620_E1_ASIC_HIFSYS_WORKAROUND == 1)
2246     if(prAdapter->fgIsClockGatingEnabled == FALSE) {
2247         nicEnableClockGating(prAdapter);
2248     }
2249 #endif
2250
2251     return rStatus;
2252 } /* end of wlanSendCommand() */
2253
2254
2255 /*----------------------------------------------------------------------------*/
2256 /*!
2257  * \brief This function will release thd CMD_INFO upon its attribution
2258  *
2259  * \param prAdapter  Pointer of Adapter Data Structure
2260  * \param prCmdInfo  Pointer of CMD_INFO_T
2261  *
2262  * \return (none)
2263  */
2264 /*----------------------------------------------------------------------------*/
2265 VOID
2266 wlanReleaseCommand (
2267     IN P_ADAPTER_T  prAdapter,
2268     IN P_CMD_INFO_T prCmdInfo
2269     )
2270 {
2271     P_TX_CTRL_T prTxCtrl;
2272     P_MSDU_INFO_T prMsduInfo;
2273
2274     ASSERT(prAdapter);
2275     ASSERT(prCmdInfo);
2276
2277     prTxCtrl = &prAdapter->rTxCtrl;
2278
2279     switch(prCmdInfo->eCmdType) {
2280     case COMMAND_TYPE_GENERAL_IOCTL:
2281     case COMMAND_TYPE_NETWORK_IOCTL:
2282         if (prCmdInfo->fgIsOid) {
2283             kalOidComplete(prAdapter->prGlueInfo,
2284                     prCmdInfo->fgSetQuery,
2285                     prCmdInfo->u4SetInfoLen,
2286                     WLAN_STATUS_FAILURE);
2287         }
2288         break;
2289
2290     case COMMAND_TYPE_SECURITY_FRAME:
2291         kalSecurityFrameSendComplete(prAdapter->prGlueInfo,
2292                 prCmdInfo->prPacket,
2293                 WLAN_STATUS_FAILURE);
2294         break;
2295
2296     case COMMAND_TYPE_MANAGEMENT_FRAME:
2297         prMsduInfo = (P_MSDU_INFO_T)prCmdInfo->prPacket;
2298
2299         /* invoke callbacks */
2300         if(prMsduInfo->pfTxDoneHandler != NULL) {
2301             prMsduInfo->pfTxDoneHandler(prAdapter, prMsduInfo, TX_RESULT_DROPPED_IN_DRIVER);
2302         }
2303
2304         GLUE_DEC_REF_CNT(prTxCtrl->i4TxMgmtPendingNum);
2305         cnmMgtPktFree(prAdapter, prMsduInfo);
2306         break;
2307
2308     default:
2309         ASSERT(0);
2310         break;
2311     }
2312
2313     cmdBufFreeCmdInfo(prAdapter, prCmdInfo);
2314
2315 } /* end of wlanReleaseCommand() */
2316
2317
2318 /*----------------------------------------------------------------------------*/
2319 /*!
2320 * \brief This function will search the CMD Queue to look for the pending OID and
2321 *        compelete it immediately when system request a reset.
2322 *
2323 * \param prAdapter  ointer of Adapter Data Structure
2324 *
2325 * \return (none)
2326 */
2327 /*----------------------------------------------------------------------------*/
2328 VOID
2329 wlanReleasePendingOid (
2330     IN P_ADAPTER_T  prAdapter,
2331     IN UINT_32      u4Data
2332     )
2333 {
2334     P_QUE_T prCmdQue;
2335     QUE_T rTempCmdQue;
2336     P_QUE_T prTempCmdQue = &rTempCmdQue;
2337     P_QUE_ENTRY_T prQueueEntry = (P_QUE_ENTRY_T)NULL;
2338     P_CMD_INFO_T prCmdInfo = (P_CMD_INFO_T)NULL;
2339
2340     KAL_SPIN_LOCK_DECLARATION();
2341
2342     DEBUGFUNC("wlanReleasePendingOid");
2343
2344     ASSERT(prAdapter);
2345
2346     DBGLOG(INIT, ERROR, ("OID Timeout! Releasing pending OIDs ..\n"));
2347
2348     do {
2349         // 1: Clear Pending OID in prAdapter->rPendingCmdQueue
2350         KAL_ACQUIRE_SPIN_LOCK(prAdapter, SPIN_LOCK_CMD_PENDING);
2351
2352         prCmdQue = &prAdapter->rPendingCmdQueue;
2353         QUEUE_MOVE_ALL(prTempCmdQue, prCmdQue);
2354
2355         QUEUE_REMOVE_HEAD(prTempCmdQue, prQueueEntry, P_QUE_ENTRY_T);
2356         while (prQueueEntry) {
2357             prCmdInfo = (P_CMD_INFO_T)prQueueEntry;
2358
2359             if (prCmdInfo->fgIsOid) {
2360                 if (prCmdInfo->pfCmdTimeoutHandler) {
2361                     prCmdInfo->pfCmdTimeoutHandler(prAdapter, prCmdInfo);
2362                 }
2363                 else
2364                     kalOidComplete(prAdapter->prGlueInfo,
2365                             prCmdInfo->fgSetQuery,
2366                             0,
2367                             WLAN_STATUS_FAILURE);
2368
2369                 cmdBufFreeCmdInfo(prAdapter, prCmdInfo);
2370             }
2371             else {
2372                 QUEUE_INSERT_TAIL(prCmdQue, prQueueEntry);
2373             }
2374
2375             QUEUE_REMOVE_HEAD(prTempCmdQue, prQueueEntry, P_QUE_ENTRY_T);
2376         }
2377
2378         KAL_RELEASE_SPIN_LOCK(prAdapter, SPIN_LOCK_CMD_PENDING);
2379
2380         // 2: Clear pending OID in glue layer command queue
2381         kalOidCmdClearance(prAdapter->prGlueInfo);
2382
2383         // 3: Clear pending OID queued in pvOidEntry with REQ_FLAG_OID set
2384         kalOidClearance(prAdapter->prGlueInfo);
2385
2386     } while(FALSE);
2387
2388     return;
2389 }
2390
2391
2392 /*----------------------------------------------------------------------------*/
2393 /*!
2394 * \brief This function will search the CMD Queue to look for the pending CMD/OID for specific
2395 *        NETWORK TYPE and compelete it immediately when system request a reset.
2396 *
2397 * \param prAdapter  ointer of Adapter Data Structure
2398 *
2399 * \return (none)
2400 */
2401 /*----------------------------------------------------------------------------*/
2402 VOID
2403 wlanReleasePendingCMDbyNetwork (
2404     IN P_ADAPTER_T  prAdapter,
2405     IN ENUM_NETWORK_TYPE_INDEX_T eNetworkType
2406     )
2407 {
2408     P_QUE_T prCmdQue;
2409     QUE_T rTempCmdQue;
2410     P_QUE_T prTempCmdQue = &rTempCmdQue;
2411     P_QUE_ENTRY_T prQueueEntry = (P_QUE_ENTRY_T)NULL;
2412     P_CMD_INFO_T prCmdInfo = (P_CMD_INFO_T)NULL;
2413
2414     KAL_SPIN_LOCK_DECLARATION();
2415
2416     ASSERT(prAdapter);
2417
2418     do {
2419         // 1: Clear Pending OID in prAdapter->rPendingCmdQueue
2420         KAL_ACQUIRE_SPIN_LOCK(prAdapter, SPIN_LOCK_CMD_PENDING);
2421
2422         prCmdQue = &prAdapter->rPendingCmdQueue;
2423         QUEUE_MOVE_ALL(prTempCmdQue, prCmdQue);
2424
2425         QUEUE_REMOVE_HEAD(prTempCmdQue, prQueueEntry, P_QUE_ENTRY_T);
2426         while (prQueueEntry) {
2427             prCmdInfo = (P_CMD_INFO_T)prQueueEntry;
2428
2429             DBGLOG(P2P, TRACE, ("Pending CMD for Network Type:%d \n", prCmdInfo->eNetworkType));
2430
2431             if (prCmdInfo->eNetworkType == eNetworkType) {
2432                 if (prCmdInfo->pfCmdTimeoutHandler) {
2433                     prCmdInfo->pfCmdTimeoutHandler(prAdapter, prCmdInfo);
2434                 }
2435                 else
2436                     kalOidComplete(prAdapter->prGlueInfo,
2437                             prCmdInfo->fgSetQuery,
2438                             0,
2439                             WLAN_STATUS_FAILURE);
2440
2441                 cmdBufFreeCmdInfo(prAdapter, prCmdInfo);
2442             }
2443             else {
2444                 QUEUE_INSERT_TAIL(prCmdQue, prQueueEntry);
2445             }
2446
2447             QUEUE_REMOVE_HEAD(prTempCmdQue, prQueueEntry, P_QUE_ENTRY_T);
2448         }
2449
2450         KAL_RELEASE_SPIN_LOCK(prAdapter, SPIN_LOCK_CMD_PENDING);
2451
2452
2453     } while(FALSE);
2454
2455     return;
2456 } /* wlanReleasePendingCMDbyNetwork */
2457
2458
2459
2460 /*----------------------------------------------------------------------------*/
2461 /*!
2462 * \brief Return the packet buffer and reallocate one to the RFB
2463 *
2464 * \param prAdapter      Pointer of Adapter Data Structure
2465 * \param pvPacket       Pointer of returned packet
2466 *
2467 * \retval WLAN_STATUS_SUCCESS: Success
2468 * \retval WLAN_STATUS_FAILURE: Failed
2469 */
2470 /*----------------------------------------------------------------------------*/
2471 VOID
2472 wlanReturnPacket (
2473     IN P_ADAPTER_T prAdapter,
2474     IN PVOID pvPacket
2475     )
2476 {
2477     P_RX_CTRL_T prRxCtrl;
2478     P_SW_RFB_T prSwRfb = NULL;
2479     KAL_SPIN_LOCK_DECLARATION();
2480
2481     DEBUGFUNC("wlanReturnPacket");
2482
2483     ASSERT(prAdapter);
2484
2485     prRxCtrl = &prAdapter->rRxCtrl;
2486     ASSERT(prRxCtrl);
2487
2488     if (pvPacket) {
2489         kalPacketFree(prAdapter->prGlueInfo, pvPacket);
2490         RX_ADD_CNT(prRxCtrl, RX_DATA_RETURNED_COUNT, 1);
2491 #if CFG_NATIVE_802_11
2492         if (GLUE_TEST_FLAG(prAdapter->prGlueInfo, GLUE_FLAG_HALT)) {
2493         }
2494 #endif
2495     }
2496
2497     KAL_ACQUIRE_SPIN_LOCK(prAdapter, SPIN_LOCK_RX_QUE);
2498     QUEUE_REMOVE_HEAD(&prRxCtrl->rIndicatedRfbList, prSwRfb, P_SW_RFB_T);
2499     KAL_RELEASE_SPIN_LOCK(prAdapter, SPIN_LOCK_RX_QUE);
2500     if (!prSwRfb){
2501         ASSERT(0);
2502         return;
2503     }
2504
2505     if (nicRxSetupRFB(prAdapter, prSwRfb)){
2506         ASSERT(0);
2507         return;
2508     }
2509     nicRxReturnRFB(prAdapter, prSwRfb);
2510 }
2511
2512 /*----------------------------------------------------------------------------*/
2513 /*!
2514 * \brief This function is a required function that returns information about
2515 *        the capabilities and status of the driver and/or its network adapter.
2516 *
2517 * \param[IN] prAdapter        Pointer to the Adapter structure.
2518 * \param[IN] pfnOidQryHandler Function pointer for the OID query handler.
2519 * \param[IN] pvInfoBuf        Points to a buffer for return the query information.
2520 * \param[IN] u4QueryBufferLen Specifies the number of bytes at pvInfoBuf.
2521 * \param[OUT] pu4QueryInfoLen  Points to the number of bytes it written or is needed.
2522 *
2523 * \retval WLAN_STATUS_xxx Different WLAN_STATUS code returned by different handlers.
2524 *
2525 */
2526 /*----------------------------------------------------------------------------*/
2527 WLAN_STATUS
2528 wlanQueryInformation (
2529     IN P_ADAPTER_T          prAdapter,
2530     IN PFN_OID_HANDLER_FUNC pfnOidQryHandler,
2531     IN PVOID                pvInfoBuf,
2532     IN UINT_32              u4InfoBufLen,
2533     OUT PUINT_32            pu4QryInfoLen
2534     )
2535 {
2536     WLAN_STATUS status = WLAN_STATUS_FAILURE;
2537
2538     ASSERT(prAdapter);
2539     ASSERT(pu4QryInfoLen);
2540
2541     // ignore any OID request after connected, under PS current measurement mode
2542     if (prAdapter->u4PsCurrentMeasureEn &&
2543         (prAdapter->prGlueInfo->eParamMediaStateIndicated == PARAM_MEDIA_STATE_CONNECTED)) {
2544         return WLAN_STATUS_SUCCESS; // note: return WLAN_STATUS_FAILURE or WLAN_STATUS_SUCCESS for blocking OIDs during current measurement ??
2545     }
2546
2547 #if 1
2548     /* most OID handler will just queue a command packet */
2549     status = pfnOidQryHandler(prAdapter,
2550             pvInfoBuf,
2551             u4InfoBufLen,
2552             pu4QryInfoLen);
2553 #else
2554     if (wlanIsHandlerNeedHwAccess(pfnOidQryHandler, FALSE)) {
2555         ACQUIRE_POWER_CONTROL_FROM_PM(prAdapter);
2556
2557         /* Reset sleepy state */
2558         if(prAdapter->fgWiFiInSleepyState == TRUE) {
2559             prAdapter->fgWiFiInSleepyState = FALSE;
2560         }
2561
2562         status = pfnOidQryHandler(prAdapter,
2563                                     pvInfoBuf,
2564                                     u4InfoBufLen,
2565                                     pu4QryInfoLen);
2566
2567         RECLAIM_POWER_CONTROL_TO_PM(prAdapter, FALSE);
2568     }
2569     else {
2570         status = pfnOidQryHandler(prAdapter,
2571                                     pvInfoBuf,
2572                                     u4InfoBufLen,
2573                                     pu4QryInfoLen);
2574     }
2575 #endif
2576
2577     return status;
2578
2579 }
2580
2581 /*----------------------------------------------------------------------------*/
2582 /*!
2583 * \brief This function is a required function that allows bound protocol drivers,
2584 *        or NDIS, to request changes in the state information that the miniport
2585 *        maintains for particular object identifiers, such as changes in multicast
2586 *        addresses.
2587 *
2588 * \param[IN] prAdapter     Pointer to the Glue info structure.
2589 * \param[IN] pfnOidSetHandler     Points to the OID set handlers.
2590 * \param[IN] pvInfoBuf     Points to a buffer containing the OID-specific data for the set.
2591 * \param[IN] u4InfoBufLen  Specifies the number of bytes at prSetBuffer.
2592 * \param[OUT] pu4SetInfoLen Points to the number of bytes it read or is needed.
2593 *
2594 * \retval WLAN_STATUS_xxx Different WLAN_STATUS code returned by different handlers.
2595 *
2596 */
2597 /*----------------------------------------------------------------------------*/
2598 WLAN_STATUS
2599 wlanSetInformation (
2600     IN P_ADAPTER_T          prAdapter,
2601     IN PFN_OID_HANDLER_FUNC pfnOidSetHandler,
2602     IN PVOID                pvInfoBuf,
2603     IN UINT_32              u4InfoBufLen,
2604     OUT PUINT_32            pu4SetInfoLen
2605     )
2606 {
2607     WLAN_STATUS status = WLAN_STATUS_FAILURE;
2608
2609     ASSERT(prAdapter);
2610     ASSERT(pu4SetInfoLen);
2611
2612     // ignore any OID request after connected, under PS current measurement mode
2613     if (prAdapter->u4PsCurrentMeasureEn &&
2614         (prAdapter->prGlueInfo->eParamMediaStateIndicated == PARAM_MEDIA_STATE_CONNECTED)) {
2615         return WLAN_STATUS_SUCCESS; // note: return WLAN_STATUS_FAILURE or WLAN_STATUS_SUCCESS for blocking OIDs during current measurement ??
2616     }
2617
2618 #if 1
2619     /* most OID handler will just queue a command packet
2620      * for power state transition OIDs, handler will acquire power control by itself
2621      */
2622     status = pfnOidSetHandler(prAdapter,
2623             pvInfoBuf,
2624             u4InfoBufLen,
2625             pu4SetInfoLen);
2626 #else
2627     if (wlanIsHandlerNeedHwAccess(pfnOidSetHandler, TRUE)) {
2628         ACQUIRE_POWER_CONTROL_FROM_PM(prAdapter);
2629
2630         /* Reset sleepy state */
2631         if(prAdapter->fgWiFiInSleepyState == TRUE) {
2632             prAdapter->fgWiFiInSleepyState = FALSE;
2633         }
2634
2635         status = pfnOidSetHandler(prAdapter,
2636                                     pvInfoBuf,
2637                                     u4InfoBufLen,
2638                                     pu4SetInfoLen);
2639
2640         RECLAIM_POWER_CONTROL_TO_PM(prAdapter, FALSE);
2641     }
2642     else {
2643         status = pfnOidSetHandler(prAdapter,
2644                                     pvInfoBuf,
2645                                     u4InfoBufLen,
2646                                     pu4SetInfoLen);
2647     }
2648 #endif
2649
2650     return status;
2651 }
2652
2653
2654 #if CFG_SUPPORT_WAPI
2655 /*----------------------------------------------------------------------------*/
2656 /*!
2657 * \brief This function is a used to query driver's config wapi mode or not
2658 *
2659 * \param[IN] prAdapter     Pointer to the Glue info structure.
2660 *
2661 * \retval TRUE for use wapi mode
2662 *
2663 */
2664 /*----------------------------------------------------------------------------*/
2665 BOOLEAN
2666 wlanQueryWapiMode (
2667     IN P_ADAPTER_T          prAdapter
2668     )
2669 {
2670     ASSERT(prAdapter);
2671
2672     return prAdapter->rWifiVar.rConnSettings.fgWapiMode;
2673 }
2674 #endif
2675
2676
2677 /*----------------------------------------------------------------------------*/
2678 /*!
2679 * \brief This function is called to set RX filter to Promiscuous Mode.
2680 *
2681 * \param[IN] prAdapter        Pointer to the Adapter structure.
2682 * \param[IN] fgEnablePromiscuousMode Enable/ disable RX Promiscuous Mode.
2683 *
2684 * \return (none)
2685 */
2686 /*----------------------------------------------------------------------------*/
2687 VOID
2688 wlanSetPromiscuousMode (
2689     IN P_ADAPTER_T  prAdapter,
2690     IN BOOLEAN      fgEnablePromiscuousMode
2691     )
2692 {
2693     ASSERT(prAdapter);
2694
2695 }
2696
2697 /*----------------------------------------------------------------------------*/
2698 /*!
2699 * \brief This function is called to set RX filter to allow to receive
2700 *        broadcast address packets.
2701 *
2702 * \param[IN] prAdapter        Pointer to the Adapter structure.
2703 * \param[IN] fgEnableBroadcast Enable/ disable broadcast packet to be received.
2704 *
2705 * \return (none)
2706 */
2707 /*----------------------------------------------------------------------------*/
2708 VOID
2709 wlanRxSetBroadcast (
2710     IN P_ADAPTER_T  prAdapter,
2711     IN BOOLEAN      fgEnableBroadcast
2712     )
2713 {
2714     ASSERT(prAdapter);
2715 }
2716
2717 /*----------------------------------------------------------------------------*/
2718 /*!
2719 * \brief This function is called to send out CMD_NIC_POWER_CTRL command packet
2720 *
2721 * \param[IN] prAdapter        Pointer to the Adapter structure.
2722 * \param[IN] ucPowerMode      refer to CMD/EVENT document
2723 *
2724 * \return WLAN_STATUS_SUCCESS
2725 * \return WLAN_STATUS_FAILURE
2726 */
2727 /*----------------------------------------------------------------------------*/
2728 WLAN_STATUS
2729 wlanSendNicPowerCtrlCmd (
2730     IN P_ADAPTER_T  prAdapter,
2731     IN UINT_8       ucPowerMode
2732     )
2733 {
2734     WLAN_STATUS status = WLAN_STATUS_SUCCESS;
2735     P_GLUE_INFO_T prGlueInfo;
2736     P_CMD_INFO_T prCmdInfo;
2737     P_WIFI_CMD_T prWifiCmd;
2738     UINT_8 ucTC, ucCmdSeqNum;
2739
2740     ASSERT(prAdapter);
2741
2742     prGlueInfo = prAdapter->prGlueInfo;
2743
2744     /* 1. Prepare CMD */
2745     prCmdInfo = cmdBufAllocateCmdInfo(prAdapter, (CMD_HDR_SIZE + sizeof(CMD_NIC_POWER_CTRL)));
2746     if (!prCmdInfo) {
2747         DBGLOG(INIT, ERROR, ("Allocate CMD_INFO_T ==> FAILED.\n"));
2748         return WLAN_STATUS_FAILURE;
2749     }
2750
2751     /* 2.1 increase command sequence number */
2752     ucCmdSeqNum = nicIncreaseCmdSeqNum(prAdapter);
2753     DBGLOG(REQ, TRACE, ("ucCmdSeqNum =%d\n", ucCmdSeqNum));
2754
2755     /* 2.2 Setup common CMD Info Packet */
2756     prCmdInfo->eCmdType = COMMAND_TYPE_GENERAL_IOCTL;
2757     prCmdInfo->u2InfoBufLen = (UINT_16)(CMD_HDR_SIZE + sizeof(CMD_NIC_POWER_CTRL));
2758     prCmdInfo->pfCmdDoneHandler = NULL;
2759     prCmdInfo->pfCmdTimeoutHandler = NULL;
2760     prCmdInfo->fgIsOid = TRUE;
2761     prCmdInfo->ucCID = CMD_ID_NIC_POWER_CTRL;
2762     prCmdInfo->fgSetQuery = TRUE;
2763     prCmdInfo->fgNeedResp = FALSE;
2764     prCmdInfo->fgDriverDomainMCR = FALSE;
2765     prCmdInfo->ucCmdSeqNum = ucCmdSeqNum;
2766     prCmdInfo->u4SetInfoLen = sizeof(CMD_NIC_POWER_CTRL);
2767
2768     /* 2.3 Setup WIFI_CMD_T */
2769     prWifiCmd = (P_WIFI_CMD_T)(prCmdInfo->pucInfoBuffer);
2770     prWifiCmd->u2TxByteCount_UserPriority = prCmdInfo->u2InfoBufLen;
2771     prWifiCmd->ucCID = prCmdInfo->ucCID;
2772     prWifiCmd->ucSetQuery = prCmdInfo->fgSetQuery;
2773     prWifiCmd->ucSeqNum = prCmdInfo->ucCmdSeqNum;
2774
2775     kalMemZero(prWifiCmd->aucBuffer, sizeof(CMD_NIC_POWER_CTRL));
2776     ((P_CMD_NIC_POWER_CTRL)(prWifiCmd->aucBuffer))->ucPowerMode = ucPowerMode;
2777
2778     /* 3. Issue CMD for entering specific power mode */
2779     ucTC = TC4_INDEX;
2780
2781     while(1) {
2782         // 3.0 Removal check
2783         if(kalIsCardRemoved(prAdapter->prGlueInfo) == TRUE
2784                 || fgIsBusAccessFailed == TRUE) {
2785             status = WLAN_STATUS_FAILURE;
2786             break;
2787         }
2788
2789         // 3.1 Acquire TX Resource
2790         if (nicTxAcquireResource(prAdapter, ucTC) == WLAN_STATUS_RESOURCES) {
2791             if (nicTxPollingResource(prAdapter, ucTC) != WLAN_STATUS_SUCCESS) {
2792                 DBGLOG(INIT, ERROR,("Fail to get TX resource return within timeout\n"));
2793                 status = WLAN_STATUS_FAILURE;
2794                 break;
2795             }
2796             else {
2797                 continue;
2798             }
2799         }
2800
2801         // 3.2 Send CMD Info Packet
2802         if (nicTxCmd(prAdapter, prCmdInfo, ucTC) != WLAN_STATUS_SUCCESS) {
2803             DBGLOG(INIT, ERROR,("Fail to transmit CMD_NIC_POWER_CTRL command\n"));
2804             status = WLAN_STATUS_FAILURE;
2805         }
2806
2807         break;
2808     };
2809
2810     // 4. Free CMD Info Packet.
2811     cmdBufFreeCmdInfo(prAdapter, prCmdInfo);
2812
2813     // 5. Add flag
2814     if(ucPowerMode == 1) {
2815         prAdapter->fgIsEnterD3ReqIssued = TRUE;
2816     }
2817
2818     return status;
2819 }
2820
2821
2822 /*----------------------------------------------------------------------------*/
2823 /*!
2824 * \brief This function is called to check if it is RF test mode and
2825 *        the OID is allowed to be called or not
2826 *
2827 * \param[IN] prAdapter        Pointer to the Adapter structure.
2828 * \param[IN] fgEnableBroadcast Enable/ disable broadcast packet to be received.
2829 *
2830 * \return (none)
2831 */
2832 /*----------------------------------------------------------------------------*/
2833 BOOLEAN
2834 wlanIsHandlerAllowedInRFTest (
2835     IN PFN_OID_HANDLER_FUNC pfnOidHandler,
2836     IN BOOLEAN              fgSetInfo
2837     )
2838 {
2839     PFN_OID_HANDLER_FUNC* apfnOidHandlerAllowedInRFTest;
2840     UINT_32 i;
2841     UINT_32 u4NumOfElem;
2842
2843     if (fgSetInfo) {
2844         apfnOidHandlerAllowedInRFTest = apfnOidSetHandlerAllowedInRFTest;
2845         u4NumOfElem = sizeof(apfnOidSetHandlerAllowedInRFTest) / sizeof(PFN_OID_HANDLER_FUNC);
2846     }
2847     else {
2848         apfnOidHandlerAllowedInRFTest = apfnOidQueryHandlerAllowedInRFTest;
2849         u4NumOfElem = sizeof(apfnOidQueryHandlerAllowedInRFTest) / sizeof(PFN_OID_HANDLER_FUNC);
2850     }
2851
2852     for (i = 0; i < u4NumOfElem; i++) {
2853         if (apfnOidHandlerAllowedInRFTest[i] == pfnOidHandler) {
2854             return TRUE;
2855         }
2856     }
2857
2858     return FALSE;
2859 }
2860
2861 #if CFG_ENABLE_FW_DOWNLOAD
2862     #if CFG_ENABLE_FW_DOWNLOAD_AGGREGATION
2863 /*----------------------------------------------------------------------------*/
2864 /*!
2865 * @brief This function is called to download FW image in an aggregated way
2866 *
2867 * @param prAdapter      Pointer to the Adapter structure.
2868 *
2869 * @return (none)
2870 */
2871 /*----------------------------------------------------------------------------*/
2872 WLAN_STATUS
2873 wlanImageSectionDownloadAggregated (
2874     IN P_ADAPTER_T  prAdapter,
2875     IN UINT_32      u4DestAddr,
2876     IN UINT_32      u4ImgSecSize,
2877     IN PUINT_8      pucImgSecBuf
2878     )
2879 {
2880         #if defined(MT6620) || defined(MT6628)
2881     P_CMD_INFO_T prCmdInfo;
2882     P_INIT_HIF_TX_HEADER_T prInitHifTxHeader;
2883     P_INIT_CMD_DOWNLOAD_BUF prInitCmdDownloadBuf;
2884     UINT_8 ucTC, ucCmdSeqNum;
2885     WLAN_STATUS u4Status = WLAN_STATUS_SUCCESS;
2886     PUINT_8 pucOutputBuf = (PUINT_8)NULL; /* Pointer to Transmit Data Structure Frame */
2887     UINT_32 u4PktCnt, u4Offset, u4Length;
2888     UINT_32 u4TotalLength;
2889
2890     ASSERT(prAdapter);
2891     ASSERT(pucImgSecBuf);
2892
2893     pucOutputBuf = prAdapter->rTxCtrl.pucTxCoalescingBufPtr;
2894
2895     DEBUGFUNC("wlanImageSectionDownloadAggregated");
2896
2897     if (u4ImgSecSize == 0) {
2898         return WLAN_STATUS_SUCCESS;
2899     }
2900
2901     // 1. Allocate CMD Info Packet and Pre-fill Headers
2902     prCmdInfo = cmdBufAllocateCmdInfo(prAdapter,
2903             sizeof(INIT_HIF_TX_HEADER_T) + sizeof(INIT_CMD_DOWNLOAD_BUF) + CMD_PKT_SIZE_FOR_IMAGE);
2904
2905     if (!prCmdInfo) {
2906         DBGLOG(INIT, ERROR, ("Allocate CMD_INFO_T ==> FAILED.\n"));
2907         return WLAN_STATUS_FAILURE;
2908     }
2909
2910     prCmdInfo->u2InfoBufLen =
2911         sizeof(INIT_HIF_TX_HEADER_T) + sizeof(INIT_CMD_DOWNLOAD_BUF) + CMD_PKT_SIZE_FOR_IMAGE;
2912
2913     // 2. Use TC0's resource to download image. (only TC0 is allowed)
2914     ucTC = TC0_INDEX;
2915
2916     // 3. Setup common CMD Info Packet
2917     prInitHifTxHeader = (P_INIT_HIF_TX_HEADER_T)(prCmdInfo->pucInfoBuffer);
2918     prInitHifTxHeader->ucEtherTypeOffset = 0;
2919     prInitHifTxHeader->ucCSflags = 0;
2920     prInitHifTxHeader->rInitWifiCmd.ucCID = INIT_CMD_ID_DOWNLOAD_BUF;
2921
2922     // 4. Setup CMD_DOWNLOAD_BUF
2923     prInitCmdDownloadBuf = (P_INIT_CMD_DOWNLOAD_BUF)(prInitHifTxHeader->rInitWifiCmd.aucBuffer);
2924     prInitCmdDownloadBuf->u4DataMode = 0
2925         #if CFG_ENABLE_FW_ENCRYPTION
2926         | DOWNLOAD_BUF_ENCRYPTION_MODE
2927         #endif
2928         ;
2929
2930     // 5.0 reset loop control variable
2931     u4TotalLength = 0;
2932     u4Offset = u4PktCnt = 0;
2933
2934     // 5.1 main loop for maximize transmission count per access
2935     while(u4Offset < u4ImgSecSize) {
2936         if(nicTxAcquireResource(prAdapter, ucTC) == WLAN_STATUS_SUCCESS) {
2937             // 5.1.1 calculate u4Length
2938             if(u4Offset + CMD_PKT_SIZE_FOR_IMAGE < u4ImgSecSize) {
2939                 u4Length = CMD_PKT_SIZE_FOR_IMAGE;
2940             }
2941             else {
2942                 u4Length = u4ImgSecSize - u4Offset;
2943             }
2944
2945             // 5.1.1 increase command sequence number
2946             ucCmdSeqNum = nicIncreaseCmdSeqNum(prAdapter);
2947             prInitHifTxHeader->rInitWifiCmd.ucSeqNum = ucCmdSeqNum;
2948
2949             // 5.1.2 update HIF TX hardware header
2950             prInitHifTxHeader->u2TxByteCount = ALIGN_4(sizeof(INIT_HIF_TX_HEADER_T) + sizeof(INIT_CMD_DOWNLOAD_BUF) + (UINT_16)u4Length);
2951
2952             // 5.1.3 fill command header
2953             prInitCmdDownloadBuf->u4Address = u4DestAddr + u4Offset;
2954             prInitCmdDownloadBuf->u4Length = u4Length;
2955             prInitCmdDownloadBuf->u4CRC32 = wlanCRC32(pucImgSecBuf + u4Offset, u4Length);
2956
2957             // 5.1.4.1 copy header to coalescing buffer
2958             kalMemCopy(pucOutputBuf + u4TotalLength,
2959                     (PVOID)prCmdInfo->pucInfoBuffer,
2960                     sizeof(INIT_HIF_TX_HEADER_T) + sizeof(INIT_CMD_DOWNLOAD_BUF));
2961
2962             // 5.1.4.2 copy payload to coalescing buffer
2963             kalMemCopy(pucOutputBuf + u4TotalLength + sizeof(INIT_HIF_TX_HEADER_T) + sizeof(INIT_CMD_DOWNLOAD_BUF),
2964                     pucImgSecBuf + u4Offset,
2965                     u4Length);
2966
2967             // 5.1.4.3 update length and other variables
2968             u4TotalLength += ALIGN_4(sizeof(INIT_HIF_TX_HEADER_T) + sizeof(INIT_CMD_DOWNLOAD_BUF) + u4Length);
2969             u4Offset += u4Length;
2970             u4PktCnt++;
2971
2972             if(u4Offset < u4ImgSecSize) {
2973                 continue;
2974             }
2975         }
2976         else if(u4PktCnt == 0) {
2977             /* no resource, so get some back */
2978             if (nicTxPollingResource(prAdapter, ucTC) != WLAN_STATUS_SUCCESS) {
2979                 u4Status = WLAN_STATUS_FAILURE;
2980                 DBGLOG(INIT, ERROR,("Fail to get TX resource return within timeout\n"));
2981                 break;
2982             }
2983         }
2984
2985         if(u4PktCnt != 0) {
2986             // start transmission
2987             HAL_WRITE_TX_PORT(prAdapter,
2988                     0,
2989                     u4TotalLength,
2990                     (PUINT_8)pucOutputBuf,
2991                     prAdapter->u4CoalescingBufCachedSize);
2992
2993             // reset varaibles
2994             u4PktCnt = 0;
2995             u4TotalLength = 0;
2996         }
2997     }
2998
2999     // 8. Free CMD Info Packet.
3000     cmdBufFreeCmdInfo(prAdapter, prCmdInfo);
3001
3002     return u4Status;
3003
3004         #else
3005         #error "Only MT6620/MT6628 supports firmware download in an aggregated way"
3006
3007     return WLAN_STATUS_FAILURE;
3008
3009         #endif
3010 }
3011
3012     #endif
3013 /*----------------------------------------------------------------------------*/
3014 /*!
3015 * @brief This function is called to download FW image.
3016 *
3017 * @param prAdapter      Pointer to the Adapter structure.
3018 *
3019 * @return (none)
3020 */
3021 /*----------------------------------------------------------------------------*/
3022 WLAN_STATUS
3023 wlanImageSectionDownload (
3024     IN P_ADAPTER_T  prAdapter,
3025     IN UINT_32      u4DestAddr,
3026     IN UINT_32      u4ImgSecSize,
3027     IN PUINT_8      pucImgSecBuf
3028     )
3029 {
3030     #if defined(MT6620) || defined(MT6628)
3031
3032     P_CMD_INFO_T prCmdInfo;
3033     P_INIT_HIF_TX_HEADER_T prInitHifTxHeader;
3034     P_INIT_CMD_DOWNLOAD_BUF prInitCmdDownloadBuf;
3035     UINT_8 ucTC, ucCmdSeqNum;
3036     WLAN_STATUS u4Status = WLAN_STATUS_SUCCESS;
3037
3038     ASSERT(prAdapter);
3039     ASSERT(pucImgSecBuf);
3040     ASSERT(u4ImgSecSize <= CMD_PKT_SIZE_FOR_IMAGE);
3041
3042     DEBUGFUNC("wlanImageSectionDownload");
3043
3044     if (u4ImgSecSize == 0) {
3045         return WLAN_STATUS_SUCCESS;
3046     }
3047
3048     // 1. Allocate CMD Info Packet and its Buffer.
3049     prCmdInfo = cmdBufAllocateCmdInfo(prAdapter,
3050             sizeof(INIT_HIF_TX_HEADER_T) + sizeof(INIT_CMD_DOWNLOAD_BUF) + u4ImgSecSize);
3051
3052     if (!prCmdInfo) {
3053         DBGLOG(INIT, ERROR, ("Allocate CMD_INFO_T ==> FAILED.\n"));
3054         return WLAN_STATUS_FAILURE;
3055     }
3056
3057     prCmdInfo->u2InfoBufLen =
3058         sizeof(INIT_HIF_TX_HEADER_T) + sizeof(INIT_CMD_DOWNLOAD_BUF) + (UINT_16)u4ImgSecSize;
3059
3060     // 2. Use TC0's resource to download image. (only TC0 is allowed)
3061     ucTC = TC0_INDEX;
3062
3063     // 3. increase command sequence number
3064     ucCmdSeqNum = nicIncreaseCmdSeqNum(prAdapter);
3065
3066     // 4. Setup common CMD Info Packet
3067     prInitHifTxHeader = (P_INIT_HIF_TX_HEADER_T)(prCmdInfo->pucInfoBuffer);
3068     prInitHifTxHeader->rInitWifiCmd.ucCID = INIT_CMD_ID_DOWNLOAD_BUF;
3069     prInitHifTxHeader->rInitWifiCmd.ucSeqNum = ucCmdSeqNum;
3070
3071     // 5. Setup CMD_DOWNLOAD_BUF
3072     prInitCmdDownloadBuf = (P_INIT_CMD_DOWNLOAD_BUF)(prInitHifTxHeader->rInitWifiCmd.aucBuffer);
3073     prInitCmdDownloadBuf->u4Address = u4DestAddr;
3074     prInitCmdDownloadBuf->u4Length = u4ImgSecSize;
3075     prInitCmdDownloadBuf->u4CRC32 = wlanCRC32(pucImgSecBuf, u4ImgSecSize);
3076     prInitCmdDownloadBuf->u4DataMode = 0
3077         #if CFG_ENABLE_FW_DOWNLOAD_ACK
3078         | DOWNLOAD_BUF_ACK_OPTION // ACK needed
3079         #endif
3080         #if CFG_ENABLE_FW_ENCRYPTION
3081         | DOWNLOAD_BUF_ENCRYPTION_MODE
3082         #endif
3083         ;
3084     kalMemCopy(prInitCmdDownloadBuf->aucBuffer, pucImgSecBuf, u4ImgSecSize);
3085
3086     // 6. Send FW_Download command
3087     while(1) {
3088         // 6.1 Acquire TX Resource
3089         if (nicTxAcquireResource(prAdapter, ucTC) == WLAN_STATUS_RESOURCES) {
3090             if (nicTxPollingResource(prAdapter, ucTC) != WLAN_STATUS_SUCCESS) {
3091                 u4Status = WLAN_STATUS_FAILURE;
3092                 DBGLOG(INIT, ERROR,("Fail to get TX resource return within timeout\n"));
3093                 break;
3094             }
3095             else {
3096                 continue;
3097             }
3098         }
3099
3100         // 6.2 Send CMD Info Packet
3101         if (nicTxInitCmd(prAdapter, prCmdInfo, ucTC) != WLAN_STATUS_SUCCESS) {
3102             u4Status = WLAN_STATUS_FAILURE;
3103             DBGLOG(INIT, ERROR,("Fail to transmit image download command\n"));
3104         }
3105
3106         break;
3107     };
3108
3109         #if CFG_ENABLE_FW_DOWNLOAD_ACK
3110     // 7. Wait for INIT_EVENT_ID_CMD_RESULT
3111     u4Status = wlanImageSectionDownloadStatus(prAdapter, ucCmdSeqNum);
3112         #endif
3113
3114     // 8. Free CMD Info Packet.
3115     cmdBufFreeCmdInfo(prAdapter, prCmdInfo);
3116
3117     return u4Status;
3118
3119     #elif defined(MT5931)
3120
3121     UINT_32 i, u4Value;
3122     P_HIF_HW_TX_HEADER_T prHifTxHeader;
3123
3124     WLAN_STATUS u4Status = WLAN_STATUS_SUCCESS;
3125
3126     ASSERT(prAdapter);
3127     ASSERT(pucImgSecBuf);
3128     ASSERT(u4ImgSecSize <= CMD_PKT_SIZE_FOR_IMAGE);
3129
3130     DEBUGFUNC("wlanImageSectionDownload");
3131     DBGLOG(INIT, TRACE, ("Destination: 0x%08X / Length: 0x%08X\n", u4DestAddr, u4ImgSecSize));
3132
3133     if (u4ImgSecSize == 0) {
3134         return WLAN_STATUS_SUCCESS;
3135     }
3136
3137     // 1. Use TX coalescing buffer
3138     prHifTxHeader = (P_HIF_HW_TX_HEADER_T) prAdapter->pucCoalescingBufCached;
3139
3140     // 2. Setup HIF_TX_HEADER
3141     prHifTxHeader->u2TxByteCount = (UINT_16)(ALIGN_4(sizeof(HIF_HW_TX_HEADER_T) + u4ImgSecSize));
3142     prHifTxHeader->ucEtherTypeOffset = 0;
3143     prHifTxHeader->ucCSflags = 0;
3144
3145     // 3. Copy payload
3146     kalMemCopy(prHifTxHeader->aucBuffer, pucImgSecBuf, u4ImgSecSize);
3147
3148     // 3.1 add 4-bytes zero tail
3149     kalMemZero(&(prHifTxHeader->aucBuffer[ALIGN_4(u4ImgSecSize)]), sizeof(HIF_HW_TX_HEADER_T));
3150
3151     // 4. Poll til FWDL_RDY = 1
3152     i = 0;
3153     while(1) {
3154         HAL_MCR_RD(prAdapter, MCR_FWDLSR, &u4Value);
3155
3156         if (u4Value & FWDLSR_FWDL_RDY) {
3157             DBGLOG(INIT, TRACE, ("FWDL_RDY detected\n"));
3158             break;
3159         }
3160         else if(kalIsCardRemoved(prAdapter->prGlueInfo) == TRUE
3161                 || fgIsBusAccessFailed == TRUE) {
3162             u4Status = WLAN_STATUS_FAILURE;
3163             break;
3164         }
3165         else if(i >= CFG_RESPONSE_POLLING_TIMEOUT) {
3166             DBGLOG(INIT, ERROR, ("Waiting for FWDL_RDY: Timeout (0x%08X)\n", u4Value));
3167             u4Status = WLAN_STATUS_FAILURE;
3168             break;
3169         }
3170         else {
3171             i++;
3172             kalMsleep(10);
3173         }
3174     }
3175
3176     // 5. Send firmware
3177     HAL_PORT_WR(prAdapter,
3178             MCR_FWDLDR,
3179             prHifTxHeader->u2TxByteCount,
3180             (PUINT_8)prHifTxHeader,
3181             prAdapter->u4CoalescingBufCachedSize);
3182
3183     return u4Status;
3184
3185     #endif
3186 }
3187
3188 #if !CFG_ENABLE_FW_DOWNLOAD_ACK
3189 /*----------------------------------------------------------------------------*/
3190 /*!
3191 * @brief This function is called to confirm previously firmware download is done without error
3192 *
3193 * @param prAdapter      Pointer to the Adapter structure.
3194 *
3195 * @return (none)
3196 */
3197 /*----------------------------------------------------------------------------*/
3198 WLAN_STATUS
3199 wlanImageQueryStatus(
3200     IN P_ADAPTER_T  prAdapter
3201     )
3202 {
3203     P_CMD_INFO_T prCmdInfo;
3204     P_INIT_HIF_TX_HEADER_T prInitHifTxHeader;
3205     UINT_8 aucBuffer[sizeof(INIT_HIF_RX_HEADER_T) + sizeof(INIT_EVENT_PENDING_ERROR)];
3206     UINT_32 u4RxPktLength;
3207     P_INIT_HIF_RX_HEADER_T prInitHifRxHeader;
3208     P_INIT_EVENT_PENDING_ERROR prEventPendingError;
3209     WLAN_STATUS u4Status = WLAN_STATUS_SUCCESS;
3210     UINT_8 ucTC, ucCmdSeqNum;
3211
3212     ASSERT(prAdapter);
3213
3214     DEBUGFUNC("wlanImageQueryStatus");
3215
3216     // 1. Allocate CMD Info Packet and it Buffer.
3217     prCmdInfo = cmdBufAllocateCmdInfo(prAdapter, sizeof(INIT_HIF_TX_HEADER_T));
3218
3219     if (!prCmdInfo) {
3220         DBGLOG(INIT, ERROR, ("Allocate CMD_INFO_T ==> FAILED.\n"));
3221         return WLAN_STATUS_FAILURE;
3222     }
3223
3224     kalMemZero(prCmdInfo, sizeof(INIT_HIF_TX_HEADER_T));
3225     prCmdInfo->u2InfoBufLen = sizeof(INIT_HIF_TX_HEADER_T);
3226
3227     // 2. Use TC0's resource to download image. (only TC0 is allowed)
3228     ucTC = TC0_INDEX;
3229
3230     // 3. increase command sequence number
3231     ucCmdSeqNum = nicIncreaseCmdSeqNum(prAdapter);
3232
3233     // 4. Setup common CMD Info Packet
3234     prInitHifTxHeader = (P_INIT_HIF_TX_HEADER_T)(prCmdInfo->pucInfoBuffer);
3235     prInitHifTxHeader->rInitWifiCmd.ucCID = INIT_CMD_ID_QUERY_PENDING_ERROR;
3236     prInitHifTxHeader->rInitWifiCmd.ucSeqNum = ucCmdSeqNum;
3237
3238     // 5. Send command
3239     while(1) {
3240         // 5.1 Acquire TX Resource
3241         if (nicTxAcquireResource(prAdapter, ucTC) == WLAN_STATUS_RESOURCES) {
3242             if (nicTxPollingResource(prAdapter, ucTC) != WLAN_STATUS_SUCCESS) {
3243                 u4Status = WLAN_STATUS_FAILURE;
3244                 DBGLOG(INIT, ERROR,("Fail to get TX resource return within timeout\n"));
3245                 break;
3246             }
3247             else {
3248                 continue;
3249             }
3250         }
3251
3252         // 5.2 Send CMD Info Packet
3253         if (nicTxInitCmd(prAdapter, prCmdInfo, ucTC) != WLAN_STATUS_SUCCESS) {
3254             u4Status = WLAN_STATUS_FAILURE;
3255             DBGLOG(INIT, ERROR,("Fail to transmit image download command\n"));
3256         }
3257
3258         break;
3259     };
3260
3261     // 6. Wait for INIT_EVENT_ID_PENDING_ERROR
3262     do {
3263         if(kalIsCardRemoved(prAdapter->prGlueInfo) == TRUE
3264                 || fgIsBusAccessFailed == TRUE) {
3265             u4Status = WLAN_STATUS_FAILURE;
3266                         DBGLOG(INIT, ERROR, ("Bus error(%d)/Card removed(%d)\n", fgIsBusAccessFailed, kalIsCardRemoved(prAdapter->prGlueInfo)));
3267         }
3268         else if(nicRxWaitResponse(prAdapter,
3269                     0,
3270                     aucBuffer,
3271                     sizeof(INIT_HIF_RX_HEADER_T) + sizeof(INIT_EVENT_PENDING_ERROR),
3272                     &u4RxPktLength) != WLAN_STATUS_SUCCESS) {
3273             u4Status = WLAN_STATUS_FAILURE;
3274                         DBGLOG(INIT, ERROR, ("No RX response\n"));
3275         }
3276         else {
3277             prInitHifRxHeader = (P_INIT_HIF_RX_HEADER_T) aucBuffer;
3278
3279             // EID / SeqNum check
3280             if(prInitHifRxHeader->rInitWifiEvent.ucEID != INIT_EVENT_ID_PENDING_ERROR) {
3281                 u4Status = WLAN_STATUS_FAILURE;
3282                                 DBGLOG(INIT, ERROR, ("EVENT-ID Mismatch: %d\n", prInitHifRxHeader->rInitWifiEvent.ucEID));
3283             }
3284             else if(prInitHifRxHeader->rInitWifiEvent.ucSeqNum != ucCmdSeqNum) {
3285                 u4Status = WLAN_STATUS_FAILURE;
3286                                 DBGLOG(INIT, ERROR, ("SEQ-NUM Mismatch: %d (expected: %d)\n", prInitHifRxHeader->rInitWifiEvent.ucSeqNum, ucCmdSeqNum));
3287             }
3288             else {
3289                 prEventPendingError = (P_INIT_EVENT_PENDING_ERROR) (prInitHifRxHeader->rInitWifiEvent.aucBuffer);
3290                 if(prEventPendingError->ucStatus != 0) { // 0 for download success
3291                     u4Status = WLAN_STATUS_FAILURE;
3292                                         DBGLOG(INIT, ERROR, ("ERROR CODE: %d\n", prEventCmdResult->ucStatus));
3293                 }
3294                 else {
3295                     u4Status = WLAN_STATUS_SUCCESS;
3296                 }
3297             }
3298         }
3299     } while (FALSE);
3300
3301     // 7. Free CMD Info Packet.
3302     cmdBufFreeCmdInfo(prAdapter, prCmdInfo);
3303
3304     return u4Status;
3305 }
3306
3307
3308 #else
3309 /*----------------------------------------------------------------------------*/
3310 /*!
3311 * @brief This function is called to confirm the status of
3312 *        previously downloaded firmware scatter
3313 *
3314 * @param prAdapter      Pointer to the Adapter structure.
3315 *        ucCmdSeqNum    Sequence number of previous firmware scatter
3316 *
3317 * @return WLAN_STATUS_SUCCESS
3318 *         WLAN_STATUS_FAILURE
3319 */
3320 /*----------------------------------------------------------------------------*/
3321 WLAN_STATUS
3322 wlanImageSectionDownloadStatus (
3323     IN P_ADAPTER_T  prAdapter,
3324     IN UINT_8       ucCmdSeqNum
3325     )
3326 {
3327     UINT_8 aucBuffer[sizeof(INIT_HIF_RX_HEADER_T) + sizeof(INIT_EVENT_CMD_RESULT)];
3328     P_INIT_HIF_RX_HEADER_T prInitHifRxHeader;
3329     P_INIT_EVENT_CMD_RESULT prEventCmdResult;
3330     UINT_32 u4RxPktLength;
3331     WLAN_STATUS u4Status;
3332
3333     ASSERT(prAdapter);
3334
3335     do {
3336         if(kalIsCardRemoved(prAdapter->prGlueInfo) == TRUE
3337                 || fgIsBusAccessFailed == TRUE) {
3338             u4Status = WLAN_STATUS_FAILURE;
3339                         DBGLOG(INIT, ERROR, ("Bus error(%d)/Card removed(%d)\n", fgIsBusAccessFailed, kalIsCardRemoved(prAdapter->prGlueInfo)));
3340         }
3341         else if(nicRxWaitResponse(prAdapter,
3342                     0,
3343                     aucBuffer,
3344                     sizeof(INIT_HIF_RX_HEADER_T) + sizeof(INIT_EVENT_CMD_RESULT),
3345                     &u4RxPktLength) != WLAN_STATUS_SUCCESS) {
3346             u4Status = WLAN_STATUS_FAILURE;
3347                         DBGLOG(INIT, ERROR, ("No RX response\n"));
3348         }
3349         else {
3350             prInitHifRxHeader = (P_INIT_HIF_RX_HEADER_T) aucBuffer;
3351
3352             // EID / SeqNum check
3353             if(prInitHifRxHeader->rInitWifiEvent.ucEID != INIT_EVENT_ID_CMD_RESULT) {
3354                 u4Status = WLAN_STATUS_FAILURE;
3355                                 DBGLOG(INIT, ERROR, ("EVENT-ID Mismatch: %d\n", prInitHifRxHeader->rInitWifiEvent.ucEID));
3356             }
3357             else if(prInitHifRxHeader->rInitWifiEvent.ucSeqNum != ucCmdSeqNum) {
3358                 u4Status = WLAN_STATUS_FAILURE;
3359                                 DBGLOG(INIT, ERROR, ("SEQ-NUM Mismatch: %d\n", prInitHifRxHeader->rInitWifiEvent.ucSeqNum));
3360             }
3361             else {
3362                 prEventCmdResult = (P_INIT_EVENT_CMD_RESULT) (prInitHifRxHeader->rInitWifiEvent.aucBuffer);
3363                 if(prEventCmdResult->ucStatus != 0) { // 0 for download success
3364                     u4Status = WLAN_STATUS_FAILURE;
3365                                         DBGLOG(INIT, ERROR, ("ERROR CODE: %d\n", prEventCmdResult->ucStatus));
3366                 }
3367                 else {
3368                     u4Status = WLAN_STATUS_SUCCESS;
3369                 }
3370             }
3371         }
3372     } while (FALSE);
3373
3374     return u4Status;
3375 }
3376
3377
3378 #endif
3379 /*----------------------------------------------------------------------------*/
3380 /*!
3381 * @brief This function is called to start FW normal operation.
3382 *
3383 * @param prAdapter      Pointer to the Adapter structure.
3384 *
3385 * @return (none)
3386 */
3387 /*----------------------------------------------------------------------------*/
3388 WLAN_STATUS
3389 wlanConfigWifiFunc (
3390     IN P_ADAPTER_T  prAdapter,
3391     IN BOOLEAN      fgEnable,
3392     IN UINT_32      u4StartAddress
3393     )
3394 {
3395     P_CMD_INFO_T prCmdInfo;
3396     P_INIT_HIF_TX_HEADER_T prInitHifTxHeader;
3397     P_INIT_CMD_WIFI_START prInitCmdWifiStart;
3398     UINT_8 ucTC, ucCmdSeqNum;
3399     WLAN_STATUS u4Status = WLAN_STATUS_SUCCESS;
3400
3401     ASSERT(prAdapter);
3402
3403     DEBUGFUNC("wlanConfigWifiFunc");
3404
3405      // 1. Allocate CMD Info Packet and its Buffer.
3406     prCmdInfo = cmdBufAllocateCmdInfo(prAdapter,
3407             sizeof(INIT_HIF_TX_HEADER_T) + sizeof(INIT_CMD_WIFI_START));
3408
3409     if (!prCmdInfo) {
3410         DBGLOG(INIT, ERROR, ("Allocate CMD_INFO_T ==> FAILED.\n"));
3411         return WLAN_STATUS_FAILURE;
3412     }
3413
3414         kalMemZero(prCmdInfo, sizeof(INIT_HIF_TX_HEADER_T) + sizeof(INIT_CMD_WIFI_START));
3415     prCmdInfo->u2InfoBufLen =
3416         sizeof(INIT_HIF_TX_HEADER_T) + sizeof(INIT_CMD_WIFI_START);
3417
3418     // 2. Always use TC0
3419     ucTC = TC0_INDEX;
3420
3421     // 3. increase command sequence number
3422     ucCmdSeqNum = nicIncreaseCmdSeqNum(prAdapter);
3423
3424     // 4. Setup common CMD Info Packet
3425     prInitHifTxHeader = (P_INIT_HIF_TX_HEADER_T)(prCmdInfo->pucInfoBuffer);
3426     prInitHifTxHeader->rInitWifiCmd.ucCID = INIT_CMD_ID_WIFI_START;
3427     prInitHifTxHeader->rInitWifiCmd.ucSeqNum = ucCmdSeqNum;
3428
3429     prInitCmdWifiStart = (P_INIT_CMD_WIFI_START)(prInitHifTxHeader->rInitWifiCmd.aucBuffer);
3430     prInitCmdWifiStart->u4Override = (fgEnable == TRUE ? 1 : 0);
3431     prInitCmdWifiStart->u4Address = u4StartAddress;
3432
3433     // 5. Seend WIFI start command
3434     while(1) {
3435         // 5.1 Acquire TX Resource
3436         if (nicTxAcquireResource(prAdapter, ucTC) == WLAN_STATUS_RESOURCES) {
3437             if (nicTxPollingResource(prAdapter, ucTC) != WLAN_STATUS_SUCCESS) {
3438                 u4Status = WLAN_STATUS_FAILURE;
3439                 DBGLOG(INIT, ERROR,("Fail to get TX resource return within timeout\n"));
3440                 break;
3441             }
3442             else {
3443                 continue;
3444             }
3445         }
3446
3447         // 5.2 Send CMD Info Packet
3448         if (nicTxInitCmd(prAdapter, prCmdInfo, ucTC) != WLAN_STATUS_SUCCESS) {
3449             u4Status = WLAN_STATUS_FAILURE;
3450             DBGLOG(INIT, ERROR,("Fail to transmit WIFI start command\n"));
3451         }
3452
3453         break;
3454     };
3455
3456     // 6. Free CMD Info Packet.
3457     cmdBufFreeCmdInfo(prAdapter, prCmdInfo);
3458
3459     return u4Status;
3460 }
3461
3462
3463 /*----------------------------------------------------------------------------*/
3464 /*!
3465 * @brief This function is used to generate CRC32 checksum
3466 *
3467 * @param buf Pointer to the data.
3468 * @param len data length
3469 *
3470 * @return crc32 value
3471 */
3472 /*----------------------------------------------------------------------------*/
3473 UINT_32 wlanCRC32(
3474     PUINT_8 buf,
3475     UINT_32 len)
3476 {
3477     UINT_32 i, crc32 = 0xFFFFFFFF;
3478     const UINT_32 crc32_ccitt_table[256] = {
3479         0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
3480         0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
3481         0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
3482         0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
3483         0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
3484         0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
3485         0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
3486         0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
3487         0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
3488         0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
3489         0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
3490         0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
3491         0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
3492         0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
3493         0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
3494         0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
3495         0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
3496         0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
3497         0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
3498         0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
3499         0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
3500         0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
3501         0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
3502         0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
3503         0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
3504         0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
3505         0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
3506         0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
3507         0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
3508         0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
3509         0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
3510         0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
3511         0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
3512         0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
3513         0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
3514         0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
3515         0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
3516         0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
3517         0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
3518         0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
3519         0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
3520         0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
3521         0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
3522         0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
3523         0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
3524         0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
3525         0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
3526         0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
3527         0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
3528         0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
3529         0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
3530         0x2d02ef8d };
3531
3532     for (i = 0; i < len; i++)
3533         crc32 = crc32_ccitt_table[(crc32 ^ buf[i]) & 0xff] ^ (crc32 >> 8);
3534
3535     return ( ~crc32 );
3536 }
3537 #endif
3538
3539
3540 /*----------------------------------------------------------------------------*/
3541 /*!
3542 * @brief This function is called to process queued RX packets
3543 *
3544 * @param prAdapter          Pointer to the Adapter structure.
3545 *        prSwRfbListHead    Pointer to head of RX packets link list
3546 *
3547 * @return (none)
3548 */
3549 /*----------------------------------------------------------------------------*/
3550 WLAN_STATUS
3551 wlanProcessQueuedSwRfb (
3552     IN P_ADAPTER_T prAdapter,
3553     IN P_SW_RFB_T prSwRfbListHead
3554     )
3555 {
3556     P_SW_RFB_T prSwRfb, prNextSwRfb;
3557     P_TX_CTRL_T prTxCtrl;
3558     P_RX_CTRL_T prRxCtrl;
3559
3560     ASSERT(prAdapter);
3561     ASSERT(prSwRfbListHead);
3562
3563     prTxCtrl = &prAdapter->rTxCtrl;
3564     prRxCtrl = &prAdapter->rRxCtrl;
3565
3566     prSwRfb = prSwRfbListHead;
3567
3568     do {
3569         // save next first
3570         prNextSwRfb = (P_SW_RFB_T)QUEUE_GET_NEXT_ENTRY((P_QUE_ENTRY_T)prSwRfb);
3571
3572         switch(prSwRfb->eDst) {
3573         case RX_PKT_DESTINATION_HOST:
3574             nicRxProcessPktWithoutReorder(prAdapter, prSwRfb);
3575             break;
3576
3577         case RX_PKT_DESTINATION_FORWARD:
3578             nicRxProcessForwardPkt(prAdapter, prSwRfb);
3579             break;
3580
3581         case RX_PKT_DESTINATION_HOST_WITH_FORWARD:
3582             nicRxProcessGOBroadcastPkt(prAdapter, prSwRfb);
3583             break;
3584
3585         case RX_PKT_DESTINATION_NULL:
3586             nicRxReturnRFB(prAdapter, prSwRfb);
3587             break;
3588
3589         default:
3590             break;
3591         }
3592
3593 #if CFG_HIF_RX_STARVATION_WARNING
3594         prRxCtrl->u4DequeuedCnt++;
3595 #endif
3596         prSwRfb = prNextSwRfb;
3597     } while(prSwRfb);
3598
3599     return WLAN_STATUS_SUCCESS;
3600 }
3601
3602
3603 /*----------------------------------------------------------------------------*/
3604 /*!
3605 * @brief This function is called to purge queued TX packets
3606 *        by indicating failure to OS and returned to free list
3607 *
3608 * @param prAdapter          Pointer to the Adapter structure.
3609 *        prMsduInfoListHead Pointer to head of TX packets link list
3610 *
3611 * @return (none)
3612 */
3613 /*----------------------------------------------------------------------------*/
3614 WLAN_STATUS
3615 wlanProcessQueuedMsduInfo (
3616     IN P_ADAPTER_T prAdapter,
3617     IN P_MSDU_INFO_T prMsduInfoListHead
3618     )
3619 {
3620     ASSERT(prAdapter);
3621     ASSERT(prMsduInfoListHead);
3622
3623     nicTxFreeMsduInfoPacket(prAdapter, prMsduInfoListHead);
3624     nicTxReturnMsduInfo(prAdapter, prMsduInfoListHead);
3625
3626     return WLAN_STATUS_SUCCESS;
3627 }
3628
3629
3630 /*----------------------------------------------------------------------------*/
3631 /*!
3632 * @brief This function is called to check if the OID handler needs timeout
3633 *
3634 * @param prAdapter          Pointer to the Adapter structure.
3635 *        pfnOidHandler      Pointer to the OID handler
3636 *
3637 * @return TRUE
3638 *         FALSE
3639 */
3640 /*----------------------------------------------------------------------------*/
3641 BOOLEAN
3642 wlanoidTimeoutCheck (
3643     IN P_ADAPTER_T prAdapter,
3644     IN PFN_OID_HANDLER_FUNC pfnOidHandler
3645     )
3646 {
3647     PFN_OID_HANDLER_FUNC* apfnOidHandlerWOTimeoutCheck;
3648     UINT_32 i;
3649     UINT_32 u4NumOfElem;
3650
3651     apfnOidHandlerWOTimeoutCheck = apfnOidWOTimeoutCheck;
3652     u4NumOfElem = sizeof(apfnOidWOTimeoutCheck) / sizeof(PFN_OID_HANDLER_FUNC);
3653
3654     for (i = 0; i < u4NumOfElem; i++) {
3655         if (apfnOidHandlerWOTimeoutCheck[i] == pfnOidHandler) {
3656             return FALSE;
3657         }
3658     }
3659
3660     // set timer if need timeout check
3661     //cnmTimerStartTimer(prAdapter,
3662     //        &(prAdapter->rOidTimeoutTimer),
3663     //        1000);
3664     cnmTimerStartTimer(prAdapter,
3665             &(prAdapter->rOidTimeoutTimer),
3666             2000);
3667
3668     return TRUE;
3669 }
3670
3671
3672 /*----------------------------------------------------------------------------*/
3673 /*!
3674 * @brief This function is called to clear any pending OID timeout check
3675 *
3676 * @param prAdapter          Pointer to the Adapter structure.
3677 *
3678 * @return none
3679 */
3680 /*----------------------------------------------------------------------------*/
3681 VOID
3682 wlanoidClearTimeoutCheck (
3683     IN P_ADAPTER_T prAdapter
3684     )
3685 {
3686     ASSERT(prAdapter);
3687
3688     cnmTimerStopTimer(prAdapter, &(prAdapter->rOidTimeoutTimer));
3689 }
3690
3691
3692 /*----------------------------------------------------------------------------*/
3693 /*!
3694 * @brief This function is called to set up the MCUSYS's OSC stable time
3695 *
3696 * @param prAdapter          Pointer to the Adapter structure.
3697 *
3698 * @return none
3699 */
3700 /*----------------------------------------------------------------------------*/
3701
3702 #if CFG_SUPPORT_OSC_SETTING && defined(MT5931)
3703 WLAN_STATUS
3704 wlanSetMcuOscStableTime (
3705     IN P_ADAPTER_T      prAdapter,
3706     IN UINT_16          u2OscStableTime
3707     )
3708 {
3709     UINT_8                  ucCmdSeqNum = 0;
3710     P_CMD_INFO_T            prCmdInfo = NULL;
3711     P_WIFI_CMD_T            prWifiCmd = NULL;
3712     P_CMD_MCU_LP_PARAM_T    prMcuSetOscCmd = NULL;
3713     WLAN_STATUS             status = WLAN_STATUS_SUCCESS;
3714
3715     ASSERT(prAdapter);
3716
3717     prCmdInfo = cmdBufAllocateCmdInfo(prAdapter,
3718             CMD_HDR_SIZE + sizeof(CMD_MCU_LP_PARAM_T));
3719
3720     if (!prCmdInfo) {
3721         DBGLOG(INIT, ERROR, ("Allocate CMD_INFO_T ==> FAILED.\n"));
3722         return WLAN_STATUS_FAILURE;
3723     }
3724
3725     // increase command sequence number
3726     ucCmdSeqNum = nicIncreaseCmdSeqNum(prAdapter);
3727
3728     // compose CMD_MCU_LP_PARAM_T cmd pkt
3729     prCmdInfo->eCmdType = COMMAND_TYPE_GENERAL_IOCTL;
3730     prCmdInfo->u2InfoBufLen = CMD_HDR_SIZE + sizeof(CMD_MCU_LP_PARAM_T);
3731     prCmdInfo->pfCmdDoneHandler = NULL;
3732     prCmdInfo->pfCmdTimeoutHandler = NULL;
3733     prCmdInfo->fgIsOid = FALSE;
3734     prCmdInfo->ucCID = CMD_ID_SET_OSC;
3735     prCmdInfo->fgSetQuery = TRUE;
3736     prCmdInfo->fgNeedResp = FALSE;
3737     prCmdInfo->fgDriverDomainMCR = FALSE;
3738     prCmdInfo->ucCmdSeqNum = ucCmdSeqNum;
3739     prCmdInfo->u4SetInfoLen = sizeof(CMD_MCU_LP_PARAM_T);
3740
3741     // Setup WIFI_CMD_T
3742     prWifiCmd = (P_WIFI_CMD_T)(prCmdInfo->pucInfoBuffer);
3743     prWifiCmd->u2TxByteCount_UserPriority = prCmdInfo->u2InfoBufLen;
3744     prWifiCmd->ucCID = prCmdInfo->ucCID;
3745     prWifiCmd->ucSetQuery = prCmdInfo->fgSetQuery;
3746     prWifiCmd->ucSeqNum = prCmdInfo->ucCmdSeqNum;
3747
3748     // configure CMD_MCU_LP_PARAM_T
3749     prMcuSetOscCmd = (P_CMD_MCU_LP_PARAM_T)(prWifiCmd->aucBuffer);
3750     prMcuSetOscCmd->u2OscStableTime = u2OscStableTime;
3751
3752     status = wlanSendCommand(prAdapter, prCmdInfo);
3753     cmdBufFreeCmdInfo(prAdapter, prCmdInfo);
3754
3755     return status;
3756 }
3757 #endif
3758
3759 /*----------------------------------------------------------------------------*/
3760 /*!
3761 * @brief This function is called to update network address in firmware domain
3762 *
3763 * @param prAdapter          Pointer to the Adapter structure.
3764 *
3765 * @return WLAN_STATUS_FAILURE   The request could not be processed
3766 *         WLAN_STATUS_PENDING   The request has been queued for later processing
3767 *         WLAN_STATUS_SUCCESS   The request has been processed
3768 */
3769 /*----------------------------------------------------------------------------*/
3770 WLAN_STATUS
3771 wlanUpdateNetworkAddress (
3772     IN P_ADAPTER_T prAdapter
3773     )
3774 {
3775     const UINT_8 aucZeroMacAddr[] = NULL_MAC_ADDR;
3776     PARAM_MAC_ADDRESS rMacAddr;
3777     UINT_8 ucCmdSeqNum;
3778     P_CMD_INFO_T prCmdInfo;
3779     P_WIFI_CMD_T prWifiCmd;
3780     P_CMD_BASIC_CONFIG prCmdBasicConfig;
3781     UINT_32 u4SysTime;
3782
3783     DEBUGFUNC("wlanUpdateNetworkAddress");
3784
3785     ASSERT(prAdapter);
3786
3787     if(kalRetrieveNetworkAddress(prAdapter->prGlueInfo, &rMacAddr) == FALSE
3788             || IS_BMCAST_MAC_ADDR(rMacAddr)
3789             || EQUAL_MAC_ADDR(aucZeroMacAddr, rMacAddr)) {
3790         // eFUSE has a valid address, don't do anything
3791         if(prAdapter->fgIsEmbbededMacAddrValid == TRUE) {
3792 #if CFG_SHOW_MACADDR_SOURCE
3793             DBGLOG(INIT, INFO, ("Using embedded MAC address"));
3794 #endif
3795             return WLAN_STATUS_SUCCESS;
3796         }
3797         else {
3798 #if CFG_SHOW_MACADDR_SOURCE
3799             DBGLOG(INIT, INFO, ("Using dynamically generated MAC address"));
3800 #endif
3801             // dynamic generate
3802             u4SysTime = (UINT_32) kalGetTimeTick();
3803
3804             rMacAddr[0] = 0x00;
3805             rMacAddr[1] = 0x08;
3806             rMacAddr[2] = 0x22;
3807
3808             kalMemCopy(&rMacAddr[3], &u4SysTime, 3);
3809         }
3810     }
3811     else {
3812 #if CFG_SHOW_MACADDR_SOURCE
3813         DBGLOG(INIT, INFO, ("Using host-supplied MAC address"));
3814 #endif
3815     }
3816
3817     prCmdInfo = cmdBufAllocateCmdInfo(prAdapter,
3818             CMD_HDR_SIZE + sizeof(CMD_BASIC_CONFIG));
3819
3820     if (!prCmdInfo) {
3821         DBGLOG(INIT, ERROR, ("Allocate CMD_INFO_T ==> FAILED.\n"));
3822         return WLAN_STATUS_FAILURE;
3823     }
3824
3825     // increase command sequence number
3826     ucCmdSeqNum = nicIncreaseCmdSeqNum(prAdapter);
3827
3828     // compose CMD_BUILD_CONNECTION cmd pkt
3829     prCmdInfo->eCmdType = COMMAND_TYPE_GENERAL_IOCTL;
3830     prCmdInfo->u2InfoBufLen = CMD_HDR_SIZE + sizeof(CMD_BASIC_CONFIG);
3831     prCmdInfo->pfCmdDoneHandler = NULL;
3832     prCmdInfo->pfCmdTimeoutHandler = NULL;
3833     prCmdInfo->fgIsOid = FALSE;
3834     prCmdInfo->ucCID = CMD_ID_BASIC_CONFIG;
3835     prCmdInfo->fgSetQuery = TRUE;
3836     prCmdInfo->fgNeedResp = FALSE;
3837     prCmdInfo->fgDriverDomainMCR = FALSE;
3838     prCmdInfo->ucCmdSeqNum = ucCmdSeqNum;
3839     prCmdInfo->u4SetInfoLen = sizeof(CMD_BASIC_CONFIG);
3840
3841     // Setup WIFI_CMD_T
3842     prWifiCmd = (P_WIFI_CMD_T)(prCmdInfo->pucInfoBuffer);
3843     prWifiCmd->u2TxByteCount_UserPriority = prCmdInfo->u2InfoBufLen;
3844     prWifiCmd->ucCID = prCmdInfo->ucCID;
3845     prWifiCmd->ucSetQuery = prCmdInfo->fgSetQuery;
3846     prWifiCmd->ucSeqNum = prCmdInfo->ucCmdSeqNum;
3847
3848     // configure CMD_BASIC_CONFIG
3849     prCmdBasicConfig = (P_CMD_BASIC_CONFIG)(prWifiCmd->aucBuffer);
3850     kalMemCopy(&(prCmdBasicConfig->rMyMacAddr), &rMacAddr, PARAM_MAC_ADDR_LEN);
3851     prCmdBasicConfig->ucNative80211 = 0;
3852     prCmdBasicConfig->rCsumOffload.u2RxChecksum = 0;
3853     prCmdBasicConfig->rCsumOffload.u2TxChecksum = 0;
3854
3855 #if CFG_TCP_IP_CHKSUM_OFFLOAD
3856     if(prAdapter->u4CSUMFlags & CSUM_OFFLOAD_EN_TX_TCP)
3857         prCmdBasicConfig->rCsumOffload.u2TxChecksum |= BIT(2);
3858
3859     if(prAdapter->u4CSUMFlags & CSUM_OFFLOAD_EN_TX_UDP)
3860         prCmdBasicConfig->rCsumOffload.u2TxChecksum |= BIT(1);
3861
3862     if(prAdapter->u4CSUMFlags & CSUM_OFFLOAD_EN_TX_IP)
3863         prCmdBasicConfig->rCsumOffload.u2TxChecksum |= BIT(0);
3864
3865     if(prAdapter->u4CSUMFlags & CSUM_OFFLOAD_EN_RX_TCP)
3866         prCmdBasicConfig->rCsumOffload.u2RxChecksum |= BIT(2);
3867
3868     if(prAdapter->u4CSUMFlags & CSUM_OFFLOAD_EN_RX_UDP)
3869         prCmdBasicConfig->rCsumOffload.u2RxChecksum |= BIT(1);
3870
3871     if(prAdapter->u4CSUMFlags & (CSUM_OFFLOAD_EN_RX_IPv4 | CSUM_OFFLOAD_EN_RX_IPv6))
3872         prCmdBasicConfig->rCsumOffload.u2RxChecksum |= BIT(0);
3873 #endif
3874
3875     if(wlanSendCommand(prAdapter, prCmdInfo) == WLAN_STATUS_RESOURCES) {
3876         prCmdInfo->pfCmdDoneHandler = nicCmdEventQueryAddress;
3877         kalEnqueueCommand(prAdapter->prGlueInfo, (P_QUE_ENTRY_T)prCmdInfo);
3878
3879         return WLAN_STATUS_PENDING;
3880     }
3881     else {
3882         nicCmdEventQueryAddress(prAdapter, prCmdInfo, (PUINT_8)prCmdBasicConfig);
3883         cmdBufFreeCmdInfo(prAdapter, prCmdInfo);
3884
3885         return WLAN_STATUS_SUCCESS;
3886     }
3887 }
3888
3889 /*----------------------------------------------------------------------------*/
3890 /*!
3891 * @brief This function is called to check if the device is in RF test mode
3892 *
3893 * @param pfnOidHandler      Pointer to the OID handler
3894 *
3895 * @return TRUE
3896 *         FALSE
3897 */
3898 /*----------------------------------------------------------------------------*/
3899 BOOLEAN
3900 wlanQueryTestMode(
3901     IN P_ADAPTER_T          prAdapter
3902     )
3903 {
3904     ASSERT(prAdapter);
3905
3906     return prAdapter->fgTestMode;
3907 }
3908
3909
3910 /*----------------------------------------------------------------------------*/
3911 /*!
3912 * @brief This function is called to identify 802.1x and Bluetooth-over-Wi-Fi
3913 *        security frames, and queued into command queue for strict ordering
3914 *        due to 802.1x frames before add-key OIDs are not to be encrypted
3915 *
3916 * @param prAdapter      Pointer of Adapter Data Structure
3917 * @param prPacket       Pointer of native packet
3918 *
3919 * @return TRUE
3920 *         FALSE
3921 */
3922 /*----------------------------------------------------------------------------*/
3923 BOOLEAN
3924 wlanProcessSecurityFrame(
3925     IN P_ADAPTER_T      prAdapter,
3926     IN P_NATIVE_PACKET  prPacket
3927     )
3928 {
3929     UINT_8          ucPriorityParam;
3930     UINT_8          aucEthDestAddr[PARAM_MAC_ADDR_LEN];
3931     BOOLEAN         fgIs1x = FALSE;
3932     BOOLEAN         fgIsPAL = FALSE;
3933     UINT_32         u4PacketLen;
3934     ULONG           u4SysTime;
3935     UINT_8          ucNetworkType;
3936     P_CMD_INFO_T    prCmdInfo;
3937
3938     ASSERT(prAdapter);
3939     ASSERT(prPacket);
3940
3941     if (kalQoSFrameClassifierAndPacketInfo(prAdapter->prGlueInfo,
3942                 prPacket,
3943                 &ucPriorityParam,
3944                 &u4PacketLen,
3945                 aucEthDestAddr,
3946                 &fgIs1x,
3947                 &fgIsPAL,
3948                 &ucNetworkType) == TRUE) {
3949         if(fgIs1x == FALSE) {
3950             return FALSE;
3951         }
3952         else {
3953             KAL_SPIN_LOCK_DECLARATION();
3954             KAL_ACQUIRE_SPIN_LOCK(prAdapter, SPIN_LOCK_CMD_RESOURCE);
3955             QUEUE_REMOVE_HEAD(&prAdapter->rFreeCmdList, prCmdInfo, P_CMD_INFO_T);
3956             KAL_RELEASE_SPIN_LOCK(prAdapter, SPIN_LOCK_CMD_RESOURCE);
3957
3958             DBGLOG(RSN, INFO, ("T1X len=%d\n", u4PacketLen));
3959
3960             if (prCmdInfo) {
3961                 P_STA_RECORD_T          prStaRec;
3962                 // fill arrival time
3963                 u4SysTime = (OS_SYSTIME)kalGetTimeTick();
3964                 GLUE_SET_PKT_ARRIVAL_TIME(prPacket, u4SysTime);
3965
3966                 kalMemZero(prCmdInfo, sizeof(CMD_INFO_T));
3967
3968                 prCmdInfo->eCmdType             = COMMAND_TYPE_SECURITY_FRAME;
3969                 prCmdInfo->u2InfoBufLen         = (UINT_16)u4PacketLen;
3970                 prCmdInfo->pucInfoBuffer        = NULL;
3971                 prCmdInfo->prPacket             = prPacket;
3972 #if 0
3973                 prCmdInfo->ucStaRecIndex        = qmGetStaRecIdx(prAdapter,
3974                                                                     aucEthDestAddr,
3975                                                                     (ENUM_NETWORK_TYPE_INDEX_T)ucNetworkType);
3976 #endif
3977                 prStaRec                        = cnmGetStaRecByAddress(prAdapter,
3978                                                                         (ENUM_NETWORK_TYPE_INDEX_T)ucNetworkType,
3979                                                                         aucEthDestAddr);
3980                 if(prStaRec) {
3981                     prCmdInfo->ucStaRecIndex =  prStaRec->ucIndex;
3982                 }
3983                 else {
3984                     prCmdInfo->ucStaRecIndex =  STA_REC_INDEX_NOT_FOUND;
3985                 }
3986
3987                 prCmdInfo->eNetworkType         = (ENUM_NETWORK_TYPE_INDEX_T)ucNetworkType;
3988                 prCmdInfo->pfCmdDoneHandler     = wlanSecurityFrameTxDone;
3989                 prCmdInfo->pfCmdTimeoutHandler  = wlanSecurityFrameTxTimeout;
3990                 prCmdInfo->fgIsOid              = FALSE;
3991                 prCmdInfo->fgSetQuery           = TRUE;
3992                 prCmdInfo->fgNeedResp           = FALSE;
3993
3994                 kalEnqueueCommand(prAdapter->prGlueInfo, (P_QUE_ENTRY_T)prCmdInfo);
3995
3996                 return TRUE;
3997             }
3998             else {
3999                 ASSERT(0);
4000                 return FALSE;
4001             }
4002         }
4003     }
4004     else {
4005         return FALSE;
4006     }
4007 }
4008
4009
4010 /*----------------------------------------------------------------------------*/
4011 /*!
4012 * @brief This function is called when 802.1x or Bluetooth-over-Wi-Fi
4013 *        security frames has been sent to firmware
4014 *
4015 * @param prAdapter      Pointer of Adapter Data Structure
4016 * @param prCmdInfo      Pointer of CMD_INFO_T
4017 * @param pucEventBuf    meaningless, only for API compatibility
4018 *
4019 * @return none
4020 */
4021 /*----------------------------------------------------------------------------*/
4022 VOID
4023 wlanSecurityFrameTxDone(
4024     IN P_ADAPTER_T  prAdapter,
4025     IN P_CMD_INFO_T prCmdInfo,
4026     IN PUINT_8      pucEventBuf
4027     )
4028 {
4029     ASSERT(prAdapter);
4030     ASSERT(prCmdInfo);
4031     if (prCmdInfo->eNetworkType == NETWORK_TYPE_AIS_INDEX &&
4032         prAdapter->rWifiVar.rAisSpecificBssInfo.fgCounterMeasure) {
4033         P_STA_RECORD_T prSta = cnmGetStaRecByIndex(prAdapter, prCmdInfo->ucStaRecIndex);
4034         if (prSta) {
4035             kalMsleep(10);
4036             secFsmEventEapolTxDone(prAdapter, prSta, TX_RESULT_SUCCESS);
4037         }
4038     }
4039
4040     kalSecurityFrameSendComplete(prAdapter->prGlueInfo,
4041             prCmdInfo->prPacket,
4042             WLAN_STATUS_SUCCESS);
4043 }
4044
4045
4046 /*----------------------------------------------------------------------------*/
4047 /*!
4048 * @brief This function is called when 802.1x or Bluetooth-over-Wi-Fi
4049 *        security frames has failed sending to firmware
4050 *
4051 * @param prAdapter      Pointer of Adapter Data Structure
4052 * @param prCmdInfo      Pointer of CMD_INFO_T
4053 *
4054 * @return none
4055 */
4056 /*----------------------------------------------------------------------------*/
4057 VOID
4058 wlanSecurityFrameTxTimeout(
4059     IN P_ADAPTER_T  prAdapter,
4060     IN P_CMD_INFO_T prCmdInfo
4061     )
4062 {
4063     ASSERT(prAdapter);
4064     ASSERT(prCmdInfo);
4065
4066     kalSecurityFrameSendComplete(prAdapter->prGlueInfo,
4067             prCmdInfo->prPacket,
4068             WLAN_STATUS_FAILURE);
4069 }
4070
4071
4072 /*----------------------------------------------------------------------------*/
4073 /*!
4074 * @brief This function is called before AIS is starting a new scan
4075 *
4076 * @param prAdapter      Pointer of Adapter Data Structure
4077 *
4078 * @return none
4079 */
4080 /*----------------------------------------------------------------------------*/
4081 VOID
4082 wlanClearScanningResult(
4083     IN P_ADAPTER_T  prAdapter
4084     )
4085 {
4086     BOOLEAN fgKeepCurrOne = FALSE;
4087     UINT_32 i;
4088
4089     ASSERT(prAdapter);
4090
4091     // clear scanning result
4092     if(kalGetMediaStateIndicated(prAdapter->prGlueInfo) == PARAM_MEDIA_STATE_CONNECTED) {
4093         for(i = 0 ; i < prAdapter->rWlanInfo.u4ScanResultNum ; i++) {
4094             if(EQUAL_MAC_ADDR(prAdapter->rWlanInfo.rCurrBssId.arMacAddress,
4095                         prAdapter->rWlanInfo.arScanResult[i].arMacAddress)) {
4096                 fgKeepCurrOne = TRUE;
4097
4098                 if(i != 0) {
4099                     // copy structure
4100                     kalMemCopy(&(prAdapter->rWlanInfo.arScanResult[0]),
4101                             &(prAdapter->rWlanInfo.arScanResult[i]),
4102                             OFFSET_OF(PARAM_BSSID_EX_T, aucIEs));
4103                 }
4104
4105                 if(prAdapter->rWlanInfo.arScanResult[i].u4IELength > 0) {
4106                     if(prAdapter->rWlanInfo.apucScanResultIEs[i] != &(prAdapter->rWlanInfo.aucScanIEBuf[0])) {
4107                         // move IEs to head
4108                         kalMemCopy(prAdapter->rWlanInfo.aucScanIEBuf,
4109                                 prAdapter->rWlanInfo.apucScanResultIEs[i],
4110                                 prAdapter->rWlanInfo.arScanResult[i].u4IELength);
4111                     }
4112
4113                     // modify IE pointer
4114                     prAdapter->rWlanInfo.apucScanResultIEs[0] = &(prAdapter->rWlanInfo.aucScanIEBuf[0]);
4115                 }
4116                 else {
4117                     prAdapter->rWlanInfo.apucScanResultIEs[0] = NULL;
4118                 }
4119
4120                 break;
4121             }
4122         }
4123     }
4124
4125     if(fgKeepCurrOne == TRUE) {
4126         prAdapter->rWlanInfo.u4ScanResultNum = 1;
4127         prAdapter->rWlanInfo.u4ScanIEBufferUsage =
4128             ALIGN_4(prAdapter->rWlanInfo.arScanResult[0].u4IELength);
4129     }
4130     else {
4131         prAdapter->rWlanInfo.u4ScanResultNum = 0;
4132         prAdapter->rWlanInfo.u4ScanIEBufferUsage = 0;
4133     }
4134
4135     return;
4136 }
4137
4138
4139 /*----------------------------------------------------------------------------*/
4140 /*!
4141 * @brief This function is called when AIS received a beacon timeout event
4142 *
4143 * @param prAdapter      Pointer of Adapter Data Structure
4144 * @param arBSSID        MAC address of the specified BSS
4145 *
4146 * @return none
4147 */
4148 /*----------------------------------------------------------------------------*/
4149 VOID
4150 wlanClearBssInScanningResult(
4151     IN P_ADAPTER_T      prAdapter,
4152     IN PUINT_8          arBSSID
4153     )
4154 {
4155     UINT_32 i, j, u4IELength = 0, u4IEMoveLength;
4156     PUINT_8 pucIEPtr;
4157
4158     ASSERT(prAdapter);
4159
4160     // clear scanning result
4161     i = 0;
4162     while(1) {
4163         if(i >= prAdapter->rWlanInfo.u4ScanResultNum) {
4164             break;
4165         }
4166
4167         if(EQUAL_MAC_ADDR(arBSSID, prAdapter->rWlanInfo.arScanResult[i].arMacAddress)) {
4168             // backup current IE length
4169             u4IELength = ALIGN_4(prAdapter->rWlanInfo.arScanResult[i].u4IELength);
4170             pucIEPtr = prAdapter->rWlanInfo.apucScanResultIEs[i];
4171
4172             // removed from middle
4173             for(j = i + 1 ; j < prAdapter->rWlanInfo.u4ScanResultNum ; j++) {
4174                 kalMemCopy(&(prAdapter->rWlanInfo.arScanResult[j-1]),
4175                         &(prAdapter->rWlanInfo.arScanResult[j]),
4176                         OFFSET_OF(PARAM_BSSID_EX_T, aucIEs));
4177
4178                 prAdapter->rWlanInfo.apucScanResultIEs[j-1] =
4179                     prAdapter->rWlanInfo.apucScanResultIEs[j];
4180             }
4181
4182             prAdapter->rWlanInfo.u4ScanResultNum--;
4183
4184             // remove IE buffer if needed := move rest of IE buffer
4185             if(u4IELength > 0) {
4186                 u4IEMoveLength = prAdapter->rWlanInfo.u4ScanIEBufferUsage -
4187                     (((UINT_32)pucIEPtr) + u4IELength - ((UINT_32)(&(prAdapter->rWlanInfo.aucScanIEBuf[0]))));
4188
4189                 kalMemCopy(pucIEPtr,
4190                         (PUINT_8)(((UINT_32)pucIEPtr) + u4IELength),
4191                         u4IEMoveLength);
4192
4193                 prAdapter->rWlanInfo.u4ScanIEBufferUsage -= u4IELength;
4194
4195                 // correction of pointers to IE buffer
4196                 for(j = 0 ; j < prAdapter->rWlanInfo.u4ScanResultNum ; j++) {
4197                     if(prAdapter->rWlanInfo.apucScanResultIEs[j] > pucIEPtr) {
4198                         prAdapter->rWlanInfo.apucScanResultIEs[j] =
4199                             (PUINT_8)((UINT_32)(prAdapter->rWlanInfo.apucScanResultIEs[j]) - u4IELength);
4200                     }
4201                 }
4202             }
4203         }
4204
4205         i++;
4206     }
4207
4208     return;
4209 }
4210
4211
4212 #if CFG_TEST_WIFI_DIRECT_GO
4213 VOID
4214 wlanEnableP2pFunction (
4215     IN P_ADAPTER_T prAdapter
4216     )
4217 {
4218 #if 0
4219     P_MSG_P2P_FUNCTION_SWITCH_T prMsgFuncSwitch = (P_MSG_P2P_FUNCTION_SWITCH_T)NULL;
4220
4221     prMsgFuncSwitch = (P_MSG_P2P_FUNCTION_SWITCH_T)cnmMemAlloc(prAdapter, RAM_TYPE_MSG, sizeof(MSG_P2P_FUNCTION_SWITCH_T));
4222     if (!prMsgFuncSwitch) {
4223         ASSERT(FALSE);
4224         return;
4225     }
4226
4227
4228     prMsgFuncSwitch->rMsgHdr.eMsgId = MID_MNY_P2P_FUN_SWITCH;
4229     prMsgFuncSwitch->fgIsFuncOn = TRUE;
4230
4231
4232     mboxSendMsg(prAdapter,
4233                     MBOX_ID_0,
4234                     (P_MSG_HDR_T)prMsgFuncSwitch,
4235                     MSG_SEND_METHOD_BUF);
4236 #endif
4237     return;
4238 }
4239
4240 VOID
4241 wlanEnableATGO (
4242     IN P_ADAPTER_T prAdapter
4243     )
4244 {
4245
4246     P_MSG_P2P_CONNECTION_REQUEST_T prMsgConnReq = (P_MSG_P2P_CONNECTION_REQUEST_T)NULL;
4247     UINT_8 aucTargetDeviceID[MAC_ADDR_LEN] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
4248
4249     prMsgConnReq = (P_MSG_P2P_CONNECTION_REQUEST_T)cnmMemAlloc(prAdapter, RAM_TYPE_MSG, sizeof(MSG_P2P_CONNECTION_REQUEST_T));
4250     if (!prMsgConnReq) {
4251         ASSERT(FALSE);
4252         return;
4253     }
4254
4255     prMsgConnReq->rMsgHdr.eMsgId = MID_MNY_P2P_CONNECTION_REQ;
4256
4257     /*=====Param Modified for test=====*/
4258     COPY_MAC_ADDR(prMsgConnReq->aucDeviceID, aucTargetDeviceID);
4259     prMsgConnReq->fgIsTobeGO = TRUE;
4260     prMsgConnReq->fgIsPersistentGroup = FALSE;
4261
4262     /*=====Param Modified for test=====*/
4263
4264     mboxSendMsg(prAdapter,
4265                     MBOX_ID_0,
4266                     (P_MSG_HDR_T)prMsgConnReq,
4267                     MSG_SEND_METHOD_BUF);
4268
4269     return;
4270 }
4271 #endif
4272
4273
4274 /*----------------------------------------------------------------------------*/
4275 /*!
4276 * @brief This function is called to retrieve permanent address from firmware
4277 *
4278 * @param prAdapter      Pointer of Adapter Data Structure
4279 *
4280 * @return WLAN_STATUS_SUCCESS
4281 *         WLAN_STATUS_FAILURE
4282 */
4283 /*----------------------------------------------------------------------------*/
4284 WLAN_STATUS
4285 wlanQueryPermanentAddress(
4286     IN P_ADAPTER_T  prAdapter
4287     )
4288 {
4289     UINT_8 ucCmdSeqNum;
4290     P_CMD_INFO_T prCmdInfo;
4291     P_WIFI_CMD_T prWifiCmd;
4292     UINT_32 u4RxPktLength;
4293     UINT_8 aucBuffer[sizeof(WIFI_EVENT_T) + sizeof(EVENT_BASIC_CONFIG)];
4294     P_HIF_RX_HEADER_T prHifRxHdr;
4295     P_WIFI_EVENT_T prEvent;
4296     P_EVENT_BASIC_CONFIG prEventBasicConfig;
4297
4298     ASSERT(prAdapter);
4299
4300     DEBUGFUNC("wlanQueryPermanentAddress");
4301
4302     // 1. Allocate CMD Info Packet and its Buffer
4303     prCmdInfo = cmdBufAllocateCmdInfo(prAdapter, CMD_HDR_SIZE + sizeof(CMD_BASIC_CONFIG));
4304     if (!prCmdInfo) {
4305         DBGLOG(INIT, ERROR, ("Allocate CMD_INFO_T ==> FAILED.\n"));
4306         return WLAN_STATUS_FAILURE;
4307     }
4308
4309     // increase command sequence number
4310     ucCmdSeqNum = nicIncreaseCmdSeqNum(prAdapter);
4311
4312     // compose CMD_BUILD_CONNECTION cmd pkt
4313     prCmdInfo->eCmdType = COMMAND_TYPE_GENERAL_IOCTL;
4314     prCmdInfo->u2InfoBufLen = CMD_HDR_SIZE + sizeof(CMD_BASIC_CONFIG);
4315     prCmdInfo->pfCmdDoneHandler = NULL;
4316     prCmdInfo->fgIsOid = FALSE;
4317     prCmdInfo->ucCID = CMD_ID_BASIC_CONFIG;
4318     prCmdInfo->fgSetQuery = FALSE;
4319     prCmdInfo->fgNeedResp = TRUE;
4320     prCmdInfo->fgDriverDomainMCR = FALSE;
4321     prCmdInfo->ucCmdSeqNum = ucCmdSeqNum;
4322     prCmdInfo->u4SetInfoLen = sizeof(CMD_BASIC_CONFIG);
4323
4324     // Setup WIFI_CMD_T
4325     prWifiCmd = (P_WIFI_CMD_T)(prCmdInfo->pucInfoBuffer);
4326     prWifiCmd->u2TxByteCount_UserPriority = prCmdInfo->u2InfoBufLen;
4327     prWifiCmd->ucCID = prCmdInfo->ucCID;
4328     prWifiCmd->ucSetQuery = prCmdInfo->fgSetQuery;
4329     prWifiCmd->ucSeqNum = prCmdInfo->ucCmdSeqNum;
4330
4331     wlanSendCommand(prAdapter, prCmdInfo);
4332     cmdBufFreeCmdInfo(prAdapter, prCmdInfo);
4333
4334     if(nicRxWaitResponse(prAdapter,
4335                 1,
4336                 aucBuffer,
4337                 sizeof(WIFI_EVENT_T) + sizeof(EVENT_BASIC_CONFIG),
4338                 &u4RxPktLength) != WLAN_STATUS_SUCCESS) {
4339         return WLAN_STATUS_FAILURE;
4340     }
4341
4342     // header checking ..
4343     prHifRxHdr = (P_HIF_RX_HEADER_T)aucBuffer;
4344     if(prHifRxHdr->u2PacketType != HIF_RX_PKT_TYPE_EVENT) {
4345         return WLAN_STATUS_FAILURE;
4346     }
4347
4348     prEvent = (P_WIFI_EVENT_T)aucBuffer;
4349     if(prEvent->ucEID != EVENT_ID_BASIC_CONFIG) {
4350         return WLAN_STATUS_FAILURE;
4351     }
4352
4353     prEventBasicConfig = (P_EVENT_BASIC_CONFIG)(prEvent->aucBuffer);
4354
4355     COPY_MAC_ADDR(prAdapter->rWifiVar.aucPermanentAddress, &(prEventBasicConfig->rMyMacAddr));
4356     COPY_MAC_ADDR(prAdapter->rWifiVar.aucMacAddress, &(prEventBasicConfig->rMyMacAddr));
4357
4358     return WLAN_STATUS_SUCCESS;
4359 }
4360
4361
4362 /*----------------------------------------------------------------------------*/
4363 /*!
4364 * @brief This function is called to retrieve NIC capability from firmware
4365 *
4366 * @param prAdapter      Pointer of Adapter Data Structure
4367 *
4368 * @return WLAN_STATUS_SUCCESS
4369 *         WLAN_STATUS_FAILURE
4370 */
4371 /*----------------------------------------------------------------------------*/
4372 WLAN_STATUS
4373 wlanQueryNicCapability(
4374     IN P_ADAPTER_T prAdapter
4375     )
4376 {
4377     UINT_8 ucCmdSeqNum;
4378     P_CMD_INFO_T prCmdInfo;
4379     P_WIFI_CMD_T prWifiCmd;
4380     UINT_32 u4RxPktLength;
4381     UINT_8 aucBuffer[sizeof(WIFI_EVENT_T) + sizeof(EVENT_NIC_CAPABILITY)];
4382     P_HIF_RX_HEADER_T prHifRxHdr;
4383     P_WIFI_EVENT_T prEvent;
4384     P_EVENT_NIC_CAPABILITY prEventNicCapability;
4385
4386     ASSERT(prAdapter);
4387
4388     DEBUGFUNC("wlanQueryNicCapability");
4389
4390     // 1. Allocate CMD Info Packet and its Buffer
4391     prCmdInfo = cmdBufAllocateCmdInfo(prAdapter, CMD_HDR_SIZE + sizeof(EVENT_NIC_CAPABILITY));
4392     if (!prCmdInfo) {
4393         DBGLOG(INIT, ERROR, ("Allocate CMD_INFO_T ==> FAILED.\n"));
4394         return WLAN_STATUS_FAILURE;
4395     }
4396
4397     // increase command sequence number
4398     ucCmdSeqNum = nicIncreaseCmdSeqNum(prAdapter);
4399
4400     // compose CMD_BUILD_CONNECTION cmd pkt
4401     prCmdInfo->eCmdType = COMMAND_TYPE_GENERAL_IOCTL;
4402     prCmdInfo->u2InfoBufLen = CMD_HDR_SIZE + sizeof(EVENT_NIC_CAPABILITY);
4403     prCmdInfo->pfCmdDoneHandler = NULL;
4404     prCmdInfo->fgIsOid = FALSE;
4405     prCmdInfo->ucCID = CMD_ID_GET_NIC_CAPABILITY;
4406     prCmdInfo->fgSetQuery = FALSE;
4407     prCmdInfo->fgNeedResp = TRUE;
4408     prCmdInfo->fgDriverDomainMCR = FALSE;
4409     prCmdInfo->ucCmdSeqNum = ucCmdSeqNum;
4410     prCmdInfo->u4SetInfoLen = 0;
4411
4412     // Setup WIFI_CMD_T
4413     prWifiCmd = (P_WIFI_CMD_T)(prCmdInfo->pucInfoBuffer);
4414     prWifiCmd->u2TxByteCount_UserPriority = prCmdInfo->u2InfoBufLen;
4415     prWifiCmd->ucCID = prCmdInfo->ucCID;
4416     prWifiCmd->ucSetQuery = prCmdInfo->fgSetQuery;
4417     prWifiCmd->ucSeqNum = prCmdInfo->ucCmdSeqNum;
4418
4419     wlanSendCommand(prAdapter, prCmdInfo);
4420     cmdBufFreeCmdInfo(prAdapter, prCmdInfo);
4421
4422     if(nicRxWaitResponse(prAdapter,
4423                 1,
4424                 aucBuffer,
4425                 sizeof(WIFI_EVENT_T) + sizeof(EVENT_NIC_CAPABILITY),
4426                 &u4RxPktLength) != WLAN_STATUS_SUCCESS) {
4427         return WLAN_STATUS_FAILURE;
4428     }
4429
4430     // header checking ..
4431     prHifRxHdr = (P_HIF_RX_HEADER_T)aucBuffer;
4432     if(prHifRxHdr->u2PacketType != HIF_RX_PKT_TYPE_EVENT) {
4433         return WLAN_STATUS_FAILURE;
4434     }
4435
4436     prEvent = (P_WIFI_EVENT_T)aucBuffer;
4437     if(prEvent->ucEID != EVENT_ID_NIC_CAPABILITY) {
4438         return WLAN_STATUS_FAILURE;
4439     }
4440
4441     prEventNicCapability = (P_EVENT_NIC_CAPABILITY)(prEvent->aucBuffer);
4442
4443     prAdapter->rVerInfo.u2FwProductID     = prEventNicCapability->u2ProductID;
4444     prAdapter->rVerInfo.u2FwOwnVersion    = prEventNicCapability->u2FwVersion;
4445     prAdapter->rVerInfo.u2FwPeerVersion   = prEventNicCapability->u2DriverVersion;
4446     prAdapter->fgIsHw5GBandDisabled       = (BOOLEAN)prEventNicCapability->ucHw5GBandDisabled;
4447     prAdapter->fgIsEepromUsed             = (BOOLEAN)prEventNicCapability->ucEepromUsed;
4448     prAdapter->fgIsEfuseValid             = (BOOLEAN)prEventNicCapability->ucEfuseValid;
4449     prAdapter->fgIsEmbbededMacAddrValid   = (BOOLEAN)prEventNicCapability->ucMacAddrValid;
4450
4451
4452 #if CFG_ENABLE_CAL_LOG
4453     DBGLOG(INIT, INFO, (" RF CAL FAIL  = (%d),BB CAL FAIL  = (%d)\n",
4454             prEventNicCapability->ucRfCalFail ,prEventNicCapability->ucBbCalFail ));
4455 #endif
4456     return WLAN_STATUS_SUCCESS;
4457 }
4458
4459 #ifdef MT6628
4460 static INT_32 wlanChangeCodeWord(INT_32 au4Input){
4461
4462     UINT_16     i;
4463 #if TXPWR_USE_PDSLOPE
4464     CODE_MAPPING_T arCodeTable[] = {
4465         {0X100,    -40},
4466         {0X104,    -35},
4467         {0X128,    -30},
4468         {0X14C,    -25},
4469         {0X170,    -20},
4470         {0X194,    -15},
4471         {0X1B8,    -10},
4472         {0X1DC,    - 5},
4473         {0    ,      0},
4474         {0X24 ,      5},
4475         {0X48 ,     10},
4476         {0X6C ,     15},
4477         {0X90 ,     20},
4478         {0XB4 ,     25},
4479         {0XD8 ,     30},
4480         {0XFC ,     35},
4481         {0XFF ,     40},
4482
4483     };
4484 #else
4485     CODE_MAPPING_T arCodeTable[] = {
4486         {0X100,    0x80},
4487         {0X104,    0x80},
4488         {0X128,    0x80},
4489         {0X14C,    0x80},
4490         {0X170,    0x80},
4491         {0X194,    0x94},
4492         {0X1B8,    0XB8},
4493         {0X1DC,    0xDC},
4494         {0     ,      0},
4495         {0X24 ,    0x24},
4496         {0X48 ,    0x48},
4497         {0X6C ,    0x6c},
4498         {0X90 ,    0x7F},
4499         {0XB4 ,    0x7F},
4500         {0XD8 ,    0x7F},
4501         {0XFC ,    0x7F},
4502         {0XFF ,    0x7F},
4503
4504     };
4505 #endif
4506
4507     for (i = 0; i < sizeof(arCodeTable) / sizeof(CODE_MAPPING_T); i++) {
4508
4509         if (arCodeTable[i].u4RegisterValue == au4Input){
4510             return arCodeTable[i] .u4TxpowerOffset;
4511         }
4512     }
4513
4514
4515     return 0;
4516 }
4517 #endif
4518 #if TXPWR_USE_PDSLOPE
4519
4520 /*----------------------------------------------------------------------------*/
4521 /*!
4522 * @brief
4523 *
4524 * @param prAdapter      Pointer of Adapter Data Structure
4525 *
4526 * @return WLAN_STATUS_SUCCESS
4527 *         WLAN_STATUS_FAILURE
4528 */
4529 /*----------------------------------------------------------------------------*/
4530 WLAN_STATUS
4531 wlanQueryPdMcr(
4532     IN P_ADAPTER_T prAdapter,
4533     P_PARAM_MCR_RW_STRUC_T prMcrRdInfo
4534     )
4535 {
4536     UINT_8 ucCmdSeqNum;
4537     P_CMD_INFO_T prCmdInfo;
4538     P_WIFI_CMD_T prWifiCmd;
4539     UINT_32 u4RxPktLength;
4540     UINT_8 aucBuffer[sizeof(WIFI_EVENT_T) + sizeof(CMD_ACCESS_REG)];
4541     P_HIF_RX_HEADER_T prHifRxHdr;
4542     P_WIFI_EVENT_T prEvent;
4543     P_CMD_ACCESS_REG prCmdMcrQuery;
4544     ASSERT(prAdapter);
4545
4546
4547     // 1. Allocate CMD Info Packet and its Buffer
4548     prCmdInfo = cmdBufAllocateCmdInfo(prAdapter, CMD_HDR_SIZE + sizeof(CMD_ACCESS_REG));
4549
4550     if (!prCmdInfo) {
4551         DBGLOG(INIT, ERROR, ("Allocate CMD_INFO_T ==> FAILED.\n"));
4552         return WLAN_STATUS_FAILURE;
4553     }
4554     // increase command sequence number
4555     ucCmdSeqNum = nicIncreaseCmdSeqNum(prAdapter);
4556
4557     // compose CMD_BUILD_CONNECTION cmd pkt
4558     prCmdInfo->eCmdType = COMMAND_TYPE_GENERAL_IOCTL;
4559     prCmdInfo->u2InfoBufLen = (UINT_16)(CMD_HDR_SIZE + sizeof(CMD_ACCESS_REG));
4560     prCmdInfo->pfCmdDoneHandler = NULL;
4561     prCmdInfo->pfCmdTimeoutHandler = nicOidCmdTimeoutCommon;
4562     prCmdInfo->fgIsOid = FALSE;
4563     prCmdInfo->ucCID = CMD_ID_ACCESS_REG;
4564     prCmdInfo->fgSetQuery = FALSE;
4565     prCmdInfo->fgNeedResp = TRUE;
4566     prCmdInfo->fgDriverDomainMCR = FALSE;
4567     prCmdInfo->ucCmdSeqNum = ucCmdSeqNum;
4568     prCmdInfo->u4SetInfoLen = sizeof(CMD_ACCESS_REG);
4569
4570     // Setup WIFI_CMD_T
4571     prWifiCmd = (P_WIFI_CMD_T)(prCmdInfo->pucInfoBuffer);
4572     prWifiCmd->u2TxByteCount_UserPriority = prCmdInfo->u2InfoBufLen;
4573     prWifiCmd->ucCID = prCmdInfo->ucCID;
4574     prWifiCmd->ucSetQuery = prCmdInfo->fgSetQuery;
4575     prWifiCmd->ucSeqNum = prCmdInfo->ucCmdSeqNum;
4576     kalMemCopy(prWifiCmd->aucBuffer, prMcrRdInfo, sizeof(CMD_ACCESS_REG));
4577
4578     wlanSendCommand(prAdapter, prCmdInfo);
4579     cmdBufFreeCmdInfo(prAdapter, prCmdInfo);
4580
4581     if(nicRxWaitResponse(prAdapter,
4582                 1,
4583                 aucBuffer,
4584                 sizeof(WIFI_EVENT_T) + sizeof(CMD_ACCESS_REG),
4585                 &u4RxPktLength) != WLAN_STATUS_SUCCESS) {
4586         return WLAN_STATUS_FAILURE;
4587     }
4588
4589     // header checking ..
4590     prHifRxHdr = (P_HIF_RX_HEADER_T)aucBuffer;
4591     if(prHifRxHdr->u2PacketType != HIF_RX_PKT_TYPE_EVENT) {
4592         return WLAN_STATUS_FAILURE;
4593     }
4594
4595
4596     prEvent = (P_WIFI_EVENT_T)aucBuffer;
4597
4598     if(prEvent->ucEID != EVENT_ID_ACCESS_REG) {
4599         return WLAN_STATUS_FAILURE;
4600     }
4601
4602     prCmdMcrQuery = (P_CMD_ACCESS_REG)(prEvent->aucBuffer);
4603     prMcrRdInfo->u4McrOffset = prCmdMcrQuery->u4Address;
4604     prMcrRdInfo->u4McrData = prCmdMcrQuery->u4Data;
4605
4606     return WLAN_STATUS_SUCCESS;
4607 }
4608
4609 static INT_32 wlanIntRound(INT_32 au4Input)
4610 {
4611
4612
4613     if (au4Input >= 0){
4614         if((au4Input%10) == 5){
4615             au4Input = au4Input + 5;
4616             return au4Input;
4617         }
4618     }
4619
4620     if (au4Input < 0){
4621         if((au4Input%10) == -5){
4622             au4Input = au4Input - 5;
4623             return au4Input;
4624         }
4625     }
4626
4627     return au4Input;
4628 }
4629
4630 static INT_32 wlanCal6628EfuseForm(IN P_ADAPTER_T prAdapter,INT_32 au4Input){
4631
4632     PARAM_MCR_RW_STRUC_T rMcrRdInfo;
4633     INT_32         au4PdSlope,au4TxPwrOffset,au4TxPwrOffset_Round;
4634     INT_8          auTxPwrOffset_Round;
4635
4636     rMcrRdInfo.u4McrOffset = 0x60205c68;
4637     rMcrRdInfo.u4McrData = 0;
4638     au4TxPwrOffset = au4Input;
4639     wlanQueryPdMcr(prAdapter,&rMcrRdInfo);
4640
4641     au4PdSlope =  (rMcrRdInfo.u4McrData) & BITS(0,6);
4642     au4TxPwrOffset_Round = wlanIntRound((au4TxPwrOffset*au4PdSlope))/10;
4643
4644     au4TxPwrOffset_Round = -au4TxPwrOffset_Round;
4645
4646     if(au4TxPwrOffset_Round < -128) {
4647         au4TxPwrOffset_Round = 128;
4648     }
4649     else if (au4TxPwrOffset_Round < 0){
4650         au4TxPwrOffset_Round += 256;
4651     }
4652     else if (au4TxPwrOffset_Round > 127){
4653         au4TxPwrOffset_Round = 127;
4654     }
4655
4656     auTxPwrOffset_Round = (UINT8) au4TxPwrOffset_Round ;
4657
4658     return au4TxPwrOffset_Round;
4659 }
4660
4661 #endif
4662
4663 #ifdef MT6628
4664 static VOID wlanChangeNvram6620to6628(PUINT_8 pucEFUSE){
4665
4666
4667     #define EFUSE_CH_OFFSET1_L_MASK_6620         BITS(0,8)
4668     #define EFUSE_CH_OFFSET1_L_SHIFT_6620        0
4669     #define EFUSE_CH_OFFSET1_M_MASK_6620         BITS(9,17)
4670     #define EFUSE_CH_OFFSET1_M_SHIFT_6620        9
4671     #define EFUSE_CH_OFFSET1_H_MASK_6620         BITS(18,26)
4672     #define EFUSE_CH_OFFSET1_H_SHIFT_6620        18
4673     #define EFUSE_CH_OFFSET1_VLD_MASK_6620       BIT(27)
4674     #define EFUSE_CH_OFFSET1_VLD_SHIFT_6620      27
4675
4676     #define EFUSE_CH_OFFSET1_L_MASK_5931         BITS(0,7)
4677     #define EFUSE_CH_OFFSET1_L_SHIFT_5931        0
4678     #define EFUSE_CH_OFFSET1_M_MASK_5931         BITS(8,15)
4679     #define EFUSE_CH_OFFSET1_M_SHIFT_5931        8
4680     #define EFUSE_CH_OFFSET1_H_MASK_5931         BITS(16,23)
4681     #define EFUSE_CH_OFFSET1_H_SHIFT_5931        16
4682     #define EFUSE_CH_OFFSET1_VLD_MASK_5931       BIT(24)
4683     #define EFUSE_CH_OFFSET1_VLD_SHIFT_5931      24
4684     #define EFUSE_ALL_CH_OFFSET1_MASK_5931       BITS(25,27)
4685     #define EFUSE_ALL_CH_OFFSET1_SHIFT_5931      25
4686
4687
4688
4689
4690     INT_32         au4ChOffset;
4691     INT_16         au2ChOffsetL,au2ChOffsetM,au2ChOffsetH;
4692
4693
4694         au4ChOffset = *(UINT_32*)(pucEFUSE + 72);
4695
4696         if((au4ChOffset & EFUSE_CH_OFFSET1_VLD_MASK_6620) && ((*(UINT_32*)(pucEFUSE + 28)) == 0)) {
4697
4698
4699         au2ChOffsetL = ((au4ChOffset & EFUSE_CH_OFFSET1_L_MASK_6620) >>
4700             EFUSE_CH_OFFSET1_L_SHIFT_6620);
4701
4702         au2ChOffsetM = ((au4ChOffset & EFUSE_CH_OFFSET1_M_MASK_6620) >>
4703             EFUSE_CH_OFFSET1_M_SHIFT_6620);
4704
4705         au2ChOffsetH = ((au4ChOffset & EFUSE_CH_OFFSET1_H_MASK_6620) >>
4706             EFUSE_CH_OFFSET1_H_SHIFT_6620);
4707
4708             au2ChOffsetL = wlanChangeCodeWord(au2ChOffsetL);
4709             au2ChOffsetM = wlanChangeCodeWord(au2ChOffsetM);
4710             au2ChOffsetH = wlanChangeCodeWord(au2ChOffsetH);
4711
4712             au4ChOffset =  0;
4713             au4ChOffset |=  *(UINT_32*)(pucEFUSE + 72)
4714                 >> (EFUSE_CH_OFFSET1_VLD_SHIFT_6620 - EFUSE_CH_OFFSET1_VLD_SHIFT_5931 )& EFUSE_CH_OFFSET1_VLD_MASK_5931 ;
4715
4716
4717
4718             au4ChOffset |= ((((UINT_32)au2ChOffsetL) << EFUSE_CH_OFFSET1_L_SHIFT_5931) & EFUSE_CH_OFFSET1_L_MASK_5931);
4719             au4ChOffset |= ((((UINT_32)au2ChOffsetM) << EFUSE_CH_OFFSET1_M_SHIFT_5931) & EFUSE_CH_OFFSET1_M_MASK_5931);
4720             au4ChOffset |= ((((UINT_32)au2ChOffsetH) << EFUSE_CH_OFFSET1_H_SHIFT_5931) & EFUSE_CH_OFFSET1_H_MASK_5931);
4721
4722             *((INT_32 *)((pucEFUSE + 28))) = au4ChOffset ;
4723
4724
4725
4726     }
4727
4728 }
4729 #endif
4730
4731 /*----------------------------------------------------------------------------*/
4732 /*!
4733 * @brief This function is called to load manufacture data from NVRAM
4734 * if available and valid
4735 *
4736 * @param prAdapter      Pointer of Adapter Data Structure
4737 * @param prRegInfo      Pointer of REG_INFO_T
4738 *
4739 * @return WLAN_STATUS_SUCCESS
4740 *         WLAN_STATUS_FAILURE
4741 */
4742 /*----------------------------------------------------------------------------*/
4743 WLAN_STATUS
4744 wlanLoadManufactureData (
4745     IN P_ADAPTER_T prAdapter,
4746     IN P_REG_INFO_T prRegInfo
4747     )
4748 {
4749 #if CFG_SUPPORT_RDD_TEST_MODE
4750     CMD_RDD_CH_T rRddParam;
4751 #endif
4752
4753     ASSERT(prAdapter);
4754
4755     /* 1. Version Check */
4756     kalGetConfigurationVersion(prAdapter->prGlueInfo,
4757             &(prAdapter->rVerInfo.u2Part1CfgOwnVersion),
4758             &(prAdapter->rVerInfo.u2Part1CfgPeerVersion),
4759             &(prAdapter->rVerInfo.u2Part2CfgOwnVersion),
4760             &(prAdapter->rVerInfo.u2Part2CfgPeerVersion));
4761
4762 #if (CFG_SW_NVRAM_VERSION_CHECK == 1)
4763     if(CFG_DRV_OWN_VERSION < prAdapter->rVerInfo.u2Part1CfgPeerVersion
4764             || CFG_DRV_OWN_VERSION < prAdapter->rVerInfo.u2Part2CfgPeerVersion
4765             || prAdapter->rVerInfo.u2Part1CfgOwnVersion < CFG_DRV_PEER_VERSION
4766             || prAdapter->rVerInfo.u2Part2CfgOwnVersion < CFG_DRV_PEER_VERSION) {
4767         return WLAN_STATUS_FAILURE;
4768     }
4769 #endif
4770
4771     // MT6620 E1/E2 would be ignored directly
4772     if(prAdapter->rVerInfo.u2Part1CfgOwnVersion == 0x0001) {
4773         prRegInfo->ucTxPwrValid = 1;
4774     }
4775     else {
4776         /* 2. Load TX power gain parameters if valid */
4777         if(prRegInfo->ucTxPwrValid != 0) {
4778             // send to F/W
4779             nicUpdateTxPower(prAdapter, (P_CMD_TX_PWR_T)(&(prRegInfo->rTxPwr)));
4780         }
4781     }
4782
4783     /* 3. Check if needs to support 5GHz */
4784     if(prRegInfo->ucEnable5GBand) {
4785         // check if it is disabled by hardware
4786         if(prAdapter->fgIsHw5GBandDisabled
4787                 || prRegInfo->ucSupport5GBand == 0) {
4788             prAdapter->fgEnable5GBand = FALSE;
4789         }
4790         else {
4791             prAdapter->fgEnable5GBand = TRUE;
4792         }
4793     }
4794     else {
4795         prAdapter->fgEnable5GBand = FALSE;
4796     }
4797
4798     /* 4. Send EFUSE data */
4799 #if  defined(MT6628)
4800     wlanChangeNvram6620to6628(prRegInfo->aucEFUSE);
4801 #endif
4802
4803     wlanSendSetQueryCmd(prAdapter,
4804             CMD_ID_SET_PHY_PARAM,
4805             TRUE,
4806             FALSE,
4807             FALSE,
4808             NULL,
4809             NULL,
4810             sizeof(CMD_PHY_PARAM_T),
4811             (PUINT_8)(prRegInfo->aucEFUSE),
4812             NULL,
4813             0);
4814
4815 #if CFG_SUPPORT_RDD_TEST_MODE
4816     rRddParam.ucRddTestMode = (UINT_8) prRegInfo->u4RddTestMode;
4817     rRddParam.ucRddShutCh = (UINT_8) prRegInfo->u4RddShutFreq;
4818     rRddParam.ucRddStartCh = (UINT_8) nicFreq2ChannelNum(prRegInfo->u4RddStartFreq);
4819     rRddParam.ucRddStopCh = (UINT_8) nicFreq2ChannelNum(prRegInfo->u4RddStopFreq);
4820     rRddParam.ucRddDfs = (UINT_8) prRegInfo->u4RddDfs;
4821     prAdapter->ucRddStatus = 0;
4822     nicUpdateRddTestMode(prAdapter, (P_CMD_RDD_CH_T)(&rRddParam));
4823 #endif
4824
4825     /* 5. Get 16-bits Country Code and Bandwidth */
4826     prAdapter->rWifiVar.rConnSettings.u2CountryCode =
4827         (((UINT_16) prRegInfo->au2CountryCode[0]) << 8) |
4828         (((UINT_16) prRegInfo->au2CountryCode[1]) & BITS(0,7));
4829
4830 #if 0 /* Bandwidth control will be controlled by GUI. 20110930
4831        * So ignore the setting from registry/NVRAM
4832        */
4833     prAdapter->rWifiVar.rConnSettings.uc2G4BandwidthMode =
4834             prRegInfo->uc2G4BwFixed20M ? CONFIG_BW_20M : CONFIG_BW_20_40M;
4835     prAdapter->rWifiVar.rConnSettings.uc5GBandwidthMode =
4836             prRegInfo->uc5GBwFixed20M ? CONFIG_BW_20M : CONFIG_BW_20_40M;
4837 #endif
4838
4839     /* 6. Set domain and channel information to chip */
4840     rlmDomainSendCmd(prAdapter, FALSE);
4841
4842     /* 7. set band edge tx power if available */
4843     if(prRegInfo->fg2G4BandEdgePwrUsed) {
4844         CMD_EDGE_TXPWR_LIMIT_T rCmdEdgeTxPwrLimit;
4845
4846         rCmdEdgeTxPwrLimit.cBandEdgeMaxPwrCCK
4847             = prRegInfo->cBandEdgeMaxPwrCCK;
4848         rCmdEdgeTxPwrLimit.cBandEdgeMaxPwrOFDM20
4849             = prRegInfo->cBandEdgeMaxPwrOFDM20;
4850         rCmdEdgeTxPwrLimit.cBandEdgeMaxPwrOFDM40
4851             = prRegInfo->cBandEdgeMaxPwrOFDM40;
4852
4853         wlanSendSetQueryCmd(prAdapter,
4854                 CMD_ID_SET_EDGE_TXPWR_LIMIT,
4855                 TRUE,
4856                 FALSE,
4857                 FALSE,
4858                 NULL,
4859                 NULL,
4860                 sizeof(CMD_EDGE_TXPWR_LIMIT_T),
4861                 (PUINT_8)&rCmdEdgeTxPwrLimit,
4862                 NULL,
4863                 0);
4864     }
4865
4866     return WLAN_STATUS_SUCCESS;
4867 }
4868
4869
4870 /*----------------------------------------------------------------------------*/
4871 /*!
4872 * @brief This function is called to check
4873 *        Media Stream Mode is set to non-default value or not,
4874 *        and clear to default value if above criteria is met
4875 *
4876 * @param prAdapter      Pointer of Adapter Data Structure
4877 *
4878 * @return TRUE
4879 *           The media stream mode was non-default value and has been reset
4880 *         FALSE
4881 *           The media stream mode is default value
4882 */
4883 /*----------------------------------------------------------------------------*/
4884 BOOLEAN
4885 wlanResetMediaStreamMode(
4886     IN P_ADAPTER_T prAdapter
4887     )
4888 {
4889     ASSERT(prAdapter);
4890
4891     if(prAdapter->rWlanInfo.eLinkAttr.ucMediaStreamMode != 0) {
4892         prAdapter->rWlanInfo.eLinkAttr.ucMediaStreamMode = 0;
4893
4894         return TRUE;
4895     }
4896     else {
4897         return FALSE;
4898     }
4899 }
4900
4901
4902 /*----------------------------------------------------------------------------*/
4903 /*!
4904 * @brief This function is called to check if any pending timer has expired
4905 *
4906 * @param prAdapter      Pointer of Adapter Data Structure
4907 *
4908 * @return WLAN_STATUS_SUCCESS
4909 */
4910 /*----------------------------------------------------------------------------*/
4911 WLAN_STATUS
4912 wlanTimerTimeoutCheck(
4913     IN P_ADAPTER_T prAdapter
4914     )
4915 {
4916     ASSERT(prAdapter);
4917
4918     cnmTimerDoTimeOutCheck(prAdapter);
4919
4920     return WLAN_STATUS_SUCCESS;
4921 }
4922
4923
4924 /*----------------------------------------------------------------------------*/
4925 /*!
4926 * @brief This function is called to check if any pending mailbox message
4927 *        to be handled
4928 *
4929 * @param prAdapter      Pointer of Adapter Data Structure
4930 *
4931 * @return WLAN_STATUS_SUCCESS
4932 */
4933 /*----------------------------------------------------------------------------*/
4934 WLAN_STATUS
4935 wlanProcessMboxMessage(
4936     IN P_ADAPTER_T prAdapter
4937     )
4938 {
4939     UINT_32 i;
4940
4941     ASSERT(prAdapter);
4942
4943     for(i = 0 ; i < MBOX_ID_TOTAL_NUM ; i++) {
4944        mboxRcvAllMsg(prAdapter , (ENUM_MBOX_ID_T)i);
4945     }
4946
4947     return WLAN_STATUS_SUCCESS;
4948 }
4949
4950
4951 /*----------------------------------------------------------------------------*/
4952 /*!
4953 * @brief This function is called to enqueue a single TX packet into CORE
4954 *
4955 * @param prAdapter      Pointer of Adapter Data Structure
4956 *        prNativePacket Pointer of Native Packet
4957 *
4958 * @return WLAN_STATUS_SUCCESS
4959 *         WLAN_STATUS_RESOURCES
4960 *         WLAN_STATUS_INVALID_PACKET
4961 */
4962 /*----------------------------------------------------------------------------*/
4963 WLAN_STATUS
4964 wlanEnqueueTxPacket (
4965     IN P_ADAPTER_T      prAdapter,
4966     IN P_NATIVE_PACKET  prNativePacket
4967     )
4968 {
4969     P_TX_CTRL_T prTxCtrl;
4970     P_MSDU_INFO_T prMsduInfo;
4971
4972     KAL_SPIN_LOCK_DECLARATION();
4973
4974     ASSERT(prAdapter);
4975
4976     prTxCtrl = &prAdapter->rTxCtrl;
4977
4978     KAL_ACQUIRE_SPIN_LOCK(prAdapter, SPIN_LOCK_TX_MSDU_INFO_LIST);
4979     QUEUE_REMOVE_HEAD(&prTxCtrl->rFreeMsduInfoList, prMsduInfo, P_MSDU_INFO_T);
4980     KAL_RELEASE_SPIN_LOCK(prAdapter, SPIN_LOCK_TX_MSDU_INFO_LIST);
4981
4982     if(prMsduInfo == NULL) {
4983         return WLAN_STATUS_RESOURCES;
4984     }
4985     else {
4986         prMsduInfo->eSrc = TX_PACKET_OS;
4987
4988         if(nicTxFillMsduInfo(prAdapter,
4989                     prMsduInfo,
4990                     prNativePacket) == FALSE) { // packet is not extractable
4991             kalSendComplete(prAdapter->prGlueInfo,
4992                     prNativePacket,
4993                     WLAN_STATUS_INVALID_PACKET);
4994
4995             nicTxReturnMsduInfo(prAdapter, prMsduInfo);
4996
4997             return WLAN_STATUS_INVALID_PACKET;
4998         }
4999         else {
5000             // enqueue to QM
5001             nicTxEnqueueMsdu(prAdapter, prMsduInfo);
5002
5003             return WLAN_STATUS_SUCCESS;
5004         }
5005     }
5006 }
5007
5008
5009 /*----------------------------------------------------------------------------*/
5010 /*!
5011 * @brief This function is called to flush pending TX packets in CORE
5012 *
5013 * @param prAdapter      Pointer of Adapter Data Structure
5014 *
5015 * @return WLAN_STATUS_SUCCESS
5016 */
5017 /*----------------------------------------------------------------------------*/
5018 WLAN_STATUS
5019 wlanFlushTxPendingPackets(
5020     IN P_ADAPTER_T prAdapter
5021     )
5022 {
5023     ASSERT(prAdapter);
5024
5025     return nicTxFlush(prAdapter);
5026 }
5027
5028
5029 /*----------------------------------------------------------------------------*/
5030 /*!
5031 * \brief this function sends pending MSDU_INFO_T to MT6620
5032 *
5033 * @param prAdapter      Pointer to the Adapter structure.
5034 * @param pfgHwAccess    Pointer for tracking LP-OWN status
5035 *
5036 * @retval WLAN_STATUS_SUCCESS   Reset is done successfully.
5037 */
5038 /*----------------------------------------------------------------------------*/
5039 WLAN_STATUS
5040 wlanTxPendingPackets (
5041     IN      P_ADAPTER_T prAdapter,
5042     IN OUT  PBOOLEAN    pfgHwAccess
5043     )
5044 {
5045     P_TX_CTRL_T prTxCtrl;
5046     P_MSDU_INFO_T prMsduInfo;
5047
5048     KAL_SPIN_LOCK_DECLARATION();
5049
5050     ASSERT(prAdapter);
5051     prTxCtrl = &prAdapter->rTxCtrl;
5052
5053     ASSERT(pfgHwAccess);
5054
5055     // <1> dequeue packet by txDequeuTxPackets()
5056     KAL_ACQUIRE_SPIN_LOCK(prAdapter, SPIN_LOCK_QM_TX_QUEUE);
5057     prMsduInfo = qmDequeueTxPackets(prAdapter, &prTxCtrl->rTc);
5058     KAL_RELEASE_SPIN_LOCK(prAdapter, SPIN_LOCK_QM_TX_QUEUE);
5059
5060     if(prMsduInfo != NULL) {
5061         if(kalIsCardRemoved(prAdapter->prGlueInfo) == FALSE) {
5062             /* <2> Acquire LP-OWN if necessary */
5063             if(*pfgHwAccess == FALSE) {
5064                 *pfgHwAccess = TRUE;
5065
5066                 wlanAcquirePowerControl(prAdapter);
5067             }
5068
5069 #if (MT6620_E1_ASIC_HIFSYS_WORKAROUND == 1)
5070             if(prAdapter->fgIsClockGatingEnabled == TRUE) {
5071                 nicDisableClockGating(prAdapter);
5072             }
5073 #endif
5074             // <3> send packets
5075             nicTxMsduInfoList(prAdapter, prMsduInfo);
5076
5077             // <4> update TC by txAdjustTcQuotas()
5078             nicTxAdjustTcq(prAdapter);
5079         }
5080         else {
5081             wlanProcessQueuedMsduInfo(prAdapter, prMsduInfo);
5082         }
5083     }
5084
5085 #if (MT6620_E1_ASIC_HIFSYS_WORKAROUND == 1)
5086     if(prAdapter->fgIsClockGatingEnabled == FALSE) {
5087         nicEnableClockGating(prAdapter);
5088     }
5089 #endif
5090
5091     return WLAN_STATUS_SUCCESS;
5092 }
5093
5094
5095 /*----------------------------------------------------------------------------*/
5096 /*!
5097 * @brief This function is called to acquire power control from firmware
5098 *
5099 * @param prAdapter      Pointer of Adapter Data Structure
5100 *
5101 * @return WLAN_STATUS_SUCCESS
5102 */
5103 /*----------------------------------------------------------------------------*/
5104 WLAN_STATUS
5105 wlanAcquirePowerControl(
5106     IN P_ADAPTER_T prAdapter
5107     )
5108 {
5109     ASSERT(prAdapter);
5110
5111     ACQUIRE_POWER_CONTROL_FROM_PM(prAdapter);
5112
5113     /* Reset sleepy state */
5114     if(prAdapter->fgWiFiInSleepyState == TRUE) {
5115         prAdapter->fgWiFiInSleepyState = FALSE;
5116     }
5117
5118     return WLAN_STATUS_SUCCESS;
5119 }
5120
5121
5122 /*----------------------------------------------------------------------------*/
5123 /*!
5124 * @brief This function is called to release power control to firmware
5125 *
5126 * @param prAdapter      Pointer of Adapter Data Structure
5127 *
5128 * @return WLAN_STATUS_SUCCESS
5129 */
5130 /*----------------------------------------------------------------------------*/
5131 WLAN_STATUS
5132 wlanReleasePowerControl(
5133     IN P_ADAPTER_T prAdapter
5134     )
5135 {
5136     ASSERT(prAdapter);
5137
5138     RECLAIM_POWER_CONTROL_TO_PM(prAdapter, FALSE);
5139
5140     return WLAN_STATUS_SUCCESS;
5141 }
5142
5143
5144 /*----------------------------------------------------------------------------*/
5145 /*!
5146 * @brief This function is called to report currently pending TX frames count
5147 *        (command packets are not included)
5148 *
5149 * @param prAdapter      Pointer of Adapter Data Structure
5150 *
5151 * @return number of pending TX frames
5152 */
5153 /*----------------------------------------------------------------------------*/
5154 UINT_32
5155 wlanGetTxPendingFrameCount (
5156     IN P_ADAPTER_T prAdapter
5157     )
5158 {
5159     P_TX_CTRL_T prTxCtrl;
5160     UINT_32 u4Num;
5161
5162     ASSERT(prAdapter);
5163     prTxCtrl = &prAdapter->rTxCtrl;
5164
5165     u4Num = kalGetTxPendingFrameCount(prAdapter->prGlueInfo) + (UINT_32)(prTxCtrl->i4PendingFwdFrameCount);
5166
5167     return u4Num;
5168 }
5169
5170
5171 /*----------------------------------------------------------------------------*/
5172 /*!
5173 * @brief This function is to report current ACPI state
5174 *
5175 * @param prAdapter      Pointer of Adapter Data Structure
5176 *
5177 * @return ACPI_STATE_D0 Normal Operation Mode
5178 *         ACPI_STATE_D3 Suspend Mode
5179 */
5180 /*----------------------------------------------------------------------------*/
5181 ENUM_ACPI_STATE_T
5182 wlanGetAcpiState (
5183     IN P_ADAPTER_T prAdapter
5184     )
5185 {
5186     ASSERT(prAdapter);
5187
5188     return prAdapter->rAcpiState;
5189 }
5190
5191
5192 /*----------------------------------------------------------------------------*/
5193 /*!
5194 * @brief This function is to update current ACPI state only
5195 *
5196 * @param prAdapter      Pointer of Adapter Data Structure
5197 * @param ePowerState    ACPI_STATE_D0 Normal Operation Mode
5198 *                       ACPI_STATE_D3 Suspend Mode
5199 *
5200 * @return none
5201 */
5202 /*----------------------------------------------------------------------------*/
5203 VOID
5204 wlanSetAcpiState (
5205     IN P_ADAPTER_T prAdapter,
5206     IN ENUM_ACPI_STATE_T ePowerState
5207     )
5208 {
5209     ASSERT(prAdapter);
5210     ASSERT(ePowerState <= ACPI_STATE_D3);
5211
5212     prAdapter->rAcpiState = ePowerState;
5213
5214     return;
5215 }
5216
5217
5218 /*----------------------------------------------------------------------------*/
5219 /*!
5220 * @brief This function is to query ECO version from HIFSYS CR
5221 *
5222 * @param prAdapter      Pointer of Adapter Data Structure
5223 *
5224 * @return zero      Unable to retrieve ECO version information
5225 *         non-zero  ECO version (1-based)
5226 */
5227 /*----------------------------------------------------------------------------*/
5228 UINT_8
5229 wlanGetEcoVersion(
5230     IN P_ADAPTER_T prAdapter
5231     )
5232 {
5233     ASSERT(prAdapter);
5234
5235     if(nicVerifyChipID(prAdapter) == TRUE) {
5236         return (prAdapter->ucRevID + 1);
5237     }
5238     else {
5239         return 0;
5240     }
5241 }
5242
5243
5244 /*----------------------------------------------------------------------------*/
5245 /*!
5246 * @brief This function is to setting the default Tx Power configuration
5247 *
5248 * @param prAdapter      Pointer of Adapter Data Structure
5249 *
5250 * @return zero      Unable to retrieve ECO version information
5251 *         non-zero  ECO version (1-based)
5252 */
5253 /*----------------------------------------------------------------------------*/
5254 VOID
5255 wlanDefTxPowerCfg (
5256     IN P_ADAPTER_T      prAdapter
5257     )
5258 {
5259     UINT_8 i;
5260     P_GLUE_INFO_T       prGlueInfo = prAdapter->prGlueInfo;
5261     P_SET_TXPWR_CTRL_T  prTxpwr;
5262
5263     ASSERT(prGlueInfo);
5264
5265     prTxpwr = &prGlueInfo->rTxPwr;
5266
5267     prTxpwr->c2GLegacyStaPwrOffset = 0;
5268     prTxpwr->c2GHotspotPwrOffset = 0;
5269     prTxpwr->c2GP2pPwrOffset = 0;
5270     prTxpwr->c2GBowPwrOffset = 0;
5271     prTxpwr->c5GLegacyStaPwrOffset = 0;
5272     prTxpwr->c5GHotspotPwrOffset = 0;
5273     prTxpwr->c5GP2pPwrOffset = 0;
5274     prTxpwr->c5GBowPwrOffset = 0;
5275     prTxpwr->ucConcurrencePolicy = 0;
5276     for (i=0; i<3;i++)
5277         prTxpwr->acReserved1[i] = 0;
5278
5279     for (i=0; i<14;i++)
5280         prTxpwr->acTxPwrLimit2G[i] = 63;
5281
5282     for (i=0; i<4;i++)
5283         prTxpwr->acTxPwrLimit5G[i] = 63;
5284
5285     for (i=0; i<2;i++)
5286         prTxpwr->acReserved2[i] = 0;
5287
5288 }
5289
5290
5291 /*----------------------------------------------------------------------------*/
5292 /*!
5293 * @brief This function is to
5294 *        set preferred band configuration corresponding to network type
5295 *
5296 * @param prAdapter      Pointer of Adapter Data Structure
5297 * @param eBand          Given band
5298 * @param eNetTypeIndex  Given Network Type
5299 *
5300 * @return none
5301 */
5302 /*----------------------------------------------------------------------------*/
5303 VOID
5304 wlanSetPreferBandByNetwork (
5305     IN P_ADAPTER_T prAdapter,
5306     IN ENUM_BAND_T eBand,
5307     IN ENUM_NETWORK_TYPE_INDEX_T eNetTypeIndex
5308     )
5309 {
5310     ASSERT(prAdapter);
5311     ASSERT(eBand <= BAND_NUM);
5312     ASSERT(eNetTypeIndex <= NETWORK_TYPE_INDEX_NUM);
5313
5314     /* 1. set prefer band according to network type */
5315     prAdapter->aePreferBand[eNetTypeIndex] = eBand;
5316
5317     /* 2. remove buffered BSS descriptors correspondingly */
5318     if(eBand == BAND_2G4) {
5319         scanRemoveBssDescByBandAndNetwork(prAdapter, BAND_5G, eNetTypeIndex);
5320     }
5321     else if(eBand == BAND_5G) {
5322         scanRemoveBssDescByBandAndNetwork(prAdapter, BAND_2G4, eNetTypeIndex);
5323     }
5324
5325     return;
5326 }
5327
5328
5329 /*----------------------------------------------------------------------------*/
5330 /*!
5331 * @brief This function is to
5332 *        get channel information corresponding to specified network type
5333 *
5334 * @param prAdapter      Pointer of Adapter Data Structure
5335 * @param eNetTypeIndex  Given Network Type
5336 *
5337 * @return channel number
5338 */
5339 /*----------------------------------------------------------------------------*/
5340 UINT_8
5341 wlanGetChannelNumberByNetwork (
5342     IN P_ADAPTER_T prAdapter,
5343     IN ENUM_NETWORK_TYPE_INDEX_T eNetTypeIndex
5344     )
5345 {
5346     P_BSS_INFO_T prBssInfo;
5347
5348     ASSERT(prAdapter);
5349     ASSERT(eNetTypeIndex <= NETWORK_TYPE_INDEX_NUM);
5350
5351     prBssInfo = &(prAdapter->rWifiVar.arBssInfo[eNetTypeIndex]);
5352
5353     return prBssInfo->ucPrimaryChannel;
5354 }
5355
5356
5357 /*----------------------------------------------------------------------------*/
5358 /*!
5359 * @brief This function is to
5360 *        get BSS descriptor information corresponding to specified network type
5361 *
5362 * @param prAdapter      Pointer of Adapter Data Structure
5363 * @param eNetTypeIndex  Given Network Type
5364 *
5365 * @return pointer to BSS_DESC_T
5366 */
5367 /*----------------------------------------------------------------------------*/
5368 P_BSS_DESC_T
5369 wlanGetTargetBssDescByNetwork (
5370     IN P_ADAPTER_T prAdapter,
5371     IN ENUM_NETWORK_TYPE_INDEX_T eNetTypeIndex
5372     )
5373 {
5374     ASSERT(prAdapter);
5375     ASSERT(eNetTypeIndex <= NETWORK_TYPE_INDEX_NUM);
5376
5377     switch(eNetTypeIndex) {
5378     case NETWORK_TYPE_AIS_INDEX:
5379         return prAdapter->rWifiVar.rAisFsmInfo.prTargetBssDesc;
5380
5381     case NETWORK_TYPE_P2P_INDEX:
5382         return NULL;
5383
5384     case NETWORK_TYPE_BOW_INDEX:
5385         return prAdapter->rWifiVar.rBowFsmInfo.prTargetBssDesc;
5386
5387     default:
5388         return NULL;
5389     }
5390 }
5391
5392
5393 /*----------------------------------------------------------------------------*/
5394 /*!
5395 * @brief This function is to
5396 *        check unconfigured system properties and generate related message on
5397 *        scan list to notify users
5398 *
5399 * @param prAdapter      Pointer of Adapter Data Structure
5400 *
5401 * @return WLAN_STATUS_SUCCESS
5402 */
5403 /*----------------------------------------------------------------------------*/
5404 WLAN_STATUS
5405 wlanCheckSystemConfiguration (
5406     IN P_ADAPTER_T prAdapter
5407     )
5408 {
5409 #if (CFG_NVRAM_EXISTENCE_CHECK == 1) || (CFG_SW_NVRAM_VERSION_CHECK == 1)
5410     const UINT_8 aucZeroMacAddr[] = NULL_MAC_ADDR;
5411     const UINT_8 aucBCAddr[] = BC_MAC_ADDR;
5412     BOOLEAN fgIsConfExist = TRUE;
5413     BOOLEAN fgGenErrMsg = FALSE;
5414     P_REG_INFO_T prRegInfo = NULL;
5415     P_WLAN_BEACON_FRAME_T prBeacon = NULL;
5416     P_IE_SSID_T prSsid = NULL;
5417     UINT_32 u4ErrCode = 0;
5418     UINT_8 aucErrMsg[32];
5419     PARAM_SSID_T rSsid;
5420     PARAM_802_11_CONFIG_T rConfiguration;
5421     PARAM_RATES_EX rSupportedRates;
5422 #endif
5423
5424     DEBUGFUNC("wlanCheckSystemConfiguration");
5425
5426     ASSERT(prAdapter);
5427
5428 #if (CFG_NVRAM_EXISTENCE_CHECK == 1)
5429     if(kalIsConfigurationExist(prAdapter->prGlueInfo) == FALSE) {
5430         fgIsConfExist = FALSE;
5431         fgGenErrMsg = TRUE;
5432     }
5433 #endif
5434
5435 #if (CFG_SW_NVRAM_VERSION_CHECK == 1)
5436     prRegInfo = kalGetConfiguration(prAdapter->prGlueInfo);
5437
5438     if(fgIsConfExist == TRUE &&
5439             (CFG_DRV_OWN_VERSION < prAdapter->rVerInfo.u2Part1CfgPeerVersion
5440             || CFG_DRV_OWN_VERSION < prAdapter->rVerInfo.u2Part2CfgPeerVersion
5441             || prAdapter->rVerInfo.u2Part1CfgOwnVersion < CFG_DRV_PEER_VERSION
5442             || prAdapter->rVerInfo.u2Part2CfgOwnVersion < CFG_DRV_PEER_VERSION /* NVRAM */
5443             || CFG_DRV_OWN_VERSION < prAdapter->rVerInfo.u2FwPeerVersion
5444             || prAdapter->rVerInfo.u2FwOwnVersion < CFG_DRV_PEER_VERSION
5445             || (prAdapter->fgIsEmbbededMacAddrValid == FALSE &&
5446                 (IS_BMCAST_MAC_ADDR(prRegInfo->aucMacAddr)
5447                  || EQUAL_MAC_ADDR(aucZeroMacAddr, prRegInfo->aucMacAddr)))
5448             || prRegInfo->ucTxPwrValid == 0)) {
5449         fgGenErrMsg = TRUE;
5450     }
5451 #endif
5452
5453     if(fgGenErrMsg == TRUE) {
5454         prBeacon = cnmMemAlloc(prAdapter, RAM_TYPE_BUF, sizeof(WLAN_BEACON_FRAME_T) + sizeof(IE_SSID_T));
5455
5456         // initialization
5457         kalMemZero(prBeacon, sizeof(WLAN_BEACON_FRAME_T) + sizeof(IE_SSID_T));
5458
5459         // prBeacon initialization
5460         prBeacon->u2FrameCtrl = MAC_FRAME_BEACON;
5461         COPY_MAC_ADDR(prBeacon->aucDestAddr, aucBCAddr);
5462         COPY_MAC_ADDR(prBeacon->aucSrcAddr, aucZeroMacAddr);
5463         COPY_MAC_ADDR(prBeacon->aucBSSID, aucZeroMacAddr);
5464         prBeacon->u2BeaconInterval = 100;
5465         prBeacon->u2CapInfo = CAP_INFO_ESS;
5466
5467         // prSSID initialization
5468         prSsid = (P_IE_SSID_T)(&prBeacon->aucInfoElem[0]);
5469         prSsid->ucId = ELEM_ID_SSID;
5470
5471         // rConfiguration initialization
5472         rConfiguration.u4Length             = sizeof(PARAM_802_11_CONFIG_T);
5473         rConfiguration.u4BeaconPeriod       = 100;
5474         rConfiguration.u4ATIMWindow         = 1;
5475         rConfiguration.u4DSConfig           = 2412;
5476         rConfiguration.rFHConfig.u4Length   = sizeof(PARAM_802_11_CONFIG_FH_T);
5477
5478         // rSupportedRates initialization
5479         kalMemZero(rSupportedRates, sizeof(PARAM_RATES_EX));
5480     }
5481
5482 #if (CFG_NVRAM_EXISTENCE_CHECK == 1)
5483     #define NVRAM_ERR_MSG "NVRAM WARNING: Err = 0x01"
5484     if(kalIsConfigurationExist(prAdapter->prGlueInfo) == FALSE) {
5485         COPY_SSID(prSsid->aucSSID, 
5486                 prSsid->ucLength, 
5487                 NVRAM_ERR_MSG,
5488                 strlen(NVRAM_ERR_MSG));
5489
5490         kalIndicateBssInfo(prAdapter->prGlueInfo,
5491                 (PUINT_8)prBeacon,
5492                 OFFSET_OF(WLAN_BEACON_FRAME_T, aucInfoElem) + OFFSET_OF(IE_SSID_T, aucSSID) + prSsid->ucLength,
5493                 1,
5494                 0);
5495
5496         COPY_SSID(rSsid.aucSsid, rSsid.u4SsidLen, NVRAM_ERR_MSG, strlen(NVRAM_ERR_MSG));
5497         nicAddScanResult(prAdapter,
5498                 prBeacon->aucBSSID,
5499                 &rSsid,
5500                 0,
5501                 0,
5502                 PARAM_NETWORK_TYPE_FH,
5503                 &rConfiguration,
5504                 NET_TYPE_INFRA,
5505                 rSupportedRates,
5506                 OFFSET_OF(WLAN_BEACON_FRAME_T, aucInfoElem) + OFFSET_OF(IE_SSID_T, aucSSID) + prSsid->ucLength - WLAN_MAC_MGMT_HEADER_LEN,
5507                 (PUINT_8)((UINT_32)(prBeacon) + WLAN_MAC_MGMT_HEADER_LEN));
5508     }
5509 #endif
5510
5511 #if (CFG_SW_NVRAM_VERSION_CHECK == 1)
5512     #define VER_ERR_MSG     "NVRAM WARNING: Err = 0x%02X"
5513     if(fgIsConfExist == TRUE) {
5514         if((CFG_DRV_OWN_VERSION < prAdapter->rVerInfo.u2Part1CfgPeerVersion
5515                     || CFG_DRV_OWN_VERSION < prAdapter->rVerInfo.u2Part2CfgPeerVersion
5516                     || prAdapter->rVerInfo.u2Part1CfgOwnVersion < CFG_DRV_PEER_VERSION
5517                     || prAdapter->rVerInfo.u2Part2CfgOwnVersion < CFG_DRV_PEER_VERSION /* NVRAM */
5518                     || CFG_DRV_OWN_VERSION < prAdapter->rVerInfo.u2FwPeerVersion
5519                     || prAdapter->rVerInfo.u2FwOwnVersion < CFG_DRV_PEER_VERSION)) {
5520             u4ErrCode |= NVRAM_ERROR_VERSION_MISMATCH;
5521         }
5522
5523
5524         if(prRegInfo->ucTxPwrValid == 0) {
5525             u4ErrCode |= NVRAM_ERROR_INVALID_TXPWR;
5526         }
5527
5528         if(prAdapter->fgIsEmbbededMacAddrValid == FALSE &&
5529                     (IS_BMCAST_MAC_ADDR(prRegInfo->aucMacAddr) || EQUAL_MAC_ADDR(aucZeroMacAddr, prRegInfo->aucMacAddr))) {
5530             u4ErrCode |= NVRAM_ERROR_INVALID_MAC_ADDR;
5531         }
5532
5533         if(u4ErrCode != 0) {
5534             sprintf(aucErrMsg, VER_ERR_MSG, (unsigned int)u4ErrCode);
5535             COPY_SSID(prSsid->aucSSID,
5536                         prSsid->ucLength,
5537                         aucErrMsg,
5538                         strlen(aucErrMsg));
5539
5540             kalIndicateBssInfo(prAdapter->prGlueInfo,
5541                     (PUINT_8)prBeacon,
5542                     OFFSET_OF(WLAN_BEACON_FRAME_T, aucInfoElem) + OFFSET_OF(IE_SSID_T, aucSSID) + prSsid->ucLength,
5543                     1,
5544                     0);
5545
5546             COPY_SSID(rSsid.aucSsid, rSsid.u4SsidLen, NVRAM_ERR_MSG, strlen(NVRAM_ERR_MSG));
5547             nicAddScanResult(prAdapter,
5548                     prBeacon->aucBSSID,
5549                     &rSsid,
5550                     0,
5551                     0,
5552                     PARAM_NETWORK_TYPE_FH,
5553                     &rConfiguration,
5554                     NET_TYPE_INFRA,
5555                     rSupportedRates,
5556                     OFFSET_OF(WLAN_BEACON_FRAME_T, aucInfoElem) + OFFSET_OF(IE_SSID_T, aucSSID) + prSsid->ucLength - WLAN_MAC_MGMT_HEADER_LEN,
5557                     (PUINT_8)((UINT_32)(prBeacon) + WLAN_MAC_MGMT_HEADER_LEN));
5558         }
5559     }
5560 #endif
5561
5562     if(fgGenErrMsg == TRUE) {
5563         cnmMemFree(prAdapter, prBeacon);
5564     }
5565
5566     return WLAN_STATUS_SUCCESS;
5567 }
5568