1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /* Copyright 2020 NXP */
4 #ifndef __NET_TC_GATE_H
5 #define __NET_TC_GATE_H
7 #include <net/act_api.h>
8 #include <linux/tc_act/tc_gate.h>
10 struct action_gate_entry
{
17 struct tcfg_gate_entry
{
23 struct list_head list
;
26 struct tcf_gate_params
{
30 u64 tcfg_cycletime_ext
;
34 struct list_head entries
;
37 #define GATE_ACT_GATE_OPEN BIT(0)
38 #define GATE_ACT_PENDING BIT(1)
41 struct tc_action common
;
42 struct tcf_gate_params param
;
43 u8 current_gate_status
;
44 ktime_t current_close_time
;
45 u32 current_entry_octets
;
46 s32 current_max_octets
;
47 struct tcfg_gate_entry
*next_entry
;
48 struct hrtimer hitimer
;
49 enum tk_offsets tk_offset
;
52 #define to_gate(a) ((struct tcf_gate *)a)
54 static inline bool is_tcf_gate(const struct tc_action
*a
)
56 #ifdef CONFIG_NET_CLS_ACT
57 if (a
->ops
&& a
->ops
->id
== TCA_ID_GATE
)
63 static inline s32
tcf_gate_prio(const struct tc_action
*a
)
67 tcfg_prio
= to_gate(a
)->param
.tcfg_priority
;
72 static inline u64
tcf_gate_basetime(const struct tc_action
*a
)
76 tcfg_basetime
= to_gate(a
)->param
.tcfg_basetime
;
81 static inline u64
tcf_gate_cycletime(const struct tc_action
*a
)
85 tcfg_cycletime
= to_gate(a
)->param
.tcfg_cycletime
;
87 return tcfg_cycletime
;
90 static inline u64
tcf_gate_cycletimeext(const struct tc_action
*a
)
92 u64 tcfg_cycletimeext
;
94 tcfg_cycletimeext
= to_gate(a
)->param
.tcfg_cycletime_ext
;
96 return tcfg_cycletimeext
;
99 static inline u32
tcf_gate_num_entries(const struct tc_action
*a
)
103 num_entries
= to_gate(a
)->param
.num_entries
;
108 static inline struct action_gate_entry
109 *tcf_gate_get_list(const struct tc_action
*a
)
111 struct action_gate_entry
*oe
;
112 struct tcf_gate_params
*p
;
113 struct tcfg_gate_entry
*entry
;
117 p
= &to_gate(a
)->param
;
118 num_entries
= p
->num_entries
;
120 list_for_each_entry(entry
, &p
->entries
, list
)
123 if (i
!= num_entries
)
126 oe
= kcalloc(num_entries
, sizeof(*oe
), GFP_ATOMIC
);
131 list_for_each_entry(entry
, &p
->entries
, list
) {
132 oe
[i
].gate_state
= entry
->gate_state
;
133 oe
[i
].interval
= entry
->interval
;
134 oe
[i
].ipv
= entry
->ipv
;
135 oe
[i
].maxoctets
= entry
->maxoctets
;