tc_gate.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /* Copyright 2020 NXP */
  3. #ifndef __NET_TC_GATE_H
  4. #define __NET_TC_GATE_H
  5. #include <net/act_api.h>
  6. #include <linux/tc_act/tc_gate.h>
  7. struct action_gate_entry {
  8. u8 gate_state;
  9. u32 interval;
  10. s32 ipv;
  11. s32 maxoctets;
  12. };
  13. struct tcfg_gate_entry {
  14. int index;
  15. u8 gate_state;
  16. u32 interval;
  17. s32 ipv;
  18. s32 maxoctets;
  19. struct list_head list;
  20. };
  21. struct tcf_gate_params {
  22. s32 tcfg_priority;
  23. u64 tcfg_basetime;
  24. u64 tcfg_cycletime;
  25. u64 tcfg_cycletime_ext;
  26. u32 tcfg_flags;
  27. s32 tcfg_clockid;
  28. size_t num_entries;
  29. struct list_head entries;
  30. };
  31. #define GATE_ACT_GATE_OPEN BIT(0)
  32. #define GATE_ACT_PENDING BIT(1)
  33. struct tcf_gate {
  34. struct tc_action common;
  35. struct tcf_gate_params param;
  36. u8 current_gate_status;
  37. ktime_t current_close_time;
  38. u32 current_entry_octets;
  39. s32 current_max_octets;
  40. struct tcfg_gate_entry *next_entry;
  41. struct hrtimer hitimer;
  42. enum tk_offsets tk_offset;
  43. };
  44. #define to_gate(a) ((struct tcf_gate *)a)
  45. static inline bool is_tcf_gate(const struct tc_action *a)
  46. {
  47. #ifdef CONFIG_NET_CLS_ACT
  48. if (a->ops && a->ops->id == TCA_ID_GATE)
  49. return true;
  50. #endif
  51. return false;
  52. }
  53. static inline s32 tcf_gate_prio(const struct tc_action *a)
  54. {
  55. s32 tcfg_prio;
  56. tcfg_prio = to_gate(a)->param.tcfg_priority;
  57. return tcfg_prio;
  58. }
  59. static inline u64 tcf_gate_basetime(const struct tc_action *a)
  60. {
  61. u64 tcfg_basetime;
  62. tcfg_basetime = to_gate(a)->param.tcfg_basetime;
  63. return tcfg_basetime;
  64. }
  65. static inline u64 tcf_gate_cycletime(const struct tc_action *a)
  66. {
  67. u64 tcfg_cycletime;
  68. tcfg_cycletime = to_gate(a)->param.tcfg_cycletime;
  69. return tcfg_cycletime;
  70. }
  71. static inline u64 tcf_gate_cycletimeext(const struct tc_action *a)
  72. {
  73. u64 tcfg_cycletimeext;
  74. tcfg_cycletimeext = to_gate(a)->param.tcfg_cycletime_ext;
  75. return tcfg_cycletimeext;
  76. }
  77. static inline u32 tcf_gate_num_entries(const struct tc_action *a)
  78. {
  79. u32 num_entries;
  80. num_entries = to_gate(a)->param.num_entries;
  81. return num_entries;
  82. }
  83. static inline struct action_gate_entry
  84. *tcf_gate_get_list(const struct tc_action *a)
  85. {
  86. struct action_gate_entry *oe;
  87. struct tcf_gate_params *p;
  88. struct tcfg_gate_entry *entry;
  89. u32 num_entries;
  90. int i = 0;
  91. p = &to_gate(a)->param;
  92. num_entries = p->num_entries;
  93. list_for_each_entry(entry, &p->entries, list)
  94. i++;
  95. if (i != num_entries)
  96. return NULL;
  97. oe = kcalloc(num_entries, sizeof(*oe), GFP_ATOMIC);
  98. if (!oe)
  99. return NULL;
  100. i = 0;
  101. list_for_each_entry(entry, &p->entries, list) {
  102. oe[i].gate_state = entry->gate_state;
  103. oe[i].interval = entry->interval;
  104. oe[i].ipv = entry->ipv;
  105. oe[i].maxoctets = entry->maxoctets;
  106. i++;
  107. }
  108. return oe;
  109. }
  110. #endif