[U-Boot] [PATCH 1/3] Revert "blk: Invalidate block cache when switching hwpart"

This reverts commit 0ebe112d09b48230ba4be833cd3504b06997d9a4.
Most block devices have only one hwpart. Multiple hwparts only found used by eMMC devices in u-boot. The mmc driver do blk_dselect_hwpart() at the beginning of mmc_bread() which causes block cache being invalidated too frequently and makes block cache useless.
So it's not a good idea to put blkcache_invalidate() in the common functions. It should be called inside mmc_select_hwpart().
Signed-off-by: Weijie Gao weijie.gao@mediatek.com --- drivers/block/blk-uclass.c | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-)
diff --git a/drivers/block/blk-uclass.c b/drivers/block/blk-uclass.c index c23b6682a6..baaf431e5e 100644 --- a/drivers/block/blk-uclass.c +++ b/drivers/block/blk-uclass.c @@ -208,11 +208,7 @@ int blk_select_hwpart_devnum(enum if_type if_type, int devnum, int hwpart) if (ret) return ret;
- ret = blk_select_hwpart(dev, hwpart); - if (!ret) - blkcache_invalidate(if_type, devnum); - - return ret; + return blk_select_hwpart(dev, hwpart); }
int blk_list_part(enum if_type if_type) @@ -352,13 +348,7 @@ int blk_select_hwpart(struct udevice *dev, int hwpart)
int blk_dselect_hwpart(struct blk_desc *desc, int hwpart) { - int ret; - - ret = blk_select_hwpart(desc->bdev, hwpart); - if (!ret) - blkcache_invalidate(desc->if_type, desc->devnum); - - return ret; + return blk_select_hwpart(desc->bdev, hwpart); }
int blk_first_device(int if_type, struct udevice **devp)

eMMC device has multiple hw partitions both address from zero. However the mmc driver lacks block cache invalidation for switch hwpart. This causes a problem that data of current hw partition is cached before switching to another hw partition. And the following read operation of the latter hw partition will get wrong data when reading from the addresses that have been cached previously.
To solve this problem, invalidate block cache after a successful mmc_switch_part() operation.
Signed-off-by: Weijie Gao weijie.gao@mediatek.com --- drivers/mmc/mmc-uclass.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/drivers/mmc/mmc-uclass.c b/drivers/mmc/mmc-uclass.c index 551007905c..2b146ea43c 100644 --- a/drivers/mmc/mmc-uclass.c +++ b/drivers/mmc/mmc-uclass.c @@ -360,6 +360,7 @@ static int mmc_select_hwpart(struct udevice *bdev, int hwpart) struct udevice *mmc_dev = dev_get_parent(bdev); struct mmc *mmc = mmc_get_mmc_dev(mmc_dev); struct blk_desc *desc = dev_get_uclass_platdata(bdev); + int ret;
if (desc->hwpart == hwpart) return 0; @@ -367,7 +368,11 @@ static int mmc_select_hwpart(struct udevice *bdev, int hwpart) if (mmc->part_config == MMCPART_NOAVAILABLE) return -EMEDIUMTYPE;
- return mmc_switch_part(mmc, hwpart); + ret = mmc_switch_part(mmc, hwpart); + if (!ret) + blkcache_invalidate(desc->if_type, desc->devnum); + + return ret; }
static int mmc_blk_probe(struct udevice *dev)

On 27.08.19 09:32, Weijie Gao wrote:
eMMC device has multiple hw partitions both address from zero. However the mmc driver lacks block cache invalidation for switch hwpart. This causes a problem that data of current hw partition is cached before switching to another hw partition. And the following read operation of the latter hw partition will get wrong data when reading from the addresses that have been cached previously.
To solve this problem, invalidate block cache after a successful mmc_switch_part() operation.
Signed-off-by: Weijie Gao weijie.gao@mediatek.com
For the PDU001 board:
Tested-by: Felix Brack fb@ltec.ch
regards, Felix

On Tue, Aug 27, 2019 at 03:32:19PM +0800, Weijie Gao wrote:
eMMC device has multiple hw partitions both address from zero. However the mmc driver lacks block cache invalidation for switch hwpart. This causes a problem that data of current hw partition is cached before switching to another hw partition. And the following read operation of the latter hw partition will get wrong data when reading from the addresses that have been cached previously.
To solve this problem, invalidate block cache after a successful mmc_switch_part() operation.
Signed-off-by: Weijie Gao weijie.gao@mediatek.com Tested-by: Felix Brack fb@ltec.ch
Applied to u-boot/master, thanks!

This patch enables CONFIG_BLOCK_CACHE for mt7623n_bpir2.
Signed-off-by: Weijie Gao weijie.gao@mediatek.com --- This patch must be merged after patch 1 & 2. --- configs/mt7623n_bpir2_defconfig | 1 - 1 file changed, 1 deletion(-)
diff --git a/configs/mt7623n_bpir2_defconfig b/configs/mt7623n_bpir2_defconfig index ae8209831b..f79850f849 100644 --- a/configs/mt7623n_bpir2_defconfig +++ b/configs/mt7623n_bpir2_defconfig @@ -31,7 +31,6 @@ CONFIG_ENV_IS_IN_MMC=y CONFIG_NET_RANDOM_ETHADDR=y CONFIG_REGMAP=y CONFIG_SYSCON=y -# CONFIG_BLOCK_CACHE is not set CONFIG_CLK=y CONFIG_DM_MMC=y # CONFIG_MMC_QUIRKS is not set

On Tue, Aug 27, 2019 at 03:32:20PM +0800, Weijie Gao wrote:
This patch enables CONFIG_BLOCK_CACHE for mt7623n_bpir2.
Signed-off-by: Weijie Gao weijie.gao@mediatek.com
Applied to u-boot/master, thanks!

On 27.08.19 09:32, Weijie Gao wrote:
This reverts commit 0ebe112d09b48230ba4be833cd3504b06997d9a4.
Most block devices have only one hwpart. Multiple hwparts only found used by eMMC devices in u-boot. The mmc driver do blk_dselect_hwpart() at the beginning of mmc_bread() which causes block cache being invalidated too frequently and makes block cache useless.
So it's not a good idea to put blkcache_invalidate() in the common functions. It should be called inside mmc_select_hwpart().
Signed-off-by: Weijie Gao weijie.gao@mediatek.com
For the PDU001 board:
Tested-by: Felix Brack fb@ltec.ch
regards, Felix

On Tue, Aug 27, 2019 at 03:32:18PM +0800, Weijie Gao wrote:
This reverts commit 0ebe112d09b48230ba4be833cd3504b06997d9a4.
Most block devices have only one hwpart. Multiple hwparts only found used by eMMC devices in u-boot. The mmc driver do blk_dselect_hwpart() at the beginning of mmc_bread() which causes block cache being invalidated too frequently and makes block cache useless.
So it's not a good idea to put blkcache_invalidate() in the common functions. It should be called inside mmc_select_hwpart().
Signed-off-by: Weijie Gao weijie.gao@mediatek.com Tested-by: Felix Brack fb@ltec.ch
Applied to u-boot/master, thanks!
participants (3)
-
Felix Brack
-
Tom Rini
-
Weijie Gao