Skip to content

Commit 01904ff

Browse files
avri-altman-sndkstorulf
authored andcommitted
mmc: core: Calculate the discard arg only once
In MMC, the discard arg is a read-only ext_csd parameter - set it once on card init. To be consistent, do that for SD as well even though its discard arg is always 0x0. Signed-off-by: Avri Altman <[email protected]> Signed-off-by: Ulf Hansson <[email protected]>
1 parent a2b760a commit 01904ff

File tree

6 files changed

+21
-11
lines changed

6 files changed

+21
-11
lines changed

drivers/mmc/core/block.c

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1124,7 +1124,7 @@ static void mmc_blk_issue_discard_rq(struct mmc_queue *mq, struct request *req)
11241124
{
11251125
struct mmc_blk_data *md = mq->blkdata;
11261126
struct mmc_card *card = md->queue.card;
1127-
unsigned int from, nr, arg;
1127+
unsigned int from, nr;
11281128
int err = 0, type = MMC_BLK_DISCARD;
11291129
blk_status_t status = BLK_STS_OK;
11301130

@@ -1136,24 +1136,18 @@ static void mmc_blk_issue_discard_rq(struct mmc_queue *mq, struct request *req)
11361136
from = blk_rq_pos(req);
11371137
nr = blk_rq_sectors(req);
11381138

1139-
if (mmc_can_discard(card))
1140-
arg = MMC_DISCARD_ARG;
1141-
else if (mmc_can_trim(card))
1142-
arg = MMC_TRIM_ARG;
1143-
else
1144-
arg = MMC_ERASE_ARG;
11451139
do {
11461140
err = 0;
11471141
if (card->quirks & MMC_QUIRK_INAND_CMD38) {
11481142
err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
11491143
INAND_CMD38_ARG_EXT_CSD,
1150-
arg == MMC_TRIM_ARG ?
1144+
card->erase_arg == MMC_TRIM_ARG ?
11511145
INAND_CMD38_ARG_TRIM :
11521146
INAND_CMD38_ARG_ERASE,
11531147
0);
11541148
}
11551149
if (!err)
1156-
err = mmc_erase(card, from, nr, arg);
1150+
err = mmc_erase(card, from, nr, card->erase_arg);
11571151
} while (err == -EIO && !mmc_blk_reset(md, card->host, type));
11581152
if (err)
11591153
status = BLK_STS_IOERR;

drivers/mmc/core/core.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2164,7 +2164,7 @@ static unsigned int mmc_align_erase_size(struct mmc_card *card,
21642164
* @card: card to erase
21652165
* @from: first sector to erase
21662166
* @nr: number of sectors to erase
2167-
* @arg: erase command argument (SD supports only %MMC_ERASE_ARG)
2167+
* @arg: erase command argument (SD supports only %SD_ERASE_ARG)
21682168
*
21692169
* Caller must claim host before calling this function.
21702170
*/
@@ -2181,7 +2181,7 @@ int mmc_erase(struct mmc_card *card, unsigned int from, unsigned int nr,
21812181
if (!card->erase_size)
21822182
return -EOPNOTSUPP;
21832183

2184-
if (mmc_card_sd(card) && arg != MMC_ERASE_ARG)
2184+
if (mmc_card_sd(card) && arg != SD_ERASE_ARG)
21852185
return -EOPNOTSUPP;
21862186

21872187
if ((arg & MMC_SECURE_ARGS) &&

drivers/mmc/core/mmc.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1743,6 +1743,14 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr,
17431743
card->ext_csd.power_off_notification = EXT_CSD_POWER_ON;
17441744
}
17451745

1746+
/* set erase_arg */
1747+
if (mmc_can_discard(card))
1748+
card->erase_arg = MMC_DISCARD_ARG;
1749+
else if (mmc_can_trim(card))
1750+
card->erase_arg = MMC_TRIM_ARG;
1751+
else
1752+
card->erase_arg = MMC_ERASE_ARG;
1753+
17461754
/*
17471755
* Select timing interface
17481756
*/

drivers/mmc/core/sd.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,8 @@ static int mmc_read_ssr(struct mmc_card *card)
271271
}
272272
}
273273

274+
card->erase_arg = SD_ERASE_ARG;
275+
274276
return 0;
275277
}
276278

include/linux/mmc/card.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ struct mmc_card {
277277
unsigned int erase_shift; /* if erase unit is power 2 */
278278
unsigned int pref_erase; /* in sectors */
279279
unsigned int eg_boundary; /* don't cross erase-group boundaries */
280+
unsigned int erase_arg; /* erase / trim / discard */
280281
u8 erased_byte; /* value of erased bytes */
281282

282283
u32 raw_cid[4]; /* raw card CID */

include/linux/mmc/sd.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,4 +91,9 @@
9191
#define SD_SWITCH_ACCESS_DEF 0
9292
#define SD_SWITCH_ACCESS_HS 1
9393

94+
/*
95+
* Erase/discard
96+
*/
97+
#define SD_ERASE_ARG 0x00000000
98+
9499
#endif /* LINUX_MMC_SD_H */

0 commit comments

Comments
 (0)