From ab8a8ffd2fd76bffaa70092ea4838b1e8285133e Mon Sep 17 00:00:00 2001 From: Eric Biggers Date: Fri, 6 Nov 2020 11:22:23 -0800 Subject: [PATCH] ANDROID: scsi: ufs: revise and fix custom keyslot manager support UFSHCD_QUIRK_BROKEN_CRYPTO_CAPS really means "override the blk_keyslot_manager", which (at least for now) handles both the crypto capabilities and the actual keyslot management. So give it a better name: UFSHCD_QUIRK_CUSTOM_KEYSLOT_MANAGER. Also, fix ufshcd_init_crypto() to call hba->ksm.ksm_ll_ops.keyslot_evict instead of using the standard key eviction procedure. This is needed when the blk_keyslot_manager is overridden with one that has num_slots > 0 and uses a nonstandard key eviction procedure. This patch, ANDROID-scsi-ufs-add-UFSHCD_QUIRK_BROKEN_CRYPTO_CAPS.patch, and ANDROID-scsi-ufs-allow-for-there-to-be-no-keyslots.patch should all be folded into one patch. Bug: 162257402 Bug: 166139333 Change-Id: I7081bdd111f638eb28366aacbd9f9c3a093495ee Signed-off-by: Eric Biggers --- drivers/scsi/ufs/ufshcd-crypto.c | 4 ++-- drivers/scsi/ufs/ufshcd.h | 9 +++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/drivers/scsi/ufs/ufshcd-crypto.c b/drivers/scsi/ufs/ufshcd-crypto.c index aaa5309db22a..db1b1d9ab048 100644 --- a/drivers/scsi/ufs/ufshcd-crypto.c +++ b/drivers/scsi/ufs/ufshcd-crypto.c @@ -162,7 +162,7 @@ int ufshcd_hba_init_crypto_capabilities(struct ufs_hba *hba) int err = 0; enum blk_crypto_mode_num blk_mode_num; - if (hba->quirks & UFSHCD_QUIRK_BROKEN_CRYPTO_CAPS) + if (hba->quirks & UFSHCD_QUIRK_CUSTOM_KEYSLOT_MANAGER) return 0; /* @@ -238,7 +238,7 @@ void ufshcd_init_crypto(struct ufs_hba *hba) /* Clear all keyslots */ for (slot = 0; slot < hba->ksm.num_slots; slot++) - ufshcd_clear_keyslot(hba, slot); + hba->ksm.ksm_ll_ops.keyslot_evict(&hba->ksm, NULL, slot); } void ufshcd_crypto_setup_rq_keyslot_manager(struct ufs_hba *hba, diff --git a/drivers/scsi/ufs/ufshcd.h b/drivers/scsi/ufs/ufshcd.h index 091bf771bcc4..45510d730309 100644 --- a/drivers/scsi/ufs/ufshcd.h +++ b/drivers/scsi/ufs/ufshcd.h @@ -557,11 +557,12 @@ enum ufshcd_quirks { /* * This quirk needs to be enabled if the host controller supports inline - * encryption, but it doesn't use the standard crypto capability - * registers. If enabled, the standard code won't initialize the - * keyslot manager; ufs_hba_variant_ops::init() must do it instead. + * encryption, but it needs to initialize the crypto capabilities in a + * nonstandard way and/or it needs to override blk_ksm_ll_ops. If + * enabled, the standard code won't initialize the blk_keyslot_manager; + * ufs_hba_variant_ops::init() must do it instead. */ - UFSHCD_QUIRK_BROKEN_CRYPTO_CAPS = 1 << 20, + UFSHCD_QUIRK_CUSTOM_KEYSLOT_MANAGER = 1 << 20, /* * This quirk needs to be enabled if the host controller supports inline