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