Exemplo n.º 1
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;
}
Exemplo n.º 2
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;
        }
    }

}