aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mmc/card/block.c
diff options
context:
space:
mode:
authorAdrian Hunter <adrian.hunter@intel.com>2012-04-05 07:45:48 -0400
committerChris Ball <cjb@laptop.org>2012-04-20 20:28:58 -0400
commit283028122db37621b124f079ca8eae5b64807ad4 (patch)
tree54ffa48017525a2df2acd3404e43490c88b6c49a /drivers/mmc/card/block.c
parent7194efb8f063ee3aa0cb50d9002348887e68ec10 (diff)
mmc: fixes for eMMC v4.5 sanitize operation
eMMC v4.5 sanitize operation erases all copies of unmapped data. However trim or erase operations must be used first to unmap the required sectors. That was not being done. Fixes apply to linux 3.2 on. Signed-off-by: Adrian Hunter <adrian.hunter@intel.com> Cc: <stable@vger.kernel.org> Acked-by: Jaehoon Chung <jh80.chung@samsung.com> Acked-by: Linus Walleij <linus.walleij@linaro.org> Signed-off-by: Chris Ball <cjb@laptop.org>
Diffstat (limited to 'drivers/mmc/card/block.c')
-rw-r--r--drivers/mmc/card/block.c54
1 files changed, 38 insertions, 16 deletions
diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
index b1809650b7aa..4232bc4d9926 100644
--- a/drivers/mmc/card/block.c
+++ b/drivers/mmc/card/block.c
@@ -873,7 +873,7 @@ static int mmc_blk_issue_secdiscard_rq(struct mmc_queue *mq,
873{ 873{
874 struct mmc_blk_data *md = mq->data; 874 struct mmc_blk_data *md = mq->data;
875 struct mmc_card *card = md->queue.card; 875 struct mmc_card *card = md->queue.card;
876 unsigned int from, nr, arg; 876 unsigned int from, nr, arg, trim_arg, erase_arg;
877 int err = 0, type = MMC_BLK_SECDISCARD; 877 int err = 0, type = MMC_BLK_SECDISCARD;
878 878
879 if (!(mmc_can_secure_erase_trim(card) || mmc_can_sanitize(card))) { 879 if (!(mmc_can_secure_erase_trim(card) || mmc_can_sanitize(card))) {
@@ -881,20 +881,26 @@ static int mmc_blk_issue_secdiscard_rq(struct mmc_queue *mq,
881 goto out; 881 goto out;
882 } 882 }
883 883
884 from = blk_rq_pos(req);
885 nr = blk_rq_sectors(req);
886
884 /* The sanitize operation is supported at v4.5 only */ 887 /* The sanitize operation is supported at v4.5 only */
885 if (mmc_can_sanitize(card)) { 888 if (mmc_can_sanitize(card)) {
886 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, 889 erase_arg = MMC_ERASE_ARG;
887 EXT_CSD_SANITIZE_START, 1, 0); 890 trim_arg = MMC_TRIM_ARG;
888 goto out; 891 } else {
892 erase_arg = MMC_SECURE_ERASE_ARG;
893 trim_arg = MMC_SECURE_TRIM1_ARG;
889 } 894 }
890 895
891 from = blk_rq_pos(req); 896 if (mmc_erase_group_aligned(card, from, nr))
892 nr = blk_rq_sectors(req); 897 arg = erase_arg;
893 898 else if (mmc_can_trim(card))
894 if (mmc_can_trim(card) && !mmc_erase_group_aligned(card, from, nr)) 899 arg = trim_arg;
895 arg = MMC_SECURE_TRIM1_ARG; 900 else {
896 else 901 err = -EINVAL;
897 arg = MMC_SECURE_ERASE_ARG; 902 goto out;
903 }
898retry: 904retry:
899 if (card->quirks & MMC_QUIRK_INAND_CMD38) { 905 if (card->quirks & MMC_QUIRK_INAND_CMD38) {
900 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, 906 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
@@ -904,25 +910,41 @@ retry:
904 INAND_CMD38_ARG_SECERASE, 910 INAND_CMD38_ARG_SECERASE,
905 0); 911 0);
906 if (err) 912 if (err)
907 goto out; 913 goto out_retry;
908 } 914 }
915
909 err = mmc_erase(card, from, nr, arg); 916 err = mmc_erase(card, from, nr, arg);
910 if (!err && arg == MMC_SECURE_TRIM1_ARG) { 917 if (err == -EIO)
918 goto out_retry;
919 if (err)
920 goto out;
921
922 if (arg == MMC_SECURE_TRIM1_ARG) {
911 if (card->quirks & MMC_QUIRK_INAND_CMD38) { 923 if (card->quirks & MMC_QUIRK_INAND_CMD38) {
912 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, 924 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
913 INAND_CMD38_ARG_EXT_CSD, 925 INAND_CMD38_ARG_EXT_CSD,
914 INAND_CMD38_ARG_SECTRIM2, 926 INAND_CMD38_ARG_SECTRIM2,
915 0); 927 0);
916 if (err) 928 if (err)
917 goto out; 929 goto out_retry;
918 } 930 }
931
919 err = mmc_erase(card, from, nr, MMC_SECURE_TRIM2_ARG); 932 err = mmc_erase(card, from, nr, MMC_SECURE_TRIM2_ARG);
933 if (err == -EIO)
934 goto out_retry;
935 if (err)
936 goto out;
920 } 937 }
921out: 938
922 if (err == -EIO && !mmc_blk_reset(md, card->host, type)) 939 if (mmc_can_sanitize(card))
940 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
941 EXT_CSD_SANITIZE_START, 1, 0);
942out_retry:
943 if (err && !mmc_blk_reset(md, card->host, type))
923 goto retry; 944 goto retry;
924 if (!err) 945 if (!err)
925 mmc_blk_reset_success(md, type); 946 mmc_blk_reset_success(md, type);
947out:
926 spin_lock_irq(&md->lock); 948 spin_lock_irq(&md->lock);
927 __blk_end_request(req, err, blk_rq_bytes(req)); 949 __blk_end_request(req, err, blk_rq_bytes(req));
928 spin_unlock_irq(&md->lock); 950 spin_unlock_irq(&md->lock);