mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/2] dmaengine: at_hdmac: Regression fix and cleanup
@ 2023-05-23 12:42 Peter Rosin
  2023-05-23 12:42 ` [PATCH 1/2] dmaengine: at_hdmac: Repair bitfield macros for peripheral ID handling Peter Rosin
  2023-05-23 12:42 ` [PATCH 2/2] dmaengine: at_hdmac: Remove unused field values that do not fit Peter Rosin
  0 siblings, 2 replies; 5+ messages in thread
From: Peter Rosin @ 2023-05-23 12:42 UTC (permalink / raw)
  To: LKML
  Cc: Ludovic Desroches, Tudor Ambarus, Vinod Koul, Nicolas Ferre,
	linux-arm-kernel, dmaengine

Hi!

I found a regression in DMA handling on one of our SAMA5D3 boards.

While combing through the regressing commit, a found two unrelated
strange things. The first is the actually problematic change. The
second is a number of suspect defines, that I fail to see how they
can ever do any good.

Cheers,
Peter

Peter Rosin (2):
  dmaengine: at_hdmac: Repair bitfield macros for peripheral ID handling
  dmaengine: at_hdmac: Remove unused field values that do not fit

 drivers/dma/at_hdmac.c | 39 ++++++++++++++++++++++++++++-----------
 1 file changed, 28 insertions(+), 11 deletions(-)

-- 
2.20.1


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

* [PATCH 1/2] dmaengine: at_hdmac: Repair bitfield macros for peripheral ID handling
  2023-05-23 12:42 [PATCH 0/2] dmaengine: at_hdmac: Regression fix and cleanup Peter Rosin
