LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH 0/7] mtd: rawnand: Convert drivers to use dma_request_chan()
@ 2020-02-27 12:37 Peter Ujfalusi
  2020-02-27 12:37 ` [PATCH 1/7] mtd: rawnand: gpmi: Use dma_request_chan() instead dma_request_slave_channel() Peter Ujfalusi
                   ` (6 more replies)
  0 siblings, 7 replies; 16+ messages in thread
From: Peter Ujfalusi @ 2020-02-27 12:37 UTC (permalink / raw)
  To: vigneshr, miquel.raynal, han.xu, richard, mripard, wens,
	mcoquelin.stm32, alexandre.torgue
  Cc: linux-mtd, linux-kernel, linux-arm-kernel, vkoul

Hi,

With dma_request_chan() drivers can know why the channel request failed and
depending on how they are implemented can handle the failure in a best effort,
either deferring or falling back to PIO mode.

Regards,
Peter
---
Peter Ujfalusi (7):
  mtd: rawnand: gpmi: Use dma_request_chan() instead
    dma_request_slave_channel()
  mtd: rawnand: marvell: Release DMA channel on error
  mtd: rawnand: marvell: Use dma_request_chan() instead
    dma_request_slave_channel()
  mtd: rawnand: sunxi: Use dma_request_chan() instead
    dma_request_slave_channel()
  mtd: rawnand: qcom: Release resources on failure within
    qcom_nandc_alloc()
  mtd: rawnand: qcom: Use dma_request_chan() instead
    dma_request_slave_channel()
  mtd: rawnand: stm32_fmc2: Use dma_request_chan() instead
    dma_request_slave_channel()

 drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c |  21 +++--
 drivers/mtd/nand/raw/marvell_nand.c        |  38 +++++---
 drivers/mtd/nand/raw/qcom_nandc.c          | 105 +++++++++++++--------
 drivers/mtd/nand/raw/stm32_fmc2_nand.c     |  44 +++++++--
 drivers/mtd/nand/raw/sunxi_nand.c          |  15 ++-
 5 files changed, 149 insertions(+), 74 deletions(-)

-- 
Peter

Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki.
Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH 1/7] mtd: rawnand: gpmi: Use dma_request_chan() instead dma_request_slave_channel()
  2020-02-27 12:37 [PATCH 0/7] mtd: rawnand: Convert drivers to use dma_request_chan() Peter Ujfalusi
@ 2020-02-27 12:37 ` Peter Ujfalusi
  2020-03-10 18:31   ` Miquel Raynal
  2020-02-27 12:37 ` [PATCH 2/7] mtd: rawnand: marvell: Release DMA channel on error Peter Ujfalusi
                   ` (5 subsequent siblings)
  6 siblings, 1 reply; 16+ messages in thread
From: Peter Ujfalusi @ 2020-02-27 12:37 UTC (permalink / raw)
  To: vigneshr, miquel.raynal, han.xu, richard, mripard, wens,
	mcoquelin.stm32, alexandre.torgue
  Cc: linux-mtd, linux-kernel, linux-arm-kernel, vkoul

dma_request_slave_channel() is a wrapper on top of dma_request_chan()
eating up the error code.

Use using dma_request_chan() directly to return the real error code.

Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>
---
 drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)

