mtd: rawnand: Convert drivers to use dma_request_chan()
Subsystems (7)
cover mtd: rawnand: Convert drivers to use dma_request_chan()
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(-)
Signature · 4 lines
Peter Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki
PATCH 1/7 mtd: rawnand: gpmi: Use dma_request_chan() instead dma_request_slave_channel()
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.
--- drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-)
drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c +11 -10
@@ -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)
Signature · 4 lines
Peter Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki
Re: [PATCH 1/7] mtd: rawnand: gpmi: Use dma_request_chan() instead dma_request_slave_channel()
Quoted 6 lines · Peter Ujfalusi
dma_request_slave_channel()is a wrapper on top ofdma_request_chan()eating up the error code.Use using
dma_request_chan()directly to return the real error code.Signed-off-by Peter Ujfalusi <[email protected]>
Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git nand/next, thanks.
Miquel
PATCH 2/7 mtd: rawnand: marvell: Release DMA channel on error
In reply to Peter UjfalusiRelease the DMA channel on errors after the channel has been successfully requested.
--- drivers/mtd/nand/raw/marvell_nand.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-)
drivers/mtd/nand/raw/marvell_nand.c +19 -6
@@ -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:
Signature · 10 lines
Peter Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [PATCH 2/7] mtd: rawnand: marvell: Release DMA channel on error
Quoted 4 lines · Peter Ujfalusi
Release the DMA channel on errors after the channel has been successfully requested.
Signed-off-by Peter Ujfalusi <[email protected]>
Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git nand/next, thanks.
Miquel
PATCH 3/7 mtd: rawnand: marvell: Use dma_request_chan() instead dma_request_slave_channel()
In reply to Peter Ujfalusidma_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.
--- drivers/mtd/nand/raw/marvell_nand.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)
drivers/mtd/nand/raw/marvell_nand.c +8 -5
@@ -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 );
Signature · 4 lines
Peter Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki
Re: [PATCH 3/7] mtd: rawnand: marvell: Use dma_request_chan() instead dma_request_slave_channel()
Quoted 6 lines · Peter Ujfalusi
dma_request_slave_channel()is a wrapper on top ofdma_request_chan()eating up the error code.Use using
dma_request_chan()directly to return the real error code.Signed-off-by Peter Ujfalusi <[email protected]>
Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git nand/next, thanks.
Miquel
PATCH 4/7 mtd: rawnand: sunxi: Use dma_request_chan() instead dma_request_slave_channel()
In reply to Peter Ujfalusidma_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.
--- drivers/mtd/nand/raw/sunxi_nand.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)
drivers/mtd/nand/raw/sunxi_nand.c +10 -5
@@ -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);
Signature · 4 lines
Peter Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki
Re: [PATCH 4/7] mtd: rawnand: sunxi: Use dma_request_chan() instead dma_request_slave_channel()
Quoted 7 lines · Peter Ujfalusi
dma_request_slave_channel()is a wrapper on top ofdma_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 <[email protected]>
Thanks!
Maxime
Re: [PATCH 4/7] mtd: rawnand: sunxi: Use dma_request_chan() instead dma_request_slave_channel()
In reply to Peter UjfalusiQuoted 8 lines · Peter Ujfalusi
dma_request_slave_channel()is a wrapper on top ofdma_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 <[email protected]>Acked-by Maxime Ripard <[email protected]>
Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git nand/next, thanks.
Miquel
PATCH 5/7 mtd: rawnand: qcom: Release resources on failure within qcom_nandc_alloc()
In reply to Peter UjfalusiIn case when DMA channel request or alloc_bam_transaction() fails, dma_unmap_single() and any channels already requested should be released.
--- drivers/mtd/nand/raw/qcom_nandc.c | 61 +++++++++++++++++-------------- 1 file changed, 34 insertions(+), 27 deletions(-)
drivers/mtd/nand/raw/qcom_nandc.c +34 -27
@@ -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 */
Signature · 4 lines
Peter Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki
Re: [PATCH 5/7] mtd: rawnand: qcom: Release resources on failure within qcom_nandc_alloc()
Quoted 4 lines · Peter Ujfalusi
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 <[email protected]>
Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git nand/next, thanks.
Miquel
PATCH 6/7 mtd: rawnand: qcom: Use dma_request_chan() instead dma_request_slave_channel()
In reply to Peter Ujfalusidma_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.
--- drivers/mtd/nand/raw/qcom_nandc.c | 50 ++++++++++++++++++++----------- 1 file changed, 33 insertions(+), 17 deletions(-)
drivers/mtd/nand/raw/qcom_nandc.c +33 -17
@@ -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; } }
Signature · 4 lines
Peter Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki
Re: [PATCH 6/7] mtd: rawnand: qcom: Use dma_request_chan() instead dma_request_slave_channel()
Quoted 6 lines · Peter Ujfalusi
dma_request_slave_channel()is a wrapper on top ofdma_request_chan()eating up the error code.Use using
dma_request_chan()directly to return the real error code.Signed-off-by Peter Ujfalusi <[email protected]>
Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git nand/next, thanks.
Miquel
PATCH 7/7 mtd: rawnand: stm32_fmc2: Use dma_request_chan() instead dma_request_slave_channel()
In reply to Peter Ujfalusidma_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.
--- drivers/mtd/nand/raw/stm32_fmc2_nand.c | 44 ++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 7 deletions(-)
drivers/mtd/nand/raw/stm32_fmc2_nand.c +37 -7
@@ -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 */
Signature · 4 lines
Peter Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki
Re: [PATCH 7/7] mtd: rawnand: stm32_fmc2: Use dma_request_chan() instead dma_request_slave_channel()
Quoted 7 lines · Peter Ujfalusi
dma_request_slave_channel()is a wrapper on top ofdma_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 <[email protected]>
Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git nand/next, thanks.
Miquel