• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /****************************************************************************
2 **+-----------------------------------------------------------------------+**
3 **|                                                                       |**
4 **| Copyright(c) 1998 - 2008 Texas Instruments. All rights reserved.      |**
5 **| All rights reserved.                                                  |**
6 **|                                                                       |**
7 **| Redistribution and use in source and binary forms, with or without    |**
8 **| modification, are permitted provided that the following conditions    |**
9 **| are met:                                                              |**
10 **|                                                                       |**
11 **|  * Redistributions of source code must retain the above copyright     |**
12 **|    notice, this list of conditions and the following disclaimer.      |**
13 **|  * Redistributions in binary form must reproduce the above copyright  |**
14 **|    notice, this list of conditions and the following disclaimer in    |**
15 **|    the documentation and/or other materials provided with the         |**
16 **|    distribution.                                                      |**
17 **|  * Neither the name Texas Instruments nor the names of its            |**
18 **|    contributors may be used to endorse or promote products derived    |**
19 **|    from this software without specific prior written permission.      |**
20 **|                                                                       |**
21 **| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS   |**
22 **| "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT     |**
23 **| LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |**
24 **| A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT  |**
25 **| OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |**
26 **| SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT      |**
27 **| LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |**
28 **| DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |**
29 **| THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT   |**
30 **| (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |**
31 **| OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  |**
32 **|                                                                       |**
33 **+-----------------------------------------------------------------------+**
34 ****************************************************************************/
35 
36 /**************************************************************************/
37 /*                                                                        */
38 /*	MODULE:		memMngr.h                                         */
39 /*      PURPOSE:        Driver memory management                          */
40 /*                                                                        */
41 /**************************************************************************/
42 #ifndef _MEM_MNGR_H_
43 #define _MEM_MNGR_H_
44 
45 #include "osTIType.h"
46 #include "commonTypes.h"
47 #include "osApi.h"
48 #include "TNETW_Driver_types.h"
49 
50 /*Ronnie: set # of MSDUs and BDs to be used in memMngrEx.c*/
51 #define		DEF_NUMBER_OF_MSDUS							200  /* Total number of packets queued in driver. */
52 #define		DEF_NUMBER_OF_BDS							400  /* Assuming typical MSDU uses 2 or 3 BDs. */
53 
54 #define		MIN_NUMBER_OF_BUF_POOLS						1
55 #define		MAX_NUMBER_OF_BUF_POOLS						3
56 
57 #ifdef SUPPORT_4X
58 #define		DEF_NUMBER_OF_BUF_POOLS						3
59 #define		DEF_BUFFER_LENGTH_POOL_1					64
60 #define		DEF_BUFFER_LENGTH_POOL_2					2048
61 #define		DEF_BUFFER_LENGTH_POOL_3					4096
62 #else
63 #define		DEF_NUMBER_OF_BUF_POOLS						3
64 #define		DEF_BUFFER_LENGTH_POOL_1					64
65 #define		DEF_BUFFER_LENGTH_POOL_2					256
66 #define		DEF_BUFFER_LENGTH_POOL_3					2048
67 #endif
68 
69 #define		MIN_BUFFER_LENGTH							64
70 #define		MAX_BUFFER_LENGTH							4096
71 #define		DEF_NUMBER_OF_BUFFERS_IN_POOL_1				160
72 #define		DEF_NUMBER_OF_BUFFERS_IN_POOL_2				160
73 #define		DEF_NUMBER_OF_BUFFERS_IN_POOL_3				160
74 
75 
76 #define WLAN_DRV_NULL_MEM_HANDLE						0xffffffff
77 
78 #define NUM_OF_FREE_ARGS								5
79 
80 #define MAX_NUM_OF_TIME_STAMPS                          8
81 
82 #define memMgr_BufLength(BufAddr) ( ((mem_BD_T *)BufAddr)->length   )
83 #define memMgr_BufOffset(BufAddr) ( ((mem_BD_T *)BufAddr)->dataOffset )
84 #define memMgr_BufData(BufAddr)   ( ((mem_BD_T *)BufAddr)->data )
85 #define memMgr_BufNext(BufAddr)   ( ((mem_BD_T *)BufAddr)->nextBDPtr )
86 
87 #define memMgr_MsduHdrLen(MsduAddr)		( ((mem_MSDU_T *)MsduAddr)->headerLen )
88 #define memMgr_MsduFirstLen(MsduAddr)	( ((mem_MSDU_T *)MsduAddr)->firstBDPtr->length )
89 #define memMgr_MsduHandle(MsduAddr)		( ((mem_MSDU_T *)MsduAddr)->handle )
90 /*
91  * Header resides after the Descriptor
92  */
93 #define memMgr_MsduHdrAddr(MsduAddr)    ( memMgr_BufData(((mem_MSDU_T *)MsduAddr)->firstBDPtr) + \
94                                           memMgr_BufOffset(((mem_MSDU_T *)MsduAddr)->firstBDPtr) + sizeof(DbTescriptor))
95 
96 #define memMgr_MsduNextAddr(MsduAddr)	( ((mem_MSDU_T *)MsduAddr)->firstBDPtr->nextBDPtr )
97 #define memMgr_MsduDataAddr(MsduAddr)	( ((mem_MSDU_T *)MsduAddr)->firstBDPtr )
98 #define memMgr_MsduDataSize(MsduAddr)	( ((mem_MSDU_T *)MsduAddr)->dataLen )
99 #define memMgr_MsduNextGet(MsduAddr)	( ((mem_MSDU_T *)MsduAddr)->nextMSDUinList)
100 #define memMgr_MsduFreeFuncGet(MsduAddr)( ((mem_MSDU_T *)MsduAddr)->freeFunc)
101 #define memMgr_MsduFreeArg0Get(MsduAddr)( ((mem_MSDU_T *)MsduAddr)->freeArgs[0])
102 #define memMgr_MsduFreeArg1Get(MsduAddr)( ((mem_MSDU_T *)MsduAddr)->freeArgs[1])
103 #define memMgr_MsduFreeArg2Get(MsduAddr)( ((mem_MSDU_T *)MsduAddr)->freeArgs[2])
104 #define memMgr_MsduFreeArg3Get(MsduAddr)( ((mem_MSDU_T *)MsduAddr)->freeArgs[3])
105 #define memMgr_MsduFreeArg4Get(MsduAddr)( ((mem_MSDU_T *)MsduAddr)->freeArgs[4])
106 
107 typedef enum
108 {
109 	/*
110 	 * Allocate on Tx
111 	 */
112 	MLME_MODULE		= 0,
113 	OS_ABS_TX_MODULE,
114 	RSN_MODULE,
115 	HAL_TX_MODULE,
116 	CONCAT_MODULE,
117 	DE_CONCAT_MODULE,
118 	ACK_EMUL_MODULE,
119 	TX_MODULE,
120 	MEASUREMENT_MODULE,
121 	SITE_MGR_MODULE,
122 	EXC_MANAGER_MODULE,
123 	TRACE_BUFFER_MODULE,
124 	ADM_CTRL_QOS_MODULE,
125 	CURRENT_BSS_MODULE,
126 	/*
127 	 * Allocate on Rx
128 	 */
129 	HAL_RX_MODULE,
130 	CORE_RX_MODULE,
131 	MLME_RX_MODULE,
132 	OS_ABS_RX_MODULE,
133 	RSN_RX_MODULE,
134 	MEASUREMENT_RX_MODULE,
135 	SITE_MGR_RX_MODULE,
136 	EXC_MANAGER_RX_MODULE,
137 
138 	HAL_WEP1_RX,
139 	HAL_WEP2_RX,
140 	HAL_DEFRAG_RX,
141 	HAL_DUPLICA_RX,
142 
143 	/*
144     DO NOT TOUCH - MODULE_FREE_MSDU, MAX_NUMBER_OF_MODULE!
145     */
146 	MODULE_FREE_MSDU,
147     MAX_NUMBER_OF_MODULE
148 
149 }allocatingModule_e;
150 
151 
152 typedef void (*ap_FreeMemFunc)(TI_HANDLE, TI_HANDLE, TI_STATUS);
153 
154 #ifdef TNETW_MASTER_MODE
155 typedef void (*bd_FreeMemFunc)( UINT32 , UINT32, UINT32, UINT32, UINT32 );
156 #endif
157 
158 typedef struct mem_DataBuf_T mem_DataBuf_T;
159 struct mem_DataBuf_T {
160     /* READ ONLY */
161 	/* The user MUST not change the following fields */
162 	UINT32			handle;				/* Hanlde of this Data Buffer Structure */
163     mem_DataBuf_T*  nextDataBuf;    /* pointer to the next free DataBuf
164                                            when this DataBuf is in Free mode */
165 	UINT32			refCount;			/* number of instances of this Data Buf */
166 	/* PUBLIC - For the use of the User */
167 	UINT32			poolIndex;		/* the buffer pool index */
168 	UINT8			*data;			/* pointer to the Data */
169 #if defined TNETW_MASTER_MODE
170 	OS_PHYSICAL_ADDRESS	data_physical; /* Physical address of the data */
171 #endif
172 };
173 
174 typedef struct mem_BD_T mem_BD_T;
175 struct mem_BD_T {
176     /* READ ONLY */
177 	/* The user MUST not change the following fields */
178 	UINT32			handle;			/* Hanlde of this BD Data Structure */
179 	UINT32			refCount;		/* number of instances of this BD */
180 	mem_DataBuf_T*  dataBuf;        /* pointer to the Data Buffer */
181 	/* PUBLIC - For the use of the User */
182     char*           data;           /* Pointer to the Data */
183 	UINT32			dataOffset;		/* offset of the data */
184 	UINT32			length;			/* Tx : the length of the entire data (including TxDescriptor,TNETWIF_WRITE_OFFSET_BYTES etc..) */
185 									/* Rx : the length of the data (excluding TNETWIF_READ_OFFSET_BYTES)							*/
186 	mem_BD_T*		nextBDPtr;		/* pointer to the next BD */
187 
188 #if defined TNETW_MASTER_MODE
189 	UINT32	data_physical_low;		/* Physical address (low) of the data */
190     bd_FreeMemFunc	freeFunc;		/* pointer to the Data Buffer free function */
191 	UINT32			freeArgs[NUM_OF_FREE_ARGS];	/* arguments to be send with the free function */
192 #endif
193 
194 };
195 
196 typedef struct mem_MSDU_T mem_MSDU_T;
197 struct mem_MSDU_T {
198     /* READ ONLY */
199 	/* The user MUST not change the following fields */
200 	UINT32				handle;			/* handle of this MSDU data structure */
201 	mem_MSDU_T *		nextFreeMSDU;   /* pointer to the next Free MSDU when
202 									   this MSDU Buffer is in Free mode */
203 	/* PUBLIC - For the use of the User */
204     UINT32				headerLen;      /* the length of the 802.11 header */
205 	mem_BD_T *			firstBDPtr;		/* pointer to the first BD */
206  	mem_BD_T *			lastBDPtr;		/* pointer to the last BD */
207 	ap_FreeMemFunc		freeFunc;		/* pointer to the Data Buffer free function */
208 	UINT32				freeArgs[NUM_OF_FREE_ARGS];	/* arguments to be send with the free function */
209 	UINT32				dataLen;		/* length of the data (only data) of the firstBDPtr */
210 	allocatingModule_e	module;			/* the allocating module */
211 
212 	/* support Msdu List */
213     mem_MSDU_T *		nextMSDUinList; /* pointer to the next MSDU in Tx queue link list. */
214     mem_MSDU_T *		prevMSDUinList; /* pointer to the previos MSDU in Tx queue link list. */
215 
216 
217 	UINT32				txFlags;		/* Tx flags */
218 	UINT8				txCompleteFlags;		/* Tx complete flags */
219 	UINT32              insertionTime;  /* time of msdu insersion to driver. */
220 	UINT8               qosTag;         /* 802.11d qos tag */
221 #ifdef DM_USE_WORKQUEUE
222     mem_MSDU_T *        msdu_next;      /* Used for Workqueue list */
223 #endif /* DM_USE_WORKQUEUE */
224 #ifdef TI_DBG
225     UINT32              timeStamp [MAX_NUM_OF_TIME_STAMPS];
226                                         /* array of time stamps */
227     UINT32              timeStampNum;   /* number of time stamps */
228 #endif
229 };
230 
231 typedef struct
232 {
233 	UINT32			buffersSize;		/* the size of the buffers in the pool */
234 	UINT32			numFreeDataBuf;		/* number of free data buffers */
235 	UINT32			dataBufMaxNumber;	/* maximum number of buffers */
236 	mem_DataBuf_T* 	firstFreeDataBuf;	/* pointer to the first free Data Buffer */
237 	mem_DataBuf_T*	dataBufPool;		/* list of Data Buffers */
238 #ifdef TNETW_MASTER_MODE
239 	OS_PHYSICAL_ADDRESS	physicalDataBufPoolPtr;
240 #endif
241 	UINT8*				dataBufPoolPtr;
242 
243 }buffersPool_t;
244 
245 /* structures for initialization of Memory manager */
246 typedef struct
247 {
248 	UINT32	numOfbuffers;
249 	UINT32	buffersSize;
250 }bufPoolInit_t;
251 
252 typedef struct
253 {
254 	UINT8	numOfPools;
255 	bufPoolInit_t	bufPoolInit[MAX_NUMBER_OF_BUF_POOLS];
256 }memMngrInit_t;
257 
258 /* MemMngr Control Block */
259 typedef struct
260 {
261 	TI_HANDLE		hReport;			/* report handle		*/
262 	TI_HANDLE		hOs;				/* Os handle			*/
263 	TI_HANDLE		hCriticalSectionProtect;
264 
265 	UINT32			currentNumberOfPools;
266 
267 	UINT32			msduMaxNumber;		/* maximum number of MSDUs */
268 	UINT32			bdMaxNumber;		/* maximum number of BD;s */
269 
270 	mem_MSDU_T* 	msduPool;			/* list of MSDU Buffer Desciptors	*/
271 	mem_BD_T* 		bdPool;				/* list of BD Buffer Descriptors	*/
272 
273 	mem_MSDU_T* 	firstFreeMSDU; 		/* pointer to the first free MSDU	*/
274 	mem_BD_T* 		firstFreeBD;		/* pointer to the first free BD		*/
275 
276 	UINT32			numFreeMSDU;		/* number of free MSDU's */
277 	UINT32			numFreeBD;			/* number of free BD's */
278 
279 	UINT32			moduleAllocCount[MAX_NUMBER_OF_MODULE]; /* counters of allocated */
280 															/* msdu per module		 */
281 
282 	buffersPool_t	buffersPool[MAX_NUMBER_OF_BUF_POOLS];	/* Pools of Data Buffers */
283 
284 }memMngr_t;
285 
286 typedef struct
287 {
288 	UINT32 numOfFreeBufPool1;
289 	UINT32 numOfFreeBufPool2;
290 	UINT32 numOfFreeBufPool3;
291 	UINT32 numOfFreeBDs;
292 	UINT32 numOfFreeMsdu;
293 }memMgrResources_t;
294 
295 /*************************************************************************
296  *                        wlan_memMngrInit          		             *
297  *************************************************************************
298 DESCRIPTION: Init of the Memory Manager module
299 
300 INPUT:
301 OUTPUT:
302 RETURN:      OK/NOK
303 **************************************************************************/
304 TI_HANDLE wlan_memMngrInit(TI_HANDLE hOs);
305 
306 /*************************************************************************
307  *                        wlan_memMngrDestroy                            *
308  *************************************************************************
309 DESCRIPTION:
310 
311 
312 
313 INPUT:
314 OUTPUT:
315 
316 RETURN:     OK/NOK
317 **************************************************************************/
318 TI_STATUS wlan_memMngrDestroy(TI_HANDLE hMemMngr);
319 
320 /*************************************************************************
321  *                        wlan_memMngrConfigure                           *
322  *************************************************************************
323 DESCRIPTION:
324 
325 
326 
327 INPUT:
328 OUTPUT:
329 
330 RETURN:     OK/NOK
331 **************************************************************************/
332 TI_STATUS wlan_memMngrConfigure(TI_HANDLE hMemMngr, TI_HANDLE hOs, TI_HANDLE hReport);
333 
334 /*************************************************************************
335  *                        wlan_memMngrAllocDataBuf                           *
336  *************************************************************************
337 DESCRIPTION:This function allocates BDs and Data Buffers according to the
338 			required length. The memory manager will allocate the Data
339 			Buffers, update the buffer pointer in the BD structure and link
340 			the BDs when more than one Data Buffer is required.
341 
342 INPUT:      len - the length of the required data buffer
343 OUTPUT:     BDPtr - a pointer in which this function will return a pointer
344 					to the allocated BD
345 RETURN:     OK/NOK
346 **************************************************************************/
347 TI_STATUS wlan_memMngrAllocDataBuf(TI_HANDLE hMemMngr, mem_BD_T** bdPtr, UINT32 len);
348 
349 /*************************************************************************
350  *                        wlan_memMngrAllocBDs                        		 *
351  *************************************************************************
352 DESCRIPTION:This function allocates and returns a pointer to an array of BDs.
353 			This function does not allocate any memory buffers.
354 
355 INPUT:      BDsNumber - number of required BDs
356 OUTPUT:     BDsPtr - a pointer in which this function will return a pointer
357 					 to an array of BD pointers
358 RETURN:     OK/NOK
359 **************************************************************************/
360 TI_STATUS wlan_memMngrAllocBDs(TI_HANDLE hMemMngr, UINT32 bdNumber, mem_BD_T** bdPtr);
361 
362 /*************************************************************************
363  *                        wlan_memMngrAllocMSDU                          *
364  *************************************************************************
365 DESCRIPTION:This function allocates MPDU structure.
366 
367 INPUT:		len - the length of the required data buffer
368                     if len=0, than only MSDU buffer will be allocated
369 OUTPUT:     MSDUPtr - a pointer in which this function will return a pointer
370 					  to the MSDU structure
371 RETURN:     OK/NOK
372 **************************************************************************/
373 TI_STATUS wlan_memMngrAllocMSDU (TI_HANDLE hMemMngr, mem_MSDU_T** MSDUPtr,
374 							  UINT32 len, allocatingModule_e module);
375 
376 /*************************************************************************
377  *                        wlan_memMngrAllocMSDUBufferOnly	             *
378  *************************************************************************
379 DESCRIPTION:This function allocates MPDU structure - without Data Buffers
380 
381 INPUT:
382 OUTPUT:     MSDUPtr - a pointer in which this function will return a pointer
383 					  to the MSDU structure
384 RETURN:     OK/NOK
385 **************************************************************************/
386 TI_STATUS wlan_memMngrAllocMSDUBufferOnly(TI_HANDLE hMemMngr, mem_MSDU_T** MSDUPtr,
387 									   allocatingModule_e module);
388 
389 /*************************************************************************
390  *                        wlan_memMngrDuplicateMSDU                      *
391  *************************************************************************
392 DESCRIPTION:This function duplicates the MSDU.
393 
394 INPUT:      handle - handle of the MSDU the user want to duplicate
395 OUTPUT:     newHandle - pointer in which this function sets the handle of
396                     the duplicated MSDU.
397 RETURN:     OK/NOK
398 **************************************************************************/
399 TI_STATUS wlan_memMngrDuplicateMSDU(TI_HANDLE hMemMngr, UINT32 handle, UINT32* newHandle);
400 
401 /*************************************************************************
402  *                        wlan_memMngrFreeMSDU         	                 *
403  *************************************************************************
404 DESCRIPTION:Free MSDU structure. This function will free all BDs and Data
405 			Buffers that are bind to this MSDU.
406 
407 INPUT:      handle - handle of this MSDU
408 OUTPUT:
409 RETURN:     OK/NOK
410 **************************************************************************/
411 TI_STATUS wlan_memMngrFreeMSDU(TI_HANDLE hMemMngr, UINT32 handle);
412 
413 /*************************************************************************
414  *														                 *
415  *************************************************************************
416 DESCRIPTION:
417 INPUT:
418 OUTPUT:
419 RETURN:     OK/NOK
420 **************************************************************************/
421 TI_STATUS wlan_memMngrFreeListOfMSDU(TI_HANDLE hMemMngr, UINT32 handle);
422 
423 
424 /*************************************************************************
425  *                        wlan_memMngrFreeBD          	                 *
426  *************************************************************************
427 DESCRIPTION:Free BD structure. This function will free a list of BD
428 			structures and the Data Buffer that is being pointed by these BD
429 			if any. (e.g. - free MPDU)
430 
431 INPUT:      handle - handle of this BD
432 OUTPUT:
433 RETURN:     freeFlag - return TRUE if this BD list was freed
434                        return FALSE if this BD list was not freed (refCount>0)
435 **************************************************************************/
436 UINT32 wlan_memMngrFreeBD(TI_HANDLE hMemMngr, UINT32 handle);
437 
438 /*************************************************************************
439  *                                  							         *
440  *************************************************************************
441 DESCRIPTION:
442 
443 INPUT:
444 OUTPUT:
445 RETURN:
446 **************************************************************************/
447 TI_STATUS wlan_memMngrFreeAllOsAlocatesBuffer(TI_HANDLE hMemMngr);
448 
449 /*************************************************************************
450  *                                  							         *
451  *************************************************************************
452 DESCRIPTION:
453 
454 INPUT:
455 OUTPUT:
456 RETURN:
457 **************************************************************************/
458 TI_STATUS wlan_memMngrCopyMsduFreeFunc(TI_HANDLE hMemMngr, UINT32 destMsduHandle, UINT32 sourceMsduHandle);
459 
460 /*************************************************************************
461  *                                  							         *
462  *************************************************************************
463 DESCRIPTION:
464 
465 INPUT:
466 OUTPUT:
467 RETURN:
468 **************************************************************************/
469 TI_STATUS wlan_memMngrGetMemMgrResources(TI_HANDLE hMemMngr, memMgrResources_t* memMgrResources);
470 
471 /*************************************************************************
472  *                                  							         *
473  *************************************************************************
474 DESCRIPTION:
475 
476 INPUT:
477 OUTPUT:
478 RETURN:
479 **************************************************************************/
480 TI_STATUS wlan_memMngrChangeMsduOwner(TI_HANDLE hMemMngr,allocatingModule_e newModule,mem_MSDU_T *pMsdu);
481 
482 
483 TI_STATUS wlan_memMngrSwapMsdu(TI_HANDLE hMemMngr, mem_MSDU_T *pMsdu_1, mem_MSDU_T *pMsdu_2);
484 
485 
486 TI_STATUS wlan_memMngrAddTimeStamp (TI_HANDLE hMemMngr, mem_MSDU_T *pMsdu);
487 
488 /*************************************************************************
489  *					          TEST_FUNCTIONS         	                 *
490  *************************************************************************/
491 void memMngrPrintHandle(TI_HANDLE hMemMngr, UINT32 handle);
492 void memMngrFullPrint(TI_HANDLE hMemMngr);
493 void memMngrPrint(TI_HANDLE hMemMngr);
494 
495 /*test function*/
496 TI_STATUS txDataSTUB_txSendMsdu(TI_HANDLE hMemMngr, mem_MSDU_T *pMsdu);
497 void print_MsduDataHeader(TI_HANDLE hMemMngr, mem_MSDU_T *pMsdu);
498 void memMngrPrintMSDUWithItsBds(mem_MSDU_T* pMsdu );
499 
500 
501 #endif
502