blob: 033083bf0e741e6863a5cb999f58dbda6d3729a1 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <linux/types.h>
15#include <linux/kernel.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#include <linux/errno.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#include <linux/netdevice.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include <linux/skbuff.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019#include <net/pkt_sched.h>
20
21/* 1 band FIFO pseudo-"scheduler" */
22
23struct fifo_sched_data
24{
Thomas Graf6fc8e842005-06-18 22:58:00 -070025 u32 limit;
Linus Torvalds1da177e2005-04-16 15:20:36 -070026};
27
Thomas Graf6fc8e842005-06-18 22:58:00 -070028static int bfifo_enqueue(struct sk_buff *skb, struct Qdisc* sch)
Linus Torvalds1da177e2005-04-16 15:20:36 -070029{
30 struct fifo_sched_data *q = qdisc_priv(sch);
31
Thomas Grafaaae3012005-06-18 22:57:42 -070032 if (likely(sch->qstats.backlog + skb->len <= q->limit))
33 return qdisc_enqueue_tail(skb, sch);
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
Thomas Grafaaae3012005-06-18 22:57:42 -070035 return qdisc_reshape_fail(skb, sch);
Linus Torvalds1da177e2005-04-16 15:20:36 -070036}
37
Thomas Graf6fc8e842005-06-18 22:58:00 -070038static int pfifo_enqueue(struct sk_buff *skb, struct Qdisc* sch)
Linus Torvalds1da177e2005-04-16 15:20:36 -070039{
40 struct fifo_sched_data *q = qdisc_priv(sch);
41
Thomas Grafaaae3012005-06-18 22:57:42 -070042 if (likely(skb_queue_len(&sch->q) < q->limit))
43 return qdisc_enqueue_tail(skb, sch);
Linus Torvalds1da177e2005-04-16 15:20:36 -070044
Thomas Grafaaae3012005-06-18 22:57:42 -070045 return qdisc_reshape_fail(skb, sch);
Linus Torvalds1da177e2005-04-16 15:20:36 -070046}
47
48static int fifo_init(struct Qdisc *sch, struct rtattr *opt)
49{
50 struct fifo_sched_data *q = qdisc_priv(sch);
51
52 if (opt == NULL) {
Thomas Graf6fc8e842005-06-18 22:58:00 -070053 u32 limit = sch->dev->tx_queue_len ? : 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -070054
55 if (sch->ops == &bfifo_qdisc_ops)
Thomas Graf6fc8e842005-06-18 22:58:00 -070056 limit *= sch->dev->mtu;
57
58 q->limit = limit;
Linus Torvalds1da177e2005-04-16 15:20:36 -070059 } else {
60 struct tc_fifo_qopt *ctl = RTA_DATA(opt);
Thomas Graf6fc8e842005-06-18 22:58:00 -070061
62 if (RTA_PAYLOAD(opt) < sizeof(*ctl))
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 return -EINVAL;
Thomas Graf6fc8e842005-06-18 22:58:00 -070064
Linus Torvalds1da177e2005-04-16 15:20:36 -070065 q->limit = ctl->limit;
66 }
Thomas Graf6fc8e842005-06-18 22:58:00 -070067
Linus Torvalds1da177e2005-04-16 15:20:36 -070068 return 0;
69}
70
71static int fifo_dump(struct Qdisc *sch, struct sk_buff *skb)
72{
73 struct fifo_sched_data *q = qdisc_priv(sch);
Thomas Graf6fc8e842005-06-18 22:58:00 -070074 struct tc_fifo_qopt opt = { .limit = q->limit };
Linus Torvalds1da177e2005-04-16 15:20:36 -070075
Linus Torvalds1da177e2005-04-16 15:20:36 -070076 RTA_PUT(skb, TCA_OPTIONS, sizeof(opt), &opt);
Linus Torvalds1da177e2005-04-16 15:20:36 -070077 return skb->len;
78
79rtattr_failure:
Linus Torvalds1da177e2005-04-16 15:20:36 -070080 return -1;
81}
82
83struct Qdisc_ops pfifo_qdisc_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070084 .id = "pfifo",
85 .priv_size = sizeof(struct fifo_sched_data),
86 .enqueue = pfifo_enqueue,
Thomas Grafaaae3012005-06-18 22:57:42 -070087 .dequeue = qdisc_dequeue_head,
88 .requeue = qdisc_requeue,
89 .drop = qdisc_queue_drop,
Linus Torvalds1da177e2005-04-16 15:20:36 -070090 .init = fifo_init,
Thomas Grafaaae3012005-06-18 22:57:42 -070091 .reset = qdisc_reset_queue,
Linus Torvalds1da177e2005-04-16 15:20:36 -070092 .change = fifo_init,
93 .dump = fifo_dump,
94 .owner = THIS_MODULE,
95};
96
97struct Qdisc_ops bfifo_qdisc_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 .id = "bfifo",
99 .priv_size = sizeof(struct fifo_sched_data),
100 .enqueue = bfifo_enqueue,
Thomas Grafaaae3012005-06-18 22:57:42 -0700101 .dequeue = qdisc_dequeue_head,
102 .requeue = qdisc_requeue,
103 .drop = qdisc_queue_drop,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 .init = fifo_init,
Thomas Grafaaae3012005-06-18 22:57:42 -0700105 .reset = qdisc_reset_queue,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 .change = fifo_init,
107 .dump = fifo_dump,
108 .owner = THIS_MODULE,
109};
110
111EXPORT_SYMBOL(bfifo_qdisc_ops);
112EXPORT_SYMBOL(pfifo_qdisc_ops);