⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ixosalbuffermgt.c

📁 有关ARM开发板上的IXP400网络驱动程序的源码以。
💻 C
📖 第 1 页 / 共 2 页
字号:
        sizeAligned = IX_OSAL_MBUF_POOL_SIZE_ALIGN (size);        /*         * clear the data memory area          */        memset (poolDataPtr, 0, sizeAligned * count);    }    else    {        sizeAligned = 0;    }    /*     * initialise pool fields      */    strcpy ((poolPtr)->name, name);    poolPtr->dataMemPtr = poolDataPtr;    poolPtr->mbufMemPtr = poolBufPtr;    poolPtr->bufDataSize = sizeAligned;    poolPtr->totalBufsInPool = count;    poolPtr->mbufMemSize = mbufSizeAligned * count;    poolPtr->dataMemSize = sizeAligned * count;    currentMbufPtr = (IX_OSAL_MBUF *) poolBufPtr;    poolPtr->nextFreeBuf = currentMbufPtr;    for (i = 0; i < count; i++)    {        if (i < (count - 1))        {            nextMbufPtr =                (IX_OSAL_MBUF *) ((unsigned) currentMbufPtr +                mbufSizeAligned);        }        else        {                       /* last mbuf in chain */            nextMbufPtr = NULL;        }        IX_OSAL_MBUF_NEXT_BUFFER_IN_PKT_PTR (currentMbufPtr) = nextMbufPtr;        IX_OSAL_MBUF_NET_POOL (currentMbufPtr) = poolPtr;        IX_OSAL_MBUF_SYS_SIGNATURE_INIT(currentMbufPtr);        if (poolDataPtr != NULL)        {            IX_OSAL_MBUF_MDATA (currentMbufPtr) = poolDataPtr;            IX_OSAL_MBUF_ALLOCATED_BUFF_DATA(currentMbufPtr) = (UINT32) poolDataPtr;            IX_OSAL_MBUF_MLEN (currentMbufPtr) = sizeAligned;            IX_OSAL_MBUF_ALLOCATED_BUFF_LEN(currentMbufPtr) = sizeAligned;            poolDataPtr = (void *) ((unsigned) poolDataPtr + sizeAligned);        }        currentMbufPtr = nextMbufPtr;    }    /*     * update the number of free buffers in the pool      */    poolPtr->freeBufsInPool = count;    poolPtr->poolAllocType = IX_OSAL_MBUF_POOL_TYPE_USER_ALLOC;    return poolPtr;}/*  * Get a mbuf ptr from the pool */PUBLIC IX_OSAL_MBUF *ixOsalMbufAlloc (IX_OSAL_MBUF_POOL * poolPtr){    int lock;    IX_OSAL_MBUF *newBufPtr = NULL;    /*     * check parameters      */    if (poolPtr == NULL)    {        ixOsalLog (IX_OSAL_LOG_LVL_ERROR,            IX_OSAL_LOG_DEV_STDOUT,            "ixOsalMbufAlloc(): "            "ERROR - Invalid Parameter\n", 0, 0, 0, 0, 0, 0);        return NULL;    }    lock = ixOsalIrqLock ();    newBufPtr = poolPtr->nextFreeBuf;    if (newBufPtr)    {        poolPtr->nextFreeBuf =            IX_OSAL_MBUF_NEXT_BUFFER_IN_PKT_PTR (newBufPtr);        IX_OSAL_MBUF_NEXT_BUFFER_IN_PKT_PTR (newBufPtr) = NULL;        /*         * update the number of free buffers in the pool          */        poolPtr->freeBufsInPool--;    }    else    {        /* Return NULL to indicate to caller that request is denied. */        ixOsalIrqUnlock (lock);        return NULL;    }#ifdef IX_OSAL_BUFFER_FREE_PROTECTION	/* Set Buffer Used Flag to indicate state.*/    IX_OSAL_MBUF_SET_USED_FLAG(newBufPtr);#endif    ixOsalIrqUnlock (lock);    return newBufPtr;}PUBLIC IX_OSAL_MBUF *ixOsalMbufFree (IX_OSAL_MBUF * bufPtr){    int lock;    IX_OSAL_MBUF_POOL *poolPtr;    IX_OSAL_MBUF *nextBufPtr = NULL;    /*     * check parameters      */    if (bufPtr == NULL)    {        ixOsalLog (IX_OSAL_LOG_LVL_ERROR,            IX_OSAL_LOG_DEV_STDOUT,            "ixOsalMbufFree(): "            "ERROR - Invalid Parameter\n", 0, 0, 0, 0, 0, 0);        return NULL;    }    lock = ixOsalIrqLock ();#ifdef IX_OSAL_BUFFER_FREE_PROTECTION		/* Prevention for Buffer freed more than once*/    if(!IX_OSAL_MBUF_ISSET_USED_FLAG(bufPtr))    {   	return NULL;    }    IX_OSAL_MBUF_CLEAR_USED_FLAG(bufPtr);#endif	    poolPtr = IX_OSAL_MBUF_NET_POOL (bufPtr);    /*     * check the mbuf wrapper signature (if mbuf wrapper was used)      */    if (poolPtr->poolAllocType == IX_OSAL_MBUF_POOL_TYPE_SYS_ALLOC)    {        IX_OSAL_ENSURE ( (IX_OSAL_MBUF_GET_SYS_SIGNATURE(bufPtr) == IX_OSAL_MBUF_SYS_SIGNATURE),            "ixOsalBuffPoolBufFree: ERROR - Invalid mbuf signature.");    }    nextBufPtr = IX_OSAL_MBUF_NEXT_BUFFER_IN_PKT_PTR (bufPtr);    IX_OSAL_MBUF_NEXT_BUFFER_IN_PKT_PTR (bufPtr) = poolPtr->nextFreeBuf;    poolPtr->nextFreeBuf = bufPtr;    /*     * update the number of free buffers in the pool      */    poolPtr->freeBufsInPool++;    ixOsalIrqUnlock (lock);    return nextBufPtr;}PUBLIC voidixOsalMbufChainFree (IX_OSAL_MBUF * bufPtr){    while ((bufPtr = ixOsalMbufFree (bufPtr)));}/* * Function definition: ixOsalBuffPoolShow */PUBLIC voidixOsalMbufPoolShow (IX_OSAL_MBUF_POOL * poolPtr){    IX_OSAL_MBUF *nextBufPtr;    int count = 0;    int lock;    /*     * check parameters      */    if (poolPtr == NULL)    {        ixOsalLog (IX_OSAL_LOG_LVL_ERROR,            IX_OSAL_LOG_DEV_STDOUT,            "ixOsalBuffPoolShow(): "            "ERROR - Invalid Parameter", 0, 0, 0, 0, 0, 0);        /*         * return IX_FAIL;          */        return;    }    lock = ixOsalIrqLock ();    count = poolPtr->freeBufsInPool;    nextBufPtr = poolPtr->nextFreeBuf;    ixOsalIrqUnlock (lock);    ixOsalLog (IX_OSAL_LOG_LVL_MESSAGE,        IX_OSAL_LOG_DEV_STDOUT, "=== POOL INFORMATION ===\n", 0, 0, 0,        0, 0, 0);    ixOsalLog (IX_OSAL_LOG_LVL_MESSAGE, IX_OSAL_LOG_DEV_STDOUT,        "Pool Name:                   %s\n",        (unsigned int) poolPtr->name, 0, 0, 0, 0, 0);    ixOsalLog (IX_OSAL_LOG_LVL_MESSAGE, IX_OSAL_LOG_DEV_STDOUT,        "Pool Allocation Type:        %d\n",        (unsigned int) poolPtr->poolAllocType, 0, 0, 0, 0, 0);    ixOsalLog (IX_OSAL_LOG_LVL_MESSAGE, IX_OSAL_LOG_DEV_STDOUT,        "Pool Mbuf Mem Usage (bytes): %d\n",        (unsigned int) poolPtr->mbufMemSize, 0, 0, 0, 0, 0);    ixOsalLog (IX_OSAL_LOG_LVL_MESSAGE, IX_OSAL_LOG_DEV_STDOUT,        "Pool Data Mem Usage (bytes): %d\n",        (unsigned int) poolPtr->dataMemSize, 0, 0, 0, 0, 0);    ixOsalLog (IX_OSAL_LOG_LVL_MESSAGE, IX_OSAL_LOG_DEV_STDOUT,        "Mbuf Data Capacity  (bytes): %d\n",        (unsigned int) poolPtr->bufDataSize, 0, 0, 0, 0, 0);    ixOsalLog (IX_OSAL_LOG_LVL_MESSAGE, IX_OSAL_LOG_DEV_STDOUT,        "Total Mbufs in Pool:         %d\n",        (unsigned int) poolPtr->totalBufsInPool, 0, 0, 0, 0, 0);    ixOsalLog (IX_OSAL_LOG_LVL_MESSAGE, IX_OSAL_LOG_DEV_STDOUT,        "Available Mbufs:             %d\n", (unsigned int) count, 0,        0, 0, 0, 0);    ixOsalLog (IX_OSAL_LOG_LVL_MESSAGE, IX_OSAL_LOG_DEV_STDOUT,        "Next Available Mbuf:         %p\n", (unsigned int) nextBufPtr,        0, 0, 0, 0, 0);    if (poolPtr->poolAllocType == IX_OSAL_MBUF_POOL_TYPE_USER_ALLOC)    {        ixOsalLog (IX_OSAL_LOG_LVL_MESSAGE,            IX_OSAL_LOG_DEV_STDOUT,            "Mbuf Mem Area Start address: %p\n",            (unsigned int) poolPtr->mbufMemPtr, 0, 0, 0, 0, 0);        ixOsalLog (IX_OSAL_LOG_LVL_MESSAGE, IX_OSAL_LOG_DEV_STDOUT,            "Data Mem Area Start address: %p\n",            (unsigned int) poolPtr->dataMemPtr, 0, 0, 0, 0, 0);    }}PUBLIC voidixOsalMbufDataPtrReset (IX_OSAL_MBUF * bufPtr){    IX_OSAL_MBUF_POOL *poolPtr;    UINT8 *poolDataPtr;    if (bufPtr == NULL)    {        ixOsalLog (IX_OSAL_LOG_LVL_ERROR, IX_OSAL_LOG_DEV_STDOUT,            "ixOsalBuffPoolBufDataPtrReset"            ": ERROR - Invalid Parameter\n", 0, 0, 0, 0, 0, 0);        return;    }    poolPtr = (IX_OSAL_MBUF_POOL *) IX_OSAL_MBUF_NET_POOL (bufPtr);    poolDataPtr = poolPtr->dataMemPtr;    if (poolPtr->poolAllocType == IX_OSAL_MBUF_POOL_TYPE_SYS_ALLOC)    {        if (IX_OSAL_MBUF_GET_SYS_SIGNATURE(bufPtr) != IX_OSAL_MBUF_SYS_SIGNATURE)        {            ixOsalLog (IX_OSAL_LOG_LVL_ERROR, IX_OSAL_LOG_DEV_STDOUT,                "ixOsalBuffPoolBufDataPtrReset"                ": invalid mbuf, cannot reset mData pointer\n", 0, 0,                0, 0, 0, 0);            return;        }        IX_OSAL_MBUF_MDATA (bufPtr) = (UINT8*)IX_OSAL_MBUF_ALLOCATED_BUFF_DATA (bufPtr);    }    else    {        if (poolDataPtr)        {            unsigned int bufSize = poolPtr->bufDataSize;            unsigned int bufDataAddr =                (unsigned int) IX_OSAL_MBUF_MDATA (bufPtr);            unsigned int poolDataAddr = (unsigned int) poolDataPtr;            /*             * the pointer is still pointing somewhere in the mbuf payload.             * This operation moves the pointer to the beginning of the              * mbuf payload             */            bufDataAddr = ((bufDataAddr - poolDataAddr) / bufSize) * bufSize;            IX_OSAL_MBUF_MDATA (bufPtr) = &poolDataPtr[bufDataAddr];        }        else        {            ixOsalLog (IX_OSAL_LOG_LVL_WARNING, IX_OSAL_LOG_DEV_STDOUT,                "ixOsalBuffPoolBufDataPtrReset"                ": cannot be used if user supplied NULL pointer for pool data area "                "when pool was created\n", 0, 0, 0, 0, 0, 0);            return;        }    }}/* * Function definition: ixOsalBuffPoolUninit */PUBLIC IX_STATUSixOsalBuffPoolUninit (IX_OSAL_MBUF_POOL * pool){    if (!pool)    {        ixOsalLog (IX_OSAL_LOG_LVL_ERROR, IX_OSAL_LOG_DEV_STDOUT,            "ixOsalBuffPoolUninit: NULL ptr \n", 0, 0, 0, 0, 0, 0);        return IX_FAIL;    }    if (pool->freeBufsInPool != pool->totalBufsInPool)    {        ixOsalLog (IX_OSAL_LOG_LVL_ERROR, IX_OSAL_LOG_DEV_STDOUT,            "ixOsalBuffPoolUninit: need to return all ptrs to the pool first! \n",            0, 0, 0, 0, 0, 0);        return IX_FAIL;    }    if (pool->poolAllocType == IX_OSAL_MBUF_POOL_TYPE_SYS_ALLOC)    {#ifdef IX_OSAL_BUFFER_ALLOC_SEPARATELY				UINT32 i;				IX_OSAL_MBUF* pBuf;								pBuf = pool->nextFreeBuf;				/* Freed the Buffer one by one till all the Memory is freed*/				for (i= pool->freeBufsInPool; i >0 && pBuf!=NULL ;i--){						IX_OSAL_MBUF* pBufTemp;						pBufTemp = IX_OSAL_MBUF_NEXT_BUFFER_IN_PKT_PTR(pBuf);						/* Freed MBUF Data Memory area*/						IX_OSAL_CACHE_DMA_FREE( (void *) (IX_OSAL_MBUF_ALLOCATED_BUFF_DATA(pBuf)) );						/* Freed MBUF Struct Memory area*/						IX_OSAL_CACHE_DMA_FREE(pBuf);						pBuf = pBufTemp;				}				#else    	        IX_OSAL_CACHE_DMA_FREE (pool->mbufMemPtr);        IX_OSAL_CACHE_DMA_FREE (pool->dataMemPtr);#endif            }    ixOsalBuffFreePools[pool->poolIdx / IX_OSAL_BUFF_FREE_BITS] &=        ~(1 << (pool->poolIdx % IX_OSAL_BUFF_FREE_BITS));    ixOsalBuffPoolsInUse--;    return IX_SUCCESS;}/* * Function definition: ixOsalBuffPoolDataAreaSizeGet */PUBLIC UINT32ixOsalBuffPoolDataAreaSizeGet (UINT32 count, UINT32 size){    UINT32 memorySize;    memorySize = count * IX_OSAL_MBUF_POOL_SIZE_ALIGN (size);    return memorySize;}/* * Function definition: ixOsalBuffPoolMbufAreaSizeGet */PUBLIC UINT32ixOsalBuffPoolMbufAreaSizeGet (UINT32 count){    UINT32 memorySize;    memorySize =        count * IX_OSAL_MBUF_POOL_SIZE_ALIGN (sizeof (IX_OSAL_MBUF));    return memorySize;}/* * Function definition: ixOsalBuffPoolFreeCountGet */PUBLIC UINT32 ixOsalBuffPoolFreeCountGet(IX_OSAL_MBUF_POOL * poolPtr){   return poolPtr->freeBufsInPool;}#endif /* IX_OSAL_USE_DEFAULT_BUFFER_MGT */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -