1*4882a593Smuzhiyun /* Copyright 2008 - 2016 Freescale Semiconductor, Inc.
2*4882a593Smuzhiyun *
3*4882a593Smuzhiyun * Redistribution and use in source and binary forms, with or without
4*4882a593Smuzhiyun * modification, are permitted provided that the following conditions are met:
5*4882a593Smuzhiyun * * Redistributions of source code must retain the above copyright
6*4882a593Smuzhiyun * notice, this list of conditions and the following disclaimer.
7*4882a593Smuzhiyun * * Redistributions in binary form must reproduce the above copyright
8*4882a593Smuzhiyun * notice, this list of conditions and the following disclaimer in the
9*4882a593Smuzhiyun * documentation and/or other materials provided with the distribution.
10*4882a593Smuzhiyun * * Neither the name of Freescale Semiconductor nor the
11*4882a593Smuzhiyun * names of its contributors may be used to endorse or promote products
12*4882a593Smuzhiyun * derived from this software without specific prior written permission.
13*4882a593Smuzhiyun *
14*4882a593Smuzhiyun * ALTERNATIVELY, this software may be distributed under the terms of the
15*4882a593Smuzhiyun * GNU General Public License ("GPL") as published by the Free Software
16*4882a593Smuzhiyun * Foundation, either version 2 of that License or (at your option) any
17*4882a593Smuzhiyun * later version.
18*4882a593Smuzhiyun *
19*4882a593Smuzhiyun * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
20*4882a593Smuzhiyun * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21*4882a593Smuzhiyun * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22*4882a593Smuzhiyun * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
23*4882a593Smuzhiyun * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24*4882a593Smuzhiyun * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25*4882a593Smuzhiyun * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26*4882a593Smuzhiyun * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27*4882a593Smuzhiyun * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28*4882a593Smuzhiyun * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29*4882a593Smuzhiyun */
30*4882a593Smuzhiyun
31*4882a593Smuzhiyun #ifndef __FSL_BMAN_H
32*4882a593Smuzhiyun #define __FSL_BMAN_H
33*4882a593Smuzhiyun
34*4882a593Smuzhiyun /* wrapper for 48-bit buffers */
35*4882a593Smuzhiyun struct bm_buffer {
36*4882a593Smuzhiyun union {
37*4882a593Smuzhiyun struct {
38*4882a593Smuzhiyun __be16 bpid; /* hi 8-bits reserved */
39*4882a593Smuzhiyun __be16 hi; /* High 16-bits of 48-bit address */
40*4882a593Smuzhiyun __be32 lo; /* Low 32-bits of 48-bit address */
41*4882a593Smuzhiyun };
42*4882a593Smuzhiyun __be64 data;
43*4882a593Smuzhiyun };
44*4882a593Smuzhiyun } __aligned(8);
45*4882a593Smuzhiyun /*
46*4882a593Smuzhiyun * Restore the 48 bit address previously stored in BMan
47*4882a593Smuzhiyun * hardware pools as a dma_addr_t
48*4882a593Smuzhiyun */
bm_buf_addr(const struct bm_buffer * buf)49*4882a593Smuzhiyun static inline dma_addr_t bm_buf_addr(const struct bm_buffer *buf)
50*4882a593Smuzhiyun {
51*4882a593Smuzhiyun return be64_to_cpu(buf->data) & 0xffffffffffffLLU;
52*4882a593Smuzhiyun }
53*4882a593Smuzhiyun
bm_buffer_get64(const struct bm_buffer * buf)54*4882a593Smuzhiyun static inline u64 bm_buffer_get64(const struct bm_buffer *buf)
55*4882a593Smuzhiyun {
56*4882a593Smuzhiyun return be64_to_cpu(buf->data) & 0xffffffffffffLLU;
57*4882a593Smuzhiyun }
58*4882a593Smuzhiyun
bm_buffer_set64(struct bm_buffer * buf,u64 addr)59*4882a593Smuzhiyun static inline void bm_buffer_set64(struct bm_buffer *buf, u64 addr)
60*4882a593Smuzhiyun {
61*4882a593Smuzhiyun buf->hi = cpu_to_be16(upper_32_bits(addr));
62*4882a593Smuzhiyun buf->lo = cpu_to_be32(lower_32_bits(addr));
63*4882a593Smuzhiyun }
64*4882a593Smuzhiyun
bm_buffer_get_bpid(const struct bm_buffer * buf)65*4882a593Smuzhiyun static inline u8 bm_buffer_get_bpid(const struct bm_buffer *buf)
66*4882a593Smuzhiyun {
67*4882a593Smuzhiyun return be16_to_cpu(buf->bpid) & 0xff;
68*4882a593Smuzhiyun }
69*4882a593Smuzhiyun
bm_buffer_set_bpid(struct bm_buffer * buf,int bpid)70*4882a593Smuzhiyun static inline void bm_buffer_set_bpid(struct bm_buffer *buf, int bpid)
71*4882a593Smuzhiyun {
72*4882a593Smuzhiyun buf->bpid = cpu_to_be16(bpid & 0xff);
73*4882a593Smuzhiyun }
74*4882a593Smuzhiyun
75*4882a593Smuzhiyun /* Managed portal, high-level i/face */
76*4882a593Smuzhiyun
77*4882a593Smuzhiyun /* Portal and Buffer Pools */
78*4882a593Smuzhiyun struct bman_portal;
79*4882a593Smuzhiyun struct bman_pool;
80*4882a593Smuzhiyun
81*4882a593Smuzhiyun #define BM_POOL_MAX 64 /* max # of buffer pools */
82*4882a593Smuzhiyun
83*4882a593Smuzhiyun /**
84*4882a593Smuzhiyun * bman_new_pool - Allocates a Buffer Pool object
85*4882a593Smuzhiyun *
86*4882a593Smuzhiyun * Creates a pool object, and returns a reference to it or NULL on error.
87*4882a593Smuzhiyun */
88*4882a593Smuzhiyun struct bman_pool *bman_new_pool(void);
89*4882a593Smuzhiyun
90*4882a593Smuzhiyun /**
91*4882a593Smuzhiyun * bman_free_pool - Deallocates a Buffer Pool object
92*4882a593Smuzhiyun * @pool: the pool object to release
93*4882a593Smuzhiyun */
94*4882a593Smuzhiyun void bman_free_pool(struct bman_pool *pool);
95*4882a593Smuzhiyun
96*4882a593Smuzhiyun /**
97*4882a593Smuzhiyun * bman_get_bpid - Returns a pool object's BPID.
98*4882a593Smuzhiyun * @pool: the pool object
99*4882a593Smuzhiyun *
100*4882a593Smuzhiyun * The returned value is the index of the encapsulated buffer pool,
101*4882a593Smuzhiyun * in the range of [0, @BM_POOL_MAX-1].
102*4882a593Smuzhiyun */
103*4882a593Smuzhiyun int bman_get_bpid(const struct bman_pool *pool);
104*4882a593Smuzhiyun
105*4882a593Smuzhiyun /**
106*4882a593Smuzhiyun * bman_release - Release buffer(s) to the buffer pool
107*4882a593Smuzhiyun * @pool: the buffer pool object to release to
108*4882a593Smuzhiyun * @bufs: an array of buffers to release
109*4882a593Smuzhiyun * @num: the number of buffers in @bufs (1-8)
110*4882a593Smuzhiyun *
111*4882a593Smuzhiyun * Adds the given buffers to RCR entries. If the RCR ring is unresponsive,
112*4882a593Smuzhiyun * the function will return -ETIMEDOUT. Otherwise, it returns zero.
113*4882a593Smuzhiyun */
114*4882a593Smuzhiyun int bman_release(struct bman_pool *pool, const struct bm_buffer *bufs, u8 num);
115*4882a593Smuzhiyun
116*4882a593Smuzhiyun /**
117*4882a593Smuzhiyun * bman_acquire - Acquire buffer(s) from a buffer pool
118*4882a593Smuzhiyun * @pool: the buffer pool object to acquire from
119*4882a593Smuzhiyun * @bufs: array for storing the acquired buffers
120*4882a593Smuzhiyun * @num: the number of buffers desired (@bufs is at least this big)
121*4882a593Smuzhiyun *
122*4882a593Smuzhiyun * Issues an "Acquire" command via the portal's management command interface.
123*4882a593Smuzhiyun * The return value will be the number of buffers obtained from the pool, or a
124*4882a593Smuzhiyun * negative error code if a h/w error or pool starvation was encountered. In
125*4882a593Smuzhiyun * the latter case, the content of @bufs is undefined.
126*4882a593Smuzhiyun */
127*4882a593Smuzhiyun int bman_acquire(struct bman_pool *pool, struct bm_buffer *bufs, u8 num);
128*4882a593Smuzhiyun
129*4882a593Smuzhiyun /**
130*4882a593Smuzhiyun * bman_is_probed - Check if bman is probed
131*4882a593Smuzhiyun *
132*4882a593Smuzhiyun * Returns 1 if the bman driver successfully probed, -1 if the bman driver
133*4882a593Smuzhiyun * failed to probe or 0 if the bman driver did not probed yet.
134*4882a593Smuzhiyun */
135*4882a593Smuzhiyun int bman_is_probed(void);
136*4882a593Smuzhiyun /**
137*4882a593Smuzhiyun * bman_portals_probed - Check if all cpu bound bman portals are probed
138*4882a593Smuzhiyun *
139*4882a593Smuzhiyun * Returns 1 if all the required cpu bound bman portals successfully probed,
140*4882a593Smuzhiyun * -1 if probe errors appeared or 0 if the bman portals did not yet finished
141*4882a593Smuzhiyun * probing.
142*4882a593Smuzhiyun */
143*4882a593Smuzhiyun int bman_portals_probed(void);
144*4882a593Smuzhiyun
145*4882a593Smuzhiyun #endif /* __FSL_BMAN_H */
146