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