xref: /freebsd/sys/dev/isci/scil/scif_sas_request.c (revision 1d386b48a555f61cb7325543adbbb5c3f3407a66)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause OR GPL-2.0
3  *
4  * This file is provided under a dual BSD/GPLv2 license.  When using or
5  * redistributing this file, you may do so under either license.
6  *
7  * GPL LICENSE SUMMARY
8  *
9  * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of version 2 of the GNU General Public License as
13  * published by the Free Software Foundation.
14  *
15  * This program is distributed in the hope that it will be useful, but
16  * WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18  * General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
23  * The full GNU General Public License is included in this distribution
24  * in the file called LICENSE.GPL.
25  *
26  * BSD LICENSE
27  *
28  * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
29  * All rights reserved.
30  *
31  * Redistribution and use in source and binary forms, with or without
32  * modification, are permitted provided that the following conditions
33  * are met:
34  *
35  *   * Redistributions of source code must retain the above copyright
36  *     notice, this list of conditions and the following disclaimer.
37  *   * Redistributions in binary form must reproduce the above copyright
38  *     notice, this list of conditions and the following disclaimer in
39  *     the documentation and/or other materials provided with the
40  *     distribution.
41  *
42  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
43  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
44  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
45  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
46  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
47  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
48  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
49  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
50  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
51  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
52  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
53  */
54 
55 #include <sys/cdefs.h>
56 /**
57  * @file
58  *
59  * @brief This file contains the implementation of the SCIF_SAS_REQUEST
60  *        object.  The SCIF_SAS_REQUEST object provides data and methods
61  *        that are common to both IO requests and task management requests.
62  */
63 
64 
65 #include <dev/isci/scil/scic_controller.h>
66 
67 #include <dev/isci/scil/scif_sas_request.h>
68 #include <dev/isci/scil/scif_sas_task_request.h>
69 #include <dev/isci/scil/scif_sas_controller.h>
70 #include <dev/isci/scil/scif_sas_domain.h>
71 #include <dev/isci/scil/scif_sas_remote_device.h>
72 
73 #include <dev/isci/scil/scif_sas_logger.h>
74 
75 //******************************************************************************
76 //* P R O T E C T E D   M E T H O D S
77 //******************************************************************************
78 
79 /**
80  * @brief This method constructs the SCIF_SAS_REQUEST object.
81  *
82  * @param[in] fw_request This parameter specifies the request object to
83  *            be constructed.
84  * @param[in] fw_device This parameter specifies the remote device object
85  *            to which this request is destined.
86  * @param[in] logger This parameter specifies the logger associated with
87  *            this base request object.
88  * @param[in] state_table This parameter specifies the table of state
89  *            definitions to be utilized for the request state machine.
90  *
91  * @return none
92  */
93 void scif_sas_request_construct(
94    SCIF_SAS_REQUEST_T       * fw_request,
95    SCIF_SAS_REMOTE_DEVICE_T * fw_device,
96    SCI_BASE_LOGGER_T        * logger,
97    SCI_BASE_STATE_T         * state_table
98 )
99 {
100    sci_base_request_construct(&fw_request->parent, logger, state_table);
101 
102    SCIF_LOG_TRACE((
103       sci_base_object_get_logger(fw_request),
104       SCIF_LOG_OBJECT_TASK_MANAGEMENT,
105       "scif_sas_request_construct(0x%x, 0x%x, 0x%x, 0x%x) enter\n",
106       fw_request, fw_device, logger, state_table
107    ));
108 
109    fw_request->device                    = fw_device;
110    fw_request->is_internal               = FALSE;
111    fw_request->lun                       = 0;
112    fw_request->terminate_requestor       = NULL;
113    fw_request->protocol_complete_handler = NULL;
114    fw_request->is_high_priority          = FALSE;
115    fw_request->is_waiting_for_abort_task_set = FALSE;
116 
117    sci_fast_list_element_init(fw_request, &fw_request->list_element);
118 }
119 
120 /**
121  * @brief This method will request the SCI core to terminate the supplied
122  *        request.
123  *
124  * @param[in] fw_request This parameter specifies the request to be terminated.
125  * @param[in] core_request This parameter specifies the core request (IO or
126  *            task) to be terminated.
127  *
128  * @return This method returns the status of the core termination operation.
129  */
130 SCI_STATUS scif_sas_request_terminate_start(
131    SCIF_SAS_REQUEST_T      * fw_request,
132    SCI_IO_REQUEST_HANDLE_T   core_request
133 )
134 {
135    SCIF_LOG_TRACE((
136       sci_base_object_get_logger(fw_request),
137       SCIF_LOG_OBJECT_TASK_MANAGEMENT,
138       "scif_sas_request_terminate_start(0x%x) enter\n",
139       fw_request
140    ));
141 
142    // Only increment the affected request count if this request is being
143    // terminated at the behest of a task management request.
144    if (fw_request->terminate_requestor != NULL)
145       fw_request->terminate_requestor->affected_request_count++;
146 
147    return scic_controller_terminate_request(
148              fw_request->device->domain->controller->core_object,
149              fw_request->device->core_object,
150              core_request
151           );
152 }
153 
154 /**
155  * @brief This method will perform termination completion processing for
156  *        the supplied request.  This includes updated the affected
157  *        request count, if a task management request is what generated
158  *        this termination.  Also, this method will attempt to transition
159  *        to the READY OPERATIONAL state if this represents the last
160  *        affected request.
161  *
162  * @param[in] fw_request This parameter specifies the request for which to
163  *            perform termination completion processing.
164  *
165  * @return none
166  */
167 void scif_sas_request_terminate_complete(
168    SCIF_SAS_REQUEST_T * fw_request
169 )
170 {
171    SCIF_LOG_TRACE((
172       sci_base_object_get_logger(fw_request),
173       SCIF_LOG_OBJECT_TASK_MANAGEMENT,
174       "scif_sas_request_terminate_complete(0x%x) enter\n",
175       fw_request
176    ));
177 
178    // For requests that were terminated due to a task management request,
179    // check to see if the task management request has completed.
180    if (fw_request->terminate_requestor != NULL)
181       scif_sas_task_request_operation_complete(fw_request->terminate_requestor);
182 }
183 
184