public inbox for linux-i3c@lists.infradead.org
 help / color / mirror / Atom feed
* [PATCH 1/4] i3c: mipi-i3c-hci: Switch to lower_32_bits()/upper_32_bits() helpers
@ 2024-06-28 13:15 Jarkko Nikula
  2024-06-28 13:15 ` [PATCH 2/4] i3c: mipi-i3c-hci: Set IBI Status and Data Ring base addresses Jarkko Nikula
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Jarkko Nikula @ 2024-06-28 13:15 UTC (permalink / raw)
  To: linux-i3c; +Cc: Alexandre Belloni, Jarkko Nikula

Rather than having own lo32()/hi32() helpers for dealing with 32-bit and
64-bit build targets switch to generic lower_32_bits()/upper_32_bits()
helpers.

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

diff --git a/drivers/i3c/master/mipi-i3c-hci/dma.c b/drivers/i3c/master/mipi-i3c-hci/dma.c
index 4e01a95cc4d0..6c5964e727b3 100644
--- a/drivers/i3c/master/mipi-i3c-hci/dma.c
+++ b/drivers/i3c/master/mipi-i3c-hci/dma.c
@@ -147,21 +147,6 @@ struct hci_dma_dev_ibi_data {
 	unsigned int max_len;
 };
 
-static inline u32 lo32(dma_addr_t physaddr)
-{
-	return physaddr;
-}
-
-static inline u32 hi32(dma_addr_t physaddr)
-{
-	/* trickery to avoid compiler warnings on 32-bit build targets */
-	if (sizeof(dma_addr_t) > 4) {
-		u64 hi = physaddr;
-		return hi >> 32;
-	}
-	return 0;
-}
-
 static void hci_dma_cleanup(struct i3c_hci *hci)
 {
 	struct hci_rings_data *rings = hci->io_data;
@@ -265,10 +250,10 @@ static int hci_dma_init(struct i3c_hci *hci)
 		if (!rh->xfer || !rh->resp || !rh->src_xfers)
 			goto err_out;
 
-		rh_reg_write(CMD_RING_BASE_LO, lo32(rh->xfer_dma));
-		rh_reg_write(CMD_RING_BASE_HI, hi32(rh->xfer_dma));
-		rh_reg_write(RESP_RING_BASE_LO, lo32(rh->resp_dma));
-		rh_reg_write(RESP_RING_BASE_HI, hi32(rh->resp_dma));
+		rh_reg_write(CMD_RING_BASE_LO, lower_32_bits(rh->xfer_dma));
+		rh_reg_write(CMD_RING_BASE_HI, upper_32_bits(rh->xfer_dma));
+		rh_reg_write(RESP_RING_BASE_LO, lower_32_bits(rh->resp_dma));
+		rh_reg_write(RESP_RING_BASE_HI, upper_32_bits(rh->resp_dma));
 
 		regval = FIELD_PREP(CR_RING_SIZE, rh->xfer_entries);
 		rh_reg_write(CR_SETUP, regval);
@@ -404,8 +389,8 @@ static int hci_dma_queue_xfer(struct i3c_hci *hci,
 				hci_dma_unmap_xfer(hci, xfer_list, i);
 				return -ENOMEM;
 			}
-			*ring_data++ = lo32(xfer->data_dma);
-			*ring_data++ = hi32(xfer->data_dma);
+			*ring_data++ = lower_32_bits(xfer->data_dma);
+			*ring_data++ = upper_32_bits(xfer->data_dma);
 		} else {
 			*ring_data++ = 0;
 			*ring_data++ = 0;
-- 
2.43.0


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

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

* [PATCH 2/4] i3c: mipi-i3c-hci: Set IBI Status and Data Ring base addresses
  2024-06-28 13:15 [PATCH 1/4] i3c: mipi-i3c-hci: Switch to lower_32_bits()/upper_32_bits() helpers Jarkko Nikula
@ 2024-06-28 13:15 ` Jarkko Nikula
  2024-06-28 13:15 ` [PATCH 3/4] i3c: mipi-i3c-hci: Error out instead on BUG_ON() in IBI DMA setup Jarkko Nikula
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Jarkko Nikula @ 2024-06-28 13:15 UTC (permalink / raw)
  To: linux-i3c; +Cc: Alexandre Belloni, Jarkko Nikula

IBI Status and Data Ring base address registers are not set so HW
obviously cannot update those rings after In-Band Interrupt.

Set them to already allocated and mapped ring addresses.

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

diff --git a/drivers/i3c/master/mipi-i3c-hci/dma.c b/drivers/i3c/master/mipi-i3c-hci/dma.c
index 6c5964e727b3..7a56ae4a5ddf 100644
--- a/drivers/i3c/master/mipi-i3c-hci/dma.c
+++ b/drivers/i3c/master/mipi-i3c-hci/dma.c
@@ -300,6 +300,11 @@ static int hci_dma_init(struct i3c_hci *hci)
 			goto err_out;
 		}
 
+		rh_reg_write(IBI_STATUS_RING_BASE_LO, lower_32_bits(rh->ibi_status_dma));
+		rh_reg_write(IBI_STATUS_RING_BASE_HI, upper_32_bits(rh->ibi_status_dma));
+		rh_reg_write(IBI_DATA_RING_BASE_LO, lower_32_bits(rh->ibi_data_dma));
+		rh_reg_write(IBI_DATA_RING_BASE_HI, upper_32_bits(rh->ibi_data_dma));
+
 		regval = FIELD_PREP(IBI_STATUS_RING_SIZE,
 				    rh->ibi_status_entries) |
 			 FIELD_PREP(IBI_DATA_CHUNK_SIZE,
-- 
2.43.0


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

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

* [PATCH 3/4] i3c: mipi-i3c-hci: Error out instead on BUG_ON() in IBI DMA setup
  2024-06-28 13:15 [PATCH 1/4] i3c: mipi-i3c-hci: Switch to lower_32_bits()/upper_32_bits() helpers Jarkko Nikula
  2024-06-28 13:15 ` [PATCH 2/4] i3c: mipi-i3c-hci: Set IBI Status and Data Ring base addresses Jarkko Nikula
