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 C7262C4332F for ; Tue, 22 Nov 2022 08:52:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232989AbiKVIw4 (ORCPT ); Tue, 22 Nov 2022 03:52:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53844 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232982AbiKVIwr (ORCPT ); Tue, 22 Nov 2022 03:52:47 -0500 Received: from mx1.tq-group.com (mx1.tq-group.com [93.104.207.81]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 71995558E; Tue, 22 Nov 2022 00:52:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tq-group.com; i=@tq-group.com; q=dns/txt; s=key1; t=1669107165; x=1700643165; h=message-id:subject:from:to:cc:date:in-reply-to: references:content-transfer-encoding:mime-version; bh=NJKojUVVwfNiBj6nGyV2BiX29XXsfamg3FpOm3EoRFg=; b=Gt3LBIz9oHgyzomZwcxeqav31aVyo6XiXNPK+XKmS61/rcy/b2FgBFvl A1OIWRl+Wt2PafYKJsyiisBVfpl63hNiXhMPZ6D6pi4eLjg/iumGvmgMJ 5FV+6yDLUqO2hDePwzTVGR9L/gIycojND194Ud/1FHEq5ZP8w4AbZyqr/ G+Gm2vCiE7nMwZ/Pw3ENJ3Dv4YG2g7Itueiz64sQJKFtMlLIs++as7MhX 6K3phmMrUNqpUbkJ9814Mi0OgukDtYGHBHebYMiJf4Rh7mgYbYCl1sq8U 0lKHoOHXTNVLCwvlg/+ixRmLMmNnZEudvqxtd9rkrfS0nHm2gkEjoNymp Q==; X-IronPort-AV: E=Sophos;i="5.96,183,1665439200"; d="scan'208";a="27501948" Received: from unknown (HELO tq-pgp-pr1.tq-net.de) ([192.168.6.15]) by mx1-pgp.tq-group.com with ESMTP; 22 Nov 2022 09:52:42 +0100 Received: from mx1.tq-group.com ([192.168.6.7]) by tq-pgp-pr1.tq-net.de (PGP Universal service); Tue, 22 Nov 2022 09:52:42 +0100 X-PGP-Universal: processed; by tq-pgp-pr1.tq-net.de on Tue, 22 Nov 2022 09:52:42 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tq-group.com; i=@tq-group.com; q=dns/txt; s=key1; t=1669107162; x=1700643162; h=message-id:subject:from:to:cc:date:in-reply-to: references:content-transfer-encoding:mime-version; bh=NJKojUVVwfNiBj6nGyV2BiX29XXsfamg3FpOm3EoRFg=; b=HXl9zXP+aCc45pS/jaSoSRLNYYPTiNQqVUhyQLLm9f9eVdXTBT/H9XrL vVkOBVA3TiO5wbRe/1R3qQEPV+0DkrPsvS86zvlnQoV4RYy3Svzlb5flV 7iSi+/KwWNSkmlCH2qF/wZIxvTb59iVbiNwtJWFyM2cVn9WFMmwBW0tuI mNvgDfLhvKC3iFio1hwh4H9jqx3u6opOequa7edR0CsddIIRdMNSVBX8p XqlxOm1gFKmz2VQr9q1a6OKow3Avg7xriBQJRh4LpfRJ5NgWVIW3qB8Jh ZuEVdW6Gb843ST4sclTMrDWeLFJLg37uaBEq9S1lz1VbEjOZDqM+kT7rf w==; X-IronPort-AV: E=Sophos;i="5.96,183,1665439200"; d="scan'208";a="27501947" Received: from vtuxmail01.tq-net.de ([10.115.0.20]) by mx1.tq-group.com with ESMTP; 22 Nov 2022 09:52:42 +0100 Received: from [192.168.2.129] (SCHIFFERM-M2.tq-net.de [10.121.49.14]) by vtuxmail01.tq-net.de (Postfix) with ESMTPA id 52450280056; Tue, 22 Nov 2022 09:52:42 +0100 (CET) Message-ID: Subject: Re: 8250_omap: incorrect RS485 RTS on close during transmission From: Matthias Schiffer To: Greg Kroah-Hartman , Jiri Slaby , Lukas Wunner Cc: Ilpo =?ISO-8859-1?Q?J=E4rvinen?= , linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org Date: Tue, 22 Nov 2022 09:52:40 +0100 In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.44.4-0ubuntu1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 2022-11-18 at 12:57 +0100, Matthias Schiffer wrote: > Hi Lukas, >=20 > I've discovered a new issue with EM485 in 8250_omap (and probably other > serial drivers as well?): When closing the TTY device while there is > still an ongoing transmission, the RTS pin will get stuck active until > the TTY is opened again. This can be easily reproduced by running `cat > /dev/zero > /dev/ttySx` and then stopping it using Ctrl-C. >=20 > The issue exists in current mainline (6.1-rc5+), and applying "serial: > 8250: 8250_omap: Avoid RS485 RTS glitch on ->set_termios()" from next > doesn't solve it. I think it should work with "serial: 8250: 8250_omap: > Support native RS485", but we also need RS485 on AM57xx CPUs, which > don't have native RS485. >=20 > I intend to look into this myself next week, but as you've worked on > this code a lot lately, maybe you already have an idea how to fix it? >=20 > Regards, > Matthias >=20 Okay, I've narrowed down the issue to uart_shutdown() -> uart_port_shutdown() - here, ops->shutdown() is called, which clears the FIFOs (in the case of the default 8250_port and 8250_omap) implementations, but doesn't wait for the clear to finish, and doesn't call ops->stop_tx(). I believe a similar problem can occur in uart_suspend_port(). Here, ops->stop_tx() is called before ops->shutdown(), but stop_tx() is a no- op when the TX FIFO is not empty (again, for the 8250 case - I haven't really looked at other drivers). Given that EM485 is handled in 8250_port by __stop_tx(), which is called both internally in the 8250 driver and from the serial core through stop_tx(), it is not clear to me what the correct layer to fix this is. Two ideas: (1) Have ops->shutdown() wait until the TX FIFO is empty. Call ops->stop_tx() after ops->shutdown() in serial core. For this to work, calling stop_tx() after shutdown() must be allowed in all drivers; I'm not sure if this is currently the case, and if it is desirable at all. (2) Do the whole handling in the driver's ops->shutdown(), do not further involve the serial core. So far, I've implemented (1) locally for 8250_omap, and together with "serial: 8250: 8250_omap: Avoid RS485 RTS glitch on ->set_termios()" it fixes the issue on my test devices, but I'm not too happy about the "shutdown then tx_stop" order of calls. So maybe (2) is the better solution after all?