📄 ixhssaccpdm.c
字号:
/** * @file IxHssAccPDM.c * * @author Intel Corporation * @date 14 Dec 2001 * * @brief This file contains the implementation of the private API for * the Packetised Descriptor Manager. * * * @par * IXP400 SW Release version 2.1 * * -- Copyright Notice -- * * @par * Copyright (c) 2001-2005, Intel Corporation. * All rights reserved. * * @par * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the Intel Corporation nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * * @par * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * * @par * -- End of Copyright Notice --*//* * Put the user defined include files required. */#include "IxOsal.h"#include "IxHssAccPDM_p.h"#include "IxHssAcc.h"#include "IxHssAccError_p.h"#include "IxHssAccCommon_p.h"/* * #defines and macros used in this file. */#define IX_HSSACC_PKT_NUM_DESCS_PER_POOL 16#define IX_HSSACC_PKT_NUM_POOLS_PER_CLIENT 2#define IX_HSSACC_PKT_NUM_POOLS_PER_HSS (IX_HSSACC_HDLC_PORT_MAX *\ IX_HSSACC_PKT_NUM_POOLS_PER_CLIENT)#define IX_HSSACC_PKT_NUM_DESCS_PER_HSS (IX_HSSACC_PKT_NUM_DESCS_PER_POOL *\ IX_HSSACC_PKT_NUM_POOLS_PER_HSS)#define IX_HSSACC_PKT_MAX_NUM_POOLS (IX_HSSACC_HSS_PORT_MAX *\ IX_HSSACC_PKT_NUM_POOLS_PER_HSS)#define IX_HSSACC_PKT_MAX_NUM_DESCS (IX_HSSACC_PKT_NUM_DESCS_PER_POOL *\ IX_HSSACC_PKT_MAX_NUM_POOLS)/* * Typedefs whose scope is limited to this file. */typedef struct{ unsigned gets; unsigned frees; unsigned maxInUse; unsigned errs;} IxHssAccPDMStats;typedef struct{ IxHssAccPDMStats stats; unsigned freeIndex; IxHssAccPDMDescriptor *descPool[IX_HSSACC_PKT_NUM_DESCS_PER_POOL]; } IxHssAccPDMPoolInfo;/* * Variable declarations global to this file only. Externs are followed by static variables. */IxHssAccPDMPoolInfo ixHssAccPDMPoolInfo[IX_HSSACC_PKT_MAX_NUM_POOLS];static UINT32 maxNumPools = IX_HSSACC_PKT_NUM_POOLS_PER_HSS; /* assume only HSS port 0 is available *//* * Flag used by IxHssAccPDMInit and IxHssAccPDMUninit functions */PRIVATE BOOL ixHssAccMemoryAllocdAndChecked = FALSE;/* * Pointer to memory allocated by IxHssAccPDMInit() */PRIVATE UINT8 *ixHssAccMallocData = NULL;/** * Static function prototypes. */PRIVATE void ixHssAccPDMPoolStatsInit (unsigned index1);/** * Function definition: ixHssAccPDMPoolStatsInit */PRIVATE void ixHssAccPDMPoolStatsInit (unsigned index1){ ixOsalMemSet (&(ixHssAccPDMPoolInfo[index1].stats), 0, sizeof (IxHssAccPDMStats));}/** * Function definition: ixHssAccPDMInit */IX_STATUSixHssAccPDMInit (){ unsigned index1; unsigned count; unsigned descMallocSize = sizeof (IxHssAccPDMDescriptor); unsigned totalMallocSize; static BOOL memoryAllocdAndChecked = FALSE; UINT32 maxNumDescs; UINT8 *mallocData; UINT8 *nextDescAddr; IxHssAccPDMPoolInfo *poolInfo = &ixHssAccPDMPoolInfo[0]; IX_STATUS status = IX_SUCCESS; IX_HSSACC_TRACE0 (IX_HSSACC_FN_ENTRY_EXIT, "Entering" " ixHssAccPDMInit \n"); memoryAllocdAndChecked = ixHssAccMemoryAllocdAndChecked; /* create the memory first */ if (!memoryAllocdAndChecked) { /* each descriptor will need to be cache page aligned */ if ((descMallocSize % IX_OSAL_CACHE_LINE_SIZE) != 0) { descMallocSize += (IX_OSAL_CACHE_LINE_SIZE - (descMallocSize % IX_OSAL_CACHE_LINE_SIZE)); } if (hssPortMax == IX_HSSACC_SINGLE_HSS_PORT) /* allocating mem for HSS port 0 only */ { maxNumDescs = IX_HSSACC_PKT_NUM_DESCS_PER_HSS; maxNumPools = IX_HSSACC_PKT_NUM_POOLS_PER_HSS; } else /* allocating mem for both HSS ports */ { maxNumDescs = IX_HSSACC_PKT_MAX_NUM_DESCS; maxNumPools = IX_HSSACC_PKT_MAX_NUM_POOLS; } totalMallocSize = descMallocSize * maxNumDescs; mallocData = (UINT8 *)IX_HSSACC_PKT_DRV_DMA_MALLOC(totalMallocSize); /* check that valid memory was received */ if (mallocData == NULL) { IX_HSSACC_REPORT_ERROR ("ixHssAccPDMInit:" "Failed to get memory for descriptor pool\n"); return IX_HSSACC_RESOURCE_ERR; } ixHssAccMallocData = mallocData; nextDescAddr = mallocData; for (index1 = 0; index1 < maxNumPools; index1++) { /* initialise pool stats */ ixHssAccPDMPoolStatsInit (index1); /* initialise the pool info values */ for (count = 0; count < IX_HSSACC_PKT_NUM_DESCS_PER_POOL; count++) { poolInfo->descPool[count] = (IxHssAccPDMDescriptor *) nextDescAddr; poolInfo->descPool[count]->descIndex = count; /* used in freeing */ poolInfo->descPool[count]->descInUse = FALSE; poolInfo->descPool[count]->hssPortId = index1 / IX_HSSACC_PKT_NUM_POOLS_PER_HSS; poolInfo->descPool[count]->hdlcPortId = (index1 / IX_HSSACC_PKT_NUM_POOLS_PER_CLIENT) % IX_HSSACC_HDLC_PORT_MAX; nextDescAddr += descMallocSize; } poolInfo->freeIndex = 0; poolInfo++; } memoryAllocdAndChecked = TRUE; ixHssAccMemoryAllocdAndChecked = memoryAllocdAndChecked; } else { /* may want to do a PDMInit a second time - just init desc contents */ for (index1 = 0, poolInfo = &ixHssAccPDMPoolInfo[0]; index1 < maxNumPools; index1++) { /* initialise pool stats */ ixHssAccPDMPoolStatsInit (index1); /* initialise the pool info values */ for (count = 0; count < IX_HSSACC_PKT_NUM_DESCS_PER_POOL; count++) { poolInfo->descPool[count]->descInUse = FALSE; poolInfo->descPool[count]->hssPortId = index1 / IX_HSSACC_PKT_NUM_POOLS_PER_HSS; poolInfo->descPool[count]->hdlcPortId = (index1 / IX_HSSACC_PKT_NUM_POOLS_PER_CLIENT) % IX_HSSACC_HDLC_PORT_MAX; } poolInfo->freeIndex = 0; poolInfo++; } } IX_HSSACC_TRACE0 (IX_HSSACC_FN_ENTRY_EXIT, "Exiting " "ixHssAccPDMInit \n"); return status;}/** * Function definition: ixHssAccPDMUninit */IX_STATUSixHssAccPDMUninit (void){ IX_HSSACC_TRACE0 (IX_HSSACC_FN_ENTRY_EXIT, "Entering" " ixHssAccPDMUninit \n"); /* check if uninitialised already done first */ if (ixHssAccMemoryAllocdAndChecked) { /* Free the memory alloted by initialisation*/ IX_OSAL_CACHE_DMA_FREE (ixHssAccMallocData); ixHssAccMallocData = NULL; /* Reset the flag to FALSE */ ixHssAccMemoryAllocdAndChecked = FALSE; } else { IX_HSSACC_REPORT_ERROR ("ixHssAccPDMUninit:" "Called with " " ixHssAccMemoryAllocdAndChecked == FALSE\n"); return IX_FAIL; } IX_HSSACC_TRACE0 (IX_HSSACC_FN_ENTRY_EXIT, "Exiting " "ixHssAccPDMUninit \n"); return IX_SUCCESS;}/** * Function definition: ixHssAccPDMDescGet */IX_STATUS ixHssAccPDMDescGet (IxHssAccHssPort hssPortId, IxHssAccHdlcPort hdlcPortId, IxHssAccPDMPoolType poolType, IxHssAccPDMDescriptor **desc){ /* This function may be called from within an ISR */ unsigned poolIndex = (hssPortId * IX_HSSACC_PKT_NUM_POOLS_PER_HSS) + (hdlcPortId * IX_HSSACC_PKT_NUM_POOLS_PER_CLIENT) + poolType; IxHssAccPDMPoolInfo *poolInfo = &ixHssAccPDMPoolInfo[poolIndex]; unsigned descsInUse; IX_STATUS status = IX_SUCCESS; IX_HSSACC_DEBUG_OFF (char errMsg[120]); IX_HSSACC_DEBUG_OFF (IX_HSSACC_TRACE0 (IX_HSSACC_FN_ENTRY_EXIT, "Entering" " ixHssAccPDMDescGet\n")); /* * Check that the freeIndexs dereference is "free" * if so set the desc parameter to point to the free ptr
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -