xref: /linux/drivers/net/ethernet/intel/ice/virt/virtchnl.c (revision 2802bb558e0859a2098d10f407a20f77ce289e4d)
1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (C) 2022, Intel Corporation. */
3 
4 #include "virtchnl.h"
5 #include "queues.h"
6 #include "ice_vf_lib_private.h"
7 #include "ice.h"
8 #include "ice_base.h"
9 #include "ice_lib.h"
10 #include "ice_fltr.h"
11 #include "allowlist.h"
12 #include "ice_vf_vsi_vlan_ops.h"
13 #include "ice_vlan.h"
14 #include "ice_flex_pipe.h"
15 #include "ice_dcb_lib.h"
16 
17 #define FIELD_SELECTOR(proto_hdr_field) \
18 		BIT((proto_hdr_field) & PROTO_HDR_FIELD_MASK)
19 
20 struct ice_vc_hdr_match_type {
21 	u32 vc_hdr;	/* virtchnl headers (VIRTCHNL_PROTO_HDR_XXX) */
22 	u32 ice_hdr;	/* ice headers (ICE_FLOW_SEG_HDR_XXX) */
23 };
24 
25 static const struct ice_vc_hdr_match_type ice_vc_hdr_list[] = {
26 	{VIRTCHNL_PROTO_HDR_NONE,	ICE_FLOW_SEG_HDR_NONE},
27 	{VIRTCHNL_PROTO_HDR_ETH,	ICE_FLOW_SEG_HDR_ETH},
28 	{VIRTCHNL_PROTO_HDR_S_VLAN,	ICE_FLOW_SEG_HDR_VLAN},
29 	{VIRTCHNL_PROTO_HDR_C_VLAN,	ICE_FLOW_SEG_HDR_VLAN},
30 	{VIRTCHNL_PROTO_HDR_IPV4,	ICE_FLOW_SEG_HDR_IPV4 |
31 					ICE_FLOW_SEG_HDR_IPV_OTHER},
32 	{VIRTCHNL_PROTO_HDR_IPV6,	ICE_FLOW_SEG_HDR_IPV6 |
33 					ICE_FLOW_SEG_HDR_IPV_OTHER},
34 	{VIRTCHNL_PROTO_HDR_TCP,	ICE_FLOW_SEG_HDR_TCP},
35 	{VIRTCHNL_PROTO_HDR_UDP,	ICE_FLOW_SEG_HDR_UDP},
36 	{VIRTCHNL_PROTO_HDR_SCTP,	ICE_FLOW_SEG_HDR_SCTP},
37 	{VIRTCHNL_PROTO_HDR_PPPOE,	ICE_FLOW_SEG_HDR_PPPOE},
38 	{VIRTCHNL_PROTO_HDR_GTPU_IP,	ICE_FLOW_SEG_HDR_GTPU_IP},
39 	{VIRTCHNL_PROTO_HDR_GTPU_EH,	ICE_FLOW_SEG_HDR_GTPU_EH},
40 	{VIRTCHNL_PROTO_HDR_GTPU_EH_PDU_DWN,
41 					ICE_FLOW_SEG_HDR_GTPU_DWN},
42 	{VIRTCHNL_PROTO_HDR_GTPU_EH_PDU_UP,
43 					ICE_FLOW_SEG_HDR_GTPU_UP},
44 	{VIRTCHNL_PROTO_HDR_L2TPV3,	ICE_FLOW_SEG_HDR_L2TPV3},
45 	{VIRTCHNL_PROTO_HDR_ESP,	ICE_FLOW_SEG_HDR_ESP},
46 	{VIRTCHNL_PROTO_HDR_AH,		ICE_FLOW_SEG_HDR_AH},
47 	{VIRTCHNL_PROTO_HDR_PFCP,	ICE_FLOW_SEG_HDR_PFCP_SESSION},
48 };
49 
50 struct ice_vc_hash_field_match_type {
51 	u32 vc_hdr;		/* virtchnl headers
52 				 * (VIRTCHNL_PROTO_HDR_XXX)
53 				 */
54 	u32 vc_hash_field;	/* virtchnl hash fields selector
55 				 * FIELD_SELECTOR((VIRTCHNL_PROTO_HDR_ETH_XXX))
56 				 */
57 	u64 ice_hash_field;	/* ice hash fields
58 				 * (BIT_ULL(ICE_FLOW_FIELD_IDX_XXX))
59 				 */
60 };
61 
62 static const struct
63 ice_vc_hash_field_match_type ice_vc_hash_field_list[] = {
64 	{VIRTCHNL_PROTO_HDR_ETH, FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_ETH_SRC),
65 		BIT_ULL(ICE_FLOW_FIELD_IDX_ETH_SA)},
66 	{VIRTCHNL_PROTO_HDR_ETH, FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_ETH_DST),
67 		BIT_ULL(ICE_FLOW_FIELD_IDX_ETH_DA)},
68 	{VIRTCHNL_PROTO_HDR_ETH, FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_ETH_SRC) |
69 		FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_ETH_DST),
70 		ICE_FLOW_HASH_ETH},
71 	{VIRTCHNL_PROTO_HDR_ETH,
72 		FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_ETH_ETHERTYPE),
73 		BIT_ULL(ICE_FLOW_FIELD_IDX_ETH_TYPE)},
74 	{VIRTCHNL_PROTO_HDR_S_VLAN,
75 		FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_S_VLAN_ID),
76 		BIT_ULL(ICE_FLOW_FIELD_IDX_S_VLAN)},
77 	{VIRTCHNL_PROTO_HDR_C_VLAN,
78 		FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_C_VLAN_ID),
79 		BIT_ULL(ICE_FLOW_FIELD_IDX_C_VLAN)},
80 	{VIRTCHNL_PROTO_HDR_IPV4, FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV4_SRC),
81 		BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_SA)},
82 	{VIRTCHNL_PROTO_HDR_IPV4, FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV4_DST),
83 		BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_DA)},
84 	{VIRTCHNL_PROTO_HDR_IPV4, FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV4_SRC) |
85 		FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV4_DST),
86 		ICE_FLOW_HASH_IPV4},
87 	{VIRTCHNL_PROTO_HDR_IPV4, FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV4_SRC) |
88 		FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV4_PROT),
89 		BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_SA) |
90 		BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_PROT)},
91 	{VIRTCHNL_PROTO_HDR_IPV4, FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV4_DST) |
92 		FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV4_PROT),
93 		BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_DA) |
94 		BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_PROT)},
95 	{VIRTCHNL_PROTO_HDR_IPV4, FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV4_SRC) |
96 		FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV4_DST) |
97 		FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV4_PROT),
98 		ICE_FLOW_HASH_IPV4 | BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_PROT)},
99 	{VIRTCHNL_PROTO_HDR_IPV4, FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV4_PROT),
100 		BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_PROT)},
101 	{VIRTCHNL_PROTO_HDR_IPV6, FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV6_SRC),
102 		BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_SA)},
103 	{VIRTCHNL_PROTO_HDR_IPV6, FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV6_DST),
104 		BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_DA)},
105 	{VIRTCHNL_PROTO_HDR_IPV6, FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV6_SRC) |
106 		FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV6_DST),
107 		ICE_FLOW_HASH_IPV6},
108 	{VIRTCHNL_PROTO_HDR_IPV6, FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV6_SRC) |
109 		FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV6_PROT),
110 		BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_SA) |
111 		BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_PROT)},
112 	{VIRTCHNL_PROTO_HDR_IPV6, FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV6_DST) |
113 		FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV6_PROT),
114 		BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_DA) |
115 		BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_PROT)},
116 	{VIRTCHNL_PROTO_HDR_IPV6, FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV6_SRC) |
117 		FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV6_DST) |
118 		FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV6_PROT),
119 		ICE_FLOW_HASH_IPV6 | BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_PROT)},
120 	{VIRTCHNL_PROTO_HDR_IPV6, FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV6_PROT),
121 		BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_PROT)},
122 	{VIRTCHNL_PROTO_HDR_TCP,
123 		FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_TCP_SRC_PORT),
124 		BIT_ULL(ICE_FLOW_FIELD_IDX_TCP_SRC_PORT)},
125 	{VIRTCHNL_PROTO_HDR_TCP,
126 		FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_TCP_DST_PORT),
127 		BIT_ULL(ICE_FLOW_FIELD_IDX_TCP_DST_PORT)},
128 	{VIRTCHNL_PROTO_HDR_TCP,
129 		FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_TCP_SRC_PORT) |
130 		FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_TCP_DST_PORT),
131 		ICE_FLOW_HASH_TCP_PORT},
132 	{VIRTCHNL_PROTO_HDR_UDP,
133 		FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_UDP_SRC_PORT),
134 		BIT_ULL(ICE_FLOW_FIELD_IDX_UDP_SRC_PORT)},
135 	{VIRTCHNL_PROTO_HDR_UDP,
136 		FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_UDP_DST_PORT),
137 		BIT_ULL(ICE_FLOW_FIELD_IDX_UDP_DST_PORT)},
138 	{VIRTCHNL_PROTO_HDR_UDP,
139 		FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_UDP_SRC_PORT) |
140 		FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_UDP_DST_PORT),
141 		ICE_FLOW_HASH_UDP_PORT},
142 	{VIRTCHNL_PROTO_HDR_SCTP,
143 		FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_SCTP_SRC_PORT),
144 		BIT_ULL(ICE_FLOW_FIELD_IDX_SCTP_SRC_PORT)},
145 	{VIRTCHNL_PROTO_HDR_SCTP,
146 		FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_SCTP_DST_PORT),
147 		BIT_ULL(ICE_FLOW_FIELD_IDX_SCTP_DST_PORT)},
148 	{VIRTCHNL_PROTO_HDR_SCTP,
149 		FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_SCTP_SRC_PORT) |
150 		FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_SCTP_DST_PORT),
151 		ICE_FLOW_HASH_SCTP_PORT},
152 	{VIRTCHNL_PROTO_HDR_PPPOE,
153 		FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_PPPOE_SESS_ID),
154 		BIT_ULL(ICE_FLOW_FIELD_IDX_PPPOE_SESS_ID)},
155 	{VIRTCHNL_PROTO_HDR_GTPU_IP,
156 		FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_GTPU_IP_TEID),
157 		BIT_ULL(ICE_FLOW_FIELD_IDX_GTPU_IP_TEID)},
158 	{VIRTCHNL_PROTO_HDR_L2TPV3,
159 		FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_L2TPV3_SESS_ID),
160 		BIT_ULL(ICE_FLOW_FIELD_IDX_L2TPV3_SESS_ID)},
161 	{VIRTCHNL_PROTO_HDR_ESP, FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_ESP_SPI),
162 		BIT_ULL(ICE_FLOW_FIELD_IDX_ESP_SPI)},
163 	{VIRTCHNL_PROTO_HDR_AH, FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_AH_SPI),
164 		BIT_ULL(ICE_FLOW_FIELD_IDX_AH_SPI)},
165 	{VIRTCHNL_PROTO_HDR_PFCP, FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_PFCP_SEID),
166 		BIT_ULL(ICE_FLOW_FIELD_IDX_PFCP_SEID)},
167 };
168 
169 /**
170  * ice_vc_vf_broadcast - Broadcast a message to all VFs on PF
171  * @pf: pointer to the PF structure
172  * @v_opcode: operation code
173  * @v_retval: return value
174  * @msg: pointer to the msg buffer
175  * @msglen: msg length
176  */
177 static void
178 ice_vc_vf_broadcast(struct ice_pf *pf, enum virtchnl_ops v_opcode,
179 		    enum virtchnl_status_code v_retval, u8 *msg, u16 msglen)
180 {
181 	struct ice_hw *hw = &pf->hw;
182 	struct ice_vf *vf;
183 	unsigned int bkt;
184 
185 	mutex_lock(&pf->vfs.table_lock);
186 	ice_for_each_vf(pf, bkt, vf) {
187 		/* Not all vfs are enabled so skip the ones that are not */
188 		if (!test_bit(ICE_VF_STATE_INIT, vf->vf_states) &&
189 		    !test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states))
190 			continue;
191 
192 		/* Ignore return value on purpose - a given VF may fail, but
193 		 * we need to keep going and send to all of them
194 		 */
195 		ice_aq_send_msg_to_vf(hw, vf->vf_id, v_opcode, v_retval, msg,
196 				      msglen, NULL);
197 	}
198 	mutex_unlock(&pf->vfs.table_lock);
199 }
200 
201 /**
202  * ice_set_pfe_link - Set the link speed/status of the virtchnl_pf_event
203  * @vf: pointer to the VF structure
204  * @pfe: pointer to the virtchnl_pf_event to set link speed/status for
205  * @ice_link_speed: link speed specified by ICE_AQ_LINK_SPEED_*
206  * @link_up: whether or not to set the link up/down
207  */
208 static void
209 ice_set_pfe_link(struct ice_vf *vf, struct virtchnl_pf_event *pfe,
210 		 int ice_link_speed, bool link_up)
211 {
212 	if (vf->driver_caps & VIRTCHNL_VF_CAP_ADV_LINK_SPEED) {
213 		pfe->event_data.link_event_adv.link_status = link_up;
214 		/* Speed in Mbps */
215 		pfe->event_data.link_event_adv.link_speed =
216 			ice_conv_link_speed_to_virtchnl(true, ice_link_speed);
217 	} else {
218 		pfe->event_data.link_event.link_status = link_up;
219 		/* Legacy method for virtchnl link speeds */
220 		pfe->event_data.link_event.link_speed =
221 			(enum virtchnl_link_speed)
222 			ice_conv_link_speed_to_virtchnl(false, ice_link_speed);
223 	}
224 }
225 
226 /**
227  * ice_vc_notify_vf_link_state - Inform a VF of link status
228  * @vf: pointer to the VF structure
229  *
230  * send a link status message to a single VF
231  */
232 void ice_vc_notify_vf_link_state(struct ice_vf *vf)
233 {
234 	struct virtchnl_pf_event pfe = { 0 };
235 	struct ice_hw *hw = &vf->pf->hw;
236 
237 	pfe.event = VIRTCHNL_EVENT_LINK_CHANGE;
238 	pfe.severity = PF_EVENT_SEVERITY_INFO;
239 
240 	if (ice_is_vf_link_up(vf))
241 		ice_set_pfe_link(vf, &pfe,
242 				 hw->port_info->phy.link_info.link_speed, true);
243 	else
244 		ice_set_pfe_link(vf, &pfe, ICE_AQ_LINK_SPEED_UNKNOWN, false);
245 
246 	ice_aq_send_msg_to_vf(hw, vf->vf_id, VIRTCHNL_OP_EVENT,
247 			      VIRTCHNL_STATUS_SUCCESS, (u8 *)&pfe,
248 			      sizeof(pfe), NULL);
249 }
250 
251 /**
252  * ice_vc_notify_link_state - Inform all VFs on a PF of link status
253  * @pf: pointer to the PF structure
254  */
255 void ice_vc_notify_link_state(struct ice_pf *pf)
256 {
257 	struct ice_vf *vf;
258 	unsigned int bkt;
259 
260 	mutex_lock(&pf->vfs.table_lock);
261 	ice_for_each_vf(pf, bkt, vf)
262 		ice_vc_notify_vf_link_state(vf);
263 	mutex_unlock(&pf->vfs.table_lock);
264 }
265 
266 /**
267  * ice_vc_notify_reset - Send pending reset message to all VFs
268  * @pf: pointer to the PF structure
269  *
270  * indicate a pending reset to all VFs on a given PF
271  */
272 void ice_vc_notify_reset(struct ice_pf *pf)
273 {
274 	struct virtchnl_pf_event pfe;
275 
276 	if (!ice_has_vfs(pf))
277 		return;
278 
279 	pfe.event = VIRTCHNL_EVENT_RESET_IMPENDING;
280 	pfe.severity = PF_EVENT_SEVERITY_CERTAIN_DOOM;
281 	ice_vc_vf_broadcast(pf, VIRTCHNL_OP_EVENT, VIRTCHNL_STATUS_SUCCESS,
282 			    (u8 *)&pfe, sizeof(struct virtchnl_pf_event));
283 }
284 
285 /**
286  * ice_vc_send_msg_to_vf - Send message to VF
287  * @vf: pointer to the VF info
288  * @v_opcode: virtual channel opcode
289  * @v_retval: virtual channel return value
290  * @msg: pointer to the msg buffer
291  * @msglen: msg length
292  *
293  * send msg to VF
294  */
295 int
296 ice_vc_send_msg_to_vf(struct ice_vf *vf, u32 v_opcode,
297 		      enum virtchnl_status_code v_retval, u8 *msg, u16 msglen)
298 {
299 	struct device *dev;
300 	struct ice_pf *pf;
301 	int aq_ret;
302 
303 	pf = vf->pf;
304 	dev = ice_pf_to_dev(pf);
305 
306 	aq_ret = ice_aq_send_msg_to_vf(&pf->hw, vf->vf_id, v_opcode, v_retval,
307 				       msg, msglen, NULL);
308 	if (aq_ret && pf->hw.mailboxq.sq_last_status != LIBIE_AQ_RC_ENOSYS) {
309 		dev_info(dev, "Unable to send the message to VF %d ret %d aq_err %s\n",
310 			 vf->vf_id, aq_ret,
311 			 libie_aq_str(pf->hw.mailboxq.sq_last_status));
312 		return -EIO;
313 	}
314 
315 	return 0;
316 }
317 
318 /**
319  * ice_vc_get_ver_msg
320  * @vf: pointer to the VF info
321  * @msg: pointer to the msg buffer
322  *
323  * called from the VF to request the API version used by the PF
324  */
325 static int ice_vc_get_ver_msg(struct ice_vf *vf, u8 *msg)
326 {
327 	struct virtchnl_version_info info = {
328 		VIRTCHNL_VERSION_MAJOR, VIRTCHNL_VERSION_MINOR
329 	};
330 
331 	vf->vf_ver = *(struct virtchnl_version_info *)msg;
332 	/* VFs running the 1.0 API expect to get 1.0 back or they will cry. */
333 	if (VF_IS_V10(&vf->vf_ver))
334 		info.minor = VIRTCHNL_VERSION_MINOR_NO_VF_CAPS;
335 
336 	return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_VERSION,
337 				     VIRTCHNL_STATUS_SUCCESS, (u8 *)&info,
338 				     sizeof(struct virtchnl_version_info));
339 }
340 
341 /**
342  * ice_vc_get_vlan_caps
343  * @hw: pointer to the hw
344  * @vf: pointer to the VF info
345  * @vsi: pointer to the VSI
346  * @driver_caps: current driver caps
347  *
348  * Return 0 if there is no VLAN caps supported, or VLAN caps value
349  */
350 static u32
351 ice_vc_get_vlan_caps(struct ice_hw *hw, struct ice_vf *vf, struct ice_vsi *vsi,
352 		     u32 driver_caps)
353 {
354 	if (ice_is_eswitch_mode_switchdev(vf->pf))
355 		/* In switchdev setting VLAN from VF isn't supported */
356 		return 0;
357 
358 	if (driver_caps & VIRTCHNL_VF_OFFLOAD_VLAN_V2) {
359 		/* VLAN offloads based on current device configuration */
360 		return VIRTCHNL_VF_OFFLOAD_VLAN_V2;
361 	} else if (driver_caps & VIRTCHNL_VF_OFFLOAD_VLAN) {
362 		/* allow VF to negotiate VIRTCHNL_VF_OFFLOAD explicitly for
363 		 * these two conditions, which amounts to guest VLAN filtering
364 		 * and offloads being based on the inner VLAN or the
365 		 * inner/single VLAN respectively and don't allow VF to
366 		 * negotiate VIRTCHNL_VF_OFFLOAD in any other cases
367 		 */
368 		if (ice_is_dvm_ena(hw) && ice_vf_is_port_vlan_ena(vf)) {
369 			return VIRTCHNL_VF_OFFLOAD_VLAN;
370 		} else if (!ice_is_dvm_ena(hw) &&
371 			   !ice_vf_is_port_vlan_ena(vf)) {
372 			/* configure backward compatible support for VFs that
373 			 * only support VIRTCHNL_VF_OFFLOAD_VLAN, the PF is
374 			 * configured in SVM, and no port VLAN is configured
375 			 */
376 			ice_vf_vsi_cfg_svm_legacy_vlan_mode(vsi);
377 			return VIRTCHNL_VF_OFFLOAD_VLAN;
378 		} else if (ice_is_dvm_ena(hw)) {
379 			/* configure software offloaded VLAN support when DVM
380 			 * is enabled, but no port VLAN is enabled
381 			 */
382 			ice_vf_vsi_cfg_dvm_legacy_vlan_mode(vsi);
383 		}
384 	}
385 
386 	return 0;
387 }
388 
389 /**
390  * ice_vc_get_vf_res_msg
391  * @vf: pointer to the VF info
392  * @msg: pointer to the msg buffer
393  *
394  * called from the VF to request its resources
395  */
396 static int ice_vc_get_vf_res_msg(struct ice_vf *vf, u8 *msg)
397 {
398 	enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
399 	struct virtchnl_vf_resource *vfres = NULL;
400 	struct ice_hw *hw = &vf->pf->hw;
401 	struct ice_vsi *vsi;
402 	int len = 0;
403 	int ret;
404 
405 	if (ice_check_vf_init(vf)) {
406 		v_ret = VIRTCHNL_STATUS_ERR_PARAM;
407 		goto err;
408 	}
409 
410 	len = virtchnl_struct_size(vfres, vsi_res, 0);
411 
412 	vfres = kzalloc(len, GFP_KERNEL);
413 	if (!vfres) {
414 		v_ret = VIRTCHNL_STATUS_ERR_NO_MEMORY;
415 		len = 0;
416 		goto err;
417 	}
418 	if (VF_IS_V11(&vf->vf_ver))
419 		vf->driver_caps = *(u32 *)msg;
420 	else
421 		vf->driver_caps = VIRTCHNL_VF_OFFLOAD_L2 |
422 				  VIRTCHNL_VF_OFFLOAD_VLAN;
423 
424 	vfres->vf_cap_flags = VIRTCHNL_VF_OFFLOAD_L2;
425 	vsi = ice_get_vf_vsi(vf);
426 	if (!vsi) {
427 		v_ret = VIRTCHNL_STATUS_ERR_PARAM;
428 		goto err;
429 	}
430 
431 	vfres->vf_cap_flags |= ice_vc_get_vlan_caps(hw, vf, vsi,
432 						    vf->driver_caps);
433 
434 	if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_RSS_PF)
435 		vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_RSS_PF;
436 
437 	if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_RX_FLEX_DESC)
438 		vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_RX_FLEX_DESC;
439 
440 	if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_FDIR_PF)
441 		vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_FDIR_PF;
442 
443 	if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_TC_U32 &&
444 	    vfres->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_FDIR_PF)
445 		vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_TC_U32;
446 
447 	if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_RSS_PCTYPE_V2)
448 		vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_RSS_PCTYPE_V2;
449 
450 	if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_ENCAP)
451 		vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_ENCAP;
452 
453 	if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_ENCAP_CSUM)
454 		vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_ENCAP_CSUM;
455 
456 	if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_RX_POLLING)
457 		vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_RX_POLLING;
458 
459 	if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_WB_ON_ITR)
460 		vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_WB_ON_ITR;
461 
462 	if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_REQ_QUEUES)
463 		vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_REQ_QUEUES;
464 
465 	if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_CRC)
466 		vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_CRC;
467 
468 	if (vf->driver_caps & VIRTCHNL_VF_CAP_ADV_LINK_SPEED)
469 		vfres->vf_cap_flags |= VIRTCHNL_VF_CAP_ADV_LINK_SPEED;
470 
471 	if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_ADV_RSS_PF)
472 		vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_ADV_RSS_PF;
473 
474 	if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_USO)
475 		vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_USO;
476 
477 	if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_QOS)
478 		vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_QOS;
479 
480 	if (vf->driver_caps & VIRTCHNL_VF_CAP_PTP)
481 		vfres->vf_cap_flags |= VIRTCHNL_VF_CAP_PTP;
482 
483 	vfres->num_vsis = 1;
484 	/* Tx and Rx queue are equal for VF */
485 	vfres->num_queue_pairs = vsi->num_txq;
486 	vfres->max_vectors = vf->num_msix;
487 	vfres->rss_key_size = ICE_VSIQF_HKEY_ARRAY_SIZE;
488 	vfres->rss_lut_size = ICE_LUT_VSI_SIZE;
489 	vfres->max_mtu = ice_vc_get_max_frame_size(vf);
490 
491 	vfres->vsi_res[0].vsi_id = ICE_VF_VSI_ID;
492 	vfres->vsi_res[0].vsi_type = VIRTCHNL_VSI_SRIOV;
493 	vfres->vsi_res[0].num_queue_pairs = vsi->num_txq;
494 	ether_addr_copy(vfres->vsi_res[0].default_mac_addr,
495 			vf->hw_lan_addr);
496 
497 	/* match guest capabilities */
498 	vf->driver_caps = vfres->vf_cap_flags;
499 
500 	ice_vc_set_caps_allowlist(vf);
501 	ice_vc_set_working_allowlist(vf);
502 
503 	set_bit(ICE_VF_STATE_ACTIVE, vf->vf_states);
504 
505 err:
506 	/* send the response back to the VF */
507 	ret = ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_GET_VF_RESOURCES, v_ret,
508 				    (u8 *)vfres, len);
509 
510 	kfree(vfres);
511 	return ret;
512 }
513 
514 /**
515  * ice_vc_reset_vf_msg
516  * @vf: pointer to the VF info
517  *
518  * called from the VF to reset itself,
519  * unlike other virtchnl messages, PF driver
520  * doesn't send the response back to the VF
521  */
522 static void ice_vc_reset_vf_msg(struct ice_vf *vf)
523 {
524 	if (test_bit(ICE_VF_STATE_INIT, vf->vf_states))
525 		ice_reset_vf(vf, 0);
526 }
527 
528 /**
529  * ice_vc_isvalid_vsi_id
530  * @vf: pointer to the VF info
531  * @vsi_id: VF relative VSI ID
532  *
533  * check for the valid VSI ID
534  */
535 bool ice_vc_isvalid_vsi_id(struct ice_vf *vf, u16 vsi_id)
536 {
537 	return vsi_id == ICE_VF_VSI_ID;
538 }
539 
540 /**
541  * ice_vc_validate_pattern
542  * @vf: pointer to the VF info
543  * @proto: virtchnl protocol headers
544  *
545  * validate the pattern is supported or not.
546  *
547  * Return: true on success, false on error.
548  */
549 bool
550 ice_vc_validate_pattern(struct ice_vf *vf, struct virtchnl_proto_hdrs *proto)
551 {
552 	bool is_ipv4 = false;
553 	bool is_ipv6 = false;
554 	bool is_udp = false;
555 	u16 ptype = -1;
556 	int i = 0;
557 
558 	while (i < proto->count &&
559 	       proto->proto_hdr[i].type != VIRTCHNL_PROTO_HDR_NONE) {
560 		switch (proto->proto_hdr[i].type) {
561 		case VIRTCHNL_PROTO_HDR_ETH:
562 			ptype = ICE_PTYPE_MAC_PAY;
563 			break;
564 		case VIRTCHNL_PROTO_HDR_IPV4:
565 			ptype = ICE_PTYPE_IPV4_PAY;
566 			is_ipv4 = true;
567 			break;
568 		case VIRTCHNL_PROTO_HDR_IPV6:
569 			ptype = ICE_PTYPE_IPV6_PAY;
570 			is_ipv6 = true;
571 			break;
572 		case VIRTCHNL_PROTO_HDR_UDP:
573 			if (is_ipv4)
574 				ptype = ICE_PTYPE_IPV4_UDP_PAY;
575 			else if (is_ipv6)
576 				ptype = ICE_PTYPE_IPV6_UDP_PAY;
577 			is_udp = true;
578 			break;
579 		case VIRTCHNL_PROTO_HDR_TCP:
580 			if (is_ipv4)
581 				ptype = ICE_PTYPE_IPV4_TCP_PAY;
582 			else if (is_ipv6)
583 				ptype = ICE_PTYPE_IPV6_TCP_PAY;
584 			break;
585 		case VIRTCHNL_PROTO_HDR_SCTP:
586 			if (is_ipv4)
587 				ptype = ICE_PTYPE_IPV4_SCTP_PAY;
588 			else if (is_ipv6)
589 				ptype = ICE_PTYPE_IPV6_SCTP_PAY;
590 			break;
591 		case VIRTCHNL_PROTO_HDR_GTPU_IP:
592 		case VIRTCHNL_PROTO_HDR_GTPU_EH:
593 			if (is_ipv4)
594 				ptype = ICE_MAC_IPV4_GTPU;
595 			else if (is_ipv6)
596 				ptype = ICE_MAC_IPV6_GTPU;
597 			goto out;
598 		case VIRTCHNL_PROTO_HDR_L2TPV3:
599 			if (is_ipv4)
600 				ptype = ICE_MAC_IPV4_L2TPV3;
601 			else if (is_ipv6)
602 				ptype = ICE_MAC_IPV6_L2TPV3;
603 			goto out;
604 		case VIRTCHNL_PROTO_HDR_ESP:
605 			if (is_ipv4)
606 				ptype = is_udp ? ICE_MAC_IPV4_NAT_T_ESP :
607 						ICE_MAC_IPV4_ESP;
608 			else if (is_ipv6)
609 				ptype = is_udp ? ICE_MAC_IPV6_NAT_T_ESP :
610 						ICE_MAC_IPV6_ESP;
611 			goto out;
612 		case VIRTCHNL_PROTO_HDR_AH:
613 			if (is_ipv4)
614 				ptype = ICE_MAC_IPV4_AH;
615 			else if (is_ipv6)
616 				ptype = ICE_MAC_IPV6_AH;
617 			goto out;
618 		case VIRTCHNL_PROTO_HDR_PFCP:
619 			if (is_ipv4)
620 				ptype = ICE_MAC_IPV4_PFCP_SESSION;
621 			else if (is_ipv6)
622 				ptype = ICE_MAC_IPV6_PFCP_SESSION;
623 			goto out;
624 		default:
625 			break;
626 		}
627 		i++;
628 	}
629 
630 out:
631 	return ice_hw_ptype_ena(&vf->pf->hw, ptype);
632 }
633 
634 /**
635  * ice_vc_parse_rss_cfg - parses hash fields and headers from
636  * a specific virtchnl RSS cfg
637  * @hw: pointer to the hardware
638  * @rss_cfg: pointer to the virtchnl RSS cfg
639  * @hash_cfg: pointer to the HW hash configuration
640  *
641  * Return true if all the protocol header and hash fields in the RSS cfg could
642  * be parsed, else return false
643  *
644  * This function parses the virtchnl RSS cfg to be the intended
645  * hash fields and the intended header for RSS configuration
646  */
647 static bool ice_vc_parse_rss_cfg(struct ice_hw *hw,
648 				 struct virtchnl_rss_cfg *rss_cfg,
649 				 struct ice_rss_hash_cfg *hash_cfg)
650 {
651 	const struct ice_vc_hash_field_match_type *hf_list;
652 	const struct ice_vc_hdr_match_type *hdr_list;
653 	int i, hf_list_len, hdr_list_len;
654 	u32 *addl_hdrs = &hash_cfg->addl_hdrs;
655 	u64 *hash_flds = &hash_cfg->hash_flds;
656 
657 	/* set outer layer RSS as default */
658 	hash_cfg->hdr_type = ICE_RSS_OUTER_HEADERS;
659 
660 	if (rss_cfg->rss_algorithm == VIRTCHNL_RSS_ALG_TOEPLITZ_SYMMETRIC)
661 		hash_cfg->symm = true;
662 	else
663 		hash_cfg->symm = false;
664 
665 	hf_list = ice_vc_hash_field_list;
666 	hf_list_len = ARRAY_SIZE(ice_vc_hash_field_list);
667 	hdr_list = ice_vc_hdr_list;
668 	hdr_list_len = ARRAY_SIZE(ice_vc_hdr_list);
669 
670 	for (i = 0; i < rss_cfg->proto_hdrs.count; i++) {
671 		struct virtchnl_proto_hdr *proto_hdr =
672 					&rss_cfg->proto_hdrs.proto_hdr[i];
673 		bool hdr_found = false;
674 		int j;
675 
676 		/* Find matched ice headers according to virtchnl headers. */
677 		for (j = 0; j < hdr_list_len; j++) {
678 			struct ice_vc_hdr_match_type hdr_map = hdr_list[j];
679 
680 			if (proto_hdr->type == hdr_map.vc_hdr) {
681 				*addl_hdrs |= hdr_map.ice_hdr;
682 				hdr_found = true;
683 			}
684 		}
685 
686 		if (!hdr_found)
687 			return false;
688 
689 		/* Find matched ice hash fields according to
690 		 * virtchnl hash fields.
691 		 */
692 		for (j = 0; j < hf_list_len; j++) {
693 			struct ice_vc_hash_field_match_type hf_map = hf_list[j];
694 
695 			if (proto_hdr->type == hf_map.vc_hdr &&
696 			    proto_hdr->field_selector == hf_map.vc_hash_field) {
697 				*hash_flds |= hf_map.ice_hash_field;
698 				break;
699 			}
700 		}
701 	}
702 
703 	return true;
704 }
705 
706 /**
707  * ice_vf_adv_rss_offload_ena - determine if capabilities support advanced
708  * RSS offloads
709  * @caps: VF driver negotiated capabilities
710  *
711  * Return true if VIRTCHNL_VF_OFFLOAD_ADV_RSS_PF capability is set,
712  * else return false
713  */
714 static bool ice_vf_adv_rss_offload_ena(u32 caps)
715 {
716 	return !!(caps & VIRTCHNL_VF_OFFLOAD_ADV_RSS_PF);
717 }
718 
719 /**
720  * ice_vc_handle_rss_cfg
721  * @vf: pointer to the VF info
722  * @msg: pointer to the message buffer
723  * @add: add a RSS config if true, otherwise delete a RSS config
724  *
725  * This function adds/deletes a RSS config
726  */
727 static int ice_vc_handle_rss_cfg(struct ice_vf *vf, u8 *msg, bool add)
728 {
729 	u32 v_opcode = add ? VIRTCHNL_OP_ADD_RSS_CFG : VIRTCHNL_OP_DEL_RSS_CFG;
730 	struct virtchnl_rss_cfg *rss_cfg = (struct virtchnl_rss_cfg *)msg;
731 	enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
732 	struct device *dev = ice_pf_to_dev(vf->pf);
733 	struct ice_hw *hw = &vf->pf->hw;
734 	struct ice_vsi *vsi;
735 
736 	if (!test_bit(ICE_FLAG_RSS_ENA, vf->pf->flags)) {
737 		dev_dbg(dev, "VF %d attempting to configure RSS, but RSS is not supported by the PF\n",
738 			vf->vf_id);
739 		v_ret = VIRTCHNL_STATUS_ERR_NOT_SUPPORTED;
740 		goto error_param;
741 	}
742 
743 	if (!ice_vf_adv_rss_offload_ena(vf->driver_caps)) {
744 		dev_dbg(dev, "VF %d attempting to configure RSS, but Advanced RSS offload is not supported\n",
745 			vf->vf_id);
746 		v_ret = VIRTCHNL_STATUS_ERR_PARAM;
747 		goto error_param;
748 	}
749 
750 	if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
751 		v_ret = VIRTCHNL_STATUS_ERR_PARAM;
752 		goto error_param;
753 	}
754 
755 	if (rss_cfg->proto_hdrs.count > VIRTCHNL_MAX_NUM_PROTO_HDRS ||
756 	    rss_cfg->rss_algorithm < VIRTCHNL_RSS_ALG_TOEPLITZ_ASYMMETRIC ||
757 	    rss_cfg->rss_algorithm > VIRTCHNL_RSS_ALG_XOR_SYMMETRIC) {
758 		dev_dbg(dev, "VF %d attempting to configure RSS, but RSS configuration is not valid\n",
759 			vf->vf_id);
760 		v_ret = VIRTCHNL_STATUS_ERR_PARAM;
761 		goto error_param;
762 	}
763 
764 	vsi = ice_get_vf_vsi(vf);
765 	if (!vsi) {
766 		v_ret = VIRTCHNL_STATUS_ERR_PARAM;
767 		goto error_param;
768 	}
769 
770 	if (!ice_vc_validate_pattern(vf, &rss_cfg->proto_hdrs)) {
771 		v_ret = VIRTCHNL_STATUS_ERR_PARAM;
772 		goto error_param;
773 	}
774 
775 	if (rss_cfg->rss_algorithm == VIRTCHNL_RSS_ALG_R_ASYMMETRIC) {
776 		struct ice_vsi_ctx *ctx;
777 		u8 lut_type, hash_type;
778 		int status;
779 
780 		lut_type = ICE_AQ_VSI_Q_OPT_RSS_LUT_VSI;
781 		hash_type = add ? ICE_AQ_VSI_Q_OPT_RSS_HASH_XOR :
782 				ICE_AQ_VSI_Q_OPT_RSS_HASH_TPLZ;
783 
784 		ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
785 		if (!ctx) {
786 			v_ret = VIRTCHNL_STATUS_ERR_NO_MEMORY;
787 			goto error_param;
788 		}
789 
790 		ctx->info.q_opt_rss =
791 			FIELD_PREP(ICE_AQ_VSI_Q_OPT_RSS_LUT_M, lut_type) |
792 			FIELD_PREP(ICE_AQ_VSI_Q_OPT_RSS_HASH_M, hash_type);
793 
794 		/* Preserve existing queueing option setting */
795 		ctx->info.q_opt_rss |= (vsi->info.q_opt_rss &
796 					  ICE_AQ_VSI_Q_OPT_RSS_GBL_LUT_M);
797 		ctx->info.q_opt_tc = vsi->info.q_opt_tc;
798 		ctx->info.q_opt_flags = vsi->info.q_opt_rss;
799 
800 		ctx->info.valid_sections =
801 				cpu_to_le16(ICE_AQ_VSI_PROP_Q_OPT_VALID);
802 
803 		status = ice_update_vsi(hw, vsi->idx, ctx, NULL);
804 		if (status) {
805 			dev_err(dev, "update VSI for RSS failed, err %d aq_err %s\n",
806 				status, libie_aq_str(hw->adminq.sq_last_status));
807 			v_ret = VIRTCHNL_STATUS_ERR_PARAM;
808 		} else {
809 			vsi->info.q_opt_rss = ctx->info.q_opt_rss;
810 		}
811 
812 		kfree(ctx);
813 	} else {
814 		struct ice_rss_hash_cfg cfg;
815 
816 		/* Only check for none raw pattern case */
817 		if (!ice_vc_validate_pattern(vf, &rss_cfg->proto_hdrs)) {
818 			v_ret = VIRTCHNL_STATUS_ERR_PARAM;
819 			goto error_param;
820 		}
821 		cfg.addl_hdrs = ICE_FLOW_SEG_HDR_NONE;
822 		cfg.hash_flds = ICE_HASH_INVALID;
823 		cfg.hdr_type = ICE_RSS_ANY_HEADERS;
824 
825 		if (!ice_vc_parse_rss_cfg(hw, rss_cfg, &cfg)) {
826 			v_ret = VIRTCHNL_STATUS_ERR_PARAM;
827 			goto error_param;
828 		}
829 
830 		if (add) {
831 			if (ice_add_rss_cfg(hw, vsi, &cfg)) {
832 				v_ret = VIRTCHNL_STATUS_ERR_PARAM;
833 				dev_err(dev, "ice_add_rss_cfg failed for vsi = %d, v_ret = %d\n",
834 					vsi->vsi_num, v_ret);
835 			}
836 		} else {
837 			int status;
838 
839 			status = ice_rem_rss_cfg(hw, vsi->idx, &cfg);
840 			/* We just ignore -ENOENT, because if two configurations
841 			 * share the same profile remove one of them actually
842 			 * removes both, since the profile is deleted.
843 			 */
844 			if (status && status != -ENOENT) {
845 				v_ret = VIRTCHNL_STATUS_ERR_PARAM;
846 				dev_err(dev, "ice_rem_rss_cfg failed for VF ID:%d, error:%d\n",
847 					vf->vf_id, status);
848 			}
849 		}
850 	}
851 
852 error_param:
853 	return ice_vc_send_msg_to_vf(vf, v_opcode, v_ret, NULL, 0);
854 }
855 
856 /**
857  * ice_vc_config_rss_key
858  * @vf: pointer to the VF info
859  * @msg: pointer to the msg buffer
860  *
861  * Configure the VF's RSS key
862  */
863 static int ice_vc_config_rss_key(struct ice_vf *vf, u8 *msg)
864 {
865 	enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
866 	struct virtchnl_rss_key *vrk =
867 		(struct virtchnl_rss_key *)msg;
868 	struct ice_vsi *vsi;
869 
870 	if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
871 		v_ret = VIRTCHNL_STATUS_ERR_PARAM;
872 		goto error_param;
873 	}
874 
875 	if (!ice_vc_isvalid_vsi_id(vf, vrk->vsi_id)) {
876 		v_ret = VIRTCHNL_STATUS_ERR_PARAM;
877 		goto error_param;
878 	}
879 
880 	if (vrk->key_len != ICE_VSIQF_HKEY_ARRAY_SIZE) {
881 		v_ret = VIRTCHNL_STATUS_ERR_PARAM;
882 		goto error_param;
883 	}
884 
885 	if (!test_bit(ICE_FLAG_RSS_ENA, vf->pf->flags)) {
886 		v_ret = VIRTCHNL_STATUS_ERR_PARAM;
887 		goto error_param;
888 	}
889 
890 	vsi = ice_get_vf_vsi(vf);
891 	if (!vsi) {
892 		v_ret = VIRTCHNL_STATUS_ERR_PARAM;
893 		goto error_param;
894 	}
895 
896 	if (ice_set_rss_key(vsi, vrk->key))
897 		v_ret = VIRTCHNL_STATUS_ERR_ADMIN_QUEUE_ERROR;
898 error_param:
899 	return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_CONFIG_RSS_KEY, v_ret,
900 				     NULL, 0);
901 }
902 
903 /**
904  * ice_vc_config_rss_lut
905  * @vf: pointer to the VF info
906  * @msg: pointer to the msg buffer
907  *
908  * Configure the VF's RSS LUT
909  */
910 static int ice_vc_config_rss_lut(struct ice_vf *vf, u8 *msg)
911 {
912 	struct virtchnl_rss_lut *vrl = (struct virtchnl_rss_lut *)msg;
913 	enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
914 	struct ice_vsi *vsi;
915 
916 	if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
917 		v_ret = VIRTCHNL_STATUS_ERR_PARAM;
918 		goto error_param;
919 	}
920 
921 	if (!ice_vc_isvalid_vsi_id(vf, vrl->vsi_id)) {
922 		v_ret = VIRTCHNL_STATUS_ERR_PARAM;
923 		goto error_param;
924 	}
925 
926 	if (vrl->lut_entries != ICE_LUT_VSI_SIZE) {
927 		v_ret = VIRTCHNL_STATUS_ERR_PARAM;
928 		goto error_param;
929 	}
930 
931 	if (!test_bit(ICE_FLAG_RSS_ENA, vf->pf->flags)) {
932 		v_ret = VIRTCHNL_STATUS_ERR_PARAM;
933 		goto error_param;
934 	}
935 
936 	vsi = ice_get_vf_vsi(vf);
937 	if (!vsi) {
938 		v_ret = VIRTCHNL_STATUS_ERR_PARAM;
939 		goto error_param;
940 	}
941 
942 	if (ice_set_rss_lut(vsi, vrl->lut, ICE_LUT_VSI_SIZE))
943 		v_ret = VIRTCHNL_STATUS_ERR_ADMIN_QUEUE_ERROR;
944 error_param:
945 	return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_CONFIG_RSS_LUT, v_ret,
946 				     NULL, 0);
947 }
948 
949 /**
950  * ice_vc_config_rss_hfunc
951  * @vf: pointer to the VF info
952  * @msg: pointer to the msg buffer
953  *
954  * Configure the VF's RSS Hash function
955  */
956 static int ice_vc_config_rss_hfunc(struct ice_vf *vf, u8 *msg)
957 {
958 	struct virtchnl_rss_hfunc *vrh = (struct virtchnl_rss_hfunc *)msg;
959 	enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
960 	u8 hfunc = ICE_AQ_VSI_Q_OPT_RSS_HASH_TPLZ;
961 	struct ice_vsi *vsi;
962 
963 	if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
964 		v_ret = VIRTCHNL_STATUS_ERR_PARAM;
965 		goto error_param;
966 	}
967 
968 	if (!ice_vc_isvalid_vsi_id(vf, vrh->vsi_id)) {
969 		v_ret = VIRTCHNL_STATUS_ERR_PARAM;
970 		goto error_param;
971 	}
972 
973 	if (!test_bit(ICE_FLAG_RSS_ENA, vf->pf->flags)) {
974 		v_ret = VIRTCHNL_STATUS_ERR_PARAM;
975 		goto error_param;
976 	}
977 
978 	vsi = ice_get_vf_vsi(vf);
979 	if (!vsi) {
980 		v_ret = VIRTCHNL_STATUS_ERR_PARAM;
981 		goto error_param;
982 	}
983 
984 	if (vrh->rss_algorithm == VIRTCHNL_RSS_ALG_TOEPLITZ_SYMMETRIC)
985 		hfunc = ICE_AQ_VSI_Q_OPT_RSS_HASH_SYM_TPLZ;
986 
987 	if (ice_set_rss_hfunc(vsi, hfunc))
988 		v_ret = VIRTCHNL_STATUS_ERR_ADMIN_QUEUE_ERROR;
989 error_param:
990 	return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_CONFIG_RSS_HFUNC, v_ret,
991 				     NULL, 0);
992 }
993 
994 /**
995  * ice_vc_get_qos_caps - Get current QoS caps from PF
996  * @vf: pointer to the VF info
997  *
998  * Get VF's QoS capabilities, such as TC number, arbiter and
999  * bandwidth from PF.
1000  *
1001  * Return: 0 on success or negative error value.
1002  */
1003 static int ice_vc_get_qos_caps(struct ice_vf *vf)
1004 {
1005 	enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
1006 	struct virtchnl_qos_cap_list *cap_list = NULL;
1007 	u8 tc_prio[ICE_MAX_TRAFFIC_CLASS] = { 0 };
1008 	struct virtchnl_qos_cap_elem *cfg = NULL;
1009 	struct ice_vsi_ctx *vsi_ctx;
1010 	struct ice_pf *pf = vf->pf;
1011 	struct ice_port_info *pi;
1012 	struct ice_vsi *vsi;
1013 	u8 numtc, tc;
1014 	u16 len = 0;
1015 	int ret, i;
1016 
1017 	if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
1018 		v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1019 		goto err;
1020 	}
1021 
1022 	vsi = ice_get_vf_vsi(vf);
1023 	if (!vsi) {
1024 		v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1025 		goto err;
1026 	}
1027 
1028 	pi = pf->hw.port_info;
1029 	numtc = vsi->tc_cfg.numtc;
1030 
1031 	vsi_ctx = ice_get_vsi_ctx(pi->hw, vf->lan_vsi_idx);
1032 	if (!vsi_ctx) {
1033 		v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1034 		goto err;
1035 	}
1036 
1037 	len = struct_size(cap_list, cap, numtc);
1038 	cap_list = kzalloc(len, GFP_KERNEL);
1039 	if (!cap_list) {
1040 		v_ret = VIRTCHNL_STATUS_ERR_NO_MEMORY;
1041 		len = 0;
1042 		goto err;
1043 	}
1044 
1045 	cap_list->vsi_id = vsi->vsi_num;
1046 	cap_list->num_elem = numtc;
1047 
1048 	/* Store the UP2TC configuration from DCB to a user priority bitmap
1049 	 * of each TC. Each element of prio_of_tc represents one TC. Each
1050 	 * bitmap indicates the user priorities belong to this TC.
1051 	 */
1052 	for (i = 0; i < ICE_MAX_USER_PRIORITY; i++) {
1053 		tc = pi->qos_cfg.local_dcbx_cfg.etscfg.prio_table[i];
1054 		tc_prio[tc] |= BIT(i);
1055 	}
1056 
1057 	for (i = 0; i < numtc; i++) {
1058 		cfg = &cap_list->cap[i];
1059 		cfg->tc_num = i;
1060 		cfg->tc_prio = tc_prio[i];
1061 		cfg->arbiter = pi->qos_cfg.local_dcbx_cfg.etscfg.tsatable[i];
1062 		cfg->weight = VIRTCHNL_STRICT_WEIGHT;
1063 		cfg->type = VIRTCHNL_BW_SHAPER;
1064 		cfg->shaper.committed = vsi_ctx->sched.bw_t_info[i].cir_bw.bw;
1065 		cfg->shaper.peak = vsi_ctx->sched.bw_t_info[i].eir_bw.bw;
1066 	}
1067 
1068 err:
1069 	ret = ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_GET_QOS_CAPS, v_ret,
1070 				    (u8 *)cap_list, len);
1071 	kfree(cap_list);
1072 	return ret;
1073 }
1074 
1075 /**
1076  * ice_vc_cfg_promiscuous_mode_msg
1077  * @vf: pointer to the VF info
1078  * @msg: pointer to the msg buffer
1079  *
1080  * called from the VF to configure VF VSIs promiscuous mode
1081  */
1082 static int ice_vc_cfg_promiscuous_mode_msg(struct ice_vf *vf, u8 *msg)
1083 {
1084 	enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
1085 	bool rm_promisc, alluni = false, allmulti = false;
1086 	struct virtchnl_promisc_info *info =
1087 	    (struct virtchnl_promisc_info *)msg;
1088 	struct ice_vsi_vlan_ops *vlan_ops;
1089 	int mcast_err = 0, ucast_err = 0;
1090 	struct ice_pf *pf = vf->pf;
1091 	struct ice_vsi *vsi;
1092 	u8 mcast_m, ucast_m;
1093 	struct device *dev;
1094 	int ret = 0;
1095 
1096 	if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
1097 		v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1098 		goto error_param;
1099 	}
1100 
1101 	if (!ice_vc_isvalid_vsi_id(vf, info->vsi_id)) {
1102 		v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1103 		goto error_param;
1104 	}
1105 
1106 	vsi = ice_get_vf_vsi(vf);
1107 	if (!vsi) {
1108 		v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1109 		goto error_param;
1110 	}
1111 
1112 	dev = ice_pf_to_dev(pf);
1113 	if (!ice_is_vf_trusted(vf)) {
1114 		dev_err(dev, "Unprivileged VF %d is attempting to configure promiscuous mode\n",
1115 			vf->vf_id);
1116 		/* Leave v_ret alone, lie to the VF on purpose. */
1117 		goto error_param;
1118 	}
1119 
1120 	if (info->flags & FLAG_VF_UNICAST_PROMISC)
1121 		alluni = true;
1122 
1123 	if (info->flags & FLAG_VF_MULTICAST_PROMISC)
1124 		allmulti = true;
1125 
1126 	rm_promisc = !allmulti && !alluni;
1127 
1128 	vlan_ops = ice_get_compat_vsi_vlan_ops(vsi);
1129 	if (rm_promisc)
1130 		ret = vlan_ops->ena_rx_filtering(vsi);
1131 	else
1132 		ret = vlan_ops->dis_rx_filtering(vsi);
1133 	if (ret) {
1134 		dev_err(dev, "Failed to configure VLAN pruning in promiscuous mode\n");
1135 		v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1136 		goto error_param;
1137 	}
1138 
1139 	ice_vf_get_promisc_masks(vf, vsi, &ucast_m, &mcast_m);
1140 
1141 	if (!test_bit(ICE_FLAG_VF_TRUE_PROMISC_ENA, pf->flags)) {
1142 		if (alluni) {
1143 			/* in this case we're turning on promiscuous mode */
1144 			ret = ice_set_dflt_vsi(vsi);
1145 		} else {
1146 			/* in this case we're turning off promiscuous mode */
1147 			if (ice_is_dflt_vsi_in_use(vsi->port_info))
1148 				ret = ice_clear_dflt_vsi(vsi);
1149 		}
1150 
1151 		/* in this case we're turning on/off only
1152 		 * allmulticast
1153 		 */
1154 		if (allmulti)
1155 			mcast_err = ice_vf_set_vsi_promisc(vf, vsi, mcast_m);
1156 		else
1157 			mcast_err = ice_vf_clear_vsi_promisc(vf, vsi, mcast_m);
1158 
1159 		if (ret) {
1160 			dev_err(dev, "Turning on/off promiscuous mode for VF %d failed, error: %d\n",
1161 				vf->vf_id, ret);
1162 			v_ret = VIRTCHNL_STATUS_ERR_ADMIN_QUEUE_ERROR;
1163 			goto error_param;
1164 		}
1165 	} else {
1166 		if (alluni)
1167 			ucast_err = ice_vf_set_vsi_promisc(vf, vsi, ucast_m);
1168 		else
1169 			ucast_err = ice_vf_clear_vsi_promisc(vf, vsi, ucast_m);
1170 
1171 		if (allmulti)
1172 			mcast_err = ice_vf_set_vsi_promisc(vf, vsi, mcast_m);
1173 		else
1174 			mcast_err = ice_vf_clear_vsi_promisc(vf, vsi, mcast_m);
1175 
1176 		if (ucast_err || mcast_err)
1177 			v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1178 	}
1179 
1180 	if (!mcast_err) {
1181 		if (allmulti &&
1182 		    !test_and_set_bit(ICE_VF_STATE_MC_PROMISC, vf->vf_states))
1183 			dev_info(dev, "VF %u successfully set multicast promiscuous mode\n",
1184 				 vf->vf_id);
1185 		else if (!allmulti &&
1186 			 test_and_clear_bit(ICE_VF_STATE_MC_PROMISC,
1187 					    vf->vf_states))
1188 			dev_info(dev, "VF %u successfully unset multicast promiscuous mode\n",
1189 				 vf->vf_id);
1190 	} else {
1191 		dev_err(dev, "Error while modifying multicast promiscuous mode for VF %u, error: %d\n",
1192 			vf->vf_id, mcast_err);
1193 	}
1194 
1195 	if (!ucast_err) {
1196 		if (alluni &&
1197 		    !test_and_set_bit(ICE_VF_STATE_UC_PROMISC, vf->vf_states))
1198 			dev_info(dev, "VF %u successfully set unicast promiscuous mode\n",
1199 				 vf->vf_id);
1200 		else if (!alluni &&
1201 			 test_and_clear_bit(ICE_VF_STATE_UC_PROMISC,
1202 					    vf->vf_states))
1203 			dev_info(dev, "VF %u successfully unset unicast promiscuous mode\n",
1204 				 vf->vf_id);
1205 	} else {
1206 		dev_err(dev, "Error while modifying unicast promiscuous mode for VF %u, error: %d\n",
1207 			vf->vf_id, ucast_err);
1208 	}
1209 
1210 error_param:
1211 	return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE,
1212 				     v_ret, NULL, 0);
1213 }
1214 
1215 /**
1216  * ice_vc_get_stats_msg
1217  * @vf: pointer to the VF info
1218  * @msg: pointer to the msg buffer
1219  *
1220  * called from the VF to get VSI stats
1221  */
1222 static int ice_vc_get_stats_msg(struct ice_vf *vf, u8 *msg)
1223 {
1224 	enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
1225 	struct virtchnl_queue_select *vqs =
1226 		(struct virtchnl_queue_select *)msg;
1227 	struct ice_eth_stats stats = { 0 };
1228 	struct ice_vsi *vsi;
1229 
1230 	if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
1231 		v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1232 		goto error_param;
1233 	}
1234 
1235 	if (!ice_vc_isvalid_vsi_id(vf, vqs->vsi_id)) {
1236 		v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1237 		goto error_param;
1238 	}
1239 
1240 	vsi = ice_get_vf_vsi(vf);
1241 	if (!vsi) {
1242 		v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1243 		goto error_param;
1244 	}
1245 
1246 	ice_update_eth_stats(vsi);
1247 
1248 	stats = vsi->eth_stats;
1249 
1250 error_param:
1251 	/* send the response to the VF */
1252 	return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_GET_STATS, v_ret,
1253 				     (u8 *)&stats, sizeof(stats));
1254 }
1255 
1256 /**
1257  * ice_can_vf_change_mac
1258  * @vf: pointer to the VF info
1259  *
1260  * Return true if the VF is allowed to change its MAC filters, false otherwise
1261  */
1262 static bool ice_can_vf_change_mac(struct ice_vf *vf)
1263 {
1264 	/* If the VF MAC address has been set administratively (via the
1265 	 * ndo_set_vf_mac command), then deny permission to the VF to
1266 	 * add/delete unicast MAC addresses, unless the VF is trusted
1267 	 */
1268 	if (vf->pf_set_mac && !ice_is_vf_trusted(vf))
1269 		return false;
1270 
1271 	return true;
1272 }
1273 
1274 /**
1275  * ice_vc_ether_addr_type - get type of virtchnl_ether_addr
1276  * @vc_ether_addr: used to extract the type
1277  */
1278 static u8
1279 ice_vc_ether_addr_type(struct virtchnl_ether_addr *vc_ether_addr)
1280 {
1281 	return (vc_ether_addr->type & VIRTCHNL_ETHER_ADDR_TYPE_MASK);
1282 }
1283 
1284 /**
1285  * ice_is_vc_addr_legacy - check if the MAC address is from an older VF
1286  * @vc_ether_addr: VIRTCHNL structure that contains MAC and type
1287  */
1288 static bool
1289 ice_is_vc_addr_legacy(struct virtchnl_ether_addr *vc_ether_addr)
1290 {
1291 	u8 type = ice_vc_ether_addr_type(vc_ether_addr);
1292 
1293 	return (type == VIRTCHNL_ETHER_ADDR_LEGACY);
1294 }
1295 
1296 /**
1297  * ice_is_vc_addr_primary - check if the MAC address is the VF's primary MAC
1298  * @vc_ether_addr: VIRTCHNL structure that contains MAC and type
1299  *
1300  * This function should only be called when the MAC address in
1301  * virtchnl_ether_addr is a valid unicast MAC
1302  */
1303 static bool
1304 ice_is_vc_addr_primary(struct virtchnl_ether_addr __maybe_unused *vc_ether_addr)
1305 {
1306 	u8 type = ice_vc_ether_addr_type(vc_ether_addr);
1307 
1308 	return (type == VIRTCHNL_ETHER_ADDR_PRIMARY);
1309 }
1310 
1311 /**
1312  * ice_vfhw_mac_add - update the VF's cached hardware MAC if allowed
1313  * @vf: VF to update
1314  * @vc_ether_addr: structure from VIRTCHNL with MAC to add
1315  */
1316 static void
1317 ice_vfhw_mac_add(struct ice_vf *vf, struct virtchnl_ether_addr *vc_ether_addr)
1318 {
1319 	u8 *mac_addr = vc_ether_addr->addr;
1320 
1321 	if (!is_valid_ether_addr(mac_addr))
1322 		return;
1323 
1324 	/* only allow legacy VF drivers to set the device and hardware MAC if it
1325 	 * is zero and allow new VF drivers to set the hardware MAC if the type
1326 	 * was correctly specified over VIRTCHNL
1327 	 */
1328 	if ((ice_is_vc_addr_legacy(vc_ether_addr) &&
1329 	     is_zero_ether_addr(vf->hw_lan_addr)) ||
1330 	    ice_is_vc_addr_primary(vc_ether_addr)) {
1331 		ether_addr_copy(vf->dev_lan_addr, mac_addr);
1332 		ether_addr_copy(vf->hw_lan_addr, mac_addr);
1333 	}
1334 
1335 	/* hardware and device MACs are already set, but its possible that the
1336 	 * VF driver sent the VIRTCHNL_OP_ADD_ETH_ADDR message before the
1337 	 * VIRTCHNL_OP_DEL_ETH_ADDR when trying to update its MAC, so save it
1338 	 * away for the legacy VF driver case as it will be updated in the
1339 	 * delete flow for this case
1340 	 */
1341 	if (ice_is_vc_addr_legacy(vc_ether_addr)) {
1342 		ether_addr_copy(vf->legacy_last_added_umac.addr,
1343 				mac_addr);
1344 		vf->legacy_last_added_umac.time_modified = jiffies;
1345 	}
1346 }
1347 
1348 /**
1349  * ice_is_mc_lldp_eth_addr - check if the given MAC is a multicast LLDP address
1350  * @mac: address to check
1351  *
1352  * Return: true if the address is one of the three possible LLDP multicast
1353  *	   addresses, false otherwise.
1354  */
1355 static bool ice_is_mc_lldp_eth_addr(const u8 *mac)
1356 {
1357 	const u8 lldp_mac_base[] = {0x01, 0x80, 0xc2, 0x00, 0x00};
1358 
1359 	if (memcmp(mac, lldp_mac_base, sizeof(lldp_mac_base)))
1360 		return false;
1361 
1362 	return (mac[5] == 0x0e || mac[5] == 0x03 || mac[5] == 0x00);
1363 }
1364 
1365 /**
1366  * ice_vc_can_add_mac - check if the VF is allowed to add a given MAC
1367  * @vf: a VF to add the address to
1368  * @mac: address to check
1369  *
1370  * Return: true if the VF is allowed to add such MAC address, false otherwise.
1371  */
1372 static bool ice_vc_can_add_mac(const struct ice_vf *vf, const u8 *mac)
1373 {
1374 	struct device *dev = ice_pf_to_dev(vf->pf);
1375 
1376 	if (is_unicast_ether_addr(mac) &&
1377 	    !ice_can_vf_change_mac((struct ice_vf *)vf)) {
1378 		dev_err(dev,
1379 			"VF attempting to override administratively set MAC address, bring down and up the VF interface to resume normal operation\n");
1380 		return false;
1381 	}
1382 
1383 	if (!vf->trusted && ice_is_mc_lldp_eth_addr(mac)) {
1384 		dev_warn(dev,
1385 			 "An untrusted VF %u is attempting to configure an LLDP multicast address\n",
1386 			 vf->vf_id);
1387 		return false;
1388 	}
1389 
1390 	return true;
1391 }
1392 
1393 /**
1394  * ice_vc_add_mac_addr - attempt to add the MAC address passed in
1395  * @vf: pointer to the VF info
1396  * @vsi: pointer to the VF's VSI
1397  * @vc_ether_addr: VIRTCHNL MAC address structure used to add MAC
1398  */
1399 static int
1400 ice_vc_add_mac_addr(struct ice_vf *vf, struct ice_vsi *vsi,
1401 		    struct virtchnl_ether_addr *vc_ether_addr)
1402 {
1403 	struct device *dev = ice_pf_to_dev(vf->pf);
1404 	u8 *mac_addr = vc_ether_addr->addr;
1405 	int ret;
1406 
1407 	/* device MAC already added */
1408 	if (ether_addr_equal(mac_addr, vf->dev_lan_addr))
1409 		return 0;
1410 
1411 	if (!ice_vc_can_add_mac(vf, mac_addr))
1412 		return -EPERM;
1413 
1414 	ret = ice_fltr_add_mac(vsi, mac_addr, ICE_FWD_TO_VSI);
1415 	if (ret == -EEXIST) {
1416 		dev_dbg(dev, "MAC %pM already exists for VF %d\n", mac_addr,
1417 			vf->vf_id);
1418 		/* don't return since we might need to update
1419 		 * the primary MAC in ice_vfhw_mac_add() below
1420 		 */
1421 	} else if (ret) {
1422 		dev_err(dev, "Failed to add MAC %pM for VF %d\n, error %d\n",
1423 			mac_addr, vf->vf_id, ret);
1424 		return ret;
1425 	} else {
1426 		vf->num_mac++;
1427 		if (ice_is_mc_lldp_eth_addr(mac_addr))
1428 			ice_vf_update_mac_lldp_num(vf, vsi, true);
1429 	}
1430 
1431 	ice_vfhw_mac_add(vf, vc_ether_addr);
1432 
1433 	return ret;
1434 }
1435 
1436 /**
1437  * ice_is_legacy_umac_expired - check if last added legacy unicast MAC expired
1438  * @last_added_umac: structure used to check expiration
1439  */
1440 static bool ice_is_legacy_umac_expired(struct ice_time_mac *last_added_umac)
1441 {
1442 #define ICE_LEGACY_VF_MAC_CHANGE_EXPIRE_TIME	msecs_to_jiffies(3000)
1443 	return time_is_before_jiffies(last_added_umac->time_modified +
1444 				      ICE_LEGACY_VF_MAC_CHANGE_EXPIRE_TIME);
1445 }
1446 
1447 /**
1448  * ice_update_legacy_cached_mac - update cached hardware MAC for legacy VF
1449  * @vf: VF to update
1450  * @vc_ether_addr: structure from VIRTCHNL with MAC to check
1451  *
1452  * only update cached hardware MAC for legacy VF drivers on delete
1453  * because we cannot guarantee order/type of MAC from the VF driver
1454  */
1455 static void
1456 ice_update_legacy_cached_mac(struct ice_vf *vf,
1457 			     struct virtchnl_ether_addr *vc_ether_addr)
1458 {
1459 	if (!ice_is_vc_addr_legacy(vc_ether_addr) ||
1460 	    ice_is_legacy_umac_expired(&vf->legacy_last_added_umac))
1461 		return;
1462 
1463 	ether_addr_copy(vf->dev_lan_addr, vf->legacy_last_added_umac.addr);
1464 	ether_addr_copy(vf->hw_lan_addr, vf->legacy_last_added_umac.addr);
1465 }
1466 
1467 /**
1468  * ice_vfhw_mac_del - update the VF's cached hardware MAC if allowed
1469  * @vf: VF to update
1470  * @vc_ether_addr: structure from VIRTCHNL with MAC to delete
1471  */
1472 static void
1473 ice_vfhw_mac_del(struct ice_vf *vf, struct virtchnl_ether_addr *vc_ether_addr)
1474 {
1475 	u8 *mac_addr = vc_ether_addr->addr;
1476 
1477 	if (!is_valid_ether_addr(mac_addr) ||
1478 	    !ether_addr_equal(vf->dev_lan_addr, mac_addr))
1479 		return;
1480 
1481 	/* allow the device MAC to be repopulated in the add flow and don't
1482 	 * clear the hardware MAC (i.e. hw_lan_addr) here as that is meant
1483 	 * to be persistent on VM reboot and across driver unload/load, which
1484 	 * won't work if we clear the hardware MAC here
1485 	 */
1486 	eth_zero_addr(vf->dev_lan_addr);
1487 
1488 	ice_update_legacy_cached_mac(vf, vc_ether_addr);
1489 }
1490 
1491 /**
1492  * ice_vc_del_mac_addr - attempt to delete the MAC address passed in
1493  * @vf: pointer to the VF info
1494  * @vsi: pointer to the VF's VSI
1495  * @vc_ether_addr: VIRTCHNL MAC address structure used to delete MAC
1496  */
1497 static int
1498 ice_vc_del_mac_addr(struct ice_vf *vf, struct ice_vsi *vsi,
1499 		    struct virtchnl_ether_addr *vc_ether_addr)
1500 {
1501 	struct device *dev = ice_pf_to_dev(vf->pf);
1502 	u8 *mac_addr = vc_ether_addr->addr;
1503 	int status;
1504 
1505 	if (!ice_can_vf_change_mac(vf) &&
1506 	    ether_addr_equal(vf->dev_lan_addr, mac_addr))
1507 		return 0;
1508 
1509 	status = ice_fltr_remove_mac(vsi, mac_addr, ICE_FWD_TO_VSI);
1510 	if (status == -ENOENT) {
1511 		dev_err(dev, "MAC %pM does not exist for VF %d\n", mac_addr,
1512 			vf->vf_id);
1513 		return -ENOENT;
1514 	} else if (status) {
1515 		dev_err(dev, "Failed to delete MAC %pM for VF %d, error %d\n",
1516 			mac_addr, vf->vf_id, status);
1517 		return -EIO;
1518 	}
1519 
1520 	ice_vfhw_mac_del(vf, vc_ether_addr);
1521 
1522 	vf->num_mac--;
1523 	if (ice_is_mc_lldp_eth_addr(mac_addr))
1524 		ice_vf_update_mac_lldp_num(vf, vsi, false);
1525 
1526 	return 0;
1527 }
1528 
1529 /**
1530  * ice_vc_handle_mac_addr_msg
1531  * @vf: pointer to the VF info
1532  * @msg: pointer to the msg buffer
1533  * @set: true if MAC filters are being set, false otherwise
1534  *
1535  * add guest MAC address filter
1536  */
1537 static int
1538 ice_vc_handle_mac_addr_msg(struct ice_vf *vf, u8 *msg, bool set)
1539 {
1540 	int (*ice_vc_cfg_mac)
1541 		(struct ice_vf *vf, struct ice_vsi *vsi,
1542 		 struct virtchnl_ether_addr *virtchnl_ether_addr);
1543 	enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
1544 	struct virtchnl_ether_addr_list *al =
1545 	    (struct virtchnl_ether_addr_list *)msg;
1546 	struct ice_pf *pf = vf->pf;
1547 	enum virtchnl_ops vc_op;
1548 	struct ice_vsi *vsi;
1549 	int i;
1550 
1551 	if (set) {
1552 		vc_op = VIRTCHNL_OP_ADD_ETH_ADDR;
1553 		ice_vc_cfg_mac = ice_vc_add_mac_addr;
1554 	} else {
1555 		vc_op = VIRTCHNL_OP_DEL_ETH_ADDR;
1556 		ice_vc_cfg_mac = ice_vc_del_mac_addr;
1557 	}
1558 
1559 	if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states) ||
1560 	    !ice_vc_isvalid_vsi_id(vf, al->vsi_id)) {
1561 		v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1562 		goto handle_mac_exit;
1563 	}
1564 
1565 	/* If this VF is not privileged, then we can't add more than a
1566 	 * limited number of addresses. Check to make sure that the
1567 	 * additions do not push us over the limit.
1568 	 */
1569 	if (set && !ice_is_vf_trusted(vf) &&
1570 	    (vf->num_mac + al->num_elements) > ICE_MAX_MACADDR_PER_VF) {
1571 		dev_err(ice_pf_to_dev(pf), "Can't add more MAC addresses, because VF-%d is not trusted, switch the VF to trusted mode in order to add more functionalities\n",
1572 			vf->vf_id);
1573 		v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1574 		goto handle_mac_exit;
1575 	}
1576 
1577 	vsi = ice_get_vf_vsi(vf);
1578 	if (!vsi) {
1579 		v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1580 		goto handle_mac_exit;
1581 	}
1582 
1583 	for (i = 0; i < al->num_elements; i++) {
1584 		u8 *mac_addr = al->list[i].addr;
1585 		int result;
1586 
1587 		if (is_broadcast_ether_addr(mac_addr) ||
1588 		    is_zero_ether_addr(mac_addr))
1589 			continue;
1590 
1591 		result = ice_vc_cfg_mac(vf, vsi, &al->list[i]);
1592 		if (result == -EEXIST || result == -ENOENT) {
1593 			continue;
1594 		} else if (result) {
1595 			v_ret = VIRTCHNL_STATUS_ERR_ADMIN_QUEUE_ERROR;
1596 			goto handle_mac_exit;
1597 		}
1598 	}
1599 
1600 handle_mac_exit:
1601 	/* send the response to the VF */
1602 	return ice_vc_send_msg_to_vf(vf, vc_op, v_ret, NULL, 0);
1603 }
1604 
1605 /**
1606  * ice_vc_add_mac_addr_msg
1607  * @vf: pointer to the VF info
1608  * @msg: pointer to the msg buffer
1609  *
1610  * add guest MAC address filter
1611  */
1612 static int ice_vc_add_mac_addr_msg(struct ice_vf *vf, u8 *msg)
1613 {
1614 	return ice_vc_handle_mac_addr_msg(vf, msg, true);
1615 }
1616 
1617 /**
1618  * ice_vc_del_mac_addr_msg
1619  * @vf: pointer to the VF info
1620  * @msg: pointer to the msg buffer
1621  *
1622  * remove guest MAC address filter
1623  */
1624 static int ice_vc_del_mac_addr_msg(struct ice_vf *vf, u8 *msg)
1625 {
1626 	return ice_vc_handle_mac_addr_msg(vf, msg, false);
1627 }
1628 
1629 /**
1630  * ice_vf_vlan_offload_ena - determine if capabilities support VLAN offloads
1631  * @caps: VF driver negotiated capabilities
1632  *
1633  * Return true if VIRTCHNL_VF_OFFLOAD_VLAN capability is set, else return false
1634  */
1635 static bool ice_vf_vlan_offload_ena(u32 caps)
1636 {
1637 	return !!(caps & VIRTCHNL_VF_OFFLOAD_VLAN);
1638 }
1639 
1640 /**
1641  * ice_is_vlan_promisc_allowed - check if VLAN promiscuous config is allowed
1642  * @vf: VF used to determine if VLAN promiscuous config is allowed
1643  */
1644 bool ice_is_vlan_promisc_allowed(struct ice_vf *vf)
1645 {
1646 	if ((test_bit(ICE_VF_STATE_UC_PROMISC, vf->vf_states) ||
1647 	     test_bit(ICE_VF_STATE_MC_PROMISC, vf->vf_states)) &&
1648 	    test_bit(ICE_FLAG_VF_TRUE_PROMISC_ENA, vf->pf->flags))
1649 		return true;
1650 
1651 	return false;
1652 }
1653 
1654 /**
1655  * ice_vf_ena_vlan_promisc - Enable Tx/Rx VLAN promiscuous for the VLAN
1656  * @vf: VF to enable VLAN promisc on
1657  * @vsi: VF's VSI used to enable VLAN promiscuous mode
1658  * @vlan: VLAN used to enable VLAN promiscuous
1659  *
1660  * This function should only be called if VLAN promiscuous mode is allowed,
1661  * which can be determined via ice_is_vlan_promisc_allowed().
1662  */
1663 int ice_vf_ena_vlan_promisc(struct ice_vf *vf, struct ice_vsi *vsi,
1664 			    struct ice_vlan *vlan)
1665 {
1666 	u8 promisc_m = 0;
1667 	int status;
1668 
1669 	if (test_bit(ICE_VF_STATE_UC_PROMISC, vf->vf_states))
1670 		promisc_m |= ICE_UCAST_VLAN_PROMISC_BITS;
1671 	if (test_bit(ICE_VF_STATE_MC_PROMISC, vf->vf_states))
1672 		promisc_m |= ICE_MCAST_VLAN_PROMISC_BITS;
1673 
1674 	if (!promisc_m)
1675 		return 0;
1676 
1677 	status = ice_fltr_set_vsi_promisc(&vsi->back->hw, vsi->idx, promisc_m,
1678 					  vlan->vid);
1679 	if (status && status != -EEXIST)
1680 		return status;
1681 
1682 	return 0;
1683 }
1684 
1685 /**
1686  * ice_vf_dis_vlan_promisc - Disable Tx/Rx VLAN promiscuous for the VLAN
1687  * @vsi: VF's VSI used to disable VLAN promiscuous mode for
1688  * @vlan: VLAN used to disable VLAN promiscuous
1689  *
1690  * This function should only be called if VLAN promiscuous mode is allowed,
1691  * which can be determined via ice_is_vlan_promisc_allowed().
1692  */
1693 static int ice_vf_dis_vlan_promisc(struct ice_vsi *vsi, struct ice_vlan *vlan)
1694 {
1695 	u8 promisc_m = ICE_UCAST_VLAN_PROMISC_BITS | ICE_MCAST_VLAN_PROMISC_BITS;
1696 	int status;
1697 
1698 	status = ice_fltr_clear_vsi_promisc(&vsi->back->hw, vsi->idx, promisc_m,
1699 					    vlan->vid);
1700 	if (status && status != -ENOENT)
1701 		return status;
1702 
1703 	return 0;
1704 }
1705 
1706 /**
1707  * ice_vf_has_max_vlans - check if VF already has the max allowed VLAN filters
1708  * @vf: VF to check against
1709  * @vsi: VF's VSI
1710  *
1711  * If the VF is trusted then the VF is allowed to add as many VLANs as it
1712  * wants to, so return false.
1713  *
1714  * When the VF is untrusted compare the number of non-zero VLANs + 1 to the max
1715  * allowed VLANs for an untrusted VF. Return the result of this comparison.
1716  */
1717 static bool ice_vf_has_max_vlans(struct ice_vf *vf, struct ice_vsi *vsi)
1718 {
1719 	if (ice_is_vf_trusted(vf))
1720 		return false;
1721 
1722 #define ICE_VF_ADDED_VLAN_ZERO_FLTRS	1
1723 	return ((ice_vsi_num_non_zero_vlans(vsi) +
1724 		ICE_VF_ADDED_VLAN_ZERO_FLTRS) >= ICE_MAX_VLAN_PER_VF);
1725 }
1726 
1727 /**
1728  * ice_vc_process_vlan_msg
1729  * @vf: pointer to the VF info
1730  * @msg: pointer to the msg buffer
1731  * @add_v: Add VLAN if true, otherwise delete VLAN
1732  *
1733  * Process virtchnl op to add or remove programmed guest VLAN ID
1734  */
1735 static int ice_vc_process_vlan_msg(struct ice_vf *vf, u8 *msg, bool add_v)
1736 {
1737 	enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
1738 	struct virtchnl_vlan_filter_list *vfl =
1739 	    (struct virtchnl_vlan_filter_list *)msg;
1740 	struct ice_pf *pf = vf->pf;
1741 	bool vlan_promisc = false;
1742 	struct ice_vsi *vsi;
1743 	struct device *dev;
1744 	int status = 0;
1745 	int i;
1746 
1747 	dev = ice_pf_to_dev(pf);
1748 	if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
1749 		v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1750 		goto error_param;
1751 	}
1752 
1753 	if (!ice_vf_vlan_offload_ena(vf->driver_caps)) {
1754 		v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1755 		goto error_param;
1756 	}
1757 
1758 	if (!ice_vc_isvalid_vsi_id(vf, vfl->vsi_id)) {
1759 		v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1760 		goto error_param;
1761 	}
1762 
1763 	for (i = 0; i < vfl->num_elements; i++) {
1764 		if (vfl->vlan_id[i] >= VLAN_N_VID) {
1765 			v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1766 			dev_err(dev, "invalid VF VLAN id %d\n",
1767 				vfl->vlan_id[i]);
1768 			goto error_param;
1769 		}
1770 	}
1771 
1772 	vsi = ice_get_vf_vsi(vf);
1773 	if (!vsi) {
1774 		v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1775 		goto error_param;
1776 	}
1777 
1778 	if (add_v && ice_vf_has_max_vlans(vf, vsi)) {
1779 		dev_info(dev, "VF-%d is not trusted, switch the VF to trusted mode, in order to add more VLAN addresses\n",
1780 			 vf->vf_id);
1781 		/* There is no need to let VF know about being not trusted,
1782 		 * so we can just return success message here
1783 		 */
1784 		goto error_param;
1785 	}
1786 
1787 	/* in DVM a VF can add/delete inner VLAN filters when
1788 	 * VIRTCHNL_VF_OFFLOAD_VLAN is negotiated, so only reject in SVM
1789 	 */
1790 	if (ice_vf_is_port_vlan_ena(vf) && !ice_is_dvm_ena(&pf->hw)) {
1791 		v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1792 		goto error_param;
1793 	}
1794 
1795 	/* in DVM VLAN promiscuous is based on the outer VLAN, which would be
1796 	 * the port VLAN if VIRTCHNL_VF_OFFLOAD_VLAN was negotiated, so only
1797 	 * allow vlan_promisc = true in SVM and if no port VLAN is configured
1798 	 */
1799 	vlan_promisc = ice_is_vlan_promisc_allowed(vf) &&
1800 		!ice_is_dvm_ena(&pf->hw) &&
1801 		!ice_vf_is_port_vlan_ena(vf);
1802 
1803 	if (add_v) {
1804 		for (i = 0; i < vfl->num_elements; i++) {
1805 			u16 vid = vfl->vlan_id[i];
1806 			struct ice_vlan vlan;
1807 
1808 			if (ice_vf_has_max_vlans(vf, vsi)) {
1809 				dev_info(dev, "VF-%d is not trusted, switch the VF to trusted mode, in order to add more VLAN addresses\n",
1810 					 vf->vf_id);
1811 				/* There is no need to let VF know about being
1812 				 * not trusted, so we can just return success
1813 				 * message here as well.
1814 				 */
1815 				goto error_param;
1816 			}
1817 
1818 			/* we add VLAN 0 by default for each VF so we can enable
1819 			 * Tx VLAN anti-spoof without triggering MDD events so
1820 			 * we don't need to add it again here
1821 			 */
1822 			if (!vid)
1823 				continue;
1824 
1825 			vlan = ICE_VLAN(ETH_P_8021Q, vid, 0);
1826 			status = vsi->inner_vlan_ops.add_vlan(vsi, &vlan);
1827 			if (status) {
1828 				v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1829 				goto error_param;
1830 			}
1831 
1832 			/* Enable VLAN filtering on first non-zero VLAN */
1833 			if (!vlan_promisc && vid && !ice_is_dvm_ena(&pf->hw)) {
1834 				if (vf->spoofchk) {
1835 					status = vsi->inner_vlan_ops.ena_tx_filtering(vsi);
1836 					if (status) {
1837 						v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1838 						dev_err(dev, "Enable VLAN anti-spoofing on VLAN ID: %d failed error-%d\n",
1839 							vid, status);
1840 						goto error_param;
1841 					}
1842 				}
1843 				if (vsi->inner_vlan_ops.ena_rx_filtering(vsi)) {
1844 					v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1845 					dev_err(dev, "Enable VLAN pruning on VLAN ID: %d failed error-%d\n",
1846 						vid, status);
1847 					goto error_param;
1848 				}
1849 			} else if (vlan_promisc) {
1850 				status = ice_vf_ena_vlan_promisc(vf, vsi, &vlan);
1851 				if (status) {
1852 					v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1853 					dev_err(dev, "Enable Unicast/multicast promiscuous mode on VLAN ID:%d failed error-%d\n",
1854 						vid, status);
1855 				}
1856 			}
1857 		}
1858 	} else {
1859 		/* In case of non_trusted VF, number of VLAN elements passed
1860 		 * to PF for removal might be greater than number of VLANs
1861 		 * filter programmed for that VF - So, use actual number of
1862 		 * VLANS added earlier with add VLAN opcode. In order to avoid
1863 		 * removing VLAN that doesn't exist, which result to sending
1864 		 * erroneous failed message back to the VF
1865 		 */
1866 		int num_vf_vlan;
1867 
1868 		num_vf_vlan = vsi->num_vlan;
1869 		for (i = 0; i < vfl->num_elements && i < num_vf_vlan; i++) {
1870 			u16 vid = vfl->vlan_id[i];
1871 			struct ice_vlan vlan;
1872 
1873 			/* we add VLAN 0 by default for each VF so we can enable
1874 			 * Tx VLAN anti-spoof without triggering MDD events so
1875 			 * we don't want a VIRTCHNL request to remove it
1876 			 */
1877 			if (!vid)
1878 				continue;
1879 
1880 			vlan = ICE_VLAN(ETH_P_8021Q, vid, 0);
1881 			status = vsi->inner_vlan_ops.del_vlan(vsi, &vlan);
1882 			if (status) {
1883 				v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1884 				goto error_param;
1885 			}
1886 
1887 			/* Disable VLAN filtering when only VLAN 0 is left */
1888 			if (!ice_vsi_has_non_zero_vlans(vsi)) {
1889 				vsi->inner_vlan_ops.dis_tx_filtering(vsi);
1890 				vsi->inner_vlan_ops.dis_rx_filtering(vsi);
1891 			}
1892 
1893 			if (vlan_promisc)
1894 				ice_vf_dis_vlan_promisc(vsi, &vlan);
1895 		}
1896 	}
1897 
1898 error_param:
1899 	/* send the response to the VF */
1900 	if (add_v)
1901 		return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_ADD_VLAN, v_ret,
1902 					     NULL, 0);
1903 	else
1904 		return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_DEL_VLAN, v_ret,
1905 					     NULL, 0);
1906 }
1907 
1908 /**
1909  * ice_vc_add_vlan_msg
1910  * @vf: pointer to the VF info
1911  * @msg: pointer to the msg buffer
1912  *
1913  * Add and program guest VLAN ID
1914  */
1915 static int ice_vc_add_vlan_msg(struct ice_vf *vf, u8 *msg)
1916 {
1917 	return ice_vc_process_vlan_msg(vf, msg, true);
1918 }
1919 
1920 /**
1921  * ice_vc_remove_vlan_msg
1922  * @vf: pointer to the VF info
1923  * @msg: pointer to the msg buffer
1924  *
1925  * remove programmed guest VLAN ID
1926  */
1927 static int ice_vc_remove_vlan_msg(struct ice_vf *vf, u8 *msg)
1928 {
1929 	return ice_vc_process_vlan_msg(vf, msg, false);
1930 }
1931 
1932 /**
1933  * ice_vsi_is_rxq_crc_strip_dis - check if Rx queue CRC strip is disabled or not
1934  * @vsi: pointer to the VF VSI info
1935  */
1936 static bool ice_vsi_is_rxq_crc_strip_dis(struct ice_vsi *vsi)
1937 {
1938 	unsigned int i;
1939 
1940 	ice_for_each_alloc_rxq(vsi, i)
1941 		if (vsi->rx_rings[i]->flags & ICE_RX_FLAGS_CRC_STRIP_DIS)
1942 			return true;
1943 
1944 	return false;
1945 }
1946 
1947 /**
1948  * ice_vc_ena_vlan_stripping
1949  * @vf: pointer to the VF info
1950  *
1951  * Enable VLAN header stripping for a given VF
1952  */
1953 static int ice_vc_ena_vlan_stripping(struct ice_vf *vf)
1954 {
1955 	enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
1956 	struct ice_vsi *vsi;
1957 
1958 	if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
1959 		v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1960 		goto error_param;
1961 	}
1962 
1963 	if (!ice_vf_vlan_offload_ena(vf->driver_caps)) {
1964 		v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1965 		goto error_param;
1966 	}
1967 
1968 	vsi = ice_get_vf_vsi(vf);
1969 	if (!vsi) {
1970 		v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1971 		goto error_param;
1972 	}
1973 
1974 	if (vsi->inner_vlan_ops.ena_stripping(vsi, ETH_P_8021Q))
1975 		v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1976 	else
1977 		vf->vlan_strip_ena |= ICE_INNER_VLAN_STRIP_ENA;
1978 
1979 error_param:
1980 	return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_ENABLE_VLAN_STRIPPING,
1981 				     v_ret, NULL, 0);
1982 }
1983 
1984 /**
1985  * ice_vc_dis_vlan_stripping
1986  * @vf: pointer to the VF info
1987  *
1988  * Disable VLAN header stripping for a given VF
1989  */
1990 static int ice_vc_dis_vlan_stripping(struct ice_vf *vf)
1991 {
1992 	enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
1993 	struct ice_vsi *vsi;
1994 
1995 	if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
1996 		v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1997 		goto error_param;
1998 	}
1999 
2000 	if (!ice_vf_vlan_offload_ena(vf->driver_caps)) {
2001 		v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2002 		goto error_param;
2003 	}
2004 
2005 	vsi = ice_get_vf_vsi(vf);
2006 	if (!vsi) {
2007 		v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2008 		goto error_param;
2009 	}
2010 
2011 	if (vsi->inner_vlan_ops.dis_stripping(vsi))
2012 		v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2013 	else
2014 		vf->vlan_strip_ena &= ~ICE_INNER_VLAN_STRIP_ENA;
2015 
2016 error_param:
2017 	return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_DISABLE_VLAN_STRIPPING,
2018 				     v_ret, NULL, 0);
2019 }
2020 
2021 /**
2022  * ice_vc_get_rss_hashcfg - return the RSS Hash configuration
2023  * @vf: pointer to the VF info
2024  */
2025 static int ice_vc_get_rss_hashcfg(struct ice_vf *vf)
2026 {
2027 	enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
2028 	struct virtchnl_rss_hashcfg *vrh = NULL;
2029 	int len = 0, ret;
2030 
2031 	if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
2032 		v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2033 		goto err;
2034 	}
2035 
2036 	if (!test_bit(ICE_FLAG_RSS_ENA, vf->pf->flags)) {
2037 		dev_err(ice_pf_to_dev(vf->pf), "RSS not supported by PF\n");
2038 		v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2039 		goto err;
2040 	}
2041 
2042 	len = sizeof(struct virtchnl_rss_hashcfg);
2043 	vrh = kzalloc(len, GFP_KERNEL);
2044 	if (!vrh) {
2045 		v_ret = VIRTCHNL_STATUS_ERR_NO_MEMORY;
2046 		len = 0;
2047 		goto err;
2048 	}
2049 
2050 	vrh->hashcfg = ICE_DEFAULT_RSS_HASHCFG;
2051 err:
2052 	/* send the response back to the VF */
2053 	ret = ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_GET_RSS_HASHCFG_CAPS, v_ret,
2054 				    (u8 *)vrh, len);
2055 	kfree(vrh);
2056 	return ret;
2057 }
2058 
2059 /**
2060  * ice_vc_set_rss_hashcfg - set RSS Hash configuration bits for the VF
2061  * @vf: pointer to the VF info
2062  * @msg: pointer to the msg buffer
2063  */
2064 static int ice_vc_set_rss_hashcfg(struct ice_vf *vf, u8 *msg)
2065 {
2066 	struct virtchnl_rss_hashcfg *vrh = (struct virtchnl_rss_hashcfg *)msg;
2067 	enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
2068 	struct ice_pf *pf = vf->pf;
2069 	struct ice_vsi *vsi;
2070 	struct device *dev;
2071 	int status;
2072 
2073 	dev = ice_pf_to_dev(pf);
2074 
2075 	if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
2076 		v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2077 		goto err;
2078 	}
2079 
2080 	if (!test_bit(ICE_FLAG_RSS_ENA, pf->flags)) {
2081 		dev_err(dev, "RSS not supported by PF\n");
2082 		v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2083 		goto err;
2084 	}
2085 
2086 	vsi = ice_get_vf_vsi(vf);
2087 	if (!vsi) {
2088 		v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2089 		goto err;
2090 	}
2091 
2092 	/* clear all previously programmed RSS configuration to allow VF drivers
2093 	 * the ability to customize the RSS configuration and/or completely
2094 	 * disable RSS
2095 	 */
2096 	status = ice_rem_vsi_rss_cfg(&pf->hw, vsi->idx);
2097 	if (status && !vrh->hashcfg) {
2098 		/* only report failure to clear the current RSS configuration if
2099 		 * that was clearly the VF's intention (i.e. vrh->hashcfg = 0)
2100 		 */
2101 		v_ret = ice_err_to_virt_err(status);
2102 		goto err;
2103 	} else if (status) {
2104 		/* allow the VF to update the RSS configuration even on failure
2105 		 * to clear the current RSS confguration in an attempt to keep
2106 		 * RSS in a working state
2107 		 */
2108 		dev_warn(dev, "Failed to clear the RSS configuration for VF %u\n",
2109 			 vf->vf_id);
2110 	}
2111 
2112 	if (vrh->hashcfg) {
2113 		status = ice_add_avf_rss_cfg(&pf->hw, vsi, vrh->hashcfg);
2114 		v_ret = ice_err_to_virt_err(status);
2115 	}
2116 
2117 	/* save the requested VF configuration */
2118 	if (!v_ret)
2119 		vf->rss_hashcfg = vrh->hashcfg;
2120 
2121 	/* send the response to the VF */
2122 err:
2123 	return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_SET_RSS_HASHCFG, v_ret,
2124 				     NULL, 0);
2125 }
2126 
2127 /**
2128  * ice_vc_query_rxdid - query RXDID supported by DDP package
2129  * @vf: pointer to VF info
2130  *
2131  * Called from VF to query a bitmap of supported flexible
2132  * descriptor RXDIDs of a DDP package.
2133  */
2134 static int ice_vc_query_rxdid(struct ice_vf *vf)
2135 {
2136 	enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
2137 	struct ice_pf *pf = vf->pf;
2138 	u64 rxdid;
2139 
2140 	if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
2141 		v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2142 		goto err;
2143 	}
2144 
2145 	if (!(vf->driver_caps & VIRTCHNL_VF_OFFLOAD_RX_FLEX_DESC)) {
2146 		v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2147 		goto err;
2148 	}
2149 
2150 	rxdid = pf->supported_rxdids;
2151 
2152 err:
2153 	return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_GET_SUPPORTED_RXDIDS,
2154 				     v_ret, (u8 *)&rxdid, sizeof(rxdid));
2155 }
2156 
2157 /**
2158  * ice_vf_init_vlan_stripping - enable/disable VLAN stripping on initialization
2159  * @vf: VF to enable/disable VLAN stripping for on initialization
2160  *
2161  * Set the default for VLAN stripping based on whether a port VLAN is configured
2162  * and the current VLAN mode of the device.
2163  */
2164 static int ice_vf_init_vlan_stripping(struct ice_vf *vf)
2165 {
2166 	struct ice_vsi *vsi = ice_get_vf_vsi(vf);
2167 
2168 	vf->vlan_strip_ena = 0;
2169 
2170 	if (!vsi)
2171 		return -EINVAL;
2172 
2173 	/* don't modify stripping if port VLAN is configured in SVM since the
2174 	 * port VLAN is based on the inner/single VLAN in SVM
2175 	 */
2176 	if (ice_vf_is_port_vlan_ena(vf) && !ice_is_dvm_ena(&vsi->back->hw))
2177 		return 0;
2178 
2179 	if (ice_vf_vlan_offload_ena(vf->driver_caps)) {
2180 		int err;
2181 
2182 		err = vsi->inner_vlan_ops.ena_stripping(vsi, ETH_P_8021Q);
2183 		if (!err)
2184 			vf->vlan_strip_ena |= ICE_INNER_VLAN_STRIP_ENA;
2185 		return err;
2186 	}
2187 
2188 	return vsi->inner_vlan_ops.dis_stripping(vsi);
2189 }
2190 
2191 static u16 ice_vc_get_max_vlan_fltrs(struct ice_vf *vf)
2192 {
2193 	if (vf->trusted)
2194 		return VLAN_N_VID;
2195 	else
2196 		return ICE_MAX_VLAN_PER_VF;
2197 }
2198 
2199 /**
2200  * ice_vf_outer_vlan_not_allowed - check if outer VLAN can be used
2201  * @vf: VF that being checked for
2202  *
2203  * When the device is in double VLAN mode, check whether or not the outer VLAN
2204  * is allowed.
2205  */
2206 static bool ice_vf_outer_vlan_not_allowed(struct ice_vf *vf)
2207 {
2208 	if (ice_vf_is_port_vlan_ena(vf))
2209 		return true;
2210 
2211 	return false;
2212 }
2213 
2214 /**
2215  * ice_vc_set_dvm_caps - set VLAN capabilities when the device is in DVM
2216  * @vf: VF that capabilities are being set for
2217  * @caps: VLAN capabilities to populate
2218  *
2219  * Determine VLAN capabilities support based on whether a port VLAN is
2220  * configured. If a port VLAN is configured then the VF should use the inner
2221  * filtering/offload capabilities since the port VLAN is using the outer VLAN
2222  * capabilies.
2223  */
2224 static void
2225 ice_vc_set_dvm_caps(struct ice_vf *vf, struct virtchnl_vlan_caps *caps)
2226 {
2227 	struct virtchnl_vlan_supported_caps *supported_caps;
2228 
2229 	if (ice_vf_outer_vlan_not_allowed(vf)) {
2230 		/* until support for inner VLAN filtering is added when a port
2231 		 * VLAN is configured, only support software offloaded inner
2232 		 * VLANs when a port VLAN is confgured in DVM
2233 		 */
2234 		supported_caps = &caps->filtering.filtering_support;
2235 		supported_caps->inner = VIRTCHNL_VLAN_UNSUPPORTED;
2236 
2237 		supported_caps = &caps->offloads.stripping_support;
2238 		supported_caps->inner = VIRTCHNL_VLAN_ETHERTYPE_8100 |
2239 					VIRTCHNL_VLAN_TOGGLE |
2240 					VIRTCHNL_VLAN_TAG_LOCATION_L2TAG1;
2241 		supported_caps->outer = VIRTCHNL_VLAN_UNSUPPORTED;
2242 
2243 		supported_caps = &caps->offloads.insertion_support;
2244 		supported_caps->inner = VIRTCHNL_VLAN_ETHERTYPE_8100 |
2245 					VIRTCHNL_VLAN_TOGGLE |
2246 					VIRTCHNL_VLAN_TAG_LOCATION_L2TAG1;
2247 		supported_caps->outer = VIRTCHNL_VLAN_UNSUPPORTED;
2248 
2249 		caps->offloads.ethertype_init = VIRTCHNL_VLAN_ETHERTYPE_8100;
2250 		caps->offloads.ethertype_match =
2251 			VIRTCHNL_ETHERTYPE_STRIPPING_MATCHES_INSERTION;
2252 	} else {
2253 		supported_caps = &caps->filtering.filtering_support;
2254 		supported_caps->inner = VIRTCHNL_VLAN_UNSUPPORTED;
2255 		supported_caps->outer = VIRTCHNL_VLAN_ETHERTYPE_8100 |
2256 					VIRTCHNL_VLAN_ETHERTYPE_88A8 |
2257 					VIRTCHNL_VLAN_ETHERTYPE_9100 |
2258 					VIRTCHNL_VLAN_ETHERTYPE_AND;
2259 		caps->filtering.ethertype_init = VIRTCHNL_VLAN_ETHERTYPE_8100 |
2260 						 VIRTCHNL_VLAN_ETHERTYPE_88A8 |
2261 						 VIRTCHNL_VLAN_ETHERTYPE_9100;
2262 
2263 		supported_caps = &caps->offloads.stripping_support;
2264 		supported_caps->inner = VIRTCHNL_VLAN_TOGGLE |
2265 					VIRTCHNL_VLAN_ETHERTYPE_8100 |
2266 					VIRTCHNL_VLAN_TAG_LOCATION_L2TAG1;
2267 		supported_caps->outer = VIRTCHNL_VLAN_TOGGLE |
2268 					VIRTCHNL_VLAN_ETHERTYPE_8100 |
2269 					VIRTCHNL_VLAN_ETHERTYPE_88A8 |
2270 					VIRTCHNL_VLAN_ETHERTYPE_9100 |
2271 					VIRTCHNL_VLAN_ETHERTYPE_XOR |
2272 					VIRTCHNL_VLAN_TAG_LOCATION_L2TAG2_2;
2273 
2274 		supported_caps = &caps->offloads.insertion_support;
2275 		supported_caps->inner = VIRTCHNL_VLAN_TOGGLE |
2276 					VIRTCHNL_VLAN_ETHERTYPE_8100 |
2277 					VIRTCHNL_VLAN_TAG_LOCATION_L2TAG1;
2278 		supported_caps->outer = VIRTCHNL_VLAN_TOGGLE |
2279 					VIRTCHNL_VLAN_ETHERTYPE_8100 |
2280 					VIRTCHNL_VLAN_ETHERTYPE_88A8 |
2281 					VIRTCHNL_VLAN_ETHERTYPE_9100 |
2282 					VIRTCHNL_VLAN_ETHERTYPE_XOR |
2283 					VIRTCHNL_VLAN_TAG_LOCATION_L2TAG2;
2284 
2285 		caps->offloads.ethertype_init = VIRTCHNL_VLAN_ETHERTYPE_8100;
2286 
2287 		caps->offloads.ethertype_match =
2288 			VIRTCHNL_ETHERTYPE_STRIPPING_MATCHES_INSERTION;
2289 	}
2290 
2291 	caps->filtering.max_filters = ice_vc_get_max_vlan_fltrs(vf);
2292 }
2293 
2294 /**
2295  * ice_vc_set_svm_caps - set VLAN capabilities when the device is in SVM
2296  * @vf: VF that capabilities are being set for
2297  * @caps: VLAN capabilities to populate
2298  *
2299  * Determine VLAN capabilities support based on whether a port VLAN is
2300  * configured. If a port VLAN is configured then the VF does not have any VLAN
2301  * filtering or offload capabilities since the port VLAN is using the inner VLAN
2302  * capabilities in single VLAN mode (SVM). Otherwise allow the VF to use inner
2303  * VLAN fitlering and offload capabilities.
2304  */
2305 static void
2306 ice_vc_set_svm_caps(struct ice_vf *vf, struct virtchnl_vlan_caps *caps)
2307 {
2308 	struct virtchnl_vlan_supported_caps *supported_caps;
2309 
2310 	if (ice_vf_is_port_vlan_ena(vf)) {
2311 		supported_caps = &caps->filtering.filtering_support;
2312 		supported_caps->inner = VIRTCHNL_VLAN_UNSUPPORTED;
2313 		supported_caps->outer = VIRTCHNL_VLAN_UNSUPPORTED;
2314 
2315 		supported_caps = &caps->offloads.stripping_support;
2316 		supported_caps->inner = VIRTCHNL_VLAN_UNSUPPORTED;
2317 		supported_caps->outer = VIRTCHNL_VLAN_UNSUPPORTED;
2318 
2319 		supported_caps = &caps->offloads.insertion_support;
2320 		supported_caps->inner = VIRTCHNL_VLAN_UNSUPPORTED;
2321 		supported_caps->outer = VIRTCHNL_VLAN_UNSUPPORTED;
2322 
2323 		caps->offloads.ethertype_init = VIRTCHNL_VLAN_UNSUPPORTED;
2324 		caps->offloads.ethertype_match = VIRTCHNL_VLAN_UNSUPPORTED;
2325 		caps->filtering.max_filters = 0;
2326 	} else {
2327 		supported_caps = &caps->filtering.filtering_support;
2328 		supported_caps->inner = VIRTCHNL_VLAN_ETHERTYPE_8100;
2329 		supported_caps->outer = VIRTCHNL_VLAN_UNSUPPORTED;
2330 		caps->filtering.ethertype_init = VIRTCHNL_VLAN_ETHERTYPE_8100;
2331 
2332 		supported_caps = &caps->offloads.stripping_support;
2333 		supported_caps->inner = VIRTCHNL_VLAN_ETHERTYPE_8100 |
2334 					VIRTCHNL_VLAN_TOGGLE |
2335 					VIRTCHNL_VLAN_TAG_LOCATION_L2TAG1;
2336 		supported_caps->outer = VIRTCHNL_VLAN_UNSUPPORTED;
2337 
2338 		supported_caps = &caps->offloads.insertion_support;
2339 		supported_caps->inner = VIRTCHNL_VLAN_ETHERTYPE_8100 |
2340 					VIRTCHNL_VLAN_TOGGLE |
2341 					VIRTCHNL_VLAN_TAG_LOCATION_L2TAG1;
2342 		supported_caps->outer = VIRTCHNL_VLAN_UNSUPPORTED;
2343 
2344 		caps->offloads.ethertype_init = VIRTCHNL_VLAN_ETHERTYPE_8100;
2345 		caps->offloads.ethertype_match =
2346 			VIRTCHNL_ETHERTYPE_STRIPPING_MATCHES_INSERTION;
2347 		caps->filtering.max_filters = ice_vc_get_max_vlan_fltrs(vf);
2348 	}
2349 }
2350 
2351 /**
2352  * ice_vc_get_offload_vlan_v2_caps - determine VF's VLAN capabilities
2353  * @vf: VF to determine VLAN capabilities for
2354  *
2355  * This will only be called if the VF and PF successfully negotiated
2356  * VIRTCHNL_VF_OFFLOAD_VLAN_V2.
2357  *
2358  * Set VLAN capabilities based on the current VLAN mode and whether a port VLAN
2359  * is configured or not.
2360  */
2361 static int ice_vc_get_offload_vlan_v2_caps(struct ice_vf *vf)
2362 {
2363 	enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
2364 	struct virtchnl_vlan_caps *caps = NULL;
2365 	int err, len = 0;
2366 
2367 	if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
2368 		v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2369 		goto out;
2370 	}
2371 
2372 	caps = kzalloc(sizeof(*caps), GFP_KERNEL);
2373 	if (!caps) {
2374 		v_ret = VIRTCHNL_STATUS_ERR_NO_MEMORY;
2375 		goto out;
2376 	}
2377 	len = sizeof(*caps);
2378 
2379 	if (ice_is_dvm_ena(&vf->pf->hw))
2380 		ice_vc_set_dvm_caps(vf, caps);
2381 	else
2382 		ice_vc_set_svm_caps(vf, caps);
2383 
2384 	/* store negotiated caps to prevent invalid VF messages */
2385 	memcpy(&vf->vlan_v2_caps, caps, sizeof(*caps));
2386 
2387 out:
2388 	err = ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS,
2389 				    v_ret, (u8 *)caps, len);
2390 	kfree(caps);
2391 	return err;
2392 }
2393 
2394 /**
2395  * ice_vc_validate_vlan_tpid - validate VLAN TPID
2396  * @filtering_caps: negotiated/supported VLAN filtering capabilities
2397  * @tpid: VLAN TPID used for validation
2398  *
2399  * Convert the VLAN TPID to a VIRTCHNL_VLAN_ETHERTYPE_* and then compare against
2400  * the negotiated/supported filtering caps to see if the VLAN TPID is valid.
2401  */
2402 static bool ice_vc_validate_vlan_tpid(u16 filtering_caps, u16 tpid)
2403 {
2404 	enum virtchnl_vlan_support vlan_ethertype = VIRTCHNL_VLAN_UNSUPPORTED;
2405 
2406 	switch (tpid) {
2407 	case ETH_P_8021Q:
2408 		vlan_ethertype = VIRTCHNL_VLAN_ETHERTYPE_8100;
2409 		break;
2410 	case ETH_P_8021AD:
2411 		vlan_ethertype = VIRTCHNL_VLAN_ETHERTYPE_88A8;
2412 		break;
2413 	case ETH_P_QINQ1:
2414 		vlan_ethertype = VIRTCHNL_VLAN_ETHERTYPE_9100;
2415 		break;
2416 	}
2417 
2418 	if (!(filtering_caps & vlan_ethertype))
2419 		return false;
2420 
2421 	return true;
2422 }
2423 
2424 /**
2425  * ice_vc_is_valid_vlan - validate the virtchnl_vlan
2426  * @vc_vlan: virtchnl_vlan to validate
2427  *
2428  * If the VLAN TCI and VLAN TPID are 0, then this filter is invalid, so return
2429  * false. Otherwise return true.
2430  */
2431 static bool ice_vc_is_valid_vlan(struct virtchnl_vlan *vc_vlan)
2432 {
2433 	if (!vc_vlan->tci || !vc_vlan->tpid)
2434 		return false;
2435 
2436 	return true;
2437 }
2438 
2439 /**
2440  * ice_vc_validate_vlan_filter_list - validate the filter list from the VF
2441  * @vfc: negotiated/supported VLAN filtering capabilities
2442  * @vfl: VLAN filter list from VF to validate
2443  *
2444  * Validate all of the filters in the VLAN filter list from the VF. If any of
2445  * the checks fail then return false. Otherwise return true.
2446  */
2447 static bool
2448 ice_vc_validate_vlan_filter_list(struct virtchnl_vlan_filtering_caps *vfc,
2449 				 struct virtchnl_vlan_filter_list_v2 *vfl)
2450 {
2451 	u16 i;
2452 
2453 	if (!vfl->num_elements)
2454 		return false;
2455 
2456 	for (i = 0; i < vfl->num_elements; i++) {
2457 		struct virtchnl_vlan_supported_caps *filtering_support =
2458 			&vfc->filtering_support;
2459 		struct virtchnl_vlan_filter *vlan_fltr = &vfl->filters[i];
2460 		struct virtchnl_vlan *outer = &vlan_fltr->outer;
2461 		struct virtchnl_vlan *inner = &vlan_fltr->inner;
2462 
2463 		if ((ice_vc_is_valid_vlan(outer) &&
2464 		     filtering_support->outer == VIRTCHNL_VLAN_UNSUPPORTED) ||
2465 		    (ice_vc_is_valid_vlan(inner) &&
2466 		     filtering_support->inner == VIRTCHNL_VLAN_UNSUPPORTED))
2467 			return false;
2468 
2469 		if ((outer->tci_mask &&
2470 		     !(filtering_support->outer & VIRTCHNL_VLAN_FILTER_MASK)) ||
2471 		    (inner->tci_mask &&
2472 		     !(filtering_support->inner & VIRTCHNL_VLAN_FILTER_MASK)))
2473 			return false;
2474 
2475 		if (((outer->tci & VLAN_PRIO_MASK) &&
2476 		     !(filtering_support->outer & VIRTCHNL_VLAN_PRIO)) ||
2477 		    ((inner->tci & VLAN_PRIO_MASK) &&
2478 		     !(filtering_support->inner & VIRTCHNL_VLAN_PRIO)))
2479 			return false;
2480 
2481 		if ((ice_vc_is_valid_vlan(outer) &&
2482 		     !ice_vc_validate_vlan_tpid(filtering_support->outer,
2483 						outer->tpid)) ||
2484 		    (ice_vc_is_valid_vlan(inner) &&
2485 		     !ice_vc_validate_vlan_tpid(filtering_support->inner,
2486 						inner->tpid)))
2487 			return false;
2488 	}
2489 
2490 	return true;
2491 }
2492 
2493 /**
2494  * ice_vc_to_vlan - transform from struct virtchnl_vlan to struct ice_vlan
2495  * @vc_vlan: struct virtchnl_vlan to transform
2496  */
2497 static struct ice_vlan ice_vc_to_vlan(struct virtchnl_vlan *vc_vlan)
2498 {
2499 	struct ice_vlan vlan = { 0 };
2500 
2501 	vlan.prio = FIELD_GET(VLAN_PRIO_MASK, vc_vlan->tci);
2502 	vlan.vid = vc_vlan->tci & VLAN_VID_MASK;
2503 	vlan.tpid = vc_vlan->tpid;
2504 
2505 	return vlan;
2506 }
2507 
2508 /**
2509  * ice_vc_vlan_action - action to perform on the virthcnl_vlan
2510  * @vsi: VF's VSI used to perform the action
2511  * @vlan_action: function to perform the action with (i.e. add/del)
2512  * @vlan: VLAN filter to perform the action with
2513  */
2514 static int
2515 ice_vc_vlan_action(struct ice_vsi *vsi,
2516 		   int (*vlan_action)(struct ice_vsi *, struct ice_vlan *),
2517 		   struct ice_vlan *vlan)
2518 {
2519 	int err;
2520 
2521 	err = vlan_action(vsi, vlan);
2522 	if (err)
2523 		return err;
2524 
2525 	return 0;
2526 }
2527 
2528 /**
2529  * ice_vc_del_vlans - delete VLAN(s) from the virtchnl filter list
2530  * @vf: VF used to delete the VLAN(s)
2531  * @vsi: VF's VSI used to delete the VLAN(s)
2532  * @vfl: virthchnl filter list used to delete the filters
2533  */
2534 static int
2535 ice_vc_del_vlans(struct ice_vf *vf, struct ice_vsi *vsi,
2536 		 struct virtchnl_vlan_filter_list_v2 *vfl)
2537 {
2538 	bool vlan_promisc = ice_is_vlan_promisc_allowed(vf);
2539 	int err;
2540 	u16 i;
2541 
2542 	for (i = 0; i < vfl->num_elements; i++) {
2543 		struct virtchnl_vlan_filter *vlan_fltr = &vfl->filters[i];
2544 		struct virtchnl_vlan *vc_vlan;
2545 
2546 		vc_vlan = &vlan_fltr->outer;
2547 		if (ice_vc_is_valid_vlan(vc_vlan)) {
2548 			struct ice_vlan vlan = ice_vc_to_vlan(vc_vlan);
2549 
2550 			err = ice_vc_vlan_action(vsi,
2551 						 vsi->outer_vlan_ops.del_vlan,
2552 						 &vlan);
2553 			if (err)
2554 				return err;
2555 
2556 			if (vlan_promisc)
2557 				ice_vf_dis_vlan_promisc(vsi, &vlan);
2558 
2559 			/* Disable VLAN filtering when only VLAN 0 is left */
2560 			if (!ice_vsi_has_non_zero_vlans(vsi) && ice_is_dvm_ena(&vsi->back->hw)) {
2561 				err = vsi->outer_vlan_ops.dis_tx_filtering(vsi);
2562 				if (err)
2563 					return err;
2564 			}
2565 		}
2566 
2567 		vc_vlan = &vlan_fltr->inner;
2568 		if (ice_vc_is_valid_vlan(vc_vlan)) {
2569 			struct ice_vlan vlan = ice_vc_to_vlan(vc_vlan);
2570 
2571 			err = ice_vc_vlan_action(vsi,
2572 						 vsi->inner_vlan_ops.del_vlan,
2573 						 &vlan);
2574 			if (err)
2575 				return err;
2576 
2577 			/* no support for VLAN promiscuous on inner VLAN unless
2578 			 * we are in Single VLAN Mode (SVM)
2579 			 */
2580 			if (!ice_is_dvm_ena(&vsi->back->hw)) {
2581 				if (vlan_promisc)
2582 					ice_vf_dis_vlan_promisc(vsi, &vlan);
2583 
2584 				/* Disable VLAN filtering when only VLAN 0 is left */
2585 				if (!ice_vsi_has_non_zero_vlans(vsi)) {
2586 					err = vsi->inner_vlan_ops.dis_tx_filtering(vsi);
2587 					if (err)
2588 						return err;
2589 				}
2590 			}
2591 		}
2592 	}
2593 
2594 	return 0;
2595 }
2596 
2597 /**
2598  * ice_vc_remove_vlan_v2_msg - virtchnl handler for VIRTCHNL_OP_DEL_VLAN_V2
2599  * @vf: VF the message was received from
2600  * @msg: message received from the VF
2601  */
2602 static int ice_vc_remove_vlan_v2_msg(struct ice_vf *vf, u8 *msg)
2603 {
2604 	struct virtchnl_vlan_filter_list_v2 *vfl =
2605 		(struct virtchnl_vlan_filter_list_v2 *)msg;
2606 	enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
2607 	struct ice_vsi *vsi;
2608 
2609 	if (!ice_vc_validate_vlan_filter_list(&vf->vlan_v2_caps.filtering,
2610 					      vfl)) {
2611 		v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2612 		goto out;
2613 	}
2614 
2615 	if (!ice_vc_isvalid_vsi_id(vf, vfl->vport_id)) {
2616 		v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2617 		goto out;
2618 	}
2619 
2620 	vsi = ice_get_vf_vsi(vf);
2621 	if (!vsi) {
2622 		v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2623 		goto out;
2624 	}
2625 
2626 	if (ice_vc_del_vlans(vf, vsi, vfl))
2627 		v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2628 
2629 out:
2630 	return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_DEL_VLAN_V2, v_ret, NULL,
2631 				     0);
2632 }
2633 
2634 /**
2635  * ice_vc_add_vlans - add VLAN(s) from the virtchnl filter list
2636  * @vf: VF used to add the VLAN(s)
2637  * @vsi: VF's VSI used to add the VLAN(s)
2638  * @vfl: virthchnl filter list used to add the filters
2639  */
2640 static int
2641 ice_vc_add_vlans(struct ice_vf *vf, struct ice_vsi *vsi,
2642 		 struct virtchnl_vlan_filter_list_v2 *vfl)
2643 {
2644 	bool vlan_promisc = ice_is_vlan_promisc_allowed(vf);
2645 	int err;
2646 	u16 i;
2647 
2648 	for (i = 0; i < vfl->num_elements; i++) {
2649 		struct virtchnl_vlan_filter *vlan_fltr = &vfl->filters[i];
2650 		struct virtchnl_vlan *vc_vlan;
2651 
2652 		vc_vlan = &vlan_fltr->outer;
2653 		if (ice_vc_is_valid_vlan(vc_vlan)) {
2654 			struct ice_vlan vlan = ice_vc_to_vlan(vc_vlan);
2655 
2656 			err = ice_vc_vlan_action(vsi,
2657 						 vsi->outer_vlan_ops.add_vlan,
2658 						 &vlan);
2659 			if (err)
2660 				return err;
2661 
2662 			if (vlan_promisc) {
2663 				err = ice_vf_ena_vlan_promisc(vf, vsi, &vlan);
2664 				if (err)
2665 					return err;
2666 			}
2667 
2668 			/* Enable VLAN filtering on first non-zero VLAN */
2669 			if (vf->spoofchk && vlan.vid && ice_is_dvm_ena(&vsi->back->hw)) {
2670 				err = vsi->outer_vlan_ops.ena_tx_filtering(vsi);
2671 				if (err)
2672 					return err;
2673 			}
2674 		}
2675 
2676 		vc_vlan = &vlan_fltr->inner;
2677 		if (ice_vc_is_valid_vlan(vc_vlan)) {
2678 			struct ice_vlan vlan = ice_vc_to_vlan(vc_vlan);
2679 
2680 			err = ice_vc_vlan_action(vsi,
2681 						 vsi->inner_vlan_ops.add_vlan,
2682 						 &vlan);
2683 			if (err)
2684 				return err;
2685 
2686 			/* no support for VLAN promiscuous on inner VLAN unless
2687 			 * we are in Single VLAN Mode (SVM)
2688 			 */
2689 			if (!ice_is_dvm_ena(&vsi->back->hw)) {
2690 				if (vlan_promisc) {
2691 					err = ice_vf_ena_vlan_promisc(vf, vsi,
2692 								      &vlan);
2693 					if (err)
2694 						return err;
2695 				}
2696 
2697 				/* Enable VLAN filtering on first non-zero VLAN */
2698 				if (vf->spoofchk && vlan.vid) {
2699 					err = vsi->inner_vlan_ops.ena_tx_filtering(vsi);
2700 					if (err)
2701 						return err;
2702 				}
2703 			}
2704 		}
2705 	}
2706 
2707 	return 0;
2708 }
2709 
2710 /**
2711  * ice_vc_validate_add_vlan_filter_list - validate add filter list from the VF
2712  * @vsi: VF VSI used to get number of existing VLAN filters
2713  * @vfc: negotiated/supported VLAN filtering capabilities
2714  * @vfl: VLAN filter list from VF to validate
2715  *
2716  * Validate all of the filters in the VLAN filter list from the VF during the
2717  * VIRTCHNL_OP_ADD_VLAN_V2 opcode. If any of the checks fail then return false.
2718  * Otherwise return true.
2719  */
2720 static bool
2721 ice_vc_validate_add_vlan_filter_list(struct ice_vsi *vsi,
2722 				     struct virtchnl_vlan_filtering_caps *vfc,
2723 				     struct virtchnl_vlan_filter_list_v2 *vfl)
2724 {
2725 	u16 num_requested_filters = ice_vsi_num_non_zero_vlans(vsi) +
2726 		vfl->num_elements;
2727 
2728 	if (num_requested_filters > vfc->max_filters)
2729 		return false;
2730 
2731 	return ice_vc_validate_vlan_filter_list(vfc, vfl);
2732 }
2733 
2734 /**
2735  * ice_vc_add_vlan_v2_msg - virtchnl handler for VIRTCHNL_OP_ADD_VLAN_V2
2736  * @vf: VF the message was received from
2737  * @msg: message received from the VF
2738  */
2739 static int ice_vc_add_vlan_v2_msg(struct ice_vf *vf, u8 *msg)
2740 {
2741 	enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
2742 	struct virtchnl_vlan_filter_list_v2 *vfl =
2743 		(struct virtchnl_vlan_filter_list_v2 *)msg;
2744 	struct ice_vsi *vsi;
2745 
2746 	if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
2747 		v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2748 		goto out;
2749 	}
2750 
2751 	if (!ice_vc_isvalid_vsi_id(vf, vfl->vport_id)) {
2752 		v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2753 		goto out;
2754 	}
2755 
2756 	vsi = ice_get_vf_vsi(vf);
2757 	if (!vsi) {
2758 		v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2759 		goto out;
2760 	}
2761 
2762 	if (!ice_vc_validate_add_vlan_filter_list(vsi,
2763 						  &vf->vlan_v2_caps.filtering,
2764 						  vfl)) {
2765 		v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2766 		goto out;
2767 	}
2768 
2769 	if (ice_vc_add_vlans(vf, vsi, vfl))
2770 		v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2771 
2772 out:
2773 	return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_ADD_VLAN_V2, v_ret, NULL,
2774 				     0);
2775 }
2776 
2777 /**
2778  * ice_vc_valid_vlan_setting - validate VLAN setting
2779  * @negotiated_settings: negotiated VLAN settings during VF init
2780  * @ethertype_setting: ethertype(s) requested for the VLAN setting
2781  */
2782 static bool
2783 ice_vc_valid_vlan_setting(u32 negotiated_settings, u32 ethertype_setting)
2784 {
2785 	if (ethertype_setting && !(negotiated_settings & ethertype_setting))
2786 		return false;
2787 
2788 	/* only allow a single VIRTCHNL_VLAN_ETHERTYPE if
2789 	 * VIRTHCNL_VLAN_ETHERTYPE_AND is not negotiated/supported
2790 	 */
2791 	if (!(negotiated_settings & VIRTCHNL_VLAN_ETHERTYPE_AND) &&
2792 	    hweight32(ethertype_setting) > 1)
2793 		return false;
2794 
2795 	/* ability to modify the VLAN setting was not negotiated */
2796 	if (!(negotiated_settings & VIRTCHNL_VLAN_TOGGLE))
2797 		return false;
2798 
2799 	return true;
2800 }
2801 
2802 /**
2803  * ice_vc_valid_vlan_setting_msg - validate the VLAN setting message
2804  * @caps: negotiated VLAN settings during VF init
2805  * @msg: message to validate
2806  *
2807  * Used to validate any VLAN virtchnl message sent as a
2808  * virtchnl_vlan_setting structure. Validates the message against the
2809  * negotiated/supported caps during VF driver init.
2810  */
2811 static bool
2812 ice_vc_valid_vlan_setting_msg(struct virtchnl_vlan_supported_caps *caps,
2813 			      struct virtchnl_vlan_setting *msg)
2814 {
2815 	if ((!msg->outer_ethertype_setting &&
2816 	     !msg->inner_ethertype_setting) ||
2817 	    (!caps->outer && !caps->inner))
2818 		return false;
2819 
2820 	if (msg->outer_ethertype_setting &&
2821 	    !ice_vc_valid_vlan_setting(caps->outer,
2822 				       msg->outer_ethertype_setting))
2823 		return false;
2824 
2825 	if (msg->inner_ethertype_setting &&
2826 	    !ice_vc_valid_vlan_setting(caps->inner,
2827 				       msg->inner_ethertype_setting))
2828 		return false;
2829 
2830 	return true;
2831 }
2832 
2833 /**
2834  * ice_vc_get_tpid - transform from VIRTCHNL_VLAN_ETHERTYPE_* to VLAN TPID
2835  * @ethertype_setting: VIRTCHNL_VLAN_ETHERTYPE_* used to get VLAN TPID
2836  * @tpid: VLAN TPID to populate
2837  */
2838 static int ice_vc_get_tpid(u32 ethertype_setting, u16 *tpid)
2839 {
2840 	switch (ethertype_setting) {
2841 	case VIRTCHNL_VLAN_ETHERTYPE_8100:
2842 		*tpid = ETH_P_8021Q;
2843 		break;
2844 	case VIRTCHNL_VLAN_ETHERTYPE_88A8:
2845 		*tpid = ETH_P_8021AD;
2846 		break;
2847 	case VIRTCHNL_VLAN_ETHERTYPE_9100:
2848 		*tpid = ETH_P_QINQ1;
2849 		break;
2850 	default:
2851 		*tpid = 0;
2852 		return -EINVAL;
2853 	}
2854 
2855 	return 0;
2856 }
2857 
2858 /**
2859  * ice_vc_ena_vlan_offload - enable VLAN offload based on the ethertype_setting
2860  * @vsi: VF's VSI used to enable the VLAN offload
2861  * @ena_offload: function used to enable the VLAN offload
2862  * @ethertype_setting: VIRTCHNL_VLAN_ETHERTYPE_* to enable offloads for
2863  */
2864 static int
2865 ice_vc_ena_vlan_offload(struct ice_vsi *vsi,
2866 			int (*ena_offload)(struct ice_vsi *vsi, u16 tpid),
2867 			u32 ethertype_setting)
2868 {
2869 	u16 tpid;
2870 	int err;
2871 
2872 	err = ice_vc_get_tpid(ethertype_setting, &tpid);
2873 	if (err)
2874 		return err;
2875 
2876 	err = ena_offload(vsi, tpid);
2877 	if (err)
2878 		return err;
2879 
2880 	return 0;
2881 }
2882 
2883 /**
2884  * ice_vc_ena_vlan_stripping_v2_msg
2885  * @vf: VF the message was received from
2886  * @msg: message received from the VF
2887  *
2888  * virthcnl handler for VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2
2889  */
2890 static int ice_vc_ena_vlan_stripping_v2_msg(struct ice_vf *vf, u8 *msg)
2891 {
2892 	enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
2893 	struct virtchnl_vlan_supported_caps *stripping_support;
2894 	struct virtchnl_vlan_setting *strip_msg =
2895 		(struct virtchnl_vlan_setting *)msg;
2896 	u32 ethertype_setting;
2897 	struct ice_vsi *vsi;
2898 
2899 	if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
2900 		v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2901 		goto out;
2902 	}
2903 
2904 	if (!ice_vc_isvalid_vsi_id(vf, strip_msg->vport_id)) {
2905 		v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2906 		goto out;
2907 	}
2908 
2909 	vsi = ice_get_vf_vsi(vf);
2910 	if (!vsi) {
2911 		v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2912 		goto out;
2913 	}
2914 
2915 	stripping_support = &vf->vlan_v2_caps.offloads.stripping_support;
2916 	if (!ice_vc_valid_vlan_setting_msg(stripping_support, strip_msg)) {
2917 		v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2918 		goto out;
2919 	}
2920 
2921 	if (ice_vsi_is_rxq_crc_strip_dis(vsi)) {
2922 		v_ret = VIRTCHNL_STATUS_ERR_NOT_SUPPORTED;
2923 		goto out;
2924 	}
2925 
2926 	ethertype_setting = strip_msg->outer_ethertype_setting;
2927 	if (ethertype_setting) {
2928 		if (ice_vc_ena_vlan_offload(vsi,
2929 					    vsi->outer_vlan_ops.ena_stripping,
2930 					    ethertype_setting)) {
2931 			v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2932 			goto out;
2933 		} else {
2934 			enum ice_l2tsel l2tsel =
2935 				ICE_L2TSEL_EXTRACT_FIRST_TAG_L2TAG2_2ND;
2936 
2937 			/* PF tells the VF that the outer VLAN tag is always
2938 			 * extracted to VIRTCHNL_VLAN_TAG_LOCATION_L2TAG2_2 and
2939 			 * inner is always extracted to
2940 			 * VIRTCHNL_VLAN_TAG_LOCATION_L2TAG1. This is needed to
2941 			 * support outer stripping so the first tag always ends
2942 			 * up in L2TAG2_2ND and the second/inner tag, if
2943 			 * enabled, is extracted in L2TAG1.
2944 			 */
2945 			ice_vsi_update_l2tsel(vsi, l2tsel);
2946 
2947 			vf->vlan_strip_ena |= ICE_OUTER_VLAN_STRIP_ENA;
2948 		}
2949 	}
2950 
2951 	ethertype_setting = strip_msg->inner_ethertype_setting;
2952 	if (ethertype_setting &&
2953 	    ice_vc_ena_vlan_offload(vsi, vsi->inner_vlan_ops.ena_stripping,
2954 				    ethertype_setting)) {
2955 		v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2956 		goto out;
2957 	}
2958 
2959 	if (ethertype_setting)
2960 		vf->vlan_strip_ena |= ICE_INNER_VLAN_STRIP_ENA;
2961 
2962 out:
2963 	return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2,
2964 				     v_ret, NULL, 0);
2965 }
2966 
2967 /**
2968  * ice_vc_dis_vlan_stripping_v2_msg
2969  * @vf: VF the message was received from
2970  * @msg: message received from the VF
2971  *
2972  * virthcnl handler for VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2
2973  */
2974 static int ice_vc_dis_vlan_stripping_v2_msg(struct ice_vf *vf, u8 *msg)
2975 {
2976 	enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
2977 	struct virtchnl_vlan_supported_caps *stripping_support;
2978 	struct virtchnl_vlan_setting *strip_msg =
2979 		(struct virtchnl_vlan_setting *)msg;
2980 	u32 ethertype_setting;
2981 	struct ice_vsi *vsi;
2982 
2983 	if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
2984 		v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2985 		goto out;
2986 	}
2987 
2988 	if (!ice_vc_isvalid_vsi_id(vf, strip_msg->vport_id)) {
2989 		v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2990 		goto out;
2991 	}
2992 
2993 	vsi = ice_get_vf_vsi(vf);
2994 	if (!vsi) {
2995 		v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2996 		goto out;
2997 	}
2998 
2999 	stripping_support = &vf->vlan_v2_caps.offloads.stripping_support;
3000 	if (!ice_vc_valid_vlan_setting_msg(stripping_support, strip_msg)) {
3001 		v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3002 		goto out;
3003 	}
3004 
3005 	ethertype_setting = strip_msg->outer_ethertype_setting;
3006 	if (ethertype_setting) {
3007 		if (vsi->outer_vlan_ops.dis_stripping(vsi)) {
3008 			v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3009 			goto out;
3010 		} else {
3011 			enum ice_l2tsel l2tsel =
3012 				ICE_L2TSEL_EXTRACT_FIRST_TAG_L2TAG1;
3013 
3014 			/* PF tells the VF that the outer VLAN tag is always
3015 			 * extracted to VIRTCHNL_VLAN_TAG_LOCATION_L2TAG2_2 and
3016 			 * inner is always extracted to
3017 			 * VIRTCHNL_VLAN_TAG_LOCATION_L2TAG1. This is needed to
3018 			 * support inner stripping while outer stripping is
3019 			 * disabled so that the first and only tag is extracted
3020 			 * in L2TAG1.
3021 			 */
3022 			ice_vsi_update_l2tsel(vsi, l2tsel);
3023 
3024 			vf->vlan_strip_ena &= ~ICE_OUTER_VLAN_STRIP_ENA;
3025 		}
3026 	}
3027 
3028 	ethertype_setting = strip_msg->inner_ethertype_setting;
3029 	if (ethertype_setting && vsi->inner_vlan_ops.dis_stripping(vsi)) {
3030 		v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3031 		goto out;
3032 	}
3033 
3034 	if (ethertype_setting)
3035 		vf->vlan_strip_ena &= ~ICE_INNER_VLAN_STRIP_ENA;
3036 
3037 out:
3038 	return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2,
3039 				     v_ret, NULL, 0);
3040 }
3041 
3042 /**
3043  * ice_vc_ena_vlan_insertion_v2_msg
3044  * @vf: VF the message was received from
3045  * @msg: message received from the VF
3046  *
3047  * virthcnl handler for VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2
3048  */
3049 static int ice_vc_ena_vlan_insertion_v2_msg(struct ice_vf *vf, u8 *msg)
3050 {
3051 	enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
3052 	struct virtchnl_vlan_supported_caps *insertion_support;
3053 	struct virtchnl_vlan_setting *insertion_msg =
3054 		(struct virtchnl_vlan_setting *)msg;
3055 	u32 ethertype_setting;
3056 	struct ice_vsi *vsi;
3057 
3058 	if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
3059 		v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3060 		goto out;
3061 	}
3062 
3063 	if (!ice_vc_isvalid_vsi_id(vf, insertion_msg->vport_id)) {
3064 		v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3065 		goto out;
3066 	}
3067 
3068 	vsi = ice_get_vf_vsi(vf);
3069 	if (!vsi) {
3070 		v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3071 		goto out;
3072 	}
3073 
3074 	insertion_support = &vf->vlan_v2_caps.offloads.insertion_support;
3075 	if (!ice_vc_valid_vlan_setting_msg(insertion_support, insertion_msg)) {
3076 		v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3077 		goto out;
3078 	}
3079 
3080 	ethertype_setting = insertion_msg->outer_ethertype_setting;
3081 	if (ethertype_setting &&
3082 	    ice_vc_ena_vlan_offload(vsi, vsi->outer_vlan_ops.ena_insertion,
3083 				    ethertype_setting)) {
3084 		v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3085 		goto out;
3086 	}
3087 
3088 	ethertype_setting = insertion_msg->inner_ethertype_setting;
3089 	if (ethertype_setting &&
3090 	    ice_vc_ena_vlan_offload(vsi, vsi->inner_vlan_ops.ena_insertion,
3091 				    ethertype_setting)) {
3092 		v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3093 		goto out;
3094 	}
3095 
3096 out:
3097 	return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2,
3098 				     v_ret, NULL, 0);
3099 }
3100 
3101 /**
3102  * ice_vc_dis_vlan_insertion_v2_msg
3103  * @vf: VF the message was received from
3104  * @msg: message received from the VF
3105  *
3106  * virthcnl handler for VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2
3107  */
3108 static int ice_vc_dis_vlan_insertion_v2_msg(struct ice_vf *vf, u8 *msg)
3109 {
3110 	enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
3111 	struct virtchnl_vlan_supported_caps *insertion_support;
3112 	struct virtchnl_vlan_setting *insertion_msg =
3113 		(struct virtchnl_vlan_setting *)msg;
3114 	u32 ethertype_setting;
3115 	struct ice_vsi *vsi;
3116 
3117 	if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
3118 		v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3119 		goto out;
3120 	}
3121 
3122 	if (!ice_vc_isvalid_vsi_id(vf, insertion_msg->vport_id)) {
3123 		v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3124 		goto out;
3125 	}
3126 
3127 	vsi = ice_get_vf_vsi(vf);
3128 	if (!vsi) {
3129 		v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3130 		goto out;
3131 	}
3132 
3133 	insertion_support = &vf->vlan_v2_caps.offloads.insertion_support;
3134 	if (!ice_vc_valid_vlan_setting_msg(insertion_support, insertion_msg)) {
3135 		v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3136 		goto out;
3137 	}
3138 
3139 	ethertype_setting = insertion_msg->outer_ethertype_setting;
3140 	if (ethertype_setting && vsi->outer_vlan_ops.dis_insertion(vsi)) {
3141 		v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3142 		goto out;
3143 	}
3144 
3145 	ethertype_setting = insertion_msg->inner_ethertype_setting;
3146 	if (ethertype_setting && vsi->inner_vlan_ops.dis_insertion(vsi)) {
3147 		v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3148 		goto out;
3149 	}
3150 
3151 out:
3152 	return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2,
3153 				     v_ret, NULL, 0);
3154 }
3155 
3156 static int ice_vc_get_ptp_cap(struct ice_vf *vf,
3157 			      const struct virtchnl_ptp_caps *msg)
3158 {
3159 	enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3160 	u32 caps = VIRTCHNL_1588_PTP_CAP_RX_TSTAMP |
3161 		   VIRTCHNL_1588_PTP_CAP_READ_PHC;
3162 
3163 	if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states))
3164 		goto err;
3165 
3166 	v_ret = VIRTCHNL_STATUS_SUCCESS;
3167 
3168 	if (msg->caps & caps)
3169 		vf->ptp_caps = caps;
3170 
3171 err:
3172 	/* send the response back to the VF */
3173 	return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_1588_PTP_GET_CAPS, v_ret,
3174 				     (u8 *)&vf->ptp_caps,
3175 				     sizeof(struct virtchnl_ptp_caps));
3176 }
3177 
3178 static int ice_vc_get_phc_time(struct ice_vf *vf)
3179 {
3180 	enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3181 	struct virtchnl_phc_time *phc_time = NULL;
3182 	struct ice_pf *pf = vf->pf;
3183 	u32 len = 0;
3184 	int ret;
3185 
3186 	if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states))
3187 		goto err;
3188 
3189 	v_ret = VIRTCHNL_STATUS_SUCCESS;
3190 
3191 	phc_time = kzalloc(sizeof(*phc_time), GFP_KERNEL);
3192 	if (!phc_time) {
3193 		v_ret = VIRTCHNL_STATUS_ERR_NO_MEMORY;
3194 		goto err;
3195 	}
3196 
3197 	len = sizeof(*phc_time);
3198 
3199 	phc_time->time = ice_ptp_read_src_clk_reg(pf, NULL);
3200 
3201 err:
3202 	/* send the response back to the VF */
3203 	ret = ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_1588_PTP_GET_TIME, v_ret,
3204 				    (u8 *)phc_time, len);
3205 	kfree(phc_time);
3206 	return ret;
3207 }
3208 
3209 static const struct ice_virtchnl_ops ice_virtchnl_dflt_ops = {
3210 	.get_ver_msg = ice_vc_get_ver_msg,
3211 	.get_vf_res_msg = ice_vc_get_vf_res_msg,
3212 	.reset_vf = ice_vc_reset_vf_msg,
3213 	.add_mac_addr_msg = ice_vc_add_mac_addr_msg,
3214 	.del_mac_addr_msg = ice_vc_del_mac_addr_msg,
3215 	.cfg_qs_msg = ice_vc_cfg_qs_msg,
3216 	.ena_qs_msg = ice_vc_ena_qs_msg,
3217 	.dis_qs_msg = ice_vc_dis_qs_msg,
3218 	.request_qs_msg = ice_vc_request_qs_msg,
3219 	.cfg_irq_map_msg = ice_vc_cfg_irq_map_msg,
3220 	.config_rss_key = ice_vc_config_rss_key,
3221 	.config_rss_lut = ice_vc_config_rss_lut,
3222 	.config_rss_hfunc = ice_vc_config_rss_hfunc,
3223 	.get_stats_msg = ice_vc_get_stats_msg,
3224 	.cfg_promiscuous_mode_msg = ice_vc_cfg_promiscuous_mode_msg,
3225 	.add_vlan_msg = ice_vc_add_vlan_msg,
3226 	.remove_vlan_msg = ice_vc_remove_vlan_msg,
3227 	.query_rxdid = ice_vc_query_rxdid,
3228 	.get_rss_hashcfg = ice_vc_get_rss_hashcfg,
3229 	.set_rss_hashcfg = ice_vc_set_rss_hashcfg,
3230 	.ena_vlan_stripping = ice_vc_ena_vlan_stripping,
3231 	.dis_vlan_stripping = ice_vc_dis_vlan_stripping,
3232 	.handle_rss_cfg_msg = ice_vc_handle_rss_cfg,
3233 	.add_fdir_fltr_msg = ice_vc_add_fdir_fltr,
3234 	.del_fdir_fltr_msg = ice_vc_del_fdir_fltr,
3235 	.get_offload_vlan_v2_caps = ice_vc_get_offload_vlan_v2_caps,
3236 	.add_vlan_v2_msg = ice_vc_add_vlan_v2_msg,
3237 	.remove_vlan_v2_msg = ice_vc_remove_vlan_v2_msg,
3238 	.ena_vlan_stripping_v2_msg = ice_vc_ena_vlan_stripping_v2_msg,
3239 	.dis_vlan_stripping_v2_msg = ice_vc_dis_vlan_stripping_v2_msg,
3240 	.ena_vlan_insertion_v2_msg = ice_vc_ena_vlan_insertion_v2_msg,
3241 	.dis_vlan_insertion_v2_msg = ice_vc_dis_vlan_insertion_v2_msg,
3242 	.get_qos_caps = ice_vc_get_qos_caps,
3243 	.cfg_q_bw = ice_vc_cfg_q_bw,
3244 	.cfg_q_quanta = ice_vc_cfg_q_quanta,
3245 	.get_ptp_cap = ice_vc_get_ptp_cap,
3246 	.get_phc_time = ice_vc_get_phc_time,
3247 	/* If you add a new op here please make sure to add it to
3248 	 * ice_virtchnl_repr_ops as well.
3249 	 */
3250 };
3251 
3252 /**
3253  * ice_virtchnl_set_dflt_ops - Switch to default virtchnl ops
3254  * @vf: the VF to switch ops
3255  */
3256 void ice_virtchnl_set_dflt_ops(struct ice_vf *vf)
3257 {
3258 	vf->virtchnl_ops = &ice_virtchnl_dflt_ops;
3259 }
3260 
3261 /**
3262  * ice_vc_repr_add_mac
3263  * @vf: pointer to VF
3264  * @msg: virtchannel message
3265  *
3266  * When port representors are created, we do not add MAC rule
3267  * to firmware, we store it so that PF could report same
3268  * MAC as VF.
3269  */
3270 static int ice_vc_repr_add_mac(struct ice_vf *vf, u8 *msg)
3271 {
3272 	enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
3273 	struct virtchnl_ether_addr_list *al =
3274 	    (struct virtchnl_ether_addr_list *)msg;
3275 	struct ice_vsi *vsi;
3276 	struct ice_pf *pf;
3277 	int i;
3278 
3279 	if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states) ||
3280 	    !ice_vc_isvalid_vsi_id(vf, al->vsi_id)) {
3281 		v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3282 		goto handle_mac_exit;
3283 	}
3284 
3285 	pf = vf->pf;
3286 
3287 	vsi = ice_get_vf_vsi(vf);
3288 	if (!vsi) {
3289 		v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3290 		goto handle_mac_exit;
3291 	}
3292 
3293 	for (i = 0; i < al->num_elements; i++) {
3294 		u8 *mac_addr = al->list[i].addr;
3295 
3296 		if (!is_unicast_ether_addr(mac_addr) ||
3297 		    ether_addr_equal(mac_addr, vf->hw_lan_addr))
3298 			continue;
3299 
3300 		if (vf->pf_set_mac) {
3301 			dev_err(ice_pf_to_dev(pf), "VF attempting to override administratively set MAC address\n");
3302 			v_ret = VIRTCHNL_STATUS_ERR_NOT_SUPPORTED;
3303 			goto handle_mac_exit;
3304 		}
3305 
3306 		ice_vfhw_mac_add(vf, &al->list[i]);
3307 		break;
3308 	}
3309 
3310 handle_mac_exit:
3311 	return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_ADD_ETH_ADDR,
3312 				     v_ret, NULL, 0);
3313 }
3314 
3315 /**
3316  * ice_vc_repr_del_mac - response with success for deleting MAC
3317  * @vf: pointer to VF
3318  * @msg: virtchannel message
3319  *
3320  * Respond with success to not break normal VF flow.
3321  * For legacy VF driver try to update cached MAC address.
3322  */
3323 static int
3324 ice_vc_repr_del_mac(struct ice_vf __always_unused *vf, u8 __always_unused *msg)
3325 {
3326 	struct virtchnl_ether_addr_list *al =
3327 		(struct virtchnl_ether_addr_list *)msg;
3328 
3329 	ice_update_legacy_cached_mac(vf, &al->list[0]);
3330 
3331 	return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_DEL_ETH_ADDR,
3332 				     VIRTCHNL_STATUS_SUCCESS, NULL, 0);
3333 }
3334 
3335 static int
3336 ice_vc_repr_cfg_promiscuous_mode(struct ice_vf *vf, u8 __always_unused *msg)
3337 {
3338 	dev_dbg(ice_pf_to_dev(vf->pf),
3339 		"Can't config promiscuous mode in switchdev mode for VF %d\n",
3340 		vf->vf_id);
3341 	return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE,
3342 				     VIRTCHNL_STATUS_ERR_NOT_SUPPORTED,
3343 				     NULL, 0);
3344 }
3345 
3346 static const struct ice_virtchnl_ops ice_virtchnl_repr_ops = {
3347 	.get_ver_msg = ice_vc_get_ver_msg,
3348 	.get_vf_res_msg = ice_vc_get_vf_res_msg,
3349 	.reset_vf = ice_vc_reset_vf_msg,
3350 	.add_mac_addr_msg = ice_vc_repr_add_mac,
3351 	.del_mac_addr_msg = ice_vc_repr_del_mac,
3352 	.cfg_qs_msg = ice_vc_cfg_qs_msg,
3353 	.ena_qs_msg = ice_vc_ena_qs_msg,
3354 	.dis_qs_msg = ice_vc_dis_qs_msg,
3355 	.request_qs_msg = ice_vc_request_qs_msg,
3356 	.cfg_irq_map_msg = ice_vc_cfg_irq_map_msg,
3357 	.config_rss_key = ice_vc_config_rss_key,
3358 	.config_rss_lut = ice_vc_config_rss_lut,
3359 	.config_rss_hfunc = ice_vc_config_rss_hfunc,
3360 	.get_stats_msg = ice_vc_get_stats_msg,
3361 	.cfg_promiscuous_mode_msg = ice_vc_repr_cfg_promiscuous_mode,
3362 	.add_vlan_msg = ice_vc_add_vlan_msg,
3363 	.remove_vlan_msg = ice_vc_remove_vlan_msg,
3364 	.query_rxdid = ice_vc_query_rxdid,
3365 	.get_rss_hashcfg = ice_vc_get_rss_hashcfg,
3366 	.set_rss_hashcfg = ice_vc_set_rss_hashcfg,
3367 	.ena_vlan_stripping = ice_vc_ena_vlan_stripping,
3368 	.dis_vlan_stripping = ice_vc_dis_vlan_stripping,
3369 	.handle_rss_cfg_msg = ice_vc_handle_rss_cfg,
3370 	.add_fdir_fltr_msg = ice_vc_add_fdir_fltr,
3371 	.del_fdir_fltr_msg = ice_vc_del_fdir_fltr,
3372 	.get_offload_vlan_v2_caps = ice_vc_get_offload_vlan_v2_caps,
3373 	.add_vlan_v2_msg = ice_vc_add_vlan_v2_msg,
3374 	.remove_vlan_v2_msg = ice_vc_remove_vlan_v2_msg,
3375 	.ena_vlan_stripping_v2_msg = ice_vc_ena_vlan_stripping_v2_msg,
3376 	.dis_vlan_stripping_v2_msg = ice_vc_dis_vlan_stripping_v2_msg,
3377 	.ena_vlan_insertion_v2_msg = ice_vc_ena_vlan_insertion_v2_msg,
3378 	.dis_vlan_insertion_v2_msg = ice_vc_dis_vlan_insertion_v2_msg,
3379 	.get_qos_caps = ice_vc_get_qos_caps,
3380 	.cfg_q_bw = ice_vc_cfg_q_bw,
3381 	.cfg_q_quanta = ice_vc_cfg_q_quanta,
3382 	.get_ptp_cap = ice_vc_get_ptp_cap,
3383 	.get_phc_time = ice_vc_get_phc_time,
3384 };
3385 
3386 /**
3387  * ice_virtchnl_set_repr_ops - Switch to representor virtchnl ops
3388  * @vf: the VF to switch ops
3389  */
3390 void ice_virtchnl_set_repr_ops(struct ice_vf *vf)
3391 {
3392 	vf->virtchnl_ops = &ice_virtchnl_repr_ops;
3393 }
3394 
3395 /**
3396  * ice_is_malicious_vf - check if this vf might be overflowing mailbox
3397  * @vf: the VF to check
3398  * @mbxdata: data about the state of the mailbox
3399  *
3400  * Detect if a given VF might be malicious and attempting to overflow the PF
3401  * mailbox. If so, log a warning message and ignore this event.
3402  */
3403 static bool
3404 ice_is_malicious_vf(struct ice_vf *vf, struct ice_mbx_data *mbxdata)
3405 {
3406 	bool report_malvf = false;
3407 	struct device *dev;
3408 	struct ice_pf *pf;
3409 	int status;
3410 
3411 	pf = vf->pf;
3412 	dev = ice_pf_to_dev(pf);
3413 
3414 	if (test_bit(ICE_VF_STATE_DIS, vf->vf_states))
3415 		return vf->mbx_info.malicious;
3416 
3417 	/* check to see if we have a newly malicious VF */
3418 	status = ice_mbx_vf_state_handler(&pf->hw, mbxdata, &vf->mbx_info,
3419 					  &report_malvf);
3420 	if (status)
3421 		dev_warn_ratelimited(dev, "Unable to check status of mailbox overflow for VF %u MAC %pM, status %d\n",
3422 				     vf->vf_id, vf->dev_lan_addr, status);
3423 
3424 	if (report_malvf) {
3425 		struct ice_vsi *pf_vsi = ice_get_main_vsi(pf);
3426 		u8 zero_addr[ETH_ALEN] = {};
3427 
3428 		dev_warn(dev, "VF MAC %pM on PF MAC %pM is generating asynchronous messages and may be overflowing the PF message queue. Please see the Adapter User Guide for more information\n",
3429 			 vf->dev_lan_addr,
3430 			 pf_vsi ? pf_vsi->netdev->dev_addr : zero_addr);
3431 	}
3432 
3433 	return vf->mbx_info.malicious;
3434 }
3435 
3436 /**
3437  * ice_vc_process_vf_msg - Process request from VF
3438  * @pf: pointer to the PF structure
3439  * @event: pointer to the AQ event
3440  * @mbxdata: information used to detect VF attempting mailbox overflow
3441  *
3442  * Called from the common asq/arq handler to process request from VF. When this
3443  * flow is used for devices with hardware VF to PF message queue overflow
3444  * support (ICE_F_MBX_LIMIT) mbxdata is set to NULL and ice_is_malicious_vf
3445  * check is skipped.
3446  */
3447 void ice_vc_process_vf_msg(struct ice_pf *pf, struct ice_rq_event_info *event,
3448 			   struct ice_mbx_data *mbxdata)
3449 {
3450 	u32 v_opcode = le32_to_cpu(event->desc.cookie_high);
3451 	s16 vf_id = le16_to_cpu(event->desc.retval);
3452 	const struct ice_virtchnl_ops *ops;
3453 	u16 msglen = event->msg_len;
3454 	u8 *msg = event->msg_buf;
3455 	struct ice_vf *vf = NULL;
3456 	struct device *dev;
3457 	int err = 0;
3458 
3459 	dev = ice_pf_to_dev(pf);
3460 
3461 	vf = ice_get_vf_by_id(pf, vf_id);
3462 	if (!vf) {
3463 		dev_err(dev, "Unable to locate VF for message from VF ID %d, opcode %d, len %d\n",
3464 			vf_id, v_opcode, msglen);
3465 		return;
3466 	}
3467 
3468 	mutex_lock(&vf->cfg_lock);
3469 
3470 	/* Check if the VF is trying to overflow the mailbox */
3471 	if (mbxdata && ice_is_malicious_vf(vf, mbxdata))
3472 		goto finish;
3473 
3474 	/* Check if VF is disabled. */
3475 	if (test_bit(ICE_VF_STATE_DIS, vf->vf_states)) {
3476 		err = -EPERM;
3477 		goto error_handler;
3478 	}
3479 
3480 	ops = vf->virtchnl_ops;
3481 
3482 	/* Perform basic checks on the msg */
3483 	err = virtchnl_vc_validate_vf_msg(&vf->vf_ver, v_opcode, msg, msglen);
3484 	if (err) {
3485 		if (err == VIRTCHNL_STATUS_ERR_PARAM)
3486 			err = -EPERM;
3487 		else
3488 			err = -EINVAL;
3489 	}
3490 
3491 error_handler:
3492 	if (err) {
3493 		ice_vc_send_msg_to_vf(vf, v_opcode, VIRTCHNL_STATUS_ERR_PARAM,
3494 				      NULL, 0);
3495 		dev_err(dev, "Invalid message from VF %d, opcode %d, len %d, error %d\n",
3496 			vf_id, v_opcode, msglen, err);
3497 		goto finish;
3498 	}
3499 
3500 	if (!ice_vc_is_opcode_allowed(vf, v_opcode)) {
3501 		ice_vc_send_msg_to_vf(vf, v_opcode,
3502 				      VIRTCHNL_STATUS_ERR_NOT_SUPPORTED, NULL,
3503 				      0);
3504 		goto finish;
3505 	}
3506 
3507 	switch (v_opcode) {
3508 	case VIRTCHNL_OP_VERSION:
3509 		err = ops->get_ver_msg(vf, msg);
3510 		break;
3511 	case VIRTCHNL_OP_GET_VF_RESOURCES:
3512 		err = ops->get_vf_res_msg(vf, msg);
3513 		if (ice_vf_init_vlan_stripping(vf))
3514 			dev_dbg(dev, "Failed to initialize VLAN stripping for VF %d\n",
3515 				vf->vf_id);
3516 		ice_vc_notify_vf_link_state(vf);
3517 		break;
3518 	case VIRTCHNL_OP_RESET_VF:
3519 		ops->reset_vf(vf);
3520 		break;
3521 	case VIRTCHNL_OP_ADD_ETH_ADDR:
3522 		err = ops->add_mac_addr_msg(vf, msg);
3523 		break;
3524 	case VIRTCHNL_OP_DEL_ETH_ADDR:
3525 		err = ops->del_mac_addr_msg(vf, msg);
3526 		break;
3527 	case VIRTCHNL_OP_CONFIG_VSI_QUEUES:
3528 		err = ops->cfg_qs_msg(vf, msg);
3529 		break;
3530 	case VIRTCHNL_OP_ENABLE_QUEUES:
3531 		err = ops->ena_qs_msg(vf, msg);
3532 		ice_vc_notify_vf_link_state(vf);
3533 		break;
3534 	case VIRTCHNL_OP_DISABLE_QUEUES:
3535 		err = ops->dis_qs_msg(vf, msg);
3536 		break;
3537 	case VIRTCHNL_OP_REQUEST_QUEUES:
3538 		err = ops->request_qs_msg(vf, msg);
3539 		break;
3540 	case VIRTCHNL_OP_CONFIG_IRQ_MAP:
3541 		err = ops->cfg_irq_map_msg(vf, msg);
3542 		break;
3543 	case VIRTCHNL_OP_CONFIG_RSS_KEY:
3544 		err = ops->config_rss_key(vf, msg);
3545 		break;
3546 	case VIRTCHNL_OP_CONFIG_RSS_LUT:
3547 		err = ops->config_rss_lut(vf, msg);
3548 		break;
3549 	case VIRTCHNL_OP_CONFIG_RSS_HFUNC:
3550 		err = ops->config_rss_hfunc(vf, msg);
3551 		break;
3552 	case VIRTCHNL_OP_GET_STATS:
3553 		err = ops->get_stats_msg(vf, msg);
3554 		break;
3555 	case VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE:
3556 		err = ops->cfg_promiscuous_mode_msg(vf, msg);
3557 		break;
3558 	case VIRTCHNL_OP_ADD_VLAN:
3559 		err = ops->add_vlan_msg(vf, msg);
3560 		break;
3561 	case VIRTCHNL_OP_DEL_VLAN:
3562 		err = ops->remove_vlan_msg(vf, msg);
3563 		break;
3564 	case VIRTCHNL_OP_GET_SUPPORTED_RXDIDS:
3565 		err = ops->query_rxdid(vf);
3566 		break;
3567 	case VIRTCHNL_OP_GET_RSS_HASHCFG_CAPS:
3568 		err = ops->get_rss_hashcfg(vf);
3569 		break;
3570 	case VIRTCHNL_OP_SET_RSS_HASHCFG:
3571 		err = ops->set_rss_hashcfg(vf, msg);
3572 		break;
3573 	case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING:
3574 		err = ops->ena_vlan_stripping(vf);
3575 		break;
3576 	case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING:
3577 		err = ops->dis_vlan_stripping(vf);
3578 		break;
3579 	case VIRTCHNL_OP_ADD_FDIR_FILTER:
3580 		err = ops->add_fdir_fltr_msg(vf, msg);
3581 		break;
3582 	case VIRTCHNL_OP_DEL_FDIR_FILTER:
3583 		err = ops->del_fdir_fltr_msg(vf, msg);
3584 		break;
3585 	case VIRTCHNL_OP_ADD_RSS_CFG:
3586 		err = ops->handle_rss_cfg_msg(vf, msg, true);
3587 		break;
3588 	case VIRTCHNL_OP_DEL_RSS_CFG:
3589 		err = ops->handle_rss_cfg_msg(vf, msg, false);
3590 		break;
3591 	case VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS:
3592 		err = ops->get_offload_vlan_v2_caps(vf);
3593 		break;
3594 	case VIRTCHNL_OP_ADD_VLAN_V2:
3595 		err = ops->add_vlan_v2_msg(vf, msg);
3596 		break;
3597 	case VIRTCHNL_OP_DEL_VLAN_V2:
3598 		err = ops->remove_vlan_v2_msg(vf, msg);
3599 		break;
3600 	case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2:
3601 		err = ops->ena_vlan_stripping_v2_msg(vf, msg);
3602 		break;
3603 	case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2:
3604 		err = ops->dis_vlan_stripping_v2_msg(vf, msg);
3605 		break;
3606 	case VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2:
3607 		err = ops->ena_vlan_insertion_v2_msg(vf, msg);
3608 		break;
3609 	case VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2:
3610 		err = ops->dis_vlan_insertion_v2_msg(vf, msg);
3611 		break;
3612 	case VIRTCHNL_OP_GET_QOS_CAPS:
3613 		err = ops->get_qos_caps(vf);
3614 		break;
3615 	case VIRTCHNL_OP_CONFIG_QUEUE_BW:
3616 		err = ops->cfg_q_bw(vf, msg);
3617 		break;
3618 	case VIRTCHNL_OP_CONFIG_QUANTA:
3619 		err = ops->cfg_q_quanta(vf, msg);
3620 		break;
3621 	case VIRTCHNL_OP_1588_PTP_GET_CAPS:
3622 		err = ops->get_ptp_cap(vf, (const void *)msg);
3623 		break;
3624 	case VIRTCHNL_OP_1588_PTP_GET_TIME:
3625 		err = ops->get_phc_time(vf);
3626 		break;
3627 	case VIRTCHNL_OP_UNKNOWN:
3628 	default:
3629 		dev_err(dev, "Unsupported opcode %d from VF %d\n", v_opcode,
3630 			vf_id);
3631 		err = ice_vc_send_msg_to_vf(vf, v_opcode,
3632 					    VIRTCHNL_STATUS_ERR_NOT_SUPPORTED,
3633 					    NULL, 0);
3634 		break;
3635 	}
3636 	if (err) {
3637 		/* Helper function cares less about error return values here
3638 		 * as it is busy with pending work.
3639 		 */
3640 		dev_info(dev, "PF failed to honor VF %d, opcode %d, error %d\n",
3641 			 vf_id, v_opcode, err);
3642 	}
3643 
3644 finish:
3645 	mutex_unlock(&vf->cfg_lock);
3646 	ice_put_vf(vf);
3647 }
3648