Path: blob/main/sys/contrib/ncsw/Peripherals/FM/SP/fm_sp.c
48526 views
/*1* Copyright 2008-2012 Freescale Semiconductor Inc.2*3* Redistribution and use in source and binary forms, with or without4* modification, are permitted provided that the following conditions are met:5* * Redistributions of source code must retain the above copyright6* notice, this list of conditions and the following disclaimer.7* * Redistributions in binary form must reproduce the above copyright8* notice, this list of conditions and the following disclaimer in the9* documentation and/or other materials provided with the distribution.10* * Neither the name of Freescale Semiconductor nor the11* names of its contributors may be used to endorse or promote products12* derived from this software without specific prior written permission.13*14*15* ALTERNATIVELY, this software may be distributed under the terms of the16* GNU General Public License ("GPL") as published by the Free Software17* Foundation, either version 2 of that License or (at your option) any18* later version.19*20* THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY21* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED22* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE23* DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY24* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES25* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;26* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND27* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT28* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS29* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.30*/313233/******************************************************************************34@File fm_sp.c3536@Description FM PCD Storage profile ...37*//***************************************************************************/3839#include "std_ext.h"40#include "error_ext.h"41#include "string_ext.h"42#include "debug_ext.h"43#include "net_ext.h"4445#include "fm_vsp_ext.h"46#include "fm_sp.h"47#include "fm_common.h"48#include "fsl_fman_sp.h"495051#if (DPAA_VERSION >= 11)52static t_Error CheckParamsGeneratedInternally(t_FmVspEntry *p_FmVspEntry)53{54t_Error err = E_OK;5556if ((err = FmSpCheckIntContextParams(&p_FmVspEntry->intContext))!= E_OK)57RETURN_ERROR(MAJOR, err, NO_MSG);58if ((err = FmSpCheckBufMargins(&p_FmVspEntry->bufMargins)) != E_OK)59RETURN_ERROR(MAJOR, err, NO_MSG);60return err;6162}6364static t_Error CheckParams(t_FmVspEntry *p_FmVspEntry)65{66t_Error err = E_OK;6768SANITY_CHECK_RETURN_ERROR(p_FmVspEntry, E_INVALID_HANDLE);69SANITY_CHECK_RETURN_ERROR(p_FmVspEntry->p_FmVspEntryDriverParams, E_INVALID_HANDLE);70SANITY_CHECK_RETURN_ERROR(p_FmVspEntry->h_Fm, E_INVALID_HANDLE);7172if ((err = FmSpCheckBufPoolsParams(&p_FmVspEntry->p_FmVspEntryDriverParams->extBufPools,73p_FmVspEntry->p_FmVspEntryDriverParams->p_BackupBmPools,74p_FmVspEntry->p_FmVspEntryDriverParams->p_BufPoolDepletion)) != E_OK)7576RETURN_ERROR(MAJOR, err, NO_MSG);7778if (p_FmVspEntry->p_FmVspEntryDriverParams->liodnOffset & ~FM_LIODN_OFFSET_MASK)79RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("liodnOffset is larger than %d", FM_LIODN_OFFSET_MASK+1));8081err = FmVSPCheckRelativeProfile(p_FmVspEntry->h_Fm,82p_FmVspEntry->portType,83p_FmVspEntry->portId,84p_FmVspEntry->relativeProfileId);8586return err;87}88#endif /* (DPAA_VERSION >= 11) */899091/*****************************************************************************/92/* Inter-module API routines */93/*****************************************************************************/94void FmSpSetBufPoolsInAscOrderOfBufSizes(t_FmExtPools *p_FmExtPools,95uint8_t *orderedArray,96uint16_t *sizesArray)97{98uint16_t bufSize = 0;99int i=0, j=0, k=0;100101/* First we copy the external buffers pools information to an ordered local array */102for (i=0;i<p_FmExtPools->numOfPoolsUsed;i++)103{104/* get pool size */105bufSize = p_FmExtPools->extBufPool[i].size;106107/* keep sizes in an array according to poolId for direct access */108sizesArray[p_FmExtPools->extBufPool[i].id] = bufSize;109110/* save poolId in an ordered array according to size */111for (j=0;j<=i;j++)112{113/* this is the next free place in the array */114if (j==i)115orderedArray[i] = p_FmExtPools->extBufPool[i].id;116else117{118/* find the right place for this poolId */119if (bufSize < sizesArray[orderedArray[j]])120{121/* move the poolIds one place ahead to make room for this poolId */122for (k=i;k>j;k--)123orderedArray[k] = orderedArray[k-1];124125/* now k==j, this is the place for the new size */126orderedArray[k] = p_FmExtPools->extBufPool[i].id;127break;128}129}130}131}132}133134t_Error FmSpCheckBufPoolsParams(t_FmExtPools *p_FmExtPools,135t_FmBackupBmPools *p_FmBackupBmPools,136t_FmBufPoolDepletion *p_FmBufPoolDepletion)137{138139int i = 0, j = 0;140bool found;141uint8_t count = 0;142143if (p_FmExtPools)144{145if (p_FmExtPools->numOfPoolsUsed > FM_PORT_MAX_NUM_OF_EXT_POOLS)146RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("numOfPoolsUsed can't be larger than %d", FM_PORT_MAX_NUM_OF_EXT_POOLS));147148for (i=0;i<p_FmExtPools->numOfPoolsUsed;i++)149{150if (p_FmExtPools->extBufPool[i].id >= BM_MAX_NUM_OF_POOLS)151RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("extBufPools.extBufPool[%d].id can't be larger than %d", i, BM_MAX_NUM_OF_POOLS));152if (!p_FmExtPools->extBufPool[i].size)153RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("extBufPools.extBufPool[%d].size is 0", i));154}155}156if (!p_FmExtPools && (p_FmBackupBmPools || p_FmBufPoolDepletion))157RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("backupBmPools ot bufPoolDepletion can not be defined without external pools"));158159/* backup BM pools indication is valid only for some chip derivatives160(limited by the config routine) */161if (p_FmBackupBmPools)162{163if (p_FmBackupBmPools->numOfBackupPools >= p_FmExtPools->numOfPoolsUsed)164RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("p_BackupBmPools must be smaller than extBufPools.numOfPoolsUsed"));165found = FALSE;166for (i = 0;i<p_FmBackupBmPools->numOfBackupPools;i++)167{168169for (j=0;j<p_FmExtPools->numOfPoolsUsed;j++)170{171if (p_FmBackupBmPools->poolIds[i] == p_FmExtPools->extBufPool[j].id)172{173found = TRUE;174break;175}176}177if (!found)178RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("All p_BackupBmPools.poolIds must be included in extBufPools.extBufPool[n].id"));179else180found = FALSE;181}182}183184/* up to extBufPools.numOfPoolsUsed pools may be defined */185if (p_FmBufPoolDepletion && p_FmBufPoolDepletion->poolsGrpModeEnable)186{187if ((p_FmBufPoolDepletion->numOfPools > p_FmExtPools->numOfPoolsUsed))188RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("bufPoolDepletion.numOfPools can't be larger than %d and can't be larger than numOfPoolsUsed", FM_PORT_MAX_NUM_OF_EXT_POOLS));189190if (!p_FmBufPoolDepletion->numOfPools)191RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("bufPoolDepletion.numOfPoolsToConsider can not be 0 when poolsGrpModeEnable=TRUE"));192193found = FALSE;194count = 0;195/* for each pool that is in poolsToConsider, check if it is defined196in extBufPool */197for (i=0;i<BM_MAX_NUM_OF_POOLS;i++)198{199if (p_FmBufPoolDepletion->poolsToConsider[i])200{201for (j=0;j<p_FmExtPools->numOfPoolsUsed;j++)202{203if (i == p_FmExtPools->extBufPool[j].id)204{205found = TRUE;206count++;207break;208}209}210if (!found)211RETURN_ERROR(MAJOR, E_INVALID_STATE, ("Pools selected for depletion are not used."));212else213found = FALSE;214}215}216/* check that the number of pools that we have checked is equal to the number announced by the user */217if (count != p_FmBufPoolDepletion->numOfPools)218RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("bufPoolDepletion.numOfPools is larger than the number of pools defined."));219}220221if (p_FmBufPoolDepletion && p_FmBufPoolDepletion->singlePoolModeEnable)222{223/* calculate vector for number of pools depletion */224found = FALSE;225count = 0;226for (i=0;i<BM_MAX_NUM_OF_POOLS;i++)227{228if (p_FmBufPoolDepletion->poolsToConsiderForSingleMode[i])229{230for (j=0;j<p_FmExtPools->numOfPoolsUsed;j++)231{232if (i == p_FmExtPools->extBufPool[j].id)233{234found = TRUE;235count++;236break;237}238}239if (!found)240RETURN_ERROR(MAJOR, E_INVALID_STATE, ("Pools selected for depletion are not used."));241else242found = FALSE;243}244}245if (!count)246RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("No pools defined for single buffer mode pool depletion."));247}248249return E_OK;250}251252t_Error FmSpCheckIntContextParams(t_FmSpIntContextDataCopy *p_FmSpIntContextDataCopy)253{254/* Check that divisible by 16 and not larger than 240 */255if (p_FmSpIntContextDataCopy->intContextOffset >MAX_INT_OFFSET)256RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("intContext.intContextOffset can't be larger than %d", MAX_INT_OFFSET));257if (p_FmSpIntContextDataCopy->intContextOffset % OFFSET_UNITS)258RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("intContext.intContextOffset has to be divisible by %d", OFFSET_UNITS));259260/* check that ic size+ic internal offset, does not exceed ic block size */261if (p_FmSpIntContextDataCopy->size + p_FmSpIntContextDataCopy->intContextOffset > MAX_IC_SIZE)262RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("intContext.size + intContext.intContextOffset has to be smaller than %d", MAX_IC_SIZE));263/* Check that divisible by 16 and not larger than 256 */264if (p_FmSpIntContextDataCopy->size % OFFSET_UNITS)265RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("intContext.size has to be divisible by %d", OFFSET_UNITS));266267/* Check that divisible by 16 and not larger than 4K */268if (p_FmSpIntContextDataCopy->extBufOffset > MAX_EXT_OFFSET)269RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("intContext.extBufOffset can't be larger than %d", MAX_EXT_OFFSET));270if (p_FmSpIntContextDataCopy->extBufOffset % OFFSET_UNITS)271RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("intContext.extBufOffset has to be divisible by %d", OFFSET_UNITS));272273return E_OK;274}275276t_Error FmSpCheckBufMargins(t_FmSpBufMargins *p_FmSpBufMargins)277{278/* Check the margin definition */279if (p_FmSpBufMargins->startMargins > MAX_EXT_BUFFER_OFFSET)280RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("bufMargins.startMargins can't be larger than %d", MAX_EXT_BUFFER_OFFSET));281if (p_FmSpBufMargins->endMargins > MAX_EXT_BUFFER_OFFSET)282RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("bufMargins.endMargins can't be larger than %d", MAX_EXT_BUFFER_OFFSET));283284return E_OK;285}286287t_Error FmSpBuildBufferStructure(t_FmSpIntContextDataCopy *p_FmSpIntContextDataCopy,288t_FmBufferPrefixContent *p_BufferPrefixContent,289t_FmSpBufMargins *p_FmSpBufMargins,290t_FmSpBufferOffsets *p_FmSpBufferOffsets,291uint8_t *internalBufferOffset)292{293uint32_t tmp;294295SANITY_CHECK_RETURN_ERROR(p_FmSpIntContextDataCopy, E_INVALID_VALUE);296ASSERT_COND(p_FmSpIntContextDataCopy);297ASSERT_COND(p_BufferPrefixContent);298ASSERT_COND(p_FmSpBufMargins);299ASSERT_COND(p_FmSpBufferOffsets);300301/* Align start of internal context data to 16 byte */302p_FmSpIntContextDataCopy->extBufOffset =303(uint16_t)((p_BufferPrefixContent->privDataSize & (OFFSET_UNITS-1)) ?304((p_BufferPrefixContent->privDataSize + OFFSET_UNITS) & ~(uint16_t)(OFFSET_UNITS-1)) :305p_BufferPrefixContent->privDataSize);306307/* Translate margin and intContext params to FM parameters */308/* Initialize with illegal value. Later we'll set legal values. */309p_FmSpBufferOffsets->prsResultOffset = (uint32_t)ILLEGAL_BASE;310p_FmSpBufferOffsets->timeStampOffset = (uint32_t)ILLEGAL_BASE;311p_FmSpBufferOffsets->hashResultOffset= (uint32_t)ILLEGAL_BASE;312p_FmSpBufferOffsets->pcdInfoOffset = (uint32_t)ILLEGAL_BASE;313314/* Internally the driver supports 4 options3151. prsResult/timestamp/hashResult selection (in fact 8 options, but for simplicity we'll316relate to it as 1).3172. All IC context (from AD) not including debug.*/318319/* This 'if' covers option 2. We copy from beginning of context. */320if (p_BufferPrefixContent->passAllOtherPCDInfo)321{322p_FmSpIntContextDataCopy->size = 128; /* must be aligned to 16 */323/* Start copying data after 16 bytes (FD) from the beginning of the internal context */324p_FmSpIntContextDataCopy->intContextOffset = 16;325326if (p_BufferPrefixContent->passAllOtherPCDInfo)327p_FmSpBufferOffsets->pcdInfoOffset = p_FmSpIntContextDataCopy->extBufOffset;328if (p_BufferPrefixContent->passPrsResult)329p_FmSpBufferOffsets->prsResultOffset =330(uint32_t)(p_FmSpIntContextDataCopy->extBufOffset + 16);331if (p_BufferPrefixContent->passTimeStamp)332p_FmSpBufferOffsets->timeStampOffset =333(uint32_t)(p_FmSpIntContextDataCopy->extBufOffset + 48);334if (p_BufferPrefixContent->passHashResult)335p_FmSpBufferOffsets->hashResultOffset =336(uint32_t)(p_FmSpIntContextDataCopy->extBufOffset + 56);337}338else339{340/* This case covers the options under 1 */341/* Copy size must be in 16-byte granularity. */342p_FmSpIntContextDataCopy->size =343(uint16_t)((p_BufferPrefixContent->passPrsResult ? 32 : 0) +344((p_BufferPrefixContent->passTimeStamp ||345p_BufferPrefixContent->passHashResult) ? 16 : 0));346347/* Align start of internal context data to 16 byte */348p_FmSpIntContextDataCopy->intContextOffset =349(uint8_t)(p_BufferPrefixContent->passPrsResult ? 32 :350((p_BufferPrefixContent->passTimeStamp ||351p_BufferPrefixContent->passHashResult) ? 64 : 0));352353if (p_BufferPrefixContent->passPrsResult)354p_FmSpBufferOffsets->prsResultOffset = p_FmSpIntContextDataCopy->extBufOffset;355if (p_BufferPrefixContent->passTimeStamp)356p_FmSpBufferOffsets->timeStampOffset = p_BufferPrefixContent->passPrsResult ?357(p_FmSpIntContextDataCopy->extBufOffset + sizeof(t_FmPrsResult)) :358p_FmSpIntContextDataCopy->extBufOffset;359if (p_BufferPrefixContent->passHashResult)360/* If PR is not requested, whether TS is requested or not, IC will be copied from TS */361p_FmSpBufferOffsets->hashResultOffset = p_BufferPrefixContent->passPrsResult ?362(p_FmSpIntContextDataCopy->extBufOffset + sizeof(t_FmPrsResult) + 8) :363p_FmSpIntContextDataCopy->extBufOffset + 8;364}365366if (p_FmSpIntContextDataCopy->size)367p_FmSpBufMargins->startMargins =368(uint16_t)(p_FmSpIntContextDataCopy->extBufOffset +369p_FmSpIntContextDataCopy->size);370else371/* No Internal Context passing, STartMargin is immediately after privateInfo */372p_FmSpBufMargins->startMargins = p_BufferPrefixContent->privDataSize;373374/* save extra space for manip in both external and internal buffers */375if (p_BufferPrefixContent->manipExtraSpace)376{377uint8_t extraSpace;378#ifdef FM_CAPWAP_SUPPORT379if ((p_BufferPrefixContent->manipExtraSpace + CAPWAP_FRAG_EXTRA_SPACE) >= 256)380RETURN_ERROR(MAJOR, E_INVALID_VALUE,381("p_BufferPrefixContent->manipExtraSpace should be less than %d",382256-CAPWAP_FRAG_EXTRA_SPACE));383extraSpace = (uint8_t)(p_BufferPrefixContent->manipExtraSpace + CAPWAP_FRAG_EXTRA_SPACE);384#else385extraSpace = p_BufferPrefixContent->manipExtraSpace;386#endif /* FM_CAPWAP_SUPPORT */387p_FmSpBufferOffsets->manipOffset = p_FmSpBufMargins->startMargins;388p_FmSpBufMargins->startMargins += extraSpace;389*internalBufferOffset = extraSpace;390}391392/* align data start */393tmp = (uint32_t)(p_FmSpBufMargins->startMargins % p_BufferPrefixContent->dataAlign);394if (tmp)395p_FmSpBufMargins->startMargins += (p_BufferPrefixContent->dataAlign-tmp);396p_FmSpBufferOffsets->dataOffset = p_FmSpBufMargins->startMargins;397398return E_OK;399}400/*********************** End of inter-module routines ************************/401402403#if (DPAA_VERSION >= 11)404/*****************************************************************************/405/* API routines */406/*****************************************************************************/407t_Handle FM_VSP_Config(t_FmVspParams *p_FmVspParams)408{409t_FmVspEntry *p_FmVspEntry = NULL;410struct fm_storage_profile_params fm_vsp_params;411412p_FmVspEntry = (t_FmVspEntry *)XX_Malloc(sizeof(t_FmVspEntry));413if (!p_FmVspEntry)414{415REPORT_ERROR(MAJOR, E_NO_MEMORY, ("p_StorageProfile allocation failed"));416return NULL;417}418memset(p_FmVspEntry, 0, sizeof(t_FmVspEntry));419420p_FmVspEntry->p_FmVspEntryDriverParams = (t_FmVspEntryDriverParams *)XX_Malloc(sizeof(t_FmVspEntryDriverParams));421if (!p_FmVspEntry->p_FmVspEntryDriverParams)422{423REPORT_ERROR(MAJOR, E_NO_MEMORY, ("p_StorageProfile allocation failed"));424XX_Free(p_FmVspEntry);425return NULL;426}427memset(p_FmVspEntry->p_FmVspEntryDriverParams, 0, sizeof(t_FmVspEntryDriverParams));428fman_vsp_defconfig(&fm_vsp_params);429p_FmVspEntry->p_FmVspEntryDriverParams->dmaHeaderCacheAttr = fm_vsp_params.header_cache_attr;430p_FmVspEntry->p_FmVspEntryDriverParams->dmaIntContextCacheAttr = fm_vsp_params.int_context_cache_attr;431p_FmVspEntry->p_FmVspEntryDriverParams->dmaScatterGatherCacheAttr = fm_vsp_params.scatter_gather_cache_attr;432p_FmVspEntry->p_FmVspEntryDriverParams->dmaSwapData = fm_vsp_params.dma_swap_data;433p_FmVspEntry->p_FmVspEntryDriverParams->dmaWriteOptimize = fm_vsp_params.dma_write_optimize;434p_FmVspEntry->p_FmVspEntryDriverParams->noScatherGather = fm_vsp_params.no_scather_gather;435p_FmVspEntry->p_FmVspEntryDriverParams->bufferPrefixContent.privDataSize = DEFAULT_FM_SP_bufferPrefixContent_privDataSize;436p_FmVspEntry->p_FmVspEntryDriverParams->bufferPrefixContent.passPrsResult= DEFAULT_FM_SP_bufferPrefixContent_passPrsResult;437p_FmVspEntry->p_FmVspEntryDriverParams->bufferPrefixContent.passTimeStamp= DEFAULT_FM_SP_bufferPrefixContent_passTimeStamp;438p_FmVspEntry->p_FmVspEntryDriverParams->bufferPrefixContent.passAllOtherPCDInfo439= DEFAULT_FM_SP_bufferPrefixContent_passTimeStamp;440p_FmVspEntry->p_FmVspEntryDriverParams->bufferPrefixContent.dataAlign = DEFAULT_FM_SP_bufferPrefixContent_dataAlign;441p_FmVspEntry->p_FmVspEntryDriverParams->liodnOffset = p_FmVspParams->liodnOffset;442443memcpy(&p_FmVspEntry->p_FmVspEntryDriverParams->extBufPools, &p_FmVspParams->extBufPools, sizeof(t_FmExtPools));444p_FmVspEntry->h_Fm = p_FmVspParams->h_Fm;445p_FmVspEntry->portType = p_FmVspParams->portParams.portType;446p_FmVspEntry->portId = p_FmVspParams->portParams.portId;447448p_FmVspEntry->relativeProfileId = p_FmVspParams->relativeProfileId;449450return p_FmVspEntry;451}452453t_Error FM_VSP_Init(t_Handle h_FmVsp)454{455456t_FmVspEntry *p_FmVspEntry = (t_FmVspEntry *)h_FmVsp;457struct fm_storage_profile_params fm_vsp_params;458uint8_t orderedArray[FM_PORT_MAX_NUM_OF_EXT_POOLS];459uint16_t sizesArray[BM_MAX_NUM_OF_POOLS];460t_Error err;461uint16_t absoluteProfileId = 0;462int i = 0;463464SANITY_CHECK_RETURN_ERROR(p_FmVspEntry, E_INVALID_HANDLE);465SANITY_CHECK_RETURN_ERROR(p_FmVspEntry->p_FmVspEntryDriverParams,E_INVALID_HANDLE);466467CHECK_INIT_PARAMETERS(p_FmVspEntry, CheckParams);468469memset(&orderedArray, 0, sizeof(uint8_t) * FM_PORT_MAX_NUM_OF_EXT_POOLS);470memset(&sizesArray, 0, sizeof(uint16_t) * BM_MAX_NUM_OF_POOLS);471472err = FmSpBuildBufferStructure(&p_FmVspEntry->intContext,473&p_FmVspEntry->p_FmVspEntryDriverParams->bufferPrefixContent,474&p_FmVspEntry->bufMargins,475&p_FmVspEntry->bufferOffsets,476&p_FmVspEntry->internalBufferOffset);477if (err != E_OK)478RETURN_ERROR(MAJOR, err, NO_MSG);479480481err = CheckParamsGeneratedInternally(p_FmVspEntry);482if (err != E_OK)483RETURN_ERROR(MAJOR, err, NO_MSG);484485486p_FmVspEntry->p_FmSpRegsBase =487(struct fm_pcd_storage_profile_regs *)FmGetVSPBaseAddr(p_FmVspEntry->h_Fm);488if (!p_FmVspEntry->p_FmSpRegsBase)489RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("impossible to initialize SpRegsBase"));490491/* order external buffer pools in ascending order of buffer pools sizes */492FmSpSetBufPoolsInAscOrderOfBufSizes(&(p_FmVspEntry->p_FmVspEntryDriverParams)->extBufPools,493orderedArray,494sizesArray);495496p_FmVspEntry->extBufPools.numOfPoolsUsed =497p_FmVspEntry->p_FmVspEntryDriverParams->extBufPools.numOfPoolsUsed;498for (i = 0; i < p_FmVspEntry->extBufPools.numOfPoolsUsed; i++)499{500p_FmVspEntry->extBufPools.extBufPool[i].id = orderedArray[i];501p_FmVspEntry->extBufPools.extBufPool[i].size = sizesArray[orderedArray[i]];502}503504/* on user responsibility to fill it according requirement */505memset(&fm_vsp_params, 0, sizeof(struct fm_storage_profile_params));506fm_vsp_params.dma_swap_data = p_FmVspEntry->p_FmVspEntryDriverParams->dmaSwapData;507fm_vsp_params.int_context_cache_attr = p_FmVspEntry->p_FmVspEntryDriverParams->dmaIntContextCacheAttr;508fm_vsp_params.header_cache_attr = p_FmVspEntry->p_FmVspEntryDriverParams->dmaHeaderCacheAttr;509fm_vsp_params.scatter_gather_cache_attr = p_FmVspEntry->p_FmVspEntryDriverParams->dmaScatterGatherCacheAttr;510fm_vsp_params.dma_write_optimize = p_FmVspEntry->p_FmVspEntryDriverParams->dmaWriteOptimize;511fm_vsp_params.liodn_offset = p_FmVspEntry->p_FmVspEntryDriverParams->liodnOffset;512fm_vsp_params.no_scather_gather = p_FmVspEntry->p_FmVspEntryDriverParams->noScatherGather;513514if (p_FmVspEntry->p_FmVspEntryDriverParams->p_BufPoolDepletion)515{516fm_vsp_params.buf_pool_depletion.buf_pool_depletion_enabled = TRUE;517fm_vsp_params.buf_pool_depletion.pools_grp_mode_enable = p_FmVspEntry->p_FmVspEntryDriverParams->p_BufPoolDepletion->poolsGrpModeEnable;518fm_vsp_params.buf_pool_depletion.num_pools = p_FmVspEntry->p_FmVspEntryDriverParams->p_BufPoolDepletion->numOfPools;519fm_vsp_params.buf_pool_depletion.pools_to_consider = p_FmVspEntry->p_FmVspEntryDriverParams->p_BufPoolDepletion->poolsToConsider;520fm_vsp_params.buf_pool_depletion.single_pool_mode_enable = p_FmVspEntry->p_FmVspEntryDriverParams->p_BufPoolDepletion->singlePoolModeEnable;521fm_vsp_params.buf_pool_depletion.pools_to_consider_for_single_mode = p_FmVspEntry->p_FmVspEntryDriverParams->p_BufPoolDepletion->poolsToConsiderForSingleMode;522fm_vsp_params.buf_pool_depletion.has_pfc_priorities = TRUE;523fm_vsp_params.buf_pool_depletion.pfc_priorities_en = p_FmVspEntry->p_FmVspEntryDriverParams->p_BufPoolDepletion->pfcPrioritiesEn;524}525else526fm_vsp_params.buf_pool_depletion.buf_pool_depletion_enabled = FALSE;527528if (p_FmVspEntry->p_FmVspEntryDriverParams->p_BackupBmPools)529{530fm_vsp_params.backup_pools.num_backup_pools = p_FmVspEntry->p_FmVspEntryDriverParams->p_BackupBmPools->numOfBackupPools;531fm_vsp_params.backup_pools.pool_ids = p_FmVspEntry->p_FmVspEntryDriverParams->p_BackupBmPools->poolIds;532}533else534fm_vsp_params.backup_pools.num_backup_pools = 0;535536fm_vsp_params.fm_ext_pools.num_pools_used = p_FmVspEntry->extBufPools.numOfPoolsUsed;537fm_vsp_params.fm_ext_pools.ext_buf_pool = (struct fman_ext_pool_params*)&p_FmVspEntry->extBufPools.extBufPool;538fm_vsp_params.buf_margins = (struct fman_sp_buf_margins*)&p_FmVspEntry->bufMargins;539fm_vsp_params.int_context = (struct fman_sp_int_context_data_copy*)&p_FmVspEntry->intContext;540541/* no check on err - it was checked earlier */542FmVSPGetAbsoluteProfileId(p_FmVspEntry->h_Fm,543p_FmVspEntry->portType,544p_FmVspEntry->portId,545p_FmVspEntry->relativeProfileId,546&absoluteProfileId);547548ASSERT_COND(p_FmVspEntry->p_FmSpRegsBase);549ASSERT_COND(fm_vsp_params.int_context);550ASSERT_COND(fm_vsp_params.buf_margins);551ASSERT_COND((absoluteProfileId <= FM_VSP_MAX_NUM_OF_ENTRIES));552553/* Set all registers related to VSP */554fman_vsp_init(p_FmVspEntry->p_FmSpRegsBase, absoluteProfileId, &fm_vsp_params,FM_PORT_MAX_NUM_OF_EXT_POOLS, BM_MAX_NUM_OF_POOLS, FM_MAX_NUM_OF_PFC_PRIORITIES);555556p_FmVspEntry->absoluteSpId = absoluteProfileId;557558if (p_FmVspEntry->p_FmVspEntryDriverParams)559XX_Free(p_FmVspEntry->p_FmVspEntryDriverParams);560p_FmVspEntry->p_FmVspEntryDriverParams = NULL;561562return E_OK;563}564565t_Error FM_VSP_Free(t_Handle h_FmVsp)566{567t_FmVspEntry *p_FmVspEntry = (t_FmVspEntry *)h_FmVsp;568SANITY_CHECK_RETURN_ERROR(h_FmVsp, E_INVALID_HANDLE);569XX_Free(p_FmVspEntry);570return E_OK;571}572573t_Error FM_VSP_ConfigBufferPrefixContent(t_Handle h_FmVsp, t_FmBufferPrefixContent *p_FmBufferPrefixContent)574{575t_FmVspEntry *p_FmVspEntry = (t_FmVspEntry*)h_FmVsp;576577SANITY_CHECK_RETURN_ERROR(p_FmVspEntry, E_INVALID_HANDLE);578SANITY_CHECK_RETURN_ERROR(p_FmVspEntry->p_FmVspEntryDriverParams, E_INVALID_HANDLE);579580memcpy(&p_FmVspEntry->p_FmVspEntryDriverParams->bufferPrefixContent, p_FmBufferPrefixContent, sizeof(t_FmBufferPrefixContent));581/* if dataAlign was not initialized by user, we return to driver's default */582if (!p_FmVspEntry->p_FmVspEntryDriverParams->bufferPrefixContent.dataAlign)583p_FmVspEntry->p_FmVspEntryDriverParams->bufferPrefixContent.dataAlign = DEFAULT_FM_SP_bufferPrefixContent_dataAlign;584585return E_OK;586}587588t_Error FM_VSP_ConfigDmaSwapData(t_Handle h_FmVsp, e_FmDmaSwapOption swapData)589{590t_FmVspEntry *p_FmVspEntry = (t_FmVspEntry*)h_FmVsp;591592SANITY_CHECK_RETURN_ERROR(p_FmVspEntry, E_INVALID_HANDLE);593SANITY_CHECK_RETURN_ERROR(p_FmVspEntry->p_FmVspEntryDriverParams, E_INVALID_HANDLE);594595p_FmVspEntry->p_FmVspEntryDriverParams->dmaSwapData = swapData;596597return E_OK;598}599600t_Error FM_VSP_ConfigDmaIcCacheAttr(t_Handle h_FmVsp, e_FmDmaCacheOption intContextCacheAttr)601{602t_FmVspEntry *p_FmVspEntry = (t_FmVspEntry*)h_FmVsp;603604SANITY_CHECK_RETURN_ERROR(p_FmVspEntry, E_INVALID_HANDLE);605SANITY_CHECK_RETURN_ERROR(p_FmVspEntry->p_FmVspEntryDriverParams, E_INVALID_HANDLE);606607p_FmVspEntry->p_FmVspEntryDriverParams->dmaIntContextCacheAttr = intContextCacheAttr;608609return E_OK;610}611612t_Error FM_VSP_ConfigDmaHdrAttr(t_Handle h_FmVsp, e_FmDmaCacheOption headerCacheAttr)613{614t_FmVspEntry *p_FmVspEntry = (t_FmVspEntry*)h_FmVsp;615616SANITY_CHECK_RETURN_ERROR(p_FmVspEntry, E_INVALID_HANDLE);617SANITY_CHECK_RETURN_ERROR(p_FmVspEntry->p_FmVspEntryDriverParams, E_INVALID_HANDLE);618619p_FmVspEntry->p_FmVspEntryDriverParams->dmaHeaderCacheAttr = headerCacheAttr;620621return E_OK;622}623624t_Error FM_VSP_ConfigDmaScatterGatherAttr(t_Handle h_FmVsp, e_FmDmaCacheOption scatterGatherCacheAttr)625{626t_FmVspEntry *p_FmVspEntry = (t_FmVspEntry*)h_FmVsp;627628SANITY_CHECK_RETURN_ERROR(p_FmVspEntry, E_INVALID_HANDLE);629SANITY_CHECK_RETURN_ERROR(p_FmVspEntry->p_FmVspEntryDriverParams, E_INVALID_HANDLE);630631p_FmVspEntry->p_FmVspEntryDriverParams->dmaScatterGatherCacheAttr = scatterGatherCacheAttr;632633return E_OK;634}635636t_Error FM_VSP_ConfigDmaWriteOptimize(t_Handle h_FmVsp, bool optimize)637{638t_FmVspEntry *p_FmVspEntry = (t_FmVspEntry*)h_FmVsp;639640SANITY_CHECK_RETURN_ERROR(p_FmVspEntry, E_INVALID_HANDLE);641SANITY_CHECK_RETURN_ERROR(p_FmVspEntry->p_FmVspEntryDriverParams, E_INVALID_HANDLE);642643644p_FmVspEntry->p_FmVspEntryDriverParams->dmaWriteOptimize = optimize;645646return E_OK;647}648649t_Error FM_VSP_ConfigNoScatherGather(t_Handle h_FmVsp, bool noScatherGather)650{651t_FmVspEntry *p_FmVspEntry = (t_FmVspEntry*)h_FmVsp;652653SANITY_CHECK_RETURN_ERROR(p_FmVspEntry, E_INVALID_HANDLE);654SANITY_CHECK_RETURN_ERROR(p_FmVspEntry->p_FmVspEntryDriverParams, E_INVALID_HANDLE);655656657p_FmVspEntry->p_FmVspEntryDriverParams->noScatherGather = noScatherGather;658659return E_OK;660}661662t_Error FM_VSP_ConfigPoolDepletion(t_Handle h_FmVsp, t_FmBufPoolDepletion *p_BufPoolDepletion)663{664t_FmVspEntry *p_FmVspEntry = (t_FmVspEntry*)h_FmVsp;665666SANITY_CHECK_RETURN_ERROR(h_FmVsp, E_INVALID_HANDLE);667SANITY_CHECK_RETURN_ERROR(p_FmVspEntry->p_FmVspEntryDriverParams, E_INVALID_HANDLE);668SANITY_CHECK_RETURN_ERROR(p_BufPoolDepletion, E_INVALID_HANDLE);669670p_FmVspEntry->p_FmVspEntryDriverParams->p_BufPoolDepletion = (t_FmBufPoolDepletion *)XX_Malloc(sizeof(t_FmBufPoolDepletion));671if (!p_FmVspEntry->p_FmVspEntryDriverParams->p_BufPoolDepletion)672RETURN_ERROR(MAJOR, E_NO_MEMORY, ("p_BufPoolDepletion allocation failed"));673memcpy(p_FmVspEntry->p_FmVspEntryDriverParams->p_BufPoolDepletion, p_BufPoolDepletion, sizeof(t_FmBufPoolDepletion));674675return E_OK;676}677678t_Error FM_VSP_ConfigBackupPools(t_Handle h_FmVsp, t_FmBackupBmPools *p_BackupBmPools)679{680t_FmVspEntry *p_FmVspEntry = (t_FmVspEntry*)h_FmVsp;681682SANITY_CHECK_RETURN_ERROR(h_FmVsp, E_INVALID_HANDLE);683SANITY_CHECK_RETURN_ERROR(p_FmVspEntry->p_FmVspEntryDriverParams, E_INVALID_HANDLE);684SANITY_CHECK_RETURN_ERROR(p_BackupBmPools, E_INVALID_HANDLE);685686p_FmVspEntry->p_FmVspEntryDriverParams->p_BackupBmPools = (t_FmBackupBmPools *)XX_Malloc(sizeof(t_FmBackupBmPools));687if (!p_FmVspEntry->p_FmVspEntryDriverParams->p_BackupBmPools)688RETURN_ERROR(MAJOR, E_NO_MEMORY, ("p_BackupBmPools allocation failed"));689memcpy(p_FmVspEntry->p_FmVspEntryDriverParams->p_BackupBmPools, p_BackupBmPools, sizeof(t_FmBackupBmPools));690691return E_OK;692}693694uint32_t FM_VSP_GetBufferDataOffset(t_Handle h_FmVsp)695{696t_FmVspEntry *p_FmVspEntry = (t_FmVspEntry*)h_FmVsp;697698SANITY_CHECK_RETURN_VALUE(p_FmVspEntry, E_INVALID_HANDLE, 0);699SANITY_CHECK_RETURN_VALUE(!p_FmVspEntry->p_FmVspEntryDriverParams, E_INVALID_STATE, 0);700701return p_FmVspEntry->bufferOffsets.dataOffset;702}703704uint8_t * FM_VSP_GetBufferICInfo(t_Handle h_FmVsp, char *p_Data)705{706t_FmVspEntry *p_FmVspEntry = (t_FmVspEntry*)h_FmVsp;707708SANITY_CHECK_RETURN_VALUE(p_FmVspEntry, E_INVALID_HANDLE, NULL);709SANITY_CHECK_RETURN_VALUE(!p_FmVspEntry->p_FmVspEntryDriverParams, E_INVALID_STATE, NULL);710711if (p_FmVspEntry->bufferOffsets.pcdInfoOffset == ILLEGAL_BASE)712return NULL;713714return (uint8_t *)PTR_MOVE(p_Data, p_FmVspEntry->bufferOffsets.pcdInfoOffset);715}716717t_FmPrsResult * FM_VSP_GetBufferPrsResult(t_Handle h_FmVsp, char *p_Data)718{719t_FmVspEntry *p_FmVspEntry = (t_FmVspEntry*)h_FmVsp;720721SANITY_CHECK_RETURN_VALUE(p_FmVspEntry, E_INVALID_HANDLE, NULL);722SANITY_CHECK_RETURN_VALUE(!p_FmVspEntry->p_FmVspEntryDriverParams, E_INVALID_STATE, NULL);723724if (p_FmVspEntry->bufferOffsets.prsResultOffset == ILLEGAL_BASE)725return NULL;726727return (t_FmPrsResult *)PTR_MOVE(p_Data, p_FmVspEntry->bufferOffsets.prsResultOffset);728}729730uint64_t * FM_VSP_GetBufferTimeStamp(t_Handle h_FmVsp, char *p_Data)731{732t_FmVspEntry *p_FmVspEntry = (t_FmVspEntry*)h_FmVsp;733734SANITY_CHECK_RETURN_VALUE(p_FmVspEntry, E_INVALID_HANDLE, NULL);735SANITY_CHECK_RETURN_VALUE(!p_FmVspEntry->p_FmVspEntryDriverParams, E_INVALID_STATE, NULL);736737if (p_FmVspEntry->bufferOffsets.timeStampOffset == ILLEGAL_BASE)738return NULL;739740return (uint64_t *)PTR_MOVE(p_Data, p_FmVspEntry->bufferOffsets.timeStampOffset);741}742743uint8_t * FM_VSP_GetBufferHashResult(t_Handle h_FmVsp, char *p_Data)744{745t_FmVspEntry *p_FmVspEntry = (t_FmVspEntry*)h_FmVsp;746747SANITY_CHECK_RETURN_VALUE(p_FmVspEntry, E_INVALID_HANDLE, NULL);748SANITY_CHECK_RETURN_VALUE(!p_FmVspEntry->p_FmVspEntryDriverParams, E_INVALID_STATE, NULL);749750if (p_FmVspEntry->bufferOffsets.hashResultOffset == ILLEGAL_BASE)751return NULL;752753return (uint8_t *)PTR_MOVE(p_Data, p_FmVspEntry->bufferOffsets.hashResultOffset);754}755756#endif /* (DPAA_VERSION >= 11) */757758759