2 * This file is provided under a dual BSD/GPLv2 license. When using or
3 * redistributing this file, you may do so under either license.
7 * Copyright 2008-2012 Freescale Semiconductor, Inc.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are met:
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * * Neither the name of the above-listed copyright holders nor the
17 * names of any contributors may be used to endorse or promote products
18 * derived from this software without specific prior written permission.
22 * ALTERNATIVELY, this software may be distributed under the terms of the
23 * GNU General Public License ("GPL") as published by the Free Software
24 * Foundation, either version 2 of that License or (at your option) any
27 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
28 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
31 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 * POSSIBILITY OF SUCH DAMAGE.
47 /* This wrapper represents a bit-array for the depletion state of the 64 Bman
50 struct bman_depletion {
54 static inline void bman_depletion_init(struct bman_depletion *c)
56 c->state[0] = c->state[1] = 0;
59 static inline void bman_depletion_fill(struct bman_depletion *c)
61 c->state[0] = c->state[1] = ~0;
64 /* --- Bman data structures (and associated constants) --- */
66 /* Represents s/w corenet portal mapped data structures */
67 struct bm_rcr_entry; /* RCR (Release Command Ring) entries */
68 struct bm_mc_command; /* MC (Management Command) command */
69 struct bm_mc_result; /* MC result */
71 /* Code-reduction, define a wrapper for 48-bit buffers. In cases where a buffer
72 * pool id specific to this buffer is needed (BM_RCR_VERB_CMD_BPID_MULTI,
73 * BM_MCC_VERB_ACQUIRE), the 'bpid' field is used.
78 #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
81 u16 hi; /* High 16-bits of 48-bit address */
82 u32 lo; /* Low 32-bits of 48-bit address */
91 #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
101 } __attribute__((aligned(8)));
102 static inline u64 bm_buffer_get64(const struct bm_buffer *buf)
107 static inline dma_addr_t bm_buf_addr(const struct bm_buffer *buf)
109 return (dma_addr_t)buf->addr;
112 #define bm_buffer_set64(buf, v) \
114 struct bm_buffer *__buf931 = (buf); \
115 __buf931->hi = upper_32_bits(v); \
116 __buf931->lo = lower_32_bits(v); \
119 /* See 1.5.3.5.4: "Release Command" */
120 struct bm_rcr_entry {
123 u8 __dont_write_directly__verb;
124 u8 bpid; /* used with BM_RCR_VERB_CMD_BPID_SINGLE */
127 struct bm_buffer bufs[8];
130 #define BM_RCR_VERB_VBIT 0x80
131 #define BM_RCR_VERB_CMD_MASK 0x70 /* one of two values; */
132 #define BM_RCR_VERB_CMD_BPID_SINGLE 0x20
133 #define BM_RCR_VERB_CMD_BPID_MULTI 0x30
134 #define BM_RCR_VERB_BUFCOUNT_MASK 0x0f /* values 1..8 */
136 /* See 1.5.3.1: "Acquire Command" */
137 /* See 1.5.3.2: "Query Command" */
138 struct bm_mcc_acquire {
142 struct bm_mcc_query {
145 struct bm_mc_command {
146 u8 __dont_write_directly__verb;
148 struct bm_mcc_acquire acquire;
149 struct bm_mcc_query query;
152 #define BM_MCC_VERB_VBIT 0x80
153 #define BM_MCC_VERB_CMD_MASK 0x70 /* where the verb contains; */
154 #define BM_MCC_VERB_CMD_ACQUIRE 0x10
155 #define BM_MCC_VERB_CMD_QUERY 0x40
156 #define BM_MCC_VERB_ACQUIRE_BUFCOUNT 0x0f /* values 1..8 go here */
158 /* See 1.5.3.3: "Acquire Response" */
159 /* See 1.5.3.4: "Query Response" */
160 struct bm_pool_state {
162 /* "availability state" and "depletion state" */
165 /* Access using bman_depletion_***() */
166 struct bman_depletion state;
170 struct bm_mc_result {
182 struct bm_buffer bufs[8];
184 struct bm_pool_state query;
187 #define BM_MCR_VERB_VBIT 0x80
188 #define BM_MCR_VERB_CMD_MASK BM_MCC_VERB_CMD_MASK
189 #define BM_MCR_VERB_CMD_ACQUIRE BM_MCC_VERB_CMD_ACQUIRE
190 #define BM_MCR_VERB_CMD_QUERY BM_MCC_VERB_CMD_QUERY
191 #define BM_MCR_VERB_CMD_ERR_INVALID 0x60
192 #define BM_MCR_VERB_CMD_ERR_ECC 0x70
193 #define BM_MCR_VERB_ACQUIRE_BUFCOUNT BM_MCC_VERB_ACQUIRE_BUFCOUNT /* 0..8 */
195 /* Portal and Buffer Pools */
196 /* Represents a managed portal */
199 /* This object type represents Bman buffer pools. */
202 /* This struct specifies parameters for a bman_pool object. */
203 struct bman_pool_params {
204 /* index of the buffer pool to encapsulate (0-63), ignored if
205 * BMAN_POOL_FLAG_DYNAMIC_BPID is set.
208 /* bit-mask of BMAN_POOL_FLAG_*** options */
210 /* depletion-entry/exit thresholds, if BMAN_POOL_FLAG_THRESH is set. NB:
211 * this is only allowed if BMAN_POOL_FLAG_DYNAMIC_BPID is used *and*
212 * when run in the control plane (which controls Bman CCSR). This array
213 * matches the definition of bm_pool_set().
218 /* Flags to bman_new_pool() */
219 #define BMAN_POOL_FLAG_NO_RELEASE 0x00000001 /* can't release to pool */
220 #define BMAN_POOL_FLAG_ONLY_RELEASE 0x00000002 /* can only release to pool */
221 #define BMAN_POOL_FLAG_DYNAMIC_BPID 0x00000008 /* (de)allocate bpid */
222 #define BMAN_POOL_FLAG_THRESH 0x00000010 /* set depletion thresholds */
224 /* Flags to bman_release() */
225 #define BMAN_RELEASE_FLAG_NOW 0x00000008 /* issue immediate release */
229 * bman_get_portal_index - get portal configuration index
231 int bman_get_portal_index(void);
234 * bman_rcr_is_empty - Determine if portal's RCR is empty
236 * For use in situations where a cpu-affine caller needs to determine when all
237 * releases for the local portal have been processed by Bman but can't use the
238 * BMAN_RELEASE_FLAG_WAIT_SYNC flag to do this from the final bman_release().
239 * The function forces tracking of RCR consumption (which normally doesn't
240 * happen until release processing needs to find space to put new release
241 * commands), and returns zero if the ring still has unprocessed entries,
242 * non-zero if it is empty.
244 int bman_rcr_is_empty(void);
247 * bman_alloc_bpid_range - Allocate a contiguous range of BPIDs
248 * @result: is set by the API to the base BPID of the allocated range
249 * @count: the number of BPIDs required
250 * @align: required alignment of the allocated range
251 * @partial: non-zero if the API can return fewer than @count BPIDs
253 * Returns the number of buffer pools allocated, or a negative error code. If
254 * @partial is non zero, the allocation request may return a smaller range of
255 * BPs than requested (though alignment will be as requested). If @partial is
256 * zero, the return value will either be 'count' or negative.
258 int bman_alloc_bpid_range(u32 *result, u32 count, u32 align, int partial);
259 static inline int bman_alloc_bpid(u32 *result)
261 int ret = bman_alloc_bpid_range(result, 1, 0, 0);
263 return (ret > 0) ? 0 : ret;
267 * bman_release_bpid_range - Release the specified range of buffer pool IDs
268 * @bpid: the base BPID of the range to deallocate
269 * @count: the number of BPIDs in the range
271 * This function can also be used to seed the allocator with ranges of BPIDs
272 * that it can subsequently allocate from.
274 void bman_release_bpid_range(u32 bpid, unsigned int count);
275 static inline void bman_release_bpid(u32 bpid)
277 bman_release_bpid_range(bpid, 1);
280 int bman_reserve_bpid_range(u32 bpid, unsigned int count);
281 static inline int bman_reserve_bpid(u32 bpid)
283 return bman_reserve_bpid_range(bpid, 1);
286 void bman_seed_bpid_range(u32 bpid, unsigned int count);
288 int bman_shutdown_pool(u32 bpid);
291 * bman_new_pool - Allocates a Buffer Pool object
292 * @params: parameters specifying the buffer pool ID and behaviour
294 * Creates a pool object for the given @params. A portal and the depletion
295 * callback field of @params are only used if the BMAN_POOL_FLAG_DEPLETION flag
296 * is set. NB, the fields from @params are copied into the new pool object, so
297 * the structure provided by the caller can be released or reused after the
300 struct bman_pool *bman_new_pool(const struct bman_pool_params *params);
303 * bman_free_pool - Deallocates a Buffer Pool object
304 * @pool: the pool object to release
306 void bman_free_pool(struct bman_pool *pool);
309 * bman_get_params - Returns a pool object's parameters.
310 * @pool: the pool object
312 * The returned pointer refers to state within the pool object so must not be
313 * modified and can no longer be read once the pool object is destroyed.
315 const struct bman_pool_params *bman_get_params(const struct bman_pool *pool);
318 * bman_release - Release buffer(s) to the buffer pool
319 * @pool: the buffer pool object to release to
320 * @bufs: an array of buffers to release
321 * @num: the number of buffers in @bufs (1-8)
322 * @flags: bit-mask of BMAN_RELEASE_FLAG_*** options
325 int bman_release(struct bman_pool *pool, const struct bm_buffer *bufs, u8 num,
329 * bman_acquire - Acquire buffer(s) from a buffer pool
330 * @pool: the buffer pool object to acquire from
331 * @bufs: array for storing the acquired buffers
332 * @num: the number of buffers desired (@bufs is at least this big)
334 * Issues an "Acquire" command via the portal's management command interface.
335 * The return value will be the number of buffers obtained from the pool, or a
336 * negative error code if a h/w error or pool starvation was encountered.
338 int bman_acquire(struct bman_pool *pool, struct bm_buffer *bufs, u8 num,
342 * bman_query_pools - Query all buffer pool states
343 * @state: storage for the queried availability and depletion states
345 int bman_query_pools(struct bm_pool_state *state);
348 * bman_query_free_buffers - Query how many free buffers are in buffer pool
349 * @pool: the buffer pool object to query
351 * Return the number of the free buffers
353 u32 bman_query_free_buffers(struct bman_pool *pool);
356 * bman_update_pool_thresholds - Change the buffer pool's depletion thresholds
357 * @pool: the buffer pool object to which the thresholds will be set
358 * @thresholds: the new thresholds
360 int bman_update_pool_thresholds(struct bman_pool *pool, const u32 *thresholds);
363 * bm_pool_set_hw_threshold - Change the buffer pool's thresholds
365 * @low_thresh: low threshold
366 * @high_thresh: high threshold
368 int bm_pool_set_hw_threshold(u32 bpid, const u32 low_thresh,
369 const u32 high_thresh);
375 #endif /* __FSL_BMAN_H */