@ 2023-05-23 12:42 ` Peter Rosin
  2023-05-23 15:15   ` Tudor Ambarus
  2023-05-23 12:42 ` [PATCH 2/2] dmaengine: at_hdmac: Remove unused field values that do not fit Peter Rosin
  1 sibling, 1 reply; 5+ messages in thread
From: Peter Rosin @ 2023-05-23 12:42 UTC (permalink / raw)
  To: LKML
  Cc: Ludovic Desroches, Tudor Ambarus, Vinod Koul, Nicolas Ferre,
	linux-arm-kernel, dmaengine

The MSB part of the peripheral IDs need to go into the ATC_SRC_PER_MSB
and ATC_DST_PER_MSB fields. Not the LSB part.

This fixes a severe regression for TSE-850 devices (compatible
axentia,tse850v3) where output to the audio I2S codec (the main
purpose of the device) simply do not work.

While at it, rewrite the macros as inline functions to evade checkpatch
warnings about argument reuse.

Fixes: d8840a7edcf0 ("dmaengine: at_hdmac: Use bitfield access macros")
Signed-off-by: Peter Rosin <peda@axentia.se>
---
 drivers/dma/at_hdmac.c | 35 ++++++++++++++++++++++++++++-------
 1 file changed, 28 insertions(+), 7 deletions(-)

diff --git a/drivers/dma/at_hdmac.c b/drivers/dma/at_hdmac.c
index 8858470246e1..6f352160bc3b 100644
--- a/drivers/dma/at_hdmac.c
+++ b/drivers/dma/at_hdmac.c
@@ -153,8 +153,6 @@
 #define ATC_AUTO		BIT(31)		/* Auto multiple buffer tx enable */
 
 /* Bitfields in CFG */
-#define ATC_PER_MSB(h)	((0x30U & (h)) >> 4)	/* Extract most significant bits of a handshaking identifier */
-
 #define ATC_SRC_PER		GENMASK(3, 0)	/* Channel src rq associated with periph handshaking ifc h */
 #define ATC_DST_PER		GENMASK(7, 4)	/* Channel dst rq associated with periph handshaking ifc h */
 #define ATC_SRC_REP		BIT(8)		/* Source Replay Mod */
@@ -181,10 +179,7 @@
 #define ATC_DPIP_HOLE		GENMASK(15, 0)
 #define ATC_DPIP_BOUNDARY	GENMASK(25, 16)
 
-#define ATC_SRC_PER_ID(id)	(FIELD_PREP(ATC_SRC_PER_MSB, (id)) |	\
-				 FIELD_PREP(ATC_SRC_PER, (id)))
-#define ATC_DST_PER_ID(id)	(FIELD_PREP(ATC_DST_PER_MSB, (id)) |	\
-				 FIELD_PREP(ATC_DST_PER, (id)))
+#define ATC_PER_MSB		GENMASK(5, 4)	/* Extract MSBs of a handshaking identifier */
 
 
 
@@ -1780,6 +1775,32 @@ static bool at_dma_filter(struct dma_chan *chan, void *slave)
 	}
 }
 
+/**
+ * atc_src_per_id - prepare the source peripheral fields of the CFG
+ * register for the given peripheral handshaking id.
+ *
+ * @per_id: the peripheral id
+ */
+static inline u32 atc_src_per_id(unsigned int per_id)
+{
+	return FIELD_PREP(ATC_SRC_PER_MSB,
+			  FIELD_GET(ATC_PER_MSB, per_id)) |
+		FIELD_PREP(ATC_SRC_PER, per_id);
+}
+
+/**
+ * atc_dst_per_id - prepare the destination peripheral fields of the CFG
+ * register for the given peripheral handshaking id.
+ *
+ * @per_id: the peripheral id
+ */
+static inline u32 atc_dst_per_id(unsigned int per_id)
+{
+	return FIELD_PREP(ATC_DST_PER_MSB,
+			  FIELD_GET(ATC_PER_MSB, per_id)) |
+		FIELD_PREP(ATC_DST_PER, per_id);
+}
+
 static struct dma_chan *at_dma_xlate(struct of_phandle_args *dma_spec,
 				     struct of_dma *of_dma)
 {
@@ -1812,7 +1833,7 @@ static struct dma_chan *at_dma_xlate(struct of_phandle_args *dma_spec,
 	 * ignored depending on DMA transfer direction.
 	 */
 	per_id = dma_spec->args[1] & AT91_DMA_CFG_PER_ID_MASK;
-	atslave->cfg |= ATC_DST_PER_ID(per_id) |  ATC_SRC_PER_ID(per_id);
+	atslave->cfg |= atc_dst_per_id(per_id) | atc_src_per_id(per_id);
 	/*
 	 * We have to translate the value we get from the device tree since
 	 * the half FIFO configuration value had to be 0 to keep backward
-- 
2.20.1


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

* [PATCH 2/2] dmaengine: at_hdmac: Remove unused field values that do not fit
  2023-05-23 12:42 [PATCH 0/2] dmaengine: at_hdmac: Regression fix and cleanup Peter Rosin
  2023-05-23 12:42 ` [PATCH 1/2] dmaengine: at_hdmac: Repair bitfield macros for peripheral ID handling Peter Rosin
@ 2023-05-23 12:42 ` Peter Rosin
  2023-05-23 14:04   ` Tudor Ambarus
  1 sibling, 1 reply; 5+ messages in thread
From: Peter Rosin @ 2023-05-23 12:42 UTC (permalink / raw)
  To: LKML
  Cc: Ludovic Desroches, Tudor Ambarus, Vinod Koul, Nicolas Ferre,
	linux-arm-kernel, dmaengine

The values are not used, and they do not fit in the intended
register field (ATC_FC, 2 bits wide). Kill 'em all.

Signed-off-by: Peter Rosin <peda@axentia.se>
---
 drivers/dma/at_hdmac.c | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/drivers/dma/at_hdmac.c b/drivers/dma/at_hdmac.c
index 6f352160bc3b..51d0a0c7aaf7 100644
--- a/drivers/dma/at_hdmac.c
+++ b/drivers/dma/at_hdmac.c
@@ -137,10 +137,6 @@
 #define ATC_FC_MEM2PER		0x1		/* Mem-to-Periph (DMA) */
 #define ATC_FC_PER2MEM		0x2		/* Periph-to-Mem (DMA) */
 #define ATC_FC_PER2PER		0x3		/* Periph-to-Periph (DMA) */
