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