linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/8] Management Complex restool driver
@ 2015-10-30 19:32 Lijun Pan
  2015-10-30 19:32 ` [PATCH v2 1/8] staging: fsl-mc: static inline function to differentiate root dprc Lijun Pan
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: Lijun Pan @ 2015-10-30 19:32 UTC (permalink / raw)
  To: gregkh, arnd, devel, linux-kernel
  Cc: stuart.yoder, itai.katz, german.rivera, leoli, scottwood, agraf,
	bhamciu1, R89243, bhupesh.sharma, nir.erez, richard.schmitt,
	dan.carpenter, Lijun Pan

This series of patches are based on
http://git.kernel.org/cgit/linux/kernel/git/gregkh/staging.git/commit/?h=staging-next&id=63f2be5c3b358db031f86eafa9cd450f6558a55b

patch v1 1/5 "staging: fsl-mc: section mismatch bug fix" is already accepted.

This v2 series have,
patch 1/8 use inline function to differentiate root dprc
patch 2/8 add sysfs rescan attribute in TODO list
patch 3/8 add sysfs rescan documentation for dprc device
patch 4/8 introduce the sysfs rescan attribute for root dprc device
patch 5/8 add sysfs rescan documentation for fsl-mc bus
patch 6/8 introduce the sysfs rescan attribute for fsl-mc bus
patch 7/8 add restool driver introduction in TODO list and README
patch 8/8 introduction of restool driver, which sits on fsl-mc bus and
utilizes fsl-mc bus to communicate with MC firmware.
restool driver is the first driver to start using fsl-mc bus.
This restool driver is small and helps fsl-mc bus move out of staging.

Lijun Pan (8):
  staging: fsl-mc: static inline function to differentiate root dprc
  staging: fsl-mc: add sysfs rescan attribute in TODO
  staging: fsl-mc: dprc device's sysfs rescan documentation
  staging: fsl-mc: root dprc rescan attribute to sync kernel with MC
  staging: fsl-mc: fsl-mc bus's sysfs rescan documentation
  staging: fsl-mc: bus rescan attribute to sync kernel with MC
  staging: fsl-mc: update TODO and README for restool driver
  staging: fsl-mc: Management Complex restool driver

 Documentation/ABI/testing/sysfs-bus-fsl-mc   |  11 +
 Documentation/ABI/testing/sysfs-devices-dprc |  13 +
 Documentation/ioctl/ioctl-number.txt         |   1 +
 drivers/staging/fsl-mc/README.txt            |  11 +-
 drivers/staging/fsl-mc/TODO                  |  24 +-
 drivers/staging/fsl-mc/bus/Kconfig           |   7 +-
 drivers/staging/fsl-mc/bus/Makefile          |   3 +
 drivers/staging/fsl-mc/bus/mc-bus.c          | 112 ++++++--
 drivers/staging/fsl-mc/bus/mc-ioctl.h        |  22 ++
 drivers/staging/fsl-mc/bus/mc-restool.c      | 392 +++++++++++++++++++++++++++
 drivers/staging/fsl-mc/include/mc.h          |  14 +
 11 files changed, 587 insertions(+), 23 deletions(-)
 create mode 100644 Documentation/ABI/testing/sysfs-bus-fsl-mc
 create mode 100644 Documentation/ABI/testing/sysfs-devices-dprc
 create mode 100644 drivers/staging/fsl-mc/bus/mc-ioctl.h
 create mode 100644 drivers/staging/fsl-mc/bus/mc-restool.c

-- 
2.3.3


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH v2 1/8] staging: fsl-mc: static inline function to differentiate root dprc
  2015-10-30 19:32 [PATCH v2 0/8] Management Complex restool driver Lijun Pan
@ 2015-10-30 19:32 ` Lijun Pan
  2015-10-30 19:32 ` [PATCH v2 2/8] staging: fsl-mc: add sysfs rescan attribute in TODO Lijun Pan
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Lijun Pan @ 2015-10-30 19:32 UTC (permalink / raw)
  To: gregkh, arnd, devel, linux-kernel
  Cc: stuart.yoder, itai.katz, german.rivera, leoli, scottwood, agraf,
	bhamciu1, R89243, bhupesh.sharma, nir.erez, richard.schmitt,
	dan.carpenter, Lijun Pan

Define a static inline function is_root_dprc(dev) to tell whether
a device is root dprc or not via platform_bus_type.
Remove fsl_mc_is_root_dprc() because is_root_dprc() is simpler
and easier to understand.

Signed-off-by: Lijun Pan <Lijun.Pan@freescale.com>
---
v2: use static inline function instead of macro
    replace the fsl_mc_is_root_dprc with is_root_dprc

 drivers/staging/fsl-mc/bus/mc-bus.c | 22 +++-------------------
 drivers/staging/fsl-mc/include/mc.h | 14 ++++++++++++++
 2 files changed, 17 insertions(+), 19 deletions(-)

diff --git a/drivers/staging/fsl-mc/bus/mc-bus.c b/drivers/staging/fsl-mc/bus/mc-bus.c
index 84db55b..25e205421 100644
--- a/drivers/staging/fsl-mc/bus/mc-bus.c
+++ b/drivers/staging/fsl-mc/bus/mc-bus.c
@@ -22,8 +22,6 @@
 
 static struct kmem_cache *mc_dev_cache;
 
-static bool fsl_mc_is_root_dprc(struct device *dev);
-
 /**
  * fsl_mc_bus_match - device to driver matching callback
  * @dev: the MC object device structure to match against
@@ -52,7 +50,7 @@ static int fsl_mc_bus_match(struct device *dev, struct device_driver *drv)
 	 * Only exception is the root DPRC, which is a special case.
 	 */
 	if ((mc_dev->obj_desc.state & DPRC_OBJ_STATE_PLUGGED) == 0 &&
-	    !fsl_mc_is_root_dprc(&mc_dev->dev))
+	    !is_root_dprc(&mc_dev->dev))
 		goto out;
 
 	/*
@@ -236,20 +234,6 @@ static void fsl_mc_get_root_dprc(struct device *dev,
 	}
 }
 
-/**
- * fsl_mc_is_root_dprc - function to check if a given device is a root dprc
- */
-static bool fsl_mc_is_root_dprc(struct device *dev)
-{
-	struct device *root_dprc_dev;
-
-	fsl_mc_get_root_dprc(dev, &root_dprc_dev);
-	if (!root_dprc_dev)
-		return false;
-	else
-		return dev == root_dprc_dev;
-}
-
 static int get_dprc_icid(struct fsl_mc_io *mc_io,
 			 int container_id, u16 *icid)
 {
@@ -541,7 +525,7 @@ void fsl_mc_device_remove(struct fsl_mc_device *mc_dev)
 			mc_dev->mc_io = NULL;
 		}
 
-		if (fsl_mc_is_root_dprc(&mc_dev->dev)) {
+		if (is_root_dprc(&mc_dev->dev)) {
 			if (atomic_read(&root_dprc_count) > 0)
 				atomic_dec(&root_dprc_count);
 			else
@@ -772,7 +756,7 @@ static int fsl_mc_bus_remove(struct platform_device *pdev)
 {
 	struct fsl_mc *mc = platform_get_drvdata(pdev);
 
-	if (WARN_ON(!fsl_mc_is_root_dprc(&mc->root_mc_bus_dev->dev)))
+	if (WARN_ON(!is_root_dprc(&mc->root_mc_bus_dev->dev)))
 		return -EINVAL;
 
 	fsl_mc_device_remove(mc->root_mc_bus_dev);
diff --git a/drivers/staging/fsl-mc/include/mc.h b/drivers/staging/fsl-mc/include/mc.h
index a933291..6051955 100644
--- a/drivers/staging/fsl-mc/include/mc.h
+++ b/drivers/staging/fsl-mc/include/mc.h
@@ -14,6 +14,7 @@
 #include <linux/device.h>
 #include <linux/mod_devicetable.h>
 #include <linux/list.h>
+#include <linux/platform_device.h>
 #include "../include/dprc.h"
 
 #define FSL_MC_VENDOR_FREESCALE	0x1957
@@ -200,4 +201,17 @@ void fsl_mc_object_free(struct fsl_mc_device *mc_adev);
 
 extern struct bus_type fsl_mc_bus_type;
 
+/**
+  * is_root_dprc - tell whether dev is root dprc or not.
+  * root dprc's parent is a platform device,
+  * that platform device's bus type is platform_bus_type.
+  * @dev: MC object device
+  * return 1 on root dprc, 0 otherwise
+  */
+static inline bool is_root_dprc(struct device *dev)
+{
+	return ((to_fsl_mc_device(dev)->flags & FSL_MC_IS_DPRC) &&
+		((dev)->bus == &fsl_mc_bus_type) &&
+		((dev)->parent->bus == &platform_bus_type));
+}
 #endif /* _FSL_MC_H_ */
-- 
2.3.3


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v2 2/8] staging: fsl-mc: add sysfs rescan attribute in TODO
  2015-10-30 19:32 [PATCH v2 0/8] Management Complex restool driver Lijun Pan
  2015-10-30 19:32 ` [PATCH v2 1/8] staging: fsl-mc: static inline function to differentiate root dprc Lijun Pan
