Skip to content

Commit 8ecea3d

Browse files
ebiggersmartinkpetersen
authored andcommitted
scsi: ufs: core: Add fill_crypto_prdt variant op
Add a variant op to allow host drivers to initialize nonstandard crypto-related fields in the PRDT. This is needed to support inline encryption on the "Exynos" UFS controller. Note that this will be used together with the support for overriding the PRDT entry size that was already added by commit ada1e65 ("scsi: ufs: core: Allow UFS host drivers to override the sg entry size"). Reviewed-by: Bart Van Assche <[email protected]> Reviewed-by: Peter Griffin <[email protected]> Signed-off-by: Eric Biggers <[email protected]> Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Alim Akhtar <[email protected]> Signed-off-by: Martin K. Petersen <[email protected]>
1 parent e95881e commit 8ecea3d

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

drivers/ufs/core/ufshcd-crypto.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,19 @@ ufshcd_prepare_req_desc_hdr_crypto(struct ufshcd_lrb *lrbp,
3737
h->dunu = cpu_to_le32(upper_32_bits(lrbp->data_unit_num));
3838
}
3939

40+
static inline int ufshcd_crypto_fill_prdt(struct ufs_hba *hba,
41+
struct ufshcd_lrb *lrbp)
42+
{
43+
struct scsi_cmnd *cmd = lrbp->cmd;
44+
const struct bio_crypt_ctx *crypt_ctx = scsi_cmd_to_rq(cmd)->crypt_ctx;
45+
46+
if (crypt_ctx && hba->vops && hba->vops->fill_crypto_prdt)
47+
return hba->vops->fill_crypto_prdt(hba, crypt_ctx,
48+
lrbp->ucd_prdt_ptr,
49+
scsi_sg_count(cmd));
50+
return 0;
51+
}
52+
4053
bool ufshcd_crypto_enable(struct ufs_hba *hba);
4154

4255
int ufshcd_hba_init_crypto_capabilities(struct ufs_hba *hba);
@@ -54,6 +67,12 @@ static inline void
5467
ufshcd_prepare_req_desc_hdr_crypto(struct ufshcd_lrb *lrbp,
5568
struct request_desc_header *h) { }
5669

70+
static inline int ufshcd_crypto_fill_prdt(struct ufs_hba *hba,
71+
struct ufshcd_lrb *lrbp)
72+
{
73+
return 0;
74+
}
75+
5776
static inline bool ufshcd_crypto_enable(struct ufs_hba *hba)
5877
{
5978
return false;

drivers/ufs/core/ufshcd.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2641,7 +2641,7 @@ static int ufshcd_map_sg(struct ufs_hba *hba, struct ufshcd_lrb *lrbp)
26412641

26422642
ufshcd_sgl_to_prdt(hba, lrbp, sg_segments, scsi_sglist(cmd));
26432643

2644-
return 0;
2644+
return ufshcd_crypto_fill_prdt(hba, lrbp);
26452645
}
26462646

26472647
/**

include/ufs/ufshcd.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@ struct ufs_pwr_mode_info {
322322
* @device_reset: called to issue a reset pulse on the UFS device
323323
* @config_scaling_param: called to configure clock scaling parameters
324324
* @program_key: program or evict an inline encryption key
325+
* @fill_crypto_prdt: initialize crypto-related fields in the PRDT
325326
* @event_notify: called to notify important events
326327
* @reinit_notify: called to notify reinit of UFSHCD during max gear switch
327328
* @mcq_config_resource: called to configure MCQ platform resources
@@ -367,6 +368,9 @@ struct ufs_hba_variant_ops {
367368
struct devfreq_simple_ondemand_data *data);
368369
int (*program_key)(struct ufs_hba *hba,
369370
const union ufs_crypto_cfg_entry *cfg, int slot);
371+
int (*fill_crypto_prdt)(struct ufs_hba *hba,
372+
const struct bio_crypt_ctx *crypt_ctx,
373+
void *prdt, unsigned int num_segments);
370374
void (*event_notify)(struct ufs_hba *hba,
371375
enum ufs_event_type evt, void *data);
372376
void (*reinit_notify)(struct ufs_hba *);

0 commit comments

Comments
 (0)