xref: /linux/include/soc/fsl/bman.h (revision 853dc104e6a43cba9a7a87542bc6d8e3b74f0bc9)
11f9c0a77SClaudiu Manoil /* Copyright 2008 - 2016 Freescale Semiconductor, Inc.
21f9c0a77SClaudiu Manoil  *
31f9c0a77SClaudiu Manoil  * Redistribution and use in source and binary forms, with or without
41f9c0a77SClaudiu Manoil  * modification, are permitted provided that the following conditions are met:
51f9c0a77SClaudiu Manoil  *     * Redistributions of source code must retain the above copyright
61f9c0a77SClaudiu Manoil  *	 notice, this list of conditions and the following disclaimer.
71f9c0a77SClaudiu Manoil  *     * Redistributions in binary form must reproduce the above copyright
81f9c0a77SClaudiu Manoil  *	 notice, this list of conditions and the following disclaimer in the
91f9c0a77SClaudiu Manoil  *	 documentation and/or other materials provided with the distribution.
101f9c0a77SClaudiu Manoil  *     * Neither the name of Freescale Semiconductor nor the
111f9c0a77SClaudiu Manoil  *	 names of its contributors may be used to endorse or promote products
121f9c0a77SClaudiu Manoil  *	 derived from this software without specific prior written permission.
131f9c0a77SClaudiu Manoil  *
141f9c0a77SClaudiu Manoil  * ALTERNATIVELY, this software may be distributed under the terms of the
151f9c0a77SClaudiu Manoil  * GNU General Public License ("GPL") as published by the Free Software
161f9c0a77SClaudiu Manoil  * Foundation, either version 2 of that License or (at your option) any
171f9c0a77SClaudiu Manoil  * later version.
181f9c0a77SClaudiu Manoil  *
191f9c0a77SClaudiu Manoil  * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
201f9c0a77SClaudiu Manoil  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
211f9c0a77SClaudiu Manoil  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
221f9c0a77SClaudiu Manoil  * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
231f9c0a77SClaudiu Manoil  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
241f9c0a77SClaudiu Manoil  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
251f9c0a77SClaudiu Manoil  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
261f9c0a77SClaudiu Manoil  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
271f9c0a77SClaudiu Manoil  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
281f9c0a77SClaudiu Manoil  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
291f9c0a77SClaudiu Manoil  */
301f9c0a77SClaudiu Manoil 
311f9c0a77SClaudiu Manoil #ifndef __FSL_BMAN_H
321f9c0a77SClaudiu Manoil #define __FSL_BMAN_H
331f9c0a77SClaudiu Manoil 
341f9c0a77SClaudiu Manoil /* wrapper for 48-bit buffers */
351f9c0a77SClaudiu Manoil struct bm_buffer {
361f9c0a77SClaudiu Manoil 	union {
371f9c0a77SClaudiu Manoil 		struct {
381f9c0a77SClaudiu Manoil 			__be16 bpid; /* hi 8-bits reserved */
391f9c0a77SClaudiu Manoil 			__be16 hi; /* High 16-bits of 48-bit address */
401f9c0a77SClaudiu Manoil 			__be32 lo; /* Low 32-bits of 48-bit address */
411f9c0a77SClaudiu Manoil 		};
421f9c0a77SClaudiu Manoil 		__be64 data;
431f9c0a77SClaudiu Manoil 	};
441f9c0a77SClaudiu Manoil } __aligned(8);
451f9c0a77SClaudiu Manoil /*
461f9c0a77SClaudiu Manoil  * Restore the 48 bit address previously stored in BMan
471f9c0a77SClaudiu Manoil  * hardware pools as a dma_addr_t
481f9c0a77SClaudiu Manoil  */
491f9c0a77SClaudiu Manoil static inline dma_addr_t bm_buf_addr(const struct bm_buffer *buf)
501f9c0a77SClaudiu Manoil {
511f9c0a77SClaudiu Manoil 	return be64_to_cpu(buf->data) & 0xffffffffffffLLU;
521f9c0a77SClaudiu Manoil }
531f9c0a77SClaudiu Manoil 
541f9c0a77SClaudiu Manoil static inline u64 bm_buffer_get64(const struct bm_buffer *buf)
551f9c0a77SClaudiu Manoil {
561f9c0a77SClaudiu Manoil 	return be64_to_cpu(buf->data) & 0xffffffffffffLLU;
571f9c0a77SClaudiu Manoil }
581f9c0a77SClaudiu Manoil 
591f9c0a77SClaudiu Manoil static inline void bm_buffer_set64(struct bm_buffer *buf, u64 addr)
601f9c0a77SClaudiu Manoil {
611f9c0a77SClaudiu Manoil 	buf->hi = cpu_to_be16(upper_32_bits(addr));
621f9c0a77SClaudiu Manoil 	buf->lo = cpu_to_be32(lower_32_bits(addr));
631f9c0a77SClaudiu Manoil }
641f9c0a77SClaudiu Manoil 
651f9c0a77SClaudiu Manoil static inline u8 bm_buffer_get_bpid(const struct bm_buffer *buf)
661f9c0a77SClaudiu Manoil {
671f9c0a77SClaudiu Manoil 	return be16_to_cpu(buf->bpid) & 0xff;
681f9c0a77SClaudiu Manoil }
691f9c0a77SClaudiu Manoil 
701f9c0a77SClaudiu Manoil static inline void bm_buffer_set_bpid(struct bm_buffer *buf, int bpid)
711f9c0a77SClaudiu Manoil {
721f9c0a77SClaudiu Manoil 	buf->bpid = cpu_to_be16(bpid & 0xff);
731f9c0a77SClaudiu Manoil }
741f9c0a77SClaudiu Manoil 
751f9c0a77SClaudiu Manoil /* Managed portal, high-level i/face */
761f9c0a77SClaudiu Manoil 
771f9c0a77SClaudiu Manoil /* Portal and Buffer Pools */
781f9c0a77SClaudiu Manoil struct bman_portal;
791f9c0a77SClaudiu Manoil struct bman_pool;
801f9c0a77SClaudiu Manoil 
811f9c0a77SClaudiu Manoil #define BM_POOL_MAX		64 /* max # of buffer pools */
821f9c0a77SClaudiu Manoil 
831f9c0a77SClaudiu Manoil /**
841f9c0a77SClaudiu Manoil  * bman_new_pool - Allocates a Buffer Pool object
851f9c0a77SClaudiu Manoil  *
861f9c0a77SClaudiu Manoil  * Creates a pool object, and returns a reference to it or NULL on error.
871f9c0a77SClaudiu Manoil  */
881f9c0a77SClaudiu Manoil struct bman_pool *bman_new_pool(void);
891f9c0a77SClaudiu Manoil 
901f9c0a77SClaudiu Manoil /**
911f9c0a77SClaudiu Manoil  * bman_free_pool - Deallocates a Buffer Pool object
921f9c0a77SClaudiu Manoil  * @pool: the pool object to release
931f9c0a77SClaudiu Manoil  */
941f9c0a77SClaudiu Manoil void bman_free_pool(struct bman_pool *pool);
951f9c0a77SClaudiu Manoil 
961f9c0a77SClaudiu Manoil /**
971f9c0a77SClaudiu Manoil  * bman_get_bpid - Returns a pool object's BPID.
981f9c0a77SClaudiu Manoil  * @pool: the pool object
991f9c0a77SClaudiu Manoil  *
1001f9c0a77SClaudiu Manoil  * The returned value is the index of the encapsulated buffer pool,
1011f9c0a77SClaudiu Manoil  * in the range of [0, @BM_POOL_MAX-1].
1021f9c0a77SClaudiu Manoil  */
1031f9c0a77SClaudiu Manoil int bman_get_bpid(const struct bman_pool *pool);
1041f9c0a77SClaudiu Manoil 
1051f9c0a77SClaudiu Manoil /**
1061f9c0a77SClaudiu Manoil  * bman_release - Release buffer(s) to the buffer pool
1071f9c0a77SClaudiu Manoil  * @pool: the buffer pool object to release to
1081f9c0a77SClaudiu Manoil  * @bufs: an array of buffers to release
1091f9c0a77SClaudiu Manoil  * @num: the number of buffers in @bufs (1-8)
1101f9c0a77SClaudiu Manoil  *
1111f9c0a77SClaudiu Manoil  * Adds the given buffers to RCR entries. If the RCR ring is unresponsive,
1121f9c0a77SClaudiu Manoil  * the function will return -ETIMEDOUT. Otherwise, it returns zero.
1131f9c0a77SClaudiu Manoil  */
1141f9c0a77SClaudiu Manoil int bman_release(struct bman_pool *pool, const struct bm_buffer *bufs, u8 num);
1151f9c0a77SClaudiu Manoil 
1161f9c0a77SClaudiu Manoil /**
1171f9c0a77SClaudiu Manoil  * bman_acquire - Acquire buffer(s) from a buffer pool
1181f9c0a77SClaudiu Manoil  * @pool: the buffer pool object to acquire from
1191f9c0a77SClaudiu Manoil  * @bufs: array for storing the acquired buffers
1201f9c0a77SClaudiu Manoil  * @num: the number of buffers desired (@bufs is at least this big)
1211f9c0a77SClaudiu Manoil  *
1221f9c0a77SClaudiu Manoil  * Issues an "Acquire" command via the portal's management command interface.
1231f9c0a77SClaudiu Manoil  * The return value will be the number of buffers obtained from the pool, or a
1241f9c0a77SClaudiu Manoil  * negative error code if a h/w error or pool starvation was encountered. In
1251f9c0a77SClaudiu Manoil  * the latter case, the content of @bufs is undefined.
1261f9c0a77SClaudiu Manoil  */
1271f9c0a77SClaudiu Manoil int bman_acquire(struct bman_pool *pool, struct bm_buffer *bufs, u8 num);
1281f9c0a77SClaudiu Manoil 
129*853dc104SLaurentiu Tudor /**
130*853dc104SLaurentiu Tudor  * bman_is_probed - Check if bman is probed
131*853dc104SLaurentiu Tudor  *
132*853dc104SLaurentiu Tudor  * Returns 1 if the bman driver successfully probed, -1 if the bman driver
133*853dc104SLaurentiu Tudor  * failed to probe or 0 if the bman driver did not probed yet.
134*853dc104SLaurentiu Tudor  */
135*853dc104SLaurentiu Tudor int bman_is_probed(void);
136*853dc104SLaurentiu Tudor 
1371f9c0a77SClaudiu Manoil #endif	/* __FSL_BMAN_H */
138