blob: 3b8d7197c06bff3f346b1616db0210d6e8c5e704 [file] [log] [blame]
Thomas Gleixner2874c5f2019-05-27 08:55:01 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
3 * net/sched/sch_prio.c Simple 3-band priority "scheduler".
4 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
YOSHIFUJI Hideaki10297b92007-02-09 23:25:16 +09006 * Fixes: 19990609: J Hadi Salim <hadi@nortelnetworks.com>:
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 * Init -- EINVAL when opt undefined
8 */
9
Linus Torvalds1da177e2005-04-16 15:20:36 -070010#include <linux/module.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090011#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#include <linux/types.h>
13#include <linux/kernel.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <linux/string.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <linux/errno.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#include <linux/skbuff.h>
Arnaldo Carvalho de Melodc5fc572007-03-25 23:06:12 -070017#include <net/netlink.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include <net/pkt_sched.h>
Jiri Pirkocf1facd2017-02-09 14:38:56 +010019#include <net/pkt_cls.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020
Eric Dumazetcc7ec452011-01-19 19:26:56 +000021struct prio_sched_data {
Linus Torvalds1da177e2005-04-16 15:20:36 -070022 int bands;
John Fastabend25d8c0d2014-09-12 20:05:27 -070023 struct tcf_proto __rcu *filter_list;
Jiri Pirko6529eab2017-05-17 11:07:55 +020024 struct tcf_block *block;
Linus Torvalds1da177e2005-04-16 15:20:36 -070025 u8 prio2band[TC_PRIO_MAX+1];
26 struct Qdisc *queues[TCQ_PRIO_BANDS];
27};
28
29
30static struct Qdisc *
31prio_classify(struct sk_buff *skb, struct Qdisc *sch, int *qerr)
32{
33 struct prio_sched_data *q = qdisc_priv(sch);
34 u32 band = skb->priority;
35 struct tcf_result res;
John Fastabend25d8c0d2014-09-12 20:05:27 -070036 struct tcf_proto *fl;
Patrick McHardybdba91e2007-07-30 17:07:14 -070037 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -070038
Jarek Poplawskic27f3392008-08-04 22:39:11 -070039 *qerr = NET_XMIT_SUCCESS | __NET_XMIT_BYPASS;
Linus Torvalds1da177e2005-04-16 15:20:36 -070040 if (TC_H_MAJ(skb->priority) != sch->handle) {
John Fastabend25d8c0d2014-09-12 20:05:27 -070041 fl = rcu_dereference_bh(q->filter_list);
Davide Caratti3aa26052021-07-28 20:08:00 +020042 err = tcf_classify(skb, NULL, fl, &res, false);
Linus Torvalds1da177e2005-04-16 15:20:36 -070043#ifdef CONFIG_NET_CLS_ACT
Lucas Nussbaumdbaaa072007-08-30 22:35:46 -070044 switch (err) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070045 case TC_ACT_STOLEN:
46 case TC_ACT_QUEUED:
Jiri Pirkoe25ea212017-06-06 14:12:02 +020047 case TC_ACT_TRAP:
Jarek Poplawski378a2f02008-08-04 22:31:03 -070048 *qerr = NET_XMIT_SUCCESS | __NET_XMIT_STOLEN;
Gustavo A. R. Silva964201d2020-07-07 12:21:38 -050049 fallthrough;
Linus Torvalds1da177e2005-04-16 15:20:36 -070050 case TC_ACT_SHOT:
51 return NULL;
Stephen Hemminger3ff50b72007-04-20 17:09:22 -070052 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070053#endif
John Fastabend25d8c0d2014-09-12 20:05:27 -070054 if (!fl || err < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070055 if (TC_H_MAJ(band))
56 band = 0;
Eric Dumazetcc7ec452011-01-19 19:26:56 +000057 return q->queues[q->prio2band[band & TC_PRIO_MAX]];
Linus Torvalds1da177e2005-04-16 15:20:36 -070058 }
59 band = res.classid;
60 }
61 band = TC_H_MIN(band) - 1;
Jamal Hadi Salim3e5c2d32007-05-14 02:57:19 -070062 if (band >= q->bands)
David S. Miller1d8ae3f2008-07-15 02:52:19 -070063 return q->queues[q->prio2band[0]];
64
Linus Torvalds1da177e2005-04-16 15:20:36 -070065 return q->queues[band];
66}
67
Petr Machataac5c66f2020-07-14 20:03:08 +030068static int
69prio_enqueue(struct sk_buff *skb, struct Qdisc *sch, struct sk_buff **to_free)
Linus Torvalds1da177e2005-04-16 15:20:36 -070070{
Toke Høiland-Jørgensenf6bab192019-01-09 17:09:42 +010071 unsigned int len = qdisc_pkt_len(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 struct Qdisc *qdisc;
73 int ret;
74
75 qdisc = prio_classify(skb, sch, &ret);
76#ifdef CONFIG_NET_CLS_ACT
77 if (qdisc == NULL) {
Jamal Hadi Salim29f1df62006-01-08 22:35:55 -080078
Jarek Poplawskic27f3392008-08-04 22:39:11 -070079 if (ret & __NET_XMIT_BYPASS)
John Fastabend25331d62014-09-28 11:53:29 -070080 qdisc_qstats_drop(sch);
Gao Feng39ad1292017-09-04 14:21:12 +080081 __qdisc_drop(skb, to_free);
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 return ret;
83 }
84#endif
85
Petr Machataac5c66f2020-07-14 20:03:08 +030086 ret = qdisc_enqueue(skb, qdisc, to_free);
Jussi Kivilinna5f861732008-07-20 00:08:04 -070087 if (ret == NET_XMIT_SUCCESS) {
Toke Høiland-Jørgensenf6bab192019-01-09 17:09:42 +010088 sch->qstats.backlog += len;
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 sch->q.qlen++;
90 return NET_XMIT_SUCCESS;
91 }
Jarek Poplawski378a2f02008-08-04 22:31:03 -070092 if (net_xmit_drop_count(ret))
John Fastabend25331d62014-09-28 11:53:29 -070093 qdisc_qstats_drop(sch);
YOSHIFUJI Hideaki10297b92007-02-09 23:25:16 +090094 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -070095}
96
Patrick McHardy48a8f512008-10-31 00:44:18 -070097static struct sk_buff *prio_peek(struct Qdisc *sch)
98{
99 struct prio_sched_data *q = qdisc_priv(sch);
100 int prio;
101
102 for (prio = 0; prio < q->bands; prio++) {
103 struct Qdisc *qdisc = q->queues[prio];
104 struct sk_buff *skb = qdisc->ops->peek(qdisc);
105 if (skb)
106 return skb;
107 }
108 return NULL;
109}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110
Eric Dumazetcc7ec452011-01-19 19:26:56 +0000111static struct sk_buff *prio_dequeue(struct Qdisc *sch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 struct prio_sched_data *q = qdisc_priv(sch);
114 int prio;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115
116 for (prio = 0; prio < q->bands; prio++) {
David S. Miller1d8ae3f2008-07-15 02:52:19 -0700117 struct Qdisc *qdisc = q->queues[prio];
Florian Westphal35576192011-08-09 02:04:43 +0000118 struct sk_buff *skb = qdisc_dequeue_peeked(qdisc);
David S. Miller1d8ae3f2008-07-15 02:52:19 -0700119 if (skb) {
Eric Dumazet9190b3b2011-01-20 23:31:33 -0800120 qdisc_bstats_update(sch, skb);
WANG Cong6529d752016-06-01 16:15:16 -0700121 qdisc_qstats_backlog_dec(sch, skb);
David S. Miller1d8ae3f2008-07-15 02:52:19 -0700122 sch->q.qlen--;
123 return skb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 }
125 }
126 return NULL;
127
128}
129
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130static void
Eric Dumazetcc7ec452011-01-19 19:26:56 +0000131prio_reset(struct Qdisc *sch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132{
133 int prio;
134 struct prio_sched_data *q = qdisc_priv(sch);
135
Eric Dumazetcc7ec452011-01-19 19:26:56 +0000136 for (prio = 0; prio < q->bands; prio++)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 qdisc_reset(q->queues[prio]);
WANG Cong6529d752016-06-01 16:15:16 -0700138 sch->qstats.backlog = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 sch->q.qlen = 0;
140}
141
Nogah Frankel98ceb7b2018-02-28 10:45:05 +0100142static int prio_offload(struct Qdisc *sch, struct tc_prio_qopt *qopt)
Nogah Frankel7fdb61b2018-01-14 12:33:15 +0100143{
Nogah Frankel7fdb61b2018-01-14 12:33:15 +0100144 struct net_device *dev = qdisc_dev(sch);
145 struct tc_prio_qopt_offload opt = {
146 .handle = sch->handle,
147 .parent = sch->parent,
148 };
149
150 if (!tc_can_offload(dev) || !dev->netdev_ops->ndo_setup_tc)
151 return -EOPNOTSUPP;
152
Nogah Frankel98ceb7b2018-02-28 10:45:05 +0100153 if (qopt) {
Nogah Frankel7fdb61b2018-01-14 12:33:15 +0100154 opt.command = TC_PRIO_REPLACE;
Nogah Frankel98ceb7b2018-02-28 10:45:05 +0100155 opt.replace_params.bands = qopt->bands;
156 memcpy(&opt.replace_params.priomap, qopt->priomap,
Nogah Frankel7fdb61b2018-01-14 12:33:15 +0100157 TC_PRIO_MAX + 1);
158 opt.replace_params.qstats = &sch->qstats;
159 } else {
160 opt.command = TC_PRIO_DESTROY;
161 }
162
163 return dev->netdev_ops->ndo_setup_tc(dev, TC_SETUP_QDISC_PRIO, &opt);
164}
165
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166static void
Eric Dumazetcc7ec452011-01-19 19:26:56 +0000167prio_destroy(struct Qdisc *sch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168{
169 int prio;
170 struct prio_sched_data *q = qdisc_priv(sch);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171
Jiri Pirko6529eab2017-05-17 11:07:55 +0200172 tcf_block_put(q->block);
Nogah Frankel98ceb7b2018-02-28 10:45:05 +0100173 prio_offload(sch, NULL);
Eric Dumazetcc7ec452011-01-19 19:26:56 +0000174 for (prio = 0; prio < q->bands; prio++)
Vlad Buslov86bd4462018-09-24 19:22:50 +0300175 qdisc_put(q->queues[prio]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176}
177
Alexander Aring20307212017-12-20 12:35:14 -0500178static int prio_tune(struct Qdisc *sch, struct nlattr *opt,
179 struct netlink_ext_ack *extack)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180{
181 struct prio_sched_data *q = qdisc_priv(sch);
Eric Dumazet3d7c8252016-06-13 11:33:32 -0700182 struct Qdisc *queues[TCQ_PRIO_BANDS];
183 int oldbands = q->bands, i;
Peter P Waskiewicz Jrd62733c2007-06-28 21:04:31 -0700184 struct tc_prio_qopt *qopt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185
David S. Miller1d8ae3f2008-07-15 02:52:19 -0700186 if (nla_len(opt) < sizeof(*qopt))
187 return -EINVAL;
188 qopt = nla_data(opt);
Patrick McHardycee63722008-01-23 20:33:32 -0800189
David S. Miller1d8ae3f2008-07-15 02:52:19 -0700190 if (qopt->bands > TCQ_PRIO_BANDS || qopt->bands < 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191 return -EINVAL;
192
Eric Dumazetcc7ec452011-01-19 19:26:56 +0000193 for (i = 0; i <= TC_PRIO_MAX; i++) {
David S. Miller1d8ae3f2008-07-15 02:52:19 -0700194 if (qopt->priomap[i] >= qopt->bands)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195 return -EINVAL;
196 }
197
Eric Dumazet3d7c8252016-06-13 11:33:32 -0700198 /* Before commit, make sure we can allocate all new qdiscs */
199 for (i = oldbands; i < qopt->bands; i++) {
200 queues[i] = qdisc_create_dflt(sch->dev_queue, &pfifo_qdisc_ops,
Alexander Aringa38a98822017-12-20 12:35:21 -0500201 TC_H_MAKE(sch->handle, i + 1),
202 extack);
Eric Dumazet3d7c8252016-06-13 11:33:32 -0700203 if (!queues[i]) {
204 while (i > oldbands)
Vlad Buslov86bd4462018-09-24 19:22:50 +0300205 qdisc_put(queues[--i]);
Eric Dumazet3d7c8252016-06-13 11:33:32 -0700206 return -ENOMEM;
207 }
208 }
209
Nogah Frankel98ceb7b2018-02-28 10:45:05 +0100210 prio_offload(sch, qopt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 sch_tree_lock(sch);
David S. Miller1d8ae3f2008-07-15 02:52:19 -0700212 q->bands = qopt->bands;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213 memcpy(q->prio2band, qopt->priomap, TC_PRIO_MAX+1);
214
Paolo Abenie5f0e8f2019-03-28 16:53:13 +0100215 for (i = q->bands; i < oldbands; i++)
216 qdisc_tree_flush_backlog(q->queues[i]);
Eric Dumazet3d7c8252016-06-13 11:33:32 -0700217
Jiri Kosina49b49972017-03-08 16:03:32 +0100218 for (i = oldbands; i < q->bands; i++) {
Eric Dumazet3d7c8252016-06-13 11:33:32 -0700219 q->queues[i] = queues[i];
Jiri Kosina49b49972017-03-08 16:03:32 +0100220 if (q->queues[i] != &noop_qdisc)
221 qdisc_hash_add(q->queues[i], true);
222 }
Eric Dumazet3d7c8252016-06-13 11:33:32 -0700223
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 sch_tree_unlock(sch);
Jakub Kicinski7b8e0b62018-11-07 17:33:40 -0800225
226 for (i = q->bands; i < oldbands; i++)
227 qdisc_put(q->queues[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 return 0;
229}
230
Alexander Aringe63d7dfd2017-12-20 12:35:13 -0500231static int prio_init(struct Qdisc *sch, struct nlattr *opt,
232 struct netlink_ext_ack *extack)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233{
Jiri Pirko6529eab2017-05-17 11:07:55 +0200234 struct prio_sched_data *q = qdisc_priv(sch);
235 int err;
236
Eric Dumazet3d7c8252016-06-13 11:33:32 -0700237 if (!opt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239
Alexander Aring8d1a77f2017-12-20 12:35:19 -0500240 err = tcf_block_get(&q->block, &q->filter_list, sch, extack);
Jiri Pirko6529eab2017-05-17 11:07:55 +0200241 if (err)
242 return err;
243
Alexander Aring20307212017-12-20 12:35:14 -0500244 return prio_tune(sch, opt, extack);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245}
246
Nogah Frankel7fdb61b2018-01-14 12:33:15 +0100247static int prio_dump_offload(struct Qdisc *sch)
248{
Nogah Frankel7fdb61b2018-01-14 12:33:15 +0100249 struct tc_prio_qopt_offload hw_stats = {
Andrew Mortonef58ca32018-01-18 16:30:49 -0800250 .command = TC_PRIO_STATS,
Nogah Frankel7fdb61b2018-01-14 12:33:15 +0100251 .handle = sch->handle,
252 .parent = sch->parent,
Andrew Mortonef58ca32018-01-18 16:30:49 -0800253 {
254 .stats = {
255 .bstats = &sch->bstats,
256 .qstats = &sch->qstats,
257 },
258 },
Nogah Frankel7fdb61b2018-01-14 12:33:15 +0100259 };
Nogah Frankel7fdb61b2018-01-14 12:33:15 +0100260
Jakub Kicinskib5928432018-11-07 17:33:34 -0800261 return qdisc_offload_dump_helper(sch, TC_SETUP_QDISC_PRIO, &hw_stats);
Nogah Frankel7fdb61b2018-01-14 12:33:15 +0100262}
263
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264static int prio_dump(struct Qdisc *sch, struct sk_buff *skb)
265{
266 struct prio_sched_data *q = qdisc_priv(sch);
Arnaldo Carvalho de Melo27a884d2007-04-19 20:29:13 -0700267 unsigned char *b = skb_tail_pointer(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 struct tc_prio_qopt opt;
Nogah Frankel7fdb61b2018-01-14 12:33:15 +0100269 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270
271 opt.bands = q->bands;
Eric Dumazetcc7ec452011-01-19 19:26:56 +0000272 memcpy(&opt.priomap, q->prio2band, TC_PRIO_MAX + 1);
Peter P Waskiewicz Jrd62733c2007-06-28 21:04:31 -0700273
Nogah Frankel7fdb61b2018-01-14 12:33:15 +0100274 err = prio_dump_offload(sch);
275 if (err)
276 goto nla_put_failure;
277
David S. Miller1b34ec42012-03-29 05:11:39 -0400278 if (nla_put(skb, TCA_OPTIONS, sizeof(opt), &opt))
279 goto nla_put_failure;
Peter P Waskiewicz Jrd62733c2007-06-28 21:04:31 -0700280
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281 return skb->len;
282
Patrick McHardy1e904742008-01-22 22:11:17 -0800283nla_put_failure:
Arnaldo Carvalho de Melodc5fc572007-03-25 23:06:12 -0700284 nlmsg_trim(skb, b);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285 return -1;
286}
287
288static int prio_graft(struct Qdisc *sch, unsigned long arg, struct Qdisc *new,
Alexander Aring653d6fd2017-12-20 12:35:17 -0500289 struct Qdisc **old, struct netlink_ext_ack *extack)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290{
291 struct prio_sched_data *q = qdisc_priv(sch);
Nogah Frankelb9c7a7a2018-02-28 10:45:06 +0100292 struct tc_prio_qopt_offload graft_offload;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293 unsigned long band = arg - 1;
294
Petr Machata240ce7f2020-01-06 18:01:56 +0000295 if (!new) {
296 new = qdisc_create_dflt(sch->dev_queue, &pfifo_qdisc_ops,
297 TC_H_MAKE(sch->handle, arg), extack);
298 if (!new)
299 new = &noop_qdisc;
300 else
301 qdisc_hash_add(new, true);
302 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303
WANG Cong86a79962016-02-25 14:55:00 -0800304 *old = qdisc_replace(sch, new, &q->queues[band]);
Nogah Frankelb9c7a7a2018-02-28 10:45:06 +0100305
Nogah Frankelb9c7a7a2018-02-28 10:45:06 +0100306 graft_offload.handle = sch->handle;
307 graft_offload.parent = sch->parent;
308 graft_offload.graft_params.band = band;
309 graft_offload.graft_params.child_handle = new->handle;
310 graft_offload.command = TC_PRIO_GRAFT;
311
Jakub Kicinskibfaee912018-11-07 17:33:37 -0800312 qdisc_offload_graft_helper(qdisc_dev(sch), sch, new, *old,
313 TC_SETUP_QDISC_PRIO, &graft_offload,
314 extack);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315 return 0;
316}
317
318static struct Qdisc *
319prio_leaf(struct Qdisc *sch, unsigned long arg)
320{
321 struct prio_sched_data *q = qdisc_priv(sch);
322 unsigned long band = arg - 1;
323
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 return q->queues[band];
325}
326
WANG Cong143976c2017-08-24 16:51:29 -0700327static unsigned long prio_find(struct Qdisc *sch, u32 classid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328{
329 struct prio_sched_data *q = qdisc_priv(sch);
330 unsigned long band = TC_H_MIN(classid);
331
332 if (band - 1 >= q->bands)
333 return 0;
334 return band;
335}
336
337static unsigned long prio_bind(struct Qdisc *sch, unsigned long parent, u32 classid)
338{
WANG Cong143976c2017-08-24 16:51:29 -0700339 return prio_find(sch, classid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340}
341
342
WANG Cong143976c2017-08-24 16:51:29 -0700343static void prio_unbind(struct Qdisc *q, unsigned long cl)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345}
346
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347static int prio_dump_class(struct Qdisc *sch, unsigned long cl, struct sk_buff *skb,
348 struct tcmsg *tcm)
349{
350 struct prio_sched_data *q = qdisc_priv(sch);
351
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352 tcm->tcm_handle |= TC_H_MIN(cl);
Patrick McHardy5b9a9cc2009-09-04 06:41:17 +0000353 tcm->tcm_info = q->queues[cl-1]->handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 return 0;
355}
356
Jarek Poplawski2cf6c362007-01-31 12:21:24 -0800357static int prio_dump_class_stats(struct Qdisc *sch, unsigned long cl,
358 struct gnet_dump *d)
359{
360 struct prio_sched_data *q = qdisc_priv(sch);
361 struct Qdisc *cl_q;
362
363 cl_q = q->queues[cl - 1];
Ahmed S. Darwish29cbcd82021-10-16 10:49:10 +0200364 if (gnet_stats_copy_basic(d, cl_q->cpu_bstats,
365 &cl_q->bstats, true) < 0 ||
Paolo Abeni5dd431b2019-03-28 16:53:12 +0100366 qdisc_qstats_copy(d, cl_q) < 0)
Jarek Poplawski2cf6c362007-01-31 12:21:24 -0800367 return -1;
368
369 return 0;
370}
371
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372static void prio_walk(struct Qdisc *sch, struct qdisc_walker *arg)
373{
374 struct prio_sched_data *q = qdisc_priv(sch);
375 int prio;
376
377 if (arg->stop)
378 return;
379
380 for (prio = 0; prio < q->bands; prio++) {
381 if (arg->count < arg->skip) {
382 arg->count++;
383 continue;
384 }
Eric Dumazetcc7ec452011-01-19 19:26:56 +0000385 if (arg->fn(sch, prio + 1, arg) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386 arg->stop = 1;
387 break;
388 }
389 arg->count++;
390 }
391}
392
Alexander Aringcbaacc42017-12-20 12:35:16 -0500393static struct tcf_block *prio_tcf_block(struct Qdisc *sch, unsigned long cl,
394 struct netlink_ext_ack *extack)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395{
396 struct prio_sched_data *q = qdisc_priv(sch);
397
398 if (cl)
399 return NULL;
Jiri Pirko6529eab2017-05-17 11:07:55 +0200400 return q->block;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401}
402
Eric Dumazet20fea082007-11-14 01:44:41 -0800403static const struct Qdisc_class_ops prio_class_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 .graft = prio_graft,
405 .leaf = prio_leaf,
WANG Cong143976c2017-08-24 16:51:29 -0700406 .find = prio_find,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 .walk = prio_walk,
Jiri Pirko6529eab2017-05-17 11:07:55 +0200408 .tcf_block = prio_tcf_block,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409 .bind_tcf = prio_bind,
WANG Cong143976c2017-08-24 16:51:29 -0700410 .unbind_tcf = prio_unbind,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 .dump = prio_dump_class,
Jarek Poplawski2cf6c362007-01-31 12:21:24 -0800412 .dump_stats = prio_dump_class_stats,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413};
414
Eric Dumazet20fea082007-11-14 01:44:41 -0800415static struct Qdisc_ops prio_qdisc_ops __read_mostly = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416 .next = NULL,
417 .cl_ops = &prio_class_ops,
418 .id = "prio",
419 .priv_size = sizeof(struct prio_sched_data),
420 .enqueue = prio_enqueue,
421 .dequeue = prio_dequeue,
Patrick McHardy48a8f512008-10-31 00:44:18 -0700422 .peek = prio_peek,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 .init = prio_init,
424 .reset = prio_reset,
425 .destroy = prio_destroy,
426 .change = prio_tune,
427 .dump = prio_dump,
428 .owner = THIS_MODULE,
429};
430
431static int __init prio_module_init(void)
432{
David S. Miller1d8ae3f2008-07-15 02:52:19 -0700433 return register_qdisc(&prio_qdisc_ops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434}
435
YOSHIFUJI Hideaki10297b92007-02-09 23:25:16 +0900436static void __exit prio_module_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437{
438 unregister_qdisc(&prio_qdisc_ops);
439}
440
441module_init(prio_module_init)
442module_exit(prio_module_exit)
443
444MODULE_LICENSE("GPL");