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, 0);
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_portal_create(void)
126 struct qman_portal *res;
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 res = qman_create_affine_portal(q_pcfg, NULL, true);
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);
178 process_portal_unmap(&q_map.addr);
183 int fsl_qman_portal_destroy(struct qman_portal *qp)
185 const struct qm_portal_config *cfg;
186 struct dpaa_portal_map addr;
189 cfg = qman_destroy_affine_portal(qp);
192 process_portal_irq_unmap(cfg->irq);
194 addr.cena = cfg->addr_virt[DPAA_PORTAL_CE];
195 addr.cinh = cfg->addr_virt[DPAA_PORTAL_CI];
197 ret = process_portal_unmap(&addr);
199 pr_err("process_portal_unmap() (%d)\n", ret);
206 int qman_global_init(void)
208 const struct device_node *dt_node;
211 static int ccsr_map_fd;
212 const uint32_t *qman_addr;
222 /* Use the device-tree to determine IP revision until something better
225 dt_node = of_find_compatible_node(NULL, NULL, "fsl,qman-portal");
227 pr_err("No qman portals available for any CPU\n");
230 if (of_device_is_compatible(dt_node, "fsl,qman-portal-1.0") ||
231 of_device_is_compatible(dt_node, "fsl,qman-portal-1.0.0"))
232 pr_err("QMan rev1.0 on P4080 rev1 is not supported!\n");
233 else if (of_device_is_compatible(dt_node, "fsl,qman-portal-1.1") ||
234 of_device_is_compatible(dt_node, "fsl,qman-portal-1.1.0"))
235 qman_ip_rev = QMAN_REV11;
236 else if (of_device_is_compatible(dt_node, "fsl,qman-portal-1.2") ||
237 of_device_is_compatible(dt_node, "fsl,qman-portal-1.2.0"))
238 qman_ip_rev = QMAN_REV12;
239 else if (of_device_is_compatible(dt_node, "fsl,qman-portal-2.0") ||
240 of_device_is_compatible(dt_node, "fsl,qman-portal-2.0.0"))
241 qman_ip_rev = QMAN_REV20;
242 else if (of_device_is_compatible(dt_node, "fsl,qman-portal-3.0.0") ||
243 of_device_is_compatible(dt_node, "fsl,qman-portal-3.0.1"))
244 qman_ip_rev = QMAN_REV30;
245 else if (of_device_is_compatible(dt_node, "fsl,qman-portal-3.1.0") ||
246 of_device_is_compatible(dt_node, "fsl,qman-portal-3.1.1") ||
247 of_device_is_compatible(dt_node, "fsl,qman-portal-3.1.2") ||
248 of_device_is_compatible(dt_node, "fsl,qman-portal-3.1.3"))
249 qman_ip_rev = QMAN_REV31;
250 else if (of_device_is_compatible(dt_node, "fsl,qman-portal-3.2.0") ||
251 of_device_is_compatible(dt_node, "fsl,qman-portal-3.2.1"))
252 qman_ip_rev = QMAN_REV32;
254 qman_ip_rev = QMAN_REV11;
257 pr_err("Unknown qman portal version\n");
260 if ((qman_ip_rev & 0xFF00) >= QMAN_REV30) {
261 qm_channel_pool1 = QMAN_CHANNEL_POOL1_REV3;
262 qm_channel_caam = QMAN_CHANNEL_CAAM_REV3;
263 qm_channel_pme = QMAN_CHANNEL_PME_REV3;
266 dt_node = of_find_compatible_node(NULL, NULL, "fsl,pool-channel-range");
268 pr_err("No qman pool channel range available\n");
271 chanid = of_get_property(dt_node, "fsl,pool-channel-range", &lenp);
273 pr_err("Can not get pool-channel-range property\n");
278 dt_node = of_find_compatible_node(NULL, NULL, "fsl,qman");
280 pr_err("No qman device node available\n");
283 qman_addr = of_get_address(dt_node, 0, ®s_size, NULL);
285 pr_err("of_get_address cannot return qman address\n");
288 phys_addr = of_translate_address(dt_node, qman_addr);
290 pr_err("of_translate_address failed\n");
294 ccsr_map_fd = open("/dev/mem", O_RDWR);
295 if (unlikely(ccsr_map_fd < 0)) {
296 pr_err("Can not open /dev/mem for qman ccsr map\n");
300 qman_ccsr_map = mmap(NULL, regs_size, PROT_READ | PROT_WRITE,
301 MAP_SHARED, ccsr_map_fd, phys_addr);
302 if (qman_ccsr_map == MAP_FAILED) {
303 pr_err("Can not map qman ccsr base\n");
307 clk = of_get_property(dt_node, "clock-frequency", NULL);
309 pr_warn("Can't find Qman clock frequency\n");
311 qman_clk = be32_to_cpu(*clk);
313 #ifdef CONFIG_FSL_QMAN_FQ_LOOKUP
314 return qman_setup_fq_lookup_table(CONFIG_FSL_QMAN_FQ_LOOKUP_MAX);