PageRenderTime 58ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 1ms

/drivers/net/wireless/tiwlan1251/common/src/TNETW_Driver/FW_Transfer/Cmd_MBox/CmdMBox.c

https://bitbucket.org/cyanogenmod/cm-kernel
C | 1253 lines | 797 code | 125 blank | 331 comment | 47 complexity | 3d92c9cb047af866895ad5749370fd46 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.0, AGPL-1.0

Large files files are truncated, but you can click here to view the full file

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

Large files files are truncated, but you can click here to view the full file