1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __NET_SCHED_GENERIC_H
3 #define __NET_SCHED_GENERIC_H
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 <net/gen_stats.h>
16 #include <net/rtnetlink.h>
23 struct qdisc_rate_table {
24 struct tc_ratespec rate;
26 struct qdisc_rate_table *next;
32 __QDISC_STATE_DEACTIVATED,
35 struct qdisc_size_table {
37 struct list_head list;
38 struct tc_sizespec szopts;
43 /* similar to sk_buff_head, but skb->prev pointer is undefined. */
44 struct qdisc_skb_head {
52 int (*enqueue)(struct sk_buff *skb,
54 struct sk_buff **to_free);
55 struct sk_buff * (*dequeue)(struct Qdisc *sch);
57 #define TCQ_F_BUILTIN 1
58 #define TCQ_F_INGRESS 2
59 #define TCQ_F_CAN_BYPASS 4
60 #define TCQ_F_MQROOT 8
61 #define TCQ_F_ONETXQUEUE 0x10 /* dequeue_skb() can assume all skbs are for
62 * q->dev_queue : It can test
63 * netif_xmit_frozen_or_stopped() before
64 * dequeueing next packet.
65 * Its true for MQ/MQPRIO slaves, or non
68 #define TCQ_F_WARN_NONWC (1 << 16)
69 #define TCQ_F_CPUSTATS 0x20 /* run using percpu statistics */
70 #define TCQ_F_NOPARENT 0x40 /* root of its hierarchy :
71 * qdisc_tree_decrease_qlen() should stop.
73 #define TCQ_F_INVISIBLE 0x80 /* invisible by default in dump */
74 #define TCQ_F_NOLOCK 0x100 /* qdisc does not require locking */
75 #define TCQ_F_OFFLOADED 0x200 /* qdisc is offloaded to HW */
77 const struct Qdisc_ops *ops;
78 struct qdisc_size_table __rcu *stab;
79 struct hlist_node hash;
83 struct netdev_queue *dev_queue;
85 struct net_rate_estimator __rcu *rate_est;
86 struct gnet_stats_basic_cpu __percpu *cpu_bstats;
87 struct gnet_stats_queue __percpu *cpu_qstats;
92 * For performance sake on SMP, we put highly modified fields at the end
94 struct sk_buff_head gso_skb ____cacheline_aligned_in_smp;
95 struct qdisc_skb_head q;
96 struct gnet_stats_basic_packed bstats;
98 struct gnet_stats_queue qstats;
100 struct Qdisc *next_sched;
101 struct sk_buff_head skb_bad_txq;
103 spinlock_t busylock ____cacheline_aligned_in_smp;
107 static inline void qdisc_refcount_inc(struct Qdisc *qdisc)
109 if (qdisc->flags & TCQ_F_BUILTIN)
111 refcount_inc(&qdisc->refcnt);
114 static inline bool qdisc_is_running(struct Qdisc *qdisc)
116 if (qdisc->flags & TCQ_F_NOLOCK)
117 return spin_is_locked(&qdisc->seqlock);
118 return (raw_read_seqcount(&qdisc->running) & 1) ? true : false;
121 static inline bool qdisc_run_begin(struct Qdisc *qdisc)
123 if (qdisc->flags & TCQ_F_NOLOCK) {
124 if (!spin_trylock(&qdisc->seqlock))
126 } else if (qdisc_is_running(qdisc)) {
129 /* Variant of write_seqcount_begin() telling lockdep a trylock
132 raw_write_seqcount_begin(&qdisc->running);
133 seqcount_acquire(&qdisc->running.dep_map, 0, 1, _RET_IP_);
137 static inline void qdisc_run_end(struct Qdisc *qdisc)
139 write_seqcount_end(&qdisc->running);
140 if (qdisc->flags & TCQ_F_NOLOCK)
141 spin_unlock(&qdisc->seqlock);
144 static inline bool qdisc_may_bulk(const struct Qdisc *qdisc)
146 return qdisc->flags & TCQ_F_ONETXQUEUE;
149 static inline int qdisc_avail_bulklimit(const struct netdev_queue *txq)
152 /* Non-BQL migrated drivers will return 0, too. */
153 return dql_avail(&txq->dql);
159 struct Qdisc_class_ops {
160 /* Child qdisc manipulation */
161 struct netdev_queue * (*select_queue)(struct Qdisc *, struct tcmsg *);
162 int (*graft)(struct Qdisc *, unsigned long cl,
163 struct Qdisc *, struct Qdisc **,
164 struct netlink_ext_ack *extack);
165 struct Qdisc * (*leaf)(struct Qdisc *, unsigned long cl);
166 void (*qlen_notify)(struct Qdisc *, unsigned long);
168 /* Class manipulation routines */
169 unsigned long (*find)(struct Qdisc *, u32 classid);
170 int (*change)(struct Qdisc *, u32, u32,
171 struct nlattr **, unsigned long *,
172 struct netlink_ext_ack *);
173 int (*delete)(struct Qdisc *, unsigned long);
174 void (*walk)(struct Qdisc *, struct qdisc_walker * arg);
176 /* Filter manipulation */
177 struct tcf_block * (*tcf_block)(struct Qdisc *sch,
179 struct netlink_ext_ack *extack);
180 unsigned long (*bind_tcf)(struct Qdisc *, unsigned long,
182 void (*unbind_tcf)(struct Qdisc *, unsigned long);
184 /* rtnetlink specific */
185 int (*dump)(struct Qdisc *, unsigned long,
186 struct sk_buff *skb, struct tcmsg*);
187 int (*dump_stats)(struct Qdisc *, unsigned long,
192 struct Qdisc_ops *next;
193 const struct Qdisc_class_ops *cl_ops;
196 unsigned int static_flags;
198 int (*enqueue)(struct sk_buff *skb,
200 struct sk_buff **to_free);
201 struct sk_buff * (*dequeue)(struct Qdisc *);
202 struct sk_buff * (*peek)(struct Qdisc *);
204 int (*init)(struct Qdisc *sch, struct nlattr *arg,
205 struct netlink_ext_ack *extack);
206 void (*reset)(struct Qdisc *);
207 void (*destroy)(struct Qdisc *);
208 int (*change)(struct Qdisc *sch,
210 struct netlink_ext_ack *extack);
211 void (*attach)(struct Qdisc *sch);
212 int (*change_tx_queue_len)(struct Qdisc *, unsigned int);
214 int (*dump)(struct Qdisc *, struct sk_buff *);
215 int (*dump_stats)(struct Qdisc *, struct gnet_dump *);
217 void (*ingress_block_set)(struct Qdisc *sch,
219 void (*egress_block_set)(struct Qdisc *sch,
221 u32 (*ingress_block_get)(struct Qdisc *sch);
222 u32 (*egress_block_get)(struct Qdisc *sch);
224 struct module *owner;
234 const struct tcf_proto *goto_tp;
238 struct tcf_proto_ops {
239 struct list_head head;
242 int (*classify)(struct sk_buff *,
243 const struct tcf_proto *,
244 struct tcf_result *);
245 int (*init)(struct tcf_proto*);
246 void (*destroy)(struct tcf_proto *tp,
247 struct netlink_ext_ack *extack);
249 void* (*get)(struct tcf_proto*, u32 handle);
250 int (*change)(struct net *net, struct sk_buff *,
251 struct tcf_proto*, unsigned long,
252 u32 handle, struct nlattr **,
254 struct netlink_ext_ack *);
255 int (*delete)(struct tcf_proto *tp, void *arg,
257 struct netlink_ext_ack *);
258 void (*walk)(struct tcf_proto*, struct tcf_walker *arg);
259 void (*bind_class)(void *, u32, unsigned long);
261 /* rtnetlink specific */
262 int (*dump)(struct net*, struct tcf_proto*, void *,
263 struct sk_buff *skb, struct tcmsg*);
265 struct module *owner;
269 /* Fast access part */
270 struct tcf_proto __rcu *next;
272 int (*classify)(struct sk_buff *,
273 const struct tcf_proto *,
274 struct tcf_result *);
280 const struct tcf_proto_ops *ops;
281 struct tcf_chain *chain;
285 struct qdisc_skb_cb {
286 unsigned int pkt_len;
287 u16 slave_dev_queue_mapping;
289 #define QDISC_CB_PRIV_LEN 20
290 unsigned char data[QDISC_CB_PRIV_LEN];
293 typedef void tcf_chain_head_change_t(struct tcf_proto *tp_head, void *priv);
296 struct tcf_proto __rcu *filter_chain;
297 struct list_head filter_chain_list;
298 struct list_head list;
299 struct tcf_block *block;
300 u32 index; /* chain index */
305 struct list_head chain_list;
306 u32 index; /* block index for shared blocks */
310 struct list_head cb_list;
311 struct list_head owner_list;
313 unsigned int offloadcnt; /* Number of oddloaded filters */
314 unsigned int nooffloaddevcnt; /* Number of devs unable to do offload */
317 static inline void tcf_block_offload_inc(struct tcf_block *block, u32 *flags)
319 if (*flags & TCA_CLS_FLAGS_IN_HW)
321 *flags |= TCA_CLS_FLAGS_IN_HW;
325 static inline void tcf_block_offload_dec(struct tcf_block *block, u32 *flags)
327 if (!(*flags & TCA_CLS_FLAGS_IN_HW))
329 *flags &= ~TCA_CLS_FLAGS_IN_HW;
333 static inline void qdisc_cb_private_validate(const struct sk_buff *skb, int sz)
335 struct qdisc_skb_cb *qcb;
337 BUILD_BUG_ON(sizeof(skb->cb) < offsetof(struct qdisc_skb_cb, data) + sz);
338 BUILD_BUG_ON(sizeof(qcb->data) < sz);
341 static inline int qdisc_qlen_cpu(const struct Qdisc *q)
343 return this_cpu_ptr(q->cpu_qstats)->qlen;
346 static inline int qdisc_qlen(const struct Qdisc *q)
351 static inline int qdisc_qlen_sum(const struct Qdisc *q)
353 __u32 qlen = q->qstats.qlen;
356 if (q->flags & TCQ_F_NOLOCK) {
357 for_each_possible_cpu(i)
358 qlen += per_cpu_ptr(q->cpu_qstats, i)->qlen;
366 static inline struct qdisc_skb_cb *qdisc_skb_cb(const struct sk_buff *skb)
368 return (struct qdisc_skb_cb *)skb->cb;
371 static inline spinlock_t *qdisc_lock(struct Qdisc *qdisc)
373 return &qdisc->q.lock;
376 static inline struct Qdisc *qdisc_root(const struct Qdisc *qdisc)
378 struct Qdisc *q = rcu_dereference_rtnl(qdisc->dev_queue->qdisc);
383 static inline struct Qdisc *qdisc_root_sleeping(const struct Qdisc *qdisc)
385 return qdisc->dev_queue->qdisc_sleeping;
388 /* The qdisc root lock is a mechanism by which to top level
389 * of a qdisc tree can be locked from any qdisc node in the
390 * forest. This allows changing the configuration of some
391 * aspect of the qdisc tree while blocking out asynchronous
392 * qdisc access in the packet processing paths.
394 * It is only legal to do this when the root will not change
395 * on us. Otherwise we'll potentially lock the wrong qdisc
396 * root. This is enforced by holding the RTNL semaphore, which
397 * all users of this lock accessor must do.
399 static inline spinlock_t *qdisc_root_lock(const struct Qdisc *qdisc)
401 struct Qdisc *root = qdisc_root(qdisc);
404 return qdisc_lock(root);
407 static inline spinlock_t *qdisc_root_sleeping_lock(const struct Qdisc *qdisc)
409 struct Qdisc *root = qdisc_root_sleeping(qdisc);
412 return qdisc_lock(root);
415 static inline seqcount_t *qdisc_root_sleeping_running(const struct Qdisc *qdisc)
417 struct Qdisc *root = qdisc_root_sleeping(qdisc);
420 return &root->running;
423 static inline struct net_device *qdisc_dev(const struct Qdisc *qdisc)
425 return qdisc->dev_queue->dev;
428 static inline void sch_tree_lock(const struct Qdisc *q)
430 spin_lock_bh(qdisc_root_sleeping_lock(q));
433 static inline void sch_tree_unlock(const struct Qdisc *q)
435 spin_unlock_bh(qdisc_root_sleeping_lock(q));
438 extern struct Qdisc noop_qdisc;
439 extern struct Qdisc_ops noop_qdisc_ops;
440 extern struct Qdisc_ops pfifo_fast_ops;
441 extern struct Qdisc_ops mq_qdisc_ops;
442 extern struct Qdisc_ops noqueue_qdisc_ops;
443 extern const struct Qdisc_ops *default_qdisc_ops;
444 static inline const struct Qdisc_ops *
445 get_default_qdisc_ops(const struct net_device *dev, int ntx)
447 return ntx < dev->real_num_tx_queues ?
448 default_qdisc_ops : &pfifo_fast_ops;
451 struct Qdisc_class_common {
453 struct hlist_node hnode;
456 struct Qdisc_class_hash {
457 struct hlist_head *hash;
458 unsigned int hashsize;
459 unsigned int hashmask;
460 unsigned int hashelems;
463 static inline unsigned int qdisc_class_hash(u32 id, u32 mask)
470 static inline struct Qdisc_class_common *
471 qdisc_class_find(const struct Qdisc_class_hash *hash, u32 id)
473 struct Qdisc_class_common *cl;
479 h = qdisc_class_hash(id, hash->hashmask);
480 hlist_for_each_entry(cl, &hash->hash[h], hnode) {
481 if (cl->classid == id)
487 static inline int tc_classid_to_hwtc(struct net_device *dev, u32 classid)
489 u32 hwtc = TC_H_MIN(classid) - TC_H_MIN_PRIORITY;
491 return (hwtc < netdev_get_num_tc(dev)) ? hwtc : -EINVAL;
494 int qdisc_class_hash_init(struct Qdisc_class_hash *);
495 void qdisc_class_hash_insert(struct Qdisc_class_hash *,
496 struct Qdisc_class_common *);
497 void qdisc_class_hash_remove(struct Qdisc_class_hash *,
498 struct Qdisc_class_common *);
499 void qdisc_class_hash_grow(struct Qdisc *, struct Qdisc_class_hash *);
500 void qdisc_class_hash_destroy(struct Qdisc_class_hash *);
502 int dev_qdisc_change_tx_queue_len(struct net_device *dev);
503 void dev_init_scheduler(struct net_device *dev);
504 void dev_shutdown(struct net_device *dev);
505 void dev_activate(struct net_device *dev);
506 void dev_deactivate(struct net_device *dev);
507 void dev_deactivate_many(struct list_head *head);
508 struct Qdisc *dev_graft_qdisc(struct netdev_queue *dev_queue,
509 struct Qdisc *qdisc);
510 void qdisc_reset(struct Qdisc *qdisc);
511 void qdisc_destroy(struct Qdisc *qdisc);
512 void qdisc_tree_reduce_backlog(struct Qdisc *qdisc, unsigned int n,
514 struct Qdisc *qdisc_alloc(struct netdev_queue *dev_queue,
515 const struct Qdisc_ops *ops,
516 struct netlink_ext_ack *extack);
517 void qdisc_free(struct Qdisc *qdisc);
518 struct Qdisc *qdisc_create_dflt(struct netdev_queue *dev_queue,
519 const struct Qdisc_ops *ops, u32 parentid,
520 struct netlink_ext_ack *extack);
521 void __qdisc_calculate_pkt_len(struct sk_buff *skb,
522 const struct qdisc_size_table *stab);
523 int skb_do_redirect(struct sk_buff *);
525 static inline void skb_reset_tc(struct sk_buff *skb)
527 #ifdef CONFIG_NET_CLS_ACT
528 skb->tc_redirected = 0;
532 static inline bool skb_at_tc_ingress(const struct sk_buff *skb)
534 #ifdef CONFIG_NET_CLS_ACT
535 return skb->tc_at_ingress;
541 static inline bool skb_skip_tc_classify(struct sk_buff *skb)
543 #ifdef CONFIG_NET_CLS_ACT
544 if (skb->tc_skip_classify) {
545 skb->tc_skip_classify = 0;
552 /* Reset all TX qdiscs greater than index of a device. */
553 static inline void qdisc_reset_all_tx_gt(struct net_device *dev, unsigned int i)
557 for (; i < dev->num_tx_queues; i++) {
558 qdisc = rtnl_dereference(netdev_get_tx_queue(dev, i)->qdisc);
560 spin_lock_bh(qdisc_lock(qdisc));
562 spin_unlock_bh(qdisc_lock(qdisc));
567 static inline void qdisc_reset_all_tx(struct net_device *dev)
569 qdisc_reset_all_tx_gt(dev, 0);
572 /* Are all TX queues of the device empty? */
573 static inline bool qdisc_all_tx_empty(const struct net_device *dev)
578 for (i = 0; i < dev->num_tx_queues; i++) {
579 struct netdev_queue *txq = netdev_get_tx_queue(dev, i);
580 const struct Qdisc *q = rcu_dereference(txq->qdisc);
591 /* Are any of the TX qdiscs changing? */
592 static inline bool qdisc_tx_changing(const struct net_device *dev)
596 for (i = 0; i < dev->num_tx_queues; i++) {
597 struct netdev_queue *txq = netdev_get_tx_queue(dev, i);
598 if (rcu_access_pointer(txq->qdisc) != txq->qdisc_sleeping)
604 /* Is the device using the noop qdisc on all queues? */
605 static inline bool qdisc_tx_is_noop(const struct net_device *dev)
609 for (i = 0; i < dev->num_tx_queues; i++) {
610 struct netdev_queue *txq = netdev_get_tx_queue(dev, i);
611 if (rcu_access_pointer(txq->qdisc) != &noop_qdisc)
617 static inline unsigned int qdisc_pkt_len(const struct sk_buff *skb)
619 return qdisc_skb_cb(skb)->pkt_len;
622 /* additional qdisc xmit flags (NET_XMIT_MASK in linux/netdevice.h) */
623 enum net_xmit_qdisc_t {
624 __NET_XMIT_STOLEN = 0x00010000,
625 __NET_XMIT_BYPASS = 0x00020000,
628 #ifdef CONFIG_NET_CLS_ACT
629 #define net_xmit_drop_count(e) ((e) & __NET_XMIT_STOLEN ? 0 : 1)
631 #define net_xmit_drop_count(e) (1)
634 static inline void qdisc_calculate_pkt_len(struct sk_buff *skb,
635 const struct Qdisc *sch)
637 #ifdef CONFIG_NET_SCHED
638 struct qdisc_size_table *stab = rcu_dereference_bh(sch->stab);
641 __qdisc_calculate_pkt_len(skb, stab);
645 static inline int qdisc_enqueue(struct sk_buff *skb, struct Qdisc *sch,
646 struct sk_buff **to_free)
648 qdisc_calculate_pkt_len(skb, sch);
649 return sch->enqueue(skb, sch, to_free);
652 static inline bool qdisc_is_percpu_stats(const struct Qdisc *q)
654 return q->flags & TCQ_F_CPUSTATS;
657 static inline void _bstats_update(struct gnet_stats_basic_packed *bstats,
658 __u64 bytes, __u32 packets)
660 bstats->bytes += bytes;
661 bstats->packets += packets;
664 static inline void bstats_update(struct gnet_stats_basic_packed *bstats,
665 const struct sk_buff *skb)
667 _bstats_update(bstats,
669 skb_is_gso(skb) ? skb_shinfo(skb)->gso_segs : 1);
672 static inline void _bstats_cpu_update(struct gnet_stats_basic_cpu *bstats,
673 __u64 bytes, __u32 packets)
675 u64_stats_update_begin(&bstats->syncp);
676 _bstats_update(&bstats->bstats, bytes, packets);
677 u64_stats_update_end(&bstats->syncp);
680 static inline void bstats_cpu_update(struct gnet_stats_basic_cpu *bstats,
681 const struct sk_buff *skb)
683 u64_stats_update_begin(&bstats->syncp);
684 bstats_update(&bstats->bstats, skb);
685 u64_stats_update_end(&bstats->syncp);
688 static inline void qdisc_bstats_cpu_update(struct Qdisc *sch,
689 const struct sk_buff *skb)
691 bstats_cpu_update(this_cpu_ptr(sch->cpu_bstats), skb);
694 static inline void qdisc_bstats_update(struct Qdisc *sch,
695 const struct sk_buff *skb)
697 bstats_update(&sch->bstats, skb);
700 static inline void qdisc_qstats_backlog_dec(struct Qdisc *sch,
701 const struct sk_buff *skb)
703 sch->qstats.backlog -= qdisc_pkt_len(skb);
706 static inline void qdisc_qstats_cpu_backlog_dec(struct Qdisc *sch,
707 const struct sk_buff *skb)
709 this_cpu_sub(sch->cpu_qstats->backlog, qdisc_pkt_len(skb));
712 static inline void qdisc_qstats_backlog_inc(struct Qdisc *sch,
713 const struct sk_buff *skb)
715 sch->qstats.backlog += qdisc_pkt_len(skb);
718 static inline void qdisc_qstats_cpu_backlog_inc(struct Qdisc *sch,
719 const struct sk_buff *skb)
721 this_cpu_add(sch->cpu_qstats->backlog, qdisc_pkt_len(skb));
724 static inline void qdisc_qstats_cpu_qlen_inc(struct Qdisc *sch)
726 this_cpu_inc(sch->cpu_qstats->qlen);
729 static inline void qdisc_qstats_cpu_qlen_dec(struct Qdisc *sch)
731 this_cpu_dec(sch->cpu_qstats->qlen);
734 static inline void qdisc_qstats_cpu_requeues_inc(struct Qdisc *sch)
736 this_cpu_inc(sch->cpu_qstats->requeues);
739 static inline void __qdisc_qstats_drop(struct Qdisc *sch, int count)
741 sch->qstats.drops += count;
744 static inline void qstats_drop_inc(struct gnet_stats_queue *qstats)
749 static inline void qstats_overlimit_inc(struct gnet_stats_queue *qstats)
751 qstats->overlimits++;
754 static inline void qdisc_qstats_drop(struct Qdisc *sch)
756 qstats_drop_inc(&sch->qstats);
759 static inline void qdisc_qstats_cpu_drop(struct Qdisc *sch)
761 this_cpu_inc(sch->cpu_qstats->drops);
764 static inline void qdisc_qstats_overlimit(struct Qdisc *sch)
766 sch->qstats.overlimits++;
769 static inline void qdisc_skb_head_init(struct qdisc_skb_head *qh)
776 static inline int __qdisc_enqueue_tail(struct sk_buff *skb, struct Qdisc *sch,
777 struct qdisc_skb_head *qh)
779 struct sk_buff *last = qh->tail;
790 qdisc_qstats_backlog_inc(sch, skb);
792 return NET_XMIT_SUCCESS;
795 static inline int qdisc_enqueue_tail(struct sk_buff *skb, struct Qdisc *sch)
797 return __qdisc_enqueue_tail(skb, sch, &sch->q);
800 static inline struct sk_buff *__qdisc_dequeue_head(struct qdisc_skb_head *qh)
802 struct sk_buff *skb = qh->head;
804 if (likely(skb != NULL)) {
805 qh->head = skb->next;
807 if (qh->head == NULL)
815 static inline struct sk_buff *qdisc_dequeue_head(struct Qdisc *sch)
817 struct sk_buff *skb = __qdisc_dequeue_head(&sch->q);
819 if (likely(skb != NULL)) {
820 qdisc_qstats_backlog_dec(sch, skb);
821 qdisc_bstats_update(sch, skb);
827 /* Instead of calling kfree_skb() while root qdisc lock is held,
828 * queue the skb for future freeing at end of __dev_xmit_skb()
830 static inline void __qdisc_drop(struct sk_buff *skb, struct sk_buff **to_free)
832 skb->next = *to_free;
836 static inline void __qdisc_drop_all(struct sk_buff *skb,
837 struct sk_buff **to_free)
840 skb->prev->next = *to_free;
842 skb->next = *to_free;
846 static inline unsigned int __qdisc_queue_drop_head(struct Qdisc *sch,
847 struct qdisc_skb_head *qh,
848 struct sk_buff **to_free)
850 struct sk_buff *skb = __qdisc_dequeue_head(qh);
852 if (likely(skb != NULL)) {
853 unsigned int len = qdisc_pkt_len(skb);
855 qdisc_qstats_backlog_dec(sch, skb);
856 __qdisc_drop(skb, to_free);
863 static inline unsigned int qdisc_queue_drop_head(struct Qdisc *sch,
864 struct sk_buff **to_free)
866 return __qdisc_queue_drop_head(sch, &sch->q, to_free);
869 static inline struct sk_buff *qdisc_peek_head(struct Qdisc *sch)
871 const struct qdisc_skb_head *qh = &sch->q;
876 /* generic pseudo peek method for non-work-conserving qdisc */
877 static inline struct sk_buff *qdisc_peek_dequeued(struct Qdisc *sch)
879 struct sk_buff *skb = skb_peek(&sch->gso_skb);
881 /* we can reuse ->gso_skb because peek isn't called for root qdiscs */
883 skb = sch->dequeue(sch);
886 __skb_queue_head(&sch->gso_skb, skb);
887 /* it's still part of the queue */
888 qdisc_qstats_backlog_inc(sch, skb);
896 /* use instead of qdisc->dequeue() for all qdiscs queried with ->peek() */
897 static inline struct sk_buff *qdisc_dequeue_peeked(struct Qdisc *sch)
899 struct sk_buff *skb = skb_peek(&sch->gso_skb);
902 skb = __skb_dequeue(&sch->gso_skb);
903 qdisc_qstats_backlog_dec(sch, skb);
906 skb = sch->dequeue(sch);
912 static inline void __qdisc_reset_queue(struct qdisc_skb_head *qh)
915 * We do not know the backlog in bytes of this list, it
916 * is up to the caller to correct it
920 rtnl_kfree_skbs(qh->head, qh->tail);
928 static inline void qdisc_reset_queue(struct Qdisc *sch)
930 __qdisc_reset_queue(&sch->q);
931 sch->qstats.backlog = 0;
934 static inline struct Qdisc *qdisc_replace(struct Qdisc *sch, struct Qdisc *new,
943 unsigned int qlen = old->q.qlen;
944 unsigned int backlog = old->qstats.backlog;
947 qdisc_tree_reduce_backlog(old, qlen, backlog);
949 sch_tree_unlock(sch);
954 static inline void rtnl_qdisc_drop(struct sk_buff *skb, struct Qdisc *sch)
956 rtnl_kfree_skbs(skb, skb);
957 qdisc_qstats_drop(sch);
960 static inline int qdisc_drop_cpu(struct sk_buff *skb, struct Qdisc *sch,
961 struct sk_buff **to_free)
963 __qdisc_drop(skb, to_free);
964 qdisc_qstats_cpu_drop(sch);
966 return NET_XMIT_DROP;
969 static inline int qdisc_drop(struct sk_buff *skb, struct Qdisc *sch,
970 struct sk_buff **to_free)
972 __qdisc_drop(skb, to_free);
973 qdisc_qstats_drop(sch);
975 return NET_XMIT_DROP;
978 static inline int qdisc_drop_all(struct sk_buff *skb, struct Qdisc *sch,
979 struct sk_buff **to_free)
981 __qdisc_drop_all(skb, to_free);
982 qdisc_qstats_drop(sch);
984 return NET_XMIT_DROP;
987 /* Length to Time (L2T) lookup in a qdisc_rate_table, to determine how
988 long it will take to send a packet given its size.
990 static inline u32 qdisc_l2t(struct qdisc_rate_table* rtab, unsigned int pktlen)
992 int slot = pktlen + rtab->rate.cell_align + rtab->rate.overhead;
995 slot >>= rtab->rate.cell_log;
997 return rtab->data[255]*(slot >> 8) + rtab->data[slot & 0xFF];
998 return rtab->data[slot];
1001 struct psched_ratecfg {
1002 u64 rate_bytes_ps; /* bytes per second */
1009 static inline u64 psched_l2t_ns(const struct psched_ratecfg *r,
1014 if (unlikely(r->linklayer == TC_LINKLAYER_ATM))
1015 return ((u64)(DIV_ROUND_UP(len,48)*53) * r->mult) >> r->shift;
1017 return ((u64)len * r->mult) >> r->shift;
1020 void psched_ratecfg_precompute(struct psched_ratecfg *r,
1021 const struct tc_ratespec *conf,
1024 static inline void psched_ratecfg_getrate(struct tc_ratespec *res,
1025 const struct psched_ratecfg *r)
1027 memset(res, 0, sizeof(*res));
1029 /* legacy struct tc_ratespec has a 32bit @rate field
1030 * Qdisc using 64bit rate should add new attributes
1031 * in order to maintain compatibility.
1033 res->rate = min_t(u64, r->rate_bytes_ps, ~0U);
1035 res->overhead = r->overhead;
1036 res->linklayer = (r->linklayer & TC_LINKLAYER_MASK);
1039 /* Mini Qdisc serves for specific needs of ingress/clsact Qdisc.
1040 * The fast path only needs to access filter list and to update stats
1043 struct tcf_proto *filter_list;
1044 struct gnet_stats_basic_cpu __percpu *cpu_bstats;
1045 struct gnet_stats_queue __percpu *cpu_qstats;
1046 struct rcu_head rcu;
1049 static inline void mini_qdisc_bstats_cpu_update(struct mini_Qdisc *miniq,
1050 const struct sk_buff *skb)
1052 bstats_cpu_update(this_cpu_ptr(miniq->cpu_bstats), skb);
1055 static inline void mini_qdisc_qstats_cpu_drop(struct mini_Qdisc *miniq)
1057 this_cpu_inc(miniq->cpu_qstats->drops);
1060 struct mini_Qdisc_pair {
1061 struct mini_Qdisc miniq1;
1062 struct mini_Qdisc miniq2;
1063 struct mini_Qdisc __rcu **p_miniq;
1066 void mini_qdisc_pair_swap(struct mini_Qdisc_pair *miniqp,
1067 struct tcf_proto *tp_head);
1068 void mini_qdisc_pair_init(struct mini_Qdisc_pair *miniqp, struct Qdisc *qdisc,
1069 struct mini_Qdisc __rcu **p_miniq);