All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] serial: sh-sci: Stop dmaengine transfer in sci_stop_tx()
@ 2021-06-04  9:57 Yoshihiro Shimoda
  2021-06-04 10:21 ` Jiri Slaby
  0 siblings, 1 reply; 4+ messages in thread
From: Yoshihiro Shimoda @ 2021-06-04  9:57 UTC (permalink / raw)
  To: gregkh, jirislaby; +Cc: linux-serial, linux-renesas-soc, Yoshihiro Shimoda

Stop dmaengine transfer in sci_stop_tx(). Otherwise, the following
message is possible output when system enters suspend and while
transferring data, because clearing TIE bit in SCSCR is not able to
stop any dmaengine transfer.

    sh-sci e6550000.serial: ttySC1: Unable to drain transmitter

Notes:
 - sci_dma_stop_tx() is a macro in the .h file because struct sci_port
   is declared in the .c file and #ifdef should be in the .h file.
 - This patch uses dmaengine_terminate_async() so that we can apply
   this into longterm kernel v4.9.x or later.

Fixes: 73a19e4c0301 ("serial: sh-sci: Add DMA support.")
Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
---
 Changes from v1:
 - Don't put #ifdef in the .c file.
 - Update the commit description.
 https://lore.kernel.org/linux-renesas-soc/TY2PR01MB3692C545672195370487FA60D83C9@TY2PR01MB3692.jpnprd01.prod.outlook.com/T/#t
 
 drivers/tty/serial/sh-sci.c |  2 ++
 drivers/tty/serial/sh-sci.h | 16 ++++++++++++++++
 2 files changed, 18 insertions(+)

diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
index 4baf1316ea72..3793cf9f352c 100644
--- a/drivers/tty/serial/sh-sci.c
+++ b/drivers/tty/serial/sh-sci.c
@@ -610,6 +610,8 @@ static void sci_stop_tx(struct uart_port *port)
 	ctrl &= ~SCSCR_TIE;
 
 	serial_port_out(port, SCSCR, ctrl);
+
+	sci_dma_stop_tx(port);
 }
 
 static void sci_start_rx(struct uart_port *port)
diff --git a/drivers/tty/serial/sh-sci.h b/drivers/tty/serial/sh-sci.h
index c0dfe4382898..435c674af1ce 100644
--- a/drivers/tty/serial/sh-sci.h
+++ b/drivers/tty/serial/sh-sci.h
@@ -174,3 +174,19 @@ enum {
 	(((port)->type == PORT_SCI) ? SCI_TDxE_CLEAR : SCIF_TDxE_CLEAR)
 #define SCxSR_BREAK_CLEAR(port) \
 	(((port)->type == PORT_SCI) ? SCI_BREAK_CLEAR : SCIF_BREAK_CLEAR)
+
+#ifdef CONFIG_SERIAL_SH_SCI_DMA
+#define sci_dma_stop_tx(port)					\
+{								\
+	struct sci_port *s = to_sci_port(port);			\
+								\
+	if (s->chan_tx && !dma_submit_error(s->cookie_tx)) {	\
+		dmaengine_terminate_async(s->chan_tx);		\
+		s->cookie_tx = -EINVAL;				\
+	}							\
+}
+#else
+static inline void sci_dma_stop_tx(struct uart_port *port)
+{
+}
+#endif /* CONFIG_SERIAL_SH_SCI_DMA */
-- 
2.25.1


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

* Re: [PATCH v2] serial: sh-sci: Stop dmaengine transfer in sci_stop_tx()
  2021-06-04  9:57 [PATCH v2] serial: sh-sci: Stop dmaengine transfer in sci_stop_tx() Yoshihiro Shimoda
@ 2021-06-04 10:21 ` Jiri Slaby
  2021-06-04 10:28   ` Yoshihiro Shimoda
  0 siblings, 1 reply; 4+ messages in thread
From: Jiri Slaby @ 2021-06-04 10:21 UTC (permalink / raw)
  To: Yoshihiro Shimoda, gregkh; +Cc: linux-serial, linux-renesas-soc

On 04. 06. 21, 11:57, Yoshihiro Shimoda wrote:
> Stop dmaengine transfer in sci_stop_tx(). Otherwise, the following
> message is possible output when system enters suspend and while
> transferring data, because clearing TIE bit in SCSCR is not able to
> stop any dmaengine transfer.
> 
>      sh-sci e6550000.serial: ttySC1: Unable to drain transmitter
> 
> Notes:
>   - sci_dma_stop_tx() is a macro in the .h file because struct sci_port
>     is declared in the .c file and #ifdef should be in the .h file.
>   - This patch uses dmaengine_terminate_async() so that we can apply
>     this into longterm kernel v4.9.x or later.
> 
> Fixes: 73a19e4c0301 ("serial: sh-sci: Add DMA support.")
> Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
> ---
>   Changes from v1:
>   - Don't put #ifdef in the .c file.
>   - Update the commit description.
>   https://lore.kernel.org/linux-renesas-soc/TY2PR01MB3692C545672195370487FA60D83C9@TY2PR01MB3692.jpnprd01.prod.outlook.com/T/#t
>   
>   drivers/tty/serial/sh-sci.c |  2 ++
>   drivers/tty/serial/sh-sci.h | 16 ++++++++++++++++
>   2 files changed, 18 insertions(+)
> 
> diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
> index 4baf1316ea72..3793cf9f352c 100644
> --- a/drivers/tty/serial/sh-sci.c
> +++ b/drivers/tty/serial/sh-sci.c
> @@ -610,6 +610,8 @@ static void sci_stop_tx(struct uart_port *port)
>   	ctrl &= ~SCSCR_TIE;
>   
>   	serial_port_out(port, SCSCR, ctrl);
> +
> +	sci_dma_stop_tx(port);
>   }
>   
>   static void sci_start_rx(struct uart_port *port)
> diff --git a/drivers/tty/serial/sh-sci.h b/drivers/tty/serial/sh-sci.h
> index c0dfe4382898..435c674af1ce 100644
> --- a/drivers/tty/serial/sh-sci.h
> +++ b/drivers/tty/serial/sh-sci.h
> @@ -174,3 +174,19 @@ enum {
>   	(((port)->type == PORT_SCI) ? SCI_TDxE_CLEAR : SCIF_TDxE_CLEAR)
>   #define SCxSR_BREAK_CLEAR(port) \
>   	(((port)->type == PORT_SCI) ? SCI_BREAK_CLEAR : SCIF_BREAK_CLEAR)
> +
> +#ifdef CONFIG_SERIAL_SH_SCI_DMA
> +#define sci_dma_stop_tx(port)					\

Ouch. First, why this needs to be in a header? Second, please don't do 
this by a macro.

> +{								\
> +	struct sci_port *s = to_sci_port(port);			\
> +								\
> +	if (s->chan_tx && !dma_submit_error(s->cookie_tx)) {	\
> +		dmaengine_terminate_async(s->chan_tx);		\
> +		s->cookie_tx = -EINVAL;				\
> +	}							\
> +}
> +#else
> +static inline void sci_dma_stop_tx(struct uart_port *port)
> +{
> +}
> +#endif /* CONFIG_SERIAL_SH_SCI_DMA */
> 


-- 
js
suse labs

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

* RE: [PATCH v2] serial: sh-sci: Stop dmaengine transfer in sci_stop_tx()
  2021-06-04 10:21 ` Jiri Slaby
