2 * Serial Attached SCSI (SAS) class SCSI Host glue.
4 * Copyright (C) 2005 Adaptec, Inc. All rights reserved.
5 * Copyright (C) 2005 Luben Tuikov <luben_tuikov@adaptec.com>
7 * This file is licensed under GPLv2.
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of the
12 * License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
26 #include "sas_internal.h"
28 #include <scsi/scsi_host.h>
29 #include <scsi/scsi_device.h>
30 #include <scsi/scsi_tcq.h>
31 #include <scsi/scsi.h>
32 #include <scsi/scsi_eh.h>
33 #include <scsi/scsi_transport.h>
34 #include <scsi/scsi_transport_sas.h>
35 #include "../scsi_sas_internal.h"
36 #include "../scsi_transport_api.h"
38 #include <linux/err.h>
39 #include <linux/blkdev.h>
40 #include <linux/scatterlist.h>
42 /* ---------- SCSI Host glue ---------- */
44 #define TO_SAS_TASK(_scsi_cmd) ((void *)(_scsi_cmd)->host_scribble)
45 #define ASSIGN_SAS_TASK(_sc, _t) do { (_sc)->host_scribble = (void *) _t; } while (0)
47 static void sas_scsi_task_done(struct sas_task *task)
49 struct task_status_struct *ts = &task->task_status;
50 struct scsi_cmnd *sc = task->uldd_task;
51 struct sas_ha_struct *sas_ha = SHOST_TO_SAS_HA(sc->device->host);
52 unsigned ts_flags = task->task_state_flags;
56 SAS_DPRINTK("task_done called with non existing SCSI cmnd!\n");
57 list_del_init(&task->list);
62 if (ts->resp == SAS_TASK_UNDELIVERED) {
65 } else { /* ts->resp == SAS_TASK_COMPLETE */
66 /* task delivered, what happened afterwards? */
68 case SAS_DEV_NO_RESPONSE:
75 case SAS_DATA_UNDERRUN:
76 sc->resid = ts->residual;
77 if (sc->request_bufflen - sc->resid < sc->underflow)
80 case SAS_DATA_OVERRUN:
84 hs = DID_SOFT_ERROR; /* retry */
86 case SAS_DEVICE_UNKNOWN:
93 if (ts->open_rej_reason == SAS_OREJ_RSVD_RETRY)
94 hs = DID_SOFT_ERROR; /* retry */
98 case SAS_PROTO_RESPONSE:
99 SAS_DPRINTK("LLDD:%s sent SAS_PROTO_RESP for an SSP "
100 "task; please report this\n",
101 task->dev->port->ha->sas_ha_name);
103 case SAS_ABORTED_TASK:
107 memcpy(sc->sense_buffer, ts->buf,
108 max(SCSI_SENSE_BUFFERSIZE, ts->buf_valid_size));
109 stat = SAM_CHECK_COND;
116 ASSIGN_SAS_TASK(sc, NULL);
117 sc->result = (hs << 16) | stat;
118 list_del_init(&task->list);
120 /* This is very ugly but this is how SCSI Core works. */
121 if (ts_flags & SAS_TASK_STATE_ABORTED)
122 scsi_eh_finish_cmd(sc, &sas_ha->eh_done_q);
127 static enum task_attribute sas_scsi_get_task_attr(struct scsi_cmnd *cmd)
129 enum task_attribute ta = TASK_ATTR_SIMPLE;
130 if (cmd->request && blk_rq_tagged(cmd->request)) {
131 if (cmd->device->ordered_tags &&
132 (cmd->request->cmd_flags & REQ_HARDBARRIER))
138 static struct sas_task *sas_create_task(struct scsi_cmnd *cmd,
139 struct domain_device *dev,
142 struct sas_task *task = sas_alloc_task(gfp_flags);
148 *(u32 *)cmd->sense_buffer = 0;
149 task->uldd_task = cmd;
150 ASSIGN_SAS_TASK(cmd, task);
153 task->task_proto = task->dev->tproto; /* BUG_ON(!SSP) */
155 task->ssp_task.retry_count = 1;
156 int_to_scsilun(cmd->device->lun, &lun);
157 memcpy(task->ssp_task.LUN, &lun.scsi_lun, 8);
158 task->ssp_task.task_attr = sas_scsi_get_task_attr(cmd);
159 memcpy(task->ssp_task.cdb, cmd->cmnd, 16);
161 task->scatter = cmd->request_buffer;
162 task->num_scatter = cmd->use_sg;
163 task->total_xfer_len = cmd->request_bufflen;
164 task->data_dir = cmd->sc_data_direction;
166 task->task_done = sas_scsi_task_done;
171 static int sas_queue_up(struct sas_task *task)
173 struct sas_ha_struct *sas_ha = task->dev->port->ha;
174 struct scsi_core *core = &sas_ha->core;
178 spin_lock_irqsave(&core->task_queue_lock, flags);
179 if (sas_ha->lldd_queue_size < core->task_queue_size + 1) {
180 spin_unlock_irqrestore(&core->task_queue_lock, flags);
181 return -SAS_QUEUE_FULL;
183 list_add_tail(&task->list, &core->task_queue);
184 core->task_queue_size += 1;
185 spin_unlock_irqrestore(&core->task_queue_lock, flags);
186 up(&core->queue_thread_sema);
192 * sas_queuecommand -- Enqueue a command for processing
193 * @parameters: See SCSI Core documentation
195 * Note: XXX: Remove the host unlock/lock pair when SCSI Core can
196 * call us without holding an IRQ spinlock...
198 int sas_queuecommand(struct scsi_cmnd *cmd,
199 void (*scsi_done)(struct scsi_cmnd *))
202 struct domain_device *dev = cmd_to_domain_dev(cmd);
203 struct Scsi_Host *host = cmd->device->host;
204 struct sas_internal *i = to_sas_internal(host->transportt);
206 spin_unlock_irq(host->host_lock);
209 struct sas_ha_struct *sas_ha = dev->port->ha;
210 struct sas_task *task;
213 task = sas_create_task(cmd, dev, GFP_ATOMIC);
217 cmd->scsi_done = scsi_done;
218 /* Queue up, Direct Mode or Task Collector Mode. */
219 if (sas_ha->lldd_max_execute_num < 2)
220 res = i->dft->lldd_execute_task(task, 1, GFP_ATOMIC);
222 res = sas_queue_up(task);
226 SAS_DPRINTK("lldd_execute_task returned: %d\n", res);
227 ASSIGN_SAS_TASK(cmd, NULL);
229 if (res == -SAS_QUEUE_FULL) {
230 cmd->result = DID_SOFT_ERROR << 16; /* retry */
238 spin_lock_irq(host->host_lock);
242 static void sas_scsi_clear_queue_lu(struct list_head *error_q, struct scsi_cmnd *my_cmd)
244 struct scsi_cmnd *cmd, *n;
246 list_for_each_entry_safe(cmd, n, error_q, eh_entry) {
248 list_del_init(&cmd->eh_entry);
252 static void sas_scsi_clear_queue_I_T(struct list_head *error_q,
253 struct domain_device *dev)
255 struct scsi_cmnd *cmd, *n;
257 list_for_each_entry_safe(cmd, n, error_q, eh_entry) {
258 struct domain_device *x = cmd_to_domain_dev(cmd);
261 list_del_init(&cmd->eh_entry);
265 static void sas_scsi_clear_queue_port(struct list_head *error_q,
266 struct asd_sas_port *port)
268 struct scsi_cmnd *cmd, *n;
270 list_for_each_entry_safe(cmd, n, error_q, eh_entry) {
271 struct domain_device *dev = cmd_to_domain_dev(cmd);
272 struct asd_sas_port *x = dev->port;
275 list_del_init(&cmd->eh_entry);
279 enum task_disposition {
286 static enum task_disposition sas_scsi_find_task(struct sas_task *task)
288 struct sas_ha_struct *ha = task->dev->port->ha;
291 struct sas_internal *si =
292 to_sas_internal(task->dev->port->ha->core.shost->transportt);
294 if (ha->lldd_max_execute_num > 1) {
295 struct scsi_core *core = &ha->core;
296 struct sas_task *t, *n;
298 spin_lock_irqsave(&core->task_queue_lock, flags);
299 list_for_each_entry_safe(t, n, &core->task_queue, list) {
301 list_del_init(&t->list);
302 spin_unlock_irqrestore(&core->task_queue_lock,
304 SAS_DPRINTK("%s: task 0x%p aborted from "
307 return TASK_IS_ABORTED;
310 spin_unlock_irqrestore(&core->task_queue_lock, flags);
313 spin_lock_irqsave(&task->task_state_lock, flags);
314 if (task->task_state_flags & SAS_TASK_INITIATOR_ABORTED) {
315 spin_unlock_irqrestore(&task->task_state_lock, flags);
316 SAS_DPRINTK("%s: task 0x%p already aborted\n",
318 return TASK_IS_ABORTED;
320 spin_unlock_irqrestore(&task->task_state_lock, flags);
322 for (i = 0; i < 5; i++) {
323 SAS_DPRINTK("%s: aborting task 0x%p\n", __FUNCTION__, task);
324 res = si->dft->lldd_abort_task(task);
326 spin_lock_irqsave(&task->task_state_lock, flags);
327 if (task->task_state_flags & SAS_TASK_STATE_DONE) {
328 spin_unlock_irqrestore(&task->task_state_lock, flags);
329 SAS_DPRINTK("%s: task 0x%p is done\n", __FUNCTION__,
333 spin_unlock_irqrestore(&task->task_state_lock, flags);
335 if (res == TMF_RESP_FUNC_COMPLETE) {
336 SAS_DPRINTK("%s: task 0x%p is aborted\n",
338 return TASK_IS_ABORTED;
339 } else if (si->dft->lldd_query_task) {
340 SAS_DPRINTK("%s: querying task 0x%p\n",
342 res = si->dft->lldd_query_task(task);
343 if (res == TMF_RESP_FUNC_SUCC) {
344 SAS_DPRINTK("%s: task 0x%p at LU\n",
346 return TASK_IS_AT_LU;
347 } else if (res == TMF_RESP_FUNC_COMPLETE) {
348 SAS_DPRINTK("%s: task 0x%p not at LU\n",
350 return TASK_IS_NOT_AT_LU;
357 static int sas_recover_lu(struct domain_device *dev, struct scsi_cmnd *cmd)
359 int res = TMF_RESP_FUNC_FAILED;
361 struct sas_internal *i =
362 to_sas_internal(dev->port->ha->core.shost->transportt);
364 int_to_scsilun(cmd->device->lun, &lun);
366 SAS_DPRINTK("eh: device %llx LUN %x has the task\n",
367 SAS_ADDR(dev->sas_addr),
370 if (i->dft->lldd_abort_task_set)
371 res = i->dft->lldd_abort_task_set(dev, lun.scsi_lun);
373 if (res == TMF_RESP_FUNC_FAILED) {
374 if (i->dft->lldd_clear_task_set)
375 res = i->dft->lldd_clear_task_set(dev, lun.scsi_lun);
378 if (res == TMF_RESP_FUNC_FAILED) {
379 if (i->dft->lldd_lu_reset)
380 res = i->dft->lldd_lu_reset(dev, lun.scsi_lun);
386 static int sas_recover_I_T(struct domain_device *dev)
388 int res = TMF_RESP_FUNC_FAILED;
389 struct sas_internal *i =
390 to_sas_internal(dev->port->ha->core.shost->transportt);
392 SAS_DPRINTK("I_T nexus reset for dev %016llx\n",
393 SAS_ADDR(dev->sas_addr));
395 if (i->dft->lldd_I_T_nexus_reset)
396 res = i->dft->lldd_I_T_nexus_reset(dev);
401 void sas_scsi_recover_host(struct Scsi_Host *shost)
403 struct sas_ha_struct *ha = SHOST_TO_SAS_HA(shost);
406 struct scsi_cmnd *cmd, *n;
407 enum task_disposition res = TASK_IS_DONE;
409 struct sas_internal *i = to_sas_internal(shost->transportt);
411 spin_lock_irqsave(shost->host_lock, flags);
412 list_splice_init(&shost->eh_cmd_q, &error_q);
413 spin_unlock_irqrestore(shost->host_lock, flags);
415 SAS_DPRINTK("Enter %s\n", __FUNCTION__);
417 /* All tasks on this list were marked SAS_TASK_STATE_ABORTED
418 * by sas_scsi_timed_out() callback.
421 SAS_DPRINTK("going over list...\n");
422 list_for_each_entry_safe(cmd, n, &error_q, eh_entry) {
423 struct sas_task *task = TO_SAS_TASK(cmd);
424 list_del_init(&cmd->eh_entry);
427 SAS_DPRINTK("%s: taskless cmd?!\n", __FUNCTION__);
430 SAS_DPRINTK("trying to find task 0x%p\n", task);
431 res = sas_scsi_find_task(task);
437 SAS_DPRINTK("%s: task 0x%p is done\n", __FUNCTION__,
439 task->task_done(task);
441 case TASK_IS_ABORTED:
442 SAS_DPRINTK("%s: task 0x%p is aborted\n",
444 task->task_done(task);
447 SAS_DPRINTK("task 0x%p is at LU: lu recover\n", task);
448 tmf_resp = sas_recover_lu(task->dev, cmd);
449 if (tmf_resp == TMF_RESP_FUNC_COMPLETE) {
450 SAS_DPRINTK("dev %016llx LU %x is "
454 task->task_done(task);
455 sas_scsi_clear_queue_lu(&error_q, cmd);
459 case TASK_IS_NOT_AT_LU:
460 SAS_DPRINTK("task 0x%p is not at LU: I_T recover\n",
462 tmf_resp = sas_recover_I_T(task->dev);
463 if (tmf_resp == TMF_RESP_FUNC_COMPLETE) {
464 SAS_DPRINTK("I_T %016llx recovered\n",
465 SAS_ADDR(task->dev->sas_addr));
466 task->task_done(task);
467 sas_scsi_clear_queue_I_T(&error_q, task->dev);
470 /* Hammer time :-) */
471 if (i->dft->lldd_clear_nexus_port) {
472 struct asd_sas_port *port = task->dev->port;
473 SAS_DPRINTK("clearing nexus for port:%d\n",
475 res = i->dft->lldd_clear_nexus_port(port);
476 if (res == TMF_RESP_FUNC_COMPLETE) {
477 SAS_DPRINTK("clear nexus port:%d "
478 "succeeded\n", port->id);
479 task->task_done(task);
480 sas_scsi_clear_queue_port(&error_q,
485 if (i->dft->lldd_clear_nexus_ha) {
486 SAS_DPRINTK("clear nexus ha\n");
487 res = i->dft->lldd_clear_nexus_ha(ha);
488 if (res == TMF_RESP_FUNC_COMPLETE) {
489 SAS_DPRINTK("clear nexus ha "
491 task->task_done(task);
495 /* If we are here -- this means that no amount
496 * of effort could recover from errors. Quite
497 * possibly the HA just disappeared.
499 SAS_DPRINTK("error from device %llx, LUN %x "
500 "couldn't be recovered in any way\n",
501 SAS_ADDR(task->dev->sas_addr),
504 task->task_done(task);
509 scsi_eh_flush_done_q(&ha->eh_done_q);
510 SAS_DPRINTK("--- Exit %s\n", __FUNCTION__);
513 SAS_DPRINTK("--- Exit %s -- clear_q\n", __FUNCTION__);
514 list_for_each_entry_safe(cmd, n, &error_q, eh_entry) {
515 struct sas_task *task = TO_SAS_TASK(cmd);
516 list_del_init(&cmd->eh_entry);
517 task->task_done(task);
521 enum scsi_eh_timer_return sas_scsi_timed_out(struct scsi_cmnd *cmd)
523 struct sas_task *task = TO_SAS_TASK(cmd);
527 SAS_DPRINTK("command 0x%p, task 0x%p, gone: EH_HANDLED\n",
532 spin_lock_irqsave(&task->task_state_lock, flags);
533 if (task->task_state_flags & SAS_TASK_INITIATOR_ABORTED) {
534 spin_unlock_irqrestore(&task->task_state_lock, flags);
535 SAS_DPRINTK("command 0x%p, task 0x%p, aborted by initiator: "
536 "EH_NOT_HANDLED\n", cmd, task);
537 return EH_NOT_HANDLED;
539 if (task->task_state_flags & SAS_TASK_STATE_DONE) {
540 spin_unlock_irqrestore(&task->task_state_lock, flags);
541 SAS_DPRINTK("command 0x%p, task 0x%p, timed out: EH_HANDLED\n",
545 if (!(task->task_state_flags & SAS_TASK_AT_INITIATOR)) {
546 spin_unlock_irqrestore(&task->task_state_lock, flags);
547 SAS_DPRINTK("command 0x%p, task 0x%p, not at initiator: "
550 return EH_RESET_TIMER;
552 task->task_state_flags |= SAS_TASK_STATE_ABORTED;
553 spin_unlock_irqrestore(&task->task_state_lock, flags);
555 SAS_DPRINTK("command 0x%p, task 0x%p, timed out: EH_NOT_HANDLED\n",
558 return EH_NOT_HANDLED;
561 struct domain_device *sas_find_dev_by_rphy(struct sas_rphy *rphy)
563 struct Scsi_Host *shost = dev_to_shost(rphy->dev.parent);
564 struct sas_ha_struct *ha = SHOST_TO_SAS_HA(shost);
565 struct domain_device *found_dev = NULL;
568 spin_lock(&ha->phy_port_lock);
569 for (i = 0; i < ha->num_phys; i++) {
570 struct asd_sas_port *port = ha->sas_port[i];
571 struct domain_device *dev;
573 spin_lock(&port->dev_list_lock);
574 list_for_each_entry(dev, &port->dev_list, dev_list_node) {
575 if (rphy == dev->rphy) {
577 spin_unlock(&port->dev_list_lock);
581 spin_unlock(&port->dev_list_lock);
584 spin_unlock(&ha->phy_port_lock);
589 static inline struct domain_device *sas_find_target(struct scsi_target *starget)
591 struct sas_rphy *rphy = dev_to_rphy(starget->dev.parent);
593 return sas_find_dev_by_rphy(rphy);
596 int sas_target_alloc(struct scsi_target *starget)
598 struct domain_device *found_dev = sas_find_target(starget);
603 starget->hostdata = found_dev;
607 #define SAS_DEF_QD 32
608 #define SAS_MAX_QD 64
610 int sas_slave_configure(struct scsi_device *scsi_dev)
612 struct domain_device *dev = sdev_to_domain_dev(scsi_dev);
613 struct sas_ha_struct *sas_ha;
615 BUG_ON(dev->rphy->identify.device_type != SAS_END_DEVICE);
617 sas_ha = dev->port->ha;
619 sas_read_port_mode_page(scsi_dev);
621 if (scsi_dev->tagged_supported) {
622 scsi_set_tag_type(scsi_dev, MSG_SIMPLE_TAG);
623 scsi_activate_tcq(scsi_dev, SAS_DEF_QD);
625 SAS_DPRINTK("device %llx, LUN %x doesn't support "
626 "TCQ\n", SAS_ADDR(dev->sas_addr),
628 scsi_dev->tagged_supported = 0;
629 scsi_set_tag_type(scsi_dev, 0);
630 scsi_deactivate_tcq(scsi_dev, 1);
636 void sas_slave_destroy(struct scsi_device *scsi_dev)
640 int sas_change_queue_depth(struct scsi_device *scsi_dev, int new_depth)
642 int res = min(new_depth, SAS_MAX_QD);
644 if (scsi_dev->tagged_supported)
645 scsi_adjust_queue_depth(scsi_dev, scsi_get_tag_type(scsi_dev),
648 struct domain_device *dev = sdev_to_domain_dev(scsi_dev);
649 sas_printk("device %llx LUN %x queue depth changed to 1\n",
650 SAS_ADDR(dev->sas_addr),
652 scsi_adjust_queue_depth(scsi_dev, 0, 1);
659 int sas_change_queue_type(struct scsi_device *scsi_dev, int qt)
661 if (!scsi_dev->tagged_supported)
664 scsi_deactivate_tcq(scsi_dev, 1);
666 scsi_set_tag_type(scsi_dev, qt);
667 scsi_activate_tcq(scsi_dev, scsi_dev->queue_depth);
672 int sas_bios_param(struct scsi_device *scsi_dev,
673 struct block_device *bdev,
674 sector_t capacity, int *hsc)
678 sector_div(capacity, 255*63);
684 /* ---------- Task Collector Thread implementation ---------- */
686 static void sas_queue(struct sas_ha_struct *sas_ha)
688 struct scsi_core *core = &sas_ha->core;
693 struct sas_internal *i = to_sas_internal(core->shost->transportt);
695 spin_lock_irqsave(&core->task_queue_lock, flags);
696 while (!core->queue_thread_kill &&
697 !list_empty(&core->task_queue)) {
699 can_queue = sas_ha->lldd_queue_size - core->task_queue_size;
700 if (can_queue >= 0) {
701 can_queue = core->task_queue_size;
702 list_splice_init(&core->task_queue, &q);
704 struct list_head *a, *n;
706 can_queue = sas_ha->lldd_queue_size;
707 list_for_each_safe(a, n, &core->task_queue) {
708 list_move_tail(a, &q);
709 if (--can_queue == 0)
712 can_queue = sas_ha->lldd_queue_size;
714 core->task_queue_size -= can_queue;
715 spin_unlock_irqrestore(&core->task_queue_lock, flags);
717 struct sas_task *task = list_entry(q.next,
721 res = i->dft->lldd_execute_task(task, can_queue,
724 __list_add(&q, task->list.prev, &task->list);
726 spin_lock_irqsave(&core->task_queue_lock, flags);
728 list_splice_init(&q, &core->task_queue); /*at head*/
729 core->task_queue_size += can_queue;
732 spin_unlock_irqrestore(&core->task_queue_lock, flags);
735 static DECLARE_COMPLETION(queue_th_comp);
738 * sas_queue_thread -- The Task Collector thread
739 * @_sas_ha: pointer to struct sas_ha
741 static int sas_queue_thread(void *_sas_ha)
743 struct sas_ha_struct *sas_ha = _sas_ha;
744 struct scsi_core *core = &sas_ha->core;
746 daemonize("sas_queue_%d", core->shost->host_no);
747 current->flags |= PF_NOFREEZE;
749 complete(&queue_th_comp);
752 down_interruptible(&core->queue_thread_sema);
754 if (core->queue_thread_kill)
758 complete(&queue_th_comp);
763 int sas_init_queue(struct sas_ha_struct *sas_ha)
766 struct scsi_core *core = &sas_ha->core;
768 spin_lock_init(&core->task_queue_lock);
769 core->task_queue_size = 0;
770 INIT_LIST_HEAD(&core->task_queue);
771 init_MUTEX_LOCKED(&core->queue_thread_sema);
773 res = kernel_thread(sas_queue_thread, sas_ha, 0);
775 wait_for_completion(&queue_th_comp);
777 return res < 0 ? res : 0;
780 void sas_shutdown_queue(struct sas_ha_struct *sas_ha)
783 struct scsi_core *core = &sas_ha->core;
784 struct sas_task *task, *n;
786 init_completion(&queue_th_comp);
787 core->queue_thread_kill = 1;
788 up(&core->queue_thread_sema);
789 wait_for_completion(&queue_th_comp);
791 if (!list_empty(&core->task_queue))
792 SAS_DPRINTK("HA: %llx: scsi core task queue is NOT empty!?\n",
793 SAS_ADDR(sas_ha->sas_addr));
795 spin_lock_irqsave(&core->task_queue_lock, flags);
796 list_for_each_entry_safe(task, n, &core->task_queue, list) {
797 struct scsi_cmnd *cmd = task->uldd_task;
799 list_del_init(&task->list);
801 ASSIGN_SAS_TASK(cmd, NULL);
803 cmd->result = DID_ABORT << 16;
806 spin_unlock_irqrestore(&core->task_queue_lock, flags);
809 static int do_sas_task_abort(struct sas_task *task)
811 struct scsi_cmnd *sc = task->uldd_task;
812 struct sas_internal *si =
813 to_sas_internal(task->dev->port->ha->core.shost->transportt);
817 spin_lock_irqsave(&task->task_state_lock, flags);
818 if (task->task_state_flags & SAS_TASK_STATE_ABORTED) {
819 spin_unlock_irqrestore(&task->task_state_lock, flags);
820 SAS_DPRINTK("%s: Task %p already aborted.\n", __FUNCTION__,
825 task->task_state_flags |= SAS_TASK_INITIATOR_ABORTED;
826 if (!(task->task_state_flags & SAS_TASK_STATE_DONE))
827 task->task_state_flags |= SAS_TASK_STATE_ABORTED;
828 spin_unlock_irqrestore(&task->task_state_lock, flags);
830 if (!si->dft->lldd_abort_task)
833 res = si->dft->lldd_abort_task(task);
834 if ((task->task_state_flags & SAS_TASK_STATE_DONE) ||
835 (res == TMF_RESP_FUNC_COMPLETE))
837 /* SMP commands don't have scsi_cmds(?) */
839 task->task_done(task);
842 scsi_req_abort_cmd(sc);
843 scsi_schedule_eh(sc->device->host);
847 spin_lock_irqsave(&task->task_state_lock, flags);
848 task->task_state_flags &= ~SAS_TASK_INITIATOR_ABORTED;
849 if (!(task->task_state_flags & SAS_TASK_STATE_DONE))
850 task->task_state_flags &= ~SAS_TASK_STATE_ABORTED;
851 spin_unlock_irqrestore(&task->task_state_lock, flags);
856 void sas_task_abort(struct work_struct *work)
858 struct sas_task *task =
859 container_of(work, struct sas_task, abort_work);
862 for (i = 0; i < 5; i++)
863 if (!do_sas_task_abort(task))
866 SAS_DPRINTK("%s: Could not kill task!\n", __FUNCTION__);
869 EXPORT_SYMBOL_GPL(sas_queuecommand);
870 EXPORT_SYMBOL_GPL(sas_target_alloc);
871 EXPORT_SYMBOL_GPL(sas_slave_configure);
872 EXPORT_SYMBOL_GPL(sas_slave_destroy);
873 EXPORT_SYMBOL_GPL(sas_change_queue_depth);
874 EXPORT_SYMBOL_GPL(sas_change_queue_type);
875 EXPORT_SYMBOL_GPL(sas_bios_param);
876 EXPORT_SYMBOL_GPL(sas_task_abort);
877 EXPORT_SYMBOL_GPL(sas_phy_reset);
878 EXPORT_SYMBOL_GPL(sas_phy_enable);