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