Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2)  * Codel - The Controlled-Delay Active Queue Management algorithm
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *  Copyright (C) 2011-2012 Kathleen Nichols <nichols@pollere.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *  Copyright (C) 2011-2012 Van Jacobson <van@pollere.net>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *  Implemented on linux by :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *  Copyright (C) 2012 Michael D. Taht <dave.taht@bufferbloat.net>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  *  Copyright (C) 2012,2015 Eric Dumazet <edumazet@google.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  * Redistribution and use in source and binary forms, with or without
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  * modification, are permitted provided that the following conditions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  * are met:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  * 1. Redistributions of source code must retain the above copyright
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15)  *    notice, this list of conditions, and the following disclaimer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16)  *    without modification.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17)  * 2. Redistributions in binary form must reproduce the above copyright
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)  *    notice, this list of conditions and the following disclaimer in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19)  *    documentation and/or other materials provided with the distribution.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20)  * 3. The names of the authors may not be used to endorse or promote products
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21)  *    derived from this software without specific prior written permission.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23)  * Alternatively, provided that this notice is retained in full, this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24)  * software may be distributed under the terms of the GNU General
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25)  * Public License ("GPL") version 2, in which case the provisions of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26)  * GPL apply INSTEAD OF those given above.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28)  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29)  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30)  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31)  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32)  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33)  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34)  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35)  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36)  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37)  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38)  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39)  * DAMAGE.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) #include <linux/skbuff.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) #include <linux/prefetch.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) #include <net/pkt_sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) #include <net/codel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) #include <net/codel_impl.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) #include <net/codel_qdisc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) #define DEFAULT_CODEL_LIMIT 1000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) struct codel_sched_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	struct codel_params	params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	struct codel_vars	vars;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	struct codel_stats	stats;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	u32			drop_overlimit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) /* This is the specific function called from codel_dequeue()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66)  * to dequeue a packet from queue. Note: backlog is handled in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67)  * codel, we dont need to reduce it here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) static struct sk_buff *dequeue_func(struct codel_vars *vars, void *ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	struct Qdisc *sch = ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	struct sk_buff *skb = __qdisc_dequeue_head(&sch->q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	if (skb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 		sch->qstats.backlog -= qdisc_pkt_len(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 		prefetch(&skb->end); /* we'll need skb_shinfo() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	return skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) static void drop_func(struct sk_buff *skb, void *ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	struct Qdisc *sch = ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	qdisc_qstats_drop(sch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) static struct sk_buff *codel_qdisc_dequeue(struct Qdisc *sch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	struct codel_sched_data *q = qdisc_priv(sch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	skb = codel_dequeue(sch, &sch->qstats.backlog, &q->params, &q->vars,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 			    &q->stats, qdisc_pkt_len, codel_get_enqueue_time,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 			    drop_func, dequeue_func);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	/* We cant call qdisc_tree_reduce_backlog() if our qlen is 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	 * or HTB crashes. Defer it for next round.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	if (q->stats.drop_count && sch->q.qlen) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 		qdisc_tree_reduce_backlog(sch, q->stats.drop_count, q->stats.drop_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 		q->stats.drop_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 		q->stats.drop_len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	if (skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 		qdisc_bstats_update(sch, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	return skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) static int codel_qdisc_enqueue(struct sk_buff *skb, struct Qdisc *sch,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 			       struct sk_buff **to_free)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	struct codel_sched_data *q;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	if (likely(qdisc_qlen(sch) < sch->limit)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 		codel_set_enqueue_time(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 		return qdisc_enqueue_tail(skb, sch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	q = qdisc_priv(sch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	q->drop_overlimit++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	return qdisc_drop(skb, sch, to_free);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) static const struct nla_policy codel_policy[TCA_CODEL_MAX + 1] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	[TCA_CODEL_TARGET]	= { .type = NLA_U32 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	[TCA_CODEL_LIMIT]	= { .type = NLA_U32 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	[TCA_CODEL_INTERVAL]	= { .type = NLA_U32 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	[TCA_CODEL_ECN]		= { .type = NLA_U32 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	[TCA_CODEL_CE_THRESHOLD]= { .type = NLA_U32 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) static int codel_change(struct Qdisc *sch, struct nlattr *opt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 			struct netlink_ext_ack *extack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	struct codel_sched_data *q = qdisc_priv(sch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	struct nlattr *tb[TCA_CODEL_MAX + 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	unsigned int qlen, dropped = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	if (!opt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	err = nla_parse_nested_deprecated(tb, TCA_CODEL_MAX, opt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 					  codel_policy, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	sch_tree_lock(sch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	if (tb[TCA_CODEL_TARGET]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 		u32 target = nla_get_u32(tb[TCA_CODEL_TARGET]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 		q->params.target = ((u64)target * NSEC_PER_USEC) >> CODEL_SHIFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	if (tb[TCA_CODEL_CE_THRESHOLD]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 		u64 val = nla_get_u32(tb[TCA_CODEL_CE_THRESHOLD]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 		q->params.ce_threshold = (val * NSEC_PER_USEC) >> CODEL_SHIFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	if (tb[TCA_CODEL_INTERVAL]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 		u32 interval = nla_get_u32(tb[TCA_CODEL_INTERVAL]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 		q->params.interval = ((u64)interval * NSEC_PER_USEC) >> CODEL_SHIFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	if (tb[TCA_CODEL_LIMIT])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 		sch->limit = nla_get_u32(tb[TCA_CODEL_LIMIT]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	if (tb[TCA_CODEL_ECN])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 		q->params.ecn = !!nla_get_u32(tb[TCA_CODEL_ECN]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	qlen = sch->q.qlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	while (sch->q.qlen > sch->limit) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 		struct sk_buff *skb = __qdisc_dequeue_head(&sch->q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 		dropped += qdisc_pkt_len(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 		qdisc_qstats_backlog_dec(sch, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 		rtnl_qdisc_drop(skb, sch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	qdisc_tree_reduce_backlog(sch, qlen - sch->q.qlen, dropped);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	sch_tree_unlock(sch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) static int codel_init(struct Qdisc *sch, struct nlattr *opt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 		      struct netlink_ext_ack *extack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	struct codel_sched_data *q = qdisc_priv(sch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	sch->limit = DEFAULT_CODEL_LIMIT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	codel_params_init(&q->params);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	codel_vars_init(&q->vars);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	codel_stats_init(&q->stats);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	q->params.mtu = psched_mtu(qdisc_dev(sch));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	if (opt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 		int err = codel_change(sch, opt, extack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 			return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	if (sch->limit >= 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 		sch->flags |= TCQ_F_CAN_BYPASS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 		sch->flags &= ~TCQ_F_CAN_BYPASS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) static int codel_dump(struct Qdisc *sch, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	struct codel_sched_data *q = qdisc_priv(sch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	struct nlattr *opts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	opts = nla_nest_start_noflag(skb, TCA_OPTIONS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	if (opts == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 		goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	if (nla_put_u32(skb, TCA_CODEL_TARGET,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 			codel_time_to_us(q->params.target)) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	    nla_put_u32(skb, TCA_CODEL_LIMIT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 			sch->limit) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	    nla_put_u32(skb, TCA_CODEL_INTERVAL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 			codel_time_to_us(q->params.interval)) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	    nla_put_u32(skb, TCA_CODEL_ECN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 			q->params.ecn))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 		goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	if (q->params.ce_threshold != CODEL_DISABLED_THRESHOLD &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	    nla_put_u32(skb, TCA_CODEL_CE_THRESHOLD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 			codel_time_to_us(q->params.ce_threshold)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 		goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	return nla_nest_end(skb, opts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) nla_put_failure:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	nla_nest_cancel(skb, opts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) static int codel_dump_stats(struct Qdisc *sch, struct gnet_dump *d)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	const struct codel_sched_data *q = qdisc_priv(sch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	struct tc_codel_xstats st = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 		.maxpacket	= q->stats.maxpacket,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 		.count		= q->vars.count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 		.lastcount	= q->vars.lastcount,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 		.drop_overlimit = q->drop_overlimit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 		.ldelay		= codel_time_to_us(q->vars.ldelay),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 		.dropping	= q->vars.dropping,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 		.ecn_mark	= q->stats.ecn_mark,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 		.ce_mark	= q->stats.ce_mark,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	if (q->vars.dropping) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 		codel_tdiff_t delta = q->vars.drop_next - codel_get_time();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 		if (delta >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 			st.drop_next = codel_time_to_us(delta);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 			st.drop_next = -codel_time_to_us(-delta);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	return gnet_stats_copy_app(d, &st, sizeof(st));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) static void codel_reset(struct Qdisc *sch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	struct codel_sched_data *q = qdisc_priv(sch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	qdisc_reset_queue(sch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	codel_vars_init(&q->vars);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) static struct Qdisc_ops codel_qdisc_ops __read_mostly = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	.id		=	"codel",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	.priv_size	=	sizeof(struct codel_sched_data),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	.enqueue	=	codel_qdisc_enqueue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	.dequeue	=	codel_qdisc_dequeue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	.peek		=	qdisc_peek_dequeued,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	.init		=	codel_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	.reset		=	codel_reset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	.change 	=	codel_change,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	.dump		=	codel_dump,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	.dump_stats	=	codel_dump_stats,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	.owner		=	THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) static int __init codel_module_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	return register_qdisc(&codel_qdisc_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) static void __exit codel_module_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	unregister_qdisc(&codel_qdisc_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) module_init(codel_module_init)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) module_exit(codel_module_exit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) MODULE_DESCRIPTION("Controlled Delay queue discipline");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) MODULE_AUTHOR("Dave Taht");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) MODULE_AUTHOR("Eric Dumazet");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) MODULE_LICENSE("Dual BSD/GPL");