linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/5] soc: fsl: add device links support for devices on the fsl-mc bus
@ 2018-12-10 16:50 Ioana Ciornei
  2018-12-10 16:50 ` [PATCH 1/5] soc: fsl: dpio: perform DPIO Reset on Probe Ioana Ciornei
                   ` (5 more replies)
  0 siblings, 6 replies; 9+ messages in thread
From: Ioana Ciornei @ 2018-12-10 16:50 UTC (permalink / raw)
  To: Leo Li, linux-kernel, linux-arm-kernel, netdev
  Cc: Laurentiu Tudor, Horia Geanta, Ioana Ciocoi Radulescu,
	Roy Pledge, Ioana Ciornei

The fsl-mc bus discovers and exports devices dynamically allocated
by the Management Complex firmware.
This patch set adds the ability to automatically create a device link
between a consumer device on the fsl-mc bus and a supplier one.
For example, a dpni device (a network interface) requests access to a
dpio device (I/O portal) using the dpaa2_io_service_register function
which is enhanced to also add the corresponding device link between
them.

The first 3 patches set the stage for a proper handling of device
links while the following 2 are the ones that add the actual links.

The internal management of the links is not exported to the consumer
driver, but it's rather included in the functions that actually allocate
the provider device: fsl_mc_portal_allocate, fsl_mc_object_allocate and
dpaa2_io_service_register.

Ioana Ciornei (4):
  soc: fsl: dpio: keep a per dpio device MC portal
  soc: fsl: dpio: store a backpointer to the device backing the dpaa2_io
  soc: fsl: dpio: add a device_link at dpaa2_io_service_register
  bus: fsl-mc: automatically add a device_link on
    fsl_mc_[portal,object]_allocate

Roy Pledge (1):
  soc: fsl: dpio: perform DPIO Reset on Probe

 drivers/bus/fsl-mc/fsl-mc-allocator.c            | 11 +++++++++++
 drivers/bus/fsl-mc/mc-io.c                       | 13 +++++++++++++
 drivers/crypto/caam/caamalg_qi2.c                |  6 +++---
 drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.c |  9 +++++----
 drivers/soc/fsl/dpio/dpio-cmd.h                  |  1 +
 drivers/soc/fsl/dpio/dpio-driver.c               | 18 +++++++++---------
 drivers/soc/fsl/dpio/dpio-service.c              | 23 ++++++++++++++++++++---
 drivers/soc/fsl/dpio/dpio.c                      | 23 +++++++++++++++++++++++
 drivers/soc/fsl/dpio/dpio.h                      |  4 ++++
 include/linux/fsl/mc.h                           |  1 +
 include/soc/fsl/dpaa2-io.h                       |  9 ++++++---
 11 files changed, 96 insertions(+), 22 deletions(-)

-- 
1.9.1


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

* [PATCH 1/5] soc: fsl: dpio: perform DPIO Reset on Probe
  2018-12-10 16:50 [PATCH 0/5] soc: fsl: add device links support for devices on the fsl-mc bus Ioana Ciornei
@ 2018-12-10 16:50 ` Ioana Ciornei
  2018-12-10 16:50 ` [PATCH 2/5] soc: fsl: dpio: keep a per dpio device MC portal Ioana Ciornei
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 9+ messages in thread
From: Ioana Ciornei @ 2018-12-10 16:50 UTC (permalink / raw)
  To: Leo Li, linux-kernel, linux-arm-kernel, netdev
  Cc: Laurentiu Tudor, Horia Geanta, Ioana Ciocoi Radulescu,
	Roy Pledge, Roy Pledge

From: Roy Pledge <roy.pledge@nxp.com>

Invoke a DPIO reset command when a DPIO device is probed. This
will ensure the QBMan portal is in the state the driver expects.

Signed-off-by: Roy Pledge <roy.pledge@nxp.com>
---
 drivers/soc/fsl/dpio/dpio-cmd.h    |  1 +
 drivers/soc/fsl/dpio/dpio-driver.c |  7 +++++++
 drivers/soc/fsl/dpio/dpio.c        | 23 +++++++++++++++++++++++
 drivers/soc/fsl/dpio/dpio.h        |  4 ++++
 4 files changed, 35 insertions(+)

diff --git a/drivers/soc/fsl/dpio/dpio-cmd.h b/drivers/soc/fsl/dpio/dpio-cmd.h
index ab8f82e..5814d2f 100644
--- a/drivers/soc/fsl/dpio/dpio-cmd.h
+++ b/drivers/soc/fsl/dpio/dpio-cmd.h
@@ -25,6 +25,7 @@
 #define DPIO_CMDID_ENABLE				DPIO_CMD(0x002)
 #define DPIO_CMDID_DISABLE				DPIO_CMD(0x003)
 #define DPIO_CMDID_GET_ATTR				DPIO_CMD(0x004)
