From patchwork Wed Oct 4 11:44:31 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Awais Masood X-Patchwork-Id: 9984389 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 8176C60237 for ; Wed, 4 Oct 2017 11:47:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7009328ADD for ; Wed, 4 Oct 2017 11:47:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 64E9628ADF; Wed, 4 Oct 2017 11:47:36 +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=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id B361528ADD for ; Wed, 4 Oct 2017 11:47:35 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dzi6q-0001Tp-Lr; Wed, 04 Oct 2017 11:45:04 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dzi6p-0001Tj-Jw for xen-devel@lists.xenproject.org; Wed, 04 Oct 2017 11:45:03 +0000 Received: from [85.158.139.211] by server-3.bemta-5.messagelabs.com id 90/98-30688-EB9C4D95; Wed, 04 Oct 2017 11:45:02 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrOIsWRWlGSWpSXmKPExsVyMbRhpe6+k1c iDWa+47X4vmUykwOjx+EPV1gCGKNYM/OS8isSWDPer5rHUvBBsWLfn58sDYxPpboYuTiEBGYw Six7eJAdxGERaGSVmPa6haWLkZNDQqCfVWLqCy0IO0viXctEqHiaxNZNc5gg7CqJzu2r2EFsI QENiRNNz1khpv5mlFi5dwUrSIJNQEdi3v4njCC2iICSxL1Vk5lAipgFXjFJvHl1na2LkYNDWM BRYuPWNJAaFgFVidnXOsGW8Qq4S6zc9IsVYpmcxM1zncwgNqeAh8TC3oNMIK1CQDV39khOYBR cwMiwilGjOLWoLLVI19BAL6koMz2jJDcxMwfIM9XLTS0uTkxPzUlMKtZLzs/dxAgMOAYg2MG4 ZqrzIUZJDiYlUd7qQ1cihfiS8lMqMxKLM+KLSnNSiw8xynBwKEnw3jkBlBMsSk1PrUjLzAGGP kxagoNHSYS3EBj+QrzFBYm5xZnpEKlTjJYcF+5c+sPEcWDPLSDZcfPuHyYhlrz8vFQpcd4vIP MEQBoySvPgxsHi8xKjrJQwLyPQgUI8BalFuZklqPKvGMU5GJWEef+BTOHJzCuB2/oK6CAmoIP mNIEdVJKIkJJqYKwS6GCdk/1lZ1eZ8rM/265stb8mcP6ThcZJw3vfvul2mIYy+gkwm4VLihyY sz6bw0DX4l3GP58/eiyLG22TLI+FzOhf2vZvW+PhCxsmmHbcXOjjyjVVrWqSAf9jv3Prz3Tbf ZTsMH8Ufv/M3AxFvgsxi9SVfzho8z77pqTkv+dqiG7PitnLXymxFGckGmoxFxUnAgB99QUkyg IAAA== X-Env-Sender: awais.masood@softrove.com X-Msg-Ref: server-12.tower-206.messagelabs.com!1507117502!78243634!1 X-Originating-IP: [209.85.128.169] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.4.45; banners=-,-,- X-VirusChecked: Checked Received: (qmail 42104 invoked from network); 4 Oct 2017 11:45:02 -0000 Received: from mail-wr0-f169.google.com (HELO mail-wr0-f169.google.com) (209.85.128.169) by server-12.tower-206.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 4 Oct 2017 11:45:02 -0000 Received: by mail-wr0-f169.google.com with SMTP id y44so735883wry.10 for ; Wed, 04 Oct 2017 04:45:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vadion-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=YTKUk2mYwqMXiK78m7+s/AIk6E8OJYrzTKk3TYRz9o4=; b=Da80EDBVzsnJiKsp//9LHqaSKABhJWyKDvz05AvRDFiLIkRuhvlkHhhZZpDJEIimda MYzqzQngMjCBxn+U1FcM9zYhMbn3xFMjJQMo5iPvrl7dbrwdvMVzk7DgPNpEz8Hz37Ad VuBJ8evUE3HhHWQasepQkEpsSML+c89nV6CsxYh1uwI3oISc7W48mR7yB8XxwWrWqIjb 6laMqQVIS+no1wrzhBG3bPmT59+w1oTo5alRcuCglbxnMjaaJKT+fd6rR3VHvhI3wUxd nhnocxzRRcfhsXQckA4/u3PkCLNlDoMULo2oXayx2DJFvHPhrGb7NxLO0clAvt+0ZWjf E22g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=YTKUk2mYwqMXiK78m7+s/AIk6E8OJYrzTKk3TYRz9o4=; b=Ky1PO6Qi2s4oyHcC5ux4zk0MpFnNSbhSepjKWzWW6O/h2ZpJ7a8ANXq510JcOQAwYO rSfEthOO6qAZVefuKykGehEVBpbwXyK6VeWQzeXOQpu+1wVHr0X6gRcHRrAMBiAjzi6l H+vJ2EzkXKnGM/PLqLwZYzmZ8xYBEJSETHO84exNe4O3uoyaeqYMsk6UXOoOI0bQ+UjI u6z+GnVigprYf4SB3it0+9nFgHlD+lOX1CMnxcJpVImPmpz7dNMfa0VXurdp9vnhOYtS BXyU5Wjv4FhYq8N/d4OG8bg8fSuIfF2zJq5qlrhw+X4OiXwaAv54t7xfjjLfPSjj9UJh 3Taw== X-Gm-Message-State: AMCzsaU6ny86z2NtMZZmnzH0kEON8gtw5Ai8JHMMWvnP78LaTW018dRr cVJQgtqUtTcuCsFtnMrxMXxsDG9Q X-Google-Smtp-Source: AOwi7QBQXu3++difKj6QUe/lx1mYxNlAgdGSlMbfd7NTejO5ReVkSUxdditKgq1bxGsP6cF6p7QxMw== X-Received: by 10.223.154.70 with SMTP id z64mr6549079wrb.220.1507117501530; Wed, 04 Oct 2017 04:45:01 -0700 (PDT) Received: from localhost.localdomain ([182.185.135.166]) by smtp.gmail.com with ESMTPSA id b72sm10830423wmf.30.2017.10.04.04.44.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 04 Oct 2017 04:45:00 -0700 (PDT) From: Awais Masood To: xen-devel@lists.xenproject.org Date: Wed, 4 Oct 2017 16:44:31 +0500 Message-Id: <1507117471-12389-1-git-send-email-awais.masood@vadion.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1506418634-20366-1-git-send-email-awais.masood@vadion.com> References: <1506418634-20366-1-git-send-email-awais.masood@vadion.com> Cc: Stefano Stabellini , Wei Liu , Konrad Rzeszutek Wilk , George Dunlap , Andrew Cooper , Awais Masood , Ian Jackson , Tim Deegan , Jan Beulich Subject: [Xen-devel] [PATCH v3] xen/ns16550: Fix ISR lockup on Allwinner uart X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP This patch fixes an ISR lockup seen on Allwinner uart On Allwinner H5, serial driver goes into an infinite loop when interrupts are enabled. The reason is a residual "busy detect" interrupt. Since the condition UART_IIR_NOINT will not be true unless this interrupt is cleared, the interrupt handler will remain locked up in this while loop. A HW quirk fix was previously added for designware uart under commit: 50417cd978aa54930d065ac1f139f935d14af76d It checks for a busy condition during setup and clears the condition by reading UART_USR register. On Allwinner hardware, the "busy detect" condition occurs later because an LCR write is performed during setup 'after' this clear and if uart is busy, the "busy detect" condition will trigger again and cause the ISR lockup. To solve this problem, the same UART_USR read operation needs to be performed within the interrupt handler to clear this condition. Linux dw 8250 driver also handles this condition within interrupt handler http://elixir.free-electrons.com/linux/latest/source/drivers/tty/serial/8250/8250_dw.c#L233 Tested on Orange Pi PC2 (H5). This issue is seen on H3 as well and the same fix works. Signed-off-by: Awais Masood Acked-by: Jan Beulich Acked-by: Stefano Stabellini --- CC: Andrew Cooper CC: George Dunlap CC: Ian Jackson CC: Jan Beulich CC: Konrad Rzeszutek Wilk CC: Stefano Stabellini CC: Tim Deegan CC: Wei Liu Changes since v2 - Updated comments to clarify that fix is for Allwinner hardware - Removed ns16550 prefix from local function Changes since v1 - Common quirk fix code moved to a helper function - Patch description improved with earlier commit link --- xen/drivers/char/ns16550.c | 38 +++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/xen/drivers/char/ns16550.c b/xen/drivers/char/ns16550.c index 6ab5ec3..e0f8199 100644 --- a/xen/drivers/char/ns16550.c +++ b/xen/drivers/char/ns16550.c @@ -505,6 +505,23 @@ static int ns16550_ioport_invalid(struct ns16550 *uart) return ns_read_reg(uart, UART_IER) == 0xff; } +static void handle_dw_usr_busy_quirk(struct ns16550 *uart) +{ + if ( uart->dw_usr_bsy && + (ns_read_reg(uart, UART_IIR) & UART_IIR_BSY) == UART_IIR_BSY ) + { + /* DesignWare 8250 detects if LCR is written while the UART is + * busy and raises a "busy detect" interrupt. Read the UART + * Status Register to clear this state. + * + * Allwinner/sunxi UART hardware is similar to DesignWare 8250 + * and also contains a "busy detect" interrupt. So this quirk + * fix will also be used for Allwinner UART. + */ + ns_read_reg(uart, UART_USR); + } +} + static void ns16550_interrupt( int irq, void *dev_id, struct cpu_user_regs *regs) { @@ -521,6 +538,16 @@ static void ns16550_interrupt( serial_tx_interrupt(port, regs); if ( lsr & UART_LSR_DR ) serial_rx_interrupt(port, regs); + + /* A "busy-detect" condition is observed on Allwinner/sunxi UART + * after LCR is written during setup. It needs to be cleared at + * this point or UART_IIR_NOINT will never be set and this loop + * will continue forever. + * + * This state can be cleared by calling the dw_usr_busy quirk + * handler that resolves "busy-detect" for DesignWare uart. + */ + handle_dw_usr_busy_quirk(uart); } } @@ -623,15 +650,8 @@ static void ns16550_setup_preirq(struct ns16550 *uart) /* No interrupts. */ ns_write_reg(uart, UART_IER, 0); - if ( uart->dw_usr_bsy && - (ns_read_reg(uart, UART_IIR) & UART_IIR_BSY) == UART_IIR_BSY ) - { - /* DesignWare 8250 detects if LCR is written while the UART is - * busy and raises a "busy detect" interrupt. Read the UART - * Status Register to clear this state. - */ - ns_read_reg(uart, UART_USR); - } + /* Handle the DesignWare 8250 'busy-detect' quirk. */ + handle_dw_usr_busy_quirk(uart); /* Line control and baud-rate generator. */ ns_write_reg(uart, UART_LCR, lcr | UART_LCR_DLAB);