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/module.h>
13 #include <linux/slab.h>
14 #include <linux/types.h>
15 #include <linux/kernel.h>
16 #include <linux/errno.h>
17 #include <linux/skbuff.h>
18 #include <net/pkt_sched.h>
20 /* 1 band FIFO pseudo-"scheduler" */
22 static int bfifo_enqueue(struct sk_buff
*skb
, struct Qdisc
*sch
)
24 if (likely(sch
->qstats
.backlog
+ qdisc_pkt_len(skb
) <= sch
->limit
))
25 return qdisc_enqueue_tail(skb
, sch
);
27 return qdisc_reshape_fail(skb
, sch
);
30 static int pfifo_enqueue(struct sk_buff
*skb
, struct Qdisc
*sch
)
32 if (likely(skb_queue_len(&sch
->q
) < sch
->limit
))
33 return qdisc_enqueue_tail(skb
, sch
);
35 return qdisc_reshape_fail(skb
, sch
);
38 static int pfifo_tail_enqueue(struct sk_buff
*skb
, struct Qdisc
*sch
)
40 if (likely(skb_queue_len(&sch
->q
) < sch
->limit
))
41 return qdisc_enqueue_tail(skb
, sch
);
43 /* queue full, remove one skb to fulfill the limit */
44 __qdisc_queue_drop_head(sch
, &sch
->q
);
46 qdisc_enqueue_tail(skb
, sch
);
51 static int fifo_init(struct Qdisc
*sch
, struct nlattr
*opt
)
54 bool is_bfifo
= sch
->ops
== &bfifo_qdisc_ops
;
57 u32 limit
= qdisc_dev(sch
)->tx_queue_len
? : 1;
60 limit
*= psched_mtu(qdisc_dev(sch
));
64 struct tc_fifo_qopt
*ctl
= nla_data(opt
);
66 if (nla_len(opt
) < sizeof(*ctl
))
69 sch
->limit
= ctl
->limit
;
73 bypass
= sch
->limit
>= psched_mtu(qdisc_dev(sch
));
75 bypass
= sch
->limit
>= 1;
78 sch
->flags
|= TCQ_F_CAN_BYPASS
;
80 sch
->flags
&= ~TCQ_F_CAN_BYPASS
;
84 static int fifo_dump(struct Qdisc
*sch
, struct sk_buff
*skb
)
86 struct tc_fifo_qopt opt
= { .limit
= sch
->limit
};
88 NLA_PUT(skb
, TCA_OPTIONS
, sizeof(opt
), &opt
);
95 struct Qdisc_ops pfifo_qdisc_ops __read_mostly
= {
98 .enqueue
= pfifo_enqueue
,
99 .dequeue
= qdisc_dequeue_head
,
100 .peek
= qdisc_peek_head
,
101 .drop
= qdisc_queue_drop
,
103 .reset
= qdisc_reset_queue
,
106 .owner
= THIS_MODULE
,
108 EXPORT_SYMBOL(pfifo_qdisc_ops
);
110 struct Qdisc_ops bfifo_qdisc_ops __read_mostly
= {
113 .enqueue
= bfifo_enqueue
,
114 .dequeue
= qdisc_dequeue_head
,
115 .peek
= qdisc_peek_head
,
116 .drop
= qdisc_queue_drop
,
118 .reset
= qdisc_reset_queue
,
121 .owner
= THIS_MODULE
,
123 EXPORT_SYMBOL(bfifo_qdisc_ops
);
125 struct Qdisc_ops pfifo_head_drop_qdisc_ops __read_mostly
= {
126 .id
= "pfifo_head_drop",
128 .enqueue
= pfifo_tail_enqueue
,
129 .dequeue
= qdisc_dequeue_head
,
130 .peek
= qdisc_peek_head
,
131 .drop
= qdisc_queue_drop_head
,
133 .reset
= qdisc_reset_queue
,
136 .owner
= THIS_MODULE
,
139 /* Pass size change message down to embedded FIFO */
140 int fifo_set_limit(struct Qdisc
*q
, unsigned int limit
)
145 /* Hack to avoid sending change message to non-FIFO */
146 if (strncmp(q
->ops
->id
+ 1, "fifo", 4) != 0)
149 nla
= kmalloc(nla_attr_size(sizeof(struct tc_fifo_qopt
)), GFP_KERNEL
);
151 nla
->nla_type
= RTM_NEWQDISC
;
152 nla
->nla_len
= nla_attr_size(sizeof(struct tc_fifo_qopt
));
153 ((struct tc_fifo_qopt
*)nla_data(nla
))->limit
= limit
;
155 ret
= q
->ops
->change(q
, nla
);
160 EXPORT_SYMBOL(fifo_set_limit
);
162 struct Qdisc
*fifo_create_dflt(struct Qdisc
*sch
, struct Qdisc_ops
*ops
,
168 q
= qdisc_create_dflt(sch
->dev_queue
, ops
, TC_H_MAKE(sch
->handle
, 1));
170 err
= fifo_set_limit(q
, limit
);
177 return q
? : ERR_PTR(err
);
179 EXPORT_SYMBOL(fifo_create_dflt
);