1 /*
2  * spppcomp.h - Solaris STREAMS PPP compression module definitions
3  *
4  * Copyright 2000-2002 Sun Microsystems, Inc.  All rights reserved.
5  * Use is subject to license terms.
6  *
7  * Permission to use, copy, modify, and distribute this software and its
8  * documentation is hereby granted, provided that the above copyright
9  * notice appears in all copies.
10  *
11  * SUN MAKES NO REPRESENTATION OR WARRANTIES ABOUT THE SUITABILITY OF
12  * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
13  * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
14  * PARTICULAR PURPOSE, OR NON-INFRINGEMENT.  SUN SHALL NOT BE LIABLE FOR
15  * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
16  * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES
17  *
18  * Copyright (c) 1994 The Australian National University.
19  * All rights reserved.
20  *
21  * Permission to use, copy, modify, and distribute this software and its
22  * documentation is hereby granted, provided that the above copyright
23  * notice appears in all copies.  This software is provided without any
24  * warranty, express or implied. The Australian National University
25  * makes no representations about the suitability of this software for
26  * any purpose.
27  *
28  * IN NO EVENT SHALL THE AUSTRALIAN NATIONAL UNIVERSITY BE LIABLE TO ANY
29  * PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
30  * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
31  * THE AUSTRALIAN NATIONAL UNIVERSITY HAS BEEN ADVISED OF THE POSSIBILITY
32  * OF SUCH DAMAGE.
33  *
34  * THE AUSTRALIAN NATIONAL UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES,
35  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
36  * AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
37  * ON AN "AS IS" BASIS, AND THE AUSTRALIAN NATIONAL UNIVERSITY HAS NO
38  * OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
39  * OR MODIFICATIONS.
40  *
41  * This driver is derived from the original SVR4 STREAMS PPP driver
42  * originally written by Paul Mackerras <paul.mackerras@cs.anu.edu.au>.
43  *
44  * Adi Masputra <adi.masputra@sun.com> rewrote and restructured the code
45  * for improved performance and scalability.
46  */
47 
48 #ifndef __SPPPCOMP_H
49 #define	__SPPPCOMP_H
50 
51 #ifdef	__cplusplus
52 extern "C" {
53 #endif
54 
55 /*
56  * Per-unit kstats.
57  */
58 typedef struct spppcomp_kstats {
59 	kstat_named_t	vj_out_pkts;
60 	kstat_named_t	vj_out_pkts_comp;
61 	kstat_named_t	vj_cs_searches;
62 	kstat_named_t	vj_cs_misses;
63 	kstat_named_t	vj_in_pkts_uncomp;
64 	kstat_named_t	vj_in_pkts_comp;
65 	kstat_named_t	vj_in_error;
66 	kstat_named_t	vj_in_tossed;
67 	kstat_named_t	out_errors_low;
68 	kstat_named_t	out_uncomp_bytes;
69 	kstat_named_t	out_uncomp_pkts;
70 	kstat_named_t	out_comp_bytes;
71 	kstat_named_t	out_comp_pkts;
72 	kstat_named_t	out_incomp_bytes;
73 	kstat_named_t	out_incomp_pkts;
74 	kstat_named_t	in_errors_low;
75 	kstat_named_t	in_uncomp_bytes;
76 	kstat_named_t	in_uncomp_pkts;
77 	kstat_named_t	in_comp_bytes;
78 	kstat_named_t	in_comp_pkts;
79 	kstat_named_t	in_incomp_bytes;
80 	kstat_named_t	in_incomp_pkts;
81 #ifdef SPC_DEBUG
82 	kstat_named_t	in_msg_ccp_pulledup;
83 	kstat_named_t	in_msg_vj_pulledup;
84 	kstat_named_t	out_msg_pulledup;
85 	kstat_named_t	out_msg_copied;
86 	kstat_named_t	out_queued;
87 	kstat_named_t	out_handled;
88 	kstat_named_t	in_queued;
89 	kstat_named_t	in_handled;
90 #endif
91 
92 	/* 64 bit entries */
93 	kstat_named_t	out_bytes;
94 	kstat_named_t	out_pkts;
95 	kstat_named_t	out_errors;
96 	kstat_named_t	in_bytes;
97 	kstat_named_t	in_pkts;
98 	kstat_named_t	in_errors;
99 } spppcomp_kstats_t;
100 
101 #define	SPPPCOMP_KSTATS_NAMES \
102 	"vj_out_pkts", "vj_out_pkts_comp", "vj_cs_searches", \
103 	"vj_cs_misses", "vj_in_pkts_uncomp", "vj_in_pkts_comp", \
104 	"vj_in_error", "vj_in_tossed",  "out_errors_lower", \
105 	"out_uncomp_bytes", "out_uncomp_pkts", "out_comp_bytes", \
106 	"out_comp_pkts", "out_incomp_bytes", "out_incomp_pkts", \
107 	"in_errors_lower", "in_uncomp_bytes", "in_uncomp_pkts", \
108 	"in_comp_bytes", "in_comp_pkts", "in_incomp_bytes", \
109 	"in_incomp_pkts"
110 
111 #ifdef SPC_DEBUG
112 #define	SPCDEBUG_KSTATS_NAMES \
113 	"in_msg_ccp_pulledup", "in_msg_vj_pulledup", "out_msg_pulledup", \
114 	"out_msg_copied", "out_queued", "out_handled", \
115 	"in_queued", "in_handled"
116 #endif
117 
118 #define	SPPPCOMP_KSTATS64_NAMES \
119 	"out_bytes", "out_pkts", "out_errors", \
120 	"in_bytes", "in_pkts", 	"in_errors"
121 
122 /*
123  * Per-stream instance state information.
124  *
125  * Each instance is dynamically allocated at open() and freed at close().
126  * Each per-Stream instance points to at most one per-unit kstats structure
127  * using the cp_kstats field, which is allocated once per-Stream when
128  * PPPCTL_UNIT is received from above.
129  */
130 typedef struct sppp_comp {
131 	uint32_t		cp_flags;	/* miscellaneous flags */
132 	ushort_t		cp_mru;		/* link layer MRU */
133 	ushort_t		cp_mtu;		/* link layer MTU */
134 	uint32_t		cp_unit;	/* unique unit id */
135 	struct compressor	*cp_xcomp;	/* compressor structure */
136 	void			*cp_xstate;	/* compressor state */
137 	struct compressor	*cp_rcomp;	/* de-compressor structure */
138 	void			*cp_rstate;	/* de-compressor state */
139 	struct vjcompress	cp_vj;		/* VJ compression state */
140 	kmutex_t		cp_pair_lock;	/* lock for queue pair */
141 	hrtime_t		cp_lastfinish;	/* last decode finish time */
142 	int16_t			cp_effort;	/* configured effort level */
143 	int16_t			cp_nxslots;	/* VJ compress slots */
144 	uint16_t		cp_fastin;	/* count of fast inputs */
145 	ppp_counter_t		cp_vj_last_ierrors; /* last VJ input errors */
146 	struct pppstat64	cp_stats;	/* legacy stats structure */
147 	kstat_t			*cp_kstats;	/* ptr to kstats structure */
148 	uint32_t		cp_ierr_low;	/* in error from below */
149 	uint32_t		cp_oerr_low;	/* out error from below */
150 #ifdef SPC_DEBUG
151 	uint32_t		cp_imsg_ccp_pull; /* msgpullup on recv */
152 	uint32_t		cp_imsg_vj_pull;  /* msgpullup on recv */
153 	uint32_t		cp_omsg_pull;	/* msgpullup on send */
154 	uint32_t		cp_omsg_dcopy;	/* copymsg on send */
155 	uint32_t		cp_out_queued;	/* did putq */
156 	uint32_t		cp_out_handled;	/* did putnext */
157 	uint32_t		cp_in_queued;	/* did putq */
158 	uint32_t		cp_in_handled;	/* did putnext */
159 #endif
160 } sppp_comp_t;
161 
162 /*
163  * Bits in flags are as defined in pppio.h
164  *      COMP_AC         0x00000001	compress address/control
165  *      DECOMP_AC       0x00000002      decompress address/control
166  *      COMP_PROT       0x00000004      compress PPP protocol
167  *      DECOMP_PROT     0x00000008      decompress PPP protocol
168  *      COMP_VJC        0x00000010      compress TCP/IP headers
169  *      COMP_VJCCID     0x00000020      compress connection ID as well
170  *      DECOMP_VJC      0x00000040      decompress TCP/IP headers
171  *      DECOMP_VJCCID   0x00000080      accept compressed connection ID
172  *      CCP_ISOPEN      0x00000100      look at CCP packets
173  *      CCP_ISUP        0x00000200      do packet comp/decomp
174  *      CCP_ERROR       0x00000400      (status) error in packet decomp
175  *      CCP_FATALERROR  0x00000800      (status) fatal error ditto
176  *      CCP_COMP_RUN    0x00001000      (status) seen CCP ack sent
177  *      CCP_DECOMP_RUN  0x00002000      (status) seen CCP ack rcvd
178  */
179 #define	CP_KDEBUG	0x02000000	/* log debugging stuff */
180 #define	CP_HASUNIT	0x04000000	/* PPPCTL_UNIT has been issued on */
181 #define	CP_LASTMOD	0x08000000	/* last PPP-aware module in stream */
182 #define	CCP_ERR		(CCP_ERROR | CCP_FATALERROR)
183 
184 #define	IS_COMP_AC(x)	\
185 	((x)->cp_flags & COMP_AC)
186 #define	IS_DECOMP_AC(x)	\
187 	((x)->cp_flags & DECOMP_AC)
188 #define	IS_COMP_PROT(x)	\
189 	((x)->cp_flags & COMP_PROT)
190 #define	IS_DECOMP_PROT(x)	\
191 	((x)->cp_flags & DECOMP_PROT)
192 #define	IS_COMP_VJC(x)	\
193 	((x)->cp_flags & COMP_VJC)
194 #define	IS_COMP_VJCCID(x)	\
195 	((x)->cp_flags & COMP_VJCCID)
196 #define	IS_DECOMP_VJC(x)	\
197 	((x)->cp_flags & DECOMP_VJC)
198 #define	IS_DECOMP_VJCCID(x)	\
199 	((x)->cp_flags & DECOMP_VJCCID)
200 #define	IS_CCP_ISOPEN(x)	\
201 	((x)->cp_flags & CCP_ISOPEN)
202 #define	IS_CCP_ISUP(x)	\
203 	((x)->cp_flags & CCP_ISUP)
204 #define	IS_CCP_ERROR(x)	\
205 	((x)->cp_flags & CCP_ERROR)
206 #define	IS_CCP_FATALERROR(x)	\
207 	((x)->cp_flags & CCP_FATALERROR)
208 #define	IS_CCP_COMP_RUN(x)	\
209 	((x)->cp_flags & CCP_COMP_RUN)
210 #define	IS_CCP_DECOMP_RUN(x)	\
211 	((x)->cp_flags & CCP_DECOMP_RUN)
212 #define	IS_CP_KDEBUG(x)	\
213 	((x)->cp_flags & CP_KDEBUG)
214 #define	IS_CP_HASUNIT(x)	\
215 	((x)->cp_flags & CP_HASUNIT)
216 #define	IS_CP_LASTMOD(x)	\
217 	((x)->cp_flags & CP_LASTMOD)
218 
219 /*
220  * Bit format (octal based) string for cmn_err/printf, which
221  * represents the flags.
222  */
223 #define	CP_FLAGSSTR		\
224 	"\020"			\
225 	"\1comp_ac"		\
226 	"\2decomp_ac"		\
227 	"\3comp_prot"		\
228 	"\4decomp_prot"		\
229 	"\5comp_vjc"		\
230 	"\6comp_vjccid"		\
231 	"\7decomp_vjc"		\
232 	"\10decomp_vjccid"	\
233 	"\11ccp_isopen"		\
234 	"\12ccp_isup"		\
235 	"\13ccp_error"		\
236 	"\14ccp_fatalerror"	\
237 	"\15ccp_comp_run"	\
238 	"\16ccp_decomp_run"	\
239 	"\32kdebug"		\
240 	"\33hasunit"		\
241 	"\34lastmod"
242 
243 #ifdef	__cplusplus
244 }
245 #endif
246 
247 #endif /* __SPPPCOMP_H */
248