1/* 2 * Copyright (c) 2011-2012 Apple Inc. All rights reserved. 3 * 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 * 6 * This file contains Original Code and/or Modifications of Original Code 7 * as defined in and that are subject to the Apple Public Source License 8 * Version 2.0 (the 'License'). You may not use this file except in 9 * compliance with the License. The rights granted to you under the License 10 * may not be used to create, or enable the creation or redistribution of, 11 * unlawful or unlicensed copies of an Apple operating system, or to 12 * circumvent, violate, or enable the circumvention or violation of, any 13 * terms of an Apple operating system software license agreement. 14 * 15 * Please obtain a copy of the License at 16 * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 * 18 * The Original Code and all software distributed under the License are 19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 * Please see the License for the specific language governing rights and 24 * limitations under the License. 25 * 26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 */ 28 29/* 30 * Copyright (c) 2008 The DragonFly Project. All rights reserved. 31 * 32 * This code is derived from software contributed to The DragonFly Project 33 * by Matthew Dillon <dillon@backplane.com> 34 * 35 * Redistribution and use in source and binary forms, with or without 36 * modification, are permitted provided that the following conditions 37 * are met: 38 * 39 * 1. Redistributions of source code must retain the above copyright 40 * notice, this list of conditions and the following disclaimer. 41 * 2. Redistributions in binary form must reproduce the above copyright 42 * notice, this list of conditions and the following disclaimer in 43 * the documentation and/or other materials provided with the 44 * distribution. 45 * 3. Neither the name of The DragonFly Project nor the names of its 46 * contributors may be used to endorse or promote products derived 47 * from this software without specific, prior written permission. 48 * 49 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 50 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 51 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 52 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 53 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 54 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, 55 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 56 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 57 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 58 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 59 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 60 * SUCH DAMAGE. 61 * 62 * $DragonFly: src/sys/net/altq/altq_fairq.h,v 1.1 2008/04/06 18:58:15 dillon Exp $ 63 */ 64 65#ifndef _NET_PKTSCHED_PKTSCHED_FAIRQ_H_ 66#define _NET_PKTSCHED_PKTSCHED_FAIRQ_H_ 67 68#ifdef PRIVATE 69#include <net/pktsched/pktsched.h> 70#include <net/pktsched/pktsched_rmclass.h> 71#include <net/classq/classq.h> 72#include <net/classq/classq_red.h> 73#include <net/classq/classq_rio.h> 74#include <net/classq/classq_blue.h> 75#include <net/classq/classq_sfb.h> 76 77#ifdef __cplusplus 78extern "C" { 79#endif 80 81#define FAIRQ_MAX_BUCKETS 2048 /* maximum number of sorting buckets */ 82#define FAIRQ_MAXPRI RM_MAXPRIO 83#define FAIRQ_BITMAP_WIDTH (sizeof (fairq_bitmap_t) * 8) 84#define FAIRQ_BITMAP_MASK (FAIRQ_BITMAP_WIDTH - 1) 85 86/* fairq class flags */ 87#define FARF_RED 0x0001 /* use RED */ 88#define FARF_ECN 0x0002 /* use ECN with RED/BLUE/SFB */ 89#define FARF_RIO 0x0004 /* use RIO */ 90#define FARF_CLEARDSCP 0x0010 /* clear diffserv codepoint */ 91#define FARF_BLUE 0x0100 /* use BLUE */ 92#define FARF_SFB 0x0200 /* use SFB */ 93#define FARF_FLOWCTL 0x0400 /* enable flow control advisories */ 94#define FARF_DEFAULTCLASS 0x1000 /* default class */ 95#ifdef BSD_KERNEL_PRIVATE 96#define FARF_HAS_PACKETS 0x2000 /* might have queued packets */ 97#define FARF_LAZY 0x10000000 /* on-demand resource allocation */ 98#endif /* BSD_KERNEL_PRIVATE */ 99 100#define FARF_USERFLAGS \ 101 (FARF_RED | FARF_ECN | FARF_RIO | FARF_CLEARDSCP | \ 102 FARF_BLUE | FARF_SFB | FARF_FLOWCTL | FARF_DEFAULTCLASS) 103 104#ifdef BSD_KERNEL_PRIVATE 105#define FARF_BITS \ 106 "\020\1RED\2ECN\3RIO\5CLEARDSCP\11BLUE\12SFB\13FLOWCTL\15DEFAULT" \ 107 "\16HASPKTS\35LAZY" 108#else 109#define FARF_BITS \ 110 "\020\1RED\2ECN\3RIO\5CLEARDSCP\11BLUE\12SFB\13FLOWCTL\15DEFAULT" \ 111 "\16HASPKTS" 112#endif /* !BSD_KERNEL_PRIVATE */ 113 114typedef u_int32_t fairq_bitmap_t; 115 116struct fairq_classstats { 117 u_int32_t class_handle; 118 u_int32_t priority; 119 120 u_int32_t qlength; 121 u_int32_t qlimit; 122 struct pktcntr xmit_cnt; /* transmitted packet counter */ 123 struct pktcntr drop_cnt; /* dropped packet counter */ 124 125 /* RED, RIO, BLUE, SFB related info */ 126 classq_type_t qtype; 127 union { 128 /* RIO has 3 red stats */ 129 struct red_stats red[RIO_NDROPPREC]; 130 struct blue_stats blue; 131 struct sfb_stats sfb; 132 }; 133 classq_state_t qstate; 134}; 135 136#ifdef BSD_KERNEL_PRIVATE 137 138typedef struct fairq_bucket { 139 struct fairq_bucket *next; /* circular list */ 140 struct fairq_bucket *prev; /* circular list */ 141 class_queue_t queue; /* the actual queue */ 142 u_int64_t bw_bytes; /* statistics used to calculate bw */ 143 u_int64_t bw_delta; /* statistics used to calculate bw */ 144 u_int64_t last_time; 145 int in_use; 146} fairq_bucket_t; 147 148struct fairq_class { 149 u_int32_t cl_handle; /* class handle */ 150 u_int32_t cl_nbuckets; /* (power of 2) */ 151 u_int32_t cl_nbucket_mask; /* bucket mask */ 152 u_int32_t cl_qflags; /* class queue flags */ 153 fairq_bucket_t *cl_buckets; 154 fairq_bucket_t *cl_head; /* head of circular bucket list */ 155 fairq_bucket_t *cl_polled; 156 union { 157 void *ptr; 158 struct red *red; /* RED state */ 159 struct rio *rio; /* RIO state */ 160 struct blue *blue; /* BLUE state */ 161 struct sfb *sfb; /* SFB state */ 162 } cl_qalg; 163 u_int64_t cl_hogs_m1; 164 u_int64_t cl_lssc_m1; 165 u_int64_t cl_bandwidth; 166 u_int64_t cl_bw_current; 167 u_int64_t cl_bw_bytes; 168 u_int64_t cl_bw_delta; 169 u_int64_t cl_last_time; 170 classq_type_t cl_qtype; /* rollup */ 171 classq_state_t cl_qstate; /* state */ 172 int cl_qlimit; 173 int cl_pri; /* priority */ 174 int cl_flags; /* class flags */ 175 struct fairq_if *cl_fif; /* back pointer to fif */ 176 177 /* round robin index */ 178 179 /* statistics */ 180 struct pktcntr cl_xmitcnt; /* transmitted packet counter */ 181 struct pktcntr cl_dropcnt; /* dropped packet counter */ 182}; 183 184#define cl_red cl_qalg.red 185#define cl_rio cl_qalg.rio 186#define cl_blue cl_qalg.blue 187#define cl_sfb cl_qalg.sfb 188 189/* fairq_if flags */ 190#define FAIRQIFF_ALTQ 0x1 /* configured via PF/ALTQ */ 191 192/* 193 * fairq interface state 194 */ 195struct fairq_if { 196 struct ifclassq *fif_ifq; /* backpointer to ifclassq */ 197 int fif_maxpri; /* max priority in use */ 198 u_int32_t fif_flags; /* flags */ 199 struct fairq_class *fif_poll_cache; /* cached poll */ 200 struct fairq_class *fif_default; /* default class */ 201 struct fairq_class *fif_classes[FAIRQ_MAXPRI]; /* classes */ 202}; 203 204#define FAIRQIF_IFP(_fif) ((_fif)->fif_ifq->ifcq_ifp) 205 206struct if_ifclassq_stats; 207 208extern void fairq_init(void); 209extern struct fairq_if *fairq_alloc(struct ifnet *, int, boolean_t); 210extern int fairq_destroy(struct fairq_if *); 211extern void fairq_purge(struct fairq_if *); 212extern void fairq_event(struct fairq_if *, cqev_t); 213extern int fairq_add_queue(struct fairq_if *, int, u_int32_t, u_int64_t, 214 u_int32_t, int, u_int64_t, u_int64_t, u_int64_t, u_int64_t, u_int32_t, 215 struct fairq_class **); 216extern int fairq_remove_queue(struct fairq_if *, u_int32_t); 217extern int fairq_get_class_stats(struct fairq_if *, u_int32_t, 218 struct fairq_classstats *); 219extern int fairq_enqueue(struct fairq_if *, struct fairq_class *, 220 struct mbuf *, struct pf_mtag *); 221extern struct mbuf *fairq_dequeue(struct fairq_if *, cqdq_op_t); 222extern int fairq_setup_ifclassq(struct ifclassq *, u_int32_t); 223extern int fairq_teardown_ifclassq(struct ifclassq *ifq); 224extern int fairq_getqstats_ifclassq(struct ifclassq *, u_int32_t, 225 struct if_ifclassq_stats *); 226#endif /* BSD_KERNEL_PRIVATE */ 227#ifdef __cplusplus 228} 229#endif 230#endif /* PRIVATE */ 231#endif /* _NET_PKTSCHED_PKTSCHED_FAIRQ_H_ */ 232