PageRenderTime 60ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/drivers/net/wireless/tiwlan1251/common/src/utils/memMngrEx.c

https://bitbucket.org/cyanogenmod/cm-kernel
C | 1434 lines | 861 code | 227 blank | 346 comment | 129 complexity | 2c668407b8aa38fde73601d74abeb581 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.0, AGPL-1.0

Large files files are truncated, but you can click here to view the full file

  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. /* MODULE: memMngr.c */
  38. /* PURPOSE: manage the SDRAM buffers for MSDU Data Buffers allocations */
  39. /* */
  40. /**************************************************************************/
  41. #include "memMngrEx.h"
  42. #include "osApi.h"
  43. #include "report.h"
  44. /*************************************************************************
  45. * wlan_memMngrInit *
  46. **************************************************************************
  47. * DESCRIPTION: Init of the Memory Manager module. This function allocated
  48. * all memroy resources needed for the MemMngr. It tallocate
  49. * a pool of Msdu structure, pool of Bd structure, and
  50. * number of pools of data buffers.
  51. *
  52. * INPUT: hOs - handle to Os abstraction layer
  53. *
  54. * OUTPUT:
  55. *
  56. * RETURN: Handle to the allocated MemMngr control block
  57. **************************************************************************/
  58. TI_HANDLE wlan_memMngrInit(TI_HANDLE hOs)
  59. {
  60. memMngr_t *pMemMngr;
  61. UINT32 count,i;
  62. memMngrInit_t pMemMngrInit;
  63. if( hOs == NULL )
  64. {
  65. WLAN_OS_REPORT(("wlan_memMngrInit() : FATAL ERROR: OS handle Error - Aborting\n"));
  66. return NULL;
  67. }
  68. /* structures for initialization of Memory manager */
  69. pMemMngrInit.numOfPools = DEF_NUMBER_OF_BUF_POOLS;
  70. pMemMngrInit.bufPoolInit[0].buffersSize = DEF_BUFFER_LENGTH_POOL_1;
  71. pMemMngrInit.bufPoolInit[0].numOfbuffers = DEF_NUMBER_OF_BUFFERS_IN_POOL_1;
  72. pMemMngrInit.bufPoolInit[1].buffersSize = DEF_BUFFER_LENGTH_POOL_2;
  73. pMemMngrInit.bufPoolInit[1].numOfbuffers = DEF_NUMBER_OF_BUFFERS_IN_POOL_2;
  74. pMemMngrInit.bufPoolInit[2].buffersSize = DEF_BUFFER_LENGTH_POOL_3;
  75. pMemMngrInit.bufPoolInit[2].numOfbuffers = DEF_NUMBER_OF_BUFFERS_IN_POOL_3;
  76. for( count = 0 ; count < pMemMngrInit.numOfPools ; count++ )
  77. {
  78. if( pMemMngrInit.bufPoolInit[count].buffersSize > MAX_BUFFER_LENGTH ||
  79. pMemMngrInit.bufPoolInit[count].buffersSize < MIN_BUFFER_LENGTH)
  80. {
  81. WLAN_OS_REPORT(("wlan_memMngrInit() : FATAL ERROR: Buffer length out of range - Aborting\n"));
  82. return NULL;
  83. }
  84. if( count != 0 )
  85. {
  86. if(pMemMngrInit.bufPoolInit[count].buffersSize < pMemMngrInit.bufPoolInit[count-1].buffersSize )
  87. {
  88. WLAN_OS_REPORT(("wlan_memMngrInit() : FATAL ERROR: Buffer length's out of order - Aborting\n"));
  89. return NULL;
  90. }
  91. }
  92. }
  93. /* alocate MemMngr module control block */
  94. pMemMngr = os_memoryAlloc(hOs, (sizeof(memMngr_t)));
  95. if(!pMemMngr) {
  96. WLAN_OS_REPORT(("FATAL ERROR: Could not allocate pMemMngr - Aborting\n"));
  97. return NULL;
  98. }
  99. os_memoryZero(hOs, pMemMngr, sizeof(memMngr_t));
  100. pMemMngr->hOs = hOs;
  101. pMemMngr->msduMaxNumber = DEF_NUMBER_OF_MSDUS;
  102. pMemMngr->bdMaxNumber = DEF_NUMBER_OF_BDS;
  103. pMemMngr->numFreeMSDU = pMemMngr->msduMaxNumber;
  104. pMemMngr->numFreeBD = pMemMngr->bdMaxNumber;
  105. pMemMngr->msduPool = (mem_MSDU_T*)os_memoryCAlloc(hOs, pMemMngr->msduMaxNumber, sizeof(mem_MSDU_T));
  106. os_profile (hOs, 8, pMemMngr->msduMaxNumber * sizeof(mem_MSDU_T));
  107. if (pMemMngr->msduPool == NULL)
  108. {
  109. wlan_memMngrDestroy(pMemMngr);
  110. WLAN_OS_REPORT(("FATAL ERROR: Could not allocate memory for MEM MNGR - Aborting\n"));
  111. return NULL;
  112. }
  113. pMemMngr->bdPool = (mem_BD_T*)os_memoryCAlloc(hOs, pMemMngr->bdMaxNumber, sizeof(mem_BD_T));
  114. os_profile (hOs, 8, pMemMngr->bdMaxNumber * sizeof(mem_BD_T));
  115. if (pMemMngr->bdPool == NULL)
  116. {
  117. wlan_memMngrDestroy(pMemMngr);
  118. WLAN_OS_REPORT(("FATAL ERROR: Could not allocate memory for MEM MNGR - Aborting\n"));
  119. return NULL;
  120. }
  121. /* initialize buffer pools objects */
  122. pMemMngr->currentNumberOfPools = pMemMngrInit.numOfPools;
  123. for( count = 0 ; count < pMemMngr->currentNumberOfPools ; count++ )
  124. {
  125. pMemMngr->buffersPool[count].buffersSize = pMemMngrInit.bufPoolInit[count].buffersSize;
  126. pMemMngr->buffersPool[count].numFreeDataBuf = pMemMngrInit.bufPoolInit[count].numOfbuffers;
  127. pMemMngr->buffersPool[count].dataBufMaxNumber = pMemMngrInit.bufPoolInit[count].numOfbuffers;
  128. if((pMemMngr->buffersPool[count].dataBufPool = (mem_DataBuf_T*)os_memoryCAlloc(hOs,
  129. pMemMngr->buffersPool[count].dataBufMaxNumber, sizeof(mem_DataBuf_T))) == NULL)
  130. {
  131. wlan_memMngrDestroy(pMemMngr);
  132. WLAN_OS_REPORT(("FATAL ERROR: Could not allocate buffer pools for MEM MNGR - Aborting\n"));
  133. return NULL;
  134. }
  135. os_profile (hOs, 8, pMemMngr->buffersPool[count].dataBufMaxNumber * sizeof(mem_DataBuf_T));
  136. pMemMngr->buffersPool[count].firstFreeDataBuf = pMemMngr->buffersPool[count].dataBufPool;
  137. os_memoryZero(hOs, pMemMngr->buffersPool[count].dataBufPool,
  138. (pMemMngr->buffersPool[count].numFreeDataBuf * sizeof(mem_DataBuf_T)));
  139. #ifdef TNETW_MASTER_MODE
  140. if((pMemMngr->buffersPool[count].dataBufPoolPtr = (UINT8 *)os_memorySharedAlloc(hOs,
  141. pMemMngr->buffersPool[count].buffersSize * pMemMngr->buffersPool[count].dataBufMaxNumber,
  142. (void *)&pMemMngr->buffersPool[count].physicalDataBufPoolPtr)) == NULL)
  143. {
  144. wlan_memMngrDestroy(pMemMngr);
  145. WLAN_OS_REPORT(("FATAL ERROR: Could not allocate buffers for MEM MNGR (count=%d / %d, size=%d) - Aborting\n",
  146. count, pMemMngr->currentNumberOfPools,
  147. pMemMngr->buffersPool[count].buffersSize * pMemMngr->buffersPool[count].dataBufMaxNumber));
  148. return NULL;
  149. }
  150. #else
  151. if((pMemMngr->buffersPool[count].dataBufPoolPtr = (UINT8 *)os_memoryPreAlloc(hOs, count,
  152. pMemMngr->buffersPool[count].buffersSize * pMemMngr->buffersPool[count].dataBufMaxNumber)) == NULL)
  153. {
  154. wlan_memMngrDestroy(pMemMngr);
  155. WLAN_OS_REPORT(("FATAL ERROR: Could not allocate buffers for MEM MNGR - Aborting\n"));
  156. return NULL;
  157. }
  158. #endif
  159. os_profile (hOs, 8, pMemMngr->buffersPool[count].buffersSize * pMemMngr->buffersPool[count].dataBufMaxNumber);
  160. /* alocate the buffers */
  161. for (i = 0; i < pMemMngr->buffersPool[count].dataBufMaxNumber; ++i)
  162. {
  163. #ifdef TNETW_MASTER_MODE
  164. pMemMngr->buffersPool[count].dataBufPool[i].data = (UINT8 *)
  165. (pMemMngr->buffersPool[count].dataBufPoolPtr
  166. + i*pMemMngr->buffersPool[count].buffersSize);
  167. pMemMngr->buffersPool[count].dataBufPool[i].data_physical.u.LowPart = (ULONG)
  168. (pMemMngr->buffersPool[count].physicalDataBufPoolPtr.u.LowPart + i*pMemMngr->buffersPool[count].buffersSize);
  169. #else
  170. pMemMngr->buffersPool[count].dataBufPool[i].data = (UINT8 *)
  171. (pMemMngr->buffersPool[count].dataBufPoolPtr
  172. + i*pMemMngr->buffersPool[count].buffersSize);
  173. #endif
  174. pMemMngr->buffersPool[count].dataBufPool[i].poolIndex = count;
  175. }
  176. }
  177. /* chain the items in each list */
  178. for (count = 0; count < pMemMngr->msduMaxNumber; ++count) {
  179. pMemMngr->msduPool[count].handle = count;
  180. if (count < pMemMngr->msduMaxNumber-1) /* update next pointer except of the last one */
  181. pMemMngr->msduPool[count].nextFreeMSDU = &(pMemMngr->msduPool[count+1]);
  182. }
  183. for (count = 0; count < pMemMngr->bdMaxNumber; ++count) {
  184. pMemMngr->bdPool[count].handle = count;
  185. if (count < pMemMngr->bdMaxNumber-1) /* update next pointer except of the last one */
  186. pMemMngr->bdPool[count].nextBDPtr = &(pMemMngr->bdPool[count+1]);
  187. }
  188. for (i = 0; i < pMemMngr->currentNumberOfPools; ++i) {
  189. for (count = 0; count < pMemMngr->buffersPool[i].dataBufMaxNumber; ++count) {
  190. pMemMngr->buffersPool[i].dataBufPool[count].handle = count;
  191. if (count < pMemMngr->buffersPool[i].dataBufMaxNumber-1) /* update next pointer except of the last one */
  192. pMemMngr->buffersPool[i].dataBufPool[count].nextDataBuf = &(pMemMngr->buffersPool[i].dataBufPool[count+1]);
  193. }
  194. }
  195. /* assign a pointer for the start of each list */
  196. pMemMngr->firstFreeMSDU = pMemMngr->msduPool;
  197. pMemMngr->firstFreeBD = pMemMngr->bdPool;
  198. for(count=0 ; count < MAX_NUMBER_OF_MODULE; count++)
  199. pMemMngr->moduleAllocCount[count] = 0;
  200. if(( pMemMngr->hCriticalSectionProtect = os_protectCreate(hOs)) == NULL)
  201. {
  202. wlan_memMngrDestroy(pMemMngr);
  203. WLAN_OS_REPORT(("FATAL ERROR: Could not Create Critical Section Protection for MEM MNGR - Aborting\n"));
  204. return NULL;
  205. }
  206. return pMemMngr;
  207. }
  208. /***************************************************************************
  209. * wlan_memMngrConfigure *
  210. ****************************************************************************
  211. * DESCRIPTION: This function configures MemMngr module
  212. *
  213. * INPUTS: hMemMngr - The object
  214. * hOs - Handle to the Os Abstraction Layer
  215. * hReport - Handle to the Report object
  216. * OUTPUT:
  217. *
  218. * RETURNS: OK - Configuration succesfull
  219. * NOK - Configuration unsuccesfull
  220. ***************************************************************************/
  221. TI_STATUS wlan_memMngrConfigure(TI_HANDLE hMemMngr, TI_HANDLE hOs, TI_HANDLE hReport)
  222. {
  223. memMngr_t *pMemMngr = (memMngr_t *)hMemMngr;
  224. pMemMngr->hReport = hReport;
  225. WLAN_REPORT_INIT(pMemMngr->hReport, MEM_MGR_MODULE_LOG,
  226. (".....MemMngr configured successfully\n"));
  227. return OK;
  228. }
  229. /***************************************************************************
  230. * wlan_memMngrDestroy *
  231. ****************************************************************************
  232. * DESCRIPTION: This function unload the tMemMngr module. It first free
  233. * the msdu pool, bd pool, data buffers pools and
  234. * then free the tMemMngr control block
  235. *
  236. * INPUTS: hMemMngr - the object
  237. *
  238. * OUTPUT:
  239. *
  240. * RETURNS: OK - Unload succesfull
  241. * NOK - Unload unsuccesfull
  242. ***************************************************************************/
  243. TI_STATUS wlan_memMngrDestroy(TI_HANDLE hMemMngr)
  244. {
  245. UINT32 count;
  246. memMngr_t *pMemMngr = (memMngr_t *)hMemMngr;
  247. /* Free Msdu pool */
  248. if(pMemMngr->msduPool)
  249. {
  250. os_memoryFree(pMemMngr->hOs, pMemMngr->msduPool,
  251. sizeof(mem_MSDU_T)*pMemMngr->msduMaxNumber);
  252. }
  253. /* Free Bd pool */
  254. if(pMemMngr->bdPool)
  255. {
  256. os_memoryFree(pMemMngr->hOs, pMemMngr->bdPool,
  257. sizeof(mem_BD_T)*pMemMngr->bdMaxNumber);
  258. }
  259. /* free data buf pools according to the number of pools */
  260. for( count = 0 ; count < pMemMngr->currentNumberOfPools ; count++ )
  261. {
  262. #ifdef TNETW_MASTER_MODE
  263. if(pMemMngr->buffersPool[count].dataBufPoolPtr)
  264. {
  265. os_memorySharedFree(pMemMngr->hOs,pMemMngr->buffersPool[count].dataBufPoolPtr,
  266. pMemMngr->buffersPool[count].buffersSize*pMemMngr->buffersPool[count].dataBufMaxNumber,
  267. pMemMngr->buffersPool[count].physicalDataBufPoolPtr);
  268. }
  269. #else
  270. if(pMemMngr->buffersPool[count].dataBufPoolPtr)
  271. {
  272. os_memoryFree(pMemMngr->hOs,pMemMngr->buffersPool[count].dataBufPoolPtr,
  273. pMemMngr->buffersPool[count].buffersSize*pMemMngr->buffersPool[count].dataBufMaxNumber);
  274. }
  275. #endif
  276. if(pMemMngr->buffersPool[count].dataBufPool)
  277. {
  278. os_memoryFree(pMemMngr->hOs, pMemMngr->buffersPool[count].dataBufPool,
  279. sizeof(mem_DataBuf_T)*pMemMngr->buffersPool[count].dataBufMaxNumber);
  280. }
  281. }
  282. /* free os_protect resources */
  283. if(pMemMngr->hCriticalSectionProtect)
  284. os_protectDestroy(pMemMngr->hOs,pMemMngr->hCriticalSectionProtect);
  285. /* free the MemMngr control block */
  286. os_memoryFree(pMemMngr->hOs, pMemMngr,sizeof(memMngr_t));
  287. return OK;
  288. }
  289. /*************************************************************************
  290. * wlan_memMngrAllocDataBuf *
  291. **************************************************************************
  292. * DESCRIPTION: This function allocates BDs and Data Buffers according
  293. * to the required length. The memory manager will allocate
  294. * the Data Buffers, update the buffer pointer in the BD
  295. * structure and link the BDs when more than one Data
  296. * Buffer is required. The Buffer length is selected that
  297. * minimum beffer len will allocted.
  298. *
  299. * INPUT: hMemMngr - the object
  300. * len - the length of the required data buffer
  301. *
  302. * OUTPUT: BDPtr - a pointer in which this function will return
  303. * to the allocated BD
  304. *
  305. *RETURN: OK/NOK
  306. **************************************************************************/
  307. TI_STATUS wlan_memMngrAllocDataBuf(TI_HANDLE hMemMngr, mem_BD_T** bdPtr, UINT32 len)
  308. {
  309. UINT32 poolIndex,count,dataBufNum;
  310. mem_BD_T* allocBdTmp; /* pointer to the current allocated BD in the new list */
  311. mem_DataBuf_T* allocDataBufTmp; /* pointer to the current allocated Data Buf */
  312. buffersPool_t* tempBuffersPool;
  313. memMngr_t *pMemMngr = (memMngr_t *)hMemMngr;
  314. /* calculate the length and the number of Data Buffers we need allocate */
  315. for (poolIndex = 0; poolIndex < pMemMngr->currentNumberOfPools-1; poolIndex++)
  316. {
  317. if(len < pMemMngr->buffersPool[poolIndex].buffersSize)
  318. break;
  319. }
  320. /* the selected buffer pool */
  321. tempBuffersPool = &pMemMngr->buffersPool[poolIndex];
  322. /* calculate the number of buffers needed */
  323. dataBufNum = (len / tempBuffersPool->buffersSize) + 1;
  324. os_protectLock(pMemMngr->hOs, pMemMngr->hCriticalSectionProtect); /* START OF CRITICAL SECTION */
  325. allocBdTmp = pMemMngr->firstFreeBD;
  326. *bdPtr = pMemMngr->firstFreeBD;
  327. allocDataBufTmp = tempBuffersPool->firstFreeDataBuf;
  328. /* check if we have enough memory - Data buffers (in the selected pool) and Bds */
  329. if ((pMemMngr->numFreeBD < dataBufNum) || (tempBuffersPool->numFreeDataBuf < dataBufNum))
  330. {
  331. os_protectUnlock(pMemMngr->hOs, pMemMngr->hCriticalSectionProtect); /* END OF CRITICAL SECTION */
  332. WLAN_REPORT_ERROR(pMemMngr->hReport, MEM_MGR_MODULE_LOG,
  333. ("DB: mem_allocDataBuf: not enough memory numFreeBD=%d numFreeDataBuf=%d in Pool number=%d req DataBufs=%d\n",
  334. pMemMngr->numFreeBD, tempBuffersPool->numFreeDataBuf,poolIndex, dataBufNum));
  335. *bdPtr = NULL;
  336. return NOK;
  337. }
  338. /* update the pointers to the head of the list */
  339. for (count = 0 ; count < dataBufNum ; ++count)
  340. {
  341. allocBdTmp->refCount = 1;
  342. allocBdTmp->dataBuf = allocDataBufTmp;
  343. allocBdTmp->data = (char*)(allocDataBufTmp->data);
  344. #ifdef TNETW_MASTER_MODE
  345. allocBdTmp->data_physical_low = os_memoryGetPhysicalLow(allocDataBufTmp->data_physical);
  346. #endif
  347. allocDataBufTmp->refCount = 1;
  348. allocBdTmp->length = tempBuffersPool->buffersSize;
  349. if (count == (dataBufNum-1))
  350. {
  351. /* the last BD in the allocated list */
  352. pMemMngr->firstFreeBD = allocBdTmp->nextBDPtr;
  353. tempBuffersPool->firstFreeDataBuf = allocDataBufTmp->nextDataBuf;
  354. allocBdTmp->nextBDPtr = NULL;
  355. allocDataBufTmp->nextDataBuf = NULL;
  356. }
  357. else
  358. {
  359. allocBdTmp = allocBdTmp->nextBDPtr;
  360. allocDataBufTmp = allocDataBufTmp->nextDataBuf;
  361. }
  362. }
  363. /* update counter of free Bds and Data buffers */
  364. pMemMngr->numFreeBD -= dataBufNum;
  365. tempBuffersPool->numFreeDataBuf -= dataBufNum;
  366. os_protectUnlock(pMemMngr->hOs, pMemMngr->hCriticalSectionProtect); /* END OF CRITICAL SECTION */
  367. return OK;
  368. }
  369. /*************************************************************************
  370. * wlan_memMngrAllocBDs *
  371. **************************************************************************
  372. * DESCRIPTION: This function allocates and returns a pointer to a link
  373. * list of BDs. This function allocates only Bds structure
  374. * and does not allocate any memory buffers.
  375. *
  376. * INPUT: hMemMngr - The object
  377. * bdNumber - number of required BDs
  378. *
  379. * OUTPUT: bdPtr - a pointer in which this function will return
  380. * to the first Bd in the allocated list
  381. *
  382. * RETURN: OK/NOK
  383. **************************************************************************/
  384. TI_STATUS wlan_memMngrAllocBDs(TI_HANDLE hMemMngr, UINT32 bdNumber, mem_BD_T** bdPtr)
  385. {
  386. UINT32 count;
  387. mem_BD_T* allocBdTmp; /* pointer to the current allocated BD in the new list */
  388. memMngr_t *pMemMngr = (memMngr_t *)hMemMngr;
  389. if (bdNumber == 0)
  390. {
  391. *bdPtr = NULL;
  392. return NOK;
  393. }
  394. os_protectLock(pMemMngr->hOs, pMemMngr->hCriticalSectionProtect); /* START OF CRITICAL SECTION */
  395. allocBdTmp = pMemMngr->firstFreeBD;
  396. *bdPtr = pMemMngr->firstFreeBD;
  397. /* check if we have enough Bds */
  398. if (pMemMngr->numFreeBD < bdNumber)
  399. {
  400. os_protectUnlock(pMemMngr->hOs, pMemMngr->hCriticalSectionProtect); /* END OF CRITICAL SECTION */
  401. WLAN_REPORT_ERROR(pMemMngr->hReport, MEM_MGR_MODULE_LOG,
  402. ("DB: wlan_memMngrAllocBDs: not enough memory\n"));
  403. *bdPtr = NULL;
  404. return NOK;
  405. }
  406. /* update the pointers to the head of the list */
  407. for (count = 0 ; count < bdNumber ; ++count)
  408. {
  409. allocBdTmp->refCount = 1;
  410. if (count == (bdNumber-1))
  411. {
  412. /* the last bd in the allocated list */
  413. pMemMngr->firstFreeBD = allocBdTmp->nextBDPtr;
  414. allocBdTmp->nextBDPtr = NULL;
  415. }
  416. else
  417. {
  418. allocBdTmp = allocBdTmp->nextBDPtr;
  419. }
  420. }
  421. /* update counter of free Bds */
  422. pMemMngr->numFreeBD -= bdNumber;
  423. os_protectUnlock(pMemMngr->hOs, pMemMngr->hCriticalSectionProtect); /* END OF CRITICAL SECTION */
  424. return OK;
  425. }
  426. /*************************************************************************
  427. * wlan_memMngrAllocMSDU *
  428. **************************************************************************
  429. * DESCRIPTION: This function allocates MSDU structure with a number of
  430. * BDs and Data Buffers as required by 'len'.
  431. *
  432. * INPUT: hMemMngr - The object
  433. * len - the length of the required data buffer
  434. * if len=0, than only MSDU buffer will be allocated
  435. * module - the module that allocate this Msdu
  436. *
  437. * OUTPUT: MSDUPtr - a pointer in which this function will
  438. * return to the allocated MSDU structure
  439. *
  440. * RETURN: OK/NOK
  441. **************************************************************************/
  442. TI_STATUS wlan_memMngrAllocMSDU (TI_HANDLE hMemMngr, mem_MSDU_T** MSDUPtr,
  443. UINT32 len, allocatingModule_e module)
  444. {
  445. UINT32 rc;
  446. mem_BD_T* bdTmp;
  447. memMngr_t *pMemMngr = (memMngr_t *)hMemMngr;
  448. if (pMemMngr->msduPool == NULL)
  449. {
  450. /* object not initiated yet (!!!) */
  451. *MSDUPtr = NULL;
  452. WLAN_REPORT_ERROR(pMemMngr->hReport, MEM_MGR_MODULE_LOG,
  453. ("wlan_memMngrAllocMSDU: failed!\n"));
  454. memMngrPrint(hMemMngr);
  455. return NOK;
  456. }
  457. if (len > 0)
  458. {
  459. /* we need to allocate BD and Data Buffers */
  460. rc = wlan_memMngrAllocDataBuf(hMemMngr,&bdTmp, len);
  461. if (rc == NOK)
  462. {
  463. *MSDUPtr = NULL;
  464. WLAN_REPORT_ERROR(pMemMngr->hReport, MEM_MGR_MODULE_LOG,
  465. ("wlan_memMngrAllocMSDU: failed! no data bufs\n"));
  466. memMngrPrint(hMemMngr);
  467. return NOK;
  468. }
  469. }
  470. else
  471. {
  472. /* len = 0 - need to allocate msdu structure only */
  473. rc = wlan_memMngrAllocMSDUBufferOnly(hMemMngr, MSDUPtr, module);
  474. if (rc == NOK)
  475. {
  476. *MSDUPtr = NULL;
  477. WLAN_REPORT_ERROR(pMemMngr->hReport, MEM_MGR_MODULE_LOG,
  478. ("wlan_memMngrAllocMSDU: failed to alloc buffer only!\n"));
  479. memMngrPrint(hMemMngr);
  480. return NOK;
  481. }
  482. return OK;
  483. }
  484. os_protectLock(pMemMngr->hOs, pMemMngr->hCriticalSectionProtect); /* START OF CRITICAL SECTION */
  485. /* check if we have enough free Msdu's */
  486. if (pMemMngr->firstFreeMSDU == NULL)
  487. {
  488. /* no free MSDU buffers */
  489. WLAN_REPORT_ERROR(pMemMngr->hReport, MEM_MGR_MODULE_LOG,
  490. ("wlan_memMngrAllocMSDU no free MSDU in MemMngr !!!\n"));
  491. os_protectUnlock(pMemMngr->hOs, pMemMngr->hCriticalSectionProtect); /* END OF CRITICAL SECTION */
  492. memMngrPrint(hMemMngr);
  493. /* In case we dont have free msdu - free the allocated Bds */
  494. wlan_memMngrFreeBD(hMemMngr,bdTmp->handle);
  495. *MSDUPtr = NULL;
  496. return NOK;
  497. }
  498. *MSDUPtr = pMemMngr->firstFreeMSDU;
  499. pMemMngr->firstFreeMSDU = pMemMngr->firstFreeMSDU->nextFreeMSDU;
  500. pMemMngr->moduleAllocCount[module]++;
  501. /* update counter of free msdu's */
  502. pMemMngr->numFreeMSDU--;
  503. os_protectUnlock(pMemMngr->hOs, pMemMngr->hCriticalSectionProtect); /* END OF CRITICAL SECTION */
  504. (*MSDUPtr)->nextFreeMSDU = NULL;
  505. (*MSDUPtr)->freeFunc = NULL;
  506. (*MSDUPtr)->firstBDPtr = bdTmp;
  507. (*MSDUPtr)->lastBDPtr = bdTmp;
  508. (*MSDUPtr)->dataLen = len;
  509. (*MSDUPtr)->nextMSDUinList = NULL;
  510. (*MSDUPtr)->prevMSDUinList = NULL;
  511. (*MSDUPtr)->txFlags = 0;
  512. (*MSDUPtr)->txCompleteFlags = 0;
  513. (*MSDUPtr)->module = module;
  514. #ifdef TI_DBG
  515. (*MSDUPtr)->timeStampNum = 0;
  516. #endif
  517. return OK;
  518. }
  519. /*************************************************************************
  520. * wlan_memMngrAllocMSDUBufferOnly *
  521. **************************************************************************
  522. * DESCRIPTION: This function allocates MSDU structure - without
  523. * Bds and Data Buffers
  524. *
  525. * INPUT: hMemMngr - The object
  526. *
  527. * OUTPUT: MSDUPtr - a pointer in which this function will return
  528. * to the allocated MSDU structure
  529. * module - the module that allocate this Msdu
  530. *
  531. * RETURN: OK/NOK
  532. **************************************************************************/
  533. TI_STATUS wlan_memMngrAllocMSDUBufferOnly(TI_HANDLE hMemMngr, mem_MSDU_T** MSDUPtr, allocatingModule_e module)
  534. {
  535. memMngr_t *pMemMngr = (memMngr_t *)hMemMngr;
  536. os_protectLock(pMemMngr->hOs, pMemMngr->hCriticalSectionProtect); /* START OF CRITICAL SECTION */
  537. if (pMemMngr->firstFreeMSDU == NULL)
  538. {
  539. /* no free MSDU buffers */
  540. WLAN_REPORT_ERROR(pMemMngr->hReport, MEM_MGR_MODULE_LOG,
  541. ("wlan_memMngrAllocMSDUBufferOnly no free MSDU in MemMngr !!!\n"));
  542. os_protectUnlock(pMemMngr->hOs, pMemMngr->hCriticalSectionProtect); /* END OF CRITICAL SECTION */
  543. *MSDUPtr = NULL;
  544. return NOK;
  545. }
  546. *MSDUPtr = pMemMngr->firstFreeMSDU;
  547. pMemMngr->firstFreeMSDU = pMemMngr->firstFreeMSDU->nextFreeMSDU;
  548. pMemMngr->moduleAllocCount[module]++;
  549. /* update counter of free msdu's */
  550. pMemMngr->numFreeMSDU--;
  551. os_protectUnlock(pMemMngr->hOs, pMemMngr->hCriticalSectionProtect); /* END OF CRITICAL SECTION */
  552. (*MSDUPtr)->nextFreeMSDU = NULL;
  553. (*MSDUPtr)->freeFunc = NULL;
  554. (*MSDUPtr)->firstBDPtr = NULL;
  555. (*MSDUPtr)->lastBDPtr = NULL;
  556. (*MSDUPtr)->dataLen = 0;
  557. (*MSDUPtr)->nextMSDUinList = NULL;
  558. (*MSDUPtr)->prevMSDUinList = NULL;
  559. (*MSDUPtr)->txFlags = 0;
  560. (*MSDUPtr)->txCompleteFlags = 0;
  561. (*MSDUPtr)->module = module;
  562. #ifdef TI_DBG
  563. (*MSDUPtr)->timeStampNum = 0;
  564. #endif
  565. return OK;
  566. }
  567. /*************************************************************************
  568. * wlan_memMngrFreeListOfMSDU *
  569. **************************************************************************
  570. * DESCRIPTION: Free list of MSDUs structure. This function will run
  571. * over the MSDU list (if exist) and free all MSDU's with
  572. * all BDs and Data Buffers that are bind to this MSDU.
  573. *
  574. * INPUT: hMemMngr - The object
  575. * handle - handle to the first MSDU in the list
  576. *
  577. * OUTPUT:
  578. *
  579. * RETURN: OK/NOK
  580. **************************************************************************/
  581. TI_STATUS wlan_memMngrFreeListOfMSDU(TI_HANDLE hMemMngr, UINT32 handle)
  582. {
  583. mem_MSDU_T *msduTmp,*nextTmpMsdu;
  584. memMngr_t *pMemMngr = (memMngr_t *)hMemMngr;
  585. msduTmp = &(pMemMngr->msduPool[handle]);
  586. while (msduTmp != NULL)
  587. {
  588. nextTmpMsdu = msduTmp->nextMSDUinList;
  589. if(wlan_memMngrFreeMSDU(hMemMngr,memMgr_MsduHandle(msduTmp)) != OK)
  590. {
  591. WLAN_REPORT_ERROR(pMemMngr->hReport, MEM_MGR_MODULE_LOG,
  592. ("wlan_memMngrFreeListOfMSDU This MSDU is already free\n"));
  593. //os_protectUnlock(pMemMngr->hOs, pMemMngr->hCriticalSectionProtect); /* END OF CRITICAL SECTION */
  594. return NOK;
  595. }
  596. msduTmp = nextTmpMsdu;
  597. }
  598. return OK;
  599. }
  600. /*************************************************************************
  601. * wlan_memMngrFreeMSDU *
  602. **************************************************************************
  603. * DESCRIPTION: Free ONE MSDU structure. This function will free all
  604. * BDs and Data Buffers that are bind to this MSDU.
  605. *
  606. * INPUT: hMemMngr - The object
  607. * handle - handle of the MSDU
  608. *
  609. * OUTPUT:
  610. *
  611. * RETURN: OK/NOK
  612. **************************************************************************/
  613. TI_STATUS wlan_memMngrFreeMSDU(TI_HANDLE hMemMngr, UINT32 handle)
  614. {
  615. UINT32 freeFlag;
  616. ap_FreeMemFunc freeFunc = NULL; /* pointer to the Data Buffer free function */
  617. UINT32 freeArgs[NUM_OF_FREE_ARGS]; /* arguments to be send with the free function */
  618. int i;
  619. memMngr_t *pMemMngr = (memMngr_t *)hMemMngr;
  620. if( handle == WLAN_DRV_NULL_MEM_HANDLE )
  621. return OK;
  622. /* check if the msdu is already free */
  623. if(pMemMngr->msduPool[handle].module == MODULE_FREE_MSDU)
  624. {
  625. WLAN_REPORT_ERROR(pMemMngr->hReport, MEM_MGR_MODULE_LOG,
  626. ("wlan_memMngrFreeMSDU This MSDU is already free\n"));
  627. return NOK;
  628. }
  629. if (pMemMngr->msduPool[handle].firstBDPtr != NULL)
  630. {
  631. /* free all BDs and Data Buffers */
  632. freeFlag = wlan_memMngrFreeBD(hMemMngr, pMemMngr->msduPool[handle].firstBDPtr->handle);
  633. if ((freeFlag == TRUE) && (pMemMngr->msduPool[handle].freeFunc != NULL))
  634. {
  635. /* save the free parameters to do it at the end of the function */
  636. freeFunc = pMemMngr->msduPool[handle].freeFunc;
  637. for (i=0; i<NUM_OF_FREE_ARGS; i++)
  638. freeArgs[i] = pMemMngr->msduPool[handle].freeArgs[i];
  639. }
  640. }
  641. os_protectLock(pMemMngr->hOs, pMemMngr->hCriticalSectionProtect); /* START OF CRITICAL SECTION */
  642. /* reset the fields of the MSDU buffer */
  643. pMemMngr->msduPool[handle].firstBDPtr = NULL;
  644. pMemMngr->msduPool[handle].freeFunc = NULL;
  645. pMemMngr->msduPool[handle].freeArgs[0] = 0;
  646. pMemMngr->msduPool[handle].freeArgs[1] = 0;
  647. pMemMngr->msduPool[handle].freeArgs[2] = 0;
  648. pMemMngr->msduPool[handle].dataLen = 0;
  649. pMemMngr->msduPool[handle].headerLen = 0;
  650. pMemMngr->msduPool[handle].txFlags = 0;
  651. pMemMngr->msduPool[handle].txCompleteFlags = 0;
  652. pMemMngr->msduPool[handle].nextMSDUinList = 0;
  653. pMemMngr->msduPool[handle].prevMSDUinList = 0;
  654. pMemMngr->numFreeMSDU++;
  655. pMemMngr->moduleAllocCount[pMemMngr->msduPool[handle].module]--;
  656. pMemMngr->msduPool[handle].module = MODULE_FREE_MSDU;
  657. /* add the MSDU to the free MSDU list */
  658. pMemMngr->msduPool[handle].nextFreeMSDU = pMemMngr->firstFreeMSDU;
  659. pMemMngr->firstFreeMSDU = &(pMemMngr->msduPool[handle]);
  660. os_protectUnlock(pMemMngr->hOs, pMemMngr->hCriticalSectionProtect); /* END OF CRITICAL SECTION */
  661. /* !!!!!!!! The free should be only after os_protectUnlock !!!!!!!! */
  662. if (freeFunc != NULL)
  663. {
  664. /* call free function */
  665. freeFunc((TI_HANDLE)(freeArgs[0]),
  666. (TI_HANDLE)(freeArgs[1]),
  667. (TI_STATUS)(freeArgs[2]));
  668. }
  669. return OK;
  670. }
  671. /*************************************************************************
  672. * allocDataBuf *
  673. **************************************************************************
  674. * DESCRIPTION: Allocate Data Buffer
  675. *
  676. * INPUT: hMemMngr - The object
  677. * dataBuf - pointer to the new allocated Data Buffer
  678. * poolIndex - The index of the pool to allocate from
  679. *
  680. * OUTPUT:
  681. *
  682. * RETURN: OK/NOK
  683. **************************************************************************/
  684. #if 0
  685. static TI_STATUS allocDataBuf(TI_HANDLE hMemMngr, mem_DataBuf_T* dataBuf, UINT32 poolIndex)
  686. {
  687. memMngr_t *pMemMngr = (memMngr_t *)hMemMngr;
  688. os_protectLock(pMemMngr->hOs, pMemMngr->hCriticalSectionProtect); /* START OF CRITICAL SECTION */
  689. if (pMemMngr->buffersPool[poolIndex].firstFreeDataBuf == NULL) {
  690. os_protectUnlock(pMemMngr->hOs, pMemMngr->hCriticalSectionProtect);/* END OF CRITICAL SECTION */
  691. return NOK;
  692. }
  693. dataBuf = pMemMngr->buffersPool[poolIndex].firstFreeDataBuf;
  694. pMemMngr->buffersPool[poolIndex].firstFreeDataBuf = pMemMngr->buffersPool[poolIndex].firstFreeDataBuf->nextDataBuf;
  695. pMemMngr->buffersPool[poolIndex].numFreeDataBuf--;
  696. os_protectUnlock(pMemMngr->hOs, pMemMngr->hCriticalSectionProtect);/* END OF CRITICAL SECTION */
  697. return OK;
  698. }
  699. #endif
  700. /*************************************************************************
  701. * freeDataBuf *
  702. **************************************************************************
  703. * DESCRIPTION: Free Data Buffer.
  704. *
  705. * INPUT: hMemMngr - The object
  706. * dataBuf - pointer to the Data Buffer
  707. *
  708. * OUTPUT:
  709. *
  710. * RETURN: OK/NOK
  711. **************************************************************************/
  712. static TI_STATUS freeDataBuf(TI_HANDLE hMemMngr, mem_DataBuf_T* dataBuf)
  713. {
  714. buffersPool_t *tempBuffersPool;
  715. memMngr_t *pMemMngr = (memMngr_t *)hMemMngr;
  716. if (dataBuf->refCount == 0) {
  717. WLAN_REPORT_ERROR(pMemMngr->hReport, MEM_MGR_MODULE_LOG,
  718. ("DB: freeDataBuf FATAL ERROR: dataBuf->refCount < 0\n"));
  719. return NOK;
  720. }
  721. if (--(dataBuf->refCount) == 0) {
  722. tempBuffersPool = &pMemMngr->buffersPool[dataBuf->poolIndex];
  723. /* add this Data Buffer to the free list of the correct pool*/
  724. dataBuf->nextDataBuf = tempBuffersPool->firstFreeDataBuf;
  725. tempBuffersPool->firstFreeDataBuf = dataBuf;
  726. tempBuffersPool->numFreeDataBuf++;
  727. }
  728. return OK;
  729. }
  730. /*************************************************************************
  731. * wlan_memMngrFreeBD *
  732. **************************************************************************
  733. * DESCRIPTION: Free BD structure. This function will free a list of BD
  734. * structures and the Data Buffer that is being pointed by
  735. * these BD if any.
  736. *
  737. * INPUT: hMemMngr - The object
  738. * handle - handle of this BD
  739. * OUTPUT:
  740. * RETURN: freeFlag - return TRUE if this BD list was freed
  741. * return FALSE if this BD list was not freed (refCount>0)
  742. **************************************************************************/
  743. UINT32 wlan_memMngrFreeBD(TI_HANDLE hMemMngr, UINT32 handle)
  744. {
  745. UINT32 rc = FALSE;
  746. mem_DataBuf_T* dataBuf;
  747. mem_BD_T* bdTmp; /* pointer to the current BD we need to free */
  748. mem_BD_T* nextBdTmp; /* pointer to the next BD we need to free */
  749. memMngr_t *pMemMngr = (memMngr_t *)hMemMngr;
  750. bdTmp = &(pMemMngr->bdPool[handle]);
  751. os_protectLock(pMemMngr->hOs, pMemMngr->hCriticalSectionProtect); /* START OF CRITICAL SECTION */
  752. while (bdTmp != NULL)
  753. {
  754. dataBuf = bdTmp->dataBuf;
  755. nextBdTmp = bdTmp->nextBDPtr;
  756. if (bdTmp->refCount == 0)
  757. {
  758. WLAN_REPORT_ERROR(pMemMngr->hReport, MEM_MGR_MODULE_LOG,
  759. ("DB: wlan_memMngrFreeBD FATAL ERROR: bdTmp->refCount < 0\n"));
  760. os_protectUnlock(pMemMngr->hOs, pMemMngr->hCriticalSectionProtect);/* END OF CRITICAL SECTION */
  761. return FALSE;
  762. }
  763. if (dataBuf != NULL)
  764. {
  765. freeDataBuf(hMemMngr, dataBuf);
  766. }
  767. #ifdef TNETW_MASTER_MODE
  768. if( bdTmp->freeFunc != NULL)
  769. {
  770. bdTmp->freeFunc( bdTmp->freeArgs[0], bdTmp->freeArgs[1], bdTmp->freeArgs[2],
  771. bdTmp->freeArgs[3], bdTmp->freeArgs[4]);
  772. }
  773. #endif
  774. if (--(bdTmp->refCount) == 0)
  775. {
  776. bdTmp->dataBuf = NULL;
  777. bdTmp->data = NULL;
  778. #ifdef TNETW_MASTER_MODE
  779. bdTmp->data_physical_low = 0;
  780. bdTmp->freeFunc = NULL;
  781. os_memoryZero(pMemMngr->hOs, bdTmp->freeArgs, sizeof(UINT32)*NUM_OF_FREE_ARGS);
  782. #endif
  783. bdTmp->dataOffset = 0;
  784. bdTmp->length = 0;
  785. /* adding the free BD to the free BD list */
  786. bdTmp->nextBDPtr = pMemMngr->firstFreeBD;
  787. pMemMngr->firstFreeBD = bdTmp;
  788. pMemMngr->numFreeBD++;
  789. }
  790. if (nextBdTmp == NULL)
  791. {
  792. if (bdTmp->refCount <= 0)
  793. {
  794. rc = TRUE;
  795. }
  796. }
  797. bdTmp = nextBdTmp;
  798. }
  799. os_protectUnlock(pMemMngr->hOs, pMemMngr->hCriticalSectionProtect); /* END OF CRITICAL SECTION */
  800. return rc;
  801. }
  802. /*************************************************************************
  803. * wlan_memMngrFreeAllOsAlocatesBuffer *
  804. **************************************************************************
  805. * DESCRIPTION: This function run over the all msdus in the MemMngr
  806. * and call the free function of the os allocated buffers
  807. *
  808. * INPUT: hMemMngr - The object
  809. *
  810. * OUTPUT:
  811. *
  812. * RETURN: OK
  813. **************************************************************************/
  814. TI_STATUS wlan_memMngrFreeAllOsAlocatesBuffer(TI_HANDLE hMemMngr)
  815. {
  816. UINT32 count;
  817. memMngr_t *pMemMngr = (memMngr_t *)hMemMngr;
  818. os_protectLock(pMemMngr->hOs, pMemMngr->hCriticalSectionProtect);/* START OF CRITICAL SECTION */
  819. for(count = 0 ; count < pMemMngr->msduMaxNumber ; count++)
  820. {
  821. if (pMemMngr->msduPool[count].freeFunc)
  822. {
  823. WLAN_OS_REPORT(("wlan_memMngrFreeAllOsAlocatesBuffer() - Call Os free func */*/*/**/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/ :\n"));
  824. #ifndef TNETW_MASTER_MODE
  825. pMemMngr->msduPool[count].freeArgs[2] = NOK;
  826. #endif
  827. /* call free function */
  828. pMemMngr->msduPool[count].freeFunc((TI_HANDLE)(pMemMngr->msduPool[count].freeArgs[0]),
  829. (TI_HANDLE)(pMemMngr->msduPool[count].freeArgs[1]),
  830. (TI_STATUS)(pMemMngr->msduPool[count].freeArgs[2]));
  831. pMemMngr->msduPool[count].freeFunc = NULL;
  832. pMemMngr->msduPool[count].freeArgs[0] = 0;
  833. pMemMngr->msduPool[count].freeArgs[1] = 0;
  834. pMemMngr->msduPool[count].freeArgs[2] = 0;
  835. }
  836. }
  837. os_protectUnlock(pMemMngr->hOs, pMemMngr->hCriticalSectionProtect);/* END OF CRITICAL SECTION */
  838. return OK;
  839. }
  840. /*************************************************************************
  841. * wlan_memMngrCopyMsduFreeFunc *
  842. **************************************************************************
  843. * DESCRIPTION: Copy The free function and the free arguments from on
  844. * Msdu to another
  845. *
  846. * INPUT: hMemMngr - The object
  847. * destMsduHandle - the handle of the destination msdu
  848. * sourceMsduHandle - the handle of the source msdu
  849. *
  850. * OUTPUT:
  851. *
  852. * RETURN: OK
  853. **************************************************************************/
  854. TI_STATUS wlan_memMngrCopyMsduFreeFunc(TI_HANDLE hMemMngr, UINT32 destMsduHandle, UINT32 sourceMsduHandle)
  855. {
  856. mem_MSDU_T* sourceMsdu;
  857. mem_MSDU_T* destMsdu;
  858. memMngr_t *pMemMngr = (memMngr_t *)hMemMngr;
  859. if( destMsduHandle == WLAN_DRV_NULL_MEM_HANDLE || sourceMsduHandle == WLAN_DRV_NULL_MEM_HANDLE )
  860. return NOK;
  861. os_protectLock(pMemMngr->hOs, pMemMngr->hCriticalSectionProtect); /* START OF CRITICAL SECTION */
  862. sourceMsdu = &(pMemMngr->msduPool[sourceMsduHandle]);
  863. destMsdu = &(pMemMngr->msduPool[destMsduHandle]);
  864. destMsdu->freeFunc = sourceMsdu->freeFunc;
  865. os_memoryCopy(pMemMngr->hOs, (void *)destMsdu->freeArgs, (void *)sourceMsdu->freeArgs,(NUM_OF_FREE_ARGS*sizeof(UINT32)));
  866. os_protectUnlock(pMemMngr->hOs, pMemMngr->hCriticalSectionProtect);/* END OF CRITICAL SECTION */
  867. return OK;
  868. }
  869. /*************************************************************************
  870. * wlan_memMngrChangeMsduOwner *
  871. **************************************************************************
  872. * DESCRIPTION: the function changes the msdu module owner.
  873. *
  874. * INPUT: hMemMngr - The object
  875. * newModule - msdu new module owner
  876. * pMsdu - the msdu to be changed
  877. *
  878. * OUTPUT:
  879. *
  880. * RETURN: OK
  881. **************************************************************************/
  882. TI_STATUS wlan_memMngrChangeMsduOwner(TI_HANDLE hMemMngr,allocatingModule_e newModule,mem_MSDU_T *pMsdu)
  883. {
  884. memMngr_t *pMemMngr = (memMngr_t *)hMemMngr;
  885. allocatingModule_e oldModule;
  886. if(pMsdu == NULL)
  887. {
  888. WLAN_REPORT_ERROR(pMemMngr->hReport, MEM_MGR_MODULE_LOG,
  889. ("wlan_memMngrChangeMsduOwner: pMsdu == NULL\n"));
  890. return NOK;
  891. }
  892. oldModule = pMsdu->module;
  893. if(pMemMngr->moduleAllocCount[oldModule] > 0)
  894. {
  895. pMemMngr->moduleAllocCount[oldModule]--;
  896. }
  897. else
  898. {
  899. WLAN_REPORT_ERROR(pMemMngr->hReport, MEM_MGR_MODULE_LOG,
  900. ("wlan_memMngrChangeMsduOwner: oldModule %d AllocCount < 0 ,newModule %d\n", oldModule,newModule));
  901. return NOK;
  902. }
  903. pMemMngr->moduleAllocCount[newModule]++;
  904. pMsdu->module = newModule;
  905. WLAN_REPORT_INFORMATION(pMemMngr->hReport, MEM_MGR_MODULE_LOG,
  906. ("wlan_memMngrChangeMsduOwner: oldModule: %d , newModule: %d\n", oldModule, newModule));
  907. return OK;
  908. }
  909. /*************************************************************************
  910. * wlan_memMngrSwapMsdu *
  911. **************************************************************************
  912. * DESCRIPTION: Swap two Msdu, only the MSDU descriptor and not all fields
  913. *
  914. * INPUT:
  915. *
  916. * OUTPUT:
  917. *
  918. * RETURN: OK
  919. **************************************************************************/
  920. TI_STATUS wlan_memMngrSwapMsdu(TI_HANDLE hMemMngr, mem_MSDU_T *pMsdu_1, mem_MSDU_T *pMsdu_2)
  921. {
  922. memMngr_t *pMemMngr = (memMngr_t *)hMemMngr;
  923. mem_MSDU_T Msdu_tmp;
  924. os_protectLock(pMemMngr->hOs, pMemMngr->hCriticalSectionProtect); /* START OF CRITICAL SECTION */
  925. /* copy msdu 1 to Temporary msdu */
  926. Msdu_tmp.freeFunc = pMsdu_1->freeFunc;
  927. os_memoryCopy(pMemMngr->hOs, (void *)Msdu_tmp.freeArgs, (void *)pMsdu_1->freeArgs,(NUM_OF_FREE_ARGS*sizeof(UINT32)));
  928. Msdu_tmp.dataLen = pMsdu_1->dataLen;
  929. Msdu_tmp.headerLen = pMsdu_1->headerLen;
  930. Msdu_tmp.firstBDPtr = pMsdu_1->firstBDPtr;
  931. Msdu_tmp.lastBDPtr = pMsdu_1->lastBDPtr;
  932. /* copy msdu 2 to msdu 1 */
  933. pMsdu_1->freeFunc = pMsdu_2->freeFunc;
  934. os_memoryCopy(pMemMngr->hOs, (void *)pMsdu_1->freeArgs, (void *)pMsdu_2->freeArgs,(NUM_OF_FREE_ARGS*sizeof(UINT32)));
  935. pMsdu_1->dataLen = pMsdu_2->dataLen;
  936. pMsdu_1->headerLen = pMsdu_2->headerLen;
  937. pMsdu_1->firstBDPtr = pMsdu_2->firstBDPtr;
  938. pMsdu_1->lastBDPtr = pMsdu_2->lastBDPtr;
  939. /* copy Temporary msdu to msdu 2 */
  940. pMsdu_2->freeFunc = Msdu_tmp.freeFunc;
  941. os_memoryCopy(pMemMngr->hOs, (void *)pMsdu_2->freeArgs, (void *)Msdu_tmp.freeArgs,(NUM_OF_FREE_ARGS*sizeof(UINT32)));
  942. pMsdu_2->dataLen = Msdu_tmp.dataLen;
  943. pMsdu_2->headerLen = Msdu_tmp.headerLen;
  944. pMsdu_2->firstBDPtr = Msdu_tmp.firstBDPtr;
  945. pMsdu_2->lastBDPtr = Msdu_tmp.lastBDPtr;
  946. os_protectUnlock(pMemMngr->hOs, pMemMngr->hCriticalSectionProtect);/* END OF CRITICAL SECTION */
  947. return OK;
  948. }
  949. TI_STATUS wlan_memMngrGetMemMgrResources(TI_HANDLE hMemMngr, memMgrResources_t* memMgrResources)
  950. {
  951. memMngr_t *pMemMngr = (memMngr_t *)hMemMngr;
  952. memMgrResources->numOfFreeBDs = pMemMngr->numFreeBD;
  953. memMgrResources->numOfFreeMsdu = pMemMngr->numFreeMSDU;
  954. memMgrResources->numOfFreeBufPool1 = pMemMngr->buffersPool[0].numFreeDataBuf;
  955. memMgrResources->numOfFreeBufPool2 = pMemMngr->buffersPool[1].numFreeDataBuf;
  956. memMgrResources->numOfFreeBufPool3 = pMemMngr->buffersPool[2].numFreeDataBuf;
  957. return OK;
  958. }
  959. TI_STATUS wlan_memMngrAddTimeStamp (TI_HANDLE hMemMngr, mem_MSDU_T *pMsdu)
  960. {
  961. #ifdef TI_DBG
  962. memMngr_t *pMemMngr = (memMngr_t *)hMemMngr;
  963. if (pMsdu->timeStampNum < MAX_NUM_OF_TIME_STAMPS)
  964. pMsdu->timeStamp[pMsdu->timeStampNum ++] =
  965. os_timeStampUs (pMemMngr->hOs);
  966. #endif
  967. return OK;
  968. }
  969. /*************************************************************************
  970. **************************************************************************
  971. * *
  972. * TEST FUNCTIONS *
  973. * *
  974. **************************************************************************
  975. **************************************************************************/
  976. void memMngrPrintMSDU(mem_MSDU_T* pMsdu )
  977. {
  978. WLAN_OS_REPORT(("\nPrinting MSDU :\n"));
  979. WLAN_OS_REPORT(("handle = %X\n",pMsdu->handle));
  980. WLAN_OS_REPORT(("nextFreeMSDU = %X\n",pMsdu->nextFreeMSDU));
  981. WLAN_OS_REPORT(("headerLen = %d\n",pMsdu->headerLen));
  982. WLAN_OS_REPORT(("firstBDPtr = %X\n",pMsdu->firstBDPtr));
  983. WLAN_OS_REPORT(("lastBDPtr = %X\n",pMsdu->lastBDPtr));
  984. WLAN_OS_REPORT(("freeFunc = %X\n",pMsdu->freeFunc));
  985. WLAN_OS_REPORT(("freeArgs[0] = %X\n",pMsdu->freeArgs[0]));
  986. WLAN_OS_REPORT(("freeArgs[1] = %X\n",pMsdu->freeArgs[1]));
  987. WLAN_OS_REPORT(("freeArgs[2] = %X\n",pMsdu->freeArgs[2]));
  988. WLAN_OS_REPORT(("freeArgs[3] = %X\n",pMsdu->freeArgs[3]));
  989. WLAN_OS_REPORT(("freeArgs[4] = %X\n",pMsdu->freeArgs[4]));
  990. WLAN_OS_REPORT(("dataLen = %d\n",pMsdu->dataLen));
  991. WLAN_OS_REPORT(("module = %d\n",pMsdu->module));
  992. WLAN_OS_REPORT(("nextMSDUinList = %X\n",pMsdu->nextMSDUinList));
  993. WLAN_OS_REPORT(("prevMSDUinList = %X\n",pMsdu->prevMSDUinList));
  994. WLAN_OS_REPORT(("txFlags = %X\n",pMsdu->txFlags));
  995. WLAN_OS_REPORT(("txCompleteFlags = %X\n",pMsdu->txCompleteFlags));
  996. }
  997. void memMngrPrintBD(mem_BD_T * pBd )
  998. {
  999. WLAN_OS_REPORT(("\nPrinting BD \n"));
  1000. WLAN_OS_REPORT(("handle = %X\n",pBd->handle));
  1001. WLAN_OS_REPORT(("refCount = %d\n",pBd->refCount));
  1002. WLAN_OS_REPORT(("dataBuf = %X\n",pBd->dataBuf));
  1003. WLAN_OS_REPORT(("data = %X\n",pBd->data));
  1004. WLAN_OS_REPORT(("dataOffset = %d\n",pBd->dataOffset));
  1005. WLAN_OS_REPORT(("length = %d\n",pBd->length));
  1006. WLAN_OS_REPORT(("nextBDPtr = %X\n",pBd->nextBDPtr));
  1007. #ifdef TNETW_MASTER_MODE
  1008. WLAN_OS_REPORT(("data_physical_low = %X\n",pBd->data_physical_low));
  1009. #endif
  1010. }
  1011. void memMngrPrintDataBuf(mem_DataBuf_T* pDataBuf )
  1012. {
  1013. WLAN_OS_REPORT(("\nPrinting DataBuf \n"));
  1014. WLAN_OS_REPORT(("handle = %X\n",pDataBuf->handle));
  1015. WLAN_OS_REPORT(("nextDataBuf = %X\n",pDataBuf->nextDataBuf));
  1016. WLAN_OS_REPORT(("refCount = %d\n",pDataBuf->refCount));
  1017. WLAN_OS_REPORT(("poolIndex = %X\n",pDataBuf->poolIndex));
  1018. WLAN_OS_REPORT(("data = %d\n",pDataBuf->data));
  1019. }
  1020. void memMngrPrintMSDUWithItsBds(mem_MSDU_T* pMsdu )
  1021. {
  1022. mem_BD_T *bdTmp = pMsdu->firstBDPtr;
  1023. memMngrPrintMSDU(pMsdu);
  1024. while(bdTmp != NULL)
  1025. {
  1026. memMngrPrintBD(bdTmp);
  1027. bdTmp = bdTmp->nextBDPtr;
  1028. }
  1029. }
  1030. void memMngrPrintHandle(TI_HANDLE hMemMngr, UINT32 handle)
  1031. {
  1032. mem_BD_T* tmpBD;
  1033. memMngr_t *pMemMngr = (memMngr_t *)hMemMngr;
  1034. WLAN_REPORT_INFORMATION(pMemMngr->hReport, MEM_MGR_MODULE_LOG,
  1035. ("MSDU handle = %d firstBDPtr=%X length=%d\n", handle,
  1036. pMemMngr->msduPool[handle].firstBDPtr,
  1037. pMemMngr->msduPool[handle].dataLen));
  1038. tmpBD = pMemMngr->msduPool[handle].firstBDPtr;
  1039. while (tmpBD != NULL) {
  1040. WLAN_REPORT_INFORMATION(pMemMngr->hReport, MEM_MGR_MODULE_LOG,
  1041. ("MSDU BD=%X handle=%d refCount=%d\n", tmpBD, tmpBD->handle, tmpBD->refCount));
  1042. tmpBD = tmpBD->nextBDPtr;
  1043. }
  1044. }
  1045. void memMngrFullPrint(TI_HANDLE hMemMngr)
  1046. {
  1047. mem_MSDU_T* tmpMSDU;
  1048. mem_BD_T* tmpBD;
  1049. mem_DataBuf_T* tmpDataBuf;
  1050. UINT32 j,i=0;
  1051. memMngr_t *pMemMngr = (memMngr_t *)hMemMngr;
  1052. WLAN_OS_REPORT(("memMngrPrint\n"));
  1053. WLAN_OS_REPORT(("numFreeMSDU %d numFreeBD %d \n", pMemMngr->numFreeMSDU, pMemMngr->numFreeBD));
  1054. for(j = 0 ;j < pMemMngr->currentNumberOfPools; j++)
  1055. WLAN_OS_REPORT(("Pool Num %d buffer length %d numFreeDataBuf %d \n",
  1056. j, pMemMngr->buffersPool[j].buffersSize, pMemMngr->buffersPool[j].numFreeDataBuf));
  1057. WLAN_OS_REPORT(("\nAllocated by modules : MLME=%d, OS_ABS=%d, RSN=%d, HAL_RX=%d\n",
  1058. pMemMngr->moduleAllocCount[MLME_MODULE],pMemMngr->moduleAllocCount[OS_ABS_TX_MODULE],
  1059. pMemMngr->moduleAllocCount[RSN_MODULE],pMemMngr->moduleAllocCount[HAL_RX_MODULE]));
  1060. WLAN_OS_REPORT(("\nfirstFreeMSDU=%X\n",pMemMngr->firstFreeMSDU));
  1061. tmpMSDU = pMemMngr->firstFreeMSDU;
  1062. while (++i, tmpMSDU != NULL) {
  1063. WLAN_OS_REPORT(("tmpMSDU %d = %X handle=%d tmpMSDU->nextMSDU=%X\n",
  1064. i, tmpMSDU, tmpMSDU->handle, tmpMSDU->nextFreeMSDU));
  1065. tmpMSDU = tmpMSDU->nextFreeMSDU;
  1066. }
  1067. WLAN_OS_REPORT(("\nfirstFreeBD=%X\n",pMemMngr->firstFreeBD));
  1068. i = 0;
  1069. tmpBD = pMemMngr->firstFreeBD;
  1070. while

Large files files are truncated, but you can click here to view the full file