162306a36Sopenharmony_ci/* Copyright 2008 - 2016 Freescale Semiconductor, Inc. 262306a36Sopenharmony_ci * 362306a36Sopenharmony_ci * Redistribution and use in source and binary forms, with or without 462306a36Sopenharmony_ci * modification, are permitted provided that the following conditions are met: 562306a36Sopenharmony_ci * * Redistributions of source code must retain the above copyright 662306a36Sopenharmony_ci * notice, this list of conditions and the following disclaimer. 762306a36Sopenharmony_ci * * Redistributions in binary form must reproduce the above copyright 862306a36Sopenharmony_ci * notice, this list of conditions and the following disclaimer in the 962306a36Sopenharmony_ci * documentation and/or other materials provided with the distribution. 1062306a36Sopenharmony_ci * * Neither the name of Freescale Semiconductor nor the 1162306a36Sopenharmony_ci * names of its contributors may be used to endorse or promote products 1262306a36Sopenharmony_ci * derived from this software without specific prior written permission. 1362306a36Sopenharmony_ci * 1462306a36Sopenharmony_ci * ALTERNATIVELY, this software may be distributed under the terms of the 1562306a36Sopenharmony_ci * GNU General Public License ("GPL") as published by the Free Software 1662306a36Sopenharmony_ci * Foundation, either version 2 of that License or (at your option) any 1762306a36Sopenharmony_ci * later version. 1862306a36Sopenharmony_ci * 1962306a36Sopenharmony_ci * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY 2062306a36Sopenharmony_ci * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 2162306a36Sopenharmony_ci * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 2262306a36Sopenharmony_ci * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY 2362306a36Sopenharmony_ci * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 2462306a36Sopenharmony_ci * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 2562306a36Sopenharmony_ci * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 2662306a36Sopenharmony_ci * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2762306a36Sopenharmony_ci * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 2862306a36Sopenharmony_ci * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2962306a36Sopenharmony_ci */ 3062306a36Sopenharmony_ci 3162306a36Sopenharmony_ci#ifndef __FSL_BMAN_H 3262306a36Sopenharmony_ci#define __FSL_BMAN_H 3362306a36Sopenharmony_ci 3462306a36Sopenharmony_ci/* wrapper for 48-bit buffers */ 3562306a36Sopenharmony_cistruct bm_buffer { 3662306a36Sopenharmony_ci union { 3762306a36Sopenharmony_ci struct { 3862306a36Sopenharmony_ci __be16 bpid; /* hi 8-bits reserved */ 3962306a36Sopenharmony_ci __be16 hi; /* High 16-bits of 48-bit address */ 4062306a36Sopenharmony_ci __be32 lo; /* Low 32-bits of 48-bit address */ 4162306a36Sopenharmony_ci }; 4262306a36Sopenharmony_ci __be64 data; 4362306a36Sopenharmony_ci }; 4462306a36Sopenharmony_ci} __aligned(8); 4562306a36Sopenharmony_ci/* 4662306a36Sopenharmony_ci * Restore the 48 bit address previously stored in BMan 4762306a36Sopenharmony_ci * hardware pools as a dma_addr_t 4862306a36Sopenharmony_ci */ 4962306a36Sopenharmony_cistatic inline dma_addr_t bm_buf_addr(const struct bm_buffer *buf) 5062306a36Sopenharmony_ci{ 5162306a36Sopenharmony_ci return be64_to_cpu(buf->data) & 0xffffffffffffLLU; 5262306a36Sopenharmony_ci} 5362306a36Sopenharmony_ci 5462306a36Sopenharmony_cistatic inline u64 bm_buffer_get64(const struct bm_buffer *buf) 5562306a36Sopenharmony_ci{ 5662306a36Sopenharmony_ci return be64_to_cpu(buf->data) & 0xffffffffffffLLU; 5762306a36Sopenharmony_ci} 5862306a36Sopenharmony_ci 5962306a36Sopenharmony_cistatic inline void bm_buffer_set64(struct bm_buffer *buf, u64 addr) 6062306a36Sopenharmony_ci{ 6162306a36Sopenharmony_ci buf->hi = cpu_to_be16(upper_32_bits(addr)); 6262306a36Sopenharmony_ci buf->lo = cpu_to_be32(lower_32_bits(addr)); 6362306a36Sopenharmony_ci} 6462306a36Sopenharmony_ci 6562306a36Sopenharmony_cistatic inline u8 bm_buffer_get_bpid(const struct bm_buffer *buf) 6662306a36Sopenharmony_ci{ 6762306a36Sopenharmony_ci return be16_to_cpu(buf->bpid) & 0xff; 6862306a36Sopenharmony_ci} 6962306a36Sopenharmony_ci 7062306a36Sopenharmony_cistatic inline void bm_buffer_set_bpid(struct bm_buffer *buf, int bpid) 7162306a36Sopenharmony_ci{ 7262306a36Sopenharmony_ci buf->bpid = cpu_to_be16(bpid & 0xff); 7362306a36Sopenharmony_ci} 7462306a36Sopenharmony_ci 7562306a36Sopenharmony_ci/* Managed portal, high-level i/face */ 7662306a36Sopenharmony_ci 7762306a36Sopenharmony_ci/* Portal and Buffer Pools */ 7862306a36Sopenharmony_cistruct bman_portal; 7962306a36Sopenharmony_cistruct bman_pool; 8062306a36Sopenharmony_ci 8162306a36Sopenharmony_ci#define BM_POOL_MAX 64 /* max # of buffer pools */ 8262306a36Sopenharmony_ci 8362306a36Sopenharmony_ci/** 8462306a36Sopenharmony_ci * bman_new_pool - Allocates a Buffer Pool object 8562306a36Sopenharmony_ci * 8662306a36Sopenharmony_ci * Creates a pool object, and returns a reference to it or NULL on error. 8762306a36Sopenharmony_ci */ 8862306a36Sopenharmony_cistruct bman_pool *bman_new_pool(void); 8962306a36Sopenharmony_ci 9062306a36Sopenharmony_ci/** 9162306a36Sopenharmony_ci * bman_free_pool - Deallocates a Buffer Pool object 9262306a36Sopenharmony_ci * @pool: the pool object to release 9362306a36Sopenharmony_ci */ 9462306a36Sopenharmony_civoid bman_free_pool(struct bman_pool *pool); 9562306a36Sopenharmony_ci 9662306a36Sopenharmony_ci/** 9762306a36Sopenharmony_ci * bman_get_bpid - Returns a pool object's BPID. 9862306a36Sopenharmony_ci * @pool: the pool object 9962306a36Sopenharmony_ci * 10062306a36Sopenharmony_ci * The returned value is the index of the encapsulated buffer pool, 10162306a36Sopenharmony_ci * in the range of [0, @BM_POOL_MAX-1]. 10262306a36Sopenharmony_ci */ 10362306a36Sopenharmony_ciint bman_get_bpid(const struct bman_pool *pool); 10462306a36Sopenharmony_ci 10562306a36Sopenharmony_ci/** 10662306a36Sopenharmony_ci * bman_release - Release buffer(s) to the buffer pool 10762306a36Sopenharmony_ci * @pool: the buffer pool object to release to 10862306a36Sopenharmony_ci * @bufs: an array of buffers to release 10962306a36Sopenharmony_ci * @num: the number of buffers in @bufs (1-8) 11062306a36Sopenharmony_ci * 11162306a36Sopenharmony_ci * Adds the given buffers to RCR entries. If the RCR ring is unresponsive, 11262306a36Sopenharmony_ci * the function will return -ETIMEDOUT. Otherwise, it returns zero. 11362306a36Sopenharmony_ci */ 11462306a36Sopenharmony_ciint bman_release(struct bman_pool *pool, const struct bm_buffer *bufs, u8 num); 11562306a36Sopenharmony_ci 11662306a36Sopenharmony_ci/** 11762306a36Sopenharmony_ci * bman_acquire - Acquire buffer(s) from a buffer pool 11862306a36Sopenharmony_ci * @pool: the buffer pool object to acquire from 11962306a36Sopenharmony_ci * @bufs: array for storing the acquired buffers 12062306a36Sopenharmony_ci * @num: the number of buffers desired (@bufs is at least this big) 12162306a36Sopenharmony_ci * 12262306a36Sopenharmony_ci * Issues an "Acquire" command via the portal's management command interface. 12362306a36Sopenharmony_ci * The return value will be the number of buffers obtained from the pool, or a 12462306a36Sopenharmony_ci * negative error code if a h/w error or pool starvation was encountered. In 12562306a36Sopenharmony_ci * the latter case, the content of @bufs is undefined. 12662306a36Sopenharmony_ci */ 12762306a36Sopenharmony_ciint bman_acquire(struct bman_pool *pool, struct bm_buffer *bufs, u8 num); 12862306a36Sopenharmony_ci 12962306a36Sopenharmony_ci/** 13062306a36Sopenharmony_ci * bman_is_probed - Check if bman is probed 13162306a36Sopenharmony_ci * 13262306a36Sopenharmony_ci * Returns 1 if the bman driver successfully probed, -1 if the bman driver 13362306a36Sopenharmony_ci * failed to probe or 0 if the bman driver did not probed yet. 13462306a36Sopenharmony_ci */ 13562306a36Sopenharmony_ciint bman_is_probed(void); 13662306a36Sopenharmony_ci/** 13762306a36Sopenharmony_ci * bman_portals_probed - Check if all cpu bound bman portals are probed 13862306a36Sopenharmony_ci * 13962306a36Sopenharmony_ci * Returns 1 if all the required cpu bound bman portals successfully probed, 14062306a36Sopenharmony_ci * -1 if probe errors appeared or 0 if the bman portals did not yet finished 14162306a36Sopenharmony_ci * probing. 14262306a36Sopenharmony_ci */ 14362306a36Sopenharmony_ciint bman_portals_probed(void); 14462306a36Sopenharmony_ci 14562306a36Sopenharmony_ci#endif /* __FSL_BMAN_H */ 146