Lines Matching +full:hba +full:- +full:cap

1 // SPDX-License-Identifier: GPL-2.0
7 #include "ufshcd-crypto.h"
9 /* Blk-crypto modes supported by UFS crypto */
20 static int ufshcd_program_key(struct ufs_hba *hba, in ufshcd_program_key() argument
24 u32 slot_offset = hba->crypto_cfg_register + slot * sizeof(*cfg); in ufshcd_program_key()
27 ufshcd_hold(hba); in ufshcd_program_key()
29 if (hba->vops && hba->vops->program_key) { in ufshcd_program_key()
30 err = hba->vops->program_key(hba, cfg, slot); in ufshcd_program_key()
35 ufshcd_writel(hba, 0, slot_offset + 16 * sizeof(cfg->reg_val[0])); in ufshcd_program_key()
37 ufshcd_writel(hba, le32_to_cpu(cfg->reg_val[i]), in ufshcd_program_key()
38 slot_offset + i * sizeof(cfg->reg_val[0])); in ufshcd_program_key()
41 ufshcd_writel(hba, le32_to_cpu(cfg->reg_val[17]), in ufshcd_program_key()
42 slot_offset + 17 * sizeof(cfg->reg_val[0])); in ufshcd_program_key()
44 ufshcd_writel(hba, le32_to_cpu(cfg->reg_val[16]), in ufshcd_program_key()
45 slot_offset + 16 * sizeof(cfg->reg_val[0])); in ufshcd_program_key()
47 ufshcd_release(hba); in ufshcd_program_key()
55 struct ufs_hba *hba = in ufshcd_crypto_keyslot_program() local
57 const union ufs_crypto_cap_entry *ccap_array = hba->crypto_cap_array; in ufshcd_crypto_keyslot_program()
59 &ufs_crypto_algs[key->crypto_cfg.crypto_mode]; in ufshcd_crypto_keyslot_program()
60 u8 data_unit_mask = key->crypto_cfg.data_unit_size / 512; in ufshcd_crypto_keyslot_program()
62 int cap_idx = -1; in ufshcd_crypto_keyslot_program()
67 for (i = 0; i < hba->crypto_capabilities.num_crypto_cap; i++) { in ufshcd_crypto_keyslot_program()
68 if (ccap_array[i].algorithm_id == alg->ufs_alg && in ufshcd_crypto_keyslot_program()
69 ccap_array[i].key_size == alg->ufs_key_size && in ufshcd_crypto_keyslot_program()
77 return -EOPNOTSUPP; in ufshcd_crypto_keyslot_program()
85 memcpy(cfg.crypto_key, key->raw, key->size/2); in ufshcd_crypto_keyslot_program()
87 key->raw + key->size/2, key->size/2); in ufshcd_crypto_keyslot_program()
89 memcpy(cfg.crypto_key, key->raw, key->size); in ufshcd_crypto_keyslot_program()
92 err = ufshcd_program_key(hba, &cfg, slot); in ufshcd_crypto_keyslot_program()
98 static int ufshcd_clear_keyslot(struct ufs_hba *hba, int slot) in ufshcd_clear_keyslot() argument
106 return ufshcd_program_key(hba, &cfg, slot); in ufshcd_clear_keyslot()
113 struct ufs_hba *hba = in ufshcd_crypto_keyslot_evict() local
116 return ufshcd_clear_keyslot(hba, slot); in ufshcd_crypto_keyslot_evict()
119 bool ufshcd_crypto_enable(struct ufs_hba *hba) in ufshcd_crypto_enable() argument
121 if (!(hba->caps & UFSHCD_CAP_CRYPTO)) in ufshcd_crypto_enable()
125 blk_crypto_reprogram_all_keys(&hba->crypto_profile); in ufshcd_crypto_enable()
135 ufshcd_find_blk_crypto_mode(union ufs_crypto_cap_entry cap) in ufshcd_find_blk_crypto_mode() argument
141 if (ufs_crypto_algs[i].ufs_alg == cap.algorithm_id && in ufshcd_find_blk_crypto_mode()
142 ufs_crypto_algs[i].ufs_key_size == cap.key_size) { in ufshcd_find_blk_crypto_mode()
150 * ufshcd_hba_init_crypto_capabilities - Read crypto capabilities, init crypto
151 * fields in hba
152 * @hba: Per adapter instance
154 * Return: 0 if crypto was initialized or is not supported, else a -errno value.
156 int ufshcd_hba_init_crypto_capabilities(struct ufs_hba *hba) in ufshcd_hba_init_crypto_capabilities() argument
167 if (!(hba->capabilities & MASK_CRYPTO_SUPPORT) || in ufshcd_hba_init_crypto_capabilities()
168 !(hba->caps & UFSHCD_CAP_CRYPTO)) in ufshcd_hba_init_crypto_capabilities()
171 hba->crypto_capabilities.reg_val = in ufshcd_hba_init_crypto_capabilities()
172 cpu_to_le32(ufshcd_readl(hba, REG_UFS_CCAP)); in ufshcd_hba_init_crypto_capabilities()
173 hba->crypto_cfg_register = in ufshcd_hba_init_crypto_capabilities()
174 (u32)hba->crypto_capabilities.config_array_ptr * 0x100; in ufshcd_hba_init_crypto_capabilities()
175 hba->crypto_cap_array = in ufshcd_hba_init_crypto_capabilities()
176 devm_kcalloc(hba->dev, hba->crypto_capabilities.num_crypto_cap, in ufshcd_hba_init_crypto_capabilities()
177 sizeof(hba->crypto_cap_array[0]), GFP_KERNEL); in ufshcd_hba_init_crypto_capabilities()
178 if (!hba->crypto_cap_array) { in ufshcd_hba_init_crypto_capabilities()
179 err = -ENOMEM; in ufshcd_hba_init_crypto_capabilities()
185 hba->dev, &hba->crypto_profile, in ufshcd_hba_init_crypto_capabilities()
186 hba->crypto_capabilities.config_count + 1); in ufshcd_hba_init_crypto_capabilities()
190 hba->crypto_profile.ll_ops = ufshcd_crypto_ops; in ufshcd_hba_init_crypto_capabilities()
192 hba->crypto_profile.max_dun_bytes_supported = 8; in ufshcd_hba_init_crypto_capabilities()
193 hba->crypto_profile.dev = hba->dev; in ufshcd_hba_init_crypto_capabilities()
199 for (cap_idx = 0; cap_idx < hba->crypto_capabilities.num_crypto_cap; in ufshcd_hba_init_crypto_capabilities()
201 hba->crypto_cap_array[cap_idx].reg_val = in ufshcd_hba_init_crypto_capabilities()
202 cpu_to_le32(ufshcd_readl(hba, in ufshcd_hba_init_crypto_capabilities()
206 hba->crypto_cap_array[cap_idx]); in ufshcd_hba_init_crypto_capabilities()
208 hba->crypto_profile.modes_supported[blk_mode_num] |= in ufshcd_hba_init_crypto_capabilities()
209 hba->crypto_cap_array[cap_idx].sdus_mask * 512; in ufshcd_hba_init_crypto_capabilities()
216 hba->caps &= ~UFSHCD_CAP_CRYPTO; in ufshcd_hba_init_crypto_capabilities()
221 * ufshcd_init_crypto - Initialize crypto hardware
222 * @hba: Per adapter instance
224 void ufshcd_init_crypto(struct ufs_hba *hba) in ufshcd_init_crypto() argument
228 if (!(hba->caps & UFSHCD_CAP_CRYPTO)) in ufshcd_init_crypto()
231 /* Clear all keyslots - the number of keyslots is (CFGC + 1) */ in ufshcd_init_crypto()
232 for (slot = 0; slot < hba->crypto_capabilities.config_count + 1; slot++) in ufshcd_init_crypto()
233 ufshcd_clear_keyslot(hba, slot); in ufshcd_init_crypto()
236 void ufshcd_crypto_register(struct ufs_hba *hba, struct request_queue *q) in ufshcd_crypto_register() argument
238 if (hba->caps & UFSHCD_CAP_CRYPTO) in ufshcd_crypto_register()
239 blk_crypto_register(&hba->crypto_profile, q); in ufshcd_crypto_register()