0001
0002
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
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
0028 enum ice_virtchnl_cap {
0029 ICE_VIRTCHNL_VF_CAP_PRIVILEGE = 0,
0030 };
0031
0032
0033 enum ice_vf_states {
0034 ICE_VF_STATE_INIT = 0,
0035 ICE_VF_STATE_ACTIVE,
0036 ICE_VF_STATE_QS_ENA,
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
0049 struct ice_mdd_vf_events {
0050 u16 count;
0051
0052 u16 last_printed;
0053 };
0054
0055
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
0068 struct ice_vfs {
0069 DECLARE_HASHTABLE(table, 8);
0070 struct mutex table_lock;
0071 u16 num_supported;
0072 u16 num_qps_per;
0073 u16 num_msix_per;
0074 unsigned long last_printed_mdd_jiffies;
0075 DECLARE_BITMAP(malvfs, ICE_MAX_SRIOV_VFS);
0076 };
0077
0078
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
0086
0087
0088 struct mutex cfg_lock;
0089
0090 u16 vf_id;
0091 u16 lan_vsi_idx;
0092 u16 ctrl_vsi_idx;
0093 struct ice_vf_fdir fdir;
0094
0095 int first_vector_idx;
0096 struct ice_sw *vf_sw_id;
0097 struct virtchnl_version_info vf_ver;
0098 u32 driver_caps;
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;
0105 struct virtchnl_vlan_caps vlan_v2_caps;
0106 u8 pf_set_mac:1;
0107 u8 trusted:1;
0108 u8 spoofchk:1;
0109 u8 link_forced:1;
0110 u8 link_up:1;
0111
0112
0113
0114
0115 u16 lan_vsi_num;
0116 unsigned int min_tx_rate;
0117 unsigned int max_tx_rate;
0118 DECLARE_BITMAP(vf_states, ICE_VF_STATES_NBITS);
0119
0120 unsigned long vf_caps;
0121 u8 num_req_qs;
0122 u16 num_mac;
0123 u16 num_vf_qs;
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
0133 struct devlink_port devlink_port;
0134 };
0135
0136
0137 enum ice_vf_reset_flags {
0138 ICE_VF_RESET_VFLR = BIT(0),
0139 ICE_VF_RESET_NOTIFY = BIT(1),
0140 ICE_VF_RESET_LOCK = BIT(2),
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
0164
0165
0166
0167
0168
0169
0170
0171
0172
0173
0174
0175
0176
0177
0178
0179
0180
0181
0182
0183
0184
0185
0186
0187
0188 #define ice_for_each_vf(pf, bkt, vf) \
0189 hash_for_each((pf)->vfs.table, (bkt), (vf), entry)
0190
0191
0192
0193
0194
0195
0196
0197
0198
0199
0200
0201
0202
0203
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
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
0292
0293 #endif