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