ice_switch.h 5.8 KB

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