blob: c9ccd0b5ff53504b911c49f29b698c20de80621a [file] [log] [blame]
Dan Williams6f231dd2011-07-02 22:56:22 -07001/*
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 * * Neither the name of Intel Corporation nor the names of its
40 * contributors may be used to endorse or promote products derived
41 * from this software without specific prior written permission.
42 *
43 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
44 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
45 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
46 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
47 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
48 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
49 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
50 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
51 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
52 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
53 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
54 */
Artur Wojcikcc3dbd02011-05-04 07:58:16 +000055#ifndef _ISCI_TASK_H_
Dan Williams6f231dd2011-07-02 22:56:22 -070056#define _ISCI_TASK_H_
57
Jeff Skirvined8a72d2011-03-31 13:10:40 -070058#include <scsi/sas_ata.h>
Dan Williamsce2b3262011-05-08 15:49:15 -070059#include "host.h"
Jeff Skirvined8a72d2011-03-31 13:10:40 -070060
Jeff Skirvinb343dff2011-10-27 15:05:06 -070061#define ISCI_TERMINATION_TIMEOUT_MSEC 500
62
Dan Williams6f231dd2011-07-02 22:56:22 -070063struct isci_request;
Dan Williams6f231dd2011-07-02 22:56:22 -070064
65/**
66 * enum isci_tmf_cb_state - This enum defines the possible states in which the
67 * TMF callback function is invoked during the TMF execution process.
68 *
69 *
70 */
71enum isci_tmf_cb_state {
72
73 isci_tmf_init_state = 0,
74 isci_tmf_started,
75 isci_tmf_timed_out
76};
77
78/**
79 * enum isci_tmf_function_codes - This enum defines the possible preparations
80 * of task management requests.
81 *
82 *
83 */
84enum isci_tmf_function_codes {
85
86 isci_tmf_func_none = 0,
87 isci_tmf_ssp_task_abort = TMF_ABORT_TASK,
88 isci_tmf_ssp_lun_reset = TMF_LU_RESET,
89 isci_tmf_sata_srst_high = TMF_LU_RESET + 0x100, /* Non SCSI */
90 isci_tmf_sata_srst_low = TMF_LU_RESET + 0x101 /* Non SCSI */
91};
92/**
93 * struct isci_tmf - This class represents the task management object which
94 * acts as an interface to libsas for processing task management requests
95 *
96 *
97 */
98struct isci_tmf {
99
100 struct completion *complete;
101 enum sas_protocol proto;
102 union {
Dave Jiangaf5ae892011-05-04 17:53:24 -0700103 struct ssp_response_iu resp_iu;
Dan Williams6f231dd2011-07-02 22:56:22 -0700104 struct dev_to_host_fis d2h_fis;
Dan Williams360b03e2011-06-15 11:11:03 -0700105 u8 rsp_buf[SSP_RESP_IU_MAX_SIZE];
106 } resp;
Dan Williams6f231dd2011-07-02 22:56:22 -0700107 unsigned char lun[8];
108 u16 io_tag;
109 struct isci_remote_device *device;
110 enum isci_tmf_function_codes tmf_code;
111 int status;
112
Dan Williams6f231dd2011-07-02 22:56:22 -0700113 /* The optional callback function allows the user process to
114 * track the TMF transmit / timeout conditions.
115 */
116 void (*cb_state_func)(
117 enum isci_tmf_cb_state,
118 struct isci_tmf *, void *);
119 void *cb_data;
120
121};
122
Dave Jiangaf5ae892011-05-04 17:53:24 -0700123static inline void isci_print_tmf(struct isci_tmf *tmf)
Dan Williams6f231dd2011-07-02 22:56:22 -0700124{
125 if (SAS_PROTOCOL_SATA == tmf->proto)
126 dev_dbg(&tmf->device->isci_port->isci_host->pdev->dev,
127 "%s: status = %x\n"
128 "tmf->resp.d2h_fis.status = %x\n"
129 "tmf->resp.d2h_fis.error = %x\n",
130 __func__,
131 tmf->status,
132 tmf->resp.d2h_fis.status,
133 tmf->resp.d2h_fis.error);
134 else
135 dev_dbg(&tmf->device->isci_port->isci_host->pdev->dev,
136 "%s: status = %x\n"
137 "tmf->resp.resp_iu.data_present = %x\n"
138 "tmf->resp.resp_iu.status = %x\n"
139 "tmf->resp.resp_iu.data_length = %x\n"
140 "tmf->resp.resp_iu.data[0] = %x\n"
141 "tmf->resp.resp_iu.data[1] = %x\n"
142 "tmf->resp.resp_iu.data[2] = %x\n"
143 "tmf->resp.resp_iu.data[3] = %x\n",
144 __func__,
145 tmf->status,
Dave Jiangaf5ae892011-05-04 17:53:24 -0700146 tmf->resp.resp_iu.datapres,
Dan Williams6f231dd2011-07-02 22:56:22 -0700147 tmf->resp.resp_iu.status,
Dave Jiangaf5ae892011-05-04 17:53:24 -0700148 be32_to_cpu(tmf->resp.resp_iu.response_data_len),
149 tmf->resp.resp_iu.resp_data[0],
150 tmf->resp.resp_iu.resp_data[1],
151 tmf->resp.resp_iu.resp_data[2],
152 tmf->resp.resp_iu.resp_data[3]);
Dan Williams6f231dd2011-07-02 22:56:22 -0700153}
154
155
156int isci_task_execute_task(
157 struct sas_task *task,
158 int num,
159 gfp_t gfp_flags);
160
161int isci_task_abort_task(
162 struct sas_task *task);
163
164int isci_task_abort_task_set(
165 struct domain_device *d_device,
166 u8 *lun);
167
168int isci_task_clear_aca(
169 struct domain_device *d_device,
170 u8 *lun);
171
172int isci_task_clear_task_set(
173 struct domain_device *d_device,
174 u8 *lun);
175
176int isci_task_query_task(
177 struct sas_task *task);
178
179int isci_task_lu_reset(
180 struct domain_device *d_device,
181 u8 *lun);
182
183int isci_task_clear_nexus_port(
184 struct asd_sas_port *port);
185
186int isci_task_clear_nexus_ha(
187 struct sas_ha_struct *ha);
188
189int isci_task_I_T_nexus_reset(
190 struct domain_device *d_device);
191
192void isci_task_request_complete(
193 struct isci_host *isci_host,
194 struct isci_request *request,
195 enum sci_task_status completion_status);
196
197u16 isci_task_ssp_request_get_io_tag_to_manage(
198 struct isci_request *request);
199
200u8 isci_task_ssp_request_get_function(
201 struct isci_request *request);
202
Dan Williams6f231dd2011-07-02 22:56:22 -0700203
204void *isci_task_ssp_request_get_response_data_address(
205 struct isci_request *request);
206
207u32 isci_task_ssp_request_get_response_data_length(
208 struct isci_request *request);
209
210int isci_queuecommand(
211 struct scsi_cmnd *scsi_cmd,
212 void (*donefunc)(struct scsi_cmnd *));
213
214int isci_bus_reset_handler(struct scsi_cmnd *cmd);
215
Dan Williams6f231dd2011-07-02 22:56:22 -0700216/**
217 * enum isci_completion_selection - This enum defines the possible actions to
218 * take with respect to a given request's notification back to libsas.
219 *
220 *
221 */
222enum isci_completion_selection {
223
224 isci_perform_normal_io_completion, /* Normal notify (task_done) */
225 isci_perform_aborted_io_completion, /* No notification. */
226 isci_perform_error_io_completion /* Use sas_task_abort */
227};
228
229static inline void isci_set_task_doneflags(
230 struct sas_task *task)
231{
232 /* Since no futher action will be taken on this task,
233 * make sure to mark it complete from the lldd perspective.
234 */
235 task->task_state_flags |= SAS_TASK_STATE_DONE;
236 task->task_state_flags &= ~SAS_TASK_AT_INITIATOR;
237 task->task_state_flags &= ~SAS_TASK_STATE_PENDING;
238}
239/**
240 * isci_task_all_done() - This function clears the task bits to indicate the
241 * LLDD is done with the task.
242 *
243 *
244 */
245static inline void isci_task_all_done(
246 struct sas_task *task)
247{
248 unsigned long flags;
249
250 /* Since no futher action will be taken on this task,
251 * make sure to mark it complete from the lldd perspective.
252 */
253 spin_lock_irqsave(&task->task_state_lock, flags);
254 isci_set_task_doneflags(task);
255 spin_unlock_irqrestore(&task->task_state_lock, flags);
256}
257
258/**
259 * isci_task_set_completion_status() - This function sets the completion status
260 * for the request.
261 * @task: This parameter is the completed request.
262 * @response: This parameter is the response code for the completed task.
263 * @status: This parameter is the status code for the completed task.
264 *
Jeff Skirvinec6c9632011-03-04 14:06:44 -0800265* @return The new notification mode for the request.
266*/
267static inline enum isci_completion_selection
268isci_task_set_completion_status(
Dan Williams6f231dd2011-07-02 22:56:22 -0700269 struct sas_task *task,
270 enum service_response response,
271 enum exec_status status,
272 enum isci_completion_selection task_notification_selection)
273{
274 unsigned long flags;
275
276 spin_lock_irqsave(&task->task_state_lock, flags);
277
Jeff Skirvinec6c9632011-03-04 14:06:44 -0800278 /* If a device reset is being indicated, make sure the I/O
279 * is in the error path.
280 */
Jeff Skirvinaa145102011-03-07 16:40:47 -0700281 if (task->task_state_flags & SAS_TASK_NEED_DEV_RESET) {
Jeff Skirvinaa145102011-03-07 16:40:47 -0700282 /* Fail the I/O to make sure it goes into the error path. */
283 response = SAS_TASK_UNDELIVERED;
284 status = SAM_STAT_TASK_ABORTED;
285
Jeff Skirvinec6c9632011-03-04 14:06:44 -0800286 task_notification_selection = isci_perform_error_io_completion;
Jeff Skirvinaa145102011-03-07 16:40:47 -0700287 }
288 task->task_status.resp = response;
289 task->task_status.stat = status;
Jeff Skirvinec6c9632011-03-04 14:06:44 -0800290
Jeff Skirvincd06b9b2011-09-28 18:47:46 -0700291 switch (task->task_proto) {
292
293 case SAS_PROTOCOL_SATA:
294 case SAS_PROTOCOL_STP:
295 case SAS_PROTOCOL_SATA | SAS_PROTOCOL_STP:
296
297 if (task_notification_selection
298 == isci_perform_error_io_completion) {
299 /* SATA/STP I/O has it's own means of scheduling device
300 * error handling on the normal path.
301 */
302 task_notification_selection
303 = isci_perform_normal_io_completion;
304 }
305 break;
306 default:
307 break;
308 }
309
Jeff Skirvinec6c9632011-03-04 14:06:44 -0800310 switch (task_notification_selection) {
Jeff Skirvincde76fb2011-06-20 14:09:06 -0700311
312 case isci_perform_error_io_completion:
313
314 if (task->task_proto == SAS_PROTOCOL_SMP) {
315 /* There is no error escalation in the SMP case.
316 * Convert to a normal completion to avoid the
317 * timeout in the discovery path and to let the
318 * next action take place quickly.
319 */
320 task_notification_selection
321 = isci_perform_normal_io_completion;
322
323 /* Fall through to the normal case... */
324 } else {
325 /* Use sas_task_abort */
326 /* Leave SAS_TASK_STATE_DONE clear
327 * Leave SAS_TASK_AT_INITIATOR set.
328 */
329 break;
330 }
331
Dan Williamsce0b89f2011-03-17 08:04:43 -0700332 case isci_perform_aborted_io_completion:
333 /* This path can occur with task-managed requests as well as
334 * requests terminated because of LUN or device resets.
335 */
336 /* Fall through to the normal case... */
337 case isci_perform_normal_io_completion:
338 /* Normal notification (task_done) */
339 isci_set_task_doneflags(task);
340 break;
341 default:
342 WARN_ONCE(1, "unknown task_notification_selection: %d\n",
343 task_notification_selection);
Dan Williamsce0b89f2011-03-17 08:04:43 -0700344 break;
Jeff Skirvinec6c9632011-03-04 14:06:44 -0800345 }
Dan Williams6f231dd2011-07-02 22:56:22 -0700346
347 spin_unlock_irqrestore(&task->task_state_lock, flags);
Jeff Skirvinec6c9632011-03-04 14:06:44 -0800348
349 return task_notification_selection;
350
Dan Williams6f231dd2011-07-02 22:56:22 -0700351}
Jeff Skirvined8a72d2011-03-31 13:10:40 -0700352/**
353* isci_execpath_callback() - This function is called from the task
354* execute path when the task needs to callback libsas about the submit-time
355* task failure. The callback occurs either through the task's done function
356* or through sas_task_abort. In the case of regular non-discovery SATA/STP I/O
357* requests, libsas takes the host lock before calling execute task. Therefore
358* in this situation the host lock must be managed before calling the func.
359*
360* @ihost: This parameter is the controller to which the I/O request was sent.
361* @task: This parameter is the I/O request.
362* @func: This parameter is the function to call in the correct context.
363* @status: This parameter is the status code for the completed task.
364*
365*/
Dan Williams5b3f2bd2011-05-05 17:47:44 -0700366static inline void isci_execpath_callback(struct isci_host *ihost,
367 struct sas_task *task,
368 void (*func)(struct sas_task *))
Jeff Skirvined8a72d2011-03-31 13:10:40 -0700369{
Dan Williams5b3f2bd2011-05-05 17:47:44 -0700370 struct domain_device *dev = task->dev;
Jeff Skirvined8a72d2011-03-31 13:10:40 -0700371
Dan Williams5b3f2bd2011-05-05 17:47:44 -0700372 if (dev_is_sata(dev) && task->uldd_task) {
373 unsigned long flags;
374
Jeff Skirvined8a72d2011-03-31 13:10:40 -0700375 /* Since we are still in the submit path, and since
Dan Williams5b3f2bd2011-05-05 17:47:44 -0700376 * libsas takes the host lock on behalf of SATA
377 * devices before I/O starts (in the non-discovery case),
378 * we need to unlock before we can call the callback function.
379 */
Jeff Skirvined8a72d2011-03-31 13:10:40 -0700380 raw_local_irq_save(flags);
Dan Williams5b3f2bd2011-05-05 17:47:44 -0700381 spin_unlock(dev->sata_dev.ap->lock);
Jeff Skirvined8a72d2011-03-31 13:10:40 -0700382 func(task);
Dan Williams5b3f2bd2011-05-05 17:47:44 -0700383 spin_lock(dev->sata_dev.ap->lock);
Jeff Skirvined8a72d2011-03-31 13:10:40 -0700384 raw_local_irq_restore(flags);
385 } else
386 func(task);
387}
Dan Williams6f231dd2011-07-02 22:56:22 -0700388#endif /* !defined(_SCI_TASK_H_) */