1126385Smlaier/* $FreeBSD$ */ 2126385Smlaier/* $KAME: altq_cbq.h,v 1.10 2003/08/20 23:30:23 itojun Exp $ */ 3126385Smlaier 4126385Smlaier/* 5126385Smlaier * Copyright (c) Sun Microsystems, Inc. 1993-1998 All rights reserved. 6126385Smlaier * 7126385Smlaier * Redistribution and use in source and binary forms, with or without 8126385Smlaier * modification, are permitted provided that the following conditions 9126385Smlaier * are met: 10126385Smlaier * 11126385Smlaier * 1. Redistributions of source code must retain the above copyright 12126385Smlaier * notice, this list of conditions and the following disclaimer. 13126385Smlaier * 14126385Smlaier * 2. Redistributions in binary form must reproduce the above copyright 15126385Smlaier * notice, this list of conditions and the following disclaimer in the 16126385Smlaier * documentation and/or other materials provided with the distribution. 17126385Smlaier * 18126385Smlaier * 3. All advertising materials mentioning features or use of this software 19126385Smlaier * must display the following acknowledgement: 20126385Smlaier * This product includes software developed by the SMCC Technology 21126385Smlaier * Development Group at Sun Microsystems, Inc. 22126385Smlaier * 23126385Smlaier * 4. The name of the Sun Microsystems, Inc nor may not be used to endorse or 24126385Smlaier * promote products derived from this software without specific prior 25126385Smlaier * written permission. 26126385Smlaier * 27126385Smlaier * SUN MICROSYSTEMS DOES NOT CLAIM MERCHANTABILITY OF THIS SOFTWARE OR THE 28126385Smlaier * SUITABILITY OF THIS SOFTWARE FOR ANY PARTICULAR PURPOSE. The software is 29126385Smlaier * provided "as is" without express or implied warranty of any kind. 30126385Smlaier * 31126385Smlaier * These notices must be retained in any copies of any part of this software. 32126385Smlaier */ 33126385Smlaier 34126385Smlaier#ifndef _ALTQ_ALTQ_CBQ_H_ 35126385Smlaier#define _ALTQ_ALTQ_CBQ_H_ 36126385Smlaier 37126385Smlaier#include <altq/altq.h> 38126385Smlaier#include <altq/altq_rmclass.h> 39126385Smlaier#include <altq/altq_red.h> 40126385Smlaier#include <altq/altq_rio.h> 41126385Smlaier 42126385Smlaier/* #pragma ident "@(#)cbq.h 1.18 98/05/13 SMI" */ 43126385Smlaier 44126385Smlaier#ifdef __cplusplus 45126385Smlaierextern "C" { 46126385Smlaier#endif 47126385Smlaier 48126385Smlaier/* 49126385Smlaier * Define a well known class handles 50126385Smlaier */ 51126385Smlaier#define NULL_CLASS_HANDLE 0xffffffff 52126385Smlaier#define ROOT_CLASS_HANDLE 0xfffffffe 53126385Smlaier#define DEFAULT_CLASS_HANDLE 0xfffffffd 54126385Smlaier#ifdef ALTQ3_COMPAT 55126385Smlaier#define CTL_CLASS_HANDLE 0xfffffffc 56126385Smlaier#endif 57126385Smlaier 58126385Smlaier/* class flags shoud be same as class flags in rm_class.h */ 59126385Smlaier#define CBQCLF_RED 0x0001 /* use RED */ 60126385Smlaier#define CBQCLF_ECN 0x0002 /* use RED/ECN */ 61126385Smlaier#define CBQCLF_RIO 0x0004 /* use RIO */ 62126385Smlaier#define CBQCLF_FLOWVALVE 0x0008 /* use flowvalve (aka penalty-box) */ 63126385Smlaier#define CBQCLF_CLEARDSCP 0x0010 /* clear diffserv codepoint */ 64126385Smlaier#define CBQCLF_BORROW 0x0020 /* borrow from parent */ 65126385Smlaier 66126385Smlaier/* class flags only for root class */ 67126385Smlaier#define CBQCLF_WRR 0x0100 /* weighted-round robin */ 68126385Smlaier#define CBQCLF_EFFICIENT 0x0200 /* work-conserving */ 69126385Smlaier 70126385Smlaier/* class flags for special classes */ 71126385Smlaier#define CBQCLF_ROOTCLASS 0x1000 /* root class */ 72126385Smlaier#define CBQCLF_DEFCLASS 0x2000 /* default class */ 73126385Smlaier#ifdef ALTQ3_COMPAT 74126385Smlaier#define CBQCLF_CTLCLASS 0x4000 /* control class */ 75126385Smlaier#endif 76126385Smlaier#define CBQCLF_CLASSMASK 0xf000 /* class mask */ 77126385Smlaier 78126385Smlaier#define CBQ_MAXQSIZE 200 79126385Smlaier#define CBQ_MAXPRI RM_MAXPRIO 80126385Smlaier 81126385Smlaiertypedef struct _cbq_class_stats_ { 82126385Smlaier u_int32_t handle; 83126385Smlaier u_int depth; 84126385Smlaier 85126385Smlaier struct pktcntr xmit_cnt; /* packets sent in this class */ 86126385Smlaier struct pktcntr drop_cnt; /* dropped packets */ 87126385Smlaier u_int over; /* # times went over limit */ 88126385Smlaier u_int borrows; /* # times tried to borrow */ 89126385Smlaier u_int overactions; /* # times invoked overlimit action */ 90126385Smlaier u_int delays; /* # times invoked delay actions */ 91126385Smlaier 92126385Smlaier /* other static class parameters useful for debugging */ 93126385Smlaier int priority; 94126385Smlaier int maxidle; 95126385Smlaier int minidle; 96126385Smlaier int offtime; 97126385Smlaier int qmax; 98126385Smlaier int ns_per_byte; 99126385Smlaier int wrr_allot; 100126385Smlaier 101126385Smlaier int qcnt; /* # packets in queue */ 102126385Smlaier int avgidle; 103126385Smlaier 104126385Smlaier /* red and rio related info */ 105126385Smlaier int qtype; 106126385Smlaier struct redstats red[3]; 107126385Smlaier} class_stats_t; 108126385Smlaier 109126385Smlaier#ifdef ALTQ3_COMPAT 110126385Smlaier/* 111126385Smlaier * Define structures associated with IOCTLS for cbq. 112126385Smlaier */ 113126385Smlaier 114126385Smlaier/* 115126385Smlaier * Define the CBQ interface structure. This must be included in all 116126385Smlaier * IOCTL's such that the CBQ driver may find the appropriate CBQ module 117126385Smlaier * associated with the network interface to be affected. 118126385Smlaier */ 119126385Smlaierstruct cbq_interface { 120126385Smlaier char cbq_ifacename[IFNAMSIZ]; 121126385Smlaier}; 122126385Smlaier 123126385Smlaiertypedef struct cbq_class_spec { 124126385Smlaier u_int priority; 125126385Smlaier u_int nano_sec_per_byte; 126126385Smlaier u_int maxq; 127126385Smlaier u_int maxidle; 128126385Smlaier int minidle; 129126385Smlaier u_int offtime; 130126385Smlaier u_int32_t parent_class_handle; 131126385Smlaier u_int32_t borrow_class_handle; 132126385Smlaier 133126385Smlaier u_int pktsize; 134126385Smlaier int flags; 135126385Smlaier} cbq_class_spec_t; 136126385Smlaier 137126385Smlaierstruct cbq_add_class { 138126385Smlaier struct cbq_interface cbq_iface; 139126385Smlaier 140126385Smlaier cbq_class_spec_t cbq_class; 141126385Smlaier u_int32_t cbq_class_handle; 142126385Smlaier}; 143126385Smlaier 144126385Smlaierstruct cbq_delete_class { 145126385Smlaier struct cbq_interface cbq_iface; 146126385Smlaier u_int32_t cbq_class_handle; 147126385Smlaier}; 148126385Smlaier 149126385Smlaierstruct cbq_modify_class { 150126385Smlaier struct cbq_interface cbq_iface; 151126385Smlaier 152126385Smlaier cbq_class_spec_t cbq_class; 153126385Smlaier u_int32_t cbq_class_handle; 154126385Smlaier}; 155126385Smlaier 156126385Smlaierstruct cbq_add_filter { 157126385Smlaier struct cbq_interface cbq_iface; 158126385Smlaier u_int32_t cbq_class_handle; 159126385Smlaier struct flow_filter cbq_filter; 160126385Smlaier 161126385Smlaier u_long cbq_filter_handle; 162126385Smlaier}; 163126385Smlaier 164126385Smlaierstruct cbq_delete_filter { 165126385Smlaier struct cbq_interface cbq_iface; 166126385Smlaier u_long cbq_filter_handle; 167126385Smlaier}; 168126385Smlaier 169126385Smlaier/* number of classes are returned in nclasses field */ 170126385Smlaierstruct cbq_getstats { 171126385Smlaier struct cbq_interface iface; 172126385Smlaier int nclasses; 173126385Smlaier class_stats_t *stats; 174126385Smlaier}; 175126385Smlaier 176126385Smlaier/* 177126385Smlaier * Define IOCTLs for CBQ. 178126385Smlaier */ 179126385Smlaier#define CBQ_IF_ATTACH _IOW('Q', 1, struct cbq_interface) 180126385Smlaier#define CBQ_IF_DETACH _IOW('Q', 2, struct cbq_interface) 181126385Smlaier#define CBQ_ENABLE _IOW('Q', 3, struct cbq_interface) 182126385Smlaier#define CBQ_DISABLE _IOW('Q', 4, struct cbq_interface) 183126385Smlaier#define CBQ_CLEAR_HIERARCHY _IOW('Q', 5, struct cbq_interface) 184126385Smlaier#define CBQ_ADD_CLASS _IOWR('Q', 7, struct cbq_add_class) 185126385Smlaier#define CBQ_DEL_CLASS _IOW('Q', 8, struct cbq_delete_class) 186126385Smlaier#define CBQ_MODIFY_CLASS _IOWR('Q', 9, struct cbq_modify_class) 187126385Smlaier#define CBQ_ADD_FILTER _IOWR('Q', 10, struct cbq_add_filter) 188126385Smlaier#define CBQ_DEL_FILTER _IOW('Q', 11, struct cbq_delete_filter) 189126385Smlaier#define CBQ_GETSTATS _IOWR('Q', 12, struct cbq_getstats) 190126385Smlaier#endif /* ALTQ3_COMPAT */ 191126385Smlaier 192126385Smlaier#ifdef _KERNEL 193126385Smlaier/* 194126385Smlaier * Define macros only good for kernel drivers and modules. 195126385Smlaier */ 196126385Smlaier#define CBQ_WATCHDOG (hz / 20) 197126385Smlaier#define CBQ_TIMEOUT 10 198126385Smlaier#define CBQ_LS_TIMEOUT (20 * hz / 1000) 199126385Smlaier 200126385Smlaier#define CBQ_MAX_CLASSES 256 201126385Smlaier 202126385Smlaier#ifdef ALTQ3_COMPAT 203126385Smlaier#define CBQ_MAX_FILTERS 256 204126385Smlaier 205126385Smlaier#define DISABLE 0x00 206126385Smlaier#define ENABLE 0x01 207126385Smlaier#endif /* ALTQ3_COMPAT */ 208126385Smlaier 209126385Smlaier/* 210126385Smlaier * Define State structures. 211126385Smlaier */ 212126385Smlaiertypedef struct cbqstate { 213126385Smlaier#ifdef ALTQ3_COMPAT 214126385Smlaier struct cbqstate *cbq_next; 215126385Smlaier#endif 216126385Smlaier int cbq_qlen; /* # of packets in cbq */ 217126385Smlaier struct rm_class *cbq_class_tbl[CBQ_MAX_CLASSES]; 218126385Smlaier 219126385Smlaier struct rm_ifdat ifnp; 220126385Smlaier struct callout cbq_callout; /* for timeouts */ 221126385Smlaier#ifdef ALTQ3_CLFIER_COMPAT 222126385Smlaier struct acc_classifier cbq_classifier; 223126385Smlaier#endif 224126385Smlaier} cbq_state_t; 225126385Smlaier 226126385Smlaier#endif /* _KERNEL */ 227126385Smlaier 228126385Smlaier#ifdef __cplusplus 229126385Smlaier} 230126385Smlaier#endif 231126385Smlaier 232126385Smlaier#endif /* !_ALTQ_ALTQ_CBQ_H_ */ 233