All of lore.kernel.org
 help / color / mirror / Atom feed
From: Greg KH <gregkh@linuxfoundation.org>
To: Lino Sanfilippo <LinoSanfilippo@gmx.de>
Cc: jirislaby@kernel.org, u.kleine-koenig@pengutronix.de,
	linux@armlinux.org.uk, richard.genoud@gmail.com,
	nicolas.ferre@microchip.com, alexandre.belloni@bootlin.com,
	ludovic.desroches@microchip.com, shawnguo@kernel.org,
	s.hauer@pengutronix.de, kernel@pengutronix.de,
	festevam@gmail.com, linux-imx@nxp.com, mcoquelin.stm32@gmail.com,
	alexandre.torgue@foss.st.com, linux-serial@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-stm32@st-md-mailman.stormreply.com, lukas@wunner.de
Subject: Re: [PATCH 2 1/9] serial: core: move RS485 configuration tasks from drivers into core
Date: Mon, 21 Feb 2022 19:39:56 +0100	[thread overview]
Message-ID: <YhPcfMtE7xhykgcI@kroah.com> (raw)
In-Reply-To: <20220216001803.637-2-LinoSanfilippo@gmx.de>

On Wed, Feb 16, 2022 at 01:17:55AM +0100, Lino Sanfilippo wrote:
> Several drivers that support setting the RS485 configuration via userspace
> implement one or more of the following tasks:
> 
> - in case of an invalid RTS configuration (both RTS after send and RTS on
>   send set or both unset) fall back to enable RTS on send and disable RTS
>   after send
> 
> - nullify the padding field of the returned serial_rs485 struct
> 
> - copy the configuration into the uart port struct
> 
> - limit RTS delays to 100 ms
> 
> Move these tasks into the serial core to make them generic and to provide
> a consistent behaviour among all drivers.
> 
> Signed-off-by: Lino Sanfilippo <LinoSanfilippo@gmx.de>
> ---
>  drivers/tty/serial/serial_core.c | 18 ++++++++++++++++++
>  include/uapi/linux/serial.h      |  3 +++
>  2 files changed, 21 insertions(+)
> 
> diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
> index 846192a7b4bf..a4f7e847d414 100644
> --- a/drivers/tty/serial/serial_core.c
> +++ b/drivers/tty/serial/serial_core.c
> @@ -1282,8 +1282,26 @@ static int uart_set_rs485_config(struct uart_port *port,
>  	if (copy_from_user(&rs485, rs485_user, sizeof(*rs485_user)))
>  		return -EFAULT;
>  
> +	/* pick sane settings if the user hasn't */
> +	if (!(rs485.flags & SER_RS485_RTS_ON_SEND) ==
> +	    !(rs485.flags & SER_RS485_RTS_AFTER_SEND)) {
> +		rs485.flags |= SER_RS485_RTS_ON_SEND;
> +		rs485.flags &= ~SER_RS485_RTS_AFTER_SEND;
> +	}
> +
> +	rs485.delay_rts_before_send = min_t(unsigned int,
> +					    rs485.delay_rts_before_send,
> +					    SER_RS485_MAX_RTS_DELAY);
> +	rs485.delay_rts_after_send = min_t(unsigned int,
> +					   rs485.delay_rts_after_send,
> +					   SER_RS485_MAX_RTS_DELAY);
> +	/* Return clean padding area to userspace */
> +	memset(rs485.padding, 0, sizeof(rs485.padding));
> +
>  	spin_lock_irqsave(&port->lock, flags);
>  	ret = port->rs485_config(port, &rs485);
> +	if (!ret)
> +		port->rs485 = rs485;
>  	spin_unlock_irqrestore(&port->lock, flags);
>  	if (ret)
>  		return ret;
> diff --git a/include/uapi/linux/serial.h b/include/uapi/linux/serial.h
> index fa6b16e5fdd8..859045a53231 100644
> --- a/include/uapi/linux/serial.h
> +++ b/include/uapi/linux/serial.h
> @@ -128,6 +128,9 @@ struct serial_rs485 {
>  							   (if supported) */
>  	__u32	delay_rts_before_send;	/* Delay before send (milliseconds) */
>  	__u32	delay_rts_after_send;	/* Delay after send (milliseconds) */
> +#define SER_RS485_MAX_RTS_DELAY		100		/* Max time with active
> +							   RTS before/after
> +							   data sent (msecs) */

Why is this a userspace value now?  What can userspace do with this
number?  Once we add this, it's fixed for forever.

thanks,

greg k-h

WARNING: multiple messages have this Message-ID (diff)
From: Greg KH <gregkh@linuxfoundation.org>
To: Lino Sanfilippo <LinoSanfilippo@gmx.de>
Cc: linux-arm-kernel@lists.infradead.org,
	alexandre.belloni@bootlin.com, festevam@gmail.com,
	mcoquelin.stm32@gmail.com, linux-serial@vger.kernel.org,
	richard.genoud@gmail.com, shawnguo@kernel.org,
	s.hauer@pengutronix.de, linux@armlinux.org.uk,
	alexandre.torgue@foss.st.com, ludovic.desroches@microchip.com,
	lukas@wunner.de, linux-imx@nxp.com, kernel@pengutronix.de,
	u.kleine-koenig@pengutronix.de, jirislaby@kernel.org,
	linux-stm32@st-md-mailman.stormreply.com,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2 1/9] serial: core: move RS485 configuration tasks from drivers into core
Date: Mon, 21 Feb 2022 19:39:56 +0100	[thread overview]
Message-ID: <YhPcfMtE7xhykgcI@kroah.com> (raw)
In-Reply-To: <20220216001803.637-2-LinoSanfilippo@gmx.de>

On Wed, Feb 16, 2022 at 01:17:55AM +0100, Lino Sanfilippo wrote:
> Several drivers that support setting the RS485 configuration via userspace
> implement one or more of the following tasks:
> 
> - in case of an invalid RTS configuration (both RTS after send and RTS on
>   send set or both unset) fall back to enable RTS on send and disable RTS
>   after send
> 
> - nullify the padding field of the returned serial_rs485 struct
> 
> - copy the configuration into the uart port struct
> 
> - limit RTS delays to 100 ms
> 
> Move these tasks into the serial core to make them generic and to provide
> a consistent behaviour among all drivers.
> 
> Signed-off-by: Lino Sanfilippo <LinoSanfilippo@gmx.de>
> ---
>  drivers/tty/serial/serial_core.c | 18 ++++++++++++++++++
>  include/uapi/linux/serial.h      |  3 +++
>  2 files changed, 21 insertions(+)
> 
> diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
> index 846192a7b4bf..a4f7e847d414 100644
> --- a/drivers/tty/serial/serial_core.c
> +++ b/drivers/tty/serial/serial_core.c
> @@ -1282,8 +1282,26 @@ static int uart_set_rs485_config(struct uart_port *port,
>  	if (copy_from_user(&rs485, rs485_user, sizeof(*rs485_user)))
>  		return -EFAULT;
>  
> +	/* pick sane settings if the user hasn't */
> +	if (!(rs485.flags & SER_RS485_RTS_ON_SEND) ==
> +	    !(rs485.flags & SER_RS485_RTS_AFTER_SEND)) {
> +		rs485.flags |= SER_RS485_RTS_ON_SEND;
> +		rs485.flags &= ~SER_RS485_RTS_AFTER_SEND;
> +	}
> +
> +	rs485.delay_rts_before_send = min_t(unsigned int,
> +					    rs485.delay_rts_before_send,
> +					    SER_RS485_MAX_RTS_DELAY);
> +	rs485.delay_rts_after_send = min_t(unsigned int,
> +					   rs485.delay_rts_after_send,
> +					   SER_RS485_MAX_RTS_DELAY);
> +	/* Return clean padding area to userspace */
> +	memset(rs485.padding, 0, sizeof(rs485.padding));
> +
>  	spin_lock_irqsave(&port->lock, flags);
>  	ret = port->rs485_config(port, &rs485);
> +	if (!ret)
> +		port->rs485 = rs485;
>  	spin_unlock_irqrestore(&port->lock, flags);
>  	if (ret)
>  		return ret;
> diff --git a/include/uapi/linux/serial.h b/include/uapi/linux/serial.h
> index fa6b16e5fdd8..859045a53231 100644
> --- a/include/uapi/linux/serial.h
> +++ b/include/uapi/linux/serial.h
> @@ -128,6 +128,9 @@ struct serial_rs485 {
>  							   (if supported) */
>  	__u32	delay_rts_before_send;	/* Delay before send (milliseconds) */
>  	__u32	delay_rts_after_send;	/* Delay after send (milliseconds) */
> +#define SER_RS485_MAX_RTS_DELAY		100		/* Max time with active
> +							   RTS before/after
> +							   data sent (msecs) */

Why is this a userspace value now?  What can userspace do with this
number?  Once we add this, it's fixed for forever.

thanks,

greg k-h

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

  parent reply	other threads:[~2022-02-21 18:40 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-16  0:17 Move RS485 implementation from drivers to serial core Lino Sanfilippo
2022-02-16  0:17 ` Lino Sanfilippo
2022-02-16  0:17 ` [PATCH 2 1/9] serial: core: move RS485 configuration tasks from drivers into core Lino Sanfilippo
2022-02-16  0:17   ` Lino Sanfilippo
2022-02-17 11:33   ` Lukas Wunner
2022-02-17 21:36     ` Lino Sanfilippo
2022-02-17 21:36       ` Lino Sanfilippo
2022-02-21 18:39   ` Greg KH [this message]
2022-02-21 18:39     ` Greg KH
2022-02-21 23:19     ` Lino Sanfilippo
2022-02-21 23:19       ` Lino Sanfilippo
2022-02-16  0:17 ` [PATCH 2 2/9] serial: amba-pl011: remove redundant code in rs485_config Lino Sanfilippo
2022-02-16  0:17   ` Lino Sanfilippo
2022-02-16  0:17 ` [PATCH 2 3/9] serial: stm32: " Lino Sanfilippo
2022-02-16  0:17   ` Lino Sanfilippo
2022-02-16  0:17 ` [PATCH 2 4/9] serial: sc16is7xx: remove redundant check " Lino Sanfilippo
2022-02-16  0:17   ` Lino Sanfilippo
2022-02-17 11:47   ` Lukas Wunner
2022-02-17 22:11     ` Lino Sanfilippo
2022-02-17 22:11       ` Lino Sanfilippo
2022-02-16  0:17 ` [PATCH 2 5/9] serial: omap: remove redundant code " Lino Sanfilippo
2022-02-16  0:17   ` Lino Sanfilippo
2022-02-16  0:18 ` [PATCH 2 6/9] serial: max310: remove redundant memset " Lino Sanfilippo
2022-02-16  0:18   ` Lino Sanfilippo
2022-02-16  0:18 ` [PATCH 2 7/9] serial: imx: remove redundant assignment " Lino Sanfilippo
2022-02-16  0:18   ` Lino Sanfilippo
2022-02-16 17:43   ` Uwe Kleine-König
2022-02-16 17:43     ` Uwe Kleine-König
2022-02-16  0:18 ` [PATCH 2 8/9] serial: fsl_lpuart: remove redundant code in rs485_config functions Lino Sanfilippo
2022-02-16  0:18   ` Lino Sanfilippo
2022-02-16  0:18 ` [PATCH 2 9/9] serial: atmel: remove redundant assignment in rs485_config Lino Sanfilippo
2022-02-16  0:18   ` Lino Sanfilippo
2022-02-17  9:22   ` Richard Genoud
2022-02-17  9:22     ` Richard Genoud

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YhPcfMtE7xhykgcI@kroah.com \
    --to=gregkh@linuxfoundation.org \
    --cc=LinoSanfilippo@gmx.de \
    --cc=alexandre.belloni@bootlin.com \
    --cc=alexandre.torgue@foss.st.com \
    --cc=festevam@gmail.com \
    --cc=jirislaby@kernel.org \
    --cc=kernel@pengutronix.de \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-imx@nxp.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=linux-stm32@st-md-mailman.stormreply.com \
    --cc=linux@armlinux.org.uk \
    --cc=ludovic.desroches@microchip.com \
    --cc=lukas@wunner.de \
    --cc=mcoquelin.stm32@gmail.com \
    --cc=nicolas.ferre@microchip.com \
    --cc=richard.genoud@gmail.com \
    --cc=s.hauer@pengutronix.de \
    --cc=shawnguo@kernel.org \
    --cc=u.kleine-koenig@pengutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.