ice_switch.h 5.6 KB

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