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 "ufshcd.h"
11 #include "ufshci.h"
12
ufshcd_prepare_lrbp_crypto(struct request * rq,struct ufshcd_lrb * lrbp)13 static inline void ufshcd_prepare_lrbp_crypto(struct request *rq,
14 struct ufshcd_lrb *lrbp)
15 {
16 if (!rq || !rq->crypt_keyslot) {
17 lrbp->crypto_key_slot = -1;
18 return;
19 }
20
21 lrbp->crypto_key_slot = blk_crypto_keyslot_index(rq->crypt_keyslot);
22 lrbp->data_unit_num = rq->crypt_ctx->bc_dun[0];
23 }
24
25 static inline void
ufshcd_prepare_req_desc_hdr_crypto(struct ufshcd_lrb * lrbp,u32 * dword_0,u32 * dword_1,u32 * dword_3)26 ufshcd_prepare_req_desc_hdr_crypto(struct ufshcd_lrb *lrbp, u32 *dword_0,
27 u32 *dword_1, u32 *dword_3)
28 {
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 }
35 }
36
37 bool ufshcd_crypto_enable(struct ufs_hba *hba);
38
39 int ufshcd_hba_init_crypto_capabilities(struct ufs_hba *hba);
40
41 void ufshcd_init_crypto(struct ufs_hba *hba);
42
43 void ufshcd_crypto_register(struct ufs_hba *hba, struct request_queue *q);
44
45 #else /* CONFIG_SCSI_UFS_CRYPTO */
46
ufshcd_prepare_lrbp_crypto(struct request * rq,struct ufshcd_lrb * lrbp)47 static inline void ufshcd_prepare_lrbp_crypto(struct request *rq,
48 struct ufshcd_lrb *lrbp) { }
49
50 static inline void
ufshcd_prepare_req_desc_hdr_crypto(struct ufshcd_lrb * lrbp,u32 * dword_0,u32 * dword_1,u32 * dword_3)51 ufshcd_prepare_req_desc_hdr_crypto(struct ufshcd_lrb *lrbp, u32 *dword_0,
52 u32 *dword_1, u32 *dword_3) { }
53
ufshcd_crypto_enable(struct ufs_hba * hba)54 static inline bool ufshcd_crypto_enable(struct ufs_hba *hba)
55 {
56 return false;
57 }
58
ufshcd_hba_init_crypto_capabilities(struct ufs_hba * hba)59 static inline int ufshcd_hba_init_crypto_capabilities(struct ufs_hba *hba)
60 {
61 return 0;
62 }
63
ufshcd_init_crypto(struct ufs_hba * hba)64 static inline void ufshcd_init_crypto(struct ufs_hba *hba) { }
65
ufshcd_crypto_register(struct ufs_hba * hba,struct request_queue * q)66 static inline void ufshcd_crypto_register(struct ufs_hba *hba,
67 struct request_queue *q) { }
68
69 #endif /* CONFIG_SCSI_UFS_CRYPTO */
70
71 #endif /* _UFSHCD_CRYPTO_H */
72