• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* Copyright (c) 2018, Intel Corporation. */
3 
4 #ifndef _ICE_VIRTCHNL_PF_H_
5 #define _ICE_VIRTCHNL_PF_H_
6 #include "ice.h"
7 #include "ice_virtchnl_fdir.h"
8 
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
13  */
14 #define ICE_MAX_MACADDR_PER_VF		18
15 
16 /* Malicious Driver Detection */
17 #define ICE_MDD_EVENTS_THRESHOLD		30
18 
19 /* Static VF transaction/status register def */
20 #define VF_DEVICE_STATUS		0xAA
21 #define VF_TRANS_PENDING_M		0x20
22 
23 /* wait defines for polling PF_PCI_CIAD register status */
24 #define ICE_PCI_CIAD_WAIT_COUNT		100
25 #define ICE_PCI_CIAD_WAIT_DELAY_US	1
26 
27 /* VF resource constraints */
28 #define ICE_MAX_VF_COUNT		256
29 #define ICE_MIN_QS_PER_VF		1
30 #define ICE_NONQ_VECS_VF		1
31 #define ICE_MAX_SCATTER_QS_PER_VF	16
32 #define ICE_MAX_RSS_QS_PER_VF		16
33 #define ICE_NUM_VF_MSIX_MED		17
34 #define ICE_NUM_VF_MSIX_SMALL		5
35 #define ICE_NUM_VF_MSIX_MULTIQ_MIN	3
36 #define ICE_MIN_INTR_PER_VF		(ICE_MIN_QS_PER_VF + 1)
37 #define ICE_MAX_VF_RESET_TRIES		40
38 #define ICE_MAX_VF_RESET_SLEEP_MS	20
39 
40 #define ice_for_each_vf(pf, i) \
41 	for ((i) = 0; (i) < (pf)->num_alloc_vfs; (i)++)
42 
43 /* Specific VF states */
44 enum ice_vf_states {
45 	ICE_VF_STATE_INIT = 0,		/* PF is initializing VF */
46 	ICE_VF_STATE_ACTIVE,		/* VF resources are allocated for use */
47 	ICE_VF_STATE_QS_ENA,		/* VF queue(s) enabled */
48 	ICE_VF_STATE_DIS,
49 	ICE_VF_STATE_MC_PROMISC,
50 	ICE_VF_STATE_UC_PROMISC,
51 	ICE_VF_STATES_NBITS
52 };
53 
54 /* VF capabilities */
55 enum ice_virtchnl_cap {
56 	ICE_VIRTCHNL_VF_CAP_L2 = 0,
57 	ICE_VIRTCHNL_VF_CAP_PRIVILEGE,
58 };
59 
60 struct ice_time_mac {
61 	unsigned long time_modified;
62 	u8 addr[ETH_ALEN];
63 };
64 
65 /* VF MDD events print structure */
66 struct ice_mdd_vf_events {
67 	u16 count;			/* total count of Rx|Tx events */
68 	/* count number of the last printed event */
69 	u16 last_printed;
70 };
71 
72 /* VF information structure */
73 struct ice_vf {
74 	struct ice_pf *pf;
75 
76 	/* Used during virtchnl message handling and NDO ops against the VF
77 	 * that will trigger a VFR
78 	 */
79 	struct mutex cfg_lock;
80 
81 	u16 vf_id;			/* VF ID in the PF space */
82 	u16 lan_vsi_idx;		/* index into PF struct */
83 	u16 ctrl_vsi_idx;
84 	struct ice_vf_fdir fdir;
85 	/* first vector index of this VF in the PF space */
86 	int first_vector_idx;
87 	struct ice_sw *vf_sw_id;	/* switch ID the VF VSIs connect to */
88 	struct virtchnl_version_info vf_ver;
89 	u32 driver_caps;		/* reported by VF driver */
90 	struct virtchnl_ether_addr dev_lan_addr;
91 	struct virtchnl_ether_addr hw_lan_addr;
92 	struct ice_time_mac legacy_last_added_umac;
93 	DECLARE_BITMAP(txq_ena, ICE_MAX_RSS_QS_PER_VF);
94 	DECLARE_BITMAP(rxq_ena, ICE_MAX_RSS_QS_PER_VF);
95 	u16 port_vlan_info;		/* Port VLAN ID and QoS */
96 	u8 pf_set_mac:1;		/* VF MAC address set by VMM admin */
97 	u8 trusted:1;
98 	u8 spoofchk:1;
99 	u8 link_forced:1;
100 	u8 link_up:1;			/* only valid if VF link is forced */
101 	/* VSI indices - actual VSI pointers are maintained in the PF structure
102 	 * When assigned, these will be non-zero, because VSI 0 is always
103 	 * the main LAN VSI for the PF.
104 	 */
105 	u16 lan_vsi_num;		/* ID as used by firmware */
106 	unsigned int tx_rate;		/* Tx bandwidth limit in Mbps */
107 	DECLARE_BITMAP(vf_states, ICE_VF_STATES_NBITS);	/* VF runtime states */
108 
109 	unsigned long vf_caps;		/* VF's adv. capabilities */
110 	u8 num_req_qs;			/* num of queue pairs requested by VF */
111 	u16 num_mac;
112 	u16 num_vf_qs;			/* num of queue configured per VF */
113 	struct ice_mdd_vf_events mdd_rx_events;
114 	struct ice_mdd_vf_events mdd_tx_events;
115 	DECLARE_BITMAP(opcodes_allowlist, VIRTCHNL_OP_MAX);
116 
117 	/* devlink port data */
118 	struct devlink_port devlink_port;
119 };
120 
121 #ifdef CONFIG_PCI_IOV
122 struct ice_vsi *ice_get_vf_vsi(struct ice_vf *vf);
123 void ice_process_vflr_event(struct ice_pf *pf);
124 int ice_sriov_configure(struct pci_dev *pdev, int num_vfs);
125 int ice_set_vf_mac(struct net_device *netdev, int vf_id, u8 *mac);
126 int
127 ice_get_vf_cfg(struct net_device *netdev, int vf_id, struct ifla_vf_info *ivi);
128 
129 void ice_free_vfs(struct ice_pf *pf);
130 void ice_vc_process_vf_msg(struct ice_pf *pf, struct ice_rq_event_info *event);
131 void ice_vc_notify_link_state(struct ice_pf *pf);
132 void ice_vc_notify_reset(struct ice_pf *pf);
133 bool ice_reset_all_vfs(struct ice_pf *pf, bool is_vflr);
134 bool ice_reset_vf(struct ice_vf *vf, bool is_vflr);
135 void ice_restore_all_vfs_msi_state(struct pci_dev *pdev);
136 bool
137 ice_is_malicious_vf(struct ice_pf *pf, struct ice_rq_event_info *event,
138 		    u16 num_msg_proc, u16 num_msg_pending);
139 
140 int
141 ice_set_vf_port_vlan(struct net_device *netdev, int vf_id, u16 vlan_id, u8 qos,
142 		     __be16 vlan_proto);
143 
144 int ice_set_vf_trust(struct net_device *netdev, int vf_id, bool trusted);
145 
146 int ice_set_vf_link_state(struct net_device *netdev, int vf_id, int link_state);
147 
148 int ice_set_vf_spoofchk(struct net_device *netdev, int vf_id, bool ena);
149 
150 int ice_calc_vf_reg_idx(struct ice_vf *vf, struct ice_q_vector *q_vector);
151 
152 void ice_set_vf_state_qs_dis(struct ice_vf *vf);
153 int
154 ice_get_vf_stats(struct net_device *netdev, int vf_id,
155 		 struct ifla_vf_stats *vf_stats);
156 bool ice_is_any_vf_in_promisc(struct ice_pf *pf);
157 void
158 ice_vf_lan_overflow_event(struct ice_pf *pf, struct ice_rq_event_info *event);
159 void ice_print_vfs_mdd_events(struct ice_pf *pf);
160 void ice_print_vf_rx_mdd_event(struct ice_vf *vf);
161 struct ice_vsi *ice_vf_ctrl_vsi_setup(struct ice_vf *vf);
162 int
163 ice_vc_send_msg_to_vf(struct ice_vf *vf, u32 v_opcode,
164 		      enum virtchnl_status_code v_retval, u8 *msg, u16 msglen);
165 bool ice_vc_isvalid_vsi_id(struct ice_vf *vf, u16 vsi_id);
166 #else /* CONFIG_PCI_IOV */
ice_process_vflr_event(struct ice_pf * pf)167 static inline void ice_process_vflr_event(struct ice_pf *pf) { }
ice_free_vfs(struct ice_pf * pf)168 static inline void ice_free_vfs(struct ice_pf *pf) { }
169 static inline
ice_vc_process_vf_msg(struct ice_pf * pf,struct ice_rq_event_info * event)170 void ice_vc_process_vf_msg(struct ice_pf *pf, struct ice_rq_event_info *event) { }
ice_vc_notify_link_state(struct ice_pf * pf)171 static inline void ice_vc_notify_link_state(struct ice_pf *pf) { }
ice_vc_notify_reset(struct ice_pf * pf)172 static inline void ice_vc_notify_reset(struct ice_pf *pf) { }
ice_set_vf_state_qs_dis(struct ice_vf * vf)173 static inline void ice_set_vf_state_qs_dis(struct ice_vf *vf) { }
174 static inline
ice_vf_lan_overflow_event(struct ice_pf * pf,struct ice_rq_event_info * event)175 void ice_vf_lan_overflow_event(struct ice_pf *pf, struct ice_rq_event_info *event) { }
ice_print_vfs_mdd_events(struct ice_pf * pf)176 static inline void ice_print_vfs_mdd_events(struct ice_pf *pf) { }
ice_print_vf_rx_mdd_event(struct ice_vf * vf)177 static inline void ice_print_vf_rx_mdd_event(struct ice_vf *vf) { }
ice_restore_all_vfs_msi_state(struct pci_dev * pdev)178 static inline void ice_restore_all_vfs_msi_state(struct pci_dev *pdev) { }
179 
ice_get_vf_vsi(struct ice_vf * vf)180 static inline struct ice_vsi *ice_get_vf_vsi(struct ice_vf *vf)
181 {
182 	return NULL;
183 }
184 
185 static inline bool
ice_is_malicious_vf(struct ice_pf __always_unused * pf,struct ice_rq_event_info __always_unused * event,u16 __always_unused num_msg_proc,u16 __always_unused num_msg_pending)186 ice_is_malicious_vf(struct ice_pf __always_unused *pf,
187 		    struct ice_rq_event_info __always_unused *event,
188 		    u16 __always_unused num_msg_proc,
189 		    u16 __always_unused num_msg_pending)
190 {
191 	return false;
192 }
193 
194 static inline bool
ice_reset_all_vfs(struct ice_pf __always_unused * pf,bool __always_unused is_vflr)195 ice_reset_all_vfs(struct ice_pf __always_unused *pf,
196 		  bool __always_unused is_vflr)
197 {
198 	return true;
199 }
200 
201 static inline bool
ice_reset_vf(struct ice_vf __always_unused * vf,bool __always_unused is_vflr)202 ice_reset_vf(struct ice_vf __always_unused *vf, bool __always_unused is_vflr)
203 {
204 	return true;
205 }
206 
207 static inline int
ice_sriov_configure(struct pci_dev __always_unused * pdev,int __always_unused num_vfs)208 ice_sriov_configure(struct pci_dev __always_unused *pdev,
209 		    int __always_unused num_vfs)
210 {
211 	return -EOPNOTSUPP;
212 }
213 
214 static inline int
ice_set_vf_mac(struct net_device __always_unused * netdev,int __always_unused vf_id,u8 __always_unused * mac)215 ice_set_vf_mac(struct net_device __always_unused *netdev,
216 	       int __always_unused vf_id, u8 __always_unused *mac)
217 {
218 	return -EOPNOTSUPP;
219 }
220 
221 static inline int
ice_get_vf_cfg(struct net_device __always_unused * netdev,int __always_unused vf_id,struct ifla_vf_info __always_unused * ivi)222 ice_get_vf_cfg(struct net_device __always_unused *netdev,
223 	       int __always_unused vf_id,
224 	       struct ifla_vf_info __always_unused *ivi)
225 {
226 	return -EOPNOTSUPP;
227 }
228 
229 static inline int
ice_set_vf_trust(struct net_device __always_unused * netdev,int __always_unused vf_id,bool __always_unused trusted)230 ice_set_vf_trust(struct net_device __always_unused *netdev,
231 		 int __always_unused vf_id, bool __always_unused trusted)
232 {
233 	return -EOPNOTSUPP;
234 }
235 
236 static inline int
ice_set_vf_port_vlan(struct net_device __always_unused * netdev,int __always_unused vf_id,u16 __always_unused vid,u8 __always_unused qos,__be16 __always_unused v_proto)237 ice_set_vf_port_vlan(struct net_device __always_unused *netdev,
238 		     int __always_unused vf_id, u16 __always_unused vid,
239 		     u8 __always_unused qos, __be16 __always_unused v_proto)
240 {
241 	return -EOPNOTSUPP;
242 }
243 
244 static inline int
ice_set_vf_spoofchk(struct net_device __always_unused * netdev,int __always_unused vf_id,bool __always_unused ena)245 ice_set_vf_spoofchk(struct net_device __always_unused *netdev,
246 		    int __always_unused vf_id, bool __always_unused ena)
247 {
248 	return -EOPNOTSUPP;
249 }
250 
251 static inline int
ice_set_vf_link_state(struct net_device __always_unused * netdev,int __always_unused vf_id,int __always_unused link_state)252 ice_set_vf_link_state(struct net_device __always_unused *netdev,
253 		      int __always_unused vf_id, int __always_unused link_state)
254 {
255 	return -EOPNOTSUPP;
256 }
257 
258 static inline int
ice_calc_vf_reg_idx(struct ice_vf __always_unused * vf,struct ice_q_vector __always_unused * q_vector)259 ice_calc_vf_reg_idx(struct ice_vf __always_unused *vf,
260 		    struct ice_q_vector __always_unused *q_vector)
261 {
262 	return 0;
263 }
264 
265 static inline int
ice_get_vf_stats(struct net_device __always_unused * netdev,int __always_unused vf_id,struct ifla_vf_stats __always_unused * vf_stats)266 ice_get_vf_stats(struct net_device __always_unused *netdev,
267 		 int __always_unused vf_id,
268 		 struct ifla_vf_stats __always_unused *vf_stats)
269 {
270 	return -EOPNOTSUPP;
271 }
272 
ice_is_any_vf_in_promisc(struct ice_pf __always_unused * pf)273 static inline bool ice_is_any_vf_in_promisc(struct ice_pf __always_unused *pf)
274 {
275 	return false;
276 }
277 #endif /* CONFIG_PCI_IOV */
278 #endif /* _ICE_VIRTCHNL_PF_H_ */
279