Skip to contentSkip to conversation

mmc: block: Fix tuning (by avoiding it) for RPMB

PATCH Applied Adrian Hunter 3 participants 16 messages May 4, 2016 – May 18, 2016 MMC, SD and SDIO

lore
Share & tools
lore
#0 lore raw

v2 cover mmc: block: Fix tuning (by avoiding it) for RPMB

Hi

The RPMB partition only allows certain commands. In particular, the tuning command (CMD21) is not allowed - refer JEDEC eMMC standard v5.1 section 6.2.2 Command restrictions.

That means commands will begin failing if re-tuning is needed while switched to the RPMB partition.

As we discussed here:

	http://marc.info/?l=linux-mmc&m=146218765801869

this patch set takes a new approach which is:

Re-tune before switching to the RPMB partition Don't allow re-tuning while switched to RPMB Switch back from the RPMB partition immediately

I gave it a brief test with a HS400 eMMC and using mmc utils to access RPMB. Despite all the partition switches and re-tuning in between, all RPMB operations were successful.

Changes in V2:

New approach entirely

Adrian Hunter (3):
mmc: core: Add a facility to "pause" re-tuning
mmc: block: Always switch back to main area after RPMB access
mmc: block: Pause re-tuning while switched to the RPMB partition

 drivers/mmc/card/block.c | 19 ++++++++++++++++++-
 drivers/mmc/core/host.c  | 22 ++++++++++++++++++++++
 include/linux/mmc/host.h |  4 ++++
 3 files changed, 44 insertions(+), 1 deletion(-)

Regards
Adrian

#1 lore raw

PATCH v2 1/3 mmc: core: Add a facility to "pause" re-tuning

Re-tuning is not possible when switched to the RPMB partition. However re-tuning should not be needed if re-tuning is done immediately before switching, a small set of operations is done, and then we immediately switch back to the main partition.

To ensure that re-tuning can't be done for a short while, add a facility to "pause" re-tuning.

The existing facility to hold / release re-tuning is used but it also flags re-tuning as needed to cause re-tuning before the next command (which will be the switch to RPMB).

We also need to "unpause" in the recovery path, which is catered for by adding it to mmc_retune_disable().

---
 drivers/mmc/core/host.c  | 22 ++++++++++++++++++++++
 include/linux/mmc/host.h |  4 ++++
 2 files changed, 26 insertions(+)
drivers/mmc/core/host.c +22 -0
index e0a3ee16c0d3..302e5858755a 100644
@@ -68,8 +68,30 @@ void mmc_retune_enable(struct mmc_host *host)
 			  jiffies + host->retune_period * HZ);
 }
 
