Merge with rsync://rsync.kernel.org/pub/scm/linux/kernel/git/sfrench/cifs-2.6.git
[deliverable/linux.git] / net / sched / sch_fifo.c
1 /*
2 * net/sched/sch_fifo.c The simplest FIFO queue.
3 *
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.
8 *
9 * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
10 */
11
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>
20
21 /* 1 band FIFO pseudo-"scheduler" */
22
23 struct fifo_sched_data
24 {
25 u32 limit;
26 };
27
28 static int bfifo_enqueue(struct sk_buff *skb, struct Qdisc* sch)
29 {
30 struct fifo_sched_data *q = qdisc_priv(sch);
31
32 if (likely(sch->qstats.backlog + skb->len <= q->limit))
33 return qdisc_enqueue_tail(skb, sch);
34
35 return qdisc_reshape_fail(skb, sch);
36 }
37
38 static int pfifo_enqueue(struct sk_buff *skb, struct Qdisc* sch)
39 {
40 struct fifo_sched_data *q = qdisc_priv(sch);
41
42 if (likely(skb_queue_len(&sch->q) < q->limit))
43 return qdisc_enqueue_tail(skb, sch);
44
45 return qdisc_reshape_fail(skb, sch);
46 }
47
48 static int fifo_init(struct Qdisc *sch, struct rtattr *opt)
49 {
50 struct fifo_sched_data *q = qdisc_priv(sch);
51
52 if (opt == NULL) {
53 u32 limit = sch->dev->tx_queue_len ? : 1;
54
55 if (sch->ops == &bfifo_qdisc_ops)
56 limit *= sch->dev->mtu;
57
58 q->limit = limit;
59 } else {
60 struct tc_fifo_qopt *ctl = RTA_DATA(opt);
61
62 if (RTA_PAYLOAD(opt) < sizeof(*ctl))
63 return -EINVAL;
64
65 q->limit = ctl->limit;
66 }
67
68 return 0;
69 }
70
71 static int fifo_dump(struct Qdisc *sch, struct sk_buff *skb)
72 {
73 struct fifo_sched_data *q = qdisc_priv(sch);
74 struct tc_fifo_qopt opt = { .limit = q->limit };
75
76 RTA_PUT(skb, TCA_OPTIONS, sizeof(opt), &opt);
77 return skb->len;
78
79 rtattr_failure:
80 return -1;
81 }
82
83 struct Qdisc_ops pfifo_qdisc_ops = {
84 .id = "pfifo",
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,
90 .init = fifo_init,
91 .reset = qdisc_reset_queue,
92 .change = fifo_init,
93 .dump = fifo_dump,
94 .owner = THIS_MODULE,
95 };
96
97 struct Qdisc_ops bfifo_qdisc_ops = {
98 .id = "bfifo",
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,
104 .init = fifo_init,
105 .reset = qdisc_reset_queue,
106 .change = fifo_init,
107 .dump = fifo_dump,
108 .owner = THIS_MODULE,
109 };
110
111 EXPORT_SYMBOL(bfifo_qdisc_ops);
112 EXPORT_SYMBOL(pfifo_qdisc_ops);
This page took 0.036066 seconds and 6 git commands to generate.