Message ID | 20231120132256.136625-1-rasmus.villemoes@prevas.dk |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9910:0:b0:403:3b70:6f57 with SMTP id i16csp2195256vqn; Mon, 20 Nov 2023 05:24:04 -0800 (PST) X-Google-Smtp-Source: AGHT+IG/OBN+268tbhOq4hWec0cdL7FrIrzDEWFLKaZjppe1/73TLnYiMJnlsgDJIAzjb5KqxuqG X-Received: by 2002:a05:6a00:2450:b0:6b6:e754:9e02 with SMTP id d16-20020a056a00245000b006b6e7549e02mr5850172pfj.12.1700486643899; Mon, 20 Nov 2023 05:24:03 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1700486643; cv=pass; d=google.com; s=arc-20160816; b=rPoNF+RdKwxrAJrt33BXVX3H6VBjugRPyPy7D5bJX4CUuVp8ez3CfvpwJwhXMUXfNO KEXKHfp0gjDCS497+y3ZXcpYZ9Ppk8mSBIoDt2j0xi34Mmx+FJFepyqtQBsf2FPa8qK0 +Q70BOuKfI71/1zAoN1NT2bBSuLcxoLUNLj6WROg7nMSL565AeOu4czDbshNfDUr6vlG FET3QB7O7zrm9ei9r3cuxEPc38529rFUj1kYEX88OgwXnWt9V1pO/4WXZp2ILNSDnY/r xAN0anCucm4rbkQreJcit0nlxd+ituoR1gerICXl3S6EtBXQgHTBzFsCfLC4htfcDjPw ardQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :message-id:date:subject:cc:to:from:dkim-signature; bh=DmzXDeBo+XDchVJ8hCo0/DZ8bunhflc21u3s4OEd9sI=; fh=COkGaRJljzcuXxDflWVFqqpcQmjeVPVSPI6cuRQIUZg=; b=VJ5+48xC2L3zIRh+4bC2G1K+NhapyzjUgL3tjJcjYlosvFHbQ47v1bPtwbrdTEkOT0 ZiMUhoArmXF3IuFm9L1+mjqfZVfvttvKshLnbdyjWbi2j3Qk/yt0dX0mR8jI2UL9MGtq HEfDoqqP1Iqj8bkHn0HFWiuPP+VshDy2yV+loymsIom7gdNFgimMR1ze2A2L03PV1EuS 3DQ2sVTboasC5UmrkbD13FCltLf+WMP14WgsUaH9b7U5JxmXamiZ85vtDw4D+a3b50PO /yf8LFDC8IeBQNud6F7ZHPS4g0Oy2y4AIeZ1TGVBmZDRDc6RIZv9gViG2ee2SJNqnpK0 MKfg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@prevas.dk header.s=selector1 header.b=GJbNa47V; arc=pass (i=1 spf=pass spfdomain=prevas.dk dkim=pass dkdomain=prevas.dk dmarc=pass fromdomain=prevas.dk); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=prevas.dk Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id h131-20020a636c89000000b005b7c45b1f95si7918563pgc.555.2023.11.20.05.24.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Nov 2023 05:24:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@prevas.dk header.s=selector1 header.b=GJbNa47V; arc=pass (i=1 spf=pass spfdomain=prevas.dk dkim=pass dkdomain=prevas.dk dmarc=pass fromdomain=prevas.dk); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=prevas.dk Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id A5C538073860; Mon, 20 Nov 2023 05:24:01 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233186AbjKTNXt (ORCPT <rfc822;heyuhang3455@gmail.com> + 27 others); Mon, 20 Nov 2023 08:23:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38586 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233196AbjKTNXc (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 20 Nov 2023 08:23:32 -0500 Received: from EUR02-DB5-obe.outbound.protection.outlook.com (mail-db5eur02on2130.outbound.protection.outlook.com [40.107.249.130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EE5211BC3; Mon, 20 Nov 2023 05:23:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Sd4OxwXx72ihTChxa3iagzAT/FYESLFSRmjqHZ7OhpDttnKZjJtW+gEvzRkDYvcniJ9HmQ+UgOJLIvgRczuozwgWWitBLk6wFcCTYZeM9yO+/Q9uvqEGkLtyoBFb9OieoYacEhCu2oaC/UDhw8Ne5axgMy5dOENe2PeSlkjYi/7bWU4HF+2IO+YWX5ydQ3RMuBu91Z0RAqv/uNzptoRfnVS+9FeHA7Fe8/0GNePoqtXXyDkd41o2fipWPAmas4rj2GRAy4FShfygt1C40db8QpiGhD3Po3/xc2/BrceR6CqfAWDBsz6QFwiQAMwcqY0+c7OG7mwMj9P/cUgGPQ3uuA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=DmzXDeBo+XDchVJ8hCo0/DZ8bunhflc21u3s4OEd9sI=; b=NLJixvZj+CS7Viwxr0p6DN0vRmZ8zoFoJYZalVBCk9ivfR/vrzeKKiTEARnMFc3UeYjJGwyev+LSMDZqRCDnEmtJ78qTUxXlKaZEUJX5BT8B/yVxOTN0EEB+i+iodlue8/GP++71IiFcOvBydcvUD/HJa6sthf/KOeFrQXSCbYQRKLTyLj35oifk+8MouBb1oZmB8cVDJyBRoq+k03HOIU+LuITjPpi5izxFmZHTKXrIO4MxD0766SNbxP3PHKIJ2KvF4drLPwwy/MIs8qFedCS6IyclvLFH0e9Nn6XeGpkRywI0Elax4MW4gxjHrXvtghADwPwErinNC6momM/zeg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=prevas.dk; dmarc=pass action=none header.from=prevas.dk; dkim=pass header.d=prevas.dk; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=prevas.dk; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=DmzXDeBo+XDchVJ8hCo0/DZ8bunhflc21u3s4OEd9sI=; b=GJbNa47V6+Tz0HXSJeseNYtc85w2XpfrFiWktQUdTugWwsX/mvNiqt2SmeQPHh1jnEhA5F+KeXvPEhC3L2MTJ9eJpX54fyQ0+DCMlKrOGGtClknr8HlXfQjCD6B6sap3QuX5tmwJ8nDro1uKbZWtW4ZkFmYc7y/EWgvjuUI+b8c= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=prevas.dk; Received: from DB9PR10MB7100.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:10:45a::14) by PAWPR10MB7176.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:102:2f2::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7002.26; Mon, 20 Nov 2023 13:23:07 +0000 Received: from DB9PR10MB7100.EURPRD10.PROD.OUTLOOK.COM ([fe80::8bd9:31bc:d048:af15]) by DB9PR10MB7100.EURPRD10.PROD.OUTLOOK.COM ([fe80::8bd9:31bc:d048:af15%5]) with mapi id 15.20.7002.027; Mon, 20 Nov 2023 13:23:07 +0000 From: Rasmus Villemoes <rasmus.villemoes@prevas.dk> To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>, Jiri Slaby <jirislaby@kernel.org>, Shawn Guo <shawnguo@kernel.org>, Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix Kernel Team <kernel@pengutronix.de>, Fabio Estevam <festevam@gmail.com>, NXP Linux Team <linux-imx@nxp.com> Cc: Rasmus Villemoes <rasmus.villemoes@prevas.dk>, linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH] serial: imx: also enable Transmit Complete interrupt in rs232 mode Date: Mon, 20 Nov 2023 14:22:56 +0100 Message-Id: <20231120132256.136625-1-rasmus.villemoes@prevas.dk> X-Mailer: git-send-email 2.40.1.1.g1c60b9335d Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: MM0P280CA0040.SWEP280.PROD.OUTLOOK.COM (2603:10a6:190:b::11) To DB9PR10MB7100.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:10:45a::14) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DB9PR10MB7100:EE_|PAWPR10MB7176:EE_ X-MS-Office365-Filtering-Correlation-Id: 33395abe-c967-4072-2730-08dbe9cbd5b2 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: mVuKI/OUadO5/7MxdZMQU8a5s9/kQB7899xO5/qZzSPA/pL3vGY/rL2yNezqXVnAx8bNxf6XL+VO00KY39lk9UOdCbhfkn+XsSx89dSlvhwCzRa0ZlJ1RNQQNrQiXTQ39WZ5W7Svj8/EqBthtoVnv0KVwchqUmpWHWFDO4srvDmRDZON/SCZ/iZiYPqJEBuYskAVW2rVXD00jP7b0xrAS6/AMCQ6zdogQT/ZLfbYpAWmgSief0USgolsI/WNvJDMEjXfv+rhGUG5GiMUwUwz+FFoZoJTydpBtyCH8o/7Hv63k+6+JBe7MREgIGMMY2u2MR1PsgS2JOhIsT0muhNrQj8l94naZwy/gI6XbD+hTrt+hI59uc/4789tilTeVSZ1VITWL3+09/wk18ssicc7ZlVB4DFVXD9wznqa+/7sxLnqhJccHGIhKg1/e8Oo7+Cjgp5f/aDh86R7ajFjPuszemHBUDquM8Gx9ub8eTvT6SRo0VN1/42Cxt7+xWfo4nd/dWXCpbRFviYSjlEw5YI7Jxfy2IuqH56Bv7EgbYkQl4PmBgv3dEt60Ibfn23Ej9StPotuTNeH3Nr1v/zte4v8yOaTgbkOaqUjCCw+zfKWTzp8CBkuxJ2/y/g5AHAx+g0d X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DB9PR10MB7100.EURPRD10.PROD.OUTLOOK.COM;PTR:;CAT:NONE;SFS:(13230031)(376002)(39850400004)(396003)(136003)(346002)(366004)(230922051799003)(451199024)(64100799003)(1800799012)(186009)(41300700001)(44832011)(36756003)(5660300002)(7416002)(2906002)(86362001)(38350700005)(52116002)(6506007)(6512007)(26005)(2616005)(1076003)(83380400001)(6486002)(478600001)(6666004)(38100700002)(110136005)(66556008)(66946007)(4326008)(8976002)(66476007)(8676002)(8936002)(316002);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: TE85S6ss8jTrHmrFfn6fNxsc7pHA/7eD4KDXAfVP7TK0+QxtR2onF/kE7PBjUI8PbKw0OcCOEO2KYgmkF2+T6pGHImMHsVjynqDir/ZzbU7ET7qEp5AcSFqCX59T5VPtBE2SBqQJwi/FG6iN7o+8CgSn2ABJZ067ID16QZsc9+mulIv1+jlYb0VS2OhUEH2TFIjUeeG2u8HhgQ9Sm/uEq1pVtPV4ROZ7/uy3nNlbHBs8CBv9Y/x/fT1S9ELC/Xp+agu225R9vR5Hxr5IoqROOtUkrzHhZ0CAc2MfzusadrySiw3AVtnGe0QJOvp5DveDARMAju9D+ohr64po+KspLlSH15uliTsb2qCfetUmMaduJDnTZn3+glcjUGVtOkTE2zypf2B8Ho/IG7NpCqPjrL9asJflQWnvvyIFWeKHJzfaXoiSFz/npo9ldsx/VlPfWcpmShKoEfw1aKgiHgrBMC7OapocByzoySiVbhW3I1ioV98dZXDNq6+8cXaC3RcF3xKqHfI56xiueY+N3lDTwMhY3W+TJYtqUb3ZQUCz8WG9VunDi6mFmYyC6Smi/OHyQlNbLQcsX2RYnblhv66LScqdvjXJ14vapIq9B2CAe2c+WIUgTx8rYGMVaWAjzd96bx/2RgSCaZdGWJozSGmj7SnYE4K6p5u5XMlNsULcxDbXhZw/Nsz8WDdSCdqgi8PBgEjaA517PQB8LwqKMMrpt2D8hEII9JJwpl2dqK09HAxoeRAw3gjxyppXjWyIsUVToywYsTtRKCK8YWDkI9/THFVVIXlJ9ok09DX7XbeRmDut2sQHvrYHxntE/A2Iy7b8QIC18bDuAZtVP7c4LlRlACYI9gugtu1SLP+YVs3zGr4fLKZWEYRRw5LC/lYkOE9Q24vEVVzkB1+9+1tML0C7pG/2AMh0kmjHxExYpqiVBvbSe6djnqVLjkGivKu/GOmn1GI0wot3ka+GnNEyj/QHlqC3/Jf85M5hZVNZ7+FOXg0AssnQSRElbDv/rocDJanQBFO52/A4ekHtZAhFMW5M2uIzw/dWkRcECYhL1tDMG4zcUQuO0mOiAqKBVjgyRsy8Gnf6ispGkCePH2VefXqd+kvjD9BjrlIHUNwzlof1JBDDMbjCg1mfcpiobqzT1zmzkMXAGnBxMwpXtrbmMVJP9Ex5j9HLzqFiElYxlcG4L3lGGPsE3RXCuT+YqKuh8+zz6fqk2uWkfjD5m8vqPXXXBlEtBPpbE4BjqRAvC0QHSmKwoZ2MRhbgfrUz1ASxxP0d7mml54JiEbSkfttGF6mcfHu3pP8BXuSG9VgJe7WW+FFb5a2JlsEGvxQRxYD2fbXlPWUjzXcfpd11W2DrO6C/kD0D2Lgct0AYby2X4oc6GiFBkdZM4VznjCyWr7qtnZh3TbQ+02T/UMYWogcPSbNQNQgQMz8Tb/cS8E3kJQt1Q2ug02pj41NlfTxrOOY0+DyZP38FeJxEKWm2YqZlu8aJq5f8RS1Vvyg4Mz6U+J52HH3Pk9gKnRxkxq7LQcPwy7wLQdDEDKa+AdVnWeC8OjF/iXeJ1c2sGeb4LZUhHrP5TckNQXu2y2eFA5PsHb+IwtZie7ThHIYBRTZ54OEv+43n8Q== X-OriginatorOrg: prevas.dk X-MS-Exchange-CrossTenant-Network-Message-Id: 33395abe-c967-4072-2730-08dbe9cbd5b2 X-MS-Exchange-CrossTenant-AuthSource: DB9PR10MB7100.EURPRD10.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Nov 2023 13:23:07.7447 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: d350cf71-778d-4780-88f5-071a4cb1ed61 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: nZfvnRJffkL2+1hoWQpjQaoIau6G8iPWhIotiAX6r7Je/shog72LftUW/UJoDp8YpMEtrHS3VJgIeZOKGG9CxNcqFW2Fw5/TxVN8YIxKLDA= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAWPR10MB7176 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Mon, 20 Nov 2023 05:24:01 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783089483059723100 X-GMAIL-MSGID: 1783089483059723100 |
Series |
serial: imx: also enable Transmit Complete interrupt in rs232 mode
|
|
Commit Message
Rasmus Villemoes
Nov. 20, 2023, 1:22 p.m. UTC
Currently, if one switches to rs232 mode, writes something to the
device, and then switches to rs485 mode, the imx_port's ->tx_state is
left as SEND. This then prevents a subsequent write in rs485 mode from
properly asserting the rts pin (i.e. enabling the transceiver),
because imx_uart_start_rx() does not enter the "if (sport->tx_state ==
OFF)" branch. Hence nothing is actually transmitted.
The problem is that in rs232 mode, ->tx_state never gets set to OFF,
due to
usr2 = imx_uart_readl(sport, USR2);
if (!(usr2 & USR2_TXDC)) {
/* The shifter is still busy, so retry once TC triggers */
return;
}
in imx_uart_stop_tx(), and TC never triggers because the Transmit
Complete interrupt is not enabled for rs232.
Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
---
I'm not sure this is the best fix.
At first I considered doing something much more targeted, but
definitely also more hacky: In imx_uart_rs485_config(), if switching
on rs485 mode, simply add "sport->tx_state = OFF;".
If someone has a better suggestion, I'm all ears.
drivers/tty/serial/imx.c | 24 +++++++++---------------
1 file changed, 9 insertions(+), 15 deletions(-)
Comments
> -----Original Message----- > From: Rasmus Villemoes <rasmus.villemoes@prevas.dk> > Sent: 2023年11月20日 21:23 > To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>; Jiri Slaby > <jirislaby@kernel.org>; Shawn Guo <shawnguo@kernel.org>; Sascha Hauer > <s.hauer@pengutronix.de>; Pengutronix Kernel Team > <kernel@pengutronix.de>; Fabio Estevam <festevam@gmail.com>; dl-linux- > imx <linux-imx@nxp.com> > Cc: Rasmus Villemoes <rasmus.villemoes@prevas.dk>; linux- > kernel@vger.kernel.org; linux-serial@vger.kernel.org; linux-arm- > kernel@lists.infradead.org > Subject: [PATCH] serial: imx: also enable Transmit Complete interrupt in > rs232 mode > > Currently, if one switches to rs232 mode, writes something to the device, and > then switches to rs485 mode, the imx_port's ->tx_state is left as SEND. This > then prevents a subsequent write in rs485 mode from properly asserting the > rts pin (i.e. enabling the transceiver), because imx_uart_start_rx() does not > enter the "if (sport->tx_state == OFF)" branch. Hence nothing is actually > transmitted. > > The problem is that in rs232 mode, ->tx_state never gets set to OFF, due to > > usr2 = imx_uart_readl(sport, USR2); > if (!(usr2 & USR2_TXDC)) { > /* The shifter is still busy, so retry once TC triggers */ > return; > } > > in imx_uart_stop_tx(), and TC never triggers because the Transmit Complete > interrupt is not enabled for rs232. Hi Rasmus, I am afraid this is not right, USR2_TXDC is just a flag, it is not affected by whether UCR4_TCEN is set or not, UCR4_TCEN only determines if USR2_TXDC flag can generate a interrupt or not. I tried on imx8mp-evk board, for rs232, sport->tx_state can get set to OFF even we don’t set UCR4_TCEN. Best Regards Sherry > > Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk> > --- > I'm not sure this is the best fix. > > At first I considered doing something much more targeted, but definitely also > more hacky: In imx_uart_rs485_config(), if switching on rs485 mode, simply > add "sport->tx_state = OFF;". > > If someone has a better suggestion, I'm all ears. > > drivers/tty/serial/imx.c | 24 +++++++++--------------- > 1 file changed, 9 insertions(+), 15 deletions(-) > > diff --git a/drivers/tty/serial/imx.c b/drivers/tty/serial/imx.c index > 7341d060f85c..ffee157e13cd 100644 > --- a/drivers/tty/serial/imx.c > +++ b/drivers/tty/serial/imx.c > @@ -708,25 +708,19 @@ static void imx_uart_start_tx(struct uart_port > *port) > || sport->tx_state == WAIT_AFTER_RTS) { > > hrtimer_try_to_cancel(&sport->trigger_stop_tx); > - > - /* > - * Enable transmitter and shifter empty irq only if > DMA > - * is off. In the DMA case this is done in the > - * tx-callback. > - */ > - if (!sport->dma_is_enabled) { > - u32 ucr4 = imx_uart_readl(sport, UCR4); > - ucr4 |= UCR4_TCEN; > - imx_uart_writel(sport, ucr4, UCR4); > - } > - > - sport->tx_state = SEND; > } > - } else { > - sport->tx_state = SEND; > } > > + sport->tx_state = SEND; > + > + /* > + * Enable transmitter and shifter empty irq only if DMA is > + * off. In the DMA case this is done in the tx-callback. > + */ > if (!sport->dma_is_enabled) { > + u32 ucr4 = imx_uart_readl(sport, UCR4); > + ucr4 |= UCR4_TCEN; > + imx_uart_writel(sport, ucr4, UCR4); > ucr1 = imx_uart_readl(sport, UCR1); > imx_uart_writel(sport, ucr1 | UCR1_TRDYEN, UCR1); > } > -- > 2.40.1.1.g1c60b9335d
On 21/11/2023 07.37, Sherry Sun wrote: > > >> -----Original Message----- >> From: Rasmus Villemoes <rasmus.villemoes@prevas.dk> >> Sent: 2023年11月20日 21:23 >> To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>; Jiri Slaby >> <jirislaby@kernel.org>; Shawn Guo <shawnguo@kernel.org>; Sascha Hauer >> <s.hauer@pengutronix.de>; Pengutronix Kernel Team >> <kernel@pengutronix.de>; Fabio Estevam <festevam@gmail.com>; dl-linux- >> imx <linux-imx@nxp.com> >> Cc: Rasmus Villemoes <rasmus.villemoes@prevas.dk>; linux- >> kernel@vger.kernel.org; linux-serial@vger.kernel.org; linux-arm- >> kernel@lists.infradead.org >> Subject: [PATCH] serial: imx: also enable Transmit Complete interrupt in >> rs232 mode >> >> Currently, if one switches to rs232 mode, writes something to the device, and >> then switches to rs485 mode, the imx_port's ->tx_state is left as SEND. This >> then prevents a subsequent write in rs485 mode from properly asserting the >> rts pin (i.e. enabling the transceiver), because imx_uart_start_rx() does not >> enter the "if (sport->tx_state == OFF)" branch. Hence nothing is actually >> transmitted. >> >> The problem is that in rs232 mode, ->tx_state never gets set to OFF, due to >> >> usr2 = imx_uart_readl(sport, USR2); >> if (!(usr2 & USR2_TXDC)) { >> /* The shifter is still busy, so retry once TC triggers */ >> return; >> } >> >> in imx_uart_stop_tx(), and TC never triggers because the Transmit Complete >> interrupt is not enabled for rs232. > > Hi Rasmus, > I am afraid this is not right, USR2_TXDC is just a flag, it is not affected by whether UCR4_TCEN is set or not, UCR4_TCEN only determines if USR2_TXDC flag can generate a interrupt or not. Exactly. And when TCEN is not set, we don't get that interrupt the comment refers to, so we never retry once TXDC gets set. > I tried on imx8mp-evk board, for rs232, sport->tx_state can get set to OFF even we don’t set UCR4_TCEN. I am working on an imx8mp board, so I can definitely tell you that the code currently has a problem, and this patch fixes it (though, as said, I do not know if it's the best fix or if it might introduce other problems). Yes, of course, due to random timing issues, you _might_ see that in rs232 mode, by the time imx_uart_stop_tx() gets called (most likely from imx_uart_transmit_buffer()), the transmitter might be done, so we pass that if (!(usr2 & USR2_TXDC)) test, and get right to the bottom of imx_uart_stop_tx() where ->tx_state is set to OFF. But in many cases (it reproduces completely reliably for me), that imx_uart_stop_tx() hits the early return, and if the Transmit Complete enable interrupt is not enabled, well, then (referring to the existing comment) of course TC never triggers, so we never retry, and hence nothing ever sets ->tx_state back to OFF. And that's not really a problem as long as you stay in rs232, because that mode doesn't really use the ->tx_state state machine logic. But switching to rs485 mode, and the driver is left in a confused state breaking output (input still works). Rasmus
> Currently, if one switches to rs232 mode, writes something to the > device, and then switches to rs485 mode, the imx_port's ->tx_state is > left as SEND. This then prevents a subsequent write in rs485 mode from > properly asserting the rts pin (i.e. enabling the transceiver), > because imx_uart_start_rx() does not enter the "if (sport->tx_state == > OFF)" branch. Hence nothing is actually transmitted. > > The problem is that in rs232 mode, ->tx_state never gets set to OFF, > due to > > usr2 = imx_uart_readl(sport, USR2); > if (!(usr2 & USR2_TXDC)) { > /* The shifter is still busy, so retry once TC triggers */ > return; > } > > in imx_uart_stop_tx(), and TC never triggers because the Transmit > Complete interrupt is not enabled for rs232. > > Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk> > --- > I'm not sure this is the best fix. > > At first I considered doing something much more targeted, but > definitely also more hacky: In imx_uart_rs485_config(), if switching > on rs485 mode, simply add "sport->tx_state = OFF;". > > If someone has a better suggestion, I'm all ears. Hello Rasmus, i can observe a very similar situation, but with a litte different configuration. This is how i can trigger the situation very quickly: 1) open the port 2) send 1 byte out 3) close the port Do it in a loop. As faster, the lockup may occur earlier (but not mandatory, 100ms is sufficient in my setup at 115200 Baud on an i.mx8mm board). With this configuration i get the lockup in around 1 minute. For my setup it's clear what happens: - when the tty is closed imx_uart_shutdown() is called. This calls imx_uart_stop_tx() - for a lockup, the shifter is still busy and imx_uart_stop_tx() returns early (as you explained) without modifying ->tx_state. - imx_uart_shutdown() proceeds and finally closes the port. Due to imx_uart_stop_tx() is not executed completely tx_state is left in state ->tx_state == SEND. - When the port is opened again, tx_state is SEND and nothing can be transmitted any more. The tx path has locked up! Setting ->tx_state = SEND in imx_uart_shutdown() helps for my issue (and should be ok IMHO). But IMHO there is one next issue with this situation: When the port operates with WAIT_AFTER_RTS and WAIT_AFTER_SEND then some timers for callback functions might be active. I did not discover where they are stopped for the case when the serial port is closed. Maybe stopping is not required ... I'd appreciate someone with more experience could review or revise it Best Regards Eberhard
> Currently, if one switches to rs232 mode, writes something to the > device, and then switches to rs485 mode, the imx_port's ->tx_state is > left as SEND. This then prevents a subsequent write in rs485 mode from > properly asserting the rts pin (i.e. enabling the transceiver), > because imx_uart_start_rx() does not enter the "if (sport->tx_state == > OFF)" branch. Hence nothing is actually transmitted. > > The problem is that in rs232 mode, ->tx_state never gets set to OFF, > due to > > usr2 = imx_uart_readl(sport, USR2); > if (!(usr2 & USR2_TXDC)) { > /* The shifter is still busy, so retry once TC triggers */ > return; > } > > in imx_uart_stop_tx(), and TC never triggers because the Transmit > Complete interrupt is not enabled for rs232. > > Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk> > --- > I'm not sure this is the best fix. > > At first I considered doing something much more targeted, but > definitely also more hacky: In imx_uart_rs485_config(), if switching > on rs485 mode, simply add "sport->tx_state = OFF;". > > If someone has a better suggestion, I'm all ears. Hello Rasmus, i can observe a very similar situation, but with a litte different configuration. This is how i can trigger the situation very quickly: 1) open the port 2) send 1 byte out 3) close the port Do it in a loop. As faster, the lockup may occur earlier (but not mandatory, 100ms is sufficient in my setup at 115200 Baud on an i.mx8mm board). With this configuration i get the lockup in around 1 minute. For my setup it's clear what happens: - when the tty is closed imx_uart_shutdown() is called. This calls imx_uart_stop_tx() - for a lockup, the shifter is still busy and imx_uart_stop_tx() returns early (as you explained) without modifying ->tx_state. - imx_uart_shutdown() proceeds and finally closes the port. Due to imx_uart_stop_tx() is not executed completely tx_state is left in state ->tx_state == SEND. - When the port is opened again, tx_state is SEND and nothing can be transmitted any more. The tx path has locked up! Setting ->tx_state = SEND in imx_uart_shutdown() helps for my issue (and should be ok IMHO). But IMHO there is one next issue with this situation: When the port operates with WAIT_AFTER_RTS and WAIT_AFTER_SEND then some timers for callback functions might be active. I did not discover where they are stopped for the case when the serial port is closed. Maybe stopping is not required ... I'd appreciate someone with more experience could review or revise it Best Regards Eberhard
On 21/11/2023 21.49, Eberhard Stoll wrote: >> Currently, if one switches to rs232 mode, writes something to the >> device, and then switches to rs485 mode, the imx_port's ->tx_state is >> left as SEND. This then prevents a subsequent write in rs485 mode from >> properly asserting the rts pin (i.e. enabling the transceiver), >> because imx_uart_start_rx() does not enter the "if (sport->tx_state == >> OFF)" branch. Hence nothing is actually transmitted. >> >> The problem is that in rs232 mode, ->tx_state never gets set to OFF, >> due to >> >> usr2 = imx_uart_readl(sport, USR2); >> if (!(usr2 & USR2_TXDC)) { >> /* The shifter is still busy, so retry once TC triggers */ >> return; >> } >> >> in imx_uart_stop_tx(), and TC never triggers because the Transmit >> Complete interrupt is not enabled for rs232. >> >> Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk> >> --- >> I'm not sure this is the best fix. >> >> At first I considered doing something much more targeted, but >> definitely also more hacky: In imx_uart_rs485_config(), if switching >> on rs485 mode, simply add "sport->tx_state = OFF;". >> >> If someone has a better suggestion, I'm all ears. > > > Hello Rasmus, > > i can observe a very similar situation, but with a litte different > configuration. This is how i can trigger the situation very quickly: > > 1) open the port > 2) send 1 byte out > 3) close the port Hi Eberhard Thanks for chiming in. I assume this is all in rs485 mode, no switching to rs232 and back involved? > Do it in a loop. As faster, the lockup may occur earlier (but not > mandatory, 100ms is sufficient in my setup at 115200 Baud on an > i.mx8mm board). > With this configuration i get the lockup in around 1 minute. > > For my setup it's clear what happens: > > - when the tty is closed imx_uart_shutdown() is called. This calls > imx_uart_stop_tx() > - for a lockup, the shifter is still busy and imx_uart_stop_tx() > returns early (as you explained) without modifying ->tx_state. > - imx_uart_shutdown() proceeds and finally closes the port. Due to > imx_uart_stop_tx() is not executed completely tx_state is left in > state ->tx_state == SEND. Yes, and imx_uart_shutdown() disables the TCEN which would otherwise cause _stop_tx to get called when the transmitter is no longer busy. > - When the port is opened again, tx_state is SEND and nothing can > be transmitted any more. The tx path has locked up! > > Setting ->tx_state = SEND in imx_uart_shutdown() helps for my issue > (and should be ok IMHO). [I assume you mean tx_state = OFF]. Yes, I suppose doing that would be ok, but I'm not sure it's a complete fix. In my simple test cast, I have separate programs invoked to do the I/O and do the mode switch, but in a real scenario, I'd expect the application itself to just open the device once, and then do I/O and mode switching as appropriate for the application logic, and I don't think uart_shutdown would then ever get called. > But IMHO there is one next issue with this situation: When the port > operates with WAIT_AFTER_RTS and WAIT_AFTER_SEND then some timers > for callback functions might be active. I did not discover where they > are stopped for the case when the serial port is closed. Maybe stopping > is not required ... Indeed, that's an extra complication. Adding two hrtimer_try_to_cancel() in shutdown would probably not hurt, along with setting tx_state OFF. I wonder if at least mode switching should simply be disallowed (-EBUSY) if tx_state is anything but OFF. Rasmus
>> i can observe a very similar situation, but with a litte different >> configuration. This is how i can trigger the situation very quickly: >> >> 1) open the port >> 2) send 1 byte out >> 3) close the port > > Hi Eberhard > > Thanks for chiming in. I assume this is all in rs485 mode, no switching > to rs232 and back involved? Yes, no mode switching is involved here. Only rs485 mode. >> Setting ->tx_state = SEND in imx_uart_shutdown() helps for my issue >> (and should be ok IMHO). > > [I assume you mean tx_state = OFF]. Yes, I suppose doing that would be > ok, but I'm not sure it's a complete fix. In my simple test cast, I have Oh, yes, sorry my mistake! I really meant ->tx_state = OFF as you expected in your comment > separate programs invoked to do the I/O and do the mode switch, but in a > real scenario, I'd expect the application itself to just open the device > once, and then do I/O and mode switching as appropriate for the > application logic, and I don't think uart_shutdown would then ever get > called. Switching between rs232 mode and rs485 mode on an open port is a special use case in my experience. But it's valid and introduces some extra complexity. As you stated, for this use case setting ->tx_state = OFF in imx_uart_shutdown() does not really help. > Indeed, that's an extra complication. Adding two hrtimer_try_to_cancel() > in shutdown would probably not hurt, along with setting tx_state OFF. > > I wonder if at least mode switching should simply be disallowed (-EBUSY) > if tx_state is anything but OFF. Seems there are various issues in ->tx_state handling and transmitter timing in this driver! Best Regards Eberhard
On 22.11.23 09:03, Rasmus Villemoes wrote: > On 21/11/2023 21.49, Eberhard Stoll wrote: >>> Currently, if one switches to rs232 mode, writes something to the >>> device, and then switches to rs485 mode, the imx_port's ->tx_state is >>> left as SEND. This then prevents a subsequent write in rs485 mode from >>> properly asserting the rts pin (i.e. enabling the transceiver), >>> because imx_uart_start_rx() does not enter the "if (sport->tx_state == >>> OFF)" branch. Hence nothing is actually transmitted. >>> >>> The problem is that in rs232 mode, ->tx_state never gets set to OFF, >>> due to >>> >>> usr2 = imx_uart_readl(sport, USR2); >>> if (!(usr2 & USR2_TXDC)) { >>> /* The shifter is still busy, so retry once TC triggers */ >>> return; >>> } >>> >>> in imx_uart_stop_tx(), and TC never triggers because the Transmit >>> Complete interrupt is not enabled for rs232. >>> >>> Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk> >>> --- >>> I'm not sure this is the best fix. >>> >>> At first I considered doing something much more targeted, but >>> definitely also more hacky: In imx_uart_rs485_config(), if switching >>> on rs485 mode, simply add "sport->tx_state = OFF;". >>> >>> If someone has a better suggestion, I'm all ears. >> >> >> Hello Rasmus, >> >> i can observe a very similar situation, but with a litte different >> configuration. This is how i can trigger the situation very quickly: >> >> 1) open the port >> 2) send 1 byte out >> 3) close the port > > Hi Eberhard > > Thanks for chiming in. I assume this is all in rs485 mode, no switching > to rs232 and back involved? > > >> Do it in a loop. As faster, the lockup may occur earlier (but not >> mandatory, 100ms is sufficient in my setup at 115200 Baud on an >> i.mx8mm board). >> With this configuration i get the lockup in around 1 minute. >> >> For my setup it's clear what happens: >> >> - when the tty is closed imx_uart_shutdown() is called. This calls >> imx_uart_stop_tx() >> - for a lockup, the shifter is still busy and imx_uart_stop_tx() >> returns early (as you explained) without modifying ->tx_state. >> - imx_uart_shutdown() proceeds and finally closes the port. Due to >> imx_uart_stop_tx() is not executed completely tx_state is left in >> state ->tx_state == SEND. > > Yes, and imx_uart_shutdown() disables the TCEN which would otherwise > cause _stop_tx to get called when the transmitter is no longer busy. > >> - When the port is opened again, tx_state is SEND and nothing can >> be transmitted any more. The tx path has locked up! >> >> Setting ->tx_state = SEND in imx_uart_shutdown() helps for my issue >> (and should be ok IMHO). > > [I assume you mean tx_state = OFF]. Yes, I suppose doing that would be > ok, but I'm not sure it's a complete fix. In my simple test cast, I have > separate programs invoked to do the I/O and do the mode switch, but in a > real scenario, I'd expect the application itself to just open the device > once, and then do I/O and mode switching as appropriate for the > application logic, and I don't think uart_shutdown would then ever get > called. > >> But IMHO there is one next issue with this situation: When the port >> operates with WAIT_AFTER_RTS and WAIT_AFTER_SEND then some timers >> for callback functions might be active. I did not discover where they >> are stopped for the case when the serial port is closed. Maybe stopping >> is not required ... > > Indeed, that's an extra complication. Adding two hrtimer_try_to_cancel() > in shutdown would probably not hurt, along with setting tx_state OFF. > > I wonder if at least mode switching should simply be disallowed (-EBUSY) > if tx_state is anything but OFF. Is there a valid use-case for switching the mode while the device is transmitting? Is this something we need to support for whatever reason? It sounds rather an obscure thing to do. If not I would strongly vote for disallowing it in favor of a more stable and less complex driver.
On 22/11/2023 14.01, Frieder Schrempf wrote: > On 22.11.23 09:03, Rasmus Villemoes wrote: >> On 21/11/2023 21.49, Eberhard Stoll wrote: >>> But IMHO there is one next issue with this situation: When the port >>> operates with WAIT_AFTER_RTS and WAIT_AFTER_SEND then some timers >>> for callback functions might be active. I did not discover where they >>> are stopped for the case when the serial port is closed. Maybe stopping >>> is not required ... >> >> Indeed, that's an extra complication. Adding two hrtimer_try_to_cancel() >> in shutdown would probably not hurt, along with setting tx_state OFF. >> >> I wonder if at least mode switching should simply be disallowed (-EBUSY) >> if tx_state is anything but OFF. > > Is there a valid use-case for switching the mode while the device is > transmitting? Is this something we need to support for whatever reason? > It sounds rather an obscure thing to do. No, I don't think there is, and that's not at all what I'm trying to do. I was just thinking out loud that maybe we should explicitly disallow it [further, in fact, if possible, it should be disallowed in the serial core]. But of course that requires that ->tx_state can actually be relied upon, which is what my patch attempts to do for the rs232 case - though it might not be an entirely complete fix, as described by Eberhard, since we can get to ->shutdown and thus disable the TC interrupt before it has a chance to fire. Rasmus
diff --git a/drivers/tty/serial/imx.c b/drivers/tty/serial/imx.c index 7341d060f85c..ffee157e13cd 100644 --- a/drivers/tty/serial/imx.c +++ b/drivers/tty/serial/imx.c @@ -708,25 +708,19 @@ static void imx_uart_start_tx(struct uart_port *port) || sport->tx_state == WAIT_AFTER_RTS) { hrtimer_try_to_cancel(&sport->trigger_stop_tx); - - /* - * Enable transmitter and shifter empty irq only if DMA - * is off. In the DMA case this is done in the - * tx-callback. - */ - if (!sport->dma_is_enabled) { - u32 ucr4 = imx_uart_readl(sport, UCR4); - ucr4 |= UCR4_TCEN; - imx_uart_writel(sport, ucr4, UCR4); - } - - sport->tx_state = SEND; } - } else { - sport->tx_state = SEND; } + sport->tx_state = SEND; + + /* + * Enable transmitter and shifter empty irq only if DMA is + * off. In the DMA case this is done in the tx-callback. + */ if (!sport->dma_is_enabled) { + u32 ucr4 = imx_uart_readl(sport, UCR4); + ucr4 |= UCR4_TCEN; + imx_uart_writel(sport, ucr4, UCR4); ucr1 = imx_uart_readl(sport, UCR1); imx_uart_writel(sport, ucr1 | UCR1_TRDYEN, UCR1); }