1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 /*
27  * Generic Abort, Reset and Misc Routines
28  */
29 
30 #include <sys/scsi/scsi.h>
31 
32 
33 #define	A_TO_TRAN(ap)	(ap->a_hba_tran)
34 
35 int
scsi_abort(struct scsi_address * ap,struct scsi_pkt * pkt)36 scsi_abort(struct scsi_address *ap, struct scsi_pkt *pkt)
37 {
38 	return (*A_TO_TRAN(ap)->tran_abort)(ap, pkt);
39 }
40 
41 int
scsi_reset(struct scsi_address * ap,int level)42 scsi_reset(struct scsi_address *ap, int level)
43 {
44 	ASSERT((level == RESET_LUN) || (level == RESET_TARGET) ||
45 	    (level == RESET_ALL));
46 	if ((level == RESET_LUN) &&
47 	    ((*A_TO_TRAN(ap)->tran_getcap)(ap, "lun-reset", 1) != 1)) {
48 		return (0);
49 	}
50 	if ((A_TO_TRAN(ap)->tran_reset) == NULL) {
51 		return (0);
52 	}
53 	return (*A_TO_TRAN(ap)->tran_reset)(ap, level);
54 }
55 
56 int
scsi_reset_notify(struct scsi_address * ap,int flag,void (* callback)(caddr_t),caddr_t arg)57 scsi_reset_notify(struct scsi_address *ap, int flag,
58 	void (*callback)(caddr_t), caddr_t arg)
59 {
60 	if ((A_TO_TRAN(ap)->tran_reset_notify) == NULL) {
61 		return (DDI_FAILURE);
62 	}
63 	return (*A_TO_TRAN(ap)->tran_reset_notify)(ap, flag, callback, arg);
64 }
65 
66 int
scsi_clear_task_set(struct scsi_address * ap)67 scsi_clear_task_set(struct scsi_address *ap)
68 {
69 	if ((A_TO_TRAN(ap)->tran_clear_task_set) == NULL) {
70 		return (-1);
71 	}
72 	return (*A_TO_TRAN(ap)->tran_clear_task_set)(ap);
73 }
74 
75 int
scsi_terminate_task(struct scsi_address * ap,struct scsi_pkt * pkt)76 scsi_terminate_task(struct scsi_address *ap, struct scsi_pkt *pkt)
77 {
78 	if ((A_TO_TRAN(ap)->tran_terminate_task) == NULL) {
79 		return (-1);
80 	}
81 	return (*A_TO_TRAN(ap)->tran_terminate_task)(ap, pkt);
82 }
83 
84 /*
85  * Other Misc Routines
86  */
87 
88 int
scsi_clear_aca(struct scsi_address * ap)89 scsi_clear_aca(struct scsi_address *ap)
90 {
91 	if ((A_TO_TRAN(ap)->tran_clear_aca) == NULL) {
92 		return (-1);
93 	}
94 	return (*A_TO_TRAN(ap)->tran_clear_aca)(ap);
95 }
96