1/*	$FreeBSD$	*/
2/*	$KAME: altq_cbq.h,v 1.10 2003/08/20 23:30:23 itojun 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 <altq/altq.h>
38#include <altq/altq_rmclass.h>
39#include <altq/altq_red.h>
40#include <altq/altq_rio.h>
41
42/* #pragma ident "@(#)cbq.h  1.18     98/05/13 SMI" */
43
44#ifdef __cplusplus
45extern "C" {
46#endif
47
48/*
49 * Define a well known class handles
50 */
51#define	NULL_CLASS_HANDLE	0xffffffff
52#define	ROOT_CLASS_HANDLE	0xfffffffe
53#define	DEFAULT_CLASS_HANDLE	0xfffffffd
54#ifdef ALTQ3_COMPAT
55#define	CTL_CLASS_HANDLE	0xfffffffc
56#endif
57
58/* class flags shoud be same as class flags in rm_class.h */
59#define	CBQCLF_RED		0x0001	/* use RED */
60#define	CBQCLF_ECN		0x0002  /* use RED/ECN */
61#define	CBQCLF_RIO		0x0004  /* use RIO */
62#define	CBQCLF_FLOWVALVE	0x0008	/* use flowvalve (aka penalty-box) */
63#define	CBQCLF_CLEARDSCP	0x0010  /* clear diffserv codepoint */
64#define	CBQCLF_BORROW		0x0020  /* borrow from parent */
65
66/* class flags only for root class */
67#define	CBQCLF_WRR		0x0100	/* weighted-round robin */
68#define	CBQCLF_EFFICIENT	0x0200  /* work-conserving */
69
70/* class flags for special classes */
71#define	CBQCLF_ROOTCLASS	0x1000	/* root class */
72#define	CBQCLF_DEFCLASS		0x2000	/* default class */
73#ifdef ALTQ3_COMPAT
74#define	CBQCLF_CTLCLASS		0x4000	/* control class */
75#endif
76#define	CBQCLF_CLASSMASK	0xf000	/* class mask */
77
78#define	CBQ_MAXQSIZE		200
79#define	CBQ_MAXPRI		RM_MAXPRIO
80
81typedef struct _cbq_class_stats_ {
82	u_int32_t	handle;
83	u_int		depth;
84
85	struct pktcntr	xmit_cnt;	/* packets sent in this class */
86	struct pktcntr	drop_cnt;	/* dropped packets */
87	u_int		over;		/* # times went over limit */
88	u_int		borrows;	/* # times tried to borrow */
89	u_int		overactions;	/* # times invoked overlimit action */
90	u_int		delays;		/* # times invoked delay actions */
91
92	/* other static class parameters useful for debugging */
93	int		priority;
94	int		maxidle;
95	int		minidle;
96	int		offtime;
97	int		qmax;
98	int		ns_per_byte;
99	int		wrr_allot;
100
101	int		qcnt;		/* # packets in queue */
102	int		avgidle;
103
104	/* red and rio related info */
105	int		qtype;
106	struct redstats	red[3];
107} class_stats_t;
108
109#ifdef ALTQ3_COMPAT
110/*
111 * Define structures associated with IOCTLS for cbq.
112 */
113
114/*
115 * Define the CBQ interface structure.  This must be included in all
116 * IOCTL's such that the CBQ driver may find the appropriate CBQ module
117 * associated with the network interface to be affected.
118 */
119struct cbq_interface {
120	char	cbq_ifacename[IFNAMSIZ];
121};
122
123typedef struct cbq_class_spec {
124	u_int		priority;
125	u_int		nano_sec_per_byte;
126	u_int		maxq;
127	u_int		maxidle;
128	int		minidle;
129	u_int		offtime;
130	u_int32_t	parent_class_handle;
131	u_int32_t	borrow_class_handle;
132
133	u_int		pktsize;
134	int		flags;
135} cbq_class_spec_t;
136
137struct cbq_add_class {
138	struct cbq_interface	cbq_iface;
139
140	cbq_class_spec_t	cbq_class;
141	u_int32_t		cbq_class_handle;
142};
143
144struct cbq_delete_class {
145	struct cbq_interface	cbq_iface;
146	u_int32_t		cbq_class_handle;
147};
148
149struct cbq_modify_class {
150	struct cbq_interface	cbq_iface;
151
152	cbq_class_spec_t	cbq_class;
153	u_int32_t		cbq_class_handle;
154};
155
156struct cbq_add_filter {
157	struct cbq_interface		cbq_iface;
158	u_int32_t		cbq_class_handle;
159	struct flow_filter	cbq_filter;
160
161	u_long			cbq_filter_handle;
162};
163
164struct cbq_delete_filter {
165	struct cbq_interface	cbq_iface;
166	u_long			cbq_filter_handle;
167};
168
169/* number of classes are returned in nclasses field */
170struct cbq_getstats {
171	struct cbq_interface	iface;
172	int			nclasses;
173	class_stats_t		*stats;
174};
175
176/*
177 * Define IOCTLs for CBQ.
178 */
179#define	CBQ_IF_ATTACH		_IOW('Q', 1, struct cbq_interface)
180#define	CBQ_IF_DETACH		_IOW('Q', 2, struct cbq_interface)
181#define	CBQ_ENABLE		_IOW('Q', 3, struct cbq_interface)
182#define	CBQ_DISABLE		_IOW('Q', 4, struct cbq_interface)
183#define	CBQ_CLEAR_HIERARCHY	_IOW('Q', 5, struct cbq_interface)
184#define	CBQ_ADD_CLASS		_IOWR('Q', 7, struct cbq_add_class)
185#define	CBQ_DEL_CLASS		_IOW('Q', 8, struct cbq_delete_class)
186#define	CBQ_MODIFY_CLASS	_IOWR('Q', 9, struct cbq_modify_class)
187#define	CBQ_ADD_FILTER		_IOWR('Q', 10, struct cbq_add_filter)
188#define	CBQ_DEL_FILTER		_IOW('Q', 11, struct cbq_delete_filter)
189#define	CBQ_GETSTATS		_IOWR('Q', 12, struct cbq_getstats)
190#endif /* ALTQ3_COMPAT */
191
192#ifdef _KERNEL
193/*
194 * Define macros only good for kernel drivers and modules.
195 */
196#define	CBQ_WATCHDOG    	(hz / 20)
197#define	CBQ_TIMEOUT		10
198#define	CBQ_LS_TIMEOUT		(20 * hz / 1000)
199
200#define	CBQ_MAX_CLASSES	256
201
202#ifdef ALTQ3_COMPAT
203#define	CBQ_MAX_FILTERS 256
204
205#define	DISABLE		0x00
206#define	ENABLE		0x01
207#endif /* ALTQ3_COMPAT */
208
209/*
210 * Define State structures.
211 */
212typedef struct cbqstate {
213#ifdef ALTQ3_COMPAT
214	struct cbqstate		*cbq_next;
215#endif
216	int			 cbq_qlen;	/* # of packets in cbq */
217	struct rm_class		*cbq_class_tbl[CBQ_MAX_CLASSES];
218
219	struct rm_ifdat		 ifnp;
220	struct callout		 cbq_callout;	/* for timeouts */
221#ifdef ALTQ3_CLFIER_COMPAT
222	struct acc_classifier	cbq_classifier;
223#endif
224} cbq_state_t;
225
226#endif /* _KERNEL */
227
228#ifdef __cplusplus
229}
230#endif
231
232#endif /* !_ALTQ_ALTQ_CBQ_H_ */
233