+/*
+ * Pause re-tuning for a small set of operations.  The pause begins after the
+ * next command and after first doing re-tuning.
+ */
+void mmc_retune_pause(struct mmc_host *host)
+{
+	if (!host->retune_paused) {
+		host->retune_paused = 1;
+		mmc_retune_needed(host);
+		mmc_retune_hold(host);
+	}
+}
+
+void mmc_retune_unpause(struct mmc_host *host)
+{
+	if (host->retune_paused) {
+		host->retune_paused = 0;
+		mmc_retune_release(host);
+	}
+}
+
 void mmc_retune_disable(struct mmc_host *host)
 {
+	mmc_retune_unpause(host);
 	host->can_retune = 0;
 	del_timer_sync(&host->retune_timer);
 	host->retune_now = 0;
include/linux/mmc/host.h +4 -0
index 85800b48241f..45cde8cd39f2 100644
@@ -329,6 +329,7 @@ struct mmc_host {
 	unsigned int		can_retune:1;	/* re-tuning can be used */
 	unsigned int		doing_retune:1;	/* re-tuning in progress */
 	unsigned int		retune_now:1;	/* do re-tuning at next req */
+	unsigned int		retune_paused:1; /* re-tuning is temporarily disabled */
 
 	int			rescan_disable;	/* disable card detection */
 	int			rescan_entered;	/* used with nonremovable devices */
@@ -526,4 +527,7 @@ static inline void mmc_retune_recheck(struct mmc_host *host)
 		host->retune_now = 1;
 }
 
+void mmc_retune_pause(struct mmc_host *host);
+void mmc_retune_unpause(struct mmc_host *host);
+
 #endif /* LINUX_MMC_HOST_H */
Signature · 1 line
1.9.1
#12 lore raw

PATCH v2 2/3 mmc: block: Always switch back to main area after RPMB access

In reply to Adrian Hunter

In preparation to support the use of the RPMB partition with transfer modes that might require re-tuning, always switch back to the main area after RPMB access.

RPMB is accessible only via IOCTL so only those paths are affected.

---
 drivers/mmc/card/block.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/mmc/card/block.c +8 -0
index 9ce679255775..a65043854458 100644
@@ -618,6 +618,10 @@ static int mmc_blk_ioctl_cmd(struct block_device *bdev,
 
 	ioc_err = __mmc_blk_ioctl_cmd(card, md, idata);
 
+	/* Always switch back to main area after RPMB access */
+	if (md->area_type & MMC_BLK_DATA_AREA_RPMB)
+		mmc_blk_part_switch(card, dev_get_drvdata(&card->dev));
+
 	mmc_put_card(card);
 
 	err = mmc_blk_ioctl_copy_to_user(ic_ptr, idata);
@@ -685,6 +689,10 @@ static int mmc_blk_ioctl_multi_cmd(struct block_device *bdev,
 	for (i = 0; i < num_of_cmds && !ioc_err; i++)
 		ioc_err = __mmc_blk_ioctl_cmd(card, md, idata[i]);
 
+	/* Always switch back to main area after RPMB access */
+	if (md->area_type & MMC_BLK_DATA_AREA_RPMB)
+		mmc_blk_part_switch(card, dev_get_drvdata(&card->dev));
+
 	mmc_put_card(card);
 
 	/* copy to user if data and response */
Signature · 1 line
1.9.1
#13 lore raw

PATCH v2 3/3 mmc: block: Pause re-tuning while switched to the RPMB partition

In reply to Adrian Hunter

Re-tuning is not possible when switched to the RPMB partition. However re-tuning should not be needed if re-tuning is done immediately before switching, a small set of operations is done, and then we immediately switch back to the main partition.

A previous patch ensured that we immediately switch back to the main partition.

This patch uses the new facility to "pause" re-tuning before switching to the RPMB partition, and to "unpause" it after switching from the RPMB partition.

---
 drivers/mmc/card/block.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
drivers/mmc/card/block.c +10 -1
index a65043854458..565009b190cd 100644
@@ -756,16 +756,25 @@ static inline int mmc_blk_part_switch(struct mmc_card *card,
 	if (mmc_card_mmc(card)) {
 		u8 part_config = card->ext_csd.part_config;
 
+		if (md->part_type == EXT_CSD_PART_CONFIG_ACC_RPMB)
+			mmc_retune_pause(card->host);
+
 		part_config &= ~EXT_CSD_PART_CONFIG_ACC_MASK;
 		part_config |= md->part_type;
 
 		ret = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
 				 EXT_CSD_PART_CONFIG, part_config,
 				 card->ext_csd.part_time);
-		if (ret)
+		if (ret) {
+			if (md->part_type == EXT_CSD_PART_CONFIG_ACC_RPMB)
+				mmc_retune_unpause(card->host);
 			return ret;
+		}
 
 		card->ext_csd.part_config = part_config;
+
+		if (main_md->part_curr == EXT_CSD_PART_CONFIG_ACC_RPMB)
+			mmc_retune_unpause(card->host);
 	}
 
 	main_md->part_curr = md->part_type;
Signature · 1 line
1.9.1
#14 lore raw
In reply to Adrian Hunter
Quoted 44 lines

-----Original Message-----
From: Hunter, Adrian
Sent: Wednesday, May 04, 2016 14:38
To: Ulf Hansson <[email protected]>
Cc: linux-mmc <[email protected]>; Winkler, Tomas <[email protected]>
Subject: [PATCH V2 0/3] mmc: block: Fix tuning (by avoiding it) for RPMB

Hi

The RPMB partition only allows certain commands. In particular, the tuning command (CMD21) is not allowed - refer JEDEC eMMC standard v5.1 section 6.2.2 Command restrictions.

That means commands will begin failing if re-tuning is needed while switched to the RPMB partition.

As we discussed here:

	http://marc.info/?l=linux-mmc&m=146218765801869

this patch set takes a new approach which is:

Re-tune before switching to the RPMB partition Don't allow re-tuning while switched to RPMB Switch back from the RPMB partition immediately

I gave it a brief test with a HS400 eMMC and using mmc utils to access RPMB. Despite all the partition switches and re-tuning in between, all RPMB operations were successful.

Changes in V2:

New approach entirely

Adrian Hunter (3):
mmc: core: Add a facility to "pause" re-tuning
mmc: block: Always switch back to main area after RPMB access
mmc: block: Pause re-tuning while switched to the RPMB partition

Quoted 5 lines
 drivers/mmc/card/block.c | 19 ++++++++++++++++++-
drivers/mmc/core/host.c  | 22 ++++++++++++++++++++++
include/linux/mmc/host.h |  4 ++++
 3 files changed, 44 insertions(+), 1 deletion(-)

The series looks good, it will be easy to adjust to my RPMB patch. Thanks
Tomas

Applied
#15 lore raw
In reply to Adrian Hunter
Quoted 34 lines · Adrian Hunter

Hi

The RPMB partition only allows certain commands. In particular, the tuning command (CMD21) is not allowed - refer JEDEC eMMC standard v5.1 section 6.2.2 Command restrictions.

That means commands will begin failing if re-tuning is needed while switched to the RPMB partition.

As we discussed here:

        http://marc.info/?l=linux-mmc&m=146218765801869

this patch set takes a new approach which is:

Re-tune before switching to the RPMB partition Don't allow re-tuning while switched to RPMB Switch back from the RPMB partition immediately

I gave it a brief test with a HS400 eMMC and using mmc utils to access RPMB. Despite all the partition switches and re-tuning in between, all RPMB operations were successful.

Changes in V2:

New approach entirely

Adrian Hunter (3):
mmc: core: Add a facility to "pause" re-tuning
mmc: block: Always switch back to main area after RPMB access
mmc: block: Pause re-tuning while switched to the RPMB partition

Quoted 8 lines
 drivers/mmc/card/block.c | 19 ++++++++++++++++++-
 drivers/mmc/core/host.c  | 22 ++++++++++++++++++++++
 include/linux/mmc/host.h |  4 ++++
 3 files changed, 44 insertions(+), 1 deletion(-)

Regards
Adrian

Thanks, applied for next!

Kind regards
Uffe

#2 lore raw

Re: [PATCH V2 1/3] mmc: core: Add a facility to "pause" re-tuning

In reply to Adrian Hunter
Quoted 34 lines · Adrian Hunter

Re-tuning is not possible when switched to the RPMB partition. However re-tuning should not be needed if re-tuning is done immediately before switching, a small set of operations is done, and then we immediately switch back to the main partition.

To ensure that re-tuning can't be done for a short while, add a facility to "pause" re-tuning.

The existing facility to hold / release re-tuning is used but it also flags re-tuning as needed to cause re-tuning before the next command (which will be the switch to RPMB).

We also need to "unpause" in the recovery path, which is catered for by adding it to mmc_retune_disable().

---
 drivers/mmc/core/host.c  | 22 ++++++++++++++++++++++
 include/linux/mmc/host.h |  4 ++++
 2 files changed, 26 insertions(+)
drivers/mmc/core/host.c +3 -0
index e0a3ee16c0d3..302e5858755a 100644
@@ -68,8 +68,30 @@ void mmc_retune_enable(struct mmc_host *host)
                          jiffies + host->retune_period * HZ);
 }
 
+/*
+ * Pause re-tuning for a small set of operations.  The pause begins after the
+ * next command and after first doing re-tuning.

drivers/mmc/core/host.c void mmc_retune_enable(struct mmc_host *host) · line 83

Quoted 10 lines
drivers/mmc/core/host.c +10 -0
+ */
+void mmc_retune_pause(struct mmc_host *host)
+{
+       if (!host->retune_paused) {
+               host->retune_paused = 1;
+               mmc_retune_needed(host);
+               mmc_retune_hold(host);
+       }
+}
+

When the mmc block device driver is built as a module, this doesn't build. I will drop the series from my next branch to sort this out.

Should we export these via EXPORT_SYMBOL_GPL, or implement them as inline functions?

This also made me think about the SDIO/WLAN driver issue, during system PM suspend/resume, which also needed temporary to disable re-tuning.

*If* we are going to export these, I want to make it works for the SDIO case well...

Kind regards
Uffe

Quoted 37 lines
drivers/mmc/core/host.c +9 -0
+void mmc_retune_unpause(struct mmc_host *host)
+{
+       if (host->retune_paused) {
+               host->retune_paused = 0;
+               mmc_retune_release(host);
+       }
+}
+
 void mmc_retune_disable(struct mmc_host *host)
 {
+       mmc_retune_unpause(host);
        host->can_retune = 0;
        del_timer_sync(&host->retune_timer);
        host->retune_now = 0;
include/linux/mmc/host.h +4 -1
index 85800b48241f..45cde8cd39f2 100644
@@ -329,6 +329,7 @@ struct mmc_host {
        unsigned int            can_retune:1;   /* re-tuning can be used */
        unsigned int            doing_retune:1; /* re-tuning in progress */
        unsigned int            retune_now:1;   /* do re-tuning at next req */
+       unsigned int            retune_paused:1; /* re-tuning is temporarily disabled */
 
        int                     rescan_disable; /* disable card detection */
        int                     rescan_entered; /* used with nonremovable devices */
@@ -526,4 +527,7 @@ static inline void mmc_retune_recheck(struct mmc_host *host)
                host->retune_now = 1;
 }
 
+void mmc_retune_pause(struct mmc_host *host);
+void mmc_retune_unpause(struct mmc_host *host);
+
 #endif /* LINUX_MMC_HOST_H */
--

1.9.1

#3 lore raw

Re: [PATCH V2 1/3] mmc: core: Add a facility to "pause" re-tuning

Quoted 32 lines · Ulf Hansson
Quoted 31 lines · Adrian Hunter

Re-tuning is not possible when switched to the RPMB partition. However re-tuning should not be needed if re-tuning is done immediately before switching, a small set of operations is done, and then we immediately switch back to the main partition.

To ensure that re-tuning can't be done for a short while, add a facility to "pause" re-tuning.

The existing facility to hold / release re-tuning is used but it also flags re-tuning as needed to cause re-tuning before the next command (which will be the switch to RPMB).

We also need to "unpause" in the recovery path, which is catered for by adding it to mmc_retune_disable().

---
 drivers/mmc/core/host.c  | 22 ++++++++++++++++++++++
 include/linux/mmc/host.h |  4 ++++
 2 files changed, 26 insertions(+)
drivers/mmc/core/host.c +0 -0
index e0a3ee16c0d3..302e5858755a 100644
@@ -68,8 +68,30 @@ void mmc_retune_enable(struct mmc_host *host)
                          jiffies + host->retune_period * HZ);
 }
 
