From patchwork Fri Apr 27 10:05:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Martin X-Patchwork-Id: 134569 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp522869lji; Fri, 27 Apr 2018 03:05:54 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpNJt0SCyEjVchDk6j381GDMsOoUMCIm6pFty+kbPNLnZoVmah+9E6Qy5xp6XgWVho4oJyz X-Received: by 10.98.232.1 with SMTP id c1mr1641407pfi.184.1524823554116; Fri, 27 Apr 2018 03:05:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524823554; cv=none; d=google.com; s=arc-20160816; b=uHUs9C2XcLwJHOXvcZz5UQi2EG9vonBqqY008HIQHii6U2oUq/jOqw5j4sqIK9NfY3 WSXtZZKeFltu7gT+KJuiVhL5i2utqvPLsQO/8O18xSfvAD+HFIKFUs/wAhJ9FVNIETLj doLAUYUFZLv3zmi5PkMdZ410GX/oEQKxM0iw8TI5xVIXqNR1divJA7+Eu9f+Wp/RNH0b JlNPQxzVFHvRZ5ex9Hla9qcRHfawJg1Sy2IMMP6xEe1QqVB/if1+dAxBPN4OSj/bR3Fb dw/SdX/242z5OaKMxwwDw9OdH+1jvcL/TYZKFjmeETzyZqdTWHS5u5slz0dvQlNirO3k nGIw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=KvxD3aNf6MCn5OOLiQtx88o+wFDIQ9fpLh4ZNXQLzl4=; b=N7abWZoTj3bGJ5BnJ7nEu1cKgtOOl04zBZZNmarjbQ7fT7vbMt2WvcHpCVnCdvnel0 rR2z62kg4S50Q+4M29DD//hli6IKbO91qJ0BJXSdlHmPWNn9qJr1ZF9VAPp0J/LjbA16 VrMTPNVjiA8LRFtdVBg35zUwy/0nUaOPoqoRs2Db5+t9aWB7/7oRseUg2/t6f13Tvu8V SATbgiRWujX90KZdzHjvtywQ8Wt/Wow/3CS75McVgdkjZ7Jp2PDByGzn/Sob7bTqZqIi TX616tiDAdllad+FIzS6HkHvyTcd37qY7eJ+bKfTK5Znutjuwl9/PLLYyvfURgROlKef /4+Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-serial-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-serial-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b25-v6si962637pgf.146.2018.04.27.03.05.53; Fri, 27 Apr 2018 03:05:54 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-serial-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-serial-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-serial-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932415AbeD0KFx (ORCPT + 2 others); Fri, 27 Apr 2018 06:05:53 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:37824 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757657AbeD0KFw (ORCPT ); Fri, 27 Apr 2018 06:05:52 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 8FB87165D; Fri, 27 Apr 2018 03:05:52 -0700 (PDT) Received: from e103592.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 3B0983F487; Fri, 27 Apr 2018 03:05:51 -0700 (PDT) From: Dave Martin To: linux-arm-kernel@lists.infradead.org Cc: linux-serial@vger.kernel.org, Russell King , Linus Walleij , Peter Maydell , Wei Xu , Andrew Jones , Ciro Santilli Subject: [PATCH] tty: pl011: Avoid spuriously stuck-off interrupts Date: Fri, 27 Apr 2018 11:05:45 +0100 Message-Id: <1524823545-11309-2-git-send-email-Dave.Martin@arm.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1524823545-11309-1-git-send-email-Dave.Martin@arm.com> References: <1524823545-11309-1-git-send-email-Dave.Martin@arm.com> Sender: linux-serial-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org Commit 9b96fbacda34 ("serial: PL011: clear pending interrupts") clears the RX and receive timeout interrupts on pl011 startup, to avoid a screaming-interrupt scenario that can occur when the firmware or bootloader leaves these interrupts asserted. This has been noted as an issue when running Linux on qemu [1]. Unfortunately, the above fix seems to lead to potential misbehaviour if the RX FIFO interrupt is asserted _non_ spuriously on driver startup, if the RX FIFO is also already full to the trigger level. Clearing the RX FIFO interrupt does not change the FIFO fill level. In this scenario, because the interrupt is now clear and because the FIFO is already full to the trigger level, no new assertion of the RX FIFO interrupt can occur unless the FIFO is drained back below the trigger level. This never occurs because the pl011 driver is waiting for an RX FIFO interrupt to tell it that there is something to read, and does not read the FIFO at all until that interrupt occurs. Thus, simply clearing "spurious" interrupts on startup may be misguided, since there is no way to be sure that the interrupts are truly spurious, and things can go wrong if they are not. This patch instead clears the interrupt condition by draining the RX FIFO during UART startup, after clearing any potentially spurious interrupt. This should ensure that an interrupt will definitely be asserted if the RX FIFO subsequently becomes sufficiently full. The drain is done at the point of enabling interrupts only. This means that it will occur any time the UART is newly opened through the tty layer. It will not apply to polled-mode use of the UART by kgdboc: since that scenario cannot use interrupts by design, this should not matter. kgdboc will interact badly with "normal" use of the UART in any case: this patch makes no attempt to paper over such issues. This patch does not attempt to address the case where the RX FIFO fills faster than it can be drained: that is a pathological hardware design problem that is beyond the scope of the driver to work around. [1] [Qemu-devel] [Qemu-arm] [PATCH] pl011: do not put into fifo before enabled the interruption https://lists.gnu.org/archive/html/qemu-devel/2018-01/msg06446.html Reported-by: Wei Xu Cc: Russell King Cc: Linus Walleij Cc: Peter Maydell Fixes: 9b96fbacda34 ("serial: PL011: clear pending interrupts") Signed-off-by: Dave Martin Tested-by: Andrew Jones Reviewed-by: Andrew Jones --- drivers/tty/serial/amba-pl011.c | 10 ++++++++++ 1 file changed, 10 insertions(+) -- 2.1.4 -- To unsubscribe from this list: send the line "unsubscribe linux-serial" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/tty/serial/amba-pl011.c b/drivers/tty/serial/amba-pl011.c index 4b40a5b..a6ccb85 100644 --- a/drivers/tty/serial/amba-pl011.c +++ b/drivers/tty/serial/amba-pl011.c @@ -1731,6 +1731,16 @@ static void pl011_enable_interrupts(struct uart_amba_port *uap) /* Clear out any spuriously appearing RX interrupts */ pl011_write(UART011_RTIS | UART011_RXIS, uap, REG_ICR); + + /* + * RXIS is asserted only when the RX FIFO transitions from below + * to above the trigger threshold. If the RX FIFO is already + * full to the threshold this can't happen and RXIS will now be + * stuck off. Drain the RX FIFO explicitly to fix this: + */ + while (!(pl011_read(uap, REG_FR) & UART01x_FR_RXFE)) + pl011_read(uap, REG_DR); + uap->im = UART011_RTIM; if (!pl011_dma_rx_running(uap)) uap->im |= UART011_RXIM;