vcap_api.h 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. /* SPDX-License-Identifier: BSD-3-Clause */
  2. /* Copyright (C) 2022 Microchip Technology Inc. and its subsidiaries.
  3. * Microchip VCAP API
  4. */
  5. #ifndef __VCAP_API__
  6. #define __VCAP_API__
  7. #include <linux/types.h>
  8. #include <linux/list.h>
  9. #include <linux/netdevice.h>
  10. /* Use the generated API model */
  11. #include "vcap_ag_api.h"
  12. #define VCAP_CID_LOOKUP_SIZE 100000 /* Chains in a lookup */
  13. #define VCAP_CID_INGRESS_L0 1000000 /* Ingress Stage 1 Lookup 0 */
  14. #define VCAP_CID_INGRESS_L1 1100000 /* Ingress Stage 1 Lookup 1 */
  15. #define VCAP_CID_INGRESS_L2 1200000 /* Ingress Stage 1 Lookup 2 */
  16. #define VCAP_CID_INGRESS_L3 1300000 /* Ingress Stage 1 Lookup 3 */
  17. #define VCAP_CID_INGRESS_L4 1400000 /* Ingress Stage 1 Lookup 4 */
  18. #define VCAP_CID_INGRESS_L5 1500000 /* Ingress Stage 1 Lookup 5 */
  19. #define VCAP_CID_PREROUTING_IPV6 3000000 /* Prerouting Stage */
  20. #define VCAP_CID_PREROUTING 6000000 /* Prerouting Stage */
  21. #define VCAP_CID_INGRESS_STAGE2_L0 8000000 /* Ingress Stage 2 Lookup 0 */
  22. #define VCAP_CID_INGRESS_STAGE2_L1 8100000 /* Ingress Stage 2 Lookup 1 */
  23. #define VCAP_CID_INGRESS_STAGE2_L2 8200000 /* Ingress Stage 2 Lookup 2 */
  24. #define VCAP_CID_INGRESS_STAGE2_L3 8300000 /* Ingress Stage 2 Lookup 3 */
  25. #define VCAP_CID_EGRESS_L0 10000000 /* Egress Lookup 0 */
  26. #define VCAP_CID_EGRESS_L1 10100000 /* Egress Lookup 1 */
  27. #define VCAP_CID_EGRESS_STAGE2_L0 20000000 /* Egress Stage 2 Lookup 0 */
  28. #define VCAP_CID_EGRESS_STAGE2_L1 20100000 /* Egress Stage 2 Lookup 1 */
  29. /* Known users of the VCAP API */
  30. enum vcap_user {
  31. VCAP_USER_PTP,
  32. VCAP_USER_MRP,
  33. VCAP_USER_CFM,
  34. VCAP_USER_VLAN,
  35. VCAP_USER_QOS,
  36. VCAP_USER_VCAP_UTIL,
  37. VCAP_USER_TC,
  38. VCAP_USER_TC_EXTRA,
  39. /* add new users above here */
  40. /* used to define VCAP_USER_MAX below */
  41. __VCAP_USER_AFTER_LAST,
  42. VCAP_USER_MAX = __VCAP_USER_AFTER_LAST - 1,
  43. };
  44. /* VCAP information used for displaying data */
  45. struct vcap_statistics {
  46. char *name;
  47. int count;
  48. const char * const *keyfield_set_names;
  49. const char * const *actionfield_set_names;
  50. const char * const *keyfield_names;
  51. const char * const *actionfield_names;
  52. };
  53. /* VCAP key/action field type, position and width */
  54. struct vcap_field {
  55. u16 type;
  56. u16 width;
  57. u16 offset;
  58. };
  59. /* VCAP keyset or actionset type and width */
  60. struct vcap_set {
  61. u8 type_id;
  62. u8 sw_per_item;
  63. u8 sw_cnt;
  64. };
  65. /* VCAP typegroup position and bitvalue */
  66. struct vcap_typegroup {
  67. u16 offset;
  68. u16 width;
  69. u16 value;
  70. };
  71. /* VCAP model data */
  72. struct vcap_info {
  73. char *name; /* user-friendly name */
  74. u16 rows; /* number of row in instance */
  75. u16 sw_count; /* maximum subwords used per rule */
  76. u16 sw_width; /* bits per subword in a keyset */
  77. u16 sticky_width; /* sticky bits per rule */
  78. u16 act_width; /* bits per subword in an actionset */
  79. u16 default_cnt; /* number of default rules */
  80. u16 require_cnt_dis; /* not used */
  81. u16 version; /* vcap rtl version */
  82. const struct vcap_set *keyfield_set; /* keysets */
  83. int keyfield_set_size; /* number of keysets */
  84. const struct vcap_set *actionfield_set; /* actionsets */
  85. int actionfield_set_size; /* number of actionsets */
  86. /* map of keys per keyset */
  87. const struct vcap_field **keyfield_set_map;
  88. /* number of entries in the above map */
  89. int *keyfield_set_map_size;
  90. /* map of actions per actionset */
  91. const struct vcap_field **actionfield_set_map;
  92. /* number of entries in the above map */
  93. int *actionfield_set_map_size;
  94. /* map of keyset typegroups per subword size */
  95. const struct vcap_typegroup **keyfield_set_typegroups;
  96. /* map of actionset typegroups per subword size */
  97. const struct vcap_typegroup **actionfield_set_typegroups;
  98. };
  99. enum vcap_field_type {
  100. VCAP_FIELD_BIT,
  101. VCAP_FIELD_U32,
  102. VCAP_FIELD_U48,
  103. VCAP_FIELD_U56,
  104. VCAP_FIELD_U64,
  105. VCAP_FIELD_U72,
  106. VCAP_FIELD_U112,
  107. VCAP_FIELD_U128,
  108. };
  109. /* VCAP rule data towards the VCAP cache */
  110. struct vcap_cache_data {
  111. u32 *keystream;
  112. u32 *maskstream;
  113. u32 *actionstream;
  114. u32 counter;
  115. bool sticky;
  116. };
  117. /* Selects which part of the rule must be updated */
  118. enum vcap_selection {
  119. VCAP_SEL_ENTRY = 0x01,
  120. VCAP_SEL_ACTION = 0x02,
  121. VCAP_SEL_COUNTER = 0x04,
  122. VCAP_SEL_ALL = 0xff,
  123. };
  124. /* Commands towards the VCAP cache */
  125. enum vcap_command {
  126. VCAP_CMD_WRITE = 0,
  127. VCAP_CMD_READ = 1,
  128. VCAP_CMD_MOVE_DOWN = 2,
  129. VCAP_CMD_MOVE_UP = 3,
  130. VCAP_CMD_INITIALIZE = 4,
  131. };
  132. enum vcap_rule_error {
  133. VCAP_ERR_NONE = 0, /* No known error */
  134. VCAP_ERR_NO_ADMIN, /* No admin instance */
  135. VCAP_ERR_NO_NETDEV, /* No netdev instance */
  136. VCAP_ERR_NO_KEYSET_MATCH, /* No keyset matched the rule keys */
  137. VCAP_ERR_NO_ACTIONSET_MATCH, /* No actionset matched the rule actions */
  138. VCAP_ERR_NO_PORT_KEYSET_MATCH, /* No port keyset matched the rule keys */
  139. };
  140. /* Administration of each VCAP instance */
  141. struct vcap_admin {
  142. struct list_head list; /* for insertion in vcap_control */
  143. struct list_head rules; /* list of rules */
  144. struct list_head enabled; /* list of enabled ports */
  145. struct mutex lock; /* control access to rules */
  146. enum vcap_type vtype; /* type of vcap */
  147. int vinst; /* instance number within the same type */
  148. int first_cid; /* first chain id in this vcap */
  149. int last_cid; /* last chain id in this vcap */
  150. int tgt_inst; /* hardware instance number */
  151. int lookups; /* number of lookups in this vcap type */
  152. int lookups_per_instance; /* number of lookups in this instance */
  153. int last_valid_addr; /* top of address range to be used */
  154. int first_valid_addr; /* bottom of address range to be used */
  155. int last_used_addr; /* address of lowest added rule */
  156. bool w32be; /* vcap uses "32bit-word big-endian" encoding */
  157. bool ingress; /* chain traffic direction */
  158. struct vcap_cache_data cache; /* encoded rule data */
  159. };
  160. /* Client supplied VCAP rule data */
  161. struct vcap_rule {
  162. int vcap_chain_id; /* chain used for this rule */
  163. enum vcap_user user; /* rule owner */
  164. u16 priority;
  165. u32 id; /* vcap rule id, must be unique, 0 will auto-generate a value */
  166. u64 cookie; /* used by the client to identify the rule */
  167. struct list_head keyfields; /* list of vcap_client_keyfield */
  168. struct list_head actionfields; /* list of vcap_client_actionfield */
  169. enum vcap_keyfield_set keyset; /* keyset used: may be derived from fields */
  170. enum vcap_actionfield_set actionset; /* actionset used: may be derived from fields */
  171. enum vcap_rule_error exterr; /* extended error - used by TC */
  172. u64 client; /* space for client defined data */
  173. };
  174. /* List of keysets */
  175. struct vcap_keyset_list {
  176. int max; /* size of the keyset list */
  177. int cnt; /* count of keysets actually in the list */
  178. enum vcap_keyfield_set *keysets; /* the list of keysets */
  179. };
  180. /* List of actionsets */
  181. struct vcap_actionset_list {
  182. int max; /* size of the actionset list */
  183. int cnt; /* count of actionsets actually in the list */
  184. enum vcap_actionfield_set *actionsets; /* the list of actionsets */
  185. };
  186. /* Client output printf-like function with destination */
  187. struct vcap_output_print {
  188. __printf(2, 3)
  189. void (*prf)(void *out, const char *fmt, ...);
  190. void *dst;
  191. };
  192. /* Client supplied VCAP callback operations */
  193. struct vcap_operations {
  194. /* validate port keyset operation */
  195. enum vcap_keyfield_set (*validate_keyset)
  196. (struct net_device *ndev,
  197. struct vcap_admin *admin,
  198. struct vcap_rule *rule,
  199. struct vcap_keyset_list *kslist,
  200. u16 l3_proto);
  201. /* add default rule fields for the selected keyset operations */
  202. void (*add_default_fields)
  203. (struct net_device *ndev,
  204. struct vcap_admin *admin,
  205. struct vcap_rule *rule);
  206. /* cache operations */
  207. void (*cache_erase)
  208. (struct vcap_admin *admin);
  209. void (*cache_write)
  210. (struct net_device *ndev,
  211. struct vcap_admin *admin,
  212. enum vcap_selection sel,
  213. u32 idx, u32 count);
  214. void (*cache_read)
  215. (struct net_device *ndev,
  216. struct vcap_admin *admin,
  217. enum vcap_selection sel,
  218. u32 idx,
  219. u32 count);
  220. /* block operations */
  221. void (*init)
  222. (struct net_device *ndev,
  223. struct vcap_admin *admin,
  224. u32 addr,
  225. u32 count);
  226. void (*update)
  227. (struct net_device *ndev,
  228. struct vcap_admin *admin,
  229. enum vcap_command cmd,
  230. enum vcap_selection sel,
  231. u32 addr);
  232. void (*move)
  233. (struct net_device *ndev,
  234. struct vcap_admin *admin,
  235. u32 addr,
  236. int offset,
  237. int count);
  238. /* informational */
  239. int (*port_info)
  240. (struct net_device *ndev,
  241. struct vcap_admin *admin,
  242. struct vcap_output_print *out);
  243. };
  244. /* VCAP API Client control interface */
  245. struct vcap_control {
  246. const struct vcap_operations *ops; /* client supplied operations */
  247. const struct vcap_info *vcaps; /* client supplied vcap models */
  248. const struct vcap_statistics *stats; /* client supplied vcap stats */
  249. struct list_head list; /* list of vcap instances */
  250. };
  251. #endif /* __VCAP_API__ */