@ 2021-06-04 10:28   ` Yoshihiro Shimoda
  2021-06-04 11:38     ` gregkh
  0 siblings, 1 reply; 4+ messages in thread
From: Yoshihiro Shimoda @ 2021-06-04 10:28 UTC (permalink / raw)
  To: Jiri Slaby, gregkh; +Cc: linux-serial, linux-renesas-soc

Hi Jiri,

Thank you for your review!

> From: Jiri Slaby, Sent: Friday, June 4, 2021 7:22 PM
> 
> On 04. 06. 21, 11:57, Yoshihiro Shimoda wrote:
> > Stop dmaengine transfer in sci_stop_tx(). Otherwise, the following
> > message is possible output when system enters suspend and while
> > transferring data, because clearing TIE bit in SCSCR is not able to
> > stop any dmaengine transfer.
> >
> >      sh-sci e6550000.serial: ttySC1: Unable to drain transmitter
> >
> > Notes:
> >   - sci_dma_stop_tx() is a macro in the .h file because struct sci_port
> >     is declared in the .c file and #ifdef should be in the .h file.
> >   - This patch uses dmaengine_terminate_async() so that we can apply
> >     this into longterm kernel v4.9.x or later.
> >
> > Fixes: 73a19e4c0301 ("serial: sh-sci: Add DMA support.")
> > Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
> > ---
<snip>
> > diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
> > index 4baf1316ea72..3793cf9f352c 100644
> > --- a/drivers/tty/serial/sh-sci.c
> > +++ b/drivers/tty/serial/sh-sci.c
> > @@ -610,6 +610,8 @@ static void sci_stop_tx(struct uart_port *port)
> >   	ctrl &= ~SCSCR_TIE;
> >
> >   	serial_port_out(port, SCSCR, ctrl);
> > +
> > +	sci_dma_stop_tx(port);
> >   }
> >
> >   static void sci_start_rx(struct uart_port *port)
> > diff --git a/drivers/tty/serial/sh-sci.h b/drivers/tty/serial/sh-sci.h
> > index c0dfe4382898..435c674af1ce 100644
> > --- a/drivers/tty/serial/sh-sci.h
> > +++ b/drivers/tty/serial/sh-sci.h
> > @@ -174,3 +174,19 @@ enum {
> >   	(((port)->type == PORT_SCI) ? SCI_TDxE_CLEAR : SCIF_TDxE_CLEAR)
> >   #define SCxSR_BREAK_CLEAR(port) \
> >   	(((port)->type == PORT_SCI) ? SCI_BREAK_CLEAR : SCIF_BREAK_CLEAR)
> > +
> > +#ifdef CONFIG_SERIAL_SH_SCI_DMA
> > +#define sci_dma_stop_tx(port)					\
> 
> Ouch. First, why this needs to be in a header?

The v1 patch [1] putted #ifdef in .c file, so that I got feedback from Greg like below:
"Please do not put #ifdef in .c files, this should be possible without that."

[1]
https://lore.kernel.org/linux-renesas-soc/TY2PR01MB3692C545672195370487FA60D83C9@TY2PR01MB3692.jpnprd01.prod.outlook.com/T/#md5b58540e26a28ef1acddfc326c62bfde73e8e8a

> Second, please don't do this by a macro.

I got it. I'll try to fix this issue somehow...

Best regards,
Yoshihiro Shimoda


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

* Re: [PATCH v2] serial: sh-sci: Stop dmaengine transfer in sci_stop_tx()
  2021-06-04 10:28   ` Yoshihiro Shimoda
@ 2021-06-04 11:38     ` gregkh
  0 siblings, 0 replies; 4+ messages in thread
From: gregkh @ 2021-06-04 11:38 UTC (permalink / raw)
  To: Yoshihiro Shimoda; +Cc: Jiri Slaby, linux-serial, linux-renesas-soc

On Fri, Jun 04, 2021 at 10:28:19AM +0000, Yoshihiro Shimoda wrote:
> Hi Jiri,
> 
> Thank you for your review!
> 
> > From: Jiri Slaby, Sent: Friday, June 4, 2021 7:22 PM
> > 
> > On 04. 06. 21, 11:57, Yoshihiro Shimoda wrote:
> > > Stop dmaengine transfer in sci_stop_tx(). Otherwise, the following
> > > message is possible output when system enters suspend and while
> > > transferring data, because clearing TIE bit in SCSCR is not able to
> > > stop any dmaengine transfer.
> > >
> > >      sh-sci e6550000.serial: ttySC1: Unable to drain transmitter
> > >
> > > Notes:
> > >   - sci_dma_stop_tx() is a macro in the .h file because struct sci_port
> > >     is declared in the .c file and #ifdef should be in the .h file.
> > >   - This patch uses dmaengine_terminate_async() so that we can apply
> > >     this into longterm kernel v4.9.x or later.
> > >
> > > Fixes: 73a19e4c0301 ("serial: sh-sci: Add DMA support.")
> > > Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
> > > ---
> <snip>
> > > diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
> > > index 4baf1316ea72..3793cf9f352c 100644
> > > --- a/drivers/tty/serial/sh-sci.c
> > > +++ b/drivers/tty/serial/sh-sci.c
> > > @@ -610,6 +610,8 @@ static void sci_stop_tx(struct uart_port *port)
> > >   	ctrl &= ~SCSCR_TIE;
> > >
> > >   	serial_port_out(port, SCSCR, ctrl);
> > > +
> > > +	sci_dma_stop_tx(port);
> > >   }
> > >
> > >   static void sci_start_rx(struct uart_port *port)
> > > diff --git a/drivers/tty/serial/sh-sci.h b/drivers/tty/serial/sh-sci.h
> > > index c0dfe4382898..435c674af1ce 100644
> > > --- a/drivers/tty/serial/sh-sci.h
> > > +++ b/drivers/tty/serial/sh-sci.h
> > > @@ -174,3 +174,19 @@ enum {
> > >   	(((port)->type == PORT_SCI) ? SCI_TDxE_CLEAR : SCIF_TDxE_CLEAR)
> > >   #define SCxSR_BREAK_CLEAR(port) \
> > >   	(((port)->type == PORT_SCI) ? SCI_BREAK_CLEAR : SCIF_BREAK_CLEAR)
> > > +
> > > +#ifdef CONFIG_SERIAL_SH_SCI_DMA
> > > +#define sci_dma_stop_tx(port)					\
> > 
> > Ouch. First, why this needs to be in a header?
> 
> The v1 patch [1] putted #ifdef in .c file, so that I got feedback from Greg like below:
> "Please do not put #ifdef in .c files, this should be possible without that."

Yes, but that does not mean using a macro, please do this correctly.

thanks,

greg k-h

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

end of thread, other threads:[~2021-06-04 11:38 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-04  9:57 [PATCH v2] serial: sh-sci: Stop dmaengine transfer in sci_stop_tx() Yoshihiro Shimoda
2021-06-04 10:21 ` Jiri Slaby
2021-06-04 10:28   ` Yoshihiro Shimoda
2021-06-04 11:38     ` gregkh

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.