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 <linux/kthread.h>
28 #include "sas_internal.h"
30 #include <scsi/scsi_host.h>
31 #include <scsi/scsi_device.h>
32 #include <scsi/scsi_tcq.h>
33 #include <scsi/scsi.h>
34 #include <scsi/scsi_eh.h>
35 #include <scsi/scsi_transport.h>
36 #include <scsi/scsi_transport_sas.h>
37 #include <scsi/sas_ata.h>
38 #include "../scsi_sas_internal.h"
39 #include "../scsi_transport_api.h"
40 #include "../scsi_priv.h"
42 #include <linux/err.h>
43 #include <linux/blkdev.h>
44 #include <linux/freezer.h>
45 #include <linux/scatterlist.h>
46 #include <linux/libata.h>
48 /* ---------- SCSI Host glue ---------- */
50 static void sas_scsi_task_done(struct sas_task
*task
)
52 struct task_status_struct
*ts
= &task
->task_status
;
53 struct scsi_cmnd
*sc
= task
->uldd_task
;
54 <<<<<<< HEAD
:drivers
/scsi
/libsas
/sas_scsi_host
.c
55 struct sas_ha_struct
*sas_ha
= SHOST_TO_SAS_HA(sc
->device
->host
);
56 unsigned ts_flags
= task
->task_state_flags
;
58 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/scsi
/libsas
/sas_scsi_host
.c
61 <<<<<<< HEAD
:drivers
/scsi
/libsas
/sas_scsi_host
.c
63 if (unlikely(task
->task_state_flags
& SAS_TASK_STATE_ABORTED
)) {
64 /* Aborted tasks will be completed by the error handler */
65 SAS_DPRINTK("task done but aborted\n");
69 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/scsi
/libsas
/sas_scsi_host
.c
71 SAS_DPRINTK("task_done called with non existing SCSI cmnd!\n");
72 list_del_init(&task
->list
);
77 if (ts
->resp
== SAS_TASK_UNDELIVERED
) {
80 } else { /* ts->resp == SAS_TASK_COMPLETE */
81 /* task delivered, what happened afterwards? */
83 case SAS_DEV_NO_RESPONSE
:
90 case SAS_DATA_UNDERRUN
:
91 scsi_set_resid(sc
, ts
->residual
);
92 if (scsi_bufflen(sc
) - scsi_get_resid(sc
) < sc
->underflow
)
95 case SAS_DATA_OVERRUN
:
99 hs
= DID_SOFT_ERROR
; /* retry */
101 case SAS_DEVICE_UNKNOWN
:
107 case SAS_OPEN_REJECT
:
108 if (ts
->open_rej_reason
== SAS_OREJ_RSVD_RETRY
)
109 hs
= DID_SOFT_ERROR
; /* retry */
113 case SAS_PROTO_RESPONSE
:
114 SAS_DPRINTK("LLDD:%s sent SAS_PROTO_RESP for an SSP "
115 "task; please report this\n",
116 task
->dev
->port
->ha
->sas_ha_name
);
118 case SAS_ABORTED_TASK
:
122 memcpy(sc
->sense_buffer
, ts
->buf
,
123 min(SCSI_SENSE_BUFFERSIZE
, ts
->buf_valid_size
));
124 stat
= SAM_CHECK_COND
;
131 ASSIGN_SAS_TASK(sc
, NULL
);
132 sc
->result
= (hs
<< 16) | stat
;
133 list_del_init(&task
->list
);
135 <<<<<<< HEAD
:drivers
/scsi
/libsas
/sas_scsi_host
.c
136 /* This is very ugly but this is how SCSI Core works. */
137 if (ts_flags
& SAS_TASK_STATE_ABORTED
)
138 scsi_eh_finish_cmd(sc
, &sas_ha
->eh_done_q
);
143 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/scsi
/libsas
/sas_scsi_host
.c
146 static enum task_attribute
sas_scsi_get_task_attr(struct scsi_cmnd
*cmd
)
148 enum task_attribute ta
= TASK_ATTR_SIMPLE
;
149 if (cmd
->request
&& blk_rq_tagged(cmd
->request
)) {
150 if (cmd
->device
->ordered_tags
&&
151 (cmd
->request
->cmd_flags
& REQ_HARDBARRIER
))
152 ta
= TASK_ATTR_ORDERED
;
157 static struct sas_task
*sas_create_task(struct scsi_cmnd
*cmd
,
158 struct domain_device
*dev
,
161 struct sas_task
*task
= sas_alloc_task(gfp_flags
);
167 task
->uldd_task
= cmd
;
168 ASSIGN_SAS_TASK(cmd
, task
);
171 task
->task_proto
= task
->dev
->tproto
; /* BUG_ON(!SSP) */
173 task
->ssp_task
.retry_count
= 1;
174 int_to_scsilun(cmd
->device
->lun
, &lun
);
175 memcpy(task
->ssp_task
.LUN
, &lun
.scsi_lun
, 8);
176 task
->ssp_task
.task_attr
= sas_scsi_get_task_attr(cmd
);
177 memcpy(task
->ssp_task
.cdb
, cmd
->cmnd
, 16);
179 task
->scatter
= scsi_sglist(cmd
);
180 task
->num_scatter
= scsi_sg_count(cmd
);
181 task
->total_xfer_len
= scsi_bufflen(cmd
);
182 task
->data_dir
= cmd
->sc_data_direction
;
184 task
->task_done
= sas_scsi_task_done
;
189 int sas_queue_up(struct sas_task
*task
)
191 struct sas_ha_struct
*sas_ha
= task
->dev
->port
->ha
;
192 struct scsi_core
*core
= &sas_ha
->core
;
196 spin_lock_irqsave(&core
->task_queue_lock
, flags
);
197 if (sas_ha
->lldd_queue_size
< core
->task_queue_size
+ 1) {
198 spin_unlock_irqrestore(&core
->task_queue_lock
, flags
);
199 return -SAS_QUEUE_FULL
;
201 list_add_tail(&task
->list
, &core
->task_queue
);
202 core
->task_queue_size
+= 1;
203 spin_unlock_irqrestore(&core
->task_queue_lock
, flags
);
204 wake_up_process(core
->queue_thread
);
210 * sas_queuecommand -- Enqueue a command for processing
211 * @parameters: See SCSI Core documentation
213 * Note: XXX: Remove the host unlock/lock pair when SCSI Core can
214 * call us without holding an IRQ spinlock...
216 int sas_queuecommand(struct scsi_cmnd
*cmd
,
217 void (*scsi_done
)(struct scsi_cmnd
*))
218 __releases(host
->host_lock
)
219 __acquires(dev
->sata_dev
.ap
->lock
)
220 __releases(dev
->sata_dev
.ap
->lock
)
221 __acquires(host
->host_lock
)
224 struct domain_device
*dev
= cmd_to_domain_dev(cmd
);
225 struct Scsi_Host
*host
= cmd
->device
->host
;
226 struct sas_internal
*i
= to_sas_internal(host
->transportt
);
228 spin_unlock_irq(host
->host_lock
);
231 struct sas_ha_struct
*sas_ha
= dev
->port
->ha
;
232 struct sas_task
*task
;
234 if (dev_is_sata(dev
)) {
237 spin_lock_irqsave(dev
->sata_dev
.ap
->lock
, flags
);
238 res
= ata_sas_queuecmd(cmd
, scsi_done
,
240 spin_unlock_irqrestore(dev
->sata_dev
.ap
->lock
, flags
);
245 task
= sas_create_task(cmd
, dev
, GFP_ATOMIC
);
249 cmd
->scsi_done
= scsi_done
;
250 /* Queue up, Direct Mode or Task Collector Mode. */
251 if (sas_ha
->lldd_max_execute_num
< 2)
252 res
= i
->dft
->lldd_execute_task(task
, 1, GFP_ATOMIC
);
254 res
= sas_queue_up(task
);
258 SAS_DPRINTK("lldd_execute_task returned: %d\n", res
);
259 ASSIGN_SAS_TASK(cmd
, NULL
);
261 if (res
== -SAS_QUEUE_FULL
) {
262 cmd
->result
= DID_SOFT_ERROR
<< 16; /* retry */
270 spin_lock_irq(host
->host_lock
);
274 <<<<<<< HEAD
:drivers
/scsi
/libsas
/sas_scsi_host
.c
276 static void sas_eh_finish_cmd(struct scsi_cmnd
*cmd
)
278 struct sas_task
*task
= TO_SAS_TASK(cmd
);
279 struct sas_ha_struct
*sas_ha
= SHOST_TO_SAS_HA(cmd
->device
->host
);
281 /* remove the aborted task flag to allow the task to be
282 * completed now. At this point, we only get called following
283 * an actual abort of the task, so we should be guaranteed not
284 * to be racing with any completions from the LLD (hence we
285 * don't need the task state lock to clear the flag) */
286 task
->task_state_flags
&= ~SAS_TASK_STATE_ABORTED
;
287 /* Now call task_done. However, task will be free'd after
289 task
->task_done(task
);
290 /* now finish the command and move it on to the error
291 * handler done list, this also takes it off the
292 * error handler pending list */
293 scsi_eh_finish_cmd(cmd
, &sas_ha
->eh_done_q
);
296 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/scsi
/libsas
/sas_scsi_host
.c
297 static void sas_scsi_clear_queue_lu(struct list_head
*error_q
, struct scsi_cmnd
*my_cmd
)
299 struct scsi_cmnd
*cmd
, *n
;
301 list_for_each_entry_safe(cmd
, n
, error_q
, eh_entry
) {
302 <<<<<<< HEAD
:drivers
/scsi
/libsas
/sas_scsi_host
.c
304 list_del_init(&cmd
->eh_entry
);
306 if (cmd
->device
->sdev_target
== my_cmd
->device
->sdev_target
&&
307 cmd
->device
->lun
== my_cmd
->device
->lun
)
308 sas_eh_finish_cmd(cmd
);
309 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/scsi
/libsas
/sas_scsi_host
.c
313 static void sas_scsi_clear_queue_I_T(struct list_head
*error_q
,
314 struct domain_device
*dev
)
316 struct scsi_cmnd
*cmd
, *n
;
318 list_for_each_entry_safe(cmd
, n
, error_q
, eh_entry
) {
319 struct domain_device
*x
= cmd_to_domain_dev(cmd
);
322 <<<<<<< HEAD
:drivers
/scsi
/libsas
/sas_scsi_host
.c
323 list_del_init(&cmd
->eh_entry
);
325 sas_eh_finish_cmd(cmd
);
326 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/scsi
/libsas
/sas_scsi_host
.c
330 static void sas_scsi_clear_queue_port(struct list_head
*error_q
,
331 struct asd_sas_port
*port
)
333 struct scsi_cmnd
*cmd
, *n
;
335 list_for_each_entry_safe(cmd
, n
, error_q
, eh_entry
) {
336 struct domain_device
*dev
= cmd_to_domain_dev(cmd
);
337 struct asd_sas_port
*x
= dev
->port
;
340 <<<<<<< HEAD
:drivers
/scsi
/libsas
/sas_scsi_host
.c
341 list_del_init(&cmd
->eh_entry
);
343 sas_eh_finish_cmd(cmd
);
344 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/scsi
/libsas
/sas_scsi_host
.c
348 enum task_disposition
{
356 static enum task_disposition
sas_scsi_find_task(struct sas_task
*task
)
358 struct sas_ha_struct
*ha
= task
->dev
->port
->ha
;
361 struct sas_internal
*si
=
362 to_sas_internal(task
->dev
->port
->ha
->core
.shost
->transportt
);
364 if (ha
->lldd_max_execute_num
> 1) {
365 struct scsi_core
*core
= &ha
->core
;
366 struct sas_task
*t
, *n
;
368 spin_lock_irqsave(&core
->task_queue_lock
, flags
);
369 list_for_each_entry_safe(t
, n
, &core
->task_queue
, list
) {
371 list_del_init(&t
->list
);
372 spin_unlock_irqrestore(&core
->task_queue_lock
,
374 SAS_DPRINTK("%s: task 0x%p aborted from "
377 return TASK_IS_ABORTED
;
380 spin_unlock_irqrestore(&core
->task_queue_lock
, flags
);
383 for (i
= 0; i
< 5; i
++) {
384 SAS_DPRINTK("%s: aborting task 0x%p\n", __FUNCTION__
, task
);
385 res
= si
->dft
->lldd_abort_task(task
);
387 spin_lock_irqsave(&task
->task_state_lock
, flags
);
388 if (task
->task_state_flags
& SAS_TASK_STATE_DONE
) {
389 spin_unlock_irqrestore(&task
->task_state_lock
, flags
);
390 SAS_DPRINTK("%s: task 0x%p is done\n", __FUNCTION__
,
394 spin_unlock_irqrestore(&task
->task_state_lock
, flags
);
396 if (res
== TMF_RESP_FUNC_COMPLETE
) {
397 SAS_DPRINTK("%s: task 0x%p is aborted\n",
399 return TASK_IS_ABORTED
;
400 } else if (si
->dft
->lldd_query_task
) {
401 SAS_DPRINTK("%s: querying task 0x%p\n",
403 res
= si
->dft
->lldd_query_task(task
);
405 case TMF_RESP_FUNC_SUCC
:
406 SAS_DPRINTK("%s: task 0x%p at LU\n",
408 return TASK_IS_AT_LU
;
409 case TMF_RESP_FUNC_COMPLETE
:
410 SAS_DPRINTK("%s: task 0x%p not at LU\n",
412 return TASK_IS_NOT_AT_LU
;
413 case TMF_RESP_FUNC_FAILED
:
414 SAS_DPRINTK("%s: task 0x%p failed to abort\n",
416 return TASK_ABORT_FAILED
;
424 static int sas_recover_lu(struct domain_device
*dev
, struct scsi_cmnd
*cmd
)
426 int res
= TMF_RESP_FUNC_FAILED
;
428 struct sas_internal
*i
=
429 to_sas_internal(dev
->port
->ha
->core
.shost
->transportt
);
431 int_to_scsilun(cmd
->device
->lun
, &lun
);
433 SAS_DPRINTK("eh: device %llx LUN %x has the task\n",
434 SAS_ADDR(dev
->sas_addr
),
437 if (i
->dft
->lldd_abort_task_set
)
438 res
= i
->dft
->lldd_abort_task_set(dev
, lun
.scsi_lun
);
440 if (res
== TMF_RESP_FUNC_FAILED
) {
441 if (i
->dft
->lldd_clear_task_set
)
442 res
= i
->dft
->lldd_clear_task_set(dev
, lun
.scsi_lun
);
445 if (res
== TMF_RESP_FUNC_FAILED
) {
446 if (i
->dft
->lldd_lu_reset
)
447 res
= i
->dft
->lldd_lu_reset(dev
, lun
.scsi_lun
);
453 static int sas_recover_I_T(struct domain_device
*dev
)
455 int res
= TMF_RESP_FUNC_FAILED
;
456 struct sas_internal
*i
=
457 to_sas_internal(dev
->port
->ha
->core
.shost
->transportt
);
459 SAS_DPRINTK("I_T nexus reset for dev %016llx\n",
460 SAS_ADDR(dev
->sas_addr
));
462 if (i
->dft
->lldd_I_T_nexus_reset
)
463 res
= i
->dft
->lldd_I_T_nexus_reset(dev
);
468 /* Find the sas_phy that's attached to this device */
469 <<<<<<< HEAD
:drivers
/scsi
/libsas
/sas_scsi_host
.c
470 static struct sas_phy
*find_local_sas_phy(struct domain_device
*dev
)
472 struct sas_phy
*sas_find_local_phy(struct domain_device
*dev
)
473 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/scsi
/libsas
/sas_scsi_host
.c
475 struct domain_device
*pdev
= dev
->parent
;
476 struct ex_phy
*exphy
= NULL
;
479 /* Directly attached device */
481 return dev
->port
->phy
;
483 /* Otherwise look in the expander */
484 for (i
= 0; i
< pdev
->ex_dev
.num_phys
; i
++)
485 if (!memcmp(dev
->sas_addr
,
486 pdev
->ex_dev
.ex_phy
[i
].attached_sas_addr
,
488 exphy
= &pdev
->ex_dev
.ex_phy
[i
];
495 <<<<<<< HEAD
:drivers
/scsi
/libsas
/sas_scsi_host
.c
497 EXPORT_SYMBOL_GPL(sas_find_local_phy
);
498 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/scsi
/libsas
/sas_scsi_host
.c
500 /* Attempt to send a LUN reset message to a device */
501 int sas_eh_device_reset_handler(struct scsi_cmnd
*cmd
)
503 struct domain_device
*dev
= cmd_to_domain_dev(cmd
);
504 struct sas_internal
*i
=
505 to_sas_internal(dev
->port
->ha
->core
.shost
->transportt
);
509 int_to_scsilun(cmd
->device
->lun
, &lun
);
511 if (!i
->dft
->lldd_lu_reset
)
514 res
= i
->dft
->lldd_lu_reset(dev
, lun
.scsi_lun
);
515 if (res
== TMF_RESP_FUNC_SUCC
|| res
== TMF_RESP_FUNC_COMPLETE
)
521 /* Attempt to send a phy (bus) reset */
522 int sas_eh_bus_reset_handler(struct scsi_cmnd
*cmd
)
524 struct domain_device
*dev
= cmd_to_domain_dev(cmd
);
525 <<<<<<< HEAD
:drivers
/scsi
/libsas
/sas_scsi_host
.c
526 struct sas_phy
*phy
= find_local_sas_phy(dev
);
528 struct sas_phy
*phy
= sas_find_local_phy(dev
);
529 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/scsi
/libsas
/sas_scsi_host
.c
532 res
= sas_phy_reset(phy
, 1);
534 SAS_DPRINTK("Bus reset of %s failed 0x%x\n",
535 kobject_name(&phy
->dev
.kobj
),
537 if (res
== TMF_RESP_FUNC_SUCC
|| res
== TMF_RESP_FUNC_COMPLETE
)
543 /* Try to reset a device */
544 <<<<<<< HEAD
:drivers
/scsi
/libsas
/sas_scsi_host
.c
545 static int try_to_reset_cmd_device(struct Scsi_Host
*shost
,
546 struct scsi_cmnd
*cmd
)
548 static int try_to_reset_cmd_device(struct scsi_cmnd
*cmd
)
549 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/scsi
/libsas
/sas_scsi_host
.c
552 <<<<<<< HEAD
:drivers
/scsi
/libsas
/sas_scsi_host
.c
554 struct Scsi_Host
*shost
= cmd
->device
->host
;
555 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/scsi
/libsas
/sas_scsi_host
.c
557 if (!shost
->hostt
->eh_device_reset_handler
)
560 res
= shost
->hostt
->eh_device_reset_handler(cmd
);
565 if (shost
->hostt
->eh_bus_reset_handler
)
566 return shost
->hostt
->eh_bus_reset_handler(cmd
);
571 static int sas_eh_handle_sas_errors(struct Scsi_Host
*shost
,
572 struct list_head
*work_q
,
573 struct list_head
*done_q
)
575 struct scsi_cmnd
*cmd
, *n
;
576 enum task_disposition res
= TASK_IS_DONE
;
577 int tmf_resp
, need_reset
;
578 struct sas_internal
*i
= to_sas_internal(shost
->transportt
);
580 struct sas_ha_struct
*ha
= SHOST_TO_SAS_HA(shost
);
583 list_for_each_entry_safe(cmd
, n
, work_q
, eh_entry
) {
584 struct sas_task
*task
= TO_SAS_TASK(cmd
);
589 list_del_init(&cmd
->eh_entry
);
591 spin_lock_irqsave(&task
->task_state_lock
, flags
);
592 need_reset
= task
->task_state_flags
& SAS_TASK_NEED_DEV_RESET
;
593 spin_unlock_irqrestore(&task
->task_state_lock
, flags
);
595 <<<<<<< HEAD
:drivers
/scsi
/libsas
/sas_scsi_host
.c
598 SAS_DPRINTK("%s: task 0x%p requests reset\n",
603 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/scsi
/libsas
/sas_scsi_host
.c
604 SAS_DPRINTK("trying to find task 0x%p\n", task
);
605 res
= sas_scsi_find_task(task
);
611 SAS_DPRINTK("%s: task 0x%p is done\n", __FUNCTION__
,
613 <<<<<<< HEAD
:drivers
/scsi
/libsas
/sas_scsi_host
.c
614 task
->task_done(task
);
616 try_to_reset_cmd_device(shost
, cmd
);
618 sas_eh_finish_cmd(cmd
);
619 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/scsi
/libsas
/sas_scsi_host
.c
621 case TASK_IS_ABORTED
:
622 SAS_DPRINTK("%s: task 0x%p is aborted\n",
624 <<<<<<< HEAD
:drivers
/scsi
/libsas
/sas_scsi_host
.c
625 task
->task_done(task
);
627 try_to_reset_cmd_device(shost
, cmd
);
629 sas_eh_finish_cmd(cmd
);
630 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/scsi
/libsas
/sas_scsi_host
.c
633 SAS_DPRINTK("task 0x%p is at LU: lu recover\n", task
);
634 <<<<<<< HEAD
:drivers
/scsi
/libsas
/sas_scsi_host
.c
637 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/scsi
/libsas
/sas_scsi_host
.c
638 tmf_resp
= sas_recover_lu(task
->dev
, cmd
);
639 if (tmf_resp
== TMF_RESP_FUNC_COMPLETE
) {
640 SAS_DPRINTK("dev %016llx LU %x is "
644 <<<<<<< HEAD
:drivers
/scsi
/libsas
/sas_scsi_host
.c
645 task
->task_done(task
);
647 try_to_reset_cmd_device(shost
, cmd
);
649 sas_eh_finish_cmd(cmd
);
650 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/scsi
/libsas
/sas_scsi_host
.c
651 sas_scsi_clear_queue_lu(work_q
, cmd
);
655 case TASK_IS_NOT_AT_LU
:
656 case TASK_ABORT_FAILED
:
657 SAS_DPRINTK("task 0x%p is not at LU: I_T recover\n",
659 tmf_resp
= sas_recover_I_T(task
->dev
);
660 if (tmf_resp
== TMF_RESP_FUNC_COMPLETE
) {
661 <<<<<<< HEAD
:drivers
/scsi
/libsas
/sas_scsi_host
.c
663 struct domain_device
*dev
= task
->dev
;
664 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/scsi
/libsas
/sas_scsi_host
.c
665 SAS_DPRINTK("I_T %016llx recovered\n",
666 SAS_ADDR(task
->dev
->sas_addr
));
667 <<<<<<< HEAD
:drivers
/scsi
/libsas
/sas_scsi_host
.c
668 task
->task_done(task
);
670 try_to_reset_cmd_device(shost
, cmd
);
671 sas_scsi_clear_queue_I_T(work_q
, task
->dev
);
673 sas_eh_finish_cmd(cmd
);
674 sas_scsi_clear_queue_I_T(work_q
, dev
);
675 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/scsi
/libsas
/sas_scsi_host
.c
678 /* Hammer time :-) */
679 <<<<<<< HEAD
:drivers
/scsi
/libsas
/sas_scsi_host
.c
681 try_to_reset_cmd_device(cmd
);
682 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/scsi
/libsas
/sas_scsi_host
.c
683 if (i
->dft
->lldd_clear_nexus_port
) {
684 struct asd_sas_port
*port
= task
->dev
->port
;
685 SAS_DPRINTK("clearing nexus for port:%d\n",
687 res
= i
->dft
->lldd_clear_nexus_port(port
);
688 if (res
== TMF_RESP_FUNC_COMPLETE
) {
689 SAS_DPRINTK("clear nexus port:%d "
690 "succeeded\n", port
->id
);
691 <<<<<<< HEAD
:drivers
/scsi
/libsas
/sas_scsi_host
.c
692 task
->task_done(task
);
694 try_to_reset_cmd_device(shost
, cmd
);
696 sas_eh_finish_cmd(cmd
);
697 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/scsi
/libsas
/sas_scsi_host
.c
698 sas_scsi_clear_queue_port(work_q
,
703 if (i
->dft
->lldd_clear_nexus_ha
) {
704 SAS_DPRINTK("clear nexus ha\n");
705 res
= i
->dft
->lldd_clear_nexus_ha(ha
);
706 if (res
== TMF_RESP_FUNC_COMPLETE
) {
707 SAS_DPRINTK("clear nexus ha "
709 <<<<<<< HEAD
:drivers
/scsi
/libsas
/sas_scsi_host
.c
710 task
->task_done(task
);
712 try_to_reset_cmd_device(shost
, cmd
);
715 sas_eh_finish_cmd(cmd
);
717 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/scsi
/libsas
/sas_scsi_host
.c
720 /* If we are here -- this means that no amount
721 * of effort could recover from errors. Quite
722 * possibly the HA just disappeared.
724 SAS_DPRINTK("error from device %llx, LUN %x "
725 "couldn't be recovered in any way\n",
726 SAS_ADDR(task
->dev
->sas_addr
),
729 <<<<<<< HEAD
:drivers
/scsi
/libsas
/sas_scsi_host
.c
730 task
->task_done(task
);
732 try_to_reset_cmd_device(shost
, cmd
);
734 sas_eh_finish_cmd(cmd
);
735 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/scsi
/libsas
/sas_scsi_host
.c
739 <<<<<<< HEAD
:drivers
/scsi
/libsas
/sas_scsi_host
.c
742 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/scsi
/libsas
/sas_scsi_host
.c
743 return list_empty(work_q
);
745 SAS_DPRINTK("--- Exit %s -- clear_q\n", __FUNCTION__
);
746 <<<<<<< HEAD
:drivers
/scsi
/libsas
/sas_scsi_host
.c
747 list_for_each_entry_safe(cmd
, n
, work_q
, eh_entry
) {
748 struct sas_task
*task
= TO_SAS_TASK(cmd
);
749 list_del_init(&cmd
->eh_entry
);
750 task
->task_done(task
);
753 list_for_each_entry_safe(cmd
, n
, work_q
, eh_entry
)
754 sas_eh_finish_cmd(cmd
);
756 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/scsi
/libsas
/sas_scsi_host
.c
757 return list_empty(work_q
);
760 void sas_scsi_recover_host(struct Scsi_Host
*shost
)
762 struct sas_ha_struct
*ha
= SHOST_TO_SAS_HA(shost
);
764 LIST_HEAD(eh_work_q
);
766 spin_lock_irqsave(shost
->host_lock
, flags
);
767 list_splice_init(&shost
->eh_cmd_q
, &eh_work_q
);
768 spin_unlock_irqrestore(shost
->host_lock
, flags
);
770 SAS_DPRINTK("Enter %s\n", __FUNCTION__
);
772 * Deal with commands that still have SAS tasks (i.e. they didn't
773 * complete via the normal sas_task completion mechanism)
775 if (sas_eh_handle_sas_errors(shost
, &eh_work_q
, &ha
->eh_done_q
))
779 * Now deal with SCSI commands that completed ok but have a an error
780 * code (and hopefully sense data) attached. This is roughly what
781 * scsi_unjam_host does, but we skip scsi_eh_abort_cmds because any
782 * command we see here has no sas_task and is thus unknown to the HA.
784 if (!scsi_eh_get_sense(&eh_work_q
, &ha
->eh_done_q
))
785 scsi_eh_ready_devs(shost
, &eh_work_q
, &ha
->eh_done_q
);
788 scsi_eh_flush_done_q(&ha
->eh_done_q
);
789 SAS_DPRINTK("--- Exit %s\n", __FUNCTION__
);
793 enum scsi_eh_timer_return
sas_scsi_timed_out(struct scsi_cmnd
*cmd
)
795 struct sas_task
*task
= TO_SAS_TASK(cmd
);
799 cmd
->timeout_per_command
/= 2;
800 SAS_DPRINTK("command 0x%p, task 0x%p, gone: %s\n",
801 cmd
, task
, (cmd
->timeout_per_command
?
802 "EH_RESET_TIMER" : "EH_NOT_HANDLED"));
803 if (!cmd
->timeout_per_command
)
804 return EH_NOT_HANDLED
;
805 return EH_RESET_TIMER
;
808 spin_lock_irqsave(&task
->task_state_lock
, flags
);
809 BUG_ON(task
->task_state_flags
& SAS_TASK_STATE_ABORTED
);
810 if (task
->task_state_flags
& SAS_TASK_STATE_DONE
) {
811 spin_unlock_irqrestore(&task
->task_state_lock
, flags
);
812 SAS_DPRINTK("command 0x%p, task 0x%p, timed out: EH_HANDLED\n",
816 if (!(task
->task_state_flags
& SAS_TASK_AT_INITIATOR
)) {
817 spin_unlock_irqrestore(&task
->task_state_lock
, flags
);
818 SAS_DPRINTK("command 0x%p, task 0x%p, not at initiator: "
821 return EH_RESET_TIMER
;
823 task
->task_state_flags
|= SAS_TASK_STATE_ABORTED
;
824 spin_unlock_irqrestore(&task
->task_state_lock
, flags
);
826 SAS_DPRINTK("command 0x%p, task 0x%p, timed out: EH_NOT_HANDLED\n",
829 return EH_NOT_HANDLED
;
832 int sas_ioctl(struct scsi_device
*sdev
, int cmd
, void __user
*arg
)
834 struct domain_device
*dev
= sdev_to_domain_dev(sdev
);
836 if (dev_is_sata(dev
))
837 return ata_scsi_ioctl(sdev
, cmd
, arg
);
842 struct domain_device
*sas_find_dev_by_rphy(struct sas_rphy
*rphy
)
844 struct Scsi_Host
*shost
= dev_to_shost(rphy
->dev
.parent
);
845 struct sas_ha_struct
*ha
= SHOST_TO_SAS_HA(shost
);
846 struct domain_device
*found_dev
= NULL
;
850 spin_lock_irqsave(&ha
->phy_port_lock
, flags
);
851 for (i
= 0; i
< ha
->num_phys
; i
++) {
852 struct asd_sas_port
*port
= ha
->sas_port
[i
];
853 struct domain_device
*dev
;
855 spin_lock(&port
->dev_list_lock
);
856 list_for_each_entry(dev
, &port
->dev_list
, dev_list_node
) {
857 if (rphy
== dev
->rphy
) {
859 spin_unlock(&port
->dev_list_lock
);
863 spin_unlock(&port
->dev_list_lock
);
866 spin_unlock_irqrestore(&ha
->phy_port_lock
, flags
);
871 static inline struct domain_device
*sas_find_target(struct scsi_target
*starget
)
873 struct sas_rphy
*rphy
= dev_to_rphy(starget
->dev
.parent
);
875 return sas_find_dev_by_rphy(rphy
);
878 int sas_target_alloc(struct scsi_target
*starget
)
880 struct domain_device
*found_dev
= sas_find_target(starget
);
886 if (dev_is_sata(found_dev
)) {
887 res
= sas_ata_init_host_and_port(found_dev
, starget
);
892 starget
->hostdata
= found_dev
;
896 #define SAS_DEF_QD 32
897 #define SAS_MAX_QD 64
899 int sas_slave_configure(struct scsi_device
*scsi_dev
)
901 struct domain_device
*dev
= sdev_to_domain_dev(scsi_dev
);
902 struct sas_ha_struct
*sas_ha
;
904 BUG_ON(dev
->rphy
->identify
.device_type
!= SAS_END_DEVICE
);
906 if (dev_is_sata(dev
)) {
907 ata_sas_slave_configure(scsi_dev
, dev
->sata_dev
.ap
);
911 sas_ha
= dev
->port
->ha
;
913 sas_read_port_mode_page(scsi_dev
);
915 if (scsi_dev
->tagged_supported
) {
916 scsi_set_tag_type(scsi_dev
, MSG_SIMPLE_TAG
);
917 scsi_activate_tcq(scsi_dev
, SAS_DEF_QD
);
919 SAS_DPRINTK("device %llx, LUN %x doesn't support "
920 "TCQ\n", SAS_ADDR(dev
->sas_addr
),
922 scsi_dev
->tagged_supported
= 0;
923 scsi_set_tag_type(scsi_dev
, 0);
924 scsi_deactivate_tcq(scsi_dev
, 1);
927 scsi_dev
->allow_restart
= 1;
932 void sas_slave_destroy(struct scsi_device
*scsi_dev
)
934 struct domain_device
*dev
= sdev_to_domain_dev(scsi_dev
);
936 if (dev_is_sata(dev
))
937 ata_port_disable(dev
->sata_dev
.ap
);
940 int sas_change_queue_depth(struct scsi_device
*scsi_dev
, int new_depth
)
942 int res
= min(new_depth
, SAS_MAX_QD
);
944 if (scsi_dev
->tagged_supported
)
945 scsi_adjust_queue_depth(scsi_dev
, scsi_get_tag_type(scsi_dev
),
948 struct domain_device
*dev
= sdev_to_domain_dev(scsi_dev
);
949 sas_printk("device %llx LUN %x queue depth changed to 1\n",
950 SAS_ADDR(dev
->sas_addr
),
952 scsi_adjust_queue_depth(scsi_dev
, 0, 1);
959 int sas_change_queue_type(struct scsi_device
*scsi_dev
, int qt
)
961 if (!scsi_dev
->tagged_supported
)
964 scsi_deactivate_tcq(scsi_dev
, 1);
966 scsi_set_tag_type(scsi_dev
, qt
);
967 scsi_activate_tcq(scsi_dev
, scsi_dev
->queue_depth
);
972 int sas_bios_param(struct scsi_device
*scsi_dev
,
973 struct block_device
*bdev
,
974 sector_t capacity
, int *hsc
)
978 sector_div(capacity
, 255*63);
984 /* ---------- Task Collector Thread implementation ---------- */
986 static void sas_queue(struct sas_ha_struct
*sas_ha
)
988 struct scsi_core
*core
= &sas_ha
->core
;
993 struct sas_internal
*i
= to_sas_internal(core
->shost
->transportt
);
995 spin_lock_irqsave(&core
->task_queue_lock
, flags
);
996 while (!kthread_should_stop() &&
997 !list_empty(&core
->task_queue
)) {
999 can_queue
= sas_ha
->lldd_queue_size
- core
->task_queue_size
;
1000 if (can_queue
>= 0) {
1001 can_queue
= core
->task_queue_size
;
1002 list_splice_init(&core
->task_queue
, &q
);
1004 struct list_head
*a
, *n
;
1006 can_queue
= sas_ha
->lldd_queue_size
;
1007 list_for_each_safe(a
, n
, &core
->task_queue
) {
1008 list_move_tail(a
, &q
);
1009 if (--can_queue
== 0)
1012 can_queue
= sas_ha
->lldd_queue_size
;
1014 core
->task_queue_size
-= can_queue
;
1015 spin_unlock_irqrestore(&core
->task_queue_lock
, flags
);
1017 struct sas_task
*task
= list_entry(q
.next
,
1021 res
= i
->dft
->lldd_execute_task(task
, can_queue
,
1024 __list_add(&q
, task
->list
.prev
, &task
->list
);
1026 spin_lock_irqsave(&core
->task_queue_lock
, flags
);
1028 list_splice_init(&q
, &core
->task_queue
); /*at head*/
1029 core
->task_queue_size
+= can_queue
;
1032 spin_unlock_irqrestore(&core
->task_queue_lock
, flags
);
1036 * sas_queue_thread -- The Task Collector thread
1037 * @_sas_ha: pointer to struct sas_ha
1039 static int sas_queue_thread(void *_sas_ha
)
1041 struct sas_ha_struct
*sas_ha
= _sas_ha
;
1044 set_current_state(TASK_INTERRUPTIBLE
);
1047 if (kthread_should_stop())
1054 int sas_init_queue(struct sas_ha_struct
*sas_ha
)
1056 struct scsi_core
*core
= &sas_ha
->core
;
1058 spin_lock_init(&core
->task_queue_lock
);
1059 core
->task_queue_size
= 0;
1060 INIT_LIST_HEAD(&core
->task_queue
);
1062 core
->queue_thread
= kthread_run(sas_queue_thread
, sas_ha
,
1063 "sas_queue_%d", core
->shost
->host_no
);
1064 if (IS_ERR(core
->queue_thread
))
1065 return PTR_ERR(core
->queue_thread
);
1069 void sas_shutdown_queue(struct sas_ha_struct
*sas_ha
)
1071 unsigned long flags
;
1072 struct scsi_core
*core
= &sas_ha
->core
;
1073 struct sas_task
*task
, *n
;
1075 kthread_stop(core
->queue_thread
);
1077 if (!list_empty(&core
->task_queue
))
1078 SAS_DPRINTK("HA: %llx: scsi core task queue is NOT empty!?\n",
1079 SAS_ADDR(sas_ha
->sas_addr
));
1081 spin_lock_irqsave(&core
->task_queue_lock
, flags
);
1082 list_for_each_entry_safe(task
, n
, &core
->task_queue
, list
) {
1083 struct scsi_cmnd
*cmd
= task
->uldd_task
;
1085 list_del_init(&task
->list
);
1087 ASSIGN_SAS_TASK(cmd
, NULL
);
1088 sas_free_task(task
);
1089 cmd
->result
= DID_ABORT
<< 16;
1090 cmd
->scsi_done(cmd
);
1092 spin_unlock_irqrestore(&core
->task_queue_lock
, flags
);
1096 * Call the LLDD task abort routine directly. This function is intended for
1097 * use by upper layers that need to tell the LLDD to abort a task.
1099 int __sas_task_abort(struct sas_task
*task
)
1101 struct sas_internal
*si
=
1102 to_sas_internal(task
->dev
->port
->ha
->core
.shost
->transportt
);
1103 unsigned long flags
;
1106 spin_lock_irqsave(&task
->task_state_lock
, flags
);
1107 if (task
->task_state_flags
& SAS_TASK_STATE_ABORTED
||
1108 task
->task_state_flags
& SAS_TASK_STATE_DONE
) {
1109 spin_unlock_irqrestore(&task
->task_state_lock
, flags
);
1110 SAS_DPRINTK("%s: Task %p already finished.\n", __FUNCTION__
,
1114 task
->task_state_flags
|= SAS_TASK_STATE_ABORTED
;
1115 spin_unlock_irqrestore(&task
->task_state_lock
, flags
);
1117 if (!si
->dft
->lldd_abort_task
)
1120 res
= si
->dft
->lldd_abort_task(task
);
1122 spin_lock_irqsave(&task
->task_state_lock
, flags
);
1123 if ((task
->task_state_flags
& SAS_TASK_STATE_DONE
) ||
1124 (res
== TMF_RESP_FUNC_COMPLETE
))
1126 spin_unlock_irqrestore(&task
->task_state_lock
, flags
);
1127 task
->task_done(task
);
1131 if (!(task
->task_state_flags
& SAS_TASK_STATE_DONE
))
1132 task
->task_state_flags
&= ~SAS_TASK_STATE_ABORTED
;
1133 spin_unlock_irqrestore(&task
->task_state_lock
, flags
);
1139 * Tell an upper layer that it needs to initiate an abort for a given task.
1140 * This should only ever be called by an LLDD.
1142 void sas_task_abort(struct sas_task
*task
)
1144 struct scsi_cmnd
*sc
= task
->uldd_task
;
1146 /* Escape for libsas internal commands */
1148 if (!del_timer(&task
->timer
))
1150 task
->timer
.function(task
->timer
.data
);
1154 if (dev_is_sata(task
->dev
)) {
1155 sas_ata_task_abort(task
);
1159 scsi_req_abort_cmd(sc
);
1160 scsi_schedule_eh(sc
->device
->host
);
1163 int sas_slave_alloc(struct scsi_device
*scsi_dev
)
1165 struct domain_device
*dev
= sdev_to_domain_dev(scsi_dev
);
1167 if (dev_is_sata(dev
))
1168 return ata_sas_port_init(dev
->sata_dev
.ap
);
1173 void sas_target_destroy(struct scsi_target
*starget
)
1175 struct domain_device
*found_dev
= sas_find_target(starget
);
1180 if (dev_is_sata(found_dev
))
1181 ata_sas_port_destroy(found_dev
->sata_dev
.ap
);
1186 EXPORT_SYMBOL_GPL(sas_queuecommand
);
1187 EXPORT_SYMBOL_GPL(sas_target_alloc
);
1188 EXPORT_SYMBOL_GPL(sas_slave_configure
);
1189 EXPORT_SYMBOL_GPL(sas_slave_destroy
);
1190 EXPORT_SYMBOL_GPL(sas_change_queue_depth
);
1191 EXPORT_SYMBOL_GPL(sas_change_queue_type
);
1192 EXPORT_SYMBOL_GPL(sas_bios_param
);
1193 EXPORT_SYMBOL_GPL(__sas_task_abort
);
1194 EXPORT_SYMBOL_GPL(sas_task_abort
);
1195 EXPORT_SYMBOL_GPL(sas_phy_reset
);
1196 EXPORT_SYMBOL_GPL(sas_phy_enable
);
1197 EXPORT_SYMBOL_GPL(sas_eh_device_reset_handler
);
1198 EXPORT_SYMBOL_GPL(sas_eh_bus_reset_handler
);
1199 EXPORT_SYMBOL_GPL(sas_slave_alloc
);
1200 EXPORT_SYMBOL_GPL(sas_target_destroy
);
1201 EXPORT_SYMBOL_GPL(sas_ioctl
);