18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci#ifndef __NET_GEN_STATS_H
38c2ecf20Sopenharmony_ci#define __NET_GEN_STATS_H
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ci#include <linux/gen_stats.h>
68c2ecf20Sopenharmony_ci#include <linux/socket.h>
78c2ecf20Sopenharmony_ci#include <linux/rtnetlink.h>
88c2ecf20Sopenharmony_ci#include <linux/pkt_sched.h>
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci/* Note: this used to be in include/uapi/linux/gen_stats.h */
118c2ecf20Sopenharmony_cistruct gnet_stats_basic_packed {
128c2ecf20Sopenharmony_ci	__u64	bytes;
138c2ecf20Sopenharmony_ci	__u64	packets;
148c2ecf20Sopenharmony_ci};
158c2ecf20Sopenharmony_ci
168c2ecf20Sopenharmony_cistruct gnet_stats_basic_cpu {
178c2ecf20Sopenharmony_ci	struct gnet_stats_basic_packed bstats;
188c2ecf20Sopenharmony_ci	struct u64_stats_sync syncp;
198c2ecf20Sopenharmony_ci} __aligned(2 * sizeof(u64));
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_cistruct net_rate_estimator;
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_cistruct gnet_dump {
248c2ecf20Sopenharmony_ci	spinlock_t *      lock;
258c2ecf20Sopenharmony_ci	struct sk_buff *  skb;
268c2ecf20Sopenharmony_ci	struct nlattr *   tail;
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_ci	/* Backward compatibility */
298c2ecf20Sopenharmony_ci	int               compat_tc_stats;
308c2ecf20Sopenharmony_ci	int               compat_xstats;
318c2ecf20Sopenharmony_ci	int               padattr;
328c2ecf20Sopenharmony_ci	void *            xstats;
338c2ecf20Sopenharmony_ci	int               xstats_len;
348c2ecf20Sopenharmony_ci	struct tc_stats   tc_stats;
358c2ecf20Sopenharmony_ci};
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_ciint gnet_stats_start_copy(struct sk_buff *skb, int type, spinlock_t *lock,
388c2ecf20Sopenharmony_ci			  struct gnet_dump *d, int padattr);
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_ciint gnet_stats_start_copy_compat(struct sk_buff *skb, int type,
418c2ecf20Sopenharmony_ci				 int tc_stats_type, int xstats_type,
428c2ecf20Sopenharmony_ci				 spinlock_t *lock, struct gnet_dump *d,
438c2ecf20Sopenharmony_ci				 int padattr);
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_ciint gnet_stats_copy_basic(const seqcount_t *running,
468c2ecf20Sopenharmony_ci			  struct gnet_dump *d,
478c2ecf20Sopenharmony_ci			  struct gnet_stats_basic_cpu __percpu *cpu,
488c2ecf20Sopenharmony_ci			  struct gnet_stats_basic_packed *b);
498c2ecf20Sopenharmony_civoid __gnet_stats_copy_basic(const seqcount_t *running,
508c2ecf20Sopenharmony_ci			     struct gnet_stats_basic_packed *bstats,
518c2ecf20Sopenharmony_ci			     struct gnet_stats_basic_cpu __percpu *cpu,
528c2ecf20Sopenharmony_ci			     struct gnet_stats_basic_packed *b);
538c2ecf20Sopenharmony_ciint gnet_stats_copy_basic_hw(const seqcount_t *running,
548c2ecf20Sopenharmony_ci			     struct gnet_dump *d,
558c2ecf20Sopenharmony_ci			     struct gnet_stats_basic_cpu __percpu *cpu,
568c2ecf20Sopenharmony_ci			     struct gnet_stats_basic_packed *b);
578c2ecf20Sopenharmony_ciint gnet_stats_copy_rate_est(struct gnet_dump *d,
588c2ecf20Sopenharmony_ci			     struct net_rate_estimator __rcu **ptr);
598c2ecf20Sopenharmony_ciint gnet_stats_copy_queue(struct gnet_dump *d,
608c2ecf20Sopenharmony_ci			  struct gnet_stats_queue __percpu *cpu_q,
618c2ecf20Sopenharmony_ci			  struct gnet_stats_queue *q, __u32 qlen);
628c2ecf20Sopenharmony_civoid __gnet_stats_copy_queue(struct gnet_stats_queue *qstats,
638c2ecf20Sopenharmony_ci			     const struct gnet_stats_queue __percpu *cpu_q,
648c2ecf20Sopenharmony_ci			     const struct gnet_stats_queue *q, __u32 qlen);
658c2ecf20Sopenharmony_ciint gnet_stats_copy_app(struct gnet_dump *d, void *st, int len);
668c2ecf20Sopenharmony_ci
678c2ecf20Sopenharmony_ciint gnet_stats_finish_copy(struct gnet_dump *d);
688c2ecf20Sopenharmony_ci
698c2ecf20Sopenharmony_ciint gen_new_estimator(struct gnet_stats_basic_packed *bstats,
708c2ecf20Sopenharmony_ci		      struct gnet_stats_basic_cpu __percpu *cpu_bstats,
718c2ecf20Sopenharmony_ci		      struct net_rate_estimator __rcu **rate_est,
728c2ecf20Sopenharmony_ci		      spinlock_t *lock,
738c2ecf20Sopenharmony_ci		      seqcount_t *running, struct nlattr *opt);
748c2ecf20Sopenharmony_civoid gen_kill_estimator(struct net_rate_estimator __rcu **ptr);
758c2ecf20Sopenharmony_ciint gen_replace_estimator(struct gnet_stats_basic_packed *bstats,
768c2ecf20Sopenharmony_ci			  struct gnet_stats_basic_cpu __percpu *cpu_bstats,
778c2ecf20Sopenharmony_ci			  struct net_rate_estimator __rcu **ptr,
788c2ecf20Sopenharmony_ci			  spinlock_t *lock,
798c2ecf20Sopenharmony_ci			  seqcount_t *running, struct nlattr *opt);
808c2ecf20Sopenharmony_cibool gen_estimator_active(struct net_rate_estimator __rcu **ptr);
818c2ecf20Sopenharmony_cibool gen_estimator_read(struct net_rate_estimator __rcu **ptr,
828c2ecf20Sopenharmony_ci			struct gnet_stats_rate_est64 *sample);
838c2ecf20Sopenharmony_ci#endif
84