xref: /illumos-gate/usr/src/uts/common/sys/stmf.h (revision 61dfa509)
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  */
21*61dfa509SRick McNeal 
22fcf3ce44SJohn Forte /*
233fb517f7SJames Moore  * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
24*61dfa509SRick McNeal  * Copyright 2016 Nexenta Systems, Inc. All rights reserved.
2509409df0SJeff Biseda  * Copyright (c) 2013 by Delphix. All rights reserved.
26fcf3ce44SJohn Forte  */
27*61dfa509SRick McNeal 
28fcf3ce44SJohn Forte #ifndef	_STMF_H
29fcf3ce44SJohn Forte #define	_STMF_H
30fcf3ce44SJohn Forte 
31fcf3ce44SJohn Forte #include <sys/stmf_defines.h>
32fcf3ce44SJohn Forte 
33fcf3ce44SJohn Forte #ifdef	__cplusplus
34fcf3ce44SJohn Forte extern "C" {
35fcf3ce44SJohn Forte #endif
36fcf3ce44SJohn Forte 
37fcf3ce44SJohn Forte typedef enum stmf_struct_id {
38fcf3ce44SJohn Forte 	STMF_STRUCT_LU_PROVIDER = 1,
39fcf3ce44SJohn Forte 	STMF_STRUCT_PORT_PROVIDER,
40fcf3ce44SJohn Forte 	STMF_STRUCT_STMF_LOCAL_PORT,
41fcf3ce44SJohn Forte 	STMF_STRUCT_STMF_LU,
42fcf3ce44SJohn Forte 	STMF_STRUCT_SCSI_SESSION,
43fcf3ce44SJohn Forte 	STMF_STRUCT_SCSI_TASK,
44fcf3ce44SJohn Forte 	STMF_STRUCT_DATA_BUF,
45fcf3ce44SJohn Forte 	STMF_STRUCT_DBUF_STORE,
46fcf3ce44SJohn Forte 	STMF_MAX_STRUCT_IDS
47fcf3ce44SJohn Forte } stmf_struct_id_t;
48fcf3ce44SJohn Forte 
49fcf3ce44SJohn Forte /*
50fcf3ce44SJohn Forte  * Provider callback commands
51fcf3ce44SJohn Forte  */
52fcf3ce44SJohn Forte #define	STMF_PROVIDER_DATA_UPDATED	0x01
53fcf3ce44SJohn Forte 
54fcf3ce44SJohn Forte /*
55fcf3ce44SJohn Forte  * Provider callback flags
56fcf3ce44SJohn Forte  */
57fcf3ce44SJohn Forte #define	STMF_PCB_STMF_ONLINING		0x0001
58fcf3ce44SJohn Forte #define	STMF_PCB_PREG_COMPLETE		0x0002
59fcf3ce44SJohn Forte 
60fcf3ce44SJohn Forte typedef void *data_seg_handle_t;
61fcf3ce44SJohn Forte #define	STMF_MAX_LU_CACHE_NTASKS 16
62fcf3ce44SJohn Forte 
63fcf3ce44SJohn Forte #define	STMF_NO_HANDLE	0xffffffff
64fcf3ce44SJohn Forte 
65fcf3ce44SJohn Forte #define	COMPANY_ID_NONE			0xFFFFFFFF
66fcf3ce44SJohn Forte #define	COMPANY_ID_SUN			0x00144F
67fcf3ce44SJohn Forte 
683fb517f7SJames Moore /*
693fb517f7SJames Moore  * The scatter/gather list buffer format is used in 2 different
703fb517f7SJames Moore  * contexts within stmf:
713fb517f7SJames Moore  * 1) supplied by the port provider that the LU provider uses to exchange
723fb517f7SJames Moore  *    data with the backing store.
733fb517f7SJames Moore  * 2) supplied by the LU provider that the port provider uses exchange
743fb517f7SJames Moore  *    data with the host initiator.
753fb517f7SJames Moore  * The second format is optionally supported by the port provided as
763fb517f7SJames Moore  * indicated by the command task flags.
773fb517f7SJames Moore  */
783fb517f7SJames Moore 
793fb517f7SJames Moore typedef struct stmf_sglist_ent {
803fb517f7SJames Moore 	uint32_t	seg_length;
813fb517f7SJames Moore 	uint8_t		*seg_addr;
823fb517f7SJames Moore } stmf_sglist_ent_t;
833fb517f7SJames Moore 
84fcf3ce44SJohn Forte typedef struct stmf_data_buf {
85fcf3ce44SJohn Forte 	void		*db_stmf_private;
86fcf3ce44SJohn Forte 	void		*db_port_private;
87fcf3ce44SJohn Forte 	void		*db_lu_private;
88fcf3ce44SJohn Forte 	uint32_t	db_buf_size;	/* Total size of this buffer */
89fcf3ce44SJohn Forte 	uint32_t	db_data_size;	/* Intended xfer size of this buffer */
90fcf3ce44SJohn Forte 	uint32_t	db_relative_offset;
91fcf3ce44SJohn Forte 	uint16_t	db_sglist_length;
92fcf3ce44SJohn Forte 	uint16_t	db_flags;	/* Direction, auto status etc */
93fcf3ce44SJohn Forte 	stmf_status_t	db_xfer_status;
94fcf3ce44SJohn Forte 	uint8_t		db_handle;	/* To track parallel buffers */
95427fcaf8Stim szeto 	hrtime_t	db_xfer_start_timestamp;
963fb517f7SJames Moore 	stmf_sglist_ent_t db_sglist[1];	/* PP scatter/gather list */
97fcf3ce44SJohn Forte } stmf_data_buf_t;
98fcf3ce44SJohn Forte 
99fcf3ce44SJohn Forte /*
100fcf3ce44SJohn Forte  * db_flags
101fcf3ce44SJohn Forte  */
102fcf3ce44SJohn Forte #define	DB_DIRECTION_TO_RPORT		0x0001
103fcf3ce44SJohn Forte #define	DB_DIRECTION_FROM_RPORT		0x0002
104fcf3ce44SJohn Forte #define	DB_SEND_STATUS_GOOD		0x0004
105fcf3ce44SJohn Forte #define	DB_STATUS_GOOD_SENT		0x0008
106fcf3ce44SJohn Forte #define	DB_DONT_CACHE			0x0010
1072a8164dfSZhong Wang #define	DB_DONT_REUSE			0x0020
1083fb517f7SJames Moore #define	DB_LU_DATA_BUF			0x0040
10940c3e8ffSJohn Forte #define	DB_LPORT_XFER_ACTIVE		0x8000
110fcf3ce44SJohn Forte 
111fcf3ce44SJohn Forte typedef struct scsi_task {
112fcf3ce44SJohn Forte 	void		*task_stmf_private;
113fcf3ce44SJohn Forte 	void		*task_port_private;
114fcf3ce44SJohn Forte 
115fcf3ce44SJohn Forte 	void		*task_lu_private;
116fcf3ce44SJohn Forte 	struct stmf_scsi_session *task_session;
117fcf3ce44SJohn Forte 	struct stmf_local_port *task_lport;
118fcf3ce44SJohn Forte 	struct stmf_lu	*task_lu;
119fcf3ce44SJohn Forte 	void		*task_lu_itl_handle;	/* Assigned by LU */
120fcf3ce44SJohn Forte 
121fcf3ce44SJohn Forte 	/* CMD information from initiator */
122fcf3ce44SJohn Forte 	uint8_t		task_lun_no[8];
123fcf3ce44SJohn Forte 	uint8_t		task_flags;		/* See def. for task flags */
124fcf3ce44SJohn Forte 	uint8_t		task_priority;		/* As per SAM-3 */
125fcf3ce44SJohn Forte 	uint8_t		task_mgmt_function;	/* If this is a TM request */
126fcf3ce44SJohn Forte 	uint8_t		task_max_nbufs;
127fcf3ce44SJohn Forte 	uint8_t		task_cur_nbufs;
128fcf3ce44SJohn Forte 	uint8_t		task_csn_size;		/* cmd seq no size in bits */
129fcf3ce44SJohn Forte 	uint16_t	task_additional_flags;
130fcf3ce44SJohn Forte 	uint32_t	task_cmd_seq_no;
131fcf3ce44SJohn Forte 	uint32_t	task_expected_xfer_length;
132fcf3ce44SJohn Forte 	uint32_t	task_timeout;		/* In seconds */
133fcf3ce44SJohn Forte 	uint16_t	task_ext_id;
134fcf3ce44SJohn Forte 	uint16_t	task_cdb_length;
135fcf3ce44SJohn Forte 	uint8_t		*task_cdb;
136fcf3ce44SJohn Forte 
137fcf3ce44SJohn Forte 	/* Fields to manage data phase */
138fcf3ce44SJohn Forte 	uint32_t	task_cmd_xfer_length;	/* xfer len based on CDB */
139fcf3ce44SJohn Forte 	uint32_t	task_nbytes_transferred;
1403fb517f7SJames Moore 	uint32_t	task_max_xfer_len;	/* largest xfer allowed */
1413fb517f7SJames Moore 	uint32_t	task_1st_xfer_len;	/* 1st xfer hint */
1423fb517f7SJames Moore 	uint32_t	task_copy_threshold;	/* copy reduction threshold */
1433fb517f7SJames Moore 
144fcf3ce44SJohn Forte 
145fcf3ce44SJohn Forte 	/* Status Phase */
146fcf3ce44SJohn Forte 	stmf_status_t	task_completion_status;
147fcf3ce44SJohn Forte 	uint32_t	task_resid;
148fcf3ce44SJohn Forte 	uint8_t		task_status_ctrl;	/* See def. for status ctrl */
149fcf3ce44SJohn Forte 	uint8_t		task_scsi_status;
150fcf3ce44SJohn Forte 	uint16_t	task_sense_length;
151fcf3ce44SJohn Forte 	uint8_t		*task_sense_data;
152fcf3ce44SJohn Forte 
153fcf3ce44SJohn Forte 	/* Misc. task data */
154fcf3ce44SJohn Forte 	void		*task_extended_cmd;
155fcf3ce44SJohn Forte 
156fcf3ce44SJohn Forte } scsi_task_t;
157fcf3ce44SJohn Forte 
158fcf3ce44SJohn Forte /*
159fcf3ce44SJohn Forte  * Maximum expected transfer length.   Can also be used when the transfer
160fcf3ce44SJohn Forte  * length is unknown when the task is allocated (e.g. SAS)
161fcf3ce44SJohn Forte  */
162fcf3ce44SJohn Forte 
163fcf3ce44SJohn Forte #define	TASK_MAX_XFER_LENGTH	0xFFFFFFFF
164fcf3ce44SJohn Forte 
165fcf3ce44SJohn Forte /*
166fcf3ce44SJohn Forte  * task_flags definitions.
167fcf3ce44SJohn Forte  */
168fcf3ce44SJohn Forte /*
169fcf3ce44SJohn Forte  * If TF_INITIAL_BURST is set, the dbuf passed with new_task() contains
170fcf3ce44SJohn Forte  * data from initial burst. Otherwise its just a buffer which the port
171fcf3ce44SJohn Forte  * passed to the LU.
172fcf3ce44SJohn Forte  */
173fcf3ce44SJohn Forte #define	TF_INITIAL_BURST	0x80
174fcf3ce44SJohn Forte /* Both READ_DATA and WRITE_DATA can be set for bidirectional xfers */
175fcf3ce44SJohn Forte #define	TF_READ_DATA		0x40
176fcf3ce44SJohn Forte #define	TF_WRITE_DATA		0x20
177fcf3ce44SJohn Forte #define	TF_ATTR_MASK		0x07
178fcf3ce44SJohn Forte #define	TF_ATTR_UNTAGGED	0x0
179fcf3ce44SJohn Forte #define	TF_ATTR_SIMPLE_QUEUE	0x1
180fcf3ce44SJohn Forte #define	TF_ATTR_ORDERED_QUEUE	0x2
181fcf3ce44SJohn Forte #define	TF_ATTR_HEAD_OF_QUEUE	0x3
182fcf3ce44SJohn Forte #define	TF_ATTR_ACA		0x4
183fcf3ce44SJohn Forte 
184fcf3ce44SJohn Forte /*
185fcf3ce44SJohn Forte  * Task Management flags.
186fcf3ce44SJohn Forte  */
187fcf3ce44SJohn Forte #define	TM_NONE			0x00
188fcf3ce44SJohn Forte #define	TM_ABORT_TASK		0x01
189fcf3ce44SJohn Forte #define	TM_ABORT_TASK_SET	0x02
190fcf3ce44SJohn Forte #define	TM_CLEAR_ACA		0x03
191fcf3ce44SJohn Forte #define	TM_CLEAR_TASK_SET	0x04
192fcf3ce44SJohn Forte #define	TM_LUN_RESET		0x05
193fcf3ce44SJohn Forte #define	TM_TARGET_WARM_RESET	0x06
194fcf3ce44SJohn Forte #define	TM_TARGET_COLD_RESET	0x07
195fcf3ce44SJohn Forte #define	TM_TASK_REASSIGN	0x08
196fcf3ce44SJohn Forte #define	TM_TARGET_RESET		0x09
197fcf3ce44SJohn Forte #define	TM_QUERY_TASK		0x0A
198fcf3ce44SJohn Forte 
199fcf3ce44SJohn Forte /*
200fcf3ce44SJohn Forte  * additional flags
201fcf3ce44SJohn Forte  */
202fcf3ce44SJohn Forte #define	TASK_AF_ENABLE_COMP_CONF	0x01
203fcf3ce44SJohn Forte #define	TASK_AF_PORT_LOAD_HIGH		0x02
204fcf3ce44SJohn Forte #define	TASK_AF_NO_EXPECTED_XFER_LENGTH	0x04
2053fb517f7SJames Moore /*
2063fb517f7SJames Moore  * PP sets this flag if it can process dbufs created by the LU.
2073fb517f7SJames Moore  */
2083fb517f7SJames Moore #define	TASK_AF_ACCEPT_LU_DBUF		0x08
209fcf3ce44SJohn Forte 
210fcf3ce44SJohn Forte /*
211*61dfa509SRick McNeal  * Indicating a PPPT task
212*61dfa509SRick McNeal  */
213*61dfa509SRick McNeal #define	TASK_AF_PPPT_TASK		0x10
214*61dfa509SRick McNeal 
215*61dfa509SRick McNeal /*
216fcf3ce44SJohn Forte  * scsi_task_t extension identifiers
217fcf3ce44SJohn Forte  */
218fcf3ce44SJohn Forte #define	STMF_TASK_EXT_NONE		0
219fcf3ce44SJohn Forte 
220fcf3ce44SJohn Forte /*
221fcf3ce44SJohn Forte  * max_nbufs
222fcf3ce44SJohn Forte  */
223fcf3ce44SJohn Forte #define	STMF_BUFS_MAX		255
224fcf3ce44SJohn Forte 
225fcf3ce44SJohn Forte /*
226fcf3ce44SJohn Forte  * Task status ctrl
227fcf3ce44SJohn Forte  */
228fcf3ce44SJohn Forte #define	TASK_SCTRL_OVER		1
229fcf3ce44SJohn Forte #define	TASK_SCTRL_UNDER	2
230fcf3ce44SJohn Forte 
231fcf3ce44SJohn Forte /*
232fcf3ce44SJohn Forte  * The flags used by I/O flow.
233fcf3ce44SJohn Forte  */
234fcf3ce44SJohn Forte #define	STMF_IOF_LU_DONE		0x0001
235fcf3ce44SJohn Forte #define	STMF_IOF_LPORT_DONE		0x0002
236427fcaf8Stim szeto #define	STMF_IOF_STATS_ONLY		0x0004
237fcf3ce44SJohn Forte 
238fcf3ce44SJohn Forte /*
239fcf3ce44SJohn Forte  * struct allocation flags
240fcf3ce44SJohn Forte  */
241fcf3ce44SJohn Forte #define	AF_FORCE_NOSLEEP	0x0001
2423fb517f7SJames Moore #define	AF_DONTZERO		0x0002
243fcf3ce44SJohn Forte 
244fcf3ce44SJohn Forte typedef struct stmf_state_change_info {
2453fb517f7SJames Moore 	uint64_t	st_rflags;	/* Reason behind this change */
246fcf3ce44SJohn Forte 	char		*st_additional_info;
247fcf3ce44SJohn Forte } stmf_state_change_info_t;
248fcf3ce44SJohn Forte 
249fcf3ce44SJohn Forte typedef struct stmf_change_status {
250fcf3ce44SJohn Forte 	stmf_status_t	st_completion_status;
251fcf3ce44SJohn Forte 	char		*st_additional_info;
252fcf3ce44SJohn Forte } stmf_change_status_t;
253fcf3ce44SJohn Forte 
254fcf3ce44SJohn Forte /*
255fcf3ce44SJohn Forte  * conditions causing or affecting the change.
256fcf3ce44SJohn Forte  */
257fcf3ce44SJohn Forte #define	STMF_RFLAG_USER_REQUEST		0x0001
258fcf3ce44SJohn Forte #define	STMF_RFLAG_FATAL_ERROR		0x0002
259fcf3ce44SJohn Forte #define	STMF_RFLAG_STAY_OFFLINED	0x0004
260fcf3ce44SJohn Forte #define	STMF_RFLAG_RESET		0x0008
261fcf3ce44SJohn Forte #define	STMF_RFLAG_COLLECT_DEBUG_DUMP	0x0010
262fcf3ce44SJohn Forte #define	STMF_RFLAG_LU_ABORT		0x0020
263fcf3ce44SJohn Forte #define	STMF_RFLAG_LPORT_ABORT		0x0040
264fcf3ce44SJohn Forte 
265fcf3ce44SJohn Forte #define	STMF_CHANGE_INFO_LEN		160
266fcf3ce44SJohn Forte 
267fcf3ce44SJohn Forte /*
268fcf3ce44SJohn Forte  * cmds to stmf_abort entry point
269fcf3ce44SJohn Forte  */
270fcf3ce44SJohn Forte #define	STMF_QUEUE_TASK_ABORT		1
271fcf3ce44SJohn Forte #define	STMF_REQUEUE_TASK_ABORT_LPORT	2
272fcf3ce44SJohn Forte #define	STMF_REQUEUE_TASK_ABORT_LU	3
273fcf3ce44SJohn Forte #define	STMF_QUEUE_ABORT_LU		4
274fcf3ce44SJohn Forte 
275fcf3ce44SJohn Forte /*
276fcf3ce44SJohn Forte  * cmds to be used by stmf ctl
277fcf3ce44SJohn Forte  */
278fcf3ce44SJohn Forte #define	STMF_CMD_LU_OP			0x0100
279fcf3ce44SJohn Forte #define	STMF_CMD_LPORT_OP		0x0200
280fcf3ce44SJohn Forte #define	STMF_CMD_MASK			0x00ff
281fcf3ce44SJohn Forte #define	STMF_CMD_ONLINE			0x0001
282fcf3ce44SJohn Forte #define	STMF_CMD_OFFLINE		0x0002
283fcf3ce44SJohn Forte #define	STMF_CMD_GET_STATUS		0x0003
284fcf3ce44SJohn Forte #define	STMF_CMD_ONLINE_COMPLETE	0x0004
285fcf3ce44SJohn Forte #define	STMF_CMD_OFFLINE_COMPLETE	0x0005
286fcf3ce44SJohn Forte #define	STMF_ACK_ONLINE_COMPLETE	0x0006
287fcf3ce44SJohn Forte #define	STMF_ACK_OFFLINE_COMPLETE	0x0007
288fcf3ce44SJohn Forte 
289fcf3ce44SJohn Forte #define	STMF_CMD_LU_ONLINE		(STMF_CMD_LU_OP | STMF_CMD_ONLINE)
290fcf3ce44SJohn Forte #define	STMF_CMD_LU_OFFLINE		(STMF_CMD_LU_OP | STMF_CMD_OFFLINE)
291fcf3ce44SJohn Forte #define	STMF_CMD_LPORT_ONLINE		(STMF_CMD_LPORT_OP | STMF_CMD_ONLINE)
292fcf3ce44SJohn Forte #define	STMF_CMD_LPORT_OFFLINE		(STMF_CMD_LPORT_OP | STMF_CMD_OFFLINE)
293fcf3ce44SJohn Forte #define	STMF_CMD_GET_LU_STATUS		(STMF_CMD_LU_OP | STMF_CMD_GET_STATUS)
294fcf3ce44SJohn Forte #define	STMF_CMD_GET_LPORT_STATUS	\
295fcf3ce44SJohn Forte 			(STMF_CMD_LPORT_OP | STMF_CMD_GET_STATUS)
296fcf3ce44SJohn Forte #define	STMF_CMD_LU_ONLINE_COMPLETE	\
297fcf3ce44SJohn Forte 			(STMF_CMD_LU_OP | STMF_CMD_ONLINE_COMPLETE)
298fcf3ce44SJohn Forte #define	STMF_CMD_LPORT_ONLINE_COMPLETE	\
299fcf3ce44SJohn Forte 			(STMF_CMD_LPORT_OP | STMF_CMD_ONLINE_COMPLETE)
300fcf3ce44SJohn Forte #define	STMF_ACK_LU_ONLINE_COMPLETE	\
301fcf3ce44SJohn Forte 			(STMF_CMD_LU_OP | STMF_ACK_ONLINE_COMPLETE)
302fcf3ce44SJohn Forte #define	STMF_ACK_LPORT_ONLINE_COMPLETE	\
303fcf3ce44SJohn Forte 			(STMF_CMD_LPORT_OP | STMF_ACK_ONLINE_COMPLETE)
304fcf3ce44SJohn Forte #define	STMF_CMD_LU_OFFLINE_COMPLETE	\
305fcf3ce44SJohn Forte 			(STMF_CMD_LU_OP | STMF_CMD_OFFLINE_COMPLETE)
306fcf3ce44SJohn Forte #define	STMF_CMD_LPORT_OFFLINE_COMPLETE	\
307fcf3ce44SJohn Forte 			(STMF_CMD_LPORT_OP | STMF_CMD_OFFLINE_COMPLETE)
308fcf3ce44SJohn Forte #define	STMF_ACK_LU_OFFLINE_COMPLETE	\
309fcf3ce44SJohn Forte 			(STMF_CMD_LU_OP | STMF_ACK_OFFLINE_COMPLETE)
310fcf3ce44SJohn Forte #define	STMF_ACK_LPORT_OFFLINE_COMPLETE	\
311fcf3ce44SJohn Forte 			(STMF_CMD_LPORT_OP | STMF_ACK_OFFLINE_COMPLETE)
312fcf3ce44SJohn Forte /*
313fcf3ce44SJohn Forte  * For LPORTs and LUs to create their own ctl cmds which dont
314fcf3ce44SJohn Forte  * conflict with stmf ctl cmds.
315fcf3ce44SJohn Forte  */
316fcf3ce44SJohn Forte #define	STMF_LPORT_CTL_CMDS		0x1000
317fcf3ce44SJohn Forte #define	STMF_LU_CTL_CMDS		0x2000
318fcf3ce44SJohn Forte 
319fcf3ce44SJohn Forte /*
320fcf3ce44SJohn Forte  * Commands for various info routines.
321fcf3ce44SJohn Forte  */
322fcf3ce44SJohn Forte /* Command classifiers */
323fcf3ce44SJohn Forte #define	SI_LPORT		0x1000000
324fcf3ce44SJohn Forte #define	SI_STMF			0x2000000
325fcf3ce44SJohn Forte #define	SI_LU			0x4000000
326fcf3ce44SJohn Forte #define	SI_LPORT_FC		0x0000000
327fcf3ce44SJohn Forte #define	SI_LPORT_ISCSI		0x0010000
328fcf3ce44SJohn Forte #define	SI_LPORT_SAS		0x0020000
329fcf3ce44SJohn Forte #define	SI_STMF_LU		0x0010000
330fcf3ce44SJohn Forte #define	SI_STMF_LPORT		0x0020000
331fcf3ce44SJohn Forte 
332fcf3ce44SJohn Forte #define	SI_GET_CLASS(v)		((v) & 0xFF000000)
333fcf3ce44SJohn Forte #define	SI_GET_SUBCLASS(v)	((v) & 0x00FF0000)
334fcf3ce44SJohn Forte 
335fcf3ce44SJohn Forte /* Commands for LPORT info routines */
336fcf3ce44SJohn Forte /* XXX - Implement these. */
337fcf3ce44SJohn Forte #if 0
338fcf3ce44SJohn Forte #define	SI_LPORT_FC_PORTINFO		(SI_LPORT | SI_LPORT_FC | 1)
339fcf3ce44SJohn Forte #define	SI_RPORT_FC_PORTINFO		(SI_LPORT | SI_LPORT_FC | 2)
340fcf3ce44SJohn Forte #endif
341fcf3ce44SJohn Forte 
342fcf3ce44SJohn Forte /*
343fcf3ce44SJohn Forte  * Events
344fcf3ce44SJohn Forte  */
345fcf3ce44SJohn Forte #define	STMF_EVENT_ALL			((int)-1)
346fcf3ce44SJohn Forte #define	LPORT_EVENT_INITIAL_LUN_MAPPED	0
347fcf3ce44SJohn Forte 
348fcf3ce44SJohn Forte /*
349fcf3ce44SJohn Forte  * This needs to go into common/ddi/sunddi.h
350fcf3ce44SJohn Forte  */
351fcf3ce44SJohn Forte #define	DDI_NT_STMF		"ddi_scsi_target:framework"
352fcf3ce44SJohn Forte #define	DDI_NT_STMF_LP		"ddi_scsi_target:lu_provider"
353fcf3ce44SJohn Forte #define	DDI_NT_STMF_PP		"ddi_scsi_target:port_provider"
354fcf3ce44SJohn Forte 
355fcf3ce44SJohn Forte /*
356fcf3ce44SJohn Forte  * VPD page bits.
357fcf3ce44SJohn Forte  */
358fcf3ce44SJohn Forte #define	STMF_VPD_LU_ID		0x01
359fcf3ce44SJohn Forte #define	STMF_VPD_TARGET_ID	0x02
360fcf3ce44SJohn Forte #define	STMF_VPD_TP_GROUP	0x04
361fcf3ce44SJohn Forte #define	STMF_VPD_RELATIVE_TP_ID	0x08
362fcf3ce44SJohn Forte 
363fcf3ce44SJohn Forte /*
364fcf3ce44SJohn Forte  * Common macros to simplify coding
365fcf3ce44SJohn Forte  */
366fcf3ce44SJohn Forte #define	STMF_SEC2TICK(x_sec)	(drv_usectohz((x_sec) * 1000000))
367fcf3ce44SJohn Forte 
368fcf3ce44SJohn Forte void stmf_trace(caddr_t ident, const char *fmt, ...);
369fcf3ce44SJohn Forte void *stmf_alloc(stmf_struct_id_t sid, int additional_size, int alloc_flags);
370fcf3ce44SJohn Forte void stmf_free(void *struct_ptr);
371fcf3ce44SJohn Forte struct scsi_task *stmf_task_alloc(struct stmf_local_port *lport,
372fcf3ce44SJohn Forte     struct stmf_scsi_session *ss, uint8_t *lun, uint16_t cdb_length,
373fcf3ce44SJohn Forte     uint16_t ext_id);
374fcf3ce44SJohn Forte void stmf_post_task(scsi_task_t *task, stmf_data_buf_t *dbuf);
375fcf3ce44SJohn Forte stmf_data_buf_t *stmf_alloc_dbuf(scsi_task_t *task, uint32_t size,
376fcf3ce44SJohn Forte     uint32_t *pminsize, uint32_t flags);
377fcf3ce44SJohn Forte void stmf_free_dbuf(scsi_task_t *task, stmf_data_buf_t *dbuf);
3783fb517f7SJames Moore stmf_status_t stmf_setup_dbuf(scsi_task_t *task, stmf_data_buf_t *dbuf,
3793fb517f7SJames Moore     uint32_t flags);
3803fb517f7SJames Moore void stmf_teardown_dbuf(scsi_task_t *task, stmf_data_buf_t *dbuf);
381fcf3ce44SJohn Forte stmf_status_t stmf_xfer_data(scsi_task_t *task, stmf_data_buf_t *dbuf,
382fcf3ce44SJohn Forte     uint32_t ioflags);
383fcf3ce44SJohn Forte stmf_status_t stmf_send_scsi_status(scsi_task_t *task, uint32_t ioflags);
384fcf3ce44SJohn Forte void stmf_data_xfer_done(scsi_task_t *task, stmf_data_buf_t *dbuf,
385fcf3ce44SJohn Forte     uint32_t iof);
386fcf3ce44SJohn Forte void stmf_send_status_done(scsi_task_t *task, stmf_status_t s, uint32_t iof);
387fcf3ce44SJohn Forte void stmf_task_lu_done(scsi_task_t *task);
388fcf3ce44SJohn Forte void stmf_abort(int abort_cmd, scsi_task_t *task, stmf_status_t s, void *arg);
389fcf3ce44SJohn Forte void stmf_task_lu_aborted(scsi_task_t *task, stmf_status_t s, uint32_t iof);
390*61dfa509SRick McNeal void stmf_task_lport_aborted_unlocked(scsi_task_t *task, stmf_status_t s,
391*61dfa509SRick McNeal     uint32_t iof);
392fcf3ce44SJohn Forte stmf_status_t stmf_task_poll_lu(scsi_task_t *task, uint32_t timeout);
393fcf3ce44SJohn Forte stmf_status_t stmf_task_poll_lport(scsi_task_t *task, uint32_t timeout);
394fcf3ce44SJohn Forte stmf_status_t stmf_ctl(int cmd, void *obj, void *arg);
395fcf3ce44SJohn Forte stmf_status_t stmf_register_itl_handle(struct stmf_lu *lu, uint8_t *lun,
396fcf3ce44SJohn Forte     struct stmf_scsi_session *ss, uint64_t session_id, void *itl_handle);
397fcf3ce44SJohn Forte stmf_status_t stmf_deregister_all_lu_itl_handles(struct stmf_lu *lu);
398fcf3ce44SJohn Forte stmf_status_t stmf_get_itl_handle(struct stmf_lu *lu, uint8_t *lun,
399fcf3ce44SJohn Forte     struct stmf_scsi_session *ss, uint64_t session_id, void **itl_handle_retp);
400fcf3ce44SJohn Forte stmf_data_buf_t *stmf_handle_to_buf(scsi_task_t *task, uint8_t h);
401fcf3ce44SJohn Forte stmf_status_t stmf_lu_add_event(struct stmf_lu *lu, int eventid);
402fcf3ce44SJohn Forte stmf_status_t stmf_lu_remove_event(struct stmf_lu *lu, int eventid);
403fcf3ce44SJohn Forte stmf_status_t stmf_lport_add_event(struct stmf_local_port *lport, int eventid);
404fcf3ce44SJohn Forte stmf_status_t stmf_lport_remove_event(struct stmf_local_port *lport,
405fcf3ce44SJohn Forte     int eventid);
406fcf3ce44SJohn Forte void stmf_wwn_to_devid_desc(struct scsi_devid_desc *sdid, uint8_t *wwn,
407fcf3ce44SJohn Forte     uint8_t protocol_id);
408fcf3ce44SJohn Forte stmf_status_t stmf_scsilib_uniq_lu_id(uint32_t company_id,
409fcf3ce44SJohn Forte     struct scsi_devid_desc *lu_id);
410fdcc480aSJohn Forte stmf_status_t stmf_scsilib_uniq_lu_id2(uint32_t company_id, uint32_t host_id,
411fdcc480aSJohn Forte     struct scsi_devid_desc *lu_id);
412fcf3ce44SJohn Forte void stmf_scsilib_send_status(scsi_task_t *task, uint8_t st, uint32_t saa);
413fcf3ce44SJohn Forte uint32_t stmf_scsilib_prepare_vpd_page83(scsi_task_t *task, uint8_t *page,
414fcf3ce44SJohn Forte 		uint32_t page_len, uint8_t byte0, uint32_t vpd_mask);
4158fe96085Stim szeto uint16_t stmf_scsilib_get_lport_rtid(struct scsi_devid_desc *devid);
4168fe96085Stim szeto struct scsi_devid_desc *stmf_scsilib_get_devid_desc(uint16_t rtpid);
417fcf3ce44SJohn Forte void stmf_scsilib_handle_report_tpgs(scsi_task_t *task, stmf_data_buf_t *dbuf);
418fcf3ce44SJohn Forte void stmf_scsilib_handle_task_mgmt(scsi_task_t *task);
419fcf3ce44SJohn Forte 
420716c1805SNattuvetty Bhavyan struct stmf_remote_port *stmf_scsilib_devid_to_remote_port(
421716c1805SNattuvetty Bhavyan     struct scsi_devid_desc *);
422716c1805SNattuvetty Bhavyan boolean_t stmf_scsilib_tptid_validate(struct scsi_transport_id *,
423716c1805SNattuvetty Bhavyan     uint32_t, uint16_t *);
424716c1805SNattuvetty Bhavyan boolean_t stmf_scsilib_tptid_compare(struct scsi_transport_id *,
425716c1805SNattuvetty Bhavyan     struct scsi_transport_id *);
426716c1805SNattuvetty Bhavyan struct stmf_remote_port *stmf_remote_port_alloc(uint16_t);
427716c1805SNattuvetty Bhavyan void stmf_remote_port_free(struct stmf_remote_port *);
428*61dfa509SRick McNeal struct stmf_lu *stmf_check_and_hold_lu(struct scsi_task *task, uint8_t *guid);
429*61dfa509SRick McNeal void stmf_release_lu(struct stmf_lu *lu);
430*61dfa509SRick McNeal int stmf_is_task_being_aborted(struct scsi_task *task);
431fcf3ce44SJohn Forte #ifdef	__cplusplus
432fcf3ce44SJohn Forte }
433fcf3ce44SJohn Forte #endif
434fcf3ce44SJohn Forte 
435fcf3ce44SJohn Forte #endif	/* _STMF_H */
436