2 * net/sched/sch_fifo.c The simplest FIFO queue.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version
7 * 2 of the License, or (at your option) any later version.
9 * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
12 #include <linux/config.h>
13 #include <linux/module.h>
14 #include <linux/types.h>
15 #include <linux/kernel.h>
16 #include <linux/errno.h>
17 #include <linux/netdevice.h>
18 #include <linux/skbuff.h>
19 #include <net/pkt_sched.h>
21 /* 1 band FIFO pseudo-"scheduler" */
23 struct fifo_sched_data
28 static int bfifo_enqueue(struct sk_buff *skb, struct Qdisc* sch)
30 struct fifo_sched_data *q = qdisc_priv(sch);
32 if (likely(sch->qstats.backlog + skb->len <= q->limit))
33 return qdisc_enqueue_tail(skb, sch);
35 return qdisc_reshape_fail(skb, sch);
38 static int pfifo_enqueue(struct sk_buff *skb, struct Qdisc* sch)
40 struct fifo_sched_data *q = qdisc_priv(sch);
42 if (likely(skb_queue_len(&sch->q) < q->limit))
43 return qdisc_enqueue_tail(skb, sch);
45 return qdisc_reshape_fail(skb, sch);
48 static int fifo_init(struct Qdisc *sch, struct rtattr *opt)
50 struct fifo_sched_data *q = qdisc_priv(sch);
53 u32 limit = sch->dev->tx_queue_len ? : 1;
55 if (sch->ops == &bfifo_qdisc_ops)
56 limit *= sch->dev->mtu;
60 struct tc_fifo_qopt *ctl = RTA_DATA(opt);
62 if (RTA_PAYLOAD(opt) < sizeof(*ctl))
65 q->limit = ctl->limit;
71 static int fifo_dump(struct Qdisc *sch, struct sk_buff *skb)
73 struct fifo_sched_data *q = qdisc_priv(sch);
74 struct tc_fifo_qopt opt = { .limit = q->limit };
76 RTA_PUT(skb, TCA_OPTIONS, sizeof(opt), &opt);
83 struct Qdisc_ops pfifo_qdisc_ops = {
85 .priv_size = sizeof(struct fifo_sched_data),
86 .enqueue = pfifo_enqueue,
87 .dequeue = qdisc_dequeue_head,
88 .requeue = qdisc_requeue,
89 .drop = qdisc_queue_drop,
91 .reset = qdisc_reset_queue,
97 struct Qdisc_ops bfifo_qdisc_ops = {
99 .priv_size = sizeof(struct fifo_sched_data),
100 .enqueue = bfifo_enqueue,
101 .dequeue = qdisc_dequeue_head,
102 .requeue = qdisc_requeue,
103 .drop = qdisc_queue_drop,
105 .reset = qdisc_reset_queue,
108 .owner = THIS_MODULE,
111 EXPORT_SYMBOL(bfifo_qdisc_ops);
112 EXPORT_SYMBOL(pfifo_qdisc_ops);