Lines Matching refs:profile
42 struct blk_crypto_profile *profile; member
45 static inline void blk_crypto_hw_enter(struct blk_crypto_profile *profile) in blk_crypto_hw_enter() argument
52 if (profile->dev) in blk_crypto_hw_enter()
53 pm_runtime_get_sync(profile->dev); in blk_crypto_hw_enter()
54 down_write(&profile->lock); in blk_crypto_hw_enter()
57 static inline void blk_crypto_hw_exit(struct blk_crypto_profile *profile) in blk_crypto_hw_exit() argument
59 up_write(&profile->lock); in blk_crypto_hw_exit()
60 if (profile->dev) in blk_crypto_hw_exit()
61 pm_runtime_put_sync(profile->dev); in blk_crypto_hw_exit()
74 int blk_crypto_profile_init(struct blk_crypto_profile *profile, in blk_crypto_profile_init() argument
81 memset(profile, 0, sizeof(*profile)); in blk_crypto_profile_init()
88 lockdep_register_key(&profile->lockdep_key); in blk_crypto_profile_init()
89 __init_rwsem(&profile->lock, "&profile->lock", &profile->lockdep_key); in blk_crypto_profile_init()
96 profile->slots = kvcalloc(num_slots, sizeof(profile->slots[0]), in blk_crypto_profile_init()
98 if (!profile->slots) in blk_crypto_profile_init()
101 profile->num_slots = num_slots; in blk_crypto_profile_init()
103 init_waitqueue_head(&profile->idle_slots_wait_queue); in blk_crypto_profile_init()
104 INIT_LIST_HEAD(&profile->idle_slots); in blk_crypto_profile_init()
107 profile->slots[slot].profile = profile; in blk_crypto_profile_init()
108 list_add_tail(&profile->slots[slot].idle_slot_node, in blk_crypto_profile_init()
109 &profile->idle_slots); in blk_crypto_profile_init()
112 spin_lock_init(&profile->idle_slots_lock); in blk_crypto_profile_init()
122 profile->log_slot_ht_size = ilog2(slot_hashtable_size); in blk_crypto_profile_init()
123 profile->slot_hashtable = in blk_crypto_profile_init()
125 sizeof(profile->slot_hashtable[0]), GFP_KERNEL); in blk_crypto_profile_init()
126 if (!profile->slot_hashtable) in blk_crypto_profile_init()
129 INIT_HLIST_HEAD(&profile->slot_hashtable[i]); in blk_crypto_profile_init()
134 blk_crypto_profile_destroy(profile); in blk_crypto_profile_init()
139 static void blk_crypto_profile_destroy_callback(void *profile) in blk_crypto_profile_destroy_callback() argument
141 blk_crypto_profile_destroy(profile); in blk_crypto_profile_destroy_callback()
156 struct blk_crypto_profile *profile, in devm_blk_crypto_profile_init() argument
159 int err = blk_crypto_profile_init(profile, num_slots); in devm_blk_crypto_profile_init()
166 profile); in devm_blk_crypto_profile_init()
171 blk_crypto_hash_bucket_for_key(struct blk_crypto_profile *profile, in blk_crypto_hash_bucket_for_key() argument
174 return &profile->slot_hashtable[ in blk_crypto_hash_bucket_for_key()
175 hash_ptr(key, profile->log_slot_ht_size)]; in blk_crypto_hash_bucket_for_key()
181 struct blk_crypto_profile *profile = slot->profile; in blk_crypto_remove_slot_from_lru_list() local
184 spin_lock_irqsave(&profile->idle_slots_lock, flags); in blk_crypto_remove_slot_from_lru_list()
186 spin_unlock_irqrestore(&profile->idle_slots_lock, flags); in blk_crypto_remove_slot_from_lru_list()
190 blk_crypto_find_keyslot(struct blk_crypto_profile *profile, in blk_crypto_find_keyslot() argument
194 blk_crypto_hash_bucket_for_key(profile, key); in blk_crypto_find_keyslot()
205 blk_crypto_find_and_grab_keyslot(struct blk_crypto_profile *profile, in blk_crypto_find_and_grab_keyslot() argument
210 slot = blk_crypto_find_keyslot(profile, key); in blk_crypto_find_and_grab_keyslot()
228 return slot - slot->profile->slots; in blk_crypto_keyslot_index()
248 blk_status_t blk_crypto_get_keyslot(struct blk_crypto_profile *profile, in blk_crypto_get_keyslot() argument
262 if (profile->num_slots == 0) in blk_crypto_get_keyslot()
265 down_read(&profile->lock); in blk_crypto_get_keyslot()
266 slot = blk_crypto_find_and_grab_keyslot(profile, key); in blk_crypto_get_keyslot()
267 up_read(&profile->lock); in blk_crypto_get_keyslot()
272 blk_crypto_hw_enter(profile); in blk_crypto_get_keyslot()
273 slot = blk_crypto_find_and_grab_keyslot(profile, key); in blk_crypto_get_keyslot()
275 blk_crypto_hw_exit(profile); in blk_crypto_get_keyslot()
283 if (!list_empty(&profile->idle_slots)) in blk_crypto_get_keyslot()
286 blk_crypto_hw_exit(profile); in blk_crypto_get_keyslot()
287 wait_event(profile->idle_slots_wait_queue, in blk_crypto_get_keyslot()
288 !list_empty(&profile->idle_slots)); in blk_crypto_get_keyslot()
291 slot = list_first_entry(&profile->idle_slots, struct blk_crypto_keyslot, in blk_crypto_get_keyslot()
295 err = profile->ll_ops.keyslot_program(profile, key, slot_idx); in blk_crypto_get_keyslot()
297 wake_up(&profile->idle_slots_wait_queue); in blk_crypto_get_keyslot()
298 blk_crypto_hw_exit(profile); in blk_crypto_get_keyslot()
307 blk_crypto_hash_bucket_for_key(profile, key)); in blk_crypto_get_keyslot()
313 blk_crypto_hw_exit(profile); in blk_crypto_get_keyslot()
327 struct blk_crypto_profile *profile = slot->profile; in blk_crypto_put_keyslot() local
331 &profile->idle_slots_lock, flags)) { in blk_crypto_put_keyslot()
332 list_add_tail(&slot->idle_slot_node, &profile->idle_slots); in blk_crypto_put_keyslot()
333 spin_unlock_irqrestore(&profile->idle_slots_lock, flags); in blk_crypto_put_keyslot()
334 wake_up(&profile->idle_slots_wait_queue); in blk_crypto_put_keyslot()
346 bool __blk_crypto_cfg_supported(struct blk_crypto_profile *profile, in __blk_crypto_cfg_supported() argument
349 if (!profile) in __blk_crypto_cfg_supported()
351 if (!(profile->modes_supported[cfg->crypto_mode] & cfg->data_unit_size)) in __blk_crypto_cfg_supported()
353 if (profile->max_dun_bytes_supported < cfg->dun_bytes) in __blk_crypto_cfg_supported()
363 int __blk_crypto_evict_key(struct blk_crypto_profile *profile, in __blk_crypto_evict_key() argument
369 if (profile->num_slots == 0) { in __blk_crypto_evict_key()
370 if (profile->ll_ops.keyslot_evict) { in __blk_crypto_evict_key()
371 blk_crypto_hw_enter(profile); in __blk_crypto_evict_key()
372 err = profile->ll_ops.keyslot_evict(profile, key, -1); in __blk_crypto_evict_key()
373 blk_crypto_hw_exit(profile); in __blk_crypto_evict_key()
379 blk_crypto_hw_enter(profile); in __blk_crypto_evict_key()
380 slot = blk_crypto_find_keyslot(profile, key); in __blk_crypto_evict_key()
395 err = profile->ll_ops.keyslot_evict(profile, key, in __blk_crypto_evict_key()
405 blk_crypto_hw_exit(profile); in __blk_crypto_evict_key()
418 void blk_crypto_reprogram_all_keys(struct blk_crypto_profile *profile) in blk_crypto_reprogram_all_keys() argument
422 if (profile->num_slots == 0) in blk_crypto_reprogram_all_keys()
426 down_write(&profile->lock); in blk_crypto_reprogram_all_keys()
427 for (slot = 0; slot < profile->num_slots; slot++) { in blk_crypto_reprogram_all_keys()
428 const struct blk_crypto_key *key = profile->slots[slot].key; in blk_crypto_reprogram_all_keys()
434 err = profile->ll_ops.keyslot_program(profile, key, slot); in blk_crypto_reprogram_all_keys()
437 up_write(&profile->lock); in blk_crypto_reprogram_all_keys()
441 void blk_crypto_profile_destroy(struct blk_crypto_profile *profile) in blk_crypto_profile_destroy() argument
443 if (!profile) in blk_crypto_profile_destroy()
445 lockdep_unregister_key(&profile->lockdep_key); in blk_crypto_profile_destroy()
446 kvfree(profile->slot_hashtable); in blk_crypto_profile_destroy()
447 kvfree_sensitive(profile->slots, in blk_crypto_profile_destroy()
448 sizeof(profile->slots[0]) * profile->num_slots); in blk_crypto_profile_destroy()
449 memzero_explicit(profile, sizeof(*profile)); in blk_crypto_profile_destroy()
453 bool blk_crypto_register(struct blk_crypto_profile *profile, in blk_crypto_register() argument
460 q->crypto_profile = profile; in blk_crypto_register()