28 #include <linux/export.h>
29 #include <linux/ctype.h>
36 #include <scsi/scsi.h>
41 #include "../scsi_sas_internal.h"
42 #include "../scsi_transport_api.h"
43 #include "../scsi_priv.h"
73 if (scsi_bufflen(sc) - scsi_get_resid(sc) < sc->
underflow)
95 SAS_DPRINTK(
"LLDD:%s sent SAS_PROTO_RESP for an SSP "
96 "task; please report this\n",
97 task->
dev->port->ha->sas_ha_name);
115 list_del_init(&task->
list);
119 static void sas_scsi_task_done(
struct sas_task *task)
131 spin_unlock_irqrestore(&dev->
done_lock, flags);
140 SAS_DPRINTK(
"task_done called with non existing SCSI cmnd!\n");
141 list_del_init(&task->
list);
146 sas_end_task(sc, task);
172 task->
scatter = scsi_sglist(cmd);
216 if (dev_is_sata(dev)) {
217 spin_lock_irq(dev->
sata_dev.ap->lock);
219 spin_unlock_irq(dev->
sata_dev.ap->lock);
238 SAS_DPRINTK(
"lldd_execute_task returned: %d\n", res);
250 static void sas_eh_finish_cmd(
struct scsi_cmnd *cmd)
259 sas_end_task(cmd, task);
268 static void sas_eh_defer_cmd(
struct scsi_cmnd *cmd)
274 if (!dev_is_sata(dev)) {
275 sas_eh_finish_cmd(cmd);
280 sas_end_task(cmd, task);
284 static void sas_scsi_clear_queue_lu(
struct list_head *error_q,
struct scsi_cmnd *my_cmd)
289 if (cmd->
device->sdev_target == my_cmd->
device->sdev_target &&
291 sas_eh_defer_cmd(cmd);
295 static void sas_scsi_clear_queue_I_T(
struct list_head *error_q,
304 sas_eh_finish_cmd(cmd);
308 static void sas_scsi_clear_queue_port(
struct list_head *error_q,
318 sas_eh_finish_cmd(cmd);
347 list_del_init(&t->
list);
357 for (i = 0; i < 5; i++) {
358 SAS_DPRINTK(
"%s: aborting task 0x%p\n", __func__, task);
359 res = si->
dft->lldd_abort_task(task);
374 }
else if (si->
dft->lldd_query_task) {
377 res = si->
dft->lldd_query_task(task);
407 SAS_DPRINTK(
"eh: device %llx LUN %x has the task\n",
411 if (i->
dft->lldd_abort_task_set)
412 res = i->
dft->lldd_abort_task_set(dev,
lun.scsi_lun);
415 if (i->
dft->lldd_clear_task_set)
416 res = i->
dft->lldd_clear_task_set(dev,
lun.scsi_lun);
420 if (i->
dft->lldd_lu_reset)
421 res = i->
dft->lldd_lu_reset(dev,
lun.scsi_lun);
436 if (i->
dft->lldd_I_T_nexus_reset)
437 res = i->
dft->lldd_I_T_nexus_reset(dev);
468 if (dev_is_sata(dev)) {
473 spin_lock_irq(&ha->
lock);
477 spin_unlock_irq(&ha->
lock);
479 spin_lock_irq(&ha->
lock);
483 spin_unlock_irq(&ha->
lock);
486 if (scsi_host_in_recovery(ha->
core.shost)) {
496 int scheduled = 0, tries = 100;
499 if (dev_is_sata(dev)) {
506 while (!scheduled && tries--) {
507 spin_lock_irq(&ha->
lock);
518 spin_unlock_irq(&ha->
lock);
529 dev_name(&dev->
rphy->dev));
544 if (!i->
dft->lldd_abort_task)
547 res = i->
dft->lldd_abort_task(task);
569 if (!i->
dft->lldd_lu_reset)
589 if (!i->
dft->lldd_I_T_nexus_reset)
592 res = i->
dft->lldd_I_T_nexus_reset(dev);
601 static int try_to_reset_cmd_device(
struct scsi_cmnd *cmd)
606 if (!shost->
hostt->eh_device_reset_handler)
609 res = shost->
hostt->eh_device_reset_handler(cmd);
614 if (shost->
hostt->eh_bus_reset_handler)
615 return shost->
hostt->eh_bus_reset_handler(cmd);
624 int tmf_resp, need_reset;
641 spin_unlock_irqrestore(&dev->
done_lock, flags);
664 res = sas_scsi_find_task(task);
672 cmd->
retries ?
"retry" :
"aborted");
675 sas_eh_finish_cmd(cmd);
680 sas_eh_defer_cmd(cmd);
685 sas_eh_defer_cmd(cmd);
688 SAS_DPRINTK(
"task 0x%p is at LU: lu recover\n", task);
690 tmf_resp = sas_recover_lu(task->
dev, cmd);
696 sas_eh_defer_cmd(cmd);
697 sas_scsi_clear_queue_lu(work_q, cmd);
703 SAS_DPRINTK(
"task 0x%p is not at LU: I_T recover\n",
705 tmf_resp = sas_recover_I_T(task->
dev);
711 sas_eh_finish_cmd(cmd);
712 sas_scsi_clear_queue_I_T(work_q, dev);
716 try_to_reset_cmd_device(cmd);
717 if (i->
dft->lldd_clear_nexus_port) {
721 res = i->
dft->lldd_clear_nexus_port(port);
724 "succeeded\n", port->
id);
725 sas_eh_finish_cmd(cmd);
726 sas_scsi_clear_queue_port(work_q,
731 if (i->
dft->lldd_clear_nexus_ha) {
733 res = i->
dft->lldd_clear_nexus_ha(ha);
737 sas_eh_finish_cmd(cmd);
746 "couldn't be recovered in any way\n",
750 sas_eh_finish_cmd(cmd);
755 list_splice_tail(&
done, work_q);
756 list_splice_tail_init(&ha->
eh_ata_q, work_q);
762 sas_eh_finish_cmd(cmd);
772 spin_lock_irq(&ha->
lock);
773 while (!list_empty(&ha->
eh_dev_q)) {
780 kref_get(&dev->
kref);
781 WARN_ONCE(dev_is_sata(dev),
"ssp reset to ata device?\n");
783 spin_unlock_irq(&ha->
lock);
789 i->
dft->lldd_I_T_nexus_reset(dev);
792 spin_lock_irq(&ha->
lock);
796 spin_unlock_irq(&ha->
lock);
811 list_splice_init(&shost->
eh_cmd_q, &eh_work_q);
822 sas_eh_handle_sas_errors(shost, &eh_work_q);
824 if (list_empty(&eh_work_q))
841 sas_eh_handle_resets(shost);
849 spin_lock_irq(&ha->
lock);
854 spin_unlock_irq(&ha->
lock);
859 SAS_DPRINTK(
"--- Exit %s: busy: %d failed: %d tries: %d\n",
867 return BLK_EH_NOT_HANDLED;
874 if (dev_is_sata(dev))
882 struct Scsi_Host *shost = dev_to_shost(rphy->
dev.parent);
889 for (i = 0; i < ha->
num_phys; i++) {
895 if (rphy == dev->
rphy) {
917 kref_get(&found_dev->
kref);
922 #define SAS_DEF_QD 256
931 if (dev_is_sata(dev)) {
936 sas_ha = dev->
port->ha;
948 scsi_set_tag_type(scsi_dev, 0);
949 scsi_deactivate_tcq(scsi_dev, 1);
961 if (dev_is_sata(dev))
986 if (dev_is_sata(dev))
992 scsi_deactivate_tcq(scsi_dev, 1);
994 scsi_set_tag_type(scsi_dev, qt);
995 scsi_activate_tcq(scsi_dev, scsi_dev->
queue_depth);
1017 unsigned long flags;
1030 if (can_queue >= 0) {
1038 list_move_tail(a, &
q);
1039 if (--can_queue == 0)
1051 res = i->
dft->lldd_execute_task(task, can_queue,
1070 static int sas_queue_thread(
void *_sas_ha)
1095 "sas_queue_%d", core->
shost->host_no);
1103 unsigned long flags;
1110 SAS_DPRINTK(
"HA: %llx: scsi core task queue is NOT empty!?\n",
1117 list_del_init(&task->
list);
1147 if (dev_is_sata(task->
dev)) {
1151 unsigned long flags;
1155 spin_unlock_irqrestore(q->queue_lock, flags);
1167 sas_put_device(found_dev);
1170 static void sas_parse_addr(
u8 *
sas_addr,
const char *
p)
1181 sas_addr[
i] = (h<<4) | l;
1185 #define SAS_STRING_ADDR_SIZE 16
1201 sas_parse_addr(addr, fw->
data);