xref: /openbmc/linux/include/net/codel_qdisc.h (revision 4f2c0a4acffbec01079c28f839422e64ddeff004)
1d068ca2aSMichal Kazior #ifndef __NET_SCHED_CODEL_QDISC_H
2d068ca2aSMichal Kazior #define __NET_SCHED_CODEL_QDISC_H
3d068ca2aSMichal Kazior 
4d068ca2aSMichal Kazior /*
5d068ca2aSMichal Kazior  * Codel - The Controlled-Delay Active Queue Management algorithm
6d068ca2aSMichal Kazior  *
7d068ca2aSMichal Kazior  *  Copyright (C) 2011-2012 Kathleen Nichols <nichols@pollere.com>
8d068ca2aSMichal Kazior  *  Copyright (C) 2011-2012 Van Jacobson <van@pollere.net>
9d068ca2aSMichal Kazior  *  Copyright (C) 2012 Michael D. Taht <dave.taht@bufferbloat.net>
10d068ca2aSMichal Kazior  *  Copyright (C) 2012,2015 Eric Dumazet <edumazet@google.com>
11d068ca2aSMichal Kazior  *
12d068ca2aSMichal Kazior  * Redistribution and use in source and binary forms, with or without
13d068ca2aSMichal Kazior  * modification, are permitted provided that the following conditions
14d068ca2aSMichal Kazior  * are met:
15d068ca2aSMichal Kazior  * 1. Redistributions of source code must retain the above copyright
16d068ca2aSMichal Kazior  *    notice, this list of conditions, and the following disclaimer,
17d068ca2aSMichal Kazior  *    without modification.
18d068ca2aSMichal Kazior  * 2. Redistributions in binary form must reproduce the above copyright
19d068ca2aSMichal Kazior  *    notice, this list of conditions and the following disclaimer in the
20d068ca2aSMichal Kazior  *    documentation and/or other materials provided with the distribution.
21d068ca2aSMichal Kazior  * 3. The names of the authors may not be used to endorse or promote products
22d068ca2aSMichal Kazior  *    derived from this software without specific prior written permission.
23d068ca2aSMichal Kazior  *
24d068ca2aSMichal Kazior  * Alternatively, provided that this notice is retained in full, this
25d068ca2aSMichal Kazior  * software may be distributed under the terms of the GNU General
26d068ca2aSMichal Kazior  * Public License ("GPL") version 2, in which case the provisions of the
27d068ca2aSMichal Kazior  * GPL apply INSTEAD OF those given above.
28d068ca2aSMichal Kazior  *
29d068ca2aSMichal Kazior  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
30d068ca2aSMichal Kazior  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
31d068ca2aSMichal Kazior  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
32d068ca2aSMichal Kazior  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
33d068ca2aSMichal Kazior  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
34d068ca2aSMichal Kazior  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
35d068ca2aSMichal Kazior  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
36d068ca2aSMichal Kazior  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
37d068ca2aSMichal Kazior  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38d068ca2aSMichal Kazior  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
39d068ca2aSMichal Kazior  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
40d068ca2aSMichal Kazior  * DAMAGE.
41d068ca2aSMichal Kazior  *
42d068ca2aSMichal Kazior  */
43d068ca2aSMichal Kazior 
44d068ca2aSMichal Kazior /* Controlling Queue Delay (CoDel) algorithm
45d068ca2aSMichal Kazior  * =========================================
46d068ca2aSMichal Kazior  * Source : Kathleen Nichols and Van Jacobson
47d068ca2aSMichal Kazior  * http://queue.acm.org/detail.cfm?id=2209336
48d068ca2aSMichal Kazior  *
49d068ca2aSMichal Kazior  * Implemented on linux by Dave Taht and Eric Dumazet
50d068ca2aSMichal Kazior  */
51d068ca2aSMichal Kazior 
52*949d6b40SJakub Kicinski #include <net/codel.h>
53e6e59044SJakub Kicinski #include <net/pkt_sched.h>
54e6e59044SJakub Kicinski 
55d068ca2aSMichal Kazior /* Qdiscs using codel plugin must use codel_skb_cb in their own cb[] */
56d068ca2aSMichal Kazior struct codel_skb_cb {
57d068ca2aSMichal Kazior 	codel_time_t enqueue_time;
58008830bcSEric Dumazet 	unsigned int mem_usage;
59d068ca2aSMichal Kazior };
60d068ca2aSMichal Kazior 
get_codel_cb(const struct sk_buff * skb)61d068ca2aSMichal Kazior static struct codel_skb_cb *get_codel_cb(const struct sk_buff *skb)
62d068ca2aSMichal Kazior {
63d068ca2aSMichal Kazior 	qdisc_cb_private_validate(skb, sizeof(struct codel_skb_cb));
64d068ca2aSMichal Kazior 	return (struct codel_skb_cb *)qdisc_skb_cb(skb)->data;
65d068ca2aSMichal Kazior }
66d068ca2aSMichal Kazior 
codel_get_enqueue_time(const struct sk_buff * skb)67d068ca2aSMichal Kazior static codel_time_t codel_get_enqueue_time(const struct sk_buff *skb)
68d068ca2aSMichal Kazior {
69d068ca2aSMichal Kazior 	return get_codel_cb(skb)->enqueue_time;
70d068ca2aSMichal Kazior }
71d068ca2aSMichal Kazior 
codel_set_enqueue_time(struct sk_buff * skb)72d068ca2aSMichal Kazior static void codel_set_enqueue_time(struct sk_buff *skb)
73d068ca2aSMichal Kazior {
74d068ca2aSMichal Kazior 	get_codel_cb(skb)->enqueue_time = codel_get_time();
75d068ca2aSMichal Kazior }
76d068ca2aSMichal Kazior 
77d068ca2aSMichal Kazior #endif
78