Branch data Line data Source code
1 : : /* SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0) 2 : : * 3 : : * Copyright 2008-2012 Freescale Semiconductor, Inc. 4 : : * Copyright 2024 NXP 5 : : * 6 : : */ 7 : : 8 : : #ifndef __FSL_BMAN_H 9 : : #define __FSL_BMAN_H 10 : : 11 : : #include <rte_compat.h> 12 : : 13 : : #ifdef __cplusplus 14 : : extern "C" { 15 : : #endif 16 : : 17 : : /* This wrapper represents a bit-array for the depletion state of the 64 Bman 18 : : * buffer pools. 19 : : */ 20 : : struct bman_depletion { 21 : : u32 state[2]; 22 : : }; 23 : : 24 : : static inline void bman_depletion_init(struct bman_depletion *c) 25 : : { 26 : 0 : c->state[0] = c->state[1] = 0; 27 : 0 : } 28 : : 29 : : static inline void bman_depletion_fill(struct bman_depletion *c) 30 : : { 31 : 0 : c->state[0] = c->state[1] = ~0; 32 : : } 33 : : 34 : : /* --- Bman data structures (and associated constants) --- */ 35 : : 36 : : /* Represents s/w corenet portal mapped data structures */ 37 : : struct bm_rcr_entry; /* RCR (Release Command Ring) entries */ 38 : : struct bm_mc_command; /* MC (Management Command) command */ 39 : : struct bm_mc_result; /* MC result */ 40 : : 41 : : /* Code-reduction, define a wrapper for 48-bit buffers. In cases where a buffer 42 : : * pool id specific to this buffer is needed (BM_RCR_VERB_CMD_BPID_MULTI, 43 : : * BM_MCC_VERB_ACQUIRE), the 'bpid' field is used. 44 : : */ 45 : : struct __rte_aligned(8) bm_buffer { 46 : : union { 47 : : struct { 48 : : #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ 49 : : u8 __reserved1; 50 : : u8 bpid; 51 : : u16 hi; /* High 16-bits of 48-bit address */ 52 : : u32 lo; /* Low 32-bits of 48-bit address */ 53 : : #else 54 : : u32 lo; 55 : : u16 hi; 56 : : u8 bpid; 57 : : u8 __reserved; 58 : : #endif 59 : : }; 60 : : struct { 61 : : #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ 62 : : u64 __notaddress:16; 63 : : u64 addr:48; 64 : : #else 65 : : u64 addr:48; 66 : : u64 __notaddress:16; 67 : : #endif 68 : : }; 69 : : u64 opaque; 70 : : }; 71 : : }; 72 : : 73 : : struct __rte_packed_begin bm_hw_buf_desc { 74 : : uint8_t rsv; 75 : : uint8_t bpid; 76 : : rte_be16_t hi_addr; /* High 16-bits of 48-bit address */ 77 : : rte_be32_t lo_addr; /* Low 32-bits of 48-bit address */ 78 : : } __rte_packed_end; 79 : : 80 : : static inline u64 bm_buffer_get64(const struct bm_buffer *buf) 81 : : { 82 : : return buf->addr; 83 : : } 84 : : 85 : : static inline dma_addr_t bm_buf_addr(const struct bm_buffer *buf) 86 : : { 87 : : return (dma_addr_t)buf->addr; 88 : : } 89 : : 90 : : #define bm_buffer_set64(buf, v) \ 91 : : do { \ 92 : : struct bm_buffer *__buf931 = (buf); \ 93 : : __buf931->hi = upper_32_bits(v); \ 94 : : __buf931->lo = lower_32_bits(v); \ 95 : : } while (0) 96 : : 97 : : #define FSL_BM_BURST_MAX 8 98 : : 99 : : /* See 1.5.3.5.4: "Release Command" */ 100 : : struct __rte_packed_begin bm_rcr_entry { 101 : : union { 102 : : struct { 103 : : u8 __dont_write_directly__verb; 104 : : u8 bpid; /* used with BM_RCR_VERB_CMD_BPID_SINGLE */ 105 : : u8 __reserved1[62]; 106 : : }; 107 : : struct bm_buffer bufs[FSL_BM_BURST_MAX]; 108 : : }; 109 : : } __rte_packed_end; 110 : : #define BM_RCR_VERB_VBIT 0x80 111 : : #define BM_RCR_VERB_CMD_MASK 0x70 /* one of two values; */ 112 : : #define BM_RCR_VERB_CMD_BPID_SINGLE 0x20 113 : : #define BM_RCR_VERB_CMD_BPID_MULTI 0x30 114 : : #define BM_RCR_VERB_BUFCOUNT_MASK 0x0f /* values 1..8 */ 115 : : 116 : : /* See 1.5.3.1: "Acquire Command" */ 117 : : /* See 1.5.3.2: "Query Command" */ 118 : : struct __rte_packed_begin bm_mcc_acquire { 119 : : u8 bpid; 120 : : u8 __reserved1[62]; 121 : : } __rte_packed_end; 122 : : struct __rte_packed_begin bm_mcc_query { 123 : : u8 __reserved2[63]; 124 : : } __rte_packed_end; 125 : : struct __rte_packed_begin bm_mc_command { 126 : : u8 __dont_write_directly__verb; 127 : : union { 128 : : struct bm_mcc_acquire acquire; 129 : : struct bm_mcc_query query; 130 : : }; 131 : : } __rte_packed_end; 132 : : #define BM_MCC_VERB_VBIT 0x80 133 : : #define BM_MCC_VERB_CMD_MASK 0x70 /* where the verb contains; */ 134 : : #define BM_MCC_VERB_CMD_ACQUIRE 0x10 135 : : #define BM_MCC_VERB_CMD_QUERY 0x40 136 : : #define BM_MCC_VERB_ACQUIRE_BUFCOUNT 0x0f /* values 1..8 go here */ 137 : : 138 : : /* See 1.5.3.3: "Acquire Response" */ 139 : : /* See 1.5.3.4: "Query Response" */ 140 : : struct bm_pool_state { 141 : : u8 __reserved1[32]; 142 : : /* "availability state" and "depletion state" */ 143 : : struct { 144 : : u8 __reserved1[8]; 145 : : /* Access using bman_depletion_***() */ 146 : : struct bman_depletion state; 147 : : } as, ds; 148 : : }; 149 : : 150 : : struct __rte_packed_begin bm_mc_result { 151 : : union { 152 : : struct { 153 : : u8 verb; 154 : : u8 __reserved1[63]; 155 : : }; 156 : : union { 157 : : struct { 158 : : u8 __reserved1; 159 : : u8 bpid; 160 : : u8 __reserved2[62]; 161 : : }; 162 : : struct bm_buffer bufs[FSL_BM_BURST_MAX]; 163 : : } acquire; 164 : : struct bm_pool_state query; 165 : : }; 166 : : } __rte_packed_end; 167 : : #define BM_MCR_VERB_VBIT 0x80 168 : : #define BM_MCR_VERB_CMD_MASK BM_MCC_VERB_CMD_MASK 169 : : #define BM_MCR_VERB_CMD_ACQUIRE BM_MCC_VERB_CMD_ACQUIRE 170 : : #define BM_MCR_VERB_CMD_QUERY BM_MCC_VERB_CMD_QUERY 171 : : #define BM_MCR_VERB_CMD_ERR_INVALID 0x60 172 : : #define BM_MCR_VERB_CMD_ERR_ECC 0x70 173 : : #define BM_MCR_VERB_ACQUIRE_BUFCOUNT BM_MCC_VERB_ACQUIRE_BUFCOUNT /* 0..8 */ 174 : : 175 : : /* Portal and Buffer Pools */ 176 : : /* Represents a managed portal */ 177 : : struct bman_portal; 178 : : 179 : : /* This object type represents Bman buffer pools. */ 180 : : struct bman_pool; 181 : : 182 : : /* This struct specifies parameters for a bman_pool object. */ 183 : : struct bman_pool_params { 184 : : /* index of the buffer pool to encapsulate (0-63), ignored if 185 : : * BMAN_POOL_FLAG_DYNAMIC_BPID is set. 186 : : */ 187 : : u32 bpid; 188 : : /* bit-mask of BMAN_POOL_FLAG_*** options */ 189 : : u32 flags; 190 : : /* depletion-entry/exit thresholds, if BMAN_POOL_FLAG_THRESH is set. NB: 191 : : * this is only allowed if BMAN_POOL_FLAG_DYNAMIC_BPID is used *and* 192 : : * when run in the control plane (which controls Bman CCSR). This array 193 : : * matches the definition of bm_pool_set(). 194 : : */ 195 : : u32 thresholds[4]; 196 : : }; 197 : : 198 : : /* Flags to bman_new_pool() */ 199 : : #define BMAN_POOL_FLAG_NO_RELEASE 0x00000001 /* can't release to pool */ 200 : : #define BMAN_POOL_FLAG_ONLY_RELEASE 0x00000002 /* can only release to pool */ 201 : : #define BMAN_POOL_FLAG_DYNAMIC_BPID 0x00000008 /* (de)allocate bpid */ 202 : : #define BMAN_POOL_FLAG_THRESH 0x00000010 /* set depletion thresholds */ 203 : : 204 : : /* Flags to bman_release() */ 205 : : #define BMAN_RELEASE_FLAG_NOW 0x00000008 /* issue immediate release */ 206 : : 207 : : 208 : : /** 209 : : * bman_get_portal_index - get portal configuration index 210 : : */ 211 : : int bman_get_portal_index(void); 212 : : 213 : : /** 214 : : * bman_rcr_is_empty - Determine if portal's RCR is empty 215 : : * 216 : : * For use in situations where a cpu-affine caller needs to determine when all 217 : : * releases for the local portal have been processed by Bman but can't use the 218 : : * BMAN_RELEASE_FLAG_WAIT_SYNC flag to do this from the final bman_release(). 219 : : * The function forces tracking of RCR consumption (which normally doesn't 220 : : * happen until release processing needs to find space to put new release 221 : : * commands), and returns zero if the ring still has unprocessed entries, 222 : : * non-zero if it is empty. 223 : : */ 224 : : int bman_rcr_is_empty(void); 225 : : 226 : : /** 227 : : * bman_alloc_bpid_range - Allocate a contiguous range of BPIDs 228 : : * @result: is set by the API to the base BPID of the allocated range 229 : : * @count: the number of BPIDs required 230 : : * @align: required alignment of the allocated range 231 : : * @partial: non-zero if the API can return fewer than @count BPIDs 232 : : * 233 : : * Returns the number of buffer pools allocated, or a negative error code. If 234 : : * @partial is non zero, the allocation request may return a smaller range of 235 : : * BPs than requested (though alignment will be as requested). If @partial is 236 : : * zero, the return value will either be 'count' or negative. 237 : : */ 238 : : int bman_alloc_bpid_range(u32 *result, u32 count, u32 align, int partial); 239 : : static inline int bman_alloc_bpid(u32 *result) 240 : : { 241 : 0 : int ret = bman_alloc_bpid_range(result, 1, 0, 0); 242 : : 243 : : return (ret > 0) ? 0 : ret; 244 : : } 245 : : 246 : : /** 247 : : * bman_release_bpid_range - Release the specified range of buffer pool IDs 248 : : * @bpid: the base BPID of the range to deallocate 249 : : * @count: the number of BPIDs in the range 250 : : * 251 : : * This function can also be used to seed the allocator with ranges of BPIDs 252 : : * that it can subsequently allocate from. 253 : : */ 254 : : void bman_release_bpid_range(u32 bpid, unsigned int count); 255 : : static inline void bman_release_bpid(u32 bpid) 256 : : { 257 : 0 : bman_release_bpid_range(bpid, 1); 258 : 0 : } 259 : : 260 : : int bman_reserve_bpid_range(u32 bpid, unsigned int count); 261 : : static inline int bman_reserve_bpid(u32 bpid) 262 : : { 263 : : return bman_reserve_bpid_range(bpid, 1); 264 : : } 265 : : 266 : : void bman_seed_bpid_range(u32 bpid, unsigned int count); 267 : : 268 : : int bman_shutdown_pool(u32 bpid); 269 : : 270 : : /** 271 : : * bman_new_pool - Allocates a Buffer Pool object 272 : : * @params: parameters specifying the buffer pool ID and behaviour 273 : : * 274 : : * Creates a pool object for the given @params. A portal and the depletion 275 : : * callback field of @params are only used if the BMAN_POOL_FLAG_DEPLETION flag 276 : : * is set. NB, the fields from @params are copied into the new pool object, so 277 : : * the structure provided by the caller can be released or reused after the 278 : : * function returns. 279 : : */ 280 : : __rte_internal 281 : : struct bman_pool *bman_new_pool(const struct bman_pool_params *params); 282 : : 283 : : /** 284 : : * bman_free_pool - Deallocates a Buffer Pool object 285 : : * @pool: the pool object to release 286 : : */ 287 : : __rte_internal 288 : : void bman_free_pool(struct bman_pool *pool); 289 : : 290 : : /** 291 : : * bman_get_params - Returns a pool object's parameters. 292 : : * @pool: the pool object 293 : : * 294 : : * The returned pointer refers to state within the pool object so must not be 295 : : * modified and can no longer be read once the pool object is destroyed. 296 : : */ 297 : : __rte_internal 298 : : const struct bman_pool_params *bman_get_params(const struct bman_pool *pool); 299 : : 300 : : /** 301 : : * bman_release - Release buffer(s) to the buffer pool 302 : : * @pool: the buffer pool object to release to 303 : : * @bufs: an array of buffers to release 304 : : * @num: the number of buffers in @bufs (1-8) 305 : : * @flags: bit-mask of BMAN_RELEASE_FLAG_*** options 306 : : * 307 : : */ 308 : : __rte_internal 309 : : int bman_release(struct bman_pool *pool, const struct bm_buffer *bufs, u8 num, 310 : : u32 flags); 311 : : __rte_internal 312 : : int bman_release_fast(struct bman_pool *pool, const uint64_t *bufs, 313 : : uint8_t num); 314 : : 315 : : /** 316 : : * bman_acquire - Acquire buffer(s) from a buffer pool 317 : : * @pool: the buffer pool object to acquire from 318 : : * @bufs: array for storing the acquired buffers 319 : : * @num: the number of buffers desired (@bufs is at least this big) 320 : : * 321 : : * Issues an "Acquire" command via the portal's management command interface. 322 : : * The return value will be the number of buffers obtained from the pool, or a 323 : : * negative error code if a h/w error or pool starvation was encountered. 324 : : */ 325 : : __rte_internal 326 : : int bman_acquire(struct bman_pool *pool, struct bm_buffer *bufs, u8 num, 327 : : u32 flags); 328 : : __rte_internal 329 : : int bman_acquire_fast(struct bman_pool *pool, uint64_t *bufs, uint8_t num); 330 : : 331 : : /** 332 : : * bman_query_pools - Query all buffer pool states 333 : : * @state: storage for the queried availability and depletion states 334 : : */ 335 : : int bman_query_pools(struct bm_pool_state *state); 336 : : 337 : : /** 338 : : * bman_query_free_buffers - Query how many free buffers are in buffer pool 339 : : * @pool: the buffer pool object to query 340 : : * 341 : : * Return the number of the free buffers 342 : : */ 343 : : __rte_internal 344 : : u32 bman_query_free_buffers(struct bman_pool *pool); 345 : : 346 : : /** 347 : : * bman_update_pool_thresholds - Change the buffer pool's depletion thresholds 348 : : * @pool: the buffer pool object to which the thresholds will be set 349 : : * @thresholds: the new thresholds 350 : : */ 351 : : int bman_update_pool_thresholds(struct bman_pool *pool, const u32 *thresholds); 352 : : 353 : : /** 354 : : * bm_pool_set_hw_threshold - Change the buffer pool's thresholds 355 : : * @pool: Pool id 356 : : * @low_thresh: low threshold 357 : : * @high_thresh: high threshold 358 : : */ 359 : : int bm_pool_set_hw_threshold(u32 bpid, const u32 low_thresh, 360 : : const u32 high_thresh); 361 : : 362 : : #ifdef __cplusplus 363 : : } 364 : : #endif 365 : : 366 : : #endif /* __FSL_BMAN_H */