ocelot_vcap.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731
  1. /* SPDX-License-Identifier: (GPL-2.0 OR MIT)
  2. * Microsemi Ocelot Switch driver
  3. * Copyright (c) 2019 Microsemi Corporation
  4. */
  5. #ifndef _OCELOT_VCAP_H_
  6. #define _OCELOT_VCAP_H_
  7. #include <soc/mscc/ocelot.h>
  8. /* Cookie definitions for private VCAP filters installed by the driver.
  9. * Must be unique per VCAP block.
  10. */
  11. #define OCELOT_VCAP_ES0_TAG_8021Q_RXVLAN(ocelot, port, upstream) ((upstream) << 16 | (port))
  12. #define OCELOT_VCAP_IS1_TAG_8021Q_TXVLAN(ocelot, port) (port)
  13. #define OCELOT_VCAP_IS2_TAG_8021Q_TXVLAN(ocelot, port) (port)
  14. #define OCELOT_VCAP_IS2_MRP_REDIRECT(ocelot, port) ((ocelot)->num_phys_ports + (port))
  15. #define OCELOT_VCAP_IS2_MRP_TRAP(ocelot) ((ocelot)->num_phys_ports * 2)
  16. #define OCELOT_VCAP_IS2_L2_PTP_TRAP(ocelot) ((ocelot)->num_phys_ports * 2 + 1)
  17. #define OCELOT_VCAP_IS2_IPV4_GEN_PTP_TRAP(ocelot) ((ocelot)->num_phys_ports * 2 + 2)
  18. #define OCELOT_VCAP_IS2_IPV4_EV_PTP_TRAP(ocelot) ((ocelot)->num_phys_ports * 2 + 3)
  19. #define OCELOT_VCAP_IS2_IPV6_GEN_PTP_TRAP(ocelot) ((ocelot)->num_phys_ports * 2 + 4)
  20. #define OCELOT_VCAP_IS2_IPV6_EV_PTP_TRAP(ocelot) ((ocelot)->num_phys_ports * 2 + 5)
  21. /* =================================================================
  22. * VCAP Common
  23. * =================================================================
  24. */
  25. enum {
  26. VCAP_ES0,
  27. VCAP_IS1,
  28. VCAP_IS2,
  29. __VCAP_COUNT,
  30. };
  31. #define OCELOT_NUM_VCAP_BLOCKS __VCAP_COUNT
  32. struct vcap_props {
  33. u16 tg_width; /* Type-group width (in bits) */
  34. u16 sw_count; /* Sub word count */
  35. u16 entry_count; /* Entry count */
  36. u16 entry_words; /* Number of entry words */
  37. u16 entry_width; /* Entry width (in bits) */
  38. u16 action_count; /* Action count */
  39. u16 action_words; /* Number of action words */
  40. u16 action_width; /* Action width (in bits) */
  41. u16 action_type_width; /* Action type width (in bits) */
  42. struct {
  43. u16 width; /* Action type width (in bits) */
  44. u16 count; /* Action type sub word count */
  45. } action_table[2];
  46. u16 counter_words; /* Number of counter words */
  47. u16 counter_width; /* Counter width (in bits) */
  48. enum ocelot_target target;
  49. const struct vcap_field *keys;
  50. const struct vcap_field *actions;
  51. };
  52. /* VCAP Type-Group values */
  53. #define VCAP_TG_NONE 0 /* Entry is invalid */
  54. #define VCAP_TG_FULL 1 /* Full entry */
  55. #define VCAP_TG_HALF 2 /* Half entry */
  56. #define VCAP_TG_QUARTER 3 /* Quarter entry */
  57. #define VCAP_CORE_UPDATE_CTRL_UPDATE_CMD(x) (((x) << 22) & GENMASK(24, 22))
  58. #define VCAP_CORE_UPDATE_CTRL_UPDATE_CMD_M GENMASK(24, 22)
  59. #define VCAP_CORE_UPDATE_CTRL_UPDATE_CMD_X(x) (((x) & GENMASK(24, 22)) >> 22)
  60. #define VCAP_CORE_UPDATE_CTRL_UPDATE_ENTRY_DIS BIT(21)
  61. #define VCAP_CORE_UPDATE_CTRL_UPDATE_ACTION_DIS BIT(20)
  62. #define VCAP_CORE_UPDATE_CTRL_UPDATE_CNT_DIS BIT(19)
  63. #define VCAP_CORE_UPDATE_CTRL_UPDATE_ADDR(x) (((x) << 3) & GENMASK(18, 3))
  64. #define VCAP_CORE_UPDATE_CTRL_UPDATE_ADDR_M GENMASK(18, 3)
  65. #define VCAP_CORE_UPDATE_CTRL_UPDATE_ADDR_X(x) (((x) & GENMASK(18, 3)) >> 3)
  66. #define VCAP_CORE_UPDATE_CTRL_UPDATE_SHOT BIT(2)
  67. #define VCAP_CORE_UPDATE_CTRL_CLEAR_CACHE BIT(1)
  68. #define VCAP_CORE_UPDATE_CTRL_MV_TRAFFIC_IGN BIT(0)
  69. #define VCAP_CORE_MV_CFG_MV_NUM_POS(x) (((x) << 16) & GENMASK(31, 16))
  70. #define VCAP_CORE_MV_CFG_MV_NUM_POS_M GENMASK(31, 16)
  71. #define VCAP_CORE_MV_CFG_MV_NUM_POS_X(x) (((x) & GENMASK(31, 16)) >> 16)
  72. #define VCAP_CORE_MV_CFG_MV_SIZE(x) ((x) & GENMASK(15, 0))
  73. #define VCAP_CORE_MV_CFG_MV_SIZE_M GENMASK(15, 0)
  74. #define VCAP_CACHE_ENTRY_DAT_RSZ 0x4
  75. #define VCAP_CACHE_MASK_DAT_RSZ 0x4
  76. #define VCAP_CACHE_ACTION_DAT_RSZ 0x4
  77. #define VCAP_CACHE_CNT_DAT_RSZ 0x4
  78. #define VCAP_STICKY_VCAP_ROW_DELETED_STICKY BIT(0)
  79. #define TCAM_BIST_CTRL_TCAM_BIST BIT(1)
  80. #define TCAM_BIST_CTRL_TCAM_INIT BIT(0)
  81. #define TCAM_BIST_CFG_TCAM_BIST_SOE_ENA BIT(8)
  82. #define TCAM_BIST_CFG_TCAM_HCG_DIS BIT(7)
  83. #define TCAM_BIST_CFG_TCAM_CG_DIS BIT(6)
  84. #define TCAM_BIST_CFG_TCAM_BIAS(x) ((x) & GENMASK(5, 0))
  85. #define TCAM_BIST_CFG_TCAM_BIAS_M GENMASK(5, 0)
  86. #define TCAM_BIST_STAT_BIST_RT_ERR BIT(15)
  87. #define TCAM_BIST_STAT_BIST_PENC_ERR BIT(14)
  88. #define TCAM_BIST_STAT_BIST_COMP_ERR BIT(13)
  89. #define TCAM_BIST_STAT_BIST_ADDR_ERR BIT(12)
  90. #define TCAM_BIST_STAT_BIST_BL1E_ERR BIT(11)
  91. #define TCAM_BIST_STAT_BIST_BL1_ERR BIT(10)
  92. #define TCAM_BIST_STAT_BIST_BL0E_ERR BIT(9)
  93. #define TCAM_BIST_STAT_BIST_BL0_ERR BIT(8)
  94. #define TCAM_BIST_STAT_BIST_PH1_ERR BIT(7)
  95. #define TCAM_BIST_STAT_BIST_PH0_ERR BIT(6)
  96. #define TCAM_BIST_STAT_BIST_PV1_ERR BIT(5)
  97. #define TCAM_BIST_STAT_BIST_PV0_ERR BIT(4)
  98. #define TCAM_BIST_STAT_BIST_RUN BIT(3)
  99. #define TCAM_BIST_STAT_BIST_ERR BIT(2)
  100. #define TCAM_BIST_STAT_BIST_BUSY BIT(1)
  101. #define TCAM_BIST_STAT_TCAM_RDY BIT(0)
  102. /* =================================================================
  103. * VCAP IS2
  104. * =================================================================
  105. */
  106. /* IS2 half key types */
  107. #define IS2_TYPE_ETYPE 0
  108. #define IS2_TYPE_LLC 1
  109. #define IS2_TYPE_SNAP 2
  110. #define IS2_TYPE_ARP 3
  111. #define IS2_TYPE_IP_UDP_TCP 4
  112. #define IS2_TYPE_IP_OTHER 5
  113. #define IS2_TYPE_IPV6 6
  114. #define IS2_TYPE_OAM 7
  115. #define IS2_TYPE_SMAC_SIP6 8
  116. #define IS2_TYPE_ANY 100 /* Pseudo type */
  117. /* IS2 half key type mask for matching any IP */
  118. #define IS2_TYPE_MASK_IP_ANY 0xe
  119. enum {
  120. IS2_ACTION_TYPE_NORMAL,
  121. IS2_ACTION_TYPE_SMAC_SIP,
  122. IS2_ACTION_TYPE_MAX,
  123. };
  124. /* IS2 MASK_MODE values */
  125. #define IS2_ACT_MASK_MODE_NONE 0
  126. #define IS2_ACT_MASK_MODE_FILTER 1
  127. #define IS2_ACT_MASK_MODE_POLICY 2
  128. #define IS2_ACT_MASK_MODE_REDIR 3
  129. /* IS2 REW_OP values */
  130. #define IS2_ACT_REW_OP_NONE 0
  131. #define IS2_ACT_REW_OP_PTP_ONE 2
  132. #define IS2_ACT_REW_OP_PTP_TWO 3
  133. #define IS2_ACT_REW_OP_SPECIAL 8
  134. #define IS2_ACT_REW_OP_PTP_ORG 9
  135. #define IS2_ACT_REW_OP_PTP_ONE_SUB_DELAY_1 (IS2_ACT_REW_OP_PTP_ONE | (1 << 3))
  136. #define IS2_ACT_REW_OP_PTP_ONE_SUB_DELAY_2 (IS2_ACT_REW_OP_PTP_ONE | (2 << 3))
  137. #define IS2_ACT_REW_OP_PTP_ONE_ADD_DELAY (IS2_ACT_REW_OP_PTP_ONE | (1 << 5))
  138. #define IS2_ACT_REW_OP_PTP_ONE_ADD_SUB BIT(7)
  139. #define VCAP_PORT_WIDTH 4
  140. /* IS2 quarter key - SMAC_SIP4 */
  141. #define IS2_QKO_IGR_PORT 0
  142. #define IS2_QKL_IGR_PORT VCAP_PORT_WIDTH
  143. #define IS2_QKO_L2_SMAC (IS2_QKO_IGR_PORT + IS2_QKL_IGR_PORT)
  144. #define IS2_QKL_L2_SMAC 48
  145. #define IS2_QKO_L3_IP4_SIP (IS2_QKO_L2_SMAC + IS2_QKL_L2_SMAC)
  146. #define IS2_QKL_L3_IP4_SIP 32
  147. enum vcap_is2_half_key_field {
  148. /* Common */
  149. VCAP_IS2_TYPE,
  150. VCAP_IS2_HK_FIRST,
  151. VCAP_IS2_HK_PAG,
  152. VCAP_IS2_HK_RSV1,
  153. VCAP_IS2_HK_IGR_PORT_MASK,
  154. VCAP_IS2_HK_RSV2,
  155. VCAP_IS2_HK_HOST_MATCH,
  156. VCAP_IS2_HK_L2_MC,
  157. VCAP_IS2_HK_L2_BC,
  158. VCAP_IS2_HK_VLAN_TAGGED,
  159. VCAP_IS2_HK_VID,
  160. VCAP_IS2_HK_DEI,
  161. VCAP_IS2_HK_PCP,
  162. /* MAC_ETYPE / MAC_LLC / MAC_SNAP / OAM common */
  163. VCAP_IS2_HK_L2_DMAC,
  164. VCAP_IS2_HK_L2_SMAC,
  165. /* MAC_ETYPE (TYPE=000) */
  166. VCAP_IS2_HK_MAC_ETYPE_ETYPE,
  167. VCAP_IS2_HK_MAC_ETYPE_L2_PAYLOAD0,
  168. VCAP_IS2_HK_MAC_ETYPE_L2_PAYLOAD1,
  169. VCAP_IS2_HK_MAC_ETYPE_L2_PAYLOAD2,
  170. /* MAC_LLC (TYPE=001) */
  171. VCAP_IS2_HK_MAC_LLC_DMAC,
  172. VCAP_IS2_HK_MAC_LLC_SMAC,
  173. VCAP_IS2_HK_MAC_LLC_L2_LLC,
  174. /* MAC_SNAP (TYPE=010) */
  175. VCAP_IS2_HK_MAC_SNAP_SMAC,
  176. VCAP_IS2_HK_MAC_SNAP_DMAC,
  177. VCAP_IS2_HK_MAC_SNAP_L2_SNAP,
  178. /* MAC_ARP (TYPE=011) */
  179. VCAP_IS2_HK_MAC_ARP_SMAC,
  180. VCAP_IS2_HK_MAC_ARP_ADDR_SPACE_OK,
  181. VCAP_IS2_HK_MAC_ARP_PROTO_SPACE_OK,
  182. VCAP_IS2_HK_MAC_ARP_LEN_OK,
  183. VCAP_IS2_HK_MAC_ARP_TARGET_MATCH,
  184. VCAP_IS2_HK_MAC_ARP_SENDER_MATCH,
  185. VCAP_IS2_HK_MAC_ARP_OPCODE_UNKNOWN,
  186. VCAP_IS2_HK_MAC_ARP_OPCODE,
  187. VCAP_IS2_HK_MAC_ARP_L3_IP4_DIP,
  188. VCAP_IS2_HK_MAC_ARP_L3_IP4_SIP,
  189. VCAP_IS2_HK_MAC_ARP_DIP_EQ_SIP,
  190. /* IP4_TCP_UDP / IP4_OTHER common */
  191. VCAP_IS2_HK_IP4,
  192. VCAP_IS2_HK_L3_FRAGMENT,
  193. VCAP_IS2_HK_L3_FRAG_OFS_GT0,
  194. VCAP_IS2_HK_L3_OPTIONS,
  195. VCAP_IS2_HK_IP4_L3_TTL_GT0,
  196. VCAP_IS2_HK_L3_TOS,
  197. VCAP_IS2_HK_L3_IP4_DIP,
  198. VCAP_IS2_HK_L3_IP4_SIP,
  199. VCAP_IS2_HK_DIP_EQ_SIP,
  200. /* IP4_TCP_UDP (TYPE=100) */
  201. VCAP_IS2_HK_TCP,
  202. VCAP_IS2_HK_L4_SPORT,
  203. VCAP_IS2_HK_L4_DPORT,
  204. VCAP_IS2_HK_L4_RNG,
  205. VCAP_IS2_HK_L4_SPORT_EQ_DPORT,
  206. VCAP_IS2_HK_L4_SEQUENCE_EQ0,
  207. VCAP_IS2_HK_L4_URG,
  208. VCAP_IS2_HK_L4_ACK,
  209. VCAP_IS2_HK_L4_PSH,
  210. VCAP_IS2_HK_L4_RST,
  211. VCAP_IS2_HK_L4_SYN,
  212. VCAP_IS2_HK_L4_FIN,
  213. VCAP_IS2_HK_L4_1588_DOM,
  214. VCAP_IS2_HK_L4_1588_VER,
  215. /* IP4_OTHER (TYPE=101) */
  216. VCAP_IS2_HK_IP4_L3_PROTO,
  217. VCAP_IS2_HK_L3_PAYLOAD,
  218. /* IP6_STD (TYPE=110) */
  219. VCAP_IS2_HK_IP6_L3_TTL_GT0,
  220. VCAP_IS2_HK_IP6_L3_PROTO,
  221. VCAP_IS2_HK_L3_IP6_SIP,
  222. /* OAM (TYPE=111) */
  223. VCAP_IS2_HK_OAM_MEL_FLAGS,
  224. VCAP_IS2_HK_OAM_VER,
  225. VCAP_IS2_HK_OAM_OPCODE,
  226. VCAP_IS2_HK_OAM_FLAGS,
  227. VCAP_IS2_HK_OAM_MEPID,
  228. VCAP_IS2_HK_OAM_CCM_CNTS_EQ0,
  229. VCAP_IS2_HK_OAM_IS_Y1731,
  230. };
  231. struct vcap_field {
  232. int offset;
  233. int length;
  234. };
  235. enum vcap_is2_action_field {
  236. VCAP_IS2_ACT_HIT_ME_ONCE,
  237. VCAP_IS2_ACT_CPU_COPY_ENA,
  238. VCAP_IS2_ACT_CPU_QU_NUM,
  239. VCAP_IS2_ACT_MASK_MODE,
  240. VCAP_IS2_ACT_MIRROR_ENA,
  241. VCAP_IS2_ACT_LRN_DIS,
  242. VCAP_IS2_ACT_POLICE_ENA,
  243. VCAP_IS2_ACT_POLICE_IDX,
  244. VCAP_IS2_ACT_POLICE_VCAP_ONLY,
  245. VCAP_IS2_ACT_PORT_MASK,
  246. VCAP_IS2_ACT_REW_OP,
  247. VCAP_IS2_ACT_SMAC_REPLACE_ENA,
  248. VCAP_IS2_ACT_RSV,
  249. VCAP_IS2_ACT_ACL_ID,
  250. VCAP_IS2_ACT_HIT_CNT,
  251. };
  252. /* =================================================================
  253. * VCAP IS1
  254. * =================================================================
  255. */
  256. /* IS1 half key types */
  257. #define IS1_TYPE_S1_NORMAL 0
  258. #define IS1_TYPE_S1_5TUPLE_IP4 1
  259. /* IS1 full key types */
  260. #define IS1_TYPE_S1_NORMAL_IP6 0
  261. #define IS1_TYPE_S1_7TUPLE 1
  262. #define IS2_TYPE_S1_5TUPLE_IP6 2
  263. enum {
  264. IS1_ACTION_TYPE_NORMAL,
  265. IS1_ACTION_TYPE_MAX,
  266. };
  267. enum vcap_is1_half_key_field {
  268. VCAP_IS1_HK_TYPE,
  269. VCAP_IS1_HK_LOOKUP,
  270. VCAP_IS1_HK_IGR_PORT_MASK,
  271. VCAP_IS1_HK_RSV,
  272. VCAP_IS1_HK_OAM_Y1731,
  273. VCAP_IS1_HK_L2_MC,
  274. VCAP_IS1_HK_L2_BC,
  275. VCAP_IS1_HK_IP_MC,
  276. VCAP_IS1_HK_VLAN_TAGGED,
  277. VCAP_IS1_HK_VLAN_DBL_TAGGED,
  278. VCAP_IS1_HK_TPID,
  279. VCAP_IS1_HK_VID,
  280. VCAP_IS1_HK_DEI,
  281. VCAP_IS1_HK_PCP,
  282. /* Specific Fields for IS1 Half Key S1_NORMAL */
  283. VCAP_IS1_HK_L2_SMAC,
  284. VCAP_IS1_HK_ETYPE_LEN,
  285. VCAP_IS1_HK_ETYPE,
  286. VCAP_IS1_HK_IP_SNAP,
  287. VCAP_IS1_HK_IP4,
  288. VCAP_IS1_HK_L3_FRAGMENT,
  289. VCAP_IS1_HK_L3_FRAG_OFS_GT0,
  290. VCAP_IS1_HK_L3_OPTIONS,
  291. VCAP_IS1_HK_L3_DSCP,
  292. VCAP_IS1_HK_L3_IP4_SIP,
  293. VCAP_IS1_HK_TCP_UDP,
  294. VCAP_IS1_HK_TCP,
  295. VCAP_IS1_HK_L4_SPORT,
  296. VCAP_IS1_HK_L4_RNG,
  297. /* Specific Fields for IS1 Half Key S1_5TUPLE_IP4 */
  298. VCAP_IS1_HK_IP4_INNER_TPID,
  299. VCAP_IS1_HK_IP4_INNER_VID,
  300. VCAP_IS1_HK_IP4_INNER_DEI,
  301. VCAP_IS1_HK_IP4_INNER_PCP,
  302. VCAP_IS1_HK_IP4_IP4,
  303. VCAP_IS1_HK_IP4_L3_FRAGMENT,
  304. VCAP_IS1_HK_IP4_L3_FRAG_OFS_GT0,
  305. VCAP_IS1_HK_IP4_L3_OPTIONS,
  306. VCAP_IS1_HK_IP4_L3_DSCP,
  307. VCAP_IS1_HK_IP4_L3_IP4_DIP,
  308. VCAP_IS1_HK_IP4_L3_IP4_SIP,
  309. VCAP_IS1_HK_IP4_L3_PROTO,
  310. VCAP_IS1_HK_IP4_TCP_UDP,
  311. VCAP_IS1_HK_IP4_TCP,
  312. VCAP_IS1_HK_IP4_L4_RNG,
  313. VCAP_IS1_HK_IP4_IP_PAYLOAD_S1_5TUPLE,
  314. };
  315. enum vcap_is1_action_field {
  316. VCAP_IS1_ACT_DSCP_ENA,
  317. VCAP_IS1_ACT_DSCP_VAL,
  318. VCAP_IS1_ACT_QOS_ENA,
  319. VCAP_IS1_ACT_QOS_VAL,
  320. VCAP_IS1_ACT_DP_ENA,
  321. VCAP_IS1_ACT_DP_VAL,
  322. VCAP_IS1_ACT_PAG_OVERRIDE_MASK,
  323. VCAP_IS1_ACT_PAG_VAL,
  324. VCAP_IS1_ACT_RSV,
  325. VCAP_IS1_ACT_VID_REPLACE_ENA,
  326. VCAP_IS1_ACT_VID_ADD_VAL,
  327. VCAP_IS1_ACT_FID_SEL,
  328. VCAP_IS1_ACT_FID_VAL,
  329. VCAP_IS1_ACT_PCP_DEI_ENA,
  330. VCAP_IS1_ACT_PCP_VAL,
  331. VCAP_IS1_ACT_DEI_VAL,
  332. VCAP_IS1_ACT_VLAN_POP_CNT_ENA,
  333. VCAP_IS1_ACT_VLAN_POP_CNT,
  334. VCAP_IS1_ACT_CUSTOM_ACE_TYPE_ENA,
  335. VCAP_IS1_ACT_HIT_STICKY,
  336. };
  337. /* =================================================================
  338. * VCAP ES0
  339. * =================================================================
  340. */
  341. enum {
  342. ES0_ACTION_TYPE_NORMAL,
  343. ES0_ACTION_TYPE_MAX,
  344. };
  345. enum vcap_es0_key_field {
  346. VCAP_ES0_EGR_PORT,
  347. VCAP_ES0_IGR_PORT,
  348. VCAP_ES0_RSV,
  349. VCAP_ES0_L2_MC,
  350. VCAP_ES0_L2_BC,
  351. VCAP_ES0_VID,
  352. VCAP_ES0_DP,
  353. VCAP_ES0_PCP,
  354. };
  355. enum vcap_es0_action_field {
  356. VCAP_ES0_ACT_PUSH_OUTER_TAG,
  357. VCAP_ES0_ACT_PUSH_INNER_TAG,
  358. VCAP_ES0_ACT_TAG_A_TPID_SEL,
  359. VCAP_ES0_ACT_TAG_A_VID_SEL,
  360. VCAP_ES0_ACT_TAG_A_PCP_SEL,
  361. VCAP_ES0_ACT_TAG_A_DEI_SEL,
  362. VCAP_ES0_ACT_TAG_B_TPID_SEL,
  363. VCAP_ES0_ACT_TAG_B_VID_SEL,
  364. VCAP_ES0_ACT_TAG_B_PCP_SEL,
  365. VCAP_ES0_ACT_TAG_B_DEI_SEL,
  366. VCAP_ES0_ACT_VID_A_VAL,
  367. VCAP_ES0_ACT_PCP_A_VAL,
  368. VCAP_ES0_ACT_DEI_A_VAL,
  369. VCAP_ES0_ACT_VID_B_VAL,
  370. VCAP_ES0_ACT_PCP_B_VAL,
  371. VCAP_ES0_ACT_DEI_B_VAL,
  372. VCAP_ES0_ACT_RSV,
  373. VCAP_ES0_ACT_HIT_STICKY,
  374. };
  375. struct ocelot_ipv4 {
  376. u8 addr[4];
  377. };
  378. enum ocelot_vcap_bit {
  379. OCELOT_VCAP_BIT_ANY,
  380. OCELOT_VCAP_BIT_0,
  381. OCELOT_VCAP_BIT_1
  382. };
  383. struct ocelot_vcap_u8 {
  384. u8 value[1];
  385. u8 mask[1];
  386. };
  387. struct ocelot_vcap_u16 {
  388. u8 value[2];
  389. u8 mask[2];
  390. };
  391. struct ocelot_vcap_u24 {
  392. u8 value[3];
  393. u8 mask[3];
  394. };
  395. struct ocelot_vcap_u32 {
  396. u8 value[4];
  397. u8 mask[4];
  398. };
  399. struct ocelot_vcap_u40 {
  400. u8 value[5];
  401. u8 mask[5];
  402. };
  403. struct ocelot_vcap_u48 {
  404. u8 value[6];
  405. u8 mask[6];
  406. };
  407. struct ocelot_vcap_u64 {
  408. u8 value[8];
  409. u8 mask[8];
  410. };
  411. struct ocelot_vcap_u128 {
  412. u8 value[16];
  413. u8 mask[16];
  414. };
  415. struct ocelot_vcap_vid {
  416. u16 value;
  417. u16 mask;
  418. };
  419. struct ocelot_vcap_ipv4 {
  420. struct ocelot_ipv4 value;
  421. struct ocelot_ipv4 mask;
  422. };
  423. struct ocelot_vcap_udp_tcp {
  424. u16 value;
  425. u16 mask;
  426. };
  427. struct ocelot_vcap_port {
  428. u8 value;
  429. u8 mask;
  430. };
  431. enum ocelot_vcap_key_type {
  432. OCELOT_VCAP_KEY_ANY,
  433. OCELOT_VCAP_KEY_ETYPE,
  434. OCELOT_VCAP_KEY_LLC,
  435. OCELOT_VCAP_KEY_SNAP,
  436. OCELOT_VCAP_KEY_ARP,
  437. OCELOT_VCAP_KEY_IPV4,
  438. OCELOT_VCAP_KEY_IPV6
  439. };
  440. struct ocelot_vcap_key_vlan {
  441. struct ocelot_vcap_vid vid; /* VLAN ID (12 bit) */
  442. struct ocelot_vcap_u8 pcp; /* PCP (3 bit) */
  443. enum ocelot_vcap_bit dei; /* DEI */
  444. enum ocelot_vcap_bit tagged; /* Tagged/untagged frame */
  445. };
  446. struct ocelot_vcap_key_etype {
  447. struct ocelot_vcap_u48 dmac;
  448. struct ocelot_vcap_u48 smac;
  449. struct ocelot_vcap_u16 etype;
  450. struct ocelot_vcap_u16 data; /* MAC data */
  451. };
  452. struct ocelot_vcap_key_llc {
  453. struct ocelot_vcap_u48 dmac;
  454. struct ocelot_vcap_u48 smac;
  455. /* LLC header: DSAP at byte 0, SSAP at byte 1, Control at byte 2 */
  456. struct ocelot_vcap_u32 llc;
  457. };
  458. struct ocelot_vcap_key_snap {
  459. struct ocelot_vcap_u48 dmac;
  460. struct ocelot_vcap_u48 smac;
  461. /* SNAP header: Organization Code at byte 0, Type at byte 3 */
  462. struct ocelot_vcap_u40 snap;
  463. };
  464. struct ocelot_vcap_key_arp {
  465. struct ocelot_vcap_u48 smac;
  466. enum ocelot_vcap_bit arp; /* Opcode ARP/RARP */
  467. enum ocelot_vcap_bit req; /* Opcode request/reply */
  468. enum ocelot_vcap_bit unknown; /* Opcode unknown */
  469. enum ocelot_vcap_bit smac_match; /* Sender MAC matches SMAC */
  470. enum ocelot_vcap_bit dmac_match; /* Target MAC matches DMAC */
  471. /**< Protocol addr. length 4, hardware length 6 */
  472. enum ocelot_vcap_bit length;
  473. enum ocelot_vcap_bit ip; /* Protocol address type IP */
  474. enum ocelot_vcap_bit ethernet; /* Hardware address type Ethernet */
  475. struct ocelot_vcap_ipv4 sip; /* Sender IP address */
  476. struct ocelot_vcap_ipv4 dip; /* Target IP address */
  477. };
  478. struct ocelot_vcap_key_ipv4 {
  479. enum ocelot_vcap_bit ttl; /* TTL zero */
  480. enum ocelot_vcap_bit fragment; /* Fragment */
  481. enum ocelot_vcap_bit options; /* Header options */
  482. struct ocelot_vcap_u8 ds;
  483. struct ocelot_vcap_u8 proto; /* Protocol */
  484. struct ocelot_vcap_ipv4 sip; /* Source IP address */
  485. struct ocelot_vcap_ipv4 dip; /* Destination IP address */
  486. struct ocelot_vcap_u48 data; /* Not UDP/TCP: IP data */
  487. struct ocelot_vcap_udp_tcp sport; /* UDP/TCP: Source port */
  488. struct ocelot_vcap_udp_tcp dport; /* UDP/TCP: Destination port */
  489. enum ocelot_vcap_bit tcp_fin;
  490. enum ocelot_vcap_bit tcp_syn;
  491. enum ocelot_vcap_bit tcp_rst;
  492. enum ocelot_vcap_bit tcp_psh;
  493. enum ocelot_vcap_bit tcp_ack;
  494. enum ocelot_vcap_bit tcp_urg;
  495. enum ocelot_vcap_bit sip_eq_dip; /* SIP equals DIP */
  496. enum ocelot_vcap_bit sport_eq_dport; /* SPORT equals DPORT */
  497. enum ocelot_vcap_bit seq_zero; /* TCP sequence number is zero */
  498. };
  499. struct ocelot_vcap_key_ipv6 {
  500. struct ocelot_vcap_u8 proto; /* IPv6 protocol */
  501. struct ocelot_vcap_u128 sip; /* IPv6 source (byte 0-7 ignored) */
  502. struct ocelot_vcap_u128 dip; /* IPv6 destination (byte 0-7 ignored) */
  503. enum ocelot_vcap_bit ttl; /* TTL zero */
  504. struct ocelot_vcap_u8 ds;
  505. struct ocelot_vcap_u48 data; /* Not UDP/TCP: IP data */
  506. struct ocelot_vcap_udp_tcp sport;
  507. struct ocelot_vcap_udp_tcp dport;
  508. enum ocelot_vcap_bit tcp_fin;
  509. enum ocelot_vcap_bit tcp_syn;
  510. enum ocelot_vcap_bit tcp_rst;
  511. enum ocelot_vcap_bit tcp_psh;
  512. enum ocelot_vcap_bit tcp_ack;
  513. enum ocelot_vcap_bit tcp_urg;
  514. enum ocelot_vcap_bit sip_eq_dip; /* SIP equals DIP */
  515. enum ocelot_vcap_bit sport_eq_dport; /* SPORT equals DPORT */
  516. enum ocelot_vcap_bit seq_zero; /* TCP sequence number is zero */
  517. };
  518. enum ocelot_mask_mode {
  519. OCELOT_MASK_MODE_NONE,
  520. OCELOT_MASK_MODE_PERMIT_DENY,
  521. OCELOT_MASK_MODE_POLICY,
  522. OCELOT_MASK_MODE_REDIRECT,
  523. };
  524. enum ocelot_es0_vid_sel {
  525. OCELOT_ES0_VID_PLUS_CLASSIFIED_VID = 0,
  526. OCELOT_ES0_VID = 1,
  527. };
  528. enum ocelot_es0_pcp_sel {
  529. OCELOT_CLASSIFIED_PCP = 0,
  530. OCELOT_ES0_PCP = 1,
  531. };
  532. enum ocelot_es0_tag {
  533. OCELOT_NO_ES0_TAG,
  534. OCELOT_ES0_TAG,
  535. OCELOT_FORCE_PORT_TAG,
  536. OCELOT_FORCE_UNTAG,
  537. };
  538. enum ocelot_tag_tpid_sel {
  539. OCELOT_TAG_TPID_SEL_8021Q,
  540. OCELOT_TAG_TPID_SEL_8021AD,
  541. };
  542. struct ocelot_vcap_action {
  543. union {
  544. /* VCAP ES0 */
  545. struct {
  546. enum ocelot_es0_tag push_outer_tag;
  547. enum ocelot_es0_tag push_inner_tag;
  548. enum ocelot_tag_tpid_sel tag_a_tpid_sel;
  549. int tag_a_vid_sel;
  550. int tag_a_pcp_sel;
  551. u16 vid_a_val;
  552. u8 pcp_a_val;
  553. u8 dei_a_val;
  554. enum ocelot_tag_tpid_sel tag_b_tpid_sel;
  555. int tag_b_vid_sel;
  556. int tag_b_pcp_sel;
  557. u16 vid_b_val;
  558. u8 pcp_b_val;
  559. u8 dei_b_val;
  560. };
  561. /* VCAP IS1 */
  562. struct {
  563. bool vid_replace_ena;
  564. u16 vid;
  565. bool vlan_pop_cnt_ena;
  566. int vlan_pop_cnt;
  567. bool pcp_dei_ena;
  568. u8 pcp;
  569. u8 dei;
  570. bool qos_ena;
  571. u8 qos_val;
  572. u8 pag_override_mask;
  573. u8 pag_val;
  574. };
  575. /* VCAP IS2 */
  576. struct {
  577. bool cpu_copy_ena;
  578. u8 cpu_qu_num;
  579. enum ocelot_mask_mode mask_mode;
  580. unsigned long port_mask;
  581. bool police_ena;
  582. bool mirror_ena;
  583. struct ocelot_policer pol;
  584. u32 pol_ix;
  585. };
  586. };
  587. };
  588. struct ocelot_vcap_stats {
  589. u64 bytes;
  590. u64 pkts;
  591. u64 used;
  592. };
  593. enum ocelot_vcap_filter_type {
  594. OCELOT_VCAP_FILTER_DUMMY,
  595. OCELOT_VCAP_FILTER_PAG,
  596. OCELOT_VCAP_FILTER_OFFLOAD,
  597. OCELOT_PSFP_FILTER_OFFLOAD,
  598. };
  599. struct ocelot_vcap_id {
  600. unsigned long cookie;
  601. bool tc_offload;
  602. };
  603. struct ocelot_vcap_filter {
  604. struct list_head list;
  605. enum ocelot_vcap_filter_type type;
  606. int block_id;
  607. int goto_target;
  608. int lookup;
  609. u8 pag;
  610. u16 prio;
  611. struct ocelot_vcap_id id;
  612. struct ocelot_vcap_action action;
  613. struct ocelot_vcap_stats stats;
  614. /* For VCAP IS1 and IS2 */
  615. bool take_ts;
  616. bool is_trap;
  617. unsigned long ingress_port_mask;
  618. /* For VCAP ES0 */
  619. struct ocelot_vcap_port ingress_port;
  620. /* For VCAP IS2 mirrors and ES0 */
  621. struct ocelot_vcap_port egress_port;
  622. enum ocelot_vcap_bit dmac_mc;
  623. enum ocelot_vcap_bit dmac_bc;
  624. struct ocelot_vcap_key_vlan vlan;
  625. enum ocelot_vcap_key_type key_type;
  626. union {
  627. /* OCELOT_VCAP_KEY_ANY: No specific fields */
  628. struct ocelot_vcap_key_etype etype;
  629. struct ocelot_vcap_key_llc llc;
  630. struct ocelot_vcap_key_snap snap;
  631. struct ocelot_vcap_key_arp arp;
  632. struct ocelot_vcap_key_ipv4 ipv4;
  633. struct ocelot_vcap_key_ipv6 ipv6;
  634. } key;
  635. };
  636. int ocelot_vcap_filter_add(struct ocelot *ocelot,
  637. struct ocelot_vcap_filter *rule,
  638. struct netlink_ext_ack *extack);
  639. int ocelot_vcap_filter_del(struct ocelot *ocelot,
  640. struct ocelot_vcap_filter *rule);
  641. int ocelot_vcap_filter_replace(struct ocelot *ocelot,
  642. struct ocelot_vcap_filter *filter);
  643. struct ocelot_vcap_filter *
  644. ocelot_vcap_block_find_filter_by_id(struct ocelot_vcap_block *block,
  645. unsigned long cookie, bool tc_offload);
  646. #endif /* _OCELOT_VCAP_H_ */