hc
2024-05-10 37f49e37ab4cb5d0bc4c60eb5c6d4dd57db767bb
kernel/drivers/scsi/ufs/ufshcd-crypto.h
....@@ -7,168 +7,81 @@
77 #define _UFSHCD_CRYPTO_H
88
99 #ifdef CONFIG_SCSI_UFS_CRYPTO
10
-#include <linux/keyslot-manager.h>
1110 #include "ufshcd.h"
1211 #include "ufshci.h"
1312
14
-static inline int ufshcd_num_keyslots(struct ufs_hba *hba)
13
+static inline void ufshcd_prepare_lrbp_crypto(struct request *rq,
14
+ struct ufshcd_lrb *lrbp)
1515 {
16
- return hba->crypto_capabilities.config_count + 1;
16
+ if (!rq || !rq->crypt_keyslot) {
17
+ lrbp->crypto_key_slot = -1;
18
+ return;
19
+ }
20
+
21
+ lrbp->crypto_key_slot = blk_ksm_get_slot_idx(rq->crypt_keyslot);
22
+ lrbp->data_unit_num = rq->crypt_ctx->bc_dun[0];
1723 }
1824
19
-static inline bool ufshcd_keyslot_valid(struct ufs_hba *hba, unsigned int slot)
25
+static inline void
26
+ufshcd_prepare_req_desc_hdr_crypto(struct ufshcd_lrb *lrbp, u32 *dword_0,
27
+ u32 *dword_1, u32 *dword_3)
2028 {
21
- /*
22
- * The actual number of configurations supported is (CFGC+1), so slot
23
- * numbers range from 0 to config_count inclusive.
24
- */
25
- return slot < ufshcd_num_keyslots(hba);
29
+ if (lrbp->crypto_key_slot >= 0) {
30
+ *dword_0 |= UTP_REQ_DESC_CRYPTO_ENABLE_CMD;
31
+ *dword_0 |= lrbp->crypto_key_slot;
32
+ *dword_1 = lower_32_bits(lrbp->data_unit_num);
33
+ *dword_3 = upper_32_bits(lrbp->data_unit_num);
34
+ }
2635 }
2736
28
-static inline bool ufshcd_hba_is_crypto_supported(struct ufs_hba *hba)
37
+static inline void ufshcd_crypto_clear_prdt(struct ufs_hba *hba,
38
+ struct ufshcd_lrb *lrbp)
2939 {
30
- return hba->crypto_capabilities.reg_val != 0;
40
+ if (!(hba->quirks & UFSHCD_QUIRK_KEYS_IN_PRDT))
41
+ return;
42
+
43
+ if (!lrbp->cmd->request->crypt_ctx)
44
+ return;
45
+
46
+ memzero_explicit(lrbp->ucd_prdt_ptr,
47
+ hba->sg_entry_size * scsi_sg_count(lrbp->cmd));
3148 }
3249
33
-static inline bool ufshcd_is_crypto_enabled(struct ufs_hba *hba)
34
-{
35
- return hba->caps & UFSHCD_CAP_CRYPTO;
36
-}
50
+bool ufshcd_crypto_enable(struct ufs_hba *hba);
3751
38
-/* Functions implementing UFSHCI v2.1 specification behaviour */
39
-int ufshcd_crypto_cap_find(struct ufs_hba *hba,
40
- enum blk_crypto_mode_num crypto_mode,
41
- unsigned int data_unit_size);
52
+int ufshcd_hba_init_crypto_capabilities(struct ufs_hba *hba);
4253
43
-int ufshcd_prepare_lrbp_crypto_spec(struct ufs_hba *hba,
44
- struct scsi_cmnd *cmd,
45
- struct ufshcd_lrb *lrbp);
46
-
47
-void ufshcd_crypto_enable_spec(struct ufs_hba *hba);
48
-
49
-void ufshcd_crypto_disable_spec(struct ufs_hba *hba);
50
-
51
-struct keyslot_mgmt_ll_ops;
52
-int ufshcd_hba_init_crypto_spec(struct ufs_hba *hba,
53
- const struct keyslot_mgmt_ll_ops *ksm_ops);
54
-
55
-void ufshcd_crypto_setup_rq_keyslot_manager_spec(struct ufs_hba *hba,
56
- struct request_queue *q);
57
-
58
-void ufshcd_crypto_destroy_rq_keyslot_manager_spec(struct ufs_hba *hba,
59
- struct request_queue *q);
60
-
61
-static inline bool ufshcd_lrbp_crypto_enabled(struct ufshcd_lrb *lrbp)
62
-{
63
- return lrbp->crypto_enable;
64
-}
65
-
66
-/* Crypto Variant Ops Support */
67
-void ufshcd_crypto_enable(struct ufs_hba *hba);
68
-
69
-void ufshcd_crypto_disable(struct ufs_hba *hba);
70
-
71
-int ufshcd_hba_init_crypto(struct ufs_hba *hba);
54
+void ufshcd_init_crypto(struct ufs_hba *hba);
7255
7356 void ufshcd_crypto_setup_rq_keyslot_manager(struct ufs_hba *hba,
7457 struct request_queue *q);
7558
76
-void ufshcd_crypto_destroy_rq_keyslot_manager(struct ufs_hba *hba,
77
- struct request_queue *q);
78
-
79
-int ufshcd_prepare_lrbp_crypto(struct ufs_hba *hba,
80
- struct scsi_cmnd *cmd,
81
- struct ufshcd_lrb *lrbp);
82
-
83
-int ufshcd_map_sg_crypto(struct ufs_hba *hba, struct ufshcd_lrb *lrbp);
84
-
85
-int ufshcd_complete_lrbp_crypto(struct ufs_hba *hba,
86
- struct scsi_cmnd *cmd,
87
- struct ufshcd_lrb *lrbp);
88
-
89
-void ufshcd_crypto_debug(struct ufs_hba *hba);
90
-
91
-int ufshcd_crypto_suspend(struct ufs_hba *hba, enum ufs_pm_op pm_op);
92
-
93
-int ufshcd_crypto_resume(struct ufs_hba *hba, enum ufs_pm_op pm_op);
94
-
95
-void ufshcd_crypto_set_vops(struct ufs_hba *hba,
96
- struct ufs_hba_crypto_variant_ops *crypto_vops);
97
-
9859 #else /* CONFIG_SCSI_UFS_CRYPTO */
9960
100
-static inline bool ufshcd_keyslot_valid(struct ufs_hba *hba,
101
- unsigned int slot)
61
+static inline void ufshcd_prepare_lrbp_crypto(struct request *rq,
62
+ struct ufshcd_lrb *lrbp) { }
63
+
64
+static inline void
65
+ufshcd_prepare_req_desc_hdr_crypto(struct ufshcd_lrb *lrbp, u32 *dword_0,
66
+ u32 *dword_1, u32 *dword_3) { }
67
+
68
+static inline void ufshcd_crypto_clear_prdt(struct ufs_hba *hba,
69
+ struct ufshcd_lrb *lrbp) { }
70
+
71
+static inline bool ufshcd_crypto_enable(struct ufs_hba *hba)
10272 {
10373 return false;
10474 }
10575
106
-static inline bool ufshcd_hba_is_crypto_supported(struct ufs_hba *hba)
107
-{
108
- return false;
109
-}
110
-
111
-static inline bool ufshcd_is_crypto_enabled(struct ufs_hba *hba)
112
-{
113
- return false;
114
-}
115
-
116
-static inline void ufshcd_crypto_enable(struct ufs_hba *hba) { }
117
-
118
-static inline void ufshcd_crypto_disable(struct ufs_hba *hba) { }
119
-
120
-static inline int ufshcd_hba_init_crypto(struct ufs_hba *hba)
76
+static inline int ufshcd_hba_init_crypto_capabilities(struct ufs_hba *hba)
12177 {
12278 return 0;
12379 }
80
+
81
+static inline void ufshcd_init_crypto(struct ufs_hba *hba) { }
12482
12583 static inline void ufshcd_crypto_setup_rq_keyslot_manager(struct ufs_hba *hba,
12684 struct request_queue *q) { }
127
-
128
-static inline void ufshcd_crypto_destroy_rq_keyslot_manager(struct ufs_hba *hba,
129
- struct request_queue *q) { }
130
-
131
-static inline int ufshcd_prepare_lrbp_crypto(struct ufs_hba *hba,
132
- struct scsi_cmnd *cmd,
133
- struct ufshcd_lrb *lrbp)
134
-{
135
- return 0;
136
-}
137
-
138
-static inline int ufshcd_map_sg_crypto(struct ufs_hba *hba,
139
- struct ufshcd_lrb *lrbp)
140
-{
141
- return 0;
142
-}
143
-
144
-static inline bool ufshcd_lrbp_crypto_enabled(struct ufshcd_lrb *lrbp)
145
-{
146
- return false;
147
-}
148
-
149
-static inline int ufshcd_complete_lrbp_crypto(struct ufs_hba *hba,
150
- struct scsi_cmnd *cmd,
151
- struct ufshcd_lrb *lrbp)
152
-{
153
- return 0;
154
-}
155
-
156
-static inline void ufshcd_crypto_debug(struct ufs_hba *hba) { }
157
-
158
-static inline int ufshcd_crypto_suspend(struct ufs_hba *hba,
159
- enum ufs_pm_op pm_op)
160
-{
161
- return 0;
162
-}
163
-
164
-static inline int ufshcd_crypto_resume(struct ufs_hba *hba,
165
- enum ufs_pm_op pm_op)
166
-{
167
- return 0;
168
-}
169
-
170
-static inline void ufshcd_crypto_set_vops(struct ufs_hba *hba,
171
- struct ufs_hba_crypto_variant_ops *crypto_vops) { }
17285
17386 #endif /* CONFIG_SCSI_UFS_CRYPTO */
17487