Path: blob/main/sys/contrib/ncsw/Peripherals/BM/bm.h
48375 views
/******************************************************************************12� 1995-2003, 2004, 2005-2011 Freescale Semiconductor, Inc.3All rights reserved.45This is proprietary source code of Freescale Semiconductor Inc.,6and its use is subject to the NetComm Device Drivers EULA.7The copyright notice above does not evidence any actual or intended8publication of such source code.910ALTERNATIVELY, redistribution and use in source and binary forms, with11or without modification, are permitted provided that the following12conditions are met:13* Redistributions of source code must retain the above copyright14notice, this list of conditions and the following disclaimer.15* Redistributions in binary form must reproduce the above copyright16notice, this list of conditions and the following disclaimer in the17documentation and/or other materials provided with the distribution.18* Neither the name of Freescale Semiconductor nor the19names of its contributors may be used to endorse or promote products20derived from this software without specific prior written permission.2122THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY23EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED24WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE25DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY26DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES27(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;28LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND29ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT30(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS31SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.32*3334**************************************************************************/35/******************************************************************************36@File bm.h3738@Description BM header39*//***************************************************************************/40#ifndef __BM_H41#define __BM_H4243#include "xx_common.h"44#include "bm_ext.h"45#include "mm_ext.h"4647#include "bman_private.h"48#include "bm_ipc.h"495051#define __ERR_MODULE__ MODULE_BM5253#define BM_NUM_OF_POOLS 6454#define BM_NUM_OF_PM 85556/**************************************************************************//**57@Description Exceptions58*//***************************************************************************/59#define BM_EX_INVALID_COMMAND 0x0000001060#define BM_EX_FBPR_THRESHOLD 0x0000000861#define BM_EX_MULTI_ECC 0x0000000462#define BM_EX_SINGLE_ECC 0x0000000263#define BM_EX_POOLS_AVAIL_STATE 0x000000016465#define GET_EXCEPTION_FLAG(bitMask, exception) \66switch(exception){ \67case e_BM_EX_INVALID_COMMAND: \68bitMask = BM_EX_INVALID_COMMAND; break; \69case e_BM_EX_FBPR_THRESHOLD: \70bitMask = BM_EX_FBPR_THRESHOLD; break; \71case e_BM_EX_SINGLE_ECC: \72bitMask = BM_EX_SINGLE_ECC; break; \73case e_BM_EX_MULTI_ECC: \74bitMask = BM_EX_MULTI_ECC; break; \75default: bitMask = 0;break; \76}7778/**************************************************************************//**79@Description defaults80*//***************************************************************************/81/* BM defaults */82#define DEFAULT_exceptions (BM_EX_INVALID_COMMAND |\83BM_EX_FBPR_THRESHOLD |\84BM_EX_MULTI_ECC |\85BM_EX_SINGLE_ECC )8687#define DEFAULT_fbprThreshold 088/* BM-Portal defaults */89#define DEFAULT_memAttr MEMORY_ATTR_CACHEABLE9091/* BM-Pool defaults */92#define DEFAULT_dynamicBpid TRUE93#define DEFAULT_useDepletion FALSE94#define DEFAULT_useStockpile FALSE95#define DEFAULT_numOfBufsPerCmd 89697/**************************************************************************//**98@Description Memory Mapped Registers99*//***************************************************************************/100101#if defined(__MWERKS__) && !defined(__GNUC__)102#pragma pack(push,1)103#endif /* defined(__MWERKS__) && ... */104#define MEM_MAP_START105106typedef _Packed struct107{108/* BMan Buffer Pool Configuration & Status Registers */109volatile uint32_t swdet[BM_NUM_OF_POOLS]; /**< S/W Portal depletion entry threshold */110volatile uint32_t hwdet[BM_NUM_OF_POOLS]; /**< H/W Portal depletion entry threshold */111volatile uint32_t swdxt[BM_NUM_OF_POOLS]; /**< S/W Portal depletion exit threshold */112volatile uint32_t hwdxt[BM_NUM_OF_POOLS]; /**< H/W Portal depletion exit threshold */113volatile uint32_t sdcnt[BM_NUM_OF_POOLS]; /**< S/W Portal depletion count */114volatile uint32_t hdcnt[BM_NUM_OF_POOLS]; /**< H/W Portal depletion count */115volatile uint32_t content[BM_NUM_OF_POOLS]; /**< Snapshot of buffer count in Pool */116volatile uint32_t hdptr[BM_NUM_OF_POOLS]; /**< Head Pointer for Pool's FBPR list. */117118/* Free Buffer Proxy Record (FBPR) Manager Query Registers */119volatile uint32_t fbpr_fpc; /**< FBPR Free Pool Count */120volatile uint32_t fbpr_fp_lwit; /**< FBPR Free Pool Low Watermark Interrupt Threshold */121volatile uint8_t res1[248]; /**< reserved */122123/* Performance Monitor (PM) Configuration Register */124volatile uint32_t cmd_pm_cfg[BM_NUM_OF_PM]; /**< BMan Command Performance Monitor configuration registers. */125volatile uint32_t fl_pm_cfg[BM_NUM_OF_PM]; /**< BMan Free List Performance Monitor configuration registers */126volatile uint8_t res2[192]; /**< reserved */127128/* BMan Error Capture Registers */129volatile uint32_t ecsr; /**< BMan Error Capture Status Register */130volatile uint32_t ecir; /**< BMan Error Capture Information Register */131volatile uint32_t eadr; /**< BMan Error Capture Address Register */132volatile uint8_t res3[4]; /**< reserved */133volatile uint32_t edata[8]; /**< BMan ECC Error Data Register */134volatile uint32_t sbet; /**< BMan Single Bit ECC Error Threshold Register */135volatile uint32_t efcr; /**< BMan Error Fetch Capture Register */136volatile uint32_t efar; /**< BMan Error Fetch Address Register */137volatile uint8_t res4[68]; /**< reserved */138volatile uint32_t sbec0; /**< BMan Single Bit ECC Error Count 0 Register */139volatile uint32_t sbec1; /**< BMan Single Bit ECC Error Count 1 Register */140volatile uint8_t res5[368]; /**< reserved */141142/* BMan ID/Revision Registers */143volatile uint32_t ip_rev_1; /**< BMan IP Block Revision 1 register */144volatile uint32_t ip_rev_2; /**< BMan IP Block Revision 2 register */145146/* CoreNet Initiator Interface Memory Window Configuration Registers */147volatile uint32_t fbpr_bare; /**< Data Structure Extended Base Address Register */148volatile uint32_t fbpr_bar; /**< Data Structure Base Address Register */149volatile uint8_t res6[8]; /**< reserved */150volatile uint32_t fbpr_ar; /**< Data Structure Attributes Register */151volatile uint8_t res7[240]; /**< reserved */152volatile uint32_t srcidr; /**< BMan Source ID Register */153volatile uint32_t liodnr; /**< BMan Logical I/O Device Number Register */154volatile uint8_t res8[244]; /**< reserved */155156/* BMan Interrupt and Error Registers */157volatile uint32_t err_isr; /**< BMan Error Interrupt Status Register */158volatile uint32_t err_ier; /**< BMan Error Interrupt Enable Register */159volatile uint32_t err_isdr; /**< BMan Error Interrupt Status Disable Register */160volatile uint32_t err_iir; /**< BMan Error Interrupt Inhibit Register */161volatile uint32_t err_ifr; /**< BMan Error Interrupt Force Register */162} _PackedType t_BmRegs;163164#define MEM_MAP_END165#if defined(__MWERKS__) && !defined(__GNUC__)166#pragma pack(pop)167#endif /* defined(__MWERKS__) && ... */168169/**************************************************************************//**170@Description General defines171*//***************************************************************************/172#define MODULE_NAME_SIZE 30173174#define FBPR_ENTRY_SIZE 64 /* 64 bytes */175176/* Compilation constants */177#define RCR_THRESH 2 /* reread h/w CI when running out of space */178#define RCR_ITHRESH 4 /* if RCR congests, interrupt threshold */179180/* Lock/unlock portals, subject to "UNLOCKED" flag */181#define NCSW_PLOCK(p) ((t_BmPortal*)(p))->irq_flags = XX_DisableAllIntr()182#define PUNLOCK(p) XX_RestoreAllIntr(((t_BmPortal*)(p))->irq_flags)183184#define BM_RCR_RING 0185#define BM_NUM_OF_RINGS 1186187/**************************************************************************//**188@Description Register defines189*//***************************************************************************/190191/* masks */192#define REV1_MAJOR_MASK 0x0000FF00193#define REV1_MINOR_MASK 0x000000FF194195#define REV2_INTEG_MASK 0x00FF0000196#define REV2_ERR_MASK 0x0000FF00197#define REV2_CFG_MASK 0x000000FF198199#define AR_PRIORITY 0x40000000200#define AR_SIZE_MASK 0x0000003f201202/* shifts */203#define REV1_MAJOR_SHIFT 8204#define REV1_MINOR_SHIFT 0205206#define REV2_INTEG_SHIFT 16207#define REV2_ERR_SHIFT 8208#define REV2_CFG_SHIFT 0209210#define AR_SIZE_SHIFT 0211212typedef uint8_t bmRingType_t;213typedef uint8_t (t_BmUpdateCb)(struct bm_portal *p_BmPortalLow);214typedef void (t_BmPrefetchCb)(struct bm_portal *p_BmPortalLow);215typedef void (t_BmCommitCb)(struct bm_portal *p_BmPortalLow, uint8_t myverb);216217typedef struct {218bool useStockpile; /**< */219bool dynamicBpid; /**< boolean indicates use of dynamic Bpid */220bool useDepletion; /**< boolean indicates use of depletion */221uint32_t depletionThresholds[MAX_DEPLETION_THRESHOLDS]; /**< depletion-entry/exit thresholds, if useThresholds is set. NB:222this is only allowed if useThresholds is used and223when run in the control plane (which controls Bman CCSR) */224} t_BmPoolDriverParams;225226typedef struct BmPool {227uint8_t bpid; /**< index of the buffer pool to encapsulate (0-63) */228t_Handle h_Bm;229t_Handle h_BmPortal;230bool shadowMode;231uint32_t numOfBuffers; /**< Number of buffers use by this pool */232t_BufferPoolInfo bufferPoolInfo; /**< Data buffers pool information */233uint32_t flags; /**< bit-mask of BMAN_POOL_FLAG_*** options */234t_Handle h_App; /**< opaque user value passed as a parameter to 'cb' */235t_BmDepletionCallback *f_Depletion; /**< depletion-entry/exit callback, if BMAN_POOL_FLAG_DEPLETION is set */236uint32_t swDepletionCount;237uint32_t hwDepletionCount;238/* stockpile state - NULL unless BMAN_POOL_FLAG_STOCKPILE is set */239struct bm_buffer *sp;240uint16_t spFill;241uint8_t spBufsCmd;242uint16_t spMaxBufs;243uint16_t spMinBufs;244bool noBuffCtxt;245246t_BmPoolDriverParams *p_BmPoolDriverParams;247} t_BmPool;248249typedef struct {250t_BmUpdateCb *f_BmUpdateCb;251t_BmPrefetchCb *f_BmPrefetchCb;252t_BmCommitCb *f_BmCommitCb;253} t_BmPortalCallbacks;254255typedef struct {256uint32_t hwExtStructsMemAttr;257struct bman_depletion mask;258} t_BmPortalDriverParams;259260typedef struct {261t_Handle h_Bm;262struct bm_portal *p_BmPortalLow;263t_BmPortalCallbacks cbs[BM_NUM_OF_RINGS];264uintptr_t irq;265int cpu; /* This is used for any "core-affine" portals, ie. default portals266* associated to the corresponding cpu. -1 implies that there is no core267* affinity configured. */268struct bman_depletion pools[2]; /**< 2-element array. pools[0] is mask, pools[1] is snapshot. */269uint32_t flags; /**< BMAN_PORTAL_FLAG_*** - static, caller-provided */270uint32_t irq_flags;271int thresh_set;272uint32_t slowpoll;273uint32_t rcrProd; /**< The wrap-around rcr_[prod|cons] counters are used to support BMAN_RELEASE_FLAG_WAIT_SYNC. */274uint32_t rcrCons;275/**< 64-entry hash-table of pool objects that are tracking depletion276* entry/exit (ie. BMAN_POOL_FLAG_DEPLETION). This isn't fast-path, so277* we're not fussy about cache-misses and so forth - whereas the above278* members should all fit in one cacheline.279* BTW, with BM_MAX_NUM_OF_POOLS entries in the hash table and BM_MAX_NUM_OF_POOLS buffer pools to track,280* you'll never guess the hash-function ... */281t_BmPool *depletionPoolsTable[BM_MAX_NUM_OF_POOLS];282t_BmPortalDriverParams *p_BmPortalDriverParams;283} t_BmPortal;284285typedef struct {286uint8_t partBpidBase;287uint8_t partNumOfPools;288uint32_t totalNumOfBuffers; /**< total number of buffers */289uint32_t fbprMemPartitionId;290uint32_t fbprThreshold;291uint16_t liodn;292} t_BmDriverParams;293294typedef struct {295uint8_t guestId;296t_Handle h_BpidMm;297t_Handle h_SpinLock;298t_Handle h_Portals[DPAA_MAX_NUM_OF_SW_PORTALS];299t_Handle h_Session;300char moduleName[MODULE_NAME_SIZE];301t_BmRegs *p_BmRegs;302void *p_FbprBase;303uint32_t exceptions;304t_BmExceptionsCallback *f_Exception;305t_Handle h_App;306uintptr_t errIrq; /**< error interrupt line; NO_IRQ if interrupts not used */307t_BmDriverParams *p_BmDriverParams;308} t_Bm;309310static __inline__ void BmSetPortalHandle(t_Handle h_Bm, t_Handle h_Portal, e_DpaaSwPortal portalId)311{312ASSERT_COND(!((t_Bm*)h_Bm)->h_Portals[portalId] || !h_Portal);313((t_Bm*)h_Bm)->h_Portals[portalId] = h_Portal;314}315316static __inline__ t_Handle BmGetPortalHandle(t_Handle h_Bm)317{318t_Bm *p_Bm = (t_Bm*)h_Bm;319ASSERT_COND(p_Bm);320return p_Bm->h_Portals[CORE_GetId()];321}322323static __inline__ uint8_t BmUpdate(t_BmPortal *p_BmPortal, bmRingType_t type)324{325return p_BmPortal->cbs[type].f_BmUpdateCb(p_BmPortal->p_BmPortalLow);326}327328static __inline__ void BmPrefetch(t_BmPortal *p_BmPortal, bmRingType_t type)329{330if (p_BmPortal->cbs[type].f_BmPrefetchCb)331p_BmPortal->cbs[type].f_BmPrefetchCb(p_BmPortal->p_BmPortalLow);332}333334static __inline__ void BmCommit(t_BmPortal *p_BmPortal, bmRingType_t type, uint8_t myverb)335{336p_BmPortal->cbs[type].f_BmCommitCb(p_BmPortal->p_BmPortalLow, myverb);337}338339static __inline__ uint32_t BmBpidGet(t_Bm *p_Bm, bool force, uint32_t base)340{341uint64_t ans, size = 1;342uint64_t alignment = 1;343344if (force)345{346if (MM_InRange(p_Bm->h_BpidMm, (uint64_t)base))347{348ans = MM_GetForce(p_Bm->h_BpidMm,349base,350size,351"BM BPID MEM");352ans = base;353}354else if (p_Bm->h_Session)355{356t_BmIpcMsg msg;357t_BmIpcReply reply;358uint32_t replyLength;359t_BmIpcBpidParams ipcBpid;360t_Error errCode = E_OK;361362memset(&msg, 0, sizeof(t_BmIpcMsg));363memset(&reply, 0, sizeof(t_BmIpcReply));364ipcBpid.bpid = (uint8_t)base;365msg.msgId = BM_FORCE_BPID;366memcpy(msg.msgBody, &ipcBpid, sizeof(t_BmIpcBpidParams));367replyLength = sizeof(uint32_t) + sizeof(uint32_t);368if ((errCode = XX_IpcSendMessage(p_Bm->h_Session,369(uint8_t*)&msg,370sizeof(msg.msgId) + sizeof(t_BmIpcBpidParams),371(uint8_t*)&reply,372&replyLength,373NULL,374NULL)) != E_OK)375{376REPORT_ERROR(MAJOR, errCode, NO_MSG);377return (uint32_t)ILLEGAL_BASE;378}379if (replyLength != (sizeof(uint32_t) + sizeof(uint32_t)))380{381REPORT_ERROR(MAJOR, E_INVALID_VALUE, ("IPC reply length mismatch"));382return (uint32_t)ILLEGAL_BASE;383}384memcpy((uint8_t*)&ans, reply.replyBody, sizeof(uint32_t));385}386else387{388DBG(WARNING, ("No Ipc - can't validate bpid."));389ans = base;390}391}392else393ans = MM_Get(p_Bm->h_BpidMm,394size,395alignment,396"BM BPID MEM");397KASSERT(ans < UINT32_MAX, ("Oops, %jx > UINT32_MAX!\n", (uintmax_t)ans));398return (uint32_t)ans;399}400401static __inline__ t_Error BmBpidPut(t_Bm *p_Bm, uint32_t base)402{403if (MM_InRange(p_Bm->h_BpidMm, (uint64_t)base))404{405if (MM_Put(p_Bm->h_BpidMm, (uint64_t)base) != base)406return E_OK;407else408return ERROR_CODE(E_NOT_FOUND);409}410else if (p_Bm->h_Session)411{412t_BmIpcMsg msg;413t_BmIpcBpidParams ipcBpid;414t_Error errCode = E_OK;415416memset(&msg, 0, sizeof(t_BmIpcMsg));417ipcBpid.bpid = (uint8_t)base;418msg.msgId = BM_PUT_BPID;419memcpy(msg.msgBody, &ipcBpid, sizeof(t_BmIpcBpidParams));420if ((errCode = XX_IpcSendMessage(p_Bm->h_Session,421(uint8_t*)&msg,422sizeof(msg.msgId) + sizeof(t_BmIpcBpidParams),423NULL,424NULL,425NULL,426NULL)) != E_OK)427RETURN_ERROR(MAJOR, errCode, NO_MSG);428}429else430DBG(WARNING, ("No Ipc - can't validate bpid."));431return E_OK;432}433434/****************************************/435/* Inter-Module functions */436/****************************************/437typedef enum e_BmInterModuleCounters {438e_BM_IM_COUNTERS_FBPR = 0,439e_BM_IM_COUNTERS_POOL_CONTENT,440e_BM_IM_COUNTERS_POOL_SW_DEPLETION,441e_BM_IM_COUNTERS_POOL_HW_DEPLETION442} e_BmInterModuleCounters;443444445t_Error BmSetPoolThresholds(t_Handle h_Bm, uint8_t bpid, const uint32_t *thresholds);446t_Error BmUnSetPoolThresholds(t_Handle h_Bm, uint8_t bpid);447uint8_t BmPortalAcquire(t_Handle h_BmPortal, uint8_t bpid, struct bm_buffer *bufs, uint8_t num);448t_Error BmPortalRelease(t_Handle h_BmPortal, uint8_t bpid, struct bm_buffer *bufs, uint8_t num, uint32_t flags);449t_Error BmPortalQuery(t_Handle h_BmPortal, struct bman_depletion *p_Pools, bool depletion);450uint32_t BmGetCounter(t_Handle h_Bm, e_BmInterModuleCounters counter, uint8_t bpid);451t_Error BmGetRevision(t_Handle h_Bm, t_BmRevisionInfo *p_BmRevisionInfo);452453454#endif /* __BM_H */455456457