dma: rcar-dma: add wait after stopping dma engine
Subsystems (3)
PATCH 1/6 dma: rcar-dma: add wait after stopping dma engine
From: Muhammad Hamza Farooq <[email protected]>
DMA engine does not stop instantaneously when transaction is going on (see datasheet). Wait has been added
--- drivers/dma/sh/rcar-dmac.c | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-)
drivers/dma/sh/rcar-dmac.c +26 -2
@@ -716,14 +716,38 @@ static int rcar_dmac_fill_hwdesc(struct rcar_dmac_chan *chan,/* ----------------------------------------------------------------------------- * Stop and reset */ +#define NR_READS_TO_WAIT 5/* number of times to check if DE = 0 */ +static inline int rcar_dmac_wait_stop (struct rcar_dmac_chan *chan) +{ +unsigned int i =0 ; + +do { +u32 chcr =rcar_dmac_chan_read (chan,RCAR_DMACHCR ); + +if (!(chcr &RCAR_DMACHCR_DE )) +return 0 ; +cpu_relax (); +dev_dbg (chan->chan.device->dev,"DMA xfer couldn't be stopped" ); + }while (++i <NR_READS_TO_WAIT ); -static void rcar_dmac_chan_halt (struct rcar_dmac_chan *chan) +return -EBUSY ; +} + +/* Called with chan lock held */ +static int rcar_dmac_chan_halt (struct rcar_dmac_chan *chan) { -u32 chcr =rcar_dmac_chan_read (chan,RCAR_DMACHCR ); +u32 chcr; +int ret; + chcr =rcar_dmac_chan_read (chan,RCAR_DMACHCR ); chcr &= ~(RCAR_DMACHCR_DSE |RCAR_DMACHCR_DSIE |RCAR_DMACHCR_IE |RCAR_DMACHCR_TE |RCAR_DMACHCR_DE );rcar_dmac_chan_write (chan,RCAR_DMACHCR , chcr); + ret =rcar_dmac_wait_stop (chan); + +WARN_ON (ret <0 ); + +return ret; }static void rcar_dmac_chan_reinit (struct rcar_dmac_chan *chan)
Signature · 1 line
1.9.1
Quoted 4 lines · On Tue, Sep 29, 2015 at 10:44:43PM +0200, [email protected] wrote:
From: Muhammad Hamza Farooq <[email protected]>
DMA engine does not stop instantaneously when transaction is going on (see datasheet). Wait has been added
Hmmm, why is threading broken in this series?
Also why is this PATCH 1/6 whereas the rest of series is v3!
Right way is to let git do this for you and use git format-patch --subject-prefix="PATCH v3"...
You don't do these things manually, that would be terrible waste of time
Also use git send-email to keep threading
Quoted 15 lines
Signed-off-by Muhammad Hamza Farooq <[email protected]>--- drivers/dma/sh/rcar-dmac.c | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-)drivers/dma/sh/rcar-dmac.c +2
-0@@ -716,14 +716,38 @@ static int rcar_dmac_fill_hwdesc(struct rcar_dmac_chan *chan,/* ----------------------------------------------------------------------------- * Stop and reset */ +#define NR_READS_TO_WAIT 5/* number of times to check if DE = 0 */ +static inline int rcar_dmac_wait_stop (struct rcar_dmac_chan *chan)
drivers/dma/sh/rcar-dmac.c static int rcar_dmac_fill_hwdesc(struct rcar_dmac_chan *chan, · line 730
Quoted 10 lines
drivers/dma/sh/rcar-dmac.c +10
-0+{ +unsigned int i =0 ; + + do { + u32 chcr = rcar_dmac_chan_read(chan, RCAR_DMACHCR); + + if (!(chcr & RCAR_DMACHCR_DE)) + return 0; + cpu_relax(); + dev_dbg(chan->chan.device->dev, "DMA xfer couldn't be stopped");
And user has no way of knowing this on production system
Quoted 10 lines
drivers/dma/sh/rcar-dmac.c +6
-2+ }while (++i <NR_READS_TO_WAIT ); -static void rcar_dmac_chan_halt (struct rcar_dmac_chan *chan) +return -EBUSY ; +} + +/* Called with chan lock held */ +static int rcar_dmac_chan_halt (struct rcar_dmac_chan *chan) { -u32 chcr =rcar_dmac_chan_read (chan,RCAR_DMACHCR );
drivers/dma/sh/rcar-dmac.c static int rcar_dmac_fill_hwdesc(struct rcar_dmac_chan *chan, · line 748
Quoted 10 lines
drivers/dma/sh/rcar-dmac.c +6
-0+u32 chcr; +int ret; + chcr =rcar_dmac_chan_read (chan,RCAR_DMACHCR ); chcr &= ~(RCAR_DMACHCR_DSE |RCAR_DMACHCR_DSIE |RCAR_DMACHCR_IE |RCAR_DMACHCR_TE |RCAR_DMACHCR_DE );rcar_dmac_chan_write (chan,RCAR_DMACHCR , chcr); + ret =rcar_dmac_wait_stop (chan); + +WARN_ON (ret <0 );
What if we have broken board and will see dmesg storm for this, perhaps WARN_ON_ONCE and also would be helpful to use the verbose version and print some meaningful message
Signature · 1 line
~Vinod
Hello Muhammad,
Thank you for the patch.
Quoted 21 lines · On Tuesday 29 September 2015 22:44:43 [email protected] wrote:
From: Muhammad Hamza Farooq <[email protected]>
DMA engine does not stop instantaneously when transaction is going on (see datasheet). Wait has been added
Signed-off-by Muhammad Hamza Farooq <[email protected]>--- drivers/dma/sh/rcar-dmac.c | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-)drivers/dma/sh/rcar-dmac.c +2
-1@@ -716,14 +716,38 @@ static int rcar_dmac_fill_hwdesc(struct rcar_dmac_chan *chan, /* --------------------------------------------------------------------------- * Stop and reset */ +#define NR_READS_TO_WAIT 5/* number of times to check if DE = 0 */ +static inline int rcar_dmac_wait_stop (struct rcar_dmac_chan *chan)
drivers/dma/sh/rcar-dmac.c static int rcar_dmac_fill_hwdesc(struct rcar_dmac_chan · line 730
Quoted 10 lines
drivers/dma/sh/rcar-dmac.c +10
-0+{ +unsigned int i =0 ; + + do { + u32 chcr = rcar_dmac_chan_read(chan, RCAR_DMACHCR); + + if (!(chcr & RCAR_DMACHCR_DE)) + return 0; + cpu_relax(); + dev_dbg(chan->chan.device->dev, "DMA xfer couldn't be stopped");
Would it make sense to move the message out of the loop and use dev_err() ? It seems like a pretty serious error.
drivers/dma/sh/rcar-dmac.c static int rcar_dmac_fill_hwdesc(struct rcar_dmac_chan *chan, · line 731
Quoted 1 line
drivers/dma/sh/rcar-dmac.c +1
-0+ }while (++i <NR_READS_TO_WAIT );
How long does the DMA engine typically need to stop ? Is there a safe upper bound ?
Quoted 6 lines
drivers/dma/sh/rcar-dmac.c +5
-1-static void rcar_dmac_chan_halt (struct rcar_dmac_chan *chan) +return -EBUSY ; +} + +/* Called with chan lock held */ +static int rcar_dmac_chan_halt (struct rcar_dmac_chan *chan)
drivers/dma/sh/rcar-dmac.c static int rcar_dmac_fill_hwdesc(struct rcar_dmac_chan *chan, · line 746
Quoted 10 lines
drivers/dma/sh/rcar-dmac.c +4
-1{ -u32 chcr =rcar_dmac_chan_read (chan,RCAR_DMACHCR ); +u32 chcr; +int ret; + chcr =rcar_dmac_chan_read (chan,RCAR_DMACHCR ); chcr &= ~(RCAR_DMACHCR_DSE |RCAR_DMACHCR_DSIE |RCAR_DMACHCR_IE |RCAR_DMACHCR_TE |RCAR_DMACHCR_DE );rcar_dmac_chan_write (chan,RCAR_DMACHCR , chcr); + ret =rcar_dmac_wait_stop (chan);
As the rcar_dmac_wait_stop() function is used here only I'd inline the code directly.
drivers/dma/sh/rcar-dmac.c static int rcar_dmac_fill_hwdesc(struct rcar_dmac_chan · line 747
Quoted 2 lines
drivers/dma/sh/rcar-dmac.c +2
-0+ +WARN_ON (ret <0 );
If you use dev_err() instead of dev_dbg() above you could remove the WARN_on.
Quoted 5 lines
drivers/dma/sh/rcar-dmac.c +2
-0+ +return ret; }static void rcar_dmac_chan_reinit (struct rcar_dmac_chan *chan)
Signature · 3 lines
Regards, Laurent Pinchart
Hi Vinod,
Quoted 9 lines
Hmmm, why is threading broken in this series?
Also why is this PATCH 1/6 whereas the rest of series is v3!Right way is to let git do this for you and use git format-patch --subject-prefix="PATCH v3"...
You don't do these things manually, that would be terrible waste of time
Also use git send-email to keep threading
I will keep that in mind
Quoted 6 lines
Quoted 6 lines
drivers/dma/sh/rcar-dmac.c +6
-0+#define NR_READS_TO_WAIT 5/* number of times to check if DE = 0 */ +static inline int rcar_dmac_wait_stop (struct rcar_dmac_chan *chan) +{ +unsigned int i =0 ; + + do {
Quoted 8 lines
drivers/dma/sh/rcar-dmac.c static int rcar_dmac_fill_hwdesc(struct rcar_dmac_chan *chan, · line 730
Quoted 6 lines
drivers/dma/sh/rcar-dmac.c +6
-0+u32 chcr =rcar_dmac_chan_read (chan,RCAR_DMACHCR ); + +if (!(chcr &RCAR_DMACHCR_DE )) +return 0 ; +cpu_relax (); +dev_dbg (chan->chan.device->dev,"DMA xfer couldn't be stopped" );And user has no way of knowing this on production system
What do you suggest here instead?
Quoted 7 lines
Quoted 7 lines
drivers/dma/sh/rcar-dmac.c +4
-1+/* Called with chan lock held */ +static int rcar_dmac_chan_halt (struct rcar_dmac_chan *chan) { -u32 chcr =rcar_dmac_chan_read (chan,RCAR_DMACHCR ); +u32 chcr; +int ret;
Quoted 11 lines
drivers/dma/sh/rcar-dmac.c static int rcar_dmac_fill_hwdesc(struct rcar_dmac_chan *chan, · line 748
Quoted 7 lines
drivers/dma/sh/rcar-dmac.c +4
-0+ chcr =rcar_dmac_chan_read (chan,RCAR_DMACHCR ); chcr &= ~(RCAR_DMACHCR_DSE |RCAR_DMACHCR_DSIE |RCAR_DMACHCR_IE |RCAR_DMACHCR_TE |RCAR_DMACHCR_DE );rcar_dmac_chan_write (chan,RCAR_DMACHCR , chcr); + ret =rcar_dmac_wait_stop (chan); + +WARN_ON (ret <0 );What if we have broken board and will see dmesg storm for this, perhaps
WARN_ON_ONCEand also would be helpful to use the verbose version and print some meaningful message
Yes that does make sense. I shall update it in next version
Thanks for the comments
Best,
Hamza
Quoted 71 lines · Vinod Koul
Quoted 4 lines · On Tue, Sep 29, 2015 at 10:44:43PM +0200, [email protected] wrote:
From: Muhammad Hamza Farooq <[email protected]>
DMA engine does not stop instantaneously when transaction is going on (see datasheet). Wait has been added
Hmmm, why is threading broken in this series?
Also why is this PATCH 1/6 whereas the rest of series is v3!Right way is to let git do this for you and use git format-patch --subject-prefix="PATCH v3"...
You don't do these things manually, that would be terrible waste of time
Also use git send-email to keep threading
Quoted 15 lines
Signed-off-by Muhammad Hamza Farooq <[email protected]>--- drivers/dma/sh/rcar-dmac.c | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-)drivers/dma/sh/rcar-dmac.c +2
-0@@ -716,14 +716,38 @@ static int rcar_dmac_fill_hwdesc(struct rcar_dmac_chan *chan,/* ----------------------------------------------------------------------------- * Stop and reset */ +#define NR_READS_TO_WAIT 5/* number of times to check if DE = 0 */ +static inline int rcar_dmac_wait_stop (struct rcar_dmac_chan *chan)drivers/dma/sh/rcar-dmac.c static int rcar_dmac_fill_hwdesc(struct rcar_dmac_chan *chan, · line 730
Quoted 10 lines
drivers/dma/sh/rcar-dmac.c +10
-0+{ +unsigned int i =0 ; + + do { + u32 chcr = rcar_dmac_chan_read(chan, RCAR_DMACHCR); + + if (!(chcr & RCAR_DMACHCR_DE)) + return 0; + cpu_relax(); + dev_dbg(chan->chan.device->dev, "DMA xfer couldn't be stopped");And user has no way of knowing this on production system
Quoted 10 lines
drivers/dma/sh/rcar-dmac.c +6
-2+ }while (++i <NR_READS_TO_WAIT ); -static void rcar_dmac_chan_halt (struct rcar_dmac_chan *chan) +return -EBUSY ; +} + +/* Called with chan lock held */ +static int rcar_dmac_chan_halt (struct rcar_dmac_chan *chan) { -u32 chcr =rcar_dmac_chan_read (chan,RCAR_DMACHCR );drivers/dma/sh/rcar-dmac.c static int rcar_dmac_fill_hwdesc(struct rcar_dmac_chan *chan, · line 748
Quoted 10 lines
drivers/dma/sh/rcar-dmac.c +6
-0+u32 chcr; +int ret; + chcr =rcar_dmac_chan_read (chan,RCAR_DMACHCR ); chcr &= ~(RCAR_DMACHCR_DSE |RCAR_DMACHCR_DSIE |RCAR_DMACHCR_IE |RCAR_DMACHCR_TE |RCAR_DMACHCR_DE );rcar_dmac_chan_write (chan,RCAR_DMACHCR , chcr); + ret =rcar_dmac_wait_stop (chan); + +WARN_ON (ret <0 );What if we have broken board and will see dmesg storm for this, perhaps
WARN_ON_ONCEand also would be helpful to use the verbose version and print some meaningful message--
~Vinod
Hi Laurent,
Thank you for the review. Please see my comments below. Also please let me know if this code needs to be fixed on somewhat urgent basis since I am a little occupied with few other tasks. I'd try to prioritize it then
Best regards,
Hamza
Quoted 31 lines · Laurent Pinchart
Hello Muhammad,
Thank you for the patch.
Quoted 26 lines · On Tuesday 29 September 2015 22:44:43 [email protected] wrote:
From: Muhammad Hamza Farooq <[email protected]>
DMA engine does not stop instantaneously when transaction is going on (see datasheet). Wait has been added
Signed-off-by Muhammad Hamza Farooq <[email protected]>--- drivers/dma/sh/rcar-dmac.c | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-)drivers/dma/sh/rcar-dmac.c +7
-1@@ -716,14 +716,38 @@ static int rcar_dmac_fill_hwdesc(struct rcar_dmac_chan *chan, /* --------------------------------------------------------------------------- * Stop and reset */ +#define NR_READS_TO_WAIT 5/* number of times to check if DE = 0 */ +static inline int rcar_dmac_wait_stop (struct rcar_dmac_chan *chan) +{ +unsigned int i =0 ; + + do { + u32 chcr = rcar_dmac_chan_read(chan, RCAR_DMACHCR);
Quoted 8 lines
drivers/dma/sh/rcar-dmac.c static int rcar_dmac_fill_hwdesc(struct rcar_dmac_chan *chan, · line 730
Quoted 5 lines
drivers/dma/sh/rcar-dmac.c +5
-0+ +if (!(chcr &RCAR_DMACHCR_DE )) +return 0 ; +cpu_relax (); +dev_dbg (chan->chan.device->dev,"DMA xfer couldn't be stopped" );Would it make sense to move the message out of the loop and use
dev_err()? It seems like a pretty serious error.
It happens quite often so dev_err might be too noisy. After couple attempts (1-3) it stops so I think it is better to not make it dev_err
Quoted 5 lines
drivers/dma/sh/rcar-dmac.c static int rcar_dmac_fill_hwdesc(struct rcar_dmac_chan *chan, · line 731
Quoted 2 lines
drivers/dma/sh/rcar-dmac.c +1
-0+ }while (++i <NR_READS_TO_WAIT );How long does the DMA engine typically need to stop ? Is there a safe upper bound ?
I have tested it many times. The highest number of retries was 3 which occurred not very frequently. Normally it is 1-2
Quoted 12 lines
Quoted 12 lines
drivers/dma/sh/rcar-dmac.c +7
-2-static void rcar_dmac_chan_halt (struct rcar_dmac_chan *chan) +return -EBUSY ; +} + +/* Called with chan lock held */ +static int rcar_dmac_chan_halt (struct rcar_dmac_chan *chan) { -u32 chcr =rcar_dmac_chan_read (chan,RCAR_DMACHCR ); +u32 chcr; +int ret;
Quoted 8 lines
drivers/dma/sh/rcar-dmac.c static int rcar_dmac_fill_hwdesc(struct rcar_dmac_chan *chan, · line 746
Quoted 5 lines
drivers/dma/sh/rcar-dmac.c +2
-0+ chcr =rcar_dmac_chan_read (chan,RCAR_DMACHCR ); chcr &= ~(RCAR_DMACHCR_DSE |RCAR_DMACHCR_DSIE |RCAR_DMACHCR_IE |RCAR_DMACHCR_TE |RCAR_DMACHCR_DE );rcar_dmac_chan_write (chan,RCAR_DMACHCR , chcr); + ret =rcar_dmac_wait_stop (chan);As the
rcar_dmac_wait_stop()function is used here only I'd inline the code directly.
It is used in DMA_PAUSE operation as well
Quoted 5 lines
drivers/dma/sh/rcar-dmac.c static int rcar_dmac_fill_hwdesc(struct rcar_dmac_chan · line 747
Quoted 3 lines
drivers/dma/sh/rcar-dmac.c +2
-0+ +WARN_ON (ret <0 );If you use
dev_err()instead ofdev_dbg()above you could remove theWARN_on.
see comment about dev_err above
Quoted 12 lines
drivers/dma/sh/rcar-dmac.c static int rcar_dmac_fill_hwdesc(struct rcar_dmac_chan *chan, · line 753
Quoted 6 lines
drivers/dma/sh/rcar-dmac.c +2
-0+ +return ret; }static void rcar_dmac_chan_reinit (struct rcar_dmac_chan *chan)--
Regards,Laurent Pinchart
Hello Hamza,
(With a question for Morimoto-san below)
Quoted 5 lines · On Thursday 15 October 2015 18:08:56 Hamza Farooq wrote:
Hi Laurent,
Thank you for the review. Please see my comments below. Also please let me know if this code needs to be fixed on somewhat urgent basis since I am a little occupied with few other tasks. I'd try to prioritize it then
I don't think this is urgent, so no worries.
Quoted 40 lines · Laurent Pinchart
Quoted 22 lines · On Tuesday 29 September 2015 22:44:43 [email protected] wrote:
Quoted 21 lines
From: Muhammad Hamza Farooq <[email protected]>
DMA engine does not stop instantaneously when transaction is going on (see datasheet). Wait has been added
Signed-off-by Muhammad Hamza Farooq <[email protected]>---
drivers/dma/sh/rcar-dmac.c | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-)drivers/dma/sh/rcar-dmac.c +0
-0@@ -716,14 +716,38 @@ static int rcar_dmac_fill_hwdesc(struct rcar_dmac_chan *chan,/* ---------------------------------------------------------------------- * Stop and reset */ Quoted 16 lines
Quoted 4 lines
drivers/dma/sh/rcar-dmac.c +4
-0+#define NR_READS_TO_WAIT 5/* number of times to check if DE = 0 */ +static inline int rcar_dmac_wait_stop (struct rcar_dmac_chan *chan) +{ +unsigned int i =0 ;drivers/dma/sh/rcar-dmac.c static int rcar_dmac_fill_hwdesc(struct rcar_dmac_chan *chan, · line 732
Quoted 10 lines
drivers/dma/sh/rcar-dmac.c +8
-0+ + do { + u32 chcr = rcar_dmac_chan_read(chan, RCAR_DMACHCR); + + if (!(chcr & RCAR_DMACHCR_DE)) + return 0; + cpu_relax(); + dev_dbg(chan->chan.device->dev, "DMA xfer couldn't be stopped");Would it make sense to move the message out of the loop and use
dev_err()? It seems like a pretty serious error.
Quoted 2 lines
It happens quite often so
dev_errmight be too noisy. After couple attempts (1-3) it stops so I think it is better to not make itdev_err
That's why I mentioned moving it outside of the loop and only printing it when the DMA channel doesn't stop.
Quoted 7 lines
Quoted 4 lines
drivers/dma/sh/rcar-dmac.c static int rcar_dmac_fill_hwdesc(struct rcar_dmac_chan *chan, · line 731
Quoted 1 line
drivers/dma/sh/rcar-dmac.c +1
-0+ }while (++i <NR_READS_TO_WAIT );How long does the DMA engine typically need to stop ? Is there a safe upper bound ?
I have tested it many times. The highest number of retries was 3 which occurred not very frequently. Normally it is 1-2
Morimoto-san, could you check with the hardware team if there's a worst case guarantee regarding how long the channel could take to stop ?
Quoted 20 lines
Quoted 11 lines
Quoted 11 lines
drivers/dma/sh/rcar-dmac.c +7
-2-static void rcar_dmac_chan_halt (struct rcar_dmac_chan *chan) +return -EBUSY ; +} + +/* Called with chan lock held */ +static int rcar_dmac_chan_halt (struct rcar_dmac_chan *chan) { -u32 chcr =rcar_dmac_chan_read (chan,RCAR_DMACHCR ); +u32 chcr; +int ret;Quoted 8 lines
drivers/dma/sh/rcar-dmac.c static int rcar_dmac_fill_hwdesc(struct rcar_dmac_chan *chan, · line 746
Quoted 5 lines
drivers/dma/sh/rcar-dmac.c +2
-0+ chcr =rcar_dmac_chan_read (chan,RCAR_DMACHCR ); chcr &= ~(RCAR_DMACHCR_DSE |RCAR_DMACHCR_DSIE |RCAR_DMACHCR_IE |RCAR_DMACHCR_TE |RCAR_DMACHCR_DE );rcar_dmac_chan_write (chan,RCAR_DMACHCR , chcr); + ret =rcar_dmac_wait_stop (chan);As the
rcar_dmac_wait_stop()function is used here only I'd inline the code directly.
Quoted 1 line
It is used in
DMA_PAUSEoperation as well
Let's resolve the DMA pause issue and then decide :-)
Quoted 13 lines
Quoted 5 lines
drivers/dma/sh/rcar-dmac.c static int rcar_dmac_fill_hwdesc(struct · line 751
Quoted 2 lines
drivers/dma/sh/rcar-dmac.c +2
-0+ +WARN_ON (ret <0 );If you use
dev_err()instead ofdev_dbg()above you could remove theWARN_on.see comment about
dev_erraboveQuoted 5 lines
Quoted 5 lines
drivers/dma/sh/rcar-dmac.c +2
-0+ +return ret;}
static void
rcar_dmac_chan_reinit(struct rcar_dmac_chan *chan)
Signature · 3 lines
Regards, Laurent Pinchart
Hi Laurent,
Quoted 53 lines · Laurent Pinchart
Hello Hamza,
(With a question for Morimoto-san below)
Quoted 5 lines · On Thursday 15 October 2015 18:08:56 Hamza Farooq wrote:
Hi Laurent,
Thank you for the review. Please see my comments below. Also please let me know if this code needs to be fixed on somewhat urgent basis since I am a little occupied with few other tasks. I'd try to prioritize it then
I don't think this is urgent, so no worries.
Quoted 40 lines · Laurent Pinchart
Quoted 38 lines · On Tuesday 29 September 2015 22:44:43 [email protected] wrote:
Quoted 25 lines
From: Muhammad Hamza Farooq <[email protected]>
DMA engine does not stop instantaneously when transaction is going on (see datasheet). Wait has been added
Signed-off-by Muhammad Hamza Farooq <[email protected]>---
drivers/dma/sh/rcar-dmac.c | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-)drivers/dma/sh/rcar-dmac.c +4
-0@@ -716,14 +716,38 @@ static int rcar_dmac_fill_hwdesc(struct rcar_dmac_chan *chan,/* ---------------------------------------------------------------------- * Stop and reset */ +#define NR_READS_TO_WAIT 5/* number of times to check if DE = 0 */ +static inline int rcar_dmac_wait_stop (struct rcar_dmac_chan *chan) +{ +unsigned int i =0 ;drivers/dma/sh/rcar-dmac.c static int rcar_dmac_fill_hwdesc(struct · line 734
Quoted 10 lines
drivers/dma/sh/rcar-dmac.c +8
-0+ + do { + u32 chcr = rcar_dmac_chan_read(chan, RCAR_DMACHCR); + + if (!(chcr & RCAR_DMACHCR_DE)) + return 0; + cpu_relax(); + dev_dbg(chan->chan.device->dev, "DMA xfer couldn't be stopped");Would it make sense to move the message out of the loop and use
dev_err()? It seems like a pretty serious error.
Quoted 5 lines
Quoted 2 lines
It happens quite often so
dev_errmight be too noisy. After couple attempts (1-3) it stops so I think it is better to not make itdev_errThat's why I mentioned moving it outside of the loop and only printing it when the DMA channel doesn't stop.
I don't think it is a good idea to notify the user again and again about it, specially when it is handled by this patch. It occurs quite a lot (for me, a lot means around 10 times for a data transfer of 7 MB over sh-sci at 150 kbps)
Quoted 48 lines
Quoted 8 lines
Quoted 5 lines
drivers/dma/sh/rcar-dmac.c static int rcar_dmac_fill_hwdesc(struct rcar_dmac_chan *chan, · line 731
Quoted 2 lines
drivers/dma/sh/rcar-dmac.c +1
-0+ }while (++i <NR_READS_TO_WAIT );How long does the DMA engine typically need to stop ? Is there a safe upper bound ?
I have tested it many times. The highest number of retries was 3 which occurred not very frequently. Normally it is 1-2
Morimoto-san, could you check with the hardware team if there's a worst case guarantee regarding how long the channel could take to stop ?
Quoted 20 lines
Quoted 11 lines
Quoted 11 lines
drivers/dma/sh/rcar-dmac.c +7
-2-static void rcar_dmac_chan_halt (struct rcar_dmac_chan *chan) +return -EBUSY ; +} + +/* Called with chan lock held */ +static int rcar_dmac_chan_halt (struct rcar_dmac_chan *chan) { -u32 chcr =rcar_dmac_chan_read (chan,RCAR_DMACHCR ); +u32 chcr; +int ret;Quoted 8 lines
drivers/dma/sh/rcar-dmac.c static int rcar_dmac_fill_hwdesc(struct rcar_dmac_chan *chan, · line 746
Quoted 5 lines
drivers/dma/sh/rcar-dmac.c +2
-0+ chcr =rcar_dmac_chan_read (chan,RCAR_DMACHCR ); chcr &= ~(RCAR_DMACHCR_DSE |RCAR_DMACHCR_DSIE |RCAR_DMACHCR_IE |RCAR_DMACHCR_TE |RCAR_DMACHCR_DE );rcar_dmac_chan_write (chan,RCAR_DMACHCR , chcr); + ret =rcar_dmac_wait_stop (chan);As the
rcar_dmac_wait_stop()function is used here only I'd inline the code directly.Quoted 1 line
It is used in
DMA_PAUSEoperation as wellLet's resolve the DMA pause issue and then decide :-)
Quoted 12 lines
Quoted 5 lines
drivers/dma/sh/rcar-dmac.c static int rcar_dmac_fill_hwdesc(struct · line 751
Quoted 2 lines
drivers/dma/sh/rcar-dmac.c +2
-0+ +WARN_ON (ret <0 );If you use
dev_err()instead ofdev_dbg()above you could remove theWARN_on.see comment about
dev_erraboveQuoted 4 lines
Quoted 4 lines
drivers/dma/sh/rcar-dmac.c +2
-0+ +return ret;}
Quoted 7 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
static void
rcar_dmac_chan_reinit(struct rcar_dmac_chan *chan)--
Regards,Laurent Pinchart
Best,
Hamza
Hi Hamza,
Quoted 53 lines · On Monday 19 October 2015 22:54:53 Hamza Farooq wrote:
Quoted 52 lines · Laurent Pinchart
Quoted 5 lines · On Thursday 15 October 2015 18:08:56 Hamza Farooq wrote:
Hi Laurent,
Thank you for the review. Please see my comments below. Also please let me know if this code needs to be fixed on somewhat urgent basis since I am a little occupied with few other tasks. I'd try to prioritize it then
I don't think this is urgent, so no worries.
Quoted 42 lines · Laurent Pinchart
Quoted 22 lines · On Tuesday 29 September 2015 22:44:43 [email protected] wrote:
Quoted 21 lines
From: Muhammad Hamza Farooq <[email protected]>
DMA engine does not stop instantaneously when transaction is going on (see datasheet). Wait has been added
Signed-off-by Muhammad Hamza Farooq <[email protected]>---
drivers/dma/sh/rcar-dmac.c | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-)drivers/dma/sh/rcar-dmac.c +0
-0@@ -716,14 +716,38 @@ static int rcar_dmac_fill_hwdesc(struct rcar_dmac_chan *chan,/* ------------------------------------------------------------------- * Stop and reset */ Quoted 16 lines
drivers/dma/sh/rcar-dmac.c static int rcar_dmac_fill_hwdesc(struct rcar_dmac_chan *chan,
Quoted 13 lines
drivers/dma/sh/rcar-dmac.c +12
-0+#define NR_READS_TO_WAIT 5/* number of times to check if DE = 0 */ +static inline int rcar_dmac_wait_stop (struct rcar_dmac_chan *chan) +{ +unsigned int i =0 ; + + do { + u32 chcr = rcar_dmac_chan_read(chan, RCAR_DMACHCR); + + if (!(chcr & RCAR_DMACHCR_DE)) + return 0; + cpu_relax(); + dev_dbg(chan->chan.device->dev, "DMA xfer couldn't be stopped");Would it make sense to move the message out of the loop and use
dev_err()? It seems like a pretty serious error.It happens quite often so
dev_errmight be too noisy. After couple attempts (1-3) it stops so I think it is better to not make itdev_err
Quoted 7 lines
Quoted 2 lines
That's why I mentioned moving it outside of the loop and only printing it when the DMA channel doesn't stop.
I don't think it is a good idea to notify the user again and again about it, specially when it is handled by this patch. It occurs quite a lot (for me, a lot means around 10 times for a data transfer of 7 MB over sh-sci at 150 kbps)
I think there's some miscommunication going on. What I meant is
#define NR_READS_TO_WAIT 5 /* number of times to check if DE = 0 */
static inline int rcar_dmac_wait_stop(struct rcar_dmac_chan *chan)
{
unsigned int i;
for (i = 0; i < NR_READS_TO_WAIT; ++i) {
u32 chcr = rcar_dmac_chan_read(chan, RCAR_DMACHCR);
if (!(chcr & RCAR_DMACHCR_DE))
return 0;
cpu_relax();
}
dev_err(chan->chan.device->dev, "DMA xfer couldn't be stopped");
return -EBUSY;
}Signature · 3 lines
Regards, Laurent Pinchart
Hi Laurent,
Quoted 69 lines · Laurent Pinchart
Hi Hamza,
Quoted 53 lines · On Monday 19 October 2015 22:54:53 Hamza Farooq wrote:
Quoted 52 lines · Laurent Pinchart
Quoted 5 lines · On Thursday 15 October 2015 18:08:56 Hamza Farooq wrote:
Hi Laurent,
Thank you for the review. Please see my comments below. Also please let me know if this code needs to be fixed on somewhat urgent basis since I am a little occupied with few other tasks. I'd try to prioritize it then
I don't think this is urgent, so no worries.
Quoted 42 lines · Laurent Pinchart
Quoted 22 lines · On Tuesday 29 September 2015 22:44:43 [email protected] wrote:
Quoted 21 lines
From: Muhammad Hamza Farooq <[email protected]>
DMA engine does not stop instantaneously when transaction is going on (see datasheet). Wait has been added
Signed-off-by Muhammad Hamza Farooq <[email protected]>---
drivers/dma/sh/rcar-dmac.c | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-)drivers/dma/sh/rcar-dmac.c +0
-0@@ -716,14 +716,38 @@ static int rcar_dmac_fill_hwdesc(struct rcar_dmac_chan *chan,/* ------------------------------------------------------------------- * Stop and reset */ Quoted 16 lines
drivers/dma/sh/rcar-dmac.c static int rcar_dmac_fill_hwdesc(struct rcar_dmac_chan *chan,
Quoted 13 lines
drivers/dma/sh/rcar-dmac.c +12
-0+#define NR_READS_TO_WAIT 5/* number of times to check if DE = 0 */ +static inline int rcar_dmac_wait_stop (struct rcar_dmac_chan *chan) +{ +unsigned int i =0 ; + + do { + u32 chcr = rcar_dmac_chan_read(chan, RCAR_DMACHCR); + + if (!(chcr & RCAR_DMACHCR_DE)) + return 0; + cpu_relax(); + dev_dbg(chan->chan.device->dev, "DMA xfer couldn't be stopped");Would it make sense to move the message out of the loop and use
dev_err()? It seems like a pretty serious error.It happens quite often so
dev_errmight be too noisy. After couple attempts (1-3) it stops so I think it is better to not make itdev_errQuoted 7 lines
Quoted 2 lines
That's why I mentioned moving it outside of the loop and only printing it when the DMA channel doesn't stop.
I don't think it is a good idea to notify the user again and again about it, specially when it is handled by this patch. It occurs quite a lot (for me, a lot means around 10 times for a data transfer of 7 MB over sh-sci at 150 kbps)
I think there's some miscommunication going on. What I meant is
#define
NR_READS_TO_WAIT5 /* number of times to check if DE = 0 */static inline int
rcar_dmac_wait_stop(struct rcar_dmac_chan *chan)
Quoted 14 lines
{
unsigned int i;
for (i = 0; i < NR_READS_TO_WAIT; ++i) {
u32 chcr = rcar_dmac_chan_read(chan, RCAR_DMACHCR);
if (!(chcr & RCAR_DMACHCR_DE))
return 0;
cpu_relax();
}
dev_err(chan->chan.device->dev, "DMA xfer couldn't be stopped");
return -EBUSY;
}ah ok, I understood it as displaying error every time it does not stop. Yea this makes sense. As a DMA engine user, I would like to see the information in at least debug output though, that DMA did not stop in first attempt. So what do you say about keeping the dev_dbg message in the loop and adding your line (dev_err) outside?
Quoted 6 lines
--
Regards,Laurent Pinchart
Hi Laurent
# add Niklas
Sorry for my suport late response.
Thanks Niklas for reminder
Quoted 1 line
(With a question for Morimoto-san below)
(snip)
Quoted 10 lines
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
+ } while (++i <
NR_READS_TO_WAIT);How long does the DMA engine typically need to stop ? Is there a safe upper bound ?
I have tested it many times. The highest number of retries was 3 which occurred not very frequently. Normally it is 1-2
Morimoto-san, could you check with the hardware team if there's a worst case guarantee regarding how long the channel could take to stop ?
You need to wait maximum 0.7ms for it.
both for Gen2/Gen3.
In worst case, it needs 8 request times.
If 1 request is 20,000 cycle
20,000cycle x 8request x [4ns/cylce] = 640,000ns > 700us
Hi Morimoto-san,
Quoted 21 lines · On Wednesday 08 Jun 2016 10:05:09 Kuninori Morimoto wrote:
Hi Laurent
# add NiklasSorry for my suport late response.
Thanks Niklas for reminderQuoted 1 line
(With a question for Morimoto-san below)
(snip)
Quoted 10 lines
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
+ } while (++i <
NR_READS_TO_WAIT);How long does the DMA engine typically need to stop ? Is there a safe upper bound ?
I have tested it many times. The highest number of retries was 3 which occurred not very frequently. Normally it is 1-2
Morimoto-san, could you check with the hardware team if there's a worst case guarantee regarding how long the channel could take to stop ?
Quoted 6 lines
You need to wait maximum 0.7ms for it.
both for Gen2/Gen3.
In worst case, it needs 8 request times.
If 1 request is 20,000 cycle20,000cycle x 8request x [4ns/cylce] = 640,000ns > 700us
And we're calling the wait function both from interrupt context and from user context with a spinlock held. I'm afraid that's not acceptable, we can't busy- loop for so long with interrupts disabled.
Signature · 3 lines
Regards, Laurent Pinchart