/*-1* Copyright (C) 1997-20032* Sony Computer Science Laboratories Inc. All rights reserved.3*4* Redistribution and use in source and binary forms, with or without5* modification, are permitted provided that the following conditions6* are met:7* 1. Redistributions of source code must retain the above copyright8* notice, this list of conditions and the following disclaimer.9* 2. Redistributions in binary form must reproduce the above copyright10* notice, this list of conditions and the following disclaimer in the11* documentation and/or other materials provided with the distribution.12*13* THIS SOFTWARE IS PROVIDED BY SONY CSL AND CONTRIBUTORS ``AS IS'' AND14* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE15* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE16* ARE DISCLAIMED. IN NO EVENT SHALL SONY CSL OR CONTRIBUTORS BE LIABLE17* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL18* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS19* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)20* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT21* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY22* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF23* SUCH DAMAGE.24*25* $KAME: if_altq.h,v 1.12 2005/04/13 03:44:25 suz Exp $26*/27#ifndef _ALTQ_IF_ALTQ_H_28#define _ALTQ_IF_ALTQ_H_2930#include <sys/lock.h> /* XXX */31#include <sys/mutex.h> /* XXX */32#include <sys/event.h> /* XXX */3334struct altq_pktattr; struct tb_regulator; struct top_cdnr;3536/*37* Structure defining a queue for a network interface.38*/39struct ifaltq {40/* fields compatible with struct ifqueue */41struct mbuf *ifq_head;42struct mbuf *ifq_tail;43int ifq_len;44int ifq_maxlen;45struct mtx ifq_mtx;4647/* driver owned queue (used for bulk dequeue and prepend) UNLOCKED */48struct mbuf *ifq_drv_head;49struct mbuf *ifq_drv_tail;50int ifq_drv_len;51int ifq_drv_maxlen;5253/* alternate queueing related fields */54int altq_type; /* discipline type */55int altq_flags; /* flags (e.g. ready, in-use) */56void *altq_disc; /* for discipline-specific use */57struct ifnet *altq_ifp; /* back pointer to interface */5859int (*altq_enqueue)(struct ifaltq *, struct mbuf *,60struct altq_pktattr *);61struct mbuf *(*altq_dequeue)(struct ifaltq *, int);62int (*altq_request)(struct ifaltq *, int, void *);6364/* token bucket regulator */65struct tb_regulator *altq_tbr;6667/* input traffic conditioner (doesn't belong to the output queue...) */68struct top_cdnr *altq_cdnr;69};7071#ifdef _KERNEL7273/*74* packet attributes used by queueing disciplines.75* pattr_class is a discipline-dependent scheduling class that is76* set by a classifier.77* pattr_hdr and pattr_af may be used by a discipline to access78* the header within a mbuf. (e.g. ECN needs to update the CE bit)79* note that pattr_hdr could be stale after m_pullup, though link80* layer output routines usually don't use m_pullup. link-level81* compression also invalidates these fields. thus, pattr_hdr needs82* to be verified when a discipline touches the header.83*/84struct altq_pktattr {85void *pattr_class; /* sched class set by classifier */86int pattr_af; /* address family */87caddr_t pattr_hdr; /* saved header position in mbuf */88};8990/*91* mbuf tag to carry a queue id (and hints for ECN).92*/93struct altq_tag {94u_int32_t qid; /* queue id */95/* hints for ecn */96int af; /* address family */97void *hdr; /* saved header position in mbuf */98};99100/*101* a token-bucket regulator limits the rate that a network driver can102* dequeue packets from the output queue.103* modern cards are able to buffer a large amount of packets and dequeue104* too many packets at a time. this bursty dequeue behavior makes it105* impossible to schedule packets by queueing disciplines.106* a token-bucket is used to control the burst size in a device107* independent manner.108*/109struct tb_regulator {110int64_t tbr_rate; /* (scaled) token bucket rate */111int64_t tbr_depth; /* (scaled) token bucket depth */112113int64_t tbr_token; /* (scaled) current token */114int64_t tbr_filluptime; /* (scaled) time to fill up bucket */115u_int64_t tbr_last; /* last time token was updated */116117int tbr_lastop; /* last dequeue operation type118needed for poll-and-dequeue */119};120121/* if_altqflags */122#define ALTQF_READY 0x01 /* driver supports alternate queueing */123#define ALTQF_ENABLED 0x02 /* altq is in use */124/* ALTQF_CLASSIFY 0x04 obsolete classify packets */125#define ALTQF_CNDTNING 0x08 /* altq traffic conditioning is enabled */126#define ALTQF_DRIVER1 0x40 /* driver specific */127128/* if_altqflags set internally only: */129#define ALTQF_CANTCHANGE (ALTQF_READY)130131/* altq_dequeue 2nd arg */132#define ALTDQ_REMOVE 1 /* dequeue mbuf from the queue */133#define ALTDQ_POLL 2 /* don't dequeue mbuf from the queue */134135/* altq request types (currently only purge is defined) */136#define ALTRQ_PURGE 1 /* purge all packets */137138#define ALTQ_IS_READY(ifq) ((ifq)->altq_flags & ALTQF_READY)139#ifdef ALTQ140#define ALTQ_IS_ENABLED(ifq) ((ifq)->altq_flags & ALTQF_ENABLED)141#else142#define ALTQ_IS_ENABLED(ifq) 0143#endif144#define ALTQ_IS_CNDTNING(ifq) ((ifq)->altq_flags & ALTQF_CNDTNING)145146#define ALTQ_SET_CNDTNING(ifq) ((ifq)->altq_flags |= ALTQF_CNDTNING)147#define ALTQ_CLEAR_CNDTNING(ifq) ((ifq)->altq_flags &= ~ALTQF_CNDTNING)148#define ALTQ_IS_ATTACHED(ifq) ((ifq)->altq_disc != NULL)149150#define ALTQ_ENQUEUE(ifq, m, pa, err) \151(err) = (*(ifq)->altq_enqueue)((ifq),(m),(pa))152#define ALTQ_DEQUEUE(ifq, m) \153(m) = (*(ifq)->altq_dequeue)((ifq), ALTDQ_REMOVE)154#define ALTQ_POLL(ifq, m) \155(m) = (*(ifq)->altq_dequeue)((ifq), ALTDQ_POLL)156#define ALTQ_PURGE(ifq) \157(void)(*(ifq)->altq_request)((ifq), ALTRQ_PURGE, (void *)0)158#define ALTQ_IS_EMPTY(ifq) ((ifq)->ifq_len == 0)159#define TBR_IS_ENABLED(ifq) ((ifq)->altq_tbr != NULL)160161extern int altq_attach(struct ifaltq *, int, void *,162int (*)(struct ifaltq *, struct mbuf *,163struct altq_pktattr *),164struct mbuf *(*)(struct ifaltq *, int),165int (*)(struct ifaltq *, int, void *));166extern int altq_detach(struct ifaltq *);167extern int altq_enable(struct ifaltq *);168extern int altq_disable(struct ifaltq *);169extern struct mbuf *(*tbr_dequeue_ptr)(struct ifaltq *, int);170#if 0 /* ALTQ3_CLFIER_COMPAT */171void altq_etherclassify(struct ifaltq *, struct mbuf *, struct altq_pktattr *);172#endif173#endif /* _KERNEL */174175#endif /* _ALTQ_IF_ALTQ_H_ */176177178