162306a36Sopenharmony_ci/*
262306a36Sopenharmony_ci * This file is provided under a dual BSD/GPLv2 license.  When using or
362306a36Sopenharmony_ci * redistributing this file, you may do so under either license.
462306a36Sopenharmony_ci *
562306a36Sopenharmony_ci * GPL LICENSE SUMMARY
662306a36Sopenharmony_ci *
762306a36Sopenharmony_ci * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
862306a36Sopenharmony_ci *
962306a36Sopenharmony_ci * This program is free software; you can redistribute it and/or modify
1062306a36Sopenharmony_ci * it under the terms of version 2 of the GNU General Public License as
1162306a36Sopenharmony_ci * published by the Free Software Foundation.
1262306a36Sopenharmony_ci *
1362306a36Sopenharmony_ci * This program is distributed in the hope that it will be useful, but
1462306a36Sopenharmony_ci * WITHOUT ANY WARRANTY; without even the implied warranty of
1562306a36Sopenharmony_ci * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
1662306a36Sopenharmony_ci * General Public License for more details.
1762306a36Sopenharmony_ci *
1862306a36Sopenharmony_ci * You should have received a copy of the GNU General Public License
1962306a36Sopenharmony_ci * along with this program; if not, write to the Free Software
2062306a36Sopenharmony_ci * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
2162306a36Sopenharmony_ci * The full GNU General Public License is included in this distribution
2262306a36Sopenharmony_ci * in the file called LICENSE.GPL.
2362306a36Sopenharmony_ci *
2462306a36Sopenharmony_ci * BSD LICENSE
2562306a36Sopenharmony_ci *
2662306a36Sopenharmony_ci * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
2762306a36Sopenharmony_ci * All rights reserved.
2862306a36Sopenharmony_ci *
2962306a36Sopenharmony_ci * Redistribution and use in source and binary forms, with or without
3062306a36Sopenharmony_ci * modification, are permitted provided that the following conditions
3162306a36Sopenharmony_ci * are met:
3262306a36Sopenharmony_ci *
3362306a36Sopenharmony_ci *   * Redistributions of source code must retain the above copyright
3462306a36Sopenharmony_ci *     notice, this list of conditions and the following disclaimer.
3562306a36Sopenharmony_ci *   * Redistributions in binary form must reproduce the above copyright
3662306a36Sopenharmony_ci *     notice, this list of conditions and the following disclaimer in
3762306a36Sopenharmony_ci *     the documentation and/or other materials provided with the
3862306a36Sopenharmony_ci *     distribution.
3962306a36Sopenharmony_ci *   * Neither the name of Intel Corporation nor the names of its
4062306a36Sopenharmony_ci *     contributors may be used to endorse or promote products derived
4162306a36Sopenharmony_ci *     from this software without specific prior written permission.
4262306a36Sopenharmony_ci *
4362306a36Sopenharmony_ci * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4462306a36Sopenharmony_ci * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
4562306a36Sopenharmony_ci * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
4662306a36Sopenharmony_ci * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
4762306a36Sopenharmony_ci * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
4862306a36Sopenharmony_ci * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
4962306a36Sopenharmony_ci * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
5062306a36Sopenharmony_ci * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
5162306a36Sopenharmony_ci * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
5262306a36Sopenharmony_ci * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
5362306a36Sopenharmony_ci * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
5462306a36Sopenharmony_ci */
5562306a36Sopenharmony_ci#ifndef _ISCI_TASK_H_
5662306a36Sopenharmony_ci#define _ISCI_TASK_H_
5762306a36Sopenharmony_ci
5862306a36Sopenharmony_ci#include <scsi/sas_ata.h>
5962306a36Sopenharmony_ci#include "host.h"
6062306a36Sopenharmony_ci
6162306a36Sopenharmony_ci#define ISCI_TERMINATION_TIMEOUT_MSEC 500
6262306a36Sopenharmony_ci
6362306a36Sopenharmony_cistruct isci_request;
6462306a36Sopenharmony_ci
6562306a36Sopenharmony_ci/**
6662306a36Sopenharmony_ci * enum isci_tmf_function_codes - This enum defines the possible preparations
6762306a36Sopenharmony_ci *    of task management requests.
6862306a36Sopenharmony_ci *
6962306a36Sopenharmony_ci *
7062306a36Sopenharmony_ci */
7162306a36Sopenharmony_cienum isci_tmf_function_codes {
7262306a36Sopenharmony_ci
7362306a36Sopenharmony_ci	isci_tmf_func_none      = 0,
7462306a36Sopenharmony_ci	isci_tmf_ssp_task_abort = TMF_ABORT_TASK,
7562306a36Sopenharmony_ci	isci_tmf_ssp_lun_reset  = TMF_LU_RESET,
7662306a36Sopenharmony_ci};
7762306a36Sopenharmony_ci
7862306a36Sopenharmony_ci/**
7962306a36Sopenharmony_ci * struct isci_tmf - This class represents the task management object which
8062306a36Sopenharmony_ci *    acts as an interface to libsas for processing task management requests
8162306a36Sopenharmony_ci *
8262306a36Sopenharmony_ci *
8362306a36Sopenharmony_ci */
8462306a36Sopenharmony_cistruct isci_tmf {
8562306a36Sopenharmony_ci
8662306a36Sopenharmony_ci	struct completion *complete;
8762306a36Sopenharmony_ci	enum sas_protocol proto;
8862306a36Sopenharmony_ci	union {
8962306a36Sopenharmony_ci		struct ssp_response_iu resp_iu;
9062306a36Sopenharmony_ci		struct dev_to_host_fis d2h_fis;
9162306a36Sopenharmony_ci		u8 rsp_buf[SSP_RESP_IU_MAX_SIZE];
9262306a36Sopenharmony_ci	} resp;
9362306a36Sopenharmony_ci	unsigned char lun[8];
9462306a36Sopenharmony_ci	u16 io_tag;
9562306a36Sopenharmony_ci	enum isci_tmf_function_codes tmf_code;
9662306a36Sopenharmony_ci	int status;
9762306a36Sopenharmony_ci};
9862306a36Sopenharmony_ci
9962306a36Sopenharmony_cistatic inline void isci_print_tmf(struct isci_host *ihost, struct isci_tmf *tmf)
10062306a36Sopenharmony_ci{
10162306a36Sopenharmony_ci	if (SAS_PROTOCOL_SATA == tmf->proto)
10262306a36Sopenharmony_ci		dev_dbg(&ihost->pdev->dev,
10362306a36Sopenharmony_ci			"%s: status = %x\n"
10462306a36Sopenharmony_ci			"tmf->resp.d2h_fis.status = %x\n"
10562306a36Sopenharmony_ci			"tmf->resp.d2h_fis.error = %x\n",
10662306a36Sopenharmony_ci			__func__,
10762306a36Sopenharmony_ci			tmf->status,
10862306a36Sopenharmony_ci			tmf->resp.d2h_fis.status,
10962306a36Sopenharmony_ci			tmf->resp.d2h_fis.error);
11062306a36Sopenharmony_ci	else
11162306a36Sopenharmony_ci		dev_dbg(&ihost->pdev->dev,
11262306a36Sopenharmony_ci			"%s: status = %x\n"
11362306a36Sopenharmony_ci			"tmf->resp.resp_iu.data_present = %x\n"
11462306a36Sopenharmony_ci			"tmf->resp.resp_iu.status = %x\n"
11562306a36Sopenharmony_ci			"tmf->resp.resp_iu.data_length = %x\n"
11662306a36Sopenharmony_ci			"tmf->resp.resp_iu.data[0] = %x\n"
11762306a36Sopenharmony_ci			"tmf->resp.resp_iu.data[1] = %x\n"
11862306a36Sopenharmony_ci			"tmf->resp.resp_iu.data[2] = %x\n"
11962306a36Sopenharmony_ci			"tmf->resp.resp_iu.data[3] = %x\n",
12062306a36Sopenharmony_ci			__func__,
12162306a36Sopenharmony_ci			tmf->status,
12262306a36Sopenharmony_ci			tmf->resp.resp_iu.datapres,
12362306a36Sopenharmony_ci			tmf->resp.resp_iu.status,
12462306a36Sopenharmony_ci			be32_to_cpu(tmf->resp.resp_iu.response_data_len),
12562306a36Sopenharmony_ci			tmf->resp.resp_iu.resp_data[0],
12662306a36Sopenharmony_ci			tmf->resp.resp_iu.resp_data[1],
12762306a36Sopenharmony_ci			tmf->resp.resp_iu.resp_data[2],
12862306a36Sopenharmony_ci			tmf->resp.resp_iu.resp_data[3]);
12962306a36Sopenharmony_ci}
13062306a36Sopenharmony_ci
13162306a36Sopenharmony_ci
13262306a36Sopenharmony_ciint isci_task_execute_task(
13362306a36Sopenharmony_ci	struct sas_task *task,
13462306a36Sopenharmony_ci	gfp_t gfp_flags);
13562306a36Sopenharmony_ci
13662306a36Sopenharmony_ciint isci_task_abort_task(
13762306a36Sopenharmony_ci	struct sas_task *task);
13862306a36Sopenharmony_ci
13962306a36Sopenharmony_ciint isci_task_abort_task_set(
14062306a36Sopenharmony_ci	struct domain_device *d_device,
14162306a36Sopenharmony_ci	u8 *lun);
14262306a36Sopenharmony_ci
14362306a36Sopenharmony_ciint isci_task_clear_task_set(
14462306a36Sopenharmony_ci	struct domain_device *d_device,
14562306a36Sopenharmony_ci	u8 *lun);
14662306a36Sopenharmony_ci
14762306a36Sopenharmony_ciint isci_task_query_task(
14862306a36Sopenharmony_ci	struct sas_task *task);
14962306a36Sopenharmony_ci
15062306a36Sopenharmony_ciint isci_task_lu_reset(
15162306a36Sopenharmony_ci	struct domain_device *d_device,
15262306a36Sopenharmony_ci	u8 *lun);
15362306a36Sopenharmony_ci
15462306a36Sopenharmony_ciint isci_task_clear_nexus_port(
15562306a36Sopenharmony_ci	struct asd_sas_port *port);
15662306a36Sopenharmony_ci
15762306a36Sopenharmony_ciint isci_task_clear_nexus_ha(
15862306a36Sopenharmony_ci	struct sas_ha_struct *ha);
15962306a36Sopenharmony_ci
16062306a36Sopenharmony_ciint isci_task_I_T_nexus_reset(
16162306a36Sopenharmony_ci	struct domain_device *d_device);
16262306a36Sopenharmony_ci
16362306a36Sopenharmony_civoid isci_task_request_complete(
16462306a36Sopenharmony_ci	struct isci_host *isci_host,
16562306a36Sopenharmony_ci	struct isci_request *request,
16662306a36Sopenharmony_ci	enum sci_task_status completion_status);
16762306a36Sopenharmony_ci
16862306a36Sopenharmony_ciu16 isci_task_ssp_request_get_io_tag_to_manage(
16962306a36Sopenharmony_ci	struct isci_request *request);
17062306a36Sopenharmony_ci
17162306a36Sopenharmony_ciu8 isci_task_ssp_request_get_function(
17262306a36Sopenharmony_ci	struct isci_request *request);
17362306a36Sopenharmony_ci
17462306a36Sopenharmony_ci
17562306a36Sopenharmony_civoid *isci_task_ssp_request_get_response_data_address(
17662306a36Sopenharmony_ci	struct isci_request *request);
17762306a36Sopenharmony_ci
17862306a36Sopenharmony_ciu32 isci_task_ssp_request_get_response_data_length(
17962306a36Sopenharmony_ci	struct isci_request *request);
18062306a36Sopenharmony_ci
18162306a36Sopenharmony_ci#endif /* !defined(_SCI_TASK_H_) */
182