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