Skip to content

Commit b4911fb

Browse files
committed
Merge tag 'mmc-v6.16-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/ulfh/mmc
Pull MMC fixes from Ulf Hansson: "MMC core: - Apply BROKEN_SD_DISCARD quirk earlier during init - Silence some confusing error messages for SD UHS-II cards MMC host: - mtk-sd: - Prevent memory corruption from DMA map failure - Fix a pagefault in dma_unmap_sg() for not prepared data - sdhci: Revert "Disable SD card clock before changing parameters" - sdhci-of-k1: Fix error code in probe() - sdhci-uhs2: Silence some confusing error messages for SD UHS-II cards" * tag 'mmc-v6.16-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/ulfh/mmc: mtk-sd: reset host->mrq on prepare_data() error Revert "mmc: sdhci: Disable SD card clock before changing parameters" mmc: sdhci-uhs2: Adjust some error messages and register dump for SD UHS-II card mmc: sdhci: Add a helper function for dump register in dynamic debug mode mmc: core: Adjust some error messages for SD UHS-II cards mtk-sd: Prevent memory corruption from DMA map failure mtk-sd: Fix a pagefault in dma_unmap_sg() for not prepared data mmc: sdhci-of-k1: Fix error code in probe() mmc: core: sd: Apply BROKEN_SD_DISCARD quirk earlier
2 parents ba6a2f2 + ec54c0a commit b4911fb

File tree

7 files changed

+57
-28
lines changed

7 files changed

+57
-28
lines changed

drivers/mmc/core/quirks.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ static const struct mmc_fixup __maybe_unused mmc_sd_fixups[] = {
4444
0, -1ull, SDIO_ANY_ID, SDIO_ANY_ID, add_quirk_sd,
4545
MMC_QUIRK_NO_UHS_DDR50_TUNING, EXT_CSD_REV_ANY),
4646

47+
/*
48+
* Some SD cards reports discard support while they don't
49+
*/
50+
MMC_FIXUP(CID_NAME_ANY, CID_MANFID_SANDISK_SD, 0x5344, add_quirk_sd,
51+
MMC_QUIRK_BROKEN_SD_DISCARD),
52+
4753
END_FIXUP
4854
};
4955

@@ -147,12 +153,6 @@ static const struct mmc_fixup __maybe_unused mmc_blk_fixups[] = {
147153
MMC_FIXUP("M62704", CID_MANFID_KINGSTON, 0x0100, add_quirk_mmc,
148154
MMC_QUIRK_TRIM_BROKEN),
149155

150-
/*
151-
* Some SD cards reports discard support while they don't
152-
*/
153-
MMC_FIXUP(CID_NAME_ANY, CID_MANFID_SANDISK_SD, 0x5344, add_quirk_sd,
154-
MMC_QUIRK_BROKEN_SD_DISCARD),
155-
156156
END_FIXUP
157157
};
158158

drivers/mmc/core/sd_uhs2.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ static int sd_uhs2_phy_init(struct mmc_host *host)
9191

9292
err = host->ops->uhs2_control(host, UHS2_PHY_INIT);
9393
if (err) {
94-
pr_err("%s: failed to initial phy for UHS-II!\n",
95-
mmc_hostname(host));
94+
pr_debug("%s: failed to initial phy for UHS-II!\n",
95+
mmc_hostname(host));
9696
}
9797

9898
return err;

