vcap_api_private.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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_PRIVATE__
  6. #define __VCAP_API_PRIVATE__
  7. #include <linux/types.h>
  8. #include "vcap_api.h"
  9. #include "vcap_api_client.h"
  10. #define to_intrule(rule) container_of((rule), struct vcap_rule_internal, data)
  11. enum vcap_rule_state {
  12. VCAP_RS_PERMANENT, /* the rule is always stored in HW */
  13. VCAP_RS_ENABLED, /* enabled in HW but can be disabled */
  14. VCAP_RS_DISABLED, /* disabled (stored in SW) and can be enabled */
  15. };
  16. /* Private VCAP API rule data */
  17. struct vcap_rule_internal {
  18. struct vcap_rule data; /* provided by the client */
  19. struct list_head list; /* the vcap admin list of rules */
  20. struct vcap_admin *admin; /* vcap hw instance */
  21. struct net_device *ndev; /* the interface that the rule applies to */
  22. struct vcap_control *vctrl; /* the client control */
  23. u32 sort_key; /* defines the position in the VCAP */
  24. int keyset_sw; /* subwords in a keyset */
  25. int actionset_sw; /* subwords in an actionset */
  26. int keyset_sw_regs; /* registers in a subword in an keyset */
  27. int actionset_sw_regs; /* registers in a subword in an actionset */
  28. int size; /* the size of the rule: max(entry, action) */
  29. u32 addr; /* address in the VCAP at insertion */
  30. u32 counter_id; /* counter id (if a dedicated counter is available) */
  31. struct vcap_counter counter; /* last read counter value */
  32. enum vcap_rule_state state; /* rule storage state */
  33. };
  34. /* Bit iterator for the VCAP cache streams */
  35. struct vcap_stream_iter {
  36. u32 offset; /* bit offset from the stream start */
  37. u32 sw_width; /* subword width in bits */
  38. u32 regs_per_sw; /* registers per subword */
  39. u32 reg_idx; /* current register index */
  40. u32 reg_bitpos; /* bit offset in current register */
  41. const struct vcap_typegroup *tg; /* current typegroup */
  42. };
  43. /* Check that the control has a valid set of callbacks */
  44. int vcap_api_check(struct vcap_control *ctrl);
  45. /* Erase the VCAP cache area used or encoding and decoding */
  46. void vcap_erase_cache(struct vcap_rule_internal *ri);
  47. /* Iterator functionality */
  48. void vcap_iter_init(struct vcap_stream_iter *itr, int sw_width,
  49. const struct vcap_typegroup *tg, u32 offset);
  50. void vcap_iter_next(struct vcap_stream_iter *itr);
  51. void vcap_iter_set(struct vcap_stream_iter *itr, int sw_width,
  52. const struct vcap_typegroup *tg, u32 offset);
  53. void vcap_iter_update(struct vcap_stream_iter *itr);
  54. /* Keyset and keyfield functionality */
  55. /* Return the number of keyfields in the keyset */
  56. int vcap_keyfield_count(struct vcap_control *vctrl,
  57. enum vcap_type vt, enum vcap_keyfield_set keyset);
  58. /* Return the typegroup table for the matching keyset (using subword size) */
  59. const struct vcap_typegroup *
  60. vcap_keyfield_typegroup(struct vcap_control *vctrl,
  61. enum vcap_type vt, enum vcap_keyfield_set keyset);
  62. /* Return the list of keyfields for the keyset */
  63. const struct vcap_field *vcap_keyfields(struct vcap_control *vctrl,
  64. enum vcap_type vt,
  65. enum vcap_keyfield_set keyset);
  66. /* Actionset and actionfield functionality */
  67. /* Return the actionset information for the actionset */
  68. const struct vcap_set *
  69. vcap_actionfieldset(struct vcap_control *vctrl,
  70. enum vcap_type vt, enum vcap_actionfield_set actionset);
  71. /* Return the number of actionfields in the actionset */
  72. int vcap_actionfield_count(struct vcap_control *vctrl,
  73. enum vcap_type vt,
  74. enum vcap_actionfield_set actionset);
  75. /* Return the typegroup table for the matching actionset (using subword size) */
  76. const struct vcap_typegroup *
  77. vcap_actionfield_typegroup(struct vcap_control *vctrl, enum vcap_type vt,
  78. enum vcap_actionfield_set actionset);
  79. /* Return the list of actionfields for the actionset */
  80. const struct vcap_field *
  81. vcap_actionfields(struct vcap_control *vctrl,
  82. enum vcap_type vt, enum vcap_actionfield_set actionset);
  83. /* Map actionset id to a string with the actionset name */
  84. const char *vcap_actionset_name(struct vcap_control *vctrl,
  85. enum vcap_actionfield_set actionset);
  86. /* Map key field id to a string with the key name */
  87. const char *vcap_actionfield_name(struct vcap_control *vctrl,
  88. enum vcap_action_field action);
  89. /* Read key data from a VCAP address and discover if there are any rule keysets
  90. * here
  91. */
  92. int vcap_addr_keysets(struct vcap_control *vctrl, struct net_device *ndev,
  93. struct vcap_admin *admin, int addr,
  94. struct vcap_keyset_list *kslist);
  95. /* Verify that the typegroup information, subword count, keyset and type id
  96. * are in sync and correct, return the list of matching keysets
  97. */
  98. int vcap_find_keystream_keysets(struct vcap_control *vctrl, enum vcap_type vt,
  99. u32 *keystream, u32 *mskstream, bool mask,
  100. int sw_max, struct vcap_keyset_list *kslist);
  101. /* Get the keysets that matches the rule key type/mask */
  102. int vcap_rule_get_keysets(struct vcap_rule_internal *ri,
  103. struct vcap_keyset_list *matches);
  104. /* Decode a rule from the VCAP cache and return a copy */
  105. struct vcap_rule *vcap_decode_rule(struct vcap_rule_internal *elem);
  106. #endif /* __VCAP_API_PRIVATE__ */