From patchwork Fri Apr 8 23:35:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 559133 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8D213C433EF for ; Fri, 8 Apr 2022 23:36:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234092AbiDHXiN (ORCPT ); Fri, 8 Apr 2022 19:38:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56600 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230403AbiDHXiN (ORCPT ); Fri, 8 Apr 2022 19:38:13 -0400 Received: from mout.gmx.net (mout.gmx.net [212.227.17.22]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E53CAC6B4E; Fri, 8 Apr 2022 16:36:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1649460959; bh=PE93BArNOfspKWatWSSijWYxkhAMOPY4ZFX7FNX7uHQ=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date; b=DVOU7uZJ0aWbIf5Fdt57sirk94Etp+kJguemPm2oQJnkiKn/VHl2zI/F9zSXe9/jX w/WXaVwglLyCAaA6DqNdoGLqN5YQLP65MqT/C5W1zkM6KIrDRUAzHliNRpVewyjY+7 L2mZVKdts8qS8If7E/6aLPczbwL18wbWLvt41o8w= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from Venus.fritz.box ([46.223.2.213]) by mail.gmx.net (mrgmx105 [212.227.17.168]) with ESMTPSA (Nemesis) id 1MdebB-1oCIxi15hB-00ZcVv; Sat, 09 Apr 2022 01:35:59 +0200 From: Lino Sanfilippo To: gregkh@linuxfoundation.org Cc: linux@armlinux.org.uk, jirislaby@kernel.org, linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, p.rosenberger@kunbus.com, lukas@wunner.de, Lino Sanfilippo , stable@vger.kernel.org Subject: [PATCH] serial: amba-pl011: do not time out prematurely when draining tx fifo Date: Sat, 9 Apr 2022 01:35:02 +0200 Message-Id: <20220408233503.7251-1-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 X-Provags-ID: V03:K1:2Pi391PVpa6mz3HDqrEJVvoWX3RP/HWxrw14lQr48Wx7DltIAtf 8FWeQrDo3ShvEexNvnNKwtwOrEBi8gnsakCStv2bg1751YJF/pJRO+1WCdm1aIRMWYNAOcI 4MqcCvYZHrIKZWYP0tAyQnBDHwTPv0KwBOajHxojwOiBbNn1woVMA2Hz+RPvSBMBX53tzEY rUtDV0HYRY7e9zGN9mPYA== X-UI-Out-Filterresults: notjunk:1;V03:K0:1WIr7NdhmBo=:qrqZHMQgybDqyVMSBON3kN S0woaUywjvcNPEqa9b9/3SuSNqJgJku17bjnEdvGX2gFeyGshXwCzf2w3XjyKtdBuaJHVSPpw j9HTm2UtR0qqriWGJ96W5j2NKXdSa3p+6R9W4o98okDPGs4npj5JKbJGTQ0k3Etf50r5IeueL ADcZIgnissMobyr8nQgfOF+JdPJesYS7ZhUFPQKbH2d59fkYrhzlrOmJ81pSDat7KgIEF5Ueq V1/DXS8HSf7nlNv6tN9azg6sSuGKOSlE41X47gyHt7tv+gby5xuSfGtU5HMglEy6h/qpDAXu/ rWqreuoLq1OB6Zz3y4MDe/LUK6a9n58T8zjmR+lO5D/DWvslM02bvkkD84nvZPsJVaktTn+fV SlBlBbMTzlA/kWH2u3mV6Zz/wkzfOjQsvATdeJn1hmNLSetksJvaKMw6ASL2FD0qBfVP/J5XU 2f9HdCPE4ik8KXhIAMqq20K/OjBv+AVUA3G+8EpFGsWPYQmYQonK+HNzL6r958k6MMpavt++A Ygn3LXN8ir3OcqQdR9Nn4FACi4wcbabctA/GDQRvH4KQEu0L5uEllZP0+3LxMtL+fIJL2Ql1O AJQJQ2rx3dB81I1sdrECC1Sa4n+RyUVwG7MIcb6n2E3BhhbTfVAXWBXub2/+E90ENqk1vvSzZ OBrWHB0wscwp51HR8wGPB3hKznZcxcisj2vzbxus/cm1zvSImc4NGJAtUY5ie//0KIqgPIrx6 qvch+791bduXYUxRt1IsfmA5tZriDO+BjgNOzemegPnNlvcvLwtVm3z9jlyr0+D+KrjSotgS4 kpLIOP9JRFwDaYCCnMm6yRqoNzt4oq0gTOAOQBjI6V9CsS7Z5H/9CKvoYO2cWRWbICi0Dwkyu wYF6unvYD4i2mSGavB+2wZm6LpSBEe6B1FhxSblTowCyuoBTj1f5j9bkhwShw5bfLIgMvnsZU Owf6d5tpXClOiwgmDSRl6viFMttoYcLbkffFsayHtrh4f9vng7vPTJ+Rgsi+m8rLqF3NW9OEQ 2HVHWEO+PzkQGt17QvxXUwbQtAK2k8VgN/LJKMU9SDCUQB9gN4SLIgmkk5ltT+EYlrIENg4AM MSoONKNBbSiWRE= Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org The current timeout for draining the tx fifo in RS485 mode is calculated by multiplying the time it takes to transmit one character (with the given baud rate) with the maximal number of characters in the tx queue. This timeout is too short for two reasons: First when calculating the time to transmit one character integer division is used which may round down the result in case of a remainder of the division. Fix this by rounding up the division result. Second the hardware may need additional time (e.g for first putting the characters from the fifo into the shift register) before the characters are actually put onto the wire. To be on the safe side double the current maximum number of iterations that are used to wait for the queue draining. Fixes: 8d479237727c ("serial: amba-pl011: add RS485 support") Cc: stable@vger.kernel.org Signed-off-by: Lino Sanfilippo --- drivers/tty/serial/amba-pl011.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) base-commit: 1a3b1bba7c7a5eb8a11513cf88427cb9d77bc60a diff --git a/drivers/tty/serial/amba-pl011.c b/drivers/tty/serial/amba-pl011.c index 51ecb050ae40..4d11a3e547f9 100644 --- a/drivers/tty/serial/amba-pl011.c +++ b/drivers/tty/serial/amba-pl011.c @@ -1255,13 +1255,18 @@ static inline bool pl011_dma_rx_running(struct uart_amba_port *uap) static void pl011_rs485_tx_stop(struct uart_amba_port *uap) { + /* + * To be on the safe side only time out after twice as many iterations + * as fifo size. + */ + const int MAX_TX_DRAIN_ITERS = uap->port.fifosize * 2; struct uart_port *port = &uap->port; int i = 0; u32 cr; /* Wait until hardware tx queue is empty */ while (!pl011_tx_empty(port)) { - if (i == port->fifosize) { + if (i > MAX_TX_DRAIN_ITERS) { dev_warn(port->dev, "timeout while draining hardware tx queue\n"); break; @@ -2052,7 +2057,7 @@ pl011_set_termios(struct uart_port *port, struct ktermios *termios, * with the given baud rate. We use this as the poll interval when we * wait for the tx queue to empty. */ - uap->rs485_tx_drain_interval = (bits * 1000 * 1000) / baud; + uap->rs485_tx_drain_interval = DIV_ROUND_UP(bits * 1000 * 1000, baud); pl011_setup_status_masks(port, termios);