New upstream version 17.11-rc3
[deb_dpdk.git] / drivers / bus / dpaa / base / qbman / bman_priv.h
1 /*-
2  * This file is provided under a dual BSD/GPLv2 license. When using or
3  * redistributing this file, you may do so under either license.
4  *
5  *   BSD LICENSE
6  *
7  * Copyright 2008-2016 Freescale Semiconductor Inc.
8  * Copyright 2017 NXP.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions are met:
12  * * Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  * * Redistributions in binary form must reproduce the above copyright
15  * notice, this list of conditions and the following disclaimer in the
16  * documentation and/or other materials provided with the distribution.
17  * * Neither the name of the above-listed copyright holders nor the
18  * names of any contributors may be used to endorse or promote products
19  * derived from this software without specific prior written permission.
20  *
21  *   GPL LICENSE SUMMARY
22  *
23  * ALTERNATIVELY, this software may be distributed under the terms of the
24  * GNU General Public License ("GPL") as published by the Free Software
25  * Foundation, either version 2 of that License or (at your option) any
26  * later version.
27  *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
29  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
32  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
33  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
34  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
35  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
36  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
37  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38  * POSSIBILITY OF SUCH DAMAGE.
39  */
40
41 #ifndef __BMAN_PRIV_H
42 #define __BMAN_PRIV_H
43
44 #include "dpaa_sys.h"
45 #include <fsl_bman.h>
46
47 /* Revision info (for errata and feature handling) */
48 #define BMAN_REV10 0x0100
49 #define BMAN_REV20 0x0200
50 #define BMAN_REV21 0x0201
51
52 #define BMAN_PORTAL_IRQ_PATH "/dev/fsl-usdpaa-irq"
53 #define BMAN_CCSR_MAP "/dev/mem"
54
55 /* This mask contains all the "irqsource" bits visible to API users */
56 #define BM_PIRQ_VISIBLE (BM_PIRQ_RCRI | BM_PIRQ_BSCN)
57
58 /* These are bm_<reg>_<verb>(). So for example, bm_disable_write() means "write
59  * the disable register" rather than "disable the ability to write".
60  */
61 #define bm_isr_status_read(bm)          __bm_isr_read(bm, bm_isr_status)
62 #define bm_isr_status_clear(bm, m)      __bm_isr_write(bm, bm_isr_status, m)
63 #define bm_isr_enable_read(bm)          __bm_isr_read(bm, bm_isr_enable)
64 #define bm_isr_enable_write(bm, v)      __bm_isr_write(bm, bm_isr_enable, v)
65 #define bm_isr_disable_read(bm)         __bm_isr_read(bm, bm_isr_disable)
66 #define bm_isr_disable_write(bm, v)     __bm_isr_write(bm, bm_isr_disable, v)
67 #define bm_isr_inhibit(bm)              __bm_isr_write(bm, bm_isr_inhibit, 1)
68 #define bm_isr_uninhibit(bm)            __bm_isr_write(bm, bm_isr_inhibit, 0)
69
70 /*
71  * Global variables of the max portal/pool number this bman version supported
72  */
73 extern u16 bman_pool_max;
74
75 /* used by CCSR and portal interrupt code */
76 enum bm_isr_reg {
77         bm_isr_status = 0,
78         bm_isr_enable = 1,
79         bm_isr_disable = 2,
80         bm_isr_inhibit = 3
81 };
82
83 struct bm_portal_config {
84         /*
85          * Corenet portal addresses;
86          * [0]==cache-enabled, [1]==cache-inhibited.
87          */
88         void __iomem *addr_virt[2];
89         /* Allow these to be joined in lists */
90         struct list_head list;
91         /* User-visible portal configuration settings */
92         /* This is used for any "core-affine" portals, ie. default portals
93          * associated to the corresponding cpu. -1 implies that there is no
94          * core affinity configured.
95          */
96         int cpu;
97         /* portal interrupt line */
98         int irq;
99         /* the unique index of this portal */
100         u32 index;
101         /* Is this portal shared? (If so, it has coarser locking and demuxes
102          * processing on behalf of other CPUs.).
103          */
104         int is_shared;
105         /* These are the buffer pool IDs that may be used via this portal. */
106         struct bman_depletion mask;
107
108 };
109
110 int bman_init_ccsr(const struct device_node *node);
111
112 struct bman_portal *bman_create_affine_portal(
113                         const struct bm_portal_config *config);
114 const struct bm_portal_config *bman_destroy_affine_portal(void);
115
116 /* Set depletion thresholds associated with a buffer pool. Requires that the
117  * operating system have access to Bman CCSR (ie. compiled in support and
118  * run-time access courtesy of the device-tree).
119  */
120 int bm_pool_set(u32 bpid, const u32 *thresholds);
121
122 /* Read the free buffer count for a given buffer */
123 u32 bm_pool_free_buffers(u32 bpid);
124
125 #endif /* __BMAN_PRIV_H */