1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Copyright 2019 Google LLC
6 #ifndef _UFSHCD_CRYPTO_H
7 #define _UFSHCD_CRYPTO_H
9 #include <scsi/scsi_cmnd.h>
10 #include <ufs/ufshcd.h>
11 #include "ufshcd-priv.h"
12 #include <ufs/ufshci.h>
14 #ifdef CONFIG_SCSI_UFS_CRYPTO
16 static inline void ufshcd_prepare_lrbp_crypto(struct request *rq,
17 struct ufshcd_lrb *lrbp)
19 if (!rq || !rq->crypt_keyslot) {
20 lrbp->crypto_key_slot = -1;
24 lrbp->crypto_key_slot = blk_crypto_keyslot_index(rq->crypt_keyslot);
25 lrbp->data_unit_num = rq->crypt_ctx->bc_dun[0];
29 ufshcd_prepare_req_desc_hdr_crypto(struct ufshcd_lrb *lrbp,
30 struct request_desc_header *h)
32 if (lrbp->crypto_key_slot < 0)
35 h->cci = lrbp->crypto_key_slot;
36 h->dunl = cpu_to_le32(lower_32_bits(lrbp->data_unit_num));
37 h->dunu = cpu_to_le32(upper_32_bits(lrbp->data_unit_num));
40 bool ufshcd_crypto_enable(struct ufs_hba *hba);
42 int ufshcd_hba_init_crypto_capabilities(struct ufs_hba *hba);
44 void ufshcd_init_crypto(struct ufs_hba *hba);
46 void ufshcd_crypto_register(struct ufs_hba *hba, struct request_queue *q);
48 #else /* CONFIG_SCSI_UFS_CRYPTO */
50 static inline void ufshcd_prepare_lrbp_crypto(struct request *rq,
51 struct ufshcd_lrb *lrbp) { }
54 ufshcd_prepare_req_desc_hdr_crypto(struct ufshcd_lrb *lrbp,
55 struct request_desc_header *h) { }
57 static inline bool ufshcd_crypto_enable(struct ufs_hba *hba)
62 static inline int ufshcd_hba_init_crypto_capabilities(struct ufs_hba *hba)
67 static inline void ufshcd_init_crypto(struct ufs_hba *hba) { }
69 static inline void ufshcd_crypto_register(struct ufs_hba *hba,
70 struct request_queue *q) { }
72 #endif /* CONFIG_SCSI_UFS_CRYPTO */
74 #endif /* _UFSHCD_CRYPTO_H */