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