+#define DPIO_CMDID_RESET				DPIO_CMD(0x005)
 
 struct dpio_cmd_open {
 	__le32 dpio_id;
diff --git a/drivers/soc/fsl/dpio/dpio-driver.c b/drivers/soc/fsl/dpio/dpio-driver.c
index 832175c..38ee9db 100644
--- a/drivers/soc/fsl/dpio/dpio-driver.c
+++ b/drivers/soc/fsl/dpio/dpio-driver.c
@@ -110,6 +110,12 @@ static int dpaa2_dpio_probe(struct fsl_mc_device *dpio_dev)
 		goto err_open;
 	}
 
+	err = dpio_reset(dpio_dev->mc_io, 0, dpio_dev->mc_handle);
+	if (err) {
+		dev_err(dev, "dpio_reset() failed\n");
+		goto err_reset;
+	}
+
 	err = dpio_get_attributes(dpio_dev->mc_io, 0, dpio_dev->mc_handle,
 				  &dpio_attrs);
 	if (err) {
@@ -192,6 +198,7 @@ static int dpaa2_dpio_probe(struct fsl_mc_device *dpio_dev)
 err_allocate_irqs:
 	dpio_disable(dpio_dev->mc_io, 0, dpio_dev->mc_handle);
 err_get_attr:
+err_reset:
 	dpio_close(dpio_dev->mc_io, 0, dpio_dev->mc_handle);
 err_open:
 	fsl_mc_portal_free(dpio_dev->mc_io);
diff --git a/drivers/soc/fsl/dpio/dpio.c b/drivers/soc/fsl/dpio/dpio.c
index ff37c80..521bc69 100644
--- a/drivers/soc/fsl/dpio/dpio.c
+++ b/drivers/soc/fsl/dpio/dpio.c
@@ -196,3 +196,26 @@ int dpio_get_api_version(struct fsl_mc_io *mc_io,
 
 	return 0;
 }
+
+/**
+ * dpio_reset() - Reset the DPIO, returns the object to initial state.
+ * @mc_io:	Pointer to MC portal's I/O object
+ * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
+ * @token:	Token of DPIO object
+ *
+ * Return:	'0' on Success; Error code otherwise.
+ */
+int dpio_reset(struct fsl_mc_io *mc_io,
+	       u32 cmd_flags,
+	       u16 token)
+{
+	struct fsl_mc_command cmd = { 0 };
+
+	/* prepare command */
+	cmd.header = mc_encode_cmd_header(DPIO_CMDID_RESET,
+					  cmd_flags,
+					  token);
+
+	/* send command to mc*/
+	return mc_send_command(mc_io, &cmd);
+}
diff --git a/drivers/soc/fsl/dpio/dpio.h b/drivers/soc/fsl/dpio/dpio.h
index 49194c8..b2ac4ba 100644
--- a/drivers/soc/fsl/dpio/dpio.h
+++ b/drivers/soc/fsl/dpio/dpio.h
@@ -80,4 +80,8 @@ int dpio_get_api_version(struct fsl_mc_io *mc_io,
 			 u16 *major_ver,
 			 u16 *minor_ver);
 
+int dpio_reset(struct fsl_mc_io	*mc_io,
+	       u32 cmd_flags,
+	       u16 token);
+
 #endif /* __FSL_DPIO_H */
-- 
1.9.1


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

* [PATCH 2/5] soc: fsl: dpio: keep a per dpio device MC portal
  2018-12-10 16:50 [PATCH 0/5] soc: fsl: add device links support for devices on the fsl-mc bus Ioana Ciornei
  2018-12-10 16:50 ` [PATCH 1/5] soc: fsl: dpio: perform DPIO Reset on Probe Ioana Ciornei
@ 2018-12-10 16:50 ` Ioana Ciornei
  2018-12-10 16:50 ` [PATCH 3/5] soc: fsl: dpio: store a backpointer to the device backing the dpaa2_io Ioana Ciornei
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 9+ messages in thread
From: Ioana Ciornei @ 2018-12-10 16:50 UTC (permalink / raw)
  To: Leo Li, linux-kernel, linux-arm-kernel, netdev
  Cc: Laurentiu Tudor, Horia Geanta, Ioana Ciocoi Radulescu,
	Roy Pledge, Ioana Ciornei

At the moment, the dpio-driver allocates an MC portal at probe time and
frees it right after usage. The same thing happens on the remove path.
This behavior could lead to scenarios where an MC portal is available
for use at probing but not longer free on the remove path which could
lead to unproper unbind of resources.

Change the driver's behavior in such a way that an MC portal is
allocated at probe and kept until the DPIO device is removed. This will
ensure that at any time after a DPIO device was successfully probed, all
its dependencies will be met.

Signed-off-by: Ioana Ciornei <ioana.ciornei@nxp.com>
---
 drivers/soc/fsl/dpio/dpio-driver.c | 9 +--------
 1 file changed, 1 insertion(+), 8 deletions(-)

diff --git a/drivers/soc/fsl/dpio/dpio-driver.c b/drivers/soc/fsl/dpio/dpio-driver.c
index 38ee9db..5286723 100644
--- a/drivers/soc/fsl/dpio/dpio-driver.c
+++ b/drivers/soc/fsl/dpio/dpio-driver.c
@@ -187,7 +187,6 @@ static int dpaa2_dpio_probe(struct fsl_mc_device *dpio_dev)
 	dev_dbg(dev, "   receives_notifications = %d\n",
 		desc.receives_notifications);
 	dpio_close(dpio_dev->mc_io, 0, dpio_dev->mc_handle);
-	fsl_mc_portal_free(dpio_dev->mc_io);
 
 	return 0;
 
@@ -229,12 +228,6 @@ static int dpaa2_dpio_remove(struct fsl_mc_device *dpio_dev)
 	cpu = dpaa2_io_get_cpu(priv->io);
 	cpumask_set_cpu(cpu, cpus_unused_mask);
 
-	err = fsl_mc_portal_allocate(dpio_dev, 0, &dpio_dev->mc_io);
-	if (err) {
-		dev_err(dev, "MC portal allocation failed\n");
-		goto err_mcportal;
-	}
-
 	err = dpio_open(dpio_dev->mc_io, 0, dpio_dev->obj_desc.id,
 			&dpio_dev->mc_handle);
 	if (err) {
@@ -252,7 +245,7 @@ static int dpaa2_dpio_remove(struct fsl_mc_device *dpio_dev)
 
 err_open:
 	fsl_mc_portal_free(dpio_dev->mc_io);
-err_mcportal:
+
 	return err;
 }
 
-- 
1.9.1


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

* [PATCH 3/5] soc: fsl: dpio: store a backpointer to the device backing the dpaa2_io
  2018-12-10 16:50 [PATCH 0/5] soc: fsl: add device links support for devices on the fsl-mc bus Ioana Ciornei
  2018-12-10 16:50 ` [PATCH 1/5] soc: fsl: dpio: perform DPIO Reset on Probe Ioana Ciornei
  2018-12-10 16:50 ` [PATCH 2/5] soc: fsl: dpio: keep a per dpio device MC portal Ioana Ciornei
@ 2018-12-10 16:50 ` Ioana Ciornei
  2018-12-10 16:50 ` [PATCH 5/5] bus: fsl-mc: automatically add a device_link on fsl_mc_[portal,object]_allocate Ioana Ciornei
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 9+ messages in thread
From: Ioana Ciornei @ 2018-12-10 16:50 UTC (permalink / raw)
  To: Leo Li, linux-kernel, linux-arm-kernel, netdev
  Cc: Laurentiu Tudor, Horia Geanta, Ioana Ciocoi Radulescu,
	Roy Pledge, Ioana Ciornei

Add a new field in the dpaa2_io structure to hold a backpointer to the
actual DPIO device.

Signed-off-by: Ioana Ciornei <ioana.ciornei@nxp.com>
---
 drivers/soc/fsl/dpio/dpio-driver.c  | 2 +-
 drivers/soc/fsl/dpio/dpio-service.c | 7 ++++++-
 include/soc/fsl/dpaa2-io.h          | 3 ++-
 3 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/drivers/soc/fsl/dpio/dpio-driver.c b/drivers/soc/fsl/dpio/dpio-driver.c
index 5286723..2d4af32 100644
--- a/drivers/soc/fsl/dpio/dpio-driver.c
+++ b/drivers/soc/fsl/dpio/dpio-driver.c
@@ -176,7 +176,7 @@ static int dpaa2_dpio_probe(struct fsl_mc_device *dpio_dev)
 	if (err)
 		goto err_register_dpio_irq;
 
-	priv->io = dpaa2_io_create(&desc);
+	priv->io = dpaa2_io_create(&desc, dev);
 	if (!priv->io) {
 		dev_err(dev, "dpaa2_io_create failed\n");
 		err = -ENOMEM;
diff --git a/drivers/soc/fsl/dpio/dpio-service.c b/drivers/soc/fsl/dpio/dpio-service.c
index 5583d28..87e01710 100644
--- a/drivers/soc/fsl/dpio/dpio-service.c
+++ b/drivers/soc/fsl/dpio/dpio-service.c
@@ -27,6 +27,7 @@ struct dpaa2_io {
 	/* protect notifications list */
 	spinlock_t lock_notifications;
 	struct list_head notifications;
+	struct device *dev;
 };
 
 struct dpaa2_io_store {
@@ -98,13 +99,15 @@ struct dpaa2_io *dpaa2_io_service_select(int cpu)
 /**
  * dpaa2_io_create() - create a dpaa2_io object.
  * @desc: the dpaa2_io descriptor
+ * @dev: the actual DPIO device
  *
  * Activates a "struct dpaa2_io" corresponding to the given config of an actual
  * DPIO object.
  *
  * Return a valid dpaa2_io object for success, or NULL for failure.
  */
-struct dpaa2_io *dpaa2_io_create(const struct dpaa2_io_desc *desc)
+struct dpaa2_io *dpaa2_io_create(const struct dpaa2_io_desc *desc,
+				 struct device *dev)
 {
 	struct dpaa2_io *obj = kmalloc(sizeof(*obj), GFP_KERNEL);
 
@@ -146,6 +149,8 @@ struct dpaa2_io *dpaa2_io_create(const struct dpaa2_io_desc *desc)
 		dpio_by_cpu[desc->cpu] = obj;
 	spin_unlock(&dpio_list_lock);
 
+	obj->dev = dev;
+
 	return obj;
 }
 
diff --git a/include/soc/fsl/dpaa2-io.h b/include/soc/fsl/dpaa2-io.h
index e11eed1..5b5ba26 100644
--- a/include/soc/fsl/dpaa2-io.h
+++ b/include/soc/fsl/dpaa2-io.h
@@ -57,7 +57,8 @@ struct dpaa2_io_desc {
 	u32 qman_version;
 };
 
-struct dpaa2_io *dpaa2_io_create(const struct dpaa2_io_desc *desc);
+struct dpaa2_io *dpaa2_io_create(const struct dpaa2_io_desc *desc,
+				 struct device *dev);
 
 void dpaa2_io_down(struct dpaa2_io *d);
 
-- 
1.9.1


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

* [PATCH 5/5] bus: fsl-mc: automatically add a device_link on fsl_mc_[portal,object]_allocate
  2018-12-10 16:50 [PATCH 0/5] soc: fsl: add device links support for devices on the fsl-mc bus Ioana Ciornei
                   ` (2 preceding siblings ...)
  2018-12-10 16:50 ` [PATCH 3/5] soc: fsl: dpio: store a backpointer to the device backing the dpaa2_io Ioana Ciornei
@ 2018-12-10 16:50 ` Ioana Ciornei
  2018-12-10 16:50 ` [PATCH 4/5] soc: fsl: dpio: add a device_link at dpaa2_io_service_register Ioana Ciornei
  2018-12-17 10:46 ` [PATCH 0/5] soc: fsl: add device links support for devices on the fsl-mc bus Laurentiu Tudor
  5 siblings, 0 replies; 9+ messages in thread
From: Ioana Ciornei @ 2018-12-10 16:50 UTC (permalink / raw)
  To: Leo Li, linux-kernel, linux-arm-kernel, netdev
  Cc: Laurentiu Tudor, Horia Geanta, Ioana Ciocoi Radulescu,
	Roy Pledge, Ioana Ciornei

Allocatable devices can be acquired by drivers on the fsl-mc bus using
the fsl_mc_portal_allocate or fsl_mc_object_allocate functions. Add a
device link between the consumer device and the supplier device so that
proper resource management is achieved.
Also, adding a link between these devices ensures that a proper unbind
order is respected (ie before the supplier device is unbound from its
respective driver all consumer devices will be notified and unbound
first).

Signed-off-by: Ioana Ciornei <ioana.ciornei@nxp.com>
---
 drivers/bus/fsl-mc/fsl-mc-allocator.c | 11 +++++++++++
 drivers/bus/fsl-mc/mc-io.c            | 13 +++++++++++++
 include/linux/fsl/mc.h                |  1 +
 3 files changed, 25 insertions(+)

diff --git a/drivers/bus/fsl-mc/fsl-mc-allocator.c b/drivers/bus/fsl-mc/fsl-mc-allocator.c
index e906ecfe..8ad7724 100644
--- a/drivers/bus/fsl-mc/fsl-mc-allocator.c
+++ b/drivers/bus/fsl-mc/fsl-mc-allocator.c
@@ -295,6 +295,14 @@ int __must_check fsl_mc_object_allocate(struct fsl_mc_device *mc_dev,
 	if (!mc_adev)
 		goto error;
 
+	mc_adev->consumer_link = device_link_add(&mc_dev->dev,
+						 &mc_adev->dev,
+						 DL_FLAG_AUTOREMOVE_CONSUMER);
+	if (!mc_adev->consumer_link) {
+		error = -EINVAL;
+		goto error;
+	}
+
 	*new_mc_adev = mc_adev;
 	return 0;
 error:
@@ -321,6 +329,9 @@ void fsl_mc_object_free(struct fsl_mc_device *mc_adev)
 		return;
 
 	fsl_mc_resource_free(resource);
+
+	device_link_del(mc_adev->consumer_link);
+	mc_adev->consumer_link = NULL;
 }
 EXPORT_SYMBOL_GPL(fsl_mc_object_free);
 
diff --git a/drivers/bus/fsl-mc/mc-io.c b/drivers/bus/fsl-mc/mc-io.c
index 7226cfc..3ae574a 100644
--- a/drivers/bus/fsl-mc/mc-io.c
+++ b/drivers/bus/fsl-mc/mc-io.c
@@ -209,9 +209,19 @@ int __must_check fsl_mc_portal_allocate(struct fsl_mc_device *mc_dev,
 	if (error < 0)
 		goto error_cleanup_resource;
 
+	dpmcp_dev->consumer_link = device_link_add(&mc_dev->dev,
+						   &dpmcp_dev->dev,
+						   DL_FLAG_AUTOREMOVE_CONSUMER);
+	if (!dpmcp_dev->consumer_link) {
+		error = -EINVAL;
+		goto error_cleanup_mc_io;
+	}
+
 	*new_mc_io = mc_io;
 	return 0;
 
+error_cleanup_mc_io:
+	fsl_destroy_mc_io(mc_io);
 error_cleanup_resource:
 	fsl_mc_resource_free(resource);
 	return error;
@@ -244,6 +254,9 @@ void fsl_mc_portal_free(struct fsl_mc_io *mc_io)
 
 	fsl_destroy_mc_io(mc_io);
 	fsl_mc_resource_free(resource);
+
+	device_link_del(dpmcp_dev->consumer_link);
+	dpmcp_dev->consumer_link = NULL;
 }
 EXPORT_SYMBOL_GPL(fsl_mc_portal_free);
 
diff --git a/include/linux/fsl/mc.h b/include/linux/fsl/mc.h
index 9d3f668..0c4f9805 100644
--- a/include/linux/fsl/mc.h
+++ b/include/linux/fsl/mc.h
@@ -193,6 +193,7 @@ struct fsl_mc_device {
 	struct resource *regions;
 	struct fsl_mc_device_irq **irqs;
 	struct fsl_mc_resource *resource;
+	struct device_link *consumer_link;
 };
 
 #define to_fsl_mc_device(_dev) \
-- 
1.9.1


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

* [PATCH 4/5] soc: fsl: dpio: add a device_link at dpaa2_io_service_register
  2018-12-10 16:50 [PATCH 0/5] soc: fsl: add device links support for devices on the fsl-mc bus Ioana Ciornei
                   ` (3 preceding siblings ...)
  2018-12-10 16:50 ` [PATCH 5/5] bus: fsl-mc: automatically add a device_link on fsl_mc_[portal,object]_allocate Ioana Ciornei
@ 2018-12-10 16:50 ` Ioana Ciornei
  2018-12-14 14:44   ` Horia Geanta
  2018-12-17 10:46 ` [PATCH 0/5] soc: fsl: add device links support for devices on the fsl-mc bus Laurentiu Tudor
  5 siblings, 1 reply; 9+ messages in thread
From: Ioana Ciornei @ 2018-12-10 16:50 UTC (permalink / raw)
  To: Leo Li, linux-kernel, linux-arm-kernel, netdev
  Cc: Laurentiu Tudor, Horia Geanta, Ioana Ciocoi Radulescu,
	Roy Pledge, Ioana Ciornei

Automatically add a device link between the actual device requesting the
dpaa2_io_service_register and the underlying dpaa2_io used. This link
will ensure that when a DPIO device, which is indirectly used by other
devices, is unbound any consumer devices will be also unbound from their
drivers.

For example, any DPNI, bound to the dpaa2-eth driver, which is using
DPIO devices will be unbound before its supplier device.

Also, add a new parameter to the dpaa2_io_service_[de]register functions
to specify the requesting device (ie the consumer).

Signed-off-by: Ioana Ciornei <ioana.ciornei@nxp.com>
---
 drivers/crypto/caam/caamalg_qi2.c                |  6 +++---
 drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.c |  9 +++++----
 drivers/soc/fsl/dpio/dpio-service.c              | 16 ++++++++++++++--
 include/soc/fsl/dpaa2-io.h                       |  6 ++++--
 4 files changed, 26 insertions(+), 11 deletions(-)

diff --git a/drivers/crypto/caam/caamalg_qi2.c b/drivers/crypto/caam/caamalg_qi2.c
index 7d8ac02..3167539 100644
--- a/drivers/crypto/caam/caamalg_qi2.c
+++ b/drivers/crypto/caam/caamalg_qi2.c
@@ -4371,7 +4371,7 @@ static int __cold dpaa2_dpseci_dpio_setup(struct dpaa2_caam_priv *priv)
 		nctx->cb = dpaa2_caam_fqdan_cb;
 
 		/* Register notification callbacks */
-		err = dpaa2_io_service_register(NULL, nctx);
+		err = dpaa2_io_service_register(NULL, nctx, dev);
 		if (unlikely(err)) {
 			dev_dbg(dev, "No affine DPIO for cpu %d\n", cpu);
 			nctx->cb = NULL;
@@ -4404,7 +4404,7 @@ static int __cold dpaa2_dpseci_dpio_setup(struct dpaa2_caam_priv *priv)
 		ppriv = per_cpu_ptr(priv->ppriv, cpu);
 		if (!ppriv->nctx.cb)
 			break;
-		dpaa2_io_service_deregister(NULL, &ppriv->nctx);
+		dpaa2_io_service_deregister(NULL, &ppriv->nctx, dev);
 	}
 
 	for_each_online_cpu(cpu) {
@@ -4424,7 +4424,7 @@ static void __cold dpaa2_dpseci_dpio_free(struct dpaa2_caam_priv *priv)
 
 	for_each_online_cpu(cpu) {
 		ppriv = per_cpu_ptr(priv->ppriv, cpu);
-		dpaa2_io_service_deregister(NULL, &ppriv->nctx);
+		dpaa2_io_service_deregister(NULL, &ppriv->nctx, priv->dev);
 		dpaa2_io_store_destroy(ppriv->store);
 
 		if (++i == priv->num_pairs)
diff --git a/drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.c b/drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.c
index 04d5c44..e8790f9 100644
--- a/drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.c
+++ b/drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.c
@@ -1570,7 +1570,7 @@ static int setup_dpio(struct dpaa2_eth_priv *priv)
 
 		/* Register the new context */
 		channel->dpio = dpaa2_io_service_select(i);
-		err = dpaa2_io_service_register(channel->dpio, nctx);
+		err = dpaa2_io_service_register(channel->dpio, nctx, dev);
 		if (err) {
 			dev_dbg(dev, "No affine DPIO for cpu %d\n", i);
 			/* If no affine DPIO for this core, there's probably
@@ -1610,7 +1610,7 @@ static int setup_dpio(struct dpaa2_eth_priv *priv)
 	return 0;
 
 err_set_cdan:
-	dpaa2_io_service_deregister(channel->dpio, nctx);
+	dpaa2_io_service_deregister(channel->dpio, nctx, dev);
 err_service_reg:
 	free_channel(priv, channel);
 err_alloc_ch:
@@ -1630,13 +1630,14 @@ static int setup_dpio(struct dpaa2_eth_priv *priv)
 
 static void free_dpio(struct dpaa2_eth_priv *priv)
 {
-	int i;
+	struct device *dev = priv->net_dev->dev.parent;
 	struct dpaa2_eth_channel *ch;
+	int i;
 
 	/* deregister CDAN notifications and free channels */
 	for (i = 0; i < priv->num_channels; i++) {
 		ch = priv->channel[i];
-		dpaa2_io_service_deregister(ch->dpio, &ch->nctx);
+		dpaa2_io_service_deregister(ch->dpio, &ch->nctx, dev);
 		free_channel(priv, ch);
 	}
 }
diff --git a/drivers/soc/fsl/dpio/dpio-service.c b/drivers/soc/fsl/dpio/dpio-service.c
index 87e01710..01b24ac 100644
--- a/drivers/soc/fsl/dpio/dpio-service.c
+++ b/drivers/soc/fsl/dpio/dpio-service.c
@@ -237,6 +237,7 @@ int dpaa2_io_get_cpu(struct dpaa2_io *d)
  *                               notifications on the given DPIO service.
  * @d:   the given DPIO service.
  * @ctx: the notification context.
+ * @dev: the device that requests the register
  *
  * The caller should make the MC command to attach a DPAA2 object to
  * a DPIO after this function completes successfully.  In that way:
@@ -251,14 +252,20 @@ int dpaa2_io_get_cpu(struct dpaa2_io *d)
  * Return 0 for success, or -ENODEV for failure.
  */
 int dpaa2_io_service_register(struct dpaa2_io *d,
-			      struct dpaa2_io_notification_ctx *ctx)
+			      struct dpaa2_io_notification_ctx *ctx,
+			      struct device *dev)
 {
+	struct device_link *link;
 	unsigned long irqflags;
 
 	d = service_select_by_cpu(d, ctx->desired_cpu);
 	if (!d)
 		return -ENODEV;
 
+	link = device_link_add(dev, d->dev, DL_FLAG_AUTOREMOVE_CONSUMER);
+	if (!link)
+		return -EINVAL;
+
 	ctx->dpio_id = d->dpio_desc.dpio_id;
 	ctx->qman64 = (u64)(uintptr_t)ctx;
 	ctx->dpio_private = d;
@@ -279,12 +286,14 @@ int dpaa2_io_service_register(struct dpaa2_io *d,
  * dpaa2_io_service_deregister - The opposite of 'register'.
  * @service: the given DPIO service.
  * @ctx: the notification context.
+ * @dev: the device that requests to be deregistered
  *
  * This function should be called only after sending the MC command to
  * to detach the notification-producing device from the DPIO.
  */
 void dpaa2_io_service_deregister(struct dpaa2_io *service,
-				 struct dpaa2_io_notification_ctx *ctx)
+				 struct dpaa2_io_notification_ctx *ctx,
+				 struct device *dev)
 {
 	struct dpaa2_io *d = ctx->dpio_private;
 	unsigned long irqflags;
@@ -295,6 +304,9 @@ void dpaa2_io_service_deregister(struct dpaa2_io *service,
 	spin_lock_irqsave(&d->lock_notifications, irqflags);
 	list_del(&ctx->node);
 	spin_unlock_irqrestore(&d->lock_notifications, irqflags);
+
+	if (dev)
+		device_link_remove(dev, d->dev);
 }
 EXPORT_SYMBOL_GPL(dpaa2_io_service_deregister);
 
diff --git a/include/soc/fsl/dpaa2-io.h b/include/soc/fsl/dpaa2-io.h
index 5b5ba26..850e46d 100644
--- a/include/soc/fsl/dpaa2-io.h
+++ b/include/soc/fsl/dpaa2-io.h
@@ -94,9 +94,11 @@ struct dpaa2_io_notification_ctx {
 int dpaa2_io_get_cpu(struct dpaa2_io *d);
 
 int dpaa2_io_service_register(struct dpaa2_io *service,
-			      struct dpaa2_io_notification_ctx *ctx);
+			      struct dpaa2_io_notification_ctx *ctx,
+			      struct device *dev);
 void dpaa2_io_service_deregister(struct dpaa2_io *service,
-				 struct dpaa2_io_notification_ctx *ctx);
+				 struct dpaa2_io_notification_ctx *ctx,
+				 struct device *dev);
 int dpaa2_io_service_rearm(struct dpaa2_io *service,
 			   struct dpaa2_io_notification_ctx *ctx);
 
-- 
1.9.1


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

* Re: [PATCH 4/5] soc: fsl: dpio: add a device_link at dpaa2_io_service_register
  2018-12-10 16:50 ` [PATCH 4/5] soc: fsl: dpio: add a device_link at dpaa2_io_service_register Ioana Ciornei
@ 2018-12-14 14:44   ` Horia Geanta
  2018-12-14 14:49     ` Ioana Ciocoi Radulescu
  0 siblings, 1 reply; 9+ messages in thread
From: Horia Geanta @ 2018-12-14 14:44 UTC (permalink / raw)
  To: Ioana Ciornei, Leo Li, linux-kernel, linux-arm-kernel, netdev
  Cc: Laurentiu Tudor, Ioana Ciocoi Radulescu, Roy Pledge

On 12/10/2018 6:50 PM, Ioana Ciornei wrote:
> Automatically add a device link between the actual device requesting the
> dpaa2_io_service_register and the underlying dpaa2_io used. This link
> will ensure that when a DPIO device, which is indirectly used by other
> devices, is unbound any consumer devices will be also unbound from their
> drivers.
> 
> For example, any DPNI, bound to the dpaa2-eth driver, which is using
> DPIO devices will be unbound before its supplier device.
> 
> Also, add a new parameter to the dpaa2_io_service_[de]register functions
> to specify the requesting device (ie the consumer).
> 
> Signed-off-by: Ioana Ciornei <ioana.ciornei@nxp.com>
Reviewed-by: Horia Geantă <horia.geanta@nxp.com>

Thanks,
Horia

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

* RE: [PATCH 4/5] soc: fsl: dpio: add a device_link at dpaa2_io_service_register
  2018-12-14 14:44   ` Horia Geanta
@ 2018-12-14 14:49     ` Ioana Ciocoi Radulescu
  0 siblings, 0 replies; 9+ messages in thread
From: Ioana Ciocoi Radulescu @ 2018-12-14 14:49 UTC (permalink / raw)
  To: Ioana Ciornei, Leo Li, linux-kernel, linux-arm-kernel, netdev
  Cc: Laurentiu Tudor, Roy Pledge, Horia Geanta

> -----Original Message-----
> From: Horia Geanta
> Sent: Friday, December 14, 2018 4:45 PM
> To: Ioana Ciornei <ioana.ciornei@nxp.com>; Leo Li <leoyang.li@nxp.com>;
> linux-kernel@vger.kernel.org; linux-arm-kernel@lists.infradead.org;
> netdev@vger.kernel.org
> Cc: Laurentiu Tudor <laurentiu.tudor@nxp.com>; Ioana Ciocoi Radulescu
> <ruxandra.radulescu@nxp.com>; Roy Pledge <roy.pledge@nxp.com>
> Subject: Re: [PATCH 4/5] soc: fsl: dpio: add a device_link at
> dpaa2_io_service_register
> 
> On 12/10/2018 6:50 PM, Ioana Ciornei wrote:
> > Automatically add a device link between the actual device requesting the
> > dpaa2_io_service_register and the underlying dpaa2_io used. This link
> > will ensure that when a DPIO device, which is indirectly used by other
> > devices, is unbound any consumer devices will be also unbound from their
> > drivers.
> >
> > For example, any DPNI, bound to the dpaa2-eth driver, which is using
> > DPIO devices will be unbound before its supplier device.
> >
> > Also, add a new parameter to the dpaa2_io_service_[de]register functions
> > to specify the requesting device (ie the consumer).
> >
> > Signed-off-by: Ioana Ciornei <ioana.ciornei@nxp.com>
> Reviewed-by: Horia Geantă <horia.geanta@nxp.com>

Reviewed-by: Ioana Radulescu <ruxandra.radulescu@nxp.com>

Thanks,
Ioana

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

* RE: [PATCH 0/5] soc: fsl: add device links support for devices on the fsl-mc bus
  2018-12-10 16:50 [PATCH 0/5] soc: fsl: add device links support for devices on the fsl-mc bus Ioana Ciornei
                   ` (4 preceding siblings ...)
  2018-12-10 16:50 ` [PATCH 4/5] soc: fsl: dpio: add a device_link at dpaa2_io_service_register Ioana Ciornei
@ 2018-12-17 10:46 ` Laurentiu Tudor
  5 siblings, 0 replies; 9+ messages in thread
From: Laurentiu Tudor @ 2018-12-17 10:46 UTC (permalink / raw)
  To: Ioana Ciornei, Leo Li, linux-kernel, linux-arm-kernel, netdev
  Cc: Horia Geanta, Ioana Ciocoi Radulescu, Roy Pledge



> -----Original Message-----
> From: Ioana Ciornei
> Sent: Monday, December 10, 2018 6:50 PM
> 
> The fsl-mc bus discovers and exports devices dynamically allocated
> by the Management Complex firmware.
> This patch set adds the ability to automatically create a device link
> between a consumer device on the fsl-mc bus and a supplier one.
> For example, a dpni device (a network interface) requests access to a
> dpio device (I/O portal) using the dpaa2_io_service_register function
> which is enhanced to also add the corresponding device link between
> them.
> 
> The first 3 patches set the stage for a proper handling of device
> links while the following 2 are the ones that add the actual links.
> 
> The internal management of the links is not exported to the consumer
> driver, but it's rather included in the functions that actually allocate
> the provider device: fsl_mc_portal_allocate, fsl_mc_object_allocate and
> dpaa2_io_service_register.
> 
> Ioana Ciornei (4):
>   soc: fsl: dpio: keep a per dpio device MC portal
>   soc: fsl: dpio: store a backpointer to the device backing the dpaa2_io
>   soc: fsl: dpio: add a device_link at dpaa2_io_service_register
>   bus: fsl-mc: automatically add a device_link on
>     fsl_mc_[portal,object]_allocate
> 
> Roy Pledge (1):
>   soc: fsl: dpio: perform DPIO Reset on Probe
> 
>  drivers/bus/fsl-mc/fsl-mc-allocator.c            | 11 +++++++++++
>  drivers/bus/fsl-mc/mc-io.c                       | 13 +++++++++++++
>  drivers/crypto/caam/caamalg_qi2.c                |  6 +++---
>  drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.c |  9 +++++----
>  drivers/soc/fsl/dpio/dpio-cmd.h                  |  1 +
>  drivers/soc/fsl/dpio/dpio-driver.c               | 18 +++++++++---------
>  drivers/soc/fsl/dpio/dpio-service.c              | 23
> ++++++++++++++++++++---
>  drivers/soc/fsl/dpio/dpio.c                      | 23
> +++++++++++++++++++++++
>  drivers/soc/fsl/dpio/dpio.h                      |  4 ++++
>  include/linux/fsl/mc.h                           |  1 +
>  include/soc/fsl/dpaa2-io.h                       |  9 ++++++---
>  11 files changed, 96 insertions(+), 22 deletions(-)

Reviewed-by: Laurentiu Tudor <laurentiu.tudor@nxp.com>

---
Best Regards, Laurentiu

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

end of thread, other threads:[~2018-12-17 10:46 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-10 16:50 [PATCH 0/5] soc: fsl: add device links support for devices on the fsl-mc bus Ioana Ciornei
2018-12-10 16:50 ` [PATCH 1/5] soc: fsl: dpio: perform DPIO Reset on Probe Ioana Ciornei
2018-12-10 16:50 ` [PATCH 2/5] soc: fsl: dpio: keep a per dpio device MC portal Ioana Ciornei
2018-12-10 16:50 ` [PATCH 3/5] soc: fsl: dpio: store a backpointer to the device backing the dpaa2_io Ioana Ciornei
2018-12-10 16:50 ` [PATCH 5/5] bus: fsl-mc: automatically add a device_link on fsl_mc_[portal,object]_allocate Ioana Ciornei
2018-12-10 16:50 ` [PATCH 4/5] soc: fsl: dpio: add a device_link at dpaa2_io_service_register Ioana Ciornei
2018-12-14 14:44   ` Horia Geanta
2018-12-14 14:49     ` Ioana Ciocoi Radulescu
2018-12-17 10:46 ` [PATCH 0/5] soc: fsl: add device links support for devices on the fsl-mc bus Laurentiu Tudor

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