Skip to contentSkip to conversation

drivers/bus: Freescale Management Complex bus driver patch series

PATCH Superseded J. German Rivera 3 participants 17 messages Nov 13, 2014 – Dec 1, 2014

Subsystems (2)

v4 of 9 Superseded Latest is v9 →

lore
Share & tools
lore
#0 lore raw

v4 cover drivers/bus: Freescale Management Complex bus driver patch series

(Sorry in my previous post, I forgot to add the respin version in the subject)

This patch series introduces Linux support for the Freescale Management Complex (fsl-mc) hardware. This patch series is dependent on the patch series "ARM64: Add support for FSL's LS2085A SoC"
(http://thread.gmane.org/gmane.linux.ports.arm.kernel/351829)

The fsl-mc is a hardware resource manager that manages specialized hardware objects used in network-oriented packet processing applications. After the fsl-mc block is enabled, pools of hardware resources are available, such as queues, buffer pools, I/O interfaces. These resources are building blocks that can be used to create functional hardware objects such as network interfaces, crypto accelerator instances, or L2 switches.

All the fsl-mc managed hardware resources/objects are represented in a physical grouping mechanism called a 'container' or DPRC (data path resource container).

Quoted 1 line

From the point of view of an OS, a DPRC functions similar to a plug

and play bus. Using fsl-mc commands software can enumerate the contents of the DPRC discovering the hardware objects present and binding them to drivers. Hardware objects can be created and removed dynamically, providing hot pluggability of the hardware objects.

Software contexts interact with the fsl-mc by sending commands through a memory mapped hardware interface called an "MC portal". Every fsl-mc object type has a command set to manage the objects. Key DPRC commands include:
-create/destroy a DPRC
-enumerate objects and resource pools in the DPRC, including
identifying mappable regions and the number of IRQs an object may have
-IRQ configuration
-move objects/resources between DPRCs
-connecting objects (e.g. connecting a network interface to
an L2 switch port)
-reset

Patch 1 contains a minimal set of low level functions to send an d receive commands to the fsl-mc. It includes support for basic management commands and commands to manipulate DPRC objects.

Patch 2 contains a platform device driver that sets up and registers the basic bus infrastructure including support for adding/removing devices, register/unregister of drivers, and bus match support to bind devices to drivers.

Patch 3 contains an driver that manages DPRC objects (the container that holds the hardware resources). This driver functions as a bus controller and handles enumeration of the objects in the container and hotplug events.

CHANGE HISTORY

Changes in v4:
- Addressed changes from ALex Graf. Details in each patch.
- Upgraded MC flibs to version 0.5
- Fixed bug related to setting fsl_mc_bus_type.dev_root too late

Changes in v3:
- Addressed pending issues not resolved in v2:
* Removed Doxygen comments as requested by Greg Kroah-Hartman
* Moved newly added FSL-specific header files from include/linux to include/linux/fsl
* Changed wording of licenses in MC flib source files
* Fixed sparse warning about context imbalance in 'mc_send_command'

- Addressed additional comments from Kim Phillips, Scott Wood and Timur Tabi. Details in each patch.

Issues pending resolution not addressed by v3:
- Checkpatch warnings:
* WARNING: DT compatible string "fsl,qoriq-mc" appears un-documented This warning will go away once the prerequisite patch series is accepted upstream.
* WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? This warning still happens even after adding MAINTAINERS file entries in the same patch where new files were added

Changes in v2:
- Added reference to the patch series this patch is dependent on for device tree and device tree bindings changes. (See above).
- Removed patch 4 (update to the MAINTAINERS file), as this is done now in patch 1
- Addressed comments from Joe Perches, Kim Phillips, Alex Graf and Scott Wood. Details in each patch.

Issues pending resolution not addressed by v2:
- What to do with Doxygen comments in patch 1
- Whether to move or not FSL-specific header files added in include/linux,
by this patch series, to another location
- Whether to change or not the wording of the licenses used in some
source files
- Checkpatch warnings:
* WARNING: DT compatible string "fsl,qoriq-mc" appears un-documented
This warning will go away once the prerequisite patch series is
accepted upstream.
* WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?
This warning still happens even after adding MAINTAINERS file entries in
the same patch where new files were added
- Sparse warning:
* drivers/bus/fsl-mc/fsl_mc_sys.c:193:9: warning: context imbalance in 'mc_send_command' - different lock contexts for basic block This warning is caused by conditionally acquiring/releasing a lock in function mc_send_command().
Not clear how to solve this warning, as we need to be able to decide at
run time based on a flag whether to acquire the lock or not.

Changes in v1:
- No changes since RFC v4

Changes in RFC v4:
- Fixed parameter mismatch for device_find_child() call in fsl_mc_dprc.c
- Added back the dma_mask field to struct fsl_mc_device as it is needed by some MC child device drivers. However, the default DMA mask now does not have the 32-bit limitation of the original patch series (v1).

Changes in RFC v3:
Rework to address comments from Arnd Bergmann:
- Removed per-bus list of children, and instead use device_for_each_child()
- Use the same structure (struct fsl_mc_device) to represent both bus devices and their children.
http://www.mail-archive.com/linux-kernel%40vger.kernel.org/msg711301.html

Changes in RFC v2:
Rework to address comments from Arnd Bergmann:
- Removed fsl_mc_bus structure and global variable
- Removed the 'magic' fields from all structs
- Removed NULL initializers
- Replaced all occurrences of EXPORT_SYMBOL() with EXPORT_SYMBOL_GPL()
- Removed function dprc_parse_dt_node(), and replaced its call by a direct call to of_address_to_resource()
- Removed struct fsl_mc_device_region and use standard 'struct resource' instead.
- Removed dma_mask field from 'struct fsl_mc_device' as it is not currently being used.
- Removed redundant 'driver' field from struct fsl_mc_device
- Removed the container field. We can get the parent DPRC of a given dev, from its dev.parent field.
http://www.mail-archive.com/linux-kernel%40vger.kernel.org/msg708858.html

#1 lore raw

PATCH v4 1/3 drivers/bus: Added Freescale Management Complex APIs

APIs to access the Management Complex (MC) hardware module of Freescale LS2 SoCs. This patch includes APIs to check the MC firmware version and to manipulate DPRC objects in the MC.

---
Changes in v4:
- Addressed comments from Alex Graf:
* Added file description for files that did not have one
* Removed Marshalling/unmarshalling macros invoked in MC command wrapper functions, and instead do the marshalling/ unmarshalling directly in these functions.
* Added type cast u32 in status range-check in mc_status_to_error()
* Moved mc_write_command() and mc_read_response() inline function to mc_sys.c as they are only used in that file
* Renamed u64_enc() as mc_enc() and u64_dec() as mc_dec()
- Upgraded MC flibs for MC firmware 0.5

Changes in v3:
- Addressed comment from Greg Kroah-Hartman:
* Removed doxygen comments

- Addressed comment from Scott Wood:
* Replaced udelay() call with usleep_range() call in polling loop
- Addressed comments from Kim Phillips:
* Fixed license text in all files
* Renamed files:

	drivers/bus/fsl-mc/fsl_dpmng_cmd.h -> drivers/bus/fsl-mc/dpmng-cmd.h
	drivers/bus/fsl-mc/fsl_dprc_cmd.h -> drivers/bus/fsl-mc/dprc-cmd.h
	drivers/bus/fsl-mc/fsl_mc_sys.c -> drivers/bus/fsl-mc/mc-sys.c
	include/linux/fsl_dpmng.h -> include/linux/fsl/dpmng.h
	include/linux/fsl_dprc.h -> include/linux/fsl/dprc.h
	include/linux/fsl_mc_cmd.h -> include/linux/fsl/mc-cmd.h
	include/linux/fsl_mc_sys.h -> include/linux/fsl/mc-sys.h

* Changed dpmng_load_iop() to take the DMA address directly, instead of the image virtual address.
* Removed if and WARN_ON that checks for NULL fsl_destroy_mc_io()
* Removed locking from mc_send_command(). Now the caller of MC flib APIs is responsible for protecting concurrent accesses to the same MC portal.

Changes in v2:
- Addressed comment from Joe Perches:
* Refactored logic to actively fail on err and proceed at the same indent level on success, for all functions in dprc.c and dpmng.c.

- Addressed comments from Kim Phillips:
* Fixed warning in mc_send_command
* Changed serialization logic in mc_send_command() to only use spinlock_irqsave() when both threads and interrupt handlers concurrently access the same portal.
* Changed switch to lookup table in mc_status_to_error()
* Removed macros iowrite64(), ioread64(), ENOTSUP from fsl_mc_sys.h
* Removed #ifdef side for FSL_MC_FIRMWARE in fsl_mc_cmd.h
* Changed non-devm_ API calls to devm_ API calls and refactored fsl_create_mc_io()/fsl_destroy_mc_io() to simplify cleanup logic.

- Addressed comments from Scott Wood:
* Return -ENXIO instead of -EFAULT when ioremap_nocache() fails

- Addressed comments from Alex Graf:
* Added MAINTAINERS file entries for new files
* Added dev param to fsl_create_mc_io(), to enable the use of devm_ APIs in this function and fsl_destroy_mc_io().
* Changed the value of the timeout for MC command completion to be a function of HZ instead of a hard-coded jiffies value.

 MAINTAINERS                    |   8 +
 drivers/bus/fsl-mc/dpmng-cmd.h |  50 +++
 drivers/bus/fsl-mc/dpmng.c     | 126 ++++++
 drivers/bus/fsl-mc/dprc-cmd.h  |  85 ++++
 drivers/bus/fsl-mc/dprc.c      | 933 +++++++++++++++++++++++++++++++++++++++++
 drivers/bus/fsl-mc/mc-sys.c    | 284 +++++++++++++
 include/linux/fsl/dpmng.h      | 151 +++++++
 include/linux/fsl/dprc.h       | 868 ++++++++++++++++++++++++++++++++++++++
 include/linux/fsl/mc-cmd.h     | 109 +++++
 include/linux/fsl/mc-sys.h     |  70 ++++
 10 files changed, 2684 insertions(+)
 create mode 100644 drivers/bus/fsl-mc/dpmng-cmd.h
 create mode 100644 drivers/bus/fsl-mc/dpmng.c
 create mode 100644 drivers/bus/fsl-mc/dprc-cmd.h
 create mode 100644 drivers/bus/fsl-mc/dprc.c
 create mode 100644 drivers/bus/fsl-mc/mc-sys.c
 create mode 100644 include/linux/fsl/dpmng.h
 create mode 100644 include/linux/fsl/dprc.h
 create mode 100644 include/linux/fsl/mc-cmd.h
 create mode 100644 include/linux/fsl/mc-sys.h
MAINTAINERS +8 -0
index c3cfa1b..11523ee 100644
@@ -3880,6 +3880,14 @@ F:	sound/soc/fsl/fsl*
 F:	sound/soc/fsl/imx*
 F:	sound/soc/fsl/mpc8610_hpcd.c
 
+FREESCALE QORIQ MANAGEMENT COMPLEX DRIVER
+M:	J. German Rivera <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	include/linux/fsl_mc*
+F:	include/linux/fsl_dp*
+F:	drivers/bus/fsl-mc/*
+
 FREEVXFS FILESYSTEM
 M:	Christoph Hellwig <[email protected]>
 W:	ftp://ftp.openlinux.org/pub/people/hch/vxfs
drivers/bus/fsl-mc/dpmng-cmd.h new file +50 -0

50 lines not on this page · raw message

drivers/bus/fsl-mc/dpmng.c new file +126 -0

126 lines not on this page · raw message

drivers/bus/fsl-mc/dprc-cmd.h new file +85 -0

85 lines not on this page · raw message

drivers/bus/fsl-mc/dprc.c new file +933 -0

933 lines not on this page · raw message

drivers/bus/fsl-mc/mc-sys.c new file +284 -0

284 lines not on this page · raw message

include/linux/fsl/dpmng.h new file +151 -0

151 lines not on this page · raw message

include/linux/fsl/dprc.h new file +868 -0

868 lines not on this page · raw message

include/linux/fsl/mc-cmd.h new file +109 -0

109 lines not on this page · raw message

include/linux/fsl/mc-sys.h new file +70 -0

70 lines not on this page · raw message

--
2.1.2

#2 lore raw

Re: [PATCH 1/3 v4] drivers/bus: Added Freescale Management Complex APIs

Quoted 91 lines · J. German Rivera

APIs to access the Management Complex (MC) hardware module of Freescale LS2 SoCs. This patch includes APIs to check the MC firmware version and to manipulate DPRC objects in the MC.

---
Changes in v4:
- Addressed comments from Alex Graf:
* Added file description for files that did not have one
* Removed Marshalling/unmarshalling macros invoked in MC command wrapper functions, and instead do the marshalling/ unmarshalling directly in these functions.
* Added type cast u32 in status range-check in mc_status_to_error()
* Moved mc_write_command() and mc_read_response() inline function to mc_sys.c as they are only used in that file
* Renamed u64_enc() as mc_enc() and u64_dec() as mc_dec()
- Upgraded MC flibs for MC firmware 0.5

Changes in v3:
- Addressed comment from Greg Kroah-Hartman:
* Removed doxygen comments

- Addressed comment from Scott Wood:
* Replaced udelay() call with usleep_range() call in polling loop
- Addressed comments from Kim Phillips:
* Fixed license text in all files
* Renamed files:

	drivers/bus/fsl-mc/fsl_dpmng_cmd.h -> drivers/bus/fsl-mc/dpmng-cmd.h
	drivers/bus/fsl-mc/fsl_dprc_cmd.h -> drivers/bus/fsl-mc/dprc-cmd.h
	drivers/bus/fsl-mc/fsl_mc_sys.c -> drivers/bus/fsl-mc/mc-sys.c
	include/linux/fsl_dpmng.h -> include/linux/fsl/dpmng.h
	include/linux/fsl_dprc.h -> include/linux/fsl/dprc.h
	include/linux/fsl_mc_cmd.h -> include/linux/fsl/mc-cmd.h
	include/linux/fsl_mc_sys.h -> include/linux/fsl/mc-sys.h

* Changed dpmng_load_iop() to take the DMA address directly, instead of the image virtual address.
* Removed if and WARN_ON that checks for NULL fsl_destroy_mc_io()
* Removed locking from mc_send_command(). Now the caller of MC flib APIs is responsible for protecting concurrent accesses to the same MC portal.

Changes in v2:
- Addressed comment from Joe Perches:
* Refactored logic to actively fail on err and proceed at the same indent level on success, for all functions in dprc.c and dpmng.c.

- Addressed comments from Kim Phillips:
* Fixed warning in mc_send_command
* Changed serialization logic in mc_send_command() to only use spinlock_irqsave() when both threads and interrupt handlers concurrently access the same portal.
* Changed switch to lookup table in mc_status_to_error()
* Removed macros iowrite64(), ioread64(), ENOTSUP from fsl_mc_sys.h
* Removed #ifdef side for FSL_MC_FIRMWARE in fsl_mc_cmd.h
* Changed non-devm_ API calls to devm_ API calls and refactored fsl_create_mc_io()/fsl_destroy_mc_io() to simplify cleanup logic.

- Addressed comments from Scott Wood:
* Return -ENXIO instead of -EFAULT when ioremap_nocache() fails

- Addressed comments from Alex Graf:
* Added MAINTAINERS file entries for new files
* Added dev param to fsl_create_mc_io(), to enable the use of devm_ APIs in this function and fsl_destroy_mc_io().
* Changed the value of the timeout for MC command completion to be a function of HZ instead of a hard-coded jiffies value.

 MAINTAINERS                    |   8 +
 drivers/bus/fsl-mc/dpmng-cmd.h |  50 +++
 drivers/bus/fsl-mc/dpmng.c     | 126 ++++++
 drivers/bus/fsl-mc/dprc-cmd.h  |  85 ++++
 drivers/bus/fsl-mc/dprc.c      | 933 +++++++++++++++++++++++++++++++++++++++++
 drivers/bus/fsl-mc/mc-sys.c    | 284 +++++++++++++
 include/linux/fsl/dpmng.h      | 151 +++++++
 include/linux/fsl/dprc.h       | 868 ++++++++++++++++++++++++++++++++++++++
 include/linux/fsl/mc-cmd.h     | 109 +++++
 include/linux/fsl/mc-sys.h     |  70 ++++
 10 files changed, 2684 insertions(+)
 create mode 100644 drivers/bus/fsl-mc/dpmng-cmd.h
 create mode 100644 drivers/bus/fsl-mc/dpmng.c
 create mode 100644 drivers/bus/fsl-mc/dprc-cmd.h
 create mode 100644 drivers/bus/fsl-mc/dprc.c
 create mode 100644 drivers/bus/fsl-mc/mc-sys.c
 create mode 100644 include/linux/fsl/dpmng.h
 create mode 100644 include/linux/fsl/dprc.h
 create mode 100644 include/linux/fsl/mc-cmd.h
 create mode 100644 include/linux/fsl/mc-sys.h

[...]

Quoted 4 lines
drivers/bus/fsl-mc/mc-sys.c new file +4 -0
+/**
+ * Sends an command to the MC device using the given MC I/O object
+ *
+ * @mc_io: MC I/O object to be used

drivers/bus/fsl-mc/mc-sys.c line 235

Quoted 10 lines
drivers/bus/fsl-mc/mc-sys.c new file +10 -0
+ * @cmd: command to be sent
+ *
+ * Returns '0' on Success; Error code otherwise.
+ *
+ * NOTE: This function cannot be invoked from from atomic contexts.
+ */
+int mc_send_command(struct fsl_mc_io *mc_io, struct mc_command *cmd)
+{
+	enum mc_cmd_status status;
+	unsigned long irqsave_flags = 0;

drivers/bus/fsl-mc/mc-sys.c: In function ‘mc_send_command’:
drivers/bus/fsl-mc/mc-sys.c:235:16: warning: unused variable ‘irqsave_flags’ [-Wunused-variable]

  unsigned long irqsave_flags = 0;
                ^

Alex

#3 lore raw

Re: [PATCH 1/3 v4] drivers/bus: Added Freescale Management Complex APIs

Quoted 108 lines · Alexander Graf
Quoted 91 lines · J. German Rivera

APIs to access the Management Complex (MC) hardware module of Freescale LS2 SoCs. This patch includes APIs to check the MC firmware version and to manipulate DPRC objects in the MC.

---
Changes in v4:
- Addressed comments from Alex Graf:
* Added file description for files that did not have one
* Removed Marshalling/unmarshalling macros invoked in MC command wrapper functions, and instead do the marshalling/ unmarshalling directly in these functions.
* Added type cast u32 in status range-check in mc_status_to_error()
* Moved mc_write_command() and mc_read_response() inline function to mc_sys.c as they are only used in that file
* Renamed u64_enc() as mc_enc() and u64_dec() as mc_dec()
- Upgraded MC flibs for MC firmware 0.5

Changes in v3:
- Addressed comment from Greg Kroah-Hartman:
* Removed doxygen comments

- Addressed comment from Scott Wood:
* Replaced udelay() call with usleep_range() call in polling loop
- Addressed comments from Kim Phillips:
* Fixed license text in all files
* Renamed files:

	drivers/bus/fsl-mc/fsl_dpmng_cmd.h -> drivers/bus/fsl-mc/dpmng-cmd.h
	drivers/bus/fsl-mc/fsl_dprc_cmd.h -> drivers/bus/fsl-mc/dprc-cmd.h
	drivers/bus/fsl-mc/fsl_mc_sys.c -> drivers/bus/fsl-mc/mc-sys.c
	include/linux/fsl_dpmng.h -> include/linux/fsl/dpmng.h
	include/linux/fsl_dprc.h -> include/linux/fsl/dprc.h
	include/linux/fsl_mc_cmd.h -> include/linux/fsl/mc-cmd.h
	include/linux/fsl_mc_sys.h -> include/linux/fsl/mc-sys.h

* Changed dpmng_load_iop() to take the DMA address directly, instead of the image virtual address.
* Removed if and WARN_ON that checks for NULL fsl_destroy_mc_io()
* Removed locking from mc_send_command(). Now the caller of MC flib APIs is responsible for protecting concurrent accesses to the same MC portal.

Changes in v2:
- Addressed comment from Joe Perches:
* Refactored logic to actively fail on err and proceed at the same indent level on success, for all functions in dprc.c and dpmng.c.

- Addressed comments from Kim Phillips:
* Fixed warning in mc_send_command
* Changed serialization logic in mc_send_command() to only use spinlock_irqsave() when both threads and interrupt handlers concurrently access the same portal.
* Changed switch to lookup table in mc_status_to_error()
* Removed macros iowrite64(), ioread64(), ENOTSUP from fsl_mc_sys.h
* Removed #ifdef side for FSL_MC_FIRMWARE in fsl_mc_cmd.h
* Changed non-devm_ API calls to devm_ API calls and refactored fsl_create_mc_io()/fsl_destroy_mc_io() to simplify cleanup logic.

- Addressed comments from Scott Wood:
* Return -ENXIO instead of -EFAULT when ioremap_nocache() fails

- Addressed comments from Alex Graf:
* Added MAINTAINERS file entries for new files
* Added dev param to fsl_create_mc_io(), to enable the use of devm_ APIs in this function and fsl_destroy_mc_io().
* Changed the value of the timeout for MC command completion to be a function of HZ instead of a hard-coded jiffies value.

  MAINTAINERS                    |   8 +
  drivers/bus/fsl-mc/dpmng-cmd.h |  50 +++
  drivers/bus/fsl-mc/dpmng.c     | 126 ++++++
  drivers/bus/fsl-mc/dprc-cmd.h  |  85 ++++
  drivers/bus/fsl-mc/dprc.c      | 933 +++++++++++++++++++++++++++++++++++++++++
  drivers/bus/fsl-mc/mc-sys.c    | 284 +++++++++++++
  include/linux/fsl/dpmng.h      | 151 +++++++
  include/linux/fsl/dprc.h       | 868 ++++++++++++++++++++++++++++++++++++++
  include/linux/fsl/mc-cmd.h     | 109 +++++
  include/linux/fsl/mc-sys.h     |  70 ++++
  10 files changed, 2684 insertions(+)

create mode 100644 drivers/bus/fsl-mc/dpmng-cmd.h create mode 100644 drivers/bus/fsl-mc/dpmng.c create mode 100644 drivers/bus/fsl-mc/dprc-cmd.h create mode 100644 drivers/bus/fsl-mc/dprc.c create mode 100644 drivers/bus/fsl-mc/mc-sys.c create mode 100644 include/linux/fsl/dpmng.h create mode 100644 include/linux/fsl/dprc.h create mode 100644 include/linux/fsl/mc-cmd.h create mode 100644 include/linux/fsl/mc-sys.h

[...]

Quoted 11 lines
drivers/bus/fsl-mc/mc-sys.c new file +11 -0
+/**
+ * Sends an command to the MC device using the given MC I/O object
+ *
+ * @mc_io: MC I/O object to be used
+ * @cmd: command to be sent
+ *
+ * Returns '0' on Success; Error code otherwise.
+ *
+ * NOTE: This function cannot be invoked from from atomic contexts.
+ */
+int mc_send_command(struct fsl_mc_io *mc_io, struct mc_command *cmd)
Quoted 9 lines

drivers/bus/fsl-mc/mc-sys.c line 235

Quoted 3 lines
drivers/bus/fsl-mc/mc-sys.c new file +3 -0
+{
+	enum mc_cmd_status status;
+	unsigned long irqsave_flags = 0;

drivers/bus/fsl-mc/mc-sys.c: In function ‘mc_send_command’:
drivers/bus/fsl-mc/mc-sys.c:235:16: warning: unused variable ‘irqsave_flags’ [-Wunused-variable]
unsigned long irqsave_flags = 0;

I'll fix this in the next respin.

Thanks,

German

                ^
Quoted 4 lines

Alex

#4 lore raw

Re: [PATCH 1/3 v4] drivers/bus: Added Freescale Management Complex APIs

In reply to J. German Rivera
Quoted 7 lines · J. German Rivera

APIs to access the Management Complex (MC) hardware module of Freescale LS2 SoCs. This patch includes APIs to check the MC firmware version and to manipulate DPRC objects in the MC.

[...]

Quoted 33 lines
drivers/bus/fsl-mc/dprc.c new file +27 -0
new file mode 100644
index 0000000..40ae552
@@ -0,0 +1,933 @@
+/* Copyright 2013-2014 Freescale Semiconductor Inc.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+* * Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+* * Redistributions in binary form must reproduce the above copyright
+* notice, this list of conditions and the following disclaimer in the
+* documentation and/or other materials provided with the distribution.
+* * Neither the name of the above-listed copyright holders nor the
+* names of any contributors may be used to endorse or promote products
+* derived from this software without specific prior written permission.
+*
+*
+* ALTERNATIVELY, this software may be distributed under the terms of the
+* GNU General Public License ("GPL") as published by the Free Software
+* Foundation, either version 2 of that License or (at your option) any
+* later version.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
+* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN

drivers/bus/fsl-mc/dprc.c line 37

Quoted 10 lines
drivers/bus/fsl-mc/dprc.c new file +10 -0
+* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+* POSSIBILITY OF SUCH DAMAGE.
+*/
+#include <linux/fsl/mc-sys.h>
+#include <linux/fsl/mc-cmd.h>
+#include <linux/fsl/dprc.h>
+#include "dprc-cmd.h"
+
+int dprc_get_container_id(struct fsl_mc_io *mc_io, int *container_id)

This one is definitely a misnomer. It's a command that operates on the MC object, not a DPRC object. Also it doesn't fetch a random "container_id", it fetches the root container id.

Please move it and its definition to the files that operate on the MC management interface.

Alex

#5 lore raw

Re: [PATCH 1/3 v4] drivers/bus: Added Freescale Management Complex APIs

Quoted 8 lines · Alexander Graf
Quoted 5 lines · J. German Rivera

APIs to access the Management Complex (MC) hardware module of Freescale LS2 SoCs. This patch includes APIs to check the MC firmware version and to manipulate DPRC objects in the MC.

Quoted 5 lines
Quoted 2 lines

[...]

[]

Quoted 10 lines

drivers/bus/fsl-mc/dprc.c line 37

Quoted 2 lines
drivers/bus/fsl-mc/dprc.c new file +2 -0
+
+int dprc_get_container_id(struct fsl_mc_io *mc_io, int *container_id)

This one is definitely a misnomer. It's a command that operates on the MC object, not a DPRC object. Also it doesn't fetch a random "container_id", it fetches the root container id.

Please move it and its definition to the files that operate on the MC management interface.

Ok, I will make this change in respin v5.

Thanks,

German

Quoted 3 lines

Alex

#6 lore raw

RE: [PATCH 1/3 v4] drivers/bus: Added Freescale Management Complex APIs

In reply to Alexander Graf
Quoted 62 lines

-----Original Message-----
From: Alexander Graf [mailto:[email protected]]
Sent: Wednesday, November 26, 2014 4:16 AM
To: Rivera Jose-B46482; [email protected]; [email protected]; [email protected]
Cc: Yoder Stuart-B08248; Phillips Kim-R1AAHA; Wood Scott-B07421; Hamciuc Bogdan-BHAMCIU1; Marginean Alexandru-R89243; Thorpe Geoff-R01361; Sharma Bhupesh-B45370; Erez Nir-RM30794; Schmitt Richard-B43082
Subject: Re: [PATCH 1/3 v4] drivers/bus: Added Freescale Management Complex APIs

Quoted 7 lines · J. German Rivera

APIs to access the Management Complex (MC) hardware module of Freescale LS2 SoCs. This patch includes APIs to check the MC firmware version and to manipulate DPRC objects in the MC.

[...]

Quoted 39 lines
drivers/bus/fsl-mc/dprc.c new file +33 -0
new file mode 100644
index 0000000..40ae552
@@ -0,0 +1,933 @@
+/* Copyright 2013-2014 Freescale Semiconductor Inc.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+* * Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+* * Redistributions in binary form must reproduce the above copyright
+* notice, this list of conditions and the following disclaimer in the
+* documentation and/or other materials provided with the distribution.
+* * Neither the name of the above-listed copyright holders nor the
+* names of any contributors may be used to endorse or promote products
+* derived from this software without specific prior written permission.
+*
+*
+* ALTERNATIVELY, this software may be distributed under the terms of the
+* GNU General Public License ("GPL") as published by the Free Software
+* Foundation, either version 2 of that License or (at your option) any
+* later version.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
+* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+* POSSIBILITY OF SUCH DAMAGE.
+*/
+#include <linux/fsl/mc-sys.h>
+#include <linux/fsl/mc-cmd.h>
Quoted 8 lines

drivers/bus/fsl-mc/dprc.c line 37

Quoted 4 lines
drivers/bus/fsl-mc/dprc.c new file +4 -0
+#include <linux/fsl/dprc.h>
+#include "dprc-cmd.h"
+
+int dprc_get_container_id(struct fsl_mc_io *mc_io, int *container_id)

This one is definitely a misnomer. It's a command that operates on the MC object, not a DPRC object. Also it doesn't fetch a random "container_id", it fetches the root container id.

It's not strictly the root container. It fetches the container/DPRC ID associated with the portal you are using. A virtual machine would use it to fetch it's container ID.

Quoted 2 lines

Please move it and its definition to the files that operate on the MC management interface.

Note, the binary interface opcode really is DPRC_CMDID_GET_CONT_ID.

We can request that the binary interface naming be changed, but wouldn't it be better to keep the functions separated by opcode type-- having DPRC_CMDID* opcode-based commands be in one file and DPMNG_CMDID* commands in a separate file?

We have already submitted a request to move this opcode to the DPMNG group.

Thanks,
Stuart

#7 lore raw

Re: [PATCH 1/3 v4] drivers/bus: Added Freescale Management Complex APIs

Quoted 71 lines · Stuart Yoder
Quoted 62 lines

-----Original Message-----
From: Alexander Graf [mailto:[email protected]]
Sent: Wednesday, November 26, 2014 4:16 AM
To: Rivera Jose-B46482; [email protected]; [email protected]; [email protected]
Cc: Yoder Stuart-B08248; Phillips Kim-R1AAHA; Wood Scott-B07421; Hamciuc Bogdan-BHAMCIU1; Marginean Alexandru-R89243; Thorpe Geoff-R01361; Sharma Bhupesh-B45370; Erez Nir-RM30794; Schmitt Richard-B43082
Subject: Re: [PATCH 1/3 v4] drivers/bus: Added Freescale Management Complex APIs

Quoted 7 lines · J. German Rivera

APIs to access the Management Complex (MC) hardware module of Freescale LS2 SoCs. This patch includes APIs to check the MC firmware version and to manipulate DPRC objects in the MC.

[...]

Quoted 39 lines
drivers/bus/fsl-mc/dprc.c new file +33 -0
new file mode 100644
index 0000000..40ae552
@@ -0,0 +1,933 @@
+/* Copyright 2013-2014 Freescale Semiconductor Inc.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+* * Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+* * Redistributions in binary form must reproduce the above copyright
+* notice, this list of conditions and the following disclaimer in the
+* documentation and/or other materials provided with the distribution.
+* * Neither the name of the above-listed copyright holders nor the
+* names of any contributors may be used to endorse or promote products
+* derived from this software without specific prior written permission.
+*
+*
+* ALTERNATIVELY, this software may be distributed under the terms of the
+* GNU General Public License ("GPL") as published by the Free Software
+* Foundation, either version 2 of that License or (at your option) any
+* later version.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
+* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+* POSSIBILITY OF SUCH DAMAGE.
+*/
+#include <linux/fsl/mc-sys.h>
+#include <linux/fsl/mc-cmd.h>
Quoted 8 lines

drivers/bus/fsl-mc/dprc.c line 37

Quoted 4 lines
drivers/bus/fsl-mc/dprc.c new file +4 -0
+#include <linux/fsl/dprc.h>
+#include "dprc-cmd.h"
+
+int dprc_get_container_id(struct fsl_mc_io *mc_io, int *container_id)

This one is definitely a misnomer. It's a command that operates on the MC object, not a DPRC object. Also it doesn't fetch a random "container_id", it fetches the root container id.

Quoted 3 lines

It's not strictly the root container. It fetches the container/DPRC ID associated with the portal you are using. A virtual machine would use it to fetch it's container ID.

So does every portal properly react to this call? Or do only container portals react to it?

In fact, what does make the initial portal special? Who reacts to DPMNG_CMDID_foo calls? Every DPRC or only the initial root?

Quoted 9 lines
Quoted 2 lines

Please move it and its definition to the files that operate on the MC management interface.

Note, the binary interface opcode really is DPRC_CMDID_GET_CONT_ID.

We can request that the binary interface naming be changed, but wouldn't it be better to keep the functions separated by opcode type-- having DPRC_CMDID* opcode-based commands be in one file and DPMNG_CMDID* commands in a separate file?

It really depends on what the semantics are. If this is a call that's only valid on the MC root, then it should belong there. If it's available on every container portal, it should be part of dprc of course.

Alex

#8 lore raw

RE: [PATCH 1/3 v4] drivers/bus: Added Freescale Management Complex APIs

Quoted 11 lines
Quoted 9 lines
Quoted 5 lines
Quoted 1 line

+int dprc_get_container_id(struct fsl_mc_io *mc_io, int *container_id)

This one is definitely a misnomer. It's a command that operates on the MC object, not a DPRC object. Also it doesn't fetch a random "container_id", it fetches the root container id.

It's not strictly the root container. It fetches the container/DPRC ID associated with the portal you are using. A virtual machine would use it to fetch it's container ID.

So does every portal properly react to this call?

Yes, they should.

Quoted 2 lines

Or do only container
portals react to it?

Every portal is associated with some contianer-- either built into the container/DPRC object, or in a container/DPRC.

Quoted 1 line

In fact, what does make the initial portal special?

Nothing...it has the same semantics as any other portal.

Quoted 2 lines

Who reacts to
DPMNG_CMDID_foo calls? Every DPRC or only the initial root?

All portals. It just means 'what container am I in?'

Quoted 5 lines
Quoted 5 lines
Quoted 2 lines

Please move it and its definition to the files that operate on the MC management interface.

Note, the binary interface opcode really is DPRC_CMDID_GET_CONT_ID.

Quoted 8 lines
Quoted 4 lines

We can request that the binary interface naming be changed, but wouldn't it be better to keep the functions separated by opcode type-- having DPRC_CMDID* opcode-based commands be in one file and DPMNG_CMDID* commands in a separate file?

It really depends on what the semantics are. If this is a call that's only valid on the MC root, then it should belong there. If it's available on every container portal, it should be part of dprc of course.

It is valid on any portal, including container portals. For that reason, I do think it may make sense for it to be a DPMNG* command. But, I would say leave the files implementing the opcode groupings alone until the MC architecture is changed.

Stuart

#9 lore raw

Re: [PATCH 1/3 v4] drivers/bus: Added Freescale Management Complex APIs

In reply to J. German Rivera
Quoted 7 lines · J. German Rivera

APIs to access the Management Complex (MC) hardware module of Freescale LS2 SoCs. This patch includes APIs to check the MC firmware version and to manipulate DPRC objects in the MC.

[...]

include/linux/fsl/dprc.h line 662

Quoted 6 lines
include/linux/fsl/dprc.h new file +6 -0
+/*
+ * Object descriptor, returned from dprc_get_obj()
+ */
+struct dprc_obj_desc {
+	/* Type of object: NULL terminated string */
+	char type[16];

I don't see where it actually gets NULL terminated - all 16 bytes come directly from the device.

While it's probably ok to trust it, I think we'd still be safer off if we just make this a char[17] array to always have our NULL terminating string. That way we're guaranteed we'll never run over our memory boundaries.

Also sorry for the slowly trickling in comments - I'm just noting things as I dig through the whole interface :).

Alex

#10 lore raw

RE: [PATCH 1/3 v4] drivers/bus: Added Freescale Management Complex APIs

Quoted 33 lines

-----Original Message-----
From: Alexander Graf [mailto:[email protected]]
Sent: Thursday, November 27, 2014 8:30 AM
To: Rivera Jose-B46482; [email protected]; [email protected]; [email protected]
Cc: Yoder Stuart-B08248; Phillips Kim-R1AAHA; Wood Scott-B07421; Hamciuc Bogdan-BHAMCIU1; Marginean Alexandru-R89243; Thorpe Geoff-R01361; Sharma Bhupesh-B45370; Erez Nir-RM30794; Schmitt Richard-B43082
Subject: Re: [PATCH 1/3 v4] drivers/bus: Added Freescale Management Complex APIs

Quoted 7 lines · J. German Rivera

APIs to access the Management Complex (MC) hardware module of Freescale LS2 SoCs. This patch includes APIs to check the MC firmware version and to manipulate DPRC objects in the MC.

[...]

include/linux/fsl/dprc.h line 662

Quoted 6 lines
include/linux/fsl/dprc.h new file +6 -0
+/*
+ * Object descriptor, returned from dprc_get_obj()
+ */
+struct dprc_obj_desc {
+	/* Type of object: NULL terminated string */
+	char type[16];

I don't see where it actually gets NULL terminated - all 16 bytes come directly from the device.

Quoted 4 lines

While it's probably ok to trust it, I think we'd still be safer off if we just make this a char[17] array to always have our NULL terminating string. That way we're guaranteed we'll never run over our memory boundaries.

The device is supposed to guarantee that the string is null terminated...so there will never be valid chars in the 16th character. So, what about just forcing type[15] = '\0'?

I think that would be better than making it a char[17].

Stuart

#11 lore raw

Re: [PATCH 1/3 v4] drivers/bus: Added Freescale Management Complex APIs

Quoted 38 lines · Stuart Yoder
Quoted 33 lines

-----Original Message-----
From: Alexander Graf [mailto:[email protected]]
Sent: Thursday, November 27, 2014 8:30 AM
To: Rivera Jose-B46482; [email protected]; [email protected]; [email protected]
Cc: Yoder Stuart-B08248; Phillips Kim-R1AAHA; Wood Scott-B07421; Hamciuc Bogdan-BHAMCIU1; Marginean Alexandru-R89243; Thorpe Geoff-R01361; Sharma Bhupesh-B45370; Erez Nir-RM30794; Schmitt Richard-B43082
Subject: Re: [PATCH 1/3 v4] drivers/bus: Added Freescale Management Complex APIs

Quoted 7 lines · J. German Rivera

APIs to access the Management Complex (MC) hardware module of Freescale LS2 SoCs. This patch includes APIs to check the MC firmware version and to manipulate DPRC objects in the MC.

[...]

include/linux/fsl/dprc.h line 662

Quoted 6 lines
include/linux/fsl/dprc.h new file +6 -0
+/*
+ * Object descriptor, returned from dprc_get_obj()
+ */
+struct dprc_obj_desc {
+	/* Type of object: NULL terminated string */
+	char type[16];

I don't see where it actually gets NULL terminated - all 16 bytes come directly from the device.

Quoted 4 lines

While it's probably ok to trust it, I think we'd still be safer off if we just make this a char[17] array to always have our NULL terminating string. That way we're guaranteed we'll never run over our memory boundaries.

Quoted 5 lines

The device is supposed to guarantee that the string is null terminated...so there will never be valid chars in the 16th character. So, what about just forcing type[15] = '\0'?

I think that would be better than making it a char[17].

Sure, that works too.

Alex

#12 lore raw

Re: [PATCH 1/3 v4] drivers/bus: Added Freescale Management Complex APIs

In reply to J. German Rivera
Quoted 7 lines · J. German Rivera

APIs to access the Management Complex (MC) hardware module of Freescale LS2 SoCs. This patch includes APIs to check the MC firmware version and to manipulate DPRC objects in the MC.

[...]

Quoted 32 lines
drivers/bus/fsl-mc/mc-sys.c new file +32 -0
+/**
+ * Creates an MC I/O object
+ *
+ * @dev: device to be associated with the MC I/O object
+ * @mc_portal_phys_addr: physical address of the MC portal to use
+ * @mc_portal_size: size in bytes of the MC portal
+ * @flags: flags for the new MC I/O object
+ * @new_mc_io: Area to return pointer to newly created MC I/O object
+ *
+ * Returns '0' on Success; Error code otherwise.
+ */
+int __must_check fsl_create_mc_io(struct device *dev,
+				  phys_addr_t mc_portal_phys_addr,
+				  uint32_t mc_portal_size,
+				  uint32_t flags, struct fsl_mc_io **new_mc_io)
+{
+	struct fsl_mc_io *mc_io;
+	void __iomem *mc_portal_virt_addr;
+	struct resource *res;
+
+	mc_io = devm_kzalloc(dev, sizeof(*mc_io), GFP_KERNEL);
+	if (mc_io == NULL)
+		return -ENOMEM;
+
+	mc_io->dev = dev;
+	mc_io->flags = flags;
+	mc_io->portal_phys_addr = mc_portal_phys_addr;
+	mc_io->portal_size = mc_portal_size;
+	res = devm_request_mem_region(dev,
+				      mc_portal_phys_addr,
+				      mc_portal_size,
+				      "mc_portal");

drivers/bus/fsl-mc/mc-sys.c line 98

Quoted 10 lines
drivers/bus/fsl-mc/mc-sys.c new file +10 -0
+	if (res == NULL) {
+		dev_err(dev,
+			"devm_request_mem_region failed for MC portal %#llx\n",
+			mc_portal_phys_addr);
+		return -EBUSY;
+	}
+
+	mc_portal_virt_addr = devm_ioremap_nocache(dev,
+						   mc_portal_phys_addr,
+						   mc_portal_size);

While I can't complain about the device itself, I will note that I think it's a pretty bad design decision to expose actual host physical addresses in the protocol.

Basically this means that you won't be able to pass a full MC complex into a guest, even if you could virtualize IRQ and DMA access unless you map it at the exact same location as the host's MC complex.

Could we at least add a "ranges" property to the MC device description and check whether the physical addresses we get are within that range - if nothing else, at least as sanity check? Then maybe add some calls in the next version that act on that range rather than actual host physical addresses?

Alex

#13 lore raw

RE: [PATCH 1/3 v4] drivers/bus: Added Freescale Management Complex APIs

Quoted 61 lines

-----Original Message-----
From: Alexander Graf [mailto:[email protected]]
Sent: Thursday, November 27, 2014 10:14 AM
To: Rivera Jose-B46482; [email protected]; [email protected]; [email protected]
Cc: Yoder Stuart-B08248; Phillips Kim-R1AAHA; Wood Scott-B07421; Hamciuc Bogdan-BHAMCIU1; Marginean Alexandru-R89243; Thorpe Geoff-R01361; Sharma Bhupesh-B45370; Erez Nir-RM30794; Schmitt Richard-B43082
Subject: Re: [PATCH 1/3 v4] drivers/bus: Added Freescale Management Complex APIs

Quoted 7 lines · J. German Rivera

APIs to access the Management Complex (MC) hardware module of Freescale LS2 SoCs. This patch includes APIs to check the MC firmware version and to manipulate DPRC objects in the MC.

[...]

Quoted 38 lines
drivers/bus/fsl-mc/mc-sys.c new file +38 -0
+/**
+ * Creates an MC I/O object
+ *
+ * @dev: device to be associated with the MC I/O object
+ * @mc_portal_phys_addr: physical address of the MC portal to use
+ * @mc_portal_size: size in bytes of the MC portal
+ * @flags: flags for the new MC I/O object
+ * @new_mc_io: Area to return pointer to newly created MC I/O object
+ *
+ * Returns '0' on Success; Error code otherwise.
+ */
+int __must_check fsl_create_mc_io(struct device *dev,
+				  phys_addr_t mc_portal_phys_addr,
+				  uint32_t mc_portal_size,
+				  uint32_t flags, struct fsl_mc_io **new_mc_io)
+{
+	struct fsl_mc_io *mc_io;
+	void __iomem *mc_portal_virt_addr;
+	struct resource *res;
+
+	mc_io = devm_kzalloc(dev, sizeof(*mc_io), GFP_KERNEL);
+	if (mc_io == NULL)
+		return -ENOMEM;
+
+	mc_io->dev = dev;
+	mc_io->flags = flags;
+	mc_io->portal_phys_addr = mc_portal_phys_addr;
+	mc_io->portal_size = mc_portal_size;
+	res = devm_request_mem_region(dev,
+				      mc_portal_phys_addr,
+				      mc_portal_size,
+				      "mc_portal");
+	if (res == NULL) {
+		dev_err(dev,
+			"devm_request_mem_region failed for MC portal %#llx\n",
+			mc_portal_phys_addr);
+		return -EBUSY;
+	}
Quoted 8 lines

drivers/bus/fsl-mc/mc-sys.c line 98

Quoted 4 lines
drivers/bus/fsl-mc/mc-sys.c new file +4 -0
+
+	mc_portal_virt_addr = devm_ioremap_nocache(dev,
+						   mc_portal_phys_addr,
+						   mc_portal_size);

While I can't complain about the device itself, I will note that I think it's a pretty bad design decision to expose actual host physical addresses in the protocol.

I tend to agree. I'll look into creating a proposed change to the architecture to have the MC communicate a physical offset of some kind.

Quoted 3 lines

Basically this means that you won't be able to pass a full MC complex into a guest, even if you could virtualize IRQ and DMA access unless you map it at the exact same location as the host's MC complex.

Right. But is that really an issue in practice?

Quoted 5 lines

Could we at least add a "ranges" property to the MC device description and check whether the physical addresses we get are within that range - if nothing else, at least as sanity check? Then maybe add some calls in the next version that act on that range rather than actual host physical addresses?

So you mean something like:

        fsl_mc: fsl-mc@80c000000 {
                compatible = "fsl,qoriq-mc";
                #stream-id-cells = <2>;
                reg = <0x00000008 0x0c000000 0 0x40>,    /* MC portal base */
                      <0x00000000 0x08340000 0 0x40000>; /* MC control reg */
                ranges = <0x8 0x0 0x8 0x0 0x20000000>;
                lpi-parent = <&its>;
        };

The physical addresses returned by the MC fall into a 512MB "portal" region at 0x8_0000_0000 in the physical address map. For now map it 1:1, but in the future it could become:

                   ranges = <0x0 0x0 0x8 0x0 0x20000000>;

...if I can get the hardware architecture changed.

Stuart

#14 lore raw

Re: [PATCH 1/3 v4] drivers/bus: Added Freescale Management Complex APIs

Quoted 70 lines · Stuart Yoder
Quoted 61 lines

-----Original Message-----
From: Alexander Graf [mailto:[email protected]]
Sent: Thursday, November 27, 2014 10:14 AM
To: Rivera Jose-B46482; [email protected]; [email protected]; [email protected]
Cc: Yoder Stuart-B08248; Phillips Kim-R1AAHA; Wood Scott-B07421; Hamciuc Bogdan-BHAMCIU1; Marginean Alexandru-R89243; Thorpe Geoff-R01361; Sharma Bhupesh-B45370; Erez Nir-RM30794; Schmitt Richard-B43082
Subject: Re: [PATCH 1/3 v4] drivers/bus: Added Freescale Management Complex APIs

Quoted 7 lines · J. German Rivera

APIs to access the Management Complex (MC) hardware module of Freescale LS2 SoCs. This patch includes APIs to check the MC firmware version and to manipulate DPRC objects in the MC.

[...]

Quoted 38 lines
drivers/bus/fsl-mc/mc-sys.c new file +38 -0
+/**
+ * Creates an MC I/O object
+ *
+ * @dev: device to be associated with the MC I/O object
+ * @mc_portal_phys_addr: physical address of the MC portal to use
+ * @mc_portal_size: size in bytes of the MC portal
+ * @flags: flags for the new MC I/O object
+ * @new_mc_io: Area to return pointer to newly created MC I/O object
+ *
+ * Returns '0' on Success; Error code otherwise.
+ */
+int __must_check fsl_create_mc_io(struct device *dev,
+				  phys_addr_t mc_portal_phys_addr,
+				  uint32_t mc_portal_size,
+				  uint32_t flags, struct fsl_mc_io **new_mc_io)
+{
+	struct fsl_mc_io *mc_io;
+	void __iomem *mc_portal_virt_addr;
+	struct resource *res;
+
+	mc_io = devm_kzalloc(dev, sizeof(*mc_io), GFP_KERNEL);
+	if (mc_io == NULL)
+		return -ENOMEM;
+
+	mc_io->dev = dev;
+	mc_io->flags = flags;
+	mc_io->portal_phys_addr = mc_portal_phys_addr;
+	mc_io->portal_size = mc_portal_size;
+	res = devm_request_mem_region(dev,
+				      mc_portal_phys_addr,
+				      mc_portal_size,
+				      "mc_portal");
+	if (res == NULL) {
+		dev_err(dev,
+			"devm_request_mem_region failed for MC portal %#llx\n",
+			mc_portal_phys_addr);
+		return -EBUSY;
+	}
Quoted 8 lines

drivers/bus/fsl-mc/mc-sys.c line 98

Quoted 4 lines
drivers/bus/fsl-mc/mc-sys.c new file +4 -0
+
+	mc_portal_virt_addr = devm_ioremap_nocache(dev,
+						   mc_portal_phys_addr,
+						   mc_portal_size);

While I can't complain about the device itself, I will note that I think it's a pretty bad design decision to expose actual host physical addresses in the protocol.

Quoted 8 lines

I tend to agree. I'll look into creating a proposed change to the architecture to have the MC communicate a physical offset of some kind.

Quoted 3 lines

Basically this means that you won't be able to pass a full MC complex into a guest, even if you could virtualize IRQ and DMA access unless you map it at the exact same location as the host's MC complex.

Right. But is that really an issue in practice?

Well, it obviously depends on what you're trying to do. For everything that's envisioned today I don't think it's a problem, but I like to stick to the "know as little as you have to know" rule when it comes to communication protocols.

Quoted 17 lines
Quoted 5 lines

Could we at least add a "ranges" property to the MC device description and check whether the physical addresses we get are within that range - if nothing else, at least as sanity check? Then maybe add some calls in the next version that act on that range rather than actual host physical addresses?

So you mean something like:

        fsl_mc: fsl-mc@80c000000 {
                compatible = "fsl,qoriq-mc";
                #stream-id-cells = <2>;
                reg = <0x00000008 0x0c000000 0 0x40>,    /* MC portal base */
                      <0x00000000 0x08340000 0 0x40000>; /* MC control reg */
                ranges = <0x8 0x0 0x8 0x0 0x20000000>;
                lpi-parent = <&its>;
        };
Quoted 6 lines

The physical addresses returned by the MC fall into a 512MB "portal" region at 0x8_0000_0000 in the physical address map. For now map it 1:1, but in the future it could become:

                   ranges = <0x0 0x0 0x8 0x0 0x20000000>;

...if I can get the hardware architecture changed.

Yup, I think that makes things a lot less error prone - you don't randomly access any pointer the device tells you to access :).

Alex

#15 lore raw

PATCH v4 2/3 drivers/bus: Freescale Management Complex (fsl-mc) bus driver

In reply to J. German Rivera

Platform device driver that sets up the basic bus infrastructure for the fsl-mc bus type, including support for adding/removing fsl-mc devices, register/unregister of fsl-mc drivers, and bus match support to bind devices to drivers.

---
Changes addressed in v4:
- Addressed comments from Alex Graf:
* Added missing scope limitations and more descriptive help text for the FSL_MC_BUS config option.
- Fixed bug related to setting fsl_mc_bus_type.dev_root too late.

Changes in v3:
- Addressed changes from Kim Phillips:
* Renamed files:

	drivers/bus/fsl-mc/fsl_mc_bus.c -> drivers/bus/fsl-mc/mc-bus.c
	include/linux/fsl_mc.h -> include/linux/fsl/mc.h
	include/linux/fsl_mc_private.h -> include/linux/fsl/mc-private.h

- Addressed comments from Timur Tabi:
* Changed all functions that had goto out/error when no common cleanup was done, to just have multiple return points.
* Replaced error cleanup boolean flags with multiple exit points.

Changes in v2:
- Addressed comment from Joe Perches:
* Changed pr_debug to dev_dbg in fsl_mc_bus_match

- Addressed comments from Kim Phillips and Alex Graf:
* Changed version check to allow the driver to run with MC firmware that has major version number greater than or equal to the driver's major version number.
* Removed minor version check

- Removed unused variable parent_dev in fsl_mc_device_remove

 drivers/bus/Kconfig            |   3 +
 drivers/bus/Makefile           |   3 +
 drivers/bus/fsl-mc/Kconfig     |  24 ++
 drivers/bus/fsl-mc/Makefile    |  14 +
 drivers/bus/fsl-mc/mc-bus.c    | 573 +++++++++++++++++++++++++++++++++++++++++
 include/linux/fsl/mc-private.h |  33 +++
 include/linux/fsl/mc.h         | 137 ++++++++++
 7 files changed, 787 insertions(+)
 create mode 100644 drivers/bus/fsl-mc/Kconfig
 create mode 100644 drivers/bus/fsl-mc/Makefile
 create mode 100644 drivers/bus/fsl-mc/mc-bus.c
 create mode 100644 include/linux/fsl/mc-private.h
 create mode 100644 include/linux/fsl/mc.h
drivers/bus/Kconfig +3 -0
index 603eb1b..2fbb1fd 100644
@@ -67,4 +67,7 @@ config VEXPRESS_CONFIG
 	help
 	  Platform configuration infrastructure for the ARM Ltd.
 	  Versatile Express.
+
+source "drivers/bus/fsl-mc/Kconfig"
+
 endmenu
drivers/bus/Makefile +3 -0
index 2973c18..6abcab1 100644
@@ -15,3 +15,6 @@ obj-$(CONFIG_ARM_CCI)		+= arm-cci.o
 obj-$(CONFIG_ARM_CCN)		+= arm-ccn.o
 
 obj-$(CONFIG_VEXPRESS_CONFIG)	+= vexpress-config.o
+
+# Freescale Management Complex (MC) bus drivers
+obj-$(CONFIG_FSL_MC_BUS)	+= fsl-mc/
drivers/bus/fsl-mc/Kconfig new file +24 -0
new file mode 100644
index 0000000..0d779d9
@@ -0,0 +1,24 @@
+#
+# Freescale Management Complex (MC) bus drivers
+#
+# Copyright (C) 2014 Freescale Semiconductor, Inc.
+#
+# This file is released under the GPLv2
+#
+
+config FSL_MC_BUS
+	tristate "Freescale Management Complex (MC) bus driver"
+	depends on OF && ARM64
+	help
+	  Driver to enable the bus infrastructure for the Freescale
+          QorIQ Management Complex (fsl-mc). The fsl-mc is a hardware
+	  module of the QorIQ LS2 SoCs, that does resource management
+	  for hardware building-blocks in the SoC that can be used
+	  to dynamically create networking hardware objects such as
+	  network interfaces (NICs), crypto accelerator instances,
+	  or L2 switches.
+
+	  Only enable this option when building the kernel for
+	  Freescale QorQIQ LS2xxxx SoCs.
+
+
drivers/bus/fsl-mc/Makefile new file +14 -0
new file mode 100644
index 0000000..decd339
@@ -0,0 +1,14 @@
+#
+# Freescale Management Complex (MC) bus drivers
+#
+# Copyright (C) 2014 Freescale Semiconductor, Inc.
+#
+# This file is released under the GPLv2
+#
+obj-$(CONFIG_FSL_MC_BUS) += mc-bus-driver.o
+
+mc-bus-driver-objs := mc-bus.o \
+		      mc-sys.o \
+		      dprc.o \
+		      dpmng.o
+
drivers/bus/fsl-mc/mc-bus.c new file +573 -0

573 lines not on this page · raw message

include/linux/fsl/mc-private.h new file +33 -0
new file mode 100644
index 0000000..604832a
@@ -0,0 +1,33 @@
+/*
+ * Freescale Management Complex (MC) bus private declarations
+ *
+ * Copyright (C) 2014 Freescale Semiconductor, Inc.
+ * Author: German Rivera <[email protected]>
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2. This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+#ifndef _FSL_MC_PRIVATE_H_
+#define _FSL_MC_PRIVATE_H_
+
+#include <linux/fsl/mc.h>
+#include <linux/mutex.h>
+#include <linux/stringify.h>
+
+#define FSL_MC_DEVICE_MATCH(_mc_dev, _obj_desc) \
+	(strcmp((_mc_dev)->obj_desc.type, (_obj_desc)->type) == 0 && \
+	 (_mc_dev)->obj_desc.id == (_obj_desc)->id)
+
+#define FSL_MC_IS_ALLOCATABLE(_obj_type) \
+	(strcmp(_obj_type, "dpbp") == 0 || \
+	 strcmp(_obj_type, "dpcon") == 0)
+
+int __must_check fsl_mc_device_add(struct dprc_obj_desc *obj_desc,
+				   struct fsl_mc_io *mc_io,
+				   struct device *parent_dev,
+				   struct fsl_mc_device **new_mc_dev);
+
+void fsl_mc_device_remove(struct fsl_mc_device *mc_dev);
+
+#endif /* _FSL_MC_PRIVATE_H_ */
include/linux/fsl/mc.h new file +137 -0

137 lines not on this page · raw message

--
2.1.2

#16 lore raw

PATCH v4 3/3 drivers/bus: Device driver for FSL-MC DPRC devices

In reply to J. German Rivera

A DPRC (Data Path Resource Container) is an isolation device that contains a set of DPAA networking devices to be assigned to an isolation domain (e.g., a virtual machine).

---
Changes addressed in v4:
- Addressed comments from Alex Graf:
* Fixed typo in comment

Changes in v3:
- Addressed comments from Kim Phillips:
* Renamed files:

    drivers/bus/fsl-mc/fsl_mc_dprc.c -> drivers/bus/fsl-mc/dprc-driver.c

- Addressed comments from Timur Tabi:
* Changed dprc_scan_container() to just return dprc_scan_objects()
* Changed all functions that had goto out/error when no common cleanup was done, to just have multiple return points.
* Replaced error cleanup boolean flags with multiple exit points.
* REmoved __must_chewck from dprc_scan_*() functions

Changes in v2:
- Addressed comments from Kim Phillips:
* Fix warning in drivers/bus/fsl-mc/fsl_mc_dprc.c:173
* Fixed linker errors when MC bus driver built as module

 drivers/bus/fsl-mc/Makefile      |   3 +-
 drivers/bus/fsl-mc/dprc-driver.c | 383 +++++++++++++++++++++++++++++++++++++++
 drivers/bus/fsl-mc/mc-bus.c      |   8 +
 include/linux/fsl/mc-private.h   |  10 +
 4 files changed, 403 insertions(+), 1 deletion(-)
 create mode 100644 drivers/bus/fsl-mc/dprc-driver.c
drivers/bus/fsl-mc/Makefile +2 -1
index decd339..424e58e 100644
@@ -10,5 +10,6 @@ obj-$(CONFIG_FSL_MC_BUS) += mc-bus-driver.o
 mc-bus-driver-objs := mc-bus.o \
 		      mc-sys.o \
 		      dprc.o \
-		      dpmng.o
+		      dpmng.o \
+		      dprc-driver.o
 
drivers/bus/fsl-mc/dprc-driver.c new file +383 -0

383 lines not on this page · raw message

drivers/bus/fsl-mc/mc-bus.c +8 -0
index 01d9f09..7e28767 100644
@@ -543,8 +543,15 @@ static int __init fsl_mc_bus_driver_init(void)
 		goto error_cleanup_bus;
 	}
 
+	error = dprc_driver_init();
+	if (error < 0)
+		goto error_cleanup_driver;
+
 	return 0;
 
+error_cleanup_driver:
+	platform_driver_unregister(&fsl_mc_bus_driver);
+
 error_cleanup_bus:
 	bus_unregister(&fsl_mc_bus_type);
 
@@ -560,6 +567,7 @@ static void __exit fsl_mc_bus_driver_exit(void)
 	if (WARN_ON(mc_dev_cache == NULL))
 		return;
 
+	dprc_driver_exit();
 	platform_driver_unregister(&fsl_mc_bus_driver);
 	bus_unregister(&fsl_mc_bus_type);
 	kmem_cache_destroy(mc_dev_cache);
include/linux/fsl/mc-private.h +10 -0
index 604832a..431a0b1 100644
@@ -15,6 +15,8 @@
 #include <linux/mutex.h>
 #include <linux/stringify.h>
 
+#define FSL_MC_DPRC_DRIVER_NAME    "fsl_mc_dprc"
+
 #define FSL_MC_DEVICE_MATCH(_mc_dev, _obj_desc) \
 	(strcmp((_mc_dev)->obj_desc.type, (_obj_desc)->type) == 0 && \
 	 (_mc_dev)->obj_desc.id == (_obj_desc)->id)
@@ -30,4 +32,12 @@ int __must_check fsl_mc_device_add(struct dprc_obj_desc *obj_desc,
 
 void fsl_mc_device_remove(struct fsl_mc_device *mc_dev);
 
+int dprc_scan_container(struct fsl_mc_device *mc_bus_dev);
+
+int dprc_scan_objects(struct fsl_mc_device *mc_bus_dev);
+
+int __init dprc_driver_init(void);
+
+void __exit dprc_driver_exit(void);
+
 #endif /* _FSL_MC_PRIVATE_H_ */

--
2.1.2