if_altq.h revision 1.16.4.1 1 1.16.4.1 thorpej /* $NetBSD: if_altq.h,v 1.16.4.1 2023/11/11 13:16:30 thorpej Exp $ */
2 1.11 peter /* $KAME: if_altq.h,v 1.12 2005/04/13 03:44:25 suz Exp $ */
3 1.1 thorpej
4 1.1 thorpej /*
5 1.11 peter * Copyright (C) 1997-2003
6 1.1 thorpej * Sony Computer Science Laboratories Inc. All rights reserved.
7 1.1 thorpej *
8 1.1 thorpej * Redistribution and use in source and binary forms, with or without
9 1.1 thorpej * modification, are permitted provided that the following conditions
10 1.1 thorpej * are met:
11 1.1 thorpej * 1. Redistributions of source code must retain the above copyright
12 1.1 thorpej * notice, this list of conditions and the following disclaimer.
13 1.1 thorpej * 2. Redistributions in binary form must reproduce the above copyright
14 1.1 thorpej * notice, this list of conditions and the following disclaimer in the
15 1.1 thorpej * documentation and/or other materials provided with the distribution.
16 1.1 thorpej *
17 1.1 thorpej * THIS SOFTWARE IS PROVIDED BY SONY CSL AND CONTRIBUTORS ``AS IS'' AND
18 1.1 thorpej * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 1.1 thorpej * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 1.1 thorpej * ARE DISCLAIMED. IN NO EVENT SHALL SONY CSL OR CONTRIBUTORS BE LIABLE
21 1.1 thorpej * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 1.1 thorpej * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 1.1 thorpej * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 1.1 thorpej * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 1.1 thorpej * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 1.1 thorpej * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 1.1 thorpej * SUCH DAMAGE.
28 1.1 thorpej */
29 1.1 thorpej #ifndef _ALTQ_IF_ALTQ_H_
30 1.1 thorpej #define _ALTQ_IF_ALTQ_H_
31 1.4 thorpej
32 1.8 jdolecek #if defined(_KERNEL_OPT)
33 1.8 jdolecek #include "opt_altq_enabled.h"
34 1.4 thorpej #endif
35 1.1 thorpej
36 1.1 thorpej struct altq_pktattr; struct tb_regulator; struct top_cdnr;
37 1.1 thorpej
38 1.1 thorpej /*
39 1.16.4.1 thorpej * Structure defining a complex queue for a network interface.
40 1.1 thorpej */
41 1.16.4.1 thorpej struct ifaltq {
42 1.16.4.1 thorpej struct ifaltq *ifq_altq; /* pointer back to self */
43 1.16.4.1 thorpej struct ifqueue *altq_ifq; /* pointer back to base queue */
44 1.1 thorpej int altq_type; /* discipline type */
45 1.1 thorpej int altq_flags; /* flags (e.g. ready, in-use) */
46 1.1 thorpej void *altq_disc; /* for discipline-specific use */
47 1.1 thorpej struct ifnet *altq_ifp; /* back pointer to interface */
48 1.1 thorpej
49 1.15 knakahar int (*altq_enqueue)(struct ifaltq *, struct mbuf *);
50 1.11 peter struct mbuf *(*altq_dequeue)(struct ifaltq *, int);
51 1.11 peter int (*altq_request)(struct ifaltq *, int, void *);
52 1.1 thorpej
53 1.1 thorpej /* classifier fields */
54 1.1 thorpej void *altq_clfier; /* classifier-specific use */
55 1.11 peter void *(*altq_classify)(void *, struct mbuf *, int);
56 1.1 thorpej
57 1.1 thorpej /* token bucket regulator */
58 1.1 thorpej struct tb_regulator *altq_tbr;
59 1.1 thorpej
60 1.1 thorpej /* input traffic conditioner (doesn't belong to the output queue...) */
61 1.1 thorpej struct top_cdnr *altq_cdnr;
62 1.1 thorpej };
63 1.1 thorpej
64 1.1 thorpej
65 1.1 thorpej #ifdef _KERNEL
66 1.1 thorpej
67 1.1 thorpej /*
68 1.1 thorpej * packet attributes used by queueing disciplines.
69 1.1 thorpej * pattr_class is a discipline-dependent scheduling class that is
70 1.1 thorpej * set by a classifier.
71 1.1 thorpej * pattr_hdr and pattr_af may be used by a discipline to access
72 1.1 thorpej * the header within a mbuf. (e.g. ECN needs to update the CE bit)
73 1.1 thorpej * note that pattr_hdr could be stale after m_pullup, though link
74 1.1 thorpej * layer output routines usually don't use m_pullup. link-level
75 1.1 thorpej * compression also invalidates these fields. thus, pattr_hdr needs
76 1.1 thorpej * to be verified when a discipline touches the header.
77 1.1 thorpej */
78 1.1 thorpej struct altq_pktattr {
79 1.1 thorpej void *pattr_class; /* sched class set by classifier */
80 1.1 thorpej int pattr_af; /* address family */
81 1.12 christos void * pattr_hdr; /* saved header position in mbuf */
82 1.1 thorpej };
83 1.1 thorpej
84 1.1 thorpej /*
85 1.11 peter * mbuf tag to carry a queue id (and hints for ECN).
86 1.11 peter */
87 1.11 peter struct altq_tag {
88 1.11 peter u_int32_t qid; /* queue id */
89 1.11 peter /* hints for ecn */
90 1.11 peter int af; /* address family */
91 1.11 peter void *hdr; /* saved header position in mbuf */
92 1.11 peter };
93 1.11 peter
94 1.11 peter /*
95 1.1 thorpej * a token-bucket regulator limits the rate that a network driver can
96 1.1 thorpej * dequeue packets from the output queue.
97 1.1 thorpej * modern cards are able to buffer a large amount of packets and dequeue
98 1.1 thorpej * too many packets at a time. this bursty dequeue behavior makes it
99 1.1 thorpej * impossible to schedule packets by queueing disciplines.
100 1.1 thorpej * a token-bucket is used to control the burst size in a device
101 1.1 thorpej * independent manner.
102 1.1 thorpej */
103 1.1 thorpej struct tb_regulator {
104 1.1 thorpej int64_t tbr_rate; /* (scaled) token bucket rate */
105 1.1 thorpej int64_t tbr_depth; /* (scaled) token bucket depth */
106 1.1 thorpej
107 1.1 thorpej int64_t tbr_token; /* (scaled) current token */
108 1.1 thorpej int64_t tbr_filluptime; /* (scaled) time to fill up bucket */
109 1.1 thorpej u_int64_t tbr_last; /* last time token was updated */
110 1.1 thorpej
111 1.1 thorpej int tbr_lastop; /* last dequeue operation type
112 1.1 thorpej needed for poll-and-dequeue */
113 1.1 thorpej };
114 1.1 thorpej
115 1.1 thorpej /* if_altqflags */
116 1.1 thorpej #define ALTQF_READY 0x01 /* driver supports alternate queueing */
117 1.1 thorpej #define ALTQF_ENABLED 0x02 /* altq is in use */
118 1.1 thorpej #define ALTQF_CLASSIFY 0x04 /* classify packets */
119 1.1 thorpej #define ALTQF_CNDTNING 0x08 /* altq traffic conditioning is enabled */
120 1.1 thorpej #define ALTQF_DRIVER1 0x40 /* driver specific */
121 1.1 thorpej
122 1.1 thorpej /* if_altqflags set internally only: */
123 1.1 thorpej #define ALTQF_CANTCHANGE (ALTQF_READY)
124 1.1 thorpej
125 1.1 thorpej /* altq_dequeue 2nd arg */
126 1.1 thorpej #define ALTDQ_REMOVE 1 /* dequeue mbuf from the queue */
127 1.1 thorpej #define ALTDQ_POLL 2 /* don't dequeue mbuf from the queue */
128 1.1 thorpej
129 1.1 thorpej /* altq request types (currently only purge is defined) */
130 1.1 thorpej #define ALTRQ_PURGE 1 /* purge all packets */
131 1.1 thorpej
132 1.16.4.1 thorpej #define ALTQ_INC_LEN(altq) (altq)->altq_ifq->ifq_len++
133 1.16.4.1 thorpej #define ALTQ_DEC_LEN(altq) (altq)->altq_ifq->ifq_len--
134 1.16.4.1 thorpej #define ALTQ_GET_LEN(altq) (altq)->altq_ifq->ifq_len
135 1.16.4.1 thorpej #define ALTQ_SET_LEN(altq, v) (altq)->altq_ifq->ifq_len = (v)
136 1.16.4.1 thorpej #define ALTQ_IS_EMPTY(altq) ((altq)->altq_ifq->ifq_len == 0)
137 1.16.4.1 thorpej
138 1.16.4.1 thorpej #define _ALTQ_FLAGS(ifq) ((ifq)->ifq_altq != NULL ? \
139 1.16.4.1 thorpej (ifq)->ifq_altq->altq_flags : 0)
140 1.16.4.1 thorpej
141 1.16.4.1 thorpej #define ALTQ_IS_READY(ifq) (_ALTQ_FLAGS(ifq) & ALTQF_READY)
142 1.16.4.1 thorpej #define ALTQ_IS_ENABLED(ifq) (_ALTQ_FLAGS(ifq) & ALTQF_ENABLED)
143 1.16.4.1 thorpej #define ALTQ_NEEDS_CLASSIFY(ifq) (_ALTQ_FLAGS(ifq) & ALTQF_CLASSIFY)
144 1.16.4.1 thorpej #define ALTQ_IS_CNDTNING(ifq) (_ALTQ_FLAGS(ifq) & ALTQF_CNDTNING)
145 1.16.4.1 thorpej
146 1.16.4.1 thorpej #define ALTQ_SET_CNDTNING(ifq) \
147 1.16.4.1 thorpej do { \
148 1.16.4.1 thorpej if ((ifq)->ifq_altq != NULL) { \
149 1.16.4.1 thorpej (ifq)->ifq_altq->altq_flags |= ALTQF_CNDTNING; \
150 1.16.4.1 thorpej } \
151 1.16.4.1 thorpej } while (/*CONSTCOND*/0)
152 1.16.4.1 thorpej
153 1.16.4.1 thorpej #define ALTQ_CLEAR_CNDTNING(ifq) \
154 1.16.4.1 thorpej do { \
155 1.16.4.1 thorpej if ((ifq)->ifq_altq != NULL) { \
156 1.16.4.1 thorpej (ifq)->ifq_altq->altq_flags &= ~ALTQF_CNDTNING; \
157 1.16.4.1 thorpej } \
158 1.16.4.1 thorpej } while (/*CONSTCOND*/0)
159 1.16.4.1 thorpej
160 1.16.4.1 thorpej #define ALTQ_IS_ATTACHED(ifq) ((ifq)->ifq_altq != NULL && \
161 1.16.4.1 thorpej (ifq)->ifq_altq->altq_disc != NULL)
162 1.1 thorpej
163 1.15 knakahar #define ALTQ_ENQUEUE(ifq, m, err) \
164 1.16.4.1 thorpej (err) = (*(ifq)->ifq_altq->altq_enqueue)((ifq)->ifq_altq,(m))
165 1.1 thorpej #define ALTQ_DEQUEUE(ifq, m) \
166 1.16.4.1 thorpej (m) = (*(ifq)->ifq_altq->altq_dequeue)((ifq)->ifq_altq, ALTDQ_REMOVE)
167 1.1 thorpej #define ALTQ_POLL(ifq, m) \
168 1.16.4.1 thorpej (m) = (*(ifq)->ifq_altq->altq_dequeue)((ifq)->ifq_altq, ALTDQ_POLL)
169 1.1 thorpej #define ALTQ_PURGE(ifq) \
170 1.16.4.1 thorpej (void)(*(ifq)->ifq_altq->altq_request)((ifq)->ifq_altq, ALTRQ_PURGE, (void *)0)
171 1.16.4.1 thorpej
172 1.16.4.1 thorpej #define TBR_IS_ENABLED(ifq) ((ifq)->ifq_altq != NULL && \
173 1.16.4.1 thorpej (ifq)->ifq_altq->altq_tbr != NULL)
174 1.16.4.1 thorpej
175 1.16.4.1 thorpej extern void altq_alloc(struct ifqueue *, struct ifnet *);
176 1.16.4.1 thorpej extern void altq_free(struct ifqueue *);
177 1.16.4.1 thorpej extern void altq_set_ready(struct ifqueue *);
178 1.1 thorpej
179 1.11 peter extern int altq_attach(struct ifaltq *, int, void *,
180 1.15 knakahar int (*)(struct ifaltq *, struct mbuf *),
181 1.11 peter struct mbuf *(*)(struct ifaltq *, int),
182 1.11 peter int (*)(struct ifaltq *, int, void *),
183 1.11 peter void *,
184 1.11 peter void *(*)(void *, struct mbuf *, int));
185 1.11 peter extern int altq_detach(struct ifaltq *);
186 1.11 peter extern int altq_enable(struct ifaltq *);
187 1.11 peter extern int altq_disable(struct ifaltq *);
188 1.11 peter extern struct mbuf *tbr_dequeue(struct ifaltq *, int);
189 1.11 peter extern int (*altq_input)(struct mbuf *, int);
190 1.11 peter #if 1 /* ALTQ3_CLFIER_COMPAT */
191 1.15 knakahar void altq_etherclassify(struct ifaltq *, struct mbuf *);
192 1.11 peter #endif
193 1.1 thorpej #endif /* _KERNEL */
194 1.1 thorpej
195 1.1 thorpej #endif /* _ALTQ_IF_ALTQ_H_ */
196