1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* Copyright (c) 2018, Intel Corporation. */
7 #include "ice_common.h"
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
17 /* VSI queue context structure */
22 /* VSI context structure for add/get/update/free operations */
28 struct ice_aqc_vsi_props info;
29 struct ice_sched_vsi_info sched;
32 u16 num_lan_q_entries[ICE_MAX_TRAFFIC_CLASS];
33 struct ice_q_ctx *lan_q_ctx[ICE_MAX_TRAFFIC_CLASS];
36 enum ice_sw_fwd_act_type {
38 ICE_FWD_TO_VSI_LIST, /* Do not use this when adding filter */
45 /* Switch recipe ID enum values are specific to hardware */
46 enum ice_sw_lkup_type {
47 ICE_SW_LKUP_ETHERTYPE = 0,
49 ICE_SW_LKUP_MAC_VLAN = 2,
50 ICE_SW_LKUP_PROMISC = 3,
53 ICE_SW_LKUP_ETHERTYPE_MAC = 8,
54 ICE_SW_LKUP_PROMISC_VLAN = 9,
58 /* type of filter src ID */
60 ICE_SRC_ID_UNKNOWN = 0,
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 */
75 /* Source VSI for LOOKUP_TX or source port for LOOKUP_RX */
77 enum ice_src_id src_id;
81 u8 mac_addr[ETH_ALEN];
84 u8 mac_addr[ETH_ALEN];
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.
97 u8 mac_addr[ETH_ALEN]; /* optional */
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
104 /* Depending on filter action */
106 /* queue ID in case of ICE_FWD_TO_Q and starting
107 * queue ID in case of ICE_FWD_TO_QGRP.
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.
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 */
128 struct ice_sw_recipe {
129 struct list_head l_entry;
131 /* To protect modification of filt_rule list
134 struct mutex filt_rule_lock;
136 /* List of type ice_fltr_mgmt_list_entry */
137 struct list_head filt_rules;
138 struct list_head filt_replay_rules;
140 /* linked list of type recipe_list_entry */
141 struct list_head rg_list;
142 /* linked list of type ice_sw_fv_list_entry*/
143 struct list_head fv_list;
144 struct ice_aqc_recipe_data_elem *r_buf;
150 /* recipe bitmap: what all recipes makes this recipe */
151 DECLARE_BITMAP(r_bitmap, ICE_MAX_NUM_RECIPES);
154 /* Bookkeeping structure to hold bitmap of VSIs corresponding to VSI list ID */
155 struct ice_vsi_list_map_info {
156 struct list_head list_entry;
157 DECLARE_BITMAP(vsi_map, ICE_MAX_VSI);
159 /* counter to track how many rules are reusing this VSI list */
163 struct ice_fltr_list_entry {
164 struct list_head list_entry;
165 enum ice_status status;
166 struct ice_fltr_info fltr_info;
169 /* This defines an entry in the list that maintains MAC or VLAN membership
170 * to HW list mapping, since multiple VSIs can subscribe to the same MAC or
171 * VLAN. As an optimization the VSI list should be created only when a
172 * second VSI becomes a subscriber to the same MAC address. VSI lists are always
173 * used for VLAN membership.
175 struct ice_fltr_mgmt_list_entry {
176 /* back pointer to VSI list ID to VSI list mapping */
177 struct ice_vsi_list_map_info *vsi_list_info;
179 #define ICE_INVAL_LG_ACT_INDEX 0xffff
181 #define ICE_INVAL_SW_MARKER_ID 0xffff
183 struct list_head list_entry;
184 struct ice_fltr_info fltr_info;
185 #define ICE_INVAL_COUNTER_ID 0xff
189 enum ice_promisc_flags {
190 ICE_PROMISC_UCAST_RX = 0x1,
191 ICE_PROMISC_UCAST_TX = 0x2,
192 ICE_PROMISC_MCAST_RX = 0x4,
193 ICE_PROMISC_MCAST_TX = 0x8,
194 ICE_PROMISC_BCAST_RX = 0x10,
195 ICE_PROMISC_BCAST_TX = 0x20,
196 ICE_PROMISC_VLAN_RX = 0x40,
197 ICE_PROMISC_VLAN_TX = 0x80,
200 /* VSI related commands */
202 ice_add_vsi(struct ice_hw *hw, u16 vsi_handle, struct ice_vsi_ctx *vsi_ctx,
203 struct ice_sq_cd *cd);
205 ice_free_vsi(struct ice_hw *hw, u16 vsi_handle, struct ice_vsi_ctx *vsi_ctx,
206 bool keep_vsi_alloc, struct ice_sq_cd *cd);
208 ice_update_vsi(struct ice_hw *hw, u16 vsi_handle, struct ice_vsi_ctx *vsi_ctx,
209 struct ice_sq_cd *cd);
210 bool ice_is_vsi_valid(struct ice_hw *hw, u16 vsi_handle);
211 struct ice_vsi_ctx *ice_get_vsi_ctx(struct ice_hw *hw, u16 vsi_handle);
212 void ice_clear_all_vsi_ctx(struct ice_hw *hw);
214 enum ice_status ice_get_initial_sw_cfg(struct ice_hw *hw);
216 /* Switch/bridge related commands */
217 enum ice_status ice_update_sw_rule_bridge_mode(struct ice_hw *hw);
218 enum ice_status ice_add_mac(struct ice_hw *hw, struct list_head *m_lst);
219 enum ice_status ice_remove_mac(struct ice_hw *hw, struct list_head *m_lst);
221 ice_add_eth_mac(struct ice_hw *hw, struct list_head *em_list);
223 ice_remove_eth_mac(struct ice_hw *hw, struct list_head *em_list);
224 void ice_remove_vsi_fltr(struct ice_hw *hw, u16 vsi_handle);
226 ice_add_vlan(struct ice_hw *hw, struct list_head *m_list);
227 enum ice_status ice_remove_vlan(struct ice_hw *hw, struct list_head *v_list);
229 /* Promisc/defport setup for VSIs */
231 ice_cfg_dflt_vsi(struct ice_hw *hw, u16 vsi_handle, bool set, u8 direction);
233 ice_set_vsi_promisc(struct ice_hw *hw, u16 vsi_handle, u8 promisc_mask,
236 ice_clear_vsi_promisc(struct ice_hw *hw, u16 vsi_handle, u8 promisc_mask,
239 ice_set_vlan_vsi_promisc(struct ice_hw *hw, u16 vsi_handle, u8 promisc_mask,
240 bool rm_vlan_promisc);
242 enum ice_status ice_init_def_sw_recp(struct ice_hw *hw);
243 u16 ice_get_hw_vsi_num(struct ice_hw *hw, u16 vsi_handle);
244 bool ice_is_vsi_valid(struct ice_hw *hw, u16 vsi_handle);
246 enum ice_status ice_replay_vsi_all_fltr(struct ice_hw *hw, u16 vsi_handle);
247 void ice_rm_all_sw_replay_rule_info(struct ice_hw *hw);
249 #endif /* _ICE_SWITCH_H_ */