xref: /linux/drivers/scsi/libsas/sas_task.c (revision d188e5db9d274db4c183861438f883c1d74b0f16)
1*d188e5dbSJohn Garry 
2*d188e5dbSJohn Garry #include "sas_internal.h"
3*d188e5dbSJohn 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)
29366ca51fSJames Bottomley 			dev_printk(KERN_WARNING, dev,
30366ca51fSJames Bottomley 				   "dev %llx sent sense data, but "
31366ca51fSJames Bottomley 				   "stat(%x) is not CHECK CONDITION\n",
32366ca51fSJames Bottomley 				   SAS_ADDR(task->dev->sas_addr),
33366ca51fSJames Bottomley 				   iu->status);
34366ca51fSJames Bottomley 	}
35366ca51fSJames Bottomley 	else
36366ca51fSJames Bottomley 		/* when datapres contains corrupt/unknown value... */
37df64d3caSJames Bottomley 		tstat->stat = SAM_STAT_CHECK_CONDITION;
38366ca51fSJames Bottomley }
39366ca51fSJames Bottomley EXPORT_SYMBOL_GPL(sas_ssp_task_response);
40366ca51fSJames Bottomley 
41