diff --git a/drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c b/drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c
index b9d5d55a5edb..53b00c841aec 100644
--- a/drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c
+++ b/drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c
@@ -1148,20 +1148,21 @@ static int acquire_dma_channels(struct gpmi_nand_data *this)
 {
 	struct platform_device *pdev = this->pdev;
 	struct dma_chan *dma_chan;
+	int ret = 0;
 
 	/* request dma channel */
-	dma_chan = dma_request_slave_channel(&pdev->dev, "rx-tx");
-	if (!dma_chan) {
-		dev_err(this->dev, "Failed to request DMA channel.\n");
-		goto acquire_err;
+	dma_chan = dma_request_chan(&pdev->dev, "rx-tx");
+	if (IS_ERR(dma_chan)) {
+		ret = PTR_ERR(dma_chan);
+		if (ret != -EPROBE_DEFER)
+			dev_err(this->dev, "DMA channel request failed: %d\n",
+				ret);
+		release_dma_channels(this);
+	} else {
+		this->dma_chans[0] = dma_chan;
 	}
 
-	this->dma_chans[0] = dma_chan;
-	return 0;
-
-acquire_err:
-	release_dma_channels(this);
-	return -EINVAL;
+	return ret;
 }
 
 static int gpmi_get_clks(struct gpmi_nand_data *this)
-- 
Peter

Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki.
Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH 2/7] mtd: rawnand: marvell: Release DMA channel on error
  2020-02-27 12:37 [PATCH 0/7] mtd: rawnand: Convert drivers to use dma_request_chan() Peter Ujfalusi
  2020-02-27 12:37 ` [PATCH 1/7] mtd: rawnand: gpmi: Use dma_request_chan() instead dma_request_slave_channel() Peter Ujfalusi
@ 2020-02-27 12:37 ` Peter Ujfalusi
  2020-03-10 18:30   ` Miquel Raynal
  2020-02-27 12:37 ` [PATCH 3/7] mtd: rawnand: marvell: Use dma_request_chan() instead dma_request_slave_channel() Peter Ujfalusi
                   ` (4 subsequent siblings)
  6 siblings, 1 reply; 16+ messages in thread
From: Peter Ujfalusi @ 2020-02-27 12:37 UTC (permalink / raw)
  To: vigneshr, miquel.raynal, han.xu, richard, mripard, wens,
	mcoquelin.stm32, alexandre.torgue
  Cc: linux-mtd, linux-kernel, linux-arm-kernel, vkoul

Release the DMA channel on errors after the channel has been successfully
requested.

Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>
---
 drivers/mtd/nand/raw/marvell_nand.c | 25 +++++++++++++++++++------
 1 file changed, 19 insertions(+), 6 deletions(-)

diff --git a/drivers/mtd/nand/raw/marvell_nand.c b/drivers/mtd/nand/raw/marvell_nand.c
index fb5abdcfb007..b6c7e1903396 100644
--- a/drivers/mtd/nand/raw/marvell_nand.c
+++ b/drivers/mtd/nand/raw/marvell_nand.c
@@ -2751,8 +2751,10 @@ static int marvell_nfc_init_dma(struct marvell_nfc *nfc)
 	}
 
 	r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-	if (!r)
-		return -ENXIO;
+	if (!r) {
+		ret = -ENXIO;
+		goto release_channel;
+	}
 
 	config.src_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
 	config.dst_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
@@ -2763,7 +2765,7 @@ static int marvell_nfc_init_dma(struct marvell_nfc *nfc)
 	ret = dmaengine_slave_config(nfc->dma_chan, &config);
 	if (ret < 0) {
 		dev_err(nfc->dev, "Failed to configure DMA channel\n");
-		return ret;
+		goto release_channel;
 	}
 
 	/*
@@ -2773,12 +2775,20 @@ static int marvell_nfc_init_dma(struct marvell_nfc *nfc)
 	 * the provided buffer.
 	 */
 	nfc->dma_buf = kmalloc(MAX_CHUNK_SIZE, GFP_KERNEL | GFP_DMA);
-	if (!nfc->dma_buf)
-		return -ENOMEM;
+	if (!nfc->dma_buf) {
+		ret = -ENOMEM;
+		goto release_channel;
+	}
 
 	nfc->use_dma = true;
 
 	return 0;
+
+release_channel:
+	dma_release_channel(nfc->dma_chan);
+	nfc->dma_chan = NULL;
+
+	return ret;
 }
 
 static void marvell_nfc_reset(struct marvell_nfc *nfc)
@@ -2920,10 +2930,13 @@ static int marvell_nfc_probe(struct platform_device *pdev)
 
 	ret = marvell_nand_chips_init(dev, nfc);
 	if (ret)
-		goto unprepare_reg_clk;
+		goto release_dma;
 
 	return 0;
 
+release_dma:
+	if (nfc->use_dma)
+		dma_release_channel(nfc->dma_chan);
 unprepare_reg_clk:
 	clk_disable_unprepare(nfc->reg_clk);
 unprepare_core_clk:
-- 
Peter

Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki.
Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH 3/7] mtd: rawnand: marvell: Use dma_request_chan() instead dma_request_slave_channel()
  2020-02-27 12:37 [PATCH 0/7] mtd: rawnand: Convert drivers to use dma_request_chan() Peter Ujfalusi
  2020-02-27 12:37 ` [PATCH 1/7] mtd: rawnand: gpmi: Use dma_request_chan() instead dma_request_slave_channel() Peter Ujfalusi
  2020-02-27 12:37 ` [PATCH 2/7] mtd: rawnand: marvell: Release DMA channel on error Peter Ujfalusi
@ 2020-02-27 12:37 ` Peter Ujfalusi
  2020-03-10 18:30   ` Miquel Raynal
  2020-02-27 12:37 ` [PATCH 4/7] mtd: rawnand: sunxi: " Peter Ujfalusi
                   ` (3 subsequent siblings)
  6 siblings, 1 reply; 16+ messages in thread
From: Peter Ujfalusi @ 2020-02-27 12:37 UTC (permalink / raw)
  To: vigneshr, miquel.raynal, han.xu, richard, mripard, wens,
	mcoquelin.stm32, alexandre.torgue
  Cc: linux-mtd, linux-kernel, linux-arm-kernel, vkoul

dma_request_slave_channel() is a wrapper on top of dma_request_chan()
eating up the error code.

Use using dma_request_chan() directly to return the real error code.

Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>
---
 drivers/mtd/nand/raw/marvell_nand.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/drivers/mtd/nand/raw/marvell_nand.c b/drivers/mtd/nand/raw/marvell_nand.c
index b6c7e1903396..911430cca7c8 100644
--- a/drivers/mtd/nand/raw/marvell_nand.c
+++ b/drivers/mtd/nand/raw/marvell_nand.c
@@ -2743,11 +2743,14 @@ static int marvell_nfc_init_dma(struct marvell_nfc *nfc)
 	if (ret)
 		return ret;
 
-	nfc->dma_chan =	dma_request_slave_channel(nfc->dev, "data");
-	if (!nfc->dma_chan) {
-		dev_err(nfc->dev,
-			"Unable to request data DMA channel\n");
-		return -ENODEV;
+	nfc->dma_chan =	dma_request_chan(nfc->dev, "data");
+	if (IS_ERR(nfc->dma_chan)) {
+		ret = PTR_ERR(nfc->dma_chan);
+		nfc->dma_chan = NULL;
+		if (ret != -EPROBE_DEFER)
+			dev_err(nfc->dev, "DMA channel request failed: %d\n",
+				ret);
+		return ret;
 	}
 
 	r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-- 
Peter

Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki.
Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH 4/7] mtd: rawnand: sunxi: Use dma_request_chan() instead dma_request_slave_channel()
  2020-02-27 12:37 [PATCH 0/7] mtd: rawnand: Convert drivers to use dma_request_chan() Peter Ujfalusi
                   ` (2 preceding siblings ...)
  2020-02-27 12:37 ` [PATCH 3/7] mtd: rawnand: marvell: Use dma_request_chan() instead dma_request_slave_channel() Peter Ujfalusi
@ 2020-02-27 12:37 ` Peter Ujfalusi
  2020-03-09  9:58   ` Maxime Ripard
  2020-03-10 18:30   ` Miquel Raynal
  2020-02-27 12:37 ` [PATCH 5/7] mtd: rawnand: qcom: Release resources on failure within qcom_nandc_alloc() Peter Ujfalusi
                   ` (2 subsequent siblings)
  6 siblings, 2 replies; 16+ messages in thread
From: Peter Ujfalusi @ 2020-02-27 12:37 UTC (permalink / raw)
  To: vigneshr, miquel.raynal, han.xu, richard, mripard, wens,
	mcoquelin.stm32, alexandre.torgue
  Cc: linux-mtd, linux-kernel, linux-arm-kernel, vkoul

dma_request_slave_channel() is a wrapper on top of dma_request_chan()
eating up the error code.

By using dma_request_chan() directly the driver can support deferred
probing against DMA.

Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>
---
 drivers/mtd/nand/raw/sunxi_nand.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/drivers/mtd/nand/raw/sunxi_nand.c b/drivers/mtd/nand/raw/sunxi_nand.c
index 37a4ac0dd85b..3a24c4512af7 100644
--- a/drivers/mtd/nand/raw/sunxi_nand.c
+++ b/drivers/mtd/nand/raw/sunxi_nand.c
@@ -2123,8 +2123,16 @@ static int sunxi_nfc_probe(struct platform_device *pdev)
 	if (ret)
 		goto out_ahb_reset_reassert;
 
-	nfc->dmac = dma_request_slave_channel(dev, "rxtx");
-	if (nfc->dmac) {
+	nfc->dmac = dma_request_chan(dev, "rxtx");
+	if (IS_ERR(nfc->dmac)) {
+		ret = PTR_ERR(nfc->dmac);
+		if (ret == -EPROBE_DEFER)
+			goto out_ahb_reset_reassert;
+
+		/* Ignore errors to fall back to PIO mode */
+		dev_warn(dev, "failed to request rxtx DMA channel: %d\n", ret);
+		nfc->dmac = NULL;
+	} else {
 		struct dma_slave_config dmac_cfg = { };
 
 		dmac_cfg.src_addr = r->start + nfc->caps->reg_io_data;
@@ -2138,9 +2146,6 @@ static int sunxi_nfc_probe(struct platform_device *pdev)
 		if (nfc->caps->extra_mbus_conf)
 			writel(readl(nfc->regs + NFC_REG_CTL) |
 			       NFC_DMA_TYPE_NORMAL, nfc->regs + NFC_REG_CTL);
-
-	} else {
-		dev_warn(dev, "failed to request rxtx DMA channel\n");
 	}
 
 	platform_set_drvdata(pdev, nfc);
-- 
Peter

Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki.
Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH 5/7] mtd: rawnand: qcom: Release resources on failure within qcom_nandc_alloc()
  2020-02-27 12:37 [PATCH 0/7] mtd: rawnand: Convert drivers to use dma_request_chan() Peter Ujfalusi
                   ` (3 preceding siblings ...)
  2020-02-27 12:37 ` [PATCH 4/7] mtd: rawnand: sunxi: " Peter Ujfalusi
@ 2020-02-27 12:37 ` Peter Ujfalusi
  2020-03-10 18:30   ` Miquel Raynal
  2020-02-27 12:37 ` [PATCH 6/7] mtd: rawnand: qcom: Use dma_request_chan() instead dma_request_slave_channel() Peter Ujfalusi
  2020-02-27 12:37 ` [PATCH 7/7] mtd: rawnand: stm32_fmc2: " Peter Ujfalusi
  6 siblings, 1 reply; 16+ messages in thread
From: Peter Ujfalusi @ 2020-02-27 12:37 UTC (permalink / raw)
  To: vigneshr, miquel.raynal, han.xu, richard, mripard, wens,
	mcoquelin.stm32, alexandre.torgue
  Cc: linux-mtd, linux-kernel, linux-arm-kernel, vkoul

In case when DMA channel request or alloc_bam_transaction() fails,
dma_unmap_single() and any channels already requested should be released.

Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>
---
 drivers/mtd/nand/raw/qcom_nandc.c | 61 +++++++++++++++++--------------
 1 file changed, 34 insertions(+), 27 deletions(-)

diff --git a/drivers/mtd/nand/raw/qcom_nandc.c b/drivers/mtd/nand/raw/qcom_nandc.c
index 7bb9a7e8e1e7..ca21cb3836dc 100644
--- a/drivers/mtd/nand/raw/qcom_nandc.c
+++ b/drivers/mtd/nand/raw/qcom_nandc.c
@@ -2628,6 +2628,29 @@ static const struct nand_controller_ops qcom_nandc_ops = {
 	.attach_chip = qcom_nand_attach_chip,
 };
 
+static void qcom_nandc_unalloc(struct qcom_nand_controller *nandc)
+{
+	if (nandc->props->is_bam) {
+		if (!dma_mapping_error(nandc->dev, nandc->reg_read_dma))
+			dma_unmap_single(nandc->dev, nandc->reg_read_dma,
+					 MAX_REG_RD *
+					 sizeof(*nandc->reg_read_buf),
+					 DMA_FROM_DEVICE);
+
+		if (nandc->tx_chan)
+			dma_release_channel(nandc->tx_chan);
+
+		if (nandc->rx_chan)
+			dma_release_channel(nandc->rx_chan);
+
+		if (nandc->cmd_chan)
+			dma_release_channel(nandc->cmd_chan);
+	} else {
+		if (nandc->chan)
+			dma_release_channel(nandc->chan);
+	}
+}
+
 static int qcom_nandc_alloc(struct qcom_nand_controller *nandc)
 {
 	int ret;
@@ -2676,19 +2699,22 @@ static int qcom_nandc_alloc(struct qcom_nand_controller *nandc)
 		nandc->tx_chan = dma_request_slave_channel(nandc->dev, "tx");
 		if (!nandc->tx_chan) {
 			dev_err(nandc->dev, "failed to request tx channel\n");
-			return -ENODEV;
+			ret = -ENODEV;
+			goto unalloc;
 		}
 
 		nandc->rx_chan = dma_request_slave_channel(nandc->dev, "rx");
 		if (!nandc->rx_chan) {
 			dev_err(nandc->dev, "failed to request rx channel\n");
-			return -ENODEV;
+			ret = -ENODEV;
+			goto unalloc;
 		}
 
 		nandc->cmd_chan = dma_request_slave_channel(nandc->dev, "cmd");
 		if (!nandc->cmd_chan) {
 			dev_err(nandc->dev, "failed to request cmd channel\n");
-			return -ENODEV;
+			ret = -ENODEV;
+			goto unalloc;
 		}
 
 		/*
@@ -2702,7 +2728,8 @@ static int qcom_nandc_alloc(struct qcom_nand_controller *nandc)
 		if (!nandc->bam_txn) {
 			dev_err(nandc->dev,
 				"failed to allocate bam transaction\n");
-			return -ENOMEM;
+			ret = -ENOMEM;
+			goto unalloc;
 		}
 	} else {
 		nandc->chan = dma_request_slave_channel(nandc->dev, "rxtx");
@@ -2720,29 +2747,9 @@ static int qcom_nandc_alloc(struct qcom_nand_controller *nandc)
 	nandc->controller.ops = &qcom_nandc_ops;
 
 	return 0;
-}
-
-static void qcom_nandc_unalloc(struct qcom_nand_controller *nandc)
-{
-	if (nandc->props->is_bam) {
-		if (!dma_mapping_error(nandc->dev, nandc->reg_read_dma))
-			dma_unmap_single(nandc->dev, nandc->reg_read_dma,
-					 MAX_REG_RD *
-					 sizeof(*nandc->reg_read_buf),
-					 DMA_FROM_DEVICE);
-
-		if (nandc->tx_chan)
-			dma_release_channel(nandc->tx_chan);
-
-		if (nandc->rx_chan)
-			dma_release_channel(nandc->rx_chan);
-
-		if (nandc->cmd_chan)
-			dma_release_channel(nandc->cmd_chan);
-	} else {
-		if (nandc->chan)
-			dma_release_channel(nandc->chan);
-	}
+unalloc:
+	qcom_nandc_unalloc(nandc);
+	return ret;
 }
 
 /* one time setup of a few nand controller registers */
-- 
Peter

Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki.
Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH 6/7] mtd: rawnand: qcom: Use dma_request_chan() instead dma_request_slave_channel()
  2020-02-27 12:37 [PATCH 0/7] mtd: rawnand: Convert drivers to use dma_request_chan() Peter Ujfalusi
                   ` (4 preceding siblings ...)
  2020-02-27 12:37 ` [PATCH 5/7] mtd: rawnand: qcom: Release resources on failure within qcom_nandc_alloc() Peter Ujfalusi
@ 2020-02-27 12:37 ` Peter Ujfalusi
  2020-03-10 18:30   ` Miquel Raynal
  2020-02-27 12:37 ` [PATCH 7/7] mtd: rawnand: stm32_fmc2: " Peter Ujfalusi
  6 siblings, 1 reply; 16+ messages in thread
From: Peter Ujfalusi @ 2020-02-27 12:37 UTC (permalink / raw)
  To: vigneshr, miquel.raynal, han.xu, richard, mripard, wens,
	mcoquelin.stm32, alexandre.torgue
  Cc: linux-mtd, linux-kernel, linux-arm-kernel, vkoul

dma_request_slave_channel() is a wrapper on top of dma_request_chan()
eating up the error code.

Use using dma_request_chan() directly to return the real error code.

Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>
---
 drivers/mtd/nand/raw/qcom_nandc.c | 50 ++++++++++++++++++++-----------
 1 file changed, 33 insertions(+), 17 deletions(-)

diff --git a/drivers/mtd/nand/raw/qcom_nandc.c b/drivers/mtd/nand/raw/qcom_nandc.c
index ca21cb3836dc..5b11c7061497 100644
--- a/drivers/mtd/nand/raw/qcom_nandc.c
+++ b/drivers/mtd/nand/raw/qcom_nandc.c
@@ -2696,24 +2696,36 @@ static int qcom_nandc_alloc(struct qcom_nand_controller *nandc)
 			return -EIO;
 		}
 
-		nandc->tx_chan = dma_request_slave_channel(nandc->dev, "tx");
-		if (!nandc->tx_chan) {
-			dev_err(nandc->dev, "failed to request tx channel\n");
-			ret = -ENODEV;
+		nandc->tx_chan = dma_request_chan(nandc->dev, "tx");
+		if (IS_ERR(nandc->tx_chan)) {
+			ret = PTR_ERR(nandc->tx_chan);
+			nandc->tx_chan = NULL;
+			if (ret != -EPROBE_DEFER)
+				dev_err(nandc->dev,
+					"tx DMA channel request failed: %d\n",
+					ret);
 			goto unalloc;
 		}
 
-		nandc->rx_chan = dma_request_slave_channel(nandc->dev, "rx");
-		if (!nandc->rx_chan) {
-			dev_err(nandc->dev, "failed to request rx channel\n");
-			ret = -ENODEV;
+		nandc->rx_chan = dma_request_chan(nandc->dev, "rx");
+		if (IS_ERR(nandc->rx_chan)) {
+			ret = PTR_ERR(nandc->rx_chan);
+			nandc->rx_chan = NULL;
+			if (ret != -EPROBE_DEFER)
+				dev_err(nandc->dev,
+					"rx DMA channel request failed: %d\n",
+					ret);
 			goto unalloc;
 		}
 
-		nandc->cmd_chan = dma_request_slave_channel(nandc->dev, "cmd");
-		if (!nandc->cmd_chan) {
-			dev_err(nandc->dev, "failed to request cmd channel\n");
-			ret = -ENODEV;
+		nandc->cmd_chan = dma_request_chan(nandc->dev, "cmd");
+		if (IS_ERR(nandc->cmd_chan)) {
+			ret = PTR_ERR(nandc->cmd_chan);
+			nandc->cmd_chan = NULL;
+			if (ret != -EPROBE_DEFER)
+				dev_err(nandc->dev,
+					"cmd DMA channel request failed: %d\n",
+					ret);
 			goto unalloc;
 		}
 
@@ -2732,11 +2744,15 @@ static int qcom_nandc_alloc(struct qcom_nand_controller *nandc)
 			goto unalloc;
 		}
 	} else {
-		nandc->chan = dma_request_slave_channel(nandc->dev, "rxtx");
-		if (!nandc->chan) {
-			dev_err(nandc->dev,
-				"failed to request slave channel\n");
-			return -ENODEV;
+		nandc->chan = dma_request_chan(nandc->dev, "rxtx");
+		if (IS_ERR(nandc->chan)) {
+			ret = PTR_ERR(nandc->chan);
+			nandc->chan = NULL;
+			if (ret != -EPROBE_DEFER)
+				dev_err(nandc->dev,
+					"rxtx DMA channel request failed: %d\n",
+					ret);
+			return ret;
 		}
 	}
 
-- 
Peter

Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki.
Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH 7/7] mtd: rawnand: stm32_fmc2: Use dma_request_chan() instead dma_request_slave_channel()
  2020-02-27 12:37 [PATCH 0/7] mtd: rawnand: Convert drivers to use dma_request_chan() Peter Ujfalusi
                   ` (5 preceding siblings ...)
  2020-02-27 12:37 ` [PATCH 6/7] mtd: rawnand: qcom: Use dma_request_chan() instead dma_request_slave_channel() Peter Ujfalusi
@ 2020-02-27 12:37 ` Peter Ujfalusi
  2020-03-10 18:30   ` Miquel Raynal
  6 siblings, 1 reply; 16+ messages in thread
From: Peter Ujfalusi @ 2020-02-27 12:37 UTC (permalink / raw)
  To: vigneshr, miquel.raynal, han.xu, richard, mripard, wens,
	mcoquelin.stm32, alexandre.torgue
  Cc: linux-mtd, linux-kernel, linux-arm-kernel, vkoul

dma_request_slave_channel() is a wrapper on top of dma_request_chan()
eating up the error code.

Use using dma_request_chan() directly and inform user of error in case the
DMA request failed.

Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>
---
 drivers/mtd/nand/raw/stm32_fmc2_nand.c | 44 ++++++++++++++++++++++----
 1 file changed, 37 insertions(+), 7 deletions(-)

diff --git a/drivers/mtd/nand/raw/stm32_fmc2_nand.c b/drivers/mtd/nand/raw/stm32_fmc2_nand.c
index 3ba73f18841f..b6d45cd911ae 100644
--- a/drivers/mtd/nand/raw/stm32_fmc2_nand.c
+++ b/drivers/mtd/nand/raw/stm32_fmc2_nand.c
@@ -1606,15 +1606,36 @@ static int stm32_fmc2_setup_interface(struct nand_chip *chip, int chipnr,
 /* DMA configuration */
 static int stm32_fmc2_dma_setup(struct stm32_fmc2_nfc *fmc2)
 {
-	int ret;
+	int ret = 0;
 
-	fmc2->dma_tx_ch = dma_request_slave_channel(fmc2->dev, "tx");
-	fmc2->dma_rx_ch = dma_request_slave_channel(fmc2->dev, "rx");
-	fmc2->dma_ecc_ch = dma_request_slave_channel(fmc2->dev, "ecc");
+	fmc2->dma_tx_ch = dma_request_chan(fmc2->dev, "tx");
+	if (IS_ERR(fmc2->dma_tx_ch)) {
+		ret = PTR_ERR(fmc2->dma_tx_ch);
+		if (ret != -ENODEV)
+			dev_err(fmc2->dev,
+				"failed to request tx DMA channel: %d\n", ret);
+		fmc2->dma_tx_ch = NULL;
+		goto err_dma;
+	}
 
-	if (!fmc2->dma_tx_ch || !fmc2->dma_rx_ch || !fmc2->dma_ecc_ch) {
-		dev_warn(fmc2->dev, "DMAs not defined in the device tree, polling mode is used\n");
-		return 0;
+	fmc2->dma_rx_ch = dma_request_chan(fmc2->dev, "rx");
+	if (IS_ERR(fmc2->dma_rx_ch)) {
+		ret = PTR_ERR(fmc2->dma_rx_ch);
+		if (ret != -ENODEV)
+			dev_err(fmc2->dev,
+				"failed to request rx DMA channel: %d\n", ret);
+		fmc2->dma_rx_ch = NULL;
+		goto err_dma;
+	}
+
+	fmc2->dma_ecc_ch = dma_request_chan(fmc2->dev, "ecc");
+	if (IS_ERR(fmc2->dma_ecc_ch)) {
+		ret = PTR_ERR(fmc2->dma_ecc_ch);
+		if (ret != -ENODEV)
+			dev_err(fmc2->dev,
+				"failed to request ecc DMA channel: %d\n", ret);
+		fmc2->dma_ecc_ch = NULL;
+		goto err_dma;
 	}
 
 	ret = sg_alloc_table(&fmc2->dma_ecc_sg, FMC2_MAX_SG, GFP_KERNEL);
@@ -1635,6 +1656,15 @@ static int stm32_fmc2_dma_setup(struct stm32_fmc2_nfc *fmc2)
 	init_completion(&fmc2->dma_ecc_complete);
 
 	return 0;
+
+err_dma:
+	if (ret == -ENODEV) {
+		dev_warn(fmc2->dev,
+			 "DMAs not defined in the DT, polling mode is used\n");
+		ret = 0;
+	}
+
+	return ret;
 }
 
 /* NAND callbacks setup */
-- 
Peter

Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki.
Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 4/7] mtd: rawnand: sunxi: Use dma_request_chan() instead dma_request_slave_channel()
  2020-02-27 12:37 ` [PATCH 4/7] mtd: rawnand: sunxi: " Peter Ujfalusi
@ 2020-03-09  9:58   ` Maxime Ripard
  2020-03-10 18:30   ` Miquel Raynal
  1 sibling, 0 replies; 16+ messages in thread
From: Maxime Ripard @ 2020-03-09  9:58 UTC (permalink / raw)
  To: Peter Ujfalusi
  Cc: vigneshr, miquel.raynal, han.xu, richard, wens, mcoquelin.stm32,
	alexandre.torgue, linux-mtd, linux-kernel, linux-arm-kernel,
	vkoul

[-- Attachment #1: Type: text/plain, Size: 380 bytes --]

On Thu, Feb 27, 2020 at 02:37:46PM +0200, Peter Ujfalusi wrote:
> dma_request_slave_channel() is a wrapper on top of dma_request_chan()
> eating up the error code.
>
> By using dma_request_chan() directly the driver can support deferred
> probing against DMA.
>
> Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>

Acked-by: Maxime Ripard <mripard@kernel.org>

Thanks!
Maxime

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 7/7] mtd: rawnand: stm32_fmc2: Use dma_request_chan() instead dma_request_slave_channel()
  2020-02-27 12:37 ` [PATCH 7/7] mtd: rawnand: stm32_fmc2: " Peter Ujfalusi
@ 2020-03-10 18:30   ` Miquel Raynal
  0 siblings, 0 replies; 16+ messages in thread
From: Miquel Raynal @ 2020-03-10 18:30 UTC (permalink / raw)
  To: Peter Ujfalusi, vigneshr, miquel.raynal, han.xu, richard,
	mripard, wens, mcoquelin.stm32, alexandre.torgue
  Cc: vkoul, linux-mtd, linux-kernel, linux-arm-kernel

On Thu, 2020-02-27 at 12:37:49 UTC, Peter Ujfalusi wrote:
> dma_request_slave_channel() is a wrapper on top of dma_request_chan()
> eating up the error code.
> 
> Use using dma_request_chan() directly and inform user of error in case the
> DMA request failed.
> 
> Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>

Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git nand/next, thanks.

Miquel

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 6/7] mtd: rawnand: qcom: Use dma_request_chan() instead dma_request_slave_channel()
  2020-02-27 12:37 ` [PATCH 6/7] mtd: rawnand: qcom: Use dma_request_chan() instead dma_request_slave_channel() Peter Ujfalusi
@ 2020-03-10 18:30   ` Miquel Raynal
  0 siblings, 0 replies; 16+ messages in thread
From: Miquel Raynal @ 2020-03-10 18:30 UTC (permalink / raw)
  To: Peter Ujfalusi, vigneshr, miquel.raynal, han.xu, richard,
	mripard, wens, mcoquelin.stm32, alexandre.torgue
  Cc: vkoul, linux-mtd, linux-kernel, linux-arm-kernel

On Thu, 2020-02-27 at 12:37:48 UTC, Peter Ujfalusi wrote:
> dma_request_slave_channel() is a wrapper on top of dma_request_chan()
> eating up the error code.
> 
> Use using dma_request_chan() directly to return the real error code.
> 
> Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>

Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git nand/next, thanks.

Miquel

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 5/7] mtd: rawnand: qcom: Release resources on failure within qcom_nandc_alloc()
  2020-02-27 12:37 ` [PATCH 5/7] mtd: rawnand: qcom: Release resources on failure within qcom_nandc_alloc() Peter Ujfalusi
@ 2020-03-10 18:30   ` Miquel Raynal
  0 siblings, 0 replies; 16+ messages in thread
From: Miquel Raynal @ 2020-03-10 18:30 UTC (permalink / raw)
  To: Peter Ujfalusi, vigneshr, miquel.raynal, han.xu, richard,
	mripard, wens, mcoquelin.stm32, alexandre.torgue
  Cc: vkoul, linux-mtd, linux-kernel, linux-arm-kernel

On Thu, 2020-02-27 at 12:37:47 UTC, Peter Ujfalusi wrote:
> In case when DMA channel request or alloc_bam_transaction() fails,
> dma_unmap_single() and any channels already requested should be released.
> 
> Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>

Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git nand/next, thanks.

Miquel

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 4/7] mtd: rawnand: sunxi: Use dma_request_chan() instead dma_request_slave_channel()
  2020-02-27 12:37 ` [PATCH 4/7] mtd: rawnand: sunxi: " Peter Ujfalusi
  2020-03-09  9:58   ` Maxime Ripard
@ 2020-03-10 18:30   ` Miquel Raynal
  1 sibling, 0 replies; 16+ messages in thread
From: Miquel Raynal @ 2020-03-10 18:30 UTC (permalink / raw)
  To: Peter Ujfalusi, vigneshr, miquel.raynal, han.xu, richard,
	mripard, wens, mcoquelin.stm32, alexandre.torgue
  Cc: vkoul, linux-mtd, linux-kernel, linux-arm-kernel

On Thu, 2020-02-27 at 12:37:46 UTC, Peter Ujfalusi wrote:
> dma_request_slave_channel() is a wrapper on top of dma_request_chan()
> eating up the error code.
> 
> By using dma_request_chan() directly the driver can support deferred
> probing against DMA.
> 
> Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>
> Acked-by: Maxime Ripard <mripard@kernel.org>

Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git nand/next, thanks.

Miquel

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 3/7] mtd: rawnand: marvell: Use dma_request_chan() instead dma_request_slave_channel()
  2020-02-27 12:37 ` [PATCH 3/7] mtd: rawnand: marvell: Use dma_request_chan() instead dma_request_slave_channel() Peter Ujfalusi
