1 /* SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0)
3 * Copyright 2008-2012 Freescale Semiconductor, Inc.
14 /* This wrapper represents a bit-array for the depletion state of the 64 Bman
17 struct bman_depletion {
21 static inline void bman_depletion_init(struct bman_depletion *c)
23 c->state[0] = c->state[1] = 0;
26 static inline void bman_depletion_fill(struct bman_depletion *c)
28 c->state[0] = c->state[1] = ~0;
31 /* --- Bman data structures (and associated constants) --- */
33 /* Represents s/w corenet portal mapped data structures */
34 struct bm_rcr_entry; /* RCR (Release Command Ring) entries */
35 struct bm_mc_command; /* MC (Management Command) command */
36 struct bm_mc_result; /* MC result */
38 /* Code-reduction, define a wrapper for 48-bit buffers. In cases where a buffer
39 * pool id specific to this buffer is needed (BM_RCR_VERB_CMD_BPID_MULTI,
40 * BM_MCC_VERB_ACQUIRE), the 'bpid' field is used.
45 #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
48 u16 hi; /* High 16-bits of 48-bit address */
49 u32 lo; /* Low 32-bits of 48-bit address */
58 #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
68 } __attribute__((aligned(8)));
69 static inline u64 bm_buffer_get64(const struct bm_buffer *buf)
74 static inline dma_addr_t bm_buf_addr(const struct bm_buffer *buf)
76 return (dma_addr_t)buf->addr;
79 #define bm_buffer_set64(buf, v) \
81 struct bm_buffer *__buf931 = (buf); \
82 __buf931->hi = upper_32_bits(v); \
83 __buf931->lo = lower_32_bits(v); \
86 /* See 1.5.3.5.4: "Release Command" */
90 u8 __dont_write_directly__verb;
91 u8 bpid; /* used with BM_RCR_VERB_CMD_BPID_SINGLE */
94 struct bm_buffer bufs[8];
97 #define BM_RCR_VERB_VBIT 0x80
98 #define BM_RCR_VERB_CMD_MASK 0x70 /* one of two values; */
99 #define BM_RCR_VERB_CMD_BPID_SINGLE 0x20
100 #define BM_RCR_VERB_CMD_BPID_MULTI 0x30
101 #define BM_RCR_VERB_BUFCOUNT_MASK 0x0f /* values 1..8 */
103 /* See 1.5.3.1: "Acquire Command" */
104 /* See 1.5.3.2: "Query Command" */
105 struct bm_mcc_acquire {
109 struct bm_mcc_query {
112 struct bm_mc_command {
113 u8 __dont_write_directly__verb;
115 struct bm_mcc_acquire acquire;
116 struct bm_mcc_query query;
119 #define BM_MCC_VERB_VBIT 0x80
120 #define BM_MCC_VERB_CMD_MASK 0x70 /* where the verb contains; */
121 #define BM_MCC_VERB_CMD_ACQUIRE 0x10
122 #define BM_MCC_VERB_CMD_QUERY 0x40
123 #define BM_MCC_VERB_ACQUIRE_BUFCOUNT 0x0f /* values 1..8 go here */
125 /* See 1.5.3.3: "Acquire Response" */
126 /* See 1.5.3.4: "Query Response" */
127 struct bm_pool_state {
129 /* "availability state" and "depletion state" */
132 /* Access using bman_depletion_***() */
133 struct bman_depletion state;
137 struct bm_mc_result {
149 struct bm_buffer bufs[8];
151 struct bm_pool_state query;
154 #define BM_MCR_VERB_VBIT 0x80
155 #define BM_MCR_VERB_CMD_MASK BM_MCC_VERB_CMD_MASK
156 #define BM_MCR_VERB_CMD_ACQUIRE BM_MCC_VERB_CMD_ACQUIRE
157 #define BM_MCR_VERB_CMD_QUERY BM_MCC_VERB_CMD_QUERY
158 #define BM_MCR_VERB_CMD_ERR_INVALID 0x60
159 #define BM_MCR_VERB_CMD_ERR_ECC 0x70
160 #define BM_MCR_VERB_ACQUIRE_BUFCOUNT BM_MCC_VERB_ACQUIRE_BUFCOUNT /* 0..8 */
162 /* Portal and Buffer Pools */
163 /* Represents a managed portal */
166 /* This object type represents Bman buffer pools. */
169 /* This struct specifies parameters for a bman_pool object. */
170 struct bman_pool_params {
171 /* index of the buffer pool to encapsulate (0-63), ignored if
172 * BMAN_POOL_FLAG_DYNAMIC_BPID is set.
175 /* bit-mask of BMAN_POOL_FLAG_*** options */
177 /* depletion-entry/exit thresholds, if BMAN_POOL_FLAG_THRESH is set. NB:
178 * this is only allowed if BMAN_POOL_FLAG_DYNAMIC_BPID is used *and*
179 * when run in the control plane (which controls Bman CCSR). This array
180 * matches the definition of bm_pool_set().
185 /* Flags to bman_new_pool() */
186 #define BMAN_POOL_FLAG_NO_RELEASE 0x00000001 /* can't release to pool */
187 #define BMAN_POOL_FLAG_ONLY_RELEASE 0x00000002 /* can only release to pool */
188 #define BMAN_POOL_FLAG_DYNAMIC_BPID 0x00000008 /* (de)allocate bpid */
189 #define BMAN_POOL_FLAG_THRESH 0x00000010 /* set depletion thresholds */
191 /* Flags to bman_release() */
192 #define BMAN_RELEASE_FLAG_NOW 0x00000008 /* issue immediate release */
196 * bman_get_portal_index - get portal configuration index
198 int bman_get_portal_index(void);
201 * bman_rcr_is_empty - Determine if portal's RCR is empty
203 * For use in situations where a cpu-affine caller needs to determine when all
204 * releases for the local portal have been processed by Bman but can't use the
205 * BMAN_RELEASE_FLAG_WAIT_SYNC flag to do this from the final bman_release().
206 * The function forces tracking of RCR consumption (which normally doesn't
207 * happen until release processing needs to find space to put new release
208 * commands), and returns zero if the ring still has unprocessed entries,
209 * non-zero if it is empty.
211 int bman_rcr_is_empty(void);
214 * bman_alloc_bpid_range - Allocate a contiguous range of BPIDs
215 * @result: is set by the API to the base BPID of the allocated range
216 * @count: the number of BPIDs required
217 * @align: required alignment of the allocated range
218 * @partial: non-zero if the API can return fewer than @count BPIDs
220 * Returns the number of buffer pools allocated, or a negative error code. If
221 * @partial is non zero, the allocation request may return a smaller range of
222 * BPs than requested (though alignment will be as requested). If @partial is
223 * zero, the return value will either be 'count' or negative.
225 int bman_alloc_bpid_range(u32 *result, u32 count, u32 align, int partial);
226 static inline int bman_alloc_bpid(u32 *result)
228 int ret = bman_alloc_bpid_range(result, 1, 0, 0);
230 return (ret > 0) ? 0 : ret;
234 * bman_release_bpid_range - Release the specified range of buffer pool IDs
235 * @bpid: the base BPID of the range to deallocate
236 * @count: the number of BPIDs in the range
238 * This function can also be used to seed the allocator with ranges of BPIDs
239 * that it can subsequently allocate from.
241 void bman_release_bpid_range(u32 bpid, unsigned int count);
242 static inline void bman_release_bpid(u32 bpid)
244 bman_release_bpid_range(bpid, 1);
247 int bman_reserve_bpid_range(u32 bpid, unsigned int count);
248 static inline int bman_reserve_bpid(u32 bpid)
250 return bman_reserve_bpid_range(bpid, 1);
253 void bman_seed_bpid_range(u32 bpid, unsigned int count);
255 int bman_shutdown_pool(u32 bpid);
258 * bman_new_pool - Allocates a Buffer Pool object
259 * @params: parameters specifying the buffer pool ID and behaviour
261 * Creates a pool object for the given @params. A portal and the depletion
262 * callback field of @params are only used if the BMAN_POOL_FLAG_DEPLETION flag
263 * is set. NB, the fields from @params are copied into the new pool object, so
264 * the structure provided by the caller can be released or reused after the
267 struct bman_pool *bman_new_pool(const struct bman_pool_params *params);
270 * bman_free_pool - Deallocates a Buffer Pool object
271 * @pool: the pool object to release
273 void bman_free_pool(struct bman_pool *pool);
276 * bman_get_params - Returns a pool object's parameters.
277 * @pool: the pool object
279 * The returned pointer refers to state within the pool object so must not be
280 * modified and can no longer be read once the pool object is destroyed.
282 const struct bman_pool_params *bman_get_params(const struct bman_pool *pool);
285 * bman_release - Release buffer(s) to the buffer pool
286 * @pool: the buffer pool object to release to
287 * @bufs: an array of buffers to release
288 * @num: the number of buffers in @bufs (1-8)
289 * @flags: bit-mask of BMAN_RELEASE_FLAG_*** options
292 int bman_release(struct bman_pool *pool, const struct bm_buffer *bufs, u8 num,
296 * bman_acquire - Acquire buffer(s) from a buffer pool
297 * @pool: the buffer pool object to acquire from
298 * @bufs: array for storing the acquired buffers
299 * @num: the number of buffers desired (@bufs is at least this big)
301 * Issues an "Acquire" command via the portal's management command interface.
302 * The return value will be the number of buffers obtained from the pool, or a
303 * negative error code if a h/w error or pool starvation was encountered.
305 int bman_acquire(struct bman_pool *pool, struct bm_buffer *bufs, u8 num,
309 * bman_query_pools - Query all buffer pool states
310 * @state: storage for the queried availability and depletion states
312 int bman_query_pools(struct bm_pool_state *state);
315 * bman_query_free_buffers - Query how many free buffers are in buffer pool
316 * @pool: the buffer pool object to query
318 * Return the number of the free buffers
320 u32 bman_query_free_buffers(struct bman_pool *pool);
323 * bman_update_pool_thresholds - Change the buffer pool's depletion thresholds
324 * @pool: the buffer pool object to which the thresholds will be set
325 * @thresholds: the new thresholds
327 int bman_update_pool_thresholds(struct bman_pool *pool, const u32 *thresholds);
330 * bm_pool_set_hw_threshold - Change the buffer pool's thresholds
332 * @low_thresh: low threshold
333 * @high_thresh: high threshold
335 int bm_pool_set_hw_threshold(u32 bpid, const u32 low_thresh,
336 const u32 high_thresh);
342 #endif /* __FSL_BMAN_H */