mmc: sdhi: Convert from tasklet to BH workqueue
authorAllen Pais <allen.lkml@gmail.com>
Wed, 26 Jun 2024 08:48:21 +0000 (10:48 +0200)
committerUlf Hansson <ulf.hansson@linaro.org>
Mon, 8 Jul 2024 09:35:18 +0000 (11:35 +0200)
The only generic interface to execute asynchronously in the BH context is
tasklet; however, it's marked deprecated and has some design flaws. To
replace tasklets, BH workqueue support was recently added. A BH workqueue
behaves similarly to regular workqueues except that the queued work items
are executed in the BH context.

This patch converts the SDHI driver from tasklet to BH workqueue.

Based on the work done by Tejun Heo <tj@kernel.org>

Signed-off-by: Allen Pais <allen.lkml@gmail.com>
[wsa: fixed build faliures, corrected whitespace issues]
Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
Tested-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
Link: https://lore.kernel.org/r/20240626085015.32171-2-wsa+renesas@sang-engineering.com
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
drivers/mmc/host/renesas_sdhi.h
drivers/mmc/host/renesas_sdhi_core.c
drivers/mmc/host/renesas_sdhi_internal_dmac.c
drivers/mmc/host/renesas_sdhi_sys_dmac.c
drivers/mmc/host/tmio_mmc.h
drivers/mmc/host/tmio_mmc_core.c

index 586f94d4dbfddd7d54f45d1a59d47f95b4dc10ce..f12a87442338ab81fbf3ba1669a8eac1e1385692 100644 (file)
@@ -11,6 +11,7 @@
 
 #include <linux/dmaengine.h>
 #include <linux/platform_device.h>
+#include <linux/workqueue.h>
 #include "tmio_mmc.h"
 
 struct renesas_sdhi_scc {
@@ -67,7 +68,7 @@ struct renesas_sdhi_dma {
        dma_filter_fn filter;
        void (*enable)(struct tmio_mmc_host *host, bool enable);
        struct completion dma_dataend;
-       struct tasklet_struct dma_complete;
+       struct work_struct dma_complete;
 };
 
 struct renesas_sdhi {
@@ -93,6 +94,7 @@ struct renesas_sdhi {
        unsigned int tap_set;
 
        struct reset_control *rstc;
+       struct tmio_mmc_host *host;
 };
 
 #define host_to_priv(host) \
index 58536626e6c52556e83e8388d2a07cc4a9472623..04874791541fec27fc19aa3d993591a82bd36b65 100644 (file)
@@ -970,6 +970,8 @@ int renesas_sdhi_probe(struct platform_device *pdev,
        if (IS_ERR(host))
                return PTR_ERR(host);
 
+       priv->host = host;
+
        if (of_data) {
                mmc_data->flags |= of_data->tmio_flags;
                mmc_data->ocr_mask = of_data->tmio_ocr_mask;
index 422fa63a2e99abd3e81e3b69320be62baa0a37ca..d4b66daeda6654f15e773f3f2529e13455f53fa8 100644 (file)
@@ -337,7 +337,7 @@ static bool renesas_sdhi_internal_dmac_dma_irq(struct tmio_mmc_host *host)
                writel(status ^ dma_irqs, host->ctl + DM_CM_INFO1);
                set_bit(SDHI_DMA_END_FLAG_DMA, &dma_priv->end_flags);
                if (test_bit(SDHI_DMA_END_FLAG_ACCESS, &dma_priv->end_flags))
-                       tasklet_schedule(&dma_priv->dma_complete);
+                       queue_work(system_bh_wq, &dma_priv->dma_complete);
        }
 
        return status & dma_irqs;
@@ -352,7 +352,7 @@ renesas_sdhi_internal_dmac_dataend_dma(struct tmio_mmc_host *host)
        set_bit(SDHI_DMA_END_FLAG_ACCESS, &dma_priv->end_flags);
        if (test_bit(SDHI_DMA_END_FLAG_DMA, &dma_priv->end_flags) ||
            host->data->error)
-               tasklet_schedule(&dma_priv->dma_complete);
+               queue_work(system_bh_wq, &dma_priv->dma_complete);
 }
 
 /*
@@ -440,9 +440,9 @@ force_pio:
        renesas_sdhi_internal_dmac_enable_dma(host, false);
 }
 
-static void renesas_sdhi_internal_dmac_issue_tasklet_fn(unsigned long arg)
+static void renesas_sdhi_internal_dmac_issue_work_fn(struct work_struct *work)
 {
-       struct tmio_mmc_host *host = (struct tmio_mmc_host *)arg;
+       struct tmio_mmc_host *host = from_work(host, work, dma_issue);
        struct renesas_sdhi *priv = host_to_priv(host);
 
        tmio_mmc_enable_mmc_irqs(host, TMIO_STAT_DATAEND);
@@ -454,7 +454,7 @@ static void renesas_sdhi_internal_dmac_issue_tasklet_fn(unsigned long arg)
                /* on CMD errors, simulate DMA end immediately */
                set_bit(SDHI_DMA_END_FLAG_DMA, &priv->dma_priv.end_flags);
                if (test_bit(SDHI_DMA_END_FLAG_ACCESS, &priv->dma_priv.end_flags))
-                       tasklet_schedule(&priv->dma_priv.dma_complete);
+                       queue_work(system_bh_wq, &priv->dma_priv.dma_complete);
        }
 }
 
