1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3 * Copyright 2019 Google LLC
4 */
5
6 #ifndef _UFSHCD_CRYPTO_H
7 #define _UFSHCD_CRYPTO_H
8
9 #ifdef CONFIG_SCSI_UFS_CRYPTO
10 #include <linux/keyslot-manager.h>
11 #include "ufshcd.h"
12 #include "ufshci.h"
13
ufshcd_num_keyslots(struct ufs_hba * hba)14 static inline int ufshcd_num_keyslots(struct ufs_hba *hba)
15 {
16 return hba->crypto_capabilities.config_count + 1;
17 }
18
ufshcd_keyslot_valid(struct ufs_hba * hba,unsigned int slot)19 static inline bool ufshcd_keyslot_valid(struct ufs_hba *hba, unsigned int slot)
20 {
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);
26 }
27
ufshcd_hba_is_crypto_supported(struct ufs_hba * hba)28 static inline bool ufshcd_hba_is_crypto_supported(struct ufs_hba *hba)
29 {
30 return hba->crypto_capabilities.reg_val != 0;
31 }
32
ufshcd_is_crypto_enabled(struct ufs_hba * hba)33 static inline bool ufshcd_is_crypto_enabled(struct ufs_hba *hba)
34 {
35 return hba->caps & UFSHCD_CAP_CRYPTO;
36 }
37
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);
42
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
ufshcd_lrbp_crypto_enabled(struct ufshcd_lrb * lrbp)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);
72
73 void ufshcd_crypto_setup_rq_keyslot_manager(struct ufs_hba *hba,
74 struct request_queue *q);
75
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
98 #else /* CONFIG_SCSI_UFS_CRYPTO */
99
ufshcd_keyslot_valid(struct ufs_hba * hba,unsigned int slot)100 static inline bool ufshcd_keyslot_valid(struct ufs_hba *hba,
101 unsigned int slot)
102 {
103 return false;
104 }
105
ufshcd_hba_is_crypto_supported(struct ufs_hba * hba)106 static inline bool ufshcd_hba_is_crypto_supported(struct ufs_hba *hba)
107 {
108 return false;
109 }
110
ufshcd_is_crypto_enabled(struct ufs_hba * hba)111 static inline bool ufshcd_is_crypto_enabled(struct ufs_hba *hba)
112 {
113 return false;
114 }
115
ufshcd_crypto_enable(struct ufs_hba * hba)116 static inline void ufshcd_crypto_enable(struct ufs_hba *hba) { }
117
ufshcd_crypto_disable(struct ufs_hba * hba)118 static inline void ufshcd_crypto_disable(struct ufs_hba *hba) { }
119
ufshcd_hba_init_crypto(struct ufs_hba * hba)120 static inline int ufshcd_hba_init_crypto(struct ufs_hba *hba)
121 {
122 return 0;
123 }
124
ufshcd_crypto_setup_rq_keyslot_manager(struct ufs_hba * hba,struct request_queue * q)125 static inline void ufshcd_crypto_setup_rq_keyslot_manager(struct ufs_hba *hba,
126 struct request_queue *q) { }
127
ufshcd_crypto_destroy_rq_keyslot_manager(struct ufs_hba * hba,struct request_queue * q)128 static inline void ufshcd_crypto_destroy_rq_keyslot_manager(struct ufs_hba *hba,
129 struct request_queue *q) { }
130
ufshcd_prepare_lrbp_crypto(struct ufs_hba * hba,struct scsi_cmnd * cmd,struct ufshcd_lrb * lrbp)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
ufshcd_map_sg_crypto(struct ufs_hba * hba,struct ufshcd_lrb * lrbp)138 static inline int ufshcd_map_sg_crypto(struct ufs_hba *hba,
139 struct ufshcd_lrb *lrbp)
140 {
141 return 0;
142 }
143
ufshcd_lrbp_crypto_enabled(struct ufshcd_lrb * lrbp)144 static inline bool ufshcd_lrbp_crypto_enabled(struct ufshcd_lrb *lrbp)
145 {
146 return false;
147 }
148
ufshcd_complete_lrbp_crypto(struct ufs_hba * hba,struct scsi_cmnd * cmd,struct ufshcd_lrb * lrbp)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
ufshcd_crypto_debug(struct ufs_hba * hba)156 static inline void ufshcd_crypto_debug(struct ufs_hba *hba) { }
157
ufshcd_crypto_suspend(struct ufs_hba * hba,enum ufs_pm_op pm_op)158 static inline int ufshcd_crypto_suspend(struct ufs_hba *hba,
159 enum ufs_pm_op pm_op)
160 {
161 return 0;
162 }
163
ufshcd_crypto_resume(struct ufs_hba * hba,enum ufs_pm_op pm_op)164 static inline int ufshcd_crypto_resume(struct ufs_hba *hba,
165 enum ufs_pm_op pm_op)
166 {
167 return 0;
168 }
169
ufshcd_crypto_set_vops(struct ufs_hba * hba,struct ufs_hba_crypto_variant_ops * crypto_vops)170 static inline void ufshcd_crypto_set_vops(struct ufs_hba *hba,
171 struct ufs_hba_crypto_variant_ops *crypto_vops) { }
172
173 #endif /* CONFIG_SCSI_UFS_CRYPTO */
174
175 #endif /* _UFSHCD_CRYPTO_H */
176