From patchwork Tue Jun 3 05:51:44 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 4285221 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id EE01E9F326 for ; Tue, 3 Jun 2014 05:54:08 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1D83C201BF for ; Tue, 3 Jun 2014 05:54:08 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id AFBBD201BC for ; Tue, 3 Jun 2014 05:54:06 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1Wrhdu-000575-QQ; Tue, 03 Jun 2014 05:52:14 +0000 Received: from relay1.mentorg.com ([192.94.38.131]) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1Wrhdr-0004us-GT for linux-arm-kernel@lists.infradead.org; Tue, 03 Jun 2014 05:52:12 +0000 Received: from svr-orw-exc-10.mgc.mentorg.com ([147.34.98.58]) by relay1.mentorg.com with esmtp id 1WrhdR-0001GW-6y from Jiada_Wang@mentor.com ; Mon, 02 Jun 2014 22:51:45 -0700 Received: from SVR-ORW-FEM-03.mgc.mentorg.com ([147.34.97.39]) by SVR-ORW-EXC-10.mgc.mentorg.com with Microsoft SMTPSVC(6.0.3790.4675); Mon, 2 Jun 2014 22:51:44 -0700 Received: from NA-MBX-01.mgc.mentorg.com ([169.254.1.163]) by SVR-ORW-FEM-03.mgc.mentorg.com ([147.34.97.39]) with mapi id 14.02.0247.003; Mon, 2 Jun 2014 22:51:44 -0700 From: "Wang, Jiada (ESD)" To: Huang Shijie , "shawn.guo@linaro.org" , "s.hauer@pengutronix.de" Subject: RE: [PATCH 1/4] serial: imx: implement the flush_buffer hook Thread-Topic: [PATCH 1/4] serial: imx: implement the flush_buffer hook Thread-Index: AQHOxm+ZGMZK1ttOdEml/foDEfbGXZtgTanQ Date: Tue, 3 Jun 2014 05:51:44 +0000 Message-ID: <857E9EDCA6C0904DB3357321AA9123EBE14C42AE@NA-MBX-01.mgc.mentorg.com> References: <1381487461-12850-1-git-send-email-b32955@freescale.com> <1381487461-12850-2-git-send-email-b32955@freescale.com> In-Reply-To: <1381487461-12850-2-git-send-email-b32955@freescale.com> Accept-Language: en-US Content-Language: ja-JP X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [147.34.91.1] MIME-Version: 1.0 X-OriginalArrivalTime: 03 Jun 2014 05:51:44.0938 (UTC) FILETIME=[E6AC78A0:01CF7EEF] X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140602_225211_575018_9D540CA8 X-CRM114-Status: GOOD ( 16.54 ) X-Spam-Score: 0.0 (/) Cc: "linux-arm-kernel@lists.infradead.org" , "dirk.behme@gmail.com" , "linux-serial@vger.kernel.org" X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Hi Shijie By having this commit, I am seeing random hit of BUG_ON() in dma_cookie_complete(), When large data file is set to UART port with relately high baud rate. I suspect even after dmaengine_terminate_all() is called in .flush_buffer(), By some reason, the 'terminated sdma channel' 's irq handler is still got called sometimes Thus cause a extra of dma_cookie_complete() executed randomly. To Shawn and Sascha I found your discussion about sdma_disable_channel in http://permalink.gmane.org/gmane.linux.ports.arm.kernel/103283 this seems like a similar issue to the one I have observed in UART-SDMA usage my understanding is there is potential race between stop of SDMA channel and finish of SDMA transfer. Do you have any ideas how to avoid this race condition? Thanks, Jiada -----Original Message----- From: linux-arm-kernel [mailto:linux-arm-kernel-bounces@lists.infradead.org] On Behalf Of Huang Shijie Sent: Friday, October 11, 2013 7:31 PM To: gregkh@linuxfoundation.org Cc: Huang Shijie; shawn.guo@linaro.org; linux-arm-kernel@lists.infradead.org; linux-serial@vger.kernel.org Subject: [PATCH 1/4] serial: imx: implement the flush_buffer hook The current driver does not implement the flush_buffer hook for uart_ops. When we enable the DMA for the driver, and test it with Bluetooth, we may meet the following bug for TX: [1] User application may call the flush operation at any time. The uart_flush_buffer() calls the uart_circ_clear() to set the xmit->head and xmit->tail with 0. [2] The TX DMA callback can be called at any time too. The dma_tx_call() will update the xmit->tail. If [2] occurs just after the [1], we will get the wrong xmit->tail. This patch implements the flush_buffer hook to fix this issue. Signed-off-by: Huang Shijie --- drivers/tty/serial/imx.c | 11 +++++++++++ 1 files changed, 11 insertions(+), 0 deletions(-) .break_ctl = imx_break_ctl, .startup = imx_startup, .shutdown = imx_shutdown, + .flush_buffer = imx_flush_buffer, .set_termios = imx_set_termios, .type = imx_type, .release_port = imx_release_port, -- 1.7.2.rc3 diff --git a/drivers/tty/serial/imx.c b/drivers/tty/serial/imx.c index c07d9bb..708ba89 100644 --- a/drivers/tty/serial/imx.c +++ b/drivers/tty/serial/imx.c @@ -1303,6 +1303,16 @@ static void imx_shutdown(struct uart_port *port) clk_disable_unprepare(sport->clk_ipg); } +static void imx_flush_buffer(struct uart_port *port) { + struct imx_port *sport = (struct imx_port *)port; + + if (sport->dma_is_enabled) { + sport->tx_bytes = 0; + dmaengine_terminate_all(sport->dma_chan_tx); + } +} + static void imx_set_termios(struct uart_port *port, struct ktermios *termios, struct ktermios *old) @@ -1623,6 +1633,7 @@ static struct uart_ops imx_pops = {