xref: /linux/drivers/scsi/libsas/sas_task.c (revision df64d3caab8db6ae17dacd229a03d7689a10c432)
1366ca51fSJames Bottomley #include <linux/kernel.h>
2366ca51fSJames Bottomley #include <scsi/sas.h>
3366ca51fSJames Bottomley #include <scsi/libsas.h>
4366ca51fSJames Bottomley 
5366ca51fSJames Bottomley /* fill task_status_struct based on SSP response frame */
6366ca51fSJames Bottomley void sas_ssp_task_response(struct device *dev, struct sas_task *task,
7366ca51fSJames Bottomley 			   struct ssp_response_iu *iu)
8366ca51fSJames Bottomley {
9366ca51fSJames Bottomley 	struct task_status_struct *tstat = &task->task_status;
10366ca51fSJames Bottomley 
11366ca51fSJames Bottomley 	tstat->resp = SAS_TASK_COMPLETE;
12366ca51fSJames Bottomley 
13366ca51fSJames Bottomley 	if (iu->datapres == 0)
14366ca51fSJames Bottomley 		tstat->stat = iu->status;
15366ca51fSJames Bottomley 	else if (iu->datapres == 1)
16366ca51fSJames Bottomley 		tstat->stat = iu->resp_data[3];
17366ca51fSJames Bottomley 	else if (iu->datapres == 2) {
18*df64d3caSJames Bottomley 		tstat->stat = SAM_STAT_CHECK_CONDITION;
19366ca51fSJames Bottomley 		tstat->buf_valid_size =
20366ca51fSJames Bottomley 			min_t(int, SAS_STATUS_BUF_SIZE,
21366ca51fSJames Bottomley 			      be32_to_cpu(iu->sense_data_len));
22366ca51fSJames Bottomley 		memcpy(tstat->buf, iu->sense_data, tstat->buf_valid_size);
23366ca51fSJames Bottomley 
24*df64d3caSJames Bottomley 		if (iu->status != SAM_STAT_CHECK_CONDITION)
25366ca51fSJames Bottomley 			dev_printk(KERN_WARNING, dev,
26366ca51fSJames Bottomley 				   "dev %llx sent sense data, but "
27366ca51fSJames Bottomley 				   "stat(%x) is not CHECK CONDITION\n",
28366ca51fSJames Bottomley 				   SAS_ADDR(task->dev->sas_addr),
29366ca51fSJames Bottomley 				   iu->status);
30366ca51fSJames Bottomley 	}
31366ca51fSJames Bottomley 	else
32366ca51fSJames Bottomley 		/* when datapres contains corrupt/unknown value... */
33*df64d3caSJames Bottomley 		tstat->stat = SAM_STAT_CHECK_CONDITION;
34366ca51fSJames Bottomley }
35366ca51fSJames Bottomley EXPORT_SYMBOL_GPL(sas_ssp_task_response);
36366ca51fSJames Bottomley 
37