tc_gate.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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. struct rcu_head rcu;
  31. };
  32. #define GATE_ACT_GATE_OPEN BIT(0)
  33. #define GATE_ACT_PENDING BIT(1)
  34. struct tcf_gate {
  35. struct tc_action common;
  36. struct tcf_gate_params __rcu *param;
  37. u8 current_gate_status;
  38. ktime_t current_close_time;
  39. u32 current_entry_octets;
  40. s32 current_max_octets;
  41. struct tcfg_gate_entry *next_entry;
  42. struct hrtimer hitimer;
  43. enum tk_offsets tk_offset;
  44. };
  45. #define to_gate(a) ((struct tcf_gate *)a)
  46. static inline struct tcf_gate_params *tcf_gate_params_locked(const struct tc_action *a)
  47. {
  48. struct tcf_gate *gact = to_gate(a);
  49. return rcu_dereference_protected(gact->param,
  50. lockdep_is_held(&gact->tcf_lock));
  51. }
  52. static inline s32 tcf_gate_prio(const struct tc_action *a)
  53. {
  54. struct tcf_gate_params *p;
  55. s32 tcfg_prio;
  56. p = tcf_gate_params_locked(a);
  57. tcfg_prio = p->tcfg_priority;
  58. return tcfg_prio;
  59. }
  60. static inline u64 tcf_gate_basetime(const struct tc_action *a)
  61. {
  62. struct tcf_gate_params *p;
  63. u64 tcfg_basetime;
  64. p = tcf_gate_params_locked(a);
  65. tcfg_basetime = p->tcfg_basetime;
  66. return tcfg_basetime;
  67. }
  68. static inline u64 tcf_gate_cycletime(const struct tc_action *a)
  69. {
  70. struct tcf_gate_params *p;
  71. u64 tcfg_cycletime;
  72. p = tcf_gate_params_locked(a);
  73. tcfg_cycletime = p->tcfg_cycletime;
  74. return tcfg_cycletime;
  75. }
  76. static inline u64 tcf_gate_cycletimeext(const struct tc_action *a)
  77. {
  78. struct tcf_gate_params *p;
  79. u64 tcfg_cycletimeext;
  80. p = tcf_gate_params_locked(a);
  81. tcfg_cycletimeext = p->tcfg_cycletime_ext;
  82. return tcfg_cycletimeext;
  83. }
  84. static inline u32 tcf_gate_num_entries(const struct tc_action *a)
  85. {
  86. struct tcf_gate_params *p;
  87. u32 num_entries;
  88. p = tcf_gate_params_locked(a);
  89. num_entries = p->num_entries;
  90. return num_entries;
  91. }
  92. static inline struct action_gate_entry
  93. *tcf_gate_get_list(const struct tc_action *a)
  94. {
  95. struct action_gate_entry *oe;
  96. struct tcf_gate_params *p;
  97. struct tcfg_gate_entry *entry;
  98. u32 num_entries;
  99. int i = 0;
  100. p = tcf_gate_params_locked(a);
  101. num_entries = p->num_entries;
  102. list_for_each_entry(entry, &p->entries, list)
  103. i++;
  104. if (i != num_entries)
  105. return NULL;
  106. oe = kzalloc_objs(*oe, num_entries, GFP_ATOMIC);
  107. if (!oe)
  108. return NULL;
  109. i = 0;
  110. list_for_each_entry(entry, &p->entries, list) {
  111. oe[i].gate_state = entry->gate_state;
  112. oe[i].interval = entry->interval;
  113. oe[i].ipv = entry->ipv;
  114. oe[i].maxoctets = entry->maxoctets;
  115. i++;
  116. }
  117. return oe;
  118. }
  119. #endif