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 _ISCSI_STATS_H
27*fcf3ce44SJohn Forte #define	_ISCSI_STATS_H
28*fcf3ce44SJohn Forte 
29*fcf3ce44SJohn Forte #ifdef __cplusplus
30*fcf3ce44SJohn Forte extern "C" {
31*fcf3ce44SJohn Forte #endif
32*fcf3ce44SJohn Forte 
33*fcf3ce44SJohn Forte /*
34*fcf3ce44SJohn Forte  * This file contains all the definitions and prototypes relevant to KSTAT.
35*fcf3ce44SJohn Forte  * It also contains the declaration and initialization of data.  When including
36*fcf3ce44SJohn Forte  * this file, if _INIT_KSTAT_DATA_ is defined, the data is declared AND
37*fcf3ce44SJohn Forte  * initialized. As a consequence, this file should be included only once with
38*fcf3ce44SJohn Forte  * _INIT_KSTAT_DATA_ defined.  Failure to do so will lead to a link error.
39*fcf3ce44SJohn Forte  * Today, iscsi_stats.c is the only file defining _INIT_KSTAT_DATA_.
40*fcf3ce44SJohn Forte  *
41*fcf3ce44SJohn Forte  * Four types of KSTAT structures are created for iSCSI.
42*fcf3ce44SJohn Forte  *
43*fcf3ce44SJohn Forte  *   sun_iscsi_hba
44*fcf3ce44SJohn Forte  *   -------------
45*fcf3ce44SJohn Forte  *
46*fcf3ce44SJohn Forte  *	This structure gathers statistics relevant to an HBA. Each HBA or
47*fcf3ce44SJohn Forte  *	software state structure is given one.  It contains the following
48*fcf3ce44SJohn Forte  *	fieds:
49*fcf3ce44SJohn Forte  *
50*fcf3ce44SJohn Forte  *	  _name			iSCSI name of the HBA
51*fcf3ce44SJohn Forte  *	  _alias		iSCSI alias of the HBA
52*fcf3ce44SJohn Forte  *	  _cntr_sess		Numbers of sessions created
53*fcf3ce44SJohn Forte  *
54*fcf3ce44SJohn Forte  *   sun_iscsi_sess
55*fcf3ce44SJohn Forte  *   --------------
56*fcf3ce44SJohn Forte  *
57*fcf3ce44SJohn Forte  *	This structure gathers statistics relevant to a session.  Each session
58*fcf3ce44SJohn Forte  *	is given one.  It contains the following fields:
59*fcf3ce44SJohn Forte  *
60*fcf3ce44SJohn Forte  *	  _state		State of the session
61*fcf3ce44SJohn Forte  *	  _oid			OID of the session
62*fcf3ce44SJohn Forte  *	  _hba			HBA the session belongs to.  It is the name
63*fcf3ce44SJohn Forte  *				of the sun_iscsi_hba structure of the HBA
64*fcf3ce44SJohn Forte  *	  _cntr_conn		Number of connections
65*fcf3ce44SJohn Forte  *	  _cntr_pkt_pending	Number of scsi_pkt in the pending queue
66*fcf3ce44SJohn Forte  *	  _cmd_sn		CmdSN
67*fcf3ce44SJohn Forte  *	  _cmd_sn_exp		CmdSNExp,
68*fcf3ce44SJohn Forte  *	  _cmd_sn_max		CmdSNMax
69*fcf3ce44SJohn Forte  *
70*fcf3ce44SJohn Forte  *   sun_iscsi_sess_io
71*fcf3ce44SJohn Forte  *   -----------------
72*fcf3ce44SJohn Forte  *
73*fcf3ce44SJohn Forte  *	This structure is completely defined by the KSTAT frame work of Solaris.
74*fcf3ce44SJohn Forte  *	It contains accumulated time and queue length statistics.  It assumes
75*fcf3ce44SJohn Forte  *	the driver has a pending queue and an active.  In our implementation,
76*fcf3ce44SJohn Forte  *	the pending queue is the pending queue defined in the session context.
77*fcf3ce44SJohn Forte  *	The active queue is any queue defined in the connection context.
78*fcf3ce44SJohn Forte  *	If you want more information about the meaning of the fields of this
79*fcf3ce44SJohn Forte  *	structure you can read the nice explanation contained in the file:
80*fcf3ce44SJohn Forte  *	/usr/src/uts/common/sys/kstat.h.
81*fcf3ce44SJohn Forte  *	At any rate, all the sessions are given a sun_iscsi_sess_io structure.
82*fcf3ce44SJohn Forte  *	The fields are:
83*fcf3ce44SJohn Forte  *
84*fcf3ce44SJohn Forte  *	  nread			number of bytes read without iSCSI overhead.
85*fcf3ce44SJohn Forte  *	  nwritten		number of bytes written without iSCSI overhead.
86*fcf3ce44SJohn Forte  *	  reads			number of read operations
87*fcf3ce44SJohn Forte  *	  writes		number of write operations
88*fcf3ce44SJohn Forte  *	  wtime			cumulative wait (pre-service) time
89*fcf3ce44SJohn Forte  *	  wlentime		cumulative wait length*time product
90*fcf3ce44SJohn Forte  *	  wlastupdate		last time wait queue changed
91*fcf3ce44SJohn Forte  *	  rtime			cumulative run (service) time
92*fcf3ce44SJohn Forte  *	  rlentime		cumulative run length*time product
93*fcf3ce44SJohn Forte  *	  rlastupdate		last time run queue changed
94*fcf3ce44SJohn Forte  *	  wcnt			count of elements in wait state
95*fcf3ce44SJohn Forte  *	  rcnt			count of elements in run state
96*fcf3ce44SJohn Forte  *
97*fcf3ce44SJohn Forte  *	The time is expressed in nanoseconds.
98*fcf3ce44SJohn Forte  *
99*fcf3ce44SJohn Forte  *   sun_iscsi_conn
100*fcf3ce44SJohn Forte  *   --------------
101*fcf3ce44SJohn Forte  *
102*fcf3ce44SJohn Forte  *	This structure gathers statistics relevant to a connection.  Each
103*fcf3ce44SJohn Forte  *      connection is given one.  It contains the following fields:
104*fcf3ce44SJohn Forte  *
105*fcf3ce44SJohn Forte  *	  _state		State of the connection
106*fcf3ce44SJohn Forte  *	  _cid			iSCSI CID
107*fcf3ce44SJohn Forte  *	  _oid			OID of the connection
108*fcf3ce44SJohn Forte  *	  _session		Session the connection belongs to.  It is the
109*fcf3ce44SJohn Forte  *				name of the sun_iscsi_sess structure of the
110*fcf3ce44SJohn Forte  *				session.
111*fcf3ce44SJohn Forte  *	  _err_header_digest	Number of header digest errors
112*fcf3ce44SJohn Forte  *	  _err_data_digest	Number of data digest errors
113*fcf3ce44SJohn Forte  *	  _err_connection_reset	Number of reset
114*fcf3ce44SJohn Forte  *	  _err_protocol_error	Number of protocol errors
115*fcf3ce44SJohn Forte  *	  _cntr_tx_bytes	Number of bytes transmitted with iSCSI overhead.
116*fcf3ce44SJohn Forte  *	  _cntr_rx_bytes	Number of bytes received with iSCSI overhead.
117*fcf3ce44SJohn Forte  *	  _cntr_qactive		Number of requests in the active queue.
118*fcf3ce44SJohn Forte  *	  _stat_sn_exp		ExpStatusSN
119*fcf3ce44SJohn Forte  *	  _stat_sn_last		LastStatusSN (Last one sent to the target)
120*fcf3ce44SJohn Forte  *
121*fcf3ce44SJohn Forte  *
122*fcf3ce44SJohn Forte  *
123*fcf3ce44SJohn Forte  * The KSTAT frame work of Solaris associates a module name, a instance number
124*fcf3ce44SJohn Forte  * a class and a name to every kstat structure.  All the kstat structures of
125*fcf3ce44SJohn Forte  * iSCSI have the same module name. It is define farther down in this file to
126*fcf3ce44SJohn Forte  * "iscsi".  Regarding the class, three classes are defined here. Those classes
127*fcf3ce44SJohn Forte  * are:
128*fcf3ce44SJohn Forte  *
129*fcf3ce44SJohn Forte  *   - issci_hba
130*fcf3ce44SJohn Forte  *   - iscsi_sess
131*fcf3ce44SJohn Forte  *   - iscsi_conn
132*fcf3ce44SJohn Forte  *
133*fcf3ce44SJohn Forte  * The instance number is the number returned by ddi_get_instance.  Today the
134*fcf3ce44SJohn Forte  * the driver creates one HBA only.  Therefore, all the structures will have
135*fcf3ce44SJohn Forte  * zero as instance number.
136*fcf3ce44SJohn Forte  *
137*fcf3ce44SJohn Forte  *
138*fcf3ce44SJohn Forte  * Each kstat structure can be named.  The naming convention is the following:
139*fcf3ce44SJohn Forte  *
140*fcf3ce44SJohn Forte  *	KSTAT Struct	   Class	Name
141*fcf3ce44SJohn Forte  *
142*fcf3ce44SJohn Forte  *	sun_iscsi_hba	   iscsi_hba	"sun_iscsi_hba" + instance number
143*fcf3ce44SJohn Forte  *	sun_iscsi_sess	   iscsi_sess	"sun_iscsi_sess" + session oid
144*fcf3ce44SJohn Forte  *	sun_iscsi_sess_io  iscsi_sess	"sun_iscsi_sess_io" + session oid
145*fcf3ce44SJohn Forte  *	sun_iscsi_conn	   iscsi_conn	"sun_iscsi_conn" + connection oid
146*fcf3ce44SJohn Forte  */
147*fcf3ce44SJohn Forte 
148*fcf3ce44SJohn Forte /*
149*fcf3ce44SJohn Forte  * strings used by kstat (Module name and Class name).
150*fcf3ce44SJohn Forte  */
151*fcf3ce44SJohn Forte #define	iSCSI_MODULE_NAME	"iscsi"
152*fcf3ce44SJohn Forte 
153*fcf3ce44SJohn Forte typedef struct _kstat_item {
154*fcf3ce44SJohn Forte 	char		*_name;
155*fcf3ce44SJohn Forte 	uchar_t		_data_type;
156*fcf3ce44SJohn Forte } kstat_item_t;
157*fcf3ce44SJohn Forte 
158*fcf3ce44SJohn Forte /*
159*fcf3ce44SJohn Forte  * ========================= Connection Class Section ======================
160*fcf3ce44SJohn Forte  */
161*fcf3ce44SJohn Forte 
162*fcf3ce44SJohn Forte #define	iSCSI_CLASS_CONN			"iscsi_conn"
163*fcf3ce44SJohn Forte #define	iSCSI_CONN_BASE_NAME			"iscsi_conn_%d_%d_%d"
164*fcf3ce44SJohn Forte 
165*fcf3ce44SJohn Forte #define	ISCSI_CONN_STATE_FREE_STR		"free"
166*fcf3ce44SJohn Forte #define	ISCSI_CONN_STATE_IN_LOGIN_STR		"in_login"
167*fcf3ce44SJohn Forte #define	ISCSI_CONN_STATE_LOGGED_IN_STR		"logged_in"
168*fcf3ce44SJohn Forte #define	ISCSI_CONN_STATE_IN_LOGOUT_STR		"in_logout"
169*fcf3ce44SJohn Forte #define	ISCSI_CONN_STATE_CLEANUP_WAIT_STR	"cleanup_wait"
170*fcf3ce44SJohn Forte 
171*fcf3ce44SJohn Forte /*
172*fcf3ce44SJohn Forte  * WARNING: The order of this enum important.  If you change it you have to
173*fcf3ce44SJohn Forte  *          reorder the table kstat_items_conn (in the file iscsi_stats.c)
174*fcf3ce44SJohn Forte  *	    accordingly.
175*fcf3ce44SJohn Forte  */
176*fcf3ce44SJohn Forte typedef enum _kn_conn_idx {
177*fcf3ce44SJohn Forte 	KN_CONN_IDX_STATE = 0,
178*fcf3ce44SJohn Forte 	KN_CONN_IDX_CID,
179*fcf3ce44SJohn Forte 	KN_CONN_IDX_OID,
180*fcf3ce44SJohn Forte 	KN_CONN_IDX_SESS,
181*fcf3ce44SJohn Forte 	KN_CONN_IDX_ERR_HDR_DIGEST,
182*fcf3ce44SJohn Forte 	KN_CONN_IDX_ERR_DATA_DIGEST,
183*fcf3ce44SJohn Forte 	KN_CONN_IDX_ERR_CONN_RESET,
184*fcf3ce44SJohn Forte 	KN_CONN_IDX_ERR_PROTOCOL,
185*fcf3ce44SJohn Forte 	KN_CONN_IDX_CNTR_TX_BYTES,
186*fcf3ce44SJohn Forte 	KN_CONN_IDX_CNTR_RX_BYTES,
187*fcf3ce44SJohn Forte 	KN_CONN_IDX_CNTR_QACTIVE,
188*fcf3ce44SJohn Forte 	KN_CONN_IDX_EXPSTATSN,
189*fcf3ce44SJohn Forte 	KN_CONN_IDX_LASTSTATSN,
190*fcf3ce44SJohn Forte 	KN_CONN_IDX_MAX
191*fcf3ce44SJohn Forte } kn_conn_idx_t;
192*fcf3ce44SJohn Forte 
193*fcf3ce44SJohn Forte typedef struct _iscsi_conn_kstats {
194*fcf3ce44SJohn Forte 	kstat_named_t	kn[KN_CONN_IDX_MAX];
195*fcf3ce44SJohn Forte 	char 		sess_str[KSTAT_STRLEN];
196*fcf3ce44SJohn Forte 	char 		state_str[KSTAT_STRLEN];
197*fcf3ce44SJohn Forte } iscsi_conn_stats_t;
198*fcf3ce44SJohn Forte 
199*fcf3ce44SJohn Forte #define	KSTAT_INC_CONN_ERR_HEADER_DIGEST(_icp_) \
200*fcf3ce44SJohn Forte 	(_icp_->stats.ks_data.kn[KN_CONN_IDX_ERR_HDR_DIGEST].value.ul++)
201*fcf3ce44SJohn Forte 
202*fcf3ce44SJohn Forte #define	KSTAT_INC_CONN_ERR_DATA_DIGEST(_icp_) \
203*fcf3ce44SJohn Forte 	(_icp_->stats.ks_data.kn[KN_CONN_IDX_ERR_DATA_DIGEST].value.ul++)
204*fcf3ce44SJohn Forte 
205*fcf3ce44SJohn Forte #define	KSTAT_INC_CONN_ERR_PROTOCOL(_icp_) \
206*fcf3ce44SJohn Forte 	(_icp_->stats.ks_data.kn[KN_CONN_IDX_ERR_PROTOCOL].value.ul++)
207*fcf3ce44SJohn Forte 
208*fcf3ce44SJohn Forte #define	KSTAT_INC_CONN_ERR_RESET(_icp_) \
209*fcf3ce44SJohn Forte 	(_icp_->stats.ks_data.kn[KN_CONN_IDX_ERR_CONN_RESET].value.ul++)
210*fcf3ce44SJohn Forte 
211*fcf3ce44SJohn Forte #define	KSTAT_ADD_CONN_TX_BYTES(_icp_, _v_) \
212*fcf3ce44SJohn Forte 	(_icp_->stats.ks_data.kn[KN_CONN_IDX_CNTR_TX_BYTES].value.ui64 += \
213*fcf3ce44SJohn Forte 	_v_)
214*fcf3ce44SJohn Forte 
215*fcf3ce44SJohn Forte #define	KSTAT_ADD_CONN_RX_BYTES(_icp_, _v_) \
216*fcf3ce44SJohn Forte 	(_icp_->stats.ks_data.kn[KN_CONN_IDX_CNTR_RX_BYTES].value.ui64 += \
217*fcf3ce44SJohn Forte 	_v_)
218*fcf3ce44SJohn Forte 
219*fcf3ce44SJohn Forte /*
220*fcf3ce44SJohn Forte  * ========================== Session Class Section ========================
221*fcf3ce44SJohn Forte  */
222*fcf3ce44SJohn Forte 
223*fcf3ce44SJohn Forte /* Session Class */
224*fcf3ce44SJohn Forte #define	iSCSI_CLASS_SESS			"iscsi_sess"
225*fcf3ce44SJohn Forte #define	iSCSI_SESS_BASE_NAME			"iscsi_sess_%d_%d"
226*fcf3ce44SJohn Forte #define	iSCSI_SESS_IO_BASE_NAME			"iscsi_sess_io_%d_%d"
227*fcf3ce44SJohn Forte 
228*fcf3ce44SJohn Forte #define	ISCSI_SESS_STATE_FREE_STR		"free"
229*fcf3ce44SJohn Forte #define	ISCSI_SESS_STATE_LOGGED_IN_STR		"logged_in"
230*fcf3ce44SJohn Forte #define	ISCSI_SESS_STATE_FAILED_STR		"failed"
231*fcf3ce44SJohn Forte 
232*fcf3ce44SJohn Forte /*
233*fcf3ce44SJohn Forte  * WARNING: The order of this enum important.  If you change it you have to
234*fcf3ce44SJohn Forte  *          reorder the table kstat_items_sess (in the file iscsi_stats.c)
235*fcf3ce44SJohn Forte  *	    accordingly.
236*fcf3ce44SJohn Forte  */
237*fcf3ce44SJohn Forte typedef enum _kn_sess_idx {
238*fcf3ce44SJohn Forte 	KN_SESS_IDX_STATE = 0,
239*fcf3ce44SJohn Forte 	KN_SESS_IDX_OID,
240*fcf3ce44SJohn Forte 	KN_SESS_IDX_HBA,
241*fcf3ce44SJohn Forte 	KN_SESS_IDX_CNTR_CONN,
242*fcf3ce44SJohn Forte 	KN_SESS_IDX_CNTR_RESET,
243*fcf3ce44SJohn Forte 	KN_SESS_IDX_CNTR_PKT_PENDING,
244*fcf3ce44SJohn Forte 	KN_SESS_IDX_CMDSN,
245*fcf3ce44SJohn Forte 	KN_SESS_IDX_EXPCMDSN,
246*fcf3ce44SJohn Forte 	KN_SESS_IDX_MAXCMDSN,
247*fcf3ce44SJohn Forte 	KN_SESS_IDX_TARGET_NAME,
248*fcf3ce44SJohn Forte 	KN_SESS_IDX_TARGET_ALIAS,
249*fcf3ce44SJohn Forte 	KN_SESS_IDX_TPGT,
250*fcf3ce44SJohn Forte 	KN_SESS_IDX_MAX
251*fcf3ce44SJohn Forte } kn_sess_idx_t;
252*fcf3ce44SJohn Forte 
253*fcf3ce44SJohn Forte typedef struct _iscsi_sess_stats {
254*fcf3ce44SJohn Forte 	kstat_named_t	kn[KN_SESS_IDX_MAX];
255*fcf3ce44SJohn Forte 	char 		hba_str[KSTAT_STRLEN];
256*fcf3ce44SJohn Forte 	char 		state_str[KSTAT_STRLEN];
257*fcf3ce44SJohn Forte 	char 		target_name[ISCSI_MAX_NAME_LEN];
258*fcf3ce44SJohn Forte 	char 		target_alias[ISCSI_MAX_NAME_LEN];
259*fcf3ce44SJohn Forte } iscsi_sess_stats_t;
260*fcf3ce44SJohn Forte 
261*fcf3ce44SJohn Forte #define	KSTAT_INC_SESS_CNTR_RESET(_isp_) \
262*fcf3ce44SJohn Forte 	(_isp_->stats.ks_data.kn[KN_SESS_IDX_CNTR_RESET].value.ul++)
263*fcf3ce44SJohn Forte 
264*fcf3ce44SJohn Forte #define	KSTAT_INC_SESS_CNTR_CONN(_isp_) \
265*fcf3ce44SJohn Forte 	(_isp_->stats.ks_data.kn[KN_SESS_IDX_CNTR_CONN].value.ul++)
266*fcf3ce44SJohn Forte 
267*fcf3ce44SJohn Forte #define	KSTAT_DEC_SESS_CNTR_CONN(_isp_) \
268*fcf3ce44SJohn Forte 	(_isp_->stats.ks_data.kn[KN_SESS_IDX_CNTR_CONN].value.ul--)
269*fcf3ce44SJohn Forte 
270*fcf3ce44SJohn Forte #define	KSTAT_ADD_SESS_CNTR_TX_BYTES(_isp_, _v_) \
271*fcf3ce44SJohn Forte 	mutex_enter(&_isp_->stats.ks_io_lock); \
272*fcf3ce44SJohn Forte 	(_isp_->stats.ks_io_data.nwritten += _v_); \
273*fcf3ce44SJohn Forte 	mutex_exit(&_isp_->stats.ks_io_lock);
274*fcf3ce44SJohn Forte 
275*fcf3ce44SJohn Forte #define	KSTAT_ADD_SESS_CNTR_RX_BYTES(_isp_, _v_) \
276*fcf3ce44SJohn Forte 	mutex_enter(&_isp_->stats.ks_io_lock); \
277*fcf3ce44SJohn Forte 	(_isp_->stats.ks_io_data.nread += _v_); \
278*fcf3ce44SJohn Forte 	mutex_exit(&_isp_->stats.ks_io_lock);
279*fcf3ce44SJohn Forte 
280*fcf3ce44SJohn Forte #define	KSTAT_INC_SESS_CNTR_NWRITES(_isp_) \
281*fcf3ce44SJohn Forte 	mutex_enter(&_isp_->stats.ks_io_lock); \
282*fcf3ce44SJohn Forte 	(_isp_->stats.ks_io_data.writes++); \
283*fcf3ce44SJohn Forte 	mutex_exit(&_isp_->stats.ks_io_lock);
284*fcf3ce44SJohn Forte 
285*fcf3ce44SJohn Forte #define	KSTAT_INC_SESS_CNTR_NREADS(_isp_) \
286*fcf3ce44SJohn Forte 	mutex_enter(&_isp_->stats.ks_io_lock); \
287*fcf3ce44SJohn Forte 	(_isp_->stats.ks_io_data.reads++); \
288*fcf3ce44SJohn Forte 	mutex_exit(&_isp_->stats.ks_io_lock);
289*fcf3ce44SJohn Forte 
290*fcf3ce44SJohn Forte #define	KSTAT_WAITQ_ENTER(_isp_) \
291*fcf3ce44SJohn Forte 	mutex_enter(&_isp_->stats.ks_io_lock); \
292*fcf3ce44SJohn Forte 	(kstat_waitq_enter(&_isp_->stats.ks_io_data)); \
293*fcf3ce44SJohn Forte 	mutex_exit(&_isp_->stats.ks_io_lock);
294*fcf3ce44SJohn Forte 
295*fcf3ce44SJohn Forte #define	KSTAT_WAITQ_EXIT(_isp_) \
296*fcf3ce44SJohn Forte 	mutex_enter(&_isp_->stats.ks_io_lock); \
297*fcf3ce44SJohn Forte 	(kstat_waitq_exit(&_isp_->stats.ks_io_data)); \
298*fcf3ce44SJohn Forte 	mutex_exit(&_isp_->stats.ks_io_lock);
299*fcf3ce44SJohn Forte 
300*fcf3ce44SJohn Forte #define	KSTAT_RUNQ_ENTER(_isp_) \
301*fcf3ce44SJohn Forte 	mutex_enter(&_isp_->stats.ks_io_lock); \
302*fcf3ce44SJohn Forte 	(kstat_runq_enter(&_isp_->stats.ks_io_data)); \
303*fcf3ce44SJohn Forte 	mutex_exit(&_isp_->stats.ks_io_lock);
304*fcf3ce44SJohn Forte 
305*fcf3ce44SJohn Forte #define	KSTAT_RUNQ_EXIT(_isp_) \
306*fcf3ce44SJohn Forte 	mutex_enter(&_isp_->stats.ks_io_lock); \
307*fcf3ce44SJohn Forte 	(kstat_runq_exit(&_isp_->stats.ks_io_data)); \
308*fcf3ce44SJohn Forte 	mutex_exit(&_isp_->stats.ks_io_lock);
309*fcf3ce44SJohn Forte 
310*fcf3ce44SJohn Forte #define	KSTAT_SESS_TX_IO_DONE(_isp_, _v_) \
311*fcf3ce44SJohn Forte 	mutex_enter(&_isp_->stats.ks_io_lock); \
312*fcf3ce44SJohn Forte 	(_isp_->stats.ks_io_data.nwritten += _v_); \
313*fcf3ce44SJohn Forte 	(_isp_->stats.ks_io_data.writes++); \
314*fcf3ce44SJohn Forte 	mutex_exit(&_isp_->stats.ks_io_lock);
315*fcf3ce44SJohn Forte 
316*fcf3ce44SJohn Forte #define	KSTAT_SESS_RX_IO_DONE(_isp_, _v_) \
317*fcf3ce44SJohn Forte 	mutex_enter(&_isp_->stats.ks_io_lock); \
318*fcf3ce44SJohn Forte 	(_isp_->stats.ks_io_data.nread += _v_); \
319*fcf3ce44SJohn Forte 	(_isp_->stats.ks_io_data.reads++); \
320*fcf3ce44SJohn Forte 	mutex_exit(&_isp_->stats.ks_io_lock);
321*fcf3ce44SJohn Forte 
322*fcf3ce44SJohn Forte /*
323*fcf3ce44SJohn Forte  * ============================ HBA Class Section ==========================
324*fcf3ce44SJohn Forte  */
325*fcf3ce44SJohn Forte 
326*fcf3ce44SJohn Forte #define	iSCSI_CLASS_HBA		"iscsi_hba"
327*fcf3ce44SJohn Forte #define	iSCSI_HBA_BASE_NAME	"iscsi_hba_%d"
328*fcf3ce44SJohn Forte 
329*fcf3ce44SJohn Forte /*
330*fcf3ce44SJohn Forte  * WARNING: The order of this enum important.  If you change it you have to
331*fcf3ce44SJohn Forte  *          reorder the table kstat_items_hba (in iscsi_stats.c) accordingly.
332*fcf3ce44SJohn Forte  */
333*fcf3ce44SJohn Forte typedef enum _kn_hba_idx {
334*fcf3ce44SJohn Forte 	KN_HBA_IDX_NAME = 0,
335*fcf3ce44SJohn Forte 	KN_HBA_IDX_ALIAS,
336*fcf3ce44SJohn Forte 	KN_HBA_IDX_CNTR_SESS,
337*fcf3ce44SJohn Forte 	KN_HBA_IDX_MAX
338*fcf3ce44SJohn Forte } kn_hba_idx_t;
339*fcf3ce44SJohn Forte 
340*fcf3ce44SJohn Forte typedef struct _iscsi_hba_stats {
341*fcf3ce44SJohn Forte 	kstat_named_t	kn[KN_HBA_IDX_MAX];
342*fcf3ce44SJohn Forte 	char 		name[ISCSI_MAX_NAME_LEN];
343*fcf3ce44SJohn Forte 	char 		alias[ISCSI_MAX_NAME_LEN];
344*fcf3ce44SJohn Forte } iscsi_hba_stats_t;
345*fcf3ce44SJohn Forte 
346*fcf3ce44SJohn Forte #define	KSTAT_INC_HBA_CNTR_SESS(_ihp_) \
347*fcf3ce44SJohn Forte 	(_ihp_->stats.ks_data.kn[KN_HBA_IDX_CNTR_SESS].value.ul++)
348*fcf3ce44SJohn Forte 
349*fcf3ce44SJohn Forte #define	KSTAT_DEC_HBA_CNTR_SESS(_ihp_) \
350*fcf3ce44SJohn Forte 	(_ihp_->stats.ks_data.kn[KN_HBA_IDX_CNTR_SESS].value.ul--)
351*fcf3ce44SJohn Forte 
352*fcf3ce44SJohn Forte #ifdef __cplusplus
353*fcf3ce44SJohn Forte }
354*fcf3ce44SJohn Forte #endif
355*fcf3ce44SJohn Forte 
356*fcf3ce44SJohn Forte #endif	/* _ISCSI_STATS_H */
357