Commit | Line | Data |
---|---|---|
4d723e5a JS |
1 | /*- |
2 | * Copyright (c) 2005 The DragonFly Project. All rights reserved. | |
3 | * | |
4 | * Redistribution and use in source and binary forms, with or without | |
5 | * modification, are permitted provided that the following conditions | |
6 | * are met: | |
7 | * | |
8 | * 1. Redistributions of source code must retain the above copyright | |
9 | * notice, this list of conditions and the following disclaimer. | |
10 | * 2. Redistributions in binary form must reproduce the above copyright | |
11 | * notice, this list of conditions and the following disclaimer in | |
12 | * the documentation and/or other materials provided with the | |
13 | * distribution. | |
14 | * 3. Neither the name of The DragonFly Project nor the names of its | |
15 | * contributors may be used to endorse or promote products derived | |
16 | * from this software without specific, prior written permission. | |
17 | * | |
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
19 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | |
21 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | |
22 | * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | |
23 | * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, | |
24 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |
25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED | |
26 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |
27 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |
28 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
29 | * SUCH DAMAGE. | |
4d723e5a | 30 | */ |
78195a76 | 31 | |
1bd40720 MD |
32 | #ifndef _NET_IFQ_VAR_H_ |
33 | #define _NET_IFQ_VAR_H_ | |
4d723e5a | 34 | |
03d6a592 | 35 | #ifndef _KERNEL |
03d6a592 | 36 | #error "This file should not be included by userland programs." |
74f8b40c | 37 | #endif |
03d6a592 MD |
38 | |
39 | #ifndef _SYS_SYSTM_H_ | |
1bd40720 MD |
40 | #include <sys/systm.h> |
41 | #endif | |
1bd40720 MD |
42 | #ifndef _SYS_SERIALIZE_H_ |
43 | #include <sys/serialize.h> | |
44 | #endif | |
45 | #ifndef _SYS_MBUF_H_ | |
46 | #include <sys/mbuf.h> | |
47 | #endif | |
48 | #ifndef _NET_IF_VAR_H_ | |
49 | #include <net/if_var.h> | |
50 | #endif | |
51 | #ifndef _NET_ALTQ_IF_ALTQ_H_ | |
52 | #include <net/altq/if_altq.h> | |
53 | #endif | |
54 | ||
f0a26983 SZ |
55 | #define ASSERT_ALTQ_SQ_DEFAULT(ifp, ifsq) \ |
56 | KASSERT(ifsq_get_ifp((ifsq)) == (ifp) && \ | |
57 | ifsq_get_index((ifsq)) == ALTQ_SUBQ_INDEX_DEFAULT, \ | |
58 | ("not ifp's default subqueue")); | |
59 | ||
1bd40720 | 60 | struct ifaltq; |
8a248085 SZ |
61 | struct ifaltq_subque; |
62 | ||
74f8b40c SZ |
63 | /* |
64 | * Subqueue watchdog | |
65 | */ | |
8a248085 SZ |
66 | typedef void (*ifsq_watchdog_t)(struct ifaltq_subque *); |
67 | ||
68 | struct ifsubq_watchdog { | |
69 | struct callout wd_callout; | |
70 | int wd_timer; | |
e2292763 | 71 | int wd_flags; |
8a248085 SZ |
72 | struct ifaltq_subque *wd_subq; |
73 | ifsq_watchdog_t wd_watchdog; | |
74 | }; | |
4986965b | 75 | |
e2292763 MD |
76 | #define IF_WDOG_ALLTICKS 0x00000001 |
77 | #define IF_WDOG_LASTTICK 0x00000002 | |
78 | ||
9db4b353 | 79 | /* |
058d1cd0 | 80 | * Support for "classic" ALTQ interfaces. |
9db4b353 | 81 | */ |
f0a26983 | 82 | int ifsq_classic_enqueue(struct ifaltq_subque *, struct mbuf *, |
058d1cd0 | 83 | struct altq_pktattr *); |
6dadc833 | 84 | struct mbuf *ifsq_classic_dequeue(struct ifaltq_subque *, int); |
f0a26983 | 85 | int ifsq_classic_request(struct ifaltq_subque *, int, void *); |
9db4b353 SZ |
86 | void ifq_set_classic(struct ifaltq *); |
87 | ||
0faec0d1 | 88 | void ifq_set_maxlen(struct ifaltq *, int); |
2cc2f639 SZ |
89 | void ifq_set_methods(struct ifaltq *, altq_mapsubq_t, |
90 | ifsq_enqueue_t, ifsq_dequeue_t, ifsq_request_t); | |
91 | int ifq_mapsubq_default(struct ifaltq *, int); | |
68732d8f | 92 | int ifq_mapsubq_modulo(struct ifaltq *, int); |
f0a26983 SZ |
93 | |
94 | void ifsq_devstart(struct ifaltq_subque *ifsq); | |
95 | void ifsq_devstart_sched(struct ifaltq_subque *ifsq); | |
058d1cd0 | 96 | |
8a248085 | 97 | void ifsq_watchdog_init(struct ifsubq_watchdog *, |
e2292763 | 98 | struct ifaltq_subque *, ifsq_watchdog_t, int); |
8a248085 SZ |
99 | void ifsq_watchdog_start(struct ifsubq_watchdog *); |
100 | void ifsq_watchdog_stop(struct ifsubq_watchdog *); | |
e2292763 | 101 | void ifsq_watchdog_set_count(struct ifsubq_watchdog *, int); |
8a248085 | 102 | |
058d1cd0 SZ |
103 | /* |
104 | * Dispatch a packet to an interface. | |
105 | */ | |
9db4b353 | 106 | int ifq_dispatch(struct ifnet *, struct mbuf *, |
058d1cd0 | 107 | struct altq_pktattr *); |
9db4b353 | 108 | |
4d723e5a | 109 | #ifdef ALTQ |
058d1cd0 | 110 | |
4d723e5a JS |
111 | static __inline int |
112 | ifq_is_enabled(struct ifaltq *_ifq) | |
113 | { | |
114 | return(_ifq->altq_flags & ALTQF_ENABLED); | |
115 | } | |
116 | ||
117 | static __inline int | |
118 | ifq_is_attached(struct ifaltq *_ifq) | |
119 | { | |
120 | return(_ifq->altq_disc != NULL); | |
121 | } | |
058d1cd0 SZ |
122 | |
123 | #else /* !ALTQ */ | |
124 | ||
4d723e5a JS |
125 | static __inline int |
126 | ifq_is_enabled(struct ifaltq *_ifq) | |
127 | { | |
128 | return(0); | |
129 | } | |
130 | ||
131 | static __inline int | |
132 | ifq_is_attached(struct ifaltq *_ifq) | |
133 | { | |
134 | return(0); | |
135 | } | |
4d723e5a | 136 | |
058d1cd0 SZ |
137 | #endif /* ALTQ */ |
138 | ||
4d723e5a JS |
139 | static __inline int |
140 | ifq_is_ready(struct ifaltq *_ifq) | |
141 | { | |
142 | return(_ifq->altq_flags & ALTQF_READY); | |
143 | } | |
144 | ||
145 | static __inline void | |
146 | ifq_set_ready(struct ifaltq *_ifq) | |
147 | { | |
148 | _ifq->altq_flags |= ALTQF_READY; | |
149 | } | |
150 | ||
78195a76 | 151 | /* |
74f8b40c | 152 | * Subqueue lock must be held |
78195a76 | 153 | */ |
9db4b353 | 154 | static __inline int |
f0a26983 SZ |
155 | ifsq_enqueue_locked(struct ifaltq_subque *_ifsq, struct mbuf *_m, |
156 | struct altq_pktattr *_pa) | |
9db4b353 SZ |
157 | { |
158 | #ifdef ALTQ | |
f0a26983 SZ |
159 | if (!ifq_is_enabled(_ifsq->ifsq_altq)) |
160 | return ifsq_classic_enqueue(_ifsq, _m, _pa); | |
9db4b353 SZ |
161 | else |
162 | #endif | |
f0a26983 | 163 | return _ifsq->ifsq_enqueue(_ifsq, _m, _pa); |
9db4b353 SZ |
164 | } |
165 | ||
4d723e5a | 166 | static __inline int |
f0a26983 SZ |
167 | ifsq_enqueue(struct ifaltq_subque *_ifsq, struct mbuf *_m, |
168 | struct altq_pktattr *_pa) | |
4d723e5a | 169 | { |
9db4b353 SZ |
170 | int _error; |
171 | ||
f0a26983 SZ |
172 | ALTQ_SQ_LOCK(_ifsq); |
173 | _error = ifsq_enqueue_locked(_ifsq, _m, _pa); | |
174 | ALTQ_SQ_UNLOCK(_ifsq); | |
9db4b353 | 175 | return _error; |
4d723e5a JS |
176 | } |
177 | ||
178 | static __inline struct mbuf * | |
ac9843a1 | 179 | ifsq_dequeue(struct ifaltq_subque *_ifsq) |
4d723e5a | 180 | { |
9db4b353 SZ |
181 | struct mbuf *_m; |
182 | ||
f0a26983 SZ |
183 | ALTQ_SQ_LOCK(_ifsq); |
184 | if (_ifsq->ifsq_prepended != NULL) { | |
185 | _m = _ifsq->ifsq_prepended; | |
186 | _ifsq->ifsq_prepended = NULL; | |
68dc1916 | 187 | ALTQ_SQ_CNTR_DEC(_ifsq, _m->m_pkthdr.len); |
f0a26983 | 188 | ALTQ_SQ_UNLOCK(_ifsq); |
9db4b353 SZ |
189 | return _m; |
190 | } | |
191 | ||
4d723e5a | 192 | #ifdef ALTQ |
f0a26983 | 193 | if (_ifsq->ifsq_altq->altq_tbr != NULL) |
ac9843a1 | 194 | _m = tbr_dequeue(_ifsq, ALTDQ_REMOVE); |
f0a26983 | 195 | else if (!ifq_is_enabled(_ifsq->ifsq_altq)) |
6dadc833 | 196 | _m = ifsq_classic_dequeue(_ifsq, ALTDQ_REMOVE); |
9db4b353 | 197 | else |
4d723e5a | 198 | #endif |
6dadc833 | 199 | _m = _ifsq->ifsq_dequeue(_ifsq, ALTDQ_REMOVE); |
f0a26983 | 200 | ALTQ_SQ_UNLOCK(_ifsq); |
9db4b353 | 201 | return _m; |
4d723e5a JS |
202 | } |
203 | ||
78195a76 | 204 | /* |
74f8b40c | 205 | * Subqueue lock must be held |
78195a76 | 206 | */ |
4d723e5a | 207 | static __inline struct mbuf * |
f0a26983 | 208 | ifsq_poll_locked(struct ifaltq_subque *_ifsq) |
4d723e5a | 209 | { |
f0a26983 SZ |
210 | if (_ifsq->ifsq_prepended != NULL) |
211 | return _ifsq->ifsq_prepended; | |
9db4b353 | 212 | |
4d723e5a | 213 | #ifdef ALTQ |
f0a26983 | 214 | if (_ifsq->ifsq_altq->altq_tbr != NULL) |
ac9843a1 | 215 | return tbr_dequeue(_ifsq, ALTDQ_POLL); |
f0a26983 | 216 | else if (!ifq_is_enabled(_ifsq->ifsq_altq)) |
6dadc833 | 217 | return ifsq_classic_dequeue(_ifsq, ALTDQ_POLL); |
9db4b353 | 218 | else |
4d723e5a | 219 | #endif |
6dadc833 | 220 | return _ifsq->ifsq_dequeue(_ifsq, ALTDQ_POLL); |
9db4b353 SZ |
221 | } |
222 | ||
223 | static __inline struct mbuf * | |
f0a26983 | 224 | ifsq_poll(struct ifaltq_subque *_ifsq) |
9db4b353 SZ |
225 | { |
226 | struct mbuf *_m; | |
227 | ||
f0a26983 SZ |
228 | ALTQ_SQ_LOCK(_ifsq); |
229 | _m = ifsq_poll_locked(_ifsq); | |
230 | ALTQ_SQ_UNLOCK(_ifsq); | |
9db4b353 | 231 | return _m; |
4d723e5a JS |
232 | } |
233 | ||
13f46fca SZ |
234 | static __inline int |
235 | ifsq_poll_pktlen(struct ifaltq_subque *_ifsq) | |
236 | { | |
237 | struct mbuf *_m; | |
238 | int _len = 0; | |
239 | ||
240 | ALTQ_SQ_LOCK(_ifsq); | |
241 | ||
242 | _m = ifsq_poll_locked(_ifsq); | |
243 | if (_m != NULL) { | |
244 | M_ASSERTPKTHDR(_m); | |
245 | _len = _m->m_pkthdr.len; | |
246 | } | |
247 | ||
248 | ALTQ_SQ_UNLOCK(_ifsq); | |
249 | ||
250 | return _len; | |
251 | } | |
252 | ||
78195a76 | 253 | /* |
74f8b40c | 254 | * Subqueue lock must be held |
78195a76 | 255 | */ |
4d723e5a | 256 | static __inline void |
f0a26983 | 257 | ifsq_purge_locked(struct ifaltq_subque *_ifsq) |
4d723e5a | 258 | { |
f0a26983 | 259 | if (_ifsq->ifsq_prepended != NULL) { |
68dc1916 | 260 | ALTQ_SQ_CNTR_DEC(_ifsq, _ifsq->ifsq_prepended->m_pkthdr.len); |
f0a26983 SZ |
261 | m_freem(_ifsq->ifsq_prepended); |
262 | _ifsq->ifsq_prepended = NULL; | |
9db4b353 SZ |
263 | } |
264 | ||
265 | #ifdef ALTQ | |
f0a26983 SZ |
266 | if (!ifq_is_enabled(_ifsq->ifsq_altq)) |
267 | ifsq_classic_request(_ifsq, ALTRQ_PURGE, NULL); | |
91148f10 | 268 | else |
9db4b353 | 269 | #endif |
f0a26983 | 270 | _ifsq->ifsq_request(_ifsq, ALTRQ_PURGE, NULL); |
9db4b353 SZ |
271 | } |
272 | ||
273 | static __inline void | |
f0a26983 SZ |
274 | ifsq_purge(struct ifaltq_subque *_ifsq) |
275 | { | |
276 | ALTQ_SQ_LOCK(_ifsq); | |
277 | ifsq_purge_locked(_ifsq); | |
278 | ALTQ_SQ_UNLOCK(_ifsq); | |
279 | } | |
280 | ||
281 | static __inline void | |
282 | ifq_lock_all(struct ifaltq *_ifq) | |
283 | { | |
284 | int _q; | |
285 | ||
286 | for (_q = 0; _q < _ifq->altq_subq_cnt; ++_q) | |
287 | ALTQ_SQ_LOCK(&_ifq->altq_subq[_q]); | |
288 | } | |
289 | ||
290 | static __inline void | |
291 | ifq_unlock_all(struct ifaltq *_ifq) | |
9db4b353 | 292 | { |
f0a26983 SZ |
293 | int _q; |
294 | ||
295 | for (_q = _ifq->altq_subq_cnt - 1; _q >= 0; --_q) | |
296 | ALTQ_SQ_UNLOCK(&_ifq->altq_subq[_q]); | |
4d723e5a JS |
297 | } |
298 | ||
9275f515 | 299 | /* |
74f8b40c | 300 | * All of the subqueue locks must be held |
9275f515 SZ |
301 | */ |
302 | static __inline void | |
303 | ifq_purge_all_locked(struct ifaltq *_ifq) | |
304 | { | |
f0a26983 SZ |
305 | int _q; |
306 | ||
307 | for (_q = 0; _q < _ifq->altq_subq_cnt; ++_q) | |
308 | ifsq_purge_locked(&_ifq->altq_subq[_q]); | |
9275f515 SZ |
309 | } |
310 | ||
311 | static __inline void | |
312 | ifq_purge_all(struct ifaltq *_ifq) | |
313 | { | |
f0a26983 | 314 | ifq_lock_all(_ifq); |
9275f515 | 315 | ifq_purge_all_locked(_ifq); |
f0a26983 | 316 | ifq_unlock_all(_ifq); |
9275f515 SZ |
317 | } |
318 | ||
4d723e5a JS |
319 | static __inline void |
320 | ifq_classify(struct ifaltq *_ifq, struct mbuf *_m, uint8_t _af, | |
f0a26983 | 321 | struct altq_pktattr *_pa) |
4d723e5a | 322 | { |
9db4b353 | 323 | #ifdef ALTQ |
9db4b353 SZ |
324 | if (ifq_is_enabled(_ifq)) { |
325 | _pa->pattr_af = _af; | |
326 | _pa->pattr_hdr = mtod(_m, caddr_t); | |
f0a26983 SZ |
327 | if (ifq_is_enabled(_ifq) && |
328 | (_ifq->altq_flags & ALTQF_CLASSIFY)) { | |
329 | /* XXX default subqueue */ | |
330 | struct ifaltq_subque *_ifsq = | |
331 | &_ifq->altq_subq[ALTQ_SUBQ_INDEX_DEFAULT]; | |
332 | ||
333 | ALTQ_SQ_LOCK(_ifsq); | |
334 | if (ifq_is_enabled(_ifq) && | |
335 | (_ifq->altq_flags & ALTQF_CLASSIFY)) | |
336 | _ifq->altq_classify(_ifq, _m, _pa); | |
337 | ALTQ_SQ_UNLOCK(_ifsq); | |
338 | } | |
9db4b353 | 339 | } |
9db4b353 SZ |
340 | #endif |
341 | } | |
342 | ||
343 | static __inline void | |
f0a26983 | 344 | ifsq_prepend(struct ifaltq_subque *_ifsq, struct mbuf *_m) |
9db4b353 | 345 | { |
f0a26983 SZ |
346 | ALTQ_SQ_LOCK(_ifsq); |
347 | KASSERT(_ifsq->ifsq_prepended == NULL, ("pending prepended mbuf")); | |
348 | _ifsq->ifsq_prepended = _m; | |
68dc1916 | 349 | ALTQ_SQ_CNTR_INC(_ifsq, _m->m_pkthdr.len); |
f0a26983 | 350 | ALTQ_SQ_UNLOCK(_ifsq); |
4d723e5a JS |
351 | } |
352 | ||
058d1cd0 | 353 | /* |
74f8b40c | 354 | * Subqueue hardware serializer must be held |
058d1cd0 | 355 | */ |
9ed293e0 | 356 | static __inline void |
f0a26983 | 357 | ifsq_set_oactive(struct ifaltq_subque *_ifsq) |
9ed293e0 | 358 | { |
f0a26983 | 359 | _ifsq->ifsq_hw_oactive = 1; |
9ed293e0 SZ |
360 | } |
361 | ||
058d1cd0 | 362 | /* |
74f8b40c | 363 | * Subqueue hardware serializer must be held |
058d1cd0 | 364 | */ |
9ed293e0 | 365 | static __inline void |
f0a26983 | 366 | ifsq_clr_oactive(struct ifaltq_subque *_ifsq) |
9ed293e0 | 367 | { |
f0a26983 | 368 | _ifsq->ifsq_hw_oactive = 0; |
9ed293e0 SZ |
369 | } |
370 | ||
058d1cd0 | 371 | /* |
74f8b40c | 372 | * Subqueue hardware serializer must be held |
058d1cd0 | 373 | */ |
9ed293e0 | 374 | static __inline int |
f0a26983 | 375 | ifsq_is_oactive(const struct ifaltq_subque *_ifsq) |
9ed293e0 | 376 | { |
f0a26983 | 377 | return _ifsq->ifsq_hw_oactive; |
9ed293e0 SZ |
378 | } |
379 | ||
78195a76 | 380 | /* |
74f8b40c | 381 | * Hand a packet to the interface's default subqueue. |
78195a76 | 382 | * |
74f8b40c SZ |
383 | * The default subqueue hardware serializer must be held. If the |
384 | * subqueue hardware serializer is not held yet, ifq_dispatch() | |
385 | * should be used to get better performance. | |
78195a76 | 386 | */ |
4d723e5a JS |
387 | static __inline int |
388 | ifq_handoff(struct ifnet *_ifp, struct mbuf *_m, struct altq_pktattr *_pa) | |
389 | { | |
f0a26983 | 390 | struct ifaltq_subque *_ifsq; |
4986965b | 391 | int _error; |
f0a26983 SZ |
392 | int _qid = ALTQ_SUBQ_INDEX_DEFAULT; /* XXX default subqueue */ |
393 | ||
394 | _ifsq = &_ifp->if_snd.altq_subq[_qid]; | |
4d723e5a | 395 | |
bfefe4a6 | 396 | ASSERT_ALTQ_SQ_SERIALIZED_HW(_ifsq); |
f0a26983 | 397 | _error = ifsq_enqueue(_ifsq, _m, _pa); |
4d723e5a | 398 | if (_error == 0) { |
d40991ef | 399 | IFNET_STAT_INC(_ifp, obytes, _m->m_pkthdr.len); |
4d723e5a | 400 | if (_m->m_flags & M_MCAST) |
d40991ef | 401 | IFNET_STAT_INC(_ifp, omcasts, 1); |
f0a26983 SZ |
402 | if (!ifsq_is_oactive(_ifsq)) |
403 | (*_ifp->if_start)(_ifp, _ifsq); | |
6de344ba SZ |
404 | } else { |
405 | IFNET_STAT_INC(_ifp, oqdrops, 1); | |
4d723e5a | 406 | } |
4d723e5a JS |
407 | return(_error); |
408 | } | |
409 | ||
410 | static __inline int | |
f0a26983 | 411 | ifsq_is_empty(const struct ifaltq_subque *_ifsq) |
4d723e5a | 412 | { |
b21c2105 | 413 | return(_ifsq->ifsq_len == 0); |
4d723e5a JS |
414 | } |
415 | ||
058d1cd0 | 416 | /* |
74f8b40c | 417 | * Subqueue lock must be held |
058d1cd0 | 418 | */ |
9db4b353 | 419 | static __inline int |
f0a26983 | 420 | ifsq_data_ready(struct ifaltq_subque *_ifsq) |
9db4b353 SZ |
421 | { |
422 | #ifdef ALTQ | |
f0a26983 SZ |
423 | if (_ifsq->ifsq_altq->altq_tbr != NULL) |
424 | return (ifsq_poll_locked(_ifsq) != NULL); | |
9db4b353 SZ |
425 | else |
426 | #endif | |
f0a26983 | 427 | return !ifsq_is_empty(_ifsq); |
9db4b353 | 428 | } |
b2f93efe | 429 | |
acf18b65 | 430 | /* |
74f8b40c | 431 | * Subqueue lock must be held |
acf18b65 SZ |
432 | */ |
433 | static __inline int | |
f0a26983 | 434 | ifsq_is_started(const struct ifaltq_subque *_ifsq) |
acf18b65 | 435 | { |
f0a26983 | 436 | return _ifsq->ifsq_started; |
acf18b65 SZ |
437 | } |
438 | ||
439 | /* | |
74f8b40c | 440 | * Subqueue lock must be held |
acf18b65 SZ |
441 | */ |
442 | static __inline void | |
f0a26983 | 443 | ifsq_set_started(struct ifaltq_subque *_ifsq) |
acf18b65 | 444 | { |
f0a26983 | 445 | _ifsq->ifsq_started = 1; |
acf18b65 SZ |
446 | } |
447 | ||
448 | /* | |
74f8b40c | 449 | * Subqueue lock must be held |
acf18b65 SZ |
450 | */ |
451 | static __inline void | |
f0a26983 | 452 | ifsq_clr_started(struct ifaltq_subque *_ifsq) |
acf18b65 | 453 | { |
f0a26983 | 454 | _ifsq->ifsq_started = 0; |
acf18b65 SZ |
455 | } |
456 | ||
f0a26983 SZ |
457 | static __inline struct ifsubq_stage * |
458 | ifsq_get_stage(struct ifaltq_subque *_ifsq, int _cpuid) | |
928e2027 | 459 | { |
f0a26983 | 460 | return &_ifsq->ifsq_stage[_cpuid]; |
928e2027 SZ |
461 | } |
462 | ||
dfd3b18b | 463 | static __inline int |
f0a26983 | 464 | ifsq_get_cpuid(const struct ifaltq_subque *_ifsq) |
dfd3b18b | 465 | { |
f0a26983 | 466 | return _ifsq->ifsq_cpuid; |
dfd3b18b SZ |
467 | } |
468 | ||
469 | static __inline void | |
f0a26983 | 470 | ifsq_set_cpuid(struct ifaltq_subque *_ifsq, int _cpuid) |
dfd3b18b | 471 | { |
f0a26983 SZ |
472 | KASSERT(_cpuid >= 0 && _cpuid < ncpus, |
473 | ("invalid ifsq_cpuid %d", _cpuid)); | |
474 | _ifsq->ifsq_cpuid = _cpuid; | |
dfd3b18b SZ |
475 | } |
476 | ||
42fdf81e | 477 | static __inline struct lwkt_msg * |
f0a26983 SZ |
478 | ifsq_get_ifstart_lmsg(struct ifaltq_subque *_ifsq, int _cpuid) |
479 | { | |
480 | return &_ifsq->ifsq_ifstart_nmsg[_cpuid].lmsg; | |
481 | } | |
482 | ||
483 | static __inline int | |
484 | ifsq_get_index(const struct ifaltq_subque *_ifsq) | |
485 | { | |
486 | return _ifsq->ifsq_index; | |
487 | } | |
488 | ||
489 | static __inline void | |
490 | ifsq_set_priv(struct ifaltq_subque *_ifsq, void *_priv) | |
491 | { | |
492 | _ifsq->ifsq_hw_priv = _priv; | |
493 | } | |
494 | ||
495 | static __inline void * | |
496 | ifsq_get_priv(const struct ifaltq_subque *_ifsq) | |
497 | { | |
498 | return _ifsq->ifsq_hw_priv; | |
499 | } | |
500 | ||
501 | static __inline struct ifnet * | |
502 | ifsq_get_ifp(const struct ifaltq_subque *_ifsq) | |
503 | { | |
504 | return _ifsq->ifsq_ifp; | |
505 | } | |
506 | ||
bfefe4a6 SZ |
507 | static __inline void |
508 | ifsq_set_hw_serialize(struct ifaltq_subque *_ifsq, | |
509 | struct lwkt_serialize *_hwslz) | |
510 | { | |
511 | KASSERT(_hwslz != NULL, ("NULL hw serialize")); | |
512 | KASSERT(_ifsq->ifsq_hw_serialize == NULL, | |
513 | ("hw serialize has been setup")); | |
514 | _ifsq->ifsq_hw_serialize = _hwslz; | |
515 | } | |
516 | ||
517 | static __inline void | |
518 | ifsq_serialize_hw(struct ifaltq_subque *_ifsq) | |
519 | { | |
520 | lwkt_serialize_enter(_ifsq->ifsq_hw_serialize); | |
521 | } | |
522 | ||
523 | static __inline void | |
524 | ifsq_deserialize_hw(struct ifaltq_subque *_ifsq) | |
525 | { | |
526 | lwkt_serialize_exit(_ifsq->ifsq_hw_serialize); | |
527 | } | |
528 | ||
529 | static __inline int | |
530 | ifsq_tryserialize_hw(struct ifaltq_subque *_ifsq) | |
531 | { | |
532 | return lwkt_serialize_try(_ifsq->ifsq_hw_serialize); | |
533 | } | |
534 | ||
f0a26983 SZ |
535 | static __inline struct ifaltq_subque * |
536 | ifq_get_subq_default(const struct ifaltq *_ifq) | |
537 | { | |
538 | return &_ifq->altq_subq[ALTQ_SUBQ_INDEX_DEFAULT]; | |
539 | } | |
540 | ||
541 | static __inline struct ifaltq_subque * | |
542 | ifq_get_subq(const struct ifaltq *_ifq, int _idx) | |
543 | { | |
544 | KASSERT(_idx >= 0 && _idx < _ifq->altq_subq_cnt, | |
545 | ("invalid qid %d", _idx)); | |
546 | return &_ifq->altq_subq[_idx]; | |
547 | } | |
548 | ||
2cc2f639 SZ |
549 | static __inline struct ifaltq_subque * |
550 | ifq_map_subq(struct ifaltq *_ifq, int _cpuid) | |
551 | { | |
552 | int _idx = _ifq->altq_mapsubq(_ifq, _cpuid); | |
553 | return ifq_get_subq(_ifq, _idx); | |
554 | } | |
555 | ||
9469a4a2 SZ |
556 | static __inline void |
557 | ifq_set_subq_cnt(struct ifaltq *_ifq, int _cnt) | |
558 | { | |
559 | _ifq->altq_subq_cnt = _cnt; | |
560 | } | |
561 | ||
68732d8f SZ |
562 | static __inline void |
563 | ifq_set_subq_divisor(struct ifaltq *_ifq, uint32_t _divisor) | |
564 | { | |
565 | ||
566 | KASSERT(_divisor > 0, ("invalid divisor %u", _divisor)); | |
567 | KASSERT(_divisor <= _ifq->altq_subq_cnt, | |
568 | ("invalid divisor %u, max %d", _divisor, _ifq->altq_subq_cnt)); | |
569 | _ifq->altq_subq_mappriv = _divisor; | |
c3fb75dd SZ |
570 | } |
571 | ||
f0a26983 SZ |
572 | /* COMPAT */ |
573 | static __inline int | |
574 | ifq_is_oactive(const struct ifaltq *_ifq) | |
575 | { | |
576 | return ifsq_is_oactive(ifq_get_subq_default(_ifq)); | |
577 | } | |
578 | ||
579 | /* COMPAT */ | |
580 | static __inline void | |
581 | ifq_set_oactive(struct ifaltq *_ifq) | |
582 | { | |
583 | ifsq_set_oactive(ifq_get_subq_default(_ifq)); | |
584 | } | |
585 | ||
586 | /* COMPAT */ | |
587 | static __inline void | |
588 | ifq_clr_oactive(struct ifaltq *_ifq) | |
589 | { | |
590 | ifsq_clr_oactive(ifq_get_subq_default(_ifq)); | |
591 | } | |
592 | ||
593 | /* COMPAT */ | |
594 | static __inline int | |
595 | ifq_is_empty(struct ifaltq *_ifq) | |
596 | { | |
597 | return ifsq_is_empty(ifq_get_subq_default(_ifq)); | |
598 | } | |
599 | ||
600 | /* COMPAT */ | |
601 | static __inline void | |
602 | ifq_purge(struct ifaltq *_ifq) | |
603 | { | |
604 | ifsq_purge(ifq_get_subq_default(_ifq)); | |
605 | } | |
606 | ||
607 | /* COMPAT */ | |
608 | static __inline struct mbuf * | |
ac9843a1 | 609 | ifq_dequeue(struct ifaltq *_ifq) |
f0a26983 | 610 | { |
ac9843a1 | 611 | return ifsq_dequeue(ifq_get_subq_default(_ifq)); |
f0a26983 SZ |
612 | } |
613 | ||
614 | /* COMPAT */ | |
615 | static __inline void | |
616 | ifq_prepend(struct ifaltq *_ifq, struct mbuf *_m) | |
617 | { | |
618 | ifsq_prepend(ifq_get_subq_default(_ifq), _m); | |
619 | } | |
620 | ||
621 | /* COMPAT */ | |
622 | static __inline void | |
623 | ifq_set_cpuid(struct ifaltq *_ifq, int _cpuid) | |
42fdf81e | 624 | { |
f0a26983 SZ |
625 | KASSERT(_ifq->altq_subq_cnt == 1, |
626 | ("invalid subqueue count %d", _ifq->altq_subq_cnt)); | |
627 | ifsq_set_cpuid(ifq_get_subq_default(_ifq), _cpuid); | |
42fdf81e SZ |
628 | } |
629 | ||
54daabe8 SZ |
630 | /* COMPAT */ |
631 | static __inline void | |
632 | ifq_set_hw_serialize(struct ifaltq *_ifq, struct lwkt_serialize *_hwslz) | |
633 | { | |
634 | KASSERT(_ifq->altq_subq_cnt == 1, | |
635 | ("invalid subqueue count %d", _ifq->altq_subq_cnt)); | |
636 | ifsq_set_hw_serialize(ifq_get_subq_default(_ifq), _hwslz); | |
637 | } | |
638 | ||
03d6a592 | 639 | #endif /* _NET_IFQ_VAR_H_ */ |