]>
Commit | Line | Data |
---|---|---|
b2441318 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
1da177e4 LT |
2 | #ifndef __NET_SCHED_GENERIC_H |
3 | #define __NET_SCHED_GENERIC_H | |
4 | ||
1da177e4 LT |
5 | #include <linux/netdevice.h> |
6 | #include <linux/types.h> | |
7 | #include <linux/rcupdate.h> | |
1da177e4 LT |
8 | #include <linux/pkt_sched.h> |
9 | #include <linux/pkt_cls.h> | |
22e0f8b9 | 10 | #include <linux/percpu.h> |
5772e9a3 | 11 | #include <linux/dynamic_queue_limits.h> |
5bc17018 | 12 | #include <linux/list.h> |
7b936405 | 13 | #include <linux/refcount.h> |
7aa0045d | 14 | #include <linux/workqueue.h> |
1da177e4 | 15 | #include <net/gen_stats.h> |
be577ddc | 16 | #include <net/rtnetlink.h> |
1da177e4 LT |
17 | |
18 | struct Qdisc_ops; | |
19 | struct qdisc_walker; | |
20 | struct tcf_walker; | |
21 | struct module; | |
22 | ||
e56185c7 JH |
23 | typedef int tc_setup_cb_t(enum tc_setup_type type, |
24 | void *type_data, void *cb_priv); | |
25 | ||
fd2c3ef7 | 26 | struct qdisc_rate_table { |
1da177e4 LT |
27 | struct tc_ratespec rate; |
28 | u32 data[256]; | |
29 | struct qdisc_rate_table *next; | |
30 | int refcnt; | |
31 | }; | |
32 | ||
fd2c3ef7 | 33 | enum qdisc_state_t { |
37437bb2 | 34 | __QDISC_STATE_SCHED, |
a9312ae8 | 35 | __QDISC_STATE_DEACTIVATED, |
e2627c8c DM |
36 | }; |
37 | ||
175f9c1b | 38 | struct qdisc_size_table { |
a2da570d | 39 | struct rcu_head rcu; |
175f9c1b JK |
40 | struct list_head list; |
41 | struct tc_sizespec szopts; | |
42 | int refcnt; | |
43 | u16 data[]; | |
44 | }; | |
45 | ||
48da34b7 FW |
46 | /* similar to sk_buff_head, but skb->prev pointer is undefined. */ |
47 | struct qdisc_skb_head { | |
48 | struct sk_buff *head; | |
49 | struct sk_buff *tail; | |
50 | __u32 qlen; | |
51 | spinlock_t lock; | |
52 | }; | |
53 | ||
fd2c3ef7 | 54 | struct Qdisc { |
520ac30f ED |
55 | int (*enqueue)(struct sk_buff *skb, |
56 | struct Qdisc *sch, | |
57 | struct sk_buff **to_free); | |
58 | struct sk_buff * (*dequeue)(struct Qdisc *sch); | |
05bdd2f1 | 59 | unsigned int flags; |
b00355db | 60 | #define TCQ_F_BUILTIN 1 |
fd245a4a ED |
61 | #define TCQ_F_INGRESS 2 |
62 | #define TCQ_F_CAN_BYPASS 4 | |
63 | #define TCQ_F_MQROOT 8 | |
1abbe139 ED |
64 | #define TCQ_F_ONETXQUEUE 0x10 /* dequeue_skb() can assume all skbs are for |
65 | * q->dev_queue : It can test | |
66 | * netif_xmit_frozen_or_stopped() before | |
67 | * dequeueing next packet. | |
68 | * Its true for MQ/MQPRIO slaves, or non | |
69 | * multiqueue device. | |
70 | */ | |
b00355db | 71 | #define TCQ_F_WARN_NONWC (1 << 16) |
22e0f8b9 | 72 | #define TCQ_F_CPUSTATS 0x20 /* run using percpu statistics */ |
4eaf3b84 ED |
73 | #define TCQ_F_NOPARENT 0x40 /* root of its hierarchy : |
74 | * qdisc_tree_decrease_qlen() should stop. | |
75 | */ | |
49b49971 | 76 | #define TCQ_F_INVISIBLE 0x80 /* invisible by default in dump */ |
6b3ba914 | 77 | #define TCQ_F_NOLOCK 0x100 /* qdisc does not require locking */ |
7a4fa291 | 78 | #define TCQ_F_OFFLOADED 0x200 /* qdisc is offloaded to HW */ |
45203a3b | 79 | u32 limit; |
05bdd2f1 | 80 | const struct Qdisc_ops *ops; |
a2da570d | 81 | struct qdisc_size_table __rcu *stab; |
59cc1f61 | 82 | struct hlist_node hash; |
1da177e4 LT |
83 | u32 handle; |
84 | u32 parent; | |
72b25a91 | 85 | |
5e140dfc | 86 | struct netdev_queue *dev_queue; |
5e140dfc | 87 | |
1c0d32fd | 88 | struct net_rate_estimator __rcu *rate_est; |
0d32ef8c ED |
89 | struct gnet_stats_basic_cpu __percpu *cpu_bstats; |
90 | struct gnet_stats_queue __percpu *cpu_qstats; | |
e9be0e99 PA |
91 | int padded; |
92 | refcount_t refcnt; | |
0d32ef8c | 93 | |
5e140dfc ED |
94 | /* |
95 | * For performance sake on SMP, we put highly modified fields at the end | |
96 | */ | |
a53851e2 | 97 | struct sk_buff_head gso_skb ____cacheline_aligned_in_smp; |
48da34b7 | 98 | struct qdisc_skb_head q; |
0d32ef8c | 99 | struct gnet_stats_basic_packed bstats; |
f9eb8aea | 100 | seqcount_t running; |
0d32ef8c | 101 | struct gnet_stats_queue qstats; |
4d202a0d ED |
102 | unsigned long state; |
103 | struct Qdisc *next_sched; | |
70e57d5e | 104 | struct sk_buff_head skb_bad_txq; |
45203a3b ED |
105 | |
106 | spinlock_t busylock ____cacheline_aligned_in_smp; | |
96009c7d | 107 | spinlock_t seqlock; |
1da177e4 LT |
108 | }; |
109 | ||
551143d8 ED |
110 | static inline void qdisc_refcount_inc(struct Qdisc *qdisc) |
111 | { | |
112 | if (qdisc->flags & TCQ_F_BUILTIN) | |
113 | return; | |
114 | refcount_inc(&qdisc->refcnt); | |
115 | } | |
116 | ||
96009c7d | 117 | static inline bool qdisc_is_running(struct Qdisc *qdisc) |
bc135b23 | 118 | { |
32f7b44d | 119 | if (qdisc->flags & TCQ_F_NOLOCK) |
96009c7d | 120 | return spin_is_locked(&qdisc->seqlock); |
f9eb8aea | 121 | return (raw_read_seqcount(&qdisc->running) & 1) ? true : false; |
bc135b23 ED |
122 | } |
123 | ||
124 | static inline bool qdisc_run_begin(struct Qdisc *qdisc) | |
125 | { | |
32f7b44d | 126 | if (qdisc->flags & TCQ_F_NOLOCK) { |
96009c7d | 127 | if (!spin_trylock(&qdisc->seqlock)) |
32f7b44d PA |
128 | return false; |
129 | } else if (qdisc_is_running(qdisc)) { | |
fd245a4a | 130 | return false; |
32f7b44d | 131 | } |
52fbb290 ED |
132 | /* Variant of write_seqcount_begin() telling lockdep a trylock |
133 | * was attempted. | |
134 | */ | |
135 | raw_write_seqcount_begin(&qdisc->running); | |
136 | seqcount_acquire(&qdisc->running.dep_map, 0, 1, _RET_IP_); | |
fd245a4a | 137 | return true; |
bc135b23 ED |
138 | } |
139 | ||
140 | static inline void qdisc_run_end(struct Qdisc *qdisc) | |
141 | { | |
f9eb8aea | 142 | write_seqcount_end(&qdisc->running); |
32f7b44d | 143 | if (qdisc->flags & TCQ_F_NOLOCK) |
96009c7d | 144 | spin_unlock(&qdisc->seqlock); |
fd245a4a ED |
145 | } |
146 | ||
5772e9a3 JDB |
147 | static inline bool qdisc_may_bulk(const struct Qdisc *qdisc) |
148 | { | |
149 | return qdisc->flags & TCQ_F_ONETXQUEUE; | |
150 | } | |
151 | ||
152 | static inline int qdisc_avail_bulklimit(const struct netdev_queue *txq) | |
153 | { | |
154 | #ifdef CONFIG_BQL | |
155 | /* Non-BQL migrated drivers will return 0, too. */ | |
156 | return dql_avail(&txq->dql); | |
157 | #else | |
158 | return 0; | |
159 | #endif | |
160 | } | |
161 | ||
fd2c3ef7 | 162 | struct Qdisc_class_ops { |
1da177e4 | 163 | /* Child qdisc manipulation */ |
926e61b7 | 164 | struct netdev_queue * (*select_queue)(struct Qdisc *, struct tcmsg *); |
1da177e4 | 165 | int (*graft)(struct Qdisc *, unsigned long cl, |
653d6fd6 AA |
166 | struct Qdisc *, struct Qdisc **, |
167 | struct netlink_ext_ack *extack); | |
1da177e4 | 168 | struct Qdisc * (*leaf)(struct Qdisc *, unsigned long cl); |
43effa1e | 169 | void (*qlen_notify)(struct Qdisc *, unsigned long); |
1da177e4 LT |
170 | |
171 | /* Class manipulation routines */ | |
143976ce | 172 | unsigned long (*find)(struct Qdisc *, u32 classid); |
1da177e4 | 173 | int (*change)(struct Qdisc *, u32, u32, |
793d81d6 AA |
174 | struct nlattr **, unsigned long *, |
175 | struct netlink_ext_ack *); | |
1da177e4 LT |
176 | int (*delete)(struct Qdisc *, unsigned long); |
177 | void (*walk)(struct Qdisc *, struct qdisc_walker * arg); | |
178 | ||
179 | /* Filter manipulation */ | |
0ac4bd68 | 180 | struct tcf_block * (*tcf_block)(struct Qdisc *sch, |
cbaacc4e AA |
181 | unsigned long arg, |
182 | struct netlink_ext_ack *extack); | |
1da177e4 LT |
183 | unsigned long (*bind_tcf)(struct Qdisc *, unsigned long, |
184 | u32 classid); | |
185 | void (*unbind_tcf)(struct Qdisc *, unsigned long); | |
186 | ||
187 | /* rtnetlink specific */ | |
188 | int (*dump)(struct Qdisc *, unsigned long, | |
189 | struct sk_buff *skb, struct tcmsg*); | |
190 | int (*dump_stats)(struct Qdisc *, unsigned long, | |
191 | struct gnet_dump *); | |
192 | }; | |
193 | ||
fd2c3ef7 | 194 | struct Qdisc_ops { |
1da177e4 | 195 | struct Qdisc_ops *next; |
20fea08b | 196 | const struct Qdisc_class_ops *cl_ops; |
1da177e4 LT |
197 | char id[IFNAMSIZ]; |
198 | int priv_size; | |
d59f5ffa | 199 | unsigned int static_flags; |
1da177e4 | 200 | |
520ac30f ED |
201 | int (*enqueue)(struct sk_buff *skb, |
202 | struct Qdisc *sch, | |
203 | struct sk_buff **to_free); | |
1da177e4 | 204 | struct sk_buff * (*dequeue)(struct Qdisc *); |
90d841fd | 205 | struct sk_buff * (*peek)(struct Qdisc *); |
1da177e4 | 206 | |
e63d7dfd AA |
207 | int (*init)(struct Qdisc *sch, struct nlattr *arg, |
208 | struct netlink_ext_ack *extack); | |
1da177e4 LT |
209 | void (*reset)(struct Qdisc *); |
210 | void (*destroy)(struct Qdisc *); | |
0ac4bd68 | 211 | int (*change)(struct Qdisc *sch, |
2030721c AA |
212 | struct nlattr *arg, |
213 | struct netlink_ext_ack *extack); | |
0ac4bd68 | 214 | void (*attach)(struct Qdisc *sch); |
48bfd55e | 215 | int (*change_tx_queue_len)(struct Qdisc *, unsigned int); |
1da177e4 LT |
216 | |
217 | int (*dump)(struct Qdisc *, struct sk_buff *); | |
218 | int (*dump_stats)(struct Qdisc *, struct gnet_dump *); | |
219 | ||
d47a6b0e JP |
220 | void (*ingress_block_set)(struct Qdisc *sch, |
221 | u32 block_index); | |
222 | void (*egress_block_set)(struct Qdisc *sch, | |
223 | u32 block_index); | |
224 | u32 (*ingress_block_get)(struct Qdisc *sch); | |
225 | u32 (*egress_block_get)(struct Qdisc *sch); | |
226 | ||
1da177e4 LT |
227 | struct module *owner; |
228 | }; | |
229 | ||
230 | ||
fd2c3ef7 | 231 | struct tcf_result { |
db50514f JP |
232 | union { |
233 | struct { | |
234 | unsigned long class; | |
235 | u32 classid; | |
236 | }; | |
237 | const struct tcf_proto *goto_tp; | |
cd11b164 PA |
238 | |
239 | /* used by the TC_ACT_REINSERT action */ | |
240 | struct { | |
241 | bool ingress; | |
242 | struct gnet_stats_queue *qstats; | |
243 | }; | |
db50514f | 244 | }; |
1da177e4 LT |
245 | }; |
246 | ||
9f407f17 JP |
247 | struct tcf_chain; |
248 | ||
fd2c3ef7 | 249 | struct tcf_proto_ops { |
36272874 | 250 | struct list_head head; |
1da177e4 LT |
251 | char kind[IFNAMSIZ]; |
252 | ||
dc7f9f6e ED |
253 | int (*classify)(struct sk_buff *, |
254 | const struct tcf_proto *, | |
255 | struct tcf_result *); | |
1da177e4 | 256 | int (*init)(struct tcf_proto*); |
715df5ec JK |
257 | void (*destroy)(struct tcf_proto *tp, |
258 | struct netlink_ext_ack *extack); | |
1da177e4 | 259 | |
8113c095 | 260 | void* (*get)(struct tcf_proto*, u32 handle); |
c1b52739 | 261 | int (*change)(struct net *net, struct sk_buff *, |
af4c6641 | 262 | struct tcf_proto*, unsigned long, |
add93b61 | 263 | u32 handle, struct nlattr **, |
7306db38 AA |
264 | void **, bool, |
265 | struct netlink_ext_ack *); | |
8865fdd4 | 266 | int (*delete)(struct tcf_proto *tp, void *arg, |
571acf21 AA |
267 | bool *last, |
268 | struct netlink_ext_ack *); | |
1da177e4 | 269 | void (*walk)(struct tcf_proto*, struct tcf_walker *arg); |
e56185c7 JH |
270 | int (*reoffload)(struct tcf_proto *tp, bool add, |
271 | tc_setup_cb_t *cb, void *cb_priv, | |
272 | struct netlink_ext_ack *extack); | |
07d79fc7 | 273 | void (*bind_class)(void *, u32, unsigned long); |
9f407f17 JP |
274 | void * (*tmplt_create)(struct net *net, |
275 | struct tcf_chain *chain, | |
276 | struct nlattr **tca, | |
277 | struct netlink_ext_ack *extack); | |
278 | void (*tmplt_destroy)(void *tmplt_priv); | |
1da177e4 LT |
279 | |
280 | /* rtnetlink specific */ | |
8113c095 | 281 | int (*dump)(struct net*, struct tcf_proto*, void *, |
1da177e4 | 282 | struct sk_buff *skb, struct tcmsg*); |
9f407f17 JP |
283 | int (*tmplt_dump)(struct sk_buff *skb, |
284 | struct net *net, | |
285 | void *tmplt_priv); | |
1da177e4 LT |
286 | |
287 | struct module *owner; | |
288 | }; | |
289 | ||
fd2c3ef7 | 290 | struct tcf_proto { |
1da177e4 | 291 | /* Fast access part */ |
25d8c0d5 JF |
292 | struct tcf_proto __rcu *next; |
293 | void __rcu *root; | |
7fd4b288 PA |
294 | |
295 | /* called under RCU BH lock*/ | |
dc7f9f6e ED |
296 | int (*classify)(struct sk_buff *, |
297 | const struct tcf_proto *, | |
298 | struct tcf_result *); | |
66c6f529 | 299 | __be16 protocol; |
1da177e4 LT |
300 | |
301 | /* All the rest */ | |
302 | u32 prio; | |
1da177e4 | 303 | void *data; |
dc7f9f6e | 304 | const struct tcf_proto_ops *ops; |
5bc17018 | 305 | struct tcf_chain *chain; |
25d8c0d5 | 306 | struct rcu_head rcu; |
1da177e4 LT |
307 | }; |
308 | ||
175f9c1b JK |
309 | struct qdisc_skb_cb { |
310 | unsigned int pkt_len; | |
df4ab5b3 | 311 | u16 slave_dev_queue_mapping; |
045efa82 | 312 | u16 tc_classid; |
25711786 ED |
313 | #define QDISC_CB_PRIV_LEN 20 |
314 | unsigned char data[QDISC_CB_PRIV_LEN]; | |
175f9c1b JK |
315 | }; |
316 | ||
c7eb7d72 JP |
317 | typedef void tcf_chain_head_change_t(struct tcf_proto *tp_head, void *priv); |
318 | ||
2190d1d0 JP |
319 | struct tcf_chain { |
320 | struct tcf_proto __rcu *filter_chain; | |
5bc17018 JP |
321 | struct list_head list; |
322 | struct tcf_block *block; | |
323 | u32 index; /* chain index */ | |
324 | unsigned int refcnt; | |
1f3ed383 | 325 | unsigned int action_refcnt; |
32a4f5ec | 326 | bool explicitly_created; |
9f407f17 JP |
327 | const struct tcf_proto_ops *tmplt_ops; |
328 | void *tmplt_priv; | |
6529eaba JP |
329 | }; |
330 | ||
2190d1d0 | 331 | struct tcf_block { |
5bc17018 | 332 | struct list_head chain_list; |
48617387 JP |
333 | u32 index; /* block index for shared blocks */ |
334 | unsigned int refcnt; | |
855319be | 335 | struct net *net; |
69d78ef2 | 336 | struct Qdisc *q; |
acb67442 | 337 | struct list_head cb_list; |
f36fe1c4 JP |
338 | struct list_head owner_list; |
339 | bool keep_dst; | |
caa72601 JP |
340 | unsigned int offloadcnt; /* Number of oddloaded filters */ |
341 | unsigned int nooffloaddevcnt; /* Number of devs unable to do offload */ | |
f71e0ca4 JP |
342 | struct { |
343 | struct tcf_chain *chain; | |
344 | struct list_head filter_chain_list; | |
345 | } chain0; | |
2190d1d0 JP |
346 | }; |
347 | ||
caa72601 JP |
348 | static inline void tcf_block_offload_inc(struct tcf_block *block, u32 *flags) |
349 | { | |
350 | if (*flags & TCA_CLS_FLAGS_IN_HW) | |
351 | return; | |
352 | *flags |= TCA_CLS_FLAGS_IN_HW; | |
353 | block->offloadcnt++; | |
354 | } | |
355 | ||
356 | static inline void tcf_block_offload_dec(struct tcf_block *block, u32 *flags) | |
357 | { | |
358 | if (!(*flags & TCA_CLS_FLAGS_IN_HW)) | |
359 | return; | |
360 | *flags &= ~TCA_CLS_FLAGS_IN_HW; | |
361 | block->offloadcnt--; | |
362 | } | |
363 | ||
31533cba JH |
364 | static inline void |
365 | tc_cls_offload_cnt_update(struct tcf_block *block, unsigned int *cnt, | |
366 | u32 *flags, bool add) | |
367 | { | |
368 | if (add) { | |
369 | if (!*cnt) | |
370 | tcf_block_offload_inc(block, flags); | |
371 | (*cnt)++; | |
372 | } else { | |
373 | (*cnt)--; | |
374 | if (!*cnt) | |
375 | tcf_block_offload_dec(block, flags); | |
376 | } | |
377 | } | |
378 | ||
16bda13d DM |
379 | static inline void qdisc_cb_private_validate(const struct sk_buff *skb, int sz) |
380 | { | |
381 | struct qdisc_skb_cb *qcb; | |
5ee31c68 ED |
382 | |
383 | BUILD_BUG_ON(sizeof(skb->cb) < offsetof(struct qdisc_skb_cb, data) + sz); | |
16bda13d DM |
384 | BUILD_BUG_ON(sizeof(qcb->data) < sz); |
385 | } | |
386 | ||
7e66016f JF |
387 | static inline int qdisc_qlen_cpu(const struct Qdisc *q) |
388 | { | |
389 | return this_cpu_ptr(q->cpu_qstats)->qlen; | |
390 | } | |
391 | ||
05bdd2f1 | 392 | static inline int qdisc_qlen(const struct Qdisc *q) |
bbd8a0d3 KK |
393 | { |
394 | return q->q.qlen; | |
395 | } | |
396 | ||
7e66016f JF |
397 | static inline int qdisc_qlen_sum(const struct Qdisc *q) |
398 | { | |
6172abc1 | 399 | __u32 qlen = q->qstats.qlen; |
7e66016f JF |
400 | int i; |
401 | ||
402 | if (q->flags & TCQ_F_NOLOCK) { | |
403 | for_each_possible_cpu(i) | |
404 | qlen += per_cpu_ptr(q->cpu_qstats, i)->qlen; | |
405 | } else { | |
6172abc1 | 406 | qlen += q->q.qlen; |
7e66016f JF |
407 | } |
408 | ||
409 | return qlen; | |
410 | } | |
411 | ||
bfe0d029 | 412 | static inline struct qdisc_skb_cb *qdisc_skb_cb(const struct sk_buff *skb) |
175f9c1b JK |
413 | { |
414 | return (struct qdisc_skb_cb *)skb->cb; | |
415 | } | |
416 | ||
83874000 DM |
417 | static inline spinlock_t *qdisc_lock(struct Qdisc *qdisc) |
418 | { | |
419 | return &qdisc->q.lock; | |
420 | } | |
421 | ||
05bdd2f1 | 422 | static inline struct Qdisc *qdisc_root(const struct Qdisc *qdisc) |
7698b4fc | 423 | { |
46e5da40 JF |
424 | struct Qdisc *q = rcu_dereference_rtnl(qdisc->dev_queue->qdisc); |
425 | ||
426 | return q; | |
7698b4fc DM |
427 | } |
428 | ||
05bdd2f1 | 429 | static inline struct Qdisc *qdisc_root_sleeping(const struct Qdisc *qdisc) |
2540e051 JP |
430 | { |
431 | return qdisc->dev_queue->qdisc_sleeping; | |
432 | } | |
433 | ||
7e43f112 DM |
434 | /* The qdisc root lock is a mechanism by which to top level |
435 | * of a qdisc tree can be locked from any qdisc node in the | |
436 | * forest. This allows changing the configuration of some | |
437 | * aspect of the qdisc tree while blocking out asynchronous | |
438 | * qdisc access in the packet processing paths. | |
439 | * | |
440 | * It is only legal to do this when the root will not change | |
441 | * on us. Otherwise we'll potentially lock the wrong qdisc | |
442 | * root. This is enforced by holding the RTNL semaphore, which | |
443 | * all users of this lock accessor must do. | |
444 | */ | |
05bdd2f1 | 445 | static inline spinlock_t *qdisc_root_lock(const struct Qdisc *qdisc) |
7698b4fc DM |
446 | { |
447 | struct Qdisc *root = qdisc_root(qdisc); | |
448 | ||
7e43f112 | 449 | ASSERT_RTNL(); |
83874000 | 450 | return qdisc_lock(root); |
7698b4fc DM |
451 | } |
452 | ||
05bdd2f1 | 453 | static inline spinlock_t *qdisc_root_sleeping_lock(const struct Qdisc *qdisc) |
f6f9b93f JP |
454 | { |
455 | struct Qdisc *root = qdisc_root_sleeping(qdisc); | |
456 | ||
457 | ASSERT_RTNL(); | |
458 | return qdisc_lock(root); | |
459 | } | |
460 | ||
edb09eb1 ED |
461 | static inline seqcount_t *qdisc_root_sleeping_running(const struct Qdisc *qdisc) |
462 | { | |
463 | struct Qdisc *root = qdisc_root_sleeping(qdisc); | |
464 | ||
465 | ASSERT_RTNL(); | |
466 | return &root->running; | |
467 | } | |
468 | ||
05bdd2f1 | 469 | static inline struct net_device *qdisc_dev(const struct Qdisc *qdisc) |
5ce2d488 DM |
470 | { |
471 | return qdisc->dev_queue->dev; | |
472 | } | |
1da177e4 | 473 | |
05bdd2f1 | 474 | static inline void sch_tree_lock(const struct Qdisc *q) |
78a5b30b | 475 | { |
fe439dd0 | 476 | spin_lock_bh(qdisc_root_sleeping_lock(q)); |
78a5b30b DM |
477 | } |
478 | ||
05bdd2f1 | 479 | static inline void sch_tree_unlock(const struct Qdisc *q) |
78a5b30b | 480 | { |
fe439dd0 | 481 | spin_unlock_bh(qdisc_root_sleeping_lock(q)); |
78a5b30b DM |
482 | } |
483 | ||
e41a33e6 TG |
484 | extern struct Qdisc noop_qdisc; |
485 | extern struct Qdisc_ops noop_qdisc_ops; | |
6ec1c69a DM |
486 | extern struct Qdisc_ops pfifo_fast_ops; |
487 | extern struct Qdisc_ops mq_qdisc_ops; | |
d66d6c31 | 488 | extern struct Qdisc_ops noqueue_qdisc_ops; |
6da7c8fc | 489 | extern const struct Qdisc_ops *default_qdisc_ops; |
1f27cde3 ED |
490 | static inline const struct Qdisc_ops * |
491 | get_default_qdisc_ops(const struct net_device *dev, int ntx) | |
492 | { | |
493 | return ntx < dev->real_num_tx_queues ? | |
494 | default_qdisc_ops : &pfifo_fast_ops; | |
495 | } | |
e41a33e6 | 496 | |
fd2c3ef7 | 497 | struct Qdisc_class_common { |
6fe1c7a5 PM |
498 | u32 classid; |
499 | struct hlist_node hnode; | |
500 | }; | |
501 | ||
fd2c3ef7 | 502 | struct Qdisc_class_hash { |
6fe1c7a5 PM |
503 | struct hlist_head *hash; |
504 | unsigned int hashsize; | |
505 | unsigned int hashmask; | |
506 | unsigned int hashelems; | |
507 | }; | |
508 | ||
509 | static inline unsigned int qdisc_class_hash(u32 id, u32 mask) | |
510 | { | |
511 | id ^= id >> 8; | |
512 | id ^= id >> 4; | |
513 | return id & mask; | |
514 | } | |
515 | ||
516 | static inline struct Qdisc_class_common * | |
05bdd2f1 | 517 | qdisc_class_find(const struct Qdisc_class_hash *hash, u32 id) |
6fe1c7a5 PM |
518 | { |
519 | struct Qdisc_class_common *cl; | |
6fe1c7a5 PM |
520 | unsigned int h; |
521 | ||
7d3f0cd4 GF |
522 | if (!id) |
523 | return NULL; | |
524 | ||
6fe1c7a5 | 525 | h = qdisc_class_hash(id, hash->hashmask); |
b67bfe0d | 526 | hlist_for_each_entry(cl, &hash->hash[h], hnode) { |
6fe1c7a5 PM |
527 | if (cl->classid == id) |
528 | return cl; | |
529 | } | |
530 | return NULL; | |
531 | } | |
532 | ||
384c181e AN |
533 | static inline int tc_classid_to_hwtc(struct net_device *dev, u32 classid) |
534 | { | |
535 | u32 hwtc = TC_H_MIN(classid) - TC_H_MIN_PRIORITY; | |
536 | ||
537 | return (hwtc < netdev_get_num_tc(dev)) ? hwtc : -EINVAL; | |
538 | } | |
539 | ||
5c15257f JP |
540 | int qdisc_class_hash_init(struct Qdisc_class_hash *); |
541 | void qdisc_class_hash_insert(struct Qdisc_class_hash *, | |
542 | struct Qdisc_class_common *); | |
543 | void qdisc_class_hash_remove(struct Qdisc_class_hash *, | |
544 | struct Qdisc_class_common *); | |
545 | void qdisc_class_hash_grow(struct Qdisc *, struct Qdisc_class_hash *); | |
546 | void qdisc_class_hash_destroy(struct Qdisc_class_hash *); | |
547 | ||
48bfd55e | 548 | int dev_qdisc_change_tx_queue_len(struct net_device *dev); |
5c15257f JP |
549 | void dev_init_scheduler(struct net_device *dev); |
550 | void dev_shutdown(struct net_device *dev); | |
551 | void dev_activate(struct net_device *dev); | |
552 | void dev_deactivate(struct net_device *dev); | |
553 | void dev_deactivate_many(struct list_head *head); | |
554 | struct Qdisc *dev_graft_qdisc(struct netdev_queue *dev_queue, | |
555 | struct Qdisc *qdisc); | |
556 | void qdisc_reset(struct Qdisc *qdisc); | |
557 | void qdisc_destroy(struct Qdisc *qdisc); | |
2ccccf5f WC |
558 | void qdisc_tree_reduce_backlog(struct Qdisc *qdisc, unsigned int n, |
559 | unsigned int len); | |
5c15257f | 560 | struct Qdisc *qdisc_alloc(struct netdev_queue *dev_queue, |
d0bd684d AA |
561 | const struct Qdisc_ops *ops, |
562 | struct netlink_ext_ack *extack); | |
81d947e2 | 563 | void qdisc_free(struct Qdisc *qdisc); |
5c15257f | 564 | struct Qdisc *qdisc_create_dflt(struct netdev_queue *dev_queue, |
a38a9882 AA |
565 | const struct Qdisc_ops *ops, u32 parentid, |
566 | struct netlink_ext_ack *extack); | |
5c15257f JP |
567 | void __qdisc_calculate_pkt_len(struct sk_buff *skb, |
568 | const struct qdisc_size_table *stab); | |
27b29f63 | 569 | int skb_do_redirect(struct sk_buff *); |
1da177e4 | 570 | |
a5135bcf WB |
571 | static inline void skb_reset_tc(struct sk_buff *skb) |
572 | { | |
573 | #ifdef CONFIG_NET_CLS_ACT | |
bc31c905 | 574 | skb->tc_redirected = 0; |
a5135bcf WB |
575 | #endif |
576 | } | |
577 | ||
cd11b164 PA |
578 | static inline bool skb_is_tc_redirected(const struct sk_buff *skb) |
579 | { | |
580 | #ifdef CONFIG_NET_CLS_ACT | |
581 | return skb->tc_redirected; | |
582 | #else | |
583 | return false; | |
584 | #endif | |
585 | } | |
586 | ||
fdc5432a DB |
587 | static inline bool skb_at_tc_ingress(const struct sk_buff *skb) |
588 | { | |
589 | #ifdef CONFIG_NET_CLS_ACT | |
8dc07fdb | 590 | return skb->tc_at_ingress; |
fdc5432a DB |
591 | #else |
592 | return false; | |
593 | #endif | |
594 | } | |
595 | ||
e7246e12 WB |
596 | static inline bool skb_skip_tc_classify(struct sk_buff *skb) |
597 | { | |
598 | #ifdef CONFIG_NET_CLS_ACT | |
599 | if (skb->tc_skip_classify) { | |
600 | skb->tc_skip_classify = 0; | |
601 | return true; | |
602 | } | |
603 | #endif | |
604 | return false; | |
605 | } | |
606 | ||
3a053b1a | 607 | /* Reset all TX qdiscs greater than index of a device. */ |
f0796d5c | 608 | static inline void qdisc_reset_all_tx_gt(struct net_device *dev, unsigned int i) |
5aa70995 | 609 | { |
4ef6acff JF |
610 | struct Qdisc *qdisc; |
611 | ||
f0796d5c | 612 | for (; i < dev->num_tx_queues; i++) { |
46e5da40 | 613 | qdisc = rtnl_dereference(netdev_get_tx_queue(dev, i)->qdisc); |
4ef6acff JF |
614 | if (qdisc) { |
615 | spin_lock_bh(qdisc_lock(qdisc)); | |
616 | qdisc_reset(qdisc); | |
617 | spin_unlock_bh(qdisc_lock(qdisc)); | |
618 | } | |
619 | } | |
5aa70995 DM |
620 | } |
621 | ||
5aa70995 DM |
622 | static inline void qdisc_reset_all_tx(struct net_device *dev) |
623 | { | |
f0796d5c | 624 | qdisc_reset_all_tx_gt(dev, 0); |
5aa70995 DM |
625 | } |
626 | ||
3e745dd6 DM |
627 | /* Are all TX queues of the device empty? */ |
628 | static inline bool qdisc_all_tx_empty(const struct net_device *dev) | |
629 | { | |
e8a0464c | 630 | unsigned int i; |
46e5da40 JF |
631 | |
632 | rcu_read_lock(); | |
e8a0464c DM |
633 | for (i = 0; i < dev->num_tx_queues; i++) { |
634 | struct netdev_queue *txq = netdev_get_tx_queue(dev, i); | |
46e5da40 | 635 | const struct Qdisc *q = rcu_dereference(txq->qdisc); |
3e745dd6 | 636 | |
46e5da40 JF |
637 | if (q->q.qlen) { |
638 | rcu_read_unlock(); | |
e8a0464c | 639 | return false; |
46e5da40 | 640 | } |
e8a0464c | 641 | } |
46e5da40 | 642 | rcu_read_unlock(); |
e8a0464c | 643 | return true; |
3e745dd6 DM |
644 | } |
645 | ||
6fa9864b | 646 | /* Are any of the TX qdiscs changing? */ |
05bdd2f1 | 647 | static inline bool qdisc_tx_changing(const struct net_device *dev) |
6fa9864b | 648 | { |
e8a0464c | 649 | unsigned int i; |
46e5da40 | 650 | |
e8a0464c DM |
651 | for (i = 0; i < dev->num_tx_queues; i++) { |
652 | struct netdev_queue *txq = netdev_get_tx_queue(dev, i); | |
46e5da40 | 653 | if (rcu_access_pointer(txq->qdisc) != txq->qdisc_sleeping) |
e8a0464c DM |
654 | return true; |
655 | } | |
656 | return false; | |
6fa9864b DM |
657 | } |
658 | ||
e8a0464c | 659 | /* Is the device using the noop qdisc on all queues? */ |
05297949 DM |
660 | static inline bool qdisc_tx_is_noop(const struct net_device *dev) |
661 | { | |
e8a0464c | 662 | unsigned int i; |
46e5da40 | 663 | |
e8a0464c DM |
664 | for (i = 0; i < dev->num_tx_queues; i++) { |
665 | struct netdev_queue *txq = netdev_get_tx_queue(dev, i); | |
46e5da40 | 666 | if (rcu_access_pointer(txq->qdisc) != &noop_qdisc) |
e8a0464c DM |
667 | return false; |
668 | } | |
669 | return true; | |
05297949 DM |
670 | } |
671 | ||
bfe0d029 | 672 | static inline unsigned int qdisc_pkt_len(const struct sk_buff *skb) |
0abf77e5 | 673 | { |
175f9c1b | 674 | return qdisc_skb_cb(skb)->pkt_len; |
0abf77e5 JK |
675 | } |
676 | ||
c27f339a | 677 | /* additional qdisc xmit flags (NET_XMIT_MASK in linux/netdevice.h) */ |
378a2f09 JP |
678 | enum net_xmit_qdisc_t { |
679 | __NET_XMIT_STOLEN = 0x00010000, | |
c27f339a | 680 | __NET_XMIT_BYPASS = 0x00020000, |
378a2f09 JP |
681 | }; |
682 | ||
c27f339a | 683 | #ifdef CONFIG_NET_CLS_ACT |
378a2f09 | 684 | #define net_xmit_drop_count(e) ((e) & __NET_XMIT_STOLEN ? 0 : 1) |
378a2f09 JP |
685 | #else |
686 | #define net_xmit_drop_count(e) (1) | |
687 | #endif | |
688 | ||
a2da570d ED |
689 | static inline void qdisc_calculate_pkt_len(struct sk_buff *skb, |
690 | const struct Qdisc *sch) | |
5f86173b | 691 | { |
3a682fbd | 692 | #ifdef CONFIG_NET_SCHED |
a2da570d ED |
693 | struct qdisc_size_table *stab = rcu_dereference_bh(sch->stab); |
694 | ||
695 | if (stab) | |
696 | __qdisc_calculate_pkt_len(skb, stab); | |
3a682fbd | 697 | #endif |
a2da570d ED |
698 | } |
699 | ||
520ac30f ED |
700 | static inline int qdisc_enqueue(struct sk_buff *skb, struct Qdisc *sch, |
701 | struct sk_buff **to_free) | |
a2da570d ED |
702 | { |
703 | qdisc_calculate_pkt_len(skb, sch); | |
520ac30f | 704 | return sch->enqueue(skb, sch, to_free); |
5f86173b JK |
705 | } |
706 | ||
22e0f8b9 JF |
707 | static inline bool qdisc_is_percpu_stats(const struct Qdisc *q) |
708 | { | |
709 | return q->flags & TCQ_F_CPUSTATS; | |
710 | } | |
bfe0d029 | 711 | |
38040702 AV |
712 | static inline void _bstats_update(struct gnet_stats_basic_packed *bstats, |
713 | __u64 bytes, __u32 packets) | |
714 | { | |
715 | bstats->bytes += bytes; | |
716 | bstats->packets += packets; | |
717 | } | |
718 | ||
bfe0d029 ED |
719 | static inline void bstats_update(struct gnet_stats_basic_packed *bstats, |
720 | const struct sk_buff *skb) | |
721 | { | |
38040702 AV |
722 | _bstats_update(bstats, |
723 | qdisc_pkt_len(skb), | |
724 | skb_is_gso(skb) ? skb_shinfo(skb)->gso_segs : 1); | |
725 | } | |
726 | ||
727 | static inline void _bstats_cpu_update(struct gnet_stats_basic_cpu *bstats, | |
728 | __u64 bytes, __u32 packets) | |
729 | { | |
730 | u64_stats_update_begin(&bstats->syncp); | |
731 | _bstats_update(&bstats->bstats, bytes, packets); | |
732 | u64_stats_update_end(&bstats->syncp); | |
bfe0d029 ED |
733 | } |
734 | ||
24ea591d ED |
735 | static inline void bstats_cpu_update(struct gnet_stats_basic_cpu *bstats, |
736 | const struct sk_buff *skb) | |
22e0f8b9 | 737 | { |
22e0f8b9 JF |
738 | u64_stats_update_begin(&bstats->syncp); |
739 | bstats_update(&bstats->bstats, skb); | |
740 | u64_stats_update_end(&bstats->syncp); | |
741 | } | |
742 | ||
24ea591d ED |
743 | static inline void qdisc_bstats_cpu_update(struct Qdisc *sch, |
744 | const struct sk_buff *skb) | |
745 | { | |
746 | bstats_cpu_update(this_cpu_ptr(sch->cpu_bstats), skb); | |
747 | } | |
748 | ||
bfe0d029 ED |
749 | static inline void qdisc_bstats_update(struct Qdisc *sch, |
750 | const struct sk_buff *skb) | |
bbd8a0d3 | 751 | { |
bfe0d029 | 752 | bstats_update(&sch->bstats, skb); |
bbd8a0d3 KK |
753 | } |
754 | ||
25331d6c JF |
755 | static inline void qdisc_qstats_backlog_dec(struct Qdisc *sch, |
756 | const struct sk_buff *skb) | |
757 | { | |
758 | sch->qstats.backlog -= qdisc_pkt_len(skb); | |
759 | } | |
760 | ||
40bd0362 JF |
761 | static inline void qdisc_qstats_cpu_backlog_dec(struct Qdisc *sch, |
762 | const struct sk_buff *skb) | |
763 | { | |
764 | this_cpu_sub(sch->cpu_qstats->backlog, qdisc_pkt_len(skb)); | |
765 | } | |
766 | ||
25331d6c JF |
767 | static inline void qdisc_qstats_backlog_inc(struct Qdisc *sch, |
768 | const struct sk_buff *skb) | |
769 | { | |
770 | sch->qstats.backlog += qdisc_pkt_len(skb); | |
771 | } | |
772 | ||
40bd0362 JF |
773 | static inline void qdisc_qstats_cpu_backlog_inc(struct Qdisc *sch, |
774 | const struct sk_buff *skb) | |
775 | { | |
776 | this_cpu_add(sch->cpu_qstats->backlog, qdisc_pkt_len(skb)); | |
777 | } | |
778 | ||
779 | static inline void qdisc_qstats_cpu_qlen_inc(struct Qdisc *sch) | |
780 | { | |
781 | this_cpu_inc(sch->cpu_qstats->qlen); | |
782 | } | |
783 | ||
784 | static inline void qdisc_qstats_cpu_qlen_dec(struct Qdisc *sch) | |
785 | { | |
786 | this_cpu_dec(sch->cpu_qstats->qlen); | |
787 | } | |
788 | ||
789 | static inline void qdisc_qstats_cpu_requeues_inc(struct Qdisc *sch) | |
790 | { | |
791 | this_cpu_inc(sch->cpu_qstats->requeues); | |
792 | } | |
793 | ||
25331d6c JF |
794 | static inline void __qdisc_qstats_drop(struct Qdisc *sch, int count) |
795 | { | |
796 | sch->qstats.drops += count; | |
797 | } | |
798 | ||
24ea591d | 799 | static inline void qstats_drop_inc(struct gnet_stats_queue *qstats) |
25331d6c | 800 | { |
24ea591d | 801 | qstats->drops++; |
25331d6c JF |
802 | } |
803 | ||
24ea591d | 804 | static inline void qstats_overlimit_inc(struct gnet_stats_queue *qstats) |
b0ab6f92 | 805 | { |
24ea591d ED |
806 | qstats->overlimits++; |
807 | } | |
b0ab6f92 | 808 | |
24ea591d ED |
809 | static inline void qdisc_qstats_drop(struct Qdisc *sch) |
810 | { | |
811 | qstats_drop_inc(&sch->qstats); | |
812 | } | |
813 | ||
814 | static inline void qdisc_qstats_cpu_drop(struct Qdisc *sch) | |
815 | { | |
eb60a8dd | 816 | this_cpu_inc(sch->cpu_qstats->drops); |
b0ab6f92 JF |
817 | } |
818 | ||
25331d6c JF |
819 | static inline void qdisc_qstats_overlimit(struct Qdisc *sch) |
820 | { | |
821 | sch->qstats.overlimits++; | |
822 | } | |
823 | ||
48da34b7 FW |
824 | static inline void qdisc_skb_head_init(struct qdisc_skb_head *qh) |
825 | { | |
826 | qh->head = NULL; | |
827 | qh->tail = NULL; | |
828 | qh->qlen = 0; | |
829 | } | |
830 | ||
9972b25d | 831 | static inline int __qdisc_enqueue_tail(struct sk_buff *skb, struct Qdisc *sch, |
48da34b7 | 832 | struct qdisc_skb_head *qh) |
9972b25d | 833 | { |
48da34b7 FW |
834 | struct sk_buff *last = qh->tail; |
835 | ||
836 | if (last) { | |
837 | skb->next = NULL; | |
838 | last->next = skb; | |
839 | qh->tail = skb; | |
840 | } else { | |
841 | qh->tail = skb; | |
842 | qh->head = skb; | |
843 | } | |
844 | qh->qlen++; | |
25331d6c | 845 | qdisc_qstats_backlog_inc(sch, skb); |
9972b25d TG |
846 | |
847 | return NET_XMIT_SUCCESS; | |
848 | } | |
849 | ||
850 | static inline int qdisc_enqueue_tail(struct sk_buff *skb, struct Qdisc *sch) | |
851 | { | |
852 | return __qdisc_enqueue_tail(skb, sch, &sch->q); | |
853 | } | |
854 | ||
48da34b7 | 855 | static inline struct sk_buff *__qdisc_dequeue_head(struct qdisc_skb_head *qh) |
9972b25d | 856 | { |
48da34b7 FW |
857 | struct sk_buff *skb = qh->head; |
858 | ||
859 | if (likely(skb != NULL)) { | |
860 | qh->head = skb->next; | |
861 | qh->qlen--; | |
862 | if (qh->head == NULL) | |
863 | qh->tail = NULL; | |
864 | skb->next = NULL; | |
865 | } | |
9972b25d | 866 | |
ec323368 FW |
867 | return skb; |
868 | } | |
869 | ||
870 | static inline struct sk_buff *qdisc_dequeue_head(struct Qdisc *sch) | |
871 | { | |
872 | struct sk_buff *skb = __qdisc_dequeue_head(&sch->q); | |
873 | ||
9190b3b3 | 874 | if (likely(skb != NULL)) { |
25331d6c | 875 | qdisc_qstats_backlog_dec(sch, skb); |
9190b3b3 ED |
876 | qdisc_bstats_update(sch, skb); |
877 | } | |
9972b25d TG |
878 | |
879 | return skb; | |
880 | } | |
881 | ||
520ac30f ED |
882 | /* Instead of calling kfree_skb() while root qdisc lock is held, |
883 | * queue the skb for future freeing at end of __dev_xmit_skb() | |
884 | */ | |
885 | static inline void __qdisc_drop(struct sk_buff *skb, struct sk_buff **to_free) | |
886 | { | |
887 | skb->next = *to_free; | |
888 | *to_free = skb; | |
889 | } | |
890 | ||
35d889d1 AK |
891 | static inline void __qdisc_drop_all(struct sk_buff *skb, |
892 | struct sk_buff **to_free) | |
893 | { | |
894 | if (skb->prev) | |
895 | skb->prev->next = *to_free; | |
896 | else | |
897 | skb->next = *to_free; | |
898 | *to_free = skb; | |
899 | } | |
900 | ||
57dbb2d8 | 901 | static inline unsigned int __qdisc_queue_drop_head(struct Qdisc *sch, |
48da34b7 | 902 | struct qdisc_skb_head *qh, |
520ac30f | 903 | struct sk_buff **to_free) |
57dbb2d8 | 904 | { |
48da34b7 | 905 | struct sk_buff *skb = __qdisc_dequeue_head(qh); |
57dbb2d8 HPP |
906 | |
907 | if (likely(skb != NULL)) { | |
908 | unsigned int len = qdisc_pkt_len(skb); | |
520ac30f | 909 | |
25331d6c | 910 | qdisc_qstats_backlog_dec(sch, skb); |
520ac30f | 911 | __qdisc_drop(skb, to_free); |
57dbb2d8 HPP |
912 | return len; |
913 | } | |
914 | ||
915 | return 0; | |
916 | } | |
917 | ||
520ac30f ED |
918 | static inline unsigned int qdisc_queue_drop_head(struct Qdisc *sch, |
919 | struct sk_buff **to_free) | |
57dbb2d8 | 920 | { |
520ac30f | 921 | return __qdisc_queue_drop_head(sch, &sch->q, to_free); |
9972b25d TG |
922 | } |
923 | ||
48a8f519 PM |
924 | static inline struct sk_buff *qdisc_peek_head(struct Qdisc *sch) |
925 | { | |
48da34b7 FW |
926 | const struct qdisc_skb_head *qh = &sch->q; |
927 | ||
928 | return qh->head; | |
48a8f519 PM |
929 | } |
930 | ||
77be155c JP |
931 | /* generic pseudo peek method for non-work-conserving qdisc */ |
932 | static inline struct sk_buff *qdisc_peek_dequeued(struct Qdisc *sch) | |
933 | { | |
a53851e2 JF |
934 | struct sk_buff *skb = skb_peek(&sch->gso_skb); |
935 | ||
77be155c | 936 | /* we can reuse ->gso_skb because peek isn't called for root qdiscs */ |
a53851e2 JF |
937 | if (!skb) { |
938 | skb = sch->dequeue(sch); | |
939 | ||
940 | if (skb) { | |
941 | __skb_queue_head(&sch->gso_skb, skb); | |
61c9eaf9 | 942 | /* it's still part of the queue */ |
a53851e2 | 943 | qdisc_qstats_backlog_inc(sch, skb); |
61c9eaf9 | 944 | sch->q.qlen++; |
a27758ff | 945 | } |
61c9eaf9 | 946 | } |
77be155c | 947 | |
a53851e2 | 948 | return skb; |
77be155c JP |
949 | } |
950 | ||
951 | /* use instead of qdisc->dequeue() for all qdiscs queried with ->peek() */ | |
952 | static inline struct sk_buff *qdisc_dequeue_peeked(struct Qdisc *sch) | |
953 | { | |
a53851e2 | 954 | struct sk_buff *skb = skb_peek(&sch->gso_skb); |
77be155c | 955 | |
61c9eaf9 | 956 | if (skb) { |
a53851e2 | 957 | skb = __skb_dequeue(&sch->gso_skb); |
a27758ff | 958 | qdisc_qstats_backlog_dec(sch, skb); |
61c9eaf9 JP |
959 | sch->q.qlen--; |
960 | } else { | |
77be155c | 961 | skb = sch->dequeue(sch); |
61c9eaf9 | 962 | } |
77be155c JP |
963 | |
964 | return skb; | |
965 | } | |
966 | ||
48da34b7 | 967 | static inline void __qdisc_reset_queue(struct qdisc_skb_head *qh) |
9972b25d TG |
968 | { |
969 | /* | |
970 | * We do not know the backlog in bytes of this list, it | |
971 | * is up to the caller to correct it | |
972 | */ | |
48da34b7 FW |
973 | ASSERT_RTNL(); |
974 | if (qh->qlen) { | |
975 | rtnl_kfree_skbs(qh->head, qh->tail); | |
976 | ||
977 | qh->head = NULL; | |
978 | qh->tail = NULL; | |
979 | qh->qlen = 0; | |
1b5c5493 | 980 | } |
9972b25d TG |
981 | } |
982 | ||
983 | static inline void qdisc_reset_queue(struct Qdisc *sch) | |
984 | { | |
1b5c5493 | 985 | __qdisc_reset_queue(&sch->q); |
9972b25d TG |
986 | sch->qstats.backlog = 0; |
987 | } | |
988 | ||
86a7996c WC |
989 | static inline struct Qdisc *qdisc_replace(struct Qdisc *sch, struct Qdisc *new, |
990 | struct Qdisc **pold) | |
991 | { | |
992 | struct Qdisc *old; | |
993 | ||
994 | sch_tree_lock(sch); | |
995 | old = *pold; | |
996 | *pold = new; | |
997 | if (old != NULL) { | |
68a66d14 KK |
998 | unsigned int qlen = old->q.qlen; |
999 | unsigned int backlog = old->qstats.backlog; | |
1000 | ||
86a7996c | 1001 | qdisc_reset(old); |
68a66d14 | 1002 | qdisc_tree_reduce_backlog(old, qlen, backlog); |
86a7996c WC |
1003 | } |
1004 | sch_tree_unlock(sch); | |
1005 | ||
1006 | return old; | |
1007 | } | |
1008 | ||
1b5c5493 ED |
1009 | static inline void rtnl_qdisc_drop(struct sk_buff *skb, struct Qdisc *sch) |
1010 | { | |
1011 | rtnl_kfree_skbs(skb, skb); | |
1012 | qdisc_qstats_drop(sch); | |
1013 | } | |
1014 | ||
40bd0362 JF |
1015 | static inline int qdisc_drop_cpu(struct sk_buff *skb, struct Qdisc *sch, |
1016 | struct sk_buff **to_free) | |
1017 | { | |
1018 | __qdisc_drop(skb, to_free); | |
1019 | qdisc_qstats_cpu_drop(sch); | |
1020 | ||
1021 | return NET_XMIT_DROP; | |
1022 | } | |
520ac30f ED |
1023 | |
1024 | static inline int qdisc_drop(struct sk_buff *skb, struct Qdisc *sch, | |
1025 | struct sk_buff **to_free) | |
9972b25d | 1026 | { |
520ac30f | 1027 | __qdisc_drop(skb, to_free); |
25331d6c | 1028 | qdisc_qstats_drop(sch); |
9972b25d TG |
1029 | |
1030 | return NET_XMIT_DROP; | |
1031 | } | |
1032 | ||
35d889d1 AK |
1033 | static inline int qdisc_drop_all(struct sk_buff *skb, struct Qdisc *sch, |
1034 | struct sk_buff **to_free) | |
1035 | { | |
1036 | __qdisc_drop_all(skb, to_free); | |
1037 | qdisc_qstats_drop(sch); | |
1038 | ||
1039 | return NET_XMIT_DROP; | |
1040 | } | |
1041 | ||
e9bef55d JDB |
1042 | /* Length to Time (L2T) lookup in a qdisc_rate_table, to determine how |
1043 | long it will take to send a packet given its size. | |
1044 | */ | |
1045 | static inline u32 qdisc_l2t(struct qdisc_rate_table* rtab, unsigned int pktlen) | |
1046 | { | |
e08b0998 JDB |
1047 | int slot = pktlen + rtab->rate.cell_align + rtab->rate.overhead; |
1048 | if (slot < 0) | |
1049 | slot = 0; | |
e9bef55d JDB |
1050 | slot >>= rtab->rate.cell_log; |
1051 | if (slot > 255) | |
a02cec21 | 1052 | return rtab->data[255]*(slot >> 8) + rtab->data[slot & 0xFF]; |
e9bef55d JDB |
1053 | return rtab->data[slot]; |
1054 | } | |
1055 | ||
292f1c7f | 1056 | struct psched_ratecfg { |
130d3d68 | 1057 | u64 rate_bytes_ps; /* bytes per second */ |
01cb71d2 ED |
1058 | u32 mult; |
1059 | u16 overhead; | |
8a8e3d84 | 1060 | u8 linklayer; |
01cb71d2 | 1061 | u8 shift; |
292f1c7f JP |
1062 | }; |
1063 | ||
1064 | static inline u64 psched_l2t_ns(const struct psched_ratecfg *r, | |
1065 | unsigned int len) | |
1066 | { | |
8a8e3d84 JDB |
1067 | len += r->overhead; |
1068 | ||
1069 | if (unlikely(r->linklayer == TC_LINKLAYER_ATM)) | |
1070 | return ((u64)(DIV_ROUND_UP(len,48)*53) * r->mult) >> r->shift; | |
1071 | ||
1072 | return ((u64)len * r->mult) >> r->shift; | |
292f1c7f JP |
1073 | } |
1074 | ||
5c15257f | 1075 | void psched_ratecfg_precompute(struct psched_ratecfg *r, |
3e1e3aae ED |
1076 | const struct tc_ratespec *conf, |
1077 | u64 rate64); | |
292f1c7f | 1078 | |
01cb71d2 ED |
1079 | static inline void psched_ratecfg_getrate(struct tc_ratespec *res, |
1080 | const struct psched_ratecfg *r) | |
292f1c7f | 1081 | { |
01cb71d2 | 1082 | memset(res, 0, sizeof(*res)); |
3e1e3aae ED |
1083 | |
1084 | /* legacy struct tc_ratespec has a 32bit @rate field | |
1085 | * Qdisc using 64bit rate should add new attributes | |
1086 | * in order to maintain compatibility. | |
1087 | */ | |
1088 | res->rate = min_t(u64, r->rate_bytes_ps, ~0U); | |
1089 | ||
01cb71d2 | 1090 | res->overhead = r->overhead; |
8a8e3d84 | 1091 | res->linklayer = (r->linklayer & TC_LINKLAYER_MASK); |
292f1c7f JP |
1092 | } |
1093 | ||
46209401 JP |
1094 | /* Mini Qdisc serves for specific needs of ingress/clsact Qdisc. |
1095 | * The fast path only needs to access filter list and to update stats | |
1096 | */ | |
1097 | struct mini_Qdisc { | |
1098 | struct tcf_proto *filter_list; | |
1099 | struct gnet_stats_basic_cpu __percpu *cpu_bstats; | |
1100 | struct gnet_stats_queue __percpu *cpu_qstats; | |
1101 | struct rcu_head rcu; | |
1102 | }; | |
1103 | ||
1104 | static inline void mini_qdisc_bstats_cpu_update(struct mini_Qdisc *miniq, | |
1105 | const struct sk_buff *skb) | |
1106 | { | |
1107 | bstats_cpu_update(this_cpu_ptr(miniq->cpu_bstats), skb); | |
1108 | } | |
1109 | ||
1110 | static inline void mini_qdisc_qstats_cpu_drop(struct mini_Qdisc *miniq) | |
1111 | { | |
1112 | this_cpu_inc(miniq->cpu_qstats->drops); | |
1113 | } | |
1114 | ||
1115 | struct mini_Qdisc_pair { | |
1116 | struct mini_Qdisc miniq1; | |
1117 | struct mini_Qdisc miniq2; | |
1118 | struct mini_Qdisc __rcu **p_miniq; | |
1119 | }; | |
1120 | ||
1121 | void mini_qdisc_pair_swap(struct mini_Qdisc_pair *miniqp, | |
1122 | struct tcf_proto *tp_head); | |
1123 | void mini_qdisc_pair_init(struct mini_Qdisc_pair *miniqp, struct Qdisc *qdisc, | |
1124 | struct mini_Qdisc __rcu **p_miniq); | |
1125 | ||
cd11b164 PA |
1126 | static inline void skb_tc_reinsert(struct sk_buff *skb, struct tcf_result *res) |
1127 | { | |
1128 | struct gnet_stats_queue *stats = res->qstats; | |
1129 | int ret; | |
1130 | ||
1131 | if (res->ingress) | |
1132 | ret = netif_receive_skb(skb); | |
1133 | else | |
1134 | ret = dev_queue_xmit(skb); | |
1135 | if (ret && stats) | |
1136 | qstats_overlimit_inc(res->qstats); | |
1137 | } | |
1138 | ||
1da177e4 | 1139 | #endif |