Linux SCSI subsystem development
 help / color / mirror / Atom feed
From: Damien Le Moal <dlemoal@kernel.org>
To: "Martin K . Petersen" <martin.petersen@oracle.com>,
	"James E . J . Bottomley" <James.Bottomley@HansenPartnership.com>,
	linux-scsi@vger.kernel.org, linux-ide@vger.kernel.org,
	Niklas Cassel <cassel@kernel.org>,
	linux-usb@vger.kernel.org, Alan Stern <stern@rowland.harvard.edu>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Subject: [PATCH 06/37] scsi: use struct scsi_sense_hdr to log sense keys and codes
Date: Mon, 31 Aug 2026 11:04:20 +0900	[thread overview]
Message-ID: <20260831020451.585944-7-dlemoal@kernel.org> (raw)
In-Reply-To: <20260831020451.585944-1-dlemoal@kernel.org>

Instead of passing the sense key, additional sense code and additional
sense code qualifier as separate parameters, change the functions
scsi_extd_sense_format(), scsi_format_extd_sense(), and
usb_stor_show_sense() to take a pointer to a struct scsi_sense_hdr to
access the sense key and sense code with a single argument.

No functional change intended.

Signed-off-by: Damien Le Moal <dlemoal@kernel.org>
---
 drivers/scsi/constants.c        | 11 +++++------
 drivers/scsi/scsi_logging.c     | 22 ++++++++++++----------
 drivers/usb/storage/debug.c     | 12 +++++-------
 drivers/usb/storage/debug.h     |  4 ++--
 drivers/usb/storage/transport.c |  2 +-
 include/scsi/scsi_dbg.h         |  6 +++---
 6 files changed, 28 insertions(+), 29 deletions(-)

diff --git a/drivers/scsi/constants.c b/drivers/scsi/constants.c
index 4b97f574fe8c..57b51c4529c3 100644
--- a/drivers/scsi/constants.c
+++ b/drivers/scsi/constants.c
@@ -377,22 +377,21 @@ EXPORT_SYMBOL(scsi_sense_key_string);
  * This string may contain a "%x" and should be printed with ascq as arg.
  */
 const char *
-scsi_extd_sense_format(unsigned char asc, unsigned char ascq, const char **fmt)
+scsi_extd_sense_format(const struct scsi_sense_hdr *sshdr, const char **fmt)
 {
-	u16 code = scsi_sense_code(asc, ascq);
 	unsigned offset = 0;
 	int i;
 
 	*fmt = NULL;
 	for (i = 0; i < ARRAY_SIZE(additional); i++) {
-		if (additional[i].code == code)
+		if (additional[i].code == sshdr->sense_code)
 			return additional_text + offset;
 		offset += additional[i].size;
 	}
 	for (i = 0; additional2[i].fmt; i++) {
-		if (additional2[i].asc == asc &&
-		    ascq >= additional2[i].ascq_min &&
-		    ascq <= additional2[i].ascq_max) {
+		if (additional2[i].asc == scsi_sense_asc(sshdr) &&
+		    scsi_sense_ascq(sshdr) >= additional2[i].ascq_min &&
+		    scsi_sense_ascq(sshdr) <= additional2[i].ascq_max) {
 			*fmt = additional2[i].fmt;
 			return additional2[i].str;
 		}
diff --git a/drivers/scsi/scsi_logging.c b/drivers/scsi/scsi_logging.c
index 3cd0d3074085..0a9a2f7c1966 100644
--- a/drivers/scsi/scsi_logging.c
+++ b/drivers/scsi/scsi_logging.c
@@ -238,29 +238,32 @@ EXPORT_SYMBOL(scsi_print_command);
 
 static size_t
 scsi_format_extd_sense(char *buffer, size_t buf_len,
-		       unsigned char asc, unsigned char ascq)
+		       const struct scsi_sense_hdr *sshdr)
 {
 	size_t off = 0;
 	const char *extd_sense_fmt = NULL;
-	const char *extd_sense_str = scsi_extd_sense_format(asc, ascq,
-							    &extd_sense_fmt);
+	const char *extd_sense_str =
+		scsi_extd_sense_format(sshdr, &extd_sense_fmt);
 
 	if (extd_sense_str) {
 		off = scnprintf(buffer, buf_len, "Add. Sense: %s",
 				extd_sense_str);
 		if (extd_sense_fmt)
 			off += scnprintf(buffer + off, buf_len - off,
-					 "(%s%x)", extd_sense_fmt, ascq);
+					 "(%s%x)", extd_sense_fmt,
+					 scsi_sense_ascq(sshdr));
 	} else {
-		if (asc >= 0x80)
+		if (scsi_sense_asc(sshdr) >= 0x80)
 			off = scnprintf(buffer, buf_len, "<<vendor>>");
 		off += scnprintf(buffer + off, buf_len - off,
-				 "ASC=0x%x ", asc);
-		if (ascq >= 0x80)
+				 "ASC=0x%x ",
+				 scsi_sense_asc(sshdr));
+		if (scsi_sense_ascq(sshdr) >= 0x80)
 			off += scnprintf(buffer + off, buf_len - off,
 					 "<<vendor>>");
 		off += scnprintf(buffer + off, buf_len - off,
-				 "ASCQ=0x%x ", ascq);
+				 "ASCQ=0x%x ",
+				 scsi_sense_ascq(sshdr));
 	}
 	return off;
 }