@ 2024-06-28 13:15 ` Jarkko Nikula
  2024-06-28 13:15 ` [PATCH 4/4] i3c: mipi-i3c-hci: Round IBI data chunk size to HW supported value Jarkko Nikula
  2024-06-28 14:42 ` [PATCH 1/4] i3c: mipi-i3c-hci: Switch to lower_32_bits()/upper_32_bits() helpers Alexandre Belloni
  3 siblings, 0 replies; 5+ messages in thread
From: Jarkko Nikula @ 2024-06-28 13:15 UTC (permalink / raw)
  To: linux-i3c; +Cc: Alexandre Belloni, Jarkko Nikula

Definitely condition dma_get_cache_alignment * defined value > 256
during driver initialization is not reason to BUG_ON(). Turn that to
graceful error out with -EINVAL.

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

diff --git a/drivers/i3c/master/mipi-i3c-hci/dma.c b/drivers/i3c/master/mipi-i3c-hci/dma.c
index 7a56ae4a5ddf..9bdfe40bc1e1 100644
--- a/drivers/i3c/master/mipi-i3c-hci/dma.c
+++ b/drivers/i3c/master/mipi-i3c-hci/dma.c
@@ -279,7 +279,10 @@ static int hci_dma_init(struct i3c_hci *hci)
 
 		rh->ibi_chunk_sz = dma_get_cache_alignment();
 		rh->ibi_chunk_sz *= IBI_CHUNK_CACHELINES;
-		BUG_ON(rh->ibi_chunk_sz > 256);
+		if (rh->ibi_chunk_sz > 256) {
+			ret = -EINVAL;
+			goto err_out;
+		}
 
 		ibi_status_ring_sz = rh->ibi_status_sz * rh->ibi_status_entries;
 		ibi_data_ring_sz = rh->ibi_chunk_sz * rh->ibi_chunks_total;
-- 
2.43.0


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

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

* [PATCH 4/4] i3c: mipi-i3c-hci: Round IBI data chunk size to HW supported value
  2024-06-28 13:15 [PATCH 1/4] i3c: mipi-i3c-hci: Switch to lower_32_bits()/upper_32_bits() helpers Jarkko Nikula
  2024-06-28 13:15 ` [PATCH 2/4] i3c: mipi-i3c-hci: Set IBI Status and Data Ring base addresses Jarkko Nikula
  2024-06-28 13:15 ` [PATCH 3/4] i3c: mipi-i3c-hci: Error out instead on BUG_ON() in IBI DMA setup Jarkko Nikula
@ 2024-06-28 13:15 ` Jarkko Nikula
  2024-06-28 14:42 ` [PATCH 1/4] i3c: mipi-i3c-hci: Switch to lower_32_bits()/upper_32_bits() helpers Alexandre Belloni
  3 siblings, 0 replies; 5+ messages in thread
From: Jarkko Nikula @ 2024-06-28 13:15 UTC (permalink / raw)
  To: linux-i3c; +Cc: Alexandre Belloni, Jarkko Nikula

The dma.c: hci_dma_init() sets the CHUNK_SIZE field in the IBI_SETUP
register incorrectly if the calculated ibi_chunk_sz is not exactly
2^(n+2) bytes, where n is 0..6.

Fix this by rounding the chunk size up to nearest 2^(n+2) bytes.

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

diff --git a/drivers/i3c/master/mipi-i3c-hci/dma.c b/drivers/i3c/master/mipi-i3c-hci/dma.c
index 9bdfe40bc1e1..a918e96b21fd 100644
--- a/drivers/i3c/master/mipi-i3c-hci/dma.c
+++ b/drivers/i3c/master/mipi-i3c-hci/dma.c
@@ -279,6 +279,13 @@ static int hci_dma_init(struct i3c_hci *hci)
 
 		rh->ibi_chunk_sz = dma_get_cache_alignment();
 		rh->ibi_chunk_sz *= IBI_CHUNK_CACHELINES;
+		/*
+		 * Round IBI data chunk size to number of bytes supported by
+		 * the HW. Chunk size can be 2^n number of DWORDs which is the
+		 * same as 2^(n+2) bytes, where n is 0..6.
+		 */
+		rh->ibi_chunk_sz = umax(4, rh->ibi_chunk_sz);
+		rh->ibi_chunk_sz = roundup_pow_of_two(rh->ibi_chunk_sz);
 		if (rh->ibi_chunk_sz > 256) {
 			ret = -EINVAL;
 			goto err_out;
-- 
2.43.0


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

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

* Re: [PATCH 1/4] i3c: mipi-i3c-hci: Switch to lower_32_bits()/upper_32_bits() helpers
  2024-06-28 13:15 [PATCH 1/4] i3c: mipi-i3c-hci: Switch to lower_32_bits()/upper_32_bits() helpers Jarkko Nikula
                   ` (2 preceding siblings ...)
  2024-06-28 13:15 ` [PATCH 4/4] i3c: mipi-i3c-hci: Round IBI data chunk size to HW supported value Jarkko Nikula
@ 2024-06-28 14:42 ` Alexandre Belloni
  3 siblings, 0 replies; 5+ messages in thread
