]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - net/sched/sch_ingress.c
drm/i915: Save the old CDCLK atomic state
[mirror_ubuntu-bionic-kernel.git] / net / sched / sch_ingress.c
CommitLineData
1f211a1b
DB
1/* net/sched/sch_ingress.c - Ingress and clsact qdisc
2 *
1da177e4
LT
3 * This program is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU General Public License
5 * as published by the Free Software Foundation; either version
6 * 2 of the License, or (at your option) any later version.
7 *
8 * Authors: Jamal Hadi Salim 1999
9 */
10
1da177e4
LT
11#include <linux/module.h>
12#include <linux/types.h>
0ba48053 13#include <linux/list.h>
1da177e4 14#include <linux/skbuff.h>
1da177e4 15#include <linux/rtnetlink.h>
d2788d34 16
dc5fc579 17#include <net/netlink.h>
1da177e4 18#include <net/pkt_sched.h>
cf1facda 19#include <net/pkt_cls.h>
1da177e4 20
6529eaba
JP
21struct ingress_sched_data {
22 struct tcf_block *block;
6e40cf2d 23 struct tcf_block_ext_info block_info;
46209401 24 struct mini_Qdisc_pair miniqp;
6529eaba
JP
25};
26
1da177e4
LT
27static struct Qdisc *ingress_leaf(struct Qdisc *sch, unsigned long arg)
28{
29 return NULL;
30}
31
143976ce 32static unsigned long ingress_find(struct Qdisc *sch, u32 classid)
1da177e4 33{
1da177e4
LT
34 return TC_H_MIN(classid) + 1;
35}
36
1da177e4 37static unsigned long ingress_bind_filter(struct Qdisc *sch,
58f4df42 38 unsigned long parent, u32 classid)
1da177e4 39{
143976ce 40 return ingress_find(sch, classid);
1da177e4
LT
41}
42
143976ce 43static void ingress_unbind_filter(struct Qdisc *sch, unsigned long cl)
1da177e4
LT
44{
45}
46
58f4df42 47static void ingress_walk(struct Qdisc *sch, struct qdisc_walker *walker)
1da177e4 48{
1da177e4
LT
49}
50
6529eaba 51static struct tcf_block *ingress_tcf_block(struct Qdisc *sch, unsigned long cl)
1da177e4 52{
6529eaba 53 struct ingress_sched_data *q = qdisc_priv(sch);
1da177e4 54
6529eaba 55 return q->block;
1da177e4
LT
56}
57
c7eb7d72
JP
58static void clsact_chain_head_change(struct tcf_proto *tp_head, void *priv)
59{
46209401 60 struct mini_Qdisc_pair *miniqp = priv;
c7eb7d72 61
46209401 62 mini_qdisc_pair_swap(miniqp, tp_head);
c7eb7d72
JP
63}
64
4577139b
DB
65static int ingress_init(struct Qdisc *sch, struct nlattr *opt)
66{
6529eaba
JP
67 struct ingress_sched_data *q = qdisc_priv(sch);
68 struct net_device *dev = qdisc_dev(sch);
6529eaba 69
b59e6979
JP
70 net_inc_ingress_queue();
71
46209401
JP
72 mini_qdisc_pair_init(&q->miniqp, sch, &dev->miniq_ingress);
73
6e40cf2d 74 q->block_info.binder_type = TCF_BLOCK_BINDER_TYPE_CLSACT_INGRESS;
c7eb7d72 75 q->block_info.chain_head_change = clsact_chain_head_change;
46209401 76 q->block_info.chain_head_change_priv = &q->miniqp;
6e40cf2d 77
81d947e2 78 return tcf_block_get_ext(&q->block, sch, &q->block_info);
4577139b
DB
79}
80
1da177e4
LT
81static void ingress_destroy(struct Qdisc *sch)
82{
6529eaba 83 struct ingress_sched_data *q = qdisc_priv(sch);
1da177e4 84
c7eb7d72 85 tcf_block_put_ext(q->block, sch, &q->block_info);
4577139b 86 net_dec_ingress_queue();
1da177e4
LT
87}
88
1da177e4
LT
89static int ingress_dump(struct Qdisc *sch, struct sk_buff *skb)
90{
4b3550ef 91 struct nlattr *nest;
1da177e4 92
4b3550ef
PM
93 nest = nla_nest_start(skb, TCA_OPTIONS);
94 if (nest == NULL)
95 goto nla_put_failure;
d2788d34 96
d59b7d80 97 return nla_nest_end(skb, nest);
1da177e4 98
1e90474c 99nla_put_failure:
4b3550ef 100 nla_nest_cancel(skb, nest);
1da177e4
LT
101 return -1;
102}
103
20fea08b 104static const struct Qdisc_class_ops ingress_class_ops = {
1da177e4 105 .leaf = ingress_leaf,
143976ce 106 .find = ingress_find,
1da177e4 107 .walk = ingress_walk,
6529eaba 108 .tcf_block = ingress_tcf_block,
1da177e4 109 .bind_tcf = ingress_bind_filter,
143976ce 110 .unbind_tcf = ingress_unbind_filter,
1da177e4
LT
111};
112
20fea08b 113static struct Qdisc_ops ingress_qdisc_ops __read_mostly = {
1da177e4
LT
114 .cl_ops = &ingress_class_ops,
115 .id = "ingress",
6529eaba 116 .priv_size = sizeof(struct ingress_sched_data),
81d947e2 117 .static_flags = TCQ_F_CPUSTATS,
4577139b 118 .init = ingress_init,
1da177e4 119 .destroy = ingress_destroy,
1da177e4
LT
120 .dump = ingress_dump,
121 .owner = THIS_MODULE,
122};
123
6529eaba
JP
124struct clsact_sched_data {
125 struct tcf_block *ingress_block;
126 struct tcf_block *egress_block;
6e40cf2d
JP
127 struct tcf_block_ext_info ingress_block_info;
128 struct tcf_block_ext_info egress_block_info;
46209401
JP
129 struct mini_Qdisc_pair miniqp_ingress;
130 struct mini_Qdisc_pair miniqp_egress;
6529eaba
JP
131};
132
143976ce 133static unsigned long clsact_find(struct Qdisc *sch, u32 classid)
1f211a1b
DB
134{
135 switch (TC_H_MIN(classid)) {
136 case TC_H_MIN(TC_H_MIN_INGRESS):
137 case TC_H_MIN(TC_H_MIN_EGRESS):
138 return TC_H_MIN(classid);
139 default:
140 return 0;
141 }
142}
143
144static unsigned long clsact_bind_filter(struct Qdisc *sch,
145 unsigned long parent, u32 classid)
146{
143976ce 147 return clsact_find(sch, classid);
1f211a1b
DB
148}
149
6529eaba 150static struct tcf_block *clsact_tcf_block(struct Qdisc *sch, unsigned long cl)
1f211a1b 151{
6529eaba 152 struct clsact_sched_data *q = qdisc_priv(sch);
1f211a1b
DB
153
154 switch (cl) {
155 case TC_H_MIN(TC_H_MIN_INGRESS):
6529eaba 156 return q->ingress_block;
1f211a1b 157 case TC_H_MIN(TC_H_MIN_EGRESS):
6529eaba 158 return q->egress_block;
1f211a1b
DB
159 default:
160 return NULL;
161 }
162}
163
164static int clsact_init(struct Qdisc *sch, struct nlattr *opt)
165{
6529eaba
JP
166 struct clsact_sched_data *q = qdisc_priv(sch);
167 struct net_device *dev = qdisc_dev(sch);
168 int err;
169
b59e6979
JP
170 net_inc_ingress_queue();
171 net_inc_egress_queue();
172
46209401
JP
173 mini_qdisc_pair_init(&q->miniqp_ingress, sch, &dev->miniq_ingress);
174
6e40cf2d 175 q->ingress_block_info.binder_type = TCF_BLOCK_BINDER_TYPE_CLSACT_INGRESS;
c7eb7d72 176 q->ingress_block_info.chain_head_change = clsact_chain_head_change;
46209401 177 q->ingress_block_info.chain_head_change_priv = &q->miniqp_ingress;
6e40cf2d 178
c7eb7d72 179 err = tcf_block_get_ext(&q->ingress_block, sch, &q->ingress_block_info);
6529eaba
JP
180 if (err)
181 return err;
182
46209401
JP
183 mini_qdisc_pair_init(&q->miniqp_egress, sch, &dev->miniq_egress);
184
6e40cf2d 185 q->egress_block_info.binder_type = TCF_BLOCK_BINDER_TYPE_CLSACT_EGRESS;
c7eb7d72 186 q->egress_block_info.chain_head_change = clsact_chain_head_change;
46209401 187 q->egress_block_info.chain_head_change_priv = &q->miniqp_egress;
6e40cf2d 188
81d947e2 189 return tcf_block_get_ext(&q->egress_block, sch, &q->egress_block_info);
1f211a1b
DB
190}
191
192static void clsact_destroy(struct Qdisc *sch)
193{
6529eaba 194 struct clsact_sched_data *q = qdisc_priv(sch);
1f211a1b 195
c7eb7d72
JP
196 tcf_block_put_ext(q->egress_block, sch, &q->egress_block_info);
197 tcf_block_put_ext(q->ingress_block, sch, &q->ingress_block_info);
1f211a1b
DB
198
199 net_dec_ingress_queue();
200 net_dec_egress_queue();
201}
202
203static const struct Qdisc_class_ops clsact_class_ops = {
204 .leaf = ingress_leaf,
143976ce 205 .find = clsact_find,
1f211a1b 206 .walk = ingress_walk,
6529eaba 207 .tcf_block = clsact_tcf_block,
1f211a1b 208 .bind_tcf = clsact_bind_filter,
143976ce 209 .unbind_tcf = ingress_unbind_filter,
1f211a1b
DB
210};
211
212static struct Qdisc_ops clsact_qdisc_ops __read_mostly = {
213 .cl_ops = &clsact_class_ops,
214 .id = "clsact",
6529eaba 215 .priv_size = sizeof(struct clsact_sched_data),
81d947e2 216 .static_flags = TCQ_F_CPUSTATS,
1f211a1b
DB
217 .init = clsact_init,
218 .destroy = clsact_destroy,
219 .dump = ingress_dump,
220 .owner = THIS_MODULE,
221};
222
1da177e4
LT
223static int __init ingress_module_init(void)
224{
1f211a1b
DB
225 int ret;
226
227 ret = register_qdisc(&ingress_qdisc_ops);
228 if (!ret) {
229 ret = register_qdisc(&clsact_qdisc_ops);
230 if (ret)
231 unregister_qdisc(&ingress_qdisc_ops);
232 }
233
234 return ret;
1da177e4 235}
58f4df42 236
10297b99 237static void __exit ingress_module_exit(void)
1da177e4
LT
238{
239 unregister_qdisc(&ingress_qdisc_ops);
1f211a1b 240 unregister_qdisc(&clsact_qdisc_ops);
1da177e4 241}
58f4df42 242
d2788d34
DB
243module_init(ingress_module_init);
244module_exit(ingress_module_exit);
245
1f211a1b 246MODULE_ALIAS("sch_clsact");
1da177e4 247MODULE_LICENSE("GPL");