-#define ATC_FC_PER2MEM_PER	0x4		/* Periph-to-Mem (Peripheral) */
-#define ATC_FC_MEM2PER_PER	0x5		/* Mem-to-Periph (Peripheral) */
-#define ATC_FC_PER2PER_SRCPER	0x6		/* Periph-to-Periph (Src Peripheral) */
-#define ATC_FC_PER2PER_DSTPER	0x7		/* Periph-to-Periph (Dst Peripheral) */
 #define ATC_SRC_ADDR_MODE	GENMASK(25, 24)
 #define ATC_SRC_ADDR_MODE_INCR	0x0		/* Incrementing Mode */
 #define ATC_SRC_ADDR_MODE_DECR	0x1		/* Decrementing Mode */
-- 
2.20.1


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

* Re: [PATCH 2/2] dmaengine: at_hdmac: Remove unused field values that do not fit
  2023-05-23 12:42 ` [PATCH 2/2] dmaengine: at_hdmac: Remove unused field values that do not fit Peter Rosin
@ 2023-05-23 14:04   ` Tudor Ambarus
  0 siblings, 0 replies; 5+ messages in thread
From: Tudor Ambarus @ 2023-05-23 14:04 UTC (permalink / raw)
  To: Peter Rosin, LKML
  Cc: Ludovic Desroches, Vinod Koul, Nicolas Ferre, linux-arm-kernel,
	dmaengine

Hi, Peter,

On 5/23/23 13:42, Peter Rosin wrote:
> The values are not used, and they do not fit in the intended
> register field (ATC_FC, 2 bits wide). Kill 'em all.
> 
Actually ATC_FC should be set to GENMASK(23, 21) and keep the other
definitions, see:
http://ww1.microchip.com/downloads/en/devicedoc/Atmel-6438-32-bit-ARM926-Embedded-Microprocessor-SAM9G45_Datasheet.pdf

After you update the patch you should also add:
Fixes: d8840a7edcf0 ("dmaengine: at_hdmac: Use bitfield access macros")
Cc: stable@vger.kernel.org
so that it gets backported to Linux-stable.

Feel free to add my R-b tag after addressing the comments:
Reviewed-by: Tudor Ambarus <tudor.ambarus@linaro.org>

> Signed-off-by: Peter Rosin <peda@axentia.se>
> ---
>  drivers/dma/at_hdmac.c | 4 ----
>  1 file changed, 4 deletions(-)
> 
> diff --git a/drivers/dma/at_hdmac.c b/drivers/dma/at_hdmac.c
> index 6f352160bc3b..51d0a0c7aaf7 100644
> --- a/drivers/dma/at_hdmac.c
> +++ b/drivers/dma/at_hdmac.c
> @@ -137,10 +137,6 @@
>  #define ATC_FC_MEM2PER		0x1		/* Mem-to-Periph (DMA) */
>  #define ATC_FC_PER2MEM		0x2		/* Periph-to-Mem (DMA) */
>  #define ATC_FC_PER2PER		0x3		/* Periph-to-Periph (DMA) */
> -#define ATC_FC_PER2MEM_PER	0x4		/* Periph-to-Mem (Peripheral) */
> -#define ATC_FC_MEM2PER_PER	0x5		/* Mem-to-Periph (Peripheral) */
> -#define ATC_FC_PER2PER_SRCPER	0x6		/* Periph-to-Periph (Src Peripheral) */
> -#define ATC_FC_PER2PER_DSTPER	0x7		/* Periph-to-Periph (Dst Peripheral) */
>  #define ATC_SRC_ADDR_MODE	GENMASK(25, 24)
>  #define ATC_SRC_ADDR_MODE_INCR	0x0		/* Incrementing Mode */
>  #define ATC_SRC_ADDR_MODE_DECR	0x1		/* Decrementing Mode */


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

* Re: [PATCH 1/2] dmaengine: at_hdmac: Repair bitfield macros for peripheral ID handling
  2023-05-23 12:42 ` [PATCH 1/2] dmaengine: at_hdmac: Repair bitfield macros for peripheral ID handling Peter Rosin
@ 2023-05-23 15:15   ` Tudor Ambarus
  0 siblings, 0 replies; 5+ messages in thread
From: Tudor Ambarus @ 2023-05-23 15:15 UTC (permalink / raw)
  To: Peter Rosin, LKML
  Cc: Ludovic Desroches, Vinod Koul, Nicolas Ferre, linux-arm-kernel,
	dmaengine



