xref: /openbmc/linux/include/net/psample.h (revision 762f99f4f3cb41a775b5157dd761217beba65873)
1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
26ae0a628SYotam Gigi #ifndef __NET_PSAMPLE_H
36ae0a628SYotam Gigi #define __NET_PSAMPLE_H
46ae0a628SYotam Gigi 
56ae0a628SYotam Gigi #include <uapi/linux/psample.h>
66ae0a628SYotam Gigi #include <linux/list.h>
76ae0a628SYotam Gigi 
86ae0a628SYotam Gigi struct psample_group {
96ae0a628SYotam Gigi 	struct list_head list;
106ae0a628SYotam Gigi 	struct net *net;
116ae0a628SYotam Gigi 	u32 group_num;
126ae0a628SYotam Gigi 	u32 refcount;
136ae0a628SYotam Gigi 	u32 seq;
14dbf47a2aSVlad Buslov 	struct rcu_head rcu;
156ae0a628SYotam Gigi };
166ae0a628SYotam Gigi 
17a03e99d3SIdo Schimmel struct psample_metadata {
18a03e99d3SIdo Schimmel 	u32 trunc_size;
19a03e99d3SIdo Schimmel 	int in_ifindex;
20a03e99d3SIdo Schimmel 	int out_ifindex;
2107e1a580SIdo Schimmel 	u16 out_tc;
2207e1a580SIdo Schimmel 	u64 out_tc_occ;	/* bytes */
2307e1a580SIdo Schimmel 	u64 latency;	/* nanoseconds */
2407e1a580SIdo Schimmel 	u8 out_tc_valid:1,
2507e1a580SIdo Schimmel 	   out_tc_occ_valid:1,
2607e1a580SIdo Schimmel 	   latency_valid:1,
2707e1a580SIdo Schimmel 	   unused:5;
28a03e99d3SIdo Schimmel };
29a03e99d3SIdo Schimmel 
306ae0a628SYotam Gigi struct psample_group *psample_group_get(struct net *net, u32 group_num);
314a5da47dSVlad Buslov void psample_group_take(struct psample_group *group);
326ae0a628SYotam Gigi void psample_group_put(struct psample_group *group);
336ae0a628SYotam Gigi 
34*beb7f2deSRoi Dayan struct sk_buff;
35*beb7f2deSRoi Dayan 
366ae0a628SYotam Gigi #if IS_ENABLED(CONFIG_PSAMPLE)
376ae0a628SYotam Gigi 
386ae0a628SYotam Gigi void psample_sample_packet(struct psample_group *group, struct sk_buff *skb,
39a03e99d3SIdo Schimmel 			   u32 sample_rate, const struct psample_metadata *md);
406ae0a628SYotam Gigi 
416ae0a628SYotam Gigi #else
426ae0a628SYotam Gigi 
psample_sample_packet(struct psample_group * group,struct sk_buff * skb,u32 sample_rate,const struct psample_metadata * md)436ae0a628SYotam Gigi static inline void psample_sample_packet(struct psample_group *group,
44a03e99d3SIdo Schimmel 					 struct sk_buff *skb, u32 sample_rate,
45a03e99d3SIdo Schimmel 					 const struct psample_metadata *md)
466ae0a628SYotam Gigi {
476ae0a628SYotam Gigi }
486ae0a628SYotam Gigi 
496ae0a628SYotam Gigi #endif
506ae0a628SYotam Gigi 
516ae0a628SYotam Gigi #endif /* __NET_PSAMPLE_H */
52