scsi: libsas: Use enum for response frame DATAPRES field

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.

Link: https://lore.kernel.org/r/1645112566-115804-3-git-send-email-john.garry@huawei.com
Suggested-by: Xiang Chen <chenxiang66@hisilicon.com>
Tested-by: Yihang Li <liyihang6@hisilicon.com>
Tested-by: Damien Le Moal <damien.lemoal@opensource.wdc.com>
Reviewed-by: Jack Wang <jinpu.wang@ionos.com>
Signed-off-by: John Garry <john.garry@huawei.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
This commit is contained in:
John Garry 2022-02-17 23:42:30 +08:00 committed by Martin K. Petersen
parent 9aacf6fe90
commit 1d6049a3b1
5 changed files with 22 additions and 10 deletions

View File

@ -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;

View File

@ -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 {

View File

@ -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);

View File

@ -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;

View File

@ -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;