^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * net/sched/sch_generic.c Generic packet scheduler routines.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Jamal Hadi Salim, <hadi@cyberus.ca> 990601
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * - Ingress support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/bitops.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/netdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/skbuff.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/rtnetlink.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/rcupdate.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/list.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/if_vlan.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <linux/skb_array.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <linux/if_macvlan.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <net/sch_generic.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include <net/pkt_sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #include <net/dst.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #include <trace/events/qdisc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #include <trace/events/net.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #include <net/xfrm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) /* Qdisc to use by default */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) const struct Qdisc_ops *default_qdisc_ops = &pfifo_fast_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) EXPORT_SYMBOL(default_qdisc_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) static void qdisc_maybe_clear_missed(struct Qdisc *q,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) const struct netdev_queue *txq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) clear_bit(__QDISC_STATE_MISSED, &q->state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) /* Make sure the below netif_xmit_frozen_or_stopped()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) * checking happens after clearing STATE_MISSED.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) smp_mb__after_atomic();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) /* Checking netif_xmit_frozen_or_stopped() again to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) * make sure STATE_MISSED is set if the STATE_MISSED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) * set by netif_tx_wake_queue()'s rescheduling of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) * net_tx_action() is cleared by the above clear_bit().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) if (!netif_xmit_frozen_or_stopped(txq))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) set_bit(__QDISC_STATE_MISSED, &q->state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) /* Main transmission queue. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) /* Modifications to data participating in scheduling must be protected with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) * qdisc_lock(qdisc) spinlock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) * The idea is the following:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) * - enqueue, dequeue are serialized via qdisc root lock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) * - ingress filtering is also serialized via qdisc root lock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) * - updates to tree and tree walking are only done under the rtnl mutex.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) #define SKB_XOFF_MAGIC ((struct sk_buff *)1UL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) static inline struct sk_buff *__skb_dequeue_bad_txq(struct Qdisc *q)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) const struct netdev_queue *txq = q->dev_queue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) spinlock_t *lock = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) if (q->flags & TCQ_F_NOLOCK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) lock = qdisc_lock(q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) spin_lock(lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) skb = skb_peek(&q->skb_bad_txq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) if (skb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) /* check the reason of requeuing without tx lock first */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) txq = skb_get_tx_queue(txq->dev, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) if (!netif_xmit_frozen_or_stopped(txq)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) skb = __skb_dequeue(&q->skb_bad_txq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) if (qdisc_is_percpu_stats(q)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) qdisc_qstats_cpu_backlog_dec(q, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) qdisc_qstats_cpu_qlen_dec(q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) qdisc_qstats_backlog_dec(q, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) q->q.qlen--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) skb = SKB_XOFF_MAGIC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) qdisc_maybe_clear_missed(q, txq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) if (lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) spin_unlock(lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) return skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) static inline struct sk_buff *qdisc_dequeue_skb_bad_txq(struct Qdisc *q)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) struct sk_buff *skb = skb_peek(&q->skb_bad_txq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) if (unlikely(skb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) skb = __skb_dequeue_bad_txq(q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) return skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) static inline void qdisc_enqueue_skb_bad_txq(struct Qdisc *q,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) spinlock_t *lock = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) if (q->flags & TCQ_F_NOLOCK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) lock = qdisc_lock(q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) spin_lock(lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) __skb_queue_tail(&q->skb_bad_txq, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) if (qdisc_is_percpu_stats(q)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) qdisc_qstats_cpu_backlog_inc(q, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) qdisc_qstats_cpu_qlen_inc(q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) qdisc_qstats_backlog_inc(q, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) q->q.qlen++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) if (lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) spin_unlock(lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) static inline void dev_requeue_skb(struct sk_buff *skb, struct Qdisc *q)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) spinlock_t *lock = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) if (q->flags & TCQ_F_NOLOCK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) lock = qdisc_lock(q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) spin_lock(lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) while (skb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) struct sk_buff *next = skb->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) __skb_queue_tail(&q->gso_skb, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) /* it's still part of the queue */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) if (qdisc_is_percpu_stats(q)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) qdisc_qstats_cpu_requeues_inc(q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) qdisc_qstats_cpu_backlog_inc(q, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) qdisc_qstats_cpu_qlen_inc(q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) q->qstats.requeues++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) qdisc_qstats_backlog_inc(q, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) q->q.qlen++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) skb = next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) if (lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) spin_unlock(lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) __netif_schedule(q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) static void try_bulk_dequeue_skb(struct Qdisc *q,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) const struct netdev_queue *txq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) int *packets)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) int bytelimit = qdisc_avail_bulklimit(txq) - skb->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) while (bytelimit > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) struct sk_buff *nskb = q->dequeue(q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) if (!nskb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) bytelimit -= nskb->len; /* covers GSO len */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) skb->next = nskb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) skb = nskb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) (*packets)++; /* GSO counts as one pkt */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) skb_mark_not_on_list(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) /* This variant of try_bulk_dequeue_skb() makes sure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) * all skbs in the chain are for the same txq
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) static void try_bulk_dequeue_skb_slow(struct Qdisc *q,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) int *packets)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) int mapping = skb_get_queue_mapping(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) struct sk_buff *nskb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) int cnt = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) nskb = q->dequeue(q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) if (!nskb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) if (unlikely(skb_get_queue_mapping(nskb) != mapping)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) qdisc_enqueue_skb_bad_txq(q, nskb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) skb->next = nskb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) skb = nskb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) } while (++cnt < 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) (*packets) += cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) skb_mark_not_on_list(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) /* Note that dequeue_skb can possibly return a SKB list (via skb->next).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) * A requeued skb (via q->gso_skb) can also be a SKB list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) static struct sk_buff *dequeue_skb(struct Qdisc *q, bool *validate,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) int *packets)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) const struct netdev_queue *txq = q->dev_queue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) struct sk_buff *skb = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) *packets = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) if (unlikely(!skb_queue_empty(&q->gso_skb))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) spinlock_t *lock = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) if (q->flags & TCQ_F_NOLOCK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) lock = qdisc_lock(q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) spin_lock(lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) skb = skb_peek(&q->gso_skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) /* skb may be null if another cpu pulls gso_skb off in between
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) * empty check and lock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) if (!skb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) if (lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) spin_unlock(lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) goto validate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) /* skb in gso_skb were already validated */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) *validate = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) if (xfrm_offload(skb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) *validate = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) /* check the reason of requeuing without tx lock first */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) txq = skb_get_tx_queue(txq->dev, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) if (!netif_xmit_frozen_or_stopped(txq)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) skb = __skb_dequeue(&q->gso_skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) if (qdisc_is_percpu_stats(q)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) qdisc_qstats_cpu_backlog_dec(q, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) qdisc_qstats_cpu_qlen_dec(q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) qdisc_qstats_backlog_dec(q, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) q->q.qlen--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) skb = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) qdisc_maybe_clear_missed(q, txq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) if (lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) spin_unlock(lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) goto trace;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) validate:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) *validate = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) if ((q->flags & TCQ_F_ONETXQUEUE) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) netif_xmit_frozen_or_stopped(txq)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) qdisc_maybe_clear_missed(q, txq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) return skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) skb = qdisc_dequeue_skb_bad_txq(q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) if (unlikely(skb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) if (skb == SKB_XOFF_MAGIC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) goto bulk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) skb = q->dequeue(q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) if (skb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) bulk:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) if (qdisc_may_bulk(q))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) try_bulk_dequeue_skb(q, skb, txq, packets);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) try_bulk_dequeue_skb_slow(q, skb, packets);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) trace:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) trace_qdisc_dequeue(q, txq, *packets, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) return skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) * Transmit possibly several skbs, and handle the return status as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) * required. Owning running seqcount bit guarantees that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) * only one CPU can execute this function.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) * Returns to the caller:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) * false - hardware queue frozen backoff
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) * true - feel free to send more pkts
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) bool sch_direct_xmit(struct sk_buff *skb, struct Qdisc *q,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) struct net_device *dev, struct netdev_queue *txq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) spinlock_t *root_lock, bool validate)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) int ret = NETDEV_TX_BUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) bool again = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) /* And release qdisc */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) if (root_lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) spin_unlock(root_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) /* Note that we validate skb (GSO, checksum, ...) outside of locks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) if (validate)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) skb = validate_xmit_skb_list(skb, dev, &again);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) #ifdef CONFIG_XFRM_OFFLOAD
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) if (unlikely(again)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) if (root_lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) spin_lock(root_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) dev_requeue_skb(skb, q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) if (likely(skb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) HARD_TX_LOCK(dev, txq, smp_processor_id());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) if (!netif_xmit_frozen_or_stopped(txq))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) skb = dev_hard_start_xmit(skb, dev, txq, &ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) qdisc_maybe_clear_missed(q, txq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) HARD_TX_UNLOCK(dev, txq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) if (root_lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) spin_lock(root_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) if (root_lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) spin_lock(root_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) if (!dev_xmit_complete(ret)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) /* Driver returned NETDEV_TX_BUSY - requeue skb */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) if (unlikely(ret != NETDEV_TX_BUSY))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) net_warn_ratelimited("BUG %s code %d qlen %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) dev->name, ret, q->q.qlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) dev_requeue_skb(skb, q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) * NOTE: Called under qdisc_lock(q) with locally disabled BH.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) * running seqcount guarantees only one CPU can process
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) * this qdisc at a time. qdisc_lock(q) serializes queue accesses for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) * this queue.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) * netif_tx_lock serializes accesses to device driver.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) * qdisc_lock(q) and netif_tx_lock are mutually exclusive,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) * if one is grabbed, another must be free.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) * Note, that this procedure can be called by a watchdog timer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) * Returns to the caller:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) * 0 - queue is empty or throttled.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) * >0 - queue is not empty.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) static inline bool qdisc_restart(struct Qdisc *q, int *packets)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) spinlock_t *root_lock = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) struct netdev_queue *txq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) struct net_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) bool validate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) /* Dequeue packet */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) skb = dequeue_skb(q, &validate, packets);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) if (unlikely(!skb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) if (!(q->flags & TCQ_F_NOLOCK))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) root_lock = qdisc_lock(q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) dev = qdisc_dev(q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) txq = skb_get_tx_queue(dev, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) return sch_direct_xmit(skb, q, dev, txq, root_lock, validate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) void __qdisc_run(struct Qdisc *q)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) int quota = dev_tx_weight;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) int packets;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) while (qdisc_restart(q, &packets)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) quota -= packets;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) if (quota <= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) __netif_schedule(q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) unsigned long dev_trans_start(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) unsigned long val, res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) if (is_vlan_dev(dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) dev = vlan_dev_real_dev(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) else if (netif_is_macvlan(dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) dev = macvlan_dev_real_dev(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) res = netdev_get_tx_queue(dev, 0)->trans_start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) for (i = 1; i < dev->num_tx_queues; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) val = netdev_get_tx_queue(dev, i)->trans_start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) if (val && time_after(val, res))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) res = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) EXPORT_SYMBOL(dev_trans_start);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) static void dev_watchdog(struct timer_list *t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) struct net_device *dev = from_timer(dev, t, watchdog_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) netif_tx_lock(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) if (!qdisc_tx_is_noop(dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) if (netif_device_present(dev) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) netif_running(dev) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) netif_carrier_ok(dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) int some_queue_timedout = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) unsigned long trans_start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) for (i = 0; i < dev->num_tx_queues; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) struct netdev_queue *txq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) txq = netdev_get_tx_queue(dev, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) trans_start = txq->trans_start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) if (netif_xmit_stopped(txq) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) time_after(jiffies, (trans_start +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) dev->watchdog_timeo))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) some_queue_timedout = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) txq->trans_timeout++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) if (some_queue_timedout) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) trace_net_dev_xmit_timeout(dev, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) WARN_ONCE(1, KERN_INFO "NETDEV WATCHDOG: %s (%s): transmit queue %u timed out\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) dev->name, netdev_drivername(dev), i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) dev->netdev_ops->ndo_tx_timeout(dev, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) if (!mod_timer(&dev->watchdog_timer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) round_jiffies(jiffies +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) dev->watchdog_timeo)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) dev_hold(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) netif_tx_unlock(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) dev_put(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) void __netdev_watchdog_up(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) if (dev->netdev_ops->ndo_tx_timeout) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) if (dev->watchdog_timeo <= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) dev->watchdog_timeo = 5*HZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) if (!mod_timer(&dev->watchdog_timer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) round_jiffies(jiffies + dev->watchdog_timeo)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) dev_hold(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) EXPORT_SYMBOL_GPL(__netdev_watchdog_up);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) static void dev_watchdog_up(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) __netdev_watchdog_up(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) static void dev_watchdog_down(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) netif_tx_lock_bh(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) if (del_timer(&dev->watchdog_timer))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) dev_put(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) netif_tx_unlock_bh(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) * netif_carrier_on - set carrier
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) * @dev: network device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) * Device has detected acquisition of carrier.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) void netif_carrier_on(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) if (test_and_clear_bit(__LINK_STATE_NOCARRIER, &dev->state)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) if (dev->reg_state == NETREG_UNINITIALIZED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) atomic_inc(&dev->carrier_up_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) linkwatch_fire_event(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) if (netif_running(dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) __netdev_watchdog_up(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) EXPORT_SYMBOL(netif_carrier_on);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) * netif_carrier_off - clear carrier
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) * @dev: network device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) * Device has detected loss of carrier.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) void netif_carrier_off(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) if (!test_and_set_bit(__LINK_STATE_NOCARRIER, &dev->state)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) if (dev->reg_state == NETREG_UNINITIALIZED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) atomic_inc(&dev->carrier_down_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) linkwatch_fire_event(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) EXPORT_SYMBOL(netif_carrier_off);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) /* "NOOP" scheduler: the best scheduler, recommended for all interfaces
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) under all circumstances. It is difficult to invent anything faster or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) cheaper.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) static int noop_enqueue(struct sk_buff *skb, struct Qdisc *qdisc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) struct sk_buff **to_free)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) __qdisc_drop(skb, to_free);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) return NET_XMIT_CN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) static struct sk_buff *noop_dequeue(struct Qdisc *qdisc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) struct Qdisc_ops noop_qdisc_ops __read_mostly = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) .id = "noop",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) .priv_size = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) .enqueue = noop_enqueue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) .dequeue = noop_dequeue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) .peek = noop_dequeue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) static struct netdev_queue noop_netdev_queue = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) RCU_POINTER_INITIALIZER(qdisc, &noop_qdisc),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) .qdisc_sleeping = &noop_qdisc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) struct Qdisc noop_qdisc = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) .enqueue = noop_enqueue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) .dequeue = noop_dequeue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) .flags = TCQ_F_BUILTIN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) .ops = &noop_qdisc_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) .q.lock = __SPIN_LOCK_UNLOCKED(noop_qdisc.q.lock),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) .dev_queue = &noop_netdev_queue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) .running = SEQCNT_ZERO(noop_qdisc.running),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) .busylock = __SPIN_LOCK_UNLOCKED(noop_qdisc.busylock),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) .gso_skb = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) .next = (struct sk_buff *)&noop_qdisc.gso_skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) .prev = (struct sk_buff *)&noop_qdisc.gso_skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) .qlen = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) .lock = __SPIN_LOCK_UNLOCKED(noop_qdisc.gso_skb.lock),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) .skb_bad_txq = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) .next = (struct sk_buff *)&noop_qdisc.skb_bad_txq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) .prev = (struct sk_buff *)&noop_qdisc.skb_bad_txq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) .qlen = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) .lock = __SPIN_LOCK_UNLOCKED(noop_qdisc.skb_bad_txq.lock),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) EXPORT_SYMBOL(noop_qdisc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) static int noqueue_init(struct Qdisc *qdisc, struct nlattr *opt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) struct netlink_ext_ack *extack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) /* register_qdisc() assigns a default of noop_enqueue if unset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) * but __dev_queue_xmit() treats noqueue only as such
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) * if this is NULL - so clear it here. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) qdisc->enqueue = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) struct Qdisc_ops noqueue_qdisc_ops __read_mostly = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) .id = "noqueue",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) .priv_size = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) .init = noqueue_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) .enqueue = noop_enqueue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) .dequeue = noop_dequeue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) .peek = noop_dequeue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) static const u8 prio2band[TC_PRIO_MAX + 1] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) 1, 2, 2, 2, 1, 2, 0, 0 , 1, 1, 1, 1, 1, 1, 1, 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) /* 3-band FIFO queue: old style, but should be a bit faster than
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) generic prio+fifo combination.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) #define PFIFO_FAST_BANDS 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) * Private data for a pfifo_fast scheduler containing:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) * - rings for priority bands
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) struct pfifo_fast_priv {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) struct skb_array q[PFIFO_FAST_BANDS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) static inline struct skb_array *band2list(struct pfifo_fast_priv *priv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) int band)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) return &priv->q[band];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) static int pfifo_fast_enqueue(struct sk_buff *skb, struct Qdisc *qdisc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) struct sk_buff **to_free)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) int band = prio2band[skb->priority & TC_PRIO_MAX];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) struct pfifo_fast_priv *priv = qdisc_priv(qdisc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) struct skb_array *q = band2list(priv, band);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) unsigned int pkt_len = qdisc_pkt_len(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) err = skb_array_produce(q, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) if (unlikely(err)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) if (qdisc_is_percpu_stats(qdisc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) return qdisc_drop_cpu(skb, qdisc, to_free);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) return qdisc_drop(skb, qdisc, to_free);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) qdisc_update_stats_at_enqueue(qdisc, pkt_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) return NET_XMIT_SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) static struct sk_buff *pfifo_fast_dequeue(struct Qdisc *qdisc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) struct pfifo_fast_priv *priv = qdisc_priv(qdisc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) struct sk_buff *skb = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) bool need_retry = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) int band;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) retry:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) for (band = 0; band < PFIFO_FAST_BANDS && !skb; band++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) struct skb_array *q = band2list(priv, band);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) if (__skb_array_empty(q))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) skb = __skb_array_consume(q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) if (likely(skb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) qdisc_update_stats_at_dequeue(qdisc, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) } else if (need_retry &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) test_bit(__QDISC_STATE_MISSED, &qdisc->state)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) /* Delay clearing the STATE_MISSED here to reduce
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) * the overhead of the second spin_trylock() in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) * qdisc_run_begin() and __netif_schedule() calling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) * in qdisc_run_end().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) clear_bit(__QDISC_STATE_MISSED, &qdisc->state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) /* Make sure dequeuing happens after clearing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) * STATE_MISSED.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) smp_mb__after_atomic();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) need_retry = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) goto retry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) WRITE_ONCE(qdisc->empty, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) return skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) static struct sk_buff *pfifo_fast_peek(struct Qdisc *qdisc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) struct pfifo_fast_priv *priv = qdisc_priv(qdisc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) struct sk_buff *skb = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) int band;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) for (band = 0; band < PFIFO_FAST_BANDS && !skb; band++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) struct skb_array *q = band2list(priv, band);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) skb = __skb_array_peek(q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) return skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) static void pfifo_fast_reset(struct Qdisc *qdisc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) int i, band;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) struct pfifo_fast_priv *priv = qdisc_priv(qdisc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) for (band = 0; band < PFIFO_FAST_BANDS; band++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) struct skb_array *q = band2list(priv, band);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) /* NULL ring is possible if destroy path is due to a failed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) * skb_array_init() in pfifo_fast_init() case.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) if (!q->ring.queue)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) while ((skb = __skb_array_consume(q)) != NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) if (qdisc_is_percpu_stats(qdisc)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) for_each_possible_cpu(i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) struct gnet_stats_queue *q;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) q = per_cpu_ptr(qdisc->cpu_qstats, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) q->backlog = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) q->qlen = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) static int pfifo_fast_dump(struct Qdisc *qdisc, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) struct tc_prio_qopt opt = { .bands = PFIFO_FAST_BANDS };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) memcpy(&opt.priomap, prio2band, TC_PRIO_MAX + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) if (nla_put(skb, TCA_OPTIONS, sizeof(opt), &opt))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) return skb->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) nla_put_failure:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) static int pfifo_fast_init(struct Qdisc *qdisc, struct nlattr *opt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) struct netlink_ext_ack *extack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) unsigned int qlen = qdisc_dev(qdisc)->tx_queue_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) struct pfifo_fast_priv *priv = qdisc_priv(qdisc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) int prio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) /* guard against zero length rings */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) if (!qlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) for (prio = 0; prio < PFIFO_FAST_BANDS; prio++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) struct skb_array *q = band2list(priv, prio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) err = skb_array_init(q, qlen, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) /* Can by-pass the queue discipline */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) qdisc->flags |= TCQ_F_CAN_BYPASS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) static void pfifo_fast_destroy(struct Qdisc *sch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) struct pfifo_fast_priv *priv = qdisc_priv(sch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) int prio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) for (prio = 0; prio < PFIFO_FAST_BANDS; prio++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) struct skb_array *q = band2list(priv, prio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) /* NULL ring is possible if destroy path is due to a failed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) * skb_array_init() in pfifo_fast_init() case.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) if (!q->ring.queue)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) /* Destroy ring but no need to kfree_skb because a call to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) * pfifo_fast_reset() has already done that work.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) ptr_ring_cleanup(&q->ring, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) static int pfifo_fast_change_tx_queue_len(struct Qdisc *sch,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) unsigned int new_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) struct pfifo_fast_priv *priv = qdisc_priv(sch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) struct skb_array *bands[PFIFO_FAST_BANDS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) int prio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) for (prio = 0; prio < PFIFO_FAST_BANDS; prio++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) struct skb_array *q = band2list(priv, prio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) bands[prio] = q;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) return skb_array_resize_multiple(bands, PFIFO_FAST_BANDS, new_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) struct Qdisc_ops pfifo_fast_ops __read_mostly = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) .id = "pfifo_fast",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) .priv_size = sizeof(struct pfifo_fast_priv),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) .enqueue = pfifo_fast_enqueue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) .dequeue = pfifo_fast_dequeue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) .peek = pfifo_fast_peek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) .init = pfifo_fast_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) .destroy = pfifo_fast_destroy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) .reset = pfifo_fast_reset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) .dump = pfifo_fast_dump,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) .change_tx_queue_len = pfifo_fast_change_tx_queue_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) .static_flags = TCQ_F_NOLOCK | TCQ_F_CPUSTATS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) EXPORT_SYMBOL(pfifo_fast_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) static struct lock_class_key qdisc_tx_busylock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) static struct lock_class_key qdisc_running_key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) struct Qdisc *qdisc_alloc(struct netdev_queue *dev_queue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) const struct Qdisc_ops *ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) struct netlink_ext_ack *extack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) struct Qdisc *sch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) unsigned int size = sizeof(*sch) + ops->priv_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) int err = -ENOBUFS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) struct net_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) if (!dev_queue) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) NL_SET_ERR_MSG(extack, "No device queue given");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) goto errout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) dev = dev_queue->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) sch = kzalloc_node(size, GFP_KERNEL, netdev_queue_numa_node_read(dev_queue));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) if (!sch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) goto errout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) __skb_queue_head_init(&sch->gso_skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) __skb_queue_head_init(&sch->skb_bad_txq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) qdisc_skb_head_init(&sch->q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) spin_lock_init(&sch->q.lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) if (ops->static_flags & TCQ_F_CPUSTATS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) sch->cpu_bstats =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) netdev_alloc_pcpu_stats(struct gnet_stats_basic_cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) if (!sch->cpu_bstats)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) goto errout1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) sch->cpu_qstats = alloc_percpu(struct gnet_stats_queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) if (!sch->cpu_qstats) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) free_percpu(sch->cpu_bstats);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) goto errout1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) spin_lock_init(&sch->busylock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) lockdep_set_class(&sch->busylock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) dev->qdisc_tx_busylock ?: &qdisc_tx_busylock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) /* seqlock has the same scope of busylock, for NOLOCK qdisc */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) spin_lock_init(&sch->seqlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) lockdep_set_class(&sch->seqlock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) dev->qdisc_tx_busylock ?: &qdisc_tx_busylock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) seqcount_init(&sch->running);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) lockdep_set_class(&sch->running,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) dev->qdisc_running_key ?: &qdisc_running_key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) sch->ops = ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) sch->flags = ops->static_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) sch->enqueue = ops->enqueue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) sch->dequeue = ops->dequeue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) sch->dev_queue = dev_queue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) sch->empty = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) dev_hold(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) refcount_set(&sch->refcnt, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) return sch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) errout1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) kfree(sch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) errout:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) return ERR_PTR(err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) struct Qdisc *qdisc_create_dflt(struct netdev_queue *dev_queue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) const struct Qdisc_ops *ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) unsigned int parentid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) struct netlink_ext_ack *extack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) struct Qdisc *sch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) if (!try_module_get(ops->owner)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) NL_SET_ERR_MSG(extack, "Failed to increase module reference counter");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924) sch = qdisc_alloc(dev_queue, ops, extack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) if (IS_ERR(sch)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) module_put(ops->owner);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) sch->parent = parentid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) if (!ops->init || ops->init(sch, NULL, extack) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) trace_qdisc_create(ops, dev_queue->dev, parentid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) return sch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) qdisc_put(sch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939) EXPORT_SYMBOL(qdisc_create_dflt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) /* Under qdisc_lock(qdisc) and BH! */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943) void qdisc_reset(struct Qdisc *qdisc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945) const struct Qdisc_ops *ops = qdisc->ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946) struct sk_buff *skb, *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948) trace_qdisc_reset(qdisc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950) if (ops->reset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951) ops->reset(qdisc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953) skb_queue_walk_safe(&qdisc->gso_skb, skb, tmp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954) __skb_unlink(skb, &qdisc->gso_skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955) kfree_skb_list(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958) skb_queue_walk_safe(&qdisc->skb_bad_txq, skb, tmp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959) __skb_unlink(skb, &qdisc->skb_bad_txq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960) kfree_skb_list(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963) qdisc->q.qlen = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964) qdisc->qstats.backlog = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966) EXPORT_SYMBOL(qdisc_reset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968) void qdisc_free(struct Qdisc *qdisc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970) if (qdisc_is_percpu_stats(qdisc)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971) free_percpu(qdisc->cpu_bstats);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972) free_percpu(qdisc->cpu_qstats);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975) kfree(qdisc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978) static void qdisc_free_cb(struct rcu_head *head)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980) struct Qdisc *q = container_of(head, struct Qdisc, rcu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982) qdisc_free(q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985) static void qdisc_destroy(struct Qdisc *qdisc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 986) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 987) const struct Qdisc_ops *ops = qdisc->ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 988)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 989) #ifdef CONFIG_NET_SCHED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 990) qdisc_hash_del(qdisc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 991)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 992) qdisc_put_stab(rtnl_dereference(qdisc->stab));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 993) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 994) gen_kill_estimator(&qdisc->rate_est);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 995)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 996) qdisc_reset(qdisc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 997)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 998) if (ops->destroy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 999) ops->destroy(qdisc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) module_put(ops->owner);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) dev_put(qdisc_dev(qdisc));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) trace_qdisc_destroy(qdisc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) call_rcu(&qdisc->rcu, qdisc_free_cb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) void qdisc_put(struct Qdisc *qdisc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) if (!qdisc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) if (qdisc->flags & TCQ_F_BUILTIN ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) !refcount_dec_and_test(&qdisc->refcnt))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) qdisc_destroy(qdisc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) EXPORT_SYMBOL(qdisc_put);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) /* Version of qdisc_put() that is called with rtnl mutex unlocked.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) * Intended to be used as optimization, this function only takes rtnl lock if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) * qdisc reference counter reached zero.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) void qdisc_put_unlocked(struct Qdisc *qdisc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) if (qdisc->flags & TCQ_F_BUILTIN ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) !refcount_dec_and_rtnl_lock(&qdisc->refcnt))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) qdisc_destroy(qdisc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) rtnl_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) EXPORT_SYMBOL(qdisc_put_unlocked);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) /* Attach toplevel qdisc to device queue. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) struct Qdisc *dev_graft_qdisc(struct netdev_queue *dev_queue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) struct Qdisc *qdisc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) struct Qdisc *oqdisc = dev_queue->qdisc_sleeping;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) spinlock_t *root_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) root_lock = qdisc_lock(oqdisc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) spin_lock_bh(root_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) /* ... and graft new one */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) if (qdisc == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) qdisc = &noop_qdisc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) dev_queue->qdisc_sleeping = qdisc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) rcu_assign_pointer(dev_queue->qdisc, &noop_qdisc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) spin_unlock_bh(root_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) return oqdisc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) EXPORT_SYMBOL(dev_graft_qdisc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) static void attach_one_default_qdisc(struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) struct netdev_queue *dev_queue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) void *_unused)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) struct Qdisc *qdisc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) const struct Qdisc_ops *ops = default_qdisc_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) if (dev->priv_flags & IFF_NO_QUEUE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) ops = &noqueue_qdisc_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) else if(dev->type == ARPHRD_CAN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) ops = &pfifo_fast_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) qdisc = qdisc_create_dflt(dev_queue, ops, TC_H_ROOT, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) if (!qdisc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) if (!netif_is_multiqueue(dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) qdisc->flags |= TCQ_F_ONETXQUEUE | TCQ_F_NOPARENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) dev_queue->qdisc_sleeping = qdisc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) static void attach_default_qdiscs(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) struct netdev_queue *txq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) struct Qdisc *qdisc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) txq = netdev_get_tx_queue(dev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) if (!netif_is_multiqueue(dev) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) dev->priv_flags & IFF_NO_QUEUE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) netdev_for_each_tx_queue(dev, attach_one_default_qdisc, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) qdisc = txq->qdisc_sleeping;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) rcu_assign_pointer(dev->qdisc, qdisc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) qdisc_refcount_inc(qdisc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) qdisc = qdisc_create_dflt(txq, &mq_qdisc_ops, TC_H_ROOT, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) if (qdisc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) rcu_assign_pointer(dev->qdisc, qdisc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) qdisc->ops->attach(qdisc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) qdisc = rtnl_dereference(dev->qdisc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) /* Detect default qdisc setup/init failed and fallback to "noqueue" */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) if (qdisc == &noop_qdisc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) netdev_warn(dev, "default qdisc (%s) fail, fallback to %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) default_qdisc_ops->id, noqueue_qdisc_ops.id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) dev->priv_flags |= IFF_NO_QUEUE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) netdev_for_each_tx_queue(dev, attach_one_default_qdisc, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) qdisc = txq->qdisc_sleeping;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) rcu_assign_pointer(dev->qdisc, qdisc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) qdisc_refcount_inc(qdisc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) dev->priv_flags ^= IFF_NO_QUEUE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) #ifdef CONFIG_NET_SCHED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) if (qdisc != &noop_qdisc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) qdisc_hash_add(qdisc, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) static void transition_one_qdisc(struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) struct netdev_queue *dev_queue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) void *_need_watchdog)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) struct Qdisc *new_qdisc = dev_queue->qdisc_sleeping;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) int *need_watchdog_p = _need_watchdog;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) if (!(new_qdisc->flags & TCQ_F_BUILTIN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) clear_bit(__QDISC_STATE_DEACTIVATED, &new_qdisc->state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) rcu_assign_pointer(dev_queue->qdisc, new_qdisc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) if (need_watchdog_p) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) dev_queue->trans_start = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) *need_watchdog_p = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) void dev_activate(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) int need_watchdog;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) /* No queueing discipline is attached to device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) * create default one for devices, which need queueing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) * and noqueue_qdisc for virtual interfaces
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) if (rtnl_dereference(dev->qdisc) == &noop_qdisc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) attach_default_qdiscs(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) if (!netif_carrier_ok(dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) /* Delay activation until next carrier-on event */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) need_watchdog = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) netdev_for_each_tx_queue(dev, transition_one_qdisc, &need_watchdog);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) if (dev_ingress_queue(dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) transition_one_qdisc(dev, dev_ingress_queue(dev), NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) if (need_watchdog) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) netif_trans_update(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) dev_watchdog_up(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) EXPORT_SYMBOL(dev_activate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) static void qdisc_deactivate(struct Qdisc *qdisc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) if (qdisc->flags & TCQ_F_BUILTIN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) set_bit(__QDISC_STATE_DEACTIVATED, &qdisc->state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) static void dev_deactivate_queue(struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) struct netdev_queue *dev_queue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) void *_qdisc_default)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) struct Qdisc *qdisc_default = _qdisc_default;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) struct Qdisc *qdisc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) qdisc = rtnl_dereference(dev_queue->qdisc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) if (qdisc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) qdisc_deactivate(qdisc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) rcu_assign_pointer(dev_queue->qdisc, qdisc_default);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) static void dev_reset_queue(struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) struct netdev_queue *dev_queue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) void *_unused)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) struct Qdisc *qdisc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) bool nolock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) qdisc = dev_queue->qdisc_sleeping;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) if (!qdisc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) nolock = qdisc->flags & TCQ_F_NOLOCK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) if (nolock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) spin_lock_bh(&qdisc->seqlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) spin_lock_bh(qdisc_lock(qdisc));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) qdisc_reset(qdisc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) spin_unlock_bh(qdisc_lock(qdisc));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) if (nolock) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) clear_bit(__QDISC_STATE_MISSED, &qdisc->state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) spin_unlock_bh(&qdisc->seqlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) static bool some_qdisc_is_busy(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) for (i = 0; i < dev->num_tx_queues; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) struct netdev_queue *dev_queue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) spinlock_t *root_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) struct Qdisc *q;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) int val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) dev_queue = netdev_get_tx_queue(dev, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) q = dev_queue->qdisc_sleeping;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) root_lock = qdisc_lock(q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) spin_lock_bh(root_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) val = (qdisc_is_running(q) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) test_bit(__QDISC_STATE_SCHED, &q->state));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) spin_unlock_bh(root_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) if (val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) * dev_deactivate_many - deactivate transmissions on several devices
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) * @head: list of devices to deactivate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) * This function returns only when all outstanding transmissions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) * have completed, unless all devices are in dismantle phase.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) void dev_deactivate_many(struct list_head *head)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) struct net_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) list_for_each_entry(dev, head, close_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) netdev_for_each_tx_queue(dev, dev_deactivate_queue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) &noop_qdisc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) if (dev_ingress_queue(dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) dev_deactivate_queue(dev, dev_ingress_queue(dev),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) &noop_qdisc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) dev_watchdog_down(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) /* Wait for outstanding qdisc-less dev_queue_xmit calls or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) * outstanding qdisc enqueuing calls.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) * This is avoided if all devices are in dismantle phase :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) * Caller will call synchronize_net() for us
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) synchronize_net();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) list_for_each_entry(dev, head, close_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) netdev_for_each_tx_queue(dev, dev_reset_queue, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) if (dev_ingress_queue(dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) dev_reset_queue(dev, dev_ingress_queue(dev), NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) /* Wait for outstanding qdisc_run calls. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) list_for_each_entry(dev, head, close_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) while (some_qdisc_is_busy(dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) /* wait_event() would avoid this sleep-loop but would
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) * require expensive checks in the fast paths of packet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) * processing which isn't worth it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) schedule_timeout_uninterruptible(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) void dev_deactivate(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) LIST_HEAD(single);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) list_add(&dev->close_list, &single);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) dev_deactivate_many(&single);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) list_del(&single);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) EXPORT_SYMBOL(dev_deactivate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) static int qdisc_change_tx_queue_len(struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) struct netdev_queue *dev_queue)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) struct Qdisc *qdisc = dev_queue->qdisc_sleeping;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) const struct Qdisc_ops *ops = qdisc->ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) if (ops->change_tx_queue_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) return ops->change_tx_queue_len(qdisc, dev->tx_queue_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) int dev_qdisc_change_tx_queue_len(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) bool up = dev->flags & IFF_UP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) if (up)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) dev_deactivate(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) for (i = 0; i < dev->num_tx_queues; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) ret = qdisc_change_tx_queue_len(dev, &dev->_tx[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) /* TODO: revert changes on a partial failure */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) if (up)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) dev_activate(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) static void dev_init_scheduler_queue(struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) struct netdev_queue *dev_queue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) void *_qdisc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) struct Qdisc *qdisc = _qdisc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) rcu_assign_pointer(dev_queue->qdisc, qdisc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) dev_queue->qdisc_sleeping = qdisc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) void dev_init_scheduler(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) rcu_assign_pointer(dev->qdisc, &noop_qdisc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) netdev_for_each_tx_queue(dev, dev_init_scheduler_queue, &noop_qdisc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) if (dev_ingress_queue(dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) dev_init_scheduler_queue(dev, dev_ingress_queue(dev), &noop_qdisc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) timer_setup(&dev->watchdog_timer, dev_watchdog, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) static void shutdown_scheduler_queue(struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) struct netdev_queue *dev_queue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) void *_qdisc_default)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) struct Qdisc *qdisc = dev_queue->qdisc_sleeping;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) struct Qdisc *qdisc_default = _qdisc_default;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) if (qdisc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) rcu_assign_pointer(dev_queue->qdisc, qdisc_default);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) dev_queue->qdisc_sleeping = qdisc_default;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) qdisc_put(qdisc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) void dev_shutdown(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) netdev_for_each_tx_queue(dev, shutdown_scheduler_queue, &noop_qdisc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369) if (dev_ingress_queue(dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) shutdown_scheduler_queue(dev, dev_ingress_queue(dev), &noop_qdisc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371) qdisc_put(rtnl_dereference(dev->qdisc));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) rcu_assign_pointer(dev->qdisc, &noop_qdisc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) WARN_ON(timer_pending(&dev->watchdog_timer));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377) void psched_ratecfg_precompute(struct psched_ratecfg *r,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) const struct tc_ratespec *conf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) u64 rate64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) memset(r, 0, sizeof(*r));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382) r->overhead = conf->overhead;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) r->mpu = conf->mpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) r->rate_bytes_ps = max_t(u64, conf->rate, rate64);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385) r->linklayer = (conf->linklayer & TC_LINKLAYER_MASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) r->mult = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) * The deal here is to replace a divide by a reciprocal one
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389) * in fast path (a reciprocal divide is a multiply and a shift)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) * Normal formula would be :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) * time_in_ns = (NSEC_PER_SEC * len) / rate_bps
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394) * We compute mult/shift to use instead :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395) * time_in_ns = (len * mult) >> shift;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397) * We try to get the highest possible mult value for accuracy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398) * but have to make sure no overflows will ever happen.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400) if (r->rate_bytes_ps > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401) u64 factor = NSEC_PER_SEC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403) for (;;) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) r->mult = div64_u64(factor, r->rate_bytes_ps);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405) if (r->mult & (1U << 31) || factor & (1ULL << 63))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407) factor <<= 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408) r->shift++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412) EXPORT_SYMBOL(psched_ratecfg_precompute);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414) static void mini_qdisc_rcu_func(struct rcu_head *head)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418) void mini_qdisc_pair_swap(struct mini_Qdisc_pair *miniqp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419) struct tcf_proto *tp_head)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421) /* Protected with chain0->filter_chain_lock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422) * Can't access chain directly because tp_head can be NULL.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424) struct mini_Qdisc *miniq_old =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425) rcu_dereference_protected(*miniqp->p_miniq, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426) struct mini_Qdisc *miniq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428) if (!tp_head) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429) RCU_INIT_POINTER(*miniqp->p_miniq, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430) /* Wait for flying RCU callback before it is freed. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431) rcu_barrier();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435) miniq = !miniq_old || miniq_old == &miniqp->miniq2 ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436) &miniqp->miniq1 : &miniqp->miniq2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438) /* We need to make sure that readers won't see the miniq
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439) * we are about to modify. So wait until previous call_rcu callback
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440) * is done.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442) rcu_barrier();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443) miniq->filter_list = tp_head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444) rcu_assign_pointer(*miniqp->p_miniq, miniq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446) if (miniq_old)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447) /* This is counterpart of the rcu barriers above. We need to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448) * block potential new user of miniq_old until all readers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449) * are not seeing it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451) call_rcu(&miniq_old->rcu, mini_qdisc_rcu_func);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1453) EXPORT_SYMBOL(mini_qdisc_pair_swap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455) void mini_qdisc_pair_block_init(struct mini_Qdisc_pair *miniqp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456) struct tcf_block *block)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458) miniqp->miniq1.block = block;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459) miniqp->miniq2.block = block;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461) EXPORT_SYMBOL(mini_qdisc_pair_block_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463) void mini_qdisc_pair_init(struct mini_Qdisc_pair *miniqp, struct Qdisc *qdisc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464) struct mini_Qdisc __rcu **p_miniq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466) miniqp->miniq1.cpu_bstats = qdisc->cpu_bstats;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467) miniqp->miniq1.cpu_qstats = qdisc->cpu_qstats;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468) miniqp->miniq2.cpu_bstats = qdisc->cpu_bstats;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469) miniqp->miniq2.cpu_qstats = qdisc->cpu_qstats;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470) miniqp->p_miniq = p_miniq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472) EXPORT_SYMBOL(mini_qdisc_pair_init);