Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | #include <linux/types.h> |
| 15 | #include <linux/kernel.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | #include <linux/errno.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | #include <linux/netdevice.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #include <linux/skbuff.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | #include <net/pkt_sched.h> |
| 20 | |
| 21 | /* 1 band FIFO pseudo-"scheduler" */ |
| 22 | |
| 23 | struct fifo_sched_data |
| 24 | { |
Thomas Graf | 6fc8e84 | 2005-06-18 22:58:00 -0700 | [diff] [blame] | 25 | u32 limit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | }; |
| 27 | |
Thomas Graf | 6fc8e84 | 2005-06-18 22:58:00 -0700 | [diff] [blame] | 28 | static int bfifo_enqueue(struct sk_buff *skb, struct Qdisc* sch) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | { |
| 30 | struct fifo_sched_data *q = qdisc_priv(sch); |
| 31 | |
Thomas Graf | aaae301 | 2005-06-18 22:57:42 -0700 | [diff] [blame] | 32 | if (likely(sch->qstats.backlog + skb->len <= q->limit)) |
| 33 | return qdisc_enqueue_tail(skb, sch); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | |
Thomas Graf | aaae301 | 2005-06-18 22:57:42 -0700 | [diff] [blame] | 35 | return qdisc_reshape_fail(skb, sch); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | } |
| 37 | |
Thomas Graf | 6fc8e84 | 2005-06-18 22:58:00 -0700 | [diff] [blame] | 38 | static int pfifo_enqueue(struct sk_buff *skb, struct Qdisc* sch) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | { |
| 40 | struct fifo_sched_data *q = qdisc_priv(sch); |
| 41 | |
Thomas Graf | aaae301 | 2005-06-18 22:57:42 -0700 | [diff] [blame] | 42 | if (likely(skb_queue_len(&sch->q) < q->limit)) |
| 43 | return qdisc_enqueue_tail(skb, sch); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | |
Thomas Graf | aaae301 | 2005-06-18 22:57:42 -0700 | [diff] [blame] | 45 | return qdisc_reshape_fail(skb, sch); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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) { |
Thomas Graf | 6fc8e84 | 2005-06-18 22:58:00 -0700 | [diff] [blame] | 53 | u32 limit = sch->dev->tx_queue_len ? : 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | |
| 55 | if (sch->ops == &bfifo_qdisc_ops) |
Thomas Graf | 6fc8e84 | 2005-06-18 22:58:00 -0700 | [diff] [blame] | 56 | limit *= sch->dev->mtu; |
| 57 | |
| 58 | q->limit = limit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | } else { |
| 60 | struct tc_fifo_qopt *ctl = RTA_DATA(opt); |
Thomas Graf | 6fc8e84 | 2005-06-18 22:58:00 -0700 | [diff] [blame] | 61 | |
| 62 | if (RTA_PAYLOAD(opt) < sizeof(*ctl)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | return -EINVAL; |
Thomas Graf | 6fc8e84 | 2005-06-18 22:58:00 -0700 | [diff] [blame] | 64 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | q->limit = ctl->limit; |
| 66 | } |
Thomas Graf | 6fc8e84 | 2005-06-18 22:58:00 -0700 | [diff] [blame] | 67 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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); |
Thomas Graf | 6fc8e84 | 2005-06-18 22:58:00 -0700 | [diff] [blame] | 74 | struct tc_fifo_qopt opt = { .limit = q->limit }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | RTA_PUT(skb, TCA_OPTIONS, sizeof(opt), &opt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | return skb->len; |
| 78 | |
| 79 | rtattr_failure: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | return -1; |
| 81 | } |
| 82 | |
| 83 | struct Qdisc_ops pfifo_qdisc_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | .id = "pfifo", |
| 85 | .priv_size = sizeof(struct fifo_sched_data), |
| 86 | .enqueue = pfifo_enqueue, |
Thomas Graf | aaae301 | 2005-06-18 22:57:42 -0700 | [diff] [blame] | 87 | .dequeue = qdisc_dequeue_head, |
| 88 | .requeue = qdisc_requeue, |
| 89 | .drop = qdisc_queue_drop, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | .init = fifo_init, |
Thomas Graf | aaae301 | 2005-06-18 22:57:42 -0700 | [diff] [blame] | 91 | .reset = qdisc_reset_queue, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | .change = fifo_init, |
| 93 | .dump = fifo_dump, |
| 94 | .owner = THIS_MODULE, |
| 95 | }; |
| 96 | |
| 97 | struct Qdisc_ops bfifo_qdisc_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | .id = "bfifo", |
| 99 | .priv_size = sizeof(struct fifo_sched_data), |
| 100 | .enqueue = bfifo_enqueue, |
Thomas Graf | aaae301 | 2005-06-18 22:57:42 -0700 | [diff] [blame] | 101 | .dequeue = qdisc_dequeue_head, |
| 102 | .requeue = qdisc_requeue, |
| 103 | .drop = qdisc_queue_drop, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | .init = fifo_init, |
Thomas Graf | aaae301 | 2005-06-18 22:57:42 -0700 | [diff] [blame] | 105 | .reset = qdisc_reset_queue, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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); |