ice_switch.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /* Copyright (c) 2018, Intel Corporation. */
  3. #ifndef _ICE_SWITCH_H_
  4. #define _ICE_SWITCH_H_
  5. #include "ice_common.h"
  6. #define ICE_SW_CFG_MAX_BUF_LEN 2048
  7. #define ICE_DFLT_VSI_INVAL 0xff
  8. #define ICE_FLTR_RX BIT(0)
  9. #define ICE_FLTR_TX BIT(1)
  10. #define ICE_FLTR_TX_ONLY BIT(2)
  11. #define ICE_VSI_INVAL_ID 0xffff
  12. #define ICE_INVAL_Q_HANDLE 0xFFFF
  13. /* Switch Profile IDs for Profile related switch rules */
  14. #define ICE_PROFID_IPV4_GTPC_TEID 41
  15. #define ICE_PROFID_IPV4_GTPC_NO_TEID 42
  16. #define ICE_PROFID_IPV4_GTPU_TEID 43
  17. #define ICE_PROFID_IPV6_GTPC_TEID 44
  18. #define ICE_PROFID_IPV6_GTPC_NO_TEID 45
  19. #define ICE_PROFID_IPV6_GTPU_TEID 46
  20. #define ICE_PROFID_IPV6_GTPU_IPV6_TCP_INNER 70
  21. #define ICE_PROFID_IPV4_PFCP_NODE 79
  22. #define ICE_PROFID_IPV6_PFCP_SESSION 82
  23. #define ICE_SW_RULE_VSI_LIST_SIZE(s, n) struct_size((s), vsi, (n))
  24. #define ICE_SW_RULE_RX_TX_HDR_SIZE(s, l) struct_size((s), hdr_data, (l))
  25. #define ICE_SW_RULE_RX_TX_ETH_HDR_SIZE(s) \
  26. ICE_SW_RULE_RX_TX_HDR_SIZE((s), DUMMY_ETH_HDR_LEN)
  27. #define ICE_SW_RULE_RX_TX_NO_HDR_SIZE(s) \
  28. ICE_SW_RULE_RX_TX_HDR_SIZE((s), 0)
  29. #define ICE_SW_RULE_LG_ACT_SIZE(s, n) struct_size((s), act, (n))
  30. #define DUMMY_ETH_HDR_LEN 16
  31. /* VSI context structure for add/get/update/free operations */
  32. struct ice_vsi_ctx {
  33. u16 vsi_num;
  34. u16 vsis_allocd;
  35. u16 vsis_unallocated;
  36. u16 flags;
  37. struct ice_aqc_vsi_props info;
  38. struct ice_sched_vsi_info sched;
  39. u8 alloc_from_pool;
  40. u8 vf_num;
  41. u16 num_lan_q_entries[ICE_MAX_TRAFFIC_CLASS];
  42. struct ice_q_ctx *lan_q_ctx[ICE_MAX_TRAFFIC_CLASS];
  43. u16 num_rdma_q_entries[ICE_MAX_TRAFFIC_CLASS];
  44. struct ice_q_ctx *rdma_q_ctx[ICE_MAX_TRAFFIC_CLASS];
  45. };
  46. /* Switch recipe ID enum values are specific to hardware */
  47. enum ice_sw_lkup_type {
  48. ICE_SW_LKUP_ETHERTYPE = 0,
  49. ICE_SW_LKUP_MAC = 1,
  50. ICE_SW_LKUP_MAC_VLAN = 2,
  51. ICE_SW_LKUP_PROMISC = 3,
  52. ICE_SW_LKUP_VLAN = 4,
  53. ICE_SW_LKUP_DFLT = 5,
  54. ICE_SW_LKUP_ETHERTYPE_MAC = 8,
  55. ICE_SW_LKUP_PROMISC_VLAN = 9,
  56. ICE_SW_LKUP_LAST
  57. };
  58. /* type of filter src ID */
  59. enum ice_src_id {
  60. ICE_SRC_ID_UNKNOWN = 0,
  61. ICE_SRC_ID_VSI,
  62. ICE_SRC_ID_QUEUE,
  63. ICE_SRC_ID_LPORT,
  64. };
  65. struct ice_fltr_info {
  66. /* Look up information: how to look up packet */
  67. enum ice_sw_lkup_type lkup_type;
  68. /* Forward action: filter action to do after lookup */
  69. enum ice_sw_fwd_act_type fltr_act;
  70. /* rule ID returned by firmware once filter rule is created */
  71. u16 fltr_rule_id;
  72. u16 flag;
  73. /* Source VSI for LOOKUP_TX or source port for LOOKUP_RX */
  74. u16 src;
  75. enum ice_src_id src_id;
  76. union {
  77. struct {
  78. u8 mac_addr[ETH_ALEN];
  79. } mac;
  80. struct {
  81. u8 mac_addr[ETH_ALEN];
  82. u16 vlan_id;
  83. } mac_vlan;
  84. struct {
  85. u16 vlan_id;
  86. u16 tpid;
  87. u8 tpid_valid;
  88. } vlan;
  89. /* Set lkup_type as ICE_SW_LKUP_ETHERTYPE
  90. * if just using ethertype as filter. Set lkup_type as
  91. * ICE_SW_LKUP_ETHERTYPE_MAC if MAC also needs to be
  92. * passed in as filter.
  93. */
  94. struct {
  95. u16 ethertype;
  96. u8 mac_addr[ETH_ALEN]; /* optional */
  97. } ethertype_mac;
  98. } l_data; /* Make sure to zero out the memory of l_data before using
  99. * it or only set the data associated with lookup match
  100. * rest everything should be zero
  101. */
  102. /* Depending on filter action */
  103. union {
  104. /* queue ID in case of ICE_FWD_TO_Q and starting
  105. * queue ID in case of ICE_FWD_TO_QGRP.
  106. */
  107. u16 q_id:11;
  108. u16 hw_vsi_id:10;
  109. u16 vsi_list_id:10;
  110. } fwd_id;
  111. /* Sw VSI handle */
  112. u16 vsi_handle;
  113. /* Set to num_queues if action is ICE_FWD_TO_QGRP. This field
  114. * determines the range of queues the packet needs to be forwarded to.
  115. * Note that qgrp_size must be set to a power of 2.
  116. */
  117. u8 qgrp_size;
  118. /* Rule creations populate these indicators basing on the switch type */
  119. u8 lb_en; /* Indicate if packet can be looped back */
  120. u8 lan_en; /* Indicate if packet can be forwarded to the uplink */
  121. };
  122. struct ice_update_recipe_lkup_idx_params {
  123. u16 rid;
  124. u16 fv_idx;
  125. bool ignore_valid;
  126. u16 mask;
  127. bool mask_valid;
  128. u8 lkup_idx;
  129. };
  130. struct ice_adv_lkup_elem {
  131. enum ice_protocol_type type;
  132. union {
  133. union ice_prot_hdr h_u; /* Header values */
  134. /* Used to iterate over the headers */
  135. u16 h_raw[sizeof(union ice_prot_hdr) / sizeof(u16)];
  136. };
  137. union {
  138. union ice_prot_hdr m_u; /* Mask of header values to match */
  139. /* Used to iterate over header mask */
  140. u16 m_raw[sizeof(union ice_prot_hdr) / sizeof(u16)];
  141. };
  142. };
  143. struct ice_sw_act_ctrl {
  144. /* Source VSI for LOOKUP_TX or source port for LOOKUP_RX */
  145. u16 src;
  146. u16 flag;
  147. enum ice_sw_fwd_act_type fltr_act;
  148. /* Depending on filter action */
  149. union {
  150. /* This is a queue ID in case of ICE_FWD_TO_Q and starting
  151. * queue ID in case of ICE_FWD_TO_QGRP.
  152. */
  153. u16 q_id:11;
  154. u16 vsi_id:10;
  155. u16 hw_vsi_id:10;
  156. u16 vsi_list_id:10;
  157. } fwd_id;
  158. /* software VSI handle */
  159. u16 vsi_handle;
  160. u8 qgrp_size;
  161. };
  162. struct ice_rule_query_data {
  163. /* Recipe ID for which the requested rule was added */
  164. u16 rid;
  165. /* Rule ID that was added or is supposed to be removed */
  166. u16 rule_id;
  167. /* vsi_handle for which Rule was added or is supposed to be removed */
  168. u16 vsi_handle;
  169. };
  170. /* This structure allows to pass info about lb_en and lan_en
  171. * flags to ice_add_adv_rule. Values in act would be used
  172. * only if act_valid was set to true, otherwise default
  173. * values would be used.
  174. */
  175. struct ice_adv_rule_flags_info {
  176. u32 act;
  177. u8 act_valid; /* indicate if flags in act are valid */
  178. };
  179. struct ice_adv_rule_info {
  180. /* Store metadata values in rule info */
  181. enum ice_sw_tunnel_type tun_type;
  182. u16 vlan_type;
  183. u16 fltr_rule_id;
  184. u32 priority;
  185. u16 need_pass_l2:1;
  186. u16 allow_pass_l2:1;
  187. u16 src_vsi;
  188. struct ice_sw_act_ctrl sw_act;
  189. struct ice_adv_rule_flags_info flags_info;
  190. };
  191. /* A collection of one or more four word recipe */
  192. struct ice_sw_recipe {
  193. /* For a chained recipe the root recipe is what should be used for
  194. * programming rules
  195. */
  196. u8 root_rid;
  197. u8 recp_created;
  198. /* Number of extraction words */
  199. u8 n_ext_words;
  200. /* Protocol ID and Offset pair (extraction word) to describe the
  201. * recipe
  202. */
  203. struct ice_fv_word ext_words[ICE_MAX_CHAIN_WORDS];
  204. u16 word_masks[ICE_MAX_CHAIN_WORDS];
  205. u8 fv_idx[ICE_MAX_CHAIN_WORDS];
  206. u16 fv_mask[ICE_MAX_CHAIN_WORDS];
  207. /* Bit map specifying the IDs associated with this group of recipe */
  208. DECLARE_BITMAP(r_bitmap, ICE_MAX_NUM_RECIPES);
  209. enum ice_sw_tunnel_type tun_type;
  210. /* List of type ice_fltr_mgmt_list_entry or adv_rule */
  211. u8 adv_rule;
  212. struct list_head filt_rules;
  213. struct list_head filt_replay_rules;
  214. struct mutex filt_rule_lock; /* protect filter rule structure */
  215. /* Profiles this recipe should be associated with */
  216. struct list_head fv_list;
  217. /* Profiles this recipe is associated with */
  218. u8 num_profs, *prof_ids;
  219. /* Bit map for possible result indexes */
  220. DECLARE_BITMAP(res_idxs, ICE_MAX_FV_WORDS);
  221. /* This allows user to specify the recipe priority.
  222. * For now, this becomes 'fwd_priority' when recipe
  223. * is created, usually recipes can have 'fwd' and 'join'
  224. * priority.
  225. */
  226. u8 priority;
  227. u8 need_pass_l2:1;
  228. u8 allow_pass_l2:1;
  229. /* This struct saves the fv_words for a given lookup */
  230. struct ice_prot_lkup_ext lkup_exts;
  231. };
  232. /* Bookkeeping structure to hold bitmap of VSIs corresponding to VSI list ID */
  233. struct ice_vsi_list_map_info {
  234. struct list_head list_entry;
  235. DECLARE_BITMAP(vsi_map, ICE_MAX_VSI);
  236. u16 vsi_list_id;
  237. /* counter to track how many rules are reusing this VSI list */
  238. u16 ref_cnt;
  239. };
  240. struct ice_fltr_list_entry {
  241. struct list_head list_entry;
  242. int status;
  243. struct ice_fltr_info fltr_info;
  244. };
  245. /* This defines an entry in the list that maintains MAC or VLAN membership
  246. * to HW list mapping, since multiple VSIs can subscribe to the same MAC or
  247. * VLAN. As an optimization the VSI list should be created only when a
  248. * second VSI becomes a subscriber to the same MAC address. VSI lists are always
  249. * used for VLAN membership.
  250. */
  251. struct ice_fltr_mgmt_list_entry {
  252. /* back pointer to VSI list ID to VSI list mapping */
  253. struct ice_vsi_list_map_info *vsi_list_info;
  254. u16 vsi_count;
  255. #define ICE_INVAL_LG_ACT_INDEX 0xffff
  256. u16 lg_act_idx;
  257. #define ICE_INVAL_SW_MARKER_ID 0xffff
  258. u16 sw_marker_id;
  259. struct list_head list_entry;
  260. struct ice_fltr_info fltr_info;
  261. #define ICE_INVAL_COUNTER_ID 0xff
  262. u8 counter_index;
  263. };
  264. struct ice_adv_fltr_mgmt_list_entry {
  265. struct list_head list_entry;
  266. struct ice_adv_lkup_elem *lkups;
  267. struct ice_adv_rule_info rule_info;
  268. u16 lkups_cnt;
  269. struct ice_vsi_list_map_info *vsi_list_info;
  270. u16 vsi_count;
  271. };
  272. enum ice_promisc_flags {
  273. ICE_PROMISC_UCAST_RX = 0x1,
  274. ICE_PROMISC_UCAST_TX = 0x2,
  275. ICE_PROMISC_MCAST_RX = 0x4,
  276. ICE_PROMISC_MCAST_TX = 0x8,
  277. ICE_PROMISC_BCAST_RX = 0x10,
  278. ICE_PROMISC_BCAST_TX = 0x20,
  279. ICE_PROMISC_VLAN_RX = 0x40,
  280. ICE_PROMISC_VLAN_TX = 0x80,
  281. };
  282. /* VSI related commands */
  283. int
  284. ice_add_vsi(struct ice_hw *hw, u16 vsi_handle, struct ice_vsi_ctx *vsi_ctx,
  285. struct ice_sq_cd *cd);
  286. int
  287. ice_free_vsi(struct ice_hw *hw, u16 vsi_handle, struct ice_vsi_ctx *vsi_ctx,
  288. bool keep_vsi_alloc, struct ice_sq_cd *cd);
  289. int
  290. ice_update_vsi(struct ice_hw *hw, u16 vsi_handle, struct ice_vsi_ctx *vsi_ctx,
  291. struct ice_sq_cd *cd);
  292. bool ice_is_vsi_valid(struct ice_hw *hw, u16 vsi_handle);
  293. struct ice_vsi_ctx *ice_get_vsi_ctx(struct ice_hw *hw, u16 vsi_handle);
  294. void ice_clear_all_vsi_ctx(struct ice_hw *hw);
  295. /* Switch config */
  296. int ice_get_initial_sw_cfg(struct ice_hw *hw);
  297. int
  298. ice_alloc_res_cntr(struct ice_hw *hw, u8 type, u8 alloc_shared, u16 num_items,
  299. u16 *counter_id);
  300. int
  301. ice_free_res_cntr(struct ice_hw *hw, u8 type, u8 alloc_shared, u16 num_items,
  302. u16 counter_id);
  303. int ice_share_res(struct ice_hw *hw, u16 type, u8 shared, u16 res_id);
  304. /* Switch/bridge related commands */
  305. void ice_rule_add_tunnel_metadata(struct ice_adv_lkup_elem *lkup);
  306. void ice_rule_add_direction_metadata(struct ice_adv_lkup_elem *lkup);
  307. void ice_rule_add_vlan_metadata(struct ice_adv_lkup_elem *lkup);
  308. void ice_rule_add_src_vsi_metadata(struct ice_adv_lkup_elem *lkup);
  309. int
  310. ice_add_adv_rule(struct ice_hw *hw, struct ice_adv_lkup_elem *lkups,
  311. u16 lkups_cnt, struct ice_adv_rule_info *rinfo,
  312. struct ice_rule_query_data *added_entry);
  313. int ice_update_sw_rule_bridge_mode(struct ice_hw *hw);
  314. int ice_add_vlan(struct ice_hw *hw, struct list_head *m_list);
  315. int ice_remove_vlan(struct ice_hw *hw, struct list_head *v_list);
  316. int ice_add_mac(struct ice_hw *hw, struct list_head *m_lst);
  317. int ice_remove_mac(struct ice_hw *hw, struct list_head *m_lst);
  318. bool ice_vlan_fltr_exist(struct ice_hw *hw, u16 vlan_id, u16 vsi_handle);
  319. int ice_add_eth_mac(struct ice_hw *hw, struct list_head *em_list);
  320. int ice_remove_eth_mac(struct ice_hw *hw, struct list_head *em_list);
  321. int ice_cfg_rdma_fltr(struct ice_hw *hw, u16 vsi_handle, bool enable);
  322. void ice_remove_vsi_fltr(struct ice_hw *hw, u16 vsi_handle);
  323. /* Promisc/defport setup for VSIs */
  324. int
  325. ice_cfg_dflt_vsi(struct ice_port_info *pi, u16 vsi_handle, bool set,
  326. u8 direction);
  327. bool
  328. ice_check_if_dflt_vsi(struct ice_port_info *pi, u16 vsi_handle,
  329. bool *rule_exists);
  330. int
  331. ice_set_vsi_promisc(struct ice_hw *hw, u16 vsi_handle, u8 promisc_mask,
  332. u16 vid);
  333. int
  334. ice_clear_vsi_promisc(struct ice_hw *hw, u16 vsi_handle, u8 promisc_mask,
  335. u16 vid);
  336. int
  337. ice_set_vlan_vsi_promisc(struct ice_hw *hw, u16 vsi_handle, u8 promisc_mask,
  338. bool rm_vlan_promisc);
  339. int
  340. ice_rem_adv_rule_by_id(struct ice_hw *hw,
  341. struct ice_rule_query_data *remove_entry);
  342. int ice_init_def_sw_recp(struct ice_hw *hw);
  343. u16 ice_get_hw_vsi_num(struct ice_hw *hw, u16 vsi_handle);
  344. int ice_replay_vsi_all_fltr(struct ice_hw *hw, u16 vsi_handle);
  345. void ice_rm_all_sw_replay_rule_info(struct ice_hw *hw);
  346. void ice_fill_eth_hdr(u8 *eth_hdr);
  347. int
  348. ice_aq_sw_rules(struct ice_hw *hw, void *rule_list, u16 rule_list_sz,
  349. u8 num_rules, enum ice_adminq_opc opc, struct ice_sq_cd *cd);
  350. int
  351. ice_update_recipe_lkup_idx(struct ice_hw *hw,
  352. struct ice_update_recipe_lkup_idx_params *params);
  353. void ice_change_proto_id_to_dvm(void);
  354. struct ice_vsi_list_map_info *
  355. ice_find_vsi_list_entry(struct ice_hw *hw, u8 recp_id, u16 vsi_handle,
  356. u16 *vsi_list_id);
  357. int ice_alloc_recipe(struct ice_hw *hw, u16 *rid);
  358. int ice_aq_get_recipe(struct ice_hw *hw,
  359. struct ice_aqc_recipe_data_elem *s_recipe_list,
  360. u16 *num_recipes, u16 recipe_root, struct ice_sq_cd *cd);
  361. int ice_aq_add_recipe(struct ice_hw *hw,
  362. struct ice_aqc_recipe_data_elem *s_recipe_list,
  363. u16 num_recipes, struct ice_sq_cd *cd);
  364. int
  365. ice_aq_get_recipe_to_profile(struct ice_hw *hw, u32 profile_id, u64 *r_assoc,
  366. struct ice_sq_cd *cd);
  367. int
  368. ice_aq_map_recipe_to_profile(struct ice_hw *hw, u32 profile_id, u64 r_assoc,
  369. struct ice_sq_cd *cd);
  370. void ice_init_chk_recipe_reuse_support(struct ice_hw *hw);
  371. #endif /* _ICE_SWITCH_H_ */