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