Quoted 16 lines

drivers/mmc/core/host.c void mmc_retune_enable(struct mmc_host *host) · line 83

Quoted 13 lines
drivers/mmc/core/host.c +13 -0
+/*
+ * Pause re-tuning for a small set of operations.  The pause begins after the
+ * next command and after first doing re-tuning.
+ */
+void mmc_retune_pause(struct mmc_host *host)
+{
+       if (!host->retune_paused) {
+               host->retune_paused = 1;
+               mmc_retune_needed(host);
+               mmc_retune_hold(host);
+       }
+}
+

When the mmc block device driver is built as a module, this doesn't build. I will drop the series from my next branch to sort this out.

Oops. Sorry!

Quoted 2 lines

Should we export these via EXPORT_SYMBOL_GPL, or implement them as inline functions?

They need to be exported. I tend to go with what else is in the same file i.e. host.c is exporting using EXPORT_SYMBOL()

Quoted 7 lines

This also made me think about the SDIO/WLAN driver issue, during system PM suspend/resume, which also needed temporary to disable re-tuning.

*If* we are going to export these, I want to make it works for the SDIO case well...

SDIO case is slightly different, and SDIO uses its own header file sdio_func.h.

Quoted 42 lines

Kind regards
Uffe

Quoted 37 lines
drivers/mmc/core/host.c +9 -0
+void mmc_retune_unpause(struct mmc_host *host)
+{
+       if (host->retune_paused) {
+               host->retune_paused = 0;
+               mmc_retune_release(host);
+       }
+}
+
 void mmc_retune_disable(struct mmc_host *host)
 {
+       mmc_retune_unpause(host);
        host->can_retune = 0;
        del_timer_sync(&host->retune_timer);
        host->retune_now = 0;
include/linux/mmc/host.h +4 -1
index 85800b48241f..45cde8cd39f2 100644
@@ -329,6 +329,7 @@ struct mmc_host {
        unsigned int            can_retune:1;   /* re-tuning can be used */
        unsigned int            doing_retune:1; /* re-tuning in progress */
        unsigned int            retune_now:1;   /* do re-tuning at next req */
+       unsigned int            retune_paused:1; /* re-tuning is temporarily disabled */
 
        int                     rescan_disable; /* disable card detection */
        int                     rescan_entered; /* used with nonremovable devices */
@@ -526,4 +527,7 @@ static inline void mmc_retune_recheck(struct mmc_host *host)
                host->retune_now = 1;
 }
 
+void mmc_retune_pause(struct mmc_host *host);
+void mmc_retune_unpause(struct mmc_host *host);
+
 #endif /* LINUX_MMC_HOST_H */
--

1.9.1

#4 lore raw

Re: [PATCH V2 1/3] mmc: core: Add a facility to "pause" re-tuning

Quoted 50 lines · Adrian Hunter
Quoted 32 lines · Ulf Hansson
Quoted 31 lines · Adrian Hunter

Re-tuning is not possible when switched to the RPMB partition. However re-tuning should not be needed if re-tuning is done immediately before switching, a small set of operations is done, and then we immediately switch back to the main partition.

To ensure that re-tuning can't be done for a short while, add a facility to "pause" re-tuning.

The existing facility to hold / release re-tuning is used but it also flags re-tuning as needed to cause re-tuning before the next command (which will be the switch to RPMB).

We also need to "unpause" in the recovery path, which is catered for by adding it to mmc_retune_disable().

---
 drivers/mmc/core/host.c  | 22 ++++++++++++++++++++++
 include/linux/mmc/host.h |  4 ++++
 2 files changed, 26 insertions(+)
drivers/mmc/core/host.c +0 -0
index e0a3ee16c0d3..302e5858755a 100644
@@ -68,8 +68,30 @@ void mmc_retune_enable(struct mmc_host *host)
                          jiffies + host->retune_period * HZ);
 }
 
