]>
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 _PKTSCHED_PKTSCHED_H_ | |
30 | #define _PKTSCHED_PKTSCHED_H_ | |
31 | ||
32 | #ifdef PRIVATE | |
33 | #ifdef __cplusplus | |
34 | extern "C" { | |
35 | #endif | |
36 | ||
37 | /* packet scheduler type */ | |
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_MAX 7 /* should be max sched type + 1 */ | |
46 | ||
47 | #ifdef BSD_KERNEL_PRIVATE | |
48 | #include <mach/mach_time.h> | |
49 | #include <sys/sysctl.h> | |
50 | #include <libkern/libkern.h> | |
51 | ||
52 | /* flags for pktsched_setup */ | |
53 | #define PKTSCHEDF_QALG_RED 0x1 /* use RED */ | |
54 | #define PKTSCHEDF_QALG_RIO 0x2 /* use RIO */ | |
55 | #define PKTSCHEDF_QALG_BLUE 0x4 /* use BLUE */ | |
56 | #define PKTSCHEDF_QALG_SFB 0x8 /* use SFB */ | |
57 | #define PKTSCHEDF_QALG_ECN 0x10 /* enable ECN */ | |
58 | #define PKTSCHEDF_QALG_FLOWCTL 0x20 /* enable flow control advisories */ | |
fe8ab488 | 59 | #define PKTSCHEDF_QALG_DELAYBASED 0x40 /* Delay based queueing */ |
316670eb A |
60 | |
61 | /* macro for timeout/untimeout */ | |
62 | /* use old-style timeout/untimeout */ | |
63 | /* dummy callout structure */ | |
64 | struct callout { | |
65 | void *c_arg; /* function argument */ | |
66 | void (*c_func)(void *); /* function to call */ | |
67 | }; | |
68 | ||
69 | #define CALLOUT_INIT(c) do { \ | |
70 | (void) memset((c), 0, sizeof (*(c))); \ | |
71 | } while (/*CONSTCOND*/ 0) | |
72 | ||
73 | #define CALLOUT_RESET(c, t, f, a) do { \ | |
74 | (c)->c_arg = (a); \ | |
75 | (c)->c_func = (f); \ | |
76 | timeout((f), (a), (t)); \ | |
77 | } while (/*CONSTCOND*/ 0) | |
78 | ||
79 | #define CALLOUT_STOP(c) untimeout((c)->c_func, (c)->c_arg) | |
80 | #define CALLOUT_INITIALIZER { NULL, NULL } | |
81 | ||
82 | typedef void (timeout_t)(void *); | |
83 | ||
84 | /* | |
85 | * Bitmap operations | |
86 | */ | |
87 | typedef u_int32_t pktsched_bitmap_t; | |
88 | ||
89 | static inline boolean_t | |
90 | pktsched_bit_tst(u_int32_t ix, pktsched_bitmap_t *pData) | |
91 | { | |
92 | return (*pData & (1 << ix)); | |
93 | } | |
94 | ||
95 | static inline void | |
96 | pktsched_bit_set(u_int32_t ix, pktsched_bitmap_t *pData) | |
97 | { | |
98 | *pData |= (1 << ix); | |
99 | } | |
100 | ||
101 | static inline void | |
102 | pktsched_bit_clr(u_int32_t ix, pktsched_bitmap_t *pData) | |
103 | { | |
104 | *pData &= ~(1 << ix); | |
105 | } | |
106 | ||
107 | static inline pktsched_bitmap_t | |
108 | pktsched_ffs(pktsched_bitmap_t pData) | |
109 | { | |
110 | return (ffs(pData)); | |
111 | } | |
112 | ||
113 | static inline pktsched_bitmap_t | |
114 | pktsched_fls(pktsched_bitmap_t pData) | |
115 | { | |
116 | return ((sizeof (pktsched_bitmap_t) << 3) - clz(pData)); | |
117 | } | |
118 | ||
119 | static inline pktsched_bitmap_t | |
120 | __fls(pktsched_bitmap_t word) | |
121 | { | |
122 | VERIFY(word != 0); | |
123 | return (pktsched_fls(word) - 1); | |
124 | } | |
125 | ||
126 | /* | |
127 | * We can use mach_absolute_time which returns a 64-bit value with | |
128 | * granularity less than a microsecond even on the slowest processor. | |
129 | */ | |
130 | #define read_machclk() mach_absolute_time() | |
131 | ||
132 | /* | |
133 | * machine dependent clock | |
134 | * a 64bit high resolution time counter. | |
135 | */ | |
136 | extern u_int32_t machclk_freq; | |
137 | extern u_int64_t machclk_per_sec; | |
138 | extern u_int32_t pktsched_verbose; | |
139 | ||
140 | SYSCTL_DECL(_net_pktsched); | |
141 | ||
142 | struct if_ifclassq_stats; | |
143 | ||
144 | extern void pktsched_init(void); | |
145 | extern int pktsched_setup(struct ifclassq *, u_int32_t, u_int32_t); | |
146 | extern int pktsched_teardown(struct ifclassq *); | |
147 | extern int pktsched_getqstats(struct ifclassq *, u_int32_t, | |
148 | struct if_ifclassq_stats *); | |
149 | extern u_int64_t pktsched_abs_to_nsecs(u_int64_t); | |
150 | extern u_int64_t pktsched_nsecs_to_abstime(u_int64_t); | |
151 | #endif /* BSD_KERNEL_PRIVATE */ | |
152 | ||
153 | #ifdef __cplusplus | |
154 | } | |
155 | #endif | |
156 | #endif /* PRIVATE */ | |
157 | #endif /* _PKTSCHED_PKTSCHED_H_ */ |