U-Boot Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Jorge Ramirez-Ortiz <jorge.ramirez@oss.qualcomm.com>
To: jorge.ramirez@oss.qualcomm.com, dlechner@baylibre.com,
	trini@konsulko.com,  jens.wiklander@linaro.org,
	ilias.apalodimas@linaro.org, peng.fan@nxp.com,
	jh80.chung@samsung.com, tanmay.kathpalia@altera.com,
	neil.armstrong@linaro.org, bhupesh.linux@gmail.com,
	n-francis@ti.com, xypron.glpk@gmx.de, s-vadapalli@ti.com,
	michal.simek@amd.com, jbx6244@gmail.com,
	marek.vasut+renesas@mailbox.org, sumit.garg@oss.qualcomm.com,
	jens.wiklander@oss.qualcomm.com
Cc: u-boot@lists.u-boot-project.org
Subject: [PATCH v5 2/6] ufs: surface sense data from ufs_scsi_exec()
Date: Fri, 18 Sep 2026 22:06:34 +0200	[thread overview]
Message-ID: <20260918200641.2286077-3-jorge.ramirez@oss.qualcomm.com> (raw)
In-Reply-To: <20260918200641.2286077-1-jorge.ramirez@oss.qualcomm.com>

On a CHECK CONDITION the UFS device returns SCSI sense data inline in the
RESPONSE UPIU, but ufs_scsi_exec() discarded it and reported every
failure as a bare -EINVAL, leaving callers unable to tell a transient
condition such as a power-on UNIT ATTENTION from a hard error.

Preserve the sense data and SCSI status in the scsi_cmd. No caller
inspects them yet, so behaviour is unchanged.

Signed-off-by: Jorge Ramirez-Ortiz <jorge.ramirez@oss.qualcomm.com>
---
 drivers/ufs/ufs-uclass.c | 25 ++++++++++++++++++++++++-
 1 file changed, 24 insertions(+), 1 deletion(-)

diff --git a/drivers/ufs/ufs-uclass.c b/drivers/ufs/ufs-uclass.c
index 21aed9f97bd..3d96a05281c 100644
--- a/drivers/ufs/ufs-uclass.c
+++ b/drivers/ufs/ufs-uclass.c
@@ -1657,6 +1657,22 @@ static void prepare_prdt_table(struct ufs_hba *hba, struct scsi_cmd *pccb)
 	ufshcd_cache_flush(req_desc, sizeof(*req_desc));
 }
 