@ 2015-10-30 19:32 ` Lijun Pan
  2015-10-30 19:32 ` [PATCH v3 3/8] staging: fsl-mc: dprc device's sysfs rescan documentation Lijun Pan
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Lijun Pan @ 2015-10-30 19:32 UTC (permalink / raw)
  To: gregkh, arnd, devel, linux-kernel
  Cc: stuart.yoder, itai.katz, german.rivera, leoli, scottwood, agraf,
	bhamciu1, R89243, bhupesh.sharma, nir.erez, richard.schmitt,
	dan.carpenter, Lijun Pan

Demonstrate why sysfs rescan attribute is helpful for
moving fsl-mc bus out of staging.

Signed-off-by: Lijun Pan <Lijun.Pan@freescale.com>
---
 drivers/staging/fsl-mc/TODO | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/staging/fsl-mc/TODO b/drivers/staging/fsl-mc/TODO
index 3894368..5065821 100644
--- a/drivers/staging/fsl-mc/TODO
+++ b/drivers/staging/fsl-mc/TODO
@@ -1,3 +1,9 @@
+* Add sysfs rescan attribute for fsl-mc bus, and dprc device. The rescan will
+  trigger the fsl-mc bus, dprc driver to re-discover the objects under fsl-mc
+  bus and dprc.X container. Hence this feature actually verifies the
+  functionality of fsl-mc bus, and dprc driver, and it helps moving
+  fsl-mc bus out of staging.
+
 * Decide if multiple root fsl-mc buses will be supported per Linux instance,
   and if so add support for this.
 
-- 
2.3.3


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v3 3/8] staging: fsl-mc: dprc device's sysfs rescan documentation
  2015-10-30 19:32 [PATCH v2 0/8] Management Complex restool driver Lijun Pan
  2015-10-30 19:32 ` [PATCH v2 1/8] staging: fsl-mc: static inline function to differentiate root dprc Lijun Pan
  2015-10-30 19:32 ` [PATCH v2 2/8] staging: fsl-mc: add sysfs rescan attribute in TODO Lijun Pan
@ 2015-10-30 19:32 ` Lijun Pan
  2015-10-30 19:32 ` [PATCH v2 4/8] staging: fsl-mc: root dprc rescan attribute to sync kernel with MC Lijun Pan
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Lijun Pan @ 2015-10-30 19:32 UTC (permalink / raw)
  To: gregkh, arnd, devel, linux-kernel
  Cc: stuart.yoder, itai.katz, german.rivera, leoli, scottwood, agraf,
	bhamciu1, R89243, bhupesh.sharma, nir.erez, richard.schmitt,
	dan.carpenter, Lijun Pan

Add the sysfs documentation for the rescan attribute of
dprc devices.

Signed-off-by: Lijun Pan <Lijun.Pan@freescale.com>
---
 Documentation/ABI/testing/sysfs-devices-dprc | 13 +++++++++++++
 1 file changed, 13 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-devices-dprc

diff --git a/Documentation/ABI/testing/sysfs-devices-dprc b/Documentation/ABI/testing/sysfs-devices-dprc
new file mode 100644
index 0000000..3c5d725
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-devices-dprc
@@ -0,0 +1,13 @@
+What:		/sys/devices/.../dprc.X/rescan
+Date:		October 2015
+Contact:	Lijun Pan <Lijun.Pan@freescale.com>
+Description:
+		Writing a non-zero value to this attribute will
+		force a rescan of dprc.X container in the system, and
+		add/remove previously added/removed objects in
+		Management Complex firmwarer, i.e., synchronize
+		the objects under dprc.X and Management Complex
+		firmware. For example:
+		# echo 1 > /sys/devices/platform/80c000000.fsl-mc/dprc.1/rescan
+
+
-- 
2.3.3


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v2 4/8] staging: fsl-mc: root dprc rescan attribute to sync kernel with MC
  2015-10-30 19:32 [PATCH v2 0/8] Management Complex restool driver Lijun Pan
                   ` (2 preceding siblings ...)
  2015-10-30 19:32 ` [PATCH v3 3/8] staging: fsl-mc: dprc device's sysfs rescan documentation Lijun Pan
@ 2015-10-30 19:32 ` Lijun Pan
  2015-10-30 19:32 ` [PATCH v2 5/8] staging: fsl-mc: fsl-mc bus's sysfs rescan documentation Lijun Pan
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Lijun Pan @ 2015-10-30 19:32 UTC (permalink / raw)
  To: gregkh, arnd, devel, linux-kernel
  Cc: stuart.yoder, itai.katz, german.rivera, leoli, scottwood, agraf,
	bhamciu1, R89243, bhupesh.sharma, nir.erez, richard.schmitt,
	dan.carpenter, Lijun Pan

Introduce the rescan attribute as a device attribute to
synchronize the fsl-mc bus objects and the MC firmware.

To rescan the root dprc only, e.g.
echo 1 > /sys/bus/fsl-mc/devices/dprc.1/rescan

Signed-off-by: Lijun Pan <Lijun.Pan@freescale.com>
---
 drivers/staging/fsl-mc/bus/mc-bus.c | 43 +++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)

diff --git a/drivers/staging/fsl-mc/bus/mc-bus.c b/drivers/staging/fsl-mc/bus/mc-bus.c
index 25e205421..61d44fd 100644
--- a/drivers/staging/fsl-mc/bus/mc-bus.c
+++ b/drivers/staging/fsl-mc/bus/mc-bus.c
@@ -100,10 +100,53 @@ static int fsl_mc_bus_uevent(struct device *dev, struct kobj_uevent_env *env)
 	return 0;
 }
 
+static ssize_t rescan_store(struct device *dev,
+			    struct device_attribute *attr,
+			    const char *buf, size_t count)
+{
+	unsigned long val;
+	struct fsl_mc_device *root_mc_dev;
+	struct fsl_mc_bus *root_mc_bus;
+
+	if (!is_root_dprc(dev))
+		return -EINVAL;
+
+	root_mc_dev = to_fsl_mc_device(dev);
+	root_mc_bus = to_fsl_mc_bus(root_mc_dev);
+
+	if (kstrtoul(buf, 0, &val) < 0)
+		return -EINVAL;
+
+	if (val) {
+		mutex_lock(&root_mc_bus->scan_mutex);
+		dprc_scan_objects(root_mc_dev);
+		mutex_unlock(&root_mc_bus->scan_mutex);
+	}
+
+	return count;
+}
+
+static DEVICE_ATTR_WO(rescan);
+
+static struct attribute *fsl_mc_dev_attrs[] = {
+	&dev_attr_rescan.attr,
+	NULL,
+};
+
+static const struct attribute_group fsl_mc_dev_group = {
+	.attrs = fsl_mc_dev_attrs,
+};
+
+static const struct attribute_group *fsl_mc_dev_groups[] = {
+	&fsl_mc_dev_group,
+	NULL,
+};
+
 struct bus_type fsl_mc_bus_type = {
 	.name = "fsl-mc",
 	.match = fsl_mc_bus_match,
 	.uevent = fsl_mc_bus_uevent,
+	.dev_groups = fsl_mc_dev_groups,
 };
 EXPORT_SYMBOL_GPL(fsl_mc_bus_type);
 
-- 
2.3.3


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v2 5/8] staging: fsl-mc: fsl-mc bus's sysfs rescan documentation
  2015-10-30 19:32 [PATCH v2 0/8] Management Complex restool driver Lijun Pan
                   ` (3 preceding siblings ...)
  2015-10-30 19:32 ` [PATCH v2 4/8] staging: fsl-mc: root dprc rescan attribute to sync kernel with MC Lijun Pan
@ 2015-10-30 19:32 ` Lijun Pan
  2015-10-30 19:32 ` [PATCH v2 6/8] staging: fsl-mc: bus rescan attribute to sync kernel with MC Lijun Pan
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Lijun Pan @ 2015-10-30 19:32 UTC (permalink / raw)
  To: gregkh, arnd, devel, linux-kernel
  Cc: stuart.yoder, itai.katz, german.rivera, leoli, scottwood, agraf,
	bhamciu1, R89243, bhupesh.sharma, nir.erez, richard.schmitt,
	dan.carpenter, Lijun Pan

Add the sysfs documentation for the rescan attribute of
fsl-mc bus.

Signed-off-by: Lijun Pan <Lijun.Pan@freescale.com>
---
 Documentation/ABI/testing/sysfs-bus-fsl-mc | 11 +++++++++++
 1 file changed, 11 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-bus-fsl-mc