@@ -333,8 +336,7 @@ scsi_log_print_sense_hdr(const struct scsi_device *sdev, const char *name,
 	if (!logbuf)
 		return;
 	off = sdev_format_header(logbuf, logbuf_len, name, tag);
-	off += scsi_format_extd_sense(logbuf + off, logbuf_len - off,
-				      sshdr->asc, sshdr->ascq);
+	off += scsi_format_extd_sense(logbuf + off, logbuf_len - off, sshdr);
 	dev_printk(KERN_INFO, &sdev->sdev_gendev, "%s", logbuf);
 	scsi_log_release_buffer(logbuf);
 }
diff --git a/drivers/usb/storage/debug.c b/drivers/usb/storage/debug.c
index dda610f689b7..4cc5a019382a 100644
--- a/drivers/usb/storage/debug.c
+++ b/drivers/usb/storage/debug.c
@@ -140,15 +140,12 @@ void usb_stor_show_command(const struct us_data *us, struct scsi_cmnd *srb)
 		     (const unsigned char *)srb->cmnd);
 }
 
-void usb_stor_show_sense(const struct us_data *us,
-			 unsigned char key,
-			 unsigned char asc,
-			 unsigned char ascq)
+void usb_stor_show_sense(const struct us_data *us, struct scsi_sense_hdr *sshdr)
 {
 	const char *what, *keystr, *fmt;
 
-	keystr = scsi_sense_key_string(key);
-	what = scsi_extd_sense_format(asc, ascq, &fmt);
+	keystr = scsi_sense_key_string(sshdr->sense_key);
+	what = scsi_extd_sense_format(sshdr, &fmt);
 
 	if (keystr == NULL)
 		keystr = "(Unknown Key)";
@@ -156,7 +153,8 @@ void usb_stor_show_sense(const struct us_data *us,
 		what = "(unknown ASC/ASCQ)";
 
 	if (fmt)
-		usb_stor_dbg(us, "%s: %s (%s%x)\n", keystr, what, fmt, ascq);
+		usb_stor_dbg(us, "%s: %s (%s%x)\n", keystr, what, fmt,
+			     scsi_sense_ascq(sshdr));
 	else
 		usb_stor_dbg(us, "%s: %s\n", keystr, what);
 }
diff --git a/drivers/usb/storage/debug.h b/drivers/usb/storage/debug.h
index a6505ceb6693..616e518eeb21 100644
--- a/drivers/usb/storage/debug.h
+++ b/drivers/usb/storage/debug.h
@@ -31,8 +31,8 @@
 
 #ifdef CONFIG_USB_STORAGE_DEBUG
 void usb_stor_show_command(const struct us_data *us, struct scsi_cmnd *srb);
-void usb_stor_show_sense(const struct us_data *us, unsigned char key,
-			 unsigned char asc, unsigned char ascq);
+void usb_stor_show_sense(const struct us_data *us,
+			 struct scsi_sense_hdr *sshdr);
 __printf(2, 3) void usb_stor_dbg(const struct us_data *us,
 				 const char *fmt, ...);
 
diff --git a/drivers/usb/storage/transport.c b/drivers/usb/storage/transport.c
index 9a4bf86e7b6a..8e9359501d88 100644
--- a/drivers/usb/storage/transport.c
+++ b/drivers/usb/storage/transport.c
@@ -805,7 +805,7 @@ void usb_stor_invoke_transport(struct scsi_cmnd *srb, struct us_data *us)
 			     sshdr.response_code, sshdr.sense_key,
 			     sshdr.asc, sshdr.ascq);
 #ifdef CONFIG_USB_STORAGE_DEBUG
