| .. | .. |
|---|
| 7 | 7 | #define _UFSHCD_CRYPTO_H |
|---|
| 8 | 8 | |
|---|
| 9 | 9 | #ifdef CONFIG_SCSI_UFS_CRYPTO |
|---|
| 10 | | -#include <linux/keyslot-manager.h> |
|---|
| 11 | 10 | #include "ufshcd.h" |
|---|
| 12 | 11 | #include "ufshci.h" |
|---|
| 13 | 12 | |
|---|
| 14 | | -static inline int ufshcd_num_keyslots(struct ufs_hba *hba) |
|---|
| 13 | +static inline void ufshcd_prepare_lrbp_crypto(struct request *rq, |
|---|
| 14 | + struct ufshcd_lrb *lrbp) |
|---|
| 15 | 15 | { |
|---|
| 16 | | - return hba->crypto_capabilities.config_count + 1; |
|---|
| 16 | + if (!rq || !rq->crypt_keyslot) { |
|---|
| 17 | + lrbp->crypto_key_slot = -1; |
|---|
| 18 | + return; |
|---|
| 19 | + } |
|---|
| 20 | + |
|---|
| 21 | + lrbp->crypto_key_slot = blk_ksm_get_slot_idx(rq->crypt_keyslot); |
|---|
| 22 | + lrbp->data_unit_num = rq->crypt_ctx->bc_dun[0]; |
|---|
| 17 | 23 | } |
|---|
| 18 | 24 | |
|---|
| 19 | | -static inline bool ufshcd_keyslot_valid(struct ufs_hba *hba, unsigned int slot) |
|---|
| 25 | +static inline void |
|---|
| 26 | +ufshcd_prepare_req_desc_hdr_crypto(struct ufshcd_lrb *lrbp, u32 *dword_0, |
|---|
| 27 | + u32 *dword_1, u32 *dword_3) |
|---|
| 20 | 28 | { |
|---|
| 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); |
|---|
| 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 | + } |
|---|
| 26 | 35 | } |
|---|
| 27 | 36 | |
|---|
| 28 | | -static inline bool ufshcd_hba_is_crypto_supported(struct ufs_hba *hba) |
|---|
| 37 | +static inline void ufshcd_crypto_clear_prdt(struct ufs_hba *hba, |
|---|
| 38 | + struct ufshcd_lrb *lrbp) |
|---|
| 29 | 39 | { |
|---|
| 30 | | - return hba->crypto_capabilities.reg_val != 0; |
|---|
| 40 | + if (!(hba->quirks & UFSHCD_QUIRK_KEYS_IN_PRDT)) |
|---|
| 41 | + return; |
|---|
| 42 | + |
|---|
| 43 | + if (!lrbp->cmd->request->crypt_ctx) |
|---|
| 44 | + return; |
|---|
| 45 | + |
|---|
| 46 | + memzero_explicit(lrbp->ucd_prdt_ptr, |
|---|
| 47 | + hba->sg_entry_size * scsi_sg_count(lrbp->cmd)); |
|---|
| 31 | 48 | } |
|---|
| 32 | 49 | |
|---|
| 33 | | -static inline bool ufshcd_is_crypto_enabled(struct ufs_hba *hba) |
|---|
| 34 | | -{ |
|---|
| 35 | | - return hba->caps & UFSHCD_CAP_CRYPTO; |
|---|
| 36 | | -} |
|---|
| 50 | +bool ufshcd_crypto_enable(struct ufs_hba *hba); |
|---|
| 37 | 51 | |
|---|
| 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); |
|---|
| 52 | +int ufshcd_hba_init_crypto_capabilities(struct ufs_hba *hba); |
|---|
| 42 | 53 | |
|---|
| 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 | | - |
|---|
| 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); |
|---|
| 54 | +void ufshcd_init_crypto(struct ufs_hba *hba); |
|---|
| 72 | 55 | |
|---|
| 73 | 56 | void ufshcd_crypto_setup_rq_keyslot_manager(struct ufs_hba *hba, |
|---|
| 74 | 57 | struct request_queue *q); |
|---|
| 75 | 58 | |
|---|
| 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 | 59 | #else /* CONFIG_SCSI_UFS_CRYPTO */ |
|---|
| 99 | 60 | |
|---|
| 100 | | -static inline bool ufshcd_keyslot_valid(struct ufs_hba *hba, |
|---|
| 101 | | - unsigned int slot) |
|---|
| 61 | +static inline void ufshcd_prepare_lrbp_crypto(struct request *rq, |
|---|
| 62 | + struct ufshcd_lrb *lrbp) { } |
|---|
| 63 | + |
|---|
| 64 | +static inline void |
|---|
| 65 | +ufshcd_prepare_req_desc_hdr_crypto(struct ufshcd_lrb *lrbp, u32 *dword_0, |
|---|
| 66 | + u32 *dword_1, u32 *dword_3) { } |
|---|
| 67 | + |
|---|
| 68 | +static inline void ufshcd_crypto_clear_prdt(struct ufs_hba *hba, |
|---|
| 69 | + struct ufshcd_lrb *lrbp) { } |
|---|
| 70 | + |
|---|
| 71 | +static inline bool ufshcd_crypto_enable(struct ufs_hba *hba) |
|---|
| 102 | 72 | { |
|---|
| 103 | 73 | return false; |
|---|
| 104 | 74 | } |
|---|
| 105 | 75 | |
|---|
| 106 | | -static inline bool ufshcd_hba_is_crypto_supported(struct ufs_hba *hba) |
|---|
| 107 | | -{ |
|---|
| 108 | | - return false; |
|---|
| 109 | | -} |
|---|
| 110 | | - |
|---|
| 111 | | -static inline bool ufshcd_is_crypto_enabled(struct ufs_hba *hba) |
|---|
| 112 | | -{ |
|---|
| 113 | | - return false; |
|---|
| 114 | | -} |
|---|
| 115 | | - |
|---|
| 116 | | -static inline void ufshcd_crypto_enable(struct ufs_hba *hba) { } |
|---|
| 117 | | - |
|---|
| 118 | | -static inline void ufshcd_crypto_disable(struct ufs_hba *hba) { } |
|---|
| 119 | | - |
|---|
| 120 | | -static inline int ufshcd_hba_init_crypto(struct ufs_hba *hba) |
|---|
| 76 | +static inline int ufshcd_hba_init_crypto_capabilities(struct ufs_hba *hba) |
|---|
| 121 | 77 | { |
|---|
| 122 | 78 | return 0; |
|---|
| 123 | 79 | } |
|---|
| 80 | + |
|---|
| 81 | +static inline void ufshcd_init_crypto(struct ufs_hba *hba) { } |
|---|
| 124 | 82 | |
|---|
| 125 | 83 | static inline void ufshcd_crypto_setup_rq_keyslot_manager(struct ufs_hba *hba, |
|---|
| 126 | 84 | struct request_queue *q) { } |
|---|
| 127 | | - |
|---|
| 128 | | -static inline void ufshcd_crypto_destroy_rq_keyslot_manager(struct ufs_hba *hba, |
|---|
| 129 | | - struct request_queue *q) { } |
|---|
| 130 | | - |
|---|
| 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 | | - |
|---|
| 138 | | -static inline int ufshcd_map_sg_crypto(struct ufs_hba *hba, |
|---|
| 139 | | - struct ufshcd_lrb *lrbp) |
|---|
| 140 | | -{ |
|---|
| 141 | | - return 0; |
|---|
| 142 | | -} |
|---|
| 143 | | - |
|---|
| 144 | | -static inline bool ufshcd_lrbp_crypto_enabled(struct ufshcd_lrb *lrbp) |
|---|
| 145 | | -{ |
|---|
| 146 | | - return false; |
|---|
| 147 | | -} |
|---|
| 148 | | - |
|---|
| 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 | | - |
|---|
| 156 | | -static inline void ufshcd_crypto_debug(struct ufs_hba *hba) { } |
|---|
| 157 | | - |
|---|
| 158 | | -static inline int ufshcd_crypto_suspend(struct ufs_hba *hba, |
|---|
| 159 | | - enum ufs_pm_op pm_op) |
|---|
| 160 | | -{ |
|---|
| 161 | | - return 0; |
|---|
| 162 | | -} |
|---|
| 163 | | - |
|---|
| 164 | | -static inline int ufshcd_crypto_resume(struct ufs_hba *hba, |
|---|
| 165 | | - enum ufs_pm_op pm_op) |
|---|
| 166 | | -{ |
|---|
| 167 | | - return 0; |
|---|
| 168 | | -} |
|---|
| 169 | | - |
|---|
| 170 | | -static inline void ufshcd_crypto_set_vops(struct ufs_hba *hba, |
|---|
| 171 | | - struct ufs_hba_crypto_variant_ops *crypto_vops) { } |
|---|
| 172 | 85 | |
|---|
| 173 | 86 | #endif /* CONFIG_SCSI_UFS_CRYPTO */ |
|---|
| 174 | 87 | |
|---|