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 32/37] scsi: hpsa: use 16-bits defined sense codes
Date: Mon, 31 Aug 2026 11:04:46 +0900 [thread overview]
Message-ID: <20260831020451.585944-33-dlemoal@kernel.org> (raw)
In-Reply-To: <20260831020451.585944-1-dlemoal@kernel.org>
Refactor the hpsa driver to replace all hard-coded additional sense codes
and additional sense code qualifiers with the enum values defined in
include/scsi/scsi_sense.h. This helps with code clarity as the sense codes
being processed are easier to test and self-documented.
The function decode_sense_data() is also modified to take a pointer to a
16-bits sense_code variable in place of the two pointers to the additional
sense code and its code qualifier. The local definitions of ASCs and ASCQs
are deleted too.
No functional change intended, but the function hpsa_volume_offline() was
checking only the addditional sense code qualifier with checking the
additional sense code. This change assumes that the intended additional
sense code to check is ASC_LU_NOT_READY.
Signed-off-by: Damien Le Moal <dlemoal@kernel.org>
---
drivers/scsi/hpsa.c | 69 +++++++++++++++++++++--------------------
drivers/scsi/hpsa_cmd.h | 23 --------------
2 files changed, 35 insertions(+), 57 deletions(-)
diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
index 8edad1830abe..795e8c7592af 100644
--- a/drivers/scsi/hpsa.c
+++ b/drivers/scsi/hpsa.c
@@ -353,14 +353,13 @@ static inline bool hpsa_is_cmd_idle(struct CommandList *c)
/* extract sense key, asc, and ascq from sense data. -1 means invalid. */
static void decode_sense_data(const u8 *sense_data, int sense_data_len,
- u8 *sense_key, u8 *asc, u8 *ascq)
+ u8 *sense_key, u16 *sense_code)
{
struct scsi_sense_hdr sshdr;
bool rc;
*sense_key = -1;
- *asc = -1;
- *ascq = -1;
+ *sense_code = -1;
if (sense_data_len < 1)
return;
@@ -368,15 +367,15 @@ static void decode_sense_data(const u8 *sense_data, int sense_data_len,
rc = scsi_normalize_sense(sense_data, sense_data_len, &sshdr);
if (rc) {
*sense_key = sshdr.sense_key;
- *asc = sshdr.asc;
- *ascq = sshdr.ascq;
+ *sense_code = sshdr.sense_code;
}
}
static int check_for_unit_attention(struct ctlr_info *h,
struct CommandList *c)
{
- u8 sense_key, asc, ascq;
+ u8 sense_key;
+ u16 sense_code;
int sense_len;
if (c->err_info->SenseLen > sizeof(c->err_info->SenseInfo))
@@ -385,34 +384,35 @@ static int check_for_unit_attention(struct ctlr_info *h,
sense_len = c->err_info->SenseLen;
decode_sense_data(c->err_info->SenseInfo, sense_len,
- &sense_key, &asc, &ascq);
- if (sense_key != UNIT_ATTENTION || asc == 0xff)
+ &sense_key, &sense_code);
+ if (sense_key != UNIT_ATTENTION ||
+ scsi_sense_code_asc(sense_code) == 0xff)
return 0;
- switch (asc) {
- case STATE_CHANGED:
+ switch (scsi_sense_code_asc(sense_code)) {
+ case ASC_PARAMETERS_CHANGED:
dev_warn(&h->pdev->dev,
"%s: a state change detected, command retried\n",
h->devname);
break;
- case LUN_FAILED:
+ case ASC_LU_HAS_NOT_SELF_CONFIGURED_YET:
dev_warn(&h->pdev->dev,
"%s: LUN failure detected\n", h->devname);
break;
- case REPORT_LUNS_CHANGED:
+ case ASC_TARGET_OPERATING_CONDITIONS_HAVE_CHANGED:
dev_warn(&h->pdev->dev,
"%s: report LUN data changed\n", h->devname);
/*
- * Note: this REPORT_LUNS_CHANGED condition only occurs on the external
- * target (array) devices.
+ * Note: this ASC_TARGET_OPERATING_CONDITIONS_HAVE_CHANGED condition
+ * only occurs on the external target (array) devices.
*/
break;
- case POWER_OR_RESET:
+ case ASC_POWER_ON_RESET_OR_BUS_DEVICE_RESET_OCCURRED:
dev_warn(&h->pdev->dev,
"%s: a power on or device reset detected\n",
h->devname);
break;
- case UNIT_ATTENTION_CLEARED:
+ case ASC_COMMANDS_CLEARED_BY_ANOTHER_INITIATOR:
dev_warn(&h->pdev->dev,
"%s: unit attention cleared by another initiator\n",
h->devname);
@@ -2562,10 +2562,8 @@ static void complete_scsi_command(struct CommandList *cp)
struct ErrorInfo *ei;
struct hpsa_scsi_dev_t *dev;
struct io_accel2_cmd *c2;
-
u8 sense_key;
- u8 asc; /* additional sense code */
- u8 ascq; /* additional sense code qualifier */
+ u16 sense_code;
unsigned long sense_data_size;
ei = cp->err_info;
@@ -2666,18 +2664,19 @@ static void complete_scsi_command(struct CommandList *cp)
memcpy(cmd->sense_buffer, ei->SenseInfo, sense_data_size);
if (ei->ScsiStatus)
decode_sense_data(ei->SenseInfo, sense_data_size,
- &sense_key, &asc, &ascq);
+ &sense_key, &sense_code);
if (ei->ScsiStatus == SAM_STAT_CHECK_CONDITION) {
switch (sense_key) {
case ABORTED_COMMAND:
cmd->result |= DID_SOFT_ERROR << 16;
break;
case UNIT_ATTENTION:
- if (asc == 0x3F && ascq == 0x0E)
+ if (sense_code ==
+ REPORTED_LUNS_DATA_HAS_CHANGED)
h->drv_req_rescan = 1;
break;
case ILLEGAL_REQUEST:
- if (asc == 0x25 && ascq == 0x00) {
+ if (sense_code == LU_NOT_SUPPORTED) {
dev->removed = 1;
cmd->result = DID_NO_CONNECT << 16;
}
@@ -2693,7 +2692,9 @@ static void complete_scsi_command(struct CommandList *cp)
"Sense: 0x%x, ASC: 0x%x, ASCQ: 0x%x, "
"Returning result: 0x%x\n",
cp, ei->ScsiStatus,
- sense_key, asc, ascq,
+ sense_key,
+ scsi_sense_code_asc(sense_code),
+ scsi_sense_code_ascq(sense_code),
cmd->result);
} else { /* scsi status is zero??? How??? */
dev_warn(&h->pdev->dev, "cp %p SCSI status was 0. "
@@ -2919,7 +2920,8 @@ static void hpsa_scsi_interpret_error(struct ctlr_info *h,
{
const struct ErrorInfo *ei = cp->err_info;
struct device *d = &cp->h->pdev->dev;
- u8 sense_key, asc, ascq;
+ u8 sense_key;
+ u16 sense_code;
int sense_len;
switch (ei->CommandStatus) {
@@ -2928,12 +2930,13 @@ static void hpsa_scsi_interpret_error(struct ctlr_info *h,
sense_len = sizeof(ei->SenseInfo);
else
sense_len = ei->SenseLen;
- decode_sense_data(ei->SenseInfo, sense_len,
- &sense_key, &asc, &ascq);
+ decode_sense_data(ei->SenseInfo, sense_len, &sense_key,
+ &sense_code);
hpsa_print_cmd(h, "SCSI status", cp);
if (ei->ScsiStatus == SAM_STAT_CHECK_CONDITION)
dev_warn(d, "SCSI Status = 02, Sense key = 0x%02x, ASC = 0x%02x, ASCQ = 0x%02x\n",
- sense_key, asc, ascq);
+ sense_key, scsi_sense_code_asc(sense_code),
+ scsi_sense_code_ascq(sense_code));
else
dev_warn(d, "SCSI Status = 0x%02x\n", ei->ScsiStatus);
if (ei->ScsiStatus == 0)
@@ -3868,12 +3871,10 @@ static unsigned char hpsa_volume_offline(struct ctlr_info *h,
{
struct CommandList *c;
unsigned char *sense;
- u8 sense_key, asc, ascq;
+ u8 sense_key;
+ u16 sense_code;
int sense_len;
int rc, ldstat = 0;
-#define ASC_LUN_NOT_READY 0x04
-#define ASCQ_LUN_NOT_READY_FORMAT_IN_PROGRESS 0x04
-#define ASCQ_LUN_NOT_READY_INITIALIZING_CMD_REQ 0x02
c = cmd_alloc(h);
@@ -3889,7 +3890,7 @@ static unsigned char hpsa_volume_offline(struct ctlr_info *h,
sense_len = sizeof(c->err_info->SenseInfo);
else
sense_len = c->err_info->SenseLen;
- decode_sense_data(sense, sense_len, &sense_key, &asc, &ascq);
+ decode_sense_data(sense, sense_len, &sense_key, &sense_code);
cmd_free(h, c);
/* Determine the reason for not ready state */
@@ -3912,8 +3913,8 @@ static unsigned char hpsa_volume_offline(struct ctlr_info *h,
/* If VPD status page isn't available,
* use ASC/ASCQ to determine state
*/
- if ((ascq == ASCQ_LUN_NOT_READY_FORMAT_IN_PROGRESS) ||
- (ascq == ASCQ_LUN_NOT_READY_INITIALIZING_CMD_REQ))
+ if (sense_code == LU_NOT_READY_FORMAT_IN_PROGRESS ||
+ sense_code == LU_NOT_READY_INITIALIZING_COMMAND_REQUIRED)
return ldstat;
break;
default:
diff --git a/drivers/scsi/hpsa_cmd.h b/drivers/scsi/hpsa_cmd.h
index ba6a3aa8d954..0dbfbec37ce2 100644
--- a/drivers/scsi/hpsa_cmd.h
+++ b/drivers/scsi/hpsa_cmd.h
@@ -63,29 +63,6 @@
#define CISS_TMF_WRONG_LUN 0x09
#define CISS_TMF_OVERLAPPED_TAG 0x0a
-/* Unit Attentions ASC's as defined for the MSA2012sa */
-#define POWER_OR_RESET 0x29
-#define STATE_CHANGED 0x2a
-#define UNIT_ATTENTION_CLEARED 0x2f
-#define LUN_FAILED 0x3e
-#define REPORT_LUNS_CHANGED 0x3f
-
-/* Unit Attentions ASCQ's as defined for the MSA2012sa */
-
- /* These ASCQ's defined for ASC = POWER_OR_RESET */
-#define POWER_ON_RESET 0x00
-#define POWER_ON_REBOOT 0x01
-#define SCSI_BUS_RESET 0x02
-#define MSA_TARGET_RESET 0x03
-#define CONTROLLER_FAILOVER 0x04
-#define TRANSCEIVER_SE 0x05
-#define TRANSCEIVER_LVD 0x06
-
- /* These ASCQ's defined for ASC = STATE_CHANGED */
-#define RESERVATION_PREEMPTED 0x03
-#define ASYM_ACCESS_CHANGED 0x06
-#define LUN_CAPACITY_CHANGED 0x09
-
/* transfer direction */
#define XFER_NONE 0x00
#define XFER_WRITE 0x01
--
2.55.0
next prev parent reply other threads:[~2026-08-31 2:05 UTC|newest]
Thread overview: 41+ 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:04 ` [PATCH 05/37] scsi: prepare for using 16-bits defined sense codes Damien Le Moal
2026-08-31 2:04 ` [PATCH 06/37] scsi: use struct scsi_sense_hdr to log sense keys and codes Damien Le Moal
2026-08-31 2:04 ` [PATCH 07/37] scsi: core: use 16-bits defined sense codes Damien Le Moal
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: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: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: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: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: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:04 ` [PATCH 31/37] scsi: scsi_debug: " Damien Le Moal
2026-08-31 2:04 ` Damien Le Moal [this message]
2026-08-31 2:04 ` [PATCH 33/37] scsi: storvsc: " Damien Le Moal
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:04 ` [PATCH 36/37] ata: libata: " Damien Le Moal
2026-09-02 11:29 ` Niklas Cassel
2026-09-02 23:48 ` Damien Le Moal
2026-08-31 2:04 ` [PATCH 37/37] scsi: cleanup scsi_proto.h Damien Le Moal
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-33-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