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 /*
22*309bed43SCharles 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
1138fe96085Stim szeto 
1148fe96085Stim szeto typedef struct sbd_pgr_key_info {
1158fe96085Stim szeto 	uint64_t	pgr_key;
1168fe96085Stim szeto 	uint16_t	pgr_key_lpt_len;
1178fe96085Stim szeto 	uint16_t	pgr_key_rpt_len;
1188fe96085Stim szeto 	uint8_t		pgr_key_flags;
1198fe96085Stim szeto 	uint8_t		pgr_key_it[1];	/* devid_desc of initiator will be */
1208fe96085Stim szeto 					/* followed by devid_desc of target */
1218fe96085Stim szeto } sbd_pgr_key_info_t;
1228fe96085Stim szeto 
1238fe96085Stim szeto typedef struct sbd_pgr_info {
1248fe96085Stim szeto 	sm_section_hdr_t	pgr_sms_header;
1258fe96085Stim szeto 	uint32_t		pgr_rsvholder_indx;
1268fe96085Stim szeto 	uint32_t		pgr_numkeys;
1278fe96085Stim szeto 	uint8_t			pgr_flags;
1288fe96085Stim szeto 	uint8_t			pgr_data_order;
1298fe96085Stim szeto #ifdef _BIT_FIELDS_LTOH
1308fe96085Stim szeto 	uint8_t			pgr_rsv_type:4,
1318fe96085Stim szeto 				pgr_rsv_scope:4;
1328fe96085Stim szeto #else
1338fe96085Stim szeto 	uint8_t			pgr_rsv_scope:4,
1348fe96085Stim szeto 				pgr_rsv_type:4;
1358fe96085Stim szeto #endif
1368fe96085Stim szeto 	uint8_t			rsvd[5];	/* 8 byte boundary */
1378fe96085Stim szeto 
1388fe96085Stim szeto } sbd_pgr_info_t;
1398fe96085Stim szeto 
1408fe96085Stim szeto typedef struct sbd_pgr_key {
1418fe96085Stim szeto 	uint64_t		pgr_key;
1428fe96085Stim szeto 	uint16_t		pgr_key_lpt_len;
1438fe96085Stim szeto 	uint16_t		pgr_key_rpt_len;
1448fe96085Stim szeto 	uint8_t			pgr_key_flags;
1458fe96085Stim szeto 	struct scsi_devid_desc	*pgr_key_lpt_id;
1468fe96085Stim szeto 	struct scsi_devid_desc	*pgr_key_rpt_id;
1478fe96085Stim szeto 	struct sbd_it_data	*pgr_key_it;
1488fe96085Stim szeto 	struct sbd_pgr_key	*pgr_key_next;
1498fe96085Stim szeto 	struct sbd_pgr_key	*pgr_key_prev;
1508fe96085Stim szeto } sbd_pgr_key_t;
1518fe96085Stim szeto 
1528fe96085Stim szeto typedef struct sbd_pgr {
1538fe96085Stim szeto 	sbd_pgr_key_t		*pgr_keylist;
1548fe96085Stim szeto 	sbd_pgr_key_t		*pgr_rsvholder;
1558fe96085Stim szeto 	uint32_t		pgr_PRgeneration; /* PGR PRgeneration value */
1568fe96085Stim szeto 	uint8_t			pgr_flags;	/* PGR flags (eg: APTPL)  */
1578fe96085Stim szeto 	uint8_t			pgr_rsv_type:4,
1588fe96085Stim szeto 				pgr_rsv_scope:4;
1598fe96085Stim szeto 	krwlock_t		pgr_lock; /* Lock order pgr_lock, sl_lock */
1608fe96085Stim szeto } sbd_pgr_t;
1618fe96085Stim szeto 
162fcf3ce44SJohn Forte 
163fcf3ce44SJohn Forte typedef struct sbd_v0_lu_info {
164fcf3ce44SJohn Forte 	sm_v0_section_hdr_t	sli_sms_header;
165fcf3ce44SJohn Forte 	uint64_t		sli_total_store_size;
166fcf3ce44SJohn Forte 	uint64_t		sli_total_meta_size;
167fcf3ce44SJohn Forte 	uint64_t		rsvd0;
168fcf3ce44SJohn Forte 	uint64_t		sli_lu_data_offset;
169fcf3ce44SJohn Forte 	uint64_t		sli_lu_data_size;
170fcf3ce44SJohn Forte 	uint64_t		rsvd1;
171fcf3ce44SJohn Forte 	uint32_t		sli_flags;
172fcf3ce44SJohn Forte 	uint16_t		sli_blocksize;
173fcf3ce44SJohn Forte 	uint16_t		rsvd2;
174fcf3ce44SJohn Forte 	uint8_t			sli_lu_devid[20];
175fcf3ce44SJohn Forte 	uint32_t		rsvd3;
176fcf3ce44SJohn Forte } sbd_v0_lu_info_t;
177fcf3ce44SJohn Forte 
178fcf3ce44SJohn Forte typedef struct sbd_lu_info {
179fcf3ce44SJohn Forte 	sm_section_hdr_t	sli_sms_header;
180fcf3ce44SJohn Forte 	uint64_t		sli_total_store_size;
181fcf3ce44SJohn Forte 	uint64_t		sli_total_meta_size;
182fcf3ce44SJohn Forte 	uint64_t		sli_lu_data_offset;
183fcf3ce44SJohn Forte 	uint64_t		sli_lu_data_size;
184fcf3ce44SJohn Forte 	uint32_t		sli_flags;
185fcf3ce44SJohn Forte 	uint16_t		sli_blocksize;
186fcf3ce44SJohn Forte 	uint8_t			sli_data_order;
187fcf3ce44SJohn Forte 	uint8_t			rsvd1;
188fcf3ce44SJohn Forte 	uint8_t			sli_lu_devid[20];
189fcf3ce44SJohn Forte 	uint32_t		rsvd2;
190fcf3ce44SJohn Forte } sbd_lu_info_t;
191fcf3ce44SJohn Forte 
192fcf3ce44SJohn Forte /*
193fcf3ce44SJohn Forte  * sl_flags
194fcf3ce44SJohn Forte  */
195fcf3ce44SJohn Forte #define	SBD_LU_HAS_SCSI2_RESERVATION	0x0001
196fcf3ce44SJohn Forte 
197fcf3ce44SJohn Forte typedef struct sbd_cmd {
198fcf3ce44SJohn Forte 	uint8_t		flags;
199fcf3ce44SJohn Forte 	uint8_t		nbufs;
200fcf3ce44SJohn Forte 	uint16_t	cmd_type;	/* Type of command */
201fcf3ce44SJohn Forte 	uint32_t	rsvd2;
202fcf3ce44SJohn Forte 	uint64_t	addr;		/* current */
203fcf3ce44SJohn Forte 	uint32_t	len;		/* len left */
204fcf3ce44SJohn Forte 	uint32_t	current_ro;	/* running relative offset */
205fcf3ce44SJohn Forte } sbd_cmd_t;
206fcf3ce44SJohn Forte 
207fcf3ce44SJohn Forte /*
208fcf3ce44SJohn Forte  * flags for sbd_cmd
209fcf3ce44SJohn Forte  */
210fcf3ce44SJohn Forte #define	SBD_SCSI_CMD_ACTIVE		0x01
211fcf3ce44SJohn Forte #define	SBD_SCSI_CMD_ABORT_REQUESTED	0x02
212fcf3ce44SJohn Forte #define	SBD_SCSI_CMD_XFER_FAIL		0x04
213*309bed43SCharles Binford - Sun Microsystems - Wichita #define	SBD_SCSI_CMD_SYNC_WRITE		0x08
214fcf3ce44SJohn Forte 
215fcf3ce44SJohn Forte /*
216fcf3ce44SJohn Forte  * cmd types
217fcf3ce44SJohn Forte  */
218fcf3ce44SJohn Forte #define	SBD_CMD_SCSI_READ	0x01
219fcf3ce44SJohn Forte #define	SBD_CMD_SCSI_WRITE	0x02
220fcf3ce44SJohn Forte #define	SBD_CMD_SMALL_READ	0x03
221fcf3ce44SJohn Forte #define	SBD_CMD_SMALL_WRITE	0x04
2228fe96085Stim szeto #define	SBD_CMD_SCSI_PR_OUT	0x05
223fcf3ce44SJohn Forte 
224fcf3ce44SJohn Forte typedef struct sbd_it_data {
225fcf3ce44SJohn Forte 	struct sbd_it_data	*sbd_it_next;
226fcf3ce44SJohn Forte 	uint64_t		sbd_it_session_id;
227fcf3ce44SJohn Forte 	uint8_t			sbd_it_lun[8];
228fcf3ce44SJohn Forte 	uint8_t			sbd_it_ua_conditions;
229fcf3ce44SJohn Forte 	uint8_t			sbd_it_flags;
2308fe96085Stim szeto 	sbd_pgr_key_t		*pgr_key_ptr;
231fcf3ce44SJohn Forte } sbd_it_data_t;
232fcf3ce44SJohn Forte 
23345039663SJohn Forte typedef struct sbd_create_standby_lu {
23445039663SJohn Forte 	uint32_t	stlu_meta_fname_size;
23545039663SJohn Forte 	uint32_t	stlu_rsvd;
23645039663SJohn Forte 	uint8_t		stlu_guid[16];
23745039663SJohn Forte 	char		stlu_meta_fname[8];
23845039663SJohn Forte } sbd_create_standby_lu_t;
23945039663SJohn Forte 
240fcf3ce44SJohn Forte /*
241fcf3ce44SJohn Forte  * Different UA conditions
242fcf3ce44SJohn Forte  */
24345039663SJohn Forte #define	SBD_UA_POR			    0x01
24445039663SJohn Forte #define	SBD_UA_CAPACITY_CHANGED		    0x02
24545039663SJohn Forte #define	SBD_UA_MODE_PARAMETERS_CHANGED	    0x04
24645039663SJohn Forte #define	SBD_UA_ACCESS_STATE_TRANSITION	    0x08
24745039663SJohn Forte #define	SBD_UA_REGISTRATIONS_PREEMPTED	    0x10
24845039663SJohn Forte #define	SBD_UA_RESERVATIONS_PREEMPTED	    0x20
24945039663SJohn Forte #define	SBD_UA_RESERVATIONS_RELEASED	    0x40
25045039663SJohn Forte #define	SBD_UA_ASYMMETRIC_ACCESS_CHANGED    0x80
251fcf3ce44SJohn Forte 
252fcf3ce44SJohn Forte /*
253fcf3ce44SJohn Forte  * sbd_it_flags
254fcf3ce44SJohn Forte  */
2558fe96085Stim szeto #define	SBD_IT_HAS_SCSI2_RESERVATION	0x0001
256fcf3ce44SJohn Forte 
257fcf3ce44SJohn Forte stmf_status_t sbd_task_alloc(struct scsi_task *task);
258fcf3ce44SJohn Forte void sbd_new_task(struct scsi_task *task, struct stmf_data_buf *initial_dbuf);
259fcf3ce44SJohn Forte void sbd_dbuf_xfer_done(struct scsi_task *task, struct stmf_data_buf *dbuf);
260fcf3ce44SJohn Forte void sbd_send_status_done(struct scsi_task *task);
261fcf3ce44SJohn Forte void sbd_task_free(struct scsi_task *task);
262fcf3ce44SJohn Forte stmf_status_t sbd_abort(struct stmf_lu *lu, int abort_cmd, void *arg,
263fcf3ce44SJohn Forte 							uint32_t flags);
264fcf3ce44SJohn Forte void sbd_ctl(struct stmf_lu *lu, int cmd, void *arg);
265fcf3ce44SJohn Forte stmf_status_t sbd_info(uint32_t cmd, stmf_lu_t *lu, void *arg,
266fcf3ce44SJohn Forte 				uint8_t *buf, uint32_t *bufsizep);
267fcf3ce44SJohn Forte 
268fcf3ce44SJohn Forte #ifdef	__cplusplus
269fcf3ce44SJohn Forte }
270fcf3ce44SJohn Forte #endif
271fcf3ce44SJohn Forte 
272fcf3ce44SJohn Forte #endif /* _SBD_IMPL_H */
273