Received: by 2002:a05:7412:f589:b0:e2:908c:2ebd with SMTP id eh9csp720908rdb; Tue, 31 Oct 2023 23:50:39 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGY56/kenuInkvH9sPc+1pt3XolBKWEFcnDaDENNAEZ7ow9McirW1Lo/6L6MVfCUnT75nsa X-Received: by 2002:a17:902:ea10:b0:1cc:56b3:efc5 with SMTP id s16-20020a170902ea1000b001cc56b3efc5mr6741753plg.21.1698821439304; Tue, 31 Oct 2023 23:50:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698821439; cv=none; d=google.com; s=arc-20160816; b=WZAGXW7PE12Qp6B5q9VVw1QpDKbopCGISWppx0nS+zIqSMjSFHkVAVsJ0hdJMxtD3A I/lJrT0brImIZFSRT0Idr4mbw5xho7y+SopLrRISQFqY9hMec4UUvD4MjcoplNjk2cpY DCzzaIIsBZ8HOEvvjdNOKjr6p1CcY4hFXOFjJMrnQMKRuz6snvPnjcCWh457o0mfXntv aZZUUY09eLKP/62sgCll/6+ZyfjyveD0yKn3q0uiC3nEeDq4/hKCW9Enet3dMTMGAXRA vu/7DzrSuyjXEf8rVEbYNROiPqv+Zsh3G6liSl/OAcrKarg2VG+lXtvdRaqkztOYRjT/ T4DQ== 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=EabtA2Ue2K1L82hhGAgB96H16vkxzK4gewp0dwwBlbQ=; fh=N3XrWI8FGPZ1oyn2NirsQ7Y4cPzZzZtGDDjMl9sGykA=; b=jl8lXePJzqaR5qYLRCGtL/Pl980CI+lHAhe2JbufgHlql5Sp9gjFWXBLSoG2xnR/8F C2lecMwN+zeSu73e5gvhZQ3lSGyR59y2ogBQS4HSi1pbfe4YqD1pWmAZQY1G2iNXMGWj 86RORYO6VRee5nkLpR+TrscfxvOb1gPez/k/JfKjUbLuAG513O2ZxVF2Qrg0YfMgHhoC /rzwb5m7dyl0Y7bqDlnVAFdJQB3BEdCvxAaw6cWqVcT+jV+k5FBZEcHr89UGZu8f2vJF xIYRRWd2Br3m/u737ojKU/n790xv8qHXE1jbwRlx4eStntncCtWOzJVxY5761gGtRQE7 gF+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=zz4teDGV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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 pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id u6-20020a170902e5c600b001c32fe6cdf9si2489501plf.386.2023.10.31.23.50.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Oct 2023 23:50:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=zz4teDGV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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 out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id DF1518082A9A; Tue, 31 Oct 2023 23:50:16 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345130AbjKAGuD (ORCPT + 99 others); Wed, 1 Nov 2023 02:50:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33064 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231240AbjKAGuC (ORCPT ); Wed, 1 Nov 2023 02:50:02 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9EA35A6; Tue, 31 Oct 2023 23:49:56 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B5249C433C8; Wed, 1 Nov 2023 06:49:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1698821396; bh=IrJZzwa1LgUljgZ2pNJ6BxSyMe71q3iklIBfrKxqK5g=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=zz4teDGVyicLH+2JW0PTJ/4ys7ufZO5iW4ESyOqVpIzH++E1HRi7nYG3N+BJCa6ja sWDNEPGZ6CyFu0VTP3itptGAxbgW+oGvrnMTZSmA38HcsW6ND8od9LDYmCznkCNNSB pvWFb3+LKGTKPu2DkztOkcBPwFeWrgQHjxLfTOyA= Date: Wed, 1 Nov 2023 07:49:48 +0100 From: Greg Kroah-Hartman To: Crescent CY Hsieh Cc: Jiri Slaby , linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org Subject: Re: [PATCH v2] tty: serial: Add RS422 flag to struct serial_rs485 Message-ID: <2023110127-wireless-candy-c298@gregkh> References: <20231101064404.45711-1-crescentcy.hsieh@moxa.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231101064404.45711-1-crescentcy.hsieh@moxa.com> X-Spam-Status: No, score=-1.3 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Tue, 31 Oct 2023 23:50:17 -0700 (PDT) On Wed, Nov 01, 2023 at 02:44:04PM +0800, Crescent CY Hsieh wrote: > Add "SER_RS422_ENABLED" flag within struct serial_rs485, so that serial > port can switching interface into RS422 if supported by using ioctl > command "TIOCSRS485". > > In case of interfaces confliction, add checks within > uart_sanitize_serial_rs485() such that only one of RS422/RS485 is set. > > Signed-off-by: Crescent CY Hsieh > > --- > Changes in v2: > - Revise the logic that checks whether RS422/RS485 are enabled > simultaneously. > > v1: https://lore.kernel.org/all/20231030053632.5109-1-crescentcy.hsieh@moxa.com/ > > --- > drivers/tty/serial/serial_core.c | 19 +++++++++++++++++-- > include/uapi/linux/serial.h | 4 ++++ > 2 files changed, 21 insertions(+), 2 deletions(-) > > diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c > index 831d03361..54a104c52 100644 > --- a/drivers/tty/serial/serial_core.c > +++ b/drivers/tty/serial/serial_core.c > @@ -1305,7 +1305,7 @@ static int uart_get_icount(struct tty_struct *tty, > > #define SER_RS485_LEGACY_FLAGS (SER_RS485_ENABLED | SER_RS485_RTS_ON_SEND | \ > SER_RS485_RTS_AFTER_SEND | SER_RS485_RX_DURING_TX | \ > - SER_RS485_TERMINATE_BUS) > + SER_RS485_TERMINATE_BUS | SER_RS422_ENABLED) A new flag is "legacy"? > > static int uart_check_rs485_flags(struct uart_port *port, struct serial_rs485 *rs485) > { > @@ -1371,11 +1371,26 @@ static void uart_sanitize_serial_rs485(struct uart_port *port, struct serial_rs4 > { > u32 supported_flags = port->rs485_supported.flags; > > - if (!(rs485->flags & SER_RS485_ENABLED)) { > + if (!(rs485->flags & (SER_RS485_ENABLED | SER_RS422_ENABLED))) { > memset(rs485, 0, sizeof(*rs485)); > return; > } > > + /* Pick sane setting if the user enables both interfaces */ > + if (rs485->flags & SER_RS485_ENABLED && rs485->flags & SER_RS422_ENABLED) { > + dev_warn_ratelimited(port->dev, > + "%s (%d): Invalid serial interface setting, using RS485 instead\n", > + port->name, port->line); Why is this ratelimited? What would cause lots of repeats of this? > + rs485->flags &= ~SER_RS422_ENABLED; > + } > + > + /* Clear other bits and return if RS422 is enabled */ > + if (rs485->flags & SER_RS422_ENABLED) { > + memset(rs485, 0, sizeof(*rs485)); > + rs485->flags |= SER_RS422_ENABLED; > + return; > + } > + > /* Pick sane settings if the user hasn't */ > if ((supported_flags & (SER_RS485_RTS_ON_SEND|SER_RS485_RTS_AFTER_SEND)) && > !(rs485->flags & SER_RS485_RTS_ON_SEND) == > diff --git a/include/uapi/linux/serial.h b/include/uapi/linux/serial.h > index 53bc1af67..427609fd5 100644 > --- a/include/uapi/linux/serial.h > +++ b/include/uapi/linux/serial.h > @@ -137,6 +137,8 @@ struct serial_icounter_struct { > * * %SER_RS485_ADDRB - Enable RS485 addressing mode. > * * %SER_RS485_ADDR_RECV - Receive address filter (enables @addr_recv). Requires %SER_RS485_ADDRB. > * * %SER_RS485_ADDR_DEST - Destination address (enables @addr_dest). Requires %SER_RS485_ADDRB. > + * > + * * %SER_RS422_ENABLED - RS422 enabled. > */ > struct serial_rs485 { > __u32 flags; > @@ -149,6 +151,8 @@ struct serial_rs485 { > #define SER_RS485_ADDR_RECV (1 << 7) > #define SER_RS485_ADDR_DEST (1 << 8) > > +#define SER_RS422_ENABLED (1 << 9) Why the extra blank line before this? And why isn't it using the proper BIT() type macro instead (yeah, the others are not, I understand...) Also, what userspace code is going to use this? How is it tested? thanks, greg k-h