From patchwork Fri Dec 2 12:35:11 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geert Uytterhoeven X-Patchwork-Id: 9458341 X-Patchwork-Delegate: horms@verge.net.au Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 038DF60585 for ; Fri, 2 Dec 2016 12:35:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E9C192852A for ; Fri, 2 Dec 2016 12:35:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DE5852853D; Fri, 2 Dec 2016 12:35:20 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AD2F32852A for ; Fri, 2 Dec 2016 12:35:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759948AbcLBMfS (ORCPT ); Fri, 2 Dec 2016 07:35:18 -0500 Received: from laurent.telenet-ops.be ([195.130.137.89]:47928 "EHLO laurent.telenet-ops.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757570AbcLBMfR (ORCPT ); Fri, 2 Dec 2016 07:35:17 -0500 Received: from ayla.of.borg ([84.193.137.253]) by laurent.telenet-ops.be with bizsmtp id F0bD1u00T5UCtCs010bDUB; Fri, 02 Dec 2016 13:35:16 +0100 Received: from ramsan.of.borg ([192.168.97.29] helo=ramsan) by ayla.of.borg with esmtp (Exim 4.82) (envelope-from ) id 1cCn3Z-0005JS-M4; Fri, 02 Dec 2016 13:35:13 +0100 Received: from geert by ramsan with local (Exim 4.82) (envelope-from ) id 1cCn3d-0002Ql-FB; Fri, 02 Dec 2016 13:35:17 +0100 From: Geert Uytterhoeven To: Greg Kroah-Hartman , Jiri Slaby Cc: Yoshihiro Shimoda , Wolfram Sang , Christoph Baumann , linux-serial@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-kernel@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH 2/2] serial: sh-sci: Fix hang in sci_reset() Date: Fri, 2 Dec 2016 13:35:11 +0100 Message-Id: <1480682111-9299-3-git-send-email-geert+renesas@glider.be> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1480682111-9299-1-git-send-email-geert+renesas@glider.be> References: <1480682111-9299-1-git-send-email-geert+renesas@glider.be> Sender: linux-renesas-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When the .set_termios() callback resets the UART, it first waits until all characters in the transmit FIFO have been transmitted, to prevent a port configuration change from impacting these characters. However, if the previous user of the UART had dedicated RTS/CTS hardware flow control enabled, these characters may have been stuck in the FIFO due to CTS not being asserted. When the new user opens the port, .set_termios() is called while transmission is still disabled, leading to an infinite loop: NMI watchdog: BUG: soft lockup - CPU#0 stuck for 22s! This has been observed with SCIFA (on r8a7740/armadillo) and SCIFB (on r8a7791/koelsch). The issue does not seem to happen when using: - GPIO RTS/CTS hardware flow control, - No hardware flow control, - HSCIF (on r8a7791/koelsch). To fix this, wait for the draining of the transmit FIFO only if transmission is already enabled. Signed-off-by: Geert Uytterhoeven --- To reproduce: stty -echo < /dev/scifb0 stty crtscts < /dev/scifb0 echo hello > /dev/scifb0 # returns early (wrote to FIFO) echo hello > /dev/scifb0 # hangs drivers/tty/serial/sh-sci.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c index c503db1900f003ed..db5de80c5399a7bd 100644 --- a/drivers/tty/serial/sh-sci.c +++ b/drivers/tty/serial/sh-sci.c @@ -2137,9 +2137,11 @@ static void sci_reset(struct uart_port *port) const struct plat_sci_reg *reg; unsigned int status; - do { - status = serial_port_in(port, SCxSR); - } while (!(status & SCxSR_TEND(port))); + if (serial_port_in(port, SCSCR) & SCSCR_TE) { + do { + status = serial_port_in(port, SCxSR); + } while (!(status & SCxSR_TEND(port))); + } serial_port_out(port, SCSCR, 0x00); /* TE=0, RE=0, CKE1=0 */