Quoted 16 lines

drivers/mmc/core/host.c void mmc_retune_enable(struct mmc_host *host) · line 83

Quoted 13 lines
drivers/mmc/core/host.c +13 -0
+/*
+ * Pause re-tuning for a small set of operations.  The pause begins after the
+ * next command and after first doing re-tuning.
+ */
+void mmc_retune_pause(struct mmc_host *host)
+{
+       if (!host->retune_paused) {
+               host->retune_paused = 1;
+               mmc_retune_needed(host);
+               mmc_retune_hold(host);
+       }
+}
+

When the mmc block device driver is built as a module, this doesn't build. I will drop the series from my next branch to sort this out.

Quoted 7 lines

Oops. Sorry!

Quoted 2 lines

Should we export these via EXPORT_SYMBOL_GPL, or implement them as inline functions?

They need to be exported. I tend to go with what else is in the same file i.e. host.c is exporting using EXPORT_SYMBOL()

Yes, okay!

Quoted 10 lines
Quoted 8 lines

This also made me think about the SDIO/WLAN driver issue, during system PM suspend/resume, which also needed temporary to disable re-tuning.

*If* we are going to export these, I want to make it works for the SDIO case well...

SDIO case is slightly different, and SDIO uses its own header file sdio_func.h.

I what way is it different?

Regarding the header file, my point is that I want to keep the numbers of exported functions to a minimum.

Do you think there is way to combine these two use cases, such only one pair of new functions would be needed?

Kind regards
Uffe

#5 lore raw

Re: [PATCH V2 1/3] mmc: core: Add a facility to "pause" re-tuning

Quoted 67 lines · Ulf Hansson
Quoted 50 lines · Adrian Hunter
Quoted 32 lines · Ulf Hansson
Quoted 31 lines · Adrian Hunter

Re-tuning is not possible when switched to the RPMB partition. However re-tuning should not be needed if re-tuning is done immediately before switching, a small set of operations is done, and then we immediately switch back to the main partition.

To ensure that re-tuning can't be done for a short while, add a facility to "pause" re-tuning.

The existing facility to hold / release re-tuning is used but it also flags re-tuning as needed to cause re-tuning before the next command (which will be the switch to RPMB).

We also need to "unpause" in the recovery path, which is catered for by adding it to mmc_retune_disable().

---
 drivers/mmc/core/host.c  | 22 ++++++++++++++++++++++
 include/linux/mmc/host.h |  4 ++++
 2 files changed, 26 insertions(+)
drivers/mmc/core/host.c +0 -0
index e0a3ee16c0d3..302e5858755a 100644
@@ -68,8 +68,30 @@ void mmc_retune_enable(struct mmc_host *host)
                          jiffies + host->retune_period * HZ);
 }
 
Quoted 16 lines

