xref: /freebsd/sys/dev/ice/ice_switch.h (revision f2635e844dd138ac9dfba676f27d41750049af26)
171d10453SEric Joyner /* SPDX-License-Identifier: BSD-3-Clause */
2015f8cc5SEric Joyner /*  Copyright (c) 2024, Intel Corporation
371d10453SEric Joyner  *  All rights reserved.
471d10453SEric Joyner  *
571d10453SEric Joyner  *  Redistribution and use in source and binary forms, with or without
671d10453SEric Joyner  *  modification, are permitted provided that the following conditions are met:
771d10453SEric Joyner  *
871d10453SEric Joyner  *   1. Redistributions of source code must retain the above copyright notice,
971d10453SEric Joyner  *      this list of conditions and the following disclaimer.
1071d10453SEric Joyner  *
1171d10453SEric Joyner  *   2. Redistributions in binary form must reproduce the above copyright
1271d10453SEric Joyner  *      notice, this list of conditions and the following disclaimer in the
1371d10453SEric Joyner  *      documentation and/or other materials provided with the distribution.
1471d10453SEric Joyner  *
1571d10453SEric Joyner  *   3. Neither the name of the Intel Corporation nor the names of its
1671d10453SEric Joyner  *      contributors may be used to endorse or promote products derived from
1771d10453SEric Joyner  *      this software without specific prior written permission.
1871d10453SEric Joyner  *
1971d10453SEric Joyner  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
2071d10453SEric Joyner  *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2171d10453SEric Joyner  *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2271d10453SEric Joyner  *  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
2371d10453SEric Joyner  *  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2471d10453SEric Joyner  *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2571d10453SEric Joyner  *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2671d10453SEric Joyner  *  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2771d10453SEric Joyner  *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2871d10453SEric Joyner  *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2971d10453SEric Joyner  *  POSSIBILITY OF SUCH DAMAGE.
3071d10453SEric Joyner  */
3171d10453SEric Joyner 
3271d10453SEric Joyner #ifndef _ICE_SWITCH_H_
3371d10453SEric Joyner #define _ICE_SWITCH_H_
3471d10453SEric Joyner 
358923de59SPiotr Kubaj #include "ice_type.h"
3671d10453SEric Joyner #include "ice_protocol_type.h"
3771d10453SEric Joyner 
3871d10453SEric Joyner #define ICE_SW_CFG_MAX_BUF_LEN 2048
3971d10453SEric Joyner #define ICE_MAX_SW 256
4071d10453SEric Joyner #define ICE_DFLT_VSI_INVAL 0xff
419e54973fSEric Joyner 
4271d10453SEric Joyner #define ICE_FLTR_RX	BIT(0)
4371d10453SEric Joyner #define ICE_FLTR_TX	BIT(1)
449e54973fSEric Joyner #define ICE_FLTR_RX_LB	BIT(2)
4571d10453SEric Joyner #define ICE_FLTR_TX_RX	(ICE_FLTR_RX | ICE_FLTR_TX)
4671d10453SEric Joyner 
478923de59SPiotr Kubaj #define ICE_PROFID_IPV4_GTPC_TEID	41
488923de59SPiotr Kubaj #define ICE_PROFID_IPV4_GTPC_NO_TEID		42
498923de59SPiotr Kubaj #define ICE_PROFID_IPV4_GTPU_TEID		43
508923de59SPiotr Kubaj #define ICE_PROFID_IPV6_GTPC_TEID		44
518923de59SPiotr Kubaj #define ICE_PROFID_IPV6_GTPC_NO_TEID		45
528923de59SPiotr Kubaj #define ICE_PROFID_IPV6_GTPU_TEID		46
538923de59SPiotr Kubaj #define ICE_PROFID_IPV6_GTPU_IPV6_TCP		70
548923de59SPiotr Kubaj 
557d7af7f8SEric Joyner #define DUMMY_ETH_HDR_LEN		16
567d7af7f8SEric Joyner 
5771d10453SEric Joyner /* Worst case buffer length for ice_aqc_opc_get_res_alloc */
5871d10453SEric Joyner #define ICE_MAX_RES_TYPES 0x80
5971d10453SEric Joyner #define ICE_AQ_GET_RES_ALLOC_BUF_LEN \
6071d10453SEric Joyner 	(ICE_MAX_RES_TYPES * sizeof(struct ice_aqc_get_res_resp_elem))
6171d10453SEric Joyner 
6271d10453SEric Joyner #define ICE_VSI_INVAL_ID 0xFFFF
6371d10453SEric Joyner #define ICE_INVAL_Q_HANDLE 0xFFFF
6471d10453SEric Joyner 
6571d10453SEric Joyner /* VSI context structure for add/get/update/free operations */
6671d10453SEric Joyner struct ice_vsi_ctx {
6771d10453SEric Joyner 	u16 vsi_num;
6871d10453SEric Joyner 	u16 vsis_allocd;
6971d10453SEric Joyner 	u16 vsis_unallocated;
7071d10453SEric Joyner 	u16 flags;
7171d10453SEric Joyner 	struct ice_aqc_vsi_props info;
7271d10453SEric Joyner 	struct ice_sched_vsi_info sched;
7371d10453SEric Joyner 	u8 alloc_from_pool;
7471d10453SEric Joyner 	u8 vf_num;
7571d10453SEric Joyner 	u16 num_lan_q_entries[ICE_MAX_TRAFFIC_CLASS];
7671d10453SEric Joyner 	struct ice_q_ctx *lan_q_ctx[ICE_MAX_TRAFFIC_CLASS];
778a13362dSEric Joyner 	u16 num_rdma_q_entries[ICE_MAX_TRAFFIC_CLASS];
788a13362dSEric Joyner 	struct ice_q_ctx *rdma_q_ctx[ICE_MAX_TRAFFIC_CLASS];
7971d10453SEric Joyner };
8071d10453SEric Joyner 
8171d10453SEric Joyner /* This is to be used by add/update mirror rule Admin Queue command */
8271d10453SEric Joyner struct ice_mir_rule_buf {
8371d10453SEric Joyner 	u16 vsi_idx; /* VSI index */
8471d10453SEric Joyner 
8571d10453SEric Joyner 	/* For each VSI, user can specify whether corresponding VSI
8671d10453SEric Joyner 	 * should be added/removed to/from mirror rule
8771d10453SEric Joyner 	 *
8871d10453SEric Joyner 	 * add mirror rule: this should always be TRUE.
8971d10453SEric Joyner 	 * update mirror rule:  add(true) or remove(false) VSI to/from
9071d10453SEric Joyner 	 * mirror rule
9171d10453SEric Joyner 	 */
9271d10453SEric Joyner 	u8 add;
9371d10453SEric Joyner };
9471d10453SEric Joyner 
9571d10453SEric Joyner /* Switch recipe ID enum values are specific to hardware */
9671d10453SEric Joyner enum ice_sw_lkup_type {
9771d10453SEric Joyner 	ICE_SW_LKUP_ETHERTYPE = 0,
9871d10453SEric Joyner 	ICE_SW_LKUP_MAC = 1,
9971d10453SEric Joyner 	ICE_SW_LKUP_MAC_VLAN = 2,
10071d10453SEric Joyner 	ICE_SW_LKUP_PROMISC = 3,
10171d10453SEric Joyner 	ICE_SW_LKUP_VLAN = 4,
10271d10453SEric Joyner 	ICE_SW_LKUP_DFLT = 5,
10371d10453SEric Joyner 	ICE_SW_LKUP_ETHERTYPE_MAC = 8,
10471d10453SEric Joyner 	ICE_SW_LKUP_PROMISC_VLAN = 9,
10571d10453SEric Joyner 	ICE_SW_LKUP_LAST
10671d10453SEric Joyner };
10771d10453SEric Joyner 
10871d10453SEric Joyner /* type of filter src ID */
10971d10453SEric Joyner enum ice_src_id {
11071d10453SEric Joyner 	ICE_SRC_ID_UNKNOWN = 0,
11171d10453SEric Joyner 	ICE_SRC_ID_VSI,
11271d10453SEric Joyner 	ICE_SRC_ID_QUEUE,
11371d10453SEric Joyner 	ICE_SRC_ID_LPORT,
11471d10453SEric Joyner };
11571d10453SEric Joyner 
11671d10453SEric Joyner struct ice_fltr_info {
11771d10453SEric Joyner 	/* Look up information: how to look up packet */
11871d10453SEric Joyner 	enum ice_sw_lkup_type lkup_type;
11971d10453SEric Joyner 	/* Forward action: filter action to do after lookup */
12071d10453SEric Joyner 	enum ice_sw_fwd_act_type fltr_act;
12171d10453SEric Joyner 	/* rule ID returned by firmware once filter rule is created */
12271d10453SEric Joyner 	u16 fltr_rule_id;
12371d10453SEric Joyner 	u16 flag;
12471d10453SEric Joyner 
12571d10453SEric Joyner 	/* Source VSI for LOOKUP_TX or source port for LOOKUP_RX */
12671d10453SEric Joyner 	u16 src;
12771d10453SEric Joyner 	enum ice_src_id src_id;
12871d10453SEric Joyner 
12971d10453SEric Joyner 	union {
13071d10453SEric Joyner 		struct {
13171d10453SEric Joyner 			u8 mac_addr[ETH_ALEN];
132*f2635e84SEric Joyner 			u16 sw_id;
13371d10453SEric Joyner 		} mac;
13471d10453SEric Joyner 		struct {
13571d10453SEric Joyner 			u8 mac_addr[ETH_ALEN];
13671d10453SEric Joyner 			u16 vlan_id;
13771d10453SEric Joyner 		} mac_vlan;
13871d10453SEric Joyner 		struct {
13971d10453SEric Joyner 			u16 vlan_id;
1409cf1841cSEric Joyner 			u16 tpid;
1419cf1841cSEric Joyner 			u8 tpid_valid;
142*f2635e84SEric Joyner 			u16 sw_id;
14371d10453SEric Joyner 		} vlan;
14471d10453SEric Joyner 		/* Set lkup_type as ICE_SW_LKUP_ETHERTYPE
14571d10453SEric Joyner 		 * if just using ethertype as filter. Set lkup_type as
14671d10453SEric Joyner 		 * ICE_SW_LKUP_ETHERTYPE_MAC if MAC also needs to be
14771d10453SEric Joyner 		 * passed in as filter.
14871d10453SEric Joyner 		 */
14971d10453SEric Joyner 		struct {
15071d10453SEric Joyner 			u16 ethertype;
15171d10453SEric Joyner 			u8 mac_addr[ETH_ALEN]; /* optional */
15271d10453SEric Joyner 		} ethertype_mac;
15371d10453SEric Joyner 	} l_data; /* Make sure to zero out the memory of l_data before using
15471d10453SEric Joyner 		   * it or only set the data associated with lookup match
15571d10453SEric Joyner 		   * rest everything should be zero
15671d10453SEric Joyner 		   */
15771d10453SEric Joyner 
15871d10453SEric Joyner 	/* Depending on filter action */
15971d10453SEric Joyner 	union {
16071d10453SEric Joyner 		/* queue ID in case of ICE_FWD_TO_Q and starting
16171d10453SEric Joyner 		 * queue ID in case of ICE_FWD_TO_QGRP.
16271d10453SEric Joyner 		 */
16371d10453SEric Joyner 		u16 q_id:11;
16471d10453SEric Joyner 		u16 hw_vsi_id:10;
16571d10453SEric Joyner 		u16 vsi_list_id:10;
16671d10453SEric Joyner 	} fwd_id;
16771d10453SEric Joyner 
16871d10453SEric Joyner 	/* Sw VSI handle */
16971d10453SEric Joyner 	u16 vsi_handle;
17071d10453SEric Joyner 
17171d10453SEric Joyner 	/* Set to num_queues if action is ICE_FWD_TO_QGRP. This field
17271d10453SEric Joyner 	 * determines the range of queues the packet needs to be forwarded to.
17371d10453SEric Joyner 	 * Note that qgrp_size must be set to a power of 2.
17471d10453SEric Joyner 	 */
17571d10453SEric Joyner 	u8 qgrp_size;
17671d10453SEric Joyner 
17771d10453SEric Joyner 	/* Rule creations populate these indicators basing on the switch type */
17871d10453SEric Joyner 	u8 lb_en;	/* Indicate if packet can be looped back */
17971d10453SEric Joyner 	u8 lan_en;	/* Indicate if packet can be forwarded to the uplink */
180*f2635e84SEric Joyner 	u8 fltVeb_en;   /* Indicate if VSI is connected to floating VEB */
18171d10453SEric Joyner };
18271d10453SEric Joyner 
18371d10453SEric Joyner struct ice_adv_lkup_elem {
18471d10453SEric Joyner 	enum ice_protocol_type type;
18571d10453SEric Joyner 	union ice_prot_hdr h_u;	/* Header values */
18671d10453SEric Joyner 	union ice_prot_hdr m_u;	/* Mask of header values to match */
18771d10453SEric Joyner };
18871d10453SEric Joyner 
1899c30461dSEric Joyner struct entry_vsi_fwd {
1909c30461dSEric Joyner 	u16 vsi_list;
1919c30461dSEric Joyner 	u8 list;
1929c30461dSEric Joyner 	u8 valid;
1939c30461dSEric Joyner };
1949c30461dSEric Joyner 
1959c30461dSEric Joyner struct entry_to_q {
1969c30461dSEric Joyner 	u16 q_idx;
1979c30461dSEric Joyner 	u8 q_region_sz;
1989c30461dSEric Joyner 	u8 q_pri;
1999c30461dSEric Joyner };
2009c30461dSEric Joyner 
2019c30461dSEric Joyner struct entry_prune {
2029c30461dSEric Joyner 	u16 vsi_list;
2039c30461dSEric Joyner 	u8 list;
2049c30461dSEric Joyner 	u8 egr;
2059c30461dSEric Joyner 	u8 ing;
2069c30461dSEric Joyner 	u8 prune_t;
2079c30461dSEric Joyner };
2089c30461dSEric Joyner 
2099c30461dSEric Joyner struct entry_mirror {
2109c30461dSEric Joyner 	u16 mirror_vsi;
2119c30461dSEric Joyner };
2129c30461dSEric Joyner 
2139c30461dSEric Joyner struct entry_generic_act {
2149c30461dSEric Joyner 	u16 generic_value;
2159c30461dSEric Joyner 	u8 offset;
2169c30461dSEric Joyner 	u8 priority;
2179c30461dSEric Joyner };
2189c30461dSEric Joyner 
2199c30461dSEric Joyner struct entry_statistics {
2209c30461dSEric Joyner 	u8 counter_idx;
2219c30461dSEric Joyner };
2229c30461dSEric Joyner 
22371d10453SEric Joyner struct ice_sw_act_ctrl {
22471d10453SEric Joyner 	/* Source VSI for LOOKUP_TX or source port for LOOKUP_RX */
22571d10453SEric Joyner 	u16 src;
22671d10453SEric Joyner 	u16 flag;
22771d10453SEric Joyner 	enum ice_sw_fwd_act_type fltr_act;
22871d10453SEric Joyner 	/* Depending on filter action */
22971d10453SEric Joyner 	union {
23071d10453SEric Joyner 		/* This is a queue ID in case of ICE_FWD_TO_Q and starting
23171d10453SEric Joyner 		 * queue ID in case of ICE_FWD_TO_QGRP.
23271d10453SEric Joyner 		 */
23371d10453SEric Joyner 		u16 q_id:11;
23471d10453SEric Joyner 		u16 vsi_id:10;
23571d10453SEric Joyner 		u16 hw_vsi_id:10;
23671d10453SEric Joyner 		u16 vsi_list_id:10;
23771d10453SEric Joyner 	} fwd_id;
23871d10453SEric Joyner 	/* software VSI handle */
23971d10453SEric Joyner 	u16 vsi_handle;
24071d10453SEric Joyner 	u8 qgrp_size;
24171d10453SEric Joyner };
24271d10453SEric Joyner 
24371d10453SEric Joyner struct ice_rule_query_data {
24471d10453SEric Joyner 	/* Recipe ID for which the requested rule was added */
24571d10453SEric Joyner 	u16 rid;
24671d10453SEric Joyner 	/* Rule ID that was added or is supposed to be removed */
24771d10453SEric Joyner 	u16 rule_id;
24871d10453SEric Joyner 	/* vsi_handle for which Rule was added or is supposed to be removed */
24971d10453SEric Joyner 	u16 vsi_handle;
25071d10453SEric Joyner };
25171d10453SEric Joyner 
25256429daeSEric Joyner /*
25356429daeSEric Joyner  * This structure allows to pass info about lb_en and lan_en
25456429daeSEric Joyner  * flags to ice_add_adv_rule. Values in act would be used
25556429daeSEric Joyner  * only if act_valid was set to true, otherwise dflt
25656429daeSEric Joyner  * values would be used.
25756429daeSEric Joyner  */
25856429daeSEric Joyner struct ice_adv_rule_flags_info {
25956429daeSEric Joyner 	u32 act;
26056429daeSEric Joyner 	u8 act_valid;		/* indicate if flags in act are valid */
26156429daeSEric Joyner };
26256429daeSEric Joyner 
26371d10453SEric Joyner struct ice_adv_rule_info {
26471d10453SEric Joyner 	enum ice_sw_tunnel_type tun_type;
26571d10453SEric Joyner 	struct ice_sw_act_ctrl sw_act;
26671d10453SEric Joyner 	u32 priority;
26771d10453SEric Joyner 	u8 rx; /* true means LOOKUP_RX otherwise LOOKUP_TX */
2689dc2f6e2SEric Joyner 	u8 add_dir_lkup;
26971d10453SEric Joyner 	u16 fltr_rule_id;
2708923de59SPiotr Kubaj 	u16 lg_id;
2719dc2f6e2SEric Joyner 	u16 vlan_type;
27256429daeSEric Joyner 	struct ice_adv_rule_flags_info flags_info;
27371d10453SEric Joyner };
27471d10453SEric Joyner 
27571d10453SEric Joyner /* A collection of one or more four word recipe */
27671d10453SEric Joyner struct ice_sw_recipe {
27771d10453SEric Joyner 	/* For a chained recipe the root recipe is what should be used for
27871d10453SEric Joyner 	 * programming rules
27971d10453SEric Joyner 	 */
28071d10453SEric Joyner 	u8 is_root;
28171d10453SEric Joyner 	u8 root_rid;
28271d10453SEric Joyner 	u8 recp_created;
28371d10453SEric Joyner 
28471d10453SEric Joyner 	/* Number of extraction words */
28571d10453SEric Joyner 	u8 n_ext_words;
28671d10453SEric Joyner 	/* Protocol ID and Offset pair (extraction word) to describe the
28771d10453SEric Joyner 	 * recipe
28871d10453SEric Joyner 	 */
28971d10453SEric Joyner 	struct ice_fv_word ext_words[ICE_MAX_CHAIN_WORDS];
29071d10453SEric Joyner 	u16 word_masks[ICE_MAX_CHAIN_WORDS];
29171d10453SEric Joyner 
29271d10453SEric Joyner 	/* if this recipe is a collection of other recipe */
29371d10453SEric Joyner 	u8 big_recp;
29471d10453SEric Joyner 
29571d10453SEric Joyner 	/* if this recipe is part of another bigger recipe then chain index
29671d10453SEric Joyner 	 * corresponding to this recipe
29771d10453SEric Joyner 	 */
29871d10453SEric Joyner 	u8 chain_idx;
29971d10453SEric Joyner 
30071d10453SEric Joyner 	/* if this recipe is a collection of other recipe then count of other
30171d10453SEric Joyner 	 * recipes and recipe IDs of those recipes
30271d10453SEric Joyner 	 */
30371d10453SEric Joyner 	u8 n_grp_count;
30471d10453SEric Joyner 
30571d10453SEric Joyner 	/* Bit map specifying the IDs associated with this group of recipe */
30671d10453SEric Joyner 	ice_declare_bitmap(r_bitmap, ICE_MAX_NUM_RECIPES);
30771d10453SEric Joyner 
30871d10453SEric Joyner 	enum ice_sw_tunnel_type tun_type;
30971d10453SEric Joyner 
31071d10453SEric Joyner 	/* List of type ice_fltr_mgmt_list_entry or adv_rule */
31171d10453SEric Joyner 	u8 adv_rule;
31271d10453SEric Joyner 	struct LIST_HEAD_TYPE filt_rules;
31371d10453SEric Joyner 	struct LIST_HEAD_TYPE filt_replay_rules;
31471d10453SEric Joyner 
31571d10453SEric Joyner 	struct ice_lock filt_rule_lock;	/* protect filter rule structure */
31671d10453SEric Joyner 
31771d10453SEric Joyner 	/* Profiles this recipe should be associated with */
31871d10453SEric Joyner 	struct LIST_HEAD_TYPE fv_list;
31971d10453SEric Joyner 
32071d10453SEric Joyner 	/* Profiles this recipe is associated with */
32171d10453SEric Joyner 	u8 num_profs, *prof_ids;
32271d10453SEric Joyner 
3237d7af7f8SEric Joyner 	/* Bit map for possible result indexes */
32471d10453SEric Joyner 	ice_declare_bitmap(res_idxs, ICE_MAX_FV_WORDS);
32571d10453SEric Joyner 
32671d10453SEric Joyner 	/* This allows user to specify the recipe priority.
32771d10453SEric Joyner 	 * For now, this becomes 'fwd_priority' when recipe
32871d10453SEric Joyner 	 * is created, usually recipes can have 'fwd' and 'join'
32971d10453SEric Joyner 	 * priority.
33071d10453SEric Joyner 	 */
33171d10453SEric Joyner 	u8 priority;
33271d10453SEric Joyner 
33371d10453SEric Joyner 	struct LIST_HEAD_TYPE rg_list;
33471d10453SEric Joyner 
33571d10453SEric Joyner 	/* AQ buffer associated with this recipe */
33671d10453SEric Joyner 	struct ice_aqc_recipe_data_elem *root_buf;
33771d10453SEric Joyner 	/* This struct saves the fv_words for a given lookup */
33871d10453SEric Joyner 	struct ice_prot_lkup_ext lkup_exts;
33971d10453SEric Joyner };
34071d10453SEric Joyner 
34171d10453SEric Joyner /* Bookkeeping structure to hold bitmap of VSIs corresponding to VSI list ID */
34271d10453SEric Joyner struct ice_vsi_list_map_info {
34371d10453SEric Joyner 	struct LIST_ENTRY_TYPE list_entry;
34471d10453SEric Joyner 	ice_declare_bitmap(vsi_map, ICE_MAX_VSI);
34571d10453SEric Joyner 	u16 vsi_list_id;
34671d10453SEric Joyner 	/* counter to track how many rules are reusing this VSI list */
34771d10453SEric Joyner 	u16 ref_cnt;
34871d10453SEric Joyner };
34971d10453SEric Joyner 
35071d10453SEric Joyner struct ice_fltr_list_entry {
35171d10453SEric Joyner 	struct LIST_ENTRY_TYPE list_entry;
352*f2635e84SEric Joyner 	int status;
35371d10453SEric Joyner 	struct ice_fltr_info fltr_info;
35471d10453SEric Joyner };
35571d10453SEric Joyner 
35671d10453SEric Joyner /**
35771d10453SEric Joyner  * enum ice_fltr_marker - Marker for syncing OS and driver filter lists
35871d10453SEric Joyner  * @ICE_FLTR_NOT_FOUND: initial state, indicates filter has not been found
35971d10453SEric Joyner  * @ICE_FLTR_FOUND: set when a filter has been found in both lists
36071d10453SEric Joyner  *
36171d10453SEric Joyner  * This enumeration is used to help sync an operating system provided filter
36271d10453SEric Joyner  * list with the filters previously added.
36371d10453SEric Joyner  *
36471d10453SEric Joyner  * This is required for FreeBSD because the operating system does not provide
36571d10453SEric Joyner  * individual indications of whether a filter has been added or deleted, but
36671d10453SEric Joyner  * instead just notifies the driver with the entire new list.
36771d10453SEric Joyner  *
36871d10453SEric Joyner  * To use this marker state, the driver shall initially reset all filters to
36971d10453SEric Joyner  * the ICE_FLTR_NOT_FOUND state. Then, for each filter in the OS list, it
37071d10453SEric Joyner  * shall search the driver list for the filter. If found, the filter state
37171d10453SEric Joyner  * will be set to ICE_FLTR_FOUND. If not found, that filter will be added.
37271d10453SEric Joyner  * Finally, the driver shall search the internal filter list for all filters
37371d10453SEric Joyner  * still marked as ICE_FLTR_NOT_FOUND and remove them.
37471d10453SEric Joyner  */
37571d10453SEric Joyner enum ice_fltr_marker {
37671d10453SEric Joyner 	ICE_FLTR_NOT_FOUND,
37771d10453SEric Joyner 	ICE_FLTR_FOUND,
37871d10453SEric Joyner };
37971d10453SEric Joyner 
38071d10453SEric Joyner /* This defines an entry in the list that maintains MAC or VLAN membership
38171d10453SEric Joyner  * to HW list mapping, since multiple VSIs can subscribe to the same MAC or
38271d10453SEric Joyner  * VLAN. As an optimization the VSI list should be created only when a
38371d10453SEric Joyner  * second VSI becomes a subscriber to the same MAC address. VSI lists are always
38471d10453SEric Joyner  * used for VLAN membership.
38571d10453SEric Joyner  */
38671d10453SEric Joyner struct ice_fltr_mgmt_list_entry {
38771d10453SEric Joyner 	/* back pointer to VSI list ID to VSI list mapping */
38871d10453SEric Joyner 	struct ice_vsi_list_map_info *vsi_list_info;
38971d10453SEric Joyner 	u16 vsi_count;
39071d10453SEric Joyner #define ICE_INVAL_LG_ACT_INDEX 0xffff
39171d10453SEric Joyner 	u16 lg_act_idx;
39271d10453SEric Joyner #define ICE_INVAL_SW_MARKER_ID 0xffff
39371d10453SEric Joyner 	u16 sw_marker_id;
39471d10453SEric Joyner 	struct LIST_ENTRY_TYPE list_entry;
39571d10453SEric Joyner 	struct ice_fltr_info fltr_info;
39671d10453SEric Joyner #define ICE_INVAL_COUNTER_ID 0xff
39771d10453SEric Joyner 	u8 counter_index;
39871d10453SEric Joyner 	enum ice_fltr_marker marker;
39971d10453SEric Joyner };
40071d10453SEric Joyner 
40171d10453SEric Joyner struct ice_adv_fltr_mgmt_list_entry {
40271d10453SEric Joyner 	struct LIST_ENTRY_TYPE list_entry;
40371d10453SEric Joyner 
40471d10453SEric Joyner 	struct ice_adv_lkup_elem *lkups;
40571d10453SEric Joyner 	struct ice_adv_rule_info rule_info;
40671d10453SEric Joyner 	u16 lkups_cnt;
40771d10453SEric Joyner 	struct ice_vsi_list_map_info *vsi_list_info;
40871d10453SEric Joyner 	u16 vsi_count;
40971d10453SEric Joyner };
41071d10453SEric Joyner 
41171d10453SEric Joyner enum ice_promisc_flags {
4129c30461dSEric Joyner 	ICE_PROMISC_UCAST_RX = 0,
4139c30461dSEric Joyner 	ICE_PROMISC_UCAST_TX,
4149c30461dSEric Joyner 	ICE_PROMISC_MCAST_RX,
4159c30461dSEric Joyner 	ICE_PROMISC_MCAST_TX,
4169c30461dSEric Joyner 	ICE_PROMISC_BCAST_RX,
4179c30461dSEric Joyner 	ICE_PROMISC_BCAST_TX,
4189c30461dSEric Joyner 	ICE_PROMISC_VLAN_RX,
4199c30461dSEric Joyner 	ICE_PROMISC_VLAN_TX,
4209e54973fSEric Joyner 	ICE_PROMISC_UCAST_RX_LB,
4219c30461dSEric Joyner 	/* Max value */
4229c30461dSEric Joyner 	ICE_PROMISC_MAX,
42371d10453SEric Joyner };
42471d10453SEric Joyner 
4258923de59SPiotr Kubaj struct ice_dummy_pkt_offsets {
4268923de59SPiotr Kubaj 	enum ice_protocol_type type;
4278923de59SPiotr Kubaj 	u16 offset; /* ICE_PROTOCOL_LAST indicates end of list */
4288923de59SPiotr Kubaj };
4298923de59SPiotr Kubaj 
4308923de59SPiotr Kubaj void
4318923de59SPiotr Kubaj ice_find_dummy_packet(struct ice_adv_lkup_elem *lkups, u16 lkups_cnt,
4328923de59SPiotr Kubaj 		      enum ice_sw_tunnel_type tun_type, const u8 **pkt,
4338923de59SPiotr Kubaj 		      u16 *pkt_len,
4348923de59SPiotr Kubaj 		      const struct ice_dummy_pkt_offsets **offsets);
4358923de59SPiotr Kubaj 
436*f2635e84SEric Joyner int
4378923de59SPiotr Kubaj ice_fill_adv_dummy_packet(struct ice_adv_lkup_elem *lkups, u16 lkups_cnt,
4389c30461dSEric Joyner 			  struct ice_sw_rule_lkup_rx_tx *s_rule,
4398923de59SPiotr Kubaj 			  const u8 *dummy_pkt, u16 pkt_len,
4408923de59SPiotr Kubaj 			  const struct ice_dummy_pkt_offsets *offsets);
4418923de59SPiotr Kubaj 
442*f2635e84SEric Joyner int
4438923de59SPiotr Kubaj ice_add_adv_recipe(struct ice_hw *hw, struct ice_adv_lkup_elem *lkups,
4448923de59SPiotr Kubaj 		   u16 lkups_cnt, struct ice_adv_rule_info *rinfo, u16 *rid);
4458923de59SPiotr Kubaj 
4468923de59SPiotr Kubaj struct ice_adv_fltr_mgmt_list_entry *
4478923de59SPiotr Kubaj ice_find_adv_rule_entry(struct ice_hw *hw, struct ice_adv_lkup_elem *lkups,
4488923de59SPiotr Kubaj 			u16 lkups_cnt, u16 recp_id,
4498923de59SPiotr Kubaj 			struct ice_adv_rule_info *rinfo);
4508923de59SPiotr Kubaj 
451*f2635e84SEric Joyner int
4528923de59SPiotr Kubaj ice_adv_add_update_vsi_list(struct ice_hw *hw,
4538923de59SPiotr Kubaj 			    struct ice_adv_fltr_mgmt_list_entry *m_entry,
4548923de59SPiotr Kubaj 			    struct ice_adv_rule_info *cur_fltr,
4558923de59SPiotr Kubaj 			    struct ice_adv_rule_info *new_fltr);
4568923de59SPiotr Kubaj 
4578923de59SPiotr Kubaj struct ice_vsi_list_map_info *
4588923de59SPiotr Kubaj ice_find_vsi_list_entry(struct ice_sw_recipe *recp_list, u16 vsi_handle,
4598923de59SPiotr Kubaj 			u16 *vsi_list_id);
4608923de59SPiotr Kubaj 
46171d10453SEric Joyner /* VSI related commands */
462*f2635e84SEric Joyner int
46371d10453SEric Joyner ice_aq_add_vsi(struct ice_hw *hw, struct ice_vsi_ctx *vsi_ctx,
46471d10453SEric Joyner 	       struct ice_sq_cd *cd);
465*f2635e84SEric Joyner int
46671d10453SEric Joyner ice_aq_free_vsi(struct ice_hw *hw, struct ice_vsi_ctx *vsi_ctx,
46771d10453SEric Joyner 		bool keep_vsi_alloc, struct ice_sq_cd *cd);
468*f2635e84SEric Joyner int
46971d10453SEric Joyner ice_aq_update_vsi(struct ice_hw *hw, struct ice_vsi_ctx *vsi_ctx,
47071d10453SEric Joyner 		  struct ice_sq_cd *cd);
471*f2635e84SEric Joyner int
47271d10453SEric Joyner ice_add_vsi(struct ice_hw *hw, u16 vsi_handle, struct ice_vsi_ctx *vsi_ctx,
47371d10453SEric Joyner 	    struct ice_sq_cd *cd);
474*f2635e84SEric Joyner int
47571d10453SEric Joyner ice_free_vsi(struct ice_hw *hw, u16 vsi_handle, struct ice_vsi_ctx *vsi_ctx,
47671d10453SEric Joyner 	     bool keep_vsi_alloc, struct ice_sq_cd *cd);
477*f2635e84SEric Joyner int
47871d10453SEric Joyner ice_update_vsi(struct ice_hw *hw, u16 vsi_handle, struct ice_vsi_ctx *vsi_ctx,
47971d10453SEric Joyner 	       struct ice_sq_cd *cd);
48071d10453SEric Joyner struct ice_vsi_ctx *ice_get_vsi_ctx(struct ice_hw *hw, u16 vsi_handle);
481*f2635e84SEric Joyner void ice_clear_vsi_q_ctx(struct ice_hw *hw, u16 vsi_handle);
48271d10453SEric Joyner void ice_clear_all_vsi_ctx(struct ice_hw *hw);
483*f2635e84SEric Joyner int
48471d10453SEric Joyner ice_aq_get_vsi_params(struct ice_hw *hw, struct ice_vsi_ctx *vsi_ctx,
48571d10453SEric Joyner 		      struct ice_sq_cd *cd);
486*f2635e84SEric Joyner int
48771d10453SEric Joyner ice_aq_add_update_mir_rule(struct ice_hw *hw, u16 rule_type, u16 dest_vsi,
48871d10453SEric Joyner 			   u16 count, struct ice_mir_rule_buf *mr_buf,
48971d10453SEric Joyner 			   struct ice_sq_cd *cd, u16 *rule_id);
490*f2635e84SEric Joyner int
49171d10453SEric Joyner ice_aq_delete_mir_rule(struct ice_hw *hw, u16 rule_id, bool keep_allocd,
49271d10453SEric Joyner 		       struct ice_sq_cd *cd);
493*f2635e84SEric Joyner int
49471d10453SEric Joyner ice_aq_get_storm_ctrl(struct ice_hw *hw, u32 *bcast_thresh, u32 *mcast_thresh,
49571d10453SEric Joyner 		      u32 *ctl_bitmask);
496*f2635e84SEric Joyner int
49771d10453SEric Joyner ice_aq_set_storm_ctrl(struct ice_hw *hw, u32 bcast_thresh, u32 mcast_thresh,
49871d10453SEric Joyner 		      u32 ctl_bitmask);
49971d10453SEric Joyner /* Switch config */
500*f2635e84SEric Joyner int ice_get_initial_sw_cfg(struct ice_hw *hw);
501*f2635e84SEric Joyner int
50271d10453SEric Joyner ice_alloc_vlan_res_counter(struct ice_hw *hw, u16 *counter_id);
503*f2635e84SEric Joyner int
50471d10453SEric Joyner ice_free_vlan_res_counter(struct ice_hw *hw, u16 counter_id);
50571d10453SEric Joyner 
506*f2635e84SEric Joyner int ice_update_sw_rule_bridge_mode(struct ice_hw *hw);
507*f2635e84SEric Joyner int ice_alloc_rss_global_lut(struct ice_hw *hw, bool shared_res, u16 *global_lut_id);
508*f2635e84SEric Joyner int ice_free_rss_global_lut(struct ice_hw *hw, u16 global_lut_id);
509*f2635e84SEric Joyner int
51071d10453SEric Joyner ice_alloc_sw(struct ice_hw *hw, bool ena_stats, bool shared_res, u16 *sw_id,
51171d10453SEric Joyner 	     u16 *counter_id);
512*f2635e84SEric Joyner int
51371d10453SEric Joyner ice_free_sw(struct ice_hw *hw, u16 sw_id, u16 counter_id);
514*f2635e84SEric Joyner int
5157d7af7f8SEric Joyner ice_aq_get_res_alloc(struct ice_hw *hw, u16 *num_entries,
5167d7af7f8SEric Joyner 		     struct ice_aqc_get_res_resp_elem *buf, u16 buf_size,
5177d7af7f8SEric Joyner 		     struct ice_sq_cd *cd);
518*f2635e84SEric Joyner int
51971d10453SEric Joyner ice_aq_get_res_descs(struct ice_hw *hw, u16 num_entries,
5207d7af7f8SEric Joyner 		     struct ice_aqc_res_elem *buf, u16 buf_size, u16 res_type,
5217d7af7f8SEric Joyner 		     bool res_shared, u16 *desc_id, struct ice_sq_cd *cd);
522*f2635e84SEric Joyner int
52371d10453SEric Joyner ice_add_vlan(struct ice_hw *hw, struct LIST_HEAD_TYPE *m_list);
524*f2635e84SEric Joyner int ice_remove_vlan(struct ice_hw *hw, struct LIST_HEAD_TYPE *v_list);
52571d10453SEric Joyner void ice_rem_all_sw_rules_info(struct ice_hw *hw);
526*f2635e84SEric Joyner int ice_add_mac(struct ice_hw *hw, struct LIST_HEAD_TYPE *m_lst);
527*f2635e84SEric Joyner int ice_remove_mac(struct ice_hw *hw, struct LIST_HEAD_TYPE *m_lst);
528*f2635e84SEric Joyner int
52971d10453SEric Joyner ice_add_eth_mac(struct ice_hw *hw, struct LIST_HEAD_TYPE *em_list);
530*f2635e84SEric Joyner int
53171d10453SEric Joyner ice_remove_eth_mac(struct ice_hw *hw, struct LIST_HEAD_TYPE *em_list);
532*f2635e84SEric Joyner int
5338a13362dSEric Joyner ice_cfg_iwarp_fltr(struct ice_hw *hw, u16 vsi_handle, bool enable);
53471d10453SEric Joyner 
535*f2635e84SEric Joyner int
53671d10453SEric Joyner ice_add_mac_with_sw_marker(struct ice_hw *hw, struct ice_fltr_info *f_info,
53771d10453SEric Joyner 			   u16 sw_marker);
538*f2635e84SEric Joyner int
53971d10453SEric Joyner ice_add_mac_with_counter(struct ice_hw *hw, struct ice_fltr_info *f_info);
54071d10453SEric Joyner void ice_remove_vsi_fltr(struct ice_hw *hw, u16 vsi_handle);
54171d10453SEric Joyner 
54271d10453SEric Joyner /* Promisc/defport setup for VSIs */
543*f2635e84SEric Joyner int
54471d10453SEric Joyner ice_cfg_dflt_vsi(struct ice_port_info *pi, u16 vsi_handle, bool set,
54571d10453SEric Joyner 		 u8 direction);
5468923de59SPiotr Kubaj bool ice_check_if_dflt_vsi(struct ice_port_info *pi, u16 vsi_handle,
5478923de59SPiotr Kubaj 			   bool *rule_exists);
548*f2635e84SEric Joyner int
5499c30461dSEric Joyner ice_set_vsi_promisc(struct ice_hw *hw, u16 vsi_handle,
5509c30461dSEric Joyner 		    ice_bitmap_t *promisc_mask, u16 vid);
551*f2635e84SEric Joyner int
5529c30461dSEric Joyner ice_clear_vsi_promisc(struct ice_hw *hw, u16 vsi_handle,
5539c30461dSEric Joyner 		      ice_bitmap_t *promisc_mask, u16 vid);
554*f2635e84SEric Joyner int
5559c30461dSEric Joyner ice_set_vlan_vsi_promisc(struct ice_hw *hw, u16 vsi_handle,
5569c30461dSEric Joyner 			 ice_bitmap_t *promisc_mask, bool rm_vlan_promisc);
55771d10453SEric Joyner 
55871d10453SEric Joyner /* Get VSIs Promisc/defport settings */
559*f2635e84SEric Joyner int
5609c30461dSEric Joyner ice_get_vsi_promisc(struct ice_hw *hw, u16 vsi_handle,
5619c30461dSEric Joyner 		    ice_bitmap_t *promisc_mask, u16 *vid);
562*f2635e84SEric Joyner int
5639c30461dSEric Joyner ice_get_vsi_vlan_promisc(struct ice_hw *hw, u16 vsi_handle,
5649c30461dSEric Joyner 			 ice_bitmap_t *promisc_mask, u16 *vid);
56571d10453SEric Joyner 
566*f2635e84SEric Joyner int ice_replay_all_fltr(struct ice_hw *hw);
56771d10453SEric Joyner 
568*f2635e84SEric Joyner int
56971d10453SEric Joyner ice_init_def_sw_recp(struct ice_hw *hw, struct ice_sw_recipe **recp_list);
57071d10453SEric Joyner u16 ice_get_hw_vsi_num(struct ice_hw *hw, u16 vsi_handle);
57171d10453SEric Joyner bool ice_is_vsi_valid(struct ice_hw *hw, u16 vsi_handle);
57271d10453SEric Joyner 
573*f2635e84SEric Joyner int
5747d7af7f8SEric Joyner ice_replay_vsi_all_fltr(struct ice_hw *hw, struct ice_port_info *pi,
5757d7af7f8SEric Joyner 			u16 vsi_handle);
5767d7af7f8SEric Joyner void ice_rm_sw_replay_rule_info(struct ice_hw *hw, struct ice_switch_info *sw);
57771d10453SEric Joyner void ice_rm_all_sw_replay_rule_info(struct ice_hw *hw);
578*f2635e84SEric Joyner int
5798923de59SPiotr Kubaj ice_aq_sw_rules(struct ice_hw *hw, void *rule_list, u16 rule_list_sz,
5808923de59SPiotr Kubaj 		u8 num_rules, enum ice_adminq_opc opc, struct ice_sq_cd *cd);
58171d10453SEric Joyner #endif /* _ICE_SWITCH_H_ */
582