ocelot_vcap.h 19 KB

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