xref: /titanic_52/usr/src/uts/common/ipp/ipp_impl.h (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
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 2002-2003 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	_IPP_IPP_IMPL_H
28*7c478bd9Sstevel@tonic-gate #define	_IPP_IPP_IMPL_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  * IP Policy Framework (IPPF) implementation detail.
34*7c478bd9Sstevel@tonic-gate  *
35*7c478bd9Sstevel@tonic-gate  * WARNING: Everything in this file is private, belonging to the IPPF
36*7c478bd9Sstevel@tonic-gate  * subsystem.  The interfaces and declarations made here are subject
37*7c478bd9Sstevel@tonic-gate  * to change.
38*7c478bd9Sstevel@tonic-gate  */
39*7c478bd9Sstevel@tonic-gate 
40*7c478bd9Sstevel@tonic-gate #include <sys/stream.h>
41*7c478bd9Sstevel@tonic-gate #include <sys/thread.h>
42*7c478bd9Sstevel@tonic-gate #include <ipp/ipp.h>
43*7c478bd9Sstevel@tonic-gate 
44*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
45*7c478bd9Sstevel@tonic-gate extern "C" {
46*7c478bd9Sstevel@tonic-gate #endif
47*7c478bd9Sstevel@tonic-gate 
48*7c478bd9Sstevel@tonic-gate #ifdef	_KERNEL
49*7c478bd9Sstevel@tonic-gate 
50*7c478bd9Sstevel@tonic-gate #define	IPP_ALIGN		64
51*7c478bd9Sstevel@tonic-gate 
52*7c478bd9Sstevel@tonic-gate #define	IPP_NBUCKET		23
53*7c478bd9Sstevel@tonic-gate 
54*7c478bd9Sstevel@tonic-gate #define	IPP_LOG2NACTION		16
55*7c478bd9Sstevel@tonic-gate #define	IPP_NACTION		(1 << IPP_LOG2NACTION)
56*7c478bd9Sstevel@tonic-gate 
57*7c478bd9Sstevel@tonic-gate #define	IPP_LOG2NMOD		6
58*7c478bd9Sstevel@tonic-gate #define	IPP_NMOD		(1 << IPP_LOG2NMOD)
59*7c478bd9Sstevel@tonic-gate 
60*7c478bd9Sstevel@tonic-gate #define	IPP_NCLASS		5
61*7c478bd9Sstevel@tonic-gate #define	IPP_NLOG		IPP_NMOD
62*7c478bd9Sstevel@tonic-gate 
63*7c478bd9Sstevel@tonic-gate typedef	struct ipp_ref	ipp_ref_t;
64*7c478bd9Sstevel@tonic-gate 
65*7c478bd9Sstevel@tonic-gate struct ipp_ref {
66*7c478bd9Sstevel@tonic-gate 	ipp_ref_t		*ippr_nextp;
67*7c478bd9Sstevel@tonic-gate 	uint_t			ippr_count;
68*7c478bd9Sstevel@tonic-gate 	union {
69*7c478bd9Sstevel@tonic-gate 	    ipp_mod_t		*u_mod;
70*7c478bd9Sstevel@tonic-gate 	    ipp_action_t	*u_action;
71*7c478bd9Sstevel@tonic-gate 	    void		*u_ptr;
72*7c478bd9Sstevel@tonic-gate 	} ippr_u;
73*7c478bd9Sstevel@tonic-gate };
74*7c478bd9Sstevel@tonic-gate 
75*7c478bd9Sstevel@tonic-gate #define	ippr_action	ippr_u.u_action
76*7c478bd9Sstevel@tonic-gate #define	ippr_mod	ippr_u.u_mod
77*7c478bd9Sstevel@tonic-gate #define	ippr_ptr	ippr_u.u_ptr
78*7c478bd9Sstevel@tonic-gate 
79*7c478bd9Sstevel@tonic-gate typedef enum {
80*7c478bd9Sstevel@tonic-gate 	IPP_MODSTATE_PROTO = 0x10,
81*7c478bd9Sstevel@tonic-gate 	IPP_MODSTATE_AVAILABLE
82*7c478bd9Sstevel@tonic-gate } ipp_modstate_t;
83*7c478bd9Sstevel@tonic-gate 
84*7c478bd9Sstevel@tonic-gate struct ipp_mod {
85*7c478bd9Sstevel@tonic-gate 	ipp_mod_id_t	ippm_id;
86*7c478bd9Sstevel@tonic-gate 	ipp_ops_t	*ippm_ops;
87*7c478bd9Sstevel@tonic-gate 	ipp_ref_t	*ippm_action;
88*7c478bd9Sstevel@tonic-gate 	ipp_modstate_t	ippm_state;
89*7c478bd9Sstevel@tonic-gate 	krwlock_t	ippm_lock[1];
90*7c478bd9Sstevel@tonic-gate 	uint32_t	ippm_hold_count;
91*7c478bd9Sstevel@tonic-gate 	boolean_t	ippm_destruct_pending;
92*7c478bd9Sstevel@tonic-gate 	char		ippm_name[MAXNAMELEN];
93*7c478bd9Sstevel@tonic-gate };
94*7c478bd9Sstevel@tonic-gate 
95*7c478bd9Sstevel@tonic-gate typedef enum {
96*7c478bd9Sstevel@tonic-gate 	IPP_ASTATE_PROTO = 0x20,
97*7c478bd9Sstevel@tonic-gate 	IPP_ASTATE_CONFIG_PENDING,
98*7c478bd9Sstevel@tonic-gate 	IPP_ASTATE_AVAILABLE
99*7c478bd9Sstevel@tonic-gate } ipp_astate_t;
100*7c478bd9Sstevel@tonic-gate 
101*7c478bd9Sstevel@tonic-gate typedef struct cfglock {
102*7c478bd9Sstevel@tonic-gate 	kmutex_t	cl_mutex[1];
103*7c478bd9Sstevel@tonic-gate 	kcondvar_t	cl_cv[1];
104*7c478bd9Sstevel@tonic-gate 	uint_t		cl_writers;
105*7c478bd9Sstevel@tonic-gate 	boolean_t	cl_reader;
106*7c478bd9Sstevel@tonic-gate 	kthread_id_t	cl_owner;
107*7c478bd9Sstevel@tonic-gate } cfglock_t;
108*7c478bd9Sstevel@tonic-gate 
109*7c478bd9Sstevel@tonic-gate #ifndef	__lint
110*7c478bd9Sstevel@tonic-gate 
111*7c478bd9Sstevel@tonic-gate #define	CL_READ		0
112*7c478bd9Sstevel@tonic-gate #define	CL_WRITE	1
113*7c478bd9Sstevel@tonic-gate 
114*7c478bd9Sstevel@tonic-gate #define	CONFIG_LOCK_INIT(_clp)						\
115*7c478bd9Sstevel@tonic-gate 	{								\
116*7c478bd9Sstevel@tonic-gate 		mutex_init((_clp)->cl_mutex, NULL, MUTEX_DEFAULT,	\
117*7c478bd9Sstevel@tonic-gate 		    (void *)ipltospl(LOCK_LEVEL));			\
118*7c478bd9Sstevel@tonic-gate 		cv_init((_clp)->cl_cv, NULL, CV_DEFAULT, NULL);		\
119*7c478bd9Sstevel@tonic-gate 	}
120*7c478bd9Sstevel@tonic-gate 
121*7c478bd9Sstevel@tonic-gate #define	CONFIG_LOCK_FINI(_clp)						\
122*7c478bd9Sstevel@tonic-gate 	{								\
123*7c478bd9Sstevel@tonic-gate 		mutex_destroy((_clp)->cl_mutex);			\
124*7c478bd9Sstevel@tonic-gate 		cv_destroy((_clp)->cl_cv);				\
125*7c478bd9Sstevel@tonic-gate 	}
126*7c478bd9Sstevel@tonic-gate 
127*7c478bd9Sstevel@tonic-gate #define	CONFIG_LOCK_ENTER(_clp, _rw)					\
128*7c478bd9Sstevel@tonic-gate 	{								\
129*7c478bd9Sstevel@tonic-gate 		mutex_enter((_clp)->cl_mutex);				\
130*7c478bd9Sstevel@tonic-gate 		if ((_rw) == CL_WRITE) {				\
131*7c478bd9Sstevel@tonic-gate 			while ((_clp)->cl_reader ||			\
132*7c478bd9Sstevel@tonic-gate 			    ((_clp)->cl_owner != NULL &&		\
133*7c478bd9Sstevel@tonic-gate 			    (_clp)->cl_owner != curthread))		\
134*7c478bd9Sstevel@tonic-gate 				cv_wait((_clp)->cl_cv,			\
135*7c478bd9Sstevel@tonic-gate 				    (_clp)->cl_mutex);			\
136*7c478bd9Sstevel@tonic-gate 			(_clp)->cl_owner = curthread;			\
137*7c478bd9Sstevel@tonic-gate 			(_clp)->cl_writers++;				\
138*7c478bd9Sstevel@tonic-gate 		}							\
139*7c478bd9Sstevel@tonic-gate 		else if ((_rw) == CL_READ) {				\
140*7c478bd9Sstevel@tonic-gate 			while ((_clp)->cl_reader ||			\
141*7c478bd9Sstevel@tonic-gate 			    (_clp)->cl_writers > 0) {			\
142*7c478bd9Sstevel@tonic-gate 				ASSERT((_clp)->cl_owner != curthread);	\
143*7c478bd9Sstevel@tonic-gate 				cv_wait((_clp)->cl_cv,			\
144*7c478bd9Sstevel@tonic-gate 				    (_clp)->cl_mutex);			\
145*7c478bd9Sstevel@tonic-gate 			}						\
146*7c478bd9Sstevel@tonic-gate 			(_clp)->cl_owner = curthread;			\
147*7c478bd9Sstevel@tonic-gate 			(_clp)->cl_reader = B_TRUE;			\
148*7c478bd9Sstevel@tonic-gate 		}							\
149*7c478bd9Sstevel@tonic-gate 		mutex_exit((_clp)->cl_mutex);				\
150*7c478bd9Sstevel@tonic-gate 	}
151*7c478bd9Sstevel@tonic-gate 
152*7c478bd9Sstevel@tonic-gate #define	CONFIG_LOCK_EXIT(_clp)						\
153*7c478bd9Sstevel@tonic-gate 	{								\
154*7c478bd9Sstevel@tonic-gate 		mutex_enter((_clp)->cl_mutex);				\
155*7c478bd9Sstevel@tonic-gate 		if ((_clp)->cl_reader) {				\
156*7c478bd9Sstevel@tonic-gate 			(_clp)->cl_reader = B_FALSE;			\
157*7c478bd9Sstevel@tonic-gate 			(_clp)->cl_owner = NULL;			\
158*7c478bd9Sstevel@tonic-gate 			cv_broadcast((_clp)->cl_cv);			\
159*7c478bd9Sstevel@tonic-gate 		} else {						\
160*7c478bd9Sstevel@tonic-gate 			ASSERT((_clp)->cl_writers != 0);		\
161*7c478bd9Sstevel@tonic-gate 			(_clp)->cl_writers--;				\
162*7c478bd9Sstevel@tonic-gate 			if ((_clp)->cl_writers == 0) {			\
163*7c478bd9Sstevel@tonic-gate 				(_clp)->cl_owner = NULL;		\
164*7c478bd9Sstevel@tonic-gate 				cv_broadcast((_clp)->cl_cv);		\
165*7c478bd9Sstevel@tonic-gate 			}						\
166*7c478bd9Sstevel@tonic-gate 		}							\
167*7c478bd9Sstevel@tonic-gate 		mutex_exit((_clp)->cl_mutex);				\
168*7c478bd9Sstevel@tonic-gate 	}
169*7c478bd9Sstevel@tonic-gate 
170*7c478bd9Sstevel@tonic-gate #else	/* __lint */
171*7c478bd9Sstevel@tonic-gate 
172*7c478bd9Sstevel@tonic-gate #define	CONFIG_LOCK_INIT(_clp)
173*7c478bd9Sstevel@tonic-gate #define	CONFIG_LOCK_FINI(_clp)
174*7c478bd9Sstevel@tonic-gate #define	CONFIG_LOCK_ENTER(_clp, _rw)
175*7c478bd9Sstevel@tonic-gate #define	CONFIG_LOCK_EXIT(_clp)
176*7c478bd9Sstevel@tonic-gate 
177*7c478bd9Sstevel@tonic-gate #endif	/* __lint */
178*7c478bd9Sstevel@tonic-gate 
179*7c478bd9Sstevel@tonic-gate struct ipp_action {
180*7c478bd9Sstevel@tonic-gate 	ipp_action_id_t	ippa_id;
181*7c478bd9Sstevel@tonic-gate 	ipp_mod_t	*ippa_mod;
182*7c478bd9Sstevel@tonic-gate 	ipp_ref_t	*ippa_ref;
183*7c478bd9Sstevel@tonic-gate 	ipp_ref_t	*ippa_refby;
184*7c478bd9Sstevel@tonic-gate 	void		*ippa_ptr;
185*7c478bd9Sstevel@tonic-gate 	uint32_t	ippa_packets;
186*7c478bd9Sstevel@tonic-gate 	ipp_astate_t	ippa_state;
187*7c478bd9Sstevel@tonic-gate 	krwlock_t	ippa_lock[1];
188*7c478bd9Sstevel@tonic-gate 	uint32_t	ippa_hold_count;
189*7c478bd9Sstevel@tonic-gate 	boolean_t	ippa_destruct_pending;
190*7c478bd9Sstevel@tonic-gate 	cfglock_t	ippa_config_lock[1];
191*7c478bd9Sstevel@tonic-gate 	boolean_t	ippa_nameless;
192*7c478bd9Sstevel@tonic-gate 	char		ippa_name[MAXNAMELEN];
193*7c478bd9Sstevel@tonic-gate 	ipp_ref_t	**ippa_condemned;
194*7c478bd9Sstevel@tonic-gate };
195*7c478bd9Sstevel@tonic-gate 
196*7c478bd9Sstevel@tonic-gate struct ipp_class {
197*7c478bd9Sstevel@tonic-gate 	ipp_action_id_t	ippc_aid;
198*7c478bd9Sstevel@tonic-gate 	char		ippc_name[MAXNAMELEN];
199*7c478bd9Sstevel@tonic-gate };
200*7c478bd9Sstevel@tonic-gate 
201*7c478bd9Sstevel@tonic-gate struct ipp_log {
202*7c478bd9Sstevel@tonic-gate 	ipp_action_id_t	ippl_aid;
203*7c478bd9Sstevel@tonic-gate 	timespec_t	ippl_begin;
204*7c478bd9Sstevel@tonic-gate 	timespec_t	ippl_end;
205*7c478bd9Sstevel@tonic-gate 	char		ippl_name[MAXNAMELEN];
206*7c478bd9Sstevel@tonic-gate };
207*7c478bd9Sstevel@tonic-gate 
208*7c478bd9Sstevel@tonic-gate typedef struct ipp_stat_impl	ipp_stat_impl_t;
209*7c478bd9Sstevel@tonic-gate 
210*7c478bd9Sstevel@tonic-gate struct ipp_stat_impl {
211*7c478bd9Sstevel@tonic-gate 	void		*ippsi_data;
212*7c478bd9Sstevel@tonic-gate 	kstat_t		*ippsi_ksp;
213*7c478bd9Sstevel@tonic-gate 	int		ippsi_limit;
214*7c478bd9Sstevel@tonic-gate 	int		ippsi_count;
215*7c478bd9Sstevel@tonic-gate 	int		(*ippsi_update)(ipp_stat_t *, void *, int);
216*7c478bd9Sstevel@tonic-gate 	void		*ippsi_arg;
217*7c478bd9Sstevel@tonic-gate 	kmutex_t	ippsi_lock[1];
218*7c478bd9Sstevel@tonic-gate 	char		ippsi_name[MAXNAMELEN];
219*7c478bd9Sstevel@tonic-gate };
220*7c478bd9Sstevel@tonic-gate 
221*7c478bd9Sstevel@tonic-gate struct ipp_packet {
222*7c478bd9Sstevel@tonic-gate 	mblk_t		*ippp_data;
223*7c478bd9Sstevel@tonic-gate 	ipp_class_t	*ippp_class_array;
224*7c478bd9Sstevel@tonic-gate 	uint_t		ippp_class_limit;
225*7c478bd9Sstevel@tonic-gate 	uint_t		ippp_class_rindex;
226*7c478bd9Sstevel@tonic-gate 	uint_t		ippp_class_windex;
227*7c478bd9Sstevel@tonic-gate 	ipp_log_t	*ippp_log;
228*7c478bd9Sstevel@tonic-gate 	uint_t		ippp_log_limit;
229*7c478bd9Sstevel@tonic-gate 	uint_t		ippp_log_windex;
230*7c478bd9Sstevel@tonic-gate 	void		*ippp_private;
231*7c478bd9Sstevel@tonic-gate 	void		(*ippp_private_free)(void *);
232*7c478bd9Sstevel@tonic-gate };
233*7c478bd9Sstevel@tonic-gate 
234*7c478bd9Sstevel@tonic-gate extern void		ipp_init(void);
235*7c478bd9Sstevel@tonic-gate 
236*7c478bd9Sstevel@tonic-gate #endif	/* _KERNEL */
237*7c478bd9Sstevel@tonic-gate 
238*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus
239*7c478bd9Sstevel@tonic-gate }
240*7c478bd9Sstevel@tonic-gate #endif
241*7c478bd9Sstevel@tonic-gate 
242*7c478bd9Sstevel@tonic-gate #endif /* _IPP_IPP_IMPL_H */
243