Lines Matching +full:ts +full:- +full:attached
1 // SPDX-License-Identifier: GPL-2.0-only
3 * Serial Attached SCSI (SAS) class SCSI Host glue.
39 struct task_status_struct *ts = &task->task_status; in sas_end_task() local
42 if (ts->resp == SAS_TASK_UNDELIVERED) { in sas_end_task()
45 } else { /* ts->resp == SAS_TASK_COMPLETE */ in sas_end_task()
47 switch (ts->stat) { in sas_end_task()
56 scsi_set_resid(sc, ts->residual); in sas_end_task()
57 if (scsi_bufflen(sc) - scsi_get_resid(sc) < sc->underflow) in sas_end_task()
73 if (ts->open_rej_reason == SAS_OREJ_RSVD_RETRY) in sas_end_task()
80 task->dev->port->ha->sas_ha_name); in sas_end_task()
86 memcpy(sc->sense_buffer, ts->buf, in sas_end_task()
87 min(SCSI_SENSE_BUFFERSIZE, ts->buf_valid_size)); in sas_end_task()
91 stat = ts->stat; in sas_end_task()
96 sc->result = (hs << 16) | stat; in sas_end_task()
103 struct scsi_cmnd *sc = task->uldd_task; in sas_scsi_task_done()
104 struct domain_device *dev = task->dev; in sas_scsi_task_done()
105 struct sas_ha_struct *ha = dev->port->ha; in sas_scsi_task_done()
108 spin_lock_irqsave(&dev->done_lock, flags); in sas_scsi_task_done()
109 if (test_bit(SAS_HA_FROZEN, &ha->state)) in sas_scsi_task_done()
113 spin_unlock_irqrestore(&dev->done_lock, flags); in sas_scsi_task_done()
128 sc->scsi_done(sc); in sas_scsi_task_done()
141 task->uldd_task = cmd; in sas_create_task()
144 task->dev = dev; in sas_create_task()
145 task->task_proto = task->dev->tproto; /* BUG_ON(!SSP) */ in sas_create_task()
147 task->ssp_task.retry_count = 1; in sas_create_task()
148 int_to_scsilun(cmd->device->lun, &lun); in sas_create_task()
149 memcpy(task->ssp_task.LUN, &lun.scsi_lun, 8); in sas_create_task()
150 task->ssp_task.task_attr = TASK_ATTR_SIMPLE; in sas_create_task()
151 task->ssp_task.cmd = cmd; in sas_create_task()
153 task->scatter = scsi_sglist(cmd); in sas_create_task()
154 task->num_scatter = scsi_sg_count(cmd); in sas_create_task()
155 task->total_xfer_len = scsi_bufflen(cmd); in sas_create_task()
156 task->data_dir = cmd->sc_data_direction; in sas_create_task()
158 task->task_done = sas_scsi_task_done; in sas_create_task()
165 struct sas_internal *i = to_sas_internal(host->transportt); in sas_queuecommand()
171 if (test_bit(SAS_DEV_GONE, &dev->state)) { in sas_queuecommand()
172 cmd->result = DID_BAD_TARGET << 16; in sas_queuecommand()
177 spin_lock_irq(dev->sata_dev.ap->lock); in sas_queuecommand()
178 res = ata_sas_queuecmd(cmd, dev->sata_dev.ap); in sas_queuecommand()
179 spin_unlock_irq(dev->sata_dev.ap->lock); in sas_queuecommand()
187 res = i->dft->lldd_execute_task(task, GFP_ATOMIC); in sas_queuecommand()
196 if (res == -SAS_QUEUE_FULL) in sas_queuecommand()
197 cmd->result = DID_SOFT_ERROR << 16; /* retry */ in sas_queuecommand()
199 cmd->result = DID_ERROR << 16; in sas_queuecommand()
201 cmd->scsi_done(cmd); in sas_queuecommand()
207 struct sas_ha_struct *sas_ha = SHOST_TO_SAS_HA(cmd->device->host); in sas_eh_finish_cmd()
221 list_move_tail(&cmd->eh_entry, &sas_ha->eh_ata_q); in sas_eh_finish_cmd()
229 scsi_eh_finish_cmd(cmd, &sas_ha->eh_done_q); in sas_eh_finish_cmd()
237 if (cmd->device->sdev_target == my_cmd->device->sdev_target && in sas_scsi_clear_queue_lu()
238 cmd->device->lun == my_cmd->device->lun) in sas_scsi_clear_queue_lu()
263 struct asd_sas_port *x = dev->port; in sas_scsi_clear_queue_port()
283 to_sas_internal(task->dev->port->ha->core.shost->transportt); in sas_scsi_find_task()
287 res = si->dft->lldd_abort_task(task); in sas_scsi_find_task()
289 spin_lock_irqsave(&task->task_state_lock, flags); in sas_scsi_find_task()
290 if (task->task_state_flags & SAS_TASK_STATE_DONE) { in sas_scsi_find_task()
291 spin_unlock_irqrestore(&task->task_state_lock, flags); in sas_scsi_find_task()
295 spin_unlock_irqrestore(&task->task_state_lock, flags); in sas_scsi_find_task()
301 } else if (si->dft->lldd_query_task) { in sas_scsi_find_task()
303 res = si->dft->lldd_query_task(task); in sas_scsi_find_task()
329 to_sas_internal(dev->port->ha->core.shost->transportt); in sas_recover_lu()
331 int_to_scsilun(cmd->device->lun, &lun); in sas_recover_lu()
334 SAS_ADDR(dev->sas_addr), in sas_recover_lu()
335 cmd->device->lun); in sas_recover_lu()
337 if (i->dft->lldd_abort_task_set) in sas_recover_lu()
338 res = i->dft->lldd_abort_task_set(dev, lun.scsi_lun); in sas_recover_lu()
341 if (i->dft->lldd_clear_task_set) in sas_recover_lu()
342 res = i->dft->lldd_clear_task_set(dev, lun.scsi_lun); in sas_recover_lu()
346 if (i->dft->lldd_lu_reset) in sas_recover_lu()
347 res = i->dft->lldd_lu_reset(dev, lun.scsi_lun); in sas_recover_lu()
357 to_sas_internal(dev->port->ha->core.shost->transportt); in sas_recover_I_T()
360 SAS_ADDR(dev->sas_addr)); in sas_recover_I_T()
362 if (i->dft->lldd_I_T_nexus_reset) in sas_recover_I_T()
363 res = i->dft->lldd_I_T_nexus_reset(dev); in sas_recover_I_T()
371 struct sas_ha_struct *ha = dev->port->ha; in sas_get_local_phy()
378 BUG_ON(!dev->phy); in sas_get_local_phy()
380 spin_lock_irqsave(&ha->phy_port_lock, flags); in sas_get_local_phy()
381 phy = dev->phy; in sas_get_local_phy()
382 get_device(&phy->dev); in sas_get_local_phy()
383 spin_unlock_irqrestore(&ha->phy_port_lock, flags); in sas_get_local_phy()
391 struct sas_ha_struct *ha = dev->port->ha; in sas_wait_eh()
395 ata_port_wait_eh(dev->sata_dev.ap); in sas_wait_eh()
399 spin_lock_irq(&ha->lock); in sas_wait_eh()
401 while (test_bit(SAS_DEV_EH_PENDING, &dev->state)) { in sas_wait_eh()
402 prepare_to_wait(&ha->eh_wait_q, &wait, TASK_UNINTERRUPTIBLE); in sas_wait_eh()
403 spin_unlock_irq(&ha->lock); in sas_wait_eh()
405 spin_lock_irq(&ha->lock); in sas_wait_eh()
407 finish_wait(&ha->eh_wait_q, &wait); in sas_wait_eh()
409 spin_unlock_irq(&ha->lock); in sas_wait_eh()
412 if (scsi_host_in_recovery(ha->core.shost)) { in sas_wait_eh()
421 struct sas_ha_struct *ha = dev->port->ha; in sas_queue_reset()
432 while (!scheduled && tries--) { in sas_queue_reset()
433 spin_lock_irq(&ha->lock); in sas_queue_reset()
434 if (!test_bit(SAS_DEV_EH_PENDING, &dev->state) && in sas_queue_reset()
435 !test_bit(reset_type, &dev->state)) { in sas_queue_reset()
437 ha->eh_active++; in sas_queue_reset()
438 list_add_tail(&dev->ssp_dev.eh_list_node, &ha->eh_dev_q); in sas_queue_reset()
439 set_bit(SAS_DEV_EH_PENDING, &dev->state); in sas_queue_reset()
440 set_bit(reset_type, &dev->state); in sas_queue_reset()
441 int_to_scsilun(lun, &dev->ssp_dev.reset_lun); in sas_queue_reset()
442 scsi_schedule_eh(ha->core.shost); in sas_queue_reset()
444 spin_unlock_irq(&ha->lock); in sas_queue_reset()
455 dev_name(&dev->rphy->dev)); in sas_queue_reset()
464 struct Scsi_Host *host = cmd->device->host; in sas_eh_abort_handler()
466 struct sas_internal *i = to_sas_internal(host->transportt); in sas_eh_abort_handler()
469 if (!i->dft->lldd_abort_task) in sas_eh_abort_handler()
472 spin_lock_irqsave(host->host_lock, flags); in sas_eh_abort_handler()
474 if (dev_is_sata(dev) && !host->host_eh_scheduled) { in sas_eh_abort_handler()
475 spin_unlock_irqrestore(host->host_lock, flags); in sas_eh_abort_handler()
478 spin_unlock_irqrestore(host->host_lock, flags); in sas_eh_abort_handler()
481 res = i->dft->lldd_abort_task(task); in sas_eh_abort_handler()
496 struct Scsi_Host *host = cmd->device->host; in sas_eh_device_reset_handler()
498 struct sas_internal *i = to_sas_internal(host->transportt); in sas_eh_device_reset_handler()
500 if (current != host->ehandler) in sas_eh_device_reset_handler()
501 return sas_queue_reset(dev, SAS_DEV_LU_RESET, cmd->device->lun, 0); in sas_eh_device_reset_handler()
503 int_to_scsilun(cmd->device->lun, &lun); in sas_eh_device_reset_handler()
505 if (!i->dft->lldd_lu_reset) in sas_eh_device_reset_handler()
508 res = i->dft->lldd_lu_reset(dev, lun.scsi_lun); in sas_eh_device_reset_handler()
518 struct Scsi_Host *host = cmd->device->host; in sas_eh_target_reset_handler()
520 struct sas_internal *i = to_sas_internal(host->transportt); in sas_eh_target_reset_handler()
522 if (current != host->ehandler) in sas_eh_target_reset_handler()
525 if (!i->dft->lldd_I_T_nexus_reset) in sas_eh_target_reset_handler()
528 res = i->dft->lldd_I_T_nexus_reset(dev); in sas_eh_target_reset_handler()
530 res == -ENODEV) in sas_eh_target_reset_handler()
540 struct Scsi_Host *shost = cmd->device->host; in try_to_reset_cmd_device()
542 if (!shost->hostt->eh_device_reset_handler) in try_to_reset_cmd_device()
545 res = shost->hostt->eh_device_reset_handler(cmd); in try_to_reset_cmd_device()
550 if (shost->hostt->eh_target_reset_handler) in try_to_reset_cmd_device()
551 return shost->hostt->eh_target_reset_handler(cmd); in try_to_reset_cmd_device()
561 struct sas_internal *i = to_sas_internal(shost->transportt); in sas_eh_handle_sas_errors()
571 spin_lock_irqsave(&dev->done_lock, flags); in sas_eh_handle_sas_errors()
577 spin_unlock_irqrestore(&dev->done_lock, flags); in sas_eh_handle_sas_errors()
580 list_move_tail(&cmd->eh_entry, &done); in sas_eh_handle_sas_errors()
587 list_del_init(&cmd->eh_entry); in sas_eh_handle_sas_errors()
589 spin_lock_irqsave(&task->task_state_lock, flags); in sas_eh_handle_sas_errors()
590 need_reset = task->task_state_flags & SAS_TASK_NEED_DEV_RESET; in sas_eh_handle_sas_errors()
591 spin_unlock_irqrestore(&task->task_state_lock, flags); in sas_eh_handle_sas_errors()
616 tmf_resp = sas_recover_lu(task->dev, cmd); in sas_eh_handle_sas_errors()
619 SAS_ADDR(task->dev), in sas_eh_handle_sas_errors()
620 cmd->device->lun); in sas_eh_handle_sas_errors()
630 tmf_resp = sas_recover_I_T(task->dev); in sas_eh_handle_sas_errors()
632 tmf_resp == -ENODEV) { in sas_eh_handle_sas_errors()
633 struct domain_device *dev = task->dev; in sas_eh_handle_sas_errors()
635 SAS_ADDR(task->dev->sas_addr)); in sas_eh_handle_sas_errors()
640 /* Hammer time :-) */ in sas_eh_handle_sas_errors()
642 if (i->dft->lldd_clear_nexus_port) { in sas_eh_handle_sas_errors()
643 struct asd_sas_port *port = task->dev->port; in sas_eh_handle_sas_errors()
645 port->id); in sas_eh_handle_sas_errors()
646 res = i->dft->lldd_clear_nexus_port(port); in sas_eh_handle_sas_errors()
649 port->id); in sas_eh_handle_sas_errors()
656 if (i->dft->lldd_clear_nexus_ha) { in sas_eh_handle_sas_errors()
658 res = i->dft->lldd_clear_nexus_ha(ha); in sas_eh_handle_sas_errors()
665 /* If we are here -- this means that no amount in sas_eh_handle_sas_errors()
670 SAS_ADDR(task->dev->sas_addr), in sas_eh_handle_sas_errors()
671 cmd->device->lun); in sas_eh_handle_sas_errors()
679 list_splice_tail_init(&ha->eh_ata_q, work_q); in sas_eh_handle_sas_errors()
683 pr_debug("--- Exit %s -- clear_q\n", __func__); in sas_eh_handle_sas_errors()
692 struct sas_internal *i = to_sas_internal(shost->transportt); in sas_eh_handle_resets()
695 spin_lock_irq(&ha->lock); in sas_eh_handle_resets()
696 while (!list_empty(&ha->eh_dev_q)) { in sas_eh_handle_resets()
700 ssp = list_entry(ha->eh_dev_q.next, typeof(*ssp), eh_list_node); in sas_eh_handle_resets()
701 list_del_init(&ssp->eh_list_node); in sas_eh_handle_resets()
703 kref_get(&dev->kref); in sas_eh_handle_resets()
706 spin_unlock_irq(&ha->lock); in sas_eh_handle_resets()
708 if (test_and_clear_bit(SAS_DEV_LU_RESET, &dev->state)) in sas_eh_handle_resets()
709 i->dft->lldd_lu_reset(dev, ssp->reset_lun.scsi_lun); in sas_eh_handle_resets()
711 if (test_and_clear_bit(SAS_DEV_RESET, &dev->state)) in sas_eh_handle_resets()
712 i->dft->lldd_I_T_nexus_reset(dev); in sas_eh_handle_resets()
715 spin_lock_irq(&ha->lock); in sas_eh_handle_resets()
716 clear_bit(SAS_DEV_EH_PENDING, &dev->state); in sas_eh_handle_resets()
717 ha->eh_active--; in sas_eh_handle_resets()
719 spin_unlock_irq(&ha->lock); in sas_eh_handle_resets()
733 spin_lock_irq(shost->host_lock); in sas_scsi_recover_host()
734 list_splice_init(&shost->eh_cmd_q, &eh_work_q); in sas_scsi_recover_host()
735 spin_unlock_irq(shost->host_lock); in sas_scsi_recover_host()
738 __func__, scsi_host_busy(shost), shost->host_failed); in sas_scsi_recover_host()
744 set_bit(SAS_HA_FROZEN, &ha->state); in sas_scsi_recover_host()
746 clear_bit(SAS_HA_FROZEN, &ha->state); in sas_scsi_recover_host()
752 * code (and hopefully sense data) attached. This is roughly what in sas_scsi_recover_host()
756 sas_ata_eh(shost, &eh_work_q, &ha->eh_done_q); in sas_scsi_recover_host()
757 if (!scsi_eh_get_sense(&eh_work_q, &ha->eh_done_q)) in sas_scsi_recover_host()
758 scsi_eh_ready_devs(shost, &eh_work_q, &ha->eh_done_q); in sas_scsi_recover_host()
763 /* now link into libata eh --- if we have any ata devices */ in sas_scsi_recover_host()
766 scsi_eh_flush_done_q(&ha->eh_done_q); in sas_scsi_recover_host()
769 spin_lock_irq(&ha->lock); in sas_scsi_recover_host()
770 if (ha->eh_active == 0) { in sas_scsi_recover_host()
771 shost->host_eh_scheduled = 0; in sas_scsi_recover_host()
774 spin_unlock_irq(&ha->lock); in sas_scsi_recover_host()
779 pr_notice("--- Exit %s: busy: %d failed: %d tries: %d\n", in sas_scsi_recover_host()
781 shost->host_failed, tries); in sas_scsi_recover_host()
789 return ata_sas_scsi_ioctl(dev->sata_dev.ap, sdev, cmd, arg); in sas_ioctl()
791 return -EINVAL; in sas_ioctl()
796 struct Scsi_Host *shost = dev_to_shost(rphy->dev.parent); in sas_find_dev_by_rphy()
802 spin_lock_irqsave(&ha->phy_port_lock, flags); in sas_find_dev_by_rphy()
803 for (i = 0; i < ha->num_phys; i++) { in sas_find_dev_by_rphy()
804 struct asd_sas_port *port = ha->sas_port[i]; in sas_find_dev_by_rphy()
807 spin_lock(&port->dev_list_lock); in sas_find_dev_by_rphy()
808 list_for_each_entry(dev, &port->dev_list, dev_list_node) { in sas_find_dev_by_rphy()
809 if (rphy == dev->rphy) { in sas_find_dev_by_rphy()
811 spin_unlock(&port->dev_list_lock); in sas_find_dev_by_rphy()
815 spin_unlock(&port->dev_list_lock); in sas_find_dev_by_rphy()
818 spin_unlock_irqrestore(&ha->phy_port_lock, flags); in sas_find_dev_by_rphy()
825 struct sas_rphy *rphy = dev_to_rphy(starget->dev.parent); in sas_target_alloc()
829 return -ENODEV; in sas_target_alloc()
831 kref_get(&found_dev->kref); in sas_target_alloc()
832 starget->hostdata = found_dev; in sas_target_alloc()
842 BUG_ON(dev->rphy->identify.device_type != SAS_END_DEVICE); in sas_slave_configure()
845 ata_sas_slave_configure(scsi_dev, dev->sata_dev.ap); in sas_slave_configure()
851 if (scsi_dev->tagged_supported) { in sas_slave_configure()
855 SAS_ADDR(dev->sas_addr), scsi_dev->lun); in sas_slave_configure()
859 scsi_dev->allow_restart = 1; in sas_slave_configure()
869 return __ata_change_queue_depth(dev->sata_dev.ap, sdev, depth); in sas_change_queue_depth()
871 if (!sdev->tagged_supported) in sas_change_queue_depth()
894 struct scsi_cmnd *sc = task->uldd_task; in sas_task_abort()
898 struct sas_task_slow *slow = task->slow_task; in sas_task_abort()
902 if (!del_timer(&slow->timer)) in sas_task_abort()
904 slow->timer.function(&slow->timer); in sas_task_abort()
908 if (dev_is_sata(task->dev)) in sas_task_abort()
911 blk_abort_request(sc->request); in sas_task_abort()
916 struct domain_device *found_dev = starget->hostdata; in sas_target_destroy()
921 starget->hostdata = NULL; in sas_target_destroy()
932 res = request_firmware(&fw, "sas_addr", &shost->shost_gendev); in sas_request_addr()
936 if (fw->size < SAS_STRING_ADDR_SIZE) { in sas_request_addr()
937 res = -ENODEV; in sas_request_addr()
941 res = hex2bin(addr, fw->data, strnlen(fw->data, SAS_ADDR_SIZE * 2) / 2); in sas_request_addr()