-		usb_stor_show_sense(us, sshdr.sense_key, sshdr.asc, sshdr.ascq);
+		usb_stor_show_sense(us, &sshdr);
 #endif
 
 		/* set the result so the higher layers expect this data */
diff --git a/include/scsi/scsi_dbg.h b/include/scsi/scsi_dbg.h
index efcdc78530d5..f21a5e3caca9 100644
--- a/include/scsi/scsi_dbg.h
+++ b/include/scsi/scsi_dbg.h
@@ -20,8 +20,8 @@ extern void scsi_print_result(struct scsi_cmnd *, const char *, int);
 #ifdef CONFIG_SCSI_CONSTANTS
 extern bool scsi_opcode_sa_name(int, int, const char **, const char **);
 extern const char *scsi_sense_key_string(unsigned char);
-extern const char *scsi_extd_sense_format(unsigned char, unsigned char,
-					  const char **);
+extern const char *scsi_extd_sense_format(const struct scsi_sense_hdr *sshdr,
+					  const char **fmt);
 extern const char *scsi_mlreturn_string(int);
 extern const char *scsi_hostbyte_string(int);
 #else
@@ -57,7 +57,7 @@ scsi_sense_key_string(unsigned char key)
 }
 
 static inline const char *
-scsi_extd_sense_format(unsigned char asc, unsigned char ascq, const char **fmt)
+scsi_extd_sense_format(const struct scsi_sense_hdr *sshdr, const char **fmt)
 {
 	*fmt = NULL;
 	return NULL;
-- 
2.55.0


  parent reply	other threads:[~2026-08-31  2:05 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-31  2:04 [PATCH 00/37] Use defined 16-bits ASC/ASCQ combinations Damien Le Moal
2026-08-31  2:04 ` [PATCH 01/37] scsi: define all additional sense codes and their qualifiers Damien Le Moal
2026-08-31  2:04 ` [PATCH 02/37] scsi: constants: use defined sense codes Damien Le Moal
2026-08-31  2:04 ` [PATCH 03/37] scsi: constants: rename internal struct field names Damien Le Moal
2026-08-31  2:04 ` [PATCH 04/37] scsi: rename sense field of struct scsi_failure Damien Le Moal
2026-08-31  2:17   ` sashiko-bot
2026-08-31  2:04 ` [PATCH 05/37] scsi: prepare for using 16-bits defined sense codes Damien Le Moal
2026-08-31  2:04 ` Damien Le Moal [this message]
2026-08-31  2:04 ` [PATCH 07/37] scsi: core: use " Damien Le Moal
2026-08-31  2:18   ` sashiko-bot
2026-08-31  2:04 ` [PATCH 08/37] scsi: sd: " Damien Le Moal
2026-08-31  2:04 ` [PATCH 09/37] scsi: sr: " Damien Le Moal
2026-08-31  2:04 ` [PATCH 10/37] scsi: ses: " Damien Le Moal
2026-08-31  2:04 ` [PATCH 11/37] scsi: ch: " Damien Le Moal
2026-08-31  2:04 ` [PATCH 12/37] scsi: st: " Damien Le Moal
2026-08-31  2:19   ` sashiko-bot
2026-08-31  2:04 ` [PATCH 13/37] scsi: device_handlers: hp_sw: " Damien Le Moal
2026-08-31  2:04 ` [PATCH 14/37] scsi: device_handlers: rdac: " Damien Le Moal
2026-08-31  2:04 ` [PATCH 15/37] scsi: device_handlers: emc: " Damien Le Moal
2026-08-31  2:04 ` [PATCH 16/37] scsi: device_handlers: alua: " Damien Le Moal
2026-08-31  2:04 ` [PATCH 17/37] scsi: mpt3sas: " Damien Le Moal
2026-08-31  2:19   ` sashiko-bot
2026-08-31  2:04 ` [PATCH 18/37] scsi: mpi3mr: " Damien Le Moal
2026-08-31  2:04 ` [PATCH 19/37] scsi: 3w-xxxx: " Damien Le Moal
2026-08-31  2:04 ` [PATCH 20/37] scsi: leapraid: " Damien Le Moal
2026-08-31  2:18   ` sashiko-bot
2026-08-31  2:04 ` [PATCH 21/37] scsi: megaraid: " Damien Le Moal
2026-08-31  2:04 ` [PATCH 22/37] scsi: myrX: " Damien Le Moal
2026-08-31  2:30   ` sashiko-bot
2026-08-31  2:04 ` [PATCH 23/37] scsi: smartpqi: " Damien Le Moal
2026-08-31  2:04 ` [PATCH 24/37] scsi: qla2xxx: " Damien Le Moal
2026-08-31  2:04 ` [PATCH 25/37] scsi: ps3rom: " Damien Le Moal
2026-08-31  2:04 ` [PATCH 26/37] scsi: lpfc: " Damien Le Moal
2026-08-31  2:04 ` [PATCH 27/37] scsi: stex: " Damien Le Moal
2026-08-31  2:04 ` [PATCH 28/37] scsi: mvumi: " Damien Le Moal
2026-08-31  2:24   ` sashiko-bot
2026-08-31  2:04 ` [PATCH 29/37] scsi: libiscsi: " Damien Le Moal
2026-08-31  2:04 ` [PATCH 30/37] scsi: ibmvscsi_tgt: " Damien Le Moal
2026-08-31  2:27   ` sashiko-bot
2026-08-31  2:04 ` [PATCH 31/37] scsi: scsi_debug: " Damien Le Moal
2026-08-31  2:04 ` [PATCH 32/37] scsi: hpsa: " Damien Le Moal
2026-08-31  2:04 ` [PATCH 33/37] scsi: storvsc: " Damien Le Moal
2026-08-31  2:27   ` sashiko-bot
2026-08-31  2:04 ` [PATCH 34/37] usb: storage: " Damien Le Moal
2026-08-31  2:04 ` [PATCH 35/37] cdrom: " Damien Le Moal
2026-08-31  2:29   ` sashiko-bot
2026-08-31  2:04 ` [PATCH 36/37] ata: libata: " Damien Le Moal
2026-09-02 11:29   ` Niklas Cassel
2026-08-31  2:04 ` [PATCH 37/37] scsi: cleanup scsi_proto.h Damien Le Moal
2026-08-31  2:31   ` sashiko-bot
2026-08-31  2:36 ` [PATCH 00/37] Use defined 16-bits ASC/ASCQ combinations Damien Le Moal

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=20260831020451.585944-7-dlemoal@kernel.org \
    --to=dlemoal@kernel.org \
    --cc=James.Bottomley@HansenPartnership.com \
    --cc=cassel@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-ide@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=stern@rowland.harvard.edu \
    /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