1/*
2 * Copyright (c) 2016-2017 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 _NET_CLASSQ_CLASSQ_FQ_CODEL_H
30#define _NET_CLASSQ_CLASSQ_FQ_CODEL_H
31#ifdef PRIVATE
32#ifdef BSD_KERNEL_PRIVATE
33#include <stdbool.h>
34#include <sys/time.h>
35#include <net/flowadv.h>
36#include <net/classq/if_classq.h>
37
38#ifdef __cplusplus
39extern "C" {
40#endif
41
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; \
46} while (0)
47#define FQ_CLEAR_DELAY_HIGH(_fq_) do { \
48 (_fq_)->fq_flags &= ~FQF_DELAY_HIGH; \
49} while (0)
50
51typedef struct flowq {
52 union {
53 MBUFQ_HEAD(mbufq_head) __mbufq; /* mbuf packet queue */
54 } __fq_pktq_u;
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 u_int8_t fq_flags; /* flags */
61 u_int8_t fq_sc_index; /* service_class index */
62 int16_t fq_deficit; /* Deficit for scheduling */
63 u_int32_t fq_bytes; /* Number of bytes in the queue */
64 u_int64_t fq_min_qdelay; /* min queue delay for Codel */
65 u_int64_t fq_updatetime; /* next update interval */
66 u_int64_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 u_int32_t fq_flowhash; /* Flow hash */
70 classq_pkt_type_t fq_ptype; /* Packet type */
71} fq_t;
72
73#define fq_mbufq __fq_pktq_u.__mbufq
74
75#define fq_empty(_q) MBUFQ_EMPTY(&(_q)->fq_mbufq)
76
77#define fq_enqueue(_q, _p) MBUFQ_ENQUEUE(&(_q)->fq_mbufq, (mbuf_t)_p)
78
79#define fq_dequeue(_q, _p) do { \
80 mbuf_t _m; \
81 MBUFQ_DEQUEUE(&(_q)->fq_mbufq, _m); \
82 (_p) = _m; \
83} while (0)
84
85struct fq_codel_sched_data;
86struct fq_if_classq;
87
88/* Function definitions */
89extern void fq_codel_init(void);
90extern void fq_codel_reap_caches(boolean_t);
91extern fq_t *fq_alloc(classq_pkt_type_t);
92extern void fq_destroy(fq_t *);
93extern int fq_addq(struct fq_codel_sched_data *, pktsched_pkt_t *,
94 struct fq_if_classq *);
95extern void *fq_getq_flow(struct fq_codel_sched_data *, fq_t *,
96 pktsched_pkt_t *);
97extern void *fq_getq_flow_internal(struct fq_codel_sched_data *,
98 fq_t *, pktsched_pkt_t *);
99extern void fq_head_drop(struct fq_codel_sched_data *, fq_t *);
100
101#ifdef __cplusplus
102}
103#endif
104#endif /* BSD_KERNEL_PRIVATE */
105#endif /* PRIVATE */
106#endif /* _NET_CLASSQ_CLASSQ_FQ_CODEL_H */
107