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 _NET_PKTSCHED_PKTSCHED_TCQ_H_
30#define _NET_PKTSCHED_PKTSCHED_TCQ_H_
31
32#ifdef PRIVATE
33#include <net/pktsched/pktsched.h>
34#include <net/classq/classq.h>
35#include <net/classq/classq_red.h>
36#include <net/classq/classq_rio.h>
37#include <net/classq/classq_blue.h>
38#include <net/classq/classq_sfb.h>
39
40#ifdef __cplusplus
41extern "C" {
42#endif
43
44#define TCQ_MAXPRI 4 /* upper limit of the number of priorities */
45
46/* tcq class flags */
47#define TQCF_RED 0x0001 /* use RED */
48#define TQCF_ECN 0x0002 /* use ECN with RED/BLUE/SFB */
49#define TQCF_RIO 0x0004 /* use RIO */
50#define TQCF_CLEARDSCP 0x0010 /* clear diffserv codepoint */
51#define TQCF_BLUE 0x0100 /* use BLUE */
52#define TQCF_SFB 0x0200 /* use SFB */
53#define TQCF_FLOWCTL 0x0400 /* enable flow control advisories */
54#define TQCF_DEFAULTCLASS 0x1000 /* default class */
55#define TQCF_DELAYBASED 0x2000 /* queue sizing is delay based */
56#ifdef BSD_KERNEL_PRIVATE
57#define TQCF_LAZY 0x10000000 /* on-demand resource allocation */
58#endif /* BSD_KERNEL_PRIVATE */
59
60#define TQCF_USERFLAGS \
61 (TQCF_RED | TQCF_ECN | TQCF_RIO | TQCF_CLEARDSCP | TQCF_BLUE | \
62 TQCF_SFB | TQCF_FLOWCTL | TQCF_DEFAULTCLASS)
63
64#ifdef BSD_KERNEL_PRIVATE
65#define TQCF_BITS \
66 "\020\1RED\2ECN\3RIO\5CLEARDSCP\11BLUE\12SFB\13FLOWCTL\15DEFAULT" \
67 "\35LAZY"
68#else
69#define TQCF_BITS \
70 "\020\1RED\2ECN\3RIO\5CLEARDSCP\11BLUE\12SFB\13FLOWCTL"
71#endif /* !BSD_KERNEL_PRIVATE */
72
73struct tcq_classstats {
74 u_int32_t class_handle;
75 u_int32_t priority;
76
77 u_int32_t qlength;
78 u_int32_t qlimit;
79 u_int32_t period;
80 struct pktcntr xmitcnt; /* transmitted packet counter */
81 struct pktcntr dropcnt; /* dropped packet counter */
82
83 /* RED, RIO, BLUE, SFB related info */
84 classq_type_t qtype;
85 union {
86 /* RIO has 3 red stats */
87 struct red_stats red[RIO_NDROPPREC];
88 struct blue_stats blue;
89 struct sfb_stats sfb;
90 };
91 classq_state_t qstate;
92};
93
94#ifdef BSD_KERNEL_PRIVATE
95struct tcq_class {
96 u_int32_t cl_handle; /* class handle */
97 class_queue_t cl_q; /* class queue structure */
98 u_int32_t cl_qflags; /* class queue flags */
99 union {
100 void *ptr;
101 struct sfb *sfb; /* SFB state */
102 } cl_qalg;
103 int32_t cl_pri; /* priority */
104 u_int32_t cl_flags; /* class flags */
105 struct tcq_if *cl_tif; /* back pointer to tif */
106
107 /* statistics */
108 u_int32_t cl_period; /* backlog period */
109 struct pktcntr cl_xmitcnt; /* transmitted packet counter */
110 struct pktcntr cl_dropcnt; /* dropped packet counter */
111};
112
113#define cl_sfb cl_qalg.sfb
114
115/*
116 * tcq interface state
117 */
118struct tcq_if {
119 struct ifclassq *tif_ifq; /* backpointer to ifclassq */
120 int tif_maxpri; /* max priority in use */
121 u_int32_t tif_throttle; /* throttling level */
122 struct tcq_class *tif_default; /* default class */
123 struct tcq_class *tif_classes[TCQ_MAXPRI]; /* classes */
124};
125
126#define TCQIF_IFP(_tif) ((_tif)->tif_ifq->ifcq_ifp)
127
128struct if_ifclassq_stats;
129
130extern void tcq_init(void);
131extern struct tcq_if *tcq_alloc(struct ifnet *, int);
132extern int tcq_destroy(struct tcq_if *);
133extern void tcq_purge(struct tcq_if *);
134extern void tcq_event(struct tcq_if *, cqev_t);
135extern int tcq_add_queue(struct tcq_if *, int, u_int32_t, int, u_int32_t,
136 struct tcq_class **, classq_pkt_type_t);
137extern int tcq_remove_queue(struct tcq_if *, u_int32_t);
138extern int tcq_get_class_stats(struct tcq_if *, u_int32_t,
139 struct tcq_classstats *);
140extern int tcq_enqueue(struct tcq_if *, struct tcq_class *, pktsched_pkt_t *,
141 struct pf_mtag *);
142extern void tcq_dequeue_tc(struct tcq_if *, mbuf_svc_class_t, pktsched_pkt_t *);
143extern int tcq_setup_ifclassq(struct ifclassq *, u_int32_t, classq_pkt_type_t);
144extern int tcq_teardown_ifclassq(struct ifclassq *ifq);
145extern int tcq_getqstats_ifclassq(struct ifclassq *, u_int32_t qid,
146 struct if_ifclassq_stats *);
147#endif /* BSD_KERNEL_PRIVATE */
148#ifdef __cplusplus
149}
150#endif
151#endif /* PRIVATE */
152#endif /* _NET_PKTSCHED_PKTSCHED_TCQ_H_ */
153