drivers/mmc/core/host.c void mmc_retune_enable(struct mmc_host *host) · line 83

Quoted 13 lines
drivers/mmc/core/host.c +13 -0
+/*
+ * Pause re-tuning for a small set of operations.  The pause begins after the
+ * next command and after first doing re-tuning.
+ */
+void mmc_retune_pause(struct mmc_host *host)
+{
+       if (!host->retune_paused) {
+               host->retune_paused = 1;
+               mmc_retune_needed(host);
+               mmc_retune_hold(host);
+       }
+}
+

When the mmc block device driver is built as a module, this doesn't build. I will drop the series from my next branch to sort this out.

Quoted 7 lines

Oops. Sorry!

Quoted 2 lines

Should we export these via EXPORT_SYMBOL_GPL, or implement them as inline functions?

They need to be exported. I tend to go with what else is in the same file i.e. host.c is exporting using EXPORT_SYMBOL()

Yes, okay!

Quoted 6 lines
Quoted 6 lines

This also made me think about the SDIO/WLAN driver issue, during system PM suspend/resume, which also needed temporary to disable re-tuning.

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

*If* we are going to export these, I want to make it works for the SDIO case well...

SDIO case is slightly different, and SDIO uses its own header file sdio_func.h.

I what way is it different?

In the RPMB case there are 3 things to do:
1. Do re-tuning at next command
2. Hold re-tuning
3. Release re-tuning

In the SDIO case there are 3 things to do:
1. Prevent re-tuning at next command
2. Hold re-tuning
3. Release re-tuning

So the first thing is different.

Quoted 6 lines

Regarding the header file, my point is that I want to keep the numbers of exported functions to a minimum.

Do you think there is way to combine these two use cases, such only one pair of new functions would be needed?

To make them the same we would need to add a parameter to mmc_retune_pause() i.e. something like

void mmc_retune_pause(struct mmc_host *host, bool retune_now)

{
	if (!host->retune_paused) {
		host->retune_paused = 1;
		mmc_retune_hold(host);
		if (retune_now)
			mmc_retune_needed(host);
		else
			host->retune_now = 0;
	}
}

For SDIO we would need to put the function declarations in sdio_func.h as well as host.h.

Shall I make a V3 of these patches like that?

#6 lore raw

Re: [PATCH V2 1/3] mmc: core: Add a facility to "pause" re-tuning

Quoted 109 lines · Adrian Hunter
Quoted 67 lines · Ulf Hansson
Quoted 50 lines · Adrian Hunter
Quoted 32 lines · Ulf Hansson
Quoted 31 lines · Adrian Hunter

Re-tuning is not possible when switched to the RPMB partition. However re-tuning should not be needed if re-tuning is done immediately before switching, a small set of operations is done, and then we immediately switch back to the main partition.

To ensure that re-tuning can't be done for a short while, add a facility to "pause" re-tuning.

The existing facility to hold / release re-tuning is used but it also flags re-tuning as needed to cause re-tuning before the next command (which will be the switch to RPMB).

We also need to "unpause" in the recovery path, which is catered for by adding it to mmc_retune_disable().

---
 drivers/mmc/core/host.c  | 22 ++++++++++++++++++++++
 include/linux/mmc/host.h |  4 ++++
 2 files changed, 26 insertions(+)
drivers/mmc/core/host.c +0 -0
index e0a3ee16c0d3..302e5858755a 100644
@@ -68,8 +68,30 @@ void mmc_retune_enable(struct mmc_host *host)
                          jiffies + host->retune_period * HZ);
 }
 
Quoted 16 lines

drivers/mmc/core/host.c void mmc_retune_enable(struct mmc_host *host) · line 83

Quoted 13 lines
drivers/mmc/core/host.c +13 -0
+/*
+ * Pause re-tuning for a small set of operations.  The pause begins after the
+ * next command and after first doing re-tuning.
+ */
+void mmc_retune_pause(struct mmc_host *host)
+{
+       if (!host->retune_paused) {
+               host->retune_paused = 1;
+               mmc_retune_needed(host);
+               mmc_retune_hold(host);
+       }
+}
+

When the mmc block device driver is built as a module, this doesn't build. I will drop the series from my next branch to sort this out.

Quoted 7 lines

Oops. Sorry!

Quoted 2 lines

Should we export these via EXPORT_SYMBOL_GPL, or implement them as inline functions?

They need to be exported. I tend to go with what else is in the same file i.e. host.c is exporting using EXPORT_SYMBOL()

Yes, okay!

Quoted 6 lines
Quoted 6 lines

This also made me think about the SDIO/WLAN driver issue, during system PM suspend/resume, which also needed temporary to disable re-tuning.

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

*If* we are going to export these, I want to make it works for the SDIO case well...

SDIO case is slightly different, and SDIO uses its own header file sdio_func.h.

I what way is it different?

In the RPMB case there are 3 things to do:
1. Do re-tuning at next command
2. Hold re-tuning
3. Release re-tuning

In the SDIO case there are 3 things to do:
1. Prevent re-tuning at next command
2. Hold re-tuning
3. Release re-tuning

So the first thing is different.

Quoted 6 lines

Regarding the header file, my point is that I want to keep the numbers of exported functions to a minimum.

Do you think there is way to combine these two use cases, such only one pair of new functions would be needed?

To make them the same we would need to add a parameter to mmc_retune_pause() i.e. something like

void mmc_retune_pause(struct mmc_host *host, bool retune_now)

