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