scif_sas_request.c revision 331722
1/*-
2 * This file is provided under a dual BSD/GPLv2 license.  When using or
3 * redistributing this file, you may do so under either license.
4 *
5 * GPL LICENSE SUMMARY
6 *
7 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of version 2 of the GNU General Public License as
11 * published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
21 * The full GNU General Public License is included in this distribution
22 * in the file called LICENSE.GPL.
23 *
24 * BSD LICENSE
25 *
26 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
27 * All rights reserved.
28 *
29 * Redistribution and use in source and binary forms, with or without
30 * modification, are permitted provided that the following conditions
31 * are met:
32 *
33 *   * Redistributions of source code must retain the above copyright
34 *     notice, this list of conditions and the following disclaimer.
35 *   * Redistributions in binary form must reproduce the above copyright
36 *     notice, this list of conditions and the following disclaimer in
37 *     the documentation and/or other materials provided with the
38 *     distribution.
39 *
40 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
41 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
42 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
43 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
44 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
45 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
46 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
47 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
48 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
49 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
50 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
51 */
52
53#include <sys/cdefs.h>
54__FBSDID("$FreeBSD: stable/11/sys/dev/isci/scil/scif_sas_request.c 331722 2018-03-29 02:50:57Z eadler $");
55
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 */
93void 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 */
130SCI_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 */
167void 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