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