Merge "ice_driver: Fix the ice keyslot conflict"

This commit is contained in:
qctecmdr
2023-12-19 21:41:33 -08:00
committed by Gerrit - the friendly Code Review server
2 changed files with 34 additions and 9 deletions

View File

@@ -5402,14 +5402,20 @@ static void ufs_qcom_hook_prepare_command(void *param, struct ufs_hba *hba,
#if IS_ENABLED(CONFIG_QTI_CRYPTO_FDE)
struct ice_data_setting setting;
if (!crypto_qti_ice_config_start(rq, &setting)) {
if ((rq_data_dir(rq) == WRITE) ? setting.encr_bypass : setting.decr_bypass) {
lrbp->crypto_key_slot = -1;
} else {
lrbp->crypto_key_slot = setting.crypto_data.key_index;
lrbp->data_unit_num = rq->bio->bi_iter.bi_sector >>
ICE_CRYPTO_DATA_UNIT_4_KB;
if (!rq->crypt_keyslot) {
if (!crypto_qti_ice_config_start(rq, &setting)) {
if ((rq_data_dir(rq) == WRITE) ? setting.encr_bypass :
setting.decr_bypass) {
lrbp->crypto_key_slot = -1;
} else {
lrbp->crypto_key_slot = setting.crypto_data.key_index;
lrbp->data_unit_num = rq->bio->bi_iter.bi_sector >>
ICE_CRYPTO_DATA_UNIT_4_KB;
}
}
} else {
lrbp->crypto_key_slot = blk_ksm_get_slot_idx(rq->crypt_keyslot);
lrbp->data_unit_num = rq->crypt_ctx->bc_dun[0];
}
#endif
}

View File

@@ -186,6 +186,7 @@ int ufshcd_qti_hba_init_crypto_capabilities(struct ufs_hba *hba)
{
int cap_idx;
int err = 0;
unsigned int max_slots = 0;
enum blk_crypto_mode_num blk_mode_num;
/*
@@ -212,9 +213,27 @@ int ufshcd_qti_hba_init_crypto_capabilities(struct ufs_hba *hba)
goto out;
}
max_slots = hba->crypto_capabilities.config_count + 1;
#if IS_ENABLED(CONFIG_QTI_CRYPTO_FDE)
if (max_slots > crypto_qti_ice_get_num_fde_slots()) {
/*
* Reduce the total number of slots available to FBE
* (by the number reserved for the FDE)
* Check at least one slot for backward compatibility,
* otherwise return failure
*/
if (max_slots - crypto_qti_ice_get_num_fde_slots() < 1) {
pr_err("%s: Too much slots allocated to fde\n", __func__);
err = -EINVAL;
goto out;
} else {
max_slots = max_slots - crypto_qti_ice_get_num_fde_slots();
}
}
#endif
/* The actual number of configurations supported is (CFGC+1) */
err = devm_blk_ksm_init(hba->dev, &hba->ksm,
hba->crypto_capabilities.config_count + 1);
err = devm_blk_ksm_init(hba->dev, &hba->ksm, max_slots);
if (err)
goto out;