ice_switch.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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_VSI_INVAL_ID 0xffff
  9. /* VSI context structure for add/get/update/free operations */
  10. struct ice_vsi_ctx {
  11. u16 vsi_num;
  12. u16 vsis_allocd;
  13. u16 vsis_unallocated;
  14. u16 flags;
  15. struct ice_aqc_vsi_props info;
  16. struct ice_sched_vsi_info sched;
  17. u8 alloc_from_pool;
  18. u8 vf_num;
  19. };
  20. enum ice_sw_fwd_act_type {
  21. ICE_FWD_TO_VSI = 0,
  22. ICE_FWD_TO_VSI_LIST, /* Do not use this when adding filter */
  23. ICE_FWD_TO_Q,
  24. ICE_FWD_TO_QGRP,
  25. ICE_DROP_PACKET,
  26. ICE_INVAL_ACT
  27. };
  28. /* Switch recipe ID enum values are specific to hardware */
  29. enum ice_sw_lkup_type {
  30. ICE_SW_LKUP_ETHERTYPE = 0,
  31. ICE_SW_LKUP_MAC = 1,
  32. ICE_SW_LKUP_MAC_VLAN = 2,
  33. ICE_SW_LKUP_PROMISC = 3,
  34. ICE_SW_LKUP_VLAN = 4,
  35. ICE_SW_LKUP_DFLT = 5,
  36. ICE_SW_LKUP_ETHERTYPE_MAC = 8,
  37. ICE_SW_LKUP_PROMISC_VLAN = 9,
  38. ICE_SW_LKUP_LAST
  39. };
  40. /* type of filter src id */
  41. enum ice_src_id {
  42. ICE_SRC_ID_UNKNOWN = 0,
  43. ICE_SRC_ID_VSI,
  44. ICE_SRC_ID_QUEUE,
  45. ICE_SRC_ID_LPORT,
  46. };
  47. struct ice_fltr_info {
  48. /* Look up information: how to look up packet */
  49. enum ice_sw_lkup_type lkup_type;
  50. /* Forward action: filter action to do after lookup */
  51. enum ice_sw_fwd_act_type fltr_act;
  52. /* rule ID returned by firmware once filter rule is created */
  53. u16 fltr_rule_id;
  54. u16 flag;
  55. #define ICE_FLTR_RX BIT(0)
  56. #define ICE_FLTR_TX BIT(1)
  57. #define ICE_FLTR_TX_RX (ICE_FLTR_RX | ICE_FLTR_TX)
  58. /* Source VSI for LOOKUP_TX or source port for LOOKUP_RX */
  59. u16 src;
  60. enum ice_src_id src_id;
  61. union {
  62. struct {
  63. u8 mac_addr[ETH_ALEN];
  64. } mac;
  65. struct {
  66. u8 mac_addr[ETH_ALEN];
  67. u16 vlan_id;
  68. } mac_vlan;
  69. struct {
  70. u16 vlan_id;
  71. } vlan;
  72. /* Set lkup_type as ICE_SW_LKUP_ETHERTYPE
  73. * if just using ethertype as filter. Set lkup_type as
  74. * ICE_SW_LKUP_ETHERTYPE_MAC if MAC also needs to be
  75. * passed in as filter.
  76. */
  77. struct {
  78. u16 ethertype;
  79. u8 mac_addr[ETH_ALEN]; /* optional */
  80. } ethertype_mac;
  81. } l_data; /* Make sure to zero out the memory of l_data before using
  82. * it or only set the data associated with lookup match
  83. * rest everything should be zero
  84. */
  85. /* Depending on filter action */
  86. union {
  87. /* queue id in case of ICE_FWD_TO_Q and starting
  88. * queue id in case of ICE_FWD_TO_QGRP.
  89. */
  90. u16 q_id:11;
  91. u16 hw_vsi_id:10;
  92. u16 vsi_list_id:10;
  93. } fwd_id;
  94. /* Sw VSI handle */
  95. u16 vsi_handle;
  96. /* Set to num_queues if action is ICE_FWD_TO_QGRP. This field
  97. * determines the range of queues the packet needs to be forwarded to.
  98. * Note that qgrp_size must be set to a power of 2.
  99. */
  100. u8 qgrp_size;
  101. /* Rule creations populate these indicators basing on the switch type */
  102. u8 lb_en; /* Indicate if packet can be looped back */
  103. u8 lan_en; /* Indicate if packet can be forwarded to the uplink */
  104. };
  105. struct ice_sw_recipe {
  106. struct list_head l_entry;
  107. /* To protect modification of filt_rule list
  108. * defined below
  109. */
  110. struct mutex filt_rule_lock;
  111. /* List of type ice_fltr_mgmt_list_entry */
  112. struct list_head filt_rules;
  113. struct list_head filt_replay_rules;
  114. /* linked list of type recipe_list_entry */
  115. struct list_head rg_list;
  116. /* linked list of type ice_sw_fv_list_entry*/
  117. struct list_head fv_list;
  118. struct ice_aqc_recipe_data_elem *r_buf;
  119. u8 recp_count;
  120. u8 root_rid;
  121. u8 num_profs;
  122. u8 *prof_ids;
  123. /* recipe bitmap: what all recipes makes this recipe */
  124. DECLARE_BITMAP(r_bitmap, ICE_MAX_NUM_RECIPES);
  125. };
  126. /* Bookkeeping structure to hold bitmap of VSIs corresponding to VSI list id */
  127. struct ice_vsi_list_map_info {
  128. struct list_head list_entry;
  129. DECLARE_BITMAP(vsi_map, ICE_MAX_VSI);
  130. u16 vsi_list_id;
  131. /* counter to track how many rules are reusing this VSI list */
  132. u16 ref_cnt;
  133. };
  134. struct ice_fltr_list_entry {
  135. struct list_head list_entry;
  136. enum ice_status status;
  137. struct ice_fltr_info fltr_info;
  138. };
  139. /* This defines an entry in the list that maintains MAC or VLAN membership
  140. * to HW list mapping, since multiple VSIs can subscribe to the same MAC or
  141. * VLAN. As an optimization the VSI list should be created only when a
  142. * second VSI becomes a subscriber to the same MAC address. VSI lists are always
  143. * used for VLAN membership.
  144. */
  145. struct ice_fltr_mgmt_list_entry {
  146. /* back pointer to VSI list id to VSI list mapping */
  147. struct ice_vsi_list_map_info *vsi_list_info;
  148. u16 vsi_count;
  149. #define ICE_INVAL_LG_ACT_INDEX 0xffff
  150. u16 lg_act_idx;
  151. #define ICE_INVAL_SW_MARKER_ID 0xffff
  152. u16 sw_marker_id;
  153. struct list_head list_entry;
  154. struct ice_fltr_info fltr_info;
  155. #define ICE_INVAL_COUNTER_ID 0xff
  156. u8 counter_index;
  157. };
  158. /* VSI related commands */
  159. enum ice_status
  160. ice_add_vsi(struct ice_hw *hw, u16 vsi_handle, struct ice_vsi_ctx *vsi_ctx,
  161. struct ice_sq_cd *cd);
  162. enum ice_status
  163. ice_free_vsi(struct ice_hw *hw, u16 vsi_handle, struct ice_vsi_ctx *vsi_ctx,
  164. bool keep_vsi_alloc, struct ice_sq_cd *cd);
  165. enum ice_status
  166. ice_update_vsi(struct ice_hw *hw, u16 vsi_handle, struct ice_vsi_ctx *vsi_ctx,
  167. struct ice_sq_cd *cd);
  168. bool ice_is_vsi_valid(struct ice_hw *hw, u16 vsi_handle);
  169. struct ice_vsi_ctx *ice_get_vsi_ctx(struct ice_hw *hw, u16 vsi_handle);
  170. enum ice_status ice_get_initial_sw_cfg(struct ice_hw *hw);
  171. /* Switch/bridge related commands */
  172. enum ice_status ice_update_sw_rule_bridge_mode(struct ice_hw *hw);
  173. enum ice_status ice_add_mac(struct ice_hw *hw, struct list_head *m_lst);
  174. enum ice_status ice_remove_mac(struct ice_hw *hw, struct list_head *m_lst);
  175. void ice_remove_vsi_fltr(struct ice_hw *hw, u16 vsi_handle);
  176. enum ice_status ice_add_vlan(struct ice_hw *hw, struct list_head *m_list);
  177. enum ice_status ice_remove_vlan(struct ice_hw *hw, struct list_head *v_list);
  178. enum ice_status
  179. ice_cfg_dflt_vsi(struct ice_hw *hw, u16 vsi_handle, bool set, u8 direction);
  180. enum ice_status ice_init_def_sw_recp(struct ice_hw *hw);
  181. u16 ice_get_hw_vsi_num(struct ice_hw *hw, u16 vsi_handle);
  182. bool ice_is_vsi_valid(struct ice_hw *hw, u16 vsi_handle);
  183. enum ice_status ice_replay_vsi_all_fltr(struct ice_hw *hw, u16 vsi_handle);
  184. void ice_rm_all_sw_replay_rule_info(struct ice_hw *hw);
  185. #endif /* _ICE_SWITCH_H_ */