hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
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
/* SPDX-License-Identifier: GPL-2.0 */
/*
 * Copyright 2019 Google LLC
 */
 
#ifndef _UFSHCD_CRYPTO_H
#define _UFSHCD_CRYPTO_H
 
#ifdef CONFIG_SCSI_UFS_CRYPTO
#include "ufshcd.h"
#include "ufshci.h"
 
static inline void ufshcd_prepare_lrbp_crypto(struct request *rq,
                         struct ufshcd_lrb *lrbp)
{
   if (!rq || !rq->crypt_keyslot) {
       lrbp->crypto_key_slot = -1;
       return;
   }
 
   lrbp->crypto_key_slot = blk_ksm_get_slot_idx(rq->crypt_keyslot);
   lrbp->data_unit_num = rq->crypt_ctx->bc_dun[0];
}
 
static inline void
ufshcd_prepare_req_desc_hdr_crypto(struct ufshcd_lrb *lrbp, u32 *dword_0,
                  u32 *dword_1, u32 *dword_3)
{
   if (lrbp->crypto_key_slot >= 0) {
       *dword_0 |= UTP_REQ_DESC_CRYPTO_ENABLE_CMD;
       *dword_0 |= lrbp->crypto_key_slot;
       *dword_1 = lower_32_bits(lrbp->data_unit_num);
       *dword_3 = upper_32_bits(lrbp->data_unit_num);
   }
}
 
static inline void ufshcd_crypto_clear_prdt(struct ufs_hba *hba,
                       struct ufshcd_lrb *lrbp)
{
   if (!(hba->quirks & UFSHCD_QUIRK_KEYS_IN_PRDT))
       return;
 
   if (!lrbp->cmd->request->crypt_ctx)
       return;
 
   memzero_explicit(lrbp->ucd_prdt_ptr,
            hba->sg_entry_size * scsi_sg_count(lrbp->cmd));
}
 
bool ufshcd_crypto_enable(struct ufs_hba *hba);
 
int ufshcd_hba_init_crypto_capabilities(struct ufs_hba *hba);
 
void ufshcd_init_crypto(struct ufs_hba *hba);
 
void ufshcd_crypto_setup_rq_keyslot_manager(struct ufs_hba *hba,
                       struct request_queue *q);
 
#else /* CONFIG_SCSI_UFS_CRYPTO */
 
static inline void ufshcd_prepare_lrbp_crypto(struct request *rq,
                         struct ufshcd_lrb *lrbp) { }
 
static inline void
ufshcd_prepare_req_desc_hdr_crypto(struct ufshcd_lrb *lrbp, u32 *dword_0,
                  u32 *dword_1, u32 *dword_3) { }
 
static inline void ufshcd_crypto_clear_prdt(struct ufs_hba *hba,
                       struct ufshcd_lrb *lrbp) { }
 
static inline bool ufshcd_crypto_enable(struct ufs_hba *hba)
{
   return false;
}
 
static inline int ufshcd_hba_init_crypto_capabilities(struct ufs_hba *hba)
{
   return 0;
}
 
static inline void ufshcd_init_crypto(struct ufs_hba *hba) { }
 
static inline void ufshcd_crypto_setup_rq_keyslot_manager(struct ufs_hba *hba,
                       struct request_queue *q) { }
 
#endif /* CONFIG_SCSI_UFS_CRYPTO */
 
#endif /* _UFSHCD_CRYPTO_H */