From: Alexandre Belloni @ 2024-06-28 14:42 UTC (permalink / raw)
  To: linux-i3c, Jarkko Nikula

On Fri, 28 Jun 2024 16:15:56 +0300, Jarkko Nikula wrote:
> Rather than having own lo32()/hi32() helpers for dealing with 32-bit and
> 64-bit build targets switch to generic lower_32_bits()/upper_32_bits()
> helpers.
> 
> 

Applied, thanks!

[1/4] i3c: mipi-i3c-hci: Switch to lower_32_bits()/upper_32_bits() helpers
      https://git.kernel.org/abelloni/c/8b4813a33a4b
[2/4] i3c: mipi-i3c-hci: Set IBI Status and Data Ring base addresses
      https://git.kernel.org/abelloni/c/a95d8fa46962
[3/4] i3c: mipi-i3c-hci: Error out instead on BUG_ON() in IBI DMA setup
      https://git.kernel.org/abelloni/c/3b85c83cce0b
[4/4] i3c: mipi-i3c-hci: Round IBI data chunk size to HW supported value
      https://git.kernel.org/abelloni/c/67678602c4fc

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] 5+ messages in thread

end of thread, other threads:[~2024-06-28 14:42 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-28 13:15 [PATCH 1/4] i3c: mipi-i3c-hci: Switch to lower_32_bits()/upper_32_bits() helpers Jarkko Nikula
2024-06-28 13:15 ` [PATCH 2/4] i3c: mipi-i3c-hci: Set IBI Status and Data Ring base addresses Jarkko Nikula
2024-06-28 13:15 ` [PATCH 3/4] i3c: mipi-i3c-hci: Error out instead on BUG_ON() in IBI DMA setup Jarkko Nikula
2024-06-28 13:15 ` [PATCH 4/4] i3c: mipi-i3c-hci: Round IBI data chunk size to HW supported value Jarkko Nikula
2024-06-28 14:42 ` [PATCH 1/4] i3c: mipi-i3c-hci: Switch to lower_32_bits()/upper_32_bits() helpers Alexandre Belloni

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox