All of lore.kernel.org
 help / color / mirror / Atom feed
* [v3,3/3] dmaengine: imx-sdma: allocate max 20 bds for one transfer
  2018-07-23 17:46 ` Robin Gong
  (?)
@ 2018-07-23 10:54 ` Lucas Stach
  -1 siblings, 0 replies; 35+ messages in thread
From: Lucas Stach @ 2018-07-23 10:54 UTC (permalink / raw)
  To: Robin Gong, vkoul, dan.j.williams, s.hauer, linux
  Cc: dmaengine, linux-imx, kernel, linux-arm-kernel, linux-kernel

Am Dienstag, den 24.07.2018, 01:46 +0800 schrieb Robin Gong:
> If multi-bds used in one transfer, all bds should be consisten
> memory.To easily follow it, enlarge the dma pool size into 20 bds,
> and it will report error if the number of bds is over than 20. For
> dmatest, the max count for single transfer is NUM_BD *
> SDMA_BD_MAX_CNT = 20 * 65535 = ~1.28MB.

Both the commit message and the comment need a lot more care to
actually tell what this commit is trying to achieve. Currently I don't
follow at all. What does "consisten" mean? Do you mean BDs should be
contiguous in memory?

What do you gain by over-allocating each BD by a factor of 20?

Regards,
Lucas

> Signed-off-by: Robin Gong <yibin.gong@nxp.com>
> ---
>  drivers/dma/imx-sdma.c | 17 ++++++++++++++++-
>  1 file changed, 16 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/dma/imx-sdma.c b/drivers/dma/imx-sdma.c
> index b4ec2d2..5973489 100644
> --- a/drivers/dma/imx-sdma.c
> +++ b/drivers/dma/imx-sdma.c
> @@ -298,6 +298,15 @@ struct sdma_context_data {
> >  	u32  scratch7;
>  } __attribute__ ((packed));
>  
> +/*
> + * All bds in one transfer should be consitent on SDMA. To easily follow it,just
> + * set the dma pool size as the enough bds. For example, in dmatest case, the
> + * max 20 bds means the max for single transfer is NUM_BD * SDMA_BD_MAX_CNT = 20
> + * * 65535 = ~1.28MB. 20 bds supposed to be enough basically.If it's still not
> + * enough in some specific cases, enlarge it here.Warning message would also
> + * appear if the bd numbers is over than 20.
> + */
> +#define NUM_BD 20
>  
>  struct sdma_engine;
>  
> @@ -1273,7 +1282,7 @@ static int sdma_alloc_chan_resources(struct dma_chan *chan)
> >  		goto disable_clk_ahb;
>  
> >  	sdmac->bd_pool = dma_pool_create("bd_pool", chan->device->dev,
> > -				sizeof(struct sdma_buffer_descriptor),
> > +				NUM_BD * sizeof(struct sdma_buffer_descriptor),
> >  				32, 0);
>  
> >  	return 0;
> @@ -1314,6 +1323,12 @@ static struct sdma_desc *sdma_transfer_init(struct sdma_channel *sdmac,
>  {
> >  	struct sdma_desc *desc;
>  
> > +	if (bds > NUM_BD) {
> > +		dev_err(sdmac->sdma->dev, "%d bds exceed the max %d\n",
> > +			bds, NUM_BD);
> > +		goto err_out;
> > +	}
> +
> >  	desc = kzalloc((sizeof(*desc)), GFP_NOWAIT);
> >  	if (!desc)
> >  		goto err_out;
---
To unsubscribe from this list: send the line "unsubscribe dmaengine" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH v3 3/3] dmaengine: imx-sdma: allocate max 20 bds for one transfer
@ 2018-07-23 10:54 ` Lucas Stach
  0 siblings, 0 replies; 35+ messages in thread
From: Lucas Stach @ 2018-07-23 10:54 UTC (permalink / raw)
  To: Robin Gong, vkoul, dan.j.williams, s.hauer, linux
  Cc: dmaengine, linux-imx, kernel, linux-arm-kernel, linux-kernel

Am Dienstag, den 24.07.2018, 01:46 +0800 schrieb Robin Gong:
> If multi-bds used in one transfer, all bds should be consisten
> memory.To easily follow it, enlarge the dma pool size into 20 bds,
> and it will report error if the number of bds is over than 20. For
> dmatest, the max count for single transfer is NUM_BD *
> SDMA_BD_MAX_CNT = 20 * 65535 = ~1.28MB.

Both the commit message and the comment need a lot more care to
actually tell what this commit is trying to achieve. Currently I don't
follow at all. What does "consisten" mean? Do you mean BDs should be
contiguous in memory?

What do you gain by over-allocating each BD by a factor of 20?

Regards,
Lucas

> Signed-off-by: Robin Gong <yibin.gong@nxp.com>
> ---
>  drivers/dma/imx-sdma.c | 17 ++++++++++++++++-
>  1 file changed, 16 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/dma/imx-sdma.c b/drivers/dma/imx-sdma.c
> index b4ec2d2..5973489 100644
> --- a/drivers/dma/imx-sdma.c
> +++ b/drivers/dma/imx-sdma.c
> @@ -298,6 +298,15 @@ struct sdma_context_data {
> >  	u32  scratch7;
>  } __attribute__ ((packed));
>  
> +/*
> + * All bds in one transfer should be consitent on SDMA. To easily follow it,just
> + * set the dma pool size as the enough bds. For example, in dmatest case, the
> + * max 20 bds means the max for single transfer is NUM_BD * SDMA_BD_MAX_CNT = 20
> + * * 65535 = ~1.28MB. 20 bds supposed to be enough basically.If it's still not
> + * enough in some specific cases, enlarge it here.Warning message would also
> + * appear if the bd numbers is over than 20.
> + */
> +#define NUM_BD 20
>  
>  struct sdma_engine;
>  
> @@ -1273,7 +1282,7 @@ static int sdma_alloc_chan_resources(struct dma_chan *chan)
> >  		goto disable_clk_ahb;
>  
> >  	sdmac->bd_pool = dma_pool_create("bd_pool", chan->device->dev,
> > -				sizeof(struct sdma_buffer_descriptor),
> > +				NUM_BD * sizeof(struct sdma_buffer_descriptor),
> >  				32, 0);
>  
> >  	return 0;
> @@ -1314,6 +1323,12 @@ static struct sdma_desc *sdma_transfer_init(struct sdma_channel *sdmac,
>  {
> >  	struct sdma_desc *desc;
>  
> > +	if (bds > NUM_BD) {
> > +		dev_err(sdmac->sdma->dev, "%d bds exceed the max %d\n",
> > +			bds, NUM_BD);
> > +		goto err_out;
> > +	}
> +
> >  	desc = kzalloc((sizeof(*desc)), GFP_NOWAIT);
> >  	if (!desc)
> >  		goto err_out;

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

* [PATCH v3 3/3] dmaengine: imx-sdma: allocate max 20 bds for one transfer
@ 2018-07-23 10:54 ` Lucas Stach
  0 siblings, 0 replies; 35+ messages in thread
From: Lucas Stach @ 2018-07-23 10:54 UTC (permalink / raw)
  To: linux-arm-kernel

Am Dienstag, den 24.07.2018, 01:46 +0800 schrieb Robin Gong:
> If multi-bds used in one transfer, all bds should be consisten
> memory.To easily follow it, enlarge the dma pool size into 20 bds,
> and it will report error if the number of bds is over than 20. For
> dmatest, the max count for single transfer is NUM_BD *
> SDMA_BD_MAX_CNT = 20 * 65535 = ~1.28MB.

Both the commit message and the comment need a lot more care to
actually tell what this commit is trying to achieve. Currently I don't
follow at all. What does "consisten" mean? Do you mean BDs should be
contiguous in memory?

What do you gain by over-allocating each BD by a factor of 20?

Regards,
Lucas

> Signed-off-by: Robin Gong <yibin.gong@nxp.com>
> ---
> ?drivers/dma/imx-sdma.c | 17 ++++++++++++++++-
> ?1 file changed, 16 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/dma/imx-sdma.c b/drivers/dma/imx-sdma.c
> index b4ec2d2..5973489 100644
> --- a/drivers/dma/imx-sdma.c
> +++ b/drivers/dma/imx-sdma.c
> @@ -298,6 +298,15 @@ struct sdma_context_data {
> > ?	u32??scratch7;
> ?} __attribute__ ((packed));
> ?
> +/*
> + * All bds in one transfer should be consitent on SDMA. To easily follow it,just
> + * set the dma pool size as the enough bds. For example, in dmatest case, the
> + * max 20 bds means the max for single transfer is NUM_BD * SDMA_BD_MAX_CNT = 20
> + * * 65535 = ~1.28MB. 20 bds supposed to be enough basically.If it's still not
> + * enough in some specific cases, enlarge it here.Warning message would also
> + * appear if the bd numbers is over than 20.
> + */
> +#define NUM_BD 20
> ?
> ?struct sdma_engine;
> ?
> @@ -1273,7 +1282,7 @@ static int sdma_alloc_chan_resources(struct dma_chan *chan)
> > ?		goto disable_clk_ahb;
> ?
> > ?	sdmac->bd_pool = dma_pool_create("bd_pool", chan->device->dev,
> > -				sizeof(struct sdma_buffer_descriptor),
> > +				NUM_BD * sizeof(struct sdma_buffer_descriptor),
> > ?				32, 0);
> ?
> > ?	return 0;
> @@ -1314,6 +1323,12 @@ static struct sdma_desc *sdma_transfer_init(struct sdma_channel *sdmac,
> ?{
> > ?	struct sdma_desc *desc;
> ?
> > +	if (bds > NUM_BD) {
> > +		dev_err(sdmac->sdma->dev, "%d bds exceed the max %d\n",
> > +			bds, NUM_BD);
> > +		goto err_out;
> > +	}
> +
> > ?	desc = kzalloc((sizeof(*desc)), GFP_NOWAIT);
> > ?	if (!desc)
> > ?		goto err_out;

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

* [v3,3/3] dmaengine: imx-sdma: allocate max 20 bds for one transfer
  2018-07-23 10:54 ` Lucas Stach
  (?)
@ 2018-07-23 13:55 ` Robin Gong
  -1 siblings, 0 replies; 35+ messages in thread
From: Robin Gong @ 2018-07-23 13:55 UTC (permalink / raw)
  To: Lucas Stach, vkoul, dan.j.williams, s.hauer, linux
  Cc: dmaengine, dl-linux-imx, kernel, linux-arm-kernel, linux-kernel

PiAtLS0tLU9yaWdpbmFsIE1lc3NhZ2UtLS0tLQ0KPiBGcm9tOiBMdWNhcyBTdGFjaCBbbWFpbHRv
Omwuc3RhY2hAcGVuZ3V0cm9uaXguZGVdDQo+IFNlbnQ6IDIwMTjlubQ35pyIMjPml6UgMTg6NTQN
Cj4gVG86IFJvYmluIEdvbmcgPHlpYmluLmdvbmdAbnhwLmNvbT47IHZrb3VsQGtlcm5lbC5vcmc7
DQo+IGRhbi5qLndpbGxpYW1zQGludGVsLmNvbTsgcy5oYXVlckBwZW5ndXRyb25peC5kZTsgbGlu
dXhAYXJtbGludXgub3JnLnVrDQo+IENjOiBkbWFlbmdpbmVAdmdlci5rZXJuZWwub3JnOyBkbC1s
aW51eC1pbXggPGxpbnV4LWlteEBueHAuY29tPjsNCj4ga2VybmVsQHBlbmd1dHJvbml4LmRlOyBs
aW51eC1hcm0ta2VybmVsQGxpc3RzLmluZnJhZGVhZC5vcmc7DQo+IGxpbnV4LWtlcm5lbEB2Z2Vy
Lmtlcm5lbC5vcmcNCj4gU3ViamVjdDogUmU6IFtQQVRDSCB2MyAzLzNdIGRtYWVuZ2luZTogaW14
LXNkbWE6IGFsbG9jYXRlIG1heCAyMCBiZHMgZm9yIG9uZQ0KPiB0cmFuc2Zlcg0KPiANCj4gQW0g
RGllbnN0YWcsIGRlbiAyNC4wNy4yMDE4LCAwMTo0NiArMDgwMCBzY2hyaWViIFJvYmluIEdvbmc6
DQo+ID4gSWYgbXVsdGktYmRzIHVzZWQgaW4gb25lIHRyYW5zZmVyLCBhbGwgYmRzIHNob3VsZCBi
ZSBjb25zaXN0ZW4NCj4gPiBtZW1vcnkuVG8gZWFzaWx5IGZvbGxvdyBpdCwgZW5sYXJnZSB0aGUg
ZG1hIHBvb2wgc2l6ZSBpbnRvIDIwIGJkcywgYW5kDQo+ID4gaXQgd2lsbCByZXBvcnQgZXJyb3Ig
aWYgdGhlIG51bWJlciBvZiBiZHMgaXMgb3ZlciB0aGFuIDIwLiBGb3INCj4gPiBkbWF0ZXN0LCB0
aGUgbWF4IGNvdW50IGZvciBzaW5nbGUgdHJhbnNmZXIgaXMgTlVNX0JEICoNCj4gU0RNQV9CRF9N
QVhfQ05UDQo+ID4gPSAyMCAqIDY1NTM1ID0gfjEuMjhNQi4NCj4gDQo+IEJvdGggdGhlIGNvbW1p
dCBtZXNzYWdlIGFuZCB0aGUgY29tbWVudCBuZWVkIGEgbG90IG1vcmUgY2FyZSB0byBhY3R1YWxs
eQ0KPiB0ZWxsIHdoYXQgdGhpcyBjb21taXQgaXMgdHJ5aW5nIHRvIGFjaGlldmUuIEN1cnJlbnRs
eSBJIGRvbid0IGZvbGxvdyBhdCBhbGwuIFdoYXQNCj4gZG9lcyAiY29uc2lzdGVuIiBtZWFuPyBE
byB5b3UgbWVhbiBCRHMgc2hvdWxkIGJlIGNvbnRpZ3VvdXMgaW4gbWVtb3J5Pw0KWWVzLCBCRHMg
c2hvdWxkIGJlIGNvbnRpZ3VvdXMgIG9uZSBieSBvbmUgaW4gbWVtb3J5Lg0KPiANCj4gV2hhdCBk
byB5b3UgZ2FpbiBieSBvdmVyLWFsbG9jYXRpbmcgZWFjaCBCRCBieSBhIGZhY3RvciBvZiAyMD8N
CkkgZ3Vlc3MgZG1hX3Bvb2xfYWxsb2Mgd2lsbCByZXR1cm4gZXJyb3IgaW4gc3VjaCBjYXNlLCBh
bmQgdGhlbiBjYXVzZSBkbWEgc2V0dXANCnRyYW5zZmVyIGZhaWx1cmUuDQo+IA0KPiBSZWdhcmRz
LA0KPiBMdWNhcw0KPiANCj4gPiBTaWduZWQtb2ZmLWJ5OiBSb2JpbiBHb25nIDx5aWJpbi5nb25n
QG54cC5jb20+DQo+ID4gLS0tDQo+ID4gwqBkcml2ZXJzL2RtYS9pbXgtc2RtYS5jIHwgMTcgKysr
KysrKysrKysrKysrKy0NCj4gPiDCoDEgZmlsZSBjaGFuZ2VkLCAxNiBpbnNlcnRpb25zKCspLCAx
IGRlbGV0aW9uKC0pDQo+ID4NCj4gPiBkaWZmIC0tZ2l0IGEvZHJpdmVycy9kbWEvaW14LXNkbWEu
YyBiL2RyaXZlcnMvZG1hL2lteC1zZG1hLmMgaW5kZXgNCj4gPiBiNGVjMmQyLi41OTczNDg5IDEw
MDY0NA0KPiA+IC0tLSBhL2RyaXZlcnMvZG1hL2lteC1zZG1hLmMNCj4gPiArKysgYi9kcml2ZXJz
L2RtYS9pbXgtc2RtYS5jDQo+ID4gQEAgLTI5OCw2ICsyOTgsMTUgQEAgc3RydWN0IHNkbWFfY29u
dGV4dF9kYXRhIHsNCj4gPiA+IMKgCXUzMsKgwqBzY3JhdGNoNzsNCj4gPiDCoH0gX19hdHRyaWJ1
dGVfXyAoKHBhY2tlZCkpOw0KPiA+DQo+ID4gKy8qDQo+ID4gKyAqIEFsbCBiZHMgaW4gb25lIHRy
YW5zZmVyIHNob3VsZCBiZSBjb25zaXRlbnQgb24gU0RNQS4gVG8gZWFzaWx5DQo+ID4gK2ZvbGxv
dyBpdCxqdXN0DQo+ID4gKyAqIHNldCB0aGUgZG1hIHBvb2wgc2l6ZSBhcyB0aGUgZW5vdWdoIGJk
cy4gRm9yIGV4YW1wbGUsIGluIGRtYXRlc3QNCj4gPiArY2FzZSwgdGhlDQo+ID4gKyAqIG1heCAy
MCBiZHMgbWVhbnMgdGhlIG1heCBmb3Igc2luZ2xlIHRyYW5zZmVyIGlzIE5VTV9CRCAqDQo+ID4g
K1NETUFfQkRfTUFYX0NOVCA9IDIwDQo+ID4gKyAqICogNjU1MzUgPSB+MS4yOE1CLiAyMCBiZHMg
c3VwcG9zZWQgdG8gYmUgZW5vdWdoIGJhc2ljYWxseS5JZiBpdCdzDQo+ID4gK3N0aWxsIG5vdA0K
PiA+ICsgKiBlbm91Z2ggaW4gc29tZSBzcGVjaWZpYyBjYXNlcywgZW5sYXJnZSBpdCBoZXJlLldh
cm5pbmcgbWVzc2FnZQ0KPiA+ICt3b3VsZCBhbHNvDQo+ID4gKyAqIGFwcGVhciBpZiB0aGUgYmQg
bnVtYmVycyBpcyBvdmVyIHRoYW4gMjAuDQo+ID4gKyAqLw0KPiA+ICsjZGVmaW5lIE5VTV9CRCAy
MA0KPiA+DQo+ID4gwqBzdHJ1Y3Qgc2RtYV9lbmdpbmU7DQo+ID4NCj4gPiBAQCAtMTI3Myw3ICsx
MjgyLDcgQEAgc3RhdGljIGludCBzZG1hX2FsbG9jX2NoYW5fcmVzb3VyY2VzKHN0cnVjdA0KPiA+
IGRtYV9jaGFuICpjaGFuKQ0KPiA+ID4gwqAJCWdvdG8gZGlzYWJsZV9jbGtfYWhiOw0KPiA+DQo+
ID4gPiDCoAlzZG1hYy0+YmRfcG9vbCA9IGRtYV9wb29sX2NyZWF0ZSgiYmRfcG9vbCIsIGNoYW4t
PmRldmljZS0+ZGV2LA0KPiA+ID4gLQkJCQlzaXplb2Yoc3RydWN0IHNkbWFfYnVmZmVyX2Rlc2Ny
aXB0b3IpLA0KPiA+ID4gKwkJCQlOVU1fQkQgKiBzaXplb2Yoc3RydWN0IHNkbWFfYnVmZmVyX2Rl
c2NyaXB0b3IpLA0KPiA+ID4gwqAJCQkJMzIsIDApOw0KPiA+DQo+ID4gPiDCoAlyZXR1cm4gMDsN
Cj4gPiBAQCAtMTMxNCw2ICsxMzIzLDEyIEBAIHN0YXRpYyBzdHJ1Y3Qgc2RtYV9kZXNjDQo+ID4g
KnNkbWFfdHJhbnNmZXJfaW5pdChzdHJ1Y3Qgc2RtYV9jaGFubmVsICpzZG1hYywNCj4gPiDCoHsN
Cj4gPiA+IMKgCXN0cnVjdCBzZG1hX2Rlc2MgKmRlc2M7DQo+ID4NCj4gPiA+ICsJaWYgKGJkcyA+
IE5VTV9CRCkgew0KPiA+ID4gKwkJZGV2X2VycihzZG1hYy0+c2RtYS0+ZGV2LCAiJWQgYmRzIGV4
Y2VlZCB0aGUgbWF4ICVkXG4iLA0KPiA+ID4gKwkJCWJkcywgTlVNX0JEKTsNCj4gPiA+ICsJCWdv
dG8gZXJyX291dDsNCj4gPiA+ICsJfQ0KPiA+ICsNCj4gPiA+IMKgCWRlc2MgPSBremFsbG9jKChz
aXplb2YoKmRlc2MpKSwgR0ZQX05PV0FJVCk7DQo+ID4gPiDCoAlpZiAoIWRlc2MpDQo+ID4gPiDC
oAkJZ290byBlcnJfb3V0Ow0K
---
To unsubscribe from this list: send the line "unsubscribe dmaengine" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* RE: [PATCH v3 3/3] dmaengine: imx-sdma: allocate max 20 bds for one transfer
@ 2018-07-23 13:55 ` Robin Gong
  0 siblings, 0 replies; 35+ messages in thread
From: Robin Gong @ 2018-07-23 13:55 UTC (permalink / raw)
  To: Lucas Stach, vkoul, dan.j.williams, s.hauer, linux
  Cc: dmaengine, dl-linux-imx, kernel, linux-arm-kernel, linux-kernel

> -----Original Message-----
> From: Lucas Stach [mailto:l.stach@pengutronix.de]
> Sent: 2018年7月23日 18:54
> To: Robin Gong <yibin.gong@nxp.com>; vkoul@kernel.org;
> dan.j.williams@intel.com; s.hauer@pengutronix.de; linux@armlinux.org.uk
> Cc: dmaengine@vger.kernel.org; dl-linux-imx <linux-imx@nxp.com>;
> kernel@pengutronix.de; linux-arm-kernel@lists.infradead.org;
> linux-kernel@vger.kernel.org
> Subject: Re: [PATCH v3 3/3] dmaengine: imx-sdma: allocate max 20 bds for one
> transfer
> 
> Am Dienstag, den 24.07.2018, 01:46 +0800 schrieb Robin Gong:
> > If multi-bds used in one transfer, all bds should be consisten
> > memory.To easily follow it, enlarge the dma pool size into 20 bds, and
> > it will report error if the number of bds is over than 20. For
> > dmatest, the max count for single transfer is NUM_BD *
> SDMA_BD_MAX_CNT
> > = 20 * 65535 = ~1.28MB.
> 
> Both the commit message and the comment need a lot more care to actually
> tell what this commit is trying to achieve. Currently I don't follow at all. What
> does "consisten" mean? Do you mean BDs should be contiguous in memory?
Yes, BDs should be contiguous  one by one in memory.
> 
> What do you gain by over-allocating each BD by a factor of 20?
I guess dma_pool_alloc will return error in such case, and then cause dma setup
transfer failure.
> 
> Regards,
> Lucas
> 
> > Signed-off-by: Robin Gong <yibin.gong@nxp.com>
> > ---
> >  drivers/dma/imx-sdma.c | 17 ++++++++++++++++-
> >  1 file changed, 16 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/dma/imx-sdma.c b/drivers/dma/imx-sdma.c index
> > b4ec2d2..5973489 100644
> > --- a/drivers/dma/imx-sdma.c
> > +++ b/drivers/dma/imx-sdma.c
> > @@ -298,6 +298,15 @@ struct sdma_context_data {
> > >  	u32  scratch7;
> >  } __attribute__ ((packed));
> >
> > +/*
> > + * All bds in one transfer should be consitent on SDMA. To easily
> > +follow it,just
> > + * set the dma pool size as the enough bds. For example, in dmatest
> > +case, the
> > + * max 20 bds means the max for single transfer is NUM_BD *
> > +SDMA_BD_MAX_CNT = 20
> > + * * 65535 = ~1.28MB. 20 bds supposed to be enough basically.If it's
> > +still not
> > + * enough in some specific cases, enlarge it here.Warning message
> > +would also
> > + * appear if the bd numbers is over than 20.
> > + */
> > +#define NUM_BD 20
> >
> >  struct sdma_engine;
> >
> > @@ -1273,7 +1282,7 @@ static int sdma_alloc_chan_resources(struct
> > dma_chan *chan)
> > >  		goto disable_clk_ahb;
> >
> > >  	sdmac->bd_pool = dma_pool_create("bd_pool", chan->device->dev,
> > > -				sizeof(struct sdma_buffer_descriptor),
> > > +				NUM_BD * sizeof(struct sdma_buffer_descriptor),
> > >  				32, 0);
> >
> > >  	return 0;
> > @@ -1314,6 +1323,12 @@ static struct sdma_desc
> > *sdma_transfer_init(struct sdma_channel *sdmac,
> >  {
> > >  	struct sdma_desc *desc;
> >
> > > +	if (bds > NUM_BD) {
> > > +		dev_err(sdmac->sdma->dev, "%d bds exceed the max %d\n",
> > > +			bds, NUM_BD);
> > > +		goto err_out;
> > > +	}
> > +
> > >  	desc = kzalloc((sizeof(*desc)), GFP_NOWAIT);
> > >  	if (!desc)
> > >  		goto err_out;

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

* [PATCH v3 3/3] dmaengine: imx-sdma: allocate max 20 bds for one transfer
@ 2018-07-23 13:55 ` Robin Gong
  0 siblings, 0 replies; 35+ messages in thread
From: Robin Gong @ 2018-07-23 13:55 UTC (permalink / raw)
  To: linux-arm-kernel

> -----Original Message-----
> From: Lucas Stach [mailto:l.stach at pengutronix.de]
> Sent: 2018?7?23? 18:54
> To: Robin Gong <yibin.gong@nxp.com>; vkoul at kernel.org;
> dan.j.williams at intel.com; s.hauer at pengutronix.de; linux at armlinux.org.uk
> Cc: dmaengine at vger.kernel.org; dl-linux-imx <linux-imx@nxp.com>;
> kernel at pengutronix.de; linux-arm-kernel at lists.infradead.org;
> linux-kernel at vger.kernel.org
> Subject: Re: [PATCH v3 3/3] dmaengine: imx-sdma: allocate max 20 bds for one
> transfer
> 
> Am Dienstag, den 24.07.2018, 01:46 +0800 schrieb Robin Gong:
> > If multi-bds used in one transfer, all bds should be consisten
> > memory.To easily follow it, enlarge the dma pool size into 20 bds, and
> > it will report error if the number of bds is over than 20. For
> > dmatest, the max count for single transfer is NUM_BD *
> SDMA_BD_MAX_CNT
> > = 20 * 65535 = ~1.28MB.
> 
> Both the commit message and the comment need a lot more care to actually
> tell what this commit is trying to achieve. Currently I don't follow at all. What
> does "consisten" mean? Do you mean BDs should be contiguous in memory?
Yes, BDs should be contiguous  one by one in memory.
> 
> What do you gain by over-allocating each BD by a factor of 20?
I guess dma_pool_alloc will return error in such case, and then cause dma setup
transfer failure.
> 
> Regards,
> Lucas
> 
> > Signed-off-by: Robin Gong <yibin.gong@nxp.com>
> > ---
> > ?drivers/dma/imx-sdma.c | 17 ++++++++++++++++-
> > ?1 file changed, 16 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/dma/imx-sdma.c b/drivers/dma/imx-sdma.c index
> > b4ec2d2..5973489 100644
> > --- a/drivers/dma/imx-sdma.c
> > +++ b/drivers/dma/imx-sdma.c
> > @@ -298,6 +298,15 @@ struct sdma_context_data {
> > > ?	u32??scratch7;
> > ?} __attribute__ ((packed));
> >
> > +/*
> > + * All bds in one transfer should be consitent on SDMA. To easily
> > +follow it,just
> > + * set the dma pool size as the enough bds. For example, in dmatest
> > +case, the
> > + * max 20 bds means the max for single transfer is NUM_BD *
> > +SDMA_BD_MAX_CNT = 20
> > + * * 65535 = ~1.28MB. 20 bds supposed to be enough basically.If it's
> > +still not
> > + * enough in some specific cases, enlarge it here.Warning message
> > +would also
> > + * appear if the bd numbers is over than 20.
> > + */
> > +#define NUM_BD 20
> >
> > ?struct sdma_engine;
> >
> > @@ -1273,7 +1282,7 @@ static int sdma_alloc_chan_resources(struct
> > dma_chan *chan)
> > > ?		goto disable_clk_ahb;
> >
> > > ?	sdmac->bd_pool = dma_pool_create("bd_pool", chan->device->dev,
> > > -				sizeof(struct sdma_buffer_descriptor),
> > > +				NUM_BD * sizeof(struct sdma_buffer_descriptor),
> > > ?				32, 0);
> >
> > > ?	return 0;
> > @@ -1314,6 +1323,12 @@ static struct sdma_desc
> > *sdma_transfer_init(struct sdma_channel *sdmac,
> > ?{
> > > ?	struct sdma_desc *desc;
> >
> > > +	if (bds > NUM_BD) {
> > > +		dev_err(sdmac->sdma->dev, "%d bds exceed the max %d\n",
> > > +			bds, NUM_BD);
> > > +		goto err_out;
> > > +	}
> > +
> > > ?	desc = kzalloc((sizeof(*desc)), GFP_NOWAIT);
> > > ?	if (!desc)
> > > ?		goto err_out;

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

* [PATCH v3 0/3] add memcpy support for sdma
@ 2018-07-23 17:46 ` Robin Gong
  0 siblings, 0 replies; 35+ messages in thread
From: Robin Gong @ 2018-07-23 17:46 UTC (permalink / raw)
  To: vkoul, dan.j.williams, s.hauer, linux
  Cc: linux-arm-kernel, kernel, dmaengine, linux-kernel, linux-imx

This patchset is to add memcpy interface for imx-sdma, besides,to
support dmatest and enable config by default, so that could test dma
easily without any other device support such as uart/audio/spi...

Change from v2:
  1. remove 'copy_align' since sdma script for memory_2_memory will handle
     such align issue. No such align limitation. Also remove bus width
     description in bd.
  2. for multi bds case such as in dmatest, should make sure all bds of 
     single transfer should be consistent, so enlarge allocated size for
     dma pool to max bds, 20 bds/1.28MB should be enough for all case.Report
     error if the bd number exceed 20.

Change from v1:
  1. remove bus_width check for memcpy since only max bus width needed for
     memcpy case to speedup copy.
  2. remove DMATEST support patch, since DMATEST is a common memcpy case.
  3. split to single patch for SDMA_BD_MAX_CNT instead of '0xffff'
  4. move sdma_config_ownership() from alloc_chan into sdma_prep_memcpy.
  5. address some minor review comments.

Robin Gong (3):
  dmaengine: imx-sdma: add SDMA_BD_MAX_CNT to replace '0xffff'
  dmaengine: imx-sdma: add memcpy interface
  dmaengine: imx-sdma: allocate max 20 bds for one transfer

 drivers/dma/imx-sdma.c | 121 +++++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 112 insertions(+), 9 deletions(-)

-- 
2.7.4


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

* [PATCH v3 0/3] add memcpy support for sdma
@ 2018-07-23 17:46 ` Robin Gong
  0 siblings, 0 replies; 35+ messages in thread
From: Robin Gong @ 2018-07-23 17:46 UTC (permalink / raw)
  To: linux-arm-kernel

This patchset is to add memcpy interface for imx-sdma, besides,to
support dmatest and enable config by default, so that could test dma
easily without any other device support such as uart/audio/spi...

Change from v2:
  1. remove 'copy_align' since sdma script for memory_2_memory will handle
     such align issue. No such align limitation. Also remove bus width
     description in bd.
  2. for multi bds case such as in dmatest, should make sure all bds of 
     single transfer should be consistent, so enlarge allocated size for
     dma pool to max bds, 20 bds/1.28MB should be enough for all case.Report
     error if the bd number exceed 20.

Change from v1:
  1. remove bus_width check for memcpy since only max bus width needed for
     memcpy case to speedup copy.
  2. remove DMATEST support patch, since DMATEST is a common memcpy case.
  3. split to single patch for SDMA_BD_MAX_CNT instead of '0xffff'
  4. move sdma_config_ownership() from alloc_chan into sdma_prep_memcpy.
  5. address some minor review comments.

Robin Gong (3):
  dmaengine: imx-sdma: add SDMA_BD_MAX_CNT to replace '0xffff'
  dmaengine: imx-sdma: add memcpy interface
  dmaengine: imx-sdma: allocate max 20 bds for one transfer

 drivers/dma/imx-sdma.c | 121 +++++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 112 insertions(+), 9 deletions(-)

-- 
2.7.4

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

* [v3,1/3] dmaengine: imx-sdma: add SDMA_BD_MAX_CNT to replace '0xffff'
  2018-07-23 17:46 ` Robin Gong
  (?)
@ 2018-07-23 17:46 ` Robin Gong
  -1 siblings, 0 replies; 35+ messages in thread
From: Robin Gong @ 2018-07-23 17:46 UTC (permalink / raw)
  To: vkoul, dan.j.williams, s.hauer, linux
  Cc: linux-arm-kernel, kernel, dmaengine, linux-kernel, linux-imx

Add macro SDMA_BD_MAX_CNT to replace '0xffff'.

Signed-off-by: Robin Gong <yibin.gong@nxp.com>
---
 drivers/dma/imx-sdma.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/drivers/dma/imx-sdma.c b/drivers/dma/imx-sdma.c
index 3b622d6..e3d5e73 100644
--- a/drivers/dma/imx-sdma.c
+++ b/drivers/dma/imx-sdma.c
@@ -185,6 +185,7 @@
  * Mode/Count of data node descriptors - IPCv2
  */
 struct sdma_mode_count {
+#define SDMA_BD_MAX_CNT	0xffff
 	u32 count   : 16; /* size of the buffer pointed by this BD */
 	u32 status  :  8; /* E,R,I,C,W,D status bits stored here */
 	u32 command :  8; /* command mostly used for channel 0 */
@@ -1344,9 +1345,9 @@ static struct dma_async_tx_descriptor *sdma_prep_slave_sg(
 
 		count = sg_dma_len(sg);
 
-		if (count > 0xffff) {
+		if (count > SDMA_BD_MAX_CNT) {
 			dev_err(sdma->dev, "SDMA channel %d: maximum bytes for sg entry exceeded: %d > %d\n",
-					channel, count, 0xffff);
+					channel, count, SDMA_BD_MAX_CNT);
 			goto err_bd_out;
 		}
 
@@ -1421,9 +1422,9 @@ static struct dma_async_tx_descriptor *sdma_prep_dma_cyclic(
 
 	sdmac->flags |= IMX_DMA_SG_LOOP;
 
-	if (period_len > 0xffff) {
+	if (period_len > SDMA_BD_MAX_CNT) {
 		dev_err(sdma->dev, "SDMA channel %d: maximum period size exceeded: %zu > %d\n",
-				channel, period_len, 0xffff);
+				channel, period_len, SDMA_BD_MAX_CNT);
 		goto err_bd_out;
 	}
 
@@ -1970,7 +1971,7 @@ static int sdma_probe(struct platform_device *pdev)
 	sdma->dma_device.residue_granularity = DMA_RESIDUE_GRANULARITY_SEGMENT;
 	sdma->dma_device.device_issue_pending = sdma_issue_pending;
 	sdma->dma_device.dev->dma_parms = &sdma->dma_parms;
-	dma_set_max_seg_size(sdma->dma_device.dev, 65535);
+	dma_set_max_seg_size(sdma->dma_device.dev, SDMA_BD_MAX_CNT);
 
 	platform_set_drvdata(pdev, sdma);
 

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

* [PATCH v3 1/3] dmaengine: imx-sdma: add SDMA_BD_MAX_CNT to replace '0xffff'
@ 2018-07-23 17:46 ` Robin Gong
  0 siblings, 0 replies; 35+ messages in thread
From: Robin Gong @ 2018-07-23 17:46 UTC (permalink / raw)
  To: vkoul, dan.j.williams, s.hauer, linux
  Cc: linux-arm-kernel, kernel, dmaengine, linux-kernel, linux-imx

Add macro SDMA_BD_MAX_CNT to replace '0xffff'.

Signed-off-by: Robin Gong <yibin.gong@nxp.com>
---
 drivers/dma/imx-sdma.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/drivers/dma/imx-sdma.c b/drivers/dma/imx-sdma.c
index 3b622d6..e3d5e73 100644
--- a/drivers/dma/imx-sdma.c
+++ b/drivers/dma/imx-sdma.c
@@ -185,6 +185,7 @@
  * Mode/Count of data node descriptors - IPCv2
  */
 struct sdma_mode_count {
+#define SDMA_BD_MAX_CNT	0xffff
 	u32 count   : 16; /* size of the buffer pointed by this BD */
 	u32 status  :  8; /* E,R,I,C,W,D status bits stored here */
 	u32 command :  8; /* command mostly used for channel 0 */
@@ -1344,9 +1345,9 @@ static struct dma_async_tx_descriptor *sdma_prep_slave_sg(
 
 		count = sg_dma_len(sg);
 
-		if (count > 0xffff) {
+		if (count > SDMA_BD_MAX_CNT) {
 			dev_err(sdma->dev, "SDMA channel %d: maximum bytes for sg entry exceeded: %d > %d\n",
-					channel, count, 0xffff);
+					channel, count, SDMA_BD_MAX_CNT);
 			goto err_bd_out;
 		}
 
@@ -1421,9 +1422,9 @@ static struct dma_async_tx_descriptor *sdma_prep_dma_cyclic(
 
 	sdmac->flags |= IMX_DMA_SG_LOOP;
 
-	if (period_len > 0xffff) {
+	if (period_len > SDMA_BD_MAX_CNT) {
 		dev_err(sdma->dev, "SDMA channel %d: maximum period size exceeded: %zu > %d\n",
-				channel, period_len, 0xffff);
+				channel, period_len, SDMA_BD_MAX_CNT);
 		goto err_bd_out;
 	}
 
@@ -1970,7 +1971,7 @@ static int sdma_probe(struct platform_device *pdev)
 	sdma->dma_device.residue_granularity = DMA_RESIDUE_GRANULARITY_SEGMENT;
 	sdma->dma_device.device_issue_pending = sdma_issue_pending;
 	sdma->dma_device.dev->dma_parms = &sdma->dma_parms;
-	dma_set_max_seg_size(sdma->dma_device.dev, 65535);
+	dma_set_max_seg_size(sdma->dma_device.dev, SDMA_BD_MAX_CNT);
 
 	platform_set_drvdata(pdev, sdma);
 
-- 
2.7.4


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

* [PATCH v3 1/3] dmaengine: imx-sdma: add SDMA_BD_MAX_CNT to replace '0xffff'
@ 2018-07-23 17:46 ` Robin Gong
  0 siblings, 0 replies; 35+ messages in thread
From: Robin Gong @ 2018-07-23 17:46 UTC (permalink / raw)
  To: linux-arm-kernel

Add macro SDMA_BD_MAX_CNT to replace '0xffff'.

Signed-off-by: Robin Gong <yibin.gong@nxp.com>
---
 drivers/dma/imx-sdma.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/drivers/dma/imx-sdma.c b/drivers/dma/imx-sdma.c
index 3b622d6..e3d5e73 100644
--- a/drivers/dma/imx-sdma.c
+++ b/drivers/dma/imx-sdma.c
@@ -185,6 +185,7 @@
  * Mode/Count of data node descriptors - IPCv2
  */
 struct sdma_mode_count {
+#define SDMA_BD_MAX_CNT	0xffff
 	u32 count   : 16; /* size of the buffer pointed by this BD */
 	u32 status  :  8; /* E,R,I,C,W,D status bits stored here */
 	u32 command :  8; /* command mostly used for channel 0 */
@@ -1344,9 +1345,9 @@ static struct dma_async_tx_descriptor *sdma_prep_slave_sg(
 
 		count = sg_dma_len(sg);
 
-		if (count > 0xffff) {
+		if (count > SDMA_BD_MAX_CNT) {
 			dev_err(sdma->dev, "SDMA channel %d: maximum bytes for sg entry exceeded: %d > %d\n",
-					channel, count, 0xffff);
+					channel, count, SDMA_BD_MAX_CNT);
 			goto err_bd_out;
 		}
 
@@ -1421,9 +1422,9 @@ static struct dma_async_tx_descriptor *sdma_prep_dma_cyclic(
 
 	sdmac->flags |= IMX_DMA_SG_LOOP;
 
-	if (period_len > 0xffff) {
+	if (period_len > SDMA_BD_MAX_CNT) {
 		dev_err(sdma->dev, "SDMA channel %d: maximum period size exceeded: %zu > %d\n",
-				channel, period_len, 0xffff);
+				channel, period_len, SDMA_BD_MAX_CNT);
 		goto err_bd_out;
 	}
 
@@ -1970,7 +1971,7 @@ static int sdma_probe(struct platform_device *pdev)
 	sdma->dma_device.residue_granularity = DMA_RESIDUE_GRANULARITY_SEGMENT;
 	sdma->dma_device.device_issue_pending = sdma_issue_pending;
 	sdma->dma_device.dev->dma_parms = &sdma->dma_parms;
-	dma_set_max_seg_size(sdma->dma_device.dev, 65535);
+	dma_set_max_seg_size(sdma->dma_device.dev, SDMA_BD_MAX_CNT);
 
 	platform_set_drvdata(pdev, sdma);
 
-- 
2.7.4

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

* [v3,2/3] dmaengine: imx-sdma: add memcpy interface
  2018-07-23 17:46 ` Robin Gong
  (?)
@ 2018-07-23 17:46 ` Robin Gong
  -1 siblings, 0 replies; 35+ messages in thread
From: Robin Gong @ 2018-07-23 17:46 UTC (permalink / raw)
  To: vkoul, dan.j.williams, s.hauer, linux
  Cc: linux-arm-kernel, kernel, dmaengine, linux-kernel, linux-imx

Add MEMCPY capability for imx-sdma driver.

Signed-off-by: Robin Gong <yibin.gong@nxp.com>
---
 drivers/dma/imx-sdma.c | 93 ++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 90 insertions(+), 3 deletions(-)

diff --git a/drivers/dma/imx-sdma.c b/drivers/dma/imx-sdma.c
index e3d5e73..b4ec2d2 100644
--- a/drivers/dma/imx-sdma.c
+++ b/drivers/dma/imx-sdma.c
@@ -342,6 +342,7 @@ struct sdma_desc {
  * @pc_from_device:	script address for those device_2_memory
  * @pc_to_device:	script address for those memory_2_device
  * @device_to_device:	script address for those device_2_device
+ * @pc_to_pc:		script address for those memory_2_memory
  * @flags:		loop mode or not
  * @per_address:	peripheral source or destination address in common case
  *                      destination address in p_2_p case
@@ -367,6 +368,7 @@ struct sdma_channel {
 	enum dma_slave_buswidth		word_size;
 	unsigned int			pc_from_device, pc_to_device;
 	unsigned int			device_to_device;
+	unsigned int                    pc_to_pc;
 	unsigned long			flags;
 	dma_addr_t			per_address, per_address2;
 	unsigned long			event_mask[2];
@@ -869,14 +871,16 @@ static void sdma_get_pc(struct sdma_channel *sdmac,
 	 * These are needed once we start to support transfers between
 	 * two peripherals or memory-to-memory transfers
 	 */
-	int per_2_per = 0;
+	int per_2_per = 0, emi_2_emi = 0;
 
 	sdmac->pc_from_device = 0;
 	sdmac->pc_to_device = 0;
 	sdmac->device_to_device = 0;
+	sdmac->pc_to_pc = 0;
 
 	switch (peripheral_type) {
 	case IMX_DMATYPE_MEMORY:
+		emi_2_emi = sdma->script_addrs->ap_2_ap_addr;
 		break;
 	case IMX_DMATYPE_DSP:
 		emi_2_per = sdma->script_addrs->bp_2_ap_addr;
@@ -949,6 +953,7 @@ static void sdma_get_pc(struct sdma_channel *sdmac,
 	sdmac->pc_from_device = per_2_emi;
 	sdmac->pc_to_device = emi_2_per;
 	sdmac->device_to_device = per_2_per;
+	sdmac->pc_to_pc = emi_2_emi;
 }
 
 static int sdma_load_context(struct sdma_channel *sdmac)
@@ -965,6 +970,8 @@ static int sdma_load_context(struct sdma_channel *sdmac)
 		load_address = sdmac->pc_from_device;
 	else if (sdmac->direction == DMA_DEV_TO_DEV)
 		load_address = sdmac->device_to_device;
+	else if (sdmac->direction == DMA_MEM_TO_MEM)
+		load_address = sdmac->pc_to_pc;
 	else
 		load_address = sdmac->pc_to_device;
 
@@ -1214,10 +1221,28 @@ static int sdma_alloc_chan_resources(struct dma_chan *chan)
 {
 	struct sdma_channel *sdmac = to_sdma_chan(chan);
 	struct imx_dma_data *data = chan->private;
+	struct imx_dma_data mem_data;
 	int prio, ret;
 
-	if (!data)
-		return -EINVAL;
+	/*
+	 * MEMCPY may never setup chan->private by filter function such as
+	 * dmatest, thus create 'struct imx_dma_data mem_data' for this case.
+	 * Please note in any other slave case, you have to setup chan->private
+	 * with 'struct imx_dma_data' in your own filter function if you want to
+	 * request dma channel by dma_request_channel() rather than
+	 * dma_request_slave_channel(). Othwise, 'MEMCPY in case?' will appear
+	 * to warn you to correct your filter function.
+	 */
+	if (!data) {
+		dev_dbg(sdmac->sdma->dev, "MEMCPY in case?\n");
+		mem_data.priority = 2;
+		mem_data.peripheral_type = IMX_DMATYPE_MEMORY;
+		mem_data.dma_request = 0;
+		mem_data.dma_request2 = 0;
+		data = &mem_data;
+
+		sdma_get_pc(sdmac, IMX_DMATYPE_MEMORY);
+	}
 
 	switch (data->priority) {
 	case DMA_PRIO_HIGH:
@@ -1307,6 +1332,10 @@ static struct sdma_desc *sdma_transfer_init(struct sdma_channel *sdmac,
 	if (sdma_alloc_bd(desc))
 		goto err_desc_out;
 
+	/* No slave_config called in MEMCPY case, so do here */
+	if (direction == DMA_MEM_TO_MEM)
+		sdma_config_ownership(sdmac, false, true, false);
+
 	if (sdma_load_context(sdmac))
 		goto err_desc_out;
 
@@ -1318,6 +1347,62 @@ static struct sdma_desc *sdma_transfer_init(struct sdma_channel *sdmac,
 	return NULL;
 }
 
+static struct dma_async_tx_descriptor *sdma_prep_memcpy(
+		struct dma_chan *chan, dma_addr_t dma_dst,
+		dma_addr_t dma_src, size_t len, unsigned long flags)
+{
+	struct sdma_channel *sdmac = to_sdma_chan(chan);
+	struct sdma_engine *sdma = sdmac->sdma;
+	int channel = sdmac->channel;
+	size_t count;
+	int i = 0, param;
+	struct sdma_buffer_descriptor *bd;
+	struct sdma_desc *desc;
+
+	if (!chan || !len)
+		return NULL;
+
+	dev_dbg(sdma->dev, "memcpy: %pad->%pad, len=%zu, channel=%d.\n",
+		&dma_src, &dma_dst, len, channel);
+
+	desc = sdma_transfer_init(sdmac, DMA_MEM_TO_MEM,
+					len / SDMA_BD_MAX_CNT + 1);
+	if (!desc)
+		return NULL;
+
+	do {
+		count = min_t(size_t, len, SDMA_BD_MAX_CNT);
+		bd = &desc->bd[i];
+		bd->buffer_addr = dma_src;
+		bd->ext_buffer_addr = dma_dst;
+		bd->mode.count = count;
+		desc->chn_count += count;
+		bd->mode.command = 0;
+
+		dma_src += count;
+		dma_dst += count;
+		len -= count;
+		i++;
+
+		param = BD_DONE | BD_EXTD | BD_CONT;
+		/* last bd */
+		if (!len) {
+			param |= BD_INTR;
+			param |= BD_LAST;
+			param &= ~BD_CONT;
+		}
+
+		dev_dbg(sdma->dev, "entry %d: count: %zd dma: 0x%x %s%s\n",
+				i, count, bd->buffer_addr,
+				param & BD_WRAP ? "wrap" : "",
+				param & BD_INTR ? " intr" : "");
+
+		bd->mode.status = param;
+	} while (len);
+
+	return vchan_tx_prep(&sdmac->vc, &desc->vd, flags);
+}
+
 static struct dma_async_tx_descriptor *sdma_prep_slave_sg(
 		struct dma_chan *chan, struct scatterlist *sgl,
 		unsigned int sg_len, enum dma_transfer_direction direction,
@@ -1903,6 +1988,7 @@ static int sdma_probe(struct platform_device *pdev)
 
 	dma_cap_set(DMA_SLAVE, sdma->dma_device.cap_mask);
 	dma_cap_set(DMA_CYCLIC, sdma->dma_device.cap_mask);
+	dma_cap_set(DMA_MEMCPY, sdma->dma_device.cap_mask);
 
 	INIT_LIST_HEAD(&sdma->dma_device.channels);
 	/* Initialize channel parameters */
@@ -1969,6 +2055,7 @@ static int sdma_probe(struct platform_device *pdev)
 	sdma->dma_device.dst_addr_widths = SDMA_DMA_BUSWIDTHS;
 	sdma->dma_device.directions = SDMA_DMA_DIRECTIONS;
 	sdma->dma_device.residue_granularity = DMA_RESIDUE_GRANULARITY_SEGMENT;
+	sdma->dma_device.device_prep_dma_memcpy = sdma_prep_memcpy;
 	sdma->dma_device.device_issue_pending = sdma_issue_pending;
 	sdma->dma_device.dev->dma_parms = &sdma->dma_parms;
 	dma_set_max_seg_size(sdma->dma_device.dev, SDMA_BD_MAX_CNT);

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

* [PATCH v3 2/3] dmaengine: imx-sdma: add memcpy interface
@ 2018-07-23 17:46 ` Robin Gong
  0 siblings, 0 replies; 35+ messages in thread
From: Robin Gong @ 2018-07-23 17:46 UTC (permalink / raw)
  To: vkoul, dan.j.williams, s.hauer, linux
  Cc: linux-arm-kernel, kernel, dmaengine, linux-kernel, linux-imx

Add MEMCPY capability for imx-sdma driver.

Signed-off-by: Robin Gong <yibin.gong@nxp.com>
---
 drivers/dma/imx-sdma.c | 93 ++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 90 insertions(+), 3 deletions(-)

diff --git a/drivers/dma/imx-sdma.c b/drivers/dma/imx-sdma.c
index e3d5e73..b4ec2d2 100644
--- a/drivers/dma/imx-sdma.c
+++ b/drivers/dma/imx-sdma.c
@@ -342,6 +342,7 @@ struct sdma_desc {
  * @pc_from_device:	script address for those device_2_memory
  * @pc_to_device:	script address for those memory_2_device
  * @device_to_device:	script address for those device_2_device
+ * @pc_to_pc:		script address for those memory_2_memory
  * @flags:		loop mode or not
  * @per_address:	peripheral source or destination address in common case
  *                      destination address in p_2_p case
@@ -367,6 +368,7 @@ struct sdma_channel {
 	enum dma_slave_buswidth		word_size;
 	unsigned int			pc_from_device, pc_to_device;
 	unsigned int			device_to_device;
+	unsigned int                    pc_to_pc;
 	unsigned long			flags;
 	dma_addr_t			per_address, per_address2;
 	unsigned long			event_mask[2];
@@ -869,14 +871,16 @@ static void sdma_get_pc(struct sdma_channel *sdmac,
 	 * These are needed once we start to support transfers between
 	 * two peripherals or memory-to-memory transfers
 	 */
-	int per_2_per = 0;
+	int per_2_per = 0, emi_2_emi = 0;
 
 	sdmac->pc_from_device = 0;
 	sdmac->pc_to_device = 0;
 	sdmac->device_to_device = 0;
+	sdmac->pc_to_pc = 0;
 
 	switch (peripheral_type) {
 	case IMX_DMATYPE_MEMORY:
+		emi_2_emi = sdma->script_addrs->ap_2_ap_addr;
 		break;
 	case IMX_DMATYPE_DSP:
 		emi_2_per = sdma->script_addrs->bp_2_ap_addr;
@@ -949,6 +953,7 @@ static void sdma_get_pc(struct sdma_channel *sdmac,
 	sdmac->pc_from_device = per_2_emi;
 	sdmac->pc_to_device = emi_2_per;
 	sdmac->device_to_device = per_2_per;
+	sdmac->pc_to_pc = emi_2_emi;
 }
 
 static int sdma_load_context(struct sdma_channel *sdmac)
@@ -965,6 +970,8 @@ static int sdma_load_context(struct sdma_channel *sdmac)
 		load_address = sdmac->pc_from_device;
 	else if (sdmac->direction == DMA_DEV_TO_DEV)
 		load_address = sdmac->device_to_device;
+	else if (sdmac->direction == DMA_MEM_TO_MEM)
+		load_address = sdmac->pc_to_pc;
 	else
 		load_address = sdmac->pc_to_device;
 
@@ -1214,10 +1221,28 @@ static int sdma_alloc_chan_resources(struct dma_chan *chan)
 {
 	struct sdma_channel *sdmac = to_sdma_chan(chan);
 	struct imx_dma_data *data = chan->private;
+	struct imx_dma_data mem_data;
 	int prio, ret;
 
-	if (!data)
-		return -EINVAL;
+	/*
+	 * MEMCPY may never setup chan->private by filter function such as
+	 * dmatest, thus create 'struct imx_dma_data mem_data' for this case.
+	 * Please note in any other slave case, you have to setup chan->private
+	 * with 'struct imx_dma_data' in your own filter function if you want to
+	 * request dma channel by dma_request_channel() rather than
+	 * dma_request_slave_channel(). Othwise, 'MEMCPY in case?' will appear
+	 * to warn you to correct your filter function.
+	 */
+	if (!data) {
+		dev_dbg(sdmac->sdma->dev, "MEMCPY in case?\n");
+		mem_data.priority = 2;
+		mem_data.peripheral_type = IMX_DMATYPE_MEMORY;
+		mem_data.dma_request = 0;
+		mem_data.dma_request2 = 0;
+		data = &mem_data;
+
+		sdma_get_pc(sdmac, IMX_DMATYPE_MEMORY);
+	}
 
 	switch (data->priority) {
 	case DMA_PRIO_HIGH:
@@ -1307,6 +1332,10 @@ static struct sdma_desc *sdma_transfer_init(struct sdma_channel *sdmac,
 	if (sdma_alloc_bd(desc))
 		goto err_desc_out;
 
+	/* No slave_config called in MEMCPY case, so do here */
+	if (direction == DMA_MEM_TO_MEM)
+		sdma_config_ownership(sdmac, false, true, false);
+
 	if (sdma_load_context(sdmac))
 		goto err_desc_out;
 
@@ -1318,6 +1347,62 @@ static struct sdma_desc *sdma_transfer_init(struct sdma_channel *sdmac,
 	return NULL;
 }
 
+static struct dma_async_tx_descriptor *sdma_prep_memcpy(
+		struct dma_chan *chan, dma_addr_t dma_dst,
+		dma_addr_t dma_src, size_t len, unsigned long flags)
+{
+	struct sdma_channel *sdmac = to_sdma_chan(chan);
+	struct sdma_engine *sdma = sdmac->sdma;
+	int channel = sdmac->channel;
+	size_t count;
+	int i = 0, param;
+	struct sdma_buffer_descriptor *bd;
+	struct sdma_desc *desc;
+
+	if (!chan || !len)
+		return NULL;
+
+	dev_dbg(sdma->dev, "memcpy: %pad->%pad, len=%zu, channel=%d.\n",
+		&dma_src, &dma_dst, len, channel);
+
+	desc = sdma_transfer_init(sdmac, DMA_MEM_TO_MEM,
+					len / SDMA_BD_MAX_CNT + 1);
+	if (!desc)
+		return NULL;
+
+	do {
+		count = min_t(size_t, len, SDMA_BD_MAX_CNT);
+		bd = &desc->bd[i];
+		bd->buffer_addr = dma_src;
+		bd->ext_buffer_addr = dma_dst;
+		bd->mode.count = count;
+		desc->chn_count += count;
+		bd->mode.command = 0;
+
+		dma_src += count;
+		dma_dst += count;
+		len -= count;
+		i++;
+
+		param = BD_DONE | BD_EXTD | BD_CONT;
+		/* last bd */
+		if (!len) {
+			param |= BD_INTR;
+			param |= BD_LAST;
+			param &= ~BD_CONT;
+		}
+
+		dev_dbg(sdma->dev, "entry %d: count: %zd dma: 0x%x %s%s\n",
+				i, count, bd->buffer_addr,
+				param & BD_WRAP ? "wrap" : "",
+				param & BD_INTR ? " intr" : "");
+
+		bd->mode.status = param;
+	} while (len);
+
+	return vchan_tx_prep(&sdmac->vc, &desc->vd, flags);
+}
+
 static struct dma_async_tx_descriptor *sdma_prep_slave_sg(
 		struct dma_chan *chan, struct scatterlist *sgl,
 		unsigned int sg_len, enum dma_transfer_direction direction,
@@ -1903,6 +1988,7 @@ static int sdma_probe(struct platform_device *pdev)
 
 	dma_cap_set(DMA_SLAVE, sdma->dma_device.cap_mask);
 	dma_cap_set(DMA_CYCLIC, sdma->dma_device.cap_mask);
+	dma_cap_set(DMA_MEMCPY, sdma->dma_device.cap_mask);
 
 	INIT_LIST_HEAD(&sdma->dma_device.channels);
 	/* Initialize channel parameters */
@@ -1969,6 +2055,7 @@ static int sdma_probe(struct platform_device *pdev)
 	sdma->dma_device.dst_addr_widths = SDMA_DMA_BUSWIDTHS;
 	sdma->dma_device.directions = SDMA_DMA_DIRECTIONS;
 	sdma->dma_device.residue_granularity = DMA_RESIDUE_GRANULARITY_SEGMENT;
+	sdma->dma_device.device_prep_dma_memcpy = sdma_prep_memcpy;
 	sdma->dma_device.device_issue_pending = sdma_issue_pending;
 	sdma->dma_device.dev->dma_parms = &sdma->dma_parms;
 	dma_set_max_seg_size(sdma->dma_device.dev, SDMA_BD_MAX_CNT);
-- 
2.7.4


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

* [PATCH v3 2/3] dmaengine: imx-sdma: add memcpy interface
@ 2018-07-23 17:46 ` Robin Gong
  0 siblings, 0 replies; 35+ messages in thread
From: Robin Gong @ 2018-07-23 17:46 UTC (permalink / raw)
  To: linux-arm-kernel

Add MEMCPY capability for imx-sdma driver.

Signed-off-by: Robin Gong <yibin.gong@nxp.com>
---
 drivers/dma/imx-sdma.c | 93 ++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 90 insertions(+), 3 deletions(-)

diff --git a/drivers/dma/imx-sdma.c b/drivers/dma/imx-sdma.c
index e3d5e73..b4ec2d2 100644
--- a/drivers/dma/imx-sdma.c
+++ b/drivers/dma/imx-sdma.c
@@ -342,6 +342,7 @@ struct sdma_desc {
  * @pc_from_device:	script address for those device_2_memory
  * @pc_to_device:	script address for those memory_2_device
  * @device_to_device:	script address for those device_2_device
+ * @pc_to_pc:		script address for those memory_2_memory
  * @flags:		loop mode or not
  * @per_address:	peripheral source or destination address in common case
  *                      destination address in p_2_p case
@@ -367,6 +368,7 @@ struct sdma_channel {
 	enum dma_slave_buswidth		word_size;
 	unsigned int			pc_from_device, pc_to_device;
 	unsigned int			device_to_device;
+	unsigned int                    pc_to_pc;
 	unsigned long			flags;
 	dma_addr_t			per_address, per_address2;
 	unsigned long			event_mask[2];
@@ -869,14 +871,16 @@ static void sdma_get_pc(struct sdma_channel *sdmac,
 	 * These are needed once we start to support transfers between
 	 * two peripherals or memory-to-memory transfers
 	 */
-	int per_2_per = 0;
+	int per_2_per = 0, emi_2_emi = 0;
 
 	sdmac->pc_from_device = 0;
 	sdmac->pc_to_device = 0;
 	sdmac->device_to_device = 0;
+	sdmac->pc_to_pc = 0;
 
 	switch (peripheral_type) {
 	case IMX_DMATYPE_MEMORY:
+		emi_2_emi = sdma->script_addrs->ap_2_ap_addr;
 		break;
 	case IMX_DMATYPE_DSP:
 		emi_2_per = sdma->script_addrs->bp_2_ap_addr;
@@ -949,6 +953,7 @@ static void sdma_get_pc(struct sdma_channel *sdmac,
 	sdmac->pc_from_device = per_2_emi;
 	sdmac->pc_to_device = emi_2_per;
 	sdmac->device_to_device = per_2_per;
+	sdmac->pc_to_pc = emi_2_emi;
 }
 
 static int sdma_load_context(struct sdma_channel *sdmac)
@@ -965,6 +970,8 @@ static int sdma_load_context(struct sdma_channel *sdmac)
 		load_address = sdmac->pc_from_device;
 	else if (sdmac->direction == DMA_DEV_TO_DEV)
 		load_address = sdmac->device_to_device;
+	else if (sdmac->direction == DMA_MEM_TO_MEM)
+		load_address = sdmac->pc_to_pc;
 	else
 		load_address = sdmac->pc_to_device;
 
@@ -1214,10 +1221,28 @@ static int sdma_alloc_chan_resources(struct dma_chan *chan)
 {
 	struct sdma_channel *sdmac = to_sdma_chan(chan);
 	struct imx_dma_data *data = chan->private;
+	struct imx_dma_data mem_data;
 	int prio, ret;
 
-	if (!data)
-		return -EINVAL;
+	/*
+	 * MEMCPY may never setup chan->private by filter function such as
+	 * dmatest, thus create 'struct imx_dma_data mem_data' for this case.
+	 * Please note in any other slave case, you have to setup chan->private
+	 * with 'struct imx_dma_data' in your own filter function if you want to
+	 * request dma channel by dma_request_channel() rather than
+	 * dma_request_slave_channel(). Othwise, 'MEMCPY in case?' will appear
+	 * to warn you to correct your filter function.
+	 */
+	if (!data) {
+		dev_dbg(sdmac->sdma->dev, "MEMCPY in case?\n");
+		mem_data.priority = 2;
+		mem_data.peripheral_type = IMX_DMATYPE_MEMORY;
+		mem_data.dma_request = 0;
+		mem_data.dma_request2 = 0;
+		data = &mem_data;
+
+		sdma_get_pc(sdmac, IMX_DMATYPE_MEMORY);
+	}
 
 	switch (data->priority) {
 	case DMA_PRIO_HIGH:
@@ -1307,6 +1332,10 @@ static struct sdma_desc *sdma_transfer_init(struct sdma_channel *sdmac,
 	if (sdma_alloc_bd(desc))
 		goto err_desc_out;
 
+	/* No slave_config called in MEMCPY case, so do here */
+	if (direction == DMA_MEM_TO_MEM)
+		sdma_config_ownership(sdmac, false, true, false);
+
 	if (sdma_load_context(sdmac))
 		goto err_desc_out;
 
@@ -1318,6 +1347,62 @@ static struct sdma_desc *sdma_transfer_init(struct sdma_channel *sdmac,
 	return NULL;
 }
 
+static struct dma_async_tx_descriptor *sdma_prep_memcpy(
+		struct dma_chan *chan, dma_addr_t dma_dst,
+		dma_addr_t dma_src, size_t len, unsigned long flags)
+{
+	struct sdma_channel *sdmac = to_sdma_chan(chan);
+	struct sdma_engine *sdma = sdmac->sdma;
+	int channel = sdmac->channel;
+	size_t count;
+	int i = 0, param;
+	struct sdma_buffer_descriptor *bd;
+	struct sdma_desc *desc;
+
+	if (!chan || !len)
+		return NULL;
+
+	dev_dbg(sdma->dev, "memcpy: %pad->%pad, len=%zu, channel=%d.\n",
+		&dma_src, &dma_dst, len, channel);
+
+	desc = sdma_transfer_init(sdmac, DMA_MEM_TO_MEM,
+					len / SDMA_BD_MAX_CNT + 1);
+	if (!desc)
+		return NULL;
+
+	do {
+		count = min_t(size_t, len, SDMA_BD_MAX_CNT);
+		bd = &desc->bd[i];
+		bd->buffer_addr = dma_src;
+		bd->ext_buffer_addr = dma_dst;
+		bd->mode.count = count;
+		desc->chn_count += count;
+		bd->mode.command = 0;
+
+		dma_src += count;
+		dma_dst += count;
+		len -= count;
+		i++;
+
+		param = BD_DONE | BD_EXTD | BD_CONT;
+		/* last bd */
+		if (!len) {
+			param |= BD_INTR;
+			param |= BD_LAST;
+			param &= ~BD_CONT;
+		}
+
+		dev_dbg(sdma->dev, "entry %d: count: %zd dma: 0x%x %s%s\n",
+				i, count, bd->buffer_addr,
+				param & BD_WRAP ? "wrap" : "",
+				param & BD_INTR ? " intr" : "");
+
+		bd->mode.status = param;
+	} while (len);
+
+	return vchan_tx_prep(&sdmac->vc, &desc->vd, flags);
+}
+
 static struct dma_async_tx_descriptor *sdma_prep_slave_sg(
 		struct dma_chan *chan, struct scatterlist *sgl,
 		unsigned int sg_len, enum dma_transfer_direction direction,
@@ -1903,6 +1988,7 @@ static int sdma_probe(struct platform_device *pdev)
 
 	dma_cap_set(DMA_SLAVE, sdma->dma_device.cap_mask);
 	dma_cap_set(DMA_CYCLIC, sdma->dma_device.cap_mask);
+	dma_cap_set(DMA_MEMCPY, sdma->dma_device.cap_mask);
 
 	INIT_LIST_HEAD(&sdma->dma_device.channels);
 	/* Initialize channel parameters */
@@ -1969,6 +2055,7 @@ static int sdma_probe(struct platform_device *pdev)
 	sdma->dma_device.dst_addr_widths = SDMA_DMA_BUSWIDTHS;
 	sdma->dma_device.directions = SDMA_DMA_DIRECTIONS;
 	sdma->dma_device.residue_granularity = DMA_RESIDUE_GRANULARITY_SEGMENT;
+	sdma->dma_device.device_prep_dma_memcpy = sdma_prep_memcpy;
 	sdma->dma_device.device_issue_pending = sdma_issue_pending;
 	sdma->dma_device.dev->dma_parms = &sdma->dma_parms;
 	dma_set_max_seg_size(sdma->dma_device.dev, SDMA_BD_MAX_CNT);
-- 
2.7.4

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

* [v3,3/3] dmaengine: imx-sdma: allocate max 20 bds for one transfer
  2018-07-23 17:46 ` Robin Gong
  (?)
@ 2018-07-23 17:46 ` Robin Gong
  -1 siblings, 0 replies; 35+ messages in thread
From: Robin Gong @ 2018-07-23 17:46 UTC (permalink / raw)
  To: vkoul, dan.j.williams, s.hauer, linux
  Cc: linux-arm-kernel, kernel, dmaengine, linux-kernel, linux-imx

If multi-bds used in one transfer, all bds should be consisten
memory.To easily follow it, enlarge the dma pool size into 20 bds,
and it will report error if the number of bds is over than 20. For
dmatest, the max count for single transfer is NUM_BD *
SDMA_BD_MAX_CNT = 20 * 65535 = ~1.28MB.

Signed-off-by: Robin Gong <yibin.gong@nxp.com>
---
 drivers/dma/imx-sdma.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/drivers/dma/imx-sdma.c b/drivers/dma/imx-sdma.c
index b4ec2d2..5973489 100644
--- a/drivers/dma/imx-sdma.c
+++ b/drivers/dma/imx-sdma.c
@@ -298,6 +298,15 @@ struct sdma_context_data {
 	u32  scratch7;
 } __attribute__ ((packed));
 
+/*
+ * All bds in one transfer should be consitent on SDMA. To easily follow it,just
+ * set the dma pool size as the enough bds. For example, in dmatest case, the
+ * max 20 bds means the max for single transfer is NUM_BD * SDMA_BD_MAX_CNT = 20
+ * * 65535 = ~1.28MB. 20 bds supposed to be enough basically.If it's still not
+ * enough in some specific cases, enlarge it here.Warning message would also
+ * appear if the bd numbers is over than 20.
+ */
+#define NUM_BD 20
 
 struct sdma_engine;
 
@@ -1273,7 +1282,7 @@ static int sdma_alloc_chan_resources(struct dma_chan *chan)
 		goto disable_clk_ahb;
 
 	sdmac->bd_pool = dma_pool_create("bd_pool", chan->device->dev,
-				sizeof(struct sdma_buffer_descriptor),
+				NUM_BD * sizeof(struct sdma_buffer_descriptor),
 				32, 0);
 
 	return 0;
@@ -1314,6 +1323,12 @@ static struct sdma_desc *sdma_transfer_init(struct sdma_channel *sdmac,
 {
 	struct sdma_desc *desc;
 
+	if (bds > NUM_BD) {
+		dev_err(sdmac->sdma->dev, "%d bds exceed the max %d\n",
+			bds, NUM_BD);
+		goto err_out;
+	}
+
 	desc = kzalloc((sizeof(*desc)), GFP_NOWAIT);
 	if (!desc)
 		goto err_out;

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

* [PATCH v3 3/3] dmaengine: imx-sdma: allocate max 20 bds for one transfer
@ 2018-07-23 17:46 ` Robin Gong
  0 siblings, 0 replies; 35+ messages in thread
From: Robin Gong @ 2018-07-23 17:46 UTC (permalink / raw)
  To: vkoul, dan.j.williams, s.hauer, linux
  Cc: linux-arm-kernel, kernel, dmaengine, linux-kernel, linux-imx

If multi-bds used in one transfer, all bds should be consisten
memory.To easily follow it, enlarge the dma pool size into 20 bds,
and it will report error if the number of bds is over than 20. For
dmatest, the max count for single transfer is NUM_BD *
SDMA_BD_MAX_CNT = 20 * 65535 = ~1.28MB.

Signed-off-by: Robin Gong <yibin.gong@nxp.com>
---
 drivers/dma/imx-sdma.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/drivers/dma/imx-sdma.c b/drivers/dma/imx-sdma.c
index b4ec2d2..5973489 100644
--- a/drivers/dma/imx-sdma.c
+++ b/drivers/dma/imx-sdma.c
@@ -298,6 +298,15 @@ struct sdma_context_data {
 	u32  scratch7;
 } __attribute__ ((packed));
 
+/*
+ * All bds in one transfer should be consitent on SDMA. To easily follow it,just
+ * set the dma pool size as the enough bds. For example, in dmatest case, the
+ * max 20 bds means the max for single transfer is NUM_BD * SDMA_BD_MAX_CNT = 20
+ * * 65535 = ~1.28MB. 20 bds supposed to be enough basically.If it's still not
+ * enough in some specific cases, enlarge it here.Warning message would also
+ * appear if the bd numbers is over than 20.
+ */
+#define NUM_BD 20
 
 struct sdma_engine;
 
@@ -1273,7 +1282,7 @@ static int sdma_alloc_chan_resources(struct dma_chan *chan)
 		goto disable_clk_ahb;
 
 	sdmac->bd_pool = dma_pool_create("bd_pool", chan->device->dev,
-				sizeof(struct sdma_buffer_descriptor),
+				NUM_BD * sizeof(struct sdma_buffer_descriptor),
 				32, 0);
 
 	return 0;
@@ -1314,6 +1323,12 @@ static struct sdma_desc *sdma_transfer_init(struct sdma_channel *sdmac,
 {
 	struct sdma_desc *desc;
 
+	if (bds > NUM_BD) {
+		dev_err(sdmac->sdma->dev, "%d bds exceed the max %d\n",
+			bds, NUM_BD);
+		goto err_out;
+	}
+
 	desc = kzalloc((sizeof(*desc)), GFP_NOWAIT);
 	if (!desc)
 		goto err_out;
-- 
2.7.4


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

* [PATCH v3 3/3] dmaengine: imx-sdma: allocate max 20 bds for one transfer
@ 2018-07-23 17:46 ` Robin Gong
  0 siblings, 0 replies; 35+ messages in thread
From: Robin Gong @ 2018-07-23 17:46 UTC (permalink / raw)
  To: linux-arm-kernel

If multi-bds used in one transfer, all bds should be consisten
memory.To easily follow it, enlarge the dma pool size into 20 bds,
and it will report error if the number of bds is over than 20. For
dmatest, the max count for single transfer is NUM_BD *
SDMA_BD_MAX_CNT = 20 * 65535 = ~1.28MB.

Signed-off-by: Robin Gong <yibin.gong@nxp.com>
---
 drivers/dma/imx-sdma.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/drivers/dma/imx-sdma.c b/drivers/dma/imx-sdma.c
index b4ec2d2..5973489 100644
--- a/drivers/dma/imx-sdma.c
+++ b/drivers/dma/imx-sdma.c
@@ -298,6 +298,15 @@ struct sdma_context_data {
 	u32  scratch7;
 } __attribute__ ((packed));
 
+/*
+ * All bds in one transfer should be consitent on SDMA. To easily follow it,just
+ * set the dma pool size as the enough bds. For example, in dmatest case, the
+ * max 20 bds means the max for single transfer is NUM_BD * SDMA_BD_MAX_CNT = 20
+ * * 65535 = ~1.28MB. 20 bds supposed to be enough basically.If it's still not
+ * enough in some specific cases, enlarge it here.Warning message would also
+ * appear if the bd numbers is over than 20.
+ */
+#define NUM_BD 20
 
 struct sdma_engine;
 
@@ -1273,7 +1282,7 @@ static int sdma_alloc_chan_resources(struct dma_chan *chan)
 		goto disable_clk_ahb;
 
 	sdmac->bd_pool = dma_pool_create("bd_pool", chan->device->dev,
-				sizeof(struct sdma_buffer_descriptor),
+				NUM_BD * sizeof(struct sdma_buffer_descriptor),
 				32, 0);
 
 	return 0;
@@ -1314,6 +1323,12 @@ static struct sdma_desc *sdma_transfer_init(struct sdma_channel *sdmac,
 {
 	struct sdma_desc *desc;
 
+	if (bds > NUM_BD) {
+		dev_err(sdmac->sdma->dev, "%d bds exceed the max %d\n",
+			bds, NUM_BD);
+		goto err_out;
+	}
+
 	desc = kzalloc((sizeof(*desc)), GFP_NOWAIT);
 	if (!desc)
 		goto err_out;
-- 
2.7.4

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

* [v3,3/3] dmaengine: imx-sdma: allocate max 20 bds for one transfer
  2018-07-23 13:55 ` Robin Gong
  (?)
@ 2018-07-24  9:22 ` Lucas Stach
  -1 siblings, 0 replies; 35+ messages in thread
From: Lucas Stach @ 2018-07-24  9:22 UTC (permalink / raw)
  To: Robin Gong, vkoul, dan.j.williams, s.hauer, linux
  Cc: dmaengine, dl-linux-imx, kernel, linux-arm-kernel, linux-kernel

Am Montag, den 23.07.2018, 13:55 +0000 schrieb Robin Gong:
> > -----Original Message-----
> > From: Lucas Stach [mailto:l.stach@pengutronix.de]
> > Sent: 2018年7月23日 18:54
> > To: Robin Gong <yibin.gong@nxp.com>; vkoul@kernel.org;
> > dan.j.williams@intel.com; s.hauer@pengutronix.de; linux@armlinux.or
> > g.uk
> > Cc: dmaengine@vger.kernel.org; dl-linux-imx <linux-imx@nxp.com>;
> > kernel@pengutronix.de; linux-arm-kernel@lists.infradead.org;
> > linux-kernel@vger.kernel.org
> > Subject: Re: [PATCH v3 3/3] dmaengine: imx-sdma: allocate max 20
> > bds for one
> > transfer
> > 
> > Am Dienstag, den 24.07.2018, 01:46 +0800 schrieb Robin Gong:
> > > If multi-bds used in one transfer, all bds should be consisten
> > > memory.To easily follow it, enlarge the dma pool size into 20
> > > bds, and
> > > it will report error if the number of bds is over than 20. For
> > > dmatest, the max count for single transfer is NUM_BD *
> > 
> > SDMA_BD_MAX_CNT
> > > = 20 * 65535 = ~1.28MB.
> > 
> > Both the commit message and the comment need a lot more care to
> > actually
> > tell what this commit is trying to achieve. Currently I don't
> > follow at all. What
> > does "consisten" mean? Do you mean BDs should be contiguous in
> > memory?
> 
> Yes, BDs should be contiguous  one by one in memory.

Okay, but this isn't what the code change does. By increasing the size
parameter of the dma pool you just allocate 20 times as much memory as
needed for each BD. So actually the BDs end up being very non-
contiguous in memory as there are now holes of 19 BD sizes between the
start of each BD.

So something isn't right with this change.

Regards,
Lucas

> > 
> > What do you gain by over-allocating each BD by a factor of 20?
> 
> I guess dma_pool_alloc will return error in such case, and then cause
> dma setup
> transfer failure.
> > 
> > Regards,
> > Lucas
> > 
> > > Signed-off-by: Robin Gong <yibin.gong@nxp.com>
> > > ---
> > >  drivers/dma/imx-sdma.c | 17 ++++++++++++++++-
> > >  1 file changed, 16 insertions(+), 1 deletion(-)
> > > 
> > > diff --git a/drivers/dma/imx-sdma.c b/drivers/dma/imx-sdma.c
> > > index
> > > b4ec2d2..5973489 100644
> > > --- a/drivers/dma/imx-sdma.c
> > > +++ b/drivers/dma/imx-sdma.c
> > > @@ -298,6 +298,15 @@ struct sdma_context_data {
> > > >  	u32  scratch7;
> > > 
> > >  } __attribute__ ((packed));
> > > 
> > > +/*
> > > + * All bds in one transfer should be consitent on SDMA. To
> > > easily
> > > +follow it,just
> > > + * set the dma pool size as the enough bds. For example, in
> > > dmatest
> > > +case, the
> > > + * max 20 bds means the max for single transfer is NUM_BD *
> > > +SDMA_BD_MAX_CNT = 20
> > > + * * 65535 = ~1.28MB. 20 bds supposed to be enough basically.If
> > > it's
> > > +still not
> > > + * enough in some specific cases, enlarge it here.Warning
> > > message
> > > +would also
> > > + * appear if the bd numbers is over than 20.
> > > + */
> > > +#define NUM_BD 20
> > > 
> > >  struct sdma_engine;
> > > 
> > > @@ -1273,7 +1282,7 @@ static int sdma_alloc_chan_resources(struct
> > > dma_chan *chan)
> > > >  		goto disable_clk_ahb;
> > > >  	sdmac->bd_pool = dma_pool_create("bd_pool", chan-
> > > > >device->dev,
> > > > -				sizeof(struct
> > > > sdma_buffer_descriptor),
> > > > +				NUM_BD * sizeof(struct
> > > > sdma_buffer_descriptor),
> > > >  				32, 0);
> > > >  	return 0;
> > > 
> > > @@ -1314,6 +1323,12 @@ static struct sdma_desc
> > > *sdma_transfer_init(struct sdma_channel *sdmac,
> > >  {
> > > >  	struct sdma_desc *desc;
> > > > +	if (bds > NUM_BD) {
> > > > +		dev_err(sdmac->sdma->dev, "%d bds exceed the
> > > > max %d\n",
> > > > +			bds, NUM_BD);
> > > > +		goto err_out;
> > > > +	}
> > > 
> > > +
> > > >  	desc = kzalloc((sizeof(*desc)), GFP_NOWAIT);
> > > >  	if (!desc)
> > > >  		goto err_out;
---
To unsubscribe from this list: send the line "unsubscribe dmaengine" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH v3 3/3] dmaengine: imx-sdma: allocate max 20 bds for one transfer
@ 2018-07-24  9:22 ` Lucas Stach
  0 siblings, 0 replies; 35+ messages in thread
From: Lucas Stach @ 2018-07-24  9:22 UTC (permalink / raw)
  To: Robin Gong, vkoul, dan.j.williams, s.hauer, linux
  Cc: dmaengine, dl-linux-imx, kernel, linux-arm-kernel, linux-kernel

Am Montag, den 23.07.2018, 13:55 +0000 schrieb Robin Gong:
> > -----Original Message-----
> > From: Lucas Stach [mailto:l.stach@pengutronix.de]
> > Sent: 2018年7月23日 18:54
> > To: Robin Gong <yibin.gong@nxp.com>; vkoul@kernel.org;
> > dan.j.williams@intel.com; s.hauer@pengutronix.de; linux@armlinux.or
> > g.uk
> > Cc: dmaengine@vger.kernel.org; dl-linux-imx <linux-imx@nxp.com>;
> > kernel@pengutronix.de; linux-arm-kernel@lists.infradead.org;
> > linux-kernel@vger.kernel.org
> > Subject: Re: [PATCH v3 3/3] dmaengine: imx-sdma: allocate max 20
> > bds for one
> > transfer
> > 
> > Am Dienstag, den 24.07.2018, 01:46 +0800 schrieb Robin Gong:
> > > If multi-bds used in one transfer, all bds should be consisten
> > > memory.To easily follow it, enlarge the dma pool size into 20
> > > bds, and
> > > it will report error if the number of bds is over than 20. For
> > > dmatest, the max count for single transfer is NUM_BD *
> > 
> > SDMA_BD_MAX_CNT
> > > = 20 * 65535 = ~1.28MB.
> > 
> > Both the commit message and the comment need a lot more care to
> > actually
> > tell what this commit is trying to achieve. Currently I don't
> > follow at all. What
> > does "consisten" mean? Do you mean BDs should be contiguous in
> > memory?
> 
> Yes, BDs should be contiguous  one by one in memory.

Okay, but this isn't what the code change does. By increasing the size
parameter of the dma pool you just allocate 20 times as much memory as
needed for each BD. So actually the BDs end up being very non-
contiguous in memory as there are now holes of 19 BD sizes between the
start of each BD.

So something isn't right with this change.

Regards,
Lucas

> > 
> > What do you gain by over-allocating each BD by a factor of 20?
> 
> I guess dma_pool_alloc will return error in such case, and then cause
> dma setup
> transfer failure.
> > 
> > Regards,
> > Lucas
> > 
> > > Signed-off-by: Robin Gong <yibin.gong@nxp.com>
> > > ---
> > >  drivers/dma/imx-sdma.c | 17 ++++++++++++++++-
> > >  1 file changed, 16 insertions(+), 1 deletion(-)
> > > 
> > > diff --git a/drivers/dma/imx-sdma.c b/drivers/dma/imx-sdma.c
> > > index
> > > b4ec2d2..5973489 100644
> > > --- a/drivers/dma/imx-sdma.c
> > > +++ b/drivers/dma/imx-sdma.c
> > > @@ -298,6 +298,15 @@ struct sdma_context_data {
> > > >  	u32  scratch7;
> > > 
> > >  } __attribute__ ((packed));
> > > 
> > > +/*
> > > + * All bds in one transfer should be consitent on SDMA. To
> > > easily
> > > +follow it,just
> > > + * set the dma pool size as the enough bds. For example, in
> > > dmatest
> > > +case, the
> > > + * max 20 bds means the max for single transfer is NUM_BD *
> > > +SDMA_BD_MAX_CNT = 20
> > > + * * 65535 = ~1.28MB. 20 bds supposed to be enough basically.If
> > > it's
> > > +still not
> > > + * enough in some specific cases, enlarge it here.Warning
> > > message
> > > +would also
> > > + * appear if the bd numbers is over than 20.
> > > + */
> > > +#define NUM_BD 20
> > > 
> > >  struct sdma_engine;
> > > 
> > > @@ -1273,7 +1282,7 @@ static int sdma_alloc_chan_resources(struct
> > > dma_chan *chan)
> > > >  		goto disable_clk_ahb;
> > > >  	sdmac->bd_pool = dma_pool_create("bd_pool", chan-
> > > > >device->dev,
> > > > -				sizeof(struct
> > > > sdma_buffer_descriptor),
> > > > +				NUM_BD * sizeof(struct
> > > > sdma_buffer_descriptor),
> > > >  				32, 0);
> > > >  	return 0;
> > > 
> > > @@ -1314,6 +1323,12 @@ static struct sdma_desc
> > > *sdma_transfer_init(struct sdma_channel *sdmac,
> > >  {
> > > >  	struct sdma_desc *desc;
> > > > +	if (bds > NUM_BD) {
> > > > +		dev_err(sdmac->sdma->dev, "%d bds exceed the
> > > > max %d\n",
> > > > +			bds, NUM_BD);
> > > > +		goto err_out;
> > > > +	}
> > > 
> > > +
> > > >  	desc = kzalloc((sizeof(*desc)), GFP_NOWAIT);
> > > >  	if (!desc)
> > > >  		goto err_out;

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

* [PATCH v3 3/3] dmaengine: imx-sdma: allocate max 20 bds for one transfer
@ 2018-07-24  9:22 ` Lucas Stach
  0 siblings, 0 replies; 35+ messages in thread
From: Lucas Stach @ 2018-07-24  9:22 UTC (permalink / raw)
  To: linux-arm-kernel

Am Montag, den 23.07.2018, 13:55 +0000 schrieb Robin Gong:
> > -----Original Message-----
> > From: Lucas Stach [mailto:l.stach at pengutronix.de]
> > Sent: 2018?7?23? 18:54
> > To: Robin Gong <yibin.gong@nxp.com>; vkoul at kernel.org;
> > dan.j.williams at intel.com; s.hauer at pengutronix.de; linux at armlinux.or
> > g.uk
> > Cc: dmaengine at vger.kernel.org; dl-linux-imx <linux-imx@nxp.com>;
> > kernel at pengutronix.de; linux-arm-kernel at lists.infradead.org;
> > linux-kernel at vger.kernel.org
> > Subject: Re: [PATCH v3 3/3] dmaengine: imx-sdma: allocate max 20
> > bds for one
> > transfer
> > 
> > Am Dienstag, den 24.07.2018, 01:46 +0800 schrieb Robin Gong:
> > > If multi-bds used in one transfer, all bds should be consisten
> > > memory.To easily follow it, enlarge the dma pool size into 20
> > > bds, and
> > > it will report error if the number of bds is over than 20. For
> > > dmatest, the max count for single transfer is NUM_BD *
> > 
> > SDMA_BD_MAX_CNT
> > > = 20 * 65535 = ~1.28MB.
> > 
> > Both the commit message and the comment need a lot more care to
> > actually
> > tell what this commit is trying to achieve. Currently I don't
> > follow at all. What
> > does "consisten" mean? Do you mean BDs should be contiguous in
> > memory?
> 
> Yes, BDs should be contiguous??one by one in memory.

Okay, but this isn't what the code change does. By increasing the size
parameter of the dma pool you just allocate 20 times as much memory as
needed for each BD. So actually the BDs end up being very non-
contiguous in memory as there are now holes of 19 BD sizes between the
start of each BD.

So something isn't right with this change.

Regards,
Lucas

> > 
> > What do you gain by over-allocating each BD by a factor of 20?
> 
> I guess dma_pool_alloc will return error in such case, and then cause
> dma setup
> transfer failure.
> > 
> > Regards,
> > Lucas
> > 
> > > Signed-off-by: Robin Gong <yibin.gong@nxp.com>
> > > ---
> > > ?drivers/dma/imx-sdma.c | 17 ++++++++++++++++-
> > > ?1 file changed, 16 insertions(+), 1 deletion(-)
> > > 
> > > diff --git a/drivers/dma/imx-sdma.c b/drivers/dma/imx-sdma.c
> > > index
> > > b4ec2d2..5973489 100644
> > > --- a/drivers/dma/imx-sdma.c
> > > +++ b/drivers/dma/imx-sdma.c
> > > @@ -298,6 +298,15 @@ struct sdma_context_data {
> > > > ?	u32??scratch7;
> > > 
> > > ?} __attribute__ ((packed));
> > > 
> > > +/*
> > > + * All bds in one transfer should be consitent on SDMA. To
> > > easily
> > > +follow it,just
> > > + * set the dma pool size as the enough bds. For example, in
> > > dmatest
> > > +case, the
> > > + * max 20 bds means the max for single transfer is NUM_BD *
> > > +SDMA_BD_MAX_CNT = 20
> > > + * * 65535 = ~1.28MB. 20 bds supposed to be enough basically.If
> > > it's
> > > +still not
> > > + * enough in some specific cases, enlarge it here.Warning
> > > message
> > > +would also
> > > + * appear if the bd numbers is over than 20.
> > > + */
> > > +#define NUM_BD 20
> > > 
> > > ?struct sdma_engine;
> > > 
> > > @@ -1273,7 +1282,7 @@ static int sdma_alloc_chan_resources(struct
> > > dma_chan *chan)
> > > > ?		goto disable_clk_ahb;
> > > > ?	sdmac->bd_pool = dma_pool_create("bd_pool", chan-
> > > > >device->dev,
> > > > -				sizeof(struct
> > > > sdma_buffer_descriptor),
> > > > +				NUM_BD * sizeof(struct
> > > > sdma_buffer_descriptor),
> > > > ?				32, 0);
> > > > ?	return 0;
> > > 
> > > @@ -1314,6 +1323,12 @@ static struct sdma_desc
> > > *sdma_transfer_init(struct sdma_channel *sdmac,
> > > ?{
> > > > ?	struct sdma_desc *desc;
> > > > +	if (bds > NUM_BD) {
> > > > +		dev_err(sdmac->sdma->dev, "%d bds exceed the
> > > > max %d\n",
> > > > +			bds, NUM_BD);
> > > > +		goto err_out;
> > > > +	}
> > > 
> > > +
> > > > ?	desc = kzalloc((sizeof(*desc)), GFP_NOWAIT);
> > > > ?	if (!desc)
> > > > ?		goto err_out;

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

* [v3,3/3] dmaengine: imx-sdma: allocate max 20 bds for one transfer
  2018-07-24  9:22 ` Lucas Stach
  (?)
@ 2018-07-25  1:24 ` Robin Gong
  -1 siblings, 0 replies; 35+ messages in thread
From: Robin Gong @ 2018-07-25  1:24 UTC (permalink / raw)
  To: Lucas Stach, vkoul, dan.j.williams, s.hauer, linux
  Cc: dmaengine, dl-linux-imx, kernel, linux-arm-kernel, linux-kernel

> -----Original Message-----
> From: Lucas Stach [mailto:l.stach@pengutronix.de]
> Sent: 2018年7月24日 17:22
> To: Robin Gong <yibin.gong@nxp.com>; vkoul@kernel.org;
> dan.j.williams@intel.com; s.hauer@pengutronix.de; linux@armlinux.org.uk
> Cc: dmaengine@vger.kernel.org; dl-linux-imx <linux-imx@nxp.com>;
> kernel@pengutronix.de; linux-arm-kernel@lists.infradead.org;
> linux-kernel@vger.kernel.org
> Subject: Re: [PATCH v3 3/3] dmaengine: imx-sdma: allocate max 20 bds for one
> transfer
> 
> Am Montag, den 23.07.2018, 13:55 +0000 schrieb Robin Gong:
> > > -----Original Message-----
> > > From: Lucas Stach [mailto:l.stach@pengutronix.de]
> > > Sent: 2018年7月23日 18:54
> > > To: Robin Gong <yibin.gong@nxp.com>; vkoul@kernel.org;
> > > dan.j.williams@intel.com; s.hauer@pengutronix.de; linux@armlinux.or
> > > g.uk
> > > Cc: dmaengine@vger.kernel.org; dl-linux-imx <linux-imx@nxp.com>;
> > > kernel@pengutronix.de; linux-arm-kernel@lists.infradead.org;
> > > linux-kernel@vger.kernel.org
> > > Subject: Re: [PATCH v3 3/3] dmaengine: imx-sdma: allocate max 20 bds
> > > for one transfer
> > >
> > > Am Dienstag, den 24.07.2018, 01:46 +0800 schrieb Robin Gong:
> > > > If multi-bds used in one transfer, all bds should be consisten
> > > > memory.To easily follow it, enlarge the dma pool size into 20 bds,
> > > > and it will report error if the number of bds is over than 20. For
> > > > dmatest, the max count for single transfer is NUM_BD *
> > >
> > > SDMA_BD_MAX_CNT
> > > > = 20 * 65535 = ~1.28MB.
> > >
> > > Both the commit message and the comment need a lot more care to
> > > actually tell what this commit is trying to achieve. Currently I
> > > don't follow at all. What does "consisten" mean? Do you mean BDs
> > > should be contiguous in memory?
> >
> > Yes, BDs should be contiguous  one by one in memory.
> 
> Okay, but this isn't what the code change does. By increasing the size
> parameter of the dma pool you just allocate 20 times as much memory as
> needed for each BD. So actually the BDs end up being very non- contiguous in
> memory as there are now holes of 19 BD sizes between the start of each BD.
Please notice only allocate bds memory from dma pool one time even in multi bds.
That's different with the common use case that allocate memory from dma pool everytime
for every bd. Why do this is to make sure all bd memory is contiguous for single transfer
whatever single bd or multi-bds, since two call dma_pool_alloc() can't promise the address
is contiguous especially for multi thread case such as dmatest 'threads_per_chan = 5'. You
can change to ' norandom=true ' and ' test_buf_size = 163840' in dmatest.c to look what
issue coming without this patch.
> 
> So something isn't right with this change.
I think this patch is the easy way to resolve the bd contiguous issue, but the cost is to
allocate more dma pool memory which may not used.
> 
> Regards,
> Lucas
> 
> > >
> > > What do you gain by over-allocating each BD by a factor of 20?
> >
> > I guess dma_pool_alloc will return error in such case, and then cause
> > dma setup transfer failure.
> > >
> > > Regards,
> > > Lucas
> > >
> > > > Signed-off-by: Robin Gong <yibin.gong@nxp.com>
> > > > ---
> > > >  drivers/dma/imx-sdma.c | 17 ++++++++++++++++-
> > > >  1 file changed, 16 insertions(+), 1 deletion(-)
> > > >
> > > > diff --git a/drivers/dma/imx-sdma.c b/drivers/dma/imx-sdma.c index
> > > > b4ec2d2..5973489 100644
> > > > --- a/drivers/dma/imx-sdma.c
> > > > +++ b/drivers/dma/imx-sdma.c
> > > > @@ -298,6 +298,15 @@ struct sdma_context_data {
> > > > >  	u32  scratch7;
> > > >
> > > >  } __attribute__ ((packed));
> > > >
> > > > +/*
> > > > + * All bds in one transfer should be consitent on SDMA. To
> > > > easily
> > > > +follow it,just
> > > > + * set the dma pool size as the enough bds. For example, in
> > > > dmatest
> > > > +case, the
> > > > + * max 20 bds means the max for single transfer is NUM_BD *
> > > > +SDMA_BD_MAX_CNT = 20
> > > > + * * 65535 = ~1.28MB. 20 bds supposed to be enough basically.If
> > > > it's
> > > > +still not
> > > > + * enough in some specific cases, enlarge it here.Warning
> > > > message
> > > > +would also
> > > > + * appear if the bd numbers is over than 20.
> > > > + */
> > > > +#define NUM_BD 20
> > > >
> > > >  struct sdma_engine;
> > > >
> > > > @@ -1273,7 +1282,7 @@ static int sdma_alloc_chan_resources(struct
> > > > dma_chan *chan)
> > > > >  		goto disable_clk_ahb;
> > > > >  	sdmac->bd_pool = dma_pool_create("bd_pool", chan-
> > > > > >device->dev,
> > > > > -				sizeof(struct
> > > > > sdma_buffer_descriptor),
> > > > > +				NUM_BD * sizeof(struct
> > > > > sdma_buffer_descriptor),
> > > > >  				32, 0);
> > > > >  	return 0;
> > > >
> > > > @@ -1314,6 +1323,12 @@ static struct sdma_desc
> > > > *sdma_transfer_init(struct sdma_channel *sdmac,
> > > >  {
> > > > >  	struct sdma_desc *desc;
> > > > > +	if (bds > NUM_BD) {
> > > > > +		dev_err(sdmac->sdma->dev, "%d bds exceed the
> > > > > max %d\n",
> > > > > +			bds, NUM_BD);
> > > > > +		goto err_out;
> > > > > +	}
> > > >
> > > > +
> > > > >  	desc = kzalloc((sizeof(*desc)), GFP_NOWAIT);
> > > > >  	if (!desc)
> > > > >  		goto err_out;

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

* RE: [PATCH v3 3/3] dmaengine: imx-sdma: allocate max 20 bds for one transfer
@ 2018-07-25  1:24 ` Robin Gong
  0 siblings, 0 replies; 35+ messages in thread
From: Robin Gong @ 2018-07-25  1:24 UTC (permalink / raw)
  To: Lucas Stach, vkoul, dan.j.williams, s.hauer, linux
  Cc: dmaengine, dl-linux-imx, kernel, linux-arm-kernel, linux-kernel

> -----Original Message-----
> From: Lucas Stach [mailto:l.stach@pengutronix.de]
> Sent: 2018年7月24日 17:22
> To: Robin Gong <yibin.gong@nxp.com>; vkoul@kernel.org;
> dan.j.williams@intel.com; s.hauer@pengutronix.de; linux@armlinux.org.uk
> Cc: dmaengine@vger.kernel.org; dl-linux-imx <linux-imx@nxp.com>;
> kernel@pengutronix.de; linux-arm-kernel@lists.infradead.org;
> linux-kernel@vger.kernel.org
> Subject: Re: [PATCH v3 3/3] dmaengine: imx-sdma: allocate max 20 bds for one
> transfer
> 
> Am Montag, den 23.07.2018, 13:55 +0000 schrieb Robin Gong:
> > > -----Original Message-----
> > > From: Lucas Stach [mailto:l.stach@pengutronix.de]
> > > Sent: 2018年7月23日 18:54
> > > To: Robin Gong <yibin.gong@nxp.com>; vkoul@kernel.org;
> > > dan.j.williams@intel.com; s.hauer@pengutronix.de; linux@armlinux.or
> > > g.uk
> > > Cc: dmaengine@vger.kernel.org; dl-linux-imx <linux-imx@nxp.com>;
> > > kernel@pengutronix.de; linux-arm-kernel@lists.infradead.org;
> > > linux-kernel@vger.kernel.org
> > > Subject: Re: [PATCH v3 3/3] dmaengine: imx-sdma: allocate max 20 bds
> > > for one transfer
> > >
> > > Am Dienstag, den 24.07.2018, 01:46 +0800 schrieb Robin Gong:
> > > > If multi-bds used in one transfer, all bds should be consisten
> > > > memory.To easily follow it, enlarge the dma pool size into 20 bds,
> > > > and it will report error if the number of bds is over than 20. For
> > > > dmatest, the max count for single transfer is NUM_BD *
> > >
> > > SDMA_BD_MAX_CNT
> > > > = 20 * 65535 = ~1.28MB.
> > >
> > > Both the commit message and the comment need a lot more care to
> > > actually tell what this commit is trying to achieve. Currently I
> > > don't follow at all. What does "consisten" mean? Do you mean BDs
> > > should be contiguous in memory?
> >
> > Yes, BDs should be contiguous  one by one in memory.
> 
> Okay, but this isn't what the code change does. By increasing the size
> parameter of the dma pool you just allocate 20 times as much memory as
> needed for each BD. So actually the BDs end up being very non- contiguous in
> memory as there are now holes of 19 BD sizes between the start of each BD.
Please notice only allocate bds memory from dma pool one time even in multi bds.
That's different with the common use case that allocate memory from dma pool everytime
for every bd. Why do this is to make sure all bd memory is contiguous for single transfer
whatever single bd or multi-bds, since two call dma_pool_alloc() can't promise the address
is contiguous especially for multi thread case such as dmatest 'threads_per_chan = 5'. You
can change to ' norandom=true ' and ' test_buf_size = 163840' in dmatest.c to look what
issue coming without this patch.
> 
> So something isn't right with this change.
I think this patch is the easy way to resolve the bd contiguous issue, but the cost is to
allocate more dma pool memory which may not used.
> 
> Regards,
> Lucas
> 
> > >
> > > What do you gain by over-allocating each BD by a factor of 20?
> >
> > I guess dma_pool_alloc will return error in such case, and then cause
> > dma setup transfer failure.
> > >
> > > Regards,
> > > Lucas
> > >
> > > > Signed-off-by: Robin Gong <yibin.gong@nxp.com>
> > > > ---
> > > >  drivers/dma/imx-sdma.c | 17 ++++++++++++++++-
> > > >  1 file changed, 16 insertions(+), 1 deletion(-)
> > > >
> > > > diff --git a/drivers/dma/imx-sdma.c b/drivers/dma/imx-sdma.c index
> > > > b4ec2d2..5973489 100644
> > > > --- a/drivers/dma/imx-sdma.c
> > > > +++ b/drivers/dma/imx-sdma.c
> > > > @@ -298,6 +298,15 @@ struct sdma_context_data {
> > > > >  	u32  scratch7;
> > > >
> > > >  } __attribute__ ((packed));
> > > >
> > > > +/*
> > > > + * All bds in one transfer should be consitent on SDMA. To
> > > > easily
> > > > +follow it,just
> > > > + * set the dma pool size as the enough bds. For example, in
> > > > dmatest
> > > > +case, the
> > > > + * max 20 bds means the max for single transfer is NUM_BD *
> > > > +SDMA_BD_MAX_CNT = 20
> > > > + * * 65535 = ~1.28MB. 20 bds supposed to be enough basically.If
> > > > it's
> > > > +still not
> > > > + * enough in some specific cases, enlarge it here.Warning
> > > > message
> > > > +would also
> > > > + * appear if the bd numbers is over than 20.
> > > > + */
> > > > +#define NUM_BD 20
> > > >
> > > >  struct sdma_engine;
> > > >
> > > > @@ -1273,7 +1282,7 @@ static int sdma_alloc_chan_resources(struct
> > > > dma_chan *chan)
> > > > >  		goto disable_clk_ahb;
> > > > >  	sdmac->bd_pool = dma_pool_create("bd_pool", chan-
> > > > > >device->dev,
> > > > > -				sizeof(struct
> > > > > sdma_buffer_descriptor),
> > > > > +				NUM_BD * sizeof(struct
> > > > > sdma_buffer_descriptor),
> > > > >  				32, 0);
> > > > >  	return 0;
> > > >
> > > > @@ -1314,6 +1323,12 @@ static struct sdma_desc
> > > > *sdma_transfer_init(struct sdma_channel *sdmac,
> > > >  {
> > > > >  	struct sdma_desc *desc;
> > > > > +	if (bds > NUM_BD) {
> > > > > +		dev_err(sdmac->sdma->dev, "%d bds exceed the
> > > > > max %d\n",
> > > > > +			bds, NUM_BD);
> > > > > +		goto err_out;
> > > > > +	}
> > > >
> > > > +
> > > > >  	desc = kzalloc((sizeof(*desc)), GFP_NOWAIT);
> > > > >  	if (!desc)
> > > > >  		goto err_out;

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

* [PATCH v3 3/3] dmaengine: imx-sdma: allocate max 20 bds for one transfer
@ 2018-07-25  1:24 ` Robin Gong
  0 siblings, 0 replies; 35+ messages in thread
From: Robin Gong @ 2018-07-25  1:24 UTC (permalink / raw)
  To: linux-arm-kernel

> -----Original Message-----
> From: Lucas Stach [mailto:l.stach at pengutronix.de]
> Sent: 2018?7?24? 17:22
> To: Robin Gong <yibin.gong@nxp.com>; vkoul at kernel.org;
> dan.j.williams at intel.com; s.hauer at pengutronix.de; linux at armlinux.org.uk
> Cc: dmaengine at vger.kernel.org; dl-linux-imx <linux-imx@nxp.com>;
> kernel at pengutronix.de; linux-arm-kernel at lists.infradead.org;
> linux-kernel at vger.kernel.org
> Subject: Re: [PATCH v3 3/3] dmaengine: imx-sdma: allocate max 20 bds for one
> transfer
> 
> Am Montag, den 23.07.2018, 13:55 +0000 schrieb Robin Gong:
> > > -----Original Message-----
> > > From: Lucas Stach [mailto:l.stach at pengutronix.de]
> > > Sent: 2018?7?23? 18:54
> > > To: Robin Gong <yibin.gong@nxp.com>; vkoul at kernel.org;
> > > dan.j.williams at intel.com; s.hauer at pengutronix.de; linux at armlinux.or
> > > g.uk
> > > Cc: dmaengine at vger.kernel.org; dl-linux-imx <linux-imx@nxp.com>;
> > > kernel at pengutronix.de; linux-arm-kernel at lists.infradead.org;
> > > linux-kernel at vger.kernel.org
> > > Subject: Re: [PATCH v3 3/3] dmaengine: imx-sdma: allocate max 20 bds
> > > for one transfer
> > >
> > > Am Dienstag, den 24.07.2018, 01:46 +0800 schrieb Robin Gong:
> > > > If multi-bds used in one transfer, all bds should be consisten
> > > > memory.To easily follow it, enlarge the dma pool size into 20 bds,
> > > > and it will report error if the number of bds is over than 20. For
> > > > dmatest, the max count for single transfer is NUM_BD *
> > >
> > > SDMA_BD_MAX_CNT
> > > > = 20 * 65535 = ~1.28MB.
> > >
> > > Both the commit message and the comment need a lot more care to
> > > actually tell what this commit is trying to achieve. Currently I
> > > don't follow at all. What does "consisten" mean? Do you mean BDs
> > > should be contiguous in memory?
> >
> > Yes, BDs should be contiguous??one by one in memory.
> 
> Okay, but this isn't what the code change does. By increasing the size
> parameter of the dma pool you just allocate 20 times as much memory as
> needed for each BD. So actually the BDs end up being very non- contiguous in
> memory as there are now holes of 19 BD sizes between the start of each BD.
Please notice only allocate bds memory from dma pool one time even in multi bds.
That's different with the common use case that allocate memory from dma pool everytime
for every bd. Why do this is to make sure all bd memory is contiguous for single transfer
whatever single bd or multi-bds, since two call dma_pool_alloc() can't promise the address
is contiguous especially for multi thread case such as dmatest 'threads_per_chan = 5'. You
can change to ' norandom=true ' and ' test_buf_size = 163840' in dmatest.c to look what
issue coming without this patch.
> 
> So something isn't right with this change.
I think this patch is the easy way to resolve the bd contiguous issue, but the cost is to
allocate more dma pool memory which may not used.
> 
> Regards,
> Lucas
> 
> > >
> > > What do you gain by over-allocating each BD by a factor of 20?
> >
> > I guess dma_pool_alloc will return error in such case, and then cause
> > dma setup transfer failure.
> > >
> > > Regards,
> > > Lucas
> > >
> > > > Signed-off-by: Robin Gong <yibin.gong@nxp.com>
> > > > ---
> > > > ?drivers/dma/imx-sdma.c | 17 ++++++++++++++++-
> > > > ?1 file changed, 16 insertions(+), 1 deletion(-)
> > > >
> > > > diff --git a/drivers/dma/imx-sdma.c b/drivers/dma/imx-sdma.c index
> > > > b4ec2d2..5973489 100644
> > > > --- a/drivers/dma/imx-sdma.c
> > > > +++ b/drivers/dma/imx-sdma.c
> > > > @@ -298,6 +298,15 @@ struct sdma_context_data {
> > > > > ?	u32??scratch7;
> > > >
> > > > ?} __attribute__ ((packed));
> > > >
> > > > +/*
> > > > + * All bds in one transfer should be consitent on SDMA. To
> > > > easily
> > > > +follow it,just
> > > > + * set the dma pool size as the enough bds. For example, in
> > > > dmatest
> > > > +case, the
> > > > + * max 20 bds means the max for single transfer is NUM_BD *
> > > > +SDMA_BD_MAX_CNT = 20
> > > > + * * 65535 = ~1.28MB. 20 bds supposed to be enough basically.If
> > > > it's
> > > > +still not
> > > > + * enough in some specific cases, enlarge it here.Warning
> > > > message
> > > > +would also
> > > > + * appear if the bd numbers is over than 20.
> > > > + */
> > > > +#define NUM_BD 20
> > > >
> > > > ?struct sdma_engine;
> > > >
> > > > @@ -1273,7 +1282,7 @@ static int sdma_alloc_chan_resources(struct
> > > > dma_chan *chan)
> > > > > ?		goto disable_clk_ahb;
> > > > > ?	sdmac->bd_pool = dma_pool_create("bd_pool", chan-
> > > > > >device->dev,
> > > > > -				sizeof(struct
> > > > > sdma_buffer_descriptor),
> > > > > +				NUM_BD * sizeof(struct
> > > > > sdma_buffer_descriptor),
> > > > > ?				32, 0);
> > > > > ?	return 0;
> > > >
> > > > @@ -1314,6 +1323,12 @@ static struct sdma_desc
> > > > *sdma_transfer_init(struct sdma_channel *sdmac,
> > > > ?{
> > > > > ?	struct sdma_desc *desc;
> > > > > +	if (bds > NUM_BD) {
> > > > > +		dev_err(sdmac->sdma->dev, "%d bds exceed the
> > > > > max %d\n",
> > > > > +			bds, NUM_BD);
> > > > > +		goto err_out;
> > > > > +	}
> > > >
> > > > +
> > > > > ?	desc = kzalloc((sizeof(*desc)), GFP_NOWAIT);
> > > > > ?	if (!desc)
> > > > > ?		goto err_out;

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

* [v3,1/3] dmaengine: imx-sdma: add SDMA_BD_MAX_CNT to replace '0xffff'
  2018-07-23 17:46 ` Robin Gong
  (?)
@ 2018-07-30  5:04 ` Vinod
  -1 siblings, 0 replies; 35+ messages in thread
From: Vinod Koul @ 2018-07-30  5:04 UTC (permalink / raw)
  To: Robin Gong
  Cc: dan.j.williams, s.hauer, linux, linux-arm-kernel, kernel,
	dmaengine, linux-kernel, linux-imx

On 24-07-18, 01:46, Robin Gong wrote:
> Add macro SDMA_BD_MAX_CNT to replace '0xffff'.

Applied, thanks

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

* Re: [PATCH v3 1/3] dmaengine: imx-sdma: add SDMA_BD_MAX_CNT to replace '0xffff'
@ 2018-07-30  5:04 ` Vinod
  0 siblings, 0 replies; 35+ messages in thread
From: Vinod @ 2018-07-30  5:04 UTC (permalink / raw)
  To: Robin Gong
  Cc: dan.j.williams, s.hauer, linux, linux-arm-kernel, kernel,
	dmaengine, linux-kernel, linux-imx

On 24-07-18, 01:46, Robin Gong wrote:
> Add macro SDMA_BD_MAX_CNT to replace '0xffff'.

Applied, thanks

-- 
~Vinod

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

* [PATCH v3 1/3] dmaengine: imx-sdma: add SDMA_BD_MAX_CNT to replace '0xffff'
@ 2018-07-30  5:04 ` Vinod
  0 siblings, 0 replies; 35+ messages in thread
From: Vinod @ 2018-07-30  5:04 UTC (permalink / raw)
  To: linux-arm-kernel

On 24-07-18, 01:46, Robin Gong wrote:
> Add macro SDMA_BD_MAX_CNT to replace '0xffff'.

Applied, thanks

-- 
~Vinod

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

* [v3,2/3] dmaengine: imx-sdma: add memcpy interface
  2018-07-23 17:46 ` Robin Gong
  (?)
@ 2018-07-30  5:04 ` Vinod
  -1 siblings, 0 replies; 35+ messages in thread
From: Vinod Koul @ 2018-07-30  5:04 UTC (permalink / raw)
  To: Robin Gong
  Cc: dan.j.williams, s.hauer, linux, linux-arm-kernel, kernel,
	dmaengine, linux-kernel, linux-imx

On 24-07-18, 01:46, Robin Gong wrote:
> Add MEMCPY capability for imx-sdma driver.

Applied, thanks

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

* Re: [PATCH v3 2/3] dmaengine: imx-sdma: add memcpy interface
@ 2018-07-30  5:04 ` Vinod
  0 siblings, 0 replies; 35+ messages in thread
From: Vinod @ 2018-07-30  5:04 UTC (permalink / raw)
  To: Robin Gong
  Cc: dan.j.williams, s.hauer, linux, linux-arm-kernel, kernel,
	dmaengine, linux-kernel, linux-imx

On 24-07-18, 01:46, Robin Gong wrote:
> Add MEMCPY capability for imx-sdma driver.

Applied, thanks

-- 
~Vinod

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

* [PATCH v3 2/3] dmaengine: imx-sdma: add memcpy interface
@ 2018-07-30  5:04 ` Vinod
  0 siblings, 0 replies; 35+ messages in thread
From: Vinod @ 2018-07-30  5:04 UTC (permalink / raw)
  To: linux-arm-kernel

On 24-07-18, 01:46, Robin Gong wrote:
> Add MEMCPY capability for imx-sdma driver.

Applied, thanks

-- 
~Vinod

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

* [v3,3/3] dmaengine: imx-sdma: allocate max 20 bds for one transfer
  2018-07-25  1:24 ` Robin Gong
  (?)
@ 2018-08-06  8:04 ` Robin Gong
  -1 siblings, 0 replies; 35+ messages in thread
From: Robin Gong @ 2018-08-06  8:04 UTC (permalink / raw)
  To: Lucas Stach, vkoul, dan.j.williams, s.hauer, linux
  Cc: dmaengine, dl-linux-imx, kernel, linux-arm-kernel, linux-kernel

Hello Lucas,
	Any comment for my reply?

> -----Original Message-----
> From: Robin Gong
> Sent: 2018年7月25日 9:25
> To: 'Lucas Stach' <l.stach@pengutronix.de>; vkoul@kernel.org;
> dan.j.williams@intel.com; s.hauer@pengutronix.de; linux@armlinux.org.uk
> Cc: dmaengine@vger.kernel.org; dl-linux-imx <linux-imx@nxp.com>;
> kernel@pengutronix.de; linux-arm-kernel@lists.infradead.org;
> linux-kernel@vger.kernel.org
> Subject: RE: [PATCH v3 3/3] dmaengine: imx-sdma: allocate max 20 bds for one
> transfer
> 
> > -----Original Message-----
> > From: Lucas Stach [mailto:l.stach@pengutronix.de]
> > Sent: 2018年7月24日 17:22
> > To: Robin Gong <yibin.gong@nxp.com>; vkoul@kernel.org;
> > dan.j.williams@intel.com; s.hauer@pengutronix.de;
> > linux@armlinux.org.uk
> > Cc: dmaengine@vger.kernel.org; dl-linux-imx <linux-imx@nxp.com>;
> > kernel@pengutronix.de; linux-arm-kernel@lists.infradead.org;
> > linux-kernel@vger.kernel.org
> > Subject: Re: [PATCH v3 3/3] dmaengine: imx-sdma: allocate max 20 bds
> > for one transfer
> >
> > Am Montag, den 23.07.2018, 13:55 +0000 schrieb Robin Gong:
> > > > -----Original Message-----
> > > > From: Lucas Stach [mailto:l.stach@pengutronix.de]
> > > > Sent: 2018年7月23日 18:54
> > > > To: Robin Gong <yibin.gong@nxp.com>; vkoul@kernel.org;
> > > > dan.j.williams@intel.com; s.hauer@pengutronix.de;
> > > > linux@armlinux.or g.uk
> > > > Cc: dmaengine@vger.kernel.org; dl-linux-imx <linux-imx@nxp.com>;
> > > > kernel@pengutronix.de; linux-arm-kernel@lists.infradead.org;
> > > > linux-kernel@vger.kernel.org
> > > > Subject: Re: [PATCH v3 3/3] dmaengine: imx-sdma: allocate max 20
> > > > bds for one transfer
> > > >
> > > > Am Dienstag, den 24.07.2018, 01:46 +0800 schrieb Robin Gong:
> > > > > If multi-bds used in one transfer, all bds should be consisten
> > > > > memory.To easily follow it, enlarge the dma pool size into 20
> > > > > bds, and it will report error if the number of bds is over than
> > > > > 20. For dmatest, the max count for single transfer is NUM_BD *
> > > >
> > > > SDMA_BD_MAX_CNT
> > > > > = 20 * 65535 = ~1.28MB.
> > > >
> > > > Both the commit message and the comment need a lot more care to
> > > > actually tell what this commit is trying to achieve. Currently I
> > > > don't follow at all. What does "consisten" mean? Do you mean BDs
> > > > should be contiguous in memory?
> > >
> > > Yes, BDs should be contiguous  one by one in memory.
> >
> > Okay, but this isn't what the code change does. By increasing the size
> > parameter of the dma pool you just allocate 20 times as much memory as
> > needed for each BD. So actually the BDs end up being very non-
> > contiguous in memory as there are now holes of 19 BD sizes between the
> start of each BD.
> Please notice only allocate bds memory from dma pool one time even in multi
> bds.
> That's different with the common use case that allocate memory from dma
> pool everytime for every bd. Why do this is to make sure all bd memory is
> contiguous for single transfer whatever single bd or multi-bds, since two call
> dma_pool_alloc() can't promise the address is contiguous especially for multi
> thread case such as dmatest 'threads_per_chan = 5'. You can change to '
> norandom=true ' and ' test_buf_size = 163840' in dmatest.c to look what issue
> coming without this patch.
> >
> > So something isn't right with this change.
> I think this patch is the easy way to resolve the bd contiguous issue, but the
> cost is to allocate more dma pool memory which may not used.
> >
> > Regards,
> > Lucas
> >
> > > >
> > > > What do you gain by over-allocating each BD by a factor of 20?
> > >
> > > I guess dma_pool_alloc will return error in such case, and then
> > > cause dma setup transfer failure.
> > > >
> > > > Regards,
> > > > Lucas
> > > >
> > > > > Signed-off-by: Robin Gong <yibin.gong@nxp.com>
> > > > > ---
> > > > >  drivers/dma/imx-sdma.c | 17 ++++++++++++++++-
> > > > >  1 file changed, 16 insertions(+), 1 deletion(-)
> > > > >
> > > > > diff --git a/drivers/dma/imx-sdma.c b/drivers/dma/imx-sdma.c
> > > > > index
> > > > > b4ec2d2..5973489 100644
> > > > > --- a/drivers/dma/imx-sdma.c
> > > > > +++ b/drivers/dma/imx-sdma.c
> > > > > @@ -298,6 +298,15 @@ struct sdma_context_data {
> > > > > >  	u32  scratch7;
> > > > >
> > > > >  } __attribute__ ((packed));
> > > > >
> > > > > +/*
> > > > > + * All bds in one transfer should be consitent on SDMA. To
> > > > > easily
> > > > > +follow it,just
> > > > > + * set the dma pool size as the enough bds. For example, in
> > > > > dmatest
> > > > > +case, the
> > > > > + * max 20 bds means the max for single transfer is NUM_BD *
> > > > > +SDMA_BD_MAX_CNT = 20
> > > > > + * * 65535 = ~1.28MB. 20 bds supposed to be enough basically.If
> > > > > it's
> > > > > +still not
> > > > > + * enough in some specific cases, enlarge it here.Warning
> > > > > message
> > > > > +would also
> > > > > + * appear if the bd numbers is over than 20.
> > > > > + */
> > > > > +#define NUM_BD 20
> > > > >
> > > > >  struct sdma_engine;
> > > > >
> > > > > @@ -1273,7 +1282,7 @@ static int
> > > > > sdma_alloc_chan_resources(struct dma_chan *chan)
> > > > > >  		goto disable_clk_ahb;
> > > > > >  	sdmac->bd_pool = dma_pool_create("bd_pool", chan-
> > > > > > >device->dev,
> > > > > > -				sizeof(struct
> > > > > > sdma_buffer_descriptor),
> > > > > > +				NUM_BD * sizeof(struct
> > > > > > sdma_buffer_descriptor),
> > > > > >  				32, 0);
> > > > > >  	return 0;
> > > > >
> > > > > @@ -1314,6 +1323,12 @@ static struct sdma_desc
> > > > > *sdma_transfer_init(struct sdma_channel *sdmac,
> > > > >  {
> > > > > >  	struct sdma_desc *desc;
> > > > > > +	if (bds > NUM_BD) {
> > > > > > +		dev_err(sdmac->sdma->dev, "%d bds exceed the
> > > > > > max %d\n",
> > > > > > +			bds, NUM_BD);
> > > > > > +		goto err_out;
> > > > > > +	}
> > > > >
> > > > > +
> > > > > >  	desc = kzalloc((sizeof(*desc)), GFP_NOWAIT);
> > > > > >  	if (!desc)
> > > > > >  		goto err_out;

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

* RE: [PATCH v3 3/3] dmaengine: imx-sdma: allocate max 20 bds for one transfer
@ 2018-08-06  8:04 ` Robin Gong
  0 siblings, 0 replies; 35+ messages in thread
From: Robin Gong @ 2018-08-06  8:04 UTC (permalink / raw)
  To: Lucas Stach, vkoul, dan.j.williams, s.hauer, linux
  Cc: dmaengine, dl-linux-imx, kernel, linux-arm-kernel, linux-kernel

Hello Lucas,
	Any comment for my reply?

> -----Original Message-----
> From: Robin Gong
> Sent: 2018年7月25日 9:25
> To: 'Lucas Stach' <l.stach@pengutronix.de>; vkoul@kernel.org;
> dan.j.williams@intel.com; s.hauer@pengutronix.de; linux@armlinux.org.uk
> Cc: dmaengine@vger.kernel.org; dl-linux-imx <linux-imx@nxp.com>;
> kernel@pengutronix.de; linux-arm-kernel@lists.infradead.org;
> linux-kernel@vger.kernel.org
> Subject: RE: [PATCH v3 3/3] dmaengine: imx-sdma: allocate max 20 bds for one
> transfer
> 
> > -----Original Message-----
> > From: Lucas Stach [mailto:l.stach@pengutronix.de]
> > Sent: 2018年7月24日 17:22
> > To: Robin Gong <yibin.gong@nxp.com>; vkoul@kernel.org;
> > dan.j.williams@intel.com; s.hauer@pengutronix.de;
> > linux@armlinux.org.uk
> > Cc: dmaengine@vger.kernel.org; dl-linux-imx <linux-imx@nxp.com>;
> > kernel@pengutronix.de; linux-arm-kernel@lists.infradead.org;
> > linux-kernel@vger.kernel.org
> > Subject: Re: [PATCH v3 3/3] dmaengine: imx-sdma: allocate max 20 bds
> > for one transfer
> >
> > Am Montag, den 23.07.2018, 13:55 +0000 schrieb Robin Gong:
> > > > -----Original Message-----
> > > > From: Lucas Stach [mailto:l.stach@pengutronix.de]
> > > > Sent: 2018年7月23日 18:54
> > > > To: Robin Gong <yibin.gong@nxp.com>; vkoul@kernel.org;
> > > > dan.j.williams@intel.com; s.hauer@pengutronix.de;
> > > > linux@armlinux.or g.uk
> > > > Cc: dmaengine@vger.kernel.org; dl-linux-imx <linux-imx@nxp.com>;
> > > > kernel@pengutronix.de; linux-arm-kernel@lists.infradead.org;
> > > > linux-kernel@vger.kernel.org
> > > > Subject: Re: [PATCH v3 3/3] dmaengine: imx-sdma: allocate max 20
> > > > bds for one transfer
> > > >
> > > > Am Dienstag, den 24.07.2018, 01:46 +0800 schrieb Robin Gong:
> > > > > If multi-bds used in one transfer, all bds should be consisten
> > > > > memory.To easily follow it, enlarge the dma pool size into 20
> > > > > bds, and it will report error if the number of bds is over than
> > > > > 20. For dmatest, the max count for single transfer is NUM_BD *
> > > >
> > > > SDMA_BD_MAX_CNT
> > > > > = 20 * 65535 = ~1.28MB.
> > > >
> > > > Both the commit message and the comment need a lot more care to
> > > > actually tell what this commit is trying to achieve. Currently I
> > > > don't follow at all. What does "consisten" mean? Do you mean BDs
> > > > should be contiguous in memory?
> > >
> > > Yes, BDs should be contiguous  one by one in memory.
> >
> > Okay, but this isn't what the code change does. By increasing the size
> > parameter of the dma pool you just allocate 20 times as much memory as
> > needed for each BD. So actually the BDs end up being very non-
> > contiguous in memory as there are now holes of 19 BD sizes between the
> start of each BD.
> Please notice only allocate bds memory from dma pool one time even in multi
> bds.
> That's different with the common use case that allocate memory from dma
> pool everytime for every bd. Why do this is to make sure all bd memory is
> contiguous for single transfer whatever single bd or multi-bds, since two call
> dma_pool_alloc() can't promise the address is contiguous especially for multi
> thread case such as dmatest 'threads_per_chan = 5'. You can change to '
> norandom=true ' and ' test_buf_size = 163840' in dmatest.c to look what issue
> coming without this patch.
> >
> > So something isn't right with this change.
> I think this patch is the easy way to resolve the bd contiguous issue, but the
> cost is to allocate more dma pool memory which may not used.
> >
> > Regards,
> > Lucas
> >
> > > >
> > > > What do you gain by over-allocating each BD by a factor of 20?
> > >
> > > I guess dma_pool_alloc will return error in such case, and then
> > > cause dma setup transfer failure.
> > > >
> > > > Regards,
> > > > Lucas
> > > >
> > > > > Signed-off-by: Robin Gong <yibin.gong@nxp.com>
> > > > > ---
> > > > >  drivers/dma/imx-sdma.c | 17 ++++++++++++++++-
> > > > >  1 file changed, 16 insertions(+), 1 deletion(-)
> > > > >
> > > > > diff --git a/drivers/dma/imx-sdma.c b/drivers/dma/imx-sdma.c
> > > > > index
> > > > > b4ec2d2..5973489 100644
> > > > > --- a/drivers/dma/imx-sdma.c
> > > > > +++ b/drivers/dma/imx-sdma.c
> > > > > @@ -298,6 +298,15 @@ struct sdma_context_data {
> > > > > >  	u32  scratch7;
> > > > >
> > > > >  } __attribute__ ((packed));
> > > > >
> > > > > +/*
> > > > > + * All bds in one transfer should be consitent on SDMA. To
> > > > > easily
> > > > > +follow it,just
> > > > > + * set the dma pool size as the enough bds. For example, in
> > > > > dmatest
> > > > > +case, the
> > > > > + * max 20 bds means the max for single transfer is NUM_BD *
> > > > > +SDMA_BD_MAX_CNT = 20
> > > > > + * * 65535 = ~1.28MB. 20 bds supposed to be enough basically.If
> > > > > it's
> > > > > +still not
> > > > > + * enough in some specific cases, enlarge it here.Warning
> > > > > message
> > > > > +would also
> > > > > + * appear if the bd numbers is over than 20.
> > > > > + */
> > > > > +#define NUM_BD 20
> > > > >
> > > > >  struct sdma_engine;
> > > > >
> > > > > @@ -1273,7 +1282,7 @@ static int
> > > > > sdma_alloc_chan_resources(struct dma_chan *chan)
> > > > > >  		goto disable_clk_ahb;
> > > > > >  	sdmac->bd_pool = dma_pool_create("bd_pool", chan-
> > > > > > >device->dev,
> > > > > > -				sizeof(struct
> > > > > > sdma_buffer_descriptor),
> > > > > > +				NUM_BD * sizeof(struct
> > > > > > sdma_buffer_descriptor),
> > > > > >  				32, 0);
> > > > > >  	return 0;
> > > > >
> > > > > @@ -1314,6 +1323,12 @@ static struct sdma_desc
> > > > > *sdma_transfer_init(struct sdma_channel *sdmac,
> > > > >  {
> > > > > >  	struct sdma_desc *desc;
> > > > > > +	if (bds > NUM_BD) {
> > > > > > +		dev_err(sdmac->sdma->dev, "%d bds exceed the
> > > > > > max %d\n",
> > > > > > +			bds, NUM_BD);
> > > > > > +		goto err_out;
> > > > > > +	}
> > > > >
> > > > > +
> > > > > >  	desc = kzalloc((sizeof(*desc)), GFP_NOWAIT);
> > > > > >  	if (!desc)
> > > > > >  		goto err_out;

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

* [PATCH v3 3/3] dmaengine: imx-sdma: allocate max 20 bds for one transfer
@ 2018-08-06  8:04 ` Robin Gong
  0 siblings, 0 replies; 35+ messages in thread
From: Robin Gong @ 2018-08-06  8:04 UTC (permalink / raw)
  To: linux-arm-kernel

Hello Lucas,
	Any comment for my reply?

> -----Original Message-----
> From: Robin Gong
> Sent: 2018?7?25? 9:25
> To: 'Lucas Stach' <l.stach@pengutronix.de>; vkoul at kernel.org;
> dan.j.williams at intel.com; s.hauer at pengutronix.de; linux at armlinux.org.uk
> Cc: dmaengine at vger.kernel.org; dl-linux-imx <linux-imx@nxp.com>;
> kernel at pengutronix.de; linux-arm-kernel at lists.infradead.org;
> linux-kernel at vger.kernel.org
> Subject: RE: [PATCH v3 3/3] dmaengine: imx-sdma: allocate max 20 bds for one
> transfer
> 
> > -----Original Message-----
> > From: Lucas Stach [mailto:l.stach at pengutronix.de]
> > Sent: 2018?7?24? 17:22
> > To: Robin Gong <yibin.gong@nxp.com>; vkoul at kernel.org;
> > dan.j.williams at intel.com; s.hauer at pengutronix.de;
> > linux at armlinux.org.uk
> > Cc: dmaengine at vger.kernel.org; dl-linux-imx <linux-imx@nxp.com>;
> > kernel at pengutronix.de; linux-arm-kernel at lists.infradead.org;
> > linux-kernel at vger.kernel.org
> > Subject: Re: [PATCH v3 3/3] dmaengine: imx-sdma: allocate max 20 bds
> > for one transfer
> >
> > Am Montag, den 23.07.2018, 13:55 +0000 schrieb Robin Gong:
> > > > -----Original Message-----
> > > > From: Lucas Stach [mailto:l.stach at pengutronix.de]
> > > > Sent: 2018?7?23? 18:54
> > > > To: Robin Gong <yibin.gong@nxp.com>; vkoul at kernel.org;
> > > > dan.j.williams at intel.com; s.hauer at pengutronix.de;
> > > > linux at armlinux.or g.uk
> > > > Cc: dmaengine at vger.kernel.org; dl-linux-imx <linux-imx@nxp.com>;
> > > > kernel at pengutronix.de; linux-arm-kernel at lists.infradead.org;
> > > > linux-kernel at vger.kernel.org
> > > > Subject: Re: [PATCH v3 3/3] dmaengine: imx-sdma: allocate max 20
> > > > bds for one transfer
> > > >
> > > > Am Dienstag, den 24.07.2018, 01:46 +0800 schrieb Robin Gong:
> > > > > If multi-bds used in one transfer, all bds should be consisten
> > > > > memory.To easily follow it, enlarge the dma pool size into 20
> > > > > bds, and it will report error if the number of bds is over than
> > > > > 20. For dmatest, the max count for single transfer is NUM_BD *
> > > >
> > > > SDMA_BD_MAX_CNT
> > > > > = 20 * 65535 = ~1.28MB.
> > > >
> > > > Both the commit message and the comment need a lot more care to
> > > > actually tell what this commit is trying to achieve. Currently I
> > > > don't follow at all. What does "consisten" mean? Do you mean BDs
> > > > should be contiguous in memory?
> > >
> > > Yes, BDs should be contiguous??one by one in memory.
> >
> > Okay, but this isn't what the code change does. By increasing the size
> > parameter of the dma pool you just allocate 20 times as much memory as
> > needed for each BD. So actually the BDs end up being very non-
> > contiguous in memory as there are now holes of 19 BD sizes between the
> start of each BD.
> Please notice only allocate bds memory from dma pool one time even in multi
> bds.
> That's different with the common use case that allocate memory from dma
> pool everytime for every bd. Why do this is to make sure all bd memory is
> contiguous for single transfer whatever single bd or multi-bds, since two call
> dma_pool_alloc() can't promise the address is contiguous especially for multi
> thread case such as dmatest 'threads_per_chan = 5'. You can change to '
> norandom=true ' and ' test_buf_size = 163840' in dmatest.c to look what issue
> coming without this patch.
> >
> > So something isn't right with this change.
> I think this patch is the easy way to resolve the bd contiguous issue, but the
> cost is to allocate more dma pool memory which may not used.
> >
> > Regards,
> > Lucas
> >
> > > >
> > > > What do you gain by over-allocating each BD by a factor of 20?
> > >
> > > I guess dma_pool_alloc will return error in such case, and then
> > > cause dma setup transfer failure.
> > > >
> > > > Regards,
> > > > Lucas
> > > >
> > > > > Signed-off-by: Robin Gong <yibin.gong@nxp.com>
> > > > > ---
> > > > > ?drivers/dma/imx-sdma.c | 17 ++++++++++++++++-
> > > > > ?1 file changed, 16 insertions(+), 1 deletion(-)
> > > > >
> > > > > diff --git a/drivers/dma/imx-sdma.c b/drivers/dma/imx-sdma.c
> > > > > index
> > > > > b4ec2d2..5973489 100644
> > > > > --- a/drivers/dma/imx-sdma.c
> > > > > +++ b/drivers/dma/imx-sdma.c
> > > > > @@ -298,6 +298,15 @@ struct sdma_context_data {
> > > > > > ?	u32??scratch7;
> > > > >
> > > > > ?} __attribute__ ((packed));
> > > > >
> > > > > +/*
> > > > > + * All bds in one transfer should be consitent on SDMA. To
> > > > > easily
> > > > > +follow it,just
> > > > > + * set the dma pool size as the enough bds. For example, in
> > > > > dmatest
> > > > > +case, the
> > > > > + * max 20 bds means the max for single transfer is NUM_BD *
> > > > > +SDMA_BD_MAX_CNT = 20
> > > > > + * * 65535 = ~1.28MB. 20 bds supposed to be enough basically.If
> > > > > it's
> > > > > +still not
> > > > > + * enough in some specific cases, enlarge it here.Warning
> > > > > message
> > > > > +would also
> > > > > + * appear if the bd numbers is over than 20.
> > > > > + */
> > > > > +#define NUM_BD 20
> > > > >
> > > > > ?struct sdma_engine;
> > > > >
> > > > > @@ -1273,7 +1282,7 @@ static int
> > > > > sdma_alloc_chan_resources(struct dma_chan *chan)
> > > > > > ?		goto disable_clk_ahb;
> > > > > > ?	sdmac->bd_pool = dma_pool_create("bd_pool", chan-
> > > > > > >device->dev,
> > > > > > -				sizeof(struct
> > > > > > sdma_buffer_descriptor),
> > > > > > +				NUM_BD * sizeof(struct
> > > > > > sdma_buffer_descriptor),
> > > > > > ?				32, 0);
> > > > > > ?	return 0;
> > > > >
> > > > > @@ -1314,6 +1323,12 @@ static struct sdma_desc
> > > > > *sdma_transfer_init(struct sdma_channel *sdmac,
> > > > > ?{
> > > > > > ?	struct sdma_desc *desc;
> > > > > > +	if (bds > NUM_BD) {
> > > > > > +		dev_err(sdmac->sdma->dev, "%d bds exceed the
> > > > > > max %d\n",
> > > > > > +			bds, NUM_BD);
> > > > > > +		goto err_out;
> > > > > > +	}
> > > > >
> > > > > +
> > > > > > ?	desc = kzalloc((sizeof(*desc)), GFP_NOWAIT);
> > > > > > ?	if (!desc)
> > > > > > ?		goto err_out;

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

* [v3,3/3] dmaengine: imx-sdma: allocate max 20 bds for one transfer
  2018-08-06  8:04 ` Robin Gong
  (?)
@ 2018-08-06 12:29 ` Lucas Stach
  -1 siblings, 0 replies; 35+ messages in thread
From: Lucas Stach @ 2018-08-06 12:29 UTC (permalink / raw)
  To: Robin Gong, vkoul, dan.j.williams, s.hauer, linux
  Cc: dmaengine, linux-kernel, dl-linux-imx, kernel, linux-arm-kernel

Hi Robin,

Am Montag, den 06.08.2018, 08:04 +0000 schrieb Robin Gong:
> Hello Lucas,
> 	Any comment for my reply?

So I've looked at this again and sadly I need to NACK this patch. It is
a total API abuse of the dma_pool API and even the patch introducing
the dma_pool usage in this driver is wrong and should be reverted.

The SDMA need contiguous buffer descriptors for each channel, something
the dma_pool abstraction isn't able to provide. So either the dma_pool
implementation needs to be extended to support this use-case, or you
can't use this at all in the sdma driver. Adding hacks, which are
abusing the API, to cram a dma_pool into the sdma driver is not a valid
way to implement things for upstream.

Regards,
Lucas

> > -----Original Message-----
> > From: Robin Gong
> > Sent: 2018年7月25日 9:25
> > To: 'Lucas Stach' <l.stach@pengutronix.de>; vkoul@kernel.org;
> > dan.j.williams@intel.com; s.hauer@pengutronix.de; linux@armlinux.or
> > g.uk
> > Cc: dmaengine@vger.kernel.org; dl-linux-imx <linux-imx@nxp.com>;
> > kernel@pengutronix.de; linux-arm-kernel@lists.infradead.org;
> > linux-kernel@vger.kernel.org
> > Subject: RE: [PATCH v3 3/3] dmaengine: imx-sdma: allocate max 20
> > bds for one
> > transfer
> > 
> > > -----Original Message-----
> > > From: Lucas Stach [mailto:l.stach@pengutronix.de]
> > > Sent: 2018年7月24日 17:22
> > > To: Robin Gong <yibin.gong@nxp.com>; vkoul@kernel.org;
> > > dan.j.williams@intel.com; s.hauer@pengutronix.de;
> > > linux@armlinux.org.uk
> > > Cc: dmaengine@vger.kernel.org; dl-linux-imx <linux-imx@nxp.com>;
> > > kernel@pengutronix.de; linux-arm-kernel@lists.infradead.org;
> > > linux-kernel@vger.kernel.org
> > > Subject: Re: [PATCH v3 3/3] dmaengine: imx-sdma: allocate max 20
> > > bds
> > > for one transfer
> > > 
> > > Am Montag, den 23.07.2018, 13:55 +0000 schrieb Robin Gong:
> > > > > -----Original Message-----
> > > > > From: Lucas Stach [mailto:l.stach@pengutronix.de]
> > > > > Sent: 2018年7月23日 18:54
> > > > > To: Robin Gong <yibin.gong@nxp.com>; vkoul@kernel.org;
> > > > > dan.j.williams@intel.com; s.hauer@pengutronix.de;
> > > > > linux@armlinux.or g.uk
> > > > > Cc: dmaengine@vger.kernel.org; dl-linux-imx <linux-imx@nxp.co
> > > > > m>;
> > > > > kernel@pengutronix.de; linux-arm-kernel@lists.infradead.org;
> > > > > linux-kernel@vger.kernel.org
> > > > > Subject: Re: [PATCH v3 3/3] dmaengine: imx-sdma: allocate max
> > > > > 20
> > > > > bds for one transfer
> > > > > 
> > > > > Am Dienstag, den 24.07.2018, 01:46 +0800 schrieb Robin Gong:
> > > > > > If multi-bds used in one transfer, all bds should be
> > > > > > consisten
> > > > > > memory.To easily follow it, enlarge the dma pool size into
> > > > > > 20
> > > > > > bds, and it will report error if the number of bds is over
> > > > > > than
> > > > > > 20. For dmatest, the max count for single transfer is
> > > > > > NUM_BD *
> > > > > 
> > > > > SDMA_BD_MAX_CNT
> > > > > > = 20 * 65535 = ~1.28MB.
> > > > > 
> > > > > Both the commit message and the comment need a lot more care
> > > > > to
> > > > > actually tell what this commit is trying to achieve.
> > > > > Currently I
> > > > > don't follow at all. What does "consisten" mean? Do you mean
> > > > > BDs
> > > > > should be contiguous in memory?
> > > > 
> > > > Yes, BDs should be contiguous  one by one in memory.
> > > 
> > > Okay, but this isn't what the code change does. By increasing the
> > > size
> > > parameter of the dma pool you just allocate 20 times as much
> > > memory as
> > > needed for each BD. So actually the BDs end up being very non-
> > > contiguous in memory as there are now holes of 19 BD sizes
> > > between the
> > 
> > start of each BD.
> > Please notice only allocate bds memory from dma pool one time even
> > in multi
> > bds.
> > That's different with the common use case that allocate memory from
> > dma
> > pool everytime for every bd. Why do this is to make sure all bd
> > memory is
> > contiguous for single transfer whatever single bd or multi-bds,
> > since two call
> > dma_pool_alloc() can't promise the address is contiguous especially
> > for multi
> > thread case such as dmatest 'threads_per_chan = 5'. You can change
> > to '
> > norandom=true ' and ' test_buf_size = 163840' in dmatest.c to look
> > what issue
> > coming without this patch.
> > > 
> > > So something isn't right with this change.
> > 
> > I think this patch is the easy way to resolve the bd contiguous
> > issue, but the
> > cost is to allocate more dma pool memory which may not used.
> > > 
> > > Regards,
> > > Lucas
> > > 
> > > > > 
> > > > > What do you gain by over-allocating each BD by a factor of
> > > > > 20?
> > > > 
> > > > I guess dma_pool_alloc will return error in such case, and then
> > > > cause dma setup transfer failure.
> > > > > 
> > > > > Regards,
> > > > > Lucas
> > > > > 
> > > > > > Signed-off-by: Robin Gong <yibin.gong@nxp.com>
> > > > > > ---
> > > > > >  drivers/dma/imx-sdma.c | 17 ++++++++++++++++-
> > > > > >  1 file changed, 16 insertions(+), 1 deletion(-)
> > > > > > 
> > > > > > diff --git a/drivers/dma/imx-sdma.c b/drivers/dma/imx-
> > > > > > sdma.c
> > > > > > index
> > > > > > b4ec2d2..5973489 100644
> > > > > > --- a/drivers/dma/imx-sdma.c
> > > > > > +++ b/drivers/dma/imx-sdma.c
> > > > > > @@ -298,6 +298,15 @@ struct sdma_context_data {
> > > > > > >  	u32  scratch7;
> > > > > > 
> > > > > >  } __attribute__ ((packed));
> > > > > > 
> > > > > > +/*
> > > > > > + * All bds in one transfer should be consitent on SDMA. To
> > > > > > easily
> > > > > > +follow it,just
> > > > > > + * set the dma pool size as the enough bds. For example,
> > > > > > in
> > > > > > dmatest
> > > > > > +case, the
> > > > > > + * max 20 bds means the max for single transfer is NUM_BD
> > > > > > *
> > > > > > +SDMA_BD_MAX_CNT = 20
> > > > > > + * * 65535 = ~1.28MB. 20 bds supposed to be enough
> > > > > > basically.If
> > > > > > it's
> > > > > > +still not
> > > > > > + * enough in some specific cases, enlarge it here.Warning
> > > > > > message
> > > > > > +would also
> > > > > > + * appear if the bd numbers is over than 20.
> > > > > > + */
> > > > > > +#define NUM_BD 20
> > > > > > 
> > > > > >  struct sdma_engine;
> > > > > > 
> > > > > > @@ -1273,7 +1282,7 @@ static int
> > > > > > sdma_alloc_chan_resources(struct dma_chan *chan)
> > > > > > >  		goto disable_clk_ahb;
> > > > > > >  	sdmac->bd_pool = dma_pool_create("bd_pool",
> > > > > > > chan-
> > > > > > > > device->dev,
> > > > > > > 
> > > > > > > -				sizeof(struct
> > > > > > > sdma_buffer_descriptor),
> > > > > > > +				NUM_BD * sizeof(struct
> > > > > > > sdma_buffer_descriptor),
> > > > > > >  				32, 0);
> > > > > > >  	return 0;
> > > > > > 
> > > > > > @@ -1314,6 +1323,12 @@ static struct sdma_desc
> > > > > > *sdma_transfer_init(struct sdma_channel *sdmac,
> > > > > >  {
> > > > > > >  	struct sdma_desc *desc;
> > > > > > > +	if (bds > NUM_BD) {
> > > > > > > +		dev_err(sdmac->sdma->dev, "%d bds exceed
> > > > > > > the
> > > > > > > max %d\n",
> > > > > > > +			bds, NUM_BD);
> > > > > > > +		goto err_out;
> > > > > > > +	}
> > > > > > 
> > > > > > +
> > > > > > >  	desc = kzalloc((sizeof(*desc)), GFP_NOWAIT);
> > > > > > >  	if (!desc)
> > > > > > >  		goto err_out;
---
To unsubscribe from this list: send the line "unsubscribe dmaengine" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH v3 3/3] dmaengine: imx-sdma: allocate max 20 bds for one transfer
@ 2018-08-06 12:29 ` Lucas Stach
  0 siblings, 0 replies; 35+ messages in thread
From: Lucas Stach @ 2018-08-06 12:29 UTC (permalink / raw)
  To: Robin Gong, vkoul, dan.j.williams, s.hauer, linux
  Cc: dmaengine, linux-kernel, dl-linux-imx, kernel, linux-arm-kernel

Hi Robin,

Am Montag, den 06.08.2018, 08:04 +0000 schrieb Robin Gong:
> Hello Lucas,
> 	Any comment for my reply?

So I've looked at this again and sadly I need to NACK this patch. It is
a total API abuse of the dma_pool API and even the patch introducing
the dma_pool usage in this driver is wrong and should be reverted.

The SDMA need contiguous buffer descriptors for each channel, something
the dma_pool abstraction isn't able to provide. So either the dma_pool
implementation needs to be extended to support this use-case, or you
can't use this at all in the sdma driver. Adding hacks, which are
abusing the API, to cram a dma_pool into the sdma driver is not a valid
way to implement things for upstream.

Regards,
Lucas

> > -----Original Message-----
> > From: Robin Gong
> > Sent: 2018年7月25日 9:25
> > To: 'Lucas Stach' <l.stach@pengutronix.de>; vkoul@kernel.org;
> > dan.j.williams@intel.com; s.hauer@pengutronix.de; linux@armlinux.or
> > g.uk
> > Cc: dmaengine@vger.kernel.org; dl-linux-imx <linux-imx@nxp.com>;
> > kernel@pengutronix.de; linux-arm-kernel@lists.infradead.org;
> > linux-kernel@vger.kernel.org
> > Subject: RE: [PATCH v3 3/3] dmaengine: imx-sdma: allocate max 20
> > bds for one
> > transfer
> > 
> > > -----Original Message-----
> > > From: Lucas Stach [mailto:l.stach@pengutronix.de]
> > > Sent: 2018年7月24日 17:22
> > > To: Robin Gong <yibin.gong@nxp.com>; vkoul@kernel.org;
> > > dan.j.williams@intel.com; s.hauer@pengutronix.de;
> > > linux@armlinux.org.uk
> > > Cc: dmaengine@vger.kernel.org; dl-linux-imx <linux-imx@nxp.com>;
> > > kernel@pengutronix.de; linux-arm-kernel@lists.infradead.org;
> > > linux-kernel@vger.kernel.org
> > > Subject: Re: [PATCH v3 3/3] dmaengine: imx-sdma: allocate max 20
> > > bds
> > > for one transfer
> > > 
> > > Am Montag, den 23.07.2018, 13:55 +0000 schrieb Robin Gong:
> > > > > -----Original Message-----
> > > > > From: Lucas Stach [mailto:l.stach@pengutronix.de]
> > > > > Sent: 2018年7月23日 18:54
> > > > > To: Robin Gong <yibin.gong@nxp.com>; vkoul@kernel.org;
> > > > > dan.j.williams@intel.com; s.hauer@pengutronix.de;
> > > > > linux@armlinux.or g.uk
> > > > > Cc: dmaengine@vger.kernel.org; dl-linux-imx <linux-imx@nxp.co
> > > > > m>;
> > > > > kernel@pengutronix.de; linux-arm-kernel@lists.infradead.org;
> > > > > linux-kernel@vger.kernel.org
> > > > > Subject: Re: [PATCH v3 3/3] dmaengine: imx-sdma: allocate max
> > > > > 20
> > > > > bds for one transfer
> > > > > 
> > > > > Am Dienstag, den 24.07.2018, 01:46 +0800 schrieb Robin Gong:
> > > > > > If multi-bds used in one transfer, all bds should be
> > > > > > consisten
> > > > > > memory.To easily follow it, enlarge the dma pool size into
> > > > > > 20
> > > > > > bds, and it will report error if the number of bds is over
> > > > > > than
> > > > > > 20. For dmatest, the max count for single transfer is
> > > > > > NUM_BD *
> > > > > 
> > > > > SDMA_BD_MAX_CNT
> > > > > > = 20 * 65535 = ~1.28MB.
> > > > > 
> > > > > Both the commit message and the comment need a lot more care
> > > > > to
> > > > > actually tell what this commit is trying to achieve.
> > > > > Currently I
> > > > > don't follow at all. What does "consisten" mean? Do you mean
> > > > > BDs
> > > > > should be contiguous in memory?
> > > > 
> > > > Yes, BDs should be contiguous  one by one in memory.
> > > 
> > > Okay, but this isn't what the code change does. By increasing the
> > > size
> > > parameter of the dma pool you just allocate 20 times as much
> > > memory as
> > > needed for each BD. So actually the BDs end up being very non-
> > > contiguous in memory as there are now holes of 19 BD sizes
> > > between the
> > 
> > start of each BD.
> > Please notice only allocate bds memory from dma pool one time even
> > in multi
> > bds.
> > That's different with the common use case that allocate memory from
> > dma
> > pool everytime for every bd. Why do this is to make sure all bd
> > memory is
> > contiguous for single transfer whatever single bd or multi-bds,
> > since two call
> > dma_pool_alloc() can't promise the address is contiguous especially
> > for multi
> > thread case such as dmatest 'threads_per_chan = 5'. You can change
> > to '
> > norandom=true ' and ' test_buf_size = 163840' in dmatest.c to look
> > what issue
> > coming without this patch.
> > > 
> > > So something isn't right with this change.
> > 
> > I think this patch is the easy way to resolve the bd contiguous
> > issue, but the
> > cost is to allocate more dma pool memory which may not used.
> > > 
> > > Regards,
> > > Lucas
> > > 
> > > > > 
> > > > > What do you gain by over-allocating each BD by a factor of
> > > > > 20?
> > > > 
> > > > I guess dma_pool_alloc will return error in such case, and then
> > > > cause dma setup transfer failure.
> > > > > 
> > > > > Regards,
> > > > > Lucas
> > > > > 
> > > > > > Signed-off-by: Robin Gong <yibin.gong@nxp.com>
> > > > > > ---
> > > > > >  drivers/dma/imx-sdma.c | 17 ++++++++++++++++-
> > > > > >  1 file changed, 16 insertions(+), 1 deletion(-)
> > > > > > 
> > > > > > diff --git a/drivers/dma/imx-sdma.c b/drivers/dma/imx-
> > > > > > sdma.c
> > > > > > index
> > > > > > b4ec2d2..5973489 100644
> > > > > > --- a/drivers/dma/imx-sdma.c
> > > > > > +++ b/drivers/dma/imx-sdma.c
> > > > > > @@ -298,6 +298,15 @@ struct sdma_context_data {
> > > > > > >  	u32  scratch7;
> > > > > > 
> > > > > >  } __attribute__ ((packed));
> > > > > > 
> > > > > > +/*
> > > > > > + * All bds in one transfer should be consitent on SDMA. To
> > > > > > easily
> > > > > > +follow it,just
> > > > > > + * set the dma pool size as the enough bds. For example,
> > > > > > in
> > > > > > dmatest
> > > > > > +case, the
> > > > > > + * max 20 bds means the max for single transfer is NUM_BD
> > > > > > *
> > > > > > +SDMA_BD_MAX_CNT = 20
> > > > > > + * * 65535 = ~1.28MB. 20 bds supposed to be enough
> > > > > > basically.If
> > > > > > it's
> > > > > > +still not
> > > > > > + * enough in some specific cases, enlarge it here.Warning
> > > > > > message
> > > > > > +would also
> > > > > > + * appear if the bd numbers is over than 20.
> > > > > > + */
> > > > > > +#define NUM_BD 20
> > > > > > 
> > > > > >  struct sdma_engine;
> > > > > > 
> > > > > > @@ -1273,7 +1282,7 @@ static int
> > > > > > sdma_alloc_chan_resources(struct dma_chan *chan)
> > > > > > >  		goto disable_clk_ahb;
> > > > > > >  	sdmac->bd_pool = dma_pool_create("bd_pool",
> > > > > > > chan-
> > > > > > > > device->dev,
> > > > > > > 
> > > > > > > -				sizeof(struct
> > > > > > > sdma_buffer_descriptor),
> > > > > > > +				NUM_BD * sizeof(struct
> > > > > > > sdma_buffer_descriptor),
> > > > > > >  				32, 0);
> > > > > > >  	return 0;
> > > > > > 
> > > > > > @@ -1314,6 +1323,12 @@ static struct sdma_desc
> > > > > > *sdma_transfer_init(struct sdma_channel *sdmac,
> > > > > >  {
> > > > > > >  	struct sdma_desc *desc;
> > > > > > > +	if (bds > NUM_BD) {
> > > > > > > +		dev_err(sdmac->sdma->dev, "%d bds exceed
> > > > > > > the
> > > > > > > max %d\n",
> > > > > > > +			bds, NUM_BD);
> > > > > > > +		goto err_out;
> > > > > > > +	}
> > > > > > 
> > > > > > +
> > > > > > >  	desc = kzalloc((sizeof(*desc)), GFP_NOWAIT);
> > > > > > >  	if (!desc)
> > > > > > >  		goto err_out;

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

* [PATCH v3 3/3] dmaengine: imx-sdma: allocate max 20 bds for one transfer
@ 2018-08-06 12:29 ` Lucas Stach
  0 siblings, 0 replies; 35+ messages in thread
From: Lucas Stach @ 2018-08-06 12:29 UTC (permalink / raw)
  To: linux-arm-kernel

Hi Robin,

Am Montag, den 06.08.2018, 08:04 +0000 schrieb Robin Gong:
> Hello Lucas,
> 	Any comment for my reply?

So I've looked at this again and sadly I need to NACK this patch. It is
a total API abuse of the dma_pool API and even the patch introducing
the dma_pool usage in this driver is wrong and should be reverted.

The SDMA need contiguous buffer descriptors for each channel, something
the dma_pool abstraction isn't able to provide. So either the dma_pool
implementation needs to be extended to support this use-case, or you
can't use this at all in the sdma driver. Adding hacks, which are
abusing the API, to cram a dma_pool into the sdma driver is not a valid
way to implement things for upstream.

Regards,
Lucas

> > -----Original Message-----
> > From: Robin Gong
> > Sent: 2018?7?25? 9:25
> > To: 'Lucas Stach' <l.stach@pengutronix.de>; vkoul at kernel.org;
> > dan.j.williams at intel.com; s.hauer at pengutronix.de; linux at armlinux.or
> > g.uk
> > Cc: dmaengine at vger.kernel.org; dl-linux-imx <linux-imx@nxp.com>;
> > kernel at pengutronix.de; linux-arm-kernel at lists.infradead.org;
> > linux-kernel at vger.kernel.org
> > Subject: RE: [PATCH v3 3/3] dmaengine: imx-sdma: allocate max 20
> > bds for one
> > transfer
> > 
> > > -----Original Message-----
> > > From: Lucas Stach [mailto:l.stach at pengutronix.de]
> > > Sent: 2018?7?24? 17:22
> > > To: Robin Gong <yibin.gong@nxp.com>; vkoul at kernel.org;
> > > dan.j.williams at intel.com; s.hauer at pengutronix.de;
> > > linux at armlinux.org.uk
> > > Cc: dmaengine at vger.kernel.org; dl-linux-imx <linux-imx@nxp.com>;
> > > kernel at pengutronix.de; linux-arm-kernel at lists.infradead.org;
> > > linux-kernel at vger.kernel.org
> > > Subject: Re: [PATCH v3 3/3] dmaengine: imx-sdma: allocate max 20
> > > bds
> > > for one transfer
> > > 
> > > Am Montag, den 23.07.2018, 13:55 +0000 schrieb Robin Gong:
> > > > > -----Original Message-----
> > > > > From: Lucas Stach [mailto:l.stach at pengutronix.de]
> > > > > Sent: 2018?7?23? 18:54
> > > > > To: Robin Gong <yibin.gong@nxp.com>; vkoul at kernel.org;
> > > > > dan.j.williams at intel.com; s.hauer at pengutronix.de;
> > > > > linux at armlinux.or g.uk
> > > > > Cc: dmaengine at vger.kernel.org; dl-linux-imx <linux-imx@nxp.co
> > > > > m>;
> > > > > kernel at pengutronix.de; linux-arm-kernel at lists.infradead.org;
> > > > > linux-kernel at vger.kernel.org
> > > > > Subject: Re: [PATCH v3 3/3] dmaengine: imx-sdma: allocate max
> > > > > 20
> > > > > bds for one transfer
> > > > > 
> > > > > Am Dienstag, den 24.07.2018, 01:46 +0800 schrieb Robin Gong:
> > > > > > If multi-bds used in one transfer, all bds should be
> > > > > > consisten
> > > > > > memory.To easily follow it, enlarge the dma pool size into
> > > > > > 20
> > > > > > bds, and it will report error if the number of bds is over
> > > > > > than
> > > > > > 20. For dmatest, the max count for single transfer is
> > > > > > NUM_BD *
> > > > > 
> > > > > SDMA_BD_MAX_CNT
> > > > > > = 20 * 65535 = ~1.28MB.
> > > > > 
> > > > > Both the commit message and the comment need a lot more care
> > > > > to
> > > > > actually tell what this commit is trying to achieve.
> > > > > Currently I
> > > > > don't follow at all. What does "consisten" mean? Do you mean
> > > > > BDs
> > > > > should be contiguous in memory?
> > > > 
> > > > Yes, BDs should be contiguous??one by one in memory.
> > > 
> > > Okay, but this isn't what the code change does. By increasing the
> > > size
> > > parameter of the dma pool you just allocate 20 times as much
> > > memory as
> > > needed for each BD. So actually the BDs end up being very non-
> > > contiguous in memory as there are now holes of 19 BD sizes
> > > between the
> > 
> > start of each BD.
> > Please notice only allocate bds memory from dma pool one time even
> > in multi
> > bds.
> > That's different with the common use case that allocate memory from
> > dma
> > pool everytime for every bd. Why do this is to make sure all bd
> > memory is
> > contiguous for single transfer whatever single bd or multi-bds,
> > since two call
> > dma_pool_alloc() can't promise the address is contiguous especially
> > for multi
> > thread case such as dmatest 'threads_per_chan = 5'. You can change
> > to '
> > norandom=true ' and ' test_buf_size = 163840' in dmatest.c to look
> > what issue
> > coming without this patch.
> > > 
> > > So something isn't right with this change.
> > 
> > I think this patch is the easy way to resolve the bd contiguous
> > issue, but the
> > cost is to allocate more dma pool memory which may not used.
> > > 
> > > Regards,
> > > Lucas
> > > 
> > > > > 
> > > > > What do you gain by over-allocating each BD by a factor of
> > > > > 20?
> > > > 
> > > > I guess dma_pool_alloc will return error in such case, and then
> > > > cause dma setup transfer failure.
> > > > > 
> > > > > Regards,
> > > > > Lucas
> > > > > 
> > > > > > Signed-off-by: Robin Gong <yibin.gong@nxp.com>
> > > > > > ---
> > > > > > ?drivers/dma/imx-sdma.c | 17 ++++++++++++++++-
> > > > > > ?1 file changed, 16 insertions(+), 1 deletion(-)
> > > > > > 
> > > > > > diff --git a/drivers/dma/imx-sdma.c b/drivers/dma/imx-
> > > > > > sdma.c
> > > > > > index
> > > > > > b4ec2d2..5973489 100644
> > > > > > --- a/drivers/dma/imx-sdma.c
> > > > > > +++ b/drivers/dma/imx-sdma.c
> > > > > > @@ -298,6 +298,15 @@ struct sdma_context_data {
> > > > > > > ?	u32??scratch7;
> > > > > > 
> > > > > > ?} __attribute__ ((packed));
> > > > > > 
> > > > > > +/*
> > > > > > + * All bds in one transfer should be consitent on SDMA. To
> > > > > > easily
> > > > > > +follow it,just
> > > > > > + * set the dma pool size as the enough bds. For example,
> > > > > > in
> > > > > > dmatest
> > > > > > +case, the
> > > > > > + * max 20 bds means the max for single transfer is NUM_BD
> > > > > > *
> > > > > > +SDMA_BD_MAX_CNT = 20
> > > > > > + * * 65535 = ~1.28MB. 20 bds supposed to be enough
> > > > > > basically.If
> > > > > > it's
> > > > > > +still not
> > > > > > + * enough in some specific cases, enlarge it here.Warning
> > > > > > message
> > > > > > +would also
> > > > > > + * appear if the bd numbers is over than 20.
> > > > > > + */
> > > > > > +#define NUM_BD 20
> > > > > > 
> > > > > > ?struct sdma_engine;
> > > > > > 
> > > > > > @@ -1273,7 +1282,7 @@ static int
> > > > > > sdma_alloc_chan_resources(struct dma_chan *chan)
> > > > > > > ?		goto disable_clk_ahb;
> > > > > > > ?	sdmac->bd_pool = dma_pool_create("bd_pool",
> > > > > > > chan-
> > > > > > > > device->dev,
> > > > > > > 
> > > > > > > -				sizeof(struct
> > > > > > > sdma_buffer_descriptor),
> > > > > > > +				NUM_BD * sizeof(struct
> > > > > > > sdma_buffer_descriptor),
> > > > > > > ?				32, 0);
> > > > > > > ?	return 0;
> > > > > > 
> > > > > > @@ -1314,6 +1323,12 @@ static struct sdma_desc
> > > > > > *sdma_transfer_init(struct sdma_channel *sdmac,
> > > > > > ?{
> > > > > > > ?	struct sdma_desc *desc;
> > > > > > > +	if (bds > NUM_BD) {
> > > > > > > +		dev_err(sdmac->sdma->dev, "%d bds exceed
> > > > > > > the
> > > > > > > max %d\n",
> > > > > > > +			bds, NUM_BD);
> > > > > > > +		goto err_out;
> > > > > > > +	}
> > > > > > 
> > > > > > +
> > > > > > > ?	desc = kzalloc((sizeof(*desc)), GFP_NOWAIT);
> > > > > > > ?	if (!desc)
> > > > > > > ?		goto err_out;

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

end of thread, other threads:[~2018-08-06 12:30 UTC | newest]

Thread overview: 35+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-30  5:04 [v3,1/3] dmaengine: imx-sdma: add SDMA_BD_MAX_CNT to replace '0xffff' Vinod Koul
2018-07-30  5:04 ` [PATCH v3 1/3] " Vinod
2018-07-30  5:04 ` Vinod
  -- strict thread matches above, loose matches on Subject: below --
2018-08-06 12:29 [v3,3/3] dmaengine: imx-sdma: allocate max 20 bds for one transfer Lucas Stach
2018-08-06 12:29 ` [PATCH v3 3/3] " Lucas Stach
2018-08-06 12:29 ` Lucas Stach
2018-08-06  8:04 [v3,3/3] " Robin Gong
2018-08-06  8:04 ` [PATCH v3 3/3] " Robin Gong
2018-08-06  8:04 ` Robin Gong
2018-07-30  5:04 [v3,2/3] dmaengine: imx-sdma: add memcpy interface Vinod Koul
2018-07-30  5:04 ` [PATCH v3 2/3] " Vinod
2018-07-30  5:04 ` Vinod
2018-07-25  1:24 [v3,3/3] dmaengine: imx-sdma: allocate max 20 bds for one transfer Robin Gong
2018-07-25  1:24 ` [PATCH v3 3/3] " Robin Gong
2018-07-25  1:24 ` Robin Gong
2018-07-24  9:22 [v3,3/3] " Lucas Stach
2018-07-24  9:22 ` [PATCH v3 3/3] " Lucas Stach
2018-07-24  9:22 ` Lucas Stach
2018-07-23 17:46 [v3,3/3] " Robin Gong
2018-07-23 17:46 ` [PATCH v3 3/3] " Robin Gong
2018-07-23 17:46 ` Robin Gong
2018-07-23 17:46 [v3,2/3] dmaengine: imx-sdma: add memcpy interface Robin Gong
2018-07-23 17:46 ` [PATCH v3 2/3] " Robin Gong
2018-07-23 17:46 ` Robin Gong
2018-07-23 17:46 [v3,1/3] dmaengine: imx-sdma: add SDMA_BD_MAX_CNT to replace '0xffff' Robin Gong
2018-07-23 17:46 ` [PATCH v3 1/3] " Robin Gong
2018-07-23 17:46 ` Robin Gong
2018-07-23 17:46 [PATCH v3 0/3] add memcpy support for sdma Robin Gong
2018-07-23 17:46 ` Robin Gong
2018-07-23 13:55 [v3,3/3] dmaengine: imx-sdma: allocate max 20 bds for one transfer Robin Gong
2018-07-23 13:55 ` [PATCH v3 3/3] " Robin Gong
2018-07-23 13:55 ` Robin Gong
2018-07-23 10:54 [v3,3/3] " Lucas Stach
2018-07-23 10:54 ` [PATCH v3 3/3] " Lucas Stach
2018-07-23 10:54 ` Lucas Stach

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.