diff --git a/Documentation/ABI/testing/sysfs-bus-fsl-mc b/Documentation/ABI/testing/sysfs-bus-fsl-mc
new file mode 100644
index 0000000..3fa747c
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-bus-fsl-mc
@@ -0,0 +1,11 @@
+What:		/sys/bus/fsl-mc/rescan
+Date:		October 2015
+Contact:	Lijun Pan <Lijun.Pan@freescale.com>
+Description:
+		Writing a non-zero value to this attribute will
+		force a rescan of fsl-mc bus in the system, and
+		add/remove previously added/removed objects in
+		Management Complex firmwarer, i.e., synchronize
+		the objects under fsl-mc bus and Management Complex
+		firmware. For example:
+		# echo 1 > /sys/bus/fsl-mc/rescan
-- 
2.3.3


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v2 6/8] staging: fsl-mc: bus rescan attribute to sync kernel with MC
  2015-10-30 19:32 [PATCH v2 0/8] Management Complex restool driver Lijun Pan
                   ` (4 preceding siblings ...)
  2015-10-30 19:32 ` [PATCH v2 5/8] staging: fsl-mc: fsl-mc bus's sysfs rescan documentation Lijun Pan
@ 2015-10-30 19:32 ` Lijun Pan
  2015-10-30 19:32 ` [PATCH v2 7/8] staging: fsl-mc: update TODO and README for restool driver Lijun Pan
  2015-10-30 19:32 ` [PATCH v2 8/8] staging: fsl-mc: Management Complex " Lijun Pan
  7 siblings, 0 replies; 9+ messages in thread
From: Lijun Pan @ 2015-10-30 19:32 UTC (permalink / raw)
  To: gregkh, arnd, devel, linux-kernel
  Cc: stuart.yoder, itai.katz, german.rivera, leoli, scottwood, agraf,
	bhamciu1, R89243, bhupesh.sharma, nir.erez, richard.schmitt,
	dan.carpenter, Lijun Pan

Introduce the rescan attribute as a bus attribute to
synchronize the fsl-mc bus objects and the MC firmware.

To rescan the fsl-mc bus, e.g.,
echo 1 > /sys/bus/fsl-mc/rescan

Signed-off-by: Lijun Pan <Lijun.Pan@freescale.com>
---
 drivers/staging/fsl-mc/bus/mc-bus.c | 46 +++++++++++++++++++++++++++++++++++++
 1 file changed, 46 insertions(+)

diff --git a/drivers/staging/fsl-mc/bus/mc-bus.c b/drivers/staging/fsl-mc/bus/mc-bus.c
index 61d44fd..f9ee5fe 100644
--- a/drivers/staging/fsl-mc/bus/mc-bus.c
+++ b/drivers/staging/fsl-mc/bus/mc-bus.c
@@ -142,11 +142,57 @@ static const struct attribute_group *fsl_mc_dev_groups[] = {
 	NULL,
 };
 
+static int scan_fsl_mc_bus(struct device *dev, void *data)
+{
+	struct fsl_mc_device *root_mc_dev;
+	struct fsl_mc_bus *root_mc_bus;
+
+	if (is_root_dprc(dev)) {
+		root_mc_dev = to_fsl_mc_device(dev);
+		root_mc_bus = to_fsl_mc_bus(root_mc_dev);
+		mutex_lock(&root_mc_bus->scan_mutex);
+		dprc_scan_objects(root_mc_dev);
+		mutex_unlock(&root_mc_bus->scan_mutex);
+	}
+
+	return 0;
+}
+
+static ssize_t bus_rescan_store(struct bus_type *bus,
+				const char *buf, size_t count)
+{
+	unsigned long val;
+
+	if (kstrtoul(buf, 0, &val) < 0)
+		return -EINVAL;
+
+	if (val)
+		bus_for_each_dev(bus, NULL, NULL, scan_fsl_mc_bus);
+
+	return count;
+}
+static BUS_ATTR(rescan, (S_IWUSR | S_IWGRP), NULL, bus_rescan_store);
+
+static struct attribute *fsl_mc_bus_attrs[] = {
+	&bus_attr_rescan.attr,
+	NULL,
+};
+
+static const struct attribute_group fsl_mc_bus_group = {
+	.attrs = fsl_mc_bus_attrs,
+};
+
+static const struct attribute_group *fsl_mc_bus_groups[] = {
+	&fsl_mc_bus_group,
+	NULL,
+};
+
 struct bus_type fsl_mc_bus_type = {
 	.name = "fsl-mc",
 	.match = fsl_mc_bus_match,
 	.uevent = fsl_mc_bus_uevent,
 	.dev_groups = fsl_mc_dev_groups,
+	.bus_groups = fsl_mc_bus_groups,
 };
 EXPORT_SYMBOL_GPL(fsl_mc_bus_type);
 
-- 
2.3.3


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v2 7/8] staging: fsl-mc: update TODO and README for restool driver
  2015-10-30 19:32 [PATCH v2 0/8] Management Complex restool driver Lijun Pan
                   ` (5 preceding siblings ...)
  2015-10-30 19:32 ` [PATCH v2 6/8] staging: fsl-mc: bus rescan attribute to sync kernel with MC Lijun Pan
@ 2015-10-30 19:32 ` Lijun Pan
  2015-10-30 19:32 ` [PATCH v2 8/8] staging: fsl-mc: Management Complex " Lijun Pan
  7 siblings, 0 replies; 9+ messages in thread
From: Lijun Pan @ 2015-10-30 19:32 UTC (permalink / raw)
  To: gregkh, arnd, devel, linux-kernel
  Cc: stuart.yoder, itai.katz, german.rivera, leoli, scottwood, agraf,
	bhamciu1, R89243, bhupesh.sharma, nir.erez, richard.schmitt,
	dan.carpenter, Lijun Pan

Add more introduction of restool driver and state why
restool driver is needed in helping moving fsl-mc bus
out of staging tree.

Signed-off-by: Lijun Pan <Lijun.Pan@freescale.com>
---
 drivers/staging/fsl-mc/README.txt | 11 ++++++++++-
 drivers/staging/fsl-mc/TODO       | 18 ++++++++++++++++--
 2 files changed, 26 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/fsl-mc/README.txt b/drivers/staging/fsl-mc/README.txt
index 8214102..e9ec507 100644
--- a/drivers/staging/fsl-mc/README.txt
+++ b/drivers/staging/fsl-mc/README.txt
@@ -130,7 +130,16 @@ the objects involved in creating a network interfaces.
     via a config file passed to the MC when firmware starts
     it.  There is also a Linux user space tool called "restool"
     that can be used to create/destroy containers and objects
-    dynamically.
+    dynamically. The kernel side restool driver communicates with
+    user space restool via ioctl. Restool relies on allocator driver
+    to allocate dpmcp resources, enumerates fsl-mc bus to find root dprc
+    objects of interest. When the user space restool program sends a request
+    to restool driver to create a dp* objects in MC firmware, an interrupt
+    will be triggered by MC firmware and the dprc driver's interrupt handler
+    shall process the interrupt (synchronizing the objects in MC firmware and
+    objects in Linux kernel). Though small, restool driver helps verify all
+    the functionality of fsl-mc bus, dprc driver, allocator driver,
+    and MC flib API.
 
 -DPAA2 Objects for an Ethernet Network Interface
 
diff --git a/drivers/staging/fsl-mc/TODO b/drivers/staging/fsl-mc/TODO
index 5065821..4892eb6 100644
--- a/drivers/staging/fsl-mc/TODO
+++ b/drivers/staging/fsl-mc/TODO
@@ -5,10 +5,24 @@
   fsl-mc bus out of staging.
 
 * Decide if multiple root fsl-mc buses will be supported per Linux instance,
-  and if so add support for this.
+  and if so add support for this. No matter fsl-mc bus support multiple root
+  dprc or not, restool driver is designed to support multiple root if fsl-mc
+  bus is ready some day later. If there is only one root dprc, restool driver
+  works fine.
+
+* Add at least one driver utilizing fsl-mc bus. Restool driver is a very
+  small and simple driver, which interacts with fsl-mc bus, dprc driver,
+  allocator driver. Restool relies on allocator driver to allocate
+  dpmcp resources, enumerates fsl-mc bus to find root dprc objects of interest.
+  When the user space restool program sends a request to restool driver to
+  create a dp* objects in MC firmware, an interrupt will be triggered by
+  MC firmware and the dprc driver's interrupt handler shall process the
+  interrupt. Though small, restool driver helps verify all the functionality
+  of fsl-mc bus, dprc driver, allocator driver, and MC flib API. Restool
+  driver helps in moving fsl-mc bus out of staging branch.
 
 * Add at least one device driver for a DPAA2 object (child device of the
-  fsl-mc bus).  Most likely candidate for this is adding DPAA2 Ethernet
+  fsl-mc bus). Most likely candidate for this is adding DPAA2 Ethernet
   driver support, which depends on drivers for several objects: DPNI,
   DPIO, DPMAC.  Other pre-requisites include:
 
-- 
2.3.3


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v2 8/8] staging: fsl-mc: Management Complex restool driver
  2015-10-30 19:32 [PATCH v2 0/8] Management Complex restool driver Lijun Pan
                   ` (6 preceding siblings ...)
  2015-10-30 19:32 ` [PATCH v2 7/8] staging: fsl-mc: update TODO and README for restool driver Lijun Pan
@ 2015-10-30 19:32 ` Lijun Pan
  7 siblings, 0 replies; 9+ messages in thread
