2 ** $Id: //Department/DaVinci/BRANCHES/MT6620_WIFI_DRIVER_V2_2/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
20 /*******************************************************************************
21 * Copyright (c) 2007 MediaTek Inc.
23 * All rights reserved. Copying, compilation, modification, distribution
24 * or any other use whatsoever of this material is strictly prohibited
25 * except in accordance with a Software License Agreement with
27 ********************************************************************************
30 /*******************************************************************************
33 * BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND
34 * AGREES THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK
35 * SOFTWARE") RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE
36 * PROVIDED TO BUYER ON AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY
37 * DISCLAIMS ANY AND ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT
38 * LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
39 * PARTICULAR PURPOSE OR NONINFRINGEMENT. NEITHER DOES MEDIATEK PROVIDE
40 * ANY WARRANTY WHATSOEVER WITH RESPECT TO THE SOFTWARE OF ANY THIRD PARTY
41 * WHICH MAY BE USED BY, INCORPORATED IN, OR SUPPLIED WITH THE MEDIATEK
42 * SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH THIRD PARTY FOR ANY
43 * WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE
44 * FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S SPECIFICATION OR TO
45 * CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
47 * BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
48 * LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL
49 * BE, AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT
50 * ISSUE, OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY
51 * BUYER TO MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
53 * THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
54 * WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT
55 * OF LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING
56 * THEREOF AND RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN
57 * FRANCISCO, CA, UNDER THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE
59 ********************************************************************************
66 * [WCXRP00000577] [MT6620 Wi-Fi][Driver][FW] Create V2.0 branch for firmware and driver
67 * create V2.0 driver release based on label "MT6620_WIFI_DRIVER_V2_0_110318_1600" from main trunk
71 * [WPD00003833] [MT6620 and MT5931] Driver migration - move to new repository.
74 * [WPD00003841][LITE Driver] Migrate RLM/CNM to host driver
75 * Provide cnmMgtPktAlloc() and alloc/free function of msg/buf
77 * 06 06 2010 kevin.huang
78 * [WPD00003832][MT6620 5931] Create driver base
79 * [MT6620 5931] Create driver base
82 * [WPD00001943]Create WiFi test driver framework on WinXP
83 * 1. clear prPendingCmdInfo properly
84 * * 2. while allocating memory for cmdinfo, no need to add extra 4 bytes.
85 ** \main\maintrunk.MT6620WiFiDriver_Prj\4 2009-10-13 21:59:08 GMT mtk01084
86 ** remove un-neceasary spaces
87 ** \main\maintrunk.MT6620WiFiDriver_Prj\3 2009-05-20 12:24:26 GMT mtk01461
88 ** Increase CMD Buffer - HIF_RX_HW_APPENDED_LEN when doing CMD_INFO_T allocation
89 ** \main\maintrunk.MT6620WiFiDriver_Prj\2 2009-04-21 09:41:08 GMT mtk01461
90 ** Add init of Driver Domain MCR flag and fix lint MTK WARN
91 ** \main\maintrunk.MT6620WiFiDriver_Prj\1 2009-04-17 19:51:45 GMT mtk01461
92 ** allocation function of CMD_INFO_T
95 /*******************************************************************************
96 * C O M P I L E R F L A G S
97 ********************************************************************************
100 /*******************************************************************************
101 * E X T E R N A L R E F E R E N C E S
102 ********************************************************************************
106 /*******************************************************************************
108 ********************************************************************************
111 /*******************************************************************************
113 ********************************************************************************
116 /*******************************************************************************
117 * P U B L I C D A T A
118 ********************************************************************************
121 /*******************************************************************************
122 * P R I V A T E D A T A
123 ********************************************************************************
126 /*******************************************************************************
128 ********************************************************************************
131 /*******************************************************************************
132 * F U N C T I O N D E C L A R A T I O N S
133 ********************************************************************************
136 /*******************************************************************************
138 ********************************************************************************
140 /*----------------------------------------------------------------------------*/
142 * @brief This function is used to initial the MGMT memory pool for CMD Packet.
144 * @param prAdapter Pointer to the Adapter structure.
148 /*----------------------------------------------------------------------------*/
151 IN P_ADAPTER_T prAdapter
154 P_CMD_INFO_T prCmdInfo;
159 QUEUE_INITIALIZE(&prAdapter->rFreeCmdList);
161 for (i = 0; i < CFG_TX_MAX_CMD_PKT_NUM; i++) {
162 prCmdInfo = &prAdapter->arHifCmdDesc[i];
163 QUEUE_INSERT_TAIL(&prAdapter->rFreeCmdList, &prCmdInfo->rQueEntry);
166 } /* end of cmdBufInitialize() */
169 /*----------------------------------------------------------------------------*/
171 * @brief Allocate CMD_INFO_T from a free list and MGMT memory pool.
173 * @param[in] prAdapter Pointer to the Adapter structure.
174 * @param[in] u4Length Length of the frame buffer to allocate.
176 * @retval NULL Pointer to the valid CMD Packet handler
177 * @retval !NULL Fail to allocat CMD Packet
179 /*----------------------------------------------------------------------------*/
181 cmdBufAllocateCmdInfo (
182 IN P_ADAPTER_T prAdapter,
186 P_CMD_INFO_T prCmdInfo;
187 KAL_SPIN_LOCK_DECLARATION();
189 DEBUGFUNC("cmdBufAllocateCmdInfo");
194 KAL_ACQUIRE_SPIN_LOCK(prAdapter, SPIN_LOCK_CMD_RESOURCE);
195 QUEUE_REMOVE_HEAD(&prAdapter->rFreeCmdList, prCmdInfo, P_CMD_INFO_T);
196 KAL_RELEASE_SPIN_LOCK(prAdapter, SPIN_LOCK_CMD_RESOURCE);
199 /* Setup initial value in CMD_INFO_T */
200 /* Start address of allocated memory */
201 prCmdInfo->pucInfoBuffer =
202 cnmMemAlloc(prAdapter, RAM_TYPE_BUF, u4Length);
204 if (prCmdInfo->pucInfoBuffer == NULL) {
205 KAL_ACQUIRE_SPIN_LOCK(prAdapter, SPIN_LOCK_CMD_RESOURCE);
206 QUEUE_INSERT_TAIL(&prAdapter->rFreeCmdList, &prCmdInfo->rQueEntry);
207 KAL_RELEASE_SPIN_LOCK(prAdapter, SPIN_LOCK_CMD_RESOURCE);
212 prCmdInfo->u2InfoBufLen = 0;
213 prCmdInfo->fgIsOid = FALSE;
214 prCmdInfo->fgDriverDomainMCR = FALSE;
220 } /* end of cmdBufAllocateCmdInfo() */
223 /*----------------------------------------------------------------------------*/
225 * @brief This function is used to free the CMD Packet to the MGMT memory pool.
227 * @param prAdapter Pointer to the Adapter structure.
228 * @param prCmdInfo CMD Packet handler
232 /*----------------------------------------------------------------------------*/
235 IN P_ADAPTER_T prAdapter,
236 IN P_CMD_INFO_T prCmdInfo
239 KAL_SPIN_LOCK_DECLARATION();
241 DEBUGFUNC("cmdBufFreeCmdInfo");
248 if (prCmdInfo->pucInfoBuffer) {
249 cnmMemFree(prAdapter, prCmdInfo->pucInfoBuffer);
250 prCmdInfo->pucInfoBuffer = NULL;
253 KAL_ACQUIRE_SPIN_LOCK(prAdapter, SPIN_LOCK_CMD_RESOURCE);
254 QUEUE_INSERT_TAIL(&prAdapter->rFreeCmdList, &prCmdInfo->rQueEntry);
255 KAL_RELEASE_SPIN_LOCK(prAdapter, SPIN_LOCK_CMD_RESOURCE);
260 } /* end of cmdBufFreeCmdPacket() */