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 #ifndef	_SBD_IMPL_H
27 #define	_SBD_IMPL_H
28 
29 #ifdef	__cplusplus
30 extern "C" {
31 #endif
32 
33 struct register_lu_cmd;
34 struct modify_lu_cmd;
35 struct sbd_lu_attr;
36 struct sbd_it_data;
37 
38 /*
39  * sms endianess
40  */
41 #define	SMS_BIG_ENDIAN			0x00
42 #define	SMS_LITTLE_ENDIAN		0xFF
43 
44 #ifdef	_BIG_ENDIAN
45 #define	SMS_DATA_ORDER	SMS_BIG_ENDIAN
46 #else
47 #define	SMS_DATA_ORDER	SMS_LITTLE_ENDIAN
48 #endif
49 
50 /* Test if one of the BitOrder definitions exists */
51 #ifdef _BIT_FIELDS_LTOH
52 #elif defined(_BIT_FIELDS_HTOL)
53 #else
54 #error  One of _BIT_FIELDS_LTOH or _BIT_FIELDS_HTOL must be defined
55 #endif
56 
57 #define	SBD_V0_MAGIC	0x53554e4d4943524f
58 #define	SBD_MAGIC	0x53554e5342444c55
59 
60 typedef struct sbd_v0_meta_start {
61 	uint64_t		sm_magic;	/* SBD_MAGIC */
62 	uint64_t		sm_meta_size;	/* Includes everything */
63 } sbd_v0_meta_start_t;
64 
65 typedef struct sbd_meta_start {
66 	uint64_t		sm_magic;
67 	uint64_t		sm_meta_size;
68 	uint64_t		sm_meta_size_used;
69 	uint64_t		sm_rsvd1;	/* Defaults to zero */
70 	uint64_t		sm_rsvd2;
71 	uint16_t		sm_ver_major;
72 	uint16_t		sm_ver_minor;
73 	uint16_t		sm_ver_subminor;
74 	uint8_t			sm_flags;	/* None at this moment */
75 	uint8_t			sm_chksum;
76 } sbd_meta_start_t;
77 
78 typedef struct sm_v0_section_hdr {
79 	uint64_t	sms_offset;	/* Offset of this section */
80 	uint64_t	sms_size;	/* Includes the header and padding */
81 	uint16_t	sms_id;		/* Section identifier */
82 	uint16_t	sms_padding;	/* For alignment */
83 	uint32_t	sms_seqno;	/* For multiple sections with same ID */
84 	uint8_t		sms_hdr_data_order; /* 0x00 or 0xff */
85 	uint8_t		sms_payload_data_order;
86 	uint16_t	rsvd2;
87 	uint32_t	rsvd3;		/* 8 byte align */
88 } sm_v0_section_hdr_t;
89 
90 /*
91  * sbd_it_flags
92  */
93 #define	SBD_IT_HAS_SCSI2_RESERVATION	0x0001
94 #define	SBD_IT_PGR_REGISTERED		0x0002
95 #define	SBD_IT_PGR_EXCLUSIVE_RSV_HOLDER	0x0004
96 #define	SBD_IT_PGR_CHECK_FLAG		0x0008
97 
98 /*
99  * PGR flags
100  */
101 #define	SBD_PGR_APTPL			0x01
102 #define	SBD_PGR_RSVD_ONE		0x02
103 #define	SBD_PGR_RSVD_ALL_REGISTRANTS	0x04
104 #define	SBD_PGR_ALL_KEYS_HAS_IT		0x08
105 
106 #define	SBD_PGR_RSVD(pgr)	(((pgr)->pgr_flags) & (SBD_PGR_RSVD_ONE | \
107 					SBD_PGR_RSVD_ALL_REGISTRANTS))
108 #define	SBD_PGR_RSVD_NONE(pgr)	(!(SBD_PGR_RSVD(pgr)))
109 
110 /*
111  * PGR key flags
112  */
113 #define	SBD_PGR_KEY_ALL_TG_PT		0x01
114 
115 typedef struct sbd_pgr_key_info {
116 	uint64_t	pgr_key;
117 	uint16_t	pgr_key_lpt_len;
118 	uint16_t	pgr_key_rpt_len;
119 	uint8_t		pgr_key_flags;
120 	uint8_t		pgr_key_it[1];	/* devid_desc of initiator will be */
121 					/* followed by devid_desc of target */
122 } sbd_pgr_key_info_t;
123 
124 typedef struct sbd_pgr_info {
125 	sm_section_hdr_t	pgr_sms_header;
126 	uint32_t		pgr_rsvholder_indx;
127 	uint32_t		pgr_numkeys;
128 	uint8_t			pgr_flags;
129 	uint8_t			pgr_data_order;
130 #ifdef _BIT_FIELDS_LTOH
131 	uint8_t			pgr_rsv_type:4,
132 				pgr_rsv_scope:4;
133 #else
134 	uint8_t			pgr_rsv_scope:4,
135 				pgr_rsv_type:4;
136 #endif
137 	uint8_t			rsvd[5];	/* 8 byte boundary */
138 
139 } sbd_pgr_info_t;
140 
141 typedef struct sbd_pgr_key {
142 	uint64_t		pgr_key;
143 	uint16_t		pgr_key_lpt_len;
144 	uint16_t		pgr_key_rpt_len;
145 	uint8_t			pgr_key_flags;
146 	struct scsi_devid_desc	*pgr_key_lpt_id;
147 	struct scsi_devid_desc	*pgr_key_rpt_id;
148 	struct sbd_it_data	*pgr_key_it;
149 	struct sbd_pgr_key	*pgr_key_next;
150 	struct sbd_pgr_key	*pgr_key_prev;
151 } sbd_pgr_key_t;
152 
153 typedef struct sbd_pgr {
154 	sbd_pgr_key_t		*pgr_keylist;
155 	sbd_pgr_key_t		*pgr_rsvholder;
156 	uint32_t		pgr_PRgeneration; /* PGR PRgeneration value */
157 	uint8_t			pgr_flags;	/* PGR flags (eg: APTPL)  */
158 	uint8_t			pgr_rsv_type:4,
159 				pgr_rsv_scope:4;
160 	krwlock_t		pgr_lock; /* Lock order pgr_lock, sl_lock */
161 } sbd_pgr_t;
162 
163 
164 typedef struct sbd_v0_lu_info {
165 	sm_v0_section_hdr_t	sli_sms_header;
166 	uint64_t		sli_total_store_size;
167 	uint64_t		sli_total_meta_size;
168 	uint64_t		rsvd0;
169 	uint64_t		sli_lu_data_offset;
170 	uint64_t		sli_lu_data_size;
171 	uint64_t		rsvd1;
172 	uint32_t		sli_flags;
173 	uint16_t		sli_blocksize;
174 	uint16_t		rsvd2;
175 	uint8_t			sli_lu_devid[20];
176 	uint32_t		rsvd3;
177 } sbd_v0_lu_info_t;
178 
179 typedef struct sbd_lu_info {
180 	sm_section_hdr_t	sli_sms_header;
181 	uint64_t		sli_total_store_size;
182 	uint64_t		sli_total_meta_size;
183 	uint64_t		sli_lu_data_offset;
184 	uint64_t		sli_lu_data_size;
185 	uint32_t		sli_flags;
186 	uint16_t		sli_blocksize;
187 	uint8_t			sli_data_order;
188 	uint8_t			rsvd1;
189 	uint8_t			sli_lu_devid[20];
190 	uint32_t		rsvd2;
191 } sbd_lu_info_t;
192 
193 /*
194  * sl_flags
195  */
196 #define	SBD_LU_HAS_SCSI2_RESERVATION	0x0001
197 
198 typedef struct sbd_cmd {
199 	uint8_t		flags;
200 	uint8_t		nbufs;
201 	uint16_t	cmd_type;	/* Type of command */
202 	uint32_t	rsvd2;
203 	uint64_t	addr;		/* current */
204 	uint32_t	len;		/* len left */
205 	uint32_t	current_ro;	/* running relative offset */
206 } sbd_cmd_t;
207 
208 /*
209  * flags for sbd_cmd
210  */
211 #define	SBD_SCSI_CMD_ACTIVE		0x01
212 #define	SBD_SCSI_CMD_ABORT_REQUESTED	0x02
213 #define	SBD_SCSI_CMD_XFER_FAIL		0x04
214 
215 /*
216  * cmd types
217  */
218 #define	SBD_CMD_SCSI_READ	0x01
219 #define	SBD_CMD_SCSI_WRITE	0x02
220 #define	SBD_CMD_SMALL_READ	0x03
221 #define	SBD_CMD_SMALL_WRITE	0x04
222 #define	SBD_CMD_SCSI_PR_OUT	0x05
223 
224 typedef struct sbd_it_data {
225 	struct sbd_it_data	*sbd_it_next;
226 	uint64_t		sbd_it_session_id;
227 	uint8_t			sbd_it_lun[8];
228 	uint8_t			sbd_it_ua_conditions;
229 	uint8_t			sbd_it_flags;
230 	sbd_pgr_key_t		*pgr_key_ptr;
231 } sbd_it_data_t;
232 
233 typedef struct sbd_create_standby_lu {
234 	uint32_t	stlu_meta_fname_size;
235 	uint32_t	stlu_rsvd;
236 	uint8_t		stlu_guid[16];
237 	char		stlu_meta_fname[8];
238 } sbd_create_standby_lu_t;
239 
240 /*
241  * Different UA conditions
242  */
243 #define	SBD_UA_POR			    0x01
244 #define	SBD_UA_CAPACITY_CHANGED		    0x02
245 #define	SBD_UA_MODE_PARAMETERS_CHANGED	    0x04
246 #define	SBD_UA_ACCESS_STATE_TRANSITION	    0x08
247 #define	SBD_UA_REGISTRATIONS_PREEMPTED	    0x10
248 #define	SBD_UA_RESERVATIONS_PREEMPTED	    0x20
249 #define	SBD_UA_RESERVATIONS_RELEASED	    0x40
250 #define	SBD_UA_ASYMMETRIC_ACCESS_CHANGED    0x80
251 
252 /*
253  * sbd_it_flags
254  */
255 #define	SBD_IT_HAS_SCSI2_RESERVATION	0x0001
256 
257 stmf_status_t sbd_task_alloc(struct scsi_task *task);
258 void sbd_new_task(struct scsi_task *task, struct stmf_data_buf *initial_dbuf);
259 void sbd_dbuf_xfer_done(struct scsi_task *task, struct stmf_data_buf *dbuf);
260 void sbd_send_status_done(struct scsi_task *task);
261 void sbd_task_free(struct scsi_task *task);
262 stmf_status_t sbd_abort(struct stmf_lu *lu, int abort_cmd, void *arg,
263 							uint32_t flags);
264 void sbd_ctl(struct stmf_lu *lu, int cmd, void *arg);
265 stmf_status_t sbd_info(uint32_t cmd, stmf_lu_t *lu, void *arg,
266 				uint8_t *buf, uint32_t *bufsizep);
267 
268 #ifdef	__cplusplus
269 }
270 #endif
271 
272 #endif /* _SBD_IMPL_H */
273