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"
9 /* Restrict number of MAC Addr and VLAN that non-trusted VF can programmed */
10 #define ICE_MAX_VLAN_PER_VF 8
11 /* MAC filters: 1 is reserved for the VF's default/perm_addr/LAA MAC, 1 for
12 * broadcast, and 16 for additional unicast/multicast filters
14 #define ICE_MAX_MACADDR_PER_VF 18
16 /* Malicious Driver Detection */
17 #define ICE_DFLT_NUM_INVAL_MSGS_ALLOWED 10
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 #define ice_for_each_vf(pf, i) \
42 for ((i) = 0; (i) < (pf)->num_alloc_vfs; (i)++)
44 /* Specific VF states */
46 ICE_VF_STATE_INIT = 0, /* PF is initializing VF */
47 ICE_VF_STATE_ACTIVE, /* VF resources are allocated for use */
48 ICE_VF_STATE_QS_ENA, /* VF queue(s) enabled */
50 ICE_VF_STATE_MC_PROMISC,
51 ICE_VF_STATE_UC_PROMISC,
56 enum ice_virtchnl_cap {
57 ICE_VIRTCHNL_VF_CAP_L2 = 0,
58 ICE_VIRTCHNL_VF_CAP_PRIVILEGE,
62 unsigned long time_modified;
66 /* VF MDD events print structure */
67 struct ice_mdd_vf_events {
68 u16 count; /* total count of Rx|Tx events */
69 /* count number of the last printed event */
73 /* VF information structure */
77 u16 vf_id; /* VF ID in the PF space */
78 u16 lan_vsi_idx; /* index into PF struct */
80 struct ice_vf_fdir fdir;
81 /* first vector index of this VF in the PF space */
83 struct ice_sw *vf_sw_id; /* switch ID the VF VSIs connect to */
84 struct virtchnl_version_info vf_ver;
85 u32 driver_caps; /* reported by VF driver */
86 struct virtchnl_ether_addr dev_lan_addr;
87 struct virtchnl_ether_addr hw_lan_addr;
88 struct ice_time_mac legacy_last_added_umac;
89 DECLARE_BITMAP(txq_ena, ICE_MAX_RSS_QS_PER_VF);
90 DECLARE_BITMAP(rxq_ena, ICE_MAX_RSS_QS_PER_VF);
91 u16 port_vlan_info; /* Port VLAN ID and QoS */
92 u8 pf_set_mac:1; /* VF MAC address set by VMM admin */
96 u8 link_up:1; /* only valid if VF link is forced */
97 /* VSI indices - actual VSI pointers are maintained in the PF structure
98 * When assigned, these will be non-zero, because VSI 0 is always
99 * the main LAN VSI for the PF.
101 u16 lan_vsi_num; /* ID as used by firmware */
102 unsigned int tx_rate; /* Tx bandwidth limit in Mbps */
103 DECLARE_BITMAP(vf_states, ICE_VF_STATES_NBITS); /* VF runtime states */
105 u64 num_inval_msgs; /* number of continuous invalid msgs */
106 u64 num_valid_msgs; /* number of valid msgs detected */
107 unsigned long vf_caps; /* VF's adv. capabilities */
108 u8 num_req_qs; /* num of queue pairs requested by VF */
110 u16 num_vf_qs; /* num of queue configured per VF */
111 struct ice_mdd_vf_events mdd_rx_events;
112 struct ice_mdd_vf_events mdd_tx_events;
113 DECLARE_BITMAP(opcodes_allowlist, VIRTCHNL_OP_MAX);
116 #ifdef CONFIG_PCI_IOV
117 void ice_process_vflr_event(struct ice_pf *pf);
118 int ice_sriov_configure(struct pci_dev *pdev, int num_vfs);
119 int ice_set_vf_mac(struct net_device *netdev, int vf_id, u8 *mac);
121 ice_get_vf_cfg(struct net_device *netdev, int vf_id, struct ifla_vf_info *ivi);
123 void ice_free_vfs(struct ice_pf *pf);
124 void ice_vc_process_vf_msg(struct ice_pf *pf, struct ice_rq_event_info *event);
125 void ice_vc_notify_link_state(struct ice_pf *pf);
126 void ice_vc_notify_reset(struct ice_pf *pf);
127 bool ice_reset_all_vfs(struct ice_pf *pf, bool is_vflr);
128 bool ice_reset_vf(struct ice_vf *vf, bool is_vflr);
129 void ice_restore_all_vfs_msi_state(struct pci_dev *pdev);
131 ice_is_malicious_vf(struct ice_pf *pf, struct ice_rq_event_info *event,
132 u16 num_msg_proc, u16 num_msg_pending);
135 ice_set_vf_port_vlan(struct net_device *netdev, int vf_id, u16 vlan_id, u8 qos,
138 int ice_set_vf_trust(struct net_device *netdev, int vf_id, bool trusted);
140 int ice_set_vf_link_state(struct net_device *netdev, int vf_id, int link_state);
142 int ice_set_vf_spoofchk(struct net_device *netdev, int vf_id, bool ena);
144 int ice_calc_vf_reg_idx(struct ice_vf *vf, struct ice_q_vector *q_vector);
146 void ice_set_vf_state_qs_dis(struct ice_vf *vf);
148 ice_get_vf_stats(struct net_device *netdev, int vf_id,
149 struct ifla_vf_stats *vf_stats);
150 bool ice_is_any_vf_in_promisc(struct ice_pf *pf);
152 ice_vf_lan_overflow_event(struct ice_pf *pf, struct ice_rq_event_info *event);
153 void ice_print_vfs_mdd_events(struct ice_pf *pf);
154 void ice_print_vf_rx_mdd_event(struct ice_vf *vf);
155 struct ice_vsi *ice_vf_ctrl_vsi_setup(struct ice_vf *vf);
157 ice_vc_send_msg_to_vf(struct ice_vf *vf, u32 v_opcode,
158 enum virtchnl_status_code v_retval, u8 *msg, u16 msglen);
159 bool ice_vc_isvalid_vsi_id(struct ice_vf *vf, u16 vsi_id);
160 #else /* CONFIG_PCI_IOV */
161 static inline void ice_process_vflr_event(struct ice_pf *pf) { }
162 static inline void ice_free_vfs(struct ice_pf *pf) { }
164 void ice_vc_process_vf_msg(struct ice_pf *pf, struct ice_rq_event_info *event) { }
165 static inline void ice_vc_notify_link_state(struct ice_pf *pf) { }
166 static inline void ice_vc_notify_reset(struct ice_pf *pf) { }
167 static inline void ice_set_vf_state_qs_dis(struct ice_vf *vf) { }
169 void ice_vf_lan_overflow_event(struct ice_pf *pf, struct ice_rq_event_info *event) { }
170 static inline void ice_print_vfs_mdd_events(struct ice_pf *pf) { }
171 static inline void ice_print_vf_rx_mdd_event(struct ice_vf *vf) { }
172 static inline void ice_restore_all_vfs_msi_state(struct pci_dev *pdev) { }
175 ice_is_malicious_vf(struct ice_pf __always_unused *pf,
176 struct ice_rq_event_info __always_unused *event,
177 u16 __always_unused num_msg_proc,
178 u16 __always_unused num_msg_pending)
184 ice_reset_all_vfs(struct ice_pf __always_unused *pf,
185 bool __always_unused is_vflr)
191 ice_reset_vf(struct ice_vf __always_unused *vf, bool __always_unused is_vflr)
197 ice_sriov_configure(struct pci_dev __always_unused *pdev,
198 int __always_unused num_vfs)
204 ice_set_vf_mac(struct net_device __always_unused *netdev,
205 int __always_unused vf_id, u8 __always_unused *mac)
211 ice_get_vf_cfg(struct net_device __always_unused *netdev,
212 int __always_unused vf_id,
213 struct ifla_vf_info __always_unused *ivi)
219 ice_set_vf_trust(struct net_device __always_unused *netdev,
220 int __always_unused vf_id, bool __always_unused trusted)
226 ice_set_vf_port_vlan(struct net_device __always_unused *netdev,
227 int __always_unused vf_id, u16 __always_unused vid,
228 u8 __always_unused qos, __be16 __always_unused v_proto)
234 ice_set_vf_spoofchk(struct net_device __always_unused *netdev,
235 int __always_unused vf_id, bool __always_unused ena)
241 ice_set_vf_link_state(struct net_device __always_unused *netdev,
242 int __always_unused vf_id, int __always_unused link_state)
248 ice_calc_vf_reg_idx(struct ice_vf __always_unused *vf,
249 struct ice_q_vector __always_unused *q_vector)
255 ice_get_vf_stats(struct net_device __always_unused *netdev,
256 int __always_unused vf_id,
257 struct ifla_vf_stats __always_unused *vf_stats)
262 static inline bool ice_is_any_vf_in_promisc(struct ice_pf __always_unused *pf)
266 #endif /* CONFIG_PCI_IOV */
267 #endif /* _ICE_VIRTCHNL_PF_H_ */