1 | /* |
2 | * Copyright (c) 2011-2016 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_FQ_CODEL 7 /* Flow queues with CoDel */ |
46 | #define PKTSCHEDT_MAX 8 /* should be max sched type + 1 */ |
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 */ |
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 */ |
59 | |
60 | typedef struct _pktsched_pkt_ { |
61 | classq_pkt_type_t __ptype; |
62 | uint32_t __plen; |
63 | void *__pkt; |
64 | #define pktsched_ptype __ptype |
65 | #define pktsched_plen __plen |
66 | #define pktsched_pkt __pkt |
67 | } pktsched_pkt_t; |
68 | |
69 | #define _PKTSCHED_PKT_INIT(_p) do { \ |
70 | (_p)->pktsched_ptype = QP_INVALID; \ |
71 | (_p)->pktsched_plen = 0; \ |
72 | (_p)->pktsched_pkt = NULL; \ |
73 | } while (0) |
74 | |
75 | /* macro for timeout/untimeout */ |
76 | /* use old-style timeout/untimeout */ |
77 | /* dummy callout structure */ |
78 | struct callout { |
79 | void *c_arg; /* function argument */ |
80 | void (*c_func)(void *); /* function to call */ |
81 | }; |
82 | |
83 | #define CALLOUT_INIT(c) do { \ |
84 | (void) memset((c), 0, sizeof (*(c))); \ |
85 | } while (/*CONSTCOND*/ 0) |
86 | |
87 | #define CALLOUT_RESET(c, t, f, a) do { \ |
88 | (c)->c_arg = (a); \ |
89 | (c)->c_func = (f); \ |
90 | timeout((f), (a), (t)); \ |
91 | } while (/*CONSTCOND*/ 0) |
92 | |
93 | #define CALLOUT_STOP(c) untimeout((c)->c_func, (c)->c_arg) |
94 | #define CALLOUT_INITIALIZER { NULL, NULL } |
95 | |
96 | typedef void (timeout_t)(void *); |
97 | |
98 | /* |
99 | * Bitmap operations |
100 | */ |
101 | typedef u_int32_t pktsched_bitmap_t; |
102 | |
103 | static inline boolean_t |
104 | pktsched_bit_tst(u_int32_t ix, pktsched_bitmap_t *pData) |
105 | { |
106 | return (*pData & (1 << ix)); |
107 | } |
108 | |
109 | static inline void |
110 | pktsched_bit_set(u_int32_t ix, pktsched_bitmap_t *pData) |
111 | { |
112 | *pData |= (1 << ix); |
113 | } |
114 | |
115 | static inline void |
116 | pktsched_bit_clr(u_int32_t ix, pktsched_bitmap_t *pData) |
117 | { |
118 | *pData &= ~(1 << ix); |
119 | } |
120 | |
121 | static inline pktsched_bitmap_t |
122 | pktsched_ffs(pktsched_bitmap_t pData) |
123 | { |
124 | return (ffs(pData)); |
125 | } |
126 | |
127 | static inline pktsched_bitmap_t |
128 | pktsched_fls(pktsched_bitmap_t pData) |
129 | { |
130 | return ((sizeof (pktsched_bitmap_t) << 3) - clz(pData)); |
131 | } |
132 | |
133 | static inline pktsched_bitmap_t |
134 | __fls(pktsched_bitmap_t word) |
135 | { |
136 | VERIFY(word != 0); |
137 | return (pktsched_fls(word) - 1); |
138 | } |
139 | |
140 | /* |
141 | * We can use mach_absolute_time which returns a 64-bit value with |
142 | * granularity less than a microsecond even on the slowest processor. |
143 | */ |
144 | #define read_machclk() mach_absolute_time() |
145 | |
146 | /* |
147 | * machine dependent clock |
148 | * a 64bit high resolution time counter. |
149 | */ |
150 | extern u_int32_t machclk_freq; |
151 | extern u_int64_t machclk_per_sec; |
152 | extern u_int32_t pktsched_verbose; |
153 | |
154 | SYSCTL_DECL(_net_pktsched); |
155 | |
156 | struct if_ifclassq_stats; |
157 | |
158 | extern void pktsched_init(void); |
159 | extern int pktsched_setup(struct ifclassq *, u_int32_t, u_int32_t, |
160 | classq_pkt_type_t); |
161 | extern int pktsched_teardown(struct ifclassq *); |
162 | extern int pktsched_getqstats(struct ifclassq *, u_int32_t, |
163 | struct if_ifclassq_stats *); |
164 | extern u_int64_t pktsched_abs_to_nsecs(u_int64_t); |
165 | extern u_int64_t pktsched_nsecs_to_abstime(u_int64_t); |
166 | extern void pktsched_free_pkt(pktsched_pkt_t *); |
167 | extern uint32_t pktsched_get_pkt_len(pktsched_pkt_t *); |
168 | extern void pktsched_get_pkt_vars(pktsched_pkt_t *, uint32_t **, uint64_t **, |
169 | uint32_t *, uint8_t *, uint8_t *, uint32_t *); |
170 | extern uint32_t *pktsched_get_pkt_sfb_vars(pktsched_pkt_t *, uint32_t **); |
171 | extern void pktsched_pkt_encap(pktsched_pkt_t *, classq_pkt_type_t, void *); |
172 | extern mbuf_svc_class_t pktsched_get_pkt_svc(pktsched_pkt_t *); |
173 | extern struct flowadv_fcentry *pktsched_alloc_fcentry(pktsched_pkt_t *, |
174 | struct ifnet *, int); |
175 | #endif /* BSD_KERNEL_PRIVATE */ |
176 | |
177 | #ifdef __cplusplus |
178 | } |
179 | #endif |
180 | #endif /* PRIVATE */ |
181 | #endif /* _PKTSCHED_PKTSCHED_H_ */ |
182 | |