1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* Copyright (c) 2018, Intel Corporation. */
4 #ifndef _ICE_VIRTCHNL_PF_H_
5 #define _ICE_VIRTCHNL_PF_H_
7 #include "ice_virtchnl_fdir.h"
8 #include "ice_vsi_vlan_ops.h"
10 /* Restrict number of MAC Addr and VLAN that non-trusted VF can programmed */
11 #define ICE_MAX_VLAN_PER_VF 8
12 /* MAC filters: 1 is reserved for the VF's default/perm_addr/LAA MAC, 1 for
13 * broadcast, and 16 for additional unicast/multicast filters
15 #define ICE_MAX_MACADDR_PER_VF 18
17 /* Malicious Driver Detection */
18 #define ICE_MDD_EVENTS_THRESHOLD 30
20 /* Static VF transaction/status register def */
21 #define VF_DEVICE_STATUS 0xAA
22 #define VF_TRANS_PENDING_M 0x20
24 /* wait defines for polling PF_PCI_CIAD register status */
25 #define ICE_PCI_CIAD_WAIT_COUNT 100
26 #define ICE_PCI_CIAD_WAIT_DELAY_US 1
28 /* VF resource constraints */
29 #define ICE_MAX_VF_COUNT 256
30 #define ICE_MIN_QS_PER_VF 1
31 #define ICE_NONQ_VECS_VF 1
32 #define ICE_MAX_SCATTER_QS_PER_VF 16
33 #define ICE_MAX_RSS_QS_PER_VF 16
34 #define ICE_NUM_VF_MSIX_MED 17
35 #define ICE_NUM_VF_MSIX_SMALL 5
36 #define ICE_NUM_VF_MSIX_MULTIQ_MIN 3
37 #define ICE_MIN_INTR_PER_VF (ICE_MIN_QS_PER_VF + 1)
38 #define ICE_MAX_VF_RESET_TRIES 40
39 #define ICE_MAX_VF_RESET_SLEEP_MS 20
41 /* VF Hash Table access functions
43 * These functions provide abstraction for interacting with the VF hash table.
44 * In general, direct access to the hash table should be avoided outside of
45 * these functions where possible.
47 * The VF entries in the hash table are protected by reference counting to
48 * track lifetime of accesses from the table. The ice_get_vf_by_id() function
49 * obtains a reference to the VF structure which must be dropped by using
54 * ice_for_each_vf - Iterate over each VF entry
55 * @pf: pointer to the PF private structure
56 * @bkt: bucket index used for iteration
57 * @vf: pointer to the VF entry currently being processed in the loop.
59 * The bkt variable is an unsigned integer iterator used to traverse the VF
60 * entries. It is *not* guaranteed to be the VF's vf_id. Do not assume it is.
61 * Use vf->vf_id to get the id number if needed.
63 * The caller is expected to be under the table_lock mutex for the entire
64 * loop. Use this iterator if your loop is long or if it might sleep.
66 #define ice_for_each_vf(pf, bkt, vf) \
67 hash_for_each((pf)->vfs.table, (bkt), (vf), entry)
70 * ice_for_each_vf_rcu - Iterate over each VF entry protected by RCU
71 * @pf: pointer to the PF private structure
72 * @bkt: bucket index used for iteration
73 * @vf: pointer to the VF entry currently being processed in the loop.
75 * The bkt variable is an unsigned integer iterator used to traverse the VF
76 * entries. It is *not* guaranteed to be the VF's vf_id. Do not assume it is.
77 * Use vf->vf_id to get the id number if needed.
79 * The caller is expected to be under rcu_read_lock() for the entire loop.
80 * Only use this iterator if your loop is short and you can guarantee it does
83 #define ice_for_each_vf_rcu(pf, bkt, vf) \
84 hash_for_each_rcu((pf)->vfs.table, (bkt), (vf), entry)
86 /* Specific VF states */
88 ICE_VF_STATE_INIT = 0, /* PF is initializing VF */
89 ICE_VF_STATE_ACTIVE, /* VF resources are allocated for use */
90 ICE_VF_STATE_QS_ENA, /* VF queue(s) enabled */
92 ICE_VF_STATE_MC_PROMISC,
93 ICE_VF_STATE_UC_PROMISC,
98 enum ice_virtchnl_cap {
99 ICE_VIRTCHNL_VF_CAP_L2 = 0,
100 ICE_VIRTCHNL_VF_CAP_PRIVILEGE,
103 struct ice_time_mac {
104 unsigned long time_modified;
108 /* VF MDD events print structure */
109 struct ice_mdd_vf_events {
110 u16 count; /* total count of Rx|Tx events */
111 /* count number of the last printed event */
117 struct ice_vc_vf_ops {
118 int (*get_ver_msg)(struct ice_vf *vf, u8 *msg);
119 int (*get_vf_res_msg)(struct ice_vf *vf, u8 *msg);
120 void (*reset_vf)(struct ice_vf *vf);
121 int (*add_mac_addr_msg)(struct ice_vf *vf, u8 *msg);
122 int (*del_mac_addr_msg)(struct ice_vf *vf, u8 *msg);
123 int (*cfg_qs_msg)(struct ice_vf *vf, u8 *msg);
124 int (*ena_qs_msg)(struct ice_vf *vf, u8 *msg);
125 int (*dis_qs_msg)(struct ice_vf *vf, u8 *msg);
126 int (*request_qs_msg)(struct ice_vf *vf, u8 *msg);
127 int (*cfg_irq_map_msg)(struct ice_vf *vf, u8 *msg);
128 int (*config_rss_key)(struct ice_vf *vf, u8 *msg);
129 int (*config_rss_lut)(struct ice_vf *vf, u8 *msg);
130 int (*get_stats_msg)(struct ice_vf *vf, u8 *msg);
131 int (*cfg_promiscuous_mode_msg)(struct ice_vf *vf, u8 *msg);
132 int (*add_vlan_msg)(struct ice_vf *vf, u8 *msg);
133 int (*remove_vlan_msg)(struct ice_vf *vf, u8 *msg);
134 int (*ena_vlan_stripping)(struct ice_vf *vf);
135 int (*dis_vlan_stripping)(struct ice_vf *vf);
136 int (*handle_rss_cfg_msg)(struct ice_vf *vf, u8 *msg, bool add);
137 int (*add_fdir_fltr_msg)(struct ice_vf *vf, u8 *msg);
138 int (*del_fdir_fltr_msg)(struct ice_vf *vf, u8 *msg);
139 int (*get_offload_vlan_v2_caps)(struct ice_vf *vf);
140 int (*add_vlan_v2_msg)(struct ice_vf *vf, u8 *msg);
141 int (*remove_vlan_v2_msg)(struct ice_vf *vf, u8 *msg);
142 int (*ena_vlan_stripping_v2_msg)(struct ice_vf *vf, u8 *msg);
143 int (*dis_vlan_stripping_v2_msg)(struct ice_vf *vf, u8 *msg);
144 int (*ena_vlan_insertion_v2_msg)(struct ice_vf *vf, u8 *msg);
145 int (*dis_vlan_insertion_v2_msg)(struct ice_vf *vf, u8 *msg);
148 /* Virtchnl/SR-IOV config info */
150 DECLARE_HASHTABLE(table, 8); /* table of VF entries */
151 struct mutex table_lock; /* Lock for protecting the hash table */
152 u16 num_supported; /* max supported VFs on this PF */
153 u16 num_qps_per; /* number of queue pairs per VF */
154 u16 num_msix_per; /* number of MSI-X vectors per VF */
155 unsigned long last_printed_mdd_jiffies; /* MDD message rate limit */
156 DECLARE_BITMAP(malvfs, ICE_MAX_VF_COUNT); /* malicious VF indicator */
159 /* VF information structure */
161 struct hlist_node entry;
166 /* Used during virtchnl message handling and NDO ops against the VF
167 * that will trigger a VFR
169 struct mutex cfg_lock;
171 u16 vf_id; /* VF ID in the PF space */
172 u16 lan_vsi_idx; /* index into PF struct */
174 struct ice_vf_fdir fdir;
175 /* first vector index of this VF in the PF space */
176 int first_vector_idx;
177 struct ice_sw *vf_sw_id; /* switch ID the VF VSIs connect to */
178 struct virtchnl_version_info vf_ver;
179 u32 driver_caps; /* reported by VF driver */
180 struct virtchnl_ether_addr dev_lan_addr;
181 struct virtchnl_ether_addr hw_lan_addr;
182 struct ice_time_mac legacy_last_added_umac;
183 DECLARE_BITMAP(txq_ena, ICE_MAX_RSS_QS_PER_VF);
184 DECLARE_BITMAP(rxq_ena, ICE_MAX_RSS_QS_PER_VF);
185 struct ice_vlan port_vlan_info; /* Port VLAN ID, QoS, and TPID */
186 struct virtchnl_vlan_caps vlan_v2_caps;
187 u8 pf_set_mac:1; /* VF MAC address set by VMM admin */
191 u8 link_up:1; /* only valid if VF link is forced */
192 /* VSI indices - actual VSI pointers are maintained in the PF structure
193 * When assigned, these will be non-zero, because VSI 0 is always
194 * the main LAN VSI for the PF.
196 u16 lan_vsi_num; /* ID as used by firmware */
197 unsigned int min_tx_rate; /* Minimum Tx bandwidth limit in Mbps */
198 unsigned int max_tx_rate; /* Maximum Tx bandwidth limit in Mbps */
199 DECLARE_BITMAP(vf_states, ICE_VF_STATES_NBITS); /* VF runtime states */
201 unsigned long vf_caps; /* VF's adv. capabilities */
202 u8 num_req_qs; /* num of queue pairs requested by VF */
204 u16 num_vf_qs; /* num of queue configured per VF */
205 struct ice_mdd_vf_events mdd_rx_events;
206 struct ice_mdd_vf_events mdd_tx_events;
207 DECLARE_BITMAP(opcodes_allowlist, VIRTCHNL_OP_MAX);
209 struct ice_repr *repr;
211 struct ice_vc_vf_ops vc_ops;
213 /* devlink port data */
214 struct devlink_port devlink_port;
217 #ifdef CONFIG_PCI_IOV
218 struct ice_vf *ice_get_vf_by_id(struct ice_pf *pf, u16 vf_id);
219 void ice_put_vf(struct ice_vf *vf);
220 bool ice_has_vfs(struct ice_pf *pf);
221 u16 ice_get_num_vfs(struct ice_pf *pf);
222 struct ice_vsi *ice_get_vf_vsi(struct ice_vf *vf);
223 void ice_process_vflr_event(struct ice_pf *pf);
224 int ice_sriov_configure(struct pci_dev *pdev, int num_vfs);
225 int ice_set_vf_mac(struct net_device *netdev, int vf_id, u8 *mac);
227 ice_get_vf_cfg(struct net_device *netdev, int vf_id, struct ifla_vf_info *ivi);
229 void ice_free_vfs(struct ice_pf *pf);
230 void ice_vc_process_vf_msg(struct ice_pf *pf, struct ice_rq_event_info *event);
231 void ice_vc_notify_link_state(struct ice_pf *pf);
232 void ice_vc_notify_reset(struct ice_pf *pf);
233 void ice_vc_notify_vf_link_state(struct ice_vf *vf);
234 void ice_vc_change_ops_to_repr(struct ice_vc_vf_ops *ops);
235 void ice_vc_set_dflt_vf_ops(struct ice_vc_vf_ops *ops);
236 bool ice_reset_all_vfs(struct ice_pf *pf, bool is_vflr);
237 bool ice_reset_vf(struct ice_vf *vf, bool is_vflr);
238 void ice_restore_all_vfs_msi_state(struct pci_dev *pdev);
240 ice_is_malicious_vf(struct ice_pf *pf, struct ice_rq_event_info *event,
241 u16 num_msg_proc, u16 num_msg_pending);
244 ice_set_vf_port_vlan(struct net_device *netdev, int vf_id, u16 vlan_id, u8 qos,
248 ice_set_vf_bw(struct net_device *netdev, int vf_id, int min_tx_rate,
251 int ice_set_vf_trust(struct net_device *netdev, int vf_id, bool trusted);
253 int ice_set_vf_link_state(struct net_device *netdev, int vf_id, int link_state);
255 int ice_check_vf_ready_for_cfg(struct ice_vf *vf);
257 bool ice_is_vf_disabled(struct ice_vf *vf);
259 int ice_set_vf_spoofchk(struct net_device *netdev, int vf_id, bool ena);
261 int ice_calc_vf_reg_idx(struct ice_vf *vf, struct ice_q_vector *q_vector);
263 void ice_set_vf_state_qs_dis(struct ice_vf *vf);
265 ice_get_vf_stats(struct net_device *netdev, int vf_id,
266 struct ifla_vf_stats *vf_stats);
267 bool ice_is_any_vf_in_promisc(struct ice_pf *pf);
269 ice_vf_lan_overflow_event(struct ice_pf *pf, struct ice_rq_event_info *event);
270 void ice_print_vfs_mdd_events(struct ice_pf *pf);
271 void ice_print_vf_rx_mdd_event(struct ice_vf *vf);
273 ice_vc_validate_pattern(struct ice_vf *vf, struct virtchnl_proto_hdrs *proto);
274 struct ice_vsi *ice_vf_ctrl_vsi_setup(struct ice_vf *vf);
276 ice_vc_send_msg_to_vf(struct ice_vf *vf, u32 v_opcode,
277 enum virtchnl_status_code v_retval, u8 *msg, u16 msglen);
278 bool ice_vc_isvalid_vsi_id(struct ice_vf *vf, u16 vsi_id);
279 bool ice_vf_is_port_vlan_ena(struct ice_vf *vf);
280 #else /* CONFIG_PCI_IOV */
281 static inline struct ice_vf *ice_get_vf_by_id(struct ice_pf *pf, u16 vf_id)
286 static inline void ice_put_vf(struct ice_vf *vf)
290 static inline bool ice_has_vfs(struct ice_pf *pf)
295 static inline u16 ice_get_num_vfs(struct ice_pf *pf)
300 static inline void ice_process_vflr_event(struct ice_pf *pf) { }
301 static inline void ice_free_vfs(struct ice_pf *pf) { }
303 void ice_vc_process_vf_msg(struct ice_pf *pf, struct ice_rq_event_info *event) { }
304 static inline void ice_vc_notify_link_state(struct ice_pf *pf) { }
305 static inline void ice_vc_notify_reset(struct ice_pf *pf) { }
306 static inline void ice_vc_notify_vf_link_state(struct ice_vf *vf) { }
307 static inline void ice_vc_change_ops_to_repr(struct ice_vc_vf_ops *ops) { }
308 static inline void ice_vc_set_dflt_vf_ops(struct ice_vc_vf_ops *ops) { }
309 static inline void ice_set_vf_state_qs_dis(struct ice_vf *vf) { }
311 void ice_vf_lan_overflow_event(struct ice_pf *pf, struct ice_rq_event_info *event) { }
312 static inline void ice_print_vfs_mdd_events(struct ice_pf *pf) { }
313 static inline void ice_print_vf_rx_mdd_event(struct ice_vf *vf) { }
314 static inline void ice_restore_all_vfs_msi_state(struct pci_dev *pdev) { }
316 static inline int ice_check_vf_ready_for_cfg(struct ice_vf *vf)
321 static inline bool ice_is_vf_disabled(struct ice_vf *vf)
326 static inline struct ice_vsi *ice_get_vf_vsi(struct ice_vf *vf)
332 ice_is_malicious_vf(struct ice_pf __always_unused *pf,
333 struct ice_rq_event_info __always_unused *event,
334 u16 __always_unused num_msg_proc,
335 u16 __always_unused num_msg_pending)
341 ice_reset_all_vfs(struct ice_pf __always_unused *pf,
342 bool __always_unused is_vflr)
348 ice_reset_vf(struct ice_vf __always_unused *vf, bool __always_unused is_vflr)
354 ice_sriov_configure(struct pci_dev __always_unused *pdev,
355 int __always_unused num_vfs)
361 ice_set_vf_mac(struct net_device __always_unused *netdev,
362 int __always_unused vf_id, u8 __always_unused *mac)
368 ice_get_vf_cfg(struct net_device __always_unused *netdev,
369 int __always_unused vf_id,
370 struct ifla_vf_info __always_unused *ivi)
376 ice_set_vf_trust(struct net_device __always_unused *netdev,
377 int __always_unused vf_id, bool __always_unused trusted)
383 ice_set_vf_port_vlan(struct net_device __always_unused *netdev,
384 int __always_unused vf_id, u16 __always_unused vid,
385 u8 __always_unused qos, __be16 __always_unused v_proto)
391 ice_set_vf_spoofchk(struct net_device __always_unused *netdev,
392 int __always_unused vf_id, bool __always_unused ena)
398 ice_set_vf_link_state(struct net_device __always_unused *netdev,
399 int __always_unused vf_id, int __always_unused link_state)
405 ice_set_vf_bw(struct net_device __always_unused *netdev,
406 int __always_unused vf_id, int __always_unused min_tx_rate,
407 int __always_unused max_tx_rate)
413 ice_calc_vf_reg_idx(struct ice_vf __always_unused *vf,
414 struct ice_q_vector __always_unused *q_vector)
420 ice_get_vf_stats(struct net_device __always_unused *netdev,
421 int __always_unused vf_id,
422 struct ifla_vf_stats __always_unused *vf_stats)
427 static inline bool ice_is_any_vf_in_promisc(struct ice_pf __always_unused *pf)
432 static inline bool ice_vf_is_port_vlan_ena(struct ice_vf __always_unused *vf)
436 #endif /* CONFIG_PCI_IOV */
437 #endif /* _ICE_VIRTCHNL_PF_H_ */