On 5/23/23 13:42, Peter Rosin wrote:
> The MSB part of the peripheral IDs need to go into the ATC_SRC_PER_MSB
> and ATC_DST_PER_MSB fields. Not the LSB part.
> 
> This fixes a severe regression for TSE-850 devices (compatible
> axentia,tse850v3) where output to the audio I2S codec (the main
> purpose of the device) simply do not work.
> 

Indeed, sorry Peter.

> While at it, rewrite the macros as inline functions to evade checkpatch
> warnings about argument reuse.
> 
> Fixes: d8840a7edcf0 ("dmaengine: at_hdmac: Use bitfield access macros")

cc stable please

> Signed-off-by: Peter Rosin <peda@axentia.se>
> ---
>  drivers/dma/at_hdmac.c | 35 ++++++++++++++++++++++++++++-------
>  1 file changed, 28 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/dma/at_hdmac.c b/drivers/dma/at_hdmac.c
> index 8858470246e1..6f352160bc3b 100644
> --- a/drivers/dma/at_hdmac.c
> +++ b/drivers/dma/at_hdmac.c
> @@ -153,8 +153,6 @@
>  #define ATC_AUTO		BIT(31)		/* Auto multiple buffer tx enable */
>  
>  /* Bitfields in CFG */
> -#define ATC_PER_MSB(h)	((0x30U & (h)) >> 4)	/* Extract most significant bits of a handshaking identifier */
> -
>  #define ATC_SRC_PER		GENMASK(3, 0)	/* Channel src rq associated with periph handshaking ifc h */
>  #define ATC_DST_PER		GENMASK(7, 4)	/* Channel dst rq associated with periph handshaking ifc h */
>  #define ATC_SRC_REP		BIT(8)		/* Source Replay Mod */
> @@ -181,10 +179,7 @@
>  #define ATC_DPIP_HOLE		GENMASK(15, 0)
>  #define ATC_DPIP_BOUNDARY	GENMASK(25, 16)
>  
> -#define ATC_SRC_PER_ID(id)	(FIELD_PREP(ATC_SRC_PER_MSB, (id)) |	\
> -				 FIELD_PREP(ATC_SRC_PER, (id)))
> -#define ATC_DST_PER_ID(id)	(FIELD_PREP(ATC_DST_PER_MSB, (id)) |	\
> -				 FIELD_PREP(ATC_DST_PER, (id)))
> +#define ATC_PER_MSB		GENMASK(5, 4)	/* Extract MSBs of a handshaking identifier */
>  
>  
>  
> @@ -1780,6 +1775,32 @@ static bool at_dma_filter(struct dma_chan *chan, void *slave)
>  	}
>  }
>  
> +/**
> + * atc_src_per_id - prepare the source peripheral fields of the CFG
> + * register for the given peripheral handshaking id.
> + *
> + * @per_id: the peripheral id
> + */
> +static inline u32 atc_src_per_id(unsigned int per_id)
> +{
> +	return FIELD_PREP(ATC_SRC_PER_MSB,
> +			  FIELD_GET(ATC_PER_MSB, per_id)) |
> +		FIELD_PREP(ATC_SRC_PER, per_id);
> +}

I still prefer a macro, would you use the following instead?
+#define ATC_SRC_PER_ID(id)                                            \
+       ({ typeof(id) _id = (id);                                      \
+          FIELD_PREP(ATC_SRC_PER_MSB, FIELD_GET(ATC_PER_MSB, _id)) |  \
+          FIELD_PREP(ATC_SRC_PER, _id); })

Cheers,
ta

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

end of thread, other threads:[~2023-05-23 15:18 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-23 12:42 [PATCH 0/2] dmaengine: at_hdmac: Regression fix and cleanup Peter Rosin
2023-05-23 12:42 ` [PATCH 1/2] dmaengine: at_hdmac: Repair bitfield macros for peripheral ID handling Peter Rosin
2023-05-23 15:15   ` Tudor Ambarus
2023-05-23 12:42 ` [PATCH 2/2] dmaengine: at_hdmac: Remove unused field values that do not fit Peter Rosin
2023-05-23 14:04   ` Tudor Ambarus

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

all inboxes | Powered by JetHome®