@@ -484,9 +484,11 @@ static bool renesas_sdhi_internal_dmac_complete(struct tmio_mmc_host *host)
        return true;
 }
 
-static void renesas_sdhi_internal_dmac_complete_tasklet_fn(unsigned long arg)
+static void renesas_sdhi_internal_dmac_complete_work_fn(struct work_struct *work)
 {
-       struct tmio_mmc_host *host = (struct tmio_mmc_host *)arg;
+       struct renesas_sdhi_dma *dma_priv = from_work(dma_priv, work, dma_complete);
+       struct renesas_sdhi *priv = container_of(dma_priv, typeof(*priv), dma_priv);
+       struct tmio_mmc_host *host = priv->host;
 
        spin_lock_irq(&host->lock);
        if (!renesas_sdhi_internal_dmac_complete(host))
@@ -544,12 +546,10 @@ renesas_sdhi_internal_dmac_request_dma(struct tmio_mmc_host *host,
        /* Each value is set to non-zero to assume "enabling" each DMA */
        host->chan_rx = host->chan_tx = (void *)0xdeadbeaf;
 
-       tasklet_init(&priv->dma_priv.dma_complete,
-                    renesas_sdhi_internal_dmac_complete_tasklet_fn,
-                    (unsigned long)host);
-       tasklet_init(&host->dma_issue,
-                    renesas_sdhi_internal_dmac_issue_tasklet_fn,
-                    (unsigned long)host);
+       INIT_WORK(&priv->dma_priv.dma_complete,
+                 renesas_sdhi_internal_dmac_complete_work_fn);
+       INIT_WORK(&host->dma_issue,
+                 renesas_sdhi_internal_dmac_issue_work_fn);
 
        /* Add pre_req and post_req */
        host->ops.pre_req = renesas_sdhi_internal_dmac_pre_req;
index 9cf7f9feab72f12b14382017e982b419bac93b05..5a6f413186455ea6f3a619d68a8071e55980a815 100644 (file)
@@ -312,9 +312,9 @@ static void renesas_sdhi_sys_dmac_start_dma(struct tmio_mmc_host *host,
        }
 }
 
-static void renesas_sdhi_sys_dmac_issue_tasklet_fn(unsigned long priv)
+static void renesas_sdhi_sys_dmac_issue_work_fn(struct work_struct *work)
 {
-       struct tmio_mmc_host *host = (struct tmio_mmc_host *)priv;
+       struct tmio_mmc_host *host = from_work(host, work, dma_issue);
        struct dma_chan *chan = NULL;
 
        spin_lock_irq(&host->lock);
@@ -401,9 +401,8 @@ static void renesas_sdhi_sys_dmac_request_dma(struct tmio_mmc_host *host,
                        goto ebouncebuf;
 
                init_completion(&priv->dma_priv.dma_dataend);
-               tasklet_init(&host->dma_issue,
-                            renesas_sdhi_sys_dmac_issue_tasklet_fn,
-                            (unsigned long)host);
+               INIT_WORK(&host->dma_issue,
+                         renesas_sdhi_sys_dmac_issue_work_fn);
        }
 
        renesas_sdhi_sys_dmac_enable_dma(host, true);
index 2af5730c21f4a98df132e229b36d8c0cabe813a6..a75755f31d3195f5a4a28bbc5e247741bc97ad87 100644 (file)
@@ -21,6 +21,7 @@
 #include <linux/scatterlist.h>
 #include <linux/spinlock.h>
 #include <linux/interrupt.h>
+#include <linux/workqueue.h>
 
 #define CTL_SD_CMD 0x00
 #define CTL_ARG_REG 0x04
@@ -153,7 +154,7 @@ struct tmio_mmc_host {
        bool                    dma_on;
        struct dma_chan         *chan_rx;
        struct dma_chan         *chan_tx;
-       struct tasklet_struct   dma_issue;
+       struct work_struct      dma_issue;
        struct scatterlist      bounce_sg;
        u8                      *bounce_buf;
 
index 2780f0a2987140f3ca253ee1729ce9d38fc155d1..b61a6310311da31fd58fc789c77b276a105a4675 100644 (file)
@@ -608,7 +608,7 @@ static void tmio_mmc_cmd_irq(struct tmio_mmc_host *host, unsigned int stat)
                        } else {
                                tmio_mmc_disable_mmc_irqs(host,
                                                          TMIO_MASK_READOP);
-                               tasklet_schedule(&host->dma_issue);
+                               queue_work(system_bh_wq, &host->dma_issue);
                        }
                } else {
                        if (!host->dma_on) {
@@ -616,7 +616,7 @@ static void tmio_mmc_cmd_irq(struct tmio_mmc_host *host, unsigned int stat)
                        } else {
                                tmio_mmc_disable_mmc_irqs(host,
                                                          TMIO_MASK_WRITEOP);
-                               tasklet_schedule(&host->dma_issue);
+                               queue_work(system_bh_wq, &host->dma_issue);
                        }
                }
        } else {