1 | /* Copyright 2008 - 2015 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 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
---|
32 | |
---|
33 | #include "dpaa_sys.h" |
---|
34 | |
---|
35 | #include <soc/fsl/bman.h> |
---|
36 | |
---|
37 | /* used by CCSR and portal interrupt code */ |
---|
38 | enum bm_isr_reg { |
---|
39 | bm_isr_status = 0, |
---|
40 | bm_isr_enable = 1, |
---|
41 | bm_isr_disable = 2, |
---|
42 | bm_isr_inhibit = 3 |
---|
43 | }; |
---|
44 | |
---|
45 | #ifdef CONFIG_FSL_BMAN |
---|
46 | /* Set depletion thresholds associated with a buffer pool. Requires that the |
---|
47 | * operating system have access to BMan CCSR (ie. compiled in support and |
---|
48 | * run-time access courtesy of the device-tree). */ |
---|
49 | int bm_pool_set(u32 bpid, const u32 *thresholds); |
---|
50 | #define BM_POOL_THRESH_SW_ENTER 0 |
---|
51 | #define BM_POOL_THRESH_SW_EXIT 1 |
---|
52 | #define BM_POOL_THRESH_HW_ENTER 2 |
---|
53 | #define BM_POOL_THRESH_HW_EXIT 3 |
---|
54 | |
---|
55 | /* Read the free buffer count for a given buffer */ |
---|
56 | u32 bm_pool_free_buffers(u32 bpid); |
---|
57 | |
---|
58 | #endif /* CONFIG_FSL_BMAN */ |
---|
59 | |
---|
60 | #if defined(CONFIG_FSL_BMAN_PORTAL) || defined(CONFIG_FSL_BMAN_PORTAL_MODULE) |
---|
61 | /* Revision info (for errata and feature handling) */ |
---|
62 | #define BMAN_REV10 0x0100 |
---|
63 | #define BMAN_REV20 0x0200 |
---|
64 | #define BMAN_REV21 0x0201 |
---|
65 | extern u16 bman_ip_rev; /* 0 if uninitialised, otherwise BMAN_REVx */ |
---|
66 | |
---|
67 | struct bm_portal_config { |
---|
68 | /* Corenet portal addresses; |
---|
69 | * [0]==cache-enabled, [1]==cache-inhibited. */ |
---|
70 | __iomem void *addr_virt[2]; |
---|
71 | #ifndef __rtems__ |
---|
72 | struct resource addr_phys[2]; |
---|
73 | /* Allow these to be joined in lists */ |
---|
74 | struct list_head list; |
---|
75 | #endif /* __rtems__ */ |
---|
76 | /* User-visible portal configuration settings */ |
---|
77 | struct bman_portal_config public_cfg; |
---|
78 | }; |
---|
79 | |
---|
80 | /* Hooks from bman_driver.c in to bman_high.c */ |
---|
81 | struct bman_portal *bman_create_portal( |
---|
82 | struct bman_portal *portal, |
---|
83 | const struct bm_portal_config *config); |
---|
84 | struct bman_portal *bman_create_affine_portal( |
---|
85 | const struct bm_portal_config *config); |
---|
86 | struct bman_portal *bman_create_affine_slave(struct bman_portal *redirect, |
---|
87 | int cpu); |
---|
88 | void bman_destroy_portal(struct bman_portal *bm); |
---|
89 | |
---|
90 | const struct bm_portal_config *bman_destroy_affine_portal(void); |
---|
91 | |
---|
92 | /* Stockpile build constants. The _LOW value: when bman_acquire() is called and |
---|
93 | * the stockpile fill-level is <= _LOW, an acquire is attempted from h/w but it |
---|
94 | * might fail (if the buffer pool is depleted). So this value provides some |
---|
95 | * "stagger" in that the bman_acquire() function will only fail if lots of bufs |
---|
96 | * are requested at once or if h/w has been tested a couple of times without |
---|
97 | * luck. The _HIGH value: when bman_release() is called and the stockpile |
---|
98 | * fill-level is >= _HIGH, a release is attempted to h/w but it might fail (if |
---|
99 | * the release ring is full). So this value provides some "stagger" so that |
---|
100 | * ring-access is retried a couple of times prior to the API returning a |
---|
101 | * failure. The following *must* be true; |
---|
102 | * BMAN_STOCKPILE_HIGH-BMAN_STOCKPILE_LOW > 8 |
---|
103 | * (to avoid thrashing) |
---|
104 | * BMAN_STOCKPILE_SZ >= 16 |
---|
105 | * (as the release logic expects to either send 8 buffers to hw prior to |
---|
106 | * adding the given buffers to the stockpile or add the buffers to the |
---|
107 | * stockpile before sending 8 to hw, as the API must be an all-or-nothing |
---|
108 | * success/fail.) |
---|
109 | */ |
---|
110 | #define BMAN_STOCKPILE_SZ 16u /* number of bufs in per-pool cache */ |
---|
111 | #define BMAN_STOCKPILE_LOW 2u /* when fill is <= this, acquire from hw */ |
---|
112 | #define BMAN_STOCKPILE_HIGH 14u /* when fill is >= this, release to hw */ |
---|
113 | |
---|
114 | /*************************************************/ |
---|
115 | /* BMan s/w corenet portal, low-level i/face */ |
---|
116 | /*************************************************/ |
---|
117 | |
---|
118 | /* Used by all portal interrupt registers except 'inhibit' |
---|
119 | * This mask contains all the "irqsource" bits visible to API users |
---|
120 | */ |
---|
121 | #define BM_PIRQ_VISIBLE (BM_PIRQ_RCRI | BM_PIRQ_BSCN) |
---|
122 | |
---|
123 | /* These are bm_<reg>_<verb>(). So for example, bm_disable_write() means "write |
---|
124 | * the disable register" rather than "disable the ability to write". */ |
---|
125 | #define bm_isr_status_read(bm) __bm_isr_read(bm, bm_isr_status) |
---|
126 | #define bm_isr_status_clear(bm, m) __bm_isr_write(bm, bm_isr_status, m) |
---|
127 | #define bm_isr_enable_read(bm) __bm_isr_read(bm, bm_isr_enable) |
---|
128 | #define bm_isr_enable_write(bm, v) __bm_isr_write(bm, bm_isr_enable, v) |
---|
129 | #define bm_isr_disable_read(bm) __bm_isr_read(bm, bm_isr_disable) |
---|
130 | #define bm_isr_disable_write(bm, v) __bm_isr_write(bm, bm_isr_disable, v) |
---|
131 | #define bm_isr_inhibit(bm) __bm_isr_write(bm, bm_isr_inhibit, 1) |
---|
132 | #define bm_isr_uninhibit(bm) __bm_isr_write(bm, bm_isr_inhibit, 0) |
---|
133 | |
---|
134 | const struct bm_portal_config * |
---|
135 | bman_get_bm_portal_config(const struct bman_portal *portal); |
---|
136 | #endif /* CONFIG_FSL_BMAN_PORTAL* */ |
---|