xref: /linux/drivers/scsi/libsas/sas_task.c (revision 15ba7806c316ce88d45db7d12d32380f53c01a06)
1d188e5dbSJohn Garry 
2d188e5dbSJohn Garry #include "sas_internal.h"
3d188e5dbSJohn Garry 
4366ca51fSJames Bottomley #include <linux/kernel.h>
509703660SPaul Gortmaker #include <linux/export.h>
6366ca51fSJames Bottomley #include <scsi/sas.h>
7366ca51fSJames Bottomley #include <scsi/libsas.h>
8366ca51fSJames Bottomley 
9366ca51fSJames Bottomley /* fill task_status_struct based on SSP response frame */
10366ca51fSJames Bottomley void sas_ssp_task_response(struct device *dev, struct sas_task *task,
11366ca51fSJames Bottomley 			   struct ssp_response_iu *iu)
12366ca51fSJames Bottomley {
13366ca51fSJames Bottomley 	struct task_status_struct *tstat = &task->task_status;
14366ca51fSJames Bottomley 
15366ca51fSJames Bottomley 	tstat->resp = SAS_TASK_COMPLETE;
16366ca51fSJames Bottomley 
17366ca51fSJames Bottomley 	if (iu->datapres == 0)
18366ca51fSJames Bottomley 		tstat->stat = iu->status;
19366ca51fSJames Bottomley 	else if (iu->datapres == 1)
20366ca51fSJames Bottomley 		tstat->stat = iu->resp_data[3];
21366ca51fSJames Bottomley 	else if (iu->datapres == 2) {
22df64d3caSJames Bottomley 		tstat->stat = SAM_STAT_CHECK_CONDITION;
23366ca51fSJames Bottomley 		tstat->buf_valid_size =
24366ca51fSJames Bottomley 			min_t(int, SAS_STATUS_BUF_SIZE,
25366ca51fSJames Bottomley 			      be32_to_cpu(iu->sense_data_len));
26366ca51fSJames Bottomley 		memcpy(tstat->buf, iu->sense_data, tstat->buf_valid_size);
27366ca51fSJames Bottomley 
28df64d3caSJames Bottomley 		if (iu->status != SAM_STAT_CHECK_CONDITION)
29*15ba7806SJohn Garry 			dev_warn(dev, "dev %llx sent sense data, but stat(%x) is not CHECK CONDITION\n",
30*15ba7806SJohn Garry 				 SAS_ADDR(task->dev->sas_addr), iu->status);
31366ca51fSJames Bottomley 	}
32366ca51fSJames Bottomley 	else
33366ca51fSJames Bottomley 		/* when datapres contains corrupt/unknown value... */
34df64d3caSJames Bottomley 		tstat->stat = SAM_STAT_CHECK_CONDITION;
35366ca51fSJames Bottomley }
36366ca51fSJames Bottomley EXPORT_SYMBOL_GPL(sas_ssp_task_response);
37366ca51fSJames Bottomley 
38