Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /* Copyright (C) 2018-2021, Intel Corporation. */
0003 
0004 #ifndef _ICE_VF_LIB_H_
0005 #define _ICE_VF_LIB_H_
0006 
0007 #include <linux/types.h>
0008 #include <linux/hashtable.h>
0009 #include <linux/bitmap.h>
0010 #include <linux/mutex.h>
0011 #include <linux/pci.h>
0012 #include <net/devlink.h>
0013 #include <linux/avf/virtchnl.h>
0014 #include "ice_type.h"
0015 #include "ice_virtchnl_fdir.h"
0016 #include "ice_vsi_vlan_ops.h"
0017 
0018 #define ICE_MAX_SRIOV_VFS       256
0019 
0020 /* VF resource constraints */
0021 #define ICE_MAX_RSS_QS_PER_VF   16
0022 
0023 struct ice_pf;
0024 struct ice_vf;
0025 struct ice_virtchnl_ops;
0026 
0027 /* VF capabilities */
0028 enum ice_virtchnl_cap {
0029     ICE_VIRTCHNL_VF_CAP_PRIVILEGE = 0,
0030 };
0031 
0032 /* Specific VF states */
0033 enum ice_vf_states {
0034     ICE_VF_STATE_INIT = 0,      /* PF is initializing VF */
0035     ICE_VF_STATE_ACTIVE,        /* VF resources are allocated for use */
0036     ICE_VF_STATE_QS_ENA,        /* VF queue(s) enabled */
0037     ICE_VF_STATE_DIS,
0038     ICE_VF_STATE_MC_PROMISC,
0039     ICE_VF_STATE_UC_PROMISC,
0040     ICE_VF_STATES_NBITS
0041 };
0042 
0043 struct ice_time_mac {
0044     unsigned long time_modified;
0045     u8 addr[ETH_ALEN];
0046 };
0047 
0048 /* VF MDD events print structure */
0049 struct ice_mdd_vf_events {
0050     u16 count;          /* total count of Rx|Tx events */
0051     /* count number of the last printed event */
0052     u16 last_printed;
0053 };
0054 
0055 /* VF operations */
0056 struct ice_vf_ops {
0057     enum ice_disq_rst_src reset_type;
0058     void (*free)(struct ice_vf *vf);
0059     void (*clear_mbx_register)(struct ice_vf *vf);
0060     void (*trigger_reset_register)(struct ice_vf *vf, bool is_vflr);
0061     bool (*poll_reset_status)(struct ice_vf *vf);
0062     void (*clear_reset_trigger)(struct ice_vf *vf);
0063     int (*vsi_rebuild)(struct ice_vf *vf);
0064     void (*post_vsi_rebuild)(struct ice_vf *vf);
0065 };
0066 
0067 /* Virtchnl/SR-IOV config info */
0068 struct ice_vfs {
0069     DECLARE_HASHTABLE(table, 8);    /* table of VF entries */
0070     struct mutex table_lock;    /* Lock for protecting the hash table */
0071     u16 num_supported;      /* max supported VFs on this PF */
0072     u16 num_qps_per;        /* number of queue pairs per VF */
0073     u16 num_msix_per;       /* number of MSI-X vectors per VF */
0074     unsigned long last_printed_mdd_jiffies; /* MDD message rate limit */
0075     DECLARE_BITMAP(malvfs, ICE_MAX_SRIOV_VFS); /* malicious VF indicator */
0076 };
0077 
0078 /* VF information structure */
0079 struct ice_vf {
0080     struct hlist_node entry;
0081     struct rcu_head rcu;
0082     struct kref refcnt;
0083     struct ice_pf *pf;
0084 
0085     /* Used during virtchnl message handling and NDO ops against the VF
0086      * that will trigger a VFR
0087      */
0088     struct mutex cfg_lock;
0089 
0090     u16 vf_id;          /* VF ID in the PF space */
0091     u16 lan_vsi_idx;        /* index into PF struct */
0092     u16 ctrl_vsi_idx;
0093     struct ice_vf_fdir fdir;
0094     /* first vector index of this VF in the PF space */
0095     int first_vector_idx;
0096     struct ice_sw *vf_sw_id;    /* switch ID the VF VSIs connect to */
0097     struct virtchnl_version_info vf_ver;
0098     u32 driver_caps;        /* reported by VF driver */
0099     struct virtchnl_ether_addr dev_lan_addr;
0100     struct virtchnl_ether_addr hw_lan_addr;
0101     struct ice_time_mac legacy_last_added_umac;
0102     DECLARE_BITMAP(txq_ena, ICE_MAX_RSS_QS_PER_VF);
0103     DECLARE_BITMAP(rxq_ena, ICE_MAX_RSS_QS_PER_VF);
0104     struct ice_vlan port_vlan_info; /* Port VLAN ID, QoS, and TPID */
0105     struct virtchnl_vlan_caps vlan_v2_caps;
0106     u8 pf_set_mac:1;        /* VF MAC address set by VMM admin */
0107     u8 trusted:1;
0108     u8 spoofchk:1;
0109     u8 link_forced:1;
0110     u8 link_up:1;           /* only valid if VF link is forced */
0111     /* VSI indices - actual VSI pointers are maintained in the PF structure
0112      * When assigned, these will be non-zero, because VSI 0 is always
0113      * the main LAN VSI for the PF.
0114      */
0115     u16 lan_vsi_num;        /* ID as used by firmware */
0116     unsigned int min_tx_rate;   /* Minimum Tx bandwidth limit in Mbps */
0117     unsigned int max_tx_rate;   /* Maximum Tx bandwidth limit in Mbps */
0118     DECLARE_BITMAP(vf_states, ICE_VF_STATES_NBITS); /* VF runtime states */
0119 
0120     unsigned long vf_caps;      /* VF's adv. capabilities */
0121     u8 num_req_qs;          /* num of queue pairs requested by VF */
0122     u16 num_mac;
0123     u16 num_vf_qs;          /* num of queue configured per VF */
0124     struct ice_mdd_vf_events mdd_rx_events;
0125     struct ice_mdd_vf_events mdd_tx_events;
0126     DECLARE_BITMAP(opcodes_allowlist, VIRTCHNL_OP_MAX);
0127 
0128     struct ice_repr *repr;
0129     const struct ice_virtchnl_ops *virtchnl_ops;
0130     const struct ice_vf_ops *vf_ops;
0131 
0132     /* devlink port data */
0133     struct devlink_port devlink_port;
0134 };
0135 
0136 /* Flags for controlling behavior of ice_reset_vf */
0137 enum ice_vf_reset_flags {
0138     ICE_VF_RESET_VFLR = BIT(0), /* Indicate a VFLR reset */
0139     ICE_VF_RESET_NOTIFY = BIT(1), /* Notify VF prior to reset */
0140     ICE_VF_RESET_LOCK = BIT(2), /* Acquire the VF cfg_lock */
0141 };
0142 
0143 static inline u16 ice_vf_get_port_vlan_id(struct ice_vf *vf)
0144 {
0145     return vf->port_vlan_info.vid;
0146 }
0147 
0148 static inline u8 ice_vf_get_port_vlan_prio(struct ice_vf *vf)
0149 {
0150     return vf->port_vlan_info.prio;
0151 }
0152 
0153 static inline bool ice_vf_is_port_vlan_ena(struct ice_vf *vf)
0154 {
0155     return (ice_vf_get_port_vlan_id(vf) || ice_vf_get_port_vlan_prio(vf));
0156 }
0157 
0158 static inline u16 ice_vf_get_port_vlan_tpid(struct ice_vf *vf)
0159 {
0160     return vf->port_vlan_info.tpid;
0161 }
0162 
0163 /* VF Hash Table access functions
0164  *
0165  * These functions provide abstraction for interacting with the VF hash table.
0166  * In general, direct access to the hash table should be avoided outside of
0167  * these functions where possible.
0168  *
0169  * The VF entries in the hash table are protected by reference counting to
0170  * track lifetime of accesses from the table. The ice_get_vf_by_id() function
0171  * obtains a reference to the VF structure which must be dropped by using
0172  * ice_put_vf().
0173  */
0174 
0175 /**
0176  * ice_for_each_vf - Iterate over each VF entry
0177  * @pf: pointer to the PF private structure
0178  * @bkt: bucket index used for iteration
0179  * @vf: pointer to the VF entry currently being processed in the loop
0180  *
0181  * The bkt variable is an unsigned integer iterator used to traverse the VF
0182  * entries. It is *not* guaranteed to be the VF's vf_id. Do not assume it is.
0183  * Use vf->vf_id to get the id number if needed.
0184  *
0185  * The caller is expected to be under the table_lock mutex for the entire
0186  * loop. Use this iterator if your loop is long or if it might sleep.
0187  */
0188 #define ice_for_each_vf(pf, bkt, vf) \
0189     hash_for_each((pf)->vfs.table, (bkt), (vf), entry)
0190 
0191 /**
0192  * ice_for_each_vf_rcu - Iterate over each VF entry protected by RCU
0193  * @pf: pointer to the PF private structure
0194  * @bkt: bucket index used for iteration
0195  * @vf: pointer to the VF entry currently being processed in the loop
0196  *
0197  * The bkt variable is an unsigned integer iterator used to traverse the VF
0198  * entries. It is *not* guaranteed to be the VF's vf_id. Do not assume it is.
0199  * Use vf->vf_id to get the id number if needed.
0200  *
0201  * The caller is expected to be under rcu_read_lock() for the entire loop.
0202  * Only use this iterator if your loop is short and you can guarantee it does
0203  * not sleep.
0204  */
0205 #define ice_for_each_vf_rcu(pf, bkt, vf) \
0206     hash_for_each_rcu((pf)->vfs.table, (bkt), (vf), entry)
0207 
0208 #ifdef CONFIG_PCI_IOV
0209 struct ice_vf *ice_get_vf_by_id(struct ice_pf *pf, u16 vf_id);
0210 void ice_put_vf(struct ice_vf *vf);
0211 bool ice_has_vfs(struct ice_pf *pf);
0212 u16 ice_get_num_vfs(struct ice_pf *pf);
0213 struct ice_vsi *ice_get_vf_vsi(struct ice_vf *vf);
0214 bool ice_is_vf_disabled(struct ice_vf *vf);
0215 int ice_check_vf_ready_for_cfg(struct ice_vf *vf);
0216 void ice_set_vf_state_qs_dis(struct ice_vf *vf);
0217 bool ice_is_any_vf_in_unicast_promisc(struct ice_pf *pf);
0218 void
0219 ice_vf_get_promisc_masks(struct ice_vf *vf, struct ice_vsi *vsi,
0220              u8 *ucast_m, u8 *mcast_m);
0221 int
0222 ice_vf_set_vsi_promisc(struct ice_vf *vf, struct ice_vsi *vsi, u8 promisc_m);
0223 int
0224 ice_vf_clear_vsi_promisc(struct ice_vf *vf, struct ice_vsi *vsi, u8 promisc_m);
0225 int ice_reset_vf(struct ice_vf *vf, u32 flags);
0226 void ice_reset_all_vfs(struct ice_pf *pf);
0227 #else /* CONFIG_PCI_IOV */
0228 static inline struct ice_vf *ice_get_vf_by_id(struct ice_pf *pf, u16 vf_id)
0229 {
0230     return NULL;
0231 }
0232 
0233 static inline void ice_put_vf(struct ice_vf *vf)
0234 {
0235 }
0236 
0237 static inline bool ice_has_vfs(struct ice_pf *pf)
0238 {
0239     return false;
0240 }
0241 
0242 static inline u16 ice_get_num_vfs(struct ice_pf *pf)
0243 {
0244     return 0;
0245 }
0246 
0247 static inline struct ice_vsi *ice_get_vf_vsi(struct ice_vf *vf)
0248 {
0249     return NULL;
0250 }
0251 
0252 static inline bool ice_is_vf_disabled(struct ice_vf *vf)
0253 {
0254     return true;
0255 }
0256 
0257 static inline int ice_check_vf_ready_for_cfg(struct ice_vf *vf)
0258 {
0259     return -EOPNOTSUPP;
0260 }
0261 
0262 static inline void ice_set_vf_state_qs_dis(struct ice_vf *vf)
0263 {
0264 }
0265 
0266 static inline bool ice_is_any_vf_in_unicast_promisc(struct ice_pf *pf)
0267 {
0268     return false;
0269 }
0270 
0271 static inline int
0272 ice_vf_set_vsi_promisc(struct ice_vf *vf, struct ice_vsi *vsi, u8 promisc_m)
0273 {
0274     return -EOPNOTSUPP;
0275 }
0276 
0277 static inline int
0278 ice_vf_clear_vsi_promisc(struct ice_vf *vf, struct ice_vsi *vsi, u8 promisc_m)
0279 {
0280     return -EOPNOTSUPP;
0281 }
0282 
0283 static inline int ice_reset_vf(struct ice_vf *vf, u32 flags)
0284 {
0285     return 0;
0286 }
0287 
0288 static inline void ice_reset_all_vfs(struct ice_pf *pf)
0289 {
0290 }
0291 #endif /* !CONFIG_PCI_IOV */
0292 
0293 #endif /* _ICE_VF_LIB_H_ */