1 From afb7254de9f03c3efaf4e306dcf5f88e1873fc6b Mon Sep 17 00:00:00 2001
2 From: Yangbo Lu <yangbo.lu@nxp.com>
3 Date: Mon, 25 Sep 2017 12:06:25 +0800
4 Subject: [PATCH] fsl-mc: layerscape support
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
9 This is a integrated patch for layerscape mc-bus support.
11 Signed-off-by: Stuart Yoder <stuart.yoder@nxp.com>
12 Signed-off-by: Bharat Bhushan <Bharat.Bhushan@nxp.com>
13 Signed-off-by: Arnd Bergmann <arnd@arndb.de>
14 Signed-off-by: Laurentiu Tudor <laurentiu.tudor@nxp.com>
15 Signed-off-by: Roy Pledge <roy.pledge@nxp.com>
16 Signed-off-by: Shiva Kerdel <shiva@exdev.nl>
17 Signed-off-by: Nipun Gupta <nipun.gupta@nxp.com>
18 Signed-off-by: Ioana Ciornei <ioana.ciornei@nxp.com>
19 Signed-off-by: Horia Geantă <horia.geanta@nxp.com>
20 Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>
22 drivers/staging/fsl-mc/bus/Kconfig | 41 +-
23 drivers/staging/fsl-mc/bus/Makefile | 10 +-
24 drivers/staging/fsl-mc/bus/dpbp-cmd.h | 80 ++
25 drivers/staging/fsl-mc/bus/dpbp.c | 450 +--------
26 drivers/staging/fsl-mc/bus/dpcon-cmd.h | 85 ++
27 drivers/staging/fsl-mc/bus/dpcon.c | 317 ++++++
28 drivers/staging/fsl-mc/bus/dpio/Makefile | 11 +
29 .../{include/dpcon-cmd.h => bus/dpio/dpio-cmd.h} | 73 +-
30 drivers/staging/fsl-mc/bus/dpio/dpio-driver.c | 296 ++++++
31 drivers/staging/fsl-mc/bus/dpio/dpio-driver.txt | 135 +++
32 drivers/staging/fsl-mc/bus/dpio/dpio-service.c | 693 +++++++++++++
33 drivers/staging/fsl-mc/bus/dpio/dpio.c | 224 +++++
34 drivers/staging/fsl-mc/bus/dpio/dpio.h | 109 ++
35 drivers/staging/fsl-mc/bus/dpio/qbman-portal.c | 1049 ++++++++++++++++++++
36 drivers/staging/fsl-mc/bus/dpio/qbman-portal.h | 662 ++++++++++++
37 drivers/staging/fsl-mc/bus/dpio/qbman_debug.c | 853 ++++++++++++++++
38 drivers/staging/fsl-mc/bus/dpio/qbman_debug.h | 136 +++
39 drivers/staging/fsl-mc/bus/dpio/qbman_private.h | 171 ++++
40 drivers/staging/fsl-mc/bus/dpmcp-cmd.h | 112 +--
41 drivers/staging/fsl-mc/bus/dpmcp.c | 374 +------
42 drivers/staging/fsl-mc/bus/dpmcp.h | 127 +--
43 drivers/staging/fsl-mc/bus/dpmng-cmd.h | 14 +-
44 drivers/staging/fsl-mc/bus/dpmng.c | 37 +-
45 drivers/staging/fsl-mc/bus/dprc-cmd.h | 82 +-
46 drivers/staging/fsl-mc/bus/dprc-driver.c | 38 +-
47 drivers/staging/fsl-mc/bus/dprc.c | 629 +-----------
48 drivers/staging/fsl-mc/bus/fsl-mc-allocator.c | 78 +-
49 drivers/staging/fsl-mc/bus/fsl-mc-bus.c | 318 +++---
50 drivers/staging/fsl-mc/bus/fsl-mc-iommu.c | 104 ++
51 drivers/staging/fsl-mc/bus/fsl-mc-msi.c | 3 +-
52 drivers/staging/fsl-mc/bus/fsl-mc-private.h | 6 +-
53 .../staging/fsl-mc/bus/irq-gic-v3-its-fsl-mc-msi.c | 11 +-
54 drivers/staging/fsl-mc/bus/mc-io.c | 4 +-
55 drivers/staging/fsl-mc/bus/mc-ioctl.h | 22 +
56 drivers/staging/fsl-mc/bus/mc-restool.c | 405 ++++++++
57 drivers/staging/fsl-mc/bus/mc-sys.c | 14 +-
58 drivers/staging/fsl-mc/include/dpaa2-fd.h | 706 +++++++++++++
59 drivers/staging/fsl-mc/include/dpaa2-global.h | 202 ++++
60 drivers/staging/fsl-mc/include/dpaa2-io.h | 190 ++++
61 drivers/staging/fsl-mc/include/dpbp-cmd.h | 185 ----
62 drivers/staging/fsl-mc/include/dpbp.h | 158 +--
63 drivers/staging/fsl-mc/include/dpcon.h | 115 +++
64 drivers/staging/fsl-mc/include/dpmng.h | 16 +-
65 drivers/staging/fsl-mc/include/dpopr.h | 110 ++
66 drivers/staging/fsl-mc/include/dprc.h | 470 +++------
67 drivers/staging/fsl-mc/include/mc-bus.h | 7 +-
68 drivers/staging/fsl-mc/include/mc-cmd.h | 44 +-
69 drivers/staging/fsl-mc/include/mc-sys.h | 3 +-
70 drivers/staging/fsl-mc/include/mc.h | 17 +-
71 49 files changed, 7384 insertions(+), 2612 deletions(-)
72 create mode 100644 drivers/staging/fsl-mc/bus/dpbp-cmd.h
73 create mode 100644 drivers/staging/fsl-mc/bus/dpcon-cmd.h
74 create mode 100644 drivers/staging/fsl-mc/bus/dpcon.c
75 create mode 100644 drivers/staging/fsl-mc/bus/dpio/Makefile
76 rename drivers/staging/fsl-mc/{include/dpcon-cmd.h => bus/dpio/dpio-cmd.h} (64%)
77 create mode 100644 drivers/staging/fsl-mc/bus/dpio/dpio-driver.c
78 create mode 100644 drivers/staging/fsl-mc/bus/dpio/dpio-driver.txt
79 create mode 100644 drivers/staging/fsl-mc/bus/dpio/dpio-service.c
80 create mode 100644 drivers/staging/fsl-mc/bus/dpio/dpio.c
81 create mode 100644 drivers/staging/fsl-mc/bus/dpio/dpio.h
82 create mode 100644 drivers/staging/fsl-mc/bus/dpio/qbman-portal.c
83 create mode 100644 drivers/staging/fsl-mc/bus/dpio/qbman-portal.h
84 create mode 100644 drivers/staging/fsl-mc/bus/dpio/qbman_debug.c
85 create mode 100644 drivers/staging/fsl-mc/bus/dpio/qbman_debug.h
86 create mode 100644 drivers/staging/fsl-mc/bus/dpio/qbman_private.h
87 create mode 100644 drivers/staging/fsl-mc/bus/fsl-mc-iommu.c
88 create mode 100644 drivers/staging/fsl-mc/bus/mc-ioctl.h
89 create mode 100644 drivers/staging/fsl-mc/bus/mc-restool.c
90 create mode 100644 drivers/staging/fsl-mc/include/dpaa2-fd.h
91 create mode 100644 drivers/staging/fsl-mc/include/dpaa2-global.h
92 create mode 100644 drivers/staging/fsl-mc/include/dpaa2-io.h
93 delete mode 100644 drivers/staging/fsl-mc/include/dpbp-cmd.h
94 create mode 100644 drivers/staging/fsl-mc/include/dpcon.h
95 create mode 100644 drivers/staging/fsl-mc/include/dpopr.h
97 diff --git a/drivers/staging/fsl-mc/bus/Kconfig b/drivers/staging/fsl-mc/bus/Kconfig
98 index 1f959339..67847c0e 100644
99 --- a/drivers/staging/fsl-mc/bus/Kconfig
100 +++ b/drivers/staging/fsl-mc/bus/Kconfig
103 -# Freescale Management Complex (MC) bus drivers
106 -# Copyright (C) 2014 Freescale Semiconductor, Inc.
107 +# Copyright (C) 2014-2016 Freescale Semiconductor, Inc.
109 # This file is released under the GPLv2
113 - bool "Freescale Management Complex (MC) bus driver"
114 - depends on OF && ARM64
115 + bool "QorIQ DPAA2 fsl-mc bus driver"
116 + depends on OF && ARCH_LAYERSCAPE
117 select GENERIC_MSI_IRQ_DOMAIN
119 - Driver to enable the bus infrastructure for the Freescale
120 - QorIQ Management Complex (fsl-mc). The fsl-mc is a hardware
121 - module of the QorIQ LS2 SoCs, that does resource management
122 - for hardware building-blocks in the SoC that can be used
123 - to dynamically create networking hardware objects such as
124 - network interfaces (NICs), crypto accelerator instances,
126 + Driver to enable the bus infrastructure for the QorIQ DPAA2
127 + architecture. The fsl-mc bus driver handles discovery of
128 + DPAA2 objects (which are represented as Linux devices) and
129 + binding objects to drivers.
131 - Only enable this option when building the kernel for
132 - Freescale QorQIQ LS2xxxx SoCs.
134 + tristate "QorIQ DPAA2 DPIO driver"
135 + depends on FSL_MC_BUS
137 + Driver for the DPAA2 DPIO object. A DPIO provides queue and
138 + buffer management facilities for software to interact with
139 + other DPAA2 objects. This driver does not expose the DPIO
140 + objects individually, but groups them under a service layer
143 +config FSL_QBMAN_DEBUG
144 + tristate "Freescale QBMAN Debug APIs"
145 + depends on FSL_MC_DPIO
147 + QBMan debug assistant APIs.
149 +config FSL_MC_RESTOOL
150 + tristate "Freescale Management Complex (MC) restool driver"
151 + depends on FSL_MC_BUS
153 + Driver that provides kernel support for the Freescale Management
154 + Complex resource manager user-space tool.
155 diff --git a/drivers/staging/fsl-mc/bus/Makefile b/drivers/staging/fsl-mc/bus/Makefile
156 index 38716fd5..e7e2239c 100644
157 --- a/drivers/staging/fsl-mc/bus/Makefile
158 +++ b/drivers/staging/fsl-mc/bus/Makefile
159 @@ -17,4 +17,12 @@ mc-bus-driver-objs := fsl-mc-bus.o \
161 irq-gic-v3-its-fsl-mc-msi.o \
169 +obj-$(CONFIG_FSL_MC_DPIO) += dpio/
171 +# MC restool kernel support
172 +obj-$(CONFIG_FSL_MC_RESTOOL) += mc-restool.o
173 diff --git a/drivers/staging/fsl-mc/bus/dpbp-cmd.h b/drivers/staging/fsl-mc/bus/dpbp-cmd.h
175 index 00000000..8aa65452
177 +++ b/drivers/staging/fsl-mc/bus/dpbp-cmd.h
180 + * Copyright 2013-2016 Freescale Semiconductor Inc.
182 + * Redistribution and use in source and binary forms, with or without
183 + * modification, are permitted provided that the following conditions are met:
184 + * * Redistributions of source code must retain the above copyright
185 + * notice, this list of conditions and the following disclaimer.
186 + * * Redistributions in binary form must reproduce the above copyright
187 + * notice, this list of conditions and the following disclaimer in the
188 + * documentation and/or other materials provided with the distribution.
189 + * * Neither the name of the above-listed copyright holders nor the
190 + * names of any contributors may be used to endorse or promote products
191 + * derived from this software without specific prior written permission.
193 + * ALTERNATIVELY, this software may be distributed under the terms of the
194 + * GNU General Public License ("GPL") as published by the Free Software
195 + * Foundation, either version 2 of that License or (at your option) any
198 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
199 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
200 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
201 + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
202 + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
203 + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
204 + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
205 + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
206 + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
207 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
208 + * POSSIBILITY OF SUCH DAMAGE.
210 +#ifndef _FSL_DPBP_CMD_H
211 +#define _FSL_DPBP_CMD_H
214 +#define DPBP_VER_MAJOR 3
215 +#define DPBP_VER_MINOR 2
217 +/* Command versioning */
218 +#define DPBP_CMD_BASE_VERSION 1
219 +#define DPBP_CMD_ID_OFFSET 4
221 +#define DPBP_CMD(id) ((id << DPBP_CMD_ID_OFFSET) | DPBP_CMD_BASE_VERSION)
224 +#define DPBP_CMDID_CLOSE DPBP_CMD(0x800)
225 +#define DPBP_CMDID_OPEN DPBP_CMD(0x804)
226 +#define DPBP_CMDID_GET_API_VERSION DPBP_CMD(0xa04)
228 +#define DPBP_CMDID_ENABLE DPBP_CMD(0x002)
229 +#define DPBP_CMDID_DISABLE DPBP_CMD(0x003)
230 +#define DPBP_CMDID_GET_ATTR DPBP_CMD(0x004)
231 +#define DPBP_CMDID_RESET DPBP_CMD(0x005)
232 +#define DPBP_CMDID_IS_ENABLED DPBP_CMD(0x006)
234 +struct dpbp_cmd_open {
238 +struct dpbp_cmd_destroy {
242 +#define DPBP_ENABLE 0x1
244 +struct dpbp_rsp_is_enabled {
248 +struct dpbp_rsp_get_attributes {
249 + /* response word 0 */
253 + /* response word 1 */
254 + __le16 version_major;
255 + __le16 version_minor;
258 +#endif /* _FSL_DPBP_CMD_H */
259 diff --git a/drivers/staging/fsl-mc/bus/dpbp.c b/drivers/staging/fsl-mc/bus/dpbp.c
260 index 5d4cd812..d9e450a6 100644
261 --- a/drivers/staging/fsl-mc/bus/dpbp.c
262 +++ b/drivers/staging/fsl-mc/bus/dpbp.c
264 -/* Copyright 2013-2016 Freescale Semiconductor Inc.
266 + * Copyright 2013-2016 Freescale Semiconductor Inc.
268 * Redistribution and use in source and binary forms, with or without
269 * modification, are permitted provided that the following conditions are met:
271 * names of any contributors may be used to endorse or promote products
272 * derived from this software without specific prior written permission.
275 * ALTERNATIVELY, this software may be distributed under the terms of the
276 * GNU General Public License ("GPL") as published by the Free Software
277 * Foundation, either version 2 of that License or (at your option) any
279 #include "../include/mc-sys.h"
280 #include "../include/mc-cmd.h"
281 #include "../include/dpbp.h"
282 -#include "../include/dpbp-cmd.h"
284 +#include "dpbp-cmd.h"
287 * dpbp_open() - Open a control session for the specified object.
288 @@ -104,74 +105,6 @@ int dpbp_close(struct fsl_mc_io *mc_io,
290 EXPORT_SYMBOL(dpbp_close);
293 - * dpbp_create() - Create the DPBP object.
294 - * @mc_io: Pointer to MC portal's I/O object
295 - * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
296 - * @cfg: Configuration structure
297 - * @token: Returned token; use in subsequent API calls
299 - * Create the DPBP object, allocate required resources and
300 - * perform required initialization.
302 - * The object can be created either by declaring it in the
303 - * DPL file, or by calling this function.
304 - * This function returns a unique authentication token,
305 - * associated with the specific object ID and the specific MC
306 - * portal; this token must be used in all subsequent calls to
307 - * this specific object. For objects that are created using the
308 - * DPL file, call dpbp_open function to get an authentication
311 - * Return: '0' on Success; Error code otherwise.
313 -int dpbp_create(struct fsl_mc_io *mc_io,
315 - const struct dpbp_cfg *cfg,
318 - struct mc_command cmd = { 0 };
321 - (void)(cfg); /* unused */
323 - /* prepare command */
324 - cmd.header = mc_encode_cmd_header(DPBP_CMDID_CREATE,
327 - /* send command to mc*/
328 - err = mc_send_command(mc_io, &cmd);
332 - /* retrieve response parameters */
333 - *token = mc_cmd_hdr_read_token(&cmd);
339 - * dpbp_destroy() - Destroy the DPBP object and release all its resources.
340 - * @mc_io: Pointer to MC portal's I/O object
341 - * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
342 - * @token: Token of DPBP object
344 - * Return: '0' on Success; error code otherwise.
346 -int dpbp_destroy(struct fsl_mc_io *mc_io,
350 - struct mc_command cmd = { 0 };
352 - /* prepare command */
353 - cmd.header = mc_encode_cmd_header(DPBP_CMDID_DESTROY,
356 - /* send command to mc*/
357 - return mc_send_command(mc_io, &cmd);
361 * dpbp_enable() - Enable the DPBP.
362 * @mc_io: Pointer to MC portal's I/O object
363 @@ -250,6 +183,7 @@ int dpbp_is_enabled(struct fsl_mc_io *mc_io,
367 +EXPORT_SYMBOL(dpbp_is_enabled);
370 * dpbp_reset() - Reset the DPBP, returns the object to initial state.
371 @@ -272,310 +206,7 @@ int dpbp_reset(struct fsl_mc_io *mc_io,
372 /* send command to mc*/
373 return mc_send_command(mc_io, &cmd);
377 - * dpbp_set_irq() - Set IRQ information for the DPBP to trigger an interrupt.
378 - * @mc_io: Pointer to MC portal's I/O object
379 - * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
380 - * @token: Token of DPBP object
381 - * @irq_index: Identifies the interrupt index to configure
382 - * @irq_cfg: IRQ configuration
384 - * Return: '0' on Success; Error code otherwise.
386 -int dpbp_set_irq(struct fsl_mc_io *mc_io,
390 - struct dpbp_irq_cfg *irq_cfg)
392 - struct mc_command cmd = { 0 };
393 - struct dpbp_cmd_set_irq *cmd_params;
395 - /* prepare command */
396 - cmd.header = mc_encode_cmd_header(DPBP_CMDID_SET_IRQ,
398 - cmd_params = (struct dpbp_cmd_set_irq *)cmd.params;
399 - cmd_params->irq_index = irq_index;
400 - cmd_params->irq_val = cpu_to_le32(irq_cfg->val);
401 - cmd_params->irq_addr = cpu_to_le64(irq_cfg->addr);
402 - cmd_params->irq_num = cpu_to_le32(irq_cfg->irq_num);
404 - /* send command to mc*/
405 - return mc_send_command(mc_io, &cmd);
409 - * dpbp_get_irq() - Get IRQ information from the DPBP.
410 - * @mc_io: Pointer to MC portal's I/O object
411 - * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
412 - * @token: Token of DPBP object
413 - * @irq_index: The interrupt index to configure
414 - * @type: Interrupt type: 0 represents message interrupt
415 - * type (both irq_addr and irq_val are valid)
416 - * @irq_cfg: IRQ attributes
418 - * Return: '0' on Success; Error code otherwise.
420 -int dpbp_get_irq(struct fsl_mc_io *mc_io,
425 - struct dpbp_irq_cfg *irq_cfg)
427 - struct mc_command cmd = { 0 };
428 - struct dpbp_cmd_get_irq *cmd_params;
429 - struct dpbp_rsp_get_irq *rsp_params;
432 - /* prepare command */
433 - cmd.header = mc_encode_cmd_header(DPBP_CMDID_GET_IRQ,
435 - cmd_params = (struct dpbp_cmd_get_irq *)cmd.params;
436 - cmd_params->irq_index = irq_index;
438 - /* send command to mc*/
439 - err = mc_send_command(mc_io, &cmd);
443 - /* retrieve response parameters */
444 - rsp_params = (struct dpbp_rsp_get_irq *)cmd.params;
445 - irq_cfg->val = le32_to_cpu(rsp_params->irq_val);
446 - irq_cfg->addr = le64_to_cpu(rsp_params->irq_addr);
447 - irq_cfg->irq_num = le32_to_cpu(rsp_params->irq_num);
448 - *type = le32_to_cpu(rsp_params->type);
454 - * dpbp_set_irq_enable() - Set overall interrupt state.
455 - * @mc_io: Pointer to MC portal's I/O object
456 - * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
457 - * @token: Token of DPBP object
458 - * @irq_index: The interrupt index to configure
459 - * @en: Interrupt state - enable = 1, disable = 0
461 - * Allows GPP software to control when interrupts are generated.
462 - * Each interrupt can have up to 32 causes. The enable/disable control's the
463 - * overall interrupt state. if the interrupt is disabled no causes will cause
466 - * Return: '0' on Success; Error code otherwise.
468 -int dpbp_set_irq_enable(struct fsl_mc_io *mc_io,
474 - struct mc_command cmd = { 0 };
475 - struct dpbp_cmd_set_irq_enable *cmd_params;
477 - /* prepare command */
478 - cmd.header = mc_encode_cmd_header(DPBP_CMDID_SET_IRQ_ENABLE,
480 - cmd_params = (struct dpbp_cmd_set_irq_enable *)cmd.params;
481 - cmd_params->enable = en & DPBP_ENABLE;
482 - cmd_params->irq_index = irq_index;
484 - /* send command to mc*/
485 - return mc_send_command(mc_io, &cmd);
489 - * dpbp_get_irq_enable() - Get overall interrupt state
490 - * @mc_io: Pointer to MC portal's I/O object
491 - * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
492 - * @token: Token of DPBP object
493 - * @irq_index: The interrupt index to configure
494 - * @en: Returned interrupt state - enable = 1, disable = 0
496 - * Return: '0' on Success; Error code otherwise.
498 -int dpbp_get_irq_enable(struct fsl_mc_io *mc_io,
504 - struct mc_command cmd = { 0 };
505 - struct dpbp_cmd_get_irq_enable *cmd_params;
506 - struct dpbp_rsp_get_irq_enable *rsp_params;
509 - /* prepare command */
510 - cmd.header = mc_encode_cmd_header(DPBP_CMDID_GET_IRQ_ENABLE,
512 - cmd_params = (struct dpbp_cmd_get_irq_enable *)cmd.params;
513 - cmd_params->irq_index = irq_index;
515 - /* send command to mc*/
516 - err = mc_send_command(mc_io, &cmd);
520 - /* retrieve response parameters */
521 - rsp_params = (struct dpbp_rsp_get_irq_enable *)cmd.params;
522 - *en = rsp_params->enabled & DPBP_ENABLE;
527 - * dpbp_set_irq_mask() - Set interrupt mask.
528 - * @mc_io: Pointer to MC portal's I/O object
529 - * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
530 - * @token: Token of DPBP object
531 - * @irq_index: The interrupt index to configure
532 - * @mask: Event mask to trigger interrupt;
535 - * 1 = consider event for asserting IRQ
537 - * Every interrupt can have up to 32 causes and the interrupt model supports
538 - * masking/unmasking each cause independently
540 - * Return: '0' on Success; Error code otherwise.
542 -int dpbp_set_irq_mask(struct fsl_mc_io *mc_io,
548 - struct mc_command cmd = { 0 };
549 - struct dpbp_cmd_set_irq_mask *cmd_params;
551 - /* prepare command */
552 - cmd.header = mc_encode_cmd_header(DPBP_CMDID_SET_IRQ_MASK,
554 - cmd_params = (struct dpbp_cmd_set_irq_mask *)cmd.params;
555 - cmd_params->mask = cpu_to_le32(mask);
556 - cmd_params->irq_index = irq_index;
558 - /* send command to mc*/
559 - return mc_send_command(mc_io, &cmd);
563 - * dpbp_get_irq_mask() - Get interrupt mask.
564 - * @mc_io: Pointer to MC portal's I/O object
565 - * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
566 - * @token: Token of DPBP object
567 - * @irq_index: The interrupt index to configure
568 - * @mask: Returned event mask to trigger interrupt
570 - * Every interrupt can have up to 32 causes and the interrupt model supports
571 - * masking/unmasking each cause independently
573 - * Return: '0' on Success; Error code otherwise.
575 -int dpbp_get_irq_mask(struct fsl_mc_io *mc_io,
581 - struct mc_command cmd = { 0 };
582 - struct dpbp_cmd_get_irq_mask *cmd_params;
583 - struct dpbp_rsp_get_irq_mask *rsp_params;
586 - /* prepare command */
587 - cmd.header = mc_encode_cmd_header(DPBP_CMDID_GET_IRQ_MASK,
589 - cmd_params = (struct dpbp_cmd_get_irq_mask *)cmd.params;
590 - cmd_params->irq_index = irq_index;
592 - /* send command to mc*/
593 - err = mc_send_command(mc_io, &cmd);
597 - /* retrieve response parameters */
598 - rsp_params = (struct dpbp_rsp_get_irq_mask *)cmd.params;
599 - *mask = le32_to_cpu(rsp_params->mask);
605 - * dpbp_get_irq_status() - Get the current status of any pending interrupts.
607 - * @mc_io: Pointer to MC portal's I/O object
608 - * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
609 - * @token: Token of DPBP object
610 - * @irq_index: The interrupt index to configure
611 - * @status: Returned interrupts status - one bit per cause:
612 - * 0 = no interrupt pending
613 - * 1 = interrupt pending
615 - * Return: '0' on Success; Error code otherwise.
617 -int dpbp_get_irq_status(struct fsl_mc_io *mc_io,
623 - struct mc_command cmd = { 0 };
624 - struct dpbp_cmd_get_irq_status *cmd_params;
625 - struct dpbp_rsp_get_irq_status *rsp_params;
628 - /* prepare command */
629 - cmd.header = mc_encode_cmd_header(DPBP_CMDID_GET_IRQ_STATUS,
631 - cmd_params = (struct dpbp_cmd_get_irq_status *)cmd.params;
632 - cmd_params->status = cpu_to_le32(*status);
633 - cmd_params->irq_index = irq_index;
635 - /* send command to mc*/
636 - err = mc_send_command(mc_io, &cmd);
640 - /* retrieve response parameters */
641 - rsp_params = (struct dpbp_rsp_get_irq_status *)cmd.params;
642 - *status = le32_to_cpu(rsp_params->status);
648 - * dpbp_clear_irq_status() - Clear a pending interrupt's status
650 - * @mc_io: Pointer to MC portal's I/O object
651 - * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
652 - * @token: Token of DPBP object
653 - * @irq_index: The interrupt index to configure
654 - * @status: Bits to clear (W1C) - one bit per cause:
656 - * 1 = clear status bit
658 - * Return: '0' on Success; Error code otherwise.
660 -int dpbp_clear_irq_status(struct fsl_mc_io *mc_io,
666 - struct mc_command cmd = { 0 };
667 - struct dpbp_cmd_clear_irq_status *cmd_params;
669 - /* prepare command */
670 - cmd.header = mc_encode_cmd_header(DPBP_CMDID_CLEAR_IRQ_STATUS,
672 - cmd_params = (struct dpbp_cmd_clear_irq_status *)cmd.params;
673 - cmd_params->status = cpu_to_le32(status);
674 - cmd_params->irq_index = irq_index;
676 - /* send command to mc*/
677 - return mc_send_command(mc_io, &cmd);
679 +EXPORT_SYMBOL(dpbp_reset);
682 * dpbp_get_attributes - Retrieve DPBP attributes.
683 @@ -609,83 +240,40 @@ int dpbp_get_attributes(struct fsl_mc_io *mc_io,
684 rsp_params = (struct dpbp_rsp_get_attributes *)cmd.params;
685 attr->bpid = le16_to_cpu(rsp_params->bpid);
686 attr->id = le32_to_cpu(rsp_params->id);
687 - attr->version.major = le16_to_cpu(rsp_params->version_major);
688 - attr->version.minor = le16_to_cpu(rsp_params->version_minor);
692 EXPORT_SYMBOL(dpbp_get_attributes);
695 - * dpbp_set_notifications() - Set notifications towards software
696 - * @mc_io: Pointer to MC portal's I/O object
697 + * dpbp_get_api_version - Get Data Path Buffer Pool API version
698 + * @mc_io: Pointer to Mc portal's I/O object
699 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
700 - * @token: Token of DPBP object
701 - * @cfg: notifications configuration
702 + * @major_ver: Major version of Buffer Pool API
703 + * @minor_ver: Minor version of Buffer Pool API
705 * Return: '0' on Success; Error code otherwise.
707 -int dpbp_set_notifications(struct fsl_mc_io *mc_io,
710 - struct dpbp_notification_cfg *cfg)
711 +int dpbp_get_api_version(struct fsl_mc_io *mc_io,
716 struct mc_command cmd = { 0 };
717 - struct dpbp_cmd_set_notifications *cmd_params;
719 - /* prepare command */
720 - cmd.header = mc_encode_cmd_header(DPBP_CMDID_SET_NOTIFICATIONS,
722 - cmd_params = (struct dpbp_cmd_set_notifications *)cmd.params;
723 - cmd_params->depletion_entry = cpu_to_le32(cfg->depletion_entry);
724 - cmd_params->depletion_exit = cpu_to_le32(cfg->depletion_exit);
725 - cmd_params->surplus_entry = cpu_to_le32(cfg->surplus_entry);
726 - cmd_params->surplus_exit = cpu_to_le32(cfg->surplus_exit);
727 - cmd_params->options = cpu_to_le16(cfg->options);
728 - cmd_params->message_ctx = cpu_to_le64(cfg->message_ctx);
729 - cmd_params->message_iova = cpu_to_le64(cfg->message_iova);
731 - /* send command to mc*/
732 - return mc_send_command(mc_io, &cmd);
736 - * dpbp_get_notifications() - Get the notifications configuration
737 - * @mc_io: Pointer to MC portal's I/O object
738 - * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
739 - * @token: Token of DPBP object
740 - * @cfg: notifications configuration
742 - * Return: '0' on Success; Error code otherwise.
744 -int dpbp_get_notifications(struct fsl_mc_io *mc_io,
747 - struct dpbp_notification_cfg *cfg)
749 - struct mc_command cmd = { 0 };
750 - struct dpbp_rsp_get_notifications *rsp_params;
753 /* prepare command */
754 - cmd.header = mc_encode_cmd_header(DPBP_CMDID_GET_NOTIFICATIONS,
757 + cmd.header = mc_encode_cmd_header(DPBP_CMDID_GET_API_VERSION,
760 - /* send command to mc*/
761 + /* send command to mc */
762 err = mc_send_command(mc_io, &cmd);
766 /* retrieve response parameters */
767 - rsp_params = (struct dpbp_rsp_get_notifications *)cmd.params;
768 - cfg->depletion_entry = le32_to_cpu(rsp_params->depletion_entry);
769 - cfg->depletion_exit = le32_to_cpu(rsp_params->depletion_exit);
770 - cfg->surplus_entry = le32_to_cpu(rsp_params->surplus_entry);
771 - cfg->surplus_exit = le32_to_cpu(rsp_params->surplus_exit);
772 - cfg->options = le16_to_cpu(rsp_params->options);
773 - cfg->message_ctx = le64_to_cpu(rsp_params->message_ctx);
774 - cfg->message_iova = le64_to_cpu(rsp_params->message_iova);
775 + mc_cmd_read_api_version(&cmd, major_ver, minor_ver);
779 +EXPORT_SYMBOL(dpbp_get_api_version);
780 diff --git a/drivers/staging/fsl-mc/bus/dpcon-cmd.h b/drivers/staging/fsl-mc/bus/dpcon-cmd.h
782 index 00000000..2bb66988
784 +++ b/drivers/staging/fsl-mc/bus/dpcon-cmd.h
787 + * Copyright 2013-2016 Freescale Semiconductor Inc.
789 + * Redistribution and use in source and binary forms, with or without
790 + * modification, are permitted provided that the following conditions are met:
791 + * * Redistributions of source code must retain the above copyright
792 + * notice, this list of conditions and the following disclaimer.
793 + * * Redistributions in binary form must reproduce the above copyright
794 + * notice, this list of conditions and the following disclaimer in the
795 + * documentation and/or other materials provided with the distribution.
796 + * * Neither the name of the above-listed copyright holders nor the
797 + * names of any contributors may be used to endorse or promote products
798 + * derived from this software without specific prior written permission.
800 + * ALTERNATIVELY, this software may be distributed under the terms of the
801 + * GNU General Public License ("GPL") as published by the Free Software
802 + * Foundation, either version 2 of that License or (at your option) any
805 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
806 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
807 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
808 + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
809 + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
810 + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
811 + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
812 + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
813 + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
814 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
815 + * POSSIBILITY OF SUCH DAMAGE.
817 +#ifndef _FSL_DPCON_CMD_H
818 +#define _FSL_DPCON_CMD_H
821 +#define DPCON_VER_MAJOR 3
822 +#define DPCON_VER_MINOR 2
824 +/* Command versioning */
825 +#define DPCON_CMD_BASE_VERSION 1
826 +#define DPCON_CMD_ID_OFFSET 4
828 +#define DPCON_CMD(id) (((id) << DPCON_CMD_ID_OFFSET) | DPCON_CMD_BASE_VERSION)
831 +#define DPCON_CMDID_CLOSE DPCON_CMD(0x800)
832 +#define DPCON_CMDID_OPEN DPCON_CMD(0x808)
833 +#define DPCON_CMDID_GET_API_VERSION DPCON_CMD(0xa08)
835 +#define DPCON_CMDID_ENABLE DPCON_CMD(0x002)
836 +#define DPCON_CMDID_DISABLE DPCON_CMD(0x003)
837 +#define DPCON_CMDID_GET_ATTR DPCON_CMD(0x004)
838 +#define DPCON_CMDID_RESET DPCON_CMD(0x005)
839 +#define DPCON_CMDID_IS_ENABLED DPCON_CMD(0x006)
841 +#define DPCON_CMDID_SET_NOTIFICATION DPCON_CMD(0x100)
843 +struct dpcon_cmd_open {
847 +#define DPCON_ENABLE 1
849 +struct dpcon_rsp_is_enabled {
853 +struct dpcon_rsp_get_attr {
854 + /* response word 0 */
856 + __le16 qbman_ch_id;
861 +struct dpcon_cmd_set_notification {
870 +#endif /* _FSL_DPCON_CMD_H */
871 diff --git a/drivers/staging/fsl-mc/bus/dpcon.c b/drivers/staging/fsl-mc/bus/dpcon.c
873 index 00000000..eb713578
875 +++ b/drivers/staging/fsl-mc/bus/dpcon.c
877 +/* Copyright 2013-2016 Freescale Semiconductor Inc.
879 + * Redistribution and use in source and binary forms, with or without
880 + * modification, are permitted provided that the following conditions are met:
881 + * * Redistributions of source code must retain the above copyright
882 + * notice, this list of conditions and the following disclaimer.
883 + * * Redistributions in binary form must reproduce the above copyright
884 + * notice, this list of conditions and the following disclaimer in the
885 + * documentation and/or other materials provided with the distribution.
886 + * * Neither the name of the above-listed copyright holders nor the
887 + * names of any contributors may be used to endorse or promote products
888 + * derived from this software without specific prior written permission.
891 + * ALTERNATIVELY, this software may be distributed under the terms of the
892 + * GNU General Public License ("GPL") as published by the Free Software
893 + * Foundation, either version 2 of that License or (at your option) any
896 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
897 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
898 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
899 + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
900 + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
901 + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
902 + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
903 + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
904 + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
905 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
906 + * POSSIBILITY OF SUCH DAMAGE.
908 +#include "../include/mc-sys.h"
909 +#include "../include/mc-cmd.h"
910 +#include "../include/dpcon.h"
912 +#include "dpcon-cmd.h"
915 + * dpcon_open() - Open a control session for the specified object
916 + * @mc_io: Pointer to MC portal's I/O object
917 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
918 + * @dpcon_id: DPCON unique ID
919 + * @token: Returned token; use in subsequent API calls
921 + * This function can be used to open a control session for an
922 + * already created object; an object may have been declared in
923 + * the DPL or by calling the dpcon_create() function.
924 + * This function returns a unique authentication token,
925 + * associated with the specific object ID and the specific MC
926 + * portal; this token must be used in all subsequent commands for
927 + * this specific object.
929 + * Return: '0' on Success; Error code otherwise.
931 +int dpcon_open(struct fsl_mc_io *mc_io,
936 + struct mc_command cmd = { 0 };
937 + struct dpcon_cmd_open *dpcon_cmd;
940 + /* prepare command */
941 + cmd.header = mc_encode_cmd_header(DPCON_CMDID_OPEN,
944 + dpcon_cmd = (struct dpcon_cmd_open *)cmd.params;
945 + dpcon_cmd->dpcon_id = cpu_to_le32(dpcon_id);
947 + /* send command to mc*/
948 + err = mc_send_command(mc_io, &cmd);
952 + /* retrieve response parameters */
953 + *token = mc_cmd_hdr_read_token(&cmd);
957 +EXPORT_SYMBOL(dpcon_open);
960 + * dpcon_close() - Close the control session of the object
961 + * @mc_io: Pointer to MC portal's I/O object
962 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
963 + * @token: Token of DPCON object
965 + * After this function is called, no further operations are
966 + * allowed on the object without opening a new control session.
968 + * Return: '0' on Success; Error code otherwise.
970 +int dpcon_close(struct fsl_mc_io *mc_io,
974 + struct mc_command cmd = { 0 };
976 + /* prepare command */
977 + cmd.header = mc_encode_cmd_header(DPCON_CMDID_CLOSE,
981 + /* send command to mc*/
982 + return mc_send_command(mc_io, &cmd);
984 +EXPORT_SYMBOL(dpcon_close);
987 + * dpcon_enable() - Enable the DPCON
988 + * @mc_io: Pointer to MC portal's I/O object
989 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
990 + * @token: Token of DPCON object
992 + * Return: '0' on Success; Error code otherwise
994 +int dpcon_enable(struct fsl_mc_io *mc_io,
998 + struct mc_command cmd = { 0 };
1000 + /* prepare command */
1001 + cmd.header = mc_encode_cmd_header(DPCON_CMDID_ENABLE,
1005 + /* send command to mc*/
1006 + return mc_send_command(mc_io, &cmd);
1008 +EXPORT_SYMBOL(dpcon_enable);
1011 + * dpcon_disable() - Disable the DPCON
1012 + * @mc_io: Pointer to MC portal's I/O object
1013 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1014 + * @token: Token of DPCON object
1016 + * Return: '0' on Success; Error code otherwise
1018 +int dpcon_disable(struct fsl_mc_io *mc_io,
1022 + struct mc_command cmd = { 0 };
1024 + /* prepare command */
1025 + cmd.header = mc_encode_cmd_header(DPCON_CMDID_DISABLE,
1029 + /* send command to mc*/
1030 + return mc_send_command(mc_io, &cmd);
1032 +EXPORT_SYMBOL(dpcon_disable);
1035 + * dpcon_is_enabled() - Check if the DPCON is enabled.
1036 + * @mc_io: Pointer to MC portal's I/O object
1037 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1038 + * @token: Token of DPCON object
1039 + * @en: Returns '1' if object is enabled; '0' otherwise
1041 + * Return: '0' on Success; Error code otherwise.
1043 +int dpcon_is_enabled(struct fsl_mc_io *mc_io,
1048 + struct mc_command cmd = { 0 };
1049 + struct dpcon_rsp_is_enabled *dpcon_rsp;
1052 + /* prepare command */
1053 + cmd.header = mc_encode_cmd_header(DPCON_CMDID_IS_ENABLED,
1057 + /* send command to mc*/
1058 + err = mc_send_command(mc_io, &cmd);
1062 + /* retrieve response parameters */
1063 + dpcon_rsp = (struct dpcon_rsp_is_enabled *)cmd.params;
1064 + *en = dpcon_rsp->enabled & DPCON_ENABLE;
1068 +EXPORT_SYMBOL(dpcon_is_enabled);
1071 + * dpcon_reset() - Reset the DPCON, returns the object to initial state.
1072 + * @mc_io: Pointer to MC portal's I/O object
1073 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1074 + * @token: Token of DPCON object
1076 + * Return: '0' on Success; Error code otherwise.
1078 +int dpcon_reset(struct fsl_mc_io *mc_io,
1082 + struct mc_command cmd = { 0 };
1084 + /* prepare command */
1085 + cmd.header = mc_encode_cmd_header(DPCON_CMDID_RESET,
1086 + cmd_flags, token);
1088 + /* send command to mc*/
1089 + return mc_send_command(mc_io, &cmd);
1091 +EXPORT_SYMBOL(dpcon_reset);
1094 + * dpcon_get_attributes() - Retrieve DPCON attributes.
1095 + * @mc_io: Pointer to MC portal's I/O object
1096 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1097 + * @token: Token of DPCON object
1098 + * @attr: Object's attributes
1100 + * Return: '0' on Success; Error code otherwise.
1102 +int dpcon_get_attributes(struct fsl_mc_io *mc_io,
1105 + struct dpcon_attr *attr)
1107 + struct mc_command cmd = { 0 };
1108 + struct dpcon_rsp_get_attr *dpcon_rsp;
1111 + /* prepare command */
1112 + cmd.header = mc_encode_cmd_header(DPCON_CMDID_GET_ATTR,
1116 + /* send command to mc*/
1117 + err = mc_send_command(mc_io, &cmd);
1121 + /* retrieve response parameters */
1122 + dpcon_rsp = (struct dpcon_rsp_get_attr *)cmd.params;
1123 + attr->id = le32_to_cpu(dpcon_rsp->id);
1124 + attr->qbman_ch_id = le16_to_cpu(dpcon_rsp->qbman_ch_id);
1125 + attr->num_priorities = dpcon_rsp->num_priorities;
1129 +EXPORT_SYMBOL(dpcon_get_attributes);
1132 + * dpcon_set_notification() - Set DPCON notification destination
1133 + * @mc_io: Pointer to MC portal's I/O object
1134 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1135 + * @token: Token of DPCON object
1136 + * @cfg: Notification parameters
1138 + * Return: '0' on Success; Error code otherwise
1140 +int dpcon_set_notification(struct fsl_mc_io *mc_io,
1143 + struct dpcon_notification_cfg *cfg)
1145 + struct mc_command cmd = { 0 };
1146 + struct dpcon_cmd_set_notification *dpcon_cmd;
1148 + /* prepare command */
1149 + cmd.header = mc_encode_cmd_header(DPCON_CMDID_SET_NOTIFICATION,
1152 + dpcon_cmd = (struct dpcon_cmd_set_notification *)cmd.params;
1153 + dpcon_cmd->dpio_id = cpu_to_le32(cfg->dpio_id);
1154 + dpcon_cmd->priority = cfg->priority;
1155 + dpcon_cmd->user_ctx = cpu_to_le64(cfg->user_ctx);
1157 + /* send command to mc*/
1158 + return mc_send_command(mc_io, &cmd);
1160 +EXPORT_SYMBOL(dpcon_set_notification);
1163 + * dpcon_get_api_version - Get Data Path Concentrator API version
1164 + * @mc_io: Pointer to MC portal's DPCON object
1165 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1166 + * @major_ver: Major version of DPCON API
1167 + * @minor_ver: Minor version of DPCON API
1169 + * Return: '0' on Success; Error code otherwise
1171 +int dpcon_get_api_version(struct fsl_mc_io *mc_io,
1176 + struct mc_command cmd = { 0 };
1179 + /* prepare command */
1180 + cmd.header = mc_encode_cmd_header(DPCON_CMDID_GET_API_VERSION,
1183 + /* send command to mc */
1184 + err = mc_send_command(mc_io, &cmd);
1188 + /* retrieve response parameters */
1189 + mc_cmd_read_api_version(&cmd, major_ver, minor_ver);
1193 +EXPORT_SYMBOL(dpcon_get_api_version);
1194 diff --git a/drivers/staging/fsl-mc/bus/dpio/Makefile b/drivers/staging/fsl-mc/bus/dpio/Makefile
1195 new file mode 100644
1196 index 00000000..1c28794e
1198 +++ b/drivers/staging/fsl-mc/bus/dpio/Makefile
1201 +# QorIQ DPAA2 DPIO driver
1204 +subdir-ccflags-y := -Werror
1206 +obj-$(CONFIG_FSL_MC_DPIO) += fsl-mc-dpio.o
1208 +fsl-mc-dpio-objs := dpio.o qbman-portal.o dpio-service.o dpio-driver.o
1210 +obj-$(CONFIG_FSL_QBMAN_DEBUG) += qbman_debug.o
1211 diff --git a/drivers/staging/fsl-mc/include/dpcon-cmd.h b/drivers/staging/fsl-mc/bus/dpio/dpio-cmd.h
1212 similarity index 64%
1213 rename from drivers/staging/fsl-mc/include/dpcon-cmd.h
1214 rename to drivers/staging/fsl-mc/bus/dpio/dpio-cmd.h
1215 index 536b2ef1..b2dc6e76 100644
1216 --- a/drivers/staging/fsl-mc/include/dpcon-cmd.h
1217 +++ b/drivers/staging/fsl-mc/bus/dpio/dpio-cmd.h
1219 -/* Copyright 2013-2015 Freescale Semiconductor Inc.
1221 + * Copyright 2013-2016 Freescale Semiconductor Inc.
1222 + * Copyright 2016 NXP
1224 * Redistribution and use in source and binary forms, with or without
1225 * modification, are permitted provided that the following conditions are met:
1227 * names of any contributors may be used to endorse or promote products
1228 * derived from this software without specific prior written permission.
1231 * ALTERNATIVELY, this software may be distributed under the terms of the
1232 * GNU General Public License ("GPL") as published by the Free Software
1233 * Foundation, either version 2 of that License or (at your option) any
1235 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
1236 * POSSIBILITY OF SUCH DAMAGE.
1238 -#ifndef _FSL_DPCON_CMD_H
1239 -#define _FSL_DPCON_CMD_H
1240 +#ifndef _FSL_DPIO_CMD_H
1241 +#define _FSL_DPIO_CMD_H
1244 +#define DPIO_VER_MAJOR 4
1245 +#define DPIO_VER_MINOR 2
1247 +/* Command Versioning */
1249 +#define DPIO_CMD_ID_OFFSET 4
1250 +#define DPIO_CMD_BASE_VERSION 1
1252 -/* DPCON Version */
1253 -#define DPCON_VER_MAJOR 2
1254 -#define DPCON_VER_MINOR 1
1255 +#define DPIO_CMD(id) (((id) << DPIO_CMD_ID_OFFSET) | DPIO_CMD_BASE_VERSION)
1258 -#define DPCON_CMDID_CLOSE 0x800
1259 -#define DPCON_CMDID_OPEN 0x808
1260 -#define DPCON_CMDID_CREATE 0x908
1261 -#define DPCON_CMDID_DESTROY 0x900
1263 -#define DPCON_CMDID_ENABLE 0x002
1264 -#define DPCON_CMDID_DISABLE 0x003
1265 -#define DPCON_CMDID_GET_ATTR 0x004
1266 -#define DPCON_CMDID_RESET 0x005
1267 -#define DPCON_CMDID_IS_ENABLED 0x006
1269 -#define DPCON_CMDID_SET_IRQ 0x010
1270 -#define DPCON_CMDID_GET_IRQ 0x011
1271 -#define DPCON_CMDID_SET_IRQ_ENABLE 0x012
1272 -#define DPCON_CMDID_GET_IRQ_ENABLE 0x013
1273 -#define DPCON_CMDID_SET_IRQ_MASK 0x014
1274 -#define DPCON_CMDID_GET_IRQ_MASK 0x015
1275 -#define DPCON_CMDID_GET_IRQ_STATUS 0x016
1276 -#define DPCON_CMDID_CLEAR_IRQ_STATUS 0x017
1278 -#define DPCON_CMDID_SET_NOTIFICATION 0x100
1280 -#endif /* _FSL_DPCON_CMD_H */
1281 +#define DPIO_CMDID_CLOSE DPIO_CMD(0x800)
1282 +#define DPIO_CMDID_OPEN DPIO_CMD(0x803)
1283 +#define DPIO_CMDID_GET_API_VERSION DPIO_CMD(0xa03)
1284 +#define DPIO_CMDID_ENABLE DPIO_CMD(0x002)
1285 +#define DPIO_CMDID_DISABLE DPIO_CMD(0x003)
1286 +#define DPIO_CMDID_GET_ATTR DPIO_CMD(0x004)
1288 +struct dpio_cmd_open {
1292 +#define DPIO_CHANNEL_MODE_MASK 0x3
1294 +struct dpio_rsp_get_attr {
1297 + __le16 qbman_portal_id;
1298 + u8 num_priorities;
1301 + __le64 qbman_portal_ce_addr;
1303 + __le64 qbman_portal_ci_addr;
1305 + __le32 qbman_version;
1308 +#endif /* _FSL_DPIO_CMD_H */
1309 diff --git a/drivers/staging/fsl-mc/bus/dpio/dpio-driver.c b/drivers/staging/fsl-mc/bus/dpio/dpio-driver.c
1310 new file mode 100644
1311 index 00000000..8c8244a1
1313 +++ b/drivers/staging/fsl-mc/bus/dpio/dpio-driver.c
1316 + * Copyright 2014-2016 Freescale Semiconductor Inc.
1317 + * Copyright 2016 NXP
1319 + * Redistribution and use in source and binary forms, with or without
1320 + * modification, are permitted provided that the following conditions are met:
1321 + * * Redistributions of source code must retain the above copyright
1322 + * notice, this list of conditions and the following disclaimer.
1323 + * * Redistributions in binary form must reproduce the above copyright
1324 + * notice, this list of conditions and the following disclaimer in the
1325 + * documentation and/or other materials provided with the distribution.
1326 + * * Neither the name of Freescale Semiconductor nor the
1327 + * names of its contributors may be used to endorse or promote products
1328 + * derived from this software without specific prior written permission.
1330 + * ALTERNATIVELY, this software may be distributed under the terms of the
1331 + * GNU General Public License ("GPL") as published by the Free Software
1332 + * Foundation, either version 2 of that License or (at your option) any
1335 + * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
1336 + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
1337 + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
1338 + * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
1339 + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
1340 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
1341 + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
1342 + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
1343 + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
1344 + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1347 +#include <linux/types.h>
1348 +#include <linux/init.h>
1349 +#include <linux/module.h>
1350 +#include <linux/platform_device.h>
1351 +#include <linux/interrupt.h>
1352 +#include <linux/msi.h>
1353 +#include <linux/dma-mapping.h>
1354 +#include <linux/delay.h>
1356 +#include "../../include/mc.h"
1357 +#include "../../include/dpaa2-io.h"
1359 +#include "qbman-portal.h"
1361 +#include "dpio-cmd.h"
1363 +MODULE_LICENSE("Dual BSD/GPL");
1364 +MODULE_AUTHOR("Freescale Semiconductor, Inc");
1365 +MODULE_DESCRIPTION("DPIO Driver");
1368 + struct dpaa2_io *io;
1371 +static irqreturn_t dpio_irq_handler(int irq_num, void *arg)
1373 + struct device *dev = (struct device *)arg;
1374 + struct dpio_priv *priv = dev_get_drvdata(dev);
1376 + return dpaa2_io_irq(priv->io);
1379 +static void unregister_dpio_irq_handlers(struct fsl_mc_device *dpio_dev)
1381 + struct fsl_mc_device_irq *irq;
1383 + irq = dpio_dev->irqs[0];
1385 + /* clear the affinity hint */
1386 + irq_set_affinity_hint(irq->msi_desc->irq, NULL);
1389 +static int register_dpio_irq_handlers(struct fsl_mc_device *dpio_dev, int cpu)
1391 + struct dpio_priv *priv;
1393 + struct fsl_mc_device_irq *irq;
1396 + priv = dev_get_drvdata(&dpio_dev->dev);
1398 + irq = dpio_dev->irqs[0];
1399 + error = devm_request_irq(&dpio_dev->dev,
1400 + irq->msi_desc->irq,
1403 + dev_name(&dpio_dev->dev),
1406 + dev_err(&dpio_dev->dev,
1407 + "devm_request_irq() failed: %d\n",
1412 + /* set the affinity hint */
1413 + cpumask_clear(&mask);
1414 + cpumask_set_cpu(cpu, &mask);
1415 + if (irq_set_affinity_hint(irq->msi_desc->irq, &mask))
1416 + dev_err(&dpio_dev->dev,
1417 + "irq_set_affinity failed irq %d cpu %d\n",
1418 + irq->msi_desc->irq, cpu);
1423 +static int dpaa2_dpio_probe(struct fsl_mc_device *dpio_dev)
1425 + struct dpio_attr dpio_attrs;
1426 + struct dpaa2_io_desc desc;
1427 + struct dpio_priv *priv;
1428 + int err = -ENOMEM;
1429 + struct device *dev = &dpio_dev->dev;
1430 + static int next_cpu = -1;
1432 + priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
1434 + goto err_priv_alloc;
1436 + dev_set_drvdata(dev, priv);
1438 + err = fsl_mc_portal_allocate(dpio_dev, 0, &dpio_dev->mc_io);
1440 + dev_dbg(dev, "MC portal allocation failed\n");
1441 + err = -EPROBE_DEFER;
1442 + goto err_mcportal;
1445 + err = dpio_open(dpio_dev->mc_io, 0, dpio_dev->obj_desc.id,
1446 + &dpio_dev->mc_handle);
1448 + dev_err(dev, "dpio_open() failed\n");
1452 + err = dpio_get_attributes(dpio_dev->mc_io, 0, dpio_dev->mc_handle,
1455 + dev_err(dev, "dpio_get_attributes() failed %d\n", err);
1456 + goto err_get_attr;
1458 + desc.qman_version = dpio_attrs.qbman_version;
1460 + err = dpio_enable(dpio_dev->mc_io, 0, dpio_dev->mc_handle);
1462 + dev_err(dev, "dpio_enable() failed %d\n", err);
1463 + goto err_get_attr;
1466 + /* initialize DPIO descriptor */
1467 + desc.receives_notifications = dpio_attrs.num_priorities ? 1 : 0;
1468 + desc.has_8prio = dpio_attrs.num_priorities == 8 ? 1 : 0;
1469 + desc.dpio_id = dpio_dev->obj_desc.id;
1471 + /* get the cpu to use for the affinity hint */
1472 + if (next_cpu == -1)
1473 + next_cpu = cpumask_first(cpu_online_mask);
1475 + next_cpu = cpumask_next(next_cpu, cpu_online_mask);
1477 + if (!cpu_possible(next_cpu)) {
1478 + dev_err(dev, "probe failed. Number of DPIOs exceeds NR_CPUS.\n");
1480 + goto err_allocate_irqs;
1482 + desc.cpu = next_cpu;
1485 + * Set the CENA regs to be the cache enabled area of the portal to
1486 + * achieve the best performance.
1488 + desc.regs_cena = ioremap_cache_ns(dpio_dev->regions[0].start,
1489 + resource_size(&dpio_dev->regions[0]));
1490 + desc.regs_cinh = ioremap(dpio_dev->regions[1].start,
1491 + resource_size(&dpio_dev->regions[1]));
1493 + err = fsl_mc_allocate_irqs(dpio_dev);
1495 + dev_err(dev, "fsl_mc_allocate_irqs failed. err=%d\n", err);
1496 + goto err_allocate_irqs;
1499 + err = register_dpio_irq_handlers(dpio_dev, desc.cpu);
1501 + goto err_register_dpio_irq;
1503 + priv->io = dpaa2_io_create(&desc);
1505 + dev_err(dev, "dpaa2_io_create failed\n");
1506 + goto err_dpaa2_io_create;
1509 + dev_info(dev, "probed\n");
1510 + dev_dbg(dev, " receives_notifications = %d\n",
1511 + desc.receives_notifications);
1512 + dpio_close(dpio_dev->mc_io, 0, dpio_dev->mc_handle);
1513 + fsl_mc_portal_free(dpio_dev->mc_io);
1517 +err_dpaa2_io_create:
1518 + unregister_dpio_irq_handlers(dpio_dev);
1519 +err_register_dpio_irq:
1520 + fsl_mc_free_irqs(dpio_dev);
1522 + dpio_disable(dpio_dev->mc_io, 0, dpio_dev->mc_handle);
1524 + dpio_close(dpio_dev->mc_io, 0, dpio_dev->mc_handle);
1526 + fsl_mc_portal_free(dpio_dev->mc_io);
1528 + dev_set_drvdata(dev, NULL);
1533 +/* Tear down interrupts for a given DPIO object */
1534 +static void dpio_teardown_irqs(struct fsl_mc_device *dpio_dev)
1536 + unregister_dpio_irq_handlers(dpio_dev);
1537 + fsl_mc_free_irqs(dpio_dev);
1540 +static int dpaa2_dpio_remove(struct fsl_mc_device *dpio_dev)
1542 + struct device *dev;
1543 + struct dpio_priv *priv;
1546 + dev = &dpio_dev->dev;
1547 + priv = dev_get_drvdata(dev);
1549 + dpaa2_io_down(priv->io);
1551 + dpio_teardown_irqs(dpio_dev);
1553 + err = fsl_mc_portal_allocate(dpio_dev, 0, &dpio_dev->mc_io);
1555 + dev_err(dev, "MC portal allocation failed\n");
1556 + goto err_mcportal;
1559 + err = dpio_open(dpio_dev->mc_io, 0, dpio_dev->obj_desc.id,
1560 + &dpio_dev->mc_handle);
1562 + dev_err(dev, "dpio_open() failed\n");
1566 + dpio_disable(dpio_dev->mc_io, 0, dpio_dev->mc_handle);
1568 + dpio_close(dpio_dev->mc_io, 0, dpio_dev->mc_handle);
1570 + fsl_mc_portal_free(dpio_dev->mc_io);
1572 + dev_set_drvdata(dev, NULL);
1577 + fsl_mc_portal_free(dpio_dev->mc_io);
1582 +static const struct fsl_mc_device_id dpaa2_dpio_match_id_table[] = {
1584 + .vendor = FSL_MC_VENDOR_FREESCALE,
1585 + .obj_type = "dpio",
1590 +static struct fsl_mc_driver dpaa2_dpio_driver = {
1592 + .name = KBUILD_MODNAME,
1593 + .owner = THIS_MODULE,
1595 + .probe = dpaa2_dpio_probe,
1596 + .remove = dpaa2_dpio_remove,
1597 + .match_id_table = dpaa2_dpio_match_id_table
1600 +static int dpio_driver_init(void)
1602 + return fsl_mc_driver_register(&dpaa2_dpio_driver);
1605 +static void dpio_driver_exit(void)
1607 + fsl_mc_driver_unregister(&dpaa2_dpio_driver);
1609 +module_init(dpio_driver_init);
1610 +module_exit(dpio_driver_exit);
1611 diff --git a/drivers/staging/fsl-mc/bus/dpio/dpio-driver.txt b/drivers/staging/fsl-mc/bus/dpio/dpio-driver.txt
1612 new file mode 100644
1613 index 00000000..0ba67716
1615 +++ b/drivers/staging/fsl-mc/bus/dpio/dpio-driver.txt
1622 +A DPAA2 DPIO (Data Path I/O) is a hardware object that provides
1623 +interfaces to enqueue and dequeue frames to/from network interfaces
1624 +and other accelerators. A DPIO also provides hardware buffer
1625 +pool management for network interfaces.
1627 +This document provides an overview the Linux DPIO driver, its
1628 +subcomponents, and its APIs.
1630 +See Documentation/dpaa2/overview.txt for a general overview of DPAA2
1631 +and the general DPAA2 driver architecture in Linux.
1636 +The DPIO driver is bound to DPIO objects discovered on the fsl-mc bus and
1637 +provides services that:
1638 + A) allow other drivers, such as the Ethernet driver, to enqueue and dequeue
1639 + frames for their respective objects
1640 + B) allow drivers to register callbacks for data availability notifications
1641 + when data becomes available on a queue or channel
1642 + C) allow drivers to manage hardware buffer pools
1644 +The Linux DPIO driver consists of 3 primary components--
1645 + DPIO object driver-- fsl-mc driver that manages the DPIO object
1646 + DPIO service-- provides APIs to other Linux drivers for services
1647 + QBman portal interface-- sends portal commands, gets responses
1652 + +---+----+ +------+-----+
1653 + |DPIO obj| |DPIO service|
1654 + | driver |---| (DPIO) |
1655 + +--------+ +------+-----+
1664 +The diagram below shows how the DPIO driver components fit with the other
1665 +DPAA2 Linux driver components:
1669 + +------------+ +------------+
1670 + | Allocator |. . . . . . . | Ethernet |
1671 + |(DPMCP,DPBP)| | (DPNI) |
1672 + +-.----------+ +---+---+----+
1674 + . . <data avail, | |<enqueue,
1675 + . . tx confirm> | | dequeue>
1676 + +-------------+ . | |
1677 + | DPRC driver | . +--------+ +------------+
1678 + | (DPRC) | . . |DPIO obj| |DPIO service|
1679 + +----------+--+ | driver |-| (DPIO) |
1680 + | +--------+ +------+-----+
1681 + |<dev add/remove> +------|-----+
1683 + +----+--------------+ | portal i/f |
1684 + | MC-bus driver | +------------+
1687 + +-------------------+ |
1689 + =========================================|=========|========================
1690 + +-+--DPIO---|-----------+
1693 + +-----------------------+
1695 + ============================================================================
1698 +DPIO Object Driver (dpio-driver.c)
1699 +----------------------------------
1701 + The dpio-driver component registers with the fsl-mc bus to handle objects of
1702 + type "dpio". The implementation of probe() handles basic initialization
1703 + of the DPIO including mapping of the DPIO regions (the QBman SW portal)
1704 + and initializing interrupts and registering irq handlers. The dpio-driver
1705 + registers the probed DPIO with dpio-service.
1707 +DPIO service (dpio-service.c, dpaa2-io.h)
1708 +------------------------------------------
1710 + The dpio service component provides queuing, notification, and buffers
1711 + management services to DPAA2 drivers, such as the Ethernet driver. A system
1712 + will typically allocate 1 DPIO object per CPU to allow queuing operations
1713 + to happen simultaneously across all CPUs.
1715 + Notification handling
1716 + dpaa2_io_service_register()
1717 + dpaa2_io_service_deregister()
1718 + dpaa2_io_service_rearm()
1721 + dpaa2_io_service_pull_fq()
1722 + dpaa2_io_service_pull_channel()
1723 + dpaa2_io_service_enqueue_fq()
1724 + dpaa2_io_service_enqueue_qd()
1725 + dpaa2_io_store_create()
1726 + dpaa2_io_store_destroy()
1727 + dpaa2_io_store_next()
1729 + Buffer pool management
1730 + dpaa2_io_service_release()
1731 + dpaa2_io_service_acquire()
1733 +QBman portal interface (qbman-portal.c)
1734 +---------------------------------------
1736 + The qbman-portal component provides APIs to do the low level hardware
1737 + bit twiddling for operations such as:
1738 + -initializing Qman software portals
1739 + -building and sending portal commands
1740 + -portal interrupt configuration and processing
1742 + The qbman-portal APIs are not public to other drivers, and are
1743 + only used by dpio-service.
1745 +Other (dpaa2-fd.h, dpaa2-global.h)
1746 +----------------------------------
1748 + Frame descriptor and scatter-gather definitions and the APIs used to
1749 + manipulate them are defined in dpaa2-fd.h.
1751 + Dequeue result struct and parsing APIs are defined in dpaa2-global.h.
1752 diff --git a/drivers/staging/fsl-mc/bus/dpio/dpio-service.c b/drivers/staging/fsl-mc/bus/dpio/dpio-service.c
1753 new file mode 100644
1754 index 00000000..8449d988
1756 +++ b/drivers/staging/fsl-mc/bus/dpio/dpio-service.c
1759 + * Copyright 2014-2016 Freescale Semiconductor Inc.
1760 + * Copyright 2016 NXP
1762 + * Redistribution and use in source and binary forms, with or without
1763 + * modification, are permitted provided that the following conditions are met:
1764 + * * Redistributions of source code must retain the above copyright
1765 + * notice, this list of conditions and the following disclaimer.
1766 + * * Redistributions in binary form must reproduce the above copyright
1767 + * notice, this list of conditions and the following disclaimer in the
1768 + * documentation and/or other materials provided with the distribution.
1769 + * * Neither the name of Freescale Semiconductor nor the
1770 + * names of its contributors may be used to endorse or promote products
1771 + * derived from this software without specific prior written permission.
1773 + * ALTERNATIVELY, this software may be distributed under the terms of the
1774 + * GNU General Public License ("GPL") as published by the Free Software
1775 + * Foundation, either version 2 of that License or (at your option) any
1778 + * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
1779 + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
1780 + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
1781 + * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
1782 + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
1783 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
1784 + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
1785 + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
1786 + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
1787 + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1789 +#include <linux/types.h>
1790 +#include "../../include/mc.h"
1791 +#include "../../include/dpaa2-io.h"
1792 +#include <linux/init.h>
1793 +#include <linux/module.h>
1794 +#include <linux/platform_device.h>
1795 +#include <linux/interrupt.h>
1796 +#include <linux/dma-mapping.h>
1797 +#include <linux/slab.h>
1800 +#include "qbman-portal.h"
1801 +#include "qbman_debug.h"
1805 + struct dpaa2_io_desc dpio_desc;
1806 + struct qbman_swp_desc swp_desc;
1807 + struct qbman_swp *swp;
1808 + struct list_head node;
1809 + /* protect against multiple management commands */
1810 + spinlock_t lock_mgmt_cmd;
1811 + /* protect notifications list */
1812 + spinlock_t lock_notifications;
1813 + struct list_head notifications;
1816 +struct dpaa2_io_store {
1819 + struct dpaa2_dq *vaddr;
1820 + void *alloced_addr; /* unaligned value from kmalloc() */
1821 + unsigned int idx; /* position of the next-to-be-returned entry */
1822 + struct qbman_swp *swp; /* portal used to issue VDQCR */
1823 + struct device *dev; /* device used for DMA mapping */
1826 +/* keep a per cpu array of DPIOs for fast access */
1827 +static struct dpaa2_io *dpio_by_cpu[NR_CPUS];
1828 +static struct list_head dpio_list = LIST_HEAD_INIT(dpio_list);
1829 +static DEFINE_SPINLOCK(dpio_list_lock);
1831 +static inline struct dpaa2_io *service_select_by_cpu(struct dpaa2_io *d,
1837 + if (unlikely(cpu >= (int)num_possible_cpus()))
1841 + * If cpu == -1, choose the current cpu, with no guarantees about
1842 + * potentially being migrated away.
1845 + cpu = smp_processor_id();
1847 + /* If a specific cpu was requested, pick it up immediately */
1848 + return dpio_by_cpu[cpu];
1851 +static inline struct dpaa2_io *service_select(struct dpaa2_io *d)
1856 + d = service_select_by_cpu(d, -1);
1860 + spin_lock(&dpio_list_lock);
1861 + d = list_entry(dpio_list.next, struct dpaa2_io, node);
1862 + list_del(&d->node);
1863 + list_add_tail(&d->node, &dpio_list);
1864 + spin_unlock(&dpio_list_lock);
1870 + * dpaa2_io_create() - create a dpaa2_io object.
1871 + * @desc: the dpaa2_io descriptor
1873 + * Activates a "struct dpaa2_io" corresponding to the given config of an actual
1876 + * Return a valid dpaa2_io object for success, or NULL for failure.
1878 +struct dpaa2_io *dpaa2_io_create(const struct dpaa2_io_desc *desc)
1880 + struct dpaa2_io *obj = kmalloc(sizeof(*obj), GFP_KERNEL);
1885 + /* check if CPU is out of range (-1 means any cpu) */
1886 + if (desc->cpu >= (int)num_possible_cpus()) {
1891 + atomic_set(&obj->refs, 1);
1892 + obj->dpio_desc = *desc;
1893 + obj->swp_desc.cena_bar = obj->dpio_desc.regs_cena;
1894 + obj->swp_desc.cinh_bar = obj->dpio_desc.regs_cinh;
1895 + obj->swp_desc.qman_version = obj->dpio_desc.qman_version;
1896 + obj->swp = qbman_swp_init(&obj->swp_desc);
1903 + INIT_LIST_HEAD(&obj->node);
1904 + spin_lock_init(&obj->lock_mgmt_cmd);
1905 + spin_lock_init(&obj->lock_notifications);
1906 + INIT_LIST_HEAD(&obj->notifications);
1908 + /* For now only enable DQRR interrupts */
1909 + qbman_swp_interrupt_set_trigger(obj->swp,
1910 + QBMAN_SWP_INTERRUPT_DQRI);
1911 + qbman_swp_interrupt_clear_status(obj->swp, 0xffffffff);
1912 + if (obj->dpio_desc.receives_notifications)
1913 + qbman_swp_push_set(obj->swp, 0, 1);
1915 + spin_lock(&dpio_list_lock);
1916 + list_add_tail(&obj->node, &dpio_list);
1917 + if (desc->cpu >= 0 && !dpio_by_cpu[desc->cpu])
1918 + dpio_by_cpu[desc->cpu] = obj;
1919 + spin_unlock(&dpio_list_lock);
1923 +EXPORT_SYMBOL(dpaa2_io_create);
1926 + * dpaa2_io_down() - release the dpaa2_io object.
1927 + * @d: the dpaa2_io object to be released.
1929 + * The "struct dpaa2_io" type can represent an individual DPIO object (as
1930 + * described by "struct dpaa2_io_desc") or an instance of a "DPIO service",
1931 + * which can be used to group/encapsulate multiple DPIO objects. In all cases,
1932 + * each handle obtained should be released using this function.
1934 +void dpaa2_io_down(struct dpaa2_io *d)
1936 + if (!atomic_dec_and_test(&d->refs))
1940 +EXPORT_SYMBOL(dpaa2_io_down);
1942 +#define DPAA_POLL_MAX 32
1945 + * dpaa2_io_irq() - ISR for DPIO interrupts
1947 + * @obj: the given DPIO object.
1949 + * Return IRQ_HANDLED for success or IRQ_NONE if there
1950 + * were no pending interrupts.
1952 +irqreturn_t dpaa2_io_irq(struct dpaa2_io *obj)
1954 + const struct dpaa2_dq *dq;
1956 + struct qbman_swp *swp;
1960 + status = qbman_swp_interrupt_read_status(swp);
1964 + dq = qbman_swp_dqrr_next(swp);
1966 + if (qbman_result_is_SCN(dq)) {
1967 + struct dpaa2_io_notification_ctx *ctx;
1970 + q64 = qbman_result_SCN_ctx(dq);
1971 + ctx = (void *)q64;
1974 + pr_crit("fsl-mc-dpio: Unrecognised/ignored DQRR entry\n");
1976 + qbman_swp_dqrr_consume(swp, dq);
1978 + if (max > DPAA_POLL_MAX)
1980 + dq = qbman_swp_dqrr_next(swp);
1983 + qbman_swp_interrupt_clear_status(swp, status);
1984 + qbman_swp_interrupt_set_inhibit(swp, 0);
1985 + return IRQ_HANDLED;
1987 +EXPORT_SYMBOL(dpaa2_io_irq);
1990 + * dpaa2_io_service_register() - Prepare for servicing of FQDAN or CDAN
1991 + * notifications on the given DPIO service.
1992 + * @d: the given DPIO service.
1993 + * @ctx: the notification context.
1995 + * The caller should make the MC command to attach a DPAA2 object to
1996 + * a DPIO after this function completes successfully. In that way:
1997 + * (a) The DPIO service is "ready" to handle a notification arrival
1998 + * (which might happen before the "attach" command to MC has
1999 + * returned control of execution back to the caller)
2000 + * (b) The DPIO service can provide back to the caller the 'dpio_id' and
2001 + * 'qman64' parameters that it should pass along in the MC command
2002 + * in order for the object to be configured to produce the right
2003 + * notification fields to the DPIO service.
2005 + * Return 0 for success, or -ENODEV for failure.
2007 +int dpaa2_io_service_register(struct dpaa2_io *d,
2008 + struct dpaa2_io_notification_ctx *ctx)
2010 + unsigned long irqflags;
2012 + d = service_select_by_cpu(d, ctx->desired_cpu);
2016 + ctx->dpio_id = d->dpio_desc.dpio_id;
2017 + ctx->qman64 = (u64)ctx;
2018 + ctx->dpio_private = d;
2019 + spin_lock_irqsave(&d->lock_notifications, irqflags);
2020 + list_add(&ctx->node, &d->notifications);
2021 + spin_unlock_irqrestore(&d->lock_notifications, irqflags);
2023 + /* Enable the generation of CDAN notifications */
2025 + qbman_swp_CDAN_set_context_enable(d->swp,
2030 +EXPORT_SYMBOL(dpaa2_io_service_register);
2033 + * dpaa2_io_service_deregister - The opposite of 'register'.
2034 + * @service: the given DPIO service.
2035 + * @ctx: the notification context.
2037 + * This function should be called only after sending the MC command to
2038 + * to detach the notification-producing device from the DPIO.
2040 +void dpaa2_io_service_deregister(struct dpaa2_io *service,
2041 + struct dpaa2_io_notification_ctx *ctx)
2043 + struct dpaa2_io *d = ctx->dpio_private;
2044 + unsigned long irqflags;
2047 + qbman_swp_CDAN_disable(d->swp, (u16)ctx->id);
2049 + spin_lock_irqsave(&d->lock_notifications, irqflags);
2050 + list_del(&ctx->node);
2051 + spin_unlock_irqrestore(&d->lock_notifications, irqflags);
2053 +EXPORT_SYMBOL(dpaa2_io_service_deregister);
2056 + * dpaa2_io_service_rearm() - Rearm the notification for the given DPIO service.
2057 + * @d: the given DPIO service.
2058 + * @ctx: the notification context.
2060 + * Once a FQDAN/CDAN has been produced, the corresponding FQ/channel is
2061 + * considered "disarmed". Ie. the user can issue pull dequeue operations on that
2062 + * traffic source for as long as it likes. Eventually it may wish to "rearm"
2063 + * that source to allow it to produce another FQDAN/CDAN, that's what this
2064 + * function achieves.
2066 + * Return 0 for success.
2068 +int dpaa2_io_service_rearm(struct dpaa2_io *d,
2069 + struct dpaa2_io_notification_ctx *ctx)
2071 + unsigned long irqflags;
2074 + d = service_select_by_cpu(d, ctx->desired_cpu);
2078 + spin_lock_irqsave(&d->lock_mgmt_cmd, irqflags);
2080 + err = qbman_swp_CDAN_enable(d->swp, (u16)ctx->id);
2082 + err = qbman_swp_fq_schedule(d->swp, ctx->id);
2083 + spin_unlock_irqrestore(&d->lock_mgmt_cmd, irqflags);
2087 +EXPORT_SYMBOL(dpaa2_io_service_rearm);
2090 + * dpaa2_io_service_pull_fq() - pull dequeue functions from a fq.
2091 + * @d: the given DPIO service.
2092 + * @fqid: the given frame queue id.
2093 + * @s: the dpaa2_io_store object for the result.
2095 + * Return 0 for success, or error code for failure.
2097 +int dpaa2_io_service_pull_fq(struct dpaa2_io *d, u32 fqid,
2098 + struct dpaa2_io_store *s)
2100 + struct qbman_pull_desc pd;
2103 + qbman_pull_desc_clear(&pd);
2104 + qbman_pull_desc_set_storage(&pd, s->vaddr, s->paddr, 1);
2105 + qbman_pull_desc_set_numframes(&pd, (u8)s->max);
2106 + qbman_pull_desc_set_fq(&pd, fqid);
2108 + d = service_select(d);
2112 + err = qbman_swp_pull(d->swp, &pd);
2118 +EXPORT_SYMBOL(dpaa2_io_service_pull_fq);
2121 + * dpaa2_io_service_pull_channel() - pull dequeue functions from a channel.
2122 + * @d: the given DPIO service.
2123 + * @channelid: the given channel id.
2124 + * @s: the dpaa2_io_store object for the result.
2126 + * Return 0 for success, or error code for failure.
2128 +int dpaa2_io_service_pull_channel(struct dpaa2_io *d, u32 channelid,
2129 + struct dpaa2_io_store *s)
2131 + struct qbman_pull_desc pd;
2134 + qbman_pull_desc_clear(&pd);
2135 + qbman_pull_desc_set_storage(&pd, s->vaddr, s->paddr, 1);
2136 + qbman_pull_desc_set_numframes(&pd, (u8)s->max);
2137 + qbman_pull_desc_set_channel(&pd, channelid, qbman_pull_type_prio);
2139 + d = service_select(d);
2144 + err = qbman_swp_pull(d->swp, &pd);
2150 +EXPORT_SYMBOL(dpaa2_io_service_pull_channel);
2153 + * dpaa2_io_service_enqueue_fq() - Enqueue a frame to a frame queue.
2154 + * @d: the given DPIO service.
2155 + * @fqid: the given frame queue id.
2156 + * @fd: the frame descriptor which is enqueued.
2158 + * Return 0 for successful enqueue, -EBUSY if the enqueue ring is not ready,
2159 + * or -ENODEV if there is no dpio service.
2161 +int dpaa2_io_service_enqueue_fq(struct dpaa2_io *d,
2163 + const struct dpaa2_fd *fd)
2165 + struct qbman_eq_desc ed;
2167 + d = service_select(d);
2171 + qbman_eq_desc_clear(&ed);
2172 + qbman_eq_desc_set_no_orp(&ed, 0);
2173 + qbman_eq_desc_set_fq(&ed, fqid);
2175 + return qbman_swp_enqueue(d->swp, &ed, fd);
2177 +EXPORT_SYMBOL(dpaa2_io_service_enqueue_fq);
2180 + * dpaa2_io_service_enqueue_qd() - Enqueue a frame to a QD.
2181 + * @d: the given DPIO service.
2182 + * @qdid: the given queuing destination id.
2183 + * @prio: the given queuing priority.
2184 + * @qdbin: the given queuing destination bin.
2185 + * @fd: the frame descriptor which is enqueued.
2187 + * Return 0 for successful enqueue, or -EBUSY if the enqueue ring is not ready,
2188 + * or -ENODEV if there is no dpio service.
2190 +int dpaa2_io_service_enqueue_qd(struct dpaa2_io *d,
2191 + u32 qdid, u8 prio, u16 qdbin,
2192 + const struct dpaa2_fd *fd)
2194 + struct qbman_eq_desc ed;
2196 + d = service_select(d);
2200 + qbman_eq_desc_clear(&ed);
2201 + qbman_eq_desc_set_no_orp(&ed, 0);
2202 + qbman_eq_desc_set_qd(&ed, qdid, qdbin, prio);
2204 + return qbman_swp_enqueue(d->swp, &ed, fd);
2206 +EXPORT_SYMBOL(dpaa2_io_service_enqueue_qd);
2209 + * dpaa2_io_service_release() - Release buffers to a buffer pool.
2210 + * @d: the given DPIO object.
2211 + * @bpid: the buffer pool id.
2212 + * @buffers: the buffers to be released.
2213 + * @num_buffers: the number of the buffers to be released.
2215 + * Return 0 for success, and negative error code for failure.
2217 +int dpaa2_io_service_release(struct dpaa2_io *d,
2219 + const u64 *buffers,
2220 + unsigned int num_buffers)
2222 + struct qbman_release_desc rd;
2224 + d = service_select(d);
2228 + qbman_release_desc_clear(&rd);
2229 + qbman_release_desc_set_bpid(&rd, bpid);
2231 + return qbman_swp_release(d->swp, &rd, buffers, num_buffers);
2233 +EXPORT_SYMBOL(dpaa2_io_service_release);
2236 + * dpaa2_io_service_acquire() - Acquire buffers from a buffer pool.
2237 + * @d: the given DPIO object.
2238 + * @bpid: the buffer pool id.
2239 + * @buffers: the buffer addresses for acquired buffers.
2240 + * @num_buffers: the expected number of the buffers to acquire.
2242 + * Return a negative error code if the command failed, otherwise it returns
2243 + * the number of buffers acquired, which may be less than the number requested.
2244 + * Eg. if the buffer pool is empty, this will return zero.
2246 +int dpaa2_io_service_acquire(struct dpaa2_io *d,
2249 + unsigned int num_buffers)
2251 + unsigned long irqflags;
2254 + d = service_select(d);
2258 + spin_lock_irqsave(&d->lock_mgmt_cmd, irqflags);
2259 + err = qbman_swp_acquire(d->swp, bpid, buffers, num_buffers);
2260 + spin_unlock_irqrestore(&d->lock_mgmt_cmd, irqflags);
2264 +EXPORT_SYMBOL(dpaa2_io_service_acquire);
2267 + * 'Stores' are reusable memory blocks for holding dequeue results, and to
2268 + * assist with parsing those results.
2272 + * dpaa2_io_store_create() - Create the dma memory storage for dequeue result.
2273 + * @max_frames: the maximum number of dequeued result for frames, must be <= 16.
2274 + * @dev: the device to allow mapping/unmapping the DMAable region.
2276 + * The size of the storage is "max_frames*sizeof(struct dpaa2_dq)".
2277 + * The 'dpaa2_io_store' returned is a DPIO service managed object.
2279 + * Return pointer to dpaa2_io_store struct for successfuly created storage
2280 + * memory, or NULL on error.
2282 +struct dpaa2_io_store *dpaa2_io_store_create(unsigned int max_frames,
2283 + struct device *dev)
2285 + struct dpaa2_io_store *ret;
2288 + if (!max_frames || (max_frames > 16))
2291 + ret = kmalloc(sizeof(*ret), GFP_KERNEL);
2295 + ret->max = max_frames;
2296 + size = max_frames * sizeof(struct dpaa2_dq) + 64;
2297 + ret->alloced_addr = kzalloc(size, GFP_KERNEL);
2298 + if (!ret->alloced_addr) {
2303 + ret->vaddr = PTR_ALIGN(ret->alloced_addr, 64);
2304 + ret->paddr = dma_map_single(dev, ret->vaddr,
2305 + sizeof(struct dpaa2_dq) * max_frames,
2307 + if (dma_mapping_error(dev, ret->paddr)) {
2308 + kfree(ret->alloced_addr);
2318 +EXPORT_SYMBOL(dpaa2_io_store_create);
2321 + * dpaa2_io_store_destroy() - Frees the dma memory storage for dequeue
2323 + * @s: the storage memory to be destroyed.
2325 +void dpaa2_io_store_destroy(struct dpaa2_io_store *s)
2327 + dma_unmap_single(s->dev, s->paddr, sizeof(struct dpaa2_dq) * s->max,
2329 + kfree(s->alloced_addr);
2332 +EXPORT_SYMBOL(dpaa2_io_store_destroy);
2335 + * dpaa2_io_store_next() - Determine when the next dequeue result is available.
2336 + * @s: the dpaa2_io_store object.
2337 + * @is_last: indicate whether this is the last frame in the pull command.
2339 + * When an object driver performs dequeues to a dpaa2_io_store, this function
2340 + * can be used to determine when the next frame result is available. Once
2341 + * this function returns non-NULL, a subsequent call to it will try to find
2342 + * the next dequeue result.
2344 + * Note that if a pull-dequeue has a NULL result because the target FQ/channel
2345 + * was empty, then this function will also return NULL (rather than expecting
2346 + * the caller to always check for this. As such, "is_last" can be used to
2347 + * differentiate between "end-of-empty-dequeue" and "still-waiting".
2349 + * Return dequeue result for a valid dequeue result, or NULL for empty dequeue.
2351 +struct dpaa2_dq *dpaa2_io_store_next(struct dpaa2_io_store *s, int *is_last)
2354 + struct dpaa2_dq *ret = &s->vaddr[s->idx];
2356 + match = qbman_result_has_new_result(s->swp, ret);
2364 + if (dpaa2_dq_is_pull_complete(ret)) {
2368 + * If we get an empty dequeue result to terminate a zero-results
2369 + * vdqcr, return NULL to the caller rather than expecting him to
2370 + * check non-NULL results every time.
2372 + if (!(dpaa2_dq_flags(ret) & DPAA2_DQ_STAT_VALIDFRAME))
2380 +EXPORT_SYMBOL(dpaa2_io_store_next);
2382 +#ifdef CONFIG_FSL_QBMAN_DEBUG
2384 + * dpaa2_io_query_fq_count() - Get the frame and byte count for a given fq.
2385 + * @d: the given DPIO object.
2386 + * @fqid: the id of frame queue to be queried.
2387 + * @fcnt: the queried frame count.
2388 + * @bcnt: the queried byte count.
2390 + * Knowing the FQ count at run-time can be useful in debugging situations.
2391 + * The instantaneous frame- and byte-count are hereby returned.
2393 + * Return 0 for a successful query, and negative error code if query fails.
2395 +int dpaa2_io_query_fq_count(struct dpaa2_io *d, uint32_t fqid,
2396 + u32 *fcnt, u32 *bcnt)
2398 + struct qbman_attr state;
2399 + struct qbman_swp *swp;
2400 + unsigned long irqflags;
2403 + d = service_select(d);
2408 + spin_lock_irqsave(&d->lock_mgmt_cmd, irqflags);
2409 + ret = qbman_fq_query_state(swp, fqid, &state);
2410 + spin_unlock_irqrestore(&d->lock_mgmt_cmd, irqflags);
2413 + *fcnt = qbman_fq_state_frame_count(&state);
2414 + *bcnt = qbman_fq_state_byte_count(&state);
2418 +EXPORT_SYMBOL(dpaa2_io_query_fq_count);
2421 + * dpaa2_io_query_bp_count() - Query the number of buffers currenty in a
2423 + * @d: the given DPIO object.
2424 + * @bpid: the index of buffer pool to be queried.
2425 + * @num: the queried number of buffers in the buffer pool.
2427 + * Return 0 for a sucessful query, and negative error code if query fails.
2429 +int dpaa2_io_query_bp_count(struct dpaa2_io *d, uint32_t bpid, u32 *num)
2431 + struct qbman_attr state;
2432 + struct qbman_swp *swp;
2433 + unsigned long irqflags;
2436 + d = service_select(d);
2441 + spin_lock_irqsave(&d->lock_mgmt_cmd, irqflags);
2442 + ret = qbman_bp_query(swp, bpid, &state);
2443 + spin_unlock_irqrestore(&d->lock_mgmt_cmd, irqflags);
2446 + *num = qbman_bp_info_num_free_bufs(&state);
2449 +EXPORT_SYMBOL(dpaa2_io_query_bp_count);
2451 diff --git a/drivers/staging/fsl-mc/bus/dpio/dpio.c b/drivers/staging/fsl-mc/bus/dpio/dpio.c
2452 new file mode 100644
2453 index 00000000..d81e0232
2455 +++ b/drivers/staging/fsl-mc/bus/dpio/dpio.c
2458 + * Copyright 2013-2016 Freescale Semiconductor Inc.
2459 + * Copyright 2016 NXP
2461 + * Redistribution and use in source and binary forms, with or without
2462 + * modification, are permitted provided that the following conditions are met:
2463 + * * Redistributions of source code must retain the above copyright
2464 + * notice, this list of conditions and the following disclaimer.
2465 + * * Redistributions in binary form must reproduce the above copyright
2466 + * notice, this list of conditions and the following disclaimer in the
2467 + * documentation and/or other materials provided with the distribution.
2468 + * * Neither the name of the above-listed copyright holders nor the
2469 + * names of any contributors may be used to endorse or promote products
2470 + * derived from this software without specific prior written permission.
2472 + * ALTERNATIVELY, this software may be distributed under the terms of the
2473 + * GNU General Public License ("GPL") as published by the Free Software
2474 + * Foundation, either version 2 of that License or (at your option) any
2477 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
2478 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2479 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2480 + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
2481 + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2482 + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2483 + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2484 + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2485 + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2486 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2487 + * POSSIBILITY OF SUCH DAMAGE.
2489 +#include "../../include/mc-sys.h"
2490 +#include "../../include/mc-cmd.h"
2493 +#include "dpio-cmd.h"
2496 + * Data Path I/O Portal API
2497 + * Contains initialization APIs and runtime control APIs for DPIO
2501 + * dpio_open() - Open a control session for the specified object
2502 + * @mc_io: Pointer to MC portal's I/O object
2503 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2504 + * @dpio_id: DPIO unique ID
2505 + * @token: Returned token; use in subsequent API calls
2507 + * This function can be used to open a control session for an
2508 + * already created object; an object may have been declared in
2509 + * the DPL or by calling the dpio_create() function.
2510 + * This function returns a unique authentication token,
2511 + * associated with the specific object ID and the specific MC
2512 + * portal; this token must be used in all subsequent commands for
2513 + * this specific object.
2515 + * Return: '0' on Success; Error code otherwise.
2517 +int dpio_open(struct fsl_mc_io *mc_io,
2522 + struct mc_command cmd = { 0 };
2523 + struct dpio_cmd_open *dpio_cmd;
2526 + /* prepare command */
2527 + cmd.header = mc_encode_cmd_header(DPIO_CMDID_OPEN,
2530 + dpio_cmd = (struct dpio_cmd_open *)cmd.params;
2531 + dpio_cmd->dpio_id = cpu_to_le32(dpio_id);
2533 + err = mc_send_command(mc_io, &cmd);
2537 + /* retrieve response parameters */
2538 + *token = mc_cmd_hdr_read_token(&cmd);
2544 + * dpio_close() - Close the control session of the object
2545 + * @mc_io: Pointer to MC portal's I/O object
2546 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2547 + * @token: Token of DPIO object
2549 + * Return: '0' on Success; Error code otherwise.
2551 +int dpio_close(struct fsl_mc_io *mc_io,
2555 + struct mc_command cmd = { 0 };
2557 + /* prepare command */
2558 + cmd.header = mc_encode_cmd_header(DPIO_CMDID_CLOSE,
2562 + return mc_send_command(mc_io, &cmd);
2566 + * dpio_enable() - Enable the DPIO, allow I/O portal operations.
2567 + * @mc_io: Pointer to MC portal's I/O object
2568 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2569 + * @token: Token of DPIO object
2571 + * Return: '0' on Success; Error code otherwise
2573 +int dpio_enable(struct fsl_mc_io *mc_io,
2577 + struct mc_command cmd = { 0 };
2579 + /* prepare command */
2580 + cmd.header = mc_encode_cmd_header(DPIO_CMDID_ENABLE,
2584 + return mc_send_command(mc_io, &cmd);
2588 + * dpio_disable() - Disable the DPIO, stop any I/O portal operation.
2589 + * @mc_io: Pointer to MC portal's I/O object
2590 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2591 + * @token: Token of DPIO object
2593 + * Return: '0' on Success; Error code otherwise
2595 +int dpio_disable(struct fsl_mc_io *mc_io,
2599 + struct mc_command cmd = { 0 };
2601 + /* prepare command */
2602 + cmd.header = mc_encode_cmd_header(DPIO_CMDID_DISABLE,
2606 + return mc_send_command(mc_io, &cmd);
2610 + * dpio_get_attributes() - Retrieve DPIO attributes
2611 + * @mc_io: Pointer to MC portal's I/O object
2612 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2613 + * @token: Token of DPIO object
2614 + * @attr: Returned object's attributes
2616 + * Return: '0' on Success; Error code otherwise
2618 +int dpio_get_attributes(struct fsl_mc_io *mc_io,
2621 + struct dpio_attr *attr)
2623 + struct mc_command cmd = { 0 };
2624 + struct dpio_rsp_get_attr *dpio_rsp;
2627 + /* prepare command */
2628 + cmd.header = mc_encode_cmd_header(DPIO_CMDID_GET_ATTR,
2632 + err = mc_send_command(mc_io, &cmd);
2636 + /* retrieve response parameters */
2637 + dpio_rsp = (struct dpio_rsp_get_attr *)cmd.params;
2638 + attr->id = le32_to_cpu(dpio_rsp->id);
2639 + attr->qbman_portal_id = le16_to_cpu(dpio_rsp->qbman_portal_id);
2640 + attr->num_priorities = dpio_rsp->num_priorities;
2641 + attr->channel_mode = dpio_rsp->channel_mode & DPIO_CHANNEL_MODE_MASK;
2642 + attr->qbman_portal_ce_offset =
2643 + le64_to_cpu(dpio_rsp->qbman_portal_ce_addr);
2644 + attr->qbman_portal_ci_offset =
2645 + le64_to_cpu(dpio_rsp->qbman_portal_ci_addr);
2646 + attr->qbman_version = le32_to_cpu(dpio_rsp->qbman_version);
2652 + * dpio_get_api_version - Get Data Path I/O API version
2653 + * @mc_io: Pointer to MC portal's DPIO object
2654 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2655 + * @major_ver: Major version of DPIO API
2656 + * @minor_ver: Minor version of DPIO API
2658 + * Return: '0' on Success; Error code otherwise
2660 +int dpio_get_api_version(struct fsl_mc_io *mc_io,
2665 + struct mc_command cmd = { 0 };
2668 + /* prepare command */
2669 + cmd.header = mc_encode_cmd_header(DPIO_CMDID_GET_API_VERSION,
2672 + err = mc_send_command(mc_io, &cmd);
2676 + /* retrieve response parameters */
2677 + mc_cmd_read_api_version(&cmd, major_ver, minor_ver);
2681 diff --git a/drivers/staging/fsl-mc/bus/dpio/dpio.h b/drivers/staging/fsl-mc/bus/dpio/dpio.h
2682 new file mode 100644
2683 index 00000000..ced1103d
2685 +++ b/drivers/staging/fsl-mc/bus/dpio/dpio.h
2688 + * Copyright 2013-2016 Freescale Semiconductor Inc.
2689 + * Copyright 2016 NXP
2691 + * Redistribution and use in source and binary forms, with or without
2692 + * modification, are permitted provided that the following conditions are met:
2693 + * * Redistributions of source code must retain the above copyright
2694 + * notice, this list of conditions and the following disclaimer.
2695 + * * Redistributions in binary form must reproduce the above copyright
2696 + * notice, this list of conditions and the following disclaimer in the
2697 + * documentation and/or other materials provided with the distribution.
2698 + * * Neither the name of the above-listed copyright holders nor the
2699 + * names of any contributors may be used to endorse or promote products
2700 + * derived from this software without specific prior written permission.
2702 + * ALTERNATIVELY, this software may be distributed under the terms of the
2703 + * GNU General Public License ("GPL") as published by the Free Software
2704 + * Foundation, either version 2 of that License or (at your option) any
2707 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
2708 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2709 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2710 + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
2711 + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2712 + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2713 + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2714 + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2715 + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2716 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2717 + * POSSIBILITY OF SUCH DAMAGE.
2719 +#ifndef __FSL_DPIO_H
2720 +#define __FSL_DPIO_H
2724 +int dpio_open(struct fsl_mc_io *mc_io,
2729 +int dpio_close(struct fsl_mc_io *mc_io,
2734 + * enum dpio_channel_mode - DPIO notification channel mode
2735 + * @DPIO_NO_CHANNEL: No support for notification channel
2736 + * @DPIO_LOCAL_CHANNEL: Notifications on data availability can be received by a
2737 + * dedicated channel in the DPIO; user should point the queue's
2738 + * destination in the relevant interface to this DPIO
2740 +enum dpio_channel_mode {
2741 + DPIO_NO_CHANNEL = 0,
2742 + DPIO_LOCAL_CHANNEL = 1,
2746 + * struct dpio_cfg - Structure representing DPIO configuration
2747 + * @channel_mode: Notification channel mode
2748 + * @num_priorities: Number of priorities for the notification channel (1-8);
2749 + * relevant only if 'channel_mode = DPIO_LOCAL_CHANNEL'
2752 + enum dpio_channel_mode channel_mode;
2753 + u8 num_priorities;
2756 +int dpio_enable(struct fsl_mc_io *mc_io,
2760 +int dpio_disable(struct fsl_mc_io *mc_io,
2765 + * struct dpio_attr - Structure representing DPIO attributes
2766 + * @id: DPIO object ID
2767 + * @qbman_portal_ce_offset: offset of the software portal cache-enabled area
2768 + * @qbman_portal_ci_offset: offset of the software portal cache-inhibited area
2769 + * @qbman_portal_id: Software portal ID
2770 + * @channel_mode: Notification channel mode
2771 + * @num_priorities: Number of priorities for the notification channel (1-8);
2772 + * relevant only if 'channel_mode = DPIO_LOCAL_CHANNEL'
2773 + * @qbman_version: QBMAN version
2777 + u64 qbman_portal_ce_offset;
2778 + u64 qbman_portal_ci_offset;
2779 + u16 qbman_portal_id;
2780 + enum dpio_channel_mode channel_mode;
2781 + u8 num_priorities;
2782 + u32 qbman_version;
2785 +int dpio_get_attributes(struct fsl_mc_io *mc_io,
2788 + struct dpio_attr *attr);
2790 +int dpio_get_api_version(struct fsl_mc_io *mc_io,
2795 +#endif /* __FSL_DPIO_H */
2796 diff --git a/drivers/staging/fsl-mc/bus/dpio/qbman-portal.c b/drivers/staging/fsl-mc/bus/dpio/qbman-portal.c
2797 new file mode 100644
2798 index 00000000..e14fb65b
2800 +++ b/drivers/staging/fsl-mc/bus/dpio/qbman-portal.c
2803 + * Copyright (C) 2014-2016 Freescale Semiconductor, Inc.
2804 + * Copyright 2016 NXP
2806 + * Redistribution and use in source and binary forms, with or without
2807 + * modification, are permitted provided that the following conditions are met:
2808 + * * Redistributions of source code must retain the above copyright
2809 + * notice, this list of conditions and the following disclaimer.
2810 + * * Redistributions in binary form must reproduce the above copyright
2811 + * notice, this list of conditions and the following disclaimer in the
2812 + * documentation and/or other materials provided with the distribution.
2813 + * * Neither the name of Freescale Semiconductor nor the
2814 + * names of its contributors may be used to endorse or promote products
2815 + * derived from this software without specific prior written permission.
2817 + * ALTERNATIVELY, this software may be distributed under the terms of the
2818 + * GNU General Public License ("GPL") as published by the Free Software
2819 + * Foundation, either version 2 of that License or (at your option) any
2822 + * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
2823 + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
2824 + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
2825 + * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
2826 + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
2827 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
2828 + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
2829 + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2830 + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
2831 + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2834 +#include <asm/cacheflush.h>
2835 +#include <linux/io.h>
2836 +#include <linux/slab.h>
2837 +#include "../../include/dpaa2-global.h"
2839 +#include "qbman-portal.h"
2841 +struct qb_attr_code code_generic_verb = QB_CODE(0, 0, 7);
2842 +struct qb_attr_code code_generic_rslt = QB_CODE(0, 8, 8);
2844 +#define QMAN_REV_4000 0x04000000
2845 +#define QMAN_REV_4100 0x04010000
2846 +#define QMAN_REV_4101 0x04010001
2847 +#define QMAN_REV_MASK 0xffff0000
2849 +/* All QBMan command and result structures use this "valid bit" encoding */
2850 +#define QB_VALID_BIT ((u32)0x80)
2852 +/* QBMan portal management command codes */
2853 +#define QBMAN_MC_ACQUIRE 0x30
2854 +#define QBMAN_WQCHAN_CONFIGURE 0x46
2856 +/* CINH register offsets */
2857 +#define QBMAN_CINH_SWP_EQAR 0x8c0
2858 +#define QBMAN_CINH_SWP_DQPI 0xa00
2859 +#define QBMAN_CINH_SWP_DCAP 0xac0
2860 +#define QBMAN_CINH_SWP_SDQCR 0xb00
2861 +#define QBMAN_CINH_SWP_RAR 0xcc0
2862 +#define QBMAN_CINH_SWP_ISR 0xe00
2863 +#define QBMAN_CINH_SWP_IER 0xe40
2864 +#define QBMAN_CINH_SWP_ISDR 0xe80
2865 +#define QBMAN_CINH_SWP_IIR 0xec0
2867 +/* CENA register offsets */
2868 +#define QBMAN_CENA_SWP_EQCR(n) (0x000 + ((u32)(n) << 6))
2869 +#define QBMAN_CENA_SWP_DQRR(n) (0x200 + ((u32)(n) << 6))
2870 +#define QBMAN_CENA_SWP_RCR(n) (0x400 + ((u32)(n) << 6))
2871 +#define QBMAN_CENA_SWP_CR 0x600
2872 +#define QBMAN_CENA_SWP_RR(vb) (0x700 + ((u32)(vb) >> 1))
2873 +#define QBMAN_CENA_SWP_VDQCR 0x780
2875 +/* Reverse mapping of QBMAN_CENA_SWP_DQRR() */
2876 +#define QBMAN_IDX_FROM_DQRR(p) (((unsigned long)(p) & 0x1ff) >> 6)
2878 +/* Define token used to determine if response written to memory is valid */
2879 +#define QMAN_DQ_TOKEN_VALID 1
2881 +/* SDQCR attribute codes */
2882 +#define QB_SDQCR_FC_SHIFT 29
2883 +#define QB_SDQCR_FC_MASK 0x1
2884 +#define QB_SDQCR_DCT_SHIFT 24
2885 +#define QB_SDQCR_DCT_MASK 0x3
2886 +#define QB_SDQCR_TOK_SHIFT 16
2887 +#define QB_SDQCR_TOK_MASK 0xff
2888 +#define QB_SDQCR_SRC_SHIFT 0
2889 +#define QB_SDQCR_SRC_MASK 0xffff
2891 +/* opaque token for static dequeues */
2892 +#define QMAN_SDQCR_TOKEN 0xbb
2894 +enum qbman_sdqcr_dct {
2895 + qbman_sdqcr_dct_null = 0,
2896 + qbman_sdqcr_dct_prio_ics,
2897 + qbman_sdqcr_dct_active_ics,
2898 + qbman_sdqcr_dct_active
2901 +enum qbman_sdqcr_fc {
2902 + qbman_sdqcr_fc_one = 0,
2903 + qbman_sdqcr_fc_up_to_3 = 1
2906 +#define dccvac(p) { asm volatile("dc cvac, %0;" : : "r" (p) : "memory"); }
2907 +#define dcivac(p) { asm volatile("dc ivac, %0" : : "r"(p) : "memory"); }
2908 +static inline void qbman_inval_prefetch(struct qbman_swp *p, uint32_t offset)
2910 + dcivac(p->addr_cena + offset);
2911 + prefetch(p->addr_cena + offset);
2914 +/* Portal Access */
2916 +static inline u32 qbman_read_register(struct qbman_swp *p, u32 offset)
2918 + return readl_relaxed(p->addr_cinh + offset);
2921 +static inline void qbman_write_register(struct qbman_swp *p, u32 offset,
2924 + writel_relaxed(value, p->addr_cinh + offset);
2927 +static inline void *qbman_get_cmd(struct qbman_swp *p, u32 offset)
2929 + return p->addr_cena + offset;
2932 +#define QBMAN_CINH_SWP_CFG 0xd00
2934 +#define SWP_CFG_DQRR_MF_SHIFT 20
2935 +#define SWP_CFG_EST_SHIFT 16
2936 +#define SWP_CFG_WN_SHIFT 14
2937 +#define SWP_CFG_RPM_SHIFT 12
2938 +#define SWP_CFG_DCM_SHIFT 10
2939 +#define SWP_CFG_EPM_SHIFT 8
2940 +#define SWP_CFG_SD_SHIFT 5
2941 +#define SWP_CFG_SP_SHIFT 4
2942 +#define SWP_CFG_SE_SHIFT 3
2943 +#define SWP_CFG_DP_SHIFT 2
2944 +#define SWP_CFG_DE_SHIFT 1
2945 +#define SWP_CFG_EP_SHIFT 0
2947 +static inline u32 qbman_set_swp_cfg(u8 max_fill, u8 wn, u8 est, u8 rpm, u8 dcm,
2948 + u8 epm, int sd, int sp, int se,
2949 + int dp, int de, int ep)
2951 + return cpu_to_le32 (max_fill << SWP_CFG_DQRR_MF_SHIFT |
2952 + est << SWP_CFG_EST_SHIFT |
2953 + wn << SWP_CFG_WN_SHIFT |
2954 + rpm << SWP_CFG_RPM_SHIFT |
2955 + dcm << SWP_CFG_DCM_SHIFT |
2956 + epm << SWP_CFG_EPM_SHIFT |
2957 + sd << SWP_CFG_SD_SHIFT |
2958 + sp << SWP_CFG_SP_SHIFT |
2959 + se << SWP_CFG_SE_SHIFT |
2960 + dp << SWP_CFG_DP_SHIFT |
2961 + de << SWP_CFG_DE_SHIFT |
2962 + ep << SWP_CFG_EP_SHIFT);
2966 + * qbman_swp_init() - Create a functional object representing the given
2967 + * QBMan portal descriptor.
2968 + * @d: the given qbman swp descriptor
2970 + * Return qbman_swp portal for success, NULL if the object cannot
2973 +struct qbman_swp *qbman_swp_init(const struct qbman_swp_desc *d)
2975 + struct qbman_swp *p = kmalloc(sizeof(*p), GFP_KERNEL);
2981 + p->mc.valid_bit = QB_VALID_BIT;
2983 + p->sdq |= qbman_sdqcr_dct_prio_ics << QB_SDQCR_DCT_SHIFT;
2984 + p->sdq |= qbman_sdqcr_fc_up_to_3 << QB_SDQCR_FC_SHIFT;
2985 + p->sdq |= QMAN_SDQCR_TOKEN << QB_SDQCR_TOK_SHIFT;
2987 + atomic_set(&p->vdq.available, 1);
2988 + p->vdq.valid_bit = QB_VALID_BIT;
2989 + p->dqrr.next_idx = 0;
2990 + p->dqrr.valid_bit = QB_VALID_BIT;
2992 + if ((p->desc->qman_version & QMAN_REV_MASK) < QMAN_REV_4100) {
2993 + p->dqrr.dqrr_size = 4;
2994 + p->dqrr.reset_bug = 1;
2996 + p->dqrr.dqrr_size = 8;
2997 + p->dqrr.reset_bug = 0;
3000 + p->addr_cena = d->cena_bar;
3001 + p->addr_cinh = d->cinh_bar;
3003 + reg = qbman_set_swp_cfg(p->dqrr.dqrr_size,
3004 + 0, /* Writes cacheable */
3005 + 0, /* EQCR_CI stashing threshold */
3006 + 3, /* RPM: Valid bit mode, RCR in array mode */
3007 + 2, /* DCM: Discrete consumption ack mode */
3008 + 3, /* EPM: Valid bit mode, EQCR in array mode */
3009 + 0, /* mem stashing drop enable == FALSE */
3010 + 1, /* mem stashing priority == TRUE */
3011 + 0, /* mem stashing enable == FALSE */
3012 + 1, /* dequeue stashing priority == TRUE */
3013 + 0, /* dequeue stashing enable == FALSE */
3014 + 0); /* EQCR_CI stashing priority == FALSE */
3016 + qbman_write_register(p, QBMAN_CINH_SWP_CFG, reg);
3017 + reg = qbman_read_register(p, QBMAN_CINH_SWP_CFG);
3019 + pr_err("qbman: the portal is not enabled!\n");
3024 + * SDQCR needs to be initialized to 0 when no channels are
3025 + * being dequeued from or else the QMan HW will indicate an
3026 + * error. The values that were calculated above will be
3027 + * applied when dequeues from a specific channel are enabled.
3029 + qbman_write_register(p, QBMAN_CINH_SWP_SDQCR, 0);
3034 + * qbman_swp_finish() - Create and destroy a functional object representing
3035 + * the given QBMan portal descriptor.
3036 + * @p: the qbman_swp object to be destroyed
3038 +void qbman_swp_finish(struct qbman_swp *p)
3044 + * qbman_swp_interrupt_read_status()
3045 + * @p: the given software portal
3047 + * Return the value in the SWP_ISR register.
3049 +u32 qbman_swp_interrupt_read_status(struct qbman_swp *p)
3051 + return qbman_read_register(p, QBMAN_CINH_SWP_ISR);
3055 + * qbman_swp_interrupt_clear_status()
3056 + * @p: the given software portal
3057 + * @mask: The mask to clear in SWP_ISR register
3059 +void qbman_swp_interrupt_clear_status(struct qbman_swp *p, u32 mask)
3061 + qbman_write_register(p, QBMAN_CINH_SWP_ISR, mask);
3065 + * qbman_swp_interrupt_get_trigger() - read interrupt enable register
3066 + * @p: the given software portal
3068 + * Return the value in the SWP_IER register.
3070 +u32 qbman_swp_interrupt_get_trigger(struct qbman_swp *p)
3072 + return qbman_read_register(p, QBMAN_CINH_SWP_IER);
3076 + * qbman_swp_interrupt_set_trigger() - enable interrupts for a swp
3077 + * @p: the given software portal
3078 + * @mask: The mask of bits to enable in SWP_IER
3080 +void qbman_swp_interrupt_set_trigger(struct qbman_swp *p, u32 mask)
3082 + qbman_write_register(p, QBMAN_CINH_SWP_IER, mask);
3086 + * qbman_swp_interrupt_get_inhibit() - read interrupt mask register
3087 + * @p: the given software portal object
3089 + * Return the value in the SWP_IIR register.
3091 +int qbman_swp_interrupt_get_inhibit(struct qbman_swp *p)
3093 + return qbman_read_register(p, QBMAN_CINH_SWP_IIR);
3097 + * qbman_swp_interrupt_set_inhibit() - write interrupt mask register
3098 + * @p: the given software portal object
3099 + * @mask: The mask to set in SWP_IIR register
3101 +void qbman_swp_interrupt_set_inhibit(struct qbman_swp *p, int inhibit)
3103 + qbman_write_register(p, QBMAN_CINH_SWP_IIR, inhibit ? 0xffffffff : 0);
3107 + * Different management commands all use this common base layer of code to issue
3108 + * commands and poll for results.
3112 + * Returns a pointer to where the caller should fill in their management command
3113 + * (caller should ignore the verb byte)
3115 +void *qbman_swp_mc_start(struct qbman_swp *p)
3117 + return qbman_get_cmd(p, QBMAN_CENA_SWP_CR);
3121 + * Commits merges in the caller-supplied command verb (which should not include
3122 + * the valid-bit) and submits the command to hardware
3124 +void qbman_swp_mc_submit(struct qbman_swp *p, void *cmd, u8 cmd_verb)
3129 + *v = cmd_verb | p->mc.valid_bit;
3134 + * Checks for a completed response (returns non-NULL if only if the response
3137 +void *qbman_swp_mc_result(struct qbman_swp *p)
3141 + qbman_inval_prefetch(p, QBMAN_CENA_SWP_RR(p->mc.valid_bit));
3142 + ret = qbman_get_cmd(p, QBMAN_CENA_SWP_RR(p->mc.valid_bit));
3144 + /* Remove the valid-bit - command completed if the rest is non-zero */
3145 + verb = ret[0] & ~QB_VALID_BIT;
3148 + p->mc.valid_bit ^= QB_VALID_BIT;
3152 +#define QB_ENQUEUE_CMD_OPTIONS_SHIFT 0
3153 +enum qb_enqueue_commands {
3154 + enqueue_empty = 0,
3155 + enqueue_response_always = 1,
3156 + enqueue_rejects_to_fq = 2
3159 +#define QB_ENQUEUE_CMD_ORP_ENABLE_SHIFT 2
3160 +#define QB_ENQUEUE_CMD_IRQ_ON_DISPATCH_SHIFT 3
3161 +#define QB_ENQUEUE_CMD_TARGET_TYPE_SHIFT 4
3164 + * qbman_eq_desc_clear() - Clear the contents of a descriptor to
3165 + * default/starting state.
3167 +void qbman_eq_desc_clear(struct qbman_eq_desc *d)
3169 + memset(d, 0, sizeof(*d));
3173 + * qbman_eq_desc_set_no_orp() - Set enqueue descriptor without orp
3174 + * @d: the enqueue descriptor.
3175 + * @response_success: 1 = enqueue with response always; 0 = enqueue with
3176 + * rejections returned on a FQ.
3178 +void qbman_eq_desc_set_no_orp(struct qbman_eq_desc *d, int respond_success)
3180 + d->verb &= ~(1 << QB_ENQUEUE_CMD_ORP_ENABLE_SHIFT);
3181 + if (respond_success)
3182 + d->verb |= enqueue_response_always;
3184 + d->verb |= enqueue_rejects_to_fq;
3188 + * Exactly one of the following descriptor "targets" should be set. (Calling any
3189 + * one of these will replace the effect of any prior call to one of these.)
3190 + * -enqueue to a frame queue
3191 + * -enqueue to a queuing destination
3195 + * qbman_eq_desc_set_fq() - set the FQ for the enqueue command
3196 + * @d: the enqueue descriptor
3197 + * @fqid: the id of the frame queue to be enqueued
3199 +void qbman_eq_desc_set_fq(struct qbman_eq_desc *d, u32 fqid)
3201 + d->verb &= ~(1 << QB_ENQUEUE_CMD_TARGET_TYPE_SHIFT);
3202 + d->tgtid = cpu_to_le32(fqid);
3206 + * qbman_eq_desc_set_qd() - Set Queuing Destination for the enqueue command
3207 + * @d: the enqueue descriptor
3208 + * @qdid: the id of the queuing destination to be enqueued
3209 + * @qd_bin: the queuing destination bin
3210 + * @qd_prio: the queuing destination priority
3212 +void qbman_eq_desc_set_qd(struct qbman_eq_desc *d, u32 qdid,
3213 + u32 qd_bin, u32 qd_prio)
3215 + d->verb |= 1 << QB_ENQUEUE_CMD_TARGET_TYPE_SHIFT;
3216 + d->tgtid = cpu_to_le32(qdid);
3217 + d->qdbin = cpu_to_le16(qd_bin);
3218 + d->qpri = qd_prio;
3221 +#define EQAR_IDX(eqar) ((eqar) & 0x7)
3222 +#define EQAR_VB(eqar) ((eqar) & 0x80)
3223 +#define EQAR_SUCCESS(eqar) ((eqar) & 0x100)
3226 + * qbman_swp_enqueue() - Issue an enqueue command
3227 + * @s: the software portal used for enqueue
3228 + * @d: the enqueue descriptor
3229 + * @fd: the frame descriptor to be enqueued
3231 + * Please note that 'fd' should only be NULL if the "action" of the
3232 + * descriptor is "orp_hole" or "orp_nesn".
3234 + * Return 0 for successful enqueue, -EBUSY if the EQCR is not ready.
3236 +int qbman_swp_enqueue(struct qbman_swp *s, const struct qbman_eq_desc *d,
3237 + const struct dpaa2_fd *fd)
3239 + struct qbman_eq_desc *p;
3240 + u32 eqar = qbman_read_register(s, QBMAN_CINH_SWP_EQAR);
3242 + if (!EQAR_SUCCESS(eqar))
3245 + p = qbman_get_cmd(s, QBMAN_CENA_SWP_EQCR(EQAR_IDX(eqar)));
3246 + memcpy(&p->dca, &d->dca, 31);
3247 + memcpy(&p->fd, fd, sizeof(*fd));
3249 + /* Set the verb byte, have to substitute in the valid-bit */
3251 + p->verb = d->verb | EQAR_VB(eqar);
3257 +/* Static (push) dequeue */
3260 + * qbman_swp_push_get() - Get the push dequeue setup
3261 + * @p: the software portal object
3262 + * @channel_idx: the channel index to query
3263 + * @enabled: returned boolean to show whether the push dequeue is enabled
3264 + * for the given channel
3266 +void qbman_swp_push_get(struct qbman_swp *s, u8 channel_idx, int *enabled)
3268 + u16 src = (s->sdq >> QB_SDQCR_SRC_SHIFT) & QB_SDQCR_SRC_MASK;
3270 + WARN_ON(channel_idx > 15);
3271 + *enabled = src | (1 << channel_idx);
3275 + * qbman_swp_push_set() - Enable or disable push dequeue
3276 + * @p: the software portal object
3277 + * @channel_idx: the channel index (0 to 15)
3278 + * @enable: enable or disable push dequeue
3280 +void qbman_swp_push_set(struct qbman_swp *s, u8 channel_idx, int enable)
3284 + WARN_ON(channel_idx > 15);
3286 + s->sdq |= 1 << channel_idx;
3288 + s->sdq &= ~(1 << channel_idx);
3290 + /* Read make the complete src map. If no channels are enabled
3291 + * the SDQCR must be 0 or else QMan will assert errors
3293 + dqsrc = (s->sdq >> QB_SDQCR_SRC_SHIFT) & QB_SDQCR_SRC_MASK;
3295 + qbman_write_register(s, QBMAN_CINH_SWP_SDQCR, s->sdq);
3297 + qbman_write_register(s, QBMAN_CINH_SWP_SDQCR, 0);
3300 +#define QB_VDQCR_VERB_DCT_SHIFT 0
3301 +#define QB_VDQCR_VERB_DT_SHIFT 2
3302 +#define QB_VDQCR_VERB_RLS_SHIFT 4
3303 +#define QB_VDQCR_VERB_WAE_SHIFT 5
3305 +enum qb_pull_dt_e {
3306 + qb_pull_dt_channel,
3307 + qb_pull_dt_workqueue,
3308 + qb_pull_dt_framequeue
3312 + * qbman_pull_desc_clear() - Clear the contents of a descriptor to
3313 + * default/starting state
3314 + * @d: the pull dequeue descriptor to be cleared
3316 +void qbman_pull_desc_clear(struct qbman_pull_desc *d)
3318 + memset(d, 0, sizeof(*d));
3322 + * qbman_pull_desc_set_storage()- Set the pull dequeue storage
3323 + * @d: the pull dequeue descriptor to be set
3324 + * @storage: the pointer of the memory to store the dequeue result
3325 + * @storage_phys: the physical address of the storage memory
3326 + * @stash: to indicate whether write allocate is enabled
3328 + * If not called, or if called with 'storage' as NULL, the result pull dequeues
3329 + * will produce results to DQRR. If 'storage' is non-NULL, then results are
3330 + * produced to the given memory location (using the DMA address which
3331 + * the caller provides in 'storage_phys'), and 'stash' controls whether or not
3332 + * those writes to main-memory express a cache-warming attribute.
3334 +void qbman_pull_desc_set_storage(struct qbman_pull_desc *d,
3335 + struct dpaa2_dq *storage,
3336 + dma_addr_t storage_phys,
3339 + /* save the virtual address */
3340 + d->rsp_addr_virt = (u64)storage;
3343 + d->verb &= ~(1 << QB_VDQCR_VERB_RLS_SHIFT);
3346 + d->verb |= 1 << QB_VDQCR_VERB_RLS_SHIFT;
3348 + d->verb |= 1 << QB_VDQCR_VERB_WAE_SHIFT;
3350 + d->verb &= ~(1 << QB_VDQCR_VERB_WAE_SHIFT);
3352 + d->rsp_addr = cpu_to_le64(storage_phys);
3356 + * qbman_pull_desc_set_numframes() - Set the number of frames to be dequeued
3357 + * @d: the pull dequeue descriptor to be set
3358 + * @numframes: number of frames to be set, must be between 1 and 16, inclusive
3360 +void qbman_pull_desc_set_numframes(struct qbman_pull_desc *d, u8 numframes)
3362 + d->numf = numframes - 1;
3365 +void qbman_pull_desc_set_token(struct qbman_pull_desc *d, u8 token)
3371 + * Exactly one of the following descriptor "actions" should be set. (Calling any
3372 + * one of these will replace the effect of any prior call to one of these.)
3373 + * - pull dequeue from the given frame queue (FQ)
3374 + * - pull dequeue from any FQ in the given work queue (WQ)
3375 + * - pull dequeue from any FQ in any WQ in the given channel
3379 + * qbman_pull_desc_set_fq() - Set fqid from which the dequeue command dequeues
3380 + * @fqid: the frame queue index of the given FQ
3382 +void qbman_pull_desc_set_fq(struct qbman_pull_desc *d, u32 fqid)
3384 + d->verb |= 1 << QB_VDQCR_VERB_DCT_SHIFT;
3385 + d->verb |= qb_pull_dt_framequeue << QB_VDQCR_VERB_DT_SHIFT;
3386 + d->dq_src = cpu_to_le32(fqid);
3390 + * qbman_pull_desc_set_wq() - Set wqid from which the dequeue command dequeues
3391 + * @wqid: composed of channel id and wqid within the channel
3392 + * @dct: the dequeue command type
3394 +void qbman_pull_desc_set_wq(struct qbman_pull_desc *d, u32 wqid,
3395 + enum qbman_pull_type_e dct)
3397 + d->verb |= dct << QB_VDQCR_VERB_DCT_SHIFT;
3398 + d->verb |= qb_pull_dt_workqueue << QB_VDQCR_VERB_DT_SHIFT;
3399 + d->dq_src = cpu_to_le32(wqid);
3403 + * qbman_pull_desc_set_channel() - Set channelid from which the dequeue command
3405 + * @chid: the channel id to be dequeued
3406 + * @dct: the dequeue command type
3408 +void qbman_pull_desc_set_channel(struct qbman_pull_desc *d, u32 chid,
3409 + enum qbman_pull_type_e dct)
3411 + d->verb |= dct << QB_VDQCR_VERB_DCT_SHIFT;
3412 + d->verb |= qb_pull_dt_channel << QB_VDQCR_VERB_DT_SHIFT;
3413 + d->dq_src = cpu_to_le32(chid);
3417 + * qbman_swp_pull() - Issue the pull dequeue command
3418 + * @s: the software portal object
3419 + * @d: the software portal descriptor which has been configured with
3420 + * the set of qbman_pull_desc_set_*() calls
3422 + * Return 0 for success, and -EBUSY if the software portal is not ready
3423 + * to do pull dequeue.
3425 +int qbman_swp_pull(struct qbman_swp *s, struct qbman_pull_desc *d)
3427 + struct qbman_pull_desc *p;
3429 + if (!atomic_dec_and_test(&s->vdq.available)) {
3430 + atomic_inc(&s->vdq.available);
3433 + s->vdq.storage = (void *)d->rsp_addr_virt;
3434 + p = qbman_get_cmd(s, QBMAN_CENA_SWP_VDQCR);
3435 + p->numf = d->numf;
3436 + p->tok = QMAN_DQ_TOKEN_VALID;
3437 + p->dq_src = d->dq_src;
3438 + p->rsp_addr = d->rsp_addr;
3439 + p->rsp_addr_virt = d->rsp_addr_virt;
3442 + /* Set the verb byte, have to substitute in the valid-bit */
3443 + p->verb = d->verb | s->vdq.valid_bit;
3444 + s->vdq.valid_bit ^= QB_VALID_BIT;
3450 +#define QMAN_DQRR_PI_MASK 0xf
3453 + * qbman_swp_dqrr_next() - Get an valid DQRR entry
3454 + * @s: the software portal object
3456 + * Return NULL if there are no unconsumed DQRR entries. Return a DQRR entry
3457 + * only once, so repeated calls can return a sequence of DQRR entries, without
3458 + * requiring they be consumed immediately or in any particular order.
3460 +const struct dpaa2_dq *qbman_swp_dqrr_next(struct qbman_swp *s)
3463 + u32 response_verb;
3465 + struct dpaa2_dq *p;
3467 + /* Before using valid-bit to detect if something is there, we have to
3468 + * handle the case of the DQRR reset bug...
3470 + if (unlikely(s->dqrr.reset_bug)) {
3472 + * We pick up new entries by cache-inhibited producer index,
3473 + * which means that a non-coherent mapping would require us to
3474 + * invalidate and read *only* once that PI has indicated that
3475 + * there's an entry here. The first trip around the DQRR ring
3476 + * will be much less efficient than all subsequent trips around
3479 + u8 pi = qbman_read_register(s, QBMAN_CINH_SWP_DQPI) &
3480 + QMAN_DQRR_PI_MASK;
3482 + /* there are new entries if pi != next_idx */
3483 + if (pi == s->dqrr.next_idx)
3487 + * if next_idx is/was the last ring index, and 'pi' is
3488 + * different, we can disable the workaround as all the ring
3489 + * entries have now been DMA'd to so valid-bit checking is
3490 + * repaired. Note: this logic needs to be based on next_idx
3491 + * (which increments one at a time), rather than on pi (which
3492 + * can burst and wrap-around between our snapshots of it).
3494 + if (s->dqrr.next_idx == (s->dqrr.dqrr_size - 1)) {
3495 + pr_debug("next_idx=%d, pi=%d, clear reset bug\n",
3496 + s->dqrr.next_idx, pi);
3497 + s->dqrr.reset_bug = 0;
3499 + qbman_inval_prefetch(s, QBMAN_CENA_SWP_DQRR(s->dqrr.next_idx));
3502 + p = qbman_get_cmd(s, QBMAN_CENA_SWP_DQRR(s->dqrr.next_idx));
3503 + verb = p->dq.verb;
3506 + * If the valid-bit isn't of the expected polarity, nothing there. Note,
3507 + * in the DQRR reset bug workaround, we shouldn't need to skip these
3508 + * check, because we've already determined that a new entry is available
3509 + * and we've invalidated the cacheline before reading it, so the
3510 + * valid-bit behaviour is repaired and should tell us what we already
3511 + * knew from reading PI.
3513 + if ((verb & QB_VALID_BIT) != s->dqrr.valid_bit) {
3514 + qbman_inval_prefetch(s, QBMAN_CENA_SWP_DQRR(s->dqrr.next_idx));
3518 + * There's something there. Move "next_idx" attention to the next ring
3519 + * entry (and prefetch it) before returning what we found.
3521 + s->dqrr.next_idx++;
3522 + s->dqrr.next_idx &= s->dqrr.dqrr_size - 1; /* Wrap around */
3523 + if (!s->dqrr.next_idx)
3524 + s->dqrr.valid_bit ^= QB_VALID_BIT;
3527 + * If this is the final response to a volatile dequeue command
3528 + * indicate that the vdq is available
3530 + flags = p->dq.stat;
3531 + response_verb = verb & QBMAN_RESULT_MASK;
3532 + if ((response_verb == QBMAN_RESULT_DQ) &&
3533 + (flags & DPAA2_DQ_STAT_VOLATILE) &&
3534 + (flags & DPAA2_DQ_STAT_EXPIRED))
3535 + atomic_inc(&s->vdq.available);
3537 + qbman_inval_prefetch(s, QBMAN_CENA_SWP_DQRR(s->dqrr.next_idx));
3543 + * qbman_swp_dqrr_consume() - Consume DQRR entries previously returned from
3544 + * qbman_swp_dqrr_next().
3545 + * @s: the software portal object
3546 + * @dq: the DQRR entry to be consumed
3548 +void qbman_swp_dqrr_consume(struct qbman_swp *s, const struct dpaa2_dq *dq)
3550 + qbman_write_register(s, QBMAN_CINH_SWP_DCAP, QBMAN_IDX_FROM_DQRR(dq));
3554 + * qbman_result_has_new_result() - Check and get the dequeue response from the
3555 + * dq storage memory set in pull dequeue command
3556 + * @s: the software portal object
3557 + * @dq: the dequeue result read from the memory
3559 + * Return 1 for getting a valid dequeue result, or 0 for not getting a valid
3562 + * Only used for user-provided storage of dequeue results, not DQRR. For
3563 + * efficiency purposes, the driver will perform any required endianness
3564 + * conversion to ensure that the user's dequeue result storage is in host-endian
3565 + * format. As such, once the user has called qbman_result_has_new_result() and
3566 + * been returned a valid dequeue result, they should not call it again on
3567 + * the same memory location (except of course if another dequeue command has
3568 + * been executed to produce a new result to that location).
3570 +int qbman_result_has_new_result(struct qbman_swp *s, const struct dpaa2_dq *dq)
3572 + if (dq->dq.tok != QMAN_DQ_TOKEN_VALID)
3576 + * Set token to be 0 so we will detect change back to 1
3577 + * next time the looping is traversed. Const is cast away here
3578 + * as we want users to treat the dequeue responses as read only.
3580 + ((struct dpaa2_dq *)dq)->dq.tok = 0;
3583 + * Determine whether VDQCR is available based on whether the
3584 + * current result is sitting in the first storage location of
3585 + * the busy command.
3587 + if (s->vdq.storage == dq) {
3588 + s->vdq.storage = NULL;
3589 + atomic_inc(&s->vdq.available);
3596 + * qbman_release_desc_clear() - Clear the contents of a descriptor to
3597 + * default/starting state.
3599 +void qbman_release_desc_clear(struct qbman_release_desc *d)
3601 + memset(d, 0, sizeof(*d));
3602 + d->verb = 1 << 5; /* Release Command Valid */
3606 + * qbman_release_desc_set_bpid() - Set the ID of the buffer pool to release to
3608 +void qbman_release_desc_set_bpid(struct qbman_release_desc *d, u16 bpid)
3610 + d->bpid = cpu_to_le16(bpid);
3614 + * qbman_release_desc_set_rcdi() - Determines whether or not the portal's RCDI
3615 + * interrupt source should be asserted after the release command is completed.
3617 +void qbman_release_desc_set_rcdi(struct qbman_release_desc *d, int enable)
3620 + d->verb |= 1 << 6;
3622 + d->verb &= ~(1 << 6);
3625 +#define RAR_IDX(rar) ((rar) & 0x7)
3626 +#define RAR_VB(rar) ((rar) & 0x80)
3627 +#define RAR_SUCCESS(rar) ((rar) & 0x100)
3630 + * qbman_swp_release() - Issue a buffer release command
3631 + * @s: the software portal object
3632 + * @d: the release descriptor
3633 + * @buffers: a pointer pointing to the buffer address to be released
3634 + * @num_buffers: number of buffers to be released, must be less than 8
3636 + * Return 0 for success, -EBUSY if the release command ring is not ready.
3638 +int qbman_swp_release(struct qbman_swp *s, const struct qbman_release_desc *d,
3639 + const u64 *buffers, unsigned int num_buffers)
3642 + struct qbman_release_desc *p;
3645 + if (!num_buffers || (num_buffers > 7))
3648 + rar = qbman_read_register(s, QBMAN_CINH_SWP_RAR);
3649 + if (!RAR_SUCCESS(rar))
3652 + /* Start the release command */
3653 + p = qbman_get_cmd(s, QBMAN_CENA_SWP_RCR(RAR_IDX(rar)));
3654 + /* Copy the caller's buffer pointers to the command */
3655 + for (i = 0; i < num_buffers; i++)
3656 + p->buf[i] = cpu_to_le64(buffers[i]);
3657 + p->bpid = d->bpid;
3660 + * Set the verb byte, have to substitute in the valid-bit and the number
3664 + p->verb = d->verb | RAR_VB(rar) | num_buffers;
3670 +struct qbman_acquire_desc {
3678 +struct qbman_acquire_rslt {
3688 + * qbman_swp_acquire() - Issue a buffer acquire command
3689 + * @s: the software portal object
3690 + * @bpid: the buffer pool index
3691 + * @buffers: a pointer pointing to the acquired buffer addresses
3692 + * @num_buffers: number of buffers to be acquired, must be less than 8
3694 + * Return 0 for success, or negative error code if the acquire command
3697 +int qbman_swp_acquire(struct qbman_swp *s, u16 bpid, u64 *buffers,
3698 + unsigned int num_buffers)
3700 + struct qbman_acquire_desc *p;
3701 + struct qbman_acquire_rslt *r;
3704 + if (!num_buffers || (num_buffers > 7))
3707 + /* Start the management command */
3708 + p = qbman_swp_mc_start(s);
3713 + /* Encode the caller-provided attributes */
3714 + p->bpid = cpu_to_le16(bpid);
3715 + p->num = num_buffers;
3717 + /* Complete the management command */
3718 + r = qbman_swp_mc_complete(s, p, QBMAN_MC_ACQUIRE);
3719 + if (unlikely(!r)) {
3720 + pr_err("qbman: acquire from BPID %d failed, no response\n",
3725 + /* Decode the outcome */
3726 + WARN_ON((r->verb & 0x7f) != QBMAN_MC_ACQUIRE);
3728 + /* Determine success or failure */
3729 + if (unlikely(r->rslt != QBMAN_MC_RSLT_OK)) {
3730 + pr_err("qbman: acquire from BPID 0x%x failed, code=0x%02x\n",
3735 + WARN_ON(r->num > num_buffers);
3737 + /* Copy the acquired buffers to the caller's array */
3738 + for (i = 0; i < r->num; i++)
3739 + buffers[i] = le64_to_cpu(r->buf[i]);
3741 + return (int)r->num;
3744 +struct qbman_alt_fq_state_desc {
3751 +struct qbman_alt_fq_state_rslt {
3757 +#define ALT_FQ_FQID_MASK 0x00FFFFFF
3759 +int qbman_swp_alt_fq_state(struct qbman_swp *s, u32 fqid,
3762 + struct qbman_alt_fq_state_desc *p;
3763 + struct qbman_alt_fq_state_rslt *r;
3765 + /* Start the management command */
3766 + p = qbman_swp_mc_start(s);
3770 + p->fqid = cpu_to_le32(fqid) & ALT_FQ_FQID_MASK;
3772 + /* Complete the management command */
3773 + r = qbman_swp_mc_complete(s, p, alt_fq_verb);
3774 + if (unlikely(!r)) {
3775 + pr_err("qbman: mgmt cmd failed, no response (verb=0x%x)\n",
3780 + /* Decode the outcome */
3781 + WARN_ON((r->verb & QBMAN_RESULT_MASK) != alt_fq_verb);
3783 + /* Determine success or failure */
3784 + if (unlikely(r->rslt != QBMAN_MC_RSLT_OK)) {
3785 + pr_err("qbman: ALT FQID %d failed: verb = 0x%08x code = 0x%02x\n",
3786 + fqid, r->verb, r->rslt);
3793 +struct qbman_cdan_ctrl_desc {
3805 +struct qbman_cdan_ctrl_rslt {
3812 +int qbman_swp_CDAN_set(struct qbman_swp *s, u16 channelid,
3813 + u8 we_mask, u8 cdan_en,
3816 + struct qbman_cdan_ctrl_desc *p = NULL;
3817 + struct qbman_cdan_ctrl_rslt *r = NULL;
3819 + /* Start the management command */
3820 + p = qbman_swp_mc_start(s);
3824 + /* Encode the caller-provided attributes */
3825 + p->ch = cpu_to_le16(channelid);
3831 + p->cdan_ctx = cpu_to_le64(ctx);
3833 + /* Complete the management command */
3834 + r = qbman_swp_mc_complete(s, p, QBMAN_WQCHAN_CONFIGURE);
3835 + if (unlikely(!r)) {
3836 + pr_err("qbman: wqchan config failed, no response\n");
3840 + WARN_ON((r->verb & 0x7f) != QBMAN_WQCHAN_CONFIGURE);
3842 + /* Determine success or failure */
3843 + if (unlikely(r->rslt != QBMAN_MC_RSLT_OK)) {
3844 + pr_err("qbman: CDAN cQID %d failed: code = 0x%02x\n",
3845 + channelid, r->rslt);
3851 diff --git a/drivers/staging/fsl-mc/bus/dpio/qbman-portal.h b/drivers/staging/fsl-mc/bus/dpio/qbman-portal.h
3852 new file mode 100644
3853 index 00000000..4254034c
3855 +++ b/drivers/staging/fsl-mc/bus/dpio/qbman-portal.h
3858 + * Copyright (C) 2014-2016 Freescale Semiconductor, Inc.
3859 + * Copyright 2016 NXP
3861 + * Redistribution and use in source and binary forms, with or without
3862 + * modification, are permitted provided that the following conditions are met:
3863 + * * Redistributions of source code must retain the above copyright
3864 + * notice, this list of conditions and the following disclaimer.
3865 + * * Redistributions in binary form must reproduce the above copyright
3866 + * notice, this list of conditions and the following disclaimer in the
3867 + * documentation and/or other materials provided with the distribution.
3868 + * * Neither the name of Freescale Semiconductor nor the
3869 + * names of its contributors may be used to endorse or promote products
3870 + * derived from this software without specific prior written permission.
3872 + * ALTERNATIVELY, this software may be distributed under the terms of the
3873 + * GNU General Public License ("GPL") as published by the Free Software
3874 + * Foundation, either version 2 of that License or (at your option) any
3877 + * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
3878 + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
3879 + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
3880 + * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
3881 + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
3882 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
3883 + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
3884 + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
3885 + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
3886 + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3888 +#ifndef __FSL_QBMAN_PORTAL_H
3889 +#define __FSL_QBMAN_PORTAL_H
3891 +#include "qbman_private.h"
3892 +#include "../../include/dpaa2-fd.h"
3897 +/* qbman software portal descriptor structure */
3898 +struct qbman_swp_desc {
3899 + void *cena_bar; /* Cache-enabled portal base address */
3900 + void *cinh_bar; /* Cache-inhibited portal base address */
3904 +#define QBMAN_SWP_INTERRUPT_EQRI 0x01
3905 +#define QBMAN_SWP_INTERRUPT_EQDI 0x02
3906 +#define QBMAN_SWP_INTERRUPT_DQRI 0x04
3907 +#define QBMAN_SWP_INTERRUPT_RCRI 0x08
3908 +#define QBMAN_SWP_INTERRUPT_RCDI 0x10
3909 +#define QBMAN_SWP_INTERRUPT_VDCI 0x20
3911 +/* the structure for pull dequeue descriptor */
3912 +struct qbman_pull_desc {
3919 + u64 rsp_addr_virt;
3923 +enum qbman_pull_type_e {
3924 + /* dequeue with priority precedence, respect intra-class scheduling */
3925 + qbman_pull_type_prio = 1,
3926 + /* dequeue with active FQ precedence, respect ICS */
3927 + qbman_pull_type_active,
3928 + /* dequeue with active FQ precedence, no ICS */
3929 + qbman_pull_type_active_noics
3932 +/* Definitions for parsing dequeue entries */
3933 +#define QBMAN_RESULT_MASK 0x7f
3934 +#define QBMAN_RESULT_DQ 0x60
3935 +#define QBMAN_RESULT_FQRN 0x21
3936 +#define QBMAN_RESULT_FQRNI 0x22
3937 +#define QBMAN_RESULT_FQPN 0x24
3938 +#define QBMAN_RESULT_FQDAN 0x25
3939 +#define QBMAN_RESULT_CDAN 0x26
3940 +#define QBMAN_RESULT_CSCN_MEM 0x27
3941 +#define QBMAN_RESULT_CGCU 0x28
3942 +#define QBMAN_RESULT_BPSCN 0x29
3943 +#define QBMAN_RESULT_CSCN_WQ 0x2a
3945 +/* QBMan FQ management command codes */
3946 +#define QBMAN_FQ_SCHEDULE 0x48
3947 +#define QBMAN_FQ_FORCE 0x49
3948 +#define QBMAN_FQ_XON 0x4d
3949 +#define QBMAN_FQ_XOFF 0x4e
3951 +/* structure of enqueue descriptor */
3952 +struct qbman_eq_desc {
3969 +/* buffer release descriptor */
3970 +struct qbman_release_desc {
3978 +/* Management command result codes */
3979 +#define QBMAN_MC_RSLT_OK 0xf0
3981 +#define CODE_CDAN_WE_EN 0x1
3982 +#define CODE_CDAN_WE_CTX 0x4
3984 +/* portal data structure */
3986 + const struct qbman_swp_desc *desc;
3987 + void __iomem *addr_cena;
3988 + void __iomem *addr_cinh;
3990 + /* Management commands */
3992 + u32 valid_bit; /* 0x00 or 0x80 */
3995 + /* Push dequeues */
3998 + /* Volatile dequeues */
4000 + atomic_t available; /* indicates if a command can be sent */
4001 + u32 valid_bit; /* 0x00 or 0x80 */
4002 + struct dpaa2_dq *storage; /* NULL if DQRR */
4010 + int reset_bug; /* indicates dqrr reset workaround is needed */
4014 +struct qbman_swp *qbman_swp_init(const struct qbman_swp_desc *d);
4015 +void qbman_swp_finish(struct qbman_swp *p);
4016 +u32 qbman_swp_interrupt_read_status(struct qbman_swp *p);
4017 +void qbman_swp_interrupt_clear_status(struct qbman_swp *p, u32 mask);
4018 +u32 qbman_swp_interrupt_get_trigger(struct qbman_swp *p);
4019 +void qbman_swp_interrupt_set_trigger(struct qbman_swp *p, u32 mask);
4020 +int qbman_swp_interrupt_get_inhibit(struct qbman_swp *p);
4021 +void qbman_swp_interrupt_set_inhibit(struct qbman_swp *p, int inhibit);
4023 +void qbman_swp_push_get(struct qbman_swp *p, u8 channel_idx, int *enabled);
4024 +void qbman_swp_push_set(struct qbman_swp *p, u8 channel_idx, int enable);
4026 +void qbman_pull_desc_clear(struct qbman_pull_desc *d);
4027 +void qbman_pull_desc_set_storage(struct qbman_pull_desc *d,
4028 + struct dpaa2_dq *storage,
4029 + dma_addr_t storage_phys,
4031 +void qbman_pull_desc_set_numframes(struct qbman_pull_desc *d, u8 numframes);
4032 +void qbman_pull_desc_set_fq(struct qbman_pull_desc *d, u32 fqid);
4033 +void qbman_pull_desc_set_wq(struct qbman_pull_desc *d, u32 wqid,
4034 + enum qbman_pull_type_e dct);
4035 +void qbman_pull_desc_set_channel(struct qbman_pull_desc *d, u32 chid,
4036 + enum qbman_pull_type_e dct);
4038 +int qbman_swp_pull(struct qbman_swp *p, struct qbman_pull_desc *d);
4040 +const struct dpaa2_dq *qbman_swp_dqrr_next(struct qbman_swp *s);
4041 +void qbman_swp_dqrr_consume(struct qbman_swp *s, const struct dpaa2_dq *dq);
4043 +int qbman_result_has_new_result(struct qbman_swp *p, const struct dpaa2_dq *dq);
4045 +void qbman_eq_desc_clear(struct qbman_eq_desc *d);
4046 +void qbman_eq_desc_set_no_orp(struct qbman_eq_desc *d, int respond_success);
4047 +void qbman_eq_desc_set_token(struct qbman_eq_desc *d, u8 token);
4048 +void qbman_eq_desc_set_fq(struct qbman_eq_desc *d, u32 fqid);
4049 +void qbman_eq_desc_set_qd(struct qbman_eq_desc *d, u32 qdid,
4050 + u32 qd_bin, u32 qd_prio);
4052 +int qbman_swp_enqueue(struct qbman_swp *p, const struct qbman_eq_desc *d,
4053 + const struct dpaa2_fd *fd);
4055 +void qbman_release_desc_clear(struct qbman_release_desc *d);
4056 +void qbman_release_desc_set_bpid(struct qbman_release_desc *d, u16 bpid);
4057 +void qbman_release_desc_set_rcdi(struct qbman_release_desc *d, int enable);
4059 +int qbman_swp_release(struct qbman_swp *s, const struct qbman_release_desc *d,
4060 + const u64 *buffers, unsigned int num_buffers);
4061 +int qbman_swp_acquire(struct qbman_swp *s, u16 bpid, u64 *buffers,
4062 + unsigned int num_buffers);
4063 +int qbman_swp_alt_fq_state(struct qbman_swp *s, u32 fqid,
4065 +int qbman_swp_CDAN_set(struct qbman_swp *s, u16 channelid,
4066 + u8 we_mask, u8 cdan_en,
4069 +void *qbman_swp_mc_start(struct qbman_swp *p);
4070 +void qbman_swp_mc_submit(struct qbman_swp *p, void *cmd, u8 cmd_verb);
4071 +void *qbman_swp_mc_result(struct qbman_swp *p);
4074 + * qbman_result_is_DQ() - check if the dequeue result is a dequeue response
4075 + * @dq: the dequeue result to be checked
4077 + * DQRR entries may contain non-dequeue results, ie. notifications
4079 +static inline int qbman_result_is_DQ(const struct dpaa2_dq *dq)
4081 + return ((dq->dq.verb & QBMAN_RESULT_MASK) == QBMAN_RESULT_DQ);
4085 + * qbman_result_is_SCN() - Check the dequeue result is notification or not
4086 + * @dq: the dequeue result to be checked
4089 +static inline int qbman_result_is_SCN(const struct dpaa2_dq *dq)
4091 + return !qbman_result_is_DQ(dq);
4094 +/* FQ Data Availability */
4095 +static inline int qbman_result_is_FQDAN(const struct dpaa2_dq *dq)
4097 + return ((dq->dq.verb & QBMAN_RESULT_MASK) == QBMAN_RESULT_FQDAN);
4100 +/* Channel Data Availability */
4101 +static inline int qbman_result_is_CDAN(const struct dpaa2_dq *dq)
4103 + return ((dq->dq.verb & QBMAN_RESULT_MASK) == QBMAN_RESULT_CDAN);
4106 +/* Congestion State Change */
4107 +static inline int qbman_result_is_CSCN(const struct dpaa2_dq *dq)
4109 + return ((dq->dq.verb & QBMAN_RESULT_MASK) == QBMAN_RESULT_CSCN_WQ);
4112 +/* Buffer Pool State Change */
4113 +static inline int qbman_result_is_BPSCN(const struct dpaa2_dq *dq)
4115 + return ((dq->dq.verb & QBMAN_RESULT_MASK) == QBMAN_RESULT_BPSCN);
4118 +/* Congestion Group Count Update */
4119 +static inline int qbman_result_is_CGCU(const struct dpaa2_dq *dq)
4121 + return ((dq->dq.verb & QBMAN_RESULT_MASK) == QBMAN_RESULT_CGCU);
4125 +static inline int qbman_result_is_FQRN(const struct dpaa2_dq *dq)
4127 + return ((dq->dq.verb & QBMAN_RESULT_MASK) == QBMAN_RESULT_FQRN);
4130 +/* Retirement Immediate */
4131 +static inline int qbman_result_is_FQRNI(const struct dpaa2_dq *dq)
4133 + return ((dq->dq.verb & QBMAN_RESULT_MASK) == QBMAN_RESULT_FQRNI);
4137 +static inline int qbman_result_is_FQPN(const struct dpaa2_dq *dq)
4139 + return ((dq->dq.verb & QBMAN_RESULT_MASK) == QBMAN_RESULT_FQPN);
4143 + * qbman_result_SCN_state() - Get the state field in State-change notification
4145 +static inline u8 qbman_result_SCN_state(const struct dpaa2_dq *scn)
4147 + return scn->scn.state;
4150 +#define SCN_RID_MASK 0x00FFFFFF
4153 + * qbman_result_SCN_rid() - Get the resource id in State-change notification
4155 +static inline u32 qbman_result_SCN_rid(const struct dpaa2_dq *scn)
4157 + return le32_to_cpu(scn->scn.rid_tok) & SCN_RID_MASK;
4161 + * qbman_result_SCN_ctx() - Get the context data in State-change notification
4163 +static inline u64 qbman_result_SCN_ctx(const struct dpaa2_dq *scn)
4165 + return le64_to_cpu(scn->scn.ctx);
4169 + * qbman_swp_fq_schedule() - Move the fq to the scheduled state
4170 + * @s: the software portal object
4171 + * @fqid: the index of frame queue to be scheduled
4173 + * There are a couple of different ways that a FQ can end up parked state,
4174 + * This schedules it.
4176 + * Return 0 for success, or negative error code for failure.
4178 +static inline int qbman_swp_fq_schedule(struct qbman_swp *s, u32 fqid)
4180 + return qbman_swp_alt_fq_state(s, fqid, QBMAN_FQ_SCHEDULE);
4184 + * qbman_swp_fq_force() - Force the FQ to fully scheduled state
4185 + * @s: the software portal object
4186 + * @fqid: the index of frame queue to be forced
4188 + * Force eligible will force a tentatively-scheduled FQ to be fully-scheduled
4189 + * and thus be available for selection by any channel-dequeuing behaviour (push
4190 + * or pull). If the FQ is subsequently "dequeued" from the channel and is still
4191 + * empty at the time this happens, the resulting dq_entry will have no FD.
4192 + * (qbman_result_DQ_fd() will return NULL.)
4194 + * Return 0 for success, or negative error code for failure.
4196 +static inline int qbman_swp_fq_force(struct qbman_swp *s, u32 fqid)
4198 + return qbman_swp_alt_fq_state(s, fqid, QBMAN_FQ_FORCE);
4202 + * qbman_swp_fq_xon() - sets FQ flow-control to XON
4203 + * @s: the software portal object
4204 + * @fqid: the index of frame queue
4206 + * This setting doesn't affect enqueues to the FQ, just dequeues.
4208 + * Return 0 for success, or negative error code for failure.
4210 +static inline int qbman_swp_fq_xon(struct qbman_swp *s, u32 fqid)
4212 + return qbman_swp_alt_fq_state(s, fqid, QBMAN_FQ_XON);
4216 + * qbman_swp_fq_xoff() - sets FQ flow-control to XOFF
4217 + * @s: the software portal object
4218 + * @fqid: the index of frame queue
4220 + * This setting doesn't affect enqueues to the FQ, just dequeues.
4221 + * XOFF FQs will remain in the tenatively-scheduled state, even when
4222 + * non-empty, meaning they won't be selected for scheduled dequeuing.
4223 + * If a FQ is changed to XOFF after it had already become truly-scheduled
4224 + * to a channel, and a pull dequeue of that channel occurs that selects
4225 + * that FQ for dequeuing, then the resulting dq_entry will have no FD.
4226 + * (qbman_result_DQ_fd() will return NULL.)
4228 + * Return 0 for success, or negative error code for failure.
4230 +static inline int qbman_swp_fq_xoff(struct qbman_swp *s, u32 fqid)
4232 + return qbman_swp_alt_fq_state(s, fqid, QBMAN_FQ_XOFF);
4235 +/* If the user has been allocated a channel object that is going to generate
4236 + * CDANs to another channel, then the qbman_swp_CDAN* functions will be
4239 + * CDAN-enabled channels only generate a single CDAN notification, after which
4240 + * they need to be reenabled before they'll generate another. The idea is
4241 + * that pull dequeuing will occur in reaction to the CDAN, followed by a
4242 + * reenable step. Each function generates a distinct command to hardware, so a
4243 + * combination function is provided if the user wishes to modify the "context"
4244 + * (which shows up in each CDAN message) each time they reenable, as a single
4245 + * command to hardware.
4249 + * qbman_swp_CDAN_set_context() - Set CDAN context
4250 + * @s: the software portal object
4251 + * @channelid: the channel index
4252 + * @ctx: the context to be set in CDAN
4254 + * Return 0 for success, or negative error code for failure.
4256 +static inline int qbman_swp_CDAN_set_context(struct qbman_swp *s, u16 channelid,
4259 + return qbman_swp_CDAN_set(s, channelid,
4265 + * qbman_swp_CDAN_enable() - Enable CDAN for the channel
4266 + * @s: the software portal object
4267 + * @channelid: the index of the channel to generate CDAN
4269 + * Return 0 for success, or negative error code for failure.
4271 +static inline int qbman_swp_CDAN_enable(struct qbman_swp *s, u16 channelid)
4273 + return qbman_swp_CDAN_set(s, channelid,
4279 + * qbman_swp_CDAN_disable() - disable CDAN for the channel
4280 + * @s: the software portal object
4281 + * @channelid: the index of the channel to generate CDAN
4283 + * Return 0 for success, or negative error code for failure.
4285 +static inline int qbman_swp_CDAN_disable(struct qbman_swp *s, u16 channelid)
4287 + return qbman_swp_CDAN_set(s, channelid,
4293 + * qbman_swp_CDAN_set_context_enable() - Set CDAN contest and enable CDAN
4294 + * @s: the software portal object
4295 + * @channelid: the index of the channel to generate CDAN
4296 + * @ctx:i the context set in CDAN
4298 + * Return 0 for success, or negative error code for failure.
4300 +static inline int qbman_swp_CDAN_set_context_enable(struct qbman_swp *s,
4304 + return qbman_swp_CDAN_set(s, channelid,
4305 + CODE_CDAN_WE_EN | CODE_CDAN_WE_CTX,
4309 +/* Wraps up submit + poll-for-result */
4310 +static inline void *qbman_swp_mc_complete(struct qbman_swp *swp, void *cmd,
4313 + int loopvar = 1000;
4315 + qbman_swp_mc_submit(swp, cmd, cmd_verb);
4318 + cmd = qbman_swp_mc_result(swp);
4319 + } while (!cmd && loopvar--);
4321 + WARN_ON(!loopvar);
4330 +/* This struct locates a sub-field within a QBMan portal (CENA) cacheline which
4331 + * is either serving as a configuration command or a query result. The
4332 + * representation is inherently little-endian, as the indexing of the words is
4333 + * itself little-endian in nature and layerscape is little endian for anything
4334 + * that crosses a word boundary too (64-bit fields are the obvious examples).
4336 +struct qb_attr_code {
4337 + unsigned int word; /* which u32[] array member encodes the field */
4338 + unsigned int lsoffset; /* encoding offset from ls-bit */
4339 + unsigned int width; /* encoding width. (bool must be 1.) */
4342 +/* Some pre-defined codes */
4343 +extern struct qb_attr_code code_generic_verb;
4344 +extern struct qb_attr_code code_generic_rslt;
4346 +/* Macros to define codes */
4347 +#define QB_CODE(a, b, c) { a, b, c}
4348 +#define QB_CODE_NULL \
4349 + QB_CODE((unsigned int)-1, (unsigned int)-1, (unsigned int)-1)
4351 +/* Rotate a code "ms", meaning that it moves from less-significant bytes to
4352 + * more-significant, from less-significant words to more-significant, etc. The
4353 + * "ls" version does the inverse, from more-significant towards
4354 + * less-significant.
4356 +static inline void qb_attr_code_rotate_ms(struct qb_attr_code *code,
4357 + unsigned int bits)
4359 + code->lsoffset += bits;
4360 + while (code->lsoffset > 31) {
4362 + code->lsoffset -= 32;
4366 +static inline void qb_attr_code_rotate_ls(struct qb_attr_code *code,
4367 + unsigned int bits)
4369 + /* Don't be fooled, this trick should work because the types are
4370 + * unsigned. So the case that interests the while loop (the rotate has
4371 + * gone too far and the word count needs to compensate for it), is
4372 + * manifested when lsoffset is negative. But that equates to a really
4373 + * large unsigned value, starting with lots of "F"s. As such, we can
4374 + * continue adding 32 back to it until it wraps back round above zero,
4375 + * to a value of 31 or less...
4377 + code->lsoffset -= bits;
4378 + while (code->lsoffset > 31) {
4380 + code->lsoffset += 32;
4384 +/* Implement a loop of code rotations until 'expr' evaluates to FALSE (0). */
4385 +#define qb_attr_code_for_ms(code, bits, expr) \
4386 + for (; expr; qb_attr_code_rotate_ms(code, bits))
4387 +#define qb_attr_code_for_ls(code, bits, expr) \
4388 + for (; expr; qb_attr_code_rotate_ls(code, bits))
4390 +static inline void word_copy(void *d, const void *s, unsigned int cnt)
4393 + const u32 *ss = s;
4396 + *(dd++) = *(ss++);
4400 + * Currently, the CENA support code expects each 32-bit word to be written in
4401 + * host order, and these are converted to hardware (little-endian) order on
4402 + * command submission. However, 64-bit quantities are must be written (and read)
4403 + * as two 32-bit words with the least-significant word first, irrespective of
4404 + * host endianness.
4406 +static inline void u64_to_le32_copy(void *d, const u64 *s,
4410 + const u32 *ss = (const u32 *)s;
4414 + * TBD: the toolchain was choking on the use of 64-bit types up
4415 + * until recently so this works entirely with 32-bit variables.
4416 + * When 64-bit types become usable again, investigate better
4417 + * ways of doing this.
4419 +#if defined(__BIG_ENDIAN)
4424 + *(dd++) = *(ss++);
4425 + *(dd++) = *(ss++);
4430 +static inline void u64_from_le32_copy(u64 *d, const void *s,
4433 + const u32 *ss = s;
4434 + u32 *dd = (u32 *)d;
4437 +#if defined(__BIG_ENDIAN)
4442 + *(dd++) = *(ss++);
4443 + *(dd++) = *(ss++);
4448 +/* decode a field from a cacheline */
4449 +static inline u32 qb_attr_code_decode(const struct qb_attr_code *code,
4450 + const u32 *cacheline)
4452 + return d32_u32(code->lsoffset, code->width, cacheline[code->word]);
4455 +static inline u64 qb_attr_code_decode_64(const struct qb_attr_code *code,
4456 + const u64 *cacheline)
4460 + u64_from_le32_copy(&res, &cacheline[code->word / 2], 1);
4464 +/* encode a field to a cacheline */
4465 +static inline void qb_attr_code_encode(const struct qb_attr_code *code,
4466 + u32 *cacheline, u32 val)
4468 + cacheline[code->word] =
4469 + r32_u32(code->lsoffset, code->width, cacheline[code->word])
4470 + | e32_u32(code->lsoffset, code->width, val);
4473 +static inline void qb_attr_code_encode_64(const struct qb_attr_code *code,
4474 + u64 *cacheline, u64 val)
4476 + u64_to_le32_copy(&cacheline[code->word / 2], &val, 1);
4479 +/* Small-width signed values (two's-complement) will decode into medium-width
4480 + * positives. (Eg. for an 8-bit signed field, which stores values from -128 to
4481 + * +127, a setting of -7 would appear to decode to the 32-bit unsigned value
4482 + * 249. Likewise -120 would decode as 136.) This function allows the caller to
4483 + * "re-sign" such fields to 32-bit signed. (Eg. -7, which was 249 with an 8-bit
4484 + * encoding, will become 0xfffffff9 if you cast the return value to u32).
4486 +static inline int32_t qb_attr_code_makesigned(const struct qb_attr_code *code,
4489 + WARN_ON(val >= (1 << code->width));
4490 + /* If the high bit was set, it was encoding a negative */
4491 + if (val >= (1 << (code->width - 1)))
4492 + return (int32_t)0 - (int32_t)(((u32)1 << code->width) -
4494 + /* Otherwise, it was encoding a positive */
4495 + return (int32_t)val;
4498 +/* ---------------------- */
4499 +/* Descriptors/cachelines */
4500 +/* ---------------------- */
4502 +/* To avoid needless dynamic allocation, the driver API often gives the caller
4503 + * a "descriptor" type that the caller can instantiate however they like.
4504 + * Ultimately though, it is just a cacheline of binary storage (or something
4505 + * smaller when it is known that the descriptor doesn't need all 64 bytes) for
4506 + * holding pre-formatted pieces of hardware commands. The performance-critical
4507 + * code can then copy these descriptors directly into hardware command
4508 + * registers more efficiently than trying to construct/format commands
4509 + * on-the-fly. The API user sees the descriptor as an array of 32-bit words in
4510 + * order for the compiler to know its size, but the internal details are not
4511 + * exposed. The following macro is used within the driver for converting *any*
4512 + * descriptor pointer to a usable array pointer. The use of a macro (instead of
4513 + * an inline) is necessary to work with different descriptor types and to work
4514 + * correctly with const and non-const inputs (and similarly-qualified outputs).
4516 +#define qb_cl(d) (&(d)->dont_manipulate_directly[0])
4518 +#endif /* __FSL_QBMAN_PORTAL_H */
4519 diff --git a/drivers/staging/fsl-mc/bus/dpio/qbman_debug.c b/drivers/staging/fsl-mc/bus/dpio/qbman_debug.c
4520 new file mode 100644
4521 index 00000000..1c77fa6a
4523 +++ b/drivers/staging/fsl-mc/bus/dpio/qbman_debug.c
4525 +/* Copyright (C) 2015 Freescale Semiconductor, Inc.
4527 + * Redistribution and use in source and binary forms, with or without
4528 + * modification, are permitted provided that the following conditions are met:
4529 + * * Redistributions of source code must retain the above copyright
4530 + * notice, this list of conditions and the following disclaimer.
4531 + * * Redistributions in binary form must reproduce the above copyright
4532 + * notice, this list of conditions and the following disclaimer in the
4533 + * documentation and/or other materials provided with the distribution.
4534 + * * Neither the name of Freescale Semiconductor nor the
4535 + * names of its contributors may be used to endorse or promote products
4536 + * derived from this software without specific prior written permission.
4539 + * ALTERNATIVELY, this software may be distributed under the terms of the
4540 + * GNU General Public License ("GPL") as published by the Free Software
4541 + * Foundation, either version 2 of that License or (at your option) any
4544 + * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
4545 + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
4546 + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
4547 + * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
4548 + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
4549 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
4550 + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
4551 + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
4552 + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
4553 + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4556 +#include <linux/errno.h>
4558 +#include "../../include/dpaa2-global.h"
4559 +#include "qbman-portal.h"
4560 +#include "qbman_debug.h"
4562 +/* QBMan portal management command code */
4563 +#define QBMAN_BP_QUERY 0x32
4564 +#define QBMAN_FQ_QUERY 0x44
4565 +#define QBMAN_FQ_QUERY_NP 0x45
4566 +#define QBMAN_CGR_QUERY 0x51
4567 +#define QBMAN_WRED_QUERY 0x54
4568 +#define QBMAN_CGR_STAT_QUERY 0x55
4569 +#define QBMAN_CGR_STAT_QUERY_CLR 0x56
4571 +enum qbman_attr_usage_e {
4572 + qbman_attr_usage_fq,
4573 + qbman_attr_usage_bpool,
4574 + qbman_attr_usage_cgr,
4577 +struct int_qbman_attr {
4579 + enum qbman_attr_usage_e usage;
4582 +#define attr_type_set(a, e) \
4584 + struct qbman_attr *__attr = a; \
4585 + enum qbman_attr_usage_e __usage = e; \
4586 + ((struct int_qbman_attr *)__attr)->usage = __usage; \
4589 +#define ATTR32(d) (&(d)->dont_manipulate_directly[0])
4590 +#define ATTR32_1(d) (&(d)->dont_manipulate_directly[16])
4592 +static struct qb_attr_code code_bp_bpid = QB_CODE(0, 16, 16);
4593 +static struct qb_attr_code code_bp_bdi = QB_CODE(1, 16, 1);
4594 +static struct qb_attr_code code_bp_va = QB_CODE(1, 17, 1);
4595 +static struct qb_attr_code code_bp_wae = QB_CODE(1, 18, 1);
4596 +static struct qb_attr_code code_bp_swdet = QB_CODE(4, 0, 16);
4597 +static struct qb_attr_code code_bp_swdxt = QB_CODE(4, 16, 16);
4598 +static struct qb_attr_code code_bp_hwdet = QB_CODE(5, 0, 16);
4599 +static struct qb_attr_code code_bp_hwdxt = QB_CODE(5, 16, 16);
4600 +static struct qb_attr_code code_bp_swset = QB_CODE(6, 0, 16);
4601 +static struct qb_attr_code code_bp_swsxt = QB_CODE(6, 16, 16);
4602 +static struct qb_attr_code code_bp_vbpid = QB_CODE(7, 0, 14);
4603 +static struct qb_attr_code code_bp_icid = QB_CODE(7, 16, 15);
4604 +static struct qb_attr_code code_bp_pl = QB_CODE(7, 31, 1);
4605 +static struct qb_attr_code code_bp_bpscn_addr_lo = QB_CODE(8, 0, 32);
4606 +static struct qb_attr_code code_bp_bpscn_addr_hi = QB_CODE(9, 0, 32);
4607 +static struct qb_attr_code code_bp_bpscn_ctx_lo = QB_CODE(10, 0, 32);
4608 +static struct qb_attr_code code_bp_bpscn_ctx_hi = QB_CODE(11, 0, 32);
4609 +static struct qb_attr_code code_bp_hw_targ = QB_CODE(12, 0, 16);
4610 +static struct qb_attr_code code_bp_state = QB_CODE(1, 24, 3);
4611 +static struct qb_attr_code code_bp_fill = QB_CODE(2, 0, 32);
4612 +static struct qb_attr_code code_bp_hdptr = QB_CODE(3, 0, 32);
4613 +static struct qb_attr_code code_bp_sdcnt = QB_CODE(13, 0, 8);
4614 +static struct qb_attr_code code_bp_hdcnt = QB_CODE(13, 1, 8);
4615 +static struct qb_attr_code code_bp_sscnt = QB_CODE(13, 2, 8);
4617 +void qbman_bp_attr_clear(struct qbman_attr *a)
4619 + memset(a, 0, sizeof(*a));
4620 + attr_type_set(a, qbman_attr_usage_bpool);
4623 +int qbman_bp_query(struct qbman_swp *s, u32 bpid,
4624 + struct qbman_attr *a)
4628 + u32 *attr = ATTR32(a);
4630 + qbman_bp_attr_clear(a);
4632 + /* Start the management command */
4633 + p = qbman_swp_mc_start(s);
4637 + /* Encode the caller-provided attributes */
4638 + qb_attr_code_encode(&code_bp_bpid, p, bpid);
4640 + /* Complete the management command */
4641 + p = qbman_swp_mc_complete(s, p, QBMAN_BP_QUERY);
4643 + /* Decode the outcome */
4644 + verb = qb_attr_code_decode(&code_generic_verb, p);
4645 + rslt = qb_attr_code_decode(&code_generic_rslt, p);
4646 + WARN_ON(verb != QBMAN_BP_QUERY);
4648 + /* Determine success or failure */
4649 + if (unlikely(rslt != QBMAN_MC_RSLT_OK)) {
4650 + pr_err("Query of BPID 0x%x failed, code=0x%02x\n", bpid, rslt);
4654 + /* For the query, word[0] of the result contains only the
4655 + * verb/rslt fields, so skip word[0].
4657 + word_copy(&attr[1], &p[1], 15);
4661 +void qbman_bp_attr_get_bdi(struct qbman_attr *a, int *bdi, int *va, int *wae)
4663 + u32 *p = ATTR32(a);
4665 + *bdi = !!qb_attr_code_decode(&code_bp_bdi, p);
4666 + *va = !!qb_attr_code_decode(&code_bp_va, p);
4667 + *wae = !!qb_attr_code_decode(&code_bp_wae, p);
4670 +static u32 qbman_bp_thresh_to_value(u32 val)
4672 + return (val & 0xff) << ((val & 0xf00) >> 8);
4675 +void qbman_bp_attr_get_swdet(struct qbman_attr *a, u32 *swdet)
4677 + u32 *p = ATTR32(a);
4679 + *swdet = qbman_bp_thresh_to_value(qb_attr_code_decode(&code_bp_swdet,
4683 +void qbman_bp_attr_get_swdxt(struct qbman_attr *a, u32 *swdxt)
4685 + u32 *p = ATTR32(a);
4687 + *swdxt = qbman_bp_thresh_to_value(qb_attr_code_decode(&code_bp_swdxt,
4691 +void qbman_bp_attr_get_hwdet(struct qbman_attr *a, u32 *hwdet)
4693 + u32 *p = ATTR32(a);
4695 + *hwdet = qbman_bp_thresh_to_value(qb_attr_code_decode(&code_bp_hwdet,
4699 +void qbman_bp_attr_get_hwdxt(struct qbman_attr *a, u32 *hwdxt)
4701 + u32 *p = ATTR32(a);
4703 + *hwdxt = qbman_bp_thresh_to_value(qb_attr_code_decode(&code_bp_hwdxt,
4707 +void qbman_bp_attr_get_swset(struct qbman_attr *a, u32 *swset)
4709 + u32 *p = ATTR32(a);
4711 + *swset = qbman_bp_thresh_to_value(qb_attr_code_decode(&code_bp_swset,
4715 +void qbman_bp_attr_get_swsxt(struct qbman_attr *a, u32 *swsxt)
4717 + u32 *p = ATTR32(a);
4719 + *swsxt = qbman_bp_thresh_to_value(qb_attr_code_decode(&code_bp_swsxt,
4723 +void qbman_bp_attr_get_vbpid(struct qbman_attr *a, u32 *vbpid)
4725 + u32 *p = ATTR32(a);
4727 + *vbpid = qb_attr_code_decode(&code_bp_vbpid, p);
4730 +void qbman_bp_attr_get_icid(struct qbman_attr *a, u32 *icid, int *pl)
4732 + u32 *p = ATTR32(a);
4734 + *icid = qb_attr_code_decode(&code_bp_icid, p);
4735 + *pl = !!qb_attr_code_decode(&code_bp_pl, p);
4738 +void qbman_bp_attr_get_bpscn_addr(struct qbman_attr *a, u64 *bpscn_addr)
4740 + u32 *p = ATTR32(a);
4742 + *bpscn_addr = ((u64)qb_attr_code_decode(&code_bp_bpscn_addr_hi,
4744 + (u64)qb_attr_code_decode(&code_bp_bpscn_addr_lo,
4748 +void qbman_bp_attr_get_bpscn_ctx(struct qbman_attr *a, u64 *bpscn_ctx)
4750 + u32 *p = ATTR32(a);
4752 + *bpscn_ctx = ((u64)qb_attr_code_decode(&code_bp_bpscn_ctx_hi, p)
4754 + (u64)qb_attr_code_decode(&code_bp_bpscn_ctx_lo,
4758 +void qbman_bp_attr_get_hw_targ(struct qbman_attr *a, u32 *hw_targ)
4760 + u32 *p = ATTR32(a);
4762 + *hw_targ = qb_attr_code_decode(&code_bp_hw_targ, p);
4765 +int qbman_bp_info_has_free_bufs(struct qbman_attr *a)
4767 + u32 *p = ATTR32(a);
4769 + return !(int)(qb_attr_code_decode(&code_bp_state, p) & 0x1);
4772 +int qbman_bp_info_is_depleted(struct qbman_attr *a)
4774 + u32 *p = ATTR32(a);
4776 + return (int)(qb_attr_code_decode(&code_bp_state, p) & 0x2);
4779 +int qbman_bp_info_is_surplus(struct qbman_attr *a)
4781 + u32 *p = ATTR32(a);
4783 + return (int)(qb_attr_code_decode(&code_bp_state, p) & 0x4);
4786 +u32 qbman_bp_info_num_free_bufs(struct qbman_attr *a)
4788 + u32 *p = ATTR32(a);
4790 + return qb_attr_code_decode(&code_bp_fill, p);
4793 +u32 qbman_bp_info_hdptr(struct qbman_attr *a)
4795 + u32 *p = ATTR32(a);
4797 + return qb_attr_code_decode(&code_bp_hdptr, p);
4800 +u32 qbman_bp_info_sdcnt(struct qbman_attr *a)
4802 + u32 *p = ATTR32(a);
4804 + return qb_attr_code_decode(&code_bp_sdcnt, p);
4807 +u32 qbman_bp_info_hdcnt(struct qbman_attr *a)
4809 + u32 *p = ATTR32(a);
4811 + return qb_attr_code_decode(&code_bp_hdcnt, p);
4814 +u32 qbman_bp_info_sscnt(struct qbman_attr *a)
4816 + u32 *p = ATTR32(a);
4818 + return qb_attr_code_decode(&code_bp_sscnt, p);
4821 +static struct qb_attr_code code_fq_fqid = QB_CODE(1, 0, 24);
4822 +static struct qb_attr_code code_fq_cgrid = QB_CODE(2, 16, 16);
4823 +static struct qb_attr_code code_fq_destwq = QB_CODE(3, 0, 15);
4824 +static struct qb_attr_code code_fq_fqctrl = QB_CODE(3, 24, 8);
4825 +static struct qb_attr_code code_fq_icscred = QB_CODE(4, 0, 15);
4826 +static struct qb_attr_code code_fq_tdthresh = QB_CODE(4, 16, 13);
4827 +static struct qb_attr_code code_fq_oa_len = QB_CODE(5, 0, 12);
4828 +static struct qb_attr_code code_fq_oa_ics = QB_CODE(5, 14, 1);
4829 +static struct qb_attr_code code_fq_oa_cgr = QB_CODE(5, 15, 1);
4830 +static struct qb_attr_code code_fq_mctl_bdi = QB_CODE(5, 24, 1);
4831 +static struct qb_attr_code code_fq_mctl_ff = QB_CODE(5, 25, 1);
4832 +static struct qb_attr_code code_fq_mctl_va = QB_CODE(5, 26, 1);
4833 +static struct qb_attr_code code_fq_mctl_ps = QB_CODE(5, 27, 1);
4834 +static struct qb_attr_code code_fq_ctx_lower32 = QB_CODE(6, 0, 32);
4835 +static struct qb_attr_code code_fq_ctx_upper32 = QB_CODE(7, 0, 32);
4836 +static struct qb_attr_code code_fq_icid = QB_CODE(8, 0, 15);
4837 +static struct qb_attr_code code_fq_pl = QB_CODE(8, 15, 1);
4838 +static struct qb_attr_code code_fq_vfqid = QB_CODE(9, 0, 24);
4839 +static struct qb_attr_code code_fq_erfqid = QB_CODE(10, 0, 24);
4841 +void qbman_fq_attr_clear(struct qbman_attr *a)
4843 + memset(a, 0, sizeof(*a));
4844 + attr_type_set(a, qbman_attr_usage_fq);
4847 +/* FQ query function for programmable fields */
4848 +int qbman_fq_query(struct qbman_swp *s, u32 fqid, struct qbman_attr *desc)
4852 + u32 *d = ATTR32(desc);
4854 + qbman_fq_attr_clear(desc);
4856 + p = qbman_swp_mc_start(s);
4859 + qb_attr_code_encode(&code_fq_fqid, p, fqid);
4860 + p = qbman_swp_mc_complete(s, p, QBMAN_FQ_QUERY);
4862 + /* Decode the outcome */
4863 + verb = qb_attr_code_decode(&code_generic_verb, p);
4864 + rslt = qb_attr_code_decode(&code_generic_rslt, p);
4865 + WARN_ON(verb != QBMAN_FQ_QUERY);
4867 + /* Determine success or failure */
4868 + if (unlikely(rslt != QBMAN_MC_RSLT_OK)) {
4869 + pr_err("Query of FQID 0x%x failed, code=0x%02x\n",
4874 + * For the configure, word[0] of the command contains only the WE-mask.
4875 + * For the query, word[0] of the result contains only the verb/rslt
4876 + * fields. Skip word[0] in the latter case.
4878 + word_copy(&d[1], &p[1], 15);
4882 +void qbman_fq_attr_get_fqctrl(struct qbman_attr *d, u32 *fqctrl)
4884 + u32 *p = ATTR32(d);
4886 + *fqctrl = qb_attr_code_decode(&code_fq_fqctrl, p);
4889 +void qbman_fq_attr_get_cgrid(struct qbman_attr *d, u32 *cgrid)
4891 + u32 *p = ATTR32(d);
4893 + *cgrid = qb_attr_code_decode(&code_fq_cgrid, p);
4896 +void qbman_fq_attr_get_destwq(struct qbman_attr *d, u32 *destwq)
4898 + u32 *p = ATTR32(d);
4900 + *destwq = qb_attr_code_decode(&code_fq_destwq, p);
4903 +void qbman_fq_attr_get_icscred(struct qbman_attr *d, u32 *icscred)
4905 + u32 *p = ATTR32(d);
4907 + *icscred = qb_attr_code_decode(&code_fq_icscred, p);
4910 +static struct qb_attr_code code_tdthresh_exp = QB_CODE(0, 0, 5);
4911 +static struct qb_attr_code code_tdthresh_mant = QB_CODE(0, 5, 8);
4912 +static u32 qbman_thresh_to_value(u32 val)
4916 + m = qb_attr_code_decode(&code_tdthresh_mant, &val);
4917 + e = qb_attr_code_decode(&code_tdthresh_exp, &val);
4921 +void qbman_fq_attr_get_tdthresh(struct qbman_attr *d, u32 *tdthresh)
4923 + u32 *p = ATTR32(d);
4925 + *tdthresh = qbman_thresh_to_value(qb_attr_code_decode(&code_fq_tdthresh,
4929 +void qbman_fq_attr_get_oa(struct qbman_attr *d,
4930 + int *oa_ics, int *oa_cgr, int32_t *oa_len)
4932 + u32 *p = ATTR32(d);
4934 + *oa_ics = !!qb_attr_code_decode(&code_fq_oa_ics, p);
4935 + *oa_cgr = !!qb_attr_code_decode(&code_fq_oa_cgr, p);
4936 + *oa_len = qb_attr_code_makesigned(&code_fq_oa_len,
4937 + qb_attr_code_decode(&code_fq_oa_len, p));
4940 +void qbman_fq_attr_get_mctl(struct qbman_attr *d,
4941 + int *bdi, int *ff, int *va, int *ps)
4943 + u32 *p = ATTR32(d);
4945 + *bdi = !!qb_attr_code_decode(&code_fq_mctl_bdi, p);
4946 + *ff = !!qb_attr_code_decode(&code_fq_mctl_ff, p);
4947 + *va = !!qb_attr_code_decode(&code_fq_mctl_va, p);
4948 + *ps = !!qb_attr_code_decode(&code_fq_mctl_ps, p);
4951 +void qbman_fq_attr_get_ctx(struct qbman_attr *d, u32 *hi, u32 *lo)
4953 + u32 *p = ATTR32(d);
4955 + *hi = qb_attr_code_decode(&code_fq_ctx_upper32, p);
4956 + *lo = qb_attr_code_decode(&code_fq_ctx_lower32, p);
4959 +void qbman_fq_attr_get_icid(struct qbman_attr *d, u32 *icid, int *pl)
4961 + u32 *p = ATTR32(d);
4963 + *icid = qb_attr_code_decode(&code_fq_icid, p);
4964 + *pl = !!qb_attr_code_decode(&code_fq_pl, p);
4967 +void qbman_fq_attr_get_vfqid(struct qbman_attr *d, u32 *vfqid)
4969 + u32 *p = ATTR32(d);
4971 + *vfqid = qb_attr_code_decode(&code_fq_vfqid, p);
4974 +void qbman_fq_attr_get_erfqid(struct qbman_attr *d, u32 *erfqid)
4976 + u32 *p = ATTR32(d);
4978 + *erfqid = qb_attr_code_decode(&code_fq_erfqid, p);
4981 +/* Query FQ Non-Programmalbe Fields */
4982 +static struct qb_attr_code code_fq_np_state = QB_CODE(0, 16, 3);
4983 +static struct qb_attr_code code_fq_np_fe = QB_CODE(0, 19, 1);
4984 +static struct qb_attr_code code_fq_np_x = QB_CODE(0, 20, 1);
4985 +static struct qb_attr_code code_fq_np_r = QB_CODE(0, 21, 1);
4986 +static struct qb_attr_code code_fq_np_oe = QB_CODE(0, 22, 1);
4987 +static struct qb_attr_code code_fq_np_frm_cnt = QB_CODE(6, 0, 24);
4988 +static struct qb_attr_code code_fq_np_byte_cnt = QB_CODE(7, 0, 32);
4990 +int qbman_fq_query_state(struct qbman_swp *s, u32 fqid,
4991 + struct qbman_attr *state)
4995 + u32 *d = ATTR32(state);
4997 + qbman_fq_attr_clear(state);
4999 + p = qbman_swp_mc_start(s);
5002 + qb_attr_code_encode(&code_fq_fqid, p, fqid);
5003 + p = qbman_swp_mc_complete(s, p, QBMAN_FQ_QUERY_NP);
5005 + /* Decode the outcome */
5006 + verb = qb_attr_code_decode(&code_generic_verb, p);
5007 + rslt = qb_attr_code_decode(&code_generic_rslt, p);
5008 + WARN_ON(verb != QBMAN_FQ_QUERY_NP);
5010 + /* Determine success or failure */
5011 + if (unlikely(rslt != QBMAN_MC_RSLT_OK)) {
5012 + pr_err("Query NP fields of FQID 0x%x failed, code=0x%02x\n",
5016 + word_copy(&d[0], &p[0], 16);
5020 +u32 qbman_fq_state_schedstate(const struct qbman_attr *state)
5022 + const u32 *p = ATTR32(state);
5024 + return qb_attr_code_decode(&code_fq_np_state, p);
5027 +int qbman_fq_state_force_eligible(const struct qbman_attr *state)
5029 + const u32 *p = ATTR32(state);
5031 + return !!qb_attr_code_decode(&code_fq_np_fe, p);
5034 +int qbman_fq_state_xoff(const struct qbman_attr *state)
5036 + const u32 *p = ATTR32(state);
5038 + return !!qb_attr_code_decode(&code_fq_np_x, p);
5041 +int qbman_fq_state_retirement_pending(const struct qbman_attr *state)
5043 + const u32 *p = ATTR32(state);
5045 + return !!qb_attr_code_decode(&code_fq_np_r, p);
5048 +int qbman_fq_state_overflow_error(const struct qbman_attr *state)
5050 + const u32 *p = ATTR32(state);
5052 + return !!qb_attr_code_decode(&code_fq_np_oe, p);
5055 +u32 qbman_fq_state_frame_count(const struct qbman_attr *state)
5057 + const u32 *p = ATTR32(state);
5059 + return qb_attr_code_decode(&code_fq_np_frm_cnt, p);
5062 +u32 qbman_fq_state_byte_count(const struct qbman_attr *state)
5064 + const u32 *p = ATTR32(state);
5066 + return qb_attr_code_decode(&code_fq_np_byte_cnt, p);
5070 +static struct qb_attr_code code_cgr_cgid = QB_CODE(0, 16, 16);
5071 +static struct qb_attr_code code_cgr_cscn_wq_en_enter = QB_CODE(2, 0, 1);
5072 +static struct qb_attr_code code_cgr_cscn_wq_en_exit = QB_CODE(2, 1, 1);
5073 +static struct qb_attr_code code_cgr_cscn_wq_icd = QB_CODE(2, 2, 1);
5074 +static struct qb_attr_code code_cgr_mode = QB_CODE(3, 16, 2);
5075 +static struct qb_attr_code code_cgr_rej_cnt_mode = QB_CODE(3, 18, 1);
5076 +static struct qb_attr_code code_cgr_cscn_bdi = QB_CODE(3, 19, 1);
5077 +static struct qb_attr_code code_cgr_cscn_wr_en_enter = QB_CODE(3, 24, 1);
5078 +static struct qb_attr_code code_cgr_cscn_wr_en_exit = QB_CODE(3, 25, 1);
5079 +static struct qb_attr_code code_cgr_cg_wr_ae = QB_CODE(3, 26, 1);
5080 +static struct qb_attr_code code_cgr_cscn_dcp_en = QB_CODE(3, 27, 1);
5081 +static struct qb_attr_code code_cgr_cg_wr_va = QB_CODE(3, 28, 1);
5082 +static struct qb_attr_code code_cgr_i_cnt_wr_en = QB_CODE(4, 0, 1);
5083 +static struct qb_attr_code code_cgr_i_cnt_wr_bnd = QB_CODE(4, 1, 5);
5084 +static struct qb_attr_code code_cgr_td_en = QB_CODE(4, 8, 1);
5085 +static struct qb_attr_code code_cgr_cs_thres = QB_CODE(4, 16, 13);
5086 +static struct qb_attr_code code_cgr_cs_thres_x = QB_CODE(5, 0, 13);
5087 +static struct qb_attr_code code_cgr_td_thres = QB_CODE(5, 16, 13);
5088 +static struct qb_attr_code code_cgr_cscn_tdcp = QB_CODE(6, 0, 16);
5089 +static struct qb_attr_code code_cgr_cscn_wqid = QB_CODE(6, 16, 16);
5090 +static struct qb_attr_code code_cgr_cscn_vcgid = QB_CODE(7, 0, 16);
5091 +static struct qb_attr_code code_cgr_cg_icid = QB_CODE(7, 16, 15);
5092 +static struct qb_attr_code code_cgr_cg_pl = QB_CODE(7, 31, 1);
5093 +static struct qb_attr_code code_cgr_cg_wr_addr_lo = QB_CODE(8, 0, 32);
5094 +static struct qb_attr_code code_cgr_cg_wr_addr_hi = QB_CODE(9, 0, 32);
5095 +static struct qb_attr_code code_cgr_cscn_ctx_lo = QB_CODE(10, 0, 32);
5096 +static struct qb_attr_code code_cgr_cscn_ctx_hi = QB_CODE(11, 0, 32);
5098 +void qbman_cgr_attr_clear(struct qbman_attr *a)
5100 + memset(a, 0, sizeof(*a));
5101 + attr_type_set(a, qbman_attr_usage_cgr);
5104 +int qbman_cgr_query(struct qbman_swp *s, u32 cgid, struct qbman_attr *attr)
5112 + d[0] = ATTR32(attr);
5113 + d[1] = ATTR32_1(attr);
5115 + qbman_cgr_attr_clear(attr);
5117 + for (i = 0; i < 2; i++) {
5118 + p = qbman_swp_mc_start(s);
5121 + query_verb = i ? QBMAN_WRED_QUERY : QBMAN_CGR_QUERY;
5123 + qb_attr_code_encode(&code_cgr_cgid, p, cgid);
5124 + p = qbman_swp_mc_complete(s, p, p[0] | query_verb);
5126 + /* Decode the outcome */
5127 + verb = qb_attr_code_decode(&code_generic_verb, p);
5128 + rslt = qb_attr_code_decode(&code_generic_rslt, p);
5129 + WARN_ON(verb != query_verb);
5131 + /* Determine success or failure */
5132 + if (unlikely(rslt != QBMAN_MC_RSLT_OK)) {
5133 + pr_err("Query CGID 0x%x failed,", cgid);
5134 + pr_err(" verb=0x%02x, code=0x%02x\n", verb, rslt);
5137 + /* For the configure, word[0] of the command contains only the
5138 + * verb/cgid. For the query, word[0] of the result contains
5139 + * only the verb/rslt fields. Skip word[0] in the latter case.
5141 + word_copy(&d[i][1], &p[1], 15);
5146 +void qbman_cgr_attr_get_ctl1(struct qbman_attr *d, int *cscn_wq_en_enter,
5147 + int *cscn_wq_en_exit, int *cscn_wq_icd)
5149 + u32 *p = ATTR32(d);
5150 + *cscn_wq_en_enter = !!qb_attr_code_decode(&code_cgr_cscn_wq_en_enter,
5152 + *cscn_wq_en_exit = !!qb_attr_code_decode(&code_cgr_cscn_wq_en_exit, p);
5153 + *cscn_wq_icd = !!qb_attr_code_decode(&code_cgr_cscn_wq_icd, p);
5156 +void qbman_cgr_attr_get_mode(struct qbman_attr *d, u32 *mode,
5157 + int *rej_cnt_mode, int *cscn_bdi)
5159 + u32 *p = ATTR32(d);
5160 + *mode = qb_attr_code_decode(&code_cgr_mode, p);
5161 + *rej_cnt_mode = !!qb_attr_code_decode(&code_cgr_rej_cnt_mode, p);
5162 + *cscn_bdi = !!qb_attr_code_decode(&code_cgr_cscn_bdi, p);
5165 +void qbman_cgr_attr_get_ctl2(struct qbman_attr *d, int *cscn_wr_en_enter,
5166 + int *cscn_wr_en_exit, int *cg_wr_ae,
5167 + int *cscn_dcp_en, int *cg_wr_va)
5169 + u32 *p = ATTR32(d);
5170 + *cscn_wr_en_enter = !!qb_attr_code_decode(&code_cgr_cscn_wr_en_enter,
5172 + *cscn_wr_en_exit = !!qb_attr_code_decode(&code_cgr_cscn_wr_en_exit, p);
5173 + *cg_wr_ae = !!qb_attr_code_decode(&code_cgr_cg_wr_ae, p);
5174 + *cscn_dcp_en = !!qb_attr_code_decode(&code_cgr_cscn_dcp_en, p);
5175 + *cg_wr_va = !!qb_attr_code_decode(&code_cgr_cg_wr_va, p);
5178 +void qbman_cgr_attr_get_iwc(struct qbman_attr *d, int *i_cnt_wr_en,
5179 + u32 *i_cnt_wr_bnd)
5181 + u32 *p = ATTR32(d);
5182 + *i_cnt_wr_en = !!qb_attr_code_decode(&code_cgr_i_cnt_wr_en, p);
5183 + *i_cnt_wr_bnd = qb_attr_code_decode(&code_cgr_i_cnt_wr_bnd, p);
5186 +void qbman_cgr_attr_get_tdc(struct qbman_attr *d, int *td_en)
5188 + u32 *p = ATTR32(d);
5189 + *td_en = !!qb_attr_code_decode(&code_cgr_td_en, p);
5192 +void qbman_cgr_attr_get_cs_thres(struct qbman_attr *d, u32 *cs_thres)
5194 + u32 *p = ATTR32(d);
5195 + *cs_thres = qbman_thresh_to_value(qb_attr_code_decode(
5196 + &code_cgr_cs_thres, p));
5199 +void qbman_cgr_attr_get_cs_thres_x(struct qbman_attr *d,
5202 + u32 *p = ATTR32(d);
5203 + *cs_thres_x = qbman_thresh_to_value(qb_attr_code_decode(
5204 + &code_cgr_cs_thres_x, p));
5207 +void qbman_cgr_attr_get_td_thres(struct qbman_attr *d, u32 *td_thres)
5209 + u32 *p = ATTR32(d);
5210 + *td_thres = qbman_thresh_to_value(qb_attr_code_decode(
5211 + &code_cgr_td_thres, p));
5214 +void qbman_cgr_attr_get_cscn_tdcp(struct qbman_attr *d, u32 *cscn_tdcp)
5216 + u32 *p = ATTR32(d);
5217 + *cscn_tdcp = qb_attr_code_decode(&code_cgr_cscn_tdcp, p);
5220 +void qbman_cgr_attr_get_cscn_wqid(struct qbman_attr *d, u32 *cscn_wqid)
5222 + u32 *p = ATTR32(d);
5223 + *cscn_wqid = qb_attr_code_decode(&code_cgr_cscn_wqid, p);
5226 +void qbman_cgr_attr_get_cscn_vcgid(struct qbman_attr *d,
5229 + u32 *p = ATTR32(d);
5230 + *cscn_vcgid = qb_attr_code_decode(&code_cgr_cscn_vcgid, p);
5233 +void qbman_cgr_attr_get_cg_icid(struct qbman_attr *d, u32 *icid,
5236 + u32 *p = ATTR32(d);
5237 + *icid = qb_attr_code_decode(&code_cgr_cg_icid, p);
5238 + *pl = !!qb_attr_code_decode(&code_cgr_cg_pl, p);
5241 +void qbman_cgr_attr_get_cg_wr_addr(struct qbman_attr *d,
5244 + u32 *p = ATTR32(d);
5245 + *cg_wr_addr = ((u64)qb_attr_code_decode(&code_cgr_cg_wr_addr_hi,
5247 + (u64)qb_attr_code_decode(&code_cgr_cg_wr_addr_lo,
5251 +void qbman_cgr_attr_get_cscn_ctx(struct qbman_attr *d, u64 *cscn_ctx)
5253 + u32 *p = ATTR32(d);
5254 + *cscn_ctx = ((u64)qb_attr_code_decode(&code_cgr_cscn_ctx_hi, p)
5256 + (u64)qb_attr_code_decode(&code_cgr_cscn_ctx_lo, p);
5259 +#define WRED_EDP_WORD(n) (18 + (n) / 4)
5260 +#define WRED_EDP_OFFSET(n) (8 * ((n) % 4))
5261 +#define WRED_PARM_DP_WORD(n) ((n) + 20)
5262 +#define WRED_WE_EDP(n) (16 + (n) * 2)
5263 +#define WRED_WE_PARM_DP(n) (17 + (n) * 2)
5264 +void qbman_cgr_attr_wred_get_edp(struct qbman_attr *d, u32 idx,
5267 + u32 *p = ATTR32(d);
5268 + struct qb_attr_code code_wred_edp = QB_CODE(WRED_EDP_WORD(idx),
5269 + WRED_EDP_OFFSET(idx), 8);
5270 + *edp = (int)qb_attr_code_decode(&code_wred_edp, p);
5273 +void qbman_cgr_attr_wred_dp_decompose(u32 dp, u64 *minth,
5274 + u64 *maxth, u8 *maxp)
5276 + u8 ma, mn, step_i, step_s, pn;
5278 + ma = (u8)(dp >> 24);
5279 + mn = (u8)(dp >> 19) & 0x1f;
5280 + step_i = (u8)(dp >> 11);
5281 + step_s = (u8)(dp >> 6) & 0x1f;
5282 + pn = (u8)dp & 0x3f;
5284 + *maxp = ((pn << 2) * 100) / 256;
5289 + *maxth = ((ma + 256) * (1 << (mn - 1)));
5292 + *minth = *maxth - step_i;
5294 + *minth = *maxth - (256 + step_i) * (1 << (step_s - 1));
5297 +void qbman_cgr_attr_wred_get_parm_dp(struct qbman_attr *d, u32 idx,
5300 + u32 *p = ATTR32(d);
5301 + struct qb_attr_code code_wred_parm_dp = QB_CODE(WRED_PARM_DP_WORD(idx),
5303 + *dp = qb_attr_code_decode(&code_wred_parm_dp, p);
5306 +/* Query CGR/CCGR/CQ statistics */
5307 +static struct qb_attr_code code_cgr_stat_ct = QB_CODE(4, 0, 32);
5308 +static struct qb_attr_code code_cgr_stat_frame_cnt_lo = QB_CODE(4, 0, 32);
5309 +static struct qb_attr_code code_cgr_stat_frame_cnt_hi = QB_CODE(5, 0, 8);
5310 +static struct qb_attr_code code_cgr_stat_byte_cnt_lo = QB_CODE(6, 0, 32);
5311 +static struct qb_attr_code code_cgr_stat_byte_cnt_hi = QB_CODE(7, 0, 16);
5312 +static int qbman_cgr_statistics_query(struct qbman_swp *s, u32 cgid,
5313 + int clear, u32 command_type,
5314 + u64 *frame_cnt, u64 *byte_cnt)
5321 + p = qbman_swp_mc_start(s);
5325 + qb_attr_code_encode(&code_cgr_cgid, p, cgid);
5326 + if (command_type < 2)
5327 + qb_attr_code_encode(&code_cgr_stat_ct, p, command_type);
5328 + query_verb = clear ?
5329 + QBMAN_CGR_STAT_QUERY_CLR : QBMAN_CGR_STAT_QUERY;
5330 + p = qbman_swp_mc_complete(s, p, p[0] | query_verb);
5332 + /* Decode the outcome */
5333 + verb = qb_attr_code_decode(&code_generic_verb, p);
5334 + rslt = qb_attr_code_decode(&code_generic_rslt, p);
5335 + WARN_ON(verb != query_verb);
5337 + /* Determine success or failure */
5338 + if (unlikely(rslt != QBMAN_MC_RSLT_OK)) {
5339 + pr_err("Query statistics of CGID 0x%x failed,", cgid);
5340 + pr_err(" verb=0x%02x code=0x%02x\n", verb, rslt);
5345 + hi = qb_attr_code_decode(&code_cgr_stat_frame_cnt_hi, p);
5346 + lo = qb_attr_code_decode(&code_cgr_stat_frame_cnt_lo, p);
5347 + *frame_cnt = ((u64)hi << 32) | (u64)lo;
5350 + hi = qb_attr_code_decode(&code_cgr_stat_byte_cnt_hi, p);
5351 + lo = qb_attr_code_decode(&code_cgr_stat_byte_cnt_lo, p);
5352 + *byte_cnt = ((u64)hi << 32) | (u64)lo;
5358 +int qbman_cgr_reject_statistics(struct qbman_swp *s, u32 cgid, int clear,
5359 + u64 *frame_cnt, u64 *byte_cnt)
5361 + return qbman_cgr_statistics_query(s, cgid, clear, 0xff,
5362 + frame_cnt, byte_cnt);
5365 +int qbman_ccgr_reject_statistics(struct qbman_swp *s, u32 cgid, int clear,
5366 + u64 *frame_cnt, u64 *byte_cnt)
5368 + return qbman_cgr_statistics_query(s, cgid, clear, 1,
5369 + frame_cnt, byte_cnt);
5372 +int qbman_cq_dequeue_statistics(struct qbman_swp *s, u32 cgid, int clear,
5373 + u64 *frame_cnt, u64 *byte_cnt)
5375 + return qbman_cgr_statistics_query(s, cgid, clear, 0,
5376 + frame_cnt, byte_cnt);
5378 diff --git a/drivers/staging/fsl-mc/bus/dpio/qbman_debug.h b/drivers/staging/fsl-mc/bus/dpio/qbman_debug.h
5379 new file mode 100644
5380 index 00000000..0a247a49
5382 +++ b/drivers/staging/fsl-mc/bus/dpio/qbman_debug.h
5384 +/* Copyright (C) 2015 Freescale Semiconductor, Inc.
5386 + * Redistribution and use in source and binary forms, with or without
5387 + * modification, are permitted provided that the following conditions are met:
5388 + * * Redistributions of source code must retain the above copyright
5389 + * notice, this list of conditions and the following disclaimer.
5390 + * * Redistributions in binary form must reproduce the above copyright
5391 + * notice, this list of conditions and the following disclaimer in the
5392 + * documentation and/or other materials provided with the distribution.
5393 + * * Neither the name of Freescale Semiconductor nor the
5394 + * names of its contributors may be used to endorse or promote products
5395 + * derived from this software without specific prior written permission.
5398 + * ALTERNATIVELY, this software may be distributed under the terms of the
5399 + * GNU General Public License ("GPL") as published by the Free Software
5400 + * Foundation, either version 2 of that License or (at your option) any
5403 + * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
5404 + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
5405 + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
5406 + * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
5407 + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
5408 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
5409 + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
5410 + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
5411 + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
5412 + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
5415 +struct qbman_attr {
5416 + u32 dont_manipulate_directly[40];
5419 +/* Buffer pool query commands */
5420 +int qbman_bp_query(struct qbman_swp *s, u32 bpid,
5421 + struct qbman_attr *a);
5422 +void qbman_bp_attr_get_bdi(struct qbman_attr *a, int *bdi, int *va, int *wae);
5423 +void qbman_bp_attr_get_swdet(struct qbman_attr *a, u32 *swdet);
5424 +void qbman_bp_attr_get_swdxt(struct qbman_attr *a, u32 *swdxt);
5425 +void qbman_bp_attr_get_hwdet(struct qbman_attr *a, u32 *hwdet);
5426 +void qbman_bp_attr_get_hwdxt(struct qbman_attr *a, u32 *hwdxt);
5427 +void qbman_bp_attr_get_swset(struct qbman_attr *a, u32 *swset);
5428 +void qbman_bp_attr_get_swsxt(struct qbman_attr *a, u32 *swsxt);
5429 +void qbman_bp_attr_get_vbpid(struct qbman_attr *a, u32 *vbpid);
5430 +void qbman_bp_attr_get_icid(struct qbman_attr *a, u32 *icid, int *pl);
5431 +void qbman_bp_attr_get_bpscn_addr(struct qbman_attr *a, u64 *bpscn_addr);
5432 +void qbman_bp_attr_get_bpscn_ctx(struct qbman_attr *a, u64 *bpscn_ctx);
5433 +void qbman_bp_attr_get_hw_targ(struct qbman_attr *a, u32 *hw_targ);
5434 +int qbman_bp_info_has_free_bufs(struct qbman_attr *a);
5435 +int qbman_bp_info_is_depleted(struct qbman_attr *a);
5436 +int qbman_bp_info_is_surplus(struct qbman_attr *a);
5437 +u32 qbman_bp_info_num_free_bufs(struct qbman_attr *a);
5438 +u32 qbman_bp_info_hdptr(struct qbman_attr *a);
5439 +u32 qbman_bp_info_sdcnt(struct qbman_attr *a);
5440 +u32 qbman_bp_info_hdcnt(struct qbman_attr *a);
5441 +u32 qbman_bp_info_sscnt(struct qbman_attr *a);
5443 +/* FQ query function for programmable fields */
5444 +int qbman_fq_query(struct qbman_swp *s, u32 fqid,
5445 + struct qbman_attr *desc);
5446 +void qbman_fq_attr_get_fqctrl(struct qbman_attr *d, u32 *fqctrl);
5447 +void qbman_fq_attr_get_cgrid(struct qbman_attr *d, u32 *cgrid);
5448 +void qbman_fq_attr_get_destwq(struct qbman_attr *d, u32 *destwq);
5449 +void qbman_fq_attr_get_icscred(struct qbman_attr *d, u32 *icscred);
5450 +void qbman_fq_attr_get_tdthresh(struct qbman_attr *d, u32 *tdthresh);
5451 +void qbman_fq_attr_get_oa(struct qbman_attr *d,
5452 + int *oa_ics, int *oa_cgr, int32_t *oa_len);
5453 +void qbman_fq_attr_get_mctl(struct qbman_attr *d,
5454 + int *bdi, int *ff, int *va, int *ps);
5455 +void qbman_fq_attr_get_ctx(struct qbman_attr *d, u32 *hi, u32 *lo);
5456 +void qbman_fq_attr_get_icid(struct qbman_attr *d, u32 *icid, int *pl);
5457 +void qbman_fq_attr_get_vfqid(struct qbman_attr *d, u32 *vfqid);
5458 +void qbman_fq_attr_get_erfqid(struct qbman_attr *d, u32 *erfqid);
5460 +/* FQ query command for non-programmable fields*/
5461 +enum qbman_fq_schedstate_e {
5462 + qbman_fq_schedstate_oos = 0,
5463 + qbman_fq_schedstate_retired,
5464 + qbman_fq_schedstate_tentatively_scheduled,
5465 + qbman_fq_schedstate_truly_scheduled,
5466 + qbman_fq_schedstate_parked,
5467 + qbman_fq_schedstate_held_active,
5470 +int qbman_fq_query_state(struct qbman_swp *s, u32 fqid,
5471 + struct qbman_attr *state);
5472 +u32 qbman_fq_state_schedstate(const struct qbman_attr *state);
5473 +int qbman_fq_state_force_eligible(const struct qbman_attr *state);
5474 +int qbman_fq_state_xoff(const struct qbman_attr *state);
5475 +int qbman_fq_state_retirement_pending(const struct qbman_attr *state);
5476 +int qbman_fq_state_overflow_error(const struct qbman_attr *state);
5477 +u32 qbman_fq_state_frame_count(const struct qbman_attr *state);
5478 +u32 qbman_fq_state_byte_count(const struct qbman_attr *state);
5481 +int qbman_cgr_query(struct qbman_swp *s, u32 cgid,
5482 + struct qbman_attr *attr);
5483 +void qbman_cgr_attr_get_ctl1(struct qbman_attr *d, int *cscn_wq_en_enter,
5484 + int *cscn_wq_en_exit, int *cscn_wq_icd);
5485 +void qbman_cgr_attr_get_mode(struct qbman_attr *d, u32 *mode,
5486 + int *rej_cnt_mode, int *cscn_bdi);
5487 +void qbman_cgr_attr_get_ctl2(struct qbman_attr *d, int *cscn_wr_en_enter,
5488 + int *cscn_wr_en_exit, int *cg_wr_ae,
5489 + int *cscn_dcp_en, int *cg_wr_va);
5490 +void qbman_cgr_attr_get_iwc(struct qbman_attr *d, int *i_cnt_wr_en,
5491 + u32 *i_cnt_wr_bnd);
5492 +void qbman_cgr_attr_get_tdc(struct qbman_attr *d, int *td_en);
5493 +void qbman_cgr_attr_get_cs_thres(struct qbman_attr *d, u32 *cs_thres);
5494 +void qbman_cgr_attr_get_cs_thres_x(struct qbman_attr *d,
5496 +void qbman_cgr_attr_get_td_thres(struct qbman_attr *d, u32 *td_thres);
5497 +void qbman_cgr_attr_get_cscn_tdcp(struct qbman_attr *d, u32 *cscn_tdcp);
5498 +void qbman_cgr_attr_get_cscn_wqid(struct qbman_attr *d, u32 *cscn_wqid);
5499 +void qbman_cgr_attr_get_cscn_vcgid(struct qbman_attr *d,
5501 +void qbman_cgr_attr_get_cg_icid(struct qbman_attr *d, u32 *icid,
5503 +void qbman_cgr_attr_get_cg_wr_addr(struct qbman_attr *d,
5505 +void qbman_cgr_attr_get_cscn_ctx(struct qbman_attr *d, u64 *cscn_ctx);
5506 +void qbman_cgr_attr_wred_get_edp(struct qbman_attr *d, u32 idx,
5508 +void qbman_cgr_attr_wred_dp_decompose(u32 dp, u64 *minth,
5509 + u64 *maxth, u8 *maxp);
5510 +void qbman_cgr_attr_wred_get_parm_dp(struct qbman_attr *d, u32 idx,
5513 +/* CGR/CCGR/CQ statistics query */
5514 +int qbman_cgr_reject_statistics(struct qbman_swp *s, u32 cgid, int clear,
5515 + u64 *frame_cnt, u64 *byte_cnt);
5516 +int qbman_ccgr_reject_statistics(struct qbman_swp *s, u32 cgid, int clear,
5517 + u64 *frame_cnt, u64 *byte_cnt);
5518 +int qbman_cq_dequeue_statistics(struct qbman_swp *s, u32 cgid, int clear,
5519 + u64 *frame_cnt, u64 *byte_cnt);
5520 diff --git a/drivers/staging/fsl-mc/bus/dpio/qbman_private.h b/drivers/staging/fsl-mc/bus/dpio/qbman_private.h
5521 new file mode 100644
5522 index 00000000..98a64be2
5524 +++ b/drivers/staging/fsl-mc/bus/dpio/qbman_private.h
5526 +/* Copyright (C) 2014 Freescale Semiconductor, Inc.
5528 + * Redistribution and use in source and binary forms, with or without
5529 + * modification, are permitted provided that the following conditions are met:
5530 + * * Redistributions of source code must retain the above copyright
5531 + * notice, this list of conditions and the following disclaimer.
5532 + * * Redistributions in binary form must reproduce the above copyright
5533 + * notice, this list of conditions and the following disclaimer in the
5534 + * documentation and/or other materials provided with the distribution.
5535 + * * Neither the name of Freescale Semiconductor nor the
5536 + * names of its contributors may be used to endorse or promote products
5537 + * derived from this software without specific prior written permission.
5540 + * ALTERNATIVELY, this software may be distributed under the terms of the
5541 + * GNU General Public License ("GPL") as published by the Free Software
5542 + * Foundation, either version 2 of that License or (at your option) any
5545 + * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
5546 + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
5547 + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
5548 + * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
5549 + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
5550 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
5551 + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
5552 + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
5553 + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
5554 + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
5557 +/* Perform extra checking */
5558 +#define QBMAN_CHECKING
5560 +/* To maximise the amount of logic that is common between the Linux driver and
5561 + * other targets (such as the embedded MC firmware), we pivot here between the
5562 + * inclusion of two platform-specific headers.
5564 + * The first, qbman_sys_decl.h, includes any and all required system headers as
5565 + * well as providing any definitions for the purposes of compatibility. The
5566 + * second, qbman_sys.h, is where platform-specific routines go.
5568 + * The point of the split is that the platform-independent code (including this
5569 + * header) may depend on platform-specific declarations, yet other
5570 + * platform-specific routines may depend on platform-independent definitions.
5573 +#define QMAN_REV_4000 0x04000000
5574 +#define QMAN_REV_4100 0x04010000
5575 +#define QMAN_REV_4101 0x04010001
5577 +/* When things go wrong, it is a convenient trick to insert a few FOO()
5578 + * statements in the code to trace progress. TODO: remove this once we are
5579 + * hacking the code less actively.
5581 +#define FOO() fsl_os_print("FOO: %s:%d\n", __FILE__, __LINE__)
5583 +/* Any time there is a register interface which we poll on, this provides a
5584 + * "break after x iterations" scheme for it. It's handy for debugging, eg.
5585 + * where you don't want millions of lines of log output from a polling loop
5586 + * that won't, because such things tend to drown out the earlier log output
5587 + * that might explain what caused the problem. (NB: put ";" after each macro!)
5588 + * TODO: we should probably remove this once we're done sanitising the
5591 +#define DBG_POLL_START(loopvar) (loopvar = 1000)
5592 +#define DBG_POLL_CHECK(loopvar) \
5593 + do {if (!((loopvar)--)) WARN_ON(1); } while (0)
5595 +/* For CCSR or portal-CINH registers that contain fields at arbitrary offsets
5596 + * and widths, these macro-generated encode/decode/isolate/remove inlines can
5599 + * Eg. to "d"ecode a 14-bit field out of a register (into a "u16" type),
5600 + * where the field is located 3 bits "up" from the least-significant bit of the
5601 + * register (ie. the field location within the 32-bit register corresponds to a
5602 + * mask of 0x0001fff8), you would do;
5603 + * u16 field = d32_u16(3, 14, reg_value);
5605 + * Or to "e"ncode a 1-bit boolean value (input type is "int", zero is FALSE,
5606 + * non-zero is TRUE, so must convert all non-zero inputs to 1, hence the "!!"
5607 + * operator) into a register at bit location 0x00080000 (19 bits "in" from the
5609 + * reg_value |= e32_int(19, 1, !!field);
5611 + * If you wish to read-modify-write a register, such that you leave the 14-bit
5612 + * field as-is but have all other fields set to zero, then "i"solate the 14-bit
5614 + * reg_value = i32_u16(3, 14, reg_value);
5616 + * Alternatively, you could "r"emove the 1-bit boolean field (setting it to
5617 + * zero) but leaving all other fields as-is;
5618 + * reg_val = r32_int(19, 1, reg_value);
5621 +#define MAKE_MASK32(width) (width == 32 ? 0xffffffff : \
5622 + (u32)((1 << width) - 1))
5623 +#define DECLARE_CODEC32(t) \
5624 +static inline u32 e32_##t(u32 lsoffset, u32 width, t val) \
5626 + WARN_ON(width > (sizeof(t) * 8)); \
5627 + return ((u32)val & MAKE_MASK32(width)) << lsoffset; \
5629 +static inline t d32_##t(u32 lsoffset, u32 width, u32 val) \
5631 + WARN_ON(width > (sizeof(t) * 8)); \
5632 + return (t)((val >> lsoffset) & MAKE_MASK32(width)); \
5634 +static inline u32 i32_##t(u32 lsoffset, u32 width, \
5637 + WARN_ON(width > (sizeof(t) * 8)); \
5638 + return e32_##t(lsoffset, width, d32_##t(lsoffset, width, val)); \
5640 +static inline u32 r32_##t(u32 lsoffset, u32 width, \
5643 + WARN_ON(width > (sizeof(t) * 8)); \
5644 + return ~(MAKE_MASK32(width) << lsoffset) & val; \
5646 +DECLARE_CODEC32(u32)
5647 +DECLARE_CODEC32(u16)
5648 +DECLARE_CODEC32(u8)
5649 +DECLARE_CODEC32(int)
5651 + /*********************/
5652 + /* Debugging assists */
5653 + /*********************/
5655 +static inline void __hexdump(unsigned long start, unsigned long end,
5656 + unsigned long p, size_t sz,
5657 + const unsigned char *c)
5659 + while (start < end) {
5660 + unsigned int pos = 0;
5664 + pos += sprintf(buf + pos, "%08lx: ", start);
5666 + if ((start < p) || (start >= (p + sz)))
5667 + pos += sprintf(buf + pos, "..");
5669 + pos += sprintf(buf + pos, "%02x", *(c++));
5670 + if (!(++start & 15)) {
5671 + buf[pos++] = '\n';
5680 + } while (start & 15);
5682 + buf[pos++] = '\n';
5684 + pr_info("%s", buf);
5688 +static inline void hexdump(const void *ptr, size_t sz)
5690 + unsigned long p = (unsigned long)ptr;
5691 + unsigned long start = p & ~15ul;
5692 + unsigned long end = (p + sz + 15) & ~15ul;
5693 + const unsigned char *c = ptr;
5695 + __hexdump(start, end, p, sz, c);
5697 diff --git a/drivers/staging/fsl-mc/bus/dpmcp-cmd.h b/drivers/staging/fsl-mc/bus/dpmcp-cmd.h
5698 index d098a6d8..384a13d0 100644
5699 --- a/drivers/staging/fsl-mc/bus/dpmcp-cmd.h
5700 +++ b/drivers/staging/fsl-mc/bus/dpmcp-cmd.h
5702 -/* Copyright 2013-2016 Freescale Semiconductor Inc.
5704 + * Copyright 2013-2016 Freescale Semiconductor Inc.
5706 * Redistribution and use in source and binary forms, with or without
5707 * modification, are permitted provided that the following conditions are met:
5709 * names of any contributors may be used to endorse or promote products
5710 * derived from this software without specific prior written permission.
5713 * ALTERNATIVELY, this software may be distributed under the terms of the
5714 * GNU General Public License ("GPL") as published by the Free Software
5715 * Foundation, either version 2 of that License or (at your option) any
5716 @@ -33,108 +33,24 @@
5717 #define _FSL_DPMCP_CMD_H
5719 /* Minimal supported DPMCP Version */
5720 -#define DPMCP_MIN_VER_MAJOR 3
5721 -#define DPMCP_MIN_VER_MINOR 0
5722 +#define DPMCP_MIN_VER_MAJOR 3
5723 +#define DPMCP_MIN_VER_MINOR 0
5726 -#define DPMCP_CMDID_CLOSE 0x800
5727 -#define DPMCP_CMDID_OPEN 0x80b
5728 -#define DPMCP_CMDID_CREATE 0x90b
5729 -#define DPMCP_CMDID_DESTROY 0x900
5730 +/* Command versioning */
5731 +#define DPMCP_CMD_BASE_VERSION 1
5732 +#define DPMCP_CMD_ID_OFFSET 4
5734 -#define DPMCP_CMDID_GET_ATTR 0x004
5735 -#define DPMCP_CMDID_RESET 0x005
5736 +#define DPMCP_CMD(id) ((id << DPMCP_CMD_ID_OFFSET) | DPMCP_CMD_BASE_VERSION)
5739 +#define DPMCP_CMDID_CLOSE DPMCP_CMD(0x800)
5740 +#define DPMCP_CMDID_OPEN DPMCP_CMD(0x80b)
5741 +#define DPMCP_CMDID_GET_API_VERSION DPMCP_CMD(0xa0b)
5743 -#define DPMCP_CMDID_SET_IRQ 0x010
5744 -#define DPMCP_CMDID_GET_IRQ 0x011
5745 -#define DPMCP_CMDID_SET_IRQ_ENABLE 0x012
5746 -#define DPMCP_CMDID_GET_IRQ_ENABLE 0x013
5747 -#define DPMCP_CMDID_SET_IRQ_MASK 0x014
5748 -#define DPMCP_CMDID_GET_IRQ_MASK 0x015
5749 -#define DPMCP_CMDID_GET_IRQ_STATUS 0x016
5750 +#define DPMCP_CMDID_RESET DPMCP_CMD(0x005)
5752 struct dpmcp_cmd_open {
5756 -struct dpmcp_cmd_create {
5760 -struct dpmcp_cmd_set_irq {
5771 -struct dpmcp_cmd_get_irq {
5776 -struct dpmcp_rsp_get_irq {
5787 -#define DPMCP_ENABLE 0x1
5789 -struct dpmcp_cmd_set_irq_enable {
5795 -struct dpmcp_cmd_get_irq_enable {
5800 -struct dpmcp_rsp_get_irq_enable {
5804 -struct dpmcp_cmd_set_irq_mask {
5809 -struct dpmcp_cmd_get_irq_mask {
5814 -struct dpmcp_rsp_get_irq_mask {
5818 -struct dpmcp_cmd_get_irq_status {
5823 -struct dpmcp_rsp_get_irq_status {
5827 -struct dpmcp_rsp_get_attributes {
5828 - /* response word 0 */
5831 - /* response word 1 */
5832 - __le16 version_major;
5833 - __le16 version_minor;
5836 #endif /* _FSL_DPMCP_CMD_H */
5837 diff --git a/drivers/staging/fsl-mc/bus/dpmcp.c b/drivers/staging/fsl-mc/bus/dpmcp.c
5838 index 55766f78..ad4c8b43 100644
5839 --- a/drivers/staging/fsl-mc/bus/dpmcp.c
5840 +++ b/drivers/staging/fsl-mc/bus/dpmcp.c
5842 -/* Copyright 2013-2016 Freescale Semiconductor Inc.
5844 + * Copyright 2013-2016 Freescale Semiconductor Inc.
5846 * Redistribution and use in source and binary forms, with or without
5847 * modification, are permitted provided that the following conditions are met:
5849 * names of any contributors may be used to endorse or promote products
5850 * derived from this software without specific prior written permission.
5853 * ALTERNATIVELY, this software may be distributed under the terms of the
5854 * GNU General Public License ("GPL") as published by the Free Software
5855 * Foundation, either version 2 of that License or (at your option) any
5856 @@ -103,76 +103,6 @@ int dpmcp_close(struct fsl_mc_io *mc_io,
5857 return mc_send_command(mc_io, &cmd);
5861 - * dpmcp_create() - Create the DPMCP object.
5862 - * @mc_io: Pointer to MC portal's I/O object
5863 - * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
5864 - * @cfg: Configuration structure
5865 - * @token: Returned token; use in subsequent API calls
5867 - * Create the DPMCP object, allocate required resources and
5868 - * perform required initialization.
5870 - * The object can be created either by declaring it in the
5871 - * DPL file, or by calling this function.
5872 - * This function returns a unique authentication token,
5873 - * associated with the specific object ID and the specific MC
5874 - * portal; this token must be used in all subsequent calls to
5875 - * this specific object. For objects that are created using the
5876 - * DPL file, call dpmcp_open function to get an authentication
5879 - * Return: '0' on Success; Error code otherwise.
5881 -int dpmcp_create(struct fsl_mc_io *mc_io,
5883 - const struct dpmcp_cfg *cfg,
5886 - struct mc_command cmd = { 0 };
5887 - struct dpmcp_cmd_create *cmd_params;
5891 - /* prepare command */
5892 - cmd.header = mc_encode_cmd_header(DPMCP_CMDID_CREATE,
5894 - cmd_params = (struct dpmcp_cmd_create *)cmd.params;
5895 - cmd_params->portal_id = cpu_to_le32(cfg->portal_id);
5897 - /* send command to mc*/
5898 - err = mc_send_command(mc_io, &cmd);
5902 - /* retrieve response parameters */
5903 - *token = mc_cmd_hdr_read_token(&cmd);
5909 - * dpmcp_destroy() - Destroy the DPMCP object and release all its resources.
5910 - * @mc_io: Pointer to MC portal's I/O object
5911 - * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
5912 - * @token: Token of DPMCP object
5914 - * Return: '0' on Success; error code otherwise.
5916 -int dpmcp_destroy(struct fsl_mc_io *mc_io,
5920 - struct mc_command cmd = { 0 };
5922 - /* prepare command */
5923 - cmd.header = mc_encode_cmd_header(DPMCP_CMDID_DESTROY,
5924 - cmd_flags, token);
5926 - /* send command to mc*/
5927 - return mc_send_command(mc_io, &cmd);
5931 * dpmcp_reset() - Reset the DPMCP, returns the object to initial state.
5932 * @mc_io: Pointer to MC portal's I/O object
5933 @@ -196,309 +126,33 @@ int dpmcp_reset(struct fsl_mc_io *mc_io,
5937 - * dpmcp_set_irq() - Set IRQ information for the DPMCP to trigger an interrupt.
5938 - * @mc_io: Pointer to MC portal's I/O object
5939 - * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
5940 - * @token: Token of DPMCP object
5941 - * @irq_index: Identifies the interrupt index to configure
5942 - * @irq_cfg: IRQ configuration
5944 - * Return: '0' on Success; Error code otherwise.
5946 -int dpmcp_set_irq(struct fsl_mc_io *mc_io,
5950 - struct dpmcp_irq_cfg *irq_cfg)
5952 - struct mc_command cmd = { 0 };
5953 - struct dpmcp_cmd_set_irq *cmd_params;
5955 - /* prepare command */
5956 - cmd.header = mc_encode_cmd_header(DPMCP_CMDID_SET_IRQ,
5957 - cmd_flags, token);
5958 - cmd_params = (struct dpmcp_cmd_set_irq *)cmd.params;
5959 - cmd_params->irq_index = irq_index;
5960 - cmd_params->irq_val = cpu_to_le32(irq_cfg->val);
5961 - cmd_params->irq_addr = cpu_to_le64(irq_cfg->paddr);
5962 - cmd_params->irq_num = cpu_to_le32(irq_cfg->irq_num);
5964 - /* send command to mc*/
5965 - return mc_send_command(mc_io, &cmd);
5969 - * dpmcp_get_irq() - Get IRQ information from the DPMCP.
5970 - * @mc_io: Pointer to MC portal's I/O object
5971 + * dpmcp_get_api_version - Get Data Path Management Command Portal API version
5972 + * @mc_io: Pointer to Mc portal's I/O object
5973 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
5974 - * @token: Token of DPMCP object
5975 - * @irq_index: The interrupt index to configure
5976 - * @type: Interrupt type: 0 represents message interrupt
5977 - * type (both irq_addr and irq_val are valid)
5978 - * @irq_cfg: IRQ attributes
5979 + * @major_ver: Major version of Data Path Management Command Portal API
5980 + * @minor_ver: Minor version of Data Path Management Command Portal API
5982 * Return: '0' on Success; Error code otherwise.
5984 -int dpmcp_get_irq(struct fsl_mc_io *mc_io,
5989 - struct dpmcp_irq_cfg *irq_cfg)
5990 +int dpmcp_get_api_version(struct fsl_mc_io *mc_io,
5995 struct mc_command cmd = { 0 };
5996 - struct dpmcp_cmd_get_irq *cmd_params;
5997 - struct dpmcp_rsp_get_irq *rsp_params;
6000 /* prepare command */
6001 - cmd.header = mc_encode_cmd_header(DPMCP_CMDID_GET_IRQ,
6002 - cmd_flags, token);
6003 - cmd_params = (struct dpmcp_cmd_get_irq *)cmd.params;
6004 - cmd_params->irq_index = irq_index;
6006 - /* send command to mc*/
6007 - err = mc_send_command(mc_io, &cmd);
6011 - /* retrieve response parameters */
6012 - rsp_params = (struct dpmcp_rsp_get_irq *)cmd.params;
6013 - irq_cfg->val = le32_to_cpu(rsp_params->irq_val);
6014 - irq_cfg->paddr = le64_to_cpu(rsp_params->irq_paddr);
6015 - irq_cfg->irq_num = le32_to_cpu(rsp_params->irq_num);
6016 - *type = le32_to_cpu(rsp_params->type);
6021 - * dpmcp_set_irq_enable() - Set overall interrupt state.
6022 - * @mc_io: Pointer to MC portal's I/O object
6023 - * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
6024 - * @token: Token of DPMCP object
6025 - * @irq_index: The interrupt index to configure
6026 - * @en: Interrupt state - enable = 1, disable = 0
6028 - * Allows GPP software to control when interrupts are generated.
6029 - * Each interrupt can have up to 32 causes. The enable/disable control's the
6030 - * overall interrupt state. if the interrupt is disabled no causes will cause
6033 - * Return: '0' on Success; Error code otherwise.
6035 -int dpmcp_set_irq_enable(struct fsl_mc_io *mc_io,
6041 - struct mc_command cmd = { 0 };
6042 - struct dpmcp_cmd_set_irq_enable *cmd_params;
6044 - /* prepare command */
6045 - cmd.header = mc_encode_cmd_header(DPMCP_CMDID_SET_IRQ_ENABLE,
6046 - cmd_flags, token);
6047 - cmd_params = (struct dpmcp_cmd_set_irq_enable *)cmd.params;
6048 - cmd_params->enable = en & DPMCP_ENABLE;
6049 - cmd_params->irq_index = irq_index;
6051 - /* send command to mc*/
6052 - return mc_send_command(mc_io, &cmd);
6056 - * dpmcp_get_irq_enable() - Get overall interrupt state
6057 - * @mc_io: Pointer to MC portal's I/O object
6058 - * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
6059 - * @token: Token of DPMCP object
6060 - * @irq_index: The interrupt index to configure
6061 - * @en: Returned interrupt state - enable = 1, disable = 0
6063 - * Return: '0' on Success; Error code otherwise.
6065 -int dpmcp_get_irq_enable(struct fsl_mc_io *mc_io,
6071 - struct mc_command cmd = { 0 };
6072 - struct dpmcp_cmd_get_irq_enable *cmd_params;
6073 - struct dpmcp_rsp_get_irq_enable *rsp_params;
6076 - /* prepare command */
6077 - cmd.header = mc_encode_cmd_header(DPMCP_CMDID_GET_IRQ_ENABLE,
6078 - cmd_flags, token);
6079 - cmd_params = (struct dpmcp_cmd_get_irq_enable *)cmd.params;
6080 - cmd_params->irq_index = irq_index;
6082 - /* send command to mc*/
6083 - err = mc_send_command(mc_io, &cmd);
6087 - /* retrieve response parameters */
6088 - rsp_params = (struct dpmcp_rsp_get_irq_enable *)cmd.params;
6089 - *en = rsp_params->enabled & DPMCP_ENABLE;
6094 - * dpmcp_set_irq_mask() - Set interrupt mask.
6095 - * @mc_io: Pointer to MC portal's I/O object
6096 - * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
6097 - * @token: Token of DPMCP object
6098 - * @irq_index: The interrupt index to configure
6099 - * @mask: Event mask to trigger interrupt;
6101 - * 0 = ignore event
6102 - * 1 = consider event for asserting IRQ
6104 - * Every interrupt can have up to 32 causes and the interrupt model supports
6105 - * masking/unmasking each cause independently
6107 - * Return: '0' on Success; Error code otherwise.
6109 -int dpmcp_set_irq_mask(struct fsl_mc_io *mc_io,
6115 - struct mc_command cmd = { 0 };
6116 - struct dpmcp_cmd_set_irq_mask *cmd_params;
6118 - /* prepare command */
6119 - cmd.header = mc_encode_cmd_header(DPMCP_CMDID_SET_IRQ_MASK,
6120 - cmd_flags, token);
6121 - cmd_params = (struct dpmcp_cmd_set_irq_mask *)cmd.params;
6122 - cmd_params->mask = cpu_to_le32(mask);
6123 - cmd_params->irq_index = irq_index;
6125 - /* send command to mc*/
6126 - return mc_send_command(mc_io, &cmd);
6130 - * dpmcp_get_irq_mask() - Get interrupt mask.
6131 - * @mc_io: Pointer to MC portal's I/O object
6132 - * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
6133 - * @token: Token of DPMCP object
6134 - * @irq_index: The interrupt index to configure
6135 - * @mask: Returned event mask to trigger interrupt
6137 - * Every interrupt can have up to 32 causes and the interrupt model supports
6138 - * masking/unmasking each cause independently
6140 - * Return: '0' on Success; Error code otherwise.
6142 -int dpmcp_get_irq_mask(struct fsl_mc_io *mc_io,
6148 - struct mc_command cmd = { 0 };
6149 - struct dpmcp_cmd_get_irq_mask *cmd_params;
6150 - struct dpmcp_rsp_get_irq_mask *rsp_params;
6154 - /* prepare command */
6155 - cmd.header = mc_encode_cmd_header(DPMCP_CMDID_GET_IRQ_MASK,
6156 - cmd_flags, token);
6157 - cmd_params = (struct dpmcp_cmd_get_irq_mask *)cmd.params;
6158 - cmd_params->irq_index = irq_index;
6160 - /* send command to mc*/
6161 - err = mc_send_command(mc_io, &cmd);
6165 - /* retrieve response parameters */
6166 - rsp_params = (struct dpmcp_rsp_get_irq_mask *)cmd.params;
6167 - *mask = le32_to_cpu(rsp_params->mask);
6173 - * dpmcp_get_irq_status() - Get the current status of any pending interrupts.
6175 - * @mc_io: Pointer to MC portal's I/O object
6176 - * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
6177 - * @token: Token of DPMCP object
6178 - * @irq_index: The interrupt index to configure
6179 - * @status: Returned interrupts status - one bit per cause:
6180 - * 0 = no interrupt pending
6181 - * 1 = interrupt pending
6183 - * Return: '0' on Success; Error code otherwise.
6185 -int dpmcp_get_irq_status(struct fsl_mc_io *mc_io,
6191 - struct mc_command cmd = { 0 };
6192 - struct dpmcp_cmd_get_irq_status *cmd_params;
6193 - struct dpmcp_rsp_get_irq_status *rsp_params;
6196 - /* prepare command */
6197 - cmd.header = mc_encode_cmd_header(DPMCP_CMDID_GET_IRQ_STATUS,
6198 - cmd_flags, token);
6199 - cmd_params = (struct dpmcp_cmd_get_irq_status *)cmd.params;
6200 - cmd_params->status = cpu_to_le32(*status);
6201 - cmd_params->irq_index = irq_index;
6203 - /* send command to mc*/
6204 - err = mc_send_command(mc_io, &cmd);
6208 - /* retrieve response parameters */
6209 - rsp_params = (struct dpmcp_rsp_get_irq_status *)cmd.params;
6210 - *status = le32_to_cpu(rsp_params->status);
6216 - * dpmcp_get_attributes - Retrieve DPMCP attributes.
6218 - * @mc_io: Pointer to MC portal's I/O object
6219 - * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
6220 - * @token: Token of DPMCP object
6221 - * @attr: Returned object's attributes
6223 - * Return: '0' on Success; Error code otherwise.
6225 -int dpmcp_get_attributes(struct fsl_mc_io *mc_io,
6228 - struct dpmcp_attr *attr)
6230 - struct mc_command cmd = { 0 };
6231 - struct dpmcp_rsp_get_attributes *rsp_params;
6234 - /* prepare command */
6235 - cmd.header = mc_encode_cmd_header(DPMCP_CMDID_GET_ATTR,
6236 - cmd_flags, token);
6237 + cmd.header = mc_encode_cmd_header(DPMCP_CMDID_GET_API_VERSION,
6240 - /* send command to mc*/
6241 + /* send command to mc */
6242 err = mc_send_command(mc_io, &cmd);
6246 /* retrieve response parameters */
6247 - rsp_params = (struct dpmcp_rsp_get_attributes *)cmd.params;
6248 - attr->id = le32_to_cpu(rsp_params->id);
6249 - attr->version.major = le16_to_cpu(rsp_params->version_major);
6250 - attr->version.minor = le16_to_cpu(rsp_params->version_minor);
6251 + mc_cmd_read_api_version(&cmd, major_ver, minor_ver);
6255 diff --git a/drivers/staging/fsl-mc/bus/dpmcp.h b/drivers/staging/fsl-mc/bus/dpmcp.h
6256 index fe79d4d9..f616031e 100644
6257 --- a/drivers/staging/fsl-mc/bus/dpmcp.h
6258 +++ b/drivers/staging/fsl-mc/bus/dpmcp.h
6260 -/* Copyright 2013-2015 Freescale Semiconductor Inc.
6262 + * Copyright 2013-2016 Freescale Semiconductor Inc.
6264 * Redistribution and use in source and binary forms, with or without
6265 * modification, are permitted provided that the following conditions are met:
6267 * names of any contributors may be used to endorse or promote products
6268 * derived from this software without specific prior written permission.
6271 * ALTERNATIVELY, this software may be distributed under the terms of the
6272 * GNU General Public License ("GPL") as published by the Free Software
6273 * Foundation, either version 2 of that License or (at your option) any
6274 @@ -32,128 +32,29 @@
6275 #ifndef __FSL_DPMCP_H
6276 #define __FSL_DPMCP_H
6278 -/* Data Path Management Command Portal API
6280 + * Data Path Management Command Portal API
6281 * Contains initialization APIs and runtime control APIs for DPMCP
6286 int dpmcp_open(struct fsl_mc_io *mc_io,
6287 - uint32_t cmd_flags,
6292 -/* Get portal ID from pool */
6293 -#define DPMCP_GET_PORTAL_ID_FROM_POOL (-1)
6296 int dpmcp_close(struct fsl_mc_io *mc_io,
6297 - uint32_t cmd_flags,
6301 - * struct dpmcp_cfg - Structure representing DPMCP configuration
6302 - * @portal_id: Portal ID; 'DPMCP_GET_PORTAL_ID_FROM_POOL' to get the portal ID
6309 -int dpmcp_create(struct fsl_mc_io *mc_io,
6310 - uint32_t cmd_flags,
6311 - const struct dpmcp_cfg *cfg,
6316 -int dpmcp_destroy(struct fsl_mc_io *mc_io,
6317 - uint32_t cmd_flags,
6319 +int dpmcp_get_api_version(struct fsl_mc_io *mc_io,
6324 int dpmcp_reset(struct fsl_mc_io *mc_io,
6325 - uint32_t cmd_flags,
6330 -#define DPMCP_IRQ_INDEX 0
6331 -/* irq event - Indicates that the link state changed */
6332 -#define DPMCP_IRQ_EVENT_CMD_DONE 0x00000001
6335 - * struct dpmcp_irq_cfg - IRQ configuration
6336 - * @paddr: Address that must be written to signal a message-based interrupt
6337 - * @val: Value to write into irq_addr address
6338 - * @irq_num: A user defined number associated with this IRQ
6340 -struct dpmcp_irq_cfg {
6346 -int dpmcp_set_irq(struct fsl_mc_io *mc_io,
6347 - uint32_t cmd_flags,
6349 - uint8_t irq_index,
6350 - struct dpmcp_irq_cfg *irq_cfg);
6352 -int dpmcp_get_irq(struct fsl_mc_io *mc_io,
6353 - uint32_t cmd_flags,
6355 - uint8_t irq_index,
6357 - struct dpmcp_irq_cfg *irq_cfg);
6359 -int dpmcp_set_irq_enable(struct fsl_mc_io *mc_io,
6360 - uint32_t cmd_flags,
6362 - uint8_t irq_index,
6365 -int dpmcp_get_irq_enable(struct fsl_mc_io *mc_io,
6366 - uint32_t cmd_flags,
6368 - uint8_t irq_index,
6371 -int dpmcp_set_irq_mask(struct fsl_mc_io *mc_io,
6372 - uint32_t cmd_flags,
6374 - uint8_t irq_index,
6377 -int dpmcp_get_irq_mask(struct fsl_mc_io *mc_io,
6378 - uint32_t cmd_flags,
6380 - uint8_t irq_index,
6383 -int dpmcp_get_irq_status(struct fsl_mc_io *mc_io,
6384 - uint32_t cmd_flags,
6386 - uint8_t irq_index,
6387 - uint32_t *status);
6390 - * struct dpmcp_attr - Structure representing DPMCP attributes
6391 - * @id: DPMCP object ID
6392 - * @version: DPMCP version
6394 -struct dpmcp_attr {
6397 - * struct version - Structure representing DPMCP version
6398 - * @major: DPMCP major version
6399 - * @minor: DPMCP minor version
6407 -int dpmcp_get_attributes(struct fsl_mc_io *mc_io,
6408 - uint32_t cmd_flags,
6410 - struct dpmcp_attr *attr);
6414 #endif /* __FSL_DPMCP_H */
6415 diff --git a/drivers/staging/fsl-mc/bus/dpmng-cmd.h b/drivers/staging/fsl-mc/bus/dpmng-cmd.h
6416 index a7b77d58..cdddfb80 100644
6417 --- a/drivers/staging/fsl-mc/bus/dpmng-cmd.h
6418 +++ b/drivers/staging/fsl-mc/bus/dpmng-cmd.h
6420 * names of any contributors may be used to endorse or promote products
6421 * derived from this software without specific prior written permission.
6424 * ALTERNATIVELY, this software may be distributed under the terms of the
6425 * GNU General Public License ("GPL") as published by the Free Software
6426 * Foundation, either version 2 of that License or (at your option) any
6428 #ifndef __FSL_DPMNG_CMD_H
6429 #define __FSL_DPMNG_CMD_H
6432 -#define DPMNG_CMDID_GET_CONT_ID 0x830
6433 -#define DPMNG_CMDID_GET_VERSION 0x831
6434 +/* Command versioning */
6435 +#define DPMNG_CMD_BASE_VERSION 1
6436 +#define DPMNG_CMD_ID_OFFSET 4
6438 -struct dpmng_rsp_get_container_id {
6439 - __le32 container_id;
6441 +#define DPMNG_CMD(id) ((id << DPMNG_CMD_ID_OFFSET) | DPMNG_CMD_BASE_VERSION)
6444 +#define DPMNG_CMDID_GET_VERSION DPMNG_CMD(0x831)
6446 struct dpmng_rsp_get_version {
6448 diff --git a/drivers/staging/fsl-mc/bus/dpmng.c b/drivers/staging/fsl-mc/bus/dpmng.c
6449 index 96b1d677..ad5d5bbe 100644
6450 --- a/drivers/staging/fsl-mc/bus/dpmng.c
6451 +++ b/drivers/staging/fsl-mc/bus/dpmng.c
6453 -/* Copyright 2013-2016 Freescale Semiconductor Inc.
6455 + * Copyright 2013-2016 Freescale Semiconductor Inc.
6457 * Redistribution and use in source and binary forms, with or without
6458 * modification, are permitted provided that the following conditions are met:
6460 * names of any contributors may be used to endorse or promote products
6461 * derived from this software without specific prior written permission.
6464 * ALTERNATIVELY, this software may be distributed under the terms of the
6465 * GNU General Public License ("GPL") as published by the Free Software
6466 * Foundation, either version 2 of that License or (at your option) any
6467 @@ -72,36 +72,3 @@ int mc_get_version(struct fsl_mc_io *mc_io,
6469 EXPORT_SYMBOL(mc_get_version);
6472 - * dpmng_get_container_id() - Get container ID associated with a given portal.
6473 - * @mc_io: Pointer to MC portal's I/O object
6474 - * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
6475 - * @container_id: Requested container ID
6477 - * Return: '0' on Success; Error code otherwise.
6479 -int dpmng_get_container_id(struct fsl_mc_io *mc_io,
6481 - int *container_id)
6483 - struct mc_command cmd = { 0 };
6484 - struct dpmng_rsp_get_container_id *rsp_params;
6487 - /* prepare command */
6488 - cmd.header = mc_encode_cmd_header(DPMNG_CMDID_GET_CONT_ID,
6492 - /* send command to mc*/
6493 - err = mc_send_command(mc_io, &cmd);
6497 - /* retrieve response parameters */
6498 - rsp_params = (struct dpmng_rsp_get_container_id *)cmd.params;
6499 - *container_id = le32_to_cpu(rsp_params->container_id);
6504 diff --git a/drivers/staging/fsl-mc/bus/dprc-cmd.h b/drivers/staging/fsl-mc/bus/dprc-cmd.h
6505 index 009d6567..b7d8c345 100644
6506 --- a/drivers/staging/fsl-mc/bus/dprc-cmd.h
6507 +++ b/drivers/staging/fsl-mc/bus/dprc-cmd.h
6509 * names of any contributors may be used to endorse or promote products
6510 * derived from this software without specific prior written permission.
6513 * ALTERNATIVELY, this software may be distributed under the terms of the
6514 * GNU General Public License ("GPL") as published by the Free Software
6515 * Foundation, either version 2 of that License or (at your option) any
6517 #define _FSL_DPRC_CMD_H
6519 /* Minimal supported DPRC Version */
6520 -#define DPRC_MIN_VER_MAJOR 5
6521 +#define DPRC_MIN_VER_MAJOR 6
6522 #define DPRC_MIN_VER_MINOR 0
6524 +/* Command versioning */
6525 +#define DPRC_CMD_BASE_VERSION 1
6526 +#define DPRC_CMD_ID_OFFSET 4
6528 +#define DPRC_CMD(id) ((id << DPRC_CMD_ID_OFFSET) | DPRC_CMD_BASE_VERSION)
6531 -#define DPRC_CMDID_CLOSE 0x800
6532 -#define DPRC_CMDID_OPEN 0x805
6533 -#define DPRC_CMDID_CREATE 0x905
6535 -#define DPRC_CMDID_GET_ATTR 0x004
6536 -#define DPRC_CMDID_RESET_CONT 0x005
6538 -#define DPRC_CMDID_SET_IRQ 0x010
6539 -#define DPRC_CMDID_GET_IRQ 0x011
6540 -#define DPRC_CMDID_SET_IRQ_ENABLE 0x012
6541 -#define DPRC_CMDID_GET_IRQ_ENABLE 0x013
6542 -#define DPRC_CMDID_SET_IRQ_MASK 0x014
6543 -#define DPRC_CMDID_GET_IRQ_MASK 0x015
6544 -#define DPRC_CMDID_GET_IRQ_STATUS 0x016
6545 -#define DPRC_CMDID_CLEAR_IRQ_STATUS 0x017
6547 -#define DPRC_CMDID_CREATE_CONT 0x151
6548 -#define DPRC_CMDID_DESTROY_CONT 0x152
6549 -#define DPRC_CMDID_SET_RES_QUOTA 0x155
6550 -#define DPRC_CMDID_GET_RES_QUOTA 0x156
6551 -#define DPRC_CMDID_ASSIGN 0x157
6552 -#define DPRC_CMDID_UNASSIGN 0x158
6553 -#define DPRC_CMDID_GET_OBJ_COUNT 0x159
6554 -#define DPRC_CMDID_GET_OBJ 0x15A
6555 -#define DPRC_CMDID_GET_RES_COUNT 0x15B
6556 -#define DPRC_CMDID_GET_RES_IDS 0x15C
6557 -#define DPRC_CMDID_GET_OBJ_REG 0x15E
6558 -#define DPRC_CMDID_SET_OBJ_IRQ 0x15F
6559 -#define DPRC_CMDID_GET_OBJ_IRQ 0x160
6560 -#define DPRC_CMDID_SET_OBJ_LABEL 0x161
6561 -#define DPRC_CMDID_GET_OBJ_DESC 0x162
6563 -#define DPRC_CMDID_CONNECT 0x167
6564 -#define DPRC_CMDID_DISCONNECT 0x168
6565 -#define DPRC_CMDID_GET_POOL 0x169
6566 -#define DPRC_CMDID_GET_POOL_COUNT 0x16A
6568 -#define DPRC_CMDID_GET_CONNECTION 0x16C
6569 +#define DPRC_CMDID_CLOSE DPRC_CMD(0x800)
6570 +#define DPRC_CMDID_OPEN DPRC_CMD(0x805)
6571 +#define DPRC_CMDID_GET_API_VERSION DPRC_CMD(0xa05)
6573 +#define DPRC_CMDID_GET_ATTR DPRC_CMD(0x004)
6574 +#define DPRC_CMDID_RESET_CONT DPRC_CMD(0x005)
6576 +#define DPRC_CMDID_SET_IRQ DPRC_CMD(0x010)
6577 +#define DPRC_CMDID_GET_IRQ DPRC_CMD(0x011)
6578 +#define DPRC_CMDID_SET_IRQ_ENABLE DPRC_CMD(0x012)
6579 +#define DPRC_CMDID_GET_IRQ_ENABLE DPRC_CMD(0x013)
6580 +#define DPRC_CMDID_SET_IRQ_MASK DPRC_CMD(0x014)
6581 +#define DPRC_CMDID_GET_IRQ_MASK DPRC_CMD(0x015)
6582 +#define DPRC_CMDID_GET_IRQ_STATUS DPRC_CMD(0x016)
6583 +#define DPRC_CMDID_CLEAR_IRQ_STATUS DPRC_CMD(0x017)
6585 +#define DPRC_CMDID_GET_CONT_ID DPRC_CMD(0x830)
6586 +#define DPRC_CMDID_GET_OBJ_COUNT DPRC_CMD(0x159)
6587 +#define DPRC_CMDID_GET_OBJ DPRC_CMD(0x15A)
6588 +#define DPRC_CMDID_GET_RES_COUNT DPRC_CMD(0x15B)
6589 +#define DPRC_CMDID_GET_OBJ_REG DPRC_CMD(0x15E)
6590 +#define DPRC_CMDID_SET_OBJ_IRQ DPRC_CMD(0x15F)
6591 +#define DPRC_CMDID_GET_OBJ_IRQ DPRC_CMD(0x160)
6593 struct dprc_cmd_open {
6594 __le32 container_id;
6595 @@ -199,9 +189,6 @@ struct dprc_rsp_get_attributes {
6596 /* response word 1 */
6599 - /* response word 2 */
6600 - __le16 version_major;
6601 - __le16 version_minor;
6604 struct dprc_cmd_set_res_quota {
6605 @@ -367,11 +354,16 @@ struct dprc_cmd_get_obj_region {
6607 struct dprc_rsp_get_obj_region {
6608 /* response word 0 */
6611 /* response word 1 */
6615 /* response word 2 */
6619 + /* response word 3 */
6623 struct dprc_cmd_set_obj_label {
6624 diff --git a/drivers/staging/fsl-mc/bus/dprc-driver.c b/drivers/staging/fsl-mc/bus/dprc-driver.c
6625 index c5ee4639..f6e6211b 100644
6626 --- a/drivers/staging/fsl-mc/bus/dprc-driver.c
6627 +++ b/drivers/staging/fsl-mc/bus/dprc-driver.c
6630 * Freescale data path resource container (DPRC) driver
6632 - * Copyright (C) 2014 Freescale Semiconductor, Inc.
6633 + * Copyright (C) 2014-2016 Freescale Semiconductor, Inc.
6634 * Author: German Rivera <German.Rivera@freescale.com>
6636 * This file is licensed under the terms of the GNU General Public
6637 @@ -160,6 +160,8 @@ static void check_plugged_state_change(struct fsl_mc_device *mc_dev,
6638 * dprc_add_new_devices - Adds devices to the logical bus for a DPRC
6640 * @mc_bus_dev: pointer to the fsl-mc device that represents a DPRC object
6641 + * @driver_override: driver override to apply to new objects found in the
6642 + * DPRC, or NULL, if none.
6643 * @obj_desc_array: array of device descriptors for child devices currently
6644 * present in the physical DPRC.
6645 * @num_child_objects_in_mc: number of entries in obj_desc_array
6646 @@ -169,6 +171,7 @@ static void check_plugged_state_change(struct fsl_mc_device *mc_dev,
6647 * in the physical DPRC.
6649 static void dprc_add_new_devices(struct fsl_mc_device *mc_bus_dev,
6650 + const char *driver_override,
6651 struct dprc_obj_desc *obj_desc_array,
6652 int num_child_objects_in_mc)
6654 @@ -188,11 +191,12 @@ static void dprc_add_new_devices(struct fsl_mc_device *mc_bus_dev,
6655 child_dev = fsl_mc_device_lookup(obj_desc, mc_bus_dev);
6657 check_plugged_state_change(child_dev, obj_desc);
6658 + put_device(&child_dev->dev);
6662 error = fsl_mc_device_add(obj_desc, NULL, &mc_bus_dev->dev,
6664 + driver_override, &child_dev);
6668 @@ -202,6 +206,8 @@ static void dprc_add_new_devices(struct fsl_mc_device *mc_bus_dev,
6669 * dprc_scan_objects - Discover objects in a DPRC
6671 * @mc_bus_dev: pointer to the fsl-mc device that represents a DPRC object
6672 + * @driver_override: driver override to apply to new objects found in the
6673 + * DPRC, or NULL, if none.
6674 * @total_irq_count: total number of IRQs needed by objects in the DPRC.
6676 * Detects objects added and removed from a DPRC and synchronizes the
6677 @@ -217,6 +223,7 @@ static void dprc_add_new_devices(struct fsl_mc_device *mc_bus_dev,
6678 * of the device drivers for the non-allocatable devices.
6680 int dprc_scan_objects(struct fsl_mc_device *mc_bus_dev,
6681 + const char *driver_override,
6682 unsigned int *total_irq_count)
6684 int num_child_objects;
6685 @@ -297,7 +304,7 @@ int dprc_scan_objects(struct fsl_mc_device *mc_bus_dev,
6686 dprc_remove_devices(mc_bus_dev, child_obj_desc_array,
6689 - dprc_add_new_devices(mc_bus_dev, child_obj_desc_array,
6690 + dprc_add_new_devices(mc_bus_dev, driver_override, child_obj_desc_array,
6693 if (child_obj_desc_array)
6694 @@ -328,7 +335,7 @@ int dprc_scan_container(struct fsl_mc_device *mc_bus_dev)
6695 * Discover objects in the DPRC:
6697 mutex_lock(&mc_bus->scan_mutex);
6698 - error = dprc_scan_objects(mc_bus_dev, &irq_count);
6699 + error = dprc_scan_objects(mc_bus_dev, NULL, &irq_count);
6700 mutex_unlock(&mc_bus->scan_mutex);
6703 @@ -415,7 +422,7 @@ static irqreturn_t dprc_irq0_handler_thread(int irq_num, void *arg)
6704 DPRC_IRQ_EVENT_OBJ_CREATED)) {
6705 unsigned int irq_count;
6707 - error = dprc_scan_objects(mc_dev, &irq_count);
6708 + error = dprc_scan_objects(mc_dev, NULL, &irq_count);
6711 * If the error is -ENXIO, we ignore it, as it indicates
6712 @@ -505,7 +512,7 @@ static int register_dprc_irq_handler(struct fsl_mc_device *mc_dev)
6714 dprc_irq0_handler_thread,
6715 IRQF_NO_SUSPEND | IRQF_ONESHOT,
6716 - "FSL MC DPRC irq0",
6717 + dev_name(&mc_dev->dev),
6720 dev_err(&mc_dev->dev,
6721 @@ -597,6 +604,7 @@ static int dprc_probe(struct fsl_mc_device *mc_dev)
6722 struct fsl_mc_bus *mc_bus = to_fsl_mc_bus(mc_dev);
6723 bool mc_io_created = false;
6724 bool msi_domain_set = false;
6725 + u16 major_ver, minor_ver;
6727 if (WARN_ON(strcmp(mc_dev->obj_desc.type, "dprc") != 0))
6729 @@ -669,13 +677,21 @@ static int dprc_probe(struct fsl_mc_device *mc_dev)
6730 goto error_cleanup_open;
6733 - if (mc_bus->dprc_attr.version.major < DPRC_MIN_VER_MAJOR ||
6734 - (mc_bus->dprc_attr.version.major == DPRC_MIN_VER_MAJOR &&
6735 - mc_bus->dprc_attr.version.minor < DPRC_MIN_VER_MINOR)) {
6736 + error = dprc_get_api_version(mc_dev->mc_io, 0,
6740 + dev_err(&mc_dev->dev, "dprc_get_api_version() failed: %d\n",
6742 + goto error_cleanup_open;
6745 + if (major_ver < DPRC_MIN_VER_MAJOR ||
6746 + (major_ver == DPRC_MIN_VER_MAJOR &&
6747 + minor_ver < DPRC_MIN_VER_MINOR)) {
6748 dev_err(&mc_dev->dev,
6749 "ERROR: DPRC version %d.%d not supported\n",
6750 - mc_bus->dprc_attr.version.major,
6751 - mc_bus->dprc_attr.version.minor);
6752 + major_ver, minor_ver);
6754 goto error_cleanup_open;
6756 diff --git a/drivers/staging/fsl-mc/bus/dprc.c b/drivers/staging/fsl-mc/bus/dprc.c
6757 index 9fea3def..764cd3fb 100644
6758 --- a/drivers/staging/fsl-mc/bus/dprc.c
6759 +++ b/drivers/staging/fsl-mc/bus/dprc.c
6761 -/* Copyright 2013-2016 Freescale Semiconductor Inc.
6763 + * Copyright 2013-2016 Freescale Semiconductor Inc.
6765 * Redistribution and use in source and binary forms, with or without
6766 * modification, are permitted provided that the following conditions are met:
6768 * names of any contributors may be used to endorse or promote products
6769 * derived from this software without specific prior written permission.
6772 * ALTERNATIVELY, this software may be distributed under the terms of the
6773 * GNU General Public License ("GPL") as published by the Free Software
6774 * Foundation, either version 2 of that License or (at your option) any
6775 @@ -99,93 +99,6 @@ int dprc_close(struct fsl_mc_io *mc_io,
6777 EXPORT_SYMBOL(dprc_close);
6780 - * dprc_create_container() - Create child container
6781 - * @mc_io: Pointer to MC portal's I/O object
6782 - * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
6783 - * @token: Token of DPRC object
6784 - * @cfg: Child container configuration
6785 - * @child_container_id: Returned child container ID
6786 - * @child_portal_offset: Returned child portal offset from MC portal base
6788 - * Return: '0' on Success; Error code otherwise.
6790 -int dprc_create_container(struct fsl_mc_io *mc_io,
6793 - struct dprc_cfg *cfg,
6794 - int *child_container_id,
6795 - u64 *child_portal_offset)
6797 - struct mc_command cmd = { 0 };
6798 - struct dprc_cmd_create_container *cmd_params;
6799 - struct dprc_rsp_create_container *rsp_params;
6802 - /* prepare command */
6803 - cmd_params = (struct dprc_cmd_create_container *)cmd.params;
6804 - cmd_params->options = cpu_to_le32(cfg->options);
6805 - cmd_params->icid = cpu_to_le16(cfg->icid);
6806 - cmd_params->portal_id = cpu_to_le32(cfg->portal_id);
6807 - strncpy(cmd_params->label, cfg->label, 16);
6808 - cmd_params->label[15] = '\0';
6810 - cmd.header = mc_encode_cmd_header(DPRC_CMDID_CREATE_CONT,
6811 - cmd_flags, token);
6813 - /* send command to mc*/
6814 - err = mc_send_command(mc_io, &cmd);
6818 - /* retrieve response parameters */
6819 - rsp_params = (struct dprc_rsp_create_container *)cmd.params;
6820 - *child_container_id = le32_to_cpu(rsp_params->child_container_id);
6821 - *child_portal_offset = le64_to_cpu(rsp_params->child_portal_addr);
6827 - * dprc_destroy_container() - Destroy child container.
6828 - * @mc_io: Pointer to MC portal's I/O object
6829 - * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
6830 - * @token: Token of DPRC object
6831 - * @child_container_id: ID of the container to destroy
6833 - * This function terminates the child container, so following this call the
6834 - * child container ID becomes invalid.
6837 - * - All resources and objects of the destroyed container are returned to the
6838 - * parent container or destroyed if were created be the destroyed container.
6839 - * - This function destroy all the child containers of the specified
6840 - * container prior to destroying the container itself.
6842 - * warning: Only the parent container is allowed to destroy a child policy
6843 - * Container 0 can't be destroyed
6845 - * Return: '0' on Success; Error code otherwise.
6848 -int dprc_destroy_container(struct fsl_mc_io *mc_io,
6851 - int child_container_id)
6853 - struct mc_command cmd = { 0 };
6854 - struct dprc_cmd_destroy_container *cmd_params;
6856 - /* prepare command */
6857 - cmd.header = mc_encode_cmd_header(DPRC_CMDID_DESTROY_CONT,
6858 - cmd_flags, token);
6859 - cmd_params = (struct dprc_cmd_destroy_container *)cmd.params;
6860 - cmd_params->child_container_id = cpu_to_le32(child_container_id);
6862 - /* send command to mc*/
6863 - return mc_send_command(mc_io, &cmd);
6867 * dprc_reset_container - Reset child container.
6868 * @mc_io: Pointer to MC portal's I/O object
6869 @@ -565,279 +478,6 @@ int dprc_get_attributes(struct fsl_mc_io *mc_io,
6870 attr->icid = le16_to_cpu(rsp_params->icid);
6871 attr->options = le32_to_cpu(rsp_params->options);
6872 attr->portal_id = le32_to_cpu(rsp_params->portal_id);
6873 - attr->version.major = le16_to_cpu(rsp_params->version_major);
6874 - attr->version.minor = le16_to_cpu(rsp_params->version_minor);
6880 - * dprc_set_res_quota() - Set allocation policy for a specific resource/object
6881 - * type in a child container
6882 - * @mc_io: Pointer to MC portal's I/O object
6883 - * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
6884 - * @token: Token of DPRC object
6885 - * @child_container_id: ID of the child container
6886 - * @type: Resource/object type
6887 - * @quota: Sets the maximum number of resources of the selected type
6888 - * that the child container is allowed to allocate from its parent;
6889 - * when quota is set to -1, the policy is the same as container's
6892 - * Allocation policy determines whether or not a container may allocate
6893 - * resources from its parent. Each container has a 'global' allocation policy
6894 - * that is set when the container is created.
6896 - * This function sets allocation policy for a specific resource type.
6897 - * The default policy for all resource types matches the container's 'global'
6898 - * allocation policy.
6900 - * Return: '0' on Success; Error code otherwise.
6902 - * @warning Only the parent container is allowed to change a child policy.
6904 -int dprc_set_res_quota(struct fsl_mc_io *mc_io,
6907 - int child_container_id,
6911 - struct mc_command cmd = { 0 };
6912 - struct dprc_cmd_set_res_quota *cmd_params;
6914 - /* prepare command */
6915 - cmd.header = mc_encode_cmd_header(DPRC_CMDID_SET_RES_QUOTA,
6916 - cmd_flags, token);
6917 - cmd_params = (struct dprc_cmd_set_res_quota *)cmd.params;
6918 - cmd_params->child_container_id = cpu_to_le32(child_container_id);
6919 - cmd_params->quota = cpu_to_le16(quota);
6920 - strncpy(cmd_params->type, type, 16);
6921 - cmd_params->type[15] = '\0';
6923 - /* send command to mc*/
6924 - return mc_send_command(mc_io, &cmd);
6928 - * dprc_get_res_quota() - Gets the allocation policy of a specific
6929 - * resource/object type in a child container
6930 - * @mc_io: Pointer to MC portal's I/O object
6931 - * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
6932 - * @token: Token of DPRC object
6933 - * @child_container_id; ID of the child container
6934 - * @type: resource/object type
6935 - * @quota: Returnes the maximum number of resources of the selected type
6936 - * that the child container is allowed to allocate from the parent;
6937 - * when quota is set to -1, the policy is the same as container's
6940 - * Return: '0' on Success; Error code otherwise.
6942 -int dprc_get_res_quota(struct fsl_mc_io *mc_io,
6945 - int child_container_id,
6949 - struct mc_command cmd = { 0 };
6950 - struct dprc_cmd_get_res_quota *cmd_params;
6951 - struct dprc_rsp_get_res_quota *rsp_params;
6954 - /* prepare command */
6955 - cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_RES_QUOTA,
6956 - cmd_flags, token);
6957 - cmd_params = (struct dprc_cmd_get_res_quota *)cmd.params;
6958 - cmd_params->child_container_id = cpu_to_le32(child_container_id);
6959 - strncpy(cmd_params->type, type, 16);
6960 - cmd_params->type[15] = '\0';
6962 - /* send command to mc*/
6963 - err = mc_send_command(mc_io, &cmd);
6967 - /* retrieve response parameters */
6968 - rsp_params = (struct dprc_rsp_get_res_quota *)cmd.params;
6969 - *quota = le16_to_cpu(rsp_params->quota);
6975 - * dprc_assign() - Assigns objects or resource to a child container.
6976 - * @mc_io: Pointer to MC portal's I/O object
6977 - * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
6978 - * @token: Token of DPRC object
6979 - * @container_id: ID of the child container
6980 - * @res_req: Describes the type and amount of resources to
6981 - * assign to the given container
6983 - * Assignment is usually done by a parent (this DPRC) to one of its child
6986 - * According to the DPRC allocation policy, the assigned resources may be taken
6987 - * (allocated) from the container's ancestors, if not enough resources are
6988 - * available in the container itself.
6990 - * The type of assignment depends on the dprc_res_req options, as follows:
6991 - * - DPRC_RES_REQ_OPT_EXPLICIT: indicates that assigned resources should have
6992 - * the explicit base ID specified at the id_base_align field of res_req.
6993 - * - DPRC_RES_REQ_OPT_ALIGNED: indicates that the assigned resources should be
6994 - * aligned to the value given at id_base_align field of res_req.
6995 - * - DPRC_RES_REQ_OPT_PLUGGED: Relevant only for object assignment,
6996 - * and indicates that the object must be set to the plugged state.
6998 - * A container may use this function with its own ID in order to change a
6999 - * object state to plugged or unplugged.
7001 - * If IRQ information has been set in the child DPRC, it will signal an
7002 - * interrupt following every change in its object assignment.
7004 - * Return: '0' on Success; Error code otherwise.
7006 -int dprc_assign(struct fsl_mc_io *mc_io,
7010 - struct dprc_res_req *res_req)
7012 - struct mc_command cmd = { 0 };
7013 - struct dprc_cmd_assign *cmd_params;
7015 - /* prepare command */
7016 - cmd.header = mc_encode_cmd_header(DPRC_CMDID_ASSIGN,
7017 - cmd_flags, token);
7018 - cmd_params = (struct dprc_cmd_assign *)cmd.params;
7019 - cmd_params->container_id = cpu_to_le32(container_id);
7020 - cmd_params->options = cpu_to_le32(res_req->options);
7021 - cmd_params->num = cpu_to_le32(res_req->num);
7022 - cmd_params->id_base_align = cpu_to_le32(res_req->id_base_align);
7023 - strncpy(cmd_params->type, res_req->type, 16);
7024 - cmd_params->type[15] = '\0';
7026 - /* send command to mc*/
7027 - return mc_send_command(mc_io, &cmd);
7031 - * dprc_unassign() - Un-assigns objects or resources from a child container
7032 - * and moves them into this (parent) DPRC.
7033 - * @mc_io: Pointer to MC portal's I/O object
7034 - * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
7035 - * @token: Token of DPRC object
7036 - * @child_container_id: ID of the child container
7037 - * @res_req: Describes the type and amount of resources to un-assign from
7038 - * the child container
7040 - * Un-assignment of objects can succeed only if the object is not in the
7041 - * plugged or opened state.
7043 - * Return: '0' on Success; Error code otherwise.
7045 -int dprc_unassign(struct fsl_mc_io *mc_io,
7048 - int child_container_id,
7049 - struct dprc_res_req *res_req)
7051 - struct mc_command cmd = { 0 };
7052 - struct dprc_cmd_unassign *cmd_params;
7054 - /* prepare command */
7055 - cmd.header = mc_encode_cmd_header(DPRC_CMDID_UNASSIGN,
7058 - cmd_params = (struct dprc_cmd_unassign *)cmd.params;
7059 - cmd_params->child_container_id = cpu_to_le32(child_container_id);
7060 - cmd_params->options = cpu_to_le32(res_req->options);
7061 - cmd_params->num = cpu_to_le32(res_req->num);
7062 - cmd_params->id_base_align = cpu_to_le32(res_req->id_base_align);
7063 - strncpy(cmd_params->type, res_req->type, 16);
7064 - cmd_params->type[15] = '\0';
7066 - /* send command to mc*/
7067 - return mc_send_command(mc_io, &cmd);
7071 - * dprc_get_pool_count() - Get the number of dprc's pools
7072 - * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
7073 - * @mc_io: Pointer to MC portal's I/O object
7074 - * @token: Token of DPRC object
7075 - * @pool_count: Returned number of resource pools in the dprc
7077 - * Return: '0' on Success; Error code otherwise.
7079 -int dprc_get_pool_count(struct fsl_mc_io *mc_io,
7084 - struct mc_command cmd = { 0 };
7085 - struct dprc_rsp_get_pool_count *rsp_params;
7088 - /* prepare command */
7089 - cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_POOL_COUNT,
7090 - cmd_flags, token);
7092 - /* send command to mc*/
7093 - err = mc_send_command(mc_io, &cmd);
7097 - /* retrieve response parameters */
7098 - rsp_params = (struct dprc_rsp_get_pool_count *)cmd.params;
7099 - *pool_count = le32_to_cpu(rsp_params->pool_count);
7105 - * dprc_get_pool() - Get the type (string) of a certain dprc's pool
7106 - * @mc_io: Pointer to MC portal's I/O object
7107 - * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
7108 - * @token: Token of DPRC object
7109 - * @pool_index; Index of the pool to be queried (< pool_count)
7110 - * @type: The type of the pool
7112 - * The pool types retrieved one by one by incrementing
7113 - * pool_index up to (not including) the value of pool_count returned
7114 - * from dprc_get_pool_count(). dprc_get_pool_count() must
7115 - * be called prior to dprc_get_pool().
7117 - * Return: '0' on Success; Error code otherwise.
7119 -int dprc_get_pool(struct fsl_mc_io *mc_io,
7125 - struct mc_command cmd = { 0 };
7126 - struct dprc_cmd_get_pool *cmd_params;
7127 - struct dprc_rsp_get_pool *rsp_params;
7130 - /* prepare command */
7131 - cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_POOL,
7134 - cmd_params = (struct dprc_cmd_get_pool *)cmd.params;
7135 - cmd_params->pool_index = cpu_to_le32(pool_index);
7137 - /* send command to mc*/
7138 - err = mc_send_command(mc_io, &cmd);
7142 - /* retrieve response parameters */
7143 - rsp_params = (struct dprc_rsp_get_pool *)cmd.params;
7144 - strncpy(type, rsp_params->type, 16);
7149 @@ -933,64 +573,6 @@ int dprc_get_obj(struct fsl_mc_io *mc_io,
7151 EXPORT_SYMBOL(dprc_get_obj);
7154 - * dprc_get_obj_desc() - Get object descriptor.
7156 - * @mc_io: Pointer to MC portal's I/O object
7157 - * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
7158 - * @token: Token of DPRC object
7159 - * @obj_type: The type of the object to get its descriptor.
7160 - * @obj_id: The id of the object to get its descriptor
7161 - * @obj_desc: The returned descriptor to fill and return to the user
7163 - * Return: '0' on Success; Error code otherwise.
7166 -int dprc_get_obj_desc(struct fsl_mc_io *mc_io,
7171 - struct dprc_obj_desc *obj_desc)
7173 - struct mc_command cmd = { 0 };
7174 - struct dprc_cmd_get_obj_desc *cmd_params;
7175 - struct dprc_rsp_get_obj_desc *rsp_params;
7178 - /* prepare command */
7179 - cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_OBJ_DESC,
7182 - cmd_params = (struct dprc_cmd_get_obj_desc *)cmd.params;
7183 - cmd_params->obj_id = cpu_to_le32(obj_id);
7184 - strncpy(cmd_params->type, obj_type, 16);
7185 - cmd_params->type[15] = '\0';
7187 - /* send command to mc*/
7188 - err = mc_send_command(mc_io, &cmd);
7192 - /* retrieve response parameters */
7193 - rsp_params = (struct dprc_rsp_get_obj_desc *)cmd.params;
7194 - obj_desc->id = le32_to_cpu(rsp_params->id);
7195 - obj_desc->vendor = le16_to_cpu(rsp_params->vendor);
7196 - obj_desc->irq_count = rsp_params->irq_count;
7197 - obj_desc->region_count = rsp_params->region_count;
7198 - obj_desc->state = le32_to_cpu(rsp_params->state);
7199 - obj_desc->ver_major = le16_to_cpu(rsp_params->version_major);
7200 - obj_desc->ver_minor = le16_to_cpu(rsp_params->version_minor);
7201 - obj_desc->flags = le16_to_cpu(rsp_params->flags);
7202 - strncpy(obj_desc->type, rsp_params->type, 16);
7203 - obj_desc->type[15] = '\0';
7204 - strncpy(obj_desc->label, rsp_params->label, 16);
7205 - obj_desc->label[15] = '\0';
7209 -EXPORT_SYMBOL(dprc_get_obj_desc);
7212 * dprc_set_obj_irq() - Set IRQ information for object to trigger an interrupt.
7213 * @mc_io: Pointer to MC portal's I/O object
7214 @@ -1129,52 +711,6 @@ int dprc_get_res_count(struct fsl_mc_io *mc_io,
7216 EXPORT_SYMBOL(dprc_get_res_count);
7219 - * dprc_get_res_ids() - Obtains IDs of free resources in the container
7220 - * @mc_io: Pointer to MC portal's I/O object
7221 - * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
7222 - * @token: Token of DPRC object
7223 - * @type: pool type
7224 - * @range_desc: range descriptor
7226 - * Return: '0' on Success; Error code otherwise.
7228 -int dprc_get_res_ids(struct fsl_mc_io *mc_io,
7232 - struct dprc_res_ids_range_desc *range_desc)
7234 - struct mc_command cmd = { 0 };
7235 - struct dprc_cmd_get_res_ids *cmd_params;
7236 - struct dprc_rsp_get_res_ids *rsp_params;
7239 - /* prepare command */
7240 - cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_RES_IDS,
7241 - cmd_flags, token);
7242 - cmd_params = (struct dprc_cmd_get_res_ids *)cmd.params;
7243 - cmd_params->iter_status = range_desc->iter_status;
7244 - cmd_params->base_id = cpu_to_le32(range_desc->base_id);
7245 - cmd_params->last_id = cpu_to_le32(range_desc->last_id);
7246 - strncpy(cmd_params->type, type, 16);
7247 - cmd_params->type[15] = '\0';
7249 - /* send command to mc*/
7250 - err = mc_send_command(mc_io, &cmd);
7254 - /* retrieve response parameters */
7255 - rsp_params = (struct dprc_rsp_get_res_ids *)cmd.params;
7256 - range_desc->iter_status = rsp_params->iter_status;
7257 - range_desc->base_id = le32_to_cpu(rsp_params->base_id);
7258 - range_desc->last_id = le32_to_cpu(rsp_params->last_id);
7262 -EXPORT_SYMBOL(dprc_get_res_ids);
7265 * dprc_get_obj_region() - Get region information for a specified object.
7266 * @mc_io: Pointer to MC portal's I/O object
7267 @@ -1216,160 +752,66 @@ int dprc_get_obj_region(struct fsl_mc_io *mc_io,
7269 /* retrieve response parameters */
7270 rsp_params = (struct dprc_rsp_get_obj_region *)cmd.params;
7271 - region_desc->base_offset = le64_to_cpu(rsp_params->base_addr);
7272 + region_desc->base_offset = le32_to_cpu(rsp_params->base_addr);
7273 region_desc->size = le32_to_cpu(rsp_params->size);
7274 + region_desc->type = rsp_params->type;
7275 + region_desc->flags = le32_to_cpu(rsp_params->flags);
7279 EXPORT_SYMBOL(dprc_get_obj_region);
7282 - * dprc_set_obj_label() - Set object label.
7283 - * @mc_io: Pointer to MC portal's I/O object
7284 + * dprc_get_api_version - Get Data Path Resource Container API version
7285 + * @mc_io: Pointer to Mc portal's I/O object
7286 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
7287 - * @token: Token of DPRC object
7288 - * @obj_type: Object's type
7289 - * @obj_id: Object's ID
7290 - * @label: The required label. The maximum length is 16 chars.
7291 + * @major_ver: Major version of Data Path Resource Container API
7292 + * @minor_ver: Minor version of Data Path Resource Container API
7294 * Return: '0' on Success; Error code otherwise.
7296 -int dprc_set_obj_label(struct fsl_mc_io *mc_io,
7302 +int dprc_get_api_version(struct fsl_mc_io *mc_io,
7307 struct mc_command cmd = { 0 };
7308 - struct dprc_cmd_set_obj_label *cmd_params;
7311 /* prepare command */
7312 - cmd.header = mc_encode_cmd_header(DPRC_CMDID_SET_OBJ_LABEL,
7315 - cmd_params = (struct dprc_cmd_set_obj_label *)cmd.params;
7316 - cmd_params->obj_id = cpu_to_le32(obj_id);
7317 - strncpy(cmd_params->label, label, 16);
7318 - cmd_params->label[15] = '\0';
7319 - strncpy(cmd_params->obj_type, obj_type, 16);
7320 - cmd_params->obj_type[15] = '\0';
7321 + cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_API_VERSION,
7324 - /* send command to mc*/
7325 - return mc_send_command(mc_io, &cmd);
7327 -EXPORT_SYMBOL(dprc_set_obj_label);
7330 - * dprc_connect() - Connect two endpoints to create a network link between them
7331 - * @mc_io: Pointer to MC portal's I/O object
7332 - * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
7333 - * @token: Token of DPRC object
7334 - * @endpoint1: Endpoint 1 configuration parameters
7335 - * @endpoint2: Endpoint 2 configuration parameters
7336 - * @cfg: Connection configuration. The connection configuration is ignored for
7337 - * connections made to DPMAC objects, where rate is retrieved from the
7338 - * MAC configuration.
7340 - * Return: '0' on Success; Error code otherwise.
7342 -int dprc_connect(struct fsl_mc_io *mc_io,
7345 - const struct dprc_endpoint *endpoint1,
7346 - const struct dprc_endpoint *endpoint2,
7347 - const struct dprc_connection_cfg *cfg)
7349 - struct mc_command cmd = { 0 };
7350 - struct dprc_cmd_connect *cmd_params;
7351 + /* send command to mc */
7352 + err = mc_send_command(mc_io, &cmd);
7356 - /* prepare command */
7357 - cmd.header = mc_encode_cmd_header(DPRC_CMDID_CONNECT,
7360 - cmd_params = (struct dprc_cmd_connect *)cmd.params;
7361 - cmd_params->ep1_id = cpu_to_le32(endpoint1->id);
7362 - cmd_params->ep1_interface_id = cpu_to_le32(endpoint1->if_id);
7363 - cmd_params->ep2_id = cpu_to_le32(endpoint2->id);
7364 - cmd_params->ep2_interface_id = cpu_to_le32(endpoint2->if_id);
7365 - strncpy(cmd_params->ep1_type, endpoint1->type, 16);
7366 - cmd_params->ep1_type[15] = '\0';
7367 - cmd_params->max_rate = cpu_to_le32(cfg->max_rate);
7368 - cmd_params->committed_rate = cpu_to_le32(cfg->committed_rate);
7369 - strncpy(cmd_params->ep2_type, endpoint2->type, 16);
7370 - cmd_params->ep2_type[15] = '\0';
7371 + /* retrieve response parameters */
7372 + mc_cmd_read_api_version(&cmd, major_ver, minor_ver);
7374 - /* send command to mc*/
7375 - return mc_send_command(mc_io, &cmd);
7380 - * dprc_disconnect() - Disconnect one endpoint to remove its network connection
7381 - * @mc_io: Pointer to MC portal's I/O object
7382 - * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
7383 - * @token: Token of DPRC object
7384 - * @endpoint: Endpoint configuration parameters
7385 + * dprc_get_container_id - Get container ID associated with a given portal.
7386 + * @mc_io: Pointer to Mc portal's I/O object
7387 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
7388 + * @container_id: Requested container id
7390 * Return: '0' on Success; Error code otherwise.
7392 -int dprc_disconnect(struct fsl_mc_io *mc_io,
7395 - const struct dprc_endpoint *endpoint)
7397 - struct mc_command cmd = { 0 };
7398 - struct dprc_cmd_disconnect *cmd_params;
7400 - /* prepare command */
7401 - cmd.header = mc_encode_cmd_header(DPRC_CMDID_DISCONNECT,
7404 - cmd_params = (struct dprc_cmd_disconnect *)cmd.params;
7405 - cmd_params->id = cpu_to_le32(endpoint->id);
7406 - cmd_params->interface_id = cpu_to_le32(endpoint->if_id);
7407 - strncpy(cmd_params->type, endpoint->type, 16);
7408 - cmd_params->type[15] = '\0';
7410 - /* send command to mc*/
7411 - return mc_send_command(mc_io, &cmd);
7415 - * dprc_get_connection() - Get connected endpoint and link status if connection
7417 - * @mc_io: Pointer to MC portal's I/O object
7418 - * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
7419 - * @token: Token of DPRC object
7420 - * @endpoint1: Endpoint 1 configuration parameters
7421 - * @endpoint2: Returned endpoint 2 configuration parameters
7422 - * @state: Returned link state:
7424 - * 0 - link is down;
7425 - * -1 - no connection (endpoint2 information is irrelevant)
7427 - * Return: '0' on Success; -ENAVAIL if connection does not exist.
7429 -int dprc_get_connection(struct fsl_mc_io *mc_io,
7432 - const struct dprc_endpoint *endpoint1,
7433 - struct dprc_endpoint *endpoint2,
7435 +int dprc_get_container_id(struct fsl_mc_io *mc_io,
7437 + int *container_id)
7439 struct mc_command cmd = { 0 };
7440 - struct dprc_cmd_get_connection *cmd_params;
7441 - struct dprc_rsp_get_connection *rsp_params;
7444 /* prepare command */
7445 - cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_CONNECTION,
7446 + cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_CONT_ID,
7449 - cmd_params = (struct dprc_cmd_get_connection *)cmd.params;
7450 - cmd_params->ep1_id = cpu_to_le32(endpoint1->id);
7451 - cmd_params->ep1_interface_id = cpu_to_le32(endpoint1->if_id);
7452 - strncpy(cmd_params->ep1_type, endpoint1->type, 16);
7453 - cmd_params->ep1_type[15] = '\0';
7456 /* send command to mc*/
7457 err = mc_send_command(mc_io, &cmd);
7458 @@ -1377,12 +819,7 @@ int dprc_get_connection(struct fsl_mc_io *mc_io,
7461 /* retrieve response parameters */
7462 - rsp_params = (struct dprc_rsp_get_connection *)cmd.params;
7463 - endpoint2->id = le32_to_cpu(rsp_params->ep2_id);
7464 - endpoint2->if_id = le32_to_cpu(rsp_params->ep2_interface_id);
7465 - strncpy(endpoint2->type, rsp_params->ep2_type, 16);
7466 - endpoint2->type[15] = '\0';
7467 - *state = le32_to_cpu(rsp_params->state);
7468 + *container_id = (int)mc_cmd_read_object_id(&cmd);
7472 diff --git a/drivers/staging/fsl-mc/bus/fsl-mc-allocator.c b/drivers/staging/fsl-mc/bus/fsl-mc-allocator.c
7473 index e93ab53b..ce07096c 100644
7474 --- a/drivers/staging/fsl-mc/bus/fsl-mc-allocator.c
7475 +++ b/drivers/staging/fsl-mc/bus/fsl-mc-allocator.c
7478 - * Freescale MC object device allocator driver
7479 + * fsl-mc object allocator driver
7481 - * Copyright (C) 2013 Freescale Semiconductor, Inc.
7482 + * Copyright (C) 2013-2016 Freescale Semiconductor, Inc.
7484 * This file is licensed under the terms of the GNU General Public
7485 * License version 2. This program is licensed "as is" without any
7487 #include <linux/msi.h>
7488 #include "../include/mc-bus.h"
7489 #include "../include/mc-sys.h"
7490 -#include "../include/dpbp-cmd.h"
7491 -#include "../include/dpcon-cmd.h"
7493 +#include "dpbp-cmd.h"
7494 +#include "dpcon-cmd.h"
7495 #include "fsl-mc-private.h"
7497 #define FSL_MC_IS_ALLOCATABLE(_obj_type) \
7499 strcmp(_obj_type, "dpcon") == 0)
7502 - * fsl_mc_resource_pool_add_device - add allocatable device to a resource
7503 - * pool of a given MC bus
7504 + * fsl_mc_resource_pool_add_device - add allocatable object to a resource
7505 + * pool of a given fsl-mc bus
7507 - * @mc_bus: pointer to the MC bus
7508 - * @pool_type: MC bus pool type
7509 - * @mc_dev: Pointer to allocatable MC object device
7511 - * It adds an allocatable MC object device to a container's resource pool of
7512 - * the given resource type
7513 + * @mc_bus: pointer to the fsl-mc bus
7514 + * @pool_type: pool type
7515 + * @mc_dev: pointer to allocatable fsl-mc device
7517 static int __must_check fsl_mc_resource_pool_add_device(struct fsl_mc_bus
7519 @@ -95,10 +92,10 @@ static int __must_check fsl_mc_resource_pool_add_device(struct fsl_mc_bus
7520 * fsl_mc_resource_pool_remove_device - remove an allocatable device from a
7523 - * @mc_dev: Pointer to allocatable MC object device
7524 + * @mc_dev: pointer to allocatable fsl-mc device
7526 - * It permanently removes an allocatable MC object device from the resource
7527 - * pool, the device is currently in, as long as it is in the pool's free list.
7528 + * It permanently removes an allocatable fsl-mc device from the resource
7529 + * pool. It's an error if the device is in use.
7531 static int __must_check fsl_mc_resource_pool_remove_device(struct fsl_mc_device
7533 @@ -255,17 +252,18 @@ void fsl_mc_resource_free(struct fsl_mc_resource *resource)
7534 EXPORT_SYMBOL_GPL(fsl_mc_resource_free);
7537 - * fsl_mc_object_allocate - Allocates a MC object device of the given
7538 - * pool type from a given MC bus
7539 + * fsl_mc_object_allocate - Allocates an fsl-mc object of the given
7540 + * pool type from a given fsl-mc bus instance
7542 - * @mc_dev: MC device for which the MC object device is to be allocated
7543 - * @pool_type: MC bus resource pool type
7544 - * @new_mc_dev: Pointer to area where the pointer to the allocated
7545 - * MC object device is to be returned
7546 + * @mc_dev: fsl-mc device which is used in conjunction with the
7547 + * allocated object
7548 + * @pool_type: pool type
7549 + * @new_mc_dev: pointer to area where the pointer to the allocated device
7550 + * is to be returned
7552 - * This function allocates a MC object device from the device's parent DPRC,
7553 - * from the corresponding MC bus' pool of allocatable MC object devices of
7554 - * the given resource type. mc_dev cannot be a DPRC itself.
7555 + * Allocatable objects are always used in conjunction with some functional
7556 + * device. This function allocates an object of the specified type from
7557 + * the DPRC containing the functional device.
7559 * NOTE: pool_type must be different from FSL_MC_POOL_MCP, since MC
7560 * portals are allocated using fsl_mc_portal_allocate(), instead of
7561 @@ -312,10 +310,9 @@ int __must_check fsl_mc_object_allocate(struct fsl_mc_device *mc_dev,
7562 EXPORT_SYMBOL_GPL(fsl_mc_object_allocate);
7565 - * fsl_mc_object_free - Returns an allocatable MC object device to the
7566 - * corresponding resource pool of a given MC bus.
7568 - * @mc_adev: Pointer to the MC object device
7569 + * fsl_mc_object_free - Returns an fsl-mc object to the resource
7570 + * pool where it came from.
7571 + * @mc_adev: Pointer to the fsl-mc device
7573 void fsl_mc_object_free(struct fsl_mc_device *mc_adev)
7575 @@ -332,8 +329,14 @@ void fsl_mc_object_free(struct fsl_mc_device *mc_adev)
7576 EXPORT_SYMBOL_GPL(fsl_mc_object_free);
7579 - * Initialize the interrupt pool associated with a MC bus.
7580 - * It allocates a block of IRQs from the GIC-ITS
7581 + * A DPRC and the devices in the DPRC all share the same GIC-ITS device
7582 + * ID. A block of IRQs is pre-allocated and maintained in a pool
7583 + * from which devices can allocate them when needed.
7587 + * Initialize the interrupt pool associated with an fsl-mc bus.
7588 + * It allocates a block of IRQs from the GIC-ITS.
7590 int fsl_mc_populate_irq_pool(struct fsl_mc_bus *mc_bus,
7591 unsigned int irq_count)
7592 @@ -395,7 +398,7 @@ int fsl_mc_populate_irq_pool(struct fsl_mc_bus *mc_bus,
7593 EXPORT_SYMBOL_GPL(fsl_mc_populate_irq_pool);
7596 - * Teardown the interrupt pool associated with an MC bus.
7597 + * Teardown the interrupt pool associated with an fsl-mc bus.
7598 * It frees the IRQs that were allocated to the pool, back to the GIC-ITS.
7600 void fsl_mc_cleanup_irq_pool(struct fsl_mc_bus *mc_bus)
7601 @@ -422,11 +425,7 @@ void fsl_mc_cleanup_irq_pool(struct fsl_mc_bus *mc_bus)
7602 EXPORT_SYMBOL_GPL(fsl_mc_cleanup_irq_pool);
7605 - * It allocates the IRQs required by a given MC object device. The
7606 - * IRQs are allocated from the interrupt pool associated with the
7607 - * MC bus that contains the device, if the device is not a DPRC device.
7608 - * Otherwise, the IRQs are allocated from the interrupt pool associated
7609 - * with the MC bus that represents the DPRC device itself.
7610 + * Allocate the IRQs required by a given fsl-mc device.
7612 int __must_check fsl_mc_allocate_irqs(struct fsl_mc_device *mc_dev)
7614 @@ -495,8 +494,7 @@ int __must_check fsl_mc_allocate_irqs(struct fsl_mc_device *mc_dev)
7615 EXPORT_SYMBOL_GPL(fsl_mc_allocate_irqs);
7618 - * It frees the IRQs that were allocated for a MC object device, by
7619 - * returning them to the corresponding interrupt pool.
7620 + * Frees the IRQs that were allocated for an fsl-mc device.
7622 void fsl_mc_free_irqs(struct fsl_mc_device *mc_dev)
7624 @@ -605,7 +603,7 @@ static int fsl_mc_allocator_probe(struct fsl_mc_device *mc_dev)
7627 dev_dbg(&mc_dev->dev,
7628 - "Allocatable MC object device bound to fsl_mc_allocator driver");
7629 + "Allocatable fsl-mc device bound to fsl_mc_allocator driver");
7633 @@ -627,7 +625,7 @@ static int fsl_mc_allocator_remove(struct fsl_mc_device *mc_dev)
7636 dev_dbg(&mc_dev->dev,
7637 - "Allocatable MC object device unbound from fsl_mc_allocator driver");
7638 + "Allocatable fsl-mc device unbound from fsl_mc_allocator driver");
7642 diff --git a/drivers/staging/fsl-mc/bus/fsl-mc-bus.c b/drivers/staging/fsl-mc/bus/fsl-mc-bus.c
7643 index 44f64b6f..30a48df3 100644
7644 --- a/drivers/staging/fsl-mc/bus/fsl-mc-bus.c
7645 +++ b/drivers/staging/fsl-mc/bus/fsl-mc-bus.c
7648 * Freescale Management Complex (MC) bus driver
7650 - * Copyright (C) 2014 Freescale Semiconductor, Inc.
7651 + * Copyright (C) 2014-2016 Freescale Semiconductor, Inc.
7652 * Author: German Rivera <German.Rivera@freescale.com>
7654 * This file is licensed under the terms of the GNU General Public
7656 * warranty of any kind, whether express or implied.
7659 +#define pr_fmt(fmt) "fsl-mc: " fmt
7661 #include <linux/module.h>
7662 #include <linux/of_device.h>
7663 #include <linux/of_address.h>
7665 #include "fsl-mc-private.h"
7666 #include "dprc-cmd.h"
7668 -static struct kmem_cache *mc_dev_cache;
7671 * Default DMA mask for devices on a fsl-mc bus
7673 @@ -34,7 +34,7 @@ static struct kmem_cache *mc_dev_cache;
7676 * struct fsl_mc - Private data of a "fsl,qoriq-mc" platform device
7677 - * @root_mc_bus_dev: MC object device representing the root DPRC
7678 + * @root_mc_bus_dev: fsl-mc device representing the root DPRC
7679 * @num_translation_ranges: number of entries in addr_translation_ranges
7680 * @translation_ranges: array of bus to system address translation ranges
7682 @@ -62,8 +62,8 @@ struct fsl_mc_addr_translation_range {
7685 * fsl_mc_bus_match - device to driver matching callback
7686 - * @dev: the MC object device structure to match against
7687 - * @drv: the device driver to search for matching MC object device id
7688 + * @dev: the fsl-mc device to match against
7689 + * @drv: the device driver to search for matching fsl-mc object type
7692 * Returns 1 on success, 0 otherwise.
7693 @@ -75,8 +75,11 @@ static int fsl_mc_bus_match(struct device *dev, struct device_driver *drv)
7694 struct fsl_mc_driver *mc_drv = to_fsl_mc_driver(drv);
7697 - if (WARN_ON(!fsl_mc_bus_exists()))
7698 + /* When driver_override is set, only bind to the matching driver */
7699 + if (mc_dev->driver_override) {
7700 + found = !strcmp(mc_dev->driver_override, mc_drv->driver.name);
7704 if (!mc_drv->match_id_table)
7706 @@ -91,7 +94,7 @@ static int fsl_mc_bus_match(struct device *dev, struct device_driver *drv)
7709 * Traverse the match_id table of the given driver, trying to find
7710 - * a matching for the given MC object device.
7711 + * a matching for the given device.
7713 for (id = mc_drv->match_id_table; id->vendor != 0x0; id++) {
7714 if (id->vendor == mc_dev->obj_desc.vendor &&
7715 @@ -132,23 +135,141 @@ static ssize_t modalias_show(struct device *dev, struct device_attribute *attr,
7717 static DEVICE_ATTR_RO(modalias);
7719 +static ssize_t rescan_store(struct device *dev,
7720 + struct device_attribute *attr,
7721 + const char *buf, size_t count)
7723 + unsigned long val;
7724 + unsigned int irq_count;
7725 + struct fsl_mc_device *root_mc_dev;
7726 + struct fsl_mc_bus *root_mc_bus;
7728 + if (!fsl_mc_is_root_dprc(dev))
7731 + root_mc_dev = to_fsl_mc_device(dev);
7732 + root_mc_bus = to_fsl_mc_bus(root_mc_dev);
7734 + if (kstrtoul(buf, 0, &val) < 0)
7738 + mutex_lock(&root_mc_bus->scan_mutex);
7739 + dprc_scan_objects(root_mc_dev, NULL, &irq_count);
7740 + mutex_unlock(&root_mc_bus->scan_mutex);
7745 +static DEVICE_ATTR_WO(rescan);
7747 +static ssize_t driver_override_store(struct device *dev,
7748 + struct device_attribute *attr,
7749 + const char *buf, size_t count)
7751 + struct fsl_mc_device *mc_dev = to_fsl_mc_device(dev);
7752 + const char *driver_override, *old = mc_dev->driver_override;
7755 + if (WARN_ON(dev->bus != &fsl_mc_bus_type))
7758 + if (count >= (PAGE_SIZE - 1))
7761 + driver_override = kstrndup(buf, count, GFP_KERNEL);
7762 + if (!driver_override)
7765 + cp = strchr(driver_override, '\n');
7769 + if (strlen(driver_override)) {
7770 + mc_dev->driver_override = driver_override;
7772 + kfree(driver_override);
7773 + mc_dev->driver_override = NULL;
7781 +static ssize_t driver_override_show(struct device *dev,
7782 + struct device_attribute *attr, char *buf)
7784 + struct fsl_mc_device *mc_dev = to_fsl_mc_device(dev);
7786 + return snprintf(buf, PAGE_SIZE, "%s\n", mc_dev->driver_override);
7788 +static DEVICE_ATTR_RW(driver_override);
7790 static struct attribute *fsl_mc_dev_attrs[] = {
7791 &dev_attr_modalias.attr,
7792 + &dev_attr_rescan.attr,
7793 + &dev_attr_driver_override.attr,
7797 ATTRIBUTE_GROUPS(fsl_mc_dev);
7799 +static int scan_fsl_mc_bus(struct device *dev, void *data)
7801 + unsigned int irq_count;
7802 + struct fsl_mc_device *root_mc_dev;
7803 + struct fsl_mc_bus *root_mc_bus;
7805 + if (fsl_mc_is_root_dprc(dev)) {
7806 + root_mc_dev = to_fsl_mc_device(dev);
7807 + root_mc_bus = to_fsl_mc_bus(root_mc_dev);
7808 + mutex_lock(&root_mc_bus->scan_mutex);
7809 + dprc_scan_objects(root_mc_dev, NULL, &irq_count);
7810 + mutex_unlock(&root_mc_bus->scan_mutex);
7816 +static ssize_t bus_rescan_store(struct bus_type *bus,
7817 + const char *buf, size_t count)
7819 + unsigned long val;
7821 + if (kstrtoul(buf, 0, &val) < 0)
7825 + bus_for_each_dev(bus, NULL, NULL, scan_fsl_mc_bus);
7829 +static BUS_ATTR(rescan, (S_IWUSR | S_IWGRP), NULL, bus_rescan_store);
7831 +static struct attribute *fsl_mc_bus_attrs[] = {
7832 + &bus_attr_rescan.attr,
7836 +static const struct attribute_group fsl_mc_bus_group = {
7837 + .attrs = fsl_mc_bus_attrs,
7840 +static const struct attribute_group *fsl_mc_bus_groups[] = {
7841 + &fsl_mc_bus_group,
7845 struct bus_type fsl_mc_bus_type = {
7847 .match = fsl_mc_bus_match,
7848 .uevent = fsl_mc_bus_uevent,
7849 .dev_groups = fsl_mc_dev_groups,
7850 + .bus_groups = fsl_mc_bus_groups,
7852 EXPORT_SYMBOL_GPL(fsl_mc_bus_type);
7854 -static atomic_t root_dprc_count = ATOMIC_INIT(0);
7856 static int fsl_mc_driver_probe(struct device *dev)
7858 struct fsl_mc_driver *mc_drv;
7859 @@ -164,8 +285,7 @@ static int fsl_mc_driver_probe(struct device *dev)
7861 error = mc_drv->probe(mc_dev);
7863 - dev_err(dev, "MC object device probe callback failed: %d\n",
7865 + dev_err(dev, "%s failed: %d\n", __func__, error);
7869 @@ -183,9 +303,7 @@ static int fsl_mc_driver_remove(struct device *dev)
7871 error = mc_drv->remove(mc_dev);
7874 - "MC object device remove callback failed: %d\n",
7876 + dev_err(dev, "%s failed: %d\n", __func__, error);
7880 @@ -232,8 +350,6 @@ int __fsl_mc_driver_register(struct fsl_mc_driver *mc_driver,
7884 - pr_info("MC object device driver %s registered\n",
7885 - mc_driver->driver.name);
7888 EXPORT_SYMBOL_GPL(__fsl_mc_driver_register);
7889 @@ -248,15 +364,6 @@ void fsl_mc_driver_unregister(struct fsl_mc_driver *mc_driver)
7891 EXPORT_SYMBOL_GPL(fsl_mc_driver_unregister);
7894 - * fsl_mc_bus_exists - check if a root dprc exists
7896 -bool fsl_mc_bus_exists(void)
7898 - return atomic_read(&root_dprc_count) > 0;
7900 -EXPORT_SYMBOL_GPL(fsl_mc_bus_exists);
7903 * fsl_mc_get_root_dprc - function to traverse to the root dprc
7905 @@ -315,21 +422,6 @@ static int get_dprc_icid(struct fsl_mc_io *mc_io,
7909 -static int get_dprc_version(struct fsl_mc_io *mc_io,
7910 - int container_id, u16 *major, u16 *minor)
7912 - struct dprc_attributes attr;
7915 - error = get_dprc_attr(mc_io, container_id, &attr);
7917 - *major = attr.version.major;
7918 - *minor = attr.version.minor;
7924 static int translate_mc_addr(struct fsl_mc_device *mc_dev,
7925 enum dprc_region_type mc_region_type,
7926 u64 mc_offset, phys_addr_t *phys_addr)
7927 @@ -451,18 +543,37 @@ bool fsl_mc_is_root_dprc(struct device *dev)
7928 return dev == root_dprc_dev;
7931 +static void fsl_mc_device_release(struct device *dev)
7933 + struct fsl_mc_device *mc_dev = to_fsl_mc_device(dev);
7934 + struct fsl_mc_bus *mc_bus = NULL;
7936 + kfree(mc_dev->regions);
7938 + if (strcmp(mc_dev->obj_desc.type, "dprc") == 0)
7939 + mc_bus = to_fsl_mc_bus(mc_dev);
7948 - * Add a newly discovered MC object device to be visible in Linux
7949 + * Add a newly discovered fsl-mc device to be visible in Linux
7951 int fsl_mc_device_add(struct dprc_obj_desc *obj_desc,
7952 struct fsl_mc_io *mc_io,
7953 struct device *parent_dev,
7954 + const char *driver_override,
7955 struct fsl_mc_device **new_mc_dev)
7958 struct fsl_mc_device *mc_dev = NULL;
7959 struct fsl_mc_bus *mc_bus = NULL;
7960 struct fsl_mc_device *parent_mc_dev;
7961 + struct device *fsl_mc_platform_dev;
7962 + struct device_node *fsl_mc_platform_node;
7964 if (dev_is_fsl_mc(parent_dev))
7965 parent_mc_dev = to_fsl_mc_device(parent_dev);
7966 @@ -473,7 +584,7 @@ int fsl_mc_device_add(struct dprc_obj_desc *obj_desc,
7968 * Allocate an MC bus device object:
7970 - mc_bus = devm_kzalloc(parent_dev, sizeof(*mc_bus), GFP_KERNEL);
7971 + mc_bus = kzalloc(sizeof(*mc_bus), GFP_KERNEL);
7975 @@ -482,16 +593,30 @@ int fsl_mc_device_add(struct dprc_obj_desc *obj_desc,
7977 * Allocate a regular fsl_mc_device object:
7979 - mc_dev = kmem_cache_zalloc(mc_dev_cache, GFP_KERNEL);
7980 + mc_dev = kzalloc(sizeof(*mc_dev), GFP_KERNEL);
7985 mc_dev->obj_desc = *obj_desc;
7986 mc_dev->mc_io = mc_io;
7988 + if (driver_override) {
7990 + * We trust driver_override, so we don't need to use
7993 + mc_dev->driver_override = kstrdup(driver_override, GFP_KERNEL);
7994 + if (!mc_dev->driver_override) {
7996 + goto error_cleanup_dev;
8000 device_initialize(&mc_dev->dev);
8001 mc_dev->dev.parent = parent_dev;
8002 mc_dev->dev.bus = &fsl_mc_bus_type;
8003 + mc_dev->dev.release = fsl_mc_device_release;
8004 dev_set_name(&mc_dev->dev, "%s.%d", obj_desc->type, obj_desc->id);
8006 if (strcmp(obj_desc->type, "dprc") == 0) {
8007 @@ -524,8 +649,6 @@ int fsl_mc_device_add(struct dprc_obj_desc *obj_desc,
8012 - atomic_inc(&root_dprc_count);
8015 error = get_dprc_icid(mc_io2, obj_desc->id, &mc_dev->icid);
8016 @@ -533,8 +656,8 @@ int fsl_mc_device_add(struct dprc_obj_desc *obj_desc,
8017 goto error_cleanup_dev;
8020 - * A non-DPRC MC object device has to be a child of another
8021 - * MC object (specifically a DPRC object)
8022 + * A non-DPRC object has to be a child of a DPRC, use the
8023 + * parent's ICID and interrupt domain.
8025 mc_dev->icid = parent_mc_dev->icid;
8026 mc_dev->dma_mask = FSL_MC_DEFAULT_DMA_MASK;
8027 @@ -556,9 +679,14 @@ int fsl_mc_device_add(struct dprc_obj_desc *obj_desc,
8028 goto error_cleanup_dev;
8031 - /* Objects are coherent, unless 'no shareability' flag set. */
8032 - if (!(obj_desc->flags & DPRC_OBJ_FLAG_NO_MEM_SHAREABILITY))
8033 - arch_setup_dma_ops(&mc_dev->dev, 0, 0, NULL, true);
8034 + fsl_mc_platform_dev = &mc_dev->dev;
8035 + while (dev_is_fsl_mc(fsl_mc_platform_dev))
8036 + fsl_mc_platform_dev = fsl_mc_platform_dev->parent;
8037 + fsl_mc_platform_node = fsl_mc_platform_dev->of_node;
8039 + /* Set up the iommu configuration for the devices. */
8040 + fsl_mc_dma_configure(mc_dev, fsl_mc_platform_node,
8041 + !(obj_desc->flags & DPRC_OBJ_FLAG_NO_MEM_SHAREABILITY));
8044 * The device-specific probe callback will get invoked by device_add()
8045 @@ -571,9 +699,7 @@ int fsl_mc_device_add(struct dprc_obj_desc *obj_desc,
8046 goto error_cleanup_dev;
8049 - (void)get_device(&mc_dev->dev);
8050 - dev_dbg(parent_dev, "Added MC object device %s\n",
8051 - dev_name(&mc_dev->dev));
8052 + dev_dbg(parent_dev, "added %s\n", dev_name(&mc_dev->dev));
8054 *new_mc_dev = mc_dev;
8056 @@ -581,47 +707,34 @@ int fsl_mc_device_add(struct dprc_obj_desc *obj_desc,
8058 kfree(mc_dev->regions);
8060 - devm_kfree(parent_dev, mc_bus);
8063 - kmem_cache_free(mc_dev_cache, mc_dev);
8068 EXPORT_SYMBOL_GPL(fsl_mc_device_add);
8071 - * fsl_mc_device_remove - Remove a MC object device from being visible to
8072 + * fsl_mc_device_remove - Remove an fsl-mc device from being visible to
8075 - * @mc_dev: Pointer to a MC object device object
8076 + * @mc_dev: Pointer to an fsl-mc device
8078 void fsl_mc_device_remove(struct fsl_mc_device *mc_dev)
8080 - struct fsl_mc_bus *mc_bus = NULL;
8082 - kfree(mc_dev->regions);
8083 + kfree(mc_dev->driver_override);
8084 + mc_dev->driver_override = NULL;
8087 * The device-specific remove callback will get invoked by device_del()
8089 device_del(&mc_dev->dev);
8090 - put_device(&mc_dev->dev);
8092 - if (strcmp(mc_dev->obj_desc.type, "dprc") == 0) {
8093 - mc_bus = to_fsl_mc_bus(mc_dev);
8094 + if (strcmp(mc_dev->obj_desc.type, "dprc") != 0)
8095 + mc_dev->dev.iommu_fwspec = NULL;
8097 - if (fsl_mc_is_root_dprc(&mc_dev->dev)) {
8098 - if (atomic_read(&root_dprc_count) > 0)
8099 - atomic_dec(&root_dprc_count);
8106 - devm_kfree(mc_dev->dev.parent, mc_bus);
8108 - kmem_cache_free(mc_dev_cache, mc_dev);
8109 + put_device(&mc_dev->dev);
8111 EXPORT_SYMBOL_GPL(fsl_mc_device_remove);
8113 @@ -629,8 +742,7 @@ static int parse_mc_ranges(struct device *dev,
8117 - const __be32 **ranges_start,
8119 + const __be32 **ranges_start)
8122 int range_tuple_cell_count;
8123 @@ -643,8 +755,6 @@ static int parse_mc_ranges(struct device *dev,
8125 "missing or empty ranges property for device tree node '%s'\n",
8132 @@ -671,8 +781,7 @@ static int parse_mc_ranges(struct device *dev,
8136 - *num_ranges = ranges_len / tuple_len;
8138 + return ranges_len / tuple_len;
8141 static int get_mc_addr_translation_ranges(struct device *dev,
8142 @@ -680,7 +789,7 @@ static int get_mc_addr_translation_ranges(struct device *dev,
8151 @@ -688,16 +797,16 @@ static int get_mc_addr_translation_ranges(struct device *dev,
8152 const __be32 *ranges_start;
8155 - error = parse_mc_ranges(dev,
8156 + ret = parse_mc_ranges(dev,
8168 - if (!(*num_ranges)) {
8169 + *num_ranges = ret;
8172 * Missing or empty ranges property ("ranges;") for the
8173 * 'fsl,qoriq-mc' node. In this case, identity mapping
8174 @@ -749,8 +858,6 @@ static int fsl_mc_bus_probe(struct platform_device *pdev)
8175 struct mc_version mc_version;
8176 struct resource res;
8178 - dev_info(&pdev->dev, "Root MC bus device probed");
8180 mc = devm_kzalloc(&pdev->dev, sizeof(*mc), GFP_KERNEL);
8183 @@ -783,8 +890,7 @@ static int fsl_mc_bus_probe(struct platform_device *pdev)
8184 goto error_cleanup_mc_io;
8187 - dev_info(&pdev->dev,
8188 - "Freescale Management Complex Firmware version: %u.%u.%u\n",
8189 + dev_info(&pdev->dev, "MC firmware version: %u.%u.%u\n",
8190 mc_version.major, mc_version.minor, mc_version.revision);
8192 error = get_mc_addr_translation_ranges(&pdev->dev,
8193 @@ -793,16 +899,17 @@ static int fsl_mc_bus_probe(struct platform_device *pdev)
8195 goto error_cleanup_mc_io;
8197 - error = dpmng_get_container_id(mc_io, 0, &container_id);
8198 + error = dprc_get_container_id(mc_io, 0, &container_id);
8201 - "dpmng_get_container_id() failed: %d\n", error);
8202 + "dprc_get_container_id() failed: %d\n", error);
8203 goto error_cleanup_mc_io;
8206 memset(&obj_desc, 0, sizeof(struct dprc_obj_desc));
8207 - error = get_dprc_version(mc_io, container_id,
8208 - &obj_desc.ver_major, &obj_desc.ver_minor);
8209 + error = dprc_get_api_version(mc_io, 0,
8210 + &obj_desc.ver_major,
8211 + &obj_desc.ver_minor);
8213 goto error_cleanup_mc_io;
8215 @@ -812,7 +919,8 @@ static int fsl_mc_bus_probe(struct platform_device *pdev)
8216 obj_desc.irq_count = 1;
8217 obj_desc.region_count = 0;
8219 - error = fsl_mc_device_add(&obj_desc, mc_io, &pdev->dev, &mc_bus_dev);
8220 + error = fsl_mc_device_add(&obj_desc, mc_io, &pdev->dev, NULL,
8223 goto error_cleanup_mc_io;
8225 @@ -840,7 +948,6 @@ static int fsl_mc_bus_remove(struct platform_device *pdev)
8226 fsl_destroy_mc_io(mc->root_mc_bus_dev->mc_io);
8227 mc->root_mc_bus_dev->mc_io = NULL;
8229 - dev_info(&pdev->dev, "Root MC bus device removed");
8233 @@ -865,22 +972,12 @@ static int __init fsl_mc_bus_driver_init(void)
8237 - mc_dev_cache = kmem_cache_create("fsl_mc_device",
8238 - sizeof(struct fsl_mc_device), 0, 0,
8240 - if (!mc_dev_cache) {
8241 - pr_err("Could not create fsl_mc_device cache\n");
8245 error = bus_register(&fsl_mc_bus_type);
8247 - pr_err("fsl-mc bus type registration failed: %d\n", error);
8248 + pr_err("bus type registration failed: %d\n", error);
8249 goto error_cleanup_cache;
8252 - pr_info("fsl-mc bus type registered\n");
8254 error = platform_driver_register(&fsl_mc_bus_driver);
8256 pr_err("platform_driver_register() failed: %d\n", error);
8257 @@ -914,7 +1011,6 @@ static int __init fsl_mc_bus_driver_init(void)
8258 bus_unregister(&fsl_mc_bus_type);
8260 error_cleanup_cache:
8261 - kmem_cache_destroy(mc_dev_cache);
8264 postcore_initcall(fsl_mc_bus_driver_init);
8265 diff --git a/drivers/staging/fsl-mc/bus/fsl-mc-iommu.c b/drivers/staging/fsl-mc/bus/fsl-mc-iommu.c
8266 new file mode 100644
8267 index 00000000..86b2cd84
8269 +++ b/drivers/staging/fsl-mc/bus/fsl-mc-iommu.c
8272 + * Copyright 2016-17 NXP
8273 + * Author: Nipun Gupta <nipun.gupta@nxp.com>
8275 + * This file is licensed under the terms of the GNU General Public
8276 + * License version 2. This program is licensed "as is" without any
8277 + * warranty of any kind, whether express or implied.
8280 +#include <linux/iommu.h>
8281 +#include <linux/of.h>
8282 +#include <linux/of_iommu.h>
8283 +#include "../include/mc.h"
8285 +/* Setup the IOMMU for the DPRC container */
8286 +static const struct iommu_ops
8287 +*fsl_mc_iommu_configure(struct fsl_mc_device *mc_dev,
8288 + struct device_node *fsl_mc_platform_node)
8290 + struct of_phandle_args iommu_spec;
8291 + const struct iommu_ops *ops;
8292 + u32 iommu_phandle;
8293 + struct device_node *iommu_node;
8294 + const __be32 *map = NULL;
8295 + int iommu_cells, map_len, ret;
8297 + map = of_get_property(fsl_mc_platform_node, "iommu-map", &map_len);
8301 + ops = mc_dev->dev.bus->iommu_ops;
8302 + if (!ops || !ops->of_xlate)
8305 + iommu_phandle = be32_to_cpup(map + 1);
8306 + iommu_node = of_find_node_by_phandle(iommu_phandle);
8308 + if (of_property_read_u32(iommu_node, "#iommu-cells", &iommu_cells)) {
8309 + pr_err("%s: missing #iommu-cells property\n", iommu_node->name);
8313 + /* Initialize the fwspec */
8314 + ret = iommu_fwspec_init(&mc_dev->dev, &iommu_node->fwnode, ops);
8319 + * Fill in the required stream-id before calling the iommu's
8320 + * ops->xlate callback.
8322 + iommu_spec.np = iommu_node;
8323 + iommu_spec.args[0] = mc_dev->icid;
8324 + iommu_spec.args_count = 1;
8326 + ret = ops->of_xlate(&mc_dev->dev, &iommu_spec);
8330 + of_node_put(iommu_spec.np);
8335 +/* Set up DMA configuration for fsl-mc devices */
8336 +void fsl_mc_dma_configure(struct fsl_mc_device *mc_dev,
8337 + struct device_node *fsl_mc_platform_node, int coherent)
8339 + const struct iommu_ops *ops;
8341 + ops = fsl_mc_iommu_configure(mc_dev, fsl_mc_platform_node);
8343 + mc_dev->dev.coherent_dma_mask = DMA_BIT_MASK(48);
8344 + mc_dev->dev.dma_mask = &mc_dev->dev.coherent_dma_mask;
8345 + arch_setup_dma_ops(&mc_dev->dev, 0,
8346 + mc_dev->dev.coherent_dma_mask + 1, ops, coherent);
8349 +/* Macro to get the container device of a MC device */
8350 +#define fsl_mc_cont_dev(_dev) ((to_fsl_mc_device(_dev)->flags & \
8351 + FSL_MC_IS_DPRC) ? (_dev) : ((_dev)->parent))
8353 +/* Macro to check if a device is a container device */
8354 +#define is_cont_dev(_dev) (to_fsl_mc_device(_dev)->flags & FSL_MC_IS_DPRC)
8356 +/* Get the IOMMU group for device on fsl-mc bus */
8357 +struct iommu_group *fsl_mc_device_group(struct device *dev)
8359 + struct device *cont_dev = fsl_mc_cont_dev(dev);
8360 + struct iommu_group *group;
8362 + /* Container device is responsible for creating the iommu group */
8363 + if (is_cont_dev(dev)) {
8364 + group = iommu_group_alloc();
8365 + if (IS_ERR(group))
8368 + get_device(cont_dev);
8369 + group = iommu_group_get(cont_dev);
8370 + put_device(cont_dev);
8375 diff --git a/drivers/staging/fsl-mc/bus/fsl-mc-msi.c b/drivers/staging/fsl-mc/bus/fsl-mc-msi.c
8376 index 3d46b1b1..b8b2c86e 100644
8377 --- a/drivers/staging/fsl-mc/bus/fsl-mc-msi.c
8378 +++ b/drivers/staging/fsl-mc/bus/fsl-mc-msi.c
8381 * Freescale Management Complex (MC) bus driver MSI support
8383 - * Copyright (C) 2015 Freescale Semiconductor, Inc.
8384 + * Copyright (C) 2015-2016 Freescale Semiconductor, Inc.
8385 * Author: German Rivera <German.Rivera@freescale.com>
8387 * This file is licensed under the terms of the GNU General Public
8389 #include <linux/irqdomain.h>
8390 #include <linux/msi.h>
8391 #include "../include/mc-bus.h"
8392 +#include "fsl-mc-private.h"
8395 * Generate a unique ID identifying the interrupt (only used within the MSI
8396 diff --git a/drivers/staging/fsl-mc/bus/fsl-mc-private.h b/drivers/staging/fsl-mc/bus/fsl-mc-private.h
8397 index d459c267..e08b8843 100644
8398 --- a/drivers/staging/fsl-mc/bus/fsl-mc-private.h
8399 +++ b/drivers/staging/fsl-mc/bus/fsl-mc-private.h
8401 #ifndef _FSL_MC_PRIVATE_H_
8402 #define _FSL_MC_PRIVATE_H_
8404 +#include "../include/mc.h"
8405 +#include "../include/mc-bus.h"
8407 int __must_check fsl_mc_device_add(struct dprc_obj_desc *obj_desc,
8408 struct fsl_mc_io *mc_io,
8409 struct device *parent_dev,
8410 + const char *driver_override,
8411 struct fsl_mc_device **new_mc_dev);
8413 -void fsl_mc_device_remove(struct fsl_mc_device *mc_dev);
8415 int __init dprc_driver_init(void);
8417 void dprc_driver_exit(void);
8418 diff --git a/drivers/staging/fsl-mc/bus/irq-gic-v3-its-fsl-mc-msi.c b/drivers/staging/fsl-mc/bus/irq-gic-v3-its-fsl-mc-msi.c
8419 index 7a6ac640..49127acb 100644
8420 --- a/drivers/staging/fsl-mc/bus/irq-gic-v3-its-fsl-mc-msi.c
8421 +++ b/drivers/staging/fsl-mc/bus/irq-gic-v3-its-fsl-mc-msi.c
8424 * Freescale Management Complex (MC) bus driver MSI support
8426 - * Copyright (C) 2015 Freescale Semiconductor, Inc.
8427 + * Copyright (C) 2015-2016 Freescale Semiconductor, Inc.
8428 * Author: German Rivera <German.Rivera@freescale.com>
8430 * This file is licensed under the terms of the GNU General Public
8432 #include <linux/of.h>
8433 #include <linux/of_irq.h>
8434 #include "../include/mc-bus.h"
8435 +#include "fsl-mc-private.h"
8437 static struct irq_chip its_msi_irq_chip = {
8438 - .name = "fsl-mc-bus-msi",
8439 + .name = "ITS-fMSI",
8440 .irq_mask = irq_chip_mask_parent,
8441 .irq_unmask = irq_chip_unmask_parent,
8442 .irq_eoi = irq_chip_eoi_parent,
8443 @@ -51,7 +52,7 @@ static int its_fsl_mc_msi_prepare(struct irq_domain *msi_domain,
8444 return msi_info->ops->msi_prepare(msi_domain->parent, dev, nvec, info);
8447 -static struct msi_domain_ops its_fsl_mc_msi_ops = {
8448 +static struct msi_domain_ops its_fsl_mc_msi_ops __ro_after_init = {
8449 .msi_prepare = its_fsl_mc_msi_prepare,
8452 @@ -94,8 +95,8 @@ int __init its_fsl_mc_msi_init(void)
8456 - WARN_ON(mc_msi_domain->
8457 - host_data != &its_fsl_mc_msi_domain_info);
8458 + WARN_ON(mc_msi_domain->host_data !=
8459 + &its_fsl_mc_msi_domain_info);
8461 pr_info("fsl-mc MSI: %s domain created\n", np->full_name);
8463 diff --git a/drivers/staging/fsl-mc/bus/mc-io.c b/drivers/staging/fsl-mc/bus/mc-io.c
8464 index 798c965f..d66b87f0 100644
8465 --- a/drivers/staging/fsl-mc/bus/mc-io.c
8466 +++ b/drivers/staging/fsl-mc/bus/mc-io.c
8468 -/* Copyright 2013-2016 Freescale Semiconductor Inc.
8470 + * Copyright 2013-2016 Freescale Semiconductor Inc.
8472 * Redistribution and use in source and binary forms, with or without
8473 * modification, are permitted provided that the following conditions are met:
8475 * names of any contributors may be used to endorse or promote products
8476 * derived from this software without specific prior written permission.
8479 * ALTERNATIVELY, this software may be distributed under the terms of the
8480 * GNU General Public License ("GPL") as published by the Free Software
8481 * Foundation, either version 2 of that License or (at your option) any
8482 diff --git a/drivers/staging/fsl-mc/bus/mc-ioctl.h b/drivers/staging/fsl-mc/bus/mc-ioctl.h
8483 new file mode 100644
8484 index 00000000..8ac502a1
8486 +++ b/drivers/staging/fsl-mc/bus/mc-ioctl.h
8489 + * Freescale Management Complex (MC) ioclt interface
8491 + * Copyright (C) 2014 Freescale Semiconductor, Inc.
8492 + * Author: Lijun Pan <Lijun.Pan@freescale.com>
8494 + * This file is licensed under the terms of the GNU General Public
8495 + * License version 2. This program is licensed "as is" without any
8496 + * warranty of any kind, whether express or implied.
8498 +#ifndef _FSL_MC_IOCTL_H_
8499 +#define _FSL_MC_IOCTL_H_
8501 +#include <linux/ioctl.h>
8502 +#include "../include/mc-sys.h"
8504 +#define RESTOOL_IOCTL_TYPE 'R'
8506 +#define RESTOOL_SEND_MC_COMMAND \
8507 + _IOWR(RESTOOL_IOCTL_TYPE, 0xE0, struct mc_command)
8509 +#endif /* _FSL_MC_IOCTL_H_ */
8510 diff --git a/drivers/staging/fsl-mc/bus/mc-restool.c b/drivers/staging/fsl-mc/bus/mc-restool.c
8511 new file mode 100644
8512 index 00000000..d5330b68
8514 +++ b/drivers/staging/fsl-mc/bus/mc-restool.c
8517 + * Freescale Management Complex (MC) restool driver
8519 + * Copyright (C) 2014 Freescale Semiconductor, Inc.
8520 + * Author: Lijun Pan <Lijun.Pan@freescale.com>
8522 + * This file is licensed under the terms of the GNU General Public
8523 + * License version 2. This program is licensed "as is" without any
8524 + * warranty of any kind, whether express or implied.
8527 +#include "../include/mc.h"
8528 +#include <linux/module.h>
8529 +#include <linux/fs.h>
8530 +#include <linux/miscdevice.h>
8531 +#include <linux/mm.h>
8532 +#include <linux/slab.h>
8533 +#include <linux/uaccess.h>
8534 +#include <linux/mutex.h>
8535 +#include <linux/platform_device.h>
8536 +#include "mc-ioctl.h"
8537 +#include "../include/mc-sys.h"
8538 +#include "../include/mc-bus.h"
8539 +#include "../include/mc-cmd.h"
8540 +#include "../include/dpmng.h"
8543 + * Maximum number of DPRCs that can be opened at the same time
8545 +#define MAX_DPRC_HANDLES 64
8548 + * restool_misc - information associated with the newly added miscdevice
8549 + * @misc: newly created miscdevice associated with root dprc
8550 + * @miscdevt: device id of this miscdevice
8551 + * @list: a linked list node representing this miscdevcie
8552 + * @static_mc_io: pointer to the static MC I/O object used by the restool
8553 + * @dynamic_instance_count: number of dynamically created instances
8554 + * @static_instance_in_use: static instance is in use or not
8555 + * @mutex: mutex lock to serialze the open/release operations
8556 + * @dev: root dprc associated with this miscdevice
8558 +struct restool_misc {
8559 + struct miscdevice misc;
8561 + struct list_head list;
8562 + struct fsl_mc_io *static_mc_io;
8563 + u32 dynamic_instance_count;
8564 + bool static_instance_in_use;
8565 + struct mutex mutex; /* serialze the open/release operations */
8566 + struct device *dev;
8570 + * struct fsl_mc - Private data of a "fsl,qoriq-mc" platform device
8571 + * @root_mc_bus_dev: fsl-mc device representing the root DPRC
8572 + * @num_translation_ranges: number of entries in addr_translation_ranges
8573 + * @translation_ranges: array of bus to system address translation ranges
8576 + struct fsl_mc_device *root_mc_bus_dev;
8577 + u8 num_translation_ranges;
8578 + struct fsl_mc_addr_translation_range *translation_ranges;
8582 + * initialize a global list to link all
8583 + * the miscdevice nodes (struct restool_misc)
8585 +static LIST_HEAD(misc_list);
8586 +static DEFINE_MUTEX(misc_list_mutex);
8588 +static int fsl_mc_restool_dev_open(struct inode *inode, struct file *filep)
8590 + struct fsl_mc_device *root_mc_dev;
8592 + struct fsl_mc_io *dynamic_mc_io = NULL;
8593 + struct restool_misc *restool_misc = NULL;
8594 + struct restool_misc *restool_misc_cursor;
8596 + mutex_lock(&misc_list_mutex);
8598 + list_for_each_entry(restool_misc_cursor, &misc_list, list) {
8599 + if (restool_misc_cursor->miscdevt == inode->i_rdev) {
8600 + restool_misc = restool_misc_cursor;
8605 + mutex_unlock(&misc_list_mutex);
8607 + if (!restool_misc)
8610 + if (WARN_ON(!restool_misc->dev))
8613 + mutex_lock(&restool_misc->mutex);
8615 + if (!restool_misc->static_instance_in_use) {
8616 + restool_misc->static_instance_in_use = true;
8617 + filep->private_data = restool_misc->static_mc_io;
8619 + dynamic_mc_io = kzalloc(sizeof(*dynamic_mc_io), GFP_KERNEL);
8620 + if (!dynamic_mc_io) {
8625 + root_mc_dev = to_fsl_mc_device(restool_misc->dev);
8626 + error = fsl_mc_portal_allocate(root_mc_dev, 0, &dynamic_mc_io);
8628 + pr_err("Not able to allocate MC portal\n");
8629 + goto free_dynamic_mc_io;
8631 + ++restool_misc->dynamic_instance_count;
8632 + filep->private_data = dynamic_mc_io;
8635 + mutex_unlock(&restool_misc->mutex);
8639 +free_dynamic_mc_io:
8640 + kfree(dynamic_mc_io);
8642 + mutex_unlock(&restool_misc->mutex);
8647 +static int fsl_mc_restool_dev_release(struct inode *inode, struct file *filep)
8649 + struct fsl_mc_io *local_mc_io = filep->private_data;
8650 + struct restool_misc *restool_misc = NULL;
8651 + struct restool_misc *restool_misc_cursor;
8653 + if (WARN_ON(!filep->private_data))
8656 + mutex_lock(&misc_list_mutex);
8658 + list_for_each_entry(restool_misc_cursor, &misc_list, list) {
8659 + if (restool_misc_cursor->miscdevt == inode->i_rdev) {
8660 + restool_misc = restool_misc_cursor;
8665 + mutex_unlock(&misc_list_mutex);
8667 + if (!restool_misc)
8670 + mutex_lock(&restool_misc->mutex);
8672 + if (WARN_ON(restool_misc->dynamic_instance_count == 0 &&
8673 + !restool_misc->static_instance_in_use)) {
8674 + mutex_unlock(&restool_misc->mutex);
8678 + /* Globally clean up opened/untracked handles */
8679 + fsl_mc_portal_reset(local_mc_io);
8683 + * whether local_mc_io is dynamic or static instance
8684 + * Otherwise it will free up the reserved portal by accident
8685 + * or even not free up the dynamic allocated portal
8686 + * if 2 or more instances running concurrently
8688 + if (local_mc_io == restool_misc->static_mc_io) {
8689 + restool_misc->static_instance_in_use = false;
8691 + fsl_mc_portal_free(local_mc_io);
8692 + kfree(filep->private_data);
8693 + --restool_misc->dynamic_instance_count;
8696 + filep->private_data = NULL;
8697 + mutex_unlock(&restool_misc->mutex);
8702 +static int restool_send_mc_command(unsigned long arg,
8703 + struct fsl_mc_io *local_mc_io)
8706 + struct mc_command mc_cmd;
8708 + if (copy_from_user(&mc_cmd, (void __user *)arg, sizeof(mc_cmd)))
8712 + * Send MC command to the MC:
8714 + error = mc_send_command(local_mc_io, &mc_cmd);
8718 + if (copy_to_user((void __user *)arg, &mc_cmd, sizeof(mc_cmd)))
8725 +fsl_mc_restool_dev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
8730 + case RESTOOL_SEND_MC_COMMAND:
8731 + error = restool_send_mc_command(arg, file->private_data);
8734 + pr_err("%s: unexpected ioctl call number\n", __func__);
8741 +static const struct file_operations fsl_mc_restool_dev_fops = {
8742 + .owner = THIS_MODULE,
8743 + .open = fsl_mc_restool_dev_open,
8744 + .release = fsl_mc_restool_dev_release,
8745 + .unlocked_ioctl = fsl_mc_restool_dev_ioctl,
8748 +static int restool_add_device_file(struct device *dev)
8751 + char name2[20] = {0};
8753 + struct fsl_mc_device *root_mc_dev;
8754 + struct restool_misc *restool_misc;
8756 + if (dev->bus == &platform_bus_type && dev->driver_data) {
8757 + if (sscanf(dev_name(dev), "%x.%s", &name1, name2) != 2)
8760 + if (strcmp(name2, "fsl-mc") == 0)
8761 + pr_debug("platform's root dprc name is: %s\n",
8762 + dev_name(&(((struct fsl_mc *)
8763 + (dev->driver_data))->root_mc_bus_dev->dev)));
8766 + if (!fsl_mc_is_root_dprc(dev))
8769 + restool_misc = kzalloc(sizeof(*restool_misc), GFP_KERNEL);
8770 + if (!restool_misc)
8773 + restool_misc->dev = dev;
8774 + root_mc_dev = to_fsl_mc_device(dev);
8775 + error = fsl_mc_portal_allocate(root_mc_dev, 0,
8776 + &restool_misc->static_mc_io);
8778 + pr_err("Not able to allocate MC portal\n");
8779 + goto free_restool_misc;
8782 + restool_misc->misc.minor = MISC_DYNAMIC_MINOR;
8783 + restool_misc->misc.name = dev_name(dev);
8784 + restool_misc->misc.fops = &fsl_mc_restool_dev_fops;
8786 + error = misc_register(&restool_misc->misc);
8788 + pr_err("misc_register() failed: %d\n", error);
8792 + restool_misc->miscdevt = restool_misc->misc.this_device->devt;
8793 + mutex_init(&restool_misc->mutex);
8794 + mutex_lock(&misc_list_mutex);
8795 + list_add(&restool_misc->list, &misc_list);
8796 + mutex_unlock(&misc_list_mutex);
8798 + pr_info("/dev/%s driver registered\n", dev_name(dev));
8803 + fsl_mc_portal_free(restool_misc->static_mc_io);
8805 + kfree(restool_misc);
8810 +static int restool_bus_notifier(struct notifier_block *nb,
8811 + unsigned long action, void *data)
8814 + struct device *dev = data;
8817 + case BUS_NOTIFY_ADD_DEVICE:
8818 + error = restool_add_device_file(dev);
8822 + case BUS_NOTIFY_DEL_DEVICE:
8823 + case BUS_NOTIFY_REMOVED_DEVICE:
8824 + case BUS_NOTIFY_BIND_DRIVER:
8825 + case BUS_NOTIFY_BOUND_DRIVER:
8826 + case BUS_NOTIFY_UNBIND_DRIVER:
8827 + case BUS_NOTIFY_UNBOUND_DRIVER:
8830 + pr_err("%s: unrecognized device action from %s\n", __func__,
8838 +static int add_to_restool(struct device *dev, void *data)
8840 + return restool_add_device_file(dev);
8843 +static int __init fsl_mc_restool_driver_init(void)
8846 + struct notifier_block *nb;
8848 + nb = kzalloc(sizeof(*nb), GFP_KERNEL);
8852 + nb->notifier_call = restool_bus_notifier;
8853 + error = bus_register_notifier(&fsl_mc_bus_type, nb);
8858 + * This driver runs after fsl-mc bus driver runs.
8859 + * Hence, many of the root dprcs are already attached to fsl-mc bus
8860 + * In order to make sure we find all the root dprcs,
8861 + * we need to scan the fsl_mc_bus_type.
8863 + error = bus_for_each_dev(&fsl_mc_bus_type, NULL, NULL, add_to_restool);
8865 + bus_unregister_notifier(&fsl_mc_bus_type, nb);
8867 + pr_err("restool driver registration failure\n");
8878 +module_init(fsl_mc_restool_driver_init);
8880 +static void __exit fsl_mc_restool_driver_exit(void)
8882 + struct restool_misc *restool_misc;
8883 + struct restool_misc *restool_misc_tmp;
8884 + char name1[20] = {0};
8887 + list_for_each_entry_safe(restool_misc, restool_misc_tmp,
8888 + &misc_list, list) {
8889 + if (sscanf(restool_misc->misc.name, "%4s.%u", name1, &name2)
8893 + pr_debug("name1=%s,name2=%u\n", name1, name2);
8894 + pr_debug("misc-device: %s\n", restool_misc->misc.name);
8895 + if (strcmp(name1, "dprc") != 0)
8898 + if (WARN_ON(!restool_misc->static_mc_io))
8901 + if (WARN_ON(restool_misc->dynamic_instance_count != 0))
8904 + if (WARN_ON(restool_misc->static_instance_in_use))
8907 + misc_deregister(&restool_misc->misc);
8908 + pr_info("/dev/%s driver unregistered\n",
8909 + restool_misc->misc.name);
8910 + fsl_mc_portal_free(restool_misc->static_mc_io);
8911 + list_del(&restool_misc->list);
8912 + kfree(restool_misc);
8916 +module_exit(fsl_mc_restool_driver_exit);
8918 +MODULE_AUTHOR("Freescale Semiconductor Inc.");
8919 +MODULE_DESCRIPTION("Freescale's MC restool driver");
8920 +MODULE_LICENSE("GPL");
8921 diff --git a/drivers/staging/fsl-mc/bus/mc-sys.c b/drivers/staging/fsl-mc/bus/mc-sys.c
8922 index 285917c7..cf63c7b6 100644
8923 --- a/drivers/staging/fsl-mc/bus/mc-sys.c
8924 +++ b/drivers/staging/fsl-mc/bus/mc-sys.c
8926 -/* Copyright 2013-2014 Freescale Semiconductor Inc.
8928 + * Copyright 2013-2016 Freescale Semiconductor Inc.
8930 * I/O services to send MC commands to the MC hardware
8933 * names of any contributors may be used to endorse or promote products
8934 * derived from this software without specific prior written permission.
8937 * ALTERNATIVELY, this software may be distributed under the terms of the
8938 * GNU General Public License ("GPL") as published by the Free Software
8939 * Foundation, either version 2 of that License or (at your option) any
8942 * Timeout in milliseconds to wait for the completion of an MC command
8944 -#define MC_CMD_COMPLETION_TIMEOUT_MS 500
8945 +#define MC_CMD_COMPLETION_TIMEOUT_MS 15000
8948 * usleep_range() min and max values used to throttle down polling
8949 @@ -67,7 +67,7 @@ static u16 mc_cmd_hdr_read_cmdid(struct mc_command *cmd)
8950 struct mc_cmd_header *hdr = (struct mc_cmd_header *)&cmd->header;
8951 u16 cmd_id = le16_to_cpu(hdr->cmd_id);
8953 - return (cmd_id & MC_CMD_HDR_CMDID_MASK) >> MC_CMD_HDR_CMDID_SHIFT;
8957 static int mc_status_to_error(enum mc_cmd_status status)
8958 @@ -200,7 +200,7 @@ static int mc_polling_wait_preemptible(struct fsl_mc_io *mc_io,
8960 if (time_after_eq(jiffies, jiffies_until_timeout)) {
8962 - "MC command timed out (portal: %#llx, obj handle: %#x, command: %#x)\n",
8963 + "MC command timed out (portal: %#llx, dprc handle: %#x, command: %#x)\n",
8964 mc_io->portal_phys_addr,
8965 (unsigned int)mc_cmd_hdr_read_token(cmd),
8966 (unsigned int)mc_cmd_hdr_read_cmdid(cmd));
8967 @@ -240,7 +240,7 @@ static int mc_polling_wait_atomic(struct fsl_mc_io *mc_io,
8968 timeout_usecs -= MC_CMD_COMPLETION_POLLING_MAX_SLEEP_USECS;
8969 if (timeout_usecs == 0) {
8971 - "MC command timed out (portal: %#llx, obj handle: %#x, command: %#x)\n",
8972 + "MC command timed out (portal: %#llx, dprc handle: %#x, command: %#x)\n",
8973 mc_io->portal_phys_addr,
8974 (unsigned int)mc_cmd_hdr_read_token(cmd),
8975 (unsigned int)mc_cmd_hdr_read_cmdid(cmd));
8976 @@ -294,7 +294,7 @@ int mc_send_command(struct fsl_mc_io *mc_io, struct mc_command *cmd)
8978 if (status != MC_CMD_STATUS_OK) {
8980 - "MC command failed: portal: %#llx, obj handle: %#x, command: %#x, status: %s (%#x)\n",
8981 + "MC command failed: portal: %#llx, dprc handle: %#x, command: %#x, status: %s (%#x)\n",
8982 mc_io->portal_phys_addr,
8983 (unsigned int)mc_cmd_hdr_read_token(cmd),
8984 (unsigned int)mc_cmd_hdr_read_cmdid(cmd),
8985 diff --git a/drivers/staging/fsl-mc/include/dpaa2-fd.h b/drivers/staging/fsl-mc/include/dpaa2-fd.h
8986 new file mode 100644
8987 index 00000000..72328415
8989 +++ b/drivers/staging/fsl-mc/include/dpaa2-fd.h
8992 + * Copyright 2014-2016 Freescale Semiconductor Inc.
8993 + * Copyright 2016 NXP
8995 + * Redistribution and use in source and binary forms, with or without
8996 + * modification, are permitted provided that the following conditions are met:
8997 + * * Redistributions of source code must retain the above copyright
8998 + * notice, this list of conditions and the following disclaimer.
8999 + * * Redistributions in binary form must reproduce the above copyright
9000 + * notice, this list of conditions and the following disclaimer in the
9001 + * documentation and/or other materials provided with the distribution.
9002 + * * Neither the name of Freescale Semiconductor nor the
9003 + * names of its contributors may be used to endorse or promote products
9004 + * derived from this software without specific prior written permission.
9006 + * ALTERNATIVELY, this software may be distributed under the terms of the
9007 + * GNU General Public License ("GPL") as published by the Free Software
9008 + * Foundation, either version 2 of that License or (at your option) any
9011 + * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
9012 + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
9013 + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
9014 + * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
9015 + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
9016 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
9017 + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
9018 + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
9019 + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
9020 + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
9022 +#ifndef __FSL_DPAA2_FD_H
9023 +#define __FSL_DPAA2_FD_H
9025 +#include <linux/kernel.h>
9028 + * DOC: DPAA2 FD - Frame Descriptor APIs for DPAA2
9030 + * Frame Descriptors (FDs) are used to describe frame data in the DPAA2.
9031 + * Frames can be enqueued and dequeued to Frame Queues (FQs) which are consumed
9032 + * by the various DPAA accelerators (WRIOP, SEC, PME, DCE)
9034 + * There are three types of frames: single, scatter gather, and frame lists.
9036 + * The set of APIs in this file must be used to create, manipulate and
9037 + * query Frame Descriptors.
9041 + * struct dpaa2_fd - Struct describing FDs
9042 + * @words: for easier/faster copying the whole FD structure
9043 + * @addr: address in the FD
9044 + * @len: length in the FD
9045 + * @bpid: buffer pool ID
9046 + * @format_offset: format, offset, and short-length fields
9047 + * @frc: frame context
9048 + * @ctrl: control bits...including dd, sc, va, err, etc
9049 + * @flc: flow context address
9051 + * This structure represents the basic Frame Descriptor used in the system.
9056 + struct dpaa2_fd_simple {
9060 + __le16 format_offset;
9068 +#define FD_SHORT_LEN_FLAG_MASK 0x1
9069 +#define FD_SHORT_LEN_FLAG_SHIFT 14
9070 +#define FD_SHORT_LEN_MASK 0x3FFFF
9071 +#define FD_OFFSET_MASK 0x0FFF
9072 +#define FD_FORMAT_MASK 0x3
9073 +#define FD_FORMAT_SHIFT 12
9074 +#define FD_BPID_MASK 0x3FFF
9075 +#define SG_SHORT_LEN_FLAG_MASK 0x1
9076 +#define SG_SHORT_LEN_FLAG_SHIFT 14
9077 +#define SG_SHORT_LEN_MASK 0x1FFFF
9078 +#define SG_OFFSET_MASK 0x0FFF
9079 +#define SG_FORMAT_MASK 0x3
9080 +#define SG_FORMAT_SHIFT 12
9081 +#define SG_BPID_MASK 0x3FFF
9082 +#define SG_FINAL_FLAG_MASK 0x1
9083 +#define SG_FINAL_FLAG_SHIFT 15
9084 +#define FL_SHORT_LEN_FLAG_MASK 0x1
9085 +#define FL_SHORT_LEN_FLAG_SHIFT 14
9086 +#define FL_SHORT_LEN_MASK 0x3FFFF
9087 +#define FL_OFFSET_MASK 0x0FFF
9088 +#define FL_FORMAT_MASK 0x3
9089 +#define FL_FORMAT_SHIFT 12
9090 +#define FL_BPID_MASK 0x3FFF
9091 +#define FL_FINAL_FLAG_MASK 0x1
9092 +#define FL_FINAL_FLAG_SHIFT 15
9094 +/* Error bits in FD CTRL */
9095 +#define FD_CTRL_ERR_MASK 0x000000FF
9096 +#define FD_CTRL_UFD 0x00000004
9097 +#define FD_CTRL_SBE 0x00000008
9098 +#define FD_CTRL_FLC 0x00000010
9099 +#define FD_CTRL_FSE 0x00000020
9100 +#define FD_CTRL_FAERR 0x00000040
9102 +/* Annotation bits in FD CTRL */
9103 +#define FD_CTRL_PTA 0x00800000
9104 +#define FD_CTRL_PTV1 0x00400000
9106 +enum dpaa2_fd_format {
9107 + dpaa2_fd_single = 0,
9113 + * dpaa2_fd_get_addr() - get the addr field of frame descriptor
9114 + * @fd: the given frame descriptor
9116 + * Return the address in the frame descriptor.
9118 +static inline dma_addr_t dpaa2_fd_get_addr(const struct dpaa2_fd *fd)
9120 + return (dma_addr_t)le64_to_cpu(fd->simple.addr);
9124 + * dpaa2_fd_set_addr() - Set the addr field of frame descriptor
9125 + * @fd: the given frame descriptor
9126 + * @addr: the address needs to be set in frame descriptor
9128 +static inline void dpaa2_fd_set_addr(struct dpaa2_fd *fd, dma_addr_t addr)
9130 + fd->simple.addr = cpu_to_le64(addr);
9134 + * dpaa2_fd_get_frc() - Get the frame context in the frame descriptor
9135 + * @fd: the given frame descriptor
9137 + * Return the frame context field in the frame descriptor.
9139 +static inline u32 dpaa2_fd_get_frc(const struct dpaa2_fd *fd)
9141 + return le32_to_cpu(fd->simple.frc);
9145 + * dpaa2_fd_set_frc() - Set the frame context in the frame descriptor
9146 + * @fd: the given frame descriptor
9147 + * @frc: the frame context needs to be set in frame descriptor
9149 +static inline void dpaa2_fd_set_frc(struct dpaa2_fd *fd, u32 frc)
9151 + fd->simple.frc = cpu_to_le32(frc);
9155 + * dpaa2_fd_get_ctrl() - Get the control bits in the frame descriptor
9156 + * @fd: the given frame descriptor
9158 + * Return the control bits field in the frame descriptor.
9160 +static inline u32 dpaa2_fd_get_ctrl(const struct dpaa2_fd *fd)
9162 + return le32_to_cpu(fd->simple.ctrl);
9166 + * dpaa2_fd_set_ctrl() - Set the control bits in the frame descriptor
9167 + * @fd: the given frame descriptor
9168 + * @ctrl: the control bits to be set in the frame descriptor
9170 +static inline void dpaa2_fd_set_ctrl(struct dpaa2_fd *fd, u32 ctrl)
9172 + fd->simple.ctrl = cpu_to_le32(ctrl);
9176 + * dpaa2_fd_get_flc() - Get the flow context in the frame descriptor
9177 + * @fd: the given frame descriptor
9179 + * Return the flow context in the frame descriptor.
9181 +static inline dma_addr_t dpaa2_fd_get_flc(const struct dpaa2_fd *fd)
9183 + return (dma_addr_t)le64_to_cpu(fd->simple.flc);
9187 + * dpaa2_fd_set_flc() - Set the flow context field of frame descriptor
9188 + * @fd: the given frame descriptor
9189 + * @flc_addr: the flow context needs to be set in frame descriptor
9191 +static inline void dpaa2_fd_set_flc(struct dpaa2_fd *fd, dma_addr_t flc_addr)
9193 + fd->simple.flc = cpu_to_le64(flc_addr);
9196 +static inline bool dpaa2_fd_short_len(const struct dpaa2_fd *fd)
9198 + return !!((le16_to_cpu(fd->simple.format_offset) >>
9199 + FD_SHORT_LEN_FLAG_SHIFT) & FD_SHORT_LEN_FLAG_MASK);
9203 + * dpaa2_fd_get_len() - Get the length in the frame descriptor
9204 + * @fd: the given frame descriptor
9206 + * Return the length field in the frame descriptor.
9208 +static inline u32 dpaa2_fd_get_len(const struct dpaa2_fd *fd)
9210 + if (dpaa2_fd_short_len(fd))
9211 + return le32_to_cpu(fd->simple.len) & FD_SHORT_LEN_MASK;
9213 + return le32_to_cpu(fd->simple.len);
9217 + * dpaa2_fd_set_len() - Set the length field of frame descriptor
9218 + * @fd: the given frame descriptor
9219 + * @len: the length needs to be set in frame descriptor
9221 +static inline void dpaa2_fd_set_len(struct dpaa2_fd *fd, u32 len)
9223 + fd->simple.len = cpu_to_le32(len);
9227 + * dpaa2_fd_get_offset() - Get the offset field in the frame descriptor
9228 + * @fd: the given frame descriptor
9230 + * Return the offset.
9232 +static inline uint16_t dpaa2_fd_get_offset(const struct dpaa2_fd *fd)
9234 + return le16_to_cpu(fd->simple.format_offset) & FD_OFFSET_MASK;
9238 + * dpaa2_fd_set_offset() - Set the offset field of frame descriptor
9239 + * @fd: the given frame descriptor
9240 + * @offset: the offset needs to be set in frame descriptor
9242 +static inline void dpaa2_fd_set_offset(struct dpaa2_fd *fd, uint16_t offset)
9244 + fd->simple.format_offset &= cpu_to_le16(~FD_OFFSET_MASK);
9245 + fd->simple.format_offset |= cpu_to_le16(offset);
9249 + * dpaa2_fd_get_format() - Get the format field in the frame descriptor
9250 + * @fd: the given frame descriptor
9252 + * Return the format.
9254 +static inline enum dpaa2_fd_format dpaa2_fd_get_format(
9255 + const struct dpaa2_fd *fd)
9257 + return (enum dpaa2_fd_format)((le16_to_cpu(fd->simple.format_offset)
9258 + >> FD_FORMAT_SHIFT) & FD_FORMAT_MASK);
9262 + * dpaa2_fd_set_format() - Set the format field of frame descriptor
9263 + * @fd: the given frame descriptor
9264 + * @format: the format needs to be set in frame descriptor
9266 +static inline void dpaa2_fd_set_format(struct dpaa2_fd *fd,
9267 + enum dpaa2_fd_format format)
9269 + fd->simple.format_offset &=
9270 + cpu_to_le16(~(FD_FORMAT_MASK << FD_FORMAT_SHIFT));
9271 + fd->simple.format_offset |= cpu_to_le16(format << FD_FORMAT_SHIFT);
9275 + * dpaa2_fd_get_bpid() - Get the bpid field in the frame descriptor
9276 + * @fd: the given frame descriptor
9278 + * Return the buffer pool id.
9280 +static inline uint16_t dpaa2_fd_get_bpid(const struct dpaa2_fd *fd)
9282 + return le16_to_cpu(fd->simple.bpid) & FD_BPID_MASK;
9286 + * dpaa2_fd_set_bpid() - Set the bpid field of frame descriptor
9287 + * @fd: the given frame descriptor
9288 + * @bpid: buffer pool id to be set
9290 +static inline void dpaa2_fd_set_bpid(struct dpaa2_fd *fd, uint16_t bpid)
9292 + fd->simple.bpid &= cpu_to_le16(~(FD_BPID_MASK));
9293 + fd->simple.bpid |= cpu_to_le16(bpid);
9297 + * struct dpaa2_sg_entry - the scatter-gathering structure
9298 + * @addr: address of the sg entry
9299 + * @len: length in this sg entry
9300 + * @bpid: buffer pool id
9301 + * @format_offset: format and offset fields
9303 +struct dpaa2_sg_entry {
9307 + __le16 format_offset;
9310 +enum dpaa2_sg_format {
9311 + dpaa2_sg_single = 0,
9312 + dpaa2_sg_frame_data,
9316 +/* Accessors for SG entry fields */
9319 + * dpaa2_sg_get_addr() - Get the address from SG entry
9320 + * @sg: the given scatter-gathering object
9322 + * Return the address.
9324 +static inline dma_addr_t dpaa2_sg_get_addr(const struct dpaa2_sg_entry *sg)
9326 + return le64_to_cpu((dma_addr_t)sg->addr);
9330 + * dpaa2_sg_set_addr() - Set the address in SG entry
9331 + * @sg: the given scatter-gathering object
9332 + * @addr: the address to be set
9334 +static inline void dpaa2_sg_set_addr(struct dpaa2_sg_entry *sg, dma_addr_t addr)
9336 + sg->addr = cpu_to_le64(addr);
9339 +static inline bool dpaa2_sg_short_len(const struct dpaa2_sg_entry *sg)
9341 + return !!((le16_to_cpu(sg->format_offset) >> SG_SHORT_LEN_FLAG_SHIFT)
9342 + & SG_SHORT_LEN_FLAG_MASK);
9346 + * dpaa2_sg_get_len() - Get the length in SG entry
9347 + * @sg: the given scatter-gathering object
9349 + * Return the length.
9351 +static inline u32 dpaa2_sg_get_len(const struct dpaa2_sg_entry *sg)
9353 + if (dpaa2_sg_short_len(sg))
9354 + return le32_to_cpu(sg->len) & SG_SHORT_LEN_MASK;
9356 + return le32_to_cpu(sg->len);
9360 + * dpaa2_sg_set_len() - Set the length in SG entry
9361 + * @sg: the given scatter-gathering object
9362 + * @len: the length to be set
9364 +static inline void dpaa2_sg_set_len(struct dpaa2_sg_entry *sg, u32 len)
9366 + sg->len = cpu_to_le32(len);
9370 + * dpaa2_sg_get_offset() - Get the offset in SG entry
9371 + * @sg: the given scatter-gathering object
9373 + * Return the offset.
9375 +static inline u16 dpaa2_sg_get_offset(const struct dpaa2_sg_entry *sg)
9377 + return le16_to_cpu(sg->format_offset) & SG_OFFSET_MASK;
9381 + * dpaa2_sg_set_offset() - Set the offset in SG entry
9382 + * @sg: the given scatter-gathering object
9383 + * @offset: the offset to be set
9385 +static inline void dpaa2_sg_set_offset(struct dpaa2_sg_entry *sg,
9388 + sg->format_offset &= cpu_to_le16(~SG_OFFSET_MASK);
9389 + sg->format_offset |= cpu_to_le16(offset);
9393 + * dpaa2_sg_get_format() - Get the SG format in SG entry
9394 + * @sg: the given scatter-gathering object
9396 + * Return the format.
9398 +static inline enum dpaa2_sg_format
9399 + dpaa2_sg_get_format(const struct dpaa2_sg_entry *sg)
9401 + return (enum dpaa2_sg_format)((le16_to_cpu(sg->format_offset)
9402 + >> SG_FORMAT_SHIFT) & SG_FORMAT_MASK);
9406 + * dpaa2_sg_set_format() - Set the SG format in SG entry
9407 + * @sg: the given scatter-gathering object
9408 + * @format: the format to be set
9410 +static inline void dpaa2_sg_set_format(struct dpaa2_sg_entry *sg,
9411 + enum dpaa2_sg_format format)
9413 + sg->format_offset &= cpu_to_le16(~(SG_FORMAT_MASK << SG_FORMAT_SHIFT));
9414 + sg->format_offset |= cpu_to_le16(format << SG_FORMAT_SHIFT);
9418 + * dpaa2_sg_get_bpid() - Get the buffer pool id in SG entry
9419 + * @sg: the given scatter-gathering object
9421 + * Return the bpid.
9423 +static inline u16 dpaa2_sg_get_bpid(const struct dpaa2_sg_entry *sg)
9425 + return le16_to_cpu(sg->bpid) & SG_BPID_MASK;
9429 + * dpaa2_sg_set_bpid() - Set the buffer pool id in SG entry
9430 + * @sg: the given scatter-gathering object
9431 + * @bpid: the bpid to be set
9433 +static inline void dpaa2_sg_set_bpid(struct dpaa2_sg_entry *sg, u16 bpid)
9435 + sg->bpid &= cpu_to_le16(~(SG_BPID_MASK));
9436 + sg->bpid |= cpu_to_le16(bpid);
9440 + * dpaa2_sg_is_final() - Check final bit in SG entry
9441 + * @sg: the given scatter-gathering object
9445 +static inline bool dpaa2_sg_is_final(const struct dpaa2_sg_entry *sg)
9447 + return !!(le16_to_cpu(sg->format_offset) >> SG_FINAL_FLAG_SHIFT);
9451 + * dpaa2_sg_set_final() - Set the final bit in SG entry
9452 + * @sg: the given scatter-gathering object
9453 + * @final: the final boolean to be set
9455 +static inline void dpaa2_sg_set_final(struct dpaa2_sg_entry *sg, bool final)
9457 + sg->format_offset &= cpu_to_le16(~(SG_FINAL_FLAG_MASK
9458 + << SG_FINAL_FLAG_SHIFT));
9459 + sg->format_offset |= cpu_to_le16(final << SG_FINAL_FLAG_SHIFT);
9463 + * struct dpaa2_fl_entry - structure for frame list entry.
9464 + * @addr: address in the FLE
9465 + * @len: length in the FLE
9466 + * @bpid: buffer pool ID
9467 + * @format_offset: format, offset, and short-length fields
9468 + * @frc: frame context
9469 + * @ctrl: control bits...including pta, pvt1, pvt2, err, etc
9470 + * @flc: flow context address
9472 +struct dpaa2_fl_entry {
9476 + __le16 format_offset;
9482 +enum dpaa2_fl_format {
9483 + dpaa2_fl_single = 0,
9489 + * dpaa2_fl_get_addr() - get the addr field of FLE
9490 + * @fle: the given frame list entry
9492 + * Return the address in the frame list entry.
9494 +static inline dma_addr_t dpaa2_fl_get_addr(const struct dpaa2_fl_entry *fle)
9496 + return (dma_addr_t)le64_to_cpu(fle->addr);
9500 + * dpaa2_fl_set_addr() - Set the addr field of FLE
9501 + * @fle: the given frame list entry
9502 + * @addr: the address needs to be set in frame list entry
9504 +static inline void dpaa2_fl_set_addr(struct dpaa2_fl_entry *fle,
9507 + fle->addr = cpu_to_le64(addr);
9511 + * dpaa2_fl_get_frc() - Get the frame context in the FLE
9512 + * @fle: the given frame list entry
9514 + * Return the frame context field in the frame lsit entry.
9516 +static inline u32 dpaa2_fl_get_frc(const struct dpaa2_fl_entry *fle)
9518 + return le32_to_cpu(fle->frc);
9522 + * dpaa2_fl_set_frc() - Set the frame context in the FLE
9523 + * @fle: the given frame list entry
9524 + * @frc: the frame context needs to be set in frame list entry
9526 +static inline void dpaa2_fl_set_frc(struct dpaa2_fl_entry *fle, u32 frc)
9528 + fle->frc = cpu_to_le32(frc);
9532 + * dpaa2_fl_get_ctrl() - Get the control bits in the FLE
9533 + * @fle: the given frame list entry
9535 + * Return the control bits field in the frame list entry.
9537 +static inline u32 dpaa2_fl_get_ctrl(const struct dpaa2_fl_entry *fle)
9539 + return le32_to_cpu(fle->ctrl);
9543 + * dpaa2_fl_set_ctrl() - Set the control bits in the FLE
9544 + * @fle: the given frame list entry
9545 + * @ctrl: the control bits to be set in the frame list entry
9547 +static inline void dpaa2_fl_set_ctrl(struct dpaa2_fl_entry *fle, u32 ctrl)
9549 + fle->ctrl = cpu_to_le32(ctrl);
9553 + * dpaa2_fl_get_flc() - Get the flow context in the FLE
9554 + * @fle: the given frame list entry
9556 + * Return the flow context in the frame list entry.
9558 +static inline dma_addr_t dpaa2_fl_get_flc(const struct dpaa2_fl_entry *fle)
9560 + return (dma_addr_t)le64_to_cpu(fle->flc);
9564 + * dpaa2_fl_set_flc() - Set the flow context field of FLE
9565 + * @fle: the given frame list entry
9566 + * @flc_addr: the flow context needs to be set in frame list entry
9568 +static inline void dpaa2_fl_set_flc(struct dpaa2_fl_entry *fle,
9569 + dma_addr_t flc_addr)
9571 + fle->flc = cpu_to_le64(flc_addr);
9574 +static inline bool dpaa2_fl_short_len(const struct dpaa2_fl_entry *fle)
9576 + return !!((le16_to_cpu(fle->format_offset) >>
9577 + FL_SHORT_LEN_FLAG_SHIFT) & FL_SHORT_LEN_FLAG_MASK);
9581 + * dpaa2_fl_get_len() - Get the length in the FLE
9582 + * @fle: the given frame list entry
9584 + * Return the length field in the frame list entry.
9586 +static inline u32 dpaa2_fl_get_len(const struct dpaa2_fl_entry *fle)
9588 + if (dpaa2_fl_short_len(fle))
9589 + return le32_to_cpu(fle->len) & FL_SHORT_LEN_MASK;
9591 + return le32_to_cpu(fle->len);
9595 + * dpaa2_fl_set_len() - Set the length field of FLE
9596 + * @fle: the given frame list entry
9597 + * @len: the length needs to be set in frame list entry
9599 +static inline void dpaa2_fl_set_len(struct dpaa2_fl_entry *fle, u32 len)
9601 + fle->len = cpu_to_le32(len);
9605 + * dpaa2_fl_get_offset() - Get the offset field in the frame list entry
9606 + * @fle: the given frame list entry
9608 + * Return the offset.
9610 +static inline u16 dpaa2_fl_get_offset(const struct dpaa2_fl_entry *fle)
9612 + return le16_to_cpu(fle->format_offset) & FL_OFFSET_MASK;
9616 + * dpaa2_fl_set_offset() - Set the offset field of FLE
9617 + * @fle: the given frame list entry
9618 + * @offset: the offset needs to be set in frame list entry
9620 +static inline void dpaa2_fl_set_offset(struct dpaa2_fl_entry *fle, u16 offset)
9622 + fle->format_offset &= cpu_to_le16(~FL_OFFSET_MASK);
9623 + fle->format_offset |= cpu_to_le16(offset);
9627 + * dpaa2_fl_get_format() - Get the format field in the FLE
9628 + * @fle: the given frame list entry
9630 + * Return the format.
9632 +static inline enum dpaa2_fl_format dpaa2_fl_get_format(
9633 + const struct dpaa2_fl_entry *fle)
9635 + return (enum dpaa2_fl_format)((le16_to_cpu(fle->format_offset) >>
9636 + FL_FORMAT_SHIFT) & FL_FORMAT_MASK);
9640 + * dpaa2_fl_set_format() - Set the format field of FLE
9641 + * @fle: the given frame list entry
9642 + * @format: the format needs to be set in frame list entry
9644 +static inline void dpaa2_fl_set_format(struct dpaa2_fl_entry *fle,
9645 + enum dpaa2_fl_format format)
9647 + fle->format_offset &= cpu_to_le16(~(FL_FORMAT_MASK << FL_FORMAT_SHIFT));
9648 + fle->format_offset |= cpu_to_le16(format << FL_FORMAT_SHIFT);
9652 + * dpaa2_fl_get_bpid() - Get the bpid field in the FLE
9653 + * @fle: the given frame list entry
9655 + * Return the buffer pool id.
9657 +static inline u16 dpaa2_fl_get_bpid(const struct dpaa2_fl_entry *fle)
9659 + return le16_to_cpu(fle->bpid) & FL_BPID_MASK;
9663 + * dpaa2_fl_set_bpid() - Set the bpid field of FLE
9664 + * @fle: the given frame list entry
9665 + * @bpid: buffer pool id to be set
9667 +static inline void dpaa2_fl_set_bpid(struct dpaa2_fl_entry *fle, u16 bpid)
9669 + fle->bpid &= cpu_to_le16(~(FL_BPID_MASK));
9670 + fle->bpid |= cpu_to_le16(bpid);
9674 + * dpaa2_fl_is_final() - Check final bit in FLE
9675 + * @fle: the given frame list entry
9679 +static inline bool dpaa2_fl_is_final(const struct dpaa2_fl_entry *fle)
9681 + return !!(le16_to_cpu(fle->format_offset) >> FL_FINAL_FLAG_SHIFT);
9685 + * dpaa2_fl_set_final() - Set the final bit in FLE
9686 + * @fle: the given frame list entry
9687 + * @final: the final boolean to be set
9689 +static inline void dpaa2_fl_set_final(struct dpaa2_fl_entry *fle, bool final)
9691 + fle->format_offset &= cpu_to_le16(~(FL_FINAL_FLAG_MASK <<
9692 + FL_FINAL_FLAG_SHIFT));
9693 + fle->format_offset |= cpu_to_le16(final << FL_FINAL_FLAG_SHIFT);
9696 +#endif /* __FSL_DPAA2_FD_H */
9697 diff --git a/drivers/staging/fsl-mc/include/dpaa2-global.h b/drivers/staging/fsl-mc/include/dpaa2-global.h
9698 new file mode 100644
9699 index 00000000..0326447f
9701 +++ b/drivers/staging/fsl-mc/include/dpaa2-global.h
9704 + * Copyright 2014-2016 Freescale Semiconductor Inc.
9705 + * Copyright 2016 NXP
9707 + * Redistribution and use in source and binary forms, with or without
9708 + * modification, are permitted provided that the following conditions are met:
9709 + * * Redistributions of source code must retain the above copyright
9710 + * notice, this list of conditions and the following disclaimer.
9711 + * * Redistributions in binary form must reproduce the above copyright
9712 + * notice, this list of conditions and the following disclaimer in the
9713 + * documentation and/or other materials provided with the distribution.
9714 + * * Neither the name of Freescale Semiconductor nor the
9715 + * names of its contributors may be used to endorse or promote products
9716 + * derived from this software without specific prior written permission.
9718 + * ALTERNATIVELY, this software may be distributed under the terms of the
9719 + * GNU General Public License ("GPL") as published by the Free Software
9720 + * Foundation, either version 2 of that License or (at your option) any
9723 + * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
9724 + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
9725 + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
9726 + * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
9727 + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
9728 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
9729 + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
9730 + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
9731 + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
9732 + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
9734 +#ifndef __FSL_DPAA2_GLOBAL_H
9735 +#define __FSL_DPAA2_GLOBAL_H
9737 +#include <linux/types.h>
9738 +#include <linux/cpumask.h>
9739 +#include "dpaa2-fd.h"
9756 + __le32 fq_byte_cnt;
9757 + __le32 fq_frm_cnt;
9772 +/* Parsing frame dequeue results */
9774 +#define DPAA2_DQ_STAT_FQEMPTY 0x80
9775 +/* FQ held active */
9776 +#define DPAA2_DQ_STAT_HELDACTIVE 0x40
9777 +/* FQ force eligible */
9778 +#define DPAA2_DQ_STAT_FORCEELIGIBLE 0x20
9780 +#define DPAA2_DQ_STAT_VALIDFRAME 0x10
9781 +/* FQ ODP enable */
9782 +#define DPAA2_DQ_STAT_ODPVALID 0x04
9783 +/* volatile dequeue */
9784 +#define DPAA2_DQ_STAT_VOLATILE 0x02
9785 +/* volatile dequeue command is expired */
9786 +#define DPAA2_DQ_STAT_EXPIRED 0x01
9788 +#define DQ_FQID_MASK 0x00FFFFFF
9789 +#define DQ_FRAME_COUNT_MASK 0x00FFFFFF
9792 + * dpaa2_dq_flags() - Get the stat field of dequeue response
9793 + * @dq: the dequeue result.
9795 +static inline u32 dpaa2_dq_flags(const struct dpaa2_dq *dq)
9797 + return dq->dq.stat;
9801 + * dpaa2_dq_is_pull() - Check whether the dq response is from a pull
9803 + * @dq: the dequeue result
9805 + * Return 1 for volatile(pull) dequeue, 0 for static dequeue.
9807 +static inline int dpaa2_dq_is_pull(const struct dpaa2_dq *dq)
9809 + return (int)(dpaa2_dq_flags(dq) & DPAA2_DQ_STAT_VOLATILE);
9813 + * dpaa2_dq_is_pull_complete() - Check whether the pull command is completed.
9814 + * @dq: the dequeue result
9818 +static inline bool dpaa2_dq_is_pull_complete(const struct dpaa2_dq *dq)
9820 + return !!(dpaa2_dq_flags(dq) & DPAA2_DQ_STAT_EXPIRED);
9824 + * dpaa2_dq_seqnum() - Get the seqnum field in dequeue response
9825 + * @dq: the dequeue result
9827 + * seqnum is valid only if VALIDFRAME flag is TRUE
9831 +static inline u16 dpaa2_dq_seqnum(const struct dpaa2_dq *dq)
9833 + return le16_to_cpu(dq->dq.seqnum);
9837 + * dpaa2_dq_odpid() - Get the odpid field in dequeue response
9838 + * @dq: the dequeue result
9840 + * odpid is valid only if ODPVALID flag is TRUE.
9844 +static inline u16 dpaa2_dq_odpid(const struct dpaa2_dq *dq)
9846 + return le16_to_cpu(dq->dq.oprid);
9850 + * dpaa2_dq_fqid() - Get the fqid in dequeue response
9851 + * @dq: the dequeue result
9855 +static inline u32 dpaa2_dq_fqid(const struct dpaa2_dq *dq)
9857 + return le32_to_cpu(dq->dq.fqid) & DQ_FQID_MASK;
9861 + * dpaa2_dq_byte_count() - Get the byte count in dequeue response
9862 + * @dq: the dequeue result
9864 + * Return the byte count remaining in the FQ.
9866 +static inline u32 dpaa2_dq_byte_count(const struct dpaa2_dq *dq)
9868 + return le32_to_cpu(dq->dq.fq_byte_cnt);
9872 + * dpaa2_dq_frame_count() - Get the frame count in dequeue response
9873 + * @dq: the dequeue result
9875 + * Return the frame count remaining in the FQ.
9877 +static inline u32 dpaa2_dq_frame_count(const struct dpaa2_dq *dq)
9879 + return le32_to_cpu(dq->dq.fq_frm_cnt) & DQ_FRAME_COUNT_MASK;
9883 + * dpaa2_dq_fd_ctx() - Get the frame queue context in dequeue response
9884 + * @dq: the dequeue result
9886 + * Return the frame queue context.
9888 +static inline u64 dpaa2_dq_fqd_ctx(const struct dpaa2_dq *dq)
9890 + return le64_to_cpu(dq->dq.fqd_ctx);
9894 + * dpaa2_dq_fd() - Get the frame descriptor in dequeue response
9895 + * @dq: the dequeue result
9897 + * Return the frame descriptor.
9899 +static inline const struct dpaa2_fd *dpaa2_dq_fd(const struct dpaa2_dq *dq)
9901 + return (const struct dpaa2_fd *)&dq->dq.fd[0];
9904 +#endif /* __FSL_DPAA2_GLOBAL_H */
9905 diff --git a/drivers/staging/fsl-mc/include/dpaa2-io.h b/drivers/staging/fsl-mc/include/dpaa2-io.h
9906 new file mode 100644
9907 index 00000000..c7d1d997
9909 +++ b/drivers/staging/fsl-mc/include/dpaa2-io.h
9912 + * Copyright 2014-2016 Freescale Semiconductor Inc.
9913 + * Copyright 2017 NXP
9915 + * Redistribution and use in source and binary forms, with or without
9916 + * modification, are permitted provided that the following conditions are met:
9917 + * * Redistributions of source code must retain the above copyright
9918 + * notice, this list of conditions and the following disclaimer.
9919 + * * Redistributions in binary form must reproduce the above copyright
9920 + * notice, this list of conditions and the following disclaimer in the
9921 + * documentation and/or other materials provided with the distribution.
9922 + * * Neither the name of Freescale Semiconductor nor the
9923 + * names of its contributors may be used to endorse or promote products
9924 + * derived from this software without specific prior written permission.
9926 + * ALTERNATIVELY, this software may be distributed under the terms of the
9927 + * GNU General Public License ("GPL") as published by the Free Software
9928 + * Foundation, either version 2 of that License or (at your option) any
9931 + * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
9932 + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
9933 + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
9934 + * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
9935 + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
9936 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
9937 + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
9938 + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
9939 + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
9940 + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
9942 +#ifndef __FSL_DPAA2_IO_H
9943 +#define __FSL_DPAA2_IO_H
9945 +#include <linux/types.h>
9946 +#include <linux/cpumask.h>
9948 +#include "dpaa2-fd.h"
9949 +#include "dpaa2-global.h"
9952 +struct dpaa2_io_store;
9956 + * DOC: DPIO Service
9958 + * The DPIO service provides APIs for users to interact with the datapath
9959 + * by enqueueing and dequeing frame descriptors.
9961 + * The following set of APIs can be used to enqueue and dequeue frames
9962 + * as well as producing notification callbacks when data is available
9967 + * struct dpaa2_io_desc - The DPIO descriptor
9968 + * @receives_notifications: Use notificaton mode. Non-zero if the DPIO
9970 + * @has_8prio: Set to non-zero for channel with 8 priority WQs. Ignored
9971 + * unless receives_notification is TRUE.
9972 + * @cpu: The cpu index that at least interrupt handlers will
9974 + * @stash_affinity: The stash affinity for this portal favour 'cpu'
9975 + * @regs_cena: The cache enabled regs.
9976 + * @regs_cinh: The cache inhibited regs
9977 + * @dpio_id: The dpio index
9978 + * @qman_version: The qman version
9980 + * Describes the attributes and features of the DPIO object.
9982 +struct dpaa2_io_desc {
9983 + int receives_notifications;
9992 +struct dpaa2_io *dpaa2_io_create(const struct dpaa2_io_desc *desc);
9994 +void dpaa2_io_down(struct dpaa2_io *d);
9996 +irqreturn_t dpaa2_io_irq(struct dpaa2_io *obj);
9999 + * struct dpaa2_io_notification_ctx - The DPIO notification context structure
10000 + * @cb: The callback to be invoked when the notification arrives
10001 + * @is_cdan: Zero for FQDAN, non-zero for CDAN
10002 + * @id: FQID or channel ID, needed for rearm
10003 + * @desired_cpu: The cpu on which the notifications will show up. -1 means
10005 + * @dpio_id: The dpio index
10006 + * @qman64: The 64-bit context value shows up in the FQDAN/CDAN.
10007 + * @node: The list node
10008 + * @dpio_private: The dpio object internal to dpio_service
10010 + * Used when a FQDAN/CDAN registration is made by drivers.
10012 +struct dpaa2_io_notification_ctx {
10013 + void (*cb)(struct dpaa2_io_notification_ctx *);
10019 + struct list_head node;
10020 + void *dpio_private;
10023 +int dpaa2_io_service_register(struct dpaa2_io *service,
10024 + struct dpaa2_io_notification_ctx *ctx);
10025 +void dpaa2_io_service_deregister(struct dpaa2_io *service,
10026 + struct dpaa2_io_notification_ctx *ctx);
10027 +int dpaa2_io_service_rearm(struct dpaa2_io *service,
10028 + struct dpaa2_io_notification_ctx *ctx);
10030 +int dpaa2_io_service_pull_fq(struct dpaa2_io *d, u32 fqid,
10031 + struct dpaa2_io_store *s);
10032 +int dpaa2_io_service_pull_channel(struct dpaa2_io *d, u32 channelid,
10033 + struct dpaa2_io_store *s);
10035 +int dpaa2_io_service_enqueue_fq(struct dpaa2_io *d, u32 fqid,
10036 + const struct dpaa2_fd *fd);
10037 +int dpaa2_io_service_enqueue_qd(struct dpaa2_io *d, u32 qdid, u8 prio,
10038 + u16 qdbin, const struct dpaa2_fd *fd);
10039 +int dpaa2_io_service_release(struct dpaa2_io *d, u32 bpid,
10040 + const u64 *buffers, unsigned int num_buffers);
10041 +int dpaa2_io_service_acquire(struct dpaa2_io *d, u32 bpid,
10042 + u64 *buffers, unsigned int num_buffers);
10044 +struct dpaa2_io_store *dpaa2_io_store_create(unsigned int max_frames,
10045 + struct device *dev);
10046 +void dpaa2_io_store_destroy(struct dpaa2_io_store *s);
10047 +struct dpaa2_dq *dpaa2_io_store_next(struct dpaa2_io_store *s, int *is_last);
10049 +#ifdef CONFIG_FSL_QBMAN_DEBUG
10050 +int dpaa2_io_query_fq_count(struct dpaa2_io *d, uint32_t fqid,
10051 + uint32_t *fcnt, uint32_t *bcnt);
10052 +int dpaa2_io_query_bp_count(struct dpaa2_io *d, uint32_t bpid,
10062 + * struct dpaa2_cscn - The CSCN message format
10063 + * @verb: identifies the type of message (should be 0x27).
10064 + * @stat: status bits related to dequeuing response (not used)
10065 + * @state: bit 0 = 0/1 if CG is no/is congested
10066 + * @reserved: reserved byte
10067 + * @cgid: congest grp ID - the first 16 bits
10068 + * @ctx: context data
10070 + * Congestion management can be implemented in software through
10071 + * the use of Congestion State Change Notifications (CSCN). These
10072 + * are messages written by DPAA2 hardware to memory whenever the
10073 + * instantaneous count (I_CNT field in the CG) exceeds the
10074 + * Congestion State (CS) entrance threshold, signifying congestion
10075 + * entrance, or when the instantaneous count returns below exit
10076 + * threshold, signifying congestion exit. The format of the message
10077 + * is given by the dpaa2_cscn structure. Bit 0 of the state field
10078 + * represents congestion state written by the hardware.
10080 +struct dpaa2_cscn {
10089 +#define DPAA2_CSCN_SIZE 64
10090 +#define DPAA2_CSCN_ALIGN 16
10092 +#define DPAA2_CSCN_STATE_MASK 0x1
10093 +#define DPAA2_CSCN_CONGESTED 1
10095 +static inline bool dpaa2_cscn_state_congested(struct dpaa2_cscn *cscn)
10097 + return ((cscn->state & DPAA2_CSCN_STATE_MASK) == DPAA2_CSCN_CONGESTED);
10100 +#endif /* __FSL_DPAA2_IO_H */
10101 diff --git a/drivers/staging/fsl-mc/include/dpbp-cmd.h b/drivers/staging/fsl-mc/include/dpbp-cmd.h
10102 deleted file mode 100644
10103 index 2860411d..00000000
10104 --- a/drivers/staging/fsl-mc/include/dpbp-cmd.h
10107 -/* Copyright 2013-2016 Freescale Semiconductor Inc.
10109 - * Redistribution and use in source and binary forms, with or without
10110 - * modification, are permitted provided that the following conditions are met:
10111 - * * Redistributions of source code must retain the above copyright
10112 - * notice, this list of conditions and the following disclaimer.
10113 - * * Redistributions in binary form must reproduce the above copyright
10114 - * notice, this list of conditions and the following disclaimer in the
10115 - * documentation and/or other materials provided with the distribution.
10116 - * * Neither the name of the above-listed copyright holders nor the
10117 - * names of any contributors may be used to endorse or promote products
10118 - * derived from this software without specific prior written permission.
10121 - * ALTERNATIVELY, this software may be distributed under the terms of the
10122 - * GNU General Public License ("GPL") as published by the Free Software
10123 - * Foundation, either version 2 of that License or (at your option) any
10126 - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
10127 - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
10128 - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
10129 - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
10130 - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
10131 - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
10132 - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
10133 - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
10134 - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
10135 - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
10136 - * POSSIBILITY OF SUCH DAMAGE.
10138 -#ifndef _FSL_DPBP_CMD_H
10139 -#define _FSL_DPBP_CMD_H
10141 -/* DPBP Version */
10142 -#define DPBP_VER_MAJOR 2
10143 -#define DPBP_VER_MINOR 2
10146 -#define DPBP_CMDID_CLOSE 0x800
10147 -#define DPBP_CMDID_OPEN 0x804
10148 -#define DPBP_CMDID_CREATE 0x904
10149 -#define DPBP_CMDID_DESTROY 0x900
10151 -#define DPBP_CMDID_ENABLE 0x002
10152 -#define DPBP_CMDID_DISABLE 0x003
10153 -#define DPBP_CMDID_GET_ATTR 0x004
10154 -#define DPBP_CMDID_RESET 0x005
10155 -#define DPBP_CMDID_IS_ENABLED 0x006
10157 -#define DPBP_CMDID_SET_IRQ 0x010
10158 -#define DPBP_CMDID_GET_IRQ 0x011
10159 -#define DPBP_CMDID_SET_IRQ_ENABLE 0x012
10160 -#define DPBP_CMDID_GET_IRQ_ENABLE 0x013
10161 -#define DPBP_CMDID_SET_IRQ_MASK 0x014
10162 -#define DPBP_CMDID_GET_IRQ_MASK 0x015
10163 -#define DPBP_CMDID_GET_IRQ_STATUS 0x016
10164 -#define DPBP_CMDID_CLEAR_IRQ_STATUS 0x017
10166 -#define DPBP_CMDID_SET_NOTIFICATIONS 0x01b0
10167 -#define DPBP_CMDID_GET_NOTIFICATIONS 0x01b1
10169 -struct dpbp_cmd_open {
10173 -#define DPBP_ENABLE 0x1
10175 -struct dpbp_rsp_is_enabled {
10179 -struct dpbp_cmd_set_irq {
10190 -struct dpbp_cmd_get_irq {
10195 -struct dpbp_rsp_get_irq {
10196 - /* response word 0 */
10199 - /* response word 1 */
10201 - /* response word 2 */
10206 -struct dpbp_cmd_set_irq_enable {
10212 -struct dpbp_cmd_get_irq_enable {
10217 -struct dpbp_rsp_get_irq_enable {
10221 -struct dpbp_cmd_set_irq_mask {
10226 -struct dpbp_cmd_get_irq_mask {
10231 -struct dpbp_rsp_get_irq_mask {
10235 -struct dpbp_cmd_get_irq_status {
10240 -struct dpbp_rsp_get_irq_status {
10244 -struct dpbp_cmd_clear_irq_status {
10249 -struct dpbp_rsp_get_attributes {
10250 - /* response word 0 */
10254 - /* response word 1 */
10255 - __le16 version_major;
10256 - __le16 version_minor;
10259 -struct dpbp_cmd_set_notifications {
10261 - __le32 depletion_entry;
10262 - __le32 depletion_exit;
10264 - __le32 surplus_entry;
10265 - __le32 surplus_exit;
10270 - __le64 message_ctx;
10272 - __le64 message_iova;
10275 -struct dpbp_rsp_get_notifications {
10276 - /* response word 0 */
10277 - __le32 depletion_entry;
10278 - __le32 depletion_exit;
10279 - /* response word 1 */
10280 - __le32 surplus_entry;
10281 - __le32 surplus_exit;
10282 - /* response word 2 */
10285 - /* response word 3 */
10286 - __le64 message_ctx;
10287 - /* response word 4 */
10288 - __le64 message_iova;
10291 -#endif /* _FSL_DPBP_CMD_H */
10292 diff --git a/drivers/staging/fsl-mc/include/dpbp.h b/drivers/staging/fsl-mc/include/dpbp.h
10293 index e14e85a5..e9e04cce 100644
10294 --- a/drivers/staging/fsl-mc/include/dpbp.h
10295 +++ b/drivers/staging/fsl-mc/include/dpbp.h
10297 -/* Copyright 2013-2015 Freescale Semiconductor Inc.
10299 + * Copyright 2013-2016 Freescale Semiconductor Inc.
10301 * Redistribution and use in source and binary forms, with or without
10302 * modification, are permitted provided that the following conditions are met:
10304 #ifndef __FSL_DPBP_H
10305 #define __FSL_DPBP_H
10307 -/* Data Path Buffer Pool API
10309 + * Data Path Buffer Pool API
10310 * Contains initialization APIs and runtime control APIs for DPBP
10313 @@ -44,25 +46,8 @@ int dpbp_open(struct fsl_mc_io *mc_io,
10316 int dpbp_close(struct fsl_mc_io *mc_io,
10321 - * struct dpbp_cfg - Structure representing DPBP configuration
10322 - * @options: place holder
10328 -int dpbp_create(struct fsl_mc_io *mc_io,
10330 - const struct dpbp_cfg *cfg,
10333 -int dpbp_destroy(struct fsl_mc_io *mc_io,
10339 int dpbp_enable(struct fsl_mc_io *mc_io,
10341 @@ -81,140 +66,25 @@ int dpbp_reset(struct fsl_mc_io *mc_io,
10346 - * struct dpbp_irq_cfg - IRQ configuration
10347 - * @addr: Address that must be written to signal a message-based interrupt
10348 - * @val: Value to write into irq_addr address
10349 - * @irq_num: A user defined number associated with this IRQ
10351 -struct dpbp_irq_cfg {
10357 -int dpbp_set_irq(struct fsl_mc_io *mc_io,
10361 - struct dpbp_irq_cfg *irq_cfg);
10363 -int dpbp_get_irq(struct fsl_mc_io *mc_io,
10368 - struct dpbp_irq_cfg *irq_cfg);
10370 -int dpbp_set_irq_enable(struct fsl_mc_io *mc_io,
10376 -int dpbp_get_irq_enable(struct fsl_mc_io *mc_io,
10382 -int dpbp_set_irq_mask(struct fsl_mc_io *mc_io,
10388 -int dpbp_get_irq_mask(struct fsl_mc_io *mc_io,
10394 -int dpbp_get_irq_status(struct fsl_mc_io *mc_io,
10400 -int dpbp_clear_irq_status(struct fsl_mc_io *mc_io,
10407 * struct dpbp_attr - Structure representing DPBP attributes
10408 * @id: DPBP object ID
10409 - * @version: DPBP version
10410 * @bpid: Hardware buffer pool ID; should be used as an argument in
10411 * acquire/release operations on buffers
10416 - * struct version - Structure representing DPBP version
10417 - * @major: DPBP major version
10418 - * @minor: DPBP minor version
10427 -int dpbp_get_attributes(struct fsl_mc_io *mc_io,
10430 - struct dpbp_attr *attr);
10433 - * DPBP notifications options
10437 - * BPSCN write will attempt to allocate into a cache (coherent write)
10439 -#define DPBP_NOTIF_OPT_COHERENT_WRITE 0x00000001
10442 - * struct dpbp_notification_cfg - Structure representing DPBP notifications
10443 - * towards software
10444 - * @depletion_entry: below this threshold the pool is "depleted";
10445 - * set it to '0' to disable it
10446 - * @depletion_exit: greater than or equal to this threshold the pool exit its
10447 - * "depleted" state
10448 - * @surplus_entry: above this threshold the pool is in "surplus" state;
10449 - * set it to '0' to disable it
10450 - * @surplus_exit: less than or equal to this threshold the pool exit its
10451 - * "surplus" state
10452 - * @message_iova: MUST be given if either 'depletion_entry' or 'surplus_entry'
10453 - * is not '0' (enable); I/O virtual address (must be in DMA-able memory),
10454 - * must be 16B aligned.
10455 - * @message_ctx: The context that will be part of the BPSCN message and will
10456 - * be written to 'message_iova'
10457 - * @options: Mask of available options; use 'DPBP_NOTIF_OPT_<X>' values
10459 -struct dpbp_notification_cfg {
10460 - u32 depletion_entry;
10461 - u32 depletion_exit;
10462 - u32 surplus_entry;
10463 - u32 surplus_exit;
10464 - u64 message_iova;
10469 -int dpbp_set_notifications(struct fsl_mc_io *mc_io,
10472 - struct dpbp_notification_cfg *cfg);
10474 -int dpbp_get_notifications(struct fsl_mc_io *mc_io,
10477 - struct dpbp_notification_cfg *cfg);
10478 +int dpbp_get_attributes(struct fsl_mc_io *mc_io,
10481 + struct dpbp_attr *attr);
10484 +int dpbp_get_api_version(struct fsl_mc_io *mc_io,
10489 #endif /* __FSL_DPBP_H */
10490 diff --git a/drivers/staging/fsl-mc/include/dpcon.h b/drivers/staging/fsl-mc/include/dpcon.h
10491 new file mode 100644
10492 index 00000000..efa23906
10494 +++ b/drivers/staging/fsl-mc/include/dpcon.h
10496 +/* Copyright 2013-2016 Freescale Semiconductor Inc.
10498 + * Redistribution and use in source and binary forms, with or without
10499 + * modification, are permitted provided that the following conditions are met:
10500 + * * Redistributions of source code must retain the above copyright
10501 + * notice, this list of conditions and the following disclaimer.
10502 + * * Redistributions in binary form must reproduce the above copyright
10503 + * notice, this list of conditions and the following disclaimer in the
10504 + * documentation and/or other materials provided with the distribution.
10505 + * * Neither the name of the above-listed copyright holders nor the
10506 + * names of any contributors may be used to endorse or promote products
10507 + * derived from this software without specific prior written permission.
10510 + * ALTERNATIVELY, this software may be distributed under the terms of the
10511 + * GNU General Public License ("GPL") as published by the Free Software
10512 + * Foundation, either version 2 of that License or (at your option) any
10515 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
10516 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
10517 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
10518 + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
10519 + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
10520 + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
10521 + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
10522 + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
10523 + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
10524 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
10525 + * POSSIBILITY OF SUCH DAMAGE.
10527 +#ifndef __FSL_DPCON_H
10528 +#define __FSL_DPCON_H
10530 +/* Data Path Concentrator API
10531 + * Contains initialization APIs and runtime control APIs for DPCON
10536 +/** General DPCON macros */
10539 + * Use it to disable notifications; see dpcon_set_notification()
10541 +#define DPCON_INVALID_DPIO_ID (int)(-1)
10543 +int dpcon_open(struct fsl_mc_io *mc_io,
10548 +int dpcon_close(struct fsl_mc_io *mc_io,
10552 +int dpcon_enable(struct fsl_mc_io *mc_io,
10556 +int dpcon_disable(struct fsl_mc_io *mc_io,
10560 +int dpcon_is_enabled(struct fsl_mc_io *mc_io,
10565 +int dpcon_reset(struct fsl_mc_io *mc_io,
10570 + * struct dpcon_attr - Structure representing DPCON attributes
10571 + * @id: DPCON object ID
10572 + * @qbman_ch_id: Channel ID to be used by dequeue operation
10573 + * @num_priorities: Number of priorities for the DPCON channel (1-8)
10575 +struct dpcon_attr {
10578 + u8 num_priorities;
10581 +int dpcon_get_attributes(struct fsl_mc_io *mc_io,
10584 + struct dpcon_attr *attr);
10587 + * struct dpcon_notification_cfg - Structure representing notification params
10588 + * @dpio_id: DPIO object ID; must be configured with a notification channel;
10589 + * to disable notifications set it to 'DPCON_INVALID_DPIO_ID';
10590 + * @priority: Priority selection within the DPIO channel; valid values
10591 + * are 0-7, depending on the number of priorities in that channel
10592 + * @user_ctx: User context value provided with each CDAN message
10594 +struct dpcon_notification_cfg {
10600 +int dpcon_set_notification(struct fsl_mc_io *mc_io,
10603 + struct dpcon_notification_cfg *cfg);
10605 +int dpcon_get_api_version(struct fsl_mc_io *mc_io,
10610 +#endif /* __FSL_DPCON_H */
10611 diff --git a/drivers/staging/fsl-mc/include/dpmng.h b/drivers/staging/fsl-mc/include/dpmng.h
10612 index e5cfd017..170c07dd 100644
10613 --- a/drivers/staging/fsl-mc/include/dpmng.h
10614 +++ b/drivers/staging/fsl-mc/include/dpmng.h
10616 -/* Copyright 2013-2015 Freescale Semiconductor Inc.
10618 + * Copyright 2013-2016 Freescale Semiconductor Inc.
10620 * Redistribution and use in source and binary forms, with or without
10621 * modification, are permitted provided that the following conditions are met:
10623 #ifndef __FSL_DPMNG_H
10624 #define __FSL_DPMNG_H
10626 -/* Management Complex General API
10628 + * Management Complex General API
10629 * Contains general API for the Management Complex firmware
10632 @@ -58,12 +60,8 @@ struct mc_version {
10636 -int mc_get_version(struct fsl_mc_io *mc_io,
10638 - struct mc_version *mc_ver_info);
10640 -int dpmng_get_container_id(struct fsl_mc_io *mc_io,
10642 - int *container_id);
10643 +int mc_get_version(struct fsl_mc_io *mc_io,
10645 + struct mc_version *mc_ver_info);
10647 #endif /* __FSL_DPMNG_H */
10648 diff --git a/drivers/staging/fsl-mc/include/dpopr.h b/drivers/staging/fsl-mc/include/dpopr.h
10649 new file mode 100644
10650 index 00000000..e1110af2
10652 +++ b/drivers/staging/fsl-mc/include/dpopr.h
10655 + * Copyright 2017 NXP
10657 + * Redistribution and use in source and binary forms, with or without
10658 + * modification, are permitted provided that the following conditions are met:
10659 + * * Redistributions of source code must retain the above copyright
10660 + * notice, this list of conditions and the following disclaimer.
10661 + * * Redistributions in binary form must reproduce the above copyright
10662 + * notice, this list of conditions and the following disclaimer in the
10663 + * documentation and/or other materials provided with the distribution.
10664 + * * Neither the name of the above-listed copyright holders nor the
10665 + * names of any contributors may be used to endorse or promote products
10666 + * derived from this software without specific prior written permission.
10669 + * ALTERNATIVELY, this software may be distributed under the terms of the
10670 + * GNU General Public License ("GPL") as published by the Free Software
10671 + * Foundation, either version 2 of that License or (at your option) any
10674 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
10675 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
10676 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
10677 + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
10678 + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
10679 + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
10680 + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
10681 + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
10682 + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
10683 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
10684 + * POSSIBILITY OF SUCH DAMAGE.
10686 +#ifndef __FSL_DPOPR_H_
10687 +#define __FSL_DPOPR_H_
10689 +/* Data Path Order Restoration API
10690 + * Contains initialization APIs and runtime APIs for the Order Restoration
10693 +/** Order Restoration properties */
10696 + * Create a new Order Point Record option
10698 +#define OPR_OPT_CREATE 0x1
10700 + * Retire an existing Order Point Record option
10702 +#define OPR_OPT_RETIRE 0x2
10705 + * struct opr_cfg - Structure representing OPR configuration
10706 + * @oprrws: Order point record (OPR) restoration window size (0 to 5)
10707 + * 0 - Window size is 32 frames.
10708 + * 1 - Window size is 64 frames.
10709 + * 2 - Window size is 128 frames.
10710 + * 3 - Window size is 256 frames.
10711 + * 4 - Window size is 512 frames.
10712 + * 5 - Window size is 1024 frames.
10713 + * @oa: OPR auto advance NESN window size (0 disabled, 1 enabled)
10714 + * @olws: OPR acceptable late arrival window size (0 to 3)
10715 + * 0 - Disabled. Late arrivals are always rejected.
10716 + * 1 - Window size is 32 frames.
10717 + * 2 - Window size is the same as the OPR restoration
10718 + * window size configured in the OPRRWS field.
10719 + * 3 - Window size is 8192 frames. Late arrivals are
10720 + * always accepted.
10721 + * @oeane: Order restoration list (ORL) resource exhaustion
10722 + * advance NESN enable (0 disabled, 1 enabled)
10723 + * @oloe: OPR loose ordering enable (0 disabled, 1 enabled)
10734 + * struct opr_qry - Structure representing OPR configuration
10735 + * @enable: Enabled state
10736 + * @rip: Retirement In Progress
10737 + * @ndsn: Next dispensed sequence number
10738 + * @nesn: Next expected sequence number
10739 + * @ea_hseq: Early arrival head sequence number
10740 + * @hseq_nlis: HSEQ not last in sequence
10741 + * @ea_tseq: Early arrival tail sequence number
10742 + * @tseq_nlis: TSEQ not last in sequence
10743 + * @ea_tptr: Early arrival tail pointer
10744 + * @ea_hptr: Early arrival head pointer
10745 + * @opr_id: Order Point Record ID
10746 + * @opr_vid: Order Point Record Virtual ID
10763 +#endif /* __FSL_DPOPR_H_ */
10764 diff --git a/drivers/staging/fsl-mc/include/dprc.h b/drivers/staging/fsl-mc/include/dprc.h
10765 index 593b2bbe..8dc411ec 100644
10766 --- a/drivers/staging/fsl-mc/include/dprc.h
10767 +++ b/drivers/staging/fsl-mc/include/dprc.h
10769 -/* Copyright 2013-2015 Freescale Semiconductor Inc.
10771 + * Copyright 2013-2016 Freescale Semiconductor Inc.
10773 * Redistribution and use in source and binary forms, with or without
10774 * modification, are permitted provided that the following conditions are met:
10775 @@ -34,26 +35,13 @@
10777 #include "mc-cmd.h"
10779 -/* Data Path Resource Container API
10781 + * Data Path Resource Container API
10782 * Contains DPRC API for managing and querying DPAA resources
10788 - * Set this value as the icid value in dprc_cfg structure when creating a
10789 - * container, in case the ICID is not selected by the user and should be
10790 - * allocated by the DPRC from the pool of ICIDs.
10792 -#define DPRC_GET_ICID_FROM_POOL (u16)(~(0))
10795 - * Set this value as the portal_id value in dprc_cfg structure when creating a
10796 - * container, in case the portal ID is not specifically selected by the
10797 - * user and should be allocated by the DPRC from the pool of portal ids.
10799 -#define DPRC_GET_PORTAL_ID_FROM_POOL (int)(~(0))
10801 int dprc_open(struct fsl_mc_io *mc_io,
10804 @@ -63,75 +51,6 @@ int dprc_close(struct fsl_mc_io *mc_io,
10809 - * Container general options
10811 - * These options may be selected at container creation by the container creator
10812 - * and can be retrieved using dprc_get_attributes()
10815 -/* Spawn Policy Option allowed - Indicates that the new container is allowed
10816 - * to spawn and have its own child containers.
10818 -#define DPRC_CFG_OPT_SPAWN_ALLOWED 0x00000001
10820 -/* General Container allocation policy - Indicates that the new container is
10821 - * allowed to allocate requested resources from its parent container; if not
10822 - * set, the container is only allowed to use resources in its own pools; Note
10823 - * that this is a container's global policy, but the parent container may
10824 - * override it and set specific quota per resource type.
10826 -#define DPRC_CFG_OPT_ALLOC_ALLOWED 0x00000002
10828 -/* Object initialization allowed - software context associated with this
10829 - * container is allowed to invoke object initialization operations.
10831 -#define DPRC_CFG_OPT_OBJ_CREATE_ALLOWED 0x00000004
10833 -/* Topology change allowed - software context associated with this
10834 - * container is allowed to invoke topology operations, such as attach/detach
10835 - * of network objects.
10837 -#define DPRC_CFG_OPT_TOPOLOGY_CHANGES_ALLOWED 0x00000008
10839 -/* AIOP - Indicates that container belongs to AIOP. */
10840 -#define DPRC_CFG_OPT_AIOP 0x00000020
10842 -/* IRQ Config - Indicates that the container allowed to configure its IRQs. */
10843 -#define DPRC_CFG_OPT_IRQ_CFG_ALLOWED 0x00000040
10846 - * struct dprc_cfg - Container configuration options
10847 - * @icid: Container's ICID; if set to 'DPRC_GET_ICID_FROM_POOL', a free
10848 - * ICID value is allocated by the DPRC
10849 - * @portal_id: Portal ID; if set to 'DPRC_GET_PORTAL_ID_FROM_POOL', a free
10850 - * portal ID is allocated by the DPRC
10851 - * @options: Combination of 'DPRC_CFG_OPT_<X>' options
10852 - * @label: Object's label
10861 -int dprc_create_container(struct fsl_mc_io *mc_io,
10864 - struct dprc_cfg *cfg,
10865 - int *child_container_id,
10866 - u64 *child_portal_offset);
10868 -int dprc_destroy_container(struct fsl_mc_io *mc_io,
10871 - int child_container_id);
10873 -int dprc_reset_container(struct fsl_mc_io *mc_io,
10876 - int child_container_id);
10880 @@ -139,7 +58,7 @@ int dprc_reset_container(struct fsl_mc_io *mc_io,
10881 #define DPRC_IRQ_INDEX 0
10883 /* Number of dprc's IRQs */
10884 -#define DPRC_NUM_OF_IRQS 1
10885 +#define DPRC_NUM_OF_IRQS 1
10887 /* DPRC IRQ events */
10889 @@ -151,12 +70,14 @@ int dprc_reset_container(struct fsl_mc_io *mc_io,
10890 #define DPRC_IRQ_EVENT_RES_ADDED 0x00000004
10891 /* IRQ event - Indicates that resources removed from the container */
10892 #define DPRC_IRQ_EVENT_RES_REMOVED 0x00000008
10893 -/* IRQ event - Indicates that one of the descendant containers that opened by
10895 + * IRQ event - Indicates that one of the descendant containers that opened by
10896 * this container is destroyed
10898 #define DPRC_IRQ_EVENT_CONTAINER_DESTROYED 0x00000010
10900 -/* IRQ event - Indicates that on one of the container's opened object is
10902 + * IRQ event - Indicates that on one of the container's opened object is
10905 #define DPRC_IRQ_EVENT_OBJ_DESTROYED 0x00000020
10906 @@ -171,59 +92,59 @@ int dprc_reset_container(struct fsl_mc_io *mc_io,
10907 * @irq_num: A user defined number associated with this IRQ
10909 struct dprc_irq_cfg {
10910 - phys_addr_t paddr;
10913 + phys_addr_t paddr;
10918 -int dprc_set_irq(struct fsl_mc_io *mc_io,
10922 - struct dprc_irq_cfg *irq_cfg);
10924 -int dprc_get_irq(struct fsl_mc_io *mc_io,
10929 - struct dprc_irq_cfg *irq_cfg);
10931 -int dprc_set_irq_enable(struct fsl_mc_io *mc_io,
10937 -int dprc_get_irq_enable(struct fsl_mc_io *mc_io,
10943 -int dprc_set_irq_mask(struct fsl_mc_io *mc_io,
10949 -int dprc_get_irq_mask(struct fsl_mc_io *mc_io,
10955 -int dprc_get_irq_status(struct fsl_mc_io *mc_io,
10961 -int dprc_clear_irq_status(struct fsl_mc_io *mc_io,
10966 +int dprc_set_irq(struct fsl_mc_io *mc_io,
10970 + struct dprc_irq_cfg *irq_cfg);
10972 +int dprc_get_irq(struct fsl_mc_io *mc_io,
10977 + struct dprc_irq_cfg *irq_cfg);
10979 +int dprc_set_irq_enable(struct fsl_mc_io *mc_io,
10985 +int dprc_get_irq_enable(struct fsl_mc_io *mc_io,
10991 +int dprc_set_irq_mask(struct fsl_mc_io *mc_io,
10997 +int dprc_get_irq_mask(struct fsl_mc_io *mc_io,
11003 +int dprc_get_irq_status(struct fsl_mc_io *mc_io,
11009 +int dprc_clear_irq_status(struct fsl_mc_io *mc_io,
11016 * struct dprc_attributes - Container attributes
11017 @@ -231,114 +152,23 @@ int dprc_clear_irq_status(struct fsl_mc_io *mc_io,
11018 * @icid: Container's ICID
11019 * @portal_id: Container's portal ID
11020 * @options: Container's options as set at container's creation
11021 - * @version: DPRC version
11023 struct dprc_attributes {
11029 - * struct version - DPRC version
11030 - * @major: DPRC major version
11031 - * @minor: DPRC minor version
11039 -int dprc_get_attributes(struct fsl_mc_io *mc_io,
11042 - struct dprc_attributes *attributes);
11044 -int dprc_set_res_quota(struct fsl_mc_io *mc_io,
11047 - int child_container_id,
11051 -int dprc_get_res_quota(struct fsl_mc_io *mc_io,
11054 - int child_container_id,
11058 -/* Resource request options */
11060 -/* Explicit resource ID request - The requested objects/resources
11061 - * are explicit and sequential (in case of resources).
11062 - * The base ID is given at res_req at base_align field
11064 -#define DPRC_RES_REQ_OPT_EXPLICIT 0x00000001
11066 -/* Aligned resources request - Relevant only for resources
11067 - * request (and not objects). Indicates that resources base ID should be
11068 - * sequential and aligned to the value given at dprc_res_req base_align field
11070 -#define DPRC_RES_REQ_OPT_ALIGNED 0x00000002
11072 -/* Plugged Flag - Relevant only for object assignment request.
11073 - * Indicates that after all objects assigned. An interrupt will be invoked at
11074 - * the relevant GPP. The assigned object will be marked as plugged.
11075 - * plugged objects can't be assigned from their container
11077 -#define DPRC_RES_REQ_OPT_PLUGGED 0x00000004
11080 - * struct dprc_res_req - Resource request descriptor, to be used in assignment
11081 - * or un-assignment of resources and objects.
11082 - * @type: Resource/object type: Represent as a NULL terminated string.
11083 - * This string may received by using dprc_get_pool() to get resource
11084 - * type and dprc_get_obj() to get object type;
11085 - * Note: it is not possible to assign/un-assign DPRC objects
11086 - * @num: Number of resources
11087 - * @options: Request options: combination of DPRC_RES_REQ_OPT_ options
11088 - * @id_base_align: In case of explicit assignment (DPRC_RES_REQ_OPT_EXPLICIT
11089 - * is set at option), this field represents the required base ID
11090 - * for resource allocation; In case of aligned assignment
11091 - * (DPRC_RES_REQ_OPT_ALIGNED is set at option), this field
11092 - * indicates the required alignment for the resource ID(s) -
11093 - * use 0 if there is no alignment or explicit ID requirements
11095 -struct dprc_res_req {
11099 - int id_base_align;
11102 -int dprc_assign(struct fsl_mc_io *mc_io,
11105 - int container_id,
11106 - struct dprc_res_req *res_req);
11108 -int dprc_unassign(struct fsl_mc_io *mc_io,
11111 - int child_container_id,
11112 - struct dprc_res_req *res_req);
11114 -int dprc_get_pool_count(struct fsl_mc_io *mc_io,
11117 - int *pool_count);
11119 -int dprc_get_pool(struct fsl_mc_io *mc_io,
11124 +int dprc_get_attributes(struct fsl_mc_io *mc_io,
11127 + struct dprc_attributes *attributes);
11129 int dprc_get_obj_count(struct fsl_mc_io *mc_io,
11137 /* Objects Attributes Flags */
11139 @@ -353,7 +183,7 @@ int dprc_get_obj_count(struct fsl_mc_io *mc_io,
11141 * user is responsible for proper memory handling through IOMMU configuration.
11143 -#define DPRC_OBJ_FLAG_NO_MEM_SHAREABILITY 0x0001
11144 +#define DPRC_OBJ_FLAG_NO_MEM_SHAREABILITY 0x0001
11147 * struct dprc_obj_desc - Object descriptor, returned from dprc_get_obj()
11148 @@ -381,41 +211,41 @@ struct dprc_obj_desc {
11152 -int dprc_get_obj(struct fsl_mc_io *mc_io,
11156 - struct dprc_obj_desc *obj_desc);
11158 -int dprc_get_obj_desc(struct fsl_mc_io *mc_io,
11163 - struct dprc_obj_desc *obj_desc);
11165 -int dprc_set_obj_irq(struct fsl_mc_io *mc_io,
11171 - struct dprc_irq_cfg *irq_cfg);
11173 -int dprc_get_obj_irq(struct fsl_mc_io *mc_io,
11180 - struct dprc_irq_cfg *irq_cfg);
11182 -int dprc_get_res_count(struct fsl_mc_io *mc_io,
11187 +int dprc_get_obj(struct fsl_mc_io *mc_io,
11191 + struct dprc_obj_desc *obj_desc);
11193 +int dprc_get_obj_desc(struct fsl_mc_io *mc_io,
11198 + struct dprc_obj_desc *obj_desc);
11200 +int dprc_set_obj_irq(struct fsl_mc_io *mc_io,
11206 + struct dprc_irq_cfg *irq_cfg);
11208 +int dprc_get_obj_irq(struct fsl_mc_io *mc_io,
11215 + struct dprc_irq_cfg *irq_cfg);
11217 +int dprc_get_res_count(struct fsl_mc_io *mc_io,
11224 * enum dprc_iter_status - Iteration status
11225 @@ -429,27 +259,6 @@ enum dprc_iter_status {
11226 DPRC_ITER_STATUS_LAST = 2
11230 - * struct dprc_res_ids_range_desc - Resource ID range descriptor
11231 - * @base_id: Base resource ID of this range
11232 - * @last_id: Last resource ID of this range
11233 - * @iter_status: Iteration status - should be set to DPRC_ITER_STATUS_FIRST at
11234 - * first iteration; while the returned marker is DPRC_ITER_STATUS_MORE,
11235 - * additional iterations are needed, until the returned marker is
11236 - * DPRC_ITER_STATUS_LAST
11238 -struct dprc_res_ids_range_desc {
11241 - enum dprc_iter_status iter_status;
11244 -int dprc_get_res_ids(struct fsl_mc_io *mc_io,
11248 - struct dprc_res_ids_range_desc *range_desc);
11251 /* Cacheable - Indicates that region should be mapped as cacheable */
11252 #define DPRC_REGION_CACHEABLE 0x00000001
11253 @@ -481,64 +290,27 @@ struct dprc_region_desc {
11254 enum dprc_region_type type;
11257 -int dprc_get_obj_region(struct fsl_mc_io *mc_io,
11263 - struct dprc_region_desc *region_desc);
11265 -int dprc_set_obj_label(struct fsl_mc_io *mc_io,
11271 +int dprc_get_obj_region(struct fsl_mc_io *mc_io,
11277 + struct dprc_region_desc *region_desc);
11280 - * struct dprc_endpoint - Endpoint description for link connect/disconnect
11282 - * @type: Endpoint object type: NULL terminated string
11283 - * @id: Endpoint object ID
11284 - * @if_id: Interface ID; should be set for endpoints with multiple
11285 - * interfaces ("dpsw", "dpdmux"); for others, always set to 0
11287 -struct dprc_endpoint {
11292 +int dprc_get_api_version(struct fsl_mc_io *mc_io,
11298 - * struct dprc_connection_cfg - Connection configuration.
11299 - * Used for virtual connections only
11300 - * @committed_rate: Committed rate (Mbits/s)
11301 - * @max_rate: Maximum rate (Mbits/s)
11303 -struct dprc_connection_cfg {
11304 - u32 committed_rate;
11307 +int dprc_get_container_id(struct fsl_mc_io *mc_io,
11309 + int *container_id);
11311 -int dprc_connect(struct fsl_mc_io *mc_io,
11314 - const struct dprc_endpoint *endpoint1,
11315 - const struct dprc_endpoint *endpoint2,
11316 - const struct dprc_connection_cfg *cfg);
11318 -int dprc_disconnect(struct fsl_mc_io *mc_io,
11321 - const struct dprc_endpoint *endpoint);
11323 -int dprc_get_connection(struct fsl_mc_io *mc_io,
11326 - const struct dprc_endpoint *endpoint1,
11327 - struct dprc_endpoint *endpoint2,
11329 +int dprc_reset_container(struct fsl_mc_io *mc_io,
11332 + int child_container_id);
11334 #endif /* _FSL_DPRC_H */
11336 diff --git a/drivers/staging/fsl-mc/include/mc-bus.h b/drivers/staging/fsl-mc/include/mc-bus.h
11337 index 170684a5..4d1f2d3e 100644
11338 --- a/drivers/staging/fsl-mc/include/mc-bus.h
11339 +++ b/drivers/staging/fsl-mc/include/mc-bus.h
11342 * Freescale Management Complex (MC) bus declarations
11344 - * Copyright (C) 2014 Freescale Semiconductor, Inc.
11345 + * Copyright (C) 2014-2016 Freescale Semiconductor, Inc.
11346 * Author: German Rivera <German.Rivera@freescale.com>
11348 * This file is licensed under the terms of the GNU General Public
11349 @@ -42,8 +42,8 @@ struct msi_domain_info;
11351 struct fsl_mc_resource_pool {
11352 enum fsl_mc_pool_type type;
11353 - int16_t max_count;
11354 - int16_t free_count;
11357 struct mutex mutex; /* serializes access to free_list */
11358 struct list_head free_list;
11359 struct fsl_mc_bus *mc_bus;
11360 @@ -73,6 +73,7 @@ struct fsl_mc_bus {
11361 int dprc_scan_container(struct fsl_mc_device *mc_bus_dev);
11363 int dprc_scan_objects(struct fsl_mc_device *mc_bus_dev,
11364 + const char *driver_override,
11365 unsigned int *total_irq_count);
11367 int __init dprc_driver_init(void);
11368 diff --git a/drivers/staging/fsl-mc/include/mc-cmd.h b/drivers/staging/fsl-mc/include/mc-cmd.h
11369 index 5decb989..2e08aa31 100644
11370 --- a/drivers/staging/fsl-mc/include/mc-cmd.h
11371 +++ b/drivers/staging/fsl-mc/include/mc-cmd.h
11373 -/* Copyright 2013-2015 Freescale Semiconductor Inc.
11375 + * Copyright 2013-2016 Freescale Semiconductor Inc.
11377 * Redistribution and use in source and binary forms, with or without
11378 * modification, are permitted provided that the following conditions are met:
11379 @@ -48,6 +49,15 @@ struct mc_command {
11380 u64 params[MC_CMD_NUM_OF_PARAMS];
11383 +struct mc_rsp_create {
11384 + __le32 object_id;
11387 +struct mc_rsp_api_ver {
11388 + __le16 major_ver;
11389 + __le16 minor_ver;
11392 enum mc_cmd_status {
11393 MC_CMD_STATUS_OK = 0x0, /* Completed successfully */
11394 MC_CMD_STATUS_READY = 0x1, /* Ready to be processed */
11395 @@ -72,11 +82,6 @@ enum mc_cmd_status {
11396 /* Command completion flag */
11397 #define MC_CMD_FLAG_INTR_DIS 0x01
11399 -#define MC_CMD_HDR_CMDID_MASK 0xFFF0
11400 -#define MC_CMD_HDR_CMDID_SHIFT 4
11401 -#define MC_CMD_HDR_TOKEN_MASK 0xFFC0
11402 -#define MC_CMD_HDR_TOKEN_SHIFT 6
11404 static inline u64 mc_encode_cmd_header(u16 cmd_id,
11407 @@ -84,10 +89,8 @@ static inline u64 mc_encode_cmd_header(u16 cmd_id,
11409 struct mc_cmd_header *hdr = (struct mc_cmd_header *)&header;
11411 - hdr->cmd_id = cpu_to_le16((cmd_id << MC_CMD_HDR_CMDID_SHIFT) &
11412 - MC_CMD_HDR_CMDID_MASK);
11413 - hdr->token = cpu_to_le16((token << MC_CMD_HDR_TOKEN_SHIFT) &
11414 - MC_CMD_HDR_TOKEN_MASK);
11415 + hdr->cmd_id = cpu_to_le16(cmd_id);
11416 + hdr->token = cpu_to_le16(token);
11417 hdr->status = MC_CMD_STATUS_READY;
11418 if (cmd_flags & MC_CMD_FLAG_PRI)
11419 hdr->flags_hw = MC_CMD_FLAG_PRI;
11420 @@ -102,7 +105,26 @@ static inline u16 mc_cmd_hdr_read_token(struct mc_command *cmd)
11421 struct mc_cmd_header *hdr = (struct mc_cmd_header *)&cmd->header;
11422 u16 token = le16_to_cpu(hdr->token);
11424 - return (token & MC_CMD_HDR_TOKEN_MASK) >> MC_CMD_HDR_TOKEN_SHIFT;
11428 +static inline u32 mc_cmd_read_object_id(struct mc_command *cmd)
11430 + struct mc_rsp_create *rsp_params;
11432 + rsp_params = (struct mc_rsp_create *)cmd->params;
11433 + return le32_to_cpu(rsp_params->object_id);
11436 +static inline void mc_cmd_read_api_version(struct mc_command *cmd,
11440 + struct mc_rsp_api_ver *rsp_params;
11442 + rsp_params = (struct mc_rsp_api_ver *)cmd->params;
11443 + *major_ver = le16_to_cpu(rsp_params->major_ver);
11444 + *minor_ver = le16_to_cpu(rsp_params->minor_ver);
11447 #endif /* __FSL_MC_CMD_H */
11448 diff --git a/drivers/staging/fsl-mc/include/mc-sys.h b/drivers/staging/fsl-mc/include/mc-sys.h
11449 index 89ad0cf5..dca7f908 100644
11450 --- a/drivers/staging/fsl-mc/include/mc-sys.h
11451 +++ b/drivers/staging/fsl-mc/include/mc-sys.h
11453 -/* Copyright 2013-2014 Freescale Semiconductor Inc.
11455 + * Copyright 2013-2016 Freescale Semiconductor Inc.
11457 * Interface of the I/O services to send MC commands to the MC hardware
11459 diff --git a/drivers/staging/fsl-mc/include/mc.h b/drivers/staging/fsl-mc/include/mc.h
11460 index f6e720e8..c23b78a4 100644
11461 --- a/drivers/staging/fsl-mc/include/mc.h
11462 +++ b/drivers/staging/fsl-mc/include/mc.h
11465 * Freescale Management Complex (MC) bus public interface
11467 - * Copyright (C) 2014 Freescale Semiconductor, Inc.
11468 + * Copyright (C) 2014-2016 Freescale Semiconductor, Inc.
11469 * Author: German Rivera <German.Rivera@freescale.com>
11471 * This file is licensed under the terms of the GNU General Public
11472 @@ -81,7 +81,7 @@ enum fsl_mc_pool_type {
11474 struct fsl_mc_resource {
11475 enum fsl_mc_pool_type type;
11479 struct fsl_mc_resource_pool *parent_pool;
11480 struct list_head node;
11481 @@ -122,6 +122,7 @@ struct fsl_mc_device_irq {
11482 * @regions: pointer to array of MMIO region entries
11483 * @irqs: pointer to array of pointers to interrupts allocated to this device
11484 * @resource: generic resource associated with this MC object device, if any.
11485 + * @driver_override: Driver name to force a match
11487 * Generic device object for MC object devices that are "attached" to a
11489 @@ -154,6 +155,7 @@ struct fsl_mc_device {
11490 struct resource *regions;
11491 struct fsl_mc_device_irq **irqs;
11492 struct fsl_mc_resource *resource;
11493 + const char *driver_override;
11496 #define to_fsl_mc_device(_dev) \
11497 @@ -175,6 +177,8 @@ struct fsl_mc_device {
11498 #define fsl_mc_driver_register(drv) \
11499 __fsl_mc_driver_register(drv, THIS_MODULE)
11501 +void fsl_mc_device_remove(struct fsl_mc_device *mc_dev);
11503 int __must_check __fsl_mc_driver_register(struct fsl_mc_driver *fsl_mc_driver,
11504 struct module *owner);
11506 @@ -198,4 +202,13 @@ int __must_check fsl_mc_allocate_irqs(struct fsl_mc_device *mc_dev);
11508 void fsl_mc_free_irqs(struct fsl_mc_device *mc_dev);
11510 +void fsl_mc_dma_configure(struct fsl_mc_device *mc_dev,
11511 + struct device_node *fsl_mc_platform_node, int coherent);
11513 +#ifdef CONFIG_FSL_MC_BUS
11514 +struct iommu_group *fsl_mc_device_group(struct device *dev);
11516 +#define fsl_mc_device_group(__dev) NULL
11519 #endif /* _FSL_MC_H_ */