2 ** $Id: //Department/DaVinci/BRANCHES/MT6620_WIFI_DRIVER_V2_3/nic/cmd_buf.c#1 $
6 \brief This file contain the management function of internal Command Buffer
9 We'll convert the OID into Command Packet and then send to FW. Thus we need
10 to copy the OID information to Command Buffer for following reasons.
11 1. The data structure of OID information may not equal to the data structure of
12 Command, we cannot use the OID buffer directly.
13 2. If the Command was not generated by driver we also need a place to store the
15 3. Because the CMD is NOT FIFO when doing memory allocation (CMD will be generated
16 from OID or interrupt handler), thus we'll use the Block style of Memory Allocation
27 * [WPD00003833] [MT6620 and MT5931] Driver migration - move to new repository.
30 * [WPD00003841][LITE Driver] Migrate RLM/CNM to host driver
31 * Provide cnmMgtPktAlloc() and alloc/free function of msg/buf
33 * 06 06 2010 kevin.huang
34 * [WPD00003832][MT6620 5931] Create driver base
35 * [MT6620 5931] Create driver base
38 * [WPD00001943]Create WiFi test driver framework on WinXP
39 * 1. clear prPendingCmdInfo properly
40 * * 2. while allocating memory for cmdinfo, no need to add extra 4 bytes.
41 ** \main\maintrunk.MT6620WiFiDriver_Prj\4 2009-10-13 21:59:08 GMT mtk01084
42 ** remove un-neceasary spaces
43 ** \main\maintrunk.MT6620WiFiDriver_Prj\3 2009-05-20 12:24:26 GMT mtk01461
44 ** Increase CMD Buffer - HIF_RX_HW_APPENDED_LEN when doing CMD_INFO_T allocation
45 ** \main\maintrunk.MT6620WiFiDriver_Prj\2 2009-04-21 09:41:08 GMT mtk01461
46 ** Add init of Driver Domain MCR flag and fix lint MTK WARN
47 ** \main\maintrunk.MT6620WiFiDriver_Prj\1 2009-04-17 19:51:45 GMT mtk01461
48 ** allocation function of CMD_INFO_T
51 /*******************************************************************************
52 * C O M P I L E R F L A G S
53 ********************************************************************************
56 /*******************************************************************************
57 * E X T E R N A L R E F E R E N C E S
58 ********************************************************************************
62 /*******************************************************************************
64 ********************************************************************************
67 /*******************************************************************************
69 ********************************************************************************
72 /*******************************************************************************
74 ********************************************************************************
77 /*******************************************************************************
78 * P R I V A T E D A T A
79 ********************************************************************************
82 /*******************************************************************************
84 ********************************************************************************
87 /*******************************************************************************
88 * F U N C T I O N D E C L A R A T I O N S
89 ********************************************************************************
92 /*******************************************************************************
94 ********************************************************************************
96 /*----------------------------------------------------------------------------*/
98 * @brief This function is used to initial the MGMT memory pool for CMD Packet.
100 * @param prAdapter Pointer to the Adapter structure.
104 /*----------------------------------------------------------------------------*/
107 IN P_ADAPTER_T prAdapter
110 P_CMD_INFO_T prCmdInfo;
115 QUEUE_INITIALIZE(&prAdapter->rFreeCmdList);
117 for (i = 0; i < CFG_TX_MAX_CMD_PKT_NUM; i++) {
118 prCmdInfo = &prAdapter->arHifCmdDesc[i];
119 QUEUE_INSERT_TAIL(&prAdapter->rFreeCmdList, &prCmdInfo->rQueEntry);
122 } /* end of cmdBufInitialize() */
125 /*----------------------------------------------------------------------------*/
127 * @brief Allocate CMD_INFO_T from a free list and MGMT memory pool.
129 * @param[in] prAdapter Pointer to the Adapter structure.
130 * @param[in] u4Length Length of the frame buffer to allocate.
132 * @retval NULL Pointer to the valid CMD Packet handler
133 * @retval !NULL Fail to allocat CMD Packet
135 /*----------------------------------------------------------------------------*/
137 cmdBufAllocateCmdInfo (
138 IN P_ADAPTER_T prAdapter,
142 P_CMD_INFO_T prCmdInfo;
143 KAL_SPIN_LOCK_DECLARATION();
145 DEBUGFUNC("cmdBufAllocateCmdInfo");
150 KAL_ACQUIRE_SPIN_LOCK(prAdapter, SPIN_LOCK_CMD_RESOURCE);
151 QUEUE_REMOVE_HEAD(&prAdapter->rFreeCmdList, prCmdInfo, P_CMD_INFO_T);
152 KAL_RELEASE_SPIN_LOCK(prAdapter, SPIN_LOCK_CMD_RESOURCE);
155 /* Setup initial value in CMD_INFO_T */
156 /* Start address of allocated memory */
157 prCmdInfo->pucInfoBuffer =
158 cnmMemAlloc(prAdapter, RAM_TYPE_BUF, u4Length);
160 if (prCmdInfo->pucInfoBuffer == NULL) {
161 KAL_ACQUIRE_SPIN_LOCK(prAdapter, SPIN_LOCK_CMD_RESOURCE);
162 QUEUE_INSERT_TAIL(&prAdapter->rFreeCmdList, &prCmdInfo->rQueEntry);
163 KAL_RELEASE_SPIN_LOCK(prAdapter, SPIN_LOCK_CMD_RESOURCE);
168 prCmdInfo->u2InfoBufLen = 0;
169 prCmdInfo->fgIsOid = FALSE;
170 prCmdInfo->fgDriverDomainMCR = FALSE;
176 } /* end of cmdBufAllocateCmdInfo() */
179 /*----------------------------------------------------------------------------*/
181 * @brief This function is used to free the CMD Packet to the MGMT memory pool.
183 * @param prAdapter Pointer to the Adapter structure.
184 * @param prCmdInfo CMD Packet handler
188 /*----------------------------------------------------------------------------*/
191 IN P_ADAPTER_T prAdapter,
192 IN P_CMD_INFO_T prCmdInfo
195 KAL_SPIN_LOCK_DECLARATION();
197 DEBUGFUNC("cmdBufFreeCmdInfo");
204 if (prCmdInfo->pucInfoBuffer) {
205 cnmMemFree(prAdapter, prCmdInfo->pucInfoBuffer);
206 prCmdInfo->pucInfoBuffer = NULL;
209 KAL_ACQUIRE_SPIN_LOCK(prAdapter, SPIN_LOCK_CMD_RESOURCE);
210 QUEUE_INSERT_TAIL(&prAdapter->rFreeCmdList, &prCmdInfo->rQueEntry);
211 KAL_RELEASE_SPIN_LOCK(prAdapter, SPIN_LOCK_CMD_RESOURCE);
216 } /* end of cmdBufFreeCmdPacket() */