From: Lijun Pan @ 2015-10-30 19:32 UTC (permalink / raw)
  To: gregkh, arnd, devel, linux-kernel
  Cc: stuart.yoder, itai.katz, german.rivera, leoli, scottwood, agraf,
	bhamciu1, R89243, bhupesh.sharma, nir.erez, richard.schmitt,
	dan.carpenter, Lijun Pan

The kernel support for the restool (a user space resource management
tool) is a driver for the /dev/dprc.N device file.
Its purpose is to provide an ioctl interface,
which the restool uses to interact with the MC bus driver
and with the MC firmware.
We allocate a dpmcp at driver initialization,
and keep that dpmcp until driver exit.
We use that dpmcp by default.
If that dpmcp is in use, we create another portal at run time
and destroy the newly created portal after use.
The ioctl RESTOOL_SEND_MC_COMMAND sends user space command to fsl-mc
bus and utilizes the fsl-mc bus to communicate with MC firmware.
The ioctl RESTOOL_DPRC_SYNC request the mc-bus launch
objects scan under root dprc.
In order to support multiple root dprc, we utilize the bus notify
mechanism to scan fsl_mc_bus_type for the newly added root dprc.
After discovering the root dprc, it creates a miscdevice
/dev/dprc.N to associate with this root dprc.

Signed-off-by: Lijun Pan <Lijun.Pan@freescale.com>
---
v2:
    remove verbose printk
    improve error handling
    synchronize misc_list access
    reserve ioctl range in Documentation/ioctl/ioctl-number.txt
    remove ioctl sync command
    flip if(!...) to make them fit in 80 columns
    change if(x==NULL) to if(!x)
    change ("int error = 0;" initialization) to (int error;)
	

 Documentation/ioctl/ioctl-number.txt    |   1 +
 drivers/staging/fsl-mc/bus/Kconfig      |   7 +-
 drivers/staging/fsl-mc/bus/Makefile     |   3 +
 drivers/staging/fsl-mc/bus/mc-ioctl.h   |  22 ++
 drivers/staging/fsl-mc/bus/mc-restool.c | 392 ++++++++++++++++++++++++++++++++
 5 files changed, 424 insertions(+), 1 deletion(-)
 create mode 100644 drivers/staging/fsl-mc/bus/mc-ioctl.h
 create mode 100644 drivers/staging/fsl-mc/bus/mc-restool.c

