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()
58 __func__, ts->stat); in sas_to_ata_err()
75 struct ata_queued_cmd *qc = task->uldd_task; in sas_ata_task_done()
76 struct domain_device *dev = task->dev; in sas_ata_task_done()
77 struct task_status_struct *stat = &task->task_status; in sas_ata_task_done()
78 struct ata_task_resp *resp = (struct ata_task_resp *)stat->buf; in sas_ata_task_done()
79 struct sas_ha_struct *sas_ha = dev->port->ha; in sas_ata_task_done()
85 spin_lock_irqsave(&dev->done_lock, flags); in sas_ata_task_done()
86 if (test_bit(SAS_HA_FROZEN, &sas_ha->state)) in sas_ata_task_done()
88 else if (qc && qc->scsicmd) in sas_ata_task_done()
89 ASSIGN_SAS_TASK(qc->scsicmd, NULL); in sas_ata_task_done()
90 spin_unlock_irqrestore(&dev->done_lock, flags); in sas_ata_task_done()
92 /* check if libsas-eh got to the task before us */ in sas_ata_task_done()
99 ap = qc->ap; in sas_ata_task_done()
100 link = &ap->link; in sas_ata_task_done()
102 spin_lock_irqsave(ap->lock, flags); in sas_ata_task_done()
105 spin_unlock_irqrestore(ap->lock, flags); in sas_ata_task_done()
106 if (qc->scsicmd) in sas_ata_task_done()
117 if (stat->stat == SAS_PROTO_RESPONSE || in sas_ata_task_done()
118 stat->stat == SAS_SAM_STAT_GOOD || in sas_ata_task_done()
119 (stat->stat == SAS_SAM_STAT_CHECK_CONDITION && in sas_ata_task_done()
120 dev->sata_dev.class == ATA_DEV_ATAPI)) { in sas_ata_task_done()
121 memcpy(dev->sata_dev.fis, resp->ending_fis, ATA_RESP_FIS_SIZE); in sas_ata_task_done()
123 if (!link->sactive) { in sas_ata_task_done()
124 qc->err_mask |= ac_err_mask(dev->sata_dev.fis[2]); in sas_ata_task_done()
126 link->eh_info.err_mask |= ac_err_mask(dev->sata_dev.fis[2]); in sas_ata_task_done()
127 if (unlikely(link->eh_info.err_mask)) in sas_ata_task_done()
128 qc->flags |= ATA_QCFLAG_EH; in sas_ata_task_done()
133 pr_warn("%s: SAS error 0x%x\n", __func__, stat->stat); in sas_ata_task_done()
135 if (!link->sactive) { in sas_ata_task_done()
136 qc->err_mask = ac; in sas_ata_task_done()
138 link->eh_info.err_mask |= AC_ERR_DEV; in sas_ata_task_done()
139 qc->flags |= ATA_QCFLAG_EH; in sas_ata_task_done()
142 dev->sata_dev.fis[2] = ATA_ERR | ATA_DRDY; /* tf status */ in sas_ata_task_done()
143 dev->sata_dev.fis[3] = ATA_ABORTED; /* tf error */ in sas_ata_task_done()
147 qc->lldd_task = NULL; in sas_ata_task_done()
149 spin_unlock_irqrestore(ap->lock, flags); in sas_ata_task_done()
156 __must_hold(ap->lock) in sas_ata_qc_issue()
162 struct ata_port *ap = qc->ap; in sas_ata_qc_issue()
163 struct domain_device *dev = ap->private_data; in sas_ata_qc_issue()
164 struct sas_ha_struct *sas_ha = dev->port->ha; in sas_ata_qc_issue()
165 struct Scsi_Host *host = sas_ha->shost; in sas_ata_qc_issue()
166 struct sas_internal *i = to_sas_internal(host->transportt); in sas_ata_qc_issue()
169 spin_unlock(ap->lock); in sas_ata_qc_issue()
172 if (test_bit(SAS_DEV_GONE, &dev->state)) in sas_ata_qc_issue()
178 task->dev = dev; in sas_ata_qc_issue()
179 task->task_proto = SAS_PROTOCOL_STP; in sas_ata_qc_issue()
180 task->task_done = sas_ata_task_done; in sas_ata_qc_issue()
183 if (ata_is_ncq(qc->tf.protocol)) in sas_ata_qc_issue()
184 qc->tf.nsect = 0; in sas_ata_qc_issue()
186 ata_tf_to_fis(&qc->tf, qc->dev->link->pmp, 1, (u8 *)&task->ata_task.fis); in sas_ata_qc_issue()
187 task->uldd_task = qc; in sas_ata_qc_issue()
188 if (ata_is_atapi(qc->tf.protocol)) { in sas_ata_qc_issue()
189 memcpy(task->ata_task.atapi_packet, qc->cdb, qc->dev->cdb_len); in sas_ata_qc_issue()
190 task->total_xfer_len = qc->nbytes; in sas_ata_qc_issue()
191 task->num_scatter = qc->n_elem; in sas_ata_qc_issue()
192 task->data_dir = qc->dma_dir; in sas_ata_qc_issue()
193 } else if (!ata_is_data(qc->tf.protocol)) { in sas_ata_qc_issue()
194 task->data_dir = DMA_NONE; in sas_ata_qc_issue()
196 for_each_sg(qc->sg, sg, qc->n_elem, si) in sas_ata_qc_issue()
199 task->total_xfer_len = xfer; in sas_ata_qc_issue()
200 task->num_scatter = si; in sas_ata_qc_issue()
201 task->data_dir = qc->dma_dir; in sas_ata_qc_issue()
203 task->scatter = qc->sg; in sas_ata_qc_issue()
204 qc->lldd_task = task; in sas_ata_qc_issue()
206 task->ata_task.use_ncq = ata_is_ncq(qc->tf.protocol); in sas_ata_qc_issue()
207 task->ata_task.dma_xfer = ata_is_dma(qc->tf.protocol); in sas_ata_qc_issue()
209 if (qc->flags & ATA_QCFLAG_RESULT_TF) in sas_ata_qc_issue()
210 task->ata_task.return_fis_on_success = 1; in sas_ata_qc_issue()
212 if (qc->scsicmd) in sas_ata_qc_issue()
213 ASSIGN_SAS_TASK(qc->scsicmd, task); in sas_ata_qc_issue()
215 ret = i->dft->lldd_execute_task(task, GFP_ATOMIC); in sas_ata_qc_issue()
219 if (qc->scsicmd) in sas_ata_qc_issue()
220 ASSIGN_SAS_TASK(qc->scsicmd, NULL); in sas_ata_qc_issue()
222 qc->lldd_task = NULL; in sas_ata_qc_issue()
227 spin_lock(ap->lock); in sas_ata_qc_issue()
233 struct domain_device *dev = qc->ap->private_data; in sas_ata_qc_fill_rtf()
235 ata_tf_from_fis(dev->sata_dev.fis, &qc->result_tf); in sas_ata_qc_fill_rtf()
240 return to_sas_internal(dev->port->ha->shost->transportt); in dev_to_sas_internal()
247 if (dev->dev_type == SAS_SATA_PENDING) in sas_get_ata_command_set()
250 ata_tf_from_fis(dev->frame_rcvd, &tf); in sas_get_ata_command_set()
257 if (phy->attached_tproto & SAS_PROTOCOL_STP) in sas_get_ata_info()
258 dev->tproto = phy->attached_tproto; in sas_get_ata_info()
259 if (phy->attached_sata_dev) in sas_get_ata_info()
260 dev->tproto |= SAS_SATA_DEV; in sas_get_ata_info()
262 if (phy->attached_dev_type == SAS_SATA_PENDING) in sas_get_ata_info()
263 dev->dev_type = SAS_SATA_PENDING; in sas_get_ata_info()
267 dev->dev_type = SAS_SATA_DEV; in sas_get_ata_info()
268 res = sas_get_report_phy_sata(dev->parent, phy->phy_id, in sas_get_ata_info()
269 &dev->sata_dev.rps_resp); in sas_get_ata_info()
272 SAS_ADDR(dev->parent->sas_addr), in sas_get_ata_info()
273 phy->phy_id, res); in sas_get_ata_info()
276 memcpy(dev->frame_rcvd, &dev->sata_dev.rps_resp.rps.fis, in sas_get_ata_info()
278 dev->sata_dev.class = sas_get_ata_command_set(dev); in sas_get_ata_info()
288 if (dev->dev_type != SAS_SATA_PENDING) in sas_ata_clear_pending()
303 struct domain_device *dev = link->ap->private_data; in smp_ata_check_ready_type()
305 struct domain_device *ex_dev = dev->parent; in smp_ata_check_ready_type()
310 res = sas_get_phy_attached_dev(ex_dev, phy->number, sas_addr, &type); in smp_ata_check_ready_type()
321 return -ENODEV; in smp_ata_check_ready_type()
329 struct ata_port *ap = link->ap; in smp_ata_check_ready()
330 struct domain_device *dev = ap->private_data; in smp_ata_check_ready()
331 struct domain_device *ex_dev = dev->parent; in smp_ata_check_ready()
333 struct ex_phy *ex_phy = &ex_dev->ex_dev.ex_phy[phy->number]; in smp_ata_check_ready()
335 res = sas_ex_phy_discover(ex_dev, phy->number); in smp_ata_check_ready()
341 if (res == -ECOMM) in smp_ata_check_ready()
346 switch (ex_phy->attached_dev_type) { in smp_ata_check_ready()
350 if (ex_phy->attached_sata_dev) in smp_ata_check_ready()
354 return -ENODEV; in smp_ata_check_ready()
360 struct ata_port *ap = link->ap; in local_ata_check_ready()
361 struct domain_device *dev = ap->private_data; in local_ata_check_ready()
364 if (i->dft->lldd_ata_check_ready) in local_ata_check_ready()
365 return i->dft->lldd_ata_check_ready(dev); in local_ata_check_ready()
378 struct ata_port *ap = ddev->sata_dev.ap; in sas_ata_printk()
379 struct device *dev = &ddev->rphy->dev; in sas_ata_printk()
390 level, ap->print_id, dev_name(dev), &vaf); in sas_ata_printk()
399 struct sata_device *sata_dev = &dev->sata_dev; in sas_ata_wait_after_reset()
401 struct ata_port *ap = sata_dev->ap; in sas_ata_wait_after_reset()
402 struct ata_link *link = &ap->link; in sas_ata_wait_after_reset()
414 if (ret && ret != -EAGAIN) in sas_ata_wait_after_reset()
423 struct ata_port *ap = link->ap; in sas_ata_hard_reset()
424 struct domain_device *dev = ap->private_data; in sas_ata_hard_reset()
428 ret = i->dft->lldd_I_T_nexus_reset(dev); in sas_ata_hard_reset()
429 if (ret == -ENODEV) in sas_ata_hard_reset()
437 *class = dev->sata_dev.class; in sas_ata_hard_reset()
439 ap->cbl = ATA_CBL_SATA; in sas_ata_hard_reset()
445 * that bypasses scsi-eh
449 struct sas_internal *si = dev_to_sas_internal(task->dev); in sas_ata_internal_abort()
453 spin_lock_irqsave(&task->task_state_lock, flags); in sas_ata_internal_abort()
454 if (task->task_state_flags & SAS_TASK_STATE_ABORTED || in sas_ata_internal_abort()
455 task->task_state_flags & SAS_TASK_STATE_DONE) { in sas_ata_internal_abort()
456 spin_unlock_irqrestore(&task->task_state_lock, flags); in sas_ata_internal_abort()
460 task->task_state_flags |= SAS_TASK_STATE_ABORTED; in sas_ata_internal_abort()
461 spin_unlock_irqrestore(&task->task_state_lock, flags); in sas_ata_internal_abort()
463 res = si->dft->lldd_abort_task(task); in sas_ata_internal_abort()
465 spin_lock_irqsave(&task->task_state_lock, flags); in sas_ata_internal_abort()
466 if (task->task_state_flags & SAS_TASK_STATE_DONE || in sas_ata_internal_abort()
468 spin_unlock_irqrestore(&task->task_state_lock, flags); in sas_ata_internal_abort()
472 /* XXX we are not prepared to deal with ->lldd_abort_task() in sas_ata_internal_abort()
479 if (!(task->task_state_flags & SAS_TASK_STATE_DONE)) in sas_ata_internal_abort()
480 task->task_state_flags &= ~SAS_TASK_STATE_ABORTED; in sas_ata_internal_abort()
481 spin_unlock_irqrestore(&task->task_state_lock, flags); in sas_ata_internal_abort()
490 if (qc->flags & ATA_QCFLAG_EH) in sas_ata_post_internal()
491 qc->err_mask |= AC_ERR_OTHER; in sas_ata_post_internal()
493 if (qc->err_mask) { in sas_ata_post_internal()
499 * ->lldd_abort_task) that the task is dead and free it in sas_ata_post_internal()
502 struct sas_task *task = qc->lldd_task; in sas_ata_post_internal()
504 qc->lldd_task = NULL; in sas_ata_post_internal()
507 task->uldd_task = NULL; in sas_ata_post_internal()
515 struct domain_device *dev = ap->private_data; in sas_ata_set_dmamode()
518 if (i->dft->lldd_ata_set_dmamode) in sas_ata_set_dmamode()
519 i->dft->lldd_ata_set_dmamode(dev); in sas_ata_set_dmamode()
524 struct domain_device *dev = ap->private_data; in sas_ata_sched_eh()
525 struct sas_ha_struct *ha = dev->port->ha; in sas_ata_sched_eh()
528 spin_lock_irqsave(&ha->lock, flags); in sas_ata_sched_eh()
529 if (!test_and_set_bit(SAS_DEV_EH_PENDING, &dev->state)) in sas_ata_sched_eh()
530 ha->eh_active++; in sas_ata_sched_eh()
532 spin_unlock_irqrestore(&ha->lock, flags); in sas_ata_sched_eh()
537 struct domain_device *dev = ap->private_data; in sas_ata_end_eh()
538 struct sas_ha_struct *ha = dev->port->ha; in sas_ata_end_eh()
541 spin_lock_irqsave(&ha->lock, flags); in sas_ata_end_eh()
542 if (test_and_clear_bit(SAS_DEV_EH_PENDING, &dev->state)) in sas_ata_end_eh()
543 ha->eh_active--; in sas_ata_end_eh()
544 spin_unlock_irqrestore(&ha->lock, flags); in sas_ata_end_eh()
549 struct ata_port *ap = link->ap; in sas_ata_prereset()
550 struct domain_device *dev = ap->private_data; in sas_ata_prereset()
554 if (!local_phy->enabled || test_bit(SAS_DEV_GONE, &dev->state)) in sas_ata_prereset()
555 res = -ENOENT; in sas_ata_prereset()
576 struct sas_ha_struct *ha = found_dev->port->ha; in sas_ata_init()
577 struct Scsi_Host *shost = ha->shost; in sas_ata_init()
585 return -ENOMEM; in sas_ata_init()
588 ata_host_init(ata_host, ha->dev, &sas_sata_ops); in sas_ata_init()
593 rc = -ENODEV; in sas_ata_init()
597 ap->port_no = 0; in sas_ata_init()
598 ap->pio_mask = ATA_PIO4; in sas_ata_init()
599 ap->mwdma_mask = ATA_MWDMA2; in sas_ata_init()
600 ap->udma_mask = ATA_UDMA6; in sas_ata_init()
601 ap->flags |= ATA_FLAG_SATA | ATA_FLAG_PIO_DMA | ATA_FLAG_NCQ | in sas_ata_init()
603 ap->ops = &sas_sata_ops; in sas_ata_init()
604 ap->private_data = found_dev; in sas_ata_init()
605 ap->cbl = ATA_CBL_SATA; in sas_ata_init()
606 ap->scsi_host = shost; in sas_ata_init()
608 rc = ata_tport_add(ata_host->dev, ap); in sas_ata_init()
612 found_dev->sata_dev.ata_host = ata_host; in sas_ata_init()
613 found_dev->sata_dev.ap = ap; in sas_ata_init()
626 struct ata_queued_cmd *qc = task->uldd_task; in sas_ata_task_abort()
629 /* Bounce SCSI-initiated commands to the SCSI EH */ in sas_ata_task_abort()
630 if (qc->scsicmd) { in sas_ata_task_abort()
631 blk_abort_request(scsi_cmd_to_rq(qc->scsicmd)); in sas_ata_task_abort()
636 qc->flags &= ~ATA_QCFLAG_ACTIVE; in sas_ata_task_abort()
637 qc->flags |= ATA_QCFLAG_EH; in sas_ata_task_abort()
638 qc->err_mask |= AC_ERR_TIMEOUT; in sas_ata_task_abort()
639 waiting = qc->private_data; in sas_ata_task_abort()
647 mutex_lock(&port->ha->disco_mutex); in sas_probe_sata()
648 list_for_each_entry(dev, &port->disco_list, disco_list_node) { in sas_probe_sata()
652 ata_port_probe(dev->sata_dev.ap); in sas_probe_sata()
654 mutex_unlock(&port->ha->disco_mutex); in sas_probe_sata()
656 list_for_each_entry_safe(dev, n, &port->disco_list, disco_list_node) { in sas_probe_sata()
666 sas_fail_probe(dev, __func__, -ENODEV); in sas_probe_sata()
677 if (child->linkrate > parent->min_linkrate) { in sas_ata_add_dev()
678 struct sas_phy *cphy = child->phy; in sas_ata_add_dev()
679 enum sas_linkrate min_prate = cphy->minimum_linkrate, in sas_ata_add_dev()
680 parent_min_lrate = parent->min_linkrate, in sas_ata_add_dev()
684 .maximum_linkrate = parent->min_linkrate, in sas_ata_add_dev()
689 SAS_ADDR(child->sas_addr), phy_id); in sas_ata_add_dev()
694 SAS_ADDR(child->sas_addr), phy_id, ret); in sas_ata_add_dev()
698 SAS_ADDR(child->sas_addr), phy_id); in sas_ata_add_dev()
699 child->linkrate = child->min_linkrate; in sas_ata_add_dev()
710 rphy = sas_end_device_alloc(phy->port); in sas_ata_add_dev()
712 return -ENOMEM; in sas_ata_add_dev()
714 rphy->identify.phy_identifier = phy_id; in sas_ata_add_dev()
715 child->rphy = rphy; in sas_ata_add_dev()
716 get_device(&rphy->dev); in sas_ata_add_dev()
718 list_add_tail(&child->disco_list_node, &parent->port->disco_list); in sas_ata_add_dev()
723 SAS_ADDR(child->sas_addr), in sas_ata_add_dev()
724 SAS_ADDR(parent->sas_addr), phy_id, ret); in sas_ata_add_dev()
725 sas_rphy_free(child->rphy); in sas_ata_add_dev()
726 list_del(&child->disco_list_node); in sas_ata_add_dev()
737 list_for_each_entry_safe(dev, n, &port->dev_list, dev_list_node) { in sas_ata_flush_pm_eh()
745 sas_fail_probe(dev, func, -ENODEV); in sas_ata_flush_pm_eh()
753 mutex_lock(&port->ha->disco_mutex); in sas_suspend_sata()
754 list_for_each_entry(dev, &port->dev_list, dev_list_node) { in sas_suspend_sata()
760 sata = &dev->sata_dev; in sas_suspend_sata()
761 if (sata->ap->pm_mesg.event == PM_EVENT_SUSPEND) in sas_suspend_sata()
764 ata_sas_port_suspend(sata->ap); in sas_suspend_sata()
766 mutex_unlock(&port->ha->disco_mutex); in sas_suspend_sata()
775 mutex_lock(&port->ha->disco_mutex); in sas_resume_sata()
776 list_for_each_entry(dev, &port->dev_list, dev_list_node) { in sas_resume_sata()
782 sata = &dev->sata_dev; in sas_resume_sata()
783 if (sata->ap->pm_mesg.event == PM_EVENT_ON) in sas_resume_sata()
786 ata_sas_port_resume(sata->ap); in sas_resume_sata()
788 mutex_unlock(&port->ha->disco_mutex); in sas_resume_sata()
794 * sas_discover_sata - discover an STP/SATA domain device
797 * Devices directly attached to a HA port, have no parents. All other
803 if (dev->dev_type == SAS_SATA_PM) in sas_discover_sata()
804 return -ENODEV; in sas_discover_sata()
806 dev->sata_dev.class = sas_get_ata_command_set(dev); in sas_discover_sata()
807 sas_fill_in_rphy(dev, dev->rphy); in sas_discover_sata()
815 struct ata_port *ap = dev->sata_dev.ap; in async_sas_ata_eh()
816 struct sas_ha_struct *ha = dev->port->ha; in async_sas_ata_eh()
819 ata_scsi_port_error_handler(ha->shost, ap); in async_sas_ata_eh()
839 spin_lock_irq(&sas_ha->phy_port_lock); in sas_ata_strategy_handler()
840 for (i = 0; i < sas_ha->num_phys; i++) { in sas_ata_strategy_handler()
841 struct asd_sas_port *port = sas_ha->sas_port[i]; in sas_ata_strategy_handler()
844 spin_lock(&port->dev_list_lock); in sas_ata_strategy_handler()
845 list_for_each_entry(dev, &port->dev_list, dev_list_node) { in sas_ata_strategy_handler()
853 kref_get(&dev->kref); in sas_ata_strategy_handler()
857 spin_unlock(&port->dev_list_lock); in sas_ata_strategy_handler()
859 spin_unlock_irq(&sas_ha->phy_port_lock); in sas_ata_strategy_handler()
883 list_move(&cmd->eh_entry, &sata_q); in sas_ata_eh()
887 struct ata_port *ap = eh_dev->sata_dev.ap; in sas_ata_eh()
917 ap = dev->sata_dev.ap; in sas_ata_schedule_reset()
918 ehi = &ap->link.eh_info; in sas_ata_schedule_reset()
920 spin_lock_irqsave(ap->lock, flags); in sas_ata_schedule_reset()
921 ehi->err_mask |= AC_ERR_TIMEOUT; in sas_ata_schedule_reset()
922 ehi->action |= ATA_EH_RESET; in sas_ata_schedule_reset()
924 spin_unlock_irqrestore(ap->lock, flags); in sas_ata_schedule_reset()
935 ap = dev->sata_dev.ap; in sas_ata_wait_eh()
941 struct ata_port *ap = device->sata_dev.ap; in sas_ata_device_link_abort()
942 struct ata_link *link = &ap->link; in sas_ata_device_link_abort()
945 spin_lock_irqsave(ap->lock, flags); in sas_ata_device_link_abort()
946 device->sata_dev.fis[2] = ATA_ERR | ATA_DRDY; /* tf status */ in sas_ata_device_link_abort()
947 device->sata_dev.fis[3] = ATA_ABORTED; /* tf error */ in sas_ata_device_link_abort()
949 link->eh_info.err_mask |= AC_ERR_DEV; in sas_ata_device_link_abort()
951 link->eh_info.action |= ATA_EH_RESET; in sas_ata_device_link_abort()
953 spin_unlock_irqrestore(ap->lock, flags); in sas_ata_device_link_abort()
974 rc = ata_ncq_prio_supported(ddev->sata_dev.ap, sdev, &supported); in sas_ncq_prio_supported_show()
993 rc = ata_ncq_prio_enabled(ddev->sata_dev.ap, sdev, &enabled); in sas_ncq_prio_enable_show()
1013 rc = ata_ncq_prio_enable(ddev->sata_dev.ap, sdev, enable); in sas_ncq_prio_enable_store()
1040 return attr->mode; in sas_ata_attr_is_visible()