2 * SPDX-License-Identifier: BSD-2-Clause
6 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
13 * * Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * * Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 #include <sys/cdefs.h>
34 __FBSDID("$FreeBSD$");
36 #include <dev/isci/isci.h>
38 #include <dev/isci/scil/scif_controller.h>
39 #include <dev/isci/scil/scif_user_callback.h>
42 * @brief This user callback will inform the user that a task management
45 * @param[in] controller This parameter specifies the controller on
46 * which the task management request is completing.
47 * @param[in] remote_device This parameter specifies the remote device on
48 * which this task management request is completing.
49 * @param[in] task_request This parameter specifies the task management
50 * request that has completed.
51 * @param[in] completion_status This parameter specifies the results of
52 * the IO request operation. SCI_TASK_SUCCESS indicates
53 * successful completion.
58 scif_cb_task_request_complete(SCI_CONTROLLER_HANDLE_T controller,
59 SCI_REMOTE_DEVICE_HANDLE_T remote_device,
60 SCI_TASK_REQUEST_HANDLE_T task_request, SCI_TASK_STATUS completion_status)
63 scif_controller_complete_task(controller, remote_device, task_request);
64 isci_task_request_complete(controller, remote_device, task_request,
69 * @brief This method returns the Logical Unit to be utilized for this
70 * task management request.
72 * @note The contents of the value returned from this callback are defined
73 * by the protocol standard (e.g. T10 SAS specification). Please
74 * refer to the transport task information unit description
75 * in the associated standard.
77 * @param[in] scif_user_task_request This parameter points to the user's
78 * task request object. It is a cookie that allows the user to
79 * provide the necessary information for this callback.
81 * @return This method returns the LUN associated with this request.
82 * @todo This should be U64?
85 scif_cb_task_request_get_lun(void * scif_user_task_request)
88 /* Currently we are only doing hard resets, not LUN resets. So
89 * always returning 0 is OK here, since LUN doesn't matter for
90 * a hard device reset.
96 * @brief This method returns the task management function to be utilized
97 * for this task request.
99 * @note The contents of the value returned from this callback are defined
100 * by the protocol standard (e.g. T10 SAS specification). Please
101 * refer to the transport task information unit description
102 * in the associated standard.
104 * @param[in] scif_user_task_request This parameter points to the user's
105 * task request object. It is a cookie that allows the user to
106 * provide the necessary information for this callback.
108 * @return This method returns an unsigned byte representing the task
109 * management function to be performed.
111 uint8_t scif_cb_task_request_get_function(void * scif_user_task_request)
113 /* SCIL supports many types of task management functions, but this
114 * driver only uses HARD_RESET.
116 return (SCI_SAS_HARD_RESET);
120 * @brief This method returns the task management IO tag to be managed.
121 * Depending upon the task management function the value returned
122 * from this method may be ignored.
124 * @param[in] scif_user_task_request This parameter points to the user's
125 * task request object. It is a cookie that allows the user to
126 * provide the necessary information for this callback.
128 * @return This method returns an unsigned 16-bit word depicting the IO
132 scif_cb_task_request_get_io_tag_to_manage(void * scif_user_task_request)
139 * @brief This callback method asks the user to provide the virtual
140 * address of the response data buffer for the supplied IO request.
142 * @param[in] scif_user_task_request This parameter points to the user's
143 * task request object. It is a cookie that allows the user to
144 * provide the necessary information for this callback.
146 * @return This method returns the virtual address for the response data buffer
147 * associated with this IO request.
150 scif_cb_task_request_get_response_data_address(void * scif_user_task_request)
152 struct ISCI_TASK_REQUEST *task_request =
153 (struct ISCI_TASK_REQUEST *)scif_user_task_request;
155 return (&task_request->sense_data);
159 * @brief This callback method asks the user to provide the length of the
160 * response data buffer for the supplied IO request.
162 * @param[in] scif_user_task_request This parameter points to the user's
163 * task request object. It is a cookie that allows the user to
164 * provide the necessary information for this callback.
166 * @return This method returns the length of the response buffer data
167 * associated with this IO request.
170 scif_cb_task_request_get_response_data_length(void * scif_user_task_request)
173 return (sizeof(struct scsi_sense_data));
177 isci_task_request_complete(SCI_CONTROLLER_HANDLE_T scif_controller,
178 SCI_REMOTE_DEVICE_HANDLE_T remote_device,
179 SCI_TASK_REQUEST_HANDLE_T task_request, SCI_TASK_STATUS completion_status)
181 struct ISCI_TASK_REQUEST *isci_task_request =
182 (struct ISCI_TASK_REQUEST *)sci_object_get_association(task_request);
183 struct ISCI_CONTROLLER *isci_controller =
184 (struct ISCI_CONTROLLER *)sci_object_get_association(scif_controller);
185 struct ISCI_REMOTE_DEVICE *isci_remote_device =
186 (struct ISCI_REMOTE_DEVICE *)sci_object_get_association(remote_device);
187 struct ISCI_REMOTE_DEVICE *pending_remote_device;
188 BOOL retry_task = FALSE;
189 union ccb *ccb = isci_task_request->ccb;
191 isci_remote_device->is_resetting = FALSE;
193 switch ((int)completion_status) {
194 case SCI_TASK_SUCCESS:
195 case SCI_TASK_FAILURE_RESPONSE_VALID:
198 case SCI_TASK_FAILURE_INVALID_STATE:
200 isci_log_message(0, "ISCI",
201 "task failure (invalid state) - retrying\n");
204 case SCI_TASK_FAILURE_INSUFFICIENT_RESOURCES:
206 isci_log_message(0, "ISCI",
207 "task failure (insufficient resources) - retrying\n");
210 case SCI_FAILURE_TIMEOUT:
211 if (isci_controller->fail_on_task_timeout) {
213 isci_log_message(0, "ISCI",
214 "task timeout - not retrying\n");
215 scif_cb_domain_device_removed(scif_controller,
216 isci_remote_device->domain->sci_object,
220 isci_log_message(0, "ISCI",
221 "task timeout - retrying\n");
225 case SCI_TASK_FAILURE:
226 case SCI_TASK_FAILURE_UNSUPPORTED_PROTOCOL:
227 case SCI_TASK_FAILURE_INVALID_TAG:
228 case SCI_TASK_FAILURE_CONTROLLER_SPECIFIC_ERR:
229 case SCI_TASK_FAILURE_TERMINATED:
230 case SCI_TASK_FAILURE_INVALID_PARAMETER_VALUE:
231 isci_log_message(0, "ISCI",
232 "unhandled task completion code 0x%x\n", completion_status);
236 isci_log_message(0, "ISCI",
237 "unhandled task completion code 0x%x\n", completion_status);
241 if (isci_controller->is_frozen == TRUE) {
242 isci_controller->is_frozen = FALSE;
243 xpt_release_simq(isci_controller->sim, TRUE);
246 sci_pool_put(isci_controller->request_pool,
247 (struct ISCI_REQUEST *)isci_task_request);
249 /* Make sure we release the device queue, since it may have been frozen
250 * if someone tried to start an I/O while the task was in progress.
252 isci_remote_device_release_device_queue(isci_remote_device);
254 if (retry_task == TRUE)
255 isci_remote_device_reset(isci_remote_device, ccb);
257 pending_remote_device = sci_fast_list_remove_head(
258 &isci_controller->pending_device_reset_list);
260 if (pending_remote_device != NULL) {
261 /* Any resets that were triggered from an XPT_RESET_DEV
262 * CCB are never put in the pending list if the request
263 * pool is empty - they are given back to CAM to be
264 * requeued. So we will alawys pass NULL here,
265 * denoting that there is no CCB associated with the
268 isci_remote_device_reset(pending_remote_device, NULL);
269 } else if (ccb != NULL) {
270 /* There was a CCB associated with this reset, so mark
271 * it complete and return it to CAM.
273 ccb->ccb_h.status &= ~CAM_STATUS_MASK;
274 ccb->ccb_h.status |= CAM_REQ_CMP;