xref: /freebsd/sys/cam/cam.h (revision a8445737e740901f5f2c8d24c12ef7fc8b00134e)
1 /*
2  * Data structures and definitions for the CAM system.
3  *
4  * Copyright (c) 1997 Justin T. Gibbs.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions, and the following disclaimer,
12  *    without modification, immediately at the beginning of the file.
13  * 2. The name of the author may not be used to endorse or promote products
14  *    derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
20  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  *
28  *      $Id$
29  */
30 
31 #ifndef _CAM_CAM_H
32 #define _CAM_CAM_H 1
33 
34 #ifdef KERNEL
35 #include <opt_cam.h>
36 #endif /* KERNEL */
37 
38 #include <sys/cdefs.h>
39 
40 typedef u_int path_id_t;
41 typedef u_int target_id_t;
42 typedef u_int lun_id_t;
43 
44 #define	CAM_XPT_PATH_ID	((path_id_t)~0)
45 #define	CAM_BUS_WILDCARD ((path_id_t)~0)
46 #define	CAM_TARGET_WILDCARD ((target_id_t)~0)
47 #define	CAM_LUN_WILDCARD ((lun_id_t)~0)
48 
49 /*
50  * Maximum length for a CAM CDB.
51  */
52 #define CAM_MAX_CDBLEN 16
53 
54 /*
55  * Definition of a CAM peripheral driver entry.  Peripheral drivers instantiate
56  * one of these for each device they wish to communicate with and pass it into
57  * the xpt layer when they wish to schedule work on that device via the
58  * xpt_schecule API.
59  */
60 struct cam_periph;
61 
62 /*
63  * Priority information for a CAM structure.  The generation number is
64  * incremented everytime a new entry is entered into the queue giving round
65  * robin per priority level scheduling.
66  */
67 typedef struct {
68 	u_int32_t priority;
69 #define CAM_PRIORITY_NONE	(u_int32_t)-1
70 	u_int32_t generation;
71 	int       index;
72 #define CAM_UNQUEUED_INDEX	-1
73 #define CAM_ACTIVE_INDEX	-2
74 #define CAM_DONEQ_INDEX		-3
75 } cam_pinfo;
76 
77 /* CAM flags */
78 typedef enum {
79 	CAM_FLAG_NONE		= 0x00,
80 	CAM_EXPECT_INQ_CHANGE	= 0x01
81 } cam_flags;
82 
83 /* CAM  Status field values */
84 typedef enum {
85 	CAM_REQ_INPROG,		/* CCB request is in progress */
86 	CAM_REQ_CMP,		/* CCB request completed without error */
87 	CAM_REQ_ABORTED,	/* CCB request aborted by the host */
88 	CAM_UA_ABORT,		/* Unable to abort CCB request */
89 	CAM_REQ_CMP_ERR,	/* CCB request completed with an error */
90 	CAM_BUSY,		/* CAM subsytem is busy */
91 	CAM_REQ_INVALID,	/* CCB request was invalid */
92 	CAM_PATH_INVALID,	/* Supplied Path ID is invalid */
93 	CAM_DEV_NOT_THERE,	/* SCSI Device Not Installed/there */
94 	CAM_UA_TERMIO,		/* Unable to terminate I/O CCB request */
95 	CAM_SEL_TIMEOUT,	/* Target Selection Timeout */
96 	CAM_CMD_TIMEOUT,	/* Command timeout */
97 	CAM_SCSI_STATUS_ERROR,	/* SCSI error, look at error code in CCB */
98 	CAM_MSG_REJECT_REC,	/* Message Reject Reveived */
99 	CAM_SCSI_BUS_RESET,	/* SCSI Bus Reset Sent/Received */
100 	CAM_UNCOR_PARITY,	/* Uncorrectable parity error occurred */
101 	CAM_AUTOSENSE_FAIL = 0x10,/* Autosense: request sense cmd fail */
102 	CAM_NO_HBA,		/* No HBA Detected error */
103 	CAM_DATA_RUN_ERR,	/* Data Overrun error */
104 	CAM_UNEXP_BUSFREE,	/* Unexpected Bus Free */
105 	CAM_SEQUENCE_FAIL,	/* Target Bus Phase Sequence Failure */
106 	CAM_CCB_LEN_ERR,	/* CCB length supplied is inadequate */
107 	CAM_PROVIDE_FAIL,	/* Unable to provide requested capability */
108 	CAM_BDR_SENT,		/* A SCSI BDR msg was sent to target */
109 	CAM_REQ_TERMIO,		/* CCB request terminated by the host */
110 	CAM_UNREC_HBA_ERROR,	/* Unrecoverable Host Bus Adapter Error */
111 	CAM_REQ_TOO_BIG,	/* The request was too large for this host */
112 	CAM_REQUEUE_REQ,	/*
113 				 * This request should be requeued to preserve
114 				 * transaction ordering.  This typically occurs
115 				 * when the SIM recognizes an error that should
116 				 * freeze the queue and must place additional
117 				 * requests for the target at the sim level
118 				 * back into the XPT queue.
119 				 */
120 	CAM_IDE = 0x33,		/* Initiator Detected Error */
121 	CAM_RESRC_UNAVAIL,	/* Resource Unavailable */
122 	CAM_UNACKED_EVENT,	/* Unacknowledged Event by Host */
123 	CAM_MESSAGE_RECV,	/* Message Received in Host Target Mode */
124 	CAM_INVALID_CDB,	/* Invalid CDB received in Host Target Mode */
125 	CAM_LUN_INVALID,	/* Lun supplied is invalid */
126 	CAM_TID_INVALID,	/* Target ID supplied is invalid */
127 	CAM_FUNC_NOTAVAIL,	/* The requested function is not available */
128 	CAM_NO_NEXUS,		/* Nexus is not established */
129 	CAM_IID_INVALID,	/* The initiator ID is invalid */
130 	CAM_CDB_RECVD,		/* The SCSI CDB has been received */
131 	CAM_LUN_ALRDY_ENA,	/* The LUN is already eanbeld for target mode */
132 	CAM_SCSI_BUSY,		/* SCSI Bus Busy */
133 
134 	CAM_DEV_QFRZN = 0x40,	/* The DEV queue is frozen w/this err */
135 
136 				/* Autosense data valid for target */
137 	CAM_AUTOSNS_VALID = 0x80,
138 	CAM_RELEASE_SIMQ = 0x100,/* SIM ready to take more commands */
139 	CAM_SIM_QUEUED   = 0x200,/* SIM has this command in it's queue */
140 
141 	CAM_STATUS_MASK = 0x3F,	/* Mask bits for just the status # */
142 } cam_status;
143 
144 __BEGIN_DECLS
145 typedef int (cam_quirkmatch_t)(caddr_t, caddr_t);
146 
147 caddr_t	cam_quirkmatch(caddr_t target, caddr_t quirk_table, int num_entries,
148 		       int entry_size, cam_quirkmatch_t *comp_func);
149 
150 void	cam_strvis(u_int8_t *dst, const u_int8_t *src, int srclen, int dstlen);
151 
152 int	cam_strmatch(const u_int8_t *str, const u_int8_t *pattern, int str_len);
153 __END_DECLS
154 
155 #ifdef KERNEL
156 static __inline void cam_init_pinfo(cam_pinfo *pinfo);
157 
158 static __inline void cam_init_pinfo(cam_pinfo *pinfo)
159 {
160 	pinfo->priority = CAM_PRIORITY_NONE;
161 	pinfo->index = CAM_UNQUEUED_INDEX;
162 }
163 #endif /* KERNEL */
164 
165 #endif /* _CAM_CAM_H */
166