xref: /freebsd/sys/dev/isci/scil/scif_sas_request.c (revision 685dc743dc3b5645e34836464128e1c0558b404b)
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 /**
57f11c7f63SJim Harris  * @file
58f11c7f63SJim Harris  *
59f11c7f63SJim Harris  * @brief This file contains the implementation of the SCIF_SAS_REQUEST
60f11c7f63SJim Harris  *        object.  The SCIF_SAS_REQUEST object provides data and methods
61f11c7f63SJim Harris  *        that are common to both IO requests and task management requests.
62f11c7f63SJim Harris  */
63f11c7f63SJim Harris 
64f11c7f63SJim Harris 
65f11c7f63SJim Harris #include <dev/isci/scil/scic_controller.h>
66f11c7f63SJim Harris 
67f11c7f63SJim Harris #include <dev/isci/scil/scif_sas_request.h>
68f11c7f63SJim Harris #include <dev/isci/scil/scif_sas_task_request.h>
69f11c7f63SJim Harris #include <dev/isci/scil/scif_sas_controller.h>
70f11c7f63SJim Harris #include <dev/isci/scil/scif_sas_domain.h>
71f11c7f63SJim Harris #include <dev/isci/scil/scif_sas_remote_device.h>
72f11c7f63SJim Harris 
73f11c7f63SJim Harris #include <dev/isci/scil/scif_sas_logger.h>
74f11c7f63SJim Harris 
75f11c7f63SJim Harris //******************************************************************************
76f11c7f63SJim Harris //* P R O T E C T E D   M E T H O D S
77f11c7f63SJim Harris //******************************************************************************
78f11c7f63SJim Harris 
79f11c7f63SJim Harris /**
80f11c7f63SJim Harris  * @brief This method constructs the SCIF_SAS_REQUEST object.
81f11c7f63SJim Harris  *
82f11c7f63SJim Harris  * @param[in] fw_request This parameter specifies the request object to
83f11c7f63SJim Harris  *            be constructed.
84f11c7f63SJim Harris  * @param[in] fw_device This parameter specifies the remote device object
85f11c7f63SJim Harris  *            to which this request is destined.
86f11c7f63SJim Harris  * @param[in] logger This parameter specifies the logger associated with
87f11c7f63SJim Harris  *            this base request object.
88f11c7f63SJim Harris  * @param[in] state_table This parameter specifies the table of state
89f11c7f63SJim Harris  *            definitions to be utilized for the request state machine.
90f11c7f63SJim Harris  *
91f11c7f63SJim Harris  * @return none
92f11c7f63SJim Harris  */
scif_sas_request_construct(SCIF_SAS_REQUEST_T * fw_request,SCIF_SAS_REMOTE_DEVICE_T * fw_device,SCI_BASE_LOGGER_T * logger,SCI_BASE_STATE_T * state_table)93f11c7f63SJim Harris void scif_sas_request_construct(
94f11c7f63SJim Harris    SCIF_SAS_REQUEST_T       * fw_request,
95f11c7f63SJim Harris    SCIF_SAS_REMOTE_DEVICE_T * fw_device,
96f11c7f63SJim Harris    SCI_BASE_LOGGER_T        * logger,
97f11c7f63SJim Harris    SCI_BASE_STATE_T         * state_table
98f11c7f63SJim Harris )
99f11c7f63SJim Harris {
100f11c7f63SJim Harris    sci_base_request_construct(&fw_request->parent, logger, state_table);
101f11c7f63SJim Harris 
102f11c7f63SJim Harris    SCIF_LOG_TRACE((
103f11c7f63SJim Harris       sci_base_object_get_logger(fw_request),
104f11c7f63SJim Harris       SCIF_LOG_OBJECT_TASK_MANAGEMENT,
105f11c7f63SJim Harris       "scif_sas_request_construct(0x%x, 0x%x, 0x%x, 0x%x) enter\n",
106f11c7f63SJim Harris       fw_request, fw_device, logger, state_table
107f11c7f63SJim Harris    ));
108f11c7f63SJim Harris 
109f11c7f63SJim Harris    fw_request->device                    = fw_device;
110f11c7f63SJim Harris    fw_request->is_internal               = FALSE;
111f11c7f63SJim Harris    fw_request->lun                       = 0;
112f11c7f63SJim Harris    fw_request->terminate_requestor       = NULL;
113f11c7f63SJim Harris    fw_request->protocol_complete_handler = NULL;
114f11c7f63SJim Harris    fw_request->is_high_priority          = FALSE;
115f11c7f63SJim Harris    fw_request->is_waiting_for_abort_task_set = FALSE;
116f11c7f63SJim Harris 
117f11c7f63SJim Harris    sci_fast_list_element_init(fw_request, &fw_request->list_element);
118f11c7f63SJim Harris }
119f11c7f63SJim Harris 
120f11c7f63SJim Harris /**
121f11c7f63SJim Harris  * @brief This method will request the SCI core to terminate the supplied
122f11c7f63SJim Harris  *        request.
123f11c7f63SJim Harris  *
124f11c7f63SJim Harris  * @param[in] fw_request This parameter specifies the request to be terminated.
125f11c7f63SJim Harris  * @param[in] core_request This parameter specifies the core request (IO or
126f11c7f63SJim Harris  *            task) to be terminated.
127f11c7f63SJim Harris  *
128f11c7f63SJim Harris  * @return This method returns the status of the core termination operation.
129f11c7f63SJim Harris  */
scif_sas_request_terminate_start(SCIF_SAS_REQUEST_T * fw_request,SCI_IO_REQUEST_HANDLE_T core_request)130f11c7f63SJim Harris SCI_STATUS scif_sas_request_terminate_start(
131f11c7f63SJim Harris    SCIF_SAS_REQUEST_T      * fw_request,
132f11c7f63SJim Harris    SCI_IO_REQUEST_HANDLE_T   core_request
133f11c7f63SJim Harris )
134f11c7f63SJim Harris {
135f11c7f63SJim Harris    SCIF_LOG_TRACE((
136f11c7f63SJim Harris       sci_base_object_get_logger(fw_request),
137f11c7f63SJim Harris       SCIF_LOG_OBJECT_TASK_MANAGEMENT,
138f11c7f63SJim Harris       "scif_sas_request_terminate_start(0x%x) enter\n",
139f11c7f63SJim Harris       fw_request
140f11c7f63SJim Harris    ));
141f11c7f63SJim Harris 
142f11c7f63SJim Harris    // Only increment the affected request count if this request is being
143f11c7f63SJim Harris    // terminated at the behest of a task management request.
144f11c7f63SJim Harris    if (fw_request->terminate_requestor != NULL)
145f11c7f63SJim Harris       fw_request->terminate_requestor->affected_request_count++;
146f11c7f63SJim Harris 
147f11c7f63SJim Harris    return scic_controller_terminate_request(
148f11c7f63SJim Harris              fw_request->device->domain->controller->core_object,
149f11c7f63SJim Harris              fw_request->device->core_object,
150f11c7f63SJim Harris              core_request
151f11c7f63SJim Harris           );
152f11c7f63SJim Harris }
153f11c7f63SJim Harris 
154f11c7f63SJim Harris /**
155f11c7f63SJim Harris  * @brief This method will perform termination completion processing for
156f11c7f63SJim Harris  *        the supplied request.  This includes updated the affected
157f11c7f63SJim Harris  *        request count, if a task management request is what generated
158f11c7f63SJim Harris  *        this termination.  Also, this method will attempt to transition
159f11c7f63SJim Harris  *        to the READY OPERATIONAL state if this represents the last
160f11c7f63SJim Harris  *        affected request.
161f11c7f63SJim Harris  *
162f11c7f63SJim Harris  * @param[in] fw_request This parameter specifies the request for which to
163f11c7f63SJim Harris  *            perform termination completion processing.
164f11c7f63SJim Harris  *
165f11c7f63SJim Harris  * @return none
166f11c7f63SJim Harris  */
scif_sas_request_terminate_complete(SCIF_SAS_REQUEST_T * fw_request)167f11c7f63SJim Harris void scif_sas_request_terminate_complete(
168f11c7f63SJim Harris    SCIF_SAS_REQUEST_T * fw_request
169f11c7f63SJim Harris )
170f11c7f63SJim Harris {
171f11c7f63SJim Harris    SCIF_LOG_TRACE((
172f11c7f63SJim Harris       sci_base_object_get_logger(fw_request),
173f11c7f63SJim Harris       SCIF_LOG_OBJECT_TASK_MANAGEMENT,
174f11c7f63SJim Harris       "scif_sas_request_terminate_complete(0x%x) enter\n",
175f11c7f63SJim Harris       fw_request
176f11c7f63SJim Harris    ));
177f11c7f63SJim Harris 
178f11c7f63SJim Harris    // For requests that were terminated due to a task management request,
179f11c7f63SJim Harris    // check to see if the task management request has completed.
180f11c7f63SJim Harris    if (fw_request->terminate_requestor != NULL)
181f11c7f63SJim Harris       scif_sas_task_request_operation_complete(fw_request->terminate_requestor);
182f11c7f63SJim Harris }
183f11c7f63SJim Harris 
184