1f11c7f63SJim Harris /*-
2*718cf2ccSPedro F. Giffuni * SPDX-License-Identifier: BSD-2-Clause OR GPL-2.0
3*718cf2ccSPedro F. Giffuni *
4f11c7f63SJim Harris * This file is provided under a dual BSD/GPLv2 license. When using or
5f11c7f63SJim Harris * redistributing this file, you may do so under either license.
6f11c7f63SJim Harris *
7f11c7f63SJim Harris * GPL LICENSE SUMMARY
8f11c7f63SJim Harris *
9f11c7f63SJim Harris * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
10f11c7f63SJim Harris *
11f11c7f63SJim Harris * This program is free software; you can redistribute it and/or modify
12f11c7f63SJim Harris * it under the terms of version 2 of the GNU General Public License as
13f11c7f63SJim Harris * published by the Free Software Foundation.
14f11c7f63SJim Harris *
15f11c7f63SJim Harris * This program is distributed in the hope that it will be useful, but
16f11c7f63SJim Harris * WITHOUT ANY WARRANTY; without even the implied warranty of
17f11c7f63SJim Harris * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18f11c7f63SJim Harris * General Public License for more details.
19f11c7f63SJim Harris *
20f11c7f63SJim Harris * You should have received a copy of the GNU General Public License
21f11c7f63SJim Harris * along with this program; if not, write to the Free Software
22f11c7f63SJim Harris * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
23f11c7f63SJim Harris * The full GNU General Public License is included in this distribution
24f11c7f63SJim Harris * in the file called LICENSE.GPL.
25f11c7f63SJim Harris *
26f11c7f63SJim Harris * BSD LICENSE
27f11c7f63SJim Harris *
28f11c7f63SJim Harris * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
29f11c7f63SJim Harris * All rights reserved.
30f11c7f63SJim Harris *
31f11c7f63SJim Harris * Redistribution and use in source and binary forms, with or without
32f11c7f63SJim Harris * modification, are permitted provided that the following conditions
33f11c7f63SJim Harris * are met:
34f11c7f63SJim Harris *
35f11c7f63SJim Harris * * Redistributions of source code must retain the above copyright
36f11c7f63SJim Harris * notice, this list of conditions and the following disclaimer.
37f11c7f63SJim Harris * * Redistributions in binary form must reproduce the above copyright
38f11c7f63SJim Harris * notice, this list of conditions and the following disclaimer in
39f11c7f63SJim Harris * the documentation and/or other materials provided with the
40f11c7f63SJim Harris * distribution.
41f11c7f63SJim Harris *
42f11c7f63SJim Harris * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
43f11c7f63SJim Harris * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
44f11c7f63SJim Harris * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
45f11c7f63SJim Harris * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
46f11c7f63SJim Harris * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
47f11c7f63SJim Harris * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
48f11c7f63SJim Harris * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
49f11c7f63SJim Harris * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
50f11c7f63SJim Harris * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
51f11c7f63SJim Harris * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
52f11c7f63SJim Harris * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
53f11c7f63SJim Harris */
54f11c7f63SJim Harris
55f11c7f63SJim Harris #include <sys/cdefs.h>
56f11c7f63SJim Harris #include <dev/isci/scil/sati.h>
57f11c7f63SJim Harris #include <dev/isci/scil/scif_sas_logger.h>
58f11c7f63SJim Harris #include <dev/isci/scil/scif_sas_task_request.h>
59f11c7f63SJim Harris #include <dev/isci/scil/scif_sas_controller.h>
60f11c7f63SJim Harris #include <dev/isci/scil/scif_sas_remote_device.h>
61f11c7f63SJim Harris #include <dev/isci/scil/scif_sas_stp_task_request.h>
62f11c7f63SJim Harris #include <dev/isci/scil/scic_task_request.h>
63f11c7f63SJim Harris #include <dev/isci/scil/scic_controller.h>
64f11c7f63SJim Harris
65f11c7f63SJim Harris /**
66f11c7f63SJim Harris * @brief This method provides SATA/STP STARTED state specific handling for
67f11c7f63SJim Harris * when the user attempts to complete the supplied IO request.
68f11c7f63SJim Harris * It will perform data/response translation and free NCQ tags
69f11c7f63SJim Harris * if necessary.
70f11c7f63SJim Harris *
71f11c7f63SJim Harris * @param[in] io_request This parameter specifies the IO request object
72f11c7f63SJim Harris * to be started.
73f11c7f63SJim Harris *
74f11c7f63SJim Harris * @return This method returns a value indicating if the IO request was
75f11c7f63SJim Harris * successfully completed or not.
76f11c7f63SJim Harris */
77f11c7f63SJim Harris static
scif_sas_stp_core_cb_task_request_complete_handler(SCIF_SAS_CONTROLLER_T * fw_controller,SCIF_SAS_REMOTE_DEVICE_T * fw_device,SCIF_SAS_REQUEST_T * fw_request,SCI_STATUS * completion_status)78f11c7f63SJim Harris SCI_STATUS scif_sas_stp_core_cb_task_request_complete_handler(
79f11c7f63SJim Harris SCIF_SAS_CONTROLLER_T * fw_controller,
80f11c7f63SJim Harris SCIF_SAS_REMOTE_DEVICE_T * fw_device,
81f11c7f63SJim Harris SCIF_SAS_REQUEST_T * fw_request,
82f11c7f63SJim Harris SCI_STATUS * completion_status
83f11c7f63SJim Harris )
84f11c7f63SJim Harris {
85f11c7f63SJim Harris #if !defined(DISABLE_SATI_TASK_MANAGEMENT)
86f11c7f63SJim Harris SCIF_SAS_TASK_REQUEST_T * fw_task = (SCIF_SAS_TASK_REQUEST_T *) fw_request;
87f11c7f63SJim Harris
88f11c7f63SJim Harris SCIF_LOG_TRACE((
89f11c7f63SJim Harris sci_base_object_get_logger(fw_controller),
90f11c7f63SJim Harris SCIF_LOG_OBJECT_TASK_MANAGEMENT,
91f11c7f63SJim Harris "scif_sas_stp_core_cb_task_request_complete_handler(0x%x, 0x%x, 0x%x, 0x%x) enter\n",
92f11c7f63SJim Harris fw_controller, fw_device, fw_request, *completion_status
93f11c7f63SJim Harris ));
94f11c7f63SJim Harris
95f11c7f63SJim Harris // Translating the response is only necessary if some sort of error
96f11c7f63SJim Harris // occurred resulting in having the error bit set in the ATA status
97f11c7f63SJim Harris // register and values to decode in the ATA error register.
98f11c7f63SJim Harris if ( (*completion_status == SCI_SUCCESS)
99f11c7f63SJim Harris || (*completion_status == SCI_FAILURE_IO_RESPONSE_VALID) )
100f11c7f63SJim Harris {
101f11c7f63SJim Harris SATI_STATUS sati_status = sati_translate_task_response(
102f11c7f63SJim Harris &fw_task->parent.stp.sequence,
103f11c7f63SJim Harris fw_task,
104f11c7f63SJim Harris fw_task
105f11c7f63SJim Harris );
106f11c7f63SJim Harris
107f11c7f63SJim Harris if (sati_status == SATI_COMPLETE)
108f11c7f63SJim Harris *completion_status = SCI_SUCCESS;
109f11c7f63SJim Harris else if (sati_status == SATI_FAILURE_CHECK_RESPONSE_DATA)
110f11c7f63SJim Harris *completion_status = SCI_FAILURE_IO_RESPONSE_VALID;
111f11c7f63SJim Harris else if (sati_status == SATI_SEQUENCE_INCOMPLETE)
112f11c7f63SJim Harris {
113f11c7f63SJim Harris // The translation indicates that additional SATA requests are
114f11c7f63SJim Harris // necessary to finish the original SCSI request. As a result,
115f11c7f63SJim Harris // do not complete the IO and begin the next stage of the
116f11c7f63SJim Harris // translation.
117f11c7f63SJim Harris /// @todo multiple ATA commands are required, but not supported yet.
118f11c7f63SJim Harris return SCI_FAILURE;
119f11c7f63SJim Harris }
120f11c7f63SJim Harris else
121f11c7f63SJim Harris {
122f11c7f63SJim Harris // Something unexpected occurred during translation. Fail the
123f11c7f63SJim Harris // IO request to the user.
124f11c7f63SJim Harris *completion_status = SCI_FAILURE;
125f11c7f63SJim Harris }
126f11c7f63SJim Harris }
127f11c7f63SJim Harris else //A stp task request sometimes fails.
128f11c7f63SJim Harris {
129f11c7f63SJim Harris if (scif_sas_task_request_get_function(fw_task) == SCI_SAS_ABORT_TASK_SET)
130f11c7f63SJim Harris {
131f11c7f63SJim Harris scif_sas_stp_task_request_abort_task_set_failure_handler(
132f11c7f63SJim Harris fw_device, fw_task);
133f11c7f63SJim Harris }
134f11c7f63SJim Harris }
135f11c7f63SJim Harris
136f11c7f63SJim Harris return SCI_SUCCESS;
137f11c7f63SJim Harris #else // !defined(DISABLE_SATI_TASK_MANAGEMENT)
138f11c7f63SJim Harris return SCI_FAILURE;
139f11c7f63SJim Harris #endif // !defined(DISABLE_SATI_TASK_MANAGEMENT)
140f11c7f63SJim Harris }
141f11c7f63SJim Harris
142f11c7f63SJim Harris /**
143f11c7f63SJim Harris * @file
144f11c7f63SJim Harris *
145f11c7f63SJim Harris * @brief This file contains the method implementations for the
146f11c7f63SJim Harris * SCIF_SAS_STP_TASK_REQUEST object. The contents will implement
147f11c7f63SJim Harris * SATA/STP specific functionality.
148f11c7f63SJim Harris */
scif_sas_stp_task_request_construct(SCIF_SAS_TASK_REQUEST_T * fw_task)149f11c7f63SJim Harris SCI_STATUS scif_sas_stp_task_request_construct(
150f11c7f63SJim Harris SCIF_SAS_TASK_REQUEST_T * fw_task
151f11c7f63SJim Harris )
152f11c7f63SJim Harris {
153f11c7f63SJim Harris SCI_STATUS sci_status = SCI_FAILURE;
154f11c7f63SJim Harris
155f11c7f63SJim Harris #if !defined(DISABLE_SATI_TASK_MANAGEMENT)
156f11c7f63SJim Harris SATI_STATUS sati_status;
157f11c7f63SJim Harris SCIF_SAS_REMOTE_DEVICE_T * fw_device = fw_task->parent.device;
158f11c7f63SJim Harris
159f11c7f63SJim Harris SCIF_LOG_TRACE((
160f11c7f63SJim Harris sci_base_object_get_logger(fw_task),
161f11c7f63SJim Harris SCIF_LOG_OBJECT_TASK_MANAGEMENT,
162f11c7f63SJim Harris "scif_sas_stp_task_request_construct(0x%x) enter\n",
163f11c7f63SJim Harris fw_task
164f11c7f63SJim Harris ));
165f11c7f63SJim Harris
166f11c7f63SJim Harris // The translator will indirectly invoke core methods to set the fields
167f11c7f63SJim Harris // of the ATA register FIS inside of this method.
168f11c7f63SJim Harris sati_status = sati_translate_task_management(
169f11c7f63SJim Harris &fw_task->parent.stp.sequence,
170f11c7f63SJim Harris &fw_device->protocol_device.stp_device.sati_device,
171f11c7f63SJim Harris fw_task,
172f11c7f63SJim Harris fw_task
173f11c7f63SJim Harris );
174f11c7f63SJim Harris
175f11c7f63SJim Harris if (sati_status == SATI_SUCCESS)
176f11c7f63SJim Harris {
177f11c7f63SJim Harris sci_status = scic_task_request_construct_sata(fw_task->parent.core_object);
178f11c7f63SJim Harris //fw_task->parent.state_handlers = &stp_io_request_constructed_handlers;
179f11c7f63SJim Harris fw_task->parent.protocol_complete_handler =
180f11c7f63SJim Harris scif_sas_stp_core_cb_task_request_complete_handler;
181f11c7f63SJim Harris }
182f11c7f63SJim Harris else
183f11c7f63SJim Harris {
184f11c7f63SJim Harris SCIF_LOG_ERROR((
185f11c7f63SJim Harris sci_base_object_get_logger(fw_task),
186f11c7f63SJim Harris SCIF_LOG_OBJECT_TASK_MANAGEMENT,
187f11c7f63SJim Harris "Task 0x%x received unexpected SAT translation failure 0x%x\n",
188f11c7f63SJim Harris fw_task, sati_status
189f11c7f63SJim Harris ));
190f11c7f63SJim Harris }
191f11c7f63SJim Harris #endif // !defined(DISABLE_SATI_TASK_MANAGEMENT)
192f11c7f63SJim Harris
193f11c7f63SJim Harris return sci_status;
194f11c7f63SJim Harris }
195f11c7f63SJim Harris
196f11c7f63SJim Harris
197f11c7f63SJim Harris /**
198f11c7f63SJim Harris * @brief This method provides handling for failed stp TASK MANAGEMENT
199f11c7f63SJim Harris * request.
200f11c7f63SJim Harris *
201f11c7f63SJim Harris * @param[in] fw_device This parameter specifies the target device the
202f11c7f63SJim Harris * task management request towards to.
203f11c7f63SJim Harris * @param[in] fw_request This parameter specifies the failed task management
204f11c7f63SJim Harris * request.
205f11c7f63SJim Harris * @param[in] completion_status This parameter sprecifies the completion
206f11c7f63SJim Harris * status of the task management request's core status.
207f11c7f63SJim Harris *
208f11c7f63SJim Harris * @return None.
209f11c7f63SJim Harris */
scif_sas_stp_task_request_abort_task_set_failure_handler(SCIF_SAS_REMOTE_DEVICE_T * fw_device,SCIF_SAS_TASK_REQUEST_T * fw_task)210f11c7f63SJim Harris void scif_sas_stp_task_request_abort_task_set_failure_handler(
211f11c7f63SJim Harris SCIF_SAS_REMOTE_DEVICE_T * fw_device,
212f11c7f63SJim Harris SCIF_SAS_TASK_REQUEST_T * fw_task
213f11c7f63SJim Harris )
214f11c7f63SJim Harris {
215f11c7f63SJim Harris #if !defined(DISABLE_SATI_TASK_MANAGEMENT)
216f11c7f63SJim Harris SCIF_SAS_DOMAIN_T * fw_domain = fw_device->domain;
217f11c7f63SJim Harris SCI_FAST_LIST_ELEMENT_T * pending_request_element;
218f11c7f63SJim Harris SCIF_SAS_REQUEST_T * pending_request = NULL;
219f11c7f63SJim Harris
220f11c7f63SJim Harris pending_request_element = fw_domain->request_list.list_head;
221f11c7f63SJim Harris
222f11c7f63SJim Harris // Cycle through the list of IO requests. search all the
223f11c7f63SJim Harris // outstanding IOs with "waiting for abort task set" flag,
224f11c7f63SJim Harris // completes them now.
225f11c7f63SJim Harris while (pending_request_element != NULL)
226f11c7f63SJim Harris {
227f11c7f63SJim Harris pending_request =
228f11c7f63SJim Harris (SCIF_SAS_REQUEST_T*) sci_fast_list_get_object(pending_request_element);
229f11c7f63SJim Harris
230453130d9SPedro F. Giffuni // The current element may be deleted from the list because of
231f11c7f63SJim Harris // IO completion so advance to the next element early
232f11c7f63SJim Harris pending_request_element = sci_fast_list_get_next(pending_request_element);
233f11c7f63SJim Harris
234f11c7f63SJim Harris if ( pending_request->device == fw_device
235f11c7f63SJim Harris && pending_request->is_waiting_for_abort_task_set == TRUE )
236f11c7f63SJim Harris {
237f11c7f63SJim Harris //In case the pending_request is still in the middle of aborting.
238f11c7f63SJim Harris //abort it again to the core.
239f11c7f63SJim Harris SCI_STATUS abort_status;
240f11c7f63SJim Harris
241f11c7f63SJim Harris //Reset the flag now since we are process the read log ext command now.
242f11c7f63SJim Harris pending_request->is_waiting_for_abort_task_set = FALSE;
243f11c7f63SJim Harris
244f11c7f63SJim Harris abort_status = scic_controller_terminate_request(
245f11c7f63SJim Harris fw_domain->controller->core_object,
246f11c7f63SJim Harris fw_device->core_object,
247f11c7f63SJim Harris pending_request->core_object
248f11c7f63SJim Harris );
249f11c7f63SJim Harris
250f11c7f63SJim Harris if (abort_status == SCI_FAILURE_INVALID_STATE)
251f11c7f63SJim Harris {
252f11c7f63SJim Harris //the request must have not be in aborting state anymore, complete it now.
253f11c7f63SJim Harris scif_cb_io_request_complete(
254f11c7f63SJim Harris fw_domain->controller,
255f11c7f63SJim Harris fw_device,
256f11c7f63SJim Harris pending_request,
2570f2a8452SJim Harris SCI_IO_FAILURE_TERMINATED
258f11c7f63SJim Harris );
259f11c7f63SJim Harris }
260f11c7f63SJim Harris //otherwise, the abort succeeded. Since the waiting flag is cleared,
261f11c7f63SJim Harris //the pending request will be completed later.
262f11c7f63SJim Harris }
263f11c7f63SJim Harris }
264f11c7f63SJim Harris #endif //#if !defined(DISABLE_SATI_TASK_MANAGEMENT)
265f11c7f63SJim Harris }
266