Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp2150338ybv; Fri, 21 Feb 2020 09:50:10 -0800 (PST) X-Google-Smtp-Source: APXvYqyYu5d0cA/P2H/K7dpdwIh7a8GDja8QPtEFO1bEmu4IX1a2mCoiXame75ORkMlzSgDBTgOv X-Received: by 2002:a9d:7ac9:: with SMTP id m9mr28147554otn.80.1582307409846; Fri, 21 Feb 2020 09:50:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582307409; cv=none; d=google.com; s=arc-20160816; b=bj6LVYY+WFkaDWP+1Ir+H81biJmn3m97C3a0Za0i0nsb5Hp4boLA7bTt7AvoKBCCBa BzcuaV9b7AfRqv+MwL2636RgtWEp08/HcCQDLjkJiFgkJL7yAIzuSwUq9DYR/q5LHDkp of1PNtkfSJFKqQxTepLjekUAa7/0ZXw8ncg+4DCvlymUV6GbbvrKzEsx/RvcSwNw+Z8P hRbO6xuupmzwN6XVlMG5iaHfXhGd7sQvEHOPVai7oaiVQMeGAfyLGhekSr2+VyaNE8Gy DswyQN1Ugl/MNDYU7NMRMUeMFOnCy4+rav/oQKNNtmuImvzwbLWfyjz8t4vrLVPMhpSl k04g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=UaO+mat3+Uxwq9DbMCw/0coohVq5jCugVuQMQ8FIwrs=; b=SDKAYbb1t7O9I9FO/vF0iuc96EiQX2wdyOWWi2BqF0K82J6b/OW3ndoCdJBqvTYyqd WANE9irstbgk7pT2wp6BhjDyinQ/dSNHmNyhID7nAjqiaVSAMnib3Uv7lelokLdTI9+k vddTRg30kl1V1iZZzTObUVZeUR0P8O+EN6+nijJVtAbCZIZQyMX5IIkeY1S1tnHu0Ueq exGXrEf2eC3cd1NGad9pdmE3uZIutvPIIG37iw9J67B/CRtyYxSHPqknMCtLjoUwqPBb 587OYzuCbTCFQavDhfOPgYKcb9zf5bIOX0w/2/gQczxsnClFVUVxeODXeAHIj0O4GSM7 gyoQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@walle.cc header.s=mail2016061301 header.b=idc5b+QM; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h64si1065705oif.215.2020.02.21.09.49.57; Fri, 21 Feb 2020 09:50:09 -0800 (PST) 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=@walle.cc header.s=mail2016061301 header.b=idc5b+QM; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729278AbgBURsR (ORCPT + 99 others); Fri, 21 Feb 2020 12:48:17 -0500 Received: from ssl.serverraum.org ([176.9.125.105]:40293 "EHLO ssl.serverraum.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727656AbgBURsP (ORCPT ); Fri, 21 Feb 2020 12:48:15 -0500 Received: from mwalle01.sab.local. (unknown [213.135.10.150]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by ssl.serverraum.org (Postfix) with ESMTPSA id A907223E48; Fri, 21 Feb 2020 18:48:13 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=walle.cc; s=mail2016061301; t=1582307293; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UaO+mat3+Uxwq9DbMCw/0coohVq5jCugVuQMQ8FIwrs=; b=idc5b+QMoxawIvKVFlumo+VKwBVU+wu8qoriOT8yy2LjtP358qRiPgrG2ypwk0t/BjAtsf RmJtmFd2YZfFYcrCHLcH5JvPhtLiuUcV8zb+NXrWanXidNWNhjavtro2Kl1sue6z1sQ64h kXI9fGHrYM9eW3k3GypteLKapvdJ0oI= From: Michael Walle To: linux-serial@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: Greg Kroah-Hartman , Rob Herring , Mark Rutland , Shawn Guo , Li Yang , Jiri Slaby , Peng Fan , Vabhav Sharma , Michael Walle Subject: [PATCH v2 3/9] tty: serial: fsl_lpuart: handle EPROBE_DEFER for DMA Date: Fri, 21 Feb 2020 18:47:48 +0100 Message-Id: <20200221174754.5295-4-michael@walle.cc> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200221174754.5295-1-michael@walle.cc> References: <20200221174754.5295-1-michael@walle.cc> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spamd-Bar: ++++++ X-Spam-Level: ****** X-Rspamd-Server: web X-Spam-Status: Yes, score=6.40 X-Spam-Score: 6.40 X-Rspamd-Queue-Id: A907223E48 X-Spamd-Result: default: False [6.40 / 15.00]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; R_MISSING_CHARSET(2.50)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; TAGGED_RCPT(0.00)[dt]; MIME_GOOD(-0.10)[text/plain]; BROKEN_CONTENT_TYPE(1.50)[]; NEURAL_SPAM(0.00)[0.764]; DKIM_SIGNED(0.00)[]; RCPT_COUNT_TWELVE(0.00)[13]; MID_CONTAINS_FROM(1.00)[]; RCVD_COUNT_ZERO(0.00)[0]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; ASN(0.00)[asn:12941, ipnet:213.135.0.0/19, country:DE]; SUSPICIOUS_RECIPS(1.50)[] X-Spam: Yes Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The DMA channel might not be available at the first probe time. This is esp. the case if the DMA controller has an IOMMU mapping. Use the new dma_request_chan() API and handle EPROBE_DEFER errors. Also reorder the code a bit, so that we don't prepare the whole UART just to determine that the DMA channel is not ready yet and we have to undo all the stuff. Try to map the DMA channels earlier. Signed-off-by: Michael Walle --- drivers/tty/serial/fsl_lpuart.c | 35 +++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/drivers/tty/serial/fsl_lpuart.c b/drivers/tty/serial/fsl_lpuart.c index c31b8f3db6bf..fd9f60d0817a 100644 --- a/drivers/tty/serial/fsl_lpuart.c +++ b/drivers/tty/serial/fsl_lpuart.c @@ -2416,6 +2416,7 @@ static int lpuart_probe(struct platform_device *pdev) const struct lpuart_soc_data *sdata = of_id->data; struct device_node *np = pdev->dev.of_node; struct lpuart_port *sport; + struct dma_chan *dma_chan; struct resource *res; int ret; @@ -2483,6 +2484,26 @@ static int lpuart_probe(struct platform_device *pdev) } sport->port.line = ret; + dma_chan = dma_request_chan(sport->port.dev, "tx"); + if (PTR_ERR(dma_chan) == -EPROBE_DEFER) { + ret = -EPROBE_DEFER; + goto failed_request_tx_dma; + } else if (IS_ERR(dma_chan)) + dev_info(sport->port.dev, "DMA tx channel request failed, " + "operating without tx DMA\n"); + else + sport->dma_tx_chan = dma_chan; + + dma_chan = dma_request_chan(sport->port.dev, "rx"); + if (PTR_ERR(dma_chan) == -EPROBE_DEFER) { + ret = -EPROBE_DEFER; + goto failed_request_rx_dma; + } else if (IS_ERR(dma_chan)) + dev_info(sport->port.dev, "DMA rx channel request failed, " + "operating without rx DMA\n"); + else + sport->dma_rx_chan = dma_chan; + ret = lpuart_enable_clks(sport); if (ret) goto failed_clock_enable; @@ -2520,22 +2541,16 @@ static int lpuart_probe(struct platform_device *pdev) sport->port.rs485_config(&sport->port, &sport->port.rs485); - sport->dma_tx_chan = 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 = 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: failed_irq_request: lpuart_disable_clks(sport); failed_clock_enable: + dma_release_channel(sport->dma_rx_chan); +failed_request_rx_dma: + dma_release_channel(sport->dma_tx_chan); +failed_request_tx_dma: failed_out_of_range: if (sport->id_allocated) ida_simple_remove(&fsl_lpuart_ida, sport->port.line); -- 2.20.1