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