Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp5005639ybb; Tue, 24 Mar 2020 09:13:10 -0700 (PDT) X-Google-Smtp-Source: ADFU+vugZPW6Z0VvoxQYhPVLwUdeLQjHcfrtmZYaWH3kjjqPxw6QRxzVCol5pMUPVM3czxitEI1T X-Received: by 2002:a9d:6b8b:: with SMTP id b11mr6817787otq.119.1585066390401; Tue, 24 Mar 2020 09:13:10 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1585066390; cv=pass; d=google.com; s=arc-20160816; b=NzfrssEXeBZoqU27H6zHqMIcMIPbObJCyuJYzWqdJ/Juc1j/TJH+ZKfBj5D/HwFAH0 OYCuzNO0QANx3Q14TzlmXGg8v216vWVXYlEZi0dxpjHeqDokJ0opZmnkDKyXuG1m/ARM yAKK8hWD7fWmN+5egdqHPCZSQCgIb3F+eNEns0SiWwrn31Ds0s9bOzIeO37RC3H9lsOJ 0E5Wn/4dFbQKNDYdHLfON7QXLB8wcwCBb5RlpsXk5NJimQllhoUjIk4IuKLdfornuwLo 5IN+KCeTWlV1eh1uiPrwkcfAso+xpTa1gjs3dYHxnORKO6B5DO0nSz/SFb9fH49cgL7f SWgg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :content-language:accept-language:in-reply-to:references:message-id :date:thread-index:thread-topic:subject:cc:to:from:dkim-signature; bh=iEQ5an93V2aaUXoITnMc4MEvldKwDZ8+83cHgSDIVvM=; b=df9pMBDO6kCaZtr5557mj5InaIYjHGIlRGQDCrkv+sy9suotLk5+meeBy9/zWZmRfN 691fIL3XNyTQ8HkK3BCFe96KHQvAOUgu/yQ//3WRiEMaUexclg5x+rzuPN5g/OSjygtZ adspm53cgvIxPCVyAWA3BAt7FKgspb+yxy2rRkgAuSG7nYgTOsjG6cYLZopKNYu/A3J4 24qf2h2NGjQSl0KpYf8FA1RTpsln0y50s45HK9E67rlH3oQJ3uS6IY3hw4GObQymaKGk 4ADjzPNBucVFhH/expqNvJtYZavsx5qxBNZL9/px1MC7uJ59/pRwO/rfMEdA6ldPhMGZ 6/2Q== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@nxp.com header.s=selector2 header.b=cEtIX7FC; arc=pass (i=1 spf=pass spfdomain=nxp.com dkim=pass dkdomain=nxp.com dmarc=pass fromdomain=nxp.com); spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nxp.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s132si828104oig.109.2020.03.24.09.12.57; Tue, 24 Mar 2020 09:13:10 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@nxp.com header.s=selector2 header.b=cEtIX7FC; arc=pass (i=1 spf=pass spfdomain=nxp.com dkim=pass dkdomain=nxp.com dmarc=pass fromdomain=nxp.com); spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728840AbgCXQMJ (ORCPT + 99 others); Tue, 24 Mar 2020 12:12:09 -0400 Received: from mail-eopbgr20054.outbound.protection.outlook.com ([40.107.2.54]:57764 "EHLO EUR02-VE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728571AbgCXQMI (ORCPT ); Tue, 24 Mar 2020 12:12:08 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Ywi2b/v3xB/NzP5vGzUy2g+YDFTTeCp6CNlpLbInr3oe8VIsOVU6X/QoDcEMV3vDjFy/WC85AD+gsa2rQSb7KdbKbZfGFhE+oa54dsyEj93gyzam8HX83tsfhBa4QLviI9qjyaLbviQjvmNfPhF9tn3OKDx8wyGgECloBxUyeKj12gDIR8DcV2aHLmwjBq81LmrFeuVsymaQKU/edrULE5nRlHAFbm/RAy0llnwenw4QiFmx+3YUVveHVvzHeE7KwL3PD5UUOqx/S7LiZYUiEr5JJnnifXo6062vEsSgU5Bt7qxZ0mNL5ZL8gVA2cvyiGZDr8+Lr/qJk+XAM1HI6dg== 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=iEQ5an93V2aaUXoITnMc4MEvldKwDZ8+83cHgSDIVvM=; b=TJb7O8GHuzFBk1GcddK7q0H1QcvWAwQ6kb1+dItaRSSxMXwhgY0z/x2OsNWoHC7OHcBjxHFCau7TgY5I/O88V8M3Ogyho9Y1H5PQtYjLzglFb1g7Xfxg1UVgdhoFPGt8a5DkeDbxkl6o/IgmqdNEod954d7SkiUiJCaY3xOHkEXCNnXjIMbIE/mKe391HXmZkFhb3z5usWRck1jlSM6vHYhtWStr5jpqIXhz0NL46ql6Rbld7DB3FmFTDWDP2qmrRrxwwsIpG9tJDQ6W1utNKnXrQpD9ppfiKlA7G4VP2SIaI6UlByKMK/HXrPF/gfBFJaz4wSX3RYiaqCZR4HOygw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=iEQ5an93V2aaUXoITnMc4MEvldKwDZ8+83cHgSDIVvM=; b=cEtIX7FC/gz8qGP7Cz0ruyEl3fRjYPP+hV9DbLuWXM0QcfcwzrofeqRYPetU3z0hy0Dr7ej4JKVLJKJhusBqShs572arGV8fHbEp56OuiJ8cNYR/8Ml4DpTKdfHScHQaZc1LCxG4okyONZS/xRHNYrS1QPvxpFD0YcccFSr/zRY= Received: from VI1PR0402MB3600.eurprd04.prod.outlook.com (52.134.3.146) by VI1PR0402MB3663.eurprd04.prod.outlook.com (52.134.15.152) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2835.22; Tue, 24 Mar 2020 16:12:04 +0000 Received: from VI1PR0402MB3600.eurprd04.prod.outlook.com ([fe80::c991:848b:cc80:2768]) by VI1PR0402MB3600.eurprd04.prod.outlook.com ([fe80::c991:848b:cc80:2768%7]) with mapi id 15.20.2835.023; Tue, 24 Mar 2020 16:12:04 +0000 From: Andy Duan To: Leonard Crestez , Michael Walle , Greg Kroah-Hartman , Shawn Guo CC: "linux-serial@vger.kernel.org" , "linux-kernel@vger.kernel.org" , Jiri Slaby , Rob Herring , Aisheng Dong , Vabhav Sharma , Andrey Smirnov , Peng Fan Subject: RE: [PATCH v4 1/4] tty: serial: fsl_lpuart: fix DMA operation when using IOMMU Thread-Topic: [PATCH v4 1/4] tty: serial: fsl_lpuart: fix DMA operation when using IOMMU Thread-Index: AQHV9AB7XTSsAtbd1E+3Etbi7F0aCKhYBLIQ Date: Tue, 24 Mar 2020 16:12:04 +0000 Message-ID: References: <20200306214433.23215-1-michael@walle.cc> <20200306214433.23215-2-michael@walle.cc> In-Reply-To: Accept-Language: zh-CN, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=fugang.duan@nxp.com; x-originating-ip: [119.31.174.68] x-ms-publictraffictype: Email x-ms-office365-filtering-ht: Tenant x-ms-office365-filtering-correlation-id: 50c138ea-4898-46aa-dd55-08d7d00e17d8 x-ms-traffictypediagnostic: VI1PR0402MB3663:|VI1PR0402MB3663: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:9508; x-forefront-prvs: 03524FBD26 x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(4636009)(366004)(136003)(39860400002)(396003)(346002)(376002)(71200400001)(186003)(53546011)(33656002)(4326008)(86362001)(8936002)(478600001)(55016002)(54906003)(81156014)(5660300002)(316002)(66946007)(7696005)(9686003)(26005)(6506007)(52536014)(66476007)(2906002)(66556008)(81166006)(66446008)(110136005)(76116006)(8676002)(64756008);DIR:OUT;SFP:1101;SCL:1;SRVR:VI1PR0402MB3663;H:VI1PR0402MB3600.eurprd04.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords; received-spf: None (protection.outlook.com: nxp.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: eaHPQDuFzH2SBfOTVRDyT00r7TWpCF74l8MFZUkAPP7Z6hik4UY8LFqg1DxE1yXJjt6rMVm8ETVqEXWX+r64UsQzzU9M37WRpUKk2IPcmDUHJZuf7smQ7YUpWTHKXyuPFc4PRDol+CMqSRlMqCv7SQ48DnmU2wvtb12wQXL4lO147M8P99iKCj7RchvU3BOyoUEpsITR8qhxUMrs2cVv2yG682zQLDEUAE8R4cvKE1DHSxS891svEcP7jO4/mIrP5mXSHuecFuh9AAQ5NBPlh8RpKtXx0n3WLZMviq1QGmEDaInz/KieGuARmKi3hQif8YTs5u1nUIqjnAQZg9Si/1+Qwhs8f04I0B6aJsRh2y4M02TQxdugVLACdoOGgnka0XdD2aC57g/ii0pQzeA73x+M4ZrKOcz6LA2KIovVGl2Xjr9NMd58scoI6k3PxMbW x-ms-exchange-antispam-messagedata: GX2yMc+ZNbQ92m7VXrhDUFNIHSdYCjc/IaPoEOi3QBvuveOQIBj5hTX7KKQ1Y6h2/+OmtC43AL+PG2A29eUX7ZqwcFGEj3bufrlnJ+9+m2ay2pctCccAez6utPBt9WT1iayOKn+hQe4kmemVS7nP7Q== Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 50c138ea-4898-46aa-dd55-08d7d00e17d8 X-MS-Exchange-CrossTenant-originalarrivaltime: 24 Mar 2020 16:12:04.2753 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: kFlxcdq+hE/u72X5sgBBXCOowgjn2O8CQ3V7Xv4sYCuVSFV9rvJDstuq8HLIEBLOjZWif0JhApzDbCbjuGMd4Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0402MB3663 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Leonard Crestez Sent: Tuesday, March 24, 20= 20 11:27 PM > On 06.03.2020 23:44, Michael Walle wrote: > > The DMA channel might not be available at probe time. This is esp. the > > case if the DMA controller has an IOMMU mapping. > > > > There is also another caveat. If there is no DMA controller at all, > > dma_request_chan() will also return -EPROBE_DEFER. Thus we cannot test > > for -EPROBE_DEFER in probe(). Otherwise the lpuart driver will fail to > > probe if, for example, the DMA driver is not enabled in the kernel > > configuration. If DMA driver is not enabled, we should disable DMA controller node in dts file to match current sw environment, then driver doesn't do defer prob= e. So I still suggest to check -EPROBE_DEFER for dma_request_slave_channel() i= n .probe() function. Andy > > > > To workaround this, we request the DMA channel in _startup(). Other > > serial drivers do it the same way. > > > > Signed-off-by: Michael Walle >=20 > This appears to cause boot hangs on imx8qxp-mek (boards boots fine on > next-20200324 if this patch is reverted) >=20 > > --- > > drivers/tty/serial/fsl_lpuart.c | 88 +++++++++++++++++++++-----------= - > > 1 file changed, 57 insertions(+), 31 deletions(-) > > > > diff --git a/drivers/tty/serial/fsl_lpuart.c > > b/drivers/tty/serial/fsl_lpuart.c index c31b8f3db6bf..33798df4d727 > > 100644 > > --- a/drivers/tty/serial/fsl_lpuart.c > > +++ b/drivers/tty/serial/fsl_lpuart.c > > @@ -1493,36 +1493,67 @@ static void rx_dma_timer_init(struct > lpuart_port *sport) > > static void lpuart_tx_dma_startup(struct lpuart_port *sport) > > { > > u32 uartbaud; > > + int ret; > > > > - if (sport->dma_tx_chan && !lpuart_dma_tx_request(&sport->port)) { > > - init_waitqueue_head(&sport->dma_wait); > > - sport->lpuart_dma_tx_use =3D true; > > - if (lpuart_is_32(sport)) { > > - uartbaud =3D lpuart32_read(&sport->port, UARTBAUD); > > - lpuart32_write(&sport->port, > > - uartbaud | UARTBAUD_TDMAE, UARTBAUD); > > - } else { > > - writeb(readb(sport->port.membase + UARTCR5) | > > - UARTCR5_TDMAS, sport->port.membase + UARTCR5); > > - } > > + sport->dma_tx_chan =3D dma_request_chan(sport->port.dev, "tx"); > > + if (IS_ERR(sport->dma_tx_chan)) { > > + dev_info_once(sport->port.dev, > > + "DMA tx channel request failed, operating without tx > DMA (%ld)\n", > > + PTR_ERR(sport->dma_tx_chan)); >=20 > It seems that this since this is called from lpuart32_startup with > &sport->port.lock held and lpuart32_console_write takes the same lock it = can > and hang. >=20 > As a workaround I can just remove this print but there are other possible= error > conditions in dmaengine code which can cause a printk. >=20 > Maybe the port lock should only be held around register manipulation? >=20 > > + sport->dma_tx_chan =3D NULL; > > + goto err; > > + } > > + > > + ret =3D lpuart_dma_tx_request(&sport->port); > > + if (!ret) > > + goto err; >=20 > This is backwards: lpuart_dma_tx_request returns negative errno on failur= e. >=20 > > + > > + init_waitqueue_head(&sport->dma_wait); > > + sport->lpuart_dma_tx_use =3D true; > > + if (lpuart_is_32(sport)) { > > + uartbaud =3D lpuart32_read(&sport->port, UARTBAUD); > > + lpuart32_write(&sport->port, > > + uartbaud | UARTBAUD_TDMAE, UARTBAUD); > > } else { > > - sport->lpuart_dma_tx_use =3D false; > > + writeb(readb(sport->port.membase + UARTCR5) | > > + UARTCR5_TDMAS, sport->port.membase + UARTCR5); > > } > > + > > + return; > > + > > +err: > > + sport->lpuart_dma_tx_use =3D false; > > } > > > > static void lpuart_rx_dma_startup(struct lpuart_port *sport) > > { > > - if (sport->dma_rx_chan && !lpuart_start_rx_dma(sport)) { > > - /* set Rx DMA timeout */ > > - sport->dma_rx_timeout =3D msecs_to_jiffies(DMA_RX_TIMEOUT); > > - if (!sport->dma_rx_timeout) > > - sport->dma_rx_timeout =3D 1; > > + int ret; > > > > - sport->lpuart_dma_rx_use =3D true; > > - rx_dma_timer_init(sport); > > - } else { > > - sport->lpuart_dma_rx_use =3D false; > > + sport->dma_rx_chan =3D dma_request_chan(sport->port.dev, "rx"); > > + if (IS_ERR(sport->dma_rx_chan)) { > > + dev_info_once(sport->port.dev, > > + "DMA rx channel request failed, operating without rx > DMA (%ld)\n", > > + PTR_ERR(sport->dma_rx_chan)); > > + sport->dma_rx_chan =3D NULL; > > + goto err; > > } > > + > > + ret =3D lpuart_start_rx_dma(sport); > > + if (ret) > > + goto err; >=20 > This is not backwards. >=20 > > + > > + /* set Rx DMA timeout */ > > + sport->dma_rx_timeout =3D msecs_to_jiffies(DMA_RX_TIMEOUT); > > + if (!sport->dma_rx_timeout) > > + sport->dma_rx_timeout =3D 1; > > + > > + sport->lpuart_dma_rx_use =3D true; > > + rx_dma_timer_init(sport); > > + > > + return; > > + > > +err: > > + sport->lpuart_dma_rx_use =3D false; > > } > > > > static int lpuart_startup(struct uart_port *port) @@ -1615,6 > > +1646,11 @@ static void lpuart_dma_shutdown(struct lpuart_port *sport) > > dmaengine_terminate_all(sport->dma_tx_chan); > > } > > } > > + > > + if (sport->dma_tx_chan) > > + dma_release_channel(sport->dma_tx_chan); > > + if (sport->dma_rx_chan) > > + dma_release_channel(sport->dma_rx_chan); > > } > > > > static void lpuart_shutdown(struct uart_port *port) @@ -2520,16 > > +2556,6 @@ static int lpuart_probe(struct platform_device *pdev) > > > > sport->port.rs485_config(&sport->port, &sport->port.rs485); > > > > - sport->dma_tx_chan =3D dma_request_slave_channel(sport->port.dev, > "tx"); > > - if (!sport->dma_tx_chan) > > - dev_info(sport->port.dev, "DMA tx channel request failed, " > > - "operating without tx DMA\n"); > > - > > - sport->dma_rx_chan =3D dma_request_slave_channel(sport->port.dev, > "rx"); > > - if (!sport->dma_rx_chan) > > - dev_info(sport->port.dev, "DMA rx channel request failed, " > > - "operating without rx DMA\n"); > > - > > return 0; > > > > failed_attach_port: > >