@ 2020-03-10 18:30   ` Miquel Raynal
  0 siblings, 0 replies; 16+ messages in thread
From: Miquel Raynal @ 2020-03-10 18:30 UTC (permalink / raw)
  To: Peter Ujfalusi, vigneshr, miquel.raynal, han.xu, richard,
	mripard, wens, mcoquelin.stm32, alexandre.torgue
  Cc: vkoul, linux-mtd, linux-kernel, linux-arm-kernel

On Thu, 2020-02-27 at 12:37:45 UTC, Peter Ujfalusi wrote:
> dma_request_slave_channel() is a wrapper on top of dma_request_chan()
> eating up the error code.
> 
> Use using dma_request_chan() directly to return the real error code.
> 
> Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>

Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git nand/next, thanks.

Miquel

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 2/7] mtd: rawnand: marvell: Release DMA channel on error
  2020-02-27 12:37 ` [PATCH 2/7] mtd: rawnand: marvell: Release DMA channel on error Peter Ujfalusi
@ 2020-03-10 18:30   ` Miquel Raynal
  0 siblings, 0 replies; 16+ messages in thread
From: Miquel Raynal @ 2020-03-10 18:30 UTC (permalink / raw)
  To: Peter Ujfalusi, vigneshr, miquel.raynal, han.xu, richard,
	mripard, wens, mcoquelin.stm32, alexandre.torgue
  Cc: vkoul, linux-mtd, linux-kernel, linux-arm-kernel

On Thu, 2020-02-27 at 12:37:44 UTC, Peter Ujfalusi wrote:
> Release the DMA channel on errors after the channel has been successfully
> requested.
> 
> Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>

Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git nand/next, thanks.

Miquel

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 1/7] mtd: rawnand: gpmi: Use dma_request_chan() instead dma_request_slave_channel()
  2020-02-27 12:37 ` [PATCH 1/7] mtd: rawnand: gpmi: Use dma_request_chan() instead dma_request_slave_channel() Peter Ujfalusi
@ 2020-03-10 18:31   ` Miquel Raynal
  0 siblings, 0 replies; 16+ messages in thread
From: Miquel Raynal @ 2020-03-10 18:31 UTC (permalink / raw)
  To: Peter Ujfalusi, vigneshr, miquel.raynal, han.xu, richard,
	mripard, wens, mcoquelin.stm32, alexandre.torgue
  Cc: vkoul, linux-mtd, linux-kernel, linux-arm-kernel

On Thu, 2020-02-27 at 12:37:43 UTC, Peter Ujfalusi wrote:
> dma_request_slave_channel() is a wrapper on top of dma_request_chan()
> eating up the error code.
> 
> Use using dma_request_chan() directly to return the real error code.
> 
> Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>

Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git nand/next, thanks.

Miquel

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2020-03-10 18:31 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-27 12:37 [PATCH 0/7] mtd: rawnand: Convert drivers to use dma_request_chan() Peter Ujfalusi
2020-02-27 12:37 ` [PATCH 1/7] mtd: rawnand: gpmi: Use dma_request_chan() instead dma_request_slave_channel() Peter Ujfalusi
2020-03-10 18:31   ` Miquel Raynal
2020-02-27 12:37 ` [PATCH 2/7] mtd: rawnand: marvell: Release DMA channel on error Peter Ujfalusi
2020-03-10 18:30   ` Miquel Raynal
2020-02-27 12:37 ` [PATCH 3/7] mtd: rawnand: marvell: Use dma_request_chan() instead dma_request_slave_channel() Peter Ujfalusi
2020-03-10 18:30   ` Miquel Raynal
2020-02-27 12:37 ` [PATCH 4/7] mtd: rawnand: sunxi: " Peter Ujfalusi
2020-03-09  9:58   ` Maxime Ripard
2020-03-10 18:30   ` Miquel Raynal
2020-02-27 12:37 ` [PATCH 5/7] mtd: rawnand: qcom: Release resources on failure within qcom_nandc_alloc() Peter Ujfalusi
2020-03-10 18:30   ` Miquel Raynal
2020-02-27 12:37 ` [PATCH 6/7] mtd: rawnand: qcom: Use dma_request_chan() instead dma_request_slave_channel() Peter Ujfalusi
2020-03-10 18:30   ` Miquel Raynal
2020-02-27 12:37 ` [PATCH 7/7] mtd: rawnand: stm32_fmc2: " Peter Ujfalusi
2020-03-10 18:30   ` Miquel Raynal

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).