{
	if (!host->retune_paused) {
		host->retune_paused = 1;
		mmc_retune_hold(host);
		if (retune_now)
			mmc_retune_needed(host);
		else
			host->retune_now = 0;
	}
}
Quoted 4 lines

For SDIO we would need to put the function declarations in sdio_func.h as well as host.h.

Shall I make a V3 of these patches like that?

I looked again at sdio_func.h and it seems to have its own paradigm i.e. it is a completely separate set of functions that take the SDIO function as a parameter, and that hide and encapsulate core and host functions.

It would be inconsistent with that paradigm to expose mmc_retune_pause() and mmc_retune_unpause() there. Is that what you want to do?

#7 lore raw

Re: [PATCH V2 1/3] mmc: core: Add a facility to "pause" re-tuning

Quoted 110 lines · Adrian Hunter
Quoted 109 lines · Adrian Hunter
Quoted 67 lines · Ulf Hansson
Quoted 50 lines · Adrian Hunter
Quoted 32 lines · Ulf Hansson
Quoted 31 lines · Adrian Hunter

Re-tuning is not possible when switched to the RPMB partition. However re-tuning should not be needed if re-tuning is done immediately before switching, a small set of operations is done, and then we immediately switch back to the main partition.

To ensure that re-tuning can't be done for a short while, add a facility to "pause" re-tuning.

The existing facility to hold / release re-tuning is used but it also flags re-tuning as needed to cause re-tuning before the next command (which will be the switch to RPMB).

We also need to "unpause" in the recovery path, which is catered for by adding it to mmc_retune_disable().

---
 drivers/mmc/core/host.c  | 22 ++++++++++++++++++++++
 include/linux/mmc/host.h |  4 ++++
 2 files changed, 26 insertions(+)
drivers/mmc/core/host.c +0 -0
index e0a3ee16c0d3..302e5858755a 100644
@@ -68,8 +68,30 @@ void mmc_retune_enable(struct mmc_host *host)
                          jiffies + host->retune_period * HZ);
 }
 
Quoted 16 lines

drivers/mmc/core/host.c void mmc_retune_enable(struct mmc_host *host) · line 83

Quoted 13 lines
drivers/mmc/core/host.c +13 -0
+/*
+ * Pause re-tuning for a small set of operations.  The pause begins after the
+ * next command and after first doing re-tuning.
+ */
+void mmc_retune_pause(struct mmc_host *host)
+{
+       if (!host->retune_paused) {
+               host->retune_paused = 1;
+               mmc_retune_needed(host);
+               mmc_retune_hold(host);
+       }
+}
+

When the mmc block device driver is built as a module, this doesn't build. I will drop the series from my next branch to sort this out.

Quoted 7 lines

Oops. Sorry!

Quoted 2 lines

Should we export these via EXPORT_SYMBOL_GPL, or implement them as inline functions?

They need to be exported. I tend to go with what else is in the same file i.e. host.c is exporting using EXPORT_SYMBOL()

Yes, okay!

Quoted 6 lines
Quoted 6 lines

This also made me think about the SDIO/WLAN driver issue, during system PM suspend/resume, which also needed temporary to disable re-tuning.

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

*If* we are going to export these, I want to make it works for the SDIO case well...

SDIO case is slightly different, and SDIO uses its own header file sdio_func.h.

I what way is it different?

In the RPMB case there are 3 things to do:
1. Do re-tuning at next command
2. Hold re-tuning
3. Release re-tuning

In the SDIO case there are 3 things to do:
1. Prevent re-tuning at next command
2. Hold re-tuning
3. Release re-tuning

So the first thing is different.

Quoted 6 lines

Regarding the header file, my point is that I want to keep the numbers of exported functions to a minimum.

Do you think there is way to combine these two use cases, such only one pair of new functions would be needed?

To make them the same we would need to add a parameter to mmc_retune_pause() i.e. something like

void mmc_retune_pause(struct mmc_host *host, bool retune_now)

{
      if (!host->retune_paused) {
              host->retune_paused = 1;
              mmc_retune_hold(host);
              if (retune_now)
                      mmc_retune_needed(host);
              else
                      host->retune_now = 0;
      }
}
Quoted 4 lines
Quoted 4 lines

For SDIO we would need to put the function declarations in sdio_func.h as well as host.h.

Shall I make a V3 of these patches like that?

No.

Quoted 7 lines

I looked again at sdio_func.h and it seems to have its own paradigm i.e. it is a completely separate set of functions that take the SDIO function as a parameter, and that hide and encapsulate core and host functions.

It would be inconsistent with that paradigm to expose mmc_retune_pause() and mmc_retune_unpause() there. Is that what you want to do?

I agree, we shouldn't mess up the SDIO API with these functions.

Instead, let's keep it simple and just leave out the SDIO case for now. So do EXPORT_SYMBOL for those APIs you added in $subject patch, without further changes.

Okay?

Kind regards
Uffe

#8 lore raw

Re: [PATCH V2 1/3] mmc: core: Add a facility to "pause" re-tuning

Quoted 126 lines · Ulf Hansson
Quoted 110 lines · Adrian Hunter
Quoted 109 lines · Adrian Hunter
Quoted 67 lines · Ulf Hansson
Quoted 50 lines · Adrian Hunter
Quoted 32 lines · Ulf Hansson
Quoted 31 lines · Adrian Hunter

Re-tuning is not possible when switched to the RPMB partition. However re-tuning should not be needed if re-tuning is done immediately before switching, a small set of operations is done, and then we immediately switch back to the main partition.

To ensure that re-tuning can't be done for a short while, add a facility to "pause" re-tuning.

