Linux-i3c Archive mirror
 help / color / mirror / Atom feed
* [PATCH 00/12] i3c: mipi-i3c-hci: Enabling fixes
@ 2023-09-21  5:56 Jarkko Nikula
  2023-09-21  5:56 ` [PATCH 01/12] i3c: master: Inherit DMA masks and parameters from parent device Jarkko Nikula
                   ` (12 more replies)
  0 siblings, 13 replies; 14+ messages in thread
From: Jarkko Nikula @ 2023-09-21  5:56 UTC (permalink / raw
  To: Alexandre Belloni; +Cc: linux-i3c, Jarkko Nikula

Hi

I've been hacking with an early MIPI I3C HCI version compatible
controller on our development HW. Basically a glue code registering the
"mipi-i3c-hci" platform device with some additional code for logic on top
of MIPI I3C HCI.

This early MIPI I3C HCI version won't be productized and the glue code
won't be released in near future but I believe these patches might
benefit others who may be also enabling the MIPI I3C HCI on their HW.

Patches are on top of v6.6-rc1.

Jarkko Nikula (12):
  i3c: master: Inherit DMA masks and parameters from parent device
  i3c: mipi-i3c-hci: Add MODULE_ALIAS
  i3c: mipi-i3c-hci: Fix DAT/DCT entry sizes
  i3c: mipi-i3c-hci: Fix out of bounds access in hci_dma_irq_handler
  i3c: mipi-i3c-hci: Remove BUG() when Ring Abort request times out
  i3c: mipi-i3c-hci: Set ring start request together with enable
  i3c: mipi-i3c-hci: Fix race between bus cleanup and interrupt
  i3c: mipi-i3c-hci: Set number of SW enabled Ring Bundles earlier
  i3c: mipi-i3c-hci: Do not unmap region not mapped for transfer
  i3c: mipi-i3c-hci: Fix missing xfer->completion in hci_cmd_v1_daa()
  i3c: mipi-i3c-hci: Resume controller explicitly
  i3c: mipi-i3c-hci: Resume controller after aborted transfer

 drivers/i3c/master.c                     |  4 ++++
 drivers/i3c/master/mipi-i3c-hci/cmd_v1.c |  1 +
 drivers/i3c/master/mipi-i3c-hci/core.c   | 14 ++++++++------
 drivers/i3c/master/mipi-i3c-hci/dma.c    | 19 ++++++++++++-------
 4 files changed, 25 insertions(+), 13 deletions(-)

-- 
2.40.1


-- 
linux-i3c mailing list
linux-i3c@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-i3c

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

* [PATCH 01/12] i3c: master: Inherit DMA masks and parameters from parent device
  2023-09-21  5:56 [PATCH 00/12] i3c: mipi-i3c-hci: Enabling fixes Jarkko Nikula
@ 2023-09-21  5:56 ` Jarkko Nikula
  2023-09-21  5:56 ` [PATCH 02/12] i3c: mipi-i3c-hci: Add MODULE_ALIAS Jarkko Nikula
                   ` (11 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: Jarkko Nikula @ 2023-09-21  5:56 UTC (permalink / raw
  To: Alexandre Belloni; +Cc: linux-i3c, Jarkko Nikula

Copy the DMA masks and parameters for an I3C master device from parent
device so that the master device has them set for the DMA buffer and
mapping API.

Signed-off-by: Jarkko Nikula <jarkko.nikula@linux.intel.com>
---
 drivers/i3c/master.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c
index 87283e4a4607..401380c17156 100644
--- a/drivers/i3c/master.c
+++ b/drivers/i3c/master.c
@@ -2629,6 +2629,10 @@ int i3c_master_register(struct i3c_master_controller *master,
 	device_initialize(&master->dev);
 	dev_set_name(&master->dev, "i3c-%d", i3cbus->id);
 
+	master->dev.dma_mask = parent->dma_mask;
+	master->dev.coherent_dma_mask = parent->coherent_dma_mask;
+	master->dev.dma_parms = parent->dma_parms;
+
 	ret = of_populate_i3c_bus(master);
 	if (ret)
 		goto err_put_dev;
-- 
2.40.1


-- 
linux-i3c mailing list
linux-i3c@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-i3c

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

* [PATCH 02/12] i3c: mipi-i3c-hci: Add MODULE_ALIAS
  2023-09-21  5:56 [PATCH 00/12] i3c: mipi-i3c-hci: Enabling fixes Jarkko Nikula
  2023-09-21  5:56 ` [PATCH 01/12] i3c: master: Inherit DMA masks and parameters from parent device Jarkko Nikula
@ 2023-09-21  5:56 ` Jarkko Nikula
  2023-09-21  5:56 ` [PATCH 03/12] i3c: mipi-i3c-hci: Fix DAT/DCT entry sizes Jarkko Nikula
                   ` (10 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: Jarkko Nikula @ 2023-09-21  5:56 UTC (permalink / raw
  To: Alexandre Belloni; +Cc: linux-i3c, Jarkko Nikula

Add MODULE_ALIAS() in order to be able to autoload this driver when the
device is added as a platform device from another glue code driver.

Signed-off-by: Jarkko Nikula <jarkko.nikula@linux.intel.com>
---
 drivers/i3c/master/mipi-i3c-hci/core.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/i3c/master/mipi-i3c-hci/core.c b/drivers/i3c/master/mipi-i3c-hci/core.c
index 837af83c85f4..8f43ad81fbfd 100644
--- a/drivers/i3c/master/mipi-i3c-hci/core.c
+++ b/drivers/i3c/master/mipi-i3c-hci/core.c
@@ -787,6 +787,7 @@ static struct platform_driver i3c_hci_driver = {
 	},
 };
 module_platform_driver(i3c_hci_driver);
+MODULE_ALIAS("platform:mipi-i3c-hci");
 
 MODULE_AUTHOR("Nicolas Pitre <npitre@baylibre.com>");
 MODULE_DESCRIPTION("MIPI I3C HCI driver");
-- 
2.40.1


-- 
linux-i3c mailing list
linux-i3c@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-i3c

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

* [PATCH 03/12] i3c: mipi-i3c-hci: Fix DAT/DCT entry sizes
  2023-09-21  5:56 [PATCH 00/12] i3c: mipi-i3c-hci: Enabling fixes Jarkko Nikula
  2023-09-21  5:56 ` [PATCH 01/12] i3c: master: Inherit DMA masks and parameters from parent device Jarkko Nikula
  2023-09-21  5:56 ` [PATCH 02/12] i3c: mipi-i3c-hci: Add MODULE_ALIAS Jarkko Nikula
@ 2023-09-21  5:56 ` Jarkko Nikula
  2023-09-21  5:56 ` [PATCH 04/12] i3c: mipi-i3c-hci: Fix out of bounds access in hci_dma_irq_handler Jarkko Nikula
                   ` (9 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: Jarkko Nikula @ 2023-09-21  5:56 UTC (permalink / raw
  To: Alexandre Belloni; +Cc: linux-i3c, Jarkko Nikula

MIPI I3C HCI specification v1.1 describes the ENTRY_SIZE field for the
Device Address Table (DAT) and the Device Characteristics Table (DCT)
section offset registers (DAT_SECTION_OFFSET and DCT_SECTION_OFFSET).
That field is not documented in earlier version.

ENTRY_SIZE value 0 is meant to be backward compatible. For the DAT entry
size it is interpreted as 2 DWORDs (8-bytes) and for the DCT entry size
as 4 DWORDs (16-bytes). Values 1-15 are reserved for future use.

New version I believe fixes also the TABLE_SIZE field description.
Before it was defined in DWORDs which I believe is incorrect since the
DAT/DCT table entry structures, and sizes, are described having
8-bytes/16-bytes entries.

This is more clear in the specification v1.1 which states the TABLE_SIZE
fields are interpreted as number of entries in the DAT/DCT tables. I
believe this same holds also in earlier version, at least it makes more
sense.

Fix code accordingly and let the DAT_entry_size and the DCT_entry_size
variables carry the size as bytes. Which is how it is already
interpreted in the dat_v1.c: hci_dat_v1_init().

Signed-off-by: Jarkko Nikula <jarkko.nikula@linux.intel.com>
---
 drivers/i3c/master/mipi-i3c-hci/core.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/i3c/master/mipi-i3c-hci/core.c b/drivers/i3c/master/mipi-i3c-hci/core.c
index 8f43ad81fbfd..76a3e6bb3665 100644
--- a/drivers/i3c/master/mipi-i3c-hci/core.c
+++ b/drivers/i3c/master/mipi-i3c-hci/core.c
@@ -610,17 +610,17 @@ static int i3c_hci_init(struct i3c_hci *hci)
 	offset = FIELD_GET(DAT_TABLE_OFFSET, regval);
 	hci->DAT_regs = offset ? hci->base_regs + offset : NULL;
 	hci->DAT_entries = FIELD_GET(DAT_TABLE_SIZE, regval);
-	hci->DAT_entry_size = FIELD_GET(DAT_ENTRY_SIZE, regval);
+	hci->DAT_entry_size = FIELD_GET(DAT_ENTRY_SIZE, regval) ? 0 : 8;
 	dev_info(&hci->master.dev, "DAT: %u %u-bytes entries at offset %#x\n",
-		 hci->DAT_entries, hci->DAT_entry_size * 4, offset);
+		 hci->DAT_entries, hci->DAT_entry_size, offset);
 
 	regval = reg_read(DCT_SECTION);
 	offset = FIELD_GET(DCT_TABLE_OFFSET, regval);
 	hci->DCT_regs = offset ? hci->base_regs + offset : NULL;
 	hci->DCT_entries = FIELD_GET(DCT_TABLE_SIZE, regval);
-	hci->DCT_entry_size = FIELD_GET(DCT_ENTRY_SIZE, regval);
+	hci->DCT_entry_size = FIELD_GET(DCT_ENTRY_SIZE, regval) ? 0 : 16;
 	dev_info(&hci->master.dev, "DCT: %u %u-bytes entries at offset %#x\n",
-		 hci->DCT_entries, hci->DCT_entry_size * 4, offset);
+		 hci->DCT_entries, hci->DCT_entry_size, offset);
 
 	regval = reg_read(RING_HEADERS_SECTION);
 	offset = FIELD_GET(RING_HEADERS_OFFSET, regval);
-- 
2.40.1


-- 
linux-i3c mailing list
linux-i3c@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-i3c

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

* [PATCH 04/12] i3c: mipi-i3c-hci: Fix out of bounds access in hci_dma_irq_handler
  2023-09-21  5:56 [PATCH 00/12] i3c: mipi-i3c-hci: Enabling fixes Jarkko Nikula
                   ` (2 preceding siblings ...)
  2023-09-21  5:56 ` [PATCH 03/12] i3c: mipi-i3c-hci: Fix DAT/DCT entry sizes Jarkko Nikula
@ 2023-09-21  5:56 ` Jarkko Nikula
  2023-09-21  5:56 ` [PATCH 05/12] i3c: mipi-i3c-hci: Remove BUG() when Ring Abort request times out Jarkko Nikula
                   ` (8 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: Jarkko Nikula @ 2023-09-21  5:56 UTC (permalink / raw
  To: Alexandre Belloni; +Cc: linux-i3c, Jarkko Nikula

Do not loop over ring headers in hci_dma_irq_handler() that are not
allocated and enabled in hci_dma_init(). Otherwise out of bounds access
will occur from rings->headers[i] access when i >= number of allocated
ring headers.

Signed-off-by: Jarkko Nikula <jarkko.nikula@linux.intel.com>
---
 drivers/i3c/master/mipi-i3c-hci/dma.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/i3c/master/mipi-i3c-hci/dma.c b/drivers/i3c/master/mipi-i3c-hci/dma.c
index 2990ac9eaade..71b5dbe45c45 100644
--- a/drivers/i3c/master/mipi-i3c-hci/dma.c
+++ b/drivers/i3c/master/mipi-i3c-hci/dma.c
@@ -734,7 +734,7 @@ static bool hci_dma_irq_handler(struct i3c_hci *hci, unsigned int mask)
 	unsigned int i;
 	bool handled = false;
 
-	for (i = 0; mask && i < 8; i++) {
+	for (i = 0; mask && i < rings->total; i++) {
 		struct hci_rh_data *rh;
 		u32 status;
 
-- 
2.40.1


-- 
linux-i3c mailing list
linux-i3c@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-i3c

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

* [PATCH 05/12] i3c: mipi-i3c-hci: Remove BUG() when Ring Abort request times out
  2023-09-21  5:56 [PATCH 00/12] i3c: mipi-i3c-hci: Enabling fixes Jarkko Nikula
                   ` (3 preceding siblings ...)
  2023-09-21  5:56 ` [PATCH 04/12] i3c: mipi-i3c-hci: Fix out of bounds access in hci_dma_irq_handler Jarkko Nikula
@ 2023-09-21  5:56 ` Jarkko Nikula
  2023-09-21  5:56 ` [PATCH 06/12] i3c: mipi-i3c-hci: Set ring start request together with enable Jarkko Nikula
                   ` (7 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: Jarkko Nikula @ 2023-09-21  5:56 UTC (permalink / raw
  To: Alexandre Belloni; +Cc: linux-i3c, Jarkko Nikula

Ring Abort request will timeout in case there is an error in the Host
Controller interrupt delivery or Ring Header configuration. Using BUG()
makes hard to debug those cases.

Make it less severe and turn BUG() to WARN_ON().

Signed-off-by: Jarkko Nikula <jarkko.nikula@linux.intel.com>
---
 drivers/i3c/master/mipi-i3c-hci/dma.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/i3c/master/mipi-i3c-hci/dma.c b/drivers/i3c/master/mipi-i3c-hci/dma.c
index 71b5dbe45c45..a28ff177022c 100644
--- a/drivers/i3c/master/mipi-i3c-hci/dma.c
+++ b/drivers/i3c/master/mipi-i3c-hci/dma.c
@@ -450,10 +450,9 @@ static bool hci_dma_dequeue_xfer(struct i3c_hci *hci,
 		/*
 		 * We're deep in it if ever this condition is ever met.
 		 * Hardware might still be writing to memory, etc.
-		 * Better suspend the world than risking silent corruption.
 		 */
 		dev_crit(&hci->master.dev, "unable to abort the ring\n");
-		BUG();
+		WARN_ON(1);
 	}
 
 	for (i = 0; i < n; i++) {
-- 
2.40.1


-- 
linux-i3c mailing list
linux-i3c@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-i3c

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

* [PATCH 06/12] i3c: mipi-i3c-hci: Set ring start request together with enable
  2023-09-21  5:56 [PATCH 00/12] i3c: mipi-i3c-hci: Enabling fixes Jarkko Nikula
                   ` (4 preceding siblings ...)
  2023-09-21  5:56 ` [PATCH 05/12] i3c: mipi-i3c-hci: Remove BUG() when Ring Abort request times out Jarkko Nikula
@ 2023-09-21  5:56 ` Jarkko Nikula
  2023-09-21  5:56 ` [PATCH 07/12] i3c: mipi-i3c-hci: Fix race between bus cleanup and interrupt Jarkko Nikula
                   ` (6 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: Jarkko Nikula @ 2023-09-21  5:56 UTC (permalink / raw
  To: Alexandre Belloni; +Cc: linux-i3c, Jarkko Nikula

Set ring start request together with ring enable in hci_dma_init(). This
causes the ring abort request in hci_dma_dequeue_xfer() will raise the
INTR_RING_OP (RING_OP_STAT in MIPI I3C HCI specification) interrupt in
the RH_INTR_STATUS register.

Signed-off-by: Jarkko Nikula <jarkko.nikula@linux.intel.com>
---
 drivers/i3c/master/mipi-i3c-hci/dma.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/i3c/master/mipi-i3c-hci/dma.c b/drivers/i3c/master/mipi-i3c-hci/dma.c
index a28ff177022c..df569d1351be 100644
--- a/drivers/i3c/master/mipi-i3c-hci/dma.c
+++ b/drivers/i3c/master/mipi-i3c-hci/dma.c
@@ -325,7 +325,8 @@ static int hci_dma_init(struct i3c_hci *hci)
 		rh_reg_write(INTR_SIGNAL_ENABLE, regval);
 
 ring_ready:
-		rh_reg_write(RING_CONTROL, RING_CTRL_ENABLE);
+		rh_reg_write(RING_CONTROL, RING_CTRL_ENABLE |
+					   RING_CTRL_RUN_STOP);
 	}
 
 	regval = FIELD_PREP(MAX_HEADER_COUNT, rings->total);
-- 
2.40.1


-- 
linux-i3c mailing list
linux-i3c@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-i3c

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

* [PATCH 07/12] i3c: mipi-i3c-hci: Fix race between bus cleanup and interrupt
  2023-09-21  5:56 [PATCH 00/12] i3c: mipi-i3c-hci: Enabling fixes Jarkko Nikula
                   ` (5 preceding siblings ...)
  2023-09-21  5:56 ` [PATCH 06/12] i3c: mipi-i3c-hci: Set ring start request together with enable Jarkko Nikula
@ 2023-09-21  5:56 ` Jarkko Nikula
  2023-09-21  5:57 ` [PATCH 08/12] i3c: mipi-i3c-hci: Set number of SW enabled Ring Bundles earlier Jarkko Nikula
                   ` (5 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: Jarkko Nikula @ 2023-09-21  5:56 UTC (permalink / raw
  To: Alexandre Belloni; +Cc: linux-i3c, Jarkko Nikula

If there is a transfer error during i3c_master_bus_init() and code goes
doing the bus cleanup in i3c_hci_bus_cleanup() there is possibility that
i3c_hci_irq_handler() is running in parallel with hci->io->cleanup()
which can be racy.

Prevent this by waiting there is no pending interrupt on other CPU
before doing the IO cleanup.

This was observed with ring headers where first transfer failed and
sometimes transfer error or ring transfer abort interrupt was coming
simultaneously with the bus cleanup path.

Signed-off-by: Jarkko Nikula <jarkko.nikula@linux.intel.com>
---
 drivers/i3c/master/mipi-i3c-hci/core.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/i3c/master/mipi-i3c-hci/core.c b/drivers/i3c/master/mipi-i3c-hci/core.c
index 76a3e6bb3665..d7fe8e62820a 100644
--- a/drivers/i3c/master/mipi-i3c-hci/core.c
+++ b/drivers/i3c/master/mipi-i3c-hci/core.c
@@ -161,10 +161,12 @@ static int i3c_hci_bus_init(struct i3c_master_controller *m)
 static void i3c_hci_bus_cleanup(struct i3c_master_controller *m)
 {
 	struct i3c_hci *hci = to_i3c_hci(m);
+	struct platform_device *pdev = to_platform_device(m->dev.parent);
 
 	DBG("");
 
 	reg_clear(HC_CONTROL, HC_CONTROL_BUS_ENABLE);
+	synchronize_irq(platform_get_irq(pdev, 0));
 	hci->io->cleanup(hci);
 	if (hci->cmd == &mipi_i3c_hci_cmd_v1)
 		mipi_i3c_hci_dat_v1.cleanup(hci);
-- 
2.40.1


-- 
linux-i3c mailing list
linux-i3c@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-i3c

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

* [PATCH 08/12] i3c: mipi-i3c-hci: Set number of SW enabled Ring Bundles earlier
  2023-09-21  5:56 [PATCH 00/12] i3c: mipi-i3c-hci: Enabling fixes Jarkko Nikula
                   ` (6 preceding siblings ...)
  2023-09-21  5:56 ` [PATCH 07/12] i3c: mipi-i3c-hci: Fix race between bus cleanup and interrupt Jarkko Nikula
@ 2023-09-21  5:57 ` Jarkko Nikula
  2023-09-21  5:57 ` [PATCH 09/12] i3c: mipi-i3c-hci: Do not unmap region not mapped for transfer Jarkko Nikula
                   ` (4 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: Jarkko Nikula @ 2023-09-21  5:57 UTC (permalink / raw
  To: Alexandre Belloni; +Cc: linux-i3c, Jarkko Nikula

Number of software enabled Ring Bundles must be set before using them.
Otherwise Ring will not start and may be power-gated by the Host
Controller.

Signed-off-by: Jarkko Nikula <jarkko.nikula@linux.intel.com>
---
 drivers/i3c/master/mipi-i3c-hci/dma.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/i3c/master/mipi-i3c-hci/dma.c b/drivers/i3c/master/mipi-i3c-hci/dma.c
index df569d1351be..6c7eef17921a 100644
--- a/drivers/i3c/master/mipi-i3c-hci/dma.c
+++ b/drivers/i3c/master/mipi-i3c-hci/dma.c
@@ -229,6 +229,9 @@ static int hci_dma_init(struct i3c_hci *hci)
 	hci->io_data = rings;
 	rings->total = nr_rings;
 
+	regval = FIELD_PREP(MAX_HEADER_COUNT, rings->total);
+	rhs_reg_write(CONTROL, regval);
+
 	for (i = 0; i < rings->total; i++) {
 		u32 offset = rhs_reg_read(RHn_OFFSET(i));
 
@@ -329,8 +332,6 @@ static int hci_dma_init(struct i3c_hci *hci)
 					   RING_CTRL_RUN_STOP);
 	}
 
-	regval = FIELD_PREP(MAX_HEADER_COUNT, rings->total);
-	rhs_reg_write(CONTROL, regval);
 	return 0;
 
 err_out:
-- 
2.40.1


-- 
linux-i3c mailing list
linux-i3c@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-i3c

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

* [PATCH 09/12] i3c: mipi-i3c-hci: Do not unmap region not mapped for transfer
  2023-09-21  5:56 [PATCH 00/12] i3c: mipi-i3c-hci: Enabling fixes Jarkko Nikula
                   ` (7 preceding siblings ...)
  2023-09-21  5:57 ` [PATCH 08/12] i3c: mipi-i3c-hci: Set number of SW enabled Ring Bundles earlier Jarkko Nikula
@ 2023-09-21  5:57 ` Jarkko Nikula
  2023-09-21  5:57 ` [PATCH 10/12] i3c: mipi-i3c-hci: Fix missing xfer->completion in hci_cmd_v1_daa() Jarkko Nikula
                   ` (3 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: Jarkko Nikula @ 2023-09-21  5:57 UTC (permalink / raw
  To: Alexandre Belloni; +Cc: linux-i3c, Jarkko Nikula

Fix following warning (with CONFIG_DMA_API_DEBUG) which happens with a
transfer without a data buffer.

	DMA-API: i3c mipi-i3c-hci.0: device driver tries to free DMA memory it has not allocated [device address=0x0000000000000000] [size=0 bytes]

For those transfers the hci_dma_queue_xfer() doesn't create a mapping and
the DMA address pointer xfer->data_dma is not set.

Signed-off-by: Jarkko Nikula <jarkko.nikula@linux.intel.com>
---
 drivers/i3c/master/mipi-i3c-hci/dma.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/i3c/master/mipi-i3c-hci/dma.c b/drivers/i3c/master/mipi-i3c-hci/dma.c
index 6c7eef17921a..00d20a020ffb 100644
--- a/drivers/i3c/master/mipi-i3c-hci/dma.c
+++ b/drivers/i3c/master/mipi-i3c-hci/dma.c
@@ -347,6 +347,8 @@ static void hci_dma_unmap_xfer(struct i3c_hci *hci,
 
 	for (i = 0; i < n; i++) {
 		xfer = xfer_list + i;
+		if (!xfer->data)
+			continue;
 		dma_unmap_single(&hci->master.dev,
 				 xfer->data_dma, xfer->data_len,
 				 xfer->rnw ? DMA_FROM_DEVICE : DMA_TO_DEVICE);
-- 
2.40.1


-- 
linux-i3c mailing list
linux-i3c@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-i3c

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

* [PATCH 10/12] i3c: mipi-i3c-hci: Fix missing xfer->completion in hci_cmd_v1_daa()
  2023-09-21  5:56 [PATCH 00/12] i3c: mipi-i3c-hci: Enabling fixes Jarkko Nikula
                   ` (8 preceding siblings ...)
  2023-09-21  5:57 ` [PATCH 09/12] i3c: mipi-i3c-hci: Do not unmap region not mapped for transfer Jarkko Nikula
@ 2023-09-21  5:57 ` Jarkko Nikula
  2023-09-21  5:57 ` [PATCH 11/12] i3c: mipi-i3c-hci: Resume controller explicitly Jarkko Nikula
                   ` (2 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: Jarkko Nikula @ 2023-09-21  5:57 UTC (permalink / raw
  To: Alexandre Belloni; +Cc: linux-i3c, Jarkko Nikula

Due to missing completion object for the ENTDAA command transfer in the
hci_cmd_v1_daa() the wait_for_completion_timeout() will obviously
timeout even the transfer itself may succeed.

Fix this by setting the xfer->completion to the already initialized
completion object.

Signed-off-by: Jarkko Nikula <jarkko.nikula@linux.intel.com>
---
 drivers/i3c/master/mipi-i3c-hci/cmd_v1.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/i3c/master/mipi-i3c-hci/cmd_v1.c b/drivers/i3c/master/mipi-i3c-hci/cmd_v1.c
index 6a781f89b0e4..2b2323aa6714 100644
--- a/drivers/i3c/master/mipi-i3c-hci/cmd_v1.c
+++ b/drivers/i3c/master/mipi-i3c-hci/cmd_v1.c
@@ -332,6 +332,7 @@ static int hci_cmd_v1_daa(struct i3c_hci *hci)
 			CMD_A0_DEV_COUNT(1) |
 			CMD_A0_ROC | CMD_A0_TOC;
 		xfer->cmd_desc[1] = 0;
+		xfer->completion = &done;
 		hci->io->queue_xfer(hci, xfer, 1);
 		if (!wait_for_completion_timeout(&done, HZ) &&
 		    hci->io->dequeue_xfer(hci, xfer, 1)) {
-- 
2.40.1


-- 
linux-i3c mailing list
linux-i3c@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-i3c

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

* [PATCH 11/12] i3c: mipi-i3c-hci: Resume controller explicitly
  2023-09-21  5:56 [PATCH 00/12] i3c: mipi-i3c-hci: Enabling fixes Jarkko Nikula
                   ` (9 preceding siblings ...)
  2023-09-21  5:57 ` [PATCH 10/12] i3c: mipi-i3c-hci: Fix missing xfer->completion in hci_cmd_v1_daa() Jarkko Nikula
@ 2023-09-21  5:57 ` Jarkko Nikula
  2023-09-21  5:57 ` [PATCH 12/12] i3c: mipi-i3c-hci: Resume controller after aborted transfer Jarkko Nikula
  2023-09-25 21:36 ` [PATCH 00/12] i3c: mipi-i3c-hci: Enabling fixes Alexandre Belloni
  12 siblings, 0 replies; 14+ messages in thread
From: Jarkko Nikula @ 2023-09-21  5:57 UTC (permalink / raw
  To: Alexandre Belloni; +Cc: linux-i3c, Jarkko Nikula

On an HW I'm using in enabling work the RESUME bit is not set in the
HC_CONTROLLER register when Host Controller goes to halt state. Value 1
should mean controller is suspended when reading and writing 1 resumes it.

Because of this erratic behaviour plain HC_CONTROL read and write back
won't resume the controller. Therefore do it by setting the RESUME bit
explicitly.

Signed-off-by: Jarkko Nikula <jarkko.nikula@linux.intel.com>
---
 drivers/i3c/master/mipi-i3c-hci/core.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/i3c/master/mipi-i3c-hci/core.c b/drivers/i3c/master/mipi-i3c-hci/core.c
index d7fe8e62820a..1ae56a5699c6 100644
--- a/drivers/i3c/master/mipi-i3c-hci/core.c
+++ b/drivers/i3c/master/mipi-i3c-hci/core.c
@@ -174,8 +174,7 @@ static void i3c_hci_bus_cleanup(struct i3c_master_controller *m)
 
 void mipi_i3c_hci_resume(struct i3c_hci *hci)
 {
-	/* the HC_CONTROL_RESUME bit is R/W1C so just read and write back */
-	reg_write(HC_CONTROL, reg_read(HC_CONTROL));
+	reg_set(HC_CONTROL, HC_CONTROL_RESUME);
 }
 
 /* located here rather than pio.c because needed bits are in core reg space */
-- 
2.40.1


-- 
linux-i3c mailing list
linux-i3c@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-i3c

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

* [PATCH 12/12] i3c: mipi-i3c-hci: Resume controller after aborted transfer
  2023-09-21  5:56 [PATCH 00/12] i3c: mipi-i3c-hci: Enabling fixes Jarkko Nikula
                   ` (10 preceding siblings ...)
  2023-09-21  5:57 ` [PATCH 11/12] i3c: mipi-i3c-hci: Resume controller explicitly Jarkko Nikula
@ 2023-09-21  5:57 ` Jarkko Nikula
  2023-09-25 21:36 ` [PATCH 00/12] i3c: mipi-i3c-hci: Enabling fixes Alexandre Belloni
  12 siblings, 0 replies; 14+ messages in thread
From: Jarkko Nikula @ 2023-09-21  5:57 UTC (permalink / raw
  To: Alexandre Belloni; +Cc: linux-i3c, Jarkko Nikula

Host Controller goes to halt state after aborted transfer and needs to
be resumed by SW. Add this resuming to DMA mode code too.

Signed-off-by: Jarkko Nikula <jarkko.nikula@linux.intel.com>
---
 drivers/i3c/master/mipi-i3c-hci/dma.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/i3c/master/mipi-i3c-hci/dma.c b/drivers/i3c/master/mipi-i3c-hci/dma.c
index 00d20a020ffb..bee47aac6894 100644
--- a/drivers/i3c/master/mipi-i3c-hci/dma.c
+++ b/drivers/i3c/master/mipi-i3c-hci/dma.c
@@ -759,9 +759,11 @@ static bool hci_dma_irq_handler(struct i3c_hci *hci, unsigned int mask)
 		if (status & INTR_RING_OP)
 			complete(&rh->op_done);
 
-		if (status & INTR_TRANSFER_ABORT)
+		if (status & INTR_TRANSFER_ABORT) {
 			dev_notice_ratelimited(&hci->master.dev,
 				"ring %d: Transfer Aborted\n", i);
+			mipi_i3c_hci_resume(hci);
+		}
 		if (status & INTR_WARN_INS_STOP_MODE)
 			dev_warn_ratelimited(&hci->master.dev,
 				"ring %d: Inserted Stop on Mode Change\n", i);
-- 
2.40.1


-- 
linux-i3c mailing list
linux-i3c@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-i3c

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

* Re: [PATCH 00/12] i3c: mipi-i3c-hci: Enabling fixes
  2023-09-21  5:56 [PATCH 00/12] i3c: mipi-i3c-hci: Enabling fixes Jarkko Nikula
                   ` (11 preceding siblings ...)
  2023-09-21  5:57 ` [PATCH 12/12] i3c: mipi-i3c-hci: Resume controller after aborted transfer Jarkko Nikula
@ 2023-09-25 21:36 ` Alexandre Belloni
  12 siblings, 0 replies; 14+ messages in thread
From: Alexandre Belloni @ 2023-09-25 21:36 UTC (permalink / raw
  To: Jarkko Nikula; +Cc: linux-i3c


On Thu, 21 Sep 2023 08:56:52 +0300, Jarkko Nikula wrote:
> I've been hacking with an early MIPI I3C HCI version compatible
> controller on our development HW. Basically a glue code registering the
> "mipi-i3c-hci" platform device with some additional code for logic on top
> of MIPI I3C HCI.
> 
> This early MIPI I3C HCI version won't be productized and the glue code
> won't be released in near future but I believe these patches might
> benefit others who may be also enabling the MIPI I3C HCI on their HW.
> 
> [...]

Applied, thanks!

[01/12] i3c: master: Inherit DMA masks and parameters from parent device
        commit: 0c35691551387e060e6ae7a6652b4101270c73cf
[02/12] i3c: mipi-i3c-hci: Add MODULE_ALIAS
        commit: f656f6bd22d7cd08b55c6495fcfaa391c2eb933f
[03/12] i3c: mipi-i3c-hci: Fix DAT/DCT entry sizes
        commit: 0676bfebf5766f0a60549f74ba597115028fa39c
[04/12] i3c: mipi-i3c-hci: Fix out of bounds access in hci_dma_irq_handler
        commit: 45a832f989e520095429589d5b01b0c65da9b574
[05/12] i3c: mipi-i3c-hci: Remove BUG() when Ring Abort request times out
        commit: 361acacaf7c706223968c8186f0d3b6e214e7403
[06/12] i3c: mipi-i3c-hci: Set ring start request together with enable
        commit: e141db842766b1d9af32030a842ceb5eaf389bbb
[07/12] i3c: mipi-i3c-hci: Fix race between bus cleanup and interrupt
        commit: 4e40642cdb621c669507d7ef098c93ff98e8747c
[08/12] i3c: mipi-i3c-hci: Set number of SW enabled Ring Bundles earlier
        commit: 7ccd40edc1f5c43e3f1c7d209336d3981943ab63
[09/12] i3c: mipi-i3c-hci: Do not unmap region not mapped for transfer
        commit: b8806e0c939f168237593af0056c309bf31022b0
[10/12] i3c: mipi-i3c-hci: Fix missing xfer->completion in hci_cmd_v1_daa()
        commit: 4c36f656b7d1fc00643730c5845c19b3e15be856
[11/12] i3c: mipi-i3c-hci: Resume controller explicitly
        commit: 3521fa63c1ee7414e6ba0fdf98b82b07939147d9
[12/12] i3c: mipi-i3c-hci: Resume controller after aborted transfer
        commit: fc9176e794d74baccb1e4ef41894ac141f524992

Best regards,

-- 
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

-- 
linux-i3c mailing list
linux-i3c@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-i3c

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

end of thread, other threads:[~2023-09-25 21:36 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-21  5:56 [PATCH 00/12] i3c: mipi-i3c-hci: Enabling fixes Jarkko Nikula
2023-09-21  5:56 ` [PATCH 01/12] i3c: master: Inherit DMA masks and parameters from parent device Jarkko Nikula
2023-09-21  5:56 ` [PATCH 02/12] i3c: mipi-i3c-hci: Add MODULE_ALIAS Jarkko Nikula
2023-09-21  5:56 ` [PATCH 03/12] i3c: mipi-i3c-hci: Fix DAT/DCT entry sizes Jarkko Nikula
2023-09-21  5:56 ` [PATCH 04/12] i3c: mipi-i3c-hci: Fix out of bounds access in hci_dma_irq_handler Jarkko Nikula
2023-09-21  5:56 ` [PATCH 05/12] i3c: mipi-i3c-hci: Remove BUG() when Ring Abort request times out Jarkko Nikula
2023-09-21  5:56 ` [PATCH 06/12] i3c: mipi-i3c-hci: Set ring start request together with enable Jarkko Nikula
2023-09-21  5:56 ` [PATCH 07/12] i3c: mipi-i3c-hci: Fix race between bus cleanup and interrupt Jarkko Nikula
2023-09-21  5:57 ` [PATCH 08/12] i3c: mipi-i3c-hci: Set number of SW enabled Ring Bundles earlier Jarkko Nikula
2023-09-21  5:57 ` [PATCH 09/12] i3c: mipi-i3c-hci: Do not unmap region not mapped for transfer Jarkko Nikula
2023-09-21  5:57 ` [PATCH 10/12] i3c: mipi-i3c-hci: Fix missing xfer->completion in hci_cmd_v1_daa() Jarkko Nikula
2023-09-21  5:57 ` [PATCH 11/12] i3c: mipi-i3c-hci: Resume controller explicitly Jarkko Nikula
2023-09-21  5:57 ` [PATCH 12/12] i3c: mipi-i3c-hci: Resume controller after aborted transfer Jarkko Nikula
2023-09-25 21:36 ` [PATCH 00/12] i3c: mipi-i3c-hci: Enabling fixes Alexandre Belloni

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