2 * Copyright (c) 2016-2018 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
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.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
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.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
29 #ifndef _NET_CLASSQ_CLASSQ_FQ_CODEL_H
30 #define _NET_CLASSQ_CLASSQ_FQ_CODEL_H
32 #ifdef BSD_KERNEL_PRIVATE
35 #include <net/flowadv.h>
36 #include <net/classq/if_classq.h>
42 #define FQ_MIN_FC_THRESHOLD_BYTES 7500
43 #define FQ_IS_DELAYHIGH(_fq_) ((_fq_)->fq_flags & FQF_DELAY_HIGH)
44 #define FQ_SET_DELAY_HIGH(_fq_) do { \
45 (_fq_)->fq_flags |= FQF_DELAY_HIGH; \
47 #define FQ_CLEAR_DELAY_HIGH(_fq_) do { \
48 (_fq_)->fq_flags &= ~FQF_DELAY_HIGH; \
51 typedef struct flowq
{
53 MBUFQ_HEAD(mbufq_head
) __mbufq
; /* mbuf packet queue */
55 #define FQF_FLOWCTL_CAPABLE 0x01 /* Use flow control instead of drop */
56 #define FQF_DELAY_HIGH 0x02 /* Min delay is greater than target */
57 #define FQF_NEW_FLOW 0x04 /* Currently on new flows queue */
58 #define FQF_OLD_FLOW 0x08 /* Currently on old flows queue */
59 #define FQF_FLOWCTL_ON 0x10 /* Currently flow controlled */
60 uint8_t fq_flags
; /* flags */
61 uint8_t fq_sc_index
; /* service_class index */
62 int16_t fq_deficit
; /* Deficit for scheduling */
63 uint32_t fq_bytes
; /* Number of bytes in the queue */
64 uint64_t fq_min_qdelay
; /* min queue delay for Codel */
65 uint64_t fq_updatetime
; /* next update interval */
66 uint64_t fq_getqtime
; /* last dequeue time */
67 SLIST_ENTRY(flowq
) fq_hashlink
; /* for flow queue hash table */
68 STAILQ_ENTRY(flowq
) fq_actlink
; /* for new/old flow queues */
69 uint32_t fq_flowhash
; /* Flow hash */
70 classq_pkt_type_t fq_ptype
; /* Packet type */
73 #define fq_mbufq __fq_pktq_u.__mbufq
75 #define fq_empty(_q) MBUFQ_EMPTY(&(_q)->fq_mbufq)
77 #define fq_enqueue(_q, _h, _t, _c) \
78 MBUFQ_ENQUEUE_MULTI(&(_q)->fq_mbufq, (_h).cp_mbuf, (_t).cp_mbuf)
80 #define fq_dequeue(_q, _p) do { \
81 MBUFQ_DEQUEUE(&(_q)->fq_mbufq, (_p)->cp_mbuf); \
82 if (__probable((_p)->cp_mbuf != NULL)) { \
83 CLASSQ_PKT_INIT_MBUF((_p), (_p)->cp_mbuf); \
87 struct fq_codel_sched_data
;
90 /* Function definitions */
91 extern void fq_codel_init(void);
92 extern void fq_codel_reap_caches(boolean_t
);
93 extern fq_t
*fq_alloc(classq_pkt_type_t
);
94 extern void fq_destroy(fq_t
*);
95 extern int fq_addq(struct fq_codel_sched_data
*, pktsched_pkt_t
*,
96 struct fq_if_classq
*);
97 extern void fq_getq_flow(struct fq_codel_sched_data
*, fq_t
*,
99 extern void fq_getq_flow_internal(struct fq_codel_sched_data
*,
100 fq_t
*, pktsched_pkt_t
*);
101 extern void fq_head_drop(struct fq_codel_sched_data
*, fq_t
*);
106 #endif /* BSD_KERNEL_PRIVATE */
108 #endif /* _NET_CLASSQ_CLASSQ_FQ_CODEL_H */