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