2 * @file IxOsalBufferMgt.c
4 * @brief Default buffer pool management and buffer management
10 * IXP400 SW Release version 2.0
12 * -- Copyright Notice --
15 * Copyright 2001-2005, Intel Corporation.
16 * All rights reserved.
19 * SPDX-License-Identifier: BSD-3-Clause
21 * -- End of Copyright Notice --
25 * OS may choose to use default bufferMgt by defining
26 * IX_OSAL_USE_DEFAULT_BUFFER_MGT in IxOsalOsBufferMgt.h
31 #define IX_OSAL_BUFFER_FREE_PROTECTION /* Define this to enable Illegal MBuf Freed Protection*/
34 * The implementation is only used when the following
37 #ifdef IX_OSAL_USE_DEFAULT_BUFFER_MGT
40 #define IX_OSAL_MBUF_SYS_SIGNATURE (0x8BADF00D)
41 #define IX_OSAL_MBUF_SYS_SIGNATURE_MASK (0xEFFFFFFF)
42 #define IX_OSAL_MBUF_USED_FLAG (0x10000000)
43 #define IX_OSAL_MBUF_SYS_SIGNATURE_INIT(bufPtr) IX_OSAL_MBUF_SIGNATURE (bufPtr) = (UINT32)IX_OSAL_MBUF_SYS_SIGNATURE
46 * This implementation is protect, the buffer pool management's ixOsalMBufFree
47 * against an invalid MBUF pointer argument that already has been freed earlier
48 * or in other words resides in the free pool of MBUFs. This added feature,
49 * checks the MBUF "USED" FLAG. The Flag tells if the MBUF is still not freed
50 * back to the Buffer Pool.
51 * Disable this feature for performance reasons by undef
52 * IX_OSAL_BUFFER_FREE_PROTECTION macro.
54 #ifdef IX_OSAL_BUFFER_FREE_PROTECTION /*IX_OSAL_BUFFER_FREE_PROTECTION With Buffer Free protection*/
56 #define IX_OSAL_MBUF_GET_SYS_SIGNATURE(bufPtr) (IX_OSAL_MBUF_SIGNATURE (bufPtr)&(IX_OSAL_MBUF_SYS_SIGNATURE_MASK) )
57 #define IX_OSAL_MBUF_SET_SYS_SIGNATURE(bufPtr) do { \
58 IX_OSAL_MBUF_SIGNATURE (bufPtr)&(~IX_OSAL_MBUF_SYS_SIGNATURE_MASK);\
59 IX_OSAL_MBUF_SIGNATURE (bufPtr)|=IX_OSAL_MBUF_SYS_SIGNATURE; \
62 #define IX_OSAL_MBUF_SET_USED_FLAG(bufPtr) IX_OSAL_MBUF_SIGNATURE (bufPtr)|=IX_OSAL_MBUF_USED_FLAG
63 #define IX_OSAL_MBUF_CLEAR_USED_FLAG(bufPtr) IX_OSAL_MBUF_SIGNATURE (bufPtr)&=~IX_OSAL_MBUF_USED_FLAG
64 #define IX_OSAL_MBUF_ISSET_USED_FLAG(bufPtr) (IX_OSAL_MBUF_SIGNATURE (bufPtr)&IX_OSAL_MBUF_USED_FLAG)
68 #define IX_OSAL_MBUF_GET_SYS_SIGNATURE(bufPtr) IX_OSAL_MBUF_SIGNATURE (bufPtr)
69 #define IX_OSAL_MBUF_SET_SYS_SIGNATURE(bufPtr) IX_OSAL_MBUF_SIGNATURE (bufPtr) = IX_OSAL_MBUF_SYS_SIGNATURE
71 #endif /*IX_OSAL_BUFFER_FREE_PROTECTION With Buffer Free protection*/
73 * Variable declarations global to this file only. Externs are followed by
78 * A unit of 32, used to provide bit-shift for pool
79 * management. Needs some work if users want more than 32 pools.
81 #define IX_OSAL_BUFF_FREE_BITS 32
83 PRIVATE UINT32 ixOsalBuffFreePools[IX_OSAL_MBUF_MAX_POOLS /
84 IX_OSAL_BUFF_FREE_BITS];
86 PUBLIC IX_OSAL_MBUF_POOL ixOsalBuffPools[IX_OSAL_MBUF_MAX_POOLS];
88 static int ixOsalBuffPoolsInUse = 0;
90 #ifdef IX_OSAL_BUFFER_ALLOC_SEPARATELY
91 PRIVATE IX_OSAL_MBUF *
92 ixOsalBuffPoolMbufInit (UINT32 mbufSizeAligned,
93 UINT32 dataSizeAligned,
94 IX_OSAL_MBUF_POOL *poolPtr);
97 PRIVATE IX_OSAL_MBUF_POOL * ixOsalPoolAlloc (void);
100 * Function definition: ixOsalPoolAlloc
103 /****************************/
105 PRIVATE IX_OSAL_MBUF_POOL *
106 ixOsalPoolAlloc (void)
108 register unsigned int i = 0;
111 * Scan for the first free buffer. Free buffers are indicated by 0
112 * on the corrsponding bit in ixOsalBuffFreePools.
114 if (ixOsalBuffPoolsInUse >= IX_OSAL_MBUF_MAX_POOLS)
117 * Fail to grab a ptr this time
122 while (ixOsalBuffFreePools[i / IX_OSAL_BUFF_FREE_BITS] &
123 (1 << (i % IX_OSAL_BUFF_FREE_BITS)))
126 * Free buffer found. Mark it as busy and initialize.
128 ixOsalBuffFreePools[i / IX_OSAL_BUFF_FREE_BITS] |=
129 (1 << (i % IX_OSAL_BUFF_FREE_BITS));
131 memset (&ixOsalBuffPools[i], 0, sizeof (IX_OSAL_MBUF_POOL));
133 ixOsalBuffPools[i].poolIdx = i;
134 ixOsalBuffPoolsInUse++;
136 return &ixOsalBuffPools[i];
140 #ifdef IX_OSAL_BUFFER_ALLOC_SEPARATELY
141 PRIVATE IX_OSAL_MBUF *
142 ixOsalBuffPoolMbufInit (UINT32 mbufSizeAligned,
143 UINT32 dataSizeAligned,
144 IX_OSAL_MBUF_POOL *poolPtr)
147 IX_OSAL_MBUF *realMbufPtr;
148 /* Allocate cache-aligned memory for mbuf header */
149 realMbufPtr = (IX_OSAL_MBUF *) IX_OSAL_CACHE_DMA_MALLOC (mbufSizeAligned);
150 IX_OSAL_ASSERT (realMbufPtr != NULL);
151 memset (realMbufPtr, 0, mbufSizeAligned);
153 /* Allocate cache-aligned memory for mbuf data */
154 dataPtr = (UINT8 *) IX_OSAL_CACHE_DMA_MALLOC (dataSizeAligned);
155 IX_OSAL_ASSERT (dataPtr != NULL);
156 memset (dataPtr, 0, dataSizeAligned);
158 /* Fill in mbuf header fields */
159 IX_OSAL_MBUF_MDATA (realMbufPtr) = dataPtr;
160 IX_OSAL_MBUF_ALLOCATED_BUFF_DATA (realMbufPtr) = (UINT32)dataPtr;
162 IX_OSAL_MBUF_MLEN (realMbufPtr) = dataSizeAligned;
163 IX_OSAL_MBUF_ALLOCATED_BUFF_LEN (realMbufPtr) = dataSizeAligned;
165 IX_OSAL_MBUF_NET_POOL (realMbufPtr) = (IX_OSAL_MBUF_POOL *) poolPtr;
167 IX_OSAL_MBUF_SYS_SIGNATURE_INIT(realMbufPtr);
169 /* update some statistical information */
170 poolPtr->mbufMemSize += mbufSizeAligned;
171 poolPtr->dataMemSize += dataSizeAligned;
175 #endif /* #ifdef IX_OSAL_BUFFER_ALLOC_SEPARATELY */
178 * Function definition: ixOsalBuffPoolInit
181 PUBLIC IX_OSAL_MBUF_POOL *
182 ixOsalPoolInit (UINT32 count, UINT32 size, const char *name)
185 /* These variables are only used if UX_OSAL_BUFFER_ALLOC_SEPERATELY
188 #ifdef IX_OSAL_BUFFER_ALLOC_SEPARATELY
189 UINT32 i, mbufSizeAligned, dataSizeAligned;
190 IX_OSAL_MBUF *currentMbufPtr = NULL;
198 IX_OSAL_MBUF_POOL *poolPtr = NULL;
202 ixOsalLog (IX_OSAL_LOG_LVL_ERROR,
203 IX_OSAL_LOG_DEV_STDOUT,
204 "ixOsalPoolInit(): " "count = 0 \n", 0, 0, 0, 0, 0, 0);
210 ixOsalLog (IX_OSAL_LOG_LVL_ERROR,
211 IX_OSAL_LOG_DEV_STDOUT,
212 "ixOsalPoolInit(): " "NULL name \n", 0, 0, 0, 0, 0, 0);
216 if (strlen (name) > IX_OSAL_MBUF_POOL_NAME_LEN)
218 ixOsalLog (IX_OSAL_LOG_LVL_ERROR,
219 IX_OSAL_LOG_DEV_STDOUT,
221 "ERROR - name length should be no greater than %d \n",
222 IX_OSAL_MBUF_POOL_NAME_LEN, 0, 0, 0, 0, 0);
226 /* OS can choose whether to allocate all buffers all together (if it
227 * can handle a huge single alloc request), or to allocate buffers
228 * separately by the defining IX_OSAL_BUFFER_ALLOC_SEPARATELY.
230 #ifdef IX_OSAL_BUFFER_ALLOC_SEPARATELY
232 poolPtr = ixOsalPoolAlloc ();
236 ixOsalLog (IX_OSAL_LOG_LVL_ERROR,
237 IX_OSAL_LOG_DEV_STDOUT,
238 "ixOsalPoolInit(): " "Fail to Get PoolPtr \n", 0, 0, 0, 0, 0, 0);
242 mbufSizeAligned = IX_OSAL_MBUF_POOL_SIZE_ALIGN (sizeof (IX_OSAL_MBUF));
243 dataSizeAligned = IX_OSAL_MBUF_POOL_SIZE_ALIGN(size);
245 poolPtr->nextFreeBuf = NULL;
246 poolPtr->mbufMemPtr = NULL;
247 poolPtr->dataMemPtr = NULL;
248 poolPtr->bufDataSize = dataSizeAligned;
249 poolPtr->totalBufsInPool = count;
250 poolPtr->poolAllocType = IX_OSAL_MBUF_POOL_TYPE_SYS_ALLOC;
251 strcpy (poolPtr->name, name);
254 for (i = 0; i < count; i++)
257 currentMbufPtr = ixOsalBuffPoolMbufInit (mbufSizeAligned,
261 #ifdef IX_OSAL_BUFFER_FREE_PROTECTION
262 /* Set the Buffer USED Flag. If not, ixOsalMBufFree will fail.
263 ixOsalMbufFree used here is in a special case whereby, it's
264 used to add MBUF to the Pool. By specification, ixOsalMbufFree
265 deallocates an allocated MBUF from Pool.
267 IX_OSAL_MBUF_SET_USED_FLAG(currentMbufPtr);
269 /* Add it to the pool */
270 ixOsalMbufFree (currentMbufPtr);
272 /* flush the pool information to RAM */
273 IX_OSAL_CACHE_FLUSH (currentMbufPtr, mbufSizeAligned);
277 * update the number of free buffers in the pool
279 poolPtr->freeBufsInPool = count;
282 /* Otherwise allocate buffers in a continuous block fashion */
283 poolBufPtr = IX_OSAL_MBUF_POOL_MBUF_AREA_ALLOC (count, mbufMemSize);
284 IX_OSAL_ASSERT (poolBufPtr != NULL);
286 IX_OSAL_MBUF_POOL_DATA_AREA_ALLOC (count, size, dataMemSize);
287 IX_OSAL_ASSERT (poolDataPtr != NULL);
289 poolPtr = ixOsalNoAllocPoolInit (poolBufPtr, poolDataPtr,
293 ixOsalLog (IX_OSAL_LOG_LVL_ERROR,
294 IX_OSAL_LOG_DEV_STDOUT,
295 "ixOsalPoolInit(): " "Fail to get pool ptr \n", 0, 0, 0, 0, 0, 0);
299 poolPtr->poolAllocType = IX_OSAL_MBUF_POOL_TYPE_SYS_ALLOC;
301 #endif /* IX_OSAL_BUFFER_ALLOC_SEPARATELY */
305 PUBLIC IX_OSAL_MBUF_POOL *
306 ixOsalNoAllocPoolInit (void *poolBufPtr,
307 void *poolDataPtr, UINT32 count, UINT32 size, const char *name)
309 UINT32 i, mbufSizeAligned, sizeAligned;
310 IX_OSAL_MBUF *currentMbufPtr = NULL;
311 IX_OSAL_MBUF *nextMbufPtr = NULL;
312 IX_OSAL_MBUF_POOL *poolPtr = NULL;
317 if (poolBufPtr == NULL)
319 ixOsalLog (IX_OSAL_LOG_LVL_ERROR,
320 IX_OSAL_LOG_DEV_STDOUT,
321 "ixOsalNoAllocPoolInit(): "
322 "ERROR - NULL poolBufPtr \n", 0, 0, 0, 0, 0, 0);
328 ixOsalLog (IX_OSAL_LOG_LVL_ERROR,
329 IX_OSAL_LOG_DEV_STDOUT,
330 "ixOsalNoAllocPoolInit(): "
331 "ERROR - count must > 0 \n", 0, 0, 0, 0, 0, 0);
337 ixOsalLog (IX_OSAL_LOG_LVL_ERROR,
338 IX_OSAL_LOG_DEV_STDOUT,
339 "ixOsalNoAllocPoolInit(): "
340 "ERROR - NULL name ptr \n", 0, 0, 0, 0, 0, 0);
344 if (strlen (name) > IX_OSAL_MBUF_POOL_NAME_LEN)
346 ixOsalLog (IX_OSAL_LOG_LVL_ERROR,
347 IX_OSAL_LOG_DEV_STDOUT,
348 "ixOsalNoAllocPoolInit(): "
349 "ERROR - name length should be no greater than %d \n",
350 IX_OSAL_MBUF_POOL_NAME_LEN, 0, 0, 0, 0, 0);
354 poolPtr = ixOsalPoolAlloc ();
362 * Adjust sizes to ensure alignment on cache line boundaries
365 IX_OSAL_MBUF_POOL_SIZE_ALIGN (sizeof (IX_OSAL_MBUF));
367 * clear the mbuf memory area
369 memset (poolBufPtr, 0, mbufSizeAligned * count);
371 if (poolDataPtr != NULL)
374 * Adjust sizes to ensure alignment on cache line boundaries
376 sizeAligned = IX_OSAL_MBUF_POOL_SIZE_ALIGN (size);
378 * clear the data memory area
380 memset (poolDataPtr, 0, sizeAligned * count);
388 * initialise pool fields
390 strcpy ((poolPtr)->name, name);
392 poolPtr->dataMemPtr = poolDataPtr;
393 poolPtr->mbufMemPtr = poolBufPtr;
394 poolPtr->bufDataSize = sizeAligned;
395 poolPtr->totalBufsInPool = count;
396 poolPtr->mbufMemSize = mbufSizeAligned * count;
397 poolPtr->dataMemSize = sizeAligned * count;
399 currentMbufPtr = (IX_OSAL_MBUF *) poolBufPtr;
401 poolPtr->nextFreeBuf = currentMbufPtr;
403 for (i = 0; i < count; i++)
408 (IX_OSAL_MBUF *) ((unsigned) currentMbufPtr +
412 { /* last mbuf in chain */
415 IX_OSAL_MBUF_NEXT_BUFFER_IN_PKT_PTR (currentMbufPtr) = nextMbufPtr;
416 IX_OSAL_MBUF_NET_POOL (currentMbufPtr) = poolPtr;
418 IX_OSAL_MBUF_SYS_SIGNATURE_INIT(currentMbufPtr);
420 if (poolDataPtr != NULL)
422 IX_OSAL_MBUF_MDATA (currentMbufPtr) = poolDataPtr;
423 IX_OSAL_MBUF_ALLOCATED_BUFF_DATA(currentMbufPtr) = (UINT32) poolDataPtr;
425 IX_OSAL_MBUF_MLEN (currentMbufPtr) = sizeAligned;
426 IX_OSAL_MBUF_ALLOCATED_BUFF_LEN(currentMbufPtr) = sizeAligned;
428 poolDataPtr = (void *) ((unsigned) poolDataPtr + sizeAligned);
431 currentMbufPtr = nextMbufPtr;
435 * update the number of free buffers in the pool
437 poolPtr->freeBufsInPool = count;
439 poolPtr->poolAllocType = IX_OSAL_MBUF_POOL_TYPE_USER_ALLOC;
445 * Get a mbuf ptr from the pool
447 PUBLIC IX_OSAL_MBUF *
448 ixOsalMbufAlloc (IX_OSAL_MBUF_POOL * poolPtr)
451 IX_OSAL_MBUF *newBufPtr = NULL;
458 ixOsalLog (IX_OSAL_LOG_LVL_ERROR,
459 IX_OSAL_LOG_DEV_STDOUT,
460 "ixOsalMbufAlloc(): "
461 "ERROR - Invalid Parameter\n", 0, 0, 0, 0, 0, 0);
465 lock = ixOsalIrqLock ();
467 newBufPtr = poolPtr->nextFreeBuf;
470 poolPtr->nextFreeBuf =
471 IX_OSAL_MBUF_NEXT_BUFFER_IN_PKT_PTR (newBufPtr);
472 IX_OSAL_MBUF_NEXT_BUFFER_IN_PKT_PTR (newBufPtr) = NULL;
475 * update the number of free buffers in the pool
477 poolPtr->freeBufsInPool--;
481 /* Return NULL to indicate to caller that request is denied. */
482 ixOsalIrqUnlock (lock);
487 #ifdef IX_OSAL_BUFFER_FREE_PROTECTION
488 /* Set Buffer Used Flag to indicate state.*/
489 IX_OSAL_MBUF_SET_USED_FLAG(newBufPtr);
492 ixOsalIrqUnlock (lock);
497 PUBLIC IX_OSAL_MBUF *
498 ixOsalMbufFree (IX_OSAL_MBUF * bufPtr)
501 IX_OSAL_MBUF_POOL *poolPtr;
503 IX_OSAL_MBUF *nextBufPtr = NULL;
510 ixOsalLog (IX_OSAL_LOG_LVL_ERROR,
511 IX_OSAL_LOG_DEV_STDOUT,
513 "ERROR - Invalid Parameter\n", 0, 0, 0, 0, 0, 0);
519 lock = ixOsalIrqLock ();
521 #ifdef IX_OSAL_BUFFER_FREE_PROTECTION
523 /* Prevention for Buffer freed more than once*/
524 if(!IX_OSAL_MBUF_ISSET_USED_FLAG(bufPtr))
528 IX_OSAL_MBUF_CLEAR_USED_FLAG(bufPtr);
531 poolPtr = IX_OSAL_MBUF_NET_POOL (bufPtr);
534 * check the mbuf wrapper signature (if mbuf wrapper was used)
536 if (poolPtr->poolAllocType == IX_OSAL_MBUF_POOL_TYPE_SYS_ALLOC)
538 IX_OSAL_ENSURE ( (IX_OSAL_MBUF_GET_SYS_SIGNATURE(bufPtr) == IX_OSAL_MBUF_SYS_SIGNATURE),
539 "ixOsalBuffPoolBufFree: ERROR - Invalid mbuf signature.");
542 nextBufPtr = IX_OSAL_MBUF_NEXT_BUFFER_IN_PKT_PTR (bufPtr);
544 IX_OSAL_MBUF_NEXT_BUFFER_IN_PKT_PTR (bufPtr) = poolPtr->nextFreeBuf;
545 poolPtr->nextFreeBuf = bufPtr;
548 * update the number of free buffers in the pool
550 poolPtr->freeBufsInPool++;
552 ixOsalIrqUnlock (lock);
558 ixOsalMbufChainFree (IX_OSAL_MBUF * bufPtr)
560 while ((bufPtr = ixOsalMbufFree (bufPtr)));
564 * Function definition: ixOsalBuffPoolShow
567 ixOsalMbufPoolShow (IX_OSAL_MBUF_POOL * poolPtr)
569 IX_OSAL_MBUF *nextBufPtr;
578 ixOsalLog (IX_OSAL_LOG_LVL_ERROR,
579 IX_OSAL_LOG_DEV_STDOUT,
580 "ixOsalBuffPoolShow(): "
581 "ERROR - Invalid Parameter", 0, 0, 0, 0, 0, 0);
588 lock = ixOsalIrqLock ();
589 count = poolPtr->freeBufsInPool;
590 nextBufPtr = poolPtr->nextFreeBuf;
591 ixOsalIrqUnlock (lock);
593 ixOsalLog (IX_OSAL_LOG_LVL_MESSAGE,
594 IX_OSAL_LOG_DEV_STDOUT, "=== POOL INFORMATION ===\n", 0, 0, 0,
596 ixOsalLog (IX_OSAL_LOG_LVL_MESSAGE, IX_OSAL_LOG_DEV_STDOUT,
598 (unsigned int) poolPtr->name, 0, 0, 0, 0, 0);
599 ixOsalLog (IX_OSAL_LOG_LVL_MESSAGE, IX_OSAL_LOG_DEV_STDOUT,
600 "Pool Allocation Type: %d\n",
601 (unsigned int) poolPtr->poolAllocType, 0, 0, 0, 0, 0);
602 ixOsalLog (IX_OSAL_LOG_LVL_MESSAGE, IX_OSAL_LOG_DEV_STDOUT,
603 "Pool Mbuf Mem Usage (bytes): %d\n",
604 (unsigned int) poolPtr->mbufMemSize, 0, 0, 0, 0, 0);
605 ixOsalLog (IX_OSAL_LOG_LVL_MESSAGE, IX_OSAL_LOG_DEV_STDOUT,
606 "Pool Data Mem Usage (bytes): %d\n",
607 (unsigned int) poolPtr->dataMemSize, 0, 0, 0, 0, 0);
608 ixOsalLog (IX_OSAL_LOG_LVL_MESSAGE, IX_OSAL_LOG_DEV_STDOUT,
609 "Mbuf Data Capacity (bytes): %d\n",
610 (unsigned int) poolPtr->bufDataSize, 0, 0, 0, 0, 0);
611 ixOsalLog (IX_OSAL_LOG_LVL_MESSAGE, IX_OSAL_LOG_DEV_STDOUT,
612 "Total Mbufs in Pool: %d\n",
613 (unsigned int) poolPtr->totalBufsInPool, 0, 0, 0, 0, 0);
614 ixOsalLog (IX_OSAL_LOG_LVL_MESSAGE, IX_OSAL_LOG_DEV_STDOUT,
615 "Available Mbufs: %d\n", (unsigned int) count, 0,
617 ixOsalLog (IX_OSAL_LOG_LVL_MESSAGE, IX_OSAL_LOG_DEV_STDOUT,
618 "Next Available Mbuf: %p\n", (unsigned int) nextBufPtr,
621 if (poolPtr->poolAllocType == IX_OSAL_MBUF_POOL_TYPE_USER_ALLOC)
623 ixOsalLog (IX_OSAL_LOG_LVL_MESSAGE,
624 IX_OSAL_LOG_DEV_STDOUT,
625 "Mbuf Mem Area Start address: %p\n",
626 (unsigned int) poolPtr->mbufMemPtr, 0, 0, 0, 0, 0);
627 ixOsalLog (IX_OSAL_LOG_LVL_MESSAGE, IX_OSAL_LOG_DEV_STDOUT,
628 "Data Mem Area Start address: %p\n",
629 (unsigned int) poolPtr->dataMemPtr, 0, 0, 0, 0, 0);
634 ixOsalMbufDataPtrReset (IX_OSAL_MBUF * bufPtr)
636 IX_OSAL_MBUF_POOL *poolPtr;
641 ixOsalLog (IX_OSAL_LOG_LVL_ERROR, IX_OSAL_LOG_DEV_STDOUT,
642 "ixOsalBuffPoolBufDataPtrReset"
643 ": ERROR - Invalid Parameter\n", 0, 0, 0, 0, 0, 0);
647 poolPtr = (IX_OSAL_MBUF_POOL *) IX_OSAL_MBUF_NET_POOL (bufPtr);
648 poolDataPtr = poolPtr->dataMemPtr;
650 if (poolPtr->poolAllocType == IX_OSAL_MBUF_POOL_TYPE_SYS_ALLOC)
652 if (IX_OSAL_MBUF_GET_SYS_SIGNATURE(bufPtr) != IX_OSAL_MBUF_SYS_SIGNATURE)
654 ixOsalLog (IX_OSAL_LOG_LVL_ERROR, IX_OSAL_LOG_DEV_STDOUT,
655 "ixOsalBuffPoolBufDataPtrReset"
656 ": invalid mbuf, cannot reset mData pointer\n", 0, 0,
660 IX_OSAL_MBUF_MDATA (bufPtr) = (UINT8*)IX_OSAL_MBUF_ALLOCATED_BUFF_DATA (bufPtr);
666 unsigned int bufSize = poolPtr->bufDataSize;
667 unsigned int bufDataAddr =
668 (unsigned int) IX_OSAL_MBUF_MDATA (bufPtr);
669 unsigned int poolDataAddr = (unsigned int) poolDataPtr;
672 * the pointer is still pointing somewhere in the mbuf payload.
673 * This operation moves the pointer to the beginning of the
676 bufDataAddr = ((bufDataAddr - poolDataAddr) / bufSize) * bufSize;
677 IX_OSAL_MBUF_MDATA (bufPtr) = &poolDataPtr[bufDataAddr];
681 ixOsalLog (IX_OSAL_LOG_LVL_WARNING, IX_OSAL_LOG_DEV_STDOUT,
682 "ixOsalBuffPoolBufDataPtrReset"
683 ": cannot be used if user supplied NULL pointer for pool data area "
684 "when pool was created\n", 0, 0, 0, 0, 0, 0);
692 * Function definition: ixOsalBuffPoolUninit
695 ixOsalBuffPoolUninit (IX_OSAL_MBUF_POOL * pool)
699 ixOsalLog (IX_OSAL_LOG_LVL_ERROR, IX_OSAL_LOG_DEV_STDOUT,
700 "ixOsalBuffPoolUninit: NULL ptr \n", 0, 0, 0, 0, 0, 0);
704 if (pool->freeBufsInPool != pool->totalBufsInPool)
706 ixOsalLog (IX_OSAL_LOG_LVL_ERROR, IX_OSAL_LOG_DEV_STDOUT,
707 "ixOsalBuffPoolUninit: need to return all ptrs to the pool first! \n",
712 if (pool->poolAllocType == IX_OSAL_MBUF_POOL_TYPE_SYS_ALLOC)
714 #ifdef IX_OSAL_BUFFER_ALLOC_SEPARATELY
718 pBuf = pool->nextFreeBuf;
719 /* Freed the Buffer one by one till all the Memory is freed*/
720 for (i= pool->freeBufsInPool; i >0 && pBuf!=NULL ;i--){
721 IX_OSAL_MBUF* pBufTemp;
722 pBufTemp = IX_OSAL_MBUF_NEXT_BUFFER_IN_PKT_PTR(pBuf);
723 /* Freed MBUF Data Memory area*/
724 IX_OSAL_CACHE_DMA_FREE( (void *) (IX_OSAL_MBUF_ALLOCATED_BUFF_DATA(pBuf)) );
725 /* Freed MBUF Struct Memory area*/
726 IX_OSAL_CACHE_DMA_FREE(pBuf);
731 IX_OSAL_CACHE_DMA_FREE (pool->mbufMemPtr);
732 IX_OSAL_CACHE_DMA_FREE (pool->dataMemPtr);
736 ixOsalBuffFreePools[pool->poolIdx / IX_OSAL_BUFF_FREE_BITS] &=
737 ~(1 << (pool->poolIdx % IX_OSAL_BUFF_FREE_BITS));
738 ixOsalBuffPoolsInUse--;
743 * Function definition: ixOsalBuffPoolDataAreaSizeGet
746 ixOsalBuffPoolDataAreaSizeGet (int count, int size)
749 memorySize = count * IX_OSAL_MBUF_POOL_SIZE_ALIGN (size);
754 * Function definition: ixOsalBuffPoolMbufAreaSizeGet
757 ixOsalBuffPoolMbufAreaSizeGet (int count)
761 count * IX_OSAL_MBUF_POOL_SIZE_ALIGN (sizeof (IX_OSAL_MBUF));
766 * Function definition: ixOsalBuffPoolFreeCountGet
768 PUBLIC UINT32 ixOsalBuffPoolFreeCountGet(IX_OSAL_MBUF_POOL * poolPtr)
772 return poolPtr->freeBufsInPool;
776 #endif /* IX_OSAL_USE_DEFAULT_BUFFER_MGT */