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