linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] dmaengine: zynqmp_dma: fix burst length configuration
@ 2020-01-10  8:26 Matthias Fend
  2020-01-10  8:48 ` Michal Simek
  2020-01-21  9:18 ` Vinod Koul
  0 siblings, 2 replies; 4+ messages in thread
From: Matthias Fend @ 2020-01-10  8:26 UTC (permalink / raw)
  To: linux-arm-kernel; +Cc: dmaengine, Matthias Fend, vkoul, michal.simek

Since the dma engine expects the burst length register content as
power of 2 value, the burst length needs to be converted first.
Additionally add a burst length range check to avoid corrupting unrelated
register bits.

Signed-off-by: Matthias Fend <matthias.fend@wolfvision.net>
---
 drivers/dma/xilinx/zynqmp_dma.c | 24 +++++++++++++++---------
 1 file changed, 15 insertions(+), 9 deletions(-)

diff --git a/drivers/dma/xilinx/zynqmp_dma.c b/drivers/dma/xilinx/zynqmp_dma.c
index 9c845c07b107..aa4de6c6688a 100644
--- a/drivers/dma/xilinx/zynqmp_dma.c
+++ b/drivers/dma/xilinx/zynqmp_dma.c
@@ -123,10 +123,12 @@
 /* Max transfer size per descriptor */
 #define ZYNQMP_DMA_MAX_TRANS_LEN	0x40000000
 
+/* Max burst lengths */
+#define ZYNQMP_DMA_MAX_DST_BURST_LEN    16
+#define ZYNQMP_DMA_MAX_SRC_BURST_LEN    16
+
 /* Reset values for data attributes */
 #define ZYNQMP_DMA_AXCACHE_VAL		0xF
-#define ZYNQMP_DMA_ARLEN_RST_VAL	0xF
-#define ZYNQMP_DMA_AWLEN_RST_VAL	0xF
 
 #define ZYNQMP_DMA_SRC_ISSUE_RST_VAL	0x1F
 
@@ -534,17 +536,19 @@ static void zynqmp_dma_handle_ovfl_int(struct zynqmp_dma_chan *chan, u32 status)
 
 static void zynqmp_dma_config(struct zynqmp_dma_chan *chan)
 {
-	u32 val;
+	u32 val, burst_val;
 
 	val = readl(chan->regs + ZYNQMP_DMA_CTRL0);
 	val |= ZYNQMP_DMA_POINT_TYPE_SG;
 	writel(val, chan->regs + ZYNQMP_DMA_CTRL0);
 
 	val = readl(chan->regs + ZYNQMP_DMA_DATA_ATTR);
+	burst_val = __ilog2_u32(chan->src_burst_len);
 	val = (val & ~ZYNQMP_DMA_ARLEN) |
-		(chan->src_burst_len << ZYNQMP_DMA_ARLEN_OFST);
+		(burst_val << ZYNQMP_DMA_ARLEN_OFST);
+	burst_val = __ilog2_u32(chan->dst_burst_len);
 	val = (val & ~ZYNQMP_DMA_AWLEN) |
-		(chan->dst_burst_len << ZYNQMP_DMA_AWLEN_OFST);
+		(burst_val << ZYNQMP_DMA_AWLEN_OFST);
 	writel(val, chan->regs + ZYNQMP_DMA_DATA_ATTR);
 }
 
