/* Copyright 2008 - 2016 Freescale Semiconductor, Inc.1*2* Redistribution and use in source and binary forms, with or without3* modification, are permitted provided that the following conditions are met:4* * Redistributions of source code must retain the above copyright5* notice, this list of conditions and the following disclaimer.6* * Redistributions in binary form must reproduce the above copyright7* notice, this list of conditions and the following disclaimer in the8* documentation and/or other materials provided with the distribution.9* * Neither the name of Freescale Semiconductor nor the10* names of its contributors may be used to endorse or promote products11* derived from this software without specific prior written permission.12*13* ALTERNATIVELY, this software may be distributed under the terms of the14* GNU General Public License ("GPL") as published by the Free Software15* Foundation, either version 2 of that License or (at your option) any16* later version.17*18* THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY19* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED20* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE21* DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY22* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES23* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;24* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND25* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT26* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS27* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.28*/2930#ifndef __FSL_BMAN_H31#define __FSL_BMAN_H3233/* wrapper for 48-bit buffers */34struct bm_buffer {35union {36struct {37__be16 bpid; /* hi 8-bits reserved */38__be16 hi; /* High 16-bits of 48-bit address */39__be32 lo; /* Low 32-bits of 48-bit address */40};41__be64 data;42};43} __aligned(8);44/*45* Restore the 48 bit address previously stored in BMan46* hardware pools as a dma_addr_t47*/48static inline dma_addr_t bm_buf_addr(const struct bm_buffer *buf)49{50return be64_to_cpu(buf->data) & 0xffffffffffffLLU;51}5253static inline u64 bm_buffer_get64(const struct bm_buffer *buf)54{55return be64_to_cpu(buf->data) & 0xffffffffffffLLU;56}5758static inline void bm_buffer_set64(struct bm_buffer *buf, u64 addr)59{60buf->hi = cpu_to_be16(upper_32_bits(addr));61buf->lo = cpu_to_be32(lower_32_bits(addr));62}6364static inline u8 bm_buffer_get_bpid(const struct bm_buffer *buf)65{66return be16_to_cpu(buf->bpid) & 0xff;67}6869static inline void bm_buffer_set_bpid(struct bm_buffer *buf, int bpid)70{71buf->bpid = cpu_to_be16(bpid & 0xff);72}7374/* Managed portal, high-level i/face */7576/* Portal and Buffer Pools */77struct bman_portal;78struct bman_pool;7980#define BM_POOL_MAX 64 /* max # of buffer pools */8182/**83* bman_new_pool - Allocates a Buffer Pool object84*85* Creates a pool object, and returns a reference to it or NULL on error.86*/87struct bman_pool *bman_new_pool(void);8889/**90* bman_free_pool - Deallocates a Buffer Pool object91* @pool: the pool object to release92*/93void bman_free_pool(struct bman_pool *pool);9495/**96* bman_get_bpid - Returns a pool object's BPID.97* @pool: the pool object98*99* The returned value is the index of the encapsulated buffer pool,100* in the range of [0, @BM_POOL_MAX-1].101*/102int bman_get_bpid(const struct bman_pool *pool);103104/**105* bman_release - Release buffer(s) to the buffer pool106* @pool: the buffer pool object to release to107* @bufs: an array of buffers to release108* @num: the number of buffers in @bufs (1-8)109*110* Adds the given buffers to RCR entries. If the RCR ring is unresponsive,111* the function will return -ETIMEDOUT. Otherwise, it returns zero.112*/113int bman_release(struct bman_pool *pool, const struct bm_buffer *bufs, u8 num);114115/**116* bman_acquire - Acquire buffer(s) from a buffer pool117* @pool: the buffer pool object to acquire from118* @bufs: array for storing the acquired buffers119* @num: the number of buffers desired (@bufs is at least this big)120*121* Issues an "Acquire" command via the portal's management command interface.122* The return value will be the number of buffers obtained from the pool, or a123* negative error code if a h/w error or pool starvation was encountered. In124* the latter case, the content of @bufs is undefined.125*/126int bman_acquire(struct bman_pool *pool, struct bm_buffer *bufs, u8 num);127128/**129* bman_is_probed - Check if bman is probed130*131* Returns 1 if the bman driver successfully probed, -1 if the bman driver132* failed to probe or 0 if the bman driver did not probed yet.133*/134int bman_is_probed(void);135/**136* bman_portals_probed - Check if all cpu bound bman portals are probed137*138* Returns 1 if all the required cpu bound bman portals successfully probed,139* -1 if probe errors appeared or 0 if the bman portals did not yet finished140* probing.141*/142int bman_portals_probed(void);143144#endif /* __FSL_BMAN_H */145146147