From patchwork Thu Feb 13 15:20:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 231399 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 36CD0C3B189 for ; Thu, 13 Feb 2020 15:49:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0C4D520661 for ; Thu, 13 Feb 2020 15:49:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1581608982; bh=wHGaMKgffCtYSsTxzAw+uNAjQmYOFbcSC4KShEuTDTo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=vfzAUuZZncbVS0Ae7JvQEQRYZLerfQ2tF+z+EMGf4Si3lcsaU0Q9dSF5GOS/liG8p mqq/irOunM68tGNnSMo+/5G6Cu0fYV0GCmBk5M8FHixvewAGbNqMtfRlqb+2PtMFXh rlFVbDgWIeS4XEunL0ccBYjgmakwhsXMsl0MSeSw= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728618AbgBMPtk (ORCPT ); Thu, 13 Feb 2020 10:49:40 -0500 Received: from mail.kernel.org ([198.145.29.99]:46478 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387620AbgBMP0j (ORCPT ); Thu, 13 Feb 2020 10:26:39 -0500 Received: from localhost (unknown [104.132.1.104]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 53A9824693; Thu, 13 Feb 2020 15:26:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1581607598; bh=wHGaMKgffCtYSsTxzAw+uNAjQmYOFbcSC4KShEuTDTo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=p9ED0yITl+Z3mr72eF3gUqmakeUZzqUHFsXF32cfDpJrXnb3Wdz3f1Bi/fOUYtRzU k8vs9AfRPgKgAHfJ0ule4nQ62YIOu7oFknnzB0is6NYS+o56biAx1RzO66/w6bjx5K MDrVi23W6eoAJWHNDG8r0cXPHF2mIhZwq1g8ZJYE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jean-Francois Dagenais , Shubhrajyoti Datta , Mathieu Poirier , Sasha Levin Subject: [PATCH 4.19 16/52] serial: uartps: Add a timeout to the tx empty wait Date: Thu, 13 Feb 2020 07:20:57 -0800 Message-Id: <20200213151817.584286846@linuxfoundation.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200213151810.331796857@linuxfoundation.org> References: <20200213151810.331796857@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Shubhrajyoti Datta commit 277375b864e8147975b064b513f491e2a910e66a upstream In case the cable is not connected then the target gets into an infinite wait for tx empty. Add a timeout to the tx empty wait. Reported-by: Jean-Francois Dagenais Signed-off-by: Shubhrajyoti Datta Signed-off-by: Greg Kroah-Hartman Cc: stable # 4.19 Signed-off-by: Mathieu Poirier Signed-off-by: Sasha Levin --- drivers/tty/serial/xilinx_uartps.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/drivers/tty/serial/xilinx_uartps.c b/drivers/tty/serial/xilinx_uartps.c index 66d49d5118853..7cbee19ea93d5 100644 --- a/drivers/tty/serial/xilinx_uartps.c +++ b/drivers/tty/serial/xilinx_uartps.c @@ -26,6 +26,7 @@ #include #include #include +#include #define CDNS_UART_TTY_NAME "ttyPS" #define CDNS_UART_NAME "xuartps" @@ -34,6 +35,7 @@ #define CDNS_UART_NR_PORTS 2 #define CDNS_UART_FIFO_SIZE 64 /* FIFO size */ #define CDNS_UART_REGISTER_SPACE 0x1000 +#define TX_TIMEOUT 500000 /* Rx Trigger level */ static int rx_trigger_level = 56; @@ -681,16 +683,20 @@ static void cdns_uart_set_termios(struct uart_port *port, unsigned int cval = 0; unsigned int baud, minbaud, maxbaud; unsigned long flags; - unsigned int ctrl_reg, mode_reg; + unsigned int ctrl_reg, mode_reg, val; + int err; spin_lock_irqsave(&port->lock, flags); /* Wait for the transmit FIFO to empty before making changes */ if (!(readl(port->membase + CDNS_UART_CR) & CDNS_UART_CR_TX_DIS)) { - while (!(readl(port->membase + CDNS_UART_SR) & - CDNS_UART_SR_TXEMPTY)) { - cpu_relax(); + err = readl_poll_timeout(port->membase + CDNS_UART_SR, + val, (val & CDNS_UART_SR_TXEMPTY), + 1000, TX_TIMEOUT); + if (err) { + dev_err(port->dev, "timed out waiting for tx empty"); + return; } }