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