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 --- a/drivers/staging/fsl-mc/bus/Kconfig
98 +++ b/drivers/staging/fsl-mc/bus/Kconfig
101 -# Freescale Management Complex (MC) bus drivers
104 -# Copyright (C) 2014 Freescale Semiconductor, Inc.
105 +# Copyright (C) 2014-2016 Freescale Semiconductor, Inc.
107 # This file is released under the GPLv2
111 - bool "Freescale Management Complex (MC) bus driver"
112 - depends on OF && ARM64
113 + bool "QorIQ DPAA2 fsl-mc bus driver"
114 + depends on OF && ARCH_LAYERSCAPE
115 select GENERIC_MSI_IRQ_DOMAIN
117 - Driver to enable the bus infrastructure for the Freescale
118 - QorIQ Management Complex (fsl-mc). The fsl-mc is a hardware
119 - module of the QorIQ LS2 SoCs, that does resource management
120 - for hardware building-blocks in the SoC that can be used
121 - to dynamically create networking hardware objects such as
122 - network interfaces (NICs), crypto accelerator instances,
124 + Driver to enable the bus infrastructure for the QorIQ DPAA2
125 + architecture. The fsl-mc bus driver handles discovery of
126 + DPAA2 objects (which are represented as Linux devices) and
127 + binding objects to drivers.
129 - Only enable this option when building the kernel for
130 - Freescale QorQIQ LS2xxxx SoCs.
132 + tristate "QorIQ DPAA2 DPIO driver"
133 + depends on FSL_MC_BUS
135 + Driver for the DPAA2 DPIO object. A DPIO provides queue and
136 + buffer management facilities for software to interact with
137 + other DPAA2 objects. This driver does not expose the DPIO
138 + objects individually, but groups them under a service layer
141 +config FSL_QBMAN_DEBUG
142 + tristate "Freescale QBMAN Debug APIs"
143 + depends on FSL_MC_DPIO
145 + QBMan debug assistant APIs.
147 +config FSL_MC_RESTOOL
148 + tristate "Freescale Management Complex (MC) restool driver"
149 + depends on FSL_MC_BUS
151 + Driver that provides kernel support for the Freescale Management
152 + Complex resource manager user-space tool.
153 --- a/drivers/staging/fsl-mc/bus/Makefile
154 +++ b/drivers/staging/fsl-mc/bus/Makefile
155 @@ -17,4 +17,12 @@ mc-bus-driver-objs := fsl-mc-bus.o \
157 irq-gic-v3-its-fsl-mc-msi.o \
165 +obj-$(CONFIG_FSL_MC_DPIO) += dpio/
167 +# MC restool kernel support
168 +obj-$(CONFIG_FSL_MC_RESTOOL) += mc-restool.o
170 +++ b/drivers/staging/fsl-mc/bus/dpbp-cmd.h
173 + * Copyright 2013-2016 Freescale Semiconductor Inc.
175 + * Redistribution and use in source and binary forms, with or without
176 + * modification, are permitted provided that the following conditions are met:
177 + * * Redistributions of source code must retain the above copyright
178 + * notice, this list of conditions and the following disclaimer.
179 + * * Redistributions in binary form must reproduce the above copyright
180 + * notice, this list of conditions and the following disclaimer in the
181 + * documentation and/or other materials provided with the distribution.
182 + * * Neither the name of the above-listed copyright holders nor the
183 + * names of any contributors may be used to endorse or promote products
184 + * derived from this software without specific prior written permission.
186 + * ALTERNATIVELY, this software may be distributed under the terms of the
187 + * GNU General Public License ("GPL") as published by the Free Software
188 + * Foundation, either version 2 of that License or (at your option) any
191 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
192 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
193 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
194 + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
195 + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
196 + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
197 + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
198 + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
199 + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
200 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
201 + * POSSIBILITY OF SUCH DAMAGE.
203 +#ifndef _FSL_DPBP_CMD_H
204 +#define _FSL_DPBP_CMD_H
207 +#define DPBP_VER_MAJOR 3
208 +#define DPBP_VER_MINOR 2
210 +/* Command versioning */
211 +#define DPBP_CMD_BASE_VERSION 1
212 +#define DPBP_CMD_ID_OFFSET 4
214 +#define DPBP_CMD(id) ((id << DPBP_CMD_ID_OFFSET) | DPBP_CMD_BASE_VERSION)
217 +#define DPBP_CMDID_CLOSE DPBP_CMD(0x800)
218 +#define DPBP_CMDID_OPEN DPBP_CMD(0x804)
219 +#define DPBP_CMDID_GET_API_VERSION DPBP_CMD(0xa04)
221 +#define DPBP_CMDID_ENABLE DPBP_CMD(0x002)
222 +#define DPBP_CMDID_DISABLE DPBP_CMD(0x003)
223 +#define DPBP_CMDID_GET_ATTR DPBP_CMD(0x004)
224 +#define DPBP_CMDID_RESET DPBP_CMD(0x005)
225 +#define DPBP_CMDID_IS_ENABLED DPBP_CMD(0x006)
227 +struct dpbp_cmd_open {
231 +struct dpbp_cmd_destroy {
235 +#define DPBP_ENABLE 0x1
237 +struct dpbp_rsp_is_enabled {
241 +struct dpbp_rsp_get_attributes {
242 + /* response word 0 */
246 + /* response word 1 */
247 + __le16 version_major;
248 + __le16 version_minor;
251 +#endif /* _FSL_DPBP_CMD_H */
252 --- a/drivers/staging/fsl-mc/bus/dpbp.c
253 +++ b/drivers/staging/fsl-mc/bus/dpbp.c
255 -/* Copyright 2013-2016 Freescale Semiconductor Inc.
257 + * Copyright 2013-2016 Freescale Semiconductor Inc.
259 * Redistribution and use in source and binary forms, with or without
260 * modification, are permitted provided that the following conditions are met:
262 * names of any contributors may be used to endorse or promote products
263 * derived from this software without specific prior written permission.
266 * ALTERNATIVELY, this software may be distributed under the terms of the
267 * GNU General Public License ("GPL") as published by the Free Software
268 * Foundation, either version 2 of that License or (at your option) any
270 #include "../include/mc-sys.h"
271 #include "../include/mc-cmd.h"
272 #include "../include/dpbp.h"
273 -#include "../include/dpbp-cmd.h"
275 +#include "dpbp-cmd.h"
278 * dpbp_open() - Open a control session for the specified object.
279 @@ -105,74 +106,6 @@ int dpbp_close(struct fsl_mc_io *mc_io,
280 EXPORT_SYMBOL(dpbp_close);
283 - * dpbp_create() - Create the DPBP object.
284 - * @mc_io: Pointer to MC portal's I/O object
285 - * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
286 - * @cfg: Configuration structure
287 - * @token: Returned token; use in subsequent API calls
289 - * Create the DPBP object, allocate required resources and
290 - * perform required initialization.
292 - * The object can be created either by declaring it in the
293 - * DPL file, or by calling this function.
294 - * This function returns a unique authentication token,
295 - * associated with the specific object ID and the specific MC
296 - * portal; this token must be used in all subsequent calls to
297 - * this specific object. For objects that are created using the
298 - * DPL file, call dpbp_open function to get an authentication
301 - * Return: '0' on Success; Error code otherwise.
303 -int dpbp_create(struct fsl_mc_io *mc_io,
305 - const struct dpbp_cfg *cfg,
308 - struct mc_command cmd = { 0 };
311 - (void)(cfg); /* unused */
313 - /* prepare command */
314 - cmd.header = mc_encode_cmd_header(DPBP_CMDID_CREATE,
317 - /* send command to mc*/
318 - err = mc_send_command(mc_io, &cmd);
322 - /* retrieve response parameters */
323 - *token = mc_cmd_hdr_read_token(&cmd);
329 - * dpbp_destroy() - Destroy the DPBP object and release all its resources.
330 - * @mc_io: Pointer to MC portal's I/O object
331 - * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
332 - * @token: Token of DPBP object
334 - * Return: '0' on Success; error code otherwise.
336 -int dpbp_destroy(struct fsl_mc_io *mc_io,
340 - struct mc_command cmd = { 0 };
342 - /* prepare command */
343 - cmd.header = mc_encode_cmd_header(DPBP_CMDID_DESTROY,
346 - /* send command to mc*/
347 - return mc_send_command(mc_io, &cmd);
351 * dpbp_enable() - Enable the DPBP.
352 * @mc_io: Pointer to MC portal's I/O object
353 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
354 @@ -250,6 +183,7 @@ int dpbp_is_enabled(struct fsl_mc_io *mc
358 +EXPORT_SYMBOL(dpbp_is_enabled);
361 * dpbp_reset() - Reset the DPBP, returns the object to initial state.
362 @@ -272,310 +206,7 @@ int dpbp_reset(struct fsl_mc_io *mc_io,
363 /* send command to mc*/
364 return mc_send_command(mc_io, &cmd);
368 - * dpbp_set_irq() - Set IRQ information for the DPBP to trigger an interrupt.
369 - * @mc_io: Pointer to MC portal's I/O object
370 - * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
371 - * @token: Token of DPBP object
372 - * @irq_index: Identifies the interrupt index to configure
373 - * @irq_cfg: IRQ configuration
375 - * Return: '0' on Success; Error code otherwise.
377 -int dpbp_set_irq(struct fsl_mc_io *mc_io,
381 - struct dpbp_irq_cfg *irq_cfg)
383 - struct mc_command cmd = { 0 };
384 - struct dpbp_cmd_set_irq *cmd_params;
386 - /* prepare command */
387 - cmd.header = mc_encode_cmd_header(DPBP_CMDID_SET_IRQ,
389 - cmd_params = (struct dpbp_cmd_set_irq *)cmd.params;
390 - cmd_params->irq_index = irq_index;
391 - cmd_params->irq_val = cpu_to_le32(irq_cfg->val);
392 - cmd_params->irq_addr = cpu_to_le64(irq_cfg->addr);
393 - cmd_params->irq_num = cpu_to_le32(irq_cfg->irq_num);
395 - /* send command to mc*/
396 - return mc_send_command(mc_io, &cmd);
400 - * dpbp_get_irq() - Get IRQ information from the DPBP.
401 - * @mc_io: Pointer to MC portal's I/O object
402 - * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
403 - * @token: Token of DPBP object
404 - * @irq_index: The interrupt index to configure
405 - * @type: Interrupt type: 0 represents message interrupt
406 - * type (both irq_addr and irq_val are valid)
407 - * @irq_cfg: IRQ attributes
409 - * Return: '0' on Success; Error code otherwise.
411 -int dpbp_get_irq(struct fsl_mc_io *mc_io,
416 - struct dpbp_irq_cfg *irq_cfg)
418 - struct mc_command cmd = { 0 };
419 - struct dpbp_cmd_get_irq *cmd_params;
420 - struct dpbp_rsp_get_irq *rsp_params;
423 - /* prepare command */
424 - cmd.header = mc_encode_cmd_header(DPBP_CMDID_GET_IRQ,
426 - cmd_params = (struct dpbp_cmd_get_irq *)cmd.params;
427 - cmd_params->irq_index = irq_index;
429 - /* send command to mc*/
430 - err = mc_send_command(mc_io, &cmd);
434 - /* retrieve response parameters */
435 - rsp_params = (struct dpbp_rsp_get_irq *)cmd.params;
436 - irq_cfg->val = le32_to_cpu(rsp_params->irq_val);
437 - irq_cfg->addr = le64_to_cpu(rsp_params->irq_addr);
438 - irq_cfg->irq_num = le32_to_cpu(rsp_params->irq_num);
439 - *type = le32_to_cpu(rsp_params->type);
445 - * dpbp_set_irq_enable() - Set overall interrupt state.
446 - * @mc_io: Pointer to MC portal's I/O object
447 - * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
448 - * @token: Token of DPBP object
449 - * @irq_index: The interrupt index to configure
450 - * @en: Interrupt state - enable = 1, disable = 0
452 - * Allows GPP software to control when interrupts are generated.
453 - * Each interrupt can have up to 32 causes. The enable/disable control's the
454 - * overall interrupt state. if the interrupt is disabled no causes will cause
457 - * Return: '0' on Success; Error code otherwise.
459 -int dpbp_set_irq_enable(struct fsl_mc_io *mc_io,
465 - struct mc_command cmd = { 0 };
466 - struct dpbp_cmd_set_irq_enable *cmd_params;
468 - /* prepare command */
469 - cmd.header = mc_encode_cmd_header(DPBP_CMDID_SET_IRQ_ENABLE,
471 - cmd_params = (struct dpbp_cmd_set_irq_enable *)cmd.params;
472 - cmd_params->enable = en & DPBP_ENABLE;
473 - cmd_params->irq_index = irq_index;
475 - /* send command to mc*/
476 - return mc_send_command(mc_io, &cmd);
480 - * dpbp_get_irq_enable() - Get overall interrupt state
481 - * @mc_io: Pointer to MC portal's I/O object
482 - * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
483 - * @token: Token of DPBP object
484 - * @irq_index: The interrupt index to configure
485 - * @en: Returned interrupt state - enable = 1, disable = 0
487 - * Return: '0' on Success; Error code otherwise.
489 -int dpbp_get_irq_enable(struct fsl_mc_io *mc_io,
495 - struct mc_command cmd = { 0 };
496 - struct dpbp_cmd_get_irq_enable *cmd_params;
497 - struct dpbp_rsp_get_irq_enable *rsp_params;
500 - /* prepare command */
501 - cmd.header = mc_encode_cmd_header(DPBP_CMDID_GET_IRQ_ENABLE,
503 - cmd_params = (struct dpbp_cmd_get_irq_enable *)cmd.params;
504 - cmd_params->irq_index = irq_index;
506 - /* send command to mc*/
507 - err = mc_send_command(mc_io, &cmd);
511 - /* retrieve response parameters */
512 - rsp_params = (struct dpbp_rsp_get_irq_enable *)cmd.params;
513 - *en = rsp_params->enabled & DPBP_ENABLE;
518 - * dpbp_set_irq_mask() - Set interrupt mask.
519 - * @mc_io: Pointer to MC portal's I/O object
520 - * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
521 - * @token: Token of DPBP object
522 - * @irq_index: The interrupt index to configure
523 - * @mask: Event mask to trigger interrupt;
526 - * 1 = consider event for asserting IRQ
528 - * Every interrupt can have up to 32 causes and the interrupt model supports
529 - * masking/unmasking each cause independently
531 - * Return: '0' on Success; Error code otherwise.
533 -int dpbp_set_irq_mask(struct fsl_mc_io *mc_io,
539 - struct mc_command cmd = { 0 };
540 - struct dpbp_cmd_set_irq_mask *cmd_params;
542 - /* prepare command */
543 - cmd.header = mc_encode_cmd_header(DPBP_CMDID_SET_IRQ_MASK,
545 - cmd_params = (struct dpbp_cmd_set_irq_mask *)cmd.params;
546 - cmd_params->mask = cpu_to_le32(mask);
547 - cmd_params->irq_index = irq_index;
549 - /* send command to mc*/
550 - return mc_send_command(mc_io, &cmd);
554 - * dpbp_get_irq_mask() - Get interrupt mask.
555 - * @mc_io: Pointer to MC portal's I/O object
556 - * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
557 - * @token: Token of DPBP object
558 - * @irq_index: The interrupt index to configure
559 - * @mask: Returned event mask to trigger interrupt
561 - * Every interrupt can have up to 32 causes and the interrupt model supports
562 - * masking/unmasking each cause independently
564 - * Return: '0' on Success; Error code otherwise.
566 -int dpbp_get_irq_mask(struct fsl_mc_io *mc_io,
572 - struct mc_command cmd = { 0 };
573 - struct dpbp_cmd_get_irq_mask *cmd_params;
574 - struct dpbp_rsp_get_irq_mask *rsp_params;
577 - /* prepare command */
578 - cmd.header = mc_encode_cmd_header(DPBP_CMDID_GET_IRQ_MASK,
580 - cmd_params = (struct dpbp_cmd_get_irq_mask *)cmd.params;
581 - cmd_params->irq_index = irq_index;
583 - /* send command to mc*/
584 - err = mc_send_command(mc_io, &cmd);
588 - /* retrieve response parameters */
589 - rsp_params = (struct dpbp_rsp_get_irq_mask *)cmd.params;
590 - *mask = le32_to_cpu(rsp_params->mask);
596 - * dpbp_get_irq_status() - Get the current status of any pending interrupts.
598 - * @mc_io: Pointer to MC portal's I/O object
599 - * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
600 - * @token: Token of DPBP object
601 - * @irq_index: The interrupt index to configure
602 - * @status: Returned interrupts status - one bit per cause:
603 - * 0 = no interrupt pending
604 - * 1 = interrupt pending
606 - * Return: '0' on Success; Error code otherwise.
608 -int dpbp_get_irq_status(struct fsl_mc_io *mc_io,
614 - struct mc_command cmd = { 0 };
615 - struct dpbp_cmd_get_irq_status *cmd_params;
616 - struct dpbp_rsp_get_irq_status *rsp_params;
619 - /* prepare command */
620 - cmd.header = mc_encode_cmd_header(DPBP_CMDID_GET_IRQ_STATUS,
622 - cmd_params = (struct dpbp_cmd_get_irq_status *)cmd.params;
623 - cmd_params->status = cpu_to_le32(*status);
624 - cmd_params->irq_index = irq_index;
626 - /* send command to mc*/
627 - err = mc_send_command(mc_io, &cmd);
631 - /* retrieve response parameters */
632 - rsp_params = (struct dpbp_rsp_get_irq_status *)cmd.params;
633 - *status = le32_to_cpu(rsp_params->status);
639 - * dpbp_clear_irq_status() - Clear a pending interrupt's status
641 - * @mc_io: Pointer to MC portal's I/O object
642 - * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
643 - * @token: Token of DPBP object
644 - * @irq_index: The interrupt index to configure
645 - * @status: Bits to clear (W1C) - one bit per cause:
647 - * 1 = clear status bit
649 - * Return: '0' on Success; Error code otherwise.
651 -int dpbp_clear_irq_status(struct fsl_mc_io *mc_io,
657 - struct mc_command cmd = { 0 };
658 - struct dpbp_cmd_clear_irq_status *cmd_params;
660 - /* prepare command */
661 - cmd.header = mc_encode_cmd_header(DPBP_CMDID_CLEAR_IRQ_STATUS,
663 - cmd_params = (struct dpbp_cmd_clear_irq_status *)cmd.params;
664 - cmd_params->status = cpu_to_le32(status);
665 - cmd_params->irq_index = irq_index;
667 - /* send command to mc*/
668 - return mc_send_command(mc_io, &cmd);
670 +EXPORT_SYMBOL(dpbp_reset);
673 * dpbp_get_attributes - Retrieve DPBP attributes.
674 @@ -609,83 +240,40 @@ int dpbp_get_attributes(struct fsl_mc_io
675 rsp_params = (struct dpbp_rsp_get_attributes *)cmd.params;
676 attr->bpid = le16_to_cpu(rsp_params->bpid);
677 attr->id = le32_to_cpu(rsp_params->id);
678 - attr->version.major = le16_to_cpu(rsp_params->version_major);
679 - attr->version.minor = le16_to_cpu(rsp_params->version_minor);
683 EXPORT_SYMBOL(dpbp_get_attributes);
686 - * dpbp_set_notifications() - Set notifications towards software
687 - * @mc_io: Pointer to MC portal's I/O object
688 + * dpbp_get_api_version - Get Data Path Buffer Pool API version
689 + * @mc_io: Pointer to Mc portal's I/O object
690 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
691 - * @token: Token of DPBP object
692 - * @cfg: notifications configuration
693 + * @major_ver: Major version of Buffer Pool API
694 + * @minor_ver: Minor version of Buffer Pool API
696 * Return: '0' on Success; Error code otherwise.
698 -int dpbp_set_notifications(struct fsl_mc_io *mc_io,
701 - struct dpbp_notification_cfg *cfg)
702 +int dpbp_get_api_version(struct fsl_mc_io *mc_io,
707 struct mc_command cmd = { 0 };
708 - struct dpbp_cmd_set_notifications *cmd_params;
710 - /* prepare command */
711 - cmd.header = mc_encode_cmd_header(DPBP_CMDID_SET_NOTIFICATIONS,
713 - cmd_params = (struct dpbp_cmd_set_notifications *)cmd.params;
714 - cmd_params->depletion_entry = cpu_to_le32(cfg->depletion_entry);
715 - cmd_params->depletion_exit = cpu_to_le32(cfg->depletion_exit);
716 - cmd_params->surplus_entry = cpu_to_le32(cfg->surplus_entry);
717 - cmd_params->surplus_exit = cpu_to_le32(cfg->surplus_exit);
718 - cmd_params->options = cpu_to_le16(cfg->options);
719 - cmd_params->message_ctx = cpu_to_le64(cfg->message_ctx);
720 - cmd_params->message_iova = cpu_to_le64(cfg->message_iova);
722 - /* send command to mc*/
723 - return mc_send_command(mc_io, &cmd);
727 - * dpbp_get_notifications() - Get the notifications configuration
728 - * @mc_io: Pointer to MC portal's I/O object
729 - * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
730 - * @token: Token of DPBP object
731 - * @cfg: notifications configuration
733 - * Return: '0' on Success; Error code otherwise.
735 -int dpbp_get_notifications(struct fsl_mc_io *mc_io,
738 - struct dpbp_notification_cfg *cfg)
740 - struct mc_command cmd = { 0 };
741 - struct dpbp_rsp_get_notifications *rsp_params;
744 /* prepare command */
745 - cmd.header = mc_encode_cmd_header(DPBP_CMDID_GET_NOTIFICATIONS,
748 + cmd.header = mc_encode_cmd_header(DPBP_CMDID_GET_API_VERSION,
751 - /* send command to mc*/
752 + /* send command to mc */
753 err = mc_send_command(mc_io, &cmd);
757 /* retrieve response parameters */
758 - rsp_params = (struct dpbp_rsp_get_notifications *)cmd.params;
759 - cfg->depletion_entry = le32_to_cpu(rsp_params->depletion_entry);
760 - cfg->depletion_exit = le32_to_cpu(rsp_params->depletion_exit);
761 - cfg->surplus_entry = le32_to_cpu(rsp_params->surplus_entry);
762 - cfg->surplus_exit = le32_to_cpu(rsp_params->surplus_exit);
763 - cfg->options = le16_to_cpu(rsp_params->options);
764 - cfg->message_ctx = le64_to_cpu(rsp_params->message_ctx);
765 - cfg->message_iova = le64_to_cpu(rsp_params->message_iova);
766 + mc_cmd_read_api_version(&cmd, major_ver, minor_ver);
770 +EXPORT_SYMBOL(dpbp_get_api_version);
772 +++ b/drivers/staging/fsl-mc/bus/dpcon-cmd.h
775 + * Copyright 2013-2016 Freescale Semiconductor Inc.
777 + * Redistribution and use in source and binary forms, with or without
778 + * modification, are permitted provided that the following conditions are met:
779 + * * Redistributions of source code must retain the above copyright
780 + * notice, this list of conditions and the following disclaimer.
781 + * * Redistributions in binary form must reproduce the above copyright
782 + * notice, this list of conditions and the following disclaimer in the
783 + * documentation and/or other materials provided with the distribution.
784 + * * Neither the name of the above-listed copyright holders nor the
785 + * names of any contributors may be used to endorse or promote products
786 + * derived from this software without specific prior written permission.
788 + * ALTERNATIVELY, this software may be distributed under the terms of the
789 + * GNU General Public License ("GPL") as published by the Free Software
790 + * Foundation, either version 2 of that License or (at your option) any
793 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
794 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
795 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
796 + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
797 + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
798 + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
799 + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
800 + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
801 + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
802 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
803 + * POSSIBILITY OF SUCH DAMAGE.
805 +#ifndef _FSL_DPCON_CMD_H
806 +#define _FSL_DPCON_CMD_H
809 +#define DPCON_VER_MAJOR 3
810 +#define DPCON_VER_MINOR 2
812 +/* Command versioning */
813 +#define DPCON_CMD_BASE_VERSION 1
814 +#define DPCON_CMD_ID_OFFSET 4
816 +#define DPCON_CMD(id) (((id) << DPCON_CMD_ID_OFFSET) | DPCON_CMD_BASE_VERSION)
819 +#define DPCON_CMDID_CLOSE DPCON_CMD(0x800)
820 +#define DPCON_CMDID_OPEN DPCON_CMD(0x808)
821 +#define DPCON_CMDID_GET_API_VERSION DPCON_CMD(0xa08)
823 +#define DPCON_CMDID_ENABLE DPCON_CMD(0x002)
824 +#define DPCON_CMDID_DISABLE DPCON_CMD(0x003)
825 +#define DPCON_CMDID_GET_ATTR DPCON_CMD(0x004)
826 +#define DPCON_CMDID_RESET DPCON_CMD(0x005)
827 +#define DPCON_CMDID_IS_ENABLED DPCON_CMD(0x006)
829 +#define DPCON_CMDID_SET_NOTIFICATION DPCON_CMD(0x100)
831 +struct dpcon_cmd_open {
835 +#define DPCON_ENABLE 1
837 +struct dpcon_rsp_is_enabled {
841 +struct dpcon_rsp_get_attr {
842 + /* response word 0 */
844 + __le16 qbman_ch_id;
849 +struct dpcon_cmd_set_notification {
858 +#endif /* _FSL_DPCON_CMD_H */
860 +++ b/drivers/staging/fsl-mc/bus/dpcon.c
862 +/* Copyright 2013-2016 Freescale Semiconductor Inc.
864 + * Redistribution and use in source and binary forms, with or without
865 + * modification, are permitted provided that the following conditions are met:
866 + * * Redistributions of source code must retain the above copyright
867 + * notice, this list of conditions and the following disclaimer.
868 + * * Redistributions in binary form must reproduce the above copyright
869 + * notice, this list of conditions and the following disclaimer in the
870 + * documentation and/or other materials provided with the distribution.
871 + * * Neither the name of the above-listed copyright holders nor the
872 + * names of any contributors may be used to endorse or promote products
873 + * derived from this software without specific prior written permission.
876 + * ALTERNATIVELY, this software may be distributed under the terms of the
877 + * GNU General Public License ("GPL") as published by the Free Software
878 + * Foundation, either version 2 of that License or (at your option) any
881 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
882 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
883 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
884 + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
885 + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
886 + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
887 + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
888 + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
889 + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
890 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
891 + * POSSIBILITY OF SUCH DAMAGE.
893 +#include "../include/mc-sys.h"
894 +#include "../include/mc-cmd.h"
895 +#include "../include/dpcon.h"
897 +#include "dpcon-cmd.h"
900 + * dpcon_open() - Open a control session for the specified object
901 + * @mc_io: Pointer to MC portal's I/O object
902 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
903 + * @dpcon_id: DPCON unique ID
904 + * @token: Returned token; use in subsequent API calls
906 + * This function can be used to open a control session for an
907 + * already created object; an object may have been declared in
908 + * the DPL or by calling the dpcon_create() function.
909 + * This function returns a unique authentication token,
910 + * associated with the specific object ID and the specific MC
911 + * portal; this token must be used in all subsequent commands for
912 + * this specific object.
914 + * Return: '0' on Success; Error code otherwise.
916 +int dpcon_open(struct fsl_mc_io *mc_io,
921 + struct mc_command cmd = { 0 };
922 + struct dpcon_cmd_open *dpcon_cmd;
925 + /* prepare command */
926 + cmd.header = mc_encode_cmd_header(DPCON_CMDID_OPEN,
929 + dpcon_cmd = (struct dpcon_cmd_open *)cmd.params;
930 + dpcon_cmd->dpcon_id = cpu_to_le32(dpcon_id);
932 + /* send command to mc*/
933 + err = mc_send_command(mc_io, &cmd);
937 + /* retrieve response parameters */
938 + *token = mc_cmd_hdr_read_token(&cmd);
942 +EXPORT_SYMBOL(dpcon_open);
945 + * dpcon_close() - Close the control session of the object
946 + * @mc_io: Pointer to MC portal's I/O object
947 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
948 + * @token: Token of DPCON object
950 + * After this function is called, no further operations are
951 + * allowed on the object without opening a new control session.
953 + * Return: '0' on Success; Error code otherwise.
955 +int dpcon_close(struct fsl_mc_io *mc_io,
959 + struct mc_command cmd = { 0 };
961 + /* prepare command */
962 + cmd.header = mc_encode_cmd_header(DPCON_CMDID_CLOSE,
966 + /* send command to mc*/
967 + return mc_send_command(mc_io, &cmd);
969 +EXPORT_SYMBOL(dpcon_close);
972 + * dpcon_enable() - Enable the DPCON
973 + * @mc_io: Pointer to MC portal's I/O object
974 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
975 + * @token: Token of DPCON object
977 + * Return: '0' on Success; Error code otherwise
979 +int dpcon_enable(struct fsl_mc_io *mc_io,
983 + struct mc_command cmd = { 0 };
985 + /* prepare command */
986 + cmd.header = mc_encode_cmd_header(DPCON_CMDID_ENABLE,
990 + /* send command to mc*/
991 + return mc_send_command(mc_io, &cmd);
993 +EXPORT_SYMBOL(dpcon_enable);
996 + * dpcon_disable() - Disable the DPCON
997 + * @mc_io: Pointer to MC portal's I/O object
998 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
999 + * @token: Token of DPCON object
1001 + * Return: '0' on Success; Error code otherwise
1003 +int dpcon_disable(struct fsl_mc_io *mc_io,
1007 + struct mc_command cmd = { 0 };
1009 + /* prepare command */
1010 + cmd.header = mc_encode_cmd_header(DPCON_CMDID_DISABLE,
1014 + /* send command to mc*/
1015 + return mc_send_command(mc_io, &cmd);
1017 +EXPORT_SYMBOL(dpcon_disable);
1020 + * dpcon_is_enabled() - Check if the DPCON is enabled.
1021 + * @mc_io: Pointer to MC portal's I/O object
1022 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1023 + * @token: Token of DPCON object
1024 + * @en: Returns '1' if object is enabled; '0' otherwise
1026 + * Return: '0' on Success; Error code otherwise.
1028 +int dpcon_is_enabled(struct fsl_mc_io *mc_io,
1033 + struct mc_command cmd = { 0 };
1034 + struct dpcon_rsp_is_enabled *dpcon_rsp;
1037 + /* prepare command */
1038 + cmd.header = mc_encode_cmd_header(DPCON_CMDID_IS_ENABLED,
1042 + /* send command to mc*/
1043 + err = mc_send_command(mc_io, &cmd);
1047 + /* retrieve response parameters */
1048 + dpcon_rsp = (struct dpcon_rsp_is_enabled *)cmd.params;
1049 + *en = dpcon_rsp->enabled & DPCON_ENABLE;
1053 +EXPORT_SYMBOL(dpcon_is_enabled);
1056 + * dpcon_reset() - Reset the DPCON, returns the object to initial state.
1057 + * @mc_io: Pointer to MC portal's I/O object
1058 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1059 + * @token: Token of DPCON object
1061 + * Return: '0' on Success; Error code otherwise.
1063 +int dpcon_reset(struct fsl_mc_io *mc_io,
1067 + struct mc_command cmd = { 0 };
1069 + /* prepare command */
1070 + cmd.header = mc_encode_cmd_header(DPCON_CMDID_RESET,
1071 + cmd_flags, token);
1073 + /* send command to mc*/
1074 + return mc_send_command(mc_io, &cmd);
1076 +EXPORT_SYMBOL(dpcon_reset);
1079 + * dpcon_get_attributes() - Retrieve DPCON attributes.
1080 + * @mc_io: Pointer to MC portal's I/O object
1081 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1082 + * @token: Token of DPCON object
1083 + * @attr: Object's attributes
1085 + * Return: '0' on Success; Error code otherwise.
1087 +int dpcon_get_attributes(struct fsl_mc_io *mc_io,
1090 + struct dpcon_attr *attr)
1092 + struct mc_command cmd = { 0 };
1093 + struct dpcon_rsp_get_attr *dpcon_rsp;
1096 + /* prepare command */
1097 + cmd.header = mc_encode_cmd_header(DPCON_CMDID_GET_ATTR,
1101 + /* send command to mc*/
1102 + err = mc_send_command(mc_io, &cmd);
1106 + /* retrieve response parameters */
1107 + dpcon_rsp = (struct dpcon_rsp_get_attr *)cmd.params;
1108 + attr->id = le32_to_cpu(dpcon_rsp->id);
1109 + attr->qbman_ch_id = le16_to_cpu(dpcon_rsp->qbman_ch_id);
1110 + attr->num_priorities = dpcon_rsp->num_priorities;
1114 +EXPORT_SYMBOL(dpcon_get_attributes);
1117 + * dpcon_set_notification() - Set DPCON notification destination
1118 + * @mc_io: Pointer to MC portal's I/O object
1119 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1120 + * @token: Token of DPCON object
1121 + * @cfg: Notification parameters
1123 + * Return: '0' on Success; Error code otherwise
1125 +int dpcon_set_notification(struct fsl_mc_io *mc_io,
1128 + struct dpcon_notification_cfg *cfg)
1130 + struct mc_command cmd = { 0 };
1131 + struct dpcon_cmd_set_notification *dpcon_cmd;
1133 + /* prepare command */
1134 + cmd.header = mc_encode_cmd_header(DPCON_CMDID_SET_NOTIFICATION,
1137 + dpcon_cmd = (struct dpcon_cmd_set_notification *)cmd.params;
1138 + dpcon_cmd->dpio_id = cpu_to_le32(cfg->dpio_id);
1139 + dpcon_cmd->priority = cfg->priority;
1140 + dpcon_cmd->user_ctx = cpu_to_le64(cfg->user_ctx);
1142 + /* send command to mc*/
1143 + return mc_send_command(mc_io, &cmd);
1145 +EXPORT_SYMBOL(dpcon_set_notification);
1148 + * dpcon_get_api_version - Get Data Path Concentrator API version
1149 + * @mc_io: Pointer to MC portal's DPCON object
1150 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1151 + * @major_ver: Major version of DPCON API
1152 + * @minor_ver: Minor version of DPCON API
1154 + * Return: '0' on Success; Error code otherwise
1156 +int dpcon_get_api_version(struct fsl_mc_io *mc_io,
1161 + struct mc_command cmd = { 0 };
1164 + /* prepare command */
1165 + cmd.header = mc_encode_cmd_header(DPCON_CMDID_GET_API_VERSION,
1168 + /* send command to mc */
1169 + err = mc_send_command(mc_io, &cmd);
1173 + /* retrieve response parameters */
1174 + mc_cmd_read_api_version(&cmd, major_ver, minor_ver);
1178 +EXPORT_SYMBOL(dpcon_get_api_version);
1180 +++ b/drivers/staging/fsl-mc/bus/dpio/Makefile
1183 +# QorIQ DPAA2 DPIO driver
1186 +subdir-ccflags-y := -Werror
1188 +obj-$(CONFIG_FSL_MC_DPIO) += fsl-mc-dpio.o
1190 +fsl-mc-dpio-objs := dpio.o qbman-portal.o dpio-service.o dpio-driver.o
1192 +obj-$(CONFIG_FSL_QBMAN_DEBUG) += qbman_debug.o
1193 --- a/drivers/staging/fsl-mc/include/dpcon-cmd.h
1196 -/* Copyright 2013-2015 Freescale Semiconductor Inc.
1198 - * Redistribution and use in source and binary forms, with or without
1199 - * modification, are permitted provided that the following conditions are met:
1200 - * * Redistributions of source code must retain the above copyright
1201 - * notice, this list of conditions and the following disclaimer.
1202 - * * Redistributions in binary form must reproduce the above copyright
1203 - * notice, this list of conditions and the following disclaimer in the
1204 - * documentation and/or other materials provided with the distribution.
1205 - * * Neither the name of the above-listed copyright holders nor the
1206 - * names of any contributors may be used to endorse or promote products
1207 - * derived from this software without specific prior written permission.
1210 - * ALTERNATIVELY, this software may be distributed under the terms of the
1211 - * GNU General Public License ("GPL") as published by the Free Software
1212 - * Foundation, either version 2 of that License or (at your option) any
1215 - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
1216 - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1217 - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1218 - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
1219 - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
1220 - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
1221 - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
1222 - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
1223 - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
1224 - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
1225 - * POSSIBILITY OF SUCH DAMAGE.
1227 -#ifndef _FSL_DPCON_CMD_H
1228 -#define _FSL_DPCON_CMD_H
1230 -/* DPCON Version */
1231 -#define DPCON_VER_MAJOR 2
1232 -#define DPCON_VER_MINOR 1
1235 -#define DPCON_CMDID_CLOSE 0x800
1236 -#define DPCON_CMDID_OPEN 0x808
1237 -#define DPCON_CMDID_CREATE 0x908
1238 -#define DPCON_CMDID_DESTROY 0x900
1240 -#define DPCON_CMDID_ENABLE 0x002
1241 -#define DPCON_CMDID_DISABLE 0x003
1242 -#define DPCON_CMDID_GET_ATTR 0x004
1243 -#define DPCON_CMDID_RESET 0x005
1244 -#define DPCON_CMDID_IS_ENABLED 0x006
1246 -#define DPCON_CMDID_SET_IRQ 0x010
1247 -#define DPCON_CMDID_GET_IRQ 0x011
1248 -#define DPCON_CMDID_SET_IRQ_ENABLE 0x012
1249 -#define DPCON_CMDID_GET_IRQ_ENABLE 0x013
1250 -#define DPCON_CMDID_SET_IRQ_MASK 0x014
1251 -#define DPCON_CMDID_GET_IRQ_MASK 0x015
1252 -#define DPCON_CMDID_GET_IRQ_STATUS 0x016
1253 -#define DPCON_CMDID_CLEAR_IRQ_STATUS 0x017
1255 -#define DPCON_CMDID_SET_NOTIFICATION 0x100
1257 -#endif /* _FSL_DPCON_CMD_H */
1259 +++ b/drivers/staging/fsl-mc/bus/dpio/dpio-cmd.h
1262 + * Copyright 2013-2016 Freescale Semiconductor Inc.
1263 + * Copyright 2016 NXP
1265 + * Redistribution and use in source and binary forms, with or without
1266 + * modification, are permitted provided that the following conditions are met:
1267 + * * Redistributions of source code must retain the above copyright
1268 + * notice, this list of conditions and the following disclaimer.
1269 + * * Redistributions in binary form must reproduce the above copyright
1270 + * notice, this list of conditions and the following disclaimer in the
1271 + * documentation and/or other materials provided with the distribution.
1272 + * * Neither the name of the above-listed copyright holders nor the
1273 + * names of any contributors may be used to endorse or promote products
1274 + * derived from this software without specific prior written permission.
1276 + * ALTERNATIVELY, this software may be distributed under the terms of the
1277 + * GNU General Public License ("GPL") as published by the Free Software
1278 + * Foundation, either version 2 of that License or (at your option) any
1281 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
1282 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1283 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1284 + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
1285 + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
1286 + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
1287 + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
1288 + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
1289 + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
1290 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
1291 + * POSSIBILITY OF SUCH DAMAGE.
1293 +#ifndef _FSL_DPIO_CMD_H
1294 +#define _FSL_DPIO_CMD_H
1297 +#define DPIO_VER_MAJOR 4
1298 +#define DPIO_VER_MINOR 2
1300 +/* Command Versioning */
1302 +#define DPIO_CMD_ID_OFFSET 4
1303 +#define DPIO_CMD_BASE_VERSION 1
1305 +#define DPIO_CMD(id) (((id) << DPIO_CMD_ID_OFFSET) | DPIO_CMD_BASE_VERSION)
1308 +#define DPIO_CMDID_CLOSE DPIO_CMD(0x800)
1309 +#define DPIO_CMDID_OPEN DPIO_CMD(0x803)
1310 +#define DPIO_CMDID_GET_API_VERSION DPIO_CMD(0xa03)
1311 +#define DPIO_CMDID_ENABLE DPIO_CMD(0x002)
1312 +#define DPIO_CMDID_DISABLE DPIO_CMD(0x003)
1313 +#define DPIO_CMDID_GET_ATTR DPIO_CMD(0x004)
1315 +struct dpio_cmd_open {
1319 +#define DPIO_CHANNEL_MODE_MASK 0x3
1321 +struct dpio_rsp_get_attr {
1324 + __le16 qbman_portal_id;
1325 + u8 num_priorities;
1328 + __le64 qbman_portal_ce_addr;
1330 + __le64 qbman_portal_ci_addr;
1332 + __le32 qbman_version;
1335 +#endif /* _FSL_DPIO_CMD_H */
1337 +++ b/drivers/staging/fsl-mc/bus/dpio/dpio-driver.c
1340 + * Copyright 2014-2016 Freescale Semiconductor Inc.
1341 + * Copyright 2016 NXP
1343 + * Redistribution and use in source and binary forms, with or without
1344 + * modification, are permitted provided that the following conditions are met:
1345 + * * Redistributions of source code must retain the above copyright
1346 + * notice, this list of conditions and the following disclaimer.
1347 + * * Redistributions in binary form must reproduce the above copyright
1348 + * notice, this list of conditions and the following disclaimer in the
1349 + * documentation and/or other materials provided with the distribution.
1350 + * * Neither the name of Freescale Semiconductor nor the
1351 + * names of its contributors may be used to endorse or promote products
1352 + * derived from this software without specific prior written permission.
1354 + * ALTERNATIVELY, this software may be distributed under the terms of the
1355 + * GNU General Public License ("GPL") as published by the Free Software
1356 + * Foundation, either version 2 of that License or (at your option) any
1359 + * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
1360 + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
1361 + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
1362 + * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
1363 + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
1364 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
1365 + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
1366 + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
1367 + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
1368 + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1371 +#include <linux/types.h>
1372 +#include <linux/init.h>
1373 +#include <linux/module.h>
1374 +#include <linux/platform_device.h>
1375 +#include <linux/interrupt.h>
1376 +#include <linux/msi.h>
1377 +#include <linux/dma-mapping.h>
1378 +#include <linux/delay.h>
1380 +#include "../../include/mc.h"
1381 +#include "../../include/dpaa2-io.h"
1383 +#include "qbman-portal.h"
1385 +#include "dpio-cmd.h"
1387 +MODULE_LICENSE("Dual BSD/GPL");
1388 +MODULE_AUTHOR("Freescale Semiconductor, Inc");
1389 +MODULE_DESCRIPTION("DPIO Driver");
1392 + struct dpaa2_io *io;
1395 +static irqreturn_t dpio_irq_handler(int irq_num, void *arg)
1397 + struct device *dev = (struct device *)arg;
1398 + struct dpio_priv *priv = dev_get_drvdata(dev);
1400 + return dpaa2_io_irq(priv->io);
1403 +static void unregister_dpio_irq_handlers(struct fsl_mc_device *dpio_dev)
1405 + struct fsl_mc_device_irq *irq;
1407 + irq = dpio_dev->irqs[0];
1409 + /* clear the affinity hint */
1410 + irq_set_affinity_hint(irq->msi_desc->irq, NULL);
1413 +static int register_dpio_irq_handlers(struct fsl_mc_device *dpio_dev, int cpu)
1415 + struct dpio_priv *priv;
1417 + struct fsl_mc_device_irq *irq;
1420 + priv = dev_get_drvdata(&dpio_dev->dev);
1422 + irq = dpio_dev->irqs[0];
1423 + error = devm_request_irq(&dpio_dev->dev,
1424 + irq->msi_desc->irq,
1427 + dev_name(&dpio_dev->dev),
1430 + dev_err(&dpio_dev->dev,
1431 + "devm_request_irq() failed: %d\n",
1436 + /* set the affinity hint */
1437 + cpumask_clear(&mask);
1438 + cpumask_set_cpu(cpu, &mask);
1439 + if (irq_set_affinity_hint(irq->msi_desc->irq, &mask))
1440 + dev_err(&dpio_dev->dev,
1441 + "irq_set_affinity failed irq %d cpu %d\n",
1442 + irq->msi_desc->irq, cpu);
1447 +static int dpaa2_dpio_probe(struct fsl_mc_device *dpio_dev)
1449 + struct dpio_attr dpio_attrs;
1450 + struct dpaa2_io_desc desc;
1451 + struct dpio_priv *priv;
1452 + int err = -ENOMEM;
1453 + struct device *dev = &dpio_dev->dev;
1454 + static int next_cpu = -1;
1456 + priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
1458 + goto err_priv_alloc;
1460 + dev_set_drvdata(dev, priv);
1462 + err = fsl_mc_portal_allocate(dpio_dev, 0, &dpio_dev->mc_io);
1464 + dev_dbg(dev, "MC portal allocation failed\n");
1465 + err = -EPROBE_DEFER;
1466 + goto err_mcportal;
1469 + err = dpio_open(dpio_dev->mc_io, 0, dpio_dev->obj_desc.id,
1470 + &dpio_dev->mc_handle);
1472 + dev_err(dev, "dpio_open() failed\n");
1476 + err = dpio_get_attributes(dpio_dev->mc_io, 0, dpio_dev->mc_handle,
1479 + dev_err(dev, "dpio_get_attributes() failed %d\n", err);
1480 + goto err_get_attr;
1482 + desc.qman_version = dpio_attrs.qbman_version;
1484 + err = dpio_enable(dpio_dev->mc_io, 0, dpio_dev->mc_handle);
1486 + dev_err(dev, "dpio_enable() failed %d\n", err);
1487 + goto err_get_attr;
1490 + /* initialize DPIO descriptor */
1491 + desc.receives_notifications = dpio_attrs.num_priorities ? 1 : 0;
1492 + desc.has_8prio = dpio_attrs.num_priorities == 8 ? 1 : 0;
1493 + desc.dpio_id = dpio_dev->obj_desc.id;
1495 + /* get the cpu to use for the affinity hint */
1496 + if (next_cpu == -1)
1497 + next_cpu = cpumask_first(cpu_online_mask);
1499 + next_cpu = cpumask_next(next_cpu, cpu_online_mask);
1501 + if (!cpu_possible(next_cpu)) {
1502 + dev_err(dev, "probe failed. Number of DPIOs exceeds NR_CPUS.\n");
1504 + goto err_allocate_irqs;
1506 + desc.cpu = next_cpu;
1509 + * Set the CENA regs to be the cache enabled area of the portal to
1510 + * achieve the best performance.
1512 + desc.regs_cena = ioremap_cache_ns(dpio_dev->regions[0].start,
1513 + resource_size(&dpio_dev->regions[0]));
1514 + desc.regs_cinh = ioremap(dpio_dev->regions[1].start,
1515 + resource_size(&dpio_dev->regions[1]));
1517 + err = fsl_mc_allocate_irqs(dpio_dev);
1519 + dev_err(dev, "fsl_mc_allocate_irqs failed. err=%d\n", err);
1520 + goto err_allocate_irqs;
1523 + err = register_dpio_irq_handlers(dpio_dev, desc.cpu);
1525 + goto err_register_dpio_irq;
1527 + priv->io = dpaa2_io_create(&desc);
1529 + dev_err(dev, "dpaa2_io_create failed\n");
1530 + goto err_dpaa2_io_create;
1533 + dev_info(dev, "probed\n");
1534 + dev_dbg(dev, " receives_notifications = %d\n",
1535 + desc.receives_notifications);
1536 + dpio_close(dpio_dev->mc_io, 0, dpio_dev->mc_handle);
1537 + fsl_mc_portal_free(dpio_dev->mc_io);
1541 +err_dpaa2_io_create:
1542 + unregister_dpio_irq_handlers(dpio_dev);
1543 +err_register_dpio_irq:
1544 + fsl_mc_free_irqs(dpio_dev);
1546 + dpio_disable(dpio_dev->mc_io, 0, dpio_dev->mc_handle);
1548 + dpio_close(dpio_dev->mc_io, 0, dpio_dev->mc_handle);
1550 + fsl_mc_portal_free(dpio_dev->mc_io);
1552 + dev_set_drvdata(dev, NULL);
1557 +/* Tear down interrupts for a given DPIO object */
1558 +static void dpio_teardown_irqs(struct fsl_mc_device *dpio_dev)
1560 + unregister_dpio_irq_handlers(dpio_dev);
1561 + fsl_mc_free_irqs(dpio_dev);
1564 +static int dpaa2_dpio_remove(struct fsl_mc_device *dpio_dev)
1566 + struct device *dev;
1567 + struct dpio_priv *priv;
1570 + dev = &dpio_dev->dev;
1571 + priv = dev_get_drvdata(dev);
1573 + dpaa2_io_down(priv->io);
1575 + dpio_teardown_irqs(dpio_dev);
1577 + err = fsl_mc_portal_allocate(dpio_dev, 0, &dpio_dev->mc_io);
1579 + dev_err(dev, "MC portal allocation failed\n");
1580 + goto err_mcportal;
1583 + err = dpio_open(dpio_dev->mc_io, 0, dpio_dev->obj_desc.id,
1584 + &dpio_dev->mc_handle);
1586 + dev_err(dev, "dpio_open() failed\n");
1590 + dpio_disable(dpio_dev->mc_io, 0, dpio_dev->mc_handle);
1592 + dpio_close(dpio_dev->mc_io, 0, dpio_dev->mc_handle);
1594 + fsl_mc_portal_free(dpio_dev->mc_io);
1596 + dev_set_drvdata(dev, NULL);
1601 + fsl_mc_portal_free(dpio_dev->mc_io);
1606 +static const struct fsl_mc_device_id dpaa2_dpio_match_id_table[] = {
1608 + .vendor = FSL_MC_VENDOR_FREESCALE,
1609 + .obj_type = "dpio",
1614 +static struct fsl_mc_driver dpaa2_dpio_driver = {
1616 + .name = KBUILD_MODNAME,
1617 + .owner = THIS_MODULE,
1619 + .probe = dpaa2_dpio_probe,
1620 + .remove = dpaa2_dpio_remove,
1621 + .match_id_table = dpaa2_dpio_match_id_table
1624 +static int dpio_driver_init(void)
1626 + return fsl_mc_driver_register(&dpaa2_dpio_driver);
1629 +static void dpio_driver_exit(void)
1631 + fsl_mc_driver_unregister(&dpaa2_dpio_driver);
1633 +module_init(dpio_driver_init);
1634 +module_exit(dpio_driver_exit);
1636 +++ b/drivers/staging/fsl-mc/bus/dpio/dpio-driver.txt
1643 +A DPAA2 DPIO (Data Path I/O) is a hardware object that provides
1644 +interfaces to enqueue and dequeue frames to/from network interfaces
1645 +and other accelerators. A DPIO also provides hardware buffer
1646 +pool management for network interfaces.
1648 +This document provides an overview the Linux DPIO driver, its
1649 +subcomponents, and its APIs.
1651 +See Documentation/dpaa2/overview.txt for a general overview of DPAA2
1652 +and the general DPAA2 driver architecture in Linux.
1657 +The DPIO driver is bound to DPIO objects discovered on the fsl-mc bus and
1658 +provides services that:
1659 + A) allow other drivers, such as the Ethernet driver, to enqueue and dequeue
1660 + frames for their respective objects
1661 + B) allow drivers to register callbacks for data availability notifications
1662 + when data becomes available on a queue or channel
1663 + C) allow drivers to manage hardware buffer pools
1665 +The Linux DPIO driver consists of 3 primary components--
1666 + DPIO object driver-- fsl-mc driver that manages the DPIO object
1667 + DPIO service-- provides APIs to other Linux drivers for services
1668 + QBman portal interface-- sends portal commands, gets responses
1673 + +---+----+ +------+-----+
1674 + |DPIO obj| |DPIO service|
1675 + | driver |---| (DPIO) |
1676 + +--------+ +------+-----+
1685 +The diagram below shows how the DPIO driver components fit with the other
1686 +DPAA2 Linux driver components:
1690 + +------------+ +------------+
1691 + | Allocator |. . . . . . . | Ethernet |
1692 + |(DPMCP,DPBP)| | (DPNI) |
1693 + +-.----------+ +---+---+----+
1695 + . . <data avail, | |<enqueue,
1696 + . . tx confirm> | | dequeue>
1697 + +-------------+ . | |
1698 + | DPRC driver | . +--------+ +------------+
1699 + | (DPRC) | . . |DPIO obj| |DPIO service|
1700 + +----------+--+ | driver |-| (DPIO) |
1701 + | +--------+ +------+-----+
1702 + |<dev add/remove> +------|-----+
1704 + +----+--------------+ | portal i/f |
1705 + | MC-bus driver | +------------+
1708 + +-------------------+ |
1710 + =========================================|=========|========================
1711 + +-+--DPIO---|-----------+
1714 + +-----------------------+
1716 + ============================================================================
1719 +DPIO Object Driver (dpio-driver.c)
1720 +----------------------------------
1722 + The dpio-driver component registers with the fsl-mc bus to handle objects of
1723 + type "dpio". The implementation of probe() handles basic initialization
1724 + of the DPIO including mapping of the DPIO regions (the QBman SW portal)
1725 + and initializing interrupts and registering irq handlers. The dpio-driver
1726 + registers the probed DPIO with dpio-service.
1728 +DPIO service (dpio-service.c, dpaa2-io.h)
1729 +------------------------------------------
1731 + The dpio service component provides queuing, notification, and buffers
1732 + management services to DPAA2 drivers, such as the Ethernet driver. A system
1733 + will typically allocate 1 DPIO object per CPU to allow queuing operations
1734 + to happen simultaneously across all CPUs.
1736 + Notification handling
1737 + dpaa2_io_service_register()
1738 + dpaa2_io_service_deregister()
1739 + dpaa2_io_service_rearm()
1742 + dpaa2_io_service_pull_fq()
1743 + dpaa2_io_service_pull_channel()
1744 + dpaa2_io_service_enqueue_fq()
1745 + dpaa2_io_service_enqueue_qd()
1746 + dpaa2_io_store_create()
1747 + dpaa2_io_store_destroy()
1748 + dpaa2_io_store_next()
1750 + Buffer pool management
1751 + dpaa2_io_service_release()
1752 + dpaa2_io_service_acquire()
1754 +QBman portal interface (qbman-portal.c)
1755 +---------------------------------------
1757 + The qbman-portal component provides APIs to do the low level hardware
1758 + bit twiddling for operations such as:
1759 + -initializing Qman software portals
1760 + -building and sending portal commands
1761 + -portal interrupt configuration and processing
1763 + The qbman-portal APIs are not public to other drivers, and are
1764 + only used by dpio-service.
1766 +Other (dpaa2-fd.h, dpaa2-global.h)
1767 +----------------------------------
1769 + Frame descriptor and scatter-gather definitions and the APIs used to
1770 + manipulate them are defined in dpaa2-fd.h.
1772 + Dequeue result struct and parsing APIs are defined in dpaa2-global.h.
1774 +++ b/drivers/staging/fsl-mc/bus/dpio/dpio-service.c
1777 + * Copyright 2014-2016 Freescale Semiconductor Inc.
1778 + * Copyright 2016 NXP
1780 + * Redistribution and use in source and binary forms, with or without
1781 + * modification, are permitted provided that the following conditions are met:
1782 + * * Redistributions of source code must retain the above copyright
1783 + * notice, this list of conditions and the following disclaimer.
1784 + * * Redistributions in binary form must reproduce the above copyright
1785 + * notice, this list of conditions and the following disclaimer in the
1786 + * documentation and/or other materials provided with the distribution.
1787 + * * Neither the name of Freescale Semiconductor nor the
1788 + * names of its contributors may be used to endorse or promote products
1789 + * derived from this software without specific prior written permission.
1791 + * ALTERNATIVELY, this software may be distributed under the terms of the
1792 + * GNU General Public License ("GPL") as published by the Free Software
1793 + * Foundation, either version 2 of that License or (at your option) any
1796 + * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
1797 + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
1798 + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
1799 + * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
1800 + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
1801 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
1802 + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
1803 + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
1804 + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
1805 + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1807 +#include <linux/types.h>
1808 +#include "../../include/mc.h"
1809 +#include "../../include/dpaa2-io.h"
1810 +#include <linux/init.h>
1811 +#include <linux/module.h>
1812 +#include <linux/platform_device.h>
1813 +#include <linux/interrupt.h>
1814 +#include <linux/dma-mapping.h>
1815 +#include <linux/slab.h>
1818 +#include "qbman-portal.h"
1819 +#include "qbman_debug.h"
1823 + struct dpaa2_io_desc dpio_desc;
1824 + struct qbman_swp_desc swp_desc;
1825 + struct qbman_swp *swp;
1826 + struct list_head node;
1827 + /* protect against multiple management commands */
1828 + spinlock_t lock_mgmt_cmd;
1829 + /* protect notifications list */
1830 + spinlock_t lock_notifications;
1831 + struct list_head notifications;
1834 +struct dpaa2_io_store {
1837 + struct dpaa2_dq *vaddr;
1838 + void *alloced_addr; /* unaligned value from kmalloc() */
1839 + unsigned int idx; /* position of the next-to-be-returned entry */
1840 + struct qbman_swp *swp; /* portal used to issue VDQCR */
1841 + struct device *dev; /* device used for DMA mapping */
1844 +/* keep a per cpu array of DPIOs for fast access */
1845 +static struct dpaa2_io *dpio_by_cpu[NR_CPUS];
1846 +static struct list_head dpio_list = LIST_HEAD_INIT(dpio_list);
1847 +static DEFINE_SPINLOCK(dpio_list_lock);
1849 +static inline struct dpaa2_io *service_select_by_cpu(struct dpaa2_io *d,
1855 + if (unlikely(cpu >= (int)num_possible_cpus()))
1859 + * If cpu == -1, choose the current cpu, with no guarantees about
1860 + * potentially being migrated away.
1863 + cpu = smp_processor_id();
1865 + /* If a specific cpu was requested, pick it up immediately */
1866 + return dpio_by_cpu[cpu];
1869 +static inline struct dpaa2_io *service_select(struct dpaa2_io *d)
1874 + d = service_select_by_cpu(d, -1);
1878 + spin_lock(&dpio_list_lock);
1879 + d = list_entry(dpio_list.next, struct dpaa2_io, node);
1880 + list_del(&d->node);
1881 + list_add_tail(&d->node, &dpio_list);
1882 + spin_unlock(&dpio_list_lock);
1888 + * dpaa2_io_create() - create a dpaa2_io object.
1889 + * @desc: the dpaa2_io descriptor
1891 + * Activates a "struct dpaa2_io" corresponding to the given config of an actual
1894 + * Return a valid dpaa2_io object for success, or NULL for failure.
1896 +struct dpaa2_io *dpaa2_io_create(const struct dpaa2_io_desc *desc)
1898 + struct dpaa2_io *obj = kmalloc(sizeof(*obj), GFP_KERNEL);
1903 + /* check if CPU is out of range (-1 means any cpu) */
1904 + if (desc->cpu >= (int)num_possible_cpus()) {
1909 + atomic_set(&obj->refs, 1);
1910 + obj->dpio_desc = *desc;
1911 + obj->swp_desc.cena_bar = obj->dpio_desc.regs_cena;
1912 + obj->swp_desc.cinh_bar = obj->dpio_desc.regs_cinh;
1913 + obj->swp_desc.qman_version = obj->dpio_desc.qman_version;
1914 + obj->swp = qbman_swp_init(&obj->swp_desc);
1921 + INIT_LIST_HEAD(&obj->node);
1922 + spin_lock_init(&obj->lock_mgmt_cmd);
1923 + spin_lock_init(&obj->lock_notifications);
1924 + INIT_LIST_HEAD(&obj->notifications);
1926 + /* For now only enable DQRR interrupts */
1927 + qbman_swp_interrupt_set_trigger(obj->swp,
1928 + QBMAN_SWP_INTERRUPT_DQRI);
1929 + qbman_swp_interrupt_clear_status(obj->swp, 0xffffffff);
1930 + if (obj->dpio_desc.receives_notifications)
1931 + qbman_swp_push_set(obj->swp, 0, 1);
1933 + spin_lock(&dpio_list_lock);
1934 + list_add_tail(&obj->node, &dpio_list);
1935 + if (desc->cpu >= 0 && !dpio_by_cpu[desc->cpu])
1936 + dpio_by_cpu[desc->cpu] = obj;
1937 + spin_unlock(&dpio_list_lock);
1941 +EXPORT_SYMBOL(dpaa2_io_create);
1944 + * dpaa2_io_down() - release the dpaa2_io object.
1945 + * @d: the dpaa2_io object to be released.
1947 + * The "struct dpaa2_io" type can represent an individual DPIO object (as
1948 + * described by "struct dpaa2_io_desc") or an instance of a "DPIO service",
1949 + * which can be used to group/encapsulate multiple DPIO objects. In all cases,
1950 + * each handle obtained should be released using this function.
1952 +void dpaa2_io_down(struct dpaa2_io *d)
1954 + if (!atomic_dec_and_test(&d->refs))
1958 +EXPORT_SYMBOL(dpaa2_io_down);
1960 +#define DPAA_POLL_MAX 32
1963 + * dpaa2_io_irq() - ISR for DPIO interrupts
1965 + * @obj: the given DPIO object.
1967 + * Return IRQ_HANDLED for success or IRQ_NONE if there
1968 + * were no pending interrupts.
1970 +irqreturn_t dpaa2_io_irq(struct dpaa2_io *obj)
1972 + const struct dpaa2_dq *dq;
1974 + struct qbman_swp *swp;
1978 + status = qbman_swp_interrupt_read_status(swp);
1982 + dq = qbman_swp_dqrr_next(swp);
1984 + if (qbman_result_is_SCN(dq)) {
1985 + struct dpaa2_io_notification_ctx *ctx;
1988 + q64 = qbman_result_SCN_ctx(dq);
1989 + ctx = (void *)q64;
1992 + pr_crit("fsl-mc-dpio: Unrecognised/ignored DQRR entry\n");
1994 + qbman_swp_dqrr_consume(swp, dq);
1996 + if (max > DPAA_POLL_MAX)
1998 + dq = qbman_swp_dqrr_next(swp);
2001 + qbman_swp_interrupt_clear_status(swp, status);
2002 + qbman_swp_interrupt_set_inhibit(swp, 0);
2003 + return IRQ_HANDLED;
2005 +EXPORT_SYMBOL(dpaa2_io_irq);
2008 + * dpaa2_io_service_register() - Prepare for servicing of FQDAN or CDAN
2009 + * notifications on the given DPIO service.
2010 + * @d: the given DPIO service.
2011 + * @ctx: the notification context.
2013 + * The caller should make the MC command to attach a DPAA2 object to
2014 + * a DPIO after this function completes successfully. In that way:
2015 + * (a) The DPIO service is "ready" to handle a notification arrival
2016 + * (which might happen before the "attach" command to MC has
2017 + * returned control of execution back to the caller)
2018 + * (b) The DPIO service can provide back to the caller the 'dpio_id' and
2019 + * 'qman64' parameters that it should pass along in the MC command
2020 + * in order for the object to be configured to produce the right
2021 + * notification fields to the DPIO service.
2023 + * Return 0 for success, or -ENODEV for failure.
2025 +int dpaa2_io_service_register(struct dpaa2_io *d,
2026 + struct dpaa2_io_notification_ctx *ctx)
2028 + unsigned long irqflags;
2030 + d = service_select_by_cpu(d, ctx->desired_cpu);
2034 + ctx->dpio_id = d->dpio_desc.dpio_id;
2035 + ctx->qman64 = (u64)ctx;
2036 + ctx->dpio_private = d;
2037 + spin_lock_irqsave(&d->lock_notifications, irqflags);
2038 + list_add(&ctx->node, &d->notifications);
2039 + spin_unlock_irqrestore(&d->lock_notifications, irqflags);
2041 + /* Enable the generation of CDAN notifications */
2043 + qbman_swp_CDAN_set_context_enable(d->swp,
2048 +EXPORT_SYMBOL(dpaa2_io_service_register);
2051 + * dpaa2_io_service_deregister - The opposite of 'register'.
2052 + * @service: the given DPIO service.
2053 + * @ctx: the notification context.
2055 + * This function should be called only after sending the MC command to
2056 + * to detach the notification-producing device from the DPIO.
2058 +void dpaa2_io_service_deregister(struct dpaa2_io *service,
2059 + struct dpaa2_io_notification_ctx *ctx)
2061 + struct dpaa2_io *d = ctx->dpio_private;
2062 + unsigned long irqflags;
2065 + qbman_swp_CDAN_disable(d->swp, (u16)ctx->id);
2067 + spin_lock_irqsave(&d->lock_notifications, irqflags);
2068 + list_del(&ctx->node);
2069 + spin_unlock_irqrestore(&d->lock_notifications, irqflags);
2071 +EXPORT_SYMBOL(dpaa2_io_service_deregister);
2074 + * dpaa2_io_service_rearm() - Rearm the notification for the given DPIO service.
2075 + * @d: the given DPIO service.
2076 + * @ctx: the notification context.
2078 + * Once a FQDAN/CDAN has been produced, the corresponding FQ/channel is
2079 + * considered "disarmed". Ie. the user can issue pull dequeue operations on that
2080 + * traffic source for as long as it likes. Eventually it may wish to "rearm"
2081 + * that source to allow it to produce another FQDAN/CDAN, that's what this
2082 + * function achieves.
2084 + * Return 0 for success.
2086 +int dpaa2_io_service_rearm(struct dpaa2_io *d,
2087 + struct dpaa2_io_notification_ctx *ctx)
2089 + unsigned long irqflags;
2092 + d = service_select_by_cpu(d, ctx->desired_cpu);
2096 + spin_lock_irqsave(&d->lock_mgmt_cmd, irqflags);
2098 + err = qbman_swp_CDAN_enable(d->swp, (u16)ctx->id);
2100 + err = qbman_swp_fq_schedule(d->swp, ctx->id);
2101 + spin_unlock_irqrestore(&d->lock_mgmt_cmd, irqflags);
2105 +EXPORT_SYMBOL(dpaa2_io_service_rearm);
2108 + * dpaa2_io_service_pull_fq() - pull dequeue functions from a fq.
2109 + * @d: the given DPIO service.
2110 + * @fqid: the given frame queue id.
2111 + * @s: the dpaa2_io_store object for the result.
2113 + * Return 0 for success, or error code for failure.
2115 +int dpaa2_io_service_pull_fq(struct dpaa2_io *d, u32 fqid,
2116 + struct dpaa2_io_store *s)
2118 + struct qbman_pull_desc pd;
2121 + qbman_pull_desc_clear(&pd);
2122 + qbman_pull_desc_set_storage(&pd, s->vaddr, s->paddr, 1);
2123 + qbman_pull_desc_set_numframes(&pd, (u8)s->max);
2124 + qbman_pull_desc_set_fq(&pd, fqid);
2126 + d = service_select(d);
2130 + err = qbman_swp_pull(d->swp, &pd);
2136 +EXPORT_SYMBOL(dpaa2_io_service_pull_fq);
2139 + * dpaa2_io_service_pull_channel() - pull dequeue functions from a channel.
2140 + * @d: the given DPIO service.
2141 + * @channelid: the given channel id.
2142 + * @s: the dpaa2_io_store object for the result.
2144 + * Return 0 for success, or error code for failure.
2146 +int dpaa2_io_service_pull_channel(struct dpaa2_io *d, u32 channelid,
2147 + struct dpaa2_io_store *s)
2149 + struct qbman_pull_desc pd;
2152 + qbman_pull_desc_clear(&pd);
2153 + qbman_pull_desc_set_storage(&pd, s->vaddr, s->paddr, 1);
2154 + qbman_pull_desc_set_numframes(&pd, (u8)s->max);
2155 + qbman_pull_desc_set_channel(&pd, channelid, qbman_pull_type_prio);
2157 + d = service_select(d);
2162 + err = qbman_swp_pull(d->swp, &pd);
2168 +EXPORT_SYMBOL(dpaa2_io_service_pull_channel);
2171 + * dpaa2_io_service_enqueue_fq() - Enqueue a frame to a frame queue.
2172 + * @d: the given DPIO service.
2173 + * @fqid: the given frame queue id.
2174 + * @fd: the frame descriptor which is enqueued.
2176 + * Return 0 for successful enqueue, -EBUSY if the enqueue ring is not ready,
2177 + * or -ENODEV if there is no dpio service.
2179 +int dpaa2_io_service_enqueue_fq(struct dpaa2_io *d,
2181 + const struct dpaa2_fd *fd)
2183 + struct qbman_eq_desc ed;
2185 + d = service_select(d);
2189 + qbman_eq_desc_clear(&ed);
2190 + qbman_eq_desc_set_no_orp(&ed, 0);
2191 + qbman_eq_desc_set_fq(&ed, fqid);
2193 + return qbman_swp_enqueue(d->swp, &ed, fd);
2195 +EXPORT_SYMBOL(dpaa2_io_service_enqueue_fq);
2198 + * dpaa2_io_service_enqueue_qd() - Enqueue a frame to a QD.
2199 + * @d: the given DPIO service.
2200 + * @qdid: the given queuing destination id.
2201 + * @prio: the given queuing priority.
2202 + * @qdbin: the given queuing destination bin.
2203 + * @fd: the frame descriptor which is enqueued.
2205 + * Return 0 for successful enqueue, or -EBUSY if the enqueue ring is not ready,
2206 + * or -ENODEV if there is no dpio service.
2208 +int dpaa2_io_service_enqueue_qd(struct dpaa2_io *d,
2209 + u32 qdid, u8 prio, u16 qdbin,
2210 + const struct dpaa2_fd *fd)
2212 + struct qbman_eq_desc ed;
2214 + d = service_select(d);
2218 + qbman_eq_desc_clear(&ed);
2219 + qbman_eq_desc_set_no_orp(&ed, 0);
2220 + qbman_eq_desc_set_qd(&ed, qdid, qdbin, prio);
2222 + return qbman_swp_enqueue(d->swp, &ed, fd);
2224 +EXPORT_SYMBOL(dpaa2_io_service_enqueue_qd);
2227 + * dpaa2_io_service_release() - Release buffers to a buffer pool.
2228 + * @d: the given DPIO object.
2229 + * @bpid: the buffer pool id.
2230 + * @buffers: the buffers to be released.
2231 + * @num_buffers: the number of the buffers to be released.
2233 + * Return 0 for success, and negative error code for failure.
2235 +int dpaa2_io_service_release(struct dpaa2_io *d,
2237 + const u64 *buffers,
2238 + unsigned int num_buffers)
2240 + struct qbman_release_desc rd;
2242 + d = service_select(d);
2246 + qbman_release_desc_clear(&rd);
2247 + qbman_release_desc_set_bpid(&rd, bpid);
2249 + return qbman_swp_release(d->swp, &rd, buffers, num_buffers);
2251 +EXPORT_SYMBOL(dpaa2_io_service_release);
2254 + * dpaa2_io_service_acquire() - Acquire buffers from a buffer pool.
2255 + * @d: the given DPIO object.
2256 + * @bpid: the buffer pool id.
2257 + * @buffers: the buffer addresses for acquired buffers.
2258 + * @num_buffers: the expected number of the buffers to acquire.
2260 + * Return a negative error code if the command failed, otherwise it returns
2261 + * the number of buffers acquired, which may be less than the number requested.
2262 + * Eg. if the buffer pool is empty, this will return zero.
2264 +int dpaa2_io_service_acquire(struct dpaa2_io *d,
2267 + unsigned int num_buffers)
2269 + unsigned long irqflags;
2272 + d = service_select(d);
2276 + spin_lock_irqsave(&d->lock_mgmt_cmd, irqflags);
2277 + err = qbman_swp_acquire(d->swp, bpid, buffers, num_buffers);
2278 + spin_unlock_irqrestore(&d->lock_mgmt_cmd, irqflags);
2282 +EXPORT_SYMBOL(dpaa2_io_service_acquire);
2285 + * 'Stores' are reusable memory blocks for holding dequeue results, and to
2286 + * assist with parsing those results.
2290 + * dpaa2_io_store_create() - Create the dma memory storage for dequeue result.
2291 + * @max_frames: the maximum number of dequeued result for frames, must be <= 16.
2292 + * @dev: the device to allow mapping/unmapping the DMAable region.
2294 + * The size of the storage is "max_frames*sizeof(struct dpaa2_dq)".
2295 + * The 'dpaa2_io_store' returned is a DPIO service managed object.
2297 + * Return pointer to dpaa2_io_store struct for successfuly created storage
2298 + * memory, or NULL on error.
2300 +struct dpaa2_io_store *dpaa2_io_store_create(unsigned int max_frames,
2301 + struct device *dev)
2303 + struct dpaa2_io_store *ret;
2306 + if (!max_frames || (max_frames > 16))
2309 + ret = kmalloc(sizeof(*ret), GFP_KERNEL);
2313 + ret->max = max_frames;
2314 + size = max_frames * sizeof(struct dpaa2_dq) + 64;
2315 + ret->alloced_addr = kzalloc(size, GFP_KERNEL);
2316 + if (!ret->alloced_addr) {
2321 + ret->vaddr = PTR_ALIGN(ret->alloced_addr, 64);
2322 + ret->paddr = dma_map_single(dev, ret->vaddr,
2323 + sizeof(struct dpaa2_dq) * max_frames,
2325 + if (dma_mapping_error(dev, ret->paddr)) {
2326 + kfree(ret->alloced_addr);
2336 +EXPORT_SYMBOL(dpaa2_io_store_create);
2339 + * dpaa2_io_store_destroy() - Frees the dma memory storage for dequeue
2341 + * @s: the storage memory to be destroyed.
2343 +void dpaa2_io_store_destroy(struct dpaa2_io_store *s)
2345 + dma_unmap_single(s->dev, s->paddr, sizeof(struct dpaa2_dq) * s->max,
2347 + kfree(s->alloced_addr);
2350 +EXPORT_SYMBOL(dpaa2_io_store_destroy);
2353 + * dpaa2_io_store_next() - Determine when the next dequeue result is available.
2354 + * @s: the dpaa2_io_store object.
2355 + * @is_last: indicate whether this is the last frame in the pull command.
2357 + * When an object driver performs dequeues to a dpaa2_io_store, this function
2358 + * can be used to determine when the next frame result is available. Once
2359 + * this function returns non-NULL, a subsequent call to it will try to find
2360 + * the next dequeue result.
2362 + * Note that if a pull-dequeue has a NULL result because the target FQ/channel
2363 + * was empty, then this function will also return NULL (rather than expecting
2364 + * the caller to always check for this. As such, "is_last" can be used to
2365 + * differentiate between "end-of-empty-dequeue" and "still-waiting".
2367 + * Return dequeue result for a valid dequeue result, or NULL for empty dequeue.
2369 +struct dpaa2_dq *dpaa2_io_store_next(struct dpaa2_io_store *s, int *is_last)
2372 + struct dpaa2_dq *ret = &s->vaddr[s->idx];
2374 + match = qbman_result_has_new_result(s->swp, ret);
2382 + if (dpaa2_dq_is_pull_complete(ret)) {
2386 + * If we get an empty dequeue result to terminate a zero-results
2387 + * vdqcr, return NULL to the caller rather than expecting him to
2388 + * check non-NULL results every time.
2390 + if (!(dpaa2_dq_flags(ret) & DPAA2_DQ_STAT_VALIDFRAME))
2398 +EXPORT_SYMBOL(dpaa2_io_store_next);
2400 +#ifdef CONFIG_FSL_QBMAN_DEBUG
2402 + * dpaa2_io_query_fq_count() - Get the frame and byte count for a given fq.
2403 + * @d: the given DPIO object.
2404 + * @fqid: the id of frame queue to be queried.
2405 + * @fcnt: the queried frame count.
2406 + * @bcnt: the queried byte count.
2408 + * Knowing the FQ count at run-time can be useful in debugging situations.
2409 + * The instantaneous frame- and byte-count are hereby returned.
2411 + * Return 0 for a successful query, and negative error code if query fails.
2413 +int dpaa2_io_query_fq_count(struct dpaa2_io *d, uint32_t fqid,
2414 + u32 *fcnt, u32 *bcnt)
2416 + struct qbman_attr state;
2417 + struct qbman_swp *swp;
2418 + unsigned long irqflags;
2421 + d = service_select(d);
2426 + spin_lock_irqsave(&d->lock_mgmt_cmd, irqflags);
2427 + ret = qbman_fq_query_state(swp, fqid, &state);
2428 + spin_unlock_irqrestore(&d->lock_mgmt_cmd, irqflags);
2431 + *fcnt = qbman_fq_state_frame_count(&state);
2432 + *bcnt = qbman_fq_state_byte_count(&state);
2436 +EXPORT_SYMBOL(dpaa2_io_query_fq_count);
2439 + * dpaa2_io_query_bp_count() - Query the number of buffers currenty in a
2441 + * @d: the given DPIO object.
2442 + * @bpid: the index of buffer pool to be queried.
2443 + * @num: the queried number of buffers in the buffer pool.
2445 + * Return 0 for a sucessful query, and negative error code if query fails.
2447 +int dpaa2_io_query_bp_count(struct dpaa2_io *d, uint32_t bpid, u32 *num)
2449 + struct qbman_attr state;
2450 + struct qbman_swp *swp;
2451 + unsigned long irqflags;
2454 + d = service_select(d);
2459 + spin_lock_irqsave(&d->lock_mgmt_cmd, irqflags);
2460 + ret = qbman_bp_query(swp, bpid, &state);
2461 + spin_unlock_irqrestore(&d->lock_mgmt_cmd, irqflags);
2464 + *num = qbman_bp_info_num_free_bufs(&state);
2467 +EXPORT_SYMBOL(dpaa2_io_query_bp_count);
2470 +++ b/drivers/staging/fsl-mc/bus/dpio/dpio.c
2473 + * Copyright 2013-2016 Freescale Semiconductor Inc.
2474 + * Copyright 2016 NXP
2476 + * Redistribution and use in source and binary forms, with or without
2477 + * modification, are permitted provided that the following conditions are met:
2478 + * * Redistributions of source code must retain the above copyright
2479 + * notice, this list of conditions and the following disclaimer.
2480 + * * Redistributions in binary form must reproduce the above copyright
2481 + * notice, this list of conditions and the following disclaimer in the
2482 + * documentation and/or other materials provided with the distribution.
2483 + * * Neither the name of the above-listed copyright holders nor the
2484 + * names of any contributors may be used to endorse or promote products
2485 + * derived from this software without specific prior written permission.
2487 + * ALTERNATIVELY, this software may be distributed under the terms of the
2488 + * GNU General Public License ("GPL") as published by the Free Software
2489 + * Foundation, either version 2 of that License or (at your option) any
2492 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
2493 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2494 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2495 + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
2496 + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2497 + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2498 + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2499 + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2500 + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2501 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2502 + * POSSIBILITY OF SUCH DAMAGE.
2504 +#include "../../include/mc-sys.h"
2505 +#include "../../include/mc-cmd.h"
2508 +#include "dpio-cmd.h"
2511 + * Data Path I/O Portal API
2512 + * Contains initialization APIs and runtime control APIs for DPIO
2516 + * dpio_open() - Open a control session for the specified object
2517 + * @mc_io: Pointer to MC portal's I/O object
2518 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2519 + * @dpio_id: DPIO unique ID
2520 + * @token: Returned token; use in subsequent API calls
2522 + * This function can be used to open a control session for an
2523 + * already created object; an object may have been declared in
2524 + * the DPL or by calling the dpio_create() function.
2525 + * This function returns a unique authentication token,
2526 + * associated with the specific object ID and the specific MC
2527 + * portal; this token must be used in all subsequent commands for
2528 + * this specific object.
2530 + * Return: '0' on Success; Error code otherwise.
2532 +int dpio_open(struct fsl_mc_io *mc_io,
2537 + struct mc_command cmd = { 0 };
2538 + struct dpio_cmd_open *dpio_cmd;
2541 + /* prepare command */
2542 + cmd.header = mc_encode_cmd_header(DPIO_CMDID_OPEN,
2545 + dpio_cmd = (struct dpio_cmd_open *)cmd.params;
2546 + dpio_cmd->dpio_id = cpu_to_le32(dpio_id);
2548 + err = mc_send_command(mc_io, &cmd);
2552 + /* retrieve response parameters */
2553 + *token = mc_cmd_hdr_read_token(&cmd);
2559 + * dpio_close() - Close the control session of the object
2560 + * @mc_io: Pointer to MC portal's I/O object
2561 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2562 + * @token: Token of DPIO object
2564 + * Return: '0' on Success; Error code otherwise.
2566 +int dpio_close(struct fsl_mc_io *mc_io,
2570 + struct mc_command cmd = { 0 };
2572 + /* prepare command */
2573 + cmd.header = mc_encode_cmd_header(DPIO_CMDID_CLOSE,
2577 + return mc_send_command(mc_io, &cmd);
2581 + * dpio_enable() - Enable the DPIO, allow I/O portal operations.
2582 + * @mc_io: Pointer to MC portal's I/O object
2583 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2584 + * @token: Token of DPIO object
2586 + * Return: '0' on Success; Error code otherwise
2588 +int dpio_enable(struct fsl_mc_io *mc_io,
2592 + struct mc_command cmd = { 0 };
2594 + /* prepare command */
2595 + cmd.header = mc_encode_cmd_header(DPIO_CMDID_ENABLE,
2599 + return mc_send_command(mc_io, &cmd);
2603 + * dpio_disable() - Disable the DPIO, stop any I/O portal operation.
2604 + * @mc_io: Pointer to MC portal's I/O object
2605 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2606 + * @token: Token of DPIO object
2608 + * Return: '0' on Success; Error code otherwise
2610 +int dpio_disable(struct fsl_mc_io *mc_io,
2614 + struct mc_command cmd = { 0 };
2616 + /* prepare command */
2617 + cmd.header = mc_encode_cmd_header(DPIO_CMDID_DISABLE,
2621 + return mc_send_command(mc_io, &cmd);
2625 + * dpio_get_attributes() - Retrieve DPIO attributes
2626 + * @mc_io: Pointer to MC portal's I/O object
2627 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2628 + * @token: Token of DPIO object
2629 + * @attr: Returned object's attributes
2631 + * Return: '0' on Success; Error code otherwise
2633 +int dpio_get_attributes(struct fsl_mc_io *mc_io,
2636 + struct dpio_attr *attr)
2638 + struct mc_command cmd = { 0 };
2639 + struct dpio_rsp_get_attr *dpio_rsp;
2642 + /* prepare command */
2643 + cmd.header = mc_encode_cmd_header(DPIO_CMDID_GET_ATTR,
2647 + err = mc_send_command(mc_io, &cmd);
2651 + /* retrieve response parameters */
2652 + dpio_rsp = (struct dpio_rsp_get_attr *)cmd.params;
2653 + attr->id = le32_to_cpu(dpio_rsp->id);
2654 + attr->qbman_portal_id = le16_to_cpu(dpio_rsp->qbman_portal_id);
2655 + attr->num_priorities = dpio_rsp->num_priorities;
2656 + attr->channel_mode = dpio_rsp->channel_mode & DPIO_CHANNEL_MODE_MASK;
2657 + attr->qbman_portal_ce_offset =
2658 + le64_to_cpu(dpio_rsp->qbman_portal_ce_addr);
2659 + attr->qbman_portal_ci_offset =
2660 + le64_to_cpu(dpio_rsp->qbman_portal_ci_addr);
2661 + attr->qbman_version = le32_to_cpu(dpio_rsp->qbman_version);
2667 + * dpio_get_api_version - Get Data Path I/O API version
2668 + * @mc_io: Pointer to MC portal's DPIO object
2669 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2670 + * @major_ver: Major version of DPIO API
2671 + * @minor_ver: Minor version of DPIO API
2673 + * Return: '0' on Success; Error code otherwise
2675 +int dpio_get_api_version(struct fsl_mc_io *mc_io,
2680 + struct mc_command cmd = { 0 };
2683 + /* prepare command */
2684 + cmd.header = mc_encode_cmd_header(DPIO_CMDID_GET_API_VERSION,
2687 + err = mc_send_command(mc_io, &cmd);
2691 + /* retrieve response parameters */
2692 + mc_cmd_read_api_version(&cmd, major_ver, minor_ver);
2697 +++ b/drivers/staging/fsl-mc/bus/dpio/dpio.h
2700 + * Copyright 2013-2016 Freescale Semiconductor Inc.
2701 + * Copyright 2016 NXP
2703 + * Redistribution and use in source and binary forms, with or without
2704 + * modification, are permitted provided that the following conditions are met:
2705 + * * Redistributions of source code must retain the above copyright
2706 + * notice, this list of conditions and the following disclaimer.
2707 + * * Redistributions in binary form must reproduce the above copyright
2708 + * notice, this list of conditions and the following disclaimer in the
2709 + * documentation and/or other materials provided with the distribution.
2710 + * * Neither the name of the above-listed copyright holders nor the
2711 + * names of any contributors may be used to endorse or promote products
2712 + * derived from this software without specific prior written permission.
2714 + * ALTERNATIVELY, this software may be distributed under the terms of the
2715 + * GNU General Public License ("GPL") as published by the Free Software
2716 + * Foundation, either version 2 of that License or (at your option) any
2719 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
2720 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2721 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2722 + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
2723 + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2724 + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2725 + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2726 + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2727 + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2728 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2729 + * POSSIBILITY OF SUCH DAMAGE.
2731 +#ifndef __FSL_DPIO_H
2732 +#define __FSL_DPIO_H
2736 +int dpio_open(struct fsl_mc_io *mc_io,
2741 +int dpio_close(struct fsl_mc_io *mc_io,
2746 + * enum dpio_channel_mode - DPIO notification channel mode
2747 + * @DPIO_NO_CHANNEL: No support for notification channel
2748 + * @DPIO_LOCAL_CHANNEL: Notifications on data availability can be received by a
2749 + * dedicated channel in the DPIO; user should point the queue's
2750 + * destination in the relevant interface to this DPIO
2752 +enum dpio_channel_mode {
2753 + DPIO_NO_CHANNEL = 0,
2754 + DPIO_LOCAL_CHANNEL = 1,
2758 + * struct dpio_cfg - Structure representing DPIO configuration
2759 + * @channel_mode: Notification channel mode
2760 + * @num_priorities: Number of priorities for the notification channel (1-8);
2761 + * relevant only if 'channel_mode = DPIO_LOCAL_CHANNEL'
2764 + enum dpio_channel_mode channel_mode;
2765 + u8 num_priorities;
2768 +int dpio_enable(struct fsl_mc_io *mc_io,
2772 +int dpio_disable(struct fsl_mc_io *mc_io,
2777 + * struct dpio_attr - Structure representing DPIO attributes
2778 + * @id: DPIO object ID
2779 + * @qbman_portal_ce_offset: offset of the software portal cache-enabled area
2780 + * @qbman_portal_ci_offset: offset of the software portal cache-inhibited area
2781 + * @qbman_portal_id: Software portal ID
2782 + * @channel_mode: Notification channel mode
2783 + * @num_priorities: Number of priorities for the notification channel (1-8);
2784 + * relevant only if 'channel_mode = DPIO_LOCAL_CHANNEL'
2785 + * @qbman_version: QBMAN version
2789 + u64 qbman_portal_ce_offset;
2790 + u64 qbman_portal_ci_offset;
2791 + u16 qbman_portal_id;
2792 + enum dpio_channel_mode channel_mode;
2793 + u8 num_priorities;
2794 + u32 qbman_version;
2797 +int dpio_get_attributes(struct fsl_mc_io *mc_io,
2800 + struct dpio_attr *attr);
2802 +int dpio_get_api_version(struct fsl_mc_io *mc_io,
2807 +#endif /* __FSL_DPIO_H */
2809 +++ b/drivers/staging/fsl-mc/bus/dpio/qbman-portal.c
2812 + * Copyright (C) 2014-2016 Freescale Semiconductor, Inc.
2813 + * Copyright 2016 NXP
2815 + * Redistribution and use in source and binary forms, with or without
2816 + * modification, are permitted provided that the following conditions are met:
2817 + * * Redistributions of source code must retain the above copyright
2818 + * notice, this list of conditions and the following disclaimer.
2819 + * * Redistributions in binary form must reproduce the above copyright
2820 + * notice, this list of conditions and the following disclaimer in the
2821 + * documentation and/or other materials provided with the distribution.
2822 + * * Neither the name of Freescale Semiconductor nor the
2823 + * names of its contributors may be used to endorse or promote products
2824 + * derived from this software without specific prior written permission.
2826 + * ALTERNATIVELY, this software may be distributed under the terms of the
2827 + * GNU General Public License ("GPL") as published by the Free Software
2828 + * Foundation, either version 2 of that License or (at your option) any
2831 + * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
2832 + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
2833 + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
2834 + * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
2835 + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
2836 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
2837 + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
2838 + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2839 + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
2840 + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2843 +#include <asm/cacheflush.h>
2844 +#include <linux/io.h>
2845 +#include <linux/slab.h>
2846 +#include "../../include/dpaa2-global.h"
2848 +#include "qbman-portal.h"
2850 +struct qb_attr_code code_generic_verb = QB_CODE(0, 0, 7);
2851 +struct qb_attr_code code_generic_rslt = QB_CODE(0, 8, 8);
2853 +#define QMAN_REV_4000 0x04000000
2854 +#define QMAN_REV_4100 0x04010000
2855 +#define QMAN_REV_4101 0x04010001
2856 +#define QMAN_REV_MASK 0xffff0000
2858 +/* All QBMan command and result structures use this "valid bit" encoding */
2859 +#define QB_VALID_BIT ((u32)0x80)
2861 +/* QBMan portal management command codes */
2862 +#define QBMAN_MC_ACQUIRE 0x30
2863 +#define QBMAN_WQCHAN_CONFIGURE 0x46
2865 +/* CINH register offsets */
2866 +#define QBMAN_CINH_SWP_EQAR 0x8c0
2867 +#define QBMAN_CINH_SWP_DQPI 0xa00
2868 +#define QBMAN_CINH_SWP_DCAP 0xac0
2869 +#define QBMAN_CINH_SWP_SDQCR 0xb00
2870 +#define QBMAN_CINH_SWP_RAR 0xcc0
2871 +#define QBMAN_CINH_SWP_ISR 0xe00
2872 +#define QBMAN_CINH_SWP_IER 0xe40
2873 +#define QBMAN_CINH_SWP_ISDR 0xe80
2874 +#define QBMAN_CINH_SWP_IIR 0xec0
2876 +/* CENA register offsets */
2877 +#define QBMAN_CENA_SWP_EQCR(n) (0x000 + ((u32)(n) << 6))
2878 +#define QBMAN_CENA_SWP_DQRR(n) (0x200 + ((u32)(n) << 6))
2879 +#define QBMAN_CENA_SWP_RCR(n) (0x400 + ((u32)(n) << 6))
2880 +#define QBMAN_CENA_SWP_CR 0x600
2881 +#define QBMAN_CENA_SWP_RR(vb) (0x700 + ((u32)(vb) >> 1))
2882 +#define QBMAN_CENA_SWP_VDQCR 0x780
2884 +/* Reverse mapping of QBMAN_CENA_SWP_DQRR() */
2885 +#define QBMAN_IDX_FROM_DQRR(p) (((unsigned long)(p) & 0x1ff) >> 6)
2887 +/* Define token used to determine if response written to memory is valid */
2888 +#define QMAN_DQ_TOKEN_VALID 1
2890 +/* SDQCR attribute codes */
2891 +#define QB_SDQCR_FC_SHIFT 29
2892 +#define QB_SDQCR_FC_MASK 0x1
2893 +#define QB_SDQCR_DCT_SHIFT 24
2894 +#define QB_SDQCR_DCT_MASK 0x3
2895 +#define QB_SDQCR_TOK_SHIFT 16
2896 +#define QB_SDQCR_TOK_MASK 0xff
2897 +#define QB_SDQCR_SRC_SHIFT 0
2898 +#define QB_SDQCR_SRC_MASK 0xffff
2900 +/* opaque token for static dequeues */
2901 +#define QMAN_SDQCR_TOKEN 0xbb
2903 +enum qbman_sdqcr_dct {
2904 + qbman_sdqcr_dct_null = 0,
2905 + qbman_sdqcr_dct_prio_ics,
2906 + qbman_sdqcr_dct_active_ics,
2907 + qbman_sdqcr_dct_active
2910 +enum qbman_sdqcr_fc {
2911 + qbman_sdqcr_fc_one = 0,
2912 + qbman_sdqcr_fc_up_to_3 = 1
2915 +#define dccvac(p) { asm volatile("dc cvac, %0;" : : "r" (p) : "memory"); }
2916 +#define dcivac(p) { asm volatile("dc ivac, %0" : : "r"(p) : "memory"); }
2917 +static inline void qbman_inval_prefetch(struct qbman_swp *p, uint32_t offset)
2919 + dcivac(p->addr_cena + offset);
2920 + prefetch(p->addr_cena + offset);
2923 +/* Portal Access */
2925 +static inline u32 qbman_read_register(struct qbman_swp *p, u32 offset)
2927 + return readl_relaxed(p->addr_cinh + offset);
2930 +static inline void qbman_write_register(struct qbman_swp *p, u32 offset,
2933 + writel_relaxed(value, p->addr_cinh + offset);
2936 +static inline void *qbman_get_cmd(struct qbman_swp *p, u32 offset)
2938 + return p->addr_cena + offset;
2941 +#define QBMAN_CINH_SWP_CFG 0xd00
2943 +#define SWP_CFG_DQRR_MF_SHIFT 20
2944 +#define SWP_CFG_EST_SHIFT 16
2945 +#define SWP_CFG_WN_SHIFT 14
2946 +#define SWP_CFG_RPM_SHIFT 12
2947 +#define SWP_CFG_DCM_SHIFT 10
2948 +#define SWP_CFG_EPM_SHIFT 8
2949 +#define SWP_CFG_SD_SHIFT 5
2950 +#define SWP_CFG_SP_SHIFT 4
2951 +#define SWP_CFG_SE_SHIFT 3
2952 +#define SWP_CFG_DP_SHIFT 2
2953 +#define SWP_CFG_DE_SHIFT 1
2954 +#define SWP_CFG_EP_SHIFT 0
2956 +static inline u32 qbman_set_swp_cfg(u8 max_fill, u8 wn, u8 est, u8 rpm, u8 dcm,
2957 + u8 epm, int sd, int sp, int se,
2958 + int dp, int de, int ep)
2960 + return cpu_to_le32 (max_fill << SWP_CFG_DQRR_MF_SHIFT |
2961 + est << SWP_CFG_EST_SHIFT |
2962 + wn << SWP_CFG_WN_SHIFT |
2963 + rpm << SWP_CFG_RPM_SHIFT |
2964 + dcm << SWP_CFG_DCM_SHIFT |
2965 + epm << SWP_CFG_EPM_SHIFT |
2966 + sd << SWP_CFG_SD_SHIFT |
2967 + sp << SWP_CFG_SP_SHIFT |
2968 + se << SWP_CFG_SE_SHIFT |
2969 + dp << SWP_CFG_DP_SHIFT |
2970 + de << SWP_CFG_DE_SHIFT |
2971 + ep << SWP_CFG_EP_SHIFT);
2975 + * qbman_swp_init() - Create a functional object representing the given
2976 + * QBMan portal descriptor.
2977 + * @d: the given qbman swp descriptor
2979 + * Return qbman_swp portal for success, NULL if the object cannot
2982 +struct qbman_swp *qbman_swp_init(const struct qbman_swp_desc *d)
2984 + struct qbman_swp *p = kmalloc(sizeof(*p), GFP_KERNEL);
2990 + p->mc.valid_bit = QB_VALID_BIT;
2992 + p->sdq |= qbman_sdqcr_dct_prio_ics << QB_SDQCR_DCT_SHIFT;
2993 + p->sdq |= qbman_sdqcr_fc_up_to_3 << QB_SDQCR_FC_SHIFT;
2994 + p->sdq |= QMAN_SDQCR_TOKEN << QB_SDQCR_TOK_SHIFT;
2996 + atomic_set(&p->vdq.available, 1);
2997 + p->vdq.valid_bit = QB_VALID_BIT;
2998 + p->dqrr.next_idx = 0;
2999 + p->dqrr.valid_bit = QB_VALID_BIT;
3001 + if ((p->desc->qman_version & QMAN_REV_MASK) < QMAN_REV_4100) {
3002 + p->dqrr.dqrr_size = 4;
3003 + p->dqrr.reset_bug = 1;
3005 + p->dqrr.dqrr_size = 8;
3006 + p->dqrr.reset_bug = 0;
3009 + p->addr_cena = d->cena_bar;
3010 + p->addr_cinh = d->cinh_bar;
3012 + reg = qbman_set_swp_cfg(p->dqrr.dqrr_size,
3013 + 0, /* Writes cacheable */
3014 + 0, /* EQCR_CI stashing threshold */
3015 + 3, /* RPM: Valid bit mode, RCR in array mode */
3016 + 2, /* DCM: Discrete consumption ack mode */
3017 + 3, /* EPM: Valid bit mode, EQCR in array mode */
3018 + 0, /* mem stashing drop enable == FALSE */
3019 + 1, /* mem stashing priority == TRUE */
3020 + 0, /* mem stashing enable == FALSE */
3021 + 1, /* dequeue stashing priority == TRUE */
3022 + 0, /* dequeue stashing enable == FALSE */
3023 + 0); /* EQCR_CI stashing priority == FALSE */
3025 + qbman_write_register(p, QBMAN_CINH_SWP_CFG, reg);
3026 + reg = qbman_read_register(p, QBMAN_CINH_SWP_CFG);
3028 + pr_err("qbman: the portal is not enabled!\n");
3033 + * SDQCR needs to be initialized to 0 when no channels are
3034 + * being dequeued from or else the QMan HW will indicate an
3035 + * error. The values that were calculated above will be
3036 + * applied when dequeues from a specific channel are enabled.
3038 + qbman_write_register(p, QBMAN_CINH_SWP_SDQCR, 0);
3043 + * qbman_swp_finish() - Create and destroy a functional object representing
3044 + * the given QBMan portal descriptor.
3045 + * @p: the qbman_swp object to be destroyed
3047 +void qbman_swp_finish(struct qbman_swp *p)
3053 + * qbman_swp_interrupt_read_status()
3054 + * @p: the given software portal
3056 + * Return the value in the SWP_ISR register.
3058 +u32 qbman_swp_interrupt_read_status(struct qbman_swp *p)
3060 + return qbman_read_register(p, QBMAN_CINH_SWP_ISR);
3064 + * qbman_swp_interrupt_clear_status()
3065 + * @p: the given software portal
3066 + * @mask: The mask to clear in SWP_ISR register
3068 +void qbman_swp_interrupt_clear_status(struct qbman_swp *p, u32 mask)
3070 + qbman_write_register(p, QBMAN_CINH_SWP_ISR, mask);
3074 + * qbman_swp_interrupt_get_trigger() - read interrupt enable register
3075 + * @p: the given software portal
3077 + * Return the value in the SWP_IER register.
3079 +u32 qbman_swp_interrupt_get_trigger(struct qbman_swp *p)
3081 + return qbman_read_register(p, QBMAN_CINH_SWP_IER);
3085 + * qbman_swp_interrupt_set_trigger() - enable interrupts for a swp
3086 + * @p: the given software portal
3087 + * @mask: The mask of bits to enable in SWP_IER
3089 +void qbman_swp_interrupt_set_trigger(struct qbman_swp *p, u32 mask)
3091 + qbman_write_register(p, QBMAN_CINH_SWP_IER, mask);
3095 + * qbman_swp_interrupt_get_inhibit() - read interrupt mask register
3096 + * @p: the given software portal object
3098 + * Return the value in the SWP_IIR register.
3100 +int qbman_swp_interrupt_get_inhibit(struct qbman_swp *p)
3102 + return qbman_read_register(p, QBMAN_CINH_SWP_IIR);
3106 + * qbman_swp_interrupt_set_inhibit() - write interrupt mask register
3107 + * @p: the given software portal object
3108 + * @mask: The mask to set in SWP_IIR register
3110 +void qbman_swp_interrupt_set_inhibit(struct qbman_swp *p, int inhibit)
3112 + qbman_write_register(p, QBMAN_CINH_SWP_IIR, inhibit ? 0xffffffff : 0);
3116 + * Different management commands all use this common base layer of code to issue
3117 + * commands and poll for results.
3121 + * Returns a pointer to where the caller should fill in their management command
3122 + * (caller should ignore the verb byte)
3124 +void *qbman_swp_mc_start(struct qbman_swp *p)
3126 + return qbman_get_cmd(p, QBMAN_CENA_SWP_CR);
3130 + * Commits merges in the caller-supplied command verb (which should not include
3131 + * the valid-bit) and submits the command to hardware
3133 +void qbman_swp_mc_submit(struct qbman_swp *p, void *cmd, u8 cmd_verb)
3138 + *v = cmd_verb | p->mc.valid_bit;
3143 + * Checks for a completed response (returns non-NULL if only if the response
3146 +void *qbman_swp_mc_result(struct qbman_swp *p)
3150 + qbman_inval_prefetch(p, QBMAN_CENA_SWP_RR(p->mc.valid_bit));
3151 + ret = qbman_get_cmd(p, QBMAN_CENA_SWP_RR(p->mc.valid_bit));
3153 + /* Remove the valid-bit - command completed if the rest is non-zero */
3154 + verb = ret[0] & ~QB_VALID_BIT;
3157 + p->mc.valid_bit ^= QB_VALID_BIT;
3161 +#define QB_ENQUEUE_CMD_OPTIONS_SHIFT 0
3162 +enum qb_enqueue_commands {
3163 + enqueue_empty = 0,
3164 + enqueue_response_always = 1,
3165 + enqueue_rejects_to_fq = 2
3168 +#define QB_ENQUEUE_CMD_ORP_ENABLE_SHIFT 2
3169 +#define QB_ENQUEUE_CMD_IRQ_ON_DISPATCH_SHIFT 3
3170 +#define QB_ENQUEUE_CMD_TARGET_TYPE_SHIFT 4
3173 + * qbman_eq_desc_clear() - Clear the contents of a descriptor to
3174 + * default/starting state.
3176 +void qbman_eq_desc_clear(struct qbman_eq_desc *d)
3178 + memset(d, 0, sizeof(*d));
3182 + * qbman_eq_desc_set_no_orp() - Set enqueue descriptor without orp
3183 + * @d: the enqueue descriptor.
3184 + * @response_success: 1 = enqueue with response always; 0 = enqueue with
3185 + * rejections returned on a FQ.
3187 +void qbman_eq_desc_set_no_orp(struct qbman_eq_desc *d, int respond_success)
3189 + d->verb &= ~(1 << QB_ENQUEUE_CMD_ORP_ENABLE_SHIFT);
3190 + if (respond_success)
3191 + d->verb |= enqueue_response_always;
3193 + d->verb |= enqueue_rejects_to_fq;
3197 + * Exactly one of the following descriptor "targets" should be set. (Calling any
3198 + * one of these will replace the effect of any prior call to one of these.)
3199 + * -enqueue to a frame queue
3200 + * -enqueue to a queuing destination
3204 + * qbman_eq_desc_set_fq() - set the FQ for the enqueue command
3205 + * @d: the enqueue descriptor
3206 + * @fqid: the id of the frame queue to be enqueued
3208 +void qbman_eq_desc_set_fq(struct qbman_eq_desc *d, u32 fqid)
3210 + d->verb &= ~(1 << QB_ENQUEUE_CMD_TARGET_TYPE_SHIFT);
3211 + d->tgtid = cpu_to_le32(fqid);
3215 + * qbman_eq_desc_set_qd() - Set Queuing Destination for the enqueue command
3216 + * @d: the enqueue descriptor
3217 + * @qdid: the id of the queuing destination to be enqueued
3218 + * @qd_bin: the queuing destination bin
3219 + * @qd_prio: the queuing destination priority
3221 +void qbman_eq_desc_set_qd(struct qbman_eq_desc *d, u32 qdid,
3222 + u32 qd_bin, u32 qd_prio)
3224 + d->verb |= 1 << QB_ENQUEUE_CMD_TARGET_TYPE_SHIFT;
3225 + d->tgtid = cpu_to_le32(qdid);
3226 + d->qdbin = cpu_to_le16(qd_bin);
3227 + d->qpri = qd_prio;
3230 +#define EQAR_IDX(eqar) ((eqar) & 0x7)
3231 +#define EQAR_VB(eqar) ((eqar) & 0x80)
3232 +#define EQAR_SUCCESS(eqar) ((eqar) & 0x100)
3235 + * qbman_swp_enqueue() - Issue an enqueue command
3236 + * @s: the software portal used for enqueue
3237 + * @d: the enqueue descriptor
3238 + * @fd: the frame descriptor to be enqueued
3240 + * Please note that 'fd' should only be NULL if the "action" of the
3241 + * descriptor is "orp_hole" or "orp_nesn".
3243 + * Return 0 for successful enqueue, -EBUSY if the EQCR is not ready.
3245 +int qbman_swp_enqueue(struct qbman_swp *s, const struct qbman_eq_desc *d,
3246 + const struct dpaa2_fd *fd)
3248 + struct qbman_eq_desc *p;
3249 + u32 eqar = qbman_read_register(s, QBMAN_CINH_SWP_EQAR);
3251 + if (!EQAR_SUCCESS(eqar))
3254 + p = qbman_get_cmd(s, QBMAN_CENA_SWP_EQCR(EQAR_IDX(eqar)));
3255 + memcpy(&p->dca, &d->dca, 31);
3256 + memcpy(&p->fd, fd, sizeof(*fd));
3258 + /* Set the verb byte, have to substitute in the valid-bit */
3260 + p->verb = d->verb | EQAR_VB(eqar);
3266 +/* Static (push) dequeue */
3269 + * qbman_swp_push_get() - Get the push dequeue setup
3270 + * @p: the software portal object
3271 + * @channel_idx: the channel index to query
3272 + * @enabled: returned boolean to show whether the push dequeue is enabled
3273 + * for the given channel
3275 +void qbman_swp_push_get(struct qbman_swp *s, u8 channel_idx, int *enabled)
3277 + u16 src = (s->sdq >> QB_SDQCR_SRC_SHIFT) & QB_SDQCR_SRC_MASK;
3279 + WARN_ON(channel_idx > 15);
3280 + *enabled = src | (1 << channel_idx);
3284 + * qbman_swp_push_set() - Enable or disable push dequeue
3285 + * @p: the software portal object
3286 + * @channel_idx: the channel index (0 to 15)
3287 + * @enable: enable or disable push dequeue
3289 +void qbman_swp_push_set(struct qbman_swp *s, u8 channel_idx, int enable)
3293 + WARN_ON(channel_idx > 15);
3295 + s->sdq |= 1 << channel_idx;
3297 + s->sdq &= ~(1 << channel_idx);
3299 + /* Read make the complete src map. If no channels are enabled
3300 + * the SDQCR must be 0 or else QMan will assert errors
3302 + dqsrc = (s->sdq >> QB_SDQCR_SRC_SHIFT) & QB_SDQCR_SRC_MASK;
3304 + qbman_write_register(s, QBMAN_CINH_SWP_SDQCR, s->sdq);
3306 + qbman_write_register(s, QBMAN_CINH_SWP_SDQCR, 0);
3309 +#define QB_VDQCR_VERB_DCT_SHIFT 0
3310 +#define QB_VDQCR_VERB_DT_SHIFT 2
3311 +#define QB_VDQCR_VERB_RLS_SHIFT 4
3312 +#define QB_VDQCR_VERB_WAE_SHIFT 5
3314 +enum qb_pull_dt_e {
3315 + qb_pull_dt_channel,
3316 + qb_pull_dt_workqueue,
3317 + qb_pull_dt_framequeue
3321 + * qbman_pull_desc_clear() - Clear the contents of a descriptor to
3322 + * default/starting state
3323 + * @d: the pull dequeue descriptor to be cleared
3325 +void qbman_pull_desc_clear(struct qbman_pull_desc *d)
3327 + memset(d, 0, sizeof(*d));
3331 + * qbman_pull_desc_set_storage()- Set the pull dequeue storage
3332 + * @d: the pull dequeue descriptor to be set
3333 + * @storage: the pointer of the memory to store the dequeue result
3334 + * @storage_phys: the physical address of the storage memory
3335 + * @stash: to indicate whether write allocate is enabled
3337 + * If not called, or if called with 'storage' as NULL, the result pull dequeues
3338 + * will produce results to DQRR. If 'storage' is non-NULL, then results are
3339 + * produced to the given memory location (using the DMA address which
3340 + * the caller provides in 'storage_phys'), and 'stash' controls whether or not
3341 + * those writes to main-memory express a cache-warming attribute.
3343 +void qbman_pull_desc_set_storage(struct qbman_pull_desc *d,
3344 + struct dpaa2_dq *storage,
3345 + dma_addr_t storage_phys,
3348 + /* save the virtual address */
3349 + d->rsp_addr_virt = (u64)storage;
3352 + d->verb &= ~(1 << QB_VDQCR_VERB_RLS_SHIFT);
3355 + d->verb |= 1 << QB_VDQCR_VERB_RLS_SHIFT;
3357 + d->verb |= 1 << QB_VDQCR_VERB_WAE_SHIFT;
3359 + d->verb &= ~(1 << QB_VDQCR_VERB_WAE_SHIFT);
3361 + d->rsp_addr = cpu_to_le64(storage_phys);
3365 + * qbman_pull_desc_set_numframes() - Set the number of frames to be dequeued
3366 + * @d: the pull dequeue descriptor to be set
3367 + * @numframes: number of frames to be set, must be between 1 and 16, inclusive
3369 +void qbman_pull_desc_set_numframes(struct qbman_pull_desc *d, u8 numframes)
3371 + d->numf = numframes - 1;
3374 +void qbman_pull_desc_set_token(struct qbman_pull_desc *d, u8 token)
3380 + * Exactly one of the following descriptor "actions" should be set. (Calling any
3381 + * one of these will replace the effect of any prior call to one of these.)
3382 + * - pull dequeue from the given frame queue (FQ)
3383 + * - pull dequeue from any FQ in the given work queue (WQ)
3384 + * - pull dequeue from any FQ in any WQ in the given channel
3388 + * qbman_pull_desc_set_fq() - Set fqid from which the dequeue command dequeues
3389 + * @fqid: the frame queue index of the given FQ
3391 +void qbman_pull_desc_set_fq(struct qbman_pull_desc *d, u32 fqid)
3393 + d->verb |= 1 << QB_VDQCR_VERB_DCT_SHIFT;
3394 + d->verb |= qb_pull_dt_framequeue << QB_VDQCR_VERB_DT_SHIFT;
3395 + d->dq_src = cpu_to_le32(fqid);
3399 + * qbman_pull_desc_set_wq() - Set wqid from which the dequeue command dequeues
3400 + * @wqid: composed of channel id and wqid within the channel
3401 + * @dct: the dequeue command type
3403 +void qbman_pull_desc_set_wq(struct qbman_pull_desc *d, u32 wqid,
3404 + enum qbman_pull_type_e dct)
3406 + d->verb |= dct << QB_VDQCR_VERB_DCT_SHIFT;
3407 + d->verb |= qb_pull_dt_workqueue << QB_VDQCR_VERB_DT_SHIFT;
3408 + d->dq_src = cpu_to_le32(wqid);
3412 + * qbman_pull_desc_set_channel() - Set channelid from which the dequeue command
3414 + * @chid: the channel id to be dequeued
3415 + * @dct: the dequeue command type
3417 +void qbman_pull_desc_set_channel(struct qbman_pull_desc *d, u32 chid,
3418 + enum qbman_pull_type_e dct)
3420 + d->verb |= dct << QB_VDQCR_VERB_DCT_SHIFT;
3421 + d->verb |= qb_pull_dt_channel << QB_VDQCR_VERB_DT_SHIFT;
3422 + d->dq_src = cpu_to_le32(chid);
3426 + * qbman_swp_pull() - Issue the pull dequeue command
3427 + * @s: the software portal object
3428 + * @d: the software portal descriptor which has been configured with
3429 + * the set of qbman_pull_desc_set_*() calls
3431 + * Return 0 for success, and -EBUSY if the software portal is not ready
3432 + * to do pull dequeue.
3434 +int qbman_swp_pull(struct qbman_swp *s, struct qbman_pull_desc *d)
3436 + struct qbman_pull_desc *p;
3438 + if (!atomic_dec_and_test(&s->vdq.available)) {
3439 + atomic_inc(&s->vdq.available);
3442 + s->vdq.storage = (void *)d->rsp_addr_virt;
3443 + p = qbman_get_cmd(s, QBMAN_CENA_SWP_VDQCR);
3444 + p->numf = d->numf;
3445 + p->tok = QMAN_DQ_TOKEN_VALID;
3446 + p->dq_src = d->dq_src;
3447 + p->rsp_addr = d->rsp_addr;
3448 + p->rsp_addr_virt = d->rsp_addr_virt;
3451 + /* Set the verb byte, have to substitute in the valid-bit */
3452 + p->verb = d->verb | s->vdq.valid_bit;
3453 + s->vdq.valid_bit ^= QB_VALID_BIT;
3459 +#define QMAN_DQRR_PI_MASK 0xf
3462 + * qbman_swp_dqrr_next() - Get an valid DQRR entry
3463 + * @s: the software portal object
3465 + * Return NULL if there are no unconsumed DQRR entries. Return a DQRR entry
3466 + * only once, so repeated calls can return a sequence of DQRR entries, without
3467 + * requiring they be consumed immediately or in any particular order.
3469 +const struct dpaa2_dq *qbman_swp_dqrr_next(struct qbman_swp *s)
3472 + u32 response_verb;
3474 + struct dpaa2_dq *p;
3476 + /* Before using valid-bit to detect if something is there, we have to
3477 + * handle the case of the DQRR reset bug...
3479 + if (unlikely(s->dqrr.reset_bug)) {
3481 + * We pick up new entries by cache-inhibited producer index,
3482 + * which means that a non-coherent mapping would require us to
3483 + * invalidate and read *only* once that PI has indicated that
3484 + * there's an entry here. The first trip around the DQRR ring
3485 + * will be much less efficient than all subsequent trips around
3488 + u8 pi = qbman_read_register(s, QBMAN_CINH_SWP_DQPI) &
3489 + QMAN_DQRR_PI_MASK;
3491 + /* there are new entries if pi != next_idx */
3492 + if (pi == s->dqrr.next_idx)
3496 + * if next_idx is/was the last ring index, and 'pi' is
3497 + * different, we can disable the workaround as all the ring
3498 + * entries have now been DMA'd to so valid-bit checking is
3499 + * repaired. Note: this logic needs to be based on next_idx
3500 + * (which increments one at a time), rather than on pi (which
3501 + * can burst and wrap-around between our snapshots of it).
3503 + if (s->dqrr.next_idx == (s->dqrr.dqrr_size - 1)) {
3504 + pr_debug("next_idx=%d, pi=%d, clear reset bug\n",
3505 + s->dqrr.next_idx, pi);
3506 + s->dqrr.reset_bug = 0;
3508 + qbman_inval_prefetch(s, QBMAN_CENA_SWP_DQRR(s->dqrr.next_idx));
3511 + p = qbman_get_cmd(s, QBMAN_CENA_SWP_DQRR(s->dqrr.next_idx));
3512 + verb = p->dq.verb;
3515 + * If the valid-bit isn't of the expected polarity, nothing there. Note,
3516 + * in the DQRR reset bug workaround, we shouldn't need to skip these
3517 + * check, because we've already determined that a new entry is available
3518 + * and we've invalidated the cacheline before reading it, so the
3519 + * valid-bit behaviour is repaired and should tell us what we already
3520 + * knew from reading PI.
3522 + if ((verb & QB_VALID_BIT) != s->dqrr.valid_bit) {
3523 + qbman_inval_prefetch(s, QBMAN_CENA_SWP_DQRR(s->dqrr.next_idx));
3527 + * There's something there. Move "next_idx" attention to the next ring
3528 + * entry (and prefetch it) before returning what we found.
3530 + s->dqrr.next_idx++;
3531 + s->dqrr.next_idx &= s->dqrr.dqrr_size - 1; /* Wrap around */
3532 + if (!s->dqrr.next_idx)
3533 + s->dqrr.valid_bit ^= QB_VALID_BIT;
3536 + * If this is the final response to a volatile dequeue command
3537 + * indicate that the vdq is available
3539 + flags = p->dq.stat;
3540 + response_verb = verb & QBMAN_RESULT_MASK;
3541 + if ((response_verb == QBMAN_RESULT_DQ) &&
3542 + (flags & DPAA2_DQ_STAT_VOLATILE) &&
3543 + (flags & DPAA2_DQ_STAT_EXPIRED))
3544 + atomic_inc(&s->vdq.available);
3546 + qbman_inval_prefetch(s, QBMAN_CENA_SWP_DQRR(s->dqrr.next_idx));
3552 + * qbman_swp_dqrr_consume() - Consume DQRR entries previously returned from
3553 + * qbman_swp_dqrr_next().
3554 + * @s: the software portal object
3555 + * @dq: the DQRR entry to be consumed
3557 +void qbman_swp_dqrr_consume(struct qbman_swp *s, const struct dpaa2_dq *dq)
3559 + qbman_write_register(s, QBMAN_CINH_SWP_DCAP, QBMAN_IDX_FROM_DQRR(dq));
3563 + * qbman_result_has_new_result() - Check and get the dequeue response from the
3564 + * dq storage memory set in pull dequeue command
3565 + * @s: the software portal object
3566 + * @dq: the dequeue result read from the memory
3568 + * Return 1 for getting a valid dequeue result, or 0 for not getting a valid
3571 + * Only used for user-provided storage of dequeue results, not DQRR. For
3572 + * efficiency purposes, the driver will perform any required endianness
3573 + * conversion to ensure that the user's dequeue result storage is in host-endian
3574 + * format. As such, once the user has called qbman_result_has_new_result() and
3575 + * been returned a valid dequeue result, they should not call it again on
3576 + * the same memory location (except of course if another dequeue command has
3577 + * been executed to produce a new result to that location).
3579 +int qbman_result_has_new_result(struct qbman_swp *s, const struct dpaa2_dq *dq)
3581 + if (dq->dq.tok != QMAN_DQ_TOKEN_VALID)
3585 + * Set token to be 0 so we will detect change back to 1
3586 + * next time the looping is traversed. Const is cast away here
3587 + * as we want users to treat the dequeue responses as read only.
3589 + ((struct dpaa2_dq *)dq)->dq.tok = 0;
3592 + * Determine whether VDQCR is available based on whether the
3593 + * current result is sitting in the first storage location of
3594 + * the busy command.
3596 + if (s->vdq.storage == dq) {
3597 + s->vdq.storage = NULL;
3598 + atomic_inc(&s->vdq.available);
3605 + * qbman_release_desc_clear() - Clear the contents of a descriptor to
3606 + * default/starting state.
3608 +void qbman_release_desc_clear(struct qbman_release_desc *d)
3610 + memset(d, 0, sizeof(*d));
3611 + d->verb = 1 << 5; /* Release Command Valid */
3615 + * qbman_release_desc_set_bpid() - Set the ID of the buffer pool to release to
3617 +void qbman_release_desc_set_bpid(struct qbman_release_desc *d, u16 bpid)
3619 + d->bpid = cpu_to_le16(bpid);
3623 + * qbman_release_desc_set_rcdi() - Determines whether or not the portal's RCDI
3624 + * interrupt source should be asserted after the release command is completed.
3626 +void qbman_release_desc_set_rcdi(struct qbman_release_desc *d, int enable)
3629 + d->verb |= 1 << 6;
3631 + d->verb &= ~(1 << 6);
3634 +#define RAR_IDX(rar) ((rar) & 0x7)
3635 +#define RAR_VB(rar) ((rar) & 0x80)
3636 +#define RAR_SUCCESS(rar) ((rar) & 0x100)
3639 + * qbman_swp_release() - Issue a buffer release command
3640 + * @s: the software portal object
3641 + * @d: the release descriptor
3642 + * @buffers: a pointer pointing to the buffer address to be released
3643 + * @num_buffers: number of buffers to be released, must be less than 8
3645 + * Return 0 for success, -EBUSY if the release command ring is not ready.
3647 +int qbman_swp_release(struct qbman_swp *s, const struct qbman_release_desc *d,
3648 + const u64 *buffers, unsigned int num_buffers)
3651 + struct qbman_release_desc *p;
3654 + if (!num_buffers || (num_buffers > 7))
3657 + rar = qbman_read_register(s, QBMAN_CINH_SWP_RAR);
3658 + if (!RAR_SUCCESS(rar))
3661 + /* Start the release command */
3662 + p = qbman_get_cmd(s, QBMAN_CENA_SWP_RCR(RAR_IDX(rar)));
3663 + /* Copy the caller's buffer pointers to the command */
3664 + for (i = 0; i < num_buffers; i++)
3665 + p->buf[i] = cpu_to_le64(buffers[i]);
3666 + p->bpid = d->bpid;
3669 + * Set the verb byte, have to substitute in the valid-bit and the number
3673 + p->verb = d->verb | RAR_VB(rar) | num_buffers;
3679 +struct qbman_acquire_desc {
3687 +struct qbman_acquire_rslt {
3697 + * qbman_swp_acquire() - Issue a buffer acquire command
3698 + * @s: the software portal object
3699 + * @bpid: the buffer pool index
3700 + * @buffers: a pointer pointing to the acquired buffer addresses
3701 + * @num_buffers: number of buffers to be acquired, must be less than 8
3703 + * Return 0 for success, or negative error code if the acquire command
3706 +int qbman_swp_acquire(struct qbman_swp *s, u16 bpid, u64 *buffers,
3707 + unsigned int num_buffers)
3709 + struct qbman_acquire_desc *p;
3710 + struct qbman_acquire_rslt *r;
3713 + if (!num_buffers || (num_buffers > 7))
3716 + /* Start the management command */
3717 + p = qbman_swp_mc_start(s);
3722 + /* Encode the caller-provided attributes */
3723 + p->bpid = cpu_to_le16(bpid);
3724 + p->num = num_buffers;
3726 + /* Complete the management command */
3727 + r = qbman_swp_mc_complete(s, p, QBMAN_MC_ACQUIRE);
3728 + if (unlikely(!r)) {
3729 + pr_err("qbman: acquire from BPID %d failed, no response\n",
3734 + /* Decode the outcome */
3735 + WARN_ON((r->verb & 0x7f) != QBMAN_MC_ACQUIRE);
3737 + /* Determine success or failure */
3738 + if (unlikely(r->rslt != QBMAN_MC_RSLT_OK)) {
3739 + pr_err("qbman: acquire from BPID 0x%x failed, code=0x%02x\n",
3744 + WARN_ON(r->num > num_buffers);
3746 + /* Copy the acquired buffers to the caller's array */
3747 + for (i = 0; i < r->num; i++)
3748 + buffers[i] = le64_to_cpu(r->buf[i]);
3750 + return (int)r->num;
3753 +struct qbman_alt_fq_state_desc {
3760 +struct qbman_alt_fq_state_rslt {
3766 +#define ALT_FQ_FQID_MASK 0x00FFFFFF
3768 +int qbman_swp_alt_fq_state(struct qbman_swp *s, u32 fqid,
3771 + struct qbman_alt_fq_state_desc *p;
3772 + struct qbman_alt_fq_state_rslt *r;
3774 + /* Start the management command */
3775 + p = qbman_swp_mc_start(s);
3779 + p->fqid = cpu_to_le32(fqid) & ALT_FQ_FQID_MASK;
3781 + /* Complete the management command */
3782 + r = qbman_swp_mc_complete(s, p, alt_fq_verb);
3783 + if (unlikely(!r)) {
3784 + pr_err("qbman: mgmt cmd failed, no response (verb=0x%x)\n",
3789 + /* Decode the outcome */
3790 + WARN_ON((r->verb & QBMAN_RESULT_MASK) != alt_fq_verb);
3792 + /* Determine success or failure */
3793 + if (unlikely(r->rslt != QBMAN_MC_RSLT_OK)) {
3794 + pr_err("qbman: ALT FQID %d failed: verb = 0x%08x code = 0x%02x\n",
3795 + fqid, r->verb, r->rslt);
3802 +struct qbman_cdan_ctrl_desc {
3814 +struct qbman_cdan_ctrl_rslt {
3821 +int qbman_swp_CDAN_set(struct qbman_swp *s, u16 channelid,
3822 + u8 we_mask, u8 cdan_en,
3825 + struct qbman_cdan_ctrl_desc *p = NULL;
3826 + struct qbman_cdan_ctrl_rslt *r = NULL;
3828 + /* Start the management command */
3829 + p = qbman_swp_mc_start(s);
3833 + /* Encode the caller-provided attributes */
3834 + p->ch = cpu_to_le16(channelid);
3840 + p->cdan_ctx = cpu_to_le64(ctx);
3842 + /* Complete the management command */
3843 + r = qbman_swp_mc_complete(s, p, QBMAN_WQCHAN_CONFIGURE);
3844 + if (unlikely(!r)) {
3845 + pr_err("qbman: wqchan config failed, no response\n");
3849 + WARN_ON((r->verb & 0x7f) != QBMAN_WQCHAN_CONFIGURE);
3851 + /* Determine success or failure */
3852 + if (unlikely(r->rslt != QBMAN_MC_RSLT_OK)) {
3853 + pr_err("qbman: CDAN cQID %d failed: code = 0x%02x\n",
3854 + channelid, r->rslt);
3861 +++ b/drivers/staging/fsl-mc/bus/dpio/qbman-portal.h
3864 + * Copyright (C) 2014-2016 Freescale Semiconductor, Inc.
3865 + * Copyright 2016 NXP
3867 + * Redistribution and use in source and binary forms, with or without
3868 + * modification, are permitted provided that the following conditions are met:
3869 + * * Redistributions of source code must retain the above copyright
3870 + * notice, this list of conditions and the following disclaimer.
3871 + * * Redistributions in binary form must reproduce the above copyright
3872 + * notice, this list of conditions and the following disclaimer in the
3873 + * documentation and/or other materials provided with the distribution.
3874 + * * Neither the name of Freescale Semiconductor nor the
3875 + * names of its contributors may be used to endorse or promote products
3876 + * derived from this software without specific prior written permission.
3878 + * ALTERNATIVELY, this software may be distributed under the terms of the
3879 + * GNU General Public License ("GPL") as published by the Free Software
3880 + * Foundation, either version 2 of that License or (at your option) any
3883 + * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
3884 + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
3885 + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
3886 + * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
3887 + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
3888 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
3889 + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
3890 + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
3891 + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
3892 + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3894 +#ifndef __FSL_QBMAN_PORTAL_H
3895 +#define __FSL_QBMAN_PORTAL_H
3897 +#include "qbman_private.h"
3898 +#include "../../include/dpaa2-fd.h"
3903 +/* qbman software portal descriptor structure */
3904 +struct qbman_swp_desc {
3905 + void *cena_bar; /* Cache-enabled portal base address */
3906 + void *cinh_bar; /* Cache-inhibited portal base address */
3910 +#define QBMAN_SWP_INTERRUPT_EQRI 0x01
3911 +#define QBMAN_SWP_INTERRUPT_EQDI 0x02
3912 +#define QBMAN_SWP_INTERRUPT_DQRI 0x04
3913 +#define QBMAN_SWP_INTERRUPT_RCRI 0x08
3914 +#define QBMAN_SWP_INTERRUPT_RCDI 0x10
3915 +#define QBMAN_SWP_INTERRUPT_VDCI 0x20
3917 +/* the structure for pull dequeue descriptor */
3918 +struct qbman_pull_desc {
3925 + u64 rsp_addr_virt;
3929 +enum qbman_pull_type_e {
3930 + /* dequeue with priority precedence, respect intra-class scheduling */
3931 + qbman_pull_type_prio = 1,
3932 + /* dequeue with active FQ precedence, respect ICS */
3933 + qbman_pull_type_active,
3934 + /* dequeue with active FQ precedence, no ICS */
3935 + qbman_pull_type_active_noics
3938 +/* Definitions for parsing dequeue entries */
3939 +#define QBMAN_RESULT_MASK 0x7f
3940 +#define QBMAN_RESULT_DQ 0x60
3941 +#define QBMAN_RESULT_FQRN 0x21
3942 +#define QBMAN_RESULT_FQRNI 0x22
3943 +#define QBMAN_RESULT_FQPN 0x24
3944 +#define QBMAN_RESULT_FQDAN 0x25
3945 +#define QBMAN_RESULT_CDAN 0x26
3946 +#define QBMAN_RESULT_CSCN_MEM 0x27
3947 +#define QBMAN_RESULT_CGCU 0x28
3948 +#define QBMAN_RESULT_BPSCN 0x29
3949 +#define QBMAN_RESULT_CSCN_WQ 0x2a
3951 +/* QBMan FQ management command codes */
3952 +#define QBMAN_FQ_SCHEDULE 0x48
3953 +#define QBMAN_FQ_FORCE 0x49
3954 +#define QBMAN_FQ_XON 0x4d
3955 +#define QBMAN_FQ_XOFF 0x4e
3957 +/* structure of enqueue descriptor */
3958 +struct qbman_eq_desc {
3975 +/* buffer release descriptor */
3976 +struct qbman_release_desc {
3984 +/* Management command result codes */
3985 +#define QBMAN_MC_RSLT_OK 0xf0
3987 +#define CODE_CDAN_WE_EN 0x1
3988 +#define CODE_CDAN_WE_CTX 0x4
3990 +/* portal data structure */
3992 + const struct qbman_swp_desc *desc;
3993 + void __iomem *addr_cena;
3994 + void __iomem *addr_cinh;
3996 + /* Management commands */
3998 + u32 valid_bit; /* 0x00 or 0x80 */
4001 + /* Push dequeues */
4004 + /* Volatile dequeues */
4006 + atomic_t available; /* indicates if a command can be sent */
4007 + u32 valid_bit; /* 0x00 or 0x80 */
4008 + struct dpaa2_dq *storage; /* NULL if DQRR */
4016 + int reset_bug; /* indicates dqrr reset workaround is needed */
4020 +struct qbman_swp *qbman_swp_init(const struct qbman_swp_desc *d);
4021 +void qbman_swp_finish(struct qbman_swp *p);
4022 +u32 qbman_swp_interrupt_read_status(struct qbman_swp *p);
4023 +void qbman_swp_interrupt_clear_status(struct qbman_swp *p, u32 mask);
4024 +u32 qbman_swp_interrupt_get_trigger(struct qbman_swp *p);
4025 +void qbman_swp_interrupt_set_trigger(struct qbman_swp *p, u32 mask);
4026 +int qbman_swp_interrupt_get_inhibit(struct qbman_swp *p);
4027 +void qbman_swp_interrupt_set_inhibit(struct qbman_swp *p, int inhibit);
4029 +void qbman_swp_push_get(struct qbman_swp *p, u8 channel_idx, int *enabled);
4030 +void qbman_swp_push_set(struct qbman_swp *p, u8 channel_idx, int enable);
4032 +void qbman_pull_desc_clear(struct qbman_pull_desc *d);
4033 +void qbman_pull_desc_set_storage(struct qbman_pull_desc *d,
4034 + struct dpaa2_dq *storage,
4035 + dma_addr_t storage_phys,
4037 +void qbman_pull_desc_set_numframes(struct qbman_pull_desc *d, u8 numframes);
4038 +void qbman_pull_desc_set_fq(struct qbman_pull_desc *d, u32 fqid);
4039 +void qbman_pull_desc_set_wq(struct qbman_pull_desc *d, u32 wqid,
4040 + enum qbman_pull_type_e dct);
4041 +void qbman_pull_desc_set_channel(struct qbman_pull_desc *d, u32 chid,
4042 + enum qbman_pull_type_e dct);
4044 +int qbman_swp_pull(struct qbman_swp *p, struct qbman_pull_desc *d);
4046 +const struct dpaa2_dq *qbman_swp_dqrr_next(struct qbman_swp *s);
4047 +void qbman_swp_dqrr_consume(struct qbman_swp *s, const struct dpaa2_dq *dq);
4049 +int qbman_result_has_new_result(struct qbman_swp *p, const struct dpaa2_dq *dq);
4051 +void qbman_eq_desc_clear(struct qbman_eq_desc *d);
4052 +void qbman_eq_desc_set_no_orp(struct qbman_eq_desc *d, int respond_success);
4053 +void qbman_eq_desc_set_token(struct qbman_eq_desc *d, u8 token);
4054 +void qbman_eq_desc_set_fq(struct qbman_eq_desc *d, u32 fqid);
4055 +void qbman_eq_desc_set_qd(struct qbman_eq_desc *d, u32 qdid,
4056 + u32 qd_bin, u32 qd_prio);
4058 +int qbman_swp_enqueue(struct qbman_swp *p, const struct qbman_eq_desc *d,
4059 + const struct dpaa2_fd *fd);
4061 +void qbman_release_desc_clear(struct qbman_release_desc *d);
4062 +void qbman_release_desc_set_bpid(struct qbman_release_desc *d, u16 bpid);
4063 +void qbman_release_desc_set_rcdi(struct qbman_release_desc *d, int enable);
4065 +int qbman_swp_release(struct qbman_swp *s, const struct qbman_release_desc *d,
4066 + const u64 *buffers, unsigned int num_buffers);
4067 +int qbman_swp_acquire(struct qbman_swp *s, u16 bpid, u64 *buffers,
4068 + unsigned int num_buffers);
4069 +int qbman_swp_alt_fq_state(struct qbman_swp *s, u32 fqid,
4071 +int qbman_swp_CDAN_set(struct qbman_swp *s, u16 channelid,
4072 + u8 we_mask, u8 cdan_en,
4075 +void *qbman_swp_mc_start(struct qbman_swp *p);
4076 +void qbman_swp_mc_submit(struct qbman_swp *p, void *cmd, u8 cmd_verb);
4077 +void *qbman_swp_mc_result(struct qbman_swp *p);
4080 + * qbman_result_is_DQ() - check if the dequeue result is a dequeue response
4081 + * @dq: the dequeue result to be checked
4083 + * DQRR entries may contain non-dequeue results, ie. notifications
4085 +static inline int qbman_result_is_DQ(const struct dpaa2_dq *dq)
4087 + return ((dq->dq.verb & QBMAN_RESULT_MASK) == QBMAN_RESULT_DQ);
4091 + * qbman_result_is_SCN() - Check the dequeue result is notification or not
4092 + * @dq: the dequeue result to be checked
4095 +static inline int qbman_result_is_SCN(const struct dpaa2_dq *dq)
4097 + return !qbman_result_is_DQ(dq);
4100 +/* FQ Data Availability */
4101 +static inline int qbman_result_is_FQDAN(const struct dpaa2_dq *dq)
4103 + return ((dq->dq.verb & QBMAN_RESULT_MASK) == QBMAN_RESULT_FQDAN);
4106 +/* Channel Data Availability */
4107 +static inline int qbman_result_is_CDAN(const struct dpaa2_dq *dq)
4109 + return ((dq->dq.verb & QBMAN_RESULT_MASK) == QBMAN_RESULT_CDAN);
4112 +/* Congestion State Change */
4113 +static inline int qbman_result_is_CSCN(const struct dpaa2_dq *dq)
4115 + return ((dq->dq.verb & QBMAN_RESULT_MASK) == QBMAN_RESULT_CSCN_WQ);
4118 +/* Buffer Pool State Change */
4119 +static inline int qbman_result_is_BPSCN(const struct dpaa2_dq *dq)
4121 + return ((dq->dq.verb & QBMAN_RESULT_MASK) == QBMAN_RESULT_BPSCN);
4124 +/* Congestion Group Count Update */
4125 +static inline int qbman_result_is_CGCU(const struct dpaa2_dq *dq)
4127 + return ((dq->dq.verb & QBMAN_RESULT_MASK) == QBMAN_RESULT_CGCU);
4131 +static inline int qbman_result_is_FQRN(const struct dpaa2_dq *dq)
4133 + return ((dq->dq.verb & QBMAN_RESULT_MASK) == QBMAN_RESULT_FQRN);
4136 +/* Retirement Immediate */
4137 +static inline int qbman_result_is_FQRNI(const struct dpaa2_dq *dq)
4139 + return ((dq->dq.verb & QBMAN_RESULT_MASK) == QBMAN_RESULT_FQRNI);
4143 +static inline int qbman_result_is_FQPN(const struct dpaa2_dq *dq)
4145 + return ((dq->dq.verb & QBMAN_RESULT_MASK) == QBMAN_RESULT_FQPN);
4149 + * qbman_result_SCN_state() - Get the state field in State-change notification
4151 +static inline u8 qbman_result_SCN_state(const struct dpaa2_dq *scn)
4153 + return scn->scn.state;
4156 +#define SCN_RID_MASK 0x00FFFFFF
4159 + * qbman_result_SCN_rid() - Get the resource id in State-change notification
4161 +static inline u32 qbman_result_SCN_rid(const struct dpaa2_dq *scn)
4163 + return le32_to_cpu(scn->scn.rid_tok) & SCN_RID_MASK;
4167 + * qbman_result_SCN_ctx() - Get the context data in State-change notification
4169 +static inline u64 qbman_result_SCN_ctx(const struct dpaa2_dq *scn)
4171 + return le64_to_cpu(scn->scn.ctx);
4175 + * qbman_swp_fq_schedule() - Move the fq to the scheduled state
4176 + * @s: the software portal object
4177 + * @fqid: the index of frame queue to be scheduled
4179 + * There are a couple of different ways that a FQ can end up parked state,
4180 + * This schedules it.
4182 + * Return 0 for success, or negative error code for failure.
4184 +static inline int qbman_swp_fq_schedule(struct qbman_swp *s, u32 fqid)
4186 + return qbman_swp_alt_fq_state(s, fqid, QBMAN_FQ_SCHEDULE);
4190 + * qbman_swp_fq_force() - Force the FQ to fully scheduled state
4191 + * @s: the software portal object
4192 + * @fqid: the index of frame queue to be forced
4194 + * Force eligible will force a tentatively-scheduled FQ to be fully-scheduled
4195 + * and thus be available for selection by any channel-dequeuing behaviour (push
4196 + * or pull). If the FQ is subsequently "dequeued" from the channel and is still
4197 + * empty at the time this happens, the resulting dq_entry will have no FD.
4198 + * (qbman_result_DQ_fd() will return NULL.)
4200 + * Return 0 for success, or negative error code for failure.
4202 +static inline int qbman_swp_fq_force(struct qbman_swp *s, u32 fqid)
4204 + return qbman_swp_alt_fq_state(s, fqid, QBMAN_FQ_FORCE);
4208 + * qbman_swp_fq_xon() - sets FQ flow-control to XON
4209 + * @s: the software portal object
4210 + * @fqid: the index of frame queue
4212 + * This setting doesn't affect enqueues to the FQ, just dequeues.
4214 + * Return 0 for success, or negative error code for failure.
4216 +static inline int qbman_swp_fq_xon(struct qbman_swp *s, u32 fqid)
4218 + return qbman_swp_alt_fq_state(s, fqid, QBMAN_FQ_XON);
4222 + * qbman_swp_fq_xoff() - sets FQ flow-control to XOFF
4223 + * @s: the software portal object
4224 + * @fqid: the index of frame queue
4226 + * This setting doesn't affect enqueues to the FQ, just dequeues.
4227 + * XOFF FQs will remain in the tenatively-scheduled state, even when
4228 + * non-empty, meaning they won't be selected for scheduled dequeuing.
4229 + * If a FQ is changed to XOFF after it had already become truly-scheduled
4230 + * to a channel, and a pull dequeue of that channel occurs that selects
4231 + * that FQ for dequeuing, then the resulting dq_entry will have no FD.
4232 + * (qbman_result_DQ_fd() will return NULL.)
4234 + * Return 0 for success, or negative error code for failure.
4236 +static inline int qbman_swp_fq_xoff(struct qbman_swp *s, u32 fqid)
4238 + return qbman_swp_alt_fq_state(s, fqid, QBMAN_FQ_XOFF);
4241 +/* If the user has been allocated a channel object that is going to generate
4242 + * CDANs to another channel, then the qbman_swp_CDAN* functions will be
4245 + * CDAN-enabled channels only generate a single CDAN notification, after which
4246 + * they need to be reenabled before they'll generate another. The idea is
4247 + * that pull dequeuing will occur in reaction to the CDAN, followed by a
4248 + * reenable step. Each function generates a distinct command to hardware, so a
4249 + * combination function is provided if the user wishes to modify the "context"
4250 + * (which shows up in each CDAN message) each time they reenable, as a single
4251 + * command to hardware.
4255 + * qbman_swp_CDAN_set_context() - Set CDAN context
4256 + * @s: the software portal object
4257 + * @channelid: the channel index
4258 + * @ctx: the context to be set in CDAN
4260 + * Return 0 for success, or negative error code for failure.
4262 +static inline int qbman_swp_CDAN_set_context(struct qbman_swp *s, u16 channelid,
4265 + return qbman_swp_CDAN_set(s, channelid,
4271 + * qbman_swp_CDAN_enable() - Enable CDAN for the channel
4272 + * @s: the software portal object
4273 + * @channelid: the index of the channel to generate CDAN
4275 + * Return 0 for success, or negative error code for failure.
4277 +static inline int qbman_swp_CDAN_enable(struct qbman_swp *s, u16 channelid)
4279 + return qbman_swp_CDAN_set(s, channelid,
4285 + * qbman_swp_CDAN_disable() - disable CDAN for the channel
4286 + * @s: the software portal object
4287 + * @channelid: the index of the channel to generate CDAN
4289 + * Return 0 for success, or negative error code for failure.
4291 +static inline int qbman_swp_CDAN_disable(struct qbman_swp *s, u16 channelid)
4293 + return qbman_swp_CDAN_set(s, channelid,
4299 + * qbman_swp_CDAN_set_context_enable() - Set CDAN contest and enable CDAN
4300 + * @s: the software portal object
4301 + * @channelid: the index of the channel to generate CDAN
4302 + * @ctx:i the context set in CDAN
4304 + * Return 0 for success, or negative error code for failure.
4306 +static inline int qbman_swp_CDAN_set_context_enable(struct qbman_swp *s,
4310 + return qbman_swp_CDAN_set(s, channelid,
4311 + CODE_CDAN_WE_EN | CODE_CDAN_WE_CTX,
4315 +/* Wraps up submit + poll-for-result */
4316 +static inline void *qbman_swp_mc_complete(struct qbman_swp *swp, void *cmd,
4319 + int loopvar = 1000;
4321 + qbman_swp_mc_submit(swp, cmd, cmd_verb);
4324 + cmd = qbman_swp_mc_result(swp);
4325 + } while (!cmd && loopvar--);
4327 + WARN_ON(!loopvar);
4336 +/* This struct locates a sub-field within a QBMan portal (CENA) cacheline which
4337 + * is either serving as a configuration command or a query result. The
4338 + * representation is inherently little-endian, as the indexing of the words is
4339 + * itself little-endian in nature and layerscape is little endian for anything
4340 + * that crosses a word boundary too (64-bit fields are the obvious examples).
4342 +struct qb_attr_code {
4343 + unsigned int word; /* which u32[] array member encodes the field */
4344 + unsigned int lsoffset; /* encoding offset from ls-bit */
4345 + unsigned int width; /* encoding width. (bool must be 1.) */
4348 +/* Some pre-defined codes */
4349 +extern struct qb_attr_code code_generic_verb;
4350 +extern struct qb_attr_code code_generic_rslt;
4352 +/* Macros to define codes */
4353 +#define QB_CODE(a, b, c) { a, b, c}
4354 +#define QB_CODE_NULL \
4355 + QB_CODE((unsigned int)-1, (unsigned int)-1, (unsigned int)-1)
4357 +/* Rotate a code "ms", meaning that it moves from less-significant bytes to
4358 + * more-significant, from less-significant words to more-significant, etc. The
4359 + * "ls" version does the inverse, from more-significant towards
4360 + * less-significant.
4362 +static inline void qb_attr_code_rotate_ms(struct qb_attr_code *code,
4363 + unsigned int bits)
4365 + code->lsoffset += bits;
4366 + while (code->lsoffset > 31) {
4368 + code->lsoffset -= 32;
4372 +static inline void qb_attr_code_rotate_ls(struct qb_attr_code *code,
4373 + unsigned int bits)
4375 + /* Don't be fooled, this trick should work because the types are
4376 + * unsigned. So the case that interests the while loop (the rotate has
4377 + * gone too far and the word count needs to compensate for it), is
4378 + * manifested when lsoffset is negative. But that equates to a really
4379 + * large unsigned value, starting with lots of "F"s. As such, we can
4380 + * continue adding 32 back to it until it wraps back round above zero,
4381 + * to a value of 31 or less...
4383 + code->lsoffset -= bits;
4384 + while (code->lsoffset > 31) {
4386 + code->lsoffset += 32;
4390 +/* Implement a loop of code rotations until 'expr' evaluates to FALSE (0). */
4391 +#define qb_attr_code_for_ms(code, bits, expr) \
4392 + for (; expr; qb_attr_code_rotate_ms(code, bits))
4393 +#define qb_attr_code_for_ls(code, bits, expr) \
4394 + for (; expr; qb_attr_code_rotate_ls(code, bits))
4396 +static inline void word_copy(void *d, const void *s, unsigned int cnt)
4399 + const u32 *ss = s;
4402 + *(dd++) = *(ss++);
4406 + * Currently, the CENA support code expects each 32-bit word to be written in
4407 + * host order, and these are converted to hardware (little-endian) order on
4408 + * command submission. However, 64-bit quantities are must be written (and read)
4409 + * as two 32-bit words with the least-significant word first, irrespective of
4410 + * host endianness.
4412 +static inline void u64_to_le32_copy(void *d, const u64 *s,
4416 + const u32 *ss = (const u32 *)s;
4420 + * TBD: the toolchain was choking on the use of 64-bit types up
4421 + * until recently so this works entirely with 32-bit variables.
4422 + * When 64-bit types become usable again, investigate better
4423 + * ways of doing this.
4425 +#if defined(__BIG_ENDIAN)
4430 + *(dd++) = *(ss++);
4431 + *(dd++) = *(ss++);
4436 +static inline void u64_from_le32_copy(u64 *d, const void *s,
4439 + const u32 *ss = s;
4440 + u32 *dd = (u32 *)d;
4443 +#if defined(__BIG_ENDIAN)
4448 + *(dd++) = *(ss++);
4449 + *(dd++) = *(ss++);
4454 +/* decode a field from a cacheline */
4455 +static inline u32 qb_attr_code_decode(const struct qb_attr_code *code,
4456 + const u32 *cacheline)
4458 + return d32_u32(code->lsoffset, code->width, cacheline[code->word]);
4461 +static inline u64 qb_attr_code_decode_64(const struct qb_attr_code *code,
4462 + const u64 *cacheline)
4466 + u64_from_le32_copy(&res, &cacheline[code->word / 2], 1);
4470 +/* encode a field to a cacheline */
4471 +static inline void qb_attr_code_encode(const struct qb_attr_code *code,
4472 + u32 *cacheline, u32 val)
4474 + cacheline[code->word] =
4475 + r32_u32(code->lsoffset, code->width, cacheline[code->word])
4476 + | e32_u32(code->lsoffset, code->width, val);
4479 +static inline void qb_attr_code_encode_64(const struct qb_attr_code *code,
4480 + u64 *cacheline, u64 val)
4482 + u64_to_le32_copy(&cacheline[code->word / 2], &val, 1);
4485 +/* Small-width signed values (two's-complement) will decode into medium-width
4486 + * positives. (Eg. for an 8-bit signed field, which stores values from -128 to
4487 + * +127, a setting of -7 would appear to decode to the 32-bit unsigned value
4488 + * 249. Likewise -120 would decode as 136.) This function allows the caller to
4489 + * "re-sign" such fields to 32-bit signed. (Eg. -7, which was 249 with an 8-bit
4490 + * encoding, will become 0xfffffff9 if you cast the return value to u32).
4492 +static inline int32_t qb_attr_code_makesigned(const struct qb_attr_code *code,
4495 + WARN_ON(val >= (1 << code->width));
4496 + /* If the high bit was set, it was encoding a negative */
4497 + if (val >= (1 << (code->width - 1)))
4498 + return (int32_t)0 - (int32_t)(((u32)1 << code->width) -
4500 + /* Otherwise, it was encoding a positive */
4501 + return (int32_t)val;
4504 +/* ---------------------- */
4505 +/* Descriptors/cachelines */
4506 +/* ---------------------- */
4508 +/* To avoid needless dynamic allocation, the driver API often gives the caller
4509 + * a "descriptor" type that the caller can instantiate however they like.
4510 + * Ultimately though, it is just a cacheline of binary storage (or something
4511 + * smaller when it is known that the descriptor doesn't need all 64 bytes) for
4512 + * holding pre-formatted pieces of hardware commands. The performance-critical
4513 + * code can then copy these descriptors directly into hardware command
4514 + * registers more efficiently than trying to construct/format commands
4515 + * on-the-fly. The API user sees the descriptor as an array of 32-bit words in
4516 + * order for the compiler to know its size, but the internal details are not
4517 + * exposed. The following macro is used within the driver for converting *any*
4518 + * descriptor pointer to a usable array pointer. The use of a macro (instead of
4519 + * an inline) is necessary to work with different descriptor types and to work
4520 + * correctly with const and non-const inputs (and similarly-qualified outputs).
4522 +#define qb_cl(d) (&(d)->dont_manipulate_directly[0])
4524 +#endif /* __FSL_QBMAN_PORTAL_H */
4526 +++ b/drivers/staging/fsl-mc/bus/dpio/qbman_debug.c
4528 +/* Copyright (C) 2015 Freescale Semiconductor, Inc.
4530 + * Redistribution and use in source and binary forms, with or without
4531 + * modification, are permitted provided that the following conditions are met:
4532 + * * Redistributions of source code must retain the above copyright
4533 + * notice, this list of conditions and the following disclaimer.
4534 + * * Redistributions in binary form must reproduce the above copyright
4535 + * notice, this list of conditions and the following disclaimer in the
4536 + * documentation and/or other materials provided with the distribution.
4537 + * * Neither the name of Freescale Semiconductor nor the
4538 + * names of its contributors may be used to endorse or promote products
4539 + * derived from this software without specific prior written permission.
4542 + * ALTERNATIVELY, this software may be distributed under the terms of the
4543 + * GNU General Public License ("GPL") as published by the Free Software
4544 + * Foundation, either version 2 of that License or (at your option) any
4547 + * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
4548 + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
4549 + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
4550 + * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
4551 + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
4552 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
4553 + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
4554 + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
4555 + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
4556 + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4559 +#include <linux/errno.h>
4561 +#include "../../include/dpaa2-global.h"
4562 +#include "qbman-portal.h"
4563 +#include "qbman_debug.h"
4565 +/* QBMan portal management command code */
4566 +#define QBMAN_BP_QUERY 0x32
4567 +#define QBMAN_FQ_QUERY 0x44
4568 +#define QBMAN_FQ_QUERY_NP 0x45
4569 +#define QBMAN_CGR_QUERY 0x51
4570 +#define QBMAN_WRED_QUERY 0x54
4571 +#define QBMAN_CGR_STAT_QUERY 0x55
4572 +#define QBMAN_CGR_STAT_QUERY_CLR 0x56
4574 +enum qbman_attr_usage_e {
4575 + qbman_attr_usage_fq,
4576 + qbman_attr_usage_bpool,
4577 + qbman_attr_usage_cgr,
4580 +struct int_qbman_attr {
4582 + enum qbman_attr_usage_e usage;
4585 +#define attr_type_set(a, e) \
4587 + struct qbman_attr *__attr = a; \
4588 + enum qbman_attr_usage_e __usage = e; \
4589 + ((struct int_qbman_attr *)__attr)->usage = __usage; \
4592 +#define ATTR32(d) (&(d)->dont_manipulate_directly[0])
4593 +#define ATTR32_1(d) (&(d)->dont_manipulate_directly[16])
4595 +static struct qb_attr_code code_bp_bpid = QB_CODE(0, 16, 16);
4596 +static struct qb_attr_code code_bp_bdi = QB_CODE(1, 16, 1);
4597 +static struct qb_attr_code code_bp_va = QB_CODE(1, 17, 1);
4598 +static struct qb_attr_code code_bp_wae = QB_CODE(1, 18, 1);
4599 +static struct qb_attr_code code_bp_swdet = QB_CODE(4, 0, 16);
4600 +static struct qb_attr_code code_bp_swdxt = QB_CODE(4, 16, 16);
4601 +static struct qb_attr_code code_bp_hwdet = QB_CODE(5, 0, 16);
4602 +static struct qb_attr_code code_bp_hwdxt = QB_CODE(5, 16, 16);
4603 +static struct qb_attr_code code_bp_swset = QB_CODE(6, 0, 16);
4604 +static struct qb_attr_code code_bp_swsxt = QB_CODE(6, 16, 16);
4605 +static struct qb_attr_code code_bp_vbpid = QB_CODE(7, 0, 14);
4606 +static struct qb_attr_code code_bp_icid = QB_CODE(7, 16, 15);
4607 +static struct qb_attr_code code_bp_pl = QB_CODE(7, 31, 1);
4608 +static struct qb_attr_code code_bp_bpscn_addr_lo = QB_CODE(8, 0, 32);
4609 +static struct qb_attr_code code_bp_bpscn_addr_hi = QB_CODE(9, 0, 32);
4610 +static struct qb_attr_code code_bp_bpscn_ctx_lo = QB_CODE(10, 0, 32);
4611 +static struct qb_attr_code code_bp_bpscn_ctx_hi = QB_CODE(11, 0, 32);
4612 +static struct qb_attr_code code_bp_hw_targ = QB_CODE(12, 0, 16);
4613 +static struct qb_attr_code code_bp_state = QB_CODE(1, 24, 3);
4614 +static struct qb_attr_code code_bp_fill = QB_CODE(2, 0, 32);
4615 +static struct qb_attr_code code_bp_hdptr = QB_CODE(3, 0, 32);
4616 +static struct qb_attr_code code_bp_sdcnt = QB_CODE(13, 0, 8);
4617 +static struct qb_attr_code code_bp_hdcnt = QB_CODE(13, 1, 8);
4618 +static struct qb_attr_code code_bp_sscnt = QB_CODE(13, 2, 8);
4620 +void qbman_bp_attr_clear(struct qbman_attr *a)
4622 + memset(a, 0, sizeof(*a));
4623 + attr_type_set(a, qbman_attr_usage_bpool);
4626 +int qbman_bp_query(struct qbman_swp *s, u32 bpid,
4627 + struct qbman_attr *a)
4631 + u32 *attr = ATTR32(a);
4633 + qbman_bp_attr_clear(a);
4635 + /* Start the management command */
4636 + p = qbman_swp_mc_start(s);
4640 + /* Encode the caller-provided attributes */
4641 + qb_attr_code_encode(&code_bp_bpid, p, bpid);
4643 + /* Complete the management command */
4644 + p = qbman_swp_mc_complete(s, p, QBMAN_BP_QUERY);
4646 + /* Decode the outcome */
4647 + verb = qb_attr_code_decode(&code_generic_verb, p);
4648 + rslt = qb_attr_code_decode(&code_generic_rslt, p);
4649 + WARN_ON(verb != QBMAN_BP_QUERY);
4651 + /* Determine success or failure */
4652 + if (unlikely(rslt != QBMAN_MC_RSLT_OK)) {
4653 + pr_err("Query of BPID 0x%x failed, code=0x%02x\n", bpid, rslt);
4657 + /* For the query, word[0] of the result contains only the
4658 + * verb/rslt fields, so skip word[0].
4660 + word_copy(&attr[1], &p[1], 15);
4664 +void qbman_bp_attr_get_bdi(struct qbman_attr *a, int *bdi, int *va, int *wae)
4666 + u32 *p = ATTR32(a);
4668 + *bdi = !!qb_attr_code_decode(&code_bp_bdi, p);
4669 + *va = !!qb_attr_code_decode(&code_bp_va, p);
4670 + *wae = !!qb_attr_code_decode(&code_bp_wae, p);
4673 +static u32 qbman_bp_thresh_to_value(u32 val)
4675 + return (val & 0xff) << ((val & 0xf00) >> 8);
4678 +void qbman_bp_attr_get_swdet(struct qbman_attr *a, u32 *swdet)
4680 + u32 *p = ATTR32(a);
4682 + *swdet = qbman_bp_thresh_to_value(qb_attr_code_decode(&code_bp_swdet,
4686 +void qbman_bp_attr_get_swdxt(struct qbman_attr *a, u32 *swdxt)
4688 + u32 *p = ATTR32(a);
4690 + *swdxt = qbman_bp_thresh_to_value(qb_attr_code_decode(&code_bp_swdxt,
4694 +void qbman_bp_attr_get_hwdet(struct qbman_attr *a, u32 *hwdet)
4696 + u32 *p = ATTR32(a);
4698 + *hwdet = qbman_bp_thresh_to_value(qb_attr_code_decode(&code_bp_hwdet,
4702 +void qbman_bp_attr_get_hwdxt(struct qbman_attr *a, u32 *hwdxt)
4704 + u32 *p = ATTR32(a);
4706 + *hwdxt = qbman_bp_thresh_to_value(qb_attr_code_decode(&code_bp_hwdxt,
4710 +void qbman_bp_attr_get_swset(struct qbman_attr *a, u32 *swset)
4712 + u32 *p = ATTR32(a);
4714 + *swset = qbman_bp_thresh_to_value(qb_attr_code_decode(&code_bp_swset,
4718 +void qbman_bp_attr_get_swsxt(struct qbman_attr *a, u32 *swsxt)
4720 + u32 *p = ATTR32(a);
4722 + *swsxt = qbman_bp_thresh_to_value(qb_attr_code_decode(&code_bp_swsxt,
4726 +void qbman_bp_attr_get_vbpid(struct qbman_attr *a, u32 *vbpid)
4728 + u32 *p = ATTR32(a);
4730 + *vbpid = qb_attr_code_decode(&code_bp_vbpid, p);
4733 +void qbman_bp_attr_get_icid(struct qbman_attr *a, u32 *icid, int *pl)
4735 + u32 *p = ATTR32(a);
4737 + *icid = qb_attr_code_decode(&code_bp_icid, p);
4738 + *pl = !!qb_attr_code_decode(&code_bp_pl, p);
4741 +void qbman_bp_attr_get_bpscn_addr(struct qbman_attr *a, u64 *bpscn_addr)
4743 + u32 *p = ATTR32(a);
4745 + *bpscn_addr = ((u64)qb_attr_code_decode(&code_bp_bpscn_addr_hi,
4747 + (u64)qb_attr_code_decode(&code_bp_bpscn_addr_lo,
4751 +void qbman_bp_attr_get_bpscn_ctx(struct qbman_attr *a, u64 *bpscn_ctx)
4753 + u32 *p = ATTR32(a);
4755 + *bpscn_ctx = ((u64)qb_attr_code_decode(&code_bp_bpscn_ctx_hi, p)
4757 + (u64)qb_attr_code_decode(&code_bp_bpscn_ctx_lo,
4761 +void qbman_bp_attr_get_hw_targ(struct qbman_attr *a, u32 *hw_targ)
4763 + u32 *p = ATTR32(a);
4765 + *hw_targ = qb_attr_code_decode(&code_bp_hw_targ, p);
4768 +int qbman_bp_info_has_free_bufs(struct qbman_attr *a)
4770 + u32 *p = ATTR32(a);
4772 + return !(int)(qb_attr_code_decode(&code_bp_state, p) & 0x1);
4775 +int qbman_bp_info_is_depleted(struct qbman_attr *a)
4777 + u32 *p = ATTR32(a);
4779 + return (int)(qb_attr_code_decode(&code_bp_state, p) & 0x2);
4782 +int qbman_bp_info_is_surplus(struct qbman_attr *a)
4784 + u32 *p = ATTR32(a);
4786 + return (int)(qb_attr_code_decode(&code_bp_state, p) & 0x4);
4789 +u32 qbman_bp_info_num_free_bufs(struct qbman_attr *a)
4791 + u32 *p = ATTR32(a);
4793 + return qb_attr_code_decode(&code_bp_fill, p);
4796 +u32 qbman_bp_info_hdptr(struct qbman_attr *a)
4798 + u32 *p = ATTR32(a);
4800 + return qb_attr_code_decode(&code_bp_hdptr, p);
4803 +u32 qbman_bp_info_sdcnt(struct qbman_attr *a)
4805 + u32 *p = ATTR32(a);
4807 + return qb_attr_code_decode(&code_bp_sdcnt, p);
4810 +u32 qbman_bp_info_hdcnt(struct qbman_attr *a)
4812 + u32 *p = ATTR32(a);
4814 + return qb_attr_code_decode(&code_bp_hdcnt, p);
4817 +u32 qbman_bp_info_sscnt(struct qbman_attr *a)
4819 + u32 *p = ATTR32(a);
4821 + return qb_attr_code_decode(&code_bp_sscnt, p);
4824 +static struct qb_attr_code code_fq_fqid = QB_CODE(1, 0, 24);
4825 +static struct qb_attr_code code_fq_cgrid = QB_CODE(2, 16, 16);
4826 +static struct qb_attr_code code_fq_destwq = QB_CODE(3, 0, 15);
4827 +static struct qb_attr_code code_fq_fqctrl = QB_CODE(3, 24, 8);
4828 +static struct qb_attr_code code_fq_icscred = QB_CODE(4, 0, 15);
4829 +static struct qb_attr_code code_fq_tdthresh = QB_CODE(4, 16, 13);
4830 +static struct qb_attr_code code_fq_oa_len = QB_CODE(5, 0, 12);
4831 +static struct qb_attr_code code_fq_oa_ics = QB_CODE(5, 14, 1);
4832 +static struct qb_attr_code code_fq_oa_cgr = QB_CODE(5, 15, 1);
4833 +static struct qb_attr_code code_fq_mctl_bdi = QB_CODE(5, 24, 1);
4834 +static struct qb_attr_code code_fq_mctl_ff = QB_CODE(5, 25, 1);
4835 +static struct qb_attr_code code_fq_mctl_va = QB_CODE(5, 26, 1);
4836 +static struct qb_attr_code code_fq_mctl_ps = QB_CODE(5, 27, 1);
4837 +static struct qb_attr_code code_fq_ctx_lower32 = QB_CODE(6, 0, 32);
4838 +static struct qb_attr_code code_fq_ctx_upper32 = QB_CODE(7, 0, 32);
4839 +static struct qb_attr_code code_fq_icid = QB_CODE(8, 0, 15);
4840 +static struct qb_attr_code code_fq_pl = QB_CODE(8, 15, 1);
4841 +static struct qb_attr_code code_fq_vfqid = QB_CODE(9, 0, 24);
4842 +static struct qb_attr_code code_fq_erfqid = QB_CODE(10, 0, 24);
4844 +void qbman_fq_attr_clear(struct qbman_attr *a)
4846 + memset(a, 0, sizeof(*a));
4847 + attr_type_set(a, qbman_attr_usage_fq);
4850 +/* FQ query function for programmable fields */
4851 +int qbman_fq_query(struct qbman_swp *s, u32 fqid, struct qbman_attr *desc)
4855 + u32 *d = ATTR32(desc);
4857 + qbman_fq_attr_clear(desc);
4859 + p = qbman_swp_mc_start(s);
4862 + qb_attr_code_encode(&code_fq_fqid, p, fqid);
4863 + p = qbman_swp_mc_complete(s, p, QBMAN_FQ_QUERY);
4865 + /* Decode the outcome */
4866 + verb = qb_attr_code_decode(&code_generic_verb, p);
4867 + rslt = qb_attr_code_decode(&code_generic_rslt, p);
4868 + WARN_ON(verb != QBMAN_FQ_QUERY);
4870 + /* Determine success or failure */
4871 + if (unlikely(rslt != QBMAN_MC_RSLT_OK)) {
4872 + pr_err("Query of FQID 0x%x failed, code=0x%02x\n",
4877 + * For the configure, word[0] of the command contains only the WE-mask.
4878 + * For the query, word[0] of the result contains only the verb/rslt
4879 + * fields. Skip word[0] in the latter case.
4881 + word_copy(&d[1], &p[1], 15);
4885 +void qbman_fq_attr_get_fqctrl(struct qbman_attr *d, u32 *fqctrl)
4887 + u32 *p = ATTR32(d);
4889 + *fqctrl = qb_attr_code_decode(&code_fq_fqctrl, p);
4892 +void qbman_fq_attr_get_cgrid(struct qbman_attr *d, u32 *cgrid)
4894 + u32 *p = ATTR32(d);
4896 + *cgrid = qb_attr_code_decode(&code_fq_cgrid, p);
4899 +void qbman_fq_attr_get_destwq(struct qbman_attr *d, u32 *destwq)
4901 + u32 *p = ATTR32(d);
4903 + *destwq = qb_attr_code_decode(&code_fq_destwq, p);
4906 +void qbman_fq_attr_get_icscred(struct qbman_attr *d, u32 *icscred)
4908 + u32 *p = ATTR32(d);
4910 + *icscred = qb_attr_code_decode(&code_fq_icscred, p);
4913 +static struct qb_attr_code code_tdthresh_exp = QB_CODE(0, 0, 5);
4914 +static struct qb_attr_code code_tdthresh_mant = QB_CODE(0, 5, 8);
4915 +static u32 qbman_thresh_to_value(u32 val)
4919 + m = qb_attr_code_decode(&code_tdthresh_mant, &val);
4920 + e = qb_attr_code_decode(&code_tdthresh_exp, &val);
4924 +void qbman_fq_attr_get_tdthresh(struct qbman_attr *d, u32 *tdthresh)
4926 + u32 *p = ATTR32(d);
4928 + *tdthresh = qbman_thresh_to_value(qb_attr_code_decode(&code_fq_tdthresh,
4932 +void qbman_fq_attr_get_oa(struct qbman_attr *d,
4933 + int *oa_ics, int *oa_cgr, int32_t *oa_len)
4935 + u32 *p = ATTR32(d);
4937 + *oa_ics = !!qb_attr_code_decode(&code_fq_oa_ics, p);
4938 + *oa_cgr = !!qb_attr_code_decode(&code_fq_oa_cgr, p);
4939 + *oa_len = qb_attr_code_makesigned(&code_fq_oa_len,
4940 + qb_attr_code_decode(&code_fq_oa_len, p));
4943 +void qbman_fq_attr_get_mctl(struct qbman_attr *d,
4944 + int *bdi, int *ff, int *va, int *ps)
4946 + u32 *p = ATTR32(d);
4948 + *bdi = !!qb_attr_code_decode(&code_fq_mctl_bdi, p);
4949 + *ff = !!qb_attr_code_decode(&code_fq_mctl_ff, p);
4950 + *va = !!qb_attr_code_decode(&code_fq_mctl_va, p);
4951 + *ps = !!qb_attr_code_decode(&code_fq_mctl_ps, p);
4954 +void qbman_fq_attr_get_ctx(struct qbman_attr *d, u32 *hi, u32 *lo)
4956 + u32 *p = ATTR32(d);
4958 + *hi = qb_attr_code_decode(&code_fq_ctx_upper32, p);
4959 + *lo = qb_attr_code_decode(&code_fq_ctx_lower32, p);
4962 +void qbman_fq_attr_get_icid(struct qbman_attr *d, u32 *icid, int *pl)
4964 + u32 *p = ATTR32(d);
4966 + *icid = qb_attr_code_decode(&code_fq_icid, p);
4967 + *pl = !!qb_attr_code_decode(&code_fq_pl, p);
4970 +void qbman_fq_attr_get_vfqid(struct qbman_attr *d, u32 *vfqid)
4972 + u32 *p = ATTR32(d);
4974 + *vfqid = qb_attr_code_decode(&code_fq_vfqid, p);
4977 +void qbman_fq_attr_get_erfqid(struct qbman_attr *d, u32 *erfqid)
4979 + u32 *p = ATTR32(d);
4981 + *erfqid = qb_attr_code_decode(&code_fq_erfqid, p);
4984 +/* Query FQ Non-Programmalbe Fields */
4985 +static struct qb_attr_code code_fq_np_state = QB_CODE(0, 16, 3);
4986 +static struct qb_attr_code code_fq_np_fe = QB_CODE(0, 19, 1);
4987 +static struct qb_attr_code code_fq_np_x = QB_CODE(0, 20, 1);
4988 +static struct qb_attr_code code_fq_np_r = QB_CODE(0, 21, 1);
4989 +static struct qb_attr_code code_fq_np_oe = QB_CODE(0, 22, 1);
4990 +static struct qb_attr_code code_fq_np_frm_cnt = QB_CODE(6, 0, 24);
4991 +static struct qb_attr_code code_fq_np_byte_cnt = QB_CODE(7, 0, 32);
4993 +int qbman_fq_query_state(struct qbman_swp *s, u32 fqid,
4994 + struct qbman_attr *state)
4998 + u32 *d = ATTR32(state);
5000 + qbman_fq_attr_clear(state);
5002 + p = qbman_swp_mc_start(s);
5005 + qb_attr_code_encode(&code_fq_fqid, p, fqid);
5006 + p = qbman_swp_mc_complete(s, p, QBMAN_FQ_QUERY_NP);
5008 + /* Decode the outcome */
5009 + verb = qb_attr_code_decode(&code_generic_verb, p);
5010 + rslt = qb_attr_code_decode(&code_generic_rslt, p);
5011 + WARN_ON(verb != QBMAN_FQ_QUERY_NP);
5013 + /* Determine success or failure */
5014 + if (unlikely(rslt != QBMAN_MC_RSLT_OK)) {
5015 + pr_err("Query NP fields of FQID 0x%x failed, code=0x%02x\n",
5019 + word_copy(&d[0], &p[0], 16);
5023 +u32 qbman_fq_state_schedstate(const struct qbman_attr *state)
5025 + const u32 *p = ATTR32(state);
5027 + return qb_attr_code_decode(&code_fq_np_state, p);
5030 +int qbman_fq_state_force_eligible(const struct qbman_attr *state)
5032 + const u32 *p = ATTR32(state);
5034 + return !!qb_attr_code_decode(&code_fq_np_fe, p);
5037 +int qbman_fq_state_xoff(const struct qbman_attr *state)
5039 + const u32 *p = ATTR32(state);
5041 + return !!qb_attr_code_decode(&code_fq_np_x, p);
5044 +int qbman_fq_state_retirement_pending(const struct qbman_attr *state)
5046 + const u32 *p = ATTR32(state);
5048 + return !!qb_attr_code_decode(&code_fq_np_r, p);
5051 +int qbman_fq_state_overflow_error(const struct qbman_attr *state)
5053 + const u32 *p = ATTR32(state);
5055 + return !!qb_attr_code_decode(&code_fq_np_oe, p);
5058 +u32 qbman_fq_state_frame_count(const struct qbman_attr *state)
5060 + const u32 *p = ATTR32(state);
5062 + return qb_attr_code_decode(&code_fq_np_frm_cnt, p);
5065 +u32 qbman_fq_state_byte_count(const struct qbman_attr *state)
5067 + const u32 *p = ATTR32(state);
5069 + return qb_attr_code_decode(&code_fq_np_byte_cnt, p);
5073 +static struct qb_attr_code code_cgr_cgid = QB_CODE(0, 16, 16);
5074 +static struct qb_attr_code code_cgr_cscn_wq_en_enter = QB_CODE(2, 0, 1);
5075 +static struct qb_attr_code code_cgr_cscn_wq_en_exit = QB_CODE(2, 1, 1);
5076 +static struct qb_attr_code code_cgr_cscn_wq_icd = QB_CODE(2, 2, 1);
5077 +static struct qb_attr_code code_cgr_mode = QB_CODE(3, 16, 2);
5078 +static struct qb_attr_code code_cgr_rej_cnt_mode = QB_CODE(3, 18, 1);
5079 +static struct qb_attr_code code_cgr_cscn_bdi = QB_CODE(3, 19, 1);
5080 +static struct qb_attr_code code_cgr_cscn_wr_en_enter = QB_CODE(3, 24, 1);
5081 +static struct qb_attr_code code_cgr_cscn_wr_en_exit = QB_CODE(3, 25, 1);
5082 +static struct qb_attr_code code_cgr_cg_wr_ae = QB_CODE(3, 26, 1);
5083 +static struct qb_attr_code code_cgr_cscn_dcp_en = QB_CODE(3, 27, 1);
5084 +static struct qb_attr_code code_cgr_cg_wr_va = QB_CODE(3, 28, 1);
5085 +static struct qb_attr_code code_cgr_i_cnt_wr_en = QB_CODE(4, 0, 1);
5086 +static struct qb_attr_code code_cgr_i_cnt_wr_bnd = QB_CODE(4, 1, 5);
5087 +static struct qb_attr_code code_cgr_td_en = QB_CODE(4, 8, 1);
5088 +static struct qb_attr_code code_cgr_cs_thres = QB_CODE(4, 16, 13);
5089 +static struct qb_attr_code code_cgr_cs_thres_x = QB_CODE(5, 0, 13);
5090 +static struct qb_attr_code code_cgr_td_thres = QB_CODE(5, 16, 13);
5091 +static struct qb_attr_code code_cgr_cscn_tdcp = QB_CODE(6, 0, 16);
5092 +static struct qb_attr_code code_cgr_cscn_wqid = QB_CODE(6, 16, 16);
5093 +static struct qb_attr_code code_cgr_cscn_vcgid = QB_CODE(7, 0, 16);
5094 +static struct qb_attr_code code_cgr_cg_icid = QB_CODE(7, 16, 15);
5095 +static struct qb_attr_code code_cgr_cg_pl = QB_CODE(7, 31, 1);
5096 +static struct qb_attr_code code_cgr_cg_wr_addr_lo = QB_CODE(8, 0, 32);
5097 +static struct qb_attr_code code_cgr_cg_wr_addr_hi = QB_CODE(9, 0, 32);
5098 +static struct qb_attr_code code_cgr_cscn_ctx_lo = QB_CODE(10, 0, 32);
5099 +static struct qb_attr_code code_cgr_cscn_ctx_hi = QB_CODE(11, 0, 32);
5101 +void qbman_cgr_attr_clear(struct qbman_attr *a)
5103 + memset(a, 0, sizeof(*a));
5104 + attr_type_set(a, qbman_attr_usage_cgr);
5107 +int qbman_cgr_query(struct qbman_swp *s, u32 cgid, struct qbman_attr *attr)
5115 + d[0] = ATTR32(attr);
5116 + d[1] = ATTR32_1(attr);
5118 + qbman_cgr_attr_clear(attr);
5120 + for (i = 0; i < 2; i++) {
5121 + p = qbman_swp_mc_start(s);
5124 + query_verb = i ? QBMAN_WRED_QUERY : QBMAN_CGR_QUERY;
5126 + qb_attr_code_encode(&code_cgr_cgid, p, cgid);
5127 + p = qbman_swp_mc_complete(s, p, p[0] | query_verb);
5129 + /* Decode the outcome */
5130 + verb = qb_attr_code_decode(&code_generic_verb, p);
5131 + rslt = qb_attr_code_decode(&code_generic_rslt, p);
5132 + WARN_ON(verb != query_verb);
5134 + /* Determine success or failure */
5135 + if (unlikely(rslt != QBMAN_MC_RSLT_OK)) {
5136 + pr_err("Query CGID 0x%x failed,", cgid);
5137 + pr_err(" verb=0x%02x, code=0x%02x\n", verb, rslt);
5140 + /* For the configure, word[0] of the command contains only the
5141 + * verb/cgid. For the query, word[0] of the result contains
5142 + * only the verb/rslt fields. Skip word[0] in the latter case.
5144 + word_copy(&d[i][1], &p[1], 15);
5149 +void qbman_cgr_attr_get_ctl1(struct qbman_attr *d, int *cscn_wq_en_enter,
5150 + int *cscn_wq_en_exit, int *cscn_wq_icd)
5152 + u32 *p = ATTR32(d);
5153 + *cscn_wq_en_enter = !!qb_attr_code_decode(&code_cgr_cscn_wq_en_enter,
5155 + *cscn_wq_en_exit = !!qb_attr_code_decode(&code_cgr_cscn_wq_en_exit, p);
5156 + *cscn_wq_icd = !!qb_attr_code_decode(&code_cgr_cscn_wq_icd, p);
5159 +void qbman_cgr_attr_get_mode(struct qbman_attr *d, u32 *mode,
5160 + int *rej_cnt_mode, int *cscn_bdi)
5162 + u32 *p = ATTR32(d);
5163 + *mode = qb_attr_code_decode(&code_cgr_mode, p);
5164 + *rej_cnt_mode = !!qb_attr_code_decode(&code_cgr_rej_cnt_mode, p);
5165 + *cscn_bdi = !!qb_attr_code_decode(&code_cgr_cscn_bdi, p);
5168 +void qbman_cgr_attr_get_ctl2(struct qbman_attr *d, int *cscn_wr_en_enter,
5169 + int *cscn_wr_en_exit, int *cg_wr_ae,
5170 + int *cscn_dcp_en, int *cg_wr_va)
5172 + u32 *p = ATTR32(d);
5173 + *cscn_wr_en_enter = !!qb_attr_code_decode(&code_cgr_cscn_wr_en_enter,
5175 + *cscn_wr_en_exit = !!qb_attr_code_decode(&code_cgr_cscn_wr_en_exit, p);
5176 + *cg_wr_ae = !!qb_attr_code_decode(&code_cgr_cg_wr_ae, p);
5177 + *cscn_dcp_en = !!qb_attr_code_decode(&code_cgr_cscn_dcp_en, p);
5178 + *cg_wr_va = !!qb_attr_code_decode(&code_cgr_cg_wr_va, p);
5181 +void qbman_cgr_attr_get_iwc(struct qbman_attr *d, int *i_cnt_wr_en,
5182 + u32 *i_cnt_wr_bnd)
5184 + u32 *p = ATTR32(d);
5185 + *i_cnt_wr_en = !!qb_attr_code_decode(&code_cgr_i_cnt_wr_en, p);
5186 + *i_cnt_wr_bnd = qb_attr_code_decode(&code_cgr_i_cnt_wr_bnd, p);
5189 +void qbman_cgr_attr_get_tdc(struct qbman_attr *d, int *td_en)
5191 + u32 *p = ATTR32(d);
5192 + *td_en = !!qb_attr_code_decode(&code_cgr_td_en, p);
5195 +void qbman_cgr_attr_get_cs_thres(struct qbman_attr *d, u32 *cs_thres)
5197 + u32 *p = ATTR32(d);
5198 + *cs_thres = qbman_thresh_to_value(qb_attr_code_decode(
5199 + &code_cgr_cs_thres, p));
5202 +void qbman_cgr_attr_get_cs_thres_x(struct qbman_attr *d,
5205 + u32 *p = ATTR32(d);
5206 + *cs_thres_x = qbman_thresh_to_value(qb_attr_code_decode(
5207 + &code_cgr_cs_thres_x, p));
5210 +void qbman_cgr_attr_get_td_thres(struct qbman_attr *d, u32 *td_thres)
5212 + u32 *p = ATTR32(d);
5213 + *td_thres = qbman_thresh_to_value(qb_attr_code_decode(
5214 + &code_cgr_td_thres, p));
5217 +void qbman_cgr_attr_get_cscn_tdcp(struct qbman_attr *d, u32 *cscn_tdcp)
5219 + u32 *p = ATTR32(d);
5220 + *cscn_tdcp = qb_attr_code_decode(&code_cgr_cscn_tdcp, p);
5223 +void qbman_cgr_attr_get_cscn_wqid(struct qbman_attr *d, u32 *cscn_wqid)
5225 + u32 *p = ATTR32(d);
5226 + *cscn_wqid = qb_attr_code_decode(&code_cgr_cscn_wqid, p);
5229 +void qbman_cgr_attr_get_cscn_vcgid(struct qbman_attr *d,
5232 + u32 *p = ATTR32(d);
5233 + *cscn_vcgid = qb_attr_code_decode(&code_cgr_cscn_vcgid, p);
5236 +void qbman_cgr_attr_get_cg_icid(struct qbman_attr *d, u32 *icid,
5239 + u32 *p = ATTR32(d);
5240 + *icid = qb_attr_code_decode(&code_cgr_cg_icid, p);
5241 + *pl = !!qb_attr_code_decode(&code_cgr_cg_pl, p);
5244 +void qbman_cgr_attr_get_cg_wr_addr(struct qbman_attr *d,
5247 + u32 *p = ATTR32(d);
5248 + *cg_wr_addr = ((u64)qb_attr_code_decode(&code_cgr_cg_wr_addr_hi,
5250 + (u64)qb_attr_code_decode(&code_cgr_cg_wr_addr_lo,
5254 +void qbman_cgr_attr_get_cscn_ctx(struct qbman_attr *d, u64 *cscn_ctx)
5256 + u32 *p = ATTR32(d);
5257 + *cscn_ctx = ((u64)qb_attr_code_decode(&code_cgr_cscn_ctx_hi, p)
5259 + (u64)qb_attr_code_decode(&code_cgr_cscn_ctx_lo, p);
5262 +#define WRED_EDP_WORD(n) (18 + (n) / 4)
5263 +#define WRED_EDP_OFFSET(n) (8 * ((n) % 4))
5264 +#define WRED_PARM_DP_WORD(n) ((n) + 20)
5265 +#define WRED_WE_EDP(n) (16 + (n) * 2)
5266 +#define WRED_WE_PARM_DP(n) (17 + (n) * 2)
5267 +void qbman_cgr_attr_wred_get_edp(struct qbman_attr *d, u32 idx,
5270 + u32 *p = ATTR32(d);
5271 + struct qb_attr_code code_wred_edp = QB_CODE(WRED_EDP_WORD(idx),
5272 + WRED_EDP_OFFSET(idx), 8);
5273 + *edp = (int)qb_attr_code_decode(&code_wred_edp, p);
5276 +void qbman_cgr_attr_wred_dp_decompose(u32 dp, u64 *minth,
5277 + u64 *maxth, u8 *maxp)
5279 + u8 ma, mn, step_i, step_s, pn;
5281 + ma = (u8)(dp >> 24);
5282 + mn = (u8)(dp >> 19) & 0x1f;
5283 + step_i = (u8)(dp >> 11);
5284 + step_s = (u8)(dp >> 6) & 0x1f;
5285 + pn = (u8)dp & 0x3f;
5287 + *maxp = ((pn << 2) * 100) / 256;
5292 + *maxth = ((ma + 256) * (1 << (mn - 1)));
5295 + *minth = *maxth - step_i;
5297 + *minth = *maxth - (256 + step_i) * (1 << (step_s - 1));
5300 +void qbman_cgr_attr_wred_get_parm_dp(struct qbman_attr *d, u32 idx,
5303 + u32 *p = ATTR32(d);
5304 + struct qb_attr_code code_wred_parm_dp = QB_CODE(WRED_PARM_DP_WORD(idx),
5306 + *dp = qb_attr_code_decode(&code_wred_parm_dp, p);
5309 +/* Query CGR/CCGR/CQ statistics */
5310 +static struct qb_attr_code code_cgr_stat_ct = QB_CODE(4, 0, 32);
5311 +static struct qb_attr_code code_cgr_stat_frame_cnt_lo = QB_CODE(4, 0, 32);
5312 +static struct qb_attr_code code_cgr_stat_frame_cnt_hi = QB_CODE(5, 0, 8);
5313 +static struct qb_attr_code code_cgr_stat_byte_cnt_lo = QB_CODE(6, 0, 32);
5314 +static struct qb_attr_code code_cgr_stat_byte_cnt_hi = QB_CODE(7, 0, 16);
5315 +static int qbman_cgr_statistics_query(struct qbman_swp *s, u32 cgid,
5316 + int clear, u32 command_type,
5317 + u64 *frame_cnt, u64 *byte_cnt)
5324 + p = qbman_swp_mc_start(s);
5328 + qb_attr_code_encode(&code_cgr_cgid, p, cgid);
5329 + if (command_type < 2)
5330 + qb_attr_code_encode(&code_cgr_stat_ct, p, command_type);
5331 + query_verb = clear ?
5332 + QBMAN_CGR_STAT_QUERY_CLR : QBMAN_CGR_STAT_QUERY;
5333 + p = qbman_swp_mc_complete(s, p, p[0] | query_verb);
5335 + /* Decode the outcome */
5336 + verb = qb_attr_code_decode(&code_generic_verb, p);
5337 + rslt = qb_attr_code_decode(&code_generic_rslt, p);
5338 + WARN_ON(verb != query_verb);
5340 + /* Determine success or failure */
5341 + if (unlikely(rslt != QBMAN_MC_RSLT_OK)) {
5342 + pr_err("Query statistics of CGID 0x%x failed,", cgid);
5343 + pr_err(" verb=0x%02x code=0x%02x\n", verb, rslt);
5348 + hi = qb_attr_code_decode(&code_cgr_stat_frame_cnt_hi, p);
5349 + lo = qb_attr_code_decode(&code_cgr_stat_frame_cnt_lo, p);
5350 + *frame_cnt = ((u64)hi << 32) | (u64)lo;
5353 + hi = qb_attr_code_decode(&code_cgr_stat_byte_cnt_hi, p);
5354 + lo = qb_attr_code_decode(&code_cgr_stat_byte_cnt_lo, p);
5355 + *byte_cnt = ((u64)hi << 32) | (u64)lo;
5361 +int qbman_cgr_reject_statistics(struct qbman_swp *s, u32 cgid, int clear,
5362 + u64 *frame_cnt, u64 *byte_cnt)
5364 + return qbman_cgr_statistics_query(s, cgid, clear, 0xff,
5365 + frame_cnt, byte_cnt);
5368 +int qbman_ccgr_reject_statistics(struct qbman_swp *s, u32 cgid, int clear,
5369 + u64 *frame_cnt, u64 *byte_cnt)
5371 + return qbman_cgr_statistics_query(s, cgid, clear, 1,
5372 + frame_cnt, byte_cnt);
5375 +int qbman_cq_dequeue_statistics(struct qbman_swp *s, u32 cgid, int clear,
5376 + u64 *frame_cnt, u64 *byte_cnt)
5378 + return qbman_cgr_statistics_query(s, cgid, clear, 0,
5379 + frame_cnt, byte_cnt);
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);
5521 +++ b/drivers/staging/fsl-mc/bus/dpio/qbman_private.h
5523 +/* Copyright (C) 2014 Freescale Semiconductor, Inc.
5525 + * Redistribution and use in source and binary forms, with or without
5526 + * modification, are permitted provided that the following conditions are met:
5527 + * * Redistributions of source code must retain the above copyright
5528 + * notice, this list of conditions and the following disclaimer.
5529 + * * Redistributions in binary form must reproduce the above copyright
5530 + * notice, this list of conditions and the following disclaimer in the
5531 + * documentation and/or other materials provided with the distribution.
5532 + * * Neither the name of Freescale Semiconductor nor the
5533 + * names of its contributors may be used to endorse or promote products
5534 + * derived from this software without specific prior written permission.
5537 + * ALTERNATIVELY, this software may be distributed under the terms of the
5538 + * GNU General Public License ("GPL") as published by the Free Software
5539 + * Foundation, either version 2 of that License or (at your option) any
5542 + * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
5543 + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
5544 + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
5545 + * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
5546 + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
5547 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
5548 + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
5549 + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
5550 + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
5551 + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
5554 +/* Perform extra checking */
5555 +#define QBMAN_CHECKING
5557 +/* To maximise the amount of logic that is common between the Linux driver and
5558 + * other targets (such as the embedded MC firmware), we pivot here between the
5559 + * inclusion of two platform-specific headers.
5561 + * The first, qbman_sys_decl.h, includes any and all required system headers as
5562 + * well as providing any definitions for the purposes of compatibility. The
5563 + * second, qbman_sys.h, is where platform-specific routines go.
5565 + * The point of the split is that the platform-independent code (including this
5566 + * header) may depend on platform-specific declarations, yet other
5567 + * platform-specific routines may depend on platform-independent definitions.
5570 +#define QMAN_REV_4000 0x04000000
5571 +#define QMAN_REV_4100 0x04010000
5572 +#define QMAN_REV_4101 0x04010001
5574 +/* When things go wrong, it is a convenient trick to insert a few FOO()
5575 + * statements in the code to trace progress. TODO: remove this once we are
5576 + * hacking the code less actively.
5578 +#define FOO() fsl_os_print("FOO: %s:%d\n", __FILE__, __LINE__)
5580 +/* Any time there is a register interface which we poll on, this provides a
5581 + * "break after x iterations" scheme for it. It's handy for debugging, eg.
5582 + * where you don't want millions of lines of log output from a polling loop
5583 + * that won't, because such things tend to drown out the earlier log output
5584 + * that might explain what caused the problem. (NB: put ";" after each macro!)
5585 + * TODO: we should probably remove this once we're done sanitising the
5588 +#define DBG_POLL_START(loopvar) (loopvar = 1000)
5589 +#define DBG_POLL_CHECK(loopvar) \
5590 + do {if (!((loopvar)--)) WARN_ON(1); } while (0)
5592 +/* For CCSR or portal-CINH registers that contain fields at arbitrary offsets
5593 + * and widths, these macro-generated encode/decode/isolate/remove inlines can
5596 + * Eg. to "d"ecode a 14-bit field out of a register (into a "u16" type),
5597 + * where the field is located 3 bits "up" from the least-significant bit of the
5598 + * register (ie. the field location within the 32-bit register corresponds to a
5599 + * mask of 0x0001fff8), you would do;
5600 + * u16 field = d32_u16(3, 14, reg_value);
5602 + * Or to "e"ncode a 1-bit boolean value (input type is "int", zero is FALSE,
5603 + * non-zero is TRUE, so must convert all non-zero inputs to 1, hence the "!!"
5604 + * operator) into a register at bit location 0x00080000 (19 bits "in" from the
5606 + * reg_value |= e32_int(19, 1, !!field);
5608 + * If you wish to read-modify-write a register, such that you leave the 14-bit
5609 + * field as-is but have all other fields set to zero, then "i"solate the 14-bit
5611 + * reg_value = i32_u16(3, 14, reg_value);
5613 + * Alternatively, you could "r"emove the 1-bit boolean field (setting it to
5614 + * zero) but leaving all other fields as-is;
5615 + * reg_val = r32_int(19, 1, reg_value);
5618 +#define MAKE_MASK32(width) (width == 32 ? 0xffffffff : \
5619 + (u32)((1 << width) - 1))
5620 +#define DECLARE_CODEC32(t) \
5621 +static inline u32 e32_##t(u32 lsoffset, u32 width, t val) \
5623 + WARN_ON(width > (sizeof(t) * 8)); \
5624 + return ((u32)val & MAKE_MASK32(width)) << lsoffset; \
5626 +static inline t d32_##t(u32 lsoffset, u32 width, u32 val) \
5628 + WARN_ON(width > (sizeof(t) * 8)); \
5629 + return (t)((val >> lsoffset) & MAKE_MASK32(width)); \
5631 +static inline u32 i32_##t(u32 lsoffset, u32 width, \
5634 + WARN_ON(width > (sizeof(t) * 8)); \
5635 + return e32_##t(lsoffset, width, d32_##t(lsoffset, width, val)); \
5637 +static inline u32 r32_##t(u32 lsoffset, u32 width, \
5640 + WARN_ON(width > (sizeof(t) * 8)); \
5641 + return ~(MAKE_MASK32(width) << lsoffset) & val; \
5643 +DECLARE_CODEC32(u32)
5644 +DECLARE_CODEC32(u16)
5645 +DECLARE_CODEC32(u8)
5646 +DECLARE_CODEC32(int)
5648 + /*********************/
5649 + /* Debugging assists */
5650 + /*********************/
5652 +static inline void __hexdump(unsigned long start, unsigned long end,
5653 + unsigned long p, size_t sz,
5654 + const unsigned char *c)
5656 + while (start < end) {
5657 + unsigned int pos = 0;
5661 + pos += sprintf(buf + pos, "%08lx: ", start);
5663 + if ((start < p) || (start >= (p + sz)))
5664 + pos += sprintf(buf + pos, "..");
5666 + pos += sprintf(buf + pos, "%02x", *(c++));
5667 + if (!(++start & 15)) {
5668 + buf[pos++] = '\n';
5677 + } while (start & 15);
5679 + buf[pos++] = '\n';
5681 + pr_info("%s", buf);
5685 +static inline void hexdump(const void *ptr, size_t sz)
5687 + unsigned long p = (unsigned long)ptr;
5688 + unsigned long start = p & ~15ul;
5689 + unsigned long end = (p + sz + 15) & ~15ul;
5690 + const unsigned char *c = ptr;
5692 + __hexdump(start, end, p, sz, c);
5694 --- a/drivers/staging/fsl-mc/bus/dpmcp-cmd.h
5695 +++ b/drivers/staging/fsl-mc/bus/dpmcp-cmd.h
5697 -/* Copyright 2013-2016 Freescale Semiconductor Inc.
5699 + * Copyright 2013-2016 Freescale Semiconductor Inc.
5701 * Redistribution and use in source and binary forms, with or without
5702 * modification, are permitted provided that the following conditions are met:
5704 * names of any contributors may be used to endorse or promote products
5705 * derived from this software without specific prior written permission.
5708 * ALTERNATIVELY, this software may be distributed under the terms of the
5709 * GNU General Public License ("GPL") as published by the Free Software
5710 * Foundation, either version 2 of that License or (at your option) any
5711 @@ -33,108 +33,24 @@
5712 #define _FSL_DPMCP_CMD_H
5714 /* Minimal supported DPMCP Version */
5715 -#define DPMCP_MIN_VER_MAJOR 3
5716 -#define DPMCP_MIN_VER_MINOR 0
5719 -#define DPMCP_CMDID_CLOSE 0x800
5720 -#define DPMCP_CMDID_OPEN 0x80b
5721 -#define DPMCP_CMDID_CREATE 0x90b
5722 -#define DPMCP_CMDID_DESTROY 0x900
5724 -#define DPMCP_CMDID_GET_ATTR 0x004
5725 -#define DPMCP_CMDID_RESET 0x005
5727 -#define DPMCP_CMDID_SET_IRQ 0x010
5728 -#define DPMCP_CMDID_GET_IRQ 0x011
5729 -#define DPMCP_CMDID_SET_IRQ_ENABLE 0x012
5730 -#define DPMCP_CMDID_GET_IRQ_ENABLE 0x013
5731 -#define DPMCP_CMDID_SET_IRQ_MASK 0x014
5732 -#define DPMCP_CMDID_GET_IRQ_MASK 0x015
5733 -#define DPMCP_CMDID_GET_IRQ_STATUS 0x016
5735 -struct dpmcp_cmd_open {
5739 -struct dpmcp_cmd_create {
5743 -struct dpmcp_cmd_set_irq {
5754 -struct dpmcp_cmd_get_irq {
5759 -struct dpmcp_rsp_get_irq {
5769 +#define DPMCP_MIN_VER_MAJOR 3
5770 +#define DPMCP_MIN_VER_MINOR 0
5772 -#define DPMCP_ENABLE 0x1
5773 +/* Command versioning */
5774 +#define DPMCP_CMD_BASE_VERSION 1
5775 +#define DPMCP_CMD_ID_OFFSET 4
5777 -struct dpmcp_cmd_set_irq_enable {
5782 +#define DPMCP_CMD(id) ((id << DPMCP_CMD_ID_OFFSET) | DPMCP_CMD_BASE_VERSION)
5784 -struct dpmcp_cmd_get_irq_enable {
5789 -struct dpmcp_rsp_get_irq_enable {
5793 -struct dpmcp_cmd_set_irq_mask {
5798 -struct dpmcp_cmd_get_irq_mask {
5803 -struct dpmcp_rsp_get_irq_mask {
5807 +#define DPMCP_CMDID_CLOSE DPMCP_CMD(0x800)
5808 +#define DPMCP_CMDID_OPEN DPMCP_CMD(0x80b)
5809 +#define DPMCP_CMDID_GET_API_VERSION DPMCP_CMD(0xa0b)
5811 -struct dpmcp_cmd_get_irq_status {
5815 +#define DPMCP_CMDID_RESET DPMCP_CMD(0x005)
5817 -struct dpmcp_rsp_get_irq_status {
5821 -struct dpmcp_rsp_get_attributes {
5822 - /* response word 0 */
5825 - /* response word 1 */
5826 - __le16 version_major;
5827 - __le16 version_minor;
5828 +struct dpmcp_cmd_open {
5832 #endif /* _FSL_DPMCP_CMD_H */
5833 --- a/drivers/staging/fsl-mc/bus/dpmcp.c
5834 +++ b/drivers/staging/fsl-mc/bus/dpmcp.c
5836 -/* Copyright 2013-2016 Freescale Semiconductor Inc.
5838 + * Copyright 2013-2016 Freescale Semiconductor Inc.
5840 * Redistribution and use in source and binary forms, with or without
5841 * modification, are permitted provided that the following conditions are met:
5843 * names of any contributors may be used to endorse or promote products
5844 * derived from this software without specific prior written permission.
5847 * ALTERNATIVELY, this software may be distributed under the terms of the
5848 * GNU General Public License ("GPL") as published by the Free Software
5849 * Foundation, either version 2 of that License or (at your option) any
5850 @@ -104,76 +104,6 @@ int dpmcp_close(struct fsl_mc_io *mc_io,
5854 - * dpmcp_create() - Create the DPMCP object.
5855 - * @mc_io: Pointer to MC portal's I/O object
5856 - * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
5857 - * @cfg: Configuration structure
5858 - * @token: Returned token; use in subsequent API calls
5860 - * Create the DPMCP object, allocate required resources and
5861 - * perform required initialization.
5863 - * The object can be created either by declaring it in the
5864 - * DPL file, or by calling this function.
5865 - * This function returns a unique authentication token,
5866 - * associated with the specific object ID and the specific MC
5867 - * portal; this token must be used in all subsequent calls to
5868 - * this specific object. For objects that are created using the
5869 - * DPL file, call dpmcp_open function to get an authentication
5872 - * Return: '0' on Success; Error code otherwise.
5874 -int dpmcp_create(struct fsl_mc_io *mc_io,
5876 - const struct dpmcp_cfg *cfg,
5879 - struct mc_command cmd = { 0 };
5880 - struct dpmcp_cmd_create *cmd_params;
5884 - /* prepare command */
5885 - cmd.header = mc_encode_cmd_header(DPMCP_CMDID_CREATE,
5887 - cmd_params = (struct dpmcp_cmd_create *)cmd.params;
5888 - cmd_params->portal_id = cpu_to_le32(cfg->portal_id);
5890 - /* send command to mc*/
5891 - err = mc_send_command(mc_io, &cmd);
5895 - /* retrieve response parameters */
5896 - *token = mc_cmd_hdr_read_token(&cmd);
5902 - * dpmcp_destroy() - Destroy the DPMCP object and release all its resources.
5903 - * @mc_io: Pointer to MC portal's I/O object
5904 - * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
5905 - * @token: Token of DPMCP object
5907 - * Return: '0' on Success; error code otherwise.
5909 -int dpmcp_destroy(struct fsl_mc_io *mc_io,
5913 - struct mc_command cmd = { 0 };
5915 - /* prepare command */
5916 - cmd.header = mc_encode_cmd_header(DPMCP_CMDID_DESTROY,
5917 - cmd_flags, token);
5919 - /* send command to mc*/
5920 - return mc_send_command(mc_io, &cmd);
5924 * dpmcp_reset() - Reset the DPMCP, returns the object to initial state.
5925 * @mc_io: Pointer to MC portal's I/O object
5926 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
5927 @@ -196,309 +126,33 @@ int dpmcp_reset(struct fsl_mc_io *mc_io,
5931 - * dpmcp_set_irq() - Set IRQ information for the DPMCP to trigger an interrupt.
5932 - * @mc_io: Pointer to MC portal's I/O object
5933 - * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
5934 - * @token: Token of DPMCP object
5935 - * @irq_index: Identifies the interrupt index to configure
5936 - * @irq_cfg: IRQ configuration
5938 - * Return: '0' on Success; Error code otherwise.
5940 -int dpmcp_set_irq(struct fsl_mc_io *mc_io,
5944 - struct dpmcp_irq_cfg *irq_cfg)
5946 - struct mc_command cmd = { 0 };
5947 - struct dpmcp_cmd_set_irq *cmd_params;
5949 - /* prepare command */
5950 - cmd.header = mc_encode_cmd_header(DPMCP_CMDID_SET_IRQ,
5951 - cmd_flags, token);
5952 - cmd_params = (struct dpmcp_cmd_set_irq *)cmd.params;
5953 - cmd_params->irq_index = irq_index;
5954 - cmd_params->irq_val = cpu_to_le32(irq_cfg->val);
5955 - cmd_params->irq_addr = cpu_to_le64(irq_cfg->paddr);
5956 - cmd_params->irq_num = cpu_to_le32(irq_cfg->irq_num);
5958 - /* send command to mc*/
5959 - return mc_send_command(mc_io, &cmd);
5963 - * dpmcp_get_irq() - Get IRQ information from the DPMCP.
5964 - * @mc_io: Pointer to MC portal's I/O object
5965 + * dpmcp_get_api_version - Get Data Path Management Command Portal API version
5966 + * @mc_io: Pointer to Mc portal's I/O object
5967 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
5968 - * @token: Token of DPMCP object
5969 - * @irq_index: The interrupt index to configure
5970 - * @type: Interrupt type: 0 represents message interrupt
5971 - * type (both irq_addr and irq_val are valid)
5972 - * @irq_cfg: IRQ attributes
5973 + * @major_ver: Major version of Data Path Management Command Portal API
5974 + * @minor_ver: Minor version of Data Path Management Command Portal API
5976 * Return: '0' on Success; Error code otherwise.
5978 -int dpmcp_get_irq(struct fsl_mc_io *mc_io,
5983 - struct dpmcp_irq_cfg *irq_cfg)
5984 +int dpmcp_get_api_version(struct fsl_mc_io *mc_io,
5989 struct mc_command cmd = { 0 };
5990 - struct dpmcp_cmd_get_irq *cmd_params;
5991 - struct dpmcp_rsp_get_irq *rsp_params;
5994 /* prepare command */
5995 - cmd.header = mc_encode_cmd_header(DPMCP_CMDID_GET_IRQ,
5996 - cmd_flags, token);
5997 - cmd_params = (struct dpmcp_cmd_get_irq *)cmd.params;
5998 - cmd_params->irq_index = irq_index;
6000 - /* send command to mc*/
6001 - err = mc_send_command(mc_io, &cmd);
6005 - /* retrieve response parameters */
6006 - rsp_params = (struct dpmcp_rsp_get_irq *)cmd.params;
6007 - irq_cfg->val = le32_to_cpu(rsp_params->irq_val);
6008 - irq_cfg->paddr = le64_to_cpu(rsp_params->irq_paddr);
6009 - irq_cfg->irq_num = le32_to_cpu(rsp_params->irq_num);
6010 - *type = le32_to_cpu(rsp_params->type);
6015 - * dpmcp_set_irq_enable() - Set overall interrupt state.
6016 - * @mc_io: Pointer to MC portal's I/O object
6017 - * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
6018 - * @token: Token of DPMCP object
6019 - * @irq_index: The interrupt index to configure
6020 - * @en: Interrupt state - enable = 1, disable = 0
6022 - * Allows GPP software to control when interrupts are generated.
6023 - * Each interrupt can have up to 32 causes. The enable/disable control's the
6024 - * overall interrupt state. if the interrupt is disabled no causes will cause
6027 - * Return: '0' on Success; Error code otherwise.
6029 -int dpmcp_set_irq_enable(struct fsl_mc_io *mc_io,
6035 - struct mc_command cmd = { 0 };
6036 - struct dpmcp_cmd_set_irq_enable *cmd_params;
6038 - /* prepare command */
6039 - cmd.header = mc_encode_cmd_header(DPMCP_CMDID_SET_IRQ_ENABLE,
6040 - cmd_flags, token);
6041 - cmd_params = (struct dpmcp_cmd_set_irq_enable *)cmd.params;
6042 - cmd_params->enable = en & DPMCP_ENABLE;
6043 - cmd_params->irq_index = irq_index;
6045 - /* send command to mc*/
6046 - return mc_send_command(mc_io, &cmd);
6050 - * dpmcp_get_irq_enable() - Get overall interrupt state
6051 - * @mc_io: Pointer to MC portal's I/O object
6052 - * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
6053 - * @token: Token of DPMCP object
6054 - * @irq_index: The interrupt index to configure
6055 - * @en: Returned interrupt state - enable = 1, disable = 0
6057 - * Return: '0' on Success; Error code otherwise.
6059 -int dpmcp_get_irq_enable(struct fsl_mc_io *mc_io,
6065 - struct mc_command cmd = { 0 };
6066 - struct dpmcp_cmd_get_irq_enable *cmd_params;
6067 - struct dpmcp_rsp_get_irq_enable *rsp_params;
6070 - /* prepare command */
6071 - cmd.header = mc_encode_cmd_header(DPMCP_CMDID_GET_IRQ_ENABLE,
6072 - cmd_flags, token);
6073 - cmd_params = (struct dpmcp_cmd_get_irq_enable *)cmd.params;
6074 - cmd_params->irq_index = irq_index;
6076 - /* send command to mc*/
6077 - err = mc_send_command(mc_io, &cmd);
6081 - /* retrieve response parameters */
6082 - rsp_params = (struct dpmcp_rsp_get_irq_enable *)cmd.params;
6083 - *en = rsp_params->enabled & DPMCP_ENABLE;
6088 - * dpmcp_set_irq_mask() - Set interrupt mask.
6089 - * @mc_io: Pointer to MC portal's I/O object
6090 - * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
6091 - * @token: Token of DPMCP object
6092 - * @irq_index: The interrupt index to configure
6093 - * @mask: Event mask to trigger interrupt;
6095 - * 0 = ignore event
6096 - * 1 = consider event for asserting IRQ
6098 - * Every interrupt can have up to 32 causes and the interrupt model supports
6099 - * masking/unmasking each cause independently
6101 - * Return: '0' on Success; Error code otherwise.
6103 -int dpmcp_set_irq_mask(struct fsl_mc_io *mc_io,
6109 - struct mc_command cmd = { 0 };
6110 - struct dpmcp_cmd_set_irq_mask *cmd_params;
6112 - /* prepare command */
6113 - cmd.header = mc_encode_cmd_header(DPMCP_CMDID_SET_IRQ_MASK,
6114 - cmd_flags, token);
6115 - cmd_params = (struct dpmcp_cmd_set_irq_mask *)cmd.params;
6116 - cmd_params->mask = cpu_to_le32(mask);
6117 - cmd_params->irq_index = irq_index;
6119 - /* send command to mc*/
6120 - return mc_send_command(mc_io, &cmd);
6124 - * dpmcp_get_irq_mask() - Get interrupt mask.
6125 - * @mc_io: Pointer to MC portal's I/O object
6126 - * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
6127 - * @token: Token of DPMCP object
6128 - * @irq_index: The interrupt index to configure
6129 - * @mask: Returned event mask to trigger interrupt
6131 - * Every interrupt can have up to 32 causes and the interrupt model supports
6132 - * masking/unmasking each cause independently
6134 - * Return: '0' on Success; Error code otherwise.
6136 -int dpmcp_get_irq_mask(struct fsl_mc_io *mc_io,
6142 - struct mc_command cmd = { 0 };
6143 - struct dpmcp_cmd_get_irq_mask *cmd_params;
6144 - struct dpmcp_rsp_get_irq_mask *rsp_params;
6148 - /* prepare command */
6149 - cmd.header = mc_encode_cmd_header(DPMCP_CMDID_GET_IRQ_MASK,
6150 - cmd_flags, token);
6151 - cmd_params = (struct dpmcp_cmd_get_irq_mask *)cmd.params;
6152 - cmd_params->irq_index = irq_index;
6154 - /* send command to mc*/
6155 - err = mc_send_command(mc_io, &cmd);
6159 - /* retrieve response parameters */
6160 - rsp_params = (struct dpmcp_rsp_get_irq_mask *)cmd.params;
6161 - *mask = le32_to_cpu(rsp_params->mask);
6167 - * dpmcp_get_irq_status() - Get the current status of any pending interrupts.
6169 - * @mc_io: Pointer to MC portal's I/O object
6170 - * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
6171 - * @token: Token of DPMCP object
6172 - * @irq_index: The interrupt index to configure
6173 - * @status: Returned interrupts status - one bit per cause:
6174 - * 0 = no interrupt pending
6175 - * 1 = interrupt pending
6177 - * Return: '0' on Success; Error code otherwise.
6179 -int dpmcp_get_irq_status(struct fsl_mc_io *mc_io,
6185 - struct mc_command cmd = { 0 };
6186 - struct dpmcp_cmd_get_irq_status *cmd_params;
6187 - struct dpmcp_rsp_get_irq_status *rsp_params;
6190 - /* prepare command */
6191 - cmd.header = mc_encode_cmd_header(DPMCP_CMDID_GET_IRQ_STATUS,
6192 - cmd_flags, token);
6193 - cmd_params = (struct dpmcp_cmd_get_irq_status *)cmd.params;
6194 - cmd_params->status = cpu_to_le32(*status);
6195 - cmd_params->irq_index = irq_index;
6197 - /* send command to mc*/
6198 - err = mc_send_command(mc_io, &cmd);
6202 - /* retrieve response parameters */
6203 - rsp_params = (struct dpmcp_rsp_get_irq_status *)cmd.params;
6204 - *status = le32_to_cpu(rsp_params->status);
6210 - * dpmcp_get_attributes - Retrieve DPMCP attributes.
6212 - * @mc_io: Pointer to MC portal's I/O object
6213 - * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
6214 - * @token: Token of DPMCP object
6215 - * @attr: Returned object's attributes
6217 - * Return: '0' on Success; Error code otherwise.
6219 -int dpmcp_get_attributes(struct fsl_mc_io *mc_io,
6222 - struct dpmcp_attr *attr)
6224 - struct mc_command cmd = { 0 };
6225 - struct dpmcp_rsp_get_attributes *rsp_params;
6228 - /* prepare command */
6229 - cmd.header = mc_encode_cmd_header(DPMCP_CMDID_GET_ATTR,
6230 - cmd_flags, token);
6231 + cmd.header = mc_encode_cmd_header(DPMCP_CMDID_GET_API_VERSION,
6234 - /* send command to mc*/
6235 + /* send command to mc */
6236 err = mc_send_command(mc_io, &cmd);
6240 /* retrieve response parameters */
6241 - rsp_params = (struct dpmcp_rsp_get_attributes *)cmd.params;
6242 - attr->id = le32_to_cpu(rsp_params->id);
6243 - attr->version.major = le16_to_cpu(rsp_params->version_major);
6244 - attr->version.minor = le16_to_cpu(rsp_params->version_minor);
6245 + mc_cmd_read_api_version(&cmd, major_ver, minor_ver);
6249 --- a/drivers/staging/fsl-mc/bus/dpmcp.h
6250 +++ b/drivers/staging/fsl-mc/bus/dpmcp.h
6252 -/* Copyright 2013-2015 Freescale Semiconductor Inc.
6254 + * Copyright 2013-2016 Freescale Semiconductor Inc.
6256 * Redistribution and use in source and binary forms, with or without
6257 * modification, are permitted provided that the following conditions are met:
6259 * names of any contributors may be used to endorse or promote products
6260 * derived from this software without specific prior written permission.
6263 * ALTERNATIVELY, this software may be distributed under the terms of the
6264 * GNU General Public License ("GPL") as published by the Free Software
6265 * Foundation, either version 2 of that License or (at your option) any
6266 @@ -32,128 +32,29 @@
6267 #ifndef __FSL_DPMCP_H
6268 #define __FSL_DPMCP_H
6270 -/* Data Path Management Command Portal API
6272 + * Data Path Management Command Portal API
6273 * Contains initialization APIs and runtime control APIs for DPMCP
6278 int dpmcp_open(struct fsl_mc_io *mc_io,
6279 - uint32_t cmd_flags,
6284 -/* Get portal ID from pool */
6285 -#define DPMCP_GET_PORTAL_ID_FROM_POOL (-1)
6288 int dpmcp_close(struct fsl_mc_io *mc_io,
6289 - uint32_t cmd_flags,
6295 - * struct dpmcp_cfg - Structure representing DPMCP configuration
6296 - * @portal_id: Portal ID; 'DPMCP_GET_PORTAL_ID_FROM_POOL' to get the portal ID
6303 -int dpmcp_create(struct fsl_mc_io *mc_io,
6304 - uint32_t cmd_flags,
6305 - const struct dpmcp_cfg *cfg,
6308 -int dpmcp_destroy(struct fsl_mc_io *mc_io,
6309 - uint32_t cmd_flags,
6311 +int dpmcp_get_api_version(struct fsl_mc_io *mc_io,
6316 int dpmcp_reset(struct fsl_mc_io *mc_io,
6317 - uint32_t cmd_flags,
6322 -#define DPMCP_IRQ_INDEX 0
6323 -/* irq event - Indicates that the link state changed */
6324 -#define DPMCP_IRQ_EVENT_CMD_DONE 0x00000001
6327 - * struct dpmcp_irq_cfg - IRQ configuration
6328 - * @paddr: Address that must be written to signal a message-based interrupt
6329 - * @val: Value to write into irq_addr address
6330 - * @irq_num: A user defined number associated with this IRQ
6332 -struct dpmcp_irq_cfg {
6338 -int dpmcp_set_irq(struct fsl_mc_io *mc_io,
6339 - uint32_t cmd_flags,
6341 - uint8_t irq_index,
6342 - struct dpmcp_irq_cfg *irq_cfg);
6344 -int dpmcp_get_irq(struct fsl_mc_io *mc_io,
6345 - uint32_t cmd_flags,
6347 - uint8_t irq_index,
6349 - struct dpmcp_irq_cfg *irq_cfg);
6351 -int dpmcp_set_irq_enable(struct fsl_mc_io *mc_io,
6352 - uint32_t cmd_flags,
6354 - uint8_t irq_index,
6357 -int dpmcp_get_irq_enable(struct fsl_mc_io *mc_io,
6358 - uint32_t cmd_flags,
6360 - uint8_t irq_index,
6363 -int dpmcp_set_irq_mask(struct fsl_mc_io *mc_io,
6364 - uint32_t cmd_flags,
6366 - uint8_t irq_index,
6369 -int dpmcp_get_irq_mask(struct fsl_mc_io *mc_io,
6370 - uint32_t cmd_flags,
6372 - uint8_t irq_index,
6375 -int dpmcp_get_irq_status(struct fsl_mc_io *mc_io,
6376 - uint32_t cmd_flags,
6378 - uint8_t irq_index,
6379 - uint32_t *status);
6382 - * struct dpmcp_attr - Structure representing DPMCP attributes
6383 - * @id: DPMCP object ID
6384 - * @version: DPMCP version
6386 -struct dpmcp_attr {
6389 - * struct version - Structure representing DPMCP version
6390 - * @major: DPMCP major version
6391 - * @minor: DPMCP minor version
6399 -int dpmcp_get_attributes(struct fsl_mc_io *mc_io,
6400 - uint32_t cmd_flags,
6402 - struct dpmcp_attr *attr);
6406 #endif /* __FSL_DPMCP_H */
6407 --- a/drivers/staging/fsl-mc/bus/dpmng-cmd.h
6408 +++ b/drivers/staging/fsl-mc/bus/dpmng-cmd.h
6410 * names of any contributors may be used to endorse or promote products
6411 * derived from this software without specific prior written permission.
6414 * ALTERNATIVELY, this software may be distributed under the terms of the
6415 * GNU General Public License ("GPL") as published by the Free Software
6416 * Foundation, either version 2 of that License or (at your option) any
6418 #ifndef __FSL_DPMNG_CMD_H
6419 #define __FSL_DPMNG_CMD_H
6422 -#define DPMNG_CMDID_GET_CONT_ID 0x830
6423 -#define DPMNG_CMDID_GET_VERSION 0x831
6424 +/* Command versioning */
6425 +#define DPMNG_CMD_BASE_VERSION 1
6426 +#define DPMNG_CMD_ID_OFFSET 4
6428 -struct dpmng_rsp_get_container_id {
6429 - __le32 container_id;
6431 +#define DPMNG_CMD(id) ((id << DPMNG_CMD_ID_OFFSET) | DPMNG_CMD_BASE_VERSION)
6434 +#define DPMNG_CMDID_GET_VERSION DPMNG_CMD(0x831)
6436 struct dpmng_rsp_get_version {
6438 --- a/drivers/staging/fsl-mc/bus/dpmng.c
6439 +++ b/drivers/staging/fsl-mc/bus/dpmng.c
6441 -/* Copyright 2013-2016 Freescale Semiconductor Inc.
6443 + * Copyright 2013-2016 Freescale Semiconductor Inc.
6445 * Redistribution and use in source and binary forms, with or without
6446 * modification, are permitted provided that the following conditions are met:
6448 * names of any contributors may be used to endorse or promote products
6449 * derived from this software without specific prior written permission.
6452 * ALTERNATIVELY, this software may be distributed under the terms of the
6453 * GNU General Public License ("GPL") as published by the Free Software
6454 * Foundation, either version 2 of that License or (at your option) any
6455 @@ -72,36 +72,3 @@ int mc_get_version(struct fsl_mc_io *mc_
6457 EXPORT_SYMBOL(mc_get_version);
6460 - * dpmng_get_container_id() - Get container ID associated with a given portal.
6461 - * @mc_io: Pointer to MC portal's I/O object
6462 - * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
6463 - * @container_id: Requested container ID
6465 - * Return: '0' on Success; Error code otherwise.
6467 -int dpmng_get_container_id(struct fsl_mc_io *mc_io,
6469 - int *container_id)
6471 - struct mc_command cmd = { 0 };
6472 - struct dpmng_rsp_get_container_id *rsp_params;
6475 - /* prepare command */
6476 - cmd.header = mc_encode_cmd_header(DPMNG_CMDID_GET_CONT_ID,
6480 - /* send command to mc*/
6481 - err = mc_send_command(mc_io, &cmd);
6485 - /* retrieve response parameters */
6486 - rsp_params = (struct dpmng_rsp_get_container_id *)cmd.params;
6487 - *container_id = le32_to_cpu(rsp_params->container_id);
6492 --- a/drivers/staging/fsl-mc/bus/dprc-cmd.h
6493 +++ b/drivers/staging/fsl-mc/bus/dprc-cmd.h
6495 * names of any contributors may be used to endorse or promote products
6496 * derived from this software without specific prior written permission.
6499 * ALTERNATIVELY, this software may be distributed under the terms of the
6500 * GNU General Public License ("GPL") as published by the Free Software
6501 * Foundation, either version 2 of that License or (at your option) any
6503 #define _FSL_DPRC_CMD_H
6505 /* Minimal supported DPRC Version */
6506 -#define DPRC_MIN_VER_MAJOR 5
6507 +#define DPRC_MIN_VER_MAJOR 6
6508 #define DPRC_MIN_VER_MINOR 0
6511 -#define DPRC_CMDID_CLOSE 0x800
6512 -#define DPRC_CMDID_OPEN 0x805
6513 -#define DPRC_CMDID_CREATE 0x905
6515 -#define DPRC_CMDID_GET_ATTR 0x004
6516 -#define DPRC_CMDID_RESET_CONT 0x005
6518 -#define DPRC_CMDID_SET_IRQ 0x010
6519 -#define DPRC_CMDID_GET_IRQ 0x011
6520 -#define DPRC_CMDID_SET_IRQ_ENABLE 0x012
6521 -#define DPRC_CMDID_GET_IRQ_ENABLE 0x013
6522 -#define DPRC_CMDID_SET_IRQ_MASK 0x014
6523 -#define DPRC_CMDID_GET_IRQ_MASK 0x015
6524 -#define DPRC_CMDID_GET_IRQ_STATUS 0x016
6525 -#define DPRC_CMDID_CLEAR_IRQ_STATUS 0x017
6527 -#define DPRC_CMDID_CREATE_CONT 0x151
6528 -#define DPRC_CMDID_DESTROY_CONT 0x152
6529 -#define DPRC_CMDID_SET_RES_QUOTA 0x155
6530 -#define DPRC_CMDID_GET_RES_QUOTA 0x156
6531 -#define DPRC_CMDID_ASSIGN 0x157
6532 -#define DPRC_CMDID_UNASSIGN 0x158
6533 -#define DPRC_CMDID_GET_OBJ_COUNT 0x159
6534 -#define DPRC_CMDID_GET_OBJ 0x15A
6535 -#define DPRC_CMDID_GET_RES_COUNT 0x15B
6536 -#define DPRC_CMDID_GET_RES_IDS 0x15C
6537 -#define DPRC_CMDID_GET_OBJ_REG 0x15E
6538 -#define DPRC_CMDID_SET_OBJ_IRQ 0x15F
6539 -#define DPRC_CMDID_GET_OBJ_IRQ 0x160
6540 -#define DPRC_CMDID_SET_OBJ_LABEL 0x161
6541 -#define DPRC_CMDID_GET_OBJ_DESC 0x162
6543 -#define DPRC_CMDID_CONNECT 0x167
6544 -#define DPRC_CMDID_DISCONNECT 0x168
6545 -#define DPRC_CMDID_GET_POOL 0x169
6546 -#define DPRC_CMDID_GET_POOL_COUNT 0x16A
6547 +/* Command versioning */
6548 +#define DPRC_CMD_BASE_VERSION 1
6549 +#define DPRC_CMD_ID_OFFSET 4
6551 -#define DPRC_CMDID_GET_CONNECTION 0x16C
6552 +#define DPRC_CMD(id) ((id << DPRC_CMD_ID_OFFSET) | DPRC_CMD_BASE_VERSION)
6555 +#define DPRC_CMDID_CLOSE DPRC_CMD(0x800)
6556 +#define DPRC_CMDID_OPEN DPRC_CMD(0x805)
6557 +#define DPRC_CMDID_GET_API_VERSION DPRC_CMD(0xa05)
6559 +#define DPRC_CMDID_GET_ATTR DPRC_CMD(0x004)
6560 +#define DPRC_CMDID_RESET_CONT DPRC_CMD(0x005)
6562 +#define DPRC_CMDID_SET_IRQ DPRC_CMD(0x010)
6563 +#define DPRC_CMDID_GET_IRQ DPRC_CMD(0x011)
6564 +#define DPRC_CMDID_SET_IRQ_ENABLE DPRC_CMD(0x012)
6565 +#define DPRC_CMDID_GET_IRQ_ENABLE DPRC_CMD(0x013)
6566 +#define DPRC_CMDID_SET_IRQ_MASK DPRC_CMD(0x014)
6567 +#define DPRC_CMDID_GET_IRQ_MASK DPRC_CMD(0x015)
6568 +#define DPRC_CMDID_GET_IRQ_STATUS DPRC_CMD(0x016)
6569 +#define DPRC_CMDID_CLEAR_IRQ_STATUS DPRC_CMD(0x017)
6571 +#define DPRC_CMDID_GET_CONT_ID DPRC_CMD(0x830)
6572 +#define DPRC_CMDID_GET_OBJ_COUNT DPRC_CMD(0x159)
6573 +#define DPRC_CMDID_GET_OBJ DPRC_CMD(0x15A)
6574 +#define DPRC_CMDID_GET_RES_COUNT DPRC_CMD(0x15B)
6575 +#define DPRC_CMDID_GET_OBJ_REG DPRC_CMD(0x15E)
6576 +#define DPRC_CMDID_SET_OBJ_IRQ DPRC_CMD(0x15F)
6577 +#define DPRC_CMDID_GET_OBJ_IRQ DPRC_CMD(0x160)
6579 struct dprc_cmd_open {
6580 __le32 container_id;
6581 @@ -199,9 +189,6 @@ struct dprc_rsp_get_attributes {
6582 /* response word 1 */
6585 - /* response word 2 */
6586 - __le16 version_major;
6587 - __le16 version_minor;
6590 struct dprc_cmd_set_res_quota {
6591 @@ -367,11 +354,16 @@ struct dprc_cmd_get_obj_region {
6593 struct dprc_rsp_get_obj_region {
6594 /* response word 0 */
6597 /* response word 1 */
6601 /* response word 2 */
6605 + /* response word 3 */
6609 struct dprc_cmd_set_obj_label {
6610 --- a/drivers/staging/fsl-mc/bus/dprc-driver.c
6611 +++ b/drivers/staging/fsl-mc/bus/dprc-driver.c
6614 * Freescale data path resource container (DPRC) driver
6616 - * Copyright (C) 2014 Freescale Semiconductor, Inc.
6617 + * Copyright (C) 2014-2016 Freescale Semiconductor, Inc.
6618 * Author: German Rivera <German.Rivera@freescale.com>
6620 * This file is licensed under the terms of the GNU General Public
6621 @@ -160,6 +160,8 @@ static void check_plugged_state_change(s
6622 * dprc_add_new_devices - Adds devices to the logical bus for a DPRC
6624 * @mc_bus_dev: pointer to the fsl-mc device that represents a DPRC object
6625 + * @driver_override: driver override to apply to new objects found in the
6626 + * DPRC, or NULL, if none.
6627 * @obj_desc_array: array of device descriptors for child devices currently
6628 * present in the physical DPRC.
6629 * @num_child_objects_in_mc: number of entries in obj_desc_array
6630 @@ -169,6 +171,7 @@ static void check_plugged_state_change(s
6631 * in the physical DPRC.
6633 static void dprc_add_new_devices(struct fsl_mc_device *mc_bus_dev,
6634 + const char *driver_override,
6635 struct dprc_obj_desc *obj_desc_array,
6636 int num_child_objects_in_mc)
6638 @@ -188,11 +191,12 @@ static void dprc_add_new_devices(struct
6639 child_dev = fsl_mc_device_lookup(obj_desc, mc_bus_dev);
6641 check_plugged_state_change(child_dev, obj_desc);
6642 + put_device(&child_dev->dev);
6646 error = fsl_mc_device_add(obj_desc, NULL, &mc_bus_dev->dev,
6648 + driver_override, &child_dev);
6652 @@ -202,6 +206,8 @@ static void dprc_add_new_devices(struct
6653 * dprc_scan_objects - Discover objects in a DPRC
6655 * @mc_bus_dev: pointer to the fsl-mc device that represents a DPRC object
6656 + * @driver_override: driver override to apply to new objects found in the
6657 + * DPRC, or NULL, if none.
6658 * @total_irq_count: total number of IRQs needed by objects in the DPRC.
6660 * Detects objects added and removed from a DPRC and synchronizes the
6661 @@ -217,6 +223,7 @@ static void dprc_add_new_devices(struct
6662 * of the device drivers for the non-allocatable devices.
6664 int dprc_scan_objects(struct fsl_mc_device *mc_bus_dev,
6665 + const char *driver_override,
6666 unsigned int *total_irq_count)
6668 int num_child_objects;
6669 @@ -297,7 +304,7 @@ int dprc_scan_objects(struct fsl_mc_devi
6670 dprc_remove_devices(mc_bus_dev, child_obj_desc_array,
6673 - dprc_add_new_devices(mc_bus_dev, child_obj_desc_array,
6674 + dprc_add_new_devices(mc_bus_dev, driver_override, child_obj_desc_array,
6677 if (child_obj_desc_array)
6678 @@ -328,7 +335,7 @@ int dprc_scan_container(struct fsl_mc_de
6679 * Discover objects in the DPRC:
6681 mutex_lock(&mc_bus->scan_mutex);
6682 - error = dprc_scan_objects(mc_bus_dev, &irq_count);
6683 + error = dprc_scan_objects(mc_bus_dev, NULL, &irq_count);
6684 mutex_unlock(&mc_bus->scan_mutex);
6687 @@ -415,7 +422,7 @@ static irqreturn_t dprc_irq0_handler_thr
6688 DPRC_IRQ_EVENT_OBJ_CREATED)) {
6689 unsigned int irq_count;
6691 - error = dprc_scan_objects(mc_dev, &irq_count);
6692 + error = dprc_scan_objects(mc_dev, NULL, &irq_count);
6695 * If the error is -ENXIO, we ignore it, as it indicates
6696 @@ -505,7 +512,7 @@ static int register_dprc_irq_handler(str
6698 dprc_irq0_handler_thread,
6699 IRQF_NO_SUSPEND | IRQF_ONESHOT,
6700 - "FSL MC DPRC irq0",
6701 + dev_name(&mc_dev->dev),
6704 dev_err(&mc_dev->dev,
6705 @@ -597,6 +604,7 @@ static int dprc_probe(struct fsl_mc_devi
6706 struct fsl_mc_bus *mc_bus = to_fsl_mc_bus(mc_dev);
6707 bool mc_io_created = false;
6708 bool msi_domain_set = false;
6709 + u16 major_ver, minor_ver;
6711 if (WARN_ON(strcmp(mc_dev->obj_desc.type, "dprc") != 0))
6713 @@ -669,13 +677,21 @@ static int dprc_probe(struct fsl_mc_devi
6714 goto error_cleanup_open;
6717 - if (mc_bus->dprc_attr.version.major < DPRC_MIN_VER_MAJOR ||
6718 - (mc_bus->dprc_attr.version.major == DPRC_MIN_VER_MAJOR &&
6719 - mc_bus->dprc_attr.version.minor < DPRC_MIN_VER_MINOR)) {
6720 + error = dprc_get_api_version(mc_dev->mc_io, 0,
6724 + dev_err(&mc_dev->dev, "dprc_get_api_version() failed: %d\n",
6726 + goto error_cleanup_open;
6729 + if (major_ver < DPRC_MIN_VER_MAJOR ||
6730 + (major_ver == DPRC_MIN_VER_MAJOR &&
6731 + minor_ver < DPRC_MIN_VER_MINOR)) {
6732 dev_err(&mc_dev->dev,
6733 "ERROR: DPRC version %d.%d not supported\n",
6734 - mc_bus->dprc_attr.version.major,
6735 - mc_bus->dprc_attr.version.minor);
6736 + major_ver, minor_ver);
6738 goto error_cleanup_open;
6740 --- a/drivers/staging/fsl-mc/bus/dprc.c
6741 +++ b/drivers/staging/fsl-mc/bus/dprc.c
6743 -/* Copyright 2013-2016 Freescale Semiconductor Inc.
6745 + * Copyright 2013-2016 Freescale Semiconductor Inc.
6747 * Redistribution and use in source and binary forms, with or without
6748 * modification, are permitted provided that the following conditions are met:
6750 * names of any contributors may be used to endorse or promote products
6751 * derived from this software without specific prior written permission.
6754 * ALTERNATIVELY, this software may be distributed under the terms of the
6755 * GNU General Public License ("GPL") as published by the Free Software
6756 * Foundation, either version 2 of that License or (at your option) any
6757 @@ -100,93 +100,6 @@ int dprc_close(struct fsl_mc_io *mc_io,
6758 EXPORT_SYMBOL(dprc_close);
6761 - * dprc_create_container() - Create child container
6762 - * @mc_io: Pointer to MC portal's I/O object
6763 - * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
6764 - * @token: Token of DPRC object
6765 - * @cfg: Child container configuration
6766 - * @child_container_id: Returned child container ID
6767 - * @child_portal_offset: Returned child portal offset from MC portal base
6769 - * Return: '0' on Success; Error code otherwise.
6771 -int dprc_create_container(struct fsl_mc_io *mc_io,
6774 - struct dprc_cfg *cfg,
6775 - int *child_container_id,
6776 - u64 *child_portal_offset)
6778 - struct mc_command cmd = { 0 };
6779 - struct dprc_cmd_create_container *cmd_params;
6780 - struct dprc_rsp_create_container *rsp_params;
6783 - /* prepare command */
6784 - cmd_params = (struct dprc_cmd_create_container *)cmd.params;
6785 - cmd_params->options = cpu_to_le32(cfg->options);
6786 - cmd_params->icid = cpu_to_le16(cfg->icid);
6787 - cmd_params->portal_id = cpu_to_le32(cfg->portal_id);
6788 - strncpy(cmd_params->label, cfg->label, 16);
6789 - cmd_params->label[15] = '\0';
6791 - cmd.header = mc_encode_cmd_header(DPRC_CMDID_CREATE_CONT,
6792 - cmd_flags, token);
6794 - /* send command to mc*/
6795 - err = mc_send_command(mc_io, &cmd);
6799 - /* retrieve response parameters */
6800 - rsp_params = (struct dprc_rsp_create_container *)cmd.params;
6801 - *child_container_id = le32_to_cpu(rsp_params->child_container_id);
6802 - *child_portal_offset = le64_to_cpu(rsp_params->child_portal_addr);
6808 - * dprc_destroy_container() - Destroy child container.
6809 - * @mc_io: Pointer to MC portal's I/O object
6810 - * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
6811 - * @token: Token of DPRC object
6812 - * @child_container_id: ID of the container to destroy
6814 - * This function terminates the child container, so following this call the
6815 - * child container ID becomes invalid.
6818 - * - All resources and objects of the destroyed container are returned to the
6819 - * parent container or destroyed if were created be the destroyed container.
6820 - * - This function destroy all the child containers of the specified
6821 - * container prior to destroying the container itself.
6823 - * warning: Only the parent container is allowed to destroy a child policy
6824 - * Container 0 can't be destroyed
6826 - * Return: '0' on Success; Error code otherwise.
6829 -int dprc_destroy_container(struct fsl_mc_io *mc_io,
6832 - int child_container_id)
6834 - struct mc_command cmd = { 0 };
6835 - struct dprc_cmd_destroy_container *cmd_params;
6837 - /* prepare command */
6838 - cmd.header = mc_encode_cmd_header(DPRC_CMDID_DESTROY_CONT,
6839 - cmd_flags, token);
6840 - cmd_params = (struct dprc_cmd_destroy_container *)cmd.params;
6841 - cmd_params->child_container_id = cpu_to_le32(child_container_id);
6843 - /* send command to mc*/
6844 - return mc_send_command(mc_io, &cmd);
6848 * dprc_reset_container - Reset child container.
6849 * @mc_io: Pointer to MC portal's I/O object
6850 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
6851 @@ -565,279 +478,6 @@ int dprc_get_attributes(struct fsl_mc_io
6852 attr->icid = le16_to_cpu(rsp_params->icid);
6853 attr->options = le32_to_cpu(rsp_params->options);
6854 attr->portal_id = le32_to_cpu(rsp_params->portal_id);
6855 - attr->version.major = le16_to_cpu(rsp_params->version_major);
6856 - attr->version.minor = le16_to_cpu(rsp_params->version_minor);
6862 - * dprc_set_res_quota() - Set allocation policy for a specific resource/object
6863 - * type in a child container
6864 - * @mc_io: Pointer to MC portal's I/O object
6865 - * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
6866 - * @token: Token of DPRC object
6867 - * @child_container_id: ID of the child container
6868 - * @type: Resource/object type
6869 - * @quota: Sets the maximum number of resources of the selected type
6870 - * that the child container is allowed to allocate from its parent;
6871 - * when quota is set to -1, the policy is the same as container's
6874 - * Allocation policy determines whether or not a container may allocate
6875 - * resources from its parent. Each container has a 'global' allocation policy
6876 - * that is set when the container is created.
6878 - * This function sets allocation policy for a specific resource type.
6879 - * The default policy for all resource types matches the container's 'global'
6880 - * allocation policy.
6882 - * Return: '0' on Success; Error code otherwise.
6884 - * @warning Only the parent container is allowed to change a child policy.
6886 -int dprc_set_res_quota(struct fsl_mc_io *mc_io,
6889 - int child_container_id,
6893 - struct mc_command cmd = { 0 };
6894 - struct dprc_cmd_set_res_quota *cmd_params;
6896 - /* prepare command */
6897 - cmd.header = mc_encode_cmd_header(DPRC_CMDID_SET_RES_QUOTA,
6898 - cmd_flags, token);
6899 - cmd_params = (struct dprc_cmd_set_res_quota *)cmd.params;
6900 - cmd_params->child_container_id = cpu_to_le32(child_container_id);
6901 - cmd_params->quota = cpu_to_le16(quota);
6902 - strncpy(cmd_params->type, type, 16);
6903 - cmd_params->type[15] = '\0';
6905 - /* send command to mc*/
6906 - return mc_send_command(mc_io, &cmd);
6910 - * dprc_get_res_quota() - Gets the allocation policy of a specific
6911 - * resource/object type in a child container
6912 - * @mc_io: Pointer to MC portal's I/O object
6913 - * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
6914 - * @token: Token of DPRC object
6915 - * @child_container_id; ID of the child container
6916 - * @type: resource/object type
6917 - * @quota: Returnes the maximum number of resources of the selected type
6918 - * that the child container is allowed to allocate from the parent;
6919 - * when quota is set to -1, the policy is the same as container's
6922 - * Return: '0' on Success; Error code otherwise.
6924 -int dprc_get_res_quota(struct fsl_mc_io *mc_io,
6927 - int child_container_id,
6931 - struct mc_command cmd = { 0 };
6932 - struct dprc_cmd_get_res_quota *cmd_params;
6933 - struct dprc_rsp_get_res_quota *rsp_params;
6936 - /* prepare command */
6937 - cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_RES_QUOTA,
6938 - cmd_flags, token);
6939 - cmd_params = (struct dprc_cmd_get_res_quota *)cmd.params;
6940 - cmd_params->child_container_id = cpu_to_le32(child_container_id);
6941 - strncpy(cmd_params->type, type, 16);
6942 - cmd_params->type[15] = '\0';
6944 - /* send command to mc*/
6945 - err = mc_send_command(mc_io, &cmd);
6949 - /* retrieve response parameters */
6950 - rsp_params = (struct dprc_rsp_get_res_quota *)cmd.params;
6951 - *quota = le16_to_cpu(rsp_params->quota);
6957 - * dprc_assign() - Assigns objects or resource to a child container.
6958 - * @mc_io: Pointer to MC portal's I/O object
6959 - * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
6960 - * @token: Token of DPRC object
6961 - * @container_id: ID of the child container
6962 - * @res_req: Describes the type and amount of resources to
6963 - * assign to the given container
6965 - * Assignment is usually done by a parent (this DPRC) to one of its child
6968 - * According to the DPRC allocation policy, the assigned resources may be taken
6969 - * (allocated) from the container's ancestors, if not enough resources are
6970 - * available in the container itself.
6972 - * The type of assignment depends on the dprc_res_req options, as follows:
6973 - * - DPRC_RES_REQ_OPT_EXPLICIT: indicates that assigned resources should have
6974 - * the explicit base ID specified at the id_base_align field of res_req.
6975 - * - DPRC_RES_REQ_OPT_ALIGNED: indicates that the assigned resources should be
6976 - * aligned to the value given at id_base_align field of res_req.
6977 - * - DPRC_RES_REQ_OPT_PLUGGED: Relevant only for object assignment,
6978 - * and indicates that the object must be set to the plugged state.
6980 - * A container may use this function with its own ID in order to change a
6981 - * object state to plugged or unplugged.
6983 - * If IRQ information has been set in the child DPRC, it will signal an
6984 - * interrupt following every change in its object assignment.
6986 - * Return: '0' on Success; Error code otherwise.
6988 -int dprc_assign(struct fsl_mc_io *mc_io,
6992 - struct dprc_res_req *res_req)
6994 - struct mc_command cmd = { 0 };
6995 - struct dprc_cmd_assign *cmd_params;
6997 - /* prepare command */
6998 - cmd.header = mc_encode_cmd_header(DPRC_CMDID_ASSIGN,
6999 - cmd_flags, token);
7000 - cmd_params = (struct dprc_cmd_assign *)cmd.params;
7001 - cmd_params->container_id = cpu_to_le32(container_id);
7002 - cmd_params->options = cpu_to_le32(res_req->options);
7003 - cmd_params->num = cpu_to_le32(res_req->num);
7004 - cmd_params->id_base_align = cpu_to_le32(res_req->id_base_align);
7005 - strncpy(cmd_params->type, res_req->type, 16);
7006 - cmd_params->type[15] = '\0';
7008 - /* send command to mc*/
7009 - return mc_send_command(mc_io, &cmd);
7013 - * dprc_unassign() - Un-assigns objects or resources from a child container
7014 - * and moves them into this (parent) DPRC.
7015 - * @mc_io: Pointer to MC portal's I/O object
7016 - * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
7017 - * @token: Token of DPRC object
7018 - * @child_container_id: ID of the child container
7019 - * @res_req: Describes the type and amount of resources to un-assign from
7020 - * the child container
7022 - * Un-assignment of objects can succeed only if the object is not in the
7023 - * plugged or opened state.
7025 - * Return: '0' on Success; Error code otherwise.
7027 -int dprc_unassign(struct fsl_mc_io *mc_io,
7030 - int child_container_id,
7031 - struct dprc_res_req *res_req)
7033 - struct mc_command cmd = { 0 };
7034 - struct dprc_cmd_unassign *cmd_params;
7036 - /* prepare command */
7037 - cmd.header = mc_encode_cmd_header(DPRC_CMDID_UNASSIGN,
7040 - cmd_params = (struct dprc_cmd_unassign *)cmd.params;
7041 - cmd_params->child_container_id = cpu_to_le32(child_container_id);
7042 - cmd_params->options = cpu_to_le32(res_req->options);
7043 - cmd_params->num = cpu_to_le32(res_req->num);
7044 - cmd_params->id_base_align = cpu_to_le32(res_req->id_base_align);
7045 - strncpy(cmd_params->type, res_req->type, 16);
7046 - cmd_params->type[15] = '\0';
7048 - /* send command to mc*/
7049 - return mc_send_command(mc_io, &cmd);
7053 - * dprc_get_pool_count() - Get the number of dprc's pools
7054 - * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
7055 - * @mc_io: Pointer to MC portal's I/O object
7056 - * @token: Token of DPRC object
7057 - * @pool_count: Returned number of resource pools in the dprc
7059 - * Return: '0' on Success; Error code otherwise.
7061 -int dprc_get_pool_count(struct fsl_mc_io *mc_io,
7066 - struct mc_command cmd = { 0 };
7067 - struct dprc_rsp_get_pool_count *rsp_params;
7070 - /* prepare command */
7071 - cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_POOL_COUNT,
7072 - cmd_flags, token);
7074 - /* send command to mc*/
7075 - err = mc_send_command(mc_io, &cmd);
7079 - /* retrieve response parameters */
7080 - rsp_params = (struct dprc_rsp_get_pool_count *)cmd.params;
7081 - *pool_count = le32_to_cpu(rsp_params->pool_count);
7087 - * dprc_get_pool() - Get the type (string) of a certain dprc's pool
7088 - * @mc_io: Pointer to MC portal's I/O object
7089 - * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
7090 - * @token: Token of DPRC object
7091 - * @pool_index; Index of the pool to be queried (< pool_count)
7092 - * @type: The type of the pool
7094 - * The pool types retrieved one by one by incrementing
7095 - * pool_index up to (not including) the value of pool_count returned
7096 - * from dprc_get_pool_count(). dprc_get_pool_count() must
7097 - * be called prior to dprc_get_pool().
7099 - * Return: '0' on Success; Error code otherwise.
7101 -int dprc_get_pool(struct fsl_mc_io *mc_io,
7107 - struct mc_command cmd = { 0 };
7108 - struct dprc_cmd_get_pool *cmd_params;
7109 - struct dprc_rsp_get_pool *rsp_params;
7112 - /* prepare command */
7113 - cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_POOL,
7116 - cmd_params = (struct dprc_cmd_get_pool *)cmd.params;
7117 - cmd_params->pool_index = cpu_to_le32(pool_index);
7119 - /* send command to mc*/
7120 - err = mc_send_command(mc_io, &cmd);
7124 - /* retrieve response parameters */
7125 - rsp_params = (struct dprc_rsp_get_pool *)cmd.params;
7126 - strncpy(type, rsp_params->type, 16);
7131 @@ -934,64 +574,6 @@ int dprc_get_obj(struct fsl_mc_io *mc_io
7132 EXPORT_SYMBOL(dprc_get_obj);
7135 - * dprc_get_obj_desc() - Get object descriptor.
7137 - * @mc_io: Pointer to MC portal's I/O object
7138 - * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
7139 - * @token: Token of DPRC object
7140 - * @obj_type: The type of the object to get its descriptor.
7141 - * @obj_id: The id of the object to get its descriptor
7142 - * @obj_desc: The returned descriptor to fill and return to the user
7144 - * Return: '0' on Success; Error code otherwise.
7147 -int dprc_get_obj_desc(struct fsl_mc_io *mc_io,
7152 - struct dprc_obj_desc *obj_desc)
7154 - struct mc_command cmd = { 0 };
7155 - struct dprc_cmd_get_obj_desc *cmd_params;
7156 - struct dprc_rsp_get_obj_desc *rsp_params;
7159 - /* prepare command */
7160 - cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_OBJ_DESC,
7163 - cmd_params = (struct dprc_cmd_get_obj_desc *)cmd.params;
7164 - cmd_params->obj_id = cpu_to_le32(obj_id);
7165 - strncpy(cmd_params->type, obj_type, 16);
7166 - cmd_params->type[15] = '\0';
7168 - /* send command to mc*/
7169 - err = mc_send_command(mc_io, &cmd);
7173 - /* retrieve response parameters */
7174 - rsp_params = (struct dprc_rsp_get_obj_desc *)cmd.params;
7175 - obj_desc->id = le32_to_cpu(rsp_params->id);
7176 - obj_desc->vendor = le16_to_cpu(rsp_params->vendor);
7177 - obj_desc->irq_count = rsp_params->irq_count;
7178 - obj_desc->region_count = rsp_params->region_count;
7179 - obj_desc->state = le32_to_cpu(rsp_params->state);
7180 - obj_desc->ver_major = le16_to_cpu(rsp_params->version_major);
7181 - obj_desc->ver_minor = le16_to_cpu(rsp_params->version_minor);
7182 - obj_desc->flags = le16_to_cpu(rsp_params->flags);
7183 - strncpy(obj_desc->type, rsp_params->type, 16);
7184 - obj_desc->type[15] = '\0';
7185 - strncpy(obj_desc->label, rsp_params->label, 16);
7186 - obj_desc->label[15] = '\0';
7190 -EXPORT_SYMBOL(dprc_get_obj_desc);
7193 * dprc_set_obj_irq() - Set IRQ information for object to trigger an interrupt.
7194 * @mc_io: Pointer to MC portal's I/O object
7195 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
7196 @@ -1130,52 +712,6 @@ int dprc_get_res_count(struct fsl_mc_io
7197 EXPORT_SYMBOL(dprc_get_res_count);
7200 - * dprc_get_res_ids() - Obtains IDs of free resources in the container
7201 - * @mc_io: Pointer to MC portal's I/O object
7202 - * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
7203 - * @token: Token of DPRC object
7204 - * @type: pool type
7205 - * @range_desc: range descriptor
7207 - * Return: '0' on Success; Error code otherwise.
7209 -int dprc_get_res_ids(struct fsl_mc_io *mc_io,
7213 - struct dprc_res_ids_range_desc *range_desc)
7215 - struct mc_command cmd = { 0 };
7216 - struct dprc_cmd_get_res_ids *cmd_params;
7217 - struct dprc_rsp_get_res_ids *rsp_params;
7220 - /* prepare command */
7221 - cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_RES_IDS,
7222 - cmd_flags, token);
7223 - cmd_params = (struct dprc_cmd_get_res_ids *)cmd.params;
7224 - cmd_params->iter_status = range_desc->iter_status;
7225 - cmd_params->base_id = cpu_to_le32(range_desc->base_id);
7226 - cmd_params->last_id = cpu_to_le32(range_desc->last_id);
7227 - strncpy(cmd_params->type, type, 16);
7228 - cmd_params->type[15] = '\0';
7230 - /* send command to mc*/
7231 - err = mc_send_command(mc_io, &cmd);
7235 - /* retrieve response parameters */
7236 - rsp_params = (struct dprc_rsp_get_res_ids *)cmd.params;
7237 - range_desc->iter_status = rsp_params->iter_status;
7238 - range_desc->base_id = le32_to_cpu(rsp_params->base_id);
7239 - range_desc->last_id = le32_to_cpu(rsp_params->last_id);
7243 -EXPORT_SYMBOL(dprc_get_res_ids);
7246 * dprc_get_obj_region() - Get region information for a specified object.
7247 * @mc_io: Pointer to MC portal's I/O object
7248 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
7249 @@ -1216,160 +752,66 @@ int dprc_get_obj_region(struct fsl_mc_io
7251 /* retrieve response parameters */
7252 rsp_params = (struct dprc_rsp_get_obj_region *)cmd.params;
7253 - region_desc->base_offset = le64_to_cpu(rsp_params->base_addr);
7254 + region_desc->base_offset = le32_to_cpu(rsp_params->base_addr);
7255 region_desc->size = le32_to_cpu(rsp_params->size);
7256 + region_desc->type = rsp_params->type;
7257 + region_desc->flags = le32_to_cpu(rsp_params->flags);
7261 EXPORT_SYMBOL(dprc_get_obj_region);
7264 - * dprc_set_obj_label() - Set object label.
7265 - * @mc_io: Pointer to MC portal's I/O object
7266 + * dprc_get_api_version - Get Data Path Resource Container API version
7267 + * @mc_io: Pointer to Mc portal's I/O object
7268 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
7269 - * @token: Token of DPRC object
7270 - * @obj_type: Object's type
7271 - * @obj_id: Object's ID
7272 - * @label: The required label. The maximum length is 16 chars.
7273 + * @major_ver: Major version of Data Path Resource Container API
7274 + * @minor_ver: Minor version of Data Path Resource Container API
7276 * Return: '0' on Success; Error code otherwise.
7278 -int dprc_set_obj_label(struct fsl_mc_io *mc_io,
7284 +int dprc_get_api_version(struct fsl_mc_io *mc_io,
7289 struct mc_command cmd = { 0 };
7290 - struct dprc_cmd_set_obj_label *cmd_params;
7293 /* prepare command */
7294 - cmd.header = mc_encode_cmd_header(DPRC_CMDID_SET_OBJ_LABEL,
7297 - cmd_params = (struct dprc_cmd_set_obj_label *)cmd.params;
7298 - cmd_params->obj_id = cpu_to_le32(obj_id);
7299 - strncpy(cmd_params->label, label, 16);
7300 - cmd_params->label[15] = '\0';
7301 - strncpy(cmd_params->obj_type, obj_type, 16);
7302 - cmd_params->obj_type[15] = '\0';
7303 + cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_API_VERSION,
7306 - /* send command to mc*/
7307 - return mc_send_command(mc_io, &cmd);
7309 -EXPORT_SYMBOL(dprc_set_obj_label);
7312 - * dprc_connect() - Connect two endpoints to create a network link between them
7313 - * @mc_io: Pointer to MC portal's I/O object
7314 - * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
7315 - * @token: Token of DPRC object
7316 - * @endpoint1: Endpoint 1 configuration parameters
7317 - * @endpoint2: Endpoint 2 configuration parameters
7318 - * @cfg: Connection configuration. The connection configuration is ignored for
7319 - * connections made to DPMAC objects, where rate is retrieved from the
7320 - * MAC configuration.
7322 - * Return: '0' on Success; Error code otherwise.
7324 -int dprc_connect(struct fsl_mc_io *mc_io,
7327 - const struct dprc_endpoint *endpoint1,
7328 - const struct dprc_endpoint *endpoint2,
7329 - const struct dprc_connection_cfg *cfg)
7331 - struct mc_command cmd = { 0 };
7332 - struct dprc_cmd_connect *cmd_params;
7333 + /* send command to mc */
7334 + err = mc_send_command(mc_io, &cmd);
7338 - /* prepare command */
7339 - cmd.header = mc_encode_cmd_header(DPRC_CMDID_CONNECT,
7342 - cmd_params = (struct dprc_cmd_connect *)cmd.params;
7343 - cmd_params->ep1_id = cpu_to_le32(endpoint1->id);
7344 - cmd_params->ep1_interface_id = cpu_to_le32(endpoint1->if_id);
7345 - cmd_params->ep2_id = cpu_to_le32(endpoint2->id);
7346 - cmd_params->ep2_interface_id = cpu_to_le32(endpoint2->if_id);
7347 - strncpy(cmd_params->ep1_type, endpoint1->type, 16);
7348 - cmd_params->ep1_type[15] = '\0';
7349 - cmd_params->max_rate = cpu_to_le32(cfg->max_rate);
7350 - cmd_params->committed_rate = cpu_to_le32(cfg->committed_rate);
7351 - strncpy(cmd_params->ep2_type, endpoint2->type, 16);
7352 - cmd_params->ep2_type[15] = '\0';
7353 + /* retrieve response parameters */
7354 + mc_cmd_read_api_version(&cmd, major_ver, minor_ver);
7356 - /* send command to mc*/
7357 - return mc_send_command(mc_io, &cmd);
7362 - * dprc_disconnect() - Disconnect one endpoint to remove its network connection
7363 - * @mc_io: Pointer to MC portal's I/O object
7364 - * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
7365 - * @token: Token of DPRC object
7366 - * @endpoint: Endpoint configuration parameters
7367 + * dprc_get_container_id - Get container ID associated with a given portal.
7368 + * @mc_io: Pointer to Mc portal's I/O object
7369 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
7370 + * @container_id: Requested container id
7372 * Return: '0' on Success; Error code otherwise.
7374 -int dprc_disconnect(struct fsl_mc_io *mc_io,
7377 - const struct dprc_endpoint *endpoint)
7379 - struct mc_command cmd = { 0 };
7380 - struct dprc_cmd_disconnect *cmd_params;
7382 - /* prepare command */
7383 - cmd.header = mc_encode_cmd_header(DPRC_CMDID_DISCONNECT,
7386 - cmd_params = (struct dprc_cmd_disconnect *)cmd.params;
7387 - cmd_params->id = cpu_to_le32(endpoint->id);
7388 - cmd_params->interface_id = cpu_to_le32(endpoint->if_id);
7389 - strncpy(cmd_params->type, endpoint->type, 16);
7390 - cmd_params->type[15] = '\0';
7392 - /* send command to mc*/
7393 - return mc_send_command(mc_io, &cmd);
7397 - * dprc_get_connection() - Get connected endpoint and link status if connection
7399 - * @mc_io: Pointer to MC portal's I/O object
7400 - * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
7401 - * @token: Token of DPRC object
7402 - * @endpoint1: Endpoint 1 configuration parameters
7403 - * @endpoint2: Returned endpoint 2 configuration parameters
7404 - * @state: Returned link state:
7406 - * 0 - link is down;
7407 - * -1 - no connection (endpoint2 information is irrelevant)
7409 - * Return: '0' on Success; -ENAVAIL if connection does not exist.
7411 -int dprc_get_connection(struct fsl_mc_io *mc_io,
7414 - const struct dprc_endpoint *endpoint1,
7415 - struct dprc_endpoint *endpoint2,
7417 +int dprc_get_container_id(struct fsl_mc_io *mc_io,
7419 + int *container_id)
7421 struct mc_command cmd = { 0 };
7422 - struct dprc_cmd_get_connection *cmd_params;
7423 - struct dprc_rsp_get_connection *rsp_params;
7426 /* prepare command */
7427 - cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_CONNECTION,
7428 + cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_CONT_ID,
7431 - cmd_params = (struct dprc_cmd_get_connection *)cmd.params;
7432 - cmd_params->ep1_id = cpu_to_le32(endpoint1->id);
7433 - cmd_params->ep1_interface_id = cpu_to_le32(endpoint1->if_id);
7434 - strncpy(cmd_params->ep1_type, endpoint1->type, 16);
7435 - cmd_params->ep1_type[15] = '\0';
7438 /* send command to mc*/
7439 err = mc_send_command(mc_io, &cmd);
7440 @@ -1377,12 +819,7 @@ int dprc_get_connection(struct fsl_mc_io
7443 /* retrieve response parameters */
7444 - rsp_params = (struct dprc_rsp_get_connection *)cmd.params;
7445 - endpoint2->id = le32_to_cpu(rsp_params->ep2_id);
7446 - endpoint2->if_id = le32_to_cpu(rsp_params->ep2_interface_id);
7447 - strncpy(endpoint2->type, rsp_params->ep2_type, 16);
7448 - endpoint2->type[15] = '\0';
7449 - *state = le32_to_cpu(rsp_params->state);
7450 + *container_id = (int)mc_cmd_read_object_id(&cmd);
7454 --- a/drivers/staging/fsl-mc/bus/fsl-mc-allocator.c
7455 +++ b/drivers/staging/fsl-mc/bus/fsl-mc-allocator.c
7458 - * Freescale MC object device allocator driver
7459 + * fsl-mc object allocator driver
7461 - * Copyright (C) 2013 Freescale Semiconductor, Inc.
7462 + * Copyright (C) 2013-2016 Freescale Semiconductor, Inc.
7464 * This file is licensed under the terms of the GNU General Public
7465 * License version 2. This program is licensed "as is" without any
7467 #include <linux/msi.h>
7468 #include "../include/mc-bus.h"
7469 #include "../include/mc-sys.h"
7470 -#include "../include/dpbp-cmd.h"
7471 -#include "../include/dpcon-cmd.h"
7473 +#include "dpbp-cmd.h"
7474 +#include "dpcon-cmd.h"
7475 #include "fsl-mc-private.h"
7477 #define FSL_MC_IS_ALLOCATABLE(_obj_type) \
7479 strcmp(_obj_type, "dpcon") == 0)
7482 - * fsl_mc_resource_pool_add_device - add allocatable device to a resource
7483 - * pool of a given MC bus
7484 + * fsl_mc_resource_pool_add_device - add allocatable object to a resource
7485 + * pool of a given fsl-mc bus
7487 - * @mc_bus: pointer to the MC bus
7488 - * @pool_type: MC bus pool type
7489 - * @mc_dev: Pointer to allocatable MC object device
7491 - * It adds an allocatable MC object device to a container's resource pool of
7492 - * the given resource type
7493 + * @mc_bus: pointer to the fsl-mc bus
7494 + * @pool_type: pool type
7495 + * @mc_dev: pointer to allocatable fsl-mc device
7497 static int __must_check fsl_mc_resource_pool_add_device(struct fsl_mc_bus
7499 @@ -95,10 +92,10 @@ out:
7500 * fsl_mc_resource_pool_remove_device - remove an allocatable device from a
7503 - * @mc_dev: Pointer to allocatable MC object device
7504 + * @mc_dev: pointer to allocatable fsl-mc device
7506 - * It permanently removes an allocatable MC object device from the resource
7507 - * pool, the device is currently in, as long as it is in the pool's free list.
7508 + * It permanently removes an allocatable fsl-mc device from the resource
7509 + * pool. It's an error if the device is in use.
7511 static int __must_check fsl_mc_resource_pool_remove_device(struct fsl_mc_device
7513 @@ -255,17 +252,18 @@ out_unlock:
7514 EXPORT_SYMBOL_GPL(fsl_mc_resource_free);
7517 - * fsl_mc_object_allocate - Allocates a MC object device of the given
7518 - * pool type from a given MC bus
7519 + * fsl_mc_object_allocate - Allocates an fsl-mc object of the given
7520 + * pool type from a given fsl-mc bus instance
7522 - * @mc_dev: MC device for which the MC object device is to be allocated
7523 - * @pool_type: MC bus resource pool type
7524 - * @new_mc_dev: Pointer to area where the pointer to the allocated
7525 - * MC object device is to be returned
7526 + * @mc_dev: fsl-mc device which is used in conjunction with the
7527 + * allocated object
7528 + * @pool_type: pool type
7529 + * @new_mc_dev: pointer to area where the pointer to the allocated device
7530 + * is to be returned
7532 - * This function allocates a MC object device from the device's parent DPRC,
7533 - * from the corresponding MC bus' pool of allocatable MC object devices of
7534 - * the given resource type. mc_dev cannot be a DPRC itself.
7535 + * Allocatable objects are always used in conjunction with some functional
7536 + * device. This function allocates an object of the specified type from
7537 + * the DPRC containing the functional device.
7539 * NOTE: pool_type must be different from FSL_MC_POOL_MCP, since MC
7540 * portals are allocated using fsl_mc_portal_allocate(), instead of
7541 @@ -312,10 +310,9 @@ error:
7542 EXPORT_SYMBOL_GPL(fsl_mc_object_allocate);
7545 - * fsl_mc_object_free - Returns an allocatable MC object device to the
7546 - * corresponding resource pool of a given MC bus.
7548 - * @mc_adev: Pointer to the MC object device
7549 + * fsl_mc_object_free - Returns an fsl-mc object to the resource
7550 + * pool where it came from.
7551 + * @mc_adev: Pointer to the fsl-mc device
7553 void fsl_mc_object_free(struct fsl_mc_device *mc_adev)
7555 @@ -332,8 +329,14 @@ void fsl_mc_object_free(struct fsl_mc_de
7556 EXPORT_SYMBOL_GPL(fsl_mc_object_free);
7559 - * Initialize the interrupt pool associated with a MC bus.
7560 - * It allocates a block of IRQs from the GIC-ITS
7561 + * A DPRC and the devices in the DPRC all share the same GIC-ITS device
7562 + * ID. A block of IRQs is pre-allocated and maintained in a pool
7563 + * from which devices can allocate them when needed.
7567 + * Initialize the interrupt pool associated with an fsl-mc bus.
7568 + * It allocates a block of IRQs from the GIC-ITS.
7570 int fsl_mc_populate_irq_pool(struct fsl_mc_bus *mc_bus,
7571 unsigned int irq_count)
7572 @@ -395,7 +398,7 @@ cleanup_msi_irqs:
7573 EXPORT_SYMBOL_GPL(fsl_mc_populate_irq_pool);
7576 - * Teardown the interrupt pool associated with an MC bus.
7577 + * Teardown the interrupt pool associated with an fsl-mc bus.
7578 * It frees the IRQs that were allocated to the pool, back to the GIC-ITS.
7580 void fsl_mc_cleanup_irq_pool(struct fsl_mc_bus *mc_bus)
7581 @@ -422,11 +425,7 @@ void fsl_mc_cleanup_irq_pool(struct fsl_
7582 EXPORT_SYMBOL_GPL(fsl_mc_cleanup_irq_pool);
7585 - * It allocates the IRQs required by a given MC object device. The
7586 - * IRQs are allocated from the interrupt pool associated with the
7587 - * MC bus that contains the device, if the device is not a DPRC device.
7588 - * Otherwise, the IRQs are allocated from the interrupt pool associated
7589 - * with the MC bus that represents the DPRC device itself.
7590 + * Allocate the IRQs required by a given fsl-mc device.
7592 int __must_check fsl_mc_allocate_irqs(struct fsl_mc_device *mc_dev)
7594 @@ -495,8 +494,7 @@ error_resource_alloc:
7595 EXPORT_SYMBOL_GPL(fsl_mc_allocate_irqs);
7598 - * It frees the IRQs that were allocated for a MC object device, by
7599 - * returning them to the corresponding interrupt pool.
7600 + * Frees the IRQs that were allocated for an fsl-mc device.
7602 void fsl_mc_free_irqs(struct fsl_mc_device *mc_dev)
7604 @@ -605,7 +603,7 @@ static int fsl_mc_allocator_probe(struct
7607 dev_dbg(&mc_dev->dev,
7608 - "Allocatable MC object device bound to fsl_mc_allocator driver");
7609 + "Allocatable fsl-mc device bound to fsl_mc_allocator driver");
7613 @@ -627,7 +625,7 @@ static int fsl_mc_allocator_remove(struc
7616 dev_dbg(&mc_dev->dev,
7617 - "Allocatable MC object device unbound from fsl_mc_allocator driver");
7618 + "Allocatable fsl-mc device unbound from fsl_mc_allocator driver");
7622 --- a/drivers/staging/fsl-mc/bus/fsl-mc-bus.c
7623 +++ b/drivers/staging/fsl-mc/bus/fsl-mc-bus.c
7626 * Freescale Management Complex (MC) bus driver
7628 - * Copyright (C) 2014 Freescale Semiconductor, Inc.
7629 + * Copyright (C) 2014-2016 Freescale Semiconductor, Inc.
7630 * Author: German Rivera <German.Rivera@freescale.com>
7632 * This file is licensed under the terms of the GNU General Public
7634 * warranty of any kind, whether express or implied.
7637 +#define pr_fmt(fmt) "fsl-mc: " fmt
7639 #include <linux/module.h>
7640 #include <linux/of_device.h>
7641 #include <linux/of_address.h>
7643 #include "fsl-mc-private.h"
7644 #include "dprc-cmd.h"
7646 -static struct kmem_cache *mc_dev_cache;
7649 * Default DMA mask for devices on a fsl-mc bus
7651 @@ -34,7 +34,7 @@ static struct kmem_cache *mc_dev_cache;
7654 * struct fsl_mc - Private data of a "fsl,qoriq-mc" platform device
7655 - * @root_mc_bus_dev: MC object device representing the root DPRC
7656 + * @root_mc_bus_dev: fsl-mc device representing the root DPRC
7657 * @num_translation_ranges: number of entries in addr_translation_ranges
7658 * @translation_ranges: array of bus to system address translation ranges
7660 @@ -62,8 +62,8 @@ struct fsl_mc_addr_translation_range {
7663 * fsl_mc_bus_match - device to driver matching callback
7664 - * @dev: the MC object device structure to match against
7665 - * @drv: the device driver to search for matching MC object device id
7666 + * @dev: the fsl-mc device to match against
7667 + * @drv: the device driver to search for matching fsl-mc object type
7670 * Returns 1 on success, 0 otherwise.
7671 @@ -75,8 +75,11 @@ static int fsl_mc_bus_match(struct devic
7672 struct fsl_mc_driver *mc_drv = to_fsl_mc_driver(drv);
7675 - if (WARN_ON(!fsl_mc_bus_exists()))
7676 + /* When driver_override is set, only bind to the matching driver */
7677 + if (mc_dev->driver_override) {
7678 + found = !strcmp(mc_dev->driver_override, mc_drv->driver.name);
7682 if (!mc_drv->match_id_table)
7684 @@ -91,7 +94,7 @@ static int fsl_mc_bus_match(struct devic
7687 * Traverse the match_id table of the given driver, trying to find
7688 - * a matching for the given MC object device.
7689 + * a matching for the given device.
7691 for (id = mc_drv->match_id_table; id->vendor != 0x0; id++) {
7692 if (id->vendor == mc_dev->obj_desc.vendor &&
7693 @@ -132,23 +135,141 @@ static ssize_t modalias_show(struct devi
7695 static DEVICE_ATTR_RO(modalias);
7697 +static ssize_t rescan_store(struct device *dev,
7698 + struct device_attribute *attr,
7699 + const char *buf, size_t count)
7701 + unsigned long val;
7702 + unsigned int irq_count;
7703 + struct fsl_mc_device *root_mc_dev;
7704 + struct fsl_mc_bus *root_mc_bus;
7706 + if (!fsl_mc_is_root_dprc(dev))
7709 + root_mc_dev = to_fsl_mc_device(dev);
7710 + root_mc_bus = to_fsl_mc_bus(root_mc_dev);
7712 + if (kstrtoul(buf, 0, &val) < 0)
7716 + mutex_lock(&root_mc_bus->scan_mutex);
7717 + dprc_scan_objects(root_mc_dev, NULL, &irq_count);
7718 + mutex_unlock(&root_mc_bus->scan_mutex);
7723 +static DEVICE_ATTR_WO(rescan);
7725 +static ssize_t driver_override_store(struct device *dev,
7726 + struct device_attribute *attr,
7727 + const char *buf, size_t count)
7729 + struct fsl_mc_device *mc_dev = to_fsl_mc_device(dev);
7730 + const char *driver_override, *old = mc_dev->driver_override;
7733 + if (WARN_ON(dev->bus != &fsl_mc_bus_type))
7736 + if (count >= (PAGE_SIZE - 1))
7739 + driver_override = kstrndup(buf, count, GFP_KERNEL);
7740 + if (!driver_override)
7743 + cp = strchr(driver_override, '\n');
7747 + if (strlen(driver_override)) {
7748 + mc_dev->driver_override = driver_override;
7750 + kfree(driver_override);
7751 + mc_dev->driver_override = NULL;
7759 +static ssize_t driver_override_show(struct device *dev,
7760 + struct device_attribute *attr, char *buf)
7762 + struct fsl_mc_device *mc_dev = to_fsl_mc_device(dev);
7764 + return snprintf(buf, PAGE_SIZE, "%s\n", mc_dev->driver_override);
7766 +static DEVICE_ATTR_RW(driver_override);
7768 static struct attribute *fsl_mc_dev_attrs[] = {
7769 &dev_attr_modalias.attr,
7770 + &dev_attr_rescan.attr,
7771 + &dev_attr_driver_override.attr,
7775 ATTRIBUTE_GROUPS(fsl_mc_dev);
7777 +static int scan_fsl_mc_bus(struct device *dev, void *data)
7779 + unsigned int irq_count;
7780 + struct fsl_mc_device *root_mc_dev;
7781 + struct fsl_mc_bus *root_mc_bus;
7783 + if (fsl_mc_is_root_dprc(dev)) {
7784 + root_mc_dev = to_fsl_mc_device(dev);
7785 + root_mc_bus = to_fsl_mc_bus(root_mc_dev);
7786 + mutex_lock(&root_mc_bus->scan_mutex);
7787 + dprc_scan_objects(root_mc_dev, NULL, &irq_count);
7788 + mutex_unlock(&root_mc_bus->scan_mutex);
7794 +static ssize_t bus_rescan_store(struct bus_type *bus,
7795 + const char *buf, size_t count)
7797 + unsigned long val;
7799 + if (kstrtoul(buf, 0, &val) < 0)
7803 + bus_for_each_dev(bus, NULL, NULL, scan_fsl_mc_bus);
7807 +static BUS_ATTR(rescan, (S_IWUSR | S_IWGRP), NULL, bus_rescan_store);
7809 +static struct attribute *fsl_mc_bus_attrs[] = {
7810 + &bus_attr_rescan.attr,
7814 +static const struct attribute_group fsl_mc_bus_group = {
7815 + .attrs = fsl_mc_bus_attrs,
7818 +static const struct attribute_group *fsl_mc_bus_groups[] = {
7819 + &fsl_mc_bus_group,
7823 struct bus_type fsl_mc_bus_type = {
7825 .match = fsl_mc_bus_match,
7826 .uevent = fsl_mc_bus_uevent,
7827 .dev_groups = fsl_mc_dev_groups,
7828 + .bus_groups = fsl_mc_bus_groups,
7830 EXPORT_SYMBOL_GPL(fsl_mc_bus_type);
7832 -static atomic_t root_dprc_count = ATOMIC_INIT(0);
7834 static int fsl_mc_driver_probe(struct device *dev)
7836 struct fsl_mc_driver *mc_drv;
7837 @@ -164,8 +285,7 @@ static int fsl_mc_driver_probe(struct de
7839 error = mc_drv->probe(mc_dev);
7841 - dev_err(dev, "MC object device probe callback failed: %d\n",
7843 + dev_err(dev, "%s failed: %d\n", __func__, error);
7847 @@ -183,9 +303,7 @@ static int fsl_mc_driver_remove(struct d
7849 error = mc_drv->remove(mc_dev);
7852 - "MC object device remove callback failed: %d\n",
7854 + dev_err(dev, "%s failed: %d\n", __func__, error);
7858 @@ -232,8 +350,6 @@ int __fsl_mc_driver_register(struct fsl_
7862 - pr_info("MC object device driver %s registered\n",
7863 - mc_driver->driver.name);
7866 EXPORT_SYMBOL_GPL(__fsl_mc_driver_register);
7867 @@ -249,15 +365,6 @@ void fsl_mc_driver_unregister(struct fsl
7868 EXPORT_SYMBOL_GPL(fsl_mc_driver_unregister);
7871 - * fsl_mc_bus_exists - check if a root dprc exists
7873 -bool fsl_mc_bus_exists(void)
7875 - return atomic_read(&root_dprc_count) > 0;
7877 -EXPORT_SYMBOL_GPL(fsl_mc_bus_exists);
7880 * fsl_mc_get_root_dprc - function to traverse to the root dprc
7882 void fsl_mc_get_root_dprc(struct device *dev,
7883 @@ -315,21 +422,6 @@ static int get_dprc_icid(struct fsl_mc_i
7887 -static int get_dprc_version(struct fsl_mc_io *mc_io,
7888 - int container_id, u16 *major, u16 *minor)
7890 - struct dprc_attributes attr;
7893 - error = get_dprc_attr(mc_io, container_id, &attr);
7895 - *major = attr.version.major;
7896 - *minor = attr.version.minor;
7902 static int translate_mc_addr(struct fsl_mc_device *mc_dev,
7903 enum dprc_region_type mc_region_type,
7904 u64 mc_offset, phys_addr_t *phys_addr)
7905 @@ -451,18 +543,37 @@ bool fsl_mc_is_root_dprc(struct device *
7906 return dev == root_dprc_dev;
7909 +static void fsl_mc_device_release(struct device *dev)
7911 + struct fsl_mc_device *mc_dev = to_fsl_mc_device(dev);
7912 + struct fsl_mc_bus *mc_bus = NULL;
7914 + kfree(mc_dev->regions);
7916 + if (strcmp(mc_dev->obj_desc.type, "dprc") == 0)
7917 + mc_bus = to_fsl_mc_bus(mc_dev);
7926 - * Add a newly discovered MC object device to be visible in Linux
7927 + * Add a newly discovered fsl-mc device to be visible in Linux
7929 int fsl_mc_device_add(struct dprc_obj_desc *obj_desc,
7930 struct fsl_mc_io *mc_io,
7931 struct device *parent_dev,
7932 + const char *driver_override,
7933 struct fsl_mc_device **new_mc_dev)
7936 struct fsl_mc_device *mc_dev = NULL;
7937 struct fsl_mc_bus *mc_bus = NULL;
7938 struct fsl_mc_device *parent_mc_dev;
7939 + struct device *fsl_mc_platform_dev;
7940 + struct device_node *fsl_mc_platform_node;
7942 if (dev_is_fsl_mc(parent_dev))
7943 parent_mc_dev = to_fsl_mc_device(parent_dev);
7944 @@ -473,7 +584,7 @@ int fsl_mc_device_add(struct dprc_obj_de
7946 * Allocate an MC bus device object:
7948 - mc_bus = devm_kzalloc(parent_dev, sizeof(*mc_bus), GFP_KERNEL);
7949 + mc_bus = kzalloc(sizeof(*mc_bus), GFP_KERNEL);
7953 @@ -482,16 +593,30 @@ int fsl_mc_device_add(struct dprc_obj_de
7955 * Allocate a regular fsl_mc_device object:
7957 - mc_dev = kmem_cache_zalloc(mc_dev_cache, GFP_KERNEL);
7958 + mc_dev = kzalloc(sizeof(*mc_dev), GFP_KERNEL);
7963 mc_dev->obj_desc = *obj_desc;
7964 mc_dev->mc_io = mc_io;
7966 + if (driver_override) {
7968 + * We trust driver_override, so we don't need to use
7971 + mc_dev->driver_override = kstrdup(driver_override, GFP_KERNEL);
7972 + if (!mc_dev->driver_override) {
7974 + goto error_cleanup_dev;
7978 device_initialize(&mc_dev->dev);
7979 mc_dev->dev.parent = parent_dev;
7980 mc_dev->dev.bus = &fsl_mc_bus_type;
7981 + mc_dev->dev.release = fsl_mc_device_release;
7982 dev_set_name(&mc_dev->dev, "%s.%d", obj_desc->type, obj_desc->id);
7984 if (strcmp(obj_desc->type, "dprc") == 0) {
7985 @@ -524,8 +649,6 @@ int fsl_mc_device_add(struct dprc_obj_de
7990 - atomic_inc(&root_dprc_count);
7993 error = get_dprc_icid(mc_io2, obj_desc->id, &mc_dev->icid);
7994 @@ -533,8 +656,8 @@ int fsl_mc_device_add(struct dprc_obj_de
7995 goto error_cleanup_dev;
7998 - * A non-DPRC MC object device has to be a child of another
7999 - * MC object (specifically a DPRC object)
8000 + * A non-DPRC object has to be a child of a DPRC, use the
8001 + * parent's ICID and interrupt domain.
8003 mc_dev->icid = parent_mc_dev->icid;
8004 mc_dev->dma_mask = FSL_MC_DEFAULT_DMA_MASK;
8005 @@ -556,9 +679,14 @@ int fsl_mc_device_add(struct dprc_obj_de
8006 goto error_cleanup_dev;
8009 - /* Objects are coherent, unless 'no shareability' flag set. */
8010 - if (!(obj_desc->flags & DPRC_OBJ_FLAG_NO_MEM_SHAREABILITY))
8011 - arch_setup_dma_ops(&mc_dev->dev, 0, 0, NULL, true);
8012 + fsl_mc_platform_dev = &mc_dev->dev;
8013 + while (dev_is_fsl_mc(fsl_mc_platform_dev))
8014 + fsl_mc_platform_dev = fsl_mc_platform_dev->parent;
8015 + fsl_mc_platform_node = fsl_mc_platform_dev->of_node;
8017 + /* Set up the iommu configuration for the devices. */
8018 + fsl_mc_dma_configure(mc_dev, fsl_mc_platform_node,
8019 + !(obj_desc->flags & DPRC_OBJ_FLAG_NO_MEM_SHAREABILITY));
8022 * The device-specific probe callback will get invoked by device_add()
8023 @@ -571,9 +699,7 @@ int fsl_mc_device_add(struct dprc_obj_de
8024 goto error_cleanup_dev;
8027 - (void)get_device(&mc_dev->dev);
8028 - dev_dbg(parent_dev, "Added MC object device %s\n",
8029 - dev_name(&mc_dev->dev));
8030 + dev_dbg(parent_dev, "added %s\n", dev_name(&mc_dev->dev));
8032 *new_mc_dev = mc_dev;
8034 @@ -581,47 +707,34 @@ int fsl_mc_device_add(struct dprc_obj_de
8036 kfree(mc_dev->regions);
8038 - devm_kfree(parent_dev, mc_bus);
8041 - kmem_cache_free(mc_dev_cache, mc_dev);
8046 EXPORT_SYMBOL_GPL(fsl_mc_device_add);
8049 - * fsl_mc_device_remove - Remove a MC object device from being visible to
8050 + * fsl_mc_device_remove - Remove an fsl-mc device from being visible to
8053 - * @mc_dev: Pointer to a MC object device object
8054 + * @mc_dev: Pointer to an fsl-mc device
8056 void fsl_mc_device_remove(struct fsl_mc_device *mc_dev)
8058 - struct fsl_mc_bus *mc_bus = NULL;
8060 - kfree(mc_dev->regions);
8061 + kfree(mc_dev->driver_override);
8062 + mc_dev->driver_override = NULL;
8065 * The device-specific remove callback will get invoked by device_del()
8067 device_del(&mc_dev->dev);
8068 - put_device(&mc_dev->dev);
8070 - if (strcmp(mc_dev->obj_desc.type, "dprc") == 0) {
8071 - mc_bus = to_fsl_mc_bus(mc_dev);
8073 - if (fsl_mc_is_root_dprc(&mc_dev->dev)) {
8074 - if (atomic_read(&root_dprc_count) > 0)
8075 - atomic_dec(&root_dprc_count);
8080 + if (strcmp(mc_dev->obj_desc.type, "dprc") != 0)
8081 + mc_dev->dev.iommu_fwspec = NULL;
8084 - devm_kfree(mc_dev->dev.parent, mc_bus);
8086 - kmem_cache_free(mc_dev_cache, mc_dev);
8087 + put_device(&mc_dev->dev);
8089 EXPORT_SYMBOL_GPL(fsl_mc_device_remove);
8091 @@ -629,8 +742,7 @@ static int parse_mc_ranges(struct device
8095 - const __be32 **ranges_start,
8097 + const __be32 **ranges_start)
8100 int range_tuple_cell_count;
8101 @@ -643,8 +755,6 @@ static int parse_mc_ranges(struct device
8103 "missing or empty ranges property for device tree node '%s'\n",
8110 @@ -671,8 +781,7 @@ static int parse_mc_ranges(struct device
8114 - *num_ranges = ranges_len / tuple_len;
8116 + return ranges_len / tuple_len;
8119 static int get_mc_addr_translation_ranges(struct device *dev,
8120 @@ -680,7 +789,7 @@ static int get_mc_addr_translation_range
8129 @@ -688,16 +797,16 @@ static int get_mc_addr_translation_range
8130 const __be32 *ranges_start;
8133 - error = parse_mc_ranges(dev,
8134 + ret = parse_mc_ranges(dev,
8146 - if (!(*num_ranges)) {
8147 + *num_ranges = ret;
8150 * Missing or empty ranges property ("ranges;") for the
8151 * 'fsl,qoriq-mc' node. In this case, identity mapping
8152 @@ -749,8 +858,6 @@ static int fsl_mc_bus_probe(struct platf
8153 struct mc_version mc_version;
8154 struct resource res;
8156 - dev_info(&pdev->dev, "Root MC bus device probed");
8158 mc = devm_kzalloc(&pdev->dev, sizeof(*mc), GFP_KERNEL);
8161 @@ -783,8 +890,7 @@ static int fsl_mc_bus_probe(struct platf
8162 goto error_cleanup_mc_io;
8165 - dev_info(&pdev->dev,
8166 - "Freescale Management Complex Firmware version: %u.%u.%u\n",
8167 + dev_info(&pdev->dev, "MC firmware version: %u.%u.%u\n",
8168 mc_version.major, mc_version.minor, mc_version.revision);
8170 error = get_mc_addr_translation_ranges(&pdev->dev,
8171 @@ -793,16 +899,17 @@ static int fsl_mc_bus_probe(struct platf
8173 goto error_cleanup_mc_io;
8175 - error = dpmng_get_container_id(mc_io, 0, &container_id);
8176 + error = dprc_get_container_id(mc_io, 0, &container_id);
8179 - "dpmng_get_container_id() failed: %d\n", error);
8180 + "dprc_get_container_id() failed: %d\n", error);
8181 goto error_cleanup_mc_io;
8184 memset(&obj_desc, 0, sizeof(struct dprc_obj_desc));
8185 - error = get_dprc_version(mc_io, container_id,
8186 - &obj_desc.ver_major, &obj_desc.ver_minor);
8187 + error = dprc_get_api_version(mc_io, 0,
8188 + &obj_desc.ver_major,
8189 + &obj_desc.ver_minor);
8191 goto error_cleanup_mc_io;
8193 @@ -812,7 +919,8 @@ static int fsl_mc_bus_probe(struct platf
8194 obj_desc.irq_count = 1;
8195 obj_desc.region_count = 0;
8197 - error = fsl_mc_device_add(&obj_desc, mc_io, &pdev->dev, &mc_bus_dev);
8198 + error = fsl_mc_device_add(&obj_desc, mc_io, &pdev->dev, NULL,
8201 goto error_cleanup_mc_io;
8203 @@ -840,7 +948,6 @@ static int fsl_mc_bus_remove(struct plat
8204 fsl_destroy_mc_io(mc->root_mc_bus_dev->mc_io);
8205 mc->root_mc_bus_dev->mc_io = NULL;
8207 - dev_info(&pdev->dev, "Root MC bus device removed");
8211 @@ -865,22 +972,12 @@ static int __init fsl_mc_bus_driver_init
8215 - mc_dev_cache = kmem_cache_create("fsl_mc_device",
8216 - sizeof(struct fsl_mc_device), 0, 0,
8218 - if (!mc_dev_cache) {
8219 - pr_err("Could not create fsl_mc_device cache\n");
8223 error = bus_register(&fsl_mc_bus_type);
8225 - pr_err("fsl-mc bus type registration failed: %d\n", error);
8226 + pr_err("bus type registration failed: %d\n", error);
8227 goto error_cleanup_cache;
8230 - pr_info("fsl-mc bus type registered\n");
8232 error = platform_driver_register(&fsl_mc_bus_driver);
8234 pr_err("platform_driver_register() failed: %d\n", error);
8235 @@ -914,7 +1011,6 @@ error_cleanup_bus:
8236 bus_unregister(&fsl_mc_bus_type);
8238 error_cleanup_cache:
8239 - kmem_cache_destroy(mc_dev_cache);
8242 postcore_initcall(fsl_mc_bus_driver_init);
8244 +++ b/drivers/staging/fsl-mc/bus/fsl-mc-iommu.c
8247 + * Copyright 2016-17 NXP
8248 + * Author: Nipun Gupta <nipun.gupta@nxp.com>
8250 + * This file is licensed under the terms of the GNU General Public
8251 + * License version 2. This program is licensed "as is" without any
8252 + * warranty of any kind, whether express or implied.
8255 +#include <linux/iommu.h>
8256 +#include <linux/of.h>
8257 +#include <linux/of_iommu.h>
8258 +#include "../include/mc.h"
8260 +/* Setup the IOMMU for the DPRC container */
8261 +static const struct iommu_ops
8262 +*fsl_mc_iommu_configure(struct fsl_mc_device *mc_dev,
8263 + struct device_node *fsl_mc_platform_node)
8265 + struct of_phandle_args iommu_spec;
8266 + const struct iommu_ops *ops;
8267 + u32 iommu_phandle;
8268 + struct device_node *iommu_node;
8269 + const __be32 *map = NULL;
8270 + int iommu_cells, map_len, ret;
8272 + map = of_get_property(fsl_mc_platform_node, "iommu-map", &map_len);
8276 + ops = mc_dev->dev.bus->iommu_ops;
8277 + if (!ops || !ops->of_xlate)
8280 + iommu_phandle = be32_to_cpup(map + 1);
8281 + iommu_node = of_find_node_by_phandle(iommu_phandle);
8283 + if (of_property_read_u32(iommu_node, "#iommu-cells", &iommu_cells)) {
8284 + pr_err("%s: missing #iommu-cells property\n", iommu_node->name);
8288 + /* Initialize the fwspec */
8289 + ret = iommu_fwspec_init(&mc_dev->dev, &iommu_node->fwnode, ops);
8294 + * Fill in the required stream-id before calling the iommu's
8295 + * ops->xlate callback.
8297 + iommu_spec.np = iommu_node;
8298 + iommu_spec.args[0] = mc_dev->icid;
8299 + iommu_spec.args_count = 1;
8301 + ret = ops->of_xlate(&mc_dev->dev, &iommu_spec);
8305 + of_node_put(iommu_spec.np);
8310 +/* Set up DMA configuration for fsl-mc devices */
8311 +void fsl_mc_dma_configure(struct fsl_mc_device *mc_dev,
8312 + struct device_node *fsl_mc_platform_node, int coherent)
8314 + const struct iommu_ops *ops;
8316 + ops = fsl_mc_iommu_configure(mc_dev, fsl_mc_platform_node);
8318 + mc_dev->dev.coherent_dma_mask = DMA_BIT_MASK(48);
8319 + mc_dev->dev.dma_mask = &mc_dev->dev.coherent_dma_mask;
8320 + arch_setup_dma_ops(&mc_dev->dev, 0,
8321 + mc_dev->dev.coherent_dma_mask + 1, ops, coherent);
8324 +/* Macro to get the container device of a MC device */
8325 +#define fsl_mc_cont_dev(_dev) ((to_fsl_mc_device(_dev)->flags & \
8326 + FSL_MC_IS_DPRC) ? (_dev) : ((_dev)->parent))
8328 +/* Macro to check if a device is a container device */
8329 +#define is_cont_dev(_dev) (to_fsl_mc_device(_dev)->flags & FSL_MC_IS_DPRC)
8331 +/* Get the IOMMU group for device on fsl-mc bus */
8332 +struct iommu_group *fsl_mc_device_group(struct device *dev)
8334 + struct device *cont_dev = fsl_mc_cont_dev(dev);
8335 + struct iommu_group *group;
8337 + /* Container device is responsible for creating the iommu group */
8338 + if (is_cont_dev(dev)) {
8339 + group = iommu_group_alloc();
8340 + if (IS_ERR(group))
8343 + get_device(cont_dev);
8344 + group = iommu_group_get(cont_dev);
8345 + put_device(cont_dev);
8350 --- a/drivers/staging/fsl-mc/bus/fsl-mc-msi.c
8351 +++ b/drivers/staging/fsl-mc/bus/fsl-mc-msi.c
8354 * Freescale Management Complex (MC) bus driver MSI support
8356 - * Copyright (C) 2015 Freescale Semiconductor, Inc.
8357 + * Copyright (C) 2015-2016 Freescale Semiconductor, Inc.
8358 * Author: German Rivera <German.Rivera@freescale.com>
8360 * This file is licensed under the terms of the GNU General Public
8361 --- a/drivers/staging/fsl-mc/bus/fsl-mc-private.h
8362 +++ b/drivers/staging/fsl-mc/bus/fsl-mc-private.h
8364 #ifndef _FSL_MC_PRIVATE_H_
8365 #define _FSL_MC_PRIVATE_H_
8367 +#include "../include/mc.h"
8368 +#include "../include/mc-bus.h"
8370 int __must_check fsl_mc_device_add(struct dprc_obj_desc *obj_desc,
8371 struct fsl_mc_io *mc_io,
8372 struct device *parent_dev,
8373 + const char *driver_override,
8374 struct fsl_mc_device **new_mc_dev);
8376 -void fsl_mc_device_remove(struct fsl_mc_device *mc_dev);
8378 int __init dprc_driver_init(void);
8380 void dprc_driver_exit(void);
8381 --- a/drivers/staging/fsl-mc/bus/irq-gic-v3-its-fsl-mc-msi.c
8382 +++ b/drivers/staging/fsl-mc/bus/irq-gic-v3-its-fsl-mc-msi.c
8385 * Freescale Management Complex (MC) bus driver MSI support
8387 - * Copyright (C) 2015 Freescale Semiconductor, Inc.
8388 + * Copyright (C) 2015-2016 Freescale Semiconductor, Inc.
8389 * Author: German Rivera <German.Rivera@freescale.com>
8391 * This file is licensed under the terms of the GNU General Public
8393 #include "fsl-mc-private.h"
8395 static struct irq_chip its_msi_irq_chip = {
8396 - .name = "fsl-mc-bus-msi",
8397 + .name = "ITS-fMSI",
8398 .irq_mask = irq_chip_mask_parent,
8399 .irq_unmask = irq_chip_unmask_parent,
8400 .irq_eoi = irq_chip_eoi_parent,
8401 @@ -52,7 +52,7 @@ static int its_fsl_mc_msi_prepare(struct
8402 return msi_info->ops->msi_prepare(msi_domain->parent, dev, nvec, info);
8405 -static struct msi_domain_ops its_fsl_mc_msi_ops = {
8406 +static struct msi_domain_ops its_fsl_mc_msi_ops __ro_after_init = {
8407 .msi_prepare = its_fsl_mc_msi_prepare,
8410 @@ -95,8 +95,8 @@ int __init its_fsl_mc_msi_init(void)
8414 - WARN_ON(mc_msi_domain->
8415 - host_data != &its_fsl_mc_msi_domain_info);
8416 + WARN_ON(mc_msi_domain->host_data !=
8417 + &its_fsl_mc_msi_domain_info);
8419 pr_info("fsl-mc MSI: %s domain created\n", np->full_name);
8421 --- a/drivers/staging/fsl-mc/bus/mc-io.c
8422 +++ b/drivers/staging/fsl-mc/bus/mc-io.c
8424 -/* Copyright 2013-2016 Freescale Semiconductor Inc.
8426 + * Copyright 2013-2016 Freescale Semiconductor Inc.
8428 * Redistribution and use in source and binary forms, with or without
8429 * modification, are permitted provided that the following conditions are met:
8431 * names of any contributors may be used to endorse or promote products
8432 * derived from this software without specific prior written permission.
8435 * ALTERNATIVELY, this software may be distributed under the terms of the
8436 * GNU General Public License ("GPL") as published by the Free Software
8437 * Foundation, either version 2 of that License or (at your option) any
8439 +++ b/drivers/staging/fsl-mc/bus/mc-ioctl.h
8442 + * Freescale Management Complex (MC) ioclt interface
8444 + * Copyright (C) 2014 Freescale Semiconductor, Inc.
8445 + * Author: Lijun Pan <Lijun.Pan@freescale.com>
8447 + * This file is licensed under the terms of the GNU General Public
8448 + * License version 2. This program is licensed "as is" without any
8449 + * warranty of any kind, whether express or implied.
8451 +#ifndef _FSL_MC_IOCTL_H_
8452 +#define _FSL_MC_IOCTL_H_
8454 +#include <linux/ioctl.h>
8455 +#include "../include/mc-sys.h"
8457 +#define RESTOOL_IOCTL_TYPE 'R'
8459 +#define RESTOOL_SEND_MC_COMMAND \
8460 + _IOWR(RESTOOL_IOCTL_TYPE, 0xE0, struct mc_command)
8462 +#endif /* _FSL_MC_IOCTL_H_ */
8464 +++ b/drivers/staging/fsl-mc/bus/mc-restool.c
8467 + * Freescale Management Complex (MC) restool driver
8469 + * Copyright (C) 2014 Freescale Semiconductor, Inc.
8470 + * Author: Lijun Pan <Lijun.Pan@freescale.com>
8472 + * This file is licensed under the terms of the GNU General Public
8473 + * License version 2. This program is licensed "as is" without any
8474 + * warranty of any kind, whether express or implied.
8477 +#include "../include/mc.h"
8478 +#include <linux/module.h>
8479 +#include <linux/fs.h>
8480 +#include <linux/miscdevice.h>
8481 +#include <linux/mm.h>
8482 +#include <linux/slab.h>
8483 +#include <linux/uaccess.h>
8484 +#include <linux/mutex.h>
8485 +#include <linux/platform_device.h>
8486 +#include "mc-ioctl.h"
8487 +#include "../include/mc-sys.h"
8488 +#include "../include/mc-bus.h"
8489 +#include "../include/mc-cmd.h"
8490 +#include "../include/dpmng.h"
8493 + * Maximum number of DPRCs that can be opened at the same time
8495 +#define MAX_DPRC_HANDLES 64
8498 + * restool_misc - information associated with the newly added miscdevice
8499 + * @misc: newly created miscdevice associated with root dprc
8500 + * @miscdevt: device id of this miscdevice
8501 + * @list: a linked list node representing this miscdevcie
8502 + * @static_mc_io: pointer to the static MC I/O object used by the restool
8503 + * @dynamic_instance_count: number of dynamically created instances
8504 + * @static_instance_in_use: static instance is in use or not
8505 + * @mutex: mutex lock to serialze the open/release operations
8506 + * @dev: root dprc associated with this miscdevice
8508 +struct restool_misc {
8509 + struct miscdevice misc;
8511 + struct list_head list;
8512 + struct fsl_mc_io *static_mc_io;
8513 + u32 dynamic_instance_count;
8514 + bool static_instance_in_use;
8515 + struct mutex mutex; /* serialze the open/release operations */
8516 + struct device *dev;
8520 + * struct fsl_mc - Private data of a "fsl,qoriq-mc" platform device
8521 + * @root_mc_bus_dev: fsl-mc device representing the root DPRC
8522 + * @num_translation_ranges: number of entries in addr_translation_ranges
8523 + * @translation_ranges: array of bus to system address translation ranges
8526 + struct fsl_mc_device *root_mc_bus_dev;
8527 + u8 num_translation_ranges;
8528 + struct fsl_mc_addr_translation_range *translation_ranges;
8532 + * initialize a global list to link all
8533 + * the miscdevice nodes (struct restool_misc)
8535 +static LIST_HEAD(misc_list);
8536 +static DEFINE_MUTEX(misc_list_mutex);
8538 +static int fsl_mc_restool_dev_open(struct inode *inode, struct file *filep)
8540 + struct fsl_mc_device *root_mc_dev;
8542 + struct fsl_mc_io *dynamic_mc_io = NULL;
8543 + struct restool_misc *restool_misc = NULL;
8544 + struct restool_misc *restool_misc_cursor;
8546 + mutex_lock(&misc_list_mutex);
8548 + list_for_each_entry(restool_misc_cursor, &misc_list, list) {
8549 + if (restool_misc_cursor->miscdevt == inode->i_rdev) {
8550 + restool_misc = restool_misc_cursor;
8555 + mutex_unlock(&misc_list_mutex);
8557 + if (!restool_misc)
8560 + if (WARN_ON(!restool_misc->dev))
8563 + mutex_lock(&restool_misc->mutex);
8565 + if (!restool_misc->static_instance_in_use) {
8566 + restool_misc->static_instance_in_use = true;
8567 + filep->private_data = restool_misc->static_mc_io;
8569 + dynamic_mc_io = kzalloc(sizeof(*dynamic_mc_io), GFP_KERNEL);
8570 + if (!dynamic_mc_io) {
8575 + root_mc_dev = to_fsl_mc_device(restool_misc->dev);
8576 + error = fsl_mc_portal_allocate(root_mc_dev, 0, &dynamic_mc_io);
8578 + pr_err("Not able to allocate MC portal\n");
8579 + goto free_dynamic_mc_io;
8581 + ++restool_misc->dynamic_instance_count;
8582 + filep->private_data = dynamic_mc_io;
8585 + mutex_unlock(&restool_misc->mutex);
8589 +free_dynamic_mc_io:
8590 + kfree(dynamic_mc_io);
8592 + mutex_unlock(&restool_misc->mutex);
8597 +static int fsl_mc_restool_dev_release(struct inode *inode, struct file *filep)
8599 + struct fsl_mc_io *local_mc_io = filep->private_data;
8600 + struct restool_misc *restool_misc = NULL;
8601 + struct restool_misc *restool_misc_cursor;
8603 + if (WARN_ON(!filep->private_data))
8606 + mutex_lock(&misc_list_mutex);
8608 + list_for_each_entry(restool_misc_cursor, &misc_list, list) {
8609 + if (restool_misc_cursor->miscdevt == inode->i_rdev) {
8610 + restool_misc = restool_misc_cursor;
8615 + mutex_unlock(&misc_list_mutex);
8617 + if (!restool_misc)
8620 + mutex_lock(&restool_misc->mutex);
8622 + if (WARN_ON(restool_misc->dynamic_instance_count == 0 &&
8623 + !restool_misc->static_instance_in_use)) {
8624 + mutex_unlock(&restool_misc->mutex);
8628 + /* Globally clean up opened/untracked handles */
8629 + fsl_mc_portal_reset(local_mc_io);
8633 + * whether local_mc_io is dynamic or static instance
8634 + * Otherwise it will free up the reserved portal by accident
8635 + * or even not free up the dynamic allocated portal
8636 + * if 2 or more instances running concurrently
8638 + if (local_mc_io == restool_misc->static_mc_io) {
8639 + restool_misc->static_instance_in_use = false;
8641 + fsl_mc_portal_free(local_mc_io);
8642 + kfree(filep->private_data);
8643 + --restool_misc->dynamic_instance_count;
8646 + filep->private_data = NULL;
8647 + mutex_unlock(&restool_misc->mutex);
8652 +static int restool_send_mc_command(unsigned long arg,
8653 + struct fsl_mc_io *local_mc_io)
8656 + struct mc_command mc_cmd;
8658 + if (copy_from_user(&mc_cmd, (void __user *)arg, sizeof(mc_cmd)))
8662 + * Send MC command to the MC:
8664 + error = mc_send_command(local_mc_io, &mc_cmd);
8668 + if (copy_to_user((void __user *)arg, &mc_cmd, sizeof(mc_cmd)))
8675 +fsl_mc_restool_dev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
8680 + case RESTOOL_SEND_MC_COMMAND:
8681 + error = restool_send_mc_command(arg, file->private_data);
8684 + pr_err("%s: unexpected ioctl call number\n", __func__);
8691 +static const struct file_operations fsl_mc_restool_dev_fops = {
8692 + .owner = THIS_MODULE,
8693 + .open = fsl_mc_restool_dev_open,
8694 + .release = fsl_mc_restool_dev_release,
8695 + .unlocked_ioctl = fsl_mc_restool_dev_ioctl,
8698 +static int restool_add_device_file(struct device *dev)
8701 + char name2[20] = {0};
8703 + struct fsl_mc_device *root_mc_dev;
8704 + struct restool_misc *restool_misc;
8706 + if (dev->bus == &platform_bus_type && dev->driver_data) {
8707 + if (sscanf(dev_name(dev), "%x.%s", &name1, name2) != 2)
8710 + if (strcmp(name2, "fsl-mc") == 0)
8711 + pr_debug("platform's root dprc name is: %s\n",
8712 + dev_name(&(((struct fsl_mc *)
8713 + (dev->driver_data))->root_mc_bus_dev->dev)));
8716 + if (!fsl_mc_is_root_dprc(dev))
8719 + restool_misc = kzalloc(sizeof(*restool_misc), GFP_KERNEL);
8720 + if (!restool_misc)
8723 + restool_misc->dev = dev;
8724 + root_mc_dev = to_fsl_mc_device(dev);
8725 + error = fsl_mc_portal_allocate(root_mc_dev, 0,
8726 + &restool_misc->static_mc_io);
8728 + pr_err("Not able to allocate MC portal\n");
8729 + goto free_restool_misc;
8732 + restool_misc->misc.minor = MISC_DYNAMIC_MINOR;
8733 + restool_misc->misc.name = dev_name(dev);
8734 + restool_misc->misc.fops = &fsl_mc_restool_dev_fops;
8736 + error = misc_register(&restool_misc->misc);
8738 + pr_err("misc_register() failed: %d\n", error);
8742 + restool_misc->miscdevt = restool_misc->misc.this_device->devt;
8743 + mutex_init(&restool_misc->mutex);
8744 + mutex_lock(&misc_list_mutex);
8745 + list_add(&restool_misc->list, &misc_list);
8746 + mutex_unlock(&misc_list_mutex);
8748 + pr_info("/dev/%s driver registered\n", dev_name(dev));
8753 + fsl_mc_portal_free(restool_misc->static_mc_io);
8755 + kfree(restool_misc);
8760 +static int restool_bus_notifier(struct notifier_block *nb,
8761 + unsigned long action, void *data)
8764 + struct device *dev = data;
8767 + case BUS_NOTIFY_ADD_DEVICE:
8768 + error = restool_add_device_file(dev);
8772 + case BUS_NOTIFY_DEL_DEVICE:
8773 + case BUS_NOTIFY_REMOVED_DEVICE:
8774 + case BUS_NOTIFY_BIND_DRIVER:
8775 + case BUS_NOTIFY_BOUND_DRIVER:
8776 + case BUS_NOTIFY_UNBIND_DRIVER:
8777 + case BUS_NOTIFY_UNBOUND_DRIVER:
8780 + pr_err("%s: unrecognized device action from %s\n", __func__,
8788 +static int add_to_restool(struct device *dev, void *data)
8790 + return restool_add_device_file(dev);
8793 +static int __init fsl_mc_restool_driver_init(void)
8796 + struct notifier_block *nb;
8798 + nb = kzalloc(sizeof(*nb), GFP_KERNEL);
8802 + nb->notifier_call = restool_bus_notifier;
8803 + error = bus_register_notifier(&fsl_mc_bus_type, nb);
8808 + * This driver runs after fsl-mc bus driver runs.
8809 + * Hence, many of the root dprcs are already attached to fsl-mc bus
8810 + * In order to make sure we find all the root dprcs,
8811 + * we need to scan the fsl_mc_bus_type.
8813 + error = bus_for_each_dev(&fsl_mc_bus_type, NULL, NULL, add_to_restool);
8815 + bus_unregister_notifier(&fsl_mc_bus_type, nb);
8817 + pr_err("restool driver registration failure\n");
8828 +module_init(fsl_mc_restool_driver_init);
8830 +static void __exit fsl_mc_restool_driver_exit(void)
8832 + struct restool_misc *restool_misc;
8833 + struct restool_misc *restool_misc_tmp;
8834 + char name1[20] = {0};
8837 + list_for_each_entry_safe(restool_misc, restool_misc_tmp,
8838 + &misc_list, list) {
8839 + if (sscanf(restool_misc->misc.name, "%4s.%u", name1, &name2)
8843 + pr_debug("name1=%s,name2=%u\n", name1, name2);
8844 + pr_debug("misc-device: %s\n", restool_misc->misc.name);
8845 + if (strcmp(name1, "dprc") != 0)
8848 + if (WARN_ON(!restool_misc->static_mc_io))
8851 + if (WARN_ON(restool_misc->dynamic_instance_count != 0))
8854 + if (WARN_ON(restool_misc->static_instance_in_use))
8857 + misc_deregister(&restool_misc->misc);
8858 + pr_info("/dev/%s driver unregistered\n",
8859 + restool_misc->misc.name);
8860 + fsl_mc_portal_free(restool_misc->static_mc_io);
8861 + list_del(&restool_misc->list);
8862 + kfree(restool_misc);
8866 +module_exit(fsl_mc_restool_driver_exit);
8868 +MODULE_AUTHOR("Freescale Semiconductor Inc.");
8869 +MODULE_DESCRIPTION("Freescale's MC restool driver");
8870 +MODULE_LICENSE("GPL");
8871 --- a/drivers/staging/fsl-mc/bus/mc-sys.c
8872 +++ b/drivers/staging/fsl-mc/bus/mc-sys.c
8874 -/* Copyright 2013-2014 Freescale Semiconductor Inc.
8876 + * Copyright 2013-2016 Freescale Semiconductor Inc.
8878 * I/O services to send MC commands to the MC hardware
8881 * names of any contributors may be used to endorse or promote products
8882 * derived from this software without specific prior written permission.
8885 * ALTERNATIVELY, this software may be distributed under the terms of the
8886 * GNU General Public License ("GPL") as published by the Free Software
8887 * Foundation, either version 2 of that License or (at your option) any
8890 * Timeout in milliseconds to wait for the completion of an MC command
8892 -#define MC_CMD_COMPLETION_TIMEOUT_MS 500
8893 +#define MC_CMD_COMPLETION_TIMEOUT_MS 15000
8896 * usleep_range() min and max values used to throttle down polling
8897 @@ -67,7 +67,7 @@ static u16 mc_cmd_hdr_read_cmdid(struct
8898 struct mc_cmd_header *hdr = (struct mc_cmd_header *)&cmd->header;
8899 u16 cmd_id = le16_to_cpu(hdr->cmd_id);
8901 - return (cmd_id & MC_CMD_HDR_CMDID_MASK) >> MC_CMD_HDR_CMDID_SHIFT;
8905 static int mc_status_to_error(enum mc_cmd_status status)
8906 @@ -200,7 +200,7 @@ static int mc_polling_wait_preemptible(s
8908 if (time_after_eq(jiffies, jiffies_until_timeout)) {
8910 - "MC command timed out (portal: %#llx, obj handle: %#x, command: %#x)\n",
8911 + "MC command timed out (portal: %#llx, dprc handle: %#x, command: %#x)\n",
8912 mc_io->portal_phys_addr,
8913 (unsigned int)mc_cmd_hdr_read_token(cmd),
8914 (unsigned int)mc_cmd_hdr_read_cmdid(cmd));
8915 @@ -240,7 +240,7 @@ static int mc_polling_wait_atomic(struct
8916 timeout_usecs -= MC_CMD_COMPLETION_POLLING_MAX_SLEEP_USECS;
8917 if (timeout_usecs == 0) {
8919 - "MC command timed out (portal: %#llx, obj handle: %#x, command: %#x)\n",
8920 + "MC command timed out (portal: %#llx, dprc handle: %#x, command: %#x)\n",
8921 mc_io->portal_phys_addr,
8922 (unsigned int)mc_cmd_hdr_read_token(cmd),
8923 (unsigned int)mc_cmd_hdr_read_cmdid(cmd));
8924 @@ -294,7 +294,7 @@ int mc_send_command(struct fsl_mc_io *mc
8926 if (status != MC_CMD_STATUS_OK) {
8928 - "MC command failed: portal: %#llx, obj handle: %#x, command: %#x, status: %s (%#x)\n",
8929 + "MC command failed: portal: %#llx, dprc handle: %#x, command: %#x, status: %s (%#x)\n",
8930 mc_io->portal_phys_addr,
8931 (unsigned int)mc_cmd_hdr_read_token(cmd),
8932 (unsigned int)mc_cmd_hdr_read_cmdid(cmd),
8934 +++ b/drivers/staging/fsl-mc/include/dpaa2-fd.h
8937 + * Copyright 2014-2016 Freescale Semiconductor Inc.
8938 + * Copyright 2016 NXP
8940 + * Redistribution and use in source and binary forms, with or without
8941 + * modification, are permitted provided that the following conditions are met:
8942 + * * Redistributions of source code must retain the above copyright
8943 + * notice, this list of conditions and the following disclaimer.
8944 + * * Redistributions in binary form must reproduce the above copyright
8945 + * notice, this list of conditions and the following disclaimer in the
8946 + * documentation and/or other materials provided with the distribution.
8947 + * * Neither the name of Freescale Semiconductor nor the
8948 + * names of its contributors may be used to endorse or promote products
8949 + * derived from this software without specific prior written permission.
8951 + * ALTERNATIVELY, this software may be distributed under the terms of the
8952 + * GNU General Public License ("GPL") as published by the Free Software
8953 + * Foundation, either version 2 of that License or (at your option) any
8956 + * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
8957 + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
8958 + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
8959 + * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
8960 + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
8961 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
8962 + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
8963 + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
8964 + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
8965 + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
8967 +#ifndef __FSL_DPAA2_FD_H
8968 +#define __FSL_DPAA2_FD_H
8970 +#include <linux/kernel.h>
8973 + * DOC: DPAA2 FD - Frame Descriptor APIs for DPAA2
8975 + * Frame Descriptors (FDs) are used to describe frame data in the DPAA2.
8976 + * Frames can be enqueued and dequeued to Frame Queues (FQs) which are consumed
8977 + * by the various DPAA accelerators (WRIOP, SEC, PME, DCE)
8979 + * There are three types of frames: single, scatter gather, and frame lists.
8981 + * The set of APIs in this file must be used to create, manipulate and
8982 + * query Frame Descriptors.
8986 + * struct dpaa2_fd - Struct describing FDs
8987 + * @words: for easier/faster copying the whole FD structure
8988 + * @addr: address in the FD
8989 + * @len: length in the FD
8990 + * @bpid: buffer pool ID
8991 + * @format_offset: format, offset, and short-length fields
8992 + * @frc: frame context
8993 + * @ctrl: control bits...including dd, sc, va, err, etc
8994 + * @flc: flow context address
8996 + * This structure represents the basic Frame Descriptor used in the system.
9001 + struct dpaa2_fd_simple {
9005 + __le16 format_offset;
9013 +#define FD_SHORT_LEN_FLAG_MASK 0x1
9014 +#define FD_SHORT_LEN_FLAG_SHIFT 14
9015 +#define FD_SHORT_LEN_MASK 0x3FFFF
9016 +#define FD_OFFSET_MASK 0x0FFF
9017 +#define FD_FORMAT_MASK 0x3
9018 +#define FD_FORMAT_SHIFT 12
9019 +#define FD_BPID_MASK 0x3FFF
9020 +#define SG_SHORT_LEN_FLAG_MASK 0x1
9021 +#define SG_SHORT_LEN_FLAG_SHIFT 14
9022 +#define SG_SHORT_LEN_MASK 0x1FFFF
9023 +#define SG_OFFSET_MASK 0x0FFF
9024 +#define SG_FORMAT_MASK 0x3
9025 +#define SG_FORMAT_SHIFT 12
9026 +#define SG_BPID_MASK 0x3FFF
9027 +#define SG_FINAL_FLAG_MASK 0x1
9028 +#define SG_FINAL_FLAG_SHIFT 15
9029 +#define FL_SHORT_LEN_FLAG_MASK 0x1
9030 +#define FL_SHORT_LEN_FLAG_SHIFT 14
9031 +#define FL_SHORT_LEN_MASK 0x3FFFF
9032 +#define FL_OFFSET_MASK 0x0FFF
9033 +#define FL_FORMAT_MASK 0x3
9034 +#define FL_FORMAT_SHIFT 12
9035 +#define FL_BPID_MASK 0x3FFF
9036 +#define FL_FINAL_FLAG_MASK 0x1
9037 +#define FL_FINAL_FLAG_SHIFT 15
9039 +/* Error bits in FD CTRL */
9040 +#define FD_CTRL_ERR_MASK 0x000000FF
9041 +#define FD_CTRL_UFD 0x00000004
9042 +#define FD_CTRL_SBE 0x00000008
9043 +#define FD_CTRL_FLC 0x00000010
9044 +#define FD_CTRL_FSE 0x00000020
9045 +#define FD_CTRL_FAERR 0x00000040
9047 +/* Annotation bits in FD CTRL */
9048 +#define FD_CTRL_PTA 0x00800000
9049 +#define FD_CTRL_PTV1 0x00400000
9051 +enum dpaa2_fd_format {
9052 + dpaa2_fd_single = 0,
9058 + * dpaa2_fd_get_addr() - get the addr field of frame descriptor
9059 + * @fd: the given frame descriptor
9061 + * Return the address in the frame descriptor.
9063 +static inline dma_addr_t dpaa2_fd_get_addr(const struct dpaa2_fd *fd)
9065 + return (dma_addr_t)le64_to_cpu(fd->simple.addr);
9069 + * dpaa2_fd_set_addr() - Set the addr field of frame descriptor
9070 + * @fd: the given frame descriptor
9071 + * @addr: the address needs to be set in frame descriptor
9073 +static inline void dpaa2_fd_set_addr(struct dpaa2_fd *fd, dma_addr_t addr)
9075 + fd->simple.addr = cpu_to_le64(addr);
9079 + * dpaa2_fd_get_frc() - Get the frame context in the frame descriptor
9080 + * @fd: the given frame descriptor
9082 + * Return the frame context field in the frame descriptor.
9084 +static inline u32 dpaa2_fd_get_frc(const struct dpaa2_fd *fd)
9086 + return le32_to_cpu(fd->simple.frc);
9090 + * dpaa2_fd_set_frc() - Set the frame context in the frame descriptor
9091 + * @fd: the given frame descriptor
9092 + * @frc: the frame context needs to be set in frame descriptor
9094 +static inline void dpaa2_fd_set_frc(struct dpaa2_fd *fd, u32 frc)
9096 + fd->simple.frc = cpu_to_le32(frc);
9100 + * dpaa2_fd_get_ctrl() - Get the control bits in the frame descriptor
9101 + * @fd: the given frame descriptor
9103 + * Return the control bits field in the frame descriptor.
9105 +static inline u32 dpaa2_fd_get_ctrl(const struct dpaa2_fd *fd)
9107 + return le32_to_cpu(fd->simple.ctrl);
9111 + * dpaa2_fd_set_ctrl() - Set the control bits in the frame descriptor
9112 + * @fd: the given frame descriptor
9113 + * @ctrl: the control bits to be set in the frame descriptor
9115 +static inline void dpaa2_fd_set_ctrl(struct dpaa2_fd *fd, u32 ctrl)
9117 + fd->simple.ctrl = cpu_to_le32(ctrl);
9121 + * dpaa2_fd_get_flc() - Get the flow context in the frame descriptor
9122 + * @fd: the given frame descriptor
9124 + * Return the flow context in the frame descriptor.
9126 +static inline dma_addr_t dpaa2_fd_get_flc(const struct dpaa2_fd *fd)
9128 + return (dma_addr_t)le64_to_cpu(fd->simple.flc);
9132 + * dpaa2_fd_set_flc() - Set the flow context field of frame descriptor
9133 + * @fd: the given frame descriptor
9134 + * @flc_addr: the flow context needs to be set in frame descriptor
9136 +static inline void dpaa2_fd_set_flc(struct dpaa2_fd *fd, dma_addr_t flc_addr)
9138 + fd->simple.flc = cpu_to_le64(flc_addr);
9141 +static inline bool dpaa2_fd_short_len(const struct dpaa2_fd *fd)
9143 + return !!((le16_to_cpu(fd->simple.format_offset) >>
9144 + FD_SHORT_LEN_FLAG_SHIFT) & FD_SHORT_LEN_FLAG_MASK);
9148 + * dpaa2_fd_get_len() - Get the length in the frame descriptor
9149 + * @fd: the given frame descriptor
9151 + * Return the length field in the frame descriptor.
9153 +static inline u32 dpaa2_fd_get_len(const struct dpaa2_fd *fd)
9155 + if (dpaa2_fd_short_len(fd))
9156 + return le32_to_cpu(fd->simple.len) & FD_SHORT_LEN_MASK;
9158 + return le32_to_cpu(fd->simple.len);
9162 + * dpaa2_fd_set_len() - Set the length field of frame descriptor
9163 + * @fd: the given frame descriptor
9164 + * @len: the length needs to be set in frame descriptor
9166 +static inline void dpaa2_fd_set_len(struct dpaa2_fd *fd, u32 len)
9168 + fd->simple.len = cpu_to_le32(len);
9172 + * dpaa2_fd_get_offset() - Get the offset field in the frame descriptor
9173 + * @fd: the given frame descriptor
9175 + * Return the offset.
9177 +static inline uint16_t dpaa2_fd_get_offset(const struct dpaa2_fd *fd)
9179 + return le16_to_cpu(fd->simple.format_offset) & FD_OFFSET_MASK;
9183 + * dpaa2_fd_set_offset() - Set the offset field of frame descriptor
9184 + * @fd: the given frame descriptor
9185 + * @offset: the offset needs to be set in frame descriptor
9187 +static inline void dpaa2_fd_set_offset(struct dpaa2_fd *fd, uint16_t offset)
9189 + fd->simple.format_offset &= cpu_to_le16(~FD_OFFSET_MASK);
9190 + fd->simple.format_offset |= cpu_to_le16(offset);
9194 + * dpaa2_fd_get_format() - Get the format field in the frame descriptor
9195 + * @fd: the given frame descriptor
9197 + * Return the format.
9199 +static inline enum dpaa2_fd_format dpaa2_fd_get_format(
9200 + const struct dpaa2_fd *fd)
9202 + return (enum dpaa2_fd_format)((le16_to_cpu(fd->simple.format_offset)
9203 + >> FD_FORMAT_SHIFT) & FD_FORMAT_MASK);
9207 + * dpaa2_fd_set_format() - Set the format field of frame descriptor
9208 + * @fd: the given frame descriptor
9209 + * @format: the format needs to be set in frame descriptor
9211 +static inline void dpaa2_fd_set_format(struct dpaa2_fd *fd,
9212 + enum dpaa2_fd_format format)
9214 + fd->simple.format_offset &=
9215 + cpu_to_le16(~(FD_FORMAT_MASK << FD_FORMAT_SHIFT));
9216 + fd->simple.format_offset |= cpu_to_le16(format << FD_FORMAT_SHIFT);
9220 + * dpaa2_fd_get_bpid() - Get the bpid field in the frame descriptor
9221 + * @fd: the given frame descriptor
9223 + * Return the buffer pool id.
9225 +static inline uint16_t dpaa2_fd_get_bpid(const struct dpaa2_fd *fd)
9227 + return le16_to_cpu(fd->simple.bpid) & FD_BPID_MASK;
9231 + * dpaa2_fd_set_bpid() - Set the bpid field of frame descriptor
9232 + * @fd: the given frame descriptor
9233 + * @bpid: buffer pool id to be set
9235 +static inline void dpaa2_fd_set_bpid(struct dpaa2_fd *fd, uint16_t bpid)
9237 + fd->simple.bpid &= cpu_to_le16(~(FD_BPID_MASK));
9238 + fd->simple.bpid |= cpu_to_le16(bpid);
9242 + * struct dpaa2_sg_entry - the scatter-gathering structure
9243 + * @addr: address of the sg entry
9244 + * @len: length in this sg entry
9245 + * @bpid: buffer pool id
9246 + * @format_offset: format and offset fields
9248 +struct dpaa2_sg_entry {
9252 + __le16 format_offset;
9255 +enum dpaa2_sg_format {
9256 + dpaa2_sg_single = 0,
9257 + dpaa2_sg_frame_data,
9261 +/* Accessors for SG entry fields */
9264 + * dpaa2_sg_get_addr() - Get the address from SG entry
9265 + * @sg: the given scatter-gathering object
9267 + * Return the address.
9269 +static inline dma_addr_t dpaa2_sg_get_addr(const struct dpaa2_sg_entry *sg)
9271 + return le64_to_cpu((dma_addr_t)sg->addr);
9275 + * dpaa2_sg_set_addr() - Set the address in SG entry
9276 + * @sg: the given scatter-gathering object
9277 + * @addr: the address to be set
9279 +static inline void dpaa2_sg_set_addr(struct dpaa2_sg_entry *sg, dma_addr_t addr)
9281 + sg->addr = cpu_to_le64(addr);
9284 +static inline bool dpaa2_sg_short_len(const struct dpaa2_sg_entry *sg)
9286 + return !!((le16_to_cpu(sg->format_offset) >> SG_SHORT_LEN_FLAG_SHIFT)
9287 + & SG_SHORT_LEN_FLAG_MASK);
9291 + * dpaa2_sg_get_len() - Get the length in SG entry
9292 + * @sg: the given scatter-gathering object
9294 + * Return the length.
9296 +static inline u32 dpaa2_sg_get_len(const struct dpaa2_sg_entry *sg)
9298 + if (dpaa2_sg_short_len(sg))
9299 + return le32_to_cpu(sg->len) & SG_SHORT_LEN_MASK;
9301 + return le32_to_cpu(sg->len);
9305 + * dpaa2_sg_set_len() - Set the length in SG entry
9306 + * @sg: the given scatter-gathering object
9307 + * @len: the length to be set
9309 +static inline void dpaa2_sg_set_len(struct dpaa2_sg_entry *sg, u32 len)
9311 + sg->len = cpu_to_le32(len);
9315 + * dpaa2_sg_get_offset() - Get the offset in SG entry
9316 + * @sg: the given scatter-gathering object
9318 + * Return the offset.
9320 +static inline u16 dpaa2_sg_get_offset(const struct dpaa2_sg_entry *sg)
9322 + return le16_to_cpu(sg->format_offset) & SG_OFFSET_MASK;
9326 + * dpaa2_sg_set_offset() - Set the offset in SG entry
9327 + * @sg: the given scatter-gathering object
9328 + * @offset: the offset to be set
9330 +static inline void dpaa2_sg_set_offset(struct dpaa2_sg_entry *sg,
9333 + sg->format_offset &= cpu_to_le16(~SG_OFFSET_MASK);
9334 + sg->format_offset |= cpu_to_le16(offset);
9338 + * dpaa2_sg_get_format() - Get the SG format in SG entry
9339 + * @sg: the given scatter-gathering object
9341 + * Return the format.
9343 +static inline enum dpaa2_sg_format
9344 + dpaa2_sg_get_format(const struct dpaa2_sg_entry *sg)
9346 + return (enum dpaa2_sg_format)((le16_to_cpu(sg->format_offset)
9347 + >> SG_FORMAT_SHIFT) & SG_FORMAT_MASK);
9351 + * dpaa2_sg_set_format() - Set the SG format in SG entry
9352 + * @sg: the given scatter-gathering object
9353 + * @format: the format to be set
9355 +static inline void dpaa2_sg_set_format(struct dpaa2_sg_entry *sg,
9356 + enum dpaa2_sg_format format)
9358 + sg->format_offset &= cpu_to_le16(~(SG_FORMAT_MASK << SG_FORMAT_SHIFT));
9359 + sg->format_offset |= cpu_to_le16(format << SG_FORMAT_SHIFT);
9363 + * dpaa2_sg_get_bpid() - Get the buffer pool id in SG entry
9364 + * @sg: the given scatter-gathering object
9366 + * Return the bpid.
9368 +static inline u16 dpaa2_sg_get_bpid(const struct dpaa2_sg_entry *sg)
9370 + return le16_to_cpu(sg->bpid) & SG_BPID_MASK;
9374 + * dpaa2_sg_set_bpid() - Set the buffer pool id in SG entry
9375 + * @sg: the given scatter-gathering object
9376 + * @bpid: the bpid to be set
9378 +static inline void dpaa2_sg_set_bpid(struct dpaa2_sg_entry *sg, u16 bpid)
9380 + sg->bpid &= cpu_to_le16(~(SG_BPID_MASK));
9381 + sg->bpid |= cpu_to_le16(bpid);
9385 + * dpaa2_sg_is_final() - Check final bit in SG entry
9386 + * @sg: the given scatter-gathering object
9390 +static inline bool dpaa2_sg_is_final(const struct dpaa2_sg_entry *sg)
9392 + return !!(le16_to_cpu(sg->format_offset) >> SG_FINAL_FLAG_SHIFT);
9396 + * dpaa2_sg_set_final() - Set the final bit in SG entry
9397 + * @sg: the given scatter-gathering object
9398 + * @final: the final boolean to be set
9400 +static inline void dpaa2_sg_set_final(struct dpaa2_sg_entry *sg, bool final)
9402 + sg->format_offset &= cpu_to_le16(~(SG_FINAL_FLAG_MASK
9403 + << SG_FINAL_FLAG_SHIFT));
9404 + sg->format_offset |= cpu_to_le16(final << SG_FINAL_FLAG_SHIFT);
9408 + * struct dpaa2_fl_entry - structure for frame list entry.
9409 + * @addr: address in the FLE
9410 + * @len: length in the FLE
9411 + * @bpid: buffer pool ID
9412 + * @format_offset: format, offset, and short-length fields
9413 + * @frc: frame context
9414 + * @ctrl: control bits...including pta, pvt1, pvt2, err, etc
9415 + * @flc: flow context address
9417 +struct dpaa2_fl_entry {
9421 + __le16 format_offset;
9427 +enum dpaa2_fl_format {
9428 + dpaa2_fl_single = 0,
9434 + * dpaa2_fl_get_addr() - get the addr field of FLE
9435 + * @fle: the given frame list entry
9437 + * Return the address in the frame list entry.
9439 +static inline dma_addr_t dpaa2_fl_get_addr(const struct dpaa2_fl_entry *fle)
9441 + return (dma_addr_t)le64_to_cpu(fle->addr);
9445 + * dpaa2_fl_set_addr() - Set the addr field of FLE
9446 + * @fle: the given frame list entry
9447 + * @addr: the address needs to be set in frame list entry
9449 +static inline void dpaa2_fl_set_addr(struct dpaa2_fl_entry *fle,
9452 + fle->addr = cpu_to_le64(addr);
9456 + * dpaa2_fl_get_frc() - Get the frame context in the FLE
9457 + * @fle: the given frame list entry
9459 + * Return the frame context field in the frame lsit entry.
9461 +static inline u32 dpaa2_fl_get_frc(const struct dpaa2_fl_entry *fle)
9463 + return le32_to_cpu(fle->frc);
9467 + * dpaa2_fl_set_frc() - Set the frame context in the FLE
9468 + * @fle: the given frame list entry
9469 + * @frc: the frame context needs to be set in frame list entry
9471 +static inline void dpaa2_fl_set_frc(struct dpaa2_fl_entry *fle, u32 frc)
9473 + fle->frc = cpu_to_le32(frc);
9477 + * dpaa2_fl_get_ctrl() - Get the control bits in the FLE
9478 + * @fle: the given frame list entry
9480 + * Return the control bits field in the frame list entry.
9482 +static inline u32 dpaa2_fl_get_ctrl(const struct dpaa2_fl_entry *fle)
9484 + return le32_to_cpu(fle->ctrl);
9488 + * dpaa2_fl_set_ctrl() - Set the control bits in the FLE
9489 + * @fle: the given frame list entry
9490 + * @ctrl: the control bits to be set in the frame list entry
9492 +static inline void dpaa2_fl_set_ctrl(struct dpaa2_fl_entry *fle, u32 ctrl)
9494 + fle->ctrl = cpu_to_le32(ctrl);
9498 + * dpaa2_fl_get_flc() - Get the flow context in the FLE
9499 + * @fle: the given frame list entry
9501 + * Return the flow context in the frame list entry.
9503 +static inline dma_addr_t dpaa2_fl_get_flc(const struct dpaa2_fl_entry *fle)
9505 + return (dma_addr_t)le64_to_cpu(fle->flc);
9509 + * dpaa2_fl_set_flc() - Set the flow context field of FLE
9510 + * @fle: the given frame list entry
9511 + * @flc_addr: the flow context needs to be set in frame list entry
9513 +static inline void dpaa2_fl_set_flc(struct dpaa2_fl_entry *fle,
9514 + dma_addr_t flc_addr)
9516 + fle->flc = cpu_to_le64(flc_addr);
9519 +static inline bool dpaa2_fl_short_len(const struct dpaa2_fl_entry *fle)
9521 + return !!((le16_to_cpu(fle->format_offset) >>
9522 + FL_SHORT_LEN_FLAG_SHIFT) & FL_SHORT_LEN_FLAG_MASK);
9526 + * dpaa2_fl_get_len() - Get the length in the FLE
9527 + * @fle: the given frame list entry
9529 + * Return the length field in the frame list entry.
9531 +static inline u32 dpaa2_fl_get_len(const struct dpaa2_fl_entry *fle)
9533 + if (dpaa2_fl_short_len(fle))
9534 + return le32_to_cpu(fle->len) & FL_SHORT_LEN_MASK;
9536 + return le32_to_cpu(fle->len);
9540 + * dpaa2_fl_set_len() - Set the length field of FLE
9541 + * @fle: the given frame list entry
9542 + * @len: the length needs to be set in frame list entry
9544 +static inline void dpaa2_fl_set_len(struct dpaa2_fl_entry *fle, u32 len)
9546 + fle->len = cpu_to_le32(len);
9550 + * dpaa2_fl_get_offset() - Get the offset field in the frame list entry
9551 + * @fle: the given frame list entry
9553 + * Return the offset.
9555 +static inline u16 dpaa2_fl_get_offset(const struct dpaa2_fl_entry *fle)
9557 + return le16_to_cpu(fle->format_offset) & FL_OFFSET_MASK;
9561 + * dpaa2_fl_set_offset() - Set the offset field of FLE
9562 + * @fle: the given frame list entry
9563 + * @offset: the offset needs to be set in frame list entry
9565 +static inline void dpaa2_fl_set_offset(struct dpaa2_fl_entry *fle, u16 offset)
9567 + fle->format_offset &= cpu_to_le16(~FL_OFFSET_MASK);
9568 + fle->format_offset |= cpu_to_le16(offset);
9572 + * dpaa2_fl_get_format() - Get the format field in the FLE
9573 + * @fle: the given frame list entry
9575 + * Return the format.
9577 +static inline enum dpaa2_fl_format dpaa2_fl_get_format(
9578 + const struct dpaa2_fl_entry *fle)
9580 + return (enum dpaa2_fl_format)((le16_to_cpu(fle->format_offset) >>
9581 + FL_FORMAT_SHIFT) & FL_FORMAT_MASK);
9585 + * dpaa2_fl_set_format() - Set the format field of FLE
9586 + * @fle: the given frame list entry
9587 + * @format: the format needs to be set in frame list entry
9589 +static inline void dpaa2_fl_set_format(struct dpaa2_fl_entry *fle,
9590 + enum dpaa2_fl_format format)
9592 + fle->format_offset &= cpu_to_le16(~(FL_FORMAT_MASK << FL_FORMAT_SHIFT));
9593 + fle->format_offset |= cpu_to_le16(format << FL_FORMAT_SHIFT);
9597 + * dpaa2_fl_get_bpid() - Get the bpid field in the FLE
9598 + * @fle: the given frame list entry
9600 + * Return the buffer pool id.
9602 +static inline u16 dpaa2_fl_get_bpid(const struct dpaa2_fl_entry *fle)
9604 + return le16_to_cpu(fle->bpid) & FL_BPID_MASK;
9608 + * dpaa2_fl_set_bpid() - Set the bpid field of FLE
9609 + * @fle: the given frame list entry
9610 + * @bpid: buffer pool id to be set
9612 +static inline void dpaa2_fl_set_bpid(struct dpaa2_fl_entry *fle, u16 bpid)
9614 + fle->bpid &= cpu_to_le16(~(FL_BPID_MASK));
9615 + fle->bpid |= cpu_to_le16(bpid);
9619 + * dpaa2_fl_is_final() - Check final bit in FLE
9620 + * @fle: the given frame list entry
9624 +static inline bool dpaa2_fl_is_final(const struct dpaa2_fl_entry *fle)
9626 + return !!(le16_to_cpu(fle->format_offset) >> FL_FINAL_FLAG_SHIFT);
9630 + * dpaa2_fl_set_final() - Set the final bit in FLE
9631 + * @fle: the given frame list entry
9632 + * @final: the final boolean to be set
9634 +static inline void dpaa2_fl_set_final(struct dpaa2_fl_entry *fle, bool final)
9636 + fle->format_offset &= cpu_to_le16(~(FL_FINAL_FLAG_MASK <<
9637 + FL_FINAL_FLAG_SHIFT));
9638 + fle->format_offset |= cpu_to_le16(final << FL_FINAL_FLAG_SHIFT);
9641 +#endif /* __FSL_DPAA2_FD_H */
9643 +++ b/drivers/staging/fsl-mc/include/dpaa2-global.h
9646 + * Copyright 2014-2016 Freescale Semiconductor Inc.
9647 + * Copyright 2016 NXP
9649 + * Redistribution and use in source and binary forms, with or without
9650 + * modification, are permitted provided that the following conditions are met:
9651 + * * Redistributions of source code must retain the above copyright
9652 + * notice, this list of conditions and the following disclaimer.
9653 + * * Redistributions in binary form must reproduce the above copyright
9654 + * notice, this list of conditions and the following disclaimer in the
9655 + * documentation and/or other materials provided with the distribution.
9656 + * * Neither the name of Freescale Semiconductor nor the
9657 + * names of its contributors may be used to endorse or promote products
9658 + * derived from this software without specific prior written permission.
9660 + * ALTERNATIVELY, this software may be distributed under the terms of the
9661 + * GNU General Public License ("GPL") as published by the Free Software
9662 + * Foundation, either version 2 of that License or (at your option) any
9665 + * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
9666 + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
9667 + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
9668 + * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
9669 + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
9670 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
9671 + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
9672 + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
9673 + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
9674 + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
9676 +#ifndef __FSL_DPAA2_GLOBAL_H
9677 +#define __FSL_DPAA2_GLOBAL_H
9679 +#include <linux/types.h>
9680 +#include <linux/cpumask.h>
9681 +#include "dpaa2-fd.h"
9698 + __le32 fq_byte_cnt;
9699 + __le32 fq_frm_cnt;
9714 +/* Parsing frame dequeue results */
9716 +#define DPAA2_DQ_STAT_FQEMPTY 0x80
9717 +/* FQ held active */
9718 +#define DPAA2_DQ_STAT_HELDACTIVE 0x40
9719 +/* FQ force eligible */
9720 +#define DPAA2_DQ_STAT_FORCEELIGIBLE 0x20
9722 +#define DPAA2_DQ_STAT_VALIDFRAME 0x10
9723 +/* FQ ODP enable */
9724 +#define DPAA2_DQ_STAT_ODPVALID 0x04
9725 +/* volatile dequeue */
9726 +#define DPAA2_DQ_STAT_VOLATILE 0x02
9727 +/* volatile dequeue command is expired */
9728 +#define DPAA2_DQ_STAT_EXPIRED 0x01
9730 +#define DQ_FQID_MASK 0x00FFFFFF
9731 +#define DQ_FRAME_COUNT_MASK 0x00FFFFFF
9734 + * dpaa2_dq_flags() - Get the stat field of dequeue response
9735 + * @dq: the dequeue result.
9737 +static inline u32 dpaa2_dq_flags(const struct dpaa2_dq *dq)
9739 + return dq->dq.stat;
9743 + * dpaa2_dq_is_pull() - Check whether the dq response is from a pull
9745 + * @dq: the dequeue result
9747 + * Return 1 for volatile(pull) dequeue, 0 for static dequeue.
9749 +static inline int dpaa2_dq_is_pull(const struct dpaa2_dq *dq)
9751 + return (int)(dpaa2_dq_flags(dq) & DPAA2_DQ_STAT_VOLATILE);
9755 + * dpaa2_dq_is_pull_complete() - Check whether the pull command is completed.
9756 + * @dq: the dequeue result
9760 +static inline bool dpaa2_dq_is_pull_complete(const struct dpaa2_dq *dq)
9762 + return !!(dpaa2_dq_flags(dq) & DPAA2_DQ_STAT_EXPIRED);
9766 + * dpaa2_dq_seqnum() - Get the seqnum field in dequeue response
9767 + * @dq: the dequeue result
9769 + * seqnum is valid only if VALIDFRAME flag is TRUE
9773 +static inline u16 dpaa2_dq_seqnum(const struct dpaa2_dq *dq)
9775 + return le16_to_cpu(dq->dq.seqnum);
9779 + * dpaa2_dq_odpid() - Get the odpid field in dequeue response
9780 + * @dq: the dequeue result
9782 + * odpid is valid only if ODPVALID flag is TRUE.
9786 +static inline u16 dpaa2_dq_odpid(const struct dpaa2_dq *dq)
9788 + return le16_to_cpu(dq->dq.oprid);
9792 + * dpaa2_dq_fqid() - Get the fqid in dequeue response
9793 + * @dq: the dequeue result
9797 +static inline u32 dpaa2_dq_fqid(const struct dpaa2_dq *dq)
9799 + return le32_to_cpu(dq->dq.fqid) & DQ_FQID_MASK;
9803 + * dpaa2_dq_byte_count() - Get the byte count in dequeue response
9804 + * @dq: the dequeue result
9806 + * Return the byte count remaining in the FQ.
9808 +static inline u32 dpaa2_dq_byte_count(const struct dpaa2_dq *dq)
9810 + return le32_to_cpu(dq->dq.fq_byte_cnt);
9814 + * dpaa2_dq_frame_count() - Get the frame count in dequeue response
9815 + * @dq: the dequeue result
9817 + * Return the frame count remaining in the FQ.
9819 +static inline u32 dpaa2_dq_frame_count(const struct dpaa2_dq *dq)
9821 + return le32_to_cpu(dq->dq.fq_frm_cnt) & DQ_FRAME_COUNT_MASK;
9825 + * dpaa2_dq_fd_ctx() - Get the frame queue context in dequeue response
9826 + * @dq: the dequeue result
9828 + * Return the frame queue context.
9830 +static inline u64 dpaa2_dq_fqd_ctx(const struct dpaa2_dq *dq)
9832 + return le64_to_cpu(dq->dq.fqd_ctx);
9836 + * dpaa2_dq_fd() - Get the frame descriptor in dequeue response
9837 + * @dq: the dequeue result
9839 + * Return the frame descriptor.
9841 +static inline const struct dpaa2_fd *dpaa2_dq_fd(const struct dpaa2_dq *dq)
9843 + return (const struct dpaa2_fd *)&dq->dq.fd[0];
9846 +#endif /* __FSL_DPAA2_GLOBAL_H */
9848 +++ b/drivers/staging/fsl-mc/include/dpaa2-io.h
9851 + * Copyright 2014-2016 Freescale Semiconductor Inc.
9852 + * Copyright 2017 NXP
9854 + * Redistribution and use in source and binary forms, with or without
9855 + * modification, are permitted provided that the following conditions are met:
9856 + * * Redistributions of source code must retain the above copyright
9857 + * notice, this list of conditions and the following disclaimer.
9858 + * * Redistributions in binary form must reproduce the above copyright
9859 + * notice, this list of conditions and the following disclaimer in the
9860 + * documentation and/or other materials provided with the distribution.
9861 + * * Neither the name of Freescale Semiconductor nor the
9862 + * names of its contributors may be used to endorse or promote products
9863 + * derived from this software without specific prior written permission.
9865 + * ALTERNATIVELY, this software may be distributed under the terms of the
9866 + * GNU General Public License ("GPL") as published by the Free Software
9867 + * Foundation, either version 2 of that License or (at your option) any
9870 + * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
9871 + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
9872 + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
9873 + * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
9874 + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
9875 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
9876 + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
9877 + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
9878 + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
9879 + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
9881 +#ifndef __FSL_DPAA2_IO_H
9882 +#define __FSL_DPAA2_IO_H
9884 +#include <linux/types.h>
9885 +#include <linux/cpumask.h>
9887 +#include "dpaa2-fd.h"
9888 +#include "dpaa2-global.h"
9891 +struct dpaa2_io_store;
9895 + * DOC: DPIO Service
9897 + * The DPIO service provides APIs for users to interact with the datapath
9898 + * by enqueueing and dequeing frame descriptors.
9900 + * The following set of APIs can be used to enqueue and dequeue frames
9901 + * as well as producing notification callbacks when data is available
9906 + * struct dpaa2_io_desc - The DPIO descriptor
9907 + * @receives_notifications: Use notificaton mode. Non-zero if the DPIO
9909 + * @has_8prio: Set to non-zero for channel with 8 priority WQs. Ignored
9910 + * unless receives_notification is TRUE.
9911 + * @cpu: The cpu index that at least interrupt handlers will
9913 + * @stash_affinity: The stash affinity for this portal favour 'cpu'
9914 + * @regs_cena: The cache enabled regs.
9915 + * @regs_cinh: The cache inhibited regs
9916 + * @dpio_id: The dpio index
9917 + * @qman_version: The qman version
9919 + * Describes the attributes and features of the DPIO object.
9921 +struct dpaa2_io_desc {
9922 + int receives_notifications;
9931 +struct dpaa2_io *dpaa2_io_create(const struct dpaa2_io_desc *desc);
9933 +void dpaa2_io_down(struct dpaa2_io *d);
9935 +irqreturn_t dpaa2_io_irq(struct dpaa2_io *obj);
9938 + * struct dpaa2_io_notification_ctx - The DPIO notification context structure
9939 + * @cb: The callback to be invoked when the notification arrives
9940 + * @is_cdan: Zero for FQDAN, non-zero for CDAN
9941 + * @id: FQID or channel ID, needed for rearm
9942 + * @desired_cpu: The cpu on which the notifications will show up. -1 means
9944 + * @dpio_id: The dpio index
9945 + * @qman64: The 64-bit context value shows up in the FQDAN/CDAN.
9946 + * @node: The list node
9947 + * @dpio_private: The dpio object internal to dpio_service
9949 + * Used when a FQDAN/CDAN registration is made by drivers.
9951 +struct dpaa2_io_notification_ctx {
9952 + void (*cb)(struct dpaa2_io_notification_ctx *);
9958 + struct list_head node;
9959 + void *dpio_private;
9962 +int dpaa2_io_service_register(struct dpaa2_io *service,
9963 + struct dpaa2_io_notification_ctx *ctx);
9964 +void dpaa2_io_service_deregister(struct dpaa2_io *service,
9965 + struct dpaa2_io_notification_ctx *ctx);
9966 +int dpaa2_io_service_rearm(struct dpaa2_io *service,
9967 + struct dpaa2_io_notification_ctx *ctx);
9969 +int dpaa2_io_service_pull_fq(struct dpaa2_io *d, u32 fqid,
9970 + struct dpaa2_io_store *s);
9971 +int dpaa2_io_service_pull_channel(struct dpaa2_io *d, u32 channelid,
9972 + struct dpaa2_io_store *s);
9974 +int dpaa2_io_service_enqueue_fq(struct dpaa2_io *d, u32 fqid,
9975 + const struct dpaa2_fd *fd);
9976 +int dpaa2_io_service_enqueue_qd(struct dpaa2_io *d, u32 qdid, u8 prio,
9977 + u16 qdbin, const struct dpaa2_fd *fd);
9978 +int dpaa2_io_service_release(struct dpaa2_io *d, u32 bpid,
9979 + const u64 *buffers, unsigned int num_buffers);
9980 +int dpaa2_io_service_acquire(struct dpaa2_io *d, u32 bpid,
9981 + u64 *buffers, unsigned int num_buffers);
9983 +struct dpaa2_io_store *dpaa2_io_store_create(unsigned int max_frames,
9984 + struct device *dev);
9985 +void dpaa2_io_store_destroy(struct dpaa2_io_store *s);
9986 +struct dpaa2_dq *dpaa2_io_store_next(struct dpaa2_io_store *s, int *is_last);
9988 +#ifdef CONFIG_FSL_QBMAN_DEBUG
9989 +int dpaa2_io_query_fq_count(struct dpaa2_io *d, uint32_t fqid,
9990 + uint32_t *fcnt, uint32_t *bcnt);
9991 +int dpaa2_io_query_bp_count(struct dpaa2_io *d, uint32_t bpid,
10001 + * struct dpaa2_cscn - The CSCN message format
10002 + * @verb: identifies the type of message (should be 0x27).
10003 + * @stat: status bits related to dequeuing response (not used)
10004 + * @state: bit 0 = 0/1 if CG is no/is congested
10005 + * @reserved: reserved byte
10006 + * @cgid: congest grp ID - the first 16 bits
10007 + * @ctx: context data
10009 + * Congestion management can be implemented in software through
10010 + * the use of Congestion State Change Notifications (CSCN). These
10011 + * are messages written by DPAA2 hardware to memory whenever the
10012 + * instantaneous count (I_CNT field in the CG) exceeds the
10013 + * Congestion State (CS) entrance threshold, signifying congestion
10014 + * entrance, or when the instantaneous count returns below exit
10015 + * threshold, signifying congestion exit. The format of the message
10016 + * is given by the dpaa2_cscn structure. Bit 0 of the state field
10017 + * represents congestion state written by the hardware.
10019 +struct dpaa2_cscn {
10028 +#define DPAA2_CSCN_SIZE 64
10029 +#define DPAA2_CSCN_ALIGN 16
10031 +#define DPAA2_CSCN_STATE_MASK 0x1
10032 +#define DPAA2_CSCN_CONGESTED 1
10034 +static inline bool dpaa2_cscn_state_congested(struct dpaa2_cscn *cscn)
10036 + return ((cscn->state & DPAA2_CSCN_STATE_MASK) == DPAA2_CSCN_CONGESTED);
10039 +#endif /* __FSL_DPAA2_IO_H */
10040 --- a/drivers/staging/fsl-mc/include/dpbp-cmd.h
10043 -/* Copyright 2013-2016 Freescale Semiconductor Inc.
10045 - * Redistribution and use in source and binary forms, with or without
10046 - * modification, are permitted provided that the following conditions are met:
10047 - * * Redistributions of source code must retain the above copyright
10048 - * notice, this list of conditions and the following disclaimer.
10049 - * * Redistributions in binary form must reproduce the above copyright
10050 - * notice, this list of conditions and the following disclaimer in the
10051 - * documentation and/or other materials provided with the distribution.
10052 - * * Neither the name of the above-listed copyright holders nor the
10053 - * names of any contributors may be used to endorse or promote products
10054 - * derived from this software without specific prior written permission.
10057 - * ALTERNATIVELY, this software may be distributed under the terms of the
10058 - * GNU General Public License ("GPL") as published by the Free Software
10059 - * Foundation, either version 2 of that License or (at your option) any
10062 - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
10063 - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
10064 - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
10065 - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
10066 - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
10067 - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
10068 - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
10069 - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
10070 - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
10071 - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
10072 - * POSSIBILITY OF SUCH DAMAGE.
10074 -#ifndef _FSL_DPBP_CMD_H
10075 -#define _FSL_DPBP_CMD_H
10077 -/* DPBP Version */
10078 -#define DPBP_VER_MAJOR 2
10079 -#define DPBP_VER_MINOR 2
10082 -#define DPBP_CMDID_CLOSE 0x800
10083 -#define DPBP_CMDID_OPEN 0x804
10084 -#define DPBP_CMDID_CREATE 0x904
10085 -#define DPBP_CMDID_DESTROY 0x900
10087 -#define DPBP_CMDID_ENABLE 0x002
10088 -#define DPBP_CMDID_DISABLE 0x003
10089 -#define DPBP_CMDID_GET_ATTR 0x004
10090 -#define DPBP_CMDID_RESET 0x005
10091 -#define DPBP_CMDID_IS_ENABLED 0x006
10093 -#define DPBP_CMDID_SET_IRQ 0x010
10094 -#define DPBP_CMDID_GET_IRQ 0x011
10095 -#define DPBP_CMDID_SET_IRQ_ENABLE 0x012
10096 -#define DPBP_CMDID_GET_IRQ_ENABLE 0x013
10097 -#define DPBP_CMDID_SET_IRQ_MASK 0x014
10098 -#define DPBP_CMDID_GET_IRQ_MASK 0x015
10099 -#define DPBP_CMDID_GET_IRQ_STATUS 0x016
10100 -#define DPBP_CMDID_CLEAR_IRQ_STATUS 0x017
10102 -#define DPBP_CMDID_SET_NOTIFICATIONS 0x01b0
10103 -#define DPBP_CMDID_GET_NOTIFICATIONS 0x01b1
10105 -struct dpbp_cmd_open {
10109 -#define DPBP_ENABLE 0x1
10111 -struct dpbp_rsp_is_enabled {
10115 -struct dpbp_cmd_set_irq {
10126 -struct dpbp_cmd_get_irq {
10131 -struct dpbp_rsp_get_irq {
10132 - /* response word 0 */
10135 - /* response word 1 */
10137 - /* response word 2 */
10142 -struct dpbp_cmd_set_irq_enable {
10148 -struct dpbp_cmd_get_irq_enable {
10153 -struct dpbp_rsp_get_irq_enable {
10157 -struct dpbp_cmd_set_irq_mask {
10162 -struct dpbp_cmd_get_irq_mask {
10167 -struct dpbp_rsp_get_irq_mask {
10171 -struct dpbp_cmd_get_irq_status {
10176 -struct dpbp_rsp_get_irq_status {
10180 -struct dpbp_cmd_clear_irq_status {
10185 -struct dpbp_rsp_get_attributes {
10186 - /* response word 0 */
10190 - /* response word 1 */
10191 - __le16 version_major;
10192 - __le16 version_minor;
10195 -struct dpbp_cmd_set_notifications {
10197 - __le32 depletion_entry;
10198 - __le32 depletion_exit;
10200 - __le32 surplus_entry;
10201 - __le32 surplus_exit;
10206 - __le64 message_ctx;
10208 - __le64 message_iova;
10211 -struct dpbp_rsp_get_notifications {
10212 - /* response word 0 */
10213 - __le32 depletion_entry;
10214 - __le32 depletion_exit;
10215 - /* response word 1 */
10216 - __le32 surplus_entry;
10217 - __le32 surplus_exit;
10218 - /* response word 2 */
10221 - /* response word 3 */
10222 - __le64 message_ctx;
10223 - /* response word 4 */
10224 - __le64 message_iova;
10227 -#endif /* _FSL_DPBP_CMD_H */
10228 --- a/drivers/staging/fsl-mc/include/dpbp.h
10229 +++ b/drivers/staging/fsl-mc/include/dpbp.h
10231 -/* Copyright 2013-2015 Freescale Semiconductor Inc.
10233 + * Copyright 2013-2016 Freescale Semiconductor Inc.
10235 * Redistribution and use in source and binary forms, with or without
10236 * modification, are permitted provided that the following conditions are met:
10238 #ifndef __FSL_DPBP_H
10239 #define __FSL_DPBP_H
10241 -/* Data Path Buffer Pool API
10243 + * Data Path Buffer Pool API
10244 * Contains initialization APIs and runtime control APIs for DPBP
10247 @@ -44,25 +46,8 @@ int dpbp_open(struct fsl_mc_io *mc_io,
10250 int dpbp_close(struct fsl_mc_io *mc_io,
10255 - * struct dpbp_cfg - Structure representing DPBP configuration
10256 - * @options: place holder
10262 -int dpbp_create(struct fsl_mc_io *mc_io,
10264 - const struct dpbp_cfg *cfg,
10267 -int dpbp_destroy(struct fsl_mc_io *mc_io,
10273 int dpbp_enable(struct fsl_mc_io *mc_io,
10275 @@ -82,139 +67,24 @@ int dpbp_reset(struct fsl_mc_io *mc_io,
10279 - * struct dpbp_irq_cfg - IRQ configuration
10280 - * @addr: Address that must be written to signal a message-based interrupt
10281 - * @val: Value to write into irq_addr address
10282 - * @irq_num: A user defined number associated with this IRQ
10284 -struct dpbp_irq_cfg {
10290 -int dpbp_set_irq(struct fsl_mc_io *mc_io,
10294 - struct dpbp_irq_cfg *irq_cfg);
10296 -int dpbp_get_irq(struct fsl_mc_io *mc_io,
10301 - struct dpbp_irq_cfg *irq_cfg);
10303 -int dpbp_set_irq_enable(struct fsl_mc_io *mc_io,
10309 -int dpbp_get_irq_enable(struct fsl_mc_io *mc_io,
10315 -int dpbp_set_irq_mask(struct fsl_mc_io *mc_io,
10321 -int dpbp_get_irq_mask(struct fsl_mc_io *mc_io,
10327 -int dpbp_get_irq_status(struct fsl_mc_io *mc_io,
10333 -int dpbp_clear_irq_status(struct fsl_mc_io *mc_io,
10340 * struct dpbp_attr - Structure representing DPBP attributes
10341 * @id: DPBP object ID
10342 - * @version: DPBP version
10343 * @bpid: Hardware buffer pool ID; should be used as an argument in
10344 * acquire/release operations on buffers
10349 - * struct version - Structure representing DPBP version
10350 - * @major: DPBP major version
10351 - * @minor: DPBP minor version
10360 -int dpbp_get_attributes(struct fsl_mc_io *mc_io,
10363 - struct dpbp_attr *attr);
10366 - * DPBP notifications options
10370 - * BPSCN write will attempt to allocate into a cache (coherent write)
10372 -#define DPBP_NOTIF_OPT_COHERENT_WRITE 0x00000001
10375 - * struct dpbp_notification_cfg - Structure representing DPBP notifications
10376 - * towards software
10377 - * @depletion_entry: below this threshold the pool is "depleted";
10378 - * set it to '0' to disable it
10379 - * @depletion_exit: greater than or equal to this threshold the pool exit its
10380 - * "depleted" state
10381 - * @surplus_entry: above this threshold the pool is in "surplus" state;
10382 - * set it to '0' to disable it
10383 - * @surplus_exit: less than or equal to this threshold the pool exit its
10384 - * "surplus" state
10385 - * @message_iova: MUST be given if either 'depletion_entry' or 'surplus_entry'
10386 - * is not '0' (enable); I/O virtual address (must be in DMA-able memory),
10387 - * must be 16B aligned.
10388 - * @message_ctx: The context that will be part of the BPSCN message and will
10389 - * be written to 'message_iova'
10390 - * @options: Mask of available options; use 'DPBP_NOTIF_OPT_<X>' values
10392 -struct dpbp_notification_cfg {
10393 - u32 depletion_entry;
10394 - u32 depletion_exit;
10395 - u32 surplus_entry;
10396 - u32 surplus_exit;
10397 - u64 message_iova;
10402 -int dpbp_set_notifications(struct fsl_mc_io *mc_io,
10405 - struct dpbp_notification_cfg *cfg);
10407 -int dpbp_get_notifications(struct fsl_mc_io *mc_io,
10410 - struct dpbp_notification_cfg *cfg);
10413 +int dpbp_get_attributes(struct fsl_mc_io *mc_io,
10416 + struct dpbp_attr *attr);
10418 +int dpbp_get_api_version(struct fsl_mc_io *mc_io,
10423 #endif /* __FSL_DPBP_H */
10425 +++ b/drivers/staging/fsl-mc/include/dpcon.h
10427 +/* Copyright 2013-2016 Freescale Semiconductor Inc.
10429 + * Redistribution and use in source and binary forms, with or without
10430 + * modification, are permitted provided that the following conditions are met:
10431 + * * Redistributions of source code must retain the above copyright
10432 + * notice, this list of conditions and the following disclaimer.
10433 + * * Redistributions in binary form must reproduce the above copyright
10434 + * notice, this list of conditions and the following disclaimer in the
10435 + * documentation and/or other materials provided with the distribution.
10436 + * * Neither the name of the above-listed copyright holders nor the
10437 + * names of any contributors may be used to endorse or promote products
10438 + * derived from this software without specific prior written permission.
10441 + * ALTERNATIVELY, this software may be distributed under the terms of the
10442 + * GNU General Public License ("GPL") as published by the Free Software
10443 + * Foundation, either version 2 of that License or (at your option) any
10446 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
10447 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
10448 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
10449 + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
10450 + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
10451 + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
10452 + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
10453 + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
10454 + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
10455 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
10456 + * POSSIBILITY OF SUCH DAMAGE.
10458 +#ifndef __FSL_DPCON_H
10459 +#define __FSL_DPCON_H
10461 +/* Data Path Concentrator API
10462 + * Contains initialization APIs and runtime control APIs for DPCON
10467 +/** General DPCON macros */
10470 + * Use it to disable notifications; see dpcon_set_notification()
10472 +#define DPCON_INVALID_DPIO_ID (int)(-1)
10474 +int dpcon_open(struct fsl_mc_io *mc_io,
10479 +int dpcon_close(struct fsl_mc_io *mc_io,
10483 +int dpcon_enable(struct fsl_mc_io *mc_io,
10487 +int dpcon_disable(struct fsl_mc_io *mc_io,
10491 +int dpcon_is_enabled(struct fsl_mc_io *mc_io,
10496 +int dpcon_reset(struct fsl_mc_io *mc_io,
10501 + * struct dpcon_attr - Structure representing DPCON attributes
10502 + * @id: DPCON object ID
10503 + * @qbman_ch_id: Channel ID to be used by dequeue operation
10504 + * @num_priorities: Number of priorities for the DPCON channel (1-8)
10506 +struct dpcon_attr {
10509 + u8 num_priorities;
10512 +int dpcon_get_attributes(struct fsl_mc_io *mc_io,
10515 + struct dpcon_attr *attr);
10518 + * struct dpcon_notification_cfg - Structure representing notification params
10519 + * @dpio_id: DPIO object ID; must be configured with a notification channel;
10520 + * to disable notifications set it to 'DPCON_INVALID_DPIO_ID';
10521 + * @priority: Priority selection within the DPIO channel; valid values
10522 + * are 0-7, depending on the number of priorities in that channel
10523 + * @user_ctx: User context value provided with each CDAN message
10525 +struct dpcon_notification_cfg {
10531 +int dpcon_set_notification(struct fsl_mc_io *mc_io,
10534 + struct dpcon_notification_cfg *cfg);
10536 +int dpcon_get_api_version(struct fsl_mc_io *mc_io,
10541 +#endif /* __FSL_DPCON_H */
10542 --- a/drivers/staging/fsl-mc/include/dpmng.h
10543 +++ b/drivers/staging/fsl-mc/include/dpmng.h
10545 -/* Copyright 2013-2015 Freescale Semiconductor Inc.
10547 + * Copyright 2013-2016 Freescale Semiconductor Inc.
10549 * Redistribution and use in source and binary forms, with or without
10550 * modification, are permitted provided that the following conditions are met:
10552 #ifndef __FSL_DPMNG_H
10553 #define __FSL_DPMNG_H
10555 -/* Management Complex General API
10557 + * Management Complex General API
10558 * Contains general API for the Management Complex firmware
10561 @@ -58,12 +60,8 @@ struct mc_version {
10565 -int mc_get_version(struct fsl_mc_io *mc_io,
10567 - struct mc_version *mc_ver_info);
10569 -int dpmng_get_container_id(struct fsl_mc_io *mc_io,
10571 - int *container_id);
10572 +int mc_get_version(struct fsl_mc_io *mc_io,
10574 + struct mc_version *mc_ver_info);
10576 #endif /* __FSL_DPMNG_H */
10578 +++ b/drivers/staging/fsl-mc/include/dpopr.h
10581 + * Copyright 2017 NXP
10583 + * Redistribution and use in source and binary forms, with or without
10584 + * modification, are permitted provided that the following conditions are met:
10585 + * * Redistributions of source code must retain the above copyright
10586 + * notice, this list of conditions and the following disclaimer.
10587 + * * Redistributions in binary form must reproduce the above copyright
10588 + * notice, this list of conditions and the following disclaimer in the
10589 + * documentation and/or other materials provided with the distribution.
10590 + * * Neither the name of the above-listed copyright holders nor the
10591 + * names of any contributors may be used to endorse or promote products
10592 + * derived from this software without specific prior written permission.
10595 + * ALTERNATIVELY, this software may be distributed under the terms of the
10596 + * GNU General Public License ("GPL") as published by the Free Software
10597 + * Foundation, either version 2 of that License or (at your option) any
10600 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
10601 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
10602 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
10603 + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
10604 + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
10605 + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
10606 + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
10607 + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
10608 + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
10609 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
10610 + * POSSIBILITY OF SUCH DAMAGE.
10612 +#ifndef __FSL_DPOPR_H_
10613 +#define __FSL_DPOPR_H_
10615 +/* Data Path Order Restoration API
10616 + * Contains initialization APIs and runtime APIs for the Order Restoration
10619 +/** Order Restoration properties */
10622 + * Create a new Order Point Record option
10624 +#define OPR_OPT_CREATE 0x1
10626 + * Retire an existing Order Point Record option
10628 +#define OPR_OPT_RETIRE 0x2
10631 + * struct opr_cfg - Structure representing OPR configuration
10632 + * @oprrws: Order point record (OPR) restoration window size (0 to 5)
10633 + * 0 - Window size is 32 frames.
10634 + * 1 - Window size is 64 frames.
10635 + * 2 - Window size is 128 frames.
10636 + * 3 - Window size is 256 frames.
10637 + * 4 - Window size is 512 frames.
10638 + * 5 - Window size is 1024 frames.
10639 + * @oa: OPR auto advance NESN window size (0 disabled, 1 enabled)
10640 + * @olws: OPR acceptable late arrival window size (0 to 3)
10641 + * 0 - Disabled. Late arrivals are always rejected.
10642 + * 1 - Window size is 32 frames.
10643 + * 2 - Window size is the same as the OPR restoration
10644 + * window size configured in the OPRRWS field.
10645 + * 3 - Window size is 8192 frames. Late arrivals are
10646 + * always accepted.
10647 + * @oeane: Order restoration list (ORL) resource exhaustion
10648 + * advance NESN enable (0 disabled, 1 enabled)
10649 + * @oloe: OPR loose ordering enable (0 disabled, 1 enabled)
10660 + * struct opr_qry - Structure representing OPR configuration
10661 + * @enable: Enabled state
10662 + * @rip: Retirement In Progress
10663 + * @ndsn: Next dispensed sequence number
10664 + * @nesn: Next expected sequence number
10665 + * @ea_hseq: Early arrival head sequence number
10666 + * @hseq_nlis: HSEQ not last in sequence
10667 + * @ea_tseq: Early arrival tail sequence number
10668 + * @tseq_nlis: TSEQ not last in sequence
10669 + * @ea_tptr: Early arrival tail pointer
10670 + * @ea_hptr: Early arrival head pointer
10671 + * @opr_id: Order Point Record ID
10672 + * @opr_vid: Order Point Record Virtual ID
10689 +#endif /* __FSL_DPOPR_H_ */
10690 --- a/drivers/staging/fsl-mc/include/dprc.h
10691 +++ b/drivers/staging/fsl-mc/include/dprc.h
10693 -/* Copyright 2013-2015 Freescale Semiconductor Inc.
10695 + * Copyright 2013-2016 Freescale Semiconductor Inc.
10697 * Redistribution and use in source and binary forms, with or without
10698 * modification, are permitted provided that the following conditions are met:
10699 @@ -34,26 +35,13 @@
10701 #include "mc-cmd.h"
10703 -/* Data Path Resource Container API
10705 + * Data Path Resource Container API
10706 * Contains DPRC API for managing and querying DPAA resources
10712 - * Set this value as the icid value in dprc_cfg structure when creating a
10713 - * container, in case the ICID is not selected by the user and should be
10714 - * allocated by the DPRC from the pool of ICIDs.
10716 -#define DPRC_GET_ICID_FROM_POOL (u16)(~(0))
10719 - * Set this value as the portal_id value in dprc_cfg structure when creating a
10720 - * container, in case the portal ID is not specifically selected by the
10721 - * user and should be allocated by the DPRC from the pool of portal ids.
10723 -#define DPRC_GET_PORTAL_ID_FROM_POOL (int)(~(0))
10725 int dprc_open(struct fsl_mc_io *mc_io,
10728 @@ -63,75 +51,6 @@ int dprc_close(struct fsl_mc_io *mc_io,
10733 - * Container general options
10735 - * These options may be selected at container creation by the container creator
10736 - * and can be retrieved using dprc_get_attributes()
10739 -/* Spawn Policy Option allowed - Indicates that the new container is allowed
10740 - * to spawn and have its own child containers.
10742 -#define DPRC_CFG_OPT_SPAWN_ALLOWED 0x00000001
10744 -/* General Container allocation policy - Indicates that the new container is
10745 - * allowed to allocate requested resources from its parent container; if not
10746 - * set, the container is only allowed to use resources in its own pools; Note
10747 - * that this is a container's global policy, but the parent container may
10748 - * override it and set specific quota per resource type.
10750 -#define DPRC_CFG_OPT_ALLOC_ALLOWED 0x00000002
10752 -/* Object initialization allowed - software context associated with this
10753 - * container is allowed to invoke object initialization operations.
10755 -#define DPRC_CFG_OPT_OBJ_CREATE_ALLOWED 0x00000004
10757 -/* Topology change allowed - software context associated with this
10758 - * container is allowed to invoke topology operations, such as attach/detach
10759 - * of network objects.
10761 -#define DPRC_CFG_OPT_TOPOLOGY_CHANGES_ALLOWED 0x00000008
10763 -/* AIOP - Indicates that container belongs to AIOP. */
10764 -#define DPRC_CFG_OPT_AIOP 0x00000020
10766 -/* IRQ Config - Indicates that the container allowed to configure its IRQs. */
10767 -#define DPRC_CFG_OPT_IRQ_CFG_ALLOWED 0x00000040
10770 - * struct dprc_cfg - Container configuration options
10771 - * @icid: Container's ICID; if set to 'DPRC_GET_ICID_FROM_POOL', a free
10772 - * ICID value is allocated by the DPRC
10773 - * @portal_id: Portal ID; if set to 'DPRC_GET_PORTAL_ID_FROM_POOL', a free
10774 - * portal ID is allocated by the DPRC
10775 - * @options: Combination of 'DPRC_CFG_OPT_<X>' options
10776 - * @label: Object's label
10785 -int dprc_create_container(struct fsl_mc_io *mc_io,
10788 - struct dprc_cfg *cfg,
10789 - int *child_container_id,
10790 - u64 *child_portal_offset);
10792 -int dprc_destroy_container(struct fsl_mc_io *mc_io,
10795 - int child_container_id);
10797 -int dprc_reset_container(struct fsl_mc_io *mc_io,
10800 - int child_container_id);
10804 @@ -139,7 +58,7 @@ int dprc_reset_container(struct fsl_mc_i
10805 #define DPRC_IRQ_INDEX 0
10807 /* Number of dprc's IRQs */
10808 -#define DPRC_NUM_OF_IRQS 1
10809 +#define DPRC_NUM_OF_IRQS 1
10811 /* DPRC IRQ events */
10813 @@ -151,12 +70,14 @@ int dprc_reset_container(struct fsl_mc_i
10814 #define DPRC_IRQ_EVENT_RES_ADDED 0x00000004
10815 /* IRQ event - Indicates that resources removed from the container */
10816 #define DPRC_IRQ_EVENT_RES_REMOVED 0x00000008
10817 -/* IRQ event - Indicates that one of the descendant containers that opened by
10819 + * IRQ event - Indicates that one of the descendant containers that opened by
10820 * this container is destroyed
10822 #define DPRC_IRQ_EVENT_CONTAINER_DESTROYED 0x00000010
10824 -/* IRQ event - Indicates that on one of the container's opened object is
10826 + * IRQ event - Indicates that on one of the container's opened object is
10829 #define DPRC_IRQ_EVENT_OBJ_DESTROYED 0x00000020
10830 @@ -171,59 +92,59 @@ int dprc_reset_container(struct fsl_mc_i
10831 * @irq_num: A user defined number associated with this IRQ
10833 struct dprc_irq_cfg {
10834 - phys_addr_t paddr;
10839 -int dprc_set_irq(struct fsl_mc_io *mc_io,
10843 - struct dprc_irq_cfg *irq_cfg);
10845 -int dprc_get_irq(struct fsl_mc_io *mc_io,
10850 - struct dprc_irq_cfg *irq_cfg);
10852 -int dprc_set_irq_enable(struct fsl_mc_io *mc_io,
10858 -int dprc_get_irq_enable(struct fsl_mc_io *mc_io,
10864 -int dprc_set_irq_mask(struct fsl_mc_io *mc_io,
10870 -int dprc_get_irq_mask(struct fsl_mc_io *mc_io,
10876 -int dprc_get_irq_status(struct fsl_mc_io *mc_io,
10882 -int dprc_clear_irq_status(struct fsl_mc_io *mc_io,
10887 + phys_addr_t paddr;
10892 +int dprc_set_irq(struct fsl_mc_io *mc_io,
10896 + struct dprc_irq_cfg *irq_cfg);
10898 +int dprc_get_irq(struct fsl_mc_io *mc_io,
10903 + struct dprc_irq_cfg *irq_cfg);
10905 +int dprc_set_irq_enable(struct fsl_mc_io *mc_io,
10911 +int dprc_get_irq_enable(struct fsl_mc_io *mc_io,
10917 +int dprc_set_irq_mask(struct fsl_mc_io *mc_io,
10923 +int dprc_get_irq_mask(struct fsl_mc_io *mc_io,
10929 +int dprc_get_irq_status(struct fsl_mc_io *mc_io,
10935 +int dprc_clear_irq_status(struct fsl_mc_io *mc_io,
10942 * struct dprc_attributes - Container attributes
10943 @@ -231,114 +152,23 @@ int dprc_clear_irq_status(struct fsl_mc_
10944 * @icid: Container's ICID
10945 * @portal_id: Container's portal ID
10946 * @options: Container's options as set at container's creation
10947 - * @version: DPRC version
10949 struct dprc_attributes {
10955 - * struct version - DPRC version
10956 - * @major: DPRC major version
10957 - * @minor: DPRC minor version
10965 -int dprc_get_attributes(struct fsl_mc_io *mc_io,
10968 - struct dprc_attributes *attributes);
10970 -int dprc_set_res_quota(struct fsl_mc_io *mc_io,
10973 - int child_container_id,
10977 -int dprc_get_res_quota(struct fsl_mc_io *mc_io,
10980 - int child_container_id,
10984 -/* Resource request options */
10986 -/* Explicit resource ID request - The requested objects/resources
10987 - * are explicit and sequential (in case of resources).
10988 - * The base ID is given at res_req at base_align field
10990 -#define DPRC_RES_REQ_OPT_EXPLICIT 0x00000001
10992 -/* Aligned resources request - Relevant only for resources
10993 - * request (and not objects). Indicates that resources base ID should be
10994 - * sequential and aligned to the value given at dprc_res_req base_align field
10996 -#define DPRC_RES_REQ_OPT_ALIGNED 0x00000002
10998 -/* Plugged Flag - Relevant only for object assignment request.
10999 - * Indicates that after all objects assigned. An interrupt will be invoked at
11000 - * the relevant GPP. The assigned object will be marked as plugged.
11001 - * plugged objects can't be assigned from their container
11003 -#define DPRC_RES_REQ_OPT_PLUGGED 0x00000004
11006 - * struct dprc_res_req - Resource request descriptor, to be used in assignment
11007 - * or un-assignment of resources and objects.
11008 - * @type: Resource/object type: Represent as a NULL terminated string.
11009 - * This string may received by using dprc_get_pool() to get resource
11010 - * type and dprc_get_obj() to get object type;
11011 - * Note: it is not possible to assign/un-assign DPRC objects
11012 - * @num: Number of resources
11013 - * @options: Request options: combination of DPRC_RES_REQ_OPT_ options
11014 - * @id_base_align: In case of explicit assignment (DPRC_RES_REQ_OPT_EXPLICIT
11015 - * is set at option), this field represents the required base ID
11016 - * for resource allocation; In case of aligned assignment
11017 - * (DPRC_RES_REQ_OPT_ALIGNED is set at option), this field
11018 - * indicates the required alignment for the resource ID(s) -
11019 - * use 0 if there is no alignment or explicit ID requirements
11021 -struct dprc_res_req {
11025 - int id_base_align;
11028 -int dprc_assign(struct fsl_mc_io *mc_io,
11031 - int container_id,
11032 - struct dprc_res_req *res_req);
11034 -int dprc_unassign(struct fsl_mc_io *mc_io,
11037 - int child_container_id,
11038 - struct dprc_res_req *res_req);
11040 -int dprc_get_pool_count(struct fsl_mc_io *mc_io,
11043 - int *pool_count);
11045 -int dprc_get_pool(struct fsl_mc_io *mc_io,
11050 +int dprc_get_attributes(struct fsl_mc_io *mc_io,
11053 + struct dprc_attributes *attributes);
11055 int dprc_get_obj_count(struct fsl_mc_io *mc_io,
11063 /* Objects Attributes Flags */
11065 @@ -353,7 +183,7 @@ int dprc_get_obj_count(struct fsl_mc_io
11067 * user is responsible for proper memory handling through IOMMU configuration.
11069 -#define DPRC_OBJ_FLAG_NO_MEM_SHAREABILITY 0x0001
11070 +#define DPRC_OBJ_FLAG_NO_MEM_SHAREABILITY 0x0001
11073 * struct dprc_obj_desc - Object descriptor, returned from dprc_get_obj()
11074 @@ -381,41 +211,41 @@ struct dprc_obj_desc {
11078 -int dprc_get_obj(struct fsl_mc_io *mc_io,
11082 - struct dprc_obj_desc *obj_desc);
11084 -int dprc_get_obj_desc(struct fsl_mc_io *mc_io,
11089 - struct dprc_obj_desc *obj_desc);
11091 -int dprc_set_obj_irq(struct fsl_mc_io *mc_io,
11097 - struct dprc_irq_cfg *irq_cfg);
11099 -int dprc_get_obj_irq(struct fsl_mc_io *mc_io,
11106 - struct dprc_irq_cfg *irq_cfg);
11108 -int dprc_get_res_count(struct fsl_mc_io *mc_io,
11113 +int dprc_get_obj(struct fsl_mc_io *mc_io,
11117 + struct dprc_obj_desc *obj_desc);
11119 +int dprc_get_obj_desc(struct fsl_mc_io *mc_io,
11124 + struct dprc_obj_desc *obj_desc);
11126 +int dprc_set_obj_irq(struct fsl_mc_io *mc_io,
11132 + struct dprc_irq_cfg *irq_cfg);
11134 +int dprc_get_obj_irq(struct fsl_mc_io *mc_io,
11141 + struct dprc_irq_cfg *irq_cfg);
11143 +int dprc_get_res_count(struct fsl_mc_io *mc_io,
11150 * enum dprc_iter_status - Iteration status
11151 @@ -429,27 +259,6 @@ enum dprc_iter_status {
11152 DPRC_ITER_STATUS_LAST = 2
11156 - * struct dprc_res_ids_range_desc - Resource ID range descriptor
11157 - * @base_id: Base resource ID of this range
11158 - * @last_id: Last resource ID of this range
11159 - * @iter_status: Iteration status - should be set to DPRC_ITER_STATUS_FIRST at
11160 - * first iteration; while the returned marker is DPRC_ITER_STATUS_MORE,
11161 - * additional iterations are needed, until the returned marker is
11162 - * DPRC_ITER_STATUS_LAST
11164 -struct dprc_res_ids_range_desc {
11167 - enum dprc_iter_status iter_status;
11170 -int dprc_get_res_ids(struct fsl_mc_io *mc_io,
11174 - struct dprc_res_ids_range_desc *range_desc);
11177 /* Cacheable - Indicates that region should be mapped as cacheable */
11178 #define DPRC_REGION_CACHEABLE 0x00000001
11179 @@ -481,64 +290,27 @@ struct dprc_region_desc {
11180 enum dprc_region_type type;
11183 -int dprc_get_obj_region(struct fsl_mc_io *mc_io,
11189 - struct dprc_region_desc *region_desc);
11191 -int dprc_set_obj_label(struct fsl_mc_io *mc_io,
11197 +int dprc_get_obj_region(struct fsl_mc_io *mc_io,
11203 + struct dprc_region_desc *region_desc);
11206 - * struct dprc_endpoint - Endpoint description for link connect/disconnect
11208 - * @type: Endpoint object type: NULL terminated string
11209 - * @id: Endpoint object ID
11210 - * @if_id: Interface ID; should be set for endpoints with multiple
11211 - * interfaces ("dpsw", "dpdmux"); for others, always set to 0
11213 -struct dprc_endpoint {
11218 +int dprc_get_api_version(struct fsl_mc_io *mc_io,
11224 - * struct dprc_connection_cfg - Connection configuration.
11225 - * Used for virtual connections only
11226 - * @committed_rate: Committed rate (Mbits/s)
11227 - * @max_rate: Maximum rate (Mbits/s)
11229 -struct dprc_connection_cfg {
11230 - u32 committed_rate;
11233 +int dprc_get_container_id(struct fsl_mc_io *mc_io,
11235 + int *container_id);
11237 -int dprc_connect(struct fsl_mc_io *mc_io,
11240 - const struct dprc_endpoint *endpoint1,
11241 - const struct dprc_endpoint *endpoint2,
11242 - const struct dprc_connection_cfg *cfg);
11244 -int dprc_disconnect(struct fsl_mc_io *mc_io,
11247 - const struct dprc_endpoint *endpoint);
11249 -int dprc_get_connection(struct fsl_mc_io *mc_io,
11252 - const struct dprc_endpoint *endpoint1,
11253 - struct dprc_endpoint *endpoint2,
11255 +int dprc_reset_container(struct fsl_mc_io *mc_io,
11258 + int child_container_id);
11260 #endif /* _FSL_DPRC_H */
11262 --- a/drivers/staging/fsl-mc/include/mc-bus.h
11263 +++ b/drivers/staging/fsl-mc/include/mc-bus.h
11266 * Freescale Management Complex (MC) bus declarations
11268 - * Copyright (C) 2014 Freescale Semiconductor, Inc.
11269 + * Copyright (C) 2014-2016 Freescale Semiconductor, Inc.
11270 * Author: German Rivera <German.Rivera@freescale.com>
11272 * This file is licensed under the terms of the GNU General Public
11273 @@ -42,8 +42,8 @@ struct msi_domain_info;
11275 struct fsl_mc_resource_pool {
11276 enum fsl_mc_pool_type type;
11277 - int16_t max_count;
11278 - int16_t free_count;
11281 struct mutex mutex; /* serializes access to free_list */
11282 struct list_head free_list;
11283 struct fsl_mc_bus *mc_bus;
11284 @@ -73,6 +73,7 @@ struct fsl_mc_bus {
11285 int dprc_scan_container(struct fsl_mc_device *mc_bus_dev);
11287 int dprc_scan_objects(struct fsl_mc_device *mc_bus_dev,
11288 + const char *driver_override,
11289 unsigned int *total_irq_count);
11291 int __init dprc_driver_init(void);
11292 --- a/drivers/staging/fsl-mc/include/mc-cmd.h
11293 +++ b/drivers/staging/fsl-mc/include/mc-cmd.h
11295 -/* Copyright 2013-2015 Freescale Semiconductor Inc.
11297 + * Copyright 2013-2016 Freescale Semiconductor Inc.
11299 * Redistribution and use in source and binary forms, with or without
11300 * modification, are permitted provided that the following conditions are met:
11301 @@ -48,6 +49,15 @@ struct mc_command {
11302 u64 params[MC_CMD_NUM_OF_PARAMS];
11305 +struct mc_rsp_create {
11306 + __le32 object_id;
11309 +struct mc_rsp_api_ver {
11310 + __le16 major_ver;
11311 + __le16 minor_ver;
11314 enum mc_cmd_status {
11315 MC_CMD_STATUS_OK = 0x0, /* Completed successfully */
11316 MC_CMD_STATUS_READY = 0x1, /* Ready to be processed */
11317 @@ -72,11 +82,6 @@ enum mc_cmd_status {
11318 /* Command completion flag */
11319 #define MC_CMD_FLAG_INTR_DIS 0x01
11321 -#define MC_CMD_HDR_CMDID_MASK 0xFFF0
11322 -#define MC_CMD_HDR_CMDID_SHIFT 4
11323 -#define MC_CMD_HDR_TOKEN_MASK 0xFFC0
11324 -#define MC_CMD_HDR_TOKEN_SHIFT 6
11326 static inline u64 mc_encode_cmd_header(u16 cmd_id,
11329 @@ -84,10 +89,8 @@ static inline u64 mc_encode_cmd_header(u
11331 struct mc_cmd_header *hdr = (struct mc_cmd_header *)&header;
11333 - hdr->cmd_id = cpu_to_le16((cmd_id << MC_CMD_HDR_CMDID_SHIFT) &
11334 - MC_CMD_HDR_CMDID_MASK);
11335 - hdr->token = cpu_to_le16((token << MC_CMD_HDR_TOKEN_SHIFT) &
11336 - MC_CMD_HDR_TOKEN_MASK);
11337 + hdr->cmd_id = cpu_to_le16(cmd_id);
11338 + hdr->token = cpu_to_le16(token);
11339 hdr->status = MC_CMD_STATUS_READY;
11340 if (cmd_flags & MC_CMD_FLAG_PRI)
11341 hdr->flags_hw = MC_CMD_FLAG_PRI;
11342 @@ -102,7 +105,26 @@ static inline u16 mc_cmd_hdr_read_token(
11343 struct mc_cmd_header *hdr = (struct mc_cmd_header *)&cmd->header;
11344 u16 token = le16_to_cpu(hdr->token);
11346 - return (token & MC_CMD_HDR_TOKEN_MASK) >> MC_CMD_HDR_TOKEN_SHIFT;
11350 +static inline u32 mc_cmd_read_object_id(struct mc_command *cmd)
11352 + struct mc_rsp_create *rsp_params;
11354 + rsp_params = (struct mc_rsp_create *)cmd->params;
11355 + return le32_to_cpu(rsp_params->object_id);
11358 +static inline void mc_cmd_read_api_version(struct mc_command *cmd,
11362 + struct mc_rsp_api_ver *rsp_params;
11364 + rsp_params = (struct mc_rsp_api_ver *)cmd->params;
11365 + *major_ver = le16_to_cpu(rsp_params->major_ver);
11366 + *minor_ver = le16_to_cpu(rsp_params->minor_ver);
11369 #endif /* __FSL_MC_CMD_H */
11370 --- a/drivers/staging/fsl-mc/include/mc-sys.h
11371 +++ b/drivers/staging/fsl-mc/include/mc-sys.h
11373 -/* Copyright 2013-2014 Freescale Semiconductor Inc.
11375 + * Copyright 2013-2016 Freescale Semiconductor Inc.
11377 * Interface of the I/O services to send MC commands to the MC hardware
11379 --- a/drivers/staging/fsl-mc/include/mc.h
11380 +++ b/drivers/staging/fsl-mc/include/mc.h
11383 * Freescale Management Complex (MC) bus public interface
11385 - * Copyright (C) 2014 Freescale Semiconductor, Inc.
11386 + * Copyright (C) 2014-2016 Freescale Semiconductor, Inc.
11387 * Author: German Rivera <German.Rivera@freescale.com>
11389 * This file is licensed under the terms of the GNU General Public
11390 @@ -81,7 +81,7 @@ enum fsl_mc_pool_type {
11392 struct fsl_mc_resource {
11393 enum fsl_mc_pool_type type;
11397 struct fsl_mc_resource_pool *parent_pool;
11398 struct list_head node;
11399 @@ -122,6 +122,7 @@ struct fsl_mc_device_irq {
11400 * @regions: pointer to array of MMIO region entries
11401 * @irqs: pointer to array of pointers to interrupts allocated to this device
11402 * @resource: generic resource associated with this MC object device, if any.
11403 + * @driver_override: Driver name to force a match
11405 * Generic device object for MC object devices that are "attached" to a
11407 @@ -154,6 +155,7 @@ struct fsl_mc_device {
11408 struct resource *regions;
11409 struct fsl_mc_device_irq **irqs;
11410 struct fsl_mc_resource *resource;
11411 + const char *driver_override;
11414 #define to_fsl_mc_device(_dev) \
11415 @@ -175,6 +177,8 @@ struct fsl_mc_device {
11416 #define fsl_mc_driver_register(drv) \
11417 __fsl_mc_driver_register(drv, THIS_MODULE)
11419 +void fsl_mc_device_remove(struct fsl_mc_device *mc_dev);
11421 int __must_check __fsl_mc_driver_register(struct fsl_mc_driver *fsl_mc_driver,
11422 struct module *owner);
11424 @@ -198,4 +202,13 @@ int __must_check fsl_mc_allocate_irqs(st
11426 void fsl_mc_free_irqs(struct fsl_mc_device *mc_dev);
11428 +void fsl_mc_dma_configure(struct fsl_mc_device *mc_dev,
11429 + struct device_node *fsl_mc_platform_node, int coherent);
11431 +#ifdef CONFIG_FSL_MC_BUS
11432 +struct iommu_group *fsl_mc_device_group(struct device *dev);
11434 +#define fsl_mc_device_group(__dev) NULL
11437 #endif /* _FSL_MC_H_ */