]>
Commit | Line | Data |
---|---|---|
316670eb | 1 | /* |
cb323159 | 2 | * Copyright (c) 2011-2018 Apple Inc. All rights reserved. |
316670eb A |
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 _PKTSCHED_PKTSCHED_H_ | |
0a7de745 | 30 | #define _PKTSCHED_PKTSCHED_H_ |
316670eb A |
31 | |
32 | #ifdef PRIVATE | |
33 | #ifdef __cplusplus | |
34 | extern "C" { | |
35 | #endif | |
36 | ||
37 | /* packet scheduler type */ | |
0a7de745 A |
38 | #define PKTSCHEDT_NONE 0 /* reserved */ |
39 | #define PKTSCHEDT_CBQ 1 /* cbq */ | |
40 | #define PKTSCHEDT_HFSC 2 /* hfsc */ | |
41 | #define PKTSCHEDT_PRIQ 3 /* priority queue */ | |
42 | #define PKTSCHEDT_FAIRQ 4 /* fairq */ | |
43 | #define PKTSCHEDT_TCQ 5 /* traffic class queue */ | |
44 | #define PKTSCHEDT_QFQ 6 /* quick fair queueing */ | |
45 | #define PKTSCHEDT_FQ_CODEL 7 /* Flow queues with CoDel */ | |
46 | #define PKTSCHEDT_MAX 8 /* should be max sched type + 1 */ | |
316670eb A |
47 | |
48 | #ifdef BSD_KERNEL_PRIVATE | |
49 | #include <mach/mach_time.h> | |
50 | #include <sys/sysctl.h> | |
51 | #include <libkern/libkern.h> | |
52 | ||
53 | /* flags for pktsched_setup */ | |
0a7de745 A |
54 | #define PKTSCHEDF_QALG_SFB 0x01 /* use SFB */ |
55 | #define PKTSCHEDF_QALG_ECN 0x02 /* enable ECN */ | |
56 | #define PKTSCHEDF_QALG_FLOWCTL 0x04 /* enable flow control advisories */ | |
57 | #define PKTSCHEDF_QALG_DELAYBASED 0x08 /* Delay based queueing */ | |
58 | #define PKTSCHEDF_QALG_DRIVER_MANAGED 0x10 /* driver managed */ | |
5ba3f43e A |
59 | |
60 | typedef struct _pktsched_pkt_ { | |
cb323159 | 61 | classq_pkt_t __pkt; |
f427ee49 | 62 | classq_pkt_t __tail; |
0a7de745 | 63 | uint32_t __plen; |
f427ee49 | 64 | uint32_t __pcnt; |
cb323159 | 65 | #define pktsched_ptype __pkt.cp_ptype |
0a7de745 | 66 | #define pktsched_plen __plen |
f427ee49 | 67 | #define pktsched_pcnt __pcnt |
0a7de745 | 68 | #define pktsched_pkt __pkt |
cb323159 A |
69 | #define pktsched_pkt_mbuf __pkt.cp_mbuf |
70 | #define pktsched_pkt_kpkt __pkt.cp_kpkt | |
f427ee49 A |
71 | #define pktsched_tail __tail |
72 | #define pktsched_tail_mbuf __tail.cp_mbuf | |
73 | #define pktsched_tail_kpkt __tail.cp_kpkt | |
5ba3f43e A |
74 | } pktsched_pkt_t; |
75 | ||
cb323159 A |
76 | #define _PKTSCHED_PKT_INIT(_p) do { \ |
77 | (_p)->pktsched_pkt = CLASSQ_PKT_INITIALIZER((_p)->pktsched_pkt);\ | |
f427ee49 | 78 | (_p)->pktsched_tail = CLASSQ_PKT_INITIALIZER((_p)->pktsched_tail);\ |
cb323159 | 79 | (_p)->pktsched_plen = 0; \ |
f427ee49 | 80 | (_p)->pktsched_pcnt = 0; \ |
5ba3f43e | 81 | } while (0) |
316670eb A |
82 | |
83 | /* macro for timeout/untimeout */ | |
84 | /* use old-style timeout/untimeout */ | |
85 | /* dummy callout structure */ | |
86 | struct callout { | |
0a7de745 A |
87 | void *c_arg; /* function argument */ |
88 | void (*c_func)(void *); /* function to call */ | |
316670eb A |
89 | }; |
90 | ||
0a7de745 A |
91 | #define CALLOUT_INIT(c) do { \ |
92 | (void) memset((c), 0, sizeof (*(c))); \ | |
93 | } while ( /*CONSTCOND*/ 0) | |
316670eb | 94 | |
0a7de745 A |
95 | #define CALLOUT_RESET(c, t, f, a) do { \ |
96 | (c)->c_arg = (a); \ | |
97 | (c)->c_func = (f); \ | |
98 | timeout((f), (a), (t)); \ | |
99 | } while ( /*CONSTCOND*/ 0) | |
316670eb | 100 | |
0a7de745 A |
101 | #define CALLOUT_STOP(c) untimeout((c)->c_func, (c)->c_arg) |
102 | #define CALLOUT_INITIALIZER { NULL, NULL } | |
316670eb A |
103 | |
104 | typedef void (timeout_t)(void *); | |
105 | ||
106 | /* | |
107 | * Bitmap operations | |
108 | */ | |
0a7de745 | 109 | typedef u_int32_t pktsched_bitmap_t; |
316670eb A |
110 | |
111 | static inline boolean_t | |
112 | pktsched_bit_tst(u_int32_t ix, pktsched_bitmap_t *pData) | |
113 | { | |
f427ee49 | 114 | return (boolean_t)(*pData & (1 << ix)); |
316670eb A |
115 | } |
116 | ||
117 | static inline void | |
118 | pktsched_bit_set(u_int32_t ix, pktsched_bitmap_t *pData) | |
119 | { | |
120 | *pData |= (1 << ix); | |
121 | } | |
122 | ||
123 | static inline void | |
124 | pktsched_bit_clr(u_int32_t ix, pktsched_bitmap_t *pData) | |
125 | { | |
126 | *pData &= ~(1 << ix); | |
127 | } | |
128 | ||
129 | static inline pktsched_bitmap_t | |
130 | pktsched_ffs(pktsched_bitmap_t pData) | |
131 | { | |
f427ee49 | 132 | return (pktsched_bitmap_t)ffs(pData); |
316670eb A |
133 | } |
134 | ||
135 | static inline pktsched_bitmap_t | |
136 | pktsched_fls(pktsched_bitmap_t pData) | |
137 | { | |
f427ee49 | 138 | return (pktsched_bitmap_t)((sizeof(pktsched_bitmap_t) << 3) - (unsigned long)clz(pData)); |
316670eb A |
139 | } |
140 | ||
141 | static inline pktsched_bitmap_t | |
142 | __fls(pktsched_bitmap_t word) | |
143 | { | |
144 | VERIFY(word != 0); | |
0a7de745 | 145 | return pktsched_fls(word) - 1; |
316670eb A |
146 | } |
147 | ||
cb323159 A |
148 | static inline uint32_t |
149 | pktsched_get_pkt_len(pktsched_pkt_t *pkt) | |
150 | { | |
151 | return pkt->pktsched_plen; | |
152 | } | |
153 | ||
316670eb A |
154 | /* |
155 | * We can use mach_absolute_time which returns a 64-bit value with | |
156 | * granularity less than a microsecond even on the slowest processor. | |
157 | */ | |
0a7de745 | 158 | #define read_machclk() mach_absolute_time() |
316670eb A |
159 | |
160 | /* | |
161 | * machine dependent clock | |
162 | * a 64bit high resolution time counter. | |
163 | */ | |
f427ee49 A |
164 | extern uint32_t machclk_freq; |
165 | extern uint64_t machclk_per_sec; | |
166 | extern uint32_t pktsched_verbose; | |
316670eb A |
167 | |
168 | SYSCTL_DECL(_net_pktsched); | |
169 | ||
170 | struct if_ifclassq_stats; | |
171 | ||
172 | extern void pktsched_init(void); | |
5ba3f43e A |
173 | extern int pktsched_setup(struct ifclassq *, u_int32_t, u_int32_t, |
174 | classq_pkt_type_t); | |
f427ee49 | 175 | extern void pktsched_teardown(struct ifclassq *); |
316670eb A |
176 | extern int pktsched_getqstats(struct ifclassq *, u_int32_t, |
177 | struct if_ifclassq_stats *); | |
178 | extern u_int64_t pktsched_abs_to_nsecs(u_int64_t); | |
179 | extern u_int64_t pktsched_nsecs_to_abstime(u_int64_t); | |
5ba3f43e | 180 | extern void pktsched_free_pkt(pktsched_pkt_t *); |
cb323159 A |
181 | extern int pktsched_clone_pkt(pktsched_pkt_t *, pktsched_pkt_t *); |
182 | extern void pktsched_corrupt_packet(pktsched_pkt_t *pkt); | |
183 | extern void pktsched_get_pkt_vars(pktsched_pkt_t *, volatile uint32_t **, | |
184 | uint64_t **, uint32_t *, uint8_t *, uint8_t *, uint32_t *); | |
5ba3f43e | 185 | extern uint32_t *pktsched_get_pkt_sfb_vars(pktsched_pkt_t *, uint32_t **); |
cb323159 | 186 | extern void pktsched_pkt_encap(pktsched_pkt_t *, classq_pkt_t *); |
f427ee49 A |
187 | extern void pktsched_pkt_encap_chain(pktsched_pkt_t *, classq_pkt_t *, |
188 | classq_pkt_t *, uint32_t, uint32_t); | |
5ba3f43e A |
189 | extern mbuf_svc_class_t pktsched_get_pkt_svc(pktsched_pkt_t *); |
190 | extern struct flowadv_fcentry *pktsched_alloc_fcentry(pktsched_pkt_t *, | |
191 | struct ifnet *, int); | |
316670eb A |
192 | #endif /* BSD_KERNEL_PRIVATE */ |
193 | ||
194 | #ifdef __cplusplus | |
195 | } | |
196 | #endif | |
197 | #endif /* PRIVATE */ | |
198 | #endif /* _PKTSCHED_PKTSCHED_H_ */ |