+/*
+ * On a CHECK CONDITION the sense data is returned inline in the RESPONSE
+ * UPIU; copy it into the SCSI command so callers can inspect the sense key
+ * (for example to tell a transient UNIT ATTENTION from a hard error).
+ */
+static void ufs_scsi_copy_sense(struct ufs_hba *hba, struct scsi_cmd *pccb)
+{
+	u16 len = be16_to_cpu(hba->ucd_rsp_ptr->sr.sense_data_len);
+
+	if (len > RESPONSE_UPIU_SENSE_DATA_LENGTH)
+		len = RESPONSE_UPIU_SENSE_DATA_LENGTH;
+
+	memcpy(pccb->sense_buf, hba->ucd_rsp_ptr->sr.sense_data, len);
+	pccb->sensedatalen = len;
+}
+
 static int ufs_scsi_exec(struct udevice *scsi_dev, struct scsi_cmd *pccb)
 {
 	struct ufs_hba *hba = dev_get_uclass_priv(scsi_dev->parent);
@@ -1664,6 +1680,9 @@ static int ufs_scsi_exec(struct udevice *scsi_dev, struct scsi_cmd *pccb)
 	int ocs, result = 0;
 	u8 scsi_status;
 
+	pccb->status = 0;
+	pccb->sensedatalen = 0;
+
 	ufshcd_prepare_req_desc_hdr(hba, &upiu_flags, pccb->dma_dir);
 	ufshcd_prepare_utp_scsi_cmd_upiu(hba, pccb, upiu_flags);
 	prepare_prdt_table(hba, pccb);
@@ -1683,8 +1702,12 @@ static int ufs_scsi_exec(struct udevice *scsi_dev, struct scsi_cmd *pccb)
 			result = ufshcd_get_rsp_upiu_result(hba->ucd_rsp_ptr);
 
 			scsi_status = result & MASK_SCSI_STATUS;
-			if (scsi_status)
+			if (scsi_status) {
+				pccb->status = scsi_status;
+				if (scsi_status == S_CHECK_COND)
+					ufs_scsi_copy_sense(hba, pccb);
 				return -EINVAL;
+			}
 
 			break;
 		case UPIU_TRANSACTION_REJECT_UPIU:
-- 
2.54.0


  parent reply	other threads:[~2026-09-18 20:07 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-18 20:06 [PATCH v5 0/6] ufs: rpmb: route OP-TEE RPMB secure storage over UFS Jorge Ramirez-Ortiz
2026-09-18 20:06 ` [PATCH v5 1/6] ufs: decode string descriptors as UTF-16 big-endian Jorge Ramirez-Ortiz
2026-10-14 12:20   ` neil.armstrong
2026-09-18 20:06 ` Jorge Ramirez-Ortiz [this message]
2026-10-02 11:16   ` [PATCH v5 2/6] ufs: surface sense data from ufs_scsi_exec() Ilias Apalodimas
2026-10-13 17:48     ` Jorge Ramirez
2026-10-13 17:51       ` Tom Rini
2026-10-14 12:19     ` neil.armstrong
2026-10-14 12:20   ` neil.armstrong
2026-09-18 20:06 ` [PATCH v5 3/6] ufs: add RPMB transport over SCSI SECURITY PROTOCOL Jorge Ramirez-Ortiz
2026-09-29  3:29   ` Stanley Jhu
2026-10-14 12:22     ` neil.armstrong
2026-09-18 20:06 ` [PATCH v5 4/6] ufs: derive the per-region RPMB CID and size for OP-TEE Jorge Ramirez-Ortiz
2026-09-18 20:06 ` [PATCH v5 5/6] optee: rename rpmb.c to rpmb_emmc.c Jorge Ramirez-Ortiz
2026-10-02 11:14   ` Ilias Apalodimas
2026-09-18 20:06 ` [PATCH v5 6/6] optee: implement the RPMB subsystem interface for UFS Jorge Ramirez-Ortiz
2026-10-02 11:14   ` Ilias Apalodimas
2026-09-18 20:15 ` [PATCH v5 0/6] ufs: rpmb: route OP-TEE RPMB secure storage over UFS Jorge Ramirez
2026-09-24 17:50   ` Macpaul Lin (林智斌)
2026-09-25  9:59     ` Ilias Apalodimas
2026-09-26 20:41       ` Jorge Ramirez
2026-09-26 21:08         ` Jorge Ramirez
2026-09-28  7:32           ` Jens Wiklander
2026-09-28 10:02           ` Ilias Apalodimas

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=20260918200641.2286077-3-jorge.ramirez@oss.qualcomm.com \
    --to=jorge.ramirez@oss.qualcomm.com \
    --cc=bhupesh.linux@gmail.com \
    --cc=dlechner@baylibre.com \
    --cc=ilias.apalodimas@linaro.org \
    --cc=jbx6244@gmail.com \
    --cc=jens.wiklander@linaro.org \
    --cc=jens.wiklander@oss.qualcomm.com \
    --cc=jh80.chung@samsung.com \
    --cc=marek.vasut+renesas@mailbox.org \
    --cc=michal.simek@amd.com \
    --cc=n-francis@ti.com \
    --cc=neil.armstrong@linaro.org \
    --cc=peng.fan@nxp.com \
    --cc=s-vadapalli@ti.com \
    --cc=sumit.garg@oss.qualcomm.com \
    --cc=tanmay.kathpalia@altera.com \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.u-boot-project.org \
    --cc=xypron.glpk@gmx.de \
    /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