Skip to contentSkip to conversation

mmc: align max segment size with logical block size

PATCH Superseded Ming Lei 2 participants 3 messages Feb 27, 2019

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Ming Lei

author
#0 lore raw

PATCH 1/1 mmc: align max segment size with logical block size

Logical block size is the lowest possible block size that the storage device can address. Max segment size is often related with controller's DMA capability. And it is reasonable to align max segment size with logical block size.

SDHCI sets un-aligned max segment size, and causes ADMA error, so fix it by aligning max segment size with logical block size.

---
 drivers/mmc/core/block.c | 6 ------
 drivers/mmc/core/queue.c | 9 ++++++++-
 2 files changed, 8 insertions(+), 7 deletions(-)
drivers/mmc/core/block.c +0 -6
index 14f3fdb8c6bb..9ce8eb51a60f 100644
@@ -2380,12 +2380,6 @@ static struct mmc_blk_data *mmc_blk_alloc_req(struct mmc_card *card,
 	snprintf(md->disk->disk_name, sizeof(md->disk->disk_name),
 		 "mmcblk%u%s", card->host->index, subname ? subname : "");
 
-	if (mmc_card_mmc(card))
-		blk_queue_logical_block_size(md->queue.queue,
-					     card->ext_csd.data_sector_size);
-	else
-		blk_queue_logical_block_size(md->queue.queue, 512);
-
 	set_capacity(md->disk, size);
 
 	if (mmc_host_cmd23(card->host)) {
drivers/mmc/core/queue.c +8 -1
index cc19e71c71d4..891bdbe14192 100644
@@ -355,6 +355,7 @@ static void mmc_setup_queue(struct mmc_queue *mq, struct mmc_card *card)
 {
 	struct mmc_host *host = card->host;
 	u64 limit = BLK_BOUNCE_HIGH;
+	unsigned block_size = 512;
 
 	if (mmc_dev(host)->dma_mask && *mmc_dev(host)->dma_mask)
 		limit = (u64)dma_max_pfn(mmc_dev(host)) << PAGE_SHIFT;
@@ -368,7 +369,13 @@ static void mmc_setup_queue(struct mmc_queue *mq, struct mmc_card *card)
 	blk_queue_max_hw_sectors(mq->queue,
 		min(host->max_blk_count, host->max_req_size / 512));
 	blk_queue_max_segments(mq->queue, host->max_segs);
-	blk_queue_max_segment_size(mq->queue, host->max_seg_size);
+
+	if (mmc_card_mmc(card))
+		block_size = card->ext_csd.data_sector_size;
+
+	blk_queue_logical_block_size(mq->queue, block_size);
+	blk_queue_max_segment_size(mq->queue, host->max_seg_size &
+			~(block_size - 1));
 
 	INIT_WORK(&mq->recovery_work, mmc_mq_recovery_handler);
 	INIT_WORK(&mq->complete_work, mmc_blk_mq_complete_work);
Signature · 1 line
2.9.5
#1 lore raw

+ Christoph

Quoted 8 lines · Ming Lei

Logical block size is the lowest possible block size that the storage device can address. Max segment size is often related with controller's DMA capability. And it is reasonable to align max segment size with logical block size.

SDHCI sets un-aligned max segment size, and causes ADMA error, so fix it by aligning max segment size with logical block size.

Seems reasonable. However, is this specific to MMC or should it be managed in block layer?

Quoted 42 lines
---
 drivers/mmc/core/block.c | 6 ------
 drivers/mmc/core/queue.c | 9 ++++++++-
 2 files changed, 8 insertions(+), 7 deletions(-)
drivers/mmc/core/block.c +0 -6
index 14f3fdb8c6bb..9ce8eb51a60f 100644
@@ -2380,12 +2380,6 @@ static struct mmc_blk_data *mmc_blk_alloc_req(struct mmc_card *card,
        snprintf(md->disk->disk_name, sizeof(md->disk->disk_name),
                 "mmcblk%u%s", card->host->index, subname ? subname : "");
 
-       if (mmc_card_mmc(card))
-               blk_queue_logical_block_size(md->queue.queue,
-                                            card->ext_csd.data_sector_size);
-       else
-               blk_queue_logical_block_size(md->queue.queue, 512);
-
        set_capacity(md->disk, size);
 
        if (mmc_host_cmd23(card->host)) {
drivers/mmc/core/queue.c +1 -0
index cc19e71c71d4..891bdbe14192 100644
@@ -355,6 +355,7 @@ static void mmc_setup_queue(struct mmc_queue *mq, struct mmc_card *card)
 {
        struct mmc_host *host = card->host;
        u64 limit = BLK_BOUNCE_HIGH;
+       unsigned block_size = 512;
 
        if (mmc_dev(host)->dma_mask && *mmc_dev(host)->dma_mask)
                limit = (u64)dma_max_pfn(mmc_dev(host)) << PAGE_SHIFT;
@@ -368,7 +369,13 @@ static void mmc_setup_queue(struct mmc_queue *mq, struct mmc_card *card)
        blk_queue_max_hw_sectors(mq->queue,

drivers/mmc/core/queue.c static void mmc_setup_queue(struct mmc_queue *mq, struct mmc_card *card) · line 378

Quoted 10 lines
drivers/mmc/core/queue.c +7 -1
                min(host->max_blk_count, host->max_req_size / 512));
        blk_queue_max_segments(mq->queue, host->max_segs);
-       blk_queue_max_segment_size(mq->queue, host->max_seg_size);
+
+       if (mmc_card_mmc(card))
+               block_size = card->ext_csd.data_sector_size;
+
+       blk_queue_logical_block_size(mq->queue, block_size);
+       blk_queue_max_segment_size(mq->queue, host->max_seg_size &
+                       ~(block_size - 1));

Can't we use round_down() instead? No?

Quoted 6 lines
drivers/mmc/core/queue.c +0 -1
        INIT_WORK(&mq->recovery_work, mmc_mq_recovery_handler);
        INIT_WORK(&mq->complete_work, mmc_blk_mq_complete_work);
--

2.9.5

Kind regards
Uffe

author
#2 lore raw
Quoted 9 lines · Ulf Hansson

+ Christoph

Quoted 6 lines · Ming Lei

Logical block size is the lowest possible block size that the storage device can address. Max segment size is often related with controller's DMA capability. And it is reasonable to align max segment size with logical block size.

Quoted 5 lines
Quoted 2 lines

SDHCI sets un-aligned max segment size, and causes ADMA error, so fix it by aligning max segment size with logical block size.

Seems reasonable. However, is this specific to MMC or should it be managed in block layer?

So far, only see such broken max segment size on MMC, so suggest to fix in MMC, otherwise we may have to align the limit in fast path.

Quoted 39 lines
Quoted 39 lines
---
 drivers/mmc/core/block.c | 6 ------
 drivers/mmc/core/queue.c | 9 ++++++++-
 2 files changed, 8 insertions(+), 7 deletions(-)
drivers/mmc/core/block.c +0 -6
index 14f3fdb8c6bb..9ce8eb51a60f 100644
@@ -2380,12 +2380,6 @@ static struct mmc_blk_data *mmc_blk_alloc_req(struct mmc_card *card,
        snprintf(md->disk->disk_name, sizeof(md->disk->disk_name),
                 "mmcblk%u%s", card->host->index, subname ? subname : "");
 
-       if (mmc_card_mmc(card))
-               blk_queue_logical_block_size(md->queue.queue,
-                                            card->ext_csd.data_sector_size);
-       else
-               blk_queue_logical_block_size(md->queue.queue, 512);
-
        set_capacity(md->disk, size);
 
        if (mmc_host_cmd23(card->host)) {
drivers/mmc/core/queue.c +1 -0
index cc19e71c71d4..891bdbe14192 100644
@@ -355,6 +355,7 @@ static void mmc_setup_queue(struct mmc_queue *mq, struct mmc_card *card)
 {
        struct mmc_host *host = card->host;
        u64 limit = BLK_BOUNCE_HIGH;
+       unsigned block_size = 512;
 
Quoted 16 lines
Quoted 4 lines
drivers/mmc/core/queue.c +0 -0
        if (mmc_dev(host)->dma_mask && *mmc_dev(host)->dma_mask)
                limit = (u64)dma_max_pfn(mmc_dev(host)) << PAGE_SHIFT;
@@ -368,7 +369,13 @@ static void mmc_setup_queue(struct mmc_queue *mq, struct mmc_card *card)
        blk_queue_max_hw_sectors(mq->queue,

drivers/mmc/core/queue.c static void mmc_setup_queue(struct mmc_queue *mq, struct mmc_card *card) · line 378

Quoted 10 lines
drivers/mmc/core/queue.c +7 -1
                min(host->max_blk_count, host->max_req_size / 512));
        blk_queue_max_segments(mq->queue, host->max_segs);
-       blk_queue_max_segment_size(mq->queue, host->max_seg_size);
+
+       if (mmc_card_mmc(card))
+               block_size = card->ext_csd.data_sector_size;
+
+       blk_queue_logical_block_size(mq->queue, block_size);
+       blk_queue_max_segment_size(mq->queue, host->max_seg_size &
+                       ~(block_size - 1));

Can't we use round_down() instead? No?

Sure, use round_down() in V2.

thanks,
Ming