Darrick J. Wong | 338ec57 | 2006-10-18 14:43:37 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Support for SATA devices on Serial Attached SCSI (SAS) controllers |
| 3 | * |
| 4 | * Copyright (C) 2006 IBM Corporation |
| 5 | * |
| 6 | * Written by: Darrick J. Wong <djwong@us.ibm.com>, IBM Corporation |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU General Public License as |
| 10 | * published by the Free Software Foundation; either version 2 of the |
| 11 | * License, or (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, but |
| 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 | * General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
| 21 | * USA |
| 22 | */ |
| 23 | |
James Bottomley | b914217 | 2007-07-22 13:15:55 -0500 | [diff] [blame] | 24 | #include <linux/scatterlist.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 25 | #include <linux/slab.h> |
Dan Williams | 50824d6 | 2011-12-04 01:06:24 -0800 | [diff] [blame] | 26 | #include <linux/async.h> |
James Bottomley | b914217 | 2007-07-22 13:15:55 -0500 | [diff] [blame] | 27 | |
Darrick J. Wong | 338ec57 | 2006-10-18 14:43:37 -0700 | [diff] [blame] | 28 | #include <scsi/sas_ata.h> |
| 29 | #include "sas_internal.h" |
| 30 | #include <scsi/scsi_host.h> |
| 31 | #include <scsi/scsi_device.h> |
| 32 | #include <scsi/scsi_tcq.h> |
| 33 | #include <scsi/scsi.h> |
| 34 | #include <scsi/scsi_transport.h> |
| 35 | #include <scsi/scsi_transport_sas.h> |
| 36 | #include "../scsi_sas_internal.h" |
Darrick J. Wong | 3a2755a | 2007-01-30 01:18:58 -0800 | [diff] [blame] | 37 | #include "../scsi_transport_api.h" |
| 38 | #include <scsi/scsi_eh.h> |
Darrick J. Wong | 338ec57 | 2006-10-18 14:43:37 -0700 | [diff] [blame] | 39 | |
| 40 | static enum ata_completion_errors sas_to_ata_err(struct task_status_struct *ts) |
| 41 | { |
| 42 | /* Cheesy attempt to translate SAS errors into ATA. Hah! */ |
| 43 | |
| 44 | /* transport error */ |
| 45 | if (ts->resp == SAS_TASK_UNDELIVERED) |
| 46 | return AC_ERR_ATA_BUS; |
| 47 | |
| 48 | /* ts->resp == SAS_TASK_COMPLETE */ |
| 49 | /* task delivered, what happened afterwards? */ |
| 50 | switch (ts->stat) { |
| 51 | case SAS_DEV_NO_RESPONSE: |
| 52 | return AC_ERR_TIMEOUT; |
| 53 | |
| 54 | case SAS_INTERRUPTED: |
| 55 | case SAS_PHY_DOWN: |
| 56 | case SAS_NAK_R_ERR: |
| 57 | return AC_ERR_ATA_BUS; |
| 58 | |
| 59 | |
| 60 | case SAS_DATA_UNDERRUN: |
| 61 | /* |
| 62 | * Some programs that use the taskfile interface |
| 63 | * (smartctl in particular) can cause underrun |
| 64 | * problems. Ignore these errors, perhaps at our |
| 65 | * peril. |
| 66 | */ |
| 67 | return 0; |
| 68 | |
| 69 | case SAS_DATA_OVERRUN: |
| 70 | case SAS_QUEUE_FULL: |
| 71 | case SAS_DEVICE_UNKNOWN: |
| 72 | case SAS_SG_ERR: |
| 73 | return AC_ERR_INVALID; |
| 74 | |
Darrick J. Wong | 338ec57 | 2006-10-18 14:43:37 -0700 | [diff] [blame] | 75 | case SAS_OPEN_TO: |
| 76 | case SAS_OPEN_REJECT: |
| 77 | SAS_DPRINTK("%s: Saw error %d. What to do?\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 78 | __func__, ts->stat); |
Darrick J. Wong | 338ec57 | 2006-10-18 14:43:37 -0700 | [diff] [blame] | 79 | return AC_ERR_OTHER; |
| 80 | |
James Bottomley | 75c0b38 | 2011-01-23 08:16:24 -0600 | [diff] [blame] | 81 | case SAM_STAT_CHECK_CONDITION: |
Darrick J. Wong | 338ec57 | 2006-10-18 14:43:37 -0700 | [diff] [blame] | 82 | case SAS_ABORTED_TASK: |
| 83 | return AC_ERR_DEV; |
| 84 | |
| 85 | case SAS_PROTO_RESPONSE: |
| 86 | /* This means the ending_fis has the error |
| 87 | * value; return 0 here to collect it */ |
| 88 | return 0; |
| 89 | default: |
| 90 | return 0; |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | static void sas_ata_task_done(struct sas_task *task) |
| 95 | { |
| 96 | struct ata_queued_cmd *qc = task->uldd_task; |
Dan Williams | 9095a64 | 2011-11-28 11:29:20 -0800 | [diff] [blame] | 97 | struct domain_device *dev = task->dev; |
Darrick J. Wong | 338ec57 | 2006-10-18 14:43:37 -0700 | [diff] [blame] | 98 | struct task_status_struct *stat = &task->task_status; |
| 99 | struct ata_task_resp *resp = (struct ata_task_resp *)stat->buf; |
Dan Williams | 9095a64 | 2011-11-28 11:29:20 -0800 | [diff] [blame] | 100 | struct sas_ha_struct *sas_ha = dev->port->ha; |
Darrick J. Wong | 338ec57 | 2006-10-18 14:43:37 -0700 | [diff] [blame] | 101 | enum ata_completion_errors ac; |
Darrick J. Wong | 3eb7a51 | 2007-01-30 01:18:35 -0800 | [diff] [blame] | 102 | unsigned long flags; |
Xiangliang Yu | bb650a1 | 2011-05-08 19:27:01 +0800 | [diff] [blame] | 103 | struct ata_link *link; |
Dan Williams | 3dff572 | 2011-11-28 12:08:22 -0800 | [diff] [blame] | 104 | struct ata_port *ap; |
Darrick J. Wong | 338ec57 | 2006-10-18 14:43:37 -0700 | [diff] [blame] | 105 | |
Dan Williams | 9095a64 | 2011-11-28 11:29:20 -0800 | [diff] [blame] | 106 | spin_lock_irqsave(&dev->done_lock, flags); |
| 107 | if (test_bit(SAS_HA_FROZEN, &sas_ha->state)) |
| 108 | task = NULL; |
| 109 | else if (qc && qc->scsicmd) |
| 110 | ASSIGN_SAS_TASK(qc->scsicmd, NULL); |
| 111 | spin_unlock_irqrestore(&dev->done_lock, flags); |
| 112 | |
| 113 | /* check if libsas-eh got to the task before us */ |
| 114 | if (unlikely(!task)) |
| 115 | return; |
| 116 | |
Darrick J. Wong | 1c50dc8 | 2007-01-30 01:18:41 -0800 | [diff] [blame] | 117 | if (!qc) |
| 118 | goto qc_already_gone; |
| 119 | |
Dan Williams | 3dff572 | 2011-11-28 12:08:22 -0800 | [diff] [blame] | 120 | ap = qc->ap; |
Dan Williams | 3dff572 | 2011-11-28 12:08:22 -0800 | [diff] [blame] | 121 | link = &ap->link; |
Darrick J. Wong | 1c50dc8 | 2007-01-30 01:18:41 -0800 | [diff] [blame] | 122 | |
Dan Williams | 3dff572 | 2011-11-28 12:08:22 -0800 | [diff] [blame] | 123 | spin_lock_irqsave(ap->lock, flags); |
| 124 | /* check if we lost the race with libata/sas_ata_post_internal() */ |
| 125 | if (unlikely(ap->pflags & ATA_PFLAG_FROZEN)) { |
| 126 | spin_unlock_irqrestore(ap->lock, flags); |
| 127 | if (qc->scsicmd) |
| 128 | goto qc_already_gone; |
| 129 | else { |
| 130 | /* if eh is not involved and the port is frozen then the |
| 131 | * ata internal abort process has taken responsibility |
| 132 | * for this sas_task |
| 133 | */ |
| 134 | return; |
| 135 | } |
| 136 | } |
| 137 | |
James Bottomley | 75c0b38 | 2011-01-23 08:16:24 -0600 | [diff] [blame] | 138 | if (stat->stat == SAS_PROTO_RESPONSE || stat->stat == SAM_STAT_GOOD || |
| 139 | ((stat->stat == SAM_STAT_CHECK_CONDITION && |
| 140 | dev->sata_dev.command_set == ATAPI_COMMAND_SET))) { |
Darrick J. Wong | 338ec57 | 2006-10-18 14:43:37 -0700 | [diff] [blame] | 141 | ata_tf_from_fis(resp->ending_fis, &dev->sata_dev.tf); |
Xiangliang Yu | bb650a1 | 2011-05-08 19:27:01 +0800 | [diff] [blame] | 142 | |
| 143 | if (!link->sactive) { |
| 144 | qc->err_mask |= ac_err_mask(dev->sata_dev.tf.command); |
| 145 | } else { |
| 146 | link->eh_info.err_mask |= ac_err_mask(dev->sata_dev.tf.command); |
| 147 | if (unlikely(link->eh_info.err_mask)) |
| 148 | qc->flags |= ATA_QCFLAG_FAILED; |
| 149 | } |
James Bottomley | 75c0b38 | 2011-01-23 08:16:24 -0600 | [diff] [blame] | 150 | } else { |
Darrick J. Wong | 338ec57 | 2006-10-18 14:43:37 -0700 | [diff] [blame] | 151 | ac = sas_to_ata_err(stat); |
| 152 | if (ac) { |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 153 | SAS_DPRINTK("%s: SAS error %x\n", __func__, |
Darrick J. Wong | 338ec57 | 2006-10-18 14:43:37 -0700 | [diff] [blame] | 154 | stat->stat); |
| 155 | /* We saw a SAS error. Send a vague error. */ |
Xiangliang Yu | bb650a1 | 2011-05-08 19:27:01 +0800 | [diff] [blame] | 156 | if (!link->sactive) { |
| 157 | qc->err_mask = ac; |
| 158 | } else { |
| 159 | link->eh_info.err_mask |= AC_ERR_DEV; |
| 160 | qc->flags |= ATA_QCFLAG_FAILED; |
| 161 | } |
| 162 | |
Darrick J. Wong | 338ec57 | 2006-10-18 14:43:37 -0700 | [diff] [blame] | 163 | dev->sata_dev.tf.feature = 0x04; /* status err */ |
| 164 | dev->sata_dev.tf.command = ATA_ERR; |
| 165 | } |
| 166 | } |
| 167 | |
Darrick J. Wong | 1c50dc8 | 2007-01-30 01:18:41 -0800 | [diff] [blame] | 168 | qc->lldd_task = NULL; |
Darrick J. Wong | 338ec57 | 2006-10-18 14:43:37 -0700 | [diff] [blame] | 169 | ata_qc_complete(qc); |
Dan Williams | 3dff572 | 2011-11-28 12:08:22 -0800 | [diff] [blame] | 170 | spin_unlock_irqrestore(ap->lock, flags); |
Darrick J. Wong | 3eb7a51 | 2007-01-30 01:18:35 -0800 | [diff] [blame] | 171 | |
Darrick J. Wong | 1c50dc8 | 2007-01-30 01:18:41 -0800 | [diff] [blame] | 172 | qc_already_gone: |
Darrick J. Wong | 338ec57 | 2006-10-18 14:43:37 -0700 | [diff] [blame] | 173 | list_del_init(&task->list); |
| 174 | sas_free_task(task); |
| 175 | } |
| 176 | |
| 177 | static unsigned int sas_ata_qc_issue(struct ata_queued_cmd *qc) |
| 178 | { |
Dan Williams | 312d3e5 | 2011-11-17 17:59:50 -0800 | [diff] [blame] | 179 | unsigned long flags; |
Darrick J. Wong | 338ec57 | 2006-10-18 14:43:37 -0700 | [diff] [blame] | 180 | struct sas_task *task; |
Dan Williams | 312d3e5 | 2011-11-17 17:59:50 -0800 | [diff] [blame] | 181 | struct scatterlist *sg; |
| 182 | int ret = AC_ERR_SYSTEM; |
| 183 | unsigned int si, xfer = 0; |
| 184 | struct ata_port *ap = qc->ap; |
| 185 | struct domain_device *dev = ap->private_data; |
Darrick J. Wong | 338ec57 | 2006-10-18 14:43:37 -0700 | [diff] [blame] | 186 | struct sas_ha_struct *sas_ha = dev->port->ha; |
| 187 | struct Scsi_Host *host = sas_ha->core.shost; |
| 188 | struct sas_internal *i = to_sas_internal(host->transportt); |
Dan Williams | 312d3e5 | 2011-11-17 17:59:50 -0800 | [diff] [blame] | 189 | |
| 190 | /* TODO: audit callers to ensure they are ready for qc_issue to |
| 191 | * unconditionally re-enable interrupts |
| 192 | */ |
| 193 | local_irq_save(flags); |
| 194 | spin_unlock(ap->lock); |
Darrick J. Wong | 338ec57 | 2006-10-18 14:43:37 -0700 | [diff] [blame] | 195 | |
Darrick J. Wong | 56dd2c0 | 2010-10-01 13:55:47 -0700 | [diff] [blame] | 196 | /* If the device fell off, no sense in issuing commands */ |
Dan Williams | e139942 | 2012-01-07 08:52:39 +0000 | [diff] [blame] | 197 | if (test_bit(SAS_DEV_GONE, &dev->state)) |
Dan Williams | 312d3e5 | 2011-11-17 17:59:50 -0800 | [diff] [blame] | 198 | goto out; |
Darrick J. Wong | 56dd2c0 | 2010-10-01 13:55:47 -0700 | [diff] [blame] | 199 | |
Darrick J. Wong | 338ec57 | 2006-10-18 14:43:37 -0700 | [diff] [blame] | 200 | task = sas_alloc_task(GFP_ATOMIC); |
| 201 | if (!task) |
Dan Williams | 312d3e5 | 2011-11-17 17:59:50 -0800 | [diff] [blame] | 202 | goto out; |
Darrick J. Wong | 338ec57 | 2006-10-18 14:43:37 -0700 | [diff] [blame] | 203 | task->dev = dev; |
| 204 | task->task_proto = SAS_PROTOCOL_STP; |
| 205 | task->task_done = sas_ata_task_done; |
| 206 | |
| 207 | if (qc->tf.command == ATA_CMD_FPDMA_WRITE || |
| 208 | qc->tf.command == ATA_CMD_FPDMA_READ) { |
| 209 | /* Need to zero out the tag libata assigned us */ |
| 210 | qc->tf.nsect = 0; |
| 211 | } |
| 212 | |
James Bottomley | 110dd8f | 2007-07-20 13:11:44 -0500 | [diff] [blame] | 213 | ata_tf_to_fis(&qc->tf, 1, 0, (u8*)&task->ata_task.fis); |
Darrick J. Wong | 338ec57 | 2006-10-18 14:43:37 -0700 | [diff] [blame] | 214 | task->uldd_task = qc; |
Tejun Heo | 405e66b | 2007-11-27 19:28:53 +0900 | [diff] [blame] | 215 | if (ata_is_atapi(qc->tf.protocol)) { |
Darrick J. Wong | 338ec57 | 2006-10-18 14:43:37 -0700 | [diff] [blame] | 216 | memcpy(task->ata_task.atapi_packet, qc->cdb, qc->dev->cdb_len); |
James Bottomley | dde2020 | 2008-02-19 11:36:56 +0100 | [diff] [blame] | 217 | task->total_xfer_len = qc->nbytes; |
| 218 | task->num_scatter = qc->n_elem; |
Darrick J. Wong | 338ec57 | 2006-10-18 14:43:37 -0700 | [diff] [blame] | 219 | } else { |
Tejun Heo | ff2aeb1 | 2007-12-05 16:43:11 +0900 | [diff] [blame] | 220 | for_each_sg(qc->sg, sg, qc->n_elem, si) |
Darrick J. Wong | 338ec57 | 2006-10-18 14:43:37 -0700 | [diff] [blame] | 221 | xfer += sg->length; |
Darrick J. Wong | 338ec57 | 2006-10-18 14:43:37 -0700 | [diff] [blame] | 222 | |
| 223 | task->total_xfer_len = xfer; |
Tejun Heo | ff2aeb1 | 2007-12-05 16:43:11 +0900 | [diff] [blame] | 224 | task->num_scatter = si; |
Darrick J. Wong | 338ec57 | 2006-10-18 14:43:37 -0700 | [diff] [blame] | 225 | } |
| 226 | |
| 227 | task->data_dir = qc->dma_dir; |
Tejun Heo | ff2aeb1 | 2007-12-05 16:43:11 +0900 | [diff] [blame] | 228 | task->scatter = qc->sg; |
Darrick J. Wong | 338ec57 | 2006-10-18 14:43:37 -0700 | [diff] [blame] | 229 | task->ata_task.retry_count = 1; |
| 230 | task->task_state_flags = SAS_TASK_STATE_PENDING; |
Darrick J. Wong | 1c50dc8 | 2007-01-30 01:18:41 -0800 | [diff] [blame] | 231 | qc->lldd_task = task; |
Darrick J. Wong | 338ec57 | 2006-10-18 14:43:37 -0700 | [diff] [blame] | 232 | |
| 233 | switch (qc->tf.protocol) { |
| 234 | case ATA_PROT_NCQ: |
| 235 | task->ata_task.use_ncq = 1; |
| 236 | /* fall through */ |
Tejun Heo | 0dc3688 | 2007-12-18 16:34:43 -0500 | [diff] [blame] | 237 | case ATAPI_PROT_DMA: |
Darrick J. Wong | 338ec57 | 2006-10-18 14:43:37 -0700 | [diff] [blame] | 238 | case ATA_PROT_DMA: |
| 239 | task->ata_task.dma_xfer = 1; |
| 240 | break; |
| 241 | } |
| 242 | |
Darrick J. Wong | fe059f1 | 2007-01-30 01:18:55 -0800 | [diff] [blame] | 243 | if (qc->scsicmd) |
| 244 | ASSIGN_SAS_TASK(qc->scsicmd, task); |
| 245 | |
Darrick J. Wong | 338ec57 | 2006-10-18 14:43:37 -0700 | [diff] [blame] | 246 | if (sas_ha->lldd_max_execute_num < 2) |
Dan Williams | 312d3e5 | 2011-11-17 17:59:50 -0800 | [diff] [blame] | 247 | ret = i->dft->lldd_execute_task(task, 1, GFP_ATOMIC); |
Darrick J. Wong | 338ec57 | 2006-10-18 14:43:37 -0700 | [diff] [blame] | 248 | else |
Dan Williams | 312d3e5 | 2011-11-17 17:59:50 -0800 | [diff] [blame] | 249 | ret = sas_queue_up(task); |
Darrick J. Wong | 338ec57 | 2006-10-18 14:43:37 -0700 | [diff] [blame] | 250 | |
| 251 | /* Examine */ |
Dan Williams | 312d3e5 | 2011-11-17 17:59:50 -0800 | [diff] [blame] | 252 | if (ret) { |
| 253 | SAS_DPRINTK("lldd_execute_task returned: %d\n", ret); |
Darrick J. Wong | 338ec57 | 2006-10-18 14:43:37 -0700 | [diff] [blame] | 254 | |
Darrick J. Wong | fe059f1 | 2007-01-30 01:18:55 -0800 | [diff] [blame] | 255 | if (qc->scsicmd) |
| 256 | ASSIGN_SAS_TASK(qc->scsicmd, NULL); |
Darrick J. Wong | 338ec57 | 2006-10-18 14:43:37 -0700 | [diff] [blame] | 257 | sas_free_task(task); |
Dan Williams | 312d3e5 | 2011-11-17 17:59:50 -0800 | [diff] [blame] | 258 | ret = AC_ERR_SYSTEM; |
Darrick J. Wong | 338ec57 | 2006-10-18 14:43:37 -0700 | [diff] [blame] | 259 | } |
| 260 | |
Dan Williams | 312d3e5 | 2011-11-17 17:59:50 -0800 | [diff] [blame] | 261 | out: |
| 262 | spin_lock(ap->lock); |
| 263 | local_irq_restore(flags); |
| 264 | return ret; |
Darrick J. Wong | 338ec57 | 2006-10-18 14:43:37 -0700 | [diff] [blame] | 265 | } |
| 266 | |
Tejun Heo | 4c9bf4e | 2008-04-07 22:47:20 +0900 | [diff] [blame] | 267 | static bool sas_ata_qc_fill_rtf(struct ata_queued_cmd *qc) |
| 268 | { |
| 269 | struct domain_device *dev = qc->ap->private_data; |
| 270 | |
| 271 | memcpy(&qc->result_tf, &dev->sata_dev.tf, sizeof(qc->result_tf)); |
| 272 | return true; |
| 273 | } |
| 274 | |
Dan Williams | 36a3994 | 2011-11-17 17:59:54 -0800 | [diff] [blame] | 275 | static struct sas_internal *dev_to_sas_internal(struct domain_device *dev) |
| 276 | { |
| 277 | return to_sas_internal(dev->port->ha->core.shost->transportt); |
| 278 | } |
| 279 | |
| 280 | static int smp_ata_check_ready(struct ata_link *link) |
| 281 | { |
| 282 | int res; |
| 283 | u8 addr[8]; |
| 284 | struct ata_port *ap = link->ap; |
| 285 | struct domain_device *dev = ap->private_data; |
| 286 | struct domain_device *ex_dev = dev->parent; |
Dan Williams | f41a0c4 | 2011-12-21 21:33:17 -0800 | [diff] [blame^] | 287 | struct sas_phy *phy = sas_get_local_phy(dev); |
Dan Williams | 36a3994 | 2011-11-17 17:59:54 -0800 | [diff] [blame] | 288 | |
| 289 | res = sas_get_phy_attached_sas_addr(ex_dev, phy->number, addr); |
Dan Williams | f41a0c4 | 2011-12-21 21:33:17 -0800 | [diff] [blame^] | 290 | sas_put_local_phy(phy); |
Dan Williams | 36a3994 | 2011-11-17 17:59:54 -0800 | [diff] [blame] | 291 | /* break the wait early if the expander is unreachable, |
| 292 | * otherwise keep polling |
| 293 | */ |
| 294 | if (res == -ECOMM) |
| 295 | return res; |
| 296 | if (res != SMP_RESP_FUNC_ACC || SAS_ADDR(addr) == 0) |
| 297 | return 0; |
| 298 | else |
| 299 | return 1; |
| 300 | } |
| 301 | |
| 302 | static int local_ata_check_ready(struct ata_link *link) |
Darrick J. Wong | 338ec57 | 2006-10-18 14:43:37 -0700 | [diff] [blame] | 303 | { |
James Bottomley | 00dd499 | 2011-01-23 09:44:12 -0600 | [diff] [blame] | 304 | struct ata_port *ap = link->ap; |
Darrick J. Wong | 338ec57 | 2006-10-18 14:43:37 -0700 | [diff] [blame] | 305 | struct domain_device *dev = ap->private_data; |
Dan Williams | 36a3994 | 2011-11-17 17:59:54 -0800 | [diff] [blame] | 306 | struct sas_internal *i = dev_to_sas_internal(dev); |
Darrick J. Wong | 338ec57 | 2006-10-18 14:43:37 -0700 | [diff] [blame] | 307 | |
Dan Williams | 36a3994 | 2011-11-17 17:59:54 -0800 | [diff] [blame] | 308 | if (i->dft->lldd_ata_check_ready) |
| 309 | return i->dft->lldd_ata_check_ready(dev); |
| 310 | else { |
| 311 | /* lldd's that don't implement 'ready' checking get the |
| 312 | * old default behavior of not coordinating reset |
| 313 | * recovery with libata |
| 314 | */ |
| 315 | return 1; |
James Bottomley | 00dd499 | 2011-01-23 09:44:12 -0600 | [diff] [blame] | 316 | } |
Dan Williams | 36a3994 | 2011-11-17 17:59:54 -0800 | [diff] [blame] | 317 | } |
Darrick J. Wong | 338ec57 | 2006-10-18 14:43:37 -0700 | [diff] [blame] | 318 | |
Dan Williams | 36a3994 | 2011-11-17 17:59:54 -0800 | [diff] [blame] | 319 | static int sas_ata_hard_reset(struct ata_link *link, unsigned int *class, |
| 320 | unsigned long deadline) |
| 321 | { |
| 322 | int ret = 0, res; |
Dan Williams | f41a0c4 | 2011-12-21 21:33:17 -0800 | [diff] [blame^] | 323 | struct sas_phy *phy; |
Dan Williams | 36a3994 | 2011-11-17 17:59:54 -0800 | [diff] [blame] | 324 | struct ata_port *ap = link->ap; |
| 325 | int (*check_ready)(struct ata_link *link); |
| 326 | struct domain_device *dev = ap->private_data; |
Dan Williams | 36a3994 | 2011-11-17 17:59:54 -0800 | [diff] [blame] | 327 | struct sas_internal *i = dev_to_sas_internal(dev); |
| 328 | |
| 329 | res = i->dft->lldd_I_T_nexus_reset(dev); |
| 330 | |
| 331 | if (res != TMF_RESP_FUNC_COMPLETE) |
| 332 | SAS_DPRINTK("%s: Unable to reset ata device?\n", __func__); |
| 333 | |
Dan Williams | f41a0c4 | 2011-12-21 21:33:17 -0800 | [diff] [blame^] | 334 | phy = sas_get_local_phy(dev); |
Dan Williams | 36a3994 | 2011-11-17 17:59:54 -0800 | [diff] [blame] | 335 | if (scsi_is_sas_phy_local(phy)) |
| 336 | check_ready = local_ata_check_ready; |
| 337 | else |
| 338 | check_ready = smp_ata_check_ready; |
Dan Williams | f41a0c4 | 2011-12-21 21:33:17 -0800 | [diff] [blame^] | 339 | sas_put_local_phy(phy); |
Dan Williams | 36a3994 | 2011-11-17 17:59:54 -0800 | [diff] [blame] | 340 | |
| 341 | ret = ata_wait_after_reset(link, deadline, check_ready); |
| 342 | if (ret && ret != -EAGAIN) |
| 343 | ata_link_err(link, "COMRESET failed (errno=%d)\n", ret); |
| 344 | |
| 345 | /* XXX: if the class changes during the reset the upper layer |
| 346 | * should be informed, if the device has gone away we assume |
| 347 | * libsas will eventually delete it |
| 348 | */ |
Darrick J. Wong | 338ec57 | 2006-10-18 14:43:37 -0700 | [diff] [blame] | 349 | switch (dev->sata_dev.command_set) { |
Dan Williams | 36a3994 | 2011-11-17 17:59:54 -0800 | [diff] [blame] | 350 | case ATA_COMMAND_SET: |
| 351 | *class = ATA_DEV_ATA; |
| 352 | break; |
| 353 | case ATAPI_COMMAND_SET: |
| 354 | *class = ATA_DEV_ATAPI; |
| 355 | break; |
Darrick J. Wong | 338ec57 | 2006-10-18 14:43:37 -0700 | [diff] [blame] | 356 | } |
| 357 | |
| 358 | ap->cbl = ATA_CBL_SATA; |
James Bottomley | 00dd499 | 2011-01-23 09:44:12 -0600 | [diff] [blame] | 359 | return ret; |
Darrick J. Wong | 338ec57 | 2006-10-18 14:43:37 -0700 | [diff] [blame] | 360 | } |
| 361 | |
Dave Jiang | 1ca1e43 | 2011-05-24 13:18:04 -0700 | [diff] [blame] | 362 | static int sas_ata_soft_reset(struct ata_link *link, unsigned int *class, |
| 363 | unsigned long deadline) |
| 364 | { |
| 365 | struct ata_port *ap = link->ap; |
| 366 | struct domain_device *dev = ap->private_data; |
Dan Williams | 36a3994 | 2011-11-17 17:59:54 -0800 | [diff] [blame] | 367 | struct sas_internal *i = dev_to_sas_internal(dev); |
Dave Jiang | 1ca1e43 | 2011-05-24 13:18:04 -0700 | [diff] [blame] | 368 | int res = TMF_RESP_FUNC_FAILED; |
| 369 | int ret = 0; |
| 370 | |
| 371 | if (i->dft->lldd_ata_soft_reset) |
| 372 | res = i->dft->lldd_ata_soft_reset(dev); |
| 373 | |
| 374 | if (res != TMF_RESP_FUNC_COMPLETE) { |
| 375 | SAS_DPRINTK("%s: Unable to soft reset\n", __func__); |
| 376 | ret = -EAGAIN; |
| 377 | } |
| 378 | |
| 379 | switch (dev->sata_dev.command_set) { |
| 380 | case ATA_COMMAND_SET: |
| 381 | SAS_DPRINTK("%s: Found ATA device.\n", __func__); |
| 382 | *class = ATA_DEV_ATA; |
| 383 | break; |
| 384 | case ATAPI_COMMAND_SET: |
| 385 | SAS_DPRINTK("%s: Found ATAPI device.\n", __func__); |
| 386 | *class = ATA_DEV_ATAPI; |
| 387 | break; |
| 388 | default: |
| 389 | SAS_DPRINTK("%s: Unknown SATA command set: %d.\n", |
| 390 | __func__, dev->sata_dev.command_set); |
| 391 | *class = ATA_DEV_UNKNOWN; |
| 392 | break; |
| 393 | } |
| 394 | |
| 395 | ap->cbl = ATA_CBL_SATA; |
| 396 | return ret; |
| 397 | } |
| 398 | |
Dan Williams | 3dff572 | 2011-11-28 12:08:22 -0800 | [diff] [blame] | 399 | /* |
| 400 | * notify the lldd to forget the sas_task for this internal ata command |
| 401 | * that bypasses scsi-eh |
| 402 | */ |
| 403 | static void sas_ata_internal_abort(struct sas_task *task) |
| 404 | { |
Dan Williams | 36a3994 | 2011-11-17 17:59:54 -0800 | [diff] [blame] | 405 | struct sas_internal *si = dev_to_sas_internal(task->dev); |
Dan Williams | 3dff572 | 2011-11-28 12:08:22 -0800 | [diff] [blame] | 406 | unsigned long flags; |
| 407 | int res; |
| 408 | |
| 409 | spin_lock_irqsave(&task->task_state_lock, flags); |
| 410 | if (task->task_state_flags & SAS_TASK_STATE_ABORTED || |
| 411 | task->task_state_flags & SAS_TASK_STATE_DONE) { |
| 412 | spin_unlock_irqrestore(&task->task_state_lock, flags); |
| 413 | SAS_DPRINTK("%s: Task %p already finished.\n", __func__, |
| 414 | task); |
| 415 | goto out; |
| 416 | } |
| 417 | task->task_state_flags |= SAS_TASK_STATE_ABORTED; |
| 418 | spin_unlock_irqrestore(&task->task_state_lock, flags); |
| 419 | |
| 420 | res = si->dft->lldd_abort_task(task); |
| 421 | |
| 422 | spin_lock_irqsave(&task->task_state_lock, flags); |
| 423 | if (task->task_state_flags & SAS_TASK_STATE_DONE || |
| 424 | res == TMF_RESP_FUNC_COMPLETE) { |
| 425 | spin_unlock_irqrestore(&task->task_state_lock, flags); |
| 426 | goto out; |
| 427 | } |
| 428 | |
| 429 | /* XXX we are not prepared to deal with ->lldd_abort_task() |
| 430 | * failures. TODO: lldds need to unconditionally forget about |
| 431 | * aborted ata tasks, otherwise we (likely) leak the sas task |
| 432 | * here |
| 433 | */ |
| 434 | SAS_DPRINTK("%s: Task %p leaked.\n", __func__, task); |
| 435 | |
| 436 | if (!(task->task_state_flags & SAS_TASK_STATE_DONE)) |
| 437 | task->task_state_flags &= ~SAS_TASK_STATE_ABORTED; |
| 438 | spin_unlock_irqrestore(&task->task_state_lock, flags); |
| 439 | |
| 440 | return; |
| 441 | out: |
| 442 | list_del_init(&task->list); |
| 443 | sas_free_task(task); |
| 444 | } |
| 445 | |
Darrick J. Wong | 338ec57 | 2006-10-18 14:43:37 -0700 | [diff] [blame] | 446 | static void sas_ata_post_internal(struct ata_queued_cmd *qc) |
| 447 | { |
| 448 | if (qc->flags & ATA_QCFLAG_FAILED) |
| 449 | qc->err_mask |= AC_ERR_OTHER; |
| 450 | |
Darrick J. Wong | 1c50dc8 | 2007-01-30 01:18:41 -0800 | [diff] [blame] | 451 | if (qc->err_mask) { |
| 452 | /* |
Dan Williams | 3dff572 | 2011-11-28 12:08:22 -0800 | [diff] [blame] | 453 | * Find the sas_task and kill it. By this point, libata |
| 454 | * has decided to kill the qc and has frozen the port. |
| 455 | * In this state sas_ata_task_done() will no longer free |
| 456 | * the sas_task, so we need to notify the lldd (via |
| 457 | * ->lldd_abort_task) that the task is dead and free it |
| 458 | * ourselves. |
Darrick J. Wong | 1c50dc8 | 2007-01-30 01:18:41 -0800 | [diff] [blame] | 459 | */ |
| 460 | struct sas_task *task = qc->lldd_task; |
Darrick J. Wong | 1c50dc8 | 2007-01-30 01:18:41 -0800 | [diff] [blame] | 461 | |
| 462 | qc->lldd_task = NULL; |
Dan Williams | 3a2cdf3 | 2011-11-29 14:54:28 -0800 | [diff] [blame] | 463 | if (!task) |
| 464 | return; |
| 465 | task->uldd_task = NULL; |
| 466 | sas_ata_internal_abort(task); |
Darrick J. Wong | 1c50dc8 | 2007-01-30 01:18:41 -0800 | [diff] [blame] | 467 | } |
Darrick J. Wong | 338ec57 | 2006-10-18 14:43:37 -0700 | [diff] [blame] | 468 | } |
| 469 | |
Dan Williams | b91bb29 | 2011-11-17 17:59:52 -0800 | [diff] [blame] | 470 | |
| 471 | static void sas_ata_set_dmamode(struct ata_port *ap, struct ata_device *ata_dev) |
| 472 | { |
| 473 | struct domain_device *dev = ap->private_data; |
Dan Williams | 36a3994 | 2011-11-17 17:59:54 -0800 | [diff] [blame] | 474 | struct sas_internal *i = dev_to_sas_internal(dev); |
Dan Williams | b91bb29 | 2011-11-17 17:59:52 -0800 | [diff] [blame] | 475 | |
| 476 | if (i->dft->lldd_ata_set_dmamode) |
| 477 | i->dft->lldd_ata_set_dmamode(dev); |
| 478 | } |
| 479 | |
Darrick J. Wong | 338ec57 | 2006-10-18 14:43:37 -0700 | [diff] [blame] | 480 | static struct ata_port_operations sas_sata_ops = { |
James Bottomley | 00dd499 | 2011-01-23 09:44:12 -0600 | [diff] [blame] | 481 | .prereset = ata_std_prereset, |
Dave Jiang | 1ca1e43 | 2011-05-24 13:18:04 -0700 | [diff] [blame] | 482 | .softreset = sas_ata_soft_reset, |
James Bottomley | 00dd499 | 2011-01-23 09:44:12 -0600 | [diff] [blame] | 483 | .hardreset = sas_ata_hard_reset, |
| 484 | .postreset = ata_std_postreset, |
| 485 | .error_handler = ata_std_error_handler, |
Darrick J. Wong | 338ec57 | 2006-10-18 14:43:37 -0700 | [diff] [blame] | 486 | .post_internal_cmd = sas_ata_post_internal, |
David Milburn | f0ad30d | 2010-09-03 17:13:03 -0500 | [diff] [blame] | 487 | .qc_defer = ata_std_qc_defer, |
Darrick J. Wong | 338ec57 | 2006-10-18 14:43:37 -0700 | [diff] [blame] | 488 | .qc_prep = ata_noop_qc_prep, |
| 489 | .qc_issue = sas_ata_qc_issue, |
Tejun Heo | 4c9bf4e | 2008-04-07 22:47:20 +0900 | [diff] [blame] | 490 | .qc_fill_rtf = sas_ata_qc_fill_rtf, |
Darrick J. Wong | 338ec57 | 2006-10-18 14:43:37 -0700 | [diff] [blame] | 491 | .port_start = ata_sas_port_start, |
| 492 | .port_stop = ata_sas_port_stop, |
Dan Williams | b91bb29 | 2011-11-17 17:59:52 -0800 | [diff] [blame] | 493 | .set_dmamode = sas_ata_set_dmamode, |
Darrick J. Wong | 338ec57 | 2006-10-18 14:43:37 -0700 | [diff] [blame] | 494 | }; |
| 495 | |
| 496 | static struct ata_port_info sata_port_info = { |
Sergei Shtylyov | 9cbe056 | 2011-02-04 22:05:48 +0300 | [diff] [blame] | 497 | .flags = ATA_FLAG_SATA | ATA_FLAG_PIO_DMA | ATA_FLAG_NCQ, |
Sergei Shtylyov | 0f2e033 | 2011-01-21 20:32:01 +0300 | [diff] [blame] | 498 | .pio_mask = ATA_PIO4, |
| 499 | .mwdma_mask = ATA_MWDMA2, |
Darrick J. Wong | 338ec57 | 2006-10-18 14:43:37 -0700 | [diff] [blame] | 500 | .udma_mask = ATA_UDMA6, |
| 501 | .port_ops = &sas_sata_ops |
| 502 | }; |
| 503 | |
| 504 | int sas_ata_init_host_and_port(struct domain_device *found_dev, |
| 505 | struct scsi_target *starget) |
| 506 | { |
| 507 | struct Scsi_Host *shost = dev_to_shost(&starget->dev); |
| 508 | struct sas_ha_struct *ha = SHOST_TO_SAS_HA(shost); |
| 509 | struct ata_port *ap; |
| 510 | |
| 511 | ata_host_init(&found_dev->sata_dev.ata_host, |
Jeff Garzik | 1d1bbee | 2007-07-26 09:28:37 -0400 | [diff] [blame] | 512 | ha->dev, |
Darrick J. Wong | 338ec57 | 2006-10-18 14:43:37 -0700 | [diff] [blame] | 513 | sata_port_info.flags, |
| 514 | &sas_sata_ops); |
| 515 | ap = ata_sas_port_alloc(&found_dev->sata_dev.ata_host, |
| 516 | &sata_port_info, |
| 517 | shost); |
| 518 | if (!ap) { |
| 519 | SAS_DPRINTK("ata_sas_port_alloc failed.\n"); |
| 520 | return -ENODEV; |
| 521 | } |
| 522 | |
| 523 | ap->private_data = found_dev; |
| 524 | ap->cbl = ATA_CBL_SATA; |
| 525 | ap->scsi_host = shost; |
| 526 | found_dev->sata_dev.ap = ap; |
| 527 | |
| 528 | return 0; |
| 529 | } |
Darrick J. Wong | 3a2755a | 2007-01-30 01:18:58 -0800 | [diff] [blame] | 530 | |
| 531 | void sas_ata_task_abort(struct sas_task *task) |
| 532 | { |
| 533 | struct ata_queued_cmd *qc = task->uldd_task; |
| 534 | struct completion *waiting; |
| 535 | |
| 536 | /* Bounce SCSI-initiated commands to the SCSI EH */ |
| 537 | if (qc->scsicmd) { |
James Bottomley | 1b4d0d8 | 2010-05-13 09:31:54 -0500 | [diff] [blame] | 538 | struct request_queue *q = qc->scsicmd->device->request_queue; |
| 539 | unsigned long flags; |
| 540 | |
Tejun Heo | 70b25f8 | 2010-04-15 09:00:08 +0900 | [diff] [blame] | 541 | spin_lock_irqsave(q->queue_lock, flags); |
Jens Axboe | 242f9dc | 2008-09-14 05:55:09 -0700 | [diff] [blame] | 542 | blk_abort_request(qc->scsicmd->request); |
Tejun Heo | 70b25f8 | 2010-04-15 09:00:08 +0900 | [diff] [blame] | 543 | spin_unlock_irqrestore(q->queue_lock, flags); |
Darrick J. Wong | 3a2755a | 2007-01-30 01:18:58 -0800 | [diff] [blame] | 544 | scsi_schedule_eh(qc->scsicmd->device->host); |
| 545 | return; |
| 546 | } |
| 547 | |
| 548 | /* Internal command, fake a timeout and complete. */ |
| 549 | qc->flags &= ~ATA_QCFLAG_ACTIVE; |
| 550 | qc->flags |= ATA_QCFLAG_FAILED; |
| 551 | qc->err_mask |= AC_ERR_TIMEOUT; |
| 552 | waiting = qc->private_data; |
| 553 | complete(waiting); |
| 554 | } |
James Bottomley | b914217 | 2007-07-22 13:15:55 -0500 | [diff] [blame] | 555 | |
James Bottomley | b914217 | 2007-07-22 13:15:55 -0500 | [diff] [blame] | 556 | static void sas_get_ata_command_set(struct domain_device *dev) |
| 557 | { |
| 558 | struct dev_to_host_fis *fis = |
| 559 | (struct dev_to_host_fis *) dev->frame_rcvd; |
| 560 | |
| 561 | if ((fis->sector_count == 1 && /* ATA */ |
| 562 | fis->lbal == 1 && |
| 563 | fis->lbam == 0 && |
| 564 | fis->lbah == 0 && |
| 565 | fis->device == 0) |
| 566 | || |
| 567 | (fis->sector_count == 0 && /* CE-ATA (mATA) */ |
| 568 | fis->lbal == 0 && |
| 569 | fis->lbam == 0xCE && |
| 570 | fis->lbah == 0xAA && |
| 571 | (fis->device & ~0x10) == 0)) |
| 572 | |
| 573 | dev->sata_dev.command_set = ATA_COMMAND_SET; |
| 574 | |
| 575 | else if ((fis->interrupt_reason == 1 && /* ATAPI */ |
| 576 | fis->lbal == 1 && |
| 577 | fis->byte_count_low == 0x14 && |
| 578 | fis->byte_count_high == 0xEB && |
| 579 | (fis->device & ~0x10) == 0)) |
| 580 | |
| 581 | dev->sata_dev.command_set = ATAPI_COMMAND_SET; |
| 582 | |
| 583 | else if ((fis->sector_count == 1 && /* SEMB */ |
| 584 | fis->lbal == 1 && |
| 585 | fis->lbam == 0x3C && |
| 586 | fis->lbah == 0xC3 && |
| 587 | fis->device == 0) |
| 588 | || |
| 589 | (fis->interrupt_reason == 1 && /* SATA PM */ |
| 590 | fis->lbal == 1 && |
| 591 | fis->byte_count_low == 0x69 && |
| 592 | fis->byte_count_high == 0x96 && |
| 593 | (fis->device & ~0x10) == 0)) |
| 594 | |
| 595 | /* Treat it as a superset? */ |
| 596 | dev->sata_dev.command_set = ATAPI_COMMAND_SET; |
| 597 | } |
| 598 | |
Dan Williams | 87c8331 | 2011-11-17 17:59:51 -0800 | [diff] [blame] | 599 | void sas_probe_sata(struct work_struct *work) |
| 600 | { |
| 601 | struct domain_device *dev, *n; |
| 602 | struct sas_discovery_event *ev = |
| 603 | container_of(work, struct sas_discovery_event, work); |
| 604 | struct asd_sas_port *port = ev->port; |
| 605 | |
| 606 | clear_bit(DISCE_PROBE, &port->disc.pending); |
| 607 | |
| 608 | list_for_each_entry_safe(dev, n, &port->disco_list, disco_list_node) { |
| 609 | int err; |
| 610 | |
| 611 | spin_lock_irq(&port->dev_list_lock); |
| 612 | list_add_tail(&dev->dev_list_node, &port->dev_list); |
| 613 | spin_unlock_irq(&port->dev_list_lock); |
| 614 | |
| 615 | err = sas_rphy_add(dev->rphy); |
| 616 | |
| 617 | if (err) { |
| 618 | SAS_DPRINTK("%s: for %s device %16llx returned %d\n", |
| 619 | __func__, dev->parent ? "exp-attached" : |
| 620 | "direct-attached", |
| 621 | SAS_ADDR(dev->sas_addr), err); |
| 622 | sas_unregister_dev(port, dev); |
| 623 | } else |
| 624 | list_del_init(&dev->disco_list_node); |
| 625 | } |
| 626 | } |
| 627 | |
James Bottomley | b914217 | 2007-07-22 13:15:55 -0500 | [diff] [blame] | 628 | /** |
| 629 | * sas_discover_sata -- discover an STP/SATA domain device |
| 630 | * @dev: pointer to struct domain_device of interest |
| 631 | * |
Dan Williams | b91bb29 | 2011-11-17 17:59:52 -0800 | [diff] [blame] | 632 | * Devices directly attached to a HA port, have no parents. All other |
| 633 | * devices do, and should have their "parent" pointer set appropriately |
| 634 | * before calling this function. |
James Bottomley | b914217 | 2007-07-22 13:15:55 -0500 | [diff] [blame] | 635 | */ |
| 636 | int sas_discover_sata(struct domain_device *dev) |
| 637 | { |
| 638 | int res; |
| 639 | |
Dan Williams | b91bb29 | 2011-11-17 17:59:52 -0800 | [diff] [blame] | 640 | if (dev->dev_type == SATA_PM) |
| 641 | return -ENODEV; |
| 642 | |
James Bottomley | b914217 | 2007-07-22 13:15:55 -0500 | [diff] [blame] | 643 | sas_get_ata_command_set(dev); |
Dan Williams | b91bb29 | 2011-11-17 17:59:52 -0800 | [diff] [blame] | 644 | sas_fill_in_rphy(dev, dev->rphy); |
Dan Williams | 87c8331 | 2011-11-17 17:59:51 -0800 | [diff] [blame] | 645 | |
| 646 | res = sas_notify_lldd_dev_found(dev); |
| 647 | if (res) |
| 648 | return res; |
| 649 | |
| 650 | sas_discover_event(dev->port, DISCE_PROBE); |
Dan Williams | b91bb29 | 2011-11-17 17:59:52 -0800 | [diff] [blame] | 651 | return 0; |
James Bottomley | b914217 | 2007-07-22 13:15:55 -0500 | [diff] [blame] | 652 | } |
James Bottomley | 00dd499 | 2011-01-23 09:44:12 -0600 | [diff] [blame] | 653 | |
Dan Williams | 50824d6 | 2011-12-04 01:06:24 -0800 | [diff] [blame] | 654 | static void async_sas_ata_eh(void *data, async_cookie_t cookie) |
| 655 | { |
| 656 | struct domain_device *dev = data; |
| 657 | struct ata_port *ap = dev->sata_dev.ap; |
| 658 | struct sas_ha_struct *ha = dev->port->ha; |
| 659 | |
| 660 | ata_port_printk(ap, KERN_DEBUG, "sas eh calling libata port error handler"); |
| 661 | ata_scsi_port_error_handler(ha->core.shost, ap); |
| 662 | } |
| 663 | |
James Bottomley | 00dd499 | 2011-01-23 09:44:12 -0600 | [diff] [blame] | 664 | void sas_ata_strategy_handler(struct Scsi_Host *shost) |
| 665 | { |
| 666 | struct scsi_device *sdev; |
Dan Williams | 87c8331 | 2011-11-17 17:59:51 -0800 | [diff] [blame] | 667 | struct sas_ha_struct *sas_ha = SHOST_TO_SAS_HA(shost); |
Dan Williams | 50824d6 | 2011-12-04 01:06:24 -0800 | [diff] [blame] | 668 | LIST_HEAD(async); |
Dan Williams | 87c8331 | 2011-11-17 17:59:51 -0800 | [diff] [blame] | 669 | |
| 670 | /* it's ok to defer revalidation events during ata eh, these |
| 671 | * disks are in one of three states: |
| 672 | * 1/ present for initial domain discovery, and these |
| 673 | * resets will cause bcn flutters |
| 674 | * 2/ hot removed, we'll discover that after eh fails |
| 675 | * 3/ hot added after initial discovery, lost the race, and need |
| 676 | * to catch the next train. |
| 677 | */ |
| 678 | sas_disable_revalidation(sas_ha); |
James Bottomley | 00dd499 | 2011-01-23 09:44:12 -0600 | [diff] [blame] | 679 | |
| 680 | shost_for_each_device(sdev, shost) { |
| 681 | struct domain_device *ddev = sdev_to_domain_dev(sdev); |
James Bottomley | 00dd499 | 2011-01-23 09:44:12 -0600 | [diff] [blame] | 682 | |
| 683 | if (!dev_is_sata(ddev)) |
| 684 | continue; |
James Bottomley | c299190 | 2011-01-23 09:44:12 -0600 | [diff] [blame] | 685 | |
Dan Williams | 50824d6 | 2011-12-04 01:06:24 -0800 | [diff] [blame] | 686 | async_schedule_domain(async_sas_ata_eh, ddev, &async); |
James Bottomley | 00dd499 | 2011-01-23 09:44:12 -0600 | [diff] [blame] | 687 | } |
Dan Williams | 50824d6 | 2011-12-04 01:06:24 -0800 | [diff] [blame] | 688 | async_synchronize_full_domain(&async); |
Dan Williams | 87c8331 | 2011-11-17 17:59:51 -0800 | [diff] [blame] | 689 | |
| 690 | sas_enable_revalidation(sas_ha); |
James Bottomley | 00dd499 | 2011-01-23 09:44:12 -0600 | [diff] [blame] | 691 | } |
| 692 | |
James Bottomley | 00dd499 | 2011-01-23 09:44:12 -0600 | [diff] [blame] | 693 | int sas_ata_eh(struct Scsi_Host *shost, struct list_head *work_q, |
| 694 | struct list_head *done_q) |
| 695 | { |
| 696 | int rtn = 0; |
| 697 | struct scsi_cmnd *cmd, *n; |
| 698 | struct ata_port *ap; |
| 699 | |
| 700 | do { |
| 701 | LIST_HEAD(sata_q); |
| 702 | |
| 703 | ap = NULL; |
James Bottomley | c299190 | 2011-01-23 09:44:12 -0600 | [diff] [blame] | 704 | |
James Bottomley | 00dd499 | 2011-01-23 09:44:12 -0600 | [diff] [blame] | 705 | list_for_each_entry_safe(cmd, n, work_q, eh_entry) { |
| 706 | struct domain_device *ddev = cmd_to_domain_dev(cmd); |
| 707 | |
| 708 | if (!dev_is_sata(ddev) || TO_SAS_TASK(cmd)) |
| 709 | continue; |
James Bottomley | c299190 | 2011-01-23 09:44:12 -0600 | [diff] [blame] | 710 | if (ap && ap != ddev->sata_dev.ap) |
James Bottomley | 00dd499 | 2011-01-23 09:44:12 -0600 | [diff] [blame] | 711 | continue; |
| 712 | ap = ddev->sata_dev.ap; |
| 713 | rtn = 1; |
| 714 | list_move(&cmd->eh_entry, &sata_q); |
| 715 | } |
| 716 | |
| 717 | if (!list_empty(&sata_q)) { |
James Bottomley | c299190 | 2011-01-23 09:44:12 -0600 | [diff] [blame] | 718 | ata_port_printk(ap, KERN_DEBUG, "sas eh calling libata cmd error handler\n"); |
James Bottomley | 00dd499 | 2011-01-23 09:44:12 -0600 | [diff] [blame] | 719 | ata_scsi_cmd_error_handler(shost, ap, &sata_q); |
James Bottomley | a82058a | 2011-03-10 17:13:18 -0600 | [diff] [blame] | 720 | /* |
| 721 | * ata's error handler may leave the cmd on the list |
| 722 | * so make sure they don't remain on a stack list |
| 723 | * about to go out of scope. |
| 724 | * |
| 725 | * This looks strange, since the commands are |
| 726 | * now part of no list, but the next error |
| 727 | * action will be ata_port_error_handler() |
| 728 | * which takes no list and sweeps them up |
| 729 | * anyway from the ata tag array. |
| 730 | */ |
| 731 | while (!list_empty(&sata_q)) |
| 732 | list_del_init(sata_q.next); |
James Bottomley | 00dd499 | 2011-01-23 09:44:12 -0600 | [diff] [blame] | 733 | } |
| 734 | } while (ap); |
| 735 | |
| 736 | return rtn; |
| 737 | } |
Dan Williams | b52df41 | 2011-11-30 23:23:33 -0800 | [diff] [blame] | 738 | |
| 739 | void sas_ata_schedule_reset(struct domain_device *dev) |
| 740 | { |
| 741 | struct ata_eh_info *ehi; |
| 742 | struct ata_port *ap; |
| 743 | unsigned long flags; |
| 744 | |
| 745 | if (!dev_is_sata(dev)) |
| 746 | return; |
| 747 | |
| 748 | ap = dev->sata_dev.ap; |
| 749 | ehi = &ap->link.eh_info; |
| 750 | |
| 751 | spin_lock_irqsave(ap->lock, flags); |
| 752 | ehi->err_mask |= AC_ERR_TIMEOUT; |
| 753 | ehi->action |= ATA_EH_RESET; |
| 754 | ata_port_schedule_eh(ap); |
| 755 | spin_unlock_irqrestore(ap->lock, flags); |
| 756 | } |
Dan Williams | 81c757b | 2011-12-02 16:07:01 -0800 | [diff] [blame] | 757 | |
| 758 | void sas_ata_wait_eh(struct domain_device *dev) |
| 759 | { |
| 760 | struct ata_port *ap; |
| 761 | |
| 762 | if (!dev_is_sata(dev)) |
| 763 | return; |
| 764 | |
| 765 | ap = dev->sata_dev.ap; |
| 766 | ata_port_wait_eh(ap); |
| 767 | } |