1 /* SPDX-License-Identifier: BSD-3-Clause */
2 /* Copyright (c) 2021, Intel Corporation
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * 3. Neither the name of the Intel Corporation nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31 /*$FreeBSD$*/
32
33 #ifndef _ICE_SWITCH_H_
34 #define _ICE_SWITCH_H_
35
36 #include "ice_common.h"
37 #include "ice_protocol_type.h"
38
39 #define ICE_SW_CFG_MAX_BUF_LEN 2048
40 #define ICE_MAX_SW 256
41 #define ICE_DFLT_VSI_INVAL 0xff
42 #define ICE_FLTR_RX BIT(0)
43 #define ICE_FLTR_TX BIT(1)
44 #define ICE_FLTR_TX_RX (ICE_FLTR_RX | ICE_FLTR_TX)
45
46 #define DUMMY_ETH_HDR_LEN 16
47 #define ICE_SW_RULE_RX_TX_ETH_HDR_SIZE \
48 (offsetof(struct ice_aqc_sw_rules_elem, pdata.lkup_tx_rx.hdr) + \
49 (DUMMY_ETH_HDR_LEN * \
50 sizeof(((struct ice_sw_rule_lkup_rx_tx *)0)->hdr[0])))
51 #define ICE_SW_RULE_RX_TX_NO_HDR_SIZE \
52 (offsetof(struct ice_aqc_sw_rules_elem, pdata.lkup_tx_rx.hdr))
53 #define ICE_SW_RULE_LG_ACT_SIZE(n) \
54 (offsetof(struct ice_aqc_sw_rules_elem, pdata.lg_act.act) + \
55 ((n) * sizeof(((struct ice_sw_rule_lg_act *)0)->act[0])))
56 #define ICE_SW_RULE_VSI_LIST_SIZE(n) \
57 (offsetof(struct ice_aqc_sw_rules_elem, pdata.vsi_list.vsi) + \
58 ((n) * sizeof(((struct ice_sw_rule_vsi_list *)0)->vsi[0])))
59
60 /* Worst case buffer length for ice_aqc_opc_get_res_alloc */
61 #define ICE_MAX_RES_TYPES 0x80
62 #define ICE_AQ_GET_RES_ALLOC_BUF_LEN \
63 (ICE_MAX_RES_TYPES * sizeof(struct ice_aqc_get_res_resp_elem))
64
65 #define ICE_VSI_INVAL_ID 0xFFFF
66 #define ICE_INVAL_Q_HANDLE 0xFFFF
67
68 /* VSI context structure for add/get/update/free operations */
69 struct ice_vsi_ctx {
70 u16 vsi_num;
71 u16 vsis_allocd;
72 u16 vsis_unallocated;
73 u16 flags;
74 struct ice_aqc_vsi_props info;
75 struct ice_sched_vsi_info sched;
76 u8 alloc_from_pool;
77 u8 vf_num;
78 u16 num_lan_q_entries[ICE_MAX_TRAFFIC_CLASS];
79 struct ice_q_ctx *lan_q_ctx[ICE_MAX_TRAFFIC_CLASS];
80 u16 num_rdma_q_entries[ICE_MAX_TRAFFIC_CLASS];
81 struct ice_q_ctx *rdma_q_ctx[ICE_MAX_TRAFFIC_CLASS];
82 };
83
84 /* This is to be used by add/update mirror rule Admin Queue command */
85 struct ice_mir_rule_buf {
86 u16 vsi_idx; /* VSI index */
87
88 /* For each VSI, user can specify whether corresponding VSI
89 * should be added/removed to/from mirror rule
90 *
91 * add mirror rule: this should always be TRUE.
92 * update mirror rule: add(true) or remove(false) VSI to/from
93 * mirror rule
94 */
95 u8 add;
96 };
97
98 /* Switch recipe ID enum values are specific to hardware */
99 enum ice_sw_lkup_type {
100 ICE_SW_LKUP_ETHERTYPE = 0,
101 ICE_SW_LKUP_MAC = 1,
102 ICE_SW_LKUP_MAC_VLAN = 2,
103 ICE_SW_LKUP_PROMISC = 3,
104 ICE_SW_LKUP_VLAN = 4,
105 ICE_SW_LKUP_DFLT = 5,
106 ICE_SW_LKUP_ETHERTYPE_MAC = 8,
107 ICE_SW_LKUP_PROMISC_VLAN = 9,
108 ICE_SW_LKUP_LAST
109 };
110
111 /* type of filter src ID */
112 enum ice_src_id {
113 ICE_SRC_ID_UNKNOWN = 0,
114 ICE_SRC_ID_VSI,
115 ICE_SRC_ID_QUEUE,
116 ICE_SRC_ID_LPORT,
117 };
118
119 struct ice_fltr_info {
120 /* Look up information: how to look up packet */
121 enum ice_sw_lkup_type lkup_type;
122 /* Forward action: filter action to do after lookup */
123 enum ice_sw_fwd_act_type fltr_act;
124 /* rule ID returned by firmware once filter rule is created */
125 u16 fltr_rule_id;
126 u16 flag;
127
128 /* Source VSI for LOOKUP_TX or source port for LOOKUP_RX */
129 u16 src;
130 enum ice_src_id src_id;
131
132 union {
133 struct {
134 u8 mac_addr[ETH_ALEN];
135 } mac;
136 struct {
137 u8 mac_addr[ETH_ALEN];
138 u16 vlan_id;
139 } mac_vlan;
140 struct {
141 u16 vlan_id;
142 u16 tpid;
143 u8 tpid_valid;
144 } vlan;
145 /* Set lkup_type as ICE_SW_LKUP_ETHERTYPE
146 * if just using ethertype as filter. Set lkup_type as
147 * ICE_SW_LKUP_ETHERTYPE_MAC if MAC also needs to be
148 * passed in as filter.
149 */
150 struct {
151 u16 ethertype;
152 u8 mac_addr[ETH_ALEN]; /* optional */
153 } ethertype_mac;
154 } l_data; /* Make sure to zero out the memory of l_data before using
155 * it or only set the data associated with lookup match
156 * rest everything should be zero
157 */
158
159 /* Depending on filter action */
160 union {
161 /* queue ID in case of ICE_FWD_TO_Q and starting
162 * queue ID in case of ICE_FWD_TO_QGRP.
163 */
164 u16 q_id:11;
165 u16 hw_vsi_id:10;
166 u16 vsi_list_id:10;
167 } fwd_id;
168
169 /* Sw VSI handle */
170 u16 vsi_handle;
171
172 /* Set to num_queues if action is ICE_FWD_TO_QGRP. This field
173 * determines the range of queues the packet needs to be forwarded to.
174 * Note that qgrp_size must be set to a power of 2.
175 */
176 u8 qgrp_size;
177
178 /* Rule creations populate these indicators basing on the switch type */
179 u8 lb_en; /* Indicate if packet can be looped back */
180 u8 lan_en; /* Indicate if packet can be forwarded to the uplink */
181 };
182
183 struct ice_adv_lkup_elem {
184 enum ice_protocol_type type;
185 union ice_prot_hdr h_u; /* Header values */
186 union ice_prot_hdr m_u; /* Mask of header values to match */
187 };
188
189 struct ice_sw_act_ctrl {
190 /* Source VSI for LOOKUP_TX or source port for LOOKUP_RX */
191 u16 src;
192 u16 flag;
193 enum ice_sw_fwd_act_type fltr_act;
194 /* Depending on filter action */
195 union {
196 /* This is a queue ID in case of ICE_FWD_TO_Q and starting
197 * queue ID in case of ICE_FWD_TO_QGRP.
198 */
199 u16 q_id:11;
200 u16 vsi_id:10;
201 u16 hw_vsi_id:10;
202 u16 vsi_list_id:10;
203 } fwd_id;
204 /* software VSI handle */
205 u16 vsi_handle;
206 u8 qgrp_size;
207 };
208
209 struct ice_rule_query_data {
210 /* Recipe ID for which the requested rule was added */
211 u16 rid;
212 /* Rule ID that was added or is supposed to be removed */
213 u16 rule_id;
214 /* vsi_handle for which Rule was added or is supposed to be removed */
215 u16 vsi_handle;
216 };
217
218 /*
219 * This structure allows to pass info about lb_en and lan_en
220 * flags to ice_add_adv_rule. Values in act would be used
221 * only if act_valid was set to true, otherwise dflt
222 * values would be used.
223 */
224 struct ice_adv_rule_flags_info {
225 u32 act;
226 u8 act_valid; /* indicate if flags in act are valid */
227 };
228
229 struct ice_adv_rule_info {
230 enum ice_sw_tunnel_type tun_type;
231 struct ice_sw_act_ctrl sw_act;
232 u32 priority;
233 u8 rx; /* true means LOOKUP_RX otherwise LOOKUP_TX */
234 u16 fltr_rule_id;
235 struct ice_adv_rule_flags_info flags_info;
236 };
237
238 /* A collection of one or more four word recipe */
239 struct ice_sw_recipe {
240 /* For a chained recipe the root recipe is what should be used for
241 * programming rules
242 */
243 u8 is_root;
244 u8 root_rid;
245 u8 recp_created;
246
247 /* Number of extraction words */
248 u8 n_ext_words;
249 /* Protocol ID and Offset pair (extraction word) to describe the
250 * recipe
251 */
252 struct ice_fv_word ext_words[ICE_MAX_CHAIN_WORDS];
253 u16 word_masks[ICE_MAX_CHAIN_WORDS];
254
255 /* if this recipe is a collection of other recipe */
256 u8 big_recp;
257
258 /* if this recipe is part of another bigger recipe then chain index
259 * corresponding to this recipe
260 */
261 u8 chain_idx;
262
263 /* if this recipe is a collection of other recipe then count of other
264 * recipes and recipe IDs of those recipes
265 */
266 u8 n_grp_count;
267
268 /* Bit map specifying the IDs associated with this group of recipe */
269 ice_declare_bitmap(r_bitmap, ICE_MAX_NUM_RECIPES);
270
271 enum ice_sw_tunnel_type tun_type;
272
273 /* List of type ice_fltr_mgmt_list_entry or adv_rule */
274 u8 adv_rule;
275 struct LIST_HEAD_TYPE filt_rules;
276 struct LIST_HEAD_TYPE filt_replay_rules;
277
278 struct ice_lock filt_rule_lock; /* protect filter rule structure */
279
280 /* Profiles this recipe should be associated with */
281 struct LIST_HEAD_TYPE fv_list;
282
283 /* Profiles this recipe is associated with */
284 u8 num_profs, *prof_ids;
285
286 /* Bit map for possible result indexes */
287 ice_declare_bitmap(res_idxs, ICE_MAX_FV_WORDS);
288
289 /* This allows user to specify the recipe priority.
290 * For now, this becomes 'fwd_priority' when recipe
291 * is created, usually recipes can have 'fwd' and 'join'
292 * priority.
293 */
294 u8 priority;
295
296 struct LIST_HEAD_TYPE rg_list;
297
298 /* AQ buffer associated with this recipe */
299 struct ice_aqc_recipe_data_elem *root_buf;
300 /* This struct saves the fv_words for a given lookup */
301 struct ice_prot_lkup_ext lkup_exts;
302 };
303
304 /* Bookkeeping structure to hold bitmap of VSIs corresponding to VSI list ID */
305 struct ice_vsi_list_map_info {
306 struct LIST_ENTRY_TYPE list_entry;
307 ice_declare_bitmap(vsi_map, ICE_MAX_VSI);
308 u16 vsi_list_id;
309 /* counter to track how many rules are reusing this VSI list */
310 u16 ref_cnt;
311 };
312
313 struct ice_fltr_list_entry {
314 struct LIST_ENTRY_TYPE list_entry;
315 enum ice_status status;
316 struct ice_fltr_info fltr_info;
317 };
318
319 /**
320 * enum ice_fltr_marker - Marker for syncing OS and driver filter lists
321 * @ICE_FLTR_NOT_FOUND: initial state, indicates filter has not been found
322 * @ICE_FLTR_FOUND: set when a filter has been found in both lists
323 *
324 * This enumeration is used to help sync an operating system provided filter
325 * list with the filters previously added.
326 *
327 * This is required for FreeBSD because the operating system does not provide
328 * individual indications of whether a filter has been added or deleted, but
329 * instead just notifies the driver with the entire new list.
330 *
331 * To use this marker state, the driver shall initially reset all filters to
332 * the ICE_FLTR_NOT_FOUND state. Then, for each filter in the OS list, it
333 * shall search the driver list for the filter. If found, the filter state
334 * will be set to ICE_FLTR_FOUND. If not found, that filter will be added.
335 * Finally, the driver shall search the internal filter list for all filters
336 * still marked as ICE_FLTR_NOT_FOUND and remove them.
337 */
338 enum ice_fltr_marker {
339 ICE_FLTR_NOT_FOUND,
340 ICE_FLTR_FOUND,
341 };
342
343 /* This defines an entry in the list that maintains MAC or VLAN membership
344 * to HW list mapping, since multiple VSIs can subscribe to the same MAC or
345 * VLAN. As an optimization the VSI list should be created only when a
346 * second VSI becomes a subscriber to the same MAC address. VSI lists are always
347 * used for VLAN membership.
348 */
349 struct ice_fltr_mgmt_list_entry {
350 /* back pointer to VSI list ID to VSI list mapping */
351 struct ice_vsi_list_map_info *vsi_list_info;
352 u16 vsi_count;
353 #define ICE_INVAL_LG_ACT_INDEX 0xffff
354 u16 lg_act_idx;
355 #define ICE_INVAL_SW_MARKER_ID 0xffff
356 u16 sw_marker_id;
357 struct LIST_ENTRY_TYPE list_entry;
358 struct ice_fltr_info fltr_info;
359 #define ICE_INVAL_COUNTER_ID 0xff
360 u8 counter_index;
361 enum ice_fltr_marker marker;
362 };
363
364 struct ice_adv_fltr_mgmt_list_entry {
365 struct LIST_ENTRY_TYPE list_entry;
366
367 struct ice_adv_lkup_elem *lkups;
368 struct ice_adv_rule_info rule_info;
369 u16 lkups_cnt;
370 struct ice_vsi_list_map_info *vsi_list_info;
371 u16 vsi_count;
372 };
373
374 enum ice_promisc_flags {
375 ICE_PROMISC_UCAST_RX = 0x1,
376 ICE_PROMISC_UCAST_TX = 0x2,
377 ICE_PROMISC_MCAST_RX = 0x4,
378 ICE_PROMISC_MCAST_TX = 0x8,
379 ICE_PROMISC_BCAST_RX = 0x10,
380 ICE_PROMISC_BCAST_TX = 0x20,
381 ICE_PROMISC_VLAN_RX = 0x40,
382 ICE_PROMISC_VLAN_TX = 0x80,
383 };
384
385 /* VSI related commands */
386 enum ice_status
387 ice_aq_add_vsi(struct ice_hw *hw, struct ice_vsi_ctx *vsi_ctx,
388 struct ice_sq_cd *cd);
389 enum ice_status
390 ice_aq_free_vsi(struct ice_hw *hw, struct ice_vsi_ctx *vsi_ctx,
391 bool keep_vsi_alloc, struct ice_sq_cd *cd);
392 enum ice_status
393 ice_aq_update_vsi(struct ice_hw *hw, struct ice_vsi_ctx *vsi_ctx,
394 struct ice_sq_cd *cd);
395 enum ice_status
396 ice_add_vsi(struct ice_hw *hw, u16 vsi_handle, struct ice_vsi_ctx *vsi_ctx,
397 struct ice_sq_cd *cd);
398 enum ice_status
399 ice_free_vsi(struct ice_hw *hw, u16 vsi_handle, struct ice_vsi_ctx *vsi_ctx,
400 bool keep_vsi_alloc, struct ice_sq_cd *cd);
401 enum ice_status
402 ice_update_vsi(struct ice_hw *hw, u16 vsi_handle, struct ice_vsi_ctx *vsi_ctx,
403 struct ice_sq_cd *cd);
404 struct ice_vsi_ctx *ice_get_vsi_ctx(struct ice_hw *hw, u16 vsi_handle);
405 void ice_clear_all_vsi_ctx(struct ice_hw *hw);
406 enum ice_status
407 ice_aq_get_vsi_params(struct ice_hw *hw, struct ice_vsi_ctx *vsi_ctx,
408 struct ice_sq_cd *cd);
409 enum ice_status
410 ice_aq_add_update_mir_rule(struct ice_hw *hw, u16 rule_type, u16 dest_vsi,
411 u16 count, struct ice_mir_rule_buf *mr_buf,
412 struct ice_sq_cd *cd, u16 *rule_id);
413 enum ice_status
414 ice_aq_delete_mir_rule(struct ice_hw *hw, u16 rule_id, bool keep_allocd,
415 struct ice_sq_cd *cd);
416 enum ice_status
417 ice_aq_get_storm_ctrl(struct ice_hw *hw, u32 *bcast_thresh, u32 *mcast_thresh,
418 u32 *ctl_bitmask);
419 enum ice_status
420 ice_aq_set_storm_ctrl(struct ice_hw *hw, u32 bcast_thresh, u32 mcast_thresh,
421 u32 ctl_bitmask);
422 /* Switch config */
423 enum ice_status ice_get_initial_sw_cfg(struct ice_hw *hw);
424
425 enum ice_status
426 ice_alloc_vlan_res_counter(struct ice_hw *hw, u16 *counter_id);
427 enum ice_status
428 ice_free_vlan_res_counter(struct ice_hw *hw, u16 counter_id);
429
430 enum ice_status ice_update_sw_rule_bridge_mode(struct ice_hw *hw);
431 enum ice_status ice_alloc_rss_global_lut(struct ice_hw *hw, bool shared_res, u16 *global_lut_id);
432 enum ice_status ice_free_rss_global_lut(struct ice_hw *hw, u16 global_lut_id);
433 enum ice_status
434 ice_alloc_sw(struct ice_hw *hw, bool ena_stats, bool shared_res, u16 *sw_id,
435 u16 *counter_id);
436 enum ice_status
437 ice_free_sw(struct ice_hw *hw, u16 sw_id, u16 counter_id);
438 enum ice_status
439 ice_aq_get_res_alloc(struct ice_hw *hw, u16 *num_entries,
440 struct ice_aqc_get_res_resp_elem *buf, u16 buf_size,
441 struct ice_sq_cd *cd);
442 enum ice_status
443 ice_aq_get_res_descs(struct ice_hw *hw, u16 num_entries,
444 struct ice_aqc_res_elem *buf, u16 buf_size, u16 res_type,
445 bool res_shared, u16 *desc_id, struct ice_sq_cd *cd);
446 enum ice_status
447 ice_add_vlan(struct ice_hw *hw, struct LIST_HEAD_TYPE *m_list);
448 enum ice_status
449 ice_remove_vlan(struct ice_hw *hw, struct LIST_HEAD_TYPE *v_list);
450 void ice_rem_all_sw_rules_info(struct ice_hw *hw);
451 enum ice_status ice_add_mac(struct ice_hw *hw, struct LIST_HEAD_TYPE *m_lst);
452 enum ice_status ice_remove_mac(struct ice_hw *hw, struct LIST_HEAD_TYPE *m_lst);
453 enum ice_status
454 ice_add_eth_mac(struct ice_hw *hw, struct LIST_HEAD_TYPE *em_list);
455 enum ice_status
456 ice_remove_eth_mac(struct ice_hw *hw, struct LIST_HEAD_TYPE *em_list);
457 enum ice_status
458 ice_cfg_iwarp_fltr(struct ice_hw *hw, u16 vsi_handle, bool enable);
459
460 enum ice_status
461 ice_add_mac_with_sw_marker(struct ice_hw *hw, struct ice_fltr_info *f_info,
462 u16 sw_marker);
463 enum ice_status
464 ice_add_mac_with_counter(struct ice_hw *hw, struct ice_fltr_info *f_info);
465 void ice_remove_vsi_fltr(struct ice_hw *hw, u16 vsi_handle);
466
467 /* Promisc/defport setup for VSIs */
468 enum ice_status
469 ice_cfg_dflt_vsi(struct ice_port_info *pi, u16 vsi_handle, bool set,
470 u8 direction);
471 enum ice_status
472 ice_set_vsi_promisc(struct ice_hw *hw, u16 vsi_handle, u8 promisc_mask,
473 u16 vid);
474 enum ice_status
475 ice_clear_vsi_promisc(struct ice_hw *hw, u16 vsi_handle, u8 promisc_mask,
476 u16 vid);
477 enum ice_status
478 ice_set_vlan_vsi_promisc(struct ice_hw *hw, u16 vsi_handle, u8 promisc_mask,
479 bool rm_vlan_promisc);
480
481 /* Get VSIs Promisc/defport settings */
482 enum ice_status
483 ice_get_vsi_promisc(struct ice_hw *hw, u16 vsi_handle, u8 *promisc_mask,
484 u16 *vid);
485 enum ice_status
486 ice_get_vsi_vlan_promisc(struct ice_hw *hw, u16 vsi_handle, u8 *promisc_mask,
487 u16 *vid);
488
489 enum ice_status ice_replay_all_fltr(struct ice_hw *hw);
490
491 enum ice_status
492 ice_init_def_sw_recp(struct ice_hw *hw, struct ice_sw_recipe **recp_list);
493 u16 ice_get_hw_vsi_num(struct ice_hw *hw, u16 vsi_handle);
494 bool ice_is_vsi_valid(struct ice_hw *hw, u16 vsi_handle);
495
496 enum ice_status
497 ice_replay_vsi_all_fltr(struct ice_hw *hw, struct ice_port_info *pi,
498 u16 vsi_handle);
499 void ice_rm_sw_replay_rule_info(struct ice_hw *hw, struct ice_switch_info *sw);
500 void ice_rm_all_sw_replay_rule_info(struct ice_hw *hw);
501 #endif /* _ICE_SWITCH_H_ */
Cache object: 71b81cef228c56b70c7208f0ed2b24e3
|