add MTK-combo-module,continue with commit 17f39ed917874e77e80411f33faba1b7ee8138c8
[firefly-linux-kernel-4.4.55.git] / drivers / mtk_wcn_combo / drv_wlan / wlan / nic / nic.c
1 /*
2 ** $Id: //Department/DaVinci/BRANCHES/MT6620_WIFI_DRIVER_V2_2/nic/nic.c#3 $
3 */
4
5 /*! \file   nic.c
6     \brief  Functions that provide operation in NIC's (Network Interface Card) point of view.
7
8     This file includes functions which unite multiple hal(Hardware) operations
9     and also take the responsibility of Software Resource Management in order
10     to keep the synchronization with Hardware Manipulation.
11 */
12
13 /*******************************************************************************
14 * Copyright (c) 2007 MediaTek Inc.
15 *
16 * All rights reserved. Copying, compilation, modification, distribution
17 * or any other use whatsoever of this material is strictly prohibited
18 * except in accordance with a Software License Agreement with
19 * MediaTek Inc.
20 ********************************************************************************
21 */
22
23 /*******************************************************************************
24 * LEGAL DISCLAIMER
25 *
26 * BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND
27 * AGREES THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK
28 * SOFTWARE") RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE
29 * PROVIDED TO BUYER ON AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY
30 * DISCLAIMS ANY AND ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT
31 * LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
32 * PARTICULAR PURPOSE OR NONINFRINGEMENT. NEITHER DOES MEDIATEK PROVIDE
33 * ANY WARRANTY WHATSOEVER WITH RESPECT TO THE SOFTWARE OF ANY THIRD PARTY
34 * WHICH MAY BE USED BY, INCORPORATED IN, OR SUPPLIED WITH THE MEDIATEK
35 * SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH THIRD PARTY FOR ANY
36 * WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE
37 * FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S SPECIFICATION OR TO
38 * CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
39 *
40 * BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
41 * LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL
42 * BE, AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT
43 * ISSUE, OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY
44 * BUYER TO MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
45 *
46 * THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
47 * WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT
48 * OF LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING
49 * THEREOF AND RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN
50 * FRANCISCO, CA, UNDER THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE
51 * (ICC).
52 ********************************************************************************
53 */
54
55 /*
56 ** $Log: nic.c $
57  *
58  * 02 14 2012 yuche.tsai
59  * [ALPS00118350] [ALPS.ICS][WiFi Direct] Dirver update for wifi direct connection
60  * Replace Beacon/Probe Response IE by driver generating instead of from supplicant.
61  *
62  * 01 13 2012 yuche.tsai
63  * NULL
64  * Update driver/p2p driver for ICS tethering mode.
65  * Fix FW reply probe request issue.
66  *
67  * 01 13 2012 yuche.tsai
68  * NULL
69  * WiFi Hot Spot Tethering for ICS ALPHA testing version.
70  *
71  * 11 28 2011 cp.wu
72  * [WCXRP00001125] [MT6620 Wi-Fi][Firmware] Strengthen Wi-Fi power off sequence to have a clearroom environment when returining to ROM code
73  * 1. Due to firmware now stops HIF DMA for powering off, do not try to receive any packet from firmware
74  * 2. Take use of prAdapter->fgIsEnterD3ReqIssued for tracking whether it is powering off or not
75  *
76  * 11 22 2011 tsaiyuan.hsu
77  * [WCXRP00001083] [MT6620 Wi-Fi][DRV]] dump debug counter or frames when debugging is triggered
78  * keep debug counter setting after wake up.
79  *
80  * 11 19 2011 yuche.tsai
81  * NULL
82  * Add P2P RSSI Link Quality Query Support. (Default Off)
83  *
84  * 11 04 2011 tsaiyuan.hsu
85  * [WCXRP00001083] [MT6620 Wi-Fi][DRV]] dump debug counter or frames when debugging is triggered
86  * add debug counters and periodically dump counters for Xlog debugging.
87  *
88  * 11 04 2011 cp.wu
89  * [WCXRP00001079] [MT5931][Driver] Release pending MMPDU only when BSS is being deactivated
90  * pre-check for NULL before calling MMPDU freeing function
91  *
92  * 11 03 2011 wh.su
93  * [WCXRP00001078] [MT6620 Wi-Fi][Driver] Adding the mediatek log improment support : XLOG
94  * change the DBGLOG for "\n" and "\r\n". LABEL to LOUD for XLOG
95  *
96  * 11 01 2011 chinglan.wang
97  * NULL
98  * Modify the Wi-Fi method of the flush TX queue when disconnect the AP.
99  * If disconnect the AP and flush all the data frame in the TX queue, WPS cannot do the 4-way handshake to connect to the AP..
100  *
101  * 10 19 2011 yuche.tsai
102  * [WCXRP00001045] [WiFi Direct][Driver] Check 2.1 branch.
103  * Branch 2.1
104  * Davinci Maintrunk Label: MT6620_WIFI_DRIVER_FW_TRUNK_MT6620E5_111019_0926.
105  *
106  * 08 03 2011 terry.wu
107  * [WCXRP00000899] [MT6620] [FW] Reply probe rsp in FW for hotspot mode
108  * Reply Probe Rsp in FW for Hotspot Mode.
109  *
110  *
111  *
112  * 08 03 2011 terry.wu
113  * [WCXRP00000899] [MT6620] [FW] Reply probe rsp in FW for hotspot mode
114  * Reply Probe Rsp in FW for Hotspot Mode.
115  *
116  *
117  * 08 03 2011 terry.wu
118  * [WCXRP00000899] [MT6620] [FW] Reply probe rsp in FW for hotspot mode
119  * Reply Probe Rsp in FW for Hotspot Mode.
120  *
121  * 08 03 2011 terry.wu
122  * [WCXRP00000899] [MT6620] [FW] Reply probe rsp in FW for hotspot mode
123  * Reply Probe Rsp in FW for Hotspot Mode.
124  *
125  * 08 02 2011 yuche.tsai
126  * [WCXRP00000896] [Volunteer Patch][WiFi Direct][Driver] GO with multiple client, TX deauth to a disconnecting device issue.
127  * Support TX Deauth while tearing down a station connection.
128  *
129  * 07 11 2011 wh.su
130  * [WCXRP00000849] [MT6620 Wi-Fi][Driver] Remove some of the WAPI define for make sure the value is initialize, for customer not enable WAPI
131  * For make sure wapi initial value is set.
132  *
133  * 06 27 2011 cp.wu
134  * [WCXRP00000815] [MT6620 Wi-Fi][Driver] allow single BSSID with multiple SSID settings to work around some tricky AP which use space character as hidden SSID
135  * 1. correct logic
136  * 2. replace only BSS-DESC which doesn't have a valid SSID.
137  *
138  * 06 27 2011 cp.wu
139  * [WCXRP00000815] [MT6620 Wi-Fi][Driver] allow single BSSID with multiple SSID settings to work around some tricky AP which use space character as hidden SSID
140  * allow to have a single BSSID with multiple SSID to be presented in scanning result
141  *
142  * 05 11 2011 eddie.chen
143  * [WCXRP00000709] [MT6620 Wi-Fi][Driver] Check free number before copying broadcast packet
144  * Fix dest type when GO packet copying.
145  *
146  * 04 18 2011 terry.wu
147  * [WCXRP00000660] [MT6620 Wi-Fi][Driver] Remove flag CFG_WIFI_DIRECT_MOVED
148  * Remove flag CFG_WIFI_DIRECT_MOVED.
149  *
150  * 04 15 2011 cp.wu
151  * [WCXRP00000651] [MT6620 Wi-Fi][Driver] Refine RSSI buffering mechanism
152  * ROLLBACK due to the special design is to workaround incorrect initial RCPI value coming from firmware domain.
153  *
154  * 04 14 2011 cm.chang
155  * [WCXRP00000634] [MT6620 Wi-Fi][Driver][FW] 2nd BSS will not support 40MHz bandwidth for concurrency
156  * .
157  *
158  * 04 14 2011 cp.wu
159  * [WCXRP00000598] [MT6620 Wi-Fi][Driver] Implementation of interface for communicating with user space process for RESET_START and RESET_END events
160  * sync. whole-chip resetting mechanism to V2.0 branch.
161  *
162  * 04 12 2011 cp.wu
163  * [WCXRP00000635] [MT6620 Wi-Fi][Driver] Clear pending security frames when QM clear pending data frames for dedicated network type
164  * clear pending security frames for dedicated network type when BSS is being deactivated/disconnected
165  *
166  * 04 12 2011 wh.su
167  * NULL
168  * enable the p2p check the cipher to set the bssInfo auth mode.
169  *
170  * 04 12 2011 wh.su
171  * NULL
172  * prepare the code for sync the auth mode and encryption status for P2P and BOW.
173  *
174  * 04 11 2011 yuche.tsai
175  * [WCXRP00000627] [Volunteer Patch][MT6620][Driver] Pending MMPUD of P2P Network may crash system issue.
176  * Fix kernel panic issue when MMPDU of P2P is pending in driver after WLAN module removed.
177  *
178  * 04 10 2011 george.huang
179  * [WCXRP00000621] [MT6620 Wi-Fi][Driver] Support P2P supplicant to set power mode
180  * Fix compiler issue.
181  *
182  * 04 08 2011 george.huang
183  * [WCXRP00000621] [MT6620 Wi-Fi][Driver] Support P2P supplicant to set power mode
184  * separate settings of P2P and AIS
185  *
186  * 04 07 2011 eddie.chen
187  * [WCXRP00000527] [MT6620 Wi-Fi][FW/Driver] Clean buffered packet when BSS is inactive or disconnected[WCXRP00000617] [MT6620 Wi-Fi][DRV/FW] Fix for sigma
188  * Remove packet when BSS is inactive
189  *
190  * 04 07 2011 cp.wu
191  * [WCXRP00000616] [MT6620 Wi-Fi][Driver] Free memory to pool and kernel in case any unexpected failure happend inside wlanAdapterStart
192  * .
193  *
194  * 04 07 2011 cp.wu
195  * [WCXRP00000616] [MT6620 Wi-Fi][Driver] Free memory to pool and kernel in case any unexpected failure happend inside wlanAdapterStart
196  * implementation of internal error handling of nicAllocateAdapterMemory.
197  *
198  * 03 31 2011 chinglan.wang
199  * [WCXRP00000613] [MT6620 Wi-Fi] [FW] [Driver] BssInfo can get the security mode which is WPA/WPA2/WAPI or not.
200  * .
201  *
202  * 03 18 2011 cp.wu
203  * [WCXRP00000577] [MT6620 Wi-Fi][Driver][FW] Create V2.0 branch for firmware and driver
204  * create V2.0 driver release based on label "MT6620_WIFI_DRIVER_V2_0_110318_1600" from main trunk
205  *
206  * 03 17 2011 cp.wu
207  * [WCXRP00000562] [MT6620 Wi-Fi][Driver] I/O buffer pre-allocation to avoid physically continuous memory shortage after system running for a long period
208  * use pre-allocated buffer for storing enhanced interrupt response as well
209  *
210  * 03 16 2011 cp.wu
211  * [WCXRP00000562] [MT6620 Wi-Fi][Driver] I/O buffer pre-allocation to avoid physically continuous memory shortage after system running for a long period
212  * 1. pre-allocate physical continuous buffer while module is being loaded
213  * 2. use pre-allocated physical continuous buffer for TX/RX DMA transfer
214  *
215  * The windows part remained the same as before, but added similiar APIs to hide the difference.
216  *
217  * 03 15 2011 cp.wu
218  * [WCXRP00000559] [MT6620 Wi-Fi][Driver] Combine TX/RX DMA buffers into a single one to reduce physically continuous memory consumption
219  * 1. deprecate CFG_HANDLE_IST_IN_SDIO_CALLBACK
220  * 2. Use common coalescing buffer for both TX/RX directions
221  *
222  *
223  * 03 10 2011 cm.chang
224  * [WCXRP00000358] [MT6620 Wi-Fi][Driver] Provide concurrent information for each module
225  * Add some functions to let AIS/Tethering or AIS/BOW be the same channel
226  *
227  * 03 07 2011 terry.wu
228  * [WCXRP00000521] [MT6620 Wi-Fi][Driver] Remove non-standard debug message
229  * Toggle non-standard debug messages to comments.
230  *
231  * 03 02 2011 cp.wu
232  * [WCXRP00000503] [MT6620 Wi-Fi][Driver] Take RCPI brought by association response as initial RSSI right after connection is built.
233  * use RCPI brought by ASSOC-RESP after connection is built as initial RCPI to avoid using a uninitialized MAC-RX RCPI.
234  *
235  * 02 08 2011 terry.wu
236  * [WCXRP00000412] [MT6620 Wi-Fi][FW/Driver] Dump firmware assert info at android kernel log
237  * Use kalPrint to print firmware assert info.
238  *
239  * 02 01 2011 terry.wu
240  * [WCXRP00000412] [MT6620 Wi-Fi][FW/Driver] Dump firmware assert info at android kernel log
241  * .
242  *
243  * 02 01 2011 cm.chang
244  * [WCXRP00000415] [MT6620 Wi-Fi][Driver] Check if any memory leakage happens when uninitializing in DGB mode
245  * .
246  *
247  * 01 31 2011 terry.wu
248  * [WCXRP00000412] [MT6620 Wi-Fi][FW/Driver] Dump firmware assert info at android kernel log
249  * Print firmware ASSERT info at Android kernel log, driver side
250  *
251  * 01 27 2011 tsaiyuan.hsu
252  * [WCXRP00000392] [MT6620 Wi-Fi][Driver] Add Roaming Support
253  * add roaming fsm
254  * 1. not support 11r, only use strength of signal to determine roaming.
255  * 2. not enable CFG_SUPPORT_ROAMING until completion of full test.
256  * 3. in 6620, adopt work-around to avoid sign extension problem of cck of hw
257  * 4. assume that change of link quality in smooth way.
258  *
259  * 01 26 2011 cm.chang
260  * [WCXRP00000395] [MT6620 Wi-Fi][Driver][FW] Search STA_REC with additional net type index argument
261  * Allocate system RAM if fixed message or mgmt buffer is not available
262  *
263  * 01 24 2011 cp.wu
264  * [WCXRP00000382] [MT6620 Wi-Fi][Driver] Track forwarding packet number with notifying tx thread for serving
265  * 1. add an extra counter for tracking pending forward frames.
266  * 2. notify TX service thread as well when there is pending forward frame
267  * 3. correct build errors leaded by introduction of Wi-Fi direct separation module
268  *
269  * 01 19 2011 cp.wu
270  * [WCXRP00000372] [MT6620 Wi-Fi][Driver] Check bus access failure inside nicProcessIST()
271  * check bus error and/or card removal when retrieving interrupt status from HAL
272  *
273  * 01 04 2011 cp.wu
274  * [WCXRP00000338] [MT6620 Wi-Fi][Driver] Separate kalMemAlloc into kmalloc and vmalloc implementations to ease physically continous memory demands
275  * 1) correct typo in scan.c
276  * 2) TX descriptors, RX descriptos and management buffer should use virtually continous buffer instead of physically contineous one
277  *
278  * 01 04 2011 cp.wu
279  * [WCXRP00000338] [MT6620 Wi-Fi][Driver] Separate kalMemAlloc into kmalloc and vmalloc implementations to ease physically continous memory demands
280  * separate kalMemAlloc() into virtually-continous and physically-continous type to ease slab system pressure
281  *
282  * 12 30 2010 cp.wu
283  * [WCXRP00000327] [MT6620 Wi-Fi][Driver] Improve HEC WHQA 6972 workaround coverage in driver side
284  * host driver not to set FW-own when there is still pending interrupts
285  *
286  * 12 17 2010 cp.wu
287  * [WCXRP00000270] [MT6620 Wi-Fi][Driver] Clear issues after concurrent networking support has been merged
288  * before BSS disconnection is indicated to firmware, all correlated peer should be cleared and freed
289  *
290  * 12 07 2010 cm.chang
291  * [WCXRP00000239] MT6620 Wi-Fi][Driver][FW] Merge concurrent branch back to maintrunk
292  * 1. BSSINFO include RLM parameter
293  * 2. free all sta records when network is disconnected
294  *
295  * 12 02 2010 eddie.chen
296  * [WCXRP00000218] [MT6620 Wi-Fi][Driver] Add auto rate window control in registry
297  * Add more control value but dont use it now.
298  *
299  * 11 30 2010 eddie.chen
300  * [WCXRP00000218] [MT6620 Wi-Fi][Driver] Add auto rate window control in registry
301  * Add auto rate check window in registry
302  *
303  * 11 10 2010 eddie.chen
304  * [WCXRP00000156] [MT6620][FW] Change Auto rate window to 64 and add throughput swcr
305  * Use autorate parameter 1 as phy rate mask.
306  *
307  * 11 08 2010 cp.wu
308  * [WCXRP00000166] [MT6620 Wi-Fi][Driver] use SDIO CMD52 for enabling/disabling interrupt to reduce transaction period
309  * change to use CMD52 for enabling/disabling interrupt to reduce SDIO transaction time
310  *
311  * 10 26 2010 eddie.chen
312  * [WCXRP00000134] [MT6620 Wi-Fi][Driver] Add a registry to enable auto rate for SQA test by using E1 EVB
313  * Add auto rate parameter in registry.
314  *
315  * 10 18 2010 cp.wu
316  * [WCXRP00000053] [MT6620 Wi-Fi][Driver] Reset incomplete and might leads to BSOD when entering RF test with AIS associated
317  * 1. remove redundant variables in STA_REC structure
318  * 2. add STA-REC uninitialization routine for clearing pending events
319  *
320  * 10 18 2010 cp.wu
321  * [WCXRP00000103] [MT6620 Wi-Fi][Driver] Driver crashed when using WZC to connect to AP#B with connection with AP#A
322  * reset ptrs when IEs are going to be dropped
323  *
324  * 10 12 2010 cp.wu
325  * [WCXRP00000084] [MT6620 Wi-Fi][Driver][FW] Add fixed rate support for distance test
326  * add HT (802.11n) fixed rate support.
327  *
328  * 10 08 2010 cp.wu
329  * [WCXRP00000084] [MT6620 Wi-Fi][Driver][FW] Add fixed rate support for distance test
330  * adding fixed rate support for distance test. (from registry setting)
331  *
332  * 10 07 2010 cp.wu
333  * [WCXRP00000083] [MT5931][Driver][FW] Add necessary logic for MT5931 first connection
334  * add firmware download for MT5931.
335  *
336  * 10 05 2010 cp.wu
337  * [WCXRP00000056] [MT6620 Wi-Fi][Driver] NVRAM implementation with Version Check
338  * load manufacture data when CFG_SUPPORT_NVRAM is set to 1
339  *
340  * 10 04 2010 cp.wu
341  * [WCXRP00000077] [MT6620 Wi-Fi][Driver][FW] Eliminate use of ENUM_NETWORK_TYPE_T and replaced by ENUM_NETWORK_TYPE_INDEX_T only
342  * remove ENUM_NETWORK_TYPE_T definitions
343  *
344  * 09 21 2010 cp.wu
345  * [WCXRP00000053] [MT6620 Wi-Fi][Driver] Reset incomplete and might leads to BSOD when entering RF test with AIS associated
346  * Do a complete reset with STA-REC null checking for RF test re-entry
347  *
348  * 09 08 2010 cp.wu
349  * NULL
350  * use static memory pool for storing IEs of scanning result.
351  *
352  * 09 06 2010 cp.wu
353  * NULL
354  * Androi/Linux: return current operating channel information
355  *
356  * 09 01 2010 cp.wu
357  * NULL
358  * HIFSYS Clock Source Workaround
359  *
360  * 08 26 2010 yuche.tsai
361  * NULL
362  * Fix someones coding error while enable WIFI_DIRECT.
363  *
364  * 08 25 2010 george.huang
365  * NULL
366  * update OID/ registry control path for PM related settings
367  *
368  * 08 24 2010 cm.chang
369  * NULL
370  * Support RLM initail channel of Ad-hoc, P2P and BOW
371  *
372  * 08 24 2010 chinghwa.yu
373  * NULL
374  * Update BOW for the 1st time.
375  *
376  * 08 23 2010 chinghwa.yu
377  * NULL
378  * Update for BOW.
379  *
380  * 08 20 2010 yuche.tsai
381  * NULL
382  * Add state change indication.
383  *
384  * 08 16 2010 yuche.tsai
385  * NULL
386  * Add support for P2P BSS update info.
387  *
388  * 08 12 2010 cp.wu
389  * NULL
390  * [removing debugging] not to dump beacon content.
391  *
392  * 08 12 2010 cp.wu
393  * NULL
394  * [AIS-FSM] honor registry setting for adhoc running mode. (A/B/G)
395  *
396  * 08 11 2010 cp.wu
397  * NULL
398  * 1) do not use in-stack variable for beacon updating. (for MAUI porting)
399  * 2) extending scanning result to 64 instead of 48
400  *
401  * 08 04 2010 yarco.yang
402  * NULL
403  * Add TX_AMPDU and ADDBA_REJECT command
404  *
405  * 08 03 2010 cp.wu
406  * NULL
407  * surpress compilation warning.
408  *
409  * 08 03 2010 cp.wu
410  * NULL
411  * Centralize mgmt/system service procedures into independent calls.
412  *
413  * 07 28 2010 cp.wu
414  * NULL
415  * 1) eliminate redundant variable eOPMode in prAdapter->rWlanInfo
416  * 2) change nicMediaStateChange() API prototype
417  *
418  * 07 28 2010 cp.wu
419  * NULL
420  * sync. CMD_BSS_INFO structure change to CMD-EVENT v0.15.
421  *
422  * 07 24 2010 wh.su
423  *
424  * .support the Wi-Fi RSN
425  *
426  * 07 23 2010 cp.wu
427  *
428  * FIX: structure of CMD_SET_BSS_INFO has been changed but no follow-ups are done.
429  *
430  * 07 22 2010 george.huang
431  *
432  * .
433  *
434  * 07 22 2010 george.huang
435  *
436  * Update fgIsQoS information in BSS INFO by CMD
437  *
438  * 07 19 2010 cp.wu
439  *
440  * [WPD00003833] [MT6620 and MT5931] Driver migration.
441  * Add Ad-Hoc support to AIS-FSM
442  *
443  * 07 14 2010 yarco.yang
444  *
445  * 1. Remove CFG_MQM_MIGRATION
446  * 2. Add CMD_UPDATE_WMM_PARMS command
447  *
448  * 07 08 2010 cp.wu
449  *
450  * [WPD00003833] [MT6620 and MT5931] Driver migration - move to new repository.
451  *
452  * 07 07 2010 cp.wu
453  * [WPD00003833][MT6620 and MT5931] Driver migration
454  * update prStaRecOfAP with BSS-INFO.
455  *
456  * 07 06 2010 george.huang
457  * [WPD00001556]Basic power managemenet function
458  * Update arguments for nicUpdateBeaconIETemplate()
459  *
460  * 07 06 2010 cp.wu
461  * [WPD00003833][MT6620 and MT5931] Driver migration
462  * STA-REC is maintained by CNM only.
463  *
464  * 07 05 2010 cp.wu
465  * [WPD00003833][MT6620 and MT5931] Driver migration
466  * 1) ignore RSN checking when RSN is not turned on.
467  * 2) set STA-REC deactivation callback as NULL
468  * 3) add variable initialization API based on PHY configuration
469  *
470  * 07 01 2010 cm.chang
471  * [WPD00003841][LITE Driver] Migrate RLM/CNM to host driver
472  * Support sync command of STA_REC
473  *
474  * 06 30 2010 cp.wu
475  * [WPD00003833][MT6620 and MT5931] Driver migration
476  * sync. with CMD/EVENT document ver0.07.
477  *
478  * 06 29 2010 cp.wu
479  * [WPD00003833][MT6620 and MT5931] Driver migration
480  * correct variable naming for 8-bit variable used in CMD_BEACON_TEMPLATE_UPDATE.
481  *
482  * 06 29 2010 cp.wu
483  * [WPD00003833][MT6620 and MT5931] Driver migration
484  * 1) sync to. CMD/EVENT document v0.03
485  * 2) simplify DTIM period parsing in scan.c only, bss.c no longer parses it again.
486  * 3) send command packet to indicate FW-PM after
487  *     a) 1st beacon is received after AIS has connected to an AP
488  *     b) IBSS-ALONE has been created
489  *     c) IBSS-MERGE has occured
490  *
491  * 06 25 2010 george.huang
492  * [WPD00001556]Basic power managemenet function
493  * Create beacon update path, with expose bssUpdateBeaconContent()
494  *
495  * 06 22 2010 cp.wu
496  * [WPD00003833][MT6620 and MT5931] Driver migration
497  * fill fgIsUapsdConnection when indicating BSS-CREATE with AIS-STA mode.
498  *
499  * 06 22 2010 cp.wu
500  * [WPD00003833][MT6620 and MT5931] Driver migration
501  * 1) add command warpper for STA-REC/BSS-INFO sync.
502  * 2) enhance command packet sending procedure for non-oid part
503  * 3) add command packet definitions for STA-REC/BSS-INFO sync.
504  *
505  * 06 21 2010 cp.wu
506  * [WPD00003833][MT6620 and MT5931] Driver migration
507  * implement TX_DONE callback path.
508  *
509  * 06 21 2010 wh.su
510  * [WPD00003840][MT6620 5931] Security migration
511  * remove duplicate variable for migration.
512  *
513  * 06 21 2010 cp.wu
514  * [WPD00003833][MT6620 and MT5931] Driver migration
515  * TX descriptors are now allocated once for reducing allocation overhead
516  *
517  * 06 18 2010 cm.chang
518  * [WPD00003841][LITE Driver] Migrate RLM/CNM to host driver
519  * Provide cnmMgtPktAlloc() and alloc/free function of msg/buf
520  *
521  * 06 11 2010 cp.wu
522  * [WPD00003833][MT6620 and MT5931] Driver migration
523  * 1) migrate assoc.c.
524  * 2) add ucTxSeqNum for tracking frames which needs TX-DONE awareness
525  * 3) add configuration options for CNM_MEM and RSN modules
526  * 4) add data path for management frames
527  * 5) eliminate rPacketInfo of MSDU_INFO_T
528  *
529  * 06 10 2010 cp.wu
530  * [WPD00003833][MT6620 and MT5931] Driver migration
531  * 1) eliminate CFG_CMD_EVENT_VERSION_0_9
532  * 2) when disconnected, indicate nic directly (no event is needed)
533  *
534  * 06 06 2010 kevin.huang
535  * [WPD00003832][MT6620 5931] Create driver base
536  * [MT6620 5931] Create driver base
537  *
538  * 04 26 2010 cp.wu
539  * [WPD00001943]Create WiFi test driver framework on WinXP
540  * 1) surpress compiler warning
541  * 2) when acqruing LP-own, keep writing WHLPCR whenever OWN is not acquired yet
542  *
543  * 04 23 2010 cp.wu
544  * [WPD00001943]Create WiFi test driver framework on WinXP
545  * surpress compiler warning
546  *
547  * 04 13 2010 cp.wu
548  * [WPD00003823][MT6620 Wi-Fi] Add Bluetooth-over-Wi-Fi support
549  * add framework for BT-over-Wi-Fi support.
550  *  *  *  *  *  *  *  *  *  *  *  *  * 1) prPendingCmdInfo is replaced by queue for multiple handler capability
551  *  *  *  *  *  *  *  *  *  *  *  *  * 2) command sequence number is now increased atomically
552  *  *  *  *  *  *  *  *  *  *  *  *  * 3) private data could be hold and taken use for other purpose
553  *
554  * 04 12 2010 cp.wu
555  * [WPD00001943]Create WiFi test driver framework on WinXP
556  * add channel frequency <-> number conversion
557  *
558  * 04 06 2010 cp.wu
559  * [WPD00001943]Create WiFi test driver framework on WinXP
560  * eliminate direct access for prGlueInfo->fgIsCardRemoved in non-glue layer
561  *
562  * 04 06 2010 cp.wu
563  * [WPD00003827][MT6620 Wi-Fi] Chariot fail and following ping fail, no pkt send from driver
564  * correct nicProcessIST_impl() for interrupt status brought up by RX enhanced response
565  *
566  * 03 19 2010 cp.wu
567  * [WPD00001943]Create WiFi test driver framework on WinXP
568  * 1) add ACPI D0/D3 state switching support
569  *  *  *  *  *  *  * 2) use more formal way to handle interrupt when the status is retrieved from enhanced RX response
570  *
571  * 03 17 2010 cp.wu
572  * [WPD00001943]Create WiFi test driver framework on WinXP
573  * always process TX interrupt first then RX interrupt.
574  *
575  * 02 25 2010 cp.wu
576  * [WPD00001943]Create WiFi test driver framework on WinXP
577  * correct behavior to prevent duplicated RX handling for RX0_DONE and RX1_DONE
578  *
579  * 02 23 2010 cp.wu
580  * [WPD00001943]Create WiFi test driver framework on WinXP
581  * add checksum offloading support.
582 **  \main\maintrunk.MT6620WiFiDriver_Prj\27 2009-12-16 18:03:43 GMT mtk02752
583 **  handling enhanced response which fields are fetched at different moments
584 **  \main\maintrunk.MT6620WiFiDriver_Prj\26 2009-12-15 17:00:29 GMT mtk02752
585 **  if RX enhanced response is used, D2H interrupt status should be coming from buffered result as well
586 **  \main\maintrunk.MT6620WiFiDriver_Prj\25 2009-12-15 12:01:55 GMT mtk02752
587 **  if TX_DONE bit is not set but WTSR0/WTSR1 is non-zero, then set TX_DONE bit due to time latency of interrupt status enhanced response
588 **  \main\maintrunk.MT6620WiFiDriver_Prj\24 2009-12-10 16:52:52 GMT mtk02752
589 **  code clean
590 **  \main\maintrunk.MT6620WiFiDriver_Prj\23 2009-11-24 20:51:01 GMT mtk02752
591 **  integrate with SD1 by invoking qmHandleMailboxRxMessage()
592 **  \main\maintrunk.MT6620WiFiDriver_Prj\22 2009-11-16 17:32:33 GMT mtk02752
593 **  prepare code for invoking rxHandleMailboxRxMessage()
594 **  \main\maintrunk.MT6620WiFiDriver_Prj\21 2009-11-11 10:36:08 GMT mtk01084
595 **  \main\maintrunk.MT6620WiFiDriver_Prj\20 2009-11-09 22:56:41 GMT mtk01084
596 **  modify HW access routines
597 **  \main\maintrunk.MT6620WiFiDriver_Prj\19 2009-10-30 18:17:20 GMT mtk01084
598 **  prevent warning
599 **  \main\maintrunk.MT6620WiFiDriver_Prj\18 2009-10-29 19:54:57 GMT mtk01084
600 **  init HIF
601 **  \main\maintrunk.MT6620WiFiDriver_Prj\17 2009-10-23 16:08:30 GMT mtk01084
602 **  \main\maintrunk.MT6620WiFiDriver_Prj\16 2009-10-13 21:59:12 GMT mtk01084
603 **  update for new HW design
604 **  \main\maintrunk.MT6620WiFiDriver_Prj\15 2009-09-09 17:26:15 GMT mtk01084
605 **  modify for CFG_TEST_WITH_MT5921
606 **  \main\maintrunk.MT6620WiFiDriver_Prj\14 2009-05-19 10:55:22 GMT mtk01461
607 **  Unmask the unused HISR
608 **  \main\maintrunk.MT6620WiFiDriver_Prj\13 2009-05-18 15:59:13 GMT mtk01084
609 **  remove debug purpose code
610 **  \main\maintrunk.MT6620WiFiDriver_Prj\12 2009-05-18 14:05:02 GMT mtk01084
611 **  update for WIFI ownback part on initial
612 **  \main\maintrunk.MT6620WiFiDriver_Prj\11 2009-05-04 21:32:57 GMT mtk01084
613 **  add temporarily code to set driver own on adapter initialization
614 **  \main\maintrunk.MT6620WiFiDriver_Prj\10 2009-04-28 10:35:41 GMT mtk01461
615 **  Add init of TX aggregation and fix RX STATUS is DW align for SDIO_STATUS_ENHANCE mode
616 **  \main\maintrunk.MT6620WiFiDriver_Prj\9 2009-04-24 21:12:10 GMT mtk01104
617 **  Add function nicRestoreSpiDefMode()
618 **  \main\maintrunk.MT6620WiFiDriver_Prj\8 2009-04-21 09:43:31 GMT mtk01461
619 **  Revise for MTK coding style - nicInitializeAdapter()
620 **  \main\maintrunk.MT6620WiFiDriver_Prj\7 2009-04-17 19:52:47 GMT mtk01461
621 **  Update allocate Adapter Memory for MGMT Memory pool
622 **  \main\maintrunk.MT6620WiFiDriver_Prj\6 2009-04-01 10:57:08 GMT mtk01461
623 **  Refine the order of release memory from pucRxCoalescingBufCached
624 **  \main\maintrunk.MT6620WiFiDriver_Prj\5 2009-03-19 18:32:57 GMT mtk01084
625 **  update for basic power management functions
626 **  \main\maintrunk.MT6620WiFiDriver_Prj\4 2009-03-18 21:00:14 GMT mtk01426
627 **  Add CFG_SDIO_RX_ENHANCE support
628 **  \main\maintrunk.MT6620WiFiDriver_Prj\3 2009-03-16 09:10:27 GMT mtk01461
629 **  Update TX PATH API
630 **  \main\maintrunk.MT6620WiFiDriver_Prj\2 2009-03-10 20:25:59 GMT mtk01426
631 **  Init for develop
632 **
633 */
634
635 /*******************************************************************************
636 *                         C O M P I L E R   F L A G S
637 ********************************************************************************
638 */
639
640 /*******************************************************************************
641 *                    E X T E R N A L   R E F E R E N C E S
642 ********************************************************************************
643 */
644 #include "precomp.h"
645
646
647 /*******************************************************************************
648 *                              C O N S T A N T S
649 ********************************************************************************
650 */
651 const UINT_8 aucPhyCfg2PhyTypeSet[PHY_CONFIG_NUM] =
652 {
653     PHY_TYPE_SET_802_11ABG,         /* PHY_CONFIG_802_11ABG */
654     PHY_TYPE_SET_802_11BG,          /* PHY_CONFIG_802_11BG */
655     PHY_TYPE_SET_802_11G,           /* PHY_CONFIG_802_11G */
656     PHY_TYPE_SET_802_11A,           /* PHY_CONFIG_802_11A */
657     PHY_TYPE_SET_802_11B,           /* PHY_CONFIG_802_11B */
658     PHY_TYPE_SET_802_11ABGN,        /* PHY_CONFIG_802_11ABGN */
659     PHY_TYPE_SET_802_11BGN,         /* PHY_CONFIG_802_11BGN */
660     PHY_TYPE_SET_802_11AN,          /* PHY_CONFIG_802_11AN */
661     PHY_TYPE_SET_802_11GN           /* PHY_CONFIG_802_11GN */
662 };
663
664 #if (MT6620_E1_ASIC_HIFSYS_WORKAROUND == 1)
665     #define REQ_GATING_ENABLE_H2D_INT   BIT(31)
666     #define REQ_GATING_DISABLE_H2D_INT  BIT(30)
667     #define ACK_GATING_ENABLE_D2H_INT   BIT(31)
668     #define ACK_GATING_DISABLE_D2H_INT  BIT(30)
669
670     #define GATING_CONTROL_POLL_LIMIT   64
671 #endif
672
673 /*******************************************************************************
674 *                             D A T A   T Y P E S
675 ********************************************************************************
676 */
677
678 /*******************************************************************************
679 *                            P U B L I C   D A T A
680 ********************************************************************************
681 */
682
683 static INT_EVENT_MAP_T arIntEventMapTable[] = {
684     {WHISR_ABNORMAL_INT,                        INT_EVENT_ABNORMAL},
685     {WHISR_D2H_SW_INT,                          INT_EVENT_SW_INT},
686     {WHISR_TX_DONE_INT,                         INT_EVENT_TX},
687     {(WHISR_RX0_DONE_INT | WHISR_RX1_DONE_INT), INT_EVENT_RX}
688 };
689
690 static const UINT_8 ucIntEventMapSize = (sizeof(arIntEventMapTable) / sizeof(INT_EVENT_MAP_T));
691
692 static IST_EVENT_FUNCTION apfnEventFuncTable[] = {
693     nicProcessAbnormalInterrupt,            /*!< INT_EVENT_ABNORMAL */
694     nicProcessSoftwareInterrupt,            /*!< INT_EVENT_SW_INT   */
695     nicProcessTxInterrupt,                  /*!< INT_EVENT_TX       */
696     nicProcessRxInterrupt,                  /*!< INT_EVENT_RX       */
697 };
698 /*******************************************************************************
699 *                           P R I V A T E   D A T A
700 ********************************************************************************
701 */
702
703 /*******************************************************************************
704 *                                 M A C R O S
705 ********************************************************************************
706 */
707 /*! This macro is used to reduce coding errors inside nicAllocateAdapterMemory()
708  * and also enhance the readability.
709  */
710 #define LOCAL_NIC_ALLOCATE_MEMORY(pucMem, u4Size, eMemType, pucComment) \
711         { \
712             DBGLOG(INIT, INFO, ("Allocating %ld bytes for %s.\n", u4Size, pucComment)); \
713             if ((pucMem = (PUINT_8)kalMemAlloc(u4Size, eMemType)) == (PUINT_8)NULL) { \
714                 DBGLOG(INIT, ERROR, ("Could not allocate %ld bytes for %s.\n", u4Size, pucComment)); \
715                 break; \
716             } \
717             ASSERT(((UINT_32)pucMem % 4) == 0); \
718             DBGLOG(INIT, INFO, ("Virtual Address = %08lx for %s.\n", (UINT_32)pucMem, pucComment)); \
719         }
720
721
722
723 /*******************************************************************************
724 *                   F U N C T I O N   D E C L A R A T I O N S
725 ********************************************************************************
726 */
727
728 /*******************************************************************************
729 *                              F U N C T I O N S
730 ********************************************************************************
731 */
732
733
734 /*----------------------------------------------------------------------------*/
735 /*!
736 * @brief This routine is responsible for the allocation of the data structures
737 *        inside the Adapter structure, include:
738 *        1. SW_RFB_Ts
739 *        2. Common coalescing buffer for TX PATH.
740 *
741 * @param prAdapter Pointer of Adapter Data Structure
742 *
743 * @retval WLAN_STATUS_SUCCESS - Has enough memory.
744 * @retval WLAN_STATUS_RESOURCES - Memory is not enough.
745 */
746 /*----------------------------------------------------------------------------*/
747 WLAN_STATUS
748 nicAllocateAdapterMemory (
749     IN P_ADAPTER_T prAdapter
750     )
751 {
752     WLAN_STATUS status = WLAN_STATUS_RESOURCES;
753     P_RX_CTRL_T prRxCtrl;
754     P_TX_CTRL_T prTxCtrl;
755
756     DEBUGFUNC("nicAllocateAdapterMemory");
757
758     ASSERT(prAdapter);
759     prRxCtrl = &prAdapter->rRxCtrl;
760     prTxCtrl = &prAdapter->rTxCtrl;
761
762     do {
763         //4 <0> Reset all Memory Handler
764     #if CFG_DBG_MGT_BUF
765         prAdapter->u4MemFreeDynamicCount = 0;
766         prAdapter->u4MemAllocDynamicCount = 0;
767     #endif
768         prAdapter->pucMgtBufCached = (PUINT_8)NULL;
769         prRxCtrl->pucRxCached = (PUINT_8)NULL;
770         prAdapter->prSDIOCtrl = (P_SDIO_CTRL_T)NULL;
771
772
773         //4 <1> Memory for Management Memory Pool and CMD_INFO_T
774         /* Allocate memory for the CMD_INFO_T and its MGMT memory pool. */
775         prAdapter->u4MgtBufCachedSize = MGT_BUFFER_SIZE;
776
777         LOCAL_NIC_ALLOCATE_MEMORY(prAdapter->pucMgtBufCached,
778                                   prAdapter->u4MgtBufCachedSize,
779                                   VIR_MEM_TYPE,
780                                   "COMMON MGMT MEMORY POOL");
781
782         //4 <2> Memory for RX Descriptor
783         /* Initialize the number of rx buffers we will have in our queue. */
784         /* <TODO> We may setup ucRxPacketDescriptors by GLUE Layer, and using
785          * this variable directly.
786          */
787         /* Allocate memory for the SW receive structures. */
788         prRxCtrl->u4RxCachedSize = CFG_RX_MAX_PKT_NUM * \
789                                    ALIGN_4(sizeof(SW_RFB_T));
790
791         LOCAL_NIC_ALLOCATE_MEMORY(prRxCtrl->pucRxCached,
792                                   prRxCtrl->u4RxCachedSize,
793                                   VIR_MEM_TYPE,
794                                   "SW_RFB_T");
795
796         //4 <3> Memory for TX DEscriptor
797         prTxCtrl->u4TxCachedSize = CFG_TX_MAX_PKT_NUM * \
798                                    ALIGN_4(sizeof(MSDU_INFO_T));
799
800         LOCAL_NIC_ALLOCATE_MEMORY(prTxCtrl->pucTxCached,
801                                   prTxCtrl->u4TxCachedSize,
802                                   VIR_MEM_TYPE,
803                                   "MSDU_INFO_T");
804
805         //4 <4> Memory for Common Coalescing Buffer
806 #if CFG_COALESCING_BUFFER_SIZE || CFG_SDIO_RX_AGG
807         prAdapter->pucCoalescingBufCached = (PUINT_8)NULL;
808
809         /* Allocate memory for the common coalescing buffer. */
810         prAdapter->u4CoalescingBufCachedSize = CFG_COALESCING_BUFFER_SIZE > CFG_RX_COALESCING_BUFFER_SIZE ?
811             CFG_COALESCING_BUFFER_SIZE : CFG_RX_COALESCING_BUFFER_SIZE;
812
813         prAdapter->pucCoalescingBufCached =
814             kalAllocateIOBuffer(prAdapter->u4CoalescingBufCachedSize);
815
816         if(prAdapter->pucCoalescingBufCached == NULL) {
817             DBGLOG(INIT, ERROR, ("Could not allocate %ld bytes for coalescing buffer.\n", prAdapter->u4CoalescingBufCachedSize));
818             break;
819         }
820 #endif /* CFG_COALESCING_BUFFER_SIZE */
821
822         //4 <5> Memory for enhanced interrupt response
823         prAdapter->prSDIOCtrl = (P_SDIO_CTRL_T)
824             kalAllocateIOBuffer(sizeof(ENHANCE_MODE_DATA_STRUCT_T));
825
826         if(prAdapter->prSDIOCtrl == NULL) {
827             DBGLOG(INIT, ERROR, ("Could not allocate %ld bytes for interrupt response.\n", sizeof(ENHANCE_MODE_DATA_STRUCT_T)));
828             break;
829         }
830
831         status = WLAN_STATUS_SUCCESS;
832
833     }
834     while(FALSE);
835
836     if(status != WLAN_STATUS_SUCCESS) {
837         nicReleaseAdapterMemory(prAdapter);
838     }
839
840     return status;
841
842 }   /* end of nicAllocateAdapterMemory() */
843
844
845 /*----------------------------------------------------------------------------*/
846 /*!
847 * @brief This routine is responsible for releasing the allocated memory by
848 *        nicAllocatedAdapterMemory().
849 *
850 * @param prAdapter Pointer of Adapter Data Structure
851 *
852 * @return (none)
853 */
854 /*----------------------------------------------------------------------------*/
855 VOID
856 nicReleaseAdapterMemory (
857     IN P_ADAPTER_T prAdapter
858     )
859 {
860     P_TX_CTRL_T prTxCtrl;
861     P_RX_CTRL_T prRxCtrl;
862
863     ASSERT(prAdapter);
864     prTxCtrl = &prAdapter->rTxCtrl;
865     prRxCtrl = &prAdapter->rRxCtrl;
866
867     //4 <5> Memory for enhanced interrupt response
868     if (prAdapter->prSDIOCtrl) {
869         kalReleaseIOBuffer((PVOID)prAdapter->prSDIOCtrl, sizeof(ENHANCE_MODE_DATA_STRUCT_T));
870         prAdapter->prSDIOCtrl = (P_SDIO_CTRL_T)NULL;
871     }
872
873     //4 <4> Memory for Common Coalescing Buffer
874 #if CFG_COALESCING_BUFFER_SIZE || CFG_SDIO_RX_AGG
875     if (prAdapter->pucCoalescingBufCached) {
876         kalReleaseIOBuffer((PVOID)prAdapter->pucCoalescingBufCached, prAdapter->u4CoalescingBufCachedSize);
877         prAdapter->pucCoalescingBufCached = (PUINT_8)NULL;
878     }
879 #endif /* CFG_COALESCING_BUFFER_SIZE */
880
881     //4 <3> Memory for TX Descriptor
882     if (prTxCtrl->pucTxCached) {
883         kalMemFree((PVOID)prTxCtrl->pucTxCached,
884                    VIR_MEM_TYPE,
885                    prTxCtrl->u4TxCachedSize);
886         prTxCtrl->pucTxCached = (PUINT_8)NULL;
887     }
888
889     //4 <2> Memory for RX Descriptor
890     if (prRxCtrl->pucRxCached) {
891         kalMemFree((PVOID)prRxCtrl->pucRxCached,
892                    VIR_MEM_TYPE,
893                    prRxCtrl->u4RxCachedSize);
894         prRxCtrl->pucRxCached = (PUINT_8)NULL;
895     }
896
897     //4 <1> Memory for Management Memory Pool
898     if (prAdapter->pucMgtBufCached) {
899         kalMemFree((PVOID)prAdapter->pucMgtBufCached,
900                    VIR_MEM_TYPE,
901                    prAdapter->u4MgtBufCachedSize);
902         prAdapter->pucMgtBufCached = (PUINT_8)NULL;
903     }
904
905 #if CFG_DBG_MGT_BUF
906     /* Check if all allocated memories are free */
907     ASSERT(prAdapter->u4MemFreeDynamicCount ==
908            prAdapter->u4MemAllocDynamicCount);
909 #endif
910
911     return;
912 }
913
914
915 /*----------------------------------------------------------------------------*/
916 /*!
917 * @brief disable global interrupt
918 *
919 * @param prAdapter pointer to the Adapter handler
920 *
921 * @return (none)
922 */
923 /*----------------------------------------------------------------------------*/
924 VOID
925 nicDisableInterrupt (
926     IN P_ADAPTER_T prAdapter
927     )
928 {
929     ASSERT(prAdapter);
930
931     HAL_BYTE_WR(prAdapter, MCR_WHLPCR, WHLPCR_INT_EN_CLR);
932
933     prAdapter->fgIsIntEnable = FALSE;
934 }
935
936 /*----------------------------------------------------------------------------*/
937 /*!
938 * @brief enable global interrupt
939 *
940 * @param prAdapter pointer to the Adapter handler
941 *
942 * @return (none)
943 */
944 /*----------------------------------------------------------------------------*/
945 VOID
946 nicEnableInterrupt (
947     IN P_ADAPTER_T prAdapter
948     )
949 {
950     BOOLEAN fgIsIntEnableCache;
951
952
953     ASSERT(prAdapter);
954     fgIsIntEnableCache = prAdapter->fgIsIntEnable;
955
956     prAdapter->fgIsIntEnable = TRUE; // NOTE(Kevin): It must be placed before MCR GINT write.
957
958     /* If need enable INT and also set LPOwn at the same time. */
959     if (prAdapter->fgIsIntEnableWithLPOwnSet) {
960         prAdapter->fgIsIntEnableWithLPOwnSet = FALSE; /* NOTE(Kevin): It's better to place it
961                                                        * before MCR GINT write.
962                                                        */
963         /* If INT was enabled, only set LPOwn */
964         if (fgIsIntEnableCache) {
965             HAL_MCR_WR(prAdapter, MCR_WHLPCR, WHLPCR_FW_OWN_REQ_SET);
966             prAdapter->fgIsFwOwn = TRUE;
967         }
968         /* If INT was not enabled, enable it and also set LPOwn now */
969         else {
970             HAL_MCR_WR(prAdapter, MCR_WHLPCR, WHLPCR_FW_OWN_REQ_SET |
971                                               WHLPCR_INT_EN_SET);
972             prAdapter->fgIsFwOwn = TRUE;
973         }
974     }
975     /* If INT was not enabled, enable it now */
976     else if (!fgIsIntEnableCache) {
977         HAL_BYTE_WR(prAdapter, MCR_WHLPCR, WHLPCR_INT_EN_SET);
978     }
979
980     return;
981 } /* end of nicEnableInterrupt() */
982
983
984 #if CFG_SDIO_INTR_ENHANCE
985 /*----------------------------------------------------------------------------*/
986 /*!
987 * @brief For SDIO enhance mode, set the max rx len and tx status
988 *
989 * @param prAdapter      a pointer to adapter private data structure.
990 *
991 * @return  - none
992 */
993 /*----------------------------------------------------------------------------*/
994 VOID
995 nicSDIOInit (
996     IN P_ADAPTER_T prAdapter
997     )
998 {
999     UINT_32 u4Value = 0;
1000
1001     ASSERT(prAdapter);
1002
1003     //4 <1> Check STATUS Buffer is DW alignment.
1004     ASSERT( IS_ALIGN_4( (UINT_32)&prAdapter->prSDIOCtrl->u4WHISR ) );
1005
1006     //4 <2> Setup STATUS count.
1007     {
1008         HAL_MCR_RD(prAdapter, MCR_WHCR, &u4Value);
1009
1010         //4 <2.1> Setup the number of maximum RX length to be report
1011         u4Value &= ~(WHCR_MAX_HIF_RX_LEN_NUM);
1012         u4Value |= ((SDIO_MAXIMUM_RX_LEN_NUM << WHCR_OFFSET_MAX_HIF_RX_LEN_NUM));
1013
1014         //4 <2.2> Setup RX enhancement mode
1015 #if CFG_SDIO_RX_ENHANCE
1016         u4Value |= WHCR_RX_ENHANCE_MODE_EN;
1017 #else
1018         u4Value &= ~WHCR_RX_ENHANCE_MODE_EN;
1019 #endif /* CFG_SDIO_RX_AGG */
1020
1021         HAL_MCR_WR(prAdapter, MCR_WHCR, u4Value);
1022     }
1023
1024     return;
1025
1026 } /* end of nicSDIOInit() */
1027
1028 /*----------------------------------------------------------------------------*/
1029 /*!
1030 * @brief Read interrupt status from hardware
1031 *
1032 * @param prAdapter pointer to the Adapter handler
1033 * @param the interrupts
1034 *
1035 * @return N/A
1036 *
1037 */
1038 /*----------------------------------------------------------------------------*/
1039 VOID
1040 nicSDIOReadIntStatus (
1041     IN P_ADAPTER_T prAdapter,
1042     OUT PUINT_32   pu4IntStatus
1043     )
1044 {
1045     P_SDIO_CTRL_T prSDIOCtrl;
1046
1047     DEBUGFUNC("nicSDIOReadIntStatus");
1048
1049     ASSERT(prAdapter);
1050     ASSERT(pu4IntStatus);
1051
1052     prSDIOCtrl = prAdapter->prSDIOCtrl;
1053     ASSERT(prSDIOCtrl);
1054
1055     HAL_PORT_RD(prAdapter,
1056                 MCR_WHISR,
1057                 sizeof(ENHANCE_MODE_DATA_STRUCT_T),
1058                 (PUINT_8)prSDIOCtrl,
1059                 sizeof(ENHANCE_MODE_DATA_STRUCT_T));
1060
1061     if(kalIsCardRemoved(prAdapter->prGlueInfo) == TRUE
1062             || fgIsBusAccessFailed == TRUE) {
1063         *pu4IntStatus = 0;
1064         return;
1065     }
1066
1067     /* workaround */
1068     if((prSDIOCtrl->u4WHISR & WHISR_TX_DONE_INT) == 0 &&
1069             (prSDIOCtrl->rTxInfo.au4WTSR[0] | prSDIOCtrl->rTxInfo.au4WTSR[1])) {
1070         prSDIOCtrl->u4WHISR |= WHISR_TX_DONE_INT;
1071     }
1072
1073     if((prSDIOCtrl->u4WHISR & BIT(31)) == 0 &&
1074             HAL_GET_MAILBOX_READ_CLEAR(prAdapter) == TRUE &&
1075             (prSDIOCtrl->u4RcvMailbox0 != 0 || prSDIOCtrl->u4RcvMailbox1 != 0)) {
1076         prSDIOCtrl->u4WHISR |= BIT(31);
1077     }
1078
1079     *pu4IntStatus = prSDIOCtrl->u4WHISR;
1080
1081     return;
1082 } /* end of nicSDIOReadIntStatus() */
1083 #endif
1084
1085 /*----------------------------------------------------------------------------*/
1086 /*!
1087 * @brief The function used to read interrupt status and then invoking
1088 *        dispatching procedure for the appropriate functions
1089 *        corresponding to specific interrupt bits
1090 *
1091 * @param prAdapter pointer to the Adapter handler
1092 *
1093 * @retval WLAN_STATUS_SUCCESS
1094 * @retval WLAN_STATUS_ADAPTER_NOT_READY
1095 */
1096 /*----------------------------------------------------------------------------*/
1097 WLAN_STATUS
1098 nicProcessIST (
1099     IN P_ADAPTER_T prAdapter
1100     )
1101 {
1102     WLAN_STATUS u4Status = WLAN_STATUS_SUCCESS;
1103     UINT_32 u4IntStatus = 0;
1104     UINT_32 i;
1105
1106     DEBUGFUNC("nicProcessIST");
1107     //DBGLOG(INIT, LOUD, ("\n"));
1108
1109     ASSERT(prAdapter);
1110
1111     if (prAdapter->rAcpiState == ACPI_STATE_D3) {
1112         DBGLOG(REQ, WARN, ("Fail in set nicProcessIST! (Adapter not ready). ACPI=D%d, Radio=%d\n",
1113                     prAdapter->rAcpiState, prAdapter->fgIsRadioOff));
1114         return WLAN_STATUS_ADAPTER_NOT_READY;
1115     }
1116
1117 #if (MT6620_E1_ASIC_HIFSYS_WORKAROUND == 1)
1118     if(prAdapter->fgIsClockGatingEnabled == TRUE) {
1119         nicDisableClockGating(prAdapter);
1120     }
1121 #endif
1122
1123     for (i = 0; i < CFG_IST_LOOP_COUNT; i++) {
1124
1125 #if CFG_SDIO_INTR_ENHANCE
1126         nicSDIOReadIntStatus(prAdapter, &u4IntStatus);
1127 #else
1128         HAL_MCR_RD(prAdapter, MCR_WHISR, &u4IntStatus);
1129 #endif /* CFG_SDIO_INTR_ENHANCE */
1130
1131         //DBGLOG(INIT, TRACE, ("u4IntStatus: 0x%x\n", u4IntStatus));
1132
1133         if (u4IntStatus & ~(WHIER_DEFAULT | WHIER_FW_OWN_BACK_INT_EN)) {
1134             DBGLOG(INTR, WARN, ("Un-handled HISR %#x, HISR = %#x (HIER:0x%x)\n",
1135                 (u4IntStatus & ~WHIER_DEFAULT), u4IntStatus, WHIER_DEFAULT));
1136             u4IntStatus &= WHIER_DEFAULT;
1137         }
1138
1139         nicProcessIST_impl(prAdapter, u4IntStatus);
1140
1141         if(u4IntStatus == 0) {
1142             if(i == 0) {
1143                 u4Status = WLAN_STATUS_NOT_INDICATING;
1144             }
1145             break;
1146         }
1147     }
1148
1149 #if (MT6620_E1_ASIC_HIFSYS_WORKAROUND == 1)
1150     if(prAdapter->fgIsClockGatingEnabled == FALSE) {
1151         nicEnableClockGating(prAdapter);
1152     }
1153 #endif
1154
1155     return u4Status;
1156 } /* end of nicProcessIST() */
1157
1158
1159 /*----------------------------------------------------------------------------*/
1160 /*!
1161 * @brief The function used to dispatch the appropriate functions for specific
1162 *        interrupt bits
1163 *
1164 * @param prAdapter   pointer to the Adapter handler
1165 *        u4IntStatus interrupt status bits
1166 *
1167 * @retval WLAN_STATUS_SUCCESS
1168 * @retval WLAN_STATUS_ADAPTER_NOT_READY
1169 */
1170 /*----------------------------------------------------------------------------*/
1171 WLAN_STATUS
1172 nicProcessIST_impl (
1173     IN P_ADAPTER_T prAdapter,
1174     IN UINT_32 u4IntStatus
1175     )
1176 {
1177     UINT_32 u4IntCount = 0;
1178     P_INT_EVENT_MAP_T prIntEventMap = NULL;
1179
1180     ASSERT(prAdapter);
1181
1182     prAdapter->u4IntStatus = u4IntStatus;
1183
1184     /* Process each of the interrupt status consequently */
1185     prIntEventMap = &arIntEventMapTable[0];
1186     for (u4IntCount = 0; u4IntCount < ucIntEventMapSize; prIntEventMap++, u4IntCount++) {
1187         if (prIntEventMap->u4Int & prAdapter->u4IntStatus) {
1188             if(prIntEventMap->u4Event == INT_EVENT_RX &&
1189                     prAdapter->fgIsEnterD3ReqIssued == TRUE) {
1190                 // ignore
1191             }
1192             else if (apfnEventFuncTable[prIntEventMap->u4Event] != NULL) {
1193                 apfnEventFuncTable[prIntEventMap->u4Event](prAdapter);
1194             }
1195             else {
1196                 DBGLOG(INTR , WARN,
1197                         ("Empty INTR handler! ISAR bit#: %ld, event:%d, func: 0x%x\n",
1198                          prIntEventMap->u4Int, prIntEventMap->u4Event, apfnEventFuncTable[prIntEventMap->u4Event]));
1199
1200                 ASSERT(0); // to trap any NULL interrupt handler
1201             }
1202             prAdapter->u4IntStatus &= ~prIntEventMap->u4Int;
1203         }
1204     }
1205
1206     return WLAN_STATUS_SUCCESS;
1207 } /* end of nicProcessIST_impl() */
1208
1209
1210 /*----------------------------------------------------------------------------*/
1211 /*!
1212 * @brief Verify the CHIP ID
1213 *
1214 * @param prAdapter      a pointer to adapter private data structure.
1215 *
1216 *
1217 * @retval TRUE          CHIP ID is the same as the setting compiled
1218 * @retval FALSE         CHIP ID is different from the setting compiled
1219 */
1220 /*----------------------------------------------------------------------------*/
1221 BOOL
1222 nicVerifyChipID (
1223     IN P_ADAPTER_T prAdapter
1224     )
1225 {
1226     UINT_32 u4CIR = 0;
1227
1228     ASSERT(prAdapter);
1229
1230     HAL_MCR_RD(prAdapter, MCR_WCIR, &u4CIR );
1231
1232     DBGLOG(INIT, TRACE,("Chip ID: 0x%x\n", u4CIR & WCIR_CHIP_ID));
1233     DBGLOG(INIT, TRACE,("Revision ID: 0x%x\n", ((u4CIR & WCIR_REVISION_ID) >> 16)));
1234
1235     if ((u4CIR & WCIR_CHIP_ID) != MTK_CHIP_REV) {
1236         return FALSE;
1237     }
1238
1239     prAdapter->ucRevID = (UINT_8)(((u4CIR & WCIR_REVISION_ID) >> 16) & 0xF) ;
1240
1241     return TRUE;
1242 }
1243
1244 /*----------------------------------------------------------------------------*/
1245 /*!
1246 * @brief Initialize the MCR to the appropriate init value, and verify the init
1247 *        value
1248 *
1249 * @param prAdapter      a pointer to adapter private data structure.
1250 *
1251 * @return -
1252 */
1253 /*----------------------------------------------------------------------------*/
1254 VOID
1255 nicMCRInit (
1256     IN P_ADAPTER_T prAdapter
1257     )
1258 {
1259
1260     ASSERT(prAdapter);
1261
1262     //4 <0> Initial value
1263 }
1264
1265 VOID
1266 nicHifInit (
1267     IN P_ADAPTER_T prAdapter
1268     )
1269 {
1270
1271     ASSERT(prAdapter);
1272 #if 0
1273     /* reset event */
1274     nicPutMailbox(prAdapter, 0, 0x52455345); // RESE
1275     nicPutMailbox(prAdapter, 1, 0x545F5746); // T_WF
1276     nicSetSwIntr(prAdapter, BIT(16));
1277 #endif
1278 }
1279
1280
1281 /*----------------------------------------------------------------------------*/
1282 /*!
1283 * @brief Initialize the Adapter soft variable
1284 *
1285 * @param prAdapter pointer to the Adapter handler
1286 *
1287 * @return (none)
1288 *
1289 */
1290 /*----------------------------------------------------------------------------*/
1291 WLAN_STATUS
1292 nicInitializeAdapter (
1293     IN P_ADAPTER_T prAdapter
1294     )
1295 {
1296     WLAN_STATUS u4Status = WLAN_STATUS_SUCCESS;
1297
1298     ASSERT(prAdapter);
1299
1300     prAdapter->fgIsIntEnableWithLPOwnSet = FALSE;
1301
1302     do {
1303         if (!nicVerifyChipID(prAdapter)) {
1304             u4Status = WLAN_STATUS_FAILURE;
1305             break;
1306         }
1307
1308         //4 <1> MCR init
1309         nicMCRInit(prAdapter);
1310
1311     #if CFG_SDIO_INTR_ENHANCE
1312         nicSDIOInit(prAdapter);
1313     #endif /* CFG_SDIO_INTR_ENHANCE */
1314
1315         HAL_MCR_WR(prAdapter, MCR_WHIER, WHIER_DEFAULT);
1316
1317
1318         //4 <2> init FW HIF
1319         nicHifInit(prAdapter);
1320     }
1321     while (FALSE);
1322
1323
1324     return u4Status;
1325 }
1326
1327
1328 #if defined(_HIF_SPI)
1329 /*----------------------------------------------------------------------------*/
1330 /*!
1331 * \brief Restore the SPI Mode Select to default mode,
1332 *        this is important while driver is unload, and this must be last mcr
1333 *        since the operation will let the hif use 8bit mode access
1334 *
1335 * \param[in] prAdapter      a pointer to adapter private data structure.
1336 * \param[in] eGPIO2_Mode    GPIO2 operation mode
1337 *
1338 * \return (none)
1339 */
1340 /*----------------------------------------------------------------------------*/
1341 void
1342 nicRestoreSpiDefMode (
1343     IN P_ADAPTER_T prAdapter
1344     )
1345 {
1346     ASSERT(prAdapter);
1347
1348     HAL_MCR_WR(prAdapter, MCR_WCSR, SPICSR_8BIT_MODE_DATA);
1349
1350 }
1351 #endif
1352
1353 /*----------------------------------------------------------------------------*/
1354 /*!
1355 * @brief Process rx interrupt. When the rx
1356 *        Interrupt is asserted, it means there are frames in queue.
1357 *
1358 * @param prAdapter      Pointer to the Adapter structure.
1359 *
1360 * @return (none)
1361 */
1362 /*----------------------------------------------------------------------------*/
1363 VOID
1364 nicProcessAbnormalInterrupt (
1365     IN  P_ADAPTER_T prAdapter
1366     )
1367 {
1368     UINT_32 u4Value;
1369
1370     HAL_MCR_RD(prAdapter, MCR_WASR, &u4Value);
1371     DBGLOG(REQ, WARN, ("MCR_WASR: 0x%x \n", u4Value));
1372 }
1373
1374 /*----------------------------------------------------------------------------*/
1375 /*!
1376 * @brief .
1377 *
1378 * @param prAdapter  Pointer to the Adapter structure.
1379 *
1380 * @return (none)
1381 */
1382 /*----------------------------------------------------------------------------*/
1383 VOID
1384 nicProcessFwOwnBackInterrupt(
1385     IN P_ADAPTER_T prAdapter
1386     )
1387 {
1388
1389     return;
1390 } /* end of nicProcessFwOwnBackInterrupt() */
1391
1392 /*----------------------------------------------------------------------------*/
1393 /*!
1394 * @brief .
1395 *
1396 * @param prAdapter  Pointer to the Adapter structure.
1397 *
1398 * @return (none)
1399 */
1400 /*----------------------------------------------------------------------------*/
1401 VOID
1402 nicProcessSoftwareInterrupt(
1403     IN P_ADAPTER_T prAdapter
1404     )
1405 {
1406     UINT_32 u4IntrBits;
1407
1408     ASSERT(prAdapter);
1409
1410     u4IntrBits = prAdapter->u4IntStatus & BITS(8, 31);
1411
1412     if((u4IntrBits & WHISR_D2H_SW_ASSERT_INFO_INT) != 0) {
1413         nicPrintFirmwareAssertInfo(prAdapter);
1414 #if CFG_CHIP_RESET_SUPPORT
1415         glSendResetRequest();
1416 #endif
1417     }
1418
1419 #if (MT6620_E1_ASIC_HIFSYS_WORKAROUND == 1)
1420     ASSERT((u4IntrBits & (ACK_GATING_ENABLE_D2H_INT | ACK_GATING_DISABLE_D2H_INT))
1421             != (ACK_GATING_ENABLE_D2H_INT | ACK_GATING_DISABLE_D2H_INT));
1422
1423     if(u4IntrBits & ACK_GATING_ENABLE_D2H_INT) {
1424         prAdapter->fgIsClockGatingEnabled = TRUE;
1425     }
1426
1427     if(u4IntrBits & ACK_GATING_DISABLE_D2H_INT) {
1428         prAdapter->fgIsClockGatingEnabled = FALSE;
1429
1430         // Indicate Service Thread for TX
1431         if(kalGetTxPendingCmdCount(prAdapter->prGlueInfo) > 0
1432                 || wlanGetTxPendingFrameCount(prAdapter) > 0) {
1433             kalSetEvent(prAdapter->prGlueInfo);
1434         }
1435     }
1436 #endif
1437
1438     DBGLOG(REQ, WARN, ("u4IntrBits: 0x%x \n", u4IntrBits));
1439
1440     return;
1441 } /* end of nicProcessSoftwareInterrupt() */
1442
1443 VOID
1444 nicPutMailbox (
1445     IN P_ADAPTER_T prAdapter,
1446     IN UINT_32 u4MailboxNum,
1447     IN UINT_32 u4Data
1448     )
1449 {
1450     if (u4MailboxNum == 0) {
1451         HAL_MCR_WR(prAdapter, MCR_H2DSM0R, u4Data);
1452     } else if (u4MailboxNum == 1) {
1453         HAL_MCR_WR(prAdapter, MCR_H2DSM1R, u4Data);
1454     } else {
1455         ASSERT(0);
1456     }
1457 }
1458
1459 VOID
1460 nicGetMailbox (
1461     IN P_ADAPTER_T prAdapter,
1462     IN UINT_32 u4MailboxNum,
1463     OUT PUINT_32 pu4Data
1464     )
1465 {
1466     if (u4MailboxNum == 0) {
1467         HAL_MCR_RD(prAdapter, MCR_D2HRM0R, pu4Data);
1468     } else if (u4MailboxNum == 1) {
1469         HAL_MCR_RD(prAdapter, MCR_D2HRM1R, pu4Data);
1470     } else {
1471         ASSERT(0);
1472     }
1473 }
1474
1475 VOID
1476 nicSetSwIntr (
1477     IN P_ADAPTER_T prAdapter,
1478     IN UINT_32 u4SwIntrBitmap
1479     )
1480 {
1481     /* NOTE:
1482      *  SW interrup in HW bit 16 is mapping to SW bit 0 (shift 16bit in HW transparancy)
1483      *  SW interrupt valid from b0~b15
1484      */
1485     ASSERT((u4SwIntrBitmap & BITS(0, 15)) == 0);
1486 //    DBGLOG(INIT, TRACE, ("u4SwIntrBitmap: 0x%08x\n", u4SwIntrBitmap));
1487
1488     HAL_MCR_WR(prAdapter, MCR_WSICR, u4SwIntrBitmap);
1489 }
1490
1491
1492 /*----------------------------------------------------------------------------*/
1493 /*!
1494 * @brief This procedure is used to dequeue from prAdapter->rPendingCmdQueue
1495 *        with specified sequential number
1496 *
1497 * @param    prAdapter   Pointer of ADAPTER_T
1498 *           ucSeqNum    Sequential Number
1499 *
1500 * @retval - P_CMD_INFO_T
1501 */
1502 /*----------------------------------------------------------------------------*/
1503 P_CMD_INFO_T
1504 nicGetPendingCmdInfo (
1505     IN P_ADAPTER_T prAdapter,
1506     IN UINT_8 ucSeqNum
1507     )
1508 {
1509     P_QUE_T prCmdQue;
1510     QUE_T rTempCmdQue;
1511     P_QUE_T prTempCmdQue = &rTempCmdQue;
1512     P_QUE_ENTRY_T prQueueEntry = (P_QUE_ENTRY_T)NULL;
1513     P_CMD_INFO_T prCmdInfo = (P_CMD_INFO_T)NULL;
1514
1515     GLUE_SPIN_LOCK_DECLARATION();
1516
1517     ASSERT(prAdapter);
1518
1519     KAL_ACQUIRE_SPIN_LOCK(prAdapter, SPIN_LOCK_CMD_PENDING);
1520
1521     prCmdQue = &prAdapter->rPendingCmdQueue;
1522     QUEUE_MOVE_ALL(prTempCmdQue, prCmdQue);
1523
1524     QUEUE_REMOVE_HEAD(prTempCmdQue, prQueueEntry, P_QUE_ENTRY_T);
1525     while (prQueueEntry) {
1526         prCmdInfo = (P_CMD_INFO_T)prQueueEntry;
1527
1528         if(prCmdInfo->ucCmdSeqNum == ucSeqNum)
1529             break;
1530         else {
1531             QUEUE_INSERT_TAIL(prCmdQue, prQueueEntry);
1532
1533             prCmdInfo = NULL;
1534         }
1535
1536         QUEUE_REMOVE_HEAD(prTempCmdQue, prQueueEntry, P_QUE_ENTRY_T);
1537     }
1538     QUEUE_CONCATENATE_QUEUES(prCmdQue, prTempCmdQue);
1539
1540     KAL_RELEASE_SPIN_LOCK(prAdapter, SPIN_LOCK_CMD_PENDING);
1541
1542     return prCmdInfo;
1543 }
1544
1545
1546 /*----------------------------------------------------------------------------*/
1547 /*!
1548 * @brief This procedure is used to dequeue from prAdapter->rTxCtrl.rTxMgmtTxingQueue
1549 *        with specified sequential number
1550 *
1551 * @param    prAdapter   Pointer of ADAPTER_T
1552 *           ucSeqNum    Sequential Number
1553 *
1554 * @retval - P_MSDU_INFO_T
1555 */
1556 /*----------------------------------------------------------------------------*/
1557 P_MSDU_INFO_T
1558 nicGetPendingTxMsduInfo (
1559     IN P_ADAPTER_T prAdapter,
1560     IN UINT_8 ucSeqNum
1561     )
1562 {
1563     P_QUE_T prTxingQue;
1564     QUE_T rTempQue;
1565     P_QUE_T prTempQue = &rTempQue;
1566     P_QUE_ENTRY_T prQueueEntry = (P_QUE_ENTRY_T)NULL;
1567     P_MSDU_INFO_T prMsduInfo = (P_MSDU_INFO_T)NULL;
1568
1569     GLUE_SPIN_LOCK_DECLARATION();
1570
1571     ASSERT(prAdapter);
1572
1573     KAL_ACQUIRE_SPIN_LOCK(prAdapter, SPIN_LOCK_TXING_MGMT_LIST);
1574
1575     prTxingQue = &(prAdapter->rTxCtrl.rTxMgmtTxingQueue);
1576     QUEUE_MOVE_ALL(prTempQue, prTxingQue);
1577
1578     QUEUE_REMOVE_HEAD(prTempQue, prQueueEntry, P_QUE_ENTRY_T);
1579     while (prQueueEntry) {
1580         prMsduInfo = (P_MSDU_INFO_T)prQueueEntry;
1581
1582         if(prMsduInfo->ucTxSeqNum == ucSeqNum)
1583             break;
1584         else {
1585             QUEUE_INSERT_TAIL(prTxingQue, prQueueEntry);
1586
1587             prMsduInfo = NULL;
1588         }
1589
1590         QUEUE_REMOVE_HEAD(prTempQue, prQueueEntry, P_QUE_ENTRY_T);
1591     }
1592     QUEUE_CONCATENATE_QUEUES(prTxingQue, prTempQue);
1593
1594     KAL_RELEASE_SPIN_LOCK(prAdapter, SPIN_LOCK_TXING_MGMT_LIST);
1595
1596     return prMsduInfo;
1597 }
1598
1599 P_MSDU_INFO_T
1600 nicGetPendingStaMMPDU (
1601     IN P_ADAPTER_T prAdapter,
1602     IN UINT_8 ucStaRecIdx
1603     )
1604 {
1605     P_MSDU_INFO_T prMsduInfoListHead = (P_MSDU_INFO_T)NULL;
1606     P_QUE_T prTxingQue = (P_QUE_T)NULL;
1607     QUE_T rTempQue;
1608     P_QUE_T prTempQue = &rTempQue;
1609     P_QUE_ENTRY_T prQueueEntry = (P_QUE_ENTRY_T)NULL;
1610     P_MSDU_INFO_T prMsduInfo = (P_MSDU_INFO_T)NULL;
1611
1612     GLUE_SPIN_LOCK_DECLARATION();
1613
1614     KAL_ACQUIRE_SPIN_LOCK(prAdapter, SPIN_LOCK_TXING_MGMT_LIST);
1615     do {
1616         if (prAdapter == NULL) {
1617
1618             ASSERT(FALSE);
1619             break;
1620         }
1621
1622         prTxingQue = &(prAdapter->rTxCtrl.rTxMgmtTxingQueue);
1623         QUEUE_MOVE_ALL(prTempQue, prTxingQue);
1624
1625         QUEUE_REMOVE_HEAD(prTempQue, prQueueEntry, P_QUE_ENTRY_T);
1626         while (prQueueEntry) {
1627             prMsduInfo = (P_MSDU_INFO_T)prQueueEntry;
1628
1629             if ((prMsduInfo->ucStaRecIndex == ucStaRecIdx) && (prMsduInfo->pfTxDoneHandler != NULL)) {
1630                 QM_TX_SET_NEXT_MSDU_INFO(prMsduInfo,
1631                                     prMsduInfoListHead);
1632                 prMsduInfoListHead = prMsduInfo;
1633             }
1634             else {
1635                 QUEUE_INSERT_TAIL(prTxingQue, prQueueEntry);
1636
1637                 prMsduInfo = NULL;
1638             }
1639
1640
1641             QUEUE_REMOVE_HEAD(prTempQue, prQueueEntry, P_QUE_ENTRY_T);
1642         }
1643
1644     } while (FALSE);
1645     KAL_RELEASE_SPIN_LOCK(prAdapter, SPIN_LOCK_TXING_MGMT_LIST);
1646
1647
1648     return prMsduInfoListHead;
1649 } /* nicGetPendingStaMMPDU */
1650
1651
1652 VOID
1653 nicFreePendingTxMsduInfoByNetwork (
1654     IN P_ADAPTER_T                  prAdapter,
1655     IN ENUM_NETWORK_TYPE_INDEX_T    eNetworkType
1656     )
1657 {
1658     P_QUE_T prTxingQue;
1659     QUE_T rTempQue;
1660     P_QUE_T prTempQue = &rTempQue;
1661     P_QUE_ENTRY_T prQueueEntry = (P_QUE_ENTRY_T)NULL;
1662     P_MSDU_INFO_T prMsduInfoListHead = (P_MSDU_INFO_T)NULL;
1663     P_MSDU_INFO_T prMsduInfoListTail = (P_MSDU_INFO_T)NULL;
1664     P_MSDU_INFO_T prMsduInfo = (P_MSDU_INFO_T)NULL;
1665
1666     GLUE_SPIN_LOCK_DECLARATION();
1667
1668     ASSERT(prAdapter);
1669
1670     KAL_ACQUIRE_SPIN_LOCK(prAdapter, SPIN_LOCK_TXING_MGMT_LIST);
1671
1672     prTxingQue = &(prAdapter->rTxCtrl.rTxMgmtTxingQueue);
1673     QUEUE_MOVE_ALL(prTempQue, prTxingQue);
1674
1675     QUEUE_REMOVE_HEAD(prTempQue, prQueueEntry, P_QUE_ENTRY_T);
1676     while (prQueueEntry) {
1677         prMsduInfo = (P_MSDU_INFO_T)prQueueEntry;
1678
1679         if((ENUM_NETWORK_TYPE_INDEX_T)(prMsduInfo->ucNetworkType) == eNetworkType) {
1680             if(prMsduInfoListHead == NULL) {
1681                 prMsduInfoListHead = prMsduInfoListTail = prMsduInfo;
1682             }
1683             else {
1684                 QM_TX_SET_NEXT_MSDU_INFO(prMsduInfoListTail, prMsduInfo);
1685                 prMsduInfoListTail = prMsduInfo;
1686             }
1687         }
1688         else {
1689             QUEUE_INSERT_TAIL(prTxingQue, prQueueEntry);
1690
1691             prMsduInfo = NULL;
1692         }
1693
1694         QUEUE_REMOVE_HEAD(prTempQue, prQueueEntry, P_QUE_ENTRY_T);
1695     }
1696     QUEUE_CONCATENATE_QUEUES(prTxingQue, prTempQue);
1697
1698     KAL_RELEASE_SPIN_LOCK(prAdapter, SPIN_LOCK_TXING_MGMT_LIST);
1699
1700     /* free */
1701     if(prMsduInfoListHead) {
1702        nicTxFreeMsduInfoPacket(prAdapter, prMsduInfoListHead);
1703     }
1704
1705     return;
1706
1707 } /* end of nicFreePendingTxMsduInfoByNetwork() */
1708
1709
1710
1711 /*----------------------------------------------------------------------------*/
1712 /*!
1713 * @brief This procedure is used to retrieve a CMD sequence number atomically
1714 *
1715 * @param    prAdapter   Pointer of ADAPTER_T
1716 *
1717 * @retval - UINT_8
1718 */
1719 /*----------------------------------------------------------------------------*/
1720 UINT_8
1721 nicIncreaseCmdSeqNum (
1722     IN P_ADAPTER_T prAdapter
1723     )
1724 {
1725     UINT_8 ucRetval;
1726
1727     KAL_SPIN_LOCK_DECLARATION();
1728
1729     ASSERT(prAdapter);
1730
1731     KAL_ACQUIRE_SPIN_LOCK(prAdapter, SPIN_LOCK_CMD_SEQ_NUM);
1732
1733     prAdapter->ucCmdSeqNum++;
1734     ucRetval = prAdapter->ucCmdSeqNum;
1735
1736     KAL_RELEASE_SPIN_LOCK(prAdapter, SPIN_LOCK_CMD_SEQ_NUM);
1737
1738     return ucRetval;
1739 }
1740
1741
1742 /*----------------------------------------------------------------------------*/
1743 /*!
1744 * @brief This procedure is used to retrieve a TX sequence number atomically
1745 *
1746 * @param    prAdapter   Pointer of ADAPTER_T
1747 *
1748 * @retval - UINT_8
1749 */
1750 /*----------------------------------------------------------------------------*/
1751 UINT_8
1752 nicIncreaseTxSeqNum (
1753     IN P_ADAPTER_T prAdapter
1754     )
1755 {
1756     UINT_8 ucRetval;
1757
1758     KAL_SPIN_LOCK_DECLARATION();
1759
1760     ASSERT(prAdapter);
1761
1762     KAL_ACQUIRE_SPIN_LOCK(prAdapter, SPIN_LOCK_TX_SEQ_NUM);
1763
1764     prAdapter->ucTxSeqNum++;
1765     ucRetval = prAdapter->ucTxSeqNum;
1766
1767     KAL_RELEASE_SPIN_LOCK(prAdapter, SPIN_LOCK_TX_SEQ_NUM);
1768
1769     return ucRetval;
1770 }
1771
1772
1773
1774 /*----------------------------------------------------------------------------*/
1775 /*!
1776 * @brief This utility function is used to handle
1777 *        media state change event
1778 *
1779 * @param
1780 *
1781 * @retval
1782 */
1783 /*----------------------------------------------------------------------------*/
1784 WLAN_STATUS
1785 nicMediaStateChange (
1786     IN P_ADAPTER_T                  prAdapter,
1787     IN ENUM_NETWORK_TYPE_INDEX_T    eNetworkType,
1788     IN P_EVENT_CONNECTION_STATUS    prConnectionStatus
1789     )
1790 {
1791     P_GLUE_INFO_T prGlueInfo;
1792
1793     ASSERT(prAdapter);
1794     prGlueInfo = prAdapter->prGlueInfo;
1795
1796     switch(eNetworkType) {
1797     case NETWORK_TYPE_AIS_INDEX:
1798         if (prConnectionStatus->ucMediaStatus == PARAM_MEDIA_STATE_DISCONNECTED) { // disconnected
1799             if(kalGetMediaStateIndicated(prGlueInfo) != PARAM_MEDIA_STATE_DISCONNECTED) {
1800
1801                 kalIndicateStatusAndComplete(prGlueInfo,
1802                         WLAN_STATUS_MEDIA_DISCONNECT,
1803                         NULL,
1804                         0);
1805
1806                 prAdapter->rWlanInfo.u4SysTime = kalGetTimeTick();
1807             }
1808
1809             /* reset buffered link quality information */
1810             prAdapter->fgIsLinkQualityValid = FALSE;
1811             prAdapter->fgIsLinkRateValid = FALSE;
1812         }
1813         else if(prConnectionStatus->ucMediaStatus == PARAM_MEDIA_STATE_CONNECTED) { // connected
1814             prAdapter->rWlanInfo.u4SysTime = kalGetTimeTick();
1815
1816             // fill information for association result
1817             prAdapter->rWlanInfo.rCurrBssId.rSsid.u4SsidLen
1818                 = prConnectionStatus->ucSsidLen;
1819             kalMemCopy(prAdapter->rWlanInfo.rCurrBssId.rSsid.aucSsid,
1820                     prConnectionStatus->aucSsid,
1821                     prConnectionStatus->ucSsidLen);
1822             kalMemCopy(prAdapter->rWlanInfo.rCurrBssId.arMacAddress,
1823                     prConnectionStatus->aucBssid,
1824                     MAC_ADDR_LEN);
1825             prAdapter->rWlanInfo.rCurrBssId.u4Privacy
1826                 = prConnectionStatus->ucEncryptStatus; // @FIXME
1827             prAdapter->rWlanInfo.rCurrBssId.rRssi
1828                 = 0; //@FIXME
1829             prAdapter->rWlanInfo.rCurrBssId.eNetworkTypeInUse
1830                 = PARAM_NETWORK_TYPE_AUTOMODE; //@FIXME
1831             prAdapter->rWlanInfo.rCurrBssId.rConfiguration.u4BeaconPeriod
1832                 = prConnectionStatus->u2BeaconPeriod;
1833             prAdapter->rWlanInfo.rCurrBssId.rConfiguration.u4ATIMWindow
1834                 = prConnectionStatus->u2ATIMWindow;
1835             prAdapter->rWlanInfo.rCurrBssId.rConfiguration.u4DSConfig
1836                 = prConnectionStatus->u4FreqInKHz;
1837             prAdapter->rWlanInfo.ucNetworkType
1838                 = prConnectionStatus->ucNetworkType;
1839             prAdapter->rWlanInfo.rCurrBssId.eOpMode
1840                 = (ENUM_PARAM_OP_MODE_T) prConnectionStatus->ucInfraMode;
1841
1842             // always indicate to OS according to MSDN (re-association/roaming)
1843             kalIndicateStatusAndComplete(prGlueInfo,
1844                     WLAN_STATUS_MEDIA_CONNECT,
1845                     NULL,
1846                     0);
1847         }
1848         break;
1849
1850 #if CFG_ENABLE_BT_OVER_WIFI
1851     case NETWORK_TYPE_BOW_INDEX:
1852         break;
1853 #endif
1854
1855 #if CFG_ENABLE_WIFI_DIRECT
1856     case NETWORK_TYPE_P2P_INDEX:
1857         break;
1858 #endif
1859     default:
1860         ASSERT(0);
1861     }
1862
1863     return WLAN_STATUS_SUCCESS;
1864 } /* nicMediaStateChange */
1865
1866 /*----------------------------------------------------------------------------*/
1867 /*!
1868 * @brief This utility function is used to convert between
1869 *        frequency and channel number
1870 *
1871 * @param u4ChannelNum
1872 *
1873 * @retval - Frequency in unit of KHz, 0 for invalid channel number
1874 */
1875 /*----------------------------------------------------------------------------*/
1876 UINT_32
1877 nicChannelNum2Freq (
1878     UINT_32 u4ChannelNum
1879     )
1880 {
1881     UINT_32 u4ChannelInMHz;
1882
1883     if(u4ChannelNum >= 1 && u4ChannelNum <= 13) {
1884         u4ChannelInMHz = 2412 + (u4ChannelNum - 1) * 5;
1885     }
1886     else if(u4ChannelNum == 14) {
1887         u4ChannelInMHz = 2484;
1888     }
1889     else if(u4ChannelNum == 133) {
1890         u4ChannelInMHz = 3665; // 802.11y
1891     }
1892     else if(u4ChannelNum == 137) {
1893         u4ChannelInMHz = 3685; // 802.11y
1894     }
1895     else if(u4ChannelNum >= 34 && u4ChannelNum <= 165) {
1896         u4ChannelInMHz = 5000 + u4ChannelNum * 5;
1897     }
1898     else if(u4ChannelNum >= 183 && u4ChannelNum <= 196) {
1899         u4ChannelInMHz = 4000 + u4ChannelNum * 5;
1900     }
1901     else {
1902         u4ChannelInMHz = 0;
1903     }
1904
1905     return 1000 * u4ChannelInMHz;
1906 }
1907
1908
1909 /*----------------------------------------------------------------------------*/
1910 /*!
1911 * @brief This utility function is used to convert between
1912 *        frequency and channel number
1913 *
1914 * @param u4FreqInKHz
1915 *
1916 * @retval - Frequency Number, 0 for invalid freqency
1917 */
1918 /*----------------------------------------------------------------------------*/
1919 UINT_32
1920 nicFreq2ChannelNum (
1921     UINT_32 u4FreqInKHz
1922     )
1923 {
1924     switch(u4FreqInKHz) {
1925     case 2412000:
1926         return 1;
1927     case 2417000:
1928         return 2;
1929     case 2422000:
1930         return 3;
1931     case 2427000:
1932         return 4;
1933     case 2432000:
1934         return 5;
1935     case 2437000:
1936         return 6;
1937     case 2442000:
1938         return 7;
1939     case 2447000:
1940         return 8;
1941     case 2452000:
1942         return 9;
1943     case 2457000:
1944         return 10;
1945     case 2462000:
1946         return 11;
1947     case 2467000:
1948         return 12;
1949     case 2472000:
1950         return 13;
1951     case 2484000:
1952         return 14;
1953     case 3665000:
1954         return 133; // 802.11y
1955     case 3685000:
1956         return 137; // 802.11y
1957     case 4915000:
1958         return 183;
1959     case 4920000:
1960         return 184;
1961     case 4925000:
1962         return 185;
1963     case 4930000:
1964         return 186;
1965     case 4935000:
1966         return 187;
1967     case 4940000:
1968         return 188;
1969     case 4945000:
1970         return 189;
1971     case 4960000:
1972         return 192;
1973     case 4980000:
1974         return 196;
1975     case 5170000:
1976         return 34;
1977     case 5180000:
1978         return 36;
1979     case 5190000:
1980         return 38;
1981     case 5200000:
1982         return 40;
1983     case 5210000:
1984         return 42;
1985     case 5220000:
1986         return 44;
1987     case 5230000:
1988         return 46;
1989     case 5240000:
1990         return 48;
1991     case 5250000:
1992         return 50;
1993     case 5260000:
1994         return 52;
1995     case 5270000:
1996         return 54;
1997     case 5280000:
1998         return 56;
1999     case 5290000:
2000         return 58;
2001     case 5300000:
2002         return 60;
2003     case 5320000:
2004         return 64;
2005     case 5500000:
2006         return 100;
2007     case 5520000:
2008         return 104;
2009     case 5540000:
2010         return 108;
2011     case 5560000:
2012         return 112;
2013     case 5580000:
2014         return 116;
2015     case 5600000:
2016         return 120;
2017     case 5620000:
2018         return 124;
2019     case 5640000:
2020         return 128;
2021     case 5660000:
2022         return 132;
2023     case 5680000:
2024         return 136;
2025     case 5700000:
2026         return 140;
2027     case 5745000:
2028         return 149;
2029     case 5765000:
2030         return 153;
2031     case 5785000:
2032         return 157;
2033     case 5805000:
2034         return 161;
2035     case 5825000:
2036         return 165;
2037     default:
2038         return 0;
2039     }
2040 }
2041
2042
2043 /* firmware command wrapper */
2044 /* NETWORK (WIFISYS) */
2045 /*----------------------------------------------------------------------------*/
2046 /*!
2047 * @brief This utility function is used to activate WIFISYS for specified network
2048 *
2049 * @param prAdapter          Pointer of ADAPTER_T
2050 *        eNetworkTypeIdx    Index of network type
2051 *
2052 * @retval -
2053 */
2054 /*----------------------------------------------------------------------------*/
2055 WLAN_STATUS
2056 nicActivateNetwork(
2057     IN P_ADAPTER_T prAdapter,
2058     IN ENUM_NETWORK_TYPE_INDEX_T eNetworkTypeIdx
2059     )
2060 {
2061     CMD_BSS_ACTIVATE_CTRL   rCmdActivateCtrl;
2062     P_BSS_INFO_T            prBssInfo;
2063
2064     ASSERT(prAdapter);
2065     ASSERT(eNetworkTypeIdx < NETWORK_TYPE_INDEX_NUM);
2066
2067     rCmdActivateCtrl.ucNetTypeIndex     = (UINT_8)eNetworkTypeIdx;
2068     rCmdActivateCtrl.ucActive           = 1;
2069
2070     if (((UINT_8) eNetworkTypeIdx) < NETWORK_TYPE_INDEX_NUM) {
2071         prBssInfo = &prAdapter->rWifiVar.arBssInfo[eNetworkTypeIdx];
2072         prBssInfo->fg40mBwAllowed = FALSE;
2073         prBssInfo->fgAssoc40mBwAllowed = FALSE;
2074     }
2075
2076     return wlanSendSetQueryCmd(prAdapter,
2077             CMD_ID_BSS_ACTIVATE_CTRL,
2078             TRUE,
2079             FALSE,
2080             FALSE,
2081             NULL,
2082             NULL,
2083             sizeof(CMD_BSS_ACTIVATE_CTRL),
2084             (PUINT_8)&rCmdActivateCtrl,
2085             NULL,
2086             0);
2087 }
2088
2089
2090 /*----------------------------------------------------------------------------*/
2091 /*!
2092 * @brief This utility function is used to deactivate WIFISYS for specified network
2093 *
2094 * @param prAdapter          Pointer of ADAPTER_T
2095 *        eNetworkTypeIdx    Index of network type
2096 *
2097 * @retval -
2098 */
2099 /*----------------------------------------------------------------------------*/
2100 WLAN_STATUS
2101 nicDeactivateNetwork(
2102     IN P_ADAPTER_T prAdapter,
2103     IN ENUM_NETWORK_TYPE_INDEX_T eNetworkTypeIdx
2104     )
2105 {
2106     WLAN_STATUS u4Status;
2107     CMD_BSS_ACTIVATE_CTRL rCmdActivateCtrl;
2108
2109     ASSERT(prAdapter);
2110     ASSERT(eNetworkTypeIdx < NETWORK_TYPE_INDEX_NUM);
2111
2112     rCmdActivateCtrl.ucNetTypeIndex     = (UINT_8)eNetworkTypeIdx;
2113     rCmdActivateCtrl.ucActive           = 0;
2114
2115     u4Status = wlanSendSetQueryCmd(prAdapter,
2116             CMD_ID_BSS_ACTIVATE_CTRL,
2117             TRUE,
2118             FALSE,
2119             FALSE,
2120             NULL,
2121             NULL,
2122             sizeof(CMD_BSS_ACTIVATE_CTRL),
2123             (PUINT_8)&rCmdActivateCtrl,
2124             NULL,
2125             0);
2126
2127     /* free all correlated station records */
2128     cnmStaFreeAllStaByNetType(prAdapter, eNetworkTypeIdx, FALSE);
2129     qmFreeAllByNetType(prAdapter, eNetworkTypeIdx);
2130     nicFreePendingTxMsduInfoByNetwork(prAdapter, eNetworkTypeIdx);
2131     kalClearSecurityFramesByNetType(prAdapter->prGlueInfo, eNetworkTypeIdx);
2132
2133     return u4Status;
2134 }
2135
2136
2137 /* BSS-INFO */
2138 /*----------------------------------------------------------------------------*/
2139 /*!
2140 * @brief This utility function is used to sync bss info with firmware
2141 *        when a new BSS has been connected or disconnected
2142 *
2143 * @param prAdapter          Pointer of ADAPTER_T
2144 *        eNetworkTypeIdx    Index of BSS-INFO type
2145 *
2146 * @retval -
2147 */
2148 /*----------------------------------------------------------------------------*/
2149 WLAN_STATUS
2150 nicUpdateBss(
2151     IN P_ADAPTER_T prAdapter,
2152     IN ENUM_NETWORK_TYPE_INDEX_T eNetworkTypeIdx
2153     )
2154 {
2155     WLAN_STATUS u4Status;
2156     P_BSS_INFO_T prBssInfo;
2157     CMD_SET_BSS_INFO rCmdSetBssInfo;
2158
2159     ASSERT(prAdapter);
2160     ASSERT(eNetworkTypeIdx < NETWORK_TYPE_INDEX_NUM);
2161     DBGLOG(INIT, LOUD, ("nicUpdateBss\n"));
2162     prBssInfo = &(prAdapter->rWifiVar.arBssInfo[eNetworkTypeIdx]);
2163
2164     kalMemZero(&rCmdSetBssInfo, sizeof(CMD_SET_BSS_INFO));
2165
2166     rCmdSetBssInfo.ucNetTypeIndex               = (UINT_8)eNetworkTypeIdx;
2167     rCmdSetBssInfo.ucConnectionState            = (UINT_8)prBssInfo->eConnectionState;
2168     rCmdSetBssInfo.ucCurrentOPMode              = (UINT_8)prBssInfo->eCurrentOPMode;
2169     rCmdSetBssInfo.ucSSIDLen                    = (UINT_8)prBssInfo->ucSSIDLen;
2170     kalMemCopy(rCmdSetBssInfo.aucSSID, prBssInfo->aucSSID, prBssInfo->ucSSIDLen);
2171     COPY_MAC_ADDR(rCmdSetBssInfo.aucBSSID, prBssInfo->aucBSSID);
2172     rCmdSetBssInfo.ucIsQBSS                     = (UINT_8)prBssInfo->fgIsQBSS;
2173     rCmdSetBssInfo.ucNonHTBasicPhyType          = prBssInfo->ucNonHTBasicPhyType;
2174     rCmdSetBssInfo.u2OperationalRateSet         = prBssInfo->u2OperationalRateSet;
2175     rCmdSetBssInfo.u2BSSBasicRateSet            = prBssInfo->u2BSSBasicRateSet;
2176     rCmdSetBssInfo.ucPhyTypeSet                 = prBssInfo->ucPhyTypeSet;
2177 #if CFG_ENABLE_WIFI_DIRECT
2178     if(prAdapter->fgIsP2PRegistered) {
2179         COPY_MAC_ADDR(rCmdSetBssInfo.aucOwnMac, prBssInfo->aucOwnMacAddr);
2180     }
2181 #endif
2182
2183     rlmFillSyncCmdParam(&rCmdSetBssInfo.rBssRlmParam, prBssInfo);
2184
2185     rCmdSetBssInfo.fgWapiMode                   = (UINT_8)FALSE;
2186
2187     if(rCmdSetBssInfo.ucNetTypeIndex == NETWORK_TYPE_AIS_INDEX) {
2188         P_CONNECTION_SETTINGS_T prConnSettings = &(prAdapter->rWifiVar.rConnSettings);
2189
2190         rCmdSetBssInfo.ucAuthMode               = (UINT_8)prConnSettings->eAuthMode;
2191         rCmdSetBssInfo.ucEncStatus              = (UINT_8)prConnSettings->eEncStatus;
2192         rCmdSetBssInfo.fgWapiMode               = (UINT_8)prConnSettings->fgWapiMode;
2193     }
2194 #if CFG_ENABLE_BT_OVER_WIFI
2195     else if(rCmdSetBssInfo.ucNetTypeIndex == NETWORK_TYPE_BOW_INDEX) {
2196         //P_CONNECTION_SETTINGS_T prConnSettings = &(prAdapter->rWifiVar.rConnSettings);
2197         rCmdSetBssInfo.ucAuthMode               = (UINT_8)AUTH_MODE_WPA2_PSK;
2198         rCmdSetBssInfo.ucEncStatus              = (UINT_8)ENUM_ENCRYPTION3_KEY_ABSENT;
2199     }
2200 #endif
2201     else {
2202 #if CFG_ENABLE_WIFI_DIRECT
2203         if(prAdapter->fgIsP2PRegistered) {
2204             if (prAdapter->rP2pFuncLkr.prKalP2pGetCipher &&
2205                 prAdapter->rP2pFuncLkr.prKalP2pGetCipher(prAdapter->prGlueInfo)) {
2206                 rCmdSetBssInfo.ucAuthMode               = (UINT_8)AUTH_MODE_WPA2_PSK;
2207                 rCmdSetBssInfo.ucEncStatus              = (UINT_8)ENUM_ENCRYPTION3_KEY_ABSENT;
2208             }
2209             else {
2210                 rCmdSetBssInfo.ucAuthMode               = (UINT_8)AUTH_MODE_OPEN;
2211                 rCmdSetBssInfo.ucEncStatus              = (UINT_8)ENUM_ENCRYPTION_DISABLED;
2212             }
2213             rCmdSetBssInfo.fgIsApMode = prAdapter->rP2pFuncLkr.prP2pFuncIsApMode(prAdapter->rWifiVar.prP2pFsmInfo);
2214         }
2215 #else
2216         rCmdSetBssInfo.ucAuthMode               = (UINT_8)AUTH_MODE_WPA2_PSK;
2217         rCmdSetBssInfo.ucEncStatus              = (UINT_8)ENUM_ENCRYPTION3_KEY_ABSENT;
2218 #endif
2219     }
2220
2221     if(eNetworkTypeIdx == NETWORK_TYPE_AIS_INDEX &&
2222             prBssInfo->eCurrentOPMode == OP_MODE_INFRASTRUCTURE &&
2223             prBssInfo->prStaRecOfAP != NULL) {
2224         rCmdSetBssInfo.ucStaRecIdxOfAP          = prBssInfo->prStaRecOfAP->ucIndex;
2225
2226         cnmAisInfraConnectNotify(prAdapter);
2227     }
2228 #if CFG_ENABLE_WIFI_DIRECT
2229     else if ((prAdapter->fgIsP2PRegistered) &&
2230             (eNetworkTypeIdx == NETWORK_TYPE_P2P_INDEX) &&
2231             (prBssInfo->eCurrentOPMode == OP_MODE_INFRASTRUCTURE) &&
2232             (prBssInfo->prStaRecOfAP != NULL)) {
2233         rCmdSetBssInfo.ucStaRecIdxOfAP = prBssInfo->prStaRecOfAP->ucIndex;
2234     }
2235 #endif
2236
2237 #if CFG_ENABLE_BT_OVER_WIFI
2238     else if (eNetworkTypeIdx == NETWORK_TYPE_BOW_INDEX &&
2239             prBssInfo->eCurrentOPMode == OP_MODE_BOW &&
2240             prBssInfo->prStaRecOfAP != NULL) {
2241         rCmdSetBssInfo.ucStaRecIdxOfAP = prBssInfo->prStaRecOfAP->ucIndex;
2242     }
2243 #endif
2244     else {
2245         rCmdSetBssInfo.ucStaRecIdxOfAP              = 0;
2246     }
2247
2248     DBGLOG(REQ, TRACE, ("SET_BSS_INFO auth=%d, enc=%d\n", rCmdSetBssInfo.ucAuthMode, rCmdSetBssInfo.ucEncStatus));
2249
2250
2251     u4Status = wlanSendSetQueryCmd(prAdapter,
2252             CMD_ID_SET_BSS_INFO,
2253             TRUE,
2254             FALSE,
2255             FALSE,
2256             NULL,
2257             NULL,
2258             sizeof(CMD_SET_BSS_INFO),
2259             (PUINT_8)&rCmdSetBssInfo,
2260             NULL,
2261             0);
2262
2263     /* if BSS-INFO is going to be disconnected state, free all correlated station records */
2264     if(prBssInfo->eConnectionState == PARAM_MEDIA_STATE_DISCONNECTED) {
2265         /* clear client list */
2266         bssClearClientList(prAdapter, prBssInfo);
2267
2268         /* free all correlated station records */
2269         cnmStaFreeAllStaByNetType(prAdapter, eNetworkTypeIdx, FALSE);
2270         qmFreeAllByNetType(prAdapter, eNetworkTypeIdx);
2271         kalClearSecurityFramesByNetType(prAdapter->prGlueInfo, eNetworkTypeIdx);
2272         DBGLOG(INIT, LOUD, ("free all correlated station records\n"));
2273     }
2274
2275     return u4Status;
2276 }
2277
2278
2279 /* BSS-INFO Indication (PM) */
2280 /*----------------------------------------------------------------------------*/
2281 /*!
2282 * @brief This utility function is used to indicate PM that
2283 *        a BSS has been created. (for AdHoc / P2P-GO)
2284 *
2285 * @param prAdapter          Pointer of ADAPTER_T
2286 *        eNetworkTypeIdx    Index of BSS-INFO
2287 *
2288 * @retval -
2289 */
2290 /*----------------------------------------------------------------------------*/
2291 WLAN_STATUS
2292 nicPmIndicateBssCreated(
2293     IN P_ADAPTER_T prAdapter,
2294     IN ENUM_NETWORK_TYPE_INDEX_T eNetworkTypeIdx
2295     )
2296 {
2297     P_BSS_INFO_T prBssInfo;
2298     CMD_INDICATE_PM_BSS_CREATED rCmdIndicatePmBssCreated;
2299
2300     ASSERT(prAdapter);
2301     ASSERT(eNetworkTypeIdx < NETWORK_TYPE_INDEX_NUM);
2302
2303     prBssInfo = &(prAdapter->rWifiVar.arBssInfo[eNetworkTypeIdx]);
2304
2305     rCmdIndicatePmBssCreated.ucNetTypeIndex     = (UINT_8)eNetworkTypeIdx;
2306     rCmdIndicatePmBssCreated.ucDtimPeriod       = prBssInfo->ucDTIMPeriod;
2307     rCmdIndicatePmBssCreated.u2BeaconInterval   = prBssInfo->u2BeaconInterval;
2308     rCmdIndicatePmBssCreated.u2AtimWindow       = prBssInfo->u2ATIMWindow;
2309
2310     return wlanSendSetQueryCmd(prAdapter,
2311             CMD_ID_INDICATE_PM_BSS_CREATED,
2312             TRUE,
2313             FALSE,
2314             FALSE,
2315             NULL,
2316             NULL,
2317             sizeof(CMD_INDICATE_PM_BSS_CREATED),
2318             (PUINT_8)&rCmdIndicatePmBssCreated,
2319             NULL,
2320             0);
2321 }
2322
2323
2324 /*----------------------------------------------------------------------------*/
2325 /*!
2326 * @brief This utility function is used to indicate PM that
2327 *        a BSS has been connected
2328 *
2329 * @param prAdapter          Pointer of ADAPTER_T
2330 *        eNetworkTypeIdx    Index of BSS-INFO
2331 *
2332 * @retval -
2333 */
2334 /*----------------------------------------------------------------------------*/
2335 WLAN_STATUS
2336 nicPmIndicateBssConnected(
2337     IN P_ADAPTER_T prAdapter,
2338     IN ENUM_NETWORK_TYPE_INDEX_T eNetworkTypeIdx
2339     )
2340 {
2341     P_BSS_INFO_T prBssInfo;
2342     CMD_INDICATE_PM_BSS_CONNECTED rCmdIndicatePmBssConnected;
2343
2344     ASSERT(prAdapter);
2345     ASSERT(eNetworkTypeIdx < NETWORK_TYPE_INDEX_NUM);
2346
2347     prBssInfo = &(prAdapter->rWifiVar.arBssInfo[eNetworkTypeIdx]);
2348
2349     rCmdIndicatePmBssConnected.ucNetTypeIndex   = (UINT_8)eNetworkTypeIdx;
2350     rCmdIndicatePmBssConnected.ucDtimPeriod     = prBssInfo->ucDTIMPeriod;
2351     rCmdIndicatePmBssConnected.u2AssocId        = prBssInfo->u2AssocId;
2352     rCmdIndicatePmBssConnected.u2BeaconInterval = prBssInfo->u2BeaconInterval;
2353     rCmdIndicatePmBssConnected.u2AtimWindow     = prBssInfo->u2ATIMWindow;
2354
2355     rCmdIndicatePmBssConnected.ucBmpDeliveryAC  = prBssInfo->rPmProfSetupInfo.ucBmpDeliveryAC;
2356     rCmdIndicatePmBssConnected.ucBmpTriggerAC   = prBssInfo->rPmProfSetupInfo.ucBmpTriggerAC;
2357
2358     //DBGPRINTF("nicPmIndicateBssConnected: ucBmpDeliveryAC:0x%x, ucBmpTriggerAC:0x%x",
2359             //rCmdIndicatePmBssConnected.ucBmpDeliveryAC,
2360             //rCmdIndicatePmBssConnected.ucBmpTriggerAC);
2361
2362     if ((eNetworkTypeIdx == NETWORK_TYPE_AIS_INDEX)
2363 #if CFG_ENABLE_WIFI_DIRECT
2364         || ((eNetworkTypeIdx == NETWORK_TYPE_P2P_INDEX) && (prAdapter->fgIsP2PRegistered))
2365 #endif
2366          ) {
2367         if(prBssInfo->eCurrentOPMode == OP_MODE_INFRASTRUCTURE) {
2368             rCmdIndicatePmBssConnected.fgIsUapsdConnection  = (UINT_8)prBssInfo->prStaRecOfAP->fgIsUapsdSupported;
2369         }
2370         else {
2371             rCmdIndicatePmBssConnected.fgIsUapsdConnection  = 0; //@FIXME
2372         }
2373     }
2374     else {
2375         rCmdIndicatePmBssConnected.fgIsUapsdConnection  = 0;
2376     }
2377
2378     return wlanSendSetQueryCmd(prAdapter,
2379             CMD_ID_INDICATE_PM_BSS_CONNECTED,
2380             TRUE,
2381             FALSE,
2382             FALSE,
2383             NULL,
2384             NULL,
2385             sizeof(CMD_INDICATE_PM_BSS_CONNECTED),
2386             (PUINT_8)&rCmdIndicatePmBssConnected,
2387             NULL,
2388             0);
2389 }
2390
2391
2392 /*----------------------------------------------------------------------------*/
2393 /*!
2394 * @brief This utility function is used to indicate PM that
2395 *        a BSS has been disconnected
2396 *
2397 * @param prAdapter          Pointer of ADAPTER_T
2398 *        eNetworkTypeIdx    Index of BSS-INFO
2399 *
2400 * @retval -
2401 */
2402 /*----------------------------------------------------------------------------*/
2403 WLAN_STATUS
2404 nicPmIndicateBssAbort(
2405     IN P_ADAPTER_T prAdapter,
2406     IN ENUM_NETWORK_TYPE_INDEX_T eNetworkTypeIdx
2407     )
2408 {
2409     CMD_INDICATE_PM_BSS_ABORT rCmdIndicatePmBssAbort;
2410
2411     ASSERT(prAdapter);
2412     ASSERT(eNetworkTypeIdx < NETWORK_TYPE_INDEX_NUM);
2413
2414     rCmdIndicatePmBssAbort.ucNetTypeIndex       = (UINT_8)eNetworkTypeIdx;
2415
2416     return wlanSendSetQueryCmd(prAdapter,
2417             CMD_ID_INDICATE_PM_BSS_ABORT,
2418             TRUE,
2419             FALSE,
2420             FALSE,
2421             NULL,
2422             NULL,
2423             sizeof(CMD_INDICATE_PM_BSS_ABORT),
2424             (PUINT_8)&rCmdIndicatePmBssAbort,
2425             NULL,
2426             0);
2427 }
2428
2429 WLAN_STATUS
2430 nicConfigPowerSaveProfile (
2431     IN  P_ADAPTER_T prAdapter,
2432     ENUM_NETWORK_TYPE_INDEX_T eNetTypeIndex,
2433     PARAM_POWER_MODE ePwrMode,
2434     BOOLEAN fgEnCmdEvent
2435     )
2436 {
2437     DEBUGFUNC("nicConfigPowerSaveProfile");
2438     DBGLOG(INIT, TRACE, ("eNetTypeIndex:%d, ePwrMode:%d, fgEnCmdEvent:%d\n",
2439                     eNetTypeIndex, ePwrMode, fgEnCmdEvent));
2440
2441     ASSERT(prAdapter);
2442
2443         if (eNetTypeIndex >= NETWORK_TYPE_INDEX_NUM) {
2444                 ASSERT(0);
2445                 return WLAN_STATUS_NOT_SUPPORTED;
2446         }
2447
2448 //    prAdapter->rWlanInfo.ePowerSaveMode.ucNetTypeIndex = eNetTypeIndex;
2449 //    prAdapter->rWlanInfo.ePowerSaveMode.ucPsProfile = (UINT_8)ePwrMode;
2450     prAdapter->rWlanInfo.arPowerSaveMode[eNetTypeIndex].ucNetTypeIndex = eNetTypeIndex;
2451     prAdapter->rWlanInfo.arPowerSaveMode[eNetTypeIndex].ucPsProfile = (UINT_8)ePwrMode;
2452
2453     return wlanSendSetQueryCmd(prAdapter,
2454             CMD_ID_POWER_SAVE_MODE,
2455             TRUE,
2456             FALSE,
2457             TRUE,
2458             (fgEnCmdEvent ? nicCmdEventSetCommon : NULL),
2459             (fgEnCmdEvent ? nicOidCmdTimeoutCommon : NULL),
2460             sizeof(CMD_PS_PROFILE_T),
2461             (PUINT_8)&(prAdapter->rWlanInfo.arPowerSaveMode[eNetTypeIndex]),
2462             NULL,
2463             sizeof(PARAM_POWER_MODE)
2464             );
2465
2466 } /* end of wlanoidSetAcpiDevicePowerStateMode() */
2467
2468 /*----------------------------------------------------------------------------*/
2469 /*!
2470 * @brief This utility function is used to indicate firmware domain
2471 *        for beacon generation parameters
2472 *
2473 * @param prAdapter          Pointer of ADAPTER_T
2474 *        eIeUpdMethod,      Update Method
2475 *        eNetTypeIndex      Index of Network
2476 *        u2Capability       Capability
2477 *        aucIe              Pointer to buffer of IEs
2478 *        u2IELen            Length of IEs
2479 *
2480 * @retval - WLAN_STATUS_SUCCESS
2481 *           WLAN_STATUS_FAILURE
2482 *           WLAN_STATUS_PENDING
2483 *           WLAN_STATUS_INVALID_DATA
2484 */
2485 /*----------------------------------------------------------------------------*/
2486 WLAN_STATUS
2487 nicUpdateBeaconIETemplate (
2488     IN P_ADAPTER_T prAdapter,
2489     IN ENUM_IE_UPD_METHOD_T eIeUpdMethod,
2490     IN ENUM_NETWORK_TYPE_INDEX_T eNetTypeIndex,
2491     IN UINT_16 u2Capability,
2492     IN PUINT_8 aucIe,
2493     IN UINT_16 u2IELen
2494     )
2495 {
2496     P_CMD_BEACON_TEMPLATE_UPDATE prCmdBcnUpdate;
2497     UINT_16 u2CmdBufLen = 0;
2498     P_GLUE_INFO_T prGlueInfo;
2499     P_CMD_INFO_T prCmdInfo;
2500     P_WIFI_CMD_T prWifiCmd;
2501     UINT_8 ucCmdSeqNum;
2502
2503     DEBUGFUNC("wlanUpdateBeaconIETemplate");
2504     DBGLOG(INIT, LOUD, ("\n"));
2505
2506     ASSERT(prAdapter);
2507     prGlueInfo = prAdapter->prGlueInfo;
2508
2509     if (u2IELen > MAX_IE_LENGTH) {
2510         return WLAN_STATUS_INVALID_DATA;
2511     }
2512
2513     if (eIeUpdMethod == IE_UPD_METHOD_UPDATE_RANDOM
2514             || eIeUpdMethod == IE_UPD_METHOD_UPDATE_ALL) {
2515         u2CmdBufLen = OFFSET_OF(CMD_BEACON_TEMPLATE_UPDATE, aucIE) + u2IELen;
2516     }
2517     else if (eIeUpdMethod == IE_UPD_METHOD_DELETE_ALL) {
2518         u2CmdBufLen = OFFSET_OF(CMD_BEACON_TEMPLATE_UPDATE, u2IELen);
2519     }
2520     else {
2521         ASSERT(0);
2522         return WLAN_STATUS_FAILURE;
2523     }
2524
2525     // prepare command info
2526     prCmdInfo = cmdBufAllocateCmdInfo(prAdapter, (CMD_HDR_SIZE + u2CmdBufLen));
2527     if (!prCmdInfo) {
2528         DBGLOG(INIT, ERROR, ("Allocate CMD_INFO_T ==> FAILED.\n"));
2529         return WLAN_STATUS_FAILURE;
2530     }
2531
2532     // increase command sequence number
2533     ucCmdSeqNum = nicIncreaseCmdSeqNum(prAdapter);
2534     DBGLOG(REQ, TRACE, ("ucCmdSeqNum =%d\n", ucCmdSeqNum));
2535
2536     // Setup common CMD Info Packet
2537     prCmdInfo->eCmdType = COMMAND_TYPE_NETWORK_IOCTL;
2538     prCmdInfo->eNetworkType = eNetTypeIndex;
2539     prCmdInfo->u2InfoBufLen = (UINT_16)(CMD_HDR_SIZE + u2CmdBufLen);
2540     prCmdInfo->pfCmdDoneHandler = NULL;     //@FIXME
2541     prCmdInfo->pfCmdTimeoutHandler = NULL;  //@FIXME
2542     prCmdInfo->fgIsOid = FALSE;
2543     prCmdInfo->ucCID = CMD_ID_UPDATE_BEACON_CONTENT;
2544     prCmdInfo->fgSetQuery = TRUE;
2545     prCmdInfo->fgNeedResp = FALSE;
2546     prCmdInfo->fgDriverDomainMCR = FALSE;
2547     prCmdInfo->ucCmdSeqNum = ucCmdSeqNum;
2548     prCmdInfo->u4SetInfoLen = u2CmdBufLen;
2549     prCmdInfo->pvInformationBuffer = NULL;
2550     prCmdInfo->u4InformationBufferLength = 0;
2551
2552     // Setup WIFI_CMD_T (no payload)
2553     prWifiCmd = (P_WIFI_CMD_T)(prCmdInfo->pucInfoBuffer);
2554     prWifiCmd->u2TxByteCount_UserPriority = prCmdInfo->u2InfoBufLen;
2555     prWifiCmd->ucCID = prCmdInfo->ucCID;
2556     prWifiCmd->ucSetQuery = prCmdInfo->fgSetQuery;
2557     prWifiCmd->ucSeqNum = prCmdInfo->ucCmdSeqNum;
2558
2559     prCmdBcnUpdate = (P_CMD_BEACON_TEMPLATE_UPDATE)(prWifiCmd->aucBuffer);
2560
2561     // fill beacon updating command
2562     prCmdBcnUpdate->ucUpdateMethod  = (UINT_8) eIeUpdMethod;
2563     prCmdBcnUpdate->ucNetTypeIndex  = (UINT_8) eNetTypeIndex;
2564     prCmdBcnUpdate->u2Capability    = u2Capability;
2565     prCmdBcnUpdate->u2IELen         = u2IELen;
2566     if(u2IELen > 0 ) {
2567         kalMemCopy(prCmdBcnUpdate->aucIE, aucIe, u2IELen);
2568     }
2569
2570     // insert into prCmdQueue
2571     kalEnqueueCommand(prGlueInfo, (P_QUE_ENTRY_T)prCmdInfo);
2572
2573     // wakeup txServiceThread later
2574     GLUE_SET_EVENT(prGlueInfo);
2575     DBGLOG(INIT, LOUD, ("Command ID = 0x%08X\n", prCmdInfo->ucCID));
2576     return WLAN_STATUS_PENDING;
2577 }
2578
2579
2580 /*----------------------------------------------------------------------------*/
2581 /*!
2582 * @brief This utility function is used to initialization PHY related
2583 *        varaibles
2584 *
2585 * @param prAdapter  Pointer of ADAPTER_T
2586 *
2587 * @retval none
2588 */
2589 /*----------------------------------------------------------------------------*/
2590 VOID
2591 nicSetAvailablePhyTypeSet (
2592     IN P_ADAPTER_T prAdapter
2593     )
2594 {
2595     P_CONNECTION_SETTINGS_T prConnSettings;
2596
2597     ASSERT(prAdapter);
2598
2599     prConnSettings = &(prAdapter->rWifiVar.rConnSettings);
2600
2601     if (prConnSettings->eDesiredPhyConfig >= PHY_CONFIG_NUM) {
2602         ASSERT(0);
2603         return;
2604     }
2605
2606     prAdapter->rWifiVar.ucAvailablePhyTypeSet =
2607         aucPhyCfg2PhyTypeSet[prConnSettings->eDesiredPhyConfig];
2608
2609     if (prAdapter->rWifiVar.ucAvailablePhyTypeSet & PHY_TYPE_BIT_ERP) {
2610         prAdapter->rWifiVar.eNonHTBasicPhyType2G4 = PHY_TYPE_ERP_INDEX;
2611     }
2612     /* NOTE(Kevin): Because we don't have N only mode, TBD */
2613     else /* if (ucNonHTPhyTypeSet & PHY_TYPE_HR_DSSS_INDEX) */ {
2614         prAdapter->rWifiVar.eNonHTBasicPhyType2G4 = PHY_TYPE_HR_DSSS_INDEX;
2615     }
2616
2617     return;
2618 }
2619
2620
2621 /*----------------------------------------------------------------------------*/
2622 /*!
2623 * @brief This utility function is used to update WMM Parms
2624 *
2625 * @param prAdapter          Pointer of ADAPTER_T
2626 *        eNetworkTypeIdx    Index of BSS-INFO
2627 *
2628 * @retval -
2629 */
2630 /*----------------------------------------------------------------------------*/
2631 WLAN_STATUS
2632 nicQmUpdateWmmParms(
2633     IN P_ADAPTER_T prAdapter,
2634     IN ENUM_NETWORK_TYPE_INDEX_T eNetworkTypeIdx
2635     )
2636 {
2637     P_BSS_INFO_T prBssInfo;
2638     CMD_UPDATE_WMM_PARMS_T rCmdUpdateWmmParms;
2639
2640     ASSERT(prAdapter);
2641     ASSERT(eNetworkTypeIdx < NETWORK_TYPE_INDEX_NUM);
2642
2643     DBGLOG(QM, EVENT, ("sizeof(AC_QUE_PARMS_T): %d \n", sizeof(AC_QUE_PARMS_T)));
2644     DBGLOG(QM, EVENT, ("sizeof(CMD_UPDATE_WMM_PARMS): %d \n", sizeof(CMD_UPDATE_WMM_PARMS_T)));
2645     DBGLOG(QM, EVENT, ("sizeof(WIFI_CMD_T): %d \n", sizeof(WIFI_CMD_T)));
2646
2647     prBssInfo = &(prAdapter->rWifiVar.arBssInfo[eNetworkTypeIdx]);
2648     rCmdUpdateWmmParms.ucNetTypeIndex = (UINT_8)eNetworkTypeIdx;
2649     kalMemCopy(&rCmdUpdateWmmParms.arACQueParms[0], &prBssInfo->arACQueParms[0],
2650         (sizeof(AC_QUE_PARMS_T)*AC_NUM));
2651
2652     rCmdUpdateWmmParms.fgIsQBSS = prBssInfo->fgIsQBSS;
2653
2654     return wlanSendSetQueryCmd(prAdapter,
2655             CMD_ID_UPDATE_WMM_PARMS,
2656             TRUE,
2657             FALSE,
2658             FALSE,
2659             NULL,
2660             NULL,
2661             sizeof(CMD_UPDATE_WMM_PARMS_T),
2662             (PUINT_8)&rCmdUpdateWmmParms,
2663             NULL,
2664             0);
2665 }
2666
2667
2668 /*----------------------------------------------------------------------------*/
2669 /*!
2670 * @brief This utility function is used to update TX power gain corresponding to
2671 *        each band/modulation combination
2672 *
2673 * @param prAdapter          Pointer of ADAPTER_T
2674 *        prTxPwrParam       Pointer of TX power parameters
2675 *
2676 * @retval WLAN_STATUS_PENDING
2677 *         WLAN_STATUS_FAILURE
2678 */
2679 /*----------------------------------------------------------------------------*/
2680 WLAN_STATUS
2681 nicUpdateTxPower(
2682     IN P_ADAPTER_T      prAdapter,
2683     IN P_CMD_TX_PWR_T   prTxPwrParam
2684     )
2685 {
2686     DEBUGFUNC("nicUpdateTxPower");
2687
2688     ASSERT(prAdapter);
2689
2690     return wlanSendSetQueryCmd(prAdapter,
2691             CMD_ID_SET_TX_PWR,
2692             TRUE,
2693             FALSE,
2694             FALSE,
2695             NULL,
2696             NULL,
2697             sizeof(CMD_TX_PWR_T),
2698             (PUINT_8)prTxPwrParam,
2699             NULL,
2700             0);
2701 }
2702
2703
2704 /*----------------------------------------------------------------------------*/
2705 /*!
2706 * @brief This utility function is used to update power offset around 5GHz band
2707 *
2708 * @param prAdapter          Pointer of ADAPTER_T
2709 *        pr5GPwrOffset      Pointer of 5GHz power offset parameter
2710 *
2711 * @retval WLAN_STATUS_PENDING
2712 *         WLAN_STATUS_FAILURE
2713 */
2714 /*----------------------------------------------------------------------------*/
2715 WLAN_STATUS
2716 nicUpdate5GOffset(
2717     IN P_ADAPTER_T              prAdapter,
2718     IN P_CMD_5G_PWR_OFFSET_T    pr5GPwrOffset
2719     )
2720 {
2721     DEBUGFUNC("nicUpdate5GOffset");
2722
2723     ASSERT(prAdapter);
2724
2725     return wlanSendSetQueryCmd(prAdapter,
2726             CMD_ID_SET_5G_PWR_OFFSET,
2727             TRUE,
2728             FALSE,
2729             FALSE,
2730             NULL,
2731             NULL,
2732             sizeof(CMD_5G_PWR_OFFSET_T),
2733             (PUINT_8)pr5GPwrOffset,
2734             NULL,
2735             0);
2736 }
2737
2738
2739 /*----------------------------------------------------------------------------*/
2740 /*!
2741 * @brief This utility function is used to update DPD calibration result
2742 *
2743 * @param prAdapter          Pointer of ADAPTER_T
2744 *        pr5GPwrOffset      Pointer of parameter for DPD calibration result
2745 *
2746 * @retval WLAN_STATUS_PENDING
2747 *         WLAN_STATUS_FAILURE
2748 */
2749 /*----------------------------------------------------------------------------*/
2750 WLAN_STATUS
2751 nicUpdateDPD(
2752     IN P_ADAPTER_T          prAdapter,
2753     IN P_CMD_PWR_PARAM_T    prDpdCalResult
2754     )
2755 {
2756     DEBUGFUNC("nicUpdateDPD");
2757
2758     ASSERT(prAdapter);
2759
2760     return wlanSendSetQueryCmd(prAdapter,
2761             CMD_ID_SET_PWR_PARAM,
2762             TRUE,
2763             FALSE,
2764             FALSE,
2765             NULL,
2766             NULL,
2767             sizeof(CMD_PWR_PARAM_T),
2768             (PUINT_8)prDpdCalResult,
2769             NULL,
2770             0);
2771 }
2772
2773
2774 /*----------------------------------------------------------------------------*/
2775 /*!
2776 * @brief This utility function starts system service such as timer and
2777 *        memory pools
2778 *
2779 * @param prAdapter          Pointer of ADAPTER_T
2780 *
2781 * @retval none
2782 */
2783 /*----------------------------------------------------------------------------*/
2784 VOID
2785 nicInitSystemService (
2786     IN P_ADAPTER_T prAdapter
2787     )
2788 {
2789     ASSERT(prAdapter);
2790
2791     // <1> Initialize MGMT Memory pool and STA_REC
2792     cnmMemInit(prAdapter);
2793     cnmStaRecInit(prAdapter);
2794     cmdBufInitialize(prAdapter);
2795
2796     // <2> Mailbox Initialization
2797     mboxInitialize(prAdapter);
2798
2799     // <3> Timer Initialization
2800     cnmTimerInitialize(prAdapter);
2801
2802     return;
2803 }
2804
2805
2806 /*----------------------------------------------------------------------------*/
2807 /*!
2808 * @brief This utility function reset some specific system service,
2809 *        such as STA-REC
2810 *
2811 * @param prAdapter          Pointer of ADAPTER_T
2812 *
2813 * @retval none
2814 */
2815 /*----------------------------------------------------------------------------*/
2816 VOID
2817 nicResetSystemService (
2818     IN P_ADAPTER_T prAdapter
2819     )
2820 {
2821     ASSERT(prAdapter);
2822 }
2823
2824
2825 /*----------------------------------------------------------------------------*/
2826 /*!
2827 * @brief This utility function is used to update WMM Parms
2828 *
2829 * @param prAdapter          Pointer of ADAPTER_T
2830 *
2831 * @retval none
2832 */
2833 /*----------------------------------------------------------------------------*/
2834 VOID
2835 nicUninitSystemService (
2836     IN P_ADAPTER_T prAdapter
2837     )
2838 {
2839     ASSERT(prAdapter);
2840
2841     /* Timer Destruction */
2842     cnmTimerDestroy(prAdapter);
2843
2844     /* Mailbox Destruction */
2845     mboxDestroy(prAdapter);
2846
2847     return;
2848 }
2849
2850
2851 /*----------------------------------------------------------------------------*/
2852 /*!
2853 * @brief This utility function is used to update WMM Parms
2854 *
2855 * @param prAdapter          Pointer of ADAPTER_T
2856 *
2857 * @retval none
2858 */
2859 /*----------------------------------------------------------------------------*/
2860 VOID
2861 nicInitMGMT (
2862     IN P_ADAPTER_T prAdapter,
2863     IN P_REG_INFO_T prRegInfo
2864     )
2865 {
2866     ASSERT(prAdapter);
2867
2868     /* CNM Module - initialization */
2869     cnmInit(prAdapter);
2870
2871     /* RLM Module - initialization */
2872     rlmFsmEventInit(prAdapter);
2873
2874     /* SCN Module - initialization */
2875     scnInit(prAdapter);
2876
2877     /* AIS Module - intiailization */
2878     aisInitializeConnectionSettings(prAdapter, prRegInfo);
2879     aisFsmInit(prAdapter);
2880
2881 #if CFG_SUPPORT_ROAMING
2882     /* Roaming Module - intiailization */
2883     roamingFsmInit(prAdapter);
2884 #endif /* CFG_SUPPORT_ROAMING */
2885
2886 #if CFG_SUPPORT_SWCR
2887     swCrDebugInit(prAdapter);
2888 #endif /* CFG_SUPPORT_SWCR */
2889
2890     return;
2891 }
2892
2893
2894 /*----------------------------------------------------------------------------*/
2895 /*!
2896 * @brief This utility function is used to update WMM Parms
2897 *
2898 * @param prAdapter          Pointer of ADAPTER_T
2899 *
2900 * @retval none
2901 */
2902 /*----------------------------------------------------------------------------*/
2903 VOID
2904 nicUninitMGMT (
2905     IN P_ADAPTER_T prAdapter
2906     )
2907 {
2908     ASSERT(prAdapter);
2909
2910 #if CFG_SUPPORT_SWCR
2911     swCrDebugUninit(prAdapter);
2912 #endif /* CFG_SUPPORT_SWCR */
2913
2914 #if CFG_SUPPORT_ROAMING
2915     /* Roaming Module - unintiailization */
2916     roamingFsmUninit(prAdapter);
2917 #endif /* CFG_SUPPORT_ROAMING */
2918
2919     /* AIS Module - unintiailization */
2920     aisFsmUninit(prAdapter);
2921
2922     /* SCN Module - unintiailization */
2923     scnUninit(prAdapter);
2924
2925     /* RLM Module - uninitialization */
2926     rlmFsmEventUninit(prAdapter);
2927
2928     /* CNM Module - uninitialization */
2929     cnmUninit(prAdapter);
2930
2931     return;
2932 }
2933
2934
2935 #if (MT6620_E1_ASIC_HIFSYS_WORKAROUND == 1)
2936 /*----------------------------------------------------------------------------*/
2937 /*!
2938 * @brief This utility function is to inform firmware to enable MCU clock gating
2939 *
2940 * @param prAdapter          Pointer of ADAPTER_T
2941 *
2942 * @retval none
2943 */
2944 /*----------------------------------------------------------------------------*/
2945 WLAN_STATUS
2946 nicEnableClockGating (
2947     IN P_ADAPTER_T prAdapter
2948     )
2949 {
2950     UINT_32 i, u4WHISR = 0;
2951
2952     ASSERT(prAdapter);
2953
2954     if(prAdapter->fgIsClockGatingEnabled == TRUE) {
2955         return WLAN_STATUS_SUCCESS;
2956     }
2957     else {
2958         nicSetSwIntr(prAdapter, REQ_GATING_ENABLE_H2D_INT);
2959
2960         i = 0;
2961         while(i < GATING_CONTROL_POLL_LIMIT) {
2962             if(kalIsCardRemoved(prAdapter->prGlueInfo) == TRUE
2963                     || fgIsBusAccessFailed == TRUE) {
2964                 return WLAN_STATUS_FAILURE;
2965             }
2966
2967             HAL_READ_INTR_STATUS(prAdapter, sizeof(UINT_32), (PUINT_8)&u4WHISR);
2968
2969             if(u4WHISR & ACK_GATING_ENABLE_D2H_INT) {
2970                 prAdapter->fgIsClockGatingEnabled = TRUE;
2971                 return WLAN_STATUS_SUCCESS;
2972             }
2973         }
2974
2975         ASSERT(0);
2976         return WLAN_STATUS_PENDING;
2977     }
2978 }
2979
2980
2981 /*----------------------------------------------------------------------------*/
2982 /*!
2983 * @brief This utility function is to inform firmware to disable MCU clock gating
2984 *
2985 * @param prAdapter          Pointer of ADAPTER_T
2986 *
2987 * @retval none
2988 */
2989 /*----------------------------------------------------------------------------*/
2990 WLAN_STATUS
2991 nicDisableClockGating (
2992     IN P_ADAPTER_T prAdapter
2993     )
2994 {
2995     UINT_32 i, u4WHISR = 0;
2996
2997     ASSERT(prAdapter);
2998
2999     if(prAdapter->fgIsClockGatingEnabled == FALSE) {
3000         return WLAN_STATUS_SUCCESS;
3001     }
3002     else {
3003         nicSetSwIntr(prAdapter, REQ_GATING_DISABLE_H2D_INT);
3004
3005         i = 0;
3006         while(i < GATING_CONTROL_POLL_LIMIT) {
3007             if(kalIsCardRemoved(prAdapter->prGlueInfo) == TRUE
3008                     || fgIsBusAccessFailed == TRUE) {
3009                 return WLAN_STATUS_FAILURE;
3010             }
3011
3012             HAL_READ_INTR_STATUS(prAdapter, sizeof(UINT_32), (PUINT_8)&u4WHISR);
3013
3014             if(u4WHISR & ACK_GATING_DISABLE_D2H_INT) {
3015                 prAdapter->fgIsClockGatingEnabled = FALSE;
3016                 return WLAN_STATUS_SUCCESS;
3017             }
3018         }
3019
3020         ASSERT(0);
3021         return WLAN_STATUS_PENDING;
3022     }
3023 }
3024 #endif
3025
3026
3027 /*----------------------------------------------------------------------------*/
3028 /*!
3029 * @brief This function is invoked to buffer scan result
3030 *
3031 * @param prAdapter          Pointer to the Adapter structure.
3032 * @param rMacAddr           BSSID
3033 * @param prSsid             Pointer to SSID
3034 * @param u4Privacy          Privacy settings (0: Open / 1: WEP/WPA/WPA2 enabled)
3035 * @param rRssi              Received Strength (-10 ~ -200 dBm)
3036 * @param eNetworkType       Network Type (a/b/g)
3037 * @param prConfiguration    Network Parameter
3038 * @param eOpMode            Infra/Ad-Hoc
3039 * @param rSupportedRates    Supported basic rates
3040 * @param u2IELength         IE Length
3041 * @param pucIEBuf           Pointer to Information Elements(IEs)
3042 *
3043 * @return (none)
3044 */
3045 /*----------------------------------------------------------------------------*/
3046 VOID
3047 nicAddScanResult (
3048     IN P_ADAPTER_T                  prAdapter,
3049     IN PARAM_MAC_ADDRESS            rMacAddr,
3050     IN P_PARAM_SSID_T               prSsid,
3051     IN UINT_32                      u4Privacy,
3052     IN PARAM_RSSI                   rRssi,
3053     IN ENUM_PARAM_NETWORK_TYPE_T    eNetworkType,
3054     IN P_PARAM_802_11_CONFIG_T      prConfiguration,
3055     IN ENUM_PARAM_OP_MODE_T         eOpMode,
3056     IN PARAM_RATES_EX               rSupportedRates,
3057     IN UINT_16                      u2IELength,
3058     IN PUINT_8                      pucIEBuf
3059     )
3060 {
3061     BOOLEAN bReplace;
3062     UINT_32 i;
3063     UINT_32 u4IdxWeakest = 0;
3064     PARAM_RSSI rWeakestRssi;
3065     UINT_32 u4BufferSize;
3066
3067     ASSERT(prAdapter);
3068
3069     rWeakestRssi = (PARAM_RSSI)INT_MAX;
3070     u4BufferSize = sizeof(prAdapter->rWlanInfo.aucScanIEBuf) / sizeof(prAdapter->rWlanInfo.aucScanIEBuf[0]);
3071
3072     bReplace = FALSE;
3073
3074     // decide to replace or add
3075     for(i = 0 ; i < prAdapter->rWlanInfo.u4ScanResultNum ; i++) {
3076         // find weakest entry && not connected one
3077         if(UNEQUAL_MAC_ADDR(prAdapter->rWlanInfo.arScanResult[i].arMacAddress, prAdapter->rWlanInfo.rCurrBssId.arMacAddress)
3078                 && prAdapter->rWlanInfo.arScanResult[i].rRssi < rWeakestRssi) {
3079             u4IdxWeakest = i;
3080             rWeakestRssi = prAdapter->rWlanInfo.arScanResult[i].rRssi;
3081         }
3082
3083         if(prAdapter->rWlanInfo.arScanResult[i].eOpMode == eOpMode &&
3084                 EQUAL_MAC_ADDR(&(prAdapter->rWlanInfo.arScanResult[i].arMacAddress), rMacAddr) &&
3085                     (EQUAL_SSID(prAdapter->rWlanInfo.arScanResult[i].rSsid.aucSsid,
3086                             prAdapter->rWlanInfo.arScanResult[i].rSsid.u4SsidLen,
3087                             prSsid->aucSsid,
3088                             prSsid->u4SsidLen)
3089                      || prAdapter->rWlanInfo.arScanResult[i].rSsid.u4SsidLen == 0)) {
3090             // replace entry
3091             bReplace = TRUE;
3092
3093             // free IE buffer then zero
3094             nicFreeScanResultIE(prAdapter, i);
3095             kalMemZero(&(prAdapter->rWlanInfo.arScanResult[i]), OFFSET_OF(PARAM_BSSID_EX_T, aucIEs));
3096
3097             // then fill buffer
3098             prAdapter->rWlanInfo.arScanResult[i].u4Length =
3099                 OFFSET_OF(PARAM_BSSID_EX_T, aucIEs) + u2IELength;
3100             COPY_MAC_ADDR(prAdapter->rWlanInfo.arScanResult[i].arMacAddress, rMacAddr);
3101             COPY_SSID(prAdapter->rWlanInfo.arScanResult[i].rSsid.aucSsid,
3102                     prAdapter->rWlanInfo.arScanResult[i].rSsid.u4SsidLen,
3103                     prSsid->aucSsid,
3104                     prSsid->u4SsidLen);
3105             prAdapter->rWlanInfo.arScanResult[i].u4Privacy = u4Privacy;
3106             prAdapter->rWlanInfo.arScanResult[i].rRssi = rRssi;
3107             prAdapter->rWlanInfo.arScanResult[i].eNetworkTypeInUse = eNetworkType;
3108             kalMemCopy(&(prAdapter->rWlanInfo.arScanResult[i].rConfiguration),
3109                     prConfiguration,
3110                     sizeof(PARAM_802_11_CONFIG_T));
3111             prAdapter->rWlanInfo.arScanResult[i].eOpMode = eOpMode;
3112             kalMemCopy((prAdapter->rWlanInfo.arScanResult[i].rSupportedRates),
3113                     rSupportedRates,
3114                     sizeof(PARAM_RATES_EX));
3115             prAdapter->rWlanInfo.arScanResult[i].u4IELength = (UINT_32)u2IELength;
3116
3117             // IE - allocate buffer and update pointer
3118             if(u2IELength > 0) {
3119                 if(ALIGN_4(u2IELength) + prAdapter->rWlanInfo.u4ScanIEBufferUsage <= u4BufferSize) {
3120                     kalMemCopy(&(prAdapter->rWlanInfo.aucScanIEBuf[prAdapter->rWlanInfo.u4ScanIEBufferUsage]),
3121                             pucIEBuf,
3122                             u2IELength);
3123
3124                     prAdapter->rWlanInfo.apucScanResultIEs[i] =
3125                         &(prAdapter->rWlanInfo.aucScanIEBuf[prAdapter->rWlanInfo.u4ScanIEBufferUsage]);
3126
3127                     prAdapter->rWlanInfo.u4ScanIEBufferUsage += ALIGN_4(u2IELength);
3128                 }
3129                 else {
3130                     // buffer is not enough
3131                     prAdapter->rWlanInfo.arScanResult[i].u4Length -= u2IELength;
3132                     prAdapter->rWlanInfo.arScanResult[i].u4IELength = 0;
3133                     prAdapter->rWlanInfo.apucScanResultIEs[i] = NULL;
3134                 }
3135             }
3136             else {
3137                 prAdapter->rWlanInfo.apucScanResultIEs[i] = NULL;
3138             }
3139
3140             break;
3141         }
3142     }
3143
3144     if (bReplace == FALSE) {
3145         if (prAdapter->rWlanInfo.u4ScanResultNum < (CFG_MAX_NUM_BSS_LIST - 1)) {
3146             i = prAdapter->rWlanInfo.u4ScanResultNum;
3147
3148             // zero
3149             kalMemZero(&(prAdapter->rWlanInfo.arScanResult[i]),
3150                     OFFSET_OF(PARAM_BSSID_EX_T, aucIEs));
3151
3152             // then fill buffer
3153             prAdapter->rWlanInfo.arScanResult[i].u4Length =
3154                 OFFSET_OF(PARAM_BSSID_EX_T, aucIEs) + u2IELength;
3155             COPY_MAC_ADDR(prAdapter->rWlanInfo.arScanResult[i].arMacAddress, rMacAddr);
3156             COPY_SSID(prAdapter->rWlanInfo.arScanResult[i].rSsid.aucSsid,
3157                     prAdapter->rWlanInfo.arScanResult[i].rSsid.u4SsidLen,
3158                     prSsid->aucSsid,
3159                     prSsid->u4SsidLen);
3160             prAdapter->rWlanInfo.arScanResult[i].u4Privacy = u4Privacy;
3161             prAdapter->rWlanInfo.arScanResult[i].rRssi = rRssi;
3162             prAdapter->rWlanInfo.arScanResult[i].eNetworkTypeInUse = eNetworkType;
3163             kalMemCopy(&(prAdapter->rWlanInfo.arScanResult[i].rConfiguration),
3164                     prConfiguration,
3165                     sizeof(PARAM_802_11_CONFIG_T));
3166             prAdapter->rWlanInfo.arScanResult[i].eOpMode = eOpMode;
3167             kalMemCopy((prAdapter->rWlanInfo.arScanResult[i].rSupportedRates),
3168                     rSupportedRates,
3169                     sizeof(PARAM_RATES_EX));
3170             prAdapter->rWlanInfo.arScanResult[i].u4IELength = (UINT_32)u2IELength;
3171
3172             // IE - allocate buffer and update pointer
3173             if(u2IELength > 0) {
3174                 if(ALIGN_4(u2IELength) + prAdapter->rWlanInfo.u4ScanIEBufferUsage <= u4BufferSize) {
3175                     kalMemCopy(&(prAdapter->rWlanInfo.aucScanIEBuf[prAdapter->rWlanInfo.u4ScanIEBufferUsage]),
3176                             pucIEBuf,
3177                             u2IELength);
3178
3179                     prAdapter->rWlanInfo.apucScanResultIEs[i] =
3180                         &(prAdapter->rWlanInfo.aucScanIEBuf[prAdapter->rWlanInfo.u4ScanIEBufferUsage]);
3181
3182                     prAdapter->rWlanInfo.u4ScanIEBufferUsage += ALIGN_4(u2IELength);
3183                 }
3184                 else {
3185                     // buffer is not enough
3186                     prAdapter->rWlanInfo.arScanResult[i].u4Length -= u2IELength;
3187                     prAdapter->rWlanInfo.arScanResult[i].u4IELength = 0;
3188                     prAdapter->rWlanInfo.apucScanResultIEs[i] = NULL;
3189                 }
3190             }
3191             else {
3192                 prAdapter->rWlanInfo.apucScanResultIEs[i] = NULL;
3193             }
3194
3195             prAdapter->rWlanInfo.u4ScanResultNum++;
3196         }
3197         else if(rWeakestRssi != (PARAM_RSSI)INT_MAX) {
3198             // replace weakest one
3199             i = u4IdxWeakest;
3200
3201             // free IE buffer then zero
3202             nicFreeScanResultIE(prAdapter, i);
3203             kalMemZero(&(prAdapter->rWlanInfo.arScanResult[i]),
3204                     OFFSET_OF(PARAM_BSSID_EX_T, aucIEs));
3205
3206             // then fill buffer
3207             prAdapter->rWlanInfo.arScanResult[i].u4Length =
3208                 OFFSET_OF(PARAM_BSSID_EX_T, aucIEs) + u2IELength;
3209             COPY_MAC_ADDR(prAdapter->rWlanInfo.arScanResult[i].arMacAddress, rMacAddr);
3210             COPY_SSID(prAdapter->rWlanInfo.arScanResult[i].rSsid.aucSsid,
3211                     prAdapter->rWlanInfo.arScanResult[i].rSsid.u4SsidLen,
3212                     prSsid->aucSsid,
3213                     prSsid->u4SsidLen);
3214             prAdapter->rWlanInfo.arScanResult[i].u4Privacy = u4Privacy;
3215             prAdapter->rWlanInfo.arScanResult[i].rRssi = rRssi;
3216             prAdapter->rWlanInfo.arScanResult[i].eNetworkTypeInUse = eNetworkType;
3217             kalMemCopy(&(prAdapter->rWlanInfo.arScanResult[i].rConfiguration),
3218                     prConfiguration,
3219                     sizeof(PARAM_802_11_CONFIG_T));
3220             prAdapter->rWlanInfo.arScanResult[i].eOpMode = eOpMode;
3221             kalMemCopy((prAdapter->rWlanInfo.arScanResult[i].rSupportedRates),
3222                     rSupportedRates,
3223                     sizeof(PARAM_RATES_EX));
3224             prAdapter->rWlanInfo.arScanResult[i].u4IELength = (UINT_32)u2IELength;
3225
3226             if(u2IELength > 0) {
3227                 // IE - allocate buffer and update pointer
3228                 if(ALIGN_4(u2IELength) + prAdapter->rWlanInfo.u4ScanIEBufferUsage <= u4BufferSize) {
3229                     kalMemCopy(&(prAdapter->rWlanInfo.aucScanIEBuf[prAdapter->rWlanInfo.u4ScanIEBufferUsage]),
3230                             pucIEBuf,
3231                             u2IELength);
3232
3233                     prAdapter->rWlanInfo.apucScanResultIEs[i] =
3234                         &(prAdapter->rWlanInfo.aucScanIEBuf[prAdapter->rWlanInfo.u4ScanIEBufferUsage]);
3235
3236                     prAdapter->rWlanInfo.u4ScanIEBufferUsage += ALIGN_4(u2IELength);
3237                 }
3238                 else {
3239                     // buffer is not enough
3240                     prAdapter->rWlanInfo.arScanResult[i].u4Length -= u2IELength;
3241                     prAdapter->rWlanInfo.arScanResult[i].u4IELength = 0;
3242                     prAdapter->rWlanInfo.apucScanResultIEs[i] = NULL;
3243                 }
3244             }
3245             else {
3246                 prAdapter->rWlanInfo.apucScanResultIEs[i] = NULL;
3247             }
3248         }
3249     }
3250 }
3251
3252
3253 /*----------------------------------------------------------------------------*/
3254 /*!
3255 * @brief This function is invoked to free IE buffer for dedicated scan result
3256 *
3257 * @param prAdapter          Pointer to the Adapter structure.
3258 * @param u4Idx              Index of Scan Result
3259 *
3260 * @return (none)
3261 */
3262 /*----------------------------------------------------------------------------*/
3263 VOID
3264 nicFreeScanResultIE (
3265     IN P_ADAPTER_T  prAdapter,
3266     IN UINT_32      u4Idx
3267     )
3268 {
3269     UINT_32 i;
3270     PUINT_8 pucPivot, pucMovePivot;
3271     UINT_32 u4MoveSize, u4FreeSize, u4ReserveSize;
3272
3273     ASSERT(prAdapter);
3274     ASSERT(u4Idx < CFG_MAX_NUM_BSS_LIST);
3275
3276     if(prAdapter->rWlanInfo.arScanResult[u4Idx].u4IELength == 0
3277             || prAdapter->rWlanInfo.apucScanResultIEs[u4Idx] == NULL) {
3278         return;
3279     }
3280
3281     u4FreeSize = ALIGN_4(prAdapter->rWlanInfo.arScanResult[u4Idx].u4IELength);
3282
3283     pucPivot = prAdapter->rWlanInfo.apucScanResultIEs[u4Idx];
3284     pucMovePivot = (PUINT_8)((UINT_32)(prAdapter->rWlanInfo.apucScanResultIEs[u4Idx]) + u4FreeSize);
3285
3286     u4ReserveSize = ((UINT_32)pucPivot) - (UINT_32)(&(prAdapter->rWlanInfo.aucScanIEBuf[0]));
3287     u4MoveSize = prAdapter->rWlanInfo.u4ScanIEBufferUsage - u4ReserveSize - u4FreeSize;
3288
3289     // 1. rest of buffer to move forward
3290     kalMemCopy(pucPivot, pucMovePivot, u4MoveSize);
3291
3292     // 1.1 modify pointers
3293     for(i = 0 ; i < prAdapter->rWlanInfo.u4ScanResultNum ; i++) {
3294         if(i != u4Idx) {
3295             if(prAdapter->rWlanInfo.apucScanResultIEs[i] >= pucMovePivot) {
3296                 prAdapter->rWlanInfo.apucScanResultIEs[i] =
3297                     (PUINT_8)((UINT_32)(prAdapter->rWlanInfo.apucScanResultIEs[i]) - u4FreeSize);
3298             }
3299         }
3300     }
3301
3302     // 1.2 reset the freed one
3303     prAdapter->rWlanInfo.arScanResult[u4Idx].u4IELength = 0;
3304     prAdapter->rWlanInfo.apucScanResultIEs[i] = NULL;
3305
3306     // 2. reduce IE buffer usage
3307     prAdapter->rWlanInfo.u4ScanIEBufferUsage -= u4FreeSize;
3308
3309     return;
3310 }
3311
3312
3313 /*----------------------------------------------------------------------------*/
3314 /*!
3315 * @brief This function is to hack parameters for WLAN TABLE for
3316 *        fixed rate settings
3317 *
3318 * @param prAdapter          Pointer to the Adapter structure.
3319 * @param eRateSetting
3320 * @param pu2DesiredNonHTRateSet,
3321 * @param pu2BSSBasicRateSet,
3322 * @param pucMcsSet
3323 * @param pucSupMcs32
3324 * @param pu2HtCapInfo
3325 *
3326 * @return WLAN_STATUS_SUCCESS
3327 */
3328 /*----------------------------------------------------------------------------*/
3329 WLAN_STATUS
3330 nicUpdateRateParams (
3331     IN P_ADAPTER_T                  prAdapter,
3332     IN ENUM_REGISTRY_FIXED_RATE_T   eRateSetting,
3333     IN PUINT_8                      pucDesiredPhyTypeSet,
3334     IN PUINT_16                     pu2DesiredNonHTRateSet,
3335     IN PUINT_16                     pu2BSSBasicRateSet,
3336     IN PUINT_8                      pucMcsSet,
3337     IN PUINT_8                      pucSupMcs32,
3338     IN PUINT_16                     pu2HtCapInfo
3339     )
3340 {
3341     ASSERT(prAdapter);
3342     ASSERT(eRateSetting > FIXED_RATE_NONE && eRateSetting < FIXED_RATE_NUM);
3343
3344     switch(prAdapter->rWifiVar.eRateSetting) {
3345     case FIXED_RATE_1M:
3346         *pucDesiredPhyTypeSet = PHY_TYPE_BIT_HR_DSSS;
3347         *pu2DesiredNonHTRateSet = RATE_SET_BIT_1M;
3348         *pu2BSSBasicRateSet = RATE_SET_BIT_1M;
3349         *pucMcsSet = 0;
3350         *pucSupMcs32 = 0;
3351         *pu2HtCapInfo = 0;
3352         break;
3353
3354     case FIXED_RATE_2M:
3355         *pucDesiredPhyTypeSet = PHY_TYPE_BIT_HR_DSSS;
3356         *pu2DesiredNonHTRateSet = RATE_SET_BIT_2M;
3357         *pu2BSSBasicRateSet = RATE_SET_BIT_2M;
3358         *pucMcsSet = 0;
3359         *pucSupMcs32 = 0;
3360         *pu2HtCapInfo = 0;
3361         break;
3362
3363     case FIXED_RATE_5_5M:
3364         *pucDesiredPhyTypeSet = PHY_TYPE_BIT_HR_DSSS;
3365         *pu2DesiredNonHTRateSet = RATE_SET_BIT_5_5M;
3366         *pu2BSSBasicRateSet = RATE_SET_BIT_5_5M;
3367         *pucMcsSet = 0;
3368         *pucSupMcs32 = 0;
3369         *pu2HtCapInfo = 0;
3370         break;
3371
3372     case FIXED_RATE_11M:
3373         *pucDesiredPhyTypeSet = PHY_TYPE_BIT_HR_DSSS;
3374         *pu2DesiredNonHTRateSet = RATE_SET_BIT_11M;
3375         *pu2BSSBasicRateSet = RATE_SET_BIT_11M;
3376         *pucMcsSet = 0;
3377         *pucSupMcs32 = 0;
3378         *pu2HtCapInfo = 0;
3379         break;
3380
3381     case FIXED_RATE_6M:
3382         if((*pucDesiredPhyTypeSet) | PHY_TYPE_BIT_ERP) {
3383             *pucDesiredPhyTypeSet = PHY_TYPE_BIT_ERP;
3384         }
3385         else if((*pucDesiredPhyTypeSet) | PHY_TYPE_BIT_OFDM) {
3386             *pucDesiredPhyTypeSet = PHY_TYPE_BIT_OFDM;
3387         }
3388
3389         *pu2DesiredNonHTRateSet = RATE_SET_BIT_6M;
3390         *pu2BSSBasicRateSet = RATE_SET_BIT_6M;
3391         *pucMcsSet = 0;
3392         *pucSupMcs32 = 0;
3393         *pu2HtCapInfo = 0;
3394         break;
3395
3396     case FIXED_RATE_9M:
3397         if((*pucDesiredPhyTypeSet) | PHY_TYPE_BIT_ERP) {
3398             *pucDesiredPhyTypeSet = PHY_TYPE_BIT_ERP;
3399         }
3400         else if((*pucDesiredPhyTypeSet) | PHY_TYPE_BIT_OFDM) {
3401             *pucDesiredPhyTypeSet = PHY_TYPE_BIT_OFDM;
3402         }
3403
3404         *pu2DesiredNonHTRateSet = RATE_SET_BIT_9M;
3405         *pu2BSSBasicRateSet = RATE_SET_BIT_9M;
3406         *pucMcsSet = 0;
3407         *pucSupMcs32 = 0;
3408         *pu2HtCapInfo = 0;
3409         break;
3410
3411     case FIXED_RATE_12M:
3412         if((*pucDesiredPhyTypeSet) | PHY_TYPE_BIT_ERP) {
3413             *pucDesiredPhyTypeSet = PHY_TYPE_BIT_ERP;
3414         }
3415         else if((*pucDesiredPhyTypeSet) | PHY_TYPE_BIT_OFDM) {
3416             *pucDesiredPhyTypeSet = PHY_TYPE_BIT_OFDM;
3417         }
3418
3419         *pu2DesiredNonHTRateSet = RATE_SET_BIT_12M;
3420         *pu2BSSBasicRateSet = RATE_SET_BIT_12M;
3421         *pucMcsSet = 0;
3422         *pucSupMcs32 = 0;
3423         *pu2HtCapInfo = 0;
3424         break;
3425
3426     case FIXED_RATE_18M:
3427         if((*pucDesiredPhyTypeSet) | PHY_TYPE_BIT_ERP) {
3428             *pucDesiredPhyTypeSet = PHY_TYPE_BIT_ERP;
3429         }
3430         else if((*pucDesiredPhyTypeSet) | PHY_TYPE_BIT_OFDM) {
3431             *pucDesiredPhyTypeSet = PHY_TYPE_BIT_OFDM;
3432         }
3433
3434         *pu2DesiredNonHTRateSet = RATE_SET_BIT_18M;
3435         *pu2BSSBasicRateSet = RATE_SET_BIT_18M;
3436         *pucMcsSet = 0;
3437         *pucSupMcs32 = 0;
3438         *pu2HtCapInfo = 0;
3439         break;
3440
3441     case FIXED_RATE_24M:
3442         if((*pucDesiredPhyTypeSet) | PHY_TYPE_BIT_ERP) {
3443             *pucDesiredPhyTypeSet = PHY_TYPE_BIT_ERP;
3444         }
3445         else if((*pucDesiredPhyTypeSet) | PHY_TYPE_BIT_OFDM) {
3446             *pucDesiredPhyTypeSet = PHY_TYPE_BIT_OFDM;
3447         }
3448
3449         *pu2DesiredNonHTRateSet = RATE_SET_BIT_24M;
3450         *pu2BSSBasicRateSet = RATE_SET_BIT_24M;
3451         *pucMcsSet = 0;
3452         *pucSupMcs32 = 0;
3453         *pu2HtCapInfo = 0;
3454         break;
3455
3456     case FIXED_RATE_36M:
3457         if((*pucDesiredPhyTypeSet) | PHY_TYPE_BIT_ERP) {
3458             *pucDesiredPhyTypeSet = PHY_TYPE_BIT_ERP;
3459         }
3460         else if((*pucDesiredPhyTypeSet) | PHY_TYPE_BIT_OFDM) {
3461             *pucDesiredPhyTypeSet = PHY_TYPE_BIT_OFDM;
3462         }
3463
3464         *pu2DesiredNonHTRateSet = RATE_SET_BIT_36M;
3465         *pu2BSSBasicRateSet = RATE_SET_BIT_36M;
3466         *pucMcsSet = 0;
3467         *pucSupMcs32 = 0;
3468         *pu2HtCapInfo = 0;
3469         break;
3470
3471     case FIXED_RATE_48M:
3472         if((*pucDesiredPhyTypeSet) | PHY_TYPE_BIT_ERP) {
3473             *pucDesiredPhyTypeSet = PHY_TYPE_BIT_ERP;
3474         }
3475         else if((*pucDesiredPhyTypeSet) | PHY_TYPE_BIT_OFDM) {
3476             *pucDesiredPhyTypeSet = PHY_TYPE_BIT_OFDM;
3477         }
3478
3479         *pu2DesiredNonHTRateSet = RATE_SET_BIT_48M;
3480         *pu2BSSBasicRateSet = RATE_SET_BIT_48M;
3481         *pucMcsSet = 0;
3482         *pucSupMcs32 = 0;
3483         *pu2HtCapInfo = 0;
3484         break;
3485
3486     case FIXED_RATE_54M:
3487         if((*pucDesiredPhyTypeSet) | PHY_TYPE_BIT_ERP) {
3488             *pucDesiredPhyTypeSet = PHY_TYPE_BIT_ERP;
3489         }
3490         else if((*pucDesiredPhyTypeSet) | PHY_TYPE_BIT_OFDM) {
3491             *pucDesiredPhyTypeSet = PHY_TYPE_BIT_OFDM;
3492         }
3493
3494         *pu2DesiredNonHTRateSet = RATE_SET_BIT_54M;
3495         *pu2BSSBasicRateSet = RATE_SET_BIT_54M;
3496         *pucMcsSet = 0;
3497         *pucSupMcs32 = 0;
3498         *pu2HtCapInfo = 0;
3499         break;
3500
3501     case FIXED_RATE_MCS0_20M_800NS:
3502         *pucDesiredPhyTypeSet = PHY_TYPE_BIT_HT;
3503         *pu2DesiredNonHTRateSet = RATE_SET_BIT_HT_PHY;
3504         *pu2BSSBasicRateSet = RATE_SET_BIT_HT_PHY;
3505         *pucMcsSet = HT_RATE_MCS0_INDEX;
3506         *pucSupMcs32 = 0;
3507         (*pu2HtCapInfo) &= ~(HT_CAP_INFO_SUP_CHNL_WIDTH
3508                 | HT_CAP_INFO_SHORT_GI_20M
3509                 | HT_CAP_INFO_SHORT_GI_40M
3510                 | HT_CAP_INFO_HT_GF);
3511         break;
3512
3513     case FIXED_RATE_MCS1_20M_800NS:
3514         *pucDesiredPhyTypeSet = PHY_TYPE_BIT_HT;
3515         *pu2DesiredNonHTRateSet = RATE_SET_BIT_HT_PHY;
3516         *pu2BSSBasicRateSet = RATE_SET_BIT_HT_PHY;
3517         *pucMcsSet = HT_RATE_MCS1_INDEX;
3518         *pucSupMcs32 = 0;
3519         (*pu2HtCapInfo) &= ~(HT_CAP_INFO_SUP_CHNL_WIDTH
3520                 | HT_CAP_INFO_SHORT_GI_20M
3521                 | HT_CAP_INFO_SHORT_GI_40M
3522                 | HT_CAP_INFO_HT_GF);
3523         break;
3524
3525     case FIXED_RATE_MCS2_20M_800NS:
3526         *pucDesiredPhyTypeSet = PHY_TYPE_BIT_HT;
3527         *pu2DesiredNonHTRateSet = RATE_SET_BIT_HT_PHY;
3528         *pu2BSSBasicRateSet = RATE_SET_BIT_HT_PHY;
3529         *pucMcsSet = HT_RATE_MCS2_INDEX;
3530         *pucSupMcs32 = 0;
3531         (*pu2HtCapInfo) &= ~(HT_CAP_INFO_SUP_CHNL_WIDTH
3532                 | HT_CAP_INFO_SHORT_GI_20M
3533                 | HT_CAP_INFO_SHORT_GI_40M
3534                 | HT_CAP_INFO_HT_GF);
3535         break;
3536
3537     case FIXED_RATE_MCS3_20M_800NS:
3538         *pucDesiredPhyTypeSet = PHY_TYPE_BIT_HT;
3539         *pu2DesiredNonHTRateSet = RATE_SET_BIT_HT_PHY;
3540         *pu2BSSBasicRateSet = RATE_SET_BIT_HT_PHY;
3541         *pucMcsSet = HT_RATE_MCS3_INDEX;
3542         *pucSupMcs32 = 0;
3543         (*pu2HtCapInfo) &= ~(HT_CAP_INFO_SUP_CHNL_WIDTH
3544                 | HT_CAP_INFO_SHORT_GI_20M
3545                 | HT_CAP_INFO_SHORT_GI_40M
3546                 | HT_CAP_INFO_HT_GF);
3547         break;
3548
3549     case FIXED_RATE_MCS4_20M_800NS:
3550         *pucDesiredPhyTypeSet = PHY_TYPE_BIT_HT;
3551         *pu2DesiredNonHTRateSet = RATE_SET_BIT_HT_PHY;
3552         *pu2BSSBasicRateSet = RATE_SET_BIT_HT_PHY;
3553         *pucMcsSet = HT_RATE_MCS4_INDEX;
3554         *pucSupMcs32 = 0;
3555         (*pu2HtCapInfo) &= ~(HT_CAP_INFO_SUP_CHNL_WIDTH
3556                 | HT_CAP_INFO_SHORT_GI_20M
3557                 | HT_CAP_INFO_SHORT_GI_40M
3558                 | HT_CAP_INFO_HT_GF);
3559         break;
3560
3561     case FIXED_RATE_MCS5_20M_800NS:
3562         *pucDesiredPhyTypeSet = PHY_TYPE_BIT_HT;
3563         *pu2DesiredNonHTRateSet = RATE_SET_BIT_HT_PHY;
3564         *pu2BSSBasicRateSet = RATE_SET_BIT_HT_PHY;
3565         *pucMcsSet = HT_RATE_MCS5_INDEX;
3566         *pucSupMcs32 = 0;
3567         (*pu2HtCapInfo) &= ~(HT_CAP_INFO_SUP_CHNL_WIDTH
3568                 | HT_CAP_INFO_SHORT_GI_20M
3569                 | HT_CAP_INFO_SHORT_GI_40M
3570                 | HT_CAP_INFO_HT_GF);
3571         break;
3572
3573     case FIXED_RATE_MCS6_20M_800NS:
3574         *pucDesiredPhyTypeSet = PHY_TYPE_BIT_HT;
3575         *pu2DesiredNonHTRateSet = RATE_SET_BIT_HT_PHY;
3576         *pu2BSSBasicRateSet = RATE_SET_BIT_HT_PHY;
3577         *pucMcsSet = HT_RATE_MCS6_INDEX;
3578         *pucSupMcs32 = 0;
3579         (*pu2HtCapInfo) &= ~(HT_CAP_INFO_SUP_CHNL_WIDTH
3580                 | HT_CAP_INFO_SHORT_GI_20M
3581                 | HT_CAP_INFO_SHORT_GI_40M
3582                 | HT_CAP_INFO_HT_GF);
3583         break;
3584
3585     case FIXED_RATE_MCS7_20M_800NS:
3586         *pucDesiredPhyTypeSet = PHY_TYPE_BIT_HT;
3587         *pu2DesiredNonHTRateSet = RATE_SET_BIT_HT_PHY;
3588         *pu2BSSBasicRateSet = RATE_SET_BIT_HT_PHY;
3589         *pucMcsSet = HT_RATE_MCS7_INDEX;
3590         *pucSupMcs32 = 0;
3591         (*pu2HtCapInfo) &= ~(HT_CAP_INFO_SUP_CHNL_WIDTH
3592                 | HT_CAP_INFO_SHORT_GI_20M
3593                 | HT_CAP_INFO_SHORT_GI_40M
3594                 | HT_CAP_INFO_HT_GF);
3595         break;
3596
3597     case FIXED_RATE_MCS0_20M_400NS:
3598         *pucDesiredPhyTypeSet = PHY_TYPE_BIT_HT;
3599         *pu2DesiredNonHTRateSet = RATE_SET_BIT_HT_PHY;
3600         *pu2BSSBasicRateSet = RATE_SET_BIT_HT_PHY;
3601         *pucMcsSet = HT_RATE_MCS0_INDEX;
3602         *pucSupMcs32 = 0;
3603         (*pu2HtCapInfo) &= ~(HT_CAP_INFO_SUP_CHNL_WIDTH
3604                 | HT_CAP_INFO_SHORT_GI_40M
3605                 | HT_CAP_INFO_HT_GF);
3606         (*pu2HtCapInfo) |= HT_CAP_INFO_SHORT_GI_20M;
3607         break;
3608
3609     case FIXED_RATE_MCS1_20M_400NS:
3610         *pucDesiredPhyTypeSet = PHY_TYPE_BIT_HT;
3611         *pu2DesiredNonHTRateSet = RATE_SET_BIT_HT_PHY;
3612         *pu2BSSBasicRateSet = RATE_SET_BIT_HT_PHY;
3613         *pucMcsSet = HT_RATE_MCS1_INDEX;
3614         *pucSupMcs32 = 0;
3615         (*pu2HtCapInfo) &= ~(HT_CAP_INFO_SUP_CHNL_WIDTH
3616                 | HT_CAP_INFO_SHORT_GI_40M
3617                 | HT_CAP_INFO_HT_GF);
3618         (*pu2HtCapInfo) |= HT_CAP_INFO_SHORT_GI_20M;
3619         break;
3620
3621     case FIXED_RATE_MCS2_20M_400NS:
3622         *pucDesiredPhyTypeSet = PHY_TYPE_BIT_HT;
3623         *pu2DesiredNonHTRateSet = RATE_SET_BIT_HT_PHY;
3624         *pu2BSSBasicRateSet = RATE_SET_BIT_HT_PHY;
3625         *pucMcsSet = HT_RATE_MCS2_INDEX;
3626         *pucSupMcs32 = 0;
3627         (*pu2HtCapInfo) &= ~(HT_CAP_INFO_SUP_CHNL_WIDTH
3628                 | HT_CAP_INFO_SHORT_GI_40M
3629                 | HT_CAP_INFO_HT_GF);
3630         (*pu2HtCapInfo) |= HT_CAP_INFO_SHORT_GI_20M;
3631         break;
3632
3633     case FIXED_RATE_MCS3_20M_400NS:
3634         *pucDesiredPhyTypeSet = PHY_TYPE_BIT_HT;
3635         *pu2DesiredNonHTRateSet = RATE_SET_BIT_HT_PHY;
3636         *pu2BSSBasicRateSet = RATE_SET_BIT_HT_PHY;
3637         *pucMcsSet = HT_RATE_MCS3_INDEX;
3638         *pucSupMcs32 = 0;
3639         (*pu2HtCapInfo) &= ~(HT_CAP_INFO_SUP_CHNL_WIDTH
3640                 | HT_CAP_INFO_SHORT_GI_40M
3641                 | HT_CAP_INFO_HT_GF);
3642         (*pu2HtCapInfo) |= HT_CAP_INFO_SHORT_GI_20M;
3643         break;
3644
3645     case FIXED_RATE_MCS4_20M_400NS:
3646         *pucDesiredPhyTypeSet = PHY_TYPE_BIT_HT;
3647         *pu2DesiredNonHTRateSet = RATE_SET_BIT_HT_PHY;
3648         *pu2BSSBasicRateSet = RATE_SET_BIT_HT_PHY;
3649         *pucMcsSet = HT_RATE_MCS4_INDEX;
3650         *pucSupMcs32 = 0;
3651         (*pu2HtCapInfo) &= ~(HT_CAP_INFO_SUP_CHNL_WIDTH
3652                 | HT_CAP_INFO_SHORT_GI_40M
3653                 | HT_CAP_INFO_HT_GF);
3654         (*pu2HtCapInfo) |= HT_CAP_INFO_SHORT_GI_20M;
3655         break;
3656
3657     case FIXED_RATE_MCS5_20M_400NS:
3658         *pucDesiredPhyTypeSet = PHY_TYPE_BIT_HT;
3659         *pu2DesiredNonHTRateSet = RATE_SET_BIT_HT_PHY;
3660         *pu2BSSBasicRateSet = RATE_SET_BIT_HT_PHY;
3661         *pucMcsSet = HT_RATE_MCS5_INDEX;
3662         *pucSupMcs32 = 0;
3663         (*pu2HtCapInfo) &= ~(HT_CAP_INFO_SUP_CHNL_WIDTH
3664                 | HT_CAP_INFO_SHORT_GI_40M
3665                 | HT_CAP_INFO_HT_GF);
3666         (*pu2HtCapInfo) |= HT_CAP_INFO_SHORT_GI_20M;
3667         break;
3668
3669     case FIXED_RATE_MCS6_20M_400NS:
3670         *pucDesiredPhyTypeSet = PHY_TYPE_BIT_HT;
3671         *pu2DesiredNonHTRateSet = RATE_SET_BIT_HT_PHY;
3672         *pu2BSSBasicRateSet = RATE_SET_BIT_HT_PHY;
3673         *pucMcsSet = HT_RATE_MCS6_INDEX;
3674         *pucSupMcs32 = 0;
3675         (*pu2HtCapInfo) &= ~(HT_CAP_INFO_SUP_CHNL_WIDTH
3676                 | HT_CAP_INFO_SHORT_GI_40M
3677                 | HT_CAP_INFO_HT_GF);
3678         (*pu2HtCapInfo) |= HT_CAP_INFO_SHORT_GI_20M;
3679         break;
3680
3681     case FIXED_RATE_MCS7_20M_400NS:
3682         *pucDesiredPhyTypeSet = PHY_TYPE_BIT_HT;
3683         *pu2DesiredNonHTRateSet = RATE_SET_BIT_HT_PHY;
3684         *pu2BSSBasicRateSet = RATE_SET_BIT_HT_PHY;
3685         *pucMcsSet = HT_RATE_MCS7_INDEX;
3686         *pucSupMcs32 = 0;
3687         (*pu2HtCapInfo) &= ~(HT_CAP_INFO_SUP_CHNL_WIDTH
3688                 | HT_CAP_INFO_SHORT_GI_40M
3689                 | HT_CAP_INFO_HT_GF);
3690         (*pu2HtCapInfo) |= HT_CAP_INFO_SHORT_GI_20M;
3691         break;
3692
3693     case FIXED_RATE_MCS0_40M_800NS:
3694         *pucDesiredPhyTypeSet = PHY_TYPE_BIT_HT;
3695         *pu2DesiredNonHTRateSet = RATE_SET_BIT_HT_PHY;
3696         *pu2BSSBasicRateSet = RATE_SET_BIT_HT_PHY;
3697         *pucMcsSet = HT_RATE_MCS0_INDEX;
3698         *pucSupMcs32 = 0;
3699         (*pu2HtCapInfo) &= ~(HT_CAP_INFO_SHORT_GI_20M
3700                 | HT_CAP_INFO_SHORT_GI_40M
3701                 | HT_CAP_INFO_HT_GF);
3702         (*pu2HtCapInfo) |= HT_CAP_INFO_SUP_CHNL_WIDTH;
3703         break;
3704
3705     case FIXED_RATE_MCS1_40M_800NS:
3706         *pucDesiredPhyTypeSet = PHY_TYPE_BIT_HT;
3707         *pu2DesiredNonHTRateSet = RATE_SET_BIT_HT_PHY;
3708         *pu2BSSBasicRateSet = RATE_SET_BIT_HT_PHY;
3709         *pucMcsSet = HT_RATE_MCS1_INDEX;
3710         *pucSupMcs32 = 0;
3711         (*pu2HtCapInfo) &= ~(HT_CAP_INFO_SHORT_GI_20M
3712                 | HT_CAP_INFO_SHORT_GI_40M
3713                 | HT_CAP_INFO_HT_GF);
3714         (*pu2HtCapInfo) |= HT_CAP_INFO_SUP_CHNL_WIDTH;
3715         break;
3716
3717     case FIXED_RATE_MCS2_40M_800NS:
3718         *pucDesiredPhyTypeSet = PHY_TYPE_BIT_HT;
3719         *pu2DesiredNonHTRateSet = RATE_SET_BIT_HT_PHY;
3720         *pu2BSSBasicRateSet = RATE_SET_BIT_HT_PHY;
3721         *pucMcsSet = HT_RATE_MCS2_INDEX;
3722         *pucSupMcs32 = 0;
3723         (*pu2HtCapInfo) &= ~(HT_CAP_INFO_SHORT_GI_20M
3724                 | HT_CAP_INFO_SHORT_GI_40M
3725                 | HT_CAP_INFO_HT_GF);
3726         (*pu2HtCapInfo) |= HT_CAP_INFO_SUP_CHNL_WIDTH;
3727         break;
3728
3729     case FIXED_RATE_MCS3_40M_800NS:
3730         *pucDesiredPhyTypeSet = PHY_TYPE_BIT_HT;
3731         *pu2DesiredNonHTRateSet = RATE_SET_BIT_HT_PHY;
3732         *pu2BSSBasicRateSet = RATE_SET_BIT_HT_PHY;
3733         *pucMcsSet = HT_RATE_MCS3_INDEX;
3734         *pucSupMcs32 = 0;
3735         (*pu2HtCapInfo) &= ~(HT_CAP_INFO_SHORT_GI_20M
3736                 | HT_CAP_INFO_SHORT_GI_40M
3737                 | HT_CAP_INFO_HT_GF);
3738         (*pu2HtCapInfo) |= HT_CAP_INFO_SUP_CHNL_WIDTH;
3739         break;
3740
3741     case FIXED_RATE_MCS4_40M_800NS:
3742         *pucDesiredPhyTypeSet = PHY_TYPE_BIT_HT;
3743         *pu2DesiredNonHTRateSet = RATE_SET_BIT_HT_PHY;
3744         *pu2BSSBasicRateSet = RATE_SET_BIT_HT_PHY;
3745         *pucMcsSet = HT_RATE_MCS4_INDEX;
3746         *pucSupMcs32 = 0;
3747         (*pu2HtCapInfo) &= ~(HT_CAP_INFO_SHORT_GI_20M
3748                 | HT_CAP_INFO_SHORT_GI_40M
3749                 | HT_CAP_INFO_HT_GF);
3750         (*pu2HtCapInfo) |= HT_CAP_INFO_SUP_CHNL_WIDTH;
3751         break;
3752
3753     case FIXED_RATE_MCS5_40M_800NS:
3754         *pucDesiredPhyTypeSet = PHY_TYPE_BIT_HT;
3755         *pu2DesiredNonHTRateSet = RATE_SET_BIT_HT_PHY;
3756         *pu2BSSBasicRateSet = RATE_SET_BIT_HT_PHY;
3757         *pucMcsSet = HT_RATE_MCS5_INDEX;
3758         *pucSupMcs32 = 0;
3759         (*pu2HtCapInfo) &= ~(HT_CAP_INFO_SHORT_GI_20M
3760                 | HT_CAP_INFO_SHORT_GI_40M
3761                 | HT_CAP_INFO_HT_GF);
3762         (*pu2HtCapInfo) |= HT_CAP_INFO_SUP_CHNL_WIDTH;
3763         break;
3764
3765     case FIXED_RATE_MCS6_40M_800NS:
3766         *pucDesiredPhyTypeSet = PHY_TYPE_BIT_HT;
3767         *pu2DesiredNonHTRateSet = RATE_SET_BIT_HT_PHY;
3768         *pu2BSSBasicRateSet = RATE_SET_BIT_HT_PHY;
3769         *pucMcsSet = HT_RATE_MCS6_INDEX;
3770         *pucSupMcs32 = 0;
3771         (*pu2HtCapInfo) &= ~(HT_CAP_INFO_SHORT_GI_20M
3772                 | HT_CAP_INFO_SHORT_GI_40M
3773                 | HT_CAP_INFO_HT_GF);
3774         (*pu2HtCapInfo) |= HT_CAP_INFO_SUP_CHNL_WIDTH;
3775         break;
3776
3777     case FIXED_RATE_MCS7_40M_800NS:
3778         *pucDesiredPhyTypeSet = PHY_TYPE_BIT_HT;
3779         *pu2DesiredNonHTRateSet = RATE_SET_BIT_HT_PHY;
3780         *pu2BSSBasicRateSet = RATE_SET_BIT_HT_PHY;
3781         *pucMcsSet = HT_RATE_MCS7_INDEX;
3782         *pucSupMcs32 = 0;
3783         (*pu2HtCapInfo) &= ~(HT_CAP_INFO_SHORT_GI_20M
3784                 | HT_CAP_INFO_SHORT_GI_40M
3785                 | HT_CAP_INFO_HT_GF);
3786         (*pu2HtCapInfo) |= HT_CAP_INFO_SUP_CHNL_WIDTH;
3787         break;
3788
3789     case FIXED_RATE_MCS32_800NS:
3790         *pucDesiredPhyTypeSet = PHY_TYPE_BIT_HT;
3791         *pu2DesiredNonHTRateSet = RATE_SET_BIT_HT_PHY;
3792         *pu2BSSBasicRateSet = RATE_SET_BIT_HT_PHY;
3793         *pucMcsSet = HT_RATE_MCS32_INDEX;
3794         *pucSupMcs32 = 1;
3795         (*pu2HtCapInfo) &= ~(HT_CAP_INFO_SHORT_GI_20M
3796                 | HT_CAP_INFO_SHORT_GI_40M
3797                 | HT_CAP_INFO_HT_GF);
3798         (*pu2HtCapInfo) |= HT_CAP_INFO_SUP_CHNL_WIDTH;
3799         break;
3800
3801     case FIXED_RATE_MCS0_40M_400NS:
3802         *pucDesiredPhyTypeSet = PHY_TYPE_BIT_HT;
3803         *pu2DesiredNonHTRateSet = RATE_SET_BIT_HT_PHY;
3804         *pu2BSSBasicRateSet = RATE_SET_BIT_HT_PHY;
3805         *pucMcsSet = HT_RATE_MCS0_INDEX;
3806         *pucSupMcs32 = 0;
3807         (*pu2HtCapInfo) &= ~(HT_CAP_INFO_SHORT_GI_20M
3808                 | HT_CAP_INFO_HT_GF);
3809         (*pu2HtCapInfo) |= (HT_CAP_INFO_SUP_CHNL_WIDTH
3810                 | HT_CAP_INFO_SHORT_GI_40M);
3811         break;
3812
3813     case FIXED_RATE_MCS1_40M_400NS:
3814         *pucDesiredPhyTypeSet = PHY_TYPE_BIT_HT;
3815         *pu2DesiredNonHTRateSet = RATE_SET_BIT_HT_PHY;
3816         *pu2BSSBasicRateSet = RATE_SET_BIT_HT_PHY;
3817         *pucMcsSet = HT_RATE_MCS1_INDEX;
3818         *pucSupMcs32 = 0;
3819         (*pu2HtCapInfo) &= ~(HT_CAP_INFO_SHORT_GI_20M
3820                 | HT_CAP_INFO_HT_GF);
3821         (*pu2HtCapInfo) |= (HT_CAP_INFO_SUP_CHNL_WIDTH
3822                 | HT_CAP_INFO_SHORT_GI_40M);
3823         break;
3824
3825     case FIXED_RATE_MCS2_40M_400NS:
3826         *pucDesiredPhyTypeSet = PHY_TYPE_BIT_HT;
3827         *pu2DesiredNonHTRateSet = RATE_SET_BIT_HT_PHY;
3828         *pu2BSSBasicRateSet = RATE_SET_BIT_HT_PHY;
3829         *pucMcsSet = HT_RATE_MCS2_INDEX;
3830         *pucSupMcs32 = 0;
3831         (*pu2HtCapInfo) &= ~(HT_CAP_INFO_SHORT_GI_20M
3832                 | HT_CAP_INFO_HT_GF);
3833         (*pu2HtCapInfo) |= (HT_CAP_INFO_SUP_CHNL_WIDTH
3834                 | HT_CAP_INFO_SHORT_GI_40M);
3835         break;
3836
3837     case FIXED_RATE_MCS3_40M_400NS:
3838         *pucDesiredPhyTypeSet = PHY_TYPE_BIT_HT;
3839         *pu2DesiredNonHTRateSet = RATE_SET_BIT_HT_PHY;
3840         *pu2BSSBasicRateSet = RATE_SET_BIT_HT_PHY;
3841         *pucMcsSet = HT_RATE_MCS3_INDEX;
3842         *pucSupMcs32 = 0;
3843         (*pu2HtCapInfo) &= ~(HT_CAP_INFO_SHORT_GI_20M
3844                 | HT_CAP_INFO_HT_GF);
3845         (*pu2HtCapInfo) |= (HT_CAP_INFO_SUP_CHNL_WIDTH
3846                 | HT_CAP_INFO_SHORT_GI_40M);
3847         break;
3848
3849     case FIXED_RATE_MCS4_40M_400NS:
3850         *pucDesiredPhyTypeSet = PHY_TYPE_BIT_HT;
3851         *pu2DesiredNonHTRateSet = RATE_SET_BIT_HT_PHY;
3852         *pu2BSSBasicRateSet = RATE_SET_BIT_HT_PHY;
3853         *pucMcsSet = HT_RATE_MCS4_INDEX;
3854         *pucSupMcs32 = 0;
3855         (*pu2HtCapInfo) &= ~(HT_CAP_INFO_SHORT_GI_20M
3856                 | HT_CAP_INFO_HT_GF);
3857         (*pu2HtCapInfo) |= (HT_CAP_INFO_SUP_CHNL_WIDTH
3858                 | HT_CAP_INFO_SHORT_GI_40M);
3859         break;
3860
3861     case FIXED_RATE_MCS5_40M_400NS:
3862         *pucDesiredPhyTypeSet = PHY_TYPE_BIT_HT;
3863         *pu2DesiredNonHTRateSet = RATE_SET_BIT_HT_PHY;
3864         *pu2BSSBasicRateSet = RATE_SET_BIT_HT_PHY;
3865         *pucMcsSet = HT_RATE_MCS5_INDEX;
3866         *pucSupMcs32 = 0;
3867         (*pu2HtCapInfo) &= ~(HT_CAP_INFO_SHORT_GI_20M
3868                 | HT_CAP_INFO_HT_GF);
3869         (*pu2HtCapInfo) |= (HT_CAP_INFO_SUP_CHNL_WIDTH
3870                 | HT_CAP_INFO_SHORT_GI_40M);
3871         break;
3872
3873     case FIXED_RATE_MCS6_40M_400NS:
3874         *pucDesiredPhyTypeSet = PHY_TYPE_BIT_HT;
3875         *pu2DesiredNonHTRateSet = RATE_SET_BIT_HT_PHY;
3876         *pu2BSSBasicRateSet = RATE_SET_BIT_HT_PHY;
3877         *pucMcsSet = HT_RATE_MCS6_INDEX;
3878         *pucSupMcs32 = 0;
3879         (*pu2HtCapInfo) &= ~(HT_CAP_INFO_SHORT_GI_20M
3880                 | HT_CAP_INFO_HT_GF);
3881         (*pu2HtCapInfo) |= (HT_CAP_INFO_SUP_CHNL_WIDTH
3882                 | HT_CAP_INFO_SHORT_GI_40M);
3883         break;
3884
3885     case FIXED_RATE_MCS7_40M_400NS:
3886         *pucDesiredPhyTypeSet = PHY_TYPE_BIT_HT;
3887         *pu2DesiredNonHTRateSet = RATE_SET_BIT_HT_PHY;
3888         *pu2BSSBasicRateSet = RATE_SET_BIT_HT_PHY;
3889         *pucMcsSet = HT_RATE_MCS7_INDEX;
3890         *pucSupMcs32 = 0;
3891         (*pu2HtCapInfo) &= ~(HT_CAP_INFO_SHORT_GI_20M
3892                 | HT_CAP_INFO_HT_GF);
3893         (*pu2HtCapInfo) |= (HT_CAP_INFO_SUP_CHNL_WIDTH
3894                 | HT_CAP_INFO_SHORT_GI_40M);
3895         break;
3896
3897     case FIXED_RATE_MCS32_400NS:
3898         *pucDesiredPhyTypeSet = PHY_TYPE_BIT_HT;
3899         *pu2DesiredNonHTRateSet = RATE_SET_BIT_HT_PHY;
3900         *pu2BSSBasicRateSet = RATE_SET_BIT_HT_PHY;
3901         *pucMcsSet = HT_RATE_MCS32_INDEX;
3902         *pucSupMcs32 = 1;
3903         (*pu2HtCapInfo) &= ~(HT_CAP_INFO_SHORT_GI_20M
3904                 | HT_CAP_INFO_HT_GF);
3905         (*pu2HtCapInfo) |= (HT_CAP_INFO_SUP_CHNL_WIDTH
3906                 | HT_CAP_INFO_SHORT_GI_40M);
3907         break;
3908
3909     default:
3910         ASSERT(0);
3911     }
3912
3913     return WLAN_STATUS_SUCCESS;
3914 }
3915
3916 /*----------------------------------------------------------------------------*/
3917 /*!
3918 * @brief This utility function is used to write the register
3919 *
3920 * @param u4Address         Register address
3921 *        u4Value           the value to be written
3922 *
3923 * @retval WLAN_STATUS_SUCCESS
3924 *         WLAN_STATUS_FAILURE
3925 */
3926 /*----------------------------------------------------------------------------*/
3927
3928 WLAN_STATUS
3929 nicWriteMcr (
3930     IN P_ADAPTER_T  prAdapter,
3931     IN UINT_32   u4Address,
3932     IN  UINT_32  u4Value
3933     )
3934 {
3935     CMD_ACCESS_REG rCmdAccessReg;
3936
3937     rCmdAccessReg.u4Address = u4Address;
3938     rCmdAccessReg.u4Data = u4Value;
3939
3940     return wlanSendSetQueryCmd(prAdapter,
3941                 CMD_ID_ACCESS_REG,
3942                 TRUE,
3943                 FALSE,
3944                 FALSE,
3945                 NULL,
3946                 NULL,
3947                 sizeof(CMD_ACCESS_REG),
3948                 (PUINT_8)&rCmdAccessReg,
3949                 NULL,
3950                 0
3951                 );
3952
3953 }
3954
3955 /*----------------------------------------------------------------------------*/
3956 /*!
3957 * @brief This utility function is used to modify the auto rate parameters
3958 *
3959 * @param u4ArSysParam0  see description below
3960 *        u4ArSysParam1
3961 *        u4ArSysParam2
3962 *        u4ArSysParam3
3963 *
3964 *
3965 * @retval WLAN_STATUS_SUCCESS
3966 *         WLAN_STATUS_FAILURE
3967 *
3968 * @note
3969 *   ArSysParam0[0:3] -> auto rate version (0:disable 1:version1 2:version2)
3970 *   ArSysParam0[4:5]-> auto bw version (0:disable 1:version1 2:version2)
3971 *   ArSysParam0[6:7]-> auto gi version (0:disable 1:version1 2:version2)
3972 *   ArSysParam0[8:15]-> HT rate clear mask
3973 *   ArSysParam0[16:31]-> Legacy rate clear mask
3974 *   ArSysParam1[0:7]-> Auto Rate check weighting window
3975 *   ArSysParam1[8:15]-> Auto Rate v1 Force Rate down
3976 *   ArSysParam1[16:23]-> Auto Rate v1 PerH
3977 *   ArSysParam1[24:31]-> Auto Rate v1 PerL
3978 *
3979 *   Examples
3980 *   ArSysParam0 = 1,
3981 *   Enable auto rate version 1
3982 *
3983 *   ArSysParam0 = 983041,
3984 *   Enable auto rate version 1
3985 *   Remove CCK 1M, 2M, 5.5M, 11M
3986 *
3987 *   ArSysParam0 = 786433
3988 *   Enable auto rate version 1
3989 *   Remove CCK 5.5M 11M
3990 */
3991 /*----------------------------------------------------------------------------*/
3992
3993
3994 WLAN_STATUS
3995 nicRlmArUpdateParms(
3996     IN P_ADAPTER_T prAdapter,
3997     IN UINT_32 u4ArSysParam0,
3998     IN UINT_32 u4ArSysParam1,
3999     IN UINT_32 u4ArSysParam2,
4000     IN UINT_32 u4ArSysParam3
4001     )
4002 {
4003     UINT_8 ucArVer,ucAbwVer,ucAgiVer;
4004     UINT_16 u2HtClrMask;
4005     UINT_16 u2LegacyClrMask;
4006     UINT_8  ucArCheckWindow;
4007     UINT_8  ucArPerL;
4008     UINT_8  ucArPerH;
4009     UINT_8  ucArPerForceRateDownPer;
4010
4011     ucArVer = (UINT_8)(u4ArSysParam0 & BITS(0,3));
4012     ucAbwVer = (UINT_8)((u4ArSysParam0 & BITS(4,5)) >>4);
4013     ucAgiVer = (UINT_8)((u4ArSysParam0 & BITS(6,7)) >>6);
4014     u2HtClrMask = (UINT_16) ((u4ArSysParam0 & BITS(8,15)) >> 8);
4015     u2LegacyClrMask = (UINT_16) ((u4ArSysParam0 & BITS(16,31)) >> 16);
4016
4017 #if 0
4018     ucArCheckWindow = (UINT_8) (u4ArSysParam1 & BITS(0,7));
4019     ucArPerForceRateDownPer = (UINT_8) ((u4ArSysParam1 & BITS(8,15)>>8));
4020     ucArPerH = (UINT_8) ((u4ArSysParam1 & BITS(16,23)) >>16);
4021     ucArPerL = (UINT_8) ((u4ArSysParam1 & BITS(24,31)) >>24);
4022 #endif
4023
4024     ucArCheckWindow = (UINT_8) (u4ArSysParam1 & BITS(0,7));
4025     ucArPerForceRateDownPer = (UINT_8) (((u4ArSysParam1>>8) & BITS(0,7)));
4026     ucArPerH = (UINT_8) (((u4ArSysParam1>>16) & BITS(0,7)));
4027     ucArPerL = (UINT_8) (((u4ArSysParam1>>24) & BITS(0,7)));
4028
4029
4030     DBGLOG(INIT, INFO, ("ArParam %u %u %u %u\n", u4ArSysParam0, u4ArSysParam1, u4ArSysParam2, u4ArSysParam3));
4031     DBGLOG(INIT, INFO, ("ArVer %u AbwVer %u AgiVer %u\n", ucArVer, ucAbwVer, ucAgiVer));
4032     DBGLOG(INIT, INFO, ("HtMask %x LegacyMask %x\n", u2HtClrMask, u2LegacyClrMask));
4033     DBGLOG(INIT, INFO, ("CheckWin %u RateDownPer %u PerH %u PerL %u\n", ucArCheckWindow, ucArPerForceRateDownPer, ucArPerH, ucArPerL));
4034
4035 #define SWCR_DATA_ADDR(MOD,ADDR) (0x90000000+(MOD<<8)+(ADDR))
4036 #define SWCR_DATA_CMD(CATE,WRITE,INDEX,OPT0,OPT1) ( (CATE<<24) | (WRITE<<23) | (INDEX<<16) | (OPT0 <<8) | OPT1  )
4037 #define SWCR_DATA0 0x0
4038 #define SWCR_DATA1 0x4
4039 #define SWCR_DATA2 0x8
4040 #define SWCR_DATA3 0xC
4041 #define SWCR_DATA4 0x10
4042 #define SWCR_WRITE 1
4043 #define SWCR_READ 0
4044
4045     if(ucArVer > 0) {
4046        /* dummy = WiFi.WriteMCR(&h90000104, &h00000001) */
4047        /* dummy = WiFi.WriteMCR(&h90000100, &h00850000)*/
4048
4049        nicWriteMcr (prAdapter, SWCR_DATA_ADDR(1/*MOD*/,SWCR_DATA1),1);
4050        nicWriteMcr (prAdapter, SWCR_DATA_ADDR(1/*MOD*/,SWCR_DATA0),SWCR_DATA_CMD(0,SWCR_WRITE,5,0,0));
4051     }
4052     else {
4053        nicWriteMcr (prAdapter, SWCR_DATA_ADDR(1/*MOD*/,SWCR_DATA1),0);
4054        nicWriteMcr (prAdapter, SWCR_DATA_ADDR(1/*MOD*/,SWCR_DATA0),SWCR_DATA_CMD(0,SWCR_WRITE,5,0,0)) ;
4055     }
4056
4057     /* ucArVer 0: none 1:PER 2:Rcpi */
4058     nicWriteMcr (prAdapter, SWCR_DATA_ADDR(1/*MOD*/,SWCR_DATA1),ucArVer);
4059     nicWriteMcr (prAdapter, SWCR_DATA_ADDR(1/*MOD*/,SWCR_DATA0),SWCR_DATA_CMD(0,SWCR_WRITE,7,0,0));
4060
4061     /* Candidate rate Ht mask */
4062     nicWriteMcr (prAdapter, SWCR_DATA_ADDR(1/*MOD*/,SWCR_DATA1),u2HtClrMask);
4063     nicWriteMcr (prAdapter, SWCR_DATA_ADDR(1/*MOD*/,SWCR_DATA0),SWCR_DATA_CMD(0,SWCR_WRITE,0x1c,0,0));
4064
4065     /* Candidate rate legacy mask */
4066     nicWriteMcr (prAdapter, SWCR_DATA_ADDR(1/*MOD*/,SWCR_DATA1),u2LegacyClrMask);
4067     nicWriteMcr (prAdapter, SWCR_DATA_ADDR(1/*MOD*/,SWCR_DATA0),SWCR_DATA_CMD(0,SWCR_WRITE,0x1d,0,0));
4068
4069 #if 0
4070     if(ucArCheckWindow!=0) {
4071         /* TX DONE MCS INDEX CHECK STA RATE DOWN TH */
4072         nicWriteMcr (prAdapter, SWCR_DATA_ADDR(1/*MOD*/,SWCR_DATA1),ucArCheckWindow);
4073         nicWriteMcr (prAdapter, SWCR_DATA_ADDR(1/*MOD*/,SWCR_DATA0),SWCR_DATA_CMD(0,SWCR_WRITE,0x14,0,0));
4074         nicWriteMcr (prAdapter, SWCR_DATA_ADDR(1/*MOD*/,SWCR_DATA1),ucArCheckWindow);
4075         nicWriteMcr (prAdapter, SWCR_DATA_ADDR(1/*MOD*/,SWCR_DATA0),SWCR_DATA_CMD(0,SWCR_WRITE,0xc,0,0));
4076     }
4077
4078     if(ucArPerForceRateDownPer !=0) {
4079         nicWriteMcr (prAdapter, SWCR_DATA_ADDR(1/*MOD*/,SWCR_DATA1),ucArPerForceRateDownPer);
4080         nicWriteMcr (prAdapter, SWCR_DATA_ADDR(1/*MOD*/,SWCR_DATA0),SWCR_DATA_CMD(0,SWCR_WRITE,0x18,0,0));
4081     }
4082     if(ucArPerH !=0) {
4083         nicWriteMcr (prAdapter, SWCR_DATA_ADDR(1/*MOD*/,SWCR_DATA1),ucArPerH);
4084         nicWriteMcr (prAdapter, SWCR_DATA_ADDR(1/*MOD*/,SWCR_DATA0),SWCR_DATA_CMD(0,SWCR_WRITE,0x1,0,0));
4085     }
4086     if(ucArPerL !=0) {
4087         nicWriteMcr (prAdapter, SWCR_DATA_ADDR(1/*MOD*/,SWCR_DATA1),ucArPerL);
4088         nicWriteMcr (prAdapter, SWCR_DATA_ADDR(1/*MOD*/,SWCR_DATA0),SWCR_DATA_CMD(0,SWCR_WRITE,0x2,0,0));
4089     }
4090 #endif
4091
4092
4093
4094     return WLAN_STATUS_SUCCESS;
4095 }
4096
4097 /*----------------------------------------------------------------------------*/
4098 /*!
4099 * @brief This utility function is used to enable roaming
4100 *
4101 * @param u4EnableRoaming
4102 *
4103 *
4104 * @retval WLAN_STATUS_SUCCESS
4105 *         WLAN_STATUS_FAILURE
4106 *
4107 * @note
4108 *   u4EnableRoaming -> Enable Romaing
4109 *
4110 */
4111 /*----------------------------------------------------------------------------*/
4112 WLAN_STATUS
4113 nicRoamingUpdateParams(
4114     IN P_ADAPTER_T prAdapter,
4115     IN UINT_32 u4EnableRoaming
4116     )
4117 {
4118     P_CONNECTION_SETTINGS_T prConnSettings;
4119
4120     prConnSettings = &(prAdapter->rWifiVar.rConnSettings);
4121     prConnSettings->fgIsEnableRoaming = ((u4EnableRoaming>0)?(TRUE):(FALSE));
4122
4123     return WLAN_STATUS_SUCCESS;
4124 }
4125
4126 /*----------------------------------------------------------------------------*/
4127 /*!
4128 * \brief dump firmware Assert message
4129 *
4130 * \param[in]
4131 *           prAdapter
4132 *
4133 * \return
4134 *           TRUE
4135 *           FALSE
4136 */
4137 /*----------------------------------------------------------------------------*/
4138 VOID
4139 nicPrintFirmwareAssertInfo(
4140     IN P_ADAPTER_T prAdapter
4141     )
4142 {
4143     UINT_32 u4MailBox0, u4MailBox1;
4144     UINT_32 line = 0;
4145     UINT_8 aucAssertFile[7];
4146     UINT_32 u4ChipId;
4147
4148 #if CFG_SDIO_INTR_ENHANCE
4149     u4MailBox0 = prAdapter->prSDIOCtrl->u4RcvMailbox0;
4150     u4MailBox1 = prAdapter->prSDIOCtrl->u4RcvMailbox1;
4151 #else
4152     nicGetMailbox(prAdapter, 0, &u4MailBox0);
4153     nicGetMailbox(prAdapter, 1, &u4MailBox1);
4154 #endif
4155
4156     line = u4MailBox0 & 0x0000FFFF;
4157
4158     u4MailBox0 = ((u4MailBox0 >> 16) & 0x0000FFFF);
4159
4160     kalMemCopy(&aucAssertFile[0], &u4MailBox0, 2);
4161     kalMemCopy(&aucAssertFile[2], &u4MailBox1, 4);
4162
4163     aucAssertFile[6] = '\0';
4164
4165 #if defined(MT6620)
4166     u4ChipId = 6620;
4167 #elif defined(MT5931)
4168     u4ChipId = 5931;
4169 #elif defined(MT6628)
4170     u4ChipId = 6628;
4171 #endif
4172
4173     kalPrint("\n[MT%ld][wifi][Firmware] Assert at \"%s\" #%ld\n\n",
4174         u4ChipId,
4175         aucAssertFile,
4176         line);
4177
4178 }
4179
4180
4181 /*----------------------------------------------------------------------------*/
4182 /*!
4183 * @brief This function is called to update Link Quality information
4184 *
4185 * @param prAdapter      Pointer of Adapter Data Structure
4186 *        eNetTypeIdx
4187 *        prEventLinkQuality
4188 *        cRssi
4189 *        cLinkQuality
4190 *
4191 * @return none
4192 */
4193 /*----------------------------------------------------------------------------*/
4194 VOID
4195 nicUpdateLinkQuality(
4196     IN P_ADAPTER_T                  prAdapter,
4197     IN ENUM_NETWORK_TYPE_INDEX_T    eNetTypeIdx,
4198     IN P_EVENT_LINK_QUALITY         prEventLinkQuality
4199     )
4200 {
4201     ASSERT(prAdapter);
4202     ASSERT(eNetTypeIdx < NETWORK_TYPE_INDEX_NUM);
4203     ASSERT(prEventLinkQuality);
4204
4205     switch(eNetTypeIdx) {
4206     case NETWORK_TYPE_AIS_INDEX:
4207         /* check is to prevent RSSI to be updated by incorrect initial RSSI from hardware */
4208         /* buffer statistics for further query */
4209         if(prAdapter->fgIsLinkQualityValid == FALSE
4210                 || (kalGetTimeTick() - prAdapter->rLinkQualityUpdateTime) > CFG_LINK_QUALITY_VALID_PERIOD) {
4211             nicUpdateRSSI(prAdapter, eNetTypeIdx, prEventLinkQuality->cRssi, prEventLinkQuality->cLinkQuality);
4212         }
4213
4214         if(prAdapter->fgIsLinkRateValid == FALSE
4215                 || (kalGetTimeTick() - prAdapter->rLinkRateUpdateTime) > CFG_LINK_QUALITY_VALID_PERIOD) {
4216             nicUpdateLinkSpeed(prAdapter, eNetTypeIdx, prEventLinkQuality->u2LinkSpeed);
4217         }
4218         break;
4219 #if CFG_ENABLE_WIFI_DIRECT
4220 #if CFG_SUPPORT_P2P_RSSI_QUERY
4221     case NETWORK_TYPE_P2P_INDEX:
4222         if (prAdapter->fgIsP2pLinkQualityValid == FALSE
4223                 || (kalGetTimeTick() - prAdapter->rP2pLinkQualityUpdateTime) > CFG_LINK_QUALITY_VALID_PERIOD) {
4224             P_EVENT_LINK_QUALITY_EX prEventLQEx = (P_EVENT_LINK_QUALITY_EX)prEventLinkQuality;
4225
4226             nicUpdateRSSI(prAdapter, NETWORK_TYPE_P2P_INDEX, prEventLQEx->cRssiP2P, prEventLQEx->cLinkQualityP2P);
4227         }
4228         break;
4229 #endif
4230 #endif
4231     default:
4232         break;
4233
4234     }
4235
4236     return;
4237 }
4238
4239
4240 /*----------------------------------------------------------------------------*/
4241 /*!
4242 * @brief This function is called to update RSSI and Link Quality information
4243 *
4244 * @param prAdapter      Pointer of Adapter Data Structure
4245 *        eNetTypeIdx
4246 *        cRssi
4247 *        cLinkQuality
4248 *
4249 * @return none
4250 */
4251 /*----------------------------------------------------------------------------*/
4252 VOID
4253 nicUpdateRSSI(
4254     IN P_ADAPTER_T                  prAdapter,
4255     IN ENUM_NETWORK_TYPE_INDEX_T    eNetTypeIdx,
4256     IN INT_8                        cRssi,
4257     IN INT_8                        cLinkQuality
4258     )
4259 {
4260     ASSERT(prAdapter);
4261     ASSERT(eNetTypeIdx < NETWORK_TYPE_INDEX_NUM);
4262
4263     switch(eNetTypeIdx) {
4264     case NETWORK_TYPE_AIS_INDEX:
4265         prAdapter->fgIsLinkQualityValid = TRUE;
4266         prAdapter->rLinkQualityUpdateTime = kalGetTimeTick();
4267
4268         prAdapter->rLinkQuality.cRssi = cRssi;
4269         prAdapter->rLinkQuality.cLinkQuality = cLinkQuality;
4270
4271         /* indicate to glue layer */
4272         kalUpdateRSSI(prAdapter->prGlueInfo,
4273                 KAL_NETWORK_TYPE_AIS_INDEX,
4274                 prAdapter->rLinkQuality.cRssi,
4275                 prAdapter->rLinkQuality.cLinkQuality);
4276
4277         break;
4278 #if CFG_ENABLE_WIFI_DIRECT
4279 #if CFG_SUPPORT_P2P_RSSI_QUERY
4280     case NETWORK_TYPE_P2P_INDEX:
4281         prAdapter->fgIsP2pLinkQualityValid = TRUE;
4282         prAdapter->rP2pLinkQualityUpdateTime = kalGetTimeTick();
4283
4284         prAdapter->rP2pLinkQuality.cRssi= cRssi;
4285         prAdapter->rP2pLinkQuality.cLinkQuality= cLinkQuality;
4286
4287         kalUpdateRSSI(prAdapter->prGlueInfo,
4288                 KAL_NETWORK_TYPE_P2P_INDEX,
4289                 cRssi,
4290                 cLinkQuality);
4291         break;
4292 #endif
4293 #endif
4294     default:
4295         break;
4296
4297     }
4298
4299     return;
4300 }
4301
4302
4303 /*----------------------------------------------------------------------------*/
4304 /*!
4305 * @brief This function is called to update Link Quality information
4306 *
4307 * @param prAdapter      Pointer of Adapter Data Structure
4308 *        eNetTypeIdx
4309 *        prEventLinkQuality
4310 *        cRssi
4311 *        cLinkQuality
4312 *
4313 * @return none
4314 */
4315 /*----------------------------------------------------------------------------*/
4316 VOID
4317 nicUpdateLinkSpeed(
4318     IN P_ADAPTER_T                  prAdapter,
4319     IN ENUM_NETWORK_TYPE_INDEX_T    eNetTypeIdx,
4320     IN UINT_16                      u2LinkSpeed
4321     )
4322 {
4323     ASSERT(prAdapter);
4324     ASSERT(eNetTypeIdx < NETWORK_TYPE_INDEX_NUM);
4325
4326     switch(eNetTypeIdx) {
4327     case NETWORK_TYPE_AIS_INDEX:
4328         /* buffer statistics for further query */
4329         prAdapter->fgIsLinkRateValid = TRUE;
4330         prAdapter->rLinkRateUpdateTime = kalGetTimeTick();
4331
4332         prAdapter->rLinkQuality.u2LinkSpeed = u2LinkSpeed;
4333
4334         break;
4335
4336     default:
4337         break;
4338
4339     }
4340
4341     return;
4342 }
4343
4344 #if CFG_SUPPORT_RDD_TEST_MODE
4345 WLAN_STATUS
4346 nicUpdateRddTestMode(
4347     IN P_ADAPTER_T      prAdapter,
4348     IN P_CMD_RDD_CH_T   prRddChParam
4349     )
4350 {
4351     DEBUGFUNC("nicUpdateRddTestMode.\n");
4352
4353     ASSERT(prAdapter);
4354
4355 //    aisFsmScanRequest(prAdapter, NULL);
4356
4357     return wlanSendSetQueryCmd(prAdapter,
4358             CMD_ID_SET_RDD_CH,
4359             TRUE,
4360             FALSE,
4361             FALSE,
4362             NULL,
4363             NULL,
4364             sizeof(CMD_RDD_CH_T),
4365             (PUINT_8)prRddChParam,
4366             NULL,
4367             0);
4368 }
4369 #endif
4370