add a gpio feature for devices supporting the generic GPIO interface
[openwrt.git] / target / linux / generic-2.6 / patches-2.6.24 / 200-sched_esfq.patch
1 diff -Naur linux-2.6.21.5.orig/include/linux/pkt_sched.h linux-2.6.21.5/include/linux/pkt_sched.h
2 --- linux-2.6.21.5.orig/include/linux/pkt_sched.h 2007-06-11 11:37:06.000000000 -0700
3 +++ linux-2.6.21.5/include/linux/pkt_sched.h 2007-06-22 22:53:46.000000000 -0700
4 @@ -146,8 +146,37 @@
5 *
6 * The only reason for this is efficiency, it is possible
7 * to change these parameters in compile time.
8 + *
9 + * If you need to play with these values, use esfq instead.
10 */
11
12 +/* ESFQ section */
13 +
14 +enum
15 +{
16 + /* traditional */
17 + TCA_SFQ_HASH_CLASSIC,
18 + TCA_SFQ_HASH_DST,
19 + TCA_SFQ_HASH_SRC,
20 + TCA_SFQ_HASH_FWMARK,
21 + /* conntrack */
22 + TCA_SFQ_HASH_CTORIGDST,
23 + TCA_SFQ_HASH_CTORIGSRC,
24 + TCA_SFQ_HASH_CTREPLDST,
25 + TCA_SFQ_HASH_CTREPLSRC,
26 + TCA_SFQ_HASH_CTNATCHG,
27 +};
28 +
29 +struct tc_esfq_qopt
30 +{
31 + unsigned quantum; /* Bytes per round allocated to flow */
32 + int perturb_period; /* Period of hash perturbation */
33 + __u32 limit; /* Maximal packets in queue */
34 + unsigned divisor; /* Hash divisor */
35 + unsigned flows; /* Maximal number of flows */
36 + unsigned hash_kind; /* Hash function to use for flow identification */
37 +};
38 +
39 /* RED section */
40
41 enum
42 diff -Naur linux-2.6.21.5.orig/net/sched/Kconfig linux-2.6.21.5/net/sched/Kconfig
43 --- linux-2.6.21.5.orig/net/sched/Kconfig 2007-06-11 11:37:06.000000000 -0700
44 +++ linux-2.6.21.5/net/sched/Kconfig 2007-06-23 14:11:02.000000000 -0700
45 @@ -189,6 +189,37 @@
46 To compile this code as a module, choose M here: the
47 module will be called sch_sfq.
48
49 +config NET_SCH_ESFQ
50 + tristate "Enhanced Stochastic Fairness Queueing (ESFQ)"
51 + ---help---
52 + Say Y here if you want to use the Enhanced Stochastic Fairness
53 + Queueing (ESFQ) packet scheduling algorithm for some of your network
54 + devices or as a leaf discipline for a classful qdisc such as HTB or
55 + CBQ (see the top of <file:net/sched/sch_esfq.c> for details and
56 + references to the SFQ algorithm).
57 +
58 + This is an enchanced SFQ version which allows you to control some
59 + hardcoded values in the SFQ scheduler.
60 +
61 + ESFQ also adds control of the hash function used to identify packet
62 + flows. The original SFQ discipline hashes by connection; ESFQ add
63 + several other hashing methods, such as by src IP or by dst IP, which
64 + can be more fair to users in some networking situations.
65 +
66 + To compile this code as a module, choose M here: the
67 + module will be called sch_esfq.
68 +
69 +config NET_SCH_ESFQ_NFCT
70 + bool "Connection Tracking Hash Types"
71 + depends on NET_SCH_ESFQ && NF_CONNTRACK
72 + ---help---
73 + Say Y here to enable support for hashing based on netfilter connection
74 + tracking information. This is useful for a router that is also using
75 + NAT to connect privately-addressed hosts to the Internet. If you want
76 + to provide fair distribution of upstream bandwidth, ESFQ must use
77 + connection tracking information, since all outgoing packets will share
78 + the same source address.
79 +
80 config NET_SCH_TEQL
81 tristate "True Link Equalizer (TEQL)"
82 ---help---
83 diff -Naur linux-2.6.21.5.orig/net/sched/Makefile linux-2.6.21.5/net/sched/Makefile
84 --- linux-2.6.21.5.orig/net/sched/Makefile 2007-06-11 11:37:06.000000000 -0700
85 +++ linux-2.6.21.5/net/sched/Makefile 2007-06-22 22:53:46.000000000 -0700
86 @@ -23,6 +23,7 @@
87 obj-$(CONFIG_NET_SCH_INGRESS) += sch_ingress.o
88 obj-$(CONFIG_NET_SCH_DSMARK) += sch_dsmark.o
89 obj-$(CONFIG_NET_SCH_SFQ) += sch_sfq.o
90 +obj-$(CONFIG_NET_SCH_ESFQ) += sch_esfq.o
91 obj-$(CONFIG_NET_SCH_TBF) += sch_tbf.o
92 obj-$(CONFIG_NET_SCH_TEQL) += sch_teql.o
93 obj-$(CONFIG_NET_SCH_PRIO) += sch_prio.o
94 diff -Naur linux-2.6.21.5.orig/net/sched/sch_esfq.c linux-2.6.21.5/net/sched/sch_esfq.c
95 --- linux-2.6.21.5.orig/net/sched/sch_esfq.c 1969-12-31 16:00:00.000000000 -0800
96 +++ linux-2.6.21.5/net/sched/sch_esfq.c 2007-06-23 19:18:00.000000000 -0700
97 @@ -0,0 +1,702 @@
98 +/*
99 + * net/sched/sch_esfq.c Extended Stochastic Fairness Queueing discipline.
100 + *
101 + * This program is free software; you can redistribute it and/or
102 + * modify it under the terms of the GNU General Public License
103 + * as published by the Free Software Foundation; either version
104 + * 2 of the License, or (at your option) any later version.
105 + *
106 + * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
107 + *
108 + * Changes: Alexander Atanasov, <alex@ssi.bg>
109 + * Added dynamic depth,limit,divisor,hash_kind options.
110 + * Added dst and src hashes.
111 + *
112 + * Alexander Clouter, <alex@digriz.org.uk>
113 + * Ported ESFQ to Linux 2.6.
114 + *
115 + * Corey Hickey, <bugfood-c@fatooh.org>
116 + * Maintenance of the Linux 2.6 port.
117 + * Added fwmark hash (thanks to Robert Kurjata).
118 + * Added usage of jhash.
119 + * Added conntrack support.
120 + * Added ctnatchg hash (thanks to Ben Pfountz).
121 + */
122 +
123 +#include <linux/module.h>
124 +#include <asm/uaccess.h>
125 +#include <asm/system.h>
126 +#include <linux/bitops.h>
127 +#include <linux/types.h>
128 +#include <linux/kernel.h>
129 +#include <linux/jiffies.h>
130 +#include <linux/string.h>
131 +#include <linux/mm.h>
132 +#include <linux/socket.h>
133 +#include <linux/sockios.h>
134 +#include <linux/in.h>
135 +#include <linux/errno.h>
136 +#include <linux/interrupt.h>
137 +#include <linux/if_ether.h>
138 +#include <linux/inet.h>
139 +#include <linux/netdevice.h>
140 +#include <linux/etherdevice.h>
141 +#include <linux/notifier.h>
142 +#include <linux/init.h>
143 +#include <net/ip.h>
144 +#include <linux/ipv6.h>
145 +#include <net/route.h>
146 +#include <linux/skbuff.h>
147 +#include <net/sock.h>
148 +#include <net/pkt_sched.h>
149 +#include <linux/jhash.h>
150 +#include <net/netfilter/nf_conntrack.h>
151 +
152 +/* Stochastic Fairness Queuing algorithm.
153 + For more comments look at sch_sfq.c.
154 + The difference is that you can change limit, depth,
155 + hash table size and choose alternate hash types.
156 +
157 + classic: same as in sch_sfq.c
158 + dst: destination IP address
159 + src: source IP address
160 + fwmark: netfilter mark value
161 + ctorigdst: original destination IP address
162 + ctorigsrc: original source IP address
163 + ctrepldst: reply destination IP address
164 + ctreplsrc: reply source IP
165 +
166 +*/
167 +
168 +#define ESFQ_HEAD 0
169 +#define ESFQ_TAIL 1
170 +
171 +/* This type should contain at least SFQ_DEPTH*2 values */
172 +typedef unsigned int esfq_index;
173 +
174 +struct esfq_head
175 +{
176 + esfq_index next;
177 + esfq_index prev;
178 +};
179 +
180 +struct esfq_sched_data
181 +{
182 +/* Parameters */
183 + int perturb_period;
184 + unsigned quantum; /* Allotment per round: MUST BE >= MTU */
185 + int limit;
186 + unsigned depth;
187 + unsigned hash_divisor;
188 + unsigned hash_kind;
189 +/* Variables */
190 + struct timer_list perturb_timer;
191 + int perturbation;
192 + esfq_index tail; /* Index of current slot in round */
193 + esfq_index max_depth; /* Maximal depth */
194 +
195 + esfq_index *ht; /* Hash table */
196 + esfq_index *next; /* Active slots link */
197 + short *allot; /* Current allotment per slot */
198 + unsigned short *hash; /* Hash value indexed by slots */
199 + struct sk_buff_head *qs; /* Slot queue */
200 + struct esfq_head *dep; /* Linked list of slots, indexed by depth */
201 +};
202 +
203 +/* This contains the info we will hash. */
204 +struct esfq_packet_info
205 +{
206 + u32 proto; /* protocol or port */
207 + u32 src; /* source from packet header */
208 + u32 dst; /* destination from packet header */
209 + u32 ctorigsrc; /* original source from conntrack */
210 + u32 ctorigdst; /* original destination from conntrack */
211 + u32 ctreplsrc; /* reply source from conntrack */
212 + u32 ctrepldst; /* reply destination from conntrack */
213 + u32 mark; /* netfilter mark (fwmark) */
214 +};
215 +
216 +static __inline__ unsigned esfq_jhash_1word(struct esfq_sched_data *q,u32 a)
217 +{
218 + return jhash_1word(a, q->perturbation) & (q->hash_divisor-1);
219 +}
220 +
221 +static __inline__ unsigned esfq_jhash_2words(struct esfq_sched_data *q, u32 a, u32 b)
222 +{
223 + return jhash_2words(a, b, q->perturbation) & (q->hash_divisor-1);
224 +}
225 +
226 +static __inline__ unsigned esfq_jhash_3words(struct esfq_sched_data *q, u32 a, u32 b, u32 c)
227 +{
228 + return jhash_3words(a, b, c, q->perturbation) & (q->hash_divisor-1);
229 +}
230 +
231 +static unsigned esfq_hash(struct esfq_sched_data *q, struct sk_buff *skb)
232 +{
233 + struct esfq_packet_info info;
234 +#ifdef CONFIG_NET_SCH_ESFQ_NFCT
235 + enum ip_conntrack_info ctinfo;
236 + struct nf_conn *ct = nf_ct_get(skb, &ctinfo);
237 +#endif
238 +
239 + switch (skb->protocol) {
240 + case __constant_htons(ETH_P_IP):
241 + {
242 + struct iphdr *iph = ip_hdr(skb);
243 + info.dst = iph->daddr;
244 + info.src = iph->saddr;
245 + if (!(iph->frag_off&htons(IP_MF|IP_OFFSET)) &&
246 + (iph->protocol == IPPROTO_TCP ||
247 + iph->protocol == IPPROTO_UDP ||
248 + iph->protocol == IPPROTO_SCTP ||
249 + iph->protocol == IPPROTO_DCCP ||
250 + iph->protocol == IPPROTO_ESP))
251 + info.proto = *(((u32*)iph) + iph->ihl);
252 + else
253 + info.proto = iph->protocol;
254 + break;
255 + }
256 + case __constant_htons(ETH_P_IPV6):
257 + {
258 + struct ipv6hdr *iph = ipv6_hdr(skb);
259 + /* Hash ipv6 addresses into a u32. This isn't ideal,
260 + * but the code is simple. */
261 + info.dst = jhash2(iph->daddr.s6_addr32, 4, q->perturbation);
262 + info.src = jhash2(iph->saddr.s6_addr32, 4, q->perturbation);
263 + if (iph->nexthdr == IPPROTO_TCP ||
264 + iph->nexthdr == IPPROTO_UDP ||
265 + iph->nexthdr == IPPROTO_SCTP ||
266 + iph->nexthdr == IPPROTO_DCCP ||
267 + iph->nexthdr == IPPROTO_ESP)
268 + info.proto = *(u32*)&iph[1];
269 + else
270 + info.proto = iph->nexthdr;
271 + break;
272 + }
273 + default:
274 + info.dst = (u32)(unsigned long)skb->dst;
275 + info.src = (u32)(unsigned long)skb->sk;
276 + info.proto = skb->protocol;
277 + }
278 +
279 + info.mark = skb->mark;
280 +
281 +#ifdef CONFIG_NET_SCH_ESFQ_NFCT
282 + /* defaults if there is no conntrack info */
283 + info.ctorigsrc = info.src;
284 + info.ctorigdst = info.dst;
285 + info.ctreplsrc = info.dst;
286 + info.ctrepldst = info.src;
287 + /* collect conntrack info */
288 + if (ct && ct != &nf_conntrack_untracked) {
289 + if (skb->protocol == __constant_htons(ETH_P_IP)) {
290 + info.ctorigsrc = ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.u3.ip;
291 + info.ctorigdst = ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.u3.ip;
292 + info.ctreplsrc = ct->tuplehash[IP_CT_DIR_REPLY].tuple.src.u3.ip;
293 + info.ctrepldst = ct->tuplehash[IP_CT_DIR_REPLY].tuple.dst.u3.ip;
294 + }
295 + else if (skb->protocol == __constant_htons(ETH_P_IPV6)) {
296 + /* Again, hash ipv6 addresses into a single u32. */
297 + info.ctorigsrc = jhash2(ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.u3.ip6, 4, q->perturbation);
298 + info.ctorigdst = jhash2(ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.u3.ip6, 4, q->perturbation);
299 + info.ctreplsrc = jhash2(ct->tuplehash[IP_CT_DIR_REPLY].tuple.src.u3.ip6, 4, q->perturbation);
300 + info.ctrepldst = jhash2(ct->tuplehash[IP_CT_DIR_REPLY].tuple.dst.u3.ip6, 4, q->perturbation);
301 + }
302 +
303 + }
304 +#endif
305 +
306 + switch(q->hash_kind) {
307 + case TCA_SFQ_HASH_CLASSIC:
308 + return esfq_jhash_3words(q, info.dst, info.src, info.proto);
309 + case TCA_SFQ_HASH_DST:
310 + return esfq_jhash_1word(q, info.dst);
311 + case TCA_SFQ_HASH_SRC:
312 + return esfq_jhash_1word(q, info.src);
313 + case TCA_SFQ_HASH_FWMARK:
314 + return esfq_jhash_1word(q, info.mark);
315 +#ifdef CONFIG_NET_SCH_ESFQ_NFCT
316 + case TCA_SFQ_HASH_CTORIGDST:
317 + return esfq_jhash_1word(q, info.ctorigdst);
318 + case TCA_SFQ_HASH_CTORIGSRC:
319 + return esfq_jhash_1word(q, info.ctorigsrc);
320 + case TCA_SFQ_HASH_CTREPLDST:
321 + return esfq_jhash_1word(q, info.ctrepldst);
322 + case TCA_SFQ_HASH_CTREPLSRC:
323 + return esfq_jhash_1word(q, info.ctreplsrc);
324 + case TCA_SFQ_HASH_CTNATCHG:
325 + {
326 + if (info.ctorigdst == info.ctreplsrc)
327 + return esfq_jhash_1word(q, info.ctorigsrc);
328 + return esfq_jhash_1word(q, info.ctreplsrc);
329 + }
330 +#endif
331 + default:
332 + if (net_ratelimit())
333 + printk(KERN_WARNING "ESFQ: Unknown hash method. Falling back to classic.\n");
334 + }
335 + return esfq_jhash_3words(q, info.dst, info.src, info.proto);
336 +}
337 +
338 +static inline void esfq_link(struct esfq_sched_data *q, esfq_index x)
339 +{
340 + esfq_index p, n;
341 + int d = q->qs[x].qlen + q->depth;
342 +
343 + p = d;
344 + n = q->dep[d].next;
345 + q->dep[x].next = n;
346 + q->dep[x].prev = p;
347 + q->dep[p].next = q->dep[n].prev = x;
348 +}
349 +
350 +static inline void esfq_dec(struct esfq_sched_data *q, esfq_index x)
351 +{
352 + esfq_index p, n;
353 +
354 + n = q->dep[x].next;
355 + p = q->dep[x].prev;
356 + q->dep[p].next = n;
357 + q->dep[n].prev = p;
358 +
359 + if (n == p && q->max_depth == q->qs[x].qlen + 1)
360 + q->max_depth--;
361 +
362 + esfq_link(q, x);
363 +}
364 +
365 +static inline void esfq_inc(struct esfq_sched_data *q, esfq_index x)
366 +{
367 + esfq_index p, n;
368 + int d;
369 +
370 + n = q->dep[x].next;
371 + p = q->dep[x].prev;
372 + q->dep[p].next = n;
373 + q->dep[n].prev = p;
374 + d = q->qs[x].qlen;
375 + if (q->max_depth < d)
376 + q->max_depth = d;
377 +
378 + esfq_link(q, x);
379 +}
380 +
381 +static unsigned int esfq_drop(struct Qdisc *sch)
382 +{
383 + struct esfq_sched_data *q = qdisc_priv(sch);
384 + esfq_index d = q->max_depth;
385 + struct sk_buff *skb;
386 + unsigned int len;
387 +
388 + /* Queue is full! Find the longest slot and
389 + drop a packet from it */
390 +
391 + if (d > 1) {
392 + esfq_index x = q->dep[d+q->depth].next;
393 + skb = q->qs[x].prev;
394 + len = skb->len;
395 + __skb_unlink(skb, &q->qs[x]);
396 + kfree_skb(skb);
397 + esfq_dec(q, x);
398 + sch->q.qlen--;
399 + sch->qstats.drops++;
400 + sch->qstats.backlog -= len;
401 + return len;
402 + }
403 +
404 + if (d == 1) {
405 + /* It is difficult to believe, but ALL THE SLOTS HAVE LENGTH 1. */
406 + d = q->next[q->tail];
407 + q->next[q->tail] = q->next[d];
408 + q->allot[q->next[d]] += q->quantum;
409 + skb = q->qs[d].prev;
410 + len = skb->len;
411 + __skb_unlink(skb, &q->qs[d]);
412 + kfree_skb(skb);
413 + esfq_dec(q, d);
414 + sch->q.qlen--;
415 + q->ht[q->hash[d]] = q->depth;
416 + sch->qstats.drops++;
417 + sch->qstats.backlog -= len;
418 + return len;
419 + }
420 +
421 + return 0;
422 +}
423 +
424 +static void esfq_q_enqueue(struct sk_buff *skb, struct esfq_sched_data *q, unsigned int end)
425 +{
426 + unsigned hash = esfq_hash(q, skb);
427 + unsigned depth = q->depth;
428 + esfq_index x;
429 +
430 + x = q->ht[hash];
431 + if (x == depth) {
432 + q->ht[hash] = x = q->dep[depth].next;
433 + q->hash[x] = hash;
434 + }
435 +
436 + if (end == ESFQ_TAIL)
437 + __skb_queue_tail(&q->qs[x], skb);
438 + else
439 + __skb_queue_head(&q->qs[x], skb);
440 +
441 + esfq_inc(q, x);
442 + if (q->qs[x].qlen == 1) { /* The flow is new */
443 + if (q->tail == depth) { /* It is the first flow */
444 + q->tail = x;
445 + q->next[x] = x;
446 + q->allot[x] = q->quantum;
447 + } else {
448 + q->next[x] = q->next[q->tail];
449 + q->next[q->tail] = x;
450 + q->tail = x;
451 + }
452 + }
453 +}
454 +
455 +static int esfq_enqueue(struct sk_buff *skb, struct Qdisc* sch)
456 +{
457 + struct esfq_sched_data *q = qdisc_priv(sch);
458 + esfq_q_enqueue(skb, q, ESFQ_TAIL);
459 + sch->qstats.backlog += skb->len;
460 + if (++sch->q.qlen < q->limit-1) {
461 + sch->bstats.bytes += skb->len;
462 + sch->bstats.packets++;
463 + return 0;
464 + }
465 +
466 + sch->qstats.drops++;
467 + esfq_drop(sch);
468 + return NET_XMIT_CN;
469 +}
470 +
471 +
472 +static int esfq_requeue(struct sk_buff *skb, struct Qdisc* sch)
473 +{
474 + struct esfq_sched_data *q = qdisc_priv(sch);
475 + esfq_q_enqueue(skb, q, ESFQ_HEAD);
476 + sch->qstats.backlog += skb->len;
477 + if (++sch->q.qlen < q->limit - 1) {
478 + sch->qstats.requeues++;
479 + return 0;
480 + }
481 +
482 + sch->qstats.drops++;
483 + esfq_drop(sch);
484 + return NET_XMIT_CN;
485 +}
486 +
487 +static struct sk_buff *esfq_q_dequeue(struct esfq_sched_data *q)
488 +{
489 + struct sk_buff *skb;
490 + unsigned depth = q->depth;
491 + esfq_index a, old_a;
492 +
493 + /* No active slots */
494 + if (q->tail == depth)
495 + return NULL;
496 +
497 + a = old_a = q->next[q->tail];
498 +
499 + /* Grab packet */
500 + skb = __skb_dequeue(&q->qs[a]);
501 + esfq_dec(q, a);
502 +
503 + /* Is the slot empty? */
504 + if (q->qs[a].qlen == 0) {
505 + q->ht[q->hash[a]] = depth;
506 + a = q->next[a];
507 + if (a == old_a) {
508 + q->tail = depth;
509 + return skb;
510 + }
511 + q->next[q->tail] = a;
512 + q->allot[a] += q->quantum;
513 + } else if ((q->allot[a] -= skb->len) <= 0) {
514 + q->tail = a;
515 + a = q->next[a];
516 + q->allot[a] += q->quantum;
517 + }
518 +
519 + return skb;
520 +}
521 +
522 +static struct sk_buff *esfq_dequeue(struct Qdisc* sch)
523 +{
524 + struct esfq_sched_data *q = qdisc_priv(sch);
525 + struct sk_buff *skb;
526 +
527 + skb = esfq_q_dequeue(q);
528 + if (skb == NULL)
529 + return NULL;
530 + sch->q.qlen--;
531 + sch->qstats.backlog -= skb->len;
532 + return skb;
533 +}
534 +
535 +static void esfq_q_destroy(struct esfq_sched_data *q)
536 +{
537 + del_timer(&q->perturb_timer);
538 + if(q->ht)
539 + kfree(q->ht);
540 + if(q->dep)
541 + kfree(q->dep);
542 + if(q->next)
543 + kfree(q->next);
544 + if(q->allot)
545 + kfree(q->allot);
546 + if(q->hash)
547 + kfree(q->hash);
548 + if(q->qs)
549 + kfree(q->qs);
550 +}
551 +
552 +static void esfq_destroy(struct Qdisc *sch)
553 +{
554 + struct esfq_sched_data *q = qdisc_priv(sch);
555 + esfq_q_destroy(q);
556 +}
557 +
558 +
559 +static void esfq_reset(struct Qdisc* sch)
560 +{
561 + struct sk_buff *skb;
562 +
563 + while ((skb = esfq_dequeue(sch)) != NULL)
564 + kfree_skb(skb);
565 +}
566 +
567 +static void esfq_perturbation(unsigned long arg)
568 +{
569 + struct Qdisc *sch = (struct Qdisc*)arg;
570 + struct esfq_sched_data *q = qdisc_priv(sch);
571 +
572 + q->perturbation = net_random()&0x1F;
573 +
574 + if (q->perturb_period) {
575 + q->perturb_timer.expires = jiffies + q->perturb_period;
576 + add_timer(&q->perturb_timer);
577 + }
578 +}
579 +
580 +static unsigned int esfq_check_hash(unsigned int kind)
581 +{
582 + switch (kind) {
583 + case TCA_SFQ_HASH_CTORIGDST:
584 + case TCA_SFQ_HASH_CTORIGSRC:
585 + case TCA_SFQ_HASH_CTREPLDST:
586 + case TCA_SFQ_HASH_CTREPLSRC:
587 + case TCA_SFQ_HASH_CTNATCHG:
588 +#ifndef CONFIG_NET_SCH_ESFQ_NFCT
589 + {
590 + if (net_ratelimit())
591 + printk(KERN_WARNING "ESFQ: Conntrack hash types disabled in kernel config. Falling back to classic.\n");
592 + return TCA_SFQ_HASH_CLASSIC;
593 + }
594 +#endif
595 + case TCA_SFQ_HASH_CLASSIC:
596 + case TCA_SFQ_HASH_DST:
597 + case TCA_SFQ_HASH_SRC:
598 + case TCA_SFQ_HASH_FWMARK:
599 + return kind;
600 + default:
601 + {
602 + if (net_ratelimit())
603 + printk(KERN_WARNING "ESFQ: Unknown hash type. Falling back to classic.\n");
604 + return TCA_SFQ_HASH_CLASSIC;
605 + }
606 + }
607 +}
608 +
609 +static int esfq_q_init(struct esfq_sched_data *q, struct rtattr *opt)
610 +{
611 + struct tc_esfq_qopt *ctl = RTA_DATA(opt);
612 + esfq_index p = ~0U/2;
613 + int i;
614 +
615 + if (opt && opt->rta_len < RTA_LENGTH(sizeof(*ctl)))
616 + return -EINVAL;
617 +
618 + q->perturbation = 0;
619 + q->hash_kind = TCA_SFQ_HASH_CLASSIC;
620 + q->max_depth = 0;
621 + if (opt == NULL) {
622 + q->perturb_period = 0;
623 + q->hash_divisor = 1024;
624 + q->tail = q->limit = q->depth = 128;
625 +
626 + } else {
627 + struct tc_esfq_qopt *ctl = RTA_DATA(opt);
628 + if (ctl->quantum)
629 + q->quantum = ctl->quantum;
630 + q->perturb_period = ctl->perturb_period*HZ;
631 + q->hash_divisor = ctl->divisor ? : 1024;
632 + q->tail = q->limit = q->depth = ctl->flows ? : 128;
633 +
634 + if ( q->depth > p - 1 )
635 + return -EINVAL;
636 +
637 + if (ctl->limit)
638 + q->limit = min_t(u32, ctl->limit, q->depth);
639 +
640 + if (ctl->hash_kind) {
641 + q->hash_kind = esfq_check_hash(ctl->hash_kind);
642 + }
643 + }
644 +
645 + q->ht = kmalloc(q->hash_divisor*sizeof(esfq_index), GFP_KERNEL);
646 + if (!q->ht)
647 + goto err_case;
648 + q->dep = kmalloc((1+q->depth*2)*sizeof(struct esfq_head), GFP_KERNEL);
649 + if (!q->dep)
650 + goto err_case;
651 + q->next = kmalloc(q->depth*sizeof(esfq_index), GFP_KERNEL);
652 + if (!q->next)
653 + goto err_case;
654 + q->allot = kmalloc(q->depth*sizeof(short), GFP_KERNEL);
655 + if (!q->allot)
656 + goto err_case;
657 + q->hash = kmalloc(q->depth*sizeof(unsigned short), GFP_KERNEL);
658 + if (!q->hash)
659 + goto err_case;
660 + q->qs = kmalloc(q->depth*sizeof(struct sk_buff_head), GFP_KERNEL);
661 + if (!q->qs)
662 + goto err_case;
663 +
664 + for (i=0; i< q->hash_divisor; i++)
665 + q->ht[i] = q->depth;
666 + for (i=0; i<q->depth; i++) {
667 + skb_queue_head_init(&q->qs[i]);
668 + q->dep[i+q->depth].next = i+q->depth;
669 + q->dep[i+q->depth].prev = i+q->depth;
670 + }
671 +
672 + for (i=0; i<q->depth; i++)
673 + esfq_link(q, i);
674 + return 0;
675 +err_case:
676 + esfq_q_destroy(q);
677 + return -ENOBUFS;
678 +}
679 +
680 +static int esfq_init(struct Qdisc *sch, struct rtattr *opt)
681 +{
682 + struct esfq_sched_data *q = qdisc_priv(sch);
683 + int err;
684 +
685 + q->quantum = psched_mtu(sch->dev); /* default */
686 + if ((err = esfq_q_init(q, opt)))
687 + return err;
688 +
689 + init_timer(&q->perturb_timer);
690 + q->perturb_timer.data = (unsigned long)sch;
691 + q->perturb_timer.function = esfq_perturbation;
692 + if (q->perturb_period) {
693 + q->perturb_timer.expires = jiffies + q->perturb_period;
694 + add_timer(&q->perturb_timer);
695 + }
696 +
697 + return 0;
698 +}
699 +
700 +static int esfq_change(struct Qdisc *sch, struct rtattr *opt)
701 +{
702 + struct esfq_sched_data *q = qdisc_priv(sch);
703 + struct esfq_sched_data new;
704 + struct sk_buff *skb;
705 + int err;
706 +
707 + /* set up new queue */
708 + memset(&new, 0, sizeof(struct esfq_sched_data));
709 + new.quantum = psched_mtu(sch->dev); /* default */
710 + if ((err = esfq_q_init(&new, opt)))
711 + return err;
712 +
713 + /* copy all packets from the old queue to the new queue */
714 + sch_tree_lock(sch);
715 + while ((skb = esfq_q_dequeue(q)) != NULL)
716 + esfq_q_enqueue(skb, &new, ESFQ_TAIL);
717 +
718 + /* clean up the old queue */
719 + esfq_q_destroy(q);
720 +
721 + /* copy elements of the new queue into the old queue */
722 + q->perturb_period = new.perturb_period;
723 + q->quantum = new.quantum;
724 + q->limit = new.limit;
725 + q->depth = new.depth;
726 + q->hash_divisor = new.hash_divisor;
727 + q->hash_kind = new.hash_kind;
728 + q->tail = new.tail;
729 + q->max_depth = new.max_depth;
730 + q->ht = new.ht;
731 + q->dep = new.dep;
732 + q->next = new.next;
733 + q->allot = new.allot;
734 + q->hash = new.hash;
735 + q->qs = new.qs;
736 +
737 + /* finish up */
738 + if (q->perturb_period) {
739 + q->perturb_timer.expires = jiffies + q->perturb_period;
740 + add_timer(&q->perturb_timer);
741 + } else {
742 + q->perturbation = 0;
743 + }
744 + sch_tree_unlock(sch);
745 + return 0;
746 +}
747 +
748 +static int esfq_dump(struct Qdisc *sch, struct sk_buff *skb)
749 +{
750 + struct esfq_sched_data *q = qdisc_priv(sch);
751 + unsigned char *b = skb->tail;
752 + struct tc_esfq_qopt opt;
753 +
754 + opt.quantum = q->quantum;
755 + opt.perturb_period = q->perturb_period/HZ;
756 +
757 + opt.limit = q->limit;
758 + opt.divisor = q->hash_divisor;
759 + opt.flows = q->depth;
760 + opt.hash_kind = q->hash_kind;
761 +
762 + RTA_PUT(skb, TCA_OPTIONS, sizeof(opt), &opt);
763 +
764 + return skb->len;
765 +
766 +rtattr_failure:
767 + skb_trim(skb, b - skb->data);
768 + return -1;
769 +}
770 +
771 +static struct Qdisc_ops esfq_qdisc_ops =
772 +{
773 + .next = NULL,
774 + .cl_ops = NULL,
775 + .id = "esfq",
776 + .priv_size = sizeof(struct esfq_sched_data),
777 + .enqueue = esfq_enqueue,
778 + .dequeue = esfq_dequeue,
779 + .requeue = esfq_requeue,
780 + .drop = esfq_drop,
781 + .init = esfq_init,
782 + .reset = esfq_reset,
783 + .destroy = esfq_destroy,
784 + .change = esfq_change,
785 + .dump = esfq_dump,
786 + .owner = THIS_MODULE,
787 +};
788 +
789 +static int __init esfq_module_init(void)
790 +{
791 + return register_qdisc(&esfq_qdisc_ops);
792 +}
793 +static void __exit esfq_module_exit(void)
794 +{
795 + unregister_qdisc(&esfq_qdisc_ops);
796 +}
797 +module_init(esfq_module_init)
798 +module_exit(esfq_module_exit)
799 +MODULE_LICENSE("GPL");
This page took 0.072103 seconds and 5 git commands to generate.