From e5a4407a84c84446e675a0104a4f45831d065e62 Mon Sep 17 00:00:00 2001 From: Neeraj Soni Date: Thu, 17 Sep 2020 23:10:22 +0530 Subject: [PATCH] mmc: host: Use right parameter for ext4 plus eMMC With new encryption framework intermediate vector calculation is changed so to support the legacy mechanism for ext4 file system use correct parameter for data encrypt/decrypt. Change-Id: I7921699c7a213bad7314a789d7f14a359205690f Signed-off-by: Neeraj Soni --- drivers/mmc/host/cmdq_hci-crypto-qti.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/drivers/mmc/host/cmdq_hci-crypto-qti.c b/drivers/mmc/host/cmdq_hci-crypto-qti.c index f16f07a0fbac..83e0adf7bae8 100644 --- a/drivers/mmc/host/cmdq_hci-crypto-qti.c +++ b/drivers/mmc/host/cmdq_hci-crypto-qti.c @@ -41,6 +41,7 @@ static struct cmdq_host_crypto_variant_ops cmdq_crypto_qti_variant_ops = { }; static atomic_t keycache; +static bool cmdq_use_default_du_size; static bool ice_cap_idx_valid(struct cmdq_host *host, unsigned int cap_idx) @@ -50,12 +51,19 @@ static bool ice_cap_idx_valid(struct cmdq_host *host, static uint8_t get_data_unit_size_mask(unsigned int data_unit_size) { + unsigned int du_size; + if (data_unit_size < MINIMUM_DUN_SIZE || data_unit_size > MAXIMUM_DUN_SIZE || !is_power_of_2(data_unit_size)) return 0; - return data_unit_size / MINIMUM_DUN_SIZE; + if (cmdq_use_default_du_size) + du_size = MINIMUM_DUN_SIZE; + else + du_size = data_unit_size; + + return du_size / MINIMUM_DUN_SIZE; } @@ -357,6 +365,9 @@ int cmdq_crypto_qti_prep_desc(struct cmdq_host *host, struct mmc_request *mrq, return -EINVAL; if (!(atomic_read(&keycache) & (1 << bc->bc_keyslot))) { + if (bc->is_ext4) + cmdq_use_default_du_size = true; + ret = cmdq_crypto_qti_keyslot_program(host->ksm, bc->bc_key, bc->bc_keyslot); if (ret) { @@ -368,8 +379,12 @@ int cmdq_crypto_qti_prep_desc(struct cmdq_host *host, struct mmc_request *mrq, } if (ice_ctx) { - *ice_ctx = DATA_UNIT_NUM(bc->bc_dun[0]) | - CRYPTO_CONFIG_INDEX(bc->bc_keyslot) | + if (bc->is_ext4) + *ice_ctx = DATA_UNIT_NUM(req->__sector); + else + *ice_ctx = DATA_UNIT_NUM(bc->bc_dun[0]); + + *ice_ctx = *ice_ctx | CRYPTO_CONFIG_INDEX(bc->bc_keyslot) | CRYPTO_ENABLE(true); } return 0;