xref: /openbmc/linux/include/net/pkt_cls.h (revision 992b4785)
1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
21da177e4SLinus Torvalds #ifndef __NET_PKT_CLS_H
31da177e4SLinus Torvalds #define __NET_PKT_CLS_H
41da177e4SLinus Torvalds 
51da177e4SLinus Torvalds #include <linux/pkt_cls.h>
67aa0045dSCong Wang #include <linux/workqueue.h>
71da177e4SLinus Torvalds #include <net/sch_generic.h>
81da177e4SLinus Torvalds #include <net/act_api.h>
9a5148626SJiri Pirko #include <net/net_namespace.h>
101da177e4SLinus Torvalds 
11cd11b164SPaolo Abeni /* TC action not accessible from user space */
12720f22feSJohn Hurley #define TC_ACT_CONSUMED		(TC_ACT_VALUE_MAX + 1)
13cd11b164SPaolo Abeni 
141da177e4SLinus Torvalds /* Basic packet classifier frontend definitions. */
151da177e4SLinus Torvalds 
16fd2c3ef7SEric Dumazet struct tcf_walker {
171da177e4SLinus Torvalds 	int	stop;
181da177e4SLinus Torvalds 	int	skip;
191da177e4SLinus Torvalds 	int	count;
206676d5e4SVlad Buslov 	bool	nonempty;
2101683a14SVlad Buslov 	unsigned long cookie;
228113c095SWANG Cong 	int	(*fn)(struct tcf_proto *, void *node, struct tcf_walker *);
231da177e4SLinus Torvalds };
241da177e4SLinus Torvalds 
255c15257fSJoe Perches int register_tcf_proto_ops(struct tcf_proto_ops *ops);
26bc5c8260SZhengchao Shao void unregister_tcf_proto_ops(struct tcf_proto_ops *ops);
271da177e4SLinus Torvalds 
288c4083b3SJiri Pirko struct tcf_block_ext_info {
2932f8c409SPablo Neira Ayuso 	enum flow_block_binder_type binder_type;
30c7eb7d72SJiri Pirko 	tcf_chain_head_change_t *chain_head_change;
31c7eb7d72SJiri Pirko 	void *chain_head_change_priv;
3248617387SJiri Pirko 	u32 block_index;
338c4083b3SJiri Pirko };
348c4083b3SJiri Pirko 
353625750fSPetr Machata struct tcf_qevent {
363625750fSPetr Machata 	struct tcf_block	*block;
373625750fSPetr Machata 	struct tcf_block_ext_info info;
383625750fSPetr Machata 	struct tcf_proto __rcu *filter_chain;
393625750fSPetr Machata };
403625750fSPetr Machata 
41acb67442SJiri Pirko struct tcf_block_cb;
42aaa908ffSCong Wang bool tcf_queue_work(struct rcu_work *rwork, work_func_t func);
43acb67442SJiri Pirko 
448ae70032SJiri Pirko #ifdef CONFIG_NET_CLS
451f3ed383SJiri Pirko struct tcf_chain *tcf_chain_get_by_act(struct tcf_block *block,
461f3ed383SJiri Pirko 				       u32 chain_index);
471f3ed383SJiri Pirko void tcf_chain_put_by_act(struct tcf_chain *chain);
48bbf73830SVlad Buslov struct tcf_chain *tcf_get_next_chain(struct tcf_block *block,
49bbf73830SVlad Buslov 				     struct tcf_chain *chain);
50fe2923afSVlad Buslov struct tcf_proto *tcf_get_next_proto(struct tcf_chain *chain,
510fca55edSVlad Buslov 				     struct tcf_proto *tp);
52f36fe1c4SJiri Pirko void tcf_block_netif_keep_dst(struct tcf_block *block);
536529eabaSJiri Pirko int tcf_block_get(struct tcf_block **p_block,
548d1a77f9SAlexander Aring 		  struct tcf_proto __rcu **p_filter_chain, struct Qdisc *q,
558d1a77f9SAlexander Aring 		  struct netlink_ext_ack *extack);
56c7eb7d72SJiri Pirko int tcf_block_get_ext(struct tcf_block **p_block, struct Qdisc *q,
578d1a77f9SAlexander Aring 		      struct tcf_block_ext_info *ei,
588d1a77f9SAlexander Aring 		      struct netlink_ext_ack *extack);
596529eabaSJiri Pirko void tcf_block_put(struct tcf_block *block);
60c7eb7d72SJiri Pirko void tcf_block_put_ext(struct tcf_block *block, struct Qdisc *q,
618c4083b3SJiri Pirko 		       struct tcf_block_ext_info *ei);
6280cd22c3SPaul Blakey int tcf_exts_init_ex(struct tcf_exts *exts, struct net *net, int action,
6380cd22c3SPaul Blakey 		     int police, struct tcf_proto *tp, u32 handle, bool used_action_miss);
6444186460SJiri Pirko 
tcf_block_shared(struct tcf_block * block)6548617387SJiri Pirko static inline bool tcf_block_shared(struct tcf_block *block)
6648617387SJiri Pirko {
6748617387SJiri Pirko 	return block->index;
6848617387SJiri Pirko }
6948617387SJiri Pirko 
tcf_block_non_null_shared(struct tcf_block * block)70c1a970d0SVlad Buslov static inline bool tcf_block_non_null_shared(struct tcf_block *block)
71c1a970d0SVlad Buslov {
72c1a970d0SVlad Buslov 	return block && block->index;
73c1a970d0SVlad Buslov }
74c1a970d0SVlad Buslov 
tcf_block_q(struct tcf_block * block)7544186460SJiri Pirko static inline struct Qdisc *tcf_block_q(struct tcf_block *block)
7644186460SJiri Pirko {
7748617387SJiri Pirko 	WARN_ON(tcf_block_shared(block));
7844186460SJiri Pirko 	return block->q;
7944186460SJiri Pirko }
8044186460SJiri Pirko 
813aa26055SDavide Caratti int tcf_classify(struct sk_buff *skb,
823aa26055SDavide Caratti 		 const struct tcf_block *block,
837d17c544SPaul Blakey 		 const struct tcf_proto *tp, struct tcf_result *res,
847d17c544SPaul Blakey 		 bool compat_mode);
8587d83093SJiri Pirko 
tc_cls_stats_dump(struct tcf_proto * tp,struct tcf_walker * arg,void * filter)86fe0df81dSZhengchao Shao static inline bool tc_cls_stats_dump(struct tcf_proto *tp,
87fe0df81dSZhengchao Shao 				     struct tcf_walker *arg,
88fe0df81dSZhengchao Shao 				     void *filter)
89fe0df81dSZhengchao Shao {
90fe0df81dSZhengchao Shao 	if (arg->count >= arg->skip && arg->fn(tp, filter, arg) < 0) {
91fe0df81dSZhengchao Shao 		arg->stop = 1;
92fe0df81dSZhengchao Shao 		return false;
93fe0df81dSZhengchao Shao 	}
94fe0df81dSZhengchao Shao 
95fe0df81dSZhengchao Shao 	arg->count++;
96fe0df81dSZhengchao Shao 	return true;
97fe0df81dSZhengchao Shao }
98fe0df81dSZhengchao Shao 
998ae70032SJiri Pirko #else
tcf_block_shared(struct tcf_block * block)10088c44a52SPieter Jansen van Vuuren static inline bool tcf_block_shared(struct tcf_block *block)
10188c44a52SPieter Jansen van Vuuren {
10288c44a52SPieter Jansen van Vuuren 	return false;
10388c44a52SPieter Jansen van Vuuren }
10488c44a52SPieter Jansen van Vuuren 
tcf_block_non_null_shared(struct tcf_block * block)105c1a970d0SVlad Buslov static inline bool tcf_block_non_null_shared(struct tcf_block *block)
106c1a970d0SVlad Buslov {
107c1a970d0SVlad Buslov 	return false;
108c1a970d0SVlad Buslov }
109c1a970d0SVlad Buslov 
1106529eabaSJiri Pirko static inline
tcf_block_get(struct tcf_block ** p_block,struct tcf_proto __rcu ** p_filter_chain,struct Qdisc * q,struct netlink_ext_ack * extack)1116529eabaSJiri Pirko int tcf_block_get(struct tcf_block **p_block,
1123c149091SSudip Mukherjee 		  struct tcf_proto __rcu **p_filter_chain, struct Qdisc *q,
1133c149091SSudip Mukherjee 		  struct netlink_ext_ack *extack)
1146529eabaSJiri Pirko {
1156529eabaSJiri Pirko 	return 0;
1166529eabaSJiri Pirko }
1176529eabaSJiri Pirko 
1188c4083b3SJiri Pirko static inline
tcf_block_get_ext(struct tcf_block ** p_block,struct Qdisc * q,struct tcf_block_ext_info * ei,struct netlink_ext_ack * extack)119c7eb7d72SJiri Pirko int tcf_block_get_ext(struct tcf_block **p_block, struct Qdisc *q,
12033c30a8bSQuentin Monnet 		      struct tcf_block_ext_info *ei,
12133c30a8bSQuentin Monnet 		      struct netlink_ext_ack *extack)
1228c4083b3SJiri Pirko {
1238c4083b3SJiri Pirko 	return 0;
1248c4083b3SJiri Pirko }
1258c4083b3SJiri Pirko 
tcf_block_put(struct tcf_block * block)1266529eabaSJiri Pirko static inline void tcf_block_put(struct tcf_block *block)
1278ae70032SJiri Pirko {
1288ae70032SJiri Pirko }
12987d83093SJiri Pirko 
1308c4083b3SJiri Pirko static inline
tcf_block_put_ext(struct tcf_block * block,struct Qdisc * q,struct tcf_block_ext_info * ei)131c7eb7d72SJiri Pirko void tcf_block_put_ext(struct tcf_block *block, struct Qdisc *q,
1328c4083b3SJiri Pirko 		       struct tcf_block_ext_info *ei)
1338c4083b3SJiri Pirko {
1348c4083b3SJiri Pirko }
1358c4083b3SJiri Pirko 
tcf_block_q(struct tcf_block * block)13644186460SJiri Pirko static inline struct Qdisc *tcf_block_q(struct tcf_block *block)
13744186460SJiri Pirko {
13844186460SJiri Pirko 	return NULL;
13944186460SJiri Pirko }
14044186460SJiri Pirko 
tcf_classify(struct sk_buff * skb,const struct tcf_block * block,const struct tcf_proto * tp,struct tcf_result * res,bool compat_mode)1413aa26055SDavide Caratti static inline int tcf_classify(struct sk_buff *skb,
1423aa26055SDavide Caratti 			       const struct tcf_block *block,
1439410c940SPaul Blakey 			       const struct tcf_proto *tp,
1449410c940SPaul Blakey 			       struct tcf_result *res, bool compat_mode)
1459410c940SPaul Blakey {
1469410c940SPaul Blakey 	return TC_ACT_UNSPEC;
1479410c940SPaul Blakey }
1489410c940SPaul Blakey 
1498ae70032SJiri Pirko #endif
150cf1facdaSJiri Pirko 
1511da177e4SLinus Torvalds static inline unsigned long
__cls_set_class(unsigned long * clp,unsigned long cl)1521da177e4SLinus Torvalds __cls_set_class(unsigned long *clp, unsigned long cl)
1531da177e4SLinus Torvalds {
154a0efb80cSWANG Cong 	return xchg(clp, cl);
1551da177e4SLinus Torvalds }
1561da177e4SLinus Torvalds 
1572e24cd75SCong Wang static inline void
__tcf_bind_filter(struct Qdisc * q,struct tcf_result * r,unsigned long base)1582e24cd75SCong Wang __tcf_bind_filter(struct Qdisc *q, struct tcf_result *r, unsigned long base)
1591da177e4SLinus Torvalds {
1602e24cd75SCong Wang 	unsigned long cl;
1611da177e4SLinus Torvalds 
1622e24cd75SCong Wang 	cl = q->ops->cl_ops->bind_tcf(q, base, r->classid);
1632e24cd75SCong Wang 	cl = __cls_set_class(&r->class, cl);
1642e24cd75SCong Wang 	if (cl)
1652e24cd75SCong Wang 		q->ops->cl_ops->unbind_tcf(q, cl);
1661da177e4SLinus Torvalds }
1671da177e4SLinus Torvalds 
1681da177e4SLinus Torvalds static inline void
tcf_bind_filter(struct tcf_proto * tp,struct tcf_result * r,unsigned long base)1691da177e4SLinus Torvalds tcf_bind_filter(struct tcf_proto *tp, struct tcf_result *r, unsigned long base)
1701da177e4SLinus Torvalds {
17134e3759cSJiri Pirko 	struct Qdisc *q = tp->chain->block->q;
1721da177e4SLinus Torvalds 
17334e3759cSJiri Pirko 	/* Check q as it is not set for shared blocks. In that case,
17434e3759cSJiri Pirko 	 * setting class is not supported.
17534e3759cSJiri Pirko 	 */
17634e3759cSJiri Pirko 	if (!q)
17734e3759cSJiri Pirko 		return;
1782e24cd75SCong Wang 	sch_tree_lock(q);
1792e24cd75SCong Wang 	__tcf_bind_filter(q, r, base);
1802e24cd75SCong Wang 	sch_tree_unlock(q);
1812e24cd75SCong Wang }
1822e24cd75SCong Wang 
1832e24cd75SCong Wang static inline void
__tcf_unbind_filter(struct Qdisc * q,struct tcf_result * r)1842e24cd75SCong Wang __tcf_unbind_filter(struct Qdisc *q, struct tcf_result *r)
1852e24cd75SCong Wang {
1862e24cd75SCong Wang 	unsigned long cl;
1872e24cd75SCong Wang 
1882e24cd75SCong Wang 	if ((cl = __cls_set_class(&r->class, 0)) != 0)
18934e3759cSJiri Pirko 		q->ops->cl_ops->unbind_tcf(q, cl);
1901da177e4SLinus Torvalds }
1911da177e4SLinus Torvalds 
1921da177e4SLinus Torvalds static inline void
tcf_unbind_filter(struct tcf_proto * tp,struct tcf_result * r)1931da177e4SLinus Torvalds tcf_unbind_filter(struct tcf_proto *tp, struct tcf_result *r)
1941da177e4SLinus Torvalds {
19534e3759cSJiri Pirko 	struct Qdisc *q = tp->chain->block->q;
1961da177e4SLinus Torvalds 
19734e3759cSJiri Pirko 	if (!q)
19834e3759cSJiri Pirko 		return;
1992e24cd75SCong Wang 	__tcf_unbind_filter(q, r);
2001da177e4SLinus Torvalds }
2011da177e4SLinus Torvalds 
tc_cls_bind_class(u32 classid,unsigned long cl,void * q,struct tcf_result * res,unsigned long base)202402963e3SZhengchao Shao static inline void tc_cls_bind_class(u32 classid, unsigned long cl,
203402963e3SZhengchao Shao 				     void *q, struct tcf_result *res,
204402963e3SZhengchao Shao 				     unsigned long base)
205402963e3SZhengchao Shao {
206402963e3SZhengchao Shao 	if (res->classid == classid) {
207402963e3SZhengchao Shao 		if (cl)
208402963e3SZhengchao Shao 			__tcf_bind_filter(q, res, base);
209402963e3SZhengchao Shao 		else
210402963e3SZhengchao Shao 			__tcf_unbind_filter(q, res);
211402963e3SZhengchao Shao 	}
212402963e3SZhengchao Shao }
213402963e3SZhengchao Shao 
214fd2c3ef7SEric Dumazet struct tcf_exts {
2151da177e4SLinus Torvalds #ifdef CONFIG_NET_CLS_ACT
21633be6271SWANG Cong 	__u32	type; /* for backward compat(TCA_OLD_COMPAT) */
21722dc13c8SWANG Cong 	int nr_actions;
21822dc13c8SWANG Cong 	struct tc_action **actions;
219e4b95c41SCong Wang 	struct net	*net;
220dbdcda63SEric Dumazet 	netns_tracker	ns_tracker;
22180cd22c3SPaul Blakey 	struct tcf_exts_miss_cookie_node *miss_cookie_node;
2221da177e4SLinus Torvalds #endif
2231da177e4SLinus Torvalds 	/* Map to export classifier specific extension TLV types to the
2241da177e4SLinus Torvalds 	 * generic extensions API. Unsupported extensions must be set to 0.
2251da177e4SLinus Torvalds 	 */
2261da177e4SLinus Torvalds 	int action;
2271da177e4SLinus Torvalds 	int police;
2281da177e4SLinus Torvalds };
2291da177e4SLinus Torvalds 
tcf_exts_init(struct tcf_exts * exts,struct net * net,int action,int police)23014215108SCong Wang static inline int tcf_exts_init(struct tcf_exts *exts, struct net *net,
23114215108SCong Wang 				int action, int police)
23233be6271SWANG Cong {
23380cd22c3SPaul Blakey #ifdef CONFIG_NET_CLS
23480cd22c3SPaul Blakey 	return tcf_exts_init_ex(exts, net, action, police, NULL, 0, false);
23580cd22c3SPaul Blakey #else
23680cd22c3SPaul Blakey 	return -EOPNOTSUPP;
23733be6271SWANG Cong #endif
23833be6271SWANG Cong }
23933be6271SWANG Cong 
240e4b95c41SCong Wang /* Return false if the netns is being destroyed in cleanup_net(). Callers
241e4b95c41SCong Wang  * need to do cleanup synchronously in this case, otherwise may race with
242e4b95c41SCong Wang  * tc_action_net_exit(). Return true for other cases.
243e4b95c41SCong Wang  */
tcf_exts_get_net(struct tcf_exts * exts)244e4b95c41SCong Wang static inline bool tcf_exts_get_net(struct tcf_exts *exts)
245e4b95c41SCong Wang {
246e4b95c41SCong Wang #ifdef CONFIG_NET_CLS_ACT
247e4b95c41SCong Wang 	exts->net = maybe_get_net(exts->net);
248dbdcda63SEric Dumazet 	if (exts->net)
249dbdcda63SEric Dumazet 		netns_tracker_alloc(exts->net, &exts->ns_tracker, GFP_KERNEL);
250e4b95c41SCong Wang 	return exts->net != NULL;
251e4b95c41SCong Wang #else
252e4b95c41SCong Wang 	return true;
253e4b95c41SCong Wang #endif
254e4b95c41SCong Wang }
255e4b95c41SCong Wang 
tcf_exts_put_net(struct tcf_exts * exts)256e4b95c41SCong Wang static inline void tcf_exts_put_net(struct tcf_exts *exts)
257e4b95c41SCong Wang {
258e4b95c41SCong Wang #ifdef CONFIG_NET_CLS_ACT
259e4b95c41SCong Wang 	if (exts->net)
260dbdcda63SEric Dumazet 		put_net_track(exts->net, &exts->ns_tracker);
261e4b95c41SCong Wang #endif
262e4b95c41SCong Wang }
263e4b95c41SCong Wang 
26422dc13c8SWANG Cong #ifdef CONFIG_NET_CLS_ACT
265244cd96aSCong Wang #define tcf_exts_for_each_action(i, a, exts) \
266244cd96aSCong Wang 	for (i = 0; i < TCA_ACT_MAX_PRIO && ((a) = (exts)->actions[i]); i++)
267244cd96aSCong Wang #else
268244cd96aSCong Wang #define tcf_exts_for_each_action(i, a, exts) \
269191672caSArnd Bergmann 	for (; 0; (void)(i), (void)(a), (void)(exts))
27022dc13c8SWANG Cong #endif
27122dc13c8SWANG Cong 
2728cbfe939SBaowen Zheng #define tcf_act_for_each_action(i, a, actions) \
2738cbfe939SBaowen Zheng 	for (i = 0; i < TCA_ACT_MAX_PRIO && ((a) = actions[i]); i++)
2748cbfe939SBaowen Zheng 
tc_act_in_hw(struct tc_action * act)2755246c896SOz Shlomo static inline bool tc_act_in_hw(struct tc_action *act)
2765246c896SOz Shlomo {
2775246c896SOz Shlomo 	return !!act->in_hw_count;
2785246c896SOz Shlomo }
2795246c896SOz Shlomo 
280d897a638SJakub Kicinski static inline void
tcf_exts_hw_stats_update(const struct tcf_exts * exts,struct flow_stats * stats,bool use_act_stats)281bcd64368SBaowen Zheng tcf_exts_hw_stats_update(const struct tcf_exts *exts,
2825246c896SOz Shlomo 			 struct flow_stats *stats,
2835246c896SOz Shlomo 			 bool use_act_stats)
284d897a638SJakub Kicinski {
285d897a638SJakub Kicinski #ifdef CONFIG_NET_CLS_ACT
286d897a638SJakub Kicinski 	int i;
287d897a638SJakub Kicinski 
288d897a638SJakub Kicinski 	for (i = 0; i < exts->nr_actions; i++) {
289d897a638SJakub Kicinski 		struct tc_action *a = exts->actions[i];
290d897a638SJakub Kicinski 
2915246c896SOz Shlomo 		if (use_act_stats || tc_act_in_hw(a)) {
2925246c896SOz Shlomo 			if (!tcf_action_update_hw_stats(a))
2935246c896SOz Shlomo 				continue;
2945246c896SOz Shlomo 		}
2955246c896SOz Shlomo 
296c7a66f8dSBaowen Zheng 		preempt_disable();
297ac7d2790SOz Shlomo 		tcf_action_stats_update(a, stats->bytes, stats->pkts, stats->drops,
298ac7d2790SOz Shlomo 					stats->lastused, true);
299c7a66f8dSBaowen Zheng 		preempt_enable();
300c7a66f8dSBaowen Zheng 
301ac7d2790SOz Shlomo 		a->used_hw_stats = stats->used_hw_stats;
302ac7d2790SOz Shlomo 		a->used_hw_stats_valid = stats->used_hw_stats_valid;
303d897a638SJakub Kicinski 	}
304d897a638SJakub Kicinski #endif
305d897a638SJakub Kicinski }
306d897a638SJakub Kicinski 
3071da177e4SLinus Torvalds /**
3083bcc0cecSJiri Pirko  * tcf_exts_has_actions - check if at least one action is present
3093bcc0cecSJiri Pirko  * @exts: tc filter extensions handle
3103bcc0cecSJiri Pirko  *
3113bcc0cecSJiri Pirko  * Returns true if at least one action is present.
3123bcc0cecSJiri Pirko  */
tcf_exts_has_actions(struct tcf_exts * exts)3133bcc0cecSJiri Pirko static inline bool tcf_exts_has_actions(struct tcf_exts *exts)
3143bcc0cecSJiri Pirko {
3152734437eSWANG Cong #ifdef CONFIG_NET_CLS_ACT
3163bcc0cecSJiri Pirko 	return exts->nr_actions;
3173bcc0cecSJiri Pirko #else
3183bcc0cecSJiri Pirko 	return false;
3193bcc0cecSJiri Pirko #endif
3203bcc0cecSJiri Pirko }
3212734437eSWANG Cong 
3223bcc0cecSJiri Pirko /**
323af69afc5SJiri Pirko  * tcf_exts_exec - execute tc filter extensions
324af69afc5SJiri Pirko  * @skb: socket buffer
325af69afc5SJiri Pirko  * @exts: tc filter extensions handle
326af69afc5SJiri Pirko  * @res: desired result
327af69afc5SJiri Pirko  *
328af089e70SJiri Pirko  * Executes all configured extensions. Returns TC_ACT_OK on a normal execution,
329af69afc5SJiri Pirko  * a negative number if the filter must be considered unmatched or
330af69afc5SJiri Pirko  * a positive action code (TC_ACT_*) which must be returned to the
331af69afc5SJiri Pirko  * underlying layer.
332af69afc5SJiri Pirko  */
333af69afc5SJiri Pirko static inline int
tcf_exts_exec(struct sk_buff * skb,struct tcf_exts * exts,struct tcf_result * res)334af69afc5SJiri Pirko tcf_exts_exec(struct sk_buff *skb, struct tcf_exts *exts,
335af69afc5SJiri Pirko 	      struct tcf_result *res)
336af69afc5SJiri Pirko {
337af69afc5SJiri Pirko #ifdef CONFIG_NET_CLS_ACT
338ec1a9ccaSJiri Pirko 	return tcf_action_exec(skb, exts->actions, exts->nr_actions, res);
339af69afc5SJiri Pirko #endif
340af089e70SJiri Pirko 	return TC_ACT_OK;
341af69afc5SJiri Pirko }
342af69afc5SJiri Pirko 
34380cd22c3SPaul Blakey static inline int
tcf_exts_exec_ex(struct sk_buff * skb,struct tcf_exts * exts,int act_index,struct tcf_result * res)34480cd22c3SPaul Blakey tcf_exts_exec_ex(struct sk_buff *skb, struct tcf_exts *exts, int act_index,
34580cd22c3SPaul Blakey 		 struct tcf_result *res)
34680cd22c3SPaul Blakey {
34780cd22c3SPaul Blakey #ifdef CONFIG_NET_CLS_ACT
34880cd22c3SPaul Blakey 	return tcf_action_exec(skb, exts->actions + act_index,
34980cd22c3SPaul Blakey 			       exts->nr_actions - act_index, res);
35080cd22c3SPaul Blakey #else
35180cd22c3SPaul Blakey 	return TC_ACT_OK;
35280cd22c3SPaul Blakey #endif
35380cd22c3SPaul Blakey }
35480cd22c3SPaul Blakey 
3555c15257fSJoe Perches int tcf_exts_validate(struct net *net, struct tcf_proto *tp,
356c1b52739SBenjamin LaHaise 		      struct nlattr **tb, struct nlattr *rate_tlv,
357695176bfSCong Wang 		      struct tcf_exts *exts, u32 flags,
35850a56190SAlexander Aring 		      struct netlink_ext_ack *extack);
359c86e0209SBaowen Zheng int tcf_exts_validate_ex(struct net *net, struct tcf_proto *tp, struct nlattr **tb,
360c86e0209SBaowen Zheng 			 struct nlattr *rate_tlv, struct tcf_exts *exts,
361c86e0209SBaowen Zheng 			 u32 flags, u32 fl_flags, struct netlink_ext_ack *extack);
36218d0264fSWANG Cong void tcf_exts_destroy(struct tcf_exts *exts);
3639b0d4446SJiri Pirko void tcf_exts_change(struct tcf_exts *dst, struct tcf_exts *src);
3645da57f42SWANG Cong int tcf_exts_dump(struct sk_buff *skb, struct tcf_exts *exts);
365ca44b738SVlad Buslov int tcf_exts_terse_dump(struct sk_buff *skb, struct tcf_exts *exts);
3665da57f42SWANG Cong int tcf_exts_dump_stats(struct sk_buff *skb, struct tcf_exts *exts);
3671da177e4SLinus Torvalds 
3681da177e4SLinus Torvalds /**
3691da177e4SLinus Torvalds  * struct tcf_pkt_info - packet information
3700161d151SBijie Xu  *
3710161d151SBijie Xu  * @ptr: start of the pkt data
3720161d151SBijie Xu  * @nexthdr: offset of the next header
3731da177e4SLinus Torvalds  */
374fd2c3ef7SEric Dumazet struct tcf_pkt_info {
3751da177e4SLinus Torvalds 	unsigned char *		ptr;
3761da177e4SLinus Torvalds 	int			nexthdr;
3771da177e4SLinus Torvalds };
3781da177e4SLinus Torvalds 
3791da177e4SLinus Torvalds #ifdef CONFIG_NET_EMATCH
3801da177e4SLinus Torvalds 
3811da177e4SLinus Torvalds struct tcf_ematch_ops;
3821da177e4SLinus Torvalds 
3831da177e4SLinus Torvalds /**
3841da177e4SLinus Torvalds  * struct tcf_ematch - extended match (ematch)
3851da177e4SLinus Torvalds  *
3861da177e4SLinus Torvalds  * @matchid: identifier to allow userspace to reidentify a match
3871da177e4SLinus Torvalds  * @flags: flags specifying attributes and the relation to other matches
3881da177e4SLinus Torvalds  * @ops: the operations lookup table of the corresponding ematch module
3891da177e4SLinus Torvalds  * @datalen: length of the ematch specific configuration data
3901da177e4SLinus Torvalds  * @data: ematch specific data
3910161d151SBijie Xu  * @net: the network namespace
3921da177e4SLinus Torvalds  */
393fd2c3ef7SEric Dumazet struct tcf_ematch {
3941da177e4SLinus Torvalds 	struct tcf_ematch_ops * ops;
3951da177e4SLinus Torvalds 	unsigned long		data;
3961da177e4SLinus Torvalds 	unsigned int		datalen;
3971da177e4SLinus Torvalds 	u16			matchid;
3981da177e4SLinus Torvalds 	u16			flags;
39982a470f1SJohn Fastabend 	struct net		*net;
4001da177e4SLinus Torvalds };
4011da177e4SLinus Torvalds 
tcf_em_is_container(struct tcf_ematch * em)4021da177e4SLinus Torvalds static inline int tcf_em_is_container(struct tcf_ematch *em)
4031da177e4SLinus Torvalds {
4041da177e4SLinus Torvalds 	return !em->ops;
4051da177e4SLinus Torvalds }
4061da177e4SLinus Torvalds 
tcf_em_is_simple(struct tcf_ematch * em)4071da177e4SLinus Torvalds static inline int tcf_em_is_simple(struct tcf_ematch *em)
4081da177e4SLinus Torvalds {
4091da177e4SLinus Torvalds 	return em->flags & TCF_EM_SIMPLE;
4101da177e4SLinus Torvalds }
4111da177e4SLinus Torvalds 
tcf_em_is_inverted(struct tcf_ematch * em)4121da177e4SLinus Torvalds static inline int tcf_em_is_inverted(struct tcf_ematch *em)
4131da177e4SLinus Torvalds {
4141da177e4SLinus Torvalds 	return em->flags & TCF_EM_INVERT;
4151da177e4SLinus Torvalds }
4161da177e4SLinus Torvalds 
tcf_em_last_match(struct tcf_ematch * em)4171da177e4SLinus Torvalds static inline int tcf_em_last_match(struct tcf_ematch *em)
4181da177e4SLinus Torvalds {
4191da177e4SLinus Torvalds 	return (em->flags & TCF_EM_REL_MASK) == TCF_EM_REL_END;
4201da177e4SLinus Torvalds }
4211da177e4SLinus Torvalds 
tcf_em_early_end(struct tcf_ematch * em,int result)4221da177e4SLinus Torvalds static inline int tcf_em_early_end(struct tcf_ematch *em, int result)
4231da177e4SLinus Torvalds {
4241da177e4SLinus Torvalds 	if (tcf_em_last_match(em))
4251da177e4SLinus Torvalds 		return 1;
4261da177e4SLinus Torvalds 
4271da177e4SLinus Torvalds 	if (result == 0 && em->flags & TCF_EM_REL_AND)
4281da177e4SLinus Torvalds 		return 1;
4291da177e4SLinus Torvalds 
4301da177e4SLinus Torvalds 	if (result != 0 && em->flags & TCF_EM_REL_OR)
4311da177e4SLinus Torvalds 		return 1;
4321da177e4SLinus Torvalds 
4331da177e4SLinus Torvalds 	return 0;
4341da177e4SLinus Torvalds }
4351da177e4SLinus Torvalds 
4361da177e4SLinus Torvalds /**
4371da177e4SLinus Torvalds  * struct tcf_ematch_tree - ematch tree handle
4381da177e4SLinus Torvalds  *
4391da177e4SLinus Torvalds  * @hdr: ematch tree header supplied by userspace
4401da177e4SLinus Torvalds  * @matches: array of ematches
4411da177e4SLinus Torvalds  */
442fd2c3ef7SEric Dumazet struct tcf_ematch_tree {
4431da177e4SLinus Torvalds 	struct tcf_ematch_tree_hdr hdr;
4441da177e4SLinus Torvalds 	struct tcf_ematch *	matches;
4451da177e4SLinus Torvalds 
4461da177e4SLinus Torvalds };
4471da177e4SLinus Torvalds 
4481da177e4SLinus Torvalds /**
4491da177e4SLinus Torvalds  * struct tcf_ematch_ops - ematch module operations
4501da177e4SLinus Torvalds  *
4511da177e4SLinus Torvalds  * @kind: identifier (kind) of this ematch module
4521da177e4SLinus Torvalds  * @datalen: length of expected configuration data (optional)
4531da177e4SLinus Torvalds  * @change: called during validation (optional)
4541da177e4SLinus Torvalds  * @match: called during ematch tree evaluation, must return 1/0
4551da177e4SLinus Torvalds  * @destroy: called during destroyage (optional)
4561da177e4SLinus Torvalds  * @dump: called during dumping process (optional)
4571da177e4SLinus Torvalds  * @owner: owner, must be set to THIS_MODULE
4581da177e4SLinus Torvalds  * @link: link to previous/next ematch module (internal use)
4591da177e4SLinus Torvalds  */
460fd2c3ef7SEric Dumazet struct tcf_ematch_ops {
4611da177e4SLinus Torvalds 	int			kind;
4621da177e4SLinus Torvalds 	int			datalen;
46382a470f1SJohn Fastabend 	int			(*change)(struct net *net, void *,
4641da177e4SLinus Torvalds 					  int, struct tcf_ematch *);
4651da177e4SLinus Torvalds 	int			(*match)(struct sk_buff *, struct tcf_ematch *,
4661da177e4SLinus Torvalds 					 struct tcf_pkt_info *);
46782a470f1SJohn Fastabend 	void			(*destroy)(struct tcf_ematch *);
4681da177e4SLinus Torvalds 	int			(*dump)(struct sk_buff *, struct tcf_ematch *);
4691da177e4SLinus Torvalds 	struct module		*owner;
4701da177e4SLinus Torvalds 	struct list_head	link;
4711da177e4SLinus Torvalds };
4721da177e4SLinus Torvalds 
4735c15257fSJoe Perches int tcf_em_register(struct tcf_ematch_ops *);
4745c15257fSJoe Perches void tcf_em_unregister(struct tcf_ematch_ops *);
4755c15257fSJoe Perches int tcf_em_tree_validate(struct tcf_proto *, struct nlattr *,
4761da177e4SLinus Torvalds 			 struct tcf_ematch_tree *);
47782a470f1SJohn Fastabend void tcf_em_tree_destroy(struct tcf_ematch_tree *);
4785c15257fSJoe Perches int tcf_em_tree_dump(struct sk_buff *, struct tcf_ematch_tree *, int);
4795c15257fSJoe Perches int __tcf_em_tree_match(struct sk_buff *, struct tcf_ematch_tree *,
4801da177e4SLinus Torvalds 			struct tcf_pkt_info *);
4811da177e4SLinus Torvalds 
4821da177e4SLinus Torvalds /**
4831da177e4SLinus Torvalds  * tcf_em_tree_match - evaulate an ematch tree
4841da177e4SLinus Torvalds  *
4851da177e4SLinus Torvalds  * @skb: socket buffer of the packet in question
4861da177e4SLinus Torvalds  * @tree: ematch tree to be used for evaluation
4871da177e4SLinus Torvalds  * @info: packet information examined by classifier
4881da177e4SLinus Torvalds  *
4891da177e4SLinus Torvalds  * This function matches @skb against the ematch tree in @tree by going
4901da177e4SLinus Torvalds  * through all ematches respecting their logic relations returning
4911da177e4SLinus Torvalds  * as soon as the result is obvious.
4921da177e4SLinus Torvalds  *
4931da177e4SLinus Torvalds  * Returns 1 if the ematch tree as-one matches, no ematches are configured
4941da177e4SLinus Torvalds  * or ematch is not enabled in the kernel, otherwise 0 is returned.
4951da177e4SLinus Torvalds  */
tcf_em_tree_match(struct sk_buff * skb,struct tcf_ematch_tree * tree,struct tcf_pkt_info * info)4961da177e4SLinus Torvalds static inline int tcf_em_tree_match(struct sk_buff *skb,
4971da177e4SLinus Torvalds 				    struct tcf_ematch_tree *tree,
4981da177e4SLinus Torvalds 				    struct tcf_pkt_info *info)
4991da177e4SLinus Torvalds {
5001da177e4SLinus Torvalds 	if (tree->hdr.nmatches)
5011da177e4SLinus Torvalds 		return __tcf_em_tree_match(skb, tree, info);
5021da177e4SLinus Torvalds 	else
5031da177e4SLinus Torvalds 		return 1;
5041da177e4SLinus Torvalds }
5051da177e4SLinus Torvalds 
506db3d99c0SPatrick McHardy #define MODULE_ALIAS_TCF_EMATCH(kind)	MODULE_ALIAS("ematch-kind-" __stringify(kind))
507db3d99c0SPatrick McHardy 
5081da177e4SLinus Torvalds #else /* CONFIG_NET_EMATCH */
5091da177e4SLinus Torvalds 
510fd2c3ef7SEric Dumazet struct tcf_ematch_tree {
5111da177e4SLinus Torvalds };
5121da177e4SLinus Torvalds 
5131da177e4SLinus Torvalds #define tcf_em_tree_validate(tp, tb, t) ((void)(t), 0)
51482a470f1SJohn Fastabend #define tcf_em_tree_destroy(t) do { (void)(t); } while(0)
5151da177e4SLinus Torvalds #define tcf_em_tree_dump(skb, t, tlv) (0)
5161da177e4SLinus Torvalds #define tcf_em_tree_match(skb, t, info) ((void)(info), 1)
5171da177e4SLinus Torvalds 
5181da177e4SLinus Torvalds #endif /* CONFIG_NET_EMATCH */
5191da177e4SLinus Torvalds 
tcf_get_base_ptr(struct sk_buff * skb,int layer)5201da177e4SLinus Torvalds static inline unsigned char * tcf_get_base_ptr(struct sk_buff *skb, int layer)
5211da177e4SLinus Torvalds {
5221da177e4SLinus Torvalds 	switch (layer) {
5231da177e4SLinus Torvalds 		case TCF_LAYER_LINK:
524d3303a65SWolfgang Bumiller 			return skb_mac_header(skb);
5251da177e4SLinus Torvalds 		case TCF_LAYER_NETWORK:
526d56f90a7SArnaldo Carvalho de Melo 			return skb_network_header(skb);
5271da177e4SLinus Torvalds 		case TCF_LAYER_TRANSPORT:
5289c70220bSArnaldo Carvalho de Melo 			return skb_transport_header(skb);
5291da177e4SLinus Torvalds 	}
5301da177e4SLinus Torvalds 
5311da177e4SLinus Torvalds 	return NULL;
5321da177e4SLinus Torvalds }
5331da177e4SLinus Torvalds 
tcf_valid_offset(const struct sk_buff * skb,const unsigned char * ptr,const int len)534eddc9ec5SArnaldo Carvalho de Melo static inline int tcf_valid_offset(const struct sk_buff *skb,
535eddc9ec5SArnaldo Carvalho de Melo 				   const unsigned char *ptr, const int len)
5361da177e4SLinus Torvalds {
537da521b2cSDavid S. Miller 	return likely((ptr + len) <= skb_tail_pointer(skb) &&
538da521b2cSDavid S. Miller 		      ptr >= skb->head &&
539da521b2cSDavid S. Miller 		      (ptr <= (ptr + len)));
5401da177e4SLinus Torvalds }
5411da177e4SLinus Torvalds 
5421da177e4SLinus Torvalds static inline int
tcf_change_indev(struct net * net,struct nlattr * indev_tlv,struct netlink_ext_ack * extack)5431057c55fSAlexander Aring tcf_change_indev(struct net *net, struct nlattr *indev_tlv,
5441057c55fSAlexander Aring 		 struct netlink_ext_ack *extack)
5451da177e4SLinus Torvalds {
5462519a602SWANG Cong 	char indev[IFNAMSIZ];
547c01003c2SPatrick McHardy 	struct net_device *dev;
548c01003c2SPatrick McHardy 
549872f6903SFrancis Laniel 	if (nla_strscpy(indev, indev_tlv, IFNAMSIZ) < 0) {
550e4a58ef3SGuillaume Nault 		NL_SET_ERR_MSG_ATTR(extack, indev_tlv,
551e4a58ef3SGuillaume Nault 				    "Interface name too long");
5522519a602SWANG Cong 		return -EINVAL;
5531057c55fSAlexander Aring 	}
5542519a602SWANG Cong 	dev = __dev_get_by_name(net, indev);
555e4a58ef3SGuillaume Nault 	if (!dev) {
556e4a58ef3SGuillaume Nault 		NL_SET_ERR_MSG_ATTR(extack, indev_tlv,
557e4a58ef3SGuillaume Nault 				    "Network device not found");
5582519a602SWANG Cong 		return -ENODEV;
559e4a58ef3SGuillaume Nault 	}
5602519a602SWANG Cong 	return dev->ifindex;
5611da177e4SLinus Torvalds }
5621da177e4SLinus Torvalds 
5632519a602SWANG Cong static inline bool
tcf_match_indev(struct sk_buff * skb,int ifindex)5642519a602SWANG Cong tcf_match_indev(struct sk_buff *skb, int ifindex)
5652519a602SWANG Cong {
5662519a602SWANG Cong 	if (!ifindex)
5672519a602SWANG Cong 		return true;
5682519a602SWANG Cong 	if  (!skb->skb_iif)
5692519a602SWANG Cong 		return false;
5702519a602SWANG Cong 	return ifindex == skb->skb_iif;
5711da177e4SLinus Torvalds }
5721da177e4SLinus Torvalds 
5739c1c0e12SBaowen Zheng int tc_setup_offload_action(struct flow_action *flow_action,
574c2ccf84eSIdo Schimmel 			    const struct tcf_exts *exts,
575c2ccf84eSIdo Schimmel 			    struct netlink_ext_ack *extack);
5769c1c0e12SBaowen Zheng void tc_cleanup_offload_action(struct flow_action *flow_action);
5778cbfe939SBaowen Zheng int tc_setup_action(struct flow_action *flow_action,
578c2ccf84eSIdo Schimmel 		    struct tc_action *actions[],
57980cd22c3SPaul Blakey 		    u32 miss_cookie_base,
580c2ccf84eSIdo Schimmel 		    struct netlink_ext_ack *extack);
5815a6ff4b1SVlad Buslov 
582aeb3fecdSCong Wang int tc_setup_cb_call(struct tcf_block *block, enum tc_setup_type type,
58340119211SVlad Buslov 		     void *type_data, bool err_stop, bool rtnl_held);
58440119211SVlad Buslov int tc_setup_cb_add(struct tcf_block *block, struct tcf_proto *tp,
58540119211SVlad Buslov 		    enum tc_setup_type type, void *type_data, bool err_stop,
58640119211SVlad Buslov 		    u32 *flags, unsigned int *in_hw_count, bool rtnl_held);
58740119211SVlad Buslov int tc_setup_cb_replace(struct tcf_block *block, struct tcf_proto *tp,
58840119211SVlad Buslov 			enum tc_setup_type type, void *type_data, bool err_stop,
58940119211SVlad Buslov 			u32 *old_flags, unsigned int *old_in_hw_count,
59040119211SVlad Buslov 			u32 *new_flags, unsigned int *new_in_hw_count,
59140119211SVlad Buslov 			bool rtnl_held);
59240119211SVlad Buslov int tc_setup_cb_destroy(struct tcf_block *block, struct tcf_proto *tp,
59340119211SVlad Buslov 			enum tc_setup_type type, void *type_data, bool err_stop,
59440119211SVlad Buslov 			u32 *flags, unsigned int *in_hw_count, bool rtnl_held);
59540119211SVlad Buslov int tc_setup_cb_reoffload(struct tcf_block *block, struct tcf_proto *tp,
59640119211SVlad Buslov 			  bool add, flow_setup_cb_t *cb,
59740119211SVlad Buslov 			  enum tc_setup_type type, void *type_data,
59840119211SVlad Buslov 			  void *cb_priv, u32 *flags, unsigned int *in_hw_count);
599e3ab786bSPablo Neira Ayuso unsigned int tcf_exts_num_actions(struct tcf_exts *exts);
600717503b9SJiri Pirko 
6013625750fSPetr Machata #ifdef CONFIG_NET_CLS_ACT
6023625750fSPetr Machata int tcf_qevent_init(struct tcf_qevent *qe, struct Qdisc *sch,
6033625750fSPetr Machata 		    enum flow_block_binder_type binder_type,
6043625750fSPetr Machata 		    struct nlattr *block_index_attr,
6053625750fSPetr Machata 		    struct netlink_ext_ack *extack);
6063625750fSPetr Machata void tcf_qevent_destroy(struct tcf_qevent *qe, struct Qdisc *sch);
6073625750fSPetr Machata int tcf_qevent_validate_change(struct tcf_qevent *qe, struct nlattr *block_index_attr,
6083625750fSPetr Machata 			       struct netlink_ext_ack *extack);
6093625750fSPetr Machata struct sk_buff *tcf_qevent_handle(struct tcf_qevent *qe, struct Qdisc *sch, struct sk_buff *skb,
61055f656cdSPetr Machata 				  struct sk_buff **to_free, int *ret);
6113625750fSPetr Machata int tcf_qevent_dump(struct sk_buff *skb, int attr_name, struct tcf_qevent *qe);
6123625750fSPetr Machata #else
tcf_qevent_init(struct tcf_qevent * qe,struct Qdisc * sch,enum flow_block_binder_type binder_type,struct nlattr * block_index_attr,struct netlink_ext_ack * extack)6133625750fSPetr Machata static inline int tcf_qevent_init(struct tcf_qevent *qe, struct Qdisc *sch,
6143625750fSPetr Machata 				  enum flow_block_binder_type binder_type,
6153625750fSPetr Machata 				  struct nlattr *block_index_attr,
6163625750fSPetr Machata 				  struct netlink_ext_ack *extack)
6173625750fSPetr Machata {
6183625750fSPetr Machata 	return 0;
6193625750fSPetr Machata }
6203625750fSPetr Machata 
tcf_qevent_destroy(struct tcf_qevent * qe,struct Qdisc * sch)6213625750fSPetr Machata static inline void tcf_qevent_destroy(struct tcf_qevent *qe, struct Qdisc *sch)
6223625750fSPetr Machata {
6233625750fSPetr Machata }
6243625750fSPetr Machata 
tcf_qevent_validate_change(struct tcf_qevent * qe,struct nlattr * block_index_attr,struct netlink_ext_ack * extack)6253625750fSPetr Machata static inline int tcf_qevent_validate_change(struct tcf_qevent *qe, struct nlattr *block_index_attr,
6263625750fSPetr Machata 					     struct netlink_ext_ack *extack)
6273625750fSPetr Machata {
6283625750fSPetr Machata 	return 0;
6293625750fSPetr Machata }
6303625750fSPetr Machata 
6313625750fSPetr Machata static inline struct sk_buff *
tcf_qevent_handle(struct tcf_qevent * qe,struct Qdisc * sch,struct sk_buff * skb,struct sk_buff ** to_free,int * ret)6323625750fSPetr Machata tcf_qevent_handle(struct tcf_qevent *qe, struct Qdisc *sch, struct sk_buff *skb,
63355f656cdSPetr Machata 		  struct sk_buff **to_free, int *ret)
6343625750fSPetr Machata {
6353625750fSPetr Machata 	return skb;
6363625750fSPetr Machata }
6373625750fSPetr Machata 
tcf_qevent_dump(struct sk_buff * skb,int attr_name,struct tcf_qevent * qe)6383625750fSPetr Machata static inline int tcf_qevent_dump(struct sk_buff *skb, int attr_name, struct tcf_qevent *qe)
6393625750fSPetr Machata {
6403625750fSPetr Machata 	return 0;
6413625750fSPetr Machata }
6423625750fSPetr Machata #endif
6433625750fSPetr Machata 
644a1b7c5fdSJohn Fastabend struct tc_cls_u32_knode {
645a1b7c5fdSJohn Fastabend 	struct tcf_exts *exts;
646068ceb35SJakub Kicinski 	struct tcf_result *res;
647e014860eSJohn Fastabend 	struct tc_u32_sel *sel;
648a1b7c5fdSJohn Fastabend 	u32 handle;
649a1b7c5fdSJohn Fastabend 	u32 val;
650a1b7c5fdSJohn Fastabend 	u32 mask;
651a1b7c5fdSJohn Fastabend 	u32 link_handle;
652e014860eSJohn Fastabend 	u8 fshift;
653a1b7c5fdSJohn Fastabend };
654a1b7c5fdSJohn Fastabend 
655a1b7c5fdSJohn Fastabend struct tc_cls_u32_hnode {
656a1b7c5fdSJohn Fastabend 	u32 handle;
657a1b7c5fdSJohn Fastabend 	u32 prio;
658a1b7c5fdSJohn Fastabend 	unsigned int divisor;
659a1b7c5fdSJohn Fastabend };
660a1b7c5fdSJohn Fastabend 
661a1b7c5fdSJohn Fastabend enum tc_clsu32_command {
662a1b7c5fdSJohn Fastabend 	TC_CLSU32_NEW_KNODE,
663a1b7c5fdSJohn Fastabend 	TC_CLSU32_REPLACE_KNODE,
664a1b7c5fdSJohn Fastabend 	TC_CLSU32_DELETE_KNODE,
665a1b7c5fdSJohn Fastabend 	TC_CLSU32_NEW_HNODE,
666a1b7c5fdSJohn Fastabend 	TC_CLSU32_REPLACE_HNODE,
667a1b7c5fdSJohn Fastabend 	TC_CLSU32_DELETE_HNODE,
668a1b7c5fdSJohn Fastabend };
669a1b7c5fdSJohn Fastabend 
670a1b7c5fdSJohn Fastabend struct tc_cls_u32_offload {
671f9e30088SPablo Neira Ayuso 	struct flow_cls_common_offload common;
672a1b7c5fdSJohn Fastabend 	/* knode values */
673a1b7c5fdSJohn Fastabend 	enum tc_clsu32_command command;
674a1b7c5fdSJohn Fastabend 	union {
675a1b7c5fdSJohn Fastabend 		struct tc_cls_u32_knode knode;
676a1b7c5fdSJohn Fastabend 		struct tc_cls_u32_hnode hnode;
677a1b7c5fdSJohn Fastabend 	};
678a1b7c5fdSJohn Fastabend };
679a1b7c5fdSJohn Fastabend 
tc_can_offload(const struct net_device * dev)6807b06e8aeSJiri Pirko static inline bool tc_can_offload(const struct net_device *dev)
6816843e7a2SJohn Fastabend {
68270b5aee4SJiri Pirko 	return dev->features & NETIF_F_HW_TC;
6836843e7a2SJohn Fastabend }
6846843e7a2SJohn Fastabend 
tc_can_offload_extack(const struct net_device * dev,struct netlink_ext_ack * extack)685f9eda14fSQuentin Monnet static inline bool tc_can_offload_extack(const struct net_device *dev,
686f9eda14fSQuentin Monnet 					 struct netlink_ext_ack *extack)
687f9eda14fSQuentin Monnet {
688f9eda14fSQuentin Monnet 	bool can = tc_can_offload(dev);
689f9eda14fSQuentin Monnet 
690f9eda14fSQuentin Monnet 	if (!can)
691f9eda14fSQuentin Monnet 		NL_SET_ERR_MSG(extack, "TC offload is disabled on net device");
692f9eda14fSQuentin Monnet 
693f9eda14fSQuentin Monnet 	return can;
694f9eda14fSQuentin Monnet }
695f9eda14fSQuentin Monnet 
696878db9f0SJakub Kicinski static inline bool
tc_cls_can_offload_and_chain0(const struct net_device * dev,struct flow_cls_common_offload * common)697878db9f0SJakub Kicinski tc_cls_can_offload_and_chain0(const struct net_device *dev,
698f9e30088SPablo Neira Ayuso 			      struct flow_cls_common_offload *common)
699878db9f0SJakub Kicinski {
700878db9f0SJakub Kicinski 	if (!tc_can_offload_extack(dev, common->extack))
701878db9f0SJakub Kicinski 		return false;
702878db9f0SJakub Kicinski 	if (common->chain_index) {
703878db9f0SJakub Kicinski 		NL_SET_ERR_MSG(common->extack,
704878db9f0SJakub Kicinski 			       "Driver supports only offload of chain 0");
705878db9f0SJakub Kicinski 		return false;
706878db9f0SJakub Kicinski 	}
707878db9f0SJakub Kicinski 	return true;
708878db9f0SJakub Kicinski }
709878db9f0SJakub Kicinski 
tc_skip_hw(u32 flags)71055330f05SHadar Hen Zion static inline bool tc_skip_hw(u32 flags)
71155330f05SHadar Hen Zion {
71255330f05SHadar Hen Zion 	return (flags & TCA_CLS_FLAGS_SKIP_HW) ? true : false;
71355330f05SHadar Hen Zion }
71455330f05SHadar Hen Zion 
tc_skip_sw(u32 flags)715d34e3e18SSamudrala, Sridhar static inline bool tc_skip_sw(u32 flags)
716d34e3e18SSamudrala, Sridhar {
717d34e3e18SSamudrala, Sridhar 	return (flags & TCA_CLS_FLAGS_SKIP_SW) ? true : false;
718d34e3e18SSamudrala, Sridhar }
719d34e3e18SSamudrala, Sridhar 
720d34e3e18SSamudrala, Sridhar /* SKIP_HW and SKIP_SW are mutually exclusive flags. */
tc_flags_valid(u32 flags)721d34e3e18SSamudrala, Sridhar static inline bool tc_flags_valid(u32 flags)
722d34e3e18SSamudrala, Sridhar {
72381c7288bSMarcelo Ricardo Leitner 	if (flags & ~(TCA_CLS_FLAGS_SKIP_HW | TCA_CLS_FLAGS_SKIP_SW |
72481c7288bSMarcelo Ricardo Leitner 		      TCA_CLS_FLAGS_VERBOSE))
725d34e3e18SSamudrala, Sridhar 		return false;
726d34e3e18SSamudrala, Sridhar 
72781c7288bSMarcelo Ricardo Leitner 	flags &= TCA_CLS_FLAGS_SKIP_HW | TCA_CLS_FLAGS_SKIP_SW;
728d34e3e18SSamudrala, Sridhar 	if (!(flags ^ (TCA_CLS_FLAGS_SKIP_HW | TCA_CLS_FLAGS_SKIP_SW)))
729d34e3e18SSamudrala, Sridhar 		return false;
730d34e3e18SSamudrala, Sridhar 
731d34e3e18SSamudrala, Sridhar 	return true;
732d34e3e18SSamudrala, Sridhar }
733d34e3e18SSamudrala, Sridhar 
tc_in_hw(u32 flags)734e696028aSOr Gerlitz static inline bool tc_in_hw(u32 flags)
735e696028aSOr Gerlitz {
736e696028aSOr Gerlitz 	return (flags & TCA_CLS_FLAGS_IN_HW) ? true : false;
737e696028aSOr Gerlitz }
738e696028aSOr Gerlitz 
73934832e1cSJakub Kicinski static inline void
tc_cls_common_offload_init(struct flow_cls_common_offload * cls_common,const struct tcf_proto * tp,u32 flags,struct netlink_ext_ack * extack)740f9e30088SPablo Neira Ayuso tc_cls_common_offload_init(struct flow_cls_common_offload *cls_common,
74134832e1cSJakub Kicinski 			   const struct tcf_proto *tp, u32 flags,
74234832e1cSJakub Kicinski 			   struct netlink_ext_ack *extack)
74334832e1cSJakub Kicinski {
74434832e1cSJakub Kicinski 	cls_common->chain_index = tp->chain->index;
74534832e1cSJakub Kicinski 	cls_common->protocol = tp->protocol;
746ef01adaeSPablo Neira Ayuso 	cls_common->prio = tp->prio >> 16;
74781c7288bSMarcelo Ricardo Leitner 	if (tc_skip_sw(flags) || flags & TCA_CLS_FLAGS_VERBOSE)
74834832e1cSJakub Kicinski 		cls_common->extack = extack;
74934832e1cSJakub Kicinski }
75034832e1cSJakub Kicinski 
7519453d45eSVlad Buslov #if IS_ENABLED(CONFIG_NET_TC_SKB_EXT)
tc_skb_ext_alloc(struct sk_buff * skb)7529453d45eSVlad Buslov static inline struct tc_skb_ext *tc_skb_ext_alloc(struct sk_buff *skb)
7539453d45eSVlad Buslov {
7549453d45eSVlad Buslov 	struct tc_skb_ext *tc_skb_ext = skb_ext_add(skb, TC_SKB_EXT);
7559453d45eSVlad Buslov 
7569453d45eSVlad Buslov 	if (tc_skb_ext)
7579453d45eSVlad Buslov 		memset(tc_skb_ext, 0, sizeof(*tc_skb_ext));
7589453d45eSVlad Buslov 	return tc_skb_ext;
7599453d45eSVlad Buslov }
7609453d45eSVlad Buslov #endif
7619453d45eSVlad Buslov 
762b87f7936SYotam Gigi enum tc_matchall_command {
763b87f7936SYotam Gigi 	TC_CLSMATCHALL_REPLACE,
764b87f7936SYotam Gigi 	TC_CLSMATCHALL_DESTROY,
765b7fe4ab8SPieter Jansen van Vuuren 	TC_CLSMATCHALL_STATS,
766b87f7936SYotam Gigi };
767b87f7936SYotam Gigi 
768b87f7936SYotam Gigi struct tc_cls_matchall_offload {
769f9e30088SPablo Neira Ayuso 	struct flow_cls_common_offload common;
770b87f7936SYotam Gigi 	enum tc_matchall_command command;
771f00cbf19SPieter Jansen van Vuuren 	struct flow_rule *rule;
772b7fe4ab8SPieter Jansen van Vuuren 	struct flow_stats stats;
7735246c896SOz Shlomo 	bool use_act_stats;
774b87f7936SYotam Gigi 	unsigned long cookie;
775b87f7936SYotam Gigi };
776b87f7936SYotam Gigi 
777332ae8e2SJakub Kicinski enum tc_clsbpf_command {
778102740bdSJakub Kicinski 	TC_CLSBPF_OFFLOAD,
77968d64063SJakub Kicinski 	TC_CLSBPF_STATS,
780332ae8e2SJakub Kicinski };
781332ae8e2SJakub Kicinski 
782332ae8e2SJakub Kicinski struct tc_cls_bpf_offload {
783f9e30088SPablo Neira Ayuso 	struct flow_cls_common_offload common;
784332ae8e2SJakub Kicinski 	enum tc_clsbpf_command command;
785332ae8e2SJakub Kicinski 	struct tcf_exts *exts;
786332ae8e2SJakub Kicinski 	struct bpf_prog *prog;
787102740bdSJakub Kicinski 	struct bpf_prog *oldprog;
788332ae8e2SJakub Kicinski 	const char *name;
789332ae8e2SJakub Kicinski 	bool exts_integrated;
790332ae8e2SJakub Kicinski };
791332ae8e2SJakub Kicinski 
7921045ba77SJamal Hadi Salim /* This structure holds cookie structure that is passed from user
7931045ba77SJamal Hadi Salim  * to the kernel for actions and classifiers
7941045ba77SJamal Hadi Salim  */
7951045ba77SJamal Hadi Salim struct tc_cookie {
7961045ba77SJamal Hadi Salim 	u8  *data;
7971045ba77SJamal Hadi Salim 	u32 len;
798eec94fdbSVlad Buslov 	struct rcu_head rcu;
7991045ba77SJamal Hadi Salim };
800602f3bafSNogah Frankel 
801f34b4aacSNogah Frankel struct tc_qopt_offload_stats {
80250dc9a85SAhmed S. Darwish 	struct gnet_stats_basic_sync *bstats;
803f34b4aacSNogah Frankel 	struct gnet_stats_queue *qstats;
804f34b4aacSNogah Frankel };
805f34b4aacSNogah Frankel 
806f971b132SJakub Kicinski enum tc_mq_command {
807f971b132SJakub Kicinski 	TC_MQ_CREATE,
808f971b132SJakub Kicinski 	TC_MQ_DESTROY,
80947c669a4SJakub Kicinski 	TC_MQ_STATS,
810d577a3d2SJakub Kicinski 	TC_MQ_GRAFT,
811d577a3d2SJakub Kicinski };
812d577a3d2SJakub Kicinski 
813d577a3d2SJakub Kicinski struct tc_mq_opt_offload_graft_params {
814d577a3d2SJakub Kicinski 	unsigned long queue;
815d577a3d2SJakub Kicinski 	u32 child_handle;
816f971b132SJakub Kicinski };
817f971b132SJakub Kicinski 
818f971b132SJakub Kicinski struct tc_mq_qopt_offload {
819f971b132SJakub Kicinski 	enum tc_mq_command command;
820f971b132SJakub Kicinski 	u32 handle;
821d577a3d2SJakub Kicinski 	union {
82247c669a4SJakub Kicinski 		struct tc_qopt_offload_stats stats;
823d577a3d2SJakub Kicinski 		struct tc_mq_opt_offload_graft_params graft_params;
824d577a3d2SJakub Kicinski 	};
825f971b132SJakub Kicinski };
826f971b132SJakub Kicinski 
827d03b195bSMaxim Mikityanskiy enum tc_htb_command {
828d03b195bSMaxim Mikityanskiy 	/* Root */
829d03b195bSMaxim Mikityanskiy 	TC_HTB_CREATE, /* Initialize HTB offload. */
830d03b195bSMaxim Mikityanskiy 	TC_HTB_DESTROY, /* Destroy HTB offload. */
831d03b195bSMaxim Mikityanskiy 
832d03b195bSMaxim Mikityanskiy 	/* Classes */
833d03b195bSMaxim Mikityanskiy 	/* Allocate qid and create leaf. */
834d03b195bSMaxim Mikityanskiy 	TC_HTB_LEAF_ALLOC_QUEUE,
835d03b195bSMaxim Mikityanskiy 	/* Convert leaf to inner, preserve and return qid, create new leaf. */
836d03b195bSMaxim Mikityanskiy 	TC_HTB_LEAF_TO_INNER,
837d03b195bSMaxim Mikityanskiy 	/* Delete leaf, while siblings remain. */
838d03b195bSMaxim Mikityanskiy 	TC_HTB_LEAF_DEL,
839d03b195bSMaxim Mikityanskiy 	/* Delete leaf, convert parent to leaf, preserving qid. */
840d03b195bSMaxim Mikityanskiy 	TC_HTB_LEAF_DEL_LAST,
841d03b195bSMaxim Mikityanskiy 	/* TC_HTB_LEAF_DEL_LAST, but delete driver data on hardware errors. */
842d03b195bSMaxim Mikityanskiy 	TC_HTB_LEAF_DEL_LAST_FORCE,
843d03b195bSMaxim Mikityanskiy 	/* Modify parameters of a node. */
844d03b195bSMaxim Mikityanskiy 	TC_HTB_NODE_MODIFY,
845d03b195bSMaxim Mikityanskiy 
846d03b195bSMaxim Mikityanskiy 	/* Class qdisc */
847d03b195bSMaxim Mikityanskiy 	TC_HTB_LEAF_QUERY_QUEUE, /* Query qid by classid. */
848d03b195bSMaxim Mikityanskiy };
849d03b195bSMaxim Mikityanskiy 
850d03b195bSMaxim Mikityanskiy struct tc_htb_qopt_offload {
851d03b195bSMaxim Mikityanskiy 	struct netlink_ext_ack *extack;
852d03b195bSMaxim Mikityanskiy 	enum tc_htb_command command;
853d03b195bSMaxim Mikityanskiy 	u32 parent_classid;
854ca49bfd9SMaxim Mikityanskiy 	u16 classid;
855d03b195bSMaxim Mikityanskiy 	u16 qid;
856*9fe63d5fSNaveen Mamindlapalli 	u32 quantum;
857d03b195bSMaxim Mikityanskiy 	u64 rate;
858d03b195bSMaxim Mikityanskiy 	u64 ceil;
85912e7789aSNaveen Mamindlapalli 	u8 prio;
860d03b195bSMaxim Mikityanskiy };
861d03b195bSMaxim Mikityanskiy 
862d03b195bSMaxim Mikityanskiy #define TC_HTB_CLASSID_ROOT U32_MAX
863d03b195bSMaxim Mikityanskiy 
864602f3bafSNogah Frankel enum tc_red_command {
865602f3bafSNogah Frankel 	TC_RED_REPLACE,
866602f3bafSNogah Frankel 	TC_RED_DESTROY,
867602f3bafSNogah Frankel 	TC_RED_STATS,
868602f3bafSNogah Frankel 	TC_RED_XSTATS,
869bf2a752bSJakub Kicinski 	TC_RED_GRAFT,
870602f3bafSNogah Frankel };
871602f3bafSNogah Frankel 
872602f3bafSNogah Frankel struct tc_red_qopt_offload_params {
873602f3bafSNogah Frankel 	u32 min;
874602f3bafSNogah Frankel 	u32 max;
875602f3bafSNogah Frankel 	u32 probability;
876c0b7490bSJakub Kicinski 	u32 limit;
877602f3bafSNogah Frankel 	bool is_ecn;
878190852a5SJakub Kicinski 	bool is_harddrop;
8790a7fad23SPetr Machata 	bool is_nodrop;
880416ef9b1SJakub Kicinski 	struct gnet_stats_queue *qstats;
881602f3bafSNogah Frankel };
882602f3bafSNogah Frankel 
883602f3bafSNogah Frankel struct tc_red_qopt_offload {
884602f3bafSNogah Frankel 	enum tc_red_command command;
885602f3bafSNogah Frankel 	u32 handle;
886602f3bafSNogah Frankel 	u32 parent;
887602f3bafSNogah Frankel 	union {
888602f3bafSNogah Frankel 		struct tc_red_qopt_offload_params set;
889f34b4aacSNogah Frankel 		struct tc_qopt_offload_stats stats;
890602f3bafSNogah Frankel 		struct red_stats *xstats;
891bf2a752bSJakub Kicinski 		u32 child_handle;
892602f3bafSNogah Frankel 	};
893602f3bafSNogah Frankel };
894602f3bafSNogah Frankel 
895890d8d23SJakub Kicinski enum tc_gred_command {
896890d8d23SJakub Kicinski 	TC_GRED_REPLACE,
897890d8d23SJakub Kicinski 	TC_GRED_DESTROY,
898e49efd52SJakub Kicinski 	TC_GRED_STATS,
899890d8d23SJakub Kicinski };
900890d8d23SJakub Kicinski 
901890d8d23SJakub Kicinski struct tc_gred_vq_qopt_offload_params {
902890d8d23SJakub Kicinski 	bool present;
903890d8d23SJakub Kicinski 	u32 limit;
904890d8d23SJakub Kicinski 	u32 prio;
905890d8d23SJakub Kicinski 	u32 min;
906890d8d23SJakub Kicinski 	u32 max;
907890d8d23SJakub Kicinski 	bool is_ecn;
908890d8d23SJakub Kicinski 	bool is_harddrop;
909890d8d23SJakub Kicinski 	u32 probability;
910890d8d23SJakub Kicinski 	/* Only need backlog, see struct tc_prio_qopt_offload_params */
911890d8d23SJakub Kicinski 	u32 *backlog;
912890d8d23SJakub Kicinski };
913890d8d23SJakub Kicinski 
914890d8d23SJakub Kicinski struct tc_gred_qopt_offload_params {
915890d8d23SJakub Kicinski 	bool grio_on;
916890d8d23SJakub Kicinski 	bool wred_on;
917890d8d23SJakub Kicinski 	unsigned int dp_cnt;
918890d8d23SJakub Kicinski 	unsigned int dp_def;
919890d8d23SJakub Kicinski 	struct gnet_stats_queue *qstats;
920890d8d23SJakub Kicinski 	struct tc_gred_vq_qopt_offload_params tab[MAX_DPs];
921890d8d23SJakub Kicinski };
922890d8d23SJakub Kicinski 
923e49efd52SJakub Kicinski struct tc_gred_qopt_offload_stats {
92450dc9a85SAhmed S. Darwish 	struct gnet_stats_basic_sync bstats[MAX_DPs];
925e49efd52SJakub Kicinski 	struct gnet_stats_queue qstats[MAX_DPs];
926e49efd52SJakub Kicinski 	struct red_stats *xstats[MAX_DPs];
927e49efd52SJakub Kicinski };
928e49efd52SJakub Kicinski 
929890d8d23SJakub Kicinski struct tc_gred_qopt_offload {
930890d8d23SJakub Kicinski 	enum tc_gred_command command;
931890d8d23SJakub Kicinski 	u32 handle;
932890d8d23SJakub Kicinski 	u32 parent;
933890d8d23SJakub Kicinski 	union {
934890d8d23SJakub Kicinski 		struct tc_gred_qopt_offload_params set;
935e49efd52SJakub Kicinski 		struct tc_gred_qopt_offload_stats stats;
936890d8d23SJakub Kicinski 	};
937890d8d23SJakub Kicinski };
938890d8d23SJakub Kicinski 
9397fdb61b4SNogah Frankel enum tc_prio_command {
9407fdb61b4SNogah Frankel 	TC_PRIO_REPLACE,
9417fdb61b4SNogah Frankel 	TC_PRIO_DESTROY,
9427fdb61b4SNogah Frankel 	TC_PRIO_STATS,
943b9c7a7acSNogah Frankel 	TC_PRIO_GRAFT,
9447fdb61b4SNogah Frankel };
9457fdb61b4SNogah Frankel 
9467fdb61b4SNogah Frankel struct tc_prio_qopt_offload_params {
9477fdb61b4SNogah Frankel 	int bands;
9487fdb61b4SNogah Frankel 	u8 priomap[TC_PRIO_MAX + 1];
9499586a992SPetr Machata 	/* At the point of un-offloading the Qdisc, the reported backlog and
9509586a992SPetr Machata 	 * qlen need to be reduced by the portion that is in HW.
9517fdb61b4SNogah Frankel 	 */
9527fdb61b4SNogah Frankel 	struct gnet_stats_queue *qstats;
9537fdb61b4SNogah Frankel };
9547fdb61b4SNogah Frankel 
955b9c7a7acSNogah Frankel struct tc_prio_qopt_offload_graft_params {
956b9c7a7acSNogah Frankel 	u8 band;
957b9c7a7acSNogah Frankel 	u32 child_handle;
958b9c7a7acSNogah Frankel };
959b9c7a7acSNogah Frankel 
9607fdb61b4SNogah Frankel struct tc_prio_qopt_offload {
9617fdb61b4SNogah Frankel 	enum tc_prio_command command;
9627fdb61b4SNogah Frankel 	u32 handle;
9637fdb61b4SNogah Frankel 	u32 parent;
9647fdb61b4SNogah Frankel 	union {
9657fdb61b4SNogah Frankel 		struct tc_prio_qopt_offload_params replace_params;
9667fdb61b4SNogah Frankel 		struct tc_qopt_offload_stats stats;
967b9c7a7acSNogah Frankel 		struct tc_prio_qopt_offload_graft_params graft_params;
9687fdb61b4SNogah Frankel 	};
9697fdb61b4SNogah Frankel };
970b9c7a7acSNogah Frankel 
97198b0e5f6SJakub Kicinski enum tc_root_command {
97298b0e5f6SJakub Kicinski 	TC_ROOT_GRAFT,
97398b0e5f6SJakub Kicinski };
97498b0e5f6SJakub Kicinski 
97598b0e5f6SJakub Kicinski struct tc_root_qopt_offload {
97698b0e5f6SJakub Kicinski 	enum tc_root_command command;
97798b0e5f6SJakub Kicinski 	u32 handle;
97898b0e5f6SJakub Kicinski 	bool ingress;
97998b0e5f6SJakub Kicinski };
98098b0e5f6SJakub Kicinski 
981d35eb52bSPetr Machata enum tc_ets_command {
982d35eb52bSPetr Machata 	TC_ETS_REPLACE,
983d35eb52bSPetr Machata 	TC_ETS_DESTROY,
984d35eb52bSPetr Machata 	TC_ETS_STATS,
985d35eb52bSPetr Machata 	TC_ETS_GRAFT,
986d35eb52bSPetr Machata };
987d35eb52bSPetr Machata 
988d35eb52bSPetr Machata struct tc_ets_qopt_offload_replace_params {
989d35eb52bSPetr Machata 	unsigned int bands;
990d35eb52bSPetr Machata 	u8 priomap[TC_PRIO_MAX + 1];
991d35eb52bSPetr Machata 	unsigned int quanta[TCQ_ETS_MAX_BANDS];	/* 0 for strict bands. */
992d35eb52bSPetr Machata 	unsigned int weights[TCQ_ETS_MAX_BANDS];
993d35eb52bSPetr Machata 	struct gnet_stats_queue *qstats;
994d35eb52bSPetr Machata };
995d35eb52bSPetr Machata 
996d35eb52bSPetr Machata struct tc_ets_qopt_offload_graft_params {
997d35eb52bSPetr Machata 	u8 band;
998d35eb52bSPetr Machata 	u32 child_handle;
999d35eb52bSPetr Machata };
1000d35eb52bSPetr Machata 
1001d35eb52bSPetr Machata struct tc_ets_qopt_offload {
1002d35eb52bSPetr Machata 	enum tc_ets_command command;
1003d35eb52bSPetr Machata 	u32 handle;
1004d35eb52bSPetr Machata 	u32 parent;
1005d35eb52bSPetr Machata 	union {
1006d35eb52bSPetr Machata 		struct tc_ets_qopt_offload_replace_params replace_params;
1007d35eb52bSPetr Machata 		struct tc_qopt_offload_stats stats;
1008d35eb52bSPetr Machata 		struct tc_ets_qopt_offload_graft_params graft_params;
1009d35eb52bSPetr Machata 	};
1010d35eb52bSPetr Machata };
1011d35eb52bSPetr Machata 
1012ef6aadccSPetr Machata enum tc_tbf_command {
1013ef6aadccSPetr Machata 	TC_TBF_REPLACE,
1014ef6aadccSPetr Machata 	TC_TBF_DESTROY,
1015ef6aadccSPetr Machata 	TC_TBF_STATS,
10166b3efbfaSPetr Machata 	TC_TBF_GRAFT,
1017ef6aadccSPetr Machata };
1018ef6aadccSPetr Machata 
1019ef6aadccSPetr Machata struct tc_tbf_qopt_offload_replace_params {
1020ef6aadccSPetr Machata 	struct psched_ratecfg rate;
1021ef6aadccSPetr Machata 	u32 max_size;
1022ef6aadccSPetr Machata 	struct gnet_stats_queue *qstats;
1023ef6aadccSPetr Machata };
1024ef6aadccSPetr Machata 
1025ef6aadccSPetr Machata struct tc_tbf_qopt_offload {
1026ef6aadccSPetr Machata 	enum tc_tbf_command command;
1027ef6aadccSPetr Machata 	u32 handle;
1028ef6aadccSPetr Machata 	u32 parent;
1029ef6aadccSPetr Machata 	union {
1030ef6aadccSPetr Machata 		struct tc_tbf_qopt_offload_replace_params replace_params;
1031ef6aadccSPetr Machata 		struct tc_qopt_offload_stats stats;
10326b3efbfaSPetr Machata 		u32 child_handle;
1033ef6aadccSPetr Machata 	};
1034ef6aadccSPetr Machata };
1035ef6aadccSPetr Machata 
1036aaca9408SPetr Machata enum tc_fifo_command {
1037aaca9408SPetr Machata 	TC_FIFO_REPLACE,
1038aaca9408SPetr Machata 	TC_FIFO_DESTROY,
1039aaca9408SPetr Machata 	TC_FIFO_STATS,
1040aaca9408SPetr Machata };
1041aaca9408SPetr Machata 
1042aaca9408SPetr Machata struct tc_fifo_qopt_offload {
1043aaca9408SPetr Machata 	enum tc_fifo_command command;
1044aaca9408SPetr Machata 	u32 handle;
1045aaca9408SPetr Machata 	u32 parent;
1046aaca9408SPetr Machata 	union {
1047aaca9408SPetr Machata 		struct tc_qopt_offload_stats stats;
1048aaca9408SPetr Machata 	};
1049aaca9408SPetr Machata };
1050aaca9408SPetr Machata 
105135d39fecSPaul Blakey #ifdef CONFIG_NET_CLS_ACT
105235d39fecSPaul Blakey DECLARE_STATIC_KEY_FALSE(tc_skb_ext_tc);
105335d39fecSPaul Blakey void tc_skb_ext_tc_enable(void);
105435d39fecSPaul Blakey void tc_skb_ext_tc_disable(void);
105535d39fecSPaul Blakey #define tc_skb_ext_tc_enabled() static_branch_unlikely(&tc_skb_ext_tc)
105635d39fecSPaul Blakey #else /* CONFIG_NET_CLS_ACT */
tc_skb_ext_tc_enable(void)105735d39fecSPaul Blakey static inline void tc_skb_ext_tc_enable(void) { }
tc_skb_ext_tc_disable(void)105835d39fecSPaul Blakey static inline void tc_skb_ext_tc_disable(void) { }
105935d39fecSPaul Blakey #define tc_skb_ext_tc_enabled() false
106035d39fecSPaul Blakey #endif
106135d39fecSPaul Blakey 
10621da177e4SLinus Torvalds #endif
1063