[TG3]: Set minimal hw interrupt mitigation.
[linux-2.6/verdex.git] / net / sched / sch_fifo.c
blob4888305c96dadf1f339acbd7bbc3ab5ee03d2651
1 /*
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 <asm/uaccess.h>
15 #include <asm/system.h>
16 #include <linux/bitops.h>
17 #include <linux/types.h>
18 #include <linux/kernel.h>
19 #include <linux/sched.h>
20 #include <linux/string.h>
21 #include <linux/mm.h>
22 #include <linux/socket.h>
23 #include <linux/sockios.h>
24 #include <linux/in.h>
25 #include <linux/errno.h>
26 #include <linux/interrupt.h>
27 #include <linux/if_ether.h>
28 #include <linux/inet.h>
29 #include <linux/netdevice.h>
30 #include <linux/etherdevice.h>
31 #include <linux/notifier.h>
32 #include <net/ip.h>
33 #include <net/route.h>
34 #include <linux/skbuff.h>
35 #include <net/sock.h>
36 #include <net/pkt_sched.h>
38 /* 1 band FIFO pseudo-"scheduler" */
40 struct fifo_sched_data
42 unsigned limit;
45 static int
46 bfifo_enqueue(struct sk_buff *skb, struct Qdisc* sch)
48 struct fifo_sched_data *q = qdisc_priv(sch);
50 if (sch->qstats.backlog + skb->len <= q->limit) {
51 __skb_queue_tail(&sch->q, skb);
52 sch->qstats.backlog += skb->len;
53 sch->bstats.bytes += skb->len;
54 sch->bstats.packets++;
55 return 0;
57 sch->qstats.drops++;
58 #ifdef CONFIG_NET_CLS_POLICE
59 if (sch->reshape_fail==NULL || sch->reshape_fail(skb, sch))
60 #endif
61 kfree_skb(skb);
62 return NET_XMIT_DROP;
65 static int
66 bfifo_requeue(struct sk_buff *skb, struct Qdisc* sch)
68 __skb_queue_head(&sch->q, skb);
69 sch->qstats.backlog += skb->len;
70 sch->qstats.requeues++;
71 return 0;
74 static struct sk_buff *
75 bfifo_dequeue(struct Qdisc* sch)
77 struct sk_buff *skb;
79 skb = __skb_dequeue(&sch->q);
80 if (skb)
81 sch->qstats.backlog -= skb->len;
82 return skb;
85 static unsigned int
86 fifo_drop(struct Qdisc* sch)
88 struct sk_buff *skb;
90 skb = __skb_dequeue_tail(&sch->q);
91 if (skb) {
92 unsigned int len = skb->len;
93 sch->qstats.backlog -= len;
94 kfree_skb(skb);
95 return len;
97 return 0;
100 static void
101 fifo_reset(struct Qdisc* sch)
103 skb_queue_purge(&sch->q);
104 sch->qstats.backlog = 0;
107 static int
108 pfifo_enqueue(struct sk_buff *skb, struct Qdisc* sch)
110 struct fifo_sched_data *q = qdisc_priv(sch);
112 if (sch->q.qlen < q->limit) {
113 __skb_queue_tail(&sch->q, skb);
114 sch->bstats.bytes += skb->len;
115 sch->bstats.packets++;
116 return 0;
118 sch->qstats.drops++;
119 #ifdef CONFIG_NET_CLS_POLICE
120 if (sch->reshape_fail==NULL || sch->reshape_fail(skb, sch))
121 #endif
122 kfree_skb(skb);
123 return NET_XMIT_DROP;
126 static int
127 pfifo_requeue(struct sk_buff *skb, struct Qdisc* sch)
129 __skb_queue_head(&sch->q, skb);
130 sch->qstats.requeues++;
131 return 0;
135 static struct sk_buff *
136 pfifo_dequeue(struct Qdisc* sch)
138 return __skb_dequeue(&sch->q);
141 static int fifo_init(struct Qdisc *sch, struct rtattr *opt)
143 struct fifo_sched_data *q = qdisc_priv(sch);
145 if (opt == NULL) {
146 unsigned int limit = sch->dev->tx_queue_len ? : 1;
148 if (sch->ops == &bfifo_qdisc_ops)
149 q->limit = limit*sch->dev->mtu;
150 else
151 q->limit = limit;
152 } else {
153 struct tc_fifo_qopt *ctl = RTA_DATA(opt);
154 if (opt->rta_len < RTA_LENGTH(sizeof(*ctl)))
155 return -EINVAL;
156 q->limit = ctl->limit;
158 return 0;
161 static int fifo_dump(struct Qdisc *sch, struct sk_buff *skb)
163 struct fifo_sched_data *q = qdisc_priv(sch);
164 unsigned char *b = skb->tail;
165 struct tc_fifo_qopt opt;
167 opt.limit = q->limit;
168 RTA_PUT(skb, TCA_OPTIONS, sizeof(opt), &opt);
170 return skb->len;
172 rtattr_failure:
173 skb_trim(skb, b - skb->data);
174 return -1;
177 struct Qdisc_ops pfifo_qdisc_ops = {
178 .next = NULL,
179 .cl_ops = NULL,
180 .id = "pfifo",
181 .priv_size = sizeof(struct fifo_sched_data),
182 .enqueue = pfifo_enqueue,
183 .dequeue = pfifo_dequeue,
184 .requeue = pfifo_requeue,
185 .drop = fifo_drop,
186 .init = fifo_init,
187 .reset = fifo_reset,
188 .destroy = NULL,
189 .change = fifo_init,
190 .dump = fifo_dump,
191 .owner = THIS_MODULE,
194 struct Qdisc_ops bfifo_qdisc_ops = {
195 .next = NULL,
196 .cl_ops = NULL,
197 .id = "bfifo",
198 .priv_size = sizeof(struct fifo_sched_data),
199 .enqueue = bfifo_enqueue,
200 .dequeue = bfifo_dequeue,
201 .requeue = bfifo_requeue,
202 .drop = fifo_drop,
203 .init = fifo_init,
204 .reset = fifo_reset,
205 .destroy = NULL,
206 .change = fifo_init,
207 .dump = fifo_dump,
208 .owner = THIS_MODULE,
211 EXPORT_SYMBOL(bfifo_qdisc_ops);
212 EXPORT_SYMBOL(pfifo_qdisc_ops);