xref: /linux/drivers/scsi/libsas/sas_task.c (revision d377f415dddc18b33c88dcd41cfe4fe6d9db82fb)
1457c8996SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
2d188e5dbSJohn Garry 
3d188e5dbSJohn Garry #include "sas_internal.h"
4d188e5dbSJohn Garry 
5366ca51fSJames Bottomley #include <linux/kernel.h>
609703660SPaul Gortmaker #include <linux/export.h>
7366ca51fSJames Bottomley #include <scsi/sas.h>
8366ca51fSJames Bottomley #include <scsi/libsas.h>
9366ca51fSJames Bottomley 
10366ca51fSJames Bottomley /* fill task_status_struct based on SSP response frame */
11366ca51fSJames Bottomley void sas_ssp_task_response(struct device *dev, struct sas_task *task,
12366ca51fSJames Bottomley 			   struct ssp_response_iu *iu)
13366ca51fSJames Bottomley {
14366ca51fSJames Bottomley 	struct task_status_struct *tstat = &task->task_status;
15366ca51fSJames Bottomley 
16366ca51fSJames Bottomley 	tstat->resp = SAS_TASK_COMPLETE;
17366ca51fSJames Bottomley 
18366ca51fSJames Bottomley 	if (iu->datapres == 0)
19366ca51fSJames Bottomley 		tstat->stat = iu->status;
20366ca51fSJames Bottomley 	else if (iu->datapres == 1)
21366ca51fSJames Bottomley 		tstat->stat = iu->resp_data[3];
22366ca51fSJames Bottomley 	else if (iu->datapres == 2) {
23*d377f415SBart Van Assche 		tstat->stat = SAS_SAM_STAT_CHECK_CONDITION;
24366ca51fSJames Bottomley 		tstat->buf_valid_size =
25366ca51fSJames Bottomley 			min_t(int, SAS_STATUS_BUF_SIZE,
26366ca51fSJames Bottomley 			      be32_to_cpu(iu->sense_data_len));
27366ca51fSJames Bottomley 		memcpy(tstat->buf, iu->sense_data, tstat->buf_valid_size);
28366ca51fSJames Bottomley 
29df64d3caSJames Bottomley 		if (iu->status != SAM_STAT_CHECK_CONDITION)
30b3e3d4c6SJohn Garry 			dev_warn(dev, "dev %016llx sent sense data, but stat(0x%x) is not CHECK CONDITION\n",
3115ba7806SJohn Garry 				 SAS_ADDR(task->dev->sas_addr), iu->status);
32366ca51fSJames Bottomley 	}
33366ca51fSJames Bottomley 	else
34366ca51fSJames Bottomley 		/* when datapres contains corrupt/unknown value... */
35*d377f415SBart Van Assche 		tstat->stat = SAS_SAM_STAT_CHECK_CONDITION;
36366ca51fSJames Bottomley }
37366ca51fSJames Bottomley EXPORT_SYMBOL_GPL(sas_ssp_task_response);
38366ca51fSJames Bottomley 
39