1 /* $KAME: if_altq.h,v 1.11 2003/07/10 12:07:50 kjc Exp $ */ 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 */ 28 #ifndef _NET_ALTQ_IF_ALTQ_H_ 29 #define _NET_ALTQ_IF_ALTQ_H_ 30 31 #ifndef _SYS_SERIALIZE_H_ 32 #include <sys/serialize.h> 33 #endif 34 35 struct altq_pktattr; 36 37 /* 38 * Structure defining a queue for a network interface. 39 */ 40 struct ifaltq { 41 /* fields compatible with struct ifqueue */ 42 struct mbuf *ifq_head; 43 struct mbuf *ifq_tail; 44 int ifq_len; 45 int ifq_maxlen; 46 int ifq_drops; 47 48 /* alternate queueing related fields */ 49 int altq_type; /* discipline type */ 50 int altq_flags; /* flags (e.g. ready, in-use) */ 51 void *altq_disc; /* for discipline-specific use */ 52 struct ifnet *altq_ifp; /* back pointer to interface */ 53 54 int (*altq_enqueue)(struct ifaltq *, struct mbuf *, 55 struct altq_pktattr *); 56 struct mbuf *(*altq_dequeue)(struct ifaltq *, struct mbuf *, int); 57 int (*altq_request)(struct ifaltq *, int, void *); 58 59 /* classifier fields */ 60 void *altq_clfier; /* classifier-specific use */ 61 void *(*altq_classify)(struct ifaltq *, struct mbuf *, 62 struct altq_pktattr *); 63 64 /* token bucket regulator */ 65 struct tb_regulator *altq_tbr; 66 67 struct lwkt_serialize altq_lock; 68 struct mbuf *altq_prepended; /* mbuf dequeued, but not yet xmit */ 69 int altq_started; /* ifnet.if_start interlock */ 70 }; 71 72 #define ALTQ_ASSERT_LOCKED(ifq) ASSERT_SERIALIZED(&(ifq)->altq_lock) 73 #define ALTQ_LOCK_INIT(ifq) lwkt_serialize_init(&(ifq)->altq_lock) 74 #define ALTQ_LOCK(ifq) lwkt_serialize_adaptive_enter(&(ifq)->altq_lock) 75 #define ALTQ_UNLOCK(ifq) lwkt_serialize_exit(&(ifq)->altq_lock) 76 77 #ifdef _KERNEL 78 79 /* 80 * packet attributes used by queueing disciplines. 81 * pattr_class is a discipline-dependent scheduling class that is 82 * set by a classifier. 83 * pattr_hdr and pattr_af may be used by a discipline to access 84 * the header within a mbuf. (e.g. ECN needs to update the CE bit) 85 * note that pattr_hdr could be stale after m_pullup, though link 86 * layer output routines usually don't use m_pullup. link-level 87 * compression also invalidates these fields. thus, pattr_hdr needs 88 * to be verified when a discipline touches the header. 89 */ 90 struct altq_pktattr { 91 void *pattr_class; /* sched class set by classifier */ 92 int pattr_af; /* address family */ 93 caddr_t pattr_hdr; /* saved header position in mbuf */ 94 }; 95 96 /* 97 * a token-bucket regulator limits the rate that a network driver can 98 * dequeue packets from the output queue. 99 * modern cards are able to buffer a large amount of packets and dequeue 100 * too many packets at a time. this bursty dequeue behavior makes it 101 * impossible to schedule packets by queueing disciplines. 102 * a token-bucket is used to control the burst size in a device 103 * independent manner. 104 */ 105 struct tb_regulator { 106 int64_t tbr_rate; /* (scaled) token bucket rate */ 107 int64_t tbr_depth; /* (scaled) token bucket depth */ 108 109 int64_t tbr_token; /* (scaled) current token */ 110 int64_t tbr_filluptime; /* (scaled) time to fill up bucket */ 111 uint64_t tbr_last; /* last time token was updated */ 112 113 int tbr_lastop; /* last dequeue operation type 114 needed for poll-and-dequeue */ 115 }; 116 117 /* if_altqflags */ 118 #define ALTQF_READY 0x01 /* driver supports alternate queueing */ 119 #define ALTQF_ENABLED 0x02 /* altq is in use */ 120 #define ALTQF_CLASSIFY 0x04 /* classify packets */ 121 #define ALTQF_DRIVER1 0x40 /* driver specific */ 122 123 /* if_altqflags set internally only: */ 124 #define ALTQF_CANTCHANGE (ALTQF_READY) 125 126 /* altq_dequeue 2nd arg */ 127 #define ALTDQ_REMOVE 1 /* dequeue mbuf from the queue */ 128 #define ALTDQ_POLL 2 /* don't dequeue mbuf from the queue */ 129 130 /* altq request types (currently only purge is defined) */ 131 #define ALTRQ_PURGE 1 /* purge all packets */ 132 133 int altq_attach(struct ifaltq *, int, void *, 134 int (*)(struct ifaltq *, struct mbuf *, struct altq_pktattr *), 135 struct mbuf *(*)(struct ifaltq *, struct mbuf *, int), 136 int (*)(struct ifaltq *, int, void *), 137 void *, void *(*)(struct ifaltq *, struct mbuf *, 138 struct altq_pktattr *)); 139 int altq_detach(struct ifaltq *); 140 int altq_enable(struct ifaltq *); 141 int altq_disable(struct ifaltq *); 142 struct mbuf *tbr_dequeue(struct ifaltq *, struct mbuf *, int); 143 extern int (*altq_input)(struct mbuf *, int); 144 #endif /* _KERNEL */ 145 146 #endif /* _NET_ALTQ_IF_ALTQ_H_ */ 147