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 | |
Dan Williams | a3a1425 | 2011-12-06 23:24:42 -0800 | [diff] [blame] | 52 | /* record final status and free the task */ |
| 53 | static void sas_end_task(struct scsi_cmnd *sc, struct sas_task *task) |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 54 | { |
| 55 | struct task_status_struct *ts = &task->task_status; |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 56 | int hs = 0, stat = 0; |
| 57 | |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 58 | if (ts->resp == SAS_TASK_UNDELIVERED) { |
| 59 | /* transport error */ |
| 60 | hs = DID_NO_CONNECT; |
| 61 | } else { /* ts->resp == SAS_TASK_COMPLETE */ |
| 62 | /* task delivered, what happened afterwards? */ |
| 63 | switch (ts->stat) { |
| 64 | case SAS_DEV_NO_RESPONSE: |
| 65 | case SAS_INTERRUPTED: |
| 66 | case SAS_PHY_DOWN: |
| 67 | case SAS_NAK_R_ERR: |
| 68 | case SAS_OPEN_TO: |
| 69 | hs = DID_NO_CONNECT; |
| 70 | break; |
| 71 | case SAS_DATA_UNDERRUN: |
FUJITA Tomonori | c13e556 | 2007-05-26 02:46:37 +0900 | [diff] [blame] | 72 | scsi_set_resid(sc, ts->residual); |
| 73 | if (scsi_bufflen(sc) - scsi_get_resid(sc) < sc->underflow) |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 74 | hs = DID_ERROR; |
| 75 | break; |
| 76 | case SAS_DATA_OVERRUN: |
| 77 | hs = DID_ERROR; |
| 78 | break; |
| 79 | case SAS_QUEUE_FULL: |
| 80 | hs = DID_SOFT_ERROR; /* retry */ |
| 81 | break; |
| 82 | case SAS_DEVICE_UNKNOWN: |
| 83 | hs = DID_BAD_TARGET; |
| 84 | break; |
| 85 | case SAS_SG_ERR: |
| 86 | hs = DID_PARITY; |
| 87 | break; |
| 88 | case SAS_OPEN_REJECT: |
| 89 | if (ts->open_rej_reason == SAS_OREJ_RSVD_RETRY) |
| 90 | hs = DID_SOFT_ERROR; /* retry */ |
| 91 | else |
| 92 | hs = DID_ERROR; |
| 93 | break; |
| 94 | case SAS_PROTO_RESPONSE: |
| 95 | SAS_DPRINTK("LLDD:%s sent SAS_PROTO_RESP for an SSP " |
| 96 | "task; please report this\n", |
| 97 | task->dev->port->ha->sas_ha_name); |
| 98 | break; |
| 99 | case SAS_ABORTED_TASK: |
| 100 | hs = DID_ABORT; |
| 101 | break; |
James Bottomley | df64d3c | 2010-07-27 15:51:13 -0500 | [diff] [blame] | 102 | case SAM_STAT_CHECK_CONDITION: |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 103 | memcpy(sc->sense_buffer, ts->buf, |
FUJITA Tomonori | cc75e8a | 2008-01-13 02:20:18 +0900 | [diff] [blame] | 104 | min(SCSI_SENSE_BUFFERSIZE, ts->buf_valid_size)); |
James Bottomley | df64d3c | 2010-07-27 15:51:13 -0500 | [diff] [blame] | 105 | stat = SAM_STAT_CHECK_CONDITION; |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 106 | break; |
| 107 | default: |
| 108 | stat = ts->stat; |
| 109 | break; |
| 110 | } |
| 111 | } |
Dan Williams | a3a1425 | 2011-12-06 23:24:42 -0800 | [diff] [blame] | 112 | |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 113 | sc->result = (hs << 16) | stat; |
Dan Williams | a3a1425 | 2011-12-06 23:24:42 -0800 | [diff] [blame] | 114 | ASSIGN_SAS_TASK(sc, NULL); |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 115 | sas_free_task(task); |
Dan Williams | a3a1425 | 2011-12-06 23:24:42 -0800 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | static void sas_scsi_task_done(struct sas_task *task) |
| 119 | { |
| 120 | struct scsi_cmnd *sc = task->uldd_task; |
Dan Williams | 9095a64 | 2011-11-28 11:29:20 -0800 | [diff] [blame] | 121 | struct domain_device *dev = task->dev; |
| 122 | struct sas_ha_struct *ha = dev->port->ha; |
| 123 | unsigned long flags; |
Dan Williams | a3a1425 | 2011-12-06 23:24:42 -0800 | [diff] [blame] | 124 | |
Dan Williams | 9095a64 | 2011-11-28 11:29:20 -0800 | [diff] [blame] | 125 | spin_lock_irqsave(&dev->done_lock, flags); |
| 126 | if (test_bit(SAS_HA_FROZEN, &ha->state)) |
| 127 | task = NULL; |
| 128 | else |
| 129 | ASSIGN_SAS_TASK(sc, NULL); |
| 130 | spin_unlock_irqrestore(&dev->done_lock, flags); |
| 131 | |
| 132 | if (unlikely(!task)) { |
| 133 | /* task will be completed by the error handler */ |
Dan Williams | a3a1425 | 2011-12-06 23:24:42 -0800 | [diff] [blame] | 134 | SAS_DPRINTK("task done but aborted\n"); |
| 135 | return; |
| 136 | } |
| 137 | |
| 138 | if (unlikely(!sc)) { |
| 139 | SAS_DPRINTK("task_done called with non existing SCSI cmnd!\n"); |
Dan Williams | a3a1425 | 2011-12-06 23:24:42 -0800 | [diff] [blame] | 140 | sas_free_task(task); |
| 141 | return; |
| 142 | } |
| 143 | |
Dan Williams | a3a1425 | 2011-12-06 23:24:42 -0800 | [diff] [blame] | 144 | sas_end_task(sc, task); |
James Bottomley | a8e14fe | 2008-02-19 21:48:42 -0600 | [diff] [blame] | 145 | sc->scsi_done(sc); |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 146 | } |
| 147 | |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 148 | static struct sas_task *sas_create_task(struct scsi_cmnd *cmd, |
| 149 | struct domain_device *dev, |
Al Viro | 3cc2754 | 2006-09-25 02:55:40 +0100 | [diff] [blame] | 150 | gfp_t gfp_flags) |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 151 | { |
| 152 | struct sas_task *task = sas_alloc_task(gfp_flags); |
| 153 | struct scsi_lun lun; |
| 154 | |
| 155 | if (!task) |
| 156 | return NULL; |
| 157 | |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 158 | task->uldd_task = cmd; |
| 159 | ASSIGN_SAS_TASK(cmd, task); |
| 160 | |
| 161 | task->dev = dev; |
| 162 | task->task_proto = task->dev->tproto; /* BUG_ON(!SSP) */ |
| 163 | |
| 164 | task->ssp_task.retry_count = 1; |
| 165 | int_to_scsilun(cmd->device->lun, &lun); |
| 166 | memcpy(task->ssp_task.LUN, &lun.scsi_lun, 8); |
Tejun Heo | 9cbbdca | 2010-09-03 11:56:16 +0200 | [diff] [blame] | 167 | task->ssp_task.task_attr = TASK_ATTR_SIMPLE; |
James Bottomley | e73823f | 2013-05-07 15:38:18 -0700 | [diff] [blame] | 168 | task->ssp_task.cmd = cmd; |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 169 | |
FUJITA Tomonori | c13e556 | 2007-05-26 02:46:37 +0900 | [diff] [blame] | 170 | task->scatter = scsi_sglist(cmd); |
| 171 | task->num_scatter = scsi_sg_count(cmd); |
| 172 | task->total_xfer_len = scsi_bufflen(cmd); |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 173 | task->data_dir = cmd->sc_data_direction; |
| 174 | |
| 175 | task->task_done = sas_scsi_task_done; |
| 176 | |
| 177 | return task; |
| 178 | } |
| 179 | |
Christoph Hellwig | 92bd401 | 2011-07-11 14:49:23 -0400 | [diff] [blame] | 180 | int sas_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd) |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 181 | { |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 182 | struct sas_internal *i = to_sas_internal(host->transportt); |
Christoph Hellwig | a923f75 | 2011-07-11 14:49:24 -0400 | [diff] [blame] | 183 | struct domain_device *dev = cmd_to_domain_dev(cmd); |
Christoph Hellwig | a923f75 | 2011-07-11 14:49:24 -0400 | [diff] [blame] | 184 | struct sas_task *task; |
| 185 | int res = 0; |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 186 | |
Christoph Hellwig | a923f75 | 2011-07-11 14:49:24 -0400 | [diff] [blame] | 187 | /* If the device fell off, no sense in issuing commands */ |
Dan Williams | e139942 | 2012-01-07 08:52:39 +0000 | [diff] [blame] | 188 | if (test_bit(SAS_DEV_GONE, &dev->state)) { |
Christoph Hellwig | a923f75 | 2011-07-11 14:49:24 -0400 | [diff] [blame] | 189 | cmd->result = DID_BAD_TARGET << 16; |
| 190 | goto out_done; |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 191 | } |
Christoph Hellwig | a923f75 | 2011-07-11 14:49:24 -0400 | [diff] [blame] | 192 | |
| 193 | if (dev_is_sata(dev)) { |
Dan Williams | 312d3e5 | 2011-11-17 17:59:50 -0800 | [diff] [blame] | 194 | spin_lock_irq(dev->sata_dev.ap->lock); |
Christoph Hellwig | a923f75 | 2011-07-11 14:49:24 -0400 | [diff] [blame] | 195 | res = ata_sas_queuecmd(cmd, dev->sata_dev.ap); |
Dan Williams | 312d3e5 | 2011-11-17 17:59:50 -0800 | [diff] [blame] | 196 | spin_unlock_irq(dev->sata_dev.ap->lock); |
Christoph Hellwig | a923f75 | 2011-07-11 14:49:24 -0400 | [diff] [blame] | 197 | return res; |
| 198 | } |
| 199 | |
| 200 | task = sas_create_task(cmd, dev, GFP_ATOMIC); |
| 201 | if (!task) |
Christoph Hellwig | ac81c6a | 2011-07-16 15:00:35 -0400 | [diff] [blame] | 202 | return SCSI_MLQUEUE_HOST_BUSY; |
Christoph Hellwig | a923f75 | 2011-07-11 14:49:24 -0400 | [diff] [blame] | 203 | |
Christoph Hellwig | 79855d1 | 2014-11-05 10:36:28 +0100 | [diff] [blame] | 204 | res = i->dft->lldd_execute_task(task, GFP_ATOMIC); |
Christoph Hellwig | a923f75 | 2011-07-11 14:49:24 -0400 | [diff] [blame] | 205 | if (res) |
| 206 | goto out_free_task; |
| 207 | return 0; |
| 208 | |
| 209 | out_free_task: |
| 210 | SAS_DPRINTK("lldd_execute_task returned: %d\n", res); |
| 211 | ASSIGN_SAS_TASK(cmd, NULL); |
| 212 | sas_free_task(task); |
Christoph Hellwig | ac81c6a | 2011-07-16 15:00:35 -0400 | [diff] [blame] | 213 | if (res == -SAS_QUEUE_FULL) |
| 214 | cmd->result = DID_SOFT_ERROR << 16; /* retry */ |
| 215 | else |
| 216 | cmd->result = DID_ERROR << 16; |
Christoph Hellwig | a923f75 | 2011-07-11 14:49:24 -0400 | [diff] [blame] | 217 | out_done: |
| 218 | cmd->scsi_done(cmd); |
| 219 | return 0; |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 220 | } |
| 221 | |
James Bottomley | a8e14fe | 2008-02-19 21:48:42 -0600 | [diff] [blame] | 222 | static void sas_eh_finish_cmd(struct scsi_cmnd *cmd) |
| 223 | { |
James Bottomley | a8e14fe | 2008-02-19 21:48:42 -0600 | [diff] [blame] | 224 | struct sas_ha_struct *sas_ha = SHOST_TO_SAS_HA(cmd->device->host); |
Dan Williams | 45c73b6 | 2012-01-09 10:12:52 -0800 | [diff] [blame] | 225 | struct sas_task *task = TO_SAS_TASK(cmd); |
James Bottomley | a8e14fe | 2008-02-19 21:48:42 -0600 | [diff] [blame] | 226 | |
Dan Williams | a3a1425 | 2011-12-06 23:24:42 -0800 | [diff] [blame] | 227 | /* At this point, we only get called following an actual abort |
| 228 | * of the task, so we should be guaranteed not to be racing with |
| 229 | * any completions from the LLD. Task is freed after this. |
| 230 | */ |
| 231 | sas_end_task(cmd, task); |
| 232 | |
James Bottomley | a8e14fe | 2008-02-19 21:48:42 -0600 | [diff] [blame] | 233 | /* now finish the command and move it on to the error |
| 234 | * handler done list, this also takes it off the |
Dan Williams | a3a1425 | 2011-12-06 23:24:42 -0800 | [diff] [blame] | 235 | * error handler pending list. |
| 236 | */ |
James Bottomley | a8e14fe | 2008-02-19 21:48:42 -0600 | [diff] [blame] | 237 | scsi_eh_finish_cmd(cmd, &sas_ha->eh_done_q); |
| 238 | } |
| 239 | |
Dan Williams | 3944f50 | 2011-11-29 12:08:50 -0800 | [diff] [blame] | 240 | static void sas_eh_defer_cmd(struct scsi_cmnd *cmd) |
| 241 | { |
Dan Williams | 45c73b6 | 2012-01-09 10:12:52 -0800 | [diff] [blame] | 242 | struct domain_device *dev = cmd_to_domain_dev(cmd); |
Dan Williams | 3944f50 | 2011-11-29 12:08:50 -0800 | [diff] [blame] | 243 | struct sas_ha_struct *ha = dev->port->ha; |
Dan Williams | 45c73b6 | 2012-01-09 10:12:52 -0800 | [diff] [blame] | 244 | struct sas_task *task = TO_SAS_TASK(cmd); |
Dan Williams | 3944f50 | 2011-11-29 12:08:50 -0800 | [diff] [blame] | 245 | |
| 246 | if (!dev_is_sata(dev)) { |
| 247 | sas_eh_finish_cmd(cmd); |
| 248 | return; |
| 249 | } |
| 250 | |
| 251 | /* report the timeout to libata */ |
| 252 | sas_end_task(cmd, task); |
| 253 | list_move_tail(&cmd->eh_entry, &ha->eh_ata_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) |
Dan Williams | 3a2cdf3 | 2011-11-29 14:54:28 -0800 | [diff] [blame] | 263 | sas_eh_defer_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 | { |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 304 | unsigned long flags; |
| 305 | int i, res; |
| 306 | struct sas_internal *si = |
| 307 | to_sas_internal(task->dev->port->ha->core.shost->transportt); |
| 308 | |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 309 | for (i = 0; i < 5; i++) { |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 310 | SAS_DPRINTK("%s: aborting task 0x%p\n", __func__, task); |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 311 | res = si->dft->lldd_abort_task(task); |
| 312 | |
| 313 | spin_lock_irqsave(&task->task_state_lock, flags); |
| 314 | if (task->task_state_flags & SAS_TASK_STATE_DONE) { |
| 315 | spin_unlock_irqrestore(&task->task_state_lock, flags); |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 316 | SAS_DPRINTK("%s: task 0x%p is done\n", __func__, |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 317 | task); |
| 318 | return TASK_IS_DONE; |
| 319 | } |
| 320 | spin_unlock_irqrestore(&task->task_state_lock, flags); |
| 321 | |
| 322 | if (res == TMF_RESP_FUNC_COMPLETE) { |
| 323 | SAS_DPRINTK("%s: task 0x%p is aborted\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 324 | __func__, task); |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 325 | return TASK_IS_ABORTED; |
| 326 | } else if (si->dft->lldd_query_task) { |
| 327 | SAS_DPRINTK("%s: querying task 0x%p\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 328 | __func__, task); |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 329 | res = si->dft->lldd_query_task(task); |
Darrick J. Wong | 02cd743 | 2007-01-11 14:15:46 -0800 | [diff] [blame] | 330 | switch (res) { |
| 331 | case TMF_RESP_FUNC_SUCC: |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 332 | SAS_DPRINTK("%s: task 0x%p at LU\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 333 | __func__, task); |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 334 | return TASK_IS_AT_LU; |
Darrick J. Wong | 02cd743 | 2007-01-11 14:15:46 -0800 | [diff] [blame] | 335 | case TMF_RESP_FUNC_COMPLETE: |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 336 | SAS_DPRINTK("%s: task 0x%p not at LU\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 337 | __func__, task); |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 338 | return TASK_IS_NOT_AT_LU; |
Darrick J. Wong | 02cd743 | 2007-01-11 14:15:46 -0800 | [diff] [blame] | 339 | case TMF_RESP_FUNC_FAILED: |
| 340 | SAS_DPRINTK("%s: task 0x%p failed to abort\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 341 | __func__, task); |
Darrick J. Wong | 02cd743 | 2007-01-11 14:15:46 -0800 | [diff] [blame] | 342 | return TASK_ABORT_FAILED; |
| 343 | } |
| 344 | |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 345 | } |
| 346 | } |
| 347 | return res; |
| 348 | } |
| 349 | |
| 350 | static int sas_recover_lu(struct domain_device *dev, struct scsi_cmnd *cmd) |
| 351 | { |
| 352 | int res = TMF_RESP_FUNC_FAILED; |
| 353 | struct scsi_lun lun; |
| 354 | struct sas_internal *i = |
| 355 | to_sas_internal(dev->port->ha->core.shost->transportt); |
| 356 | |
| 357 | int_to_scsilun(cmd->device->lun, &lun); |
| 358 | |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 359 | SAS_DPRINTK("eh: device %llx LUN %llx has the task\n", |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 360 | SAS_ADDR(dev->sas_addr), |
| 361 | cmd->device->lun); |
| 362 | |
| 363 | if (i->dft->lldd_abort_task_set) |
| 364 | res = i->dft->lldd_abort_task_set(dev, lun.scsi_lun); |
| 365 | |
| 366 | if (res == TMF_RESP_FUNC_FAILED) { |
| 367 | if (i->dft->lldd_clear_task_set) |
| 368 | res = i->dft->lldd_clear_task_set(dev, lun.scsi_lun); |
| 369 | } |
| 370 | |
| 371 | if (res == TMF_RESP_FUNC_FAILED) { |
| 372 | if (i->dft->lldd_lu_reset) |
| 373 | res = i->dft->lldd_lu_reset(dev, lun.scsi_lun); |
| 374 | } |
| 375 | |
| 376 | return res; |
| 377 | } |
| 378 | |
| 379 | static int sas_recover_I_T(struct domain_device *dev) |
| 380 | { |
| 381 | int res = TMF_RESP_FUNC_FAILED; |
| 382 | struct sas_internal *i = |
| 383 | to_sas_internal(dev->port->ha->core.shost->transportt); |
| 384 | |
| 385 | SAS_DPRINTK("I_T nexus reset for dev %016llx\n", |
| 386 | SAS_ADDR(dev->sas_addr)); |
| 387 | |
| 388 | if (i->dft->lldd_I_T_nexus_reset) |
| 389 | res = i->dft->lldd_I_T_nexus_reset(dev); |
| 390 | |
| 391 | return res; |
| 392 | } |
| 393 | |
Dan Williams | f41a0c4 | 2011-12-21 21:33:17 -0800 | [diff] [blame] | 394 | /* take a reference on the last known good phy for this device */ |
| 395 | struct sas_phy *sas_get_local_phy(struct domain_device *dev) |
Darrick J. Wong | 3ebf692 | 2007-01-11 14:15:17 -0800 | [diff] [blame] | 396 | { |
Dan Williams | f41a0c4 | 2011-12-21 21:33:17 -0800 | [diff] [blame] | 397 | struct sas_ha_struct *ha = dev->port->ha; |
| 398 | struct sas_phy *phy; |
| 399 | unsigned long flags; |
Darrick J. Wong | 3ebf692 | 2007-01-11 14:15:17 -0800 | [diff] [blame] | 400 | |
Dan Williams | f41a0c4 | 2011-12-21 21:33:17 -0800 | [diff] [blame] | 401 | /* a published domain device always has a valid phy, it may be |
| 402 | * stale, but it is never NULL |
| 403 | */ |
| 404 | BUG_ON(!dev->phy); |
Darrick J. Wong | 3ebf692 | 2007-01-11 14:15:17 -0800 | [diff] [blame] | 405 | |
Dan Williams | f41a0c4 | 2011-12-21 21:33:17 -0800 | [diff] [blame] | 406 | spin_lock_irqsave(&ha->phy_port_lock, flags); |
| 407 | phy = dev->phy; |
| 408 | get_device(&phy->dev); |
| 409 | spin_unlock_irqrestore(&ha->phy_port_lock, flags); |
Darrick J. Wong | ad68923 | 2007-01-26 14:08:52 -0800 | [diff] [blame] | 410 | |
Dan Williams | f41a0c4 | 2011-12-21 21:33:17 -0800 | [diff] [blame] | 411 | return phy; |
Darrick J. Wong | 3ebf692 | 2007-01-11 14:15:17 -0800 | [diff] [blame] | 412 | } |
Dan Williams | f41a0c4 | 2011-12-21 21:33:17 -0800 | [diff] [blame] | 413 | EXPORT_SYMBOL_GPL(sas_get_local_phy); |
Darrick J. Wong | 3ebf692 | 2007-01-11 14:15:17 -0800 | [diff] [blame] | 414 | |
Dan Williams | 5db45bd | 2012-06-21 23:30:48 -0700 | [diff] [blame] | 415 | static void sas_wait_eh(struct domain_device *dev) |
| 416 | { |
| 417 | struct sas_ha_struct *ha = dev->port->ha; |
| 418 | DEFINE_WAIT(wait); |
| 419 | |
| 420 | if (dev_is_sata(dev)) { |
| 421 | ata_port_wait_eh(dev->sata_dev.ap); |
| 422 | return; |
| 423 | } |
| 424 | retry: |
| 425 | spin_lock_irq(&ha->lock); |
| 426 | |
| 427 | while (test_bit(SAS_DEV_EH_PENDING, &dev->state)) { |
| 428 | prepare_to_wait(&ha->eh_wait_q, &wait, TASK_UNINTERRUPTIBLE); |
| 429 | spin_unlock_irq(&ha->lock); |
| 430 | schedule(); |
| 431 | spin_lock_irq(&ha->lock); |
| 432 | } |
| 433 | finish_wait(&ha->eh_wait_q, &wait); |
| 434 | |
| 435 | spin_unlock_irq(&ha->lock); |
| 436 | |
| 437 | /* make sure SCSI EH is complete */ |
| 438 | if (scsi_host_in_recovery(ha->core.shost)) { |
| 439 | msleep(10); |
| 440 | goto retry; |
| 441 | } |
| 442 | } |
| 443 | EXPORT_SYMBOL(sas_wait_eh); |
| 444 | |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 445 | static int sas_queue_reset(struct domain_device *dev, int reset_type, |
| 446 | u64 lun, int wait) |
Dan Williams | 5db45bd | 2012-06-21 23:30:48 -0700 | [diff] [blame] | 447 | { |
| 448 | struct sas_ha_struct *ha = dev->port->ha; |
| 449 | int scheduled = 0, tries = 100; |
| 450 | |
| 451 | /* ata: promote lun reset to bus reset */ |
| 452 | if (dev_is_sata(dev)) { |
| 453 | sas_ata_schedule_reset(dev); |
| 454 | if (wait) |
| 455 | sas_ata_wait_eh(dev); |
| 456 | return SUCCESS; |
| 457 | } |
| 458 | |
| 459 | while (!scheduled && tries--) { |
| 460 | spin_lock_irq(&ha->lock); |
| 461 | if (!test_bit(SAS_DEV_EH_PENDING, &dev->state) && |
| 462 | !test_bit(reset_type, &dev->state)) { |
| 463 | scheduled = 1; |
| 464 | ha->eh_active++; |
| 465 | list_add_tail(&dev->ssp_dev.eh_list_node, &ha->eh_dev_q); |
| 466 | set_bit(SAS_DEV_EH_PENDING, &dev->state); |
| 467 | set_bit(reset_type, &dev->state); |
| 468 | int_to_scsilun(lun, &dev->ssp_dev.reset_lun); |
| 469 | scsi_schedule_eh(ha->core.shost); |
| 470 | } |
| 471 | spin_unlock_irq(&ha->lock); |
| 472 | |
| 473 | if (wait) |
| 474 | sas_wait_eh(dev); |
| 475 | |
| 476 | if (scheduled) |
| 477 | return SUCCESS; |
| 478 | } |
| 479 | |
| 480 | SAS_DPRINTK("%s reset of %s failed\n", |
| 481 | reset_type == SAS_DEV_LU_RESET ? "LUN" : "Bus", |
| 482 | dev_name(&dev->rphy->dev)); |
| 483 | |
| 484 | return FAILED; |
| 485 | } |
| 486 | |
Dan Williams | 9524c68 | 2012-06-21 23:30:53 -0700 | [diff] [blame] | 487 | int sas_eh_abort_handler(struct scsi_cmnd *cmd) |
| 488 | { |
| 489 | int res; |
| 490 | struct sas_task *task = TO_SAS_TASK(cmd); |
| 491 | struct Scsi_Host *host = cmd->device->host; |
| 492 | struct sas_internal *i = to_sas_internal(host->transportt); |
| 493 | |
| 494 | if (current != host->ehandler) |
| 495 | return FAILED; |
| 496 | |
| 497 | if (!i->dft->lldd_abort_task) |
| 498 | return FAILED; |
| 499 | |
| 500 | res = i->dft->lldd_abort_task(task); |
| 501 | if (res == TMF_RESP_FUNC_SUCC || res == TMF_RESP_FUNC_COMPLETE) |
| 502 | return SUCCESS; |
| 503 | |
| 504 | return FAILED; |
| 505 | } |
| 506 | EXPORT_SYMBOL_GPL(sas_eh_abort_handler); |
| 507 | |
Darrick J. Wong | a9344e6 | 2007-01-29 23:48:19 -0800 | [diff] [blame] | 508 | /* Attempt to send a LUN reset message to a device */ |
Darrick J. Wong | ad68923 | 2007-01-26 14:08:52 -0800 | [diff] [blame] | 509 | int sas_eh_device_reset_handler(struct scsi_cmnd *cmd) |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 510 | { |
Darrick J. Wong | a9344e6 | 2007-01-29 23:48:19 -0800 | [diff] [blame] | 511 | int res; |
Dan Williams | 5db45bd | 2012-06-21 23:30:48 -0700 | [diff] [blame] | 512 | struct scsi_lun lun; |
| 513 | struct Scsi_Host *host = cmd->device->host; |
| 514 | struct domain_device *dev = cmd_to_domain_dev(cmd); |
| 515 | struct sas_internal *i = to_sas_internal(host->transportt); |
| 516 | |
| 517 | if (current != host->ehandler) |
| 518 | return sas_queue_reset(dev, SAS_DEV_LU_RESET, cmd->device->lun, 0); |
Darrick J. Wong | a9344e6 | 2007-01-29 23:48:19 -0800 | [diff] [blame] | 519 | |
| 520 | int_to_scsilun(cmd->device->lun, &lun); |
| 521 | |
| 522 | if (!i->dft->lldd_lu_reset) |
| 523 | return FAILED; |
| 524 | |
| 525 | res = i->dft->lldd_lu_reset(dev, lun.scsi_lun); |
| 526 | if (res == TMF_RESP_FUNC_SUCC || res == TMF_RESP_FUNC_COMPLETE) |
| 527 | return SUCCESS; |
| 528 | |
| 529 | return FAILED; |
| 530 | } |
| 531 | |
Darrick J. Wong | a9344e6 | 2007-01-29 23:48:19 -0800 | [diff] [blame] | 532 | int sas_eh_bus_reset_handler(struct scsi_cmnd *cmd) |
| 533 | { |
Darrick J. Wong | ad68923 | 2007-01-26 14:08:52 -0800 | [diff] [blame] | 534 | int res; |
Dan Williams | e7db822 | 2012-06-21 23:30:58 -0700 | [diff] [blame] | 535 | struct Scsi_Host *host = cmd->device->host; |
| 536 | struct domain_device *dev = cmd_to_domain_dev(cmd); |
| 537 | struct sas_internal *i = to_sas_internal(host->transportt); |
Darrick J. Wong | ad68923 | 2007-01-26 14:08:52 -0800 | [diff] [blame] | 538 | |
Dan Williams | 5db45bd | 2012-06-21 23:30:48 -0700 | [diff] [blame] | 539 | if (current != host->ehandler) |
| 540 | return sas_queue_reset(dev, SAS_DEV_RESET, 0, 0); |
| 541 | |
Dan Williams | e7db822 | 2012-06-21 23:30:58 -0700 | [diff] [blame] | 542 | if (!i->dft->lldd_I_T_nexus_reset) |
| 543 | return FAILED; |
Dan Williams | f41a0c4 | 2011-12-21 21:33:17 -0800 | [diff] [blame] | 544 | |
Dan Williams | e7db822 | 2012-06-21 23:30:58 -0700 | [diff] [blame] | 545 | res = i->dft->lldd_I_T_nexus_reset(dev); |
| 546 | if (res == TMF_RESP_FUNC_SUCC || res == TMF_RESP_FUNC_COMPLETE || |
| 547 | res == -ENODEV) |
Darrick J. Wong | ad68923 | 2007-01-26 14:08:52 -0800 | [diff] [blame] | 548 | return SUCCESS; |
| 549 | |
| 550 | return FAILED; |
| 551 | } |
| 552 | |
| 553 | /* Try to reset a device */ |
James Bottomley | 8de3ef2 | 2008-02-23 23:39:59 -0600 | [diff] [blame] | 554 | static int try_to_reset_cmd_device(struct scsi_cmnd *cmd) |
Darrick J. Wong | ad68923 | 2007-01-26 14:08:52 -0800 | [diff] [blame] | 555 | { |
Darrick J. Wong | a9344e6 | 2007-01-29 23:48:19 -0800 | [diff] [blame] | 556 | int res; |
James Bottomley | 8de3ef2 | 2008-02-23 23:39:59 -0600 | [diff] [blame] | 557 | struct Scsi_Host *shost = cmd->device->host; |
Darrick J. Wong | ad68923 | 2007-01-26 14:08:52 -0800 | [diff] [blame] | 558 | |
Darrick J. Wong | a9344e6 | 2007-01-29 23:48:19 -0800 | [diff] [blame] | 559 | if (!shost->hostt->eh_device_reset_handler) |
| 560 | goto try_bus_reset; |
| 561 | |
| 562 | res = shost->hostt->eh_device_reset_handler(cmd); |
| 563 | if (res == SUCCESS) |
| 564 | return res; |
| 565 | |
| 566 | try_bus_reset: |
| 567 | if (shost->hostt->eh_bus_reset_handler) |
| 568 | return shost->hostt->eh_bus_reset_handler(cmd); |
| 569 | |
| 570 | return FAILED; |
Darrick J. Wong | ad68923 | 2007-01-26 14:08:52 -0800 | [diff] [blame] | 571 | } |
| 572 | |
Dan Williams | 8402347 | 2012-01-20 15:23:07 -0800 | [diff] [blame] | 573 | static void sas_eh_handle_sas_errors(struct Scsi_Host *shost, struct list_head *work_q) |
Darrick J. Wong | ad68923 | 2007-01-26 14:08:52 -0800 | [diff] [blame] | 574 | { |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 575 | struct scsi_cmnd *cmd, *n; |
| 576 | enum task_disposition res = TASK_IS_DONE; |
Darrick J. Wong | 3ebf692 | 2007-01-11 14:15:17 -0800 | [diff] [blame] | 577 | int tmf_resp, need_reset; |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 578 | struct sas_internal *i = to_sas_internal(shost->transportt); |
Darrick J. Wong | ad68923 | 2007-01-26 14:08:52 -0800 | [diff] [blame] | 579 | unsigned long flags; |
| 580 | struct sas_ha_struct *ha = SHOST_TO_SAS_HA(shost); |
Dan Williams | 45c73b6 | 2012-01-09 10:12:52 -0800 | [diff] [blame] | 581 | LIST_HEAD(done); |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 582 | |
Dan Williams | 45c73b6 | 2012-01-09 10:12:52 -0800 | [diff] [blame] | 583 | /* clean out any commands that won the completion vs eh race */ |
Darrick J. Wong | ad68923 | 2007-01-26 14:08:52 -0800 | [diff] [blame] | 584 | list_for_each_entry_safe(cmd, n, work_q, eh_entry) { |
Dan Williams | 9095a64 | 2011-11-28 11:29:20 -0800 | [diff] [blame] | 585 | struct domain_device *dev = cmd_to_domain_dev(cmd); |
| 586 | struct sas_task *task; |
| 587 | |
| 588 | spin_lock_irqsave(&dev->done_lock, flags); |
| 589 | /* by this point the lldd has either observed |
| 590 | * SAS_HA_FROZEN and is leaving the task alone, or has |
| 591 | * won the race with eh and decided to complete it |
| 592 | */ |
| 593 | task = TO_SAS_TASK(cmd); |
| 594 | spin_unlock_irqrestore(&dev->done_lock, flags); |
Darrick J. Wong | f456393 | 2006-10-30 15:18:39 -0800 | [diff] [blame] | 595 | |
Darrick J. Wong | ad68923 | 2007-01-26 14:08:52 -0800 | [diff] [blame] | 596 | if (!task) |
Dan Williams | 45c73b6 | 2012-01-09 10:12:52 -0800 | [diff] [blame] | 597 | list_move_tail(&cmd->eh_entry, &done); |
| 598 | } |
| 599 | |
| 600 | Again: |
| 601 | list_for_each_entry_safe(cmd, n, work_q, eh_entry) { |
| 602 | struct sas_task *task = TO_SAS_TASK(cmd); |
Darrick J. Wong | ad68923 | 2007-01-26 14:08:52 -0800 | [diff] [blame] | 603 | |
| 604 | list_del_init(&cmd->eh_entry); |
Darrick J. Wong | 3ebf692 | 2007-01-11 14:15:17 -0800 | [diff] [blame] | 605 | |
| 606 | spin_lock_irqsave(&task->task_state_lock, flags); |
| 607 | need_reset = task->task_state_flags & SAS_TASK_NEED_DEV_RESET; |
Darrick J. Wong | 3ebf692 | 2007-01-11 14:15:17 -0800 | [diff] [blame] | 608 | spin_unlock_irqrestore(&task->task_state_lock, flags); |
| 609 | |
James Bottomley | 8de3ef2 | 2008-02-23 23:39:59 -0600 | [diff] [blame] | 610 | if (need_reset) { |
| 611 | SAS_DPRINTK("%s: task 0x%p requests reset\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 612 | __func__, task); |
James Bottomley | 8de3ef2 | 2008-02-23 23:39:59 -0600 | [diff] [blame] | 613 | goto reset; |
| 614 | } |
| 615 | |
Darrick J. Wong | f456393 | 2006-10-30 15:18:39 -0800 | [diff] [blame] | 616 | SAS_DPRINTK("trying to find task 0x%p\n", task); |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 617 | res = sas_scsi_find_task(task); |
| 618 | |
| 619 | cmd->eh_eflags = 0; |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 620 | |
| 621 | switch (res) { |
| 622 | case TASK_IS_DONE: |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 623 | SAS_DPRINTK("%s: task 0x%p is done\n", __func__, |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 624 | task); |
Dan Williams | 3944f50 | 2011-11-29 12:08:50 -0800 | [diff] [blame] | 625 | sas_eh_defer_cmd(cmd); |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 626 | continue; |
| 627 | case TASK_IS_ABORTED: |
| 628 | SAS_DPRINTK("%s: task 0x%p is aborted\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 629 | __func__, task); |
Dan Williams | 3944f50 | 2011-11-29 12:08:50 -0800 | [diff] [blame] | 630 | sas_eh_defer_cmd(cmd); |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 631 | continue; |
| 632 | case TASK_IS_AT_LU: |
| 633 | SAS_DPRINTK("task 0x%p is at LU: lu recover\n", task); |
James Bottomley | 8de3ef2 | 2008-02-23 23:39:59 -0600 | [diff] [blame] | 634 | reset: |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 635 | tmf_resp = sas_recover_lu(task->dev, cmd); |
| 636 | if (tmf_resp == TMF_RESP_FUNC_COMPLETE) { |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 637 | SAS_DPRINTK("dev %016llx LU %llx is " |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 638 | "recovered\n", |
| 639 | SAS_ADDR(task->dev), |
| 640 | cmd->device->lun); |
Dan Williams | 3a2cdf3 | 2011-11-29 14:54:28 -0800 | [diff] [blame] | 641 | sas_eh_defer_cmd(cmd); |
Darrick J. Wong | ad68923 | 2007-01-26 14:08:52 -0800 | [diff] [blame] | 642 | sas_scsi_clear_queue_lu(work_q, cmd); |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 643 | goto Again; |
| 644 | } |
| 645 | /* fallthrough */ |
| 646 | case TASK_IS_NOT_AT_LU: |
Darrick J. Wong | 02cd743 | 2007-01-11 14:15:46 -0800 | [diff] [blame] | 647 | case TASK_ABORT_FAILED: |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 648 | SAS_DPRINTK("task 0x%p is not at LU: I_T recover\n", |
| 649 | task); |
| 650 | tmf_resp = sas_recover_I_T(task->dev); |
Dan Williams | 26a2e68 | 2012-01-30 21:40:45 -0800 | [diff] [blame] | 651 | if (tmf_resp == TMF_RESP_FUNC_COMPLETE || |
| 652 | tmf_resp == -ENODEV) { |
James Bottomley | 8de3ef2 | 2008-02-23 23:39:59 -0600 | [diff] [blame] | 653 | struct domain_device *dev = task->dev; |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 654 | SAS_DPRINTK("I_T %016llx recovered\n", |
| 655 | SAS_ADDR(task->dev->sas_addr)); |
James Bottomley | a8e14fe | 2008-02-19 21:48:42 -0600 | [diff] [blame] | 656 | sas_eh_finish_cmd(cmd); |
James Bottomley | 8de3ef2 | 2008-02-23 23:39:59 -0600 | [diff] [blame] | 657 | sas_scsi_clear_queue_I_T(work_q, dev); |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 658 | goto Again; |
| 659 | } |
| 660 | /* Hammer time :-) */ |
James Bottomley | 8de3ef2 | 2008-02-23 23:39:59 -0600 | [diff] [blame] | 661 | try_to_reset_cmd_device(cmd); |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 662 | if (i->dft->lldd_clear_nexus_port) { |
| 663 | struct asd_sas_port *port = task->dev->port; |
| 664 | SAS_DPRINTK("clearing nexus for port:%d\n", |
| 665 | port->id); |
| 666 | res = i->dft->lldd_clear_nexus_port(port); |
| 667 | if (res == TMF_RESP_FUNC_COMPLETE) { |
| 668 | SAS_DPRINTK("clear nexus port:%d " |
| 669 | "succeeded\n", port->id); |
James Bottomley | a8e14fe | 2008-02-19 21:48:42 -0600 | [diff] [blame] | 670 | sas_eh_finish_cmd(cmd); |
Darrick J. Wong | ad68923 | 2007-01-26 14:08:52 -0800 | [diff] [blame] | 671 | sas_scsi_clear_queue_port(work_q, |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 672 | port); |
| 673 | goto Again; |
| 674 | } |
| 675 | } |
| 676 | if (i->dft->lldd_clear_nexus_ha) { |
| 677 | SAS_DPRINTK("clear nexus ha\n"); |
| 678 | res = i->dft->lldd_clear_nexus_ha(ha); |
| 679 | if (res == TMF_RESP_FUNC_COMPLETE) { |
| 680 | SAS_DPRINTK("clear nexus ha " |
| 681 | "succeeded\n"); |
James Bottomley | a8e14fe | 2008-02-19 21:48:42 -0600 | [diff] [blame] | 682 | sas_eh_finish_cmd(cmd); |
James Bottomley | a8e14fe | 2008-02-19 21:48:42 -0600 | [diff] [blame] | 683 | goto clear_q; |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 684 | } |
| 685 | } |
| 686 | /* If we are here -- this means that no amount |
| 687 | * of effort could recover from errors. Quite |
| 688 | * possibly the HA just disappeared. |
| 689 | */ |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 690 | SAS_DPRINTK("error from device %llx, LUN %llx " |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 691 | "couldn't be recovered in any way\n", |
| 692 | SAS_ADDR(task->dev->sas_addr), |
| 693 | cmd->device->lun); |
| 694 | |
James Bottomley | a8e14fe | 2008-02-19 21:48:42 -0600 | [diff] [blame] | 695 | sas_eh_finish_cmd(cmd); |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 696 | goto clear_q; |
| 697 | } |
| 698 | } |
Dan Williams | 45c73b6 | 2012-01-09 10:12:52 -0800 | [diff] [blame] | 699 | out: |
| 700 | list_splice_tail(&done, work_q); |
Dan Williams | 3944f50 | 2011-11-29 12:08:50 -0800 | [diff] [blame] | 701 | list_splice_tail_init(&ha->eh_ata_q, work_q); |
Dan Williams | 8402347 | 2012-01-20 15:23:07 -0800 | [diff] [blame] | 702 | return; |
Dan Williams | 45c73b6 | 2012-01-09 10:12:52 -0800 | [diff] [blame] | 703 | |
| 704 | clear_q: |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 705 | SAS_DPRINTK("--- Exit %s -- clear_q\n", __func__); |
James Bottomley | a8e14fe | 2008-02-19 21:48:42 -0600 | [diff] [blame] | 706 | list_for_each_entry_safe(cmd, n, work_q, eh_entry) |
| 707 | sas_eh_finish_cmd(cmd); |
Dan Williams | 45c73b6 | 2012-01-09 10:12:52 -0800 | [diff] [blame] | 708 | goto out; |
Darrick J. Wong | ad68923 | 2007-01-26 14:08:52 -0800 | [diff] [blame] | 709 | } |
| 710 | |
Dan Williams | 5db45bd | 2012-06-21 23:30:48 -0700 | [diff] [blame] | 711 | static void sas_eh_handle_resets(struct Scsi_Host *shost) |
| 712 | { |
| 713 | struct sas_ha_struct *ha = SHOST_TO_SAS_HA(shost); |
| 714 | struct sas_internal *i = to_sas_internal(shost->transportt); |
| 715 | |
| 716 | /* handle directed resets to sas devices */ |
| 717 | spin_lock_irq(&ha->lock); |
| 718 | while (!list_empty(&ha->eh_dev_q)) { |
| 719 | struct domain_device *dev; |
| 720 | struct ssp_device *ssp; |
| 721 | |
| 722 | ssp = list_entry(ha->eh_dev_q.next, typeof(*ssp), eh_list_node); |
| 723 | list_del_init(&ssp->eh_list_node); |
| 724 | dev = container_of(ssp, typeof(*dev), ssp_dev); |
| 725 | kref_get(&dev->kref); |
| 726 | WARN_ONCE(dev_is_sata(dev), "ssp reset to ata device?\n"); |
| 727 | |
| 728 | spin_unlock_irq(&ha->lock); |
| 729 | |
| 730 | if (test_and_clear_bit(SAS_DEV_LU_RESET, &dev->state)) |
| 731 | i->dft->lldd_lu_reset(dev, ssp->reset_lun.scsi_lun); |
| 732 | |
| 733 | if (test_and_clear_bit(SAS_DEV_RESET, &dev->state)) |
| 734 | i->dft->lldd_I_T_nexus_reset(dev); |
| 735 | |
| 736 | sas_put_device(dev); |
| 737 | spin_lock_irq(&ha->lock); |
| 738 | clear_bit(SAS_DEV_EH_PENDING, &dev->state); |
| 739 | ha->eh_active--; |
| 740 | } |
| 741 | spin_unlock_irq(&ha->lock); |
| 742 | } |
| 743 | |
Dan Williams | e4a9c37 | 2012-06-21 23:25:27 -0700 | [diff] [blame] | 744 | |
Darrick J. Wong | ad68923 | 2007-01-26 14:08:52 -0800 | [diff] [blame] | 745 | void sas_scsi_recover_host(struct Scsi_Host *shost) |
| 746 | { |
| 747 | struct sas_ha_struct *ha = SHOST_TO_SAS_HA(shost); |
Darrick J. Wong | ad68923 | 2007-01-26 14:08:52 -0800 | [diff] [blame] | 748 | LIST_HEAD(eh_work_q); |
Dan Williams | e4a9c37 | 2012-06-21 23:25:27 -0700 | [diff] [blame] | 749 | int tries = 0; |
| 750 | bool retry; |
Darrick J. Wong | ad68923 | 2007-01-26 14:08:52 -0800 | [diff] [blame] | 751 | |
Dan Williams | e4a9c37 | 2012-06-21 23:25:27 -0700 | [diff] [blame] | 752 | retry: |
| 753 | tries++; |
| 754 | retry = true; |
| 755 | spin_lock_irq(shost->host_lock); |
Darrick J. Wong | ad68923 | 2007-01-26 14:08:52 -0800 | [diff] [blame] | 756 | list_splice_init(&shost->eh_cmd_q, &eh_work_q); |
Dan Williams | e4a9c37 | 2012-06-21 23:25:27 -0700 | [diff] [blame] | 757 | spin_unlock_irq(shost->host_lock); |
Darrick J. Wong | ad68923 | 2007-01-26 14:08:52 -0800 | [diff] [blame] | 758 | |
Dan Williams | d230ce6 | 2012-01-11 12:08:36 -0800 | [diff] [blame] | 759 | SAS_DPRINTK("Enter %s busy: %d failed: %d\n", |
Christoph Hellwig | 7466501 | 2014-01-22 15:29:29 +0100 | [diff] [blame] | 760 | __func__, atomic_read(&shost->host_busy), shost->host_failed); |
Darrick J. Wong | ad68923 | 2007-01-26 14:08:52 -0800 | [diff] [blame] | 761 | /* |
| 762 | * Deal with commands that still have SAS tasks (i.e. they didn't |
Dan Williams | 8402347 | 2012-01-20 15:23:07 -0800 | [diff] [blame] | 763 | * complete via the normal sas_task completion mechanism), |
| 764 | * SAS_HA_FROZEN gives eh dominion over all sas_task completion. |
Darrick J. Wong | ad68923 | 2007-01-26 14:08:52 -0800 | [diff] [blame] | 765 | */ |
Dan Williams | 9095a64 | 2011-11-28 11:29:20 -0800 | [diff] [blame] | 766 | set_bit(SAS_HA_FROZEN, &ha->state); |
Dan Williams | 8402347 | 2012-01-20 15:23:07 -0800 | [diff] [blame] | 767 | sas_eh_handle_sas_errors(shost, &eh_work_q); |
| 768 | clear_bit(SAS_HA_FROZEN, &ha->state); |
| 769 | if (list_empty(&eh_work_q)) |
Darrick J. Wong | ad68923 | 2007-01-26 14:08:52 -0800 | [diff] [blame] | 770 | goto out; |
| 771 | |
| 772 | /* |
| 773 | * Now deal with SCSI commands that completed ok but have a an error |
| 774 | * code (and hopefully sense data) attached. This is roughly what |
| 775 | * scsi_unjam_host does, but we skip scsi_eh_abort_cmds because any |
| 776 | * command we see here has no sas_task and is thus unknown to the HA. |
| 777 | */ |
Dan Williams | d230ce6 | 2012-01-11 12:08:36 -0800 | [diff] [blame] | 778 | sas_ata_eh(shost, &eh_work_q, &ha->eh_done_q); |
| 779 | if (!scsi_eh_get_sense(&eh_work_q, &ha->eh_done_q)) |
| 780 | 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] | 781 | |
| 782 | out: |
Dan Williams | 5db45bd | 2012-06-21 23:30:48 -0700 | [diff] [blame] | 783 | sas_eh_handle_resets(shost); |
| 784 | |
James Bottomley | 00dd499 | 2011-01-23 09:44:12 -0600 | [diff] [blame] | 785 | /* now link into libata eh --- if we have any ata devices */ |
| 786 | sas_ata_strategy_handler(shost); |
| 787 | |
Darrick J. Wong | ad68923 | 2007-01-26 14:08:52 -0800 | [diff] [blame] | 788 | scsi_eh_flush_done_q(&ha->eh_done_q); |
James Bottomley | 00dd499 | 2011-01-23 09:44:12 -0600 | [diff] [blame] | 789 | |
Dan Williams | e4a9c37 | 2012-06-21 23:25:27 -0700 | [diff] [blame] | 790 | /* check if any new eh work was scheduled during the last run */ |
| 791 | spin_lock_irq(&ha->lock); |
| 792 | if (ha->eh_active == 0) { |
| 793 | shost->host_eh_scheduled = 0; |
| 794 | retry = false; |
| 795 | } |
| 796 | spin_unlock_irq(&ha->lock); |
| 797 | |
| 798 | if (retry) |
| 799 | goto retry; |
| 800 | |
| 801 | SAS_DPRINTK("--- Exit %s: busy: %d failed: %d tries: %d\n", |
Christoph Hellwig | 7466501 | 2014-01-22 15:29:29 +0100 | [diff] [blame] | 802 | __func__, atomic_read(&shost->host_busy), |
| 803 | shost->host_failed, tries); |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 804 | } |
| 805 | |
Jens Axboe | 242f9dc | 2008-09-14 05:55:09 -0700 | [diff] [blame] | 806 | 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] | 807 | { |
Dan Williams | 3af74a3 | 2014-02-06 12:23:07 -0800 | [diff] [blame] | 808 | scmd_dbg(cmd, "command %p timed out\n", cmd); |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 809 | |
Jens Axboe | 242f9dc | 2008-09-14 05:55:09 -0700 | [diff] [blame] | 810 | return BLK_EH_NOT_HANDLED; |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 811 | } |
| 812 | |
Darrick J. Wong | fa1c1e8 | 2006-08-10 19:19:47 -0700 | [diff] [blame] | 813 | int sas_ioctl(struct scsi_device *sdev, int cmd, void __user *arg) |
| 814 | { |
| 815 | struct domain_device *dev = sdev_to_domain_dev(sdev); |
| 816 | |
| 817 | if (dev_is_sata(dev)) |
Jeff Garzik | 94be9a5 | 2009-01-16 10:17:09 -0500 | [diff] [blame] | 818 | 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] | 819 | |
| 820 | return -EINVAL; |
| 821 | } |
| 822 | |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 823 | struct domain_device *sas_find_dev_by_rphy(struct sas_rphy *rphy) |
| 824 | { |
| 825 | struct Scsi_Host *shost = dev_to_shost(rphy->dev.parent); |
| 826 | struct sas_ha_struct *ha = SHOST_TO_SAS_HA(shost); |
| 827 | struct domain_device *found_dev = NULL; |
| 828 | int i; |
Darrick J. Wong | 980fa2f | 2007-01-11 14:15:40 -0800 | [diff] [blame] | 829 | unsigned long flags; |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 830 | |
Darrick J. Wong | 980fa2f | 2007-01-11 14:15:40 -0800 | [diff] [blame] | 831 | spin_lock_irqsave(&ha->phy_port_lock, flags); |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 832 | for (i = 0; i < ha->num_phys; i++) { |
| 833 | struct asd_sas_port *port = ha->sas_port[i]; |
| 834 | struct domain_device *dev; |
| 835 | |
| 836 | spin_lock(&port->dev_list_lock); |
| 837 | list_for_each_entry(dev, &port->dev_list, dev_list_node) { |
| 838 | if (rphy == dev->rphy) { |
| 839 | found_dev = dev; |
| 840 | spin_unlock(&port->dev_list_lock); |
| 841 | goto found; |
| 842 | } |
| 843 | } |
| 844 | spin_unlock(&port->dev_list_lock); |
| 845 | } |
| 846 | found: |
Darrick J. Wong | 980fa2f | 2007-01-11 14:15:40 -0800 | [diff] [blame] | 847 | spin_unlock_irqrestore(&ha->phy_port_lock, flags); |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 848 | |
| 849 | return found_dev; |
| 850 | } |
| 851 | |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 852 | int sas_target_alloc(struct scsi_target *starget) |
| 853 | { |
Dan Williams | 735f7d2 | 2011-11-17 17:59:47 -0800 | [diff] [blame] | 854 | struct sas_rphy *rphy = dev_to_rphy(starget->dev.parent); |
| 855 | struct domain_device *found_dev = sas_find_dev_by_rphy(rphy); |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 856 | |
| 857 | if (!found_dev) |
| 858 | return -ENODEV; |
| 859 | |
Dan Williams | 735f7d2 | 2011-11-17 17:59:47 -0800 | [diff] [blame] | 860 | kref_get(&found_dev->kref); |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 861 | starget->hostdata = found_dev; |
| 862 | return 0; |
| 863 | } |
| 864 | |
Dan Williams | 97a1420 | 2011-09-20 15:10:46 -0700 | [diff] [blame] | 865 | #define SAS_DEF_QD 256 |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 866 | |
| 867 | int sas_slave_configure(struct scsi_device *scsi_dev) |
| 868 | { |
| 869 | struct domain_device *dev = sdev_to_domain_dev(scsi_dev); |
| 870 | struct sas_ha_struct *sas_ha; |
| 871 | |
| 872 | BUG_ON(dev->rphy->identify.device_type != SAS_END_DEVICE); |
| 873 | |
Darrick J. Wong | fa1c1e8 | 2006-08-10 19:19:47 -0700 | [diff] [blame] | 874 | if (dev_is_sata(dev)) { |
| 875 | ata_sas_slave_configure(scsi_dev, dev->sata_dev.ap); |
| 876 | return 0; |
| 877 | } |
| 878 | |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 879 | sas_ha = dev->port->ha; |
| 880 | |
| 881 | sas_read_port_mode_page(scsi_dev); |
| 882 | |
| 883 | if (scsi_dev->tagged_supported) { |
Christoph Hellwig | db5ed4d | 2014-11-13 15:08:42 +0100 | [diff] [blame] | 884 | scsi_change_queue_depth(scsi_dev, SAS_DEF_QD); |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 885 | } else { |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 886 | SAS_DPRINTK("device %llx, LUN %llx doesn't support " |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 887 | "TCQ\n", SAS_ADDR(dev->sas_addr), |
| 888 | scsi_dev->lun); |
Christoph Hellwig | db5ed4d | 2014-11-13 15:08:42 +0100 | [diff] [blame] | 889 | scsi_change_queue_depth(scsi_dev, 1); |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 890 | } |
| 891 | |
Darrick J. Wong | f27708f | 2007-01-26 14:08:58 -0800 | [diff] [blame] | 892 | scsi_dev->allow_restart = 1; |
| 893 | |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 894 | return 0; |
| 895 | } |
| 896 | |
Christoph Hellwig | db5ed4d | 2014-11-13 15:08:42 +0100 | [diff] [blame] | 897 | int sas_change_queue_depth(struct scsi_device *sdev, int depth) |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 898 | { |
Dan Williams | 97a1420 | 2011-09-20 15:10:46 -0700 | [diff] [blame] | 899 | struct domain_device *dev = sdev_to_domain_dev(sdev); |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 900 | |
Dan Williams | f6e6703 | 2011-09-20 15:10:33 -0700 | [diff] [blame] | 901 | if (dev_is_sata(dev)) |
Christoph Hellwig | db5ed4d | 2014-11-13 15:08:42 +0100 | [diff] [blame] | 902 | return __ata_change_queue_depth(dev->sata_dev.ap, sdev, depth); |
Dan Williams | f6e6703 | 2011-09-20 15:10:33 -0700 | [diff] [blame] | 903 | |
Christoph Hellwig | c40ecc1 | 2014-11-13 14:25:11 +0100 | [diff] [blame] | 904 | if (!sdev->tagged_supported) |
| 905 | depth = 1; |
Christoph Hellwig | db5ed4d | 2014-11-13 15:08:42 +0100 | [diff] [blame] | 906 | return scsi_change_queue_depth(sdev, depth); |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 907 | } |
| 908 | |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 909 | int sas_bios_param(struct scsi_device *scsi_dev, |
| 910 | struct block_device *bdev, |
| 911 | sector_t capacity, int *hsc) |
| 912 | { |
| 913 | hsc[0] = 255; |
| 914 | hsc[1] = 63; |
| 915 | sector_div(capacity, 255*63); |
| 916 | hsc[2] = capacity; |
| 917 | |
| 918 | return 0; |
| 919 | } |
| 920 | |
Darrick J. Wong | 396819f | 2007-01-11 14:15:20 -0800 | [diff] [blame] | 921 | /* |
Darrick J. Wong | 396819f | 2007-01-11 14:15:20 -0800 | [diff] [blame] | 922 | * Tell an upper layer that it needs to initiate an abort for a given task. |
| 923 | * This should only ever be called by an LLDD. |
| 924 | */ |
| 925 | void sas_task_abort(struct sas_task *task) |
Darrick J. Wong | 79a5eb6 | 2006-10-30 15:18:50 -0800 | [diff] [blame] | 926 | { |
Darrick J. Wong | 396819f | 2007-01-11 14:15:20 -0800 | [diff] [blame] | 927 | struct scsi_cmnd *sc = task->uldd_task; |
Darrick J. Wong | 79a5eb6 | 2006-10-30 15:18:50 -0800 | [diff] [blame] | 928 | |
Darrick J. Wong | 396819f | 2007-01-11 14:15:20 -0800 | [diff] [blame] | 929 | /* Escape for libsas internal commands */ |
| 930 | if (!sc) { |
Dan Williams | f0bf750 | 2012-06-21 23:36:30 -0700 | [diff] [blame] | 931 | struct sas_task_slow *slow = task->slow_task; |
| 932 | |
| 933 | if (!slow) |
Darrick J. Wong | 79a5eb6 | 2006-10-30 15:18:50 -0800 | [diff] [blame] | 934 | return; |
Dan Williams | f0bf750 | 2012-06-21 23:36:30 -0700 | [diff] [blame] | 935 | if (!del_timer(&slow->timer)) |
| 936 | return; |
| 937 | slow->timer.function(slow->timer.data); |
Darrick J. Wong | 396819f | 2007-01-11 14:15:20 -0800 | [diff] [blame] | 938 | return; |
| 939 | } |
Darrick J. Wong | 79a5eb6 | 2006-10-30 15:18:50 -0800 | [diff] [blame] | 940 | |
Darrick J. Wong | 3a2755a | 2007-01-30 01:18:58 -0800 | [diff] [blame] | 941 | if (dev_is_sata(task->dev)) { |
| 942 | sas_ata_task_abort(task); |
James Bottomley | 1b4d0d8 | 2010-05-13 09:31:54 -0500 | [diff] [blame] | 943 | } else { |
| 944 | struct request_queue *q = sc->device->request_queue; |
| 945 | unsigned long flags; |
Darrick J. Wong | 3a2755a | 2007-01-30 01:18:58 -0800 | [diff] [blame] | 946 | |
James Bottomley | 1b4d0d8 | 2010-05-13 09:31:54 -0500 | [diff] [blame] | 947 | spin_lock_irqsave(q->queue_lock, flags); |
| 948 | blk_abort_request(sc->request); |
| 949 | spin_unlock_irqrestore(q->queue_lock, flags); |
James Bottomley | 1b4d0d8 | 2010-05-13 09:31:54 -0500 | [diff] [blame] | 950 | } |
Darrick J. Wong | 79a5eb6 | 2006-10-30 15:18:50 -0800 | [diff] [blame] | 951 | } |
| 952 | |
Darrick J. Wong | fa1c1e8 | 2006-08-10 19:19:47 -0700 | [diff] [blame] | 953 | void sas_target_destroy(struct scsi_target *starget) |
| 954 | { |
Dan Williams | 735f7d2 | 2011-11-17 17:59:47 -0800 | [diff] [blame] | 955 | struct domain_device *found_dev = starget->hostdata; |
Darrick J. Wong | fa1c1e8 | 2006-08-10 19:19:47 -0700 | [diff] [blame] | 956 | |
| 957 | if (!found_dev) |
| 958 | return; |
| 959 | |
Dan Williams | 735f7d2 | 2011-11-17 17:59:47 -0800 | [diff] [blame] | 960 | starget->hostdata = NULL; |
| 961 | sas_put_device(found_dev); |
Darrick J. Wong | fa1c1e8 | 2006-08-10 19:19:47 -0700 | [diff] [blame] | 962 | } |
| 963 | |
Darrick J. Wong | 45e6cdf | 2008-02-19 10:49:40 -0800 | [diff] [blame] | 964 | static void sas_parse_addr(u8 *sas_addr, const char *p) |
| 965 | { |
| 966 | int i; |
| 967 | for (i = 0; i < SAS_ADDR_SIZE; i++) { |
| 968 | u8 h, l; |
| 969 | if (!*p) |
| 970 | break; |
| 971 | h = isdigit(*p) ? *p-'0' : toupper(*p)-'A'+10; |
| 972 | p++; |
| 973 | l = isdigit(*p) ? *p-'0' : toupper(*p)-'A'+10; |
| 974 | p++; |
| 975 | sas_addr[i] = (h<<4) | l; |
| 976 | } |
| 977 | } |
| 978 | |
| 979 | #define SAS_STRING_ADDR_SIZE 16 |
| 980 | |
| 981 | int sas_request_addr(struct Scsi_Host *shost, u8 *addr) |
| 982 | { |
| 983 | int res; |
| 984 | const struct firmware *fw; |
| 985 | |
| 986 | res = request_firmware(&fw, "sas_addr", &shost->shost_gendev); |
| 987 | if (res) |
| 988 | return res; |
| 989 | |
| 990 | if (fw->size < SAS_STRING_ADDR_SIZE) { |
| 991 | res = -ENODEV; |
| 992 | goto out; |
| 993 | } |
| 994 | |
| 995 | sas_parse_addr(addr, fw->data); |
| 996 | |
| 997 | out: |
| 998 | release_firmware(fw); |
| 999 | return res; |
| 1000 | } |
| 1001 | EXPORT_SYMBOL_GPL(sas_request_addr); |
| 1002 | |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 1003 | EXPORT_SYMBOL_GPL(sas_queuecommand); |
| 1004 | EXPORT_SYMBOL_GPL(sas_target_alloc); |
| 1005 | EXPORT_SYMBOL_GPL(sas_slave_configure); |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 1006 | EXPORT_SYMBOL_GPL(sas_change_queue_depth); |
James Bottomley | 2908d77 | 2006-08-29 09:22:51 -0500 | [diff] [blame] | 1007 | EXPORT_SYMBOL_GPL(sas_bios_param); |
Darrick J. Wong | 79a5eb6 | 2006-10-30 15:18:50 -0800 | [diff] [blame] | 1008 | EXPORT_SYMBOL_GPL(sas_task_abort); |
Darrick J. Wong | dea2221 | 2006-11-07 17:28:55 -0800 | [diff] [blame] | 1009 | EXPORT_SYMBOL_GPL(sas_phy_reset); |
Darrick J. Wong | ad68923 | 2007-01-26 14:08:52 -0800 | [diff] [blame] | 1010 | EXPORT_SYMBOL_GPL(sas_eh_device_reset_handler); |
Darrick J. Wong | a9344e6 | 2007-01-29 23:48:19 -0800 | [diff] [blame] | 1011 | EXPORT_SYMBOL_GPL(sas_eh_bus_reset_handler); |
Darrick J. Wong | fa1c1e8 | 2006-08-10 19:19:47 -0700 | [diff] [blame] | 1012 | EXPORT_SYMBOL_GPL(sas_target_destroy); |
| 1013 | EXPORT_SYMBOL_GPL(sas_ioctl); |