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