From patchwork Fri Jan 13 18:43:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Organov X-Patchwork-Id: 13101489 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 C703BC54EBD for ; Fri, 13 Jan 2023 18:45:02 +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:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=WBQzgB8vWvZ6LPJqwEe1yYfiNZYPrO9roGxyRk8Lmq4=; b=4Z7lsrgGcsTdSJ uGz7e6HQsj4xNAxb5JxqRnkMxuhlhjL4V+e2AxX7UXuJ/aHFAcPpeD51pe0IyHMata1gN3nYTzrPD O61YIqd86lnas8LvqAztaGQ347KP0Wka5Xi2atUy139wMsvnOcUr8zsgKQRrBvtox/DqLyShkzoBB zoRRSYU7PFx3lJh4zzb++gkQUuN4kXCyNxkEgluRaslXFINMpVktnj3ZKps1M4f0Pnx8r2cvW32Yn NR7UKjGk89IBLMwSK2OCsZ+wpKg6dHc34ai/7MiXvE43Pwtb1jlkvoO8D8yVJcrkHTmJ236bYo4ve 4BBXr8Ik/k4zCG56QRFg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pGP1y-0045LZ-8m; Fri, 13 Jan 2023 18:43:58 +0000 Received: from mail-lf1-x12e.google.com ([2a00:1450:4864:20::12e]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pGP1l-0045Gt-Qa for linux-arm-kernel@lists.infradead.org; Fri, 13 Jan 2023 18:43:47 +0000 Received: by mail-lf1-x12e.google.com with SMTP id bu8so34296216lfb.4 for ; Fri, 13 Jan 2023 10:43:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=fGRQXniAfmCVOhEPry8KBc9X4/FRyELFse0MGdO3NRc=; b=Rwv/g4mCVgRRqLjbB3j4SFDyC98eqLKfVRU6rwsMPyAPKCDOx42i2FyqkSPeODooW5 cmmkBSIqT1bugkOjdH0Cd2IfTWHwodxdGVhUXUuKLNg2MM/cVsVzo5DXFrXD4xEUyITV /O2iEamJmrAXjVhzv75qdTgr0xLSGqauDkq2MqEHBlj5FAZ9nTfXE3dhyuoAORwyfKLC BUHSmLS79mS41g9xbnB5XsBPNRAWzfZ72Uu1I292tBdAw6/UkU4SA5Miniwppoijbzh0 J0mCGuvI/spmgvrPgL5oLGOatPEaLCjWHvnK2UN3ou2A6GpgBQOi0B0voFNfMSRE1q5b hUgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fGRQXniAfmCVOhEPry8KBc9X4/FRyELFse0MGdO3NRc=; b=1MHfPtzeJvp/G0YJak89AWDRjIlQ5VilxIDxEL0ynWVIWQZjTunj33gbNEosAYJl1I OKAJMv21pr1m2XzQ4v2KNmSUDPJCzfXu8/WChcP0Kq4pCXli97+Thqxn/sGXKzjK9Ote jCBXILwAok4CMXHdwv3A6Q75ExbN3D4qNBeUaiQSA17JvuXDM6tctL3obqX5xiRB2gqc W01H6G7r+PNilybOv365L93EK93VZw66dKoEhPNXGXM9Ff2sKMj61d79KKKX0GMjaHZW 4XwStZt2nJHrahraoN2aX0Occ+LMH6zKAMA66EpaO6nHmVbbQKWDj9+KPwJbGSEpes2Y IxkQ== X-Gm-Message-State: AFqh2kpIr54k0IyZqUodrRE94padRq2k3QG17fMlXGGErauVNm8FtaMm mY0AOYxBp9z1FDiYzz3XobZ9HXgPDh4= X-Google-Smtp-Source: AMrXdXtT2Nn4Ju2q6l6VlG1PM1GuIkdCZMI4iPrZK+vUPRefnDla6fN9sRqXX6avbDaz4wtL7X3p/A== X-Received: by 2002:a05:6512:159b:b0:4b5:9138:145b with SMTP id bp27-20020a056512159b00b004b59138145bmr26918418lfb.14.1673635421844; Fri, 13 Jan 2023 10:43:41 -0800 (PST) Received: from osv.localdomain ([89.175.180.246]) by smtp.gmail.com with ESMTPSA id o11-20020ac2434b000000b004cc9ddce3adsm1261439lfl.82.2023.01.13.10.43.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Jan 2023 10:43:41 -0800 (PST) From: Sergey Organov To: linux-serial@vger.kernel.org Cc: Fabio Estevam , Greg Kroah-Hartman , Jiri Slaby , Richard Genoud , Sascha Hauer , Shawn Guo , Tim Harvey , =?utf-8?q?Tomasz_Mo=C5=84?= , linux-arm-kernel@lists.infradead.org, NXP Linux Team , Pengutronix Kernel Team , Sergey Organov Subject: [PATCH 1/8] serial: imx: factor-out common code to imx_uart_soft_reset() Date: Fri, 13 Jan 2023 21:43:27 +0300 Message-Id: <20230113184334.287130-2-sorganov@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230113184334.287130-1-sorganov@gmail.com> References: <87bko4e65y.fsf@osv.gnss.ru> <20230113184334.287130-1-sorganov@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230113_104345_886211_0A5408E6 X-CRM114-Status: GOOD ( 14.75 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org We perform soft reset in 2 places, slightly differently for no sufficient reasons, so move more generic variant to a function, and re-use the code. Out of 2 repeat counters, 10 and 100, select 10, as the code works at interrupts disabled, and in practice the reset happens immediately. Signed-off-by: Sergey Organov --- drivers/tty/serial/imx.c | 73 ++++++++++++++++++++-------------------- 1 file changed, 37 insertions(+), 36 deletions(-) diff --git a/drivers/tty/serial/imx.c b/drivers/tty/serial/imx.c index 757825edb0cd..bf222d8568a9 100644 --- a/drivers/tty/serial/imx.c +++ b/drivers/tty/serial/imx.c @@ -397,6 +397,39 @@ static void start_hrtimer_ms(struct hrtimer *hrt, unsigned long msec) hrtimer_start(hrt, ms_to_ktime(msec), HRTIMER_MODE_REL); } +/* called with port.lock taken and irqs off */ +static void imx_uart_soft_reset(struct imx_port *sport) +{ + int i = 10; + u32 ucr2, ubir, ubmr, uts; + + /* + * According to the Reference Manual description of the UART SRST bit: + * + * "Reset the transmit and receive state machines, + * all FIFOs and register USR1, USR2, UBIR, UBMR, UBRC, URXD, UTXD + * and UTS[6-3]". + * + * We don't need to restore the old values from USR1, USR2, URXD and + * UTXD. UBRC is read only, so only save/restore the other three + * registers. + */ + ubir = imx_uart_readl(sport, UBIR); + ubmr = imx_uart_readl(sport, UBMR); + uts = imx_uart_readl(sport, IMX21_UTS); + + ucr2 = imx_uart_readl(sport, UCR2); + imx_uart_writel(sport, ucr2 & ~UCR2_SRST, UCR2); + + while (!(imx_uart_readl(sport, UCR2) & UCR2_SRST) && (--i > 0)) + udelay(1); + + /* Restore the registers */ + imx_uart_writel(sport, ubir, UBIR); + imx_uart_writel(sport, ubmr, UBMR); + imx_uart_writel(sport, uts, IMX21_UTS); +} + /* called with port.lock taken and irqs off */ static void imx_uart_start_rx(struct uart_port *port) { @@ -1398,7 +1431,7 @@ static void imx_uart_disable_dma(struct imx_port *sport) static int imx_uart_startup(struct uart_port *port) { struct imx_port *sport = (struct imx_port *)port; - int retval, i; + int retval; unsigned long flags; int dma_is_inited = 0; u32 ucr1, ucr2, ucr3, ucr4, uts; @@ -1430,15 +1463,9 @@ static int imx_uart_startup(struct uart_port *port) dma_is_inited = 1; spin_lock_irqsave(&sport->port.lock, flags); + /* Reset fifo's and state machines */ - i = 100; - - ucr2 = imx_uart_readl(sport, UCR2); - ucr2 &= ~UCR2_SRST; - imx_uart_writel(sport, ucr2, UCR2); - - while (!(imx_uart_readl(sport, UCR2) & UCR2_SRST) && (--i > 0)) - udelay(1); + imx_uart_soft_reset(sport); /* * Finally, clear and enable interrupts @@ -1593,8 +1620,6 @@ static void imx_uart_flush_buffer(struct uart_port *port) { struct imx_port *sport = (struct imx_port *)port; struct scatterlist *sgl = &sport->tx_sgl[0]; - u32 ucr2; - int i = 100, ubir, ubmr, uts; if (!sport->dma_chan_tx) return; @@ -1612,32 +1637,8 @@ static void imx_uart_flush_buffer(struct uart_port *port) sport->dma_is_txing = 0; } - /* - * According to the Reference Manual description of the UART SRST bit: - * - * "Reset the transmit and receive state machines, - * all FIFOs and register USR1, USR2, UBIR, UBMR, UBRC, URXD, UTXD - * and UTS[6-3]". - * - * We don't need to restore the old values from USR1, USR2, URXD and - * UTXD. UBRC is read only, so only save/restore the other three - * registers. - */ - ubir = imx_uart_readl(sport, UBIR); - ubmr = imx_uart_readl(sport, UBMR); - uts = imx_uart_readl(sport, IMX21_UTS); + imx_uart_soft_reset(sport); - ucr2 = imx_uart_readl(sport, UCR2); - ucr2 &= ~UCR2_SRST; - imx_uart_writel(sport, ucr2, UCR2); - - while (!(imx_uart_readl(sport, UCR2) & UCR2_SRST) && (--i > 0)) - udelay(1); - - /* Restore the registers */ - imx_uart_writel(sport, ubir, UBIR); - imx_uart_writel(sport, ubmr, UBMR); - imx_uart_writel(sport, uts, IMX21_UTS); } static void From patchwork Fri Jan 13 18:43:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Organov X-Patchwork-Id: 13101491 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 E4AEBC3DA78 for ; Fri, 13 Jan 2023 18:45:21 +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:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=A7/D9vQ3E0iEvfjbPtp6IFD+Gx5xQaUuLqeOPitXB1w=; b=SMejGI4Xr2otlH 3FeTQt/gEPrnmxZ7WOJv9ePlESjZiG0c/z4odj7STpMqMApX/dJ4hqxPIjwpYRp/ygMDLv03nuuTf ZEIIf5uVVZoBVHP32C17F1mxE429UWZ1ycHnqaucVntdekc4ju+wpgbP2jx/qd7g8F9rjbxlHFQdD R+pNS65mXnsuWxzSqhEN9UMoB97fKWIDLHr5KQ5pyuImrORHtYseMrc0B9rp7NAQ+gm11XfswO0En UQZBI9XajB8fE6n7ydhcLp8RmeMebx8tuhkPAhfI45Vk9Nlt++gzuXja8LiAn71f8PYduSU1e942i GdPKr3SjkcO6uP9UhZYg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pGP2G-0045P9-8x; Fri, 13 Jan 2023 18:44:16 +0000 Received: from mail-lf1-x12b.google.com ([2a00:1450:4864:20::12b]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pGP1m-0045H3-An for linux-arm-kernel@lists.infradead.org; Fri, 13 Jan 2023 18:43:49 +0000 Received: by mail-lf1-x12b.google.com with SMTP id bf43so34331443lfb.6 for ; Fri, 13 Jan 2023 10:43:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=vDEp4eKXdg/3wssI2Ou1QYWdbAeeL+58ez61t5CUM9E=; b=DEbvU45S2p8aPAopC6a9pKkM/u8KbX0uDY8ZXqTQ8UeOAi2PBhwGYPABgd1xwf/APN z25YgjS9VUobk7OFhqVQGKOhcLfKxa0cESbJj92jkP8bp48ZIPYTsVg2GgVkL/Jaof+e ZnDVW2pAABKh2MYe7/VKBvsY03ZHLUcLvw9rY6ARvMKKQCWntiS2frO1usD1jUg3yK8+ FFiyDbgoVvh9oCqf4TCj8C2rSzX1PluXbLFC2jo+OI8dYnfGR1RvnQdd1yPAxnZqLP0p 6sHCpR7awMa7XbsTnSEoZR6dtkOfq4PnDIANA46abeKDC9abul6MOtWAA5jkv7t4EzhQ IfkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vDEp4eKXdg/3wssI2Ou1QYWdbAeeL+58ez61t5CUM9E=; b=ZPIwYuN2Vlf9VC1aN7yqtcE73LgmmYG516WBZekNAPvnFNSkPaY1i5TriFs0OB7Za1 j6oUp244j7dQ1GKBUajN0BsDDu4SAEqQMMYYiZYO1kvoRT/iavyXd7XfqIVFq80Sm5pb uLeVmaxElst3A66xNa43mHNJg2vP27NwLriUfQL3RnrjzFfuA6f5RmRHH2hb9NaJeCc9 T3qMQxqT5DuzOwrorCoRw0BnW5ycbsrXSJGOMqSFrxX1J4KnJJOwFU3+qTuakSGau4c7 wCP2A5ggYw6ovPhbi5hqqDtz2M2FHX+Z2iUBdylnnc2f5sAGr7NG0RcnO7gi58ldIWYu 7Lsg== X-Gm-Message-State: AFqh2krO2b4eKs4rdx4LQwFhWYouIbUb1oVFFNJjZh26TnH7zVM94vh+ xNUCtzvGKJtNSsEhReLUpnM= X-Google-Smtp-Source: AMrXdXsa/zrmKcVLowOWxl/7ymTxOgldOiFPfuXlVaUcxJRNIQqfkMfBqpGi1CSUoCmyh6GxryK3Ng== X-Received: by 2002:a19:f614:0:b0:4cc:9de0:c251 with SMTP id x20-20020a19f614000000b004cc9de0c251mr2658400lfe.40.1673635423314; Fri, 13 Jan 2023 10:43:43 -0800 (PST) Received: from osv.localdomain ([89.175.180.246]) by smtp.gmail.com with ESMTPSA id o11-20020ac2434b000000b004cc9ddce3adsm1261439lfl.82.2023.01.13.10.43.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Jan 2023 10:43:42 -0800 (PST) From: Sergey Organov To: linux-serial@vger.kernel.org Cc: Fabio Estevam , Greg Kroah-Hartman , Jiri Slaby , Richard Genoud , Sascha Hauer , Shawn Guo , Tim Harvey , =?utf-8?q?Tomasz_Mo=C5=84?= , linux-arm-kernel@lists.infradead.org, NXP Linux Team , Pengutronix Kernel Team , Sergey Organov Subject: [PATCH 2/8] serial: imx: work-around for hardware RX flood Date: Fri, 13 Jan 2023 21:43:28 +0300 Message-Id: <20230113184334.287130-3-sorganov@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230113184334.287130-1-sorganov@gmail.com> References: <87bko4e65y.fsf@osv.gnss.ru> <20230113184334.287130-1-sorganov@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230113_104346_398408_4B2AAFC6 X-CRM114-Status: GOOD ( 31.12 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Check if hardware Rx flood is in progress, and issue soft reset to UART to stop the flood. A way to reproduce the flood (checked on iMX6SX) is: open iMX UART at 9600 8N1, and from external source send 0xf0 char at 115200 8N1. In about 90% of cases this starts a flood of "receiving" of 0xff characters by the iMX UART that is terminated by any activity on RxD line, or could be stopped by issuing soft reset to the UART (just stop/start of RX does not help). Note that in essence what we did here is sending isolated start bit about 2.4 times shorter than it is to be if issued on the UART configured baud rate. There was earlier attempt to fix similar issue in: 'commit b38cb7d25711 ("serial: imx: Disable new features of autobaud detection")', but apparently it only gets harder to reproduce the issue after that commit. Signed-off-by: Sergey Organov --- drivers/tty/serial/imx.c | 123 ++++++++++++++++++++++++++++++--------- 1 file changed, 95 insertions(+), 28 deletions(-) diff --git a/drivers/tty/serial/imx.c b/drivers/tty/serial/imx.c index bf222d8568a9..e7fce31e460d 100644 --- a/drivers/tty/serial/imx.c +++ b/drivers/tty/serial/imx.c @@ -210,6 +210,9 @@ struct imx_port { struct mctrl_gpios *gpios; + /* counter to stop 0xff flood */ + int idle_counter; + /* shadow registers */ unsigned int ucr1; unsigned int ucr2; @@ -428,6 +431,8 @@ static void imx_uart_soft_reset(struct imx_port *sport) imx_uart_writel(sport, ubir, UBIR); imx_uart_writel(sport, ubmr, UBMR); imx_uart_writel(sport, uts, IMX21_UTS); + + sport->idle_counter = 0; } /* called with port.lock taken and irqs off */ @@ -834,15 +839,66 @@ static irqreturn_t imx_uart_txint(int irq, void *dev_id) return IRQ_HANDLED; } +/* Check if hardware Rx flood is in progress, and issue soft reset to stop it. + * This is to be called from Rx ISRs only when some bytes were actually + * received. + * + * A way to reproduce the flood (checked on iMX6SX) is: open iMX UART at 9600 + * 8N1, and from external source send 0xf0 char at 115200 8N1. In about 90% of + * cases this starts a flood of "receiving" of 0xff characters by the iMX6 UART + * that is terminated by any activity on RxD line, or could be stopped by + * issuing soft reset to the UART (just stop/start of RX does not help). Note + * that what we do here is sending isolated start bit about 2.4 times shorter + * than it is to be on UART configured baud rate. + */ +static void imx_uart_check_flood(struct imx_port *sport, u32 usr2) +{ + /* To detect hardware 0xff flood we monitor RxD line between RX + * interrupts to isolate "receiving" of char(s) with no activity + * on RxD line, that'd never happen on actual data transfers. + * + * We use USR2_WAKE bit to check for activity on RxD line, but we have a + * race here if we clear USR2_WAKE when receiving of a char is in + * progress, so we might get RX interrupt later with USR2_WAKE bit + * cleared. Note though that as we don't try to clear USR2_WAKE when we + * detected no activity, this race may hide actual activity only once. + * + * Yet another case where receive interrupt may occur without RxD + * activity is expiration of aging timer, so we consider this as well. + * + * We use 'idle_counter' to ensure that we got at least so many RX + * interrupts without any detected activity on RxD line. 2 cases + * described plus 1 to be on the safe side gives us a margin of 3, + * below. In practice I was not able to produce a false positive to + * induce soft reset at regular data transfers even using 1 as the + * margin, so 3 is actually very strong. + * + * We count interrupts, not chars in 'idle-counter' for simplicity. + */ + + if (usr2 & USR2_WAKE) { + imx_uart_writel(sport, USR2_WAKE, USR2); + sport->idle_counter = 0; + } else if (++sport->idle_counter > 3) { + dev_warn(sport->port.dev, "RX flood detected: soft reset."); + imx_uart_soft_reset(sport); /* also clears 'sport->idle_counter' */ + } +} + static irqreturn_t __imx_uart_rxint(int irq, void *dev_id) { struct imx_port *sport = dev_id; unsigned int rx, flg, ignored = 0; struct tty_port *port = &sport->port.state->port; + u32 usr2; - while (imx_uart_readl(sport, USR2) & USR2_RDR) { - u32 usr2; + usr2 = imx_uart_readl(sport, USR2); + /* If we received something, check for 0xff flood */ + if (usr2 & USR2_RDR) + imx_uart_check_flood(sport, usr2); + + for ( ; usr2 & USR2_RDR; usr2 = imx_uart_readl(sport, USR2)) { flg = TTY_NORMAL; sport->port.icount.rx++; @@ -1180,55 +1236,64 @@ static void imx_uart_dma_rx_callback(void *data) status = dmaengine_tx_status(chan, sport->rx_cookie, &state); if (status == DMA_ERROR) { + spin_lock(&sport->port.lock); imx_uart_clear_rx_errors(sport); + spin_unlock(&sport->port.lock); return; } - if (!(sport->port.ignore_status_mask & URXD_DUMMY_READ)) { + /* + * The state-residue variable represents the empty space + * relative to the entire buffer. Taking this in consideration + * the head is always calculated base on the buffer total + * length - DMA transaction residue. The UART script from the + * SDMA firmware will jump to the next buffer descriptor, + * once a DMA transaction if finalized (IMX53 RM - A.4.1.2.4). + * Taking this in consideration the tail is always at the + * beginning of the buffer descriptor that contains the head. + */ - /* - * The state-residue variable represents the empty space - * relative to the entire buffer. Taking this in consideration - * the head is always calculated base on the buffer total - * length - DMA transaction residue. The UART script from the - * SDMA firmware will jump to the next buffer descriptor, - * once a DMA transaction if finalized (IMX53 RM - A.4.1.2.4). - * Taking this in consideration the tail is always at the - * beginning of the buffer descriptor that contains the head. - */ + /* Calculate the head */ + rx_ring->head = sg_dma_len(sgl) - state.residue; - /* Calculate the head */ - rx_ring->head = sg_dma_len(sgl) - state.residue; + /* Calculate the tail. */ + bd_size = sg_dma_len(sgl) / sport->rx_periods; + rx_ring->tail = ((rx_ring->head-1) / bd_size) * bd_size; - /* Calculate the tail. */ - bd_size = sg_dma_len(sgl) / sport->rx_periods; - rx_ring->tail = ((rx_ring->head-1) / bd_size) * bd_size; + if (rx_ring->head <= sg_dma_len(sgl) && + rx_ring->head > rx_ring->tail) { - if (rx_ring->head <= sg_dma_len(sgl) && - rx_ring->head > rx_ring->tail) { + /* Move data from tail to head */ + r_bytes = rx_ring->head - rx_ring->tail; - /* Move data from tail to head */ - r_bytes = rx_ring->head - rx_ring->tail; + /* If we received something, check for 0xff flood */ + if (r_bytes > 0) { + spin_lock(&sport->port.lock); + imx_uart_check_flood(sport, imx_uart_readl(sport, USR2)); + spin_unlock(&sport->port.lock); + } + + if (!(sport->port.ignore_status_mask & URXD_DUMMY_READ)) { /* CPU claims ownership of RX DMA buffer */ dma_sync_sg_for_cpu(sport->port.dev, sgl, 1, - DMA_FROM_DEVICE); + DMA_FROM_DEVICE); w_bytes = tty_insert_flip_string(port, - sport->rx_buf + rx_ring->tail, r_bytes); + sport->rx_buf + rx_ring->tail, r_bytes); /* UART retrieves ownership of RX DMA buffer */ dma_sync_sg_for_device(sport->port.dev, sgl, 1, - DMA_FROM_DEVICE); + DMA_FROM_DEVICE); if (w_bytes != r_bytes) sport->port.icount.buf_overrun++; sport->port.icount.rx += w_bytes; - } else { - WARN_ON(rx_ring->head > sg_dma_len(sgl)); - WARN_ON(rx_ring->head <= rx_ring->tail); } + } else { + WARN_ON(rx_ring->head > sg_dma_len(sgl)); + WARN_ON(rx_ring->head <= rx_ring->tail); } if (w_bytes) { @@ -1304,6 +1369,8 @@ static void imx_uart_clear_rx_errors(struct imx_port *sport) imx_uart_writel(sport, USR2_ORE, USR2); } + sport->idle_counter = 0; + } #define TXTL_DEFAULT 2 /* reset default */ From patchwork Fri Jan 13 18:43:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Sergey Organov X-Patchwork-Id: 13101490 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 45F6EC677F1 for ; Fri, 13 Jan 2023 18:45:05 +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:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=pc9Ex2ubYI2H5pzgMf4cqtGjmdzs5L6TFErCS9A/N9U=; b=ENU1lImEPQ70Ok ar/sti09Mh5FKib8oiOKkOM5EP9TLyebsAnCluj/r5lhuT9a2b0dZifa4tJhYGX1eBVRqxBsEZmy7 3t2qhJfSBoV4uRQ1pnYPJNE2McOYfEuh4JvMHGnJOBQrqswfJ05xxyKKR4h4gX7KXZG0612yPk85k ZAK4+kzLt+H0Lm35gBQZi9whE2Btf3sVPA62UL4dTGzxyfJYEGCMBsx5xqnj9LzjtTi2ZX0Lql5E6 CuLOjmh3RfyqgbvMaiJi5c1xm9oBcS5/vc2fy97vv9Vfb7xCIi28GOtRnofDbAgludkrp/c1a91Vx bgEp+alkCMeqF/RQD5GA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pGP27-0045N7-0z; Fri, 13 Jan 2023 18:44:07 +0000 Received: from mail-lf1-x12e.google.com ([2a00:1450:4864:20::12e]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pGP1m-0045H7-3u for linux-arm-kernel@lists.infradead.org; Fri, 13 Jan 2023 18:43:48 +0000 Received: by mail-lf1-x12e.google.com with SMTP id bf43so34331541lfb.6 for ; Fri, 13 Jan 2023 10:43:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=+uSogoDZIxozQW5QEm2zGToSkpBWHSYVqPpGas5pKh8=; b=TR0PtLOgazeFx4JTnDSy1KbfiovsMAKfP5Httj5Bcv8O0FaCWJP41G6xvzqpsRhaTk tlnCXfjwHYb40BlO7LkuTjZSSycCwZWgp+ij13dWYzb/fPEE5/86IgJ4ShEvD8yhRWcS OORMkGKiNQx5xYcFM61F+2SfejYzUh/K/NSLME5HPh19Y7BlpbwIT6P5Vo3KbamsSf07 vubxy6zIxbcIdcVhFi3wfGrI6TZxfyKHmMorp3+deiowuiaA+dam3XbKAErYVdUmiOap Qrh+u/gyVpqcS9VEnXoMFEFbPT7I674ryim/3s9J69M5q6MOr/TlaXtf9USozUW8bUoo pZOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+uSogoDZIxozQW5QEm2zGToSkpBWHSYVqPpGas5pKh8=; b=NN7Xl2jFxn9+6rDpdcxcPKoPD2Bc+cnrfHF3Vfpbq5MIBXcxlbYQ86HljgOWimdkqn NGyWdEBiVhtAuTlkei8mCDl851QqnTGrPdfzaFwgELK9MumFgfKu+n9axGZHXqVmMxxb Wip9QrP9LYxFNFr9dQjgi7tPjzkgkqDxtHiRvmWuIjzg/f2rly2Y6AdVlqIEHy0nPhq8 BkK0edmXGJKGRXqPQLMDlfIRsfqUzeqSCLTqtBDMj/oAlmgce6J5azO4MjYryNMLN+wV kgKwnSu0DJIjE+gsx6+cul6+YXWPT/A2nGwzVqG3Lsn7v3OnCboqqyciEo4TW58cByN2 WYbg== X-Gm-Message-State: AFqh2korBJoE8g5cixUVOZYJJvMh7Uj/7i4ANyJTbvCBM2KzONm+nd28 fSO9oITSXipvfVHnXtAKMJQ= X-Google-Smtp-Source: AMrXdXv2v9QEPDicYWZ6C8d5dObmPqiC3pJ1vOYx0+av0mtu3SOR4E0mlyiirZ5mjQCR8HrdllC0GA== X-Received: by 2002:a05:6512:2349:b0:4a4:68b9:66cd with SMTP id p9-20020a056512234900b004a468b966cdmr23194583lfu.24.1673635424853; Fri, 13 Jan 2023 10:43:44 -0800 (PST) Received: from osv.localdomain ([89.175.180.246]) by smtp.gmail.com with ESMTPSA id o11-20020ac2434b000000b004cc9ddce3adsm1261439lfl.82.2023.01.13.10.43.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Jan 2023 10:43:44 -0800 (PST) From: Sergey Organov To: linux-serial@vger.kernel.org Cc: Fabio Estevam , Greg Kroah-Hartman , Jiri Slaby , Richard Genoud , Sascha Hauer , Shawn Guo , Tim Harvey , =?utf-8?q?Tomasz_Mo=C5=84?= , linux-arm-kernel@lists.infradead.org, NXP Linux Team , Pengutronix Kernel Team , Sergey Organov Subject: [PATCH 3/8] serial: imx: do not sysrq broken chars Date: Fri, 13 Jan 2023 21:43:29 +0300 Message-Id: <20230113184334.287130-4-sorganov@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230113184334.287130-1-sorganov@gmail.com> References: <87bko4e65y.fsf@osv.gnss.ru> <20230113184334.287130-1-sorganov@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230113_104346_178769_84DE8B85 X-CRM114-Status: GOOD ( 11.44 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Do not call uart_handle_sysrq_char() if we got any receive error along with the character, as we don't want random junk to be considered a sysrq. Signed-off-by: Sergey Organov Reviewed-by: Ilpo Järvinen --- drivers/tty/serial/imx.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/tty/serial/imx.c b/drivers/tty/serial/imx.c index e7fce31e460d..1c950112a598 100644 --- a/drivers/tty/serial/imx.c +++ b/drivers/tty/serial/imx.c @@ -911,9 +911,6 @@ static irqreturn_t __imx_uart_rxint(int irq, void *dev_id) continue; } - if (uart_handle_sysrq_char(&sport->port, (unsigned char)rx)) - continue; - if (unlikely(rx & URXD_ERR)) { if (rx & URXD_BRK) sport->port.icount.brk++; @@ -942,7 +939,8 @@ static irqreturn_t __imx_uart_rxint(int irq, void *dev_id) flg = TTY_OVERRUN; sport->port.sysrq = 0; - } + } else if (uart_handle_sysrq_char(&sport->port, (unsigned char)rx)) + continue; if (sport->port.ignore_status_mask & URXD_DUMMY_READ) goto out; From patchwork Fri Jan 13 18:43:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Organov X-Patchwork-Id: 13101492 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 AFD53C3DA78 for ; Fri, 13 Jan 2023 18:45:25 +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:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=2nAsQOlfStTZBJaCzgVepv9kz0cXrdImwhu0OpihQXk=; b=M/0yCFO3N3UAVg lCn4XKM3T/faazulpFJMcB+Fs3AG8/0J6XgNrfsegzWFXSqgosAPaj7aQU8G/YrZzL9rEmnhkRN6r h6VIocjJ59fCHerFCtBXZ5Q9SNo1w80lg43sUq6IeN3FHVTS/wncCNs05LdoI3ozLUJd7q0GYML0o 9koRYyAHuELR/cBBf80MhatfOgwl6v/bSlNLlJpAs0mUv8eEV/o6yEie/jrDi5roWmtVwIkkpoIk+ 7DoitiCZ9rU66hoKcoGtctXQE94Y4EeKX9u0e+MFWvGIHbbSAFHP+L6rAJlMdH9j9jCJm8hEjFOjz II8ugeHZ0g+PxpQJ1/aA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pGP2P-0045S6-Aq; Fri, 13 Jan 2023 18:44:25 +0000 Received: from mail-lf1-x134.google.com ([2a00:1450:4864:20::134]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pGP1o-0045I6-Pg for linux-arm-kernel@lists.infradead.org; Fri, 13 Jan 2023 18:43:50 +0000 Received: by mail-lf1-x134.google.com with SMTP id bu8so34296605lfb.4 for ; Fri, 13 Jan 2023 10:43:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=BEuxX1Ll6053jaM5wYHpbycjGtKOkT1kwUWem6LtYrM=; b=Qv3ZTHYSreLfmMGbsEJVQeKAj0Rsp2AJskikpPzMRGkYLhwu1mXNJoM40qhoqE2Q2N uvKLSM6tPyqNDvP4FVR3V6bs2ptSBvEAVoyXwumN6eTN6gmMZayssMjpShx1E4HGJTqa 842DzUOAgACQtCZe2pgOxXqw55+UfF5XeL9RPfyv798meJ2/U2jWSkOrSTnNXYu7r9cW Jc9TJUmBENDr2gbsacQroSK/NgVhIDxBwCDR/svbH7hn/C6RCxVAR6kETLPsU/aHg1DF Es4c2eRfGJrbmAUPRjeiqpkg3bDP304P1eL60EgJgkQjZTPku1KA2VIQF4nWu9aKlqwH GuXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=BEuxX1Ll6053jaM5wYHpbycjGtKOkT1kwUWem6LtYrM=; b=AYD7jPCQhI8OZETg24JHDoiajBPdMputvZXPGHZmwOjqj04NOQax3Yt8DW3ISfYFbU AYIdVrvRpiNo6sLsX9EXjL8bFDTY31/OyUMGdIUoT99Y7GXcnpw6jGKCReJkS/TRqR/D RCSbuptYHG/e1jJFKUg8/4TT3s8GSK4rp1L44lx1gSwYv4iX4zmo6Uk1H9XnfwWHy0r8 doRXqsUJZpX3agH/JQlcuPGEBrXYeE2hSHp0onz4JgiKPbTJsNsH0F8vSKzJfzagE/yx gY9+0E3iuh+EgosVBcV9eT1pr4FJLzZCOuXaanbRSxl/PvPEZvf5Pmov8YjvqvodM2Ls H5lg== X-Gm-Message-State: AFqh2kqiK451rDHTGy4G9r/4GzXMeE32O97uBgu0DGrh6lyefuWJjuH0 KBzaL55bbBr4y2MSzLYHOHPSdysrTO8= X-Google-Smtp-Source: AMrXdXvFqBm0yaQK2e38U4fE47XqSrNqGwyGOCkcCBfg8zyQzVL6ozWAI3Dhet38lYjyS8B+I/lR5Q== X-Received: by 2002:a05:6512:10d0:b0:4cb:4374:cc78 with SMTP id k16-20020a05651210d000b004cb4374cc78mr16172770lfg.26.1673635426335; Fri, 13 Jan 2023 10:43:46 -0800 (PST) Received: from osv.localdomain ([89.175.180.246]) by smtp.gmail.com with ESMTPSA id o11-20020ac2434b000000b004cc9ddce3adsm1261439lfl.82.2023.01.13.10.43.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Jan 2023 10:43:45 -0800 (PST) From: Sergey Organov To: linux-serial@vger.kernel.org Cc: Fabio Estevam , Greg Kroah-Hartman , Jiri Slaby , Richard Genoud , Sascha Hauer , Shawn Guo , Tim Harvey , =?utf-8?q?Tomasz_Mo=C5=84?= , linux-arm-kernel@lists.infradead.org, NXP Linux Team , Pengutronix Kernel Team , Sergey Organov Subject: [PATCH 4/8] serial: imx: do not break from FIFO reading loop prematurely Date: Fri, 13 Jan 2023 21:43:30 +0300 Message-Id: <20230113184334.287130-5-sorganov@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230113184334.287130-1-sorganov@gmail.com> References: <87bko4e65y.fsf@osv.gnss.ru> <20230113184334.287130-1-sorganov@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230113_104348_875389_FE132576 X-CRM114-Status: GOOD ( 12.77 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org There is no reason to prematurely break out of FIFO reading loop, and it might cause needless reenters into ISR, so keep reading until FIFO is empty. Signed-off-by: Sergey Organov --- drivers/tty/serial/imx.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/drivers/tty/serial/imx.c b/drivers/tty/serial/imx.c index 1c950112a598..b96b0edc7854 100644 --- a/drivers/tty/serial/imx.c +++ b/drivers/tty/serial/imx.c @@ -888,7 +888,7 @@ static void imx_uart_check_flood(struct imx_port *sport, u32 usr2) static irqreturn_t __imx_uart_rxint(int irq, void *dev_id) { struct imx_port *sport = dev_id; - unsigned int rx, flg, ignored = 0; + unsigned int rx, flg; struct tty_port *port = &sport->port.state->port; u32 usr2; @@ -921,11 +921,8 @@ static irqreturn_t __imx_uart_rxint(int irq, void *dev_id) if (rx & URXD_OVRRUN) sport->port.icount.overrun++; - if (rx & sport->port.ignore_status_mask) { - if (++ignored > 100) - goto out; + if (rx & sport->port.ignore_status_mask) continue; - } rx &= (sport->port.read_status_mask | 0xFF); @@ -943,13 +940,12 @@ static irqreturn_t __imx_uart_rxint(int irq, void *dev_id) continue; if (sport->port.ignore_status_mask & URXD_DUMMY_READ) - goto out; + continue; if (tty_insert_flip_char(port, rx, flg) == 0) sport->port.icount.buf_overrun++; } -out: tty_flip_buffer_push(port); return IRQ_HANDLED; From patchwork Fri Jan 13 18:43:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Sergey Organov X-Patchwork-Id: 13101493 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 3BC58C54EBD for ; Fri, 13 Jan 2023 18:45:55 +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:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=oX1uLGMUgvOh+ml8k1vJxAYI4Rf417dAoSpbRwUEmTA=; b=LagcB4YpxdDpcL GZdN8/a3r5f9FiuxzmEWZhalYAIryjxbN9AK3N/1IjP9FlVAtk2jbkbIPWE7Gu5YxM1c3WLSInlvS vCsuaTogNaJ7QLofYbaZRwF3cwmLcEVa5a3JR5xqRG5xz7aBMcK3xnCya8y4pNHw9mN7BjupJhKPd pWrW2wGBit+PHM0yhi8Lqkq/92TlOzbnyEP9FK0c6bGhbuZw0XRfpW9Ae4hGmCc6ph8KTJN9Lc27x 9jDMtTZtpOhFXdRFOPIAWh4N2Mmgjn9QFoCkEA07cga7tnvlFdwEi82IEZ6M0wyVrVW/zHS61Kz79 9loHGdSK2tPqa3zg9kow==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pGP2Z-0045Vn-8V; Fri, 13 Jan 2023 18:44:36 +0000 Received: from mail-lf1-x12e.google.com ([2a00:1450:4864:20::12e]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pGP1p-0045IV-5y for linux-arm-kernel@lists.infradead.org; Fri, 13 Jan 2023 18:43:50 +0000 Received: by mail-lf1-x12e.google.com with SMTP id bp15so34301796lfb.13 for ; Fri, 13 Jan 2023 10:43:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=TbM/0E+S8Ggk1+wMb510R+JTgrBTxf1YBPHLYLwKArg=; b=nLU3w/vxV1hxV25+86rkxBbQZK+BmAIZLXx6T+ellWNO3FpbmA8o5fuxCUB5Jm2Q8i Al6w8SjBakZcN4kSBLbvfyqqcOAaovr7977oM2iJf/w70U6/0ouACx7oyK3lCO7PRxf8 gbAHAhB9ArTotSJvbqp0c8cWqmQmrIkLIPMRC537cwMjD5fDc9NjIBa7AIsphaeFE93j XtPXFBAyySR9uCN3OK0Q8dPDY0q1UFH+YihyJpdE8YTUQYRZYUX/s4ZzA+3+bodw5XGB tMV9rXRYtuMflakV1THt7ZX9gW+YyBVbH4kekmi2U1ub9iWEEnPSoEssXhxS+QSm/1hk PXYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=TbM/0E+S8Ggk1+wMb510R+JTgrBTxf1YBPHLYLwKArg=; b=jarCWGgSiv9rXIr8FHX50CmzZcNsQegQJhvBJr6D8KfrxpAJpeizsi0x5RqRV7NMkl kyCc0ikKo9KTbi6XMk2JMxkmmv6lLb+1go87L5A/g2qZqeKkHbDYMn5MDbB3I4r03s+u zAoguSlDBYOU0oc6qA+8wy9EmtG8zY/1DjJnMIcTY8yWV41cw6Sbhmb3ahOhRvUBqaCz p9cP8A4YvTH5uDJDorK0TuXIDAstvIUGuvyIxFzAZJogVwZ/N4fKTcQlbRd+9p1J3+bd Eu1WsJ8bHbHA2hEMJil/R/z1A6NbodjkKNE28SEjvDoRS3eayAjyc3m92eqIH5mEMrjM y0aQ== X-Gm-Message-State: AFqh2kr2RafaDKNXZE2AagYSfe2JH5e9NOHpwmZf+C5Axx73/+CwOxBa PCecu2eeOoa9HzSOibBR+fo= X-Google-Smtp-Source: AMrXdXsXqRwIW3RF1gdJ2+dC0m7vCsdhy4s6Ys42aIGjx4EcO93YP8XInQWa95Xzt9my4fC1xjEuRg== X-Received: by 2002:ac2:429a:0:b0:4b5:7aad:2690 with SMTP id m26-20020ac2429a000000b004b57aad2690mr19833381lfh.12.1673635427842; Fri, 13 Jan 2023 10:43:47 -0800 (PST) Received: from osv.localdomain ([89.175.180.246]) by smtp.gmail.com with ESMTPSA id o11-20020ac2434b000000b004cc9ddce3adsm1261439lfl.82.2023.01.13.10.43.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Jan 2023 10:43:47 -0800 (PST) From: Sergey Organov To: linux-serial@vger.kernel.org Cc: Fabio Estevam , Greg Kroah-Hartman , Jiri Slaby , Richard Genoud , Sascha Hauer , Shawn Guo , Tim Harvey , =?utf-8?q?Tomasz_Mo=C5=84?= , linux-arm-kernel@lists.infradead.org, NXP Linux Team , Pengutronix Kernel Team , Sergey Organov Subject: [PATCH 5/8] serial: imx: remove redundant USR2 read from FIFO reading loop Date: Fri, 13 Jan 2023 21:43:31 +0300 Message-Id: <20230113184334.287130-6-sorganov@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230113184334.287130-1-sorganov@gmail.com> References: <87bko4e65y.fsf@osv.gnss.ru> <20230113184334.287130-1-sorganov@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230113_104349_262132_A5D07DEF X-CRM114-Status: GOOD ( 11.11 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org There is no need to read USR2 twice at every loop iteration: get rid of the second read. Signed-off-by: Sergey Organov Reviewed-by: Ilpo Järvinen --- drivers/tty/serial/imx.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/tty/serial/imx.c b/drivers/tty/serial/imx.c index b96b0edc7854..c44a7293c013 100644 --- a/drivers/tty/serial/imx.c +++ b/drivers/tty/serial/imx.c @@ -904,7 +904,6 @@ static irqreturn_t __imx_uart_rxint(int irq, void *dev_id) rx = imx_uart_readl(sport, URXD0); - usr2 = imx_uart_readl(sport, USR2); if (usr2 & USR2_BRCD) { imx_uart_writel(sport, USR2_BRCD, USR2); if (uart_handle_break(&sport->port)) From patchwork Fri Jan 13 18:43:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Organov X-Patchwork-Id: 13101494 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 6498EC3DA78 for ; Fri, 13 Jan 2023 18:46:09 +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:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Gl+gR9WdpZIjJvJzxW3PQU+cakYdOGk2UzjZTN0IaMk=; b=jSNUtK/9vJfPJy RijCpwZb+FkYDPtOwOFSNMdKJ91AyqO+KExN8wzDhw44mnGc5HblUq5opiEyDDksP8B3IQzgJSfqV C/zGDj8AxktwSwDs2c96ie85qkHUAm6CBkkSZiLPTYLzjOHER1nKiHDLoyWESBjOsN0lbNV4S4tyM 60lJui9BtZOQGgIzEpX808pQvGXykONoXE0qht4U1xDLSxg2vjjZi0Lh1bm1RdlhAROVLZMDdULwz REaGyh+HKQfLkLyJifmRSISi3LILeUW9OkJl9g8Z/5D0AtCySfHeH5SOJ1nEt9JEPF3Cut+S0KbBX E2T+O5iLxbH0hRZY5LSQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pGP2s-0045fs-3I; Fri, 13 Jan 2023 18:44:54 +0000 Received: from mail-lf1-x136.google.com ([2a00:1450:4864:20::136]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pGP1s-0045JI-0y for linux-arm-kernel@lists.infradead.org; Fri, 13 Jan 2023 18:43:53 +0000 Received: by mail-lf1-x136.google.com with SMTP id x40so249417lfu.12 for ; Fri, 13 Jan 2023 10:43:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=gEk4AFlxAF8T5iRhtAEH/nRNJxTDpq08gbezozP0K5c=; b=EST2u7+EY1BljGeUo+Jl+mIEA0GL3IUBwxEHYsN5Q+frpg+8rXwH/USoGKBXXuaaCq 4DNbVhaE1UxEjroEhkxeNYPTLsYfLK+yC4eH0+a3E2VRZQO287qJ1+vUifcABD7edciy ycSPaQLULmrLkqqGzc46TGE7VatG3iA9bXJE/PPeqthdFEiWQ0L0MDzDEWFRU56urgEK 47qq8OrIHpK00lgOiWmQJLNUc1ebiUV9rWtinefVmz43yYMhwycjYauOCvqVM4Z+8Toj uu7vwLvuTsKARCXTsFXHDttrpfuEgg4m2UyJGCEl9cn9qKPdI6WApM12xgUlj5CHqim9 9qQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=gEk4AFlxAF8T5iRhtAEH/nRNJxTDpq08gbezozP0K5c=; b=4zqd7AQBm9e0lG3HRT5lYk/KdmbKIi22AMP8wpjZ8CP2Cma3YsgfvD6vzXklw7sC9K mk1nW32YIZ3jmYin5f0MeSv1JWb3so8haW8UIAAms4iy75SUYjJICXCP0cxMGzuayR0T 95kGpS3YisZsMG8uVNQtJ6Db8qF/jgSaWfHpp9GyrAABUbbitBDDHySHHTYsuOX28Ewv qohAVWdmJlHSGpWl8KSRGF5btNalfrPlilYbvYBiMSjHEx1St1E5fscG87i+097W7y8D cfSBDhD1INRRtFQzhM7DxC55iFyiElInmjzA0M40LbdwmxuUMbzChgPxluDhJUgF8TU3 EPRw== X-Gm-Message-State: AFqh2koscIZ6Ue4eFm1r7braetctG9advijA8NitTbOWW+egAoj+wSOY yTa8+OnbHXxFqMmWpdnPXBs= X-Google-Smtp-Source: AMrXdXsFRmXLBepa75IdA8upDEUsOGVX6bHbVT7iNgg7WPN7teH0vjcgcywcHXIQ6vaZhr2DUfGdZw== X-Received: by 2002:ac2:5234:0:b0:4a7:64ea:7855 with SMTP id i20-20020ac25234000000b004a764ea7855mr211232lfl.47.1673635429454; Fri, 13 Jan 2023 10:43:49 -0800 (PST) Received: from osv.localdomain ([89.175.180.246]) by smtp.gmail.com with ESMTPSA id o11-20020ac2434b000000b004cc9ddce3adsm1261439lfl.82.2023.01.13.10.43.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Jan 2023 10:43:48 -0800 (PST) From: Sergey Organov To: linux-serial@vger.kernel.org Cc: Fabio Estevam , Greg Kroah-Hartman , Jiri Slaby , Richard Genoud , Sascha Hauer , Shawn Guo , Tim Harvey , =?utf-8?q?Tomasz_Mo=C5=84?= , linux-arm-kernel@lists.infradead.org, NXP Linux Team , Pengutronix Kernel Team , Sergey Organov Subject: [PATCH 6/8] serial: imx: stop using USR2 in FIFO reading loop Date: Fri, 13 Jan 2023 21:43:32 +0300 Message-Id: <20230113184334.287130-7-sorganov@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230113184334.287130-1-sorganov@gmail.com> References: <87bko4e65y.fsf@osv.gnss.ru> <20230113184334.287130-1-sorganov@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230113_104352_110766_6F10AEFA X-CRM114-Status: GOOD ( 13.11 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The chip provides all the needed bits in the URXD0 register that we read anyway for data, so get rid of reading USR2 and use only URXD0 bits instead. Signed-off-by: Sergey Organov --- drivers/tty/serial/imx.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/drivers/tty/serial/imx.c b/drivers/tty/serial/imx.c index c44a7293c013..be00362b8b67 100644 --- a/drivers/tty/serial/imx.c +++ b/drivers/tty/serial/imx.c @@ -892,27 +892,21 @@ static irqreturn_t __imx_uart_rxint(int irq, void *dev_id) struct tty_port *port = &sport->port.state->port; u32 usr2; - usr2 = imx_uart_readl(sport, USR2); - /* If we received something, check for 0xff flood */ + usr2 = imx_uart_readl(sport, USR2); if (usr2 & USR2_RDR) imx_uart_check_flood(sport, usr2); - for ( ; usr2 & USR2_RDR; usr2 = imx_uart_readl(sport, USR2)) { + while ((rx = imx_uart_readl(sport, URXD0)) & URXD_CHARRDY) { flg = TTY_NORMAL; sport->port.icount.rx++; - rx = imx_uart_readl(sport, URXD0); - - if (usr2 & USR2_BRCD) { - imx_uart_writel(sport, USR2_BRCD, USR2); - if (uart_handle_break(&sport->port)) - continue; - } - if (unlikely(rx & URXD_ERR)) { - if (rx & URXD_BRK) + if (rx & URXD_BRK) { sport->port.icount.brk++; + if (uart_handle_break(&sport->port)) + continue; + } else if (rx & URXD_PRERR) sport->port.icount.parity++; else if (rx & URXD_FRMERR) From patchwork Fri Jan 13 18:43:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Organov X-Patchwork-Id: 13101495 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 A8E93C3DA78 for ; Fri, 13 Jan 2023 18:46:30 +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:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=gsS8zBg8pGBjdIRWTY1E/er4insGlUQ4JkG8WhoVzvA=; b=qrsC2sPc7NZLty fNEeUpia7JmKmywriiWgmZLnyy9iElHCq2cGlPvqbxespXLCg3WmNqYoW0g6yGBybDEQrv40iF/Z7 apMTB6wH156VZv2CbDen2bv4XSBfdDI9QmmHMssgb2UH4tk31IGW+sjU6G0uUiEAZEEEtbAYRe2Gq FksBskCKKzjvq9V2bLMJ9GHoazOLqFtY6JAYmZNTCLCTZrHsqFj5VU1Z5gwylfrq6slqg3h5eDFRT 7oTfrtD9abfBhzOk2brpqCvSwnTEnVFY7Kt+lfj0Xx6IF4z5CGiLQ19fFn2qN2ghjKRAs3U/YTLFC XrPxKoXiy9zerwD84Gkw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pGP3G-0045tD-5y; Fri, 13 Jan 2023 18:45:18 +0000 Received: from mail-lf1-x133.google.com ([2a00:1450:4864:20::133]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pGP1t-0045Jo-GL for linux-arm-kernel@lists.infradead.org; Fri, 13 Jan 2023 18:43:54 +0000 Received: by mail-lf1-x133.google.com with SMTP id j17so34353297lfr.3 for ; Fri, 13 Jan 2023 10:43:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=u4rfVI/XJr5X+KumzfTQcZa08y9SOr59F+VA0vvNt8Y=; b=HiA03k7vO+25XVOg1p3rcNpZ+bitaCG9UPkD8GsVXWwB8igzePAu2VcREZWn5HvjwJ QWqMWKFsk42V1qIx92+u8sF9cje9g6hgZvtMcTi0dqaHY1MWnKp9j7K7Z27u2UDcXjQC jVyzWwj7nh3+fEFxrGWaJInUv3RaPLlxdvjVj2E6zbnkctwxQcoMACOIs/wX5bHxAixG UfXaJ/9F3QUIcjMqtYQew/mcVjC9TY98VYivwNzaBBh6uU/l/U5iyMFrtZBxQIKa6ADq pRQttmB0Kphnf+l240qyAAxXQ4DpGPCuF0Qe5bM1w1NVdkkxQslUapQrGKxtSmc9AJ2t zJWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=u4rfVI/XJr5X+KumzfTQcZa08y9SOr59F+VA0vvNt8Y=; b=ihpQt/rZ9hdNQCzSFYeKe7f7LQH1VkTDMm6t6tmgMcvbEnFAUvj7CxbyJ5m83OrBiT f+GzsmnJbgsAwzqN3tP21SLfjn/xQ5MeMumI2P+uH2Ujrm94P9yyx7QcUj8GyDeLkza6 irSD6I+f3WyDd5gfHJiQSJE6rxfvjKd0dRYiEtxE5Gb4T2y3DRsOhpbuoeHAfTArLWnD TCRbI8rBVqRC5DZwnxGiLl2YSrERj/r9nzgnPsO1MUgxDXevRqVx3pM3NiiV8MpQNZSV Bww2e2RQn9uVi4nyHpfyr/CyHoxZ5w0UDzkTI8bugJIZnmIg5hRU5cKi0c8KCI0stVcI Kihw== X-Gm-Message-State: AFqh2koEhKBcCXuO+SCNTKdjDyUjbRnaJbHnkIIHIYWuAcSGvpnT/1IC 1yVclLGxm5ZqK8IQ6E/wRDE= X-Google-Smtp-Source: AMrXdXsNvkqfT6j8HmsmKrH7FqifRSqm0j/FphLvcrSiVbhnqJHZdakyCGULs2BXzKrIEAyuSm6Ctg== X-Received: by 2002:ac2:484c:0:b0:4a4:68b8:c2b6 with SMTP id 12-20020ac2484c000000b004a468b8c2b6mr252565lfy.13.1673635431051; Fri, 13 Jan 2023 10:43:51 -0800 (PST) Received: from osv.localdomain ([89.175.180.246]) by smtp.gmail.com with ESMTPSA id o11-20020ac2434b000000b004cc9ddce3adsm1261439lfl.82.2023.01.13.10.43.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Jan 2023 10:43:50 -0800 (PST) From: Sergey Organov To: linux-serial@vger.kernel.org Cc: Fabio Estevam , Greg Kroah-Hartman , Jiri Slaby , Richard Genoud , Sascha Hauer , Shawn Guo , Tim Harvey , =?utf-8?q?Tomasz_Mo=C5=84?= , linux-arm-kernel@lists.infradead.org, NXP Linux Team , Pengutronix Kernel Team , Sergey Organov Subject: [PATCH 7/8] serial: imx: use readl() to optimize FIFO reading loop Date: Fri, 13 Jan 2023 21:43:33 +0300 Message-Id: <20230113184334.287130-8-sorganov@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230113184334.287130-1-sorganov@gmail.com> References: <87bko4e65y.fsf@osv.gnss.ru> <20230113184334.287130-1-sorganov@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230113_104353_586435_05E059A0 X-CRM114-Status: GOOD ( 12.64 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Use readl() instead of heavier imx_uart_readl() in the Rx ISR, as we know we read registers that must not be cached. Signed-off-by: Sergey Organov --- drivers/tty/serial/imx.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/tty/serial/imx.c b/drivers/tty/serial/imx.c index be00362b8b67..f4236e8995fa 100644 --- a/drivers/tty/serial/imx.c +++ b/drivers/tty/serial/imx.c @@ -890,14 +890,15 @@ static irqreturn_t __imx_uart_rxint(int irq, void *dev_id) struct imx_port *sport = dev_id; unsigned int rx, flg; struct tty_port *port = &sport->port.state->port; + typeof(sport->port.membase) membase = sport->port.membase; u32 usr2; /* If we received something, check for 0xff flood */ - usr2 = imx_uart_readl(sport, USR2); + usr2 = readl(membase + USR2); if (usr2 & USR2_RDR) imx_uart_check_flood(sport, usr2); - while ((rx = imx_uart_readl(sport, URXD0)) & URXD_CHARRDY) { + while ((rx = readl(membase + URXD0)) & URXD_CHARRDY) { flg = TTY_NORMAL; sport->port.icount.rx++; From patchwork Fri Jan 13 18:43:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Organov X-Patchwork-Id: 13101496 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 C248EC54EBD for ; Fri, 13 Jan 2023 18:47: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:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=vgG+Tt2oNXVdbUqStSnUlRtRC+g6kyLfxExO9pWhYKw=; b=Bb7sggVtF62Ek2 BUKWB40Un1Fsh4kXa9uBDai25KZy1JVqhuGTHybOaMepkX/QlLcAIKJQIfTTatamEUHgaZqfpVFE+ +PdYFoEnULJ/zwB3m7iLVXmLnW3XgrclZVDBv2X27i531R6h3WQRN0Fkw7Rc85+I6bos018ArKG6H +nPWmb2jszdwJHUmhzPAIlacITziROI3m/DEX4QuMHCh4iJMhV1GJScPO/pvKHGS7NQ36z9EmrfQX uYS7U5RFK8fNwSHA5egkJ7DuPGyClAj9wyIRojVYS9xKNAE+weuNc/IboQJNH0DioDdHvQgzTKYzz 0SCQQXK1GBr2oejBbTkA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pGP3z-0046I9-JG; Fri, 13 Jan 2023 18:46:03 +0000 Received: from mail-lf1-x134.google.com ([2a00:1450:4864:20::134]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pGP1t-0045KD-RM for linux-arm-kernel@lists.infradead.org; Fri, 13 Jan 2023 18:43:55 +0000 Received: by mail-lf1-x134.google.com with SMTP id b3so34328409lfv.2 for ; Fri, 13 Jan 2023 10:43:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Yv7yYu+svGwVLgS8wyxzW693EiE4HtsBGRbigAy1MWs=; b=CP0QKj9lJa+BeUqD8mjzJAzZER4o144dB1FKlqUxhlS8kvXAxLI1Zx0PSlEwZxhtpz A1HItOSE1W9IH0lAmNpXNdj5aXi+Jz3NXTWPeqfhJqrykhBMM8HcMPiSM1INLAp0Dksu N+t/ZsVCAiUJmkuv2QdCm+8qC22E0xZg+HB2GCsdIRSpXNlinC16hWmm9gAJrhAlKQxU ay0wMGuX63vB0rXHiNQv230xrMgyLGz+vNUHCRkdUdbH1iO1v6VRAHsVN4G3RJhlpZGe 3Gs8pau5Tq1YiQ+/mYwyg4MfAS0eQd+TupXow1yPoP790TblXOt0ELIH1HOwtbarFusq IbJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Yv7yYu+svGwVLgS8wyxzW693EiE4HtsBGRbigAy1MWs=; b=NjgwUIXrIcIsF0JhtmT+0DLQvyTO+eteHMtAzr0bsu4S34lDortFz9t3HOqUdaHR1M hTHK8ILC8pbq0F7XQyRQkw8+dbXz7VBT5GWCqwZdw4PKIC4qfQyyA+8iN24ra3HNiCFj 44TdZ71UGvA5lbkkRzuu5zXd0QQQXCt73vIDK5ZgjSysu3aUZ47Sb74cXz+ovaKCsZXy zoOXAwmdN9URJfE/5VMjljMdeG+d2GgF8OkAFhg5yMdaYqWE+toT2ohhTKFzcYdeCOJ9 ps5cW8brCfVnpR78ye9DWGuHTzVTbvKdOPUjeRPFfwCdvwmhLdOKPrFzc/B2Qx5JCSwp HfhA== X-Gm-Message-State: AFqh2ko6cN3DCIhvRgoa1GrkhU6ijJ4o25FTHcTEIyQGIwyUNeogW7n1 nYQJFauLSRfaj8ZxJGzSOrQ= X-Google-Smtp-Source: AMrXdXvt1TMVuja3Y+Zq+MhsrzFa4qgMzz0RT70F2OE4C6YFu2bzKAp9gyGVW7pWlLPpu2ApvjCcEA== X-Received: by 2002:a05:6512:1597:b0:4b6:f4bb:e53f with SMTP id bp23-20020a056512159700b004b6f4bbe53fmr26621541lfb.60.1673635432565; Fri, 13 Jan 2023 10:43:52 -0800 (PST) Received: from osv.localdomain ([89.175.180.246]) by smtp.gmail.com with ESMTPSA id o11-20020ac2434b000000b004cc9ddce3adsm1261439lfl.82.2023.01.13.10.43.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Jan 2023 10:43:52 -0800 (PST) From: Sergey Organov To: linux-serial@vger.kernel.org Cc: Fabio Estevam , Greg Kroah-Hartman , Jiri Slaby , Richard Genoud , Sascha Hauer , Shawn Guo , Tim Harvey , =?utf-8?q?Tomasz_Mo=C5=84?= , linux-arm-kernel@lists.infradead.org, NXP Linux Team , Pengutronix Kernel Team , Sergey Organov Subject: [PATCH 8/8] serial: imx: refine local variables in rxint() Date: Fri, 13 Jan 2023 21:43:34 +0300 Message-Id: <20230113184334.287130-9-sorganov@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230113184334.287130-1-sorganov@gmail.com> References: <87bko4e65y.fsf@osv.gnss.ru> <20230113184334.287130-1-sorganov@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230113_104353_947451_499DFA6D X-CRM114-Status: GOOD ( 12.97 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The 'rx' is chip register, similar to 'usr2', so let it be of 'u32' type as well. Move 'flg' to be FIFO read loop local as it's not used outside. Signed-off-by: Sergey Organov --- drivers/tty/serial/imx.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/tty/serial/imx.c b/drivers/tty/serial/imx.c index f4236e8995fa..45327ff6dd14 100644 --- a/drivers/tty/serial/imx.c +++ b/drivers/tty/serial/imx.c @@ -888,10 +888,9 @@ static void imx_uart_check_flood(struct imx_port *sport, u32 usr2) static irqreturn_t __imx_uart_rxint(int irq, void *dev_id) { struct imx_port *sport = dev_id; - unsigned int rx, flg; struct tty_port *port = &sport->port.state->port; typeof(sport->port.membase) membase = sport->port.membase; - u32 usr2; + u32 usr2, rx; /* If we received something, check for 0xff flood */ usr2 = readl(membase + USR2); @@ -899,7 +898,7 @@ static irqreturn_t __imx_uart_rxint(int irq, void *dev_id) imx_uart_check_flood(sport, usr2); while ((rx = readl(membase + URXD0)) & URXD_CHARRDY) { - flg = TTY_NORMAL; + unsigned int flg = TTY_NORMAL; sport->port.icount.rx++; if (unlikely(rx & URXD_ERR)) {