4 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #include <sys/cdefs.h>
32 __FBSDID("$FreeBSD$");
34 #include <dev/isci/isci.h>
36 #include <dev/isci/scil/scif_controller.h>
37 #include <dev/isci/scil/scif_user_callback.h>
40 * @brief This user callback will inform the user that a task management
43 * @param[in] controller This parameter specifies the controller on
44 * which the task management request is completing.
45 * @param[in] remote_device This parameter specifies the remote device on
46 * which this task management request is completing.
47 * @param[in] task_request This parameter specifies the task management
48 * request that has completed.
49 * @param[in] completion_status This parameter specifies the results of
50 * the IO request operation. SCI_TASK_SUCCESS indicates
51 * successful completion.
56 scif_cb_task_request_complete(SCI_CONTROLLER_HANDLE_T controller,
57 SCI_REMOTE_DEVICE_HANDLE_T remote_device,
58 SCI_TASK_REQUEST_HANDLE_T task_request, SCI_TASK_STATUS completion_status)
61 scif_controller_complete_task(controller, remote_device, task_request);
62 isci_task_request_complete(controller, remote_device, task_request,
67 * @brief This method returns the Logical Unit to be utilized for this
68 * task management request.
70 * @note The contents of the value returned from this callback are defined
71 * by the protocol standard (e.g. T10 SAS specification). Please
72 * refer to the transport task information unit description
73 * in the associated standard.
75 * @param[in] scif_user_task_request This parameter points to the user's
76 * task request object. It is a cookie that allows the user to
77 * provide the necessary information for this callback.
79 * @return This method returns the LUN associated with this request.
80 * @todo This should be U64?
83 scif_cb_task_request_get_lun(void * scif_user_task_request)
86 /* Currently we are only doing hard resets, not LUN resets. So
87 * always returning 0 is OK here, since LUN doesn't matter for
88 * a hard device reset.
94 * @brief This method returns the task management function to be utilized
95 * for this task request.
97 * @note The contents of the value returned from this callback are defined
98 * by the protocol standard (e.g. T10 SAS specification). Please
99 * refer to the transport task information unit description
100 * in the associated standard.
102 * @param[in] scif_user_task_request This parameter points to the user's
103 * task request object. It is a cookie that allows the user to
104 * provide the necessary information for this callback.
106 * @return This method returns an unsigned byte representing the task
107 * management function to be performed.
109 uint8_t scif_cb_task_request_get_function(void * scif_user_task_request)
111 /* SCIL supports many types of task management functions, but this
112 * driver only uses HARD_RESET.
114 return (SCI_SAS_HARD_RESET);
118 * @brief This method returns the task management IO tag to be managed.
119 * Depending upon the task management function the value returned
120 * from this method may be ignored.
122 * @param[in] scif_user_task_request This parameter points to the user's
123 * task request object. It is a cookie that allows the user to
124 * provide the necessary information for this callback.
126 * @return This method returns an unsigned 16-bit word depicting the IO
130 scif_cb_task_request_get_io_tag_to_manage(void * scif_user_task_request)
137 * @brief This callback method asks the user to provide the virtual
138 * address of the response data buffer for the supplied IO request.
140 * @param[in] scif_user_task_request This parameter points to the user's
141 * task request object. It is a cookie that allows the user to
142 * provide the necessary information for this callback.
144 * @return This method returns the virtual address for the response data buffer
145 * associated with this IO request.
148 scif_cb_task_request_get_response_data_address(void * scif_user_task_request)
150 struct ISCI_TASK_REQUEST *task_request =
151 (struct ISCI_TASK_REQUEST *)scif_user_task_request;
153 return (&task_request->sense_data);
157 * @brief This callback method asks the user to provide the length of the
158 * response data buffer for the supplied IO request.
160 * @param[in] scif_user_task_request This parameter points to the user's
161 * task request object. It is a cookie that allows the user to
162 * provide the necessary information for this callback.
164 * @return This method returns the length of the response buffer data
165 * associated with this IO request.
168 scif_cb_task_request_get_response_data_length(void * scif_user_task_request)
171 return (sizeof(struct scsi_sense_data));
175 isci_task_request_complete(SCI_CONTROLLER_HANDLE_T scif_controller,
176 SCI_REMOTE_DEVICE_HANDLE_T remote_device,
177 SCI_TASK_REQUEST_HANDLE_T task_request, SCI_TASK_STATUS completion_status)
179 struct ISCI_TASK_REQUEST *isci_task_request =
180 (struct ISCI_TASK_REQUEST *)sci_object_get_association(task_request);
181 struct ISCI_CONTROLLER *isci_controller =
182 (struct ISCI_CONTROLLER *)sci_object_get_association(scif_controller);
183 struct ISCI_REMOTE_DEVICE *isci_remote_device =
184 (struct ISCI_REMOTE_DEVICE *)sci_object_get_association(remote_device);
185 struct ISCI_REMOTE_DEVICE *pending_remote_device;
186 BOOL retry_task = FALSE;
187 union ccb *ccb = isci_task_request->ccb;
189 isci_remote_device->is_resetting = FALSE;
191 switch ((int)completion_status) {
192 case SCI_TASK_SUCCESS:
193 case SCI_TASK_FAILURE_RESPONSE_VALID:
196 case SCI_TASK_FAILURE_INVALID_STATE:
198 isci_log_message(0, "ISCI",
199 "task failure (invalid state) - retrying\n");
202 case SCI_TASK_FAILURE_INSUFFICIENT_RESOURCES:
204 isci_log_message(0, "ISCI",
205 "task failure (insufficient resources) - retrying\n");
208 case SCI_FAILURE_TIMEOUT:
210 isci_log_message(0, "ISCI", "task timeout - retrying\n");
213 case SCI_TASK_FAILURE:
214 case SCI_TASK_FAILURE_UNSUPPORTED_PROTOCOL:
215 case SCI_TASK_FAILURE_INVALID_TAG:
216 case SCI_TASK_FAILURE_CONTROLLER_SPECIFIC_ERR:
217 case SCI_TASK_FAILURE_TERMINATED:
218 case SCI_TASK_FAILURE_INVALID_PARAMETER_VALUE:
219 isci_log_message(0, "ISCI",
220 "unhandled task completion code 0x%x\n", completion_status);
224 isci_log_message(0, "ISCI",
225 "unhandled task completion code 0x%x\n", completion_status);
229 if (isci_controller->is_frozen == TRUE) {
230 isci_controller->is_frozen = FALSE;
231 xpt_release_simq(isci_controller->sim, TRUE);
234 sci_pool_put(isci_controller->request_pool,
235 (struct ISCI_REQUEST *)isci_task_request);
237 /* Make sure we release the device queue, since it may have been frozen
238 * if someone tried to start an I/O while the task was in progress.
240 isci_remote_device_release_device_queue(isci_remote_device);
242 if (retry_task == TRUE)
243 isci_remote_device_reset(isci_remote_device, ccb);
245 pending_remote_device = sci_fast_list_remove_head(
246 &isci_controller->pending_device_reset_list);
248 if (pending_remote_device != NULL) {
249 /* Any resets that were triggered from an XPT_RESET_DEV
250 * CCB are never put in the pending list if the request
251 * pool is empty - they are given back to CAM to be
252 * requeued. So we will alawys pass NULL here,
253 * denoting that there is no CCB associated with the
256 isci_remote_device_reset(pending_remote_device, NULL);
257 } else if (ccb != NULL) {
258 /* There was a CCB associated with this reset, so mark
259 * it complete and return it to CAM.
261 ccb->ccb_h.status &= ~CAM_STATUS_MASK;
262 ccb->ccb_h.status |= CAM_REQ_CMP;