The existing facility to hold / release re-tuning is used but it also flags re-tuning as needed to cause re-tuning before the next command (which will be the switch to RPMB).

We also need to "unpause" in the recovery path, which is catered for by adding it to mmc_retune_disable().

---
 drivers/mmc/core/host.c  | 22 ++++++++++++++++++++++
 include/linux/mmc/host.h |  4 ++++
 2 files changed, 26 insertions(+)
drivers/mmc/core/host.c +0 -0
index e0a3ee16c0d3..302e5858755a 100644
@@ -68,8 +68,30 @@ void mmc_retune_enable(struct mmc_host *host)
                          jiffies + host->retune_period * HZ);
 }
 
Quoted 16 lines

drivers/mmc/core/host.c void mmc_retune_enable(struct mmc_host *host) · line 83

Quoted 13 lines
drivers/mmc/core/host.c +13 -0
+/*
+ * Pause re-tuning for a small set of operations.  The pause begins after the
+ * next command and after first doing re-tuning.
+ */
+void mmc_retune_pause(struct mmc_host *host)
+{
+       if (!host->retune_paused) {
+               host->retune_paused = 1;
+               mmc_retune_needed(host);
+               mmc_retune_hold(host);
+       }
+}
+

When the mmc block device driver is built as a module, this doesn't build. I will drop the series from my next branch to sort this out.

Quoted 7 lines

Oops. Sorry!

Quoted 2 lines

Should we export these via EXPORT_SYMBOL_GPL, or implement them as inline functions?

They need to be exported. I tend to go with what else is in the same file i.e. host.c is exporting using EXPORT_SYMBOL()

Yes, okay!

Quoted 6 lines
Quoted 6 lines

This also made me think about the SDIO/WLAN driver issue, during system PM suspend/resume, which also needed temporary to disable re-tuning.

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

*If* we are going to export these, I want to make it works for the SDIO case well...

SDIO case is slightly different, and SDIO uses its own header file sdio_func.h.

I what way is it different?

In the RPMB case there are 3 things to do:
1. Do re-tuning at next command
2. Hold re-tuning
3. Release re-tuning

In the SDIO case there are 3 things to do:
1. Prevent re-tuning at next command
2. Hold re-tuning
3. Release re-tuning

So the first thing is different.

Quoted 6 lines

Regarding the header file, my point is that I want to keep the numbers of exported functions to a minimum.

Do you think there is way to combine these two use cases, such only one pair of new functions would be needed?

To make them the same we would need to add a parameter to mmc_retune_pause() i.e. something like

void mmc_retune_pause(struct mmc_host *host, bool retune_now)

{
      if (!host->retune_paused) {
              host->retune_paused = 1;
              mmc_retune_hold(host);
              if (retune_now)
                      mmc_retune_needed(host);
              else
                      host->retune_now = 0;
      }
}
Quoted 4 lines
Quoted 4 lines

For SDIO we would need to put the function declarations in sdio_func.h as well as host.h.

Shall I make a V3 of these patches like that?

No.

Quoted 7 lines

I looked again at sdio_func.h and it seems to have its own paradigm i.e. it is a completely separate set of functions that take the SDIO function as a parameter, and that hide and encapsulate core and host functions.

It would be inconsistent with that paradigm to expose mmc_retune_pause() and mmc_retune_unpause() there. Is that what you want to do?

Quoted 7 lines

I agree, we shouldn't mess up the SDIO API with these functions.

Instead, let's keep it simple and just leave out the SDIO case for now. So do EXPORT_SYMBOL for those APIs you added in $subject patch, without further changes.

Okay?

Yes please :-)

#9 lore raw

PATCH v3 1/3 mmc: core: Add a facility to "pause" re-tuning

Re-tuning is not possible when switched to the RPMB partition. However re-tuning should not be needed if re-tuning is done immediately before switching, a small set of operations is done, and then we immediately switch back to the main partition.

To ensure that re-tuning can't be done for a short while, add a facility to "pause" re-tuning.

The existing facility to hold / release re-tuning is used but it also flags re-tuning as needed to cause re-tuning before the next command (which will be the switch to RPMB).

We also need to "unpause" in the recovery path, which is catered for by adding it to mmc_retune_disable().

---

Changes in V3:

	Added:
		EXPORT_SYMBOL(mmc_retune_pause);
		EXPORT_SYMBOL(mmc_retune_unpause);

Changes in V2:

New approach entirely

 drivers/mmc/core/host.c  | 24 ++++++++++++++++++++++++
 include/linux/mmc/host.h |  4 ++++
 2 files changed, 28 insertions(+)
drivers/mmc/core/host.c +24 -0
index e0a3ee16c0d3..1be42fab1a30 100644
@@ -68,8 +68,32 @@ void mmc_retune_enable(struct mmc_host *host)
 			  jiffies + host->retune_period * HZ);
 }
 
