hc
2023-11-06 e3e12f52b214121840b44c91de5b3e5af5d3eb84
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
/* SPDX-License-Identifier: GPL-2.0 */
/*
 * Copyright 2019 Google LLC
 */
 
#ifndef _UFSHCD_CRYPTO_H
#define _UFSHCD_CRYPTO_H
 
#ifdef CONFIG_SCSI_UFS_CRYPTO
#include <linux/keyslot-manager.h>
#include "ufshcd.h"
#include "ufshci.h"
 
static inline int ufshcd_num_keyslots(struct ufs_hba *hba)
{
   return hba->crypto_capabilities.config_count + 1;
}
 
static inline bool ufshcd_keyslot_valid(struct ufs_hba *hba, unsigned int slot)
{
   /*
    * The actual number of configurations supported is (CFGC+1), so slot
    * numbers range from 0 to config_count inclusive.
    */
   return slot < ufshcd_num_keyslots(hba);
}
 
static inline bool ufshcd_hba_is_crypto_supported(struct ufs_hba *hba)
{
   return hba->crypto_capabilities.reg_val != 0;
}
 
static inline bool ufshcd_is_crypto_enabled(struct ufs_hba *hba)
{
   return hba->caps & UFSHCD_CAP_CRYPTO;
}
 
/* Functions implementing UFSHCI v2.1 specification behaviour */
int ufshcd_crypto_cap_find(struct ufs_hba *hba,
              enum blk_crypto_mode_num crypto_mode,
              unsigned int data_unit_size);
 
int ufshcd_prepare_lrbp_crypto_spec(struct ufs_hba *hba,
                   struct scsi_cmnd *cmd,
                   struct ufshcd_lrb *lrbp);
 
void ufshcd_crypto_enable_spec(struct ufs_hba *hba);
 
void ufshcd_crypto_disable_spec(struct ufs_hba *hba);
 
struct keyslot_mgmt_ll_ops;
int ufshcd_hba_init_crypto_spec(struct ufs_hba *hba,
               const struct keyslot_mgmt_ll_ops *ksm_ops);
 
void ufshcd_crypto_setup_rq_keyslot_manager_spec(struct ufs_hba *hba,
                        struct request_queue *q);
 
void ufshcd_crypto_destroy_rq_keyslot_manager_spec(struct ufs_hba *hba,
                          struct request_queue *q);
 
static inline bool ufshcd_lrbp_crypto_enabled(struct ufshcd_lrb *lrbp)
{
   return lrbp->crypto_enable;
}
 
/* Crypto Variant Ops Support */
void ufshcd_crypto_enable(struct ufs_hba *hba);
 
void ufshcd_crypto_disable(struct ufs_hba *hba);
 
int ufshcd_hba_init_crypto(struct ufs_hba *hba);
 
void ufshcd_crypto_setup_rq_keyslot_manager(struct ufs_hba *hba,
                       struct request_queue *q);
 
void ufshcd_crypto_destroy_rq_keyslot_manager(struct ufs_hba *hba,
                         struct request_queue *q);
 
int ufshcd_prepare_lrbp_crypto(struct ufs_hba *hba,
                  struct scsi_cmnd *cmd,
                  struct ufshcd_lrb *lrbp);
 
int ufshcd_map_sg_crypto(struct ufs_hba *hba, struct ufshcd_lrb *lrbp);
 
int ufshcd_complete_lrbp_crypto(struct ufs_hba *hba,
               struct scsi_cmnd *cmd,
               struct ufshcd_lrb *lrbp);
 
void ufshcd_crypto_debug(struct ufs_hba *hba);
 
int ufshcd_crypto_suspend(struct ufs_hba *hba, enum ufs_pm_op pm_op);
 
int ufshcd_crypto_resume(struct ufs_hba *hba, enum ufs_pm_op pm_op);
 
void ufshcd_crypto_set_vops(struct ufs_hba *hba,
               struct ufs_hba_crypto_variant_ops *crypto_vops);
 
#else /* CONFIG_SCSI_UFS_CRYPTO */
 
static inline bool ufshcd_keyslot_valid(struct ufs_hba *hba,
                   unsigned int slot)
{
   return false;
}
 
static inline bool ufshcd_hba_is_crypto_supported(struct ufs_hba *hba)
{
   return false;
}
 
static inline bool ufshcd_is_crypto_enabled(struct ufs_hba *hba)
{
   return false;
}
 
static inline void ufshcd_crypto_enable(struct ufs_hba *hba) { }
 
static inline void ufshcd_crypto_disable(struct ufs_hba *hba) { }
 
static inline int ufshcd_hba_init_crypto(struct ufs_hba *hba)
{
   return 0;
}
 
static inline void ufshcd_crypto_setup_rq_keyslot_manager(struct ufs_hba *hba,
                       struct request_queue *q) { }
 
static inline void ufshcd_crypto_destroy_rq_keyslot_manager(struct ufs_hba *hba,
                       struct request_queue *q) { }
 
static inline int ufshcd_prepare_lrbp_crypto(struct ufs_hba *hba,
                        struct scsi_cmnd *cmd,
                        struct ufshcd_lrb *lrbp)
{
   return 0;
}
 
static inline int ufshcd_map_sg_crypto(struct ufs_hba *hba,
                      struct ufshcd_lrb *lrbp)
{
   return 0;
}
 
static inline bool ufshcd_lrbp_crypto_enabled(struct ufshcd_lrb *lrbp)
{
   return false;
}
 
static inline int ufshcd_complete_lrbp_crypto(struct ufs_hba *hba,
                         struct scsi_cmnd *cmd,
                         struct ufshcd_lrb *lrbp)
{
   return 0;
}
 
static inline void ufshcd_crypto_debug(struct ufs_hba *hba) { }
 
static inline int ufshcd_crypto_suspend(struct ufs_hba *hba,
                   enum ufs_pm_op pm_op)
{
   return 0;
}
 
static inline int ufshcd_crypto_resume(struct ufs_hba *hba,
                   enum ufs_pm_op pm_op)
{
   return 0;
}
 
static inline void ufshcd_crypto_set_vops(struct ufs_hba *hba,
           struct ufs_hba_crypto_variant_ops *crypto_vops) { }
 
#endif /* CONFIG_SCSI_UFS_CRYPTO */
 
#endif /* _UFSHCD_CRYPTO_H */