Skip to contentSkip to conversation

drivers/bus: Freescale Management Complex bus driver patch series

RFC PATCH Superseded J. German Rivera 2 participants 10 messages Aug 15, 2014 – Aug 23, 2014 QorIQ DPAA2 fsl-mc bus driver

v1 of 9 Superseded Latest is v9 →

lore
Share & tools
lore
#0 lore raw

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

This patch series introduces Linux support for the Freescale Management Complex (fsl-mc) hardware.

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 poools, 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.

Patch 4 contains the update to the MAINTAINERS file.

#1 lore raw

RFC PATCH 1/4 drivers/bus: Added Freescale Management Complex APIs

From: "J. German Rivera" <[email protected]>

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.

---
 drivers/bus/fsl-mc/dpmng.c         |   93 +++++
 drivers/bus/fsl-mc/dprc.c          |  504 +++++++++++++++++++++++
 drivers/bus/fsl-mc/fsl_dpmng_cmd.h |   83 ++++
 drivers/bus/fsl-mc/fsl_dprc_cmd.h  |  545 +++++++++++++++++++++++++
 drivers/bus/fsl-mc/mc_sys.c        |  207 ++++++++++
 include/linux/fsl_dpmng.h          |  120 ++++++
 include/linux/fsl_dprc.h           |  790 ++++++++++++++++++++++++++++++++++++
 include/linux/fsl_mc_cmd.h         |  182 +++++++++
 include/linux/fsl_mc_sys.h         |   50 +++
 9 files changed, 2574 insertions(+)
 create mode 100644 drivers/bus/fsl-mc/dpmng.c
 create mode 100644 drivers/bus/fsl-mc/dprc.c
 create mode 100644 drivers/bus/fsl-mc/fsl_dpmng_cmd.h
 create mode 100644 drivers/bus/fsl-mc/fsl_dprc_cmd.h
 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
drivers/bus/fsl-mc/dpmng.c new file +93 -0
new file mode 100644
index 0000000..c6ed27c
@@ -0,0 +1,93 @@
+/* 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 Freescale Semiconductor nor the
+ *       names of its 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 Freescale Semiconductor ``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 Freescale Semiconductor 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>
+#include <linux/fsl_dpmng.h>
+#include "fsl_dpmng_cmd.h"
+
+int mc_get_version(struct fsl_mc_io *mc_io, struct mc_version *mc_ver_info)
+{
+	struct mc_command cmd = { 0 };
+	int err;
+
+	cmd.header = mc_encode_cmd_header(DPMNG_CMDID_GET_VERSION,
+					  DPMNG_CMDSZ_GET_VERSION,
+					  MC_CMD_PRI_LOW, 0);
+
+	err = mc_send_command(mc_io, &cmd);
+	if (!err)
+		DPMNG_RSP_GET_VERSION(cmd, mc_ver_info);
+
+	return err;
+}
+
+int dpmng_reset_aiop(struct fsl_mc_io *mc_io, int aiop_tile_id)
+{
+	struct mc_command cmd = { 0 };
+
+	cmd.header = mc_encode_cmd_header(DPMNG_CMDID_RESET_AIOP,
+					  DPMNG_CMDSZ_RESET_AIOP,
+					  MC_CMD_PRI_LOW, 0);
+
+	DPMNG_CMD_RESET_AIOP(cmd, aiop_tile_id);
+
+	return mc_send_command(mc_io, &cmd);
+}
+
+int dpmng_load_aiop(struct fsl_mc_io *mc_io,
+		    int aiop_tile_id, uint8_t *img_addr, int img_size)
+{
+	struct mc_command cmd = { 0 };
+	uint64_t img_paddr = virt_to_phys(img_addr);
+
+	cmd.header = mc_encode_cmd_header(DPMNG_CMDID_LOAD_AIOP,
+					  DPMNG_CMDSZ_LOAD_AIOP,
+					  MC_CMD_PRI_LOW, 0);
+
+	DPMNG_CMD_LOAD_AIOP(cmd, aiop_tile_id, img_size, img_paddr);
+
+	return mc_send_command(mc_io, &cmd);
+}
+
+int dpmng_run_aiop(struct fsl_mc_io *mc_io,
+		   int aiop_tile_id, uint32_t cores_mask, uint64_t options)
+{
+	struct mc_command cmd = { 0 };
+
+	cmd.header = mc_encode_cmd_header(DPMNG_CMDID_RUN_AIOP,
+					  DPMNG_CMDSZ_RUN_AIOP,
+					  MC_CMD_PRI_LOW, 0);
+
+	DPMNG_CMD_RUN_AIOP(cmd, aiop_tile_id, cores_mask, options);
+
+	return mc_send_command(mc_io, &cmd);
+}
drivers/bus/fsl-mc/dprc.c new file +504 -0

504 lines not on this page · raw message

drivers/bus/fsl-mc/fsl_dpmng_cmd.h new file +83 -0

83 lines not on this page · raw message

drivers/bus/fsl-mc/fsl_dprc_cmd.h new file +545 -0

545 lines not on this page · raw message

drivers/bus/fsl-mc/mc_sys.c new file +207 -0

207 lines not on this page · raw message

include/linux/fsl_dpmng.h new file +120 -0

120 lines not on this page · raw message

include/linux/fsl_dprc.h new file +790 -0

790 lines not on this page · raw message

include/linux/fsl_mc_cmd.h new file +182 -0

182 lines not on this page · raw message

include/linux/fsl_mc_sys.h new file +50 -0

50 lines not on this page · raw message

--
1.7.9.7

#2 lore raw

RFC PATCH 2/4 drivers/bus: Freescale Management Complex (fsl-mc) bus driver

In reply to J. German Rivera

From: "J. German Rivera" <[email protected]>

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.

---
 drivers/bus/Kconfig             |    3 +
 drivers/bus/Makefile            |    3 +
 drivers/bus/fsl-mc/Kconfig      |   13 +
 drivers/bus/fsl-mc/Makefile     |   14 +
 drivers/bus/fsl-mc/fsl_mc_bus.c |  734 +++++++++++++++++++++++++++++++++++++++
 include/linux/fsl_mc.h          |  177 ++++++++++
 include/linux/fsl_mc_private.h  |   85 +++++
 7 files changed, 1029 insertions(+)
 create mode 100644 drivers/bus/fsl-mc/Kconfig
 create mode 100644 drivers/bus/fsl-mc/Makefile
 create mode 100644 drivers/bus/fsl-mc/fsl_mc_bus.c
 create mode 100644 include/linux/fsl_mc.h
 create mode 100644 include/linux/fsl_mc_private.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 +13 -0
new file mode 100644
index 0000000..e3226f9
@@ -0,0 +1,13 @@
+#
+# 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"
+	help
+	  Driver to enable the bus infrastructure for the Freescale
+          QorIQ Management Complex.
drivers/bus/fsl-mc/Makefile new file +14 -0
new file mode 100644
index 0000000..f5f9033
@@ -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) += fsl_mc_bus_driver.o
+
+fsl_mc_bus_driver-objs := fsl_mc_bus.o \
+			      mc_sys.o \
+			      dprc.o \
+			      dpmng.o
+
drivers/bus/fsl-mc/fsl_mc_bus.c new file +734 -0

734 lines not on this page · raw message

include/linux/fsl_mc.h new file +177 -0

177 lines not on this page · raw message

include/linux/fsl_mc_private.h new file +85 -0

85 lines not on this page · raw message

--
1.7.9.7

#3 lore raw

Re: [RFC PATCH 2/4] drivers/bus: Freescale Management Complex (fsl-mc) bus driver

drivers/bus/fsl-mc/fsl_mc_bus.c line 23

Quoted 2 lines · On Friday 15 August 2014 17:13:12 J. German Rivera wrote:
drivers/bus/fsl-mc/fsl_mc_bus.c new file +2 -0
+struct fsl_mc_bus *fsl_mc_bus;
+EXPORT_SYMBOL(fsl_mc_bus);

This does not look like something that should be exported. Or even better, kill this structure entirely and just pass around pointers to the fsl_mc_device so you can deal with multiple root instances.

Quoted 11 lines
drivers/bus/fsl-mc/fsl_mc_bus.c new file +11 -0
+static struct kmem_cache *mc_dev_cache;
+
+/**
+ * fsl_mc_bus_match - device to driver matching callback
+ * @dev: the MC object device structure to match against
+ * @drv: the device driver to search for matching MC object device id
+ * structures
+ *
+ * Returns 1 on success, 0 otherwise.
+ */
+static int fsl_mc_bus_match(struct device *dev, struct device_driver *drv)

