blob: 1ded7d85027ec59c300ba2e25de73ee5692e48dd [file] [log] [blame]
Thomas Gleixner457c8992019-05-19 13:08:55 +01001// SPDX-License-Identifier: GPL-2.0-only
John Garryd188e5d2018-11-15 18:20:29 +08002
3#include "sas_internal.h"
4
James Bottomley366ca512008-01-18 10:47:01 -06005#include <linux/kernel.h>
Paul Gortmaker09703662011-05-27 09:37:25 -04006#include <linux/export.h>
James Bottomley366ca512008-01-18 10:47:01 -06007#include <scsi/sas.h>
8#include <scsi/libsas.h>
9
10/* fill task_status_struct based on SSP response frame */
11void 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 if (iu->datapres == 0)
19 tstat->stat = iu->status;
20 else if (iu->datapres == 1)
21 tstat->stat = iu->resp_data[3];
22 else if (iu->datapres == 2) {
James Bottomleydf64d3c2010-07-27 15:51:13 -050023 tstat->stat = SAM_STAT_CHECK_CONDITION;
James Bottomley366ca512008-01-18 10:47:01 -060024 tstat->buf_valid_size =
25 min_t(int, SAS_STATUS_BUF_SIZE,
26 be32_to_cpu(iu->sense_data_len));
27 memcpy(tstat->buf, iu->sense_data, tstat->buf_valid_size);
28
James Bottomleydf64d3c2010-07-27 15:51:13 -050029 if (iu->status != SAM_STAT_CHECK_CONDITION)
John Garry15ba7802018-11-15 18:20:31 +080030 dev_warn(dev, "dev %llx sent sense data, but stat(%x) is not CHECK CONDITION\n",
31 SAS_ADDR(task->dev->sas_addr), iu->status);
James Bottomley366ca512008-01-18 10:47:01 -060032 }
33 else
34 /* when datapres contains corrupt/unknown value... */
James Bottomleydf64d3c2010-07-27 15:51:13 -050035 tstat->stat = SAM_STAT_CHECK_CONDITION;
James Bottomley366ca512008-01-18 10:47:01 -060036}
37EXPORT_SYMBOL_GPL(sas_ssp_task_response);
38