mmc: Assorted bug fixes across MMC host drivers
Subsystems (14)
cover mmc: Assorted bug fixes across MMC host drivers
These issues were reported by Sashiko.
None of these changes have been tested on physical hardware.
Lee Jones (13):
mmc: cavium: Remove MMC slots before destroying slot platform devices
mmc: cavium: Prevent slot_pdev[] out-of-bounds write during probe
mmc: sdhci-msm: Resume runtime PM before accessing registers on remove
mmc: meson-gx: Fail request when descriptor chain DMA mapping fails
mmc: jz4740: Skip DMA cleanup in PIO mode during post_req
mmc: renesas_sdhi: Guard host->cmd access in internal DMAC issue work
mmc: tifm_sd: Synchronise timeout handler with request completion
mmc: omap: Shut down cover timer before disabling cover BH work
mmc: renesas_sdhi: Disable internal DMAC BH work items on release
mmc: jz4740: Apply DMA max_seg_size limit to unified tx-rx channel
mmc: dw_mmc: Disarm central watchdog when ending a request
mmc: renesas_sdhi: Fix SDIO manual tap correction in SDR104 mode
mmc: sdhci-brcmstb: Handle absent optional sdio_freq clock in probe
drivers/mmc/host/cavium-octeon.c | 17 +++++++++++++---- drivers/mmc/host/cavium-thunderx.c | 15 +++++++++++++-- drivers/mmc/host/dw_mmc.c | 14 +++++++++++--- drivers/mmc/host/jz4740_mmc.c | 6 +++++- drivers/mmc/host/meson-gx-mmc.c | 7 +++++++ drivers/mmc/host/omap.c | 8 ++++---- drivers/mmc/host/renesas_sdhi_core.c | 9 ++++----- drivers/mmc/host/renesas_sdhi_internal_dmac.c | 13 +++++++++++++ drivers/mmc/host/sdhci-brcmstb.c | 6 ++++-- drivers/mmc/host/sdhci-msm.c | 8 ++++---- drivers/mmc/host/tifm_sd.c | 16 ++++++++++++++-- 11 files changed, 92 insertions(+), 27 deletions(-)
Signature · 1 line
2.56.1.750.gf70dc682cf-goog
PATCH 1/13 mmc: cavium: Remove MMC slots before destroying slot platform devices
cvm_mmc_of_slot_probe() allocates each slot and its struct mmc_host via devm_mmc_alloc_host() bound to the dummy slot platform device created in octeon_mmc_probe() and thunder_mmc_probe(), and indexes host->slot[] by the Device Tree reg property while host->slot_pdev[] is indexed by the child iteration counter.
When a slot reg index is greater than its child iteration index (for example when only slot 1 is populated or enabled), the single teardown loop in probe error handling and driver removal calls of_platform_device_destroy() on the slot platform device before calling cvm_mmc_of_slot_remove() on its corresponding host->slot[] entry. Unregistering the unbound platform device immediately releases its managed resources, freeing slot regulators and dropping the initial struct mmc_host reference via mmc_free_host() while the MMC host is still registered. The subsequent cvm_mmc_of_slot_remove() call then accesses freed regulator state and frees struct mmc_host and private slot memory mid-way through mmc_remove_host(), resulting in a use-after-free.
Remove all populated MMC slots in a first pass before destroying the child slot platform devices in a second pass across both probe error and driver removal paths.
--- drivers/mmc/host/cavium-octeon.c | 4 ++++ drivers/mmc/host/cavium-thunderx.c | 4 ++++ 2 files changed, 8 insertions(+)
drivers/mmc/host/cavium-octeon.c +4 -0
@@ -283,6 +283,8 @@ static int octeon_mmc_probe(struct platform_device *pdev)for (i =0 ; i <CAVIUM_MAX_MMC ; i++) {if (host->slot[i])cvm_mmc_of_slot_remove (host->slot[i]); + } +for (i =0 ; i <CAVIUM_MAX_MMC ; i++) {if (host->slot_pdev[i])of_platform_device_destroy (&host->slot_pdev[i]->dev,NULL ); }
@@ -298,6 +300,8 @@ static void octeon_mmc_remove(struct platform_device *pdev)for (i =0 ; i <CAVIUM_MAX_MMC ; i++) {if (host->slot[i])cvm_mmc_of_slot_remove (host->slot[i]); + } +for (i =0 ; i <CAVIUM_MAX_MMC ; i++) {if (host->slot_pdev[i])of_platform_device_destroy (&host->slot_pdev[i]->dev,NULL ); }
drivers/mmc/host/cavium-thunderx.c +4 -0
@@ -157,6 +157,8 @@ static int thunder_mmc_probe(struct pci_dev *pdev,for (i =0 ; i <CAVIUM_MAX_MMC ; i++) {if (host->slot[i])cvm_mmc_of_slot_remove (host->slot[i]); + } +for (i =0 ; i <CAVIUM_MAX_MMC ; i++) {if (host->slot_pdev[i])of_platform_device_destroy (&host->slot_pdev[i]->dev,NULL ); }
@@ -173,6 +175,8 @@ static void thunder_mmc_remove(struct pci_dev *pdev)for (i =0 ; i <CAVIUM_MAX_MMC ; i++) {if (host->slot[i])cvm_mmc_of_slot_remove (host->slot[i]); + } +for (i =0 ; i <CAVIUM_MAX_MMC ; i++) {if (host->slot_pdev[i])of_platform_device_destroy (&host->slot_pdev[i]->dev,NULL ); }
Signature · 1 line
2.56.1.750.gf70dc682cf-goog
PATCH 2/13 mmc: cavium: Prevent slot_pdev[] out-of-bounds write during probe
In reply to Lee Jonesocteon_mmc_probe() and thunder_mmc_probe() iterate over Device Tree child nodes and store each created slot platform device in host->slot_pdev[i], which is sized to CAVIUM_MAX_MMC (4). Neither function checks that i remains below CAVIUM_MAX_MMC before writing to host->slot_pdev[i], and both increment i even for disabled or non-mmc-slot child nodes. When a controller node has more than four child nodes (or four valid mmc-slot nodes alongside another child node on ThunderX), host->slot_pdev[i] writes past the end of the array and corrupts the adjacent set_shared_power and acquire_bus callback pointers in struct cvm_mmc_host.
Iterate only over available child nodes, advance the slot_pdev[] index only when a slot platform device is created, and fail the probe with -EINVAL if more than CAVIUM_MAX_MMC slots are present.
--- drivers/mmc/host/cavium-octeon.c | 13 +++++++++---- drivers/mmc/host/cavium-thunderx.c | 11 +++++++++-- 2 files changed, 18 insertions(+), 6 deletions(-)
drivers/mmc/host/cavium-octeon.c +9 -4
@@ -262,13 +262,18 @@ static int octeon_mmc_probe(struct platform_device *pdev)platform_set_drvdata (pdev, host); i =0 ; -for_each_child_of_node_scoped (node, cn) { +for_each_available_child_of_node_scoped (node, cn) { +if (i >=CAVIUM_MAX_MMC ) { +dev_err (&pdev->dev,"Too many slots\n" ); + ret = -EINVAL ; +octeon_mmc_set_shared_power (host,0 ); + goto error; + } host->slot_pdev[i] =of_platform_device_create (cn,NULL , &pdev->dev); -if (!host->slot_pdev[i]) { - i++; +if (!host->slot_pdev[i])continue ; - } + ret =cvm_mmc_of_slot_probe (&host->slot_pdev[i]->dev, host);if (ret) {dev_err (&pdev->dev,"Error populating slots\n" );
drivers/mmc/host/cavium-thunderx.c +9 -2
@@ -129,7 +129,7 @@ static int thunder_mmc_probe(struct pci_dev *pdev,if (ret) goto error; -for_each_child_of_node (node, child_node) { +for_each_available_child_of_node (node, child_node) {/* * mmc_of_parse and devm* require one device per slot. * Create a dummy device per slot and set the node pointer to
@@ -137,6 +137,13 @@ static int thunder_mmc_probe(struct pci_dev *pdev,* of_platform_device_create. */ if (of_device_is_compatible (child_node,"mmc-slot" )) { +if (i >=CAVIUM_MAX_MMC ) { +dev_err (dev,"Too many slots\n" ); +of_node_put (child_node); + ret = -EINVAL ; + goto error; + } + host->slot_pdev[i] =of_platform_device_create (child_node,NULL , &pdev->dev);if (!host->slot_pdev[i])
@@ -147,8 +154,8 @@ static int thunder_mmc_probe(struct pci_dev *pdev,of_node_put (child_node); goto error; } + i++; } - i++; }dev_info (dev,"probed\n" );return 0 ;
Signature · 1 line
2.56.1.750.gf70dc682cf-goog
PATCH 3/13 mmc: sdhci-msm: Resume runtime PM before accessing registers on remove
In reply to Lee JonesDuring driver unbind, __device_release_driver() drops its temporary runtime PM reference via pm_runtime_put_sync() immediately before invoking sdhci_msm_remove(). If the 50 ms autosuspend delay has already elapsed, sdhci_msm_runtime_suspend() gates msm_host->bulk_clks before sdhci_msm_remove() is entered.
sdhci_msm_remove() currently reads SDHCI_INT_STATUS and calls sdhci_remove_host() before waking the device via pm_runtime_get_sync(), performing MMIO accesses while the controller interface and core clocks are disabled and triggering a synchronous external abort on Qualcomm platforms.
Wake the device with pm_runtime_get_sync() and disable runtime PM prior to reading SDHCI_INT_STATUS and calling sdhci_remove_host(), matching other SDHCI platform drivers.
--- drivers/mmc/host/sdhci-msm.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/mmc/host/sdhci-msm.c +4 -4
@@ -2925,15 +2925,15 @@ static void sdhci_msm_remove(struct platform_device *pdev)struct sdhci_host *host =platform_get_drvdata (pdev);struct sdhci_pltfm_host *pltfm_host =sdhci_priv (host);struct sdhci_msm_host *msm_host =sdhci_pltfm_priv (pltfm_host); -int dead = (readl_relaxed (host->ioaddr +SDHCI_INT_STATUS ) == -0xffffffff ); - -sdhci_remove_host (host, dead); +int dead;pm_runtime_get_sync (&pdev->dev);pm_runtime_disable (&pdev->dev);pm_runtime_put_noidle (&pdev->dev); + dead = (readl_relaxed (host->ioaddr +SDHCI_INT_STATUS ) ==0xffffffff ); +sdhci_remove_host (host, dead); +clk_bulk_disable_unprepare (ARRAY_SIZE (msm_host->bulk_clks), msm_host->bulk_clks);if (!IS_ERR (msm_host->bus_clk))
Signature · 1 line
2.56.1.750.gf70dc682cf-goog
PATCH 4/13 mmc: meson-gx: Fail request when descriptor chain DMA mapping fails
In reply to Lee Jonesmeson_mmc_pre_req() flags eligible transfers with SD_EMMC_DESC_CHAIN_MODE before mapping the scatterlist with dma_map_sg(). If dma_map_sg() fails and returns 0, meson_mmc_pre_req() logs an error but leaves SD_EMMC_DESC_CHAIN_MODE set with data->sg_count equal to 0. When meson_mmc_request() subsequently dispatches the transfer to meson_mmc_desc_chain_transfer(), the for_each_sg() loop executes zero iterations and desc[data->sg_count - 1].cmd_cfg writes to desc[-1], corrupting memory immediately preceding the coherent descriptor buffer before starting the DMA engine.
Check that data->sg_count is non-zero before starting a descriptor chain request in meson_mmc_request() and complete the request with -EINVAL if mapping failed.
--- drivers/mmc/host/meson-gx-mmc.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/mmc/host/meson-gx-mmc.c +7 -0
@@ -914,6 +914,13 @@ static void meson_mmc_request(struct mmc_host *mmc, struct mmc_request *mrq)if (host->needs_pre_post_req)meson_mmc_pre_req (mmc, mrq); +if (mrq->data &&meson_mmc_desc_chain_mode (mrq->data) && + !mrq->data->sg_count) { + mrq->cmd->error = -EINVAL ; +mmc_request_done (mmc, mrq); +return ; + } +/* Stop execution */ writel (0 , host->regs +SD_EMMC_START );
Signature · 1 line
2.56.1.750.gf70dc682cf-goog
PATCH 5/13 mmc: jz4740: Skip DMA cleanup in PIO mode during post_req
In reply to Lee JonesWhen DMA channel acquisition fails during probe, the JZ4740 MMC driver falls back to PIO mode with host->use_dma set to false and host->dma_tx or host->dma_rx left holding an ERR_PTR() or released channel pointer. Unlike jz4740_mmc_pre_request(), jz4740_mmc_post_request() does not check host->use_dma before calling dmaengine_terminate_all() on error, resulting in an invalid or dangling DMA channel pointer dereference whenever a PIO data transfer encounters an error.
Return early from jz4740_mmc_post_request() when host->use_dma is false, matching jz4740_mmc_pre_request().
--- drivers/mmc/host/jz4740_mmc.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/mmc/host/jz4740_mmc.c +3 -0
@@ -392,6 +392,9 @@ static void jz4740_mmc_post_request(struct mmc_host *mmc,struct jz4740_mmc_host *host =mmc_priv (mmc);struct mmc_data *data = mrq->data; +if (!host->use_dma) +return ; +if (data && data->host_cookie !=COOKIE_UNMAPPED )jz4740_mmc_dma_unmap (host, data);
Signature · 1 line
2.56.1.750.gf70dc682cf-goog
PATCH 6/13 mmc: renesas_sdhi: Guard host->cmd access in internal DMAC issue work
In reply to Lee Jonesrenesas_sdhi_internal_dmac_issue_work_fn() unmasks TMIO_STAT_DATAEND and dereferences host->cmd without holding host->lock or checking that host->cmd is still non-NULL. If tmio_mmc_reset_work() times out and clears host->cmd under host->lock after tmio_mmc_cmd_irq() queues host->dma_issue, or if unmasking TMIO_STAT_DATAEND allows a concurrent data-end error completion to clear host->cmd via tmio_mmc_finish_request(), evaluating host->cmd->error triggers a NULL pointer dereference. Unmasking TMIO_STAT_DATAEND outside host->lock also races with concurrent updates to host->sdcard_irq_mask.
Acquire host->lock across renesas_sdhi_internal_dmac_issue_work_fn() and bail out if host->cmd has already been cleared, matching the sibling system DMAC implementation.
--- drivers/mmc/host/renesas_sdhi_internal_dmac.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/mmc/host/renesas_sdhi_internal_dmac.c +8 -0
@@ -450,6 +450,13 @@ static void renesas_sdhi_internal_dmac_issue_work_fn(struct work_struct *work) {struct tmio_mmc_host *host =from_work (host, work, dma_issue);struct renesas_sdhi *priv =host_to_priv (host); +unsigned long flags; + +spin_lock_irqsave (&host->lock, flags); +if (!host->cmd) { +spin_unlock_irqrestore (&host->lock, flags); +return ; + }tmio_mmc_enable_mmc_irqs (host,TMIO_STAT_DATAEND );
@@ -462,6 +469,7 @@ static void renesas_sdhi_internal_dmac_issue_work_fn(struct work_struct *work)if (test_bit (SDHI_DMA_END_FLAG_ACCESS , &priv->dma_priv.end_flags))queue_work (system_bh_wq, &priv->dma_priv.dma_complete); } +spin_unlock_irqrestore (&host->lock, flags); }static bool renesas_sdhi_internal_dmac_complete (struct tmio_mmc_host *host)
Signature · 1 line
2.56.1.750.gf70dc682cf-goog
PATCH 7/13 mmc: tifm_sd: Synchronise timeout handler with request completion
In reply to Lee Jonestifm_sd_end_cmd() deletes host->timer with timer_delete() under sock->lock, clears host->req to NULL, and completes the request via mmc_request_done(). Because timer_delete() does not wait for an already executing timer callback and tifm_sd_abort() reads the active command opcode from host->req without holding sock->lock, a concurrent timeout expiry can dereference a NULL or freed struct mmc_request and spuriously eject the card after the request has already completed.
Serialise tifm_sd_abort() on sock->lock, return early if host->req has already been cleared or the socket is being ejected, and snapshot the command opcode and flags before releasing sock->lock prior to calling tifm_eject().
--- drivers/mmc/host/tifm_sd.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)
drivers/mmc/host/tifm_sd.c +14 -2
@@ -776,12 +776,24 @@ static void tifm_sd_end_cmd(struct work_struct *t)static void tifm_sd_abort (struct timer_list *t) {struct tifm_sd *host =timer_container_of (host, t, timer); +struct tifm_dev *sock = host->dev; +unsigned int opcode, cmd_flags; +unsigned long flags; + +spin_lock_irqsave (&sock->lock, flags); +if (!host->req || host->eject) { +spin_unlock_irqrestore (&sock->lock, flags); +return ; + } + opcode = host->req->cmd->opcode; + cmd_flags = host->cmd_flags; +spin_unlock_irqrestore (&sock->lock, flags);pr_err ("%s : card failed to respond for a long period of time " "(%x, %x)\n" , -dev_name (&host->dev->dev), host->req->cmd->opcode, host->cmd_flags); +dev_name (&sock->dev), opcode, cmd_flags); -tifm_eject (host->dev); +tifm_eject (sock); }static void tifm_sd_ios (struct mmc_host *mmc,struct mmc_ios *ios)
Signature · 1 line
2.56.1.750.gf70dc682cf-goog
PATCH 8/13 mmc: omap: Shut down cover timer before disabling cover BH work
In reply to Lee JonesIn mmc_omap_remove_slot(), cancel_work_sync(&slot->cover_bh_work) is called before timer_delete_sync(&slot->cover_timer). Because mmc_omap_cover_timer() queues slot->cover_bh_work and mmc_omap_cover_bh_handler() rearms slot->cover_timer, a timer expiry between the two calls (or a concurrent omap_mmc_notify_cover_event() before platform cleanup) can re-queue cover_bh_work so that it runs after the slot and its struct mmc_host have been freed.
When cover state polling is configured, shut down slot->cover_timer first with timer_shutdown_sync() to prevent re-arming, and then stop slot->cover_bh_work with disable_work_sync() so no further work can be queued during teardown.
--- drivers/mmc/host/omap.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/mmc/host/omap.c +4 -4
@@ -1356,11 +1356,11 @@ static void mmc_omap_remove_slot(struct mmc_omap_slot *slot)if (slot->pdata->name !=NULL )device_remove_file (&mmc->class_dev, &dev_attr_slot_name); -if (slot->pdata->get_cover_state !=NULL ) +if (slot->pdata->get_cover_state) {device_remove_file (&mmc->class_dev, &dev_attr_cover_switch); - -cancel_work_sync (&slot->cover_bh_work); -timer_delete_sync (&slot->cover_timer); +timer_shutdown_sync (&slot->cover_timer); +disable_work_sync (&slot->cover_bh_work); + }flush_workqueue (slot->host->mmc_omap_wq);mmc_remove_host (mmc);
Signature · 1 line
2.56.1.750.gf70dc682cf-goog
PATCH 9/13 mmc: renesas_sdhi: Disable internal DMAC BH work items on release
In reply to Lee Jonesrenesas_sdhi_internal_dmac_request_dma() initialises both host->dma_issue and priv->dma_priv.dma_complete, which are queued onto system_bh_wq during DMA transfers and error handling. However, renesas_sdhi_internal_dmac_release_dma() only clears host->chan_rx and host->chan_tx without disabling or draining either work item, allowing a pending execution of renesas_sdhi_internal_dmac_complete_work_fn() or renesas_sdhi_internal_dmac_issue_work_fn() to run after controller clocks are disabled and the host structures are freed.
Disable and drain both work items with disable_work_sync() in renesas_sdhi_internal_dmac_release_dma().
--- drivers/mmc/host/renesas_sdhi_internal_dmac.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/mmc/host/renesas_sdhi_internal_dmac.c +5 -0
@@ -573,6 +573,11 @@ renesas_sdhi_internal_dmac_request_dma(struct tmio_mmc_host *host,static void renesas_sdhi_internal_dmac_release_dma (struct tmio_mmc_host *host) { +struct renesas_sdhi *priv =host_to_priv (host); + +disable_work_sync (&host->dma_issue); +disable_work_sync (&priv->dma_priv.dma_complete); +/* Each value is set to zero to assume "disabling" each DMA */ host->chan_rx = host->chan_tx =NULL ; }
Signature · 1 line
2.56.1.750.gf70dc682cf-goog
PATCH 10/13 mmc: jz4740: Apply DMA max_seg_size limit to unified tx-rx channel
In reply to Lee JonesCommit afadb04f1d6e ("mmc: jz4740: Apply DMA engine limits to maximum segment size") added max_seg_size clamping at the end of jz4740_mmc_acquire_dma_channels(), below the early return for the unified "tx-rx" DMA channel added earlier by commit a474e52c3109 ("mmc:
jz4740: Support using a bi-directional DMA channel"). When "tx-rx" is used, host->mmc->max_seg_size is never clamped to dma_get_max_seg_size() and the MMC core can submit scatterlist segments exceeding the DMA controller hardware limit.
Jump to the max_seg_size clamping block when acquiring the "tx-rx" channel instead of returning early.
--- drivers/mmc/host/jz4740_mmc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/mmc/host/jz4740_mmc.c +2 -1
@@ -231,7 +231,7 @@ static int jz4740_mmc_acquire_dma_channels(struct jz4740_mmc_host *host) host->dma_tx =dma_request_chan (dev,"tx-rx" );if (!IS_ERR (host->dma_tx)) -return 0 ; + goto out;if (PTR_ERR (host->dma_tx) != -ENODEV ) {dev_err (dev,"Failed to get dma tx-rx channel\n" );
@@ -251,6 +251,7 @@ static int jz4740_mmc_acquire_dma_channels(struct jz4740_mmc_host *host)return PTR_ERR (host->dma_rx); } +out:/* * Limit the maximum segment size in any SG entry according to * the parameters of the DMA engine device.
Signature · 1 line
2.56.1.750.gf70dc682cf-goog
PATCH 11/13 mmc: dw_mmc: Disarm central watchdog when ending a request
In reply to Lee JonesWhen EVENT_DATA_ERROR (such as SDMMC_INT_DCRC or SDMMC_INT_SBE) is handled in STATE_SENDING_DATA, send_stop_abort() starts a stop command and arms host->wd_timer for DW_MCI_WD_CMD_EVENTS. In STATE_DATA_BUSY, dw_mci_data_complete() resets the controller on data error, aborting the in-flight stop command, and dw_mci_work_func() ends the request via dw_mci_request_end() if EVENT_CMD_COMPLETE is not already pending.
Because dw_mci_request_end() does not disarm host->wd_timer, the stale command watch remains armed after mmc_request_done() and later injects a spurious SDMMC_INT_RTO and EVENT_CMD_COMPLETE while idle or during a subsequent recovery command (for example MMC_GO_IDLE_STATE, which does not re-arm the command watchdog).
Disarm the central watchdog under host->irq_lock when transitioning to STATE_IDLE in dw_mci_request_end(), and clear wd_states and wd_deadline_ns alongside wd_events when disarming in dw_mci_wd_deliver().
--- drivers/mmc/host/dw_mmc.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-)
drivers/mmc/host/dw_mmc.c +11 -3
@@ -79,8 +79,11 @@static void dw_mci_wd_deliver (struct dw_mci *host,unsigned long events) { host->wd_events &= ~events; -if (!host->wd_events) +if (!host->wd_events) { + host->wd_states =0 ; + host->wd_deadline_ns =0 ;hrtimer_try_to_cancel (&host->wd_timer); + } }/*
@@ -1887,15 +1890,20 @@ static void dw_mci_request_end(struct dw_mci *host, struct mmc_request *mrq) __acquires(&host->lock) {struct mmc_host *prev_mmc = host->mmc; +unsigned long irqflags;WARN_ON (host->cmd || host->data); host->mrq =NULL ; -if (host->state ==STATE_SENDING_CMD11 ) +if (host->state ==STATE_SENDING_CMD11 ) { host->state =STATE_WAITING_CMD11_DONE ; -else + }else { +spin_lock_irqsave (&host->irq_lock, irqflags); +dw_mci_wd_deliver (host, ~0UL ); +spin_unlock_irqrestore (&host->irq_lock, irqflags); host->state =STATE_IDLE ; + }spin_unlock (&host->lock);mmc_request_done (prev_mmc, mrq);
Signature · 1 line
2.56.1.750.gf70dc682cf-goog
PATCH 12/13 mmc: renesas_sdhi: Fix SDIO manual tap correction in SDR104 mode
In reply to Lee JonesCommit 30fa7d53afd4 ("mmc: host: renesas_sdhi: Fix incorrect auto retuning for an SDIO card") switched SDIO cards from automatic to manual SCC tap correction so that DAT1 SDIO interrupts would not spuriously shift the sampling tap, but exposed two logic errors in the manual correction path:
1. renesas_sdhi_manual_correction() checks !priv->card_is_sdio instead of priv->card_is_sdio before ignoring DAT1 mismatches, so the SDIO DAT1 check never executes for SDIO cards.
2. renesas_sdhi_check_scc_error() already returns early when running in 4-tap HS400 mode, yet still passes the hs400_4taps quirk flag as use_4tap to renesas_sdhi_manual_correction(), halving the 8-tap SDR104 and HS200 tap index when writing SH_MOBILE_SDHI_SCC_TAPSET on SoCs with hs400_4taps.
Check priv->card_is_sdio without negation and drop the unused 4-tap division from renesas_sdhi_manual_correction().
--- drivers/mmc/host/renesas_sdhi_core.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/mmc/host/renesas_sdhi_core.c +4 -5
@@ -741,7 +741,7 @@ static int renesas_sdhi_execute_tuning(struct mmc_host *mmc, u32 opcode)return ret; } -static bool renesas_sdhi_manual_correction (struct tmio_mmc_host *host,bool use_4tap) +static bool renesas_sdhi_manual_correction (struct tmio_mmc_host *host) {struct renesas_sdhi *priv =host_to_priv (host);unsigned int new_tap = priv->tap_set, error_tap = priv->tap_set;
@@ -783,7 +783,7 @@ static bool renesas_sdhi_manual_correction(struct tmio_mmc_host *host, bool use_if (bad_taps &BIT (new_tap % priv->tap_num))return test_bit (error_tap % priv->tap_num, priv->smpcmp); }else { -if (!priv->card_is_sdio && +if (priv->card_is_sdio && !(val &SH_MOBILE_SDHI_SCC_RVSREQ_RVSERR )) {u32 smpcmp =sd_scc_read32 (host, priv,SH_MOBILE_SDHI_SCC_SMPCMP );
@@ -802,8 +802,7 @@ static bool renesas_sdhi_manual_correction(struct tmio_mmc_host *host, bool use_ } priv->tap_set = (new_tap % priv->tap_num); -sd_scc_write32 (host, priv,SH_MOBILE_SDHI_SCC_TAPSET , - priv->tap_set / (use_4tap ?2 :1 )); +sd_scc_write32 (host, priv,SH_MOBILE_SDHI_SCC_TAPSET , priv->tap_set);return false; }
@@ -854,7 +853,7 @@ static bool renesas_sdhi_check_scc_error(struct tmio_mmc_host *host, SH_MOBILE_SDHI_SCC_RVSCNTL_RVSEN) ret |= renesas_sdhi_auto_correction(host); else - ret |= renesas_sdhi_manual_correction(host, use_4tap); + ret |= renesas_sdhi_manual_correction(host);return ret; }
Signature · 1 line
2.56.1.750.gf70dc682cf-goog
PATCH 13/13 mmc: sdhci-brcmstb: Handle absent optional sdio_freq clock in probe
In reply to Lee JonesStandard MMC Device Tree nodes may specify "clock-frequency" on SoCs that do not provide the optional 72116B0 "sdio_freq" clock, in which case devm_clk_get_optional() legitimately returns NULL. However, sdhci_brcmstb_probe() only checks IS_ERR(base_clk): when base_clk is NULL, clk_get_rate(base_clk) evaluates to 0 and overwrites SDHCI_CLOCK_V3_BASE_MASK in host->caps with 0 MHz while leaving priv->base_freq_hz non-zero for system resume.
Check IS_ERR_OR_NULL(base_clk) and clear priv->base_freq_hz on the fallback path before jumping to add_host.
--- drivers/mmc/host/sdhci-brcmstb.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/mmc/host/sdhci-brcmstb.c +4 -2
@@ -585,8 +585,10 @@ static int sdhci_brcmstb_probe(struct platform_device *pdev) goto add_host; base_clk =devm_clk_get_optional (&pdev->dev,"sdio_freq" ); -if (IS_ERR (base_clk)) { -dev_warn (&pdev->dev,"Clock for \"sdio_freq\" not found\n" ); +if (IS_ERR_OR_NULL (base_clk)) { +if (IS_ERR (base_clk)) +dev_warn (&pdev->dev,"Clock for \"sdio_freq\" not found\n" ); + priv->base_freq_hz =0 ; goto add_host; }
Signature · 1 line
2.56.1.750.gf70dc682cf-goog
Re: [PATCH 13/13] mmc: sdhci-brcmstb: Handle absent optional sdio_freq clock in probe
Quoted 8 lines · Lee Jones
Standard MMC Device Tree nodes may specify "clock-frequency" on SoCs that do not provide the optional 72116B0 "
sdio_freq" clock, in which casedevm_clk_get_optional()legitimately returns NULL. However,sdhci_brcmstb_probe()only checksIS_ERR(base_clk): whenbase_clkis NULL,clk_get_rate(base_clk)evaluates to 0 and overwritesSDHCI_CLOCK_V3_BASE_MASKinhost->capswith 0 MHz while leavingpriv->base_freq_hznon-zero for system resume.
Quoted 7 lines
Check
IS_ERR_OR_NULL(base_clk)and clearpriv->base_freq_hzon the fallback path before jumping toadd_host.Fixes 97904a59855c ("mmc: sdhci-brcmstb: Add ability to increase max clock rate for 72116b0")Signed-off-by Lee Jones <[email protected]>
Not sure this deserves a Fixes: tag.
Signature · 1 line
Florian
Re: [PATCH 11/13] mmc: dw_mmc: Disarm central watchdog when ending a request
In reply to Lee JonesHi
Quoted 7 lines · Lee Jones
When
EVENT_DATA_ERROR(such asSDMMC_INT_DCRCorSDMMC_INT_SBE) is handled inSTATE_SENDING_DATA,send_stop_abort()starts a stop command and armshost->wd_timerforDW_MCI_WD_CMD_EVENTS. InSTATE_DATA_BUSY,dw_mci_data_complete()resets the controller on data error, aborting the in-flight stop command, anddw_mci_work_func()ends the request viadw_mci_request_end()ifEVENT_CMD_COMPLETEis not already pending.
Sure, it's a bug for send_stop_abort() case. The dw_mmc state machine is so complicated and prone to error... This fix looks clean and minimal,
Quoted 58 lines
Because
dw_mci_request_end()does not disarmhost->wd_timer, the stale command watch remains armed aftermmc_request_done()and later injects a spuriousSDMMC_INT_RTOandEVENT_CMD_COMPLETEwhile idle or during a subsequent recovery command (for exampleMMC_GO_IDLE_STATE, which does not re-arm the command watchdog).Disarm the central watchdog under
host->irq_lockwhen transitioning toSTATE_IDLEindw_mci_request_end(), and clearwd_statesandwd_deadline_nsalongsidewd_eventswhen disarming indw_mci_wd_deliver().Fixes ce0043b9a302 ("mmc: dw_mmc: add central watchdog and convert CTO onto it")Signed-off-by Lee Jones <[email protected]>--- drivers/mmc/host/dw_mmc.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-)drivers/mmc/host/dw_mmc.c +11
-3@@ -79,8 +79,11 @@static void dw_mci_wd_deliver (struct dw_mci *host,unsigned long events) { host->wd_events &= ~events; -if (!host->wd_events) +if (!host->wd_events) { + host->wd_states =0 ; + host->wd_deadline_ns =0 ;hrtimer_try_to_cancel (&host->wd_timer); + } }/* @@ -1887,15 +1890,20 @@ static void dw_mci_request_end(struct dw_mci *host, struct mmc_request *mrq) __acquires(&host->lock) {struct mmc_host *prev_mmc = host->mmc; +unsigned long irqflags;WARN_ON (host->cmd || host->data); host->mrq =NULL ; -if (host->state ==STATE_SENDING_CMD11 ) +if (host->state ==STATE_SENDING_CMD11 ) { host->state =STATE_WAITING_CMD11_DONE ; -else + }else { +spin_lock_irqsave (&host->irq_lock, irqflags); +dw_mci_wd_deliver (host, ~0UL ); +spin_unlock_irqrestore (&host->irq_lock, irqflags); host->state =STATE_IDLE ; + }spin_unlock (&host->lock);mmc_request_done (prev_mmc, mrq);