]> git.saurik.com Git - apple/xnu.git/blob - bsd/net/pktsched/pktsched_tcq.h
xnu-2050.7.9.tar.gz
[apple/xnu.git] / bsd / net / pktsched / pktsched_tcq.h
1 /*
2 * Copyright (c) 2011-2012 Apple Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28
29 #ifndef _NET_PKTSCHED_PKTSCHED_TCQ_H_
30 #define _NET_PKTSCHED_PKTSCHED_TCQ_H_
31
32 #ifdef PRIVATE
33 #include <net/pktsched/pktsched.h>
34 #include <net/classq/classq.h>
35 #include <net/classq/classq_red.h>
36 #include <net/classq/classq_rio.h>
37 #include <net/classq/classq_blue.h>
38 #include <net/classq/classq_sfb.h>
39
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
43
44 #define TCQ_MAXPRI 4 /* upper limit of the number of priorities */
45
46 /* tcq class flags */
47 #define TQCF_RED 0x0001 /* use RED */
48 #define TQCF_ECN 0x0002 /* use ECN with RED/BLUE/SFB */
49 #define TQCF_RIO 0x0004 /* use RIO */
50 #define TQCF_CLEARDSCP 0x0010 /* clear diffserv codepoint */
51 #define TQCF_BLUE 0x0100 /* use BLUE */
52 #define TQCF_SFB 0x0200 /* use SFB */
53 #define TQCF_FLOWCTL 0x0400 /* enable flow control advisories */
54 #define TQCF_DEFAULTCLASS 0x1000 /* default class */
55 #ifdef BSD_KERNEL_PRIVATE
56 #define TQCF_LAZY 0x10000000 /* on-demand resource allocation */
57 #endif /* BSD_KERNEL_PRIVATE */
58
59 #define TQCF_USERFLAGS \
60 (TQCF_RED | TQCF_ECN | TQCF_RIO | TQCF_CLEARDSCP | TQCF_BLUE | \
61 TQCF_SFB | TQCF_FLOWCTL | TQCF_DEFAULTCLASS)
62
63 #ifdef BSD_KERNEL_PRIVATE
64 #define TQCF_BITS \
65 "\020\1RED\2ECN\3RIO\5CLEARDSCP\11BLUE\12SFB\13FLOWCTL\15DEFAULT" \
66 "\35LAZY"
67 #else
68 #define TQCF_BITS \
69 "\020\1RED\2ECN\3RIO\5CLEARDSCP\11BLUE\12SFB\13FLOWCTL"
70 #endif /* !BSD_KERNEL_PRIVATE */
71
72 struct tcq_classstats {
73 u_int32_t class_handle;
74 u_int32_t priority;
75
76 u_int32_t qlength;
77 u_int32_t qlimit;
78 u_int32_t period;
79 struct pktcntr xmitcnt; /* transmitted packet counter */
80 struct pktcntr dropcnt; /* dropped packet counter */
81
82 /* RED, RIO, BLUE, SFB related info */
83 classq_type_t qtype;
84 union {
85 /* RIO has 3 red stats */
86 struct red_stats red[RIO_NDROPPREC];
87 struct blue_stats blue;
88 struct sfb_stats sfb;
89 };
90 classq_state_t qstate;
91 };
92
93 #ifdef BSD_KERNEL_PRIVATE
94 struct tcq_class {
95 u_int32_t cl_handle; /* class handle */
96 class_queue_t cl_q; /* class queue structure */
97 u_int32_t cl_qflags; /* class queue flags */
98 union {
99 void *ptr;
100 struct red *red; /* RED state */
101 struct rio *rio; /* RIO state */
102 struct blue *blue; /* BLUE state */
103 struct sfb *sfb; /* SFB state */
104 } cl_qalg;
105 int32_t cl_pri; /* priority */
106 u_int32_t cl_flags; /* class flags */
107 struct tcq_if *cl_tif; /* back pointer to tif */
108
109 /* statistics */
110 u_int32_t cl_period; /* backlog period */
111 struct pktcntr cl_xmitcnt; /* transmitted packet counter */
112 struct pktcntr cl_dropcnt; /* dropped packet counter */
113 };
114
115 #define cl_red cl_qalg.red
116 #define cl_rio cl_qalg.rio
117 #define cl_blue cl_qalg.blue
118 #define cl_sfb cl_qalg.sfb
119
120 /* tcq_if flags */
121 #define TCQIFF_ALTQ 0x1 /* configured via PF/ALTQ */
122
123 /*
124 * tcq interface state
125 */
126 struct tcq_if {
127 struct ifclassq *tif_ifq; /* backpointer to ifclassq */
128 int tif_maxpri; /* max priority in use */
129 u_int32_t tif_flags; /* flags */
130 u_int32_t tif_throttle; /* throttling level */
131 struct tcq_class *tif_default; /* default class */
132 struct tcq_class *tif_classes[TCQ_MAXPRI]; /* classes */
133 };
134
135 #define TCQIF_IFP(_tif) ((_tif)->tif_ifq->ifcq_ifp)
136
137 struct if_ifclassq_stats;
138
139 extern void tcq_init(void);
140 extern struct tcq_if *tcq_alloc(struct ifnet *, int, boolean_t);
141 extern int tcq_destroy(struct tcq_if *);
142 extern void tcq_purge(struct tcq_if *);
143 extern void tcq_event(struct tcq_if *, cqev_t);
144 extern int tcq_add_queue(struct tcq_if *, int, u_int32_t, int, u_int32_t,
145 struct tcq_class **);
146 extern int tcq_remove_queue(struct tcq_if *, u_int32_t);
147 extern int tcq_get_class_stats(struct tcq_if *, u_int32_t,
148 struct tcq_classstats *);
149 extern int tcq_enqueue(struct tcq_if *, struct tcq_class *, struct mbuf *,
150 struct pf_mtag *);
151 extern struct mbuf *tcq_dequeue_tc(struct tcq_if *, mbuf_svc_class_t,
152 cqdq_op_t);
153 extern int tcq_setup_ifclassq(struct ifclassq *, u_int32_t);
154 extern int tcq_teardown_ifclassq(struct ifclassq *ifq);
155 extern int tcq_getqstats_ifclassq(struct ifclassq *, u_int32_t qid,
156 struct if_ifclassq_stats *);
157 #endif /* BSD_KERNEL_PRIVATE */
158 #ifdef __cplusplus
159 }
160 #endif
161 #endif /* PRIVATE */
162 #endif /* _NET_PKTSCHED_PKTSCHED_TCQ_H_ */