1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* Copyright (c) 2018, Intel Corporation. */ 3 4 #ifndef _ICE_SWITCH_H_ 5 #define _ICE_SWITCH_H_ 6 7 #include "ice_common.h" 8 9 #define ICE_SW_CFG_MAX_BUF_LEN 2048 10 #define ICE_DFLT_VSI_INVAL 0xff 11 #define ICE_VSI_INVAL_ID 0xffff 12 #define ICE_INVAL_Q_HANDLE 0xFFFF 13 #define ICE_INVAL_Q_HANDLE 0xFFFF 14 15 /* VSI queue context structure */ 16 struct ice_q_ctx { 17 u16 q_handle; 18 }; 19 20 /* VSI context structure for add/get/update/free operations */ 21 struct ice_vsi_ctx { 22 u16 vsi_num; 23 u16 vsis_allocd; 24 u16 vsis_unallocated; 25 u16 flags; 26 struct ice_aqc_vsi_props info; 27 struct ice_sched_vsi_info sched; 28 u8 alloc_from_pool; 29 u8 vf_num; 30 u16 num_lan_q_entries[ICE_MAX_TRAFFIC_CLASS]; 31 struct ice_q_ctx *lan_q_ctx[ICE_MAX_TRAFFIC_CLASS]; 32 }; 33 34 enum ice_sw_fwd_act_type { 35 ICE_FWD_TO_VSI = 0, 36 ICE_FWD_TO_VSI_LIST, /* Do not use this when adding filter */ 37 ICE_FWD_TO_Q, 38 ICE_FWD_TO_QGRP, 39 ICE_DROP_PACKET, 40 ICE_INVAL_ACT 41 }; 42 43 /* Switch recipe ID enum values are specific to hardware */ 44 enum ice_sw_lkup_type { 45 ICE_SW_LKUP_ETHERTYPE = 0, 46 ICE_SW_LKUP_MAC = 1, 47 ICE_SW_LKUP_MAC_VLAN = 2, 48 ICE_SW_LKUP_PROMISC = 3, 49 ICE_SW_LKUP_VLAN = 4, 50 ICE_SW_LKUP_DFLT = 5, 51 ICE_SW_LKUP_ETHERTYPE_MAC = 8, 52 ICE_SW_LKUP_PROMISC_VLAN = 9, 53 ICE_SW_LKUP_LAST 54 }; 55 56 /* type of filter src ID */ 57 enum ice_src_id { 58 ICE_SRC_ID_UNKNOWN = 0, 59 ICE_SRC_ID_VSI, 60 ICE_SRC_ID_QUEUE, 61 ICE_SRC_ID_LPORT, 62 }; 63 64 struct ice_fltr_info { 65 /* Look up information: how to look up packet */ 66 enum ice_sw_lkup_type lkup_type; 67 /* Forward action: filter action to do after lookup */ 68 enum ice_sw_fwd_act_type fltr_act; 69 /* rule ID returned by firmware once filter rule is created */ 70 u16 fltr_rule_id; 71 u16 flag; 72 #define ICE_FLTR_RX BIT(0) 73 #define ICE_FLTR_TX BIT(1) 74 #define ICE_FLTR_TX_RX (ICE_FLTR_RX | ICE_FLTR_TX) 75 76 /* Source VSI for LOOKUP_TX or source port for LOOKUP_RX */ 77 u16 src; 78 enum ice_src_id src_id; 79 80 union { 81 struct { 82 u8 mac_addr[ETH_ALEN]; 83 } mac; 84 struct { 85 u8 mac_addr[ETH_ALEN]; 86 u16 vlan_id; 87 } mac_vlan; 88 struct { 89 u16 vlan_id; 90 } vlan; 91 /* Set lkup_type as ICE_SW_LKUP_ETHERTYPE 92 * if just using ethertype as filter. Set lkup_type as 93 * ICE_SW_LKUP_ETHERTYPE_MAC if MAC also needs to be 94 * passed in as filter. 95 */ 96 struct { 97 u16 ethertype; 98 u8 mac_addr[ETH_ALEN]; /* optional */ 99 } ethertype_mac; 100 } l_data; /* Make sure to zero out the memory of l_data before using 101 * it or only set the data associated with lookup match 102 * rest everything should be zero 103 */ 104 105 /* Depending on filter action */ 106 union { 107 /* queue ID in case of ICE_FWD_TO_Q and starting 108 * queue ID in case of ICE_FWD_TO_QGRP. 109 */ 110 u16 q_id:11; 111 u16 hw_vsi_id:10; 112 u16 vsi_list_id:10; 113 } fwd_id; 114 115 /* Sw VSI handle */ 116 u16 vsi_handle; 117 118 /* Set to num_queues if action is ICE_FWD_TO_QGRP. This field 119 * determines the range of queues the packet needs to be forwarded to. 120 * Note that qgrp_size must be set to a power of 2. 121 */ 122 u8 qgrp_size; 123 124 /* Rule creations populate these indicators basing on the switch type */ 125 u8 lb_en; /* Indicate if packet can be looped back */ 126 u8 lan_en; /* Indicate if packet can be forwarded to the uplink */ 127 }; 128 129 struct ice_sw_recipe { 130 struct list_head l_entry; 131 132 /* To protect modification of filt_rule list 133 * defined below 134 */ 135 struct mutex filt_rule_lock; 136 137 /* List of type ice_fltr_mgmt_list_entry */ 138 struct list_head filt_rules; 139 struct list_head filt_replay_rules; 140 141 /* linked list of type recipe_list_entry */ 142 struct list_head rg_list; 143 /* linked list of type ice_sw_fv_list_entry*/ 144 struct list_head fv_list; 145 struct ice_aqc_recipe_data_elem *r_buf; 146 u8 recp_count; 147 u8 root_rid; 148 u8 num_profs; 149 u8 *prof_ids; 150 151 /* recipe bitmap: what all recipes makes this recipe */ 152 DECLARE_BITMAP(r_bitmap, ICE_MAX_NUM_RECIPES); 153 }; 154 155 /* Bookkeeping structure to hold bitmap of VSIs corresponding to VSI list ID */ 156 struct ice_vsi_list_map_info { 157 struct list_head list_entry; 158 DECLARE_BITMAP(vsi_map, ICE_MAX_VSI); 159 u16 vsi_list_id; 160 /* counter to track how many rules are reusing this VSI list */ 161 u16 ref_cnt; 162 }; 163 164 struct ice_fltr_list_entry { 165 struct list_head list_entry; 166 enum ice_status status; 167 struct ice_fltr_info fltr_info; 168 }; 169 170 /* This defines an entry in the list that maintains MAC or VLAN membership 171 * to HW list mapping, since multiple VSIs can subscribe to the same MAC or 172 * VLAN. As an optimization the VSI list should be created only when a 173 * second VSI becomes a subscriber to the same MAC address. VSI lists are always 174 * used for VLAN membership. 175 */ 176 struct ice_fltr_mgmt_list_entry { 177 /* back pointer to VSI list ID to VSI list mapping */ 178 struct ice_vsi_list_map_info *vsi_list_info; 179 u16 vsi_count; 180 #define ICE_INVAL_LG_ACT_INDEX 0xffff 181 u16 lg_act_idx; 182 #define ICE_INVAL_SW_MARKER_ID 0xffff 183 u16 sw_marker_id; 184 struct list_head list_entry; 185 struct ice_fltr_info fltr_info; 186 #define ICE_INVAL_COUNTER_ID 0xff 187 u8 counter_index; 188 }; 189 190 enum ice_promisc_flags { 191 ICE_PROMISC_UCAST_RX = 0x1, 192 ICE_PROMISC_UCAST_TX = 0x2, 193 ICE_PROMISC_MCAST_RX = 0x4, 194 ICE_PROMISC_MCAST_TX = 0x8, 195 ICE_PROMISC_BCAST_RX = 0x10, 196 ICE_PROMISC_BCAST_TX = 0x20, 197 ICE_PROMISC_VLAN_RX = 0x40, 198 ICE_PROMISC_VLAN_TX = 0x80, 199 }; 200 201 /* VSI related commands */ 202 enum ice_status 203 ice_add_vsi(struct ice_hw *hw, u16 vsi_handle, struct ice_vsi_ctx *vsi_ctx, 204 struct ice_sq_cd *cd); 205 enum ice_status 206 ice_free_vsi(struct ice_hw *hw, u16 vsi_handle, struct ice_vsi_ctx *vsi_ctx, 207 bool keep_vsi_alloc, struct ice_sq_cd *cd); 208 enum ice_status 209 ice_update_vsi(struct ice_hw *hw, u16 vsi_handle, struct ice_vsi_ctx *vsi_ctx, 210 struct ice_sq_cd *cd); 211 bool ice_is_vsi_valid(struct ice_hw *hw, u16 vsi_handle); 212 struct ice_vsi_ctx *ice_get_vsi_ctx(struct ice_hw *hw, u16 vsi_handle); 213 void ice_clear_all_vsi_ctx(struct ice_hw *hw); 214 /* Switch config */ 215 enum ice_status ice_get_initial_sw_cfg(struct ice_hw *hw); 216 217 /* Switch/bridge related commands */ 218 enum ice_status ice_update_sw_rule_bridge_mode(struct ice_hw *hw); 219 enum ice_status ice_add_mac(struct ice_hw *hw, struct list_head *m_lst); 220 enum ice_status ice_remove_mac(struct ice_hw *hw, struct list_head *m_lst); 221 enum ice_status 222 ice_add_eth_mac(struct ice_hw *hw, struct list_head *em_list); 223 enum ice_status 224 ice_remove_eth_mac(struct ice_hw *hw, struct list_head *em_list); 225 void ice_remove_vsi_fltr(struct ice_hw *hw, u16 vsi_handle); 226 enum ice_status 227 ice_add_vlan(struct ice_hw *hw, struct list_head *m_list); 228 enum ice_status ice_remove_vlan(struct ice_hw *hw, struct list_head *v_list); 229 230 /* Promisc/defport setup for VSIs */ 231 enum ice_status 232 ice_cfg_dflt_vsi(struct ice_hw *hw, u16 vsi_handle, bool set, u8 direction); 233 enum ice_status 234 ice_set_vsi_promisc(struct ice_hw *hw, u16 vsi_handle, u8 promisc_mask, 235 u16 vid); 236 enum ice_status 237 ice_clear_vsi_promisc(struct ice_hw *hw, u16 vsi_handle, u8 promisc_mask, 238 u16 vid); 239 enum ice_status 240 ice_set_vlan_vsi_promisc(struct ice_hw *hw, u16 vsi_handle, u8 promisc_mask, 241 bool rm_vlan_promisc); 242 243 enum ice_status ice_init_def_sw_recp(struct ice_hw *hw); 244 u16 ice_get_hw_vsi_num(struct ice_hw *hw, u16 vsi_handle); 245 bool ice_is_vsi_valid(struct ice_hw *hw, u16 vsi_handle); 246 247 enum ice_status ice_replay_vsi_all_fltr(struct ice_hw *hw, u16 vsi_handle); 248 void ice_rm_all_sw_replay_rule_info(struct ice_hw *hw); 249 250 #endif /* _ICE_SWITCH_H_ */ 251