diff --git a/Documentation/ioctl/ioctl-number.txt b/Documentation/ioctl/ioctl-number.txt
index df1b25e..3e83fe9 100644
--- a/Documentation/ioctl/ioctl-number.txt
+++ b/Documentation/ioctl/ioctl-number.txt
@@ -166,6 +166,7 @@ Code  Seq#(hex)	Include File		Comments
 'R'	00-1F	linux/random.h		conflict!
 'R'	01	linux/rfkill.h		conflict!
 'R'	C0-DF	net/bluetooth/rfcomm.h
+'R'	E0-EF	drivers/staging/fsl-mc/bus/mc-ioctl.h
 'S'	all	linux/cdrom.h		conflict!
 'S'	80-81	scsi/scsi_ioctl.h	conflict!
 'S'	82-FF	scsi/scsi.h		conflict!
diff --git a/drivers/staging/fsl-mc/bus/Kconfig b/drivers/staging/fsl-mc/bus/Kconfig
index 0d779d9..39c6ef9 100644
--- a/drivers/staging/fsl-mc/bus/Kconfig
+++ b/drivers/staging/fsl-mc/bus/Kconfig
@@ -21,4 +21,9 @@ config FSL_MC_BUS
 	  Only enable this option when building the kernel for
 	  Freescale QorQIQ LS2xxxx SoCs.
 
-
+config FSL_MC_RESTOOL
+        tristate "Freescale Management Complex (MC) restool driver"
+        depends on FSL_MC_BUS
+        help
+          Driver that provides kernel support for the Freescale Management
+	  Complex resource manager user-space tool.
diff --git a/drivers/staging/fsl-mc/bus/Makefile b/drivers/staging/fsl-mc/bus/Makefile
index 25433a9..28b5fc0 100644
--- a/drivers/staging/fsl-mc/bus/Makefile
+++ b/drivers/staging/fsl-mc/bus/Makefile
@@ -15,3 +15,6 @@ mc-bus-driver-objs := mc-bus.o \
 		      mc-allocator.o \
 		      dpmcp.o \
 		      dpbp.o
