Home | History | Annotate | Download | only in Cmd_MBox
      1 /****************************************************************************
      2 **+-----------------------------------------------------------------------+**
      3 **|                                                                       |**
      4 **| Copyright(c) 1998 - 2008 Texas Instruments. All rights reserved.      |**
      5 **| All rights reserved.                                                  |**
      6 **|                                                                       |**
      7 **| Redistribution and use in source and binary forms, with or without    |**
      8 **| modification, are permitted provided that the following conditions    |**
      9 **| are met:                                                              |**
     10 **|                                                                       |**
     11 **|  * Redistributions of source code must retain the above copyright     |**
     12 **|    notice, this list of conditions and the following disclaimer.      |**
     13 **|  * Redistributions in binary form must reproduce the above copyright  |**
     14 **|    notice, this list of conditions and the following disclaimer in    |**
     15 **|    the documentation and/or other materials provided with the         |**
     16 **|    distribution.                                                      |**
     17 **|  * Neither the name Texas Instruments nor the names of its            |**
     18 **|    contributors may be used to endorse or promote products derived    |**
     19 **|    from this software without specific prior written permission.      |**
     20 **|                                                                       |**
     21 **| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS   |**
     22 **| "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT     |**
     23 **| LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |**
     24 **| A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT  |**
     25 **| OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |**
     26 **| SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT      |**
     27 **| LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |**
     28 **| DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |**
     29 **| THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT   |**
     30 **| (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |**
     31 **| OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  |**
     32 **|                                                                       |**
     33 **+-----------------------------------------------------------------------+**
     34 ****************************************************************************/
     35 
     36 /****************************************************************************
     37  *
     38  *   MODULE:  CmdMBox.c
     39  *   PURPOSE: Handle the wlan hardware command mailbox
     40  *
     41  ****************************************************************************/
     42 #include "osTIType.h"
     43 #include "whalCommon.h"
     44 #include "TNETWIF.h"
     45 #include "whalHwDefs.h"
     46 #include "FwEvent_api.h"
     47 #include "CmdQueue_api.h"
     48 #include "CmdMBox_api.h"
     49 #include "CmdMBox.h"
     50 #include "tnetwCommon.h"
     51 #include "osApi.h"
     52 
     53 /* Check if HostIfReg is On. This function is used on SDIO only. */
     54 int CmdMbox_CheckAndAck(TI_HANDLE hTNETWIF, UINT32 Intr);
     55 
     56 #define CMDMBOX_DEBUG_PRINT 0
     57 
     58 #ifdef REPORT_LOG
     59 #define CMDMBOX_CHECK_STATUS \
     60     switch (pCmdMBox->HW_CmdMBox.cmdStatus) \
     61     { \
     62 	case CMD_STATUS_SUCCESS: \
     63 		{ \
     64 			WLAN_REPORT_INFORMATION(pCmdMBox->hReport, CMD_MBOX_MODULE_LOG, \
     65                               ("CMD_MBOX: CMD_STATUS_SUCCESS\n")); \
     66 			break; \
     67 		} \
     68 	case CMD_STATUS_REJECT_MEAS_SG_ACTIVE: \
     69 		{ \
     70 			WLAN_REPORT_INFORMATION(pCmdMBox->hReport, CMD_MBOX_MODULE_LOG, \
     71                               ("CMD_MBOX: ERROR: CMD_STATUS_REJECT_MEAS_SG_ACTIVE received\n")); \
     72             break; \
     73 		} \
     74 	case CMD_MAILBOX_IDLE: \
     75 	case CMD_STATUS_UNKNOWN_CMD: \
     76 	case CMD_STATUS_UNKNOWN_IE: \
     77     case CMD_STATUS_RX_BUSY: \
     78     case CMD_STATUS_INVALID_PARAM: \
     79     case CMD_STATUS_TEMPLATE_TOO_LARGE: \
     80     case CMD_STATUS_OUT_OF_MEMORY: \
     81     case CMD_STATUS_STA_TABLE_FULL: \
     82 	case CMD_STATUS_RADIO_ERROR: \
     83 	case CMD_STATUS_WRONG_NESTING: \
     84 		{ \
     85 			/* print the error */ \
     86             WLAN_REPORT_ERROR(pCmdMBox->hReport, CMD_MBOX_MODULE_LOG, \
     87                               ("%s: ERROR: %s (%d), command: %s (%d), IE: %s (%d)\n", \
     88                                __FUNCTION__, CmdQueue_GetErrorString(pCmdMBox->HW_CmdMBox.cmdStatus), \
     89                                pCmdMBox->HW_CmdMBox.cmdStatus, \
     90                                CmdQueue_GetCmdString(pCmdMBox->HW_CmdMBox.cmdID), \
     91                                pCmdMBox->HW_CmdMBox.cmdID, \
     92                                CmdQueue_GetIEString(pCmdMBox->HW_CmdMBox.cmdID, *(UINT16*)&(pCmdMBox->HW_CmdMBox.parameters)), \
     93                                *(UINT16*)&(pCmdMBox->HW_CmdMBox.parameters))); \
     94 			/* continue as if the command succedded */ \
     95 			pCmdMBox->HW_CmdMBox.cmdStatus = (uint16)CMD_STATUS_SUCCESS; \
     96 			break; \
     97 		} \
     98     case CMD_STATUS_TIMEOUT: \
     99 	case CMD_STATUS_FW_RESET: \
    100 	default: \
    101         /* if the FW is not responding, start recovery */ \
    102         { \
    103             CmdQueue_Error(pCmdMBox->hCmdQueue); \
    104 			break; \
    105         } \
    106 	} /* end of switch */
    107 #else
    108 #define CMDMBOX_CHECK_STATUS \
    109     switch (pCmdMBox->HW_CmdMBox.cmdStatus) \
    110     { \
    111 	case CMD_STATUS_SUCCESS: \
    112 		{ \
    113 			break; \
    114 		} \
    115 	case CMD_STATUS_REJECT_MEAS_SG_ACTIVE: \
    116 		{ \
    117             break; \
    118 		} \
    119 	case CMD_MAILBOX_IDLE: \
    120 	case CMD_STATUS_UNKNOWN_CMD: \
    121 	case CMD_STATUS_UNKNOWN_IE: \
    122     case CMD_STATUS_RX_BUSY: \
    123     case CMD_STATUS_INVALID_PARAM: \
    124     case CMD_STATUS_TEMPLATE_TOO_LARGE: \
    125     case CMD_STATUS_OUT_OF_MEMORY: \
    126     case CMD_STATUS_STA_TABLE_FULL: \
    127 	case CMD_STATUS_RADIO_ERROR: \
    128 	case CMD_STATUS_WRONG_NESTING: \
    129 		{ \
    130 			/* continue as if the command succedded */ \
    131 			pCmdMBox->HW_CmdMBox.cmdStatus = (uint16)CMD_STATUS_SUCCESS; \
    132 			break; \
    133 		} \
    134     case CMD_STATUS_TIMEOUT: \
    135 	case CMD_STATUS_FW_RESET: \
    136 	default: \
    137         /* if the FW is not responding, start recovery */ \
    138         { \
    139             CmdQueue_Error(pCmdMBox->hCmdQueue); \
    140 			break; \
    141         } \
    142 	} /* end of switch */
    143 #endif /* REPORT_LOG */
    144 
    145 
    146 #if CMDMBOX_DEBUG_PRINT
    147 static char *StateString_array[16] = {
    148     "CMDMBOX_STATE_SENDCMD_NORMAL_IDLE",  /* 0 */
    149     "CMDMBOX_STATE_SENDCMD_NORMAL_WAIT_BUS",  /* 1 */
    150     "CMDMBOX_STATE_SENDCMD_NORMAL_WAIT_TXN_BUF",  /* 2 */
    151     "CMDMBOX_STATE_SENDCMD_NORMAL_WRITE_TRIG_v",  /* 3 */
    152     "CMDMBOX_STATE_SENDCMD_NORMAL_WAIT_TXN_TRIG",  /* 4 */
    153     "CMDMBOX_STATE_SENDCMD_BLOCKING_IDLE",  /* 5 */
    154     "CMDMBOX_STATE_SENDCMD_BLOCKING_WAIT_BUS",  /* 6 */
    155     "CMDMBOX_STATE_SENDCMD_BLOCKING_WAIT_TXN_BUF",  /* 7 */
    156     "CMDMBOX_STATE_SENDCMD_BLOCKING_WRITE_TRIG_v",  /* 8 */
    157     "CMDMBOX_STATE_SENDCMD_BLOCKING_WAIT_TXN_TRIG",  /* 9 */
    158     "CMDMBOX_STATE_SENDCMD_BLOCKING_POLL_CMPLT_v",  /* 10 */
    159     "CMDMBOX_STATE_SENDCMD_BLOCKING_FINISH_v",  /* 11 */
    160     "CMDMBOX_STATE_GETRESULT_NORMAL_IDLE",  /* 12 */
    161     "CMDMBOX_STATE_GETRESULT_NORMAL_WAIT_TXN",  /* 13 */
    162     "CMDMBOX_STATE_GETRESULT_BLOCKING_IDLE",  /* 14 */
    163     "CMDMBOX_STATE_GETRESULT_BLOCKING_WAIT_TXN",  /* 15 */
    164 };
    165 static char *StateString[NUM_COMMANDS];
    166 
    167 static char *EventString[CMDMBOX_EVENT_NUM] = {
    168     "CMDMBOX_EVENT_SEND_CMD",  /* 1 */
    169     "CMDMBOX_EVENT_CMD_CMPLT",  /* 2 */
    170     "CMDMBOX_EVENT_BUS_READY",  /* 3 */
    171     "CMDMBOX_EVENT_TXN_CMPLT",  /* 4 */
    172     "CMDMBOX_EVENT_GET_RESULT",  /* 5 */
    173 };
    174 
    175 #endif
    176 
    177 /****************************************************************************
    178  *                      CmdMBox_Create()
    179  ****************************************************************************
    180  * DESCRIPTION: Create the mailbox object
    181  *
    182  * INPUTS:
    183  *
    184  * OUTPUT:  None
    185  *
    186  * RETURNS: The Created object
    187  ****************************************************************************/
    188 TI_HANDLE       CmdMBox_Create(TI_HANDLE hOs)
    189 {
    190     CmdMBox_T *pObj;
    191 
    192     pObj = os_memoryAlloc (hOs, sizeof(CmdMBox_T));
    193     if (pObj == NULL)
    194     {
    195         WLAN_OS_REPORT(("FATAL ERROR: CmdMBox_Create(): Error Creating CmdMBox - Aborting\n"));
    196         return NULL;
    197     }
    198 
    199     /* reset control module control block */
    200     os_memoryZero(hOs, pObj, sizeof(CmdMBox_T));
    201     pObj->hOs = hOs;
    202 
    203     /* allocates Timer to use for CmdMBox timeout*/
    204     pObj->hTimer = os_timerCreate(hOs, CmdMBox_TimeOut, pObj);
    205     if (pObj->hTimer == NULL)
    206     {
    207         CmdMBox_Destroy(pObj);
    208         WLAN_OS_REPORT(("FATAL ERROR: CmdMBox_Create(): Error Creating CmdMBox Timer- Aborting\n"));
    209         return NULL;
    210     }
    211 
    212 #if CMDMBOX_DEBUG_PRINT
    213     StateString[0] = StateString_array[0];
    214     StateString[1] = StateString_array[1];
    215     StateString[2] = StateString_array[2];
    216     StateString[3] = StateString_array[3];
    217     StateString[4] = StateString_array[4];
    218     StateString[10] = StateString_array[5];
    219     StateString[11] = StateString_array[6];
    220     StateString[12] = StateString_array[7];
    221     StateString[13] = StateString_array[8];
    222     StateString[14] = StateString_array[9];
    223     StateString[15] = StateString_array[10];
    224     StateString[16] = StateString_array[11];
    225     StateString[20] = StateString_array[12];
    226     StateString[21] = StateString_array[13];
    227     StateString[30] = StateString_array[14];
    228     StateString[31] = StateString_array[15];
    229 #endif
    230 
    231     return(pObj);
    232 }
    233 
    234 /****************************************************************************
    235  *                      CmdMBox_Destroy()
    236  ****************************************************************************
    237  * DESCRIPTION: Destroy the object
    238  *
    239  * INPUTS:
    240  *      hCmdMBox        The object to free
    241  *
    242  * OUTPUT:  None
    243  *
    244  * RETURNS: OK or NOK
    245  ****************************************************************************/
    246 int             CmdMBox_Destroy(TI_HANDLE hCmdMBox)
    247 {
    248     CmdMBox_T* pCmdMBox = (CmdMBox_T*)hCmdMBox;
    249 
    250     /* free timer */
    251     if (pCmdMBox->hTimer)
    252         utils_nullTimerDestroy(pCmdMBox->hOs, pCmdMBox->hTimer);
    253 
    254     /* free context */
    255        os_memoryFree(pCmdMBox->hOs, pCmdMBox, sizeof(CmdMBox_T));
    256 
    257     return OK;
    258 }
    259 
    260 /****************************************************************************
    261  *                      CmdMBox_Config()
    262  *****************************************************************************
    263  * DESCRIPTION: Configure the object
    264  *
    265  * INPUTS:
    266  *
    267  * OUTPUT:  None
    268  *
    269  * RETURNS: OK or NOK
    270  ****************************************************************************/
    271 int CmdMBox_Config (TI_HANDLE hCmdMBox, TI_HANDLE hTNETWIF, TI_HANDLE hFwEvent, TI_HANDLE hCmdQueue, TI_HANDLE hReport)
    272 {
    273     CmdMBox_T* pCmdMBox = (CmdMBox_T*)hCmdMBox;
    274 
    275     pCmdMBox->hReport = hReport;
    276     pCmdMBox->hTNETWIF = hTNETWIF;
    277     pCmdMBox->hFwEvent = hFwEvent;
    278     pCmdMBox->hCmdQueue = hCmdQueue;
    279 
    280     pCmdMBox->GetResultNormal_State = CMDMBOX_STATE_GETRESULT_NORMAL_IDLE;
    281     pCmdMBox->GetResultBlocking_State = CMDMBOX_STATE_GETRESULT_BLOCKING_IDLE;
    282     pCmdMBox->SendCmdNormal_State = CMDMBOX_STATE_SENDCMD_NORMAL_IDLE;
    283     pCmdMBox->SendCmdBlocking_State = CMDMBOX_STATE_SENDCMD_BLOCKING_IDLE;
    284     pCmdMBox->ActiveSM = NULL;
    285 
    286   #ifdef USE_SYNC_API /* Blocking mode is using Synch IF  */
    287     pCmdMBox->SendCmdSM = CmdMBox_SM_SendCmdBlocking;
    288     pCmdMBox->GetResultSM = CmdMBox_SM_GetResultBlocking;
    289   #else
    290     pCmdMBox->SendCmdSM = CmdMBox_SM_SendCmdNormal;
    291     pCmdMBox->GetResultSM = CmdMBox_SM_GetResultNormal;
    292   #endif
    293 
    294     pCmdMBox->CmdMBox_FW_address = 0;
    295     pCmdMBox->GetResult_ParamsBuf = NULL;
    296     pCmdMBox->GetResult_ParamsLen = 0;
    297 
    298     os_timerStop (pCmdMBox->hOs, pCmdMBox->hTimer);
    299 
    300     return OK;
    301 }
    302 
    303 
    304 /****************************************************************************
    305  *                      CmdMBox_ConfigCb()
    306  ****************************************************************************
    307  * DESCRIPTION: Configure the mailbox address callback
    308  *
    309  * INPUTS:
    310  *
    311  * OUTPUT:  None
    312  *
    313  * RETURNS: OK or NOK
    314  ****************************************************************************/
    315 static void CmdMBox_ConfigHwCb (TI_HANDLE hCmdMBox, UINT8 module_id, TI_STATUS status)
    316 {
    317     CmdMBox_T* pCmdMBox = (CmdMBox_T*)hCmdMBox;
    318 
    319     WLAN_REPORT_INIT (pCmdMBox->hReport, CMD_MBOX_MODULE_LOG,
    320                       ("CmdMBox_ConfigHw: CmdMBox FW address = 0x%x\n",
    321                       pCmdMBox->CmdMBox_FW_address));
    322 
    323     /* Call upper layer callback */
    324     pCmdMBox->fCb (pCmdMBox->hCb, module_id, OK);
    325 }
    326 
    327 
    328 /****************************************************************************
    329  *                      CmdMBox_ConfigHw()
    330  ****************************************************************************
    331  * DESCRIPTION: Configure the mailbox address
    332  *
    333  * INPUTS:
    334  *
    335  * OUTPUT:  None
    336  *
    337  * RETURNS: OK or NOK
    338  ****************************************************************************/
    339 TI_STATUS CmdMBox_ConfigHw (TI_HANDLE hCmdMBox, UINT8 module_id, fnotify_t fCb, TI_HANDLE hCb)
    340 {
    341     CmdMBox_T *pCmdMBox = (CmdMBox_T*)hCmdMBox;
    342     int        status;
    343 
    344     pCmdMBox->fCb = (TNETWIF_callback_t)fCb;
    345     pCmdMBox->hCb = hCb;
    346 
    347     /*
    348      * Get the command mailbox address
    349      */
    350     status = TNETWIF_ReadRegOpt (pCmdMBox->hTNETWIF,
    351                                  REG_COMMAND_MAILBOX_PTR,
    352                                  &pCmdMBox->CmdMBox_FW_address,
    353                                  module_id,
    354                                  CmdMBox_ConfigHwCb,
    355                                  hCmdMBox);
    356 
    357     switch (status)
    358     {
    359     case TNETWIF_ERROR:
    360         WLAN_REPORT_FATAL_ERROR (pCmdMBox->hReport, CMD_MBOX_MODULE_LOG,
    361                                  ("CmdMBox_ConfigHw: ERROR reading Mailbox addresses (0x%x) !!!\n",
    362                                  pCmdMBox->CmdMBox_FW_address ));
    363         break;
    364 
    365     case TNETWIF_COMPLETE:
    366         WLAN_REPORT_INIT (pCmdMBox->hReport, CMD_MBOX_MODULE_LOG,
    367                           ("CmdMBox_ConfigHw: CmdMBox FW address = 0x%x\n",
    368                           pCmdMBox->CmdMBox_FW_address));
    369         break;
    370     }
    371 
    372     return (TI_STATUS)status;
    373 }
    374 
    375 /****************************************************************************
    376  *                      CmdMBox_SetMode()
    377  ****************************************************************************
    378  * DESCRIPTION: Set the operational mode from blocking to normal
    379  *
    380  * RETURNS: None
    381  ****************************************************************************/
    382 int CmdMBox_SetModeNormal (TI_HANDLE hCmdMBox)
    383 {
    384   #if defined(USE_SYNC_API)
    385 
    386     CmdMBox_T* pCmdMBox = (CmdMBox_T*)hCmdMBox;
    387 
    388     /* Set the state to NORMAL */
    389     pCmdMBox->SendCmdSM = CmdMBox_SM_SendCmdNormal;
    390     pCmdMBox->GetResultSM = CmdMBox_SM_GetResultNormal;
    391 
    392     FwEvent_Enable (pCmdMBox->hFwEvent, ACX_INTR_CMD_COMPLETE);
    393 
    394     WLAN_REPORT_INFORMATION (pCmdMBox->hReport, CMD_MBOX_MODULE_LOG,
    395             ("CmdMBox_SetMode: CmdMBox mode is now NORMAL"));
    396 
    397 
    398   #endif
    399 
    400     return OK;
    401 }
    402 
    403 /****************************************************************************
    404  *                      CmdMBox_Reconfig()
    405  ****************************************************************************
    406  * DESCRIPTION:
    407  *
    408  * INPUTS:
    409  *
    410  * RETURNS: OK or NOK
    411  ****************************************************************************/
    412 int                 CmdMBox_Restart(TI_HANDLE hCmdMBox)
    413 {
    414     CmdMBox_T* pCmdMBox = (CmdMBox_T*)hCmdMBox;
    415 
    416     return CmdMBox_Config(hCmdMBox, pCmdMBox->hTNETWIF, pCmdMBox->hFwEvent, pCmdMBox->hCmdQueue, pCmdMBox->hReport);
    417 }
    418 
    419 
    420 /****************************************************************************
    421  *                      CmdMBox_SendCmd()
    422  ****************************************************************************
    423  * DESCRIPTION: Try to send the Command to the Mailbox
    424  *
    425  * INPUTS:
    426  *
    427  * OUTPUT:  None
    428  *
    429  * RETURNS: OK or NOK
    430  ****************************************************************************/
    431 int                 CmdMBox_SendCmd(TI_HANDLE hCmdMBox, Command_e cmdType, UINT8* pParamsBuf, UINT32 paramsLen)
    432 {
    433     CmdMBox_T* pCmdMBox = (CmdMBox_T*)hCmdMBox;
    434 
    435     /* prepare the Cmd Hw template */
    436     pCmdMBox->HW_CmdMBox.cmdID = cmdType;
    437     pCmdMBox->HW_CmdMBox.cmdStatus = OK;
    438     os_memoryCopy(pCmdMBox->hOs, (void*)pCmdMBox->HW_CmdMBox.parameters, (void*)pParamsBuf, paramsLen);
    439     /* must make sure that the length is multiple of 32bit */
    440     if(paramsLen&0x3)
    441         paramsLen  = (paramsLen + 4) & 0xFFFFFFFC;
    442     pCmdMBox->CmdLen = paramsLen + CMDMBOX_HEADER_LEN;
    443 
    444     pCmdMBox->ActiveSM = pCmdMBox->SendCmdSM;
    445     return  pCmdMBox->ActiveSM(hCmdMBox, CMDMBOX_EVENT_SEND_CMD);
    446 }
    447 
    448 /****************************************************************************
    449  *                      CmdMBox_GetResult()
    450  ****************************************************************************
    451  * DESCRIPTION: Get result of the Cmd
    452  *
    453  * INPUTS:
    454  *
    455  * OUTPUT:  None
    456  *
    457  * RETURNS: OK or NOK
    458  ****************************************************************************/
    459 int                 CmdMBox_GetResult(TI_HANDLE hCmdMBox, UINT8* pParamsBuf, UINT32 paramsLen, UINT32* pStatus)
    460 {
    461     CmdMBox_T* pCmdMBox = (CmdMBox_T*)hCmdMBox;
    462     int rc;
    463 
    464     pCmdMBox->GetResult_ParamsBuf = pParamsBuf;
    465     pCmdMBox->GetResult_ParamsLen= paramsLen;
    466 
    467 
    468     pCmdMBox->ActiveSM = pCmdMBox->GetResultSM;
    469     rc = pCmdMBox->ActiveSM(hCmdMBox, CMDMBOX_EVENT_GET_RESULT);
    470 
    471 	if (pCmdMBox->HW_CmdMBox.cmdStatus == CMD_STATUS_SUCCESS || pCmdMBox->HW_CmdMBox.cmdStatus == CMD_STATUS_REJECT_MEAS_SG_ACTIVE)
    472 		{
    473 			*pStatus = OK;
    474 		}
    475 		else
    476 		{
    477 			*pStatus = NOK;
    478 		}
    479 
    480     return rc;
    481 }
    482 
    483 /****************************************************************************
    484  *                      CmdMBox_CmdCmplt()
    485  ****************************************************************************
    486  * DESCRIPTION: CallBack for command complete interrupt
    487  *
    488  * INPUTS:  CbFunc  The Callback will be called we upon command complete interrupt
    489  *
    490  * RETURNS: None
    491  ****************************************************************************/
    492 TI_STATUS  CmdMBox_CmdCmplt(TI_HANDLE hCmdMBox)
    493 {
    494     CmdMBox_T* pCmdMBox = (CmdMBox_T*)hCmdMBox;
    495     TI_STATUS  rc;
    496 
    497     pCmdMBox->ActiveSM = pCmdMBox->SendCmdSM;
    498     rc = (TI_STATUS)pCmdMBox->ActiveSM (hCmdMBox, CMDMBOX_EVENT_CMD_CMPLT);
    499     if (rc == TNETWIF_COMPLETE)
    500         rc = TNETWIF_OK;
    501     return rc;
    502 }
    503 
    504 /****************************************************************************
    505  *                      CmdMBox_TxnCmplt()
    506  ****************************************************************************
    507  * DESCRIPTION: CallBack for Txn complete
    508  *
    509  * INPUTS:
    510  *
    511  * RETURNS: None
    512  ****************************************************************************/
    513 void                CmdMBox_TxnCmplt(TI_HANDLE hCmdMBox, UINT8 module_id ,TI_STATUS status)
    514 {
    515     CmdMBox_T* pCmdMBox = (CmdMBox_T*)hCmdMBox;
    516 
    517     pCmdMBox->ActiveSM(hCmdMBox, CMDMBOX_EVENT_TXN_CMPLT);
    518 }
    519 
    520 /****************************************************************************
    521  *                      CmdMBox_BusReady()
    522  ****************************************************************************
    523  * DESCRIPTION: CallBack for Txn complete
    524  *
    525  * INPUTS:
    526  *
    527  * RETURNS: None
    528  ****************************************************************************/
    529 void                CmdMBox_BusReady(TI_HANDLE hCmdMBox, UINT8 module_id ,TI_STATUS status)
    530 {
    531     CmdMBox_T* pCmdMBox = (CmdMBox_T*)hCmdMBox;
    532 
    533     pCmdMBox->ActiveSM(hCmdMBox, CMDMBOX_EVENT_BUS_READY);
    534 }
    535 
    536 /****************************************************************************
    537  *                      CmdMBox_SM_GetResultNormal()
    538  ****************************************************************************
    539  * DESCRIPTION: CmdMBox SM
    540  *
    541  * INPUTS:
    542  *
    543  * RETURNS: None
    544  ****************************************************************************/
    545 int             CmdMBox_SM_GetResultNormal(CmdMBox_T* pCmdMBox, CmdMBox_SMEvents_e event)
    546 {
    547     int rc = OK;
    548     BOOLEAN breakWhile = FALSE;
    549 
    550     while(!breakWhile)
    551     {
    552 #if CMDMBOX_DEBUG_PRINT
    553         WLAN_OS_REPORT(("CmdMBox_SM_GetResultNormal: state = %s (%d) event = %s(%d)\n",
    554             StateString[pCmdMBox->GetResultNormal_State],
    555             pCmdMBox->GetResultNormal_State,
    556             EventString[event],
    557             event));
    558 #endif
    559         switch(pCmdMBox->GetResultNormal_State)
    560         {
    561             /***************************************
    562             CMDMBOX_STATE_GETRESULT_NORMAL_IDLE
    563             ***************************************/
    564             case CMDMBOX_STATE_GETRESULT_NORMAL_IDLE:
    565                 switch(event)
    566                 {
    567                     case CMDMBOX_EVENT_GET_RESULT:
    568 
    569                         /* read the results */
    570                         if(pCmdMBox->GetResult_ParamsBuf)
    571                         {
    572                             /* need to read the results also */
    573                             rc = TNETWIF_ReadMemOpt (pCmdMBox->hTNETWIF,
    574                                                      pCmdMBox->CmdMBox_FW_address,
    575                                                      PADREAD (&pCmdMBox->HW_CmdMBox),
    576                                                      pCmdMBox->GetResult_ParamsLen + CMDMBOX_HEADER_LEN,
    577                                                      FW_EVENT_MODULE_ID,
    578                                                      CmdMBox_TxnCmplt,
    579                                                      pCmdMBox);
    580                         }
    581                         else
    582                         {
    583                             /* need to read the status only */
    584                             rc = TNETWIF_ReadMemOpt (pCmdMBox->hTNETWIF,
    585                                                      pCmdMBox->CmdMBox_FW_address,
    586                                                      PADREAD (&pCmdMBox->HW_CmdMBox),
    587                                                      CMDMBOX_HEADER_LEN,
    588                                                      FW_EVENT_MODULE_ID,
    589                                                      CmdMBox_TxnCmplt,
    590                                                      pCmdMBox);
    591                         }
    592 
    593                         if(rc == TNETWIF_PENDING)
    594                         {
    595                             pCmdMBox->GetResultNormal_State = CMDMBOX_STATE_GETRESULT_NORMAL_WAIT_TXN;
    596                         }
    597                         else
    598                         {
    599 
    600                             /* check the status */
    601                             CMDMBOX_CHECK_STATUS;
    602 
    603                             /*
    604                             if GetResult_ParamsBuf is NULL then we only need to check the status and then
    605                             we don't need to copy the results
    606                             */
    607                             if(pCmdMBox->GetResult_ParamsBuf)
    608                             {
    609                                 /* copy the results to the caller buffer */
    610                                 os_memoryCopy(pCmdMBox->hOs, (void*)pCmdMBox->GetResult_ParamsBuf, (void*)pCmdMBox->HW_CmdMBox.parameters, pCmdMBox->GetResult_ParamsLen);
    611                             }
    612 
    613                             pCmdMBox->GetResultNormal_State = CMDMBOX_STATE_GETRESULT_NORMAL_IDLE;
    614                         }
    615                         breakWhile = TRUE;
    616                         break;
    617                     default:
    618                         WLAN_REPORT_ERROR(pCmdMBox->hReport, CMD_MBOX_MODULE_LOG,
    619                             ("CmdMBox_SM_GetResultNormal: ** ERROR **  No such event (%d) for state CMDMBOX_STATE_GETRESULT_NORMAL_IDLE\n",event));
    620                             return NOK;
    621                 }
    622                 break;
    623             /***************************************
    624             CMDMBOX_STATE_GETRESULT_NORMAL_WAIT_TXN
    625             ***************************************/
    626             case CMDMBOX_STATE_GETRESULT_NORMAL_WAIT_TXN:
    627                 switch(event)
    628                 {
    629                     case CMDMBOX_EVENT_TXN_CMPLT:
    630 
    631                         /* check the status */
    632                         CMDMBOX_CHECK_STATUS;
    633 
    634                         /*
    635                         if GetResult_ParamsBuf is NULL then we only need to check the status and then
    636                         we don't need to copy the results
    637                         */
    638                         if(pCmdMBox->GetResult_ParamsBuf)
    639                         {
    640                             /* copy the results to the caller buffer */
    641                             os_memoryCopy(pCmdMBox->hOs, (void*)pCmdMBox->GetResult_ParamsBuf, (void*)pCmdMBox->HW_CmdMBox.parameters, pCmdMBox->GetResult_ParamsLen);
    642                         }
    643 
    644                         /* call the CmdQueue CB */
    645                         if (pCmdMBox->HW_CmdMBox.cmdStatus == CMD_STATUS_SUCCESS || pCmdMBox->HW_CmdMBox.cmdStatus == CMD_STATUS_REJECT_MEAS_SG_ACTIVE)
    646 						{
    647 							CmdQueue_ResultReceived(pCmdMBox->hCmdQueue, OK);
    648 						}
    649 						else
    650 						{
    651 							CmdQueue_ResultReceived(pCmdMBox->hCmdQueue, NOK);
    652 						}
    653 
    654                         FwEvent_EventComplete(pCmdMBox->hFwEvent, TNETWIF_OK);
    655                         pCmdMBox->GetResultNormal_State = CMDMBOX_STATE_GETRESULT_NORMAL_IDLE;
    656                         return OK;
    657                     default:
    658                         WLAN_REPORT_ERROR(pCmdMBox->hReport, CMD_MBOX_MODULE_LOG,
    659                             ("CmdMBox_SM_GetResultNormal: ** ERROR **  No such event (%d) for state CMDMBOX_STATE_GETRESULT_NORMAL_WAIT_TXN\n",event));
    660                             return NOK;
    661                 }
    662 /*                break;  */
    663             default:
    664                 WLAN_REPORT_ERROR(pCmdMBox->hReport, CMD_MBOX_MODULE_LOG,
    665                     ("CmdMBox_SM_GetResultNormal: ** ERROR **  No such state (%d)\n",pCmdMBox->GetResultNormal_State));
    666                     return NOK;
    667         }
    668     }
    669 
    670     return rc;
    671 
    672 }
    673 
    674 
    675 #ifdef USE_SYNC_API
    676 
    677 /****************************************************************************
    678  *                      CmdMBox_SM_GetResultBlocking()
    679  ****************************************************************************
    680  * DESCRIPTION: CmdMBox SM
    681  *
    682  * INPUTS:
    683  *
    684  * RETURNS: None
    685  ****************************************************************************/
    686 int             CmdMBox_SM_GetResultBlocking(CmdMBox_T* pCmdMBox, CmdMBox_SMEvents_e event)
    687 {
    688     int rc = OK;
    689     BOOLEAN breakWhile = FALSE;
    690 
    691     while(!breakWhile)
    692     {
    693 #if CMDMBOX_DEBUG_PRINT
    694         WLAN_OS_REPORT(("CmdMBox_SM_GetResultBlocking: state = %s (%d) event = %s(%d)\n",
    695             StateString[pCmdMBox->GetResultBlocking_State],
    696             pCmdMBox->GetResultBlocking_State,
    697             EventString[event],
    698             event));
    699 #endif
    700         switch(pCmdMBox->GetResultBlocking_State)
    701         {
    702             /***************************************
    703             CMDMBOX_STATE_GETRESULT_BLOCKING_IDLE
    704             ***************************************/
    705             case CMDMBOX_STATE_GETRESULT_BLOCKING_IDLE:
    706                 switch(event)
    707                 {
    708                     case CMDMBOX_EVENT_GET_RESULT:
    709                         /* read the results */
    710                         if(pCmdMBox->GetResult_ParamsBuf)
    711                         {
    712                             /* need to read the results also */
    713                             rc = TNETWIF_ReadMemSync (pCmdMBox->hTNETWIF,
    714                                                       pCmdMBox->CmdMBox_FW_address,
    715                                                       PADREAD(&pCmdMBox->HW_CmdMBox),
    716                                                       pCmdMBox->GetResult_ParamsLen + CMDMBOX_HEADER_LEN);
    717                         }
    718                         else
    719                         {
    720                             rc = TNETWIF_ReadMemSync (pCmdMBox->hTNETWIF,
    721                                                       pCmdMBox->CmdMBox_FW_address,
    722                                                       PADREAD (&pCmdMBox->HW_CmdMBox),
    723                                                       CMDMBOX_HEADER_LEN);
    724                         }
    725 
    726                         if(rc == TNETWIF_PENDING)
    727                         {
    728                             pCmdMBox->GetResultBlocking_State = CMDMBOX_STATE_GETRESULT_BLOCKING_WAIT_TXN;
    729                         }
    730                         else
    731                         {
    732                             /* check the status */
    733                             CMDMBOX_CHECK_STATUS;
    734 
    735                             /*
    736                             if GetResult_ParamsBuf is NULL then we only need to check the status and then
    737                             we don't need to copy the results
    738                             */
    739                             if(pCmdMBox->GetResult_ParamsBuf)
    740                             {
    741                                 /* copy the results to the caller buffer */
    742                                 os_memoryCopy(pCmdMBox->hOs, (void*)pCmdMBox->GetResult_ParamsBuf, (void*)pCmdMBox->HW_CmdMBox.parameters, pCmdMBox->GetResult_ParamsLen);
    743                             }
    744                         }
    745                         breakWhile = TRUE;
    746                         break;
    747                     default:
    748                         WLAN_REPORT_ERROR(pCmdMBox->hReport, CMD_MBOX_MODULE_LOG,
    749                             ("CmdMBox_SM_GetResultBlocking: ** ERROR **  No such event (%d) for state CMDMBOX_STATE_GETRESULT_BLOCKING_IDLE\n",event));
    750                             return NOK;
    751                 }
    752                 break;
    753             /***************************************
    754             CMDMBOX_STATE_GETRESULT_BLOCKING_WAIT_TXN
    755             ***************************************/
    756             case CMDMBOX_STATE_GETRESULT_BLOCKING_WAIT_TXN:
    757                 switch(event)
    758                 {
    759 				case CMDMBOX_EVENT_TXN_CMPLT:
    760 
    761                         /* check the status */
    762                         CMDMBOX_CHECK_STATUS;
    763 
    764                         /*
    765                         if GetResult_ParamsBuf is NULL then we only need to check the status and then
    766                         we don't need to copy the results
    767                         */
    768                         if(pCmdMBox->GetResult_ParamsBuf)
    769                         {
    770                             /* copy the results to the caller buffer */
    771                             os_memoryCopy(pCmdMBox->hOs, (void*)pCmdMBox->GetResult_ParamsBuf, (void*)pCmdMBox->HW_CmdMBox.parameters, pCmdMBox->GetResult_ParamsLen);
    772                         }
    773 
    774                         /* call the CmdQueue CB */
    775 						if (pCmdMBox->HW_CmdMBox.cmdStatus == CMD_STATUS_SUCCESS || pCmdMBox->HW_CmdMBox.cmdStatus == CMD_STATUS_REJECT_MEAS_SG_ACTIVE)
    776 						{
    777 							CmdQueue_ResultReceived(pCmdMBox->hCmdQueue, OK);
    778 						}
    779 						else
    780 						{
    781 							CmdQueue_ResultReceived(pCmdMBox->hCmdQueue, NOK);
    782 						}
    783 
    784 
    785                         pCmdMBox->GetResultBlocking_State = CMDMBOX_STATE_GETRESULT_BLOCKING_IDLE;
    786                         breakWhile = TRUE;
    787                         break;
    788                     default:
    789                         WLAN_REPORT_ERROR(pCmdMBox->hReport, CMD_MBOX_MODULE_LOG,
    790                             ("CmdMBox_SM_GetResultBlocking: ** ERROR **  No such event (%d) for state CMDMBOX_STATE_GETRESULT_BLOCKING_WAIT_TXN\n",event));
    791                             return NOK;
    792                 }
    793                 break;
    794             default:
    795                 WLAN_REPORT_ERROR(pCmdMBox->hReport, CMD_MBOX_MODULE_LOG,
    796                     ("CmdMBox_SM_GetResultBlocking: ** ERROR **  No such state (%d)\n",pCmdMBox->GetResultBlocking_State));
    797                     return NOK;
    798         }
    799     }
    800     return rc;
    801 
    802 }
    803 
    804 #endif /* USE_SYNC_API */
    805 
    806 
    807 /****************************************************************************
    808  *                      CmdMBox_SM_SendCmdNormal()
    809  ****************************************************************************
    810  * DESCRIPTION: CmdMBox SM
    811  *
    812  * INPUTS:
    813  *
    814  * RETURNS: None
    815  ****************************************************************************/
    816 int             CmdMBox_SM_SendCmdNormal(CmdMBox_T* pCmdMBox, CmdMBox_SMEvents_e event)
    817 {
    818     int rc = OK;
    819     BOOLEAN breakWhile = FALSE;
    820 
    821     while(!breakWhile)
    822 {
    823 #if CMDMBOX_DEBUG_PRINT
    824         WLAN_OS_REPORT(("CmdMBox_SM_SendCmdNormal: state = %s (%d) event = %s(%d) rc = %d\n",
    825             StateString[pCmdMBox->SendCmdNormal_State],
    826             pCmdMBox->SendCmdNormal_State,
    827             EventString[event],
    828             event,rc));
    829 #endif
    830         switch(pCmdMBox->SendCmdNormal_State)
    831         {
    832             /***************************************
    833             CMDMBOX_STATE_SENDCMD_NORMAL_IDLE
    834             ***************************************/
    835             case CMDMBOX_STATE_SENDCMD_NORMAL_IDLE:
    836                 switch(event)
    837                 {
    838                     case CMDMBOX_EVENT_SEND_CMD:
    839                         pCmdMBox->SendCmdNormal_State = CMDMBOX_STATE_SENDCMD_NORMAL_WAIT_BUS;
    840                         /* ask for the bus */
    841                         TNETWIF_Start (pCmdMBox->hTNETWIF,   HAL_CMD_MODULE_ID,
    842                             pCmdMBox, CmdMBox_BusReady);
    843                         rc = TNETWIF_PENDING;
    844                         breakWhile = TRUE;
    845                         break;
    846                     case CMDMBOX_EVENT_CMD_CMPLT:
    847                         /* stop timeout timer */
    848                         os_timerStop(pCmdMBox->hOs, pCmdMBox->hTimer);
    849 
    850                         /* call the CmdQueue CB */
    851                         rc = CmdQueue_SendCmplt(pCmdMBox->hCmdQueue);
    852                         breakWhile = TRUE;
    853                         break;
    854                     default:
    855                         WLAN_REPORT_ERROR(pCmdMBox->hReport, CMD_MBOX_MODULE_LOG,
    856                             ("CmdMBox_SM_SendCmdNormal: ** ERROR **  No such event (%d) for state CMDMBOX_STATE_SENDCMD_NORMAL_IDLE\n",event));
    857                             return NOK;
    858                 }
    859                 break;
    860             /***************************************
    861             CMDMBOX_STATE_SENDCMD_NORMAL_WAIT_BUS
    862             ***************************************/
    863             case CMDMBOX_STATE_SENDCMD_NORMAL_WAIT_BUS:
    864                 switch(event)
    865                 {
    866                     case CMDMBOX_EVENT_BUS_READY:
    867                         /* write the Cmd - subtract offset for the bus reserved place */
    868             rc = TNETWIF_WriteMemOpt (pCmdMBox->hTNETWIF,
    869                                                   pCmdMBox->CmdMBox_FW_address,
    870                                                   PADWRITE (&pCmdMBox->HW_CmdMBox),
    871                                                   pCmdMBox->CmdLen,
    872                                                   HAL_CMD_MODULE_ID,
    873                                                   CmdMBox_TxnCmplt,
    874                                                   pCmdMBox);
    875             if(rc == TNETWIF_PENDING)
    876                      {
    877                             pCmdMBox->SendCmdNormal_State = CMDMBOX_STATE_SENDCMD_NORMAL_WAIT_TXN_BUF;
    878                             breakWhile = TRUE;
    879                      }
    880                      else
    881                      {
    882                             pCmdMBox->SendCmdNormal_State = CMDMBOX_STATE_SENDCMD_NORMAL_WRITE_TRIG_v;
    883                     }
    884                      break;
    885                         default:
    886                         WLAN_REPORT_ERROR(pCmdMBox->hReport, CMD_MBOX_MODULE_LOG,
    887                                 ("CmdMBox_SM_SendCmdNormal: ** ERROR **  No such event (%d) for state CMDMBOX_STATE_SENDCMD_NORMAL_WAIT_BUS\n",event));
    888                             return NOK;
    889                 }
    890                 break;
    891             /***************************************
    892             CMDMBOX_STATE_SENDCMD_NORMAL_WAIT_TXN_BUF
    893             ***************************************/
    894             case CMDMBOX_STATE_SENDCMD_NORMAL_WAIT_TXN_BUF:
    895                 switch(event)
    896                 {
    897                     case CMDMBOX_EVENT_TXN_CMPLT:
    898                         pCmdMBox->SendCmdNormal_State = CMDMBOX_STATE_SENDCMD_NORMAL_WRITE_TRIG_v;
    899                         break;
    900                     default:
    901                         WLAN_REPORT_ERROR(pCmdMBox->hReport, CMD_MBOX_MODULE_LOG,
    902                             ("CmdMBox_SM_SendCmdNormal: ** ERROR **  No such event (%d) for state CMDMBOX_STATE_SENDCMD_NORMAL_WAIT_TXN_BUF\n",event));
    903                             return NOK;
    904                 }
    905                 break;
    906             /***************************************
    907             CMDMBOX_STATE_SENDCMD_NORMAL_WRITE_TRIG_v
    908             ***************************************/
    909             case CMDMBOX_STATE_SENDCMD_NORMAL_WRITE_TRIG_v:
    910                 /* start timeout timer */
    911 #ifdef DM_USE_WORKQUEUE
    912                 os_timerStart(pCmdMBox->hOs, pCmdMBox->hTimer,
    913                       CMDMBOX_WAIT_TIMEOUT * 2, FALSE); /* Dm: Wait for 1000 ms */
    914 #else
    915                 os_timerStart(pCmdMBox->hOs, pCmdMBox->hTimer,
    916                       CMDMBOX_WAIT_TIMEOUT, FALSE);
    917 #endif
    918 
    919                 /* write the FW trigger */
    920                 rc = TNETWIF_WriteRegOpt (pCmdMBox->hTNETWIF,
    921                                           ACX_REG_INTERRUPT_TRIG,
    922                                           INTR_TRIG_CMD,
    923                                           HAL_CMD_MODULE_ID,
    924                                           CmdMBox_TxnCmplt,
    925                                           pCmdMBox);
    926                 if(rc == TNETWIF_PENDING)
    927                 {
    928                     pCmdMBox->SendCmdNormal_State = CMDMBOX_STATE_SENDCMD_NORMAL_WAIT_TXN_TRIG;
    929                 }
    930                 else
    931                 {
    932                     pCmdMBox->SendCmdNormal_State = CMDMBOX_STATE_SENDCMD_NORMAL_IDLE;
    933                     /* release the bus resource*/
    934                     TNETWIF_Finish (pCmdMBox->hTNETWIF, HAL_CMD_MODULE_ID, NULL, NULL);
    935                 }
    936                 breakWhile = TRUE;
    937                 break;
    938             /***************************************
    939             CMDMBOX_STATE_SENDCMD_NORMAL_WAIT_TXN_TRIG
    940             ***************************************/
    941             case CMDMBOX_STATE_SENDCMD_NORMAL_WAIT_TXN_TRIG:
    942                 switch(event)
    943                 {
    944                     case CMDMBOX_EVENT_TXN_CMPLT:
    945                         pCmdMBox->SendCmdNormal_State = CMDMBOX_STATE_SENDCMD_NORMAL_IDLE;
    946                         /* release the bus resource*/
    947                         TNETWIF_Finish (pCmdMBox->hTNETWIF, HAL_CMD_MODULE_ID, NULL, NULL);
    948             rc = OK;
    949                         break;
    950                     default:
    951                         WLAN_REPORT_ERROR(pCmdMBox->hReport, CMD_MBOX_MODULE_LOG,
    952                             ("CmdMBox_SM_SendCmdNormal: ** ERROR **  No such event (%d) for state CMDMBOX_STATE_SENDCMD_NORMAL_WAIT_TXN_TRIG\n",event));
    953                             return NOK;
    954                 }
    955                 breakWhile = TRUE;
    956                 break;
    957             default:
    958                 WLAN_REPORT_ERROR(pCmdMBox->hReport, CMD_MBOX_MODULE_LOG,
    959                     ("CmdMBox_SM_SendCmdNormal: ** ERROR **  No such state (%d)\n",pCmdMBox->SendCmdNormal_State));
    960                     return NOK;
    961         }
    962     }
    963 #if CMDMBOX_DEBUG_PRINT
    964         WLAN_OS_REPORT(("CmdMBox_SM_SendCmdNormal return = %d\n",rc));
    965 #endif
    966     return rc;
    967 
    968 }
    969 
    970 
    971 #ifdef USE_SYNC_API
    972 
    973 /****************************************************************************
    974  *                      CmdMBox_SM_SendCmdBlocking()
    975  ****************************************************************************
    976  * DESCRIPTION: CmdMBox SM
    977  *
    978  * INPUTS:
    979  *
    980  * RETURNS: None
    981  ****************************************************************************/
    982 int             CmdMBox_SM_SendCmdBlocking(CmdMBox_T* pCmdMBox, CmdMBox_SMEvents_e event)
    983 {
    984     int rc = OK;
    985     BOOLEAN breakWhile = FALSE;
    986     BOOLEAN CmdCmpltFlag = FALSE;
    987 
    988     static UINT32 timeoutCounterExpire;
    989     static UINT32 timeoutCounter;
    990 
    991     while(!breakWhile)
    992     {
    993 #if CMDMBOX_DEBUG_PRINT
    994         WLAN_OS_REPORT(("CmdMBox_SM_SendCmdBlocking: state = %s (%d) event = %s(%d) rc = %d\n",
    995             StateString[pCmdMBox->SendCmdBlocking_State],
    996             pCmdMBox->SendCmdBlocking_State,
    997             EventString[event],
    998             event,rc));
    999 #endif
   1000         switch(pCmdMBox->SendCmdBlocking_State)
   1001         {
   1002             /***************************************
   1003             CMDMBOX_STATE_SENDCMD_BLOCKING_IDLE
   1004             ***************************************/
   1005             case CMDMBOX_STATE_SENDCMD_BLOCKING_IDLE:
   1006                 switch(event)
   1007                 {
   1008                     case CMDMBOX_EVENT_SEND_CMD:
   1009 
   1010                         pCmdMBox->SendCmdBlocking_State = CMDMBOX_STATE_SENDCMD_BLOCKING_WAIT_BUS;
   1011 
   1012                         /* use the bus directly - it's O.K. since it's the init phase */
   1013                         event = CMDMBOX_EVENT_BUS_READY;
   1014 
   1015                         break;
   1016                     default:
   1017                         WLAN_REPORT_ERROR(pCmdMBox->hReport, CMD_MBOX_MODULE_LOG,
   1018                             ("CmdMBox_SM_SendCmdBlocking: ** ERROR **  No such event (%d) for state CMDMBOX_STATE_SENDCMD_BLOCKING_IDLE\n",event));
   1019                             return NOK;
   1020                 }
   1021                 break;
   1022             /***************************************
   1023             CMDMBOX_STATE_SENDCMD_BLOCKING_WAIT_BUS
   1024             ***************************************/
   1025             case CMDMBOX_STATE_SENDCMD_BLOCKING_WAIT_BUS:
   1026                 switch(event)
   1027                 {
   1028                     case CMDMBOX_EVENT_BUS_READY:
   1029                         /* write the Cmd */
   1030                         rc = TNETWIF_WriteMemSync (pCmdMBox->hTNETWIF,
   1031                                                    pCmdMBox->CmdMBox_FW_address,
   1032                                                    PADWRITE (&pCmdMBox->HW_CmdMBox),
   1033                                                    pCmdMBox->CmdLen);
   1034 
   1035                         pCmdMBox->SendCmdBlocking_State = CMDMBOX_STATE_SENDCMD_BLOCKING_WRITE_TRIG_v;
   1036 
   1037                         break;
   1038                     default:
   1039                         WLAN_REPORT_ERROR(pCmdMBox->hReport, CMD_MBOX_MODULE_LOG,
   1040                             ("CmdMBox_SM_SendCmdBlocking: ** ERROR **  No such event (%d) for state CMDMBOX_STATE_SENDCMD_BLOCKING_WAIT_BUS\n",event));
   1041                             return NOK;
   1042                 }
   1043                 break;
   1044             /***************************************
   1045             CMDMBOX_STATE_SENDCMD_BLOCKING_WAIT_TXN_BUF
   1046             ***************************************/
   1047             case CMDMBOX_STATE_SENDCMD_BLOCKING_WAIT_TXN_BUF:
   1048                 switch(event)
   1049                 {
   1050                     case CMDMBOX_EVENT_TXN_CMPLT:
   1051                         pCmdMBox->SendCmdBlocking_State = CMDMBOX_STATE_SENDCMD_BLOCKING_WRITE_TRIG_v;
   1052                         break;
   1053                     default:
   1054                         WLAN_REPORT_ERROR(pCmdMBox->hReport, CMD_MBOX_MODULE_LOG,
   1055                             ("CmdMBox_SM_SendCmdBlocking: ** ERROR **  No such event (%d) for state CMDMBOX_STATE_SENDCMD_BLOCKING_WAIT_TXN_BUF\n",event));
   1056                             return NOK;
   1057                 }
   1058                 break;
   1059             /***************************************
   1060             CMDMBOX_STATE_SENDCMD_BLOCKING_WRITE_TRIG_v
   1061             ***************************************/
   1062             case CMDMBOX_STATE_SENDCMD_BLOCKING_WRITE_TRIG_v:
   1063                 /* init timeout counter */
   1064                 timeoutCounterExpire = (CMDMBOX_WAIT_TIMEOUT*CMDMBOX_US_TO_MS)/CMDMBOX_WAIT_CMPLT_STALL_TIME;
   1065                 timeoutCounter = 0;
   1066 
   1067                 /* write the FW trigger */
   1068                 if(pCmdMBox->useOpt)
   1069                 rc = TNETWIF_WriteRegOpt  (pCmdMBox->hTNETWIF,
   1070                                                ACX_REG_INTERRUPT_TRIG,
   1071                                                INTR_TRIG_CMD,
   1072                                                HAL_CMD_MODULE_ID,
   1073                                                CmdMBox_TxnCmplt,
   1074                                                pCmdMBox);
   1075                 else
   1076                     rc = TNETWIF_WriteRegSync (pCmdMBox->hTNETWIF,
   1077                                                ACX_REG_INTERRUPT_TRIG,
   1078                                                INTR_TRIG_CMD);
   1079 
   1080                 if(rc == TNETWIF_PENDING)
   1081                 {
   1082                     pCmdMBox->SendCmdBlocking_State = CMDMBOX_STATE_SENDCMD_BLOCKING_WAIT_TXN_TRIG;
   1083                     breakWhile = TRUE;
   1084                 }
   1085                 else
   1086                 {
   1087                     pCmdMBox->SendCmdBlocking_State = CMDMBOX_STATE_SENDCMD_BLOCKING_POLL_CMPLT_v;
   1088                 }
   1089                 break;
   1090             /***************************************
   1091             CMDMBOX_STATE_SENDCMD_BLOCKING_WAIT_TXN_TRIG
   1092             ***************************************/
   1093             case CMDMBOX_STATE_SENDCMD_BLOCKING_WAIT_TXN_TRIG:
   1094                 switch(event)
   1095                 {
   1096                     case CMDMBOX_EVENT_TXN_CMPLT:
   1097                         pCmdMBox->SendCmdBlocking_State = CMDMBOX_STATE_SENDCMD_BLOCKING_POLL_CMPLT_v;
   1098                         break;
   1099                     default:
   1100                         WLAN_REPORT_ERROR(pCmdMBox->hReport, CMD_MBOX_MODULE_LOG,
   1101                             ("CmdMBox_SM_SendCmdBlocking: ** ERROR **  No such event (%d) for state CMDMBOX_STATE_SENDCMD_BLOCKING_WAIT_TXN_TRIG\n",event));
   1102                             return NOK;
   1103                 }
   1104                 break;
   1105             /***************************************
   1106             CMDMBOX_STATE_SENDCMD_BLOCKING_POLL_CMPLT_v
   1107             ***************************************/
   1108             case CMDMBOX_STATE_SENDCMD_BLOCKING_POLL_CMPLT_v:
   1109                 /* check CmdCmplt */
   1110                 /* the following function is done in synchronize mode */
   1111                 timeoutCounter++;
   1112                 CmdCmpltFlag = CmdMbox_CheckAndAck(pCmdMBox->hTNETWIF, ACX_INTR_CMD_COMPLETE);
   1113                 pCmdMBox->SendCmdBlocking_State = CMDMBOX_STATE_SENDCMD_BLOCKING_FINISH_v;
   1114                 break;
   1115 
   1116             /***************************************
   1117             CMDMBOX_STATE_SENDCMD_BLOCKING_FINISH_v
   1118             ***************************************/
   1119             case CMDMBOX_STATE_SENDCMD_BLOCKING_FINISH_v:
   1120                 /* check CmdCmplt */
   1121                 if(CmdCmpltFlag == FALSE)
   1122                 {
   1123                     /* check timeout counter */
   1124                     if(timeoutCounter == timeoutCounterExpire)
   1125                         CmdMBox_TimeOut(pCmdMBox);
   1126 
   1127                     pCmdMBox->SendCmdBlocking_State = CMDMBOX_STATE_SENDCMD_BLOCKING_POLL_CMPLT_v;
   1128                     os_StalluSec(pCmdMBox->hOs, CMDMBOX_WAIT_CMPLT_STALL_TIME);
   1129                 }
   1130                 else
   1131                 {
   1132                     /* stop timeout timer */
   1133                     os_timerStop(pCmdMBox->hOs, pCmdMBox->hTimer);
   1134 
   1135                     pCmdMBox->SendCmdBlocking_State = CMDMBOX_STATE_SENDCMD_BLOCKING_IDLE;
   1136 
   1137                     /* call the CmdQueue CB */
   1138                     rc = CmdQueue_SendCmplt(pCmdMBox->hCmdQueue);
   1139                     breakWhile = TRUE;
   1140                 }
   1141                 break;
   1142             default:
   1143                 WLAN_REPORT_ERROR(pCmdMBox->hReport, CMD_MBOX_MODULE_LOG,
   1144                     ("CmdMBox_SM_SendCmdBlocking: ** ERROR **  No such state (%d)\n",pCmdMBox->SendCmdBlocking_State));
   1145                     return NOK;
   1146         }
   1147     }
   1148 #if CMDMBOX_DEBUG_PRINT
   1149         WLAN_OS_REPORT(("CmdMBox_SM_SendCmdBlocking rc = %d\n",rc));
   1150 #endif
   1151     return rc;
   1152 }
   1153 #endif /* USE_SYNC_API */
   1154 /****************************************************************************
   1155  *                      CmdMBox_TimeOut()
   1156  ****************************************************************************
   1157  * DESCRIPTION:
   1158  *
   1159  * INPUTS:
   1160  *
   1161  * OUTPUT:  None
   1162  *
   1163  * RETURNS: OK, ERROR
   1164  ****************************************************************************/
   1165 void            CmdMBox_TimeOut(TI_HANDLE hCmdMBox)
   1166 {
   1167     CmdMBox_T* pCmdMBox = (CmdMBox_T*)hCmdMBox;
   1168 
   1169     WLAN_REPORT_ERROR(pCmdMBox->hReport, CMD_MBOX_MODULE_LOG,
   1170             ("CmdMBox_TimeOut: Timeout occured in CmdMBox\n"));
   1171 
   1172     /* call error CB */
   1173     CmdQueue_Error(pCmdMBox->hCmdQueue);
   1174 
   1175     return;
   1176 }
   1177 
   1178 /****************************************************************************
   1179  *                      CmdMbox_CheckAndAck()
   1180  ****************************************************************************
   1181  * DESCRIPTION: Check if HostIfReg is On
   1182  *              This function is used on SDIO only.
   1183  *
   1184  * INPUTS:
   1185  *
   1186  * OUTPUT:  None
   1187  *
   1188  * RETURNS: OK, ERROR
   1189  ****************************************************************************/
   1190 
   1191 int CmdMbox_CheckAndAck (TI_HANDLE hTNETWIF, UINT32 Intr)
   1192 {
   1193   #ifdef USE_SYNC_API
   1194 
   1195     UINT32 Reg_IntrNoClear;
   1196 
   1197     TNETWIF_ReadRegSync(hTNETWIF,ACX_REG_INTERRUPT_NO_CLEAR, &Reg_IntrNoClear);
   1198 
   1199     if (IS_MASK_ON (Reg_IntrNoClear, Intr))
   1200     {
   1201         TNETWIF_WriteRegSync (hTNETWIF, ACX_REG_INTERRUPT_ACK, Intr);
   1202         return 1;
   1203     }
   1204 
   1205   #endif /* USE_SYNC_API */
   1206 
   1207     return 0;
   1208 }
   1209 
   1210 TI_STATUS CmdMBox_GetStatus(TI_HANDLE hCmdMBox)
   1211 {
   1212     CmdMBox_T* pCmdMBox = (CmdMBox_T*)hCmdMBox;
   1213     TI_STATUS Status;
   1214     Status = (pCmdMBox->HW_CmdMBox.cmdStatus == CMD_STATUS_SUCCESS) ? OK : NOK;
   1215 
   1216 	switch (pCmdMBox->HW_CmdMBox.cmdStatus)
   1217     {
   1218 		case CMD_STATUS_SUCCESS:
   1219 		{
   1220             Status = OK;
   1221 			break;
   1222 		}
   1223 		case CMD_STATUS_REJECT_MEAS_SG_ACTIVE:
   1224 		{
   1225 			Status = SG_REJECT_MEAS_SG_ACTIVE;
   1226             break;
   1227 		}
   1228 		case CMD_MAILBOX_IDLE:
   1229 		case CMD_STATUS_UNKNOWN_CMD:
   1230 		case CMD_STATUS_UNKNOWN_IE:
   1231 		case CMD_STATUS_RX_BUSY:
   1232 		case CMD_STATUS_INVALID_PARAM:
   1233 		case CMD_STATUS_TEMPLATE_TOO_LARGE:
   1234 		case CMD_STATUS_OUT_OF_MEMORY:
   1235 		case CMD_STATUS_STA_TABLE_FULL:
   1236 		case CMD_STATUS_RADIO_ERROR:
   1237 		case CMD_STATUS_WRONG_NESTING:
   1238         case CMD_STATUS_TIMEOUT:
   1239 		case CMD_STATUS_FW_RESET:
   1240 		default:
   1241         {
   1242             Status = NOK;
   1243 			break;
   1244         }
   1245 	} /* end of switch */
   1246 
   1247     WLAN_REPORT_INFORMATION(pCmdMBox->hReport, HAL_HW_CTRL_MODULE_LOG,
   1248         ("%s - TI_STATUS = %s(%d) <= pCmdMBox->HW_CmdMBox.cmdStatus = %d\n", __FUNCTION__,
   1249         (Status==OK)?"OK":"NOK",Status, pCmdMBox->HW_CmdMBox.cmdStatus));
   1250 
   1251     return Status;
   1252 }
   1253 
   1254