add MTK-combo-module,continue with commit 17f39ed917874e77e80411f33faba1b7ee8138c8
[firefly-linux-kernel-4.4.55.git] / drivers / mtk_wcn_combo / drv_wlan / wlan / nic / cmd_buf.c
1 /*
2 ** $Id: //Department/DaVinci/BRANCHES/MT6620_WIFI_DRIVER_V2_2/nic/cmd_buf.c#1 $
3 */
4
5 /*! \file   "cmd_buf.c"
6     \brief  This file contain the management function of internal Command Buffer
7             for CMD_INFO_T.
8
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
14        information.
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
17        here.
18 */
19
20 /*******************************************************************************
21 * Copyright (c) 2007 MediaTek Inc.
22 *
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
26 * MediaTek Inc.
27 ********************************************************************************
28 */
29
30 /*******************************************************************************
31 * LEGAL DISCLAIMER
32 *
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.
46 *
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.
52 *
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
58 * (ICC).
59 ********************************************************************************
60 */
61
62 /*
63 ** $Log: cmd_buf.c $
64  *
65  * 03 18 2011 cp.wu
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
68  *
69  * 07 08 2010 cp.wu
70  * 
71  * [WPD00003833] [MT6620 and MT5931] Driver migration - move to new repository.
72  *
73  * 06 18 2010 cm.chang
74  * [WPD00003841][LITE Driver] Migrate RLM/CNM to host driver 
75  * Provide cnmMgtPktAlloc() and alloc/free function of msg/buf
76  *
77  * 06 06 2010 kevin.huang
78  * [WPD00003832][MT6620 5931] Create driver base
79  * [MT6620 5931] Create driver base
80  *
81  * 02 03 2010 cp.wu
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
93 */
94
95 /*******************************************************************************
96 *                         C O M P I L E R   F L A G S
97 ********************************************************************************
98 */
99
100 /*******************************************************************************
101 *                    E X T E R N A L   R E F E R E N C E S
102 ********************************************************************************
103 */
104 #include "precomp.h"
105
106 /*******************************************************************************
107 *                              C O N S T A N T S
108 ********************************************************************************
109 */
110
111 /*******************************************************************************
112 *                             D A T A   T Y P E S
113 ********************************************************************************
114 */
115
116 /*******************************************************************************
117 *                            P U B L I C   D A T A
118 ********************************************************************************
119 */
120
121 /*******************************************************************************
122 *                           P R I V A T E   D A T A
123 ********************************************************************************
124 */
125
126 /*******************************************************************************
127 *                                 M A C R O S
128 ********************************************************************************
129 */
130
131 /*******************************************************************************
132 *                   F U N C T I O N   D E C L A R A T I O N S
133 ********************************************************************************
134 */
135
136 /*******************************************************************************
137 *                              F U N C T I O N S
138 ********************************************************************************
139 */
140 /*----------------------------------------------------------------------------*/
141 /*!
142 * @brief This function is used to initial the MGMT memory pool for CMD Packet.
143 *
144 * @param prAdapter  Pointer to the Adapter structure.
145 *
146 * @return (none)
147 */
148 /*----------------------------------------------------------------------------*/
149 VOID
150 cmdBufInitialize (
151     IN P_ADAPTER_T  prAdapter
152     )
153 {
154     P_CMD_INFO_T    prCmdInfo;
155     UINT_32         i;
156
157     ASSERT(prAdapter);
158
159     QUEUE_INITIALIZE(&prAdapter->rFreeCmdList);
160
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);
164     }
165
166 } /* end of cmdBufInitialize() */
167
168
169 /*----------------------------------------------------------------------------*/
170 /*!
171 * @brief Allocate CMD_INFO_T from a free list and MGMT memory pool.
172 *
173 * @param[in] prAdapter      Pointer to the Adapter structure.
174 * @param[in] u4Length       Length of the frame buffer to allocate.
175 *
176 * @retval NULL      Pointer to the valid CMD Packet handler
177 * @retval !NULL     Fail to allocat CMD Packet
178 */
179 /*----------------------------------------------------------------------------*/
180 P_CMD_INFO_T
181 cmdBufAllocateCmdInfo (
182     IN P_ADAPTER_T  prAdapter,
183     IN UINT_32      u4Length
184     )
185 {
186     P_CMD_INFO_T    prCmdInfo;
187     KAL_SPIN_LOCK_DECLARATION();
188
189     DEBUGFUNC("cmdBufAllocateCmdInfo");
190
191
192     ASSERT(prAdapter);
193
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);
197
198     if (prCmdInfo) {
199         /* Setup initial value in CMD_INFO_T */
200         /* Start address of allocated memory */
201         prCmdInfo->pucInfoBuffer =
202                 cnmMemAlloc(prAdapter, RAM_TYPE_BUF, u4Length);
203
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);
208
209             prCmdInfo = NULL;
210         }
211         else {
212             prCmdInfo->u2InfoBufLen = 0;
213             prCmdInfo->fgIsOid = FALSE;
214             prCmdInfo->fgDriverDomainMCR = FALSE;
215         }
216     }
217
218     return prCmdInfo;
219
220 } /* end of cmdBufAllocateCmdInfo() */
221
222
223 /*----------------------------------------------------------------------------*/
224 /*!
225 * @brief This function is used to free the CMD Packet to the MGMT memory pool.
226 *
227 * @param prAdapter  Pointer to the Adapter structure.
228 * @param prCmdInfo  CMD Packet handler
229 *
230 * @return (none)
231 */
232 /*----------------------------------------------------------------------------*/
233 VOID
234 cmdBufFreeCmdInfo (
235     IN P_ADAPTER_T  prAdapter,
236     IN P_CMD_INFO_T prCmdInfo
237     )
238 {
239     KAL_SPIN_LOCK_DECLARATION();
240
241     DEBUGFUNC("cmdBufFreeCmdInfo");
242
243
244     ASSERT(prAdapter);
245     ASSERT(prCmdInfo);
246
247     if (prCmdInfo) {
248         if (prCmdInfo->pucInfoBuffer) {
249             cnmMemFree(prAdapter, prCmdInfo->pucInfoBuffer);
250             prCmdInfo->pucInfoBuffer = NULL;
251         }
252
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);
256     }
257
258     return;
259
260 } /* end of cmdBufFreeCmdPacket() */
261
262