support different wifi bt chip auto compatible
[firefly-linux-kernel-4.4.55.git] / drivers / net / wireless / rockchip_wlan / combo_mt66xx / mt6620 / wlan / nic / cmd_buf.c
1 /*
2 ** $Id: //Department/DaVinci/BRANCHES/MT6620_WIFI_DRIVER_V2_3/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
22 /*
23 ** $Log: cmd_buf.c $
24  *
25  * 07 08 2010 cp.wu
26  * 
27  * [WPD00003833] [MT6620 and MT5931] Driver migration - move to new repository.
28  *
29  * 06 18 2010 cm.chang
30  * [WPD00003841][LITE Driver] Migrate RLM/CNM to host driver 
31  * Provide cnmMgtPktAlloc() and alloc/free function of msg/buf
32  *
33  * 06 06 2010 kevin.huang
34  * [WPD00003832][MT6620 5931] Create driver base
35  * [MT6620 5931] Create driver base
36  *
37  * 02 03 2010 cp.wu
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
49 */
50
51 /*******************************************************************************
52 *                         C O M P I L E R   F L A G S
53 ********************************************************************************
54 */
55
56 /*******************************************************************************
57 *                    E X T E R N A L   R E F E R E N C E S
58 ********************************************************************************
59 */
60 #include "precomp.h"
61
62 /*******************************************************************************
63 *                              C O N S T A N T S
64 ********************************************************************************
65 */
66
67 /*******************************************************************************
68 *                             D A T A   T Y P E S
69 ********************************************************************************
70 */
71
72 /*******************************************************************************
73 *                            P U B L I C   D A T A
74 ********************************************************************************
75 */
76
77 /*******************************************************************************
78 *                           P R I V A T E   D A T A
79 ********************************************************************************
80 */
81
82 /*******************************************************************************
83 *                                 M A C R O S
84 ********************************************************************************
85 */
86
87 /*******************************************************************************
88 *                   F U N C T I O N   D E C L A R A T I O N S
89 ********************************************************************************
90 */
91
92 /*******************************************************************************
93 *                              F U N C T I O N S
94 ********************************************************************************
95 */
96 /*----------------------------------------------------------------------------*/
97 /*!
98 * @brief This function is used to initial the MGMT memory pool for CMD Packet.
99 *
100 * @param prAdapter  Pointer to the Adapter structure.
101 *
102 * @return (none)
103 */
104 /*----------------------------------------------------------------------------*/
105 VOID
106 cmdBufInitialize (
107     IN P_ADAPTER_T  prAdapter
108     )
109 {
110     P_CMD_INFO_T    prCmdInfo;
111     UINT_32         i;
112
113     ASSERT(prAdapter);
114
115     QUEUE_INITIALIZE(&prAdapter->rFreeCmdList);
116
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);
120     }
121
122 } /* end of cmdBufInitialize() */
123
124
125 /*----------------------------------------------------------------------------*/
126 /*!
127 * @brief Allocate CMD_INFO_T from a free list and MGMT memory pool.
128 *
129 * @param[in] prAdapter      Pointer to the Adapter structure.
130 * @param[in] u4Length       Length of the frame buffer to allocate.
131 *
132 * @retval NULL      Pointer to the valid CMD Packet handler
133 * @retval !NULL     Fail to allocat CMD Packet
134 */
135 /*----------------------------------------------------------------------------*/
136 P_CMD_INFO_T
137 cmdBufAllocateCmdInfo (
138     IN P_ADAPTER_T  prAdapter,
139     IN UINT_32      u4Length
140     )
141 {
142     P_CMD_INFO_T    prCmdInfo;
143     KAL_SPIN_LOCK_DECLARATION();
144
145     DEBUGFUNC("cmdBufAllocateCmdInfo");
146
147
148     ASSERT(prAdapter);
149
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);
153
154     if (prCmdInfo) {
155         /* Setup initial value in CMD_INFO_T */
156         /* Start address of allocated memory */
157         prCmdInfo->pucInfoBuffer =
158                 cnmMemAlloc(prAdapter, RAM_TYPE_BUF, u4Length);
159
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);
164
165             prCmdInfo = NULL;
166         }
167         else {
168             prCmdInfo->u2InfoBufLen = 0;
169             prCmdInfo->fgIsOid = FALSE;
170             prCmdInfo->fgDriverDomainMCR = FALSE;
171         }
172     }
173
174     return prCmdInfo;
175
176 } /* end of cmdBufAllocateCmdInfo() */
177
178
179 /*----------------------------------------------------------------------------*/
180 /*!
181 * @brief This function is used to free the CMD Packet to the MGMT memory pool.
182 *
183 * @param prAdapter  Pointer to the Adapter structure.
184 * @param prCmdInfo  CMD Packet handler
185 *
186 * @return (none)
187 */
188 /*----------------------------------------------------------------------------*/
189 VOID
190 cmdBufFreeCmdInfo (
191     IN P_ADAPTER_T  prAdapter,
192     IN P_CMD_INFO_T prCmdInfo
193     )
194 {
195     KAL_SPIN_LOCK_DECLARATION();
196
197     DEBUGFUNC("cmdBufFreeCmdInfo");
198
199
200     ASSERT(prAdapter);
201     ASSERT(prCmdInfo);
202
203     if (prCmdInfo) {
204         if (prCmdInfo->pucInfoBuffer) {
205             cnmMemFree(prAdapter, prCmdInfo->pucInfoBuffer);
206             prCmdInfo->pucInfoBuffer = NULL;
207         }
208
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);
212     }
213
214     return;
215
216 } /* end of cmdBufFreeCmdPacket() */
217
218