From patchwork Tue Jun 9 07:23:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Frieder Schrempf X-Patchwork-Id: 224726 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 2BBAAC433E0 for ; Tue, 9 Jun 2020 07:23:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 00FCB207C3 for ; Tue, 9 Jun 2020 07:23:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=mysnt.onmicrosoft.com header.i=@mysnt.onmicrosoft.com header.b="kvXEw30Y" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726184AbgFIHXp (ORCPT ); Tue, 9 Jun 2020 03:23:45 -0400 Received: from mail-am6eur05on2124.outbound.protection.outlook.com ([40.107.22.124]:42177 "EHLO EUR05-AM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726083AbgFIHXo (ORCPT ); Tue, 9 Jun 2020 03:23:44 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nt4j9NQwlOanWwWc/zBU9+4TwmlBuCUWN1vtBHM73VfnjcKFbdp7iKumdSkWvURs2dO9ASdvyUOVUrDsVLMAMQDyvnEXcW2VjFArmXu5Nx/YGgvonWq4/raYhNmn/FPThOnthdyACrvNw+eVx/aKvoqNiUMMRCPunKLlKPYfHg7qw/UtiC9Kp3ZLYdXCURxHzw7lLppm2jDfd10Hh2L+e4LEy6PbmW9+O3zEvuKUAkO/Sr6soaOkzppXOuUN35xizJLZedtlRba9F8gZAgmyXncOaOcplHU5XY6/cFwI31utZZ/tNLubldzcPJ3YaWwWLAb/4T5RBhF13yKOIhFg3w== 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=8WSE4mdrEa4VrmDwLEkO8/+v34K36Kl/YH4u56hlgYI=; b=U8WflaV42iaFOZd2AfWCxl6oKsOmTunoURFEH5tfDRsDABrq8kZZ5xv3oXVAK3gJhipLNld6Ef4Z7wio759VavB/eFsXzNiIVBbT2pKHVeznCYn73TtlPDzWARNQFjKXdSQjyQPrbMYMKj/2vqkXhYdSoaNl5Ka2aNdkN2B/biHSArCd7WjWAtfSEG0vHyPKYqZzzWHgkXY0oho0KCMtZTE9YXJONEDYr1FQzHWNV1NqThZFRmQlNN/1tfkqE6KAQ56hQ2nwD72BNf2JWxXkvm5Nqi42e4bR/YhTCzNDAXYPDBywgHcMAYIiB8ABvdwvP7VZRLUWR7hoTTYmYZ9Kyw== 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=8WSE4mdrEa4VrmDwLEkO8/+v34K36Kl/YH4u56hlgYI=; b=kvXEw30YCgg5zRKrnJZA1agDK7V+HPgt8FeJk7y0a8wAs3RJJroCWD9AMdrHjHM8UzhqQDCctdVPaFdQ/TK86qUVcOSl8z7tgO5VjJCu3rOtk7enCBTIYDGUYHMkzShU3at2NnGMt3GmOohlN7G7949Cq1TAycXCRX4B+F5q2UM= Received: from DB7PR10MB2490.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:10:50::12) by DB7PR10MB1900.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:5:a::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3066.20; Tue, 9 Jun 2020 07:23:40 +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; Tue, 9 Jun 2020 07:23:40 +0000 From: Schrempf Frieder To: Greg Kroah-Hartman CC: Fabio Estevam , =?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 v2] serial: imx: Fix handling of TC irq in combination with DMA Thread-Topic: [PATCH v2] serial: imx: Fix handling of TC irq in combination with DMA Thread-Index: AQHWPi7m3YXfW/ta4UitHElBbvaQXQ== Date: Tue, 9 Jun 2020 07:23:40 +0000 Message-ID: <20200609072259.8259-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: 7afe26dc-b56b-4626-99df-08d80c4608c8 x-ms-traffictypediagnostic: DB7PR10MB1900: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:226; x-forefront-prvs: 042957ACD7 x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: W2j+fdXqfUu2hAQNJRps9JlCOktEhEGf9CCxxtbZHyrMl/WDIvTio9k1fzKzUmzE/NM8Vjl7Q+hsLil7eek2HiMCgLBF1cXckff8Kxgn+9kfS3gonafcLk/Fo1PFNjrpb/PFLcxCkEK5OblJDd5xSSxR6TWtapy9ua0NquuYX50j4gxo1tmEMfKQJx9CFcGffHn0Vo8yojB+ACa9qT6Te0mCLQp0xqTmS3w8xDKPW0/0AhM5DK3DWuJBjs8Me8umVAADcBmPiS4DDetG+TUpIxYRUFp5WD5U0tluvECY83rdn6oQ3Jxcb9JGGoPMHjtgmSZKPxEfgVHfsNuui7oIUw== 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)(136003)(366004)(376002)(39850400004)(346002)(396003)(4326008)(66574014)(54906003)(6512007)(83380400001)(36756003)(6486002)(6916009)(2616005)(8936002)(2906002)(6506007)(66946007)(8676002)(5660300002)(478600001)(71200400001)(66476007)(91956017)(66556008)(66446008)(64756008)(316002)(86362001)(26005)(186003)(76116006)(1076003); DIR:OUT; SFP:1102; x-ms-exchange-antispam-messagedata: XRF9/dQpcOu+YGCBME3YEZ8Ge2f1lJ1jl5v5bP0FnLhrqsOAdudPN0/44B5cOVeLZtx2Je3qNRhaVCXP2SLmaQiORqs4JhDnGfsO+QsnpzuQ0ylc5Q5EU4d/A344yhop27AQK3593TItZpjvr+pPvNYI2JeR66LLR92+p9d8oLMK9+A5AW2VMcyk5aZRn/+YTgyxRdjWHO5hi3o4QHZ87jaRm2fi81SsPhyD1yM5WDKLrG3sldTXMtDoSLr1C6u08+B+8UF28wSLjfUTXhPGHEbRZKAxpsC7uS4egAE9+kq1RiRHl7jpppeqqxsrLWb2GXYCZvCYIkPrfBF+gfOSkhMALDVagXghpom4SxkZgFx0Q1me8yVZQX244S/oRn4z/vApw6E3uEPb8tWgMPMmesaxihDJvEhJ8Yjl+/gyPCwIeUnLAQeY60ZUE4W+JDvrfqjp9Sy2cMZfsJwv/2fSFzLAOhWmI2N55lcDuUAfyOV9UIaszdt4FhoCNBkIBVBJ Content-ID: <96F7689729BDA647AD496AAA4A8CB489@EURPRD10.PROD.OUTLOOK.COM> MIME-Version: 1.0 X-OriginatorOrg: kontron.de X-MS-Exchange-CrossTenant-Network-Message-Id: 7afe26dc-b56b-4626-99df-08d80c4608c8 X-MS-Exchange-CrossTenant-originalarrivaltime: 09 Jun 2020 07:23:40.6444 (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: DOWaNgPzZVmpGPEuz0ho6WySuSLqQeZNgh0yLZbj+b308C2h7E417fhy3abqeYkzdWonou+bR0uT9li252XPpqcsl+1XQ9d0xlL2oiI7b8s= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB7PR10MB1900 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@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 | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) -- 2.17.1 diff --git a/drivers/tty/serial/imx.c b/drivers/tty/serial/imx.c index 3f2605edd855..70c737236870 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) { @@ -617,10 +626,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) {