| 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ | 
|---|---|
| 2 | /* Copyright 2020 NXP */ | 
| 3 | |
| 4 | #ifndef __NET_TC_GATE_H | 
| 5 | #define __NET_TC_GATE_H | 
| 6 | |
| 7 | #include <net/act_api.h> | 
| 8 | #include <linux/tc_act/tc_gate.h> | 
| 9 | |
| 10 | struct action_gate_entry { | 
| 11 | u8 gate_state; | 
| 12 | u32 interval; | 
| 13 | s32 ipv; | 
| 14 | s32 maxoctets; | 
| 15 | }; | 
| 16 | |
| 17 | struct tcfg_gate_entry { | 
| 18 | int index; | 
| 19 | u8 gate_state; | 
| 20 | u32 interval; | 
| 21 | s32 ipv; | 
| 22 | s32 maxoctets; | 
| 23 | struct list_head list; | 
| 24 | }; | 
| 25 | |
| 26 | struct tcf_gate_params { | 
| 27 | s32 tcfg_priority; | 
| 28 | u64 tcfg_basetime; | 
| 29 | u64 tcfg_cycletime; | 
| 30 | u64 tcfg_cycletime_ext; | 
| 31 | u32 tcfg_flags; | 
| 32 | s32 tcfg_clockid; | 
| 33 | size_t num_entries; | 
| 34 | struct list_head entries; | 
| 35 | }; | 
| 36 | |
| 37 | #define GATE_ACT_GATE_OPEN BIT(0) | 
| 38 | #define GATE_ACT_PENDING BIT(1) | 
| 39 | |
| 40 | struct tcf_gate { | 
| 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; | 
| 50 | }; | 
| 51 | |
| 52 | #define to_gate(a) ((struct tcf_gate *)a) | 
| 53 | |
| 54 | static inline s32 tcf_gate_prio(const struct tc_action *a) | 
| 55 | { | 
| 56 | s32 tcfg_prio; | 
| 57 | |
| 58 | tcfg_prio = to_gate(a)->param.tcfg_priority; | 
| 59 | |
| 60 | return tcfg_prio; | 
| 61 | } | 
| 62 | |
| 63 | static inline u64 tcf_gate_basetime(const struct tc_action *a) | 
| 64 | { | 
| 65 | u64 tcfg_basetime; | 
| 66 | |
| 67 | tcfg_basetime = to_gate(a)->param.tcfg_basetime; | 
| 68 | |
| 69 | return tcfg_basetime; | 
| 70 | } | 
| 71 | |
| 72 | static inline u64 tcf_gate_cycletime(const struct tc_action *a) | 
| 73 | { | 
| 74 | u64 tcfg_cycletime; | 
| 75 | |
| 76 | tcfg_cycletime = to_gate(a)->param.tcfg_cycletime; | 
| 77 | |
| 78 | return tcfg_cycletime; | 
| 79 | } | 
| 80 | |
| 81 | static inline u64 tcf_gate_cycletimeext(const struct tc_action *a) | 
| 82 | { | 
| 83 | u64 tcfg_cycletimeext; | 
| 84 | |
| 85 | tcfg_cycletimeext = to_gate(a)->param.tcfg_cycletime_ext; | 
| 86 | |
| 87 | return tcfg_cycletimeext; | 
| 88 | } | 
| 89 | |
| 90 | static inline u32 tcf_gate_num_entries(const struct tc_action *a) | 
| 91 | { | 
| 92 | u32 num_entries; | 
| 93 | |
| 94 | num_entries = to_gate(a)->param.num_entries; | 
| 95 | |
| 96 | return num_entries; | 
| 97 | } | 
| 98 | |
| 99 | static inline struct action_gate_entry | 
| 100 | *tcf_gate_get_list(const struct tc_action *a) | 
| 101 | { | 
| 102 | struct action_gate_entry *oe; | 
| 103 | struct tcf_gate_params *p; | 
| 104 | struct tcfg_gate_entry *entry; | 
| 105 | u32 num_entries; | 
| 106 | int i = 0; | 
| 107 | |
| 108 | p = &to_gate(a)->param; | 
| 109 | num_entries = p->num_entries; | 
| 110 | |
| 111 | list_for_each_entry(entry, &p->entries, list) | 
| 112 | i++; | 
| 113 | |
| 114 | if (i != num_entries) | 
| 115 | return NULL; | 
| 116 | |
| 117 | oe = kcalloc(num_entries, sizeof(*oe), GFP_ATOMIC); | 
| 118 | if (!oe) | 
| 119 | return NULL; | 
| 120 | |
| 121 | i = 0; | 
| 122 | list_for_each_entry(entry, &p->entries, list) { | 
| 123 | oe[i].gate_state = entry->gate_state; | 
| 124 | oe[i].interval = entry->interval; | 
| 125 | oe[i].ipv = entry->ipv; | 
| 126 | oe[i].maxoctets = entry->maxoctets; | 
| 127 | i++; | 
| 128 | } | 
| 129 | |
| 130 | return oe; | 
| 131 | } | 
| 132 | #endif | 
| 133 | 
