xref: /illumos-gate/usr/src/uts/common/io/comstar/lu/stmf_sbd/stmf_sbd.h (revision 581cede61ac9c14d8d4ea452562a567189eead78)
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	_STMF_SBD_H
27 #define	_STMF_SBD_H
28 
29 #ifdef	__cplusplus
30 extern "C" {
31 #endif
32 
33 typedef	stmf_status_t	sbd_status_t;
34 extern char sbd_vendor_id[];
35 extern char sbd_product_id[];
36 extern char sbd_revision[];
37 /*
38  * Error codes
39  */
40 #define	SBD_SUCCESS		STMF_SUCCESS
41 #define	SBD_FAILURE		STMF_LU_FAILURE
42 
43 #define	SBD_ALREADY		(SBD_FAILURE | STMF_FSC(1))
44 #define	SBD_NOT_SUPPORTED	(SBD_FAILURE | STMF_FSC(2))
45 #define	SBD_META_CORRUPTED	(SBD_FAILURE | STMF_FSC(3))
46 #define	SBD_INVALID_ARG		(SBD_FAILURE | STMF_FSC(4))
47 #define	SBD_NOT_FOUND		(SBD_FAILURE | STMF_FSC(5))
48 #define	SBD_ALLOC_FAILURE	(SBD_FAILURE | STMF_FSC(6))
49 #define	SBD_FILEIO_FAILURE	(SBD_FAILURE | STMF_FSC(7))
50 #define	SBD_IO_PAST_EOF		(SBD_FAILURE | STMF_FSC(8))
51 #define	SBD_BUSY		(SBD_FAILURE | STMF_FSC(9))
52 
53 #define	SHARED_META_DATA_SIZE	65536
54 #define	SBD_META_OFFSET		4096
55 #define	SBD_MIN_LU_SIZE		(1024 * 1024)
56 
57 /*
58  * sms endianess
59  */
60 #define	SMS_BIG_ENDIAN			0x00
61 #define	SMS_LITTLE_ENDIAN		0xFF
62 
63 #ifdef	_BIG_ENDIAN
64 #define	SMS_DATA_ORDER	SMS_BIG_ENDIAN
65 #else
66 #define	SMS_DATA_ORDER	SMS_LITTLE_ENDIAN
67 #endif
68 
69 #define	SBD_MAGIC	0x53554e5342444c55
70 
71 #define	SBD_VER_MAJOR		1
72 #define	SBD_VER_MINOR		1
73 #define	SBD_VER_SUBMINOR	0
74 
75 #if 0
76 typedef struct sbd_meta_start {
77 	uint64_t		sm_magic;
78 	uint64_t		sm_meta_size;
79 	uint64_t		sm_meta_size_used;
80 	uint64_t		sm_rsvd1;	/* Defaults to zero */
81 	uint64_t		sm_rsvd2;
82 	uint16_t		sm_ver_major;
83 	uint16_t		sm_ver_minor;
84 	uint16_t		sm_ver_subminor;
85 	uint8_t			sm_flags;
86 	uint8_t			sm_chksum;
87 } sbd_meta_start_t;
88 #endif
89 
90 typedef struct sm_section_hdr {
91 	uint64_t	sms_offset;	/* Offset of this section */
92 	uint32_t	sms_size;	/* Includes the header and padding */
93 	uint16_t	sms_id;		/* Section identifier */
94 	uint8_t		sms_data_order; /* 0x00 or 0xff */
95 	uint8_t		sms_chksum;
96 } sm_section_hdr_t;
97 
98 /*
99  * sbd meta section identifiers
100  */
101 #define	SMS_ID_LU_INFO_1_0	0
102 #define	SMS_ID_LU_INFO_1_1	1
103 #define	SMS_ID_PGR_INFO		2
104 #define	SMS_ID_UNUSED		0x1000
105 
106 typedef struct sbd_lu_info_1_0 {
107 	sm_section_hdr_t	sli_sms_header;
108 	uint64_t		sli_total_store_size;
109 	uint64_t		sli_total_meta_size;
110 	uint64_t		sli_lu_data_offset;
111 	uint64_t		sli_lu_data_size;
112 	uint32_t		sli_flags;
113 	uint16_t		sli_blocksize;
114 	uint8_t			sli_data_order;
115 	uint8_t			rsvd1;
116 	uint8_t			sli_lu_devid[20];
117 	uint32_t		rsvd2;
118 } sbd_lu_info_1_0_t;
119 
120 typedef struct sbd_lu_info_1_1 {
121 	sm_section_hdr_t	sli_sms_header;
122 	uint32_t		sli_flags;
123 	char			sli_rev[4];
124 	char			sli_vid[8];
125 	char			sli_pid[16];
126 	uint64_t		sli_lu_size;	/* Read capacity size */
127 
128 	/*
129 	 * Essetially zfs volume name for zvols to verify that the
130 	 * metadata is coming in from the correct zvol and not from a
131 	 * clone. Has no meaning in any other case.
132 	 */
133 	uint64_t		sli_meta_fname_offset;
134 
135 	/*
136 	 * Data filename or the media filename when the metadata is in
137 	 * a separate file. Its not needed if the metadata is shared
138 	 * with data as the user supplied name is the data filename.
139 	 */
140 	uint64_t		sli_data_fname_offset;
141 	uint64_t		sli_serial_offset;
142 	uint64_t		sli_alias_offset;
143 	uint8_t			sli_data_blocksize_shift;
144 	uint8_t			sli_data_order;
145 	uint8_t			sli_serial_size;
146 	uint8_t			sli_rsvd1;
147 	uint8_t			sli_device_id[20];
148 	uint64_t		sli_mgmt_url_offset;
149 	uint8_t			sli_rsvd2[248];
150 
151 	/*
152 	 * In case there is no separate meta, sli_meta_fname_offset wont
153 	 * be valid. The same is true for zfs based metadata. The data_fname
154 	 * is the zvol.
155 	 */
156 	uint8_t			sli_buf[8];
157 } sbd_lu_info_1_1_t;
158 
159 /*
160  * sli flags
161  */
162 #define	SLI_SEPARATE_META			0x0001
163 #define	SLI_WRITE_PROTECTED			0x0002
164 #define	SLI_VID_VALID				0x0004
165 #define	SLI_PID_VALID				0x0008
166 #define	SLI_REV_VALID				0x0010
167 #define	SLI_META_FNAME_VALID			0x0020
168 #define	SLI_DATA_FNAME_VALID			0x0040
169 #define	SLI_SERIAL_VALID			0x0080
170 #define	SLI_ALIAS_VALID				0x0100
171 #define	SLI_WRITEBACK_CACHE_DISABLE		0x0200
172 #define	SLI_ZFS_META				0x0400
173 #define	SLI_MGMT_URL_VALID			0x0800
174 
175 struct sbd_it_data;
176 
177 typedef struct sbd_lu {
178 	struct sbd_lu	*sl_next;
179 	stmf_lu_t	*sl_lu;
180 	uint32_t	sl_alloc_size;
181 
182 	/* Current LU state */
183 	kmutex_t	sl_lock;
184 	uint32_t	sl_flags;
185 	uint8_t		sl_trans_op;
186 	uint8_t		sl_state:7,
187 			sl_state_not_acked:1;
188 
189 	char		*sl_name;		/* refers to meta or data */
190 
191 	/* Metadata */
192 	char		*sl_alias;
193 	char		*sl_meta_filename;	/* If applicable */
194 	char		*sl_mgmt_url;
195 	vnode_t		*sl_meta_vp;
196 	vtype_t		sl_meta_vtype;
197 	uint8_t		sl_device_id[20];	/* 4(hdr) + 16(GUID) */
198 	uint8_t		sl_meta_blocksize_shift; /* Left shift multiplier */
199 	uint8_t		sl_data_blocksize_shift;
200 	uint8_t		sl_data_fs_nbits;
201 	uint8_t		sl_serial_no_size;
202 	uint64_t	sl_total_meta_size;
203 	uint64_t	sl_meta_size_used;
204 	uint8_t		*sl_serial_no;		/* optional */
205 	char		sl_vendor_id[8];
206 	char		sl_product_id[16];
207 	char		sl_revision[4];
208 	uint32_t	sl_data_fname_alloc_size; /* for an explicit alloc */
209 	uint16_t	sl_alias_alloc_size;
210 	uint16_t	sl_mgmt_url_alloc_size;
211 	uint8_t		sl_serial_no_alloc_size;
212 	uint64_t	sl_meta_offset;
213 
214 	/* zfs metadata */
215 	krwlock_t	sl_zfs_meta_lock;
216 	char		*sl_zfs_meta;
217 
218 	/* Backing store */
219 	char		*sl_data_filename;
220 	vnode_t		*sl_data_vp;
221 	vtype_t		sl_data_vtype;
222 	uint64_t	sl_total_data_size;
223 	uint64_t	sl_data_readable_size;	/* read() fails after this */
224 	uint64_t	sl_data_offset;		/* After the metadata,if any */
225 	uint64_t	sl_lu_size;		/* READ CAPACITY size */
226 
227 	struct sbd_it_data	*sl_it_list;
228 	struct sbd_pgr		*sl_pgr;
229 	uint64_t	sl_rs_owner_session_id;
230 } sbd_lu_t;
231 
232 /*
233  * sl_flags
234  */
235 #define	SL_LINKED			    0x00001
236 #define	SL_META_OPENED			    0x00002
237 #define	SL_REGISTERED			    0x00004
238 #define	SL_META_NEEDS_FLUSH		    0x00008
239 #define	SL_DATA_NEEDS_FLUSH		    0x00010
240 #define	SL_VID_VALID			    0x00020
241 #define	SL_PID_VALID			    0x00040
242 #define	SL_REV_VALID			    0x00080
243 #define	SL_WRITE_PROTECTED		    0x00100
244 #define	SL_MEDIA_LOADED			    0x00200
245 #define	SL_LU_HAS_SCSI2_RESERVATION	    0x00400
246 #define	SL_WRITEBACK_CACHE_DISABLE	    0x00800
247 #define	SL_SAVED_WRITE_CACHE_DISABLE	    0x01000
248 #define	SL_MEDIUM_REMOVAL_PREVENTED	    0x02000
249 #define	SL_NO_DATA_DKIOFLUSH		    0x04000
250 #define	SL_SHARED_META			    0x08000
251 #define	SL_ZFS_META			    0x10000
252 #define	SL_WRITEBACK_CACHE_SET_UNSUPPORTED  0x20000
253 #define	SL_FLUSH_ON_DISABLED_WRITECACHE	    0x40000
254 
255 /*
256  * sl_trans_op. LU is undergoing some transition and this field
257  * tells what kind of transition that is.
258  */
259 #define	SL_OP_NONE				0
260 #define	SL_OP_CREATE_REGISTER_LU		1
261 #define	SL_OP_IMPORT_LU				2
262 #define	SL_OP_DELETE_LU				3
263 #define	SL_OP_MODIFY_LU				4
264 #define	SL_OP_LU_PROPS				5
265 
266 sbd_status_t sbd_data_read(sbd_lu_t *sl, uint64_t offset, uint64_t size,
267     uint8_t *buf);
268 sbd_status_t sbd_data_write(sbd_lu_t *sl, uint64_t offset, uint64_t size,
269     uint8_t *buf);
270 stmf_status_t sbd_task_alloc(struct scsi_task *task);
271 void sbd_new_task(struct scsi_task *task, struct stmf_data_buf *initial_dbuf);
272 void sbd_dbuf_xfer_done(struct scsi_task *task, struct stmf_data_buf *dbuf);
273 void sbd_send_status_done(struct scsi_task *task);
274 void sbd_task_free(struct scsi_task *task);
275 stmf_status_t sbd_abort(struct stmf_lu *lu, int abort_cmd, void *arg,
276     uint32_t flags);
277 void sbd_ctl(struct stmf_lu *lu, int cmd, void *arg);
278 stmf_status_t sbd_info(uint32_t cmd, stmf_lu_t *lu, void *arg, uint8_t *buf,
279     uint32_t *bufsizep);
280 sbd_status_t sbd_write_lu_info(sbd_lu_t *sl);
281 sbd_status_t sbd_flush_data_cache(sbd_lu_t *sl, int fsync_done);
282 sbd_status_t sbd_wcd_set(int wcd, sbd_lu_t *sl);
283 void sbd_wcd_get(int *wcd, sbd_lu_t *sl);
284 
285 #ifdef	__cplusplus
286 }
287 #endif
288 
289 #endif /* _STMF_SBD_H */
290