ocelot_ace.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. /* SPDX-License-Identifier: (GPL-2.0 OR MIT) */
  2. /* Microsemi Ocelot Switch driver
  3. * Copyright (c) 2019 Microsemi Corporation
  4. */
  5. #ifndef _MSCC_OCELOT_ACE_H_
  6. #define _MSCC_OCELOT_ACE_H_
  7. #include "ocelot.h"
  8. #include <net/sch_generic.h>
  9. #include <net/pkt_cls.h>
  10. struct ocelot_ipv4 {
  11. u8 addr[4];
  12. };
  13. enum ocelot_vcap_bit {
  14. OCELOT_VCAP_BIT_ANY,
  15. OCELOT_VCAP_BIT_0,
  16. OCELOT_VCAP_BIT_1
  17. };
  18. struct ocelot_vcap_u8 {
  19. u8 value[1];
  20. u8 mask[1];
  21. };
  22. struct ocelot_vcap_u16 {
  23. u8 value[2];
  24. u8 mask[2];
  25. };
  26. struct ocelot_vcap_u24 {
  27. u8 value[3];
  28. u8 mask[3];
  29. };
  30. struct ocelot_vcap_u32 {
  31. u8 value[4];
  32. u8 mask[4];
  33. };
  34. struct ocelot_vcap_u40 {
  35. u8 value[5];
  36. u8 mask[5];
  37. };
  38. struct ocelot_vcap_u48 {
  39. u8 value[6];
  40. u8 mask[6];
  41. };
  42. struct ocelot_vcap_u64 {
  43. u8 value[8];
  44. u8 mask[8];
  45. };
  46. struct ocelot_vcap_u128 {
  47. u8 value[16];
  48. u8 mask[16];
  49. };
  50. struct ocelot_vcap_vid {
  51. u16 value;
  52. u16 mask;
  53. };
  54. struct ocelot_vcap_ipv4 {
  55. struct ocelot_ipv4 value;
  56. struct ocelot_ipv4 mask;
  57. };
  58. struct ocelot_vcap_udp_tcp {
  59. u16 value;
  60. u16 mask;
  61. };
  62. enum ocelot_ace_type {
  63. OCELOT_ACE_TYPE_ANY,
  64. OCELOT_ACE_TYPE_ETYPE,
  65. OCELOT_ACE_TYPE_LLC,
  66. OCELOT_ACE_TYPE_SNAP,
  67. OCELOT_ACE_TYPE_ARP,
  68. OCELOT_ACE_TYPE_IPV4,
  69. OCELOT_ACE_TYPE_IPV6
  70. };
  71. struct ocelot_ace_vlan {
  72. struct ocelot_vcap_vid vid; /* VLAN ID (12 bit) */
  73. struct ocelot_vcap_u8 pcp; /* PCP (3 bit) */
  74. enum ocelot_vcap_bit dei; /* DEI */
  75. enum ocelot_vcap_bit tagged; /* Tagged/untagged frame */
  76. };
  77. struct ocelot_ace_frame_etype {
  78. struct ocelot_vcap_u48 dmac;
  79. struct ocelot_vcap_u48 smac;
  80. struct ocelot_vcap_u16 etype;
  81. struct ocelot_vcap_u16 data; /* MAC data */
  82. };
  83. struct ocelot_ace_frame_llc {
  84. struct ocelot_vcap_u48 dmac;
  85. struct ocelot_vcap_u48 smac;
  86. /* LLC header: DSAP at byte 0, SSAP at byte 1, Control at byte 2 */
  87. struct ocelot_vcap_u32 llc;
  88. };
  89. struct ocelot_ace_frame_snap {
  90. struct ocelot_vcap_u48 dmac;
  91. struct ocelot_vcap_u48 smac;
  92. /* SNAP header: Organization Code at byte 0, Type at byte 3 */
  93. struct ocelot_vcap_u40 snap;
  94. };
  95. struct ocelot_ace_frame_arp {
  96. struct ocelot_vcap_u48 smac;
  97. enum ocelot_vcap_bit arp; /* Opcode ARP/RARP */
  98. enum ocelot_vcap_bit req; /* Opcode request/reply */
  99. enum ocelot_vcap_bit unknown; /* Opcode unknown */
  100. enum ocelot_vcap_bit smac_match; /* Sender MAC matches SMAC */
  101. enum ocelot_vcap_bit dmac_match; /* Target MAC matches DMAC */
  102. /**< Protocol addr. length 4, hardware length 6 */
  103. enum ocelot_vcap_bit length;
  104. enum ocelot_vcap_bit ip; /* Protocol address type IP */
  105. enum ocelot_vcap_bit ethernet; /* Hardware address type Ethernet */
  106. struct ocelot_vcap_ipv4 sip; /* Sender IP address */
  107. struct ocelot_vcap_ipv4 dip; /* Target IP address */
  108. };
  109. struct ocelot_ace_frame_ipv4 {
  110. enum ocelot_vcap_bit ttl; /* TTL zero */
  111. enum ocelot_vcap_bit fragment; /* Fragment */
  112. enum ocelot_vcap_bit options; /* Header options */
  113. struct ocelot_vcap_u8 ds;
  114. struct ocelot_vcap_u8 proto; /* Protocol */
  115. struct ocelot_vcap_ipv4 sip; /* Source IP address */
  116. struct ocelot_vcap_ipv4 dip; /* Destination IP address */
  117. struct ocelot_vcap_u48 data; /* Not UDP/TCP: IP data */
  118. struct ocelot_vcap_udp_tcp sport; /* UDP/TCP: Source port */
  119. struct ocelot_vcap_udp_tcp dport; /* UDP/TCP: Destination port */
  120. enum ocelot_vcap_bit tcp_fin;
  121. enum ocelot_vcap_bit tcp_syn;
  122. enum ocelot_vcap_bit tcp_rst;
  123. enum ocelot_vcap_bit tcp_psh;
  124. enum ocelot_vcap_bit tcp_ack;
  125. enum ocelot_vcap_bit tcp_urg;
  126. enum ocelot_vcap_bit sip_eq_dip; /* SIP equals DIP */
  127. enum ocelot_vcap_bit sport_eq_dport; /* SPORT equals DPORT */
  128. enum ocelot_vcap_bit seq_zero; /* TCP sequence number is zero */
  129. };
  130. struct ocelot_ace_frame_ipv6 {
  131. struct ocelot_vcap_u8 proto; /* IPv6 protocol */
  132. struct ocelot_vcap_u128 sip; /* IPv6 source (byte 0-7 ignored) */
  133. enum ocelot_vcap_bit ttl; /* TTL zero */
  134. struct ocelot_vcap_u8 ds;
  135. struct ocelot_vcap_u48 data; /* Not UDP/TCP: IP data */
  136. struct ocelot_vcap_udp_tcp sport;
  137. struct ocelot_vcap_udp_tcp dport;
  138. enum ocelot_vcap_bit tcp_fin;
  139. enum ocelot_vcap_bit tcp_syn;
  140. enum ocelot_vcap_bit tcp_rst;
  141. enum ocelot_vcap_bit tcp_psh;
  142. enum ocelot_vcap_bit tcp_ack;
  143. enum ocelot_vcap_bit tcp_urg;
  144. enum ocelot_vcap_bit sip_eq_dip; /* SIP equals DIP */
  145. enum ocelot_vcap_bit sport_eq_dport; /* SPORT equals DPORT */
  146. enum ocelot_vcap_bit seq_zero; /* TCP sequence number is zero */
  147. };
  148. enum ocelot_ace_action {
  149. OCELOT_ACL_ACTION_DROP,
  150. OCELOT_ACL_ACTION_TRAP,
  151. };
  152. struct ocelot_ace_stats {
  153. u64 bytes;
  154. u64 pkts;
  155. u64 used;
  156. };
  157. struct ocelot_ace_rule {
  158. struct list_head list;
  159. struct ocelot_port *port;
  160. u16 prio;
  161. u32 id;
  162. enum ocelot_ace_action action;
  163. struct ocelot_ace_stats stats;
  164. int chip_port;
  165. enum ocelot_vcap_bit dmac_mc;
  166. enum ocelot_vcap_bit dmac_bc;
  167. struct ocelot_ace_vlan vlan;
  168. enum ocelot_ace_type type;
  169. union {
  170. /* ocelot_ACE_TYPE_ANY: No specific fields */
  171. struct ocelot_ace_frame_etype etype;
  172. struct ocelot_ace_frame_llc llc;
  173. struct ocelot_ace_frame_snap snap;
  174. struct ocelot_ace_frame_arp arp;
  175. struct ocelot_ace_frame_ipv4 ipv4;
  176. struct ocelot_ace_frame_ipv6 ipv6;
  177. } frame;
  178. };
  179. struct ocelot_acl_block {
  180. struct list_head rules;
  181. struct ocelot *ocelot;
  182. int count;
  183. };
  184. int ocelot_ace_rule_offload_add(struct ocelot_ace_rule *rule);
  185. int ocelot_ace_rule_offload_del(struct ocelot_ace_rule *rule);
  186. int ocelot_ace_rule_stats_update(struct ocelot_ace_rule *rule);
  187. int ocelot_ace_init(struct ocelot *ocelot);
  188. void ocelot_ace_deinit(void);
  189. int ocelot_setup_tc_block_flower_bind(struct ocelot_port *port,
  190. struct flow_block_offload *f);
  191. void ocelot_setup_tc_block_flower_unbind(struct ocelot_port *port,
  192. struct flow_block_offload *f);
  193. #endif /* _MSCC_OCELOT_ACE_H_ */