cmd_buf.c 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. /*
  2. ** Id: //Department/DaVinci/BRANCHES/MT6620_WIFI_DRIVER_V2_3/nic/cmd_buf.c#1
  3. */
  4. /*! \file "cmd_buf.c"
  5. \brief This file contain the management function of internal Command Buffer
  6. for CMD_INFO_T.
  7. We'll convert the OID into Command Packet and then send to FW. Thus we need
  8. to copy the OID information to Command Buffer for following reasons.
  9. 1. The data structure of OID information may not equal to the data structure of
  10. Command, we cannot use the OID buffer directly.
  11. 2. If the Command was not generated by driver we also need a place to store the
  12. information.
  13. 3. Because the CMD is NOT FIFO when doing memory allocation (CMD will be generated
  14. from OID or interrupt handler), thus we'll use the Block style of Memory Allocation
  15. here.
  16. */
  17. /*
  18. ** Log: cmd_buf.c
  19. *
  20. * 07 08 2010 cp.wu
  21. *
  22. * [WPD00003833] [MT6620 and MT5931] Driver migration - move to new repository.
  23. *
  24. * 06 18 2010 cm.chang
  25. * [WPD00003841][LITE Driver] Migrate RLM/CNM to host driver
  26. * Provide cnmMgtPktAlloc() and alloc/free function of msg/buf
  27. *
  28. * 06 06 2010 kevin.huang
  29. * [WPD00003832][MT6620 5931] Create driver base
  30. * [MT6620 5931] Create driver base
  31. *
  32. * 02 03 2010 cp.wu
  33. * [WPD00001943]Create WiFi test driver framework on WinXP
  34. * 1. clear prPendingCmdInfo properly
  35. * * 2. while allocating memory for cmdinfo, no need to add extra 4 bytes.
  36. ** \main\maintrunk.MT6620WiFiDriver_Prj\4 2009-10-13 21:59:08 GMT mtk01084
  37. ** remove un-neceasary spaces
  38. ** \main\maintrunk.MT6620WiFiDriver_Prj\3 2009-05-20 12:24:26 GMT mtk01461
  39. ** Increase CMD Buffer - HIF_RX_HW_APPENDED_LEN when doing CMD_INFO_T allocation
  40. ** \main\maintrunk.MT6620WiFiDriver_Prj\2 2009-04-21 09:41:08 GMT mtk01461
  41. ** Add init of Driver Domain MCR flag and fix lint MTK WARN
  42. ** \main\maintrunk.MT6620WiFiDriver_Prj\1 2009-04-17 19:51:45 GMT mtk01461
  43. ** allocation function of CMD_INFO_T
  44. */
  45. /*******************************************************************************
  46. * C O M P I L E R F L A G S
  47. ********************************************************************************
  48. */
  49. /*******************************************************************************
  50. * E X T E R N A L R E F E R E N C E S
  51. ********************************************************************************
  52. */
  53. #include "precomp.h"
  54. /*******************************************************************************
  55. * C O N S T A N T S
  56. ********************************************************************************
  57. */
  58. /*******************************************************************************
  59. * D A T A T Y P E S
  60. ********************************************************************************
  61. */
  62. /*******************************************************************************
  63. * P U B L I C D A T A
  64. ********************************************************************************
  65. */
  66. /*******************************************************************************
  67. * P R I V A T E D A T A
  68. ********************************************************************************
  69. */
  70. static BOOLEAN fgCmdDumpIsDone = FALSE;
  71. /*******************************************************************************
  72. * M A C R O S
  73. ********************************************************************************
  74. */
  75. /*******************************************************************************
  76. * F U N C T I O N D E C L A R A T I O N S
  77. ********************************************************************************
  78. */
  79. /*******************************************************************************
  80. * F U N C T I O N S
  81. ********************************************************************************
  82. */
  83. /*----------------------------------------------------------------------------*/
  84. /*!
  85. * @brief This function is used to initial the MGMT memory pool for CMD Packet.
  86. *
  87. * @param prAdapter Pointer to the Adapter structure.
  88. *
  89. * @return (none)
  90. */
  91. /*----------------------------------------------------------------------------*/
  92. VOID cmdBufInitialize(IN P_ADAPTER_T prAdapter)
  93. {
  94. P_CMD_INFO_T prCmdInfo;
  95. UINT_32 i;
  96. ASSERT(prAdapter);
  97. QUEUE_INITIALIZE(&prAdapter->rFreeCmdList);
  98. for (i = 0; i < CFG_TX_MAX_CMD_PKT_NUM; i++) {
  99. prCmdInfo = &prAdapter->arHifCmdDesc[i];
  100. QUEUE_INSERT_TAIL(&prAdapter->rFreeCmdList, &prCmdInfo->rQueEntry);
  101. }
  102. fgCmdDumpIsDone = FALSE;
  103. } /* end of cmdBufInitialize() */
  104. /*----------------------------------------------------------------------------*/
  105. /*!
  106. * @brief dump CMD queue and print to trace, for debug use only
  107. * @param[in] prQueue Pointer to the command Queue to be dumped
  108. * @param[in] quename Name of the queue
  109. */
  110. /*----------------------------------------------------------------------------*/
  111. VOID cmdBufDumpCmdQueue(P_QUE_T prQueue, CHAR *queName)
  112. {
  113. P_CMD_INFO_T prCmdInfo = (P_CMD_INFO_T)QUEUE_GET_HEAD(prQueue);
  114. DBGLOG(NIC, INFO, "Dump CMD info for %s, Elem number:%u\n", queName, prQueue->u4NumElem);
  115. while (prCmdInfo) {
  116. P_CMD_INFO_T prCmdInfo1, prCmdInfo2, prCmdInfo3;
  117. prCmdInfo1 = (P_CMD_INFO_T)QUEUE_GET_NEXT_ENTRY((P_QUE_ENTRY_T)prCmdInfo);
  118. if (!prCmdInfo1) {
  119. DBGLOG(NIC, INFO, "CID:%d SEQ:%d\n", prCmdInfo->ucCID, prCmdInfo->ucCmdSeqNum);
  120. break;
  121. }
  122. prCmdInfo2 = (P_CMD_INFO_T)QUEUE_GET_NEXT_ENTRY((P_QUE_ENTRY_T)prCmdInfo1);
  123. if (!prCmdInfo2) {
  124. DBGLOG(NIC, INFO, "CID:%d, SEQ:%d; CID:%d, SEQ:%d\n", prCmdInfo->ucCID,
  125. prCmdInfo->ucCmdSeqNum, prCmdInfo1->ucCID, prCmdInfo1->ucCmdSeqNum);
  126. break;
  127. }
  128. prCmdInfo3 = (P_CMD_INFO_T)QUEUE_GET_NEXT_ENTRY((P_QUE_ENTRY_T)prCmdInfo2);
  129. if (!prCmdInfo3) {
  130. DBGLOG(NIC, INFO, "CID:%d, SEQ:%d; CID:%d, SEQ:%d; CID:%d, SEQ:%d\n", prCmdInfo->ucCID,
  131. prCmdInfo->ucCmdSeqNum, prCmdInfo1->ucCID, prCmdInfo1->ucCmdSeqNum,
  132. prCmdInfo2->ucCID, prCmdInfo2->ucCmdSeqNum);
  133. break;
  134. }
  135. DBGLOG(NIC, INFO, "CID:%d, SEQ:%d; CID:%d, SEQ:%d; CID:%d, SEQ:%d; CID:%d, SEQ:%d\n",
  136. prCmdInfo->ucCID, prCmdInfo->ucCmdSeqNum, prCmdInfo1->ucCID,
  137. prCmdInfo1->ucCmdSeqNum, prCmdInfo2->ucCID, prCmdInfo2->ucCmdSeqNum,
  138. prCmdInfo3->ucCID, prCmdInfo3->ucCmdSeqNum);
  139. prCmdInfo = (P_CMD_INFO_T)QUEUE_GET_NEXT_ENTRY((P_QUE_ENTRY_T)prCmdInfo3);
  140. }
  141. }
  142. /*----------------------------------------------------------------------------*/
  143. /*!
  144. * @brief Allocate CMD_INFO_T from a free list and MGMT memory pool.
  145. *
  146. * @param[in] prAdapter Pointer to the Adapter structure.
  147. * @param[in] u4Length Length of the frame buffer to allocate.
  148. *
  149. * @retval NULL Pointer to the valid CMD Packet handler
  150. * @retval !NULL Fail to allocat CMD Packet
  151. */
  152. /*----------------------------------------------------------------------------*/
  153. P_CMD_INFO_T cmdBufAllocateCmdInfo(IN P_ADAPTER_T prAdapter, IN UINT_32 u4Length)
  154. {
  155. P_CMD_INFO_T prCmdInfo;
  156. KAL_SPIN_LOCK_DECLARATION();
  157. DEBUGFUNC("cmdBufAllocateCmdInfo");
  158. ASSERT(prAdapter);
  159. KAL_ACQUIRE_SPIN_LOCK(prAdapter, SPIN_LOCK_CMD_RESOURCE);
  160. QUEUE_REMOVE_HEAD(&prAdapter->rFreeCmdList, prCmdInfo, P_CMD_INFO_T);
  161. KAL_RELEASE_SPIN_LOCK(prAdapter, SPIN_LOCK_CMD_RESOURCE);
  162. if (prCmdInfo) {
  163. /* Setup initial value in CMD_INFO_T */
  164. /* Start address of allocated memory */
  165. prCmdInfo->pucInfoBuffer = cnmMemAlloc(prAdapter, RAM_TYPE_BUF, u4Length);
  166. if (prCmdInfo->pucInfoBuffer == NULL) {
  167. KAL_ACQUIRE_SPIN_LOCK(prAdapter, SPIN_LOCK_CMD_RESOURCE);
  168. QUEUE_INSERT_TAIL(&prAdapter->rFreeCmdList, &prCmdInfo->rQueEntry);
  169. KAL_RELEASE_SPIN_LOCK(prAdapter, SPIN_LOCK_CMD_RESOURCE);
  170. prCmdInfo = NULL;
  171. DBGLOG(NIC, ERROR, "Allocate prCmdInfo->pucInfoBuffer fail!\n");
  172. } else {
  173. prCmdInfo->u2InfoBufLen = 0;
  174. prCmdInfo->fgIsOid = FALSE;
  175. prCmdInfo->fgDriverDomainMCR = FALSE;
  176. }
  177. fgCmdDumpIsDone = FALSE;
  178. } else if (!fgCmdDumpIsDone) {
  179. P_GLUE_INFO_T prGlueInfo = prAdapter->prGlueInfo;
  180. P_QUE_T prCmdQue = &prGlueInfo->rCmdQueue;
  181. P_QUE_T prPendingCmdQue = &prAdapter->rPendingCmdQueue;
  182. P_TX_TCQ_STATUS_T prTc = &prAdapter->rTxCtrl.rTc;
  183. fgCmdDumpIsDone = TRUE;
  184. cmdBufDumpCmdQueue(prCmdQue, "waiting Tx CMD queue");
  185. cmdBufDumpCmdQueue(prPendingCmdQue, "waiting response CMD queue");
  186. DBGLOG(NIC, INFO, "Tc4 number:%d\n", prTc->aucFreeBufferCount[TC4_INDEX]);
  187. }
  188. return prCmdInfo;
  189. } /* end of cmdBufAllocateCmdInfo() */
  190. /*----------------------------------------------------------------------------*/
  191. /*!
  192. * @brief This function is used to free the CMD Packet to the MGMT memory pool.
  193. *
  194. * @param prAdapter Pointer to the Adapter structure.
  195. * @param prCmdInfo CMD Packet handler
  196. *
  197. * @return (none)
  198. */
  199. /*----------------------------------------------------------------------------*/
  200. VOID cmdBufFreeCmdInfo(IN P_ADAPTER_T prAdapter, IN P_CMD_INFO_T prCmdInfo)
  201. {
  202. KAL_SPIN_LOCK_DECLARATION();
  203. DEBUGFUNC("cmdBufFreeCmdInfo");
  204. ASSERT(prAdapter);
  205. ASSERT(prCmdInfo);
  206. if (prCmdInfo) {
  207. if (prCmdInfo->pucInfoBuffer) {
  208. cnmMemFree(prAdapter, prCmdInfo->pucInfoBuffer);
  209. prCmdInfo->pucInfoBuffer = NULL;
  210. }
  211. KAL_ACQUIRE_SPIN_LOCK(prAdapter, SPIN_LOCK_CMD_RESOURCE);
  212. QUEUE_INSERT_TAIL(&prAdapter->rFreeCmdList, &prCmdInfo->rQueEntry);
  213. KAL_RELEASE_SPIN_LOCK(prAdapter, SPIN_LOCK_CMD_RESOURCE);
  214. }
  215. return;
  216. } /* end of cmdBufFreeCmdPacket() */