0
|
1 |
/*
|
|
2 |
* txCtrlBlk.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: txCtrlBlk.c
|
|
43 |
*
|
|
44 |
* PURPOSE: Maintains active packets Tx attributes table (including descriptor).
|
|
45 |
*
|
|
46 |
* DESCRIPTION:
|
|
47 |
* ============
|
|
48 |
* This module allocates and frees table entry for each packet in the Tx
|
|
49 |
* process (from sendPkt by upper driver until Tx-complete).
|
|
50 |
*
|
|
51 |
****************************************************************************/
|
|
52 |
#define __FILE_ID__ FILE_ID_99
|
|
53 |
#include "osApi.h"
|
|
54 |
#include "tidef.h"
|
|
55 |
#include "report.h"
|
|
56 |
#include "context.h"
|
|
57 |
#include "TWDriver.h"
|
|
58 |
#include "txCtrlBlk_api.h"
|
|
59 |
|
|
60 |
|
|
61 |
/* The TxCtrlBlk module object - contains the control-block table. */
|
|
62 |
typedef struct
|
|
63 |
{
|
|
64 |
TI_HANDLE hOs;
|
|
65 |
TI_HANDLE hReport;
|
|
66 |
TI_HANDLE hContext;
|
|
67 |
|
|
68 |
TTxCtrlBlk aTxCtrlBlkTbl[CTRL_BLK_ENTRIES_NUM]; /* The table of control-block entries. */
|
|
69 |
|
|
70 |
#ifdef TI_DBG /* Just for debug. */
|
|
71 |
TI_UINT32 uNumUsedEntries;
|
|
72 |
#endif
|
|
73 |
|
|
74 |
} TTxCtrlBlkObj;
|
|
75 |
|
|
76 |
|
|
77 |
/****************************************************************************
|
|
78 |
* txCtrlBlk_Create()
|
|
79 |
****************************************************************************
|
|
80 |
* DESCRIPTION: Create the Tx control block table object
|
|
81 |
*
|
|
82 |
* INPUTS: hOs
|
|
83 |
*
|
|
84 |
* OUTPUT: None
|
|
85 |
*
|
|
86 |
* RETURNS: The Created object
|
|
87 |
****************************************************************************/
|
|
88 |
TI_HANDLE txCtrlBlk_Create (TI_HANDLE hOs)
|
|
89 |
{
|
|
90 |
TTxCtrlBlkObj *pTxCtrlBlk;
|
|
91 |
|
|
92 |
pTxCtrlBlk = os_memoryAlloc (hOs, sizeof(TTxCtrlBlkObj),MemoryNormal);
|
|
93 |
if (pTxCtrlBlk == NULL)
|
|
94 |
return NULL;
|
|
95 |
|
|
96 |
os_memoryZero (hOs, pTxCtrlBlk, sizeof(TTxCtrlBlkObj));
|
|
97 |
|
|
98 |
pTxCtrlBlk->hOs = hOs;
|
|
99 |
|
|
100 |
return( (TI_HANDLE)pTxCtrlBlk );
|
|
101 |
}
|
|
102 |
|
|
103 |
|
|
104 |
/****************************************************************************
|
|
105 |
* txCtrlBlk_Destroy()
|
|
106 |
****************************************************************************
|
|
107 |
* DESCRIPTION: Destroy the Tx control block table object
|
|
108 |
*
|
|
109 |
* INPUTS: hTxCtrlBlk - The object to free
|
|
110 |
*
|
|
111 |
* OUTPUT: None
|
|
112 |
*
|
|
113 |
* RETURNS: TI_OK or TI_NOK
|
|
114 |
****************************************************************************/
|
|
115 |
TI_STATUS txCtrlBlk_Destroy (TI_HANDLE hTxCtrlBlk)
|
|
116 |
{
|
|
117 |
TTxCtrlBlkObj *pTxCtrlBlk = (TTxCtrlBlkObj *)hTxCtrlBlk;
|
|
118 |
|
|
119 |
if (pTxCtrlBlk)
|
|
120 |
os_memoryFree(pTxCtrlBlk->hOs, pTxCtrlBlk, sizeof(TTxCtrlBlkObj));
|
|
121 |
|
|
122 |
return TI_OK;
|
|
123 |
}
|
|
124 |
|
|
125 |
|
|
126 |
/****************************************************************************
|
|
127 |
* txCtrlBlk_Init()
|
|
128 |
****************************************************************************
|
|
129 |
DESCRIPTION: Initialize the Tx control block module.
|
|
130 |
****************************************************************************/
|
|
131 |
TI_STATUS txCtrlBlk_Init (TI_HANDLE hTxCtrlBlk, TI_HANDLE hReport, TI_HANDLE hContext)
|
|
132 |
{
|
|
133 |
TTxCtrlBlkObj *pTxCtrlBlk = (TTxCtrlBlkObj *)hTxCtrlBlk;
|
|
134 |
TI_UINT8 entry;
|
|
135 |
|
|
136 |
pTxCtrlBlk->hReport = hReport;
|
|
137 |
pTxCtrlBlk->hContext = hContext;
|
|
138 |
|
|
139 |
/* For all entries, write the entry index in the descriptor and the next entry address
|
|
140 |
in the next free entery pointer. Init also some other fields. */
|
|
141 |
for(entry = 0; entry < CTRL_BLK_ENTRIES_NUM; entry++)
|
|
142 |
{
|
|
143 |
pTxCtrlBlk->aTxCtrlBlkTbl[entry].tTxDescriptor.descID = entry;
|
|
144 |
pTxCtrlBlk->aTxCtrlBlkTbl[entry].pNextFreeEntry = &(pTxCtrlBlk->aTxCtrlBlkTbl[entry + 1]);
|
|
145 |
pTxCtrlBlk->aTxCtrlBlkTbl[entry].tTxDescriptor.aid = 1; /* The value for infrastructure BSS */
|
|
146 |
pTxCtrlBlk->aTxCtrlBlkTbl[entry].tTxDescriptor.reserved = 0;
|
|
147 |
}
|
|
148 |
|
|
149 |
/* Write null in the next-free index of the last entry. */
|
|
150 |
pTxCtrlBlk->aTxCtrlBlkTbl[CTRL_BLK_ENTRIES_NUM - 1].pNextFreeEntry = NULL;
|
|
151 |
|
|
152 |
#ifdef TI_DBG
|
|
153 |
pTxCtrlBlk->uNumUsedEntries = 0;
|
|
154 |
#endif
|
|
155 |
|
|
156 |
return TI_OK;
|
|
157 |
}
|
|
158 |
|
|
159 |
|
|
160 |
/****************************************************************************
|
|
161 |
* txCtrlBlk_Alloc()
|
|
162 |
****************************************************************************
|
|
163 |
* DESCRIPTION:
|
|
164 |
Allocate a free control-block entry for the current Tx packet's parameters
|
|
165 |
(including the descriptor structure).
|
|
166 |
Note that entry 0 in the list is never allocated and points to the
|
|
167 |
first free entry.
|
|
168 |
****************************************************************************/
|
|
169 |
TTxCtrlBlk *txCtrlBlk_Alloc (TI_HANDLE hTxCtrlBlk)
|
|
170 |
{
|
|
171 |
TTxCtrlBlkObj *pTxCtrlBlk = (TTxCtrlBlkObj *)hTxCtrlBlk;
|
|
172 |
TTxCtrlBlk *pCurrentEntry; /* The pointer of the new entry allocated for the packet. */
|
|
173 |
TTxCtrlBlk *pFirstFreeEntry; /* The first entry just points to the first free entry. */
|
|
174 |
|
|
175 |
pFirstFreeEntry = &(pTxCtrlBlk->aTxCtrlBlkTbl[0]);
|
|
176 |
|
|
177 |
/* Protect block allocation from preemption (may be called from external context) */
|
|
178 |
CONTEXT_ENTER_CRITICAL_SECTION (pTxCtrlBlk->hContext);
|
|
179 |
|
|
180 |
pCurrentEntry = pFirstFreeEntry->pNextFreeEntry; /* Get free entry. */
|
|
181 |
|
|
182 |
#ifdef TI_DBG
|
|
183 |
/* If no free entries, print error (not expected to happen) and return NULL. */
|
|
184 |
if (pCurrentEntry->pNextFreeEntry == NULL)
|
|
185 |
{
|
|
186 |
TRACE1(pTxCtrlBlk->hReport, REPORT_SEVERITY_ERROR, "txCtrlBlk_alloc(): No free entry, UsedEntries=%d\n", pTxCtrlBlk->uNumUsedEntries);
|
|
187 |
CONTEXT_LEAVE_CRITICAL_SECTION (pTxCtrlBlk->hContext);
|
|
188 |
return NULL;
|
|
189 |
}
|
|
190 |
pTxCtrlBlk->uNumUsedEntries++;
|
|
191 |
#endif
|
|
192 |
|
|
193 |
/* Link the first entry to the next free entry. */
|
|
194 |
pFirstFreeEntry->pNextFreeEntry = pCurrentEntry->pNextFreeEntry;
|
|
195 |
|
|
196 |
CONTEXT_LEAVE_CRITICAL_SECTION (pTxCtrlBlk->hContext);
|
|
197 |
|
|
198 |
/* Clear the next-free-entry index just as an indication that our entry is not free. */
|
|
199 |
pCurrentEntry->pNextFreeEntry = 0;
|
|
200 |
|
|
201 |
pCurrentEntry->tTxPktParams.uFlags = 0;
|
|
202 |
pCurrentEntry->tTxPktParams.uHeadroomSize = 0;
|
|
203 |
|
|
204 |
return pCurrentEntry;
|
|
205 |
}
|
|
206 |
|
|
207 |
|
|
208 |
/****************************************************************************
|
|
209 |
* txCtrlBlk_Free()
|
|
210 |
****************************************************************************
|
|
211 |
* DESCRIPTION:
|
|
212 |
Link the freed entry after entry 0, so now it is the first free entry to
|
|
213 |
be allocated.
|
|
214 |
****************************************************************************/
|
|
215 |
void txCtrlBlk_Free (TI_HANDLE hTxCtrlBlk, TTxCtrlBlk *pCurrentEntry)
|
|
216 |
{
|
|
217 |
TTxCtrlBlkObj *pTxCtrlBlk = (TTxCtrlBlkObj *)hTxCtrlBlk;
|
|
218 |
TTxCtrlBlk *pFirstFreeEntry = &(pTxCtrlBlk->aTxCtrlBlkTbl[0]);
|
|
219 |
|
|
220 |
#ifdef TI_DBG
|
|
221 |
/* If the pointed entry is already free, print error and exit (not expected to happen). */
|
|
222 |
if (pCurrentEntry->pNextFreeEntry != 0)
|
|
223 |
{
|
|
224 |
TRACE2(pTxCtrlBlk->hReport, REPORT_SEVERITY_ERROR, "txCtrlBlk_free(): Entry %d alredy free, UsedEntries=%d\n", pCurrentEntry->tTxDescriptor.descID, pTxCtrlBlk->uNumUsedEntries);
|
|
225 |
return;
|
|
226 |
}
|
|
227 |
pTxCtrlBlk->uNumUsedEntries--;
|
|
228 |
#endif
|
|
229 |
|
|
230 |
/* Protect block freeing from preemption (may be called from external context) */
|
|
231 |
CONTEXT_ENTER_CRITICAL_SECTION (pTxCtrlBlk->hContext);
|
|
232 |
|
|
233 |
/* Link the freed entry between entry 0 and the next free entry. */
|
|
234 |
pCurrentEntry->pNextFreeEntry = pFirstFreeEntry->pNextFreeEntry;
|
|
235 |
pFirstFreeEntry->pNextFreeEntry = pCurrentEntry;
|
|
236 |
|
|
237 |
CONTEXT_LEAVE_CRITICAL_SECTION (pTxCtrlBlk->hContext);
|
|
238 |
}
|
|
239 |
|
|
240 |
|
|
241 |
/****************************************************************************
|
|
242 |
* txCtrlBlk_GetPointer()
|
|
243 |
****************************************************************************
|
|
244 |
* DESCRIPTION:
|
|
245 |
Return a pointer to the control block entry of the requested packet.
|
|
246 |
Used upon tx-complete to retrieve info after getting the descId from the FW.
|
|
247 |
****************************************************************************/
|
|
248 |
TTxCtrlBlk *txCtrlBlk_GetPointer (TI_HANDLE hTxCtrlBlk, TI_UINT8 descId)
|
|
249 |
{
|
|
250 |
TTxCtrlBlkObj *pTxCtrlBlk = (TTxCtrlBlkObj *)hTxCtrlBlk;
|
|
251 |
return ( &(pTxCtrlBlk->aTxCtrlBlkTbl[descId]) );
|
|
252 |
}
|
|
253 |
|
|
254 |
|
|
255 |
/****************************************************************************
|
|
256 |
* txCtrlBlk_PrintTable()
|
|
257 |
****************************************************************************
|
|
258 |
* DESCRIPTION: Print the txCtrlBlk table main fields.
|
|
259 |
****************************************************************************/
|
|
260 |
#ifdef TI_DBG
|
|
261 |
void txCtrlBlk_PrintTable (TI_HANDLE hTxCtrlBlk)
|
|
262 |
{
|
|
263 |
TTxCtrlBlkObj *pTxCtrlBlk = (TTxCtrlBlkObj *)hTxCtrlBlk;
|
|
264 |
TI_UINT8 entry;
|
|
265 |
|
|
266 |
WLAN_OS_REPORT((" Tx-Control-Block Information, UsedEntries=%d\n", pTxCtrlBlk->uNumUsedEntries));
|
|
267 |
WLAN_OS_REPORT(("==============================================\n"));
|
|
268 |
|
|
269 |
for(entry = 0; entry < CTRL_BLK_ENTRIES_NUM; entry++)
|
|
270 |
{
|
|
271 |
WLAN_OS_REPORT(("Entry %d: DescID=%d, Next=0x%x, Len=%d, StartTime=%d, TID=%d, ExtraBlks=%d, TotalBlks=%d, Flags=0x%x\n",
|
|
272 |
entry,
|
|
273 |
pTxCtrlBlk->aTxCtrlBlkTbl[entry].tTxDescriptor.descID,
|
|
274 |
pTxCtrlBlk->aTxCtrlBlkTbl[entry].pNextFreeEntry,
|
|
275 |
ENDIAN_HANDLE_WORD(pTxCtrlBlk->aTxCtrlBlkTbl[entry].tTxDescriptor.length),
|
|
276 |
ENDIAN_HANDLE_LONG(pTxCtrlBlk->aTxCtrlBlkTbl[entry].tTxDescriptor.startTime),
|
|
277 |
pTxCtrlBlk->aTxCtrlBlkTbl[entry].tTxDescriptor.tid,
|
|
278 |
pTxCtrlBlk->aTxCtrlBlkTbl[entry].tTxDescriptor.extraMemBlks,
|
|
279 |
pTxCtrlBlk->aTxCtrlBlkTbl[entry].tTxDescriptor.totalMemBlks,
|
|
280 |
pTxCtrlBlk->aTxCtrlBlkTbl[entry].tTxPktParams.uFlags));
|
|
281 |
}
|
|
282 |
}
|
|
283 |
#endif /* TI_DBG */
|
|
284 |
|