/*1* Copyright (c) 2008 The DragonFly Project. All rights reserved.2*3* This code is derived from software contributed to The DragonFly Project4* by Matthew Dillon <[email protected]>5*6* Redistribution and use in source and binary forms, with or without7* modification, are permitted provided that the following conditions8* are met:9*10* 1. Redistributions of source code must retain the above copyright11* notice, this list of conditions and the following disclaimer.12* 2. Redistributions in binary form must reproduce the above copyright13* notice, this list of conditions and the following disclaimer in14* the documentation and/or other materials provided with the15* distribution.16* 3. Neither the name of The DragonFly Project nor the names of its17* contributors may be used to endorse or promote products derived18* from this software without specific, prior written permission.19*20* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS21* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT22* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS23* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE24* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,25* INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,26* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;27* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED28* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,29* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT30* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF31* SUCH DAMAGE.32*33* $DragonFly: src/sys/net/altq/altq_fairq.h,v 1.1 2008/04/06 18:58:15 dillon Exp $34*/3536#ifndef _ALTQ_ALTQ_FAIRQ_H_37#define _ALTQ_ALTQ_FAIRQ_H_3839#include <net/altq/altq.h>40#include <net/altq/altq_classq.h>41#include <net/altq/altq_codel.h>42#include <net/altq/altq_red.h>43#include <net/altq/altq_rio.h>44#include <net/altq/altq_rmclass.h>4546#define FAIRQ_MAX_BUCKETS 2048 /* maximum number of sorting buckets */47#define FAIRQ_MAXPRI RM_MAXPRIO48#define FAIRQ_BITMAP_WIDTH (sizeof(fairq_bitmap_t)*8)49#define FAIRQ_BITMAP_MASK (FAIRQ_BITMAP_WIDTH - 1)5051/* fairq class flags */52#define FARF_RED 0x0001 /* use RED */53#define FARF_ECN 0x0002 /* use RED/ECN */54#define FARF_RIO 0x0004 /* use RIO */55#define FARF_CODEL 0x0008 /* use CoDel */56#define FARF_CLEARDSCP 0x0010 /* clear diffserv codepoint */57#define FARF_DEFAULTCLASS 0x1000 /* default class */5859#define FARF_HAS_PACKETS 0x2000 /* might have queued packets */6061#define FARF_USERFLAGS (FARF_RED|FARF_ECN|FARF_RIO|FARF_CLEARDSCP| \62FARF_DEFAULTCLASS)6364/* special class handles */65#define FAIRQ_NULLCLASS_HANDLE 06667typedef u_int fairq_bitmap_t;6869struct fairq_classstats {70uint32_t class_handle;7172u_int qlength;73u_int qlimit;74struct pktcntr xmit_cnt; /* transmitted packet counter */75struct pktcntr drop_cnt; /* dropped packet counter */7677/* codel, red and rio related info */78int qtype;79struct redstats red[3]; /* rio has 3 red stats */80struct codel_stats codel;81};8283/*84* FAIRQ_STATS_VERSION is defined in altq.h to work around issues stemming85* from mixing of public-API and internal bits in each scheduler-specific86* header.87*/8889#ifdef _KERNEL9091typedef struct fairq_bucket {92struct fairq_bucket *next; /* circular list */93struct fairq_bucket *prev; /* circular list */94class_queue_t queue; /* the actual queue */95uint64_t bw_bytes; /* statistics used to calculate bw */96uint64_t bw_delta; /* statistics used to calculate bw */97uint64_t last_time;98int in_use;99} fairq_bucket_t;100101struct fairq_class {102uint32_t cl_handle; /* class handle */103u_int cl_nbuckets; /* (power of 2) */104u_int cl_nbucket_mask; /* bucket mask */105fairq_bucket_t *cl_buckets;106fairq_bucket_t *cl_head; /* head of circular bucket list */107fairq_bucket_t *cl_polled;108union {109struct red *cl_red; /* RED state */110struct codel *cl_codel; /* CoDel state */111} cl_aqm;112#define cl_red cl_aqm.cl_red113#define cl_codel cl_aqm.cl_codel114u_int cl_hogs_m1;115u_int cl_lssc_m1;116u_int cl_bandwidth;117uint64_t cl_bw_bytes;118uint64_t cl_bw_delta;119uint64_t cl_last_time;120int cl_qtype; /* rollup */121int cl_qlimit;122int cl_pri; /* priority */123int cl_flags; /* class flags */124struct fairq_if *cl_pif; /* back pointer to pif */125struct altq_pktattr *cl_pktattr; /* saved header used by ECN */126127/* round robin index */128129/* statistics */130struct pktcntr cl_xmitcnt; /* transmitted packet counter */131struct pktcntr cl_dropcnt; /* dropped packet counter */132};133134/*135* fairq interface state136*/137struct fairq_if {138struct fairq_if *pif_next; /* interface state list */139struct ifaltq *pif_ifq; /* backpointer to ifaltq */140u_int pif_bandwidth; /* link bandwidth in bps */141int pif_maxpri; /* max priority in use */142struct fairq_class *pif_poll_cache;/* cached poll */143struct fairq_class *pif_default; /* default class */144struct fairq_class *pif_classes[FAIRQ_MAXPRI]; /* classes */145};146147#endif /* _KERNEL */148149#endif /* _ALTQ_ALTQ_FAIRQ_H_ */150151152