drivers/mmc/host/mtk-sd.c

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -846,12 +846,18 @@ static inline void msdc_dma_setup(struct msdc_host *host, struct msdc_dma *dma,
846846
static void msdc_prepare_data(struct msdc_host *host, struct mmc_data *data)
847847
{
848848
if (!(data->host_cookie & MSDC_PREPARE_FLAG)) {
849-
data->host_cookie |= MSDC_PREPARE_FLAG;
850849
data->sg_count = dma_map_sg(host->dev, data->sg, data->sg_len,
851850
mmc_get_dma_dir(data));
851+
if (data->sg_count)
852+
data->host_cookie |= MSDC_PREPARE_FLAG;
852853
}
853854
}
854855

856+
static bool msdc_data_prepared(struct mmc_data *data)
857+
{
858+
return data->host_cookie & MSDC_PREPARE_FLAG;
859+
}
860+
855861
static void msdc_unprepare_data(struct msdc_host *host, struct mmc_data *data)
856862
{
857863
if (data->host_cookie & MSDC_ASYNC_FLAG)
@@ -1483,8 +1489,19 @@ static void msdc_ops_request(struct mmc_host *mmc, struct mmc_request *mrq)
14831489
WARN_ON(!host->hsq_en && host->mrq);
14841490
host->mrq = mrq;
14851491

1486-
if (mrq->data)
1492+
if (mrq->data) {
14871493
msdc_prepare_data(host, mrq->data);
1494+
if (!msdc_data_prepared(mrq->data)) {
1495+
host->mrq = NULL;
1496+
/*
1497+
* Failed to prepare DMA area, fail fast before
1498+
* starting any commands.
1499+
*/
1500+
mrq->cmd->error = -ENOSPC;
1501+
mmc_request_done(mmc_from_priv(host), mrq);
1502+
return;
1503+
}
1504+
}
14881505

14891506
/* if SBC is required, we have HW option and SW option.
14901507
* if HW option is enabled, and SBC does not have "special" flags,

drivers/mmc/host/sdhci-of-k1.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,8 @@ static int spacemit_sdhci_probe(struct platform_device *pdev)
276276

277277
host->mmc->caps |= MMC_CAP_NEED_RSP_BUSY;
278278

279-
if (spacemit_sdhci_get_clocks(dev, pltfm_host))
279+
ret = spacemit_sdhci_get_clocks(dev, pltfm_host);
280+
if (ret)
280281
goto err_pltfm;
281282

282283
ret = sdhci_add_host(host);

drivers/mmc/host/sdhci-uhs2.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ void sdhci_uhs2_reset(struct sdhci_host *host, u16 mask)
9999
/* hw clears the bit when it's done */
100100
if (read_poll_timeout_atomic(sdhci_readw, val, !(val & mask), 10,
101101
UHS2_RESET_TIMEOUT_100MS, true, host, SDHCI_UHS2_SW_RESET)) {
102-
pr_warn("%s: %s: Reset 0x%x never completed. %s: clean reset bit.\n", __func__,
103-
mmc_hostname(host->mmc), (int)mask, mmc_hostname(host->mmc));
102+
pr_debug("%s: %s: Reset 0x%x never completed. %s: clean reset bit.\n", __func__,
103+
mmc_hostname(host->mmc), (int)mask, mmc_hostname(host->mmc));
104104
sdhci_writeb(host, 0, SDHCI_UHS2_SW_RESET);
105105
return;
106106
}
@@ -335,8 +335,8 @@ static int sdhci_uhs2_interface_detect(struct sdhci_host *host)
335335
if (read_poll_timeout(sdhci_readl, val, (val & SDHCI_UHS2_IF_DETECT),
336336
100, UHS2_INTERFACE_DETECT_TIMEOUT_100MS, true,
337337
host, SDHCI_PRESENT_STATE)) {
338-
pr_warn("%s: not detect UHS2 interface in 100ms.\n", mmc_hostname(host->mmc));
339-
sdhci_dumpregs(host);
338+
pr_debug("%s: not detect UHS2 interface in 100ms.\n", mmc_hostname(host->mmc));
339+
sdhci_dbg_dumpregs(host, "UHS2 interface detect timeout in 100ms");
340340
return -EIO;
341341
}
342342

@@ -345,8 +345,8 @@ static int sdhci_uhs2_interface_detect(struct sdhci_host *host)
345345

346346
if (read_poll_timeout(sdhci_readl, val, (val & SDHCI_UHS2_LANE_SYNC),
347347
100, UHS2_LANE_SYNC_TIMEOUT_150MS, true, host, SDHCI_PRESENT_STATE)) {
348-
pr_warn("%s: UHS2 Lane sync fail in 150ms.\n", mmc_hostname(host->mmc));
349-
sdhci_dumpregs(host);
348+
pr_debug("%s: UHS2 Lane sync fail in 150ms.\n", mmc_hostname(host->mmc));
349+
sdhci_dbg_dumpregs(host, "UHS2 Lane sync fail in 150ms");
350350
return -EIO;
351351
}
352352

@@ -417,12 +417,12 @@ static int sdhci_uhs2_do_detect_init(struct mmc_host *mmc)
417417
host->ops->uhs2_pre_detect_init(host);
418418

419419
if (sdhci_uhs2_interface_detect(host)) {
420-
pr_warn("%s: cannot detect UHS2 interface.\n", mmc_hostname(host->mmc));
420+
pr_debug("%s: cannot detect UHS2 interface.\n", mmc_hostname(host->mmc));
421421
return -EIO;
422422
}
423423

424424
if (sdhci_uhs2_init(host)) {
425-
pr_warn("%s: UHS2 init fail.\n", mmc_hostname(host->mmc));
425+
pr_debug("%s: UHS2 init fail.\n", mmc_hostname(host->mmc));
426426
return -EIO;
427427
}
428428

@@ -504,8 +504,8 @@ static int sdhci_uhs2_check_dormant(struct sdhci_host *host)
504504
if (read_poll_timeout(sdhci_readl, val, (val & SDHCI_UHS2_IN_DORMANT_STATE),
505505
100, UHS2_CHECK_DORMANT_TIMEOUT_100MS, true, host,
506506
SDHCI_PRESENT_STATE)) {
507-
pr_warn("%s: UHS2 IN_DORMANT fail in 100ms.\n", mmc_hostname(host->mmc));
508-
sdhci_dumpregs(host);
507+
pr_debug("%s: UHS2 IN_DORMANT fail in 100ms.\n", mmc_hostname(host->mmc));
508+
sdhci_dbg_dumpregs(host, "UHS2 IN_DORMANT fail in 100ms");
509509
return -EIO;
510510
}
511511
return 0;

drivers/mmc/host/sdhci.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2065,15 +2065,10 @@ void sdhci_set_clock(struct sdhci_host *host, unsigned int clock)
20652065

20662066
host->mmc->actual_clock = 0;
20672067

2068-
clk = sdhci_readw(host, SDHCI_CLOCK_CONTROL);
2069-
if (clk & SDHCI_CLOCK_CARD_EN)
2070-
sdhci_writew(host, clk & ~SDHCI_CLOCK_CARD_EN,
2071-
SDHCI_CLOCK_CONTROL);
2068+
sdhci_writew(host, 0, SDHCI_CLOCK_CONTROL);
20722069

2073-
if (clock == 0) {
2074-
sdhci_writew(host, 0, SDHCI_CLOCK_CONTROL);
2070+
if (clock == 0)
20752071
return;
2076-
}
20772072

20782073
clk = sdhci_calc_clk(host, clock, &host->mmc->actual_clock);
20792074
sdhci_enable_clk(host, clk);

drivers/mmc/host/sdhci.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -900,4 +900,20 @@ void sdhci_switch_external_dma(struct sdhci_host *host, bool en);
900900
void sdhci_set_data_timeout_irq(struct sdhci_host *host, bool enable);
901901
void __sdhci_set_timeout(struct sdhci_host *host, struct mmc_command *cmd);
902902

903+
#if defined(CONFIG_DYNAMIC_DEBUG) || \
904+
(defined(CONFIG_DYNAMIC_DEBUG_CORE) && defined(DYNAMIC_DEBUG_MODULE))
905+
#define SDHCI_DBG_ANYWAY 0
906+
#elif defined(DEBUG)
907+
#define SDHCI_DBG_ANYWAY 1
908+
#else
909+
#define SDHCI_DBG_ANYWAY 0
910+
#endif
911+
912+
#define sdhci_dbg_dumpregs(host, fmt) \
913+
do { \
914+
DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \
915+
if (DYNAMIC_DEBUG_BRANCH(descriptor) || SDHCI_DBG_ANYWAY) \
916+
sdhci_dumpregs(host); \
917+
} while (0)
918+
903919
#endif /* __SDHCI_HW_H */

0 commit comments

Comments
 (0)