if: Move IFF_OACTIVE bit into ifaltq; prepare multiple TX queues support
[dragonfly.git] / sys / net / altq / if_altq.h
CommitLineData
4d723e5a 1/* $KAME: if_altq.h,v 1.11 2003/07/10 12:07:50 kjc Exp $ */
4d723e5a
JS
2
3/*
4 * Copyright (C) 1997-2003
5 * Sony Computer Science Laboratories Inc. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY SONY CSL AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL SONY CSL OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 */
1bd40720
MD
28#ifndef _NET_ALTQ_IF_ALTQ_H_
29#define _NET_ALTQ_IF_ALTQ_H_
4d723e5a 30
9db4b353
SZ
31#ifndef _SYS_SERIALIZE_H_
32#include <sys/serialize.h>
33#endif
34
4d723e5a
JS
35struct altq_pktattr;
36
28cc0c29
SZ
37struct ifaltq;
38
39struct ifaltq_stage {
40 struct ifaltq *ifqs_altq;
41 int ifqs_cnt;
42 int ifqs_len;
43 uint32_t ifqs_flags;
44 TAILQ_ENTRY(ifaltq_stage) ifqs_link;
45} __cachealign;
46
47#define IFQ_STAGE_FLAG_QUED 0x1
3cab6b0d 48#define IFQ_STAGE_FLAG_SCHED 0x2
28cc0c29 49
4d723e5a
JS
50/*
51 * Structure defining a queue for a network interface.
52 */
53struct ifaltq {
54 /* fields compatible with struct ifqueue */
55 struct mbuf *ifq_head;
56 struct mbuf *ifq_tail;
57 int ifq_len;
58 int ifq_maxlen;
59 int ifq_drops;
60
61 /* alternate queueing related fields */
62 int altq_type; /* discipline type */
63 int altq_flags; /* flags (e.g. ready, in-use) */
64 void *altq_disc; /* for discipline-specific use */
65 struct ifnet *altq_ifp; /* back pointer to interface */
66
67 int (*altq_enqueue)(struct ifaltq *, struct mbuf *,
68 struct altq_pktattr *);
d2c71fa0 69 struct mbuf *(*altq_dequeue)(struct ifaltq *, struct mbuf *, int);
4d723e5a
JS
70 int (*altq_request)(struct ifaltq *, int, void *);
71
72 /* classifier fields */
73 void *altq_clfier; /* classifier-specific use */
74 void *(*altq_classify)(struct ifaltq *, struct mbuf *,
75 struct altq_pktattr *);
76
77 /* token bucket regulator */
78 struct tb_regulator *altq_tbr;
9db4b353
SZ
79
80 struct lwkt_serialize altq_lock;
81 struct mbuf *altq_prepended; /* mbuf dequeued, but not yet xmit */
82 int altq_started; /* ifnet.if_start interlock */
9ed293e0 83 int altq_hw_oactive; /* hw too busy, protected by driver */
28cc0c29 84 struct ifaltq_stage *altq_stage;
4d723e5a
JS
85};
86
9db4b353
SZ
87#define ALTQ_ASSERT_LOCKED(ifq) ASSERT_SERIALIZED(&(ifq)->altq_lock)
88#define ALTQ_LOCK_INIT(ifq) lwkt_serialize_init(&(ifq)->altq_lock)
89#define ALTQ_LOCK(ifq) lwkt_serialize_adaptive_enter(&(ifq)->altq_lock)
90#define ALTQ_UNLOCK(ifq) lwkt_serialize_exit(&(ifq)->altq_lock)
4d723e5a
JS
91
92#ifdef _KERNEL
93
94/*
95 * packet attributes used by queueing disciplines.
96 * pattr_class is a discipline-dependent scheduling class that is
97 * set by a classifier.
98 * pattr_hdr and pattr_af may be used by a discipline to access
99 * the header within a mbuf. (e.g. ECN needs to update the CE bit)
100 * note that pattr_hdr could be stale after m_pullup, though link
101 * layer output routines usually don't use m_pullup. link-level
102 * compression also invalidates these fields. thus, pattr_hdr needs
103 * to be verified when a discipline touches the header.
104 */
105struct altq_pktattr {
106 void *pattr_class; /* sched class set by classifier */
107 int pattr_af; /* address family */
108 caddr_t pattr_hdr; /* saved header position in mbuf */
109};
110
111/*
112 * a token-bucket regulator limits the rate that a network driver can
113 * dequeue packets from the output queue.
114 * modern cards are able to buffer a large amount of packets and dequeue
115 * too many packets at a time. this bursty dequeue behavior makes it
116 * impossible to schedule packets by queueing disciplines.
117 * a token-bucket is used to control the burst size in a device
118 * independent manner.
119 */
120struct tb_regulator {
121 int64_t tbr_rate; /* (scaled) token bucket rate */
122 int64_t tbr_depth; /* (scaled) token bucket depth */
123
124 int64_t tbr_token; /* (scaled) current token */
125 int64_t tbr_filluptime; /* (scaled) time to fill up bucket */
126 uint64_t tbr_last; /* last time token was updated */
127
128 int tbr_lastop; /* last dequeue operation type
129 needed for poll-and-dequeue */
130};
131
132/* if_altqflags */
133#define ALTQF_READY 0x01 /* driver supports alternate queueing */
134#define ALTQF_ENABLED 0x02 /* altq is in use */
135#define ALTQF_CLASSIFY 0x04 /* classify packets */
136#define ALTQF_DRIVER1 0x40 /* driver specific */
137
138/* if_altqflags set internally only: */
139#define ALTQF_CANTCHANGE (ALTQF_READY)
140
141/* altq_dequeue 2nd arg */
142#define ALTDQ_REMOVE 1 /* dequeue mbuf from the queue */
143#define ALTDQ_POLL 2 /* don't dequeue mbuf from the queue */
144
145/* altq request types (currently only purge is defined) */
146#define ALTRQ_PURGE 1 /* purge all packets */
147
4d723e5a
JS
148int altq_attach(struct ifaltq *, int, void *,
149 int (*)(struct ifaltq *, struct mbuf *, struct altq_pktattr *),
d2c71fa0 150 struct mbuf *(*)(struct ifaltq *, struct mbuf *, int),
4d723e5a
JS
151 int (*)(struct ifaltq *, int, void *),
152 void *, void *(*)(struct ifaltq *, struct mbuf *,
153 struct altq_pktattr *));
154int altq_detach(struct ifaltq *);
155int altq_enable(struct ifaltq *);
156int altq_disable(struct ifaltq *);
d2c71fa0 157struct mbuf *tbr_dequeue(struct ifaltq *, struct mbuf *, int);
4d723e5a
JS
158extern int (*altq_input)(struct mbuf *, int);
159#endif /* _KERNEL */
160
1bd40720 161#endif /* _NET_ALTQ_IF_ALTQ_H_ */