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;