From patchwork Tue Jul 19 07:43:03 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bhuvanchandra DV X-Patchwork-Id: 9236237 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 6CECF6075D for ; Tue, 19 Jul 2016 07:47:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5F5992015F for ; Tue, 19 Jul 2016 07:47:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 538382074F; Tue, 19 Jul 2016 07:47:06 +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=BAD_ENC_HEADER,BAYES_00, DKIM_SIGNED, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 005442015F for ; Tue, 19 Jul 2016 07:47:04 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1bPPiJ-0006hC-Rx; Tue, 19 Jul 2016 07:45:11 +0000 Received: from mail-ve1eur01on0138.outbound.protection.outlook.com ([104.47.1.138] helo=EUR01-VE1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bPPi2-0006IE-Aq for linux-arm-kernel@lists.infradead.org; Tue, 19 Jul 2016 07:44:55 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toradex.onmicrosoft.com; s=selector1-toradex-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=LawayEW1/5FSLmtmQYrMaIG3ofyZvUsvfUctKVUQH2w=; b=Ws+2avckn3CQ+fyz+UkSYjqgFDviczQoOSRQdt88VN5zqu9WiwCsFVZPB8z3iF3TfWp25ehud7eNNxTxcghuyKA62BXz+z3p22q6EPvShLKjJ+NeUMGXmQgHZ45eQorrnQQ4822z7sKJrS2XyFNcF89UbPIRbVC4qorXeWpKr6M= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=bhuvanchandra.dv@toradex.com; Received: from tdx-in-nb-0014.toradex.ext (115.115.243.34) by DB6PR0501MB2087.eurprd05.prod.outlook.com (10.168.9.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.544.10; Tue, 19 Jul 2016 07:44:35 +0000 From: Bhuvanchandra DV To: Subject: [PATCH RESEND v2 1/8] tty: serial: fsl_lpuart: consider TX FIFO too in tx_empty Date: Tue, 19 Jul 2016 13:13:03 +0530 Message-ID: <20160719074310.16872-2-bhuvanchandra.dv@toradex.com> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20160719074310.16872-1-bhuvanchandra.dv@toradex.com> References: <20160719074310.16872-1-bhuvanchandra.dv@toradex.com> MIME-Version: 1.0 X-Originating-IP: [115.115.243.34] X-ClientProxiedBy: MA1PR01CA0045.INDPRD01.PROD.OUTLOOK.COM (10.164.116.145) To DB6PR0501MB2087.eurprd05.prod.outlook.com (10.168.9.139) X-MS-Office365-Filtering-Correlation-Id: 3e5a7324-a469-4ef2-0198-08d3afa88950 X-Microsoft-Exchange-Diagnostics: 1; DB6PR0501MB2087; 2:0ma7A/UGT5E59mopAs4QX1RIP+/XqjoqAcnna025jmTnQcBrSvxGlcr4/T+E4r8W28ECVpiTRkQCT26wV9cXVvb7wT1G10z50eUyu1ZN62XdH8bG9pzSnoy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d8zQUIZB6hbidAD1usBIKpfs5Jll3SmCBFaROwi3KRfNToJgKDzyQC9DeDEMZwuvHmWwgBJVygHWPzzm/VZ7pN+Cr/3XdHz9Jon38mc6+yisNLj9QnUEz5fmlXjUlWlhXtcIaBtOzv34l/AvJNQXq9jfshqJ9vsQZ5Faia8JuV8bglfvnyjNnm53fekv7b8HfUgeOhvGWpMHzd+8y9kVeuKPd5vutcqWt6jA==; 4:1nEK8PQh9fMUkvCnGcEdvVRMjcQZI7WOtdkQPomodn1fr0BfVovRsuZfS083+6+sJ87lmxAq/fNNxcYN6pH+3KRsi/KuAghPvxv2Mh23HjlxuPdfHAaDikJ7XCTg4BsqBHmD9sI9fb8a4T31YTwLgsFjeFJZ5K+srsCEx8v8pF0FfHMQfvoCRZg8skui4p0H+cl7+qNyYsoaM0LLC0RsIKNna58zbUOQ1/66MOleY5h0ySPyiPCBKwPSIbpCxA5CjzIbUQ83lEaRxEYqfpwXQb0UtMiscfHs7ChQFB4vfwQWKfJkzOaMXesd2x6Om4StIejca7iJsHDKZFmJ5+ZSIRscYeHzRMzvRfntW/u7AqFWdXr6gNxEQljDuxHCEjfB X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(5005006)(8121501046)(3002001)(10201501046); SRVR:DB6PR0501MB2087; BCL:0; PCL:0; RULEID:; SRVR:DB6PR0501MB2087; X-Forefront-PRVS: 000800954F X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(4630300001)(6009001)(7916002)(199003)(189002)(77096005)(36756003)(42186005)(69596002)(4001430100002)(19580395003)(86362001)(7736002)(19580405001)(47776003)(5003940100001)(2950100001)(92566002)(50466002)(66066001)(76176999)(50986999)(50226002)(4326007)(48376002)(6116002)(3846002)(1076002)(586003)(97736004)(305945005)(68736007)(189998001)(105586002)(8676002)(110136002)(107886002)(53416004)(101416001)(2906002)(2351001)(81156014)(81166006)(229853001)(106356001)(7846002)(33646002)(217873001); DIR:OUT; SFP:1102; SCL:1; SRVR:DB6PR0501MB2087; H:tdx-in-nb-0014.toradex.ext; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; Received-SPF: None (protection.outlook.com: toradex.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; DB6PR0501MB2087; 23:K8pZT8nxEiZi92lJTtmlqftyxbIC7JU3Wq0M/Hp?= =?us-ascii?Q?U3iam51eKA+mj5ofrefhOUHFzL4G3LRrNazmOpZSg33QA+XjCMDR5HfP84py?= =?us-ascii?Q?Zmpwpg4X0JAJKl/gvwYMRYz36x45m+OYG9EhBRmaF7sJE+B8kAEK/WupztpY?= =?us-ascii?Q?GF6soM3HW9LzsjTmRMpEU8S1U0/65tLUz8Kylz8b0PjYic0yKhZH7ni8pwiB?= =?us-ascii?Q?OXmA6iGyUJu5bm7vejALhPOVuff99A2N5QmnNn3dREYTjWSAgpDbWqgmG/Z7?= =?us-ascii?Q?BGEa+TvGKBr+nabaA9gQ+EwaMlyazdhN2jQ7uVxaVPEIXfT/D51e+kj0i7id?= =?us-ascii?Q?1APluaQd+Mj6QdqF/g+vcNC9Cudmbr77xZlht6l04Df7AjL6CPmc5KnSyAuS?= =?us-ascii?Q?4OJ8uF5l9PKHRPCZEkjNwjoiDuOzXMLJsZqUIc2wH4Q60doYjuFGy07QHSXD?= =?us-ascii?Q?L1wQ6Jxc4mFKVXH8ysq0u4otyq20vxx6MrHWR0Ukj4zgVYo8CIJxj6PXGzoZ?= =?us-ascii?Q?WJUET1CbhCBNYAvdnuHONF0nvAL/iO09pZlkDZ9ZyrYupft6ho1u3f2WmR1z?= =?us-ascii?Q?+mb7dCPeoErrqf5cpV/bTzKUZge0R0wdrwdPYN+CYQTAAEfIk+/tHGrYASj/?= =?us-ascii?Q?MnfPRSijyBOxfs5ysh378LuDBaVfvPa9EsH9LOf322SpmjC4fgaUef/IMDnF?= =?us-ascii?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eA5/Pz0uVCmZlUI2JtCOjzEpIPxythKgh4A6dXkXCjKXUcMQEZg==; 24:Cv9mmcO4UEXSOkdxpK3aSOpVMiEp2Wzfgmrk2j9kGDllFM/dpf96R7QyAdJ+cTTkGrLceoX2ghysq3AAAGg23g1VG9cElkNIKrOpoYgLycY=; 7:bk6QydX6s4VY4lLlxzGYEafGvE7sicytlDFHvWnr/SdT94TsScQmw66L4acDMZ6AuGnV78pNSKYuWyX5fZGBgVLqKiND1HSIzOc3Og60rJOOcH3czmtQ3C6Z4YlxREMlWH1lUgN9e7BuUEy0v/ITXYTvyh3VNXM5AdxziIfC1rSl/DA6mGe5MotLK8Wq8gVzXCG7VZl9MngalVf9w8g6Im/j3yKbnwNadcNtrxV21Btp3JYPMRS8CVDVLDV2KIbt SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: toradex.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Jul 2016 07:44:35.7860 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB6PR0501MB2087 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160719_004454_672230_DA1589AA X-CRM114-Status: GOOD ( 12.02 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-serial@vger.kernel.org, mturquette@baylibre.com, sboyd@codeaurora.org, linux-kernel@vger.kernel.org, stefan@agner.ch, kernel@pengutronix.de, jslaby@suse.com, shawnguo@kernel.org, linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Bhuvanchandra DV Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP From: Stefan Agner Currently the tx_empty callback only considers the Transmit Complete Flag (TC). The reference manual is not quite clear if the TC flag covers the TX FIFO too. Debug prints on real hardware have shown that from time to time the TC flag is asserted (indicating Transmitter idle) while there are still data in the TX FIFO. Hence, in this case the serial core will call the shutdown callback even though there are data remaining in the TX FIFO buffers. Avoid early shutdowns by considering the TX FIFO empty flag too. Also avoid theoretical race conditions between DMA and the driver by checking whether the TX DMA is in progress too. Signed-off-by: Stefan Agner Signed-off-by: Bhuvanchandra DV --- drivers/tty/serial/fsl_lpuart.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/drivers/tty/serial/fsl_lpuart.c b/drivers/tty/serial/fsl_lpuart.c index 3d79003..fabfa7e 100644 --- a/drivers/tty/serial/fsl_lpuart.c +++ b/drivers/tty/serial/fsl_lpuart.c @@ -810,8 +810,18 @@ static irqreturn_t lpuart32_int(int irq, void *dev_id) /* return TIOCSER_TEMT when transmitter is not busy */ static unsigned int lpuart_tx_empty(struct uart_port *port) { - return (readb(port->membase + UARTSR1) & UARTSR1_TC) ? - TIOCSER_TEMT : 0; + struct lpuart_port *sport = container_of(port, + struct lpuart_port, port); + unsigned char sr1 = readb(port->membase + UARTSR1); + unsigned char sfifo = readb(port->membase + UARTSFIFO); + + if (sport->dma_tx_in_progress) + return 0; + + if (sr1 & UARTSR1_TC && sfifo & UARTSFIFO_TXEMPT) + return TIOCSER_TEMT; + + return 0; } static unsigned int lpuart32_tx_empty(struct uart_port *port)