WIP FPC-III support
[linux/fpc-iii.git] / include / net / tc_act / tc_police.h
blob6d1e26b709b5a27d5b2571b8dfd9d9fd04304242
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __NET_TC_POLICE_H
3 #define __NET_TC_POLICE_H
5 #include <net/act_api.h>
7 struct tcf_police_params {
8 int tcfp_result;
9 u32 tcfp_ewma_rate;
10 s64 tcfp_burst;
11 u32 tcfp_mtu;
12 s64 tcfp_mtu_ptoks;
13 struct psched_ratecfg rate;
14 bool rate_present;
15 struct psched_ratecfg peak;
16 bool peak_present;
17 struct rcu_head rcu;
20 struct tcf_police {
21 struct tc_action common;
22 struct tcf_police_params __rcu *params;
24 spinlock_t tcfp_lock ____cacheline_aligned_in_smp;
25 s64 tcfp_toks;
26 s64 tcfp_ptoks;
27 s64 tcfp_t_c;
30 #define to_police(pc) ((struct tcf_police *)pc)
32 /* old policer structure from before tc actions */
33 struct tc_police_compat {
34 u32 index;
35 int action;
36 u32 limit;
37 u32 burst;
38 u32 mtu;
39 struct tc_ratespec rate;
40 struct tc_ratespec peakrate;
43 static inline bool is_tcf_police(const struct tc_action *act)
45 #ifdef CONFIG_NET_CLS_ACT
46 if (act->ops && act->ops->id == TCA_ID_POLICE)
47 return true;
48 #endif
49 return false;
52 static inline u64 tcf_police_rate_bytes_ps(const struct tc_action *act)
54 struct tcf_police *police = to_police(act);
55 struct tcf_police_params *params;
57 params = rcu_dereference_protected(police->params,
58 lockdep_is_held(&police->tcf_lock));
59 return params->rate.rate_bytes_ps;
62 static inline u32 tcf_police_burst(const struct tc_action *act)
64 struct tcf_police *police = to_police(act);
65 struct tcf_police_params *params;
66 u32 burst;
68 params = rcu_dereference_protected(police->params,
69 lockdep_is_held(&police->tcf_lock));
72 * "rate" bytes "burst" nanoseconds
73 * ------------ * -------------------
74 * 1 second 2^6 ticks
76 * ------------------------------------
77 * NSEC_PER_SEC nanoseconds
78 * ------------------------
79 * 2^6 ticks
81 * "rate" bytes "burst" nanoseconds 2^6 ticks
82 * = ------------ * ------------------- * ------------------------
83 * 1 second 2^6 ticks NSEC_PER_SEC nanoseconds
85 * "rate" * "burst"
86 * = ---------------- bytes/nanosecond
87 * NSEC_PER_SEC^2
90 * "rate" * "burst"
91 * = ---------------- bytes/second
92 * NSEC_PER_SEC
94 burst = div_u64(params->tcfp_burst * params->rate.rate_bytes_ps,
95 NSEC_PER_SEC);
97 return burst;
100 static inline u32 tcf_police_tcfp_mtu(const struct tc_action *act)
102 struct tcf_police *police = to_police(act);
103 struct tcf_police_params *params;
105 params = rcu_dereference_protected(police->params,
106 lockdep_is_held(&police->tcf_lock));
107 return params->tcfp_mtu;
110 #endif /* __NET_TC_POLICE_H */