Skip to contentSkip to conversation

mmc: sdio: Keep card runtime resumed while adding function devices

PATCH Superseded Adrian Hunter 2 participants 3 messages May 18, 2017 – Jun 8, 2017 MMC, SD and SDIO

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mmc: sdio: Keep card runtime resumed while adding function devices

Drivers core will runtime suspend a device with no driver. That means the SDIO card will be runtime suspended as soon as it is added. It is then runtime resumed to add each function. That is entirely pointless, so add pm runtime get/put to keep the SDIO card runtime resumed until the function devices have been added.

---
 drivers/mmc/core/sdio.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
drivers/mmc/core/sdio.c +10 -1
index fae732c870a9..97bedde0610c 100644
@@ -1110,6 +1110,8 @@ int mmc_attach_sdio(struct mmc_host *host)
 		if (err)
 			goto remove;
 
+		pm_runtime_get_noresume(&card->dev);
+
 		/*
 		 * Enable runtime PM for this card
 		 */
@@ -1129,7 +1131,7 @@ int mmc_attach_sdio(struct mmc_host *host)
 	for (i = 0; i < funcs; i++, card->sdio_funcs++) {
 		err = sdio_init_func(host->card, i + 1);
 		if (err)
-			goto remove;
+			goto remove_get;
 
 		/*
 		 * Enable Runtime PM for this func (if supported)
@@ -1156,6 +1158,10 @@ int mmc_attach_sdio(struct mmc_host *host)
 	}
 
 	mmc_claim_host(host);
+
+	if (host->caps & MMC_CAP_POWER_OFF_CARD)
+		pm_runtime_put(&card->dev);
+
 	return 0;
 
 
@@ -1163,6 +1169,9 @@ int mmc_attach_sdio(struct mmc_host *host)
 	/* Remove without lock if the device has been added. */
 	mmc_sdio_remove(host);
 	mmc_claim_host(host);
+remove_get:
+	if (host->caps & MMC_CAP_POWER_OFF_CARD)
+		pm_runtime_put(&card->dev);
 remove:
 	/* And with lock if it hasn't been added. */
 	mmc_release_host(host);
Signature · 1 line
1.9.1
#1 lore raw
Quoted 7 lines · Adrian Hunter

Drivers core will runtime suspend a device with no driver. That means the SDIO card will be runtime suspended as soon as it is added. It is then runtime resumed to add each function. That is entirely pointless, so add pm runtime get/put to keep the SDIO card runtime resumed until the function devices have been added.

Adrian, apologize for the delay!

drivers/mmc/core/sdio.c int mmc_attach_sdio(struct mmc_host *host) · line 1113

Quoted 13 lines
---
 drivers/mmc/core/sdio.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
drivers/mmc/core/sdio.c +1 -0
index fae732c870a9..97bedde0610c 100644
@@ -1110,6 +1110,8 @@ int mmc_attach_sdio(struct mmc_host *host)
                if (err)
                        goto remove;
 
+               pm_runtime_get_noresume(&card->dev);

Please move this above pm_runtime_set_active(), just to be really sure the device remains active. Thus you also need to update the error path.

Quoted 25 lines
drivers/mmc/core/sdio.c +6 -1
+
                /*
                 * Enable runtime PM for this card
                 */
@@ -1129,7 +1131,7 @@ int mmc_attach_sdio(struct mmc_host *host)
        for (i = 0; i < funcs; i++, card->sdio_funcs++) {
                err = sdio_init_func(host->card, i + 1);
                if (err)
-                       goto remove;
+                       goto remove_get;
 
                /*
                 * Enable Runtime PM for this func (if supported)
@@ -1156,6 +1158,10 @@ int mmc_attach_sdio(struct mmc_host *host)
        }
 
        mmc_claim_host(host);
+
+       if (host->caps & MMC_CAP_POWER_OFF_CARD)
+               pm_runtime_put(&card->dev);
+
        return 0;
 
 

drivers/mmc/core/sdio.c int mmc_attach_sdio(struct mmc_host *host) · line 1174

Quoted 6 lines
drivers/mmc/core/sdio.c +3 -0
@@ -1163,6 +1169,9 @@ int mmc_attach_sdio(struct mmc_host *host)
        /* Remove without lock if the device has been added. */
        mmc_sdio_remove(host);
        mmc_claim_host(host);
+remove_get:
+       if (host->caps & MMC_CAP_POWER_OFF_CARD)
+               pm_runtime_put(&card->dev);

Looking in the error path, I also notice that there is a pm_runtime_disable missing. Would you mind fixing that (as a separate change of course) as well?

Quoted 6 lines
drivers/mmc/core/sdio.c +0 -1
 remove:
        /* And with lock if it hasn't been added. */
        mmc_release_host(host);
--

1.9.1

Kind regards
Uffe

#2 lore raw
Quoted 23 lines · Ulf Hansson
Quoted 7 lines · Adrian Hunter

Drivers core will runtime suspend a device with no driver. That means the SDIO card will be runtime suspended as soon as it is added. It is then runtime resumed to add each function. That is entirely pointless, so add pm runtime get/put to keep the SDIO card runtime resumed until the function devices have been added.

Adrian, apologize for the delay!

Quoted 12 lines
---
 drivers/mmc/core/sdio.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
drivers/mmc/core/sdio.c +0 -0
index fae732c870a9..97bedde0610c 100644
@@ -1110,6 +1110,8 @@ int mmc_attach_sdio(struct mmc_host *host)
                if (err)
                        goto remove;
 
Quoted 5 lines

drivers/mmc/core/sdio.c int mmc_attach_sdio(struct mmc_host *host) · line 1113

Quoted 1 line
drivers/mmc/core/sdio.c +1 -0
+               pm_runtime_get_noresume(&card->dev);

Please move this above pm_runtime_set_active(), just to be really sure the device remains active. Thus you also need to update the error path.

As you wish, but even if there was somehow another code path that could get a reference to this device, it couldn't runtime suspend it because it is not runtime enabled.

Quoted 25 lines
Quoted 25 lines
drivers/mmc/core/sdio.c +6 -1
+
                /*
                 * Enable runtime PM for this card
                 */
@@ -1129,7 +1131,7 @@ int mmc_attach_sdio(struct mmc_host *host)
        for (i = 0; i < funcs; i++, card->sdio_funcs++) {
                err = sdio_init_func(host->card, i + 1);
                if (err)
-                       goto remove;
+                       goto remove_get;
 
                /*
                 * Enable Runtime PM for this func (if supported)
@@ -1156,6 +1158,10 @@ int mmc_attach_sdio(struct mmc_host *host)
        }
 
        mmc_claim_host(host);
+
+       if (host->caps & MMC_CAP_POWER_OFF_CARD)
+               pm_runtime_put(&card->dev);
+
        return 0;
 
 
Quoted 7 lines

drivers/mmc/core/sdio.c int mmc_attach_sdio(struct mmc_host *host) · line 1174

Quoted 7 lines
drivers/mmc/core/sdio.c +3 -0
@@ -1163,6 +1169,9 @@ int mmc_attach_sdio(struct mmc_host *host)
        /* Remove without lock if the device has been added. */
        mmc_sdio_remove(host);
        mmc_claim_host(host);
+remove_get:
+       if (host->caps & MMC_CAP_POWER_OFF_CARD)
+               pm_runtime_put(&card->dev);

I notice this is wrong here - it needs to be before mmc_sdio_remove() because mmc_sdio_remove() deletes the devices.

Quoted 4 lines

Looking in the error path, I also notice that there is a pm_runtime_disable missing. Would you mind fixing that (as a separate change of course) as well?

We can't call pm_runtime_disable() after mmc_sdio_remove() because mmc_sdio_remove() deletes the devices. device_del() anyway takes care of runtime pm (i.e. ends up calling __pm_runtime_disable()).

If we call pm_runtime_disable() before mmc_sdio_remove() then it results in the devices staying in the pm state they were in at that point. The ->remove() callbacks expect that to be "active" but AFAICT they in turn leave the devices "suspended", so we would end up changing the current behaviour.

So it looks to me like we don't need to call pm_runtime_disable() and we can't call it here without side-effects.

Quoted 11 lines
Quoted 7 lines
drivers/mmc/core/sdio.c +0 -1
 remove:
        /* And with lock if it hasn't been added. */
        mmc_release_host(host);
--

1.9.1

Kind regards
Uffe