From patchwork Tue Jun 28 05:32:27 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bhuvanchandra DV X-Patchwork-Id: 9201853 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 1F2F36075F for ; Tue, 28 Jun 2016 05:33:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0F80C285E7 for ; Tue, 28 Jun 2016 05:33:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 03C9D285EC; Tue, 28 Jun 2016 05:33:25 +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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID 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 2CD9C285E9 for ; Tue, 28 Jun 2016 05:33:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751331AbcF1FdV (ORCPT ); Tue, 28 Jun 2016 01:33:21 -0400 Received: from mail-db5eur01on0118.outbound.protection.outlook.com ([104.47.2.118]:10192 "EHLO EUR01-DB5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750836AbcF1FdT (ORCPT ); Tue, 28 Jun 2016 01:33:19 -0400 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=S35XbVnte6rqfDU+U6JVvK+727L0asmyTaLNgWVyzCKN6neAvIvUTMIVHNh5Z25nLiexd0QII8XtSx6E25mhbkqqAiSHbd9Of6BAJ83aEclVe372+zDn8KllsuMNTrbt5pplMmPfiOh6rmhoSEF5YWhb+AeS/kLQUUkhu4HWf8o= 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 HE1PR0501MB2089.eurprd05.prod.outlook.com (10.167.246.9) with Microsoft SMTP Server (TLS) id 15.1.523.12; Tue, 28 Jun 2016 05:33:13 +0000 From: Bhuvanchandra DV To: CC: , , , , , , , , , , "Bhuvanchandra DV" Subject: [PATCH v2 1/9] tty: serial: fsl_lpuart: consider TX FIFO too in tx_empty Date: Tue, 28 Jun 2016 11:02:27 +0530 Message-ID: <20160628053235.5114-2-bhuvanchandra.dv@toradex.com> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20160628053235.5114-1-bhuvanchandra.dv@toradex.com> References: <20160628053235.5114-1-bhuvanchandra.dv@toradex.com> MIME-Version: 1.0 X-Originating-IP: [115.115.243.34] X-ClientProxiedBy: BM1PR01CA0056.INDPRD01.PROD.OUTLOOK.COM (10.163.199.28) To HE1PR0501MB2089.eurprd05.prod.outlook.com (10.167.246.9) X-MS-Office365-Filtering-Correlation-Id: 8011bdc5-95af-495a-5ba4-08d39f15b456 X-Microsoft-Exchange-Diagnostics: 1; HE1PR0501MB2089; 2:MW6jj6j3mIgobKyNzB4rjQ3CPOtjnobQQEEU2hsakcrDsKzh/Xj4DcM9Pmvq8EU9AgcIB9AobKwQn7ncTzGlLJy3PTQWDnDrf/rOPOjD9r50HMVZauOyVwBDkQL7vsbhkI4GtN37YlhNDxAoJEdsQu6qiAlHMmevraqRCEuaJUdl/X1MDcYaeDHVpUuAB4X7; 3:ATlU2FbcW5j+Iua5TvUbH8tFRCvLDYwBZ06c+3W77LZtap777TiwbQJQ/H6ZtnurSIahE1yKeK5R/+TfXfH0NwYnQyVfaCEXwTY8QDnBslcFthhnFqkXejVaQmZoLZKk X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:HE1PR0501MB2089; X-Microsoft-Exchange-Diagnostics: 1; HE1PR0501MB2089; 25:J0hNDcnHVGoKR1QH7twq7AKWXqHYpGWU9FA4IWuSPjzaBCyKCtywkTH7KV6qc0iQGLTAIrtfj1JM9Kt+xN7DSwl7iswmGy6sUyv9nP4DxrAj/EhC3g1RVQ9kH2yHCoBJRu5I53rW9ulR3jgoEALz7rNfyQ92YxwdJHmjWJEX3/Vc273fZKP2hrlLQ7wSqvlAxAe1aCjnBYc+FER0fKf9jVP93H3jfLaVVUAgFUtspsMfNurekquuAaU3BNzOJNzsDPR836m4TjjeXcDMyyCGSnkLIOL+G72vyVniIoOsMaXlhneG/+sPN4xV9hs445BglEyGkHlEXcUTierToDtbDkwe068ycmkNPWCCocgbyBgSRuChyLF0PGscmBzE3H0nxhYABvAvLm2jO5FyqAve9fuVXEXundrPSjRwsK90W7nNjksM6v27ILrlJlXI6IJyRM8It6oQAYzeYB+R4tXAIc/vCybz1qaQtpCakdqh2jQLUHK4oVfaQ38g0DMjnEY3wpXqHdjM4JqTpvjITOmx9Fs1twmEWpt+riQNZvAWT/MI1faI6GdSHiPe+902juJrwd3cvqGLY/53nJDQDR5DnYRZ4ERcLn0YnhxT16YY7k2l1lj4h8C8YCuw56knSybU4UvJyh0gx+cpE0YM2WgjGD1x0XM7tcDtc2OJjfwvGxJ220cEnvQfhCBi99PE5qIBLdMrmi30yr0HsJq+ybPqqA== X-Microsoft-Exchange-Diagnostics: 1; HE1PR0501MB2089; 20:MrsHWQmMJ7zKqgE3OzIlAupoDMNI6DlOGL1liN4H2Lw09G5uIJ2WHlI38uFV0QnQbXTUGBEZEEKfkZmlIlpCt3HhdpmPjcLo+Nu7kU+Nq2ItO7Yk8Z6RqYT4Wqkq7jl2k+I5s1B2du3u9F7cpcN327zor2/eNiYfyt2FQS6g80NS9ztYsSmKjovAo723aI8UVdqsahfhboS5jnuNc7DL8M/mPD4a2Yl8DAI2Ugt0jww6lnqpYiFSTjTiigSA5nYlHxx85soXRWj8tGCknhLvwkhs3FuItWgr70bSBbCeSw5C2tr91cwj0os5y17VBDJRQOVISjqnUoYwlIB38ulMGw==; 4:iD8ZI7idNdvxY/VFqVMQKWKICfWK8TQCRv/S6sND/gqiAxyCCyHxrK4CdX7oW5AOBTICxMzVbWoILcga3FwqdHvVrpT/X7WVsp61wqqAP02cbaOu3mrbbZfqWTVTKkjqH77EE8xyYL/CTYHmu4JmUtIwCXWQK3VOxKY0z2ha+oLZIR98keapiXEVSx+g08UgMtmHnhbqPlz+fNkhXKXjDKmi0/AhrRkowuF1Pj7OGF0pwSFHdqETQ9ppGVYY51lG4lJXCzoTa0SOABIxzPoRMExhguxr/P0hqQOsYZ7pXp7MllJwF9Ejb7UbgzP3nqewTSEJYD1cwQXimy16DCMz89msgTuTnlC5KlN+WCqefW/Uluj3yeqYYpNmAQK6e0t0 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)(10201501046)(3002001); SRVR:HE1PR0501MB2089; BCL:0; PCL:0; RULEID:; SRVR:HE1PR0501MB2089; X-Forefront-PRVS: 0987ACA2E2 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(4630300001)(6009001)(7916002)(199003)(189002)(189998001)(50226002)(110136002)(107886002)(7846002)(47776003)(66066001)(36756003)(8676002)(101416001)(1076002)(48376002)(33646002)(6116002)(81166006)(92566002)(3846002)(50986999)(586003)(81156014)(50466002)(2351001)(2950100001)(77096005)(105586002)(229853001)(86362001)(76176999)(5003940100001)(68736007)(305945005)(106356001)(4326007)(7736002)(53416004)(4001430100002)(19580405001)(19580395003)(69596002)(42186005)(97736004)(2906002); DIR:OUT; SFP:1102; SCL:1; SRVR:HE1PR0501MB2089; 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; HE1PR0501MB2089; 23:J4OeapJrVU5VB6zuB1yaYdBqBwsrXyG0BdNbOUY?= =?us-ascii?Q?iAJXrGZS5jzF3clOCc418JFTTDxP2R7cU6UqqpkFn/v4LhFAp8wsztL3xFcu?= =?us-ascii?Q?TUp3B70mfxyyTDMTzueqn2ZY5QPbJAcEr5keAW30ZP+NUWSbH6lKEp8sBvYv?= =?us-ascii?Q?AcxPS8lMWHUL/Y7UyW5edyWUfGiYC1Rlk4M9z6cp41Vfsq7or78nYFjAVKmu?= =?us-ascii?Q?SyPtOEQT7YtLc26rmLwPxIhSy1GaA+zXeLUBVzxGAqY+RycZOW09aFrMOlnX?= =?us-ascii?Q?2d+YlGAZS0+8N8skTstPu/YktA/nvl46OyMDljefalat7OpfvNlkL/T/BfKm?= =?us-ascii?Q?O1zUAd2qn+2XSfs+A+9HGbc5X4b8An/o9lwRHtvakdoSsyH/SDqXupQhhek2?= =?us-ascii?Q?5fWSBp2+UNpY3K1fpA7Kj+UAOIj6cU2HedreyUQza+llQwuF97ZZX4iCkILb?= =?us-ascii?Q?IPbaANcFkBS5SPAix+mAhF8gDyMnCHZx1ASFhdm7YonYxevsNBXRABztYDRk?= =?us-ascii?Q?f9uK4QagwMVSL30O3DQZcfydECX+7Z7fBikBKE1R7W7pCDJjgKcngRx9DN4P?= =?us-ascii?Q?Guya5i1SqEGMLc0AgG3i+tTqJJyVmDf83wYd14UlDh9G1QAiBxDaX/LRshpP?= =?us-ascii?Q?12vuJbhqoCatWqkU9APPDqK+3VdqYe2Dqz37iuFpoitxlizsNTD8Ty0Mbxn3?= =?us-ascii?Q?zfzDvGRgaARIWaBAgvFTi/WgXas63ot8Ilnjbg+PdKKUxkcqJ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==; 24:lWsoyraPgj+RP9sh/t15dzwwB+tCCJVyLZT1Br6DGClECY6znDi92mXTbs9Ng7iFEXPENadj/GqT24IXh5JzZWT10Z7zu7ezCM6OkYEs9so=; 7:FwV5tump2SqYX1fC0IJ0ongRd8N8mkTjLr070M1CZZWJaHKuY9lKt6WziG5CWD6NZ13/Dc6/KriXAQrKS4/lEp+q2BspTbIOtebxAFFSZL6ic2uKZl+E8BfUv3UxZcHBY8PMKUi72IBxbQ9MJEsS9aP41BA07PQ40xoP4qpRO2RH6BCTHl5K5/dCe0o/qmvC/e4gyXeBb0Ll0NivcDeryBtKVtHCPMd4ckguw05VQSJiaN7OhcUE+qx7YgRNC0nVvHRJvyMrYYigXKZ3t13ncA== SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: toradex.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Jun 2016 05:33:13.4829 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1PR0501MB2089 Sender: linux-clk-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-clk@vger.kernel.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)