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

📄 ixoamcodelet.c

📁 有关ARM开发板上的IXP400网络驱动程序的源码以。
💻 C
📖 第 1 页 / 共 3 页
字号:
    /* Get a Tx mbuf */    ixAtmUtilsMbufGet(IX_ATM_OAM_CELL_SIZE_NO_HEC, &txMbuf);    if (txMbuf != NULL)    {			/* set the packet header len */	IX_OSAL_MBUF_PKT_LEN(txMbuf) = IX_OSAL_MBUF_MLEN(txMbuf);	txCell = (IxOamITU610Cell *)(IX_OSAL_MBUF_MDATA(txMbuf));	/* Setup shortcut pointers */	lbPayload = &(txCell->payload.lbPayload);		/* Set the OAM function type to LB */	IX_OAM_TYPE_AND_FUNC_SET(lbPayload, IX_OAM_ITU610_TYPE_FAULT_MAN_LB);		/* Setup the loopback indication */	IX_OAM_LOOPBACK_INDICATION_SET(lbPayload, IX_OAM_ITU610_LB_INDICATION_PARENT);		/* Increment the correlation tag and write this into the cell */ 	lbCorrelationTag++;	ixOamMemCpy(lbPayload->correlationTag, (UCHAR *)(&lbCorrelationTag), IX_OAM_ITU610_LB_CORRELATION_TAG_LEN);		/* Set Loopback Location Id */	ixOamMemCpy(lbPayload->llid, allOnesLocId, IX_OAM_ITU610_LOCATION_ID_LEN);		/* Store the source Id as the CPID */	ixOamMemCpy(lbPayload->sourceId, oamCpid, IX_OAM_ITU610_LOCATION_ID_LEN);		/* Set the reserved fields to 0x6a */	ixOamMemSet(lbPayload->reserved, 		    IX_OAM_ITU610_RESERVED_BYTE_VALUE, 		    IX_OAM_ITU610_LB_RESERVED_BYTES_LEN);		/* Set the transmit VPI */	IX_OAM_VPI_SET(oamHdr, vpi);	/* Set the transmit VCI TX Vci */	IX_OAM_VCI_SET(oamHdr, vci);		/* Set the PTI */	IX_OAM_PTI_SET(oamHdr, pti);	/* Set the header in buffer */	IX_OAM_HEADER_SET(txCell, oamHdr);        /* flush the mbuf frm cache */        ixOamTxFlush( txMbuf );	/* Transmit the cell, not reentrant on a VC basis so protect */	lockKey = ixOsalIrqLock();	retval = ixOamTxAndRetry (oamTxConnId[port],			          txMbuf,			          0,  /* CLP 0 */			          1); /* Cells per packet */	ixOsalIrqUnlock (lockKey);	if (retval == IX_SUCCESS)	{	    /* Increment the loopback out counter */	    parentLbCellTxCount[port]++;	}	else	{	    /* Release the MBUF */	    ixAtmUtilsMbufFree (txMbuf);	}    }    else    {	IX_OAM_CODELET_IRQ_SAFE_LOG_ERROR("ixOamParentLbCellTx: Failed to get a buffer for transmit");    }    return retval;}PRIVATE voidixOamParentLbCellRx (IxAtmLogicalPort port, IX_OSAL_MBUF *rxMbuf){         /* Loopback location ID correct? */    if (ixOamRxLlidCheck (((IxOamITU610Cell *)(IX_OSAL_MBUF_MDATA(rxMbuf)))) == IX_SUCCESS)    {	parentLbCellRxCount[port]++;	/* Send loopback child cell back to originator */	ixOamChildLbCellTx (port, rxMbuf);    }    else    {	parentLbCellRxErrCount[port]++;	/* free the buffer */	ixAtmUtilsMbufFree (rxMbuf);    }}/* * Reuse the received parent LB cell * and modify some of the fields */PRIVATE IX_STATUSixOamChildLbCellTx (IxAtmLogicalPort port, IX_OSAL_MBUF *rxMbuf){        IxOamITU610Cell *txCell;    IxOamITU610LbPayload *lbPayload;    IX_STATUS retval = IX_FAIL;    UINT32 lockKey;    /* Setup a pointer to the cell data */    txCell = (IxOamITU610Cell *) IX_OSAL_MBUF_MDATA(rxMbuf);            /* Setup pointers to Lb fields */    lbPayload = &(txCell->payload.lbPayload);        /* Change the loopback indication flag */    IX_OAM_LOOPBACK_INDICATION_SET(lbPayload, IX_OAM_ITU610_LB_INDICATION_CHILD);    /* Set the LLID to the CPID */    ixOamMemCpy(lbPayload->llid, oamCpid, IX_OAM_ITU610_LOCATION_ID_LEN);    /* flush the mbuf from cache */    ixOamTxFlush( rxMbuf );    /* Transmit the cell, not reentrant on a VC basis so protect */    lockKey = ixOsalIrqLock();    retval =  ixOamTxAndRetry (oamTxConnId[port],			       rxMbuf,			       0, /* CLP 0 */			       1); /* Cells per packet */    ixOsalIrqUnlock (lockKey);    if (retval == IX_SUCCESS)    {	/* Increment the loopback out counter */	childLbCellTxCount[port]++;    }    else    {	/* Release the MBUF */	ixAtmUtilsMbufFree (rxMbuf);    }    return retval;}PRIVATE IX_STATUSixOamRxLlidCheck (IxOamITU610Cell *oamCell){    UINT8 *llid;    UINT32 pti;    UINT32 vci;    UINT32 oamHdr = 0x0;    /* Get the LLID from the payload */    llid = oamCell->payload.lbPayload.llid;    /* Get the Pt and Vci */    IX_OAM_HEADER_GET(oamCell, oamHdr);    vci = IX_OAM_VCI_GET(oamHdr);    pti = IX_OAM_PTI_GET(oamHdr);    /* Compare LLID to the CPID */    if (ixOamMemCmp (llid, oamCpid, IX_OAM_ITU610_LOCATION_ID_LEN) == 0)    {	return IX_SUCCESS;    }    /* Compare to all 1's, i.e. end point  */    else if (ixOamMemCmp (llid, allOnesLocId, IX_OAM_ITU610_LOCATION_ID_LEN) == 0)    {	return IX_SUCCESS;    }    /* is this a segment loopback cell */    else if ((vci == IX_OAM_ITU610_F4_SEG_VCI) || (pti == IX_OAM_ITU610_F5_SEG_PTI))    {	/* Compare to all 0's */	if (ixOamMemCmp (llid, allZerosLocId, IX_OAM_ITU610_LOCATION_ID_LEN) == 0)	{	    return IX_SUCCESS;	}    }    return IX_FAIL;}PRIVATE voidixOamTxDoneCallback (IxAtmdAccUserId userId,		     IX_OSAL_MBUF *mbufPtr){    ixAtmUtilsMbufFree(mbufPtr);    txDoneCallbackCount[userId]++; /* userId == port */}PRIVATE voidixOamRxFreeLowReplenishCallback (IxAtmdAccUserId userId){    IX_OSAL_MBUF *mBuf;    UINT32 numFreeEntries;    UINT32 cnt;    IX_STATUS retval;       IX_OSAL_ASSERT(userId == oamRxUserId);        retval = ixAtmdAccRxVcFreeEntriesQuery (oamRxConnId, &numFreeEntries);    if (retval != IX_SUCCESS)    {	IX_OAM_CODELET_IRQ_SAFE_LOG_ERROR("Failed to query depth of Oam Rx Free Q");	return;    }    /* Replenish Rx buffers  */    for (cnt=0; cnt<numFreeEntries; cnt++)    {     	ixAtmUtilsMbufGet(IX_ATM_OAM_CELL_SIZE_NO_HEC, &mBuf);	if (mBuf == NULL)	{	    IX_OAM_CODELET_IRQ_SAFE_LOG_ERROR("Failed to get rx free buffer");	    return;	}		/* 	 * Set the number of bytes of data in this MBUF to 1 OAM cell	 */      	IX_OSAL_MBUF_MLEN(mBuf) = IX_ATM_OAM_CELL_SIZE_NO_HEC;	        /* invalidate cache */        ixOamRxInvalidate( mBuf );        	/* Send free buffers to NPE */	retval = ixAtmdAccRxVcFreeReplenish (oamRxConnId, mBuf);      	if (retval != IX_SUCCESS)	{	    /* Free the allocated buffer */	    ixAtmUtilsMbufFree(mBuf);	    IX_OAM_CODELET_IRQ_SAFE_LOG_ERROR("Failed to pass Oam Rx free buffers to Atmd");	    return;	}	    }    replenishCallbackCount++;}/* ---------------------------------------------------*/PRIVATE IX_STATUS ixOamTxAndRetry(IxAtmConnId connId,                IX_OSAL_MBUF * mbufPtr,                IxAtmdAccClpStatus clp,                UINT32 numberOfCells){     IX_STATUS status = IX_FAIL;     int retryCount = IX_OAM_TX_RETRY_COUNT_MAX;             /* retry until the PDU is successfully submitted,        or the submit fails, or the maximum number of        retries is exceede.             */      while(retryCount-- )     {        status = ixAtmdAccTxVcPduSubmit (connId,                                         mbufPtr,                                         clp,                                         numberOfCells);        if( status != IX_ATMDACC_BUSY )        {            return status;        }        ixOsalSleep(IX_OAM_TX_RETRY_DELAY);     }     return IX_FAIL;}                        /* ---------------------------------------------------*/PRIVATE voidixOamTxFlush(IX_OSAL_MBUF * mbufPtr){    while (mbufPtr != NULL)    {      IX_OSAL_CACHE_FLUSH(IX_OSAL_MBUF_MDATA(mbufPtr), IX_OSAL_MBUF_MLEN(mbufPtr));      mbufPtr = IX_OSAL_MBUF_NEXT_BUFFER_IN_PKT_PTR(mbufPtr);    }    return;}/* ---------------------------------------------------*/PRIVATE voidixOamRxInvalidate(IX_OSAL_MBUF * mbufPtr){   while (mbufPtr != NULL)      {      IX_OSAL_CACHE_INVALIDATE(IX_OSAL_MBUF_MDATA(mbufPtr), IX_OSAL_MBUF_MLEN(mbufPtr));      mbufPtr = IX_OSAL_MBUF_NEXT_BUFFER_IN_PKT_PTR(mbufPtr);       }    return;}/* --------------------------------------------------------------   Software queue manipulation functions.   -------------------------------------------------------------- */PRIVATE void ixOamQueueInit( int port ){    ixOsalMemSet(&ixOamSwQueue[port], 0, sizeof(ixOamSwQueue[port]));    ixOamSwQueue[port].size = IX_OAMCODELET_NUM_MBUFS_IN_SW_MBUF_Q;    ixOamSwQueue[port].mask = IX_OAMCODELET_NUM_MBUFS_IN_SW_MBUF_Q - 1;}PRIVATE BOOL ixOamQueueEmptyQuery (IxOamCodeletSwMbufQ *s){    return (s->head == s->tail);}PRIVATE IX_OSAL_MBUF * ixOamMBufQueueGet (IxOamCodeletSwMbufQ *s){    IX_OSAL_ASSERT (s->head != s->tail);    return (s->array[s->tail++ & s->mask]);}PRIVATE void ixOamQueuePut (IxOamCodeletSwMbufQ *s, IX_OSAL_MBUF *buf){    IX_OSAL_ASSERT (s->head - s->tail != s->size);    s->array[s->head++ & s->mask] = buf;}/* --------------------------------------------------- */PRIVATE BOOLixOamMemCmp(UCHAR *destBuf, UCHAR* srcBuf, UINT32 len){    /* params check */    if ( (srcBuf == NULL) || (destBuf == NULL) || (len <= 0) )	return 1;    /* data check */    while(len--)    {	if ( *srcBuf++ != *destBuf++ )	    return 1;    }        /* success */    return 0;}/* --------------------------------------------------- */PRIVATE voidixOamMemCpy(UCHAR *destBuf, UCHAR* srcBuf, UINT32 len){    /* params check */    if ( (srcBuf == NULL) || (destBuf == NULL) || (len <= 0) )	return;    /* data copy */    while(len--)    {	*destBuf++ = *srcBuf++;    }    return;}/* --------------------------------------------------- */PRIVATE voidixOamMemSet(UCHAR *destBuf, UCHAR data, UINT32 len){    /* params check */    if ( (destBuf == NULL) )	return;    /* set the data */    while (len--)    {	*destBuf++ = data;    }    return;}                      

⌨️ 快捷键说明

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