c5afd1cfbde7a8f17cbcaf62f6a24fc0d20e7ee0
[deliverable/linux.git] / drivers / scsi / isci / task.h
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 * * 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 */
55
56 #if !defined(_ISCI_TASK_H_)
57 #define _ISCI_TASK_H_
58
59 #include <scsi/sas_ata.h>
60
61 struct isci_request;
62 struct isci_host;
63
64 /**
65 * enum isci_tmf_cb_state - This enum defines the possible states in which the
66 * TMF callback function is invoked during the TMF execution process.
67 *
68 *
69 */
70 enum isci_tmf_cb_state {
71
72 isci_tmf_init_state = 0,
73 isci_tmf_started,
74 isci_tmf_timed_out
75 };
76
77 /**
78 * enum isci_tmf_function_codes - This enum defines the possible preparations
79 * of task management requests.
80 *
81 *
82 */
83 enum isci_tmf_function_codes {
84
85 isci_tmf_func_none = 0,
86 isci_tmf_ssp_task_abort = TMF_ABORT_TASK,
87 isci_tmf_ssp_lun_reset = TMF_LU_RESET,
88 isci_tmf_sata_srst_high = TMF_LU_RESET + 0x100, /* Non SCSI */
89 isci_tmf_sata_srst_low = TMF_LU_RESET + 0x101 /* Non SCSI */
90 };
91 /**
92 * struct isci_tmf - This class represents the task management object which
93 * acts as an interface to libsas for processing task management requests
94 *
95 *
96 */
97 struct isci_tmf {
98
99 struct completion *complete;
100 enum sas_protocol proto;
101 union {
102 struct sci_ssp_response_iu resp_iu;
103 struct dev_to_host_fis d2h_fis;
104 } resp;
105 unsigned char lun[8];
106 u16 io_tag;
107 struct isci_remote_device *device;
108 enum isci_tmf_function_codes tmf_code;
109 int status;
110
111 struct isci_timer *timeout_timer;
112
113 /* 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
123 static inline void isci_print_tmf(
124 struct isci_tmf *tmf)
125 {
126 if (SAS_PROTOCOL_SATA == tmf->proto)
127 dev_dbg(&tmf->device->isci_port->isci_host->pdev->dev,
128 "%s: status = %x\n"
129 "tmf->resp.d2h_fis.status = %x\n"
130 "tmf->resp.d2h_fis.error = %x\n",
131 __func__,
132 tmf->status,
133 tmf->resp.d2h_fis.status,
134 tmf->resp.d2h_fis.error);
135 else
136 dev_dbg(&tmf->device->isci_port->isci_host->pdev->dev,
137 "%s: status = %x\n"
138 "tmf->resp.resp_iu.data_present = %x\n"
139 "tmf->resp.resp_iu.status = %x\n"
140 "tmf->resp.resp_iu.data_length = %x\n"
141 "tmf->resp.resp_iu.data[0] = %x\n"
142 "tmf->resp.resp_iu.data[1] = %x\n"
143 "tmf->resp.resp_iu.data[2] = %x\n"
144 "tmf->resp.resp_iu.data[3] = %x\n",
145 __func__,
146 tmf->status,
147 tmf->resp.resp_iu.data_present,
148 tmf->resp.resp_iu.status,
149 (tmf->resp.resp_iu.response_data_length[0] << 24) +
150 (tmf->resp.resp_iu.response_data_length[1] << 16) +
151 (tmf->resp.resp_iu.response_data_length[2] << 8) +
152 tmf->resp.resp_iu.response_data_length[3],
153 tmf->resp.resp_iu.data[0],
154 tmf->resp.resp_iu.data[1],
155 tmf->resp.resp_iu.data[2],
156 tmf->resp.resp_iu.data[3]);
157 }
158
159
160 int isci_task_execute_task(
161 struct sas_task *task,
162 int num,
163 gfp_t gfp_flags);
164
165 int isci_task_abort_task(
166 struct sas_task *task);
167
168 int isci_task_abort_task_set(
169 struct domain_device *d_device,
170 u8 *lun);
171
172 int isci_task_clear_aca(
173 struct domain_device *d_device,
174 u8 *lun);
175
176 int isci_task_clear_task_set(
177 struct domain_device *d_device,
178 u8 *lun);
179
180 int isci_task_query_task(
181 struct sas_task *task);
182
183 int isci_task_lu_reset(
184 struct domain_device *d_device,
185 u8 *lun);
186
187 int isci_task_clear_nexus_port(
188 struct asd_sas_port *port);
189
190 int isci_task_clear_nexus_ha(
191 struct sas_ha_struct *ha);
192
193 int isci_task_I_T_nexus_reset(
194 struct domain_device *d_device);
195
196 void isci_task_request_complete(
197 struct isci_host *isci_host,
198 struct isci_request *request,
199 enum sci_task_status completion_status);
200
201 u16 isci_task_ssp_request_get_io_tag_to_manage(
202 struct isci_request *request);
203
204 u8 isci_task_ssp_request_get_function(
205 struct isci_request *request);
206
207
208 void *isci_task_ssp_request_get_response_data_address(
209 struct isci_request *request);
210
211 u32 isci_task_ssp_request_get_response_data_length(
212 struct isci_request *request);
213
214 int isci_queuecommand(
215 struct scsi_cmnd *scsi_cmd,
216 void (*donefunc)(struct scsi_cmnd *));
217
218 int isci_bus_reset_handler(struct scsi_cmnd *cmd);
219
220 void isci_task_build_tmf(
221 struct isci_tmf *tmf,
222 struct isci_remote_device *isci_device,
223 enum isci_tmf_function_codes code,
224 void (*tmf_sent_cb)(enum isci_tmf_cb_state,
225 struct isci_tmf *,
226 void *),
227 void *cb_data);
228
229
230 int isci_task_execute_tmf(
231 struct isci_host *isci_host,
232 struct isci_tmf *tmf,
233 unsigned long timeout_ms);
234
235 /**
236 * enum isci_completion_selection - This enum defines the possible actions to
237 * take with respect to a given request's notification back to libsas.
238 *
239 *
240 */
241 enum isci_completion_selection {
242
243 isci_perform_normal_io_completion, /* Normal notify (task_done) */
244 isci_perform_aborted_io_completion, /* No notification. */
245 isci_perform_error_io_completion /* Use sas_task_abort */
246 };
247
248 static inline void isci_set_task_doneflags(
249 struct sas_task *task)
250 {
251 /* Since no futher action will be taken on this task,
252 * make sure to mark it complete from the lldd perspective.
253 */
254 task->task_state_flags |= SAS_TASK_STATE_DONE;
255 task->task_state_flags &= ~SAS_TASK_AT_INITIATOR;
256 task->task_state_flags &= ~SAS_TASK_STATE_PENDING;
257 }
258 /**
259 * isci_task_all_done() - This function clears the task bits to indicate the
260 * LLDD is done with the task.
261 *
262 *
263 */
264 static inline void isci_task_all_done(
265 struct sas_task *task)
266 {
267 unsigned long flags;
268
269 /* Since no futher action will be taken on this task,
270 * make sure to mark it complete from the lldd perspective.
271 */
272 spin_lock_irqsave(&task->task_state_lock, flags);
273 isci_set_task_doneflags(task);
274 spin_unlock_irqrestore(&task->task_state_lock, flags);
275 }
276
277 /**
278 * isci_task_set_completion_status() - This function sets the completion status
279 * for the request.
280 * @task: This parameter is the completed request.
281 * @response: This parameter is the response code for the completed task.
282 * @status: This parameter is the status code for the completed task.
283 *
284 * @return The new notification mode for the request.
285 */
286 static inline enum isci_completion_selection
287 isci_task_set_completion_status(
288 struct sas_task *task,
289 enum service_response response,
290 enum exec_status status,
291 enum isci_completion_selection task_notification_selection)
292 {
293 unsigned long flags;
294
295 spin_lock_irqsave(&task->task_state_lock, flags);
296
297 /* If a device reset is being indicated, make sure the I/O
298 * is in the error path.
299 */
300 if (task->task_state_flags & SAS_TASK_NEED_DEV_RESET) {
301 /* Fail the I/O to make sure it goes into the error path. */
302 response = SAS_TASK_UNDELIVERED;
303 status = SAM_STAT_TASK_ABORTED;
304
305 task_notification_selection = isci_perform_error_io_completion;
306 }
307 task->task_status.resp = response;
308 task->task_status.stat = status;
309
310 switch (task_notification_selection) {
311 case isci_perform_aborted_io_completion:
312 /* This path can occur with task-managed requests as well as
313 * requests terminated because of LUN or device resets.
314 */
315 /* Fall through to the normal case... */
316 case isci_perform_normal_io_completion:
317 /* Normal notification (task_done) */
318 isci_set_task_doneflags(task);
319 break;
320 default:
321 WARN_ONCE(1, "unknown task_notification_selection: %d\n",
322 task_notification_selection);
323 /* Fall through to the error case... */
324 case isci_perform_error_io_completion:
325 /* Use sas_task_abort */
326 /* Leave SAS_TASK_STATE_DONE clear
327 * Leave SAS_TASK_AT_INITIATOR set.
328 */
329 break;
330 }
331
332 spin_unlock_irqrestore(&task->task_state_lock, flags);
333
334 return task_notification_selection;
335
336 }
337 /**
338 * isci_execpath_callback() - This function is called from the task
339 * execute path when the task needs to callback libsas about the submit-time
340 * task failure. The callback occurs either through the task's done function
341 * or through sas_task_abort. In the case of regular non-discovery SATA/STP I/O
342 * requests, libsas takes the host lock before calling execute task. Therefore
343 * in this situation the host lock must be managed before calling the func.
344 *
345 * @ihost: This parameter is the controller to which the I/O request was sent.
346 * @task: This parameter is the I/O request.
347 * @func: This parameter is the function to call in the correct context.
348 * @status: This parameter is the status code for the completed task.
349 *
350 */
351 static inline void isci_execpath_callback(
352 struct isci_host *ihost,
353 struct sas_task *task,
354 void (*func)(struct sas_task *))
355 {
356 unsigned long flags;
357
358 if (dev_is_sata(task->dev) && task->uldd_task) {
359 /* Since we are still in the submit path, and since
360 * libsas takes the host lock on behalf of SATA
361 * devices before I/O starts (in the non-discovery case),
362 * we need to unlock before we can call the callback function.
363 */
364 raw_local_irq_save(flags);
365 spin_unlock(ihost->shost->host_lock);
366 func(task);
367 spin_lock(ihost->shost->host_lock);
368 raw_local_irq_restore(flags);
369 } else
370 func(task);
371 }
372
373 #endif /* !defined(_SCI_TASK_H_) */
This page took 0.046134 seconds and 4 git commands to generate.