mmc: core: PM fixes/improvements for SDIO IRQs
Subsystems (7)
v2 cover mmc: core: PM fixes/improvements for SDIO IRQs
Changes in v2:
- Added reviewed/tested-by tags.
- Updated some changelogs.
- Renamed sdio_irq_enabled() to sdio_irq_claimed().
- Don't set sdio_irq_pending when resuming SDIO card, but just queue the work.
The power management support for SDIO cards have slowly been improved, but there are still quite some serious problems, especially when dealing with the so called SDIO IRQs during system suspend/resume.
This series makes some additional improvements to this code in the mmc core, but also includes some needed adaptations for the sdhci, the dw_mmc and the mtk-sd host drivers.
The series is also available at:git://git.kernel.org/pub/scm/linux/kernel/git/ulfh/mmc.git sdio_irq_suspend_next_v2
Kind regards
Uffe
Matthias Kaehlcke (1):
mmc: core: Move code to get pending SDIO IRQs to a function
Ulf Hansson (10):
mmc: core: Add helper function to indicate if SDIO IRQs is enabled
mmc: dw_mmc: Re-store SDIO IRQs mask at system resume
mmc: mtk-sd: Re-store SDIO IRQs mask at system resume
mmc: core: Clarify sdio_irq_pending flag for
MMC_CAP2_SDIO_IRQ_NOTHREAD
mmc: core: Clarify that the ->ack_sdio_irq() callback is mandatory
mmc: core: WARN if SDIO IRQs are enabled for non-powered card in
suspend
mmc: core: Fixup processing of SDIO IRQs during system suspend/resume
mmc: sdhci: Drop redundant check in sdhci_ack_sdio_irq()
mmc: sdhci: Drop redundant code for SDIO IRQs
mmc: sdhci: Convert to use sdio_irq_claimed()
drivers/mmc/core/sdio.c | 4 ++- drivers/mmc/core/sdio_irq.c | 57 +++++++++++++++++++----------- drivers/mmc/host/dw_mmc.c | 4 +++ drivers/mmc/host/mtk-sd.c | 3 ++ drivers/mmc/host/sdhci-esdhc-imx.c | 34 ++++++++---------- drivers/mmc/host/sdhci.c | 12 ++----- drivers/mmc/host/sdhci.h | 6 ---- include/linux/mmc/host.h | 10 ++++++ 8 files changed, 75 insertions(+), 55 deletions(-)
Signature · 1 line
2.17.1
PATCH v2 1/11 mmc: core: Add helper function to indicate if SDIO IRQs is enabled
To avoid each host driver supporting SDIO IRQs, from keeping track internally about if SDIO IRQs has been claimed, let's introduce a common helper function, sdio_irq_claimed().
The function returns true if SDIO IRQs are claimed, via using the information about the number of claimed irqs. This is safe, even without any locks, as long as the helper function is called only from runtime/system suspend callbacks of the host driver.
---
Changes in v2:
- Renamed function to sdio_irq_claimed().
--- include/linux/mmc/host.h | 9 +++++++++ 1 file changed, 9 insertions(+)
include/linux/mmc/host.h +9 -0
@@ -493,6 +493,15 @@ void mmc_command_done(struct mmc_host *host, struct mmc_request *mrq);void mmc_cqe_request_done (struct mmc_host *host,struct mmc_request *mrq); +/* +* May be called from host driver's system/runtime suspend/resume callbacks, +* to know if SDIO IRQs has been claimed. +*/ +static inline bool sdio_irq_claimed (struct mmc_host *host) +{ +return host->sdio_irqs >0 ; +} +static inline void mmc_signal_sdio_irq (struct mmc_host *host) { host->ops->enable_sdio_irq (host,0 );
Signature · 1 line
2.17.1
Re: [PATCH v2 01/11] mmc: core: Add helper function to indicate if SDIO IRQs is enabled
Hi,
Quoted 12 lines · Ulf Hansson
To avoid each host driver supporting SDIO IRQs, from keeping track internally about if SDIO IRQs has been claimed, let's introduce a common helper function,
sdio_irq_claimed().The function returns true if SDIO IRQs are claimed, via using the information about the number of claimed irqs. This is safe, even without any locks, as long as the helper function is called only from runtime/system suspend callbacks of the host driver.
Tested-by Matthias Kaehlcke <[email protected]>Signed-off-by Ulf Hansson <[email protected]>
Quoted 8 lines
---
Changes in v2:
- Renamed function tosdio_irq_claimed().--- include/linux/mmc/host.h | 9 +++++++++ 1 file changed, 9 insertions(+)
PATCH v2 2/11 mmc: dw_mmc: Re-store SDIO IRQs mask at system resume
In reply to Ulf HanssonIn cases when SDIO IRQs have been enabled, runtime suspend is prevented by the driver. However, this still means dw_mci_runtime_suspend|resume() gets called during system suspend/resume, via pm_runtime_force_suspend|resume(). This means during system suspend/resume, the register context of the dw_mmc device most likely loses its register context, even in cases when SDIO IRQs have been enabled.
To re-enable the SDIO IRQs during system resume, the dw_mmc driver currently relies on the mmc core to re-enable the SDIO IRQs when it resumes the SDIO card, but this isn't the recommended solution. Instead, it's better to deal with this locally in the dw_mmc driver, so let's do that.
--- drivers/mmc/host/dw_mmc.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/mmc/host/dw_mmc.c +4 -0
@@ -3460,6 +3460,10 @@ int dw_mci_runtime_resume(struct device *dev)/* Force setup bus to guarantee available clock output */ dw_mci_setup_bus (host->slot, true); +/* Re-enable SDIO interrupts. */ +if (sdio_irq_claimed (host->slot->mmc)) +__dw_mci_enable_sdio_irq (host->slot,1 ); +/* Now that slots are all setup, we can enable card detect */ dw_mci_enable_cd (host);
Signature · 1 line
2.17.1
Re: [PATCH v2 02/11] mmc: dw_mmc: Re-store SDIO IRQs mask at system resume
Hi,
Quoted 13 lines · Ulf Hansson
In cases when SDIO IRQs have been enabled, runtime suspend is prevented by the driver. However, this still means dw_mci_runtime_suspend|resume() gets called during system suspend/resume, via pm_runtime_force_suspend|resume(). This means during system suspend/resume, the register context of the
dw_mmcdevice most likely loses its register context, even in cases when SDIO IRQs have been enabled.To re-enable the SDIO IRQs during system resume, the
dw_mmcdriver currently relies on the mmc core to re-enable the SDIO IRQs when it resumes the SDIO card, but this isn't the recommended solution. Instead, it's better to deal with this locally in thedw_mmcdriver, so let's do that.
Quoted 5 lines
Tested-by Matthias Kaehlcke <[email protected]>Signed-off-by Ulf Hansson <[email protected]>--- drivers/mmc/host/dw_mmc.c | 4 ++++ 1 file changed, 4 insertions(+)
PATCH v2 3/11 mmc: mtk-sd: Re-store SDIO IRQs mask at system resume
In reply to Ulf HanssonIn cases when SDIO IRQs have been enabled, runtime suspend is prevented by the driver. However, this still means msdc_runtime_suspend|resume() gets called during system suspend/resume, via pm_runtime_force_suspend|resume().
This means during system suspend/resume, the register context of the mtk-sd device most likely loses its register context, even in cases when SDIO IRQs have been enabled.
To re-enable the SDIO IRQs during system resume, the mtk-sd driver currently relies on the mmc core to re-enable the SDIO IRQs when it resumes the SDIO card, but this isn't the recommended solution. Instead, it's better to deal with this locally in the mtk-sd driver, so let's do that.
--- drivers/mmc/host/mtk-sd.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/mmc/host/mtk-sd.c +3 -0
@@ -2408,6 +2408,9 @@ static void msdc_save_reg(struct msdc_host *host) }else { host->save_para.pad_tune =readl (host->base + tune_reg); } + +if (sdio_irq_claimed (host->mmc)) +__msdc_enable_sdio_irq (host,1 ); }static void msdc_restore_reg (struct msdc_host *host)
Signature · 1 line
2.17.1
Re: [PATCH v2 03/11] mmc: mtk-sd: Re-store SDIO IRQs mask at system resume
Hi,
Quoted 24 lines · Ulf Hansson
In cases when SDIO IRQs have been enabled, runtime suspend is prevented by the driver. However, this still means msdc_runtime_suspend|resume() gets called during system suspend/resume, via pm_runtime_force_suspend|resume().
This means during system suspend/resume, the register context of the mtk-sd device most likely loses its register context, even in cases when SDIO IRQs have been enabled.
To re-enable the SDIO IRQs during system resume, the mtk-sd driver currently relies on the mmc core to re-enable the SDIO IRQs when it resumes the SDIO card, but this isn't the recommended solution. Instead, it's better to deal with this locally in the mtk-sd driver, so let's do that.
Signed-off-by Ulf Hansson <[email protected]>--- drivers/mmc/host/mtk-sd.c | 3 +++ 1 file changed, 3 insertions(+)drivers/mmc/host/mtk-sd.c +0
-0
drivers/mmc/host/mtk-sd.c static void msdc_save_reg(struct msdc_host *host) · line 2416
Quoted 9 lines
drivers/mmc/host/mtk-sd.c +3
-0@@ -2408,6 +2408,9 @@ static void msdc_save_reg(struct msdc_host *host) }else { host->save_para.pad_tune =readl (host->base + tune_reg); } + +if (sdio_irq_claimed (host->mmc)) +__msdc_enable_sdio_irq (host,1 ); }static void msdc_restore_reg (struct msdc_host *host)
I don't personally have a Mediatek device setup to test this patch on. If it's super urgent I could try to track down one and try to set it up, but hopefully it's easier for someone else...
That being said, from code inspection it seems like you should be adding your code to msdc_restore_reg(), not to msdc_save_reg(). Am I confused?
-Doug
Re: [PATCH v2 03/11] mmc: mtk-sd: Re-store SDIO IRQs mask at system resume
Quoted 42 lines · Doug Anderson
Hi,
Quoted 24 lines · Ulf Hansson
In cases when SDIO IRQs have been enabled, runtime suspend is prevented by the driver. However, this still means msdc_runtime_suspend|resume() gets called during system suspend/resume, via pm_runtime_force_suspend|resume().
This means during system suspend/resume, the register context of the mtk-sd device most likely loses its register context, even in cases when SDIO IRQs have been enabled.
To re-enable the SDIO IRQs during system resume, the mtk-sd driver currently relies on the mmc core to re-enable the SDIO IRQs when it resumes the SDIO card, but this isn't the recommended solution. Instead, it's better to deal with this locally in the mtk-sd driver, so let's do that.
Signed-off-by Ulf Hansson <[email protected]>--- drivers/mmc/host/mtk-sd.c | 3 +++ 1 file changed, 3 insertions(+)drivers/mmc/host/mtk-sd.c +0
-0drivers/mmc/host/mtk-sd.c static void msdc_save_reg(struct msdc_host *host) · line 2416
Quoted 9 lines
drivers/mmc/host/mtk-sd.c +3
-0@@ -2408,6 +2408,9 @@ static void msdc_save_reg(struct msdc_host *host) }else { host->save_para.pad_tune =readl (host->base + tune_reg); } + +if (sdio_irq_claimed (host->mmc)) +__msdc_enable_sdio_irq (host,1 ); }static void msdc_restore_reg (struct msdc_host *host)I don't personally have a Mediatek device setup to test this patch on. If it's super urgent I could try to track down one and try to set it up, but hopefully it's easier for someone else...
Quoted 3 lines
That being said, from code inspection it seems like you should be adding your code to
msdc_restore_reg(), not tomsdc_save_reg(). Am I confused?
No, you are absolutely correct, my bad. Thanks a lot for spotting this!
Kind regards
Uffe
PATCH v2 4/11 mmc: core: Move code to get pending SDIO IRQs to a function
In reply to Ulf HanssonFrom: Matthias Kaehlcke <[email protected]>
To improve code quality, let's move the code that gets pending SDIO IRQs from process_sdio_pending_irqs() into a dedicated function.
--- drivers/mmc/core/sdio_irq.c | 46 ++++++++++++++++++++++++------------- 1 file changed, 30 insertions(+), 16 deletions(-)
drivers/mmc/core/sdio_irq.c +30 -16
@@ -27,6 +27,34 @@#include "core.h" #include "card.h" +static int sdio_get_pending_irqs (struct mmc_host *host,u8 *pending) +{ +struct mmc_card *card = host->card; +int ret; + +WARN_ON (!host->claimed); + + ret =mmc_io_rw_direct (card,0 ,0 , SDIO_CCCR_INTx,0 , pending); +if (ret) { +pr_debug ("%s: error %d reading SDIO_CCCR_INTx\n" , +mmc_card_id (card), ret); +return ret; + } + +if (*pending &&mmc_card_broken_irq_polling (card) && + !(host->caps &MMC_CAP_SDIO_IRQ )) { +unsigned char dummy; + +/* A fake interrupt could be created when we poll SDIO_CCCR_INTx +* register with a Marvell SD8797 card. A dummy CMD52 read to +* function 0 register 0xff can avoid this. +*/ +mmc_io_rw_direct (card,0 ,0 ,0xff ,0 , &dummy); + } + +return 0 ; +} +static int process_sdio_pending_irqs (struct mmc_host *host) {struct mmc_card *card = host->card;
@@ -49,23 +77,9 @@ static int process_sdio_pending_irqs(struct mmc_host *host)return 1 ; } - ret =mmc_io_rw_direct (card,0 ,0 , SDIO_CCCR_INTx,0 , &pending); -if (ret) { -pr_debug ("%s: error %d reading SDIO_CCCR_INTx\n" , -mmc_card_id (card), ret); + ret =sdio_get_pending_irqs (host, &pending); +if (ret)return ret; - } - -if (pending &&mmc_card_broken_irq_polling (card) && - !(host->caps &MMC_CAP_SDIO_IRQ )) { -unsigned char dummy; - -/* A fake interrupt could be created when we poll SDIO_CCCR_INTx -* register with a Marvell SD8797 card. A dummy CMD52 read to -* function 0 register 0xff can avoid this. -*/ -mmc_io_rw_direct (card,0 ,0 ,0xff ,0 , &dummy); - } count =0 ;for (i =1 ; i <=7 ; i++) {
Signature · 1 line
2.17.1
Re: [PATCH v2 04/11] mmc: core: Move code to get pending SDIO IRQs to a function
Hi,
Quoted 6 lines · Ulf Hansson
From: Matthias Kaehlcke <[email protected]>
To improve code quality, let's move the code that gets pending SDIO IRQs from
process_sdio_pending_irqs()into a dedicated function.
Quoted 7 lines
Signed-off-by Matthias Kaehlcke <[email protected]>[Ulf: Converted function into static]Tested-by Matthias Kaehlcke <[email protected]>Signed-off-by Ulf Hansson <[email protected]>--- drivers/mmc/core/sdio_irq.c | 46 ++++++++++++++++++++++++------------- 1 file changed, 30 insertions(+), 16 deletions(-)
PATCH v2 5/11 mmc: core: Clarify sdio_irq_pending flag for MMC_CAP2_SDIO_IRQ_NOTHREAD
In reply to Ulf HanssonThe sdio_irq_pending flag is used to let host drivers indicate that it has signaled an IRQ. If that is the case and we only have a single SDIO func that have claimed an SDIO IRQ, our assumption is that we can avoid reading the SDIO_CCCR_INTx register and just call the SDIO func irq handler immediately. This makes sense, but the flag is set/cleared in a somewhat messy order, let's fix that up according to below.
First, the flag is currently set in sdio_run_irqs(), which is executed as a work that was scheduled from sdio_signal_irq(). To make it more implicit that the host have signaled an IRQ, let's instead immediately set the flag in sdio_signal_irq(). This also makes the behavior consistent with host drivers that uses the legacy, mmc_signal_sdio_irq() API. This have no functional impact, because we don't expect host drivers to call sdio_signal_irq() until after the work (sdio_run_irqs()) have been executed anyways.
Second, currently we never clears the flag when using the sdio_run_irqs() work, but only when using the sdio_irq_thread(). Let make the behavior consistent, by moving the flag to be cleared inside the common process_sdio_pending_irqs() function. Additionally, tweak the behavior of the flag slightly, by avoiding to clear it unless we processed the SDIO IRQ. The purpose with this at this point, is to keep the information about whether there have been an SDIO IRQ signaled by the host, so at system resume we can decide to process it without reading the SDIO_CCCR_INTx register.
---
Changes in v2:
- Re-wrote changelog.
--- drivers/mmc/core/sdio_irq.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/mmc/core/sdio_irq.c +6 -3
@@ -59,6 +59,7 @@ static int process_sdio_pending_irqs(struct mmc_host *host) {struct mmc_card *card = host->card;int i, ret, count; +bool sdio_irq_pending = host->sdio_irq_pending;unsigned char pending;struct sdio_func *func;
@@ -66,13 +67,16 @@ static int process_sdio_pending_irqs(struct mmc_host *host)if (mmc_card_suspended (card))return 0 ; +/* Clear the flag to indicate that we have processed the IRQ. */ + host->sdio_irq_pending = false; +/* * Optimization, if there is only 1 function interrupt registered * and we know an IRQ was signaled then call irq handler directly. * Otherwise do the full probe. */ func = card->sdio_single_irq; -if (func && host->sdio_irq_pending) { +if (func && sdio_irq_pending) { func->irq_handler (func);return 1 ; }
@@ -110,7 +114,6 @@ static void sdio_run_irqs(struct mmc_host *host) {mmc_claim_host (host);if (host->sdio_irqs) { - host->sdio_irq_pending = true;process_sdio_pending_irqs (host);if (host->ops->ack_sdio_irq) host->ops->ack_sdio_irq (host);
@@ -128,6 +131,7 @@ void sdio_irq_work(struct work_struct *work)void sdio_signal_irq (struct mmc_host *host) { + host->sdio_irq_pending = true;queue_delayed_work (system_wq, &host->sdio_irq_work,0 ); }EXPORT_SYMBOL_GPL (sdio_signal_irq);
@@ -173,7 +177,6 @@ static int sdio_irq_thread(void *_host)if (ret)break ; ret =process_sdio_pending_irqs (host); - host->sdio_irq_pending = false;mmc_release_host (host);/*
Signature · 1 line
2.17.1
Re: [PATCH v2 05/11] mmc: core: Clarify sdio_irq_pending flag for MMC_CAP2_SDIO_IRQ_NOTHREAD
Hi,
Quoted 17 lines · Ulf Hansson
The
sdio_irq_pendingflag is used to let host drivers indicate that it has signaled an IRQ. If that is the case and we only have a single SDIO func that have claimed an SDIO IRQ, our assumption is that we can avoid reading theSDIO_CCCR_INTxregister and just call the SDIO func irq handler immediately. This makes sense, but the flag is set/cleared in a somewhat messy order, let's fix that up according to below.First, the flag is currently set in
sdio_run_irqs(), which is executed as a work that was scheduled fromsdio_signal_irq(). To make it more implicit that the host have signaled an IRQ, let's instead immediately set the flag insdio_signal_irq(). This also makes the behavior consistent with host drivers that uses the legacy,mmc_signal_sdio_irq()API. This have no functional impact, because we don't expect host drivers to callsdio_signal_irq()until after the work (sdio_run_irqs()) have been executed anyways.
Quoted 2 lines
Second, currently we never clears the flag when using the
sdio_run_irqs()work, but only when using thesdio_irq_thread(). Let make the behavior
s/Let/Let's
Quoted 11 lines
consistent, by moving the flag to be cleared inside the common
process_sdio_pending_irqs()function. Additionally, tweak the behavior of the flag slightly, by avoiding to clear it unless we processed the SDIO IRQ. The purpose with this at this point, is to keep the information about whether there have been an SDIO IRQ signaled by the host, so at system resume we can decide to process it without reading theSDIO_CCCR_INTxregister.Tested-by Matthias Kaehlcke <[email protected]>Reviewed-by Matthias Kaehlcke <[email protected]>Signed-off-by Ulf Hansson <[email protected]>
Quoted 8 lines
---
Changes in v2:
- Re-wrote changelog.--- drivers/mmc/core/sdio_irq.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
PATCH v2 6/11 mmc: core: Clarify that the ->ack_sdio_irq() callback is mandatory
In reply to Ulf HanssonFor the MMC_CAP2_SDIO_IRQ_NOTHREAD case and when using sdio_signal_irq(), the ->ack_sdio_irq() is already mandatory, which was not the case for those host drivers that called sdio_run_irqs() directly.
As there are no longer any drivers calling sdio_run_irqs(), let's clarify the code by dropping the unnecessary check and explicitly state that the callback is mandatory in the header file.
--- drivers/mmc/core/sdio_irq.c | 3 +-- include/linux/mmc/host.h | 1 + 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/mmc/core/sdio_irq.c +1 -2
@@ -115,8 +115,7 @@ static void sdio_run_irqs(struct mmc_host *host)mmc_claim_host (host);if (host->sdio_irqs) {process_sdio_pending_irqs (host); -if (host->ops->ack_sdio_irq) - host->ops->ack_sdio_irq (host); + host->ops->ack_sdio_irq (host); }mmc_release_host (host); }
include/linux/mmc/host.h +1 -0
@@ -128,6 +128,7 @@ struct mmc_host_ops {int (*get_cd)(struct mmc_host *host);void (*enable_sdio_irq)(struct mmc_host *host,int enable); +/* Mandatory callback when using MMC_CAP2_SDIO_IRQ_NOTHREAD. */ void (*ack_sdio_irq)(struct mmc_host *host);/* optional callback for HC quirks */
Signature · 1 line
2.17.1
Re: [PATCH v2 06/11] mmc: core: Clarify that the ->ack_sdio_irq() callback is mandatory
Hi,
Quoted 9 lines · Ulf Hansson
For the
MMC_CAP2_SDIO_IRQ_NOTHREADcase and when usingsdio_signal_irq(), the ->ack_sdio_irq() is already mandatory, which was not the case for those host drivers that calledsdio_run_irqs()directly.As there are no longer any drivers calling
sdio_run_irqs(), let's clarify the code by dropping the unnecessary check and explicitly state that the callback is mandatory in the header file.
Quoted 7 lines
Tested-by Matthias Kaehlcke <[email protected]>Reviewed-by Matthias Kaehlcke <[email protected]>Signed-off-by Ulf Hansson <[email protected]>--- drivers/mmc/core/sdio_irq.c | 3 +-- include/linux/mmc/host.h | 1 + 2 files changed, 2 insertions(+), 2 deletions(-)
PATCH v2 7/11 mmc: core: WARN if SDIO IRQs are enabled for non-powered card in suspend
In reply to Ulf HanssonTo make sure SDIO func drivers behaves correctly during system suspend/resume, let add a WARN_ON in case the condition is a non-powered SDIO card and there are some SDIO IRQs still being claimed.
--- drivers/mmc/core/sdio.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/mmc/core/sdio.c +2 -0
@@ -951,6 +951,8 @@ static int mmc_sdio_pre_suspend(struct mmc_host *host)*/ static int mmc_sdio_suspend (struct mmc_host *host) { +WARN_ON (host->sdio_irqs && !mmc_card_keep_power (host)); +/* Prevent processing of SDIO IRQs in suspended state. */ mmc_card_set_suspended (host->card);cancel_delayed_work_sync (&host->sdio_irq_work);
Signature · 1 line
2.17.1
PATCH v2 8/11 mmc: core: Fixup processing of SDIO IRQs during system suspend/resume
In reply to Ulf HanssonSystem suspend/resume of SDIO cards, with SDIO IRQs enabled and when using MMC_CAP2_SDIO_IRQ_NOTHREAD is unfortunate still suffering from a fragile behaviour. Some problems have been taken care of so far, but more issues remains.
For example, calling the ->ack_sdio_irq() callback to let host drivers re-enable the SDIO IRQs is a bad idea, unless the IRQ have been consumed, which may not be the case during system suspend/resume. This may lead to that a host driver re-signals the same SDIO IRQ over and over again, causing a storm of IRQs and gives a ping-pong effect towards the sdio_irq_work().
Moreover, calling the ->enable_sdio_irq() callback at system resume to re-enable already enabled SDIO IRQs for the host, causes the runtime PM count for some host drivers to become in-balanced. This then leads to the host to remain runtime resumed, no matter if it's needed or not.
To fix these problems, let's check if process_sdio_pending_irqs() actually consumed the SDIO IRQ, before we continue to ack the IRQ by invoking the ->ack_sdio_irq() callback.
Additionally, there should be no need to re-enable SDIO IRQs as the host driver already knows if they were enabled at system suspend, thus also whether it needs to re-enable them at system resume. For this reason, drop the call to ->enable_sdio_irq() during system resume.
In regards to these changes there is yet another issue, which is when there is an SDIO IRQ being signaled by the host driver, but after the SDIO card has been system suspended. Currently these IRQs are just thrown away, while we should at least make sure to try to consume them when the SDIO card has been system resumed. Fix this by queueing a sdio_irq_work() after we system resumed the SDIO card.
---
Changes in v2:
- Queue a sdio_irq_work() rather using sdio_signal_irq().
--- drivers/mmc/core/sdio.c | 2 +- drivers/mmc/core/sdio_irq.c | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-)
drivers/mmc/core/sdio.c +1 -1
@@ -1015,7 +1015,7 @@ static int mmc_sdio_resume(struct mmc_host *host)if (!(host->caps2 &MMC_CAP2_SDIO_IRQ_NOTHREAD ))wake_up_process (host->sdio_irq_thread);else if (host->caps &MMC_CAP_SDIO_IRQ ) - host->ops->enable_sdio_irq (host,1 ); +queue_delayed_work (system_wq, &host->sdio_irq_work,0 ); } out:
drivers/mmc/core/sdio_irq.c +2 -1
@@ -115,7 +115,8 @@ static void sdio_run_irqs(struct mmc_host *host)mmc_claim_host (host);if (host->sdio_irqs) {process_sdio_pending_irqs (host); - host->ops->ack_sdio_irq (host); +if (!host->sdio_irq_pending) + host->ops->ack_sdio_irq (host); }mmc_release_host (host); }
Signature · 1 line
2.17.1
Re: [PATCH v2 08/11] mmc: core: Fixup processing of SDIO IRQs during system suspend/resume
Hi,
Quoted 39 lines · Ulf Hansson
System suspend/resume of SDIO cards, with SDIO IRQs enabled and when using
MMC_CAP2_SDIO_IRQ_NOTHREADis unfortunate still suffering from a fragile behaviour. Some problems have been taken care of so far, but more issues remains.For example, calling the ->ack_sdio_irq() callback to let host drivers re-enable the SDIO IRQs is a bad idea, unless the IRQ have been consumed, which may not be the case during system suspend/resume. This may lead to that a host driver re-signals the same SDIO IRQ over and over again, causing a storm of IRQs and gives a ping-pong effect towards the
sdio_irq_work().Moreover, calling the ->enable_sdio_irq() callback at system resume to re-enable already enabled SDIO IRQs for the host, causes the runtime PM count for some host drivers to become in-balanced. This then leads to the host to remain runtime resumed, no matter if it's needed or not.
To fix these problems, let's check if
process_sdio_pending_irqs()actually consumed the SDIO IRQ, before we continue to ack the IRQ by invoking the ->ack_sdio_irq() callback.Additionally, there should be no need to re-enable SDIO IRQs as the host driver already knows if they were enabled at system suspend, thus also whether it needs to re-enable them at system resume. For this reason, drop the call to ->enable_sdio_irq() during system resume.
In regards to these changes there is yet another issue, which is when there is an SDIO IRQ being signaled by the host driver, but after the SDIO card has been system suspended. Currently these IRQs are just thrown away, while we should at least make sure to try to consume them when the SDIO card has been system resumed. Fix this by queueing a
sdio_irq_work()after we system resumed the SDIO card.Tested-by Matthias Kaehlcke <[email protected]>Reviewed-by Matthias Kaehlcke <[email protected]>Signed-off-by Ulf Hansson <[email protected]>---
Quoted 7 lines
Changes in v2:
- Queue asdio_irq_work()rather usingsdio_signal_irq().--- drivers/mmc/core/sdio.c | 2 +- drivers/mmc/core/sdio_irq.c | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-)
PATCH v2 9/11 mmc: sdhci: Drop redundant check in sdhci_ack_sdio_irq()
In reply to Ulf HanssonThe sdhci_ack_sdio_irq() is called only when SDIO IRQs are enabled. Therefore, let's drop the redundant check of the internal SDHCI_SDIO_IRQ_ENABLED flag and just re-enable the IRQs immediately.
--- drivers/mmc/host/sdhci.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/mmc/host/sdhci.c +1 -2
@@ -2163,8 +2163,7 @@ static void sdhci_ack_sdio_irq(struct mmc_host *mmc)unsigned long flags;spin_lock_irqsave (&host->lock, flags); -if (host->flags &SDHCI_SDIO_IRQ_ENABLED ) -sdhci_enable_sdio_irq_nolock (host, true); +sdhci_enable_sdio_irq_nolock (host, true);spin_unlock_irqrestore (&host->lock, flags); }
Signature · 1 line
2.17.1
Re: [PATCH v2 09/11] mmc: sdhci: Drop redundant check in sdhci_ack_sdio_irq()
Quoted 6 lines · Ulf Hansson
The
sdhci_ack_sdio_irq()is called only when SDIO IRQs are enabled. Therefore, let's drop the redundant check of the internalSDHCI_SDIO_IRQ_ENABLEDflag and just re-enable the IRQs immediately.Reviewed-by Matthias Kaehlcke <[email protected]>Signed-off-by Ulf Hansson <[email protected]>
Quoted 19 lines
--- drivers/mmc/host/sdhci.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)drivers/mmc/host/sdhci.c +1
-2@@ -2163,8 +2163,7 @@ static void sdhci_ack_sdio_irq(struct mmc_host *mmc)unsigned long flags;spin_lock_irqsave (&host->lock, flags); -if (host->flags &SDHCI_SDIO_IRQ_ENABLED ) -sdhci_enable_sdio_irq_nolock (host, true); +sdhci_enable_sdio_irq_nolock (host, true);spin_unlock_irqrestore (&host->lock, flags); }
PATCH v2 10/11 mmc: sdhci: Drop redundant code for SDIO IRQs
In reply to Ulf HanssonNowadays sdhci prevents runtime suspend when SDIO IRQs are enabled.
However, some variants such as sdhci-esdhc-imx's, tries to allow runtime suspend while having the SDIO IRQs enabled, but without supporting remote wakeups. This support is a bit questionable, especially if the host device have a PM domain attached that can be power gated, but more importantly, the code have also become redundant (which was not the case when it was introduced).
Rather than keeping the redundant code around, let's drop it and leave this to be revisited later on.
--- drivers/mmc/host/sdhci-esdhc-imx.c | 34 +++++++++++++----------------- drivers/mmc/host/sdhci.c | 2 +- drivers/mmc/host/sdhci.h | 5 ----- 3 files changed, 16 insertions(+), 25 deletions(-)
drivers/mmc/host/sdhci-esdhc-imx.c +15 -19
@@ -1666,12 +1666,10 @@ static int sdhci_esdhc_runtime_suspend(struct device *dev)if (host->tuning_mode !=SDHCI_TUNING_MODE_3 )mmc_retune_needed (host->mmc); -if (!sdhci_sdio_irq_enabled (host)) { - imx_data->actual_clock = host->mmc->actual_clock; -esdhc_pltfm_set_clock (host,0 ); -clk_disable_unprepare (imx_data->clk_per); -clk_disable_unprepare (imx_data->clk_ipg); - } + imx_data->actual_clock = host->mmc->actual_clock; +esdhc_pltfm_set_clock (host,0 ); +clk_disable_unprepare (imx_data->clk_per); +clk_disable_unprepare (imx_data->clk_ipg);clk_disable_unprepare (imx_data->clk_ahb);if (imx_data->socdata->flags &ESDHC_FLAG_PMQOS )
@@ -1695,15 +1693,15 @@ static int sdhci_esdhc_runtime_resume(struct device *dev)if (err) goto remove_pm_qos_request; -if (!sdhci_sdio_irq_enabled (host)) { - err =clk_prepare_enable (imx_data->clk_per); -if (err) - goto disable_ahb_clk; - err =clk_prepare_enable (imx_data->clk_ipg); -if (err) - goto disable_per_clk; -esdhc_pltfm_set_clock (host, imx_data->actual_clock); - } + err =clk_prepare_enable (imx_data->clk_per); +if (err) + goto disable_ahb_clk; + + err =clk_prepare_enable (imx_data->clk_ipg); +if (err) + goto disable_per_clk; + +esdhc_pltfm_set_clock (host, imx_data->actual_clock); err =sdhci_runtime_resume_host (host,0 );if (err)
@@ -1715,11 +1713,9 @@ static int sdhci_esdhc_runtime_resume(struct device *dev)return err; disable_ipg_clk: -if (!sdhci_sdio_irq_enabled (host)) -clk_disable_unprepare (imx_data->clk_ipg); +clk_disable_unprepare (imx_data->clk_ipg); disable_per_clk: -if (!sdhci_sdio_irq_enabled (host)) -clk_disable_unprepare (imx_data->clk_per); +clk_disable_unprepare (imx_data->clk_per); disable_ahb_clk:clk_disable_unprepare (imx_data->clk_ahb); remove_pm_qos_request:
drivers/mmc/host/sdhci.c +1 -1
@@ -3048,7 +3048,7 @@ static irqreturn_t sdhci_irq(int irq, void *dev_id)spin_lock (&host->lock); -if (host->runtime_suspended && !sdhci_sdio_irq_enabled (host)) { +if (host->runtime_suspended) {spin_unlock (&host->lock);return IRQ_NONE ; }
drivers/mmc/host/sdhci.h +0 -5
@@ -753,11 +753,6 @@ static inline void sdhci_read_caps(struct sdhci_host *host)__sdhci_read_caps (host,NULL ,NULL ,NULL ); } -static inline bool sdhci_sdio_irq_enabled (struct sdhci_host *host) -{ -return !!(host->flags &SDHCI_SDIO_IRQ_ENABLED ); -} -u16 sdhci_calc_clk (struct sdhci_host *host,unsigned int clock,unsigned int *actual_clock);void sdhci_set_clock (struct sdhci_host *host,unsigned int clock);
Signature · 1 line
2.17.1
PATCH v2 11/11 mmc: sdhci: Convert to use sdio_irq_claimed()
In reply to Ulf HanssonInstead of keeping track of whether SDIO IRQs have been enabled via an internal sdhci status flag, avoid the open-coding and convert into using sdio_irq_claimed().
--- drivers/mmc/host/sdhci.c | 7 +------ drivers/mmc/host/sdhci.h | 1 - 2 files changed, 1 insertion(+), 7 deletions(-)
drivers/mmc/host/sdhci.c +1 -6
@@ -2144,11 +2144,6 @@ void sdhci_enable_sdio_irq(struct mmc_host *mmc, int enable)pm_runtime_get_noresume (host->mmc->parent);spin_lock_irqsave (&host->lock, flags); -if (enable) - host->flags |=SDHCI_SDIO_IRQ_ENABLED ; -else - host->flags &= ~SDHCI_SDIO_IRQ_ENABLED ; -sdhci_enable_sdio_irq_nolock (host, enable);spin_unlock_irqrestore (&host->lock, flags);
@@ -3382,7 +3377,7 @@ int sdhci_runtime_resume_host(struct sdhci_host *host, int soft_reset) host->runtime_suspended = false;/* Enable SDIO IRQ */ -if (host->flags &SDHCI_SDIO_IRQ_ENABLED ) +if (sdio_irq_claimed (mmc))sdhci_enable_sdio_irq_nolock (host, true);/* Enable Card Detection */
drivers/mmc/host/sdhci.h +0 -1
@@ -512,7 +512,6 @@ struct sdhci_host {#define SDHCI_AUTO_CMD12 (1<<6)/* Auto CMD12 support */ #define SDHCI_AUTO_CMD23 (1<<7)/* Auto CMD23 support */ #define SDHCI_PV_ENABLED (1<<8)/* Preset value enabled */ -#define SDHCI_SDIO_IRQ_ENABLED (1<<9)/* SDIO irq enabled */ #define SDHCI_USE_64_BIT_DMA (1<<12)/* Use 64-bit DMA */ #define SDHCI_HS400_TUNING (1<<13)/* Tuning for HS400 */ #define SDHCI_SIGNALING_330 (1<<14)/* Host is capable of 3.3V signaling */
Signature · 1 line
2.17.1
Quoted 50 lines · Ulf Hansson
Changes in v2:
- Added reviewed/tested-by tags.
- Updated some changelogs.
- Renamedsdio_irq_enabled()tosdio_irq_claimed().
- Don't setsdio_irq_pendingwhen resuming SDIO card, but just queue the work.The power management support for SDIO cards have slowly been improved, but there are still quite some serious problems, especially when dealing with the so called SDIO IRQs during system suspend/resume.
This series makes some additional improvements to this code in the mmc core, but also includes some needed adaptations for the sdhci, the
dw_mmcand the mtk-sd host drivers.The series is also available at:
git://git.kernel.org/pub/scm/linux/kernel/git/ulfh/mmc.gitsdio_irq_suspend_next_v2Kind regards
UffeMatthias Kaehlcke (1):
mmc: core: Move code to get pending SDIO IRQs to a functionUlf Hansson (10):
mmc: core: Add helper function to indicate if SDIO IRQs is enabled
mmc:dw_mmc: Re-store SDIO IRQs mask at system resume
mmc: mtk-sd: Re-store SDIO IRQs mask at system resume
mmc: core: Clarifysdio_irq_pendingflag for
MMC_CAP2_SDIO_IRQ_NOTHREAD
mmc: core: Clarify that the ->ack_sdio_irq() callback is mandatory
mmc: core: WARN if SDIO IRQs are enabled for non-powered card in
suspend
mmc: core: Fixup processing of SDIO IRQs during system suspend/resume
mmc: sdhci: Drop redundant check insdhci_ack_sdio_irq()
mmc: sdhci: Drop redundant code for SDIO IRQs
mmc: sdhci: Convert to usesdio_irq_claimed()drivers/mmc/core/sdio.c | 4 ++- drivers/mmc/core/sdio_irq.c | 57 +++++++++++++++++++----------- drivers/mmc/host/dw_mmc.c | 4 +++ drivers/mmc/host/mtk-sd.c | 3 ++ drivers/mmc/host/sdhci-esdhc-imx.c | 34 ++++++++---------- drivers/mmc/host/sdhci.c | 12 ++----- drivers/mmc/host/sdhci.h | 6 ---- include/linux/mmc/host.h | 10 ++++++ 8 files changed, 75 insertions(+), 55 deletions(-)
Quoted 3 lines
--
2.17.1
So, I have queued this up for next (using v3 of patch 3), thanks all for reviewing and testing!
Kind regards
Uffe