Lines Matching +full:ts +full:- +full:attached

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Support for SATA devices on Serial Attached SCSI (SAS) controllers
27 static enum ata_completion_errors sas_to_ata_err(struct task_status_struct *ts) in sas_to_ata_err() argument
32 if (ts->resp == SAS_TASK_UNDELIVERED) in sas_to_ata_err()
35 /* ts->resp == SAS_TASK_COMPLETE */ in sas_to_ata_err()
37 switch (ts->stat) { in sas_to_ata_err()
65 __func__, ts->stat); in sas_to_ata_err()
83 struct ata_queued_cmd *qc = task->uldd_task; in sas_ata_task_done()
84 struct domain_device *dev = task->dev; in sas_ata_task_done()
85 struct task_status_struct *stat = &task->task_status; in sas_ata_task_done()
86 struct ata_task_resp *resp = (struct ata_task_resp *)stat->buf; in sas_ata_task_done()
87 struct sas_ha_struct *sas_ha = dev->port->ha; in sas_ata_task_done()
93 spin_lock_irqsave(&dev->done_lock, flags); in sas_ata_task_done()
94 if (test_bit(SAS_HA_FROZEN, &sas_ha->state)) in sas_ata_task_done()
96 else if (qc && qc->scsicmd) in sas_ata_task_done()
97 ASSIGN_SAS_TASK(qc->scsicmd, NULL); in sas_ata_task_done()
98 spin_unlock_irqrestore(&dev->done_lock, flags); in sas_ata_task_done()
100 /* check if libsas-eh got to the task before us */ in sas_ata_task_done()
107 ap = qc->ap; in sas_ata_task_done()
108 link = &ap->link; in sas_ata_task_done()
110 spin_lock_irqsave(ap->lock, flags); in sas_ata_task_done()
112 if (unlikely(ap->pflags & ATA_PFLAG_FROZEN)) { in sas_ata_task_done()
113 spin_unlock_irqrestore(ap->lock, flags); in sas_ata_task_done()
114 if (qc->scsicmd) in sas_ata_task_done()
125 if (stat->stat == SAS_PROTO_RESPONSE || stat->stat == SAM_STAT_GOOD || in sas_ata_task_done()
126 ((stat->stat == SAM_STAT_CHECK_CONDITION && in sas_ata_task_done()
127 dev->sata_dev.class == ATA_DEV_ATAPI))) { in sas_ata_task_done()
128 memcpy(dev->sata_dev.fis, resp->ending_fis, ATA_RESP_FIS_SIZE); in sas_ata_task_done()
130 if (!link->sactive) { in sas_ata_task_done()
131 qc->err_mask |= ac_err_mask(dev->sata_dev.fis[2]); in sas_ata_task_done()
133 link->eh_info.err_mask |= ac_err_mask(dev->sata_dev.fis[2]); in sas_ata_task_done()
134 if (unlikely(link->eh_info.err_mask)) in sas_ata_task_done()
135 qc->flags |= ATA_QCFLAG_FAILED; in sas_ata_task_done()
140 pr_warn("%s: SAS error 0x%x\n", __func__, stat->stat); in sas_ata_task_done()
142 if (!link->sactive) { in sas_ata_task_done()
143 qc->err_mask = ac; in sas_ata_task_done()
145 link->eh_info.err_mask |= AC_ERR_DEV; in sas_ata_task_done()
146 qc->flags |= ATA_QCFLAG_FAILED; in sas_ata_task_done()
149 dev->sata_dev.fis[3] = 0x04; /* status err */ in sas_ata_task_done()
150 dev->sata_dev.fis[2] = ATA_ERR; in sas_ata_task_done()
154 qc->lldd_task = NULL; in sas_ata_task_done()
156 spin_unlock_irqrestore(ap->lock, flags); in sas_ata_task_done()
163 __must_hold(ap->lock) in sas_ata_qc_issue()
169 struct ata_port *ap = qc->ap; in sas_ata_qc_issue()
170 struct domain_device *dev = ap->private_data; in sas_ata_qc_issue()
171 struct sas_ha_struct *sas_ha = dev->port->ha; in sas_ata_qc_issue()
172 struct Scsi_Host *host = sas_ha->core.shost; in sas_ata_qc_issue()
173 struct sas_internal *i = to_sas_internal(host->transportt); in sas_ata_qc_issue()
176 spin_unlock(ap->lock); in sas_ata_qc_issue()
179 if (test_bit(SAS_DEV_GONE, &dev->state)) in sas_ata_qc_issue()
185 task->dev = dev; in sas_ata_qc_issue()
186 task->task_proto = SAS_PROTOCOL_STP; in sas_ata_qc_issue()
187 task->task_done = sas_ata_task_done; in sas_ata_qc_issue()
189 if (qc->tf.command == ATA_CMD_FPDMA_WRITE || in sas_ata_qc_issue()
190 qc->tf.command == ATA_CMD_FPDMA_READ || in sas_ata_qc_issue()
191 qc->tf.command == ATA_CMD_FPDMA_RECV || in sas_ata_qc_issue()
192 qc->tf.command == ATA_CMD_FPDMA_SEND || in sas_ata_qc_issue()
193 qc->tf.command == ATA_CMD_NCQ_NON_DATA) { in sas_ata_qc_issue()
195 qc->tf.nsect = 0; in sas_ata_qc_issue()
198 ata_tf_to_fis(&qc->tf, qc->dev->link->pmp, 1, (u8 *)&task->ata_task.fis); in sas_ata_qc_issue()
199 task->uldd_task = qc; in sas_ata_qc_issue()
200 if (ata_is_atapi(qc->tf.protocol)) { in sas_ata_qc_issue()
201 memcpy(task->ata_task.atapi_packet, qc->cdb, qc->dev->cdb_len); in sas_ata_qc_issue()
202 task->total_xfer_len = qc->nbytes; in sas_ata_qc_issue()
203 task->num_scatter = qc->n_elem; in sas_ata_qc_issue()
205 for_each_sg(qc->sg, sg, qc->n_elem, si) in sas_ata_qc_issue()
208 task->total_xfer_len = xfer; in sas_ata_qc_issue()
209 task->num_scatter = si; in sas_ata_qc_issue()
212 if (qc->tf.protocol == ATA_PROT_NODATA) in sas_ata_qc_issue()
213 task->data_dir = DMA_NONE; in sas_ata_qc_issue()
215 task->data_dir = qc->dma_dir; in sas_ata_qc_issue()
216 task->scatter = qc->sg; in sas_ata_qc_issue()
217 task->ata_task.retry_count = 1; in sas_ata_qc_issue()
218 task->task_state_flags = SAS_TASK_STATE_PENDING; in sas_ata_qc_issue()
219 qc->lldd_task = task; in sas_ata_qc_issue()
221 task->ata_task.use_ncq = ata_is_ncq(qc->tf.protocol); in sas_ata_qc_issue()
222 task->ata_task.dma_xfer = ata_is_dma(qc->tf.protocol); in sas_ata_qc_issue()
224 if (qc->scsicmd) in sas_ata_qc_issue()
225 ASSIGN_SAS_TASK(qc->scsicmd, task); in sas_ata_qc_issue()
227 ret = i->dft->lldd_execute_task(task, GFP_ATOMIC); in sas_ata_qc_issue()
231 if (qc->scsicmd) in sas_ata_qc_issue()
232 ASSIGN_SAS_TASK(qc->scsicmd, NULL); in sas_ata_qc_issue()
234 qc->lldd_task = NULL; in sas_ata_qc_issue()
239 spin_lock(ap->lock); in sas_ata_qc_issue()
245 struct domain_device *dev = qc->ap->private_data; in sas_ata_qc_fill_rtf()
247 ata_tf_from_fis(dev->sata_dev.fis, &qc->result_tf); in sas_ata_qc_fill_rtf()
253 return to_sas_internal(dev->port->ha->core.shost->transportt); in dev_to_sas_internal()
260 if (phy->attached_tproto & SAS_PROTOCOL_STP) in sas_get_ata_info()
261 dev->tproto = phy->attached_tproto; in sas_get_ata_info()
262 if (phy->attached_sata_dev) in sas_get_ata_info()
263 dev->tproto |= SAS_SATA_DEV; in sas_get_ata_info()
265 if (phy->attached_dev_type == SAS_SATA_PENDING) in sas_get_ata_info()
266 dev->dev_type = SAS_SATA_PENDING; in sas_get_ata_info()
270 dev->dev_type = SAS_SATA_DEV; in sas_get_ata_info()
271 res = sas_get_report_phy_sata(dev->parent, phy->phy_id, in sas_get_ata_info()
272 &dev->sata_dev.rps_resp); in sas_get_ata_info()
275 SAS_ADDR(dev->parent->sas_addr), in sas_get_ata_info()
276 phy->phy_id, res); in sas_get_ata_info()
279 memcpy(dev->frame_rcvd, &dev->sata_dev.rps_resp.rps.fis, in sas_get_ata_info()
281 dev->sata_dev.class = sas_get_ata_command_set(dev); in sas_get_ata_info()
291 if (dev->dev_type != SAS_SATA_PENDING) in sas_ata_clear_pending()
307 struct ata_port *ap = link->ap; in smp_ata_check_ready()
308 struct domain_device *dev = ap->private_data; in smp_ata_check_ready()
309 struct domain_device *ex_dev = dev->parent; in smp_ata_check_ready()
311 struct ex_phy *ex_phy = &ex_dev->ex_dev.ex_phy[phy->number]; in smp_ata_check_ready()
313 res = sas_ex_phy_discover(ex_dev, phy->number); in smp_ata_check_ready()
319 if (res == -ECOMM) in smp_ata_check_ready()
324 switch (ex_phy->attached_dev_type) { in smp_ata_check_ready()
328 if (ex_phy->attached_sata_dev) in smp_ata_check_ready()
332 return -ENODEV; in smp_ata_check_ready()
338 struct ata_port *ap = link->ap; in local_ata_check_ready()
339 struct domain_device *dev = ap->private_data; in local_ata_check_ready()
342 if (i->dft->lldd_ata_check_ready) in local_ata_check_ready()
343 return i->dft->lldd_ata_check_ready(dev); in local_ata_check_ready()
356 struct ata_port *ap = ddev->sata_dev.ap; in sas_ata_printk()
357 struct device *dev = &ddev->rphy->dev; in sas_ata_printk()
368 level, ap->print_id, dev_name(dev), &vaf); in sas_ata_printk()
380 struct ata_port *ap = link->ap; in sas_ata_hard_reset()
382 struct domain_device *dev = ap->private_data; in sas_ata_hard_reset()
385 res = i->dft->lldd_I_T_nexus_reset(dev); in sas_ata_hard_reset()
386 if (res == -ENODEV) in sas_ata_hard_reset()
400 if (ret && ret != -EAGAIN) in sas_ata_hard_reset()
403 *class = dev->sata_dev.class; in sas_ata_hard_reset()
405 ap->cbl = ATA_CBL_SATA; in sas_ata_hard_reset()
411 * that bypasses scsi-eh
415 struct sas_internal *si = dev_to_sas_internal(task->dev); in sas_ata_internal_abort()
419 spin_lock_irqsave(&task->task_state_lock, flags); in sas_ata_internal_abort()
420 if (task->task_state_flags & SAS_TASK_STATE_ABORTED || in sas_ata_internal_abort()
421 task->task_state_flags & SAS_TASK_STATE_DONE) { in sas_ata_internal_abort()
422 spin_unlock_irqrestore(&task->task_state_lock, flags); in sas_ata_internal_abort()
426 task->task_state_flags |= SAS_TASK_STATE_ABORTED; in sas_ata_internal_abort()
427 spin_unlock_irqrestore(&task->task_state_lock, flags); in sas_ata_internal_abort()
429 res = si->dft->lldd_abort_task(task); in sas_ata_internal_abort()
431 spin_lock_irqsave(&task->task_state_lock, flags); in sas_ata_internal_abort()
432 if (task->task_state_flags & SAS_TASK_STATE_DONE || in sas_ata_internal_abort()
434 spin_unlock_irqrestore(&task->task_state_lock, flags); in sas_ata_internal_abort()
438 /* XXX we are not prepared to deal with ->lldd_abort_task() in sas_ata_internal_abort()
445 if (!(task->task_state_flags & SAS_TASK_STATE_DONE)) in sas_ata_internal_abort()
446 task->task_state_flags &= ~SAS_TASK_STATE_ABORTED; in sas_ata_internal_abort()
447 spin_unlock_irqrestore(&task->task_state_lock, flags); in sas_ata_internal_abort()
456 if (qc->flags & ATA_QCFLAG_FAILED) in sas_ata_post_internal()
457 qc->err_mask |= AC_ERR_OTHER; in sas_ata_post_internal()
459 if (qc->err_mask) { in sas_ata_post_internal()
465 * ->lldd_abort_task) that the task is dead and free it in sas_ata_post_internal()
468 struct sas_task *task = qc->lldd_task; in sas_ata_post_internal()
470 qc->lldd_task = NULL; in sas_ata_post_internal()
473 task->uldd_task = NULL; in sas_ata_post_internal()
481 struct domain_device *dev = ap->private_data; in sas_ata_set_dmamode()
484 if (i->dft->lldd_ata_set_dmamode) in sas_ata_set_dmamode()
485 i->dft->lldd_ata_set_dmamode(dev); in sas_ata_set_dmamode()
490 struct domain_device *dev = ap->private_data; in sas_ata_sched_eh()
491 struct sas_ha_struct *ha = dev->port->ha; in sas_ata_sched_eh()
494 spin_lock_irqsave(&ha->lock, flags); in sas_ata_sched_eh()
495 if (!test_and_set_bit(SAS_DEV_EH_PENDING, &dev->state)) in sas_ata_sched_eh()
496 ha->eh_active++; in sas_ata_sched_eh()
498 spin_unlock_irqrestore(&ha->lock, flags); in sas_ata_sched_eh()
503 struct domain_device *dev = ap->private_data; in sas_ata_end_eh()
504 struct sas_ha_struct *ha = dev->port->ha; in sas_ata_end_eh()
507 spin_lock_irqsave(&ha->lock, flags); in sas_ata_end_eh()
508 if (test_and_clear_bit(SAS_DEV_EH_PENDING, &dev->state)) in sas_ata_end_eh()
509 ha->eh_active--; in sas_ata_end_eh()
510 spin_unlock_irqrestore(&ha->lock, flags); in sas_ata_end_eh()
515 struct ata_port *ap = link->ap; in sas_ata_prereset()
516 struct domain_device *dev = ap->private_data; in sas_ata_prereset()
520 if (!local_phy->enabled || test_bit(SAS_DEV_GONE, &dev->state)) in sas_ata_prereset()
521 res = -ENOENT; in sas_ata_prereset()
554 struct sas_ha_struct *ha = found_dev->port->ha; in sas_ata_init()
555 struct Scsi_Host *shost = ha->core.shost; in sas_ata_init()
563 return -ENOMEM; in sas_ata_init()
566 ata_host_init(ata_host, ha->dev, &sas_sata_ops); in sas_ata_init()
571 rc = -ENODEV; in sas_ata_init()
575 ap->private_data = found_dev; in sas_ata_init()
576 ap->cbl = ATA_CBL_SATA; in sas_ata_init()
577 ap->scsi_host = shost; in sas_ata_init()
582 rc = ata_sas_tport_add(ata_host->dev, ap); in sas_ata_init()
586 found_dev->sata_dev.ata_host = ata_host; in sas_ata_init()
587 found_dev->sata_dev.ap = ap; in sas_ata_init()
600 struct ata_queued_cmd *qc = task->uldd_task; in sas_ata_task_abort()
603 /* Bounce SCSI-initiated commands to the SCSI EH */ in sas_ata_task_abort()
604 if (qc->scsicmd) { in sas_ata_task_abort()
605 blk_abort_request(qc->scsicmd->request); in sas_ata_task_abort()
610 qc->flags &= ~ATA_QCFLAG_ACTIVE; in sas_ata_task_abort()
611 qc->flags |= ATA_QCFLAG_FAILED; in sas_ata_task_abort()
612 qc->err_mask |= AC_ERR_TIMEOUT; in sas_ata_task_abort()
613 waiting = qc->private_data; in sas_ata_task_abort()
620 (struct dev_to_host_fis *) dev->frame_rcvd; in sas_get_ata_command_set()
623 if (dev->dev_type == SAS_SATA_PENDING) in sas_get_ata_command_set()
635 mutex_lock(&port->ha->disco_mutex); in sas_probe_sata()
636 list_for_each_entry(dev, &port->disco_list, disco_list_node) { in sas_probe_sata()
640 ata_sas_async_probe(dev->sata_dev.ap); in sas_probe_sata()
642 mutex_unlock(&port->ha->disco_mutex); in sas_probe_sata()
644 list_for_each_entry_safe(dev, n, &port->disco_list, disco_list_node) { in sas_probe_sata()
654 sas_fail_probe(dev, __func__, -ENODEV); in sas_probe_sata()
663 list_for_each_entry_safe(dev, n, &port->dev_list, dev_list_node) { in sas_ata_flush_pm_eh()
671 sas_fail_probe(dev, func, -ENODEV); in sas_ata_flush_pm_eh()
679 mutex_lock(&port->ha->disco_mutex); in sas_suspend_sata()
680 list_for_each_entry(dev, &port->dev_list, dev_list_node) { in sas_suspend_sata()
686 sata = &dev->sata_dev; in sas_suspend_sata()
687 if (sata->ap->pm_mesg.event == PM_EVENT_SUSPEND) in sas_suspend_sata()
690 ata_sas_port_suspend(sata->ap); in sas_suspend_sata()
692 mutex_unlock(&port->ha->disco_mutex); in sas_suspend_sata()
701 mutex_lock(&port->ha->disco_mutex); in sas_resume_sata()
702 list_for_each_entry(dev, &port->dev_list, dev_list_node) { in sas_resume_sata()
708 sata = &dev->sata_dev; in sas_resume_sata()
709 if (sata->ap->pm_mesg.event == PM_EVENT_ON) in sas_resume_sata()
712 ata_sas_port_resume(sata->ap); in sas_resume_sata()
714 mutex_unlock(&port->ha->disco_mutex); in sas_resume_sata()
720 * sas_discover_sata - discover an STP/SATA domain device
723 * Devices directly attached to a HA port, have no parents. All other
729 if (dev->dev_type == SAS_SATA_PM) in sas_discover_sata()
730 return -ENODEV; in sas_discover_sata()
732 dev->sata_dev.class = sas_get_ata_command_set(dev); in sas_discover_sata()
733 sas_fill_in_rphy(dev, dev->rphy); in sas_discover_sata()
741 struct ata_port *ap = dev->sata_dev.ap; in async_sas_ata_eh()
742 struct sas_ha_struct *ha = dev->port->ha; in async_sas_ata_eh()
745 ata_scsi_port_error_handler(ha->core.shost, ap); in async_sas_ata_eh()
765 spin_lock_irq(&sas_ha->phy_port_lock); in sas_ata_strategy_handler()
766 for (i = 0; i < sas_ha->num_phys; i++) { in sas_ata_strategy_handler()
767 struct asd_sas_port *port = sas_ha->sas_port[i]; in sas_ata_strategy_handler()
770 spin_lock(&port->dev_list_lock); in sas_ata_strategy_handler()
771 list_for_each_entry(dev, &port->dev_list, dev_list_node) { in sas_ata_strategy_handler()
779 kref_get(&dev->kref); in sas_ata_strategy_handler()
783 spin_unlock(&port->dev_list_lock); in sas_ata_strategy_handler()
785 spin_unlock_irq(&sas_ha->phy_port_lock); in sas_ata_strategy_handler()
810 list_move(&cmd->eh_entry, &sata_q); in sas_ata_eh()
814 struct ata_port *ap = eh_dev->sata_dev.ap; in sas_ata_eh()
844 ap = dev->sata_dev.ap; in sas_ata_schedule_reset()
845 ehi = &ap->link.eh_info; in sas_ata_schedule_reset()
847 spin_lock_irqsave(ap->lock, flags); in sas_ata_schedule_reset()
848 ehi->err_mask |= AC_ERR_TIMEOUT; in sas_ata_schedule_reset()
849 ehi->action |= ATA_EH_RESET; in sas_ata_schedule_reset()
851 spin_unlock_irqrestore(ap->lock, flags); in sas_ata_schedule_reset()
862 ap = dev->sata_dev.ap; in sas_ata_wait_eh()