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 13 /* VSI context structure for add/get/update/free operations */ 14 struct ice_vsi_ctx { 15 u16 vsi_num; 16 u16 vsis_allocd; 17 u16 vsis_unallocated; 18 u16 flags; 19 struct ice_aqc_vsi_props info; 20 u8 alloc_from_pool; 21 }; 22 23 enum ice_sw_fwd_act_type { 24 ICE_FWD_TO_VSI = 0, 25 ICE_FWD_TO_VSI_LIST, /* Do not use this when adding filter */ 26 ICE_FWD_TO_Q, 27 ICE_FWD_TO_QGRP, 28 ICE_DROP_PACKET, 29 ICE_INVAL_ACT 30 }; 31 32 /* Switch recipe ID enum values are specific to hardware */ 33 enum ice_sw_lkup_type { 34 ICE_SW_LKUP_ETHERTYPE = 0, 35 ICE_SW_LKUP_MAC = 1, 36 ICE_SW_LKUP_MAC_VLAN = 2, 37 ICE_SW_LKUP_PROMISC = 3, 38 ICE_SW_LKUP_VLAN = 4, 39 ICE_SW_LKUP_DFLT = 5, 40 ICE_SW_LKUP_ETHERTYPE_MAC = 8, 41 ICE_SW_LKUP_PROMISC_VLAN = 9, 42 ICE_SW_LKUP_LAST 43 }; 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 57 /* Source VSI for LOOKUP_TX or source port for LOOKUP_RX */ 58 u16 src; 59 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; 81 82 /* Depending on filter action */ 83 union { 84 /* queue id in case of ICE_FWD_TO_Q and starting 85 * queue id in case of ICE_FWD_TO_QGRP. 86 */ 87 u16 q_id:11; 88 u16 vsi_id:10; 89 u16 vsi_list_id:10; 90 } fwd_id; 91 92 /* Set to num_queues if action is ICE_FWD_TO_QGRP. This field 93 * determines the range of queues the packet needs to be forwarded to 94 */ 95 u8 qgrp_size; 96 97 /* Rule creations populate these indicators basing on the switch type */ 98 u8 lb_en; /* Indicate if packet can be looped back */ 99 u8 lan_en; /* Indicate if packet can be forwarded to the uplink */ 100 }; 101 102 struct ice_sw_recipe { 103 struct list_head l_entry; 104 105 /* To protect modification of filt_rule list 106 * defined below 107 */ 108 struct mutex filt_rule_lock; 109 110 /* List of type ice_fltr_mgmt_list_entry */ 111 struct list_head filt_rules; 112 113 /* linked list of type recipe_list_entry */ 114 struct list_head rg_list; 115 /* linked list of type ice_sw_fv_list_entry*/ 116 struct list_head fv_list; 117 struct ice_aqc_recipe_data_elem *r_buf; 118 u8 recp_count; 119 u8 root_rid; 120 u8 num_profs; 121 u8 *prof_ids; 122 123 /* recipe bitmap: what all recipes makes this recipe */ 124 DECLARE_BITMAP(r_bitmap, ICE_MAX_NUM_RECIPES); 125 }; 126 127 /* Bookkeeping structure to hold bitmap of VSIs corresponding to VSI list id */ 128 struct ice_vsi_list_map_info { 129 struct list_head list_entry; 130 DECLARE_BITMAP(vsi_map, ICE_MAX_VSI); 131 u16 vsi_list_id; 132 }; 133 134 struct ice_fltr_list_entry { 135 struct list_head list_entry; 136 enum ice_status status; 137 struct ice_fltr_info fltr_info; 138 }; 139 140 /* This defines an entry in the list that maintains MAC or VLAN membership 141 * to HW list mapping, since multiple VSIs can subscribe to the same MAC or 142 * VLAN. As an optimization the VSI list should be created only when a 143 * second VSI becomes a subscriber to the VLAN address. 144 */ 145 struct ice_fltr_mgmt_list_entry { 146 /* back pointer to VSI list id to VSI list mapping */ 147 struct ice_vsi_list_map_info *vsi_list_info; 148 u16 vsi_count; 149 #define ICE_INVAL_LG_ACT_INDEX 0xffff 150 u16 lg_act_idx; 151 #define ICE_INVAL_SW_MARKER_ID 0xffff 152 u16 sw_marker_id; 153 struct list_head list_entry; 154 struct ice_fltr_info fltr_info; 155 #define ICE_INVAL_COUNTER_ID 0xff 156 u8 counter_index; 157 }; 158 159 /* VSI related commands */ 160 enum ice_status 161 ice_aq_update_vsi(struct ice_hw *hw, struct ice_vsi_ctx *vsi_ctx, 162 struct ice_sq_cd *cd); 163 enum ice_status 164 ice_add_vsi(struct ice_hw *hw, u16 vsi_handle, struct ice_vsi_ctx *vsi_ctx, 165 struct ice_sq_cd *cd); 166 enum ice_status 167 ice_free_vsi(struct ice_hw *hw, u16 vsi_handle, struct ice_vsi_ctx *vsi_ctx, 168 bool keep_vsi_alloc, struct ice_sq_cd *cd); 169 enum ice_status ice_get_initial_sw_cfg(struct ice_hw *hw); 170 171 /* Switch/bridge related commands */ 172 enum ice_status ice_update_sw_rule_bridge_mode(struct ice_hw *hw); 173 enum ice_status ice_add_mac(struct ice_hw *hw, struct list_head *m_lst); 174 enum ice_status ice_remove_mac(struct ice_hw *hw, struct list_head *m_lst); 175 void ice_remove_vsi_fltr(struct ice_hw *hw, u16 vsi_id); 176 enum ice_status ice_add_vlan(struct ice_hw *hw, struct list_head *m_list); 177 enum ice_status ice_remove_vlan(struct ice_hw *hw, struct list_head *v_list); 178 enum ice_status 179 ice_cfg_dflt_vsi(struct ice_hw *hw, u16 vsi_id, bool set, u8 direction); 180 181 enum ice_status ice_replay_all_fltr(struct ice_hw *hw); 182 183 enum ice_status ice_init_def_sw_recp(struct ice_hw *hw); 184 185 #endif /* _ICE_SWITCH_H_ */ 186