]>
Commit | Line | Data |
---|---|---|
316670eb A |
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_CLASSQ_CLASSQ_SFB_H_ | |
30 | #define _NET_CLASSQ_CLASSQ_SFB_H_ | |
31 | ||
32 | #ifdef PRIVATE | |
33 | #ifdef BSD_KERNEL_PRIVATE | |
316670eb A |
34 | #include <stdbool.h> |
35 | #include <sys/time.h> | |
39236c6e A |
36 | #include <net/flowadv.h> |
37 | #include <net/classq/if_classq.h> | |
316670eb A |
38 | #endif /* BSD_KERNEL_PRIVATE */ |
39 | ||
40 | #ifdef __cplusplus | |
41 | extern "C" { | |
42 | #endif | |
43 | ||
44 | #define SFB_FP_SHIFT 14 /* fixed-point shift (Q14) */ | |
45 | #define SFB_LEVELS 2 /* L */ | |
46 | #define SFB_BINS_SHIFT 5 | |
47 | #define SFB_BINS (1 << SFB_BINS_SHIFT) /* N */ | |
48 | ||
49 | struct sfbstats { | |
50 | u_int64_t drop_early; | |
51 | u_int64_t drop_pbox; | |
52 | u_int64_t drop_queue; | |
53 | u_int64_t marked_packets; | |
54 | u_int64_t pbox_packets; | |
55 | u_int64_t pbox_time; | |
56 | u_int64_t hold_time; | |
57 | u_int64_t dequeue_avg; | |
58 | u_int64_t rehash_intval; | |
59 | u_int64_t num_rehash; | |
39236c6e | 60 | u_int64_t null_flowid; |
316670eb A |
61 | u_int64_t flow_controlled; |
62 | u_int64_t flow_feedback; | |
fe8ab488 | 63 | u_int64_t dequeue_stall; |
316670eb A |
64 | }; |
65 | ||
66 | struct sfbbinstats { | |
67 | int16_t pmark; /* marking probability in Q format */ | |
68 | u_int16_t pkts; /* number of packets */ | |
fe8ab488 | 69 | u_int32_t bytes; /* number of bytes */ |
316670eb A |
70 | }; |
71 | ||
72 | struct sfb_stats { | |
73 | u_int32_t allocation; | |
74 | u_int32_t dropthresh; | |
75 | u_int32_t clearpkts; | |
76 | u_int32_t current; | |
fe8ab488 A |
77 | u_int64_t target_qdelay; |
78 | u_int64_t update_interval; | |
79 | u_int64_t min_estdelay; | |
80 | u_int32_t delay_fcthreshold; | |
81 | u_int32_t flags; | |
316670eb A |
82 | struct sfbstats sfbstats; |
83 | struct sfbbins { | |
84 | struct sfbbinstats stats[SFB_LEVELS][SFB_BINS]; | |
85 | } binstats[2] __attribute__((aligned(8))); | |
86 | }; | |
87 | ||
88 | #ifdef BSD_KERNEL_PRIVATE | |
316670eb A |
89 | struct sfb_bins { |
90 | u_int32_t fudge; | |
91 | struct sfbbinstats stats[SFB_LEVELS][SFB_BINS]; | |
92 | struct timespec freezetime[SFB_LEVELS][SFB_BINS]; | |
93 | }; | |
94 | ||
39236c6e A |
95 | struct sfb_fcl { |
96 | u_int32_t cnt; | |
97 | struct flowadv_fclist fclist; | |
98 | }; | |
99 | ||
316670eb A |
100 | /* SFB flags */ |
101 | #define SFBF_ECN4 0x01 /* use packet marking for IPv4 packets */ | |
102 | #define SFBF_ECN6 0x02 /* use packet marking for IPv6 packets */ | |
103 | #define SFBF_ECN (SFBF_ECN4 | SFBF_ECN6) | |
104 | #define SFBF_FLOWCTL 0x04 /* enable flow control advisories */ | |
fe8ab488 A |
105 | #define SFBF_DELAYBASED 0x08 /* queueing is delay based */ |
106 | #define SFBF_DELAYHIGH 0x10 /* Estimated delay is greater than target */ | |
316670eb A |
107 | #define SFBF_SUSPENDED 0x1000 /* queue is suspended */ |
108 | ||
109 | #define SFBF_USERFLAGS \ | |
fe8ab488 | 110 | (SFBF_ECN4 | SFBF_ECN6 | SFBF_FLOWCTL | SFBF_DELAYBASED) |
316670eb A |
111 | |
112 | typedef struct sfb { | |
113 | /* variables for internal use */ | |
114 | u_int32_t sfb_flags; /* SFB flags */ | |
115 | u_int32_t sfb_qlim; | |
116 | u_int32_t sfb_qid; | |
117 | u_int16_t sfb_allocation; | |
118 | u_int16_t sfb_drop_thresh; | |
119 | u_int32_t sfb_clearpkts; | |
120 | u_int64_t sfb_eff_rate; /* last known effective rate */ | |
fe8ab488 | 121 | struct timespec sfb_getqtime; /* last dequeue timestamp */ |
316670eb A |
122 | struct timespec sfb_holdtime; /* random holdtime in nsec */ |
123 | struct ifnet *sfb_ifp; /* back pointer to ifnet */ | |
124 | ||
fe8ab488 A |
125 | /* target queue delay and interval for queue sizing */ |
126 | u_int64_t sfb_target_qdelay; | |
127 | struct timespec sfb_update_interval; | |
128 | u_int64_t sfb_fc_threshold; /* for flow control feedback */ | |
129 | ||
130 | /* variables for computing estimated delay of the queue */ | |
131 | u_int64_t sfb_min_qdelay; | |
132 | struct timespec sfb_update_time; | |
133 | ||
316670eb A |
134 | /* moving hash function */ |
135 | struct timespec sfb_hinterval; /* random reset interval in sec */ | |
136 | struct timespec sfb_nextreset; /* reset deadline */ | |
137 | ||
138 | /* penalty box */ | |
139 | struct timespec sfb_pboxtime; /* random pboxtime in nsec */ | |
140 | struct timespec sfb_pboxfreeze; | |
141 | ||
142 | /* B[L][N] bins (2 sets: current and warm-up) */ | |
143 | u_int32_t sfb_current; /* current set (0 or 1) */ | |
144 | struct sfb_bins (*sfb_bins)[2]; | |
145 | ||
146 | /* Flow control lists for current set */ | |
39236c6e | 147 | struct sfb_fcl (*sfb_fc_lists)[SFB_BINS]; |
316670eb A |
148 | |
149 | /* statistics */ | |
150 | struct sfbstats sfb_stats __attribute__((aligned(8))); | |
151 | } sfb_t; | |
152 | ||
153 | extern void sfb_init(void); | |
154 | extern struct sfb *sfb_alloc(struct ifnet *, u_int32_t, u_int32_t, u_int32_t); | |
155 | extern void sfb_destroy(struct sfb *); | |
156 | extern int sfb_addq(struct sfb *, class_queue_t *, struct mbuf *, | |
157 | struct pf_mtag *); | |
158 | extern struct mbuf *sfb_getq(struct sfb *, class_queue_t *); | |
159 | extern void sfb_purgeq(struct sfb *, class_queue_t *, u_int32_t, | |
160 | u_int32_t *, u_int32_t *); | |
161 | extern void sfb_getstats(struct sfb *, struct sfb_stats *); | |
162 | extern void sfb_updateq(struct sfb *, cqev_t); | |
163 | extern int sfb_suspendq(struct sfb *, class_queue_t *, boolean_t); | |
164 | #endif /* BSD_KERNEL_PRIVATE */ | |
165 | ||
166 | #ifdef __cplusplus | |
167 | } | |
168 | #endif | |
169 | #endif /* PRIVATE */ | |
170 | #endif /* _NET_CLASSQ_CLASSQ_SFB_H_ */ |