Satya Tangirala | 4bac110 | 2019-10-24 14:44:27 -0700 | [diff] [blame] | 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 | |
Satya Tangirala | 4bac110 | 2019-10-24 14:44:27 -0700 | [diff] [blame] | 9 | #ifdef CONFIG_SCSI_UFS_CRYPTO |
Satya Tangirala | ecdebfe | 2019-05-08 03:44:29 -0700 | [diff] [blame] | 10 | #include "ufshcd.h" |
Satya Tangirala | 4bac110 | 2019-10-24 14:44:27 -0700 | [diff] [blame] | 11 | #include "ufshci.h" |
| 12 | |
Eric Biggers | 27b2ed4 | 2020-07-14 09:31:24 -0700 | [diff] [blame] | 13 | static inline void ufshcd_prepare_lrbp_crypto(struct request *rq, |
Eric Biggers | e12d127 | 2020-07-14 09:27:54 -0700 | [diff] [blame] | 14 | struct ufshcd_lrb *lrbp) |
Satya Tangirala | cfd7e6c | 2019-12-17 14:26:29 -0800 | [diff] [blame] | 15 | { |
Eric Biggers | 27b2ed4 | 2020-07-14 09:31:24 -0700 | [diff] [blame] | 16 | if (!rq || !rq->crypt_keyslot) { |
Satya Tangirala | c2b86b7 | 2020-06-16 14:33:37 -0700 | [diff] [blame] | 17 | lrbp->crypto_key_slot = -1; |
Eric Biggers | 27b2ed4 | 2020-07-14 09:31:24 -0700 | [diff] [blame] | 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]; |
| 23 | } |
| 24 | |
| 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) |
| 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); |
Satya Tangirala | c2b86b7 | 2020-06-16 14:33:37 -0700 | [diff] [blame] | 34 | } |
Satya Tangirala | cfd7e6c | 2019-12-17 14:26:29 -0800 | [diff] [blame] | 35 | } |
Satya Tangirala | 4bac110 | 2019-10-24 14:44:27 -0700 | [diff] [blame] | 36 | |
Eric Biggers | 4ad2fd5 | 2020-08-22 10:47:34 -0700 | [diff] [blame] | 37 | static inline void ufshcd_crypto_clear_prdt(struct ufs_hba *hba, |
| 38 | struct ufshcd_lrb *lrbp) |
| 39 | { |
| 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)); |
| 48 | } |
| 49 | |
Satya Tangirala | c2b86b7 | 2020-06-16 14:33:37 -0700 | [diff] [blame] | 50 | bool ufshcd_crypto_enable(struct ufs_hba *hba); |
Satya Tangirala | 4bac110 | 2019-10-24 14:44:27 -0700 | [diff] [blame] | 51 | |
Eric Biggers | 27b2ed4 | 2020-07-14 09:31:24 -0700 | [diff] [blame] | 52 | int ufshcd_hba_init_crypto_capabilities(struct ufs_hba *hba); |
| 53 | |
| 54 | void ufshcd_init_crypto(struct ufs_hba *hba); |
Satya Tangirala | 4bac110 | 2019-10-24 14:44:27 -0700 | [diff] [blame] | 55 | |
| 56 | void ufshcd_crypto_setup_rq_keyslot_manager(struct ufs_hba *hba, |
| 57 | struct request_queue *q); |
| 58 | |
Satya Tangirala | 4bac110 | 2019-10-24 14:44:27 -0700 | [diff] [blame] | 59 | #else /* CONFIG_SCSI_UFS_CRYPTO */ |
| 60 | |
Eric Biggers | 27b2ed4 | 2020-07-14 09:31:24 -0700 | [diff] [blame] | 61 | static inline void ufshcd_prepare_lrbp_crypto(struct request *rq, |
Satya Tangirala | c2b86b7 | 2020-06-16 14:33:37 -0700 | [diff] [blame] | 62 | struct ufshcd_lrb *lrbp) { } |
| 63 | |
Eric Biggers | 27b2ed4 | 2020-07-14 09:31:24 -0700 | [diff] [blame] | 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 | |
Eric Biggers | 4ad2fd5 | 2020-08-22 10:47:34 -0700 | [diff] [blame] | 68 | static inline void ufshcd_crypto_clear_prdt(struct ufs_hba *hba, |
| 69 | struct ufshcd_lrb *lrbp) { } |
| 70 | |
Satya Tangirala | c2b86b7 | 2020-06-16 14:33:37 -0700 | [diff] [blame] | 71 | static inline bool ufshcd_crypto_enable(struct ufs_hba *hba) |
Satya Tangirala | 4bac110 | 2019-10-24 14:44:27 -0700 | [diff] [blame] | 72 | { |
| 73 | return false; |
| 74 | } |
| 75 | |
Eric Biggers | 27b2ed4 | 2020-07-14 09:31:24 -0700 | [diff] [blame] | 76 | static inline int ufshcd_hba_init_crypto_capabilities(struct ufs_hba *hba) |
Satya Tangirala | 4bac110 | 2019-10-24 14:44:27 -0700 | [diff] [blame] | 77 | { |
| 78 | return 0; |
| 79 | } |
| 80 | |
Eric Biggers | 27b2ed4 | 2020-07-14 09:31:24 -0700 | [diff] [blame] | 81 | static inline void ufshcd_init_crypto(struct ufs_hba *hba) { } |
| 82 | |
Satya Tangirala | ecdebfe | 2019-05-08 03:44:29 -0700 | [diff] [blame] | 83 | static inline void ufshcd_crypto_setup_rq_keyslot_manager(struct ufs_hba *hba, |
| 84 | struct request_queue *q) { } |
Satya Tangirala | 4bac110 | 2019-10-24 14:44:27 -0700 | [diff] [blame] | 85 | |
Satya Tangirala | 4bac110 | 2019-10-24 14:44:27 -0700 | [diff] [blame] | 86 | #endif /* CONFIG_SCSI_UFS_CRYPTO */ |
| 87 | |
| 88 | #endif /* _UFSHCD_CRYPTO_H */ |