public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: John Garry <john.garry@huawei.com>
To: <jejb@linux.ibm.com>, <martin.petersen@oracle.com>,
	<artur.paszkiewicz@intel.com>, <jinpu.wang@cloud.ionos.com>,
	<chenxiang66@hisilicon.com>, <damien.lemoal@opensource.wdc.com>,
	<hch@lst.de>
Cc: <Ajish.Koshy@microchip.com>, <yanaijie@huawei.com>,
	<linux-doc@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	<linux-scsi@vger.kernel.org>, <linuxarm@huawei.com>,
	<liuqi115@huawei.com>, <Viswas.G@microchip.com>,
	John Garry <john.garry@huawei.com>
Subject: [PATCH v2 02/18] scsi: libsas: Use enum for response frame DATAPRES field
Date: Thu, 17 Feb 2022 23:42:30 +0800	[thread overview]
Message-ID: <1645112566-115804-3-git-send-email-john.garry@huawei.com> (raw)
In-Reply-To: <1645112566-115804-1-git-send-email-john.garry@huawei.com>

As defined in table 126 of the SAS spec 1.1, use an enum for the DATAPRES
field, which makes reading the code easier.

Also change sas_ssp_task_response() to use a switch statement, which is
more suitable (than if-else), as suggested by Christoph.

Suggested-by: Xiang Chen <chenxiang66@hisilicon.com>
Signed-off-by: John Garry <john.garry@huawei.com>
Reviewed-by: Jack Wang <jinpu.wang@ionos.com>
Tested-by: Yihang Li <liyihang6@hisilicon.com>
---
 drivers/scsi/aic94xx/aic94xx_tmf.c |  2 +-
 drivers/scsi/isci/request.c        |  7 ++++---
 drivers/scsi/libsas/sas_task.c     | 14 +++++++++-----
 drivers/scsi/mvsas/mv_sas.c        |  2 +-
 include/scsi/sas.h                 |  7 +++++++
 5 files changed, 22 insertions(+), 10 deletions(-)

