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