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 task->task_state_flags |= SAS_TASK_STATE_ABORTED;
546 spin_unlock_irqrestore(&task->task_state_lock, flags);
548 SAS_DPRINTK("command 0x%p, task 0x%p, timed out: EH_NOT_HANDLED\n",
551 return EH_NOT_HANDLED;
554 struct domain_device *sas_find_dev_by_rphy(struct sas_rphy *rphy)
556 struct Scsi_Host *shost = dev_to_shost(rphy->dev.parent);
557 struct sas_ha_struct *ha = SHOST_TO_SAS_HA(shost);
558 struct domain_device *found_dev = NULL;
561 spin_lock(&ha->phy_port_lock);
562 for (i = 0; i < ha->num_phys; i++) {
563 struct asd_sas_port *port = ha->sas_port[i];
564 struct domain_device *dev;
566 spin_lock(&port->dev_list_lock);
567 list_for_each_entry(dev, &port->dev_list, dev_list_node) {
568 if (rphy == dev->rphy) {
570 spin_unlock(&port->dev_list_lock);
574 spin_unlock(&port->dev_list_lock);
577 spin_unlock(&ha->phy_port_lock);
582 static inline struct domain_device *sas_find_target(struct scsi_target *starget)
584 struct sas_rphy *rphy = dev_to_rphy(starget->dev.parent);
586 return sas_find_dev_by_rphy(rphy);
589 int sas_target_alloc(struct scsi_target *starget)
591 struct domain_device *found_dev = sas_find_target(starget);
596 starget->hostdata = found_dev;
600 #define SAS_DEF_QD 32
601 #define SAS_MAX_QD 64
603 int sas_slave_configure(struct scsi_device *scsi_dev)
605 struct domain_device *dev = sdev_to_domain_dev(scsi_dev);
606 struct sas_ha_struct *sas_ha;
608 BUG_ON(dev->rphy->identify.device_type != SAS_END_DEVICE);
610 sas_ha = dev->port->ha;
612 sas_read_port_mode_page(scsi_dev);
614 if (scsi_dev->tagged_supported) {
615 scsi_set_tag_type(scsi_dev, MSG_SIMPLE_TAG);
616 scsi_activate_tcq(scsi_dev, SAS_DEF_QD);
618 SAS_DPRINTK("device %llx, LUN %x doesn't support "
619 "TCQ\n", SAS_ADDR(dev->sas_addr),
621 scsi_dev->tagged_supported = 0;
622 scsi_set_tag_type(scsi_dev, 0);
623 scsi_deactivate_tcq(scsi_dev, 1);
629 void sas_slave_destroy(struct scsi_device *scsi_dev)
633 int sas_change_queue_depth(struct scsi_device *scsi_dev, int new_depth)
635 int res = min(new_depth, SAS_MAX_QD);
637 if (scsi_dev->tagged_supported)
638 scsi_adjust_queue_depth(scsi_dev, scsi_get_tag_type(scsi_dev),
641 struct domain_device *dev = sdev_to_domain_dev(scsi_dev);
642 sas_printk("device %llx LUN %x queue depth changed to 1\n",
643 SAS_ADDR(dev->sas_addr),
645 scsi_adjust_queue_depth(scsi_dev, 0, 1);
652 int sas_change_queue_type(struct scsi_device *scsi_dev, int qt)
654 if (!scsi_dev->tagged_supported)
657 scsi_deactivate_tcq(scsi_dev, 1);
659 scsi_set_tag_type(scsi_dev, qt);
660 scsi_activate_tcq(scsi_dev, scsi_dev->queue_depth);
665 int sas_bios_param(struct scsi_device *scsi_dev,
666 struct block_device *bdev,
667 sector_t capacity, int *hsc)
671 sector_div(capacity, 255*63);
677 /* ---------- Task Collector Thread implementation ---------- */
679 static void sas_queue(struct sas_ha_struct *sas_ha)
681 struct scsi_core *core = &sas_ha->core;
686 struct sas_internal *i = to_sas_internal(core->shost->transportt);
688 spin_lock_irqsave(&core->task_queue_lock, flags);
689 while (!core->queue_thread_kill &&
690 !list_empty(&core->task_queue)) {
692 can_queue = sas_ha->lldd_queue_size - core->task_queue_size;
693 if (can_queue >= 0) {
694 can_queue = core->task_queue_size;
695 list_splice_init(&core->task_queue, &q);
697 struct list_head *a, *n;
699 can_queue = sas_ha->lldd_queue_size;
700 list_for_each_safe(a, n, &core->task_queue) {
701 list_move_tail(a, &q);
702 if (--can_queue == 0)
705 can_queue = sas_ha->lldd_queue_size;
707 core->task_queue_size -= can_queue;
708 spin_unlock_irqrestore(&core->task_queue_lock, flags);
710 struct sas_task *task = list_entry(q.next,
714 res = i->dft->lldd_execute_task(task, can_queue,
717 __list_add(&q, task->list.prev, &task->list);
719 spin_lock_irqsave(&core->task_queue_lock, flags);
721 list_splice_init(&q, &core->task_queue); /*at head*/
722 core->task_queue_size += can_queue;
725 spin_unlock_irqrestore(&core->task_queue_lock, flags);
728 static DECLARE_COMPLETION(queue_th_comp);
731 * sas_queue_thread -- The Task Collector thread
732 * @_sas_ha: pointer to struct sas_ha
734 static int sas_queue_thread(void *_sas_ha)
736 struct sas_ha_struct *sas_ha = _sas_ha;
737 struct scsi_core *core = &sas_ha->core;
739 daemonize("sas_queue_%d", core->shost->host_no);
740 current->flags |= PF_NOFREEZE;
742 complete(&queue_th_comp);
745 down_interruptible(&core->queue_thread_sema);
747 if (core->queue_thread_kill)
751 complete(&queue_th_comp);
756 int sas_init_queue(struct sas_ha_struct *sas_ha)
759 struct scsi_core *core = &sas_ha->core;
761 spin_lock_init(&core->task_queue_lock);
762 core->task_queue_size = 0;
763 INIT_LIST_HEAD(&core->task_queue);
764 init_MUTEX_LOCKED(&core->queue_thread_sema);
766 res = kernel_thread(sas_queue_thread, sas_ha, 0);
768 wait_for_completion(&queue_th_comp);
770 return res < 0 ? res : 0;
773 void sas_shutdown_queue(struct sas_ha_struct *sas_ha)
776 struct scsi_core *core = &sas_ha->core;
777 struct sas_task *task, *n;
779 init_completion(&queue_th_comp);
780 core->queue_thread_kill = 1;
781 up(&core->queue_thread_sema);
782 wait_for_completion(&queue_th_comp);
784 if (!list_empty(&core->task_queue))
785 SAS_DPRINTK("HA: %llx: scsi core task queue is NOT empty!?\n",
786 SAS_ADDR(sas_ha->sas_addr));
788 spin_lock_irqsave(&core->task_queue_lock, flags);
789 list_for_each_entry_safe(task, n, &core->task_queue, list) {
790 struct scsi_cmnd *cmd = task->uldd_task;
792 list_del_init(&task->list);
794 ASSIGN_SAS_TASK(cmd, NULL);
796 cmd->result = DID_ABORT << 16;
799 spin_unlock_irqrestore(&core->task_queue_lock, flags);
802 static int do_sas_task_abort(struct sas_task *task)
804 struct scsi_cmnd *sc = task->uldd_task;
805 struct sas_internal *si =
806 to_sas_internal(task->dev->port->ha->core.shost->transportt);
810 spin_lock_irqsave(&task->task_state_lock, flags);
811 if (task->task_state_flags & SAS_TASK_STATE_ABORTED) {
812 spin_unlock_irqrestore(&task->task_state_lock, flags);
813 SAS_DPRINTK("%s: Task %p already aborted.\n", __FUNCTION__,
818 task->task_state_flags |= SAS_TASK_INITIATOR_ABORTED;
819 if (!(task->task_state_flags & SAS_TASK_STATE_DONE))
820 task->task_state_flags |= SAS_TASK_STATE_ABORTED;
821 spin_unlock_irqrestore(&task->task_state_lock, flags);
823 if (!si->dft->lldd_abort_task)
826 res = si->dft->lldd_abort_task(task);
827 if ((task->task_state_flags & SAS_TASK_STATE_DONE) ||
828 (res == TMF_RESP_FUNC_COMPLETE))
830 /* SMP commands don't have scsi_cmds(?) */
832 task->task_done(task);
835 scsi_req_abort_cmd(sc);
836 scsi_schedule_eh(sc->device->host);
840 spin_lock_irqsave(&task->task_state_lock, flags);
841 task->task_state_flags &= ~SAS_TASK_INITIATOR_ABORTED;
842 if (!(task->task_state_flags & SAS_TASK_STATE_DONE))
843 task->task_state_flags &= ~SAS_TASK_STATE_ABORTED;
844 spin_unlock_irqrestore(&task->task_state_lock, flags);
849 void sas_task_abort(struct sas_task *task)
853 for (i = 0; i < 5; i++)
854 if (!do_sas_task_abort(task))
857 SAS_DPRINTK("%s: Could not kill task!\n", __FUNCTION__);
860 EXPORT_SYMBOL_GPL(sas_queuecommand);
861 EXPORT_SYMBOL_GPL(sas_target_alloc);
862 EXPORT_SYMBOL_GPL(sas_slave_configure);
863 EXPORT_SYMBOL_GPL(sas_slave_destroy);
864 EXPORT_SYMBOL_GPL(sas_change_queue_depth);
865 EXPORT_SYMBOL_GPL(sas_change_queue_type);
866 EXPORT_SYMBOL_GPL(sas_bios_param);
867 EXPORT_SYMBOL_GPL(sas_task_abort);