1
2
3
4
5
6#ifndef __LINUX_KEYSLOT_MANAGER_H
7#define __LINUX_KEYSLOT_MANAGER_H
8
9#include <linux/bio.h>
10#include <linux/blk-crypto.h>
11
12struct blk_keyslot_manager;
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27struct blk_ksm_ll_ops {
28 int (*keyslot_program)(struct blk_keyslot_manager *ksm,
29 const struct blk_crypto_key *key,
30 unsigned int slot);
31 int (*keyslot_evict)(struct blk_keyslot_manager *ksm,
32 const struct blk_crypto_key *key,
33 unsigned int slot);
34};
35
36struct blk_keyslot_manager {
37
38
39
40
41
42 struct blk_ksm_ll_ops ksm_ll_ops;
43
44
45
46
47
48 unsigned int max_dun_bytes_supported;
49
50
51
52
53
54
55
56
57 unsigned int crypto_modes_supported[BLK_ENCRYPTION_MODE_MAX];
58
59
60 struct device *dev;
61
62
63
64 unsigned int num_slots;
65
66
67 struct rw_semaphore lock;
68
69
70 wait_queue_head_t idle_slots_wait_queue;
71 struct list_head idle_slots;
72 spinlock_t idle_slots_lock;
73
74
75
76
77
78
79 struct hlist_head *slot_hashtable;
80 unsigned int log_slot_ht_size;
81
82
83 struct blk_ksm_keyslot *slots;
84};
85
86int blk_ksm_init(struct blk_keyslot_manager *ksm, unsigned int num_slots);
87
88int devm_blk_ksm_init(struct device *dev, struct blk_keyslot_manager *ksm,
89 unsigned int num_slots);
90
91blk_status_t blk_ksm_get_slot_for_key(struct blk_keyslot_manager *ksm,
92 const struct blk_crypto_key *key,
93 struct blk_ksm_keyslot **slot_ptr);
94
95unsigned int blk_ksm_get_slot_idx(struct blk_ksm_keyslot *slot);
96
97void blk_ksm_put_slot(struct blk_ksm_keyslot *slot);
98
99bool blk_ksm_crypto_cfg_supported(struct blk_keyslot_manager *ksm,
100 const struct blk_crypto_config *cfg);
101
102int blk_ksm_evict_key(struct blk_keyslot_manager *ksm,
103 const struct blk_crypto_key *key);
104
105void blk_ksm_reprogram_all_keys(struct blk_keyslot_manager *ksm);
106
107void blk_ksm_destroy(struct blk_keyslot_manager *ksm);
108
109void blk_ksm_intersect_modes(struct blk_keyslot_manager *parent,
110 const struct blk_keyslot_manager *child);
111
112void blk_ksm_init_passthrough(struct blk_keyslot_manager *ksm);
113
114bool blk_ksm_is_superset(struct blk_keyslot_manager *ksm_superset,
115 struct blk_keyslot_manager *ksm_subset);
116
117void blk_ksm_update_capabilities(struct blk_keyslot_manager *target_ksm,
118 struct blk_keyslot_manager *reference_ksm);
119
120#endif
121