15950bf01SMatthew Dillon /* 25950bf01SMatthew Dillon * Copyright (c) 2008 The DragonFly Project. All rights reserved. 35950bf01SMatthew Dillon * 45950bf01SMatthew Dillon * This code is derived from software contributed to The DragonFly Project 55950bf01SMatthew Dillon * by Matthew Dillon <dillon@backplane.com> 65950bf01SMatthew Dillon * 75950bf01SMatthew Dillon * Redistribution and use in source and binary forms, with or without 85950bf01SMatthew Dillon * modification, are permitted provided that the following conditions 95950bf01SMatthew Dillon * are met: 105950bf01SMatthew Dillon * 115950bf01SMatthew Dillon * 1. Redistributions of source code must retain the above copyright 125950bf01SMatthew Dillon * notice, this list of conditions and the following disclaimer. 135950bf01SMatthew Dillon * 2. Redistributions in binary form must reproduce the above copyright 145950bf01SMatthew Dillon * notice, this list of conditions and the following disclaimer in 155950bf01SMatthew Dillon * the documentation and/or other materials provided with the 165950bf01SMatthew Dillon * distribution. 175950bf01SMatthew Dillon * 3. Neither the name of The DragonFly Project nor the names of its 185950bf01SMatthew Dillon * contributors may be used to endorse or promote products derived 195950bf01SMatthew Dillon * from this software without specific, prior written permission. 205950bf01SMatthew Dillon * 215950bf01SMatthew Dillon * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 225950bf01SMatthew Dillon * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 235950bf01SMatthew Dillon * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 245950bf01SMatthew Dillon * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 255950bf01SMatthew Dillon * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 265950bf01SMatthew Dillon * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, 275950bf01SMatthew Dillon * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 285950bf01SMatthew Dillon * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 295950bf01SMatthew Dillon * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 305950bf01SMatthew Dillon * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 315950bf01SMatthew Dillon * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 325950bf01SMatthew Dillon * SUCH DAMAGE. 335950bf01SMatthew Dillon * 345950bf01SMatthew Dillon * $DragonFly: src/sys/net/altq/altq_fairq.h,v 1.1 2008/04/06 18:58:15 dillon Exp $ 355950bf01SMatthew Dillon */ 365950bf01SMatthew Dillon 375950bf01SMatthew Dillon #ifndef _ALTQ_ALTQ_FAIRQ_H_ 385950bf01SMatthew Dillon #define _ALTQ_ALTQ_FAIRQ_H_ 395950bf01SMatthew Dillon 405950bf01SMatthew Dillon #include <net/altq/altq.h> 415950bf01SMatthew Dillon #include <net/altq/altq_classq.h> 425950bf01SMatthew Dillon #include <net/altq/altq_red.h> 435950bf01SMatthew Dillon #include <net/altq/altq_rio.h> 445950bf01SMatthew Dillon #include <net/altq/altq_rmclass.h> 455950bf01SMatthew Dillon 465950bf01SMatthew Dillon #define FAIRQ_MAX_BUCKETS 2048 /* maximum number of sorting buckets */ 475950bf01SMatthew Dillon #define FAIRQ_MAXPRI RM_MAXPRIO 485950bf01SMatthew Dillon #define FAIRQ_BITMAP_WIDTH (sizeof(fairq_bitmap_t)*8) 495950bf01SMatthew Dillon #define FAIRQ_BITMAP_MASK (FAIRQ_BITMAP_WIDTH - 1) 505950bf01SMatthew Dillon 515950bf01SMatthew Dillon /* fairq class flags */ 525950bf01SMatthew Dillon #define FARF_RED 0x0001 /* use RED */ 535950bf01SMatthew Dillon #define FARF_ECN 0x0002 /* use RED/ECN */ 545950bf01SMatthew Dillon #define FARF_RIO 0x0004 /* use RIO */ 555950bf01SMatthew Dillon #define FARF_CLEARDSCP 0x0010 /* clear diffserv codepoint */ 565950bf01SMatthew Dillon #define FARF_DEFAULTCLASS 0x1000 /* default class */ 575950bf01SMatthew Dillon 585950bf01SMatthew Dillon #define FARF_HAS_PACKETS 0x2000 /* might have queued packets */ 595950bf01SMatthew Dillon 605950bf01SMatthew Dillon #define FARF_USERFLAGS (FARF_RED|FARF_ECN|FARF_RIO|FARF_CLEARDSCP| \ 615950bf01SMatthew Dillon FARF_DEFAULTCLASS) 625950bf01SMatthew Dillon 635950bf01SMatthew Dillon /* special class handles */ 645950bf01SMatthew Dillon #define FAIRQ_NULLCLASS_HANDLE 0 655950bf01SMatthew Dillon 665950bf01SMatthew Dillon typedef u_int fairq_bitmap_t; 675950bf01SMatthew Dillon 685950bf01SMatthew Dillon struct fairq_classstats { 695950bf01SMatthew Dillon uint32_t class_handle; 705950bf01SMatthew Dillon 715950bf01SMatthew Dillon u_int qlength; 725950bf01SMatthew Dillon u_int qlimit; 735950bf01SMatthew Dillon struct pktcntr xmit_cnt; /* transmitted packet counter */ 745950bf01SMatthew Dillon struct pktcntr drop_cnt; /* dropped packet counter */ 755950bf01SMatthew Dillon 765950bf01SMatthew Dillon /* red and rio related info */ 775950bf01SMatthew Dillon int qtype; 785950bf01SMatthew Dillon struct redstats red[3]; /* rio has 3 red stats */ 795950bf01SMatthew Dillon }; 805950bf01SMatthew Dillon 815950bf01SMatthew Dillon #ifdef _KERNEL 825950bf01SMatthew Dillon 835950bf01SMatthew Dillon typedef struct fairq_bucket { 845950bf01SMatthew Dillon struct fairq_bucket *next; /* circular list */ 855950bf01SMatthew Dillon struct fairq_bucket *prev; /* circular list */ 865950bf01SMatthew Dillon class_queue_t queue; /* the actual queue */ 875950bf01SMatthew Dillon uint64_t bw_bytes; /* statistics used to calculate bw */ 885950bf01SMatthew Dillon uint64_t bw_delta; /* statistics used to calculate bw */ 895950bf01SMatthew Dillon uint64_t last_time; 905950bf01SMatthew Dillon int in_use; 915950bf01SMatthew Dillon } fairq_bucket_t; 925950bf01SMatthew Dillon 935950bf01SMatthew Dillon struct fairq_class { 945950bf01SMatthew Dillon uint32_t cl_handle; /* class handle */ 955950bf01SMatthew Dillon u_int cl_nbuckets; /* (power of 2) */ 965950bf01SMatthew Dillon u_int cl_nbucket_mask; /* bucket mask */ 975950bf01SMatthew Dillon fairq_bucket_t *cl_buckets; 985950bf01SMatthew Dillon fairq_bucket_t *cl_head; /* head of circular bucket list */ 995950bf01SMatthew Dillon struct red *cl_red; /* RED state */ 100*630fbdc5SMatthew Dillon int cl_advanced; /* already advanced head */ 101*630fbdc5SMatthew Dillon uint64_t cl_hogs_m1; 102*630fbdc5SMatthew Dillon uint64_t cl_lssc_m1; 103*630fbdc5SMatthew Dillon uint64_t cl_bandwidth; 104*630fbdc5SMatthew Dillon uint64_t cl_bw_current; 1055950bf01SMatthew Dillon uint64_t cl_bw_bytes; 1065950bf01SMatthew Dillon uint64_t cl_bw_delta; 1075950bf01SMatthew Dillon uint64_t cl_last_time; 1085950bf01SMatthew Dillon int cl_qtype; /* rollup */ 1095950bf01SMatthew Dillon int cl_qlimit; 1105950bf01SMatthew Dillon int cl_pri; /* priority */ 1115950bf01SMatthew Dillon int cl_flags; /* class flags */ 1125950bf01SMatthew Dillon struct fairq_if *cl_pif; /* back pointer to pif */ 1135950bf01SMatthew Dillon struct altq_pktattr *cl_pktattr; /* saved header used by ECN */ 1145950bf01SMatthew Dillon 1155950bf01SMatthew Dillon /* round robin index */ 1165950bf01SMatthew Dillon 1175950bf01SMatthew Dillon /* statistics */ 1185950bf01SMatthew Dillon struct pktcntr cl_xmitcnt; /* transmitted packet counter */ 1195950bf01SMatthew Dillon struct pktcntr cl_dropcnt; /* dropped packet counter */ 1205950bf01SMatthew Dillon }; 1215950bf01SMatthew Dillon 1225950bf01SMatthew Dillon /* 1235950bf01SMatthew Dillon * fairq interface state 1245950bf01SMatthew Dillon */ 1255950bf01SMatthew Dillon struct fairq_if { 1265950bf01SMatthew Dillon struct fairq_if *pif_next; /* interface state list */ 1275950bf01SMatthew Dillon struct ifaltq *pif_ifq; /* backpointer to ifaltq */ 1285950bf01SMatthew Dillon u_int pif_bandwidth; /* link bandwidth in bps */ 1295950bf01SMatthew Dillon int pif_maxpri; /* max priority in use */ 1305950bf01SMatthew Dillon struct fairq_class *pif_poll_cache;/* cached poll */ 1315950bf01SMatthew Dillon struct fairq_class *pif_default; /* default class */ 1325950bf01SMatthew Dillon struct fairq_class *pif_classes[FAIRQ_MAXPRI]; /* classes */ 1335950bf01SMatthew Dillon }; 1345950bf01SMatthew Dillon 1355950bf01SMatthew Dillon #endif /* _KERNEL */ 1365950bf01SMatthew Dillon 1375950bf01SMatthew Dillon #endif /* _ALTQ_ALTQ_FAIRQ_H_ */ 138