diff --git a/drivers/scsi/aic94xx/aic94xx_tmf.c b/drivers/scsi/aic94xx/aic94xx_tmf.c
index 0eb6e206a2b4..2ba91eaaf0ee 100644
--- a/drivers/scsi/aic94xx/aic94xx_tmf.c
+++ b/drivers/scsi/aic94xx/aic94xx_tmf.c
@@ -287,7 +287,7 @@ static int asd_get_tmf_resp_tasklet(struct asd_ascb *ascb,
 	fh = edb->vaddr + 16;
 	ru = edb->vaddr + 16 + sizeof(*fh);
 	res = ru->status;
-	if (ru->datapres == 1)	  /* Response data present */
+	if (ru->datapres == SAS_DATAPRES_RESPONSE_DATA)
 		res = ru->resp_data[3];
 #if 0
 	ascb->tag = fh->tag;
diff --git a/drivers/scsi/isci/request.c b/drivers/scsi/isci/request.c
index 92394884fbeb..ac17e3a35d2c 100644
--- a/drivers/scsi/isci/request.c
+++ b/drivers/scsi/isci/request.c
@@ -1047,7 +1047,8 @@ request_started_state_tc_event(struct isci_request *ireq,
 		resp_iu = &ireq->ssp.rsp;
 		datapres = resp_iu->datapres;
 
-		if (datapres == 1 || datapres == 2) {
+		if (datapres == SAS_DATAPRES_RESPONSE_DATA ||
+		    datapres == SAS_DATAPRES_SENSE_DATA) {
 			ireq->scu_status = SCU_TASK_DONE_CHECK_RESPONSE;
 			ireq->sci_status = SCI_FAILURE_IO_RESPONSE_VALID;
 		} else {
@@ -1730,8 +1731,8 @@ sci_io_request_frame_handler(struct isci_request *ireq,
 
 			resp_iu = &ireq->ssp.rsp;
 
-			if (resp_iu->datapres == 0x01 ||
-			    resp_iu->datapres == 0x02) {
+			if (resp_iu->datapres == SAS_DATAPRES_RESPONSE_DATA ||
+			    resp_iu->datapres == SAS_DATAPRES_SENSE_DATA) {
 				ireq->scu_status = SCU_TASK_DONE_CHECK_RESPONSE;
 				ireq->sci_status = SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR;
 			} else {
diff --git a/drivers/scsi/libsas/sas_task.c b/drivers/scsi/libsas/sas_task.c
index 2966ead1d421..e9d291007817 100644
--- a/drivers/scsi/libsas/sas_task.c
+++ b/drivers/scsi/libsas/sas_task.c
@@ -15,11 +15,14 @@ void sas_ssp_task_response(struct device *dev, struct sas_task *task,
 
 	tstat->resp = SAS_TASK_COMPLETE;
 
-	if (iu->datapres == 0)
+	switch (iu->datapres) {
+	case SAS_DATAPRES_NO_DATA:
 		tstat->stat = iu->status;
-	else if (iu->datapres == 1)
+		break;
+	case SAS_DATAPRES_RESPONSE_DATA:
 		tstat->stat = iu->resp_data[3];
-	else if (iu->datapres == 2) {
+		break;
+	case SAS_DATAPRES_SENSE_DATA:
 		tstat->stat = SAS_SAM_STAT_CHECK_CONDITION;
 		tstat->buf_valid_size =
 			min_t(int, SAS_STATUS_BUF_SIZE,
@@ -29,10 +32,11 @@ void sas_ssp_task_response(struct device *dev, struct sas_task *task,
 		if (iu->status != SAM_STAT_CHECK_CONDITION)
 			dev_warn(dev, "dev %016llx sent sense data, but stat(0x%x) is not CHECK CONDITION\n",
 				 SAS_ADDR(task->dev->sas_addr), iu->status);
-	}
-	else
+		break;
+	default:
 		/* when datapres contains corrupt/unknown value... */
 		tstat->stat = SAS_SAM_STAT_CHECK_CONDITION;
+	}
 }
 EXPORT_SYMBOL_GPL(sas_ssp_task_response);
 
diff --git a/drivers/scsi/mvsas/mv_sas.c b/drivers/scsi/mvsas/mv_sas.c
index a8d1f3dd607a..b48ae26e29a9 100644
--- a/drivers/scsi/mvsas/mv_sas.c
+++ b/drivers/scsi/mvsas/mv_sas.c
@@ -1638,7 +1638,7 @@ static void mvs_set_sense(u8 *buffer, int len, int d_sense,
 static void mvs_fill_ssp_resp_iu(struct ssp_response_iu *iu,
 				u8 key, u8 asc, u8 asc_q)
 {
-	iu->datapres = 2;
+	iu->datapres = SAS_DATAPRES_SENSE_DATA;
 	iu->response_data_len = 0;
 	iu->sense_data_len = 17;
 	iu->status = 02;
diff --git a/include/scsi/sas.h b/include/scsi/sas.h
index 64154c1fed02..332a463d08ef 100644
--- a/include/scsi/sas.h
+++ b/include/scsi/sas.h
@@ -191,6 +191,13 @@ enum sas_gpio_reg_type {
 	SAS_GPIO_REG_TX_GP = 4,
 };
 
+/* Response frame DATAPRES field */
+enum {
+	SAS_DATAPRES_NO_DATA		= 0,
+	SAS_DATAPRES_RESPONSE_DATA	= 1,
+	SAS_DATAPRES_SENSE_DATA		= 2,
+};
+
 struct  dev_to_host_fis {
 	u8     fis_type;	  /* 0x34 */
 	u8     flags;
-- 
2.26.2


  parent reply	other threads:[~2022-02-17 15:48 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-17 15:42 [PATCH v2 00/18] scsi: libsas and users: Factor out LLDD TMF code John Garry
2022-02-17 15:42 ` [PATCH v2 01/18] scsi: libsas: Handle non-TMF codes in sas_scsi_find_task() John Garry
2022-02-17 15:42 ` John Garry [this message]
2022-02-17 15:42 ` [PATCH v2 03/18] scsi: libsas: Delete lldd_clear_aca callback John Garry
2022-02-17 15:42 ` [PATCH v2 04/18] scsi: libsas: Delete SAS_SG_ERR John Garry
2022-02-17 15:42 ` [PATCH v2 05/18] scsi: hisi_sas: Delete unused I_T_NEXUS_RESET_PHYUP_TIMEOUT John Garry
2022-02-17 15:42 ` [PATCH v2 06/18] scsi: libsas: Move SMP task handlers to core John Garry
2022-02-17 15:42 ` [PATCH v2 07/18] scsi: libsas: Add struct sas_tmf_task John Garry
2022-02-17 15:42 ` [PATCH v2 08/18] scsi: libsas: Add sas_task.tmf John Garry
2022-02-17 15:42 ` [PATCH v2 09/18] scsi: libsas: Add sas_execute_tmf() John Garry
2022-02-17 15:42 ` [PATCH v2 10/18] scsi: libsas: Add sas_execute_ssp_tmf() John Garry
2022-02-17 15:42 ` [PATCH v2 11/18] scsi: libsas: Add TMF handler exec complete callback John Garry
2022-02-17 15:42 ` [PATCH v2 12/18] scsi: libsas: Add TMF handler aborted callback John Garry
2022-02-17 15:42 ` [PATCH v2 13/18] scsi: libsas: Add sas_abort_task_set() John Garry
2022-02-17 15:42 ` [PATCH v2 14/18] scsi: libsas: Add sas_clear_task_set() John Garry
2022-02-17 15:42 ` [PATCH v2 15/18] scsi: libsas: Add sas_lu_reset() John Garry
2022-02-17 15:42 ` [PATCH v2 16/18] scsi: libsas: Add sas_query_task() John Garry
2022-02-17 15:42 ` [PATCH v2 17/18] scsi: libsas: Add sas_abort_task() John Garry
2022-02-17 15:42 ` [PATCH v2 18/18] scsi: libsas: Add sas_execute_ata_cmd() John Garry
2022-02-18  4:18 ` [PATCH v2 00/18] scsi: libsas and users: Factor out LLDD TMF code Damien Le Moal
2022-02-18  4:28   ` Martin K. Petersen
2022-02-19 21:53   ` Martin K. Petersen
2022-02-19 23:05     ` Damien Le Moal
2022-02-21  8:36     ` John Garry
2022-02-19 21:55 ` Martin K. Petersen
2022-02-20  0:38   ` Damien Le Moal
2022-02-20  1:31     ` Martin K. Petersen
2022-02-20  1:37       ` 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=1645112566-115804-3-git-send-email-john.garry@huawei.com \
    --to=john.garry@huawei.com \
    --cc=Ajish.Koshy@microchip.com \
    --cc=Viswas.G@microchip.com \
    --cc=artur.paszkiewicz@intel.com \
    --cc=chenxiang66@hisilicon.com \
    --cc=damien.lemoal@opensource.wdc.com \
    --cc=hch@lst.de \
    --cc=jejb@linux.ibm.com \
    --cc=jinpu.wang@cloud.ionos.com \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=linuxarm@huawei.com \
    --cc=liuqi115@huawei.com \
    --cc=martin.petersen@oracle.com \
    --cc=yanaijie@huawei.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