+/*
+ * Pause re-tuning for a small set of operations.  The pause begins after the
+ * next command and after first doing re-tuning.
+ */
+void mmc_retune_pause(struct mmc_host *host)
+{
+	if (!host->retune_paused) {
+		host->retune_paused = 1;
+		mmc_retune_needed(host);
+		mmc_retune_hold(host);
+	}
+}
+EXPORT_SYMBOL(mmc_retune_pause);
+
+void mmc_retune_unpause(struct mmc_host *host)
+{
+	if (host->retune_paused) {
+		host->retune_paused = 0;
+		mmc_retune_release(host);
+	}
+}
+EXPORT_SYMBOL(mmc_retune_unpause);
+
 void mmc_retune_disable(struct mmc_host *host)
 {
+	mmc_retune_unpause(host);
 	host->can_retune = 0;
 	del_timer_sync(&host->retune_timer);
 	host->retune_now = 0;
include/linux/mmc/host.h +4 -0
index 85800b48241f..45cde8cd39f2 100644
@@ -329,6 +329,7 @@ struct mmc_host {
 	unsigned int		can_retune:1;	/* re-tuning can be used */
 	unsigned int		doing_retune:1;	/* re-tuning in progress */
 	unsigned int		retune_now:1;	/* do re-tuning at next req */
+	unsigned int		retune_paused:1; /* re-tuning is temporarily disabled */
 
 	int			rescan_disable;	/* disable card detection */
 	int			rescan_entered;	/* used with nonremovable devices */
@@ -526,4 +527,7 @@ static inline void mmc_retune_recheck(struct mmc_host *host)
 		host->retune_now = 1;
 }
 
+void mmc_retune_pause(struct mmc_host *host);
+void mmc_retune_unpause(struct mmc_host *host);
+
 #endif /* LINUX_MMC_HOST_H */
Signature · 1 line
1.9.1
#10 lore raw

Re: [PATCH V3 1/3] mmc: core: Add a facility to "pause" re-tuning

Quoted 14 lines · Adrian Hunter

Re-tuning is not possible when switched to the RPMB partition. However re-tuning should not be needed if re-tuning is done immediately before switching, a small set of operations is done, and then we immediately switch back to the main partition.

To ensure that re-tuning can't be done for a short while, add a facility to "pause" re-tuning.

The existing facility to hold / release re-tuning is used but it also flags re-tuning as needed to cause re-tuning before the next command (which will be the switch to RPMB).

Quoted 5 lines

We also need to "unpause" in the recovery path, which is catered for by adding it to mmc_retune_disable().

---

Thanks, re-applied the series with this v3 version of patch 1/3.

If the tests from kernelci and in linux-next works out okay, I intend to send this as fixes for 4.7 rc1.

Kind regards
Uffe

Quoted 78 lines

Changes in V3:

        Added:
                EXPORT_SYMBOL(mmc_retune_pause);
                EXPORT_SYMBOL(mmc_retune_unpause);

Changes in V2:

New approach entirely

 drivers/mmc/core/host.c  | 24 ++++++++++++++++++++++++
 include/linux/mmc/host.h |  4 ++++
 2 files changed, 28 insertions(+)
drivers/mmc/core/host.c +24 -0
index e0a3ee16c0d3..1be42fab1a30 100644
@@ -68,8 +68,32 @@ void mmc_retune_enable(struct mmc_host *host)
                          jiffies + host->retune_period * HZ);
 }
 
+/*
+ * Pause re-tuning for a small set of operations.  The pause begins after the
+ * next command and after first doing re-tuning.
+ */
+void mmc_retune_pause(struct mmc_host *host)
+{
+       if (!host->retune_paused) {
+               host->retune_paused = 1;
+               mmc_retune_needed(host);
+               mmc_retune_hold(host);
+       }
+}
+EXPORT_SYMBOL(mmc_retune_pause);
+
+void mmc_retune_unpause(struct mmc_host *host)
+{
+       if (host->retune_paused) {
+               host->retune_paused = 0;
+               mmc_retune_release(host);
+       }
+}
+EXPORT_SYMBOL(mmc_retune_unpause);
+
 void mmc_retune_disable(struct mmc_host *host)
 {
+       mmc_retune_unpause(host);
        host->can_retune = 0;
        del_timer_sync(&host->retune_timer);
        host->retune_now = 0;
include/linux/mmc/host.h +4 -1
index 85800b48241f..45cde8cd39f2 100644
@@ -329,6 +329,7 @@ struct mmc_host {
        unsigned int            can_retune:1;   /* re-tuning can be used */
        unsigned int            doing_retune:1; /* re-tuning in progress */
        unsigned int            retune_now:1;   /* do re-tuning at next req */
+       unsigned int            retune_paused:1; /* re-tuning is temporarily disabled */
 
        int                     rescan_disable; /* disable card detection */
        int                     rescan_entered; /* used with nonremovable devices */
@@ -526,4 +527,7 @@ static inline void mmc_retune_recheck(struct mmc_host *host)
                host->retune_now = 1;
 }
 
+void mmc_retune_pause(struct mmc_host *host);
+void mmc_retune_unpause(struct mmc_host *host);
+
 #endif /* LINUX_MMC_HOST_H */
--

1.9.1

#11 lore raw

Re: [PATCH V3 1/3] mmc: core: Add a facility to "pause" re-tuning

Quoted 18 lines · Ulf Hansson
Quoted 17 lines · Adrian Hunter

Re-tuning is not possible when switched to the RPMB partition. However re-tuning should not be needed if re-tuning is done immediately before switching, a small set of operations is done, and then we immediately switch back to the main partition.

To ensure that re-tuning can't be done for a short while, add a facility to "pause" re-tuning.

The existing facility to hold / release re-tuning is used but it also flags re-tuning as needed to cause re-tuning before the next command (which will be the switch to RPMB).

We also need to "unpause" in the recovery path, which is catered for by adding it to mmc_retune_disable().

Quoted 7 lines
Quoted 2 lines

---

Thanks, re-applied the series with this v3 version of patch 1/3.

If the tests from kernelci and in linux-next works out okay, I intend to send this as fixes for 4.7 rc1.

Thank you!