Skip to contentSkip to conversation

staging: fsl-mc: New functionality to the MC bus driver

PATCH Superseded J. German Rivera 3 participants 25 messages Apr 28, 2015 – May 6, 2015 Staging

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

cover staging: fsl-mc: New functionality to the MC bus driver

This patch series includes new functionality for the Freescale fsl-mc bus driver.

Patch 1: MC bus IRQ support
Patch 2: add device binding path 'driver_override' Patch 3: Propagate driver_override for a child DPRC's children Patch 4: Upgraded MC bus driver to match MC fw 7.0.0 Patch 5: Allow the MC bus driver to run without GIC support Patch 6: Add locking to serialize mc_send_command() calls Patch 7: Use DPMCP IRQ and completion var to wait for MC

#1 lore raw

PATCH 1/7 staging: fsl-mc: MC bus IRQ support

All the IRQs for DPAA2 objects in the same DPRC must use the ICID of that DPRC, as their device Id in the GIC-ITS. Thus, all these IRQs must share the same ITT table in GIC. As a result, a pool of IRQs with the same device Id must be preallocated per DPRC (fsl-mc bus instance). So, the fsl-mc bus object allocator is extended to also provide services to allocate IRQs to DPAA2 devices, from their parent fsl-mc bus IRQ pool.

Also, the interrupt handler for DPRC IRQs is added. DPRC IRQs are generated for hot plug events related to DPAA2 objects in a given DPRC. These events include, creating/destroying DPAA2 objects in the DPRC, changing the "plugged" state of DPAA2 objects and moving objects between DPRCs.

Change-Id I2a986c465989c3811de19cfe9ed0b77168250cb1

Reviewed-on: http://git.am.freescale.net:8181/33626

---
 drivers/staging/fsl-mc/TODO                 |   3 +
 drivers/staging/fsl-mc/bus/dprc-driver.c    | 337 +++++++++++++++++++++++++-
 drivers/staging/fsl-mc/bus/mc-allocator.c   | 105 +++++++++
 drivers/staging/fsl-mc/bus/mc-bus.c         | 352 +++++++++++++++++++++++++++-
 drivers/staging/fsl-mc/include/mc-private.h |  26 +-
 drivers/staging/fsl-mc/include/mc.h         |  25 ++
 6 files changed, 837 insertions(+), 11 deletions(-)
drivers/staging/fsl-mc/TODO +3 -0
index d78288b..1b8868d 100644
@@ -8,6 +8,9 @@
 * Add at least one device driver for a DPAA2 object (child device of the
   fsl-mc bus).
 
+* Enable code blocks guarded by #ifdef GIC_ITS_MC_SUPPORT, when GIC-ITS
+  support for the MC MSIs gets merged.
+
 Please send any patches to Greg Kroah-Hartman <[email protected]>,
 [email protected], [email protected],
 [email protected]
drivers/staging/fsl-mc/bus/dprc-driver.c +333 -4

428 lines not on this page · raw message

drivers/staging/fsl-mc/bus/mc-allocator.c +105 -0

117 lines not on this page · raw message

drivers/staging/fsl-mc/bus/mc-bus.c +348 -4

417 lines not on this page · raw message

drivers/staging/fsl-mc/include/mc-private.h +23 -3
index c045f49..6e33942 100644
@@ -27,12 +27,26 @@
 	 strcmp(_obj_type, "dpcon") == 0)
 
 /**
+ * Maximum number of total IRQs that can be pre-allocated for an MC bus'
+ * IRQ pool
+ */
+#define FSL_MC_IRQ_POOL_MAX_TOTAL_IRQS	256
+
+/**
+ * Maximum number of extra IRQs pre-reallocated for an MC bus' IRQ pool,
+ * to be used by dynamically created MC objects
+ */
+#define FSL_MC_IRQ_POOL_MAX_EXTRA_IRQS	64
+
+/**
  * struct fsl_mc - Private data of a "fsl,qoriq-mc" platform device
  * @root_mc_bus_dev: MC object device representing the root DPRC
+ * @irq_domain: IRQ domain for the fsl-mc bus type
  * @addr_translation_ranges: array of bus to system address translation ranges
  */
 struct fsl_mc {
 	struct fsl_mc_device *root_mc_bus_dev;
+	struct irq_domain *irq_domain;
 	uint8_t num_translation_ranges;
 	struct fsl_mc_addr_translation_range *translation_ranges;
 };
