FROMLIST: scsi: ufs: add program_key() variant op

On Snapdragon SoCs, the Linux kernel isn't permitted to directly access
the standard UFS crypto configuration registers.  Instead, programming
and evicting keys must be done through vendor-specific SMC calls.

To support this hardware, add a ->program_key() method to
'struct ufs_hba_variant_ops'.  This allows overriding the UFS standard
key programming procedure.

Link: https://lore.kernel.org/r/20200110061634.46742-5-ebiggers@kernel.org
Bug: 137270441
Bug: 147259927
Change-Id: Ia561d5a51421baaf78de52a1eaec496093a0d0ad
Signed-off-by: Eric Biggers <ebiggers@google.com>
This commit is contained in:
Eric Biggers
2020-01-09 21:10:06 -08:00
parent 0f1c72a2f5
commit bbee78199f
2 changed files with 23 additions and 6 deletions

View File

@ -118,15 +118,21 @@ static int ufshcd_crypto_cfg_entry_write_key(union ufs_crypto_cfg_entry *cfg,
return -EINVAL; return -EINVAL;
} }
static void ufshcd_program_key(struct ufs_hba *hba, static int ufshcd_program_key(struct ufs_hba *hba,
const union ufs_crypto_cfg_entry *cfg, const union ufs_crypto_cfg_entry *cfg, int slot)
int slot)
{ {
int i; int i;
u32 slot_offset = hba->crypto_cfg_register + slot * sizeof(*cfg); u32 slot_offset = hba->crypto_cfg_register + slot * sizeof(*cfg);
int err;
pm_runtime_get_sync(hba->dev); pm_runtime_get_sync(hba->dev);
ufshcd_hold(hba, false); ufshcd_hold(hba, false);
if (hba->vops->program_key) {
err = hba->vops->program_key(hba, cfg, slot);
goto out;
}
/* Clear the dword 16 */ /* Clear the dword 16 */
ufshcd_writel(hba, 0, slot_offset + 16 * sizeof(cfg->reg_val[0])); ufshcd_writel(hba, 0, slot_offset + 16 * sizeof(cfg->reg_val[0]));
/* Ensure that CFGE is cleared before programming the key */ /* Ensure that CFGE is cleared before programming the key */
@ -146,15 +152,20 @@ static void ufshcd_program_key(struct ufs_hba *hba,
ufshcd_writel(hba, le32_to_cpu(cfg->reg_val[16]), ufshcd_writel(hba, le32_to_cpu(cfg->reg_val[16]),
slot_offset + 16 * sizeof(cfg->reg_val[0])); slot_offset + 16 * sizeof(cfg->reg_val[0]));
wmb(); wmb();
err = 0;
out:
ufshcd_release(hba); ufshcd_release(hba);
pm_runtime_put_sync(hba->dev); pm_runtime_put_sync(hba->dev);
return err;
} }
static void ufshcd_clear_keyslot(struct ufs_hba *hba, int slot) static void ufshcd_clear_keyslot(struct ufs_hba *hba, int slot)
{ {
union ufs_crypto_cfg_entry cfg = { 0 }; union ufs_crypto_cfg_entry cfg = { 0 };
int err;
ufshcd_program_key(hba, &cfg, slot); err = ufshcd_program_key(hba, &cfg, slot);
WARN_ON_ONCE(err);
} }
/* Clear all keyslots at driver init time */ /* Clear all keyslots at driver init time */
@ -199,10 +210,11 @@ static int ufshcd_crypto_keyslot_program(struct keyslot_manager *ksm,
if (err) if (err)
return err; return err;
ufshcd_program_key(hba, &cfg, slot); err = ufshcd_program_key(hba, &cfg, slot);
memzero_explicit(&cfg, sizeof(cfg)); memzero_explicit(&cfg, sizeof(cfg));
return 0;
return err;
} }
static int ufshcd_crypto_keyslot_evict(struct keyslot_manager *ksm, static int ufshcd_crypto_keyslot_evict(struct keyslot_manager *ksm,

View File

@ -280,6 +280,8 @@ struct ufs_pwr_mode_info {
struct ufs_pa_layer_attr info; struct ufs_pa_layer_attr info;
}; };
union ufs_crypto_cfg_entry;
/** /**
* struct ufs_hba_variant_ops - variant specific callbacks * struct ufs_hba_variant_ops - variant specific callbacks
* @name: variant name * @name: variant name
@ -306,6 +308,7 @@ struct ufs_pwr_mode_info {
* @resume: called during host controller PM callback * @resume: called during host controller PM callback
* @dbg_register_dump: used to dump controller debug information * @dbg_register_dump: used to dump controller debug information
* @phy_initialization: used to initialize phys * @phy_initialization: used to initialize phys
* @program_key: program an inline encryption key into a keyslot
*/ */
struct ufs_hba_variant_ops { struct ufs_hba_variant_ops {
const char *name; const char *name;
@ -334,6 +337,8 @@ struct ufs_hba_variant_ops {
int (*resume)(struct ufs_hba *, enum ufs_pm_op); int (*resume)(struct ufs_hba *, enum ufs_pm_op);
void (*dbg_register_dump)(struct ufs_hba *hba); void (*dbg_register_dump)(struct ufs_hba *hba);
int (*phy_initialization)(struct ufs_hba *); int (*phy_initialization)(struct ufs_hba *);
int (*program_key)(struct ufs_hba *hba,
const union ufs_crypto_cfg_entry *cfg, int slot);
}; };
struct keyslot_mgmt_ll_ops; struct keyslot_mgmt_ll_ops;