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#ifndef _NET_PKTSCHED_PKTSCHED_TCQ_H_ 30#define _NET_PKTSCHED_PKTSCHED_TCQ_H_ 31 32#ifdef PRIVATE 33#include <net/pktsched/pktsched.h> 34#include <net/classq/classq.h> 35#include <net/classq/classq_red.h> 36#include <net/classq/classq_rio.h> 37#include <net/classq/classq_blue.h> 38#include <net/classq/classq_sfb.h> 39 40#ifdef __cplusplus 41extern "C" { 42#endif 43 44#define TCQ_MAXPRI 4 /* upper limit of the number of priorities */ 45 46/* tcq class flags */ 47#define TQCF_RED 0x0001 /* use RED */ 48#define TQCF_ECN 0x0002 /* use ECN with RED/BLUE/SFB */ 49#define TQCF_RIO 0x0004 /* use RIO */ 50#define TQCF_CLEARDSCP 0x0010 /* clear diffserv codepoint */ 51#define TQCF_BLUE 0x0100 /* use BLUE */ 52#define TQCF_SFB 0x0200 /* use SFB */ 53#define TQCF_FLOWCTL 0x0400 /* enable flow control advisories */ 54#define TQCF_DEFAULTCLASS 0x1000 /* default class */ 55#define TQCF_DELAYBASED 0x2000 /* queue sizing is delay based */ 56#ifdef BSD_KERNEL_PRIVATE 57#define TQCF_LAZY 0x10000000 /* on-demand resource allocation */ 58#endif /* BSD_KERNEL_PRIVATE */ 59 60#define TQCF_USERFLAGS \ 61 (TQCF_RED | TQCF_ECN | TQCF_RIO | TQCF_CLEARDSCP | TQCF_BLUE | \ 62 TQCF_SFB | TQCF_FLOWCTL | TQCF_DEFAULTCLASS) 63 64#ifdef BSD_KERNEL_PRIVATE 65#define TQCF_BITS \ 66 "\020\1RED\2ECN\3RIO\5CLEARDSCP\11BLUE\12SFB\13FLOWCTL\15DEFAULT" \ 67 "\35LAZY" 68#else 69#define TQCF_BITS \ 70 "\020\1RED\2ECN\3RIO\5CLEARDSCP\11BLUE\12SFB\13FLOWCTL" 71#endif /* !BSD_KERNEL_PRIVATE */ 72 73struct tcq_classstats { 74 u_int32_t class_handle; 75 u_int32_t priority; 76 77 u_int32_t qlength; 78 u_int32_t qlimit; 79 u_int32_t period; 80 struct pktcntr xmitcnt; /* transmitted packet counter */ 81 struct pktcntr dropcnt; /* dropped packet counter */ 82 83 /* RED, RIO, BLUE, SFB related info */ 84 classq_type_t qtype; 85 union { 86 /* RIO has 3 red stats */ 87 struct red_stats red[RIO_NDROPPREC]; 88 struct blue_stats blue; 89 struct sfb_stats sfb; 90 }; 91 classq_state_t qstate; 92}; 93 94#ifdef BSD_KERNEL_PRIVATE 95struct tcq_class { 96 u_int32_t cl_handle; /* class handle */ 97 class_queue_t cl_q; /* class queue structure */ 98 u_int32_t cl_qflags; /* class queue flags */ 99 union { 100 void *ptr; 101 struct red *red; /* RED state */ 102 struct rio *rio; /* RIO state */ 103 struct blue *blue; /* BLUE state */ 104 struct sfb *sfb; /* SFB state */ 105 } cl_qalg; 106 int32_t cl_pri; /* priority */ 107 u_int32_t cl_flags; /* class flags */ 108 struct tcq_if *cl_tif; /* back pointer to tif */ 109 110 /* statistics */ 111 u_int32_t cl_period; /* backlog period */ 112 struct pktcntr cl_xmitcnt; /* transmitted packet counter */ 113 struct pktcntr cl_dropcnt; /* dropped packet counter */ 114}; 115 116#define cl_red cl_qalg.red 117#define cl_rio cl_qalg.rio 118#define cl_blue cl_qalg.blue 119#define cl_sfb cl_qalg.sfb 120 121/* tcq_if flags */ 122#define TCQIFF_ALTQ 0x1 /* configured via PF/ALTQ */ 123 124/* 125 * tcq interface state 126 */ 127struct tcq_if { 128 struct ifclassq *tif_ifq; /* backpointer to ifclassq */ 129 int tif_maxpri; /* max priority in use */ 130 u_int32_t tif_flags; /* flags */ 131 u_int32_t tif_throttle; /* throttling level */ 132 struct tcq_class *tif_default; /* default class */ 133 struct tcq_class *tif_classes[TCQ_MAXPRI]; /* classes */ 134}; 135 136#define TCQIF_IFP(_tif) ((_tif)->tif_ifq->ifcq_ifp) 137 138struct if_ifclassq_stats; 139 140extern void tcq_init(void); 141extern struct tcq_if *tcq_alloc(struct ifnet *, int, boolean_t); 142extern int tcq_destroy(struct tcq_if *); 143extern void tcq_purge(struct tcq_if *); 144extern void tcq_event(struct tcq_if *, cqev_t); 145extern int tcq_add_queue(struct tcq_if *, int, u_int32_t, int, u_int32_t, 146 struct tcq_class **); 147extern int tcq_remove_queue(struct tcq_if *, u_int32_t); 148extern int tcq_get_class_stats(struct tcq_if *, u_int32_t, 149 struct tcq_classstats *); 150extern int tcq_enqueue(struct tcq_if *, struct tcq_class *, struct mbuf *, 151 struct pf_mtag *); 152extern struct mbuf *tcq_dequeue_tc(struct tcq_if *, mbuf_svc_class_t, 153 cqdq_op_t); 154extern int tcq_setup_ifclassq(struct ifclassq *, u_int32_t); 155extern int tcq_teardown_ifclassq(struct ifclassq *ifq); 156extern int tcq_getqstats_ifclassq(struct ifclassq *, u_int32_t qid, 157 struct if_ifclassq_stats *); 158#endif /* BSD_KERNEL_PRIVATE */ 159#ifdef __cplusplus 160} 161#endif 162#endif /* PRIVATE */ 163#endif /* _NET_PKTSCHED_PKTSCHED_TCQ_H_ */ 164