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.
7 * Copyright 2008-2016 Freescale Semiconductor Inc.
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.
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
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.
43 #include "qman_priv.h"
44 #include <sys/ioctl.h>
45 #include <rte_branch_prediction.h>
47 /* Global variable containing revision id (even on non-control plane systems
48 * where CCSR isn't available).
51 u16 qm_channel_pool1 = QMAN_CHANNEL_POOL1;
52 u16 qm_channel_caam = QMAN_CHANNEL_CAAM;
53 u16 qm_channel_pme = QMAN_CHANNEL_PME;
55 /* Ccsr map address to access ccsrbased register */
57 /* The qman clock frequency */
60 static __thread int fd = -1;
61 static __thread struct qm_portal_config pcfg;
62 static __thread struct dpaa_ioctl_portal_map map = {
63 .type = dpaa_portal_qman
66 static int fsl_qman_portal_init(uint32_t index, int is_shared)
69 struct qman_portal *portal;
71 struct dpaa_ioctl_irq_map irq_map;
73 /* Verify the thread's cpu-affinity */
74 ret = pthread_getaffinity_np(pthread_self(), sizeof(cpu_set_t),
77 error(0, ret, "pthread_getaffinity_np()");
81 for (loop = 0; loop < CPU_SETSIZE; loop++)
82 if (CPU_ISSET(loop, &cpuset)) {
84 pr_err("Thread is not affine to 1 cpu\n");
90 pr_err("Bug in getaffinity handling!\n");
94 /* Allocate and map a qman portal */
96 ret = process_portal_map(&map);
98 error(0, ret, "process_portal_map()");
101 pcfg.channel = map.channel;
102 pcfg.pools = map.pools;
103 pcfg.index = map.index;
105 /* Make the portal's cache-[enabled|inhibited] regions */
106 pcfg.addr_virt[DPAA_PORTAL_CE] = map.addr.cena;
107 pcfg.addr_virt[DPAA_PORTAL_CI] = map.addr.cinh;
109 fd = open(QMAN_PORTAL_IRQ_PATH, O_RDONLY);
111 pr_err("QMan irq init failed\n");
112 process_portal_unmap(&map.addr);
116 pcfg.is_shared = is_shared;
120 portal = qman_create_affine_portal(&pcfg, NULL);
122 pr_err("Qman portal initialisation failed (%d)\n",
124 process_portal_unmap(&map.addr);
128 irq_map.type = dpaa_portal_qman;
129 irq_map.portal_cinh = map.addr.cinh;
130 process_portal_irq_map(fd, &irq_map);
134 static int fsl_qman_portal_finish(void)
136 __maybe_unused const struct qm_portal_config *cfg;
139 process_portal_irq_unmap(fd);
141 cfg = qman_destroy_affine_portal();
142 DPAA_BUG_ON(cfg != &pcfg);
143 ret = process_portal_unmap(&map.addr);
145 error(0, ret, "process_portal_unmap()");
149 int qman_thread_init(void)
151 /* Convert from contiguous/virtual cpu numbering to real cpu when
152 * calling into the code that is dependent on the device naming.
154 return fsl_qman_portal_init(QBMAN_ANY_PORTAL_IDX, 0);
157 int qman_thread_finish(void)
159 return fsl_qman_portal_finish();
162 void qman_thread_irq(void)
164 qbman_invoke_irq(pcfg.irq);
166 /* Now we need to uninhibit interrupts. This is the only code outside
167 * the regular portal driver that manipulates any portal register, so
168 * rather than breaking that encapsulation I am simply hard-coding the
169 * offset to the inhibit register here.
171 out_be32(pcfg.addr_virt[DPAA_PORTAL_CI] + 0xe0c, 0);
174 int qman_global_init(void)
176 const struct device_node *dt_node;
180 static int ccsr_map_fd;
181 const uint32_t *qman_addr;
191 /* Use the device-tree to determine IP revision until something better
194 dt_node = of_find_compatible_node(NULL, NULL, "fsl,qman-portal");
196 pr_err("No qman portals available for any CPU\n");
199 if (of_device_is_compatible(dt_node, "fsl,qman-portal-1.0") ||
200 of_device_is_compatible(dt_node, "fsl,qman-portal-1.0.0"))
201 pr_err("QMan rev1.0 on P4080 rev1 is not supported!\n");
202 else if (of_device_is_compatible(dt_node, "fsl,qman-portal-1.1") ||
203 of_device_is_compatible(dt_node, "fsl,qman-portal-1.1.0"))
204 qman_ip_rev = QMAN_REV11;
205 else if (of_device_is_compatible(dt_node, "fsl,qman-portal-1.2") ||
206 of_device_is_compatible(dt_node, "fsl,qman-portal-1.2.0"))
207 qman_ip_rev = QMAN_REV12;
208 else if (of_device_is_compatible(dt_node, "fsl,qman-portal-2.0") ||
209 of_device_is_compatible(dt_node, "fsl,qman-portal-2.0.0"))
210 qman_ip_rev = QMAN_REV20;
211 else if (of_device_is_compatible(dt_node, "fsl,qman-portal-3.0.0") ||
212 of_device_is_compatible(dt_node, "fsl,qman-portal-3.0.1"))
213 qman_ip_rev = QMAN_REV30;
214 else if (of_device_is_compatible(dt_node, "fsl,qman-portal-3.1.0") ||
215 of_device_is_compatible(dt_node, "fsl,qman-portal-3.1.1") ||
216 of_device_is_compatible(dt_node, "fsl,qman-portal-3.1.2") ||
217 of_device_is_compatible(dt_node, "fsl,qman-portal-3.1.3"))
218 qman_ip_rev = QMAN_REV31;
219 else if (of_device_is_compatible(dt_node, "fsl,qman-portal-3.2.0") ||
220 of_device_is_compatible(dt_node, "fsl,qman-portal-3.2.1"))
221 qman_ip_rev = QMAN_REV32;
223 qman_ip_rev = QMAN_REV11;
226 pr_err("Unknown qman portal version\n");
229 if ((qman_ip_rev & 0xFF00) >= QMAN_REV30) {
230 qm_channel_pool1 = QMAN_CHANNEL_POOL1_REV3;
231 qm_channel_caam = QMAN_CHANNEL_CAAM_REV3;
232 qm_channel_pme = QMAN_CHANNEL_PME_REV3;
235 dt_node = of_find_compatible_node(NULL, NULL, "fsl,pool-channel-range");
237 pr_err("No qman pool channel range available\n");
240 chanid = of_get_property(dt_node, "fsl,pool-channel-range", &lenp);
242 pr_err("Can not get pool-channel-range property\n");
247 dt_node = of_find_compatible_node(NULL, NULL, "fsl,qman");
249 pr_err("No qman device node available\n");
252 qman_addr = of_get_address(dt_node, 0, ®s_size, NULL);
254 pr_err("of_get_address cannot return qman address\n");
257 phys_addr = of_translate_address(dt_node, qman_addr);
259 pr_err("of_translate_address failed\n");
263 ccsr_map_fd = open("/dev/mem", O_RDWR);
264 if (unlikely(ccsr_map_fd < 0)) {
265 pr_err("Can not open /dev/mem for qman ccsr map\n");
269 qman_ccsr_map = mmap(NULL, regs_size, PROT_READ | PROT_WRITE,
270 MAP_SHARED, ccsr_map_fd, phys_addr);
271 if (qman_ccsr_map == MAP_FAILED) {
272 pr_err("Can not map qman ccsr base\n");
276 clk = of_get_property(dt_node, "clock-frequency", NULL);
278 pr_warn("Can't find Qman clock frequency\n");
280 qman_clk = be32_to_cpu(*clk);
282 #ifdef CONFIG_FSL_QMAN_FQ_LOOKUP
283 ret = qman_setup_fq_lookup_table(CONFIG_FSL_QMAN_FQ_LOOKUP_MAX);