xref: /openbmc/linux/include/net/sch_generic.h (revision 4c57e2fa)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __NET_SCHED_GENERIC_H
3 #define __NET_SCHED_GENERIC_H
4 
5 #include <linux/netdevice.h>
6 #include <linux/types.h>
7 #include <linux/rcupdate.h>
8 #include <linux/pkt_sched.h>
9 #include <linux/pkt_cls.h>
10 #include <linux/percpu.h>
11 #include <linux/dynamic_queue_limits.h>
12 #include <linux/list.h>
13 #include <linux/refcount.h>
14 #include <linux/workqueue.h>
15 #include <linux/mutex.h>
16 #include <linux/rwsem.h>
17 #include <linux/atomic.h>
18 #include <linux/hashtable.h>
19 #include <net/gen_stats.h>
20 #include <net/rtnetlink.h>
21 #include <net/flow_offload.h>
22 
23 struct Qdisc_ops;
24 struct qdisc_walker;
25 struct tcf_walker;
26 struct module;
27 struct bpf_flow_keys;
28 
29 struct qdisc_rate_table {
30 	struct tc_ratespec rate;
31 	u32		data[256];
32 	struct qdisc_rate_table *next;
33 	int		refcnt;
34 };
35 
36 enum qdisc_state_t {
37 	__QDISC_STATE_SCHED,
38 	__QDISC_STATE_DEACTIVATED,
39 	__QDISC_STATE_MISSED,
40 	__QDISC_STATE_DRAINING,
41 	/* Only for !TCQ_F_NOLOCK qdisc. Never access it directly.
42 	 * Use qdisc_run_begin/end() or qdisc_is_running() instead.
43 	 */
44 	__QDISC_STATE_RUNNING,
45 };
46 
47 #define QDISC_STATE_MISSED	BIT(__QDISC_STATE_MISSED)
48 #define QDISC_STATE_DRAINING	BIT(__QDISC_STATE_DRAINING)
49 
50 #define QDISC_STATE_NON_EMPTY	(QDISC_STATE_MISSED | \
51 					QDISC_STATE_DRAINING)
52 
53 struct qdisc_size_table {
54 	struct rcu_head		rcu;
55 	struct list_head	list;
56 	struct tc_sizespec	szopts;
57 	int			refcnt;
58 	u16			data[];
59 };
60 
61 /* similar to sk_buff_head, but skb->prev pointer is undefined. */
62 struct qdisc_skb_head {
63 	struct sk_buff	*head;
64 	struct sk_buff	*tail;
65 	__u32		qlen;
66 	spinlock_t	lock;
67 };
68 
69 struct Qdisc {
70 	int 			(*enqueue)(struct sk_buff *skb,
71 					   struct Qdisc *sch,
72 					   struct sk_buff **to_free);
73 	struct sk_buff *	(*dequeue)(struct Qdisc *sch);
74 	unsigned int		flags;
75 #define TCQ_F_BUILTIN		1
76 #define TCQ_F_INGRESS		2
77 #define TCQ_F_CAN_BYPASS	4
78 #define TCQ_F_MQROOT		8
79 #define TCQ_F_ONETXQUEUE	0x10 /* dequeue_skb() can assume all skbs are for
80 				      * q->dev_queue : It can test
81 				      * netif_xmit_frozen_or_stopped() before
82 				      * dequeueing next packet.
83 				      * Its true for MQ/MQPRIO slaves, or non
84 				      * multiqueue device.
85 				      */
86 #define TCQ_F_WARN_NONWC	(1 << 16)
87 #define TCQ_F_CPUSTATS		0x20 /* run using percpu statistics */
88 #define TCQ_F_NOPARENT		0x40 /* root of its hierarchy :
89 				      * qdisc_tree_decrease_qlen() should stop.
90 				      */
91 #define TCQ_F_INVISIBLE		0x80 /* invisible by default in dump */
92 #define TCQ_F_NOLOCK		0x100 /* qdisc does not require locking */
93 #define TCQ_F_OFFLOADED		0x200 /* qdisc is offloaded to HW */
94 	u32			limit;
95 	const struct Qdisc_ops	*ops;
96 	struct qdisc_size_table	__rcu *stab;
97 	struct hlist_node       hash;
98 	u32			handle;
99 	u32			parent;
100 
101 	struct netdev_queue	*dev_queue;
102 
103 	struct net_rate_estimator __rcu *rate_est;
104 	struct gnet_stats_basic_sync __percpu *cpu_bstats;
105 	struct gnet_stats_queue	__percpu *cpu_qstats;
106 	int			pad;
107 	refcount_t		refcnt;
108 
109 	/*
110 	 * For performance sake on SMP, we put highly modified fields at the end
111 	 */
112 	struct sk_buff_head	gso_skb ____cacheline_aligned_in_smp;
113 	struct qdisc_skb_head	q;
114 	struct gnet_stats_basic_sync bstats;
115 	struct gnet_stats_queue	qstats;
116 	unsigned long		state;
117 	struct Qdisc            *next_sched;
118 	struct sk_buff_head	skb_bad_txq;
119 
120 	spinlock_t		busylock ____cacheline_aligned_in_smp;
121 	spinlock_t		seqlock;
122 
123 	struct rcu_head		rcu;
124 
125 	/* private data */
126 	long privdata[] ____cacheline_aligned;
127 };
128 
129 static inline void qdisc_refcount_inc(struct Qdisc *qdisc)
130 {
131 	if (qdisc->flags & TCQ_F_BUILTIN)
132 		return;
133 	refcount_inc(&qdisc->refcnt);
134 }
135 
136 /* Intended to be used by unlocked users, when concurrent qdisc release is
137  * possible.
138  */
139 
140 static inline struct Qdisc *qdisc_refcount_inc_nz(struct Qdisc *qdisc)
141 {
142 	if (qdisc->flags & TCQ_F_BUILTIN)
143 		return qdisc;
144 	if (refcount_inc_not_zero(&qdisc->refcnt))
145 		return qdisc;
146 	return NULL;
147 }
148 
149 /* For !TCQ_F_NOLOCK qdisc: callers must either call this within a qdisc
150  * root_lock section, or provide their own memory barriers -- ordering
151  * against qdisc_run_begin/end() atomic bit operations.
152  */
153 static inline bool qdisc_is_running(struct Qdisc *qdisc)
154 {
155 	if (qdisc->flags & TCQ_F_NOLOCK)
156 		return spin_is_locked(&qdisc->seqlock);
157 	return test_bit(__QDISC_STATE_RUNNING, &qdisc->state);
158 }
159 
160 static inline bool nolock_qdisc_is_empty(const struct Qdisc *qdisc)
161 {
162 	return !(READ_ONCE(qdisc->state) & QDISC_STATE_NON_EMPTY);
163 }
164 
165 static inline bool qdisc_is_percpu_stats(const struct Qdisc *q)
166 {
167 	return q->flags & TCQ_F_CPUSTATS;
168 }
169 
170 static inline bool qdisc_is_empty(const struct Qdisc *qdisc)
171 {
172 	if (qdisc_is_percpu_stats(qdisc))
173 		return nolock_qdisc_is_empty(qdisc);
174 	return !READ_ONCE(qdisc->q.qlen);
175 }
176 
177 /* For !TCQ_F_NOLOCK qdisc, qdisc_run_begin/end() must be invoked with
178  * the qdisc root lock acquired.
179  */
180 static inline bool qdisc_run_begin(struct Qdisc *qdisc)
181 {
182 	if (qdisc->flags & TCQ_F_NOLOCK) {
183 		if (spin_trylock(&qdisc->seqlock))
184 			return true;
185 
186 		/* Paired with smp_mb__after_atomic() to make sure
187 		 * STATE_MISSED checking is synchronized with clearing
188 		 * in pfifo_fast_dequeue().
189 		 */
190 		smp_mb__before_atomic();
191 
192 		/* If the MISSED flag is set, it means other thread has
193 		 * set the MISSED flag before second spin_trylock(), so
194 		 * we can return false here to avoid multi cpus doing
195 		 * the set_bit() and second spin_trylock() concurrently.
196 		 */
197 		if (test_bit(__QDISC_STATE_MISSED, &qdisc->state))
198 			return false;
199 
200 		/* Set the MISSED flag before the second spin_trylock(),
201 		 * if the second spin_trylock() return false, it means
202 		 * other cpu holding the lock will do dequeuing for us
203 		 * or it will see the MISSED flag set after releasing
204 		 * lock and reschedule the net_tx_action() to do the
205 		 * dequeuing.
206 		 */
207 		set_bit(__QDISC_STATE_MISSED, &qdisc->state);
208 
209 		/* spin_trylock() only has load-acquire semantic, so use
210 		 * smp_mb__after_atomic() to ensure STATE_MISSED is set
211 		 * before doing the second spin_trylock().
212 		 */
213 		smp_mb__after_atomic();
214 
215 		/* Retry again in case other CPU may not see the new flag
216 		 * after it releases the lock at the end of qdisc_run_end().
217 		 */
218 		return spin_trylock(&qdisc->seqlock);
219 	}
220 	return !test_and_set_bit(__QDISC_STATE_RUNNING, &qdisc->state);
221 }
222 
223 static inline void qdisc_run_end(struct Qdisc *qdisc)
224 {
225 	if (qdisc->flags & TCQ_F_NOLOCK) {
226 		spin_unlock(&qdisc->seqlock);
227 
228 		if (unlikely(test_bit(__QDISC_STATE_MISSED,
229 				      &qdisc->state)))
230 			__netif_schedule(qdisc);
231 	} else {
232 		clear_bit(__QDISC_STATE_RUNNING, &qdisc->state);
233 	}
234 }
235 
236 static inline bool qdisc_may_bulk(const struct Qdisc *qdisc)
237 {
238 	return qdisc->flags & TCQ_F_ONETXQUEUE;
239 }
240 
241 static inline int qdisc_avail_bulklimit(const struct netdev_queue *txq)
242 {
243 #ifdef CONFIG_BQL
244 	/* Non-BQL migrated drivers will return 0, too. */
245 	return dql_avail(&txq->dql);
246 #else
247 	return 0;
248 #endif
249 }
250 
251 struct Qdisc_class_ops {
252 	unsigned int		flags;
253 	/* Child qdisc manipulation */
254 	struct netdev_queue *	(*select_queue)(struct Qdisc *, struct tcmsg *);
255 	int			(*graft)(struct Qdisc *, unsigned long cl,
256 					struct Qdisc *, struct Qdisc **,
257 					struct netlink_ext_ack *extack);
258 	struct Qdisc *		(*leaf)(struct Qdisc *, unsigned long cl);
259 	void			(*qlen_notify)(struct Qdisc *, unsigned long);
260 
261 	/* Class manipulation routines */
262 	unsigned long		(*find)(struct Qdisc *, u32 classid);
263 	int			(*change)(struct Qdisc *, u32, u32,
264 					struct nlattr **, unsigned long *,
265 					struct netlink_ext_ack *);
266 	int			(*delete)(struct Qdisc *, unsigned long,
267 					  struct netlink_ext_ack *);
268 	void			(*walk)(struct Qdisc *, struct qdisc_walker * arg);
269 
270 	/* Filter manipulation */
271 	struct tcf_block *	(*tcf_block)(struct Qdisc *sch,
272 					     unsigned long arg,
273 					     struct netlink_ext_ack *extack);
274 	unsigned long		(*bind_tcf)(struct Qdisc *, unsigned long,
275 					u32 classid);
276 	void			(*unbind_tcf)(struct Qdisc *, unsigned long);
277 
278 	/* rtnetlink specific */
279 	int			(*dump)(struct Qdisc *, unsigned long,
280 					struct sk_buff *skb, struct tcmsg*);
281 	int			(*dump_stats)(struct Qdisc *, unsigned long,
282 					struct gnet_dump *);
283 };
284 
285 /* Qdisc_class_ops flag values */
286 
287 /* Implements API that doesn't require rtnl lock */
288 enum qdisc_class_ops_flags {
289 	QDISC_CLASS_OPS_DOIT_UNLOCKED = 1,
290 };
291 
292 struct Qdisc_ops {
293 	struct Qdisc_ops	*next;
294 	const struct Qdisc_class_ops	*cl_ops;
295 	char			id[IFNAMSIZ];
296 	int			priv_size;
297 	unsigned int		static_flags;
298 
299 	int 			(*enqueue)(struct sk_buff *skb,
300 					   struct Qdisc *sch,
301 					   struct sk_buff **to_free);
302 	struct sk_buff *	(*dequeue)(struct Qdisc *);
303 	struct sk_buff *	(*peek)(struct Qdisc *);
304 
305 	int			(*init)(struct Qdisc *sch, struct nlattr *arg,
306 					struct netlink_ext_ack *extack);
307 	void			(*reset)(struct Qdisc *);
308 	void			(*destroy)(struct Qdisc *);
309 	int			(*change)(struct Qdisc *sch,
310 					  struct nlattr *arg,
311 					  struct netlink_ext_ack *extack);
312 	void			(*attach)(struct Qdisc *sch);
313 	int			(*change_tx_queue_len)(struct Qdisc *, unsigned int);
314 	void			(*change_real_num_tx)(struct Qdisc *sch,
315 						      unsigned int new_real_tx);
316 
317 	int			(*dump)(struct Qdisc *, struct sk_buff *);
318 	int			(*dump_stats)(struct Qdisc *, struct gnet_dump *);
319 
320 	void			(*ingress_block_set)(struct Qdisc *sch,
321 						     u32 block_index);
322 	void			(*egress_block_set)(struct Qdisc *sch,
323 						    u32 block_index);
324 	u32			(*ingress_block_get)(struct Qdisc *sch);
325 	u32			(*egress_block_get)(struct Qdisc *sch);
326 
327 	struct module		*owner;
328 };
329 
330 
331 struct tcf_result {
332 	union {
333 		struct {
334 			unsigned long	class;
335 			u32		classid;
336 		};
337 		const struct tcf_proto *goto_tp;
338 
339 		/* used in the skb_tc_reinsert function */
340 		struct {
341 			bool		ingress;
342 			struct gnet_stats_queue *qstats;
343 		};
344 	};
345 };
346 
347 struct tcf_chain;
348 
349 struct tcf_proto_ops {
350 	struct list_head	head;
351 	char			kind[IFNAMSIZ];
352 
353 	int			(*classify)(struct sk_buff *,
354 					    const struct tcf_proto *,
355 					    struct tcf_result *);
356 	int			(*init)(struct tcf_proto*);
357 	void			(*destroy)(struct tcf_proto *tp, bool rtnl_held,
358 					   struct netlink_ext_ack *extack);
359 
360 	void*			(*get)(struct tcf_proto*, u32 handle);
361 	void			(*put)(struct tcf_proto *tp, void *f);
362 	int			(*change)(struct net *net, struct sk_buff *,
363 					struct tcf_proto*, unsigned long,
364 					u32 handle, struct nlattr **,
365 					void **, u32,
366 					struct netlink_ext_ack *);
367 	int			(*delete)(struct tcf_proto *tp, void *arg,
368 					  bool *last, bool rtnl_held,
369 					  struct netlink_ext_ack *);
370 	bool			(*delete_empty)(struct tcf_proto *tp);
371 	void			(*walk)(struct tcf_proto *tp,
372 					struct tcf_walker *arg, bool rtnl_held);
373 	int			(*reoffload)(struct tcf_proto *tp, bool add,
374 					     flow_setup_cb_t *cb, void *cb_priv,
375 					     struct netlink_ext_ack *extack);
376 	void			(*hw_add)(struct tcf_proto *tp,
377 					  void *type_data);
378 	void			(*hw_del)(struct tcf_proto *tp,
379 					  void *type_data);
380 	void			(*bind_class)(void *, u32, unsigned long,
381 					      void *, unsigned long);
382 	void *			(*tmplt_create)(struct net *net,
383 						struct tcf_chain *chain,
384 						struct nlattr **tca,
385 						struct netlink_ext_ack *extack);
386 	void			(*tmplt_destroy)(void *tmplt_priv);
387 
388 	/* rtnetlink specific */
389 	int			(*dump)(struct net*, struct tcf_proto*, void *,
390 					struct sk_buff *skb, struct tcmsg*,
391 					bool);
392 	int			(*terse_dump)(struct net *net,
393 					      struct tcf_proto *tp, void *fh,
394 					      struct sk_buff *skb,
395 					      struct tcmsg *t, bool rtnl_held);
396 	int			(*tmplt_dump)(struct sk_buff *skb,
397 					      struct net *net,
398 					      void *tmplt_priv);
399 
400 	struct module		*owner;
401 	int			flags;
402 };
403 
404 /* Classifiers setting TCF_PROTO_OPS_DOIT_UNLOCKED in tcf_proto_ops->flags
405  * are expected to implement tcf_proto_ops->delete_empty(), otherwise race
406  * conditions can occur when filters are inserted/deleted simultaneously.
407  */
408 enum tcf_proto_ops_flags {
409 	TCF_PROTO_OPS_DOIT_UNLOCKED = 1,
410 };
411 
412 struct tcf_proto {
413 	/* Fast access part */
414 	struct tcf_proto __rcu	*next;
415 	void __rcu		*root;
416 
417 	/* called under RCU BH lock*/
418 	int			(*classify)(struct sk_buff *,
419 					    const struct tcf_proto *,
420 					    struct tcf_result *);
421 	__be16			protocol;
422 
423 	/* All the rest */
424 	u32			prio;
425 	void			*data;
426 	const struct tcf_proto_ops	*ops;
427 	struct tcf_chain	*chain;
428 	/* Lock protects tcf_proto shared state and can be used by unlocked
429 	 * classifiers to protect their private data.
430 	 */
431 	spinlock_t		lock;
432 	bool			deleting;
433 	refcount_t		refcnt;
434 	struct rcu_head		rcu;
435 	struct hlist_node	destroy_ht_node;
436 };
437 
438 struct qdisc_skb_cb {
439 	struct {
440 		unsigned int		pkt_len;
441 		u16			slave_dev_queue_mapping;
442 		u16			tc_classid;
443 	};
444 #define QDISC_CB_PRIV_LEN 20
445 	unsigned char		data[QDISC_CB_PRIV_LEN];
446 	u16			mru;
447 	bool			post_ct;
448 };
449 
450 typedef void tcf_chain_head_change_t(struct tcf_proto *tp_head, void *priv);
451 
452 struct tcf_chain {
453 	/* Protects filter_chain. */
454 	struct mutex filter_chain_lock;
455 	struct tcf_proto __rcu *filter_chain;
456 	struct list_head list;
457 	struct tcf_block *block;
458 	u32 index; /* chain index */
459 	unsigned int refcnt;
460 	unsigned int action_refcnt;
461 	bool explicitly_created;
462 	bool flushing;
463 	const struct tcf_proto_ops *tmplt_ops;
464 	void *tmplt_priv;
465 	struct rcu_head rcu;
466 };
467 
468 struct tcf_block {
469 	/* Lock protects tcf_block and lifetime-management data of chains
470 	 * attached to the block (refcnt, action_refcnt, explicitly_created).
471 	 */
472 	struct mutex lock;
473 	struct list_head chain_list;
474 	u32 index; /* block index for shared blocks */
475 	u32 classid; /* which class this block belongs to */
476 	refcount_t refcnt;
477 	struct net *net;
478 	struct Qdisc *q;
479 	struct rw_semaphore cb_lock; /* protects cb_list and offload counters */
480 	struct flow_block flow_block;
481 	struct list_head owner_list;
482 	bool keep_dst;
483 	atomic_t offloadcnt; /* Number of oddloaded filters */
484 	unsigned int nooffloaddevcnt; /* Number of devs unable to do offload */
485 	unsigned int lockeddevcnt; /* Number of devs that require rtnl lock. */
486 	struct {
487 		struct tcf_chain *chain;
488 		struct list_head filter_chain_list;
489 	} chain0;
490 	struct rcu_head rcu;
491 	DECLARE_HASHTABLE(proto_destroy_ht, 7);
492 	struct mutex proto_destroy_lock; /* Lock for proto_destroy hashtable. */
493 };
494 
495 static inline bool lockdep_tcf_chain_is_locked(struct tcf_chain *chain)
496 {
497 	return lockdep_is_held(&chain->filter_chain_lock);
498 }
499 
500 static inline bool lockdep_tcf_proto_is_locked(struct tcf_proto *tp)
501 {
502 	return lockdep_is_held(&tp->lock);
503 }
504 
505 #define tcf_chain_dereference(p, chain)					\
506 	rcu_dereference_protected(p, lockdep_tcf_chain_is_locked(chain))
507 
508 #define tcf_proto_dereference(p, tp)					\
509 	rcu_dereference_protected(p, lockdep_tcf_proto_is_locked(tp))
510 
511 static inline void qdisc_cb_private_validate(const struct sk_buff *skb, int sz)
512 {
513 	struct qdisc_skb_cb *qcb;
514 
515 	BUILD_BUG_ON(sizeof(skb->cb) < sizeof(*qcb));
516 	BUILD_BUG_ON(sizeof(qcb->data) < sz);
517 }
518 
519 static inline int qdisc_qlen_cpu(const struct Qdisc *q)
520 {
521 	return this_cpu_ptr(q->cpu_qstats)->qlen;
522 }
523 
524 static inline int qdisc_qlen(const struct Qdisc *q)
525 {
526 	return q->q.qlen;
527 }
528 
529 static inline int qdisc_qlen_sum(const struct Qdisc *q)
530 {
531 	__u32 qlen = q->qstats.qlen;
532 	int i;
533 
534 	if (qdisc_is_percpu_stats(q)) {
535 		for_each_possible_cpu(i)
536 			qlen += per_cpu_ptr(q->cpu_qstats, i)->qlen;
537 	} else {
538 		qlen += q->q.qlen;
539 	}
540 
541 	return qlen;
542 }
543 
544 static inline struct qdisc_skb_cb *qdisc_skb_cb(const struct sk_buff *skb)
545 {
546 	return (struct qdisc_skb_cb *)skb->cb;
547 }
548 
549 static inline spinlock_t *qdisc_lock(struct Qdisc *qdisc)
550 {
551 	return &qdisc->q.lock;
552 }
553 
554 static inline struct Qdisc *qdisc_root(const struct Qdisc *qdisc)
555 {
556 	struct Qdisc *q = rcu_dereference_rtnl(qdisc->dev_queue->qdisc);
557 
558 	return q;
559 }
560 
561 static inline struct Qdisc *qdisc_root_bh(const struct Qdisc *qdisc)
562 {
563 	return rcu_dereference_bh(qdisc->dev_queue->qdisc);
564 }
565 
566 static inline struct Qdisc *qdisc_root_sleeping(const struct Qdisc *qdisc)
567 {
568 	return qdisc->dev_queue->qdisc_sleeping;
569 }
570 
571 /* The qdisc root lock is a mechanism by which to top level
572  * of a qdisc tree can be locked from any qdisc node in the
573  * forest.  This allows changing the configuration of some
574  * aspect of the qdisc tree while blocking out asynchronous
575  * qdisc access in the packet processing paths.
576  *
577  * It is only legal to do this when the root will not change
578  * on us.  Otherwise we'll potentially lock the wrong qdisc
579  * root.  This is enforced by holding the RTNL semaphore, which
580  * all users of this lock accessor must do.
581  */
582 static inline spinlock_t *qdisc_root_lock(const struct Qdisc *qdisc)
583 {
584 	struct Qdisc *root = qdisc_root(qdisc);
585 
586 	ASSERT_RTNL();
587 	return qdisc_lock(root);
588 }
589 
590 static inline spinlock_t *qdisc_root_sleeping_lock(const struct Qdisc *qdisc)
591 {
592 	struct Qdisc *root = qdisc_root_sleeping(qdisc);
593 
594 	ASSERT_RTNL();
595 	return qdisc_lock(root);
596 }
597 
598 static inline struct net_device *qdisc_dev(const struct Qdisc *qdisc)
599 {
600 	return qdisc->dev_queue->dev;
601 }
602 
603 static inline void sch_tree_lock(struct Qdisc *q)
604 {
605 	if (q->flags & TCQ_F_MQROOT)
606 		spin_lock_bh(qdisc_lock(q));
607 	else
608 		spin_lock_bh(qdisc_root_sleeping_lock(q));
609 }
610 
611 static inline void sch_tree_unlock(struct Qdisc *q)
612 {
613 	if (q->flags & TCQ_F_MQROOT)
614 		spin_unlock_bh(qdisc_lock(q));
615 	else
616 		spin_unlock_bh(qdisc_root_sleeping_lock(q));
617 }
618 
619 extern struct Qdisc noop_qdisc;
620 extern struct Qdisc_ops noop_qdisc_ops;
621 extern struct Qdisc_ops pfifo_fast_ops;
622 extern struct Qdisc_ops mq_qdisc_ops;
623 extern struct Qdisc_ops noqueue_qdisc_ops;
624 extern const struct Qdisc_ops *default_qdisc_ops;
625 static inline const struct Qdisc_ops *
626 get_default_qdisc_ops(const struct net_device *dev, int ntx)
627 {
628 	return ntx < dev->real_num_tx_queues ?
629 			default_qdisc_ops : &pfifo_fast_ops;
630 }
631 
632 struct Qdisc_class_common {
633 	u32			classid;
634 	struct hlist_node	hnode;
635 };
636 
637 struct Qdisc_class_hash {
638 	struct hlist_head	*hash;
639 	unsigned int		hashsize;
640 	unsigned int		hashmask;
641 	unsigned int		hashelems;
642 };
643 
644 static inline unsigned int qdisc_class_hash(u32 id, u32 mask)
645 {
646 	id ^= id >> 8;
647 	id ^= id >> 4;
648 	return id & mask;
649 }
650 
651 static inline struct Qdisc_class_common *
652 qdisc_class_find(const struct Qdisc_class_hash *hash, u32 id)
653 {
654 	struct Qdisc_class_common *cl;
655 	unsigned int h;
656 
657 	if (!id)
658 		return NULL;
659 
660 	h = qdisc_class_hash(id, hash->hashmask);
661 	hlist_for_each_entry(cl, &hash->hash[h], hnode) {
662 		if (cl->classid == id)
663 			return cl;
664 	}
665 	return NULL;
666 }
667 
668 static inline int tc_classid_to_hwtc(struct net_device *dev, u32 classid)
669 {
670 	u32 hwtc = TC_H_MIN(classid) - TC_H_MIN_PRIORITY;
671 
672 	return (hwtc < netdev_get_num_tc(dev)) ? hwtc : -EINVAL;
673 }
674 
675 int qdisc_class_hash_init(struct Qdisc_class_hash *);
676 void qdisc_class_hash_insert(struct Qdisc_class_hash *,
677 			     struct Qdisc_class_common *);
678 void qdisc_class_hash_remove(struct Qdisc_class_hash *,
679 			     struct Qdisc_class_common *);
680 void qdisc_class_hash_grow(struct Qdisc *, struct Qdisc_class_hash *);
681 void qdisc_class_hash_destroy(struct Qdisc_class_hash *);
682 
683 int dev_qdisc_change_tx_queue_len(struct net_device *dev);
684 void dev_qdisc_change_real_num_tx(struct net_device *dev,
685 				  unsigned int new_real_tx);
686 void dev_init_scheduler(struct net_device *dev);
687 void dev_shutdown(struct net_device *dev);
688 void dev_activate(struct net_device *dev);
689 void dev_deactivate(struct net_device *dev);
690 void dev_deactivate_many(struct list_head *head);
691 struct Qdisc *dev_graft_qdisc(struct netdev_queue *dev_queue,
692 			      struct Qdisc *qdisc);
693 void qdisc_reset(struct Qdisc *qdisc);
694 void qdisc_put(struct Qdisc *qdisc);
695 void qdisc_put_unlocked(struct Qdisc *qdisc);
696 void qdisc_tree_reduce_backlog(struct Qdisc *qdisc, int n, int len);
697 #ifdef CONFIG_NET_SCHED
698 int qdisc_offload_dump_helper(struct Qdisc *q, enum tc_setup_type type,
699 			      void *type_data);
700 void qdisc_offload_graft_helper(struct net_device *dev, struct Qdisc *sch,
701 				struct Qdisc *new, struct Qdisc *old,
702 				enum tc_setup_type type, void *type_data,
703 				struct netlink_ext_ack *extack);
704 #else
705 static inline int
706 qdisc_offload_dump_helper(struct Qdisc *q, enum tc_setup_type type,
707 			  void *type_data)
708 {
709 	q->flags &= ~TCQ_F_OFFLOADED;
710 	return 0;
711 }
712 
713 static inline void
714 qdisc_offload_graft_helper(struct net_device *dev, struct Qdisc *sch,
715 			   struct Qdisc *new, struct Qdisc *old,
716 			   enum tc_setup_type type, void *type_data,
717 			   struct netlink_ext_ack *extack)
718 {
719 }
720 #endif
721 struct Qdisc *qdisc_alloc(struct netdev_queue *dev_queue,
722 			  const struct Qdisc_ops *ops,
723 			  struct netlink_ext_ack *extack);
724 void qdisc_free(struct Qdisc *qdisc);
725 struct Qdisc *qdisc_create_dflt(struct netdev_queue *dev_queue,
726 				const struct Qdisc_ops *ops, u32 parentid,
727 				struct netlink_ext_ack *extack);
728 void __qdisc_calculate_pkt_len(struct sk_buff *skb,
729 			       const struct qdisc_size_table *stab);
730 int skb_do_redirect(struct sk_buff *);
731 
732 static inline bool skb_at_tc_ingress(const struct sk_buff *skb)
733 {
734 #ifdef CONFIG_NET_CLS_ACT
735 	return skb->tc_at_ingress;
736 #else
737 	return false;
738 #endif
739 }
740 
741 static inline bool skb_skip_tc_classify(struct sk_buff *skb)
742 {
743 #ifdef CONFIG_NET_CLS_ACT
744 	if (skb->tc_skip_classify) {
745 		skb->tc_skip_classify = 0;
746 		return true;
747 	}
748 #endif
749 	return false;
750 }
751 
752 /* Reset all TX qdiscs greater than index of a device.  */
753 static inline void qdisc_reset_all_tx_gt(struct net_device *dev, unsigned int i)
754 {
755 	struct Qdisc *qdisc;
756 
757 	for (; i < dev->num_tx_queues; i++) {
758 		qdisc = rtnl_dereference(netdev_get_tx_queue(dev, i)->qdisc);
759 		if (qdisc) {
760 			spin_lock_bh(qdisc_lock(qdisc));
761 			qdisc_reset(qdisc);
762 			spin_unlock_bh(qdisc_lock(qdisc));
763 		}
764 	}
765 }
766 
767 /* Are all TX queues of the device empty?  */
768 static inline bool qdisc_all_tx_empty(const struct net_device *dev)
769 {
770 	unsigned int i;
771 
772 	rcu_read_lock();
773 	for (i = 0; i < dev->num_tx_queues; i++) {
774 		struct netdev_queue *txq = netdev_get_tx_queue(dev, i);
775 		const struct Qdisc *q = rcu_dereference(txq->qdisc);
776 
777 		if (!qdisc_is_empty(q)) {
778 			rcu_read_unlock();
779 			return false;
780 		}
781 	}
782 	rcu_read_unlock();
783 	return true;
784 }
785 
786 /* Are any of the TX qdiscs changing?  */
787 static inline bool qdisc_tx_changing(const struct net_device *dev)
788 {
789 	unsigned int i;
790 
791 	for (i = 0; i < dev->num_tx_queues; i++) {
792 		struct netdev_queue *txq = netdev_get_tx_queue(dev, i);
793 		if (rcu_access_pointer(txq->qdisc) != txq->qdisc_sleeping)
794 			return true;
795 	}
796 	return false;
797 }
798 
799 /* Is the device using the noop qdisc on all queues?  */
800 static inline bool qdisc_tx_is_noop(const struct net_device *dev)
801 {
802 	unsigned int i;
803 
804 	for (i = 0; i < dev->num_tx_queues; i++) {
805 		struct netdev_queue *txq = netdev_get_tx_queue(dev, i);
806 		if (rcu_access_pointer(txq->qdisc) != &noop_qdisc)
807 			return false;
808 	}
809 	return true;
810 }
811 
812 static inline unsigned int qdisc_pkt_len(const struct sk_buff *skb)
813 {
814 	return qdisc_skb_cb(skb)->pkt_len;
815 }
816 
817 /* additional qdisc xmit flags (NET_XMIT_MASK in linux/netdevice.h) */
818 enum net_xmit_qdisc_t {
819 	__NET_XMIT_STOLEN = 0x00010000,
820 	__NET_XMIT_BYPASS = 0x00020000,
821 };
822 
823 #ifdef CONFIG_NET_CLS_ACT
824 #define net_xmit_drop_count(e)	((e) & __NET_XMIT_STOLEN ? 0 : 1)
825 #else
826 #define net_xmit_drop_count(e)	(1)
827 #endif
828 
829 static inline void qdisc_calculate_pkt_len(struct sk_buff *skb,
830 					   const struct Qdisc *sch)
831 {
832 #ifdef CONFIG_NET_SCHED
833 	struct qdisc_size_table *stab = rcu_dereference_bh(sch->stab);
834 
835 	if (stab)
836 		__qdisc_calculate_pkt_len(skb, stab);
837 #endif
838 }
839 
840 static inline int qdisc_enqueue(struct sk_buff *skb, struct Qdisc *sch,
841 				struct sk_buff **to_free)
842 {
843 	qdisc_calculate_pkt_len(skb, sch);
844 	return sch->enqueue(skb, sch, to_free);
845 }
846 
847 static inline void _bstats_update(struct gnet_stats_basic_sync *bstats,
848 				  __u64 bytes, __u32 packets)
849 {
850 	u64_stats_update_begin(&bstats->syncp);
851 	u64_stats_add(&bstats->bytes, bytes);
852 	u64_stats_add(&bstats->packets, packets);
853 	u64_stats_update_end(&bstats->syncp);
854 }
855 
856 static inline void bstats_update(struct gnet_stats_basic_sync *bstats,
857 				 const struct sk_buff *skb)
858 {
859 	_bstats_update(bstats,
860 		       qdisc_pkt_len(skb),
861 		       skb_is_gso(skb) ? skb_shinfo(skb)->gso_segs : 1);
862 }
863 
864 static inline void qdisc_bstats_cpu_update(struct Qdisc *sch,
865 					   const struct sk_buff *skb)
866 {
867 	bstats_update(this_cpu_ptr(sch->cpu_bstats), skb);
868 }
869 
870 static inline void qdisc_bstats_update(struct Qdisc *sch,
871 				       const struct sk_buff *skb)
872 {
873 	bstats_update(&sch->bstats, skb);
874 }
875 
876 static inline void qdisc_qstats_backlog_dec(struct Qdisc *sch,
877 					    const struct sk_buff *skb)
878 {
879 	sch->qstats.backlog -= qdisc_pkt_len(skb);
880 }
881 
882 static inline void qdisc_qstats_cpu_backlog_dec(struct Qdisc *sch,
883 						const struct sk_buff *skb)
884 {
885 	this_cpu_sub(sch->cpu_qstats->backlog, qdisc_pkt_len(skb));
886 }
887 
888 static inline void qdisc_qstats_backlog_inc(struct Qdisc *sch,
889 					    const struct sk_buff *skb)
890 {
891 	sch->qstats.backlog += qdisc_pkt_len(skb);
892 }
893 
894 static inline void qdisc_qstats_cpu_backlog_inc(struct Qdisc *sch,
895 						const struct sk_buff *skb)
896 {
897 	this_cpu_add(sch->cpu_qstats->backlog, qdisc_pkt_len(skb));
898 }
899 
900 static inline void qdisc_qstats_cpu_qlen_inc(struct Qdisc *sch)
901 {
902 	this_cpu_inc(sch->cpu_qstats->qlen);
903 }
904 
905 static inline void qdisc_qstats_cpu_qlen_dec(struct Qdisc *sch)
906 {
907 	this_cpu_dec(sch->cpu_qstats->qlen);
908 }
909 
910 static inline void qdisc_qstats_cpu_requeues_inc(struct Qdisc *sch)
911 {
912 	this_cpu_inc(sch->cpu_qstats->requeues);
913 }
914 
915 static inline void __qdisc_qstats_drop(struct Qdisc *sch, int count)
916 {
917 	sch->qstats.drops += count;
918 }
919 
920 static inline void qstats_drop_inc(struct gnet_stats_queue *qstats)
921 {
922 	qstats->drops++;
923 }
924 
925 static inline void qstats_overlimit_inc(struct gnet_stats_queue *qstats)
926 {
927 	qstats->overlimits++;
928 }
929 
930 static inline void qdisc_qstats_drop(struct Qdisc *sch)
931 {
932 	qstats_drop_inc(&sch->qstats);
933 }
934 
935 static inline void qdisc_qstats_cpu_drop(struct Qdisc *sch)
936 {
937 	this_cpu_inc(sch->cpu_qstats->drops);
938 }
939 
940 static inline void qdisc_qstats_overlimit(struct Qdisc *sch)
941 {
942 	sch->qstats.overlimits++;
943 }
944 
945 static inline int qdisc_qstats_copy(struct gnet_dump *d, struct Qdisc *sch)
946 {
947 	__u32 qlen = qdisc_qlen_sum(sch);
948 
949 	return gnet_stats_copy_queue(d, sch->cpu_qstats, &sch->qstats, qlen);
950 }
951 
952 static inline void qdisc_qstats_qlen_backlog(struct Qdisc *sch,  __u32 *qlen,
953 					     __u32 *backlog)
954 {
955 	struct gnet_stats_queue qstats = { 0 };
956 
957 	gnet_stats_add_queue(&qstats, sch->cpu_qstats, &sch->qstats);
958 	*qlen = qstats.qlen + qdisc_qlen(sch);
959 	*backlog = qstats.backlog;
960 }
961 
962 static inline void qdisc_tree_flush_backlog(struct Qdisc *sch)
963 {
964 	__u32 qlen, backlog;
965 
966 	qdisc_qstats_qlen_backlog(sch, &qlen, &backlog);
967 	qdisc_tree_reduce_backlog(sch, qlen, backlog);
968 }
969 
970 static inline void qdisc_purge_queue(struct Qdisc *sch)
971 {
972 	__u32 qlen, backlog;
973 
974 	qdisc_qstats_qlen_backlog(sch, &qlen, &backlog);
975 	qdisc_reset(sch);
976 	qdisc_tree_reduce_backlog(sch, qlen, backlog);
977 }
978 
979 static inline void qdisc_skb_head_init(struct qdisc_skb_head *qh)
980 {
981 	qh->head = NULL;
982 	qh->tail = NULL;
983 	qh->qlen = 0;
984 }
985 
986 static inline void __qdisc_enqueue_tail(struct sk_buff *skb,
987 					struct qdisc_skb_head *qh)
988 {
989 	struct sk_buff *last = qh->tail;
990 
991 	if (last) {
992 		skb->next = NULL;
993 		last->next = skb;
994 		qh->tail = skb;
995 	} else {
996 		qh->tail = skb;
997 		qh->head = skb;
998 	}
999 	qh->qlen++;
1000 }
1001 
1002 static inline int qdisc_enqueue_tail(struct sk_buff *skb, struct Qdisc *sch)
1003 {
1004 	__qdisc_enqueue_tail(skb, &sch->q);
1005 	qdisc_qstats_backlog_inc(sch, skb);
1006 	return NET_XMIT_SUCCESS;
1007 }
1008 
1009 static inline void __qdisc_enqueue_head(struct sk_buff *skb,
1010 					struct qdisc_skb_head *qh)
1011 {
1012 	skb->next = qh->head;
1013 
1014 	if (!qh->head)
1015 		qh->tail = skb;
1016 	qh->head = skb;
1017 	qh->qlen++;
1018 }
1019 
1020 static inline struct sk_buff *__qdisc_dequeue_head(struct qdisc_skb_head *qh)
1021 {
1022 	struct sk_buff *skb = qh->head;
1023 
1024 	if (likely(skb != NULL)) {
1025 		qh->head = skb->next;
1026 		qh->qlen--;
1027 		if (qh->head == NULL)
1028 			qh->tail = NULL;
1029 		skb->next = NULL;
1030 	}
1031 
1032 	return skb;
1033 }
1034 
1035 static inline struct sk_buff *qdisc_dequeue_head(struct Qdisc *sch)
1036 {
1037 	struct sk_buff *skb = __qdisc_dequeue_head(&sch->q);
1038 
1039 	if (likely(skb != NULL)) {
1040 		qdisc_qstats_backlog_dec(sch, skb);
1041 		qdisc_bstats_update(sch, skb);
1042 	}
1043 
1044 	return skb;
1045 }
1046 
1047 /* Instead of calling kfree_skb() while root qdisc lock is held,
1048  * queue the skb for future freeing at end of __dev_xmit_skb()
1049  */
1050 static inline void __qdisc_drop(struct sk_buff *skb, struct sk_buff **to_free)
1051 {
1052 	skb->next = *to_free;
1053 	*to_free = skb;
1054 }
1055 
1056 static inline void __qdisc_drop_all(struct sk_buff *skb,
1057 				    struct sk_buff **to_free)
1058 {
1059 	if (skb->prev)
1060 		skb->prev->next = *to_free;
1061 	else
1062 		skb->next = *to_free;
1063 	*to_free = skb;
1064 }
1065 
1066 static inline unsigned int __qdisc_queue_drop_head(struct Qdisc *sch,
1067 						   struct qdisc_skb_head *qh,
1068 						   struct sk_buff **to_free)
1069 {
1070 	struct sk_buff *skb = __qdisc_dequeue_head(qh);
1071 
1072 	if (likely(skb != NULL)) {
1073 		unsigned int len = qdisc_pkt_len(skb);
1074 
1075 		qdisc_qstats_backlog_dec(sch, skb);
1076 		__qdisc_drop(skb, to_free);
1077 		return len;
1078 	}
1079 
1080 	return 0;
1081 }
1082 
1083 static inline struct sk_buff *qdisc_peek_head(struct Qdisc *sch)
1084 {
1085 	const struct qdisc_skb_head *qh = &sch->q;
1086 
1087 	return qh->head;
1088 }
1089 
1090 /* generic pseudo peek method for non-work-conserving qdisc */
1091 static inline struct sk_buff *qdisc_peek_dequeued(struct Qdisc *sch)
1092 {
1093 	struct sk_buff *skb = skb_peek(&sch->gso_skb);
1094 
1095 	/* we can reuse ->gso_skb because peek isn't called for root qdiscs */
1096 	if (!skb) {
1097 		skb = sch->dequeue(sch);
1098 
1099 		if (skb) {
1100 			__skb_queue_head(&sch->gso_skb, skb);
1101 			/* it's still part of the queue */
1102 			qdisc_qstats_backlog_inc(sch, skb);
1103 			sch->q.qlen++;
1104 		}
1105 	}
1106 
1107 	return skb;
1108 }
1109 
1110 static inline void qdisc_update_stats_at_dequeue(struct Qdisc *sch,
1111 						 struct sk_buff *skb)
1112 {
1113 	if (qdisc_is_percpu_stats(sch)) {
1114 		qdisc_qstats_cpu_backlog_dec(sch, skb);
1115 		qdisc_bstats_cpu_update(sch, skb);
1116 		qdisc_qstats_cpu_qlen_dec(sch);
1117 	} else {
1118 		qdisc_qstats_backlog_dec(sch, skb);
1119 		qdisc_bstats_update(sch, skb);
1120 		sch->q.qlen--;
1121 	}
1122 }
1123 
1124 static inline void qdisc_update_stats_at_enqueue(struct Qdisc *sch,
1125 						 unsigned int pkt_len)
1126 {
1127 	if (qdisc_is_percpu_stats(sch)) {
1128 		qdisc_qstats_cpu_qlen_inc(sch);
1129 		this_cpu_add(sch->cpu_qstats->backlog, pkt_len);
1130 	} else {
1131 		sch->qstats.backlog += pkt_len;
1132 		sch->q.qlen++;
1133 	}
1134 }
1135 
1136 /* use instead of qdisc->dequeue() for all qdiscs queried with ->peek() */
1137 static inline struct sk_buff *qdisc_dequeue_peeked(struct Qdisc *sch)
1138 {
1139 	struct sk_buff *skb = skb_peek(&sch->gso_skb);
1140 
1141 	if (skb) {
1142 		skb = __skb_dequeue(&sch->gso_skb);
1143 		if (qdisc_is_percpu_stats(sch)) {
1144 			qdisc_qstats_cpu_backlog_dec(sch, skb);
1145 			qdisc_qstats_cpu_qlen_dec(sch);
1146 		} else {
1147 			qdisc_qstats_backlog_dec(sch, skb);
1148 			sch->q.qlen--;
1149 		}
1150 	} else {
1151 		skb = sch->dequeue(sch);
1152 	}
1153 
1154 	return skb;
1155 }
1156 
1157 static inline void __qdisc_reset_queue(struct qdisc_skb_head *qh)
1158 {
1159 	/*
1160 	 * We do not know the backlog in bytes of this list, it
1161 	 * is up to the caller to correct it
1162 	 */
1163 	ASSERT_RTNL();
1164 	if (qh->qlen) {
1165 		rtnl_kfree_skbs(qh->head, qh->tail);
1166 
1167 		qh->head = NULL;
1168 		qh->tail = NULL;
1169 		qh->qlen = 0;
1170 	}
1171 }
1172 
1173 static inline void qdisc_reset_queue(struct Qdisc *sch)
1174 {
1175 	__qdisc_reset_queue(&sch->q);
1176 	sch->qstats.backlog = 0;
1177 }
1178 
1179 static inline struct Qdisc *qdisc_replace(struct Qdisc *sch, struct Qdisc *new,
1180 					  struct Qdisc **pold)
1181 {
1182 	struct Qdisc *old;
1183 
1184 	sch_tree_lock(sch);
1185 	old = *pold;
1186 	*pold = new;
1187 	if (old != NULL)
1188 		qdisc_purge_queue(old);
1189 	sch_tree_unlock(sch);
1190 
1191 	return old;
1192 }
1193 
1194 static inline void rtnl_qdisc_drop(struct sk_buff *skb, struct Qdisc *sch)
1195 {
1196 	rtnl_kfree_skbs(skb, skb);
1197 	qdisc_qstats_drop(sch);
1198 }
1199 
1200 static inline int qdisc_drop_cpu(struct sk_buff *skb, struct Qdisc *sch,
1201 				 struct sk_buff **to_free)
1202 {
1203 	__qdisc_drop(skb, to_free);
1204 	qdisc_qstats_cpu_drop(sch);
1205 
1206 	return NET_XMIT_DROP;
1207 }
1208 
1209 static inline int qdisc_drop(struct sk_buff *skb, struct Qdisc *sch,
1210 			     struct sk_buff **to_free)
1211 {
1212 	__qdisc_drop(skb, to_free);
1213 	qdisc_qstats_drop(sch);
1214 
1215 	return NET_XMIT_DROP;
1216 }
1217 
1218 static inline int qdisc_drop_all(struct sk_buff *skb, struct Qdisc *sch,
1219 				 struct sk_buff **to_free)
1220 {
1221 	__qdisc_drop_all(skb, to_free);
1222 	qdisc_qstats_drop(sch);
1223 
1224 	return NET_XMIT_DROP;
1225 }
1226 
1227 /* Length to Time (L2T) lookup in a qdisc_rate_table, to determine how
1228    long it will take to send a packet given its size.
1229  */
1230 static inline u32 qdisc_l2t(struct qdisc_rate_table* rtab, unsigned int pktlen)
1231 {
1232 	int slot = pktlen + rtab->rate.cell_align + rtab->rate.overhead;
1233 	if (slot < 0)
1234 		slot = 0;
1235 	slot >>= rtab->rate.cell_log;
1236 	if (slot > 255)
1237 		return rtab->data[255]*(slot >> 8) + rtab->data[slot & 0xFF];
1238 	return rtab->data[slot];
1239 }
1240 
1241 struct psched_ratecfg {
1242 	u64	rate_bytes_ps; /* bytes per second */
1243 	u32	mult;
1244 	u16	overhead;
1245 	u8	linklayer;
1246 	u8	shift;
1247 };
1248 
1249 static inline u64 psched_l2t_ns(const struct psched_ratecfg *r,
1250 				unsigned int len)
1251 {
1252 	len += r->overhead;
1253 
1254 	if (unlikely(r->linklayer == TC_LINKLAYER_ATM))
1255 		return ((u64)(DIV_ROUND_UP(len,48)*53) * r->mult) >> r->shift;
1256 
1257 	return ((u64)len * r->mult) >> r->shift;
1258 }
1259 
1260 void psched_ratecfg_precompute(struct psched_ratecfg *r,
1261 			       const struct tc_ratespec *conf,
1262 			       u64 rate64);
1263 
1264 static inline void psched_ratecfg_getrate(struct tc_ratespec *res,
1265 					  const struct psched_ratecfg *r)
1266 {
1267 	memset(res, 0, sizeof(*res));
1268 
1269 	/* legacy struct tc_ratespec has a 32bit @rate field
1270 	 * Qdisc using 64bit rate should add new attributes
1271 	 * in order to maintain compatibility.
1272 	 */
1273 	res->rate = min_t(u64, r->rate_bytes_ps, ~0U);
1274 
1275 	res->overhead = r->overhead;
1276 	res->linklayer = (r->linklayer & TC_LINKLAYER_MASK);
1277 }
1278 
1279 struct psched_pktrate {
1280 	u64	rate_pkts_ps; /* packets per second */
1281 	u32	mult;
1282 	u8	shift;
1283 };
1284 
1285 static inline u64 psched_pkt2t_ns(const struct psched_pktrate *r,
1286 				  unsigned int pkt_num)
1287 {
1288 	return ((u64)pkt_num * r->mult) >> r->shift;
1289 }
1290 
1291 void psched_ppscfg_precompute(struct psched_pktrate *r, u64 pktrate64);
1292 
1293 /* Mini Qdisc serves for specific needs of ingress/clsact Qdisc.
1294  * The fast path only needs to access filter list and to update stats
1295  */
1296 struct mini_Qdisc {
1297 	struct tcf_proto *filter_list;
1298 	struct tcf_block *block;
1299 	struct gnet_stats_basic_sync __percpu *cpu_bstats;
1300 	struct gnet_stats_queue	__percpu *cpu_qstats;
1301 	struct rcu_head rcu;
1302 };
1303 
1304 static inline void mini_qdisc_bstats_cpu_update(struct mini_Qdisc *miniq,
1305 						const struct sk_buff *skb)
1306 {
1307 	bstats_update(this_cpu_ptr(miniq->cpu_bstats), skb);
1308 }
1309 
1310 static inline void mini_qdisc_qstats_cpu_drop(struct mini_Qdisc *miniq)
1311 {
1312 	this_cpu_inc(miniq->cpu_qstats->drops);
1313 }
1314 
1315 struct mini_Qdisc_pair {
1316 	struct mini_Qdisc miniq1;
1317 	struct mini_Qdisc miniq2;
1318 	struct mini_Qdisc __rcu **p_miniq;
1319 };
1320 
1321 void mini_qdisc_pair_swap(struct mini_Qdisc_pair *miniqp,
1322 			  struct tcf_proto *tp_head);
1323 void mini_qdisc_pair_init(struct mini_Qdisc_pair *miniqp, struct Qdisc *qdisc,
1324 			  struct mini_Qdisc __rcu **p_miniq);
1325 void mini_qdisc_pair_block_init(struct mini_Qdisc_pair *miniqp,
1326 				struct tcf_block *block);
1327 
1328 void mq_change_real_num_tx(struct Qdisc *sch, unsigned int new_real_tx);
1329 
1330 int sch_frag_xmit_hook(struct sk_buff *skb, int (*xmit)(struct sk_buff *skb));
1331 
1332 #endif
1333