0
|
1 |
/*
|
|
2 |
* txHwQueue.c
|
|
3 |
*
|
|
4 |
* Copyright(c) 1998 - 2010 Texas Instruments. All rights reserved.
|
|
5 |
* All rights reserved.
|
|
6 |
*
|
|
7 |
* This program and the accompanying materials are made available under the
|
|
8 |
* terms of the Eclipse Public License v1.0 or BSD License which accompanies
|
|
9 |
* this distribution. The Eclipse Public License is available at
|
|
10 |
* http://www.eclipse.org/legal/epl-v10.html and the BSD License is as below.
|
|
11 |
*
|
|
12 |
* Redistribution and use in source and binary forms, with or without
|
|
13 |
* modification, are permitted provided that the following conditions
|
|
14 |
* are met:
|
|
15 |
*
|
|
16 |
* * Redistributions of source code must retain the above copyright
|
|
17 |
* notice, this list of conditions and the following disclaimer.
|
|
18 |
* * Redistributions in binary form must reproduce the above copyright
|
|
19 |
* notice, this list of conditions and the following disclaimer in
|
|
20 |
* the documentation and/or other materials provided with the
|
|
21 |
* distribution.
|
|
22 |
* * Neither the name Texas Instruments nor the names of its
|
|
23 |
* contributors may be used to endorse or promote products derived
|
|
24 |
* from this software without specific prior written permission.
|
|
25 |
*
|
|
26 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
27 |
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
28 |
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
29 |
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
30 |
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
31 |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
32 |
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
33 |
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
34 |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
35 |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
36 |
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
37 |
*/
|
|
38 |
|
|
39 |
|
|
40 |
/****************************************************************************
|
|
41 |
*
|
|
42 |
* MODULE: txHwQueue.c
|
|
43 |
*
|
|
44 |
* PURPOSE: manage the wlan hardware Tx memory blocks allocation per queue.
|
|
45 |
*
|
|
46 |
* DESCRIPTION:
|
|
47 |
* ============
|
|
48 |
* This module is responsible for the HW Tx data-blocks and descriptors allocation.
|
|
49 |
* The HW Tx blocks are allocated in the driver by rough calculations without
|
|
50 |
* accessing the FW.
|
|
51 |
* They are freed according to FW counters that are provided by the FwEvent module
|
|
52 |
* on every FW interrupt.
|
|
53 |
****************************************************************************/
|
|
54 |
#define __FILE_ID__ FILE_ID_100
|
|
55 |
#include "osApi.h"
|
|
56 |
#include "report.h"
|
|
57 |
#include "TWDriver.h"
|
|
58 |
#include "txCtrlBlk_api.h"
|
|
59 |
#include "txHwQueue_api.h"
|
|
60 |
|
|
61 |
|
|
62 |
/* Translate input TID to AC */
|
|
63 |
/* Note: This structure is shared with other modules */
|
|
64 |
const EAcTrfcType WMEQosTagToACTable[MAX_NUM_OF_802_1d_TAGS] =
|
|
65 |
{QOS_AC_BE, QOS_AC_BK, QOS_AC_BK, QOS_AC_BE, QOS_AC_VI, QOS_AC_VI, QOS_AC_VO, QOS_AC_VO};
|
|
66 |
|
|
67 |
/*
|
|
68 |
* Local definitions:
|
|
69 |
*/
|
|
70 |
|
|
71 |
/* Spare blocks written in extraMemBlks field in TxDescriptor for HW use */
|
|
72 |
#define BLKS_HW_ALLOC_SPARE 3
|
|
73 |
|
|
74 |
/* Set queue's backpressure bit (indicates queue state changed from ready to busy or inversely). */
|
|
75 |
#define SET_QUEUE_BACKPRESSURE(pBackpressure, uQueueId) (*pBackpressure |= (1 << uQueueId))
|
|
76 |
|
|
77 |
/* Callback function definition for UpdateBusyMap */
|
|
78 |
typedef void (* tUpdateBusyMapCb)(TI_HANDLE hCbHndl, TI_UINT32 uBackpressure);
|
|
79 |
|
|
80 |
/* Per Queue HW blocks accounting data: */
|
|
81 |
typedef struct
|
|
82 |
{
|
|
83 |
TI_UINT32 uNumBlksThresh; /* Minimum HW blocks that must be reserved for this Queue. */
|
|
84 |
TI_UINT32 uNumBlksUsed; /* Number of HW blocks that are currently allocated for this Queue. */
|
|
85 |
TI_UINT32 uNumBlksReserved; /* Number of HW blocks currently reserved for this Queue (to guarentee the low threshold). */
|
|
86 |
TI_UINT32 uAllocatedBlksCntr; /* Accumulates allocated blocks for FW freed-blocks counter coordination. */
|
|
87 |
TI_UINT32 uFwFreedBlksCntr; /* Accumulated freed blocks in FW. */
|
|
88 |
TI_UINT32 uNumBlksCausedBusy; /* Number of HW blocks that caused queue busy state. */
|
|
89 |
TI_BOOL bQueueBusy; /* If TI_TRUE, this queue is currently stopped. */
|
|
90 |
TI_UINT16 uPercentOfBlkLowThresh; /* Configured percentage of blocks to use as the queue's low allocation threshold */
|
|
91 |
TI_UINT16 uPercentOfBlkHighThresh; /* Configured percentage of blocks to use as the queue's high allocation threshold */
|
|
92 |
|
|
93 |
} TTxHwQueueInfo;
|
|
94 |
|
|
95 |
typedef struct
|
|
96 |
{
|
|
97 |
TI_HANDLE hOs;
|
|
98 |
TI_HANDLE hReport;
|
|
99 |
|
|
100 |
tUpdateBusyMapCb fUpdateBusyMapCb; /* The upper layers UpdateBusyMap callback */
|
|
101 |
TI_HANDLE hUpdateBusyMapHndl;/* The handle for the fUpdateBusyMapCb */
|
|
102 |
|
|
103 |
TI_UINT32 uNumTotalBlks; /* The total number of Tx blocks */
|
|
104 |
TI_UINT32 uNumTotalBlksFree; /* Total number of free HW blocks */
|
|
105 |
TI_UINT32 uNumTotalBlksReserved; /* Total number of free but reserved HW blocks */
|
|
106 |
TI_UINT32 uNumUsedDescriptors; /* Total number of packets in the FW. */
|
|
107 |
TI_UINT8 uFwTxResultsCntr; /* Accumulated freed descriptors in FW. */
|
|
108 |
TI_UINT8 uDrvTxPacketsCntr; /* Accumulated allocated descriptors in driver. */
|
|
109 |
|
|
110 |
TTxHwQueueInfo aTxHwQueueInfo[MAX_NUM_OF_AC]; /* The per queue variables */
|
|
111 |
|
|
112 |
} TTxHwQueue;
|
|
113 |
|
|
114 |
|
|
115 |
static void txHwQueue_UpdateFreeBlocks (TTxHwQueue *pTxHwQueue, TI_UINT32 uQueueId, TI_UINT32 uFreeBlocks);
|
|
116 |
static TI_UINT32 txHwQueue_CheckResources (TTxHwQueue *pTxHwQueue, TTxHwQueueInfo *pQueueInfo);
|
|
117 |
|
|
118 |
|
|
119 |
|
|
120 |
/****************************************************************************
|
|
121 |
* txHwQueue_Create()
|
|
122 |
****************************************************************************
|
|
123 |
* DESCRIPTION: Create the Tx buffers pool object
|
|
124 |
*
|
|
125 |
* INPUTS: None
|
|
126 |
*
|
|
127 |
* OUTPUT: None
|
|
128 |
*
|
|
129 |
* RETURNS: The Created object
|
|
130 |
****************************************************************************/
|
|
131 |
TI_HANDLE txHwQueue_Create (TI_HANDLE hOs)
|
|
132 |
{
|
|
133 |
TTxHwQueue *pTxHwQueue;
|
|
134 |
|
|
135 |
pTxHwQueue = os_memoryAlloc(hOs, sizeof(TTxHwQueue),MemoryNormal);
|
|
136 |
if (pTxHwQueue == NULL)
|
|
137 |
{
|
|
138 |
return NULL;
|
|
139 |
}
|
|
140 |
|
|
141 |
os_memoryZero(hOs, pTxHwQueue, sizeof(TTxHwQueue));
|
|
142 |
|
|
143 |
pTxHwQueue->hOs = hOs;
|
|
144 |
|
|
145 |
return (TI_HANDLE)pTxHwQueue;
|
|
146 |
}
|
|
147 |
|
|
148 |
/****************************************************************************
|
|
149 |
* txHwQueue_Destroy()
|
|
150 |
****************************************************************************
|
|
151 |
* DESCRIPTION: Destroy the Tx buffers pool object
|
|
152 |
*
|
|
153 |
* INPUTS: hTxHwQueue - The object to free
|
|
154 |
*
|
|
155 |
* OUTPUT: None
|
|
156 |
*
|
|
157 |
* RETURNS: TI_OK or TI_NOK
|
|
158 |
****************************************************************************/
|
|
159 |
TI_STATUS txHwQueue_Destroy (TI_HANDLE hTxHwQueue)
|
|
160 |
{
|
|
161 |
TTxHwQueue *pTxHwQueue = (TTxHwQueue *)hTxHwQueue;
|
|
162 |
|
|
163 |
if (pTxHwQueue)
|
|
164 |
{
|
|
165 |
os_memoryFree(pTxHwQueue->hOs, pTxHwQueue, sizeof(TTxHwQueue));
|
|
166 |
}
|
|
167 |
return TI_OK;
|
|
168 |
}
|
|
169 |
|
|
170 |
|
|
171 |
|
|
172 |
|
|
173 |
/****************************************************************************
|
|
174 |
* txHwQueue_Init()
|
|
175 |
****************************************************************************
|
|
176 |
|
|
177 |
DESCRIPTION: Initialize module handles.
|
|
178 |
|
|
179 |
****************************************************************************/
|
|
180 |
TI_STATUS txHwQueue_Init (TI_HANDLE hTxHwQueue, TI_HANDLE hReport)
|
|
181 |
{
|
|
182 |
TTxHwQueue *pTxHwQueue = (TTxHwQueue *)hTxHwQueue;
|
|
183 |
|
|
184 |
pTxHwQueue->hReport = hReport;
|
|
185 |
|
|
186 |
return TI_OK;
|
|
187 |
}
|
|
188 |
|
|
189 |
|
|
190 |
/****************************************************************************
|
|
191 |
* txHwQueue_Config()
|
|
192 |
****************************************************************************
|
|
193 |
* DESCRIPTION: Configure the Tx buffers pool object
|
|
194 |
*
|
|
195 |
* INPUTS: None
|
|
196 |
*
|
|
197 |
* OUTPUT: None
|
|
198 |
*
|
|
199 |
* RETURNS:
|
|
200 |
****************************************************************************/
|
|
201 |
TI_STATUS txHwQueue_Config (TI_HANDLE hTxHwQueue, TTwdInitParams *pInitParams)
|
|
202 |
{
|
|
203 |
TTxHwQueue *pTxHwQueue = (TTxHwQueue *)hTxHwQueue;
|
|
204 |
TI_UINT32 TxQid;
|
|
205 |
|
|
206 |
/* Configure queue parameters to Tx-HW queue module */
|
|
207 |
for (TxQid = 0; TxQid < MAX_NUM_OF_AC; TxQid++)
|
|
208 |
{
|
|
209 |
pTxHwQueue->aTxHwQueueInfo[TxQid].uNumBlksThresh = pInitParams->tGeneral.TxBlocksThresholdPerAc[TxQid];
|
|
210 |
}
|
|
211 |
|
|
212 |
return TI_OK;
|
|
213 |
}
|
|
214 |
|
|
215 |
|
|
216 |
|
|
217 |
/****************************************************************************
|
|
218 |
* txHwQueue_SetHwInfo()
|
|
219 |
****************************************************************************
|
|
220 |
|
|
221 |
DESCRIPTION:
|
|
222 |
|
|
223 |
Called after the HW configuration in the driver init or recovery process.
|
|
224 |
Configure Tx HW information, including Tx-HW-blocks number, and per queue
|
|
225 |
Tx-descriptors number. Than, restart the module variables.
|
|
226 |
|
|
227 |
Two thresholds are defined per queue:
|
|
228 |
a) TxBlocksLowPercentPerQueue[queue] - The lower threshold is the minimal number of
|
|
229 |
Tx blocks guaranteed for each queue.
|
|
230 |
The sum of all low thresholds should be less than 100%.
|
|
231 |
b) TxBlocksHighPercentPerQueue[queue] - The higher threshold is the maximal number of
|
|
232 |
Tx blocks that may be allocated to the queue.
|
|
233 |
The extra blocks above the low threshold can be allocated when needed only
|
|
234 |
if they are currently available and are not needed in order to guarantee
|
|
235 |
the other queues low threshold.
|
|
236 |
The sum of all high thresholds should be more than 100%.
|
|
237 |
****************************************************************************/
|
|
238 |
TI_STATUS txHwQueue_SetHwInfo (TI_HANDLE hTxHwQueue, TDmaParams *pDmaParams)
|
|
239 |
{
|
|
240 |
TTxHwQueue *pTxHwQueue = (TTxHwQueue *)hTxHwQueue;
|
|
241 |
|
|
242 |
pTxHwQueue->uNumTotalBlks = pDmaParams->NumTxBlocks - 1; /* One block must be always free for FW use. */
|
|
243 |
|
|
244 |
/* Restart the module variables. */
|
|
245 |
txHwQueue_Restart (hTxHwQueue);
|
|
246 |
|
|
247 |
return TI_OK;
|
|
248 |
}
|
|
249 |
|
|
250 |
|
|
251 |
/****************************************************************************
|
|
252 |
* txHwQueue_Restart()
|
|
253 |
****************************************************************************
|
|
254 |
DESCRIPTION:
|
|
255 |
============
|
|
256 |
Called after the HW configuration in the driver init or recovery process.
|
|
257 |
Restarts the Tx-HW-Queue module.
|
|
258 |
****************************************************************************/
|
|
259 |
TI_STATUS txHwQueue_Restart (TI_HANDLE hTxHwQueue)
|
|
260 |
{
|
|
261 |
TTxHwQueue *pTxHwQueue = (TTxHwQueue *)hTxHwQueue;
|
|
262 |
TTxHwQueueInfo *pQueueInfo;
|
|
263 |
TI_UINT32 TxQid;
|
|
264 |
|
|
265 |
|
|
266 |
/*
|
|
267 |
* All blocks are free at restart.
|
|
268 |
* Note that free means all blocks that are currently not in use, while reserved are
|
|
269 |
* a part of the free blocks that are the summary of all queues reserved blocks.
|
|
270 |
* Each queue may take from the reserved part only up to its own reservation (according to
|
|
271 |
* its low threshold).
|
|
272 |
*/
|
|
273 |
pTxHwQueue->uNumTotalBlksFree = pTxHwQueue->uNumTotalBlks;
|
|
274 |
pTxHwQueue->uNumTotalBlksReserved = 0;
|
|
275 |
pTxHwQueue->uNumUsedDescriptors = 0;
|
|
276 |
pTxHwQueue->uFwTxResultsCntr = 0;
|
|
277 |
pTxHwQueue->uDrvTxPacketsCntr = 0;
|
|
278 |
|
|
279 |
for (TxQid = 0; TxQid < MAX_NUM_OF_AC; TxQid++)
|
|
280 |
{
|
|
281 |
pQueueInfo = &pTxHwQueue->aTxHwQueueInfo[TxQid];
|
|
282 |
|
|
283 |
pQueueInfo->uNumBlksUsed = 0;
|
|
284 |
pQueueInfo->uAllocatedBlksCntr = 0;
|
|
285 |
pQueueInfo->uFwFreedBlksCntr = 0;
|
|
286 |
pQueueInfo->uNumBlksCausedBusy = 0;
|
|
287 |
pQueueInfo->bQueueBusy = TI_FALSE;
|
|
288 |
|
|
289 |
/* Since no blocks are used yet, reserved blocks number equals to the low threshold. */
|
|
290 |
pQueueInfo->uNumBlksReserved = pQueueInfo->uNumBlksThresh;
|
|
291 |
|
|
292 |
/* Accumulate total reserved blocks. */
|
|
293 |
pTxHwQueue->uNumTotalBlksReserved += pQueueInfo->uNumBlksReserved;
|
|
294 |
}
|
|
295 |
|
|
296 |
return TI_OK;
|
|
297 |
}
|
|
298 |
|
|
299 |
|
|
300 |
/****************************************************************************
|
|
301 |
* txHwQueue_AllocResources()
|
|
302 |
****************************************************************************
|
|
303 |
* DESCRIPTION:
|
|
304 |
============
|
|
305 |
1. Estimate required HW-blocks number.
|
|
306 |
2. If the required blocks are not available or no free descriptor,
|
|
307 |
return STOP_CURRENT (to stop current queue and requeue the packet).
|
|
308 |
3. Resources are available so update allocated blocks and descriptors counters.
|
|
309 |
4. If no resources for another similar packet, return STOP_NEXT (to stop current queue).
|
|
310 |
Else, return SUCCESS
|
|
311 |
****************************************************************************/
|
|
312 |
ETxHwQueStatus txHwQueue_AllocResources (TI_HANDLE hTxHwQueue, TTxCtrlBlk *pTxCtrlBlk)
|
|
313 |
{
|
|
314 |
TTxHwQueue *pTxHwQueue = (TTxHwQueue *)hTxHwQueue;
|
|
315 |
TI_UINT32 uNumBlksToAlloc; /* The number of blocks required for the current packet. */
|
|
316 |
TI_UINT32 uExcludedLength; /* The data length not included in the rough blocks calculation */
|
|
317 |
TI_UINT32 uAvailableBlks; /* Max blocks that are currently available for this queue. */
|
|
318 |
TI_UINT32 uReservedBlks; /* How many blocks are reserved for this queue before this allocation. */
|
|
319 |
TI_UINT32 uQueueId = WMEQosTagToACTable[pTxCtrlBlk->tTxDescriptor.tid];
|
|
320 |
TTxHwQueueInfo *pQueueInfo = &(pTxHwQueue->aTxHwQueueInfo[uQueueId]);
|
|
321 |
|
|
322 |
|
|
323 |
/***********************************************************************/
|
|
324 |
/* Calculate packet required HW blocks. */
|
|
325 |
/***********************************************************************/
|
|
326 |
|
|
327 |
/* Divide length by 256 instead of 252 (block size) to save CPU */
|
|
328 |
uNumBlksToAlloc = pTxCtrlBlk->tTxDescriptor.length >> 8;
|
|
329 |
|
|
330 |
/* The length not yet included in the uNumBlksToAlloc is the sum of:
|
|
331 |
1) 4 bytes per block as a result of using 256 instead of 252 block size.
|
|
332 |
2) The remainder of the division by 256.
|
|
333 |
3) Overhead due to header translation, security and LLC header (subtracting ethernet header).
|
|
334 |
*/
|
|
335 |
uExcludedLength = (uNumBlksToAlloc << 2) + (pTxCtrlBlk->tTxDescriptor.length & 0xFF) + MAX_HEADER_SIZE - 14;
|
|
336 |
|
|
337 |
/* Add 1 or 2 blocks for the excluded length, according to its size */
|
|
338 |
uNumBlksToAlloc += (uExcludedLength > 252) ? 2 : 1;
|
|
339 |
|
|
340 |
/* Add extra blocks needed in case of fragmentation */
|
|
341 |
uNumBlksToAlloc += BLKS_HW_ALLOC_SPARE;
|
|
342 |
|
|
343 |
/***********************************************************************/
|
|
344 |
/* Check if the required resources are available */
|
|
345 |
/***********************************************************************/
|
|
346 |
|
|
347 |
/* Find max available blocks for this queue (0 could indicate no descriptors). */
|
|
348 |
uAvailableBlks = txHwQueue_CheckResources (pTxHwQueue, pQueueInfo);
|
|
349 |
|
|
350 |
/* If we need more blocks than available, return STOP_CURRENT (stop current queue and requeue packet). */
|
|
351 |
if (uNumBlksToAlloc > uAvailableBlks)
|
|
352 |
{
|
|
353 |
TRACE6(pTxHwQueue->hReport, REPORT_SEVERITY_INFORMATION, ": No resources, Queue=%d, ReqBlks=%d, FreeBlks=%d, UsedBlks=%d, AvailBlks=%d, UsedPkts=%d\n", uQueueId, uNumBlksToAlloc, pTxHwQueue->uNumTotalBlksFree, pQueueInfo->uNumBlksUsed, uAvailableBlks, pTxHwQueue->uNumUsedDescriptors);
|
|
354 |
pQueueInfo->uNumBlksCausedBusy = uNumBlksToAlloc;
|
|
355 |
pQueueInfo->bQueueBusy = TI_TRUE;
|
|
356 |
|
|
357 |
return TX_HW_QUE_STATUS_STOP_CURRENT; /**** Exit! (we should stop queue and requeue packet) ****/
|
|
358 |
}
|
|
359 |
|
|
360 |
/***********************************************************************/
|
|
361 |
/* Allocate required resources */
|
|
362 |
/***********************************************************************/
|
|
363 |
|
|
364 |
/* Update blocks numbers in Tx descriptor */
|
|
365 |
pTxCtrlBlk->tTxDescriptor.extraMemBlks = BLKS_HW_ALLOC_SPARE;
|
|
366 |
pTxCtrlBlk->tTxDescriptor.totalMemBlks = uNumBlksToAlloc;
|
|
367 |
|
|
368 |
/* Update packet allocation info: */
|
|
369 |
pTxHwQueue->uNumUsedDescriptors++; /* Update number of packets in FW (for descriptors allocation check). */
|
|
370 |
pTxHwQueue->uDrvTxPacketsCntr++;
|
|
371 |
pQueueInfo->uAllocatedBlksCntr += uNumBlksToAlloc; /* For FW counter coordination. */
|
|
372 |
uReservedBlks = pQueueInfo->uNumBlksReserved;
|
|
373 |
|
|
374 |
/* If we are currently using less than the low threshold (i.e. we have some reserved blocks),
|
|
375 |
blocks allocation should reduce the reserved blocks number as follows:
|
|
376 |
*/
|
|
377 |
if (uReservedBlks)
|
|
378 |
{
|
|
379 |
|
|
380 |
/* If adding the allocated blocks to the used blocks will pass the low-threshold,
|
|
381 |
only the part up to the low-threshold is subtracted from the reserved blocks.
|
|
382 |
This is because blocks are reserved for the Queue only up to its low-threshold.
|
|
383 |
|
|
384 |
0 old used low new used high
|
|
385 |
|######| | | |
|
|
386 |
|######| | | |
|
|
387 |
<------------ allocated ----------->
|
|
388 |
<----- old reserved ---->
|
|
389 |
new reserved = 0 (we passed the low threshold)
|
|
390 |
*/
|
|
391 |
if (uNumBlksToAlloc > uReservedBlks)
|
|
392 |
{
|
|
393 |
pQueueInfo->uNumBlksReserved = 0;
|
|
394 |
pTxHwQueue->uNumTotalBlksReserved -= uReservedBlks; /* reduce change from total reserved.*/
|
|
395 |
}
|
|
396 |
|
|
397 |
|
|
398 |
/* Else, if allocating less than reserved,
|
|
399 |
the allocated blocks are subtracted from the reserved blocks:
|
|
400 |
|
|
401 |
0 old used new used low high
|
|
402 |
|######| | | |
|
|
403 |
|######| | | |
|
|
404 |
<- allocated ->
|
|
405 |
<--------- old reserved ---------->
|
|
406 |
<-- new reserved -->
|
|
407 |
*/
|
|
408 |
else
|
|
409 |
{
|
|
410 |
pQueueInfo->uNumBlksReserved -= uNumBlksToAlloc;
|
|
411 |
pTxHwQueue->uNumTotalBlksReserved -= uNumBlksToAlloc; /* reduce change from total reserved.*/
|
|
412 |
}
|
|
413 |
}
|
|
414 |
|
|
415 |
|
|
416 |
/* Update total free blocks and Queue used blocks with the allocated blocks number. */
|
|
417 |
pTxHwQueue->uNumTotalBlksFree -= uNumBlksToAlloc;
|
|
418 |
pQueueInfo->uNumBlksUsed += uNumBlksToAlloc;
|
|
419 |
|
|
420 |
TRACE6(pTxHwQueue->hReport, REPORT_SEVERITY_INFORMATION, ": SUCCESS, Queue=%d, Req-blks=%d , Free=%d, Used=%d, Reserved=%d, Accumulated=%d\n", uQueueId, uNumBlksToAlloc, pTxHwQueue->uNumTotalBlksFree, pQueueInfo->uNumBlksUsed, pQueueInfo->uNumBlksReserved, pQueueInfo->uAllocatedBlksCntr);
|
|
421 |
|
|
422 |
/* If no resources for another similar packet, return STOP_NEXT (to stop current queue). */
|
|
423 |
/* Note: Current packet transmission is continued */
|
|
424 |
if ( (uNumBlksToAlloc << 1) > uAvailableBlks )
|
|
425 |
{
|
|
426 |
TRACE6(pTxHwQueue->hReport, REPORT_SEVERITY_INFORMATION, ": No resources for next pkt, Queue=%d, ReqBlks=%d, FreeBlks=%d, UsedBlks=%d, AvailBlks=%d, UsedPkts=%d\n", uQueueId, uNumBlksToAlloc, pTxHwQueue->uNumTotalBlksFree, pQueueInfo->uNumBlksUsed, uAvailableBlks, pTxHwQueue->uNumUsedDescriptors);
|
|
427 |
pQueueInfo->uNumBlksCausedBusy = uNumBlksToAlloc;
|
|
428 |
pQueueInfo->bQueueBusy = TI_TRUE;
|
|
429 |
return TX_HW_QUE_STATUS_STOP_NEXT;
|
|
430 |
}
|
|
431 |
|
|
432 |
/* Return SUCCESS (resources are available). */
|
|
433 |
return TX_HW_QUE_STATUS_SUCCESS;
|
|
434 |
}
|
|
435 |
|
|
436 |
|
|
437 |
/****************************************************************************
|
|
438 |
* txHwQueue_UpdateFreeBlocks()
|
|
439 |
****************************************************************************
|
|
440 |
* DESCRIPTION:
|
|
441 |
===========
|
|
442 |
This function is called per queue after reading the freed blocks counters from the FwStatus.
|
|
443 |
It updates the queue's blocks status according to the freed blocks.
|
|
444 |
****************************************************************************/
|
|
445 |
static void txHwQueue_UpdateFreeBlocks (TTxHwQueue *pTxHwQueue, TI_UINT32 uQueueId, TI_UINT32 uFreeBlocks)
|
|
446 |
{
|
|
447 |
TTxHwQueueInfo *pQueueInfo = &(pTxHwQueue->aTxHwQueueInfo[uQueueId]);
|
|
448 |
TI_UINT32 lowThreshold; /* Minimum blocks that are guaranteed for this Queue. */
|
|
449 |
TI_UINT32 newUsedBlks; /* Blocks that are used by this Queue after updating free blocks. */
|
|
450 |
TI_UINT32 newReserved; /* How many blocks are reserved to this Queue after freeing. */
|
|
451 |
TI_UINT32 numBlksToFree; /* The number of blocks freed in the current queue. */
|
|
452 |
|
|
453 |
/* If the FW free blocks counter didn't change, exit */
|
|
454 |
uFreeBlocks = ENDIAN_HANDLE_LONG(uFreeBlocks);
|
|
455 |
if (uFreeBlocks == pQueueInfo->uFwFreedBlksCntr)
|
|
456 |
{
|
|
457 |
return;
|
|
458 |
}
|
|
459 |
|
|
460 |
pQueueInfo->uFwFreedBlksCntr = uFreeBlocks;
|
|
461 |
|
|
462 |
/* The uFreeBlocks is the accumulated number of blocks freed by the FW for the uQueueId.
|
|
463 |
* Subtracting it from the accumulated number of blocks allocated by the driver should
|
|
464 |
* give the current number of used blocks in this queue.
|
|
465 |
* Since the difference is always a small positive number, a simple subtraction should work
|
|
466 |
* also for wrap around.
|
|
467 |
*/
|
|
468 |
newUsedBlks = pQueueInfo->uAllocatedBlksCntr - uFreeBlocks;
|
|
469 |
|
|
470 |
numBlksToFree = pQueueInfo->uNumBlksUsed - newUsedBlks;
|
|
471 |
|
|
472 |
#ifdef TI_DBG /* Sanity check: make sure we don't free more than is allocated. */
|
|
473 |
if (numBlksToFree > pQueueInfo->uNumBlksUsed)
|
|
474 |
{
|
|
475 |
TRACE5(pTxHwQueue->hReport, REPORT_SEVERITY_ERROR, ": Try to free more blks than used: Queue %d, ToFree %d, Used %d, HostAlloc=0x%x, FwFree=0x%x\n", uQueueId, numBlksToFree, pQueueInfo->uNumBlksUsed, pQueueInfo->uAllocatedBlksCntr, uFreeBlocks);
|
|
476 |
}
|
|
477 |
#endif
|
|
478 |
|
|
479 |
/* Update total free blocks and Queue used blocks with the freed blocks number. */
|
|
480 |
pTxHwQueue->uNumTotalBlksFree += numBlksToFree;
|
|
481 |
pQueueInfo->uNumBlksUsed = newUsedBlks;
|
|
482 |
|
|
483 |
lowThreshold = pQueueInfo->uNumBlksThresh;
|
|
484 |
|
|
485 |
/* If after freeing the blocks we are using less than the low threshold,
|
|
486 |
update total reserved blocks number as follows:
|
|
487 |
(note: if we are above the low threshold after freeing the blocks we still have no reservation.)
|
|
488 |
*/
|
|
489 |
if (newUsedBlks < lowThreshold)
|
|
490 |
{
|
|
491 |
newReserved = lowThreshold - newUsedBlks;
|
|
492 |
pQueueInfo->uNumBlksReserved = newReserved;
|
|
493 |
|
|
494 |
|
|
495 |
/* If freeing the blocks reduces the used blocks from above to below the low-threshold,
|
|
496 |
only the part from the low-threshold to the new used number is added to the
|
|
497 |
reserved blocks (because blocks are reserved for the Queue only up to its low-threshold):
|
|
498 |
|
|
499 |
0 new used low old used high
|
|
500 |
|###########|####################|################| |
|
|
501 |
|###########|####################|################| |
|
|
502 |
<-------------- freed -------------->
|
|
503 |
<-- new reserved -->
|
|
504 |
old reserved = 0
|
|
505 |
*/
|
|
506 |
if (numBlksToFree > newReserved)
|
|
507 |
pTxHwQueue->uNumTotalBlksReserved += newReserved; /* Add change to total reserved.*/
|
|
508 |
|
|
509 |
|
|
510 |
/* Else, if we were under the low-threshold before freeing these blocks,
|
|
511 |
all freed blocks are added to the reserved blocks:
|
|
512 |
|
|
513 |
0 new used old used low high
|
|
514 |
|################|#################| | |
|
|
515 |
|################|#################| | |
|
|
516 |
<---- freed ---->
|
|
517 |
<- old reserved ->
|
|
518 |
<---------- new reserved ---------->
|
|
519 |
*/
|
|
520 |
else
|
|
521 |
pTxHwQueue->uNumTotalBlksReserved += numBlksToFree; /* Add change to total reserved.*/
|
|
522 |
}
|
|
523 |
|
|
524 |
TRACE5(pTxHwQueue->hReport, REPORT_SEVERITY_INFORMATION, ": Queue %d, ToFree %d, Used %d, HostAlloc=0x%x, FwFree=0x%x\n", uQueueId, numBlksToFree, pQueueInfo->uNumBlksUsed, pQueueInfo->uAllocatedBlksCntr, uFreeBlocks);
|
|
525 |
}
|
|
526 |
|
|
527 |
|
|
528 |
/****************************************************************************
|
|
529 |
* txHwQueue_UpdateFreeResources()
|
|
530 |
****************************************************************************
|
|
531 |
* DESCRIPTION:
|
|
532 |
===========
|
|
533 |
Called by FwEvent upon Data interrupt to update freed HW-Queue resources as follows:
|
|
534 |
1) For all queues, update blocks and descriptors numbers according to FwStatus information.
|
|
535 |
2) For each busy queue, if now available indicate it in the backpressure bitmap.
|
|
536 |
****************************************************************************/
|
|
537 |
void txHwQueue_UpdateFreeResources (TI_HANDLE hTxHwQueue, FwStatus_t *pFwStatus)
|
|
538 |
{
|
|
539 |
TTxHwQueue *pTxHwQueue = (TTxHwQueue *)hTxHwQueue;
|
|
540 |
TTxHwQueueInfo *pQueueInfo;
|
|
541 |
TI_UINT32 uQueueId;
|
|
542 |
TI_UINT32 uAvailableBlks; /* Max blocks available for current queue. */
|
|
543 |
TI_UINT32 uNewNumUsedDescriptors;
|
|
544 |
TI_UINT32 uBackpressure = 0;
|
|
545 |
TI_UINT32 *pFreeBlocks = (TI_UINT32 *)pFwStatus->txReleasedBlks;
|
|
546 |
TI_UINT32 uTempFwCounters;
|
|
547 |
FwStatCntrs_t *pFwStatusCounters;
|
|
548 |
|
|
549 |
/*
|
|
550 |
* If TxResults counter changed in FwStatus, update descriptors number according to information
|
|
551 |
*/
|
|
552 |
uTempFwCounters = (ENDIAN_HANDLE_LONG(pFwStatus->counters));
|
|
553 |
pFwStatusCounters = (FwStatCntrs_t *)&uTempFwCounters;
|
|
554 |
if (pFwStatusCounters->txResultsCntr != pTxHwQueue->uFwTxResultsCntr)
|
|
555 |
{
|
|
556 |
pTxHwQueue->uFwTxResultsCntr = pFwStatusCounters->txResultsCntr;
|
|
557 |
|
|
558 |
/* Calculate new number of used descriptors (the else is for wrap around case) */
|
|
559 |
if (pTxHwQueue->uFwTxResultsCntr <= pTxHwQueue->uDrvTxPacketsCntr)
|
|
560 |
{
|
|
561 |
uNewNumUsedDescriptors = (TI_UINT32)(pTxHwQueue->uDrvTxPacketsCntr - pTxHwQueue->uFwTxResultsCntr);
|
|
562 |
}
|
|
563 |
else
|
|
564 |
{
|
|
565 |
uNewNumUsedDescriptors = 0x100 - (TI_UINT32)(pTxHwQueue->uFwTxResultsCntr - pTxHwQueue->uDrvTxPacketsCntr);
|
|
566 |
}
|
|
567 |
|
|
568 |
#ifdef TI_DBG /* Sanity check: make sure we don't free more descriptors than allocated. */
|
|
569 |
if (uNewNumUsedDescriptors >= pTxHwQueue->uNumUsedDescriptors)
|
|
570 |
{
|
|
571 |
TRACE2(pTxHwQueue->hReport, REPORT_SEVERITY_ERROR, ": Used descriptors number should decrease: UsedDesc %d, NewUsedDesc %d\n", pTxHwQueue->uNumUsedDescriptors, uNewNumUsedDescriptors);
|
|
572 |
}
|
|
573 |
#endif
|
|
574 |
|
|
575 |
/* Update number of packets left in FW (for descriptors allocation check). */
|
|
576 |
pTxHwQueue->uNumUsedDescriptors = uNewNumUsedDescriptors;
|
|
577 |
}
|
|
578 |
|
|
579 |
/*
|
|
580 |
* For all queues, update blocks numbers according to FwStatus information
|
|
581 |
*/
|
|
582 |
for (uQueueId = 0; uQueueId < MAX_NUM_OF_AC; uQueueId++)
|
|
583 |
{
|
|
584 |
pQueueInfo = &(pTxHwQueue->aTxHwQueueInfo[uQueueId]);
|
|
585 |
|
|
586 |
/* Update per queue number of used, free and reserved blocks. */
|
|
587 |
txHwQueue_UpdateFreeBlocks (pTxHwQueue, uQueueId, pFreeBlocks[uQueueId]);
|
|
588 |
}
|
|
589 |
|
|
590 |
/*
|
|
591 |
* For each busy queue, if now available indicate it in the backpressure bitmap
|
|
592 |
*/
|
|
593 |
for (uQueueId = 0; uQueueId < MAX_NUM_OF_AC; uQueueId++)
|
|
594 |
{
|
|
595 |
pQueueInfo = &(pTxHwQueue->aTxHwQueueInfo[uQueueId]);
|
|
596 |
|
|
597 |
/* If the queue was stopped */
|
|
598 |
if (pQueueInfo->bQueueBusy)
|
|
599 |
{
|
|
600 |
/* Find max available blocks for this queue (0 could indicate no descriptors). */
|
|
601 |
uAvailableBlks = txHwQueue_CheckResources (pTxHwQueue, pQueueInfo);
|
|
602 |
|
|
603 |
/* If the required blocks and a descriptor are available,
|
|
604 |
set the queue's backpressure bit to indicate NOT-busy! */
|
|
605 |
if (pQueueInfo->uNumBlksCausedBusy <= uAvailableBlks)
|
|
606 |
{
|
|
607 |
TRACE6(pTxHwQueue->hReport, REPORT_SEVERITY_INFORMATION, ": Queue Available, Queue=%d, ReqBlks=%d, FreeBlks=%d, UsedBlks=%d, AvailBlks=%d, UsedPkts=%d\n", uQueueId, pQueueInfo->uNumBlksCausedBusy, pTxHwQueue->uNumTotalBlksFree, pQueueInfo->uNumBlksUsed, uAvailableBlks, pTxHwQueue->uNumUsedDescriptors);
|
|
608 |
SET_QUEUE_BACKPRESSURE(&uBackpressure, uQueueId); /* Start queue. */
|
|
609 |
pQueueInfo->bQueueBusy = TI_FALSE;
|
|
610 |
}
|
|
611 |
}
|
|
612 |
}
|
|
613 |
|
|
614 |
/* If released queues map is not 0, send it to the upper layers (if CB available) */
|
|
615 |
if ((uBackpressure > 0) && (pTxHwQueue->fUpdateBusyMapCb != NULL))
|
|
616 |
{
|
|
617 |
pTxHwQueue->fUpdateBusyMapCb (pTxHwQueue->hUpdateBusyMapHndl, uBackpressure);
|
|
618 |
}
|
|
619 |
}
|
|
620 |
|
|
621 |
|
|
622 |
/****************************************************************************
|
|
623 |
* txHwQueue_CheckResources()
|
|
624 |
****************************************************************************
|
|
625 |
* DESCRIPTION:
|
|
626 |
============
|
|
627 |
Return the given queue's available blocks.
|
|
628 |
If no descriptors available, return 0.
|
|
629 |
****************************************************************************/
|
|
630 |
static TI_UINT32 txHwQueue_CheckResources (TTxHwQueue *pTxHwQueue, TTxHwQueueInfo *pQueueInfo)
|
|
631 |
{
|
|
632 |
/* If descriptors are available: */
|
|
633 |
if (pTxHwQueue->uNumUsedDescriptors < NUM_TX_DESCRIPTORS)
|
|
634 |
{
|
|
635 |
/* Calculate how many buffers are available for this Queue: the total free buffers minus the buffers
|
|
636 |
that are reserved for other Queues (all reserved minus this Queue's reserved). */
|
|
637 |
return (pTxHwQueue->uNumTotalBlksFree - (pTxHwQueue->uNumTotalBlksReserved - pQueueInfo->uNumBlksReserved));
|
|
638 |
}
|
|
639 |
|
|
640 |
/* If no descriptors are available, return 0 (can't transmit anything). */
|
|
641 |
else
|
|
642 |
{
|
|
643 |
return 0;
|
|
644 |
}
|
|
645 |
}
|
|
646 |
|
|
647 |
|
|
648 |
/****************************************************************************
|
|
649 |
* txHwQueue_RegisterCb()
|
|
650 |
****************************************************************************
|
|
651 |
* DESCRIPTION: Register the upper driver TxHwQueue callback functions.
|
|
652 |
****************************************************************************/
|
|
653 |
void txHwQueue_RegisterCb (TI_HANDLE hTxHwQueue, TI_UINT32 uCallBackId, void *fCbFunc, TI_HANDLE hCbHndl)
|
|
654 |
{
|
|
655 |
TTxHwQueue *pTxHwQueue = (TTxHwQueue *)hTxHwQueue;
|
|
656 |
|
|
657 |
switch (uCallBackId)
|
|
658 |
{
|
|
659 |
case TWD_INT_UPDATE_BUSY_MAP:
|
|
660 |
pTxHwQueue->fUpdateBusyMapCb = (tUpdateBusyMapCb)fCbFunc;
|
|
661 |
pTxHwQueue->hUpdateBusyMapHndl = hCbHndl;
|
|
662 |
break;
|
|
663 |
|
|
664 |
default:
|
|
665 |
TRACE1(pTxHwQueue->hReport, REPORT_SEVERITY_ERROR, " - Illegal parameter = %d\n", uCallBackId);
|
|
666 |
return;
|
|
667 |
}
|
|
668 |
}
|
|
669 |
|
|
670 |
|
|
671 |
/****************************************************************************
|
|
672 |
* txHwQueue_PrintInfo()
|
|
673 |
****************************************************************************
|
|
674 |
* DESCRIPTION: Print the Hw Queue module current information
|
|
675 |
****************************************************************************/
|
|
676 |
#ifdef TI_DBG
|
|
677 |
void txHwQueue_PrintInfo (TI_HANDLE hTxHwQueue)
|
|
678 |
{
|
|
679 |
TTxHwQueue *pTxHwQueue = (TTxHwQueue *)hTxHwQueue;
|
|
680 |
TI_INT32 TxQid;
|
|
681 |
|
|
682 |
/* Print the Tx-HW-Queue information: */
|
|
683 |
WLAN_OS_REPORT(("Hw-Queues Information:\n"));
|
|
684 |
WLAN_OS_REPORT(("======================\n"));
|
|
685 |
WLAN_OS_REPORT(("Total Blocks: %d\n", pTxHwQueue->uNumTotalBlks));
|
|
686 |
WLAN_OS_REPORT(("Total Free Blocks: %d\n", pTxHwQueue->uNumTotalBlksFree));
|
|
687 |
WLAN_OS_REPORT(("Total Reserved Blocks: %d\n", pTxHwQueue->uNumTotalBlksReserved));
|
|
688 |
WLAN_OS_REPORT(("Total Used Descriptors: %d\n", pTxHwQueue->uNumUsedDescriptors));
|
|
689 |
WLAN_OS_REPORT(("FwTxResultsCntr: %d\n", pTxHwQueue->uFwTxResultsCntr));
|
|
690 |
WLAN_OS_REPORT(("DrvTxPacketsCntr: %d\n", pTxHwQueue->uDrvTxPacketsCntr));
|
|
691 |
|
|
692 |
for(TxQid = 0; TxQid < MAX_NUM_OF_AC; TxQid++)
|
|
693 |
{
|
|
694 |
WLAN_OS_REPORT(("Q=%d: Used=%d, Reserve=%d, Threshold=%d\n",
|
|
695 |
TxQid,
|
|
696 |
pTxHwQueue->aTxHwQueueInfo[TxQid].uNumBlksUsed,
|
|
697 |
pTxHwQueue->aTxHwQueueInfo[TxQid].uNumBlksReserved,
|
|
698 |
pTxHwQueue->aTxHwQueueInfo[TxQid].uNumBlksThresh));
|
|
699 |
}
|
|
700 |
|
|
701 |
WLAN_OS_REPORT(("\n"));
|
|
702 |
|
|
703 |
for(TxQid = 0; TxQid < MAX_NUM_OF_AC; TxQid++)
|
|
704 |
{
|
|
705 |
WLAN_OS_REPORT(("Queue=%d: HostAllocCount=0x%x, FwFreeCount=0x%x, BusyBlks=%d, Busy=%d\n",
|
|
706 |
TxQid,
|
|
707 |
pTxHwQueue->aTxHwQueueInfo[TxQid].uAllocatedBlksCntr,
|
|
708 |
pTxHwQueue->aTxHwQueueInfo[TxQid].uFwFreedBlksCntr,
|
|
709 |
pTxHwQueue->aTxHwQueueInfo[TxQid].uNumBlksCausedBusy,
|
|
710 |
pTxHwQueue->aTxHwQueueInfo[TxQid].bQueueBusy));
|
|
711 |
}
|
|
712 |
}
|
|
713 |
|
|
714 |
|
|
715 |
#endif /* TI_DBG */
|
|
716 |
|