xref: /freebsd/sys/net/altq/altq_fairq.h (revision 2ff63af9b88c7413b7d71715b5532625752a248e)
1a5b789f6SErmal Luçi /*
2a5b789f6SErmal Luçi  * Copyright (c) 2008 The DragonFly Project.  All rights reserved.
3a5b789f6SErmal Luçi  *
4a5b789f6SErmal Luçi  * This code is derived from software contributed to The DragonFly Project
5a5b789f6SErmal Luçi  * by Matthew Dillon <dillon@backplane.com>
6a5b789f6SErmal Luçi  *
7a5b789f6SErmal Luçi  * Redistribution and use in source and binary forms, with or without
8a5b789f6SErmal Luçi  * modification, are permitted provided that the following conditions
9a5b789f6SErmal Luçi  * are met:
10a5b789f6SErmal Luçi  *
11a5b789f6SErmal Luçi  * 1. Redistributions of source code must retain the above copyright
12a5b789f6SErmal Luçi  *    notice, this list of conditions and the following disclaimer.
13a5b789f6SErmal Luçi  * 2. Redistributions in binary form must reproduce the above copyright
14a5b789f6SErmal Luçi  *    notice, this list of conditions and the following disclaimer in
15a5b789f6SErmal Luçi  *    the documentation and/or other materials provided with the
16a5b789f6SErmal Luçi  *    distribution.
17a5b789f6SErmal Luçi  * 3. Neither the name of The DragonFly Project nor the names of its
18a5b789f6SErmal Luçi  *    contributors may be used to endorse or promote products derived
19a5b789f6SErmal Luçi  *    from this software without specific, prior written permission.
20a5b789f6SErmal Luçi  *
21a5b789f6SErmal Luçi  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22a5b789f6SErmal Luçi  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23a5b789f6SErmal Luçi  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24a5b789f6SErmal Luçi  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
25a5b789f6SErmal Luçi  * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26a5b789f6SErmal Luçi  * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
27a5b789f6SErmal Luçi  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28a5b789f6SErmal Luçi  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29a5b789f6SErmal Luçi  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30a5b789f6SErmal Luçi  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
31a5b789f6SErmal Luçi  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32a5b789f6SErmal Luçi  * SUCH DAMAGE.
33a5b789f6SErmal Luçi  *
34a5b789f6SErmal Luçi  * $DragonFly: src/sys/net/altq/altq_fairq.h,v 1.1 2008/04/06 18:58:15 dillon Exp $
35a5b789f6SErmal Luçi  */
36a5b789f6SErmal Luçi 
37a5b789f6SErmal Luçi #ifndef _ALTQ_ALTQ_FAIRQ_H_
38a5b789f6SErmal Luçi #define	_ALTQ_ALTQ_FAIRQ_H_
39a5b789f6SErmal Luçi 
40a5b789f6SErmal Luçi #include <net/altq/altq.h>
41a5b789f6SErmal Luçi #include <net/altq/altq_classq.h>
420a70aaf8SLuiz Otavio O Souza #include <net/altq/altq_codel.h>
43a5b789f6SErmal Luçi #include <net/altq/altq_red.h>
44a5b789f6SErmal Luçi #include <net/altq/altq_rio.h>
45a5b789f6SErmal Luçi #include <net/altq/altq_rmclass.h>
46a5b789f6SErmal Luçi 
47a5b789f6SErmal Luçi #define	FAIRQ_MAX_BUCKETS	2048	/* maximum number of sorting buckets */
48a5b789f6SErmal Luçi #define	FAIRQ_MAXPRI		RM_MAXPRIO
49a5b789f6SErmal Luçi #define FAIRQ_BITMAP_WIDTH	(sizeof(fairq_bitmap_t)*8)
50a5b789f6SErmal Luçi #define FAIRQ_BITMAP_MASK	(FAIRQ_BITMAP_WIDTH - 1)
51a5b789f6SErmal Luçi 
52a5b789f6SErmal Luçi /* fairq class flags */
53a5b789f6SErmal Luçi #define	FARF_RED		0x0001	/* use RED */
54a5b789f6SErmal Luçi #define	FARF_ECN		0x0002  /* use RED/ECN */
55a5b789f6SErmal Luçi #define	FARF_RIO		0x0004  /* use RIO */
560a70aaf8SLuiz Otavio O Souza #define	FARF_CODEL		0x0008	/* use CoDel */
57a5b789f6SErmal Luçi #define	FARF_CLEARDSCP		0x0010  /* clear diffserv codepoint */
58a5b789f6SErmal Luçi #define	FARF_DEFAULTCLASS	0x1000	/* default class */
59a5b789f6SErmal Luçi 
60a5b789f6SErmal Luçi #define FARF_HAS_PACKETS	0x2000	/* might have queued packets */
61a5b789f6SErmal Luçi 
62a5b789f6SErmal Luçi #define FARF_USERFLAGS		(FARF_RED|FARF_ECN|FARF_RIO|FARF_CLEARDSCP| \
63a5b789f6SErmal Luçi 				 FARF_DEFAULTCLASS)
64a5b789f6SErmal Luçi 
65a5b789f6SErmal Luçi /* special class handles */
66a5b789f6SErmal Luçi #define	FAIRQ_NULLCLASS_HANDLE	0
67a5b789f6SErmal Luçi 
68a5b789f6SErmal Luçi typedef u_int	fairq_bitmap_t;
69a5b789f6SErmal Luçi 
70a5b789f6SErmal Luçi struct fairq_classstats {
71a5b789f6SErmal Luçi 	uint32_t		class_handle;
72a5b789f6SErmal Luçi 
73a5b789f6SErmal Luçi 	u_int			qlength;
74a5b789f6SErmal Luçi 	u_int			qlimit;
75a5b789f6SErmal Luçi 	struct pktcntr		xmit_cnt;  /* transmitted packet counter */
76a5b789f6SErmal Luçi 	struct pktcntr		drop_cnt;  /* dropped packet counter */
77a5b789f6SErmal Luçi 
780a70aaf8SLuiz Otavio O Souza 	/* codel, red and rio related info */
79a5b789f6SErmal Luçi 	int			qtype;
80a5b789f6SErmal Luçi 	struct redstats		red[3];	/* rio has 3 red stats */
810a70aaf8SLuiz Otavio O Souza 	struct codel_stats	codel;
82a5b789f6SErmal Luçi };
83a5b789f6SErmal Luçi 
84*249cc75fSPatrick Kelsey /*
85*249cc75fSPatrick Kelsey  * FAIRQ_STATS_VERSION is defined in altq.h to work around issues stemming
86*249cc75fSPatrick Kelsey  * from mixing of public-API and internal bits in each scheduler-specific
87*249cc75fSPatrick Kelsey  * header.
88*249cc75fSPatrick Kelsey  */
89*249cc75fSPatrick Kelsey 
90a5b789f6SErmal Luçi #ifdef _KERNEL
91a5b789f6SErmal Luçi 
92a5b789f6SErmal Luçi typedef struct fairq_bucket {
93a5b789f6SErmal Luçi 	struct fairq_bucket *next;	/* circular list */
94a5b789f6SErmal Luçi 	struct fairq_bucket *prev;	/* circular list */
95a5b789f6SErmal Luçi 	class_queue_t	queue;		/* the actual queue */
96a5b789f6SErmal Luçi 	uint64_t	bw_bytes;	/* statistics used to calculate bw */
97a5b789f6SErmal Luçi 	uint64_t	bw_delta;	/* statistics used to calculate bw */
98a5b789f6SErmal Luçi 	uint64_t	last_time;
99a5b789f6SErmal Luçi 	int		in_use;
100a5b789f6SErmal Luçi } fairq_bucket_t;
101a5b789f6SErmal Luçi 
102a5b789f6SErmal Luçi struct fairq_class {
103a5b789f6SErmal Luçi 	uint32_t	cl_handle;	/* class handle */
104a5b789f6SErmal Luçi 	u_int		cl_nbuckets;	/* (power of 2) */
105a5b789f6SErmal Luçi 	u_int		cl_nbucket_mask; /* bucket mask */
106a5b789f6SErmal Luçi 	fairq_bucket_t	*cl_buckets;
107a5b789f6SErmal Luçi 	fairq_bucket_t	*cl_head;	/* head of circular bucket list */
108a5b789f6SErmal Luçi 	fairq_bucket_t	*cl_polled;
1090a70aaf8SLuiz Otavio O Souza 	union {
110a5b789f6SErmal Luçi 		struct red	*cl_red;	/* RED state */
1110a70aaf8SLuiz Otavio O Souza 		struct codel	*cl_codel;	/* CoDel state */
1120a70aaf8SLuiz Otavio O Souza 	} cl_aqm;
1130a70aaf8SLuiz Otavio O Souza #define	cl_red		cl_aqm.cl_red
1140a70aaf8SLuiz Otavio O Souza #define	cl_codel	cl_aqm.cl_codel
115a5b789f6SErmal Luçi 	u_int		cl_hogs_m1;
116a5b789f6SErmal Luçi 	u_int		cl_lssc_m1;
117a5b789f6SErmal Luçi 	u_int		cl_bandwidth;
118a5b789f6SErmal Luçi 	uint64_t	cl_bw_bytes;
119a5b789f6SErmal Luçi 	uint64_t	cl_bw_delta;
120a5b789f6SErmal Luçi 	uint64_t	cl_last_time;
121a5b789f6SErmal Luçi 	int		cl_qtype;	/* rollup */
122a5b789f6SErmal Luçi 	int		cl_qlimit;
123a5b789f6SErmal Luçi 	int		cl_pri;		/* priority */
124a5b789f6SErmal Luçi 	int		cl_flags;	/* class flags */
125a5b789f6SErmal Luçi 	struct fairq_if	*cl_pif;	/* back pointer to pif */
126a5b789f6SErmal Luçi 	struct altq_pktattr *cl_pktattr; /* saved header used by ECN */
127a5b789f6SErmal Luçi 
128a5b789f6SErmal Luçi 	/* round robin index */
129a5b789f6SErmal Luçi 
130a5b789f6SErmal Luçi 	/* statistics */
131a5b789f6SErmal Luçi 	struct pktcntr  cl_xmitcnt;	/* transmitted packet counter */
132a5b789f6SErmal Luçi 	struct pktcntr  cl_dropcnt;	/* dropped packet counter */
133a5b789f6SErmal Luçi };
134a5b789f6SErmal Luçi 
135a5b789f6SErmal Luçi /*
136a5b789f6SErmal Luçi  * fairq interface state
137a5b789f6SErmal Luçi  */
138a5b789f6SErmal Luçi struct fairq_if {
139a5b789f6SErmal Luçi 	struct fairq_if		*pif_next;	/* interface state list */
140a5b789f6SErmal Luçi 	struct ifaltq		*pif_ifq;	/* backpointer to ifaltq */
141a5b789f6SErmal Luçi 	u_int			pif_bandwidth;	/* link bandwidth in bps */
142a5b789f6SErmal Luçi 	int			pif_maxpri;	/* max priority in use */
143a5b789f6SErmal Luçi 	struct fairq_class	*pif_poll_cache;/* cached poll */
144a5b789f6SErmal Luçi 	struct fairq_class	*pif_default;	/* default class */
145a5b789f6SErmal Luçi 	struct fairq_class	*pif_classes[FAIRQ_MAXPRI]; /* classes */
146a5b789f6SErmal Luçi };
147a5b789f6SErmal Luçi 
148a5b789f6SErmal Luçi #endif /* _KERNEL */
149a5b789f6SErmal Luçi 
150a5b789f6SErmal Luçi #endif /* _ALTQ_ALTQ_FAIRQ_H_ */
151