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*8fe96085Stim szeto  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
23fcf3ce44SJohn Forte  * Use is subject to license terms.
24fcf3ce44SJohn Forte  */
25fcf3ce44SJohn Forte 
26fcf3ce44SJohn Forte #ifndef	_SBD_IMPL_H
27fcf3ce44SJohn Forte #define	_SBD_IMPL_H
28fcf3ce44SJohn Forte 
29fcf3ce44SJohn Forte #ifdef	__cplusplus
30fcf3ce44SJohn Forte extern "C" {
31fcf3ce44SJohn Forte #endif
32fcf3ce44SJohn Forte 
33fcf3ce44SJohn Forte struct register_lu_cmd;
34fcf3ce44SJohn Forte struct modify_lu_cmd;
35fcf3ce44SJohn Forte struct sbd_lu_attr;
36fcf3ce44SJohn Forte struct sbd_it_data;
37fcf3ce44SJohn Forte 
38fcf3ce44SJohn Forte /*
39fcf3ce44SJohn Forte  * sms endianess
40fcf3ce44SJohn Forte  */
41fcf3ce44SJohn Forte #define	SMS_BIG_ENDIAN			0x00
42fcf3ce44SJohn Forte #define	SMS_LITTLE_ENDIAN		0xFF
43fcf3ce44SJohn Forte 
44fcf3ce44SJohn Forte #ifdef	_BIG_ENDIAN
45fcf3ce44SJohn Forte #define	SMS_DATA_ORDER	SMS_BIG_ENDIAN
46fcf3ce44SJohn Forte #else
47fcf3ce44SJohn Forte #define	SMS_DATA_ORDER	SMS_LITTLE_ENDIAN
48fcf3ce44SJohn Forte #endif
49fcf3ce44SJohn Forte 
50*8fe96085Stim szeto /* Test if one of the BitOrder definitions exists */
51*8fe96085Stim szeto #ifdef _BIT_FIELDS_LTOH
52*8fe96085Stim szeto #elif defined(_BIT_FIELDS_HTOL)
53*8fe96085Stim szeto #else
54*8fe96085Stim szeto #error  One of _BIT_FIELDS_LTOH or _BIT_FIELDS_HTOL must be defined
55*8fe96085Stim szeto #endif
56*8fe96085Stim szeto 
57fcf3ce44SJohn Forte #define	SBD_V0_MAGIC	0x53554e4d4943524f
58fcf3ce44SJohn Forte #define	SBD_MAGIC	0x53554e5342444c55
59fcf3ce44SJohn Forte 
60fcf3ce44SJohn Forte typedef struct sbd_v0_meta_start {
61fcf3ce44SJohn Forte 	uint64_t		sm_magic;	/* SBD_MAGIC */
62fcf3ce44SJohn Forte 	uint64_t		sm_meta_size;	/* Includes everything */
63fcf3ce44SJohn Forte } sbd_v0_meta_start_t;
64fcf3ce44SJohn Forte 
65fcf3ce44SJohn Forte typedef struct sbd_meta_start {
66fcf3ce44SJohn Forte 	uint64_t		sm_magic;
67fcf3ce44SJohn Forte 	uint64_t		sm_meta_size;
68fcf3ce44SJohn Forte 	uint64_t		sm_meta_size_used;
69fcf3ce44SJohn Forte 	uint64_t		sm_rsvd1;	/* Defaults to zero */
70fcf3ce44SJohn Forte 	uint64_t		sm_rsvd2;
71fcf3ce44SJohn Forte 	uint16_t		sm_ver_major;
72fcf3ce44SJohn Forte 	uint16_t		sm_ver_minor;
73fcf3ce44SJohn Forte 	uint16_t		sm_ver_subminor;
74fcf3ce44SJohn Forte 	uint8_t			sm_flags;	/* None at this moment */
75fcf3ce44SJohn Forte 	uint8_t			sm_chksum;
76fcf3ce44SJohn Forte } sbd_meta_start_t;
77fcf3ce44SJohn Forte 
78fcf3ce44SJohn Forte typedef struct sm_v0_section_hdr {
79fcf3ce44SJohn Forte 	uint64_t	sms_offset;	/* Offset of this section */
80fcf3ce44SJohn Forte 	uint64_t	sms_size;	/* Includes the header and padding */
81fcf3ce44SJohn Forte 	uint16_t	sms_id;		/* Section identifier */
82fcf3ce44SJohn Forte 	uint16_t	sms_padding;	/* For alignment */
83fcf3ce44SJohn Forte 	uint32_t	sms_seqno;	/* For multiple sections with same ID */
84fcf3ce44SJohn Forte 	uint8_t		sms_hdr_data_order; /* 0x00 or 0xff */
85fcf3ce44SJohn Forte 	uint8_t		sms_payload_data_order;
86fcf3ce44SJohn Forte 	uint16_t	rsvd2;
87fcf3ce44SJohn Forte 	uint32_t	rsvd3;		/* 8 byte align */
88fcf3ce44SJohn Forte } sm_v0_section_hdr_t;
89fcf3ce44SJohn Forte 
90*8fe96085Stim szeto /*
91*8fe96085Stim szeto  * sbd_it_flags
92*8fe96085Stim szeto  */
93*8fe96085Stim szeto #define	SBD_IT_HAS_SCSI2_RESERVATION	0x0001
94*8fe96085Stim szeto #define	SBD_IT_PGR_REGISTERED		0x0002
95*8fe96085Stim szeto #define	SBD_IT_PGR_EXCLUSIVE_RSV_HOLDER	0x0004
96*8fe96085Stim szeto #define	SBD_IT_PGR_CHECK_FLAG		0x0008
97*8fe96085Stim szeto 
98*8fe96085Stim szeto /*
99*8fe96085Stim szeto  * PGR flags
100*8fe96085Stim szeto  */
101*8fe96085Stim szeto #define	SBD_PGR_APTPL			0x01
102*8fe96085Stim szeto #define	SBD_PGR_RSVD_ONE		0x02
103*8fe96085Stim szeto #define	SBD_PGR_RSVD_ALL_REGISTRANTS	0x04
104*8fe96085Stim szeto #define	SBD_PGR_ALL_KEYS_HAS_IT		0x08
105*8fe96085Stim szeto 
106*8fe96085Stim szeto #define	SBD_PGR_RSVD(pgr)	(((pgr)->pgr_flags) & (SBD_PGR_RSVD_ONE | \
107*8fe96085Stim szeto 					SBD_PGR_RSVD_ALL_REGISTRANTS))
108*8fe96085Stim szeto #define	SBD_PGR_RSVD_NONE(pgr)	(!(SBD_PGR_RSVD(pgr)))
109fcf3ce44SJohn Forte 
110fcf3ce44SJohn Forte /*
111*8fe96085Stim szeto  * PGR key flags
112fcf3ce44SJohn Forte  */
113*8fe96085Stim szeto #define	SBD_PGR_KEY_ALL_TG_PT		0x01
114*8fe96085Stim szeto 
115*8fe96085Stim szeto typedef struct sbd_pgr_key_info {
116*8fe96085Stim szeto 	uint64_t	pgr_key;
117*8fe96085Stim szeto 	uint16_t	pgr_key_lpt_len;
118*8fe96085Stim szeto 	uint16_t	pgr_key_rpt_len;
119*8fe96085Stim szeto 	uint8_t		pgr_key_flags;
120*8fe96085Stim szeto 	uint8_t		pgr_key_it[1];	/* devid_desc of initiator will be */
121*8fe96085Stim szeto 					/* followed by devid_desc of target */
122*8fe96085Stim szeto } sbd_pgr_key_info_t;
123*8fe96085Stim szeto 
124*8fe96085Stim szeto typedef struct sbd_pgr_info {
125*8fe96085Stim szeto 	sm_section_hdr_t	pgr_sms_header;
126*8fe96085Stim szeto 	uint32_t		pgr_rsvholder_indx;
127*8fe96085Stim szeto 	uint32_t		pgr_numkeys;
128*8fe96085Stim szeto 	uint8_t			pgr_flags;
129*8fe96085Stim szeto 	uint8_t			pgr_data_order;
130*8fe96085Stim szeto #ifdef _BIT_FIELDS_LTOH
131*8fe96085Stim szeto 	uint8_t			pgr_rsv_type:4,
132*8fe96085Stim szeto 				pgr_rsv_scope:4;
133*8fe96085Stim szeto #else
134*8fe96085Stim szeto 	uint8_t			pgr_rsv_scope:4,
135*8fe96085Stim szeto 				pgr_rsv_type:4;
136*8fe96085Stim szeto #endif
137*8fe96085Stim szeto 	uint8_t			rsvd[5];	/* 8 byte boundary */
138*8fe96085Stim szeto 
139*8fe96085Stim szeto } sbd_pgr_info_t;
140*8fe96085Stim szeto 
141*8fe96085Stim szeto typedef struct sbd_pgr_key {
142*8fe96085Stim szeto 	uint64_t		pgr_key;
143*8fe96085Stim szeto 	uint16_t		pgr_key_lpt_len;
144*8fe96085Stim szeto 	uint16_t		pgr_key_rpt_len;
145*8fe96085Stim szeto 	uint8_t			pgr_key_flags;
146*8fe96085Stim szeto 	struct scsi_devid_desc	*pgr_key_lpt_id;
147*8fe96085Stim szeto 	struct scsi_devid_desc	*pgr_key_rpt_id;
148*8fe96085Stim szeto 	struct sbd_it_data	*pgr_key_it;
149*8fe96085Stim szeto 	struct sbd_pgr_key	*pgr_key_next;
150*8fe96085Stim szeto 	struct sbd_pgr_key	*pgr_key_prev;
151*8fe96085Stim szeto } sbd_pgr_key_t;
152*8fe96085Stim szeto 
153*8fe96085Stim szeto typedef struct sbd_pgr {
154*8fe96085Stim szeto 	sbd_pgr_key_t		*pgr_keylist;
155*8fe96085Stim szeto 	sbd_pgr_key_t		*pgr_rsvholder;
156*8fe96085Stim szeto 	uint32_t		pgr_PRgeneration; /* PGR PRgeneration value */
157*8fe96085Stim szeto 	uint8_t			pgr_flags;	/* PGR flags (eg: APTPL)  */
158*8fe96085Stim szeto 	uint8_t			pgr_rsv_type:4,
159*8fe96085Stim szeto 				pgr_rsv_scope:4;
160*8fe96085Stim szeto 	krwlock_t		pgr_lock; /* Lock order pgr_lock, sl_lock */
161*8fe96085Stim szeto } sbd_pgr_t;
162*8fe96085Stim 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
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
222*8fe96085Stim 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;
230*8fe96085Stim szeto 	sbd_pgr_key_t		*pgr_key_ptr;
231fcf3ce44SJohn Forte } sbd_it_data_t;
232fcf3ce44SJohn Forte 
233fcf3ce44SJohn Forte /*
234fcf3ce44SJohn Forte  * Different UA conditions
235fcf3ce44SJohn Forte  */
236fcf3ce44SJohn Forte #define	SBD_UA_POR			0x01
237fcf3ce44SJohn Forte #define	SBD_UA_CAPACITY_CHANGED		0x02
238*8fe96085Stim szeto #define	SBD_UA_MODE_PARAMETERS_CHANGED	0x04
239*8fe96085Stim szeto #define	SBD_UA_REGISTRATIONS_PREEMPTED	0x10
240*8fe96085Stim szeto #define	SBD_UA_RESERVATIONS_PREEMPTED	0x20
241*8fe96085Stim szeto #define	SBD_UA_RESERVATIONS_RELEASED	0x40
242fcf3ce44SJohn Forte 
243fcf3ce44SJohn Forte /*
244fcf3ce44SJohn Forte  * sbd_it_flags
245fcf3ce44SJohn Forte  */
246*8fe96085Stim szeto #define	SBD_IT_HAS_SCSI2_RESERVATION	0x0001
247fcf3ce44SJohn Forte 
248fcf3ce44SJohn Forte stmf_status_t sbd_task_alloc(struct scsi_task *task);
249fcf3ce44SJohn Forte void sbd_new_task(struct scsi_task *task, struct stmf_data_buf *initial_dbuf);
250fcf3ce44SJohn Forte void sbd_dbuf_xfer_done(struct scsi_task *task, struct stmf_data_buf *dbuf);
251fcf3ce44SJohn Forte void sbd_send_status_done(struct scsi_task *task);
252fcf3ce44SJohn Forte void sbd_task_free(struct scsi_task *task);
253fcf3ce44SJohn Forte stmf_status_t sbd_abort(struct stmf_lu *lu, int abort_cmd, void *arg,
254fcf3ce44SJohn Forte 							uint32_t flags);
255fcf3ce44SJohn Forte void sbd_ctl(struct stmf_lu *lu, int cmd, void *arg);
256fcf3ce44SJohn Forte stmf_status_t sbd_info(uint32_t cmd, stmf_lu_t *lu, void *arg,
257fcf3ce44SJohn Forte 				uint8_t *buf, uint32_t *bufsizep);
258fcf3ce44SJohn Forte 
259fcf3ce44SJohn Forte #ifdef	__cplusplus
260fcf3ce44SJohn Forte }
261fcf3ce44SJohn Forte #endif
262fcf3ce44SJohn Forte 
263fcf3ce44SJohn Forte #endif /* _SBD_IMPL_H */
264