Path: blob/main/sys/contrib/ncsw/Peripherals/BM/fsl_bman.h
48375 views
/******************************************************************************12� 1995-2003, 2004, 2005-2011 Freescale Semiconductor, Inc.3All rights reserved.45This is proprietary source code of Freescale Semiconductor Inc.,6and its use is subject to the NetComm Device Drivers EULA.7The copyright notice above does not evidence any actual or intended8publication of such source code.910ALTERNATIVELY, redistribution and use in source and binary forms, with11or without modification, are permitted provided that the following12conditions are met:13* Redistributions of source code must retain the above copyright14notice, this list of conditions and the following disclaimer.15* Redistributions in binary form must reproduce the above copyright16notice, this list of conditions and the following disclaimer in the17documentation and/or other materials provided with the distribution.18* Neither the name of Freescale Semiconductor nor the19names of its contributors may be used to endorse or promote products20derived from this software without specific prior written permission.2122THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY23EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED24WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE25DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY26DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES27(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;28LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND29ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT30(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS31SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.32*3334**************************************************************************/35/******************************************************************************36@File fsl_bman.h3738@Description BM header39*//***************************************************************************/40#ifndef __FSL_BMAN_H41#define __FSL_BMAN_H4243#include "std_ext.h"444546/*************************************************/47/* BMan s/w corenet portal, low-level i/face */48/*************************************************/49typedef enum {50e_BmPortalPCI = 0, /* PI index, cache-inhibited */51e_BmPortalPCE, /* PI index, cache-enabled */52e_BmPortalPVB /* valid-bit */53} e_BmPortalProduceMode;5455typedef enum {56e_BmPortalRcrCCI = 0, /* CI index, cache-inhibited */57e_BmPortalRcrCCE /* CI index, cache-enabled */58} e_BmPortalRcrConsumeMode;5960/* Portal constants */61#define BM_RCR_SIZE 86263/* Hardware constants */64enum bm_isr_reg {65bm_isr_status = 0,66bm_isr_enable = 1,67bm_isr_disable = 2,68bm_isr_inhibit = 369};7071/* Represents s/w corenet portal mapped data structures */72struct bm_rcr_entry; /* RCR (Release Command Ring) entries */73struct bm_mc_command; /* MC (Management Command) command */74struct bm_mc_result; /* MC result */7576/* This type represents a s/w corenet portal space, and is used for creating the77* portal objects within it (RCR, etc) */78struct bm_portal;7980/* This wrapper represents a bit-array for the depletion state of the 64 Bman81* buffer pools. */82struct bman_depletion {83uint32_t __state[2];84};85#define __bmdep_word(x) ((x) >> 5)86#define __bmdep_shift(x) ((x) & 0x1f)87#define __bmdep_bit(x) (0x80000000 >> __bmdep_shift(x))88static __inline__ void bman_depletion_init(struct bman_depletion *c)89{90c->__state[0] = c->__state[1] = 0;91}92static __inline__ void bman_depletion_fill(struct bman_depletion *c)93{94c->__state[0] = c->__state[1] = (uint32_t)~0;95}96static __inline__ int bman_depletion_get(const struct bman_depletion *c, uint8_t bpid)97{98return (int)(c->__state[__bmdep_word(bpid)] & __bmdep_bit(bpid));99}100static __inline__ void bman_depletion_set(struct bman_depletion *c, uint8_t bpid)101{102c->__state[__bmdep_word(bpid)] |= __bmdep_bit(bpid);103}104static __inline__ void bman_depletion_unset(struct bman_depletion *c, uint8_t bpid)105{106c->__state[__bmdep_word(bpid)] &= ~__bmdep_bit(bpid);107}108109/* ------------------------------ */110/* --- Portal enumeration API --- */111112/* ------------------------------ */113/* --- Buffer pool allocation --- */114#define BM_POOL_THRESH_SW_ENTER 0115#define BM_POOL_THRESH_SW_EXIT 1116#define BM_POOL_THRESH_HW_ENTER 2117#define BM_POOL_THRESH_HW_EXIT 3118119/* --------------- */120/* --- RCR API --- */121122/* Create/destroy */123t_Error bm_rcr_init(struct bm_portal *portal,124e_BmPortalProduceMode pmode,125e_BmPortalRcrConsumeMode cmode);126void bm_rcr_finish(struct bm_portal *portal);127128/* Start/abort RCR entry */129struct bm_rcr_entry *bm_rcr_start(struct bm_portal *portal);130void bm_rcr_abort(struct bm_portal *portal);131132/* For PI modes only. This presumes a started but uncommitted RCR entry. If133* there's no more room in the RCR, this function returns NULL. Otherwise it134* returns the next RCR entry and increments an internal PI counter without135* flushing it to h/w. */136struct bm_rcr_entry *bm_rcr_pend_and_next(struct bm_portal *portal, uint8_t myverb);137138/* Commit RCR entries, including pending ones (aka "write PI") */139void bm_rcr_pci_commit(struct bm_portal *portal, uint8_t myverb);140void bm_rcr_pce_prefetch(struct bm_portal *portal);141void bm_rcr_pce_commit(struct bm_portal *portal, uint8_t myverb);142void bm_rcr_pvb_commit(struct bm_portal *portal, uint8_t myverb);143144/* Track h/w consumption. Returns non-zero if h/w had consumed previously145* unconsumed RCR entries. */146uint8_t bm_rcr_cci_update(struct bm_portal *portal);147void bm_rcr_cce_prefetch(struct bm_portal *portal);148uint8_t bm_rcr_cce_update(struct bm_portal *portal);149/* Returns the number of available RCR entries */150uint8_t bm_rcr_get_avail(struct bm_portal *portal);151/* Returns the number of unconsumed RCR entries */152uint8_t bm_rcr_get_fill(struct bm_portal *portal);153154/* Read/write the RCR interrupt threshold */155uint8_t bm_rcr_get_ithresh(struct bm_portal *portal);156void bm_rcr_set_ithresh(struct bm_portal *portal, uint8_t ithresh);157158159/* ------------------------------ */160/* --- Management command API --- */161162/* Create/destroy */163t_Error bm_mc_init(struct bm_portal *portal);164void bm_mc_finish(struct bm_portal *portal);165166/* Start/abort mgmt command */167struct bm_mc_command *bm_mc_start(struct bm_portal *portal);168void bm_mc_abort(struct bm_portal *portal);169170/* Writes 'verb' with appropriate 'vbit'. Invalidates and pre-fetches the171* response. */172void bm_mc_commit(struct bm_portal *portal, uint8_t myverb);173174/* Poll for result. If NULL, invalidates and prefetches for the next call. */175struct bm_mc_result *bm_mc_result(struct bm_portal *portal);176177178/* ------------------------------------- */179/* --- Portal interrupt register API --- */180181/* For a quick explanation of the Bman interrupt model, see the comments in the182* equivalent section of the qman_portal.h header.183*/184185/* Create/destroy */186t_Error bm_isr_init(struct bm_portal *portal);187void bm_isr_finish(struct bm_portal *portal);188189/* BSCN masking is a per-portal configuration */190void bm_isr_bscn_mask(struct bm_portal *portal, uint8_t bpid, int enable);191192/* Used by all portal interrupt registers except 'inhibit' */193#define BM_PIRQ_RCRI 0x00000002 /* RCR Ring (below threshold) */194#define BM_PIRQ_BSCN 0x00000001 /* Buffer depletion State Change */195196/* These are bm_<reg>_<verb>(). So for example, bm_disable_write() means "write197* the disable register" rather than "disable the ability to write". */198#define bm_isr_status_read(bm) __bm_isr_read(bm, bm_isr_status)199#define bm_isr_status_clear(bm, m) __bm_isr_write(bm, bm_isr_status, m)200#define bm_isr_enable_read(bm) __bm_isr_read(bm, bm_isr_enable)201#define bm_isr_enable_write(bm, v) __bm_isr_write(bm, bm_isr_enable, v)202#define bm_isr_disable_read(bm) __bm_isr_read(bm, bm_isr_disable)203#define bm_isr_disable_write(bm, v) __bm_isr_write(bm, bm_isr_disable, v)204#define bm_isr_inhibit(bm) __bm_isr_write(bm, bm_isr_inhibit, 1)205#define bm_isr_uninhibit(bm) __bm_isr_write(bm, bm_isr_inhibit, 0)206207/* Don't use these, use the wrappers above*/208uint32_t __bm_isr_read(struct bm_portal *portal, enum bm_isr_reg n);209void __bm_isr_write(struct bm_portal *portal, enum bm_isr_reg n, uint32_t val);210211/* ------------------------------------------------------- */212/* --- Bman data structures (and associated constants) --- */213/* Code-reduction, define a wrapper for 48-bit buffers. In cases where a buffer214* pool id specific to this buffer is needed (BM_RCR_VERB_CMD_BPID_MULTI,215* BM_MCC_VERB_ACQUIRE), the 'bpid' field is used. */216217#define BM_RCR_VERB_VBIT 0x80218#define BM_RCR_VERB_CMD_MASK 0x70 /* one of two values; */219#define BM_RCR_VERB_CMD_BPID_SINGLE 0x20220#define BM_RCR_VERB_CMD_BPID_MULTI 0x30221#define BM_RCR_VERB_BUFCOUNT_MASK 0x0f /* values 1..8 */222223#define BM_MCC_VERB_VBIT 0x80224#define BM_MCC_VERB_CMD_MASK 0x70 /* where the verb contains; */225#define BM_MCC_VERB_CMD_ACQUIRE 0x10226#define BM_MCC_VERB_CMD_QUERY 0x40227#define BM_MCC_VERB_ACQUIRE_BUFCOUNT 0x0f /* values 1..8 go here */228229230#if defined(__MWERKS__) && !defined(__GNUC__)231#pragma pack(push,1)232#endif /* defined(__MWERKS__) && ... */233#define MEM_MAP_START234235_Packed struct bm_buffer {236volatile uint8_t reserved1;237volatile uint8_t bpid;238volatile uint16_t hi; /* High 16-bits of 48-bit address */239volatile uint32_t lo; /* Low 32-bits of 48-bit address */240} _PackedType;241242/* See 1.5.3.5.4: "Release Command" */243_Packed struct bm_rcr_entry {244_Packed union {245_Packed struct {246volatile uint8_t __dont_write_directly__verb;247volatile uint8_t bpid; /* used with BM_RCR_VERB_CMD_BPID_SINGLE */248volatile uint8_t reserved1[62];249} _PackedType;250volatile struct bm_buffer bufs[8];251} _PackedType;252} _PackedType;253254/* See 1.5.3.1: "Acquire Command" */255/* See 1.5.3.2: "Query Command" */256_Packed struct bm_mc_command {257volatile uint8_t __dont_write_directly__verb;258_Packed union {259_Packed struct bm_mcc_acquire {260volatile uint8_t bpid;261volatile uint8_t reserved1[62];262} _PackedType acquire;263_Packed struct bm_mcc_query {264volatile uint8_t reserved1[63];265} _PackedType query;266} _PackedType;267} _PackedType;268269/* See 1.5.3.3: "Acquire Reponse" */270/* See 1.5.3.4: "Query Reponse" */271_Packed struct bm_mc_result {272_Packed union {273_Packed struct {274volatile uint8_t verb;275volatile uint8_t reserved1[63];276} _PackedType;277_Packed union {278_Packed struct {279volatile uint8_t reserved1;280volatile uint8_t bpid;281volatile uint8_t reserved2[62];282} _PackedType;283volatile struct bm_buffer bufs[8];284} _PackedType acquire;285_Packed struct {286volatile uint8_t reserved1[32];287/* "availability state" and "depletion state" */288_Packed struct {289volatile uint8_t reserved1[8];290/* Access using bman_depletion_***() */291volatile struct bman_depletion state;292} _PackedType as, ds;293} _PackedType query;294} _PackedType;295} _PackedType;296297#define MEM_MAP_END298#if defined(__MWERKS__) && !defined(__GNUC__)299#pragma pack(pop)300#endif /* defined(__MWERKS__) && ... */301302303#define BM_MCR_VERB_VBIT 0x80304#define BM_MCR_VERB_CMD_MASK BM_MCC_VERB_CMD_MASK305#define BM_MCR_VERB_CMD_ACQUIRE BM_MCC_VERB_CMD_ACQUIRE306#define BM_MCR_VERB_CMD_QUERY BM_MCC_VERB_CMD_QUERY307#define BM_MCR_VERB_CMD_ERR_INVALID 0x60308#define BM_MCR_VERB_CMD_ERR_ECC 0x70309#define BM_MCR_VERB_ACQUIRE_BUFCOUNT BM_MCC_VERB_ACQUIRE_BUFCOUNT /* 0..8 */310/* Determine the "availability state" of pool 'p' from a query result 'r' */311#define BM_MCR_QUERY_AVAILABILITY(r,p) bman_depletion_get(&r->query.as.state,p)312/* Determine the "depletion state" of pool 'p' from a query result 'r' */313#define BM_MCR_QUERY_DEPLETION(r,p) bman_depletion_get(&r->query.ds.state,p)314315316/* Portal and Buffer Pools */317/* ----------------------- */318319/* Flags to bman_create_portal() */320#define BMAN_PORTAL_FLAG_IRQ 0x00000001 /* use interrupt handler */321#define BMAN_PORTAL_FLAG_IRQ_FAST 0x00000002 /* ... for fast-path too! */322#define BMAN_PORTAL_FLAG_COMPACT 0x00000004 /* use compaction algorithm */323#define BMAN_PORTAL_FLAG_RECOVER 0x00000008 /* recovery mode */324#define BMAN_PORTAL_FLAG_WAIT 0x00000010 /* wait if RCR is full */325#define BMAN_PORTAL_FLAG_WAIT_INT 0x00000020 /* if wait, interruptible? */326#define BMAN_PORTAL_FLAG_CACHE 0x00000400 /* use cache-able area for rings */327328/* Flags to bman_new_pool() */329#define BMAN_POOL_FLAG_NO_RELEASE 0x00000001 /* can't release to pool */330#define BMAN_POOL_FLAG_ONLY_RELEASE 0x00000002 /* can only release to pool */331#define BMAN_POOL_FLAG_DEPLETION 0x00000004 /* track depletion entry/exit */332#define BMAN_POOL_FLAG_DYNAMIC_BPID 0x00000008 /* (de)allocate bpid */333#define BMAN_POOL_FLAG_THRESH 0x00000010 /* set depletion thresholds */334#define BMAN_POOL_FLAG_STOCKPILE 0x00000020 /* stockpile to reduce hw ops */335336/* Flags to bman_release() */337#define BMAN_RELEASE_FLAG_WAIT 0x00000001 /* wait if RCR is full */338#define BMAN_RELEASE_FLAG_WAIT_INT 0x00000002 /* if we wait, interruptible? */339#define BMAN_RELEASE_FLAG_WAIT_SYNC 0x00000004 /* if wait, until consumed? */340#define BMAN_RELEASE_FLAG_NOW 0x00000008 /* issue immediate release */341342/* Flags to bman_acquire() */343#define BMAN_ACQUIRE_FLAG_STOCKPILE 0x00000001 /* no hw op, stockpile only */344345346#endif /* __FSL_BMAN_H */347348349