1*fcf3ce44SJohn Forte /*
2*fcf3ce44SJohn Forte  * CDDL HEADER START
3*fcf3ce44SJohn Forte  *
4*fcf3ce44SJohn Forte  * The contents of this file are subject to the terms of the
5*fcf3ce44SJohn Forte  * Common Development and Distribution License (the "License").
6*fcf3ce44SJohn Forte  * You may not use this file except in compliance with the License.
7*fcf3ce44SJohn Forte  *
8*fcf3ce44SJohn Forte  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*fcf3ce44SJohn Forte  * or http://www.opensolaris.org/os/licensing.
10*fcf3ce44SJohn Forte  * See the License for the specific language governing permissions
11*fcf3ce44SJohn Forte  * and limitations under the License.
12*fcf3ce44SJohn Forte  *
13*fcf3ce44SJohn Forte  * When distributing Covered Code, include this CDDL HEADER in each
14*fcf3ce44SJohn Forte  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*fcf3ce44SJohn Forte  * If applicable, add the following below this CDDL HEADER, with the
16*fcf3ce44SJohn Forte  * fields enclosed by brackets "[]" replaced with your own identifying
17*fcf3ce44SJohn Forte  * information: Portions Copyright [yyyy] [name of copyright owner]
18*fcf3ce44SJohn Forte  *
19*fcf3ce44SJohn Forte  * CDDL HEADER END
20*fcf3ce44SJohn Forte  */
21*fcf3ce44SJohn Forte /*
22*fcf3ce44SJohn Forte  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23*fcf3ce44SJohn Forte  * Use is subject to license terms.
24*fcf3ce44SJohn Forte  */
25*fcf3ce44SJohn Forte 
26*fcf3ce44SJohn Forte #ifndef	_SBD_IMPL_H
27*fcf3ce44SJohn Forte #define	_SBD_IMPL_H
28*fcf3ce44SJohn Forte 
29*fcf3ce44SJohn Forte #ifdef	__cplusplus
30*fcf3ce44SJohn Forte extern "C" {
31*fcf3ce44SJohn Forte #endif
32*fcf3ce44SJohn Forte 
33*fcf3ce44SJohn Forte struct register_lu_cmd;
34*fcf3ce44SJohn Forte struct modify_lu_cmd;
35*fcf3ce44SJohn Forte struct sbd_lu_attr;
36*fcf3ce44SJohn Forte struct sbd_it_data;
37*fcf3ce44SJohn Forte 
38*fcf3ce44SJohn Forte /*
39*fcf3ce44SJohn Forte  * sms endianess
40*fcf3ce44SJohn Forte  */
41*fcf3ce44SJohn Forte #define	SMS_BIG_ENDIAN			0x00
42*fcf3ce44SJohn Forte #define	SMS_LITTLE_ENDIAN		0xFF
43*fcf3ce44SJohn Forte 
44*fcf3ce44SJohn Forte #ifdef	_BIG_ENDIAN
45*fcf3ce44SJohn Forte #define	SMS_DATA_ORDER	SMS_BIG_ENDIAN
46*fcf3ce44SJohn Forte #else
47*fcf3ce44SJohn Forte #define	SMS_DATA_ORDER	SMS_LITTLE_ENDIAN
48*fcf3ce44SJohn Forte #endif
49*fcf3ce44SJohn Forte 
50*fcf3ce44SJohn Forte #define	SBD_V0_MAGIC	0x53554e4d4943524f
51*fcf3ce44SJohn Forte #define	SBD_MAGIC	0x53554e5342444c55
52*fcf3ce44SJohn Forte 
53*fcf3ce44SJohn Forte typedef struct sbd_v0_meta_start {
54*fcf3ce44SJohn Forte 	uint64_t		sm_magic;	/* SBD_MAGIC */
55*fcf3ce44SJohn Forte 	uint64_t		sm_meta_size;	/* Includes everything */
56*fcf3ce44SJohn Forte } sbd_v0_meta_start_t;
57*fcf3ce44SJohn Forte 
58*fcf3ce44SJohn Forte typedef struct sbd_meta_start {
59*fcf3ce44SJohn Forte 	uint64_t		sm_magic;
60*fcf3ce44SJohn Forte 	uint64_t		sm_meta_size;
61*fcf3ce44SJohn Forte 	uint64_t		sm_meta_size_used;
62*fcf3ce44SJohn Forte 	uint64_t		sm_rsvd1;	/* Defaults to zero */
63*fcf3ce44SJohn Forte 	uint64_t		sm_rsvd2;
64*fcf3ce44SJohn Forte 	uint16_t		sm_ver_major;
65*fcf3ce44SJohn Forte 	uint16_t		sm_ver_minor;
66*fcf3ce44SJohn Forte 	uint16_t		sm_ver_subminor;
67*fcf3ce44SJohn Forte 	uint8_t			sm_flags;	/* None at this moment */
68*fcf3ce44SJohn Forte 	uint8_t			sm_chksum;
69*fcf3ce44SJohn Forte } sbd_meta_start_t;
70*fcf3ce44SJohn Forte 
71*fcf3ce44SJohn Forte typedef struct sm_v0_section_hdr {
72*fcf3ce44SJohn Forte 	uint64_t	sms_offset;	/* Offset of this section */
73*fcf3ce44SJohn Forte 	uint64_t	sms_size;	/* Includes the header and padding */
74*fcf3ce44SJohn Forte 	uint16_t	sms_id;		/* Section identifier */
75*fcf3ce44SJohn Forte 	uint16_t	sms_padding;	/* For alignment */
76*fcf3ce44SJohn Forte 	uint32_t	sms_seqno;	/* For multiple sections with same ID */
77*fcf3ce44SJohn Forte 	uint8_t		sms_hdr_data_order; /* 0x00 or 0xff */
78*fcf3ce44SJohn Forte 	uint8_t		sms_payload_data_order;
79*fcf3ce44SJohn Forte 	uint16_t	rsvd2;
80*fcf3ce44SJohn Forte 	uint32_t	rsvd3;		/* 8 byte align */
81*fcf3ce44SJohn Forte } sm_v0_section_hdr_t;
82*fcf3ce44SJohn Forte 
83*fcf3ce44SJohn Forte typedef struct sm_section_hdr {
84*fcf3ce44SJohn Forte 	uint64_t	sms_offset;	/* Offset of this section */
85*fcf3ce44SJohn Forte 	uint32_t	sms_size;	/* Includes the header and padding */
86*fcf3ce44SJohn Forte 	uint16_t	sms_id;		/* Section identifier */
87*fcf3ce44SJohn Forte 	uint8_t		sms_data_order; /* 0x00 or 0xff */
88*fcf3ce44SJohn Forte 	uint8_t		sms_chksum;
89*fcf3ce44SJohn Forte } sm_section_hdr_t;
90*fcf3ce44SJohn Forte 
91*fcf3ce44SJohn Forte /*
92*fcf3ce44SJohn Forte  * sbd meta section identifiers
93*fcf3ce44SJohn Forte  */
94*fcf3ce44SJohn Forte #define	SMS_ID_LU_INFO	0
95*fcf3ce44SJohn Forte 
96*fcf3ce44SJohn Forte typedef struct sbd_v0_lu_info {
97*fcf3ce44SJohn Forte 	sm_v0_section_hdr_t	sli_sms_header;
98*fcf3ce44SJohn Forte 	uint64_t		sli_total_store_size;
99*fcf3ce44SJohn Forte 	uint64_t		sli_total_meta_size;
100*fcf3ce44SJohn Forte 	uint64_t		rsvd0;
101*fcf3ce44SJohn Forte 	uint64_t		sli_lu_data_offset;
102*fcf3ce44SJohn Forte 	uint64_t		sli_lu_data_size;
103*fcf3ce44SJohn Forte 	uint64_t		rsvd1;
104*fcf3ce44SJohn Forte 	uint32_t		sli_flags;
105*fcf3ce44SJohn Forte 	uint16_t		sli_blocksize;
106*fcf3ce44SJohn Forte 	uint16_t		rsvd2;
107*fcf3ce44SJohn Forte 	uint8_t			sli_lu_devid[20];
108*fcf3ce44SJohn Forte 	uint32_t		rsvd3;
109*fcf3ce44SJohn Forte } sbd_v0_lu_info_t;
110*fcf3ce44SJohn Forte 
111*fcf3ce44SJohn Forte typedef struct sbd_lu_info {
112*fcf3ce44SJohn Forte 	sm_section_hdr_t	sli_sms_header;
113*fcf3ce44SJohn Forte 	uint64_t		sli_total_store_size;
114*fcf3ce44SJohn Forte 	uint64_t		sli_total_meta_size;
115*fcf3ce44SJohn Forte 	uint64_t		sli_lu_data_offset;
116*fcf3ce44SJohn Forte 	uint64_t		sli_lu_data_size;
117*fcf3ce44SJohn Forte 	uint32_t		sli_flags;
118*fcf3ce44SJohn Forte 	uint16_t		sli_blocksize;
119*fcf3ce44SJohn Forte 	uint8_t			sli_data_order;
120*fcf3ce44SJohn Forte 	uint8_t			rsvd1;
121*fcf3ce44SJohn Forte 	uint8_t			sli_lu_devid[20];
122*fcf3ce44SJohn Forte 	uint32_t		rsvd2;
123*fcf3ce44SJohn Forte } sbd_lu_info_t;
124*fcf3ce44SJohn Forte 
125*fcf3ce44SJohn Forte typedef struct sbd_lu {
126*fcf3ce44SJohn Forte 	sbd_store_t			*sl_sst;
127*fcf3ce44SJohn Forte 	uint32_t			sl_total_allocation_size;
128*fcf3ce44SJohn Forte 	uint8_t				sl_shift_count;
129*fcf3ce44SJohn Forte 	uint8_t				sl_state:7,
130*fcf3ce44SJohn Forte 					sl_state_not_acked:1;
131*fcf3ce44SJohn Forte 	uint8_t				sl_flags;
132*fcf3ce44SJohn Forte 	kmutex_t			sl_it_list_lock;
133*fcf3ce44SJohn Forte 	struct sbd_it_data		*sl_it_list;
134*fcf3ce44SJohn Forte 	uint64_t			sl_rs_owner_session_id;
135*fcf3ce44SJohn Forte 	stmf_lu_t			*sl_lu;
136*fcf3ce44SJohn Forte 	struct sbd_lu			*sl_next; /* for int. tracking */
137*fcf3ce44SJohn Forte 
138*fcf3ce44SJohn Forte 	sbd_meta_start_t		sl_sm;
139*fcf3ce44SJohn Forte 	sbd_lu_info_t			*sl_sli;
140*fcf3ce44SJohn Forte 	uint64_t			sl_meta_offset;
141*fcf3ce44SJohn Forte } sbd_lu_t;
142*fcf3ce44SJohn Forte 
143*fcf3ce44SJohn Forte extern sbd_lu_t *sbd_lu_list;
144*fcf3ce44SJohn Forte 
145*fcf3ce44SJohn Forte /*
146*fcf3ce44SJohn Forte  * sl_flags
147*fcf3ce44SJohn Forte  */
148*fcf3ce44SJohn Forte #define	SBD_LU_HAS_SCSI2_RESERVATION	0x0001
149*fcf3ce44SJohn Forte 
150*fcf3ce44SJohn Forte typedef struct sbd_cmd {
151*fcf3ce44SJohn Forte 	uint8_t		flags;
152*fcf3ce44SJohn Forte 	uint8_t		nbufs;
153*fcf3ce44SJohn Forte 	uint16_t	cmd_type;	/* Type of command */
154*fcf3ce44SJohn Forte 	uint32_t	rsvd2;
155*fcf3ce44SJohn Forte 	uint64_t	addr;		/* current */
156*fcf3ce44SJohn Forte 	uint32_t	len;		/* len left */
157*fcf3ce44SJohn Forte 	uint32_t	current_ro;	/* running relative offset */
158*fcf3ce44SJohn Forte } sbd_cmd_t;
159*fcf3ce44SJohn Forte 
160*fcf3ce44SJohn Forte /*
161*fcf3ce44SJohn Forte  * flags for sbd_cmd
162*fcf3ce44SJohn Forte  */
163*fcf3ce44SJohn Forte #define	SBD_SCSI_CMD_ACTIVE		0x01
164*fcf3ce44SJohn Forte #define	SBD_SCSI_CMD_ABORT_REQUESTED	0x02
165*fcf3ce44SJohn Forte #define	SBD_SCSI_CMD_XFER_FAIL		0x04
166*fcf3ce44SJohn Forte 
167*fcf3ce44SJohn Forte /*
168*fcf3ce44SJohn Forte  * cmd types
169*fcf3ce44SJohn Forte  */
170*fcf3ce44SJohn Forte #define	SBD_CMD_SCSI_READ	0x01
171*fcf3ce44SJohn Forte #define	SBD_CMD_SCSI_WRITE	0x02
172*fcf3ce44SJohn Forte #define	SBD_CMD_SMALL_READ	0x03
173*fcf3ce44SJohn Forte #define	SBD_CMD_SMALL_WRITE	0x04
174*fcf3ce44SJohn Forte 
175*fcf3ce44SJohn Forte typedef struct sbd_it_data {
176*fcf3ce44SJohn Forte 	struct sbd_it_data	*sbd_it_next;
177*fcf3ce44SJohn Forte 	uint64_t		sbd_it_session_id;
178*fcf3ce44SJohn Forte 	uint8_t			sbd_it_lun[8];
179*fcf3ce44SJohn Forte 	uint8_t			sbd_it_ua_conditions;
180*fcf3ce44SJohn Forte 	uint8_t			sbd_it_flags;
181*fcf3ce44SJohn Forte } sbd_it_data_t;
182*fcf3ce44SJohn Forte 
183*fcf3ce44SJohn Forte /*
184*fcf3ce44SJohn Forte  * Different UA conditions
185*fcf3ce44SJohn Forte  */
186*fcf3ce44SJohn Forte #define	SBD_UA_POR			0x01
187*fcf3ce44SJohn Forte #define	SBD_UA_CAPACITY_CHANGED		0x02
188*fcf3ce44SJohn Forte 
189*fcf3ce44SJohn Forte /*
190*fcf3ce44SJohn Forte  * sbd_it_flags
191*fcf3ce44SJohn Forte  */
192*fcf3ce44SJohn Forte #define	SBD_IT_HAS_SCSI2_RESERVATION		0x0001
193*fcf3ce44SJohn Forte 
194*fcf3ce44SJohn Forte stmf_status_t sbd_task_alloc(struct scsi_task *task);
195*fcf3ce44SJohn Forte void sbd_new_task(struct scsi_task *task, struct stmf_data_buf *initial_dbuf);
196*fcf3ce44SJohn Forte void sbd_dbuf_xfer_done(struct scsi_task *task, struct stmf_data_buf *dbuf);
197*fcf3ce44SJohn Forte void sbd_send_status_done(struct scsi_task *task);
198*fcf3ce44SJohn Forte void sbd_task_free(struct scsi_task *task);
199*fcf3ce44SJohn Forte stmf_status_t sbd_abort(struct stmf_lu *lu, int abort_cmd, void *arg,
200*fcf3ce44SJohn Forte 							uint32_t flags);
201*fcf3ce44SJohn Forte void sbd_ctl(struct stmf_lu *lu, int cmd, void *arg);
202*fcf3ce44SJohn Forte stmf_status_t sbd_info(uint32_t cmd, stmf_lu_t *lu, void *arg,
203*fcf3ce44SJohn Forte 				uint8_t *buf, uint32_t *bufsizep);
204*fcf3ce44SJohn Forte 
205*fcf3ce44SJohn Forte stmf_status_t memdisk_register_lu(struct register_lu_cmd *rlc);
206*fcf3ce44SJohn Forte stmf_status_t memdisk_deregister_lu(sbd_store_t *sst);
207*fcf3ce44SJohn Forte stmf_status_t filedisk_register_lu(struct register_lu_cmd *rlc);
208*fcf3ce44SJohn Forte stmf_status_t filedisk_deregister_lu(sbd_store_t *sst);
209*fcf3ce44SJohn Forte stmf_status_t filedisk_modify_lu(sbd_store_t *sst, struct modify_lu_cmd *mlc);
210*fcf3ce44SJohn Forte void filedisk_fillout_attr(struct sbd_store *sst, struct sbd_lu_attr *sla);
211*fcf3ce44SJohn Forte void memdisk_fillout_attr(struct sbd_store *sst, struct sbd_lu_attr *sla);
212*fcf3ce44SJohn Forte 
213*fcf3ce44SJohn Forte #ifdef	__cplusplus
214*fcf3ce44SJohn Forte }
215*fcf3ce44SJohn Forte #endif
216*fcf3ce44SJohn Forte 
217*fcf3ce44SJohn Forte #endif /* _SBD_IMPL_H */
218