drivers/bus/fsl-mc/fsl_mc_bus.c line 45

Quoted 10 lines
drivers/bus/fsl-mc/fsl_mc_bus.c new file +10 -0
+{
+	const struct fsl_mc_device_match_id *id;
+	struct fsl_mc_device *mc_dev = to_fsl_mc_device(dev);
+	struct fsl_mc_driver *mc_drv = to_fsl_mc_driver(drv);
+	bool found = false;
+
+	if (WARN_ON(mc_dev->magic != FSL_MC_DEVICE_MAGIC))
+		goto out;
+	if (WARN_ON(mc_drv->magic != FSL_MC_DRIVER_MAGIC))
+		goto out;

We normally don't do this magic number matching, just remove these and rely on the compile-time checks.

drivers/bus/fsl-mc/fsl_mc_bus.c line 97

Quoted 10 lines
drivers/bus/fsl-mc/fsl_mc_bus.c new file +10 -0
+struct bus_type fsl_mc_bus_type = {
+	.name = "fsl-mc",
+	.match = fsl_mc_bus_match,
+	.uevent = fsl_mc_bus_uevent,
+	.drv_groups = NULL,
+	.dev_groups = NULL,
+	.bus_groups = NULL,
+	.pm = NULL,
+};
+EXPORT_SYMBOL(fsl_mc_bus_type);

No need to assign NULL members.

Does it need to be exported to drivers? How about making it EXPORT_SYMBOL_GPL if it does?

Quoted 12 lines
drivers/bus/fsl-mc/fsl_mc_bus.c new file +12 -0
+static int dprc_parse_dt_node(struct platform_device *pdev,
+			      phys_addr_t *mc_portal_phys_addr,
+			      uint32_t *mc_portal_size)
+{
+	struct resource res;
+	struct device_node *pdev_of_node = pdev->dev.of_node;
+	int error = -EINVAL;
+
+	error = of_address_to_resource(pdev_of_node, 0, &res);
+	if (error < 0) {
+		FSL_MC_ERROR(&pdev->dev,
+			     "of_address_to_resource() failed for %s\n",

drivers/bus/fsl-mc/fsl_mc_bus.c line 120

Quoted 10 lines
drivers/bus/fsl-mc/fsl_mc_bus.c new file +10 -0
+			     pdev_of_node->full_name);
+		goto out;
+	}
+
+	*mc_portal_phys_addr = res.start;
+	*mc_portal_size = resource_size(&res);
+	error = 0;
+out:
+	return error;
+}

Why not just call of_address_to_resource in the caller?

drivers/bus/fsl-mc/fsl_mc_bus.c line 206

Quoted 12 lines
drivers/bus/fsl-mc/fsl_mc_bus.c new file +12 -0
+/**
+ * __fsl_mc_driver_register - registers a child device driver with the
+ * MC bus
+ *
+ * This function is implicitly invoked from the registration function of
+ * fsl_mc device drivers, which is generated by the
+ * module_fsl_mc_driver() macro.
+ */
+int __fsl_mc_driver_register(struct fsl_mc_driver *mc_driver,
+			     struct module *owner)
+{
+	struct fsl_mc_device *root_mc_dev;

Here the root_mc_dev variable isn't really used for much.

drivers/bus/fsl-mc/fsl_mc_bus.c line 316

Quoted 11 lines
drivers/bus/fsl-mc/fsl_mc_bus.c new file +11 -0
+static int fsl_mc_device_get_mmio_regions(struct fsl_mc_device *mc_dev,
+					  struct fsl_mc_device *container_dev)
+{
+	int i;
+	int error;
+	struct fsl_mc_device_region *regions;
+	struct dprc_obj_desc *obj_desc = &mc_dev->obj_desc;
+	struct device *parent_dev = mc_dev->dev.parent;
+
+	regions = kmalloc_array(obj_desc->region_count,
+				sizeof(regions[0]), GFP_KERNEL);

Better use 'struct resource' for the resources than make your own type.

drivers/bus/fsl-mc/fsl_mc_bus.c line 404

Quoted 3 lines
drivers/bus/fsl-mc/fsl_mc_bus.c new file +3 -0
+		mc_dev->icid = container_dev->icid;
+		mc_dev->dma_mask = 0xffffffff;	/* 32bit */
+		mc_dev->dev.dma_mask = &mc_dev->dma_mask;

Is 32-bit DMA a fundamental limit of the bus?

drivers/bus/fsl-mc/fsl_mc_bus.c line 661

Quoted 5 lines
drivers/bus/fsl-mc/fsl_mc_bus.c new file +5 -0
+
+static const struct of_device_id fsl_mc_bus_match_table[] = {
+	{.compatible = "fsl,qoriq-mc",},
+	{},
+};

Please add a binding documentation for this device in Documentation/device-tree/

include/linux/fsl_mc.h line 24

Quoted 5 lines
include/linux/fsl_mc.h new file +5 -0
+#define FSL_MC_MAGIC(_a, _b, _c, _d) \
+	(((uint32_t)(_a) << 24) | \
+	((uint32_t)(_b) << 16) | \
+	((uint32_t)(_c) << 8)  | \
+	(uint32_t)(_d))

Can be dropped once you remove all the magic number matching

include/linux/fsl_mc.h line 87

Quoted 9 lines
include/linux/fsl_mc.h new file +9 -0
+/**
+ * struct fsl_mc_device_region - MC object device MMIO region
+ * @addr: base physical address
+ * @size: size of the region in bytes
+ */
+struct fsl_mc_device_region {
+	phys_addr_t paddr;
+	uint32_t size;
+};

Can be removed when you move to 'struct resource'

Quoted 3 lines

+/**
+ * struct fsl_mc_device - MC object device object
+ * @magic: marker to verify identity of this structure

remove

Quoted 6 lines

+ * @flags: MC object device flags
+ * @icid: Isolation context ID for the device
+ * @mc_handle: MC handle for the corresponding MC object opened
+ * @mc_io: Pointer to MC IO object assigned to this device or
+ * NULL if none.
+ * @driver: Pointer to the MC object device driver for this device

Use container_of(&this->dev.driver, ...) instead

Quoted 1 line

+ * @container: Pointer to the DPRC device that contains this MC object device

Why are there two devices for this? Should this just use dev->parent instead?

Quoted 1 line

+ * @dev_node: Node in the container's child list

Same here: just use the device model's list management instead if you can, or explain why this is needed.

Quoted 2 lines

+ * @obj_desc: MC description of the DPAA device
+ * @num_regions: Number of MMIO regions for this MC object device

Doesn't actually exist?

include/linux/fsl_mc_private.h line 26

Quoted 9 lines
include/linux/fsl_mc_private.h new file +9 -0
+#define FSL_MC_ERROR(_dev, _fmt, ...) \
+	do {								\
+		if ((_dev) != NULL)					\
+			dev_err(_dev, "%s:" __stringify(__LINE__) " "   \
+				_fmt, __func__, ##__VA_ARGS__);		\
+		else							\
+			pr_err("%s:" __stringify(__LINE__) " " _fmt,	\
+			       __func__, ##__VA_ARGS__);		\
+	} while (0)

just use dev_err() directly, it handles the !_dev case already

include/linux/fsl_mc_private.h line 47

Quoted 12 lines
include/linux/fsl_mc_private.h new file +12 -0
+/**
+ * struct fsl_mc_bus - Management Complex (MC) bus object
+ * @magic: marker to verify identity of this structure
+ * @pdev: platform device for this MC bus object
+ * @root_mc_dev: pointer to root MC object device for this MC bus.
+ */
+struct fsl_mc_bus {
+#	define FSL_MC_BUS_MAGIC   FSL_MC_MAGIC('L', 'B', 'U', 'S')
+	uint32_t magic;
+	struct platform_device *pdev;
+	struct fsl_mc_device *root_mc_dev;
+};

pdev should be root_mc_dev->dev->parent, and magic seems pointless, so no need for this structure at all.

Quoted 6 lines
include/linux/fsl_mc_private.h new file +6 -0
+/**
+ * struct fsl_mc_dprc - Data Path Resource Container (DPRC) object
+ * @magic: marker to verify identity of this structure
+ * @mc_dev: pointer to MC object device object for this DPRC
+ * @mutex: mutex to serialize access to the container.
+ * @child_device_count: have the count of devices in this DPRC

include/linux/fsl_mc_private.h line 64

Quoted 10 lines
include/linux/fsl_mc_private.h new file +10 -0
+ * @child_list:	anchor node of list of child devices on this DPRC
+ */
+struct fsl_mc_dprc {
+#	define FSL_MC_DPRC_MAGIC   FSL_MC_MAGIC('D', 'P', 'R', 'C')
+	uint32_t magic;
+	struct fsl_mc_device *mc_dev;
+	struct mutex mutex;	/* serializes access to fields below */
+	uint16_t child_device_count;	/* Count of devices in this DPRC */
+	struct list_head child_list;
+};

It's not clear what this represents to me. mc_dev presumably already has a list of children, so why not just use a pointer to mc_dev and remove this structure entirely?

Arnd

#4 lore raw

Re: [RFC PATCH 2/4] drivers/bus: Freescale Management Complex (fsl-mc) bus driver

In reply to J. German Rivera

drivers/bus/fsl-mc/fsl_mc_bus.c line 23

Quoted 2 lines · On Friday 15 August 2014 17:13:12 J. German Rivera wrote:
drivers/bus/fsl-mc/fsl_mc_bus.c new file +2 -0
+struct fsl_mc_bus *fsl_mc_bus;
+EXPORT_SYMBOL(fsl_mc_bus);

This does not look like something that should be exported. Or even better, kill this structure entirely and just pass around pointers to the fsl_mc_device so you can deal with multiple root instances.

Quoted 11 lines
drivers/bus/fsl-mc/fsl_mc_bus.c new file +11 -0
+static struct kmem_cache *mc_dev_cache;
+
+/**
+ * fsl_mc_bus_match - device to driver matching callback
+ * @dev: the MC object device structure to match against
+ * @drv: the device driver to search for matching MC object device id
+ * structures
+ *
+ * Returns 1 on success, 0 otherwise.
+ */
+static int fsl_mc_bus_match(struct device *dev, struct device_driver *drv)

drivers/bus/fsl-mc/fsl_mc_bus.c line 45

Quoted 10 lines
drivers/bus/fsl-mc/fsl_mc_bus.c new file +10 -0
+{
+	const struct fsl_mc_device_match_id *id;
+	struct fsl_mc_device *mc_dev = to_fsl_mc_device(dev);
+	struct fsl_mc_driver *mc_drv = to_fsl_mc_driver(drv);
+	bool found = false;
+
+	if (WARN_ON(mc_dev->magic != FSL_MC_DEVICE_MAGIC))
+		goto out;
+	if (WARN_ON(mc_drv->magic != FSL_MC_DRIVER_MAGIC))
+		goto out;

We normally don't do this magic number matching, just remove these and rely on the compile-time checks.

drivers/bus/fsl-mc/fsl_mc_bus.c line 97

Quoted 10 lines
drivers/bus/fsl-mc/fsl_mc_bus.c new file +10 -0
+struct bus_type fsl_mc_bus_type = {
+	.name = "fsl-mc",
+	.match = fsl_mc_bus_match,
+	.uevent = fsl_mc_bus_uevent,
+	.drv_groups = NULL,
+	.dev_groups = NULL,
+	.bus_groups = NULL,
+	.pm = NULL,
+};
+EXPORT_SYMBOL(fsl_mc_bus_type);

No need to assign NULL members.

Does it need to be exported to drivers? How about making it EXPORT_SYMBOL_GPL if it does?

Quoted 12 lines
drivers/bus/fsl-mc/fsl_mc_bus.c new file +12 -0
+static int dprc_parse_dt_node(struct platform_device *pdev,
+			      phys_addr_t *mc_portal_phys_addr,
+			      uint32_t *mc_portal_size)
+{
+	struct resource res;
+	struct device_node *pdev_of_node = pdev->dev.of_node;
+	int error = -EINVAL;
+
+	error = of_address_to_resource(pdev_of_node, 0, &res);
+	if (error < 0) {
+		FSL_MC_ERROR(&pdev->dev,
+			     "of_address_to_resource() failed for %s\n",

drivers/bus/fsl-mc/fsl_mc_bus.c line 120

Quoted 10 lines
drivers/bus/fsl-mc/fsl_mc_bus.c new file +10 -0
+			     pdev_of_node->full_name);
+		goto out;
+	}
+
+	*mc_portal_phys_addr = res.start;
+	*mc_portal_size = resource_size(&res);
+	error = 0;
+out:
+	return error;
+}

Why not just call of_address_to_resource in the caller?

drivers/bus/fsl-mc/fsl_mc_bus.c line 206

Quoted 12 lines
drivers/bus/fsl-mc/fsl_mc_bus.c new file +12 -0
+/**
+ * __fsl_mc_driver_register - registers a child device driver with the
+ * MC bus
+ *
+ * This function is implicitly invoked from the registration function of
+ * fsl_mc device drivers, which is generated by the
+ * module_fsl_mc_driver() macro.
+ */
+int __fsl_mc_driver_register(struct fsl_mc_driver *mc_driver,
+			     struct module *owner)
+{
+	struct fsl_mc_device *root_mc_dev;

Here the root_mc_dev variable isn't really used for much.

drivers/bus/fsl-mc/fsl_mc_bus.c line 316

Quoted 11 lines
drivers/bus/fsl-mc/fsl_mc_bus.c new file +11 -0
+static int fsl_mc_device_get_mmio_regions(struct fsl_mc_device *mc_dev,
+					  struct fsl_mc_device *container_dev)
+{
+	int i;
+	int error;
+	struct fsl_mc_device_region *regions;
+	struct dprc_obj_desc *obj_desc = &mc_dev->obj_desc;
+	struct device *parent_dev = mc_dev->dev.parent;
+
+	regions = kmalloc_array(obj_desc->region_count,
+				sizeof(regions[0]), GFP_KERNEL);

Better use 'struct resource' for the resources than make your own type.

drivers/bus/fsl-mc/fsl_mc_bus.c line 404

Quoted 3 lines
drivers/bus/fsl-mc/fsl_mc_bus.c new file +3 -0
+		mc_dev->icid = container_dev->icid;
+		mc_dev->dma_mask = 0xffffffff;	/* 32bit */
+		mc_dev->dev.dma_mask = &mc_dev->dma_mask;

Is 32-bit DMA a fundamental limit of the bus?

drivers/bus/fsl-mc/fsl_mc_bus.c line 661

Quoted 5 lines
drivers/bus/fsl-mc/fsl_mc_bus.c new file +5 -0
+
+static const struct of_device_id fsl_mc_bus_match_table[] = {
+	{.compatible = "fsl,qoriq-mc",},
+	{},
+};

Please add a binding documentation for this device in Documentation/device-tree/

include/linux/fsl_mc.h line 24

Quoted 5 lines
include/linux/fsl_mc.h new file +5 -0
+#define FSL_MC_MAGIC(_a, _b, _c, _d) \
+	(((uint32_t)(_a) << 24) | \
+	((uint32_t)(_b) << 16) | \
+	((uint32_t)(_c) << 8)  | \
+	(uint32_t)(_d))

Can be dropped once you remove all the magic number matching

include/linux/fsl_mc.h line 87

Quoted 9 lines
include/linux/fsl_mc.h new file +9 -0
+/**
+ * struct fsl_mc_device_region - MC object device MMIO region
+ * @addr: base physical address
+ * @size: size of the region in bytes
+ */
+struct fsl_mc_device_region {
+	phys_addr_t paddr;
+	uint32_t size;
+};

Can be removed when you move to 'struct resource'

Quoted 3 lines

+/**
+ * struct fsl_mc_device - MC object device object
+ * @magic: marker to verify identity of this structure

remove

Quoted 6 lines

+ * @flags: MC object device flags
+ * @icid: Isolation context ID for the device
+ * @mc_handle: MC handle for the corresponding MC object opened
+ * @mc_io: Pointer to MC IO object assigned to this device or
+ * NULL if none.
+ * @driver: Pointer to the MC object device driver for this device

Use container_of(&this->dev.driver, ...) instead

Quoted 1 line

+ * @container: Pointer to the DPRC device that contains this MC object device

Why are there two devices for this? Should this just use dev->parent instead?

Quoted 1 line

+ * @dev_node: Node in the container's child list

Same here: just use the device model's list management instead if you can, or explain why this is needed.

Quoted 2 lines

+ * @obj_desc: MC description of the DPAA device
+ * @num_regions: Number of MMIO regions for this MC object device

Doesn't actually exist?

include/linux/fsl_mc_private.h line 26

Quoted 9 lines
include/linux/fsl_mc_private.h new file +9 -0
+#define FSL_MC_ERROR(_dev, _fmt, ...) \
+	do {								\
+		if ((_dev) != NULL)					\
+			dev_err(_dev, "%s:" __stringify(__LINE__) " "   \
+				_fmt, __func__, ##__VA_ARGS__);		\
+		else							\
+			pr_err("%s:" __stringify(__LINE__) " " _fmt,	\
+			       __func__, ##__VA_ARGS__);		\
+	} while (0)

just use dev_err() directly, it handles the !_dev case already

include/linux/fsl_mc_private.h line 47

Quoted 12 lines
include/linux/fsl_mc_private.h new file +12 -0
+/**
+ * struct fsl_mc_bus - Management Complex (MC) bus object
+ * @magic: marker to verify identity of this structure
+ * @pdev: platform device for this MC bus object
+ * @root_mc_dev: pointer to root MC object device for this MC bus.
+ */
+struct fsl_mc_bus {
+#	define FSL_MC_BUS_MAGIC   FSL_MC_MAGIC('L', 'B', 'U', 'S')
+	uint32_t magic;
+	struct platform_device *pdev;
+	struct fsl_mc_device *root_mc_dev;
+};

pdev should be root_mc_dev->dev->parent, and magic seems pointless, so no need for this structure at all.

Quoted 6 lines
include/linux/fsl_mc_private.h new file +6 -0
+/**
+ * struct fsl_mc_dprc - Data Path Resource Container (DPRC) object
+ * @magic: marker to verify identity of this structure
+ * @mc_dev: pointer to MC object device object for this DPRC
+ * @mutex: mutex to serialize access to the container.
+ * @child_device_count: have the count of devices in this DPRC

include/linux/fsl_mc_private.h line 64

Quoted 10 lines
include/linux/fsl_mc_private.h new file +10 -0
+ * @child_list:	anchor node of list of child devices on this DPRC
+ */
+struct fsl_mc_dprc {
+#	define FSL_MC_DPRC_MAGIC   FSL_MC_MAGIC('D', 'P', 'R', 'C')
+	uint32_t magic;
+	struct fsl_mc_device *mc_dev;
+	struct mutex mutex;	/* serializes access to fields below */
+	uint16_t child_device_count;	/* Count of devices in this DPRC */
+	struct list_head child_list;
+};

It's not clear what this represents to me. mc_dev presumably already has a list of children, so why not just use a pointer to mc_dev and remove this structure entirely?

Arnd

#5 lore raw

Re: [RFC PATCH 2/4] drivers/bus: Freescale Management Complex (fsl-mc) bus driver

Hi Arnd,

Thanks for your comments. My replies inline below. Please let me know if there is anything else, before post a respin of the patch series that addresses your comments.

Thanks,

German

Quoted 9 lines · Arnd Bergmann

drivers/bus/fsl-mc/fsl_mc_bus.c line 23

Quoted 2 lines · On Friday 15 August 2014 17:13:12 J. German Rivera wrote:
drivers/bus/fsl-mc/fsl_mc_bus.c new file +2 -0
+struct fsl_mc_bus *fsl_mc_bus;
+EXPORT_SYMBOL(fsl_mc_bus);

This does not look like something that should be exported. Or even better, kill this structure entirely and just pass around pointers to the fsl_mc_device so you can deal with multiple root instances.

Ok. I'll remove this global structure.

Quoted 16 lines
Quoted 16 lines
drivers/bus/fsl-mc/fsl_mc_bus.c new file +16 -0
+static struct kmem_cache *mc_dev_cache;
+
+/**
+ * fsl_mc_bus_match - device to driver matching callback
+ * @dev: the MC object device structure to match against
+ * @drv: the device driver to search for matching MC object device id
+ * structures
+ *
+ * Returns 1 on success, 0 otherwise.
+ */
+static int fsl_mc_bus_match(struct device *dev, struct device_driver *drv)
+{
+	const struct fsl_mc_device_match_id *id;
+	struct fsl_mc_device *mc_dev = to_fsl_mc_device(dev);
+	struct fsl_mc_driver *mc_drv = to_fsl_mc_driver(drv);
+	bool found = false;
Quoted 8 lines

drivers/bus/fsl-mc/fsl_mc_bus.c line 45

Quoted 5 lines
drivers/bus/fsl-mc/fsl_mc_bus.c new file +5 -0
+
+	if (WARN_ON(mc_dev->magic != FSL_MC_DEVICE_MAGIC))
+		goto out;
+	if (WARN_ON(mc_drv->magic != FSL_MC_DRIVER_MAGIC))
+		goto out;

We normally don't do this magic number matching, just remove these and rely on the compile-time checks.

Ok. I'll remove all the magic fields and their checking.

Quoted 4 lines
Quoted 4 lines
drivers/bus/fsl-mc/fsl_mc_bus.c new file +4 -0
+struct bus_type fsl_mc_bus_type = {
+	.name = "fsl-mc",
+	.match = fsl_mc_bus_match,
+	.uevent = fsl_mc_bus_uevent,
Quoted 9 lines

drivers/bus/fsl-mc/fsl_mc_bus.c line 97

Quoted 6 lines
drivers/bus/fsl-mc/fsl_mc_bus.c new file +6 -0
+	.drv_groups = NULL,
+	.dev_groups = NULL,
+	.bus_groups = NULL,
+	.pm = NULL,
+};
+EXPORT_SYMBOL(fsl_mc_bus_type);

No need to assign NULL members.

Ok. I'll removed them.

Quoted 3 lines

Does it need to be exported to drivers? How about making it EXPORT_SYMBOL_GPL if it does?

Yes it needs to be accessed by another driver that will come in a later patch series. I'll change it to EXPORT_SYMBOL_GPL()

Quoted 16 lines
Quoted 16 lines
drivers/bus/fsl-mc/fsl_mc_bus.c new file +16 -0
+static int dprc_parse_dt_node(struct platform_device *pdev,
+			      phys_addr_t *mc_portal_phys_addr,
+			      uint32_t *mc_portal_size)
+{
+	struct resource res;
+	struct device_node *pdev_of_node = pdev->dev.of_node;
+	int error = -EINVAL;
+
+	error = of_address_to_resource(pdev_of_node, 0, &res);
+	if (error < 0) {
+		FSL_MC_ERROR(&pdev->dev,
+			     "of_address_to_resource() failed for %s\n",
+			     pdev_of_node->full_name);
+		goto out;
+	}
+
Quoted 9 lines

drivers/bus/fsl-mc/fsl_mc_bus.c line 120

Quoted 6 lines
drivers/bus/fsl-mc/fsl_mc_bus.c new file +6 -0
+	*mc_portal_phys_addr = res.start;
+	*mc_portal_size = resource_size(&res);
+	error = 0;
+out:
+	return error;
+}

Why not just call of_address_to_resource in the caller?

Done.

Quoted 6 lines
Quoted 6 lines

+/**
+ * __fsl_mc_driver_register - registers a child device driver with the
+ * MC bus
+ *
+ * This function is implicitly invoked from the registration function of
+ * fsl_mc device drivers, which is generated by the

Quoted 9 lines

drivers/bus/fsl-mc/fsl_mc_bus.c line 206

Quoted 6 lines

+ * module_fsl_mc_driver() macro.
+ */

drivers/bus/fsl-mc/fsl_mc_bus.c new file +4 -0
+int __fsl_mc_driver_register(struct fsl_mc_driver *mc_driver,
+			     struct module *owner)
+{
+	struct fsl_mc_device *root_mc_dev;

Here the root_mc_dev variable isn't really used for much.

Removed.

Quoted 5 lines
Quoted 5 lines
drivers/bus/fsl-mc/fsl_mc_bus.c new file +5 -0
+static int fsl_mc_device_get_mmio_regions(struct fsl_mc_device *mc_dev,
+					  struct fsl_mc_device *container_dev)
+{
+	int i;
+	int error;
Quoted 9 lines

drivers/bus/fsl-mc/fsl_mc_bus.c line 316

Quoted 6 lines
drivers/bus/fsl-mc/fsl_mc_bus.c new file +6 -0
+	struct fsl_mc_device_region *regions;
+	struct dprc_obj_desc *obj_desc = &mc_dev->obj_desc;
+	struct device *parent_dev = mc_dev->dev.parent;
+
+	regions = kmalloc_array(obj_desc->region_count,
+				sizeof(regions[0]), GFP_KERNEL);

Better use 'struct resource' for the resources than make your own type.

Ok, I will remove struct fsl_mc_device_region and use struct resource instead.

Quoted 6 lines

drivers/bus/fsl-mc/fsl_mc_bus.c line 404

Quoted 3 lines
drivers/bus/fsl-mc/fsl_mc_bus.c new file +3 -0
+		mc_dev->icid = container_dev->icid;
+		mc_dev->dma_mask = 0xffffffff;	/* 32bit */
+		mc_dev->dev.dma_mask = &mc_dev->dma_mask;

Is 32-bit DMA a fundamental limit of the bus?

No, there is not 32-bit DMA limitation for this bus. Also,this dma_mask field is not currently being used. So, I'll remove it.

Quoted 8 lines

drivers/bus/fsl-mc/fsl_mc_bus.c line 661

Quoted 5 lines
drivers/bus/fsl-mc/fsl_mc_bus.c new file +5 -0
+
+static const struct of_device_id fsl_mc_bus_match_table[] = {
+	{.compatible = "fsl,qoriq-mc",},
+	{},
+};

Please add a binding documentation for this device in Documentation/device-tree/

Yes, this is being added in the 'ARM64: Add support for FSL's LS2085A SoC' patch series, already posted for review.

Quoted 8 lines

include/linux/fsl_mc.h line 24

Quoted 5 lines
include/linux/fsl_mc.h new file +5 -0
+#define FSL_MC_MAGIC(_a, _b, _c, _d) \
+	(((uint32_t)(_a) << 24) | \
+	((uint32_t)(_b) << 16) | \
+	((uint32_t)(_c) << 8)  | \
+	(uint32_t)(_d))

Can be dropped once you remove all the magic number matching

Done.

Quoted 12 lines

include/linux/fsl_mc.h line 87

Quoted 9 lines
include/linux/fsl_mc.h new file +9 -0
+/**
+ * struct fsl_mc_device_region - MC object device MMIO region
+ * @addr: base physical address
+ * @size: size of the region in bytes
+ */
+struct fsl_mc_device_region {
+	phys_addr_t paddr;
+	uint32_t size;
+};

Can be removed when you move to 'struct resource'

Done.

Quoted 6 lines
Quoted 3 lines

+/**
+ * struct fsl_mc_device - MC object device object
+ * @magic: marker to verify identity of this structure

remove

Removed all 'magic' fields

Quoted 9 lines
Quoted 6 lines

+ * @flags: MC object device flags
+ * @icid: Isolation context ID for the device
+ * @mc_handle: MC handle for the corresponding MC object opened
+ * @mc_io: Pointer to MC IO object assigned to this device or
+ * NULL if none.
+ * @driver: Pointer to the MC object device driver for this device

Use container_of(&this->dev.driver, ...) instead

Removed redundant driver field.

Quoted 4 lines
Quoted 1 line

+ * @container: Pointer to the DPRC device that contains this MC object device

Why are there two devices for this? Should this just use dev->parent instead?

You are right. Removed the container field. We can get the parent DPRC of a given dev, from its dev.parent field.

Quoted 5 lines
Quoted 1 line

+ * @dev_node: Node in the container's child list

Same here: just use the device model's list management instead if you can, or explain why this is needed.

We still need to keep a per-bus list of child devices (devices contained in a given DPRC object). Unless I'm missing something,
I think the device model's list management links together all the devices of the same bus type. We are trying to follow a similar approach to the pci_dev/pci_bus structs.

Quoted 5 lines
Quoted 2 lines

+ * @obj_desc: MC description of the DPAA device
+ * @num_regions: Number of MMIO regions for this MC object device

Doesn't actually exist?

No. Removed.

Quoted 12 lines

include/linux/fsl_mc_private.h line 26

Quoted 9 lines
include/linux/fsl_mc_private.h new file +9 -0
+#define FSL_MC_ERROR(_dev, _fmt, ...) \
+	do {								\
+		if ((_dev) != NULL)					\
+			dev_err(_dev, "%s:" __stringify(__LINE__) " "   \
+				_fmt, __func__, ##__VA_ARGS__);		\
+		else							\
+			pr_err("%s:" __stringify(__LINE__) " " _fmt,	\
+			       __func__, ##__VA_ARGS__);		\
+	} while (0)

just use dev_err() directly, it handles the !_dev case already

Done.

Quoted 7 lines
Quoted 7 lines
include/linux/fsl_mc_private.h new file +7 -0
+/**
+ * struct fsl_mc_bus - Management Complex (MC) bus object
+ * @magic: marker to verify identity of this structure
+ * @pdev: platform device for this MC bus object
+ * @root_mc_dev: pointer to root MC object device for this MC bus.
+ */
+struct fsl_mc_bus {
Quoted 9 lines

include/linux/fsl_mc_private.h line 47

Quoted 5 lines
include/linux/fsl_mc_private.h new file +5 -0
+#	define FSL_MC_BUS_MAGIC   FSL_MC_MAGIC('L', 'B', 'U', 'S')
+	uint32_t magic;
+	struct platform_device *pdev;
+	struct fsl_mc_device *root_mc_dev;
+};

pdev should be root_mc_dev->dev->parent, and magic seems pointless, so no need for this structure at all.

Agreed. This is redundant. Removed.

Quoted 12 lines
Quoted 12 lines
include/linux/fsl_mc_private.h new file +12 -0
+/**
+ * struct fsl_mc_dprc - Data Path Resource Container (DPRC) object
+ * @magic: marker to verify identity of this structure
+ * @mc_dev: pointer to MC object device object for this DPRC
+ * @mutex: mutex to serialize access to the container.
+ * @child_device_count: have the count of devices in this DPRC
+ * @child_list:	anchor node of list of child devices on this DPRC
+ */
+struct fsl_mc_dprc {
+#	define FSL_MC_DPRC_MAGIC   FSL_MC_MAGIC('D', 'P', 'R', 'C')
+	uint32_t magic;
+	struct fsl_mc_device *mc_dev;
Quoted 9 lines

include/linux/fsl_mc_private.h line 64

Quoted 4 lines
include/linux/fsl_mc_private.h new file +4 -0
+	struct mutex mutex;	/* serializes access to fields below */
+	uint16_t child_device_count;	/* Count of devices in this DPRC */
+	struct list_head child_list;
+};

It's not clear what this represents to me. mc_dev presumably already has a list of children, so why not just use a pointer to mc_dev and remove this structure entirely?

This structure represents the per-bus (per DPRC object) information. It is kind of the equivalent to 'struct pci_bus' in the PCI world. I have renamed this struct to 'struct fsl_mc_bus'.

Quoted 2 lines

Arnd

#6 lore raw

Re: [RFC PATCH 2/4] drivers/bus: Freescale Management Complex (fsl-mc) bus driver

Quoted 10 lines · German Rivera
Quoted 5 lines
Quoted 1 line

+ * @dev_node: Node in the container's child list

Same here: just use the device model's list management instead if you can, or explain why this is needed.

We still need to keep a per-bus list of child devices (devices contained in a given DPRC object). Unless I'm missing something,
I think the device model's list management links together all the devices of the same bus type. We are trying to follow a similar approach to the pci_dev/pci_bus structs.

There are multiple lists in the device handling. device_for_each_child() should iterate over the children of a particular device using the klist_children member.

Quoted 21 lines
Quoted 12 lines
Quoted 12 lines
include/linux/fsl_mc_private.h new file +12 -0
+/**
+ * struct fsl_mc_dprc - Data Path Resource Container (DPRC) object
+ * @magic: marker to verify identity of this structure
+ * @mc_dev: pointer to MC object device object for this DPRC
+ * @mutex: mutex to serialize access to the container.
+ * @child_device_count: have the count of devices in this DPRC
+ * @child_list:     anchor node of list of child devices on this DPRC
+ */
+struct fsl_mc_dprc {
+#   define FSL_MC_DPRC_MAGIC   FSL_MC_MAGIC('D', 'P', 'R', 'C')
+    uint32_t magic;
+    struct fsl_mc_device *mc_dev;
Quoted 9 lines

include/linux/fsl_mc_private.h line 64

Quoted 4 lines
include/linux/fsl_mc_private.h new file +4 -0
+    struct mutex mutex;     /* serializes access to fields below */
+    uint16_t child_device_count;    /* Count of devices in this DPRC */
+    struct list_head child_list;
+};

It's not clear what this represents to me. mc_dev presumably already has a list of children, so why not just use a pointer to mc_dev and remove this structure entirely?

Quoted 3 lines

This structure represents the per-bus (per DPRC object) information. It is kind of the equivalent to 'struct pci_bus' in the PCI world. I have renamed this struct to 'struct fsl_mc_bus'.

Ok, I'll look at the new version when I get back to Germany. I still think that can remove all members of the current structure and just use the same structure for fsl_mc_bus and fsl_mc_device. If you really need a small number of extra members beyond what is in the device, you have two other choices:

a) put the members into the device structure as well but not use them for a device that is not a bus

b) embed the device structure within the bus structure like

	struct fsl_mc_bus {
		int something;
		struct fsl_mc_device;
	};

and then use container_of() to go from the device to the bus where needed rather than having two objects that are allocated separately. This is what a lot of other subsystems (not PCI) do. See for instance platform_device, which often has child devices as well.

Arnd

#7 lore raw

Re: [RFC PATCH 2/4] drivers/bus: Freescale Management Complex (fsl-mc) bus driver

Hi Arnd,

I have posted respin v3 of this patch series to address your lastest of comments. Please see below the resolutions.

Thanks,

German

Quoted 12 lines · Arnd Bergmann
Quoted 10 lines · German Rivera
Quoted 5 lines
Quoted 1 line

+ * @dev_node: Node in the container's child list

Same here: just use the device model's list management instead if you can, or explain why this is needed.

We still need to keep a per-bus list of child devices (devices contained in a given DPRC object). Unless I'm missing something,
I think the device model's list management links together all the devices of the same bus type. We are trying to follow a similar approach to the pci_dev/pci_bus structs.

Quoted 4 lines

There are multiple lists in the device handling. device_for_each_child() should iterate over the children of a particular device using the klist_children member.

Removed per-bus list of children, and instead use device_for_each_child() as you suggested.

Quoted 25 lines
Quoted 21 lines
Quoted 12 lines
Quoted 12 lines
include/linux/fsl_mc_private.h new file +12 -0
+/**
+ * struct fsl_mc_dprc - Data Path Resource Container (DPRC) object
+ * @magic: marker to verify identity of this structure
+ * @mc_dev: pointer to MC object device object for this DPRC
+ * @mutex: mutex to serialize access to the container.
+ * @child_device_count: have the count of devices in this DPRC
+ * @child_list:     anchor node of list of child devices on this DPRC
+ */
+struct fsl_mc_dprc {
+#   define FSL_MC_DPRC_MAGIC   FSL_MC_MAGIC('D', 'P', 'R', 'C')
+    uint32_t magic;
+    struct fsl_mc_device *mc_dev;
Quoted 9 lines

include/linux/fsl_mc_private.h line 64

Quoted 4 lines
include/linux/fsl_mc_private.h new file +4 -0
+    struct mutex mutex;     /* serializes access to fields below */
+    uint16_t child_device_count;    /* Count of devices in this DPRC */
+    struct list_head child_list;
+};

It's not clear what this represents to me. mc_dev presumably already has a list of children, so why not just use a pointer to mc_dev and remove this structure entirely?

Quoted 3 lines

This structure represents the per-bus (per DPRC object) information. It is kind of the equivalent to 'struct pci_bus' in the PCI world. I have renamed this struct to 'struct fsl_mc_bus'.

Quoted 6 lines

Ok, I'll look at the new version when I get back to Germany. I still think that can remove all members of the current structure and just use the same structure for fsl_mc_bus and fsl_mc_device. If you really need a small number of extra members beyond what is in the device, you have two other choices:

By removing the child list from the fsl_mc_bus structure as you suggested, the fsl_mc_bus structure does not need to exist for this patch series. As you rightfully suggested, we can use just one structure (fsl_mc_device) to represent both regular devices (children)
and bus devices.

Quoted 10 lines

a) put the members into the device structure as well but not use them for a device that is not a bus

b) embed the device structure within the bus structure like

	struct fsl_mc_bus {
		int something;
		struct fsl_mc_device;
	};
Quoted 5 lines

and then use container_of() to go from the device to the bus where needed rather than having two objects that are allocated separately. This is what a lot of other subsystems (not PCI) do. See for instance platform_device, which often has child devices as well.

In other functionality to be delivered as a follow-on patch series
(after this patch series), we will need to track some per-bus information, and we will do so using your "b)" recommendation.

Quoted 2 lines

Arnd

#8 lore raw

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

In reply to J. German Rivera

From: "J. German Rivera" <[email protected]>

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).

---
 drivers/bus/fsl-mc/Makefile      |    3 +-
 drivers/bus/fsl-mc/fsl_mc_dprc.c |  422 ++++++++++++++++++++++++++++++++++++++
 include/linux/fsl_mc_private.h   |    4 +-
 3 files changed, 427 insertions(+), 2 deletions(-)
 create mode 100644 drivers/bus/fsl-mc/fsl_mc_dprc.c
drivers/bus/fsl-mc/Makefile +2 -1
index f5f9033..4991999 100644
@@ -5,7 +5,8 @@
 #
 # This file is released under the GPLv2
 #
-obj-$(CONFIG_FSL_MC_BUS) += fsl_mc_bus_driver.o
+obj-$(CONFIG_FSL_MC_BUS) += fsl_mc_bus_driver.o \
+			    fsl_mc_dprc.o
 
 fsl_mc_bus_driver-objs := fsl_mc_bus.o \
 			      mc_sys.o \
drivers/bus/fsl-mc/fsl_mc_dprc.c new file +422 -0

422 lines not on this page · raw message

include/linux/fsl_mc_private.h +3 -1
index dabd030..4eacb2a 100644
@@ -25,6 +25,8 @@
 			       __func__, ##__VA_ARGS__);		\
 	} while (0)
 
+#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)
@@ -78,7 +80,7 @@ struct fsl_mc_device *__must_check fsl_mc_device_lookup(struct dprc_obj_desc
 
 int __must_check dprc_scan_container(struct fsl_mc_dprc *container);
 
-int __must_check dprc_discover_container_objects(struct fsl_mc_dprc *container);
+int __must_check dprc_discover_objects(struct fsl_mc_dprc *container);
 
 extern struct fsl_mc_bus *fsl_mc_bus;
 

--
1.7.9.7

#9 lore raw

RFC PATCH 4/4 Update MAINTAINERS file

In reply to J. German Rivera

From: "J. German Rivera" <[email protected]>

---
 MAINTAINERS |    8 ++++++++
 1 file changed, 8 insertions(+)
MAINTAINERS +8 -0
index 7e2eb4c..eb8597d 100644
@@ -3841,6 +3841,14 @@ S:	Maintained
 F:	sound/soc/fsl/fsl*
 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

--
1.7.9.7