xref: /onnv-gate/usr/src/uts/common/ipp/ipp_impl.h (revision 0:68f95e015346)
1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * CDDL HEADER START
3*0Sstevel@tonic-gate  *
4*0Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*0Sstevel@tonic-gate  * with the License.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate  * and limitations under the License.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate  *
20*0Sstevel@tonic-gate  * CDDL HEADER END
21*0Sstevel@tonic-gate  */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate  * Copyright 2002-2003 Sun Microsystems, Inc.  All rights reserved.
24*0Sstevel@tonic-gate  * Use is subject to license terms.
25*0Sstevel@tonic-gate  */
26*0Sstevel@tonic-gate 
27*0Sstevel@tonic-gate #ifndef	_IPP_IPP_IMPL_H
28*0Sstevel@tonic-gate #define	_IPP_IPP_IMPL_H
29*0Sstevel@tonic-gate 
30*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
31*0Sstevel@tonic-gate 
32*0Sstevel@tonic-gate /*
33*0Sstevel@tonic-gate  * IP Policy Framework (IPPF) implementation detail.
34*0Sstevel@tonic-gate  *
35*0Sstevel@tonic-gate  * WARNING: Everything in this file is private, belonging to the IPPF
36*0Sstevel@tonic-gate  * subsystem.  The interfaces and declarations made here are subject
37*0Sstevel@tonic-gate  * to change.
38*0Sstevel@tonic-gate  */
39*0Sstevel@tonic-gate 
40*0Sstevel@tonic-gate #include <sys/stream.h>
41*0Sstevel@tonic-gate #include <sys/thread.h>
42*0Sstevel@tonic-gate #include <ipp/ipp.h>
43*0Sstevel@tonic-gate 
44*0Sstevel@tonic-gate #ifdef	__cplusplus
45*0Sstevel@tonic-gate extern "C" {
46*0Sstevel@tonic-gate #endif
47*0Sstevel@tonic-gate 
48*0Sstevel@tonic-gate #ifdef	_KERNEL
49*0Sstevel@tonic-gate 
50*0Sstevel@tonic-gate #define	IPP_ALIGN		64
51*0Sstevel@tonic-gate 
52*0Sstevel@tonic-gate #define	IPP_NBUCKET		23
53*0Sstevel@tonic-gate 
54*0Sstevel@tonic-gate #define	IPP_LOG2NACTION		16
55*0Sstevel@tonic-gate #define	IPP_NACTION		(1 << IPP_LOG2NACTION)
56*0Sstevel@tonic-gate 
57*0Sstevel@tonic-gate #define	IPP_LOG2NMOD		6
58*0Sstevel@tonic-gate #define	IPP_NMOD		(1 << IPP_LOG2NMOD)
59*0Sstevel@tonic-gate 
60*0Sstevel@tonic-gate #define	IPP_NCLASS		5
61*0Sstevel@tonic-gate #define	IPP_NLOG		IPP_NMOD
62*0Sstevel@tonic-gate 
63*0Sstevel@tonic-gate typedef	struct ipp_ref	ipp_ref_t;
64*0Sstevel@tonic-gate 
65*0Sstevel@tonic-gate struct ipp_ref {
66*0Sstevel@tonic-gate 	ipp_ref_t		*ippr_nextp;
67*0Sstevel@tonic-gate 	uint_t			ippr_count;
68*0Sstevel@tonic-gate 	union {
69*0Sstevel@tonic-gate 	    ipp_mod_t		*u_mod;
70*0Sstevel@tonic-gate 	    ipp_action_t	*u_action;
71*0Sstevel@tonic-gate 	    void		*u_ptr;
72*0Sstevel@tonic-gate 	} ippr_u;
73*0Sstevel@tonic-gate };
74*0Sstevel@tonic-gate 
75*0Sstevel@tonic-gate #define	ippr_action	ippr_u.u_action
76*0Sstevel@tonic-gate #define	ippr_mod	ippr_u.u_mod
77*0Sstevel@tonic-gate #define	ippr_ptr	ippr_u.u_ptr
78*0Sstevel@tonic-gate 
79*0Sstevel@tonic-gate typedef enum {
80*0Sstevel@tonic-gate 	IPP_MODSTATE_PROTO = 0x10,
81*0Sstevel@tonic-gate 	IPP_MODSTATE_AVAILABLE
82*0Sstevel@tonic-gate } ipp_modstate_t;
83*0Sstevel@tonic-gate 
84*0Sstevel@tonic-gate struct ipp_mod {
85*0Sstevel@tonic-gate 	ipp_mod_id_t	ippm_id;
86*0Sstevel@tonic-gate 	ipp_ops_t	*ippm_ops;
87*0Sstevel@tonic-gate 	ipp_ref_t	*ippm_action;
88*0Sstevel@tonic-gate 	ipp_modstate_t	ippm_state;
89*0Sstevel@tonic-gate 	krwlock_t	ippm_lock[1];
90*0Sstevel@tonic-gate 	uint32_t	ippm_hold_count;
91*0Sstevel@tonic-gate 	boolean_t	ippm_destruct_pending;
92*0Sstevel@tonic-gate 	char		ippm_name[MAXNAMELEN];
93*0Sstevel@tonic-gate };
94*0Sstevel@tonic-gate 
95*0Sstevel@tonic-gate typedef enum {
96*0Sstevel@tonic-gate 	IPP_ASTATE_PROTO = 0x20,
97*0Sstevel@tonic-gate 	IPP_ASTATE_CONFIG_PENDING,
98*0Sstevel@tonic-gate 	IPP_ASTATE_AVAILABLE
99*0Sstevel@tonic-gate } ipp_astate_t;
100*0Sstevel@tonic-gate 
101*0Sstevel@tonic-gate typedef struct cfglock {
102*0Sstevel@tonic-gate 	kmutex_t	cl_mutex[1];
103*0Sstevel@tonic-gate 	kcondvar_t	cl_cv[1];
104*0Sstevel@tonic-gate 	uint_t		cl_writers;
105*0Sstevel@tonic-gate 	boolean_t	cl_reader;
106*0Sstevel@tonic-gate 	kthread_id_t	cl_owner;
107*0Sstevel@tonic-gate } cfglock_t;
108*0Sstevel@tonic-gate 
109*0Sstevel@tonic-gate #ifndef	__lint
110*0Sstevel@tonic-gate 
111*0Sstevel@tonic-gate #define	CL_READ		0
112*0Sstevel@tonic-gate #define	CL_WRITE	1
113*0Sstevel@tonic-gate 
114*0Sstevel@tonic-gate #define	CONFIG_LOCK_INIT(_clp)						\
115*0Sstevel@tonic-gate 	{								\
116*0Sstevel@tonic-gate 		mutex_init((_clp)->cl_mutex, NULL, MUTEX_DEFAULT,	\
117*0Sstevel@tonic-gate 		    (void *)ipltospl(LOCK_LEVEL));			\
118*0Sstevel@tonic-gate 		cv_init((_clp)->cl_cv, NULL, CV_DEFAULT, NULL);		\
119*0Sstevel@tonic-gate 	}
120*0Sstevel@tonic-gate 
121*0Sstevel@tonic-gate #define	CONFIG_LOCK_FINI(_clp)						\
122*0Sstevel@tonic-gate 	{								\
123*0Sstevel@tonic-gate 		mutex_destroy((_clp)->cl_mutex);			\
124*0Sstevel@tonic-gate 		cv_destroy((_clp)->cl_cv);				\
125*0Sstevel@tonic-gate 	}
126*0Sstevel@tonic-gate 
127*0Sstevel@tonic-gate #define	CONFIG_LOCK_ENTER(_clp, _rw)					\
128*0Sstevel@tonic-gate 	{								\
129*0Sstevel@tonic-gate 		mutex_enter((_clp)->cl_mutex);				\
130*0Sstevel@tonic-gate 		if ((_rw) == CL_WRITE) {				\
131*0Sstevel@tonic-gate 			while ((_clp)->cl_reader ||			\
132*0Sstevel@tonic-gate 			    ((_clp)->cl_owner != NULL &&		\
133*0Sstevel@tonic-gate 			    (_clp)->cl_owner != curthread))		\
134*0Sstevel@tonic-gate 				cv_wait((_clp)->cl_cv,			\
135*0Sstevel@tonic-gate 				    (_clp)->cl_mutex);			\
136*0Sstevel@tonic-gate 			(_clp)->cl_owner = curthread;			\
137*0Sstevel@tonic-gate 			(_clp)->cl_writers++;				\
138*0Sstevel@tonic-gate 		}							\
139*0Sstevel@tonic-gate 		else if ((_rw) == CL_READ) {				\
140*0Sstevel@tonic-gate 			while ((_clp)->cl_reader ||			\
141*0Sstevel@tonic-gate 			    (_clp)->cl_writers > 0) {			\
142*0Sstevel@tonic-gate 				ASSERT((_clp)->cl_owner != curthread);	\
143*0Sstevel@tonic-gate 				cv_wait((_clp)->cl_cv,			\
144*0Sstevel@tonic-gate 				    (_clp)->cl_mutex);			\
145*0Sstevel@tonic-gate 			}						\
146*0Sstevel@tonic-gate 			(_clp)->cl_owner = curthread;			\
147*0Sstevel@tonic-gate 			(_clp)->cl_reader = B_TRUE;			\
148*0Sstevel@tonic-gate 		}							\
149*0Sstevel@tonic-gate 		mutex_exit((_clp)->cl_mutex);				\
150*0Sstevel@tonic-gate 	}
151*0Sstevel@tonic-gate 
152*0Sstevel@tonic-gate #define	CONFIG_LOCK_EXIT(_clp)						\
153*0Sstevel@tonic-gate 	{								\
154*0Sstevel@tonic-gate 		mutex_enter((_clp)->cl_mutex);				\
155*0Sstevel@tonic-gate 		if ((_clp)->cl_reader) {				\
156*0Sstevel@tonic-gate 			(_clp)->cl_reader = B_FALSE;			\
157*0Sstevel@tonic-gate 			(_clp)->cl_owner = NULL;			\
158*0Sstevel@tonic-gate 			cv_broadcast((_clp)->cl_cv);			\
159*0Sstevel@tonic-gate 		} else {						\
160*0Sstevel@tonic-gate 			ASSERT((_clp)->cl_writers != 0);		\
161*0Sstevel@tonic-gate 			(_clp)->cl_writers--;				\
162*0Sstevel@tonic-gate 			if ((_clp)->cl_writers == 0) {			\
163*0Sstevel@tonic-gate 				(_clp)->cl_owner = NULL;		\
164*0Sstevel@tonic-gate 				cv_broadcast((_clp)->cl_cv);		\
165*0Sstevel@tonic-gate 			}						\
166*0Sstevel@tonic-gate 		}							\
167*0Sstevel@tonic-gate 		mutex_exit((_clp)->cl_mutex);				\
168*0Sstevel@tonic-gate 	}
169*0Sstevel@tonic-gate 
170*0Sstevel@tonic-gate #else	/* __lint */
171*0Sstevel@tonic-gate 
172*0Sstevel@tonic-gate #define	CONFIG_LOCK_INIT(_clp)
173*0Sstevel@tonic-gate #define	CONFIG_LOCK_FINI(_clp)
174*0Sstevel@tonic-gate #define	CONFIG_LOCK_ENTER(_clp, _rw)
175*0Sstevel@tonic-gate #define	CONFIG_LOCK_EXIT(_clp)
176*0Sstevel@tonic-gate 
177*0Sstevel@tonic-gate #endif	/* __lint */
178*0Sstevel@tonic-gate 
179*0Sstevel@tonic-gate struct ipp_action {
180*0Sstevel@tonic-gate 	ipp_action_id_t	ippa_id;
181*0Sstevel@tonic-gate 	ipp_mod_t	*ippa_mod;
182*0Sstevel@tonic-gate 	ipp_ref_t	*ippa_ref;
183*0Sstevel@tonic-gate 	ipp_ref_t	*ippa_refby;
184*0Sstevel@tonic-gate 	void		*ippa_ptr;
185*0Sstevel@tonic-gate 	uint32_t	ippa_packets;
186*0Sstevel@tonic-gate 	ipp_astate_t	ippa_state;
187*0Sstevel@tonic-gate 	krwlock_t	ippa_lock[1];
188*0Sstevel@tonic-gate 	uint32_t	ippa_hold_count;
189*0Sstevel@tonic-gate 	boolean_t	ippa_destruct_pending;
190*0Sstevel@tonic-gate 	cfglock_t	ippa_config_lock[1];
191*0Sstevel@tonic-gate 	boolean_t	ippa_nameless;
192*0Sstevel@tonic-gate 	char		ippa_name[MAXNAMELEN];
193*0Sstevel@tonic-gate 	ipp_ref_t	**ippa_condemned;
194*0Sstevel@tonic-gate };
195*0Sstevel@tonic-gate 
196*0Sstevel@tonic-gate struct ipp_class {
197*0Sstevel@tonic-gate 	ipp_action_id_t	ippc_aid;
198*0Sstevel@tonic-gate 	char		ippc_name[MAXNAMELEN];
199*0Sstevel@tonic-gate };
200*0Sstevel@tonic-gate 
201*0Sstevel@tonic-gate struct ipp_log {
202*0Sstevel@tonic-gate 	ipp_action_id_t	ippl_aid;
203*0Sstevel@tonic-gate 	timespec_t	ippl_begin;
204*0Sstevel@tonic-gate 	timespec_t	ippl_end;
205*0Sstevel@tonic-gate 	char		ippl_name[MAXNAMELEN];
206*0Sstevel@tonic-gate };
207*0Sstevel@tonic-gate 
208*0Sstevel@tonic-gate typedef struct ipp_stat_impl	ipp_stat_impl_t;
209*0Sstevel@tonic-gate 
210*0Sstevel@tonic-gate struct ipp_stat_impl {
211*0Sstevel@tonic-gate 	void		*ippsi_data;
212*0Sstevel@tonic-gate 	kstat_t		*ippsi_ksp;
213*0Sstevel@tonic-gate 	int		ippsi_limit;
214*0Sstevel@tonic-gate 	int		ippsi_count;
215*0Sstevel@tonic-gate 	int		(*ippsi_update)(ipp_stat_t *, void *, int);
216*0Sstevel@tonic-gate 	void		*ippsi_arg;
217*0Sstevel@tonic-gate 	kmutex_t	ippsi_lock[1];
218*0Sstevel@tonic-gate 	char		ippsi_name[MAXNAMELEN];
219*0Sstevel@tonic-gate };
220*0Sstevel@tonic-gate 
221*0Sstevel@tonic-gate struct ipp_packet {
222*0Sstevel@tonic-gate 	mblk_t		*ippp_data;
223*0Sstevel@tonic-gate 	ipp_class_t	*ippp_class_array;
224*0Sstevel@tonic-gate 	uint_t		ippp_class_limit;
225*0Sstevel@tonic-gate 	uint_t		ippp_class_rindex;
226*0Sstevel@tonic-gate 	uint_t		ippp_class_windex;
227*0Sstevel@tonic-gate 	ipp_log_t	*ippp_log;
228*0Sstevel@tonic-gate 	uint_t		ippp_log_limit;
229*0Sstevel@tonic-gate 	uint_t		ippp_log_windex;
230*0Sstevel@tonic-gate 	void		*ippp_private;
231*0Sstevel@tonic-gate 	void		(*ippp_private_free)(void *);
232*0Sstevel@tonic-gate };
233*0Sstevel@tonic-gate 
234*0Sstevel@tonic-gate extern void		ipp_init(void);
235*0Sstevel@tonic-gate 
236*0Sstevel@tonic-gate #endif	/* _KERNEL */
237*0Sstevel@tonic-gate 
238*0Sstevel@tonic-gate #ifdef __cplusplus
239*0Sstevel@tonic-gate }
240*0Sstevel@tonic-gate #endif
241*0Sstevel@tonic-gate 
242*0Sstevel@tonic-gate #endif /* _IPP_IPP_IMPL_H */
243