support different wifi bt chip auto compatible
[firefly-linux-kernel-4.4.55.git] / drivers / net / wireless / rockchip_wlan / mt5931_kk / drv_wlan / mgmt / swcr.c
1 /*
2 ** $Id: //Department/DaVinci/BRANCHES/MT662X_593X_WIFI_DRIVER_V2_3/mgmt/swcr.c#1 $
3 */
4
5 /*! \file   "swcr.c"
6     \brief
7
8 */
9
10 /*******************************************************************************
11 * Copyright (c) 2009 MediaTek Inc.
12 *
13 * All rights reserved. Copying, compilation, modification, distribution
14 * or any other use whatsoever of this material is strictly prohibited
15 * except in accordance with a Software License Agreement with
16 * MediaTek Inc.
17 ********************************************************************************
18 */
19
20 /*******************************************************************************
21 * LEGAL DISCLAIMER
22 *
23 * BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND
24 * AGREES THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK
25 * SOFTWARE") RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE
26 * PROVIDED TO BUYER ON AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY
27 * DISCLAIMS ANY AND ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT
28 * LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
29 * PARTICULAR PURPOSE OR NONINFRINGEMENT. NEITHER DOES MEDIATEK PROVIDE
30 * ANY WARRANTY WHATSOEVER WITH RESPECT TO THE SOFTWARE OF ANY THIRD PARTY
31 * WHICH MAY BE USED BY, INCORPORATED IN, OR SUPPLIED WITH THE MEDIATEK
32 * SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH THIRD PARTY FOR ANY
33 * WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE
34 * FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S SPECIFICATION OR TO
35 * CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
36 *
37 * BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
38 * LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL
39 * BE, AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT
40 * ISSUE, OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY
41 * BUYER TO MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
42 *
43 * THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
44 * WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT
45 * OF LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING
46 * THEREOF AND RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN
47 * FRANCISCO, CA, UNDER THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE
48 * (ICC).
49 ********************************************************************************
50 */
51
52 /*
53 ** $Log: swcr.c $
54  *
55  * 06 04 2012 tsaiyuan.hsu
56  * [WCXRP00001249] [ALPS.ICS] Daily build warning on "wlan/mgmt/swcr.c#1"
57  * resolve build waring for "WNM_UNIT_TEST not defined".
58  *
59  * 03 02 2012 terry.wu
60  * NULL
61  * Sync CFG80211 modification from branch 2,2.
62  *
63  * 01 05 2012 tsaiyuan.hsu
64  * [WCXRP00001157] [MT6620 Wi-Fi][FW][DRV] add timing measurement support for 802.11v
65  * add timing measurement support for 802.11v.
66  *
67  * 11 22 2011 tsaiyuan.hsu
68  * [WCXRP00001083] [MT6620 Wi-Fi][DRV]] dump debug counter or frames when debugging is triggered
69  * keep debug counter setting after wake up.
70  *
71  * 11 15 2011 cm.chang
72  * NULL
73  * Fix compiling warning
74  *
75  * 11 11 2011 tsaiyuan.hsu
76  * [WCXRP00001083] [MT6620 Wi-Fi][DRV]] dump debug counter or frames when debugging is triggered
77  * fix debug counters of rx in driver.
78  *
79  * 11 11 2011 tsaiyuan.hsu
80  * [WCXRP00001083] [MT6620 Wi-Fi][DRV]] dump debug counter or frames when debugging is triggered
81  * add debug counters of bb and ar for xlog.
82  *
83  * 11 10 2011 eddie.chen
84  * [WCXRP00001096] [MT6620 Wi-Fi][Driver/FW] Enhance the log function (xlog)
85  * Modify the QM xlog level and remove LOG_FUNC.
86  *
87  * 11 08 2011 tsaiyuan.hsu
88  * [WCXRP00001083] [MT6620 Wi-Fi][DRV]] dump debug counter or frames when debugging is triggered
89  * add debug counters, eCurPsProf, for PS.
90  *
91  * 11 07 2011 tsaiyuan.hsu
92  * [WCXRP00001083] [MT6620 Wi-Fi][DRV]] dump debug counter or frames when debugging is triggered
93  * add debug counters and periodically dump counters for debugging.
94  *
95  * 11 03 2011 wh.su
96  * [WCXRP00001078] [MT6620 Wi-Fi][Driver] Adding the mediatek log improment support : XLOG
97  * change the DBGLOG for "\n" and "\r\n". LABEL to LOUD for XLOG
98  *
99  * 08 31 2011 tsaiyuan.hsu
100  * [WCXRP00000931] [MT5931 Wi-Fi][DRV/FW] add swcr to disable roaming from driver
101  * remove obsolete code.
102  *
103  * 08 15 2011 tsaiyuan.hsu
104  * [WCXRP00000931] [MT5931 Wi-Fi][DRV/FW] add swcr to disable roaming from driver
105  * add swcr in driver reg, 0x9fxx0000, to disable roaming .
106  *
107  * 05 11 2011 eddie.chen
108  * [WCXRP00000709] [MT6620 Wi-Fi][Driver] Check free number before copying broadcast packet
109  * Fix dest type when GO packet copying.
110  *
111  * 05 09 2011 eddie.chen
112  * [WCXRP00000709] [MT6620 Wi-Fi][Driver] Check free number before copying broadcast packet
113  * Check free number before copying broadcast packet.
114  *
115  * 04 14 2011 eddie.chen
116  * [WCXRP00000603] [MT6620 Wi-Fi][DRV] Fix Klocwork warning
117  * Check the SW RFB free. Fix the compile warning..
118  *
119  * 04 12 2011 eddie.chen
120  * [WCXRP00000617] [MT6620 Wi-Fi][DRV/FW] Fix for sigma
121  * Fix the sta index in processing security frame
122  * Simple flow control for TC4 to avoid mgt frames for PS STA to occupy the TC4
123  * Add debug message.
124  *
125  * 03 28 2011 eddie.chen
126  * [WCXRP00000603] [MT6620 Wi-Fi][DRV] Fix Klocwork warning
127  * Fix Klockwork warning.
128  *
129  * 03 15 2011 eddie.chen
130  * [WCXRP00000554] [MT6620 Wi-Fi][DRV] Add sw control debug counter
131  * Add sw debug counter for QM.
132  *
133  * 01 11 2011 eddie.chen
134  * [WCXRP00000322] Add WMM IE in beacon,
135 Add per station flow control when STA is in PS
136
137  * Add swcr for test.
138  *
139 *
140 */
141
142
143 /*******************************************************************************
144 *                         C O M P I L E R   F L A G S
145 ********************************************************************************
146 */
147
148 /*******************************************************************************
149 *                    E X T E R N A L   R E F E R E N C E S
150 ********************************************************************************
151 */
152 #include "precomp.h"
153
154 #if CFG_SUPPORT_SWCR
155
156 #ifdef __GNUC__
157 #pragma GCC diagnostic ignored "-Wformat"
158 #endif
159 /*******************************************************************************
160 *                             D A T A   T Y P E S
161 ********************************************************************************
162 */
163
164 /*******************************************************************************
165 *                            P U B L I C   D A T A
166 ********************************************************************************
167 */
168 #if 0
169 extern SWCR_MAP_ENTRY_T g_arRlmArSwCrMap[];
170 SWCR_MOD_MAP_ENTRY_T g_arSwCrAllMaps[] = {
171     { SWCR_MAP_NUM(g_arRlmArSwCrMap), g_arRlmArSwCrMap},  /* 0x00nn */
172     {0,NULL}
173 };
174 #endif
175
176 VOID swCtrlCmdCategory0(P_ADAPTER_T prAdapter, UINT_8 ucCate, UINT_8 ucAction, UINT_8 ucOpt0,UINT_8 ucOpt1);
177 VOID swCtrlCmdCategory1(P_ADAPTER_T prAdapter, UINT_8 ucCate, UINT_8 ucAction, UINT_8 ucOpt0,UINT_8 ucOpt1);
178 VOID testPsCmdCategory0(P_ADAPTER_T prAdapter, UINT_8 ucCate, UINT_8 ucAction, UINT_8 ucOpt0,UINT_8 ucOpt1);
179 VOID testPsCmdCategory1(P_ADAPTER_T prAdapter, UINT_8 ucCate, UINT_8 ucAction, UINT_8 ucOpt0,UINT_8 ucOpt1);
180 void testWNMCmdCategory0(P_ADAPTER_T prAdapter, UINT_8 ucCate, UINT_8 ucAction, UINT_8 ucOpt0,UINT_8 ucOpt1);
181 VOID swCtrlSwCr(P_ADAPTER_T prAdapter, UINT_8 ucRead, UINT_16 u2Addr, UINT_32 *pu4Data);
182
183 /* Support Debug */
184 VOID swCrDebugCheck(P_ADAPTER_T  prAdapter, P_CMD_SW_DBG_CTRL_T prCmdSwCtrl);
185 VOID swCrDebugCheckTimeout(
186     IN P_ADAPTER_T prAdapter,
187     UINT_32 u4Param);
188 VOID swCrDebugQuery(
189     IN P_ADAPTER_T  prAdapter,
190     IN P_CMD_INFO_T prCmdInfo,
191     IN PUINT_8      pucEventBuf
192     );
193 VOID swCrDebugQueryTimeout(
194     IN P_ADAPTER_T  prAdapter,
195     IN P_CMD_INFO_T prCmdInfo);
196
197 UINT_32 g_au4SwCr[SWCR_CR_NUM]; /*: 0: command other: data */
198
199 static TIMER_T g_rSwcrDebugTimer;
200 static BOOLEAN g_fgSwcrDebugTimer = FALSE;
201 static UINT_32 g_u4SwcrDebugCheckTimeout = 0;
202 static ENUM_SWCR_DBG_TYPE_T g_ucSwcrDebugCheckType = 0;
203 static UINT_32 g_u4SwcrDebugFrameDumpType = 0;
204
205 /*******************************************************************************
206 *                           P R I V A T E   D A T A
207 ********************************************************************************
208 */
209 #define TEST_PS 1
210
211 const static PFN_CMD_RW_T g_arSwCtrlCmd[] ={
212     swCtrlCmdCategory0,
213     swCtrlCmdCategory1
214 #if TEST_PS
215     , testPsCmdCategory0
216     , testPsCmdCategory1
217 #endif
218 #if CFG_SUPPORT_802_11V
219 #if (CFG_SUPPORT_802_11V_TIMING_MEASUREMENT ==1) && (WNM_UNIT_TEST ==1)
220     , testWNMCmdCategory0
221 #endif
222 #endif
223 };
224
225
226 const PFN_SWCR_RW_T g_arSwCrModHandle[] = {
227     swCtrlSwCr,
228     NULL
229 };
230
231
232 /*******************************************************************************
233 *                                 M A C R O S
234 ********************************************************************************
235 */
236
237 enum {
238     SWCTRL_MAGIC,
239     SWCTRL_DEBUG,
240     SWCTRL_WIFI_VAR,
241     SWCTRL_ENABLE_INT,
242     SWCTRL_DISABLE_INT,
243     SWCTRL_TXM_INFO,
244     SWCTRL_RXM_INFO,
245     SWCTRL_DUMP_BSS,
246     SWCTRL_QM_INFO,
247     SWCTRL_DUMP_ALL_QUEUE_LEN,
248     SWCTRL_DUMP_MEM,
249     SWCTRL_TX_CTRL_INFO,
250     SWCTRL_DUMP_QUEUE,
251     SWCTRL_DUMP_QM_DBG_CNT,
252     SWCTRL_QM_DBG_CNT,
253     SWCTRL_RX_PKTS_DUMP,
254     SWCTRL_CATA0_INDEX_NUM
255 };
256
257 enum {
258     SWCTRL_STA_INFO,
259     SWCTRL_DUMP_STA,
260     SWCTRL_STA_QUE_INFO,
261     SWCTRL_CATA1_INDEX_NUM
262 };
263
264
265
266 #if TEST_PS
267 enum {
268     TEST_PS_MAGIC,
269     TEST_PS_SETUP_BSS,
270     TEST_PS_ENABLE_BEACON,
271     TEST_PS_TRIGGER_BMC,
272     TEST_PS_SEND_NULL,
273     TEST_PS_BUFFER_BMC,
274     TEST_PS_UPDATE_BEACON,
275     TEST_PS_CATA0_INDEX_NUM
276 };
277
278 enum {
279     TEST_PS_STA_PS,
280     TEST_PS_STA_ENTER_PS,
281     TEST_PS_STA_EXIT_PS,
282     TEST_PS_STA_TRIGGER_PSPOLL,
283     TEST_PS_STA_TRIGGER_FRAME,
284     TEST_PS_CATA1_INDEX_NUM
285 };
286 #endif
287
288 #if CFG_SUPPORT_802_11V
289 #if WNM_UNIT_TEST
290 enum {
291     TEST_WNM_TIMING_MEAS,
292     TEST_WNM_CATA0_INDEX_NUM
293 };
294 #endif
295 #endif
296
297
298 #define _SWCTRL_MAGIC 0x66201642
299
300 /*******************************************************************************
301 *                   F U N C T I O N   D E C L A R A T I O N S
302 ********************************************************************************
303 */
304
305
306 /*******************************************************************************
307 *                              F U N C T I O N S
308 ********************************************************************************
309 */
310
311 void dumpQueue(P_ADAPTER_T prAdapter)
312 {
313
314     P_TX_CTRL_T prTxCtrl;
315     P_QUE_MGT_T prQM;
316     P_GLUE_INFO_T           prGlueInfo;
317     UINT_32 i;
318     UINT_32 j;
319
320
321     DEBUGFUNC("dumpQueue");
322
323     prTxCtrl = &prAdapter->rTxCtrl;
324     prQM = &prAdapter->rQM;
325     prGlueInfo = prAdapter->prGlueInfo;
326
327     for(i = TC0_INDEX; i<=TC5_INDEX; i++) {
328         DBGLOG(SW4, INFO,( "TC %u\n",i));
329         DBGLOG(SW4, INFO,( "Max %u Free %u\n",
330                 prTxCtrl->rTc.aucMaxNumOfBuffer[i], prTxCtrl->rTc.aucFreeBufferCount[i]));
331
332         DBGLOG(SW4, INFO,("Average %u minReserved %u CurrentTcResource %u GuaranteedTcResource %u\n",
333            QM_GET_TX_QUEUE_LEN(prAdapter, i),
334            prQM->au4MinReservedTcResource[i],
335            prQM->au4CurrentTcResource[i],
336            prQM->au4GuaranteedTcResource[i]));
337
338      }
339
340
341     for(i = 0; i<NUM_OF_PER_STA_TX_QUEUES; i++) {
342         DBGLOG(SW4, INFO,( "TC %u HeadStaIdx %u ForwardCount %u\n",i, prQM->au4HeadStaRecIndex[i],prQM->au4ForwardCount[i]));
343     }
344
345       DBGLOG(SW4, INFO,( "BMC or unknown TxQueue Len %u\n",prQM->arTxQueue[0].u4NumElem));
346       DBGLOG(SW4, INFO,( "Pending %d\n",prGlueInfo->i4TxPendingFrameNum));
347       DBGLOG(SW4, INFO,( "Pending Security %d\n",prGlueInfo->i4TxPendingSecurityFrameNum));
348 #if defined(LINUX)
349    for(i=0;i<4;i++){
350        for(j=0;j<CFG_MAX_TXQ_NUM;j++){
351           DBGLOG(SW4, INFO,( "Pending Q[%u][%u] %d\n",i,j,prGlueInfo->ai4TxPendingFrameNumPerQueue[i][j]));
352         }
353     }
354 #endif
355
356    DBGLOG(SW4, INFO,( " rFreeSwRfbList %u\n", prAdapter->rRxCtrl.rFreeSwRfbList.u4NumElem));
357    DBGLOG(SW4, INFO,( " rReceivedRfbList %u\n", prAdapter->rRxCtrl.rReceivedRfbList.u4NumElem));
358    DBGLOG(SW4, INFO,( " rIndicatedRfbList %u\n", prAdapter->rRxCtrl.rIndicatedRfbList.u4NumElem));
359    DBGLOG(SW4, INFO,( " ucNumIndPacket %u\n", prAdapter->rRxCtrl.ucNumIndPacket));
360    DBGLOG(SW4, INFO,( " ucNumRetainedPacket %u\n", prAdapter->rRxCtrl.ucNumRetainedPacket));
361
362
363 }
364
365
366 void dumpSTA(P_ADAPTER_T prAdapter, P_STA_RECORD_T prStaRec)
367 {
368     UINT_8 ucWTEntry;
369     UINT_32 i;
370     P_BSS_INFO_T            prBssInfo;
371
372     DEBUGFUNC("dumpSTA");
373
374     ASSERT(prStaRec);
375     ucWTEntry = prStaRec->ucWTEntry;
376
377     prBssInfo = &prAdapter->rWifiVar.arBssInfo[prStaRec->ucNetTypeIndex];
378     ASSERT(prBssInfo);
379
380     DBGLOG(SW4, INFO,("Mac address: " MACSTR " Rcpi %u" "\n", MAC2STR(prStaRec->aucMacAddr),prStaRec->ucRCPI));
381
382     DBGLOG(SW4, INFO,("Idx %u Wtbl %u Used %u State %u Bss Phy 0x%x Sta DesiredPhy 0x%x\n",
383                 prStaRec->ucIndex, ucWTEntry,
384                 prStaRec->fgIsInUse,prStaRec->ucStaState,
385                 prBssInfo->ucPhyTypeSet,
386                 prStaRec->ucDesiredPhyTypeSet));
387
388     DBGLOG(SW4, INFO,("Sta Operation 0x%x  DesiredNontHtRateSet  0x%x Mcs 0x%x u2HtCapInfo 0x%x\n",
389                 prStaRec->u2OperationalRateSet,prStaRec->u2DesiredNonHTRateSet,prStaRec->ucMcsSet, prStaRec->u2HtCapInfo));
390
391
392     for(i = 0; i<NUM_OF_PER_STA_TX_QUEUES; i++) {
393         DBGLOG(SW4, INFO,( "TC %u Queue Len %u\n",i,prStaRec->arTxQueue[i].u4NumElem));
394    }
395
396     DBGLOG(SW4, INFO, ("BmpDeliveryAC %x\n",prStaRec->ucBmpDeliveryAC));
397     DBGLOG(SW4, INFO, ("BmpTriggerAC  %x\n",prStaRec->ucBmpTriggerAC));
398     DBGLOG(SW4, INFO, ("UapsdSpSupproted  %u\n",prStaRec->fgIsUapsdSupported));
399     DBGLOG(SW4, INFO, ("IsQoS  %u\n",prStaRec->fgIsQoS));
400     DBGLOG(SW4, INFO, ("AssocId %u\n",prStaRec->u2AssocId));
401
402     DBGLOG(SW4, INFO, ("fgIsInPS %u\n",prStaRec->fgIsInPS));
403     DBGLOG(SW4, INFO, ("ucFreeQuota %u\n",prStaRec->ucFreeQuota));
404     DBGLOG(SW4, INFO, ("ucFreeQuotaForDelivery %u\n",prStaRec->ucFreeQuotaForDelivery));
405     DBGLOG(SW4, INFO, ("ucFreeQuotaForNonDelivery %u\n",prStaRec->ucFreeQuotaForNonDelivery));
406
407
408 #if 0
409     DBGLOG(SW4, INFO, ("IsQmmSup  %u\n",prStaRec->fgIsWmmSupported));
410     DBGLOG(SW4, INFO, ("IsUapsdSup  %u\n",prStaRec->fgIsUapsdSupported));
411     DBGLOG(SW4, INFO, ("AvailabaleDeliverPkts  %u\n",prStaRec->ucAvailableDeliverPkts));
412     DBGLOG(SW4, INFO, ("BmpDeliverPktsAC  %u\n",prStaRec->u4BmpDeliverPktsAC));
413     DBGLOG(SW4, INFO, ("BmpBufferAC  %u\n",prStaRec->u4BmpBufferAC));
414     DBGLOG(SW4, INFO, ("BmpNonDeliverPktsAC  %u\n",prStaRec->u4BmpNonDeliverPktsAC));
415 #endif
416
417     for(i=0;i<CFG_RX_MAX_BA_TID_NUM;i++) {
418         if(prStaRec->aprRxReorderParamRefTbl[i]){
419             DBGLOG(SW4, INFO,("RxReorder fgIsValid: %u\n",prStaRec->aprRxReorderParamRefTbl[i]->fgIsValid));
420             DBGLOG(SW4, INFO,("RxReorder Tid: %u\n",prStaRec->aprRxReorderParamRefTbl[i]->ucTid));
421             DBGLOG(SW4, INFO,("RxReorder rReOrderQue Len: %u\n", prStaRec->aprRxReorderParamRefTbl[i]->rReOrderQue.u4NumElem));
422             DBGLOG(SW4, INFO,("RxReorder WinStart: %u\n", prStaRec->aprRxReorderParamRefTbl[i]->u2WinStart));
423             DBGLOG(SW4, INFO,("RxReorder WinEnd: %u\n", prStaRec->aprRxReorderParamRefTbl[i]->u2WinEnd));
424             DBGLOG(SW4, INFO,("RxReorder WinSize: %u\n", prStaRec->aprRxReorderParamRefTbl[i]->u2WinSize));
425         }
426     }
427
428 }
429
430
431 VOID dumpBss(P_ADAPTER_T prAdapter, P_BSS_INFO_T prBssInfo)
432 {
433
434     DBGLOG(SW4, INFO, ("SSID %s\n",prBssInfo->aucSSID));
435     DBGLOG(SW4, INFO, ("OWN " MACSTR"\n",MAC2STR(prBssInfo->aucOwnMacAddr)));
436     DBGLOG(SW4, INFO, ("BSSID " MACSTR"\n",MAC2STR(prBssInfo->aucBSSID)));
437     DBGLOG(SW4, INFO, ("ucNetTypeIndex %u\n",prBssInfo->ucNetTypeIndex));
438     DBGLOG(SW4, INFO, ("eConnectionState %u\n",prBssInfo->eConnectionState));
439     DBGLOG(SW4, INFO, ("eCurrentOPMode %u\n",prBssInfo->eCurrentOPMode));
440     DBGLOG(SW4, INFO, ("fgIsQBSS %u\n",prBssInfo->fgIsQBSS));
441     DBGLOG(SW4, INFO, ("fgIsShortPreambleAllowed %u\n",prBssInfo->fgIsShortPreambleAllowed));
442     DBGLOG(SW4, INFO, ("fgUseShortPreamble %u\n",prBssInfo->fgUseShortPreamble));
443     DBGLOG(SW4, INFO, ("fgUseShortSlotTime %u\n",prBssInfo->fgUseShortSlotTime));
444     DBGLOG(SW4, INFO, ("ucNonHTBasicPhyType %x\n",prBssInfo->ucNonHTBasicPhyType));
445     DBGLOG(SW4, INFO, ("u2OperationalRateSet %x\n",prBssInfo->u2OperationalRateSet));
446     DBGLOG(SW4, INFO, ("u2BSSBasicRateSet %x\n",prBssInfo->u2BSSBasicRateSet));
447     DBGLOG(SW4, INFO, ("ucPhyTypeSet %x\n",prBssInfo->ucPhyTypeSet));
448     DBGLOG(SW4, INFO, ("rStaRecOfClientList %d\n",prBssInfo->rStaRecOfClientList.u4NumElem));
449     DBGLOG(SW4, INFO, ("u2CapInfo %x\n",prBssInfo->u2CapInfo));
450     DBGLOG(SW4, INFO, ("u2ATIMWindow %x\n",prBssInfo->u2ATIMWindow));
451     DBGLOG(SW4, INFO, ("u2AssocId %x\n",prBssInfo->u2AssocId));
452     DBGLOG(SW4, INFO, ("ucDTIMPeriod %x\n",prBssInfo->ucDTIMPeriod));
453     DBGLOG(SW4, INFO, ("ucDTIMCount %x\n",prBssInfo->ucDTIMCount));
454     DBGLOG(SW4, INFO, ("fgIsNetAbsent %x\n", prBssInfo->fgIsNetAbsent));
455     DBGLOG(SW4, INFO, ("eBand %d\n", prBssInfo->eBand));
456     DBGLOG(SW4, INFO, ("ucPrimaryChannel %d\n", prBssInfo->ucPrimaryChannel));
457     DBGLOG(SW4, INFO, ("ucHtOpInfo1 %d\n", prBssInfo->ucHtOpInfo1));
458     DBGLOG(SW4, INFO, ("ucHtOpInfo2 %d\n", prBssInfo->u2HtOpInfo2));
459     DBGLOG(SW4, INFO, ("ucHtOpInfo3 %d\n", prBssInfo->u2HtOpInfo3));
460     DBGLOG(SW4, INFO, ("fgErpProtectMode %d\n", prBssInfo->fgErpProtectMode));
461     DBGLOG(SW4, INFO, ("eHtProtectMode %d\n", prBssInfo->eHtProtectMode));
462     DBGLOG(SW4, INFO, ("eGfOperationMode %d\n", prBssInfo->eGfOperationMode));
463     DBGLOG(SW4, INFO, ("eRifsOperationMode %d\n", prBssInfo->eRifsOperationMode));
464     DBGLOG(SW4, INFO, ("fgObssErpProtectMode %d\n", prBssInfo->fgObssErpProtectMode));
465     DBGLOG(SW4, INFO, ("eObssHtProtectMode %d\n", prBssInfo->eObssHtProtectMode));
466     DBGLOG(SW4, INFO, ("eObssGfProtectMode %d\n", prBssInfo->eObssGfOperationMode));
467     DBGLOG(SW4, INFO, ("fgObssRifsOperationMode %d\n", prBssInfo->fgObssRifsOperationMode));
468     DBGLOG(SW4, INFO, ("fgAssoc40mBwAllowed %d\n", prBssInfo->fgAssoc40mBwAllowed));
469     DBGLOG(SW4, INFO, ("fg40mBwAllowed %d\n", prBssInfo->fg40mBwAllowed));
470     DBGLOG(SW4, INFO, ("eBssSCO %d\n", prBssInfo->eBssSCO));
471
472
473 }
474
475
476
477 VOID swCtrlCmdCategory0(P_ADAPTER_T prAdapter, UINT_8 ucCate, UINT_8 ucAction, UINT_8 ucOpt0,UINT_8 ucOpt1)
478 {
479     UINT_8 ucIndex,ucRead;
480     UINT_32 i;
481
482     DEBUGFUNC("swCtrlCmdCategory0");
483
484     SWCR_GET_RW_INDEX(ucAction,ucRead,ucIndex);
485
486     i=0;
487
488     if(ucIndex>=SWCTRL_CATA0_INDEX_NUM) return;
489
490     if(ucRead == SWCR_WRITE) {
491         switch(ucIndex) {
492             case SWCTRL_DEBUG:
493 #if DBG
494                 aucDebugModule[ucOpt0] = (UINT_8)g_au4SwCr[1];
495 #endif
496                 break;
497             case SWCTRL_WIFI_VAR:
498                break;
499
500 #if QM_DEBUG_COUNTER
501            case SWCTRL_DUMP_QM_DBG_CNT:
502                 for(i=0;i<QM_DBG_CNT_NUM;i++) {
503                     prAdapter->rQM.au4QmDebugCounters[i] = 0;
504                 }
505                 break;
506            case SWCTRL_QM_DBG_CNT:
507                 prAdapter->rQM.au4QmDebugCounters[ucOpt0] = g_au4SwCr[1];
508
509                break;
510 #endif
511 #if CFG_RX_PKTS_DUMP
512            case SWCTRL_RX_PKTS_DUMP:
513                    //DBGLOG(SW4, INFO,("SWCTRL_RX_PKTS_DUMP: mask %x\n", g_au4SwCr[1]));
514                    prAdapter->rRxCtrl.u4RxPktsDumpTypeMask = g_au4SwCr[1];
515                    break;
516 #endif
517             default:
518                 break;
519         }
520     }
521     else {
522         switch(ucIndex) {
523             case SWCTRL_DEBUG:
524 #if DBG
525                 g_au4SwCr[1] = aucDebugModule[ucOpt0] ;
526 #endif
527                 break;
528             case SWCTRL_MAGIC:
529                 g_au4SwCr[1] = _SWCTRL_MAGIC ;
530                 DBGLOG(SW4, INFO,("BUILD TIME: %s %s\n", __DATE__, __TIME__));
531                 break;
532             case SWCTRL_QM_INFO:
533                     {
534                         P_QUE_MGT_T prQM = &prAdapter->rQM;
535                         switch(ucOpt0) {
536                             case 0:
537                                g_au4SwCr[1] = (QM_GET_TX_QUEUE_LEN(prAdapter, ucOpt1)) ;
538                                g_au4SwCr[2] = prQM->au4MinReservedTcResource[ucOpt1] ;
539                                g_au4SwCr[3] = prQM->au4CurrentTcResource[ucOpt1];
540                                g_au4SwCr[4] = prQM->au4GuaranteedTcResource[ucOpt1];
541                                 break;
542
543                             case 1:
544                                 g_au4SwCr[1] = prQM->au4ForwardCount[ucOpt1];
545                                 g_au4SwCr[2] = prQM->au4HeadStaRecIndex[ucOpt1];
546                                 break;
547
548                             case 2:
549                                 g_au4SwCr[1] = prQM->arTxQueue[ucOpt1].u4NumElem; /* only one */
550
551
552                                 break;
553                         }
554
555                     }
556             case SWCTRL_TX_CTRL_INFO:
557                     {
558                         P_TX_CTRL_T prTxCtrl;
559                         prTxCtrl = &prAdapter->rTxCtrl;
560                         switch(ucOpt0) {
561                                case 0:
562                                     g_au4SwCr[1] =  prAdapter->rTxCtrl.rTc.aucFreeBufferCount[ucOpt1];
563                                     g_au4SwCr[2] =  prAdapter->rTxCtrl.rTc.aucMaxNumOfBuffer[ucOpt1];
564                                     break;
565                         }
566
567                     }
568                     break;
569            case SWCTRL_DUMP_QUEUE:
570                     dumpQueue(prAdapter);
571
572                     break;
573 #if QM_DEBUG_COUNTER
574            case SWCTRL_DUMP_QM_DBG_CNT:
575                     for(i=0;i<QM_DBG_CNT_NUM;i++) {
576                         DBGLOG(SW4, INFO,("QM:DBG %u %u\n",i , prAdapter->rQM.au4QmDebugCounters[i]));
577                     }
578                     break;
579
580            case SWCTRL_QM_DBG_CNT:
581                     g_au4SwCr[1] = prAdapter->rQM.au4QmDebugCounters[ucOpt0];
582                     break;
583 #endif
584             case SWCTRL_DUMP_BSS:
585                     {
586                         dumpBss(prAdapter, &(prAdapter->rWifiVar.arBssInfo[ucOpt0])) ;
587                     }
588                     break;
589
590             default:
591                     break;
592         }
593
594     }
595 }
596
597
598 VOID swCtrlCmdCategory1(P_ADAPTER_T prAdapter, UINT_8 ucCate, UINT_8 ucAction, UINT_8 ucOpt0,UINT_8 ucOpt1)
599 {
600     UINT_8 ucIndex,ucRead;
601     UINT_8 ucWTEntry;
602     P_STA_RECORD_T prStaRec;
603
604     DEBUGFUNC("swCtrlCmdCategory1");
605
606     SWCR_GET_RW_INDEX(ucAction,ucRead,ucIndex);
607
608     if(ucOpt0>=CFG_STA_REC_NUM) return;
609
610     //prStaRec = cnmGetStaRecByIndex (prAdapter, ucOpt0);
611     prStaRec = &prAdapter->arStaRec[ucOpt0];
612     ucWTEntry =  prStaRec->ucWTEntry;
613     if(ucRead == SWCR_WRITE) {
614     }
615     else {
616         /* Read */
617         switch(ucIndex) {
618             case SWCTRL_STA_QUE_INFO:
619                 {
620                     g_au4SwCr[1] = prStaRec->arTxQueue[ucOpt1].u4NumElem;
621                 }
622                 break;
623             case SWCTRL_STA_INFO:
624                 switch(ucOpt1) {
625                     case 0:
626                         g_au4SwCr[1] = prStaRec->fgIsInPS;
627                         break;
628                 }
629
630                 break;
631
632              case SWCTRL_DUMP_STA:
633                  {
634                      dumpSTA(prAdapter, prStaRec);
635                  }
636                  break;
637
638              default:
639
640                  break;
641         }
642     }
643
644
645 }
646
647 #if TEST_PS
648
649 VOID
650 testPsSendQoSNullFrame (
651     IN P_ADAPTER_T prAdapter,
652     IN P_STA_RECORD_T prStaRec,
653     IN UINT_8           ucUP,
654     IN UINT_8           ucNetTypeIndex,
655     IN BOOLEAN          fgBMC,
656     IN BOOLEAN          fgIsBurstEnd,
657     IN BOOLEAN          ucPacketType,
658     IN BOOLEAN          ucPsSessionID,
659     IN BOOLEAN          fgSetEOSP
660     )
661 {
662     P_MSDU_INFO_T prMsduInfo;
663     UINT_16 u2EstimatedFrameLen;
664     P_WLAN_MAC_HEADER_QOS_T prQoSNullFrame;
665
666
667     DEBUGFUNC("testPsSendQoSNullFrame");
668     DBGLOG(SW4, LOUD, ("\n"));
669
670     //4 <1> Allocate a PKT_INFO_T for Null Frame
671     /* Init with MGMT Header Length */
672     u2EstimatedFrameLen = MAC_TX_RESERVED_FIELD + \
673                           WLAN_MAC_HEADER_QOS_LEN;
674
675     /* Allocate a MSDU_INFO_T */
676     if ( (prMsduInfo = cnmMgtPktAlloc(prAdapter, u2EstimatedFrameLen)) == NULL) {
677         DBGLOG(SW4, WARN, ("No PKT_INFO_T for sending Null Frame.\n"));
678         return ;
679     }
680
681     //4 <2> Compose Null frame in MSDU_INfO_T.
682     bssComposeQoSNullFrame(prAdapter,
683             (PUINT_8)((UINT_32)(prMsduInfo->prPacket) + MAC_TX_RESERVED_FIELD),
684             prStaRec,
685             ucUP,
686             fgSetEOSP);
687
688
689     prMsduInfo->eSrc = TX_PACKET_MGMT;
690     //prMsduInfo->ucPacketType = HIF_TX_PACKET_TYPE_DATA;
691     prMsduInfo->ucPacketType = ucPacketType;
692     prMsduInfo->ucStaRecIndex = prStaRec->ucIndex;
693     prMsduInfo->ucNetworkType = ucNetTypeIndex;
694     prMsduInfo->ucMacHeaderLength = WLAN_MAC_HEADER_QOS_LEN;
695     prMsduInfo->fgIs802_1x = FALSE;
696     prMsduInfo->fgIs802_11 = TRUE;
697     prMsduInfo->u2FrameLength = WLAN_MAC_HEADER_QOS_LEN;
698     prMsduInfo->ucTxSeqNum = nicIncreaseTxSeqNum(prAdapter);
699     prMsduInfo->pfTxDoneHandler = NULL;
700     prMsduInfo->fgIsBasicRate = TRUE;
701     prMsduInfo->fgIsBurstEnd = fgIsBurstEnd;
702     prMsduInfo->ucUserPriority = ucUP;
703     prMsduInfo->ucPsSessionID = ucPsSessionID  /* 0~7 Test 7 means NOACK*/;
704
705     prQoSNullFrame = (P_WLAN_MAC_HEADER_QOS_T)(  (PUINT_8)((UINT_32)(prMsduInfo->prPacket) + MAC_TX_RESERVED_FIELD)   );
706
707     if(fgBMC) {
708         prQoSNullFrame->aucAddr1[0] = 0xfd;
709     }
710     else {
711         prQoSNullFrame->aucAddr1[5] = 0xdd;
712     }
713
714     //4 <4> Inform TXM  to send this Null frame.
715     nicTxEnqueueMsdu(prAdapter, prMsduInfo);
716
717 }
718
719
720
721 VOID
722 testPsSetupBss(
723     IN P_ADAPTER_T prAdapter,
724     IN UINT_8 ucNetworkTypeIndex
725     )
726 {
727     P_BSS_INFO_T prBssInfo;
728     UINT_8 _aucZeroMacAddr[] = NULL_MAC_ADDR;
729
730     DEBUGFUNC("testPsSetupBss()");
731     DBGLOG(SW4, INFO, ("index %d\n", ucNetworkTypeIndex));
732
733     prBssInfo = &(prAdapter->rWifiVar.arBssInfo[ucNetworkTypeIndex]);
734
735     //4 <1.2> Initiate PWR STATE
736     //SET_NET_PWR_STATE_IDLE(prAdapter, ucNetworkTypeIndex);
737
738
739     //4 <2> Initiate BSS_INFO_T - common part
740     BSS_INFO_INIT(prAdapter, ucNetworkTypeIndex);
741
742     prBssInfo->eConnectionState = PARAM_MEDIA_STATE_DISCONNECTED;
743     prBssInfo->eConnectionStateIndicated = PARAM_MEDIA_STATE_DISCONNECTED;
744     prBssInfo->eCurrentOPMode = OP_MODE_ACCESS_POINT;
745     prBssInfo->fgIsNetActive = TRUE;
746     prBssInfo->ucNetTypeIndex = (ucNetworkTypeIndex);
747     prBssInfo->ucReasonOfDisconnect = DISCONNECT_REASON_CODE_RESERVED;
748
749     prBssInfo->ucPhyTypeSet = PHY_TYPE_SET_802_11BG; /* Depend on eBand */
750     prBssInfo->ucConfigAdHocAPMode = AP_MODE_MIXED_11BG; /* Depend on eCurrentOPMode and ucPhyTypeSet */
751     prBssInfo->u2BSSBasicRateSet = RATE_SET_ERP;
752     prBssInfo->u2OperationalRateSet = RATE_SET_OFDM;
753     prBssInfo->fgErpProtectMode = FALSE;
754     prBssInfo->fgIsQBSS = TRUE;
755
756     //4 <1.5> Setup MIB for current BSS
757     prBssInfo->u2BeaconInterval = 100;
758     prBssInfo->ucDTIMPeriod = DOT11_DTIM_PERIOD_DEFAULT;
759     prBssInfo->u2ATIMWindow = 0;
760
761     prBssInfo->ucBeaconTimeoutCount = 0;
762
763
764     bssInitForAP (prAdapter,prBssInfo, TRUE);
765
766     COPY_MAC_ADDR(prBssInfo->aucBSSID, _aucZeroMacAddr);
767     LINK_INITIALIZE(&prBssInfo->rStaRecOfClientList);
768     prBssInfo->fgIsBeaconActivated = TRUE;
769     prBssInfo->ucHwDefaultFixedRateCode = RATE_CCK_1M_LONG;
770
771
772     COPY_MAC_ADDR(prBssInfo->aucOwnMacAddr, prAdapter->rWifiVar.aucMacAddress);
773
774     //4 <3> Initiate BSS_INFO_T - private part
775     /* TODO */
776     prBssInfo->eBand = BAND_2G4;
777     prBssInfo->ucPrimaryChannel = 1;
778     prBssInfo->prStaRecOfAP = (P_STA_RECORD_T)NULL;
779
780
781     //prBssInfo->fgErpProtectMode =  eErpProectMode;
782     //prBssInfo->eHtProtectMode = eHtProtectMode;
783     //prBssInfo->eGfOperationMode = eGfOperationMode;
784
785
786     //4 <4> Allocate MSDU_INFO_T for Beacon
787     prBssInfo->prBeacon = cnmMgtPktAlloc(prAdapter,
788             OFFSET_OF(WLAN_BEACON_FRAME_T, aucInfoElem[0]) + MAX_IE_LENGTH);
789
790     if (prBssInfo->prBeacon) {
791         prBssInfo->prBeacon->eSrc = TX_PACKET_MGMT;
792         prBssInfo->prBeacon->ucNetworkType = ucNetworkTypeIndex;
793     }
794     else {
795         DBGLOG(SW4, INFO, ("prBeacon allocation fail\n"));
796     }
797
798 #if 0
799     prBssInfo->rPmProfSetupInfo.ucBmpDeliveryAC = PM_UAPSD_ALL;
800     prBssInfo->rPmProfSetupInfo.ucBmpTriggerAC = PM_UAPSD_ALL;
801     prBssInfo->rPmProfSetupInfo.ucUapsdSp = WMM_MAX_SP_LENGTH_2;
802 #else
803     prBssInfo->rPmProfSetupInfo.ucBmpDeliveryAC = (UINT_8)prAdapter->u4UapsdAcBmp;
804     prBssInfo->rPmProfSetupInfo.ucBmpTriggerAC =(UINT_8) prAdapter->u4UapsdAcBmp;
805     prBssInfo->rPmProfSetupInfo.ucUapsdSp = (UINT_8)prAdapter->u4MaxSpLen;
806 #endif
807
808 #if 0
809     for(eAci = 0; eAci < WMM_AC_INDEX_NUM; eAci++){
810
811         prBssInfo->arACQueParms[eAci].fgIsACMSet = FALSE;
812         prBssInfo->arACQueParms[eAci].u2Aifsn = (UINT_16) eAci;
813         prBssInfo->arACQueParms[eAci].u2CWmin = 7;
814         prBssInfo->arACQueParms[eAci].u2CWmax = 31;
815         prBssInfo->arACQueParms[eAci].u2TxopLimit = eAci+1;
816         DBGLOG(SW4, INFO, ("MQM: eAci = %d, ACM = %d, Aifsn = %d, CWmin = %d, CWmax = %d, TxopLimit = %d\n",
817                    eAci,prBssInfo->arACQueParms[eAci].fgIsACMSet ,
818                    prBssInfo->arACQueParms[eAci].u2Aifsn,
819                    prBssInfo->arACQueParms[eAci].u2CWmin,
820                    prBssInfo->arACQueParms[eAci].u2CWmax,
821                    prBssInfo->arACQueParms[eAci].u2TxopLimit));
822
823     }
824 #endif
825
826
827     DBGLOG(SW4, INFO, ("[2] ucBmpDeliveryAC:0x%x, ucBmpTriggerAC:0x%x, ucUapsdSp:0x%x",
828             prBssInfo->rPmProfSetupInfo.ucBmpDeliveryAC,
829             prBssInfo->rPmProfSetupInfo.ucBmpTriggerAC,
830             prBssInfo->rPmProfSetupInfo.ucUapsdSp));
831
832     return;
833 }
834
835
836
837
838 VOID testPsCmdCategory0(P_ADAPTER_T prAdapter, UINT_8 ucCate, UINT_8 ucAction, UINT_8 ucOpt0,UINT_8 ucOpt1)
839 {
840     UINT_8 ucIndex,ucRead;
841     P_STA_RECORD_T prStaRec;
842
843     DEBUGFUNC("testPsCmdCategory0");
844     SWCR_GET_RW_INDEX(ucAction,ucRead,ucIndex);
845
846     DBGLOG(SW4, LOUD, ("Read %u Index %u\n",ucRead,ucIndex));
847
848     prStaRec = cnmGetStaRecByIndex (prAdapter, 0);
849
850     if(ucIndex>=TEST_PS_CATA0_INDEX_NUM) return;
851
852     if(ucRead == SWCR_WRITE) {
853         switch(ucIndex) {
854             case TEST_PS_SETUP_BSS:
855                 testPsSetupBss(prAdapter, ucOpt0) ;
856                 break;
857
858             case TEST_PS_ENABLE_BEACON:
859                break;
860
861             case TEST_PS_TRIGGER_BMC:
862                 //txmForwardQueuedBmcPkts (ucOpt0);
863                 break;
864             case TEST_PS_SEND_NULL:
865                 {
866
867                     testPsSendQoSNullFrame (prAdapter,prStaRec,
868                             (UINT_8)(g_au4SwCr[1] & 0xFF), /* UP */
869                             ucOpt0,
870                             (BOOLEAN)((g_au4SwCr[1] >>8)& 0xFF), /* BMC*/
871                             (BOOLEAN)((g_au4SwCr[1] >>16)& 0xFF), /* BurstEnd*/
872                             (BOOLEAN)((g_au4SwCr[1] >>24)& 0xFF), /* Packet type*/
873                             (UINT_8)((g_au4SwCr[2] )& 0xFF), /* PS sesson ID 7: NOACK */
874                             FALSE                                  /* EOSP */
875                         );
876                 }
877                     break;
878             case TEST_PS_BUFFER_BMC:
879                 //g_aprBssInfo[ucOpt0]->fgApToBufferBMC = (g_au4SwCr[1] & 0xFF);
880                 break;
881             case TEST_PS_UPDATE_BEACON:
882                 bssUpdateBeaconContent(prAdapter, ucOpt0 /*networktype*/ );
883                 break;
884
885            default:
886                 break;
887         }
888     }
889     else {
890         switch(ucIndex) {
891
892             case TEST_PS_MAGIC:
893                 g_au4SwCr[1] = 0x88660011 ;
894                 break;
895
896         }
897     }
898 }
899
900 #endif //TEST_PS
901
902 #if TEST_PS
903
904 VOID testPsCmdCategory1(P_ADAPTER_T prAdapter, UINT_8 ucCate, UINT_8 ucAction, UINT_8 ucOpt0,UINT_8 ucOpt1)
905 {
906     UINT_8 ucIndex,ucRead;
907     UINT_8 ucWTEntry;
908     P_STA_RECORD_T prStaRec;
909
910     DEBUGFUNC("testPsCmdCategory1");
911
912     SWCR_GET_RW_INDEX(ucAction,ucRead,ucIndex);
913
914     if(ucOpt0>=CFG_STA_REC_NUM) return;
915
916     prStaRec = cnmGetStaRecByIndex (prAdapter, ucOpt0);
917     ucWTEntry =  prStaRec->ucWTEntry;
918     if(ucRead == SWCR_WRITE) {
919
920         switch(ucIndex) {
921             case TEST_PS_STA_PS:
922                 prStaRec->fgIsInPS = (BOOLEAN) (g_au4SwCr[1] & 0x1);
923                 prStaRec->fgIsQoS = (BOOLEAN) (g_au4SwCr[1] >>8 & 0xFF);
924                 prStaRec->fgIsUapsdSupported = (BOOLEAN) (g_au4SwCr[1] >>16 & 0xFF);
925                 prStaRec->ucBmpDeliveryAC = (BOOLEAN) (g_au4SwCr[1] >>24 & 0xFF);
926                 break;
927
928         }
929
930     }
931     else {
932         /* Read */
933         switch(ucIndex) {
934             default:
935                 break;
936         }
937     }
938
939
940 }
941
942 #endif //TEST_PS
943
944 #if CFG_SUPPORT_802_11V
945 #if (CFG_SUPPORT_802_11V_TIMING_MEASUREMENT ==1) && (WNM_UNIT_TEST ==1)
946 VOID testWNMCmdCategory0(P_ADAPTER_T prAdapter, UINT_8 ucCate, UINT_8 ucAction, UINT_8 ucOpt0,UINT_8 ucOpt1)
947 {
948     UINT_8 ucIndex,ucRead;
949     P_STA_RECORD_T prStaRec;
950
951     DEBUGFUNC("testWNMCmdCategory0");
952     SWCR_GET_RW_INDEX(ucAction,ucRead,ucIndex);
953
954     DBGLOG(SW4, INFO, ("Read %u Index %u\n",ucRead,ucIndex));
955
956     if(ucIndex>=TEST_WNM_CATA0_INDEX_NUM) return;
957
958     if(ucRead == SWCR_WRITE) {
959         switch(ucIndex) {
960             case TEST_WNM_TIMING_MEAS:
961                 wnmTimingMeasUnitTest1(prAdapter, ucOpt0) ;
962                 break;
963
964            default:
965                 break;
966         }
967     }
968 }
969 #endif //TEST_WNM
970 #endif //CFG_SUPPORT_802_11V
971
972 VOID swCtrlSwCr(P_ADAPTER_T prAdapter, UINT_8 ucRead, UINT_16 u2Addr, UINT_32 *pu4Data)
973 {
974     /* According other register STAIDX */
975     UINT_8      ucOffset;
976     ucOffset = (u2Addr>>2) & 0x3F;
977
978     if(ucOffset>= SWCR_CR_NUM) return;
979
980     if(ucRead==SWCR_WRITE) {
981         g_au4SwCr[ucOffset] = *pu4Data;
982         if(ucOffset==0x0) {
983             /* Commmand   [31:24]: Category */
984             /* Commmand   [23:23]: 1(W) 0(R) */
985             /* Commmand   [22:16]: Index */
986             /* Commmand   [15:08]: Option0  */
987             /* Commmand   [07:00]: Option1   */
988             UINT_8 ucCate;
989             UINT_32 u4Cmd;
990             u4Cmd = g_au4SwCr[0];
991             ucCate = (UINT_8)(u4Cmd >> 24) ;
992             if(ucCate < sizeof(g_arSwCtrlCmd)/sizeof(g_arSwCtrlCmd[0])) {
993                 if(g_arSwCtrlCmd[ucCate]!=NULL) {
994                     g_arSwCtrlCmd[ucCate](prAdapter, ucCate, (UINT_8)(u4Cmd>>16 & 0xFF),(UINT_8)((u4Cmd>>8) & 0xFF), (UINT_8)(u4Cmd&0xFF));
995                 }
996             }
997         }
998     }
999     else {
1000         *pu4Data = g_au4SwCr[ucOffset];
1001     }
1002 }
1003
1004 VOID swCrReadWriteCmd(P_ADAPTER_T prAdapter, UINT_8 ucRead, UINT_16 u2Addr, UINT_32 *pu4Data)
1005 {
1006     UINT_8 ucMod;
1007
1008     ucMod =  u2Addr >>8;
1009     /* Address [15:8] MOD ID */
1010     /* Address [7:0] OFFSET */
1011
1012     DEBUGFUNC("swCrReadWriteCmd");
1013     DBGLOG(SW4, INFO, ("%u addr 0x%x data 0x%x\n",ucRead,u2Addr,*pu4Data));
1014
1015     if(ucMod < (sizeof(g_arSwCrModHandle)/sizeof(g_arSwCrModHandle[0])) ) {
1016
1017         if(g_arSwCrModHandle[ucMod]!=NULL) {
1018          g_arSwCrModHandle[ucMod](prAdapter, ucRead, u2Addr, pu4Data);
1019         }
1020    } /* ucMod */
1021 }
1022
1023 /* Debug Support */
1024 VOID swCrFrameCheckEnable(P_ADAPTER_T  prAdapter, UINT_32 u4DumpType)
1025 {
1026           g_u4SwcrDebugFrameDumpType = u4DumpType;
1027           prAdapter->rRxCtrl.u4RxPktsDumpTypeMask = u4DumpType;   
1028 }
1029
1030 VOID swCrDebugInit(P_ADAPTER_T  prAdapter)
1031 {
1032           // frame dump
1033     if (g_u4SwcrDebugFrameDumpType) {
1034           swCrFrameCheckEnable(prAdapter, g_u4SwcrDebugFrameDumpType);
1035     }
1036
1037     // debug counter
1038     g_fgSwcrDebugTimer = FALSE;
1039
1040     cnmTimerInitTimer(prAdapter,
1041                       &g_rSwcrDebugTimer,
1042                       (PFN_MGMT_TIMEOUT_FUNC)swCrDebugCheckTimeout,
1043                       (UINT_32) NULL);
1044     
1045     if (g_u4SwcrDebugCheckTimeout) {
1046           swCrDebugCheckEnable(prAdapter, TRUE, g_ucSwcrDebugCheckType, g_u4SwcrDebugCheckTimeout);
1047     }        
1048 }
1049
1050 VOID swCrDebugUninit(P_ADAPTER_T  prAdapter)
1051 {
1052           cnmTimerStopTimer(prAdapter, &g_rSwcrDebugTimer);       
1053           
1054           g_fgSwcrDebugTimer = FALSE;
1055 }
1056
1057 VOID swCrDebugCheckEnable(P_ADAPTER_T  prAdapter, BOOLEAN fgIsEnable, UINT_8 ucType, UINT_32 u4Timeout)
1058 {
1059           if (fgIsEnable) {
1060                   g_ucSwcrDebugCheckType = ucType;
1061                   g_u4SwcrDebugCheckTimeout = u4Timeout;
1062                   if (g_fgSwcrDebugTimer == FALSE) {                                  
1063                       swCrDebugCheckTimeout(prAdapter, 0);
1064                   }
1065           }
1066           else {
1067                   cnmTimerStopTimer(prAdapter, &g_rSwcrDebugTimer);
1068                   g_u4SwcrDebugCheckTimeout = 0;
1069           }
1070           
1071           g_fgSwcrDebugTimer = fgIsEnable;
1072 }
1073
1074 VOID swCrDebugCheck(P_ADAPTER_T  prAdapter, P_CMD_SW_DBG_CTRL_T prCmdSwCtrl)
1075 {
1076     P_RX_CTRL_T prRxCtrl;
1077     P_TX_CTRL_T prTxCtrl;
1078
1079     ASSERT(prAdapter);
1080
1081     prTxCtrl = &prAdapter->rTxCtrl;
1082     prRxCtrl = &prAdapter->rRxCtrl;
1083
1084     // dump counters
1085     if (prCmdSwCtrl) {
1086           if (prCmdSwCtrl->u4Data == SWCR_DBG_TYPE_ALL) {
1087
1088             // TX Counter from fw
1089             DBGLOG(SW4, INFO,  ("TX0\n" \
1090                                "%08x %08x %08x %08x\n" \
1091                                "%08x %08x %08x %08x\n",
1092                                prCmdSwCtrl->u4DebugCnt[SWCR_DBG_ALL_TX_CNT],
1093                                prCmdSwCtrl->u4DebugCnt[SWCR_DBG_ALL_TX_BCN_CNT],
1094                                prCmdSwCtrl->u4DebugCnt[SWCR_DBG_ALL_TX_FAILED_CNT],
1095                                prCmdSwCtrl->u4DebugCnt[SWCR_DBG_ALL_TX_RETRY_CNT],
1096                                prCmdSwCtrl->u4DebugCnt[SWCR_DBG_ALL_TX_AGING_TIMEOUT_CNT],
1097                                prCmdSwCtrl->u4DebugCnt[SWCR_DBG_ALL_TX_PS_OVERFLOW_CNT],
1098                                prCmdSwCtrl->u4DebugCnt[SWCR_DBG_ALL_TX_MGNT_DROP_CNT],
1099                                prCmdSwCtrl->u4DebugCnt[SWCR_DBG_ALL_TX_ERROR_CNT]));
1100 #if 1
1101             // TX Counter from drv
1102             DBGLOG(SW4, INFO,  ("TX1\n" \
1103                                "%08x %08x %08x %08x\n",
1104                                (UINT_32)TX_GET_CNT(prTxCtrl, TX_INACTIVE_BSS_DROP),
1105                                (UINT_32)TX_GET_CNT(prTxCtrl, TX_INACTIVE_STA_DROP),
1106                                (UINT_32)TX_GET_CNT(prTxCtrl, TX_FORWARD_OVERFLOW_DROP),
1107                                (UINT_32)TX_GET_CNT(prTxCtrl, TX_AP_BORADCAST_DROP)));
1108 #endif
1109
1110             // RX Counter
1111             DBGLOG(SW4, INFO,  ("RX0\n" \
1112                                "%08x %08x %08x %08x\n" \
1113                                "%08x %08x %08x %08x\n" \
1114                                "%08x %08x %08x %08x\n" \
1115                                "%08x %08x %08x %08x\n",
1116                                prCmdSwCtrl->u4DebugCnt[SWCR_DBG_ALL_RX_CNT],
1117                                prCmdSwCtrl->u4DebugCnt[SWCR_DBG_ALL_RX_DROP_CNT],
1118                                prCmdSwCtrl->u4DebugCnt[SWCR_DBG_ALL_RX_DUP_DROP_CNT],
1119                                prCmdSwCtrl->u4DebugCnt[SWCR_DBG_ALL_RX_TYPE_ERROR_DROP_CNT],
1120                                prCmdSwCtrl->u4DebugCnt[SWCR_DBG_ALL_RX_CLASS_ERROR_DROP_CNT],
1121                                prCmdSwCtrl->u4DebugCnt[SWCR_DBG_ALL_RX_AMPDU_ERROR_DROP_CNT],
1122                                prCmdSwCtrl->u4DebugCnt[SWCR_DBG_ALL_RX_STATUS_ERROR_DROP_CNT],
1123                                prCmdSwCtrl->u4DebugCnt[SWCR_DBG_ALL_RX_FORMAT_ERROR_DROP_CNT],
1124                                prCmdSwCtrl->u4DebugCnt[SWCR_DBG_ALL_RX_ICV_ERROR_DROP_CNT],
1125                                prCmdSwCtrl->u4DebugCnt[SWCR_DBG_ALL_RX_KEY_ERROR_DROP_CNT],
1126                                prCmdSwCtrl->u4DebugCnt[SWCR_DBG_ALL_RX_TKIP_ERROR_DROP_CNT],
1127                                prCmdSwCtrl->u4DebugCnt[SWCR_DBG_ALL_RX_MIC_ERROR_DROP_CNT],
1128                                prCmdSwCtrl->u4DebugCnt[SWCR_DBG_ALL_RX_BIP_ERROR_DROP_CNT],
1129                                prCmdSwCtrl->u4DebugCnt[SWCR_DBG_ALL_RX_FCSERR_CNT],
1130                                prCmdSwCtrl->u4DebugCnt[SWCR_DBG_ALL_RX_FIFOFULL_CNT],
1131                                prCmdSwCtrl->u4DebugCnt[SWCR_DBG_ALL_RX_PFDROP_CNT]));
1132
1133             DBGLOG(SW4, INFO,  ("RX1\n" \
1134                                "%08x %08x %08x %08x\n" \
1135                                "%08x %08x %08x %08x\n",
1136                                (UINT_32)RX_GET_CNT(prRxCtrl, RX_MPDU_TOTAL_COUNT),
1137                                (UINT_32)RX_GET_CNT(prRxCtrl, RX_DATA_INDICATION_COUNT),
1138                                (UINT_32)RX_GET_CNT(prRxCtrl, RX_DATA_RETURNED_COUNT),
1139                                (UINT_32)RX_GET_CNT(prRxCtrl, RX_DATA_RETAINED_COUNT),
1140                                (UINT_32)RX_GET_CNT(prRxCtrl, RX_DROP_TOTAL_COUNT),
1141                                (UINT_32)RX_GET_CNT(prRxCtrl, RX_TYPE_ERR_DROP_COUNT),
1142                                (UINT_32)RX_GET_CNT(prRxCtrl, RX_CLASS_ERR_DROP_COUNT),
1143                                (UINT_32)RX_GET_CNT(prRxCtrl, RX_DST_NULL_DROP_COUNT)));
1144
1145             DBGLOG(SW4, INFO,  ("PWR\n" \
1146                                "%08x %08x %08x %08x\n" \
1147                                "%08x %08x %08x %08x\n",
1148                                prCmdSwCtrl->u4DebugCnt[SWCR_DBG_ALL_PWR_PS_POLL_CNT],
1149                                prCmdSwCtrl->u4DebugCnt[SWCR_DBG_ALL_PWR_TRIGGER_NULL_CNT],
1150                                prCmdSwCtrl->u4DebugCnt[SWCR_DBG_ALL_PWR_BCN_IND_CNT],
1151                                prCmdSwCtrl->u4DebugCnt[SWCR_DBG_ALL_PWR_BCN_TIMEOUT_CNT],
1152                                prCmdSwCtrl->u4DebugCnt[SWCR_DBG_ALL_PWR_PM_STATE0],
1153                                prCmdSwCtrl->u4DebugCnt[SWCR_DBG_ALL_PWR_PM_STATE1],
1154                                prCmdSwCtrl->u4DebugCnt[SWCR_DBG_ALL_PWR_CUR_PS_PROF0],
1155                                prCmdSwCtrl->u4DebugCnt[SWCR_DBG_ALL_PWR_CUR_PS_PROF1]));
1156
1157             DBGLOG(SW4, INFO,  ("ARM\n" \
1158                                "%08x %08x %08x %08x\n" \
1159                                "%08x %08x\n",
1160                                prCmdSwCtrl->u4DebugCnt[SWCR_DBG_ALL_AR_STA0_RATE],
1161                                prCmdSwCtrl->u4DebugCnt[SWCR_DBG_ALL_AR_STA0_BWGI],
1162                                prCmdSwCtrl->u4DebugCnt[SWCR_DBG_ALL_AR_STA0_RX_RATE_RCPI],
1163                                prCmdSwCtrl->u4DebugCnt[SWCR_DBG_ALL_ROAMING_ENABLE],
1164                                prCmdSwCtrl->u4DebugCnt[SWCR_DBG_ALL_ROAMING_ROAM_CNT],
1165                                prCmdSwCtrl->u4DebugCnt[SWCR_DBG_ALL_ROAMING_INT_CNT]));
1166
1167             DBGLOG(SW4, INFO,  ("BB\n" \
1168                                "%08x %08x %08x %08x\n" \
1169                                "%08x %08x %08x %08x\n",
1170                                prCmdSwCtrl->u4DebugCnt[SWCR_DBG_ALL_BB_RX_MDRDY_CNT],
1171                                prCmdSwCtrl->u4DebugCnt[SWCR_DBG_ALL_BB_RX_FCSERR_CNT],
1172                                prCmdSwCtrl->u4DebugCnt[SWCR_DBG_ALL_BB_CCK_PD_CNT],
1173                                prCmdSwCtrl->u4DebugCnt[SWCR_DBG_ALL_BB_OFDM_PD_CNT],
1174                                prCmdSwCtrl->u4DebugCnt[SWCR_DBG_ALL_BB_CCK_SFDERR_CNT],
1175                                prCmdSwCtrl->u4DebugCnt[SWCR_DBG_ALL_BB_CCK_SIGERR_CNT],
1176                                prCmdSwCtrl->u4DebugCnt[SWCR_DBG_ALL_BB_OFDM_TAGERR_CNT],
1177                                prCmdSwCtrl->u4DebugCnt[SWCR_DBG_ALL_BB_OFDM_SIGERR_CNT]));
1178
1179         }
1180     }
1181
1182     // start the next check
1183           if (g_u4SwcrDebugCheckTimeout) {
1184                   cnmTimerStartTimer(prAdapter, &g_rSwcrDebugTimer, g_u4SwcrDebugCheckTimeout * MSEC_PER_SEC);
1185           }
1186 }
1187
1188 VOID swCrDebugCheckTimeout(
1189     IN P_ADAPTER_T prAdapter,
1190     UINT_32 u4Param)
1191 {
1192           CMD_SW_DBG_CTRL_T rCmdSwCtrl;
1193           WLAN_STATUS rStatus;
1194
1195     rCmdSwCtrl.u4Id = (0xb000<<16) + g_ucSwcrDebugCheckType;
1196     rCmdSwCtrl.u4Data = 0;
1197           rStatus = wlanSendSetQueryCmd (
1198                 prAdapter,                  /* prAdapter */
1199                 CMD_ID_SW_DBG_CTRL,       /* ucCID */
1200                 FALSE,                      /* fgSetQuery */
1201                 TRUE,                       /* fgNeedResp */
1202                 FALSE,                      /* fgIsOid */
1203                 swCrDebugQuery,             /* pfCmdDoneHandler */
1204                 swCrDebugQueryTimeout,      /* pfCmdTimeoutHandler */
1205                 sizeof(CMD_SW_DBG_CTRL_T),  /* u4SetQueryInfoLen */
1206                 (PUINT_8)&rCmdSwCtrl,       /* pucInfoBuffer */
1207                 NULL,                       /* pvSetQueryBuffer */
1208                 0                           /* u4SetQueryBufferLen */
1209                 );
1210
1211     ASSERT(rStatus == WLAN_STATUS_PENDING);
1212
1213     return;
1214 }
1215
1216 VOID swCrDebugQuery(
1217     IN P_ADAPTER_T  prAdapter,
1218     IN P_CMD_INFO_T prCmdInfo,
1219     IN PUINT_8      pucEventBuf
1220     )
1221 {
1222     ASSERT(prAdapter);
1223
1224     swCrDebugCheck(prAdapter, (P_CMD_SW_DBG_CTRL_T)(pucEventBuf));
1225 }
1226
1227 VOID swCrDebugQueryTimeout(
1228     IN P_ADAPTER_T  prAdapter,
1229     IN P_CMD_INFO_T prCmdInfo)
1230 {
1231           ASSERT(prAdapter);
1232
1233     swCrDebugCheck(prAdapter, NULL);
1234 }
1235
1236 #endif /* CFG_SUPPORT_SWCR */
1237
1238