xref: /linux/drivers/scsi/libsas/sas_task.c (revision 24bce201d79807b668bf9d9e0aca801c5c0d5f78)
1 // SPDX-License-Identifier: GPL-2.0-only
2 
3 #include "sas_internal.h"
4 
5 #include <linux/kernel.h>
6 #include <linux/export.h>
7 #include <scsi/sas.h>
8 #include <scsi/libsas.h>
9 
10 /* fill task_status_struct based on SSP response frame */
11 void sas_ssp_task_response(struct device *dev, struct sas_task *task,
12 			   struct ssp_response_iu *iu)
13 {
14 	struct task_status_struct *tstat = &task->task_status;
15 
16 	tstat->resp = SAS_TASK_COMPLETE;
17 
18 	switch (iu->datapres) {
19 	case SAS_DATAPRES_NO_DATA:
20 		tstat->stat = iu->status;
21 		break;
22 	case SAS_DATAPRES_RESPONSE_DATA:
23 		tstat->stat = iu->resp_data[3];
24 		break;
25 	case SAS_DATAPRES_SENSE_DATA:
26 		tstat->stat = SAS_SAM_STAT_CHECK_CONDITION;
27 		tstat->buf_valid_size =
28 			min_t(int, SAS_STATUS_BUF_SIZE,
29 			      be32_to_cpu(iu->sense_data_len));
30 		memcpy(tstat->buf, iu->sense_data, tstat->buf_valid_size);
31 
32 		if (iu->status != SAM_STAT_CHECK_CONDITION)
33 			dev_warn(dev, "dev %016llx sent sense data, but stat(0x%x) is not CHECK CONDITION\n",
34 				 SAS_ADDR(task->dev->sas_addr), iu->status);
35 		break;
36 	default:
37 		/* when datapres contains corrupt/unknown value... */
38 		tstat->stat = SAS_SAM_STAT_CHECK_CONDITION;
39 	}
40 }
41 EXPORT_SYMBOL_GPL(sas_ssp_task_response);
42 
43