@@ -560,8 +564,10 @@ static int zynqmp_dma_device_config(struct dma_chan *dchan,
 {
 	struct zynqmp_dma_chan *chan = to_chan(dchan);
 
-	chan->src_burst_len = config->src_maxburst;
-	chan->dst_burst_len = config->dst_maxburst;
+	chan->src_burst_len = clamp(config->src_maxburst, 1U,
+		(u32) ZYNQMP_DMA_MAX_SRC_BURST_LEN);
+	chan->dst_burst_len = clamp(config->dst_maxburst, 1U,
+		(u32) ZYNQMP_DMA_MAX_DST_BURST_LEN);
 
 	return 0;
 }
@@ -887,8 +893,8 @@ static int zynqmp_dma_chan_probe(struct zynqmp_dma_device *zdev,
 		return PTR_ERR(chan->regs);
 
 	chan->bus_width = ZYNQMP_DMA_BUS_WIDTH_64;
-	chan->dst_burst_len = ZYNQMP_DMA_AWLEN_RST_VAL;
-	chan->src_burst_len = ZYNQMP_DMA_ARLEN_RST_VAL;
+	chan->dst_burst_len = ZYNQMP_DMA_MAX_DST_BURST_LEN;
+	chan->src_burst_len = ZYNQMP_DMA_MAX_SRC_BURST_LEN;
 	err = of_property_read_u32(node, "xlnx,bus-width", &chan->bus_width);
 	if (err < 0) {
 		dev_err(&pdev->dev, "missing xlnx,bus-width property\n");
-- 
2.17.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH] dmaengine: zynqmp_dma: fix burst length configuration
  2020-01-10  8:26 [PATCH] dmaengine: zynqmp_dma: fix burst length configuration Matthias Fend
@ 2020-01-10  8:48 ` Michal Simek
  2020-01-15  5:41   ` Harini Katakam
  2020-01-21  9:18 ` Vinod Koul
  1 sibling, 1 reply; 4+ messages in thread
From: Michal Simek @ 2020-01-10  8:48 UTC (permalink / raw)
  To: Matthias Fend, linux-arm-kernel
  Cc: dmaengine, Harini Katakam, vkoul, Radhey Shyam Pandey, michal.simek

+Radhey and Harini

On 10. 01. 20 9:26, Matthias Fend wrote:
> Since the dma engine expects the burst length register content as
> power of 2 value, the burst length needs to be converted first.
> Additionally add a burst length range check to avoid corrupting unrelated
> register bits.
> 
> Signed-off-by: Matthias Fend <matthias.fend@wolfvision.net>
> ---
>  drivers/dma/xilinx/zynqmp_dma.c | 24 +++++++++++++++---------
>  1 file changed, 15 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/dma/xilinx/zynqmp_dma.c b/drivers/dma/xilinx/zynqmp_dma.c
> index 9c845c07b107..aa4de6c6688a 100644
> --- a/drivers/dma/xilinx/zynqmp_dma.c
> +++ b/drivers/dma/xilinx/zynqmp_dma.c
> @@ -123,10 +123,12 @@
>  /* Max transfer size per descriptor */
>  #define ZYNQMP_DMA_MAX_TRANS_LEN	0x40000000
>  
> +/* Max burst lengths */
> +#define ZYNQMP_DMA_MAX_DST_BURST_LEN    16
> +#define ZYNQMP_DMA_MAX_SRC_BURST_LEN    16
> +
>  /* Reset values for data attributes */
>  #define ZYNQMP_DMA_AXCACHE_VAL		0xF
> -#define ZYNQMP_DMA_ARLEN_RST_VAL	0xF
> -#define ZYNQMP_DMA_AWLEN_RST_VAL	0xF
>  
>  #define ZYNQMP_DMA_SRC_ISSUE_RST_VAL	0x1F
>  
> @@ -534,17 +536,19 @@ static void zynqmp_dma_handle_ovfl_int(struct zynqmp_dma_chan *chan, u32 status)
>  
>  static void zynqmp_dma_config(struct zynqmp_dma_chan *chan)
>  {
> -	u32 val;
> +	u32 val, burst_val;
>  
>  	val = readl(chan->regs + ZYNQMP_DMA_CTRL0);
>  	val |= ZYNQMP_DMA_POINT_TYPE_SG;
>  	writel(val, chan->regs + ZYNQMP_DMA_CTRL0);
>  
>  	val = readl(chan->regs + ZYNQMP_DMA_DATA_ATTR);
> +	burst_val = __ilog2_u32(chan->src_burst_len);
>  	val = (val & ~ZYNQMP_DMA_ARLEN) |
> -		(chan->src_burst_len << ZYNQMP_DMA_ARLEN_OFST);
> +		(burst_val << ZYNQMP_DMA_ARLEN_OFST);
> +	burst_val = __ilog2_u32(chan->dst_burst_len);
>  	val = (val & ~ZYNQMP_DMA_AWLEN) |
> -		(chan->dst_burst_len << ZYNQMP_DMA_AWLEN_OFST);
> +		(burst_val << ZYNQMP_DMA_AWLEN_OFST);
>  	writel(val, chan->regs + ZYNQMP_DMA_DATA_ATTR);
>  }
>  
> @@ -560,8 +564,10 @@ static int zynqmp_dma_device_config(struct dma_chan *dchan,
>  {
>  	struct zynqmp_dma_chan *chan = to_chan(dchan);
>  
> -	chan->src_burst_len = config->src_maxburst;
> -	chan->dst_burst_len = config->dst_maxburst;
> +	chan->src_burst_len = clamp(config->src_maxburst, 1U,
> +		(u32) ZYNQMP_DMA_MAX_SRC_BURST_LEN);
> +	chan->dst_burst_len = clamp(config->dst_maxburst, 1U,
> +		(u32) ZYNQMP_DMA_MAX_DST_BURST_LEN);
>  
>  	return 0;
>  }
> @@ -887,8 +893,8 @@ static int zynqmp_dma_chan_probe(struct zynqmp_dma_device *zdev,
>  		return PTR_ERR(chan->regs);
>  
>  	chan->bus_width = ZYNQMP_DMA_BUS_WIDTH_64;
> -	chan->dst_burst_len = ZYNQMP_DMA_AWLEN_RST_VAL;
> -	chan->src_burst_len = ZYNQMP_DMA_ARLEN_RST_VAL;
> +	chan->dst_burst_len = ZYNQMP_DMA_MAX_DST_BURST_LEN;
> +	chan->src_burst_len = ZYNQMP_DMA_MAX_SRC_BURST_LEN;
>  	err = of_property_read_u32(node, "xlnx,bus-width", &chan->bus_width);
>  	if (err < 0) {
>  		dev_err(&pdev->dev, "missing xlnx,bus-width property\n");
> 

M


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* RE: [PATCH] dmaengine: zynqmp_dma: fix burst length configuration
  2020-01-10  8:48 ` Michal Simek
@ 2020-01-15  5:41   ` Harini Katakam
  0 siblings, 0 replies; 4+ messages in thread
From: Harini Katakam @ 2020-01-15  5:41 UTC (permalink / raw)
  To: Michal Simek, Matthias Fend, linux-arm-kernel
  Cc: dmaengine, vkoul, Michal Simek, Radhey Shyam Pandey

Hi Matthias,

> -----Original Message-----
> From: Michal Simek [mailto:michal.simek@xilinx.com]
> Sent: Friday, January 10, 2020 2:18 PM
> To: Matthias Fend <matthias.fend@wolfvision.net>; linux-arm-
> kernel@lists.infradead.org
> Cc: dmaengine@vger.kernel.org; Michal Simek <michals@xilinx.com>;
> vkoul@kernel.org; Radhey Shyam Pandey <radheys@xilinx.com>; Harini
> Katakam <harinik@xilinx.com>
> Subject: Re: [PATCH] dmaengine: zynqmp_dma: fix burst length configuration
> 
> +Radhey and Harini
> 
> On 10. 01. 20 9:26, Matthias Fend wrote:
> > Since the dma engine expects the burst length register content as
> > power of 2 value, the burst length needs to be converted first.
> > Additionally add a burst length range check to avoid corrupting
> > unrelated register bits.
> >
> > Signed-off-by: Matthias Fend <matthias.fend@wolfvision.net>
> > ---
> >  drivers/dma/xilinx/zynqmp_dma.c | 24 +++++++++++++++---------
> >  1 file changed, 15 insertions(+), 9 deletions(-)
> >
> > diff --git a/drivers/dma/xilinx/zynqmp_dma.c
> > b/drivers/dma/xilinx/zynqmp_dma.c index 9c845c07b107..aa4de6c6688a
> > 100644
> > --- a/drivers/dma/xilinx/zynqmp_dma.c
> > +++ b/drivers/dma/xilinx/zynqmp_dma.c
> > @@ -123,10 +123,12 @@
> >  /* Max transfer size per descriptor */
> >  #define ZYNQMP_DMA_MAX_TRANS_LEN	0x40000000
> >
> > +/* Max burst lengths */
> > +#define ZYNQMP_DMA_MAX_DST_BURST_LEN    16
> > +#define ZYNQMP_DMA_MAX_SRC_BURST_LEN    16
> > +
> >  /* Reset values for data attributes */
> >  #define ZYNQMP_DMA_AXCACHE_VAL		0xF
> > -#define ZYNQMP_DMA_ARLEN_RST_VAL	0xF
> > -#define ZYNQMP_DMA_AWLEN_RST_VAL	0xF
<snip>
> > @@ -887,8 +893,8 @@ static int zynqmp_dma_chan_probe(struct
> zynqmp_dma_device *zdev,
> >  		return PTR_ERR(chan->regs);
> >
> >  	chan->bus_width = ZYNQMP_DMA_BUS_WIDTH_64;
> > -	chan->dst_burst_len = ZYNQMP_DMA_AWLEN_RST_VAL;
> > -	chan->src_burst_len = ZYNQMP_DMA_ARLEN_RST_VAL;
> > +	chan->dst_burst_len = ZYNQMP_DMA_MAX_DST_BURST_LEN;
> > +	chan->src_burst_len = ZYNQMP_DMA_MAX_SRC_BURST_LEN;
> >  	err = of_property_read_u32(node, "xlnx,bus-width", &chan-
> >bus_width);

Just a note that this changes the reset value of this field  from 0xF (acc to the spec) to 0x4.
It may need to be updated for future IP versions, if any, but I think it makes sense for now.
Thanks.
Reviewed-by: Harini Katakam <harini.katakam@xilinx.com>

Regards,
Harini
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH] dmaengine: zynqmp_dma: fix burst length configuration
  2020-01-10  8:26 [PATCH] dmaengine: zynqmp_dma: fix burst length configuration Matthias Fend
  2020-01-10  8:48 ` Michal Simek
@ 2020-01-21  9:18 ` Vinod Koul
  1 sibling, 0 replies; 4+ messages in thread
From: Vinod Koul @ 2020-01-21  9:18 UTC (permalink / raw)
  To: Matthias Fend; +Cc: dmaengine, michal.simek, linux-arm-kernel

On 10-01-20, 09:26, Matthias Fend wrote:
> Since the dma engine expects the burst length register content as
> power of 2 value, the burst length needs to be converted first.
> Additionally add a burst length range check to avoid corrupting unrelated
> register bits.

Applied, thanks

-- 
~Vinod

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

end of thread, other threads:[~2020-01-21  9:18 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-10  8:26 [PATCH] dmaengine: zynqmp_dma: fix burst length configuration Matthias Fend
2020-01-10  8:48 ` Michal Simek
2020-01-15  5:41   ` Harini Katakam
2020-01-21  9:18 ` Vinod Koul

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