Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp4413329pxb; Mon, 21 Feb 2022 20:48:49 -0800 (PST) X-Google-Smtp-Source: ABdhPJyYUPq4VzzMDBzWmMpk/s6zZkT+jItdwy3vah2ZTt23XaxAZFwiSmc005Xt2/8OI7yiav1d X-Received: by 2002:a17:902:9a48:b0:14f:a377:ee7e with SMTP id x8-20020a1709029a4800b0014fa377ee7emr10712759plv.3.1645505329215; Mon, 21 Feb 2022 20:48:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645505329; cv=none; d=google.com; s=arc-20160816; b=SnjZQ1IH7hwlP+yh1B+X+0dBhY9CIJN0SqMdNBp+QrYihyWHO4O+VBdQp19WYiZ4xF rQekm6WmC6jiSWMjHQzT2Waq62x0iXgvSiS7dArMU1iUrdc2DTJyoh8qCCVigyf+70ZM Q2XVaZhG48fWPy7M3zJb45fK+jBjQDws5lNcoF/zX9f/rLbmF6qkCvG53TU9axi+J6+7 DdvQqTRjgIpfBq+3XCyYrcVDgyDrOArjfoe3lHwzLGrbpHCxgxleKsDhR7JW3rj9EhWt Rrn+Ib8opIp+jk8QABgWIUXRYcWUwTkOERwenyKjdCbL4qDGfxkriX03Ky9bNkLp+SWP JAuA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=me1ejOKh5mAZpnbA9QrSxNIU2w0kHVxnkcT5LnrncI8=; b=wLjUR9cN1rLjxuQWdkl8JyQKoo2RaocnjLjOp9GqA/2zmsyuu546BgVhYkBvqbgixf luva8hUqQR/C79iybZQHN7gKEcIqRlocek1dwqVsFv+Zr0K0R+HWUbLIpoNxlY6MUk/F uYSe16m7nL0929eXxjUfUDwu9qsk8V+DM4tqWZPjqL/6b4FAanG7ToiH7f83FYk6Rqf5 UP9ZFGz3KlKIfl94zGoSlfT8YuNsey4jmi1DjccVduyz19kS8JODLQJmDFqzKNn8Jxjd a/DPv9wnS05MMkhow5piShLSY0V+PGjwglSM1oVoD1W8Uo0Q5lYoEKvxDZsoFsj8XjDW OAoA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="pYW+0/Bu"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id h186si19590134pgc.30.2022.02.21.20.48.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Feb 2022 20:48:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="pYW+0/Bu"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 749135C365; Mon, 21 Feb 2022 20:29:48 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232038AbiBUSlD (ORCPT + 99 others); Mon, 21 Feb 2022 13:41:03 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:56860 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233254AbiBUSk0 (ORCPT ); Mon, 21 Feb 2022 13:40:26 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 14610195; Mon, 21 Feb 2022 10:40:02 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id C2AFAB811F3; Mon, 21 Feb 2022 18:40:00 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C894DC340E9; Mon, 21 Feb 2022 18:39:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1645468799; bh=TIouyKTrY9MePsjLZLYLg6ZFF8gkEtGp45zObJ6uN5o=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=pYW+0/BuOS+GOb9Lnz6lRJxJbKBzTzErbZuoZTtdX60lLN5pXWz2LyTqoNiYFJbFi prkXb8WGTQftUX43eBZGEvDvSXLrRWCOGZ/HWyQVhAoYAC9rM2T+D19S5UAUFeWVds KgVRbxksEU8RkGyNbgxBbmK1COFq6zRa+WnmaKFQ= Date: Mon, 21 Feb 2022 19:39:56 +0100 From: Greg KH To: Lino Sanfilippo 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 Message-ID: References: <20220216001803.637-1-LinoSanfilippo@gmx.de> <20220216001803.637-2-LinoSanfilippo@gmx.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220216001803.637-2-LinoSanfilippo@gmx.de> X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 > --- > 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