From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 64B08CCA473 for ; Mon, 27 Jun 2022 09:05:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232174AbiF0JF4 (ORCPT ); Mon, 27 Jun 2022 05:05:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58086 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233086AbiF0JFz (ORCPT ); Mon, 27 Jun 2022 05:05:55 -0400 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 35FE1634B; Mon, 27 Jun 2022 02:05:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1656320754; x=1687856754; h=date:from:to:cc:subject:in-reply-to:message-id: references:mime-version; bh=jcKmTKeNDN11ToKECGTcEIIGoAMkwCReSD4tvZEnNOU=; b=gh89DNe4LlIV3cmFQXzkOR5I57fix3KhHHbqM5idztRcTyFZtuUk5W+5 DRHzumX06f2vLeVrABUuXKQfMHry2HtRYW/QDZLMW0040hF9y7dEyV15l CLDl/LLRT/UJzeDvnpubz5QQfzJVKaqWIPjqGGdKsMgjH0c550WbEfJV1 /KParq2Eo93HyjRIVCoFdRWnICVbzhYHucW5QsikB0N4MySnwbqA6FNDx d79zPv8cE73mNatcjAmW2JVYO1d650Vyab4Y7tj0XG4UsS/urrhdSO0ow AvUqprzvoUlP3r/nRuh5HFG7RDpdFuurNCWmxpbJHyB0KVDpM6DG74owq g==; X-IronPort-AV: E=McAfee;i="6400,9594,10390"; a="367719636" X-IronPort-AV: E=Sophos;i="5.92,225,1650956400"; d="scan'208";a="367719636" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jun 2022 02:05:53 -0700 X-IronPort-AV: E=Sophos;i="5.92,225,1650956400"; d="scan'208";a="646348400" Received: from gretavix-mobl3.amr.corp.intel.com ([10.249.43.78]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jun 2022 02:05:49 -0700 Date: Mon, 27 Jun 2022 12:05:50 +0300 (EEST) From: =?ISO-8859-15?Q?Ilpo_J=E4rvinen?= To: Lukas Wunner cc: Lino Sanfilippo , Greg Kroah-Hartman , Jiri Slaby , robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, Andy Shevchenko , vz@mleia.com, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, linux-serial , LKML , p.rosenberger@kunbus.com, Lino Sanfilippo Subject: Re: [PATCH 1/8] serial: core: only get RS485 termination gpio if supported In-Reply-To: <20220625194951.GA2879@wunner.de> Message-ID: References: <20220622154659.8710-1-LinoSanfilippo@gmx.de> <20220622154659.8710-2-LinoSanfilippo@gmx.de> <20220625194951.GA2879@wunner.de> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org On Sat, 25 Jun 2022, Lukas Wunner wrote: > On Wed, Jun 22, 2022 at 05:46:52PM +0200, Lino Sanfilippo wrote: > > In uart_get_rs485_mode() only try to get a termination GPIO if RS485 bus > > termination is supported by the driver. > [...] > > --- a/drivers/tty/serial/serial_core.c > > +++ b/drivers/tty/serial/serial_core.c > > @@ -3384,17 +3384,20 @@ int uart_get_rs485_mode(struct uart_port *port) > > rs485conf->flags |= SER_RS485_RTS_AFTER_SEND; > > } > > > > - /* > > - * Disabling termination by default is the safe choice: Else if many > > - * bus participants enable it, no communication is possible at all. > > - * Works fine for short cables and users may enable for longer cables. > > - */ > > - port->rs485_term_gpio = devm_gpiod_get_optional(dev, "rs485-term", > > - GPIOD_OUT_LOW); > > - if (IS_ERR(port->rs485_term_gpio)) { > > - ret = PTR_ERR(port->rs485_term_gpio); > > - port->rs485_term_gpio = NULL; > > - return dev_err_probe(dev, ret, "Cannot get rs485-term-gpios\n"); > > + if (port->rs485_supported->flags & SER_RS485_TERMINATE_BUS) { > > So I think linux-next commit be2e2cb1d281 ("serial: Sanitize rs485_struct") > contains a mistake in that it forces drivers to set SER_RS485_TERMINATE_BUS > in their rs485_supported->flags to allow enabling bus termination. > > That's wrong because *every* rs485-capable driver can enable bus > termination if a GPIO has been defined for that in the DT. Do you mean every em485 using driver? Otherwise I don't see this "forces drivers to set" happening anywhere in the code? You're partially right because there are other bugs in this area such as the one you propose a fix below. While I was making the sanitization series, I entirely missed some parts related to termination because SER_RS485_TERMINATE_BUS is seemingly not set/handled correctly by the core. Another thing that looks a bug is that on subsequent call to TIOCSRS485, w/o SER_RS485_TERMINATE_BUS nothing happens (for non-em485 driver, that is)? It seems to be taken care by 2/8 of this series though, I think. But it should be properly marked as Fixes: ... in that case although nobody has complained about it so likely not a huge issue to anyone. > In fact, another commit which was applied as part of the same series, > ebe2cf736a04 ("serial: pl011: Fill in rs485_supported") does not set > SER_RS485_TERMINATE_BUS in amba-pl011.c's flags and thus forbids the > driver from enabling bus termination, even though we know there are > products out there which support bus termination on the pl011 through > a GPIO (Revolution Pi RevPi Compact, Revpi Flat). > > I think what you want to do is amend uart_get_rs485_mode() to set > SER_RS485_TERMINATE_BUS in port->rs485_supported_flags if a GPIO > was found in the DT. Instead of the change proposed above. That seems appropriate (and is a fix). What makes it a bit complicated though is that it's a pointer currently and what it points to is shared per driver (besides being const): const struct serial_rs485 *rs485_supported; While it could be embedded into uart_port, there's the .padding which we might not want to bloat uart_port with. Perhaps create non-uapi struct kserial_rs485 w/o .padding and add static_assert()s to ensure the layout is identical to serial_rs485? -- i. From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6B729C433EF for ; Mon, 27 Jun 2022 09:07:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:Message-ID: In-Reply-To:Subject:cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=+JW4qR6XuBLgdAcBau8H8Q4MM3YKzyZpVnOyl2pEU+E=; b=OGR84fPKq98sx2 xbrG0ix2SgCPaRg1FM5yrE9h/MltV3tLBeS1S1vdHmVnIiOOSU+DP/xXLvq8dRCdWTAXHW1XuGPgj lmbchFxWZArt72DTINqvi+t5A8e9bPB9GE2umkmNwKHNpEiYZNefQTpUBaDDFjzY+w5LNM6YoxJ3J 1shwQu+4wn4o1kq5s4MV486YbFPdkZAYJJEE0MwvAljGqcoDnzKan92VZ3hk4JucMwst6B4fnLtJM GwQD17ju7VA5guL2JwiUdAHf/bE/DlcnopwawcSxttXyWe9AIc5lsl9dGF0Kfz86tUeVEFEGYmvBU p7wEiBgEGXQP/KufH6jA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1o5kh0-00H8uy-EJ; Mon, 27 Jun 2022 09:06:02 +0000 Received: from mga01.intel.com ([192.55.52.88]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1o5kgw-00H8pz-3v for linux-arm-kernel@lists.infradead.org; Mon, 27 Jun 2022 09:05:59 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1656320758; x=1687856758; h=date:from:to:cc:subject:in-reply-to:message-id: references:mime-version; bh=jcKmTKeNDN11ToKECGTcEIIGoAMkwCReSD4tvZEnNOU=; b=VwS72ETQauYYu74o4Ze1waz+qHyLa+apjVjUvul3hLgSn3YrhAGm2sVb sB590U0yZ6LvaIL0DnjlRI34ef6fiwrvguiLmL8svrAddvOtC7txtXmG6 r+EP1OkXT9RmelKMmUXi+oQVOFeiw/ye5OQ+0E3owli4K+Wj2EFDL4vqV Au3CiwHlbQINbJMMrU9EBg+uQT6s6cNAlkTs/2Y/j48uOCKJrK8DKlKdr 882hJcxTtJg1eR5uvaRht8q0+ezZrwBxg2I94+RSLLlkdh7Rn7hahUhHO kur85kKmhw69ooQT/xXBX2j5gtcv2ZNbItKtca68z2jC+7Lf3ss9LyEDU Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10390"; a="306877181" X-IronPort-AV: E=Sophos;i="5.92,225,1650956400"; d="scan'208";a="306877181" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jun 2022 02:05:53 -0700 X-IronPort-AV: E=Sophos;i="5.92,225,1650956400"; d="scan'208";a="646348400" Received: from gretavix-mobl3.amr.corp.intel.com ([10.249.43.78]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jun 2022 02:05:49 -0700 Date: Mon, 27 Jun 2022 12:05:50 +0300 (EEST) From: =?ISO-8859-15?Q?Ilpo_J=E4rvinen?= To: Lukas Wunner cc: Lino Sanfilippo , Greg Kroah-Hartman , Jiri Slaby , robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, Andy Shevchenko , vz@mleia.com, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, linux-serial , LKML , p.rosenberger@kunbus.com, Lino Sanfilippo Subject: Re: [PATCH 1/8] serial: core: only get RS485 termination gpio if supported In-Reply-To: <20220625194951.GA2879@wunner.de> Message-ID: References: <20220622154659.8710-1-LinoSanfilippo@gmx.de> <20220622154659.8710-2-LinoSanfilippo@gmx.de> <20220625194951.GA2879@wunner.de> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220627_020558_242225_961EE58A X-CRM114-Status: GOOD ( 28.16 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Sat, 25 Jun 2022, Lukas Wunner wrote: > On Wed, Jun 22, 2022 at 05:46:52PM +0200, Lino Sanfilippo wrote: > > In uart_get_rs485_mode() only try to get a termination GPIO if RS485 bus > > termination is supported by the driver. > [...] > > --- a/drivers/tty/serial/serial_core.c > > +++ b/drivers/tty/serial/serial_core.c > > @@ -3384,17 +3384,20 @@ int uart_get_rs485_mode(struct uart_port *port) > > rs485conf->flags |= SER_RS485_RTS_AFTER_SEND; > > } > > > > - /* > > - * Disabling termination by default is the safe choice: Else if many > > - * bus participants enable it, no communication is possible at all. > > - * Works fine for short cables and users may enable for longer cables. > > - */ > > - port->rs485_term_gpio = devm_gpiod_get_optional(dev, "rs485-term", > > - GPIOD_OUT_LOW); > > - if (IS_ERR(port->rs485_term_gpio)) { > > - ret = PTR_ERR(port->rs485_term_gpio); > > - port->rs485_term_gpio = NULL; > > - return dev_err_probe(dev, ret, "Cannot get rs485-term-gpios\n"); > > + if (port->rs485_supported->flags & SER_RS485_TERMINATE_BUS) { > > So I think linux-next commit be2e2cb1d281 ("serial: Sanitize rs485_struct") > contains a mistake in that it forces drivers to set SER_RS485_TERMINATE_BUS > in their rs485_supported->flags to allow enabling bus termination. > > That's wrong because *every* rs485-capable driver can enable bus > termination if a GPIO has been defined for that in the DT. Do you mean every em485 using driver? Otherwise I don't see this "forces drivers to set" happening anywhere in the code? You're partially right because there are other bugs in this area such as the one you propose a fix below. While I was making the sanitization series, I entirely missed some parts related to termination because SER_RS485_TERMINATE_BUS is seemingly not set/handled correctly by the core. Another thing that looks a bug is that on subsequent call to TIOCSRS485, w/o SER_RS485_TERMINATE_BUS nothing happens (for non-em485 driver, that is)? It seems to be taken care by 2/8 of this series though, I think. But it should be properly marked as Fixes: ... in that case although nobody has complained about it so likely not a huge issue to anyone. > In fact, another commit which was applied as part of the same series, > ebe2cf736a04 ("serial: pl011: Fill in rs485_supported") does not set > SER_RS485_TERMINATE_BUS in amba-pl011.c's flags and thus forbids the > driver from enabling bus termination, even though we know there are > products out there which support bus termination on the pl011 through > a GPIO (Revolution Pi RevPi Compact, Revpi Flat). > > I think what you want to do is amend uart_get_rs485_mode() to set > SER_RS485_TERMINATE_BUS in port->rs485_supported_flags if a GPIO > was found in the DT. Instead of the change proposed above. That seems appropriate (and is a fix). What makes it a bit complicated though is that it's a pointer currently and what it points to is shared per driver (besides being const): const struct serial_rs485 *rs485_supported; While it could be embedded into uart_port, there's the .padding which we might not want to bloat uart_port with. Perhaps create non-uapi struct kserial_rs485 w/o .padding and add static_assert()s to ensure the layout is identical to serial_rs485? -- i. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel