Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /* Copyright (c) 2018, Intel Corporation. */
0003 
0004 #ifndef _ICE_SWITCH_H_
0005 #define _ICE_SWITCH_H_
0006 
0007 #include "ice_common.h"
0008 
0009 #define ICE_SW_CFG_MAX_BUF_LEN 2048
0010 #define ICE_DFLT_VSI_INVAL 0xff
0011 #define ICE_FLTR_RX BIT(0)
0012 #define ICE_FLTR_TX BIT(1)
0013 #define ICE_FLTR_TX_RX (ICE_FLTR_RX | ICE_FLTR_TX)
0014 #define ICE_VSI_INVAL_ID 0xffff
0015 #define ICE_INVAL_Q_HANDLE 0xFFFF
0016 
0017 /* Switch Profile IDs for Profile related switch rules */
0018 #define ICE_PROFID_IPV4_GTPC_TEID           41
0019 #define ICE_PROFID_IPV4_GTPC_NO_TEID            42
0020 #define ICE_PROFID_IPV4_GTPU_TEID           43
0021 #define ICE_PROFID_IPV6_GTPC_TEID           44
0022 #define ICE_PROFID_IPV6_GTPC_NO_TEID            45
0023 #define ICE_PROFID_IPV6_GTPU_TEID           46
0024 #define ICE_PROFID_IPV6_GTPU_IPV6_TCP_INNER     70
0025 
0026 /* VSI context structure for add/get/update/free operations */
0027 struct ice_vsi_ctx {
0028     u16 vsi_num;
0029     u16 vsis_allocd;
0030     u16 vsis_unallocated;
0031     u16 flags;
0032     struct ice_aqc_vsi_props info;
0033     struct ice_sched_vsi_info sched;
0034     u8 alloc_from_pool;
0035     u8 vf_num;
0036     u16 num_lan_q_entries[ICE_MAX_TRAFFIC_CLASS];
0037     struct ice_q_ctx *lan_q_ctx[ICE_MAX_TRAFFIC_CLASS];
0038     u16 num_rdma_q_entries[ICE_MAX_TRAFFIC_CLASS];
0039     struct ice_q_ctx *rdma_q_ctx[ICE_MAX_TRAFFIC_CLASS];
0040 };
0041 
0042 /* Switch recipe ID enum values are specific to hardware */
0043 enum ice_sw_lkup_type {
0044     ICE_SW_LKUP_ETHERTYPE = 0,
0045     ICE_SW_LKUP_MAC = 1,
0046     ICE_SW_LKUP_MAC_VLAN = 2,
0047     ICE_SW_LKUP_PROMISC = 3,
0048     ICE_SW_LKUP_VLAN = 4,
0049     ICE_SW_LKUP_DFLT = 5,
0050     ICE_SW_LKUP_ETHERTYPE_MAC = 8,
0051     ICE_SW_LKUP_PROMISC_VLAN = 9,
0052     ICE_SW_LKUP_LAST
0053 };
0054 
0055 /* type of filter src ID */
0056 enum ice_src_id {
0057     ICE_SRC_ID_UNKNOWN = 0,
0058     ICE_SRC_ID_VSI,
0059     ICE_SRC_ID_QUEUE,
0060     ICE_SRC_ID_LPORT,
0061 };
0062 
0063 struct ice_fltr_info {
0064     /* Look up information: how to look up packet */
0065     enum ice_sw_lkup_type lkup_type;
0066     /* Forward action: filter action to do after lookup */
0067     enum ice_sw_fwd_act_type fltr_act;
0068     /* rule ID returned by firmware once filter rule is created */
0069     u16 fltr_rule_id;
0070     u16 flag;
0071 
0072     /* Source VSI for LOOKUP_TX or source port for LOOKUP_RX */
0073     u16 src;
0074     enum ice_src_id src_id;
0075 
0076     union {
0077         struct {
0078             u8 mac_addr[ETH_ALEN];
0079         } mac;
0080         struct {
0081             u8 mac_addr[ETH_ALEN];
0082             u16 vlan_id;
0083         } mac_vlan;
0084         struct {
0085             u16 vlan_id;
0086             u16 tpid;
0087             u8 tpid_valid;
0088         } vlan;
0089         /* Set lkup_type as ICE_SW_LKUP_ETHERTYPE
0090          * if just using ethertype as filter. Set lkup_type as
0091          * ICE_SW_LKUP_ETHERTYPE_MAC if MAC also needs to be
0092          * passed in as filter.
0093          */
0094         struct {
0095             u16 ethertype;
0096             u8 mac_addr[ETH_ALEN]; /* optional */
0097         } ethertype_mac;
0098     } l_data; /* Make sure to zero out the memory of l_data before using
0099            * it or only set the data associated with lookup match
0100            * rest everything should be zero
0101            */
0102 
0103     /* Depending on filter action */
0104     union {
0105         /* queue ID in case of ICE_FWD_TO_Q and starting
0106          * queue ID in case of ICE_FWD_TO_QGRP.
0107          */
0108         u16 q_id:11;
0109         u16 hw_vsi_id:10;
0110         u16 vsi_list_id:10;
0111     } fwd_id;
0112 
0113     /* Sw VSI handle */
0114     u16 vsi_handle;
0115 
0116     /* Set to num_queues if action is ICE_FWD_TO_QGRP. This field
0117      * determines the range of queues the packet needs to be forwarded to.
0118      * Note that qgrp_size must be set to a power of 2.
0119      */
0120     u8 qgrp_size;
0121 
0122     /* Rule creations populate these indicators basing on the switch type */
0123     u8 lb_en;   /* Indicate if packet can be looped back */
0124     u8 lan_en;  /* Indicate if packet can be forwarded to the uplink */
0125 };
0126 
0127 struct ice_update_recipe_lkup_idx_params {
0128     u16 rid;
0129     u16 fv_idx;
0130     bool ignore_valid;
0131     u16 mask;
0132     bool mask_valid;
0133     u8 lkup_idx;
0134 };
0135 
0136 struct ice_adv_lkup_elem {
0137     enum ice_protocol_type type;
0138     union {
0139         union ice_prot_hdr h_u; /* Header values */
0140         /* Used to iterate over the headers */
0141         u16 h_raw[sizeof(union ice_prot_hdr) / sizeof(u16)];
0142     };
0143     union {
0144         union ice_prot_hdr m_u; /* Mask of header values to match */
0145         /* Used to iterate over header mask */
0146         u16 m_raw[sizeof(union ice_prot_hdr) / sizeof(u16)];
0147     };
0148 };
0149 
0150 struct ice_sw_act_ctrl {
0151     /* Source VSI for LOOKUP_TX or source port for LOOKUP_RX */
0152     u16 src;
0153     u16 flag;
0154     enum ice_sw_fwd_act_type fltr_act;
0155     /* Depending on filter action */
0156     union {
0157         /* This is a queue ID in case of ICE_FWD_TO_Q and starting
0158          * queue ID in case of ICE_FWD_TO_QGRP.
0159          */
0160         u16 q_id:11;
0161         u16 vsi_id:10;
0162         u16 hw_vsi_id:10;
0163         u16 vsi_list_id:10;
0164     } fwd_id;
0165     /* software VSI handle */
0166     u16 vsi_handle;
0167     u8 qgrp_size;
0168 };
0169 
0170 struct ice_rule_query_data {
0171     /* Recipe ID for which the requested rule was added */
0172     u16 rid;
0173     /* Rule ID that was added or is supposed to be removed */
0174     u16 rule_id;
0175     /* vsi_handle for which Rule was added or is supposed to be removed */
0176     u16 vsi_handle;
0177 };
0178 
0179 /* This structure allows to pass info about lb_en and lan_en
0180  * flags to ice_add_adv_rule. Values in act would be used
0181  * only if act_valid was set to true, otherwise default
0182  * values would be used.
0183  */
0184 struct ice_adv_rule_flags_info {
0185     u32 act;
0186     u8 act_valid;       /* indicate if flags in act are valid */
0187 };
0188 
0189 struct ice_adv_rule_info {
0190     enum ice_sw_tunnel_type tun_type;
0191     struct ice_sw_act_ctrl sw_act;
0192     u32 priority;
0193     u8 rx; /* true means LOOKUP_RX otherwise LOOKUP_TX */
0194     u16 fltr_rule_id;
0195     u16 vlan_type;
0196     struct ice_adv_rule_flags_info flags_info;
0197 };
0198 
0199 /* A collection of one or more four word recipe */
0200 struct ice_sw_recipe {
0201     /* For a chained recipe the root recipe is what should be used for
0202      * programming rules
0203      */
0204     u8 is_root;
0205     u8 root_rid;
0206     u8 recp_created;
0207 
0208     /* Number of extraction words */
0209     u8 n_ext_words;
0210     /* Protocol ID and Offset pair (extraction word) to describe the
0211      * recipe
0212      */
0213     struct ice_fv_word ext_words[ICE_MAX_CHAIN_WORDS];
0214     u16 word_masks[ICE_MAX_CHAIN_WORDS];
0215 
0216     /* if this recipe is a collection of other recipe */
0217     u8 big_recp;
0218 
0219     /* if this recipe is part of another bigger recipe then chain index
0220      * corresponding to this recipe
0221      */
0222     u8 chain_idx;
0223 
0224     /* if this recipe is a collection of other recipe then count of other
0225      * recipes and recipe IDs of those recipes
0226      */
0227     u8 n_grp_count;
0228 
0229     /* Bit map specifying the IDs associated with this group of recipe */
0230     DECLARE_BITMAP(r_bitmap, ICE_MAX_NUM_RECIPES);
0231 
0232     enum ice_sw_tunnel_type tun_type;
0233 
0234     /* List of type ice_fltr_mgmt_list_entry or adv_rule */
0235     u8 adv_rule;
0236     struct list_head filt_rules;
0237     struct list_head filt_replay_rules;
0238 
0239     struct mutex filt_rule_lock;    /* protect filter rule structure */
0240 
0241     /* Profiles this recipe should be associated with */
0242     struct list_head fv_list;
0243 
0244     /* Profiles this recipe is associated with */
0245     u8 num_profs, *prof_ids;
0246 
0247     /* Bit map for possible result indexes */
0248     DECLARE_BITMAP(res_idxs, ICE_MAX_FV_WORDS);
0249 
0250     /* This allows user to specify the recipe priority.
0251      * For now, this becomes 'fwd_priority' when recipe
0252      * is created, usually recipes can have 'fwd' and 'join'
0253      * priority.
0254      */
0255     u8 priority;
0256 
0257     struct list_head rg_list;
0258 
0259     /* AQ buffer associated with this recipe */
0260     struct ice_aqc_recipe_data_elem *root_buf;
0261     /* This struct saves the fv_words for a given lookup */
0262     struct ice_prot_lkup_ext lkup_exts;
0263 };
0264 
0265 /* Bookkeeping structure to hold bitmap of VSIs corresponding to VSI list ID */
0266 struct ice_vsi_list_map_info {
0267     struct list_head list_entry;
0268     DECLARE_BITMAP(vsi_map, ICE_MAX_VSI);
0269     u16 vsi_list_id;
0270     /* counter to track how many rules are reusing this VSI list */
0271     u16 ref_cnt;
0272 };
0273 
0274 struct ice_fltr_list_entry {
0275     struct list_head list_entry;
0276     int status;
0277     struct ice_fltr_info fltr_info;
0278 };
0279 
0280 /* This defines an entry in the list that maintains MAC or VLAN membership
0281  * to HW list mapping, since multiple VSIs can subscribe to the same MAC or
0282  * VLAN. As an optimization the VSI list should be created only when a
0283  * second VSI becomes a subscriber to the same MAC address. VSI lists are always
0284  * used for VLAN membership.
0285  */
0286 struct ice_fltr_mgmt_list_entry {
0287     /* back pointer to VSI list ID to VSI list mapping */
0288     struct ice_vsi_list_map_info *vsi_list_info;
0289     u16 vsi_count;
0290 #define ICE_INVAL_LG_ACT_INDEX 0xffff
0291     u16 lg_act_idx;
0292 #define ICE_INVAL_SW_MARKER_ID 0xffff
0293     u16 sw_marker_id;
0294     struct list_head list_entry;
0295     struct ice_fltr_info fltr_info;
0296 #define ICE_INVAL_COUNTER_ID 0xff
0297     u8 counter_index;
0298 };
0299 
0300 struct ice_adv_fltr_mgmt_list_entry {
0301     struct list_head list_entry;
0302 
0303     struct ice_adv_lkup_elem *lkups;
0304     struct ice_adv_rule_info rule_info;
0305     u16 lkups_cnt;
0306     struct ice_vsi_list_map_info *vsi_list_info;
0307     u16 vsi_count;
0308 };
0309 
0310 enum ice_promisc_flags {
0311     ICE_PROMISC_UCAST_RX = 0x1,
0312     ICE_PROMISC_UCAST_TX = 0x2,
0313     ICE_PROMISC_MCAST_RX = 0x4,
0314     ICE_PROMISC_MCAST_TX = 0x8,
0315     ICE_PROMISC_BCAST_RX = 0x10,
0316     ICE_PROMISC_BCAST_TX = 0x20,
0317     ICE_PROMISC_VLAN_RX = 0x40,
0318     ICE_PROMISC_VLAN_TX = 0x80,
0319 };
0320 
0321 /* VSI related commands */
0322 int
0323 ice_add_vsi(struct ice_hw *hw, u16 vsi_handle, struct ice_vsi_ctx *vsi_ctx,
0324         struct ice_sq_cd *cd);
0325 int
0326 ice_free_vsi(struct ice_hw *hw, u16 vsi_handle, struct ice_vsi_ctx *vsi_ctx,
0327          bool keep_vsi_alloc, struct ice_sq_cd *cd);
0328 int
0329 ice_update_vsi(struct ice_hw *hw, u16 vsi_handle, struct ice_vsi_ctx *vsi_ctx,
0330            struct ice_sq_cd *cd);
0331 bool ice_is_vsi_valid(struct ice_hw *hw, u16 vsi_handle);
0332 struct ice_vsi_ctx *ice_get_vsi_ctx(struct ice_hw *hw, u16 vsi_handle);
0333 void ice_clear_all_vsi_ctx(struct ice_hw *hw);
0334 /* Switch config */
0335 int ice_get_initial_sw_cfg(struct ice_hw *hw);
0336 
0337 int
0338 ice_alloc_res_cntr(struct ice_hw *hw, u8 type, u8 alloc_shared, u16 num_items,
0339            u16 *counter_id);
0340 int
0341 ice_free_res_cntr(struct ice_hw *hw, u8 type, u8 alloc_shared, u16 num_items,
0342           u16 counter_id);
0343 
0344 /* Switch/bridge related commands */
0345 int
0346 ice_add_adv_rule(struct ice_hw *hw, struct ice_adv_lkup_elem *lkups,
0347          u16 lkups_cnt, struct ice_adv_rule_info *rinfo,
0348          struct ice_rule_query_data *added_entry);
0349 int ice_update_sw_rule_bridge_mode(struct ice_hw *hw);
0350 int ice_add_vlan(struct ice_hw *hw, struct list_head *m_list);
0351 int ice_remove_vlan(struct ice_hw *hw, struct list_head *v_list);
0352 int ice_add_mac(struct ice_hw *hw, struct list_head *m_lst);
0353 int ice_remove_mac(struct ice_hw *hw, struct list_head *m_lst);
0354 bool ice_mac_fltr_exist(struct ice_hw *hw, u8 *mac, u16 vsi_handle);
0355 bool ice_vlan_fltr_exist(struct ice_hw *hw, u16 vlan_id, u16 vsi_handle);
0356 int ice_add_eth_mac(struct ice_hw *hw, struct list_head *em_list);
0357 int ice_remove_eth_mac(struct ice_hw *hw, struct list_head *em_list);
0358 int ice_cfg_rdma_fltr(struct ice_hw *hw, u16 vsi_handle, bool enable);
0359 void ice_remove_vsi_fltr(struct ice_hw *hw, u16 vsi_handle);
0360 
0361 /* Promisc/defport setup for VSIs */
0362 int
0363 ice_cfg_dflt_vsi(struct ice_port_info *pi, u16 vsi_handle, bool set,
0364          u8 direction);
0365 bool
0366 ice_check_if_dflt_vsi(struct ice_port_info *pi, u16 vsi_handle,
0367               bool *rule_exists);
0368 
0369 int
0370 ice_set_vsi_promisc(struct ice_hw *hw, u16 vsi_handle, u8 promisc_mask,
0371             u16 vid);
0372 int
0373 ice_clear_vsi_promisc(struct ice_hw *hw, u16 vsi_handle, u8 promisc_mask,
0374               u16 vid);
0375 int
0376 ice_set_vlan_vsi_promisc(struct ice_hw *hw, u16 vsi_handle, u8 promisc_mask,
0377              bool rm_vlan_promisc);
0378 
0379 int ice_rem_adv_rule_for_vsi(struct ice_hw *hw, u16 vsi_handle);
0380 int
0381 ice_rem_adv_rule_by_id(struct ice_hw *hw,
0382                struct ice_rule_query_data *remove_entry);
0383 
0384 int ice_init_def_sw_recp(struct ice_hw *hw);
0385 u16 ice_get_hw_vsi_num(struct ice_hw *hw, u16 vsi_handle);
0386 
0387 int ice_replay_vsi_all_fltr(struct ice_hw *hw, u16 vsi_handle);
0388 void ice_rm_all_sw_replay_rule_info(struct ice_hw *hw);
0389 
0390 int
0391 ice_aq_sw_rules(struct ice_hw *hw, void *rule_list, u16 rule_list_sz,
0392         u8 num_rules, enum ice_adminq_opc opc, struct ice_sq_cd *cd);
0393 int
0394 ice_update_recipe_lkup_idx(struct ice_hw *hw,
0395                struct ice_update_recipe_lkup_idx_params *params);
0396 void ice_change_proto_id_to_dvm(void);
0397 #endif /* _ICE_SWITCH_H_ */