From patchwork Mon Jun 8 15:11:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Frieder Schrempf X-Patchwork-Id: 213933 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.7 required=3.0 tests=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=unavailable 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 A794CC433DF for ; Mon, 8 Jun 2020 15:11:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 72E3E2064C for ; Mon, 8 Jun 2020 15:11:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=mysnt.onmicrosoft.com header.i=@mysnt.onmicrosoft.com header.b="MyjiaSxu" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730201AbgFHPLo (ORCPT ); Mon, 8 Jun 2020 11:11:44 -0400 Received: from mail-eopbgr30109.outbound.protection.outlook.com ([40.107.3.109]:34305 "EHLO EUR03-AM5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1730190AbgFHPLn (ORCPT ); Mon, 8 Jun 2020 11:11:43 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=m0k9dpL6t9I/b2C1tshF6YiQFdZp5a0tSpGPMSvYZNHHAdGqGTYElM2gJ1Bit8Xr4DTwsuwNMwPhc7jKS+b2ebCT1KOvO8aKl8JnO0oO1+nFH2mquTdKxgd1DR/oC9JTrHYm1znWiT2Z1/lsSK8sTQYeVpV7UnXPMjeFqF7e+HKHduU29wI6IFmpdEgUGNnYFS11FWCI/t6nrYYRBilyMkkTZWwW2ZzzgmXUvW3IivzFIL0OTDkfXCwvNW3CgqGV+CPSyXCJlBZAc4fOVL/HbmJeuzuPzbcaxVKX9rheQMNAFBbRxps1qiUdU9pXGNYTvA5NNespqY1nG59iHkocOQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=v4kZAD0Lgw+oGfxVwzCegd01JmMLaNZFSW8ITYYMk4g=; b=FKaPV4l9tJ+OuHuTuo8lPgd62YND525RwsxHxOfVq1WVrvkv8V3KjaSN5cx0HLiIljfRSWREDCe1bRBWZzmc1brImU+Y5IM7E8ulKCy2XfmBsw0vb6GherbIatjMd3RWlVUu9mu4zgcFy38DFiWQIlhU+6cQYvg3syJ2gWxJzdrKKHRmN5C7QYTzXdTRXBoJMvgVc5FBHPORcmOtpJpbgAhkzWHkV3ZMVTQR2HGTQqq/v3uJvG5T3lDkbHb6HBVdH2uRIT9SmzVr2UIsULlFbMupL2cG6UMqO4eguFTTbyAcG/+5VEYGqmhPuT0+EofF9mzpmJQ4sqt326bzkPd5zQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=kontron.de; dmarc=pass action=none header.from=kontron.de; dkim=pass header.d=kontron.de; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mysnt.onmicrosoft.com; s=selector2-mysnt-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=v4kZAD0Lgw+oGfxVwzCegd01JmMLaNZFSW8ITYYMk4g=; b=MyjiaSxuIrpgHwlF/zWRLABL4eb7JMMmucsXfh81fAINr4CDy/mjjJg0GBxy2uvgGIYIyv65EU8wJf0K7YB1HERm2ECmgQ8jG5CP64L0/SKFaMljQzhStsBz1TeBCOwjTpAain4ivskM75E8KLpmKsblYD1Vjehu9W7mLfoRydY= Received: from DB7PR10MB2490.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:10:50::12) by DB7PR10MB2043.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:5:12::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3066.18; Mon, 8 Jun 2020 15:11:36 +0000 Received: from DB7PR10MB2490.EURPRD10.PROD.OUTLOOK.COM ([fe80::acc5:2acd:49a6:5048]) by DB7PR10MB2490.EURPRD10.PROD.OUTLOOK.COM ([fe80::acc5:2acd:49a6:5048%7]) with mapi id 15.20.3066.023; Mon, 8 Jun 2020 15:11:36 +0000 From: Schrempf Frieder To: Greg Kroah-Hartman CC: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= , "stable@vger.kernel.org" , Schrempf Frieder , "linux-kernel@vger.kernel.org" , "linux-serial@vger.kernel.org" Subject: [PATCH] serial: imx: Fix handling of TC irq in combination with DMA Thread-Topic: [PATCH] serial: imx: Fix handling of TC irq in combination with DMA Thread-Index: AQHWPacakgJZrwZ8pkOomdvwi0/9IQ== Date: Mon, 8 Jun 2020 15:11:36 +0000 Message-ID: <20200608151012.7296-1-frieder.schrempf@kontron.de> Accept-Language: en-GB, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.17.1 authentication-results: linuxfoundation.org; dkim=none (message not signed) header.d=none; linuxfoundation.org; dmarc=none action=none header.from=kontron.de; x-originating-ip: [77.246.119.226] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 32172caa-f316-4836-c6f4-08d80bbe3c93 x-ms-traffictypediagnostic: DB7PR10MB2043: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:226; x-forefront-prvs: 042857DBB5 x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: kyxuASHfKYig5pqqedEIUSoCgUJ51Dd/YGZ+cNScLqceahb5my81JCc7SbWXk7ulcNJQVWsoAqpgQeW1e8jcQxnRxSYQF/4SoCGHdK9Na655OkaLjohsre4VWzu7b9OyI9mTkXkKv9Ph4gSZ/LNGQekW9QH12GiM+HQhYdYSv2YFvi39QFCs+6LmFOZGaylpr0EXG9DlXbC+c4TVsv+Zt5HLrUdI6K+5q+RhNAhQ6HBjdwgfPuu3rtnGO8zMsg/kk9fiVTINlsReejKSisqnhAM9t3AFLoD+9uvseKe0ZhDSKr8Mps6BQy0dinetDj93rDAb6EglXvoIv99vsSAiIA== x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DB7PR10MB2490.EURPRD10.PROD.OUTLOOK.COM; PTR:; CAT:NONE; SFTY:; SFS:(4636009)(346002)(39850400004)(136003)(376002)(396003)(366004)(8936002)(66574014)(6506007)(86362001)(83380400001)(8676002)(5660300002)(36756003)(71200400001)(4326008)(2906002)(478600001)(26005)(186003)(66476007)(91956017)(6916009)(66446008)(2616005)(64756008)(54906003)(6486002)(1076003)(316002)(6512007)(66556008)(76116006)(66946007); DIR:OUT; SFP:1102; x-ms-exchange-antispam-messagedata: rbsJnBu+DNoqm2d12U7EOB9faKZBbjHjMzeqydfKqhNVn2pTB70x2WdDGkI1jaDymBskAUksBnPdS7gPLrHnMiFW38D0Eaj80hnzqC6r+vFk/EKAC0UHC7Wp7+oURxuY/tVhrhk2wMxvrrXThDPUOpR739vjH027M3hCRz92pIPu7wh/SMySKMNFqer6QLa5PRGO0aFOtyB20UWDBlRGlAStubY8S2wCo1HdJ/ckAZHYJh/6se7TTC8ZhxNfUi5yFIsftlyyg5RVlmdW6Tqbxg+dbb9Z+qcGb0R6nHQEplnUZp7ZvEiiWIB5NX0uABgO1NLeRvApCkgl43/M9RvcihLP+SV3zAOr1W3IIZWQF36qZ8iZjZ8Jh+5YrYXm2jVUgLzN90gJMNMX5W15Hd+XbeBATRFTKznXorasN+Igl7HsRZBkUq9zrXwB9+ngZ/9+eSyEiPnl/A2DV8bLn+9CFURKANvwckqCUvDXNsTsO8IcADgrcKH4fInkw/pybkT8 Content-ID: <3D23C829F8B0C34D8F5AC104D2B3DA92@EURPRD10.PROD.OUTLOOK.COM> MIME-Version: 1.0 X-OriginatorOrg: kontron.de X-MS-Exchange-CrossTenant-Network-Message-Id: 32172caa-f316-4836-c6f4-08d80bbe3c93 X-MS-Exchange-CrossTenant-originalarrivaltime: 08 Jun 2020 15:11:36.0594 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 8c9d3c97-3fd9-41c8-a2b1-646f3942daf1 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: LrY1+xSLEkmvRmTulTuDRBJXn6Rxd8+HrVzFdm8/R6ouvJB4UxbPXUPO+LVyu0tYqcIsCKuSmGlGBEpkvP+wL6++KqQlwtIPJlDymN0nK2k= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB7PR10MB2043 Sender: linux-serial-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org From: Uwe Kleine-König commit 1866541492641c02874bf51f9d8712b5510f2c64 upstream When using RS485 half duplex the Transmitter Complete irq is needed to determine the moment when the transmitter can be disabled. When using DMA this irq must only be enabled when DMA has completed to transfer all data. Otherwise the CPU might busily trigger this irq which is not properly handled and so the also pending irq for the DMA transfer cannot trigger. Cc: # v4.14.x Signed-off-by: Uwe Kleine-König Signed-off-by: Greg Kroah-Hartman [Backport to v4.14] Signed-off-by: Frieder Schrempf --- When using RS485 with DMA enabled simply transmitting some data on our i.MX6ULL based boards often freezes the system completely. The higher the baudrate, the easier it is to reproduce the issue. To test this I simply used: stty -F /dev/ttymxc1 speed 115200 while true; do echo TEST > /dev/ttymxc1; done Without the patch this leads to an almost immediate system freeze, with the patch applied, everything keeps working as expected. --- drivers/tty/serial/imx.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) -- 2.17.1 diff --git a/drivers/tty/serial/imx.c b/drivers/tty/serial/imx.c index 3f2605edd855..993ab57e7448 100644 --- a/drivers/tty/serial/imx.c +++ b/drivers/tty/serial/imx.c @@ -538,6 +538,11 @@ static void dma_tx_callback(void *data) if (!uart_circ_empty(xmit) && !uart_tx_stopped(&sport->port)) imx_dma_tx(sport); + else if (sport->port.rs485.flags & SER_RS485_ENABLED) { + temp = readl(sport->port.membase + UCR4); + temp |= UCR4_TCEN; + writel(temp, sport->port.membase + UCR4); + } spin_unlock_irqrestore(&sport->port.lock, flags); } @@ -555,6 +560,10 @@ static void imx_dma_tx(struct imx_port *sport) if (sport->dma_is_txing) return; + temp = readl(sport->port.membase + UCR4); + temp &= ~UCR4_TCEN; + writel(temp, sport->port.membase + UCR4); + sport->tx_bytes = uart_circ_chars_pending(xmit); if (xmit->tail < xmit->head || xmit->head == 0) { @@ -608,6 +617,7 @@ static void imx_start_tx(struct uart_port *port) if (port->rs485.flags & SER_RS485_ENABLED) { temp = readl(port->membase + UCR2); + if (port->rs485.flags & SER_RS485_RTS_ON_SEND) imx_port_rts_active(sport, &temp); else @@ -617,10 +627,15 @@ static void imx_start_tx(struct uart_port *port) if (!(port->rs485.flags & SER_RS485_RX_DURING_TX)) imx_stop_rx(port); - /* enable transmitter and shifter empty irq */ - temp = readl(port->membase + UCR4); - temp |= UCR4_TCEN; - writel(temp, port->membase + UCR4); + /* + * Enable transmitter and shifter empty irq only if DMA is off. + * In the DMA case this is done in the tx-callback. + */ + if (!sport->dma_is_enabled) { + temp = readl(port->membase + UCR4); + temp |= UCR4_TCEN; + writel(temp, port->membase + UCR4); + } } if (!sport->dma_is_enabled) {