public inbox for linux-scsi@vger.kernel.org
 help / color / mirror / Atom feed
From: Eric Biggers <ebiggers@kernel.org>
To: Satya Tangirala <satyat@google.com>
Cc: linux-scsi@vger.kernel.org,
	Barani Muthukumaran <bmuthuku@qti.qualcomm.com>,
	Kuohong Wang <kuohong.wang@mediatek.com>,
	Kim Boojin <boojin.kim@samsung.com>,
	Stanley Chu <stanley.chu@mediatek.com>
Subject: Re: [PATCH v3 3/3] scsi: ufs: Add inline encryption support to UFS
Date: Mon, 6 Jul 2020 12:42:13 -0700	[thread overview]
Message-ID: <20200706194213.GB833@sol.localdomain> (raw)
In-Reply-To: <20200706191016.2012191-4-satyat@google.com>

On Mon, Jul 06, 2020 at 07:10:16PM +0000, Satya Tangirala wrote:
> +/**
> + * ufshcd_init_crypto - Initialize crypto hardware
> + * @hba: Per adapter instance
> + */
> +void ufshcd_init_crypto(struct ufs_hba *hba)
> +{
> +	int slot = 0;
> +
> +	if (!(hba->caps & UFSHCD_CAP_CRYPTO))
> +		return;
> +
> +	/* Clear all keyslots - the number of keyslots is (CFGC + 1) */
> +	for (slot = 0; slot < hba->crypto_capabilities.config_count + 1; slot++)
> +		ufshcd_clear_keyslot(hba, slot);
> +}

This should just use 'int slot;'.  No need to initialize to 0.

> diff --git a/drivers/scsi/ufs/ufshcd-crypto.h b/drivers/scsi/ufs/ufshcd-crypto.h
> index 22677619de59..2512aef03f76 100644
> --- a/drivers/scsi/ufs/ufshcd-crypto.h
> +++ b/drivers/scsi/ufs/ufshcd-crypto.h
> @@ -10,9 +10,36 @@
>  #include "ufshcd.h"
>  #include "ufshci.h"
>  
> +static inline void ufshcd_prepare_lrbp_crypto(struct ufs_hba *hba,
> +					      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];
> +}

This function doesn't use the 'hba' argument, so it should be removed.

> +
> +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);
> +	}
> +}
> +
>  bool ufshcd_crypto_enable(struct ufs_hba *hba);
>  
> -int ufshcd_hba_init_crypto(struct ufs_hba *hba);
> +void ufshcd_init_crypto(struct ufs_hba *hba);
> +
> +int ufshcd_hba_init_crypto_capabilities(struct ufs_hba *hba);

The .c file defines ufshcd_hba_init_crypto_capabilities() before
ufshcd_init_crypto().  It would be nice to put the declarations in the same
order.

> @@ -2554,6 +2577,7 @@ static int ufshcd_compose_dev_cmd(struct ufs_hba *hba,
>  	lrbp->task_tag = tag;
>  	lrbp->lun = 0; /* device management cmd is not specific to any LUN */
>  	lrbp->intr_cmd = true; /* No interrupt aggregation */
> +	ufshcd_prepare_lrbp_crypto(hba, NULL, lrbp);
>  	hba->dev_cmd.type = cmd_type;
>  
>  	return ufshcd_comp_devman_upiu(hba, lrbp);
> @@ -4650,6 +4674,8 @@ static int ufshcd_slave_configure(struct scsi_device *sdev)
>  	if (ufshcd_is_rpm_autosuspend_allowed(hba))
>  		sdev->rpm_autosuspend = 1;
>  
> +	ufshcd_crypto_setup_rq_keyslot_manager(hba, q);
> +
>  	return 0;
>  }
>  
> @@ -6115,6 +6141,9 @@ static int ufshcd_issue_devman_upiu_cmd(struct ufs_hba *hba,
>  	lrbp->task_tag = tag;
>  	lrbp->lun = 0;
>  	lrbp->intr_cmd = true;
> +#ifdef CONFIG_SCSI_UFS_CRYPTO
> +	lrbp->crypto_key_slot = -1; /* No crypto operations */
> +#endif

This should use ufshcd_prepare_lrbp_crypto(hba, NULL, lrbp),
like ufshcd_compose_dev_cmd() does.

- Eric

      parent reply	other threads:[~2020-07-06 19:42 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-06 19:10 [PATCH v3 0/3] Inline Encryption Support for UFS Satya Tangirala
2020-07-06 19:10 ` [PATCH v3 1/3] scsi: ufs: UFS driver v2.1 spec crypto additions Satya Tangirala
2020-07-06 19:10 ` [PATCH v3 2/3] scsi: ufs: UFS crypto API Satya Tangirala
2020-07-06 19:10 ` [PATCH v3 3/3] scsi: ufs: Add inline encryption support to UFS Satya Tangirala
2020-07-06 19:29   ` Eric Biggers
2020-07-06 19:42   ` Eric Biggers [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200706194213.GB833@sol.localdomain \
    --to=ebiggers@kernel.org \
    --cc=bmuthuku@qti.qualcomm.com \
    --cc=boojin.kim@samsung.com \
    --cc=kuohong.wang@mediatek.com \
    --cc=linux-scsi@vger.kernel.org \
    --cc=satyat@google.com \
    --cc=stanley.chu@mediatek.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox