2 * Copyright (c) 2008 The DragonFly Project. All rights reserved.
4 * This code is derived from software contributed to The DragonFly Project
5 * by Matthew Dillon <dillon@backplane.com>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * 3. Neither the name of The DragonFly Project nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific, prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
31 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * $DragonFly: src/sys/net/altq/altq_fairq.h,v 1.1 2008/04/06 18:58:15 dillon Exp $
38 #ifndef _ALTQ_ALTQ_FAIRQ_H_
39 #define _ALTQ_ALTQ_FAIRQ_H_
41 #include <altq/altq.h>
42 #include <altq/altq_classq.h>
43 #include <altq/altq_red.h>
44 #include <altq/altq_rio.h>
45 #include <altq/altq_rmclass.h>
47 #define FAIRQ_MAX_BUCKETS 2048 /* maximum number of sorting buckets */
48 #define FAIRQ_MAXPRI RM_MAXPRIO
49 #define FAIRQ_BITMAP_WIDTH (sizeof(fairq_bitmap_t)*8)
50 #define FAIRQ_BITMAP_MASK (FAIRQ_BITMAP_WIDTH - 1)
52 /* fairq class flags */
53 #define FARF_RED 0x0001 /* use RED */
54 #define FARF_ECN 0x0002 /* use RED/ECN */
55 #define FARF_RIO 0x0004 /* use RIO */
56 #define FARF_CLEARDSCP 0x0010 /* clear diffserv codepoint */
57 #define FARF_DEFAULTCLASS 0x1000 /* default class */
59 #define FARF_HAS_PACKETS 0x2000 /* might have queued packets */
61 #define FARF_USERFLAGS (FARF_RED|FARF_ECN|FARF_RIO|FARF_CLEARDSCP| \
64 /* special class handles */
65 #define FAIRQ_NULLCLASS_HANDLE 0
67 typedef u_int fairq_bitmap_t;
69 struct fairq_classstats {
70 uint32_t class_handle;
74 struct pktcntr xmit_cnt; /* transmitted packet counter */
75 struct pktcntr drop_cnt; /* dropped packet counter */
77 /* red and rio related info */
79 struct redstats red[3]; /* rio has 3 red stats */
84 typedef struct fairq_bucket {
85 struct fairq_bucket *next; /* circular list */
86 struct fairq_bucket *prev; /* circular list */
87 class_queue_t queue; /* the actual queue */
88 uint64_t bw_bytes; /* statistics used to calculate bw */
89 uint64_t bw_delta; /* statistics used to calculate bw */
95 uint32_t cl_handle; /* class handle */
96 u_int cl_nbuckets; /* (power of 2) */
97 u_int cl_nbucket_mask; /* bucket mask */
98 fairq_bucket_t *cl_buckets;
99 fairq_bucket_t *cl_head; /* head of circular bucket list */
100 fairq_bucket_t *cl_polled;
101 struct red *cl_red; /* RED state */
105 uint64_t cl_bw_bytes;
106 uint64_t cl_bw_delta;
107 uint64_t cl_last_time;
108 int cl_qtype; /* rollup */
110 int cl_pri; /* priority */
111 int cl_flags; /* class flags */
112 struct fairq_if *cl_pif; /* back pointer to pif */
113 struct altq_pktattr *cl_pktattr; /* saved header used by ECN */
115 /* round robin index */
118 struct pktcntr cl_xmitcnt; /* transmitted packet counter */
119 struct pktcntr cl_dropcnt; /* dropped packet counter */
123 * fairq interface state
126 struct fairq_if *pif_next; /* interface state list */
127 struct ifaltq *pif_ifq; /* backpointer to ifaltq */
128 u_int pif_bandwidth; /* link bandwidth in bps */
129 int pif_maxpri; /* max priority in use */
130 struct fairq_class *pif_poll_cache;/* cached poll */
131 struct fairq_class *pif_default; /* default class */
132 struct fairq_class *pif_classes[FAIRQ_MAXPRI]; /* classes */
137 #endif /* _ALTQ_ALTQ_FAIRQ_H_ */