xref: /freebsd/sys/net/altq/altq_cbq.h (revision d3d381b2b194b4d24853e92eecef55f262688d1a)
1 /*-
2  * Copyright (c) Sun Microsystems, Inc. 1993-1998 All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * 3. All advertising materials mentioning features or use of this software
16  *    must display the following acknowledgement:
17  *      This product includes software developed by the SMCC Technology
18  *      Development Group at Sun Microsystems, Inc.
19  *
20  * 4. The name of the Sun Microsystems, Inc nor may not be used to endorse or
21  *      promote products derived from this software without specific prior
22  *      written permission.
23  *
24  * SUN MICROSYSTEMS DOES NOT CLAIM MERCHANTABILITY OF THIS SOFTWARE OR THE
25  * SUITABILITY OF THIS SOFTWARE FOR ANY PARTICULAR PURPOSE.  The software is
26  * provided "as is" without express or implied warranty of any kind.
27  *
28  * These notices must be retained in any copies of any part of this software.
29  *
30  * $KAME: altq_cbq.h,v 1.12 2003/10/03 05:05:15 kjc Exp $
31  * $FreeBSD$
32  */
33 
34 #ifndef _ALTQ_ALTQ_CBQ_H_
35 #define	_ALTQ_ALTQ_CBQ_H_
36 
37 #include <net/altq/altq.h>
38 #include <net/altq/altq_rmclass.h>
39 #include <net/altq/altq_codel.h>
40 #include <net/altq/altq_red.h>
41 #include <net/altq/altq_rio.h>
42 
43 #ifdef __cplusplus
44 extern "C" {
45 #endif
46 
47 #define	NULL_CLASS_HANDLE	0
48 
49 /* class flags should be same as class flags in rm_class.h */
50 #define	CBQCLF_RED		0x0001	/* use RED */
51 #define	CBQCLF_ECN		0x0002  /* use RED/ECN */
52 #define	CBQCLF_RIO		0x0004  /* use RIO */
53 #define	CBQCLF_FLOWVALVE	0x0008	/* use flowvalve (aka penalty-box) */
54 #define	CBQCLF_CLEARDSCP	0x0010  /* clear diffserv codepoint */
55 #define	CBQCLF_BORROW		0x0020  /* borrow from parent */
56 #define	CBQCLF_CODEL		0x0040	/* use CoDel */
57 
58 /* class flags only for root class */
59 #define	CBQCLF_WRR		0x0100	/* weighted-round robin */
60 #define	CBQCLF_EFFICIENT	0x0200  /* work-conserving */
61 
62 /* class flags for special classes */
63 #define	CBQCLF_ROOTCLASS	0x1000	/* root class */
64 #define	CBQCLF_DEFCLASS		0x2000	/* default class */
65 #ifdef ALTQ3_COMPAT
66 #define	CBQCLF_CTLCLASS		0x4000	/* control class */
67 #endif
68 #define	CBQCLF_CLASSMASK	0xf000	/* class mask */
69 
70 #define	CBQ_MAXQSIZE		200
71 #define	CBQ_MAXPRI		RM_MAXPRIO
72 
73 typedef struct _cbq_class_stats_ {
74 	u_int32_t	handle;
75 	u_int		depth;
76 
77 	struct pktcntr	xmit_cnt;	/* packets sent in this class */
78 	struct pktcntr	drop_cnt;	/* dropped packets */
79 	u_int		over;		/* # times went over limit */
80 	u_int		borrows;	/* # times tried to borrow */
81 	u_int		overactions;	/* # times invoked overlimit action */
82 	u_int		delays;		/* # times invoked delay actions */
83 
84 	/* other static class parameters useful for debugging */
85 	int		priority;
86 	int		maxidle;
87 	int		minidle;
88 	int		offtime;
89 	int		qmax;
90 	int		ns_per_byte;
91 	int		wrr_allot;
92 
93 	int		qcnt;		/* # packets in queue */
94 	int		avgidle;
95 
96 	/* codel, red and rio related info */
97 	int		qtype;
98 	struct redstats	red[3];
99 	struct codel_stats codel;
100 } class_stats_t;
101 
102 /*
103  * CBQ_STATS_VERSION is defined in altq.h to work around issues stemming
104  * from mixing of public-API and internal bits in each scheduler-specific
105  * header.
106  */
107 
108 #ifdef ALTQ3_COMPAT
109 /*
110  * Define structures associated with IOCTLS for cbq.
111  */
112 
113 /*
114  * Define the CBQ interface structure.  This must be included in all
115  * IOCTL's such that the CBQ driver may find the appropriate CBQ module
116  * associated with the network interface to be affected.
117  */
118 struct cbq_interface {
119 	char	cbq_ifacename[IFNAMSIZ];
120 };
121 
122 typedef struct cbq_class_spec {
123 	u_int		priority;
124 	u_int		nano_sec_per_byte;
125 	u_int		maxq;
126 	u_int		maxidle;
127 	int		minidle;
128 	u_int		offtime;
129 	u_int32_t	parent_class_handle;
130 	u_int32_t	borrow_class_handle;
131 
132 	u_int		pktsize;
133 	int		flags;
134 } cbq_class_spec_t;
135 
136 struct cbq_add_class {
137 	struct cbq_interface	cbq_iface;
138 
139 	cbq_class_spec_t	cbq_class;
140 	u_int32_t		cbq_class_handle;
141 };
142 
143 struct cbq_delete_class {
144 	struct cbq_interface	cbq_iface;
145 	u_int32_t		cbq_class_handle;
146 };
147 
148 struct cbq_modify_class {
149 	struct cbq_interface	cbq_iface;
150 
151 	cbq_class_spec_t	cbq_class;
152 	u_int32_t		cbq_class_handle;
153 };
154 
155 struct cbq_add_filter {
156 	struct cbq_interface		cbq_iface;
157 	u_int32_t		cbq_class_handle;
158 	struct flow_filter	cbq_filter;
159 
160 	u_long			cbq_filter_handle;
161 };
162 
163 struct cbq_delete_filter {
164 	struct cbq_interface	cbq_iface;
165 	u_long			cbq_filter_handle;
166 };
167 
168 /* number of classes are returned in nclasses field */
169 struct cbq_getstats {
170 	struct cbq_interface	iface;
171 	int			nclasses;
172 	class_stats_t		*stats;
173 };
174 
175 /*
176  * Define IOCTLs for CBQ.
177  */
178 #define	CBQ_IF_ATTACH		_IOW('Q', 1, struct cbq_interface)
179 #define	CBQ_IF_DETACH		_IOW('Q', 2, struct cbq_interface)
180 #define	CBQ_ENABLE		_IOW('Q', 3, struct cbq_interface)
181 #define	CBQ_DISABLE		_IOW('Q', 4, struct cbq_interface)
182 #define	CBQ_CLEAR_HIERARCHY	_IOW('Q', 5, struct cbq_interface)
183 #define	CBQ_ADD_CLASS		_IOWR('Q', 7, struct cbq_add_class)
184 #define	CBQ_DEL_CLASS		_IOW('Q', 8, struct cbq_delete_class)
185 #define	CBQ_MODIFY_CLASS	_IOWR('Q', 9, struct cbq_modify_class)
186 #define	CBQ_ADD_FILTER		_IOWR('Q', 10, struct cbq_add_filter)
187 #define	CBQ_DEL_FILTER		_IOW('Q', 11, struct cbq_delete_filter)
188 #define	CBQ_GETSTATS		_IOWR('Q', 12, struct cbq_getstats)
189 #endif /* ALTQ3_COMPAT */
190 
191 #ifdef _KERNEL
192 /*
193  * Define macros only good for kernel drivers and modules.
194  */
195 #define	CBQ_WATCHDOG		(hz / 20)
196 #define	CBQ_TIMEOUT		10
197 #define	CBQ_LS_TIMEOUT		(20 * hz / 1000)
198 
199 #define	CBQ_MAX_CLASSES	256
200 
201 #ifdef ALTQ3_COMPAT
202 #define	CBQ_MAX_FILTERS 256
203 
204 #define	DISABLE		0x00
205 #define	ENABLE		0x01
206 #endif /* ALTQ3_COMPAT */
207 
208 /*
209  * Define State structures.
210  */
211 typedef struct cbqstate {
212 #ifdef ALTQ3_COMPAT
213 	struct cbqstate		*cbq_next;
214 #endif
215 	int			 cbq_qlen;	/* # of packets in cbq */
216 	struct rm_class		*cbq_class_tbl[CBQ_MAX_CLASSES];
217 
218 	struct rm_ifdat		 ifnp;
219 	struct callout		 cbq_callout;	/* for timeouts */
220 #ifdef ALTQ3_CLFIER_COMPAT
221 	struct acc_classifier	cbq_classifier;
222 #endif
223 } cbq_state_t;
224 
225 #endif /* _KERNEL */
226 
227 #ifdef __cplusplus
228 }
229 #endif
230 
231 #endif /* !_ALTQ_ALTQ_CBQ_H_ */
232