xref: /illumos-gate/usr/src/uts/common/sys/sbp2/driver.h (revision 7c478bd9)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate #ifndef	_SYS_SBP2_DRIVER_H
28*7c478bd9Sstevel@tonic-gate #define	_SYS_SBP2_DRIVER_H
29*7c478bd9Sstevel@tonic-gate 
30*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
31*7c478bd9Sstevel@tonic-gate 
32*7c478bd9Sstevel@tonic-gate /*
33*7c478bd9Sstevel@tonic-gate  * Serial Bus Protocol 2 (SBP-2) driver interfaces
34*7c478bd9Sstevel@tonic-gate  */
35*7c478bd9Sstevel@tonic-gate 
36*7c478bd9Sstevel@tonic-gate #include <sys/sbp2/defs.h>
37*7c478bd9Sstevel@tonic-gate #include <sys/sbp2/bus.h>
38*7c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h>
39*7c478bd9Sstevel@tonic-gate #include <sys/note.h>
40*7c478bd9Sstevel@tonic-gate 
41*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
42*7c478bd9Sstevel@tonic-gate extern "C" {
43*7c478bd9Sstevel@tonic-gate #endif
44*7c478bd9Sstevel@tonic-gate 
45*7c478bd9Sstevel@tonic-gate /*
46*7c478bd9Sstevel@tonic-gate  * Config ROM definitions
47*7c478bd9Sstevel@tonic-gate  *
48*7c478bd9Sstevel@tonic-gate  * bus info block
49*7c478bd9Sstevel@tonic-gate  */
50*7c478bd9Sstevel@tonic-gate typedef struct sbp2_cfgrom_bib {
51*7c478bd9Sstevel@tonic-gate 	int			cb_len;		/* info_length */
52*7c478bd9Sstevel@tonic-gate 	uint32_t		*cb_buf;	/* data buffer */
53*7c478bd9Sstevel@tonic-gate } sbp2_cfgrom_bib_t;
54*7c478bd9Sstevel@tonic-gate 
55*7c478bd9Sstevel@tonic-gate /* directory */
56*7c478bd9Sstevel@tonic-gate typedef struct sbp2_cfgrom_dir {
57*7c478bd9Sstevel@tonic-gate 	struct sbp2_cfgrom_ent	*cd_ent;	/* array of entries */
58*7c478bd9Sstevel@tonic-gate 	int			cd_cnt;		/* # of entries with data */
59*7c478bd9Sstevel@tonic-gate 	int			cd_size;	/* # of allocated entries */
60*7c478bd9Sstevel@tonic-gate } sbp2_cfgrom_dir_t;
61*7c478bd9Sstevel@tonic-gate 
62*7c478bd9Sstevel@tonic-gate /* directory entry */
63*7c478bd9Sstevel@tonic-gate typedef struct sbp2_cfgrom_ent {
64*7c478bd9Sstevel@tonic-gate 	uint8_t			ce_kt;		/* key type */
65*7c478bd9Sstevel@tonic-gate 	uint8_t			ce_kv;		/* key value */
66*7c478bd9Sstevel@tonic-gate 	uint16_t		ce_len;		/* length in quadlets */
67*7c478bd9Sstevel@tonic-gate 	uint64_t		ce_offset;	/* entry's CSR offset */
68*7c478bd9Sstevel@tonic-gate 	struct sbp2_cfgrom_ent	*ce_ref;	/* referred entry (text leaf) */
69*7c478bd9Sstevel@tonic-gate 	union {					/* data depends on key type: */
70*7c478bd9Sstevel@tonic-gate 		uint32_t	imm;		/* immediate value */
71*7c478bd9Sstevel@tonic-gate 		uint32_t	offset;		/* CSR offset */
72*7c478bd9Sstevel@tonic-gate 		uint32_t	*leaf;		/* leaf */
73*7c478bd9Sstevel@tonic-gate 		sbp2_cfgrom_dir_t dir;		/* directory */
74*7c478bd9Sstevel@tonic-gate 	} ce_data;
75*7c478bd9Sstevel@tonic-gate } sbp2_cfgrom_ent_t;
76*7c478bd9Sstevel@tonic-gate 
77*7c478bd9Sstevel@tonic-gate /* entire Config ROM */
78*7c478bd9Sstevel@tonic-gate typedef struct sbp2_cfgrom {
79*7c478bd9Sstevel@tonic-gate 	sbp2_cfgrom_bib_t	cr_bib;		/* bus info block */
80*7c478bd9Sstevel@tonic-gate 	sbp2_cfgrom_ent_t	cr_root;	/* root directory */
81*7c478bd9Sstevel@tonic-gate } sbp2_cfgrom_t;
82*7c478bd9Sstevel@tonic-gate 
83*7c478bd9Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("stable data", {
84*7c478bd9Sstevel@tonic-gate     sbp2_cfgrom_bib sbp2_cfgrom_dir sbp2_cfgrom_ent sbp2_cfgrom }))
85*7c478bd9Sstevel@tonic-gate 
86*7c478bd9Sstevel@tonic-gate /*
87*7c478bd9Sstevel@tonic-gate  * SBP-2 definitions
88*7c478bd9Sstevel@tonic-gate  */
89*7c478bd9Sstevel@tonic-gate 
90*7c478bd9Sstevel@tonic-gate /* task states */
91*7c478bd9Sstevel@tonic-gate typedef enum {
92*7c478bd9Sstevel@tonic-gate 	SBP2_TASK_INIT,		/* initial state */
93*7c478bd9Sstevel@tonic-gate 	SBP2_TASK_PEND,		/* put on the list, pending completion */
94*7c478bd9Sstevel@tonic-gate 	SBP2_TASK_COMP,		/* task completed */
95*7c478bd9Sstevel@tonic-gate 	SBP2_TASK_PROC		/* status being processed */
96*7c478bd9Sstevel@tonic-gate } sbp2_task_state_t;
97*7c478bd9Sstevel@tonic-gate 
98*7c478bd9Sstevel@tonic-gate /* task errors */
99*7c478bd9Sstevel@tonic-gate typedef enum {
100*7c478bd9Sstevel@tonic-gate 	SBP2_TASK_ERR_NONE,	/* no error */
101*7c478bd9Sstevel@tonic-gate 	SBP2_TASK_ERR_DEAD,	/* agent dead */
102*7c478bd9Sstevel@tonic-gate 	SBP2_TASK_ERR_BUS,	/* bus error */
103*7c478bd9Sstevel@tonic-gate 	SBP2_TASK_ERR_TIMEOUT,	/* timed out */
104*7c478bd9Sstevel@tonic-gate 	SBP2_TASK_ERR_ABORT,	/* task aborted */
105*7c478bd9Sstevel@tonic-gate 	SBP2_TASK_ERR_LUN_RESET, /* lun reset */
106*7c478bd9Sstevel@tonic-gate 	SBP2_TASK_ERR_TGT_RESET	/* target reset */
107*7c478bd9Sstevel@tonic-gate } sbp2_task_error;
108*7c478bd9Sstevel@tonic-gate 
109*7c478bd9Sstevel@tonic-gate /*
110*7c478bd9Sstevel@tonic-gate  * task
111*7c478bd9Sstevel@tonic-gate  */
112*7c478bd9Sstevel@tonic-gate typedef struct sbp2_task {
113*7c478bd9Sstevel@tonic-gate 	struct sbp2_task	*ts_next;	/* next task */
114*7c478bd9Sstevel@tonic-gate 	struct sbp2_task	*ts_prev;	/* previous task */
115*7c478bd9Sstevel@tonic-gate 	struct sbp2_ses		*ts_ses;	/* session we belong to */
116*7c478bd9Sstevel@tonic-gate 	void			*ts_drv_priv;	/* driver private data */
117*7c478bd9Sstevel@tonic-gate 	sbp2_bus_buf_t		*ts_buf;	/* bus buffer */
118*7c478bd9Sstevel@tonic-gate 	int			ts_timeout;	/* task timeout in seconds */
119*7c478bd9Sstevel@tonic-gate 	timeout_id_t		ts_timeout_id;	/* timeout ID */
120*7c478bd9Sstevel@tonic-gate 	sbp2_task_state_t	ts_state;	/* task state */
121*7c478bd9Sstevel@tonic-gate 	sbp2_task_error		ts_error;	/* error */
122*7c478bd9Sstevel@tonic-gate 	int			ts_bus_error;	/* bus error */
123*7c478bd9Sstevel@tonic-gate 	sbp2_status_t		ts_status;	/* status block */
124*7c478bd9Sstevel@tonic-gate 	hrtime_t		ts_time_start;
125*7c478bd9Sstevel@tonic-gate 	hrtime_t		ts_time_comp;
126*7c478bd9Sstevel@tonic-gate } sbp2_task_t;
127*7c478bd9Sstevel@tonic-gate 
128*7c478bd9Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("unique per call", sbp2_task))
129*7c478bd9Sstevel@tonic-gate 
130*7c478bd9Sstevel@tonic-gate /* fetch agent */
131*7c478bd9Sstevel@tonic-gate typedef struct sbp2_agent {
132*7c478bd9Sstevel@tonic-gate 	struct sbp2_tgt		*a_tgt;		/* target we belong to */
133*7c478bd9Sstevel@tonic-gate 	kmutex_t		a_mutex;	/* structure mutex */
134*7c478bd9Sstevel@tonic-gate 	uint16_t		a_state;	/* current agent state */
135*7c478bd9Sstevel@tonic-gate 	kcondvar_t		a_cv;		/* agent state cv */
136*7c478bd9Sstevel@tonic-gate 	boolean_t		a_acquired;	/* acquired flag */
137*7c478bd9Sstevel@tonic-gate 
138*7c478bd9Sstevel@tonic-gate 	/* commands */
139*7c478bd9Sstevel@tonic-gate 	void			*a_cmd;		/* fetch agent cmd */
140*7c478bd9Sstevel@tonic-gate 	mblk_t			*a_cmd_data;	/* cmd data */
141*7c478bd9Sstevel@tonic-gate 
142*7c478bd9Sstevel@tonic-gate 	sbp2_task_t		*a_active_task;	/* active task */
143*7c478bd9Sstevel@tonic-gate 
144*7c478bd9Sstevel@tonic-gate 	/* register offsets */
145*7c478bd9Sstevel@tonic-gate 	uint64_t		a_reg_agent_state; /* AGENT_STATE */
146*7c478bd9Sstevel@tonic-gate 	uint64_t		a_reg_agent_reset; /* AGENT_RESET */
147*7c478bd9Sstevel@tonic-gate 	uint64_t		a_reg_orbp;	/* ORB_POINTER */
148*7c478bd9Sstevel@tonic-gate 	uint64_t		a_reg_doorbell;	/* DOORBELL */
149*7c478bd9Sstevel@tonic-gate 	uint64_t		a_reg_unsol_status_enable;
150*7c478bd9Sstevel@tonic-gate 						/* UNSOLICITED_STATUS_ENABLE */
151*7c478bd9Sstevel@tonic-gate } sbp2_agent_t;
152*7c478bd9Sstevel@tonic-gate 
153*7c478bd9Sstevel@tonic-gate _NOTE(MUTEX_PROTECTS_DATA(sbp2_agent::a_mutex, sbp2_agent))
154*7c478bd9Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("stable data", sbp2_agent::{
155*7c478bd9Sstevel@tonic-gate     a_tgt a_reg_agent_state a_reg_agent_reset a_reg_orbp a_reg_doorbell
156*7c478bd9Sstevel@tonic-gate     a_reg_unsol_status_enable }))
157*7c478bd9Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("a_acquired", sbp2_agent::{
158*7c478bd9Sstevel@tonic-gate     a_cmd a_cmd_data a_active_task }))
159*7c478bd9Sstevel@tonic-gate 
160*7c478bd9Sstevel@tonic-gate /* session is a period between login and logout */
161*7c478bd9Sstevel@tonic-gate typedef struct sbp2_ses {
162*7c478bd9Sstevel@tonic-gate 	struct sbp2_tgt		*s_tgt;		/* target we belong to */
163*7c478bd9Sstevel@tonic-gate 	struct sbp2_lun		*s_lun;		/* unit we belong to */
164*7c478bd9Sstevel@tonic-gate 	kmutex_t		s_mutex;	/* structure mutex */
165*7c478bd9Sstevel@tonic-gate 	struct sbp2_ses		*s_next;	/* next session */
166*7c478bd9Sstevel@tonic-gate 
167*7c478bd9Sstevel@tonic-gate 	uint16_t		s_id;		/* login ID */
168*7c478bd9Sstevel@tonic-gate 	uint64_t		s_agent_offset;	/* fetch agent offset */
169*7c478bd9Sstevel@tonic-gate 	sbp2_agent_t		s_agent;	/* fetch agent */
170*7c478bd9Sstevel@tonic-gate 	sbp2_bus_buf_t		s_status_fifo_buf; /* status FIFO */
171*7c478bd9Sstevel@tonic-gate 
172*7c478bd9Sstevel@tonic-gate 	/* task list (command ORB's) */
173*7c478bd9Sstevel@tonic-gate 	kmutex_t		s_task_mutex;		/* protects task list */
174*7c478bd9Sstevel@tonic-gate 	sbp2_task_t		*s_task_head;		/* first on the list */
175*7c478bd9Sstevel@tonic-gate 	sbp2_task_t		*s_task_tail;		/* last on the list */
176*7c478bd9Sstevel@tonic-gate 	int			s_task_cnt;		/* # tasks */
177*7c478bd9Sstevel@tonic-gate 	void			(*s_status_cb)(void *, sbp2_task_t *);
178*7c478bd9Sstevel@tonic-gate 	void			*s_status_cb_arg;
179*7c478bd9Sstevel@tonic-gate } sbp2_ses_t;
180*7c478bd9Sstevel@tonic-gate 
181*7c478bd9Sstevel@tonic-gate _NOTE(MUTEX_PROTECTS_DATA(sbp2_ses::s_mutex, sbp2_ses))
182*7c478bd9Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("stable data", sbp2_ses::{
183*7c478bd9Sstevel@tonic-gate     s_tgt s_lun s_id s_agent_offset s_agent s_status_fifo_buf s_status_cb
184*7c478bd9Sstevel@tonic-gate     s_status_cb_arg }))
185*7c478bd9Sstevel@tonic-gate _NOTE(MUTEX_PROTECTS_DATA(sbp2_ses::s_task_mutex, sbp2_ses::{
186*7c478bd9Sstevel@tonic-gate     s_task_head s_task_tail s_task_cnt }))
187*7c478bd9Sstevel@tonic-gate _NOTE(MUTEX_PROTECTS_DATA(sbp2_ses::s_task_mutex, sbp2_task::{
188*7c478bd9Sstevel@tonic-gate     ts_next ts_prev }))
189*7c478bd9Sstevel@tonic-gate 
190*7c478bd9Sstevel@tonic-gate /* buffer list */
191*7c478bd9Sstevel@tonic-gate typedef struct sbp2_buf_list {
192*7c478bd9Sstevel@tonic-gate 	kmutex_t		bl_mutex;
193*7c478bd9Sstevel@tonic-gate 	int			bl_len;		/* number of elements */
194*7c478bd9Sstevel@tonic-gate 	sbp2_bus_buf_t		*bl_head;	/* first element */
195*7c478bd9Sstevel@tonic-gate 	sbp2_bus_buf_t		*bl_tail;	/* last element */
196*7c478bd9Sstevel@tonic-gate } sbp2_buf_list_t;
197*7c478bd9Sstevel@tonic-gate 
198*7c478bd9Sstevel@tonic-gate /* logical unit */
199*7c478bd9Sstevel@tonic-gate typedef struct sbp2_lun {
200*7c478bd9Sstevel@tonic-gate 	struct sbp2_tgt		*l_tgt;		/* target we belong to */
201*7c478bd9Sstevel@tonic-gate 	uint16_t		l_lun;		/* logical unit number */
202*7c478bd9Sstevel@tonic-gate 	uint8_t			l_type;		/* device type */
203*7c478bd9Sstevel@tonic-gate 	sbp2_ses_t		*l_ses;		/* login sessions */
204*7c478bd9Sstevel@tonic-gate 	sbp2_buf_list_t		l_orb_freelist;	/* ORB freelist */
205*7c478bd9Sstevel@tonic-gate 
206*7c478bd9Sstevel@tonic-gate 
207*7c478bd9Sstevel@tonic-gate 	sbp2_login_resp_t	l_login_resp;	/* login response */
208*7c478bd9Sstevel@tonic-gate 	boolean_t		l_logged_in;	/* true if logged in */
209*7c478bd9Sstevel@tonic-gate 	boolean_t		l_reconnecting;	/* true if being reconnected */
210*7c478bd9Sstevel@tonic-gate } sbp2_lun_t;
211*7c478bd9Sstevel@tonic-gate 
212*7c478bd9Sstevel@tonic-gate enum {
213*7c478bd9Sstevel@tonic-gate 	SBP2_ORB_FREELIST_MAX	= 3	/* max # of elements on freelist */
214*7c478bd9Sstevel@tonic-gate };
215*7c478bd9Sstevel@tonic-gate 
216*7c478bd9Sstevel@tonic-gate /* per-target statistics */
217*7c478bd9Sstevel@tonic-gate typedef struct sbp2_tgt_stat {
218*7c478bd9Sstevel@tonic-gate 	hrtime_t		stat_cfgrom_last_parse_time;
219*7c478bd9Sstevel@tonic-gate 	uint_t			stat_submit_orbp;
220*7c478bd9Sstevel@tonic-gate 	uint_t			stat_submit_doorbell;
221*7c478bd9Sstevel@tonic-gate 	uint_t			stat_status_dead;
222*7c478bd9Sstevel@tonic-gate 	uint_t			stat_status_short;
223*7c478bd9Sstevel@tonic-gate 	uint_t			stat_status_unsolicited;
224*7c478bd9Sstevel@tonic-gate 	uint_t			stat_status_notask;
225*7c478bd9Sstevel@tonic-gate 	uint_t			stat_status_mgt_notask;
226*7c478bd9Sstevel@tonic-gate 	uint_t			stat_agent_worbp;
227*7c478bd9Sstevel@tonic-gate 	uint_t			stat_agent_worbp_fail;
228*7c478bd9Sstevel@tonic-gate 	uint_t			stat_agent_wreset;
229*7c478bd9Sstevel@tonic-gate 	uint_t			stat_agent_wreset_fail;
230*7c478bd9Sstevel@tonic-gate 	uint_t			stat_task_max;
231*7c478bd9Sstevel@tonic-gate } sbp2_tgt_stat_t;
232*7c478bd9Sstevel@tonic-gate 
233*7c478bd9Sstevel@tonic-gate /* target */
234*7c478bd9Sstevel@tonic-gate typedef struct sbp2_tgt {
235*7c478bd9Sstevel@tonic-gate 	struct sbp2_bus		*t_bus;			/* bus */
236*7c478bd9Sstevel@tonic-gate 	void			*t_bus_hdl;		/* bus handle */
237*7c478bd9Sstevel@tonic-gate 	kmutex_t		t_mutex;		/* structure mutex */
238*7c478bd9Sstevel@tonic-gate 	sbp2_lun_t		*t_lun;			/* logical unit array */
239*7c478bd9Sstevel@tonic-gate 	int			t_nluns;		/* # logical units */
240*7c478bd9Sstevel@tonic-gate 	int			t_nluns_alloc;		/* # luns allocated */
241*7c478bd9Sstevel@tonic-gate 
242*7c478bd9Sstevel@tonic-gate 	/* congif ROM */
243*7c478bd9Sstevel@tonic-gate 	sbp2_cfgrom_t		t_cfgrom;		/* parsed cfgrom */
244*7c478bd9Sstevel@tonic-gate 	hrtime_t		t_last_cfgrd;		/* cfgrom timestamp */
245*7c478bd9Sstevel@tonic-gate 	int			t_orb_size;		/* ORB_size */
246*7c478bd9Sstevel@tonic-gate 
247*7c478bd9Sstevel@tonic-gate 	/* management agent */
248*7c478bd9Sstevel@tonic-gate 	uint64_t		t_mgt_agent;		/* mgt agent address */
249*7c478bd9Sstevel@tonic-gate 	int			t_mot;			/* mgt timeout, ms */
250*7c478bd9Sstevel@tonic-gate 	boolean_t		t_mgt_agent_acquired;	/* acquired flag */
251*7c478bd9Sstevel@tonic-gate 	kcondvar_t		t_mgt_agent_cv;		/* cv for busy flag */
252*7c478bd9Sstevel@tonic-gate 	sbp2_bus_buf_t		t_mgt_orb_buf;		/* mgt ORB */
253*7c478bd9Sstevel@tonic-gate 	void			*t_mgt_cmd;		/* command */
254*7c478bd9Sstevel@tonic-gate 	mblk_t			*t_mgt_cmd_data;	/* command data */
255*7c478bd9Sstevel@tonic-gate 	sbp2_bus_buf_t		t_mgt_status_fifo_buf;	/* status FIFO buf */
256*7c478bd9Sstevel@tonic-gate 	sbp2_status_t		t_mgt_status;		/* status block */
257*7c478bd9Sstevel@tonic-gate 	boolean_t		t_mgt_status_rcvd;	/* status received? */
258*7c478bd9Sstevel@tonic-gate 	kcondvar_t		t_mgt_status_cv;	/* status FIFO cv */
259*7c478bd9Sstevel@tonic-gate 	sbp2_bus_buf_t		t_mgt_login_resp_buf;	/* login response */
260*7c478bd9Sstevel@tonic-gate 
261*7c478bd9Sstevel@tonic-gate 	sbp2_tgt_stat_t		t_stat;			/* statistics */
262*7c478bd9Sstevel@tonic-gate } sbp2_tgt_t;
263*7c478bd9Sstevel@tonic-gate 
264*7c478bd9Sstevel@tonic-gate _NOTE(MUTEX_PROTECTS_DATA(sbp2_tgt::t_mutex, sbp2_tgt))
265*7c478bd9Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("stable data", sbp2_tgt::{
266*7c478bd9Sstevel@tonic-gate     t_bus t_bus_hdl t_lun t_nluns t_nluns_alloc t_cfgrom t_last_cfgrd
267*7c478bd9Sstevel@tonic-gate     t_orb_size t_mgt_agent t_mot }))
268*7c478bd9Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("t_mgt_agent_cv", sbp2_tgt::{
269*7c478bd9Sstevel@tonic-gate     t_mgt_orb_buf t_mgt_cmd t_mgt_cmd_data t_mgt_status_fifo_buf
270*7c478bd9Sstevel@tonic-gate     t_mgt_status_rcvd t_mgt_login_resp_buf }))
271*7c478bd9Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("statistics", sbp2_tgt::t_stat))
272*7c478bd9Sstevel@tonic-gate 
273*7c478bd9Sstevel@tonic-gate _NOTE(MUTEX_PROTECTS_DATA(sbp2_tgt::t_mutex, sbp2_lun))
274*7c478bd9Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("stable data", sbp2_lun::{
275*7c478bd9Sstevel@tonic-gate     l_tgt l_lun l_type l_ses }))
276*7c478bd9Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("t_mgt_agent_cv", sbp2_lun::l_login_resp))
277*7c478bd9Sstevel@tonic-gate 
278*7c478bd9Sstevel@tonic-gate _NOTE(LOCK_ORDER(sbp2_tgt::t_mutex sbp2_ses::s_mutex))
279*7c478bd9Sstevel@tonic-gate _NOTE(LOCK_ORDER(sbp2_tgt::t_mutex sbp2_ses::s_task_mutex))
280*7c478bd9Sstevel@tonic-gate _NOTE(LOCK_ORDER(sbp2_tgt::t_mutex sbp2_agent::a_mutex))
281*7c478bd9Sstevel@tonic-gate 
282*7c478bd9Sstevel@tonic-gate #define	SBP2_ORB_SIZE_ROUNDUP(tp, size) roundup(size, (tp)->t_orb_size)
283*7c478bd9Sstevel@tonic-gate 
284*7c478bd9Sstevel@tonic-gate /* walker flags */
285*7c478bd9Sstevel@tonic-gate enum {
286*7c478bd9Sstevel@tonic-gate 	SBP2_WALK_DIRONLY	= 0x01	/* walk directories only */
287*7c478bd9Sstevel@tonic-gate };
288*7c478bd9Sstevel@tonic-gate 
289*7c478bd9Sstevel@tonic-gate /* walker return codes */
290*7c478bd9Sstevel@tonic-gate enum {
291*7c478bd9Sstevel@tonic-gate 	SBP2_WALK_CONTINUE,
292*7c478bd9Sstevel@tonic-gate 	SBP2_WALK_STOP
293*7c478bd9Sstevel@tonic-gate };
294*7c478bd9Sstevel@tonic-gate 
295*7c478bd9Sstevel@tonic-gate int sbp2_tgt_init(void *, struct sbp2_bus *, int, sbp2_tgt_t **);
296*7c478bd9Sstevel@tonic-gate void sbp2_tgt_fini(sbp2_tgt_t *);
297*7c478bd9Sstevel@tonic-gate void sbp2_tgt_disconnect(sbp2_tgt_t *);
298*7c478bd9Sstevel@tonic-gate int sbp2_tgt_reconnect(sbp2_tgt_t *);
299*7c478bd9Sstevel@tonic-gate int sbp2_tgt_reset(sbp2_tgt_t *, int *);
300*7c478bd9Sstevel@tonic-gate int sbp2_tgt_get_cfgrom(sbp2_tgt_t *, sbp2_cfgrom_t **);
301*7c478bd9Sstevel@tonic-gate int sbp2_tgt_get_lun_cnt(sbp2_tgt_t *);
302*7c478bd9Sstevel@tonic-gate sbp2_lun_t *sbp2_tgt_get_lun(sbp2_tgt_t *, int);
303*7c478bd9Sstevel@tonic-gate 
304*7c478bd9Sstevel@tonic-gate int sbp2_lun_reset(sbp2_lun_t *, int *);
305*7c478bd9Sstevel@tonic-gate int sbp2_lun_login(sbp2_lun_t *, sbp2_ses_t **, void (*)(void *, sbp2_task_t *),
306*7c478bd9Sstevel@tonic-gate     void *, int *);
307*7c478bd9Sstevel@tonic-gate int sbp2_lun_logout(sbp2_lun_t *, sbp2_ses_t **, int *, boolean_t);
308*7c478bd9Sstevel@tonic-gate 
309*7c478bd9Sstevel@tonic-gate int sbp2_ses_reconnect(sbp2_ses_t *, int *, uint16_t);
310*7c478bd9Sstevel@tonic-gate int sbp2_ses_submit_task(sbp2_ses_t *, sbp2_task_t *);
311*7c478bd9Sstevel@tonic-gate void sbp2_ses_nudge(sbp2_ses_t *);
312*7c478bd9Sstevel@tonic-gate int sbp2_ses_remove_task(sbp2_ses_t *, sbp2_task_t *);
313*7c478bd9Sstevel@tonic-gate sbp2_task_t *sbp2_ses_find_task_state(sbp2_ses_t *, sbp2_task_state_t);
314*7c478bd9Sstevel@tonic-gate sbp2_task_t *sbp2_ses_remove_first_task(sbp2_ses_t *);
315*7c478bd9Sstevel@tonic-gate sbp2_task_t *sbp2_ses_remove_first_task_state(sbp2_ses_t *, sbp2_task_state_t);
316*7c478bd9Sstevel@tonic-gate sbp2_task_t *sbp2_ses_cancel_first_task(sbp2_ses_t *);
317*7c478bd9Sstevel@tonic-gate int sbp2_ses_agent_reset(sbp2_ses_t *, int *);
318*7c478bd9Sstevel@tonic-gate int sbp2_ses_abort_task(sbp2_ses_t *, sbp2_task_t *, int *);
319*7c478bd9Sstevel@tonic-gate int sbp2_ses_abort_task_set(sbp2_ses_t *, int *);
320*7c478bd9Sstevel@tonic-gate 
321*7c478bd9Sstevel@tonic-gate int sbp2_task_orb_alloc(sbp2_lun_t *, sbp2_task_t *, int);
322*7c478bd9Sstevel@tonic-gate void sbp2_task_orb_free(sbp2_lun_t *, sbp2_task_t *);
323*7c478bd9Sstevel@tonic-gate void *sbp2_task_orb_kaddr(sbp2_task_t *);
324*7c478bd9Sstevel@tonic-gate void sbp2_task_orb_sync(sbp2_lun_t *, sbp2_task_t *, int);
325*7c478bd9Sstevel@tonic-gate 
326*7c478bd9Sstevel@tonic-gate void sbp2_swap32_buf(uint32_t *, int);
327*7c478bd9Sstevel@tonic-gate 
328*7c478bd9Sstevel@tonic-gate void sbp2_cfgrom_walk(sbp2_cfgrom_ent_t *,
329*7c478bd9Sstevel@tonic-gate     int (*)(void *, sbp2_cfgrom_ent_t *, int), void *);
330*7c478bd9Sstevel@tonic-gate sbp2_cfgrom_ent_t *sbp2_cfgrom_ent_by_key(sbp2_cfgrom_ent_t *, int8_t, int8_t,
331*7c478bd9Sstevel@tonic-gate     int);
332*7c478bd9Sstevel@tonic-gate 
333*7c478bd9Sstevel@tonic-gate 
334*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
335*7c478bd9Sstevel@tonic-gate }
336*7c478bd9Sstevel@tonic-gate #endif
337*7c478bd9Sstevel@tonic-gate 
338*7c478bd9Sstevel@tonic-gate #endif	/* _SYS_SBP2_DRIVER_H */
339