@@ -76,11 +90,13 @@ struct fsl_mc_resource_pool {
  * @resource_pools: array of resource pools (one pool per resource type)
  * for this MC bus. These resources represent allocatable entities
  * from the physical DPRC.
+ * @irq_resources: Pointer to array of IRQ objects for the IRQ pool.
  * @scan_mutex: Serializes bus scanning
  */
 struct fsl_mc_bus {
 	struct fsl_mc_device mc_dev;
 	struct fsl_mc_resource_pool resource_pools[FSL_MC_NUM_POOL_TYPES];
+	struct fsl_mc_device_irq *irq_resources;
 	struct mutex scan_mutex;    /* serializes bus scanning */
 };
 
@@ -94,9 +110,8 @@ int __must_check fsl_mc_device_add(struct dprc_obj_desc *obj_desc,
 
 void fsl_mc_device_remove(struct fsl_mc_device *mc_dev);
 
-int dprc_scan_container(struct fsl_mc_device *mc_bus_dev);
-
-int dprc_scan_objects(struct fsl_mc_device *mc_bus_dev);
+int dprc_scan_objects(struct fsl_mc_device *mc_bus_dev,
+		      unsigned int *total_irq_count);
 
 int __init dprc_driver_init(void);
 
@@ -113,4 +128,9 @@ int __must_check fsl_mc_resource_allocate(struct fsl_mc_bus *mc_bus,
 
 void fsl_mc_resource_free(struct fsl_mc_resource *resource);
 
+int __must_check fsl_mc_populate_irq_pool(struct fsl_mc_bus *mc_bus,
+					  unsigned int irq_count);
+
+void fsl_mc_cleanup_irq_pool(struct fsl_mc_bus *mc_bus);
+
 #endif /* _FSL_MC_PRIVATE_H_ */
drivers/staging/fsl-mc/include/mc.h +25 -0
index fa02ef0..531cb8c 100644
@@ -14,6 +14,7 @@
 #include <linux/device.h>
 #include <linux/mod_devicetable.h>
 #include <linux/list.h>
+#include <linux/interrupt.h>
 #include "../include/dprc.h"
 
 #define FSL_MC_VENDOR_FREESCALE	0x1957
@@ -75,6 +76,7 @@ enum fsl_mc_pool_type {
 	FSL_MC_POOL_DPMCP = 0x0,    /* corresponds to "dpmcp" in the MC */
 	FSL_MC_POOL_DPBP,	    /* corresponds to "dpbp" in the MC */
 	FSL_MC_POOL_DPCON,	    /* corresponds to "dpcon" in the MC */
+	FSL_MC_POOL_IRQ,
 
 	/*
 	 * NOTE: New resource pool types must be added before this entry
@@ -104,6 +106,23 @@ struct fsl_mc_resource {
 };
 
 /**
+ * struct fsl_mc_device_irq - MC object device message-based interrupt
+ * @msi_paddr: message-based interrupt physical address
+ * @msi_value: message-based interrupt data value
+ * @irq_number: Linux IRQ number assigned to the interrupt
+ * @resource: MC generic resource associated with the interrupt
+ */
+struct fsl_mc_device_irq {
+	phys_addr_t msi_paddr;
+	uint32_t msi_value;
+	uint32_t irq_number;
+	struct fsl_mc_resource resource;
+};
+
+#define to_fsl_mc_irq(_mc_resource) \
+	container_of(_mc_resource, struct fsl_mc_device_irq, resource)
+
+/**
  * Bit masks for a MC object device (struct fsl_mc_device) flags
  */
 #define FSL_MC_IS_DPRC	0x0001
@@ -124,6 +143,7 @@ struct fsl_mc_resource {
  * NULL if none.
  * @obj_desc: MC description of the DPAA device
  * @regions: pointer to array of MMIO region entries
+ * @irqs: pointer to array of pointers to interrupts allocated to this device
  * @resource: generic resource associated with this MC object device, if any.
  *
  * Generic device object for MC object devices that are "attached" to a
@@ -155,6 +175,7 @@ struct fsl_mc_device {
 	struct fsl_mc_io *mc_io;
 	struct dprc_obj_desc obj_desc;
 	struct resource *regions;
+	struct fsl_mc_device_irq **irqs;
 	struct fsl_mc_resource *resource;
 };
 
@@ -196,6 +217,10 @@ int __must_check fsl_mc_object_allocate(struct fsl_mc_device *mc_dev,
 
 void fsl_mc_object_free(struct fsl_mc_device *mc_adev);
 
+int __must_check fsl_mc_allocate_irqs(struct fsl_mc_device *mc_dev);
+
+void fsl_mc_free_irqs(struct fsl_mc_device *mc_dev);
+
 extern struct bus_type fsl_mc_bus_type;
 
 #endif /* _FSL_MC_H_ */
Signature · 1 line
2.3.3
#2 lore raw

Re: [PATCH 1/7] staging: fsl-mc: MC bus IRQ support

Quoted 3 lines · J. German Rivera

Change-Id: I2a986c465989c3811de19cfe9ed0b77168250cb1
Reviewed-on: http://git.am.freescale.net:8181/33626

These things are totally useless to the rest of us. Don't add them.

drivers/staging/fsl-mc/TODO line 13

Quoted 11 lines
drivers/staging/fsl-mc/TODO +3 -0
index d78288b..1b8868d 100644
@@ -8,6 +8,9 @@
 * Add at least one device driver for a DPAA2 object (child device of the
   fsl-mc bus).
 
+* Enable code blocks guarded by #ifdef GIC_ITS_MC_SUPPORT, when GIC-ITS
+  support for the MC MSIs gets merged.
+

When will that be? I'd really prefer to not add these ifdeffed bits at all.

Quoted 4 lines
drivers/staging/fsl-mc/TODO +4 -0
+	if (status & (DPRC_IRQ_EVENT_OBJ_ADDED |
+		      DPRC_IRQ_EVENT_OBJ_REMOVED |
+		      DPRC_IRQ_EVENT_CONTAINER_DESTROYED |
+		      DPRC_IRQ_EVENT_OBJ_DESTROYED |

drivers/staging/fsl-mc/TODO

Quoted 10 lines
drivers/staging/fsl-mc/TODO +10 -0
+		      DPRC_IRQ_EVENT_OBJ_CREATED)) {
+		unsigned int irq_count;
+
+		error = dprc_scan_objects(mc_dev, &irq_count);
+		if (error < 0) {
+			dev_err(dev, "dprc_scan_objects() failed: %d\n", error);
+			goto out;
+		}
+
+		WARN_ON((int16_t)irq_count < 0);

This code is doing "WARN_ON(test_bit(15, (unsigned long *)&irq_count));". That seems like nonsense. Anyway, just delete the WARN_ON().

drivers/staging/fsl-mc/TODO

Quoted 3 lines
drivers/staging/fsl-mc/TODO +3 -0
+
+		if ((int16_t)irq_count >
+			mc_bus->resource_pools[FSL_MC_POOL_IRQ].max_count) {

Why are we casting this? Also can you align it like:

		if (irq_count >
		    mc_bus->resource_pools[FSL_MC_POOL_IRQ].max_count) {

[tab][tab][space][space][space][space]mc_bus->resource_pools[

That way you can tell the if condition from the indented block. Plus that is standard kernel indenting style these days.

[ snip ]

drivers/staging/fsl-mc/TODO

Quoted 6 lines
drivers/staging/fsl-mc/TODO +6 -0
+	irqs = devm_kzalloc(&mc_dev->dev, irq_count * sizeof(irqs[0]),
+			    GFP_KERNEL);
+	if (!irqs) {
+		error = -ENOMEM;
+		dev_err(&mc_dev->dev, "No memory to allocate irqs[]\n");
+		goto error;

I kind of hate One Err Style error handling, because the error labels are so general... You can never guess the point of it until you scroll down to read what "goto error;" does. The error handling here calls devm_kfree() which is not needed... devm_ functions automatically clean up after themselves. This seems a pattern throughout. Do a search for devm_free() and see which ones are really needed or not.

Also the error message isn't needed here. kzalloc() has its own better error messages built-in. Adding these error messages which will never be printed is just a waste of RAM.

In other words this should look like:

	irqs = devm_kcalloc(&mc_dev->dev, sizeof(*irqs), irq_count,
			    GFP_KERNEL);
	if (!irqs)
		return -ENOMEM;

regards,
dan carpenter

#3 lore raw

RE: [PATCH 1/7] staging: fsl-mc: MC bus IRQ support

Dan,

Thanks for your comments. My replies inline.

Thanks,

German

Quoted 11 lines

-----Original Message-----
From: Dan Carpenter [mailto:[email protected]]
Sent: Thursday, April 30, 2015 6:50 AM
To: Rivera Jose-B46482
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Yoder Stuart- B08248; Sharma Bhupesh-B45370; [email protected]; Hamciuc Bogdan-BHAMCIU1; Erez Nir-RM30794; katz Itai-RM05202; Wood Scott-B07421; Marginean Alexandru-R89243; Schmitt Richard-B43082
Subject: Re: [PATCH 1/7] staging: fsl-mc: MC bus IRQ support

Quoted 7 lines
Quoted 3 lines · J. German Rivera

Change-Id: I2a986c465989c3811de19cfe9ed0b77168250cb1
Reviewed-on: http://git.am.freescale.net:8181/33626

These things are totally useless to the rest of us. Don't add them.

Agreed. I'll remove them in the next respin.

Quoted 10 lines

drivers/staging/fsl-mc/TODO line 8

Quoted 7 lines
drivers/staging/fsl-mc/TODO +0 -0
index d78288b..1b8868d 100644
@@ -8,6 +8,9 @@
 * Add at least one device driver for a DPAA2 object (child device of

the

Quoted 2 lines
drivers/staging/fsl-mc/TODO +0 -0
   fsl-mc bus).
 
Quoted 8 lines

drivers/staging/fsl-mc/TODO line 13

Quoted 4 lines
drivers/staging/fsl-mc/TODO +4 -0
+* Enable code blocks guarded by #ifdef GIC_ITS_MC_SUPPORT, when
+GIC-ITS
+  support for the MC MSIs gets merged.
+

When will that be? I'd really prefer to not add these ifdeffed bits at all.

The owner of the GIC-ITS support patches would need to answer the "when" question. These #ifdefs are needed to be able to make the code compile without the GIC-ITS support in place. Of course, the code will not be moved out of staging with these #ifdefs. There is already an item for this in the drivers/staging/fsl-mc/TODO file.

Quoted 11 lines

drivers/staging/fsl-mc/TODO

Quoted 10 lines
drivers/staging/fsl-mc/TODO +10 -0
+	if (status & (DPRC_IRQ_EVENT_OBJ_ADDED |
+		      DPRC_IRQ_EVENT_OBJ_REMOVED |
+		      DPRC_IRQ_EVENT_CONTAINER_DESTROYED |
+		      DPRC_IRQ_EVENT_OBJ_DESTROYED |
+		      DPRC_IRQ_EVENT_OBJ_CREATED)) {
+		unsigned int irq_count;
+
+		error = dprc_scan_objects(mc_dev, &irq_count);
+		if (error < 0) {
+			dev_err(dev, "dprc_scan_objects() failed: %d\n",

error);

Quoted 8 lines

drivers/staging/fsl-mc/TODO

Quoted 4 lines
drivers/staging/fsl-mc/TODO +4 -0
+			goto out;
+		}
+
+		WARN_ON((int16_t)irq_count < 0);

This code is doing "WARN_ON(test_bit(15, (unsigned long *)&irq_count));". That seems like nonsense. Anyway, just delete the WARN_ON().

I disagree. This WARN_ON is checking that irq_count is in the expected range (it fits in int16_t as a positive number). The dprc_scan_objects() function expects irq_count to be of type "unsigned int" (which is 32-bit unsigned)

Quoted 6 lines

drivers/staging/fsl-mc/TODO

Quoted 3 lines
drivers/staging/fsl-mc/TODO +3 -0
+
+		if ((int16_t)irq_count >
+			mc_bus->resource_pools[FSL_MC_POOL_IRQ].max_count) {

Why are we casting this? Also can you align it like:

This casting is done for safety, to prevent the comparison to be done in "unsigned int" due to integer promotion rules.

Quoted 8 lines
		if (irq_count >
		    mc_bus->resource_pools[FSL_MC_POOL_IRQ].max_count) {

[tab][tab][space][space][space][space]mc_bus->resource_pools[

That way you can tell the if condition from the indented block. Plus that is standard kernel indenting style these days.

Agreed. I'll change this in the next respin.

Quoted 13 lines

[ snip ]

drivers/staging/fsl-mc/TODO

Quoted 6 lines
drivers/staging/fsl-mc/TODO +6 -0
+	irqs = devm_kzalloc(&mc_dev->dev, irq_count * sizeof(irqs[0]),
+			    GFP_KERNEL);
+	if (!irqs) {
+		error = -ENOMEM;
+		dev_err(&mc_dev->dev, "No memory to allocate irqs[]\n");
+		goto error;

I kind of hate One Err Style error handling, because the error labels are so general... You can never guess the point of it until you scroll down

Agreed. I will replace the generic error cleanup exit point with error-specific cleanup exit points, and return directly when no cleanup is needed.

Quoted 5 lines

to read what "goto error;" does. The error handling here calls devm_kfree() which is not needed... devm_ functions automatically clean up after themselves. This seems a pattern throughout. Do a search for devm_free() and see which ones are really needed or not.

I know that memory allocated with devm_kzalloc() is freed at the end of the lifetime of the device it is attached to. However, in error paths, why wait until the device is destroyed? Why not free the memory earlier so that it can be used for other purposes?

Quoted 4 lines

Also the error message isn't needed here. kzalloc() has its own better error messages built-in. Adding these error messages which will never be printed is just a waste of RAM.

Agreed. Error message removed.

Quoted 9 lines

In other words this should look like:

	irqs = devm_kcalloc(&mc_dev->dev, sizeof(*irqs), irq_count,
			    GFP_KERNEL);
	if (!irqs)
		return -ENOMEM;

regards,
dan carpenter

#4 lore raw

Re: [PATCH 1/7] staging: fsl-mc: MC bus IRQ support

Quoted 9 lines · Jose Rivera
Quoted 5 lines

drivers/staging/fsl-mc/bus/dprc-driver.c int dprc_scan_container(struct fsl_mc_device *mc_bus_dev) · line 442

Quoted 1 line
drivers/staging/fsl-mc/bus/dprc-driver.c +1 -0
+		WARN_ON((int16_t)irq_count < 0);

This code is doing "WARN_ON(test_bit(15, (unsigned long *)&irq_count));". That seems like nonsense. Anyway, just delete the WARN_ON().

I disagree. This WARN_ON is checking that irq_count is in the expected range (it fits in int16_t as a positive number). The dprc_scan_objects() function expects irq_count to be of type "unsigned int" (which is 32-bit unsigned)

You're not allowed to disagree because it's a testable thing and not an opinion about style or something. :P What you want is:

	WARN_ON(irq_count > SHRT_MAX);
Quoted 8 lines
Quoted 6 lines

drivers/staging/fsl-mc/bus/dprc-driver.c int dprc_scan_container(struct fsl_mc_device *mc_bus_dev) · line 445

Quoted 3 lines
drivers/staging/fsl-mc/bus/dprc-driver.c +3 -0
+
+		if ((int16_t)irq_count >
+			mc_bus->resource_pools[FSL_MC_POOL_IRQ].max_count) {

Why are we casting this? Also can you align it like:

This casting is done for safety, to prevent the comparison to be done in "unsigned int" due to integer promotion rules.

We are truncating away the top bytes but then we use them later. Fortunately we use them only to print out a warning, but if we used them for anything else it would be a serious bug.

Are you expecting .max_count to be negative?

If not then both sides are positive and type promotion is fine. We can delete the first (buggy) warning, like I said and just leave the second warning. It will now complain if any of bits 16 to 31 are set where before it wouldn't.

Quoted 9 lines
Quoted 5 lines

to read what "goto error;" does. The error handling here calls devm_kfree() which is not needed... devm_ functions automatically clean up after themselves. This seems a pattern throughout. Do a search for devm_free() and see which ones are really needed or not.

I know that memory allocated with devm_kzalloc() is freed at the end of the lifetime of the device it is attached to. However, in error paths, why wait until the device is destroyed? Why not free the memory earlier so that it can be used for other purposes?

My understanding is that devm_ functions are supposed to be used in the probe() functions to simplify the error handling. So hopefully the device lifetime ends as soon as this function returns a failure.

devm_ function are not a use them everywhere because now the kernel has garbage collection type thing.

regards,
dan carpenter

#5 lore raw

RE: [PATCH 1/7] staging: fsl-mc: MC bus IRQ support

Quoted 26 lines

-----Original Message-----
From: Dan Carpenter [mailto:[email protected]]
Sent: Tuesday, May 05, 2015 3:49 AM
To: Rivera Jose-B46482
Cc: [email protected]; [email protected]; [email protected]; Sharma Bhupesh-B45370; [email protected]; [email protected]; Yoder Stuart-B08248; Wood Scott-B07421; Erez Nir-RM30794; katz Itai- RM05202; Hamciuc Bogdan-BHAMCIU1; Marginean Alexandru-R89243; Schmitt Richard-B43082
Subject: Re: [PATCH 1/7] staging: fsl-mc: MC bus IRQ support

Quoted 3 lines · Jose Rivera
Quoted 3 lines

drivers/staging/fsl-mc/bus/dprc-driver.c int dprc_scan_container(struct fsl_mc_device *mc_bus_dev) · line 442

Quoted 1 line
drivers/staging/fsl-mc/bus/dprc-driver.c +1 -0
+		WARN_ON((int16_t)irq_count < 0);

This code is doing "WARN_ON(test_bit(15, (unsigned long

*)&irq_count));".

Quoted 7 lines
Quoted 2 lines

That seems like nonsense. Anyway, just delete the WARN_ON().

I disagree. This WARN_ON is checking that irq_count is in the expected range (it fits in int16_t as a positive number). The dprc_scan_objects() function expects irq_count to be of type "unsigned int" (which is 32-bit unsigned)

Quoted 5 lines

You're not allowed to disagree because it's a testable thing and not an opinion about style or something. :P What you want is:

	WARN_ON(irq_count > SHRT_MAX);

I see your point now. The check "(int16_t)irq_count < 0)" will not be able to catch 0x10000 > 0x7fff, but "irq_count > SHRT_MAX) will. So I'll make the suggested change, but I would prefer to use S16_MAX rather than SHRT_MAX.

Quoted 7 lines
Quoted 7 lines
Quoted 3 lines

drivers/staging/fsl-mc/bus/dprc-driver.c int dprc_scan_container(struct fsl_mc_device *mc_bus_dev)

Quoted 3 lines
drivers/staging/fsl-mc/bus/dprc-driver.c +3 -0
+
+		if ((int16_t)irq_count >
+			mc_bus-

resource_pools[FSL_MC_POOL_IRQ].max_count) {

Quoted 3 lines

Why are we casting this? Also can you align it like:

Quoted 9 lines
Quoted 2 lines

This casting is done for safety, to prevent the comparison to be done in "unsigned int" due to integer promotion rules.

We are truncating away the top bytes but then we use them later. Fortunately we use them only to print out a warning, but if we used them for anything else it would be a serious bug.

Are you expecting .max_count to be negative?

No.

Quoted 5 lines

If not then both sides are positive and type promotion is fine. We can delete the first (buggy) warning, like I said and just leave the second warning. It will now complain if any of bits 16 to 31 are set where before it wouldn't.

Agreed. I'll remove the (int16_t) type cast from the "if". So, I'll change this code snippet to be like this:

		WARN_ON(irq_count > S16_MAX);

		if (irq_count >
		    mc_bus->resource_pools[FSL_MC_POOL_IRQ].max_count) 
            	dev_warn(...);

Although the WARN_ON seems redundant with the "if", it catches a different problem. The WARN_ON() catches irq_count to be out of range, the "if" tells when we run out of IRQ resources fro a valid irq_count.

Quoted 11 lines
Quoted 10 lines
Quoted 6 lines

to read what "goto error;" does. The error handling here calls devm_kfree() which is not needed... devm_ functions automatically clean up after themselves. This seems a pattern throughout. Do a search for
devm_free() and see which ones are really needed or not.

I know that memory allocated with devm_kzalloc() is freed at the end of the lifetime of the device it is attached to. However, in error paths, why wait until the device is destroyed? Why not free the memory earlier so that it can be used for other purposes?

Why then do the devm_kfree() function exist?

I will not remove the devm_free() calls unless the upstream maintainer requires me to do so.

Quoted 9 lines

My understanding is that devm_ functions are supposed to be used in the probe() functions to simplify the error handling. So hopefully the device lifetime ends as soon as this function returns a failure.

devm_ function are not a use them everywhere because now the kernel has garbage collection type thing.

regards,
dan carpenter

#6 lore raw

Re: [PATCH 1/7] staging: fsl-mc: MC bus IRQ support

Quoted 18 lines · Jose Rivera
Quoted 18 lines

Subject: Re: [PATCH 1/7] staging: fsl-mc: MC bus IRQ support

Quoted 3 lines · Jose Rivera
Quoted 3 lines

drivers/staging/fsl-mc/bus/dprc-driver.c int dprc_scan_container(struct fsl_mc_device *mc_bus_dev) · line 442

Quoted 1 line
drivers/staging/fsl-mc/bus/dprc-driver.c +1 -0
+		WARN_ON((int16_t)irq_count < 0);

This code is doing "WARN_ON(test_bit(15, (unsigned long

*)&irq_count));".

Quoted 7 lines
Quoted 2 lines

That seems like nonsense. Anyway, just delete the WARN_ON().

I disagree. This WARN_ON is checking that irq_count is in the expected range (it fits in int16_t as a positive number). The dprc_scan_objects() function expects irq_count to be of type "unsigned int" (which is 32-bit unsigned)

You're not allowed to disagree because it's a testable thing and not an opinion about style or something. :P What you want is:

Quoted 7 lines
Quoted 2 lines
	WARN_ON(irq_count > SHRT_MAX);

I see your point now. The check "(int16_t)irq_count < 0)" will not be able to catch 0x10000 > 0x7fff, but "irq_count > SHRT_MAX) will. So I'll make the suggested change, but I would prefer to use S16_MAX rather than SHRT_MAX.

Huh? I didn't even know about the S16_MAX definition. There are literally no users of it in the kernel. It's not very fair because there are few users of SHRT_MAX. But there are literally no users of S32_MAX in the kernel and 358 users of INT_MAX.

Don't insist that you must be special and different from everyone else.

Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
Quoted 6 lines

to read what "goto error;" does. The error handling here calls devm_kfree() which is not needed... devm_ functions automatically clean up after themselves. This seems a pattern throughout. Do a search for
devm_free() and see which ones are really needed or not.

I know that memory allocated with devm_kzalloc() is freed at the end of the lifetime of the device it is attached to. However, in error paths, why wait until the device is destroyed? Why not free the memory earlier so that it can be used for other purposes?

Quoted 4 lines

Why then do the devm_kfree() function exist?

I will not remove the devm_free() calls unless the upstream maintainer requires me to do so.

I'm not saying remove them all. I'm saying:

1) I am concerned that you seem to thing devm_ is garbage collection.
2) Remove the ones which are not needed, because it is a lot of work for me to figure this out so I was hoping you could do it.

regards,
dan carpenter

#7 lore raw

Re: [PATCH 1/7] staging: fsl-mc: MC bus IRQ support

Quoted 27 lines · Dan Carpenter
Quoted 18 lines · Jose Rivera
Quoted 18 lines

Subject: Re: [PATCH 1/7] staging: fsl-mc: MC bus IRQ support

Quoted 3 lines · Jose Rivera
Quoted 3 lines

drivers/staging/fsl-mc/bus/dprc-driver.c int dprc_scan_container(struct fsl_mc_device *mc_bus_dev) · line 442

Quoted 1 line
drivers/staging/fsl-mc/bus/dprc-driver.c +1 -0
+		WARN_ON((int16_t)irq_count < 0);

This code is doing "WARN_ON(test_bit(15, (unsigned long

*)&irq_count));".

Quoted 7 lines
Quoted 2 lines

That seems like nonsense. Anyway, just delete the WARN_ON().

I disagree. This WARN_ON is checking that irq_count is in the expected range (it fits in int16_t as a positive number). The dprc_scan_objects() function expects irq_count to be of type "unsigned int" (which is 32-bit unsigned)

You're not allowed to disagree because it's a testable thing and not an opinion about style or something. :P What you want is:

Quoted 7 lines
Quoted 2 lines
	WARN_ON(irq_count > SHRT_MAX);

I see your point now. The check "(int16_t)irq_count < 0)" will not be able to catch 0x10000 > 0x7fff, but "irq_count > SHRT_MAX) will. So I'll make the suggested change, but I would prefer to use S16_MAX rather than SHRT_MAX.

Quoted 6 lines

Huh? I didn't even know about the S16_MAX definition. There are literally no users of it in the kernel. It's not very fair because there are few users of SHRT_MAX. But there are literally no users of S32_MAX in the kernel and 358 users of INT_MAX.

Don't insist that you must be special and different from everyone else.

There are some users of U16_MAX, U32_MAX, and U64_MAX. Why use a limit for a different type than is being used? Why have s16/s32 at all if you're going to conflate it with short/int elsewhere?

That said, I don't see where this code is actually using s16 (or int16_t) for irq_count except in these weird error checks. German, why do you need to check against 0x7fff (whatever you call it) at all? Won't comparing to a promoted-to-unsigned-int .max_count (as you do immediately after the WARN_ON) suffice?

-Scott

#8 lore raw

RE: [PATCH 1/7] staging: fsl-mc: MC bus IRQ support

Quoted 52 lines

-----Original Message-----
From: Wood Scott-B07421
Sent: Tuesday, May 05, 2015 2:57 PM
To: Dan Carpenter
Cc: Rivera Jose-B46482; [email protected]; Yoder Stuart-B08248; Hamciuc Bogdan-BHAMCIU1; [email protected]; Sharma Bhupesh-B45370; [email protected]; [email protected]; [email protected]; Erez Nir-RM30794; katz Itai-RM05202; Marginean Alexandru-R89243; Schmitt Richard-B43082
Subject: Re: [PATCH 1/7] staging: fsl-mc: MC bus IRQ support

Quoted 27 lines · Dan Carpenter
Quoted 18 lines · Jose Rivera
Quoted 18 lines

Subject: Re: [PATCH 1/7] staging: fsl-mc: MC bus IRQ support

Quoted 3 lines · Jose Rivera
Quoted 3 lines

Review

Quoted 1 line
(quoted diff) +1 -0
+		WARN_ON((int16_t)irq_count < 0);

This code is doing "WARN_ON(test_bit(15, (unsigned long

*)&irq_count));".

Quoted 7 lines
Quoted 2 lines

That seems like nonsense. Anyway, just delete the WARN_ON().

I disagree. This WARN_ON is checking that irq_count is in the expected range (it fits in int16_t as a positive number). The dprc_scan_objects() function expects irq_count to be of type "unsigned int" (which is 32-bit unsigned)

You're not allowed to disagree because it's a testable thing and not an opinion about style or something. :P What you want is:

Quoted 7 lines
Quoted 2 lines
	WARN_ON(irq_count > SHRT_MAX);

I see your point now. The check "(int16_t)irq_count < 0)" will not be able to catch 0x10000 > 0x7fff, but "irq_count > SHRT_MAX) will. So I'll make the suggested change, but I would prefer to use S16_MAX rather than SHRT_MAX.

Quoted 6 lines

Huh? I didn't even know about the S16_MAX definition. There are literally no users of it in the kernel. It's not very fair because there are few users of SHRT_MAX. But there are literally no users of S32_MAX in the kernel and 358 users of INT_MAX.

Don't insist that you must be special and different from everyone else.

There are some users of U16_MAX, U32_MAX, and U64_MAX. Why use a limit for a different type than is being used? Why have s16/s32 at all if you're going to conflate it with short/int elsewhere?

Quoted 6 lines

That said, I don't see where this code is actually using s16 (or int16_t) for irq_count except in these weird error checks. German, why do you need to check against 0x7fff (whatever you call it) at all? Won't comparing to a promoted-to-unsigned-int .max_count (as you do immediately after the WARN_ON) suffice?

mc_bus->resource_pools[FSL_MC_POOL_IRQ].max_count is of type int16_t (and is so, because its value comes from an MC API that returns an int16_t). The reason for checking irq_count against 0x7ffff is to catch the case in which irq_count is out of range (irq_count originates from values coming from the MC device, so we should do some validation before using it)

Thanks,

German

Quoted 2 lines

-Scott

���{.n�+�������+%�����ݶ��w��{.n�+����{��G�����{ay�ʇڙ�,j��f���h��������z_�(�階�ݢj"���m������G������?����&���~��iO��z��v�^�m���� ������?�I�

#9 lore raw

Re: [PATCH 1/7] staging: fsl-mc: MC bus IRQ support

Quoted 58 lines · On Tue, 2015-05-05 at 15:22 -0500, Rivera Jose-B46482 wrote:
Quoted 52 lines

-----Original Message-----
From: Wood Scott-B07421
Sent: Tuesday, May 05, 2015 2:57 PM
To: Dan Carpenter
Cc: Rivera Jose-B46482; [email protected]; Yoder Stuart-B08248; Hamciuc Bogdan-BHAMCIU1; [email protected]; Sharma Bhupesh-B45370; [email protected]; [email protected]; [email protected]; Erez Nir-RM30794; katz Itai-RM05202; Marginean Alexandru-R89243; Schmitt Richard-B43082
Subject: Re: [PATCH 1/7] staging: fsl-mc: MC bus IRQ support

Quoted 27 lines · Dan Carpenter
Quoted 18 lines · Jose Rivera
Quoted 18 lines

Subject: Re: [PATCH 1/7] staging: fsl-mc: MC bus IRQ support

Quoted 3 lines · Jose Rivera
Quoted 3 lines

Review

Quoted 1 line
(quoted diff) +1 -0
+		WARN_ON((int16_t)irq_count < 0);

This code is doing "WARN_ON(test_bit(15, (unsigned long

*)&irq_count));".

Quoted 7 lines
Quoted 2 lines

That seems like nonsense. Anyway, just delete the WARN_ON().

I disagree. This WARN_ON is checking that irq_count is in the expected range (it fits in int16_t as a positive number). The dprc_scan_objects() function expects irq_count to be of type "unsigned int" (which is 32-bit unsigned)

You're not allowed to disagree because it's a testable thing and not an opinion about style or something. :P What you want is:

Quoted 7 lines
Quoted 2 lines
	WARN_ON(irq_count > SHRT_MAX);

I see your point now. The check "(int16_t)irq_count < 0)" will not be able to catch 0x10000 > 0x7fff, but "irq_count > SHRT_MAX) will. So I'll make the suggested change, but I would prefer to use S16_MAX rather than SHRT_MAX.

Quoted 6 lines

Huh? I didn't even know about the S16_MAX definition. There are literally no users of it in the kernel. It's not very fair because there are few users of SHRT_MAX. But there are literally no users of S32_MAX in the kernel and 358 users of INT_MAX.

Don't insist that you must be special and different from everyone else.

There are some users of U16_MAX, U32_MAX, and U64_MAX. Why use a limit for a different type than is being used? Why have s16/s32 at all if you're going to conflate it with short/int elsewhere?

Quoted 6 lines

That said, I don't see where this code is actually using s16 (or int16_t) for irq_count except in these weird error checks. German, why do you need to check against 0x7fff (whatever you call it) at all? Won't comparing to a promoted-to-unsigned-int .max_count (as you do immediately after the WARN_ON) suffice?

Quoted 6 lines

mc_bus->resource_pools[FSL_MC_POOL_IRQ].max_count is of type int16_t (and is so, because its value comes from an MC API that returns an int16_t). The reason for checking irq_count against 0x7ffff is to catch the case in which irq_count is out of range (irq_count originates from values coming from the MC device, so we should do some validation before using it)

Comparing irq_count with max_count will catch any condition that comparing irq_count with 0x7fff will catch.

-Scott

#10 lore raw

Re: [PATCH 1/7] staging: fsl-mc: MC bus IRQ support

In reply to Scott Wood
Quoted 5 lines · Scott Wood
Quoted 1 line

Don't insist that you must be special and different from everyone else.

There are some users of U16_MAX, U32_MAX, and U64_MAX. Why use a limit for a different type than is being used? Why have s16/s32 at all if you're going to conflate it with short/int elsewhere?

I'm don't care about SHRT_MAX vs S16_MAX, I'm just saying generally, people should fight every instinct they have to be unique in the kernel.

regards,
dan carpenter

#11 lore raw

Re: [PATCH 1/7] staging: fsl-mc: MC bus IRQ support

In reply to Jose Rivera
Quoted 11 lines · On Tue, 2015-05-05 at 11:08 -0500, Rivera Jose-B46482 wrote:
Quoted 11 lines
Quoted 10 lines
Quoted 6 lines

to read what "goto error;" does. The error handling here calls devm_kfree() which is not needed... devm_ functions automatically clean up after themselves. This seems a pattern throughout. Do a search for
devm_free() and see which ones are really needed or not.

I know that memory allocated with devm_kzalloc() is freed at the end of the lifetime of the device it is attached to. However, in error paths, why wait until the device is destroyed? Why not free the memory earlier so that it can be used for other purposes?

Quoted 4 lines

Why then do the devm_kfree() function exist?

I will not remove the devm_free() calls unless the upstream maintainer requires me to do so.

The whole point of devm is to simplify (often poorly tested) error paths. You're trying to optimize the error path instead of simplify it, which doesn't make sense.

devm_kfree() is for the uncommon case when you want to free the memory in a situation where the device isn't being unbound any time soon, but you still want the memory to be handled by devm for some reason.

Most users of devm_kzalloc() do not use devm_kfree():

scott@snotra:~/fsl/git/linux/upstream$ git grep devm_kzalloc|wc -l
2750
scott@snotra:~/fsl/git/linux/upstream$ git grep devm_kfree|wc -l
118

-Scott

#12 lore raw

RE: [PATCH 1/7] staging: fsl-mc: MC bus IRQ support

Quoted 38 lines

-----Original Message-----
From: Wood Scott-B07421
Sent: Tuesday, May 05, 2015 2:42 PM
To: Rivera Jose-B46482
Cc: Dan Carpenter; [email protected]; [email protected]; [email protected]; Sharma Bhupesh-B45370; [email protected]; linux- [email protected]; Yoder Stuart-B08248; Erez Nir-RM30794; katz Itai- RM05202; Hamciuc Bogdan-BHAMCIU1; Marginean Alexandru-R89243; Schmitt Richard-B43082
Subject: Re: [PATCH 1/7] staging: fsl-mc: MC bus IRQ support

Quoted 11 lines · On Tue, 2015-05-05 at 11:08 -0500, Rivera Jose-B46482 wrote:
Quoted 11 lines
Quoted 10 lines
Quoted 6 lines

to read what "goto error;" does. The error handling here calls devm_kfree() which is not needed... devm_ functions automatically clean up after themselves. This seems a pattern throughout. Do a search for
devm_free() and see which ones are really needed or not.

I know that memory allocated with devm_kzalloc() is freed at the end of the lifetime of the device it is attached to. However, in error paths, why wait until the device is destroyed? Why not free the memory earlier so that it can be used for other purposes?

Quoted 4 lines

Why then do the devm_kfree() function exist?

I will not remove the devm_free() calls unless the upstream maintainer requires me to do so.

The whole point of devm is to simplify (often poorly tested) error paths. You're trying to optimize the error path instead of simplify it, which doesn't make sense.

devm_kfree() is for the uncommon case when you want to free the memory in a situation where the device isn't being unbound any time soon, but you still want the memory to be handled by devm for some reason.

Quoted 6 lines

Most users of devm_kzalloc() do not use devm_kfree():

scott@snotra:~/fsl/git/linux/upstream$ git grep devm_kzalloc|wc -l
2750
scott@snotra:~/fsl/git/linux/upstream$ git grep devm_kfree|wc -l
118

Ok, I'll remove the devm_kfree() calls.

Thanks,

German

Quoted 2 lines

-Scott

���{.n�+�������+%�����ݶ��w��{.n�+����{��G�����{ay�ʇڙ�,j��f���h��������z_�(�階�ݢj"���m������G������?����&���~��iO��z��v�^�m���� ������?�I�

#13 lore raw

PATCH 2/7 staging: fsl_-mc: add device binding path 'driver_override'

In reply to J. German Rivera

From: Bharat Bhushan <[email protected]>

This patch is required for vfio-fsl-mc meta driver to successfully bind layerscape container devices for device passthrough. This patch adds a mechanism to allow a layerscape device to specify a driver rather than a layerscape driver provide a device match.

This patch is based on following proposed patches for PCI and platform devices
- https://lkml.org/lkml/2014/4/8/571 :- For Platform devices
- http://lists-archives.com/linux-kernel/28030441-pci-introduce-new-device-binding-path-using-pci_dev-driver_override.html :- For PCI devices

Example to allow a device (dprc.1) to specifically bind with driver (vfio-fsl-mc):-
- echo vfio-fsl-mc > /sys/bus/fsl-mc/devices/dprc.1/driver_override
- echo dprc.1 > /sys/bus/fsl-mc/drivers/fsl_mc_dprc/unbind
- echo dprc.1 > /sys/bus/fsl-mc/drivers/vfio-fsl-mc/bind

Change-Id I11303bfe0196540e931dd2108a8b957dd45ae083

Reviewed-on: http://git.am.freescale.net:8181/34235

---
 drivers/staging/fsl-mc/bus/mc-bus.c | 67 +++++++++++++++++++++++++++++++++++++
 drivers/staging/fsl-mc/include/mc.h |  2 ++
 2 files changed, 69 insertions(+)
drivers/staging/fsl-mc/bus/mc-bus.c +67 -0
index 7332b26..a419c2f 100644
@@ -58,6 +58,12 @@ static int fsl_mc_bus_match(struct device *dev, struct device_driver *drv)
 	if (WARN_ON(!fsl_mc_bus_type.dev_root))
 		goto out;
 
+	/* When driver_override is set, only bind to the matching driver */
+	if (mc_dev->driver_override) {
+		found = !strcmp(mc_dev->driver_override, mc_drv->driver.name);
+		goto out;
+	}
+
 	if (!mc_drv->match_id_table)
 		goto out;
 
@@ -116,10 +122,69 @@ static int fsl_mc_bus_uevent(struct device *dev, struct kobj_uevent_env *env)
 	return 0;
 }
 
+static ssize_t driver_override_store(struct device *dev,
+				     struct device_attribute *attr,
+				     const char *buf, size_t count)
+{
+	struct fsl_mc_device *mc_dev = to_fsl_mc_device(dev);
+	const char *driver_override, *old = mc_dev->driver_override;
+	char *cp;
+
+	if (WARN_ON(dev->bus != &fsl_mc_bus_type))
+		return -EINVAL;
+
+	if (count > PATH_MAX)
+		return -EINVAL;
+
+	driver_override = kstrndup(buf, count, GFP_KERNEL);
+	if (!driver_override)
+		return -ENOMEM;
+
+	cp = strchr(driver_override, '\n');
+	if (cp)
+		*cp = '\0';
+
+	if (strlen(driver_override)) {
+		mc_dev->driver_override = driver_override;
+	} else {
+		kfree(driver_override);
+		mc_dev->driver_override = NULL;
+	}
+
+	kfree(old);
+
+	return count;
+}
+
+static ssize_t driver_override_show(struct device *dev,
+				    struct device_attribute *attr, char *buf)
+{
+	struct fsl_mc_device *mc_dev = to_fsl_mc_device(dev);
+
+	return sprintf(buf, "%s\n", mc_dev->driver_override);
+}
+
+static DEVICE_ATTR_RW(driver_override);
+
+static struct attribute *fsl_mc_dev_attrs[] = {
+	&dev_attr_driver_override.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);
 
@@ -499,6 +564,8 @@ void fsl_mc_device_remove(struct fsl_mc_device *mc_dev)
 			fsl_mc_bus_type.dev_root = NULL;
 	}
 
+	kfree(mc_dev->driver_override);
+	mc_dev->driver_override = NULL;
 	if (mc_bus)
 		devm_kfree(mc_dev->dev.parent, mc_bus);
 	else
drivers/staging/fsl-mc/include/mc.h +2 -0
index 531cb8c..f965c4d 100644
@@ -145,6 +145,7 @@ struct fsl_mc_device_irq {
  * @regions: pointer to array of MMIO region entries
  * @irqs: pointer to array of pointers to interrupts allocated to this device
  * @resource: generic resource associated with this MC object device, if any.
+ * @driver_override: Driver name to force a match
  *
  * Generic device object for MC object devices that are "attached" to a
  * MC bus.
@@ -177,6 +178,7 @@ struct fsl_mc_device {
 	struct resource *regions;
 	struct fsl_mc_device_irq **irqs;
 	struct fsl_mc_resource *resource;
+	const char *driver_override;
 };
 
 #define to_fsl_mc_device(_dev) \
Signature · 1 line
2.3.3
#14 lore raw

PATCH 3/7 staging: fsl-mc: Propagate driver_override for a child DPRC's children

In reply to J. German Rivera

When a child DPRC is bound to the vfio_fsl_mc driver via driver_override, its own children should not be bound to corresponding host kernel drivers, but instead should be bound to the vfio_fsl_mc driver as well.

Currently, when a child container is scanned by the vfio_fsl_mc driver, child devices found are automatically bound to corresponding host kernel drivers (e.g., DPMCP and DPBP objects are bound to the fsl_mc_allocator driver, DPNI objects are bound to the ldpaa_eth driver, etc), Then, the user has to manually unbind these child devices from their drivers, set the driver_override sysfs attribute to vfio_fsl_mc driver, for each of them and rebind them.

Change-Id I51e633367b019da1cd45bd4898e46be577b8ce42

Reviewed-on: http://git.am.freescale.net:8181/34567

---
 drivers/staging/fsl-mc/bus/dprc-driver.c    | 14 ++++++++++----
 drivers/staging/fsl-mc/bus/mc-bus.c         | 16 +++++++++++++++-
 drivers/staging/fsl-mc/include/mc-private.h |  2 ++
 3 files changed, 27 insertions(+), 5 deletions(-)
drivers/staging/fsl-mc/bus/dprc-driver.c +10 -4
index 8531ba8..ce88859 100644
@@ -151,6 +151,8 @@ static void check_plugged_state_change(struct fsl_mc_device *mc_dev,
  * dprc_add_new_devices - Adds devices to the logical bus for a DPRC
  *
  * @mc_bus_dev: pointer to the fsl-mc device that represents a DPRC object
+ * @driver_override: driver override to apply to new objects found in the DPRC,
+ * or NULL, if none.
  * @obj_desc_array: array of device descriptors for child devices currently
  * present in the physical DPRC.
  * @num_child_objects_in_mc: number of entries in obj_desc_array
@@ -160,6 +162,7 @@ static void check_plugged_state_change(struct fsl_mc_device *mc_dev,
  * in the physical DPRC.
  */
 static void dprc_add_new_devices(struct fsl_mc_device *mc_bus_dev,
+				 const char *driver_override,
 				 struct dprc_obj_desc *obj_desc_array,
 				 int num_child_objects_in_mc)
 {
@@ -183,7 +186,7 @@ static void dprc_add_new_devices(struct fsl_mc_device *mc_bus_dev,
 		}
 
 		error = fsl_mc_device_add(obj_desc, NULL, &mc_bus_dev->dev,
-					  &child_dev);
+					  driver_override, &child_dev);
 		if (error < 0)
 			continue;
 	}
@@ -242,6 +245,8 @@ static void dprc_cleanup_all_resource_pools(struct fsl_mc_device *mc_bus_dev)
  * dprc_scan_objects - Discover objects in a DPRC
  *
  * @mc_bus_dev: pointer to the fsl-mc device that represents a DPRC object
+ * @driver_override: driver override to apply to new objects found in the DPRC,
+ * or NULL, if none.
  * @total_irq_count: total number of IRQs needed by objects in the DPRC.
  *
  * Detects objects added and removed from a DPRC and synchronizes the
@@ -257,6 +262,7 @@ static void dprc_cleanup_all_resource_pools(struct fsl_mc_device *mc_bus_dev)
  * of the device drivers for the non-allocatable devices.
  */
 int dprc_scan_objects(struct fsl_mc_device *mc_bus_dev,
+		      const char *driver_override,
 		      unsigned int *total_irq_count)
 {
 	int num_child_objects;
@@ -326,7 +332,7 @@ int dprc_scan_objects(struct fsl_mc_device *mc_bus_dev,
 	dprc_remove_devices(mc_bus_dev, child_obj_desc_array,
 			    num_child_objects);
 
-	dprc_add_new_devices(mc_bus_dev, child_obj_desc_array,
+	dprc_add_new_devices(mc_bus_dev, driver_override, child_obj_desc_array,
 			     num_child_objects);
 
 	if (child_obj_desc_array)
@@ -357,7 +363,7 @@ static int dprc_scan_container(struct fsl_mc_device *mc_bus_dev)
 	 * Discover objects in the DPRC:
 	 */
 	mutex_lock(&mc_bus->scan_mutex);
-	error = dprc_scan_objects(mc_bus_dev, &irq_count);
+	error = dprc_scan_objects(mc_bus_dev, NULL, &irq_count);
 	mutex_unlock(&mc_bus->scan_mutex);
 	if (error < 0)
 		goto error;
@@ -433,7 +439,7 @@ static irqreturn_t dprc_irq0_handler_thread(int irq_num, void *arg)
 		      DPRC_IRQ_EVENT_OBJ_CREATED)) {
 		unsigned int irq_count;
 
-		error = dprc_scan_objects(mc_dev, &irq_count);
+		error = dprc_scan_objects(mc_dev, NULL, &irq_count);
 		if (error < 0) {
 			dev_err(dev, "dprc_scan_objects() failed: %d\n", error);
 			goto out;
drivers/staging/fsl-mc/bus/mc-bus.c +15 -1
index a419c2f..08fd559 100644
@@ -401,6 +401,7 @@ error_cleanup_regions:
 int fsl_mc_device_add(struct dprc_obj_desc *obj_desc,
 		      struct fsl_mc_io *mc_io,
 		      struct device *parent_dev,
+		      const char *driver_override,
 		      struct fsl_mc_device **new_mc_dev)
 {
 	int error;
@@ -433,6 +434,18 @@ int fsl_mc_device_add(struct dprc_obj_desc *obj_desc,
 
 	mc_dev->obj_desc = *obj_desc;
 	mc_dev->mc_io = mc_io;
+	if (driver_override) {
+		/*
+		 * We trust driver_override, so we don't need to use
+		 * kstrndup() here
+		 */
+		mc_dev->driver_override = kstrdup(driver_override, GFP_KERNEL);
+		if (!mc_dev->driver_override) {
+			error = -ENOMEM;
+			goto error_cleanup_dev;
+		}
+	}
+
 	device_initialize(&mc_dev->dev);
 
 	/*
@@ -1082,7 +1095,8 @@ static int fsl_mc_bus_probe(struct platform_device *pdev)
 	obj_desc.irq_count = 1;
 	obj_desc.region_count = 0;
 
-	error = fsl_mc_device_add(&obj_desc, mc_io, &pdev->dev, &mc_bus_dev);
+	error = fsl_mc_device_add(&obj_desc, mc_io, &pdev->dev, NULL,
+				  &mc_bus_dev);
 	if (error < 0)
 		goto error_cleanup_mc_io;
 
drivers/staging/fsl-mc/include/mc-private.h +2 -0
index 6e33942..5b9c8f2 100644
@@ -106,11 +106,13 @@ struct fsl_mc_bus {
 int __must_check fsl_mc_device_add(struct dprc_obj_desc *obj_desc,
 				   struct fsl_mc_io *mc_io,
 				   struct device *parent_dev,
+				   const char *driver_override,
 				   struct fsl_mc_device **new_mc_dev);
 
 void fsl_mc_device_remove(struct fsl_mc_device *mc_dev);
 
 int dprc_scan_objects(struct fsl_mc_device *mc_bus_dev,
+		      const char *driver_override,
 		      unsigned int *total_irq_count);
 
 int __init dprc_driver_init(void);
Signature · 1 line
2.3.3
#15 lore raw

PATCH 4/7 staging: fsl-mc: Upgraded MC bus driver to match MC fw 7.0.0

In reply to J. German Rivera

- Migrated MC bus driver to use DPRC flib 0.6.
- Changed IRQ setup infrastructure to be able to program MSIs for MC objects in an object-independent way.

---
 drivers/staging/fsl-mc/bus/dpmcp-cmd.h      |  79 ------------
 drivers/staging/fsl-mc/bus/dprc-cmd.h       |   6 +-
 drivers/staging/fsl-mc/bus/dprc-driver.c    | 106 +++++++++++++---
 drivers/staging/fsl-mc/bus/dprc.c           | 179 +++++++++++++++++++++++-----
 drivers/staging/fsl-mc/bus/mc-allocator.c   |  26 ++--
 drivers/staging/fsl-mc/bus/mc-bus.c         | 125 ++++++++-----------
 drivers/staging/fsl-mc/bus/mc-sys.c         |   6 +-
 drivers/staging/fsl-mc/include/dpmng.h      |   4 +-
 drivers/staging/fsl-mc/include/dprc.h       | 114 +++++++++++++-----
 drivers/staging/fsl-mc/include/mc-private.h |  29 ++++-
 drivers/staging/fsl-mc/include/mc.h         |   4 +
 11 files changed, 431 insertions(+), 247 deletions(-)
drivers/staging/fsl-mc/bus/dpmcp-cmd.h +0 -79
index 57f326b..62bdc18 100644
@@ -54,83 +54,4 @@
 #define DPMCP_CMDID_GET_IRQ_STATUS			0x016
 #define DPMCP_CMDID_CLEAR_IRQ_STATUS			0x017
 
-/*                cmd, param, offset, width, type, arg_name */
-#define DPMCP_CMD_CREATE(cmd, cfg) \
-	MC_CMD_OP(cmd, 0, 0,  32, int,      cfg->portal_id)
-
-/*                cmd, param, offset, width, type, arg_name */
-#define DPMCP_CMD_SET_IRQ(cmd, irq_index, irq_addr, irq_val, user_irq_id) \
-do { \
-	MC_CMD_OP(cmd, 0, 0,  8,  uint8_t,  irq_index);\
-	MC_CMD_OP(cmd, 0, 32, 32, uint32_t, irq_val);\
-	MC_CMD_OP(cmd, 1, 0,  64, uint64_t, irq_addr); \
-	MC_CMD_OP(cmd, 2, 0,  32, int,	    user_irq_id); \
-} while (0)
-
-/*                cmd, param, offset, width, type, arg_name */
-#define DPMCP_CMD_GET_IRQ(cmd, irq_index) \
-	MC_CMD_OP(cmd, 0, 32, 8,  uint8_t,  irq_index)
-
-/*                cmd, param, offset, width, type, arg_name */
-#define DPMCP_RSP_GET_IRQ(cmd, type, irq_addr, irq_val, user_irq_id) \
-do { \
-	MC_RSP_OP(cmd, 0, 0,  32, uint32_t, irq_val); \
-	MC_RSP_OP(cmd, 1, 0,  64, uint64_t, irq_addr); \
-	MC_RSP_OP(cmd, 2, 0,  32, int,	    user_irq_id); \
-	MC_RSP_OP(cmd, 2, 32, 32, int,	    type); \
-} while (0)
-
-/*                cmd, param, offset, width, type, arg_name */
-#define DPMCP_CMD_SET_IRQ_ENABLE(cmd, irq_index, en) \
-do { \
-	MC_CMD_OP(cmd, 0, 0,  8,  uint8_t,  en); \
-	MC_CMD_OP(cmd, 0, 32, 8,  uint8_t,  irq_index);\
-} while (0)
-
-/*                cmd, param, offset, width, type, arg_name */
-#define DPMCP_CMD_GET_IRQ_ENABLE(cmd, irq_index) \
-	MC_CMD_OP(cmd, 0, 32, 8,  uint8_t,  irq_index)
-
-/*                cmd, param, offset, width, type, arg_name */
-#define DPMCP_RSP_GET_IRQ_ENABLE(cmd, en) \
-	MC_RSP_OP(cmd, 0, 0,  8,  uint8_t,  en)
-
-/*                cmd, param, offset, width, type, arg_name */
-#define DPMCP_CMD_SET_IRQ_MASK(cmd, irq_index, mask) \
-do { \
-	MC_CMD_OP(cmd, 0, 0,  32, uint32_t, mask);\
-	MC_CMD_OP(cmd, 0, 32, 8,  uint8_t,  irq_index);\
-} while (0)
-
-/*                cmd, param, offset, width, type, arg_name */
-#define DPMCP_CMD_GET_IRQ_MASK(cmd, irq_index) \
-	MC_CMD_OP(cmd, 0, 32, 8,  uint8_t,  irq_index)
-
-/*                cmd, param, offset, width, type, arg_name */
-#define DPMCP_RSP_GET_IRQ_MASK(cmd, mask) \
-	MC_RSP_OP(cmd, 0, 0,  32, uint32_t, mask)
-
-/*                cmd, param, offset, width, type, arg_name */
-#define DPMCP_CMD_GET_IRQ_STATUS(cmd, irq_index) \
-	MC_CMD_OP(cmd, 0, 32, 8,  uint8_t,  irq_index)
-
-/*                cmd, param, offset, width, type, arg_name */
-#define DPMCP_RSP_GET_IRQ_STATUS(cmd, status) \
-	MC_RSP_OP(cmd, 0, 0,  32, uint32_t, status)
-
-/*                cmd, param, offset, width, type, arg_name */
-#define DPMCP_CMD_CLEAR_IRQ_STATUS(cmd, irq_index, status) \
-do { \
-	MC_CMD_OP(cmd, 0, 0,  32, uint32_t, status); \
-	MC_CMD_OP(cmd, 0, 32, 8,  uint8_t,  irq_index);\
-} while (0)
-
-/*                cmd, param, offset, width, type,	arg_name */
-#define DPMCP_RSP_GET_ATTRIBUTES(cmd, attr) \
-do { \
-	MC_RSP_OP(cmd, 0, 32, 32, int,	    attr->id);\
-	MC_RSP_OP(cmd, 1, 0,  16, uint16_t, attr->version.major);\
-	MC_RSP_OP(cmd, 1, 16, 16, uint16_t, attr->version.minor);\
-} while (0)
-
 #endif /* _FSL_DPMCP_CMD_H */
drivers/staging/fsl-mc/bus/dprc-cmd.h +4 -2
index 0920248..df5ad5f 100644
@@ -41,7 +41,7 @@
 #define _FSL_DPRC_CMD_H
 
 /* DPRC Version */
-#define DPRC_VER_MAJOR				3
+#define DPRC_VER_MAJOR				4
 #define DPRC_VER_MINOR				0
 
 /* Command IDs */
@@ -72,12 +72,14 @@
 #define DPRC_CMDID_GET_RES_COUNT		0x15B
 #define DPRC_CMDID_GET_RES_IDS			0x15C
 #define DPRC_CMDID_GET_OBJ_REG			0x15E
+#define DPRC_CMDID_OBJ_SET_IRQ			0x15F
+#define DPRC_CMDID_OBJ_GET_IRQ			0x160
+#define DPRC_CMDID_SET_OBJ_LABEL		0x161
 
 #define DPRC_CMDID_CONNECT			0x167
 #define DPRC_CMDID_DISCONNECT			0x168
 #define DPRC_CMDID_GET_POOL			0x169
 #define DPRC_CMDID_GET_POOL_COUNT		0x16A
-#define DPRC_CMDID_GET_PORTAL_PADDR		0x16B
 
 #define DPRC_CMDID_GET_CONNECTION		0x16C
 
drivers/staging/fsl-mc/bus/dprc-driver.c +88 -18

157 lines not on this page · raw message

drivers/staging/fsl-mc/bus/dprc.c +150 -29

341 lines not on this page · raw message

drivers/staging/fsl-mc/bus/mc-allocator.c +18 -8
index 27497e7..0c5fad0 100644
@@ -531,13 +531,19 @@ int __must_check fsl_mc_allocate_irqs(struct fsl_mc_device *mc_dev)
 
 		irqs[i] = to_fsl_mc_irq(resource);
 		res_allocated_count++;
+
+		WARN_ON(irqs[i]->mc_dev);
+		irqs[i]->mc_dev = mc_dev;
+		irqs[i]->dev_irq_index = i;
 	}
 
 	mc_dev->irqs = irqs;
 	return 0;
 error:
-	for (i = 0; i < res_allocated_count; i++)
+	for (i = 0; i < res_allocated_count; i++) {
+		irqs[i]->mc_dev = NULL;
 		fsl_mc_resource_free(&irqs[i]->resource);
+	}
 
 	if (irqs)
 		devm_kfree(&mc_dev->dev, irqs);
@@ -555,8 +561,9 @@ void fsl_mc_free_irqs(struct fsl_mc_device *mc_dev)
 	int i;
 	int irq_count;
 	struct fsl_mc_bus *mc_bus;
+	struct fsl_mc_device_irq **irqs = mc_dev->irqs;
 
-	if (WARN_ON(!mc_dev->irqs))
+	if (WARN_ON(!irqs))
 		return;
 
 	irq_count = mc_dev->obj_desc.irq_count;
@@ -569,8 +576,11 @@ void fsl_mc_free_irqs(struct fsl_mc_device *mc_dev)
 	if (WARN_ON(!mc_bus->irq_resources))
 		return;
 
-	for (i = 0; i < irq_count; i++)
-		fsl_mc_resource_free(&mc_dev->irqs[i]->resource);
+	for (i = 0; i < irq_count; i++) {
+		WARN_ON(!irqs[i]->mc_dev);
+		irqs[i]->mc_dev = NULL;
+		fsl_mc_resource_free(&irqs[i]->resource);
+	}
 
 	devm_kfree(&mc_dev->dev, mc_dev->irqs);
 	mc_dev->irqs = NULL;
@@ -604,8 +614,8 @@ static int fsl_mc_allocator_probe(struct fsl_mc_device *mc_dev)
 	if (error < 0)
 		goto error;
 
-	dev_info(&mc_dev->dev,
-		 "Allocatable MC object device bound to fsl_mc_allocator driver");
+	dev_dbg(&mc_dev->dev,
+		"Allocatable MC object device bound to fsl_mc_allocator driver");
 	return 0;
 error:
 
@@ -627,8 +637,8 @@ static int fsl_mc_allocator_remove(struct fsl_mc_device *mc_dev)
 	if (error < 0)
 		goto out;
 
-	dev_info(&mc_dev->dev,
-		 "Allocatable MC object device unbound from fsl_mc_allocator driver");
+	dev_dbg(&mc_dev->dev,
+		"Allocatable MC object device unbound from fsl_mc_allocator driver");
 	error = 0;
 out:
 	return error;
drivers/staging/fsl-mc/bus/mc-bus.c +50 -75

303 lines not on this page · raw message

drivers/staging/fsl-mc/bus/mc-sys.c +4 -2
index 5737f59..9ae000c 100644
@@ -256,8 +256,10 @@ int mc_send_command(struct fsl_mc_io *mc_io, struct mc_command *cmd)
 		 * TODO: When MC command completion interrupts are supported
 		 * call wait function here instead of usleep_range()
 		 */
-		usleep_range(MC_CMD_COMPLETION_POLLING_MIN_SLEEP_USECS,
-			     MC_CMD_COMPLETION_POLLING_MAX_SLEEP_USECS);
+		if (preemptible()) {
+			usleep_range(MC_CMD_COMPLETION_POLLING_MIN_SLEEP_USECS,
+				     MC_CMD_COMPLETION_POLLING_MAX_SLEEP_USECS);
+		}
 
 		if (time_after_eq(jiffies, jiffies_until_timeout)) {
 			pr_debug("MC command timed out (portal: %#llx, obj handle: %#x, command: %#x)\n",
drivers/staging/fsl-mc/include/dpmng.h +2 -2
index 1b052b8..a38eb1a 100644
@@ -41,11 +41,11 @@ struct fsl_mc_io;
 /**
  * Management Complex firmware version information
  */
-#define MC_VER_MAJOR 6
+#define MC_VER_MAJOR 7
 #define MC_VER_MINOR 0
 
 /**
- * struct mc_versoin
+ * struct mc_version
  * @major: Major version number: incremented on API compatibility changes
  * @minor: Minor version number: incremented on API additions (that are
  *		backward compatible); reset when major version is incremented
drivers/staging/fsl-mc/include/dprc.h +87 -27

200 lines not on this page · raw message

drivers/staging/fsl-mc/include/mc-private.h +24 -5
index 5b9c8f2..67ba488 100644
@@ -52,16 +52,31 @@ struct fsl_mc {
 };
 
 /**
+ * enum mc_region_types - Types of MC MMIO regions
+ */
+enum fsl_mc_region_types {
+	FSL_MC_PORTAL = 0x0,
+	FSL_QBMAN_PORTAL,
+
+	/*
+	 * New offset types must be added above this entry
+	 */
+	FSL_NUM_MC_OFFSET_TYPES
+};
+
+/**
  * struct fsl_mc_addr_translation_range - bus to system address translation
  * range
- * @start_mc_addr: Start MC address of the range being translated
- * @end_mc_addr: MC address of the first byte after the range (last MC
- * address of the range is end_mc_addr - 1)
+ * @mc_region_type: Type of MC region for the range being translated
+ * @start_mc_offset: Start MC offset of the range being translated
+ * @end_mc_offset: MC offset of the first byte after the range (last MC
+ * offset of the range is end_mc_offset - 1)
  * @start_phys_addr: system physical address corresponding to start_mc_addr
  */
 struct fsl_mc_addr_translation_range {
-	uint64_t start_mc_addr;
-	uint64_t end_mc_addr;
+	enum fsl_mc_region_types mc_region_type;
+	uint64_t start_mc_offset;
+	uint64_t end_mc_offset;
 	phys_addr_t start_phys_addr;
 };
 
@@ -115,6 +130,10 @@ int dprc_scan_objects(struct fsl_mc_device *mc_bus_dev,
 		      const char *driver_override,
 		      unsigned int *total_irq_count);
 
+int dprc_lookup_object(struct fsl_mc_device *mc_bus_dev,
+		       struct fsl_mc_device *child_dev,
+		       uint32_t *child_obj_index);
+
 int __init dprc_driver_init(void);
 
 void __exit dprc_driver_exit(void);
drivers/staging/fsl-mc/include/mc.h +4 -0
index f965c4d..0a2f381d 100644
@@ -110,12 +110,16 @@ struct fsl_mc_resource {
  * @msi_paddr: message-based interrupt physical address
  * @msi_value: message-based interrupt data value
  * @irq_number: Linux IRQ number assigned to the interrupt
+ * @mc_dev: MC object device that owns this interrupt
+ * @dev_irq_index: device-relative IRQ index
  * @resource: MC generic resource associated with the interrupt
  */
 struct fsl_mc_device_irq {
 	phys_addr_t msi_paddr;
 	uint32_t msi_value;
 	uint32_t irq_number;
+	struct fsl_mc_device *mc_dev;
+	uint8_t dev_irq_index;
 	struct fsl_mc_resource resource;
 };
 
Signature · 1 line
2.3.3
#16 lore raw

Re: [PATCH 4/7] staging: fsl-mc: Upgraded MC bus driver to match MC fw 7.0.0

Quoted 1 line · J. German Rivera

- Migrated MC bus driver to use DPRC flib 0.6.

What does this mean? What is a flib?

After reading the patch, apparently it means that we can remove all the ifdefs from patch 1. :)

Quoted 2 lines

- Changed IRQ setup infrastructure to be able to program MSIs for MC objects in an object-independent way.

Are these two things related?

Why does this patch add so many new EXPORTS()s?

regards,
dan carpenter

#17 lore raw

RE: [PATCH 4/7] staging: fsl-mc: Upgraded MC bus driver to match MC fw 7.0.0

Quoted 14 lines

-----Original Message-----
From: Dan Carpenter [mailto:[email protected]]
Sent: Thursday, April 30, 2015 7:13 AM
To: Rivera Jose-B46482
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Yoder Stuart- B08248; Sharma Bhupesh-B45370; [email protected]; Hamciuc Bogdan-BHAMCIU1; Erez Nir-RM30794; katz Itai-RM05202; Wood Scott-B07421; Marginean Alexandru-R89243; Schmitt Richard-B43082
Subject: Re: [PATCH 4/7] staging: fsl-mc: Upgraded MC bus driver to match MC fw 7.0.0

Quoted 5 lines
Quoted 1 line · J. German Rivera

- Migrated MC bus driver to use DPRC flib 0.6.

What does this mean? What is a flib?

The DPRC flib is the API to manipulate DPRC objects.

Quoted 3 lines

After reading the patch, apparently it means that we can remove all the ifdefs from patch 1. :)

No, we cannot as the required GIC-ITS support is not upstream yet. I added some of the #ifdefs back that were removed by mistake.

Quoted 5 lines
Quoted 2 lines

- Changed IRQ setup infrastructure to be able to program MSIs for MC objects in an object-independent way.

Are these two things related?

No.

Quoted 2 lines

Why does this patch add so many new EXPORTS()s?

Removed new EXPORTs added as they are not needed yet.

Quoted 2 lines

regards,
dan carpenter

#18 lore raw

Re: [PATCH 4/7] staging: fsl-mc: Upgraded MC bus driver to match MC fw 7.0.0

Quoted 14 lines · Jose Rivera
Quoted 6 lines · J. German Rivera
Quoted 1 line

- Migrated MC bus driver to use DPRC flib 0.6.

What does this mean? What is a flib?

The DPRC flib is the API to manipulate DPRC objects.

Quoted 3 lines

After reading the patch, apparently it means that we can remove all the ifdefs from patch 1. :)

No, we cannot as the required GIC-ITS support is not upstream yet. I added some of the #ifdefs back that were removed by mistake.

Quoted 6 lines
Quoted 5 lines
Quoted 2 lines

- Changed IRQ setup infrastructure to be able to program MSIs for MC objects in an object-independent way.

Are these two things related?

No.

When I asked this function I was partly wondering why they were broken up the way they are. This changelog was not enough information to start reviewing the patch.

regards,
dan carpenter

#19 lore raw

PATCH 5/7 staging: fsl-mc: Allow the MC bus driver to run without GIC support

In reply to J. German Rivera

If the lpi-parent property is not present in the fsl,qoriq-mc node of the device tree, the MC bus driver will assume that the GIC is not supported.

This change is made in order to be able to use the MC bus driver in a KVM VM, without having GIC-ITS support in guests. Added function fsl_mc_interrupts_supported(), which can be called from DPAA2 object drivers.

Change-Id I881ab2c45c949e55cfafe1d281a7a31560955e5b

Reviewed-on: http://git.am.freescale.net:8181/34712

---
 drivers/staging/fsl-mc/bus/dprc-driver.c    | 31 +++++++++++++++++++----------
 drivers/staging/fsl-mc/bus/mc-allocator.c   |  4 ++++
 drivers/staging/fsl-mc/bus/mc-bus.c         | 16 +++++++++++++--
 drivers/staging/fsl-mc/include/mc-private.h |  4 ++++
 drivers/staging/fsl-mc/include/mc.h         |  2 ++
 5 files changed, 45 insertions(+), 12 deletions(-)
drivers/staging/fsl-mc/bus/dprc-driver.c +21 -10
index b84cca3..ff321c9 100644
@@ -412,6 +412,7 @@ static int dprc_scan_container(struct fsl_mc_device *mc_bus_dev)
 	int error;
 	unsigned int irq_count;
 	struct fsl_mc_bus *mc_bus = to_fsl_mc_bus(mc_bus_dev);
+	struct fsl_mc *mc = dev_get_drvdata(fsl_mc_bus_type.dev_root->parent);
 
 	dprc_init_all_resource_pools(mc_bus_dev);
 
@@ -424,7 +425,7 @@ static int dprc_scan_container(struct fsl_mc_device *mc_bus_dev)
 	if (error < 0)
 		goto error;
 
-	if (!mc_bus->irq_resources) {
+	if (mc->gic_supported && !mc_bus->irq_resources) {
 		irq_count += FSL_MC_IRQ_POOL_MAX_EXTRA_IRQS;
 		error = fsl_mc_populate_irq_pool(mc_bus, irq_count);
 		if (error < 0)
@@ -754,6 +755,7 @@ static int dprc_probe(struct fsl_mc_device *mc_dev)
 	int error;
 	size_t region_size;
 	struct fsl_mc_bus *mc_bus = to_fsl_mc_bus(mc_dev);
+	struct fsl_mc *mc = dev_get_drvdata(fsl_mc_bus_type.dev_root->parent);
 
 	if (WARN_ON(strcmp(mc_dev->obj_desc.type, "dprc") != 0))
 		return -EINVAL;
@@ -792,12 +794,15 @@ static int dprc_probe(struct fsl_mc_device *mc_dev)
 	if (error < 0)
 		goto error_cleanup_open;
 
-	/*
-	 * Configure interrupts for the DPRC object associated with this MC bus:
-	 */
-	error = dprc_setup_irqs(mc_dev);
-	if (error < 0)
-		goto error_cleanup_dprc_scan;
+	if (mc->gic_supported) {
+		/*
+		 * Configure interrupts for the DPRC object associated with
+		 * this MC bus:
+		 */
+		error = dprc_setup_irqs(mc_dev);
+		if (error < 0)
+			goto error_cleanup_dprc_scan;
+	}
 
 	dev_info(&mc_dev->dev, "DPRC device bound to driver");
 	return 0;
@@ -805,7 +810,8 @@ static int dprc_probe(struct fsl_mc_device *mc_dev)
 error_cleanup_dprc_scan:
 	device_for_each_child(&mc_dev->dev, NULL, __fsl_mc_device_remove);
 	dprc_cleanup_all_resource_pools(mc_dev);
-	fsl_mc_cleanup_irq_pool(mc_bus);
+	if (mc->gic_supported)
+		fsl_mc_cleanup_irq_pool(mc_bus);
 
 error_cleanup_open:
 	(void)dprc_close(mc_dev->mc_io, mc_dev->mc_handle);
@@ -839,6 +845,7 @@ static int dprc_remove(struct fsl_mc_device *mc_dev)
 {
 	int error;
 	struct fsl_mc_bus *mc_bus = to_fsl_mc_bus(mc_dev);
+	struct fsl_mc *mc = dev_get_drvdata(fsl_mc_bus_type.dev_root->parent);
 
 	if (WARN_ON(strcmp(mc_dev->obj_desc.type, "dprc") != 0))
 		return -EINVAL;
@@ -848,14 +855,18 @@ static int dprc_remove(struct fsl_mc_device *mc_dev)
 	if (WARN_ON(!mc_bus->irq_resources))
 		return -EINVAL;
 
-	dprc_teardown_irqs(mc_dev);
+	if (mc->gic_supported)
+		dprc_teardown_irqs(mc_dev);
+
 	device_for_each_child(&mc_dev->dev, NULL, __fsl_mc_device_remove);
 	dprc_cleanup_all_resource_pools(mc_dev);
 	error = dprc_close(mc_dev->mc_io, mc_dev->mc_handle);
 	if (error < 0)
 		dev_err(&mc_dev->dev, "dprc_close() failed: %d\n", error);
 
-	fsl_mc_cleanup_irq_pool(mc_bus);
+	if (mc->gic_supported)
+		fsl_mc_cleanup_irq_pool(mc_bus);
+
 	dev_info(&mc_dev->dev, "DPRC device unbound from driver");
 	return 0;
 }
drivers/staging/fsl-mc/bus/mc-allocator.c +4 -0
index 0c5fad0..313a533 100644
@@ -489,6 +489,10 @@ int __must_check fsl_mc_allocate_irqs(struct fsl_mc_device *mc_dev)
 	struct fsl_mc_device_irq **irqs = NULL;
 	struct fsl_mc_bus *mc_bus;
 	struct fsl_mc_resource_pool *res_pool;
+	struct fsl_mc *mc = dev_get_drvdata(fsl_mc_bus_type.dev_root->parent);
+
+	if (!mc->gic_supported)
+		return -ENOTSUPP;
 
 	if (WARN_ON(mc_dev->irqs))
 		goto error;
drivers/staging/fsl-mc/bus/mc-bus.c +14 -2
index 55a8b86..be2faf6 100644
@@ -287,6 +287,14 @@ void fsl_mc_driver_unregister(struct fsl_mc_driver *mc_driver)
 }
 EXPORT_SYMBOL_GPL(fsl_mc_driver_unregister);
 
+bool fsl_mc_interrupts_supported(void)
+{
+	struct fsl_mc *mc = dev_get_drvdata(fsl_mc_bus_type.dev_root->parent);
+
+	return mc->gic_supported;
+}
+EXPORT_SYMBOL_GPL(fsl_mc_interrupts_supported);
+
 static int get_dprc_icid(struct fsl_mc_io *mc_io,
 			 int container_id, uint16_t *icid)
 {
@@ -1003,8 +1011,12 @@ static int fsl_mc_bus_probe(struct platform_device *pdev)
 
 	platform_set_drvdata(pdev, mc);
 	error = create_mc_irq_domain(pdev, &mc->irq_domain);
-	if (error < 0)
-		return error;
+	if (error < 0) {
+		dev_warn(&pdev->dev,
+			 "WARNING: MC bus driver will run without interrupt support\n");
+	} else {
+		mc->gic_supported = true;
+	}
 
 	/*
 	 * Get physical address of MC portal for the root DPRC:
drivers/staging/fsl-mc/include/mc-private.h +4 -0
index 67ba488..0757258 100644
@@ -42,11 +42,15 @@
  * struct fsl_mc - Private data of a "fsl,qoriq-mc" platform device
  * @root_mc_bus_dev: MC object device representing the root DPRC
  * @irq_domain: IRQ domain for the fsl-mc bus type
+ * @gic_supported: boolean flag that indicates if the GIC interrupt controller
+ * is supported.
+ * @num_translation_ranges: number of entries in addr_translation_ranges
  * @addr_translation_ranges: array of bus to system address translation ranges
  */
 struct fsl_mc {
 	struct fsl_mc_device *root_mc_bus_dev;
 	struct irq_domain *irq_domain;
+	bool gic_supported;
 	uint8_t num_translation_ranges;
 	struct fsl_mc_addr_translation_range *translation_ranges;
 };
drivers/staging/fsl-mc/include/mc.h +2 -0
index 0a2f381d..c2a702e4 100644
@@ -209,6 +209,8 @@ int __must_check __fsl_mc_driver_register(struct fsl_mc_driver *fsl_mc_driver,
 
 void fsl_mc_driver_unregister(struct fsl_mc_driver *driver);
 
+bool fsl_mc_interrupts_supported(void);
+
 int __must_check fsl_mc_portal_allocate(struct fsl_mc_device *mc_dev,
 					uint16_t mc_io_flags,
 					struct fsl_mc_io **new_mc_io);
Signature · 1 line
2.3.3
#20 lore raw

PATCH 6/7 staging: fsl-mc: Add locking to serialize mc_send_command() calls

In reply to J. German Rivera

Add a locking mechanism to serialize mc_send_command() calls that use the same fsl_mc_io object (same MC portal). All mc_send_command() calls with the same fsl_m_io object have to be either from non-atomic context or from atomic context, but not both. When the fsl_mc_io object is created the owner needs to know in which type of context the fsl_mc_io object is going to be used. A flag passed-in to fsl_create_mc_io() will indicate whether the fsl_mc_io object will be used in atomic or non-atomic context. If the fsl_mc_io object is going to be used in non-atomic context, mc_send_command() calls with it will be serialized using a mutex. Otherwise, if the fsl_mc_io object is going to be used in atomic context, mc_semd_command() calls with it will be serialized using a spinlock.

Change-Id Icb770cd36e204ee6a17ad0f81e1d31cc9fe96816

Reviewed-on: http://git.am.freescale.net:8181/34876

---
 drivers/staging/fsl-mc/bus/mc-sys.c     | 36 ++++++++++++++++++++++++++++-----
 drivers/staging/fsl-mc/include/mc-sys.h | 23 +++++++++++++++++++--
 2 files changed, 52 insertions(+), 7 deletions(-)
drivers/staging/fsl-mc/bus/mc-sys.c +31 -5
index 9ae000c..1679054 100644
@@ -86,6 +86,11 @@ int __must_check fsl_create_mc_io(struct device *dev,
 	mc_io->portal_phys_addr = mc_portal_phys_addr;
 	mc_io->portal_size = mc_portal_size;
 	mc_io->resource = resource;
+	if (flags & FSL_MC_IO_ATOMIC_CONTEXT_PORTAL)
+		spin_lock_init(&mc_io->spinlock);
+	else
+		mutex_init(&mc_io->mutex);
+
 	res = devm_request_mem_region(dev,
 				      mc_portal_phys_addr,
 				      mc_portal_size,
@@ -230,15 +235,26 @@ static inline enum mc_cmd_status mc_read_response(struct mc_command __iomem *
  * @cmd: command to be sent
  *
  * Returns '0' on Success; Error code otherwise.
- *
- * NOTE: This function cannot be invoked from from atomic contexts.
  */
 int mc_send_command(struct fsl_mc_io *mc_io, struct mc_command *cmd)
 {
+	int error;
 	enum mc_cmd_status status;
 	unsigned long jiffies_until_timeout =
 	    jiffies + MC_CMD_COMPLETION_TIMEOUT_JIFFIES;
 
+	if (preemptible()) {
+		if (WARN_ON(mc_io->flags & FSL_MC_IO_ATOMIC_CONTEXT_PORTAL))
+			return -EINVAL;
+
+		mutex_lock(&mc_io->mutex);
+	} else {
+		if (WARN_ON(!(mc_io->flags & FSL_MC_IO_ATOMIC_CONTEXT_PORTAL)))
+			return -EINVAL;
+
+		spin_lock(&mc_io->spinlock);
+	}
+
 	/*
 	 * Send command to the MC hardware:
 	 */
@@ -269,7 +285,8 @@ int mc_send_command(struct fsl_mc_io *mc_io, struct mc_command *cmd)
 				 (unsigned int)
 					MC_CMD_HDR_READ_CMDID(cmd->header));
 
-			return -ETIMEDOUT;
+			error = -ETIMEDOUT;
+			goto common_exit;
 		}
 	}
 
@@ -281,9 +298,18 @@ int mc_send_command(struct fsl_mc_io *mc_io, struct mc_command *cmd)
 			 mc_status_to_string(status),
 			 (unsigned int)status);
 
-		return mc_status_to_error(status);
+		error = mc_status_to_error(status);
+		goto common_exit;
 	}
 
-	return 0;
+	error = 0;
+
+common_exit:
+	if (preemptible())
+		mutex_unlock(&mc_io->mutex);
+	else
+		spin_unlock(&mc_io->spinlock);
+
+	return error;
 }
 EXPORT_SYMBOL(mc_send_command);
drivers/staging/fsl-mc/include/mc-sys.h +21 -2
index cb3b5a2..24e51f7 100644
@@ -39,6 +39,13 @@
 #include <linux/errno.h>
 #include <linux/io.h>
 #include <linux/dma-mapping.h>
+#include <linux/mutex.h>
+#include <linux/spinlock.h>
+
+/**
+ * Bit masks for a MC I/O object (struct fsl_mc_io) flags
+ */
+#define FSL_MC_IO_ATOMIC_CONTEXT_PORTAL	0x0001
 
 struct fsl_mc_resource;
 struct mc_command;
@@ -53,14 +60,26 @@ struct mc_command;
  * @resource: generic resource associated with the MC portal if
  * the MC portal came from a resource pool, or NULL if the MC portal
  * is permanently bound to a device (e.g., a DPRC)
+ * @mutex: Mutex to serialize mc_send_command() calls that use the same MC
+ * portal, if the fsl_mc_io object was created with the
+ * FSL_MC_IO_ATOMIC_CONTEXT_PORTAL flag off. mc_send_command() calls for this
+ * fsl_mc_io object must be made only from non-atomic context.
+ * @spinlock: Spinlock to serialize mc_send_command() calls that use the same MC
+ * portal, if the fsl_mc_io object was created with the
+ * FSL_MC_IO_ATOMIC_CONTEXT_PORTAL flag on. mc_send_command() calls for this
+ * fsl_mc_io object must be made only from atomic context.
  */
 struct fsl_mc_io {
 	struct device *dev;
-	uint32_t flags;
-	uint32_t portal_size;
+	uint16_t flags;
+	uint16_t portal_size;
 	phys_addr_t portal_phys_addr;
 	void __iomem *portal_virt_addr;
 	struct fsl_mc_resource *resource;
+	union {
+		struct mutex mutex;	/* serializes mc_send_command() calls */
+		spinlock_t spinlock;	/* serializes mc_send_command() calls */
+	};
 };
 
 int __must_check fsl_create_mc_io(struct device *dev,
Signature · 1 line
2.3.3
#21 lore raw

Re: [PATCH 6/7] staging: fsl-mc: Add locking to serialize mc_send_command() calls

drivers/staging/fsl-mc/bus/mc-sys.c static inline enum mc_cmd_status mc_read_response(struct mc_command __iomem * · line 244

Quoted 13 lines · J. German Rivera
drivers/staging/fsl-mc/bus/mc-sys.c +1 -2
@@ -230,15 +235,26 @@ static inline enum mc_cmd_status mc_read_response(struct mc_command __iomem *
  * @cmd: command to be sent
  *
  * Returns '0' on Success; Error code otherwise.
- *
- * NOTE: This function cannot be invoked from from atomic contexts.
  */
 int mc_send_command(struct fsl_mc_io *mc_io, struct mc_command *cmd)
 {
+	int error;
 	enum mc_cmd_status status;
 	unsigned long jiffies_until_timeout =
 	    jiffies + MC_CMD_COMPLETION_TIMEOUT_JIFFIES;

We busy loop while holding a spinlock for half a second. That seems bad.

drivers/staging/fsl-mc/bus/mc-sys.c static inline enum mc_cmd_status mc_read_response(struct mc_command __iomem * · line 246

Quoted 2 lines
drivers/staging/fsl-mc/bus/mc-sys.c +1 -0
+	if (preemptible()) {

This is wrong. If the user asked for spinlocks they should always get spinlocks. It shouldn't matter that they are not currently holding a different lock.

I'm skeptical of this locking anyway.

Also what about if they have PREEMPT disabled? There aren't any users for this stuff anyway so it's impossible to review how people are FSL_MC_IO_ATOMIC_CONTEXT_PORTAL.

Let's wait until there is a user before looking at this.

drivers/staging/fsl-mc/bus/mc-sys.c int mc_send_command(struct fsl_mc_io *mc_io, struct mc_command *cmd) · line 307

Quoted 9 lines
drivers/staging/fsl-mc/bus/mc-sys.c +5 -2
-		return mc_status_to_error(status);
+		error = mc_status_to_error(status);
+		goto common_exit;
 	}
 
-	return 0;
+	error = 0;
+
+common_exit:

Just name this unlock:.

drivers/staging/fsl-mc/bus/mc-sys.c int mc_send_command(struct fsl_mc_io *mc_io, struct mc_command *cmd) · line 314

Quoted 7 lines
drivers/staging/fsl-mc/bus/mc-sys.c +6 -0
+	if (preemptible())
+		mutex_unlock(&mc_io->mutex);
+	else
+		spin_unlock(&mc_io->spinlock);
+
+	return error;
 }

regards,
dan carpenter

#22 lore raw

RE: [PATCH 6/7] staging: fsl-mc: Add locking to serialize mc_send_command() calls

Quoted 17 lines

-----Original Message-----
From: Dan Carpenter [mailto:[email protected]]
Sent: Thursday, April 30, 2015 7:59 AM
To: Rivera Jose-B46482
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Yoder Stuart- B08248; Sharma Bhupesh-B45370; [email protected]; Hamciuc Bogdan-BHAMCIU1; Erez Nir-RM30794; katz Itai-RM05202; Wood Scott-B07421; Marginean Alexandru-R89243; Schmitt Richard-B43082
Subject: Re: [PATCH 6/7] staging: fsl-mc: Add locking to serialize mc_send_command() calls

Review static inline enum mc_cmd_status

Quoted 1 line · J. German Rivera
(quoted diff) +0 -0
@@ -230,15 +235,26 @@ static inline enum mc_cmd_status

mc_read_response(struct mc_command __iomem *

Quoted 15 lines

drivers/staging/fsl-mc/bus/mc-sys.c static inline enum mc_cmd_status mc_read_response(struct mc_command __iomem * · line 244

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

We busy loop while holding a spinlock for half a second. That seems bad.

What would be a reasonable max time for holding a spinlock here?

Quoted 37 lines

drivers/staging/fsl-mc/bus/mc-sys.c static inline enum mc_cmd_status mc_read_response(struct mc_command __iomem * · line 246

Quoted 2 lines
drivers/staging/fsl-mc/bus/mc-sys.c +1 -0
+	if (preemptible()) {

This is wrong. If the user asked for spinlocks they should always get spinlocks. It shouldn't matter that they are not currently holding a different lock.

I'm skeptical of this locking anyway.

Also what about if they have PREEMPT disabled? There aren't any users for this stuff anyway so it's impossible to review how people are FSL_MC_IO_ATOMIC_CONTEXT_PORTAL.

Let's wait until there is a user before looking at this.

drivers/staging/fsl-mc/bus/mc-sys.c int mc_send_command(struct fsl_mc_io *mc_io, struct mc_command *cmd) · line 307

Quoted 9 lines
drivers/staging/fsl-mc/bus/mc-sys.c +5 -2
-		return mc_status_to_error(status);
+		error = mc_status_to_error(status);
+		goto common_exit;
 	}
 
-	return 0;
+	error = 0;
+
+common_exit:

Just name this unlock:.

drivers/staging/fsl-mc/bus/mc-sys.c int mc_send_command(struct fsl_mc_io *mc_io, struct mc_command *cmd) · line 314

Quoted 7 lines
drivers/staging/fsl-mc/bus/mc-sys.c +6 -0
+	if (preemptible())
+		mutex_unlock(&mc_io->mutex);
+	else
+		spin_unlock(&mc_io->spinlock);
+
+	return error;
 }

regards,
dan carpenter

#23 lore raw

PATCH 7/7 staging: fsl-mc: Use DPMCP IRQ and completion var to wait for MC

In reply to J. German Rivera

- Refactored fsl_mc_io object to have a DPMCP object attached to it
- Created DPMCP object for DPRC's built-in portal, so that waiting on MC command completions for MC commands sent on the DPRC's built-in portal can be done using a DPMCP interrupt and a Linux completion variable. For most cases, mc_send_command() will wait on this completion variable, instead of doing polling. This completion variable will be signaled from the DPMCP IRQ handler.

Change-Id Iab294be9c00fb029702cc8625eaf29ba058fa960

Reviewed-on: http://git.am.freescale.net:8181/34276

---
 drivers/staging/fsl-mc/bus/dprc-driver.c    | 231 +++++++++++-----
 drivers/staging/fsl-mc/bus/mc-allocator.c   | 107 +++----
 drivers/staging/fsl-mc/bus/mc-bus.c         |  95 ++++++-
 drivers/staging/fsl-mc/bus/mc-sys.c         | 414 +++++++++++++++++++++++++---
 drivers/staging/fsl-mc/include/mc-private.h |   6 +-
 drivers/staging/fsl-mc/include/mc-sys.h     |  37 ++-
 6 files changed, 721 insertions(+), 169 deletions(-)
drivers/staging/fsl-mc/bus/dprc-driver.c +162 -69
index ff321c9..0fb065c 100644
@@ -15,6 +15,7 @@
 #include <linux/slab.h>
 #include <linux/interrupt.h>
 #include "dprc-cmd.h"
+#include "dpmcp.h"
 
 struct dprc_child_objs {
 	int child_count;
@@ -348,57 +349,6 @@ int dprc_scan_objects(struct fsl_mc_device *mc_bus_dev,
 EXPORT_SYMBOL_GPL(dprc_scan_objects);
 
 /**
- * dprc_lookup_object - Finds a given MC object in a DPRC and returns
- * the index of the object in the DPRC
- *
- * @mc_bus_dev: pointer to the fsl-mc device that represents a DPRC object
- * @child_dev: pointer to the fsl-mc device to be looked up
- * @child_obj_index: output parameter to hold the index of the object
- */
-int dprc_lookup_object(struct fsl_mc_device *mc_bus_dev,
-		       struct fsl_mc_device *child_dev,
-		       uint32_t *child_obj_index)
-{
-	int i;
-	int num_child_objects;
-	int error;
-
-	error = dprc_get_obj_count(mc_bus_dev->mc_io,
-				   mc_bus_dev->mc_handle,
-				   &num_child_objects);
-	if (error < 0) {
-		dev_err(&mc_bus_dev->dev, "dprc_get_obj_count() failed: %d\n",
-			error);
-		return error;
-	}
-
-	for (i = 0; i < num_child_objects; i++) {
-		struct dprc_obj_desc obj_desc;
-
-		error = dprc_get_obj(mc_bus_dev->mc_io,
-				     mc_bus_dev->mc_handle,
-				     i, &obj_desc);
-		if (error < 0) {
-			dev_err(&mc_bus_dev->dev,
-				"dprc_get_obj(i=%d) failed: %d\n",
-				i, error);
-			return error;
-		}
-
-		if (strcmp(obj_desc.type, child_dev->obj_desc.type) == 0 &&
-		    obj_desc.id == child_dev->obj_desc.id) {
-			*child_obj_index = i;
-			return 0;
-		}
-	}
-
-	dev_err(&mc_bus_dev->dev, "%s.%u not found\n",
-		child_dev->obj_desc.type, child_dev->obj_desc.id);
-
-	return -ENODEV;
-}
-
-/**
  * dprc_scan_container - Scans a physical DPRC and synchronizes Linux bus state
  *
  * @mc_bus_dev: pointer to the fsl-mc device that represents a DPRC object
@@ -412,7 +362,6 @@ static int dprc_scan_container(struct fsl_mc_device *mc_bus_dev)
 	int error;
 	unsigned int irq_count;
 	struct fsl_mc_bus *mc_bus = to_fsl_mc_bus(mc_bus_dev);
-	struct fsl_mc *mc = dev_get_drvdata(fsl_mc_bus_type.dev_root->parent);
 
 	dprc_init_all_resource_pools(mc_bus_dev);
 
@@ -425,7 +374,7 @@ static int dprc_scan_container(struct fsl_mc_device *mc_bus_dev)
 	if (error < 0)
 		goto error;
 
-	if (mc->gic_supported && !mc_bus->irq_resources) {
+	if (fsl_mc_interrupts_supported() && !mc_bus->irq_resources) {
 		irq_count += FSL_MC_IRQ_POOL_MAX_EXTRA_IRQS;
 		error = fsl_mc_populate_irq_pool(mc_bus, irq_count);
 		if (error < 0)
@@ -466,7 +415,8 @@ static irqreturn_t dprc_irq0_handler_thread(int irq_num, void *arg)
 	struct fsl_mc_io *mc_io = mc_dev->mc_io;
 	int irq_index = 0;
 
-	dev_dbg(dev, "DPRC IRQ %d\n", irq_num);
+	dev_dbg(dev, "DPRC IRQ %d triggered on CPU %u\n",
+		irq_num, smp_processor_id());
 	if (WARN_ON(!(mc_dev->flags & FSL_MC_IS_DPRC)))
 		return IRQ_HANDLED;
 
@@ -540,7 +490,8 @@ static int disable_dprc_irqs(struct fsl_mc_device *mc_dev)
 		error = dprc_set_irq_enable(mc_io, mc_dev->mc_handle, i, 0);
 		if (error < 0) {
 			dev_err(&mc_dev->dev,
-				"dprc_set_irq_enable() failed: %d\n", error);
+				"Disabling DPRC IRQ %d failed: dprc_set_irq_enable() failed: %d\n",
+				i, error);
 
 			return error;
 		}
@@ -551,7 +502,8 @@ static int disable_dprc_irqs(struct fsl_mc_device *mc_dev)
 		error = dprc_set_irq_mask(mc_io, mc_dev->mc_handle, i, 0x0);
 		if (error < 0) {
 			dev_err(&mc_dev->dev,
-				"dprc_set_irq_mask() failed: %d\n", error);
+				"Disabling DPRC IRQ %d failed: dprc_set_irq_mask() failed: %d\n",
+				i, error);
 
 			return error;
 		}
@@ -563,8 +515,9 @@ static int disable_dprc_irqs(struct fsl_mc_device *mc_dev)
 					      ~0x0U);
 		if (error < 0) {
 			dev_err(&mc_dev->dev,
-				"dprc_clear_irq_status() failed: %d\n",
-				error);
+				"Disabling DPRC IRQ %d failed: dprc_clear_irq_status() failed: %d\n",
+				i, error);
+
 			return error;
 		}
 	}
@@ -685,7 +638,8 @@ static int enable_dprc_irqs(struct fsl_mc_device *mc_dev)
 					  ~0x0u);
 		if (error < 0) {
 			dev_err(&mc_dev->dev,
-				"dprc_set_irq_mask() failed: %d\n", error);
+				"Enabling DPRC IRQ %d failed: dprc_set_irq_mask() failed: %d\n",
+				i, error);
 
 			return error;
 		}
@@ -698,7 +652,8 @@ static int enable_dprc_irqs(struct fsl_mc_device *mc_dev)
 					    i, 1);
 		if (error < 0) {
 			dev_err(&mc_dev->dev,
-				"dprc_set_irq_enable() failed: %d\n", error);
+				"Enabling DPRC IRQ %d failed: dprc_set_irq_enable() failed: %d\n",
+				i, error);
 
 			return error;
 		}
@@ -740,6 +695,95 @@ error_free_irqs:
 	return error;
 }
 
+/*
+ * Creates a DPMCP for a DPRC's built-in MC portal
+ */
+static int dprc_create_dpmcp(struct fsl_mc_device *dprc_dev)
+{
+	int error;
+	struct dpmcp_cfg dpmcp_cfg;
+	uint16_t dpmcp_handle;
+	struct dprc_res_req res_req;
+	struct dpmcp_attr dpmcp_attr;
+	struct fsl_mc_bus *mc_bus = to_fsl_mc_bus(dprc_dev);
+
+	dpmcp_cfg.portal_id = mc_bus->dprc_attr.portal_id;
+	error = dpmcp_create(dprc_dev->mc_io, &dpmcp_cfg, &dpmcp_handle);
+	if (error < 0) {
+		dev_err(&dprc_dev->dev, "dpmcp_create() failed: %d\n",
+			error);
+		return error;
+	}
+
+	/*
+	 * Set the state of the newly created DPMCP object to be "plugged":
+	 */
+
+	error = dpmcp_get_attributes(dprc_dev->mc_io, dpmcp_handle,
+				     &dpmcp_attr);
+	if (error < 0) {
+		dev_err(&dprc_dev->dev, "dpmcp_get_attributes() failed: %d\n",
+			error);
+		goto error_destroy_dpmcp;
+	}
+
+	if (WARN_ON(dpmcp_attr.id != mc_bus->dprc_attr.portal_id)) {
+		error = -EINVAL;
+		goto error_destroy_dpmcp;
+	}
+
+	strcpy(res_req.type, "dpmcp");
+	res_req.num = 1;
+	res_req.options =
+			(DPRC_RES_REQ_OPT_EXPLICIT | DPRC_RES_REQ_OPT_PLUGGED);
+	res_req.id_base_align = dpmcp_attr.id;
+
+	error = dprc_assign(dprc_dev->mc_io,
+			    dprc_dev->mc_handle,
+			    dprc_dev->obj_desc.id,
+			    &res_req);
+
+	if (error < 0) {
+		dev_err(&dprc_dev->dev, "dprc_assign() failed: %d\n", error);
+		goto error_destroy_dpmcp;
+	}
+
+	(void)dpmcp_close(dprc_dev->mc_io, dpmcp_handle);
+	return 0;
+
+error_destroy_dpmcp:
+	(void)dpmcp_destroy(dprc_dev->mc_io, dpmcp_handle);
+	return error;
+}
+
+/*
+ * Destroys the DPMCP for a DPRC's built-in MC portal
+ */
+static void dprc_destroy_dpmcp(struct fsl_mc_device *dprc_dev)
+{
+	int error;
+	uint16_t dpmcp_handle;
+	struct fsl_mc_bus *mc_bus = to_fsl_mc_bus(dprc_dev);
+
+	if (WARN_ON(!dprc_dev->mc_io || dprc_dev->mc_io->dpmcp_dev))
+		return;
+
+	error = dpmcp_open(dprc_dev->mc_io, mc_bus->dprc_attr.portal_id,
+			   &dpmcp_handle);
+	if (error < 0) {
+		dev_err(&dprc_dev->dev, "dpmcp_open() failed: %d\n",
+			error);
+		return;
+	}
+
+	error = dpmcp_destroy(dprc_dev->mc_io, dpmcp_handle);
+	if (error < 0) {
+		dev_err(&dprc_dev->dev, "dpmcp_destroy() failed: %d\n",
+			error);
+		return;
+	}
+}
+
 /**
  * dprc_probe - callback invoked when a DPRC is being bound to this driver
  *
@@ -755,7 +799,7 @@ static int dprc_probe(struct fsl_mc_device *mc_dev)
 	int error;
 	size_t region_size;
 	struct fsl_mc_bus *mc_bus = to_fsl_mc_bus(mc_dev);
-	struct fsl_mc *mc = dev_get_drvdata(fsl_mc_bus_type.dev_root->parent);
+	bool mc_io_created = false;
 
 	if (WARN_ON(strcmp(mc_dev->obj_desc.type, "dprc") != 0))
 		return -EINVAL;
@@ -776,6 +820,8 @@ static int dprc_probe(struct fsl_mc_device *mc_dev)
 					 NULL, 0, &mc_dev->mc_io);
 		if (error < 0)
 			return error;
+
+		mc_io_created = true;
 	}
 
 	error = dprc_open(mc_dev->mc_io, mc_dev->obj_desc.id,
@@ -785,16 +831,55 @@ static int dprc_probe(struct fsl_mc_device *mc_dev)
 		goto error_cleanup_mc_io;
 	}
 
+	error = dprc_get_attributes(mc_dev->mc_io, mc_dev->mc_handle,
+				    &mc_bus->dprc_attr);
+	if (error < 0) {
+		dev_err(&mc_dev->dev, "dprc_get_attributes() failed: %d\n",
+			error);
+		goto error_cleanup_open;
+	}
+
+	if (fsl_mc_interrupts_supported()) {
+		/*
+		 * Create DPMCP for the DPRC's built-in portal:
+		 */
+		error = dprc_create_dpmcp(mc_dev);
+		if (error < 0)
+			goto error_cleanup_open;
+	}
+
 	mutex_init(&mc_bus->scan_mutex);
 
 	/*
-	 * Discover MC objects in DPRC object:
+	 * Discover MC objects in the DPRC object:
 	 */
 	error = dprc_scan_container(mc_dev);
 	if (error < 0)
-		goto error_cleanup_open;
+		goto error_destroy_dpmcp;
+
+	if (fsl_mc_interrupts_supported()) {
+		/*
+		 * The fsl_mc_device object associated with the DPMCP object
+		 * created above was created as part of the
+		 * dprc_scan_container() call above:
+		 */
+		if (WARN_ON(!mc_dev->mc_io->dpmcp_dev)) {
+			error = -EINVAL;
+			goto error_cleanup_dprc_scan;
+		}
+
+		/*
+		 * Configure interrupt for the DPMCP object associated with the
+		 * DPRC object's built-in portal:
+		 *
+		 * NOTE: We have to do this after calling dprc_scan_container(),
+		 * since dprc_scan_container() will populate the IRQ pool for
+		 * this DPRC.
+		 */
+		error = fsl_mc_io_setup_dpmcp_irq(mc_dev->mc_io);
+		if (error < 0)
+			goto error_cleanup_dprc_scan;
 
-	if (mc->gic_supported) {
 		/*
 		 * Configure interrupts for the DPRC object associated with
 		 * this MC bus:
@@ -808,16 +893,23 @@ static int dprc_probe(struct fsl_mc_device *mc_dev)
 	return 0;
 
 error_cleanup_dprc_scan:
+	fsl_mc_io_unset_dpmcp(mc_dev->mc_io);
 	device_for_each_child(&mc_dev->dev, NULL, __fsl_mc_device_remove);
 	dprc_cleanup_all_resource_pools(mc_dev);
-	if (mc->gic_supported)
+	if (fsl_mc_interrupts_supported())
 		fsl_mc_cleanup_irq_pool(mc_bus);
 
+error_destroy_dpmcp:
+	dprc_destroy_dpmcp(mc_dev);
+
 error_cleanup_open:
 	(void)dprc_close(mc_dev->mc_io, mc_dev->mc_handle);
 
 error_cleanup_mc_io:
-	fsl_destroy_mc_io(mc_dev->mc_io);
+	if (mc_io_created) {
+		fsl_destroy_mc_io(mc_dev->mc_io);
+		mc_dev->mc_io = NULL;
+	}
 	return error;
 }
 
@@ -845,7 +937,6 @@ static int dprc_remove(struct fsl_mc_device *mc_dev)
 {
 	int error;
 	struct fsl_mc_bus *mc_bus = to_fsl_mc_bus(mc_dev);
-	struct fsl_mc *mc = dev_get_drvdata(fsl_mc_bus_type.dev_root->parent);
 
 	if (WARN_ON(strcmp(mc_dev->obj_desc.type, "dprc") != 0))
 		return -EINVAL;
@@ -855,16 +946,18 @@ static int dprc_remove(struct fsl_mc_device *mc_dev)
 	if (WARN_ON(!mc_bus->irq_resources))
 		return -EINVAL;
 
-	if (mc->gic_supported)
+	if (fsl_mc_interrupts_supported())
 		dprc_teardown_irqs(mc_dev);
 
+	fsl_mc_io_unset_dpmcp(mc_dev->mc_io);
 	device_for_each_child(&mc_dev->dev, NULL, __fsl_mc_device_remove);
 	dprc_cleanup_all_resource_pools(mc_dev);
+	dprc_destroy_dpmcp(mc_dev);
 	error = dprc_close(mc_dev->mc_io, mc_dev->mc_handle);
 	if (error < 0)
 		dev_err(&mc_dev->dev, "dprc_close() failed: %d\n", error);
 
-	if (mc->gic_supported)
+	if (fsl_mc_interrupts_supported())
 		fsl_mc_cleanup_irq_pool(mc_bus);
 
 	dev_info(&mc_dev->dev, "DPRC device unbound from driver");
drivers/staging/fsl-mc/bus/mc-allocator.c +60 -47

173 lines not on this page · raw message

drivers/staging/fsl-mc/bus/mc-bus.c +85 -10

238 lines not on this page · raw message

drivers/staging/fsl-mc/bus/mc-sys.c +382 -32

486 lines not on this page · raw message

drivers/staging/fsl-mc/include/mc-private.h +2 -4
index 0757258..90b059a 100644
@@ -111,12 +111,14 @@ struct fsl_mc_resource_pool {
  * from the physical DPRC.
  * @irq_resources: Pointer to array of IRQ objects for the IRQ pool.
  * @scan_mutex: Serializes bus scanning
+ * @dprc_attr: DPRC attributes
  */
 struct fsl_mc_bus {
 	struct fsl_mc_device mc_dev;
 	struct fsl_mc_resource_pool resource_pools[FSL_MC_NUM_POOL_TYPES];
 	struct fsl_mc_device_irq *irq_resources;
 	struct mutex scan_mutex;    /* serializes bus scanning */
+	struct dprc_attributes dprc_attr;
 };
 
 #define to_fsl_mc_bus(_mc_dev) \
@@ -134,10 +136,6 @@ int dprc_scan_objects(struct fsl_mc_device *mc_bus_dev,
 		      const char *driver_override,
 		      unsigned int *total_irq_count);
 
-int dprc_lookup_object(struct fsl_mc_device *mc_bus_dev,
-		       struct fsl_mc_device *child_dev,
-		       uint32_t *child_obj_index);
-
 int __init dprc_driver_init(void);
 
 void __exit dprc_driver_exit(void);
drivers/staging/fsl-mc/include/mc-sys.h +30 -7
index 24e51f7..6234425 100644
@@ -39,6 +39,7 @@
 #include <linux/errno.h>
 #include <linux/io.h>
 #include <linux/dma-mapping.h>
+#include <linux/completion.h>
 #include <linux/mutex.h>
 #include <linux/spinlock.h>
 
@@ -57,9 +58,11 @@ struct mc_command;
  * @portal_size: MC command portal size in bytes
  * @portal_phys_addr: MC command portal physical address
  * @portal_virt_addr: MC command portal virtual address
- * @resource: generic resource associated with the MC portal if
- * the MC portal came from a resource pool, or NULL if the MC portal
- * is permanently bound to a device (e.g., a DPRC)
+ * @dpmcp_dev: pointer to the DPMCP device associated with the MC portal.
+ * @mc_command_done_irq_armed: Flag indicating that the MC command done IRQ
+ * is currently armed.
+ * @mc_command_done_completion: Completion variable to be signaled when an MC
+ * command sent to the MC fw is completed.
  * @mutex: Mutex to serialize mc_send_command() calls that use the same MC
  * portal, if the fsl_mc_io object was created with the
  * FSL_MC_IO_ATOMIC_CONTEXT_PORTAL flag off. mc_send_command() calls for this
@@ -75,21 +78,41 @@ struct fsl_mc_io {
 	uint16_t portal_size;
 	phys_addr_t portal_phys_addr;
 	void __iomem *portal_virt_addr;
-	struct fsl_mc_resource *resource;
+	struct fsl_mc_device *dpmcp_dev;
 	union {
-		struct mutex mutex;	/* serializes mc_send_command() calls */
-		spinlock_t spinlock;	/* serializes mc_send_command() calls */
+		/*
+		 * These fields are only meaningful if the
+		 * FSL_MC_IO_ATOMIC_CONTEXT_PORTAL flag is not set
+		 */
+		struct {
+			struct mutex mutex; /* serializes mc_send_command() */
+			struct completion mc_command_done_completion;
+			bool mc_command_done_irq_armed;
+		};
+
+		/*
+		 * This field is only meaningful if the
+		 * FSL_MC_IO_ATOMIC_CONTEXT_PORTAL flag is set
+		 */
+		spinlock_t spinlock;	/* serializes mc_send_command() */
 	};
 };
 
 int __must_check fsl_create_mc_io(struct device *dev,
 				  phys_addr_t mc_portal_phys_addr,
 				  uint32_t mc_portal_size,
-				  struct fsl_mc_resource *resource,
+				  struct fsl_mc_device *dpmcp_dev,
 				  uint32_t flags, struct fsl_mc_io **new_mc_io);
 
 void fsl_destroy_mc_io(struct fsl_mc_io *mc_io);
 
+int fsl_mc_io_set_dpmcp(struct fsl_mc_io *mc_io,
+			struct fsl_mc_device *dpmcp_dev);
+
+void fsl_mc_io_unset_dpmcp(struct fsl_mc_io *mc_io);
+
+int fsl_mc_io_setup_dpmcp_irq(struct fsl_mc_io *mc_io);
+
 int mc_send_command(struct fsl_mc_io *mc_io, struct mc_command *cmd);
 
 #endif /* _FSL_MC_SYS_H */
Signature · 1 line
2.3.3
#24 lore raw

Re: [PATCH 7/7] staging: fsl-mc: Use DPMCP IRQ and completion var to wait for MC

drivers/staging/fsl-mc/bus/dprc-driver.c int dprc_scan_objects(struct fsl_mc_device *mc_bus_dev, · line 360

Quoted 11 lines · J. German Rivera

/**
- * dprc_lookup_object - Finds a given MC object in a DPRC and returns
- * the index of the object in the DPRC
- *
- * @mc_bus_dev: pointer to the fsl-mc device that represents a DPRC object
- * @child_dev: pointer to the fsl-mc device to be looked up
- * @child_obj_index: output parameter to hold the index of the object
- */

drivers/staging/fsl-mc/bus/dprc-driver.c +0 -3
-int dprc_lookup_object(struct fsl_mc_device *mc_bus_dev,
-		       struct fsl_mc_device *child_dev,
-		       uint32_t *child_obj_index)

This patchset is kind of jumbled up. We introduced this function in patch 4. There were never any users. Now we are deleting it in patch 7.

regards,
dan carpenter