xref: /openbsd/sys/dev/ic/aic7xxx_cam.h (revision 4b1a56af)
1 /*	$OpenBSD: aic7xxx_cam.h,v 1.10 2022/01/09 05:42:38 jsg Exp $	*/
2 /*	$NetBSD: aic7xxx_cam.h,v 1.3 2003/04/20 11:17:20 fvdl Exp $	*/
3 
4 /*
5  * Data structures and definitions for the CAM system.
6  *
7  * Copyright (c) 1997 Justin T. Gibbs.
8  * Copyright (c) 2000 Adaptec Inc.
9  * All rights reserved.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions, and the following disclaimer,
16  *    without modification.
17  * 2. The name of the author may not be used to endorse or promote products
18  *    derived from this software without specific prior written permission.
19  *
20  * Alternatively, this software may be distributed under the terms of the
21  * GNU General Public License ("GPL").
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
27  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33  * SUCH DAMAGE.
34  *
35  */
36 /*
37  * Ported from FreeBSD by Pascal Renauld, Network Storage Solutions, Inc. - April 2003
38  */
39 
40 #ifndef _AIC7XXX_CAM_H
41 #define _AIC7XXX_CAM_H
42 
43 #define	CAM_BUS_WILDCARD ((u_int)~0)
44 #define	CAM_TARGET_WILDCARD ((u_int)~0)
45 #define	CAM_LUN_WILDCARD -1
46 
47 /*
48  * Translate FreeBSD names for SCSI status byte values to OpenBSD names.
49  */
50 #define SCSI_STATUS_OK                  SCSI_OK
51 #define SCSI_STATUS_CHECK_COND          SCSI_CHECK
52 #define SCSI_STATUS_COND_MET            SCSI_COND_MET
53 #define SCSI_STATUS_BUSY                SCSI_BUSY
54 #define SCSI_STATUS_INTERMED            SCSI_INTERM
55 #define SCSI_STATUS_INTERMED_COND_MET   SCSI_INTERMED_COND_MET
56 #define SCSI_STATUS_RESERV_CONFLICT     SCSI_RESERV_CONFLICT
57 #define SCSI_STATUS_CMD_TERMINATED      SCSI_TERMINATED
58 #define SCSI_STATUS_QUEUE_FULL          SCSI_QUEUE_FULL
59 
60 #define XS_CTL_DATA_IN		SCSI_DATA_IN
61 #define XS_CTL_POLL		SCSI_POLL
62 #define XS_CTL_RESET		SCSI_RESET
63 
64 #define MSG_EXT_PPR_QAS_REQ	MSG_EXT_PPR_PROT_QAS
65 #define MSG_EXT_PPR_IU_REQ	MSG_EXT_PPR_PROT_IUS
66 #define MSG_EXT_PPR_DT_REQ	MSG_EXT_PPR_PROT_DT
67 #define MSG_ORDERED_TASK	MSG_ORDERED_Q_TAG
68 #define MSG_SIMPLE_TASK		MSG_SIMPLE_Q_TAG
69 #define MSG_ABORT_TASK		MSG_ABORT_TAG
70 
71 #define	callout_reset(timer, timeout, func, arg) do {	\
72 	if (!timeout_initialized((timer)))		\
73 		timeout_set((timer), (func), (arg));	\
74 	timeout_add((timer), (timeout));		\
75 } while (0)
76 
77 #define aic_delay	DELAY
78 
79 #define aic_htobe16(x) htobe16(x)
80 #define aic_htobe32(x) htobe32(x)
81 #define aic_htobe64(x) htobe64(x)
82 #define aic_htole16(x) htole16(x)
83 #define aic_htole32(x) htole32(x)
84 #define aic_htole64(x) htole64(x)
85 
86 #define aic_be16toh(x) be16toh(x)
87 #define aic_be32toh(x) be32toh(x)
88 #define aic_be64toh(x) be64toh(x)
89 #define aic_le16toh(x) letoh16(x)
90 #define aic_le32toh(x) letoh32(x)
91 #define aic_le64toh(x) letoh64(x)
92 
93 #define xs_control	flags
94 #define xs_callout	stimeout
95 #define xs_status	status
96 
97 /* CAM Status field values */
98 typedef enum {
99 	CAM_REQ_INPROG,		/* CCB request is in progress */
100 	CAM_REQ_CMP,		/* CCB request completed without error */
101 	CAM_REQ_ABORTED,	/* CCB request aborted by the host */
102 	CAM_UA_ABORT,		/* Unable to abort CCB request */
103 	CAM_REQ_CMP_ERR,	/* CCB request completed with an error */
104 	CAM_BUSY,		/* CAM subsystem is busy */
105 	CAM_REQ_INVALID,	/* CCB request was invalid */
106 	CAM_PATH_INVALID,	/* Supplied Path ID is invalid */
107 	CAM_SEL_TIMEOUT,	/* Target Selection Timeout */
108 	CAM_CMD_TIMEOUT,	/* Command timeout */
109 	CAM_SCSI_STATUS_ERROR,	/* SCSI error, look at error code in CCB */
110 	CAM_SCSI_BUS_RESET,	/* SCSI Bus Reset Sent/Received */
111 	CAM_UNCOR_PARITY,	/* Uncorrectable parity error occurred */
112 	CAM_AUTOSENSE_FAIL,	/* Autosense: request sense cmd fail */
113 	CAM_NO_HBA,		/* No HBA Detected Error */
114 	CAM_DATA_RUN_ERR,	/* Data Overrun error */
115 	CAM_UNEXP_BUSFREE,	/* Unexpected Bus Free */
116 	CAM_SEQUENCE_FAIL,	/* Protocol Violation */
117 	CAM_CCB_LEN_ERR,	/* CCB length supplied is inadequate */
118 	CAM_PROVIDE_FAIL,	/* Unable to provide requested capability */
119 	CAM_BDR_SENT,		/* A SCSI BDR msg was sent to target */
120 	CAM_REQ_TERMIO,		/* CCB request terminated by the host */
121 	CAM_UNREC_HBA_ERROR,	/* Unrecoverable Host Bus Adapter Error */
122 	CAM_REQ_TOO_BIG,	/* The request was too large for this host */
123 	CAM_UA_TERMIO,		/* Unable to terminate I/O CCB request */
124 	CAM_MSG_REJECT_REC,	/* Message Reject Received */
125 	CAM_DEV_NOT_THERE,	/* SCSI Device Not Installed/there */
126 	CAM_RESRC_UNAVAIL,	/* Resource Unavailable */
127 	/*
128 	 * This request should be requeued to preserve
129 	 * transaction ordering.  This typically occurs
130 	 * when the SIM recognizes an error that should
131 	 * freeze the queue and must place additional
132 	 * requests for the target at the sim level
133 	 * back into the XPT queue.
134 	 */
135 	CAM_REQUEUE_REQ,
136 	CAM_DEV_QFRZN		= 0x40,
137 
138 	CAM_STATUS_MASK		= 0x3F
139 } cam_status;
140 
141 typedef enum {
142 	CAM_DIR_IN		= SCSI_DATA_IN,
143 	CAM_DIR_OUT		= SCSI_DATA_OUT
144 } ccb_flags;
145 
146 typedef enum {
147 	AC_BUS_RESET            =       0x001,
148 	AC_UNSOL_RESEL          =       0x002,
149 	AC_SCSI_AEN             =       0x008,
150 	AC_SENT_BDR             =       0x010,
151 	AC_PATH_REGISTERED      =       0x020,
152 	AC_PATH_DEREGISTERED    =       0x040,
153 	AC_FOUND_DEVICE         =       0x080,
154 	AC_LOST_DEVICE          =       0x100,
155 	AC_TRANSFER_NEG         =       0x200,
156 	AC_INQ_CHANGED          =       0x400,
157 	AC_GETDEV_CHANGED       =       0x800
158 } ac_code;
159 
160 #endif /* _AIC7XXX_CAM_H */
161