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