xref: /openbmc/linux/net/sched/sch_sfb.c (revision 7ae9fb1b7ecbb5d85d07857943f677fd1a559b18)
1d2912cb1SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
2e13e02a3SEric Dumazet /*
3e13e02a3SEric Dumazet  * net/sched/sch_sfb.c	  Stochastic Fair Blue
4e13e02a3SEric Dumazet  *
5e13e02a3SEric Dumazet  * Copyright (c) 2008-2011 Juliusz Chroboczek <jch@pps.jussieu.fr>
6e13e02a3SEric Dumazet  * Copyright (c) 2011 Eric Dumazet <eric.dumazet@gmail.com>
7e13e02a3SEric Dumazet  *
8e13e02a3SEric Dumazet  * W. Feng, D. Kandlur, D. Saha, K. Shin. Blue:
9e13e02a3SEric Dumazet  * A New Class of Active Queue Management Algorithms.
10e13e02a3SEric Dumazet  * U. Michigan CSE-TR-387-99, April 1999.
11e13e02a3SEric Dumazet  *
12e13e02a3SEric Dumazet  * http://www.thefengs.com/wuchang/blue/CSE-TR-387-99.pdf
13e13e02a3SEric Dumazet  */
14e13e02a3SEric Dumazet 
15e13e02a3SEric Dumazet #include <linux/module.h>
16e13e02a3SEric Dumazet #include <linux/types.h>
17e13e02a3SEric Dumazet #include <linux/kernel.h>
18e13e02a3SEric Dumazet #include <linux/errno.h>
19e13e02a3SEric Dumazet #include <linux/skbuff.h>
20e13e02a3SEric Dumazet #include <linux/random.h>
2155667441SEric Dumazet #include <linux/siphash.h>
22e13e02a3SEric Dumazet #include <net/ip.h>
23e13e02a3SEric Dumazet #include <net/pkt_sched.h>
24cf1facdaSJiri Pirko #include <net/pkt_cls.h>
25e13e02a3SEric Dumazet #include <net/inet_ecn.h>
26e13e02a3SEric Dumazet 
27e13e02a3SEric Dumazet /*
28e13e02a3SEric Dumazet  * SFB uses two B[l][n] : L x N arrays of bins (L levels, N bins per level)
29e13e02a3SEric Dumazet  * This implementation uses L = 8 and N = 16
30e13e02a3SEric Dumazet  * This permits us to split one 32bit hash (provided per packet by rxhash or
31e13e02a3SEric Dumazet  * external classifier) into 8 subhashes of 4 bits.
32e13e02a3SEric Dumazet  */
33e13e02a3SEric Dumazet #define SFB_BUCKET_SHIFT 4
34e13e02a3SEric Dumazet #define SFB_NUMBUCKETS	(1 << SFB_BUCKET_SHIFT) /* N bins per Level */
35e13e02a3SEric Dumazet #define SFB_BUCKET_MASK (SFB_NUMBUCKETS - 1)
36e13e02a3SEric Dumazet #define SFB_LEVELS	(32 / SFB_BUCKET_SHIFT) /* L */
37e13e02a3SEric Dumazet 
38e13e02a3SEric Dumazet /* SFB algo uses a virtual queue, named "bin" */
39e13e02a3SEric Dumazet struct sfb_bucket {
40e13e02a3SEric Dumazet 	u16		qlen; /* length of virtual queue */
41e13e02a3SEric Dumazet 	u16		p_mark; /* marking probability */
42e13e02a3SEric Dumazet };
43e13e02a3SEric Dumazet 
44e13e02a3SEric Dumazet /* We use a double buffering right before hash change
45e13e02a3SEric Dumazet  * (Section 4.4 of SFB reference : moving hash functions)
46e13e02a3SEric Dumazet  */
47e13e02a3SEric Dumazet struct sfb_bins {
4855667441SEric Dumazet 	siphash_key_t	  perturbation; /* siphash key */
49e13e02a3SEric Dumazet 	struct sfb_bucket bins[SFB_LEVELS][SFB_NUMBUCKETS];
50e13e02a3SEric Dumazet };
51e13e02a3SEric Dumazet 
52e13e02a3SEric Dumazet struct sfb_sched_data {
53e13e02a3SEric Dumazet 	struct Qdisc	*qdisc;
5425d8c0d5SJohn Fastabend 	struct tcf_proto __rcu *filter_list;
556529eabaSJiri Pirko 	struct tcf_block *block;
56e13e02a3SEric Dumazet 	unsigned long	rehash_interval;
57e13e02a3SEric Dumazet 	unsigned long	warmup_time;	/* double buffering warmup time in jiffies */
58e13e02a3SEric Dumazet 	u32		max;
59e13e02a3SEric Dumazet 	u32		bin_size;	/* maximum queue length per bin */
60e13e02a3SEric Dumazet 	u32		increment;	/* d1 */
61e13e02a3SEric Dumazet 	u32		decrement;	/* d2 */
62e13e02a3SEric Dumazet 	u32		limit;		/* HARD maximal queue length */
63e13e02a3SEric Dumazet 	u32		penalty_rate;
64e13e02a3SEric Dumazet 	u32		penalty_burst;
65e13e02a3SEric Dumazet 	u32		tokens_avail;
66e13e02a3SEric Dumazet 	unsigned long	rehash_time;
67e13e02a3SEric Dumazet 	unsigned long	token_time;
68e13e02a3SEric Dumazet 
69e13e02a3SEric Dumazet 	u8		slot;		/* current active bins (0 or 1) */
70e13e02a3SEric Dumazet 	bool		double_buffering;
71e13e02a3SEric Dumazet 	struct sfb_bins bins[2];
72e13e02a3SEric Dumazet 
73e13e02a3SEric Dumazet 	struct {
74e13e02a3SEric Dumazet 		u32	earlydrop;
75e13e02a3SEric Dumazet 		u32	penaltydrop;
76e13e02a3SEric Dumazet 		u32	bucketdrop;
77e13e02a3SEric Dumazet 		u32	queuedrop;
78e13e02a3SEric Dumazet 		u32	childdrop;	/* drops in child qdisc */
79e13e02a3SEric Dumazet 		u32	marked;		/* ECN mark */
80e13e02a3SEric Dumazet 	} stats;
81e13e02a3SEric Dumazet };
82e13e02a3SEric Dumazet 
83e13e02a3SEric Dumazet /*
84e13e02a3SEric Dumazet  * Each queued skb might be hashed on one or two bins
85e13e02a3SEric Dumazet  * We store in skb_cb the two hash values.
86e13e02a3SEric Dumazet  * (A zero value means double buffering was not used)
87e13e02a3SEric Dumazet  */
88e13e02a3SEric Dumazet struct sfb_skb_cb {
89e13e02a3SEric Dumazet 	u32 hashes[2];
90e13e02a3SEric Dumazet };
91e13e02a3SEric Dumazet 
sfb_skb_cb(const struct sk_buff * skb)92e13e02a3SEric Dumazet static inline struct sfb_skb_cb *sfb_skb_cb(const struct sk_buff *skb)
93e13e02a3SEric Dumazet {
9416bda13dSDavid S. Miller 	qdisc_cb_private_validate(skb, sizeof(struct sfb_skb_cb));
95e13e02a3SEric Dumazet 	return (struct sfb_skb_cb *)qdisc_skb_cb(skb)->data;
96e13e02a3SEric Dumazet }
97e13e02a3SEric Dumazet 
98e13e02a3SEric Dumazet /*
99e13e02a3SEric Dumazet  * If using 'internal' SFB flow classifier, hash comes from skb rxhash
100e13e02a3SEric Dumazet  * If using external classifier, hash comes from the classid.
101e13e02a3SEric Dumazet  */
sfb_hash(const struct sk_buff * skb,u32 slot)102e13e02a3SEric Dumazet static u32 sfb_hash(const struct sk_buff *skb, u32 slot)
103e13e02a3SEric Dumazet {
104e13e02a3SEric Dumazet 	return sfb_skb_cb(skb)->hashes[slot];
105e13e02a3SEric Dumazet }
106e13e02a3SEric Dumazet 
107e13e02a3SEric Dumazet /* Probabilities are coded as Q0.16 fixed-point values,
108e13e02a3SEric Dumazet  * with 0xFFFF representing 65535/65536 (almost 1.0)
109e13e02a3SEric Dumazet  * Addition and subtraction are saturating in [0, 65535]
110e13e02a3SEric Dumazet  */
prob_plus(u32 p1,u32 p2)111e13e02a3SEric Dumazet static u32 prob_plus(u32 p1, u32 p2)
112e13e02a3SEric Dumazet {
113e13e02a3SEric Dumazet 	u32 res = p1 + p2;
114e13e02a3SEric Dumazet 
115e13e02a3SEric Dumazet 	return min_t(u32, res, SFB_MAX_PROB);
116e13e02a3SEric Dumazet }
117e13e02a3SEric Dumazet 
prob_minus(u32 p1,u32 p2)118e13e02a3SEric Dumazet static u32 prob_minus(u32 p1, u32 p2)
119e13e02a3SEric Dumazet {
120e13e02a3SEric Dumazet 	return p1 > p2 ? p1 - p2 : 0;
121e13e02a3SEric Dumazet }
122e13e02a3SEric Dumazet 
increment_one_qlen(u32 sfbhash,u32 slot,struct sfb_sched_data * q)123e13e02a3SEric Dumazet static void increment_one_qlen(u32 sfbhash, u32 slot, struct sfb_sched_data *q)
124e13e02a3SEric Dumazet {
125e13e02a3SEric Dumazet 	int i;
126e13e02a3SEric Dumazet 	struct sfb_bucket *b = &q->bins[slot].bins[0][0];
127e13e02a3SEric Dumazet 
128e13e02a3SEric Dumazet 	for (i = 0; i < SFB_LEVELS; i++) {
129e13e02a3SEric Dumazet 		u32 hash = sfbhash & SFB_BUCKET_MASK;
130e13e02a3SEric Dumazet 
131e13e02a3SEric Dumazet 		sfbhash >>= SFB_BUCKET_SHIFT;
132e13e02a3SEric Dumazet 		if (b[hash].qlen < 0xFFFF)
133e13e02a3SEric Dumazet 			b[hash].qlen++;
134e13e02a3SEric Dumazet 		b += SFB_NUMBUCKETS; /* next level */
135e13e02a3SEric Dumazet 	}
136e13e02a3SEric Dumazet }
137e13e02a3SEric Dumazet 
increment_qlen(const struct sfb_skb_cb * cb,struct sfb_sched_data * q)1389efd2329SToke Høiland-Jørgensen static void increment_qlen(const struct sfb_skb_cb *cb, struct sfb_sched_data *q)
139e13e02a3SEric Dumazet {
140e13e02a3SEric Dumazet 	u32 sfbhash;
141e13e02a3SEric Dumazet 
1429efd2329SToke Høiland-Jørgensen 	sfbhash = cb->hashes[0];
143e13e02a3SEric Dumazet 	if (sfbhash)
144e13e02a3SEric Dumazet 		increment_one_qlen(sfbhash, 0, q);
145e13e02a3SEric Dumazet 
1469efd2329SToke Høiland-Jørgensen 	sfbhash = cb->hashes[1];
147e13e02a3SEric Dumazet 	if (sfbhash)
148e13e02a3SEric Dumazet 		increment_one_qlen(sfbhash, 1, q);
149e13e02a3SEric Dumazet }
150e13e02a3SEric Dumazet 
decrement_one_qlen(u32 sfbhash,u32 slot,struct sfb_sched_data * q)151e13e02a3SEric Dumazet static void decrement_one_qlen(u32 sfbhash, u32 slot,
152e13e02a3SEric Dumazet 			       struct sfb_sched_data *q)
153e13e02a3SEric Dumazet {
154e13e02a3SEric Dumazet 	int i;
155e13e02a3SEric Dumazet 	struct sfb_bucket *b = &q->bins[slot].bins[0][0];
156e13e02a3SEric Dumazet 
157e13e02a3SEric Dumazet 	for (i = 0; i < SFB_LEVELS; i++) {
158e13e02a3SEric Dumazet 		u32 hash = sfbhash & SFB_BUCKET_MASK;
159e13e02a3SEric Dumazet 
160e13e02a3SEric Dumazet 		sfbhash >>= SFB_BUCKET_SHIFT;
161e13e02a3SEric Dumazet 		if (b[hash].qlen > 0)
162e13e02a3SEric Dumazet 			b[hash].qlen--;
163e13e02a3SEric Dumazet 		b += SFB_NUMBUCKETS; /* next level */
164e13e02a3SEric Dumazet 	}
165e13e02a3SEric Dumazet }
166e13e02a3SEric Dumazet 
decrement_qlen(const struct sk_buff * skb,struct sfb_sched_data * q)167e13e02a3SEric Dumazet static void decrement_qlen(const struct sk_buff *skb, struct sfb_sched_data *q)
168e13e02a3SEric Dumazet {
169e13e02a3SEric Dumazet 	u32 sfbhash;
170e13e02a3SEric Dumazet 
171e13e02a3SEric Dumazet 	sfbhash = sfb_hash(skb, 0);
172e13e02a3SEric Dumazet 	if (sfbhash)
173e13e02a3SEric Dumazet 		decrement_one_qlen(sfbhash, 0, q);
174e13e02a3SEric Dumazet 
175e13e02a3SEric Dumazet 	sfbhash = sfb_hash(skb, 1);
176e13e02a3SEric Dumazet 	if (sfbhash)
177e13e02a3SEric Dumazet 		decrement_one_qlen(sfbhash, 1, q);
178e13e02a3SEric Dumazet }
179e13e02a3SEric Dumazet 
decrement_prob(struct sfb_bucket * b,struct sfb_sched_data * q)180e13e02a3SEric Dumazet static void decrement_prob(struct sfb_bucket *b, struct sfb_sched_data *q)
181e13e02a3SEric Dumazet {
182e13e02a3SEric Dumazet 	b->p_mark = prob_minus(b->p_mark, q->decrement);
183e13e02a3SEric Dumazet }
184e13e02a3SEric Dumazet 
increment_prob(struct sfb_bucket * b,struct sfb_sched_data * q)185e13e02a3SEric Dumazet static void increment_prob(struct sfb_bucket *b, struct sfb_sched_data *q)
186e13e02a3SEric Dumazet {
187e13e02a3SEric Dumazet 	b->p_mark = prob_plus(b->p_mark, q->increment);
188e13e02a3SEric Dumazet }
189e13e02a3SEric Dumazet 
sfb_zero_all_buckets(struct sfb_sched_data * q)190e13e02a3SEric Dumazet static void sfb_zero_all_buckets(struct sfb_sched_data *q)
191e13e02a3SEric Dumazet {
192e13e02a3SEric Dumazet 	memset(&q->bins, 0, sizeof(q->bins));
193e13e02a3SEric Dumazet }
194e13e02a3SEric Dumazet 
195e13e02a3SEric Dumazet /*
196e13e02a3SEric Dumazet  * compute max qlen, max p_mark, and avg p_mark
197e13e02a3SEric Dumazet  */
sfb_compute_qlen(u32 * prob_r,u32 * avgpm_r,const struct sfb_sched_data * q)198e13e02a3SEric Dumazet static u32 sfb_compute_qlen(u32 *prob_r, u32 *avgpm_r, const struct sfb_sched_data *q)
199e13e02a3SEric Dumazet {
200e13e02a3SEric Dumazet 	int i;
201e13e02a3SEric Dumazet 	u32 qlen = 0, prob = 0, totalpm = 0;
202e13e02a3SEric Dumazet 	const struct sfb_bucket *b = &q->bins[q->slot].bins[0][0];
203e13e02a3SEric Dumazet 
204e13e02a3SEric Dumazet 	for (i = 0; i < SFB_LEVELS * SFB_NUMBUCKETS; i++) {
205e13e02a3SEric Dumazet 		if (qlen < b->qlen)
206e13e02a3SEric Dumazet 			qlen = b->qlen;
207e13e02a3SEric Dumazet 		totalpm += b->p_mark;
208e13e02a3SEric Dumazet 		if (prob < b->p_mark)
209e13e02a3SEric Dumazet 			prob = b->p_mark;
210e13e02a3SEric Dumazet 		b++;
211e13e02a3SEric Dumazet 	}
212e13e02a3SEric Dumazet 	*prob_r = prob;
213e13e02a3SEric Dumazet 	*avgpm_r = totalpm / (SFB_LEVELS * SFB_NUMBUCKETS);
214e13e02a3SEric Dumazet 	return qlen;
215e13e02a3SEric Dumazet }
216e13e02a3SEric Dumazet 
217e13e02a3SEric Dumazet 
sfb_init_perturbation(u32 slot,struct sfb_sched_data * q)218e13e02a3SEric Dumazet static void sfb_init_perturbation(u32 slot, struct sfb_sched_data *q)
219e13e02a3SEric Dumazet {
22055667441SEric Dumazet 	get_random_bytes(&q->bins[slot].perturbation,
22155667441SEric Dumazet 			 sizeof(q->bins[slot].perturbation));
222e13e02a3SEric Dumazet }
223e13e02a3SEric Dumazet 
sfb_swap_slot(struct sfb_sched_data * q)224e13e02a3SEric Dumazet static void sfb_swap_slot(struct sfb_sched_data *q)
225e13e02a3SEric Dumazet {
226e13e02a3SEric Dumazet 	sfb_init_perturbation(q->slot, q);
227e13e02a3SEric Dumazet 	q->slot ^= 1;
228e13e02a3SEric Dumazet 	q->double_buffering = false;
229e13e02a3SEric Dumazet }
230e13e02a3SEric Dumazet 
231e13e02a3SEric Dumazet /* Non elastic flows are allowed to use part of the bandwidth, expressed
232e13e02a3SEric Dumazet  * in "penalty_rate" packets per second, with "penalty_burst" burst
233e13e02a3SEric Dumazet  */
sfb_rate_limit(struct sk_buff * skb,struct sfb_sched_data * q)234e13e02a3SEric Dumazet static bool sfb_rate_limit(struct sk_buff *skb, struct sfb_sched_data *q)
235e13e02a3SEric Dumazet {
236e13e02a3SEric Dumazet 	if (q->penalty_rate == 0 || q->penalty_burst == 0)
237e13e02a3SEric Dumazet 		return true;
238e13e02a3SEric Dumazet 
239e13e02a3SEric Dumazet 	if (q->tokens_avail < 1) {
240e13e02a3SEric Dumazet 		unsigned long age = min(10UL * HZ, jiffies - q->token_time);
241e13e02a3SEric Dumazet 
242e13e02a3SEric Dumazet 		q->tokens_avail = (age * q->penalty_rate) / HZ;
243e13e02a3SEric Dumazet 		if (q->tokens_avail > q->penalty_burst)
244e13e02a3SEric Dumazet 			q->tokens_avail = q->penalty_burst;
245e13e02a3SEric Dumazet 		q->token_time = jiffies;
246e13e02a3SEric Dumazet 		if (q->tokens_avail < 1)
247e13e02a3SEric Dumazet 			return true;
248e13e02a3SEric Dumazet 	}
249e13e02a3SEric Dumazet 
250e13e02a3SEric Dumazet 	q->tokens_avail--;
251e13e02a3SEric Dumazet 	return false;
252e13e02a3SEric Dumazet }
253e13e02a3SEric Dumazet 
sfb_classify(struct sk_buff * skb,struct tcf_proto * fl,int * qerr,u32 * salt)25425d8c0d5SJohn Fastabend static bool sfb_classify(struct sk_buff *skb, struct tcf_proto *fl,
255e13e02a3SEric Dumazet 			 int *qerr, u32 *salt)
256e13e02a3SEric Dumazet {
257e13e02a3SEric Dumazet 	struct tcf_result res;
258e13e02a3SEric Dumazet 	int result;
259e13e02a3SEric Dumazet 
2603aa26055SDavide Caratti 	result = tcf_classify(skb, NULL, fl, &res, false);
261e13e02a3SEric Dumazet 	if (result >= 0) {
262e13e02a3SEric Dumazet #ifdef CONFIG_NET_CLS_ACT
263e13e02a3SEric Dumazet 		switch (result) {
264e13e02a3SEric Dumazet 		case TC_ACT_STOLEN:
265e13e02a3SEric Dumazet 		case TC_ACT_QUEUED:
266e25ea21fSJiri Pirko 		case TC_ACT_TRAP:
267e13e02a3SEric Dumazet 			*qerr = NET_XMIT_SUCCESS | __NET_XMIT_STOLEN;
268964201deSGustavo A. R. Silva 			fallthrough;
269e13e02a3SEric Dumazet 		case TC_ACT_SHOT:
270e13e02a3SEric Dumazet 			return false;
271e13e02a3SEric Dumazet 		}
272e13e02a3SEric Dumazet #endif
273e13e02a3SEric Dumazet 		*salt = TC_H_MIN(res.classid);
274e13e02a3SEric Dumazet 		return true;
275e13e02a3SEric Dumazet 	}
276e13e02a3SEric Dumazet 	return false;
277e13e02a3SEric Dumazet }
278e13e02a3SEric Dumazet 
sfb_enqueue(struct sk_buff * skb,struct Qdisc * sch,struct sk_buff ** to_free)279ac5c66f2SPetr Machata static int sfb_enqueue(struct sk_buff *skb, struct Qdisc *sch,
280520ac30fSEric Dumazet 		       struct sk_buff **to_free)
281e13e02a3SEric Dumazet {
282e13e02a3SEric Dumazet 
283e13e02a3SEric Dumazet 	struct sfb_sched_data *q = qdisc_priv(sch);
2842f09707dSToke Høiland-Jørgensen 	unsigned int len = qdisc_pkt_len(skb);
285e13e02a3SEric Dumazet 	struct Qdisc *child = q->qdisc;
28625d8c0d5SJohn Fastabend 	struct tcf_proto *fl;
2879efd2329SToke Høiland-Jørgensen 	struct sfb_skb_cb cb;
288e13e02a3SEric Dumazet 	int i;
289e13e02a3SEric Dumazet 	u32 p_min = ~0;
290e13e02a3SEric Dumazet 	u32 minqlen = ~0;
29163c0ad4dSTom Herbert 	u32 r, sfbhash;
29263c0ad4dSTom Herbert 	u32 slot = q->slot;
293e13e02a3SEric Dumazet 	int ret = NET_XMIT_SUCCESS | __NET_XMIT_BYPASS;
294e13e02a3SEric Dumazet 
295363437f4SEric Dumazet 	if (unlikely(sch->q.qlen >= q->limit)) {
29625331d6cSJohn Fastabend 		qdisc_qstats_overlimit(sch);
297363437f4SEric Dumazet 		q->stats.queuedrop++;
298363437f4SEric Dumazet 		goto drop;
299363437f4SEric Dumazet 	}
300363437f4SEric Dumazet 
301e13e02a3SEric Dumazet 	if (q->rehash_interval > 0) {
302e13e02a3SEric Dumazet 		unsigned long limit = q->rehash_time + q->rehash_interval;
303e13e02a3SEric Dumazet 
304e13e02a3SEric Dumazet 		if (unlikely(time_after(jiffies, limit))) {
305e13e02a3SEric Dumazet 			sfb_swap_slot(q);
306e13e02a3SEric Dumazet 			q->rehash_time = jiffies;
307e13e02a3SEric Dumazet 		} else if (unlikely(!q->double_buffering && q->warmup_time > 0 &&
308e13e02a3SEric Dumazet 				    time_after(jiffies, limit - q->warmup_time))) {
309e13e02a3SEric Dumazet 			q->double_buffering = true;
310e13e02a3SEric Dumazet 		}
311e13e02a3SEric Dumazet 	}
312e13e02a3SEric Dumazet 
31325d8c0d5SJohn Fastabend 	fl = rcu_dereference_bh(q->filter_list);
31425d8c0d5SJohn Fastabend 	if (fl) {
31563c0ad4dSTom Herbert 		u32 salt;
31663c0ad4dSTom Herbert 
317e13e02a3SEric Dumazet 		/* If using external classifiers, get result and record it. */
31825d8c0d5SJohn Fastabend 		if (!sfb_classify(skb, fl, &ret, &salt))
319e13e02a3SEric Dumazet 			goto other_drop;
32055667441SEric Dumazet 		sfbhash = siphash_1u32(salt, &q->bins[slot].perturbation);
321e13e02a3SEric Dumazet 	} else {
32255667441SEric Dumazet 		sfbhash = skb_get_hash_perturb(skb, &q->bins[slot].perturbation);
323e13e02a3SEric Dumazet 	}
324e13e02a3SEric Dumazet 
325e13e02a3SEric Dumazet 
326e13e02a3SEric Dumazet 	if (!sfbhash)
327e13e02a3SEric Dumazet 		sfbhash = 1;
328e13e02a3SEric Dumazet 	sfb_skb_cb(skb)->hashes[slot] = sfbhash;
329e13e02a3SEric Dumazet 
330e13e02a3SEric Dumazet 	for (i = 0; i < SFB_LEVELS; i++) {
331e13e02a3SEric Dumazet 		u32 hash = sfbhash & SFB_BUCKET_MASK;
332e13e02a3SEric Dumazet 		struct sfb_bucket *b = &q->bins[slot].bins[i][hash];
333e13e02a3SEric Dumazet 
334e13e02a3SEric Dumazet 		sfbhash >>= SFB_BUCKET_SHIFT;
335e13e02a3SEric Dumazet 		if (b->qlen == 0)
336e13e02a3SEric Dumazet 			decrement_prob(b, q);
337e13e02a3SEric Dumazet 		else if (b->qlen >= q->bin_size)
338e13e02a3SEric Dumazet 			increment_prob(b, q);
339e13e02a3SEric Dumazet 		if (minqlen > b->qlen)
340e13e02a3SEric Dumazet 			minqlen = b->qlen;
341e13e02a3SEric Dumazet 		if (p_min > b->p_mark)
342e13e02a3SEric Dumazet 			p_min = b->p_mark;
343e13e02a3SEric Dumazet 	}
344e13e02a3SEric Dumazet 
345e13e02a3SEric Dumazet 	slot ^= 1;
346e13e02a3SEric Dumazet 	sfb_skb_cb(skb)->hashes[slot] = 0;
347e13e02a3SEric Dumazet 
348363437f4SEric Dumazet 	if (unlikely(minqlen >= q->max)) {
34925331d6cSJohn Fastabend 		qdisc_qstats_overlimit(sch);
350e13e02a3SEric Dumazet 		q->stats.bucketdrop++;
351e13e02a3SEric Dumazet 		goto drop;
352e13e02a3SEric Dumazet 	}
353e13e02a3SEric Dumazet 
354e13e02a3SEric Dumazet 	if (unlikely(p_min >= SFB_MAX_PROB)) {
355e13e02a3SEric Dumazet 		/* Inelastic flow */
356e13e02a3SEric Dumazet 		if (q->double_buffering) {
35763c0ad4dSTom Herbert 			sfbhash = skb_get_hash_perturb(skb,
35855667441SEric Dumazet 			    &q->bins[slot].perturbation);
359e13e02a3SEric Dumazet 			if (!sfbhash)
360e13e02a3SEric Dumazet 				sfbhash = 1;
361e13e02a3SEric Dumazet 			sfb_skb_cb(skb)->hashes[slot] = sfbhash;
362e13e02a3SEric Dumazet 
363e13e02a3SEric Dumazet 			for (i = 0; i < SFB_LEVELS; i++) {
364e13e02a3SEric Dumazet 				u32 hash = sfbhash & SFB_BUCKET_MASK;
365e13e02a3SEric Dumazet 				struct sfb_bucket *b = &q->bins[slot].bins[i][hash];
366e13e02a3SEric Dumazet 
367e13e02a3SEric Dumazet 				sfbhash >>= SFB_BUCKET_SHIFT;
368e13e02a3SEric Dumazet 				if (b->qlen == 0)
369e13e02a3SEric Dumazet 					decrement_prob(b, q);
370e13e02a3SEric Dumazet 				else if (b->qlen >= q->bin_size)
371e13e02a3SEric Dumazet 					increment_prob(b, q);
372e13e02a3SEric Dumazet 			}
373e13e02a3SEric Dumazet 		}
374e13e02a3SEric Dumazet 		if (sfb_rate_limit(skb, q)) {
37525331d6cSJohn Fastabend 			qdisc_qstats_overlimit(sch);
376e13e02a3SEric Dumazet 			q->stats.penaltydrop++;
377e13e02a3SEric Dumazet 			goto drop;
378e13e02a3SEric Dumazet 		}
379e13e02a3SEric Dumazet 		goto enqueue;
380e13e02a3SEric Dumazet 	}
381e13e02a3SEric Dumazet 
382f743f16cSJason A. Donenfeld 	r = get_random_u16() & SFB_MAX_PROB;
383e13e02a3SEric Dumazet 
384e13e02a3SEric Dumazet 	if (unlikely(r < p_min)) {
385e13e02a3SEric Dumazet 		if (unlikely(p_min > SFB_MAX_PROB / 2)) {
386e13e02a3SEric Dumazet 			/* If we're marking that many packets, then either
387e13e02a3SEric Dumazet 			 * this flow is unresponsive, or we're badly congested.
388e13e02a3SEric Dumazet 			 * In either case, we want to start dropping packets.
389e13e02a3SEric Dumazet 			 */
390e13e02a3SEric Dumazet 			if (r < (p_min - SFB_MAX_PROB / 2) * 2) {
391e13e02a3SEric Dumazet 				q->stats.earlydrop++;
392e13e02a3SEric Dumazet 				goto drop;
393e13e02a3SEric Dumazet 			}
394e13e02a3SEric Dumazet 		}
395e13e02a3SEric Dumazet 		if (INET_ECN_set_ce(skb)) {
396e13e02a3SEric Dumazet 			q->stats.marked++;
397e13e02a3SEric Dumazet 		} else {
398e13e02a3SEric Dumazet 			q->stats.earlydrop++;
399e13e02a3SEric Dumazet 			goto drop;
400e13e02a3SEric Dumazet 		}
401e13e02a3SEric Dumazet 	}
402e13e02a3SEric Dumazet 
403e13e02a3SEric Dumazet enqueue:
4049efd2329SToke Høiland-Jørgensen 	memcpy(&cb, sfb_skb_cb(skb), sizeof(cb));
405ac5c66f2SPetr Machata 	ret = qdisc_enqueue(skb, child, to_free);
406e13e02a3SEric Dumazet 	if (likely(ret == NET_XMIT_SUCCESS)) {
4072f09707dSToke Høiland-Jørgensen 		sch->qstats.backlog += len;
408e13e02a3SEric Dumazet 		sch->q.qlen++;
4099efd2329SToke Høiland-Jørgensen 		increment_qlen(&cb, q);
410e13e02a3SEric Dumazet 	} else if (net_xmit_drop_count(ret)) {
411e13e02a3SEric Dumazet 		q->stats.childdrop++;
41225331d6cSJohn Fastabend 		qdisc_qstats_drop(sch);
413e13e02a3SEric Dumazet 	}
414e13e02a3SEric Dumazet 	return ret;
415e13e02a3SEric Dumazet 
416e13e02a3SEric Dumazet drop:
417520ac30fSEric Dumazet 	qdisc_drop(skb, sch, to_free);
418e13e02a3SEric Dumazet 	return NET_XMIT_CN;
419e13e02a3SEric Dumazet other_drop:
420e13e02a3SEric Dumazet 	if (ret & __NET_XMIT_BYPASS)
42125331d6cSJohn Fastabend 		qdisc_qstats_drop(sch);
422e13e02a3SEric Dumazet 	kfree_skb(skb);
423e13e02a3SEric Dumazet 	return ret;
424e13e02a3SEric Dumazet }
425e13e02a3SEric Dumazet 
sfb_dequeue(struct Qdisc * sch)426e13e02a3SEric Dumazet static struct sk_buff *sfb_dequeue(struct Qdisc *sch)
427e13e02a3SEric Dumazet {
428e13e02a3SEric Dumazet 	struct sfb_sched_data *q = qdisc_priv(sch);
429e13e02a3SEric Dumazet 	struct Qdisc *child = q->qdisc;
430e13e02a3SEric Dumazet 	struct sk_buff *skb;
431e13e02a3SEric Dumazet 
432e13e02a3SEric Dumazet 	skb = child->dequeue(q->qdisc);
433e13e02a3SEric Dumazet 
434e13e02a3SEric Dumazet 	if (skb) {
435e13e02a3SEric Dumazet 		qdisc_bstats_update(sch, skb);
4363d4357fbSWANG Cong 		qdisc_qstats_backlog_dec(sch, skb);
437e13e02a3SEric Dumazet 		sch->q.qlen--;
438e13e02a3SEric Dumazet 		decrement_qlen(skb, q);
439e13e02a3SEric Dumazet 	}
440e13e02a3SEric Dumazet 
441e13e02a3SEric Dumazet 	return skb;
442e13e02a3SEric Dumazet }
443e13e02a3SEric Dumazet 
sfb_peek(struct Qdisc * sch)444e13e02a3SEric Dumazet static struct sk_buff *sfb_peek(struct Qdisc *sch)
445e13e02a3SEric Dumazet {
446e13e02a3SEric Dumazet 	struct sfb_sched_data *q = qdisc_priv(sch);
447e13e02a3SEric Dumazet 	struct Qdisc *child = q->qdisc;
448e13e02a3SEric Dumazet 
449e13e02a3SEric Dumazet 	return child->ops->peek(child);
450e13e02a3SEric Dumazet }
451e13e02a3SEric Dumazet 
452e13e02a3SEric Dumazet /* No sfb_drop -- impossible since the child doesn't return the dropped skb. */
453e13e02a3SEric Dumazet 
sfb_reset(struct Qdisc * sch)454e13e02a3SEric Dumazet static void sfb_reset(struct Qdisc *sch)
455e13e02a3SEric Dumazet {
456e13e02a3SEric Dumazet 	struct sfb_sched_data *q = qdisc_priv(sch);
457e13e02a3SEric Dumazet 
458*2a3fc782SZhengchao Shao 	if (likely(q->qdisc))
459e13e02a3SEric Dumazet 		qdisc_reset(q->qdisc);
460e13e02a3SEric Dumazet 	q->slot = 0;
461e13e02a3SEric Dumazet 	q->double_buffering = false;
462e13e02a3SEric Dumazet 	sfb_zero_all_buckets(q);
463e13e02a3SEric Dumazet 	sfb_init_perturbation(0, q);
464e13e02a3SEric Dumazet }
465e13e02a3SEric Dumazet 
sfb_destroy(struct Qdisc * sch)466e13e02a3SEric Dumazet static void sfb_destroy(struct Qdisc *sch)
467e13e02a3SEric Dumazet {
468e13e02a3SEric Dumazet 	struct sfb_sched_data *q = qdisc_priv(sch);
469e13e02a3SEric Dumazet 
4706529eabaSJiri Pirko 	tcf_block_put(q->block);
47186bd446bSVlad Buslov 	qdisc_put(q->qdisc);
472e13e02a3SEric Dumazet }
473e13e02a3SEric Dumazet 
474e13e02a3SEric Dumazet static const struct nla_policy sfb_policy[TCA_SFB_MAX + 1] = {
475e13e02a3SEric Dumazet 	[TCA_SFB_PARMS]	= { .len = sizeof(struct tc_sfb_qopt) },
476e13e02a3SEric Dumazet };
477e13e02a3SEric Dumazet 
478e13e02a3SEric Dumazet static const struct tc_sfb_qopt sfb_default_ops = {
479e13e02a3SEric Dumazet 	.rehash_interval = 600 * MSEC_PER_SEC,
480e13e02a3SEric Dumazet 	.warmup_time = 60 * MSEC_PER_SEC,
481e13e02a3SEric Dumazet 	.limit = 0,
482e13e02a3SEric Dumazet 	.max = 25,
483e13e02a3SEric Dumazet 	.bin_size = 20,
484e13e02a3SEric Dumazet 	.increment = (SFB_MAX_PROB + 500) / 1000, /* 0.1 % */
485e13e02a3SEric Dumazet 	.decrement = (SFB_MAX_PROB + 3000) / 6000,
486e13e02a3SEric Dumazet 	.penalty_rate = 10,
487e13e02a3SEric Dumazet 	.penalty_burst = 20,
488e13e02a3SEric Dumazet };
489e13e02a3SEric Dumazet 
sfb_change(struct Qdisc * sch,struct nlattr * opt,struct netlink_ext_ack * extack)4902030721cSAlexander Aring static int sfb_change(struct Qdisc *sch, struct nlattr *opt,
4912030721cSAlexander Aring 		      struct netlink_ext_ack *extack)
492e13e02a3SEric Dumazet {
493e13e02a3SEric Dumazet 	struct sfb_sched_data *q = qdisc_priv(sch);
494e3ae1f96SVlad Buslov 	struct Qdisc *child, *old;
495e13e02a3SEric Dumazet 	struct nlattr *tb[TCA_SFB_MAX + 1];
496e13e02a3SEric Dumazet 	const struct tc_sfb_qopt *ctl = &sfb_default_ops;
497e13e02a3SEric Dumazet 	u32 limit;
498e13e02a3SEric Dumazet 	int err;
499e13e02a3SEric Dumazet 
500e13e02a3SEric Dumazet 	if (opt) {
5018cb08174SJohannes Berg 		err = nla_parse_nested_deprecated(tb, TCA_SFB_MAX, opt,
5028cb08174SJohannes Berg 						  sfb_policy, NULL);
503e13e02a3SEric Dumazet 		if (err < 0)
504e13e02a3SEric Dumazet 			return -EINVAL;
505e13e02a3SEric Dumazet 
506e13e02a3SEric Dumazet 		if (tb[TCA_SFB_PARMS] == NULL)
507e13e02a3SEric Dumazet 			return -EINVAL;
508e13e02a3SEric Dumazet 
509e13e02a3SEric Dumazet 		ctl = nla_data(tb[TCA_SFB_PARMS]);
510e13e02a3SEric Dumazet 	}
511e13e02a3SEric Dumazet 
512e13e02a3SEric Dumazet 	limit = ctl->limit;
513e13e02a3SEric Dumazet 	if (limit == 0)
514348e3435SPhil Sutter 		limit = qdisc_dev(sch)->tx_queue_len;
515e13e02a3SEric Dumazet 
516a38a9882SAlexander Aring 	child = fifo_create_dflt(sch, &pfifo_qdisc_ops, limit, extack);
517e13e02a3SEric Dumazet 	if (IS_ERR(child))
518e13e02a3SEric Dumazet 		return PTR_ERR(child);
519e13e02a3SEric Dumazet 
52049b49971SJiri Kosina 	if (child != &noop_qdisc)
52149b49971SJiri Kosina 		qdisc_hash_add(child, true);
522e13e02a3SEric Dumazet 	sch_tree_lock(sch);
523e13e02a3SEric Dumazet 
524e3ae1f96SVlad Buslov 	qdisc_purge_queue(q->qdisc);
525e3ae1f96SVlad Buslov 	old = q->qdisc;
526e13e02a3SEric Dumazet 	q->qdisc = child;
527e13e02a3SEric Dumazet 
528e13e02a3SEric Dumazet 	q->rehash_interval = msecs_to_jiffies(ctl->rehash_interval);
529e13e02a3SEric Dumazet 	q->warmup_time = msecs_to_jiffies(ctl->warmup_time);
530e13e02a3SEric Dumazet 	q->rehash_time = jiffies;
531e13e02a3SEric Dumazet 	q->limit = limit;
532e13e02a3SEric Dumazet 	q->increment = ctl->increment;
533e13e02a3SEric Dumazet 	q->decrement = ctl->decrement;
534e13e02a3SEric Dumazet 	q->max = ctl->max;
535e13e02a3SEric Dumazet 	q->bin_size = ctl->bin_size;
536e13e02a3SEric Dumazet 	q->penalty_rate = ctl->penalty_rate;
537e13e02a3SEric Dumazet 	q->penalty_burst = ctl->penalty_burst;
538e13e02a3SEric Dumazet 	q->tokens_avail = ctl->penalty_burst;
539e13e02a3SEric Dumazet 	q->token_time = jiffies;
540e13e02a3SEric Dumazet 
541e13e02a3SEric Dumazet 	q->slot = 0;
542e13e02a3SEric Dumazet 	q->double_buffering = false;
543e13e02a3SEric Dumazet 	sfb_zero_all_buckets(q);
544e13e02a3SEric Dumazet 	sfb_init_perturbation(0, q);
545e13e02a3SEric Dumazet 	sfb_init_perturbation(1, q);
546e13e02a3SEric Dumazet 
547e13e02a3SEric Dumazet 	sch_tree_unlock(sch);
548e3ae1f96SVlad Buslov 	qdisc_put(old);
549e13e02a3SEric Dumazet 
550e13e02a3SEric Dumazet 	return 0;
551e13e02a3SEric Dumazet }
552e13e02a3SEric Dumazet 
sfb_init(struct Qdisc * sch,struct nlattr * opt,struct netlink_ext_ack * extack)553e63d7dfdSAlexander Aring static int sfb_init(struct Qdisc *sch, struct nlattr *opt,
554e63d7dfdSAlexander Aring 		    struct netlink_ext_ack *extack)
555e13e02a3SEric Dumazet {
556e13e02a3SEric Dumazet 	struct sfb_sched_data *q = qdisc_priv(sch);
5576529eabaSJiri Pirko 	int err;
5586529eabaSJiri Pirko 
5598d1a77f9SAlexander Aring 	err = tcf_block_get(&q->block, &q->filter_list, sch, extack);
5606529eabaSJiri Pirko 	if (err)
5616529eabaSJiri Pirko 		return err;
562e13e02a3SEric Dumazet 
563e13e02a3SEric Dumazet 	q->qdisc = &noop_qdisc;
5642030721cSAlexander Aring 	return sfb_change(sch, opt, extack);
565e13e02a3SEric Dumazet }
566e13e02a3SEric Dumazet 
sfb_dump(struct Qdisc * sch,struct sk_buff * skb)567e13e02a3SEric Dumazet static int sfb_dump(struct Qdisc *sch, struct sk_buff *skb)
568e13e02a3SEric Dumazet {
569e13e02a3SEric Dumazet 	struct sfb_sched_data *q = qdisc_priv(sch);
570e13e02a3SEric Dumazet 	struct nlattr *opts;
571e13e02a3SEric Dumazet 	struct tc_sfb_qopt opt = {
572e13e02a3SEric Dumazet 		.rehash_interval = jiffies_to_msecs(q->rehash_interval),
573e13e02a3SEric Dumazet 		.warmup_time = jiffies_to_msecs(q->warmup_time),
574e13e02a3SEric Dumazet 		.limit = q->limit,
575e13e02a3SEric Dumazet 		.max = q->max,
576e13e02a3SEric Dumazet 		.bin_size = q->bin_size,
577e13e02a3SEric Dumazet 		.increment = q->increment,
578e13e02a3SEric Dumazet 		.decrement = q->decrement,
579e13e02a3SEric Dumazet 		.penalty_rate = q->penalty_rate,
580e13e02a3SEric Dumazet 		.penalty_burst = q->penalty_burst,
581e13e02a3SEric Dumazet 	};
582e13e02a3SEric Dumazet 
583e13e02a3SEric Dumazet 	sch->qstats.backlog = q->qdisc->qstats.backlog;
584ae0be8deSMichal Kubecek 	opts = nla_nest_start_noflag(skb, TCA_OPTIONS);
5857ac2908eSAlan Cox 	if (opts == NULL)
5867ac2908eSAlan Cox 		goto nla_put_failure;
5871b34ec43SDavid S. Miller 	if (nla_put(skb, TCA_SFB_PARMS, sizeof(opt), &opt))
5881b34ec43SDavid S. Miller 		goto nla_put_failure;
589e13e02a3SEric Dumazet 	return nla_nest_end(skb, opts);
590e13e02a3SEric Dumazet 
591e13e02a3SEric Dumazet nla_put_failure:
592e13e02a3SEric Dumazet 	nla_nest_cancel(skb, opts);
593e13e02a3SEric Dumazet 	return -EMSGSIZE;
594e13e02a3SEric Dumazet }
595e13e02a3SEric Dumazet 
sfb_dump_stats(struct Qdisc * sch,struct gnet_dump * d)596e13e02a3SEric Dumazet static int sfb_dump_stats(struct Qdisc *sch, struct gnet_dump *d)
597e13e02a3SEric Dumazet {
598e13e02a3SEric Dumazet 	struct sfb_sched_data *q = qdisc_priv(sch);
599e13e02a3SEric Dumazet 	struct tc_sfb_xstats st = {
600e13e02a3SEric Dumazet 		.earlydrop = q->stats.earlydrop,
601e13e02a3SEric Dumazet 		.penaltydrop = q->stats.penaltydrop,
602e13e02a3SEric Dumazet 		.bucketdrop = q->stats.bucketdrop,
603e13e02a3SEric Dumazet 		.queuedrop = q->stats.queuedrop,
604e13e02a3SEric Dumazet 		.childdrop = q->stats.childdrop,
605e13e02a3SEric Dumazet 		.marked = q->stats.marked,
606e13e02a3SEric Dumazet 	};
607e13e02a3SEric Dumazet 
608e13e02a3SEric Dumazet 	st.maxqlen = sfb_compute_qlen(&st.maxprob, &st.avgprob, q);
609e13e02a3SEric Dumazet 
610e13e02a3SEric Dumazet 	return gnet_stats_copy_app(d, &st, sizeof(st));
611e13e02a3SEric Dumazet }
612e13e02a3SEric Dumazet 
sfb_dump_class(struct Qdisc * sch,unsigned long cl,struct sk_buff * skb,struct tcmsg * tcm)613e13e02a3SEric Dumazet static int sfb_dump_class(struct Qdisc *sch, unsigned long cl,
614e13e02a3SEric Dumazet 			  struct sk_buff *skb, struct tcmsg *tcm)
615e13e02a3SEric Dumazet {
616e13e02a3SEric Dumazet 	return -ENOSYS;
617e13e02a3SEric Dumazet }
618e13e02a3SEric Dumazet 
sfb_graft(struct Qdisc * sch,unsigned long arg,struct Qdisc * new,struct Qdisc ** old,struct netlink_ext_ack * extack)619e13e02a3SEric Dumazet static int sfb_graft(struct Qdisc *sch, unsigned long arg, struct Qdisc *new,
620653d6fd6SAlexander Aring 		     struct Qdisc **old, struct netlink_ext_ack *extack)
621e13e02a3SEric Dumazet {
622e13e02a3SEric Dumazet 	struct sfb_sched_data *q = qdisc_priv(sch);
623e13e02a3SEric Dumazet 
624e13e02a3SEric Dumazet 	if (new == NULL)
625e13e02a3SEric Dumazet 		new = &noop_qdisc;
626e13e02a3SEric Dumazet 
62786a7996cSWANG Cong 	*old = qdisc_replace(sch, new, &q->qdisc);
628e13e02a3SEric Dumazet 	return 0;
629e13e02a3SEric Dumazet }
630e13e02a3SEric Dumazet 
sfb_leaf(struct Qdisc * sch,unsigned long arg)631e13e02a3SEric Dumazet static struct Qdisc *sfb_leaf(struct Qdisc *sch, unsigned long arg)
632e13e02a3SEric Dumazet {
633e13e02a3SEric Dumazet 	struct sfb_sched_data *q = qdisc_priv(sch);
634e13e02a3SEric Dumazet 
635e13e02a3SEric Dumazet 	return q->qdisc;
636e13e02a3SEric Dumazet }
637e13e02a3SEric Dumazet 
sfb_find(struct Qdisc * sch,u32 classid)638143976ceSWANG Cong static unsigned long sfb_find(struct Qdisc *sch, u32 classid)
639e13e02a3SEric Dumazet {
640e13e02a3SEric Dumazet 	return 1;
641e13e02a3SEric Dumazet }
642e13e02a3SEric Dumazet 
sfb_unbind(struct Qdisc * sch,unsigned long arg)643143976ceSWANG Cong static void sfb_unbind(struct Qdisc *sch, unsigned long arg)
644e13e02a3SEric Dumazet {
645e13e02a3SEric Dumazet }
646e13e02a3SEric Dumazet 
sfb_change_class(struct Qdisc * sch,u32 classid,u32 parentid,struct nlattr ** tca,unsigned long * arg,struct netlink_ext_ack * extack)647e13e02a3SEric Dumazet static int sfb_change_class(struct Qdisc *sch, u32 classid, u32 parentid,
648793d81d6SAlexander Aring 			    struct nlattr **tca, unsigned long *arg,
649793d81d6SAlexander Aring 			    struct netlink_ext_ack *extack)
650e13e02a3SEric Dumazet {
651e13e02a3SEric Dumazet 	return -ENOSYS;
652e13e02a3SEric Dumazet }
653e13e02a3SEric Dumazet 
sfb_delete(struct Qdisc * sch,unsigned long cl,struct netlink_ext_ack * extack)6544dd78a73SMaxim Mikityanskiy static int sfb_delete(struct Qdisc *sch, unsigned long cl,
6554dd78a73SMaxim Mikityanskiy 		      struct netlink_ext_ack *extack)
656e13e02a3SEric Dumazet {
657e13e02a3SEric Dumazet 	return -ENOSYS;
658e13e02a3SEric Dumazet }
659e13e02a3SEric Dumazet 
sfb_walk(struct Qdisc * sch,struct qdisc_walker * walker)660e13e02a3SEric Dumazet static void sfb_walk(struct Qdisc *sch, struct qdisc_walker *walker)
661e13e02a3SEric Dumazet {
662e13e02a3SEric Dumazet 	if (!walker->stop) {
663e046fa89SZhengchao Shao 		tc_qdisc_stats_dump(sch, 1, walker);
664e13e02a3SEric Dumazet 	}
665e13e02a3SEric Dumazet }
666e13e02a3SEric Dumazet 
sfb_tcf_block(struct Qdisc * sch,unsigned long cl,struct netlink_ext_ack * extack)667cbaacc4eSAlexander Aring static struct tcf_block *sfb_tcf_block(struct Qdisc *sch, unsigned long cl,
668cbaacc4eSAlexander Aring 				       struct netlink_ext_ack *extack)
669e13e02a3SEric Dumazet {
670e13e02a3SEric Dumazet 	struct sfb_sched_data *q = qdisc_priv(sch);
671e13e02a3SEric Dumazet 
672e13e02a3SEric Dumazet 	if (cl)
673e13e02a3SEric Dumazet 		return NULL;
6746529eabaSJiri Pirko 	return q->block;
675e13e02a3SEric Dumazet }
676e13e02a3SEric Dumazet 
sfb_bind(struct Qdisc * sch,unsigned long parent,u32 classid)677e13e02a3SEric Dumazet static unsigned long sfb_bind(struct Qdisc *sch, unsigned long parent,
678e13e02a3SEric Dumazet 			      u32 classid)
679e13e02a3SEric Dumazet {
680e13e02a3SEric Dumazet 	return 0;
681e13e02a3SEric Dumazet }
682e13e02a3SEric Dumazet 
683e13e02a3SEric Dumazet 
684e13e02a3SEric Dumazet static const struct Qdisc_class_ops sfb_class_ops = {
685e13e02a3SEric Dumazet 	.graft		=	sfb_graft,
686e13e02a3SEric Dumazet 	.leaf		=	sfb_leaf,
687143976ceSWANG Cong 	.find		=	sfb_find,
688e13e02a3SEric Dumazet 	.change		=	sfb_change_class,
689e13e02a3SEric Dumazet 	.delete		=	sfb_delete,
690e13e02a3SEric Dumazet 	.walk		=	sfb_walk,
6916529eabaSJiri Pirko 	.tcf_block	=	sfb_tcf_block,
692e13e02a3SEric Dumazet 	.bind_tcf	=	sfb_bind,
693143976ceSWANG Cong 	.unbind_tcf	=	sfb_unbind,
694e13e02a3SEric Dumazet 	.dump		=	sfb_dump_class,
695e13e02a3SEric Dumazet };
696e13e02a3SEric Dumazet 
697e13e02a3SEric Dumazet static struct Qdisc_ops sfb_qdisc_ops __read_mostly = {
698e13e02a3SEric Dumazet 	.id		=	"sfb",
699e13e02a3SEric Dumazet 	.priv_size	=	sizeof(struct sfb_sched_data),
700e13e02a3SEric Dumazet 	.cl_ops		=	&sfb_class_ops,
701e13e02a3SEric Dumazet 	.enqueue	=	sfb_enqueue,
702e13e02a3SEric Dumazet 	.dequeue	=	sfb_dequeue,
703e13e02a3SEric Dumazet 	.peek		=	sfb_peek,
704e13e02a3SEric Dumazet 	.init		=	sfb_init,
705e13e02a3SEric Dumazet 	.reset		=	sfb_reset,
706e13e02a3SEric Dumazet 	.destroy	=	sfb_destroy,
707e13e02a3SEric Dumazet 	.change		=	sfb_change,
708e13e02a3SEric Dumazet 	.dump		=	sfb_dump,
709e13e02a3SEric Dumazet 	.dump_stats	=	sfb_dump_stats,
710e13e02a3SEric Dumazet 	.owner		=	THIS_MODULE,
711e13e02a3SEric Dumazet };
712e13e02a3SEric Dumazet 
sfb_module_init(void)713e13e02a3SEric Dumazet static int __init sfb_module_init(void)
714e13e02a3SEric Dumazet {
715e13e02a3SEric Dumazet 	return register_qdisc(&sfb_qdisc_ops);
716e13e02a3SEric Dumazet }
717e13e02a3SEric Dumazet 
sfb_module_exit(void)718e13e02a3SEric Dumazet static void __exit sfb_module_exit(void)
719e13e02a3SEric Dumazet {
720e13e02a3SEric Dumazet 	unregister_qdisc(&sfb_qdisc_ops);
721e13e02a3SEric Dumazet }
722e13e02a3SEric Dumazet 
723e13e02a3SEric Dumazet module_init(sfb_module_init)
724e13e02a3SEric Dumazet module_exit(sfb_module_exit)
725e13e02a3SEric Dumazet 
726e13e02a3SEric Dumazet MODULE_DESCRIPTION("Stochastic Fair Blue queue discipline");
727e13e02a3SEric Dumazet MODULE_AUTHOR("Juliusz Chroboczek");
728e13e02a3SEric Dumazet MODULE_AUTHOR("Eric Dumazet");
729e13e02a3SEric Dumazet MODULE_LICENSE("GPL");
730