1fcf3ce44SJohn Forte /*
2fcf3ce44SJohn Forte  * CDDL HEADER START
3fcf3ce44SJohn Forte  *
4fcf3ce44SJohn Forte  * The contents of this file are subject to the terms of the
5fcf3ce44SJohn Forte  * Common Development and Distribution License (the "License").
6fcf3ce44SJohn Forte  * You may not use this file except in compliance with the License.
7fcf3ce44SJohn Forte  *
8fcf3ce44SJohn Forte  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9fcf3ce44SJohn Forte  * or http://www.opensolaris.org/os/licensing.
10fcf3ce44SJohn Forte  * See the License for the specific language governing permissions
11fcf3ce44SJohn Forte  * and limitations under the License.
12fcf3ce44SJohn Forte  *
13fcf3ce44SJohn Forte  * When distributing Covered Code, include this CDDL HEADER in each
14fcf3ce44SJohn Forte  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15fcf3ce44SJohn Forte  * If applicable, add the following below this CDDL HEADER, with the
16fcf3ce44SJohn Forte  * fields enclosed by brackets "[]" replaced with your own identifying
17fcf3ce44SJohn Forte  * information: Portions Copyright [yyyy] [name of copyright owner]
18fcf3ce44SJohn Forte  *
19fcf3ce44SJohn Forte  * CDDL HEADER END
20fcf3ce44SJohn Forte  */
21fcf3ce44SJohn Forte /*
22309bed43SCharles Binford - Sun Microsystems - Wichita  * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
23fcf3ce44SJohn Forte  */
24fcf3ce44SJohn Forte 
25fcf3ce44SJohn Forte #ifndef	_SBD_IMPL_H
26fcf3ce44SJohn Forte #define	_SBD_IMPL_H
27fcf3ce44SJohn Forte 
28fcf3ce44SJohn Forte #ifdef	__cplusplus
29fcf3ce44SJohn Forte extern "C" {
30fcf3ce44SJohn Forte #endif
31fcf3ce44SJohn Forte 
32fcf3ce44SJohn Forte struct register_lu_cmd;
33fcf3ce44SJohn Forte struct modify_lu_cmd;
34fcf3ce44SJohn Forte struct sbd_lu_attr;
35fcf3ce44SJohn Forte struct sbd_it_data;
36fcf3ce44SJohn Forte 
37fcf3ce44SJohn Forte /*
38fcf3ce44SJohn Forte  * sms endianess
39fcf3ce44SJohn Forte  */
40fcf3ce44SJohn Forte #define	SMS_BIG_ENDIAN			0x00
41fcf3ce44SJohn Forte #define	SMS_LITTLE_ENDIAN		0xFF
42fcf3ce44SJohn Forte 
43fcf3ce44SJohn Forte #ifdef	_BIG_ENDIAN
44fcf3ce44SJohn Forte #define	SMS_DATA_ORDER	SMS_BIG_ENDIAN
45fcf3ce44SJohn Forte #else
46fcf3ce44SJohn Forte #define	SMS_DATA_ORDER	SMS_LITTLE_ENDIAN
47fcf3ce44SJohn Forte #endif
48fcf3ce44SJohn Forte 
498fe96085Stim szeto /* Test if one of the BitOrder definitions exists */
508fe96085Stim szeto #ifdef _BIT_FIELDS_LTOH
518fe96085Stim szeto #elif defined(_BIT_FIELDS_HTOL)
528fe96085Stim szeto #else
538fe96085Stim szeto #error  One of _BIT_FIELDS_LTOH or _BIT_FIELDS_HTOL must be defined
548fe96085Stim szeto #endif
558fe96085Stim szeto 
56fcf3ce44SJohn Forte #define	SBD_V0_MAGIC	0x53554e4d4943524f
57fcf3ce44SJohn Forte #define	SBD_MAGIC	0x53554e5342444c55
58fcf3ce44SJohn Forte 
59fcf3ce44SJohn Forte typedef struct sbd_v0_meta_start {
60fcf3ce44SJohn Forte 	uint64_t		sm_magic;	/* SBD_MAGIC */
61fcf3ce44SJohn Forte 	uint64_t		sm_meta_size;	/* Includes everything */
62fcf3ce44SJohn Forte } sbd_v0_meta_start_t;
63fcf3ce44SJohn Forte 
64fcf3ce44SJohn Forte typedef struct sbd_meta_start {
65fcf3ce44SJohn Forte 	uint64_t		sm_magic;
66fcf3ce44SJohn Forte 	uint64_t		sm_meta_size;
67fcf3ce44SJohn Forte 	uint64_t		sm_meta_size_used;
68fcf3ce44SJohn Forte 	uint64_t		sm_rsvd1;	/* Defaults to zero */
69fcf3ce44SJohn Forte 	uint64_t		sm_rsvd2;
70fcf3ce44SJohn Forte 	uint16_t		sm_ver_major;
71fcf3ce44SJohn Forte 	uint16_t		sm_ver_minor;
72fcf3ce44SJohn Forte 	uint16_t		sm_ver_subminor;
73fcf3ce44SJohn Forte 	uint8_t			sm_flags;	/* None at this moment */
74fcf3ce44SJohn Forte 	uint8_t			sm_chksum;
75fcf3ce44SJohn Forte } sbd_meta_start_t;
76fcf3ce44SJohn Forte 
77fcf3ce44SJohn Forte typedef struct sm_v0_section_hdr {
78fcf3ce44SJohn Forte 	uint64_t	sms_offset;	/* Offset of this section */
79fcf3ce44SJohn Forte 	uint64_t	sms_size;	/* Includes the header and padding */
80fcf3ce44SJohn Forte 	uint16_t	sms_id;		/* Section identifier */
81fcf3ce44SJohn Forte 	uint16_t	sms_padding;	/* For alignment */
82fcf3ce44SJohn Forte 	uint32_t	sms_seqno;	/* For multiple sections with same ID */
83fcf3ce44SJohn Forte 	uint8_t		sms_hdr_data_order; /* 0x00 or 0xff */
84fcf3ce44SJohn Forte 	uint8_t		sms_payload_data_order;
85fcf3ce44SJohn Forte 	uint16_t	rsvd2;
86fcf3ce44SJohn Forte 	uint32_t	rsvd3;		/* 8 byte align */
87fcf3ce44SJohn Forte } sm_v0_section_hdr_t;
88fcf3ce44SJohn Forte 
898fe96085Stim szeto /*
908fe96085Stim szeto  * sbd_it_flags
918fe96085Stim szeto  */
928fe96085Stim szeto #define	SBD_IT_HAS_SCSI2_RESERVATION	0x0001
938fe96085Stim szeto #define	SBD_IT_PGR_REGISTERED		0x0002
948fe96085Stim szeto #define	SBD_IT_PGR_EXCLUSIVE_RSV_HOLDER	0x0004
958fe96085Stim szeto #define	SBD_IT_PGR_CHECK_FLAG		0x0008
968fe96085Stim szeto 
978fe96085Stim szeto /*
988fe96085Stim szeto  * PGR flags
998fe96085Stim szeto  */
1008fe96085Stim szeto #define	SBD_PGR_APTPL			0x01
1018fe96085Stim szeto #define	SBD_PGR_RSVD_ONE		0x02
1028fe96085Stim szeto #define	SBD_PGR_RSVD_ALL_REGISTRANTS	0x04
1038fe96085Stim szeto #define	SBD_PGR_ALL_KEYS_HAS_IT		0x08
1048fe96085Stim szeto 
1058fe96085Stim szeto #define	SBD_PGR_RSVD(pgr)	(((pgr)->pgr_flags) & (SBD_PGR_RSVD_ONE | \
1068fe96085Stim szeto 					SBD_PGR_RSVD_ALL_REGISTRANTS))
1078fe96085Stim szeto #define	SBD_PGR_RSVD_NONE(pgr)	(!(SBD_PGR_RSVD(pgr)))
108fcf3ce44SJohn Forte 
109fcf3ce44SJohn Forte /*
1108fe96085Stim szeto  * PGR key flags
111fcf3ce44SJohn Forte  */
1128fe96085Stim szeto #define	SBD_PGR_KEY_ALL_TG_PT		0x01
113*716c1805SNattuvetty Bhavyan #define	SBD_PGR_KEY_TPT_ID_FLAG		0x02
1148fe96085Stim szeto 
1158fe96085Stim szeto typedef struct sbd_pgr_key_info {
1168fe96085Stim szeto 	uint64_t	pgr_key;
1178fe96085Stim szeto 	uint16_t	pgr_key_lpt_len;
1188fe96085Stim szeto 	uint16_t	pgr_key_rpt_len;
1198fe96085Stim szeto 	uint8_t		pgr_key_flags;
120*716c1805SNattuvetty Bhavyan 	uint8_t		pgr_key_it[1];	/* order:- initiator info followed by */
121*716c1805SNattuvetty Bhavyan 					/* scsi_devid_desc of local port */
1228fe96085Stim szeto } sbd_pgr_key_info_t;
1238fe96085Stim szeto 
1248fe96085Stim szeto typedef struct sbd_pgr_info {
1258fe96085Stim szeto 	sm_section_hdr_t	pgr_sms_header;
1268fe96085Stim szeto 	uint32_t		pgr_rsvholder_indx;
1278fe96085Stim szeto 	uint32_t		pgr_numkeys;
1288fe96085Stim szeto 	uint8_t			pgr_flags;
1298fe96085Stim szeto 	uint8_t			pgr_data_order;
1308fe96085Stim szeto #ifdef _BIT_FIELDS_LTOH
1318fe96085Stim szeto 	uint8_t			pgr_rsv_type:4,
1328fe96085Stim szeto 				pgr_rsv_scope:4;
1338fe96085Stim szeto #else
1348fe96085Stim szeto 	uint8_t			pgr_rsv_scope:4,
1358fe96085Stim szeto 				pgr_rsv_type:4;
1368fe96085Stim szeto #endif
1378fe96085Stim szeto 	uint8_t			rsvd[5];	/* 8 byte boundary */
1388fe96085Stim szeto 
1398fe96085Stim szeto } sbd_pgr_info_t;
1408fe96085Stim szeto 
1418fe96085Stim szeto typedef struct sbd_pgr_key {
1428fe96085Stim szeto 	uint64_t		pgr_key;
1438fe96085Stim szeto 	uint16_t		pgr_key_lpt_len;
1448fe96085Stim szeto 	uint16_t		pgr_key_rpt_len;
1458fe96085Stim szeto 	uint8_t			pgr_key_flags;
1468fe96085Stim szeto 	struct scsi_devid_desc	*pgr_key_lpt_id;
147*716c1805SNattuvetty Bhavyan 	struct scsi_transport_id *pgr_key_rpt_id;
1488fe96085Stim szeto 	struct sbd_it_data	*pgr_key_it;
1498fe96085Stim szeto 	struct sbd_pgr_key	*pgr_key_next;
1508fe96085Stim szeto 	struct sbd_pgr_key	*pgr_key_prev;
1518fe96085Stim szeto } sbd_pgr_key_t;
1528fe96085Stim szeto 
1538fe96085Stim szeto typedef struct sbd_pgr {
1548fe96085Stim szeto 	sbd_pgr_key_t		*pgr_keylist;
1558fe96085Stim szeto 	sbd_pgr_key_t		*pgr_rsvholder;
1568fe96085Stim szeto 	uint32_t		pgr_PRgeneration; /* PGR PRgeneration value */
1578fe96085Stim szeto 	uint8_t			pgr_flags;	/* PGR flags (eg: APTPL)  */
1588fe96085Stim szeto 	uint8_t			pgr_rsv_type:4,
1598fe96085Stim szeto 				pgr_rsv_scope:4;
1608fe96085Stim szeto 	krwlock_t		pgr_lock; /* Lock order pgr_lock, sl_lock */
1618fe96085Stim szeto } sbd_pgr_t;
1628fe96085Stim szeto 
163fcf3ce44SJohn Forte 
164fcf3ce44SJohn Forte typedef struct sbd_v0_lu_info {
165fcf3ce44SJohn Forte 	sm_v0_section_hdr_t	sli_sms_header;
166fcf3ce44SJohn Forte 	uint64_t		sli_total_store_size;
167fcf3ce44SJohn Forte 	uint64_t		sli_total_meta_size;
168fcf3ce44SJohn Forte 	uint64_t		rsvd0;
169fcf3ce44SJohn Forte 	uint64_t		sli_lu_data_offset;
170fcf3ce44SJohn Forte 	uint64_t		sli_lu_data_size;
171fcf3ce44SJohn Forte 	uint64_t		rsvd1;
172fcf3ce44SJohn Forte 	uint32_t		sli_flags;
173fcf3ce44SJohn Forte 	uint16_t		sli_blocksize;
174fcf3ce44SJohn Forte 	uint16_t		rsvd2;
175fcf3ce44SJohn Forte 	uint8_t			sli_lu_devid[20];
176fcf3ce44SJohn Forte 	uint32_t		rsvd3;
177fcf3ce44SJohn Forte } sbd_v0_lu_info_t;
178fcf3ce44SJohn Forte 
179fcf3ce44SJohn Forte typedef struct sbd_lu_info {
180fcf3ce44SJohn Forte 	sm_section_hdr_t	sli_sms_header;
181fcf3ce44SJohn Forte 	uint64_t		sli_total_store_size;
182fcf3ce44SJohn Forte 	uint64_t		sli_total_meta_size;
183fcf3ce44SJohn Forte 	uint64_t		sli_lu_data_offset;
184fcf3ce44SJohn Forte 	uint64_t		sli_lu_data_size;
185fcf3ce44SJohn Forte 	uint32_t		sli_flags;
186fcf3ce44SJohn Forte 	uint16_t		sli_blocksize;
187fcf3ce44SJohn Forte 	uint8_t			sli_data_order;
188fcf3ce44SJohn Forte 	uint8_t			rsvd1;
189fcf3ce44SJohn Forte 	uint8_t			sli_lu_devid[20];
190fcf3ce44SJohn Forte 	uint32_t		rsvd2;
191fcf3ce44SJohn Forte } sbd_lu_info_t;
192fcf3ce44SJohn Forte 
193fcf3ce44SJohn Forte /*
194fcf3ce44SJohn Forte  * sl_flags
195fcf3ce44SJohn Forte  */
196fcf3ce44SJohn Forte #define	SBD_LU_HAS_SCSI2_RESERVATION	0x0001
197fcf3ce44SJohn Forte 
198fcf3ce44SJohn Forte typedef struct sbd_cmd {
199fcf3ce44SJohn Forte 	uint8_t		flags;
200fcf3ce44SJohn Forte 	uint8_t		nbufs;
201fcf3ce44SJohn Forte 	uint16_t	cmd_type;	/* Type of command */
202fcf3ce44SJohn Forte 	uint32_t	rsvd2;
203fcf3ce44SJohn Forte 	uint64_t	addr;		/* current */
204fcf3ce44SJohn Forte 	uint32_t	len;		/* len left */
205fcf3ce44SJohn Forte 	uint32_t	current_ro;	/* running relative offset */
206fcf3ce44SJohn Forte } sbd_cmd_t;
207fcf3ce44SJohn Forte 
208fcf3ce44SJohn Forte /*
209fcf3ce44SJohn Forte  * flags for sbd_cmd
210fcf3ce44SJohn Forte  */
211fcf3ce44SJohn Forte #define	SBD_SCSI_CMD_ACTIVE		0x01
212fcf3ce44SJohn Forte #define	SBD_SCSI_CMD_ABORT_REQUESTED	0x02
213fcf3ce44SJohn Forte #define	SBD_SCSI_CMD_XFER_FAIL		0x04
214309bed43SCharles Binford - Sun Microsystems - Wichita #define	SBD_SCSI_CMD_SYNC_WRITE		0x08
215fcf3ce44SJohn Forte 
216fcf3ce44SJohn Forte /*
217fcf3ce44SJohn Forte  * cmd types
218fcf3ce44SJohn Forte  */
219fcf3ce44SJohn Forte #define	SBD_CMD_SCSI_READ	0x01
220fcf3ce44SJohn Forte #define	SBD_CMD_SCSI_WRITE	0x02
221fcf3ce44SJohn Forte #define	SBD_CMD_SMALL_READ	0x03
222fcf3ce44SJohn Forte #define	SBD_CMD_SMALL_WRITE	0x04
2238fe96085Stim szeto #define	SBD_CMD_SCSI_PR_OUT	0x05
224fcf3ce44SJohn Forte 
225fcf3ce44SJohn Forte typedef struct sbd_it_data {
226fcf3ce44SJohn Forte 	struct sbd_it_data	*sbd_it_next;
227fcf3ce44SJohn Forte 	uint64_t		sbd_it_session_id;
228fcf3ce44SJohn Forte 	uint8_t			sbd_it_lun[8];
229fcf3ce44SJohn Forte 	uint8_t			sbd_it_ua_conditions;
230fcf3ce44SJohn Forte 	uint8_t			sbd_it_flags;
2318fe96085Stim szeto 	sbd_pgr_key_t		*pgr_key_ptr;
232fcf3ce44SJohn Forte } sbd_it_data_t;
233fcf3ce44SJohn Forte 
23445039663SJohn Forte typedef struct sbd_create_standby_lu {
23545039663SJohn Forte 	uint32_t	stlu_meta_fname_size;
23645039663SJohn Forte 	uint32_t	stlu_rsvd;
23745039663SJohn Forte 	uint8_t		stlu_guid[16];
23845039663SJohn Forte 	char		stlu_meta_fname[8];
23945039663SJohn Forte } sbd_create_standby_lu_t;
24045039663SJohn Forte 
241fcf3ce44SJohn Forte /*
242fcf3ce44SJohn Forte  * Different UA conditions
243fcf3ce44SJohn Forte  */
24445039663SJohn Forte #define	SBD_UA_POR			    0x01
24545039663SJohn Forte #define	SBD_UA_CAPACITY_CHANGED		    0x02
24645039663SJohn Forte #define	SBD_UA_MODE_PARAMETERS_CHANGED	    0x04
24745039663SJohn Forte #define	SBD_UA_ACCESS_STATE_TRANSITION	    0x08
24845039663SJohn Forte #define	SBD_UA_REGISTRATIONS_PREEMPTED	    0x10
24945039663SJohn Forte #define	SBD_UA_RESERVATIONS_PREEMPTED	    0x20
25045039663SJohn Forte #define	SBD_UA_RESERVATIONS_RELEASED	    0x40
25145039663SJohn Forte #define	SBD_UA_ASYMMETRIC_ACCESS_CHANGED    0x80
252fcf3ce44SJohn Forte 
253fcf3ce44SJohn Forte /*
254fcf3ce44SJohn Forte  * sbd_it_flags
255fcf3ce44SJohn Forte  */
2568fe96085Stim szeto #define	SBD_IT_HAS_SCSI2_RESERVATION	0x0001
257fcf3ce44SJohn Forte 
2583fb517f7SJames Moore /*
2593fb517f7SJames Moore  * dbuf private data needed for direct zvol data transfers
2603fb517f7SJames Moore  *
2613fb517f7SJames Moore  * To further isolate the zvol knowledge, the object handles
2623fb517f7SJames Moore  * needed to call into zfs are declared void * here.
2633fb517f7SJames Moore  */
2643fb517f7SJames Moore 
2653fb517f7SJames Moore typedef struct sbd_zvol_io {
2663fb517f7SJames Moore 	uint64_t	zvio_offset;	/* offset into volume */
2673fb517f7SJames Moore 	int		zvio_flags;	/* flags */
2683fb517f7SJames Moore 	void 		*zvio_dbp;	/* array of dmu buffers */
2693fb517f7SJames Moore 	void		*zvio_abp;	/* array of arc buffers */
2703fb517f7SJames Moore 	uio_t		*zvio_uio;	/* for copy operations */
2713fb517f7SJames Moore } sbd_zvol_io_t;
2723fb517f7SJames Moore 
2733fb517f7SJames Moore #define	ZVIO_DEFAULT	0
2743fb517f7SJames Moore #define	ZVIO_COMMIT	1
2753fb517f7SJames Moore #define	ZVIO_ABORT	2
2763fb517f7SJames Moore #define	ZVIO_SYNC	4
2773fb517f7SJames Moore #define	ZVIO_ASYNC	8
2783fb517f7SJames Moore 
2793fb517f7SJames Moore /*
2803fb517f7SJames Moore  * zvol data path functions
2813fb517f7SJames Moore  */
2823fb517f7SJames Moore int sbd_zvol_get_volume_params(sbd_lu_t *sl);
2833fb517f7SJames Moore uint32_t sbd_zvol_numsegs(sbd_lu_t *sl, uint64_t off, uint32_t len);
2843fb517f7SJames Moore int sbd_zvol_alloc_read_bufs(sbd_lu_t *sl, stmf_data_buf_t *dbuf);
2853fb517f7SJames Moore void sbd_zvol_rele_read_bufs(sbd_lu_t *sl, stmf_data_buf_t *dbuf);
2863fb517f7SJames Moore int sbd_zvol_alloc_write_bufs(sbd_lu_t *sl, stmf_data_buf_t *dbuf);
2873fb517f7SJames Moore void sbd_zvol_rele_write_bufs_abort(sbd_lu_t *sl, stmf_data_buf_t *dbuf);
2883fb517f7SJames Moore int sbd_zvol_rele_write_bufs(sbd_lu_t *sl, stmf_data_buf_t *dbuf);
2893fb517f7SJames Moore int sbd_zvol_copy_read(sbd_lu_t *sl, uio_t *uio);
2903fb517f7SJames Moore int sbd_zvol_copy_write(sbd_lu_t *sl, uio_t *uio, int flags);
2913fb517f7SJames Moore 
292fcf3ce44SJohn Forte stmf_status_t sbd_task_alloc(struct scsi_task *task);
293fcf3ce44SJohn Forte void sbd_new_task(struct scsi_task *task, struct stmf_data_buf *initial_dbuf);
294fcf3ce44SJohn Forte void sbd_dbuf_xfer_done(struct scsi_task *task, struct stmf_data_buf *dbuf);
295fcf3ce44SJohn Forte void sbd_send_status_done(struct scsi_task *task);
296fcf3ce44SJohn Forte void sbd_task_free(struct scsi_task *task);
297fcf3ce44SJohn Forte stmf_status_t sbd_abort(struct stmf_lu *lu, int abort_cmd, void *arg,
298fcf3ce44SJohn Forte 							uint32_t flags);
2993fb517f7SJames Moore void sbd_dbuf_free(struct scsi_task *task, struct stmf_data_buf *dbuf);
300fcf3ce44SJohn Forte void sbd_ctl(struct stmf_lu *lu, int cmd, void *arg);
301fcf3ce44SJohn Forte stmf_status_t sbd_info(uint32_t cmd, stmf_lu_t *lu, void *arg,
302fcf3ce44SJohn Forte 				uint8_t *buf, uint32_t *bufsizep);
303fcf3ce44SJohn Forte 
304fcf3ce44SJohn Forte #ifdef	__cplusplus
305fcf3ce44SJohn Forte }
306fcf3ce44SJohn Forte #endif
307fcf3ce44SJohn Forte 
308fcf3ce44SJohn Forte #endif /* _SBD_IMPL_H */
309