mmc: sdhci: Tidy reset handling
Adrian Hunter
maintainercover mmc: sdhci: Tidy reset handling
Hi
When reviewing the patch "mmc: sdhci-tegra: Issue CMD and DAT resets together" currently on the mailing list:
https://lore.kernel.org/linux-mmc/[email protected]/
it seemed like some small tidy up was needed first. Hence these patches.
In particular, patch 4 "mmc: sdhci: Centralize CMD and DATA reset handling" should enable the proposed quirk from the sdhci-tegra patch to be implemented in a more consistent way.
Adrian Hunter (4):
mmc: sdhci: Separate out sdhci_reset_for_all()
mmc: sdhci: Remove misleading comment about resets
mmc: sdhci: Get rid of SDHCI_QUIRK_RESET_CMD_DATA_ON_IOS
mmc: sdhci: Centralize CMD and DATA reset handling
drivers/mmc/host/sdhci-pci-core.c | 23 ++++++++++- drivers/mmc/host/sdhci.c | 84 ++++++++++++++++++++++++--------------- drivers/mmc/host/sdhci.h | 2 - 3 files changed, 73 insertions(+), 36 deletions(-)
Regards
Adrian
Adrian Hunter
maintainerPATCH 1/4 mmc: sdhci: Separate out sdhci_reset_for_all()
Tidy sdhci_do_reset() slightly by separating out sdhci_reset_for_all() which removes the need to test the mask in sdhci_do_reset().
--- drivers/mmc/host/sdhci.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-)
drivers/mmc/host/sdhci.c +12 -8
@@ -232,23 +232,27 @@ void sdhci_reset(struct sdhci_host *host, u8 mask) }EXPORT_SYMBOL_GPL (sdhci_reset); -static void sdhci_do_reset (struct sdhci_host *host,u8 mask) +static bool sdhci_do_reset (struct sdhci_host *host,u8 mask) {if (host->quirks &SDHCI_QUIRK_NO_CARD_NO_RESET ) {struct mmc_host *mmc = host->mmc;if (!mmc->ops->get_cd (mmc)) -return ; +return false; } host->ops->reset (host, mask); -if (mask &SDHCI_RESET_ALL ) { +return true; +} + +static void sdhci_reset_for_all (struct sdhci_host *host) +{ +if (sdhci_do_reset (host,SDHCI_RESET_ALL )) {if (host->flags & (SDHCI_USE_SDMA |SDHCI_USE_ADMA )) {if (host->ops->enable_dma) host->ops->enable_dma (host); } -/* Resetting the controller clears many */ host->preset_enabled = false; }
@@ -324,7 +328,7 @@ static void sdhci_init(struct sdhci_host *host, int soft)if (soft)sdhci_do_reset (host,SDHCI_RESET_CMD |SDHCI_RESET_DATA );else -sdhci_do_reset (host,SDHCI_RESET_ALL ); +sdhci_reset_for_all (host);if (host->v4_mode)sdhci_do_enable_v4_mode (host);
@@ -4037,7 +4041,7 @@ void __sdhci_read_caps(struct sdhci_host *host, const u16 *ver,if (debug_quirks2) host->quirks2 = debug_quirks2; -sdhci_do_reset (host,SDHCI_RESET_ALL ); +sdhci_reset_for_all (host);if (host->v4_mode)sdhci_do_enable_v4_mode (host);
@@ -4778,7 +4782,7 @@ int __sdhci_add_host(struct sdhci_host *host) unled:sdhci_led_unregister (host); unirq: -sdhci_do_reset (host,SDHCI_RESET_ALL ); +sdhci_reset_for_all (host);sdhci_writel (host,0 ,SDHCI_INT_ENABLE );sdhci_writel (host,0 ,SDHCI_SIGNAL_ENABLE );free_irq (host->irq, host);
@@ -4836,7 +4840,7 @@ void sdhci_remove_host(struct sdhci_host *host, int dead)sdhci_led_unregister (host);if (!dead) -sdhci_do_reset (host,SDHCI_RESET_ALL ); +sdhci_reset_for_all (host);sdhci_writel (host,0 ,SDHCI_INT_ENABLE );sdhci_writel (host,0 ,SDHCI_SIGNAL_ENABLE );
Signature · 1 line
2.25.1
Adrian Hunter
maintainerPATCH 2/4 mmc: sdhci: Remove misleading comment about resets
In reply to Adrian HunterIn SDHCI specification section 3.10.1 Error Interrupt Recovery, the flow chart shows Software Reset for CMD separately and before Software Reset for DAT, so the comment "Spec says we should do both at the same time" is not correct. Remove it.
--- drivers/mmc/host/sdhci.c | 4 ---- 1 file changed, 4 deletions(-)
drivers/mmc/host/sdhci.c +0 -4
@@ -3059,10 +3059,6 @@ static bool sdhci_request_done(struct sdhci_host *host)/* This is to force an update */ host->ops->set_clock (host, host->clock); -/* -* Spec says we should do both at the same time, but Ricoh -* controllers do not like that. -*/ sdhci_do_reset (host,SDHCI_RESET_CMD );sdhci_do_reset (host,SDHCI_RESET_DATA );
Signature · 1 line
2.25.1
Adrian Hunter
maintainerPATCH 3/4 mmc: sdhci: Get rid of SDHCI_QUIRK_RESET_CMD_DATA_ON_IOS
In reply to Adrian HunterSDHCI_QUIRK_RESET_CMD_DATA_ON_IOS is used by only ENE controllers but can be replaced by driver code.
Amend the ENE code to hook the ->set_ios() mmc host operation and do the reset there.
--- drivers/mmc/host/sdhci-pci-core.c | 23 ++++++++++++++++++++++- drivers/mmc/host/sdhci.c | 8 -------- drivers/mmc/host/sdhci.h | 2 -- 3 files changed, 22 insertions(+), 11 deletions(-)
drivers/mmc/host/sdhci-pci-core.c +22 -1
@@ -297,6 +297,27 @@ static const struct sdhci_pci_fixes sdhci_ricoh_mmc = {SDHCI_QUIRK_MISSING_CAPS }; +static void ene_714_set_ios (struct mmc_host *mmc,struct mmc_ios *ios) +{ +struct sdhci_host *host =mmc_priv (mmc); + +sdhci_set_ios (mmc, ios); + +/* +* Some (ENE) controllers misbehave on some ios operations, +* signalling timeout and CRC errors even on CMD0. Resetting +* it on each ios seems to solve the problem. +*/ +if (!(host->flags &SDHCI_DEVICE_DEAD )) +sdhci_reset (host,SDHCI_RESET_CMD |SDHCI_RESET_DATA ); +} + +static int ene_714_probe_slot (struct sdhci_pci_slot *slot) +{ + slot->host->mmc_host_ops.set_ios = ene_714_set_ios; +return 0 ; +} +static const struct sdhci_pci_fixes sdhci_ene_712 = { .quirks =SDHCI_QUIRK_SINGLE_POWER_WRITE |SDHCI_QUIRK_BROKEN_DMA ,
@@ -304,8 +325,8 @@ static const struct sdhci_pci_fixes sdhci_ene_712 = {static const struct sdhci_pci_fixes sdhci_ene_714 = { .quirks =SDHCI_QUIRK_SINGLE_POWER_WRITE | -SDHCI_QUIRK_RESET_CMD_DATA_ON_IOS |SDHCI_QUIRK_BROKEN_DMA , + .probe_slot = ene_714_probe_slot, };static const struct sdhci_pci_fixes sdhci_cafe = {
drivers/mmc/host/sdhci.c +0 -8
@@ -2403,14 +2403,6 @@ void sdhci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) host->ops->set_clock (host, host->clock); }else sdhci_writeb (host, ctrl,SDHCI_HOST_CONTROL ); - -/* -* Some (ENE) controllers go apeshit on some ios operation, -* signalling timeout and CRC errors even on CMD0. Resetting -* it on each ios seems to solve the problem. -*/ -if (host->quirks &SDHCI_QUIRK_RESET_CMD_DATA_ON_IOS ) -sdhci_do_reset (host,SDHCI_RESET_CMD |SDHCI_RESET_DATA ); }EXPORT_SYMBOL_GPL (sdhci_set_ios);
drivers/mmc/host/sdhci.h +0 -2
@@ -376,8 +376,6 @@ struct sdhci_host {#define SDHCI_QUIRK_NO_CARD_NO_RESET (1<<2)/* Controller doesn't like clearing the power reg before a change */ #define SDHCI_QUIRK_SINGLE_POWER_WRITE (1<<3) -/* Controller has flaky internal state so reset it on each ios change */ -#define SDHCI_QUIRK_RESET_CMD_DATA_ON_IOS (1<<4)/* Controller has an unusable DMA engine */ #define SDHCI_QUIRK_BROKEN_DMA (1<<5)/* Controller has an unusable ADMA engine */
Signature · 1 line
2.25.1
Adrian Hunter
maintainerPATCH 4/4 mmc: sdhci: Centralize CMD and DATA reset handling
In reply to Adrian HunterCentralize CMD and DATA reset handling so that is more obvious how reset is handled in different situations.
--- drivers/mmc/host/sdhci.c | 52 ++++++++++++++++++++++++++++++---------- 1 file changed, 39 insertions(+), 13 deletions(-)
drivers/mmc/host/sdhci.c +39 -13
@@ -258,6 +258,36 @@ static void sdhci_reset_for_all(struct sdhci_host *host) } } +enum sdhci_reset_reason { +SDHCI_RESET_FOR_INIT , +SDHCI_RESET_FOR_REQUEST_ERROR , +SDHCI_RESET_FOR_REQUEST_ERROR_DATA_ONLY , +SDHCI_RESET_FOR_TUNING_ABORT , +SDHCI_RESET_FOR_CARD_REMOVED , +SDHCI_RESET_FOR_CQE_RECOVERY , +}; + +static void sdhci_reset_for_reason (struct sdhci_host *host,enum sdhci_reset_reason reason) +{ +switch (reason) { +case SDHCI_RESET_FOR_INIT : +sdhci_do_reset (host,SDHCI_RESET_CMD |SDHCI_RESET_DATA ); +break ; +case SDHCI_RESET_FOR_REQUEST_ERROR : +case SDHCI_RESET_FOR_TUNING_ABORT : +case SDHCI_RESET_FOR_CARD_REMOVED : +case SDHCI_RESET_FOR_CQE_RECOVERY : +sdhci_do_reset (host,SDHCI_RESET_CMD ); +sdhci_do_reset (host,SDHCI_RESET_DATA ); +break ; +case SDHCI_RESET_FOR_REQUEST_ERROR_DATA_ONLY : +sdhci_do_reset (host,SDHCI_RESET_DATA ); +break ; + } +} + +#define sdhci_reset_for (h, r) sdhci_reset_for_reason((h), SDHCI_RESET_FOR_##r) +static void sdhci_set_default_irqs (struct sdhci_host *host) { host->ier = SDHCI_INT_BUS_POWER | SDHCI_INT_DATA_END_BIT |
@@ -326,7 +356,7 @@ static void sdhci_init(struct sdhci_host *host, int soft)unsigned long flags;if (soft) -sdhci_do_reset (host,SDHCI_RESET_CMD |SDHCI_RESET_DATA ); +sdhci_reset_for (host,INIT );else sdhci_reset_for_all (host);
@@ -1541,8 +1571,9 @@ static void __sdhci_finish_data(struct sdhci_host *host, bool sw_data_timeout)*/ if (data->error) {if (!host->cmd || host->cmd == data_cmd) -sdhci_do_reset (host,SDHCI_RESET_CMD ); -sdhci_do_reset (host,SDHCI_RESET_DATA ); +sdhci_reset_for (host,REQUEST_ERROR ); +else +sdhci_reset_for (host,REQUEST_ERROR_DATA_ONLY ); } if ((host->flags & (SDHCI_REQ_USE_DMA | SDHCI_USE_ADMA)) ==
@@ -2710,8 +2741,7 @@ void sdhci_abort_tuning(struct sdhci_host *host, u32 opcode) {sdhci_reset_tuning (host); -sdhci_do_reset (host,SDHCI_RESET_CMD ); -sdhci_do_reset (host,SDHCI_RESET_DATA ); +sdhci_reset_for (host,TUNING_ABORT );sdhci_end_tuning (host);
@@ -2979,8 +3009,7 @@ static void sdhci_card_event(struct mmc_host *mmc)pr_err ("%s: Resetting controller.\n" ,mmc_hostname (mmc)); -sdhci_do_reset (host,SDHCI_RESET_CMD ); -sdhci_do_reset (host,SDHCI_RESET_DATA ); +sdhci_reset_for (host,CARD_REMOVED );sdhci_error_out_mrqs (host, -ENOMEDIUM ); }
@@ -3051,8 +3080,7 @@ static bool sdhci_request_done(struct sdhci_host *host)/* This is to force an update */ host->ops->set_clock (host, host->clock); -sdhci_do_reset (host,SDHCI_RESET_CMD ); -sdhci_do_reset (host,SDHCI_RESET_DATA ); +sdhci_reset_for (host,REQUEST_ERROR ); host->pending_reset = false; }
@@ -3876,10 +3904,8 @@ void sdhci_cqe_disable(struct mmc_host *mmc, bool recovery) host->cqe_on = false; -if (recovery) { -sdhci_do_reset (host,SDHCI_RESET_CMD ); -sdhci_do_reset (host,SDHCI_RESET_DATA ); - } +if (recovery) +sdhci_reset_for (host,CQE_RECOVERY ); pr_debug("%s: sdhci: CQE off, IRQ mask %#x, IRQ status %#x\n", mmc_hostname(mmc), host->ier,
Signature · 1 line
2.25.1
Quoted 21 lines · Adrian Hunter
Hi
When reviewing the patch "mmc: sdhci-tegra: Issue CMD and DAT resets together" currently on the mailing list:
https://lore.kernel.org/linux-mmc/[email protected]/
it seemed like some small tidy up was needed first. Hence these patches.
In particular, patch 4 "mmc: sdhci: Centralize CMD and DATA reset handling" should enable the proposed quirk from the sdhci-tegra patch to be implemented in a more consistent way.
Adrian Hunter (4):
mmc: sdhci: Separate outsdhci_reset_for_all()
mmc: sdhci: Remove misleading comment about resets
mmc: sdhci: Get rid ofSDHCI_QUIRK_RESET_CMD_DATA_ON_IOS
mmc: sdhci: Centralize CMD and DATA reset handling
Quoted 8 lines
drivers/mmc/host/sdhci-pci-core.c | 23 ++++++++++- drivers/mmc/host/sdhci.c | 84 ++++++++++++++++++++++++--------------- drivers/mmc/host/sdhci.h | 2 - 3 files changed, 73 insertions(+), 36 deletions(-)Regards
Adrian
Applied for next, thanks!
Kind regards
Uffe
Re: [PATCH 3/4] mmc: sdhci: Get rid of SDHCI_QUIRK_RESET_CMD_DATA_ON_IOS
In reply to Adrian HunterQuoted 19 lines · Adrian Hunter
SDHCI_QUIRK_RESET_CMD_DATA_ON_IOSis used by only ENE controllers but can be replaced by driver code.Amend the ENE code to hook the ->set_ios() mmc host operation and do the reset there.
Signed-off-by Adrian Hunter <[email protected]>--- drivers/mmc/host/sdhci-pci-core.c | 23 ++++++++++++++++++++++- drivers/mmc/host/sdhci.c | 8 -------- drivers/mmc/host/sdhci.h | 2 -- 3 files changed, 22 insertions(+), 11 deletions(-)drivers/mmc/host/sdhci-pci-core.c +0
-0@@ -297,6 +297,27 @@ static const struct sdhci_pci_fixes sdhci_ricoh_mmc = {SDHCI_QUIRK_MISSING_CAPS
drivers/mmc/host/sdhci-pci-core.c static const struct sdhci_pci_fixes sdhci_ricoh_mmc = { · line 307
Quoted 10 lines
drivers/mmc/host/sdhci-pci-core.c +8
-0}; +static void ene_714_set_ios (struct mmc_host *mmc,struct mmc_ios *ios) +{ +struct sdhci_host *host =mmc_priv (mmc); + +sdhci_set_ios (mmc, ios); + +/* +* Some (ENE) controllers misbehave on some ios operations,
Nice rewording that you snuck in there. =)
I just realized, after going through the patches that Ulf has already applied this, but FWIW, the series:
Re: [PATCH 3/4] mmc: sdhci: Get rid of SDHCI_QUIRK_RESET_CMD_DATA_ON_IOS
Quoted 23 lines · Thierry Reding
Quoted 21 lines · Adrian Hunter
SDHCI_QUIRK_RESET_CMD_DATA_ON_IOSis used by only ENE controllers but can be replaced by driver code.Amend the ENE code to hook the ->set_ios() mmc host operation and do the reset there.
Signed-off-by Adrian Hunter <[email protected]>--- drivers/mmc/host/sdhci-pci-core.c | 23 ++++++++++++++++++++++- drivers/mmc/host/sdhci.c | 8 -------- drivers/mmc/host/sdhci.h | 2 -- 3 files changed, 22 insertions(+), 11 deletions(-)drivers/mmc/host/sdhci-pci-core.c +0
-0@@ -297,6 +297,27 @@ static const struct sdhci_pci_fixes sdhci_ricoh_mmc = { SDHCI_QUIRK_MISSING_CAPS };
Quoted 10 lines
drivers/mmc/host/sdhci-pci-core.c static const struct sdhci_pci_fixes sdhci_ricoh_mmc = { · line 307
Quoted 8 lines
drivers/mmc/host/sdhci-pci-core.c +8
-0+static void ene_714_set_ios (struct mmc_host *mmc,struct mmc_ios *ios) +{ +struct sdhci_host *host =mmc_priv (mmc); + +sdhci_set_ios (mmc, ios); + +/* +* Some (ENE) controllers misbehave on some ios operations, Nice rewording that you snuck in there. =)
:-)
Quoted 5 lines
I just realized, after going through the patches that Ulf has already applied this, but FWIW, the series:
Reviewed-by Thierry Reding <[email protected]>
No problem, I will add your tag to the series. Thanks for reviewing!
Kind regards
Uffe