xref: /freebsd/sys/contrib/ncsw/Peripherals/BM/bm.h (revision e99c4e4d6449626eda1934a2bdb80ab80621c8a6)
10aeed3e9SJustin Hibbits /******************************************************************************
20aeed3e9SJustin Hibbits 
30aeed3e9SJustin Hibbits  � 1995-2003, 2004, 2005-2011 Freescale Semiconductor, Inc.
40aeed3e9SJustin Hibbits  All rights reserved.
50aeed3e9SJustin Hibbits 
60aeed3e9SJustin Hibbits  This is proprietary source code of Freescale Semiconductor Inc.,
70aeed3e9SJustin Hibbits  and its use is subject to the NetComm Device Drivers EULA.
80aeed3e9SJustin Hibbits  The copyright notice above does not evidence any actual or intended
90aeed3e9SJustin Hibbits  publication of such source code.
100aeed3e9SJustin Hibbits 
110aeed3e9SJustin Hibbits  ALTERNATIVELY, redistribution and use in source and binary forms, with
120aeed3e9SJustin Hibbits  or without modification, are permitted provided that the following
130aeed3e9SJustin Hibbits  conditions are met:
140aeed3e9SJustin Hibbits      * Redistributions of source code must retain the above copyright
150aeed3e9SJustin Hibbits        notice, this list of conditions and the following disclaimer.
160aeed3e9SJustin Hibbits      * Redistributions in binary form must reproduce the above copyright
170aeed3e9SJustin Hibbits        notice, this list of conditions and the following disclaimer in the
180aeed3e9SJustin Hibbits        documentation and/or other materials provided with the distribution.
190aeed3e9SJustin Hibbits      * Neither the name of Freescale Semiconductor nor the
200aeed3e9SJustin Hibbits        names of its contributors may be used to endorse or promote products
210aeed3e9SJustin Hibbits        derived from this software without specific prior written permission.
220aeed3e9SJustin Hibbits 
230aeed3e9SJustin Hibbits  THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
240aeed3e9SJustin Hibbits  EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
250aeed3e9SJustin Hibbits  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
260aeed3e9SJustin Hibbits  DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
270aeed3e9SJustin Hibbits  DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
280aeed3e9SJustin Hibbits  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
290aeed3e9SJustin Hibbits  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
300aeed3e9SJustin Hibbits  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
310aeed3e9SJustin Hibbits  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
320aeed3e9SJustin Hibbits  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
330aeed3e9SJustin Hibbits  *
340aeed3e9SJustin Hibbits 
350aeed3e9SJustin Hibbits  **************************************************************************/
360aeed3e9SJustin Hibbits /******************************************************************************
370aeed3e9SJustin Hibbits  @File          bm.h
380aeed3e9SJustin Hibbits 
390aeed3e9SJustin Hibbits  @Description   BM header
400aeed3e9SJustin Hibbits *//***************************************************************************/
410aeed3e9SJustin Hibbits #ifndef __BM_H
420aeed3e9SJustin Hibbits #define __BM_H
430aeed3e9SJustin Hibbits 
44852ba100SJustin Hibbits #include "xx_common.h"
450aeed3e9SJustin Hibbits #include "bm_ext.h"
460aeed3e9SJustin Hibbits #include "mm_ext.h"
470aeed3e9SJustin Hibbits 
480aeed3e9SJustin Hibbits #include "bman_private.h"
490aeed3e9SJustin Hibbits #include "bm_ipc.h"
500aeed3e9SJustin Hibbits 
510aeed3e9SJustin Hibbits 
520aeed3e9SJustin Hibbits #define __ERR_MODULE__  MODULE_BM
530aeed3e9SJustin Hibbits 
540aeed3e9SJustin Hibbits #define BM_NUM_OF_POOLS             64
550aeed3e9SJustin Hibbits #define BM_NUM_OF_PM                8
560aeed3e9SJustin Hibbits 
570aeed3e9SJustin Hibbits /**************************************************************************//**
580aeed3e9SJustin Hibbits  @Description       Exceptions
590aeed3e9SJustin Hibbits *//***************************************************************************/
600aeed3e9SJustin Hibbits #define BM_EX_INVALID_COMMAND       0x00000010
610aeed3e9SJustin Hibbits #define BM_EX_FBPR_THRESHOLD        0x00000008
620aeed3e9SJustin Hibbits #define BM_EX_MULTI_ECC             0x00000004
630aeed3e9SJustin Hibbits #define BM_EX_SINGLE_ECC            0x00000002
640aeed3e9SJustin Hibbits #define BM_EX_POOLS_AVAIL_STATE     0x00000001
650aeed3e9SJustin Hibbits 
660aeed3e9SJustin Hibbits #define GET_EXCEPTION_FLAG(bitMask, exception)                          \
670aeed3e9SJustin Hibbits switch(exception){                                                      \
680aeed3e9SJustin Hibbits     case e_BM_EX_INVALID_COMMAND:                                       \
690aeed3e9SJustin Hibbits         bitMask = BM_EX_INVALID_COMMAND; break;                         \
700aeed3e9SJustin Hibbits     case e_BM_EX_FBPR_THRESHOLD:                                        \
710aeed3e9SJustin Hibbits         bitMask = BM_EX_FBPR_THRESHOLD; break;                          \
720aeed3e9SJustin Hibbits     case e_BM_EX_SINGLE_ECC:                                            \
730aeed3e9SJustin Hibbits         bitMask = BM_EX_SINGLE_ECC; break;                              \
740aeed3e9SJustin Hibbits     case e_BM_EX_MULTI_ECC:                                             \
750aeed3e9SJustin Hibbits         bitMask = BM_EX_MULTI_ECC; break;                               \
760aeed3e9SJustin Hibbits     default: bitMask = 0;break;                                         \
770aeed3e9SJustin Hibbits }
780aeed3e9SJustin Hibbits 
790aeed3e9SJustin Hibbits /**************************************************************************//**
800aeed3e9SJustin Hibbits  @Description       defaults
810aeed3e9SJustin Hibbits *//***************************************************************************/
820aeed3e9SJustin Hibbits /* BM defaults */
830aeed3e9SJustin Hibbits #define DEFAULT_exceptions                  (BM_EX_INVALID_COMMAND      |\
840aeed3e9SJustin Hibbits                                             BM_EX_FBPR_THRESHOLD        |\
850aeed3e9SJustin Hibbits                                             BM_EX_MULTI_ECC             |\
860aeed3e9SJustin Hibbits                                             BM_EX_SINGLE_ECC            )
870aeed3e9SJustin Hibbits 
880aeed3e9SJustin Hibbits #define DEFAULT_fbprThreshold               0
890aeed3e9SJustin Hibbits /* BM-Portal defaults */
900aeed3e9SJustin Hibbits #define DEFAULT_memAttr                     MEMORY_ATTR_CACHEABLE
910aeed3e9SJustin Hibbits 
920aeed3e9SJustin Hibbits /* BM-Pool defaults */
930aeed3e9SJustin Hibbits #define DEFAULT_dynamicBpid                 TRUE
940aeed3e9SJustin Hibbits #define DEFAULT_useDepletion                FALSE
950aeed3e9SJustin Hibbits #define DEFAULT_useStockpile                FALSE
960aeed3e9SJustin Hibbits #define DEFAULT_numOfBufsPerCmd             8
970aeed3e9SJustin Hibbits 
980aeed3e9SJustin Hibbits /**************************************************************************//**
990aeed3e9SJustin Hibbits  @Description       Memory Mapped Registers
1000aeed3e9SJustin Hibbits *//***************************************************************************/
1010aeed3e9SJustin Hibbits 
1020aeed3e9SJustin Hibbits #if defined(__MWERKS__) && !defined(__GNUC__)
1030aeed3e9SJustin Hibbits #pragma pack(push,1)
1040aeed3e9SJustin Hibbits #endif /* defined(__MWERKS__) && ... */
1050aeed3e9SJustin Hibbits #define MEM_MAP_START
1060aeed3e9SJustin Hibbits 
1070aeed3e9SJustin Hibbits typedef _Packed struct
1080aeed3e9SJustin Hibbits {
1090aeed3e9SJustin Hibbits     /* BMan Buffer Pool Configuration & Status Registers */
1100aeed3e9SJustin Hibbits     volatile uint32_t   swdet[BM_NUM_OF_POOLS];     /**< S/W Portal depletion entry threshold */
1110aeed3e9SJustin Hibbits     volatile uint32_t   hwdet[BM_NUM_OF_POOLS];     /**< H/W Portal depletion entry threshold */
1120aeed3e9SJustin Hibbits     volatile uint32_t   swdxt[BM_NUM_OF_POOLS];     /**< S/W Portal depletion exit threshold */
1130aeed3e9SJustin Hibbits     volatile uint32_t   hwdxt[BM_NUM_OF_POOLS];     /**< H/W Portal depletion exit threshold */
1140aeed3e9SJustin Hibbits     volatile uint32_t   sdcnt[BM_NUM_OF_POOLS];     /**< S/W Portal depletion count */
1150aeed3e9SJustin Hibbits     volatile uint32_t   hdcnt[BM_NUM_OF_POOLS];     /**< H/W Portal depletion count */
1160aeed3e9SJustin Hibbits     volatile uint32_t   content[BM_NUM_OF_POOLS];   /**< Snapshot of buffer count in Pool */
1170aeed3e9SJustin Hibbits     volatile uint32_t   hdptr[BM_NUM_OF_POOLS];     /**< Head Pointer for Pool's FBPR list. */
1180aeed3e9SJustin Hibbits 
1190aeed3e9SJustin Hibbits     /* Free Buffer Proxy Record (FBPR) Manager Query Registers */
1200aeed3e9SJustin Hibbits     volatile uint32_t   fbpr_fpc;                   /**< FBPR Free Pool Count */
1210aeed3e9SJustin Hibbits     volatile uint32_t   fbpr_fp_lwit;               /**< FBPR Free Pool Low Watermark Interrupt Threshold  */
1220aeed3e9SJustin Hibbits     volatile uint8_t    res1[248];                  /**< reserved */
1230aeed3e9SJustin Hibbits 
1240aeed3e9SJustin Hibbits     /* Performance Monitor (PM) Configuration Register */
1250aeed3e9SJustin Hibbits     volatile uint32_t   cmd_pm_cfg[BM_NUM_OF_PM];   /**< BMan Command Performance Monitor configuration registers. */
1260aeed3e9SJustin Hibbits     volatile uint32_t   fl_pm_cfg[BM_NUM_OF_PM];    /**< BMan Free List Performance Monitor configuration registers */
1270aeed3e9SJustin Hibbits     volatile uint8_t    res2[192];                  /**< reserved */
1280aeed3e9SJustin Hibbits 
1290aeed3e9SJustin Hibbits     /* BMan Error Capture Registers */
1300aeed3e9SJustin Hibbits     volatile uint32_t   ecsr;                       /**< BMan Error Capture Status Register */
1310aeed3e9SJustin Hibbits     volatile uint32_t   ecir;                       /**< BMan Error Capture Information Register */
1320aeed3e9SJustin Hibbits     volatile uint32_t   eadr;                       /**< BMan Error Capture Address Register */
1330aeed3e9SJustin Hibbits     volatile uint8_t    res3[4];                    /**< reserved */
1340aeed3e9SJustin Hibbits     volatile uint32_t   edata[8];                   /**< BMan ECC Error Data Register */
1350aeed3e9SJustin Hibbits     volatile uint32_t   sbet;                       /**< BMan Single Bit ECC Error Threshold Register */
1360aeed3e9SJustin Hibbits     volatile uint32_t   efcr;                       /**< BMan Error Fetch Capture Register */
1370aeed3e9SJustin Hibbits     volatile uint32_t   efar;                       /**< BMan Error Fetch Address Register */
1380aeed3e9SJustin Hibbits     volatile uint8_t    res4[68];                   /**< reserved */
1390aeed3e9SJustin Hibbits     volatile uint32_t   sbec0;                      /**< BMan Single Bit ECC Error Count 0 Register */
1400aeed3e9SJustin Hibbits     volatile uint32_t   sbec1;                      /**< BMan Single Bit ECC Error Count 1 Register */
1410aeed3e9SJustin Hibbits     volatile uint8_t    res5[368];                  /**< reserved */
1420aeed3e9SJustin Hibbits 
1430aeed3e9SJustin Hibbits     /* BMan ID/Revision Registers */
1440aeed3e9SJustin Hibbits     volatile uint32_t   ip_rev_1;                   /**< BMan IP Block Revision 1 register */
1450aeed3e9SJustin Hibbits     volatile uint32_t   ip_rev_2;                   /**< BMan IP Block Revision 2 register */
1460aeed3e9SJustin Hibbits 
1470aeed3e9SJustin Hibbits     /* CoreNet Initiator Interface Memory Window Configuration Registers */
1480aeed3e9SJustin Hibbits     volatile uint32_t   fbpr_bare;                  /**< Data Structure Extended Base Address Register */
1490aeed3e9SJustin Hibbits     volatile uint32_t   fbpr_bar;                   /**< Data Structure Base Address Register */
1500aeed3e9SJustin Hibbits     volatile uint8_t    res6[8];                    /**< reserved */
1510aeed3e9SJustin Hibbits     volatile uint32_t   fbpr_ar;                    /**< Data Structure Attributes Register */
1520aeed3e9SJustin Hibbits     volatile uint8_t    res7[240];                  /**< reserved */
1530aeed3e9SJustin Hibbits     volatile uint32_t   srcidr;                     /**< BMan Source ID Register */
1540aeed3e9SJustin Hibbits     volatile uint32_t   liodnr;                     /**< BMan Logical I/O Device Number Register */
1550aeed3e9SJustin Hibbits     volatile uint8_t    res8[244];                  /**< reserved */
1560aeed3e9SJustin Hibbits 
1570aeed3e9SJustin Hibbits     /* BMan Interrupt and Error Registers */
1580aeed3e9SJustin Hibbits     volatile uint32_t   err_isr;                    /**< BMan Error Interrupt Status Register */
1590aeed3e9SJustin Hibbits     volatile uint32_t   err_ier;                    /**< BMan Error Interrupt Enable Register */
1600aeed3e9SJustin Hibbits     volatile uint32_t   err_isdr;                   /**< BMan Error Interrupt Status Disable Register */
1610aeed3e9SJustin Hibbits     volatile uint32_t   err_iir;                    /**< BMan Error Interrupt Inhibit Register */
1620aeed3e9SJustin Hibbits     volatile uint32_t   err_ifr;                    /**< BMan Error Interrupt Force Register */
1630aeed3e9SJustin Hibbits } _PackedType t_BmRegs;
1640aeed3e9SJustin Hibbits 
1650aeed3e9SJustin Hibbits #define MEM_MAP_END
1660aeed3e9SJustin Hibbits #if defined(__MWERKS__) && !defined(__GNUC__)
1670aeed3e9SJustin Hibbits #pragma pack(pop)
1680aeed3e9SJustin Hibbits #endif /* defined(__MWERKS__) && ... */
1690aeed3e9SJustin Hibbits 
1700aeed3e9SJustin Hibbits /**************************************************************************//**
1710aeed3e9SJustin Hibbits  @Description       General defines
1720aeed3e9SJustin Hibbits *//***************************************************************************/
1730aeed3e9SJustin Hibbits #define MODULE_NAME_SIZE            30
1740aeed3e9SJustin Hibbits 
1750aeed3e9SJustin Hibbits #define FBPR_ENTRY_SIZE             64 /* 64 bytes */
1760aeed3e9SJustin Hibbits 
1770aeed3e9SJustin Hibbits /* Compilation constants */
1780aeed3e9SJustin Hibbits #define RCR_THRESH      2    /* reread h/w CI when running out of space */
1790aeed3e9SJustin Hibbits #define RCR_ITHRESH     4    /* if RCR congests, interrupt threshold */
1800aeed3e9SJustin Hibbits 
1810aeed3e9SJustin Hibbits /* Lock/unlock portals, subject to "UNLOCKED" flag */
1820aeed3e9SJustin Hibbits #define NCSW_PLOCK(p) ((t_BmPortal*)(p))->irq_flags = XX_DisableAllIntr()
1830aeed3e9SJustin Hibbits #define PUNLOCK(p) XX_RestoreAllIntr(((t_BmPortal*)(p))->irq_flags)
1840aeed3e9SJustin Hibbits 
1850aeed3e9SJustin Hibbits #define BM_RCR_RING         0
1860aeed3e9SJustin Hibbits #define BM_NUM_OF_RINGS     1
1870aeed3e9SJustin Hibbits 
1880aeed3e9SJustin Hibbits /**************************************************************************//**
1890aeed3e9SJustin Hibbits  @Description       Register defines
1900aeed3e9SJustin Hibbits *//***************************************************************************/
1910aeed3e9SJustin Hibbits 
1920aeed3e9SJustin Hibbits /* masks */
1930aeed3e9SJustin Hibbits #define REV1_MAJOR_MASK             0x0000FF00
1940aeed3e9SJustin Hibbits #define REV1_MINOR_MASK             0x000000FF
1950aeed3e9SJustin Hibbits 
1960aeed3e9SJustin Hibbits #define REV2_INTEG_MASK             0x00FF0000
1970aeed3e9SJustin Hibbits #define REV2_ERR_MASK               0x0000FF00
1980aeed3e9SJustin Hibbits #define REV2_CFG_MASK               0x000000FF
1990aeed3e9SJustin Hibbits 
2000aeed3e9SJustin Hibbits #define AR_PRIORITY                 0x40000000
2010aeed3e9SJustin Hibbits #define AR_SIZE_MASK                0x0000003f
2020aeed3e9SJustin Hibbits 
2030aeed3e9SJustin Hibbits /* shifts */
2040aeed3e9SJustin Hibbits #define REV1_MAJOR_SHIFT            8
2050aeed3e9SJustin Hibbits #define REV1_MINOR_SHIFT            0
2060aeed3e9SJustin Hibbits 
2070aeed3e9SJustin Hibbits #define REV2_INTEG_SHIFT            16
2080aeed3e9SJustin Hibbits #define REV2_ERR_SHIFT              8
2090aeed3e9SJustin Hibbits #define REV2_CFG_SHIFT              0
2100aeed3e9SJustin Hibbits 
2110aeed3e9SJustin Hibbits #define AR_SIZE_SHIFT               0
2120aeed3e9SJustin Hibbits 
2130aeed3e9SJustin Hibbits typedef uint8_t bmRingType_t;
2140aeed3e9SJustin Hibbits typedef uint8_t (t_BmUpdateCb)(struct bm_portal *p_BmPortalLow);
2150aeed3e9SJustin Hibbits typedef void    (t_BmPrefetchCb)(struct bm_portal *p_BmPortalLow);
2160aeed3e9SJustin Hibbits typedef void    (t_BmCommitCb)(struct bm_portal *p_BmPortalLow, uint8_t myverb);
2170aeed3e9SJustin Hibbits 
2180aeed3e9SJustin Hibbits typedef struct {
2190aeed3e9SJustin Hibbits     bool                        useStockpile;       /**<  */
2200aeed3e9SJustin Hibbits     bool                        dynamicBpid;        /**< boolean indicates use of dynamic Bpid */
2210aeed3e9SJustin Hibbits     bool                        useDepletion;       /**< boolean indicates use of depletion */
2220aeed3e9SJustin Hibbits     uint32_t                    depletionThresholds[MAX_DEPLETION_THRESHOLDS];      /**< depletion-entry/exit thresholds, if useThresholds is set. NB:
2230aeed3e9SJustin Hibbits                                                          this is only allowed if useThresholds is used and
2240aeed3e9SJustin Hibbits                                                          when run in the control plane (which controls Bman CCSR) */
2250aeed3e9SJustin Hibbits } t_BmPoolDriverParams;
2260aeed3e9SJustin Hibbits 
2270aeed3e9SJustin Hibbits typedef struct BmPool {
2280aeed3e9SJustin Hibbits     uint8_t                     bpid;           /**< index of the buffer pool to encapsulate (0-63) */
2290aeed3e9SJustin Hibbits     t_Handle                    h_Bm;
2300aeed3e9SJustin Hibbits     t_Handle                    h_BmPortal;
2310aeed3e9SJustin Hibbits     bool                        shadowMode;
2320aeed3e9SJustin Hibbits     uint32_t                    numOfBuffers;   /**< Number of buffers use by this pool */
2330aeed3e9SJustin Hibbits     t_BufferPoolInfo            bufferPoolInfo; /**< Data buffers pool information */
2340aeed3e9SJustin Hibbits     uint32_t                    flags;          /**< bit-mask of BMAN_POOL_FLAG_*** options */
2350aeed3e9SJustin Hibbits     t_Handle                    h_App;          /**< opaque user value passed as a parameter to 'cb' */
2360aeed3e9SJustin Hibbits     t_BmDepletionCallback       *f_Depletion;   /**< depletion-entry/exit callback, if BMAN_POOL_FLAG_DEPLETION is set */
2370aeed3e9SJustin Hibbits     uint32_t                    swDepletionCount;
2380aeed3e9SJustin Hibbits     uint32_t                    hwDepletionCount;
2390aeed3e9SJustin Hibbits     /* stockpile state - NULL unless BMAN_POOL_FLAG_STOCKPILE is set */
2400aeed3e9SJustin Hibbits     struct bm_buffer            *sp;
2410aeed3e9SJustin Hibbits     uint16_t                    spFill;
2420aeed3e9SJustin Hibbits     uint8_t                     spBufsCmd;
2430aeed3e9SJustin Hibbits     uint16_t                    spMaxBufs;
2440aeed3e9SJustin Hibbits     uint16_t                    spMinBufs;
2450aeed3e9SJustin Hibbits     bool                        noBuffCtxt;
2460aeed3e9SJustin Hibbits 
2470aeed3e9SJustin Hibbits     t_BmPoolDriverParams        *p_BmPoolDriverParams;
2480aeed3e9SJustin Hibbits } t_BmPool;
2490aeed3e9SJustin Hibbits 
2500aeed3e9SJustin Hibbits typedef struct {
2510aeed3e9SJustin Hibbits     t_BmUpdateCb            *f_BmUpdateCb;
2520aeed3e9SJustin Hibbits     t_BmPrefetchCb          *f_BmPrefetchCb;
2530aeed3e9SJustin Hibbits     t_BmCommitCb            *f_BmCommitCb;
2540aeed3e9SJustin Hibbits } t_BmPortalCallbacks;
2550aeed3e9SJustin Hibbits 
2560aeed3e9SJustin Hibbits typedef struct {
2570aeed3e9SJustin Hibbits     uint32_t                hwExtStructsMemAttr;
2580aeed3e9SJustin Hibbits     struct bman_depletion   mask;
2590aeed3e9SJustin Hibbits } t_BmPortalDriverParams;
2600aeed3e9SJustin Hibbits 
2610aeed3e9SJustin Hibbits typedef struct {
2620aeed3e9SJustin Hibbits     t_Handle                h_Bm;
2630aeed3e9SJustin Hibbits     struct bm_portal        *p_BmPortalLow;
2640aeed3e9SJustin Hibbits     t_BmPortalCallbacks     cbs[BM_NUM_OF_RINGS];
265852ba100SJustin Hibbits     uintptr_t               irq;
2660aeed3e9SJustin Hibbits     int                     cpu; /* This is used for any "core-affine" portals, ie. default portals
2670aeed3e9SJustin Hibbits                                   * associated to the corresponding cpu. -1 implies that there is no core
2680aeed3e9SJustin Hibbits                                   * affinity configured. */
2690aeed3e9SJustin Hibbits     struct bman_depletion   pools[2];   /**< 2-element array. pools[0] is mask, pools[1] is snapshot. */
2700aeed3e9SJustin Hibbits     uint32_t                flags;        /**< BMAN_PORTAL_FLAG_*** - static, caller-provided */
2710aeed3e9SJustin Hibbits     uint32_t                irq_flags;
2720aeed3e9SJustin Hibbits     int                     thresh_set;
2730aeed3e9SJustin Hibbits     uint32_t                slowpoll;
2740aeed3e9SJustin Hibbits     uint32_t                rcrProd;   /**< The wrap-around rcr_[prod|cons] counters are used to support BMAN_RELEASE_FLAG_WAIT_SYNC. */
2750aeed3e9SJustin Hibbits     uint32_t                rcrCons;
2760aeed3e9SJustin Hibbits     /**< 64-entry hash-table of pool objects that are tracking depletion
2770aeed3e9SJustin Hibbits      * entry/exit (ie. BMAN_POOL_FLAG_DEPLETION). This isn't fast-path, so
2780aeed3e9SJustin Hibbits      * we're not fussy about cache-misses and so forth - whereas the above
2790aeed3e9SJustin Hibbits      * members should all fit in one cacheline.
2800aeed3e9SJustin Hibbits      * BTW, with BM_MAX_NUM_OF_POOLS entries in the hash table and BM_MAX_NUM_OF_POOLS buffer pools to track,
2810aeed3e9SJustin Hibbits      * you'll never guess the hash-function ... */
2820aeed3e9SJustin Hibbits     t_BmPool                *depletionPoolsTable[BM_MAX_NUM_OF_POOLS];
2830aeed3e9SJustin Hibbits     t_BmPortalDriverParams  *p_BmPortalDriverParams;
2840aeed3e9SJustin Hibbits } t_BmPortal;
2850aeed3e9SJustin Hibbits 
2860aeed3e9SJustin Hibbits typedef struct {
2870aeed3e9SJustin Hibbits     uint8_t                     partBpidBase;
2880aeed3e9SJustin Hibbits     uint8_t                     partNumOfPools;
2890aeed3e9SJustin Hibbits     uint32_t                    totalNumOfBuffers;      /**< total number of buffers */
2900aeed3e9SJustin Hibbits     uint32_t                    fbprMemPartitionId;
2910aeed3e9SJustin Hibbits     uint32_t                    fbprThreshold;
2920aeed3e9SJustin Hibbits     uint16_t                    liodn;
2930aeed3e9SJustin Hibbits } t_BmDriverParams;
2940aeed3e9SJustin Hibbits 
2950aeed3e9SJustin Hibbits typedef struct {
2960aeed3e9SJustin Hibbits     uint8_t                     guestId;
2970aeed3e9SJustin Hibbits     t_Handle                    h_BpidMm;
2980aeed3e9SJustin Hibbits     t_Handle                    h_SpinLock;
2990aeed3e9SJustin Hibbits     t_Handle                    h_Portals[DPAA_MAX_NUM_OF_SW_PORTALS];
3000aeed3e9SJustin Hibbits     t_Handle                    h_Session;
3010aeed3e9SJustin Hibbits     char                        moduleName[MODULE_NAME_SIZE];
3020aeed3e9SJustin Hibbits     t_BmRegs                    *p_BmRegs;
3030aeed3e9SJustin Hibbits     void                        *p_FbprBase;
3040aeed3e9SJustin Hibbits     uint32_t                    exceptions;
3050aeed3e9SJustin Hibbits     t_BmExceptionsCallback      *f_Exception;
3060aeed3e9SJustin Hibbits     t_Handle                    h_App;
307852ba100SJustin Hibbits     uintptr_t                   errIrq;                 /**< error interrupt line; NO_IRQ if interrupts not used */
3080aeed3e9SJustin Hibbits     t_BmDriverParams            *p_BmDriverParams;
3090aeed3e9SJustin Hibbits } t_Bm;
3100aeed3e9SJustin Hibbits 
BmSetPortalHandle(t_Handle h_Bm,t_Handle h_Portal,e_DpaaSwPortal portalId)3110aeed3e9SJustin Hibbits static __inline__ void BmSetPortalHandle(t_Handle h_Bm, t_Handle h_Portal, e_DpaaSwPortal portalId)
3120aeed3e9SJustin Hibbits {
3130aeed3e9SJustin Hibbits     ASSERT_COND(!((t_Bm*)h_Bm)->h_Portals[portalId] || !h_Portal);
3140aeed3e9SJustin Hibbits     ((t_Bm*)h_Bm)->h_Portals[portalId] = h_Portal;
3150aeed3e9SJustin Hibbits }
3160aeed3e9SJustin Hibbits 
BmGetPortalHandle(t_Handle h_Bm)3170aeed3e9SJustin Hibbits static __inline__ t_Handle BmGetPortalHandle(t_Handle h_Bm)
3180aeed3e9SJustin Hibbits {
3190aeed3e9SJustin Hibbits     t_Bm *p_Bm = (t_Bm*)h_Bm;
3200aeed3e9SJustin Hibbits     ASSERT_COND(p_Bm);
3210aeed3e9SJustin Hibbits     return p_Bm->h_Portals[CORE_GetId()];
3220aeed3e9SJustin Hibbits }
3230aeed3e9SJustin Hibbits 
BmUpdate(t_BmPortal * p_BmPortal,bmRingType_t type)3240aeed3e9SJustin Hibbits static __inline__ uint8_t BmUpdate(t_BmPortal *p_BmPortal, bmRingType_t type)
3250aeed3e9SJustin Hibbits {
3260aeed3e9SJustin Hibbits     return p_BmPortal->cbs[type].f_BmUpdateCb(p_BmPortal->p_BmPortalLow);
3270aeed3e9SJustin Hibbits }
3280aeed3e9SJustin Hibbits 
BmPrefetch(t_BmPortal * p_BmPortal,bmRingType_t type)3290aeed3e9SJustin Hibbits static __inline__ void BmPrefetch(t_BmPortal *p_BmPortal, bmRingType_t type)
3300aeed3e9SJustin Hibbits {
3310aeed3e9SJustin Hibbits     if (p_BmPortal->cbs[type].f_BmPrefetchCb)
3320aeed3e9SJustin Hibbits         p_BmPortal->cbs[type].f_BmPrefetchCb(p_BmPortal->p_BmPortalLow);
3330aeed3e9SJustin Hibbits }
3340aeed3e9SJustin Hibbits 
BmCommit(t_BmPortal * p_BmPortal,bmRingType_t type,uint8_t myverb)3350aeed3e9SJustin Hibbits static __inline__ void BmCommit(t_BmPortal *p_BmPortal, bmRingType_t type, uint8_t myverb)
3360aeed3e9SJustin Hibbits {
3370aeed3e9SJustin Hibbits     p_BmPortal->cbs[type].f_BmCommitCb(p_BmPortal->p_BmPortalLow, myverb);
3380aeed3e9SJustin Hibbits }
3390aeed3e9SJustin Hibbits 
BmBpidGet(t_Bm * p_Bm,bool force,uint32_t base)3400aeed3e9SJustin Hibbits static __inline__ uint32_t BmBpidGet(t_Bm *p_Bm, bool force, uint32_t base)
3410aeed3e9SJustin Hibbits {
3420aeed3e9SJustin Hibbits     uint64_t ans, size = 1;
343852ba100SJustin Hibbits     uint64_t alignment = 1;
3440aeed3e9SJustin Hibbits 
3450aeed3e9SJustin Hibbits     if (force)
3460aeed3e9SJustin Hibbits     {
3470aeed3e9SJustin Hibbits         if (MM_InRange(p_Bm->h_BpidMm, (uint64_t)base))
3480aeed3e9SJustin Hibbits         {
3490aeed3e9SJustin Hibbits             ans = MM_GetForce(p_Bm->h_BpidMm,
3500aeed3e9SJustin Hibbits                               base,
351852ba100SJustin Hibbits                               size,
3520aeed3e9SJustin Hibbits                               "BM BPID MEM");
3530aeed3e9SJustin Hibbits             ans = base;
3540aeed3e9SJustin Hibbits         }
3550aeed3e9SJustin Hibbits         else if (p_Bm->h_Session)
3560aeed3e9SJustin Hibbits         {
3570aeed3e9SJustin Hibbits             t_BmIpcMsg              msg;
3580aeed3e9SJustin Hibbits             t_BmIpcReply            reply;
3590aeed3e9SJustin Hibbits             uint32_t                replyLength;
3600aeed3e9SJustin Hibbits             t_BmIpcBpidParams       ipcBpid;
3610aeed3e9SJustin Hibbits             t_Error                 errCode = E_OK;
3620aeed3e9SJustin Hibbits 
3630aeed3e9SJustin Hibbits             memset(&msg, 0, sizeof(t_BmIpcMsg));
3640aeed3e9SJustin Hibbits             memset(&reply, 0, sizeof(t_BmIpcReply));
3650aeed3e9SJustin Hibbits             ipcBpid.bpid        = (uint8_t)base;
3660aeed3e9SJustin Hibbits             msg.msgId           = BM_FORCE_BPID;
3670aeed3e9SJustin Hibbits             memcpy(msg.msgBody, &ipcBpid, sizeof(t_BmIpcBpidParams));
3680aeed3e9SJustin Hibbits             replyLength = sizeof(uint32_t) + sizeof(uint32_t);
3690aeed3e9SJustin Hibbits             if ((errCode = XX_IpcSendMessage(p_Bm->h_Session,
3700aeed3e9SJustin Hibbits                                              (uint8_t*)&msg,
3710aeed3e9SJustin Hibbits                                              sizeof(msg.msgId) + sizeof(t_BmIpcBpidParams),
3720aeed3e9SJustin Hibbits                                              (uint8_t*)&reply,
3730aeed3e9SJustin Hibbits                                              &replyLength,
3740aeed3e9SJustin Hibbits                                              NULL,
3750aeed3e9SJustin Hibbits                                              NULL)) != E_OK)
3760aeed3e9SJustin Hibbits             {
3770aeed3e9SJustin Hibbits                 REPORT_ERROR(MAJOR, errCode, NO_MSG);
3780aeed3e9SJustin Hibbits                 return (uint32_t)ILLEGAL_BASE;
3790aeed3e9SJustin Hibbits             }
3800aeed3e9SJustin Hibbits             if (replyLength != (sizeof(uint32_t) + sizeof(uint32_t)))
3810aeed3e9SJustin Hibbits             {
3820aeed3e9SJustin Hibbits                 REPORT_ERROR(MAJOR, E_INVALID_VALUE, ("IPC reply length mismatch"));
3830aeed3e9SJustin Hibbits                 return (uint32_t)ILLEGAL_BASE;
3840aeed3e9SJustin Hibbits             }
3850aeed3e9SJustin Hibbits             memcpy((uint8_t*)&ans, reply.replyBody, sizeof(uint32_t));
3860aeed3e9SJustin Hibbits         }
3870aeed3e9SJustin Hibbits         else
3880aeed3e9SJustin Hibbits         {
3890aeed3e9SJustin Hibbits             DBG(WARNING, ("No Ipc - can't validate bpid."));
3900aeed3e9SJustin Hibbits             ans = base;
3910aeed3e9SJustin Hibbits         }
3920aeed3e9SJustin Hibbits     }
3930aeed3e9SJustin Hibbits     else
3940aeed3e9SJustin Hibbits         ans = MM_Get(p_Bm->h_BpidMm,
3950aeed3e9SJustin Hibbits                      size,
3960aeed3e9SJustin Hibbits                      alignment,
3970aeed3e9SJustin Hibbits                      "BM BPID MEM");
398*e99c4e4dSBrandon Bergren     KASSERT(ans < UINT32_MAX, ("Oops, %jx > UINT32_MAX!\n", (uintmax_t)ans));
3990aeed3e9SJustin Hibbits     return (uint32_t)ans;
4000aeed3e9SJustin Hibbits }
4010aeed3e9SJustin Hibbits 
BmBpidPut(t_Bm * p_Bm,uint32_t base)4020aeed3e9SJustin Hibbits static __inline__ t_Error BmBpidPut(t_Bm *p_Bm, uint32_t base)
4030aeed3e9SJustin Hibbits {
4040aeed3e9SJustin Hibbits     if (MM_InRange(p_Bm->h_BpidMm, (uint64_t)base))
4050aeed3e9SJustin Hibbits     {
4060aeed3e9SJustin Hibbits         if (MM_Put(p_Bm->h_BpidMm, (uint64_t)base) != base)
4070aeed3e9SJustin Hibbits             return E_OK;
4080aeed3e9SJustin Hibbits         else
4090aeed3e9SJustin Hibbits             return ERROR_CODE(E_NOT_FOUND);
4100aeed3e9SJustin Hibbits     }
4110aeed3e9SJustin Hibbits     else if (p_Bm->h_Session)
4120aeed3e9SJustin Hibbits     {
4130aeed3e9SJustin Hibbits         t_BmIpcMsg              msg;
4140aeed3e9SJustin Hibbits         t_BmIpcBpidParams       ipcBpid;
4150aeed3e9SJustin Hibbits         t_Error                 errCode = E_OK;
4160aeed3e9SJustin Hibbits 
4170aeed3e9SJustin Hibbits         memset(&msg, 0, sizeof(t_BmIpcMsg));
4180aeed3e9SJustin Hibbits         ipcBpid.bpid        = (uint8_t)base;
4190aeed3e9SJustin Hibbits         msg.msgId           = BM_PUT_BPID;
4200aeed3e9SJustin Hibbits         memcpy(msg.msgBody, &ipcBpid, sizeof(t_BmIpcBpidParams));
4210aeed3e9SJustin Hibbits         if ((errCode = XX_IpcSendMessage(p_Bm->h_Session,
4220aeed3e9SJustin Hibbits                                          (uint8_t*)&msg,
4230aeed3e9SJustin Hibbits                                          sizeof(msg.msgId) + sizeof(t_BmIpcBpidParams),
4240aeed3e9SJustin Hibbits                                          NULL,
4250aeed3e9SJustin Hibbits                                          NULL,
4260aeed3e9SJustin Hibbits                                          NULL,
4270aeed3e9SJustin Hibbits                                          NULL)) != E_OK)
4280aeed3e9SJustin Hibbits             RETURN_ERROR(MAJOR, errCode, NO_MSG);
4290aeed3e9SJustin Hibbits     }
4300aeed3e9SJustin Hibbits     else
4310aeed3e9SJustin Hibbits         DBG(WARNING, ("No Ipc - can't validate bpid."));
4320aeed3e9SJustin Hibbits     return E_OK;
4330aeed3e9SJustin Hibbits }
4340aeed3e9SJustin Hibbits 
4350aeed3e9SJustin Hibbits /****************************************/
4360aeed3e9SJustin Hibbits /*       Inter-Module functions        */
4370aeed3e9SJustin Hibbits /****************************************/
4380aeed3e9SJustin Hibbits typedef enum e_BmInterModuleCounters {
4390aeed3e9SJustin Hibbits     e_BM_IM_COUNTERS_FBPR = 0,
4400aeed3e9SJustin Hibbits     e_BM_IM_COUNTERS_POOL_CONTENT,
4410aeed3e9SJustin Hibbits     e_BM_IM_COUNTERS_POOL_SW_DEPLETION,
4420aeed3e9SJustin Hibbits     e_BM_IM_COUNTERS_POOL_HW_DEPLETION
4430aeed3e9SJustin Hibbits } e_BmInterModuleCounters;
4440aeed3e9SJustin Hibbits 
4450aeed3e9SJustin Hibbits 
4460aeed3e9SJustin Hibbits t_Error BmSetPoolThresholds(t_Handle h_Bm, uint8_t bpid, const uint32_t *thresholds);
4470aeed3e9SJustin Hibbits t_Error BmUnSetPoolThresholds(t_Handle h_Bm, uint8_t bpid);
4480aeed3e9SJustin Hibbits uint8_t BmPortalAcquire(t_Handle h_BmPortal, uint8_t bpid, struct bm_buffer *bufs, uint8_t num);
4490aeed3e9SJustin Hibbits t_Error BmPortalRelease(t_Handle h_BmPortal, uint8_t bpid, struct bm_buffer *bufs, uint8_t num, uint32_t flags);
4500aeed3e9SJustin Hibbits t_Error BmPortalQuery(t_Handle h_BmPortal, struct bman_depletion *p_Pools, bool depletion);
4510aeed3e9SJustin Hibbits uint32_t BmGetCounter(t_Handle h_Bm, e_BmInterModuleCounters counter, uint8_t bpid);
4520aeed3e9SJustin Hibbits t_Error BmGetRevision(t_Handle h_Bm, t_BmRevisionInfo *p_BmRevisionInfo);
4530aeed3e9SJustin Hibbits 
4540aeed3e9SJustin Hibbits 
4550aeed3e9SJustin Hibbits #endif /* __BM_H */
456