1 /* SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0)
3 * Copyright 2008-2016 Freescale Semiconductor Inc.
4 * Copyright 2017,2019 NXP
10 #include "qman_priv.h"
11 #include <sys/ioctl.h>
12 #include <rte_branch_prediction.h>
14 /* Global variable containing revision id (even on non-control plane systems
15 * where CCSR isn't available).
18 u16 qm_channel_pool1 = QMAN_CHANNEL_POOL1;
19 u16 qm_channel_caam = QMAN_CHANNEL_CAAM;
20 u16 qm_channel_pme = QMAN_CHANNEL_PME;
22 /* Ccsr map address to access ccsrbased register */
23 static void *qman_ccsr_map;
24 /* The qman clock frequency */
27 static __thread int qmfd = -1;
28 static __thread struct qm_portal_config qpcfg;
29 static __thread struct dpaa_ioctl_portal_map map = {
30 .type = dpaa_portal_qman
33 static int fsl_qman_portal_init(uint32_t index, int is_shared)
35 struct qman_portal *portal;
36 struct dpaa_ioctl_irq_map irq_map;
39 /* Allocate and map a qman portal */
41 ret = process_portal_map(&map);
43 error(0, ret, "process_portal_map()");
46 qpcfg.channel = map.channel;
47 qpcfg.pools = map.pools;
48 qpcfg.index = map.index;
50 /* Make the portal's cache-[enabled|inhibited] regions */
51 qpcfg.addr_virt[DPAA_PORTAL_CE] = map.addr.cena;
52 qpcfg.addr_virt[DPAA_PORTAL_CI] = map.addr.cinh;
54 qmfd = open(QMAN_PORTAL_IRQ_PATH, O_RDONLY);
56 pr_err("QMan irq init failed\n");
57 process_portal_unmap(&map.addr);
61 qpcfg.is_shared = is_shared;
65 portal = qman_create_affine_portal(&qpcfg, NULL);
67 pr_err("Qman portal initialisation failed (%d)\n",
69 process_portal_unmap(&map.addr);
73 irq_map.type = dpaa_portal_qman;
74 irq_map.portal_cinh = map.addr.cinh;
75 process_portal_irq_map(qmfd, &irq_map);
79 static int fsl_qman_portal_finish(void)
81 __maybe_unused const struct qm_portal_config *cfg;
84 process_portal_irq_unmap(qmfd);
86 cfg = qman_destroy_affine_portal(NULL);
87 DPAA_BUG_ON(cfg != &qpcfg);
88 ret = process_portal_unmap(&map.addr);
90 error(0, ret, "process_portal_unmap()");
94 int qman_thread_fd(void)
99 int qman_thread_init(void)
101 /* Convert from contiguous/virtual cpu numbering to real cpu when
102 * calling into the code that is dependent on the device naming.
104 return fsl_qman_portal_init(QBMAN_ANY_PORTAL_IDX, 0);
107 int qman_thread_finish(void)
109 return fsl_qman_portal_finish();
112 void qman_thread_irq(void)
114 qbman_invoke_irq(qpcfg.irq);
116 /* Now we need to uninhibit interrupts. This is the only code outside
117 * the regular portal driver that manipulates any portal register, so
118 * rather than breaking that encapsulation I am simply hard-coding the
119 * offset to the inhibit register here.
121 out_be32(qpcfg.addr_virt[DPAA_PORTAL_CI] + 0x36C0, 0);
124 struct qman_portal *fsl_qman_fq_portal_create(void)
126 struct qman_portal *portal = NULL;
127 struct qm_portal_config *q_pcfg;
128 struct dpaa_ioctl_irq_map irq_map;
129 struct dpaa_ioctl_portal_map q_map = {0};
132 q_pcfg = kzalloc((sizeof(struct qm_portal_config)), 0);
134 error(0, -1, "q_pcfg kzalloc failed");
138 /* Allocate and map a qman portal */
139 q_map.type = dpaa_portal_qman;
140 q_map.index = QBMAN_ANY_PORTAL_IDX;
141 ret = process_portal_map(&q_map);
143 error(0, ret, "process_portal_map()");
147 q_pcfg->channel = q_map.channel;
148 q_pcfg->pools = q_map.pools;
149 q_pcfg->index = q_map.index;
151 /* Make the portal's cache-[enabled|inhibited] regions */
152 q_pcfg->addr_virt[DPAA_PORTAL_CE] = q_map.addr.cena;
153 q_pcfg->addr_virt[DPAA_PORTAL_CI] = q_map.addr.cinh;
155 q_fd = open(QMAN_PORTAL_IRQ_PATH, O_RDONLY);
157 pr_err("QMan irq init failed\n");
163 portal = qman_alloc_global_portal(q_pcfg);
165 pr_err("Qman portal initialisation failed (%d)\n",
170 irq_map.type = dpaa_portal_qman;
171 irq_map.portal_cinh = q_map.addr.cinh;
172 process_portal_irq_map(q_fd, &irq_map);
177 qman_free_global_portal(portal);
180 process_portal_unmap(&q_map.addr);
185 int fsl_qman_fq_portal_init(struct qman_portal *qp)
187 struct qman_portal *res;
189 res = qman_init_portal(qp, NULL, NULL);
191 pr_err("Qman portal initialisation failed\n");
198 int fsl_qman_fq_portal_destroy(struct qman_portal *qp)
200 const struct qm_portal_config *cfg;
201 struct dpaa_portal_map addr;
204 cfg = qman_destroy_affine_portal(qp);
206 ret = qman_free_global_portal(qp);
208 pr_err("qman_free_global_portal() (%d)\n", ret);
212 process_portal_irq_unmap(cfg->irq);
214 addr.cena = cfg->addr_virt[DPAA_PORTAL_CE];
215 addr.cinh = cfg->addr_virt[DPAA_PORTAL_CI];
217 ret = process_portal_unmap(&addr);
219 pr_err("process_portal_unmap() (%d)\n", ret);
226 int qman_global_init(void)
228 const struct device_node *dt_node;
231 static int ccsr_map_fd;
232 const uint32_t *qman_addr;
242 /* Use the device-tree to determine IP revision until something better
245 dt_node = of_find_compatible_node(NULL, NULL, "fsl,qman-portal");
247 pr_err("No qman portals available for any CPU\n");
250 if (of_device_is_compatible(dt_node, "fsl,qman-portal-1.0") ||
251 of_device_is_compatible(dt_node, "fsl,qman-portal-1.0.0"))
252 pr_err("QMan rev1.0 on P4080 rev1 is not supported!\n");
253 else if (of_device_is_compatible(dt_node, "fsl,qman-portal-1.1") ||
254 of_device_is_compatible(dt_node, "fsl,qman-portal-1.1.0"))
255 qman_ip_rev = QMAN_REV11;
256 else if (of_device_is_compatible(dt_node, "fsl,qman-portal-1.2") ||
257 of_device_is_compatible(dt_node, "fsl,qman-portal-1.2.0"))
258 qman_ip_rev = QMAN_REV12;
259 else if (of_device_is_compatible(dt_node, "fsl,qman-portal-2.0") ||
260 of_device_is_compatible(dt_node, "fsl,qman-portal-2.0.0"))
261 qman_ip_rev = QMAN_REV20;
262 else if (of_device_is_compatible(dt_node, "fsl,qman-portal-3.0.0") ||
263 of_device_is_compatible(dt_node, "fsl,qman-portal-3.0.1"))
264 qman_ip_rev = QMAN_REV30;
265 else if (of_device_is_compatible(dt_node, "fsl,qman-portal-3.1.0") ||
266 of_device_is_compatible(dt_node, "fsl,qman-portal-3.1.1") ||
267 of_device_is_compatible(dt_node, "fsl,qman-portal-3.1.2") ||
268 of_device_is_compatible(dt_node, "fsl,qman-portal-3.1.3"))
269 qman_ip_rev = QMAN_REV31;
270 else if (of_device_is_compatible(dt_node, "fsl,qman-portal-3.2.0") ||
271 of_device_is_compatible(dt_node, "fsl,qman-portal-3.2.1"))
272 qman_ip_rev = QMAN_REV32;
274 qman_ip_rev = QMAN_REV11;
277 pr_err("Unknown qman portal version\n");
280 if ((qman_ip_rev & 0xFF00) >= QMAN_REV30) {
281 qm_channel_pool1 = QMAN_CHANNEL_POOL1_REV3;
282 qm_channel_caam = QMAN_CHANNEL_CAAM_REV3;
283 qm_channel_pme = QMAN_CHANNEL_PME_REV3;
286 dt_node = of_find_compatible_node(NULL, NULL, "fsl,pool-channel-range");
288 pr_err("No qman pool channel range available\n");
291 chanid = of_get_property(dt_node, "fsl,pool-channel-range", &lenp);
293 pr_err("Can not get pool-channel-range property\n");
298 dt_node = of_find_compatible_node(NULL, NULL, "fsl,qman");
300 pr_err("No qman device node available\n");
303 qman_addr = of_get_address(dt_node, 0, ®s_size, NULL);
305 pr_err("of_get_address cannot return qman address\n");
308 phys_addr = of_translate_address(dt_node, qman_addr);
310 pr_err("of_translate_address failed\n");
314 ccsr_map_fd = open("/dev/mem", O_RDWR);
315 if (unlikely(ccsr_map_fd < 0)) {
316 pr_err("Can not open /dev/mem for qman ccsr map\n");
320 qman_ccsr_map = mmap(NULL, regs_size, PROT_READ | PROT_WRITE,
321 MAP_SHARED, ccsr_map_fd, phys_addr);
322 if (qman_ccsr_map == MAP_FAILED) {
323 pr_err("Can not map qman ccsr base\n");
327 clk = of_get_property(dt_node, "clock-frequency", NULL);
329 pr_warn("Can't find Qman clock frequency\n");
331 qman_clk = be32_to_cpu(*clk);
333 #ifdef CONFIG_FSL_QMAN_FQ_LOOKUP
334 return qman_setup_fq_lookup_table(CONFIG_FSL_QMAN_FQ_LOOKUP_MAX);