+
+# MC restool kernel support
+obj-$(CONFIG_FSL_MC_RESTOOL) += mc-restool.o
diff --git a/drivers/staging/fsl-mc/bus/mc-ioctl.h b/drivers/staging/fsl-mc/bus/mc-ioctl.h
new file mode 100644
index 0000000..8ac502a
--- /dev/null
+++ b/drivers/staging/fsl-mc/bus/mc-ioctl.h
@@ -0,0 +1,22 @@
+/*
+ * Freescale Management Complex (MC) ioclt interface
+ *
+ * Copyright (C) 2014 Freescale Semiconductor, Inc.
+ * Author: Lijun Pan <Lijun.Pan@freescale.com>
+ *
+ * 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_IOCTL_H_
+#define _FSL_MC_IOCTL_H_
+
+#include <linux/ioctl.h>
+#include "../include/mc-sys.h"
+
+#define RESTOOL_IOCTL_TYPE   'R'
+
+#define RESTOOL_SEND_MC_COMMAND \
+	_IOWR(RESTOOL_IOCTL_TYPE, 0xE0, struct mc_command)
+
+#endif /* _FSL_MC_IOCTL_H_ */
diff --git a/drivers/staging/fsl-mc/bus/mc-restool.c b/drivers/staging/fsl-mc/bus/mc-restool.c
new file mode 100644
index 0000000..57f059a
--- /dev/null
+++ b/drivers/staging/fsl-mc/bus/mc-restool.c
@@ -0,0 +1,392 @@
+/*
+ * Freescale Management Complex (MC) restool driver
+ *
+ * Copyright (C) 2014 Freescale Semiconductor, Inc.
+ * Author: Lijun Pan <Lijun.Pan@freescale.com>
+ *
+ * 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.
+ */
+
+#include "../include/mc-private.h"
+#include <linux/module.h>
+#include <linux/fs.h>
+#include <linux/miscdevice.h>
+#include <linux/mm.h>
+#include <linux/slab.h>
+#include <linux/uaccess.h>
+#include <linux/mutex.h>
+#include <linux/platform_device.h>
+#include "mc-ioctl.h"
+#include "../include/mc-sys.h"
+#include "../include/mc-cmd.h"
+#include "../include/dpmng.h"
+
+/**
+ * Maximum number of DPRCs that can be opened at the same time
+ */
+#define MAX_DPRC_HANDLES	    64
+
+/**
+ * restool_misc - information associated with the newly added miscdevice
+ * @misc: newly created miscdevice associated with root dprc
+ * @miscdevt: device id of this miscdevice
+ * @list: a linked list node representing this miscdevcie
+ * @static_mc_io: pointer to the static MC I/O object used by the restool
+ * @dynamic_instance_count: number of dynamically created instances
+ * @static_instance_in_use: static instance is in use or not
+ * @mutex: mutex lock to serialze the open/release operations
+ * @dev: root dprc associated with this miscdevice
+ */
+struct restool_misc {
+	struct miscdevice misc;
+	dev_t miscdevt;
+	struct list_head list;
+	struct fsl_mc_io *static_mc_io;
+	u32 dynamic_instance_count;
+	bool static_instance_in_use;
+	struct mutex mutex; /* serialze the open/release operations */
+	struct device *dev;
+};
+
+/*
+ * initialize a global list to link all
+ * the miscdevice nodes (struct restool_misc)
+ */
+static LIST_HEAD(misc_list);
+static DEFINE_MUTEX(misc_list_mutex);
+
+static int fsl_mc_restool_dev_open(struct inode *inode, struct file *filep)
+{
+	struct fsl_mc_device *root_mc_dev;
+	int error;
+	struct fsl_mc_io *dynamic_mc_io = NULL;
+	struct restool_misc *restool_misc = NULL;
+	struct restool_misc *restool_misc_cursor;
+
+	mutex_lock(&misc_list_mutex);
+
+	list_for_each_entry(restool_misc_cursor, &misc_list, list) {
+		if (restool_misc_cursor->miscdevt == inode->i_rdev) {
+			restool_misc = restool_misc_cursor;
+			break;
+		}
+	}
+
+	mutex_unlock(&misc_list_mutex);
+
+	if (!restool_misc)
+		return -EINVAL;
+
+	if (WARN_ON(!restool_misc->dev))
+		return -EINVAL;
+
+	mutex_lock(&restool_misc->mutex);
+
+	if (!restool_misc->static_instance_in_use) {
+		restool_misc->static_instance_in_use = true;
+		filep->private_data = restool_misc->static_mc_io;
+	} else {
+		dynamic_mc_io = kzalloc(sizeof(*dynamic_mc_io), GFP_KERNEL);
+		if (!dynamic_mc_io) {
+			error = -ENOMEM;
+			goto err_unlock;
+		}
+
+		root_mc_dev = to_fsl_mc_device(restool_misc->dev);
+		error = fsl_mc_portal_allocate(root_mc_dev, 0, &dynamic_mc_io);
+		if (error < 0) {
+			pr_err("Not able to allocate MC portal\n");
+			goto free_dynamic_mc_io;
+		}
+		++restool_misc->dynamic_instance_count;
+		filep->private_data = dynamic_mc_io;
+	}
+
+	mutex_unlock(&restool_misc->mutex);
+
+	return 0;
+
+free_dynamic_mc_io:
+	kfree(dynamic_mc_io);
+err_unlock:
+	mutex_unlock(&restool_misc->mutex);
+
+	return error;
+}
+
+static int fsl_mc_restool_dev_release(struct inode *inode, struct file *filep)
+{
+	struct fsl_mc_io *local_mc_io = filep->private_data;
+	struct restool_misc *restool_misc = NULL;
+	struct restool_misc *restool_misc_cursor;
+
+	if (WARN_ON(!filep->private_data))
+		return -EINVAL;
+
+	mutex_lock(&misc_list_mutex);
+
+	list_for_each_entry(restool_misc_cursor, &misc_list, list) {
+		if (restool_misc_cursor->miscdevt == inode->i_rdev) {
+			restool_misc = restool_misc_cursor;
+			break;
+		}
+	}
+
+	mutex_unlock(&misc_list_mutex);
+
+	if (!restool_misc)
+		return -EINVAL;
+
+	mutex_lock(&restool_misc->mutex);
+
+	if (WARN_ON(restool_misc->dynamic_instance_count == 0 &&
+		    !restool_misc->static_instance_in_use)) {
+		mutex_unlock(&restool_misc->mutex);
+		return -EINVAL;
+	}
+
+	/* Globally clean up opened/untracked handles */
+	fsl_mc_portal_reset(local_mc_io);
+
+	/*
+	 * must check
+	 * whether local_mc_io is dynamic or static instance
+	 * Otherwise it will free up the reserved portal by accident
+	 * or even not free up the dynamic allocated portal
+	 * if 2 or more instances running concurrently
+	 */
+	if (local_mc_io == restool_misc->static_mc_io) {
+		restool_misc->static_instance_in_use = false;
+	} else {
+		fsl_mc_portal_free(local_mc_io);
+		kfree(filep->private_data);
+		--restool_misc->dynamic_instance_count;
+	}
+
+	filep->private_data = NULL;
+	mutex_unlock(&restool_misc->mutex);
+
+	return 0;
+}
+
+static int restool_send_mc_command(unsigned long arg,
+				   struct fsl_mc_io *local_mc_io)
+{
+	int error;
+	struct mc_command mc_cmd;
+
+	if (copy_from_user(&mc_cmd, (void __user *)arg, sizeof(mc_cmd)))
+		return -EFAULT;
+
+	/*
+	 * Send MC command to the MC:
+	 */
+	error = mc_send_command(local_mc_io, &mc_cmd);
+	if (error < 0)
+		return error;
+
+	if (copy_to_user((void __user *)arg, &mc_cmd, sizeof(mc_cmd)))
+		return -EFAULT;
+
+	return 0;
+}
+
+static long
+fsl_mc_restool_dev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
+{
+	int error;
+
+	switch (cmd) {
+	case RESTOOL_SEND_MC_COMMAND:
+		error = restool_send_mc_command(arg, file->private_data);
+		break;
+	default:
+		pr_err("%s: unexpected ioctl call number\n", __func__);
+		error = -EINVAL;
+	}
+
+	return error;
+}
+
+static const struct file_operations fsl_mc_restool_dev_fops = {
+	.owner = THIS_MODULE,
+	.open = fsl_mc_restool_dev_open,
+	.release = fsl_mc_restool_dev_release,
+	.unlocked_ioctl = fsl_mc_restool_dev_ioctl,
+};
+
+static int restool_add_device_file(struct device *dev)
+{
+	u32 name1 = 0;
+	char name2[20] = {0};
+	int error;
+	struct fsl_mc_device *root_mc_dev;
+	struct restool_misc *restool_misc;
+
+	if (dev->bus == &platform_bus_type && dev->driver_data) {
+		if (sscanf(dev_name(dev), "%x.%s", &name1, name2) != 2)
+			return -EINVAL;
+
+		if (strcmp(name2, "fsl-mc") == 0)
+			pr_debug("platform's root dprc name is: %s\n",
+				 dev_name(&(((struct fsl_mc *)
+				 (dev->driver_data))->root_mc_bus_dev->dev)));
+	}
+
+	if (!is_root_dprc(dev))
+		return 0;
+
+	restool_misc = kzalloc(sizeof(*restool_misc), GFP_KERNEL);
+	if (!restool_misc)
+		return -ENOMEM;
+
+	restool_misc->dev = dev;
+	root_mc_dev = to_fsl_mc_device(dev);
+	error = fsl_mc_portal_allocate(root_mc_dev, 0,
+				       &restool_misc->static_mc_io);
+	if (error < 0) {
+		pr_err("Not able to allocate MC portal\n");
+		goto free_restool_misc;
+	}
+
+	restool_misc->misc.minor = MISC_DYNAMIC_MINOR;
+	restool_misc->misc.name = dev_name(dev);
+	restool_misc->misc.fops = &fsl_mc_restool_dev_fops;
+
+	error = misc_register(&restool_misc->misc);
+	if (error < 0) {
+		pr_err("misc_register() failed: %d\n", error);
+		goto free_portal;
+	}
+
+	restool_misc->miscdevt = restool_misc->misc.this_device->devt;
+	mutex_init(&restool_misc->mutex);
+	mutex_lock(&misc_list_mutex);
+	list_add(&restool_misc->list, &misc_list);
+	mutex_unlock(&misc_list_mutex);
+
+	pr_info("/dev/%s driver registered\n", dev_name(dev));
+
+	return 0;
+
+free_portal:
+	fsl_mc_portal_free(restool_misc->static_mc_io);
+free_restool_misc:
+	kfree(restool_misc);
+
+	return error;
+}
+
+static int restool_bus_notifier(struct notifier_block *nb,
+				unsigned long action, void *data)
+{
+	int error;
+	struct device *dev = data;
+
+	switch (action) {
+	case BUS_NOTIFY_ADD_DEVICE:
+		error = restool_add_device_file(dev);
+		if (error)
+			return error;
+		break;
+	case BUS_NOTIFY_DEL_DEVICE:
+	case BUS_NOTIFY_REMOVED_DEVICE:
+	case BUS_NOTIFY_BIND_DRIVER:
+	case BUS_NOTIFY_BOUND_DRIVER:
+	case BUS_NOTIFY_UNBIND_DRIVER:
+	case BUS_NOTIFY_UNBOUND_DRIVER:
+		break;
+	default:
+		pr_err("%s: unrecognized device action from %s\n", __func__,
+		       dev_name(dev));
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+static int add_to_restool(struct device *dev, void *data)
+{
+	return restool_add_device_file(dev);
+}
+
+static int __init fsl_mc_restool_driver_init(void)
+{
+	int error;
+	struct notifier_block *nb;
+
+	nb = kzalloc(sizeof(*nb), GFP_KERNEL);
+	if (!nb)
+		return -ENOMEM;
+
+	nb->notifier_call = restool_bus_notifier;
+	error = bus_register_notifier(&fsl_mc_bus_type, nb);
+	if (error)
+		goto free_nb;
+
+	/*
+	 * This driver runs after fsl-mc bus driver runs.
+	 * Hence, many of the root dprcs are already attached to fsl-mc bus
+	 * In order to make sure we find all the root dprcs,
+	 * we need to scan the fsl_mc_bus_type.
+	 */
+	error  = bus_for_each_dev(&fsl_mc_bus_type, NULL, NULL, add_to_restool);
+	if (error) {
+		bus_unregister_notifier(&fsl_mc_bus_type, nb);
+		kfree(nb);
+		pr_err("restool driver registration failure\n");
+		return error;
+	}
+
+	return 0;
+
+free_nb:
+	kfree(nb);
+	return error;
+}
+
+module_init(fsl_mc_restool_driver_init);
+
+static void __exit fsl_mc_restool_driver_exit(void)
+{
+	struct restool_misc *restool_misc;
+	struct restool_misc *restool_misc_tmp;
+	char name1[20] = {0};
+	u32 name2 = 0;
+
+	list_for_each_entry_safe(restool_misc, restool_misc_tmp,
+				 &misc_list, list) {
+		if (sscanf(restool_misc->misc.name, "%4s.%u", name1, &name2)
+		    != 2)
+			continue;
+
+		pr_debug("name1=%s,name2=%u\n", name1, name2);
+		pr_debug("misc-device: %s\n", restool_misc->misc.name);
+		if (strcmp(name1, "dprc") != 0)
+			continue;
+
+		if (WARN_ON(!restool_misc->static_mc_io))
+			return;
+
+		if (WARN_ON(restool_misc->dynamic_instance_count != 0))
+			return;
+
+		if (WARN_ON(restool_misc->static_instance_in_use))
+			return;
+
+		misc_deregister(&restool_misc->misc);
+		pr_info("/dev/%s driver unregistered\n",
+			restool_misc->misc.name);
+		fsl_mc_portal_free(restool_misc->static_mc_io);
+		list_del(&restool_misc->list);
+		kfree(restool_misc);
+	}
+}
+
+module_exit(fsl_mc_restool_driver_exit);
+
+MODULE_AUTHOR("Freescale Semiconductor Inc.");
+MODULE_DESCRIPTION("Freescale's MC restool driver");
+MODULE_LICENSE("GPL");
-- 
2.3.3


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2015-10-30 20:02 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-10-30 19:32 [PATCH v2 0/8] Management Complex restool driver Lijun Pan
2015-10-30 19:32 ` [PATCH v2 1/8] staging: fsl-mc: static inline function to differentiate root dprc Lijun Pan
2015-10-30 19:32 ` [PATCH v2 2/8] staging: fsl-mc: add sysfs rescan attribute in TODO Lijun Pan
2015-10-30 19:32 ` [PATCH v3 3/8] staging: fsl-mc: dprc device's sysfs rescan documentation Lijun Pan
2015-10-30 19:32 ` [PATCH v2 4/8] staging: fsl-mc: root dprc rescan attribute to sync kernel with MC Lijun Pan
2015-10-30 19:32 ` [PATCH v2 5/8] staging: fsl-mc: fsl-mc bus's sysfs rescan documentation Lijun Pan
2015-10-30 19:32 ` [PATCH v2 6/8] staging: fsl-mc: bus rescan attribute to sync kernel with MC Lijun Pan
2015-10-30 19:32 ` [PATCH v2 7/8] staging: fsl-mc: update TODO and README for restool driver Lijun Pan
2015-10-30 19:32 ` [PATCH v2 8/8] staging: fsl-mc: Management Complex " Lijun Pan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).