blob: 828fed1114ee823b4d26987eee1a64f0ad4a82d3 [file] [log] [blame]
James Bottomley2908d772006-08-29 09:22:51 -05001/*
2 * Serial Attached SCSI (SAS) class SCSI Host glue.
3 *
4 * Copyright (C) 2005 Adaptec, Inc. All rights reserved.
5 * Copyright (C) 2005 Luben Tuikov <luben_tuikov@adaptec.com>
6 *
7 * This file is licensed under GPLv2.
8 *
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.
13 *
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.
18 *
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
22 * USA
23 *
24 */
25
Christoph Hellwigd7a54e32007-04-26 09:38:01 -040026#include <linux/kthread.h>
27
James Bottomley2908d772006-08-29 09:22:51 -050028#include "sas_internal.h"
29
30#include <scsi/scsi_host.h>
31#include <scsi/scsi_device.h>
32#include <scsi/scsi_tcq.h>
33#include <scsi/scsi.h>
Darrick J. Wongf4563932006-10-30 15:18:39 -080034#include <scsi/scsi_eh.h>
James Bottomley2908d772006-08-29 09:22:51 -050035#include <scsi/scsi_transport.h>
36#include <scsi/scsi_transport_sas.h>
Darrick J. Wong338ec572006-10-18 14:43:37 -070037#include <scsi/sas_ata.h>
James Bottomley2908d772006-08-29 09:22:51 -050038#include "../scsi_sas_internal.h"
Darrick J. Wong79a5eb62006-10-30 15:18:50 -080039#include "../scsi_transport_api.h"
Darrick J. Wongad689232007-01-26 14:08:52 -080040#include "../scsi_priv.h"
James Bottomley2908d772006-08-29 09:22:51 -050041
42#include <linux/err.h>
43#include <linux/blkdev.h>
Rafael J. Wysocki83144182007-07-17 04:03:35 -070044#include <linux/freezer.h>
James Bottomley2908d772006-08-29 09:22:51 -050045#include <linux/scatterlist.h>
Darrick J. Wongfa1c1e82006-08-10 19:19:47 -070046#include <linux/libata.h>
James Bottomley2908d772006-08-29 09:22:51 -050047
48/* ---------- SCSI Host glue ---------- */
49
James Bottomley2908d772006-08-29 09:22:51 -050050static void sas_scsi_task_done(struct sas_task *task)
51{
52 struct task_status_struct *ts = &task->task_status;
53 struct scsi_cmnd *sc = task->uldd_task;
Darrick J. Wongf4563932006-10-30 15:18:39 -080054 struct sas_ha_struct *sas_ha = SHOST_TO_SAS_HA(sc->device->host);
James Bottomley2908d772006-08-29 09:22:51 -050055 unsigned ts_flags = task->task_state_flags;
56 int hs = 0, stat = 0;
57
58 if (unlikely(!sc)) {
59 SAS_DPRINTK("task_done called with non existing SCSI cmnd!\n");
60 list_del_init(&task->list);
61 sas_free_task(task);
62 return;
63 }
64
65 if (ts->resp == SAS_TASK_UNDELIVERED) {
66 /* transport error */
67 hs = DID_NO_CONNECT;
68 } else { /* ts->resp == SAS_TASK_COMPLETE */
69 /* task delivered, what happened afterwards? */
70 switch (ts->stat) {
71 case SAS_DEV_NO_RESPONSE:
72 case SAS_INTERRUPTED:
73 case SAS_PHY_DOWN:
74 case SAS_NAK_R_ERR:
75 case SAS_OPEN_TO:
76 hs = DID_NO_CONNECT;
77 break;
78 case SAS_DATA_UNDERRUN:
FUJITA Tomonoric13e5562007-05-26 02:46:37 +090079 scsi_set_resid(sc, ts->residual);
80 if (scsi_bufflen(sc) - scsi_get_resid(sc) < sc->underflow)
James Bottomley2908d772006-08-29 09:22:51 -050081 hs = DID_ERROR;
82 break;
83 case SAS_DATA_OVERRUN:
84 hs = DID_ERROR;
85 break;
86 case SAS_QUEUE_FULL:
87 hs = DID_SOFT_ERROR; /* retry */
88 break;
89 case SAS_DEVICE_UNKNOWN:
90 hs = DID_BAD_TARGET;
91 break;
92 case SAS_SG_ERR:
93 hs = DID_PARITY;
94 break;
95 case SAS_OPEN_REJECT:
96 if (ts->open_rej_reason == SAS_OREJ_RSVD_RETRY)
97 hs = DID_SOFT_ERROR; /* retry */
98 else
99 hs = DID_ERROR;
100 break;
101 case SAS_PROTO_RESPONSE:
102 SAS_DPRINTK("LLDD:%s sent SAS_PROTO_RESP for an SSP "
103 "task; please report this\n",
104 task->dev->port->ha->sas_ha_name);
105 break;
106 case SAS_ABORTED_TASK:
107 hs = DID_ABORT;
108 break;
109 case SAM_CHECK_COND:
110 memcpy(sc->sense_buffer, ts->buf,
FUJITA Tomonoricc75e8a2008-01-13 02:20:18 +0900111 min(SCSI_SENSE_BUFFERSIZE, ts->buf_valid_size));
James Bottomley2908d772006-08-29 09:22:51 -0500112 stat = SAM_CHECK_COND;
113 break;
114 default:
115 stat = ts->stat;
116 break;
117 }
118 }
119 ASSIGN_SAS_TASK(sc, NULL);
120 sc->result = (hs << 16) | stat;
121 list_del_init(&task->list);
122 sas_free_task(task);
123 /* This is very ugly but this is how SCSI Core works. */
124 if (ts_flags & SAS_TASK_STATE_ABORTED)
Darrick J. Wongf4563932006-10-30 15:18:39 -0800125 scsi_eh_finish_cmd(sc, &sas_ha->eh_done_q);
James Bottomley2908d772006-08-29 09:22:51 -0500126 else
127 sc->scsi_done(sc);
128}
129
130static enum task_attribute sas_scsi_get_task_attr(struct scsi_cmnd *cmd)
131{
132 enum task_attribute ta = TASK_ATTR_SIMPLE;
133 if (cmd->request && blk_rq_tagged(cmd->request)) {
134 if (cmd->device->ordered_tags &&
Jeff Garzik1bdfd552006-09-30 21:28:22 -0400135 (cmd->request->cmd_flags & REQ_HARDBARRIER))
FUJITA Tomonori63bb1bf2007-01-28 01:19:41 +0900136 ta = TASK_ATTR_ORDERED;
James Bottomley2908d772006-08-29 09:22:51 -0500137 }
138 return ta;
139}
140
141static struct sas_task *sas_create_task(struct scsi_cmnd *cmd,
142 struct domain_device *dev,
Al Viro3cc27542006-09-25 02:55:40 +0100143 gfp_t gfp_flags)
James Bottomley2908d772006-08-29 09:22:51 -0500144{
145 struct sas_task *task = sas_alloc_task(gfp_flags);
146 struct scsi_lun lun;
147
148 if (!task)
149 return NULL;
150
151 *(u32 *)cmd->sense_buffer = 0;
152 task->uldd_task = cmd;
153 ASSIGN_SAS_TASK(cmd, task);
154
155 task->dev = dev;
156 task->task_proto = task->dev->tproto; /* BUG_ON(!SSP) */
157
158 task->ssp_task.retry_count = 1;
159 int_to_scsilun(cmd->device->lun, &lun);
160 memcpy(task->ssp_task.LUN, &lun.scsi_lun, 8);
161 task->ssp_task.task_attr = sas_scsi_get_task_attr(cmd);
162 memcpy(task->ssp_task.cdb, cmd->cmnd, 16);
163
FUJITA Tomonoric13e5562007-05-26 02:46:37 +0900164 task->scatter = scsi_sglist(cmd);
165 task->num_scatter = scsi_sg_count(cmd);
166 task->total_xfer_len = scsi_bufflen(cmd);
James Bottomley2908d772006-08-29 09:22:51 -0500167 task->data_dir = cmd->sc_data_direction;
168
169 task->task_done = sas_scsi_task_done;
170
171 return task;
172}
173
Darrick J. Wong338ec572006-10-18 14:43:37 -0700174int sas_queue_up(struct sas_task *task)
James Bottomley2908d772006-08-29 09:22:51 -0500175{
176 struct sas_ha_struct *sas_ha = task->dev->port->ha;
177 struct scsi_core *core = &sas_ha->core;
178 unsigned long flags;
179 LIST_HEAD(list);
180
181 spin_lock_irqsave(&core->task_queue_lock, flags);
182 if (sas_ha->lldd_queue_size < core->task_queue_size + 1) {
183 spin_unlock_irqrestore(&core->task_queue_lock, flags);
184 return -SAS_QUEUE_FULL;
185 }
186 list_add_tail(&task->list, &core->task_queue);
187 core->task_queue_size += 1;
188 spin_unlock_irqrestore(&core->task_queue_lock, flags);
Christoph Hellwigd7a54e32007-04-26 09:38:01 -0400189 wake_up_process(core->queue_thread);
James Bottomley2908d772006-08-29 09:22:51 -0500190
191 return 0;
192}
193
194/**
195 * sas_queuecommand -- Enqueue a command for processing
196 * @parameters: See SCSI Core documentation
197 *
198 * Note: XXX: Remove the host unlock/lock pair when SCSI Core can
199 * call us without holding an IRQ spinlock...
200 */
201int sas_queuecommand(struct scsi_cmnd *cmd,
202 void (*scsi_done)(struct scsi_cmnd *))
Darrick J. Wong8ee24022007-11-05 11:52:14 -0800203 __releases(host->host_lock)
204 __acquires(dev->sata_dev.ap->lock)
205 __releases(dev->sata_dev.ap->lock)
206 __acquires(host->host_lock)
James Bottomley2908d772006-08-29 09:22:51 -0500207{
208 int res = 0;
209 struct domain_device *dev = cmd_to_domain_dev(cmd);
210 struct Scsi_Host *host = cmd->device->host;
211 struct sas_internal *i = to_sas_internal(host->transportt);
212
213 spin_unlock_irq(host->host_lock);
214
215 {
216 struct sas_ha_struct *sas_ha = dev->port->ha;
217 struct sas_task *task;
218
Darrick J. Wongfa1c1e82006-08-10 19:19:47 -0700219 if (dev_is_sata(dev)) {
Darrick J. Wong3eb7a512007-01-30 01:18:35 -0800220 unsigned long flags;
221
222 spin_lock_irqsave(dev->sata_dev.ap->lock, flags);
Darrick J. Wongfa1c1e82006-08-10 19:19:47 -0700223 res = ata_sas_queuecmd(cmd, scsi_done,
224 dev->sata_dev.ap);
Darrick J. Wong3eb7a512007-01-30 01:18:35 -0800225 spin_unlock_irqrestore(dev->sata_dev.ap->lock, flags);
Darrick J. Wongfa1c1e82006-08-10 19:19:47 -0700226 goto out;
227 }
228
James Bottomley2908d772006-08-29 09:22:51 -0500229 res = -ENOMEM;
230 task = sas_create_task(cmd, dev, GFP_ATOMIC);
231 if (!task)
232 goto out;
233
234 cmd->scsi_done = scsi_done;
235 /* Queue up, Direct Mode or Task Collector Mode. */
236 if (sas_ha->lldd_max_execute_num < 2)
237 res = i->dft->lldd_execute_task(task, 1, GFP_ATOMIC);
238 else
239 res = sas_queue_up(task);
240
241 /* Examine */
242 if (res) {
243 SAS_DPRINTK("lldd_execute_task returned: %d\n", res);
244 ASSIGN_SAS_TASK(cmd, NULL);
245 sas_free_task(task);
246 if (res == -SAS_QUEUE_FULL) {
247 cmd->result = DID_SOFT_ERROR << 16; /* retry */
248 res = 0;
249 scsi_done(cmd);
250 }
251 goto out;
252 }
253 }
254out:
255 spin_lock_irq(host->host_lock);
256 return res;
257}
258
259static void sas_scsi_clear_queue_lu(struct list_head *error_q, struct scsi_cmnd *my_cmd)
260{
261 struct scsi_cmnd *cmd, *n;
262
263 list_for_each_entry_safe(cmd, n, error_q, eh_entry) {
264 if (cmd == my_cmd)
265 list_del_init(&cmd->eh_entry);
266 }
267}
268
269static void sas_scsi_clear_queue_I_T(struct list_head *error_q,
270 struct domain_device *dev)
271{
272 struct scsi_cmnd *cmd, *n;
273
274 list_for_each_entry_safe(cmd, n, error_q, eh_entry) {
275 struct domain_device *x = cmd_to_domain_dev(cmd);
276
277 if (x == dev)
278 list_del_init(&cmd->eh_entry);
279 }
280}
281
282static void sas_scsi_clear_queue_port(struct list_head *error_q,
283 struct asd_sas_port *port)
284{
285 struct scsi_cmnd *cmd, *n;
286
287 list_for_each_entry_safe(cmd, n, error_q, eh_entry) {
288 struct domain_device *dev = cmd_to_domain_dev(cmd);
289 struct asd_sas_port *x = dev->port;
290
291 if (x == port)
292 list_del_init(&cmd->eh_entry);
293 }
294}
295
296enum task_disposition {
297 TASK_IS_DONE,
298 TASK_IS_ABORTED,
299 TASK_IS_AT_LU,
300 TASK_IS_NOT_AT_LU,
Darrick J. Wong02cd7432007-01-11 14:15:46 -0800301 TASK_ABORT_FAILED,
James Bottomley2908d772006-08-29 09:22:51 -0500302};
303
304static enum task_disposition sas_scsi_find_task(struct sas_task *task)
305{
306 struct sas_ha_struct *ha = task->dev->port->ha;
307 unsigned long flags;
308 int i, res;
309 struct sas_internal *si =
310 to_sas_internal(task->dev->port->ha->core.shost->transportt);
311
312 if (ha->lldd_max_execute_num > 1) {
313 struct scsi_core *core = &ha->core;
314 struct sas_task *t, *n;
315
316 spin_lock_irqsave(&core->task_queue_lock, flags);
317 list_for_each_entry_safe(t, n, &core->task_queue, list) {
318 if (task == t) {
319 list_del_init(&t->list);
320 spin_unlock_irqrestore(&core->task_queue_lock,
321 flags);
322 SAS_DPRINTK("%s: task 0x%p aborted from "
323 "task_queue\n",
324 __FUNCTION__, task);
325 return TASK_IS_ABORTED;
326 }
327 }
328 spin_unlock_irqrestore(&core->task_queue_lock, flags);
329 }
330
331 for (i = 0; i < 5; i++) {
332 SAS_DPRINTK("%s: aborting task 0x%p\n", __FUNCTION__, task);
333 res = si->dft->lldd_abort_task(task);
334
335 spin_lock_irqsave(&task->task_state_lock, flags);
336 if (task->task_state_flags & SAS_TASK_STATE_DONE) {
337 spin_unlock_irqrestore(&task->task_state_lock, flags);
338 SAS_DPRINTK("%s: task 0x%p is done\n", __FUNCTION__,
339 task);
340 return TASK_IS_DONE;
341 }
342 spin_unlock_irqrestore(&task->task_state_lock, flags);
343
344 if (res == TMF_RESP_FUNC_COMPLETE) {
345 SAS_DPRINTK("%s: task 0x%p is aborted\n",
346 __FUNCTION__, task);
347 return TASK_IS_ABORTED;
348 } else if (si->dft->lldd_query_task) {
349 SAS_DPRINTK("%s: querying task 0x%p\n",
350 __FUNCTION__, task);
351 res = si->dft->lldd_query_task(task);
Darrick J. Wong02cd7432007-01-11 14:15:46 -0800352 switch (res) {
353 case TMF_RESP_FUNC_SUCC:
James Bottomley2908d772006-08-29 09:22:51 -0500354 SAS_DPRINTK("%s: task 0x%p at LU\n",
355 __FUNCTION__, task);
356 return TASK_IS_AT_LU;
Darrick J. Wong02cd7432007-01-11 14:15:46 -0800357 case TMF_RESP_FUNC_COMPLETE:
James Bottomley2908d772006-08-29 09:22:51 -0500358 SAS_DPRINTK("%s: task 0x%p not at LU\n",
359 __FUNCTION__, task);
360 return TASK_IS_NOT_AT_LU;
Darrick J. Wong02cd7432007-01-11 14:15:46 -0800361 case TMF_RESP_FUNC_FAILED:
362 SAS_DPRINTK("%s: task 0x%p failed to abort\n",
363 __FUNCTION__, task);
364 return TASK_ABORT_FAILED;
365 }
366
James Bottomley2908d772006-08-29 09:22:51 -0500367 }
368 }
369 return res;
370}
371
372static int sas_recover_lu(struct domain_device *dev, struct scsi_cmnd *cmd)
373{
374 int res = TMF_RESP_FUNC_FAILED;
375 struct scsi_lun lun;
376 struct sas_internal *i =
377 to_sas_internal(dev->port->ha->core.shost->transportt);
378
379 int_to_scsilun(cmd->device->lun, &lun);
380
381 SAS_DPRINTK("eh: device %llx LUN %x has the task\n",
382 SAS_ADDR(dev->sas_addr),
383 cmd->device->lun);
384
385 if (i->dft->lldd_abort_task_set)
386 res = i->dft->lldd_abort_task_set(dev, lun.scsi_lun);
387
388 if (res == TMF_RESP_FUNC_FAILED) {
389 if (i->dft->lldd_clear_task_set)
390 res = i->dft->lldd_clear_task_set(dev, lun.scsi_lun);
391 }
392
393 if (res == TMF_RESP_FUNC_FAILED) {
394 if (i->dft->lldd_lu_reset)
395 res = i->dft->lldd_lu_reset(dev, lun.scsi_lun);
396 }
397
398 return res;
399}
400
401static int sas_recover_I_T(struct domain_device *dev)
402{
403 int res = TMF_RESP_FUNC_FAILED;
404 struct sas_internal *i =
405 to_sas_internal(dev->port->ha->core.shost->transportt);
406
407 SAS_DPRINTK("I_T nexus reset for dev %016llx\n",
408 SAS_ADDR(dev->sas_addr));
409
410 if (i->dft->lldd_I_T_nexus_reset)
411 res = i->dft->lldd_I_T_nexus_reset(dev);
412
413 return res;
414}
415
Darrick J. Wongad689232007-01-26 14:08:52 -0800416/* Find the sas_phy that's attached to this device */
Darrick J. Wong8ee24022007-11-05 11:52:14 -0800417static struct sas_phy *find_local_sas_phy(struct domain_device *dev)
Darrick J. Wong3ebf6922007-01-11 14:15:17 -0800418{
Darrick J. Wongad689232007-01-26 14:08:52 -0800419 struct domain_device *pdev = dev->parent;
420 struct ex_phy *exphy = NULL;
421 int i;
Darrick J. Wong3ebf6922007-01-11 14:15:17 -0800422
Darrick J. Wongad689232007-01-26 14:08:52 -0800423 /* Directly attached device */
424 if (!pdev)
425 return dev->port->phy;
Darrick J. Wong3ebf6922007-01-11 14:15:17 -0800426
Darrick J. Wongad689232007-01-26 14:08:52 -0800427 /* Otherwise look in the expander */
428 for (i = 0; i < pdev->ex_dev.num_phys; i++)
429 if (!memcmp(dev->sas_addr,
430 pdev->ex_dev.ex_phy[i].attached_sas_addr,
431 SAS_ADDR_SIZE)) {
432 exphy = &pdev->ex_dev.ex_phy[i];
433 break;
434 }
435
436 BUG_ON(!exphy);
437 return exphy->phy;
Darrick J. Wong3ebf6922007-01-11 14:15:17 -0800438}
439
Darrick J. Wonga9344e62007-01-29 23:48:19 -0800440/* Attempt to send a LUN reset message to a device */
Darrick J. Wongad689232007-01-26 14:08:52 -0800441int sas_eh_device_reset_handler(struct scsi_cmnd *cmd)
James Bottomley2908d772006-08-29 09:22:51 -0500442{
Darrick J. Wongad689232007-01-26 14:08:52 -0800443 struct domain_device *dev = cmd_to_domain_dev(cmd);
Darrick J. Wonga9344e62007-01-29 23:48:19 -0800444 struct sas_internal *i =
445 to_sas_internal(dev->port->ha->core.shost->transportt);
446 struct scsi_lun lun;
447 int res;
448
449 int_to_scsilun(cmd->device->lun, &lun);
450
451 if (!i->dft->lldd_lu_reset)
452 return FAILED;
453
454 res = i->dft->lldd_lu_reset(dev, lun.scsi_lun);
455 if (res == TMF_RESP_FUNC_SUCC || res == TMF_RESP_FUNC_COMPLETE)
456 return SUCCESS;
457
458 return FAILED;
459}
460
461/* Attempt to send a phy (bus) reset */
462int sas_eh_bus_reset_handler(struct scsi_cmnd *cmd)
463{
464 struct domain_device *dev = cmd_to_domain_dev(cmd);
Darrick J. Wongad689232007-01-26 14:08:52 -0800465 struct sas_phy *phy = find_local_sas_phy(dev);
466 int res;
467
468 res = sas_phy_reset(phy, 1);
469 if (res)
Darrick J. Wonga9344e62007-01-29 23:48:19 -0800470 SAS_DPRINTK("Bus reset of %s failed 0x%x\n",
Darrick J. Wongad689232007-01-26 14:08:52 -0800471 phy->dev.kobj.k_name,
472 res);
473 if (res == TMF_RESP_FUNC_SUCC || res == TMF_RESP_FUNC_COMPLETE)
474 return SUCCESS;
475
476 return FAILED;
477}
478
479/* Try to reset a device */
480static int try_to_reset_cmd_device(struct Scsi_Host *shost,
481 struct scsi_cmnd *cmd)
482{
Darrick J. Wonga9344e62007-01-29 23:48:19 -0800483 int res;
Darrick J. Wongad689232007-01-26 14:08:52 -0800484
Darrick J. Wonga9344e62007-01-29 23:48:19 -0800485 if (!shost->hostt->eh_device_reset_handler)
486 goto try_bus_reset;
487
488 res = shost->hostt->eh_device_reset_handler(cmd);
489 if (res == SUCCESS)
490 return res;
491
492try_bus_reset:
493 if (shost->hostt->eh_bus_reset_handler)
494 return shost->hostt->eh_bus_reset_handler(cmd);
495
496 return FAILED;
Darrick J. Wongad689232007-01-26 14:08:52 -0800497}
498
499static int sas_eh_handle_sas_errors(struct Scsi_Host *shost,
500 struct list_head *work_q,
501 struct list_head *done_q)
502{
James Bottomley2908d772006-08-29 09:22:51 -0500503 struct scsi_cmnd *cmd, *n;
504 enum task_disposition res = TASK_IS_DONE;
Darrick J. Wong3ebf6922007-01-11 14:15:17 -0800505 int tmf_resp, need_reset;
James Bottomley2908d772006-08-29 09:22:51 -0500506 struct sas_internal *i = to_sas_internal(shost->transportt);
Darrick J. Wongad689232007-01-26 14:08:52 -0800507 unsigned long flags;
508 struct sas_ha_struct *ha = SHOST_TO_SAS_HA(shost);
James Bottomley2908d772006-08-29 09:22:51 -0500509
James Bottomley2908d772006-08-29 09:22:51 -0500510Again:
Darrick J. Wongad689232007-01-26 14:08:52 -0800511 list_for_each_entry_safe(cmd, n, work_q, eh_entry) {
James Bottomley2908d772006-08-29 09:22:51 -0500512 struct sas_task *task = TO_SAS_TASK(cmd);
Darrick J. Wongf4563932006-10-30 15:18:39 -0800513
Darrick J. Wongad689232007-01-26 14:08:52 -0800514 if (!task)
Darrick J. Wongf4563932006-10-30 15:18:39 -0800515 continue;
Darrick J. Wongad689232007-01-26 14:08:52 -0800516
517 list_del_init(&cmd->eh_entry);
Darrick J. Wong3ebf6922007-01-11 14:15:17 -0800518
519 spin_lock_irqsave(&task->task_state_lock, flags);
520 need_reset = task->task_state_flags & SAS_TASK_NEED_DEV_RESET;
Darrick J. Wong3ebf6922007-01-11 14:15:17 -0800521 spin_unlock_irqrestore(&task->task_state_lock, flags);
522
Darrick J. Wongf4563932006-10-30 15:18:39 -0800523 SAS_DPRINTK("trying to find task 0x%p\n", task);
James Bottomley2908d772006-08-29 09:22:51 -0500524 res = sas_scsi_find_task(task);
525
526 cmd->eh_eflags = 0;
James Bottomley2908d772006-08-29 09:22:51 -0500527
528 switch (res) {
529 case TASK_IS_DONE:
530 SAS_DPRINTK("%s: task 0x%p is done\n", __FUNCTION__,
531 task);
532 task->task_done(task);
Darrick J. Wong3ebf6922007-01-11 14:15:17 -0800533 if (need_reset)
Darrick J. Wongad689232007-01-26 14:08:52 -0800534 try_to_reset_cmd_device(shost, cmd);
James Bottomley2908d772006-08-29 09:22:51 -0500535 continue;
536 case TASK_IS_ABORTED:
537 SAS_DPRINTK("%s: task 0x%p is aborted\n",
538 __FUNCTION__, task);
539 task->task_done(task);
Darrick J. Wong3ebf6922007-01-11 14:15:17 -0800540 if (need_reset)
Darrick J. Wongad689232007-01-26 14:08:52 -0800541 try_to_reset_cmd_device(shost, cmd);
James Bottomley2908d772006-08-29 09:22:51 -0500542 continue;
543 case TASK_IS_AT_LU:
544 SAS_DPRINTK("task 0x%p is at LU: lu recover\n", task);
545 tmf_resp = sas_recover_lu(task->dev, cmd);
546 if (tmf_resp == TMF_RESP_FUNC_COMPLETE) {
547 SAS_DPRINTK("dev %016llx LU %x is "
548 "recovered\n",
549 SAS_ADDR(task->dev),
550 cmd->device->lun);
551 task->task_done(task);
Darrick J. Wong3ebf6922007-01-11 14:15:17 -0800552 if (need_reset)
Darrick J. Wongad689232007-01-26 14:08:52 -0800553 try_to_reset_cmd_device(shost, cmd);
554 sas_scsi_clear_queue_lu(work_q, cmd);
James Bottomley2908d772006-08-29 09:22:51 -0500555 goto Again;
556 }
557 /* fallthrough */
558 case TASK_IS_NOT_AT_LU:
Darrick J. Wong02cd7432007-01-11 14:15:46 -0800559 case TASK_ABORT_FAILED:
James Bottomley2908d772006-08-29 09:22:51 -0500560 SAS_DPRINTK("task 0x%p is not at LU: I_T recover\n",
561 task);
562 tmf_resp = sas_recover_I_T(task->dev);
563 if (tmf_resp == TMF_RESP_FUNC_COMPLETE) {
564 SAS_DPRINTK("I_T %016llx recovered\n",
565 SAS_ADDR(task->dev->sas_addr));
566 task->task_done(task);
Darrick J. Wong3ebf6922007-01-11 14:15:17 -0800567 if (need_reset)
Darrick J. Wongad689232007-01-26 14:08:52 -0800568 try_to_reset_cmd_device(shost, cmd);
569 sas_scsi_clear_queue_I_T(work_q, task->dev);
James Bottomley2908d772006-08-29 09:22:51 -0500570 goto Again;
571 }
572 /* Hammer time :-) */
573 if (i->dft->lldd_clear_nexus_port) {
574 struct asd_sas_port *port = task->dev->port;
575 SAS_DPRINTK("clearing nexus for port:%d\n",
576 port->id);
577 res = i->dft->lldd_clear_nexus_port(port);
578 if (res == TMF_RESP_FUNC_COMPLETE) {
579 SAS_DPRINTK("clear nexus port:%d "
580 "succeeded\n", port->id);
581 task->task_done(task);
Darrick J. Wong3ebf6922007-01-11 14:15:17 -0800582 if (need_reset)
Darrick J. Wongad689232007-01-26 14:08:52 -0800583 try_to_reset_cmd_device(shost, cmd);
584 sas_scsi_clear_queue_port(work_q,
James Bottomley2908d772006-08-29 09:22:51 -0500585 port);
586 goto Again;
587 }
588 }
589 if (i->dft->lldd_clear_nexus_ha) {
590 SAS_DPRINTK("clear nexus ha\n");
591 res = i->dft->lldd_clear_nexus_ha(ha);
592 if (res == TMF_RESP_FUNC_COMPLETE) {
593 SAS_DPRINTK("clear nexus ha "
594 "succeeded\n");
595 task->task_done(task);
Darrick J. Wong3ebf6922007-01-11 14:15:17 -0800596 if (need_reset)
Darrick J. Wongad689232007-01-26 14:08:52 -0800597 try_to_reset_cmd_device(shost, cmd);
James Bottomley2908d772006-08-29 09:22:51 -0500598 goto out;
599 }
600 }
601 /* If we are here -- this means that no amount
602 * of effort could recover from errors. Quite
603 * possibly the HA just disappeared.
604 */
605 SAS_DPRINTK("error from device %llx, LUN %x "
606 "couldn't be recovered in any way\n",
607 SAS_ADDR(task->dev->sas_addr),
608 cmd->device->lun);
609
610 task->task_done(task);
Darrick J. Wong3ebf6922007-01-11 14:15:17 -0800611 if (need_reset)
Darrick J. Wongad689232007-01-26 14:08:52 -0800612 try_to_reset_cmd_device(shost, cmd);
James Bottomley2908d772006-08-29 09:22:51 -0500613 goto clear_q;
614 }
615 }
616out:
Darrick J. Wongad689232007-01-26 14:08:52 -0800617 return list_empty(work_q);
James Bottomley2908d772006-08-29 09:22:51 -0500618clear_q:
619 SAS_DPRINTK("--- Exit %s -- clear_q\n", __FUNCTION__);
Darrick J. Wongad689232007-01-26 14:08:52 -0800620 list_for_each_entry_safe(cmd, n, work_q, eh_entry) {
James Bottomley2908d772006-08-29 09:22:51 -0500621 struct sas_task *task = TO_SAS_TASK(cmd);
622 list_del_init(&cmd->eh_entry);
623 task->task_done(task);
624 }
Darrick J. Wongad689232007-01-26 14:08:52 -0800625 return list_empty(work_q);
626}
627
628void sas_scsi_recover_host(struct Scsi_Host *shost)
629{
630 struct sas_ha_struct *ha = SHOST_TO_SAS_HA(shost);
631 unsigned long flags;
632 LIST_HEAD(eh_work_q);
633
634 spin_lock_irqsave(shost->host_lock, flags);
635 list_splice_init(&shost->eh_cmd_q, &eh_work_q);
636 spin_unlock_irqrestore(shost->host_lock, flags);
637
638 SAS_DPRINTK("Enter %s\n", __FUNCTION__);
639 /*
640 * Deal with commands that still have SAS tasks (i.e. they didn't
641 * complete via the normal sas_task completion mechanism)
642 */
643 if (sas_eh_handle_sas_errors(shost, &eh_work_q, &ha->eh_done_q))
644 goto out;
645
646 /*
647 * Now deal with SCSI commands that completed ok but have a an error
648 * code (and hopefully sense data) attached. This is roughly what
649 * scsi_unjam_host does, but we skip scsi_eh_abort_cmds because any
650 * command we see here has no sas_task and is thus unknown to the HA.
651 */
652 if (!scsi_eh_get_sense(&eh_work_q, &ha->eh_done_q))
653 scsi_eh_ready_devs(shost, &eh_work_q, &ha->eh_done_q);
654
655out:
656 scsi_eh_flush_done_q(&ha->eh_done_q);
657 SAS_DPRINTK("--- Exit %s\n", __FUNCTION__);
658 return;
James Bottomley2908d772006-08-29 09:22:51 -0500659}
660
661enum scsi_eh_timer_return sas_scsi_timed_out(struct scsi_cmnd *cmd)
662{
663 struct sas_task *task = TO_SAS_TASK(cmd);
664 unsigned long flags;
665
666 if (!task) {
Darrick J. Wong6d4dcd42007-01-11 14:15:00 -0800667 cmd->timeout_per_command /= 2;
668 SAS_DPRINTK("command 0x%p, task 0x%p, gone: %s\n",
669 cmd, task, (cmd->timeout_per_command ?
670 "EH_RESET_TIMER" : "EH_NOT_HANDLED"));
671 if (!cmd->timeout_per_command)
672 return EH_NOT_HANDLED;
673 return EH_RESET_TIMER;
James Bottomley2908d772006-08-29 09:22:51 -0500674 }
675
676 spin_lock_irqsave(&task->task_state_lock, flags);
Darrick J. Wong396819f2007-01-11 14:15:20 -0800677 BUG_ON(task->task_state_flags & SAS_TASK_STATE_ABORTED);
James Bottomley2908d772006-08-29 09:22:51 -0500678 if (task->task_state_flags & SAS_TASK_STATE_DONE) {
679 spin_unlock_irqrestore(&task->task_state_lock, flags);
680 SAS_DPRINTK("command 0x%p, task 0x%p, timed out: EH_HANDLED\n",
681 cmd, task);
682 return EH_HANDLED;
683 }
Darrick J. Wongb218a0d2007-01-11 14:14:55 -0800684 if (!(task->task_state_flags & SAS_TASK_AT_INITIATOR)) {
685 spin_unlock_irqrestore(&task->task_state_lock, flags);
686 SAS_DPRINTK("command 0x%p, task 0x%p, not at initiator: "
687 "EH_RESET_TIMER\n",
688 cmd, task);
689 return EH_RESET_TIMER;
690 }
James Bottomley2908d772006-08-29 09:22:51 -0500691 task->task_state_flags |= SAS_TASK_STATE_ABORTED;
692 spin_unlock_irqrestore(&task->task_state_lock, flags);
693
694 SAS_DPRINTK("command 0x%p, task 0x%p, timed out: EH_NOT_HANDLED\n",
695 cmd, task);
696
697 return EH_NOT_HANDLED;
698}
699
Darrick J. Wongfa1c1e82006-08-10 19:19:47 -0700700int sas_ioctl(struct scsi_device *sdev, int cmd, void __user *arg)
701{
702 struct domain_device *dev = sdev_to_domain_dev(sdev);
703
704 if (dev_is_sata(dev))
705 return ata_scsi_ioctl(sdev, cmd, arg);
706
707 return -EINVAL;
708}
709
James Bottomley2908d772006-08-29 09:22:51 -0500710struct domain_device *sas_find_dev_by_rphy(struct sas_rphy *rphy)
711{
712 struct Scsi_Host *shost = dev_to_shost(rphy->dev.parent);
713 struct sas_ha_struct *ha = SHOST_TO_SAS_HA(shost);
714 struct domain_device *found_dev = NULL;
715 int i;
Darrick J. Wong980fa2f2007-01-11 14:15:40 -0800716 unsigned long flags;
James Bottomley2908d772006-08-29 09:22:51 -0500717
Darrick J. Wong980fa2f2007-01-11 14:15:40 -0800718 spin_lock_irqsave(&ha->phy_port_lock, flags);
James Bottomley2908d772006-08-29 09:22:51 -0500719 for (i = 0; i < ha->num_phys; i++) {
720 struct asd_sas_port *port = ha->sas_port[i];
721 struct domain_device *dev;
722
723 spin_lock(&port->dev_list_lock);
724 list_for_each_entry(dev, &port->dev_list, dev_list_node) {
725 if (rphy == dev->rphy) {
726 found_dev = dev;
727 spin_unlock(&port->dev_list_lock);
728 goto found;
729 }
730 }
731 spin_unlock(&port->dev_list_lock);
732 }
733 found:
Darrick J. Wong980fa2f2007-01-11 14:15:40 -0800734 spin_unlock_irqrestore(&ha->phy_port_lock, flags);
James Bottomley2908d772006-08-29 09:22:51 -0500735
736 return found_dev;
737}
738
739static inline struct domain_device *sas_find_target(struct scsi_target *starget)
740{
741 struct sas_rphy *rphy = dev_to_rphy(starget->dev.parent);
742
743 return sas_find_dev_by_rphy(rphy);
744}
745
746int sas_target_alloc(struct scsi_target *starget)
747{
748 struct domain_device *found_dev = sas_find_target(starget);
Darrick J. Wong338ec572006-10-18 14:43:37 -0700749 int res;
James Bottomley2908d772006-08-29 09:22:51 -0500750
751 if (!found_dev)
752 return -ENODEV;
753
Darrick J. Wongfa1c1e82006-08-10 19:19:47 -0700754 if (dev_is_sata(found_dev)) {
Darrick J. Wong338ec572006-10-18 14:43:37 -0700755 res = sas_ata_init_host_and_port(found_dev, starget);
756 if (res)
757 return res;
Darrick J. Wongfa1c1e82006-08-10 19:19:47 -0700758 }
759
James Bottomley2908d772006-08-29 09:22:51 -0500760 starget->hostdata = found_dev;
761 return 0;
762}
763
764#define SAS_DEF_QD 32
765#define SAS_MAX_QD 64
766
767int sas_slave_configure(struct scsi_device *scsi_dev)
768{
769 struct domain_device *dev = sdev_to_domain_dev(scsi_dev);
770 struct sas_ha_struct *sas_ha;
771
772 BUG_ON(dev->rphy->identify.device_type != SAS_END_DEVICE);
773
Darrick J. Wongfa1c1e82006-08-10 19:19:47 -0700774 if (dev_is_sata(dev)) {
775 ata_sas_slave_configure(scsi_dev, dev->sata_dev.ap);
776 return 0;
777 }
778
James Bottomley2908d772006-08-29 09:22:51 -0500779 sas_ha = dev->port->ha;
780
781 sas_read_port_mode_page(scsi_dev);
782
783 if (scsi_dev->tagged_supported) {
784 scsi_set_tag_type(scsi_dev, MSG_SIMPLE_TAG);
785 scsi_activate_tcq(scsi_dev, SAS_DEF_QD);
786 } else {
787 SAS_DPRINTK("device %llx, LUN %x doesn't support "
788 "TCQ\n", SAS_ADDR(dev->sas_addr),
789 scsi_dev->lun);
790 scsi_dev->tagged_supported = 0;
791 scsi_set_tag_type(scsi_dev, 0);
792 scsi_deactivate_tcq(scsi_dev, 1);
793 }
794
Darrick J. Wongf27708f2007-01-26 14:08:58 -0800795 scsi_dev->allow_restart = 1;
796
James Bottomley2908d772006-08-29 09:22:51 -0500797 return 0;
798}
799
800void sas_slave_destroy(struct scsi_device *scsi_dev)
801{
Darrick J. Wongfa1c1e82006-08-10 19:19:47 -0700802 struct domain_device *dev = sdev_to_domain_dev(scsi_dev);
803
804 if (dev_is_sata(dev))
805 ata_port_disable(dev->sata_dev.ap);
James Bottomley2908d772006-08-29 09:22:51 -0500806}
807
808int sas_change_queue_depth(struct scsi_device *scsi_dev, int new_depth)
809{
810 int res = min(new_depth, SAS_MAX_QD);
811
812 if (scsi_dev->tagged_supported)
813 scsi_adjust_queue_depth(scsi_dev, scsi_get_tag_type(scsi_dev),
814 res);
815 else {
816 struct domain_device *dev = sdev_to_domain_dev(scsi_dev);
817 sas_printk("device %llx LUN %x queue depth changed to 1\n",
818 SAS_ADDR(dev->sas_addr),
819 scsi_dev->lun);
820 scsi_adjust_queue_depth(scsi_dev, 0, 1);
821 res = 1;
822 }
823
824 return res;
825}
826
827int sas_change_queue_type(struct scsi_device *scsi_dev, int qt)
828{
829 if (!scsi_dev->tagged_supported)
830 return 0;
831
832 scsi_deactivate_tcq(scsi_dev, 1);
833
834 scsi_set_tag_type(scsi_dev, qt);
835 scsi_activate_tcq(scsi_dev, scsi_dev->queue_depth);
836
837 return qt;
838}
839
840int sas_bios_param(struct scsi_device *scsi_dev,
841 struct block_device *bdev,
842 sector_t capacity, int *hsc)
843{
844 hsc[0] = 255;
845 hsc[1] = 63;
846 sector_div(capacity, 255*63);
847 hsc[2] = capacity;
848
849 return 0;
850}
851
852/* ---------- Task Collector Thread implementation ---------- */
853
854static void sas_queue(struct sas_ha_struct *sas_ha)
855{
856 struct scsi_core *core = &sas_ha->core;
857 unsigned long flags;
858 LIST_HEAD(q);
859 int can_queue;
860 int res;
861 struct sas_internal *i = to_sas_internal(core->shost->transportt);
862
863 spin_lock_irqsave(&core->task_queue_lock, flags);
Christoph Hellwigd7a54e32007-04-26 09:38:01 -0400864 while (!kthread_should_stop() &&
James Bottomley2908d772006-08-29 09:22:51 -0500865 !list_empty(&core->task_queue)) {
866
867 can_queue = sas_ha->lldd_queue_size - core->task_queue_size;
868 if (can_queue >= 0) {
869 can_queue = core->task_queue_size;
870 list_splice_init(&core->task_queue, &q);
871 } else {
872 struct list_head *a, *n;
873
874 can_queue = sas_ha->lldd_queue_size;
875 list_for_each_safe(a, n, &core->task_queue) {
876 list_move_tail(a, &q);
877 if (--can_queue == 0)
878 break;
879 }
880 can_queue = sas_ha->lldd_queue_size;
881 }
882 core->task_queue_size -= can_queue;
883 spin_unlock_irqrestore(&core->task_queue_lock, flags);
884 {
885 struct sas_task *task = list_entry(q.next,
886 struct sas_task,
887 list);
888 list_del_init(&q);
889 res = i->dft->lldd_execute_task(task, can_queue,
890 GFP_KERNEL);
891 if (unlikely(res))
892 __list_add(&q, task->list.prev, &task->list);
893 }
894 spin_lock_irqsave(&core->task_queue_lock, flags);
895 if (res) {
896 list_splice_init(&q, &core->task_queue); /*at head*/
897 core->task_queue_size += can_queue;
898 }
899 }
900 spin_unlock_irqrestore(&core->task_queue_lock, flags);
901}
902
James Bottomley2908d772006-08-29 09:22:51 -0500903/**
904 * sas_queue_thread -- The Task Collector thread
905 * @_sas_ha: pointer to struct sas_ha
906 */
907static int sas_queue_thread(void *_sas_ha)
908{
909 struct sas_ha_struct *sas_ha = _sas_ha;
James Bottomley2908d772006-08-29 09:22:51 -0500910
James Bottomley2908d772006-08-29 09:22:51 -0500911 while (1) {
Christoph Hellwigd7a54e32007-04-26 09:38:01 -0400912 set_current_state(TASK_INTERRUPTIBLE);
913 schedule();
James Bottomley2908d772006-08-29 09:22:51 -0500914 sas_queue(sas_ha);
Christoph Hellwigd7a54e32007-04-26 09:38:01 -0400915 if (kthread_should_stop())
James Bottomley2908d772006-08-29 09:22:51 -0500916 break;
917 }
918
James Bottomley2908d772006-08-29 09:22:51 -0500919 return 0;
920}
921
922int sas_init_queue(struct sas_ha_struct *sas_ha)
923{
James Bottomley2908d772006-08-29 09:22:51 -0500924 struct scsi_core *core = &sas_ha->core;
925
926 spin_lock_init(&core->task_queue_lock);
927 core->task_queue_size = 0;
928 INIT_LIST_HEAD(&core->task_queue);
James Bottomley2908d772006-08-29 09:22:51 -0500929
Christoph Hellwigd7a54e32007-04-26 09:38:01 -0400930 core->queue_thread = kthread_run(sas_queue_thread, sas_ha,
931 "sas_queue_%d", core->shost->host_no);
932 if (IS_ERR(core->queue_thread))
933 return PTR_ERR(core->queue_thread);
934 return 0;
James Bottomley2908d772006-08-29 09:22:51 -0500935}
936
937void sas_shutdown_queue(struct sas_ha_struct *sas_ha)
938{
939 unsigned long flags;
940 struct scsi_core *core = &sas_ha->core;
941 struct sas_task *task, *n;
942
Christoph Hellwigd7a54e32007-04-26 09:38:01 -0400943 kthread_stop(core->queue_thread);
James Bottomley2908d772006-08-29 09:22:51 -0500944
945 if (!list_empty(&core->task_queue))
946 SAS_DPRINTK("HA: %llx: scsi core task queue is NOT empty!?\n",
947 SAS_ADDR(sas_ha->sas_addr));
948
949 spin_lock_irqsave(&core->task_queue_lock, flags);
950 list_for_each_entry_safe(task, n, &core->task_queue, list) {
951 struct scsi_cmnd *cmd = task->uldd_task;
952
953 list_del_init(&task->list);
954
955 ASSIGN_SAS_TASK(cmd, NULL);
956 sas_free_task(task);
957 cmd->result = DID_ABORT << 16;
958 cmd->scsi_done(cmd);
959 }
960 spin_unlock_irqrestore(&core->task_queue_lock, flags);
961}
962
Darrick J. Wong396819f2007-01-11 14:15:20 -0800963/*
964 * Call the LLDD task abort routine directly. This function is intended for
965 * use by upper layers that need to tell the LLDD to abort a task.
966 */
967int __sas_task_abort(struct sas_task *task)
Darrick J. Wong79a5eb62006-10-30 15:18:50 -0800968{
Darrick J. Wong79a5eb62006-10-30 15:18:50 -0800969 struct sas_internal *si =
970 to_sas_internal(task->dev->port->ha->core.shost->transportt);
971 unsigned long flags;
972 int res;
973
974 spin_lock_irqsave(&task->task_state_lock, flags);
Darrick J. Wong396819f2007-01-11 14:15:20 -0800975 if (task->task_state_flags & SAS_TASK_STATE_ABORTED ||
976 task->task_state_flags & SAS_TASK_STATE_DONE) {
Darrick J. Wong79a5eb62006-10-30 15:18:50 -0800977 spin_unlock_irqrestore(&task->task_state_lock, flags);
Darrick J. Wong396819f2007-01-11 14:15:20 -0800978 SAS_DPRINTK("%s: Task %p already finished.\n", __FUNCTION__,
Darrick J. Wong79a5eb62006-10-30 15:18:50 -0800979 task);
980 return 0;
981 }
Darrick J. Wong396819f2007-01-11 14:15:20 -0800982 task->task_state_flags |= SAS_TASK_STATE_ABORTED;
Darrick J. Wong79a5eb62006-10-30 15:18:50 -0800983 spin_unlock_irqrestore(&task->task_state_lock, flags);
984
985 if (!si->dft->lldd_abort_task)
986 return -ENODEV;
987
988 res = si->dft->lldd_abort_task(task);
Darrick J. Wong396819f2007-01-11 14:15:20 -0800989
990 spin_lock_irqsave(&task->task_state_lock, flags);
Darrick J. Wong79a5eb62006-10-30 15:18:50 -0800991 if ((task->task_state_flags & SAS_TASK_STATE_DONE) ||
992 (res == TMF_RESP_FUNC_COMPLETE))
993 {
Darrick J. Wong396819f2007-01-11 14:15:20 -0800994 spin_unlock_irqrestore(&task->task_state_lock, flags);
995 task->task_done(task);
Darrick J. Wong79a5eb62006-10-30 15:18:50 -0800996 return 0;
997 }
998
Darrick J. Wong79a5eb62006-10-30 15:18:50 -0800999 if (!(task->task_state_flags & SAS_TASK_STATE_DONE))
1000 task->task_state_flags &= ~SAS_TASK_STATE_ABORTED;
1001 spin_unlock_irqrestore(&task->task_state_lock, flags);
1002
1003 return -EAGAIN;
1004}
1005
Darrick J. Wong396819f2007-01-11 14:15:20 -08001006/*
1007 * Tell an upper layer that it needs to initiate an abort for a given task.
1008 * This should only ever be called by an LLDD.
1009 */
1010void sas_task_abort(struct sas_task *task)
Darrick J. Wong79a5eb62006-10-30 15:18:50 -08001011{
Darrick J. Wong396819f2007-01-11 14:15:20 -08001012 struct scsi_cmnd *sc = task->uldd_task;
Darrick J. Wong79a5eb62006-10-30 15:18:50 -08001013
Darrick J. Wong396819f2007-01-11 14:15:20 -08001014 /* Escape for libsas internal commands */
1015 if (!sc) {
1016 if (!del_timer(&task->timer))
Darrick J. Wong79a5eb62006-10-30 15:18:50 -08001017 return;
Darrick J. Wong396819f2007-01-11 14:15:20 -08001018 task->timer.function(task->timer.data);
1019 return;
1020 }
Darrick J. Wong79a5eb62006-10-30 15:18:50 -08001021
Darrick J. Wong3a2755a2007-01-30 01:18:58 -08001022 if (dev_is_sata(task->dev)) {
1023 sas_ata_task_abort(task);
1024 return;
1025 }
1026
Darrick J. Wong396819f2007-01-11 14:15:20 -08001027 scsi_req_abort_cmd(sc);
1028 scsi_schedule_eh(sc->device->host);
Darrick J. Wong79a5eb62006-10-30 15:18:50 -08001029}
1030
Darrick J. Wongfa1c1e82006-08-10 19:19:47 -07001031int sas_slave_alloc(struct scsi_device *scsi_dev)
1032{
1033 struct domain_device *dev = sdev_to_domain_dev(scsi_dev);
1034
1035 if (dev_is_sata(dev))
1036 return ata_sas_port_init(dev->sata_dev.ap);
1037
1038 return 0;
1039}
1040
1041void sas_target_destroy(struct scsi_target *starget)
1042{
1043 struct domain_device *found_dev = sas_find_target(starget);
1044
1045 if (!found_dev)
1046 return;
1047
1048 if (dev_is_sata(found_dev))
1049 ata_sas_port_destroy(found_dev->sata_dev.ap);
1050
1051 return;
1052}
1053
James Bottomley2908d772006-08-29 09:22:51 -05001054EXPORT_SYMBOL_GPL(sas_queuecommand);
1055EXPORT_SYMBOL_GPL(sas_target_alloc);
1056EXPORT_SYMBOL_GPL(sas_slave_configure);
1057EXPORT_SYMBOL_GPL(sas_slave_destroy);
1058EXPORT_SYMBOL_GPL(sas_change_queue_depth);
1059EXPORT_SYMBOL_GPL(sas_change_queue_type);
1060EXPORT_SYMBOL_GPL(sas_bios_param);
Darrick J. Wong396819f2007-01-11 14:15:20 -08001061EXPORT_SYMBOL_GPL(__sas_task_abort);
Darrick J. Wong79a5eb62006-10-30 15:18:50 -08001062EXPORT_SYMBOL_GPL(sas_task_abort);
Darrick J. Wongdea22212006-11-07 17:28:55 -08001063EXPORT_SYMBOL_GPL(sas_phy_reset);
Darrick J. Wongacbf1672007-01-11 14:14:57 -08001064EXPORT_SYMBOL_GPL(sas_phy_enable);
Darrick J. Wongad689232007-01-26 14:08:52 -08001065EXPORT_SYMBOL_GPL(sas_eh_device_reset_handler);
Darrick J. Wonga9344e62007-01-29 23:48:19 -08001066EXPORT_SYMBOL_GPL(sas_eh_bus_reset_handler);
Darrick J. Wongfa1c1e82006-08-10 19:19:47 -07001067EXPORT_SYMBOL_GPL(sas_slave_alloc);
1068EXPORT_SYMBOL_GPL(sas_target_destroy);
1069EXPORT_SYMBOL_GPL(sas_ioctl);