1130365Smlaier/*	$KAME: altq_cbq.h,v 1.12 2003/10/03 05:05:15 kjc Exp $	*/
2130365Smlaier
3130365Smlaier/*
4130365Smlaier * Copyright (c) Sun Microsystems, Inc. 1993-1998 All rights reserved.
5130365Smlaier *
6130365Smlaier * Redistribution and use in source and binary forms, with or without
7130365Smlaier * modification, are permitted provided that the following conditions
8130365Smlaier * are met:
9130365Smlaier *
10130365Smlaier * 1. Redistributions of source code must retain the above copyright
11130365Smlaier *    notice, this list of conditions and the following disclaimer.
12130365Smlaier *
13130365Smlaier * 2. Redistributions in binary form must reproduce the above copyright
14130365Smlaier *    notice, this list of conditions and the following disclaimer in the
15130365Smlaier *    documentation and/or other materials provided with the distribution.
16130365Smlaier *
17130365Smlaier * 3. All advertising materials mentioning features or use of this software
18130365Smlaier *    must display the following acknowledgement:
19130365Smlaier *      This product includes software developed by the SMCC Technology
20130365Smlaier *      Development Group at Sun Microsystems, Inc.
21130365Smlaier *
22130365Smlaier * 4. The name of the Sun Microsystems, Inc nor may not be used to endorse or
23130365Smlaier *      promote products derived from this software without specific prior
24130365Smlaier *      written permission.
25130365Smlaier *
26130365Smlaier * SUN MICROSYSTEMS DOES NOT CLAIM MERCHANTABILITY OF THIS SOFTWARE OR THE
27130365Smlaier * SUITABILITY OF THIS SOFTWARE FOR ANY PARTICULAR PURPOSE.  The software is
28130365Smlaier * provided "as is" without express or implied warranty of any kind.
29130365Smlaier *
30130365Smlaier * These notices must be retained in any copies of any part of this software.
31130365Smlaier */
32130365Smlaier
33130365Smlaier#ifndef _ALTQ_ALTQ_CBQ_H_
34130365Smlaier#define	_ALTQ_ALTQ_CBQ_H_
35130365Smlaier
36130365Smlaier#include <altq/altq.h>
37130365Smlaier#include <altq/altq_rmclass.h>
38130365Smlaier#include <altq/altq_red.h>
39130365Smlaier#include <altq/altq_rio.h>
40130365Smlaier
41130365Smlaier#ifdef __cplusplus
42130365Smlaierextern "C" {
43130365Smlaier#endif
44130365Smlaier
45130365Smlaier#define	NULL_CLASS_HANDLE	0
46130365Smlaier
47130365Smlaier/* class flags should be same as class flags in rm_class.h */
48130365Smlaier#define	CBQCLF_RED		0x0001	/* use RED */
49130365Smlaier#define	CBQCLF_ECN		0x0002  /* use RED/ECN */
50130365Smlaier#define	CBQCLF_RIO		0x0004  /* use RIO */
51130365Smlaier#define	CBQCLF_FLOWVALVE	0x0008	/* use flowvalve (aka penalty-box) */
52130365Smlaier#define	CBQCLF_CLEARDSCP	0x0010  /* clear diffserv codepoint */
53130365Smlaier#define	CBQCLF_BORROW		0x0020  /* borrow from parent */
54130365Smlaier
55130365Smlaier/* class flags only for root class */
56130365Smlaier#define	CBQCLF_WRR		0x0100	/* weighted-round robin */
57130365Smlaier#define	CBQCLF_EFFICIENT	0x0200  /* work-conserving */
58130365Smlaier
59130365Smlaier/* class flags for special classes */
60130365Smlaier#define	CBQCLF_ROOTCLASS	0x1000	/* root class */
61130365Smlaier#define	CBQCLF_DEFCLASS		0x2000	/* default class */
62130365Smlaier#ifdef ALTQ3_COMPAT
63130365Smlaier#define	CBQCLF_CTLCLASS		0x4000	/* control class */
64130365Smlaier#endif
65130365Smlaier#define	CBQCLF_CLASSMASK	0xf000	/* class mask */
66130365Smlaier
67130365Smlaier#define	CBQ_MAXQSIZE		200
68130365Smlaier#define	CBQ_MAXPRI		RM_MAXPRIO
69130365Smlaier
70130365Smlaiertypedef struct _cbq_class_stats_ {
71130365Smlaier	u_int32_t	handle;
72130365Smlaier	u_int		depth;
73130365Smlaier
74130365Smlaier	struct pktcntr	xmit_cnt;	/* packets sent in this class */
75130365Smlaier	struct pktcntr	drop_cnt;	/* dropped packets */
76130365Smlaier	u_int		over;		/* # times went over limit */
77130365Smlaier	u_int		borrows;	/* # times tried to borrow */
78130365Smlaier	u_int		overactions;	/* # times invoked overlimit action */
79130365Smlaier	u_int		delays;		/* # times invoked delay actions */
80130365Smlaier
81130365Smlaier	/* other static class parameters useful for debugging */
82130365Smlaier	int		priority;
83130365Smlaier	int		maxidle;
84130365Smlaier	int		minidle;
85130365Smlaier	int		offtime;
86130365Smlaier	int		qmax;
87130365Smlaier	int		ns_per_byte;
88130365Smlaier	int		wrr_allot;
89130365Smlaier
90130365Smlaier	int		qcnt;		/* # packets in queue */
91130365Smlaier	int		avgidle;
92130365Smlaier
93130365Smlaier	/* red and rio related info */
94130365Smlaier	int		qtype;
95130365Smlaier	struct redstats	red[3];
96130365Smlaier} class_stats_t;
97130365Smlaier
98130365Smlaier#ifdef ALTQ3_COMPAT
99130365Smlaier/*
100130365Smlaier * Define structures associated with IOCTLS for cbq.
101130365Smlaier */
102130365Smlaier
103130365Smlaier/*
104130365Smlaier * Define the CBQ interface structure.  This must be included in all
105130365Smlaier * IOCTL's such that the CBQ driver may find the appropriate CBQ module
106130365Smlaier * associated with the network interface to be affected.
107130365Smlaier */
108130365Smlaierstruct cbq_interface {
109130365Smlaier	char	cbq_ifacename[IFNAMSIZ];
110130365Smlaier};
111130365Smlaier
112130365Smlaiertypedef struct cbq_class_spec {
113130365Smlaier	u_int		priority;
114130365Smlaier	u_int		nano_sec_per_byte;
115130365Smlaier	u_int		maxq;
116130365Smlaier	u_int		maxidle;
117130365Smlaier	int		minidle;
118130365Smlaier	u_int		offtime;
119130365Smlaier	u_int32_t	parent_class_handle;
120130365Smlaier	u_int32_t	borrow_class_handle;
121130365Smlaier
122130365Smlaier	u_int		pktsize;
123130365Smlaier	int		flags;
124130365Smlaier} cbq_class_spec_t;
125130365Smlaier
126130365Smlaierstruct cbq_add_class {
127130365Smlaier	struct cbq_interface	cbq_iface;
128130365Smlaier
129130365Smlaier	cbq_class_spec_t	cbq_class;
130130365Smlaier	u_int32_t		cbq_class_handle;
131130365Smlaier};
132130365Smlaier
133130365Smlaierstruct cbq_delete_class {
134130365Smlaier	struct cbq_interface	cbq_iface;
135130365Smlaier	u_int32_t		cbq_class_handle;
136130365Smlaier};
137130365Smlaier
138130365Smlaierstruct cbq_modify_class {
139130365Smlaier	struct cbq_interface	cbq_iface;
140130365Smlaier
141130365Smlaier	cbq_class_spec_t	cbq_class;
142130365Smlaier	u_int32_t		cbq_class_handle;
143130365Smlaier};
144130365Smlaier
145130365Smlaierstruct cbq_add_filter {
146130365Smlaier	struct cbq_interface		cbq_iface;
147130365Smlaier	u_int32_t		cbq_class_handle;
148130365Smlaier	struct flow_filter	cbq_filter;
149130365Smlaier
150130365Smlaier	u_long			cbq_filter_handle;
151130365Smlaier};
152130365Smlaier
153130365Smlaierstruct cbq_delete_filter {
154130365Smlaier	struct cbq_interface	cbq_iface;
155130365Smlaier	u_long			cbq_filter_handle;
156130365Smlaier};
157130365Smlaier
158130365Smlaier/* number of classes are returned in nclasses field */
159130365Smlaierstruct cbq_getstats {
160130365Smlaier	struct cbq_interface	iface;
161130365Smlaier	int			nclasses;
162130365Smlaier	class_stats_t		*stats;
163130365Smlaier};
164130365Smlaier
165130365Smlaier/*
166130365Smlaier * Define IOCTLs for CBQ.
167130365Smlaier */
168130365Smlaier#define	CBQ_IF_ATTACH		_IOW('Q', 1, struct cbq_interface)
169130365Smlaier#define	CBQ_IF_DETACH		_IOW('Q', 2, struct cbq_interface)
170130365Smlaier#define	CBQ_ENABLE		_IOW('Q', 3, struct cbq_interface)
171130365Smlaier#define	CBQ_DISABLE		_IOW('Q', 4, struct cbq_interface)
172130365Smlaier#define	CBQ_CLEAR_HIERARCHY	_IOW('Q', 5, struct cbq_interface)
173130365Smlaier#define	CBQ_ADD_CLASS		_IOWR('Q', 7, struct cbq_add_class)
174130365Smlaier#define	CBQ_DEL_CLASS		_IOW('Q', 8, struct cbq_delete_class)
175130365Smlaier#define	CBQ_MODIFY_CLASS	_IOWR('Q', 9, struct cbq_modify_class)
176130365Smlaier#define	CBQ_ADD_FILTER		_IOWR('Q', 10, struct cbq_add_filter)
177130365Smlaier#define	CBQ_DEL_FILTER		_IOW('Q', 11, struct cbq_delete_filter)
178130365Smlaier#define	CBQ_GETSTATS		_IOWR('Q', 12, struct cbq_getstats)
179130365Smlaier#endif /* ALTQ3_COMPAT */
180130365Smlaier
181130365Smlaier#ifdef _KERNEL
182130365Smlaier/*
183130365Smlaier * Define macros only good for kernel drivers and modules.
184130365Smlaier */
185130365Smlaier#define	CBQ_WATCHDOG		(hz / 20)
186130365Smlaier#define	CBQ_TIMEOUT		10
187130365Smlaier#define	CBQ_LS_TIMEOUT		(20 * hz / 1000)
188130365Smlaier
189130365Smlaier#define	CBQ_MAX_CLASSES	256
190130365Smlaier
191130365Smlaier#ifdef ALTQ3_COMPAT
192130365Smlaier#define	CBQ_MAX_FILTERS 256
193130365Smlaier
194130365Smlaier#define	DISABLE		0x00
195130365Smlaier#define	ENABLE		0x01
196130365Smlaier#endif /* ALTQ3_COMPAT */
197130365Smlaier
198130365Smlaier/*
199130365Smlaier * Define State structures.
200130365Smlaier */
201130365Smlaiertypedef struct cbqstate {
202130365Smlaier#ifdef ALTQ3_COMPAT
203130365Smlaier	struct cbqstate		*cbq_next;
204130365Smlaier#endif
205130365Smlaier	int			 cbq_qlen;	/* # of packets in cbq */
206130365Smlaier	struct rm_class		*cbq_class_tbl[CBQ_MAX_CLASSES];
207130365Smlaier
208130365Smlaier	struct rm_ifdat		 ifnp;
209130365Smlaier	struct callout		 cbq_callout;	/* for timeouts */
210130365Smlaier#ifdef ALTQ3_CLFIER_COMPAT
211130365Smlaier	struct acc_classifier	cbq_classifier;
212130365Smlaier#endif
213130365Smlaier} cbq_state_t;
214130365Smlaier
215130365Smlaier#endif /* _KERNEL */
216130365Smlaier
217130365Smlaier#ifdef __cplusplus
218130365Smlaier}
219130365Smlaier#endif
220130365Smlaier
221130365Smlaier#endif /* !_ALTQ_ALTQ_CBQ_H_ */
222