Commit 01904ff7 authored by Avri Altman's avatar Avri Altman Committed by Ulf Hansson

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: default avatarAvri Altman <avri.altman@wdc.com>
Signed-off-by: default avatarUlf Hansson <ulf.hansson@linaro.org>
parent a2b760a6
...@@ -1124,7 +1124,7 @@ static void mmc_blk_issue_discard_rq(struct mmc_queue *mq, struct request *req) ...@@ -1124,7 +1124,7 @@ static void mmc_blk_issue_discard_rq(struct mmc_queue *mq, struct request *req)
{ {
struct mmc_blk_data *md = mq->blkdata; struct mmc_blk_data *md = mq->blkdata;
struct mmc_card *card = md->queue.card; struct mmc_card *card = md->queue.card;
unsigned int from, nr, arg; unsigned int from, nr;
int err = 0, type = MMC_BLK_DISCARD; int err = 0, type = MMC_BLK_DISCARD;
blk_status_t status = BLK_STS_OK; blk_status_t status = BLK_STS_OK;
...@@ -1136,24 +1136,18 @@ static void mmc_blk_issue_discard_rq(struct mmc_queue *mq, struct request *req) ...@@ -1136,24 +1136,18 @@ static void mmc_blk_issue_discard_rq(struct mmc_queue *mq, struct request *req)
from = blk_rq_pos(req); from = blk_rq_pos(req);
nr = blk_rq_sectors(req); nr = blk_rq_sectors(req);
if (mmc_can_discard(card))
arg = MMC_DISCARD_ARG;
else if (mmc_can_trim(card))
arg = MMC_TRIM_ARG;
else
arg = MMC_ERASE_ARG;
do { do {
err = 0; err = 0;
if (card->quirks & MMC_QUIRK_INAND_CMD38) { if (card->quirks & MMC_QUIRK_INAND_CMD38) {
err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
INAND_CMD38_ARG_EXT_CSD, INAND_CMD38_ARG_EXT_CSD,
arg == MMC_TRIM_ARG ? card->erase_arg == MMC_TRIM_ARG ?
INAND_CMD38_ARG_TRIM : INAND_CMD38_ARG_TRIM :
INAND_CMD38_ARG_ERASE, INAND_CMD38_ARG_ERASE,
0); 0);
} }
if (!err) if (!err)
err = mmc_erase(card, from, nr, arg); err = mmc_erase(card, from, nr, card->erase_arg);
} while (err == -EIO && !mmc_blk_reset(md, card->host, type)); } while (err == -EIO && !mmc_blk_reset(md, card->host, type));
if (err) if (err)
status = BLK_STS_IOERR; status = BLK_STS_IOERR;
......
...@@ -2164,7 +2164,7 @@ static unsigned int mmc_align_erase_size(struct mmc_card *card, ...@@ -2164,7 +2164,7 @@ static unsigned int mmc_align_erase_size(struct mmc_card *card,
* @card: card to erase * @card: card to erase
* @from: first sector to erase * @from: first sector to erase
* @nr: number of sectors to erase * @nr: number of sectors to erase
* @arg: erase command argument (SD supports only %MMC_ERASE_ARG) * @arg: erase command argument (SD supports only %SD_ERASE_ARG)
* *
* Caller must claim host before calling this function. * Caller must claim host before calling this function.
*/ */
...@@ -2181,7 +2181,7 @@ int mmc_erase(struct mmc_card *card, unsigned int from, unsigned int nr, ...@@ -2181,7 +2181,7 @@ int mmc_erase(struct mmc_card *card, unsigned int from, unsigned int nr,
if (!card->erase_size) if (!card->erase_size)
return -EOPNOTSUPP; return -EOPNOTSUPP;
if (mmc_card_sd(card) && arg != MMC_ERASE_ARG) if (mmc_card_sd(card) && arg != SD_ERASE_ARG)
return -EOPNOTSUPP; return -EOPNOTSUPP;
if ((arg & MMC_SECURE_ARGS) && if ((arg & MMC_SECURE_ARGS) &&
......
...@@ -1743,6 +1743,14 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr, ...@@ -1743,6 +1743,14 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr,
card->ext_csd.power_off_notification = EXT_CSD_POWER_ON; card->ext_csd.power_off_notification = EXT_CSD_POWER_ON;
} }
/* set erase_arg */
if (mmc_can_discard(card))
card->erase_arg = MMC_DISCARD_ARG;
else if (mmc_can_trim(card))
card->erase_arg = MMC_TRIM_ARG;
else
card->erase_arg = MMC_ERASE_ARG;
/* /*
* Select timing interface * Select timing interface
*/ */
......
...@@ -271,6 +271,8 @@ static int mmc_read_ssr(struct mmc_card *card) ...@@ -271,6 +271,8 @@ static int mmc_read_ssr(struct mmc_card *card)
} }
} }
card->erase_arg = SD_ERASE_ARG;
return 0; return 0;
} }
......
...@@ -277,6 +277,7 @@ struct mmc_card { ...@@ -277,6 +277,7 @@ struct mmc_card {
unsigned int erase_shift; /* if erase unit is power 2 */ unsigned int erase_shift; /* if erase unit is power 2 */
unsigned int pref_erase; /* in sectors */ unsigned int pref_erase; /* in sectors */
unsigned int eg_boundary; /* don't cross erase-group boundaries */ unsigned int eg_boundary; /* don't cross erase-group boundaries */
unsigned int erase_arg; /* erase / trim / discard */
u8 erased_byte; /* value of erased bytes */ u8 erased_byte; /* value of erased bytes */
u32 raw_cid[4]; /* raw card CID */ u32 raw_cid[4]; /* raw card CID */
......
...@@ -91,4 +91,9 @@ ...@@ -91,4 +91,9 @@
#define SD_SWITCH_ACCESS_DEF 0 #define SD_SWITCH_ACCESS_DEF 0
#define SD_SWITCH_ACCESS_HS 1 #define SD_SWITCH_ACCESS_HS 1
/*
* Erase/discard
*/
#define SD_ERASE_ARG 0x00000000
#endif /* LINUX_MMC_SD_H */ #endif /* LINUX_MMC_SD_H */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment