James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Serial Attached SCSI (SAS) class SCSI Host glue. |
| 3 | * |
| 4 | * Copyright (C) 2005 Adaptec, Inc. All rights reserved. |
| 5 | * Copyright (C) 2005 Luben Tuikov <luben_tuikov@adaptec.com> |
| 6 | * |
| 7 | * This file is licensed under GPLv2. |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or |
| 10 | * modify it under the terms of the GNU General Public License as |
| 11 | * published by the Free Software Foundation; either version 2 of the |
| 12 | * License, or (at your option) any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, but |
| 15 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 17 | * General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License |
| 20 | * along with this program; if not, write to the Free Software |
| 21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
| 22 | * USA |
| 23 | * |
| 24 | */ |
| 25 | |
Christoph Hellwig | d7a54e3 | 2007-04-26 09:38:01 -0400 | [diff] [blame] | 26 | #include <linux/kthread.h> |
Darrick J. Wong | 45e6cdf | 2008-02-19 10:49:40 -0800 | [diff] [blame] | 27 | #include <linux/firmware.h> |
| 28 | #include <linux/ctype.h> |
Christoph Hellwig | d7a54e3 | 2007-04-26 09:38:01 -0400 | [diff] [blame] | 29 | |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 30 | #include "sas_internal.h" |
| 31 | |
| 32 | #include <scsi/scsi_host.h> |
| 33 | #include <scsi/scsi_device.h> |
| 34 | #include <scsi/scsi_tcq.h> |
| 35 | #include <scsi/scsi.h> |
Darrick J. Wong | f456393 | 2006-10-30 15:18:39 -0800 | [diff] [blame] | 36 | #include <scsi/scsi_eh.h> |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 37 | #include <scsi/scsi_transport.h> |
| 38 | #include <scsi/scsi_transport_sas.h> |
Darrick J. Wong | 338ec57 | 2006-10-18 14:43:37 -0700 | [diff] [blame] | 39 | #include <scsi/sas_ata.h> |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 40 | #include "../scsi_sas_internal.h" |
Darrick J. Wong | 79a5eb6 | 2006-10-30 15:18:50 -0800 | [diff] [blame] | 41 | #include "../scsi_transport_api.h" |
Darrick J. Wong | ad68923 | 2007-01-26 14:08:52 -0800 | [diff] [blame] | 42 | #include "../scsi_priv.h" |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 43 | |
| 44 | #include <linux/err.h> |
| 45 | #include <linux/blkdev.h> |
Rafael J. Wysocki | 8314418 | 2007-07-17 04:03:35 -0700 | [diff] [blame] | 46 | #include <linux/freezer.h> |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 47 | #include <linux/scatterlist.h> |
Darrick J. Wong | fa1c1e8 | 2006-08-10 19:19:47 -0700 | [diff] [blame] | 48 | #include <linux/libata.h> |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 49 | |
| 50 | /* ---------- SCSI Host glue ---------- */ |
| 51 | |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 52 | static void sas_scsi_task_done(struct sas_task *task) |
| 53 | { |
| 54 | struct task_status_struct *ts = &task->task_status; |
| 55 | struct scsi_cmnd *sc = task->uldd_task; |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 56 | int hs = 0, stat = 0; |
| 57 | |
James Bottomley | a8e14fe | 2008-02-19 21:48:42 -0600 | [diff] [blame] | 58 | if (unlikely(task->task_state_flags & SAS_TASK_STATE_ABORTED)) { |
| 59 | /* Aborted tasks will be completed by the error handler */ |
| 60 | SAS_DPRINTK("task done but aborted\n"); |
| 61 | return; |
| 62 | } |
| 63 | |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 64 | if (unlikely(!sc)) { |
| 65 | SAS_DPRINTK("task_done called with non existing SCSI cmnd!\n"); |
| 66 | list_del_init(&task->list); |
| 67 | sas_free_task(task); |
| 68 | return; |
| 69 | } |
| 70 | |
| 71 | if (ts->resp == SAS_TASK_UNDELIVERED) { |
| 72 | /* transport error */ |
| 73 | hs = DID_NO_CONNECT; |
| 74 | } else { /* ts->resp == SAS_TASK_COMPLETE */ |
| 75 | /* task delivered, what happened afterwards? */ |
| 76 | switch (ts->stat) { |
| 77 | case SAS_DEV_NO_RESPONSE: |
| 78 | case SAS_INTERRUPTED: |
| 79 | case SAS_PHY_DOWN: |
| 80 | case SAS_NAK_R_ERR: |
| 81 | case SAS_OPEN_TO: |
| 82 | hs = DID_NO_CONNECT; |
| 83 | break; |
| 84 | case SAS_DATA_UNDERRUN: |
FUJITA Tomonori | c13e556 | 2007-05-26 02:46:37 +0900 | [diff] [blame] | 85 | scsi_set_resid(sc, ts->residual); |
| 86 | if (scsi_bufflen(sc) - scsi_get_resid(sc) < sc->underflow) |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 87 | hs = DID_ERROR; |
| 88 | break; |
| 89 | case SAS_DATA_OVERRUN: |
| 90 | hs = DID_ERROR; |
| 91 | break; |
| 92 | case SAS_QUEUE_FULL: |
| 93 | hs = DID_SOFT_ERROR; /* retry */ |
| 94 | break; |
| 95 | case SAS_DEVICE_UNKNOWN: |
| 96 | hs = DID_BAD_TARGET; |
| 97 | break; |
| 98 | case SAS_SG_ERR: |
| 99 | hs = DID_PARITY; |
| 100 | break; |
| 101 | case SAS_OPEN_REJECT: |
| 102 | if (ts->open_rej_reason == SAS_OREJ_RSVD_RETRY) |
| 103 | hs = DID_SOFT_ERROR; /* retry */ |
| 104 | else |
| 105 | hs = DID_ERROR; |
| 106 | break; |
| 107 | case SAS_PROTO_RESPONSE: |
| 108 | SAS_DPRINTK("LLDD:%s sent SAS_PROTO_RESP for an SSP " |
| 109 | "task; please report this\n", |
| 110 | task->dev->port->ha->sas_ha_name); |
| 111 | break; |
| 112 | case SAS_ABORTED_TASK: |
| 113 | hs = DID_ABORT; |
| 114 | break; |
| 115 | case SAM_CHECK_COND: |
| 116 | memcpy(sc->sense_buffer, ts->buf, |
FUJITA Tomonori | cc75e8a | 2008-01-13 02:20:18 +0900 | [diff] [blame] | 117 | min(SCSI_SENSE_BUFFERSIZE, ts->buf_valid_size)); |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 118 | stat = SAM_CHECK_COND; |
| 119 | break; |
| 120 | default: |
| 121 | stat = ts->stat; |
| 122 | break; |
| 123 | } |
| 124 | } |
| 125 | ASSIGN_SAS_TASK(sc, NULL); |
| 126 | sc->result = (hs << 16) | stat; |
| 127 | list_del_init(&task->list); |
| 128 | sas_free_task(task); |
James Bottomley | a8e14fe | 2008-02-19 21:48:42 -0600 | [diff] [blame] | 129 | sc->scsi_done(sc); |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | static enum task_attribute sas_scsi_get_task_attr(struct scsi_cmnd *cmd) |
| 133 | { |
| 134 | enum task_attribute ta = TASK_ATTR_SIMPLE; |
| 135 | if (cmd->request && blk_rq_tagged(cmd->request)) { |
| 136 | if (cmd->device->ordered_tags && |
Jeff Garzik | 1bdfd55 | 2006-09-30 21:28:22 -0400 | [diff] [blame] | 137 | (cmd->request->cmd_flags & REQ_HARDBARRIER)) |
FUJITA Tomonori | 63bb1bf | 2007-01-28 01:19:41 +0900 | [diff] [blame] | 138 | ta = TASK_ATTR_ORDERED; |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 139 | } |
| 140 | return ta; |
| 141 | } |
| 142 | |
| 143 | static struct sas_task *sas_create_task(struct scsi_cmnd *cmd, |
| 144 | struct domain_device *dev, |
Al Viro | 3cc2754 | 2006-09-25 02:55:40 +0100 | [diff] [blame] | 145 | gfp_t gfp_flags) |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 146 | { |
| 147 | struct sas_task *task = sas_alloc_task(gfp_flags); |
| 148 | struct scsi_lun lun; |
| 149 | |
| 150 | if (!task) |
| 151 | return NULL; |
| 152 | |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 153 | task->uldd_task = cmd; |
| 154 | ASSIGN_SAS_TASK(cmd, task); |
| 155 | |
| 156 | task->dev = dev; |
| 157 | task->task_proto = task->dev->tproto; /* BUG_ON(!SSP) */ |
| 158 | |
| 159 | task->ssp_task.retry_count = 1; |
| 160 | int_to_scsilun(cmd->device->lun, &lun); |
| 161 | memcpy(task->ssp_task.LUN, &lun.scsi_lun, 8); |
| 162 | task->ssp_task.task_attr = sas_scsi_get_task_attr(cmd); |
| 163 | memcpy(task->ssp_task.cdb, cmd->cmnd, 16); |
| 164 | |
FUJITA Tomonori | c13e556 | 2007-05-26 02:46:37 +0900 | [diff] [blame] | 165 | task->scatter = scsi_sglist(cmd); |
| 166 | task->num_scatter = scsi_sg_count(cmd); |
| 167 | task->total_xfer_len = scsi_bufflen(cmd); |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 168 | task->data_dir = cmd->sc_data_direction; |
| 169 | |
| 170 | task->task_done = sas_scsi_task_done; |
| 171 | |
| 172 | return task; |
| 173 | } |
| 174 | |
Darrick J. Wong | 338ec57 | 2006-10-18 14:43:37 -0700 | [diff] [blame] | 175 | int sas_queue_up(struct sas_task *task) |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 176 | { |
| 177 | struct sas_ha_struct *sas_ha = task->dev->port->ha; |
| 178 | struct scsi_core *core = &sas_ha->core; |
| 179 | unsigned long flags; |
| 180 | LIST_HEAD(list); |
| 181 | |
| 182 | spin_lock_irqsave(&core->task_queue_lock, flags); |
| 183 | if (sas_ha->lldd_queue_size < core->task_queue_size + 1) { |
| 184 | spin_unlock_irqrestore(&core->task_queue_lock, flags); |
| 185 | return -SAS_QUEUE_FULL; |
| 186 | } |
| 187 | list_add_tail(&task->list, &core->task_queue); |
| 188 | core->task_queue_size += 1; |
| 189 | spin_unlock_irqrestore(&core->task_queue_lock, flags); |
Christoph Hellwig | d7a54e3 | 2007-04-26 09:38:01 -0400 | [diff] [blame] | 190 | wake_up_process(core->queue_thread); |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 191 | |
| 192 | return 0; |
| 193 | } |
| 194 | |
| 195 | /** |
| 196 | * sas_queuecommand -- Enqueue a command for processing |
| 197 | * @parameters: See SCSI Core documentation |
| 198 | * |
| 199 | * Note: XXX: Remove the host unlock/lock pair when SCSI Core can |
| 200 | * call us without holding an IRQ spinlock... |
| 201 | */ |
| 202 | int sas_queuecommand(struct scsi_cmnd *cmd, |
| 203 | void (*scsi_done)(struct scsi_cmnd *)) |
Darrick J. Wong | 8ee2402 | 2007-11-05 11:52:14 -0800 | [diff] [blame] | 204 | __releases(host->host_lock) |
| 205 | __acquires(dev->sata_dev.ap->lock) |
| 206 | __releases(dev->sata_dev.ap->lock) |
| 207 | __acquires(host->host_lock) |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 208 | { |
| 209 | int res = 0; |
| 210 | struct domain_device *dev = cmd_to_domain_dev(cmd); |
| 211 | struct Scsi_Host *host = cmd->device->host; |
| 212 | struct sas_internal *i = to_sas_internal(host->transportt); |
| 213 | |
| 214 | spin_unlock_irq(host->host_lock); |
| 215 | |
| 216 | { |
| 217 | struct sas_ha_struct *sas_ha = dev->port->ha; |
| 218 | struct sas_task *task; |
| 219 | |
Darrick J. Wong | fa1c1e8 | 2006-08-10 19:19:47 -0700 | [diff] [blame] | 220 | if (dev_is_sata(dev)) { |
Darrick J. Wong | 3eb7a51 | 2007-01-30 01:18:35 -0800 | [diff] [blame] | 221 | unsigned long flags; |
| 222 | |
| 223 | spin_lock_irqsave(dev->sata_dev.ap->lock, flags); |
Darrick J. Wong | fa1c1e8 | 2006-08-10 19:19:47 -0700 | [diff] [blame] | 224 | res = ata_sas_queuecmd(cmd, scsi_done, |
| 225 | dev->sata_dev.ap); |
Darrick J. Wong | 3eb7a51 | 2007-01-30 01:18:35 -0800 | [diff] [blame] | 226 | spin_unlock_irqrestore(dev->sata_dev.ap->lock, flags); |
Darrick J. Wong | fa1c1e8 | 2006-08-10 19:19:47 -0700 | [diff] [blame] | 227 | goto out; |
| 228 | } |
| 229 | |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 230 | res = -ENOMEM; |
| 231 | task = sas_create_task(cmd, dev, GFP_ATOMIC); |
| 232 | if (!task) |
| 233 | goto out; |
| 234 | |
| 235 | cmd->scsi_done = scsi_done; |
| 236 | /* Queue up, Direct Mode or Task Collector Mode. */ |
| 237 | if (sas_ha->lldd_max_execute_num < 2) |
| 238 | res = i->dft->lldd_execute_task(task, 1, GFP_ATOMIC); |
| 239 | else |
| 240 | res = sas_queue_up(task); |
| 241 | |
| 242 | /* Examine */ |
| 243 | if (res) { |
| 244 | SAS_DPRINTK("lldd_execute_task returned: %d\n", res); |
| 245 | ASSIGN_SAS_TASK(cmd, NULL); |
| 246 | sas_free_task(task); |
| 247 | if (res == -SAS_QUEUE_FULL) { |
| 248 | cmd->result = DID_SOFT_ERROR << 16; /* retry */ |
| 249 | res = 0; |
| 250 | scsi_done(cmd); |
| 251 | } |
| 252 | goto out; |
| 253 | } |
| 254 | } |
| 255 | out: |
| 256 | spin_lock_irq(host->host_lock); |
| 257 | return res; |
| 258 | } |
| 259 | |
James Bottomley | a8e14fe | 2008-02-19 21:48:42 -0600 | [diff] [blame] | 260 | static void sas_eh_finish_cmd(struct scsi_cmnd *cmd) |
| 261 | { |
| 262 | struct sas_task *task = TO_SAS_TASK(cmd); |
| 263 | struct sas_ha_struct *sas_ha = SHOST_TO_SAS_HA(cmd->device->host); |
| 264 | |
| 265 | /* remove the aborted task flag to allow the task to be |
| 266 | * completed now. At this point, we only get called following |
| 267 | * an actual abort of the task, so we should be guaranteed not |
| 268 | * to be racing with any completions from the LLD (hence we |
| 269 | * don't need the task state lock to clear the flag) */ |
| 270 | task->task_state_flags &= ~SAS_TASK_STATE_ABORTED; |
| 271 | /* Now call task_done. However, task will be free'd after |
| 272 | * this */ |
| 273 | task->task_done(task); |
| 274 | /* now finish the command and move it on to the error |
| 275 | * handler done list, this also takes it off the |
| 276 | * error handler pending list */ |
| 277 | scsi_eh_finish_cmd(cmd, &sas_ha->eh_done_q); |
| 278 | } |
| 279 | |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 280 | static void sas_scsi_clear_queue_lu(struct list_head *error_q, struct scsi_cmnd *my_cmd) |
| 281 | { |
| 282 | struct scsi_cmnd *cmd, *n; |
| 283 | |
| 284 | list_for_each_entry_safe(cmd, n, error_q, eh_entry) { |
James Bottomley | 63e4563 | 2008-02-22 17:07:52 -0600 | [diff] [blame] | 285 | if (cmd->device->sdev_target == my_cmd->device->sdev_target && |
| 286 | cmd->device->lun == my_cmd->device->lun) |
James Bottomley | a8e14fe | 2008-02-19 21:48:42 -0600 | [diff] [blame] | 287 | sas_eh_finish_cmd(cmd); |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 288 | } |
| 289 | } |
| 290 | |
| 291 | static void sas_scsi_clear_queue_I_T(struct list_head *error_q, |
| 292 | struct domain_device *dev) |
| 293 | { |
| 294 | struct scsi_cmnd *cmd, *n; |
| 295 | |
| 296 | list_for_each_entry_safe(cmd, n, error_q, eh_entry) { |
| 297 | struct domain_device *x = cmd_to_domain_dev(cmd); |
| 298 | |
| 299 | if (x == dev) |
James Bottomley | a8e14fe | 2008-02-19 21:48:42 -0600 | [diff] [blame] | 300 | sas_eh_finish_cmd(cmd); |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 301 | } |
| 302 | } |
| 303 | |
| 304 | static void sas_scsi_clear_queue_port(struct list_head *error_q, |
| 305 | struct asd_sas_port *port) |
| 306 | { |
| 307 | struct scsi_cmnd *cmd, *n; |
| 308 | |
| 309 | list_for_each_entry_safe(cmd, n, error_q, eh_entry) { |
| 310 | struct domain_device *dev = cmd_to_domain_dev(cmd); |
| 311 | struct asd_sas_port *x = dev->port; |
| 312 | |
| 313 | if (x == port) |
James Bottomley | a8e14fe | 2008-02-19 21:48:42 -0600 | [diff] [blame] | 314 | sas_eh_finish_cmd(cmd); |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 315 | } |
| 316 | } |
| 317 | |
| 318 | enum task_disposition { |
| 319 | TASK_IS_DONE, |
| 320 | TASK_IS_ABORTED, |
| 321 | TASK_IS_AT_LU, |
| 322 | TASK_IS_NOT_AT_LU, |
Darrick J. Wong | 02cd743 | 2007-01-11 14:15:46 -0800 | [diff] [blame] | 323 | TASK_ABORT_FAILED, |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 324 | }; |
| 325 | |
| 326 | static enum task_disposition sas_scsi_find_task(struct sas_task *task) |
| 327 | { |
| 328 | struct sas_ha_struct *ha = task->dev->port->ha; |
| 329 | unsigned long flags; |
| 330 | int i, res; |
| 331 | struct sas_internal *si = |
| 332 | to_sas_internal(task->dev->port->ha->core.shost->transportt); |
| 333 | |
| 334 | if (ha->lldd_max_execute_num > 1) { |
| 335 | struct scsi_core *core = &ha->core; |
| 336 | struct sas_task *t, *n; |
| 337 | |
| 338 | spin_lock_irqsave(&core->task_queue_lock, flags); |
| 339 | list_for_each_entry_safe(t, n, &core->task_queue, list) { |
| 340 | if (task == t) { |
| 341 | list_del_init(&t->list); |
| 342 | spin_unlock_irqrestore(&core->task_queue_lock, |
| 343 | flags); |
| 344 | SAS_DPRINTK("%s: task 0x%p aborted from " |
| 345 | "task_queue\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 346 | __func__, task); |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 347 | return TASK_IS_ABORTED; |
| 348 | } |
| 349 | } |
| 350 | spin_unlock_irqrestore(&core->task_queue_lock, flags); |
| 351 | } |
| 352 | |
| 353 | for (i = 0; i < 5; i++) { |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 354 | SAS_DPRINTK("%s: aborting task 0x%p\n", __func__, task); |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 355 | res = si->dft->lldd_abort_task(task); |
| 356 | |
| 357 | spin_lock_irqsave(&task->task_state_lock, flags); |
| 358 | if (task->task_state_flags & SAS_TASK_STATE_DONE) { |
| 359 | spin_unlock_irqrestore(&task->task_state_lock, flags); |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 360 | SAS_DPRINTK("%s: task 0x%p is done\n", __func__, |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 361 | task); |
| 362 | return TASK_IS_DONE; |
| 363 | } |
| 364 | spin_unlock_irqrestore(&task->task_state_lock, flags); |
| 365 | |
| 366 | if (res == TMF_RESP_FUNC_COMPLETE) { |
| 367 | SAS_DPRINTK("%s: task 0x%p is aborted\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 368 | __func__, task); |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 369 | return TASK_IS_ABORTED; |
| 370 | } else if (si->dft->lldd_query_task) { |
| 371 | SAS_DPRINTK("%s: querying task 0x%p\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 372 | __func__, task); |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 373 | res = si->dft->lldd_query_task(task); |
Darrick J. Wong | 02cd743 | 2007-01-11 14:15:46 -0800 | [diff] [blame] | 374 | switch (res) { |
| 375 | case TMF_RESP_FUNC_SUCC: |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 376 | SAS_DPRINTK("%s: task 0x%p at LU\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 377 | __func__, task); |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 378 | return TASK_IS_AT_LU; |
Darrick J. Wong | 02cd743 | 2007-01-11 14:15:46 -0800 | [diff] [blame] | 379 | case TMF_RESP_FUNC_COMPLETE: |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 380 | SAS_DPRINTK("%s: task 0x%p not at LU\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 381 | __func__, task); |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 382 | return TASK_IS_NOT_AT_LU; |
Darrick J. Wong | 02cd743 | 2007-01-11 14:15:46 -0800 | [diff] [blame] | 383 | case TMF_RESP_FUNC_FAILED: |
| 384 | SAS_DPRINTK("%s: task 0x%p failed to abort\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 385 | __func__, task); |
Darrick J. Wong | 02cd743 | 2007-01-11 14:15:46 -0800 | [diff] [blame] | 386 | return TASK_ABORT_FAILED; |
| 387 | } |
| 388 | |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 389 | } |
| 390 | } |
| 391 | return res; |
| 392 | } |
| 393 | |
| 394 | static int sas_recover_lu(struct domain_device *dev, struct scsi_cmnd *cmd) |
| 395 | { |
| 396 | int res = TMF_RESP_FUNC_FAILED; |
| 397 | struct scsi_lun lun; |
| 398 | struct sas_internal *i = |
| 399 | to_sas_internal(dev->port->ha->core.shost->transportt); |
| 400 | |
| 401 | int_to_scsilun(cmd->device->lun, &lun); |
| 402 | |
| 403 | SAS_DPRINTK("eh: device %llx LUN %x has the task\n", |
| 404 | SAS_ADDR(dev->sas_addr), |
| 405 | cmd->device->lun); |
| 406 | |
| 407 | if (i->dft->lldd_abort_task_set) |
| 408 | res = i->dft->lldd_abort_task_set(dev, lun.scsi_lun); |
| 409 | |
| 410 | if (res == TMF_RESP_FUNC_FAILED) { |
| 411 | if (i->dft->lldd_clear_task_set) |
| 412 | res = i->dft->lldd_clear_task_set(dev, lun.scsi_lun); |
| 413 | } |
| 414 | |
| 415 | if (res == TMF_RESP_FUNC_FAILED) { |
| 416 | if (i->dft->lldd_lu_reset) |
| 417 | res = i->dft->lldd_lu_reset(dev, lun.scsi_lun); |
| 418 | } |
| 419 | |
| 420 | return res; |
| 421 | } |
| 422 | |
| 423 | static int sas_recover_I_T(struct domain_device *dev) |
| 424 | { |
| 425 | int res = TMF_RESP_FUNC_FAILED; |
| 426 | struct sas_internal *i = |
| 427 | to_sas_internal(dev->port->ha->core.shost->transportt); |
| 428 | |
| 429 | SAS_DPRINTK("I_T nexus reset for dev %016llx\n", |
| 430 | SAS_ADDR(dev->sas_addr)); |
| 431 | |
| 432 | if (i->dft->lldd_I_T_nexus_reset) |
| 433 | res = i->dft->lldd_I_T_nexus_reset(dev); |
| 434 | |
| 435 | return res; |
| 436 | } |
| 437 | |
Darrick J. Wong | ad68923 | 2007-01-26 14:08:52 -0800 | [diff] [blame] | 438 | /* Find the sas_phy that's attached to this device */ |
James Bottomley | 5319578 | 2008-02-23 23:35:44 -0600 | [diff] [blame] | 439 | struct sas_phy *sas_find_local_phy(struct domain_device *dev) |
Darrick J. Wong | 3ebf692 | 2007-01-11 14:15:17 -0800 | [diff] [blame] | 440 | { |
Darrick J. Wong | ad68923 | 2007-01-26 14:08:52 -0800 | [diff] [blame] | 441 | struct domain_device *pdev = dev->parent; |
| 442 | struct ex_phy *exphy = NULL; |
| 443 | int i; |
Darrick J. Wong | 3ebf692 | 2007-01-11 14:15:17 -0800 | [diff] [blame] | 444 | |
Darrick J. Wong | ad68923 | 2007-01-26 14:08:52 -0800 | [diff] [blame] | 445 | /* Directly attached device */ |
| 446 | if (!pdev) |
| 447 | return dev->port->phy; |
Darrick J. Wong | 3ebf692 | 2007-01-11 14:15:17 -0800 | [diff] [blame] | 448 | |
Darrick J. Wong | ad68923 | 2007-01-26 14:08:52 -0800 | [diff] [blame] | 449 | /* Otherwise look in the expander */ |
| 450 | for (i = 0; i < pdev->ex_dev.num_phys; i++) |
| 451 | if (!memcmp(dev->sas_addr, |
| 452 | pdev->ex_dev.ex_phy[i].attached_sas_addr, |
| 453 | SAS_ADDR_SIZE)) { |
| 454 | exphy = &pdev->ex_dev.ex_phy[i]; |
| 455 | break; |
| 456 | } |
| 457 | |
| 458 | BUG_ON(!exphy); |
| 459 | return exphy->phy; |
Darrick J. Wong | 3ebf692 | 2007-01-11 14:15:17 -0800 | [diff] [blame] | 460 | } |
James Bottomley | 5319578 | 2008-02-23 23:35:44 -0600 | [diff] [blame] | 461 | EXPORT_SYMBOL_GPL(sas_find_local_phy); |
Darrick J. Wong | 3ebf692 | 2007-01-11 14:15:17 -0800 | [diff] [blame] | 462 | |
Darrick J. Wong | a9344e6 | 2007-01-29 23:48:19 -0800 | [diff] [blame] | 463 | /* Attempt to send a LUN reset message to a device */ |
Darrick J. Wong | ad68923 | 2007-01-26 14:08:52 -0800 | [diff] [blame] | 464 | int sas_eh_device_reset_handler(struct scsi_cmnd *cmd) |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 465 | { |
Darrick J. Wong | ad68923 | 2007-01-26 14:08:52 -0800 | [diff] [blame] | 466 | struct domain_device *dev = cmd_to_domain_dev(cmd); |
Darrick J. Wong | a9344e6 | 2007-01-29 23:48:19 -0800 | [diff] [blame] | 467 | struct sas_internal *i = |
| 468 | to_sas_internal(dev->port->ha->core.shost->transportt); |
| 469 | struct scsi_lun lun; |
| 470 | int res; |
| 471 | |
| 472 | int_to_scsilun(cmd->device->lun, &lun); |
| 473 | |
| 474 | if (!i->dft->lldd_lu_reset) |
| 475 | return FAILED; |
| 476 | |
| 477 | res = i->dft->lldd_lu_reset(dev, lun.scsi_lun); |
| 478 | if (res == TMF_RESP_FUNC_SUCC || res == TMF_RESP_FUNC_COMPLETE) |
| 479 | return SUCCESS; |
| 480 | |
| 481 | return FAILED; |
| 482 | } |
| 483 | |
| 484 | /* Attempt to send a phy (bus) reset */ |
| 485 | int sas_eh_bus_reset_handler(struct scsi_cmnd *cmd) |
| 486 | { |
| 487 | struct domain_device *dev = cmd_to_domain_dev(cmd); |
James Bottomley | 5319578 | 2008-02-23 23:35:44 -0600 | [diff] [blame] | 488 | struct sas_phy *phy = sas_find_local_phy(dev); |
Darrick J. Wong | ad68923 | 2007-01-26 14:08:52 -0800 | [diff] [blame] | 489 | int res; |
| 490 | |
| 491 | res = sas_phy_reset(phy, 1); |
| 492 | if (res) |
Darrick J. Wong | a9344e6 | 2007-01-29 23:48:19 -0800 | [diff] [blame] | 493 | SAS_DPRINTK("Bus reset of %s failed 0x%x\n", |
Kay Sievers | af5ca3f | 2007-12-20 02:09:39 +0100 | [diff] [blame] | 494 | kobject_name(&phy->dev.kobj), |
Darrick J. Wong | ad68923 | 2007-01-26 14:08:52 -0800 | [diff] [blame] | 495 | res); |
| 496 | if (res == TMF_RESP_FUNC_SUCC || res == TMF_RESP_FUNC_COMPLETE) |
| 497 | return SUCCESS; |
| 498 | |
| 499 | return FAILED; |
| 500 | } |
| 501 | |
| 502 | /* Try to reset a device */ |
James Bottomley | 8de3ef2 | 2008-02-23 23:39:59 -0600 | [diff] [blame] | 503 | static int try_to_reset_cmd_device(struct scsi_cmnd *cmd) |
Darrick J. Wong | ad68923 | 2007-01-26 14:08:52 -0800 | [diff] [blame] | 504 | { |
Darrick J. Wong | a9344e6 | 2007-01-29 23:48:19 -0800 | [diff] [blame] | 505 | int res; |
James Bottomley | 8de3ef2 | 2008-02-23 23:39:59 -0600 | [diff] [blame] | 506 | struct Scsi_Host *shost = cmd->device->host; |
Darrick J. Wong | ad68923 | 2007-01-26 14:08:52 -0800 | [diff] [blame] | 507 | |
Darrick J. Wong | a9344e6 | 2007-01-29 23:48:19 -0800 | [diff] [blame] | 508 | if (!shost->hostt->eh_device_reset_handler) |
| 509 | goto try_bus_reset; |
| 510 | |
| 511 | res = shost->hostt->eh_device_reset_handler(cmd); |
| 512 | if (res == SUCCESS) |
| 513 | return res; |
| 514 | |
| 515 | try_bus_reset: |
| 516 | if (shost->hostt->eh_bus_reset_handler) |
| 517 | return shost->hostt->eh_bus_reset_handler(cmd); |
| 518 | |
| 519 | return FAILED; |
Darrick J. Wong | ad68923 | 2007-01-26 14:08:52 -0800 | [diff] [blame] | 520 | } |
| 521 | |
| 522 | static int sas_eh_handle_sas_errors(struct Scsi_Host *shost, |
| 523 | struct list_head *work_q, |
| 524 | struct list_head *done_q) |
| 525 | { |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 526 | struct scsi_cmnd *cmd, *n; |
| 527 | enum task_disposition res = TASK_IS_DONE; |
Darrick J. Wong | 3ebf692 | 2007-01-11 14:15:17 -0800 | [diff] [blame] | 528 | int tmf_resp, need_reset; |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 529 | struct sas_internal *i = to_sas_internal(shost->transportt); |
Darrick J. Wong | ad68923 | 2007-01-26 14:08:52 -0800 | [diff] [blame] | 530 | unsigned long flags; |
| 531 | struct sas_ha_struct *ha = SHOST_TO_SAS_HA(shost); |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 532 | |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 533 | Again: |
Darrick J. Wong | ad68923 | 2007-01-26 14:08:52 -0800 | [diff] [blame] | 534 | list_for_each_entry_safe(cmd, n, work_q, eh_entry) { |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 535 | struct sas_task *task = TO_SAS_TASK(cmd); |
Darrick J. Wong | f456393 | 2006-10-30 15:18:39 -0800 | [diff] [blame] | 536 | |
Darrick J. Wong | ad68923 | 2007-01-26 14:08:52 -0800 | [diff] [blame] | 537 | if (!task) |
Darrick J. Wong | f456393 | 2006-10-30 15:18:39 -0800 | [diff] [blame] | 538 | continue; |
Darrick J. Wong | ad68923 | 2007-01-26 14:08:52 -0800 | [diff] [blame] | 539 | |
| 540 | list_del_init(&cmd->eh_entry); |
Darrick J. Wong | 3ebf692 | 2007-01-11 14:15:17 -0800 | [diff] [blame] | 541 | |
| 542 | spin_lock_irqsave(&task->task_state_lock, flags); |
| 543 | need_reset = task->task_state_flags & SAS_TASK_NEED_DEV_RESET; |
Darrick J. Wong | 3ebf692 | 2007-01-11 14:15:17 -0800 | [diff] [blame] | 544 | spin_unlock_irqrestore(&task->task_state_lock, flags); |
| 545 | |
James Bottomley | 8de3ef2 | 2008-02-23 23:39:59 -0600 | [diff] [blame] | 546 | if (need_reset) { |
| 547 | SAS_DPRINTK("%s: task 0x%p requests reset\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 548 | __func__, task); |
James Bottomley | 8de3ef2 | 2008-02-23 23:39:59 -0600 | [diff] [blame] | 549 | goto reset; |
| 550 | } |
| 551 | |
Darrick J. Wong | f456393 | 2006-10-30 15:18:39 -0800 | [diff] [blame] | 552 | SAS_DPRINTK("trying to find task 0x%p\n", task); |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 553 | res = sas_scsi_find_task(task); |
| 554 | |
| 555 | cmd->eh_eflags = 0; |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 556 | |
| 557 | switch (res) { |
| 558 | case TASK_IS_DONE: |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 559 | SAS_DPRINTK("%s: task 0x%p is done\n", __func__, |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 560 | task); |
James Bottomley | a8e14fe | 2008-02-19 21:48:42 -0600 | [diff] [blame] | 561 | sas_eh_finish_cmd(cmd); |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 562 | continue; |
| 563 | case TASK_IS_ABORTED: |
| 564 | SAS_DPRINTK("%s: task 0x%p is aborted\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 565 | __func__, task); |
James Bottomley | a8e14fe | 2008-02-19 21:48:42 -0600 | [diff] [blame] | 566 | sas_eh_finish_cmd(cmd); |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 567 | continue; |
| 568 | case TASK_IS_AT_LU: |
| 569 | SAS_DPRINTK("task 0x%p is at LU: lu recover\n", task); |
James Bottomley | 8de3ef2 | 2008-02-23 23:39:59 -0600 | [diff] [blame] | 570 | reset: |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 571 | tmf_resp = sas_recover_lu(task->dev, cmd); |
| 572 | if (tmf_resp == TMF_RESP_FUNC_COMPLETE) { |
| 573 | SAS_DPRINTK("dev %016llx LU %x is " |
| 574 | "recovered\n", |
| 575 | SAS_ADDR(task->dev), |
| 576 | cmd->device->lun); |
James Bottomley | a8e14fe | 2008-02-19 21:48:42 -0600 | [diff] [blame] | 577 | sas_eh_finish_cmd(cmd); |
Darrick J. Wong | ad68923 | 2007-01-26 14:08:52 -0800 | [diff] [blame] | 578 | sas_scsi_clear_queue_lu(work_q, cmd); |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 579 | goto Again; |
| 580 | } |
| 581 | /* fallthrough */ |
| 582 | case TASK_IS_NOT_AT_LU: |
Darrick J. Wong | 02cd743 | 2007-01-11 14:15:46 -0800 | [diff] [blame] | 583 | case TASK_ABORT_FAILED: |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 584 | SAS_DPRINTK("task 0x%p is not at LU: I_T recover\n", |
| 585 | task); |
| 586 | tmf_resp = sas_recover_I_T(task->dev); |
| 587 | if (tmf_resp == TMF_RESP_FUNC_COMPLETE) { |
James Bottomley | 8de3ef2 | 2008-02-23 23:39:59 -0600 | [diff] [blame] | 588 | struct domain_device *dev = task->dev; |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 589 | SAS_DPRINTK("I_T %016llx recovered\n", |
| 590 | SAS_ADDR(task->dev->sas_addr)); |
James Bottomley | a8e14fe | 2008-02-19 21:48:42 -0600 | [diff] [blame] | 591 | sas_eh_finish_cmd(cmd); |
James Bottomley | 8de3ef2 | 2008-02-23 23:39:59 -0600 | [diff] [blame] | 592 | sas_scsi_clear_queue_I_T(work_q, dev); |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 593 | goto Again; |
| 594 | } |
| 595 | /* Hammer time :-) */ |
James Bottomley | 8de3ef2 | 2008-02-23 23:39:59 -0600 | [diff] [blame] | 596 | try_to_reset_cmd_device(cmd); |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 597 | if (i->dft->lldd_clear_nexus_port) { |
| 598 | struct asd_sas_port *port = task->dev->port; |
| 599 | SAS_DPRINTK("clearing nexus for port:%d\n", |
| 600 | port->id); |
| 601 | res = i->dft->lldd_clear_nexus_port(port); |
| 602 | if (res == TMF_RESP_FUNC_COMPLETE) { |
| 603 | SAS_DPRINTK("clear nexus port:%d " |
| 604 | "succeeded\n", port->id); |
James Bottomley | a8e14fe | 2008-02-19 21:48:42 -0600 | [diff] [blame] | 605 | sas_eh_finish_cmd(cmd); |
Darrick J. Wong | ad68923 | 2007-01-26 14:08:52 -0800 | [diff] [blame] | 606 | sas_scsi_clear_queue_port(work_q, |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 607 | port); |
| 608 | goto Again; |
| 609 | } |
| 610 | } |
| 611 | if (i->dft->lldd_clear_nexus_ha) { |
| 612 | SAS_DPRINTK("clear nexus ha\n"); |
| 613 | res = i->dft->lldd_clear_nexus_ha(ha); |
| 614 | if (res == TMF_RESP_FUNC_COMPLETE) { |
| 615 | SAS_DPRINTK("clear nexus ha " |
| 616 | "succeeded\n"); |
James Bottomley | a8e14fe | 2008-02-19 21:48:42 -0600 | [diff] [blame] | 617 | sas_eh_finish_cmd(cmd); |
James Bottomley | a8e14fe | 2008-02-19 21:48:42 -0600 | [diff] [blame] | 618 | goto clear_q; |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 619 | } |
| 620 | } |
| 621 | /* If we are here -- this means that no amount |
| 622 | * of effort could recover from errors. Quite |
| 623 | * possibly the HA just disappeared. |
| 624 | */ |
| 625 | SAS_DPRINTK("error from device %llx, LUN %x " |
| 626 | "couldn't be recovered in any way\n", |
| 627 | SAS_ADDR(task->dev->sas_addr), |
| 628 | cmd->device->lun); |
| 629 | |
James Bottomley | a8e14fe | 2008-02-19 21:48:42 -0600 | [diff] [blame] | 630 | sas_eh_finish_cmd(cmd); |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 631 | goto clear_q; |
| 632 | } |
| 633 | } |
Darrick J. Wong | ad68923 | 2007-01-26 14:08:52 -0800 | [diff] [blame] | 634 | return list_empty(work_q); |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 635 | clear_q: |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 636 | SAS_DPRINTK("--- Exit %s -- clear_q\n", __func__); |
James Bottomley | a8e14fe | 2008-02-19 21:48:42 -0600 | [diff] [blame] | 637 | list_for_each_entry_safe(cmd, n, work_q, eh_entry) |
| 638 | sas_eh_finish_cmd(cmd); |
| 639 | |
Darrick J. Wong | ad68923 | 2007-01-26 14:08:52 -0800 | [diff] [blame] | 640 | return list_empty(work_q); |
| 641 | } |
| 642 | |
| 643 | void sas_scsi_recover_host(struct Scsi_Host *shost) |
| 644 | { |
| 645 | struct sas_ha_struct *ha = SHOST_TO_SAS_HA(shost); |
| 646 | unsigned long flags; |
| 647 | LIST_HEAD(eh_work_q); |
| 648 | |
| 649 | spin_lock_irqsave(shost->host_lock, flags); |
| 650 | list_splice_init(&shost->eh_cmd_q, &eh_work_q); |
| 651 | spin_unlock_irqrestore(shost->host_lock, flags); |
| 652 | |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 653 | SAS_DPRINTK("Enter %s\n", __func__); |
Darrick J. Wong | ad68923 | 2007-01-26 14:08:52 -0800 | [diff] [blame] | 654 | /* |
| 655 | * Deal with commands that still have SAS tasks (i.e. they didn't |
| 656 | * complete via the normal sas_task completion mechanism) |
| 657 | */ |
| 658 | if (sas_eh_handle_sas_errors(shost, &eh_work_q, &ha->eh_done_q)) |
| 659 | goto out; |
| 660 | |
| 661 | /* |
| 662 | * Now deal with SCSI commands that completed ok but have a an error |
| 663 | * code (and hopefully sense data) attached. This is roughly what |
| 664 | * scsi_unjam_host does, but we skip scsi_eh_abort_cmds because any |
| 665 | * command we see here has no sas_task and is thus unknown to the HA. |
| 666 | */ |
| 667 | if (!scsi_eh_get_sense(&eh_work_q, &ha->eh_done_q)) |
| 668 | scsi_eh_ready_devs(shost, &eh_work_q, &ha->eh_done_q); |
| 669 | |
| 670 | out: |
| 671 | scsi_eh_flush_done_q(&ha->eh_done_q); |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 672 | SAS_DPRINTK("--- Exit %s\n", __func__); |
Darrick J. Wong | ad68923 | 2007-01-26 14:08:52 -0800 | [diff] [blame] | 673 | return; |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 674 | } |
| 675 | |
Jens Axboe | 242f9dc | 2008-09-14 05:55:09 -0700 | [diff] [blame] | 676 | enum blk_eh_timer_return sas_scsi_timed_out(struct scsi_cmnd *cmd) |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 677 | { |
| 678 | struct sas_task *task = TO_SAS_TASK(cmd); |
| 679 | unsigned long flags; |
| 680 | |
| 681 | if (!task) { |
Jens Axboe | 242f9dc | 2008-09-14 05:55:09 -0700 | [diff] [blame] | 682 | cmd->request->timeout /= 2; |
Darrick J. Wong | 6d4dcd4 | 2007-01-11 14:15:00 -0800 | [diff] [blame] | 683 | SAS_DPRINTK("command 0x%p, task 0x%p, gone: %s\n", |
Jens Axboe | 242f9dc | 2008-09-14 05:55:09 -0700 | [diff] [blame] | 684 | cmd, task, (cmd->request->timeout ? |
| 685 | "BLK_EH_RESET_TIMER" : "BLK_EH_NOT_HANDLED")); |
| 686 | if (!cmd->request->timeout) |
| 687 | return BLK_EH_NOT_HANDLED; |
| 688 | return BLK_EH_RESET_TIMER; |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 689 | } |
| 690 | |
| 691 | spin_lock_irqsave(&task->task_state_lock, flags); |
Darrick J. Wong | 396819f | 2007-01-11 14:15:20 -0800 | [diff] [blame] | 692 | BUG_ON(task->task_state_flags & SAS_TASK_STATE_ABORTED); |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 693 | if (task->task_state_flags & SAS_TASK_STATE_DONE) { |
| 694 | spin_unlock_irqrestore(&task->task_state_lock, flags); |
Jens Axboe | 242f9dc | 2008-09-14 05:55:09 -0700 | [diff] [blame] | 695 | SAS_DPRINTK("command 0x%p, task 0x%p, timed out: " |
| 696 | "BLK_EH_HANDLED\n", cmd, task); |
| 697 | return BLK_EH_HANDLED; |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 698 | } |
Darrick J. Wong | b218a0d | 2007-01-11 14:14:55 -0800 | [diff] [blame] | 699 | if (!(task->task_state_flags & SAS_TASK_AT_INITIATOR)) { |
| 700 | spin_unlock_irqrestore(&task->task_state_lock, flags); |
| 701 | SAS_DPRINTK("command 0x%p, task 0x%p, not at initiator: " |
Jens Axboe | 242f9dc | 2008-09-14 05:55:09 -0700 | [diff] [blame] | 702 | "BLK_EH_RESET_TIMER\n", |
Darrick J. Wong | b218a0d | 2007-01-11 14:14:55 -0800 | [diff] [blame] | 703 | cmd, task); |
Jens Axboe | 242f9dc | 2008-09-14 05:55:09 -0700 | [diff] [blame] | 704 | return BLK_EH_RESET_TIMER; |
Darrick J. Wong | b218a0d | 2007-01-11 14:14:55 -0800 | [diff] [blame] | 705 | } |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 706 | task->task_state_flags |= SAS_TASK_STATE_ABORTED; |
| 707 | spin_unlock_irqrestore(&task->task_state_lock, flags); |
| 708 | |
Jens Axboe | 242f9dc | 2008-09-14 05:55:09 -0700 | [diff] [blame] | 709 | SAS_DPRINTK("command 0x%p, task 0x%p, timed out: BLK_EH_NOT_HANDLED\n", |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 710 | cmd, task); |
| 711 | |
Jens Axboe | 242f9dc | 2008-09-14 05:55:09 -0700 | [diff] [blame] | 712 | return BLK_EH_NOT_HANDLED; |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 713 | } |
| 714 | |
Darrick J. Wong | fa1c1e8 | 2006-08-10 19:19:47 -0700 | [diff] [blame] | 715 | int sas_ioctl(struct scsi_device *sdev, int cmd, void __user *arg) |
| 716 | { |
| 717 | struct domain_device *dev = sdev_to_domain_dev(sdev); |
| 718 | |
| 719 | if (dev_is_sata(dev)) |
Jeff Garzik | 94be9a5 | 2009-01-16 10:17:09 -0500 | [diff] [blame] | 720 | return ata_sas_scsi_ioctl(dev->sata_dev.ap, sdev, cmd, arg); |
Darrick J. Wong | fa1c1e8 | 2006-08-10 19:19:47 -0700 | [diff] [blame] | 721 | |
| 722 | return -EINVAL; |
| 723 | } |
| 724 | |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 725 | struct domain_device *sas_find_dev_by_rphy(struct sas_rphy *rphy) |
| 726 | { |
| 727 | struct Scsi_Host *shost = dev_to_shost(rphy->dev.parent); |
| 728 | struct sas_ha_struct *ha = SHOST_TO_SAS_HA(shost); |
| 729 | struct domain_device *found_dev = NULL; |
| 730 | int i; |
Darrick J. Wong | 980fa2f | 2007-01-11 14:15:40 -0800 | [diff] [blame] | 731 | unsigned long flags; |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 732 | |
Darrick J. Wong | 980fa2f | 2007-01-11 14:15:40 -0800 | [diff] [blame] | 733 | spin_lock_irqsave(&ha->phy_port_lock, flags); |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 734 | for (i = 0; i < ha->num_phys; i++) { |
| 735 | struct asd_sas_port *port = ha->sas_port[i]; |
| 736 | struct domain_device *dev; |
| 737 | |
| 738 | spin_lock(&port->dev_list_lock); |
| 739 | list_for_each_entry(dev, &port->dev_list, dev_list_node) { |
| 740 | if (rphy == dev->rphy) { |
| 741 | found_dev = dev; |
| 742 | spin_unlock(&port->dev_list_lock); |
| 743 | goto found; |
| 744 | } |
| 745 | } |
| 746 | spin_unlock(&port->dev_list_lock); |
| 747 | } |
| 748 | found: |
Darrick J. Wong | 980fa2f | 2007-01-11 14:15:40 -0800 | [diff] [blame] | 749 | spin_unlock_irqrestore(&ha->phy_port_lock, flags); |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 750 | |
| 751 | return found_dev; |
| 752 | } |
| 753 | |
| 754 | static inline struct domain_device *sas_find_target(struct scsi_target *starget) |
| 755 | { |
| 756 | struct sas_rphy *rphy = dev_to_rphy(starget->dev.parent); |
| 757 | |
| 758 | return sas_find_dev_by_rphy(rphy); |
| 759 | } |
| 760 | |
| 761 | int sas_target_alloc(struct scsi_target *starget) |
| 762 | { |
| 763 | struct domain_device *found_dev = sas_find_target(starget); |
Darrick J. Wong | 338ec57 | 2006-10-18 14:43:37 -0700 | [diff] [blame] | 764 | int res; |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 765 | |
| 766 | if (!found_dev) |
| 767 | return -ENODEV; |
| 768 | |
Darrick J. Wong | fa1c1e8 | 2006-08-10 19:19:47 -0700 | [diff] [blame] | 769 | if (dev_is_sata(found_dev)) { |
Darrick J. Wong | 338ec57 | 2006-10-18 14:43:37 -0700 | [diff] [blame] | 770 | res = sas_ata_init_host_and_port(found_dev, starget); |
| 771 | if (res) |
| 772 | return res; |
Darrick J. Wong | fa1c1e8 | 2006-08-10 19:19:47 -0700 | [diff] [blame] | 773 | } |
| 774 | |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 775 | starget->hostdata = found_dev; |
| 776 | return 0; |
| 777 | } |
| 778 | |
| 779 | #define SAS_DEF_QD 32 |
| 780 | #define SAS_MAX_QD 64 |
| 781 | |
| 782 | int sas_slave_configure(struct scsi_device *scsi_dev) |
| 783 | { |
| 784 | struct domain_device *dev = sdev_to_domain_dev(scsi_dev); |
| 785 | struct sas_ha_struct *sas_ha; |
| 786 | |
| 787 | BUG_ON(dev->rphy->identify.device_type != SAS_END_DEVICE); |
| 788 | |
Darrick J. Wong | fa1c1e8 | 2006-08-10 19:19:47 -0700 | [diff] [blame] | 789 | if (dev_is_sata(dev)) { |
| 790 | ata_sas_slave_configure(scsi_dev, dev->sata_dev.ap); |
| 791 | return 0; |
| 792 | } |
| 793 | |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 794 | sas_ha = dev->port->ha; |
| 795 | |
| 796 | sas_read_port_mode_page(scsi_dev); |
| 797 | |
| 798 | if (scsi_dev->tagged_supported) { |
| 799 | scsi_set_tag_type(scsi_dev, MSG_SIMPLE_TAG); |
| 800 | scsi_activate_tcq(scsi_dev, SAS_DEF_QD); |
| 801 | } else { |
| 802 | SAS_DPRINTK("device %llx, LUN %x doesn't support " |
| 803 | "TCQ\n", SAS_ADDR(dev->sas_addr), |
| 804 | scsi_dev->lun); |
| 805 | scsi_dev->tagged_supported = 0; |
| 806 | scsi_set_tag_type(scsi_dev, 0); |
| 807 | scsi_deactivate_tcq(scsi_dev, 1); |
| 808 | } |
| 809 | |
Darrick J. Wong | f27708f | 2007-01-26 14:08:58 -0800 | [diff] [blame] | 810 | scsi_dev->allow_restart = 1; |
| 811 | |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 812 | return 0; |
| 813 | } |
| 814 | |
| 815 | void sas_slave_destroy(struct scsi_device *scsi_dev) |
| 816 | { |
Darrick J. Wong | fa1c1e8 | 2006-08-10 19:19:47 -0700 | [diff] [blame] | 817 | struct domain_device *dev = sdev_to_domain_dev(scsi_dev); |
| 818 | |
| 819 | if (dev_is_sata(dev)) |
| 820 | ata_port_disable(dev->sata_dev.ap); |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 821 | } |
| 822 | |
Mike Christie | e881a17 | 2009-10-15 17:46:39 -0700 | [diff] [blame] | 823 | int sas_change_queue_depth(struct scsi_device *scsi_dev, int new_depth, |
| 824 | int reason) |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 825 | { |
| 826 | int res = min(new_depth, SAS_MAX_QD); |
| 827 | |
Mike Christie | e881a17 | 2009-10-15 17:46:39 -0700 | [diff] [blame] | 828 | if (reason != SCSI_QDEPTH_DEFAULT) |
| 829 | return -EOPNOTSUPP; |
| 830 | |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 831 | if (scsi_dev->tagged_supported) |
| 832 | scsi_adjust_queue_depth(scsi_dev, scsi_get_tag_type(scsi_dev), |
| 833 | res); |
| 834 | else { |
| 835 | struct domain_device *dev = sdev_to_domain_dev(scsi_dev); |
| 836 | sas_printk("device %llx LUN %x queue depth changed to 1\n", |
| 837 | SAS_ADDR(dev->sas_addr), |
| 838 | scsi_dev->lun); |
| 839 | scsi_adjust_queue_depth(scsi_dev, 0, 1); |
| 840 | res = 1; |
| 841 | } |
| 842 | |
| 843 | return res; |
| 844 | } |
| 845 | |
| 846 | int sas_change_queue_type(struct scsi_device *scsi_dev, int qt) |
| 847 | { |
| 848 | if (!scsi_dev->tagged_supported) |
| 849 | return 0; |
| 850 | |
| 851 | scsi_deactivate_tcq(scsi_dev, 1); |
| 852 | |
| 853 | scsi_set_tag_type(scsi_dev, qt); |
| 854 | scsi_activate_tcq(scsi_dev, scsi_dev->queue_depth); |
| 855 | |
| 856 | return qt; |
| 857 | } |
| 858 | |
| 859 | int sas_bios_param(struct scsi_device *scsi_dev, |
| 860 | struct block_device *bdev, |
| 861 | sector_t capacity, int *hsc) |
| 862 | { |
| 863 | hsc[0] = 255; |
| 864 | hsc[1] = 63; |
| 865 | sector_div(capacity, 255*63); |
| 866 | hsc[2] = capacity; |
| 867 | |
| 868 | return 0; |
| 869 | } |
| 870 | |
| 871 | /* ---------- Task Collector Thread implementation ---------- */ |
| 872 | |
| 873 | static void sas_queue(struct sas_ha_struct *sas_ha) |
| 874 | { |
| 875 | struct scsi_core *core = &sas_ha->core; |
| 876 | unsigned long flags; |
| 877 | LIST_HEAD(q); |
| 878 | int can_queue; |
| 879 | int res; |
| 880 | struct sas_internal *i = to_sas_internal(core->shost->transportt); |
| 881 | |
| 882 | spin_lock_irqsave(&core->task_queue_lock, flags); |
Christoph Hellwig | d7a54e3 | 2007-04-26 09:38:01 -0400 | [diff] [blame] | 883 | while (!kthread_should_stop() && |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 884 | !list_empty(&core->task_queue)) { |
| 885 | |
| 886 | can_queue = sas_ha->lldd_queue_size - core->task_queue_size; |
| 887 | if (can_queue >= 0) { |
| 888 | can_queue = core->task_queue_size; |
| 889 | list_splice_init(&core->task_queue, &q); |
| 890 | } else { |
| 891 | struct list_head *a, *n; |
| 892 | |
| 893 | can_queue = sas_ha->lldd_queue_size; |
| 894 | list_for_each_safe(a, n, &core->task_queue) { |
| 895 | list_move_tail(a, &q); |
| 896 | if (--can_queue == 0) |
| 897 | break; |
| 898 | } |
| 899 | can_queue = sas_ha->lldd_queue_size; |
| 900 | } |
| 901 | core->task_queue_size -= can_queue; |
| 902 | spin_unlock_irqrestore(&core->task_queue_lock, flags); |
| 903 | { |
| 904 | struct sas_task *task = list_entry(q.next, |
| 905 | struct sas_task, |
| 906 | list); |
| 907 | list_del_init(&q); |
| 908 | res = i->dft->lldd_execute_task(task, can_queue, |
| 909 | GFP_KERNEL); |
| 910 | if (unlikely(res)) |
| 911 | __list_add(&q, task->list.prev, &task->list); |
| 912 | } |
| 913 | spin_lock_irqsave(&core->task_queue_lock, flags); |
| 914 | if (res) { |
| 915 | list_splice_init(&q, &core->task_queue); /*at head*/ |
| 916 | core->task_queue_size += can_queue; |
| 917 | } |
| 918 | } |
| 919 | spin_unlock_irqrestore(&core->task_queue_lock, flags); |
| 920 | } |
| 921 | |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 922 | /** |
| 923 | * sas_queue_thread -- The Task Collector thread |
| 924 | * @_sas_ha: pointer to struct sas_ha |
| 925 | */ |
| 926 | static int sas_queue_thread(void *_sas_ha) |
| 927 | { |
| 928 | struct sas_ha_struct *sas_ha = _sas_ha; |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 929 | |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 930 | while (1) { |
Christoph Hellwig | d7a54e3 | 2007-04-26 09:38:01 -0400 | [diff] [blame] | 931 | set_current_state(TASK_INTERRUPTIBLE); |
| 932 | schedule(); |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 933 | sas_queue(sas_ha); |
Christoph Hellwig | d7a54e3 | 2007-04-26 09:38:01 -0400 | [diff] [blame] | 934 | if (kthread_should_stop()) |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 935 | break; |
| 936 | } |
| 937 | |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 938 | return 0; |
| 939 | } |
| 940 | |
| 941 | int sas_init_queue(struct sas_ha_struct *sas_ha) |
| 942 | { |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 943 | struct scsi_core *core = &sas_ha->core; |
| 944 | |
| 945 | spin_lock_init(&core->task_queue_lock); |
| 946 | core->task_queue_size = 0; |
| 947 | INIT_LIST_HEAD(&core->task_queue); |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 948 | |
Christoph Hellwig | d7a54e3 | 2007-04-26 09:38:01 -0400 | [diff] [blame] | 949 | core->queue_thread = kthread_run(sas_queue_thread, sas_ha, |
| 950 | "sas_queue_%d", core->shost->host_no); |
| 951 | if (IS_ERR(core->queue_thread)) |
| 952 | return PTR_ERR(core->queue_thread); |
| 953 | return 0; |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 954 | } |
| 955 | |
| 956 | void sas_shutdown_queue(struct sas_ha_struct *sas_ha) |
| 957 | { |
| 958 | unsigned long flags; |
| 959 | struct scsi_core *core = &sas_ha->core; |
| 960 | struct sas_task *task, *n; |
| 961 | |
Christoph Hellwig | d7a54e3 | 2007-04-26 09:38:01 -0400 | [diff] [blame] | 962 | kthread_stop(core->queue_thread); |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 963 | |
| 964 | if (!list_empty(&core->task_queue)) |
| 965 | SAS_DPRINTK("HA: %llx: scsi core task queue is NOT empty!?\n", |
| 966 | SAS_ADDR(sas_ha->sas_addr)); |
| 967 | |
| 968 | spin_lock_irqsave(&core->task_queue_lock, flags); |
| 969 | list_for_each_entry_safe(task, n, &core->task_queue, list) { |
| 970 | struct scsi_cmnd *cmd = task->uldd_task; |
| 971 | |
| 972 | list_del_init(&task->list); |
| 973 | |
| 974 | ASSIGN_SAS_TASK(cmd, NULL); |
| 975 | sas_free_task(task); |
| 976 | cmd->result = DID_ABORT << 16; |
| 977 | cmd->scsi_done(cmd); |
| 978 | } |
| 979 | spin_unlock_irqrestore(&core->task_queue_lock, flags); |
| 980 | } |
| 981 | |
Darrick J. Wong | 396819f | 2007-01-11 14:15:20 -0800 | [diff] [blame] | 982 | /* |
| 983 | * Call the LLDD task abort routine directly. This function is intended for |
| 984 | * use by upper layers that need to tell the LLDD to abort a task. |
| 985 | */ |
| 986 | int __sas_task_abort(struct sas_task *task) |
Darrick J. Wong | 79a5eb6 | 2006-10-30 15:18:50 -0800 | [diff] [blame] | 987 | { |
Darrick J. Wong | 79a5eb6 | 2006-10-30 15:18:50 -0800 | [diff] [blame] | 988 | struct sas_internal *si = |
| 989 | to_sas_internal(task->dev->port->ha->core.shost->transportt); |
| 990 | unsigned long flags; |
| 991 | int res; |
| 992 | |
| 993 | spin_lock_irqsave(&task->task_state_lock, flags); |
Darrick J. Wong | 396819f | 2007-01-11 14:15:20 -0800 | [diff] [blame] | 994 | if (task->task_state_flags & SAS_TASK_STATE_ABORTED || |
| 995 | task->task_state_flags & SAS_TASK_STATE_DONE) { |
Darrick J. Wong | 79a5eb6 | 2006-10-30 15:18:50 -0800 | [diff] [blame] | 996 | spin_unlock_irqrestore(&task->task_state_lock, flags); |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 997 | SAS_DPRINTK("%s: Task %p already finished.\n", __func__, |
Darrick J. Wong | 79a5eb6 | 2006-10-30 15:18:50 -0800 | [diff] [blame] | 998 | task); |
| 999 | return 0; |
| 1000 | } |
Darrick J. Wong | 396819f | 2007-01-11 14:15:20 -0800 | [diff] [blame] | 1001 | task->task_state_flags |= SAS_TASK_STATE_ABORTED; |
Darrick J. Wong | 79a5eb6 | 2006-10-30 15:18:50 -0800 | [diff] [blame] | 1002 | spin_unlock_irqrestore(&task->task_state_lock, flags); |
| 1003 | |
| 1004 | if (!si->dft->lldd_abort_task) |
| 1005 | return -ENODEV; |
| 1006 | |
| 1007 | res = si->dft->lldd_abort_task(task); |
Darrick J. Wong | 396819f | 2007-01-11 14:15:20 -0800 | [diff] [blame] | 1008 | |
| 1009 | spin_lock_irqsave(&task->task_state_lock, flags); |
Darrick J. Wong | 79a5eb6 | 2006-10-30 15:18:50 -0800 | [diff] [blame] | 1010 | if ((task->task_state_flags & SAS_TASK_STATE_DONE) || |
| 1011 | (res == TMF_RESP_FUNC_COMPLETE)) |
| 1012 | { |
Darrick J. Wong | 396819f | 2007-01-11 14:15:20 -0800 | [diff] [blame] | 1013 | spin_unlock_irqrestore(&task->task_state_lock, flags); |
| 1014 | task->task_done(task); |
Darrick J. Wong | 79a5eb6 | 2006-10-30 15:18:50 -0800 | [diff] [blame] | 1015 | return 0; |
| 1016 | } |
| 1017 | |
Darrick J. Wong | 79a5eb6 | 2006-10-30 15:18:50 -0800 | [diff] [blame] | 1018 | if (!(task->task_state_flags & SAS_TASK_STATE_DONE)) |
| 1019 | task->task_state_flags &= ~SAS_TASK_STATE_ABORTED; |
| 1020 | spin_unlock_irqrestore(&task->task_state_lock, flags); |
| 1021 | |
| 1022 | return -EAGAIN; |
| 1023 | } |
| 1024 | |
Darrick J. Wong | 396819f | 2007-01-11 14:15:20 -0800 | [diff] [blame] | 1025 | /* |
| 1026 | * Tell an upper layer that it needs to initiate an abort for a given task. |
| 1027 | * This should only ever be called by an LLDD. |
| 1028 | */ |
| 1029 | void sas_task_abort(struct sas_task *task) |
Darrick J. Wong | 79a5eb6 | 2006-10-30 15:18:50 -0800 | [diff] [blame] | 1030 | { |
Darrick J. Wong | 396819f | 2007-01-11 14:15:20 -0800 | [diff] [blame] | 1031 | struct scsi_cmnd *sc = task->uldd_task; |
Darrick J. Wong | 79a5eb6 | 2006-10-30 15:18:50 -0800 | [diff] [blame] | 1032 | |
Darrick J. Wong | 396819f | 2007-01-11 14:15:20 -0800 | [diff] [blame] | 1033 | /* Escape for libsas internal commands */ |
| 1034 | if (!sc) { |
| 1035 | if (!del_timer(&task->timer)) |
Darrick J. Wong | 79a5eb6 | 2006-10-30 15:18:50 -0800 | [diff] [blame] | 1036 | return; |
Darrick J. Wong | 396819f | 2007-01-11 14:15:20 -0800 | [diff] [blame] | 1037 | task->timer.function(task->timer.data); |
| 1038 | return; |
| 1039 | } |
Darrick J. Wong | 79a5eb6 | 2006-10-30 15:18:50 -0800 | [diff] [blame] | 1040 | |
Darrick J. Wong | 3a2755a | 2007-01-30 01:18:58 -0800 | [diff] [blame] | 1041 | if (dev_is_sata(task->dev)) { |
| 1042 | sas_ata_task_abort(task); |
| 1043 | return; |
| 1044 | } |
| 1045 | |
Jens Axboe | 242f9dc | 2008-09-14 05:55:09 -0700 | [diff] [blame] | 1046 | blk_abort_request(sc->request); |
Darrick J. Wong | 396819f | 2007-01-11 14:15:20 -0800 | [diff] [blame] | 1047 | scsi_schedule_eh(sc->device->host); |
Darrick J. Wong | 79a5eb6 | 2006-10-30 15:18:50 -0800 | [diff] [blame] | 1048 | } |
| 1049 | |
Darrick J. Wong | fa1c1e8 | 2006-08-10 19:19:47 -0700 | [diff] [blame] | 1050 | int sas_slave_alloc(struct scsi_device *scsi_dev) |
| 1051 | { |
| 1052 | struct domain_device *dev = sdev_to_domain_dev(scsi_dev); |
| 1053 | |
| 1054 | if (dev_is_sata(dev)) |
| 1055 | return ata_sas_port_init(dev->sata_dev.ap); |
| 1056 | |
| 1057 | return 0; |
| 1058 | } |
| 1059 | |
| 1060 | void sas_target_destroy(struct scsi_target *starget) |
| 1061 | { |
| 1062 | struct domain_device *found_dev = sas_find_target(starget); |
| 1063 | |
| 1064 | if (!found_dev) |
| 1065 | return; |
| 1066 | |
| 1067 | if (dev_is_sata(found_dev)) |
| 1068 | ata_sas_port_destroy(found_dev->sata_dev.ap); |
| 1069 | |
| 1070 | return; |
| 1071 | } |
| 1072 | |
Darrick J. Wong | 45e6cdf | 2008-02-19 10:49:40 -0800 | [diff] [blame] | 1073 | static void sas_parse_addr(u8 *sas_addr, const char *p) |
| 1074 | { |
| 1075 | int i; |
| 1076 | for (i = 0; i < SAS_ADDR_SIZE; i++) { |
| 1077 | u8 h, l; |
| 1078 | if (!*p) |
| 1079 | break; |
| 1080 | h = isdigit(*p) ? *p-'0' : toupper(*p)-'A'+10; |
| 1081 | p++; |
| 1082 | l = isdigit(*p) ? *p-'0' : toupper(*p)-'A'+10; |
| 1083 | p++; |
| 1084 | sas_addr[i] = (h<<4) | l; |
| 1085 | } |
| 1086 | } |
| 1087 | |
| 1088 | #define SAS_STRING_ADDR_SIZE 16 |
| 1089 | |
| 1090 | int sas_request_addr(struct Scsi_Host *shost, u8 *addr) |
| 1091 | { |
| 1092 | int res; |
| 1093 | const struct firmware *fw; |
| 1094 | |
| 1095 | res = request_firmware(&fw, "sas_addr", &shost->shost_gendev); |
| 1096 | if (res) |
| 1097 | return res; |
| 1098 | |
| 1099 | if (fw->size < SAS_STRING_ADDR_SIZE) { |
| 1100 | res = -ENODEV; |
| 1101 | goto out; |
| 1102 | } |
| 1103 | |
| 1104 | sas_parse_addr(addr, fw->data); |
| 1105 | |
| 1106 | out: |
| 1107 | release_firmware(fw); |
| 1108 | return res; |
| 1109 | } |
| 1110 | EXPORT_SYMBOL_GPL(sas_request_addr); |
| 1111 | |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 1112 | EXPORT_SYMBOL_GPL(sas_queuecommand); |
| 1113 | EXPORT_SYMBOL_GPL(sas_target_alloc); |
| 1114 | EXPORT_SYMBOL_GPL(sas_slave_configure); |
| 1115 | EXPORT_SYMBOL_GPL(sas_slave_destroy); |
| 1116 | EXPORT_SYMBOL_GPL(sas_change_queue_depth); |
| 1117 | EXPORT_SYMBOL_GPL(sas_change_queue_type); |
| 1118 | EXPORT_SYMBOL_GPL(sas_bios_param); |
Darrick J. Wong | 396819f | 2007-01-11 14:15:20 -0800 | [diff] [blame] | 1119 | EXPORT_SYMBOL_GPL(__sas_task_abort); |
Darrick J. Wong | 79a5eb6 | 2006-10-30 15:18:50 -0800 | [diff] [blame] | 1120 | EXPORT_SYMBOL_GPL(sas_task_abort); |
Darrick J. Wong | dea2221 | 2006-11-07 17:28:55 -0800 | [diff] [blame] | 1121 | EXPORT_SYMBOL_GPL(sas_phy_reset); |
Darrick J. Wong | acbf167 | 2007-01-11 14:14:57 -0800 | [diff] [blame] | 1122 | EXPORT_SYMBOL_GPL(sas_phy_enable); |
Darrick J. Wong | ad68923 | 2007-01-26 14:08:52 -0800 | [diff] [blame] | 1123 | EXPORT_SYMBOL_GPL(sas_eh_device_reset_handler); |
Darrick J. Wong | a9344e6 | 2007-01-29 23:48:19 -0800 | [diff] [blame] | 1124 | EXPORT_SYMBOL_GPL(sas_eh_bus_reset_handler); |
Darrick J. Wong | fa1c1e8 | 2006-08-10 19:19:47 -0700 | [diff] [blame] | 1125 | EXPORT_SYMBOL_GPL(sas_slave_alloc); |
| 1126 | EXPORT_SYMBOL_GPL(sas_target_destroy); |
| 1127 | EXPORT_SYMBOL_GPL(sas_ioctl); |