Esempio n. 1
0
PRIVATE IX_OSAL_MBUF *
ixOsalBuffPoolMbufInit (UINT32 mbufSizeAligned,
                      UINT32 dataSizeAligned,
                      IX_OSAL_MBUF_POOL *poolPtr)
{
    UINT8 *dataPtr;
    IX_OSAL_MBUF *realMbufPtr;
    /* Allocate cache-aligned memory for mbuf header */
    realMbufPtr = (IX_OSAL_MBUF *) IX_OSAL_CACHE_DMA_MALLOC (mbufSizeAligned);
    IX_OSAL_ASSERT (realMbufPtr != NULL);
    memset (realMbufPtr, 0, mbufSizeAligned);

    /* Allocate cache-aligned memory for mbuf data */
    dataPtr = (UINT8 *) IX_OSAL_CACHE_DMA_MALLOC (dataSizeAligned);
    IX_OSAL_ASSERT (dataPtr != NULL);
    memset (dataPtr, 0, dataSizeAligned);

    /* Fill in mbuf header fields */
    IX_OSAL_MBUF_MDATA (realMbufPtr) = dataPtr;
    IX_OSAL_MBUF_ALLOCATED_BUFF_DATA (realMbufPtr) = (UINT32)dataPtr;

    IX_OSAL_MBUF_MLEN (realMbufPtr) = dataSizeAligned;
    IX_OSAL_MBUF_ALLOCATED_BUFF_LEN (realMbufPtr) = dataSizeAligned;

    IX_OSAL_MBUF_NET_POOL (realMbufPtr) = (IX_OSAL_MBUF_POOL *) poolPtr;

    IX_OSAL_MBUF_SYS_SIGNATURE_INIT(realMbufPtr);

    /* update some statistical information */
    poolPtr->mbufMemSize += mbufSizeAligned;
    poolPtr->dataMemSize += dataSizeAligned;

    return realMbufPtr;
}
Esempio n. 2
0
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))
    {
	ixOsalIrqUnlock (lock);
   	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;
}
Esempio n. 3
0
PUBLIC void
ixOsalMbufDataPtrReset (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;
        }
    }

}
Esempio n. 4
0
PUBLIC IX_OSAL_MBUF_POOL *
ixOsalNoAllocPoolInit (void *poolBufPtr,
    void *poolDataPtr, UINT32 count, UINT32 size, const char *name)
{
    UINT32 i,  mbufSizeAligned, sizeAligned;
    IX_OSAL_MBUF *currentMbufPtr = NULL;
    IX_OSAL_MBUF *nextMbufPtr = NULL;
    IX_OSAL_MBUF_POOL *poolPtr = NULL;

    /*
     * check parameters 
     */
    if (poolBufPtr == NULL)
    {
        ixOsalLog (IX_OSAL_LOG_LVL_ERROR,
            IX_OSAL_LOG_DEV_STDOUT,
            "ixOsalNoAllocPoolInit(): "
            "ERROR - NULL poolBufPtr \n", 0, 0, 0, 0, 0, 0);
        return NULL;
    }

    if (count <= 0)
    {
        ixOsalLog (IX_OSAL_LOG_LVL_ERROR,
            IX_OSAL_LOG_DEV_STDOUT,
            "ixOsalNoAllocPoolInit(): "
            "ERROR - count must > 0   \n", 0, 0, 0, 0, 0, 0);
        return NULL;
    }

    if (name == NULL)
    {
        ixOsalLog (IX_OSAL_LOG_LVL_ERROR,
            IX_OSAL_LOG_DEV_STDOUT,
            "ixOsalNoAllocPoolInit(): "
            "ERROR - NULL name ptr  \n", 0, 0, 0, 0, 0, 0);
        return NULL;
    }

    if (strlen (name) > IX_OSAL_MBUF_POOL_NAME_LEN)
    {
        ixOsalLog (IX_OSAL_LOG_LVL_ERROR,
            IX_OSAL_LOG_DEV_STDOUT,
            "ixOsalNoAllocPoolInit(): "
            "ERROR - name length should be no greater than %d  \n",
            IX_OSAL_MBUF_POOL_NAME_LEN, 0, 0, 0, 0, 0);
        return NULL;
    }

    poolPtr = ixOsalPoolAlloc ();

    if (poolPtr == NULL)
    {
        return NULL;
    }

    /*
     * Adjust sizes to ensure alignment on cache line boundaries 
     */
    mbufSizeAligned =
        IX_OSAL_MBUF_POOL_SIZE_ALIGN (sizeof (IX_OSAL_MBUF));
    /*
     * clear the mbuf memory area 
     */
    memset (poolBufPtr, 0, mbufSizeAligned * count);

    if (poolDataPtr != NULL)
    {
        /*
         * Adjust sizes to ensure alignment on cache line boundaries 
         */
        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;
}