altq_fairq.h revision 298091
133965Sjdp/*
277298Sobrien * Copyright (c) 2008 The DragonFly Project.  All rights reserved.
389857Sobrien *
4218822Sdim * This code is derived from software contributed to The DragonFly Project
5218822Sdim * by Matthew Dillon <dillon@backplane.com>
668765Sobrien *
7218822Sdim * Redistribution and use in source and binary forms, with or without
868765Sobrien * modification, are permitted provided that the following conditions
933965Sjdp * are met:
1033965Sjdp *
1133965Sjdp * 1. Redistributions of source code must retain the above copyright
1233965Sjdp *    notice, this list of conditions and the following disclaimer.
1333965Sjdp * 2. Redistributions in binary form must reproduce the above copyright
1433965Sjdp *    notice, this list of conditions and the following disclaimer in
1533965Sjdp *    the documentation and/or other materials provided with the
1633965Sjdp *    distribution.
1733965Sjdp * 3. Neither the name of The DragonFly Project nor the names of its
1833965Sjdp *    contributors may be used to endorse or promote products derived
1933965Sjdp *    from this software without specific, prior written permission.
2033965Sjdp *
2133965Sjdp * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
2233965Sjdp * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
2333965Sjdp * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
2433965Sjdp * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
25218822Sdim * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26218822Sdim * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
27218822Sdim * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
2833965Sjdp * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
2933965Sjdp * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
3033965Sjdp * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
3133965Sjdp * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3233965Sjdp * SUCH DAMAGE.
33218822Sdim *
3489857Sobrien * $DragonFly: src/sys/net/altq/altq_fairq.h,v 1.1 2008/04/06 18:58:15 dillon Exp $
3589857Sobrien * $FreeBSD: stable/10/sys/contrib/altq/altq/altq_fairq.h 298091 2016-04-16 02:11:04Z loos $
3660484Sobrien */
3733965Sjdp
3833965Sjdp#ifndef _ALTQ_ALTQ_FAIRQ_H_
3933965Sjdp#define	_ALTQ_ALTQ_FAIRQ_H_
4033965Sjdp
4133965Sjdp#include <altq/altq.h>
4233965Sjdp#include <altq/altq_classq.h>
4333965Sjdp#include <altq/altq_red.h>
4433965Sjdp#include <altq/altq_rio.h>
4533965Sjdp#include <altq/altq_rmclass.h>
4633965Sjdp
4733965Sjdp#define	FAIRQ_MAX_BUCKETS	2048	/* maximum number of sorting buckets */
4833965Sjdp#define	FAIRQ_MAXPRI		RM_MAXPRIO
4933965Sjdp#define FAIRQ_BITMAP_WIDTH	(sizeof(fairq_bitmap_t)*8)
5033965Sjdp#define FAIRQ_BITMAP_MASK	(FAIRQ_BITMAP_WIDTH - 1)
5133965Sjdp
5233965Sjdp/* fairq class flags */
5333965Sjdp#define	FARF_RED		0x0001	/* use RED */
5433965Sjdp#define	FARF_ECN		0x0002  /* use RED/ECN */
5533965Sjdp#define	FARF_RIO		0x0004  /* use RIO */
5633965Sjdp#define	FARF_CLEARDSCP		0x0010  /* clear diffserv codepoint */
5768765Sobrien#define	FARF_DEFAULTCLASS	0x1000	/* default class */
5833965Sjdp
5968765Sobrien#define FARF_HAS_PACKETS	0x2000	/* might have queued packets */
6068765Sobrien
6168765Sobrien#define FARF_USERFLAGS		(FARF_RED|FARF_ECN|FARF_RIO|FARF_CLEARDSCP| \
6268765Sobrien				 FARF_DEFAULTCLASS)
6368765Sobrien
6468765Sobrien/* special class handles */
6568765Sobrien#define	FAIRQ_NULLCLASS_HANDLE	0
6677298Sobrien
6777298Sobrientypedef u_int	fairq_bitmap_t;
6877298Sobrien
6968765Sobrienstruct fairq_classstats {
7077298Sobrien	uint32_t		class_handle;
7177298Sobrien
7277298Sobrien	u_int			qlength;
7377298Sobrien	u_int			qlimit;
7477298Sobrien	struct pktcntr		xmit_cnt;  /* transmitted packet counter */
75218822Sdim	struct pktcntr		drop_cnt;  /* dropped packet counter */
7677298Sobrien
7777298Sobrien	/* red and rio related info */
7877298Sobrien	int			qtype;
7977298Sobrien	struct redstats		red[3];	/* rio has 3 red stats */
8077298Sobrien};
8168765Sobrien
8268765Sobrien#ifdef _KERNEL
8368765Sobrien
8468765Sobrientypedef struct fairq_bucket {
8568765Sobrien	struct fairq_bucket *next;	/* circular list */
8677298Sobrien	struct fairq_bucket *prev;	/* circular list */
8777298Sobrien	class_queue_t	queue;		/* the actual queue */
88218822Sdim	uint64_t	bw_bytes;	/* statistics used to calculate bw */
8977298Sobrien	uint64_t	bw_delta;	/* statistics used to calculate bw */
90218822Sdim	uint64_t	last_time;
9168765Sobrien	int		in_use;
92218822Sdim} fairq_bucket_t;
9368765Sobrien
9468765Sobrienstruct fairq_class {
9568765Sobrien	uint32_t	cl_handle;	/* class handle */
9668765Sobrien	u_int		cl_nbuckets;	/* (power of 2) */
9768765Sobrien	u_int		cl_nbucket_mask; /* bucket mask */
9877298Sobrien	fairq_bucket_t	*cl_buckets;
9968765Sobrien	fairq_bucket_t	*cl_head;	/* head of circular bucket list */
10068765Sobrien	fairq_bucket_t	*cl_polled;
10168765Sobrien	struct red	*cl_red;	/* RED state */
10268765Sobrien	u_int		cl_hogs_m1;
10368765Sobrien	u_int		cl_lssc_m1;
104218822Sdim	u_int		cl_bandwidth;
10568765Sobrien	uint64_t	cl_bw_bytes;
10668765Sobrien	uint64_t	cl_bw_delta;
10768765Sobrien	uint64_t	cl_last_time;
10868765Sobrien	int		cl_qtype;	/* rollup */
10968765Sobrien	int		cl_qlimit;
11068765Sobrien	int		cl_pri;		/* priority */
11168765Sobrien	int		cl_flags;	/* class flags */
11268765Sobrien	struct fairq_if	*cl_pif;	/* back pointer to pif */
11368765Sobrien	struct altq_pktattr *cl_pktattr; /* saved header used by ECN */
11468765Sobrien
11568765Sobrien	/* round robin index */
11668765Sobrien
11733965Sjdp	/* statistics */
11833965Sjdp	struct pktcntr  cl_xmitcnt;	/* transmitted packet counter */
11933965Sjdp	struct pktcntr  cl_dropcnt;	/* dropped packet counter */
12033965Sjdp};
12133965Sjdp
12233965Sjdp/*
123218822Sdim * fairq interface state
124218822Sdim */
125218822Sdimstruct fairq_if {
12633965Sjdp	struct fairq_if		*pif_next;	/* interface state list */
12733965Sjdp	struct ifaltq		*pif_ifq;	/* backpointer to ifaltq */
12833965Sjdp	u_int			pif_bandwidth;	/* link bandwidth in bps */
12933965Sjdp	int			pif_maxpri;	/* max priority in use */
13033965Sjdp	struct fairq_class	*pif_poll_cache;/* cached poll */
13133965Sjdp	struct fairq_class	*pif_default;	/* default class */
13233965Sjdp	struct fairq_class	*pif_classes[FAIRQ_MAXPRI]; /* classes */
13333965Sjdp};
13433965Sjdp
13533965Sjdp#endif /* _KERNEL */
13633965Sjdp
13733965Sjdp#endif /* _ALTQ_ALTQ_FAIRQ_H_ */
13833965Sjdp