vcap_api_client.h 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /* Copyright (C) 2022 Microchip Technology Inc. and its subsidiaries.
  3. * Microchip VCAP API
  4. */
  5. #ifndef __VCAP_API_CLIENT__
  6. #define __VCAP_API_CLIENT__
  7. #include <linux/types.h>
  8. #include <linux/list.h>
  9. #include <linux/netdevice.h>
  10. #include <net/flow_offload.h>
  11. #include "vcap_api.h"
  12. /* Client supplied VCAP rule key control part */
  13. struct vcap_client_keyfield_ctrl {
  14. struct list_head list; /* For insertion into a rule */
  15. enum vcap_key_field key;
  16. enum vcap_field_type type;
  17. };
  18. struct vcap_u1_key {
  19. u8 value;
  20. u8 mask;
  21. };
  22. struct vcap_u32_key {
  23. u32 value;
  24. u32 mask;
  25. };
  26. struct vcap_u48_key {
  27. u8 value[6];
  28. u8 mask[6];
  29. };
  30. struct vcap_u56_key {
  31. u8 value[7];
  32. u8 mask[7];
  33. };
  34. struct vcap_u64_key {
  35. u8 value[8];
  36. u8 mask[8];
  37. };
  38. struct vcap_u72_key {
  39. u8 value[9];
  40. u8 mask[9];
  41. };
  42. struct vcap_u112_key {
  43. u8 value[14];
  44. u8 mask[14];
  45. };
  46. struct vcap_u128_key {
  47. u8 value[16];
  48. u8 mask[16];
  49. };
  50. /* Client supplied VCAP rule field data */
  51. struct vcap_client_keyfield_data {
  52. union {
  53. struct vcap_u1_key u1;
  54. struct vcap_u32_key u32;
  55. struct vcap_u48_key u48;
  56. struct vcap_u56_key u56;
  57. struct vcap_u64_key u64;
  58. struct vcap_u72_key u72;
  59. struct vcap_u112_key u112;
  60. struct vcap_u128_key u128;
  61. };
  62. };
  63. /* Client supplied VCAP rule key (value, mask) */
  64. struct vcap_client_keyfield {
  65. struct vcap_client_keyfield_ctrl ctrl;
  66. struct vcap_client_keyfield_data data;
  67. };
  68. /* Client supplied VCAP rule action control part */
  69. struct vcap_client_actionfield_ctrl {
  70. struct list_head list; /* For insertion into a rule */
  71. enum vcap_action_field action;
  72. enum vcap_field_type type;
  73. };
  74. struct vcap_u1_action {
  75. u8 value;
  76. };
  77. struct vcap_u32_action {
  78. u32 value;
  79. };
  80. struct vcap_u48_action {
  81. u8 value[6];
  82. };
  83. struct vcap_u56_action {
  84. u8 value[7];
  85. };
  86. struct vcap_u64_action {
  87. u8 value[8];
  88. };
  89. struct vcap_u72_action {
  90. u8 value[9];
  91. };
  92. struct vcap_u112_action {
  93. u8 value[14];
  94. };
  95. struct vcap_u128_action {
  96. u8 value[16];
  97. };
  98. struct vcap_client_actionfield_data {
  99. union {
  100. struct vcap_u1_action u1;
  101. struct vcap_u32_action u32;
  102. struct vcap_u48_action u48;
  103. struct vcap_u56_action u56;
  104. struct vcap_u64_action u64;
  105. struct vcap_u72_action u72;
  106. struct vcap_u112_action u112;
  107. struct vcap_u128_action u128;
  108. };
  109. };
  110. struct vcap_client_actionfield {
  111. struct vcap_client_actionfield_ctrl ctrl;
  112. struct vcap_client_actionfield_data data;
  113. };
  114. enum vcap_bit {
  115. VCAP_BIT_ANY,
  116. VCAP_BIT_0,
  117. VCAP_BIT_1
  118. };
  119. struct vcap_counter {
  120. u32 value;
  121. bool sticky;
  122. };
  123. /* Enable/Disable the VCAP instance lookups */
  124. int vcap_enable_lookups(struct vcap_control *vctrl, struct net_device *ndev,
  125. int from_cid, int to_cid, unsigned long cookie,
  126. bool enable);
  127. /* VCAP rule operations */
  128. /* Allocate a rule and fill in the basic information */
  129. struct vcap_rule *vcap_alloc_rule(struct vcap_control *vctrl,
  130. struct net_device *ndev,
  131. int vcap_chain_id,
  132. enum vcap_user user,
  133. u16 priority,
  134. u32 id);
  135. /* Free mem of a rule owned by client */
  136. void vcap_free_rule(struct vcap_rule *rule);
  137. /* Validate a rule before adding it to the VCAP */
  138. int vcap_val_rule(struct vcap_rule *rule, u16 l3_proto);
  139. /* Add rule to a VCAP instance */
  140. int vcap_add_rule(struct vcap_rule *rule);
  141. /* Delete rule in a VCAP instance */
  142. int vcap_del_rule(struct vcap_control *vctrl, struct net_device *ndev, u32 id);
  143. /* Make a full copy of an existing rule with a new rule id */
  144. struct vcap_rule *vcap_copy_rule(struct vcap_rule *rule);
  145. /* Get rule from a VCAP instance */
  146. struct vcap_rule *vcap_get_rule(struct vcap_control *vctrl, u32 id);
  147. /* Update existing rule */
  148. int vcap_mod_rule(struct vcap_rule *rule);
  149. /* Update the keyset for the rule */
  150. int vcap_set_rule_set_keyset(struct vcap_rule *rule,
  151. enum vcap_keyfield_set keyset);
  152. /* Update the actionset for the rule */
  153. int vcap_set_rule_set_actionset(struct vcap_rule *rule,
  154. enum vcap_actionfield_set actionset);
  155. /* Set a rule counter id (for certain VCAPs only) */
  156. void vcap_rule_set_counter_id(struct vcap_rule *rule, u32 counter_id);
  157. /* VCAP rule field operations */
  158. int vcap_rule_add_key_bit(struct vcap_rule *rule, enum vcap_key_field key,
  159. enum vcap_bit val);
  160. int vcap_rule_add_key_u32(struct vcap_rule *rule, enum vcap_key_field key,
  161. u32 value, u32 mask);
  162. int vcap_rule_add_key_u48(struct vcap_rule *rule, enum vcap_key_field key,
  163. struct vcap_u48_key *fieldval);
  164. int vcap_rule_add_key_u72(struct vcap_rule *rule, enum vcap_key_field key,
  165. struct vcap_u72_key *fieldval);
  166. int vcap_rule_add_key_u128(struct vcap_rule *rule, enum vcap_key_field key,
  167. struct vcap_u128_key *fieldval);
  168. int vcap_rule_add_action_bit(struct vcap_rule *rule,
  169. enum vcap_action_field action, enum vcap_bit val);
  170. int vcap_rule_add_action_u32(struct vcap_rule *rule,
  171. enum vcap_action_field action, u32 value);
  172. int vcap_rule_add_action_u72(struct vcap_rule *rule, enum vcap_action_field action,
  173. struct vcap_u72_action *fieldval);
  174. /* Get number of rules in a vcap instance lookup chain id range */
  175. int vcap_admin_rule_count(struct vcap_admin *admin, int cid);
  176. /* VCAP rule counter operations */
  177. int vcap_get_rule_count_by_cookie(struct vcap_control *vctrl,
  178. struct vcap_counter *ctr, u64 cookie);
  179. int vcap_rule_set_counter(struct vcap_rule *rule, struct vcap_counter *ctr);
  180. int vcap_rule_get_counter(struct vcap_rule *rule, struct vcap_counter *ctr);
  181. /* VCAP lookup operations */
  182. /* Convert a chain id to a VCAP lookup index */
  183. int vcap_chain_id_to_lookup(struct vcap_admin *admin, int cur_cid);
  184. /* Lookup a vcap instance using chain id */
  185. struct vcap_admin *vcap_find_admin(struct vcap_control *vctrl, int cid);
  186. /* Find information on a key field in a rule */
  187. const struct vcap_field *vcap_lookup_keyfield(struct vcap_rule *rule,
  188. enum vcap_key_field key);
  189. /* Find a rule id with a provided cookie */
  190. int vcap_lookup_rule_by_cookie(struct vcap_control *vctrl, u64 cookie);
  191. /* Calculate the value used for chaining VCAP rules */
  192. int vcap_chain_offset(struct vcap_control *vctrl, int from_cid, int to_cid);
  193. /* Is the next chain id in the following lookup, possible in another VCAP */
  194. bool vcap_is_next_lookup(struct vcap_control *vctrl, int cur_cid, int next_cid);
  195. /* Is this chain id the last lookup of all VCAPs */
  196. bool vcap_is_last_chain(struct vcap_control *vctrl, int cid, bool ingress);
  197. /* Match a list of keys against the keysets available in a vcap type */
  198. bool vcap_rule_find_keysets(struct vcap_rule *rule,
  199. struct vcap_keyset_list *matches);
  200. /* Return the keyset information for the keyset */
  201. const struct vcap_set *vcap_keyfieldset(struct vcap_control *vctrl,
  202. enum vcap_type vt,
  203. enum vcap_keyfield_set keyset);
  204. /* Copy to host byte order */
  205. void vcap_netbytes_copy(u8 *dst, u8 *src, int count);
  206. /* Convert validation error code into tc extack error message */
  207. void vcap_set_tc_exterr(struct flow_cls_offload *fco, struct vcap_rule *vrule);
  208. /* Cleanup a VCAP instance */
  209. int vcap_del_rules(struct vcap_control *vctrl, struct vcap_admin *admin);
  210. /* Add a keyset to a keyset list */
  211. bool vcap_keyset_list_add(struct vcap_keyset_list *keysetlist,
  212. enum vcap_keyfield_set keyset);
  213. /* Drop keys in a keylist and any keys that are not supported by the keyset */
  214. int vcap_filter_rule_keys(struct vcap_rule *rule,
  215. enum vcap_key_field keylist[], int length,
  216. bool drop_unsupported);
  217. /* map keyset id to a string with the keyset name */
  218. const char *vcap_keyset_name(struct vcap_control *vctrl,
  219. enum vcap_keyfield_set keyset);
  220. /* map key field id to a string with the key name */
  221. const char *vcap_keyfield_name(struct vcap_control *vctrl,
  222. enum vcap_key_field key);
  223. /* Modify a 32 bit key field with value and mask in the rule */
  224. int vcap_rule_mod_key_u32(struct vcap_rule *rule, enum vcap_key_field key,
  225. u32 value, u32 mask);
  226. /* Modify a 32 bit action field with value in the rule */
  227. int vcap_rule_mod_action_u32(struct vcap_rule *rule,
  228. enum vcap_action_field action,
  229. u32 value);
  230. /* Get a 32 bit key field value and mask from the rule */
  231. int vcap_rule_get_key_u32(struct vcap_rule *rule, enum vcap_key_field key,
  232. u32 *value, u32 *mask);
  233. /* Remove a key field with value and mask in the rule */
  234. int vcap_rule_rem_key(struct vcap_rule *rule, enum vcap_key_field key);
  235. /* Select the keyset from the list that results in the smallest rule size */
  236. enum vcap_keyfield_set
  237. vcap_select_min_rule_keyset(struct vcap_control *vctrl, enum vcap_type vtype,
  238. struct vcap_keyset_list *kslist);
  239. struct vcap_client_actionfield *
  240. vcap_find_actionfield(struct vcap_rule *rule, enum vcap_action_field act);
  241. #endif /* __VCAP_API_CLIENT__ */