diff --git a/sys/arm64/conf/GATEWAY b/sys/arm64/conf/GATEWAY index 11f83e117d8..a88521fb994 100644 --- a/sys/arm64/conf/GATEWAY +++ b/sys/arm64/conf/GATEWAY @@ -52,6 +52,9 @@ device pca954x # NXP PCA9545/9546/9548 I2C mux/switch # GPIO power-off (STUSB4500 USB-C PD reset) device gpiopower +# DPAA1 (FMan/QMan/BMan) -- NXP LS1046A packet acceleration +include "dpaa/config.dpaa_arm64" +device dpaa device sff # Small Form Factor Transceivers (SFP+) # caam is built as an out-of-tree module in opnsense-deps/drivers/caam/ diff --git a/sys/arm64/conf/dpaa/files.dpaa_arm64 b/sys/arm64/conf/dpaa/files.dpaa_arm64 index 16ce67284eb..a27432e3545 100644 --- a/sys/arm64/conf/dpaa/files.dpaa_arm64 +++ b/sys/arm64/conf/dpaa/files.dpaa_arm64 @@ -4,3 +4,88 @@ # - core.c -> core_arm64.c (ARM64 CORE_GetId etc.) # - xx.c -> xx_arm64.c (no PowerPC ccsrbar/LAW/TLB deps) # - if_dtsec* excluded (LS1046A uses mEMAC, not dTSEC) + +contrib/ncsw/etc/error.c optional dpaa \ + no-depend compile-with "${DPAA_COMPILE_CMD}" +contrib/ncsw/etc/ncsw_list.c optional dpaa \ + no-depend compile-with "${DPAA_COMPILE_CMD}" +contrib/ncsw/etc/ncsw_memcpy.c optional dpaa \ + no-depend compile-with "${DPAA_COMPILE_CMD}" +contrib/ncsw/etc/mm.c optional dpaa \ + no-depend compile-with "${DPAA_COMPILE_CMD}" +contrib/ncsw/etc/ncsw_mem.c optional dpaa \ + no-depend compile-with "${DPAA_COMPILE_CMD}" +contrib/ncsw/etc/sprint.c optional dpaa \ + no-depend compile-with "${DPAA_COMPILE_CMD}" +contrib/ncsw/Peripherals/BM/bm.c optional dpaa \ + no-depend compile-with "${DPAA_COMPILE_CMD}" +contrib/ncsw/Peripherals/BM/bman_low.c optional dpaa \ + no-depend compile-with "${DPAA_COMPILE_CMD}" +contrib/ncsw/Peripherals/BM/bm_pool.c optional dpaa \ + no-depend compile-with "${DPAA_COMPILE_CMD}" +contrib/ncsw/Peripherals/BM/bm_portal.c optional dpaa \ + no-depend compile-with "${DPAA_COMPILE_CMD}" +contrib/ncsw/Peripherals/FM/SP/fm_sp.c optional dpaa \ + no-depend compile-with "${DPAA_COMPILE_CMD} -Wno-enum-conversion" +contrib/ncsw/Peripherals/FM/SP/fman_sp.c optional dpaa \ + no-depend compile-with "${DPAA_COMPILE_CMD}" +contrib/ncsw/Peripherals/FM/Rtc/fm_rtc.c optional dpaa \ + no-depend compile-with "${DPAA_COMPILE_CMD}" +contrib/ncsw/Peripherals/FM/Rtc/fman_rtc.c optional dpaa \ + no-depend compile-with "${DPAA_COMPILE_CMD}" +contrib/ncsw/Peripherals/FM/Port/fman_port.c optional dpaa \ + no-depend compile-with "${DPAA_COMPILE_CMD}" +contrib/ncsw/Peripherals/FM/Port/fm_port.c optional dpaa \ + no-depend compile-with "${DPAA_COMPILE_CMD}" +contrib/ncsw/Peripherals/FM/Port/fm_port_im.c optional dpaa \ + no-depend compile-with "${DPAA_COMPILE_CMD}" +contrib/ncsw/Peripherals/FM/Pcd/fm_cc.c optional dpaa \ + no-depend compile-with "${DPAA_COMPILE_CMD}" +contrib/ncsw/Peripherals/FM/Pcd/fm_ehash.c optional dpaa \ + no-depend compile-with "${DPAA_COMPILE_CMD}" +contrib/ncsw/Peripherals/FM/Pcd/fm_kg.c optional dpaa \ + no-depend compile-with "${DPAA_COMPILE_CMD}" +contrib/ncsw/Peripherals/FM/Pcd/fman_kg.c optional dpaa \ + no-depend compile-with "${DPAA_COMPILE_CMD}" +contrib/ncsw/Peripherals/FM/Pcd/fm_manip.c optional dpaa \ + no-depend compile-with "${DPAA_COMPILE_CMD}" +contrib/ncsw/Peripherals/FM/Pcd/fm_pcd.c optional dpaa \ + no-depend compile-with "${DPAA_COMPILE_CMD}" +contrib/ncsw/Peripherals/FM/Pcd/fm_plcr.c optional dpaa \ + no-depend compile-with "${DPAA_COMPILE_CMD}" +contrib/ncsw/Peripherals/FM/Pcd/fm_prs.c optional dpaa \ + no-depend compile-with "${DPAA_COMPILE_CMD}" +contrib/ncsw/Peripherals/FM/Pcd/fman_prs.c optional dpaa \ + no-depend compile-with "${DPAA_COMPILE_CMD}" +contrib/ncsw/Peripherals/FM/Pcd/fm_replic.c optional dpaa \ + no-depend compile-with "${DPAA_COMPILE_CMD}" +# mEMAC — the MAC type used by LS1046A FManv3 (DPAA_VERSION >= 11) +contrib/ncsw/Peripherals/FM/MAC/memac.c optional dpaa \ + no-depend compile-with "${DPAA_COMPILE_CMD}" +contrib/ncsw/Peripherals/FM/MAC/memac_mii_acc.c optional dpaa \ + no-depend compile-with "${DPAA_COMPILE_CMD}" +contrib/ncsw/Peripherals/FM/MAC/fman_memac.c optional dpaa \ + no-depend compile-with "${DPAA_COMPILE_CMD}" +contrib/ncsw/Peripherals/FM/MAC/fman_memac_mii_acc.c optional dpaa \ + no-depend compile-with "${DPAA_COMPILE_CMD}" +contrib/ncsw/Peripherals/FM/MAC/fm_mac.c optional dpaa \ + no-depend compile-with "${DPAA_COMPILE_CMD}" +contrib/ncsw/Peripherals/FM/HC/hc.c optional dpaa \ + no-depend compile-with "${DPAA_COMPILE_CMD}" +contrib/ncsw/Peripherals/FM/fm_muram.c optional dpaa \ + no-depend compile-with "${DPAA_COMPILE_CMD}" +contrib/ncsw/Peripherals/FM/fm_ncsw.c optional dpaa \ + no-depend compile-with "${DPAA_COMPILE_CMD} -Wno-unused-but-set-variable" +contrib/ncsw/Peripherals/FM/fman_ncsw.c optional dpaa \ + no-depend compile-with "${DPAA_COMPILE_CMD} ${NO_WMISLEADING_INDENTATION}" +contrib/ncsw/Peripherals/QM/qm.c optional dpaa \ + no-depend compile-with "${DPAA_COMPILE_CMD}" +contrib/ncsw/Peripherals/QM/qm_portal_fqr.c optional dpaa \ + no-depend compile-with "${DPAA_COMPILE_CMD}" +contrib/ncsw/user/env/stdlib.c optional dpaa \ + no-depend compile-with "${DPAA_COMPILE_CMD}" +# ARM64 replacements for xx.c and core.c (no PowerPC deps) +contrib/ncsw/user/env/xx_arm64.c optional dpaa \ + no-depend compile-with "${DPAA_COMPILE_CMD}" +contrib/ncsw/user/env/core_arm64.c optional dpaa \ + no-depend compile-with "${DPAA_COMPILE_CMD}" diff --git a/sys/contrib/ncsw/Peripherals/BM/bm.c b/sys/contrib/ncsw/Peripherals/BM/bm.c index 646e38fb969..09bd8ade79e 100644 --- a/sys/contrib/ncsw/Peripherals/BM/bm.c +++ b/sys/contrib/ncsw/Peripherals/BM/bm.c @@ -441,7 +441,7 @@ t_Error BmGetRevision(t_Handle h_Bm, t_BmRevisionInfo *p_BmRevisionInfo) static void FreeInitResources(t_Bm *p_Bm) { - if (p_Bm->p_FbprBase) + if (p_Bm->p_FbprBase && !p_Bm->fbprExternal) XX_FreeSmart(p_Bm->p_FbprBase); if (p_Bm->h_Session) XX_IpcFreeSession(p_Bm->h_Session); @@ -491,6 +491,8 @@ t_Handle BM_Config(t_BmParam *p_BmParam) p_Bm->p_BmDriverParams->fbprMemPartitionId = p_BmParam->fbprMemPartitionId; p_Bm->p_BmDriverParams->fbprThreshold = DEFAULT_fbprThreshold; p_Bm->p_BmDriverParams->liodn = p_BmParam->liodn; + p_Bm->p_BmDriverParams->p_FbprBaseExt = p_BmParam->p_FbprBase; + p_Bm->p_BmDriverParams->fbprSizeExt = p_BmParam->fbprSize; } /* build the BM partition IPC address */ @@ -534,26 +536,50 @@ t_Error BM_Init(t_Handle h_Bm) WRITE_UINT32(p_Bm->p_BmRegs->liodnr, (uint16_t)p_Bm->p_BmDriverParams->liodn); /* FBPR memory */ - dsSize = (uint32_t)(p_Bm->p_BmDriverParams->totalNumOfBuffers * (FBPR_ENTRY_SIZE / 8)); - LOG2(dsSize, exp); - if (!POWER_OF_2(dsSize)) (exp++); - dsSize = (uint32_t)(1 << exp); - if (dsSize < (4*KILOBYTE)) + if (p_Bm->p_BmDriverParams->p_FbprBaseExt) { - dsSize = (4*KILOBYTE); + /* Use pre-allocated FBPR memory from caller */ + p_Bm->p_FbprBase = p_Bm->p_BmDriverParams->p_FbprBaseExt; + p_Bm->fbprExternal = TRUE; + dsSize = p_Bm->p_BmDriverParams->fbprSizeExt; LOG2(dsSize, exp); + if (!POWER_OF_2(dsSize)) (exp++); + dsSize = (uint32_t)(1 << exp); } - p_Bm->p_FbprBase = XX_MallocSmart(dsSize, (int)p_Bm->p_BmDriverParams->fbprMemPartitionId, dsSize); - if (!p_Bm->p_FbprBase) + else { - FreeInitResources(p_Bm); - RETURN_ERROR(MAJOR, E_NO_MEMORY, ("FBPR obj!!!")); + dsSize = (uint32_t)(p_Bm->p_BmDriverParams->totalNumOfBuffers * (FBPR_ENTRY_SIZE / 8)); + LOG2(dsSize, exp); + if (!POWER_OF_2(dsSize)) (exp++); + dsSize = (uint32_t)(1 << exp); + if (dsSize < (4*KILOBYTE)) + { + dsSize = (4*KILOBYTE); + LOG2(dsSize, exp); + } + p_Bm->p_FbprBase = XX_MallocSmart(dsSize, (int)p_Bm->p_BmDriverParams->fbprMemPartitionId, dsSize); + if (!p_Bm->p_FbprBase) + { + FreeInitResources(p_Bm); + RETURN_ERROR(MAJOR, E_NO_MEMORY, ("FBPR obj!!!")); + } } phyAddr = XX_VirtToPhys(p_Bm->p_FbprBase); WRITE_UINT32(p_Bm->p_BmRegs->fbpr_bare, ((uint32_t)(phyAddr >> 32) & 0xffff)); WRITE_UINT32(p_Bm->p_BmRegs->fbpr_bar, (uint32_t)phyAddr); WRITE_UINT32(p_Bm->p_BmRegs->fbpr_ar, (exp - 1)); + /* Readback and verify FBPR BAR programming */ + { + uint32_t rb_bare = GET_UINT32(p_Bm->p_BmRegs->fbpr_bare); + uint32_t rb_bar = GET_UINT32(p_Bm->p_BmRegs->fbpr_bar); + uint32_t rb_ar = GET_UINT32(p_Bm->p_BmRegs->fbpr_ar); + XX_Print("BM FBPR: va=%p phys=0x%08x%08x bare=0x%08x bar=0x%08x ar=0x%08x (exp=%d, size=0x%x)\n", + p_Bm->p_FbprBase, + (uint32_t)(phyAddr >> 32), (uint32_t)phyAddr, + rb_bare, rb_bar, rb_ar, exp, dsSize); + } + WRITE_UINT32(p_Bm->p_BmRegs->fbpr_fp_lwit, p_Bm->p_BmDriverParams->fbprThreshold); WRITE_UINT32(p_Bm->p_BmRegs->err_isr, p_Bm->exceptions); WRITE_UINT32(p_Bm->p_BmRegs->err_ier, p_Bm->exceptions); diff --git a/sys/contrib/ncsw/Peripherals/BM/bm.h b/sys/contrib/ncsw/Peripherals/BM/bm.h index 09870cb0715..7fbd30417b4 100644 --- a/sys/contrib/ncsw/Peripherals/BM/bm.h +++ b/sys/contrib/ncsw/Peripherals/BM/bm.h @@ -290,6 +290,8 @@ typedef struct { uint32_t fbprMemPartitionId; uint32_t fbprThreshold; uint16_t liodn; + void *p_FbprBaseExt; /* Pre-allocated FBPR, or NULL */ + uint32_t fbprSizeExt; } t_BmDriverParams; typedef struct { @@ -301,6 +303,7 @@ typedef struct { char moduleName[MODULE_NAME_SIZE]; t_BmRegs *p_BmRegs; void *p_FbprBase; + bool fbprExternal; /* FBPR memory externally allocated */ uint32_t exceptions; t_BmExceptionsCallback *f_Exception; t_Handle h_App; diff --git a/sys/contrib/ncsw/Peripherals/BM/bm_pool.c b/sys/contrib/ncsw/Peripherals/BM/bm_pool.c index c908846760a..83c0c4b337d 100644 --- a/sys/contrib/ncsw/Peripherals/BM/bm_pool.c +++ b/sys/contrib/ncsw/Peripherals/BM/bm_pool.c @@ -61,6 +61,7 @@ static void depletion_link(t_BmPool *p_BmPool) NCSW_PLOCK(p_Portal); p_Portal->depletionPoolsTable[p_BmPool->bpid] = p_BmPool; + bman_depletion_set(&p_Portal->pools[0], (uint8_t)p_BmPool->bpid); bm_isr_bscn_mask(p_Portal->p_BmPortalLow, (uint8_t)p_BmPool->bpid, 1); PUNLOCK(p_Portal); } @@ -71,6 +72,7 @@ static void depletion_unlink(t_BmPool *p_BmPool) NCSW_PLOCK(p_Portal); p_Portal->depletionPoolsTable[p_BmPool->bpid] = NULL; + bman_depletion_unset(&p_Portal->pools[0], (uint8_t)p_BmPool->bpid); bm_isr_bscn_mask(p_Portal->p_BmPortalLow, (uint8_t)p_BmPool->bpid, 0); PUNLOCK(p_Portal); } diff --git a/sys/contrib/ncsw/Peripherals/BM/bm_portal.c b/sys/contrib/ncsw/Peripherals/BM/bm_portal.c index 34b48e38b4d..ff42e31fc20 100644 --- a/sys/contrib/ncsw/Peripherals/BM/bm_portal.c +++ b/sys/contrib/ncsw/Peripherals/BM/bm_portal.c @@ -381,16 +381,23 @@ t_Error BmPortalRelease(t_Handle h_BmPortal, if (!r) { if (flags & BMAN_RELEASE_FLAG_WAIT) { t_Error ret = wait_rel_start(p_BmPortal, &r, flags); - if (ret) + if (ret) { + printf("BmPortalRelease: wait_rel_start FAILED E_BUSY, avail=%u, " + "rcr.ci=%u, rcr.cursor=%p, rcr.vbit=%u\n", + bm_rcr_get_avail(p_BmPortal->p_BmPortalLow), + p_BmPortal->p_BmPortalLow->rcr.ci, + p_BmPortal->p_BmPortalLow->rcr.cursor, + p_BmPortal->p_BmPortalLow->rcr.vbit); return ret; + } } else return ERROR_CODE(E_BUSY); ASSERT_COND(r != NULL); } r->bpid = bpid; for (i = 0; i < num; i++) { - r->bufs[i].hi = bufs[i].hi; - r->bufs[i].lo = bufs[i].lo; + WRITE_UINT16(r->bufs[i].hi, bufs[i].hi); + WRITE_UINT32(r->bufs[i].lo, bufs[i].lo); } /* Issue the release command and wait for sync if requested. NB: the * commit can't fail, only waiting can. Don't propagate any failure if a @@ -423,8 +430,8 @@ uint8_t BmPortalAcquire(t_Handle h_BmPortal, ASSERT_COND(num <= 8); while (num--) { bufs[num].bpid = bpid; - bufs[num].hi = mcr->acquire.bufs[num].hi; - bufs[num].lo = mcr->acquire.bufs[num].lo; + bufs[num].hi = GET_UINT16(mcr->acquire.bufs[num].hi); + bufs[num].lo = GET_UINT32(mcr->acquire.bufs[num].lo); } PUNLOCK(p_BmPortal); return ret; @@ -495,7 +502,7 @@ t_Handle BM_PORTAL_Config(t_BmPortalParam *p_BmPortalParam) p_BmPortal->h_Bm = p_BmPortalParam->h_Bm; p_BmPortal->p_BmPortalDriverParams->hwExtStructsMemAttr = DEFAULT_memAttr; - bman_depletion_fill(&p_BmPortal->p_BmPortalDriverParams->mask); + bman_depletion_init(&p_BmPortal->p_BmPortalDriverParams->mask); return p_BmPortal; } diff --git a/sys/contrib/ncsw/Peripherals/BM/bman_low.c b/sys/contrib/ncsw/Peripherals/BM/bman_low.c index 818e62df31c..fb48dc1df3b 100644 --- a/sys/contrib/ncsw/Peripherals/BM/bman_low.c +++ b/sys/contrib/ncsw/Peripherals/BM/bman_low.c @@ -40,6 +40,7 @@ *//***************************************************************************/ #include #include +#include #include #include "std_ext.h" @@ -55,15 +56,28 @@ /***************************/ /* Cache-inhibited register offsets */ +#if defined(__aarch64__) +/* + * ARM64 Layerscape (LS1046A etc.): CI space is 16KB per portal. + * Register offsets are spread out compared to PowerPC. + * See Linux drivers/soc/fsl/qbman/bman.c for reference. + */ +#define REG_RCR_PI_CINH 0x3000 +#define REG_RCR_CI_CINH 0x3100 +#define REG_RCR_ITR 0x3200 +#define REG_CFG 0x3300 +#define REG_SCN(n) (0x3400 + ((n) << 6)) +#define REG_ISR 0x3e00 +#define BM_ISR_SHIFT 6 /* ISR/IER/ISDR/IIR stride: 64 bytes */ +#else /* PowerPC */ #define REG_RCR_PI_CINH 0x0000 #define REG_RCR_CI_CINH 0x0004 #define REG_RCR_ITR 0x0008 #define REG_CFG 0x0100 #define REG_SCN(n) (0x0200 + ((n) << 2)) #define REG_ISR 0x0e00 -#define REG_IER 0x0e04 -#define REG_ISDR 0x0e08 -#define REG_IIR 0x0e0c +#define BM_ISR_SHIFT 2 /* ISR/IER/ISDR/IIR stride: 4 bytes */ +#endif /* Cache-enabled register offsets */ #define CL_CR 0x0000 @@ -258,9 +272,17 @@ struct bm_rcr_entry *bm_rcr_pend_and_next(struct bm_portal *portal, uint8_t myve void bm_rcr_pci_commit(struct bm_portal *portal, uint8_t myverb) { register struct bm_rcr *rcr = &portal->rcr; + struct bm_rcr_entry *rcursor; ASSERT_COND(rcr->busy); ASSERT_COND(rcr->pmode == e_BmPortalPCI); - rcr->cursor->__dont_write_directly__verb = (uint8_t)(myverb | rcr->vbit); + rcursor = rcr->cursor; + rcursor->__dont_write_directly__verb = (uint8_t)(myverb | rcr->vbit); + /* + * ARM64: The portal hardware cannot snoop the CPU cache via CCI-400. + * Explicitly flush the entry from cache to portal CE memory before + * writing PI. On PowerPC the CCF provides hardware coherency. + */ + dcbf_64(rcursor); RCR_INC(rcr); rcr->available--; mb(); @@ -298,7 +320,7 @@ void bm_rcr_pvb_commit(struct bm_portal *portal, uint8_t myverb) struct bm_rcr_entry *rcursor; ASSERT_COND(rcr->busy); ASSERT_COND(rcr->pmode == e_BmPortalPVB); - rmb(); + wmb(); rcursor = rcr->cursor; rcursor->__dont_write_directly__verb = (uint8_t)(myverb | rcr->vbit); dcbf_64(rcursor); @@ -487,12 +509,12 @@ void bm_isr_bscn_mask(struct bm_portal *portal, uint8_t bpid, int enable) uint32_t __bm_isr_read(struct bm_portal *portal, enum bm_isr_reg n) { - return __bm_in(&portal->addr, REG_ISR + (n << 2)); + return __bm_in(&portal->addr, REG_ISR + (n << BM_ISR_SHIFT)); } void __bm_isr_write(struct bm_portal *portal, enum bm_isr_reg n, uint32_t val) { - __bm_out(&portal->addr, REG_ISR + (n << 2), val); + __bm_out(&portal->addr, REG_ISR + (n << BM_ISR_SHIFT), val); } diff --git a/sys/contrib/ncsw/Peripherals/BM/bman_private.h b/sys/contrib/ncsw/Peripherals/BM/bman_private.h index 972c57cecb0..2641792e2e6 100644 --- a/sys/contrib/ncsw/Peripherals/BM/bman_private.h +++ b/sys/contrib/ncsw/Peripherals/BM/bman_private.h @@ -55,6 +55,39 @@ * execution reordering with respect to other code/instructions that manipulate * the same cacheline. */ +#if defined(__aarch64__) +/* + * ARM64 cache operations. + * + * Portal CE region is mapped Normal Non-Cacheable (matching Linux's + * MEMREMAP_WC), so stores go directly to hardware. However, dcbf is + * also used on cacheable DMA memory (buffer pools) — there we need + * real cache clean to make CPU writes visible to BMan hardware. + * + * dc cvac (clean by VA to PoC) is the ARM64 equivalent of PPC dcbf. + * On NC addresses it's a harmless no-op; on cached addresses it writes + * dirty lines back to memory. + * + * dc zva MUST NOT be used on portal NC memory — it generates a special + * bus transaction that can hang the interconnect. Use memset instead. + */ +#define lwsync() __asm__ __volatile__ ("dmb ish" : : : "memory") +#define dcbf(addr) do { \ + __asm__ __volatile__ ("dc cvac, %0" : : "r"(addr) : "memory"); \ + __asm__ __volatile__ ("dsb st" : : : "memory"); \ +} while(0) +#define dcbi(p) __asm__ __volatile__ ("dsb sy" : : : "memory") +#define dcbt_ro(addr) do { } while(0) +#define dcbt_rw(addr) do { } while(0) +#define dcbz_64(p) do { memset((p), 0, 64); } while(0) +#define dcbf_64(p) do { \ + __asm__ __volatile__ ("dc cvac, %0" : : "r"(p) : "memory"); \ + __asm__ __volatile__ ("dsb st" : : : "memory"); \ +} while(0) +#define dcbit_ro(p) do { } while(0) + +#else /* PowerPC */ + #define dcbf(addr) \ do { \ __asm__ __volatile__ ("dcbf 0, %0" : : "r" (addr)); \ @@ -127,6 +160,8 @@ #define dcbi(p) dcbf(p) +#endif /* __aarch64__ */ + struct bm_addr { void *addr_ce; /* cache-enabled */ void *addr_ci; /* cache-inhibited */ diff --git a/sys/contrib/ncsw/Peripherals/FM/HC/hc.c b/sys/contrib/ncsw/Peripherals/FM/HC/hc.c index 903d55e4b7e..0470bbbb777 100644 --- a/sys/contrib/ncsw/Peripherals/FM/HC/hc.c +++ b/sys/contrib/ncsw/Peripherals/FM/HC/hc.c @@ -228,7 +228,12 @@ static __inline__ t_Error EnQFrm(t_FmHc *p_FmHc, t_DpaaFD *p_FmFd, uint32_t seqN XX_UDelay(100); if (!timeout) + { + intFlags = FmPcdLock(p_FmHc->h_FmPcd); + p_FmHc->enqueued[seqNum] = FALSE; + FmPcdUnlock(p_FmHc->h_FmPcd, intFlags); RETURN_ERROR(MINOR, E_TIMEOUT, ("HC Callback, timeout exceeded")); + } return err; } diff --git a/sys/contrib/ncsw/Peripherals/FM/Pcd/fm_cc.c b/sys/contrib/ncsw/Peripherals/FM/Pcd/fm_cc.c index a9fd2c1d036..ba734f9956b 100644 --- a/sys/contrib/ncsw/Peripherals/FM/Pcd/fm_cc.c +++ b/sys/contrib/ncsw/Peripherals/FM/Pcd/fm_cc.c @@ -38,6 +38,7 @@ *//***************************************************************************/ #include #include + #include "std_ext.h" #include "error_ext.h" #include "string_ext.h" @@ -51,6 +52,15 @@ #include "fm_cc.h" #include "crc64.h" +#ifdef USE_ENHANCED_EHASH +#include "fm_ehash.h" +extern t_Handle ExternalHashTableSet(t_Handle h_FmPcd, + t_FmPcdHashTableParams *p_Param); +extern t_Error ExternalHashTableModifyMissNextEngine(t_Handle h_HashTbl, + t_FmPcdCcNextEngineParams *p_FmPcdCcNextEngineParams); +extern void copy_td_to_ccbase(void *handle, t_Handle p_CcTreeTmp); +#endif /* USE_ENHANCED_EHASH */ + /****************************************/ /* static functions */ /****************************************/ @@ -344,6 +354,24 @@ static void FillAdOfTypeContLookup(t_Handle h_Ad, /* if (p_AdNewPtr = NULL) --> Done. (case (3)) */ if (p_AdNewPtr) { +#if (DPAA_VERSION >= 11) + if (p_Node->externalHash) + { + /* + * External hash table (CDX): write a zeroed placeholder AD. + * CDX will overwrite this AD with its opcode-format entries + * when it takes over the hash table. Until then, the zero + * AD acts as a "result" type with FQID=0 / NIA=0, which + * causes FMan to enqueue to the default queue. + */ + WRITE_UINT32(p_AdContLookup->ccAdBase, 0); + WRITE_UINT32(p_AdContLookup->matchTblPtr, 0); + WRITE_UINT32(p_AdContLookup->pcAndOffsets, 0); + WRITE_UINT32(p_AdContLookup->gmask, 0); + } + else +#endif /* (DPAA_VERSION >= 11) */ + { /* cases (1) & (2) */ tmpReg32 = 0; tmpReg32 |= FM_PCD_AD_CONT_LOOKUP_TYPE; @@ -371,6 +399,7 @@ static void FillAdOfTypeContLookup(t_Handle h_Ad, MemCpy8((void*)&p_AdContLookup->gmask, p_Node->p_GlblMask, CC_GLBL_MASK_SIZE); + } } } @@ -1071,6 +1100,7 @@ static bool IsCapwapApplSpecific(t_Handle h_Node) } #endif /* FM_CAPWAP_SUPPORT */ +#ifndef USE_ENHANCED_EHASH static t_Error CcUpdateParam( t_Handle h_FmPcd, t_Handle h_PcdParams, t_Handle h_FmPort, t_FmPcdCcKeyAndNextEngineParams *p_CcKeyAndNextEngineParams, @@ -1165,6 +1195,34 @@ static t_Error CcUpdateParam( return E_OK; } +#else /* USE_ENHANCED_EHASH */ +/* + * With enhanced ehash, CC tree entries contain CDX enhanced AD content + * written by copy_td_to_ccbase(). No NCSW internal parameter update + * or recursive tree walking needed — h_CcNode handles are en_exthash_info* + * not t_FmPcdCcNode*, so the internal code would crash. + * Matching Linux SDK fm_cc.c:1209-1221. + */ +static t_Error CcUpdateParam( + t_Handle h_FmPcd, t_Handle h_PcdParams, t_Handle h_FmPort, + t_FmPcdCcKeyAndNextEngineParams *p_CcKeyAndNextEngineParams, + uint16_t numOfEntries, t_Handle h_Ad, bool validate, uint16_t level, + t_Handle h_FmTree, bool modify) +{ + UNUSED(h_FmPcd); + UNUSED(h_PcdParams); + UNUSED(h_FmPort); + UNUSED(p_CcKeyAndNextEngineParams); + UNUSED(numOfEntries); + UNUSED(h_Ad); + UNUSED(validate); + UNUSED(level); + UNUSED(h_FmTree); + UNUSED(modify); + + return E_OK; +} +#endif /* USE_ENHANCED_EHASH */ static ccPrivateInfo_t IcDefineCode(t_FmPcdCcNodeParams *p_CcNodeParam) { @@ -6005,8 +6063,10 @@ t_Handle FM_PCD_CcRootBuild(t_Handle h_FmPcd, t_NetEnvParams netEnvParams; uint8_t lastOne = 0; uint32_t requiredAction = 0; +#ifndef USE_ENHANCED_EHASH t_FmPcdCcNode *p_FmPcdCcNextNode; t_CcNodeInformation ccNodeInfo, *p_CcInformation; +#endif SANITY_CHECK_RETURN_VALUE(h_FmPcd, E_INVALID_HANDLE, NULL); SANITY_CHECK_RETURN_VALUE(p_PcdGroupsParam, E_INVALID_HANDLE, NULL); @@ -6190,6 +6250,7 @@ t_Handle FM_PCD_CcRootBuild(t_Handle h_FmPcd, p_CcTreeTmp = UINT_TO_PTR(p_FmPcdCcTree->ccTreeBaseAddr); +#ifndef USE_ENHANCED_EHASH for (i = 0; i < numOfEntries; i++) { p_KeyAndNextEngineParams = p_Params + i; @@ -6225,10 +6286,59 @@ t_Handle FM_PCD_CcRootBuild(t_Handle h_FmPcd, p_CcInformation->index++; } } +#else /* USE_ENHANCED_EHASH */ + for (i = 0; i < numOfEntries; i++) + { + t_FmPcdCcNextEngineParams *nexteng; + + p_KeyAndNextEngineParams = p_Params + i; + nexteng = &p_KeyAndNextEngineParams->nextEngineParams; + + if (nexteng->nextEngine == e_FM_PCD_CC && + nexteng->params.ccParams.h_CcNode) + { + /* Enhanced external hash table: copy AD into CC tree MURAM slot */ + copy_td_to_ccbase(nexteng->params.ccParams.h_CcNode, p_CcTreeTmp); + } + else + { + /* Non-CC entry (KG/PLCR/DONE): use standard result AD */ + NextStepAd(p_CcTreeTmp, NULL, nexteng, p_FmPcd); + } + + p_CcTreeTmp = PTR_MOVE(p_CcTreeTmp, FM_PCD_CC_AD_ENTRY_SIZE); + + memcpy(&p_FmPcdCcTree->keyAndNextEngineParams[i], + p_KeyAndNextEngineParams, + sizeof(t_FmPcdCcKeyAndNextEngineParams)); + } + + /* + * Fill unused CC tree entries (numOfEntries..15) with a copy of + * entry 0. A zeroed EHASH AD has table_base=0x0 — FMan DMA to + * physical address 0 (not DDR) hangs the task permanently. + * Copying entry 0 gives a valid table_base, int_buf_pool, and + * global_mem_offset. The miss_action starts as DONE (0); + * ExternalHashTableModifyMissNextEngine propagates the correct + * miss action to all copies by scanning for matching table_base_lo. + */ + if (numOfEntries > 0 && numOfEntries < FM_PCD_MAX_NUM_OF_CC_GROUPS) + { + uint8_t *base = (uint8_t *) + UINT_TO_PTR(p_FmPcdCcTree->ccTreeBaseAddr); + for (i = numOfEntries; i < FM_PCD_MAX_NUM_OF_CC_GROUPS; i++) + { + memcpy(base + i * FM_PCD_CC_AD_ENTRY_SIZE, + base, + FM_PCD_CC_AD_ENTRY_SIZE); + } + } +#endif /* USE_ENHANCED_EHASH */ FmPcdIncNetEnvOwners(h_FmPcd, p_FmPcdCcTree->netEnvId); p_CcTreeTmp = UINT_TO_PTR(p_FmPcdCcTree->ccTreeBaseAddr); +#ifndef USE_ENHANCED_EHASH if (!FmPcdLockTryLockAll(p_FmPcd)) { FM_PCD_CcRootDelete(p_FmPcdCcTree); @@ -6259,6 +6369,7 @@ t_Handle FM_PCD_CcRootBuild(t_Handle h_FmPcd, } FmPcdLockUnlockAll(p_FmPcd); +#endif /* USE_ENHANCED_EHASH */ p_FmPcdCcTree->p_Lock = FmPcdAcquireLock(p_FmPcd); if (!p_FmPcdCcTree->p_Lock) { @@ -7112,6 +7223,9 @@ t_Error FM_PCD_MatchTableGetIndexedHashBucket(t_Handle h_CcNode, t_Handle FM_PCD_HashTableSet(t_Handle h_FmPcd, t_FmPcdHashTableParams *p_Param) { +#ifdef USE_ENHANCED_EHASH + return ExternalHashTableSet(h_FmPcd, p_Param); +#else /* !USE_ENHANCED_EHASH */ t_FmPcdCcNode *p_CcNodeHashTbl; t_FmPcdCcNodeParams *p_IndxHashCcNodeParam, *p_ExactMatchCcNodeParam; t_FmPcdCcNode *p_CcNode; @@ -7151,6 +7265,57 @@ t_Handle FM_PCD_HashTableSet(t_Handle h_FmPcd, t_FmPcdHashTableParams *p_Param) ("RMON statistics mode is not supported for hash table")); return NULL; } + + if (p_Param->externalHash) + { + /* + * External hash table: CDX manages the hash buckets in DDR. + * NCSW only allocates a minimal t_FmPcdCcNode with a MURAM AD + * placeholder. CDX will take over the AD and rewrite it with + * CDX opcode entries. + * + * The AD is initially zeroed (safe: result type, enqueue to + * default FQ). Packets reaching this node before CDX takes + * over will be enqueued to the default queue harmlessly. + */ + t_FmPcdCcNode *p_ExtNode; + t_FmPcd *p_FmPcd = (t_FmPcd *)h_FmPcd; + + p_ExtNode = (t_FmPcdCcNode *)XX_Malloc(sizeof(t_FmPcdCcNode)); + if (!p_ExtNode) + { + REPORT_ERROR(MAJOR, E_NO_MEMORY, ("external hash CC node")); + return NULL; + } + memset(p_ExtNode, 0, sizeof(t_FmPcdCcNode)); + + p_ExtNode->externalHash = TRUE; + p_ExtNode->h_FmPcd = h_FmPcd; + p_ExtNode->kgHashShift = p_Param->kgHashShift; + p_ExtNode->statisticsMode = p_Param->statisticsMode; + + /* Allocate MURAM AD for this node */ + p_ExtNode->h_Ad = (t_Handle)FM_MURAM_AllocMem( + p_FmPcd->h_FmMuram, + FM_PCD_CC_AD_ENTRY_SIZE, FM_PCD_CC_AD_TABLE_ALIGN); + if (!p_ExtNode->h_Ad) + { + XX_Free(p_ExtNode); + REPORT_ERROR(MAJOR, E_NO_MEMORY, + ("MURAM allocation for external hash AD")); + return NULL; + } + MemSet8(p_ExtNode->h_Ad, 0, FM_PCD_CC_AD_ENTRY_SIZE); + + p_ExtNode->h_Spinlock = XX_InitSpinlock(); + + INIT_LIST(&p_ExtNode->ccPrevNodesLst); + INIT_LIST(&p_ExtNode->ccTreeIdLst); + INIT_LIST(&p_ExtNode->ccTreesLst); + INIT_LIST(&p_ExtNode->availableStatsLst); + + return (t_Handle)p_ExtNode; + } #endif /* (DPAA_VERSION >= 11) */ p_ExactMatchCcNodeParam = (t_FmPcdCcNodeParams*)XX_Malloc( @@ -7305,10 +7470,14 @@ t_Handle FM_PCD_HashTableSet(t_Handle h_FmPcd, t_FmPcdHashTableParams *p_Param) XX_Free(p_ExactMatchCcNodeParam); return p_CcNodeHashTbl; +#endif /* !USE_ENHANCED_EHASH */ } t_Error FM_PCD_HashTableDelete(t_Handle h_HashTbl) { +#ifdef USE_ENHANCED_EHASH + return (t_Error)-1; /* delete not implemented for enhanced ehash */ +#else t_FmPcdCcNode *p_HashTbl = (t_FmPcdCcNode *)h_HashTbl; t_Handle h_FmPcd; t_Handle *p_HashBuckets, h_MissStatsCounters; @@ -7317,6 +7486,19 @@ t_Error FM_PCD_HashTableDelete(t_Handle h_HashTbl) SANITY_CHECK_RETURN_ERROR(p_HashTbl, E_INVALID_HANDLE); +#if (DPAA_VERSION >= 11) + if (p_HashTbl->externalHash) + { + if (p_HashTbl->h_Ad) + FM_MURAM_FreeMem(FmPcdGetMuramHandle(p_HashTbl->h_FmPcd), + p_HashTbl->h_Ad); + if (p_HashTbl->h_Spinlock) + XX_FreeSpinlock(p_HashTbl->h_Spinlock); + XX_Free(p_HashTbl); + return E_OK; + } +#endif /* (DPAA_VERSION >= 11) */ + /* Store all hash buckets before the hash is freed */ numOfBuckets = p_HashTbl->numOfKeys; @@ -7348,11 +7530,20 @@ t_Error FM_PCD_HashTableDelete(t_Handle h_HashTbl) RETURN_ERROR(MAJOR, err, NO_MSG); return E_OK; +#endif /* !USE_ENHANCED_EHASH */ } t_Error FM_PCD_HashTableAddKey(t_Handle h_HashTbl, uint8_t keySize, t_FmPcdCcKeyParams *p_KeyParams) { +#ifdef USE_ENHANCED_EHASH + /* CDX adds keys directly via ExternalHashTableAddKey (different + * signature). This NCSW dispatch path is not used. */ + UNUSED(h_HashTbl); + UNUSED(keySize); + UNUSED(p_KeyParams); + return E_NOT_SUPPORTED; +#else t_FmPcdCcNode *p_HashTbl = (t_FmPcdCcNode *)h_HashTbl; t_Handle h_HashBucket; uint8_t bucketIndex; @@ -7377,8 +7568,10 @@ t_Error FM_PCD_HashTableAddKey(t_Handle h_HashTbl, uint8_t keySize, return FM_PCD_MatchTableAddKey(h_HashBucket, FM_PCD_LAST_KEY_INDEX, keySize, p_KeyParams); +#endif /* !USE_ENHANCED_EHASH */ } +#ifndef USE_ENHANCED_EHASH t_Error FM_PCD_HashTableRemoveKey(t_Handle h_HashTbl, uint8_t keySize, uint8_t *p_Key) { @@ -7426,11 +7619,16 @@ t_Error FM_PCD_HashTableModifyNextEngine( NULL, p_FmPcdCcNextEngineParams); } +#endif /* !USE_ENHANCED_EHASH */ t_Error FM_PCD_HashTableModifyMissNextEngine( t_Handle h_HashTbl, t_FmPcdCcNextEngineParams *p_FmPcdCcNextEngineParams) { +#ifdef USE_ENHANCED_EHASH + return ExternalHashTableModifyMissNextEngine(h_HashTbl, + p_FmPcdCcNextEngineParams); +#else t_FmPcdCcNode *p_HashTbl = (t_FmPcdCcNode *)h_HashTbl; t_Handle h_HashBucket; uint8_t i; @@ -7483,9 +7681,11 @@ t_Error FM_PCD_HashTableModifyMissNextEngine( } return E_OK; +#endif /* !USE_ENHANCED_EHASH */ } +#ifndef USE_ENHANCED_EHASH t_Error FM_PCD_HashTableGetMissNextEngine( t_Handle h_HashTbl, t_FmPcdCcNextEngineParams *p_FmPcdCcNextEngineParams) @@ -7549,3 +7749,4 @@ t_Error FM_PCD_HashTableGetMissStatistics( return FM_PCD_MatchTableGetMissStatistics(h_HashBucket, p_MissStatistics); } +#endif /* !USE_ENHANCED_EHASH */ diff --git a/sys/contrib/ncsw/Peripherals/FM/Pcd/fm_cc.h b/sys/contrib/ncsw/Peripherals/FM/Pcd/fm_cc.h index 3456bb565fd..30bed7c5c44 100644 --- a/sys/contrib/ncsw/Peripherals/FM/Pcd/fm_cc.h +++ b/sys/contrib/ncsw/Peripherals/FM/Pcd/fm_cc.h @@ -348,6 +348,11 @@ typedef struct uint32_t shadowAction; uint8_t userSizeOfExtraction; uint8_t userOffset; + +#if (DPAA_VERSION >= 11) + bool externalHash; /* CDX external hash table */ +#endif /* (DPAA_VERSION >= 11) */ + uint8_t kgHashShift; /* used in hash-table */ t_Handle h_Spinlock; diff --git a/sys/contrib/ncsw/Peripherals/FM/Pcd/fm_ehash.c b/sys/contrib/ncsw/Peripherals/FM/Pcd/fm_ehash.c new file mode 100644 index 00000000000..8df1a42f152 --- /dev/null +++ b/sys/contrib/ncsw/Peripherals/FM/Pcd/fm_ehash.c @@ -0,0 +1,1516 @@ +/* + * fm_ehash.c — FMan enhanced external hash table (kernel-side) + * + * Ported from: + * linux/drivers/net/ethernet/freescale/sdk_fman/Peripherals/FM/Pcd/fm_ehash.c + * + * Implements the ExternalHashTable* API used by CDX for hardware flow + * offload. Manages DDR-based hash tables with CRC64-indexed buckets + * and per-bucket spinlocks. + * + * With USE_ENHANCED_EHASH, FM_PCD_HashTableSet (in fm_cc.c) redirects + * to ExternalHashTableSet here. The returned handle (en_exthash_info*) + * is opaque to all callers (fmlib, FMC, dpa_app, CDX). + * + * The MURAM Action Descriptor is NOT allocated here. copy_td_to_ccbase() + * writes the AD content from info->node into the CC tree's MURAM slot + * during FM_PCD_CcRootBuild, and saves the MURAM address to info->h_Ad. + * ExternalHashTableModifyMissNextEngine then uses info->h_Ad to patch + * the miss action in-place. + * + * Simplifications for initial port: + * - NO_CUMULATIVE_ENTRY: simple linked-list buckets, no compaction + * - No IP reassembly table support (table_type REASSM is accepted + * but reassembly-specific params are ignored) + * + * Copyright 2018 NXP (original Linux SDK code) + * Copyright (c) 2026 Mono Technologies Inc. + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include "opt_dpaa.h" + +#include +#include +#include +#include +#include + +#include +#include + +/* NCSW public headers (resolved via -I paths in DPAA_COMPILE_CMD) */ +#include "ncsw_ext.h" +#include "error_ext.h" +#include "endian_ext.h" +#include "xx_ext.h" +#include "fm_pcd_ext.h" +#include "fm_muram_ext.h" + +/* NCSW internal headers — needed for t_FmPcd, FmPcdGetMuramHandle, etc. */ +#include "fm_pcd.h" +#include "fm_cc.h" +#include "fm_common.h" + +/* CRC64 from NCSW PCD */ +#include "crc64.h" + +/* CDX fm_ehash.h — entry/bucket structs and opcode constants */ +#include "fm_ehash.h" + +/* Linux endian compat — guarded against LinuxKPI which defines them too */ +#ifndef cpu_to_be16 +#define cpu_to_be16(x) htobe16(x) +#endif +#ifndef cpu_to_be32 +#define cpu_to_be32(x) htobe32(x) +#endif +#ifndef be64_to_cpu +#define be64_to_cpu(x) be64toh(x) +#endif + +/* ---------------------------------------------------------------- + * Direct MURAM accessors — batch-safe volatile stores/loads + * + * MURAM on LS1046A ARM64 requires that multiple stores to the same + * 16-byte region are batched WITHOUT a dsb sy between each store. + * A dsb sy after each store causes all but the last to be lost + * (confirmed empirically: raw batch stores + single dsb work, + * per-store dsb does not). + * + * muram_wr32 does a raw volatile store with bswap, NO barrier. + * muram_rd32 does a raw volatile load with bswap + read barrier. + * muram_barrier() issues a single dsb sy — call ONCE after all + * stores in a batch are complete. + * ---------------------------------------------------------------- */ +#define muram_barrier() __asm __volatile("dsb sy" ::: "memory") + +static __inline void +muram_wr32(volatile uint32_t *addr, uint32_t native_val) +{ + + *addr = __builtin_bswap32(native_val); + /* NO barrier here — caller must call muram_barrier() after batch */ +} + +/* + * muram_wr64 — write two native uint32_t values as a single 64-bit store. + * + * A 64-bit store is a single AXI bus transaction, which the MURAM + * controller handles atomically. This avoids the partial-write + * corruption seen with two separate 32-bit stores when FMan microcode + * concurrently reads the same 16-byte AD region. + * + * On LE ARM64, a 64-bit store writes: + * bits[31:0] → bytes at addr+0 (native_lo, byte-swapped) + * bits[63:32] → bytes at addr+4 (native_hi, byte-swapped) + */ +static __inline void +muram_wr64(volatile uint64_t *addr, uint32_t native_lo, uint32_t native_hi) +{ + + *addr = ((uint64_t)__builtin_bswap32(native_hi) << 32) | + (uint64_t)__builtin_bswap32(native_lo); + /* NO barrier here — caller must call muram_barrier() after batch */ +} + +static __inline uint32_t +muram_rd32(volatile uint32_t *addr) +{ + uint32_t v; + + v = *addr; + __asm __volatile("dsb sy" ::: "memory"); + return (__builtin_bswap32(v)); +} + +/* ---------------------------------------------------------------- + * Internal definitions (supplements fm_ehash.h) + * ---------------------------------------------------------------- */ + +/* Miss action types for en_exthash_node */ +#define EN_EHASH_MISS_ACTION_DROP 3 +#define EN_EHASH_MISS_ACTION_NIA 1 +#define EN_EHASH_MISS_ACTION_ENQUE 2 +#define EN_EHASH_MISS_ACTION_DONE 0 + +/* Internal buffer pool size and table alignment */ +#define EN_INTERNAL_BUFF_POOL_SIZE (256 * 128) +#define EN_EXTHASH_TBL_ALIGNMENT 256 + +/* + * Hardware table_type constants for en_exthash_node word_0 bits [23:20] + * (LE ARM64 C bitfield position). + * The CDX microcode uses table_type to identify the hash table's + * protocol layer. Without a valid table_type, the microcode does + * not recognize the AD as an enhanced hash table entry. + */ +#define EHASH_HW_TABLE_TYPE_L2 (1 << 0) /* 0x1 */ +#define EHASH_HW_TABLE_TYPE_L3 (1 << 1) /* 0x2 */ +#define EHASH_HW_TABLE_TYPE_L4 (1 << 2) /* 0x4 */ +#define EHASH_HW_TABLE_TYPE_REASSM (1 << 3) /* 0x8 */ + +/* + * Convert user-facing table_type enum (from dpa_app/fmlib) to + * hardware table_type constant. Enum values match fm_eh_types.h. + */ +static uint32_t +ehash_hw_table_type(uint32_t user_type) +{ + + switch (user_type & 0xf) { + case 0: /* IPV4_UDP_TABLE */ + case 1: /* IPV4_TCP_TABLE */ + case 2: /* IPV6_UDP_TABLE */ + case 3: /* IPV6_TCP_TABLE */ + case 4: /* ESP_IPV4_TABLE */ + case 5: /* ESP_IPV6_TABLE */ + case 10: /* IPV4_3TUPLE_UDP_TABLE */ + case 11: /* IPV4_3TUPLE_TCP_TABLE */ + case 12: /* IPV6_3TUPLE_UDP_TABLE */ + case 13: /* IPV6_3TUPLE_TCP_TABLE */ + return (EHASH_HW_TABLE_TYPE_L4); + case 6: /* IPV4_MULTICAST_TABLE */ + case 7: /* IPV6_MULTICAST_TABLE */ + return (EHASH_HW_TABLE_TYPE_L3); + case 14: /* IPV4_REASSM_TABLE */ + case 15: /* IPV6_REASSM_TABLE */ + return (EHASH_HW_TABLE_TYPE_REASSM); + default: /* PPPOE_RELAY_TABLE, ETHERNET_TABLE, etc. */ + return (EHASH_HW_TABLE_TYPE_L2); + } +} + +/* Flags for en_exthash_info.flags */ +#define TIMESTAMP_EN (1 << 0) +#define STATS_EN (1 << 1) + +/* + * en_exthash_node — Action Descriptor for enhanced external hash table. + * Written to MURAM (via copy_td_to_ccbase); read by FMan CDX microcode. + * + * The Linux SDK (fm_ehash.h line 563) defines this with C bitfield unions + * "assuming a LE GPP core". On LE ARM64, the first declared struct field + * occupies the LSB. muram_wr32/muram_wr64 byte-swap the native value + * so FMan (always BE) reads the correct numeric value. + * + * CONFIRMED: LE ARM64 C bitfield positions are correct. Attempting + * PPC/BE positions (build #194) causes FMan exception 5 (crash). + * + * Non-EXCLUDE_FMAN_IPR_OFFLOAD layout (active on LS1046A): + * + * word_0 — LE ARM64 C bitfield positions (first field at LSB): + * bits 7:0 = table_base_hi (8) — upper bits of 40-bit table addr + * bits 15:8 = ipv4_ad_offset (8) — IPR reassembly AD offset (0) + * bits 18:16 = hash_bytes_offset (3) — CRC64 shift parameter + * bit 19 = reserved (1) + * bits 23:20 = table_type (4) — L2/L3/L4/REASSM identifier + * bits 29:24 = key_size (6) + * bits 31:30 = miss_action_type (2) + * + * word_1 — LE ARM64 C bitfield positions: + * bits 3:0 = hash_mask_bits (4) + * bits 15:4 = global_mem_offset (12) + * bits 31:16 = int_buf_pool_addr (16) + * + * word_2: nia or fqid depending on miss_action_type + */ +struct en_exthash_node { + uint32_t word_0; + uint32_t table_base_lo; + uint32_t word_1; + uint32_t word_2; /* nia or fqid */ +} __attribute__((packed)); + +/* word_0 field construction — LE ARM64 C bitfield positions. + * + * On LE ARM64, C bitfields place the first declared field at bit 0 (LSB). + * muram_wr32/muram_wr64 byte-swap the native value for MURAM storage. + * + * Non-EXCLUDE_FMAN_IPR_OFFLOAD variant (LS1046A). */ +#define EHASH_W0_TABLE_BASE_HI(v) ((uint32_t)(v) & 0xFF) /* bits 7:0 */ +#define EHASH_W0_IPV4_AD_OFF(v) (((uint32_t)(v) & 0xFF) << 8) /* bits 15:8 */ +#define EHASH_W0_HASH_BYTES_OFF(v) (((uint32_t)(v) & 0x7) << 16) /* bits 18:16 */ +#define EHASH_W0_TABLE_TYPE(v) (((uint32_t)(v) & 0xF) << 20) /* bits 23:20 */ +#define EHASH_W0_KEY_SIZE(v) (((uint32_t)(v) & 0x3F) << 24) /* bits 29:24 */ +#define EHASH_W0_MISS_ACTION(v) (((uint32_t)(v) & 0x3) << 30) /* bits 31:30 */ +#define EHASH_W0_MISS_ACTION_MASK (0x3U << 30) /* bits 31:30 */ + +/* word_1 field construction — LE ARM64 C bitfield positions. + * Non-EXCLUDE variant: hash_mask_bits at LSB, then + * global_mem_offset, then int_buf_pool_addr at MSB. */ +#define EHASH_W1_HASH_MASK_BITS(v) ((uint32_t)(v) & 0xF) /* bits 3:0 */ +#define EHASH_W1_GLOBAL_MEM_OFF(v) (((uint32_t)(v) & 0xFFF) << 4) /* bits 15:4 */ +#define EHASH_W1_INT_BUF_POOL(v) (((uint32_t)(v) & 0xFFFF) << 16) /* bits 31:16 */ + +/* + * en_exthash_info — Per-table software state. + * Returned as opaque t_Handle to callers. + */ +struct en_exthash_info { + uint32_t flags; + void *table_base; /* DDR bucket array */ + void **pSpinlock; /* per-bucket spinlock array */ + void *h_Ad; /* MURAM AD pointer (set by copy_td_to_ccbase) */ + struct en_exthash_node node; /* local copy of table descriptor */ + uint32_t tablesize; + uint32_t hashmask; + uint32_t keysize; + uint32_t hashshift; + uint32_t dataMemId; + uint32_t dataLiodnOffset; + uint32_t num_keys; + uint32_t max_collisions; + void *pcd; /* PCD handle */ + uint32_t table_type; /* user-facing type (L2/L3/L4/REASSM) */ + struct ip_reassembly_params *ip_reassem_info; /* MURAM VA, REASSM only */ +}; + +MALLOC_DEFINE(M_EHASH, "ehash", "CDX external hash table"); + +/* ---------------------------------------------------------------- + * Internal buffer pool management — allocated once in MURAM + * ---------------------------------------------------------------- */ + +static void *ehash_int_muram_ptr; /* virtual address */ +static uint32_t ehash_int_muram_area; /* MURAM offset >> 8 */ +static void *ehash_first_table_base;/* DDR base of first table */ + +/* Global MURAM data area — dscp_vlanpcp_map + SEC_failure_stats. + * Points to pool + EN_INTERNAL_BUFF_POOL_SIZE. Initialized in + * ehash_init_muram_pool(). */ +static en_exthash_global_mem *ehash_global_mem; + +/* Reassembly table tracking — set during ExternalHashTableSet() + * for IPV4_REASSM_TABLE (14) and IPV6_REASSM_TABLE (15). */ +#define EHASH_IPV4_REASSM_TABLE 14 +#define EHASH_IPV6_REASSM_TABLE 15 + +static struct en_exthash_info *ehash_ipv4_reassly_tbl; +static struct en_exthash_info *ehash_ipv6_reassly_tbl; + +/* ---------------------------------------------------------------- + * External timestamp slots — separate MURAM allocation + * + * Timestamps MUST be in their own MURAM region, NOT in the global + * data area. The global data area (at int_buf_pool + POOL_SIZE) + * contains en_exthash_global_mem (dscp_vlanpcp_map + SEC_failure_stats) + * which the CDX microcode reads/writes at runtime. + * + * Linux SDK allocates timestamps separately in FM_PCD_Init() + * (fm_pcd.c: FM_MURAM_AllocMem for MAX_EXT_TS_TIMERS * EXT_TS_SIZE). + * ---------------------------------------------------------------- */ + +#define MAX_EXT_TS_TIMERS 4 + +static uint32_t *ehash_ts_virt; /* virtual ptr to slot[0] */ +static uint64_t ehash_ts_phys; /* physical addr of slot[0] */ +static uint64_t ehash_muram_phys_base; /* MURAM physical base */ + +/* + * Allocate the internal buffer pool + global data area in MURAM, + * plus a SEPARATE timestamp region. + * Called once on first ExternalHashTableSet. + */ +static int +ehash_init_muram_pool(t_Handle h_FmPcd) +{ + t_FmPcd *p_FmPcd = (t_FmPcd *)h_FmPcd; + t_Handle h_FmMuram; + uint32_t total_size; + uint32_t muram_offset; + uint32_t ts_size; + + if (ehash_int_muram_ptr != NULL) + return (0); + + h_FmMuram = FmPcdGetMuramHandle(h_FmPcd); + if (h_FmMuram == NULL) + return (-1); + + /* + * Layout of the pool+global allocation: + * [0 .. EN_INTERNAL_BUFF_POOL_SIZE-1] internal buffer pool + * [EN_INTERNAL_BUFF_POOL_SIZE .. +256] global data area + * (en_exthash_global_mem: dscp_vlanpcp_map + SEC_failure_stats) + * + * Timestamps are allocated SEPARATELY below. + */ + total_size = EN_INTERNAL_BUFF_POOL_SIZE + 256; + + ehash_int_muram_ptr = FM_MURAM_AllocMem(h_FmMuram, + total_size, EN_EXTHASH_TBL_ALIGNMENT); + if (ehash_int_muram_ptr == NULL) { + printf("fm_ehash: MURAM alloc failed (%u bytes)\n", + total_size); + return (-1); + } + IOMemSet32(ehash_int_muram_ptr, 0, total_size); + + /* Compute compressed MURAM offset (physical offset / 256) */ + muram_offset = (uint32_t)(XX_VirtToPhys(ehash_int_muram_ptr) - + p_FmPcd->physicalMuramBase); + if (muram_offset & 0xff) { + printf("fm_ehash: MURAM pool not 256-aligned (0x%x)\n", + muram_offset); + FM_MURAM_FreeMem(h_FmMuram, ehash_int_muram_ptr); + ehash_int_muram_ptr = NULL; + return (-1); + } + + ehash_int_muram_area = muram_offset >> 8; + + ehash_muram_phys_base = p_FmPcd->physicalMuramBase; + + printf("fm_ehash: MURAM pool at %p, offset 0x%x (compressed 0x%x)\n", + ehash_int_muram_ptr, muram_offset, ehash_int_muram_area); + ehash_global_mem = (en_exthash_global_mem *)((uint8_t *)ehash_int_muram_ptr + + EN_INTERNAL_BUFF_POOL_SIZE); + + printf("fm_ehash: global data at pool+0x%x (en_exthash_global_mem)\n", + EN_INTERNAL_BUFF_POOL_SIZE); + + /* + * Allocate timestamp slots as a SEPARATE MURAM region. + * Linux SDK does this in FM_PCD_Init() via FM_MURAM_AllocMem. + * These must NOT overlap the global data area. + */ + ts_size = MAX_EXT_TS_TIMERS * sizeof(uint32_t); + ehash_ts_virt = FM_MURAM_AllocMem(h_FmMuram, + ts_size, sizeof(uint32_t)); + if (ehash_ts_virt == NULL) { + printf("fm_ehash: MURAM timestamp alloc failed (%u bytes)\n", + ts_size); + FM_MURAM_FreeMem(h_FmMuram, ehash_int_muram_ptr); + ehash_int_muram_ptr = NULL; + return (-1); + } + IOMemSet32(ehash_ts_virt, 0, ts_size); + ehash_ts_phys = XX_VirtToPhys(ehash_ts_virt); + + printf("fm_ehash: timestamp slots at %p, phys 0x%jx " + "(MURAM offset 0x%jx)\n", + ehash_ts_virt, (uintmax_t)ehash_ts_phys, + (uintmax_t)(ehash_ts_phys - ehash_muram_phys_base)); + + return (0); +} + +/* ---------------------------------------------------------------- + * CRC64-based hash bucket indexing + * + * Ported from sdk_fman fm_cc.c:get_indexed_hash_bucket() + * ---------------------------------------------------------------- */ + +static void +get_indexed_hash_bucket(uint8_t key_size, uint8_t *key_ptr, + uint8_t crc_shift, uint16_t mask, uint16_t *bucket_index) +{ + uint64_t crc64; + + crc64 = crc64_init(); + crc64 = crc64_compute(key_ptr, key_size, crc64); + crc64 >>= ((6 - crc_shift) << 3); + *bucket_index = (uint16_t)crc64 & mask; +} + +/* ---------------------------------------------------------------- + * Bucket chain search (NO_CUMULATIVE_ENTRY path) + * ---------------------------------------------------------------- */ + +static struct en_exthash_tbl_entry * +find_entry_in_bucket(struct en_exthash_tbl_entry *entry, + uint8_t *key, uint32_t size) +{ + + while (entry != NULL) { + if (memcmp(key, &entry->hashentry.key[0], size) == 0) + return (entry); + entry = entry->next; + } + return (NULL); +} + +/* ---------------------------------------------------------------- + * Cleanup helper + * ---------------------------------------------------------------- */ + +static void +delete_ehash_info(struct en_exthash_info *info) +{ + uint32_t ii; + + if (info == NULL) + return; + + if (info->pSpinlock != NULL) { + for (ii = 0; ii <= info->hashmask; ii++) { + if (*(info->pSpinlock + ii) != NULL) + XX_FreeSpinlock(*(info->pSpinlock + ii)); + else + break; + } + free(info->pSpinlock, M_EHASH); + } + + if (info->table_base != NULL) + contigfree(info->table_base, info->tablesize, M_EHASH); + + /* + * Do NOT free h_Ad — it points into the CC tree's MURAM slot + * (set by copy_td_to_ccbase). The CC tree owns that MURAM. + */ + + free(info, M_EHASH); +} + + +/* ================================================================ + * Public API + * ================================================================ */ + +/* + * ExternalHashTableSet — Create an enhanced external hash table. + * + * Called from FM_PCD_HashTableSet (via USE_ENHANCED_EHASH redirect). + * Allocates DDR bucket array and per-bucket spinlocks. Builds the + * AD node data in info->node but does NOT write it to MURAM. + * copy_td_to_ccbase() (called during FM_PCD_CcRootBuild) writes + * the AD into the CC tree's MURAM entry and sets info->h_Ad. + * + * Returns opaque handle on success, NULL on failure. + */ +t_Handle +ExternalHashTableSet(t_Handle h_FmPcd, t_FmPcdHashTableParams *p_Param) +{ + struct en_exthash_info *info; + uint32_t ii; + struct en_exthash_node *node; + uint64_t tblphysaddr; + uint32_t num_bits; + + if (ehash_init_muram_pool(h_FmPcd) != 0) + return (NULL); + + info = malloc(sizeof(*info), M_EHASH, M_WAITOK | M_ZERO); + if (info == NULL) { + REPORT_ERROR(MAJOR, E_NO_MEMORY, + ("en_exthash_info allocation")); + return (NULL); + } + + info->hashmask = p_Param->hashResMask; + info->pcd = h_FmPcd; + + /* + * Validate hash mask: must be (2^N - 1) where N <= 15. + */ + if (info->hashmask > 0x7fff) { + REPORT_ERROR(MAJOR, E_INVALID_VALUE, + ("unsupported hash mask value")); + goto err_ret; + } + + num_bits = 0; + for (ii = 0; ii < 15; ii++) { + if ((info->hashmask + 1) & (1U << ii)) + break; + } + num_bits = ii; + + if ((1U << num_bits) != (info->hashmask + 1)) { + REPORT_ERROR(MAJOR, E_INVALID_VALUE, + ("hash mask not power-of-2 minus 1")); + goto err_ret; + } + + /* Allocate per-bucket spinlocks (CPU-only, no DMA) */ + info->pSpinlock = malloc( + sizeof(t_Handle) * (info->hashmask + 1), + M_EHASH, M_WAITOK | M_ZERO); + if (info->pSpinlock == NULL) { + REPORT_ERROR(MAJOR, E_NO_MEMORY, ("spinlock array")); + goto err_ret; + } + + for (ii = 0; ii <= info->hashmask; ii++) { + *(info->pSpinlock + ii) = XX_InitSpinlock(); + if (*(info->pSpinlock + ii) == NULL) { + REPORT_ERROR(MAJOR, E_NO_MEMORY, + ("bucket spinlock")); + goto err_ret; + } + } + + /* + * Allocate DDR hash table (bucket array). + * Must be physically contiguous — FMan microcode accesses + * buckets via table_base_phys + index * sizeof(bucket). + * Use contigmalloc directly instead of the shared NCSW + * MallocSmart pool, which is sized for dTSEC buffers only. + */ + info->tablesize = (uint32_t)(sizeof(struct en_exthash_bucket) * + (info->hashmask + 1)); + info->table_base = contigmalloc(info->tablesize, M_EHASH, + M_WAITOK | M_ZERO, 0, (vm_paddr_t)0xFFFFFFFF, + EN_EXTHASH_TBL_ALIGNMENT, 0); + if (info->table_base == NULL) { + REPORT_ERROR(MAJOR, E_NO_MEMORY, + ("hash table buckets")); + goto err_ret; + } + + /* Save first table base for diagnostic DDR bucket verification */ + if (ehash_first_table_base == NULL) + ehash_first_table_base = info->table_base; + + /* Fill table parameters */ + info->keysize = p_Param->matchKeySize; + info->hashshift = p_Param->hashShift; + info->flags |= TIMESTAMP_EN; + if (p_Param->statisticsMode) + info->flags |= STATS_EN; + + /* Build AD node in local copy — NOT written to MURAM yet. + * copy_td_to_ccbase() writes this into the CC tree MURAM slot. */ + node = &info->node; + memset(node, 0, sizeof(*node)); + + tblphysaddr = XX_VirtToPhys(info->table_base); + + { + uint32_t miss_action; + uint32_t hw_table_type; + + /* Convert user-facing table_type enum to hardware constant. + * p_Param->table_type is populated by dpa_app via fmlib. */ + hw_table_type = ehash_hw_table_type(p_Param->table_type); + + switch (p_Param->ccNextEngineParamsForMiss.nextEngine) { + case e_FM_PCD_KG: { + t_FmPcdCcNextKgParams *kgparams = + &p_Param->ccNextEngineParamsForMiss.params.kgParams; + + node->word_2 = NIA_ENG_KG | NIA_KG_DIRECT; + if (kgparams->overrideFqid) + node->word_2 |= kgparams->newFqid | + NIA_KG_CC_EN; + node->word_2 |= + FmPcdKgGetSchemeId(kgparams->h_DirectScheme); + miss_action = EN_EHASH_MISS_ACTION_NIA; + break; + } + case e_FM_PCD_DONE: { + t_FmPcdCcNextEnqueueParams *enqparams = + &p_Param->ccNextEngineParamsForMiss.params + .enqueueParams; + + if (enqparams->overrideFqid) { + node->word_2 = enqparams->newFqid; + miss_action = EN_EHASH_MISS_ACTION_ENQUE; + } else { + miss_action = EN_EHASH_MISS_ACTION_DONE; + } + break; + } + default: + miss_action = EN_EHASH_MISS_ACTION_DROP; + break; + } + + /* Build word_0 — non-EXCLUDE layout matching CDX microcode. + * ipv4_ad_offset = 0 (no IPR reassembly support). */ + node->word_0 = + EHASH_W0_TABLE_BASE_HI((tblphysaddr >> 32) & 0xff) | + EHASH_W0_IPV4_AD_OFF(0) | + EHASH_W0_HASH_BYTES_OFF(info->hashshift) | + EHASH_W0_TABLE_TYPE(hw_table_type) | + EHASH_W0_KEY_SIZE(info->keysize) | + EHASH_W0_MISS_ACTION(miss_action); + node->table_base_lo = tblphysaddr & 0xffffffff; + node->word_1 = + EHASH_W1_HASH_MASK_BITS(num_bits) | + EHASH_W1_GLOBAL_MEM_OFF(EN_INTERNAL_BUFF_POOL_SIZE >> 8) | + EHASH_W1_INT_BUF_POOL(ehash_int_muram_area); + } + + /* + * No MURAM AD allocation here. info->h_Ad stays NULL until + * copy_td_to_ccbase() writes the AD into the CC tree's MURAM + * slot during FM_PCD_CcRootBuild. + */ + info->h_Ad = NULL; + info->table_type = p_Param->table_type; + + /* + * Track reassembly tables for ExternalHashSetReasslyPool(). + * For REASSM tables, word_2 holds the MURAM offset (>>8) of + * ip_reassembly_params. Compute the VA so we can write pool + * configuration fields later. + */ + if (p_Param->table_type == EHASH_IPV4_REASSM_TABLE || + p_Param->table_type == EHASH_IPV6_REASSM_TABLE) { + t_FmPcd *p_FmPcd = (t_FmPcd *)h_FmPcd; + uint64_t reassm_phys; + + if (node->word_2 != 0) { + reassm_phys = p_FmPcd->physicalMuramBase + + ((uint64_t)node->word_2 << 8); + info->ip_reassem_info = + (struct ip_reassembly_params *)XX_PhysToVirt( + reassm_phys); + printf("fm_ehash: REASSM table type %u, " + "ip_reassem_info at %p (MURAM off 0x%x)\n", + p_Param->table_type, info->ip_reassem_info, + node->word_2 << 8); + } + + if (p_Param->table_type == EHASH_IPV4_REASSM_TABLE) + ehash_ipv4_reassly_tbl = info; + else + ehash_ipv6_reassly_tbl = info; + } + + return ((t_Handle)info); + +err_ret: + delete_ehash_info(info); + return (NULL); +} + +/* + * copy_td_to_ccbase — Write enhanced hash AD into CC tree MURAM entry. + * + * Called from FM_PCD_CcRootBuild (USE_ENHANCED_EHASH path) for each + * CC tree entry that points to a hash table. Copies the 16-byte AD + * from info->node to the CC tree's MURAM slot using big-endian + * accessors, and saves the MURAM address to info->h_Ad. + * + * After this call, FMan reads the CC tree entry and finds CDX enhanced + * hash format. ExternalHashTableModifyMissNextEngine can later patch + * the miss action via info->h_Ad. + * + * No IPR reassembly support (void return). + */ +void +copy_td_to_ccbase(void *handle, t_Handle p_CcTreeTmp) +{ + struct en_exthash_info *info = (struct en_exthash_info *)handle; + volatile uint32_t *p = (volatile uint32_t *)p_CcTreeTmp; + + struct en_exthash_node *ptr = &info->node; + + /* + * Write enhanced hash AD into CC tree MURAM slot. + * + * Enhanced hash node layout (16 bytes, all BE in MURAM): + * p[0] = word_0: flags, miss_action, int_buf_pool, etc. + * p[1] = table_base_lo: DDR hash table physical address (low 32) + * p[2] = word_1: global_mem_offset, hash_mask, key_size + * p[3] = word_2: miss FQID (set to 0 here, patched by ModifyMiss) + * + * The CDX microcode reads this format for CC lookup. + * Standard Result ADs do NOT work — CDX microcode ignores + * the standard FQID field and uses KG baseFqid instead + * (confirmed build #207: all frames discarded with QMan + * Invalid Enqueue State for FQID 65882). + */ + { + uint32_t v0, v1, v2, v3; + int retry; + + for (retry = 0; retry < 4; retry++) { + muram_wr32(&p[2], ptr->word_1); /* offset 8 */ + muram_wr32(&p[1], ptr->table_base_lo); /* offset 4 */ + muram_wr32(&p[3], ptr->word_2); /* offset 12 */ + muram_wr32(&p[0], ptr->word_0); /* offset 0 */ + muram_barrier(); + + v0 = muram_rd32(&p[0]); + v1 = muram_rd32(&p[1]); + v2 = muram_rd32(&p[2]); + v3 = muram_rd32(&p[3]); + if (v0 == ptr->word_0 && + v1 == ptr->table_base_lo && + v2 == ptr->word_1 && + v3 == ptr->word_2) + break; + + printf("fm_ehash: copy_td VERIFY FAIL attempt %d " + "AD=%p [%08x %08x %08x %08x] != " + "[%08x %08x %08x %08x]\n", + retry + 1, p, v0, v1, v2, v3, + ptr->word_0, ptr->table_base_lo, + ptr->word_1, ptr->word_2); + } + } + + /* Save MURAM address for AD — used by ModifyMissNextEngine later */ + info->h_Ad = (void *)p; +} + +/* + * ExternalHashTableAllocEntry — Allocate a new hash table entry. + */ +void * +ExternalHashTableAllocEntry(void *h_HashTbl) +{ + struct en_exthash_info *info; + void *entry; + + info = (struct en_exthash_info *)h_HashTbl; + if (info == NULL) + return (NULL); + + entry = XX_MallocSmart(sizeof(struct en_exthash_tbl_entry), + 0, EN_EHASH_ENTRY_ALIGN); + if (entry != NULL) + memset(entry, 0, sizeof(struct en_exthash_tbl_entry)); + else + REPORT_ERROR(MAJOR, E_NO_MEMORY, ("hash table entry")); + + return (entry); +} + +/* + * ExternalHashTableEntryFree — Free a hash table entry. + */ +void +ExternalHashTableEntryFree(void *entry) +{ + + if (entry != NULL) + XX_FreeSmart(entry); +} + +/* + * ExternalHashTableAddKey — Add an entry to the hash table. + * + * Returns the bucket index on success, -1 on failure. + */ +int +ExternalHashTableAddKey(void *h_HashTbl, uint8_t keySize, void *tbl_entry) +{ + struct en_exthash_info *info; + struct en_exthash_tbl_entry *first_entry; + struct en_exthash_tbl_entry *new_entry; + uint16_t index; + struct en_exthash_bucket *bucket; + t_Handle *h_Spinlock; + uint32_t intFlags; + int retval; + uint64_t phyaddr; + + SANITY_CHECK_RETURN_ERROR(h_HashTbl, E_INVALID_HANDLE); + SANITY_CHECK_RETURN_ERROR(tbl_entry, E_NULL_POINTER); + + new_entry = (struct en_exthash_tbl_entry *)tbl_entry; + info = (struct en_exthash_info *)h_HashTbl; + + if (info->table_base == NULL || info->pSpinlock == NULL) { + REPORT_ERROR(MAJOR, E_INVALID_HANDLE, + ("hash table not initialized (table_base=%p pSpinlock=%p)", + info->table_base, info->pSpinlock)); + return (-1); + } + + get_indexed_hash_bucket(keySize, &new_entry->hashentry.key[0], + info->hashshift, (uint16_t)info->hashmask, &index); + + bucket = (struct en_exthash_bucket *)info->table_base + index; + + h_Spinlock = *(info->pSpinlock + index); + intFlags = XX_LockIntrSpinlock(h_Spinlock); + + retval = index; + phyaddr = bucket->h; + + if (phyaddr) { + first_entry = XX_PhysToVirt(SwapUint64(phyaddr)); + if (find_entry_in_bucket(first_entry, + &new_entry->hashentry.key[0], keySize)) { + REPORT_ERROR(MAJOR, E_ALREADY_EXISTS, + ("hash table entry")); + retval = -1; + goto func_ret; + } + first_entry->prev = new_entry; + } else { + first_entry = NULL; + } + + /* Link new entry at head of bucket chain */ + new_entry->next = first_entry; + + /* Fill hardware next-entry pointer (byte-swapped physical addr) */ + phyaddr = SwapUint64(phyaddr); + new_entry->hashentry.next_entry_hi = + cpu_to_be16((phyaddr >> 32) & 0xffff); + new_entry->hashentry.next_entry_lo = + cpu_to_be32(phyaddr & 0xffffffff); + + /* Update bucket head to point to new entry */ + phyaddr = XX_VirtToPhys(new_entry); + bucket->h = SwapUint64(phyaddr); + +func_ret: + XX_UnlockIntrSpinlock(h_Spinlock, intFlags); + return (retval); +} + +/* + * ExternalHashTableDeleteKey — Remove an entry from the hash table. + * + * Returns 0 on success, -1 on failure. + */ +int +ExternalHashTableDeleteKey(void *h_HashTbl, uint16_t index, void *tbl_entry) +{ + struct en_exthash_info *info; + struct en_exthash_bucket *bucket; + struct en_exthash_tbl_entry *entry; + struct en_exthash_tbl_entry *temp_entry; + t_Handle *h_Spinlock; + uint32_t intFlags; + uint64_t phyaddr; + uint64_t update_entry; + + if (h_HashTbl == NULL || tbl_entry == NULL) + return (-1); + + info = (struct en_exthash_info *)h_HashTbl; + + if (info->table_base == NULL || info->pSpinlock == NULL) { + REPORT_ERROR(MAJOR, E_INVALID_HANDLE, + ("hash table not initialized in DeleteKey")); + return (-1); + } + + if (index > info->hashmask) { + REPORT_ERROR(MAJOR, E_INVALID_VALUE, + ("DeleteKey index %u exceeds hashmask %u", + (unsigned)index, (unsigned)info->hashmask)); + return (-1); + } + + bucket = (struct en_exthash_bucket *)info->table_base + index; + entry = (struct en_exthash_tbl_entry *)tbl_entry; + + h_Spinlock = *(info->pSpinlock + index); + intFlags = XX_LockIntrSpinlock(h_Spinlock); + + /* Mark entry as invalid for microcode */ + update_entry = SwapUint64(entry->hashentry.next_entry); + SET_INVALID_ENTRY_64BIT(update_entry); + entry->hashentry.next_entry = SwapUint64(update_entry); + + if (entry->prev != NULL) { + /* Not at head — unlink from middle/end */ + temp_entry = entry->prev; + temp_entry->next = entry->next; + if (entry->next != NULL) + entry->next->prev = temp_entry; + /* Update hardware next-entry pointer */ + update_entry = entry->hashentry.next_entry & ~0xffffULL; + temp_entry->hashentry.next_entry = + update_entry | temp_entry->hashentry.flags; + } else { + /* At head — update bucket pointer */ + if (entry->next != NULL) { + phyaddr = XX_VirtToPhys(entry->next); + bucket->h = SwapUint64(phyaddr); + entry->next->prev = NULL; + } else { + /* Last entry in bucket — clear to zero (empty) */ + bucket->h = 0; + } + } + + XX_UnlockIntrSpinlock(h_Spinlock, intFlags); + + if (FmPcdHcSync(info->pcd)) { + printf("fm_ehash: FmPcdHcSync failed in DeleteKey\n"); + return (-1); + } + + return (0); +} + +/* + * ExternalHashTableEntryGetStatsAndTS — Read entry stats and timestamp. + */ +int +ExternalHashTableEntryGetStatsAndTS(void *tbl_entry, + struct en_tbl_entry_stats *stats) +{ + struct en_exthash_tbl_entry *hash_node; + struct en_ehash_entry *entry; + uint16_t flags; + + hash_node = (struct en_exthash_tbl_entry *)tbl_entry; + if (hash_node == NULL) + return (-1); + + entry = &hash_node->hashentry; + flags = cpu_to_be16(entry->flags); + stats->flags = 0; + + if (GET_TIMESTAMP_ENABLE(flags)) { + stats->flags |= TIMESTAMP_VALID; + stats->timestamp = cpu_to_be32(entry->timestamp); + } + + if (GET_STATS_ENABLE(flags)) { + stats->flags |= STATS_VALID; + stats->pkts = be64_to_cpu(entry->packet_count); + stats->bytes = be64_to_cpu(entry->packet_bytes); + } + + return (0); +} + +/* + * ExternalHashTableModifyMissNextEngine — Change the miss action. + * + * Modifies the MURAM AD node directly (via info->h_Ad, set by + * copy_td_to_ccbase). ALL 4 words of the AD must be written in + * a single batch — partial writes corrupt the unwritten words + * (LS1046A MURAM / Normal-NC ARM64 store behavior). + * + * Uses info->node as the base (unchanged table_base_lo, word_1) + * and modifies word_0 (miss action) and word_2 (FQID/NIA). + * Also updates info->node so it stays in sync for future calls. + */ +t_Error +ExternalHashTableModifyMissNextEngine(t_Handle h_HashTbl, + t_FmPcdCcNextEngineParams *p_FmPcdCcNextEngineParams) +{ + struct en_exthash_info *info; + volatile uint32_t *p; + struct en_exthash_node *ptr; + + info = (struct en_exthash_info *)h_HashTbl; + if (info->h_Ad == NULL) { + printf("fm_ehash: ModifyMissNextEngine: h_Ad is NULL " + "(copy_td_to_ccbase not called?)\n"); + return (E_INVALID_STATE); + } + + ptr = &info->node; + + /* + * Enhanced hash AD miss action patching. + * + * Modify word_0 (miss_action bits [31:30]) and word_2 (FQID/NIA) + * while preserving table_base_lo and word_1 (hash table params). + * + * Build #208: reverted from standard Result AD format which the + * CDX microcode cannot interpret (build #207 showed all frames + * discarded with QMan Invalid Enqueue State for KG baseFqid). + */ + { + uint32_t fqid = 0; + + switch (p_FmPcdCcNextEngineParams->nextEngine) { + case e_FM_PCD_DONE: { + t_FmPcdCcNextEnqueueParams *enqparams = + &p_FmPcdCcNextEngineParams->params.enqueueParams; + if (enqparams->overrideFqid) + fqid = enqparams->newFqid & 0x00FFFFFF; + + /* Set miss_action to ENQUE, preserve other word_0 fields */ + ptr->word_0 = (ptr->word_0 & ~EHASH_W0_MISS_ACTION_MASK) | + EHASH_W0_MISS_ACTION(EN_EHASH_MISS_ACTION_ENQUE); + ptr->word_2 = fqid; + break; + } + default: + printf("fm_ehash: ModifyMiss: unhandled engine %d\n", + p_FmPcdCcNextEngineParams->nextEngine); + break; + } + + } + + /* + * Write the 16-byte AD to MURAM. + * Verify + retry in case of CCI-400/AXI flush timing. + */ + p = (volatile uint32_t *)info->h_Ad; + { + uint32_t v0, v1, v2, v3; + int retry; + + for (retry = 0; retry < 4; retry++) { + muram_wr32(&p[2], ptr->word_1); /* offset 8 */ + muram_wr32(&p[1], ptr->table_base_lo); /* offset 4 */ + muram_wr32(&p[3], ptr->word_2); /* offset 12 */ + muram_wr32(&p[0], ptr->word_0); /* offset 0 */ + muram_barrier(); + + v0 = muram_rd32(&p[0]); + v1 = muram_rd32(&p[1]); + v2 = muram_rd32(&p[2]); + v3 = muram_rd32(&p[3]); + if (v0 == ptr->word_0 && + v1 == ptr->table_base_lo && + v2 == ptr->word_1 && + v3 == ptr->word_2) + break; + + printf("fm_ehash: ModifyMiss AD=%p attempt %d " + "VERIFY FAIL [%08x %08x %08x %08x] != " + "[%08x %08x %08x %08x]\n", + info->h_Ad, retry + 1, + v0, v1, v2, v3, + ptr->word_0, ptr->table_base_lo, + ptr->word_1, ptr->word_2); + } + } + + /* + * Propagate miss action to CC tree copy entries. + * + * The CC tree fill logic (fm_cc.c CcRootBuild) copies entry 0 + * to unused slots (indices numOfEntries..15) via raw memcpy. + * These copies have the pre-ModifyMiss state because + * copy_td_to_ccbase only tracks a single h_Ad per hash table. + * + * Scan all 16 CC tree entries: any entry (other than h_Ad + * itself) that is a copy and needs its miss action updated. + * + * CC tree is 256-byte aligned (FM_PCD_CC_TREE_ADDR_ALIGN). + */ + { + uintptr_t tree_base = + (uintptr_t)info->h_Ad & ~(uintptr_t)0xFF; + int j; + + for (j = 0; j < FM_PCD_MAX_NUM_OF_CC_GROUPS; j++) { + volatile uint32_t *ep = (volatile uint32_t *) + (tree_base + j * FM_PCD_CC_AD_ENTRY_SIZE); + if (ep == (volatile uint32_t *)info->h_Ad) + continue; /* skip the entry we just wrote */ + if (muram_rd32(&ep[1]) == ptr->table_base_lo) { + /* Copy with same table — update all 4 words */ + muram_wr32(&ep[2], ptr->word_1); + muram_wr32(&ep[1], ptr->table_base_lo); + muram_wr32(&ep[3], ptr->word_2); + muram_wr32(&ep[0], ptr->word_0); + muram_barrier(); + } + } + } + + return (E_OK); +} + +/* + * ExternalHashTableFmPcdHcSync — Flush PCD Host Command channel. + */ +int +ExternalHashTableFmPcdHcSync(void *h_HashTbl) +{ + struct en_exthash_info *info; + + info = (struct en_exthash_info *)h_HashTbl; + if (FmPcdHcSync(info->pcd)) { + printf("fm_ehash: FmPcdHcSync failed\n"); + return (-1); + } + return (0); +} + +/* + * ExternalHashTableDelete — Destroy a table and free all resources. + */ +void +ExternalHashTableDelete(t_Handle h_HashTbl) +{ + + if (h_HashTbl != NULL) + delete_ehash_info((struct en_exthash_info *)h_HashTbl); +} + +/* ================================================================ + * Global MURAM features — read/write the global data area at + * pool + EN_INTERNAL_BUFF_POOL_SIZE (en_exthash_global_mem). + * + * All fields are big-endian in MURAM. Use GET_UINT32/WRITE_UINT32 + * for 32-bit fields, GET_UINT8/WRITE_UINT8 for byte fields. + * ================================================================ */ + +int32_t +ExternalHashGetSECfailureStats(en_SEC_failure_stats *stats) +{ + volatile en_SEC_failure_stats *src; + + if (stats == NULL) + return (-1); + if (ehash_global_mem == NULL) { + memset(stats, 0, sizeof(*stats)); + return (-1); + } + + src = &ehash_global_mem->SEC_failure_stats; + + stats->icv_failures = GET_UINT32(src->icv_failures); + stats->hw_errs = GET_UINT32(src->hw_errs); + stats->CCM_AAD_size_errs = GET_UINT32(src->CCM_AAD_size_errs); + stats->anti_replay_late_errs = GET_UINT32(src->anti_replay_late_errs); + stats->anti_replay_replay_errs = GET_UINT32(src->anti_replay_replay_errs); + stats->seq_num_overflows = GET_UINT32(src->seq_num_overflows); + stats->DMA_errs = GET_UINT32(src->DMA_errs); + stats->DECO_watchdog_timer_timedout_errs = GET_UINT32(src->DECO_watchdog_timer_timedout_errs); + stats->input_frame_read_errs = GET_UINT32(src->input_frame_read_errs); + stats->protocol_format_errs = GET_UINT32(src->protocol_format_errs); + stats->ipsec_ttl_zero_errs = GET_UINT32(src->ipsec_ttl_zero_errs); + stats->ipsec_pad_chk_failures = GET_UINT32(src->ipsec_pad_chk_failures); + stats->output_frame_length_rollover_errs = GET_UINT32(src->output_frame_length_rollover_errs); + stats->tbl_buff_too_small_errs = GET_UINT32(src->tbl_buff_too_small_errs); + stats->tbl_buff_pool_depletion_errs = GET_UINT32(src->tbl_buff_pool_depletion_errs); + stats->output_frame_too_large_errs = GET_UINT32(src->output_frame_too_large_errs); + stats->cmpnd_frame_write_errs = GET_UINT32(src->cmpnd_frame_write_errs); + stats->buff_too_small_errs = GET_UINT32(src->buff_too_small_errs); + stats->buff_pool_depletion_errs = GET_UINT32(src->buff_pool_depletion_errs); + stats->output_frame_write_errs = GET_UINT32(src->output_frame_write_errs); + stats->cmpnd_frame_read_errs = GET_UINT32(src->cmpnd_frame_read_errs); + stats->prehdr_read_errs = GET_UINT32(src->prehdr_read_errs); + stats->other_errs = GET_UINT32(src->other_errs); + + return (0); +} + +int32_t +ExternalHashResetSECfailureStats(void) +{ + volatile en_SEC_failure_stats *dst; + + if (ehash_global_mem == NULL) + return (-1); + + dst = &ehash_global_mem->SEC_failure_stats; + + WRITE_UINT32(dst->icv_failures, 0); + WRITE_UINT32(dst->hw_errs, 0); + WRITE_UINT32(dst->CCM_AAD_size_errs, 0); + WRITE_UINT32(dst->anti_replay_late_errs, 0); + WRITE_UINT32(dst->anti_replay_replay_errs, 0); + WRITE_UINT32(dst->seq_num_overflows, 0); + WRITE_UINT32(dst->DMA_errs, 0); + WRITE_UINT32(dst->DECO_watchdog_timer_timedout_errs, 0); + WRITE_UINT32(dst->input_frame_read_errs, 0); + WRITE_UINT32(dst->protocol_format_errs, 0); + WRITE_UINT32(dst->ipsec_ttl_zero_errs, 0); + WRITE_UINT32(dst->ipsec_pad_chk_failures, 0); + WRITE_UINT32(dst->output_frame_length_rollover_errs, 0); + WRITE_UINT32(dst->tbl_buff_too_small_errs, 0); + WRITE_UINT32(dst->tbl_buff_pool_depletion_errs, 0); + WRITE_UINT32(dst->output_frame_too_large_errs, 0); + WRITE_UINT32(dst->cmpnd_frame_write_errs, 0); + WRITE_UINT32(dst->buff_too_small_errs, 0); + WRITE_UINT32(dst->buff_pool_depletion_errs, 0); + WRITE_UINT32(dst->output_frame_write_errs, 0); + WRITE_UINT32(dst->cmpnd_frame_read_errs, 0); + WRITE_UINT32(dst->prehdr_read_errs, 0); + WRITE_UINT32(dst->other_errs, 0); + + return (0); +} + +int32_t +ExternalHashSetDscpVlanpcpMapCfg(en_dscp_vlanpcp_map_cfg *map) +{ + volatile uint8_t *dst; + int ii; + + if (map == NULL) + return (-1); + if (ehash_global_mem == NULL) + return (-1); + + dst = ehash_global_mem->dscp_vlanpcp_map.dscp_vlanpcp; + for (ii = 0; ii <= MAX_VLAN_PCP; ii++) + WRITE_UINT8(dst[ii], map->dscp_vlanpcp[ii]); + + return (0); +} + +int32_t +ExternalHashGetDscpVlanpcpMapCfg(en_dscp_vlanpcp_map_cfg *map) +{ + volatile uint8_t *src; + int ii; + + if (map == NULL) + return (-1); + if (ehash_global_mem == NULL) { + memset(map, 0, sizeof(*map)); + return (-1); + } + + src = ehash_global_mem->dscp_vlanpcp_map.dscp_vlanpcp; + for (ii = 0; ii <= MAX_VLAN_PCP; ii++) + map->dscp_vlanpcp[ii] = GET_UINT8(src[ii]); + + return (0); +} + +/* + * ExternalHashReasslyTableExists — Check if a reassembly table exists. + * + * Returns 1 if the specified reassembly table (IPv4 or IPv6) was + * created during PCD setup, 0 otherwise. Used by the CDX module + * to skip resource allocation when reassembly is not configured. + */ +int +ExternalHashReasslyTableExists(uint32_t type) +{ + struct en_exthash_info *tbl_info; + + switch (type) { + case EHASH_IPV4_REASSM_TABLE: + tbl_info = ehash_ipv4_reassly_tbl; + break; + case EHASH_IPV6_REASSM_TABLE: + tbl_info = ehash_ipv6_reassly_tbl; + break; + default: + return (0); + } + + return (tbl_info != NULL && tbl_info->ip_reassem_info != NULL); +} + +/* + * ExternalHashSetReasslyPool — Configure reassembly buffer pools. + * + * Called from CDX module (cdx_reassm_freebsd.c) to program BMan pool + * IDs, buffer sizes, timeout, and TX-confirm FQIDs into the MURAM + * ip_reassembly_params structure for IPv4/IPv6 reassembly tables. + * + * The ip_reassem_info pointer is set during ExternalHashTableSet() + * when a REASSM table is created. If no REASSM table exists (e.g. + * dpa_app PCD XML doesn't include reassembly), this returns -1. + */ +int +ExternalHashSetReasslyPool(uint32_t type, uint32_t ctx_bpid, + uint32_t ctx_bpsize, uint32_t frag_bpid, uint32_t frag_size, + uint32_t txc_fqid, uint32_t ipr_timer_freq) +{ + struct en_exthash_info *tbl_info; + volatile struct ip_reassembly_params *params; + uint32_t timeout; + + switch (type) { + case EHASH_IPV4_REASSM_TABLE: + tbl_info = ehash_ipv4_reassly_tbl; + break; + case EHASH_IPV6_REASSM_TABLE: + tbl_info = ehash_ipv6_reassly_tbl; + break; + default: + printf("fm_ehash: SetReasslyPool: invalid type %u\n", type); + return (-1); + } + + if (tbl_info == NULL || tbl_info->ip_reassem_info == NULL) + return (-1); + + params = (volatile struct ip_reassembly_params *)tbl_info->ip_reassem_info; + + printf("fm_ehash: SetReasslyPool type %u: ctx_bpid=%u frag_bpid=%u " + "timer_freq=%u txc_fqid=%u\n", + type, ctx_bpid, frag_bpid, ipr_timer_freq, txc_fqid); + + WRITE_UINT32(params->reassem_bpid, ctx_bpid); + WRITE_UINT32(params->reassem_bsize, ctx_bpsize); + WRITE_UINT32(params->frag_bpid, frag_bpid); + WRITE_UINT32(params->frag_bsize, frag_size); + WRITE_UINT32(params->txc_fqid, txc_fqid); + + /* Convert timeout from absolute to timer-frequency-relative. + * The existing timeout_val was set by the PCD configuration + * in absolute units; divide by timer frequency. */ + if (ipr_timer_freq != 0) { + timeout = GET_UINT32(params->timeout_val); + WRITE_UINT32(params->timeout_val, timeout / ipr_timer_freq); + } + + return (0); +} + +void +ipr_update_timestamp(void) +{ + + /* Timestamp updates handled by cdx_ehash_update_timestamp() */ +} + +/* + * cdx_ehash_update_timestamp — Write current time to MURAM timestamp slot. + * + * Called from the CDX timer thread (via dpa_update_timestamp) on every + * tick. FMan microcode reads these slots and copies the raw value into + * each hash entry's timestamp field on packet match (MURAM-to-MURAM). + * + * NO byte-swap: Linux SDK's FM_PCD_UpdateExtTimeStamp does a raw store. + * CDX software reads the timestamp back with the same raw access, so + * both sides see the same byte pattern. + */ +void +cdx_ehash_update_timestamp(uint32_t id, uint32_t value) +{ + + if (ehash_ts_virt == NULL || id >= MAX_EXT_TS_TIMERS) + return; + *(volatile uint32_t *)&ehash_ts_virt[id] = value; + __asm __volatile("dsb sy" ::: "memory"); +} + +/* + * cdx_ehash_get_timestamp_addr — Return MURAM physical offset for a + * timestamp slot. + */ +uint32_t +cdx_ehash_get_timestamp_addr(uint32_t id) +{ + + if (ehash_ts_virt == NULL || id >= MAX_EXT_TS_TIMERS) + return (0); + return ((uint32_t)(ehash_ts_phys + id * sizeof(uint32_t) - + ehash_muram_phys_base)); +} + +/* + * ehash_dump_muram_diag — Dump MURAM state for stall diagnosis. + * + * Prints global data area, timestamp slots, and first internal + * buffer pool slot. Safe to call from callout context. + */ +static void +ehash_dump_muram_diag(void) +{ + uint8_t *global_data; + volatile uint32_t *pool32; + + if (ehash_int_muram_ptr == NULL) { + printf("fm_ehash: diag: pool not initialized\n"); + return; + } + + /* Global data area: at pool + EN_INTERNAL_BUFF_POOL_SIZE */ + global_data = (uint8_t *)ehash_int_muram_ptr + + EN_INTERNAL_BUFF_POOL_SIZE; + printf("fm_ehash: global_data (dscp_vlanpcp_map): " + "%02x %02x %02x %02x %02x %02x %02x %02x\n", + global_data[0], global_data[1], global_data[2], global_data[3], + global_data[4], global_data[5], global_data[6], global_data[7]); + /* SEC failure stats — 23 × uint32_t starting at global_data+8. + * CDX microcode writes these in BE (via WRITE_UINT32), so read + * with GET_UINT32 for correct byte order. */ + { + static const char *stat_names[] = { + "icv_fail", "hw_err", "ccm_aad", "ar_late", + "ar_replay", "seq_ovfl", "dma_err", "deco_wdt", + "in_rd_err", "proto_fmt", "ttl_zero", "pad_chk", + "out_len_roll", "tbl_buf_small", "tbl_pool_depl", + "out_too_large", "cmpnd_wr", "buf_small", + "pool_depl", "out_wr", "cmpnd_rd", + "prehdr_rd", "other" + }; + volatile uint32_t *sp = + (volatile uint32_t *)(global_data + 8); + int si, any = 0; + for (si = 0; si < 23; si++) { + uint32_t v = GET_UINT32(sp[si]); + if (v != 0) { + printf("fm_ehash: SEC stat[%d] %s = %u\n", + si, stat_names[si], v); + any = 1; + } + } + if (!any) + printf("fm_ehash: SEC stats: all zero\n"); + } + + /* Timestamp slots (separate allocation) */ + if (ehash_ts_virt != NULL) + printf("fm_ehash: ts[0..3]: %08x %08x %08x %08x " + "(raw, no swap)\n", + *(volatile uint32_t *)&ehash_ts_virt[0], + *(volatile uint32_t *)&ehash_ts_virt[1], + *(volatile uint32_t *)&ehash_ts_virt[2], + *(volatile uint32_t *)&ehash_ts_virt[3]); + else + printf("fm_ehash: ts: not allocated\n"); + + /* Internal buffer pool — first 4 slots (each 256 bytes). + * Read with GET_UINT32 since microcode writes in BE. */ + pool32 = (volatile uint32_t *)ehash_int_muram_ptr; + { + int slot; + for (slot = 0; slot < 4; slot++) { + int base = slot * 64; /* 256B / 4B per word */ + printf("fm_ehash: pool[%d]: %08x %08x %08x %08x\n", + slot, + GET_UINT32(pool32[base + 0]), + GET_UINT32(pool32[base + 1]), + GET_UINT32(pool32[base + 2]), + GET_UINT32(pool32[base + 3])); + } + } + + /* DDR hash table bucket[0] verification */ + if (ehash_first_table_base != NULL) { + volatile uint64_t *bkt = + (volatile uint64_t *)ehash_first_table_base; + printf("fm_ehash: DDR bucket[0] (cached): " + "%016lx %016lx\n", bkt[0], bkt[1]); + /* Writeback + invalidate to force re-read from DDR */ + cpu_dcache_wbinv_range((vm_offset_t)ehash_first_table_base, 64); + printf("fm_ehash: DDR bucket[0] (after wbinv): " + "%016lx %016lx\n", bkt[0], bkt[1]); + } +} + +/* ================================================================ + * Debug + * ================================================================ */ + +static void +EhashTableWalk(void *h_HashTbl) +{ + struct en_exthash_info *info; + struct en_exthash_tbl_entry *entry; + struct en_exthash_bucket *bucket; + uint32_t ii; + uint32_t num_entries = 0; + uint32_t max_collisions = 0; + + info = (struct en_exthash_info *)h_HashTbl; + if (info == NULL) + return; + + bucket = (struct en_exthash_bucket *)info->table_base; + for (ii = 0; ii <= info->hashmask; ii++) { + if (bucket->h != 0) { + uint32_t bucket_entries = 0; + + entry = XX_PhysToVirt(SwapUint64(bucket->h)); + while (entry != NULL) { + bucket_entries++; + entry = entry->next; + } + num_entries += bucket_entries; + if (bucket_entries > max_collisions) + max_collisions = bucket_entries; + } + bucket++; + } + + printf("fm_ehash: table %p — %u entries, max collisions %u, " + "%u buckets\n", info, num_entries, max_collisions, + info->hashmask + 1); +} diff --git a/sys/contrib/ncsw/Peripherals/FM/Pcd/fm_kg.c b/sys/contrib/ncsw/Peripherals/FM/Pcd/fm_kg.c index f183d2f9ee0..08ffdc821b3 100644 --- a/sys/contrib/ncsw/Peripherals/FM/Pcd/fm_kg.c +++ b/sys/contrib/ncsw/Peripherals/FM/Pcd/fm_kg.c @@ -1035,6 +1035,12 @@ static t_Error BuildSchemeRegs(t_FmPcdKgScheme *p_Scheme, memset(swDefaults, 0, NUM_OF_SW_DEFAULTS*sizeof(t_FmPcdKgExtractDflt)); memset(p_SchemeRegs, 0, sizeof(struct fman_kg_scheme_regs)); + /* Default: disable policer profile generation. PLCR and + * CC-with-plcrNext cases below overwrite kgse_ppc when PGEN + * is actually needed. Without this, kgse_ppc=0 leaves + * PP_NO_GEN clear → implicit PGEN with profile 0. */ + p_SchemeRegs->kgse_ppc = KG_SCH_PP_NO_GEN; + if (p_SchemeParams->netEnvParams.numOfDistinctionUnits > FM_PCD_MAX_NUM_OF_DISTINCTION_UNITS) RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("numOfDistinctionUnits should not exceed %d", FM_PCD_MAX_NUM_OF_DISTINCTION_UNITS)); @@ -1250,7 +1256,13 @@ static t_Error BuildSchemeRegs(t_FmPcdKgScheme *p_Scheme, } p_SchemeRegs->kgse_mode = tmpReg; - p_SchemeRegs->kgse_mv = p_Scheme->matchVector; + /* SCHEME_ALWAYS_DIRECT (0xFFFFFFFF) means "match all frames" in NCSW + * software, but FMan KG hardware interprets the MV register literally: + * (classification_vector & kgse_mv) == kgse_mv. With 0xFFFFFFFF, all + * 32 classification bits must be set — no frame can ever match. + * Write 0 instead: the hardware treats MV=0 as "always match." */ + p_SchemeRegs->kgse_mv = (p_Scheme->matchVector == SCHEME_ALWAYS_DIRECT) + ? 0 : p_Scheme->matchVector; #if (DPAA_VERSION >= 11) if (p_SchemeParams->overrideStorageProfile) @@ -1569,6 +1581,17 @@ static t_Error BuildSchemeRegs(t_FmPcdKgScheme *p_Scheme, generic = FALSE; } } + /* + * CDX/ASK flow offload requires the port ID to always be + * present as the first byte of every KG key output. The + * PCD XML only adds it to + * extractedOrs (for FQID modification), but the CDX hash + * table key (union dpa_key) expects portid at byte 0. + * Force KG_SCH_KN_PORT_ID into the known-fields set so + * the hardware extracts it as known-field ID 0 (bit 31, + * highest priority → first in key output). + */ + knownTmp |= KG_SCH_KN_PORT_ID; p_SchemeRegs->kgse_ekfc = knownTmp; selectTmp = 0; diff --git a/sys/contrib/ncsw/Peripherals/FM/Pcd/fm_pcd.h b/sys/contrib/ncsw/Peripherals/FM/Pcd/fm_pcd.h index 27ec9c5bf67..d1d4acd009c 100644 --- a/sys/contrib/ncsw/Peripherals/FM/Pcd/fm_pcd.h +++ b/sys/contrib/ncsw/Peripherals/FM/Pcd/fm_pcd.h @@ -437,6 +437,7 @@ t_Handle PrsConfig(t_FmPcd *p_FmPcd,t_FmPcdParams *p_FmPcdParams); t_Error PrsInit(t_FmPcd *p_FmPcd); void PrsEnable(t_FmPcd *p_FmPcd); void PrsDisable(t_FmPcd *p_FmPcd); +int PrsIsEnabled(t_FmPcd *p_FmPcd); void PrsFree(t_FmPcd *p_FmPcd ); t_Error PrsIncludePortInStatistics(t_FmPcd *p_FmPcd, uint8_t hardwarePortId, bool include); @@ -540,4 +541,6 @@ static __inline__ void FmPcdLockUnlock(t_FmPcdLock *p_Lock) } +t_Handle FM_PCD_GetHcPort(t_Handle h_FmPcd); + #endif /* __FM_PCD_H */ diff --git a/sys/contrib/ncsw/Peripherals/FM/Pcd/fm_plcr.c b/sys/contrib/ncsw/Peripherals/FM/Pcd/fm_plcr.c index f23d8b8168b..db687ad8220 100644 --- a/sys/contrib/ncsw/Peripherals/FM/Pcd/fm_plcr.c +++ b/sys/contrib/ncsw/Peripherals/FM/Pcd/fm_plcr.c @@ -158,6 +158,14 @@ static t_Error SetProfileNia(t_FmPcd *p_FmPcd, e_FmPcdEngine nextEngine, u_FmPcd RETURN_ERROR(MAJOR, E_INVALID_STATE, ("Invalid profile ")); nia |= NIA_ENG_PLCR | NIA_PLCR_ABSOLUTE | absoluteProfileId; break; + case e_FM_PCD_PRS: + /* Post-policer: re-enter PCD pipeline via KG engine */ + nia |= 0x00480200; + break; + case e_FM_PCD_CC: + /* Post-policer: coarse classifier engine */ + nia |= 0x26; + break; default: RETURN_ERROR(MAJOR, E_INVALID_SELECTION, NO_MSG); } diff --git a/sys/contrib/ncsw/Peripherals/FM/Pcd/fm_replic.c b/sys/contrib/ncsw/Peripherals/FM/Pcd/fm_replic.c index ee82f73014b..6bf8cc09694 100644 --- a/sys/contrib/ncsw/Peripherals/FM/Pcd/fm_replic.c +++ b/sys/contrib/ncsw/Peripherals/FM/Pcd/fm_replic.c @@ -144,7 +144,7 @@ static t_FmPcdFrmReplicMember *GetAvailableMember(t_FmPcdFrmReplicGroup *p_Repli if (!LIST_IsEmpty(&p_ReplicGroup->availableMembersList)) { - p_Next = LIST_FIRST(&p_ReplicGroup->availableMembersList); + p_Next = NCSW_LIST_FIRST(&p_ReplicGroup->availableMembersList); p_ReplicMember = LIST_OBJECT(p_Next, t_FmPcdFrmReplicMember, node); ASSERT_COND(p_ReplicMember); LIST_DelAndInit(p_Next); @@ -643,7 +643,7 @@ void FrmReplicGroupUpdateOwner(t_Handle h_ReplicGroup, } } -t_Error FrmReplicGroupTryLock(t_Handle h_ReplicGroup) +static t_Error FrmReplicGroupTryLock(t_Handle h_ReplicGroup) { t_FmPcdFrmReplicGroup *p_ReplicGroup = (t_FmPcdFrmReplicGroup *)h_ReplicGroup; @@ -655,7 +655,7 @@ t_Error FrmReplicGroupTryLock(t_Handle h_ReplicGroup) return ERROR_CODE(E_BUSY); } -void FrmReplicGroupUnlock(t_Handle h_ReplicGroup) +static void FrmReplicGroupUnlock(t_Handle h_ReplicGroup) { t_FmPcdFrmReplicGroup *p_ReplicGroup = (t_FmPcdFrmReplicGroup *)h_ReplicGroup; diff --git a/sys/contrib/ncsw/Peripherals/FM/Port/fm_port.c b/sys/contrib/ncsw/Peripherals/FM/Port/fm_port.c index 79419eab453..f46cb2c840b 100644 --- a/sys/contrib/ncsw/Peripherals/FM/Port/fm_port.c +++ b/sys/contrib/ncsw/Peripherals/FM/Port/fm_port.c @@ -36,6 +36,9 @@ @Description FM driver routines implementation. *//***************************************************************************/ +#ifdef __FreeBSD__ +#endif + #include "error_ext.h" #include "std_ext.h" #include "string_ext.h" @@ -1349,7 +1352,7 @@ static t_Error SetPcd(t_FmPort *p_FmPort, t_FmPortPcdParams *p_PcdParams) } /* if CC is used directly after BMI */ - if ((p_PcdParams->pcdSupport == e_FM_PORT_PCD_SUPPORT_CC_ONLY) + if (p_PcdParams->pcdSupport == e_FM_PORT_PCD_SUPPORT_CC_ONLY #ifdef FM_CAPWAP_SUPPORT || (p_PcdParams->pcdSupport == e_FM_PORT_PCD_SUPPORT_CC_AND_KG) || (p_PcdParams->pcdSupport == e_FM_PORT_PCD_SUPPORT_CC_AND_KG_AND_PLCR) @@ -5271,6 +5274,7 @@ t_Error FM_PORT_SetPCD(t_Handle h_FmPort, t_FmPortPcdParams *p_PcdParam) RETURN_ERROR(MAJOR, err, NO_MSG); } + /* Diagnostic: dump all BMI NIA registers after SetPCD */ RELEASE_LOCK(p_FmPort->lock); return err; @@ -5668,7 +5672,7 @@ static t_Error FmPortConfigAutoResForDeepSleepSupport1(t_FmPort *p_FmPort) return E_OK; } -t_FmPortDsarTablesSizes* FM_PORT_GetDsarTablesMaxSizes(t_Handle h_FmPortRx) +static t_FmPortDsarTablesSizes* FM_PORT_GetDsarTablesMaxSizes(t_Handle h_FmPortRx) { t_FmPort *p_FmPort = (t_FmPort *)h_FmPortRx; return p_FmPort->deepSleepVars.autoResMaxSizes; diff --git a/sys/contrib/ncsw/Peripherals/FM/fm_ncsw.c b/sys/contrib/ncsw/Peripherals/FM/fm_ncsw.c index 884bc45edd3..33915989b1e 100644 --- a/sys/contrib/ncsw/Peripherals/FM/fm_ncsw.c +++ b/sys/contrib/ncsw/Peripherals/FM/fm_ncsw.c @@ -88,8 +88,11 @@ static bool IsFmanCtrlCodeLoaded(t_Fm *p_Fm) static t_Error CheckFmParameters(t_Fm *p_Fm) { +#ifndef __aarch64__ + /* On ARM64, U-Boot preloads FMan microcode into IRAM; reuse it */ if (IsFmanCtrlCodeLoaded(p_Fm) && !p_Fm->resetOnInit) RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("Old FMan CTRL code is loaded; FM must be reset!")); +#endif #if (DPAA_VERSION < 11) if (!p_Fm->p_FmDriverParam->dma_axi_dbg_num_of_beats || (p_Fm->p_FmDriverParam->dma_axi_dbg_num_of_beats > DMA_MODE_MAX_AXI_DBG_NUM_OF_BEATS)) @@ -3434,7 +3437,7 @@ t_Handle FM_Config(t_FmParams *p_FmParam) #ifdef FM_AID_MODE_NO_TNUM_SW005 if (p_Fm->p_FmStateStruct->revInfo.majorRev >= 6) - p_Fm->p_FmDriverParam->dma_aid_mode = e_FM_DMA_AID_OUT_PORT_ID; + p_Fm->p_FmDriverParam->dma_aid_mode = E_FMAN_DMA_AID_OUT_PORT_ID; #endif /* FM_AID_MODE_NO_TNUM_SW005 */ #ifndef FM_QMI_NO_DEQ_OPTIONS_SUPPORT if (p_Fm->p_FmStateStruct->revInfo.majorRev != 4) @@ -3568,12 +3571,15 @@ t_Error FM_Init(t_Handle h_Fm) if (!p_Fm->resetOnInit) /* Skip operations done in errata workaround */ { #endif /* FM_UCODE_NOT_RESET_ERRATA_BUGZILLA6173 */ - /* Load FMan-Controller code to IRAM */ + /* Load FMan-Controller code to IRAM (skip if no firmware provided, + e.g. when U-Boot has already loaded microcode) */ + if (p_Fm->firmware.p_Code) + { + ClearIRam(p_Fm); - ClearIRam(p_Fm); - - if (p_Fm->firmware.p_Code && (LoadFmanCtrlCode(p_Fm) != E_OK)) - RETURN_ERROR(MAJOR, E_INVALID_STATE, NO_MSG); + if (LoadFmanCtrlCode(p_Fm) != E_OK) + RETURN_ERROR(MAJOR, E_INVALID_STATE, NO_MSG); + } #ifdef FM_UCODE_NOT_RESET_ERRATA_BUGZILLA6173 } #endif /* FM_UCODE_NOT_RESET_ERRATA_BUGZILLA6173 */ @@ -4825,6 +4831,86 @@ uint32_t FM_GetCounter(t_Handle h_Fm, e_FmCounters counter) return fman_get_counter(&fman_rg, fsl_counter); } +#ifdef __aarch64__ +void FM_ErrorDiag(t_Handle h_Fm, uint8_t hwPortId) +{ + t_Fm *p = (t_Fm *)h_Fm; + uint32_t ps, epi, cld, npi, gs, ts, eie, dmsr, ievr; + uint32_t dmtah, dmtal; + + /* FPM: port stall status + error pending */ + ps = ioread32be(&p->p_FmFpmRegs->fmfp_ps[hwPortId]); + epi = ioread32be(&p->p_FmFpmRegs->fm_epi); + cld = ioread32be(&p->p_FmFpmRegs->fm_cld); + npi = ioread32be(&p->p_FmFpmRegs->fm_npi); + + /* QMI: global status + task status + error */ + gs = ioread32be(&p->p_FmQmiRegs->fmqm_gs); + ts = ioread32be(&p->p_FmQmiRegs->fmqm_ts); + eie = ioread32be(&p->p_FmQmiRegs->fmqm_eie); + + /* DMA: status + last transfer address */ + dmsr = ioread32be(&p->p_FmDmaRegs->fmdmsr); + dmtah = ioread32be(&p->p_FmDmaRegs->fmdmtah); + dmtal = ioread32be(&p->p_FmDmaRegs->fmdmtal); + + /* BMI: interrupt event */ + ievr = ioread32be(&p->p_FmBmiRegs->fmbm_ievr); + + printf("fman: FPM port[%u] ps=0x%08x %s\n", + hwPortId, ps, (ps & 0x00800000) ? "STALLED" : "ok"); + printf("fman: FPM epi=0x%08x npi=0x%08x cld=0x%08x\n", epi, npi, cld); + printf("fman: QMI gs=0x%08x ts=0x%08x eie=0x%08x\n", gs, ts, eie); + printf("fman: DMA sr=0x%08x addr=0x%08x%08x\n", dmsr, dmtah, dmtal); + printf("fman: BMI ievr=0x%08x\n", ievr); +} + +void FM_TaskStatusDiag(t_Handle h_Fm, uint8_t hwPortId) +{ + t_Fm *p = (t_Fm *)h_Fm; + uint32_t pp, ts; + int t, port_tasks = 0, total_active = 0; + uint8_t port_count[256]; + int i, dumped = 0; + + if (hwPortId == 0 || hwPortId > 63) + return; + + memset(port_count, 0, sizeof(port_count)); + + /* Read configured tasks from BMI Port Parameters */ + pp = ioread32be(&p->p_FmBmiRegs->fmbm_pp[hwPortId - 1]); + printf("fman: BMI pp[%u]=0x%08x (tasks=%u, extra=%u)\n", + hwPortId, pp, + ((pp >> 24) & 0x3f) + 1, + (pp >> 16) & 0xf); + + /* Scan FPM task status registers — dump first 8 non-zero raw values */ + for (t = 0; t < 128; t++) { + ts = ioread32be(&p->p_FmFpmRegs->fmfp_ts[t]); + if (ts != 0) { + uint8_t owner = (ts >> 24) & 0xff; + total_active++; + port_count[owner]++; + if (owner == hwPortId) + port_tasks++; + if (dumped < 8) { + printf("fman: ts[%d]=0x%08x (owner=%u)\n", t, ts, owner); + dumped++; + } + } + } + + /* Print per-port task breakdown for all ports with active tasks */ + printf("fman: task breakdown:"); + for (i = 0; i < 256; i++) { + if (port_count[i] > 0) + printf(" port%d=%d", i, port_count[i]); + } + printf(" (total=%d, port%u=%d)\n", total_active, hwPortId, port_tasks); +} +#endif + t_Error FM_ModifyCounter(t_Handle h_Fm, e_FmCounters counter, uint32_t val) { t_Fm *p_Fm = (t_Fm*)h_Fm; @@ -5191,7 +5277,7 @@ t_Handle FmGetPcd(t_Handle h_Fm) extern void *g_MemacRegs; void fm_clk_down(void); uint32_t fman_memac_get_event(void *regs, uint32_t ev_mask); -void FM_ChangeClock(t_Handle h_Fm, int hardwarePortId) +static void FM_ChangeClock(t_Handle h_Fm, int hardwarePortId) { int macId; uint32_t event, rcr; diff --git a/sys/contrib/ncsw/Peripherals/FM/inc/fm_common.h b/sys/contrib/ncsw/Peripherals/FM/inc/fm_common.h index 81a25e976b6..354e7277389 100644 --- a/sys/contrib/ncsw/Peripherals/FM/inc/fm_common.h +++ b/sys/contrib/ncsw/Peripherals/FM/inc/fm_common.h @@ -52,7 +52,8 @@ #define IP_OFFLOAD_PACKAGE_NUMBER 106 #define CAPWAP_OFFLOAD_PACKAGE_NUMBER 108 -#define IS_OFFLOAD_PACKAGE(num) ((num == IP_OFFLOAD_PACKAGE_NUMBER) || (num == CAPWAP_OFFLOAD_PACKAGE_NUMBER)) +#define ASK_UCODE_PACKAGE_NUMBER 209 +#define IS_OFFLOAD_PACKAGE(num) ((num == IP_OFFLOAD_PACKAGE_NUMBER) || (num == CAPWAP_OFFLOAD_PACKAGE_NUMBER) || (num >= ASK_UCODE_PACKAGE_NUMBER)) @@ -189,7 +190,13 @@ typedef _Packed struct t_FmPcdCtrlParamsPage { volatile uint32_t discardMask; volatile uint8_t reserved3[4]; volatile uint32_t postBmiFetchNia; +#if (DPAA_VERSION >= 11) + volatile uint32_t internalFEBufferManagementIndexAddr; + volatile uint32_t internalFEBufferDepletionCounter; + volatile uint8_t reserved4[164]; +#else volatile uint8_t reserved4[172]; +#endif } _PackedType t_FmPcdCtrlParamsPage; diff --git a/sys/contrib/ncsw/Peripherals/QM/qm.c b/sys/contrib/ncsw/Peripherals/QM/qm.c index ed3049f0a31..dbe25ccb364 100644 --- a/sys/contrib/ncsw/Peripherals/QM/qm.c +++ b/sys/contrib/ncsw/Peripherals/QM/qm.c @@ -295,9 +295,9 @@ static uint32_t ReserveFqids(t_Qm *p_Qm, uint32_t size, uint32_t alignment, bool static void FreeInitResources(t_Qm *p_Qm) { - if (p_Qm->p_FqdBase) + if (p_Qm->p_FqdBase && !p_Qm->fqdExternal) XX_FreeSmart(p_Qm->p_FqdBase); - if (p_Qm->p_PfdrBase) + if (p_Qm->p_PfdrBase && !p_Qm->pfdrExternal) XX_FreeSmart(p_Qm->p_PfdrBase); if (p_Qm->h_Session) XX_IpcFreeSession(p_Qm->h_Session); @@ -705,6 +705,10 @@ t_Handle QM_Config(t_QmParam *p_QmParam) p_Qm->p_QmDriverParams->pfdrThreshold = DEFAULT_pfdrThreshold; p_Qm->p_QmDriverParams->sfdrThreshold = DEFAULT_sfdrThreshold; p_Qm->p_QmDriverParams->pfdrBaseConstant = DEFAULT_pfdrBaseConstant; + p_Qm->p_QmDriverParams->p_FqdBaseExt = p_QmParam->p_FqdBase; + p_Qm->p_QmDriverParams->fqdSizeExt = p_QmParam->fqdSize; + p_Qm->p_QmDriverParams->p_PfdrBaseExt = p_QmParam->p_PfdrBase; + p_Qm->p_QmDriverParams->pfdrSizeExt = p_QmParam->pfdrSize; for(i= 0;ip_QmDriverParams->dcPortalsParams[i].sendToSw = (bool)((i < e_DPAA_DCPORTAL2) ? FALSE : TRUE); @@ -774,19 +778,32 @@ t_Error QM_Init(t_Handle h_Qm) WRITE_UINT32(p_Qm->p_QmRegs->liodnr, (uint16_t)p_QmDriverParams->liodn); /* FQD memory */ - dsSize = (uint32_t)(p_QmDriverParams->totalNumOfFqids * FQD_ENTRY_SIZE); - LOG2(dsSize, exp); - if (!POWER_OF_2(dsSize)) (exp++); - dsSize = (uint32_t)(1 << exp); - if (dsSize < (4*KILOBYTE)) + if (p_QmDriverParams->p_FqdBaseExt) { - dsSize = (4*KILOBYTE); + /* Use pre-allocated FQD memory from caller (e.g. DT reserved-memory) */ + p_Qm->p_FqdBase = p_QmDriverParams->p_FqdBaseExt; + p_Qm->fqdExternal = TRUE; + dsSize = p_QmDriverParams->fqdSizeExt; LOG2(dsSize, exp); + if (!POWER_OF_2(dsSize)) (exp++); + dsSize = (uint32_t)(1 << exp); } - p_Qm->p_FqdBase = XX_MallocSmart(dsSize, (int)p_QmDriverParams->fqdMemPartitionId, dsSize); - if (!p_Qm->p_FqdBase) + else { - RETURN_ERROR(MAJOR, E_NO_MEMORY, ("FQD obj!!!")); + dsSize = (uint32_t)(p_QmDriverParams->totalNumOfFqids * FQD_ENTRY_SIZE); + LOG2(dsSize, exp); + if (!POWER_OF_2(dsSize)) (exp++); + dsSize = (uint32_t)(1 << exp); + if (dsSize < (4*KILOBYTE)) + { + dsSize = (4*KILOBYTE); + LOG2(dsSize, exp); + } + p_Qm->p_FqdBase = XX_MallocSmart(dsSize, (int)p_QmDriverParams->fqdMemPartitionId, dsSize); + if (!p_Qm->p_FqdBase) + { + RETURN_ERROR(MAJOR, E_NO_MEMORY, ("FQD obj!!!")); + } } memset(p_Qm->p_FqdBase, 0, dsSize); mb(); @@ -799,29 +816,67 @@ t_Error QM_Init(t_Handle h_Qm) WRITE_UINT32(p_Qm->p_QmRegs->fqd_bar, (uint32_t)phyAddr); WRITE_UINT32(p_Qm->p_QmRegs->fqd_ar, AR_ENABLE | (exp - 1)); - /* PFDR memory */ - dsSize = (uint32_t)(p_QmDriverParams->rtFramesDepth * (PFDR_ENTRY_SIZE/3)); - LOG2(dsSize, exp); - if (!POWER_OF_2(dsSize)) (exp++); - dsSize = (uint32_t)(1 << exp); - if (dsSize < (4*KILOBYTE)) + /* Readback and verify FQD BAR programming */ { - dsSize = (4*KILOBYTE); - LOG2(dsSize, exp); + uint32_t rb_bare = GET_UINT32(p_Qm->p_QmRegs->fqd_bare); + uint32_t rb_bar = GET_UINT32(p_Qm->p_QmRegs->fqd_bar); + uint32_t rb_ar = GET_UINT32(p_Qm->p_QmRegs->fqd_ar); + XX_Print("QM FQD: va=%p phys=0x%08x%08x bare=0x%08x bar=0x%08x ar=0x%08x (exp=%d, size=0x%x)\n", + p_Qm->p_FqdBase, + (uint32_t)(phyAddr >> 32), (uint32_t)phyAddr, + rb_bare, rb_bar, rb_ar, exp, dsSize); } - p_Qm->p_PfdrBase = XX_MallocSmart(dsSize, (int)p_QmDriverParams->pfdrMemPartitionId, dsSize); - if (!p_Qm->p_PfdrBase) - RETURN_ERROR(MAJOR, E_NO_MEMORY, ("PFDR obj!!!")); + /* PFDR memory */ + if (p_QmDriverParams->p_PfdrBaseExt) + { + /* Use pre-allocated PFDR memory from caller */ + p_Qm->p_PfdrBase = p_QmDriverParams->p_PfdrBaseExt; + p_Qm->pfdrExternal = TRUE; + dsSize = p_QmDriverParams->pfdrSizeExt; + LOG2(dsSize, exp); + if (!POWER_OF_2(dsSize)) (exp++); + dsSize = (uint32_t)(1 << exp); + } + else + { + dsSize = (uint32_t)(p_QmDriverParams->rtFramesDepth * (PFDR_ENTRY_SIZE/3)); + LOG2(dsSize, exp); + if (!POWER_OF_2(dsSize)) (exp++); + dsSize = (uint32_t)(1 << exp); + if (dsSize < (4*KILOBYTE)) + { + dsSize = (4*KILOBYTE); + LOG2(dsSize, exp); + } + p_Qm->p_PfdrBase = XX_MallocSmart(dsSize, (int)p_QmDriverParams->pfdrMemPartitionId, dsSize); + if (!p_Qm->p_PfdrBase) + RETURN_ERROR(MAJOR, E_NO_MEMORY, ("PFDR obj!!!")); + } phyAddr = XX_VirtToPhys(p_Qm->p_PfdrBase); WRITE_UINT32(p_Qm->p_QmRegs->pfdr_bare, ((uint32_t)(phyAddr >> 32) & 0x000000ff)); WRITE_UINT32(p_Qm->p_QmRegs->pfdr_bar, (uint32_t)phyAddr); WRITE_UINT32(p_Qm->p_QmRegs->pfdr_ar, AR_ENABLE | (exp - 1)); + /* Readback and verify PFDR BAR programming */ + { + uint32_t rb_bare = GET_UINT32(p_Qm->p_QmRegs->pfdr_bare); + uint32_t rb_bar = GET_UINT32(p_Qm->p_QmRegs->pfdr_bar); + uint32_t rb_ar = GET_UINT32(p_Qm->p_QmRegs->pfdr_ar); + XX_Print("QM PFDR: va=%p phys=0x%08x%08x bare=0x%08x bar=0x%08x ar=0x%08x (exp=%d, size=0x%x)\n", + p_Qm->p_PfdrBase, + (uint32_t)(phyAddr >> 32), (uint32_t)phyAddr, + rb_bare, rb_bar, rb_ar, exp, dsSize); + XX_Print("QM PFDR init: pfdr_start=8, num=%d\n", dsSize / 64 - 8); + } + if (QmInitPfdr(p_Qm, 8, dsSize / 64 - 8) != E_OK) RETURN_ERROR(MAJOR, E_INVALID_STATE, ("PFDR init failed!!!")); + XX_Print("QM PFDR init: SUCCESS, pfdr_fpc=%d\n", + GET_UINT32(p_Qm->p_QmRegs->pfdr_fpc)); + /* thresholds */ WRITE_UINT32(p_Qm->p_QmRegs->pfdr_fp_lwit, (p_Qm->p_QmDriverParams->pfdrThreshold & 0xffffff)); WRITE_UINT32(p_Qm->p_QmRegs->pfdr_cfg, p_Qm->p_QmDriverParams->pfdrBaseConstant); @@ -1037,6 +1092,27 @@ uint32_t QM_GetCounter(t_Handle h_Qm, e_QmCounters counter) return 0; } +#ifdef __aarch64__ +void QM_ErrorDiag(t_Handle h_Qm, uint32_t *err_isr, uint32_t *ecsr, + uint32_t *ecir, uint32_t *pfdr_fpc, uint32_t *sfdr_in_use, + uint32_t *idle_stat, uint32_t *dcp0_cfg, uint32_t *dcp0_dlm_avg, + uint32_t *dcp_dd_ihrsr, uint32_t *dcp_dd_hasr) +{ + t_Qm *p_Qm = (t_Qm *)h_Qm; + + *err_isr = GET_UINT32(p_Qm->p_QmRegs->err_isr); + *ecsr = GET_UINT32(p_Qm->p_QmRegs->ecsr); + *ecir = GET_UINT32(p_Qm->p_QmRegs->ecir); + *pfdr_fpc = GET_UINT32(p_Qm->p_QmRegs->pfdr_fpc); + *sfdr_in_use = GET_UINT32(p_Qm->p_QmRegs->sfdr_in_use); + *idle_stat = GET_UINT32(p_Qm->p_QmRegs->idle_stat); + *dcp0_cfg = GET_UINT32(p_Qm->p_QmRegs->dcpConfRegs[0].cfg); + *dcp0_dlm_avg = GET_UINT32(p_Qm->p_QmRegs->dcpConfRegs[0].dlm_avg); + *dcp_dd_ihrsr = GET_UINT32(p_Qm->p_QmRegs->dcp_dd_ihrsr); + *dcp_dd_hasr = GET_UINT32(p_Qm->p_QmRegs->dcp_dd_hasr); +} +#endif + void QM_ErrorIsr(t_Handle h_Qm) { t_Qm *p_Qm = (t_Qm *)h_Qm; diff --git a/sys/contrib/ncsw/Peripherals/QM/qm.h b/sys/contrib/ncsw/Peripherals/QM/qm.h index a004dc55a67..a18ada7c719 100644 --- a/sys/contrib/ncsw/Peripherals/QM/qm.h +++ b/sys/contrib/ncsw/Peripherals/QM/qm.h @@ -373,7 +373,11 @@ typedef _Packed struct #define QM_CGR_TARGET_DCP(portlaId) (QM_CGR_TARG_FIRST_DCPORTAL >> portlaId) -#define QM_DCP_CFG_ED 0x00000100 +#ifdef __aarch64__ +#define QM_DCP_CFG_ED 0x00001000 /* QMan v3 (LS1046A) */ +#else +#define QM_DCP_CFG_ED 0x00000100 /* QMan v1/v2 (P5020) */ +#endif /* #define CGR_VALID 0x80 #define CGR_VERB_INIT 0x50 @@ -467,6 +471,10 @@ typedef struct { uint32_t pfdrBaseConstant; uint16_t liodn; t_QmDcPortalParams dcPortalsParams[DPAA_MAX_NUM_OF_DC_PORTALS]; + void *p_FqdBaseExt; /* Pre-allocated FQD, or NULL */ + uint32_t fqdSizeExt; + void *p_PfdrBaseExt; /* Pre-allocated PFDR, or NULL */ + uint32_t pfdrSizeExt; } t_QmDriverParams; typedef struct { @@ -479,6 +487,8 @@ typedef struct { t_QmRegs *p_QmRegs; uint32_t *p_FqdBase; uint32_t *p_PfdrBase; + bool fqdExternal; /* FQD memory externally allocated */ + bool pfdrExternal; /* PFDR memory externally allocated */ uint32_t exceptions; t_QmExceptionsCallback *f_Exception; t_Handle h_App; diff --git a/sys/contrib/ncsw/Peripherals/QM/qm_portal_fqr.c b/sys/contrib/ncsw/Peripherals/QM/qm_portal_fqr.c index 31313d37f97..33d630fafa6 100644 --- a/sys/contrib/ncsw/Peripherals/QM/qm_portal_fqr.c +++ b/sys/contrib/ncsw/Peripherals/QM/qm_portal_fqr.c @@ -1,6 +1,6 @@ /****************************************************************************** - © 1995-2003, 2004, 2005-2011 Freescale Semiconductor, Inc. + � 1995-2003, 2004, 2005-2011 Freescale Semiconductor, Inc. All rights reserved. This is proprietary source code of Freescale Semiconductor Inc., @@ -64,22 +64,69 @@ * call. Take advantage of this fact to shove a 64-bit kernel pointer into a * 32-bit context integer, and back. * - * XXX: This depends on the fact that VM_MAX_KERNEL_ADDRESS is less than 38-bit - * count from VM_MIN_KERNEL_ADDRESS. If this ever changes, this needs to be - * updated. + * On ARM64, encode the physical address shifted by 6 (64-byte alignment). + * XX_MallocSmart uses malloc() which returns DMAP addresses — virtual + * address encoding is not feasible because the DMAP-to-KVA offset exceeds + * 32 bits. Physical addresses on LS1046A are ≤10GB, so shifted by 6 they + * fit trivially in 32 bits (max ~160M). Reconstruction uses XX_PhysToVirt + * which returns the DMAP virtual address. + * + * On PowerPC, shift by 3 (8-byte alignment) relative to VM_MIN_KERNEL_ADDRESS. */ +#if defined(__aarch64__) +#define QMAN_CTX_SHIFT 6 +static inline uint32_t +aligned_int_from_ptr(const void *p) +{ + physAddress_t pa; + uint32_t result; + + pa = XX_VirtToPhys((void *)(uintptr_t)p); + KASSERT((pa & ((1 << QMAN_CTX_SHIFT) - 1)) == 0, + ("Pointer %p (pa %#lx) is not %d-byte aligned!\n", + p, (unsigned long)pa, 1 << QMAN_CTX_SHIFT)); + + result = (uint32_t)(pa >> QMAN_CTX_SHIFT); + KASSERT((physAddress_t)result == (pa >> QMAN_CTX_SHIFT), + ("%s: %p (pa %#lx) overflows 32-bit context\n", + __func__, p, (unsigned long)pa)); + + return (result); +} + +static inline void * +ptr_from_aligned_int(uint32_t ctx) +{ + physAddress_t pa; + + pa = (physAddress_t)ctx << QMAN_CTX_SHIFT; + + return (XX_PhysToVirt(pa)); +} +#else CTASSERT((VM_MAX_KERNEL_ADDRESS - VM_MIN_KERNEL_ADDRESS) < (1ULL << 35)); +#define QMAN_CTX_SHIFT 3 +#define QMAN_CTX_BASE VM_MIN_KERNEL_ADDRESS static inline uint32_t aligned_int_from_ptr(const void *p) { uintptr_t ctx; + uint32_t result; ctx = (uintptr_t)p; - KASSERT(ctx >= VM_MIN_KERNEL_ADDRESS, ("%p is too low!\n", p)); - ctx -= VM_MIN_KERNEL_ADDRESS; - KASSERT((ctx & 0x07) == 0, ("Pointer %p is not 8-byte aligned!\n", p)); + KASSERT(ctx >= QMAN_CTX_BASE, + ("%s: %p is below base %#lx\n", __func__, p, + (unsigned long)QMAN_CTX_BASE)); + ctx -= QMAN_CTX_BASE; + KASSERT((ctx & ((1 << QMAN_CTX_SHIFT) - 1)) == 0, + ("Pointer %p is not %d-byte aligned!\n", p, 1 << QMAN_CTX_SHIFT)); - return (ctx >> 3); + result = (ctx >> QMAN_CTX_SHIFT); + KASSERT((uintptr_t)result == (ctx >> QMAN_CTX_SHIFT), + ("%s: %p overflows 32-bit context (shifted %#lx)\n", + __func__, p, (unsigned long)(ctx >> QMAN_CTX_SHIFT))); + + return (result); } static inline void * @@ -88,10 +135,59 @@ ptr_from_aligned_int(uint32_t ctx) uintptr_t p; p = ctx; - p = VM_MIN_KERNEL_ADDRESS + (p << 3); + p = QMAN_CTX_BASE + (p << QMAN_CTX_SHIFT); return ((void *)p); } +#endif + +/* + * Copy a frame descriptor from CE portal memory (big-endian) to a native + * t_DpaaFD struct with proper byte-swapping. On big-endian (PowerPC), + * GET_UINT32 is a plain load so this is equivalent to a raw copy. + * + * On LE (ARM64), t_DpaaFD swaps the word order of the first 8 bytes: + * HW (BE): [liodn,bpid,elion,addrh][addrl_BE] + * t_DpaaFD LE: [addrl_LE][addrh,elion,bpid,liodn] + * So we swap word positions AND byte-swap each word (equivalent to bswap64). + */ +static inline void +qm_fd_read(t_DpaaFD *dst, const volatile struct qm_fd *src) +{ + const volatile uint32_t *s = (const volatile uint32_t *)src; + uint32_t *d = (uint32_t *)dst; + +#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ + d[0] = s[0]; + d[1] = s[1]; +#else + d[0] = GET_UINT32(s[1]); + d[1] = GET_UINT32(s[0]); +#endif + d[2] = GET_UINT32(s[2]); + d[3] = GET_UINT32(s[3]); +} + +/* + * Copy a native t_DpaaFD to CE portal memory (big-endian) with proper + * byte-swapping. Reverse of qm_fd_read(). + */ +static inline void +qm_fd_write(volatile struct qm_fd *dst, const t_DpaaFD *src) +{ + volatile uint32_t *d = (volatile uint32_t *)dst; + const uint32_t *s = (const uint32_t *)src; + +#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ + d[0] = s[0]; + d[1] = s[1]; +#else + WRITE_UINT32(d[0], s[1]); + WRITE_UINT32(d[1], s[0]); +#endif + WRITE_UINT32(d[2], s[2]); + WRITE_UINT32(d[3], s[3]); +} static t_Error qman_volatile_dequeue(t_QmPortal *p_QmPortal, struct qman_fq *p_Fq, @@ -152,7 +248,7 @@ static t_Error qman_create_fq(t_QmPortal *p_QmPortal, /* Everything else is RECOVER support */ NCSW_PLOCK(p_QmPortal); p_Mcc = qm_mc_start(p_QmPortal->p_LowQmPortal); - p_Mcc->queryfq.fqid = fqid; + WRITE_UINT32(p_Mcc->queryfq.fqid, fqid); qm_mc_commit(p_QmPortal->p_LowQmPortal, QM_MCC_VERB_QUERYFQ); while (!(p_Mcr = qm_mc_result(p_QmPortal->p_LowQmPortal))) ; ASSERT_COND((p_Mcr->verb & QM_MCR_VERB_MASK) == QM_MCC_VERB_QUERYFQ); @@ -162,7 +258,7 @@ static t_Error qman_create_fq(t_QmPortal *p_QmPortal, } fqd = p_Mcr->queryfq.fqd; p_Mcc = qm_mc_start(p_QmPortal->p_LowQmPortal); - p_Mcc->queryfq_np.fqid = fqid; + WRITE_UINT32(p_Mcc->queryfq_np.fqid, fqid); qm_mc_commit(p_QmPortal->p_LowQmPortal, QM_MCC_VERB_QUERYFQ_NP); while (!(p_Mcr = qm_mc_result(p_QmPortal->p_LowQmPortal))) ; ASSERT_COND((p_Mcr->verb & QM_MCR_VERB_MASK) == QM_MCC_VERB_QUERYFQ_NP); @@ -245,7 +341,56 @@ static t_Error qman_init_fq(t_QmPortal *p_QmPortal, return ERROR_CODE(E_BUSY); } p_Mcc = qm_mc_start(p_QmPortal->p_LowQmPortal); +#ifdef __aarch64__ + /* + * Portal CE memory is big-endian on QorIQ ARM64 (LS1046A). + * Mem2IOCpy32 doesn't handle LE→BE conversion correctly for packed + * structs whose fields span 32-bit word boundaries — the byte-by-byte + * prefix and the unaligned shift-merge were designed for big-endian + * PowerPC only. Write each field individually using WRITE_UINTxx + * (out{8,16,32}rb) which byte-swap LE values to BE portal bytes. + * + * Bitfield-containing sub-fields (dest_wq, td_thresh) must be manually + * reconstructed in BE bit layout because GCC allocates bitfields from + * LSB on LE vs MSB on BE. + */ + WRITE_UINT8(p_Mcc->initfq.reserved1, 0); + WRITE_UINT16(p_Mcc->initfq.we_mask, p_Opts->we_mask); + WRITE_UINT32(p_Mcc->initfq.fqid, p_Opts->fqid); + WRITE_UINT16(p_Mcc->initfq.count, p_Opts->count); + /* FQD sub-struct */ + WRITE_UINT8(p_Mcc->initfq.fqd.orpc, p_Opts->fqd.orpc); + WRITE_UINT8(p_Mcc->initfq.fqd.cgid, p_Opts->fqd.cgid); + WRITE_UINT16(p_Mcc->initfq.fqd.fq_ctrl, p_Opts->fqd.fq_ctrl); + { + /* dest_wq has bitfields channel:13 wq:3. + * BE bit layout: channel(bits15-3) wq(bits2-0). */ + uint16_t dest_wq_be = ((uint16_t)(p_Opts->fqd.dest.channel & 0x1FFF) << 3) | + (p_Opts->fqd.dest.wq & 0x7); + WRITE_UINT16(p_Mcc->initfq.fqd.dest_wq, dest_wq_be); + } + { + /* reserved2:1 + ics_cred:15 are bare bitfields with no union accessor. + * Address the 16-bit word via the preceding dest_wq union. */ + volatile uint16_t *p_ics = (volatile uint16_t *)&p_Mcc->initfq.fqd.dest_wq + 1; + /* BE bit layout: reserved2(bit15) ics_cred(bits14-0). reserved2=0. */ + uint16_t ics_be = (uint16_t)(p_Opts->fqd.ics_cred & 0x7FFF); + WRITE_UINT16(*p_ics, ics_be); + } + { + /* td_thresh has bitfields reserved1:3 mant:8 exp:5. + * BE bit layout: reserved(bits15-13) mant(bits12-5) exp(bits4-0). */ + uint16_t td_be = ((uint16_t)(p_Opts->fqd.td.mant & 0xFF) << 5) | + (p_Opts->fqd.td.exp & 0x1F); + WRITE_UINT16(p_Mcc->initfq.fqd.td_thresh, td_be); + } + WRITE_UINT32(p_Mcc->initfq.fqd.context_b, p_Opts->fqd.context_b); + WRITE_UINT32(p_Mcc->initfq.fqd.context_a.hi, p_Opts->fqd.context_a.hi); + WRITE_UINT32(p_Mcc->initfq.fqd.context_a.lo, p_Opts->fqd.context_a.lo); + /* reserved3[32] already zeroed by dcbz_64 in qm_mc_start */ +#else Mem2IOCpy32((void*)&p_Mcc->initfq, p_Opts, sizeof(struct qm_mcc_initfq)); +#endif qm_mc_commit(p_QmPortal->p_LowQmPortal, myverb); while (!(p_Mcr = qm_mc_result(p_QmPortal->p_LowQmPortal))) ; ASSERT_COND((p_Mcr->verb & QM_MCR_VERB_MASK) == myverb); @@ -253,17 +398,19 @@ static t_Error qman_init_fq(t_QmPortal *p_QmPortal, if (res != QM_MCR_RESULT_OK) { FQUNLOCK(p_Fq); PUNLOCK(p_QmPortal); - RETURN_ERROR(MINOR, E_INVALID_STATE,("INITFQ failed: %s", mcr_result_str(res))); + RETURN_ERROR(MINOR, E_INVALID_STATE,("INITFQ failed: fqid=%d %s", + p_Fq->fqid, mcr_result_str(res))); } - if (p_Mcc->initfq.we_mask & QM_INITFQ_WE_FQCTRL) { - if (p_Mcc->initfq.fqd.fq_ctrl & QM_FQCTRL_CGE) + /* Read flags back from the source struct, not portal CE (which is BE) */ + if (p_Opts->we_mask & QM_INITFQ_WE_FQCTRL) { + if (p_Opts->fqd.fq_ctrl & QM_FQCTRL_CGE) p_Fq->flags |= QMAN_FQ_STATE_CGR_EN; else p_Fq->flags &= ~QMAN_FQ_STATE_CGR_EN; } - if (p_Mcc->initfq.we_mask & QM_INITFQ_WE_CGID) - p_Fq->cgr_groupid = p_Mcc->initfq.fqd.cgid; + if (p_Opts->we_mask & QM_INITFQ_WE_CGID) + p_Fq->cgr_groupid = p_Opts->fqd.cgid; p_Fq->state = (flags & QMAN_INITFQ_FLAG_SCHED) ? qman_fq_state_sched : qman_fq_state_parked; FQUNLOCK(p_Fq); @@ -296,9 +443,9 @@ static t_Error qman_retire_fq(t_QmPortal *p_QmPortal, goto out; } p_Mcc = qm_mc_start(p_QmPortal->p_LowQmPortal); - p_Mcc->alterfq.fqid = p_Fq->fqid; + WRITE_UINT32(p_Mcc->alterfq.fqid, p_Fq->fqid); if (drain) - p_Mcc->alterfq.context_b = aligned_int_from_ptr(p_Fq); + WRITE_UINT32(p_Mcc->alterfq.context_b, aligned_int_from_ptr(p_Fq)); qm_mc_commit(p_QmPortal->p_LowQmPortal, (uint8_t)((drain)?QM_MCC_VERB_ALTER_RETIRE_CTXB:QM_MCC_VERB_ALTER_RETIRE)); while (!(p_Mcr = qm_mc_result(p_QmPortal->p_LowQmPortal))) ; @@ -347,7 +494,7 @@ static t_Error qman_oos_fq(t_QmPortal *p_QmPortal, struct qman_fq *p_Fq) return ERROR_CODE(E_BUSY); } p_Mcc = qm_mc_start(p_QmPortal->p_LowQmPortal); - p_Mcc->alterfq.fqid = p_Fq->fqid; + WRITE_UINT32(p_Mcc->alterfq.fqid, p_Fq->fqid); qm_mc_commit(p_QmPortal->p_LowQmPortal, QM_MCC_VERB_ALTER_OOS); while (!(p_Mcr = qm_mc_result(p_QmPortal->p_LowQmPortal))) ; ASSERT_COND((p_Mcr->verb & QM_MCR_VERB_MASK) == QM_MCR_VERB_ALTER_OOS); @@ -383,7 +530,7 @@ static t_Error qman_schedule_fq(t_QmPortal *p_QmPortal, struct qman_fq *p_Fq) return ERROR_CODE(E_BUSY); } p_Mcc = qm_mc_start(p_QmPortal->p_LowQmPortal); - p_Mcc->alterfq.fqid = p_Fq->fqid; + WRITE_UINT32(p_Mcc->alterfq.fqid, p_Fq->fqid); qm_mc_commit(p_QmPortal->p_LowQmPortal, QM_MCC_VERB_ALTER_SCHED); while (!(p_Mcr = qm_mc_result(p_QmPortal->p_LowQmPortal))) ; ASSERT_COND((p_Mcr->verb & QM_MCR_VERB_MASK) == QM_MCR_VERB_ALTER_SCHED); @@ -607,14 +754,30 @@ mr_loop: qmPortalMrPvbUpdate(p_QmPortal->p_LowQmPortal); p_Msg = qm_mr_current(p_QmPortal->p_LowQmPortal); if (p_Msg) { - struct qman_fq *p_FqFqs = ptr_from_aligned_int(p_Msg->fq.contextB); - struct qman_fq *p_FqErn = ptr_from_aligned_int(p_Msg->ern.tag); + struct qman_fq *p_FqFqs = ptr_from_aligned_int(GET_UINT32(p_Msg->fq.contextB)); + struct qman_fq *p_FqErn = ptr_from_aligned_int(GET_UINT32(p_Msg->ern.tag)); uint8_t verb =(uint8_t)(p_Msg->verb & QM_MR_VERB_TYPE_MASK); t_QmRejectedFrameInfo rejectedFrameInfo; + t_DpaaFD mr_fd; memset(&rejectedFrameInfo, 0, sizeof(t_QmRejectedFrameInfo)); if (!(verb & QM_MR_VERB_DC_ERN)) { + qm_fd_read(&mr_fd, &p_Msg->ern.fd); + { + static int ern_print_count; + if (ern_print_count++ < 20) + XX_Print("QM ERN: verb=0x%02x rc=0x%02x fqid=%u " + "fd_addr=0x%08x%08x fd_status=0x%x\n", + verb, p_Msg->ern.rc, + p_FqErn ? p_FqErn->fqid : 0, + DPAA_FD_GET_ADDRH(&mr_fd), + DPAA_FD_GET_ADDRL(&mr_fd), + DPAA_FD_GET_STATUS(&mr_fd)); + } + if (DPAA_FD_GET_PHYS_ADDR(&mr_fd) == 0) + XX_Print("LoopMessageRing: ERN FD.addr=0 verb=0x%02x rc=0x%02x\n", + verb, p_Msg->ern.rc); switch(p_Msg->ern.rc) { case(QM_MR_RC_CGR_TAILDROP): @@ -635,11 +798,17 @@ mr_loop: REPORT_ERROR(MINOR, E_NOT_SUPPORTED, ("Unknown rejection code")); } if (!p_FqErn) - p_QmPortal->p_NullCB->ern(p_QmPortal->h_App, NULL, p_QmPortal, 0, (t_DpaaFD*)&p_Msg->ern.fd, &rejectedFrameInfo); + p_QmPortal->p_NullCB->ern(p_QmPortal->h_App, NULL, p_QmPortal, 0, &mr_fd, &rejectedFrameInfo); else - p_FqErn->cb.ern(p_FqErn->h_App, p_FqErn->h_QmFqr, p_QmPortal, p_FqErn->fqidOffset, (t_DpaaFD*)&p_Msg->ern.fd, &rejectedFrameInfo); + p_FqErn->cb.ern(p_FqErn->h_App, p_FqErn->h_QmFqr, p_QmPortal, p_FqErn->fqidOffset, &mr_fd, &rejectedFrameInfo); } else if (verb == QM_MR_VERB_DC_ERN) { + { + static int dc_ern_count; + if (dc_ern_count++ < 20) + XX_Print("QM DC_ERN: fqid=%u\n", + p_FqErn ? p_FqErn->fqid : 0); + } if (!p_FqErn) p_QmPortal->p_NullCB->dc_ern(NULL, p_QmPortal, NULL, p_Msg); else @@ -676,6 +845,7 @@ static void LoopDequeueRing(t_Handle h_QmPortal) e_RxStoreResponse tmpRes; t_QmPortal *p_QmPortal = (t_QmPortal *)h_QmPortal; int prefetch = !(p_QmPortal->options & QMAN_PORTAL_FLAG_RSTASH); + t_DpaaFD fd; while (res != qman_cb_dqrr_pause) { @@ -685,12 +855,13 @@ static void LoopDequeueRing(t_Handle h_QmPortal) p_Dq = qm_dqrr_current(p_QmPortal->p_LowQmPortal); if (!p_Dq) break; - p_Fq = ptr_from_aligned_int(p_Dq->contextB); + p_Fq = ptr_from_aligned_int(GET_UINT32(p_Dq->contextB)); + qm_fd_read(&fd, &p_Dq->fd); if (p_Dq->stat & QM_DQRR_STAT_UNSCHEDULED) { /* We only set QMAN_FQ_STATE_NE when retiring, so we only need * to check for clearing it when doing volatile dequeues. It's * one less thing to check in the critical path (SDQCR). */ - tmpRes = p_Fq->cb.dqrr(p_Fq->h_App, p_Fq->h_QmFqr, p_QmPortal, p_Fq->fqidOffset, (t_DpaaFD*)&p_Dq->fd); + tmpRes = p_Fq->cb.dqrr(p_Fq->h_App, p_Fq->h_QmFqr, p_QmPortal, p_Fq->fqidOffset, &fd); if (tmpRes == e_RX_STORE_RESPONSE_PAUSE) res = qman_cb_dqrr_pause; /* Check for VDQCR completion */ @@ -706,14 +877,14 @@ static void LoopDequeueRing(t_Handle h_QmPortal) { /* Interpret 'dq' from the owner's perspective. */ /* use portal default handlers */ - ASSERT_COND(p_Dq->fqid); + ASSERT_COND(GET_UINT32(p_Dq->fqid)); if (p_Fq) { tmpRes = p_Fq->cb.dqrr(p_Fq->h_App, p_Fq->h_QmFqr, p_QmPortal, p_Fq->fqidOffset, - (t_DpaaFD*)&p_Dq->fd); + &fd); if (tmpRes == e_RX_STORE_RESPONSE_PAUSE) res = qman_cb_dqrr_pause; else if (p_Fq->state == qman_fq_state_waiting_parked) @@ -724,8 +895,8 @@ static void LoopDequeueRing(t_Handle h_QmPortal) tmpRes = p_QmPortal->p_NullCB->dqrr(p_QmPortal->h_App, NULL, p_QmPortal, - p_Dq->fqid, - (t_DpaaFD*)&p_Dq->fd); + GET_UINT32(p_Dq->fqid), + &fd); if (tmpRes == e_RX_STORE_RESPONSE_PAUSE) res = qman_cb_dqrr_pause; } @@ -760,6 +931,7 @@ static void LoopDequeueRingDcaOptimized(t_Handle h_QmPortal) enum qman_cb_dqrr_result res = qman_cb_dqrr_consume; e_RxStoreResponse tmpRes; t_QmPortal *p_QmPortal = (t_QmPortal *)h_QmPortal; + t_DpaaFD fd; while (res != qman_cb_dqrr_pause) { @@ -767,12 +939,13 @@ static void LoopDequeueRingDcaOptimized(t_Handle h_QmPortal) p_Dq = qm_dqrr_current(p_QmPortal->p_LowQmPortal); if (!p_Dq) break; - p_Fq = ptr_from_aligned_int(p_Dq->contextB); + p_Fq = ptr_from_aligned_int(GET_UINT32(p_Dq->contextB)); + qm_fd_read(&fd, &p_Dq->fd); if (p_Dq->stat & QM_DQRR_STAT_UNSCHEDULED) { /* We only set QMAN_FQ_STATE_NE when retiring, so we only need * to check for clearing it when doing volatile dequeues. It's * one less thing to check in the critical path (SDQCR). */ - tmpRes = p_Fq->cb.dqrr(p_Fq->h_App, p_Fq->h_QmFqr, p_QmPortal, p_Fq->fqidOffset, (t_DpaaFD*)&p_Dq->fd); + tmpRes = p_Fq->cb.dqrr(p_Fq->h_App, p_Fq->h_QmFqr, p_QmPortal, p_Fq->fqidOffset, &fd); if (tmpRes == e_RX_STORE_RESPONSE_PAUSE) res = qman_cb_dqrr_pause; /* Check for VDQCR completion */ @@ -788,14 +961,14 @@ static void LoopDequeueRingDcaOptimized(t_Handle h_QmPortal) { /* Interpret 'dq' from the owner's perspective. */ /* use portal default handlers */ - ASSERT_COND(p_Dq->fqid); + ASSERT_COND(GET_UINT32(p_Dq->fqid)); if (p_Fq) { tmpRes = p_Fq->cb.dqrr(p_Fq->h_App, p_Fq->h_QmFqr, p_QmPortal, p_Fq->fqidOffset, - (t_DpaaFD*)&p_Dq->fd); + &fd); if (tmpRes == e_RX_STORE_RESPONSE_PAUSE) res = qman_cb_dqrr_pause; else if (p_Fq->state == qman_fq_state_waiting_parked) @@ -806,8 +979,8 @@ static void LoopDequeueRingDcaOptimized(t_Handle h_QmPortal) tmpRes = p_QmPortal->p_NullCB->dqrr(p_QmPortal->h_App, NULL, p_QmPortal, - p_Dq->fqid, - (t_DpaaFD*)&p_Dq->fd); + GET_UINT32(p_Dq->fqid), + &fd); if (tmpRes == e_RX_STORE_RESPONSE_PAUSE) res = qman_cb_dqrr_pause; } @@ -834,6 +1007,7 @@ static void LoopDequeueRingOptimized(t_Handle h_QmPortal) enum qman_cb_dqrr_result res = qman_cb_dqrr_consume; e_RxStoreResponse tmpRes; t_QmPortal *p_QmPortal = (t_QmPortal *)h_QmPortal; + t_DpaaFD fd; while (res != qman_cb_dqrr_pause) { @@ -841,12 +1015,13 @@ static void LoopDequeueRingOptimized(t_Handle h_QmPortal) p_Dq = qm_dqrr_current(p_QmPortal->p_LowQmPortal); if (!p_Dq) break; - p_Fq = ptr_from_aligned_int(p_Dq->contextB); + p_Fq = ptr_from_aligned_int(GET_UINT32(p_Dq->contextB)); + qm_fd_read(&fd, &p_Dq->fd); if (p_Dq->stat & QM_DQRR_STAT_UNSCHEDULED) { /* We only set QMAN_FQ_STATE_NE when retiring, so we only need * to check for clearing it when doing volatile dequeues. It's * one less thing to check in the critical path (SDQCR). */ - tmpRes = p_Fq->cb.dqrr(p_Fq->h_App, p_Fq->h_QmFqr, p_QmPortal, p_Fq->fqidOffset, (t_DpaaFD*)&p_Dq->fd); + tmpRes = p_Fq->cb.dqrr(p_Fq->h_App, p_Fq->h_QmFqr, p_QmPortal, p_Fq->fqidOffset, &fd); if (tmpRes == e_RX_STORE_RESPONSE_PAUSE) res = qman_cb_dqrr_pause; /* Check for VDQCR completion */ @@ -862,14 +1037,14 @@ static void LoopDequeueRingOptimized(t_Handle h_QmPortal) { /* Interpret 'dq' from the owner's perspective. */ /* use portal default handlers */ - ASSERT_COND(p_Dq->fqid); + ASSERT_COND(GET_UINT32(p_Dq->fqid)); if (p_Fq) { tmpRes = p_Fq->cb.dqrr(p_Fq->h_App, p_Fq->h_QmFqr, p_QmPortal, p_Fq->fqidOffset, - (t_DpaaFD*)&p_Dq->fd); + &fd); if (tmpRes == e_RX_STORE_RESPONSE_PAUSE) res = qman_cb_dqrr_pause; else if (p_Fq->state == qman_fq_state_waiting_parked) @@ -880,8 +1055,8 @@ static void LoopDequeueRingOptimized(t_Handle h_QmPortal) tmpRes = p_QmPortal->p_NullCB->dqrr(p_QmPortal->h_App, NULL, p_QmPortal, - p_Dq->fqid, - (t_DpaaFD*)&p_Dq->fd); + GET_UINT32(p_Dq->fqid), + &fd); if (tmpRes == e_RX_STORE_RESPONSE_PAUSE) res = qman_cb_dqrr_pause; } @@ -909,6 +1084,26 @@ static void portal_isr(void *ptr) DBG(TRACE, ("software-portal %d got interrupt", p_QmPortal->p_LowQmPortal->config.cpu)); +#ifdef __aarch64__ + { + /* Per-portal ISR invocation counters (max 16 portals) */ + static volatile uint32_t portal_isr_cnt[16]; + int cpu = p_QmPortal->p_LowQmPortal->config.cpu; + uint32_t cnt; + if (cpu >= 0 && cpu < 16) + cnt = ++portal_isr_cnt[cpu]; + else + cnt = 0; + if (cnt <= 10 || (cnt % 1000 == 0)) + printf("qman: portal_isr cpu=%d count=%u ISR=0x%x IER=0x%x " + "dqrr_fill=%u\n", + cpu, cnt, + qm_isr_status_read(p_QmPortal->p_LowQmPortal), + enableEvents, + (unsigned)p_QmPortal->p_LowQmPortal->dqrr.fill); + } +#endif + event |= (qm_isr_status_read(p_QmPortal->p_LowQmPortal) & enableEvents); @@ -930,7 +1125,7 @@ static t_Error qman_query_fq_np(t_QmPortal *p_QmPortal, struct qman_fq *p_Fq, st NCSW_PLOCK(p_QmPortal); p_Mcc = qm_mc_start(p_QmPortal->p_LowQmPortal); - p_Mcc->queryfq_np.fqid = p_Fq->fqid; + WRITE_UINT32(p_Mcc->queryfq_np.fqid, p_Fq->fqid); qm_mc_commit(p_QmPortal->p_LowQmPortal, QM_MCC_VERB_QUERYFQ_NP); while (!(p_Mcr = qm_mc_result(p_QmPortal->p_LowQmPortal))) ; ASSERT_COND((p_Mcr->verb & QM_MCR_VERB_MASK) == QM_MCR_VERB_QUERYFQ_NP); @@ -1198,6 +1393,105 @@ drain_loop: } } +/* + * Clean up stale frame queues left by a previous boot (e.g. U-Boot). + * The QMan hardware's FQD cache may retain FQs in SCHED/ACTIVE state + * across a soft reboot. If not retired, these stale FQs will produce + * DQRR entries with invalid contextB pointers, causing a page fault. + * + * Called during portal creation after DQRR, MR, and MC are initialized + * but before ISR setup and SDQCR enable. + */ +#define CLEANUP_MAX_FQID 256 + +static void qman_cleanup_stale_fqs(struct qm_portal *portal) +{ + static volatile int cleanup_done = 0; + struct qm_mc_command *mcc; + struct qm_mc_result *mcr; + uint32_t fqid; + int cleaned = 0; + uint8_t state, res; + + /* All portals see the same global FQ state — only clean up once. + * Running on subsequent portals would retire FQs that drivers + * legitimately created after the first portal's cleanup. */ + if (atomic_cmpset_int(&cleanup_done, 0, 1) == 0) + return; + + /* Drain any stale DQRR entries from previous boot */ + while (qmPortalDqrrPvbUpdate(portal), + qm_dqrr_current(portal) != NULL) { + qm_dqrr_next(portal); + qmPortalDqrrCciConsume(portal, 1); + } + /* Drain any stale MR entries from previous boot */ + while (qmPortalMrPvbUpdate(portal), + qm_mr_current(portal) != NULL) { + qm_mr_next(portal); + qmPortalMrCciConsume(portal, 1); + } + /* Retire stale FQs via MC commands */ + for (fqid = 0; fqid < CLEANUP_MAX_FQID; fqid++) { + /* QUERYFQ_NP */ + mcc = qm_mc_start(portal); + WRITE_UINT32(mcc->queryfq_np.fqid, fqid); + qm_mc_commit(portal, QM_MCC_VERB_QUERYFQ_NP); + while (!(mcr = qm_mc_result(portal))) + ; + res = mcr->result; + if (res != QM_MCR_RESULT_OK) + continue; + state = mcr->queryfq_np.state & QM_MCR_NP_STATE_MASK; + if (state == QM_MCR_NP_STATE_OOS) + continue; + if (state == QM_MCR_NP_STATE_RETIRED) + goto do_oos; + + /* ALTER_RETIRE */ + mcc = qm_mc_start(portal); + WRITE_UINT32(mcc->alterfq.fqid, fqid); + qm_mc_commit(portal, QM_MCC_VERB_ALTER_RETIRE); + while (!(mcr = qm_mc_result(portal))) + ; + res = mcr->result; + if (res == QM_MCR_RESULT_PENDING) { + /* Wait for FQRNI on MR */ + int timeout = 10000; + while (timeout--) { + qmPortalMrPvbUpdate(portal); + if (qm_mr_current(portal) != NULL) { + qm_mr_next(portal); + qmPortalMrCciConsume(portal, 1); + break; + } + } + } else if (res != QM_MCR_RESULT_OK) { + XX_Print("qman_cleanup: fqid %u retire failed 0x%02x\n", + fqid, res); + continue; + } + +do_oos: + /* ALTER_OOS */ + mcc = qm_mc_start(portal); + WRITE_UINT32(mcc->alterfq.fqid, fqid); + qm_mc_commit(portal, QM_MCC_VERB_ALTER_OOS); + while (!(mcr = qm_mc_result(portal))) + ; + res = mcr->result; + if (res != QM_MCR_RESULT_OK) { + /* OOS may fail if FQ has pending frames. + * RETIRED state is safe — FQ won't be scheduled. */ + XX_Print("qman_cleanup: fqid %u OOS failed 0x%02x " + "(left retired)\n", fqid, res); + } + cleaned++; + } + if (cleaned) + printf("qman: retired %d stale FQs\n", cleaned); +} + static t_Error qman_create_portal(t_QmPortal *p_QmPortal, uint32_t flags, uint32_t sdqcrFlags, @@ -1230,6 +1524,8 @@ static t_Error qman_create_portal(t_QmPortal *p_QmPortal, REPORT_ERROR(MAJOR, E_INVALID_STATE, ("MC initialization failed")); goto fail_mc; } + /* Clean up stale FQs from previous boot before enabling SDQCR */ + qman_cleanup_stale_fqs(p_QmPortal->p_LowQmPortal); if (qm_isr_init(p_QmPortal->p_LowQmPortal)) { REPORT_ERROR(MAJOR, E_INVALID_STATE, ("ISR initialization failed")); goto fail_isr; @@ -1272,7 +1568,37 @@ goto fail_dqrr_mr_empty; goto fail_dqrr_mr_empty; } qm_isr_disable_write(p_QmPortal->p_LowQmPortal, 0); + /* + * Inhibit ISR before enabling SDQCR — stale FQs from a previous boot + * (e.g. Linux) may still be in SCHED state. Enabling SDQCR causes + * the hardware to push their DQRR entries immediately. Drain them + * here before the ISR can see them (their contextB pointers are + * garbage in this kernel's address space). + */ + qm_isr_inhibit(p_QmPortal->p_LowQmPortal); qm_dqrr_sdqcr_set(p_QmPortal->p_LowQmPortal, sdqcrFlags); + { + int idle = 0; + while (idle < 1000) { + qmPortalDqrrPvbUpdate(p_QmPortal->p_LowQmPortal); + if (qm_dqrr_current(p_QmPortal->p_LowQmPortal) != NULL) { + qm_dqrr_next(p_QmPortal->p_LowQmPortal); + qmPortalDqrrCciConsume(p_QmPortal->p_LowQmPortal, 1); + idle = 0; + } else { + XX_UDelay(10); + idle++; + } + } + /* Also drain any MR entries that appeared */ + while (qmPortalMrPvbUpdate(p_QmPortal->p_LowQmPortal), + qm_mr_current(p_QmPortal->p_LowQmPortal) != NULL) { + qm_mr_next(p_QmPortal->p_LowQmPortal); + qmPortalMrCciConsume(p_QmPortal->p_LowQmPortal, 1); + } + } + qm_isr_status_clear(p_QmPortal->p_LowQmPortal, 0xffffffff); + qm_isr_uninhibit(p_QmPortal->p_LowQmPortal); return E_OK; fail_dqrr_mr_empty: fail_eqcr_empty: @@ -1341,8 +1667,8 @@ static t_Error qman_orp_update(t_QmPortal *p_QmPortal, else /* No need to check 4 QMAN_ENQUEUE_FLAG_HOLE */ orpSeqnum &= ~QM_EQCR_SEQNUM_NESN; - p_Eq->seqnum = orpSeqnum; - p_Eq->orp = orpId; + WRITE_UINT16(p_Eq->seqnum, orpSeqnum); + WRITE_UINT32(p_Eq->orp, orpId); qmPortalEqcrPvbCommit(p_QmPortal->p_LowQmPortal, (uint8_t)QM_EQCR_VERB_ORP); PUNLOCK(p_QmPortal); @@ -1394,7 +1720,7 @@ static t_Error QmPortalUnregisterCg(t_Handle h_QmPortal, uint8_t cgId) if(!(p_QmPortal->cgrs[0].q.__state[cgId/32] & (0x80000000 >> (cgId % 32)))) RETURN_ERROR(MINOR, E_BUSY, ("CG is not in use")); - p_QmPortal->cgrs[0].q.__state[cgId/32] &= ~0x80000000 >> (cgId % 32); + p_QmPortal->cgrs[0].q.__state[cgId/32] &= ~(0x80000000 >> (cgId % 32)); p_QmPortal->cgsHandles[cgId] = NULL; return E_OK; @@ -1494,7 +1820,6 @@ static t_Error QmPortalPullFrame(t_Handle h_QmPortal, uint32_t pdqcr, t_DpaaFD * t_QmPortal *p_QmPortal = (t_QmPortal *)h_QmPortal; struct qm_dqrr_entry *p_Dq; int prefetch; - uint32_t *p_Dst, *p_Src; ASSERT_COND(p_QmPortal); ASSERT_COND(p_Frame); @@ -1515,13 +1840,8 @@ static t_Error QmPortalPullFrame(t_Handle h_QmPortal, uint32_t pdqcr, t_DpaaFD * p_Dq = qm_dqrr_current(p_QmPortal->p_LowQmPortal); if (!p_Dq) continue; - ASSERT_COND(p_Dq->fqid); - p_Dst = (uint32_t *)p_Frame; - p_Src = (uint32_t *)&p_Dq->fd; - p_Dst[0] = p_Src[0]; - p_Dst[1] = p_Src[1]; - p_Dst[2] = p_Src[2]; - p_Dst[3] = p_Src[3]; + ASSERT_COND(GET_UINT32(p_Dq->fqid)); + qm_fd_read(p_Frame, &p_Dq->fd); if (p_QmPortal->options & QMAN_PORTAL_FLAG_DCA) { qmPortalDqrrDcaConsume1ptr(p_QmPortal->p_LowQmPortal, @@ -1792,6 +2112,12 @@ t_Error QM_PORTAL_AddPoolChannel(t_Handle h_QmPortal, uint8_t poolChannelId) sdqcrFlags |= QM_SDQCR_CHANNELS_POOL(poolChannelId+1); qm_dqrr_sdqcr_set(p_QmPortal->p_LowQmPortal, sdqcrFlags); +#ifdef __aarch64__ + XX_Print("QM_PORTAL_AddPoolChannel: cpu=%d poolCh=%u SDQCR=0x%08x\n", + p_QmPortal->p_LowQmPortal->config.cpu, + (unsigned)poolChannelId, sdqcrFlags); +#endif + return E_OK; } @@ -1820,6 +2146,51 @@ t_Error QM_PORTAL_Poll(t_Handle h_QmPortal, e_QmPortalPollSource source) return E_OK; } +#ifdef __aarch64__ +/* + * Read DQRR state from hardware for diagnostics. + * Returns software PI/CI/fill and hardware PI/CI registers. + */ +void QM_PORTAL_DqrrDiag(t_Handle h_QmPortal, uint8_t *sw_pi, uint8_t *sw_ci, + uint8_t *sw_fill, uint8_t *hw_pi, uint8_t *hw_ci) +{ + t_QmPortal *p_QmPortal = (t_QmPortal *)h_QmPortal; + struct qm_portal *portal = p_QmPortal->p_LowQmPortal; + struct qm_dqrr *dqrr = &portal->dqrr; + + *sw_pi = dqrr->pi; + *sw_ci = dqrr->ci; + *sw_fill = dqrr->fill; + *hw_pi = (uint8_t)(qm_in(DQRR_PI_CINH) & (QM_DQRR_SIZE - 1)); + *hw_ci = (uint8_t)(qm_in(DQRR_CI_CINH) & (QM_DQRR_SIZE - 1)); +} + +void QM_PORTAL_IsrDiag(t_Handle h_QmPortal, uint32_t *isr, uint32_t *ier, + uint32_t *iir) +{ + t_QmPortal *p = (t_QmPortal *)h_QmPortal; + + *isr = qm_isr_status_read(p->p_LowQmPortal); + *ier = qm_isr_enable_read(p->p_LowQmPortal); + *iir = __qm_isr_read(p->p_LowQmPortal, qm_isr_inhibit); +} + +void QM_PORTAL_Inhibit(t_Handle h_QmPortal) +{ + t_QmPortal *p = (t_QmPortal *)h_QmPortal; + + qm_isr_inhibit(p->p_LowQmPortal); +} + +void QM_PORTAL_Uninhibit(t_Handle h_QmPortal) +{ + t_QmPortal *p = (t_QmPortal *)h_QmPortal; + + qm_isr_status_clear(p->p_LowQmPortal, 0xffffffff); + qm_isr_uninhibit(p->p_LowQmPortal); +} +#endif + t_Error QM_PORTAL_PollFrame(t_Handle h_QmPortal, t_QmPortalFrameInfo *p_frameInfo) { t_QmPortal *p_QmPortal = (t_QmPortal *)h_QmPortal; @@ -1842,21 +2213,21 @@ t_Error QM_PORTAL_PollFrame(t_Handle h_QmPortal, t_QmPortalFrameInfo *p_frameInf PUNLOCK(p_QmPortal); return ERROR_CODE(E_EMPTY); } - p_Fq = ptr_from_aligned_int(p_Dq->contextB); - ASSERT_COND(p_Dq->fqid); + p_Fq = ptr_from_aligned_int(GET_UINT32(p_Dq->contextB)); + ASSERT_COND(GET_UINT32(p_Dq->fqid)); if (p_Fq) { p_frameInfo->h_App = p_Fq->h_App; p_frameInfo->h_QmFqr = p_Fq->h_QmFqr; p_frameInfo->fqidOffset = p_Fq->fqidOffset; - memcpy((void*)&p_frameInfo->frame, (void*)&p_Dq->fd, sizeof(t_DpaaFD)); + qm_fd_read(&p_frameInfo->frame, &p_Dq->fd); } else { p_frameInfo->h_App = p_QmPortal->h_App; p_frameInfo->h_QmFqr = NULL; - p_frameInfo->fqidOffset = p_Dq->fqid; - memcpy((void*)&p_frameInfo->frame, (void*)&p_Dq->fd, sizeof(t_DpaaFD)); + p_frameInfo->fqidOffset = GET_UINT32(p_Dq->fqid); + qm_fd_read(&p_frameInfo->frame, &p_Dq->fd); } if (p_QmPortal->options & QMAN_PORTAL_FLAG_DCA) { qmPortalDqrrDcaConsume1ptr(p_QmPortal->p_LowQmPortal, @@ -2138,7 +2509,6 @@ t_Error QM_FQR_Enqueue(t_Handle h_QmFqr, t_Handle h_QmPortal, uint32_t fqidOffse t_QmFqr *p_QmFqr = (t_QmFqr *)h_QmFqr; t_QmPortal *p_QmPortal; struct qm_eqcr_entry *p_Eq; - uint32_t *p_Dst, *p_Src; const struct qman_fq *p_Fq; SANITY_CHECK_RETURN_ERROR(p_QmFqr, E_INVALID_HANDLE); @@ -2171,19 +2541,9 @@ t_Error QM_FQR_Enqueue(t_Handle h_QmFqr, t_Handle h_QmPortal, uint32_t fqidOffse return ERROR_CODE(E_BUSY); } - p_Eq->fqid = p_Fq->fqid; - p_Eq->tag = aligned_int_from_ptr(p_Fq); - /* gcc does a dreadful job of the following; - * eq->fd = *fd; - * It causes the entire function to save/restore a wider range of - * registers, and comes up with instruction-waste galore. This will do - * until we can rework the function for better code-generation. */ - p_Dst = (uint32_t *)&p_Eq->fd; - p_Src = (uint32_t *)p_Frame; - p_Dst[0] = p_Src[0]; - p_Dst[1] = p_Src[1]; - p_Dst[2] = p_Src[2]; - p_Dst[3] = p_Src[3]; + WRITE_UINT32(p_Eq->fqid, p_Fq->fqid); + WRITE_UINT32(p_Eq->tag, aligned_int_from_ptr(p_Fq)); + qm_fd_write(&p_Eq->fd, p_Frame); qmPortalEqcrPvbCommit(p_QmPortal->p_LowQmPortal, (uint8_t)(QM_EQCR_VERB_CMD_ENQUEUE/* | @@ -2193,6 +2553,33 @@ t_Error QM_FQR_Enqueue(t_Handle h_QmFqr, t_Handle h_QmPortal, uint32_t fqidOffse return E_OK; } +t_Error QM_PORTAL_EnqueueFqid(t_Handle h_QmPortal, uint32_t fqid, t_DpaaFD *p_Frame) +{ + t_QmPortal *p_QmPortal; + struct qm_eqcr_entry *p_Eq; + + SANITY_CHECK_RETURN_ERROR(h_QmPortal, E_INVALID_HANDLE); + p_QmPortal = (t_QmPortal *)h_QmPortal; + + NCSW_PLOCK(p_QmPortal); + p_Eq = try_eq_start(p_QmPortal); + if (!p_Eq) + { + PUNLOCK(p_QmPortal); + return ERROR_CODE(E_BUSY); + } + + WRITE_UINT32(p_Eq->fqid, fqid); + WRITE_UINT32(p_Eq->tag, 0); + qm_fd_write(&p_Eq->fd, p_Frame); + + qmPortalEqcrPvbCommit(p_QmPortal->p_LowQmPortal, + (uint8_t)QM_EQCR_VERB_CMD_ENQUEUE); + PUNLOCK(p_QmPortal); + + return E_OK; +} + t_Error QM_FQR_PullFrame(t_Handle h_QmFqr, t_Handle h_QmPortal, uint32_t fqidOffset, t_DpaaFD *p_Frame) { diff --git a/sys/contrib/ncsw/Peripherals/QM/qman_low.h b/sys/contrib/ncsw/Peripherals/QM/qman_low.h index 1becfc15554..687d58f210a 100644 --- a/sys/contrib/ncsw/Peripherals/QM/qman_low.h +++ b/sys/contrib/ncsw/Peripherals/QM/qman_low.h @@ -51,6 +51,30 @@ /***************************/ /* Cache-inhibited register offsets */ +#if defined(__aarch64__) +/* + * ARM64 Layerscape (LS1046A etc.): CI space is 16KB per portal. + * Register offsets differ from PowerPC. + * See Linux drivers/soc/fsl/qbman/qman.c for reference. + */ +#define REG_EQCR_PI_CINH 0x3000 +#define REG_EQCR_CI_CINH 0x3040 +#define REG_EQCR_ITR 0x3080 +#define REG_DQRR_PI_CINH 0x3100 +#define REG_DQRR_CI_CINH 0x3140 +#define REG_DQRR_ITR 0x3180 +#define REG_DQRR_DCAP 0x31C0 +#define REG_DQRR_SDQCR 0x3200 +#define REG_DQRR_VDQCR 0x3240 +#define REG_DQRR_PDQCR 0x3280 +#define REG_MR_PI_CINH 0x3300 +#define REG_MR_CI_CINH 0x3340 +#define REG_MR_ITR 0x3380 +#define REG_CFG 0x3500 +#define REG_ISR 0x3600 +#define REG_ITPR 0x3740 +#define QM_ISR_SHIFT 6 /* ISR/IER/ISDR/IIR stride: 64 bytes */ +#else /* PowerPC */ #define REG_EQCR_PI_CINH 0x0000 #define REG_EQCR_CI_CINH 0x0004 #define REG_EQCR_ITR 0x0008 @@ -66,22 +90,29 @@ #define REG_MR_ITR 0x0088 #define REG_CFG 0x0100 #define REG_ISR 0x0e00 -#define REG_IER 0x0e04 -#define REG_ISDR 0x0e08 -#define REG_IIR 0x0e0c #define REG_ITPR 0x0e14 +#define QM_ISR_SHIFT 2 /* ISR/IER/ISDR/IIR stride: 4 bytes */ +#endif /* Cache-enabled register offsets */ #define CL_EQCR 0x0000 #define CL_DQRR 0x1000 #define CL_MR 0x2000 #define CL_EQCR_PI_CENA 0x3000 +#if defined(__aarch64__) +#define CL_EQCR_CI_CENA 0x3040 +#define CL_DQRR_PI_CENA 0x3100 +#define CL_DQRR_CI_CENA 0x3140 +#define CL_MR_PI_CENA 0x3300 +#define CL_MR_CI_CENA 0x3340 +#else /* PowerPC */ #define CL_EQCR_CI_CENA 0x3100 #define CL_DQRR_PI_CENA 0x3200 #define CL_DQRR_CI_CENA 0x3300 #define CL_MR_PI_CENA 0x3400 #define CL_MR_CI_CENA 0x3500 #define CL_RORI_CENA 0x3600 +#endif #define CL_CR 0x3800 #define CL_RR0 0x3900 #define CL_RR1 0x3940 @@ -300,11 +331,18 @@ static __inline__ struct qm_eqcr_entry *qm_eqcr_pend_and_next(struct qm_portal * } #ifdef QM_CHECKING +/* + * EQCR entries live in CE portal memory (big-endian on hardware). + * On ARM64, WRITE_UINT32 byte-swaps values for the hardware, so we + * must use GET_UINT32 to read them back in host order for validation. + */ #define EQCR_COMMIT_CHECKS(eqcr) \ do { \ ASSERT_COND(eqcr->busy); \ - ASSERT_COND(eqcr->cursor->orp == (eqcr->cursor->orp & 0x00ffffff)); \ - ASSERT_COND(eqcr->cursor->fqid == (eqcr->cursor->fqid & 0x00ffffff)); \ + ASSERT_COND(GET_UINT32(eqcr->cursor->orp) == \ + (GET_UINT32(eqcr->cursor->orp) & 0x00ffffff)); \ + ASSERT_COND(GET_UINT32(eqcr->cursor->fqid) == \ + (GET_UINT32(eqcr->cursor->fqid) & 0x00ffffff)); \ } while(0) #else @@ -878,6 +916,7 @@ static __inline__ void qm_mr_current_prefetch(struct qm_portal *portal) { register struct qm_mr *mr = &portal->mr; dcbt_ro(mr->cursor); + (void)mr; } static __inline__ struct qm_mr_entry *qm_mr_current(struct qm_portal *portal) @@ -1139,10 +1178,10 @@ static __inline__ void qm_isr_set_iperiod(struct qm_portal *portal, uint16_t ipe static __inline__ uint32_t __qm_isr_read(struct qm_portal *portal, enum qm_isr_reg n) { - return __qm_in(&portal->addr, REG_ISR + (n << 2)); + return __qm_in(&portal->addr, REG_ISR + (n << QM_ISR_SHIFT)); } static __inline__ void __qm_isr_write(struct qm_portal *portal, enum qm_isr_reg n, uint32_t val) { - __qm_out(&portal->addr, REG_ISR + (n << 2), val); + __qm_out(&portal->addr, REG_ISR + (n << QM_ISR_SHIFT), val); } diff --git a/sys/contrib/ncsw/Peripherals/QM/qman_private.h b/sys/contrib/ncsw/Peripherals/QM/qman_private.h index 0b172879099..3b5dc9fa745 100644 --- a/sys/contrib/ncsw/Peripherals/QM/qman_private.h +++ b/sys/contrib/ncsw/Peripherals/QM/qman_private.h @@ -56,6 +56,39 @@ * execution reordering with respect to other code/instructions that manipulate * the same cacheline. */ +#if defined(__aarch64__) +/* + * ARM64 cache operations. + * + * Portal CE region is mapped Normal Non-Cacheable (matching Linux's + * MEMREMAP_WC), so stores go directly to hardware. However, dcbf is + * also used on cacheable DMA memory (FQD, PFDR) in qm.c — there we + * need real cache clean to make CPU writes visible to QMan hardware. + * + * dc cvac (clean by VA to PoC) is the ARM64 equivalent of PPC dcbf. + * On NC addresses it's a harmless no-op; on cached addresses it writes + * dirty lines back to memory. + * + * dc zva MUST NOT be used on portal NC memory — it generates a special + * bus transaction that can hang the interconnect. Use memset instead. + */ +#define lwsync() __asm__ __volatile__ ("dmb ish" : : : "memory") +#define dcbf(addr) do { \ + __asm__ __volatile__ ("dc cvac, %0" : : "r"(addr) : "memory"); \ + __asm__ __volatile__ ("dsb st" : : : "memory"); \ +} while(0) +#define dcbi(p) __asm__ __volatile__ ("dsb sy" : : : "memory") +#define dcbt_ro(addr) do { } while(0) +#define dcbt_rw(addr) do { } while(0) +#define dcbz_64(p) do { memset((p), 0, 64); } while(0) +#define dcbf_64(p) do { \ + __asm__ __volatile__ ("dc cvac, %0" : : "r"(p) : "memory"); \ + __asm__ __volatile__ ("dsb st" : : : "memory"); \ +} while(0) +#define dcbit_ro(p) do { } while(0) + +#else /* PowerPC */ + #define dcbf(addr) \ do { \ __asm__ __volatile__ ("dcbf 0, %0" : : "r" (addr)); \ @@ -132,6 +165,8 @@ #define dcbi(p) dcbf(p) +#endif /* __aarch64__ */ + struct qm_addr { void *addr_ce; /* cache-enabled */ void *addr_ci; /* cache-inhibited */ diff --git a/sys/contrib/ncsw/build/dflags_arm64.h b/sys/contrib/ncsw/build/dflags_arm64.h new file mode 100644 index 00000000000..4a5eec8e0e8 --- /dev/null +++ b/sys/contrib/ncsw/build/dflags_arm64.h @@ -0,0 +1,86 @@ +/*- + * Copyright (c) 2026 Mono Technologies Inc. + * All rights reserved. + * + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + */ + +/* + * DPAA1 / NetCommSW build flags for ARM64 (LS1046A). + * + * Equivalent to dflags.h (which targets PowerPC e500mc/P5020). + * Force-included before every ncsw source file via config.dpaa_arm64. + */ +#ifndef DFLAGS_ARM64_H_ +#define DFLAGS_ARM64_H_ + +#include "opt_platform.h" +#include "events_mapping.h" + +/* + * Core selection: ARM64 (Cortex-A72). + * The PPC path uses NCSW_PPC_CORE which pulls in ppc_ext.h and e500v2_ext.h. + * Our ARM path uses NCSW_ARM_CORE which pulls in arm_ext.h with FreeBSD + * ARM64 implementations. + */ +#define NCSW_ARM_CORE +#define NCSW_FREEBSD + +/* Cortex-A72 cache line size (LS1046A) */ +#define CORE_CACHELINE_SIZE 64 + +/* Linux-ism helpers needed by mEMAC flib code */ +#include +#include + +/* + * LIST_ compatibility macros — FreeBSD's list_ext.h prefixes everything + * with NCSW_ to avoid conflicts with . The mEMAC code + * uses the unprefixed original names from the NXP SDK. + * + * Note: LIST_FIRST/NEXT/PREV/LAST conflict with and + * are intentionally omitted here. + */ +#define LIST_Add NCSW_LIST_Add +#define LIST_AddToTail NCSW_LIST_AddToTail +#define LIST_DelAndInit NCSW_LIST_DelAndInit +#define LIST_IsEmpty NCSW_LIST_IsEmpty +#define LIST_OBJECT NCSW_LIST_OBJECT +#define LIST_FOR_EACH NCSW_LIST_FOR_EACH +#define LIST_FOR_EACH_SAFE NCSW_LIST_FOR_EACH_SAFE +#define LIST_FOR_EACH_OBJECT NCSW_LIST_FOR_EACH_OBJECT +#define LIST_FOR_EACH_OBJECT_SAFE NCSW_LIST_FOR_EACH_OBJECT_SAFE + +/* Debugging */ +#define DEBUG_ERRORS 1 +#define DPAA_DEBUG 1 +#if defined(DPAA_DEBUG) +#define DEBUG_GLOBAL_LEVEL REPORT_LEVEL_INFO +#else +#define DEBUG_GLOBAL_LEVEL REPORT_LEVEL_WARNING +#endif + +/* Events */ +#define REPORT_EVENTS 1 +#define EVENT_GLOBAL_LEVEL REPORT_LEVEL_MINOR + +#endif /* DFLAGS_ARM64_H_ */ diff --git a/sys/contrib/ncsw/etc/ncsw_memcpy.c b/sys/contrib/ncsw/etc/ncsw_memcpy.c new file mode 100644 index 00000000000..6793a2ebf84 --- /dev/null +++ b/sys/contrib/ncsw/etc/ncsw_memcpy.c @@ -0,0 +1,6 @@ +/* + * Wrapper to compile ncsw memcpy.c as ncsw_memcpy.o, avoiding + * a name collision with arm64/arm64/memcpy.S (which also produces + * memcpy.o and defines memcpy/memmove). + */ +#include "memcpy.c" diff --git a/sys/contrib/ncsw/inc/Peripherals/bm_ext.h b/sys/contrib/ncsw/inc/Peripherals/bm_ext.h index 952e95f62e4..79a1bff7264 100644 --- a/sys/contrib/ncsw/inc/Peripherals/bm_ext.h +++ b/sys/contrib/ncsw/inc/Peripherals/bm_ext.h @@ -131,6 +131,9 @@ typedef struct { NOTE: this parameter relevant only when working with multiple partitions. */ uint8_t partNumOfPools; /**< Number of Pools dedicated to this partition. NOTE: this parameter relevant only when working with multiple partitions. */ + void *p_FbprBase; /**< Pre-allocated FBPR memory (virtual), or NULL for internal allocation. + Must be physically contiguous, naturally aligned, and non-cacheable. */ + uint32_t fbprSize; /**< Size of pre-allocated FBPR memory in bytes. */ } t_BmParam; diff --git a/sys/contrib/ncsw/inc/Peripherals/dpaa_ext.h b/sys/contrib/ncsw/inc/Peripherals/dpaa_ext.h index e7c0c131fda..fae846e2b8c 100644 --- a/sys/contrib/ncsw/inc/Peripherals/dpaa_ext.h +++ b/sys/contrib/ncsw/inc/Peripherals/dpaa_ext.h @@ -182,29 +182,42 @@ typedef _Packed struct t_DpaaCompTbl { #define DPAA_SGTE_BPID_MASK 0x00ff0000 /**< SGTE BPID field mask */ #define DPAA_SGTE_OFFSET_MASK 0x00001fff /**< SGTE OFFSET field mask */ -#define DPAA_SGTE_GET_ADDRH(sgte) (((t_DpaaSGTE *)sgte)->addrh & DPAA_SGTE_ADDRH_MASK) /**< Macro to get SGTE ADDRH field */ -#define DPAA_SGTE_GET_ADDRL(sgte) ((t_DpaaSGTE *)sgte)->addrl /**< Macro to get SGTE ADDRL field */ -#define DPAA_SGTE_GET_PHYS_ADDR(sgte) ((physAddress_t)(((uint64_t)DPAA_SGTE_GET_ADDRH(sgte) << 32) | (uint64_t)DPAA_SGTE_GET_ADDRL(sgte))) /**< Macro to get FD ADDR field */ -#define DPAA_SGTE_GET_EXTENSION(sgte) ((((t_DpaaSGTE *)sgte)->length & DPAA_SGTE_E_MASK) >> (31-0)) /**< Macro to get SGTE EXTENSION field */ -#define DPAA_SGTE_GET_FINAL(sgte) ((((t_DpaaSGTE *)sgte)->length & DPAA_SGTE_F_MASK) >> (31-1)) /**< Macro to get SGTE FINAL field */ -#define DPAA_SGTE_GET_LENGTH(sgte) (((t_DpaaSGTE *)sgte)->length & DPAA_SGTE_LENGTH_MASK) /**< Macro to get SGTE LENGTH field */ -#define DPAA_SGTE_GET_BPID(sgte) ((((t_DpaaSGTE *)sgte)->offset & DPAA_SGTE_BPID_MASK) >> (31-15)) /**< Macro to get SGTE BPID field */ -#define DPAA_SGTE_GET_OFFSET(sgte) (((t_DpaaSGTE *)sgte)->offset & DPAA_SGTE_OFFSET_MASK) /**< Macro to get SGTE OFFSET field */ +/* + * SGT entries live in host DMA memory and are read/written by FMan in + * big-endian byte order. On big-endian hosts (PowerPC) no swap is needed. + * On little-endian hosts (ARM64) each 32-bit field must be byte-swapped. + */ +#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ +#define _DPAA_SGTE_R32(field) (field) +#define _DPAA_SGTE_W32(field, val) ((field) = (val)) +#else +#define _DPAA_SGTE_R32(field) __builtin_bswap32(field) +#define _DPAA_SGTE_W32(field, val) ((field) = __builtin_bswap32(val)) +#endif + +#define DPAA_SGTE_GET_ADDRH(sgte) (_DPAA_SGTE_R32(((t_DpaaSGTE *)sgte)->addrh) & DPAA_SGTE_ADDRH_MASK) +#define DPAA_SGTE_GET_ADDRL(sgte) _DPAA_SGTE_R32(((t_DpaaSGTE *)sgte)->addrl) +#define DPAA_SGTE_GET_PHYS_ADDR(sgte) ((physAddress_t)(((uint64_t)DPAA_SGTE_GET_ADDRH(sgte) << 32) | (uint64_t)DPAA_SGTE_GET_ADDRL(sgte))) +#define DPAA_SGTE_GET_EXTENSION(sgte) ((_DPAA_SGTE_R32(((t_DpaaSGTE *)sgte)->length) & DPAA_SGTE_E_MASK) >> (31-0)) +#define DPAA_SGTE_GET_FINAL(sgte) ((_DPAA_SGTE_R32(((t_DpaaSGTE *)sgte)->length) & DPAA_SGTE_F_MASK) >> (31-1)) +#define DPAA_SGTE_GET_LENGTH(sgte) (_DPAA_SGTE_R32(((t_DpaaSGTE *)sgte)->length) & DPAA_SGTE_LENGTH_MASK) +#define DPAA_SGTE_GET_BPID(sgte) ((_DPAA_SGTE_R32(((t_DpaaSGTE *)sgte)->offset) & DPAA_SGTE_BPID_MASK) >> (31-15)) +#define DPAA_SGTE_GET_OFFSET(sgte) (_DPAA_SGTE_R32(((t_DpaaSGTE *)sgte)->offset) & DPAA_SGTE_OFFSET_MASK) #define DPAA_SGTE_GET_ADDR(sgte) XX_PhysToVirt(DPAA_SGTE_GET_PHYS_ADDR(sgte)) -#define DPAA_SGTE_SET_ADDRH(sgte,val) (((t_DpaaSGTE *)sgte)->addrh = ((((t_DpaaSGTE *)sgte)->addrh & ~DPAA_SGTE_ADDRH_MASK) | ((val) & DPAA_SGTE_ADDRH_MASK))) /**< Macro to set SGTE ADDRH field */ -#define DPAA_SGTE_SET_ADDRL(sgte,val) ((t_DpaaSGTE *)sgte)->addrl = (val) /**< Macro to set SGTE ADDRL field */ +#define DPAA_SGTE_SET_ADDRH(sgte,val) _DPAA_SGTE_W32(((t_DpaaSGTE *)sgte)->addrh, (_DPAA_SGTE_R32(((t_DpaaSGTE *)sgte)->addrh) & ~DPAA_SGTE_ADDRH_MASK) | ((val) & DPAA_SGTE_ADDRH_MASK)) +#define DPAA_SGTE_SET_ADDRL(sgte,val) _DPAA_SGTE_W32(((t_DpaaSGTE *)sgte)->addrl, (val)) #define DPAA_SGTE_SET_ADDR(sgte,val) \ do { \ uint64_t physAddr = (uint64_t)(XX_VirtToPhys(val)); \ DPAA_SGTE_SET_ADDRH(sgte, ((uint32_t)(physAddr >> 32))); \ DPAA_SGTE_SET_ADDRL(sgte, (uint32_t)physAddr); \ -} while (0) /**< Macro to set SGTE ADDR field */ -#define DPAA_SGTE_SET_EXTENSION(sgte,val) (((t_DpaaSGTE *)sgte)->length = ((((t_DpaaSGTE *)sgte)->length & ~DPAA_SGTE_E_MASK) | (((val) << (31-0))& DPAA_SGTE_E_MASK))) /**< Macro to set SGTE EXTENSION field */ -#define DPAA_SGTE_SET_FINAL(sgte,val) (((t_DpaaSGTE *)sgte)->length = ((((t_DpaaSGTE *)sgte)->length & ~DPAA_SGTE_F_MASK) | (((val) << (31-1))& DPAA_SGTE_F_MASK))) /**< Macro to set SGTE FINAL field */ -#define DPAA_SGTE_SET_LENGTH(sgte,val) (((t_DpaaSGTE *)sgte)->length = (((t_DpaaSGTE *)sgte)->length & ~DPAA_SGTE_LENGTH_MASK) | ((val) & DPAA_SGTE_LENGTH_MASK)) /**< Macro to set SGTE LENGTH field */ -#define DPAA_SGTE_SET_BPID(sgte,val) (((t_DpaaSGTE *)sgte)->offset = ((((t_DpaaSGTE *)sgte)->offset & ~DPAA_SGTE_BPID_MASK) | (((val) << (31-15))& DPAA_SGTE_BPID_MASK))) /**< Macro to set SGTE BPID field */ -#define DPAA_SGTE_SET_OFFSET(sgte,val) (((t_DpaaSGTE *)sgte)->offset = ((((t_DpaaSGTE *)sgte)->offset & ~DPAA_SGTE_OFFSET_MASK) | (((val) << (31-31))& DPAA_SGTE_OFFSET_MASK) )) /**< Macro to set SGTE OFFSET field */ +} while (0) +#define DPAA_SGTE_SET_EXTENSION(sgte,val) _DPAA_SGTE_W32(((t_DpaaSGTE *)sgte)->length, (_DPAA_SGTE_R32(((t_DpaaSGTE *)sgte)->length) & ~DPAA_SGTE_E_MASK) | (((val) << (31-0)) & DPAA_SGTE_E_MASK)) +#define DPAA_SGTE_SET_FINAL(sgte,val) _DPAA_SGTE_W32(((t_DpaaSGTE *)sgte)->length, (_DPAA_SGTE_R32(((t_DpaaSGTE *)sgte)->length) & ~DPAA_SGTE_F_MASK) | (((val) << (31-1)) & DPAA_SGTE_F_MASK)) +#define DPAA_SGTE_SET_LENGTH(sgte,val) _DPAA_SGTE_W32(((t_DpaaSGTE *)sgte)->length, (_DPAA_SGTE_R32(((t_DpaaSGTE *)sgte)->length) & ~DPAA_SGTE_LENGTH_MASK) | ((val) & DPAA_SGTE_LENGTH_MASK)) +#define DPAA_SGTE_SET_BPID(sgte,val) _DPAA_SGTE_W32(((t_DpaaSGTE *)sgte)->offset, (_DPAA_SGTE_R32(((t_DpaaSGTE *)sgte)->offset) & ~DPAA_SGTE_BPID_MASK) | (((val) << (31-15)) & DPAA_SGTE_BPID_MASK)) +#define DPAA_SGTE_SET_OFFSET(sgte,val) _DPAA_SGTE_W32(((t_DpaaSGTE *)sgte)->offset, (_DPAA_SGTE_R32(((t_DpaaSGTE *)sgte)->offset) & ~DPAA_SGTE_OFFSET_MASK) | (((val) << (31-31)) & DPAA_SGTE_OFFSET_MASK)) /* @} */ #if defined(__MWERKS__) && !defined(__GNUC__) diff --git a/sys/contrib/ncsw/inc/Peripherals/fm_ehash.h b/sys/contrib/ncsw/inc/Peripherals/fm_ehash.h new file mode 100644 index 00000000000..b2c5db4f106 --- /dev/null +++ b/sys/contrib/ncsw/inc/Peripherals/fm_ehash.h @@ -0,0 +1,738 @@ +/* + * Shadow fm_ehash.h — FMan External Hash Table API + * + * Replaces the SDK header (which contains Linux-specific inline functions). + * Struct layouts match the NXP SDK exactly: + * sdk_fman/inc/Peripherals/fm_ehash.h + * + * NOTE: en_exthash_info and en_exthash_node are NOT defined here — they + * are defined locally in fm_ehash_freebsd.c (EXCLUDE_FMAN_IPR_OFFLOAD + * variant). CDX code treats table handles as opaque void*. + * + * Copyright 2011, 2014 Freescale Semiconductor, Inc. + * Copyright (c) 2026 Mono Technologies Inc. + * SPDX-License-Identifier: BSD-2-Clause + */ +#ifndef FM_EHASH_H +#define FM_EHASH_H 1 + +#include + +/* ---------------------------------------------------------------- + * Constants + * ---------------------------------------------------------------- */ +#define MAX_KEY_LEN 56 +#define MAX_EN_EHASH_EXT_ENTRY_SIZE 320 +#define MAX_EN_EHASH_ENTRY_SIZE 256 +#define EN_EHASH_ENTRY_ALIGN 256 +#define TBLENTRY_OPC_ALIGN sizeof(uint32_t) +#define MAX_OPCODES 16 + +/* ---------------------------------------------------------------- + * Entry flag accessors + * ---------------------------------------------------------------- */ +#define SET_INVALID_ENTRY_64BIT(entry) (entry |= (((uint64_t)1) << 63)) +#define SET_INVALID_ENTRY(flags) (flags |= (1 << 15)) +#define SET_TIMESTAMP_ENABLE(flags) (flags |= (1 << 13)) +#define SET_STATS_ENABLE(flags) (flags |= (1 << 12)) +#define SET_OPC_OFFSET(flags, offset) (flags |= ((offset >> 2) << 6)) +#define SET_PARAM_OFFSET(flags, offset) (flags |= (offset >> 2)) + +#define GET_INVALID_ENTRY_64BIT(entry) (entry & (((uint64_t)1) << 63)) +#define GET_INVALID_ENTRY(flags) (flags & (1 << 15)) +#define GET_TIMESTAMP_ENABLE(flags) ((flags >> 13) & 1) +#define GET_STATS_ENABLE(flags) (flags & (1 << 12)) +#define GET_OPC_OFFSET(x) (((x >> 6) & 0x1f) << 2) +#define GET_PARAM_OFFSET(x) ((x & 0x3f) << 2) + +/* ---------------------------------------------------------------- + * Hash table entry — on-hardware representation + * ---------------------------------------------------------------- */ +struct en_ehash_entry { + union { + struct { + union { + struct { + uint16_t flags; + uint16_t next_entry_hi; + uint32_t next_entry_lo; + }; + uint64_t next_entry; + }; + uint8_t key[0]; + } __attribute__((packed)); + struct { + uint8_t hash_entry[MAX_EN_EHASH_ENTRY_SIZE]; + uint64_t packet_count; + uint64_t packet_bytes; + uint32_t timestamp; + uint32_t reserved; + uint32_t timestamp_counter; + } __attribute__((packed)); + uint8_t hash_ext_entry[MAX_EN_EHASH_EXT_ENTRY_SIZE]; + } __attribute__((packed)); +} __attribute__((packed)); + +/* ---------------------------------------------------------------- + * DPA Classifier table entry statistics + * ---------------------------------------------------------------- */ +#define STATS_VALID (1 << 0) +#define TIMESTAMP_VALID (1 << 1) + +struct en_tbl_entry_stats { + uint64_t pkts; + uint64_t bytes; + uint32_t timestamp; + uint32_t flags; +}; + +/* ---------------------------------------------------------------- + * Opcodes + * ---------------------------------------------------------------- */ +#define ENQUEUE_PKT 0x01 +#define REPLICATE_PKT 0x02 +#define ENQUEUE_ONLY 0x03 +#define UPDATE_ETH_RX_STATS 0x04 +#define PREEMPTIVE_CHECKS_ON_PKT 0x05 +#define PREEMPTIVE_CHECKS_ON_IPSEC_PKT 0x06 +#define STRIP_ETH_HDR 0x11 +#define STRIP_ALL_VLAN_HDRS 0x12 +#define STRIP_PPPoE_HDR 0x14 +#define STRIP_L2_HDR 0x17 +#define STRIP_FIRST_VLAN_HDR 0x18 +#define REMOVE_FIRST_IP_HDR 0x19 +#define VALIDATE_IPSEC_ID 0x1a +#define UPDATE_TTL 0x21 +#define UPDATE_SIP_V4 0x22 +#define UPDATE_DIP_V4 0x24 +#define UPDATE_HOPLIMIT 0x29 +#define UPDATE_SIP_V6 0x2A +#define UPDATE_DIP_V6 0x2C +#define UPDATE_SPORT 0x31 +#define UPDATE_DPORT 0x32 +#define INSERT_L2_HDR 0x41 +#define INSERT_VLAN_HDR 0x42 +#define INSERT_PPPoE_HDR 0x43 +#define INSERT_L3_HDR 0x44 +#define REPLACE_PPPOE_HDR 0x45 +#define NATPT_4to6 0x51 +#define NATPT_6to4 0x52 +#define PROCESS_RTP_PAYLOAD 0x61 +#define PROCESS_RTCP_PAYLOAD 0x62 +#define UPDATE_GLOBAL_STATS 0x80 + +/* ---------------------------------------------------------------- + * Preemptive check parameters + * ---------------------------------------------------------------- */ +#define PREEMPT_TX_VALIDATE (1 << 0) +#define PREEMPT_DFBIT_HONOR (1 << 1) +#define PREEMPT_POLICE_PKT (1 << 2) +#define PREEMPT_MATCH_DSCP (1 << 3) +#define PREEMPT_REPLACE_DSCP (1 << 4) + +struct en_ehash_preempt_op { + uint8_t mtu_offset; + uint8_t OpMask; + uint8_t dscp_match_value; + uint8_t pp_no; + uint8_t new_dscp_val; + uint8_t pad; + uint16_t pad1; +} __attribute__((packed)); + +/* ---------------------------------------------------------------- + * IPSec preemptive check parameters + * ---------------------------------------------------------------- */ +#define MAX_VLAN_PER_FLOW 2 +#define MAX_SPI_PER_FLOW 16 +#define VALIDATE_SPI (0x1 << 0) + +struct spi_info { + uint32_t spi; + uint32_t fqid; +} __attribute__((packed)); + +struct en_ehash_ipsec_preempt_op { + uint8_t op_flags; + uint8_t unused; + uint16_t natt_arr_mask; + uint16_t pppoe_session_id; + uint16_t pad; + struct spi_info spi_param[MAX_SPI_PER_FLOW]; +} __attribute__((packed)); + +/* ---------------------------------------------------------------- + * Enqueue parameters + * ---------------------------------------------------------------- */ +#define EN_EHASH_DISABLE_FRAG 0xffff + +struct en_ehash_enqueue_param { + uint16_t mtu; + uint8_t hdr_xpnd_sz; + uint8_t bpid; + uint32_t fqid; + union { + struct { + uint32_t rspid:8; + uint32_t stats_ptr:24; + }; + uint32_t word; + }; + union { + struct { + uint32_t dscp_fq_enable:8; + uint32_t muram_frag_param_addr:24; + }; + uint32_t word2; + }; +} __attribute__((packed)); + +/* ---------------------------------------------------------------- + * RTP relay parameters + * ---------------------------------------------------------------- */ +#define EEH_RTP_SEND_FIRST_PACKET_TO_CP 0x0001 +#define EEH_RTP_DUPLICATE_PKT_SEND_TO_CP 0x0002 +#define EEH_RTP_ENABLE_VLAN_P_BIT_LEARN 0x0004 + +struct en_ehash_rtprelay_param { + uint32_t rtpinfo_ptr; + uint32_t in_sock_stats_ptr; + uint32_t out_sock_stats_ptr; + union { + uint32_t src_ipv4_val; + uint32_t src_ipv6_val[4]; + } __attribute__((packed)); + uint32_t TimeStampIncr; + uint32_t SSRC_1; + uint16_t seq_base; + uint16_t egress_socketID; + uint8_t DTMF_PT[2]; + uint16_t rtp_flags; + uint16_t seq_incr; + uint32_t chksum_ptr; + uint32_t rtp_hdr; + uint32_t ts_incr; + uint32_t cur_ts_msec; + int32_t rtp_check; +} __attribute__((packed)); + +/* ---------------------------------------------------------------- + * Replicate parameters (multicast) + * ---------------------------------------------------------------- */ +struct en_ehash_replicate_param { + union { + struct { + uint16_t rsvd; + uint16_t first_member_flow_addr_hi; + uint32_t first_member_flow_addr_lo; + }; + uint64_t first_member_flow_addr; + }; + void *first_listener_entry; +} __attribute__((packed)); + +/* ---------------------------------------------------------------- + * Update ethernet RX stats + * ---------------------------------------------------------------- */ +struct en_ehash_update_ether_rx_stats { + uint32_t stats_ptr; +} __attribute__((packed)); + +/* ---------------------------------------------------------------- + * Strip first VLAN header + * ---------------------------------------------------------------- */ +struct en_ehash_strip_first_vlan_hdr { + uint32_t stats_ptr; + uint16_t vlan_id; + uint16_t pad; +} __attribute__((packed)); + +/* ---------------------------------------------------------------- + * Strip all VLAN headers + * ---------------------------------------------------------------- */ +#define OP_SKIP_VLAN_VALIDATE (1 << 0) +#define OP_VLAN_FILTER_EN (1 << 1) +#define OP_VLAN_FILTER_PVID_SET (1 << 2) + +struct en_ehash_strip_all_vlan_hdrs { + uint16_t vlan_id[MAX_VLAN_PER_FLOW]; + union { + struct { + uint32_t padding:2; + uint32_t num_entries:6; + uint32_t stats_ptr:24; + }; + uint32_t word; + }; + uint8_t op_flags; + uint8_t pad; + uint16_t pad1; + uint8_t stats_offsets[0]; +} __attribute__((packed)); + +/* ---------------------------------------------------------------- + * Strip PPPoE header + * ---------------------------------------------------------------- */ +struct en_ehash_strip_pppoe_hdr { + uint32_t stats_ptr; +} __attribute__((packed)); + +/* ---------------------------------------------------------------- + * Strip all L2 headers + * ---------------------------------------------------------------- */ +struct en_ehash_strip_l2_hdrs { + uint16_t vlan_id[MAX_VLAN_PER_FLOW]; + union { + struct { + uint32_t padding:2; + uint32_t num_entries:6; + uint32_t stats_ptr:24; + }; + uint32_t word; + }; + uint8_t stats_offsets[0]; +} __attribute__((packed)); + +/* ---------------------------------------------------------------- + * Validate IPSec ID + * ---------------------------------------------------------------- */ +struct en_ehash_validate_ipsec { + uint32_t reserved:16; + uint32_t identifier:16; +} __attribute__((packed)); + +/* ---------------------------------------------------------------- + * Update IP addresses + * ---------------------------------------------------------------- */ +struct en_ehash_update_ipv4_ip { + uint32_t ip_v4; +} __attribute__((packed)); + +struct en_ehash_update_ipv6_ip { + uint8_t ip_v6[16]; +} __attribute__((packed)); + +/* ---------------------------------------------------------------- + * Update DSCP + * ---------------------------------------------------------------- */ +struct en_ehash_update_dscp { + union { + struct { + uint32_t rsvd:24; + uint32_t dscp_mark_value:6; + uint32_t dscp_mark_flag:1; + uint32_t padding:1; + }; + uint32_t dscp; + }; +} __attribute__((packed)); + +/* ---------------------------------------------------------------- + * Update ports + * ---------------------------------------------------------------- */ +struct en_ehash_update_port { + uint16_t dport; + uint16_t sport; +} __attribute__((packed)); + +/* ---------------------------------------------------------------- + * Insert L2 header + * ---------------------------------------------------------------- */ +struct en_ehash_insert_l2_hdr { + union { + struct { + uint8_t replace:1; + uint8_t header_padding:2; + uint8_t reserved:5; + uint8_t stats_count; + uint8_t reserved_1; + uint8_t hdr_len; + }; + uint32_t word; + }; + uint8_t l2hdr[0]; +} __attribute__((packed)); + +struct en_ehash_insert_l2_hdr_stats { + union { + struct { + uint32_t padding:2; + uint32_t reserved:6; + uint32_t stats_ptr:24; + }; + uint32_t word; + }; + uint8_t stats_offsets[0]; +} __attribute__((packed)); + +/* ---------------------------------------------------------------- + * Insert VLAN header + * ---------------------------------------------------------------- */ +struct en_ehash_insert_vlan_hdr { + union { + struct { + uint32_t reserved:1; + uint32_t dscp_vlanpcp_map_enable:1; + uint32_t num_hdrs:6; + uint32_t statptr:24; + } __attribute__((packed)); + uint32_t word; + } __attribute__((packed)); + uint32_t vlanhdr[0]; +} __attribute__((packed)); + +struct en_ehash_insert_vlan_hdr_stats { + uint8_t stats_offsets[1]; +} __attribute__((packed)); + +/* ---------------------------------------------------------------- + * Insert/replace PPPoE header + * ---------------------------------------------------------------- */ +#define PPPoE_VERSION 1 +#define PPPoE_TYPE 1 +#define PPPoE_CODE 0 + +struct en_ehash_insert_pppoe_hdr { + uint32_t stats_ptr; + union { + struct { + uint32_t version:4; + uint32_t type:4; + uint32_t code:8; + uint32_t session_id:16; + }; + uint32_t word; + }; +} __attribute__((packed)); + +struct en_ehash_replace_pppoe_hdr_params { + uint8_t destination_mac[6]; + uint8_t source_mac[6]; + uint16_t session_id; + uint16_t pad; + uint32_t fqid; + uint32_t stats_ptr; +} __attribute__((packed)); + +/* ---------------------------------------------------------------- + * Insert L3 header (tunnels) + * ---------------------------------------------------------------- */ +#define TYPE_CUSTOM 0 +#define TYPE_4o6 1 +#define TYPE_6o4 2 + +#define IPID_STARTVAL 1 + +struct en_ehash_insert_l3_hdr { + union { + struct { + uint8_t reserved:3; + uint8_t calc_cksum:1; + uint8_t qos:1; + uint8_t df:1; + uint8_t type:2; + uint8_t hdr_len; + uint16_t ipident; + }; + uint32_t word; + }; + union { + struct { + uint32_t route_dest_offset:8; + uint32_t stats_ptr:24; + }; + uint32_t word_1; + }; + uint8_t l3hdr[0]; +} __attribute__((packed)); + +#define COPY_DSCP_OUTER_INNER (1 << 24) + +/* ---------------------------------------------------------------- + * Remove first IP header (tunnel decap) + * ---------------------------------------------------------------- */ +struct en_ehash_remove_first_ip_hdr { + uint32_t flags:8; + uint32_t stats_ptr:24; +} __attribute__((packed)); + +/* ---------------------------------------------------------------- + * Port info / interface stats structures + * ---------------------------------------------------------------- */ +struct en_ehash_portinfo { + uint32_t reserved[3]; + uint32_t port_info; +} __attribute__((packed)); + +struct en_ehash_ifportinfo { + struct en_ehash_portinfo rxpinfo; + struct en_ehash_portinfo txpinfo; +} __attribute__((packed)); + +struct en_ehash_stats { + uint64_t bytes; + uint32_t pkts; + uint32_t reserved; +} __attribute__((packed)); + +struct en_ehash_stats_with_ts { + uint64_t bytes; + uint32_t pkts; + uint32_t pad; + uint64_t timestamp; +} __attribute__((packed)); + +struct en_ehash_ifstats { + struct en_ehash_stats rxstats; + struct en_ehash_stats txstats; +} __attribute__((packed)); + +#define STATS_WITH_TS (1 << 7) + +struct en_ehash_ifstats_with_ts { + struct en_ehash_stats_with_ts rxstats; + struct en_ehash_stats_with_ts txstats; +} __attribute__((packed)); + +/* Statistics table */ +struct en_ehash_stats_tbl { + uint32_t table_indicator:1; + uint32_t num_entries:7; + uint32_t stats_ptr:24; +} __attribute__((packed)); + +/* ---------------------------------------------------------------- + * NATPT structures + * ---------------------------------------------------------------- */ +struct en_ehash_natpt_hdr { + union { + struct { + uint32_t reserved:6; + uint32_t tcu:1; + uint32_t hlu:1; + uint32_t hdrlen:8; + uint32_t reserved1:16; + } ip4to6; + struct { + uint16_t reserved:5; + uint16_t ipu:1; + uint16_t tou:1; + uint16_t tlu:1; + uint16_t hdrlen:8; + uint16_t ipident; + } ip6to4; + uint32_t word; + }; + uint8_t l3hdr[0]; +} __attribute__((packed)); + +/* NATPT 4-to-6 flags */ +#define NATPT_TCU (1 << 25) +#define NATPT_HLU (1 << 24) +/* NATPT 6-to-4 flags */ +#define NATPT_IPU (1 << 26) +#define NATPT_TOU (1 << 25) +#define NATPT_TLU (1 << 24) + +/* ---------------------------------------------------------------- + * SEC failure statistics + * ---------------------------------------------------------------- */ +typedef struct en_SEC_failure_stats_s { + uint32_t icv_failures; + uint32_t hw_errs; + uint32_t CCM_AAD_size_errs; + uint32_t anti_replay_late_errs; + uint32_t anti_replay_replay_errs; + uint32_t seq_num_overflows; + uint32_t DMA_errs; + uint32_t DECO_watchdog_timer_timedout_errs; + uint32_t input_frame_read_errs; + uint32_t protocol_format_errs; + uint32_t ipsec_ttl_zero_errs; + uint32_t ipsec_pad_chk_failures; + uint32_t output_frame_length_rollover_errs; + uint32_t tbl_buff_too_small_errs; + uint32_t tbl_buff_pool_depletion_errs; + uint32_t output_frame_too_large_errs; + uint32_t cmpnd_frame_write_errs; + uint32_t buff_too_small_errs; + uint32_t buff_pool_depletion_errs; + uint32_t output_frame_write_errs; + uint32_t cmpnd_frame_read_errs; + uint32_t prehdr_read_errs; + uint32_t other_errs; +} __attribute__((packed)) en_SEC_failure_stats; + +/* ---------------------------------------------------------------- + * DSCP-to-VLAN PCP mapping + * ---------------------------------------------------------------- */ +#define MAX_VLAN_PCP 7 + +typedef struct en_dscp_vlanpcp_map_cfg_s { + uint8_t dscp_vlanpcp[MAX_VLAN_PCP + 1]; +} __attribute__((packed)) en_dscp_vlanpcp_map_cfg; + +/* ---------------------------------------------------------------- + * Global MURAM data area — at pool + EN_INTERNAL_BUFF_POOL_SIZE + * + * Contains DSCP-to-VLAN PCP mapping (8 bytes) followed by SEC + * failure statistics (92 bytes). Total: 100 bytes within a + * 256-byte MURAM slot. CDX microcode reads/writes these at runtime. + * ---------------------------------------------------------------- */ +typedef struct en_exthash_global_mem_s { + en_dscp_vlanpcp_map_cfg dscp_vlanpcp_map; /* +0, 8B */ + en_SEC_failure_stats SEC_failure_stats; /* +8, 92B */ +} __attribute__((packed)) en_exthash_global_mem; + +/* ---------------------------------------------------------------- + * IP reassembly MURAM parameters — written by FMan microcode, + * fields configured by ExternalHashSetReasslyPool(). + * + * This is the hardware layout in MURAM, pointed to by + * en_exthash_node.word_2 (reassm_param << 8) for REASSM tables. + * All multi-byte fields are stored big-endian. + * ---------------------------------------------------------------- */ +#define MAX_REASSM_BUCKETS 16 + +struct ip_reassembly_stats { + uint64_t num_frag_pkts; + uint64_t num_reassemblies; + uint64_t num_completed_reassly; + uint64_t num_sess_matches; + uint64_t num_frags_too_small; + uint64_t num_reassm_timeouts; + uint64_t num_overlapping_frags; + uint64_t num_too_many_frags; + uint64_t num_failed_bufallocs; + uint64_t num_failed_ctxallocs; + uint64_t num_fatal_errors; + uint64_t num_failed_ctxdeallocs; + uint32_t reassm_count; + uint32_t pad; +} __attribute__((packed)); + +struct ip_reassembly_params { + uint32_t table_base_hi; + uint32_t table_base_lo; + struct ip_reassembly_stats stats; + uint32_t table_mask; + uint32_t type; + uint32_t ipr_timer; + uint32_t timeout_val; + uint32_t timeout_fqid; + uint32_t min_frag_size; + uint32_t reassem_bpid; + uint32_t reassem_bsize; + uint32_t frag_bpid; + uint32_t frag_bsize; + uint32_t reassly_dbg; + uint32_t context_info; + uint32_t curr_sessions; + uint32_t txc_fqid; + uint32_t timer_tnum; + uint32_t max_frags; + uint32_t max_con_reassm; + uint32_t bucket_base; + uint32_t bucket_lock[MAX_REASSM_BUCKETS]; + uint32_t bucket_head[MAX_REASSM_BUCKETS]; +} __attribute__((packed)); + +/* ---------------------------------------------------------------- + * IP reassembly info (for devman.h forward reference) + * ---------------------------------------------------------------- */ +struct ip_reassembly_info { + uint64_t num_frag_pkts; + uint64_t num_reassemblies; + uint64_t num_completed_reassly; + uint64_t num_sess_matches; + uint64_t num_frags_too_small; + uint64_t num_reassm_timeouts; + uint64_t num_overlapping_frags; + uint64_t num_too_many_frags; + uint64_t num_failed_bufallocs; + uint64_t num_failed_ctxallocs; + uint64_t num_fatal_errors; + uint64_t num_failed_ctxdeallocs; + uint32_t table_mask; + uint32_t ipr_timer; + uint32_t timeout_val; + uint32_t timeout_fqid; + uint32_t max_frags; + uint32_t min_frag_size; + uint32_t max_con_reassm; + uint32_t reassem_bpid; + uint32_t reassem_bsize; + uint32_t frag_bpid; + uint32_t frag_bsize; + uint32_t timer_tnum; + uint32_t reassly_dbg; + uint32_t curr_sessions; + uint32_t txc_fqid; +}; + +/* ---------------------------------------------------------------- + * Software table entry wrapping the hardware entry + * ---------------------------------------------------------------- */ +struct en_exthash_tbl_entry { + struct en_ehash_entry hashentry; + struct en_exthash_tbl_entry *prev; + struct en_exthash_tbl_entry *next; + uint8_t *replicate_params; + union { + uint8_t *enqueue_params; + uint8_t *ipsec_preempt_params; + }; +}; + +/* Hash table bucket */ +struct en_exthash_bucket { + uint64_t h; + uint64_t pad; +}; + +/* ---------------------------------------------------------------- + * Debug display — no-op stubs replacing SDK inline functions + * that use printk/phys_to_virt/etc. Tier 1 code calls these + * but they're debug-only and not needed for correct operation. + * ---------------------------------------------------------------- */ +static inline void +display_ehash_tbl_entry(struct en_ehash_entry *entry __attribute__((unused)), + uint32_t keysize __attribute__((unused))) +{ +} + +/* ---------------------------------------------------------------- + * ExternalHash API + * ---------------------------------------------------------------- */ +extern void *ExternalHashTableAllocEntry(void *h_HashTbl); +extern void ExternalHashTableEntryFree(void *entry); +extern int ExternalHashTableFmPcdHcSync(void *h_HashTbl); +extern int ExternalHashTableAddKey(void *h_HashTbl, uint8_t keySize, + void *tbl_entry); +extern int ExternalHashTableDeleteKey(void *h_HashTbl, uint16_t index, + void *tbl_entry); +extern int ExternalHashTableEntryGetStatsAndTS(void *tbl_entry, + struct en_tbl_entry_stats *stats); +extern int32_t ExternalHashGetSECfailureStats(en_SEC_failure_stats *stats); +extern int32_t ExternalHashResetSECfailureStats(void); +extern int32_t ExternalHashSetDscpVlanpcpMapCfg(en_dscp_vlanpcp_map_cfg *map); +extern int32_t ExternalHashGetDscpVlanpcpMapCfg(en_dscp_vlanpcp_map_cfg *map); +extern int ExternalHashSetReasslyPool(uint32_t type, uint32_t ctx_bpid, + uint32_t ctx_bpsize, uint32_t frag_bpid, uint32_t frag_size, + uint32_t txc_fqid, uint32_t ipr_timer_freq); + +/* Kernel-internal ehash API (called from fm_cc.c) */ +extern t_Handle ExternalHashTableSet(t_Handle h_FmPcd, + t_FmPcdHashTableParams *p_Param); +extern void copy_td_to_ccbase(void *handle, t_Handle p_CcTreeTmp); +extern t_Error ExternalHashTableModifyMissNextEngine(t_Handle h_HashTbl, + t_FmPcdCcNextEngineParams *p_FmPcdCcNextEngineParams); +extern void ExternalHashTableDelete(t_Handle h_HashTbl); +extern int ExternalHashReasslyTableExists(uint32_t type); + +/* CDX module exports */ +extern void ipr_update_timestamp(void); +extern void cdx_ehash_update_timestamp(uint32_t id, uint32_t value); +extern uint32_t cdx_ehash_get_timestamp_addr(uint32_t id); + +#endif /* FM_EHASH_H */ diff --git a/sys/contrib/ncsw/inc/Peripherals/fm_ext.h b/sys/contrib/ncsw/inc/Peripherals/fm_ext.h index c3633592694..d12600c89bf 100644 --- a/sys/contrib/ncsw/inc/Peripherals/fm_ext.h +++ b/sys/contrib/ncsw/inc/Peripherals/fm_ext.h @@ -1462,6 +1462,11 @@ t_Error FM_GetFmanCtrlCodeRevision(t_Handle h_Fm, t_FmCtrlCodeRevisionInfo *p_Re *//***************************************************************************/ uint32_t FM_GetCounter(t_Handle h_Fm, e_FmCounters counter); +#ifdef __aarch64__ +void FM_ErrorDiag(t_Handle h_Fm, uint8_t hwPortId); +void FM_TaskStatusDiag(t_Handle h_Fm, uint8_t hwPortId); +#endif + /**************************************************************************//** @Function FM_ModifyCounter diff --git a/sys/contrib/ncsw/inc/Peripherals/fm_pcd_ext.h b/sys/contrib/ncsw/inc/Peripherals/fm_pcd_ext.h index 8d1c3d88945..488b4c81d79 100644 --- a/sys/contrib/ncsw/inc/Peripherals/fm_pcd_ext.h +++ b/sys/contrib/ncsw/inc/Peripherals/fm_pcd_ext.h @@ -39,6 +39,10 @@ #ifndef __FM_PCD_EXT #define __FM_PCD_EXT +/* CDX enhanced external hash tables — redirect FM_PCD_HashTable* APIs + * to ExternalHashTable* implementations (matching Linux SDK). */ +#define USE_ENHANCED_EHASH 1 + #include "std_ext.h" #include "net_ext.h" #include "list_ext.h" @@ -1718,6 +1722,8 @@ typedef struct t_FmPcdKgSchemeParams { uint8_t relativeSchemeId; /**< if modify=FALSE:Partition relative scheme id */ t_Handle h_Scheme; /**< if modify=TRUE: a handle of the existing scheme */ } id; + bool shared; /**< This scheme is shared between ports + (must match ioc_fm_pcd_kg_scheme_params_t layout) */ bool alwaysDirect; /**< This scheme is reached only directly, i.e. no need for match vector; KeyGen will ignore it when matching */ struct { /**< HL Relevant only if alwaysDirect = FALSE */ @@ -1991,6 +1997,34 @@ typedef struct t_FmPcdHashTableParams { t_FmPcdCcNextEngineParams ccNextEngineParamsForMiss; /**< Parameters for defining the next engine when a key is not matched */ + bool agingSupport; /**< TRUE to enable aging support for all keys of this + hash table; allows monitoring whether a key was + accessed during a given period. */ + +#if (DPAA_VERSION >= 11) + bool externalHash; /**< TRUE to use external hash table (CDX manages + the hash buckets in DDR; NCSW only allocates the + MURAM AD placeholder). */ + +#ifndef EXCLUDE_FMAN_IPR_OFFLOAD + uint32_t table_type; /**< IP reassembly table type + (must match ioc_fm_pcd_hash_table_params_t layout) */ + struct { + uint32_t timeout_val; /**< reassembly timeout */ + uint32_t timeout_fqid; /**< fqid for reassembly failures */ + uint32_t max_frags; /**< max allowed fragments */ + uint32_t min_frag_size; /**< min allowed frag size except last frag */ + uint32_t max_sessions; /**< max conn reassembly sessions */ + }; +#endif /* EXCLUDE_FMAN_IPR_OFFLOAD */ + + struct { + uint8_t dataMemId; /**< Memory partition ID for external hash table + buckets and contexts; must not cross 4GB boundary */ + uint16_t dataLiodnOffs; /**< LIODN offset for external hash table access */ + uintptr_t missMonitorAddr; /**< User-allocated miss monitor address */ + } externalHashParams; +#endif /* (DPAA_VERSION >= 11) */ } t_FmPcdHashTableParams; /**************************************************************************//** diff --git a/sys/contrib/ncsw/inc/Peripherals/qm_ext.h b/sys/contrib/ncsw/inc/Peripherals/qm_ext.h index 6a4bc9fcfe6..9c20ee48d7c 100644 --- a/sys/contrib/ncsw/inc/Peripherals/qm_ext.h +++ b/sys/contrib/ncsw/inc/Peripherals/qm_ext.h @@ -1,6 +1,6 @@ /****************************************************************************** - © 1995-2003, 2004, 2005-2011 Freescale Semiconductor, Inc. + � 1995-2003, 2004, 2005-2011 Freescale Semiconductor, Inc. All rights reserved. This is proprietary source code of Freescale Semiconductor Inc., @@ -258,6 +258,13 @@ typedef struct { NOTE: this parameter relevant only when working with multiple partitions. */ uint16_t partNumOfCgs; /**< Number of cgr's dedicated to this partition. NOTE: this parameter relevant only when working with multiple partitions. */ + void *p_FqdBase; /**< Pre-allocated FQD memory (virtual), or NULL for internal allocation. + Must be physically contiguous, naturally aligned, and non-cacheable. + When set, totalNumOfFqids is computed from fqdSize / 64. */ + uint32_t fqdSize; /**< Size of pre-allocated FQD memory in bytes. */ + void *p_PfdrBase; /**< Pre-allocated PFDR memory (virtual), or NULL for internal allocation. + Must be physically contiguous, naturally aligned, and non-cacheable. */ + uint32_t pfdrSize; /**< Size of pre-allocated PFDR memory in bytes. */ } t_QmParam; @@ -791,6 +798,40 @@ typedef struct t_QmPortalFrameInfo { *//***************************************************************************/ t_Error QM_PORTAL_Poll(t_Handle h_QmPortal, e_QmPortalPollSource source); +#ifdef __aarch64__ +void QM_PORTAL_DqrrDiag(t_Handle h_QmPortal, uint8_t *sw_pi, uint8_t *sw_ci, + uint8_t *sw_fill, uint8_t *hw_pi, uint8_t *hw_ci); +void QM_PORTAL_IsrDiag(t_Handle h_QmPortal, uint32_t *isr, uint32_t *ier, + uint32_t *iir); + +void QM_ErrorDiag(t_Handle h_Qm, uint32_t *err_isr, uint32_t *ecsr, + uint32_t *ecir, uint32_t *pfdr_fpc, uint32_t *sfdr_in_use, + uint32_t *idle_stat, uint32_t *dcp0_cfg, uint32_t *dcp0_dlm_avg, + uint32_t *dcp_dd_ihrsr, uint32_t *dcp_dd_hasr); + +/**************************************************************************//** + @Function QM_PORTAL_Inhibit + + @Description Inhibit all interrupts for this portal (IIR=1). + Used by NAPI-style FILTER handler to mask interrupts + at the source before scheduling deferred processing. + + @Param[in] h_QmPortal - A handle to a QM-Portal module +*//***************************************************************************/ +void QM_PORTAL_Inhibit(t_Handle h_QmPortal); + +/**************************************************************************//** + @Function QM_PORTAL_Uninhibit + + @Description Clear all pending ISR status and uninhibit portal + interrupts (IIR=0). Called after draining DQRR/MR + to re-enable interrupt delivery. + + @Param[in] h_QmPortal - A handle to a QM-Portal module +*//***************************************************************************/ +void QM_PORTAL_Uninhibit(t_Handle h_QmPortal); +#endif + /**************************************************************************//** @Function QM_PORTAL_PollFrame @@ -1058,6 +1099,21 @@ uint32_t QM_FQR_GetCounter(t_Handle h_QmFqr, t_Handle h_QmPortal, uint32_t fqidO *//***************************************************************************/ t_Error QM_FQR_Enqueue(t_Handle h_QmFqr, t_Handle h_QmPortal, uint32_t fqidOffset, t_DpaaFD *p_Frame); +/**************************************************************************//** + @Function QM_PORTAL_EnqueueFqid + + @Description Enqueue a frame to a specific FQID without requiring an FQR + handle. Used for CEETM frame queues which are managed by + CEETM hardware rather than NCSW FQR. + + @Param[in] h_QmPortal - A handle to a QM Portal Module. + @Param[in] fqid - The target Frame Queue ID. + @Param[in] p_Frame - Pointer to the frame to enqueue. + + @Return E_OK on success; Error code otherwise. +*//***************************************************************************/ +t_Error QM_PORTAL_EnqueueFqid(t_Handle h_QmPortal, uint32_t fqid, t_DpaaFD *p_Frame); + /**************************************************************************//** @Function QM_FQR_PullFrame diff --git a/sys/contrib/ncsw/inc/core_ext.h b/sys/contrib/ncsw/inc/core_ext.h index ec89a6dde4c..8b4779672cc 100644 --- a/sys/contrib/ncsw/inc/core_ext.h +++ b/sys/contrib/ncsw/inc/core_ext.h @@ -43,7 +43,11 @@ #ifndef __CORE_EXT_H #define __CORE_EXT_H -#ifdef CONFIG_FMAN_ARM +#if defined(NCSW_ARM_CORE) +/* FreeBSD ARM64 path — CORE_CACHELINE_SIZE set in dflags_arm64.h */ +#include "arm_ext.h" +#elif defined(CONFIG_FMAN_ARM) +/* Linux ARM path */ #include "arm_ext.h" #include #else @@ -63,7 +67,7 @@ #error "Must define the core cache-line size!" #endif /* !CORE_CACHELINE_SIZE */ -#endif /* CONFIG_FMAN_ARM */ +#endif /* NCSW_ARM_CORE / CONFIG_FMAN_ARM */ /**************************************************************************//** diff --git a/sys/contrib/ncsw/inc/cores/arm_ext.h b/sys/contrib/ncsw/inc/cores/arm_ext.h index e63444a7d67..5ab333d1efd 100644 --- a/sys/contrib/ncsw/inc/cores/arm_ext.h +++ b/sys/contrib/ncsw/inc/cores/arm_ext.h @@ -35,9 +35,6 @@ @File arm_ext.h @Description Core API for ARM cores - - These routines must be implemented by each specific PowerPC - core driver. *//***************************************************************************/ #ifndef __ARM_EXT_H #define __ARM_EXT_H @@ -52,4 +49,28 @@ static __inline__ void CORE_MemoryBarrier(void) mb(); } -#endif /* __PPC_EXT_H */ +#if defined(NCSW_ARM_CORE) && defined(NCSW_FREEBSD) +/* + * FreeBSD ARM64 core function bindings. + * Implementations are in core_arm64.c. + * + * Follow the same pattern as PPC: e500v2_ext.h defines + * CORE_GetId -> E500_GetId, etc. We map to ARM64_* equivalents. + */ + +uint32_t ARM64_GetId(void); +int ARM64_TestAndSet(volatile int *p); +void ARM64_InstructionSync(void); + +#define CORE_GetId ARM64_GetId +#define CORE_TestAndSet ARM64_TestAndSet +#define CORE_InstructionSync ARM64_InstructionSync + +/* Cache management — handled by the kernel on ARM64, no-ops here */ +#define CORE_DCacheEnable() do { } while (0) +#define CORE_ICacheEnable() do { } while (0) +#define CORE_DCacheDisable() do { } while (0) +#define CORE_ICacheDisable() do { } while (0) +#endif /* NCSW_ARM_CORE && NCSW_FREEBSD */ + +#endif /* __ARM_EXT_H */ diff --git a/sys/contrib/ncsw/inc/integrations/dpaa_integration_ext.h b/sys/contrib/ncsw/inc/integrations/dpaa_integration_ext.h index 27bb5d40237..7003e027971 100644 --- a/sys/contrib/ncsw/inc/integrations/dpaa_integration_ext.h +++ b/sys/contrib/ncsw/inc/integrations/dpaa_integration_ext.h @@ -103,6 +103,45 @@ typedef enum e_QM_FQ_CHANNEL_SWPORTAL8, e_QM_FQ_CHANNEL_SWPORTAL9, +#ifdef __aarch64__ + /* QMan v3 (LS1046A): pool channels at 0x401-0x40F, FMan DC at 0x800+, + * CAAM at 0x840. SW portal channels (0-9) are unchanged. */ + e_QM_FQ_CHANNEL_POOL1 = 0x401, + e_QM_FQ_CHANNEL_POOL2, + e_QM_FQ_CHANNEL_POOL3, + e_QM_FQ_CHANNEL_POOL4, + e_QM_FQ_CHANNEL_POOL5, + e_QM_FQ_CHANNEL_POOL6, + e_QM_FQ_CHANNEL_POOL7, + e_QM_FQ_CHANNEL_POOL8, + e_QM_FQ_CHANNEL_POOL9, + e_QM_FQ_CHANNEL_POOL10, + e_QM_FQ_CHANNEL_POOL11, + e_QM_FQ_CHANNEL_POOL12, + e_QM_FQ_CHANNEL_POOL13, + e_QM_FQ_CHANNEL_POOL14, + e_QM_FQ_CHANNEL_POOL15, + + e_QM_FQ_CHANNEL_FMAN0_SP0 = 0x800, + e_QM_FQ_CHANNEL_FMAN0_SP1, + e_QM_FQ_CHANNEL_FMAN0_SP2, + e_QM_FQ_CHANNEL_FMAN0_SP3, + e_QM_FQ_CHANNEL_FMAN0_SP4, + e_QM_FQ_CHANNEL_FMAN0_SP5, + e_QM_FQ_CHANNEL_FMAN0_SP6, + e_QM_FQ_CHANNEL_FMAN0_SP7, + e_QM_FQ_CHANNEL_FMAN0_SP8, + e_QM_FQ_CHANNEL_FMAN0_SP9, + e_QM_FQ_CHANNEL_FMAN0_SP10, + e_QM_FQ_CHANNEL_FMAN0_SP11, + e_QM_FQ_CHANNEL_FMAN0_SP12, + e_QM_FQ_CHANNEL_FMAN0_SP13, + e_QM_FQ_CHANNEL_FMAN0_SP14, + e_QM_FQ_CHANNEL_FMAN0_SP15, + + e_QM_FQ_CHANNEL_CAAM = 0x840 +#else + /* QMan v1/v2 (P5020): pool channels at 0x21-0x2F, FMan DC at 0x40+ */ e_QM_FQ_CHANNEL_POOL1 = 0x21, /**< Pool channels that can be serviced by any of the software portals */ e_QM_FQ_CHANNEL_POOL2, e_QM_FQ_CHANNEL_POOL3, @@ -144,6 +183,7 @@ typedef enum connected to PME */ e_QM_FQ_CHANNEL_RAID = 0xC0 /**< Dedicated channel serviced by Direct Connect Portal 4: connected to RAID */ +#endif } e_QmFQChannel; /***************************************************************************** @@ -156,11 +196,31 @@ typedef enum ******************************************************************************/ #define INTG_MAX_NUM_OF_FM 1 +/* + * ---------- Architecture-dependent integration parameters ---------- + * + * ARM64 (LS1046A / FManv3, DPAA 1.1) + * Values from NXP Linux SDK LS1043 dpaa_integration_ext.h + * PowerPC (P5020 / FManv2, DPAA 1.0) + * Original FreeBSD values + */ +#ifdef __aarch64__ +#define DPAA_VERSION 11 +#else +#define DPAA_VERSION 10 +#endif + /* Ports defines */ +#ifdef __aarch64__ +#define FM_MAX_NUM_OF_1G_MACS 6 +#define FM_MAX_NUM_OF_10G_MACS 2 +#define FM_MAX_NUM_OF_OH_PORTS 6 +#else #define FM_MAX_NUM_OF_1G_MACS 5 #define FM_MAX_NUM_OF_10G_MACS 1 -#define FM_MAX_NUM_OF_MACS (FM_MAX_NUM_OF_1G_MACS + FM_MAX_NUM_OF_10G_MACS) #define FM_MAX_NUM_OF_OH_PORTS 7 +#endif +#define FM_MAX_NUM_OF_MACS (FM_MAX_NUM_OF_1G_MACS + FM_MAX_NUM_OF_10G_MACS) #define FM_MAX_NUM_OF_1G_RX_PORTS FM_MAX_NUM_OF_1G_MACS #define FM_MAX_NUM_OF_10G_RX_PORTS FM_MAX_NUM_OF_10G_MACS @@ -170,46 +230,85 @@ typedef enum #define FM_MAX_NUM_OF_10G_TX_PORTS FM_MAX_NUM_OF_10G_MACS #define FM_MAX_NUM_OF_TX_PORTS (FM_MAX_NUM_OF_10G_TX_PORTS + FM_MAX_NUM_OF_1G_TX_PORTS) +#ifdef __aarch64__ +#define FM_PORT_MAX_NUM_OF_EXT_POOLS 4 /**< Number of external BM pools per Rx port */ +#define FM_MAX_NUM_OF_SUB_PORTALS 16 +#else #define FM_PORT_MAX_NUM_OF_EXT_POOLS 8 /**< Number of external BM pools per Rx port */ -#define FM_PORT_NUM_OF_CONGESTION_GRPS 256 /**< Total number of congestion groups in QM */ #define FM_MAX_NUM_OF_SUB_PORTALS 12 +#endif +#define FM_PORT_NUM_OF_CONGESTION_GRPS 256 /**< Total number of congestion groups in QM */ #define FM_PORT_MAX_NUM_OF_OBSERVED_EXT_POOLS 0 +#if (DPAA_VERSION >= 11) +#define FM_VSP_MAX_NUM_OF_ENTRIES 64 +#define FM_MAX_NUM_OF_PFC_PRIORITIES 8 +#endif + /* RAMs defines */ -#define FM_MURAM_SIZE (160 * KILOBYTE) +#ifdef __aarch64__ +#define FM_MURAM_SIZE (384 * KILOBYTE) /**< LS1046A FManv3: 384KB MURAM */ +#else +#define FM_MURAM_SIZE (160 * KILOBYTE) /**< P5020 FManv2: 160KB MURAM */ +#endif #define FM_IRAM_SIZE(a,b) ( 64 * KILOBYTE) /* PCD defines */ #define FM_PCD_PLCR_NUM_ENTRIES 256 /**< Total number of policer profiles */ #define FM_PCD_KG_NUM_OF_SCHEMES 32 /**< Total number of KG schemes */ #define FM_PCD_MAX_NUM_OF_CLS_PLANS 256 /**< Number of classification plan entries. */ +#define FM_PCD_SW_PRS_SIZE 0x00000800 +#ifdef __aarch64__ +#define FM_PCD_PRS_SW_PATCHES_SIZE 0x00000600 +#else +#define FM_PCD_PRS_SW_PATCHES_SIZE 0x00000200 +#endif /* RTC defines */ #define FM_RTC_NUM_OF_ALARMS 2 /**< RTC number of alarms */ +#ifdef __aarch64__ +#define FM_RTC_NUM_OF_PERIODIC_PULSES 3 /**< RTC number of periodic pulses */ +#else #define FM_RTC_NUM_OF_PERIODIC_PULSES 2 /**< RTC number of periodic pulses */ +#endif #define FM_RTC_NUM_OF_EXT_TRIGGERS 2 /**< RTC number of external triggers */ /* QMI defines */ #define QMI_MAX_NUM_OF_TNUMS 64 +#ifdef __aarch64__ +#define QMI_DEF_TNUMS_THRESH 32 +#else #define MAX_QMI_DEQ_SUBPORTAL 12 #define QMI_DEF_TNUMS_THRESH 48 +#endif /* FPM defines */ #define FM_NUM_OF_FMAN_CTRL_EVENT_REGS 4 /* DMA defines */ +#ifdef __aarch64__ +#define DMA_THRESH_MAX_COMMQ 83 +#else #define DMA_THRESH_MAX_COMMQ 31 +#endif #define DMA_THRESH_MAX_BUF 127 /* BMI defines */ #define BMI_MAX_NUM_OF_TASKS 128 +#ifdef __aarch64__ +#define BMI_MAX_NUM_OF_DMAS 84 +#define FM_NUM_OF_CTRL 4 +#else #define BMI_MAX_NUM_OF_DMAS 32 +#define FM_NUM_OF_CTRL 2 +#endif #define BMI_MAX_FIFO_SIZE (FM_MURAM_SIZE) #define PORT_MAX_WEIGHT 16 #define FM_CHECK_PORT_RESTRICTIONS(__validPorts, __newPortIndx) TRUE +#ifndef __aarch64__ /* P5020 unique features */ #define FM_QMI_DEQ_OPTIONS_SUPPORT #define FM_NO_DISPATCH_RAM_ECC @@ -250,8 +349,6 @@ typedef enum #define FM_IM_LARGE_MRBLR_ERRATA_FMAN15 /* Implemented by ucode */ #define FM_BMI_TO_RISC_ENQ_ERRATA_FMANc /* No implementation, Out of LLD scope */ #define FM_INVALID_SWPRS_DATA_ERRATA_FMANd -//#define FM_PRS_MPLS_SSA_ERRATA_FMANj /* No implementation, No patch yet */ -//#define FM_PRS_INITIAL_PLANID_ERRATA_FMANk /* No implementation, No patch yet */ #define FM_NO_COPY_CTXA_CTXB_ERRATA_FMAN_SW001 @@ -260,16 +357,35 @@ typedef enum /* P2041 */ #define FM_BAD_VLAN_DETECT_ERRATA_10GMAC_A010 -/* Common to all */ +/* Common to P5020 */ #define FM_RX_PREAM_4_ERRATA_DTSEC_A001 FM_NO_RX_PREAM_ERRATA_DTSECx1 #define FM_UCODE_NOT_RESET_ERRATA_BUGZILLA6173 #define FM_MAGIC_PACKET_UNRECOGNIZED_ERRATA_DTSEC2 /* No implementation, Out of LLD scope */ #define FM_PRS_MEM_ERRATA_FMAN_SW003 + +#else /* __aarch64__ — LS1046A / FManv3 errata and features */ + +#define FM_OP_OPEN_DMA_MIN_LIMIT +#define FM_NO_RESTRICT_ON_ACCESS_RSRC +#define FM_NO_OP_OBSERVED_POOLS +#define FM_FRAME_END_PARAMS_FOR_OP +#define FM_DEQ_PIPELINE_PARAMS_FOR_OP +#define FM_QMI_NO_SINGLE_ECC_EXCEPTION +#define FM_NO_GUARANTEED_RESET_VALUES + +/* LS1046A / FManv3 errata */ +#define FM_HEAVY_TRAFFIC_HANG_ERRATA_FMAN_A005669 +#define FM_WRONG_RESET_VALUES_ERRATA_FMAN_A005127 +#define FM_RX_FIFO_CORRUPT_ERRATA_10GMAC_A006320 +#define FM_OP_NO_VSP_NO_RELEASE_ERRATA_FMAN_A006675 +#define FM_HEAVY_TRAFFIC_SEQUENCER_HANG_ERRATA_FMAN_A006981 +#define FM_BCB_ERRATA_BMI_SW001 +#define FM_AID_MODE_NO_TNUM_SW005 +#define FM_ERROR_VSP_NO_MATCH_SW006 + +#endif /* __aarch64__ */ + +/* Common to all platforms */ #define FM_LEN_CHECK_ERRATA_FMAN_SW002 -#define DPAA_VERSION 10 -#define FM_PCD_SW_PRS_SIZE 0x00000800 -#define FM_PCD_PRS_SW_PATCHES_SIZE 0x00000200 -#define FM_NUM_OF_CTRL 2 - #endif /* __DPAA_INTEGRATION_EXT_H */ diff --git a/sys/contrib/ncsw/inc/integrations/part_ext.h b/sys/contrib/ncsw/inc/integrations/part_ext.h index 0fa70299389..614fc499a37 100644 --- a/sys/contrib/ncsw/inc/integrations/part_ext.h +++ b/sys/contrib/ncsw/inc/integrations/part_ext.h @@ -44,8 +44,14 @@ #include "enet_ext.h" #include "dpaa_integration_ext.h" +#if defined(NCSW_ARM_CORE) +/* ARM64 — LS1046A has 4x Cortex-A72; no PPC core type */ +#define INTG_MAX_NUM_OF_CORES 4 +#else +/* PowerPC — P5020/P3041/P5040 */ #define CORE_E500MC #define INTG_MAX_NUM_OF_CORES 24 +#endif /**************************************************************************//* @Description Part data structure - must be contained in any integration diff --git a/sys/contrib/ncsw/inc/types_freebsd.h b/sys/contrib/ncsw/inc/types_freebsd.h index 031da08e0f7..e37fb2502c2 100644 --- a/sys/contrib/ncsw/inc/types_freebsd.h +++ b/sys/contrib/ncsw/inc/types_freebsd.h @@ -36,7 +36,7 @@ #include #if !defined(__bool_true_false_are_defined) -typedef boolean_t bool; +typedef _Bool bool; #endif #define TRUE 1 #define FALSE 0 @@ -48,22 +48,39 @@ typedef vm_paddr_t physAddress_t; /** * Accessor defines. - * TODO: These are only stubs and have to be redefined (use bus_space - * facilities). + * DPAA1 registers are big-endian. On PowerPC (big-endian), native + * in32/out32 match. On ARM64 (little-endian), use the reverse-byte + * variants (in32rb/out32rb) to byte-swap. */ +#ifdef __aarch64__ +#define GET_UINT32(arg) in32rb(&(arg)) +#define GET_UINT64(arg) in64(&(arg)) + +#define _WRITE_UINT32(arg, data) out32rb(&(arg), (data)) +#define _WRITE_UINT64(arg, data) out64(&(arg), (data)) +#else #define GET_UINT32(arg) in32(&(arg)) #define GET_UINT64(arg) in64(&(arg)) #define _WRITE_UINT32(arg, data) out32(&(arg), (data)) #define _WRITE_UINT64(arg, data) out64(&(arg), (data)) +#endif #ifndef QE_32_BIT_ACCESS_RESTRICTION +#ifdef __aarch64__ +#define GET_UINT8(arg) in8(&(arg)) +#define GET_UINT16(arg) in16rb(&(arg)) + +#define _WRITE_UINT8(arg, data) out8(&(arg), (data)) +#define _WRITE_UINT16(arg, data) out16rb(&(arg), (data)) +#else #define GET_UINT8(arg) in8(&(arg)) #define GET_UINT16(arg) in16(&(arg)) #define _WRITE_UINT8(arg, data) out8(&(arg), (data)) #define _WRITE_UINT16(arg, data) out16(&(arg), (data)) +#endif #else /* QE_32_BIT_ACCESS_RESTRICTION */ diff --git a/sys/contrib/ncsw/user/env/core_arm64.c b/sys/contrib/ncsw/user/env/core_arm64.c new file mode 100644 index 00000000000..552d6be43ca --- /dev/null +++ b/sys/contrib/ncsw/user/env/core_arm64.c @@ -0,0 +1,60 @@ +/*- + * Copyright (c) 2026 Mono Technologies Inc. + * All rights reserved. + * + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + */ + +/* + * ARM64 core functions for NetCommSW (DPAA1). + * Equivalent to core.c (which provides E500_GetId for PowerPC). + */ +#include +#include +#include +#include + +#include + +#include "types_ext.h" +#include "core_ext.h" + +uint32_t +ARM64_GetId(void) +{ + + return (PCPU_GET(cpuid)); +} + +int +ARM64_TestAndSet(volatile int *p) +{ + + return (!atomic_cmpset_int((volatile u_int *)p, 0, 1)); +} + +void +ARM64_InstructionSync(void) +{ + + __asm __volatile("isb" ::: "memory"); +} diff --git a/sys/contrib/ncsw/user/env/xx_arm64.c b/sys/contrib/ncsw/user/env/xx_arm64.c new file mode 100644 index 00000000000..25ece0021f5 --- /dev/null +++ b/sys/contrib/ncsw/user/env/xx_arm64.c @@ -0,0 +1,797 @@ +/*- + * Copyright (c) 2011 Semihalf. + * Copyright (c) 2026 Mono Technologies Inc. + * All rights reserved. + * + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + */ + +/* + * NetCommSW (ncsw) environment layer for FreeBSD ARM64. + * + * Adapted from xx.c (PowerPC version) by Semihalf. Key differences: + * + * 1. No ccsrbar_va/pa (ARM64 uses FDT-based bus_space mappings) + * 2. No law_enable (ARM64 doesn't have Local Access Windows) + * 3. No powerpc_intr_mask/unmask (GIC handles interrupt masking) + * 4. No TLB1 management (ARM64 uses page tables) + * 5. XX_VirtToPhys/XX_PhysToVirt use DMAP exclusively + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include +#include + +#include +#include +#include + +#include "error_ext.h" +#include "std_ext.h" +#include "list_ext.h" +#include "mm_ext.h" + +/* Malloc Pool for NetCommSW */ +MALLOC_DEFINE(M_NETCOMMSW, "NetCommSW", "NetCommSW software stack"); +MALLOC_DEFINE(M_NETCOMMSW_MT, "NetCommSWTrack", + "NetCommSW software allocation tracker"); + +static struct mtx XX_MallocTrackLock; +MTX_SYSINIT(XX_MallocTrackLockInit, &XX_MallocTrackLock, + "NetCommSW MallocTrack Lock", MTX_DEF); + +/* Interrupt info */ +#define XX_INTR_FLAG_PREALLOCATED (1 << 0) + +/* + * ARM64 GIC can have many more interrupts than PowerPC (INTR_VECTORS=256). + * DPAA1 only uses a handful; 512 is plenty. + */ +#define XX_MAX_INTR 512 + +struct XX_IntrInfo { + driver_intr_t *handler; + void *arg; + int cpu; + int flags; + void *cookie; + /* NAPI mode: non-NULL napi_tq enables FILTER handler */ + struct taskqueue *napi_tq; + struct task *napi_task; + t_Handle napi_portal; +}; + +static struct XX_IntrInfo XX_IntrInfo[XX_MAX_INTR]; + +/* Portal type identifiers */ +enum XX_PortalIdent{ + BM_PORTAL = 0, + QM_PORTAL, +}; + +/* Structure to store portals' properties */ +struct XX_PortalInfo { + vm_paddr_t portal_ce_pa[2][MAXCPU]; + vm_paddr_t portal_ci_pa[2][MAXCPU]; + uint32_t portal_ce_size[2][MAXCPU]; + uint32_t portal_ci_size[2][MAXCPU]; + vm_offset_t portal_ce_va[2]; + vm_offset_t portal_ci_va[2]; + uintptr_t portal_intr[2][MAXCPU]; +}; + +static struct XX_PortalInfo XX_PInfo; + +void +XX_Exit(int status) +{ + + panic("NetCommSW: Exit called with status %i", status); +} + +void +XX_Print(char *str, ...) +{ + va_list ap; + + va_start(ap, str); + vprintf(str, ap); + va_end(ap); +} + +void * +XX_Malloc(uint32_t size) +{ + void *p = (malloc(size, M_NETCOMMSW, M_NOWAIT)); + + return (p); +} + +/* + * XX_MallocSmartInit — no-op, kept for API compatibility. + * Previously allocated a fixed contigmalloc pool; now XX_MallocSmart + * delegates to XX_Malloc (kernel heap) with manual alignment, matching + * the Linux NCSW implementation. + */ +int +XX_MallocSmartInit(void) +{ + + return (E_OK); +} + +/* + * XX_MallocSmart — aligned allocation via kernel heap. + * + * Matches Linux NCSW xx_arm_linux.c: allocate size + alignment + header, + * align the returned pointer, store the original malloc pointer in the + * word immediately before it so XX_FreeSmart can recover it. + */ +void * +XX_MallocSmart(uint32_t size, int memPartitionId, uint32_t alignment) +{ + uintptr_t *aligned, raw; + + if (alignment < sizeof(uintptr_t)) + alignment = sizeof(uintptr_t); + + size += alignment + sizeof(uintptr_t); + raw = (uintptr_t)XX_Malloc(size); + if (raw == 0) + return (NULL); + + aligned = (uintptr_t *)((raw + alignment + sizeof(uintptr_t)) + & ~((uintptr_t)alignment - 1)); + *(aligned - 1) = raw; + + return ((void *)aligned); +} + +void +XX_FreeSmart(void *p) +{ + + if (p != NULL) + XX_Free((void *)(*(((uintptr_t *)p) - 1))); +} + +void +XX_Free(void *p) +{ + + free(p, M_NETCOMMSW); +} + +uint32_t +XX_DisableAllIntr(void) +{ + + return (intr_disable()); +} + +void +XX_RestoreAllIntr(uint32_t flags) +{ + + intr_restore(flags); +} + +static bool +XX_IsPortalIntr(uintptr_t irq) +{ + int cpu, type; + /* Check interrupt numbers of all available portals */ + for (type = 0; type < 2; type++) + for (cpu = 0; cpu < MAXCPU; cpu++) + if (irq == XX_PInfo.portal_intr[type][cpu]) + return (1); + + return (0); +} + +static void +XX_Dispatch(void *arg) +{ + struct XX_IntrInfo *info; + + info = arg; + + if (info->handler == NULL) { + printf("%s(): IRQ handler is NULL!\n", __func__); + return; + } + + info->handler(info->arg); +} + +/* + * FILTER interrupt handler for NAPI-style portal processing. + * Runs in hard IRQ context — inhibits portal interrupts at the + * source (IIR=1) and schedules a taskqueue task for deferred + * DQRR/MR drain. Matches Linux's portal_isr → napi_schedule pattern. + */ +static int +XX_PortalFilter(void *arg) +{ + struct XX_IntrInfo *info = arg; + + if (__predict_false(info->napi_portal == NULL)) + return (FILTER_STRAY); + + QM_PORTAL_Inhibit(info->napi_portal); + taskqueue_enqueue(info->napi_tq, info->napi_task); + + return (FILTER_HANDLED); +} + +/* + * Configure NAPI mode for a portal interrupt. Must be called + * before QM_PORTAL_Init (which calls XX_SetIntr internally). + */ +void XX_ConfigPortalNapi(uintptr_t irq, struct taskqueue *tq, struct task *task); +void XX_SetPortalNapiHandle(uintptr_t irq, t_Handle portal); +void +XX_ConfigPortalNapi(uintptr_t irq, struct taskqueue *tq, struct task *task) +{ + struct resource *r; + unsigned int inum; + + r = (struct resource *)irq; + inum = rman_get_start(r); + + if (inum >= XX_MAX_INTR) + return; + + XX_IntrInfo[inum].napi_tq = tq; + XX_IntrInfo[inum].napi_task = task; + XX_IntrInfo[inum].napi_portal = NULL; +} + +/* + * Set the portal handle for a NAPI-configured interrupt. + * Called after QM_PORTAL_Init returns the portal handle. + */ +void +XX_SetPortalNapiHandle(uintptr_t irq, t_Handle portal) +{ + struct resource *r; + unsigned int inum; + + r = (struct resource *)irq; + inum = rman_get_start(r); + + if (inum >= XX_MAX_INTR) + return; + + XX_IntrInfo[inum].napi_portal = portal; +} + +t_Error +XX_PreallocAndBindIntr(device_t dev, uintptr_t irq, unsigned int cpu) +{ + struct resource *r; + unsigned int inum; + + r = (struct resource *)irq; + inum = rman_get_start(r); + + if (inum >= XX_MAX_INTR) { + printf("NetCommSW: IRQ %u exceeds XX_MAX_INTR (%d)\n", + inum, XX_MAX_INTR); + return (E_FULL); + } + + /* + * Don't call bus_setup_intr here — just record the CPU binding. + * The OS interrupt handler will be registered later when the + * portal driver calls XX_SetIntr with a real handler. This + * prevents interrupt storms from stale portal state on warm + * reboot (portal hardware may assert IRQ before the driver + * is ready to clear it). + */ + XX_IntrInfo[inum].flags = XX_INTR_FLAG_PREALLOCATED; + XX_IntrInfo[inum].cpu = cpu; + + return (E_OK); +} + +t_Error +XX_DeallocIntr(uintptr_t irq) +{ + struct resource *r; + unsigned int inum; + + r = (struct resource *)irq; + inum = rman_get_start(r); + + if (inum >= XX_MAX_INTR) + return (E_INVALID_STATE); + + if ((XX_IntrInfo[inum].flags & XX_INTR_FLAG_PREALLOCATED) == 0) + return (E_INVALID_STATE); + + XX_IntrInfo[inum].flags = 0; + XX_IntrInfo[inum].handler = NULL; + XX_IntrInfo[inum].arg = NULL; + + /* Tear down OS handler only if it was registered */ + if (XX_IntrInfo[inum].cookie != NULL) + return (XX_FreeIntr(irq)); + + return (E_OK); +} + +t_Error +XX_SetIntr(uintptr_t irq, t_Isr *f_Isr, t_Handle handle) +{ + device_t dev; + struct resource *r; + unsigned int flags; + int err; + + r = (struct resource *)irq; + dev = rman_get_device(r); + irq = rman_get_start(r); + + if (irq >= XX_MAX_INTR) + return (E_FULL); + + /* Handle preallocated interrupts */ + if (XX_IntrInfo[irq].flags & XX_INTR_FLAG_PREALLOCATED) { + if (XX_IntrInfo[irq].handler != NULL) + return (E_BUSY); + + XX_IntrInfo[irq].handler = f_Isr; + XX_IntrInfo[irq].arg = handle; + + /* Register OS handler now that portal driver is ready */ + if (XX_IntrInfo[irq].cookie == NULL) { + unsigned int iflags; + int err; + + iflags = INTR_TYPE_NET | INTR_MPSAFE; + if (XX_IsPortalIntr(irq)) + iflags |= INTR_EXCL; + + if (XX_IntrInfo[irq].napi_tq != NULL) { + /* NAPI mode: FILTER-only, no ithread */ + err = bus_setup_intr(dev, r, iflags, + XX_PortalFilter, NULL, + &XX_IntrInfo[irq], + &XX_IntrInfo[irq].cookie); + } else { + /* Legacy ithread mode */ + err = bus_setup_intr(dev, r, iflags, NULL, + XX_Dispatch, &XX_IntrInfo[irq], + &XX_IntrInfo[irq].cookie); + } + if (err) + return (E_NOT_AVAILABLE); + + bus_bind_intr(dev, r, XX_IntrInfo[irq].cpu); + } + + return (E_OK); + } + + flags = INTR_TYPE_NET | INTR_MPSAFE; + + /* BMAN/QMAN Portal interrupts must be exclusive */ + if (XX_IsPortalIntr(irq)) + flags |= INTR_EXCL; + + err = bus_setup_intr(dev, r, flags, NULL, f_Isr, handle, + &XX_IntrInfo[irq].cookie); + + return (err); +} + +t_Error +XX_FreeIntr(uintptr_t irq) +{ + device_t dev; + struct resource *r; + + r = (struct resource *)irq; + dev = rman_get_device(r); + irq = rman_get_start(r); + + if (irq >= XX_MAX_INTR) + return (E_INVALID_STATE); + + /* Handle preallocated interrupts */ + if (XX_IntrInfo[irq].flags & XX_INTR_FLAG_PREALLOCATED) { + if (XX_IntrInfo[irq].handler == NULL) + return (E_INVALID_STATE); + + XX_IntrInfo[irq].handler = NULL; + XX_IntrInfo[irq].arg = NULL; + + return (E_OK); + } + + return (bus_teardown_intr(dev, r, XX_IntrInfo[irq].cookie)); +} + +t_Error +XX_EnableIntr(uintptr_t irq) +{ + /* + * On ARM64 with GIC, interrupt masking/unmasking is handled + * by the interrupt framework. Portal interrupts are set up + * with INTR_EXCL; the GIC re-enables them after handler return. + */ + (void)irq; + return (E_OK); +} + +t_Error +XX_DisableIntr(uintptr_t irq) +{ + /* + * See XX_EnableIntr — no explicit mask needed on ARM64. + */ + (void)irq; + return (E_OK); +} + +t_TaskletHandle +XX_InitTasklet (void (*routine)(void *), void *data) +{ + /* Not referenced */ + printf("NetCommSW: Unimplemented function %s() called!\n", __func__); + return (NULL); +} + + +void +XX_FreeTasklet (t_TaskletHandle h_Tasklet) +{ + /* Not referenced */ + printf("NetCommSW: Unimplemented function %s() called!\n", __func__); +} + +int +XX_ScheduleTask(t_TaskletHandle h_Tasklet, int immediate) +{ + /* Not referenced */ + printf("NetCommSW: Unimplemented function %s() called!\n", __func__); + return (0); +} + +void +XX_FlushScheduledTasks(void) +{ + /* Not referenced */ + printf("NetCommSW: Unimplemented function %s() called!\n", __func__); +} + +int +XX_TaskletIsQueued(t_TaskletHandle h_Tasklet) +{ + /* Not referenced */ + printf("NetCommSW: Unimplemented function %s() called!\n", __func__); + return (0); +} + +void +XX_SetTaskletData(t_TaskletHandle h_Tasklet, t_Handle data) +{ + /* Not referenced */ + printf("NetCommSW: Unimplemented function %s() called!\n", __func__); +} + +t_Handle +XX_GetTaskletData(t_TaskletHandle h_Tasklet) +{ + /* Not referenced */ + printf("NetCommSW: Unimplemented function %s() called!\n", __func__); + return (NULL); +} + +t_Handle +XX_InitSpinlock(void) +{ + struct mtx *m; + + m = malloc(sizeof(*m), M_NETCOMMSW, M_NOWAIT | M_ZERO); + if (!m) + return (0); + + mtx_init(m, "NetCommSW Lock", NULL, MTX_DEF | MTX_DUPOK); + + return (m); +} + +void +XX_FreeSpinlock(t_Handle h_Spinlock) +{ + struct mtx *m; + + m = h_Spinlock; + + mtx_destroy(m); + free(m, M_NETCOMMSW); +} + +void +XX_LockSpinlock(t_Handle h_Spinlock) +{ + struct mtx *m; + + m = h_Spinlock; + mtx_lock(m); +} + +void +XX_UnlockSpinlock(t_Handle h_Spinlock) +{ + struct mtx *m; + + m = h_Spinlock; + mtx_unlock(m); +} + +uint32_t +XX_LockIntrSpinlock(t_Handle h_Spinlock) +{ + + XX_LockSpinlock(h_Spinlock); + return (0); +} + +void +XX_UnlockIntrSpinlock(t_Handle h_Spinlock, uint32_t intrFlags) +{ + + XX_UnlockSpinlock(h_Spinlock); +} + +uint32_t +XX_Sleep(uint32_t msecs) +{ + + XX_UDelay(1000 * msecs); + return (0); +} + +void +XX_UDelay(uint32_t usecs) +{ + DELAY(usecs); +} + +t_Error +XX_IpcRegisterMsgHandler(char addr[XX_IPC_MAX_ADDR_NAME_LENGTH], + t_IpcMsgHandler *f_MsgHandler, t_Handle h_Module, uint32_t replyLength) +{ + + /* + * This function returns fake E_OK status and does nothing + * as NetCommSW IPC is not used by FreeBSD drivers. + */ + return (E_OK); +} + +t_Error +XX_IpcUnregisterMsgHandler(char addr[XX_IPC_MAX_ADDR_NAME_LENGTH]) +{ + /* + * This function returns fake E_OK status and does nothing + * as NetCommSW IPC is not used by FreeBSD drivers. + */ + return (E_OK); +} + + +t_Error +XX_IpcSendMessage(t_Handle h_Session, + uint8_t *p_Msg, uint32_t msgLength, uint8_t *p_Reply, + uint32_t *p_ReplyLength, t_IpcMsgCompletion *f_Completion, t_Handle h_Arg) +{ + + /* Should not be called */ + printf("NetCommSW: Unimplemented function %s() called!\n", __func__); + return (E_OK); +} + +t_Handle +XX_IpcInitSession(char destAddr[XX_IPC_MAX_ADDR_NAME_LENGTH], + char srcAddr[XX_IPC_MAX_ADDR_NAME_LENGTH]) +{ + + /* Should not be called */ + printf("NetCommSW: Unimplemented function %s() called!\n", __func__); + return (NULL); +} + +t_Error +XX_IpcFreeSession(t_Handle h_Session) +{ + + /* Should not be called */ + printf("NetCommSW: Unimplemented function %s() called!\n", __func__); + return (E_OK); +} + +physAddress_t +XX_VirtToPhys(void *addr) +{ + vm_paddr_t paddr; + int cpu; + + cpu = PCPU_GET(cpuid); + + /* Handle NULL address */ + if (addr == NULL) + return (-1); + + /* + * No CCSR check needed on ARM64 — registers are mapped via + * bus_space, not through a global ccsrbar mapping. + */ + + /* Handle BMAN mappings */ + if (((vm_offset_t)addr >= XX_PInfo.portal_ce_va[BM_PORTAL]) && + ((vm_offset_t)addr < XX_PInfo.portal_ce_va[BM_PORTAL] + + XX_PInfo.portal_ce_size[BM_PORTAL][cpu])) + return (XX_PInfo.portal_ce_pa[BM_PORTAL][cpu] + + (vm_offset_t)addr - XX_PInfo.portal_ce_va[BM_PORTAL]); + + if (((vm_offset_t)addr >= XX_PInfo.portal_ci_va[BM_PORTAL]) && + ((vm_offset_t)addr < XX_PInfo.portal_ci_va[BM_PORTAL] + + XX_PInfo.portal_ci_size[BM_PORTAL][cpu])) + return (XX_PInfo.portal_ci_pa[BM_PORTAL][cpu] + + (vm_offset_t)addr - XX_PInfo.portal_ci_va[BM_PORTAL]); + + /* Handle QMAN mappings */ + if (((vm_offset_t)addr >= XX_PInfo.portal_ce_va[QM_PORTAL]) && + ((vm_offset_t)addr < XX_PInfo.portal_ce_va[QM_PORTAL] + + XX_PInfo.portal_ce_size[QM_PORTAL][cpu])) + return (XX_PInfo.portal_ce_pa[QM_PORTAL][cpu] + + (vm_offset_t)addr - XX_PInfo.portal_ce_va[QM_PORTAL]); + + if (((vm_offset_t)addr >= XX_PInfo.portal_ci_va[QM_PORTAL]) && + ((vm_offset_t)addr < XX_PInfo.portal_ci_va[QM_PORTAL] + + XX_PInfo.portal_ci_size[QM_PORTAL][cpu])) + return (XX_PInfo.portal_ci_pa[QM_PORTAL][cpu] + + (vm_offset_t)addr - XX_PInfo.portal_ci_va[QM_PORTAL]); + + /* ARM64 always has DMAP */ + if ((vm_offset_t)addr >= DMAP_MIN_ADDRESS && + (vm_offset_t)addr < DMAP_MAX_ADDRESS) + return (DMAP_TO_PHYS((vm_offset_t)addr)); + + paddr = pmap_kextract((vm_offset_t)addr); + + if (paddr == 0) + printf("NetCommSW: " + "Unable to translate virtual address %p!\n", addr); + + return (paddr); +} + +void * +XX_PhysToVirt(physAddress_t addr) +{ + int cpu; + + cpu = PCPU_GET(cpuid); + + /* + * No CCSR check needed on ARM64 — see XX_VirtToPhys comment. + */ + + /* Handle BMAN mappings */ + if ((addr >= XX_PInfo.portal_ce_pa[BM_PORTAL][cpu]) && + (addr < XX_PInfo.portal_ce_pa[BM_PORTAL][cpu] + + XX_PInfo.portal_ce_size[BM_PORTAL][cpu])) + return ((void *)(XX_PInfo.portal_ce_va[BM_PORTAL] + + (vm_offset_t)(addr - XX_PInfo.portal_ce_pa[BM_PORTAL][cpu]))); + + if ((addr >= XX_PInfo.portal_ci_pa[BM_PORTAL][cpu]) && + (addr < XX_PInfo.portal_ci_pa[BM_PORTAL][cpu] + + XX_PInfo.portal_ci_size[BM_PORTAL][cpu])) + return ((void *)(XX_PInfo.portal_ci_va[BM_PORTAL] + + (vm_offset_t)(addr - XX_PInfo.portal_ci_pa[BM_PORTAL][cpu]))); + + /* Handle QMAN mappings */ + if ((addr >= XX_PInfo.portal_ce_pa[QM_PORTAL][cpu]) && + (addr < XX_PInfo.portal_ce_pa[QM_PORTAL][cpu] + + XX_PInfo.portal_ce_size[QM_PORTAL][cpu])) + return ((void *)(XX_PInfo.portal_ce_va[QM_PORTAL] + + (vm_offset_t)(addr - XX_PInfo.portal_ce_pa[QM_PORTAL][cpu]))); + + if ((addr >= XX_PInfo.portal_ci_pa[QM_PORTAL][cpu]) && + (addr < XX_PInfo.portal_ci_pa[QM_PORTAL][cpu] + + XX_PInfo.portal_ci_size[QM_PORTAL][cpu])) + return ((void *)(XX_PInfo.portal_ci_va[QM_PORTAL] + + (vm_offset_t)(addr - XX_PInfo.portal_ci_pa[QM_PORTAL][cpu]))); + + /* + * Reject PA outside DRAM range (catches stale FD addresses from + * a previous boot and PA=0 which maps below dmap_phys_base). + */ + if (__predict_false(!PHYS_IN_DMAP_RANGE(addr))) + return (NULL); + return ((void *)(uintptr_t)PHYS_TO_DMAP(addr)); +} + +void +XX_PortalSetInfo(device_t dev) +{ + struct dpaa_portals_softc *sc; + const char *dev_name; + int i, type; + + dev_name = device_get_name(dev); + + if (strcmp(dev_name, "bman-portals") == 0) + type = BM_PORTAL; + else if (strcmp(dev_name, "qman-portals") == 0) + type = QM_PORTAL; + else + return; + + sc = device_get_softc(dev); + + for (i = 0; i < MAXCPU && sc->sc_dp[i].dp_ce_pa != 0; i++) { + XX_PInfo.portal_ce_pa[type][i] = sc->sc_dp[i].dp_ce_pa; + XX_PInfo.portal_ci_pa[type][i] = sc->sc_dp[i].dp_ci_pa; + XX_PInfo.portal_ce_size[type][i] = sc->sc_dp[i].dp_ce_size; + XX_PInfo.portal_ci_size[type][i] = sc->sc_dp[i].dp_ci_size; + XX_PInfo.portal_intr[type][i] = sc->sc_dp[i].dp_intr_num; + } + + XX_PInfo.portal_ce_va[type] = rman_get_bushandle(sc->sc_rres[0]); + XX_PInfo.portal_ci_va[type] = rman_get_bushandle(sc->sc_rres[1]); +} + +/* + * Stub for dead FManv3 clock-change code in fm_ncsw.c (FM_ChangeClock). + * fm_clk_down() is referenced but defined under #ifdef TODO_SOC_SUSPEND + * in fm_port.c — never compiled. g_MemacRegs is provided by memac.c. + */ +void fm_clk_down(void); +void +fm_clk_down(void) +{ + printf("NetCommSW: fm_clk_down() stub called — not implemented\n"); +}