1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (C) 2022, Intel Corporation. */
4 #include "ice_virtchnl.h"
5 #include "ice_vf_lib_private.h"
10 #include "ice_virtchnl_allowlist.h"
11 #include "ice_vf_vsi_vlan_ops.h"
13 #include "ice_flex_pipe.h"
14 #include "ice_dcb_lib.h"
16 #define FIELD_SELECTOR(proto_hdr_field) \
17 BIT((proto_hdr_field) & PROTO_HDR_FIELD_MASK)
19 struct ice_vc_hdr_match_type {
20 u32 vc_hdr; /* virtchnl headers (VIRTCHNL_PROTO_HDR_XXX) */
21 u32 ice_hdr; /* ice headers (ICE_FLOW_SEG_HDR_XXX) */
24 static const struct ice_vc_hdr_match_type ice_vc_hdr_list[] = {
25 {VIRTCHNL_PROTO_HDR_NONE, ICE_FLOW_SEG_HDR_NONE},
26 {VIRTCHNL_PROTO_HDR_ETH, ICE_FLOW_SEG_HDR_ETH},
27 {VIRTCHNL_PROTO_HDR_S_VLAN, ICE_FLOW_SEG_HDR_VLAN},
28 {VIRTCHNL_PROTO_HDR_C_VLAN, ICE_FLOW_SEG_HDR_VLAN},
29 {VIRTCHNL_PROTO_HDR_IPV4, ICE_FLOW_SEG_HDR_IPV4 |
30 ICE_FLOW_SEG_HDR_IPV_OTHER},
31 {VIRTCHNL_PROTO_HDR_IPV6, ICE_FLOW_SEG_HDR_IPV6 |
32 ICE_FLOW_SEG_HDR_IPV_OTHER},
33 {VIRTCHNL_PROTO_HDR_TCP, ICE_FLOW_SEG_HDR_TCP},
34 {VIRTCHNL_PROTO_HDR_UDP, ICE_FLOW_SEG_HDR_UDP},
35 {VIRTCHNL_PROTO_HDR_SCTP, ICE_FLOW_SEG_HDR_SCTP},
36 {VIRTCHNL_PROTO_HDR_PPPOE, ICE_FLOW_SEG_HDR_PPPOE},
37 {VIRTCHNL_PROTO_HDR_GTPU_IP, ICE_FLOW_SEG_HDR_GTPU_IP},
38 {VIRTCHNL_PROTO_HDR_GTPU_EH, ICE_FLOW_SEG_HDR_GTPU_EH},
39 {VIRTCHNL_PROTO_HDR_GTPU_EH_PDU_DWN,
40 ICE_FLOW_SEG_HDR_GTPU_DWN},
41 {VIRTCHNL_PROTO_HDR_GTPU_EH_PDU_UP,
42 ICE_FLOW_SEG_HDR_GTPU_UP},
43 {VIRTCHNL_PROTO_HDR_L2TPV3, ICE_FLOW_SEG_HDR_L2TPV3},
44 {VIRTCHNL_PROTO_HDR_ESP, ICE_FLOW_SEG_HDR_ESP},
45 {VIRTCHNL_PROTO_HDR_AH, ICE_FLOW_SEG_HDR_AH},
46 {VIRTCHNL_PROTO_HDR_PFCP, ICE_FLOW_SEG_HDR_PFCP_SESSION},
49 struct ice_vc_hash_field_match_type {
50 u32 vc_hdr; /* virtchnl headers
51 * (VIRTCHNL_PROTO_HDR_XXX)
53 u32 vc_hash_field; /* virtchnl hash fields selector
54 * FIELD_SELECTOR((VIRTCHNL_PROTO_HDR_ETH_XXX))
56 u64 ice_hash_field; /* ice hash fields
57 * (BIT_ULL(ICE_FLOW_FIELD_IDX_XXX))
62 ice_vc_hash_field_match_type ice_vc_hash_field_list[] = {
63 {VIRTCHNL_PROTO_HDR_ETH, FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_ETH_SRC),
64 BIT_ULL(ICE_FLOW_FIELD_IDX_ETH_SA)},
65 {VIRTCHNL_PROTO_HDR_ETH, FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_ETH_DST),
66 BIT_ULL(ICE_FLOW_FIELD_IDX_ETH_DA)},
67 {VIRTCHNL_PROTO_HDR_ETH, FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_ETH_SRC) |
68 FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_ETH_DST),
70 {VIRTCHNL_PROTO_HDR_ETH,
71 FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_ETH_ETHERTYPE),
72 BIT_ULL(ICE_FLOW_FIELD_IDX_ETH_TYPE)},
73 {VIRTCHNL_PROTO_HDR_S_VLAN,
74 FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_S_VLAN_ID),
75 BIT_ULL(ICE_FLOW_FIELD_IDX_S_VLAN)},
76 {VIRTCHNL_PROTO_HDR_C_VLAN,
77 FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_C_VLAN_ID),
78 BIT_ULL(ICE_FLOW_FIELD_IDX_C_VLAN)},
79 {VIRTCHNL_PROTO_HDR_IPV4, FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV4_SRC),
80 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_SA)},
81 {VIRTCHNL_PROTO_HDR_IPV4, FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV4_DST),
82 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_DA)},
83 {VIRTCHNL_PROTO_HDR_IPV4, FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV4_SRC) |
84 FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV4_DST),
86 {VIRTCHNL_PROTO_HDR_IPV4, FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV4_SRC) |
87 FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV4_PROT),
88 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_SA) |
89 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_PROT)},
90 {VIRTCHNL_PROTO_HDR_IPV4, FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV4_DST) |
91 FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV4_PROT),
92 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_DA) |
93 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_PROT)},
94 {VIRTCHNL_PROTO_HDR_IPV4, FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV4_SRC) |
95 FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV4_DST) |
96 FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV4_PROT),
97 ICE_FLOW_HASH_IPV4 | BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_PROT)},
98 {VIRTCHNL_PROTO_HDR_IPV4, FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV4_PROT),
99 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_PROT)},
100 {VIRTCHNL_PROTO_HDR_IPV6, FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV6_SRC),
101 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_SA)},
102 {VIRTCHNL_PROTO_HDR_IPV6, FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV6_DST),
103 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_DA)},
104 {VIRTCHNL_PROTO_HDR_IPV6, FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV6_SRC) |
105 FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV6_DST),
107 {VIRTCHNL_PROTO_HDR_IPV6, FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV6_SRC) |
108 FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV6_PROT),
109 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_SA) |
110 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_PROT)},
111 {VIRTCHNL_PROTO_HDR_IPV6, FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV6_DST) |
112 FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV6_PROT),
113 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_DA) |
114 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_PROT)},
115 {VIRTCHNL_PROTO_HDR_IPV6, FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV6_SRC) |
116 FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV6_DST) |
117 FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV6_PROT),
118 ICE_FLOW_HASH_IPV6 | BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_PROT)},
119 {VIRTCHNL_PROTO_HDR_IPV6, FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV6_PROT),
120 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_PROT)},
121 {VIRTCHNL_PROTO_HDR_TCP,
122 FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_TCP_SRC_PORT),
123 BIT_ULL(ICE_FLOW_FIELD_IDX_TCP_SRC_PORT)},
124 {VIRTCHNL_PROTO_HDR_TCP,
125 FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_TCP_DST_PORT),
126 BIT_ULL(ICE_FLOW_FIELD_IDX_TCP_DST_PORT)},
127 {VIRTCHNL_PROTO_HDR_TCP,
128 FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_TCP_SRC_PORT) |
129 FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_TCP_DST_PORT),
130 ICE_FLOW_HASH_TCP_PORT},
131 {VIRTCHNL_PROTO_HDR_UDP,
132 FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_UDP_SRC_PORT),
133 BIT_ULL(ICE_FLOW_FIELD_IDX_UDP_SRC_PORT)},
134 {VIRTCHNL_PROTO_HDR_UDP,
135 FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_UDP_DST_PORT),
136 BIT_ULL(ICE_FLOW_FIELD_IDX_UDP_DST_PORT)},
137 {VIRTCHNL_PROTO_HDR_UDP,
138 FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_UDP_SRC_PORT) |
139 FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_UDP_DST_PORT),
140 ICE_FLOW_HASH_UDP_PORT},
141 {VIRTCHNL_PROTO_HDR_SCTP,
142 FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_SCTP_SRC_PORT),
143 BIT_ULL(ICE_FLOW_FIELD_IDX_SCTP_SRC_PORT)},
144 {VIRTCHNL_PROTO_HDR_SCTP,
145 FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_SCTP_DST_PORT),
146 BIT_ULL(ICE_FLOW_FIELD_IDX_SCTP_DST_PORT)},
147 {VIRTCHNL_PROTO_HDR_SCTP,
148 FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_SCTP_SRC_PORT) |
149 FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_SCTP_DST_PORT),
150 ICE_FLOW_HASH_SCTP_PORT},
151 {VIRTCHNL_PROTO_HDR_PPPOE,
152 FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_PPPOE_SESS_ID),
153 BIT_ULL(ICE_FLOW_FIELD_IDX_PPPOE_SESS_ID)},
154 {VIRTCHNL_PROTO_HDR_GTPU_IP,
155 FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_GTPU_IP_TEID),
156 BIT_ULL(ICE_FLOW_FIELD_IDX_GTPU_IP_TEID)},
157 {VIRTCHNL_PROTO_HDR_L2TPV3,
158 FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_L2TPV3_SESS_ID),
159 BIT_ULL(ICE_FLOW_FIELD_IDX_L2TPV3_SESS_ID)},
160 {VIRTCHNL_PROTO_HDR_ESP, FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_ESP_SPI),
161 BIT_ULL(ICE_FLOW_FIELD_IDX_ESP_SPI)},
162 {VIRTCHNL_PROTO_HDR_AH, FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_AH_SPI),
163 BIT_ULL(ICE_FLOW_FIELD_IDX_AH_SPI)},
164 {VIRTCHNL_PROTO_HDR_PFCP, FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_PFCP_SEID),
165 BIT_ULL(ICE_FLOW_FIELD_IDX_PFCP_SEID)},
169 * ice_vc_vf_broadcast - Broadcast a message to all VFs on PF
170 * @pf: pointer to the PF structure
171 * @v_opcode: operation code
172 * @v_retval: return value
173 * @msg: pointer to the msg buffer
174 * @msglen: msg length
177 ice_vc_vf_broadcast(struct ice_pf *pf, enum virtchnl_ops v_opcode,
178 enum virtchnl_status_code v_retval, u8 *msg, u16 msglen)
180 struct ice_hw *hw = &pf->hw;
184 mutex_lock(&pf->vfs.table_lock);
185 ice_for_each_vf(pf, bkt, vf) {
186 /* Not all vfs are enabled so skip the ones that are not */
187 if (!test_bit(ICE_VF_STATE_INIT, vf->vf_states) &&
188 !test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states))
191 /* Ignore return value on purpose - a given VF may fail, but
192 * we need to keep going and send to all of them
194 ice_aq_send_msg_to_vf(hw, vf->vf_id, v_opcode, v_retval, msg,
197 mutex_unlock(&pf->vfs.table_lock);
201 * ice_set_pfe_link - Set the link speed/status of the virtchnl_pf_event
202 * @vf: pointer to the VF structure
203 * @pfe: pointer to the virtchnl_pf_event to set link speed/status for
204 * @ice_link_speed: link speed specified by ICE_AQ_LINK_SPEED_*
205 * @link_up: whether or not to set the link up/down
208 ice_set_pfe_link(struct ice_vf *vf, struct virtchnl_pf_event *pfe,
209 int ice_link_speed, bool link_up)
211 if (vf->driver_caps & VIRTCHNL_VF_CAP_ADV_LINK_SPEED) {
212 pfe->event_data.link_event_adv.link_status = link_up;
214 pfe->event_data.link_event_adv.link_speed =
215 ice_conv_link_speed_to_virtchnl(true, ice_link_speed);
217 pfe->event_data.link_event.link_status = link_up;
218 /* Legacy method for virtchnl link speeds */
219 pfe->event_data.link_event.link_speed =
220 (enum virtchnl_link_speed)
221 ice_conv_link_speed_to_virtchnl(false, ice_link_speed);
226 * ice_vc_notify_vf_link_state - Inform a VF of link status
227 * @vf: pointer to the VF structure
229 * send a link status message to a single VF
231 void ice_vc_notify_vf_link_state(struct ice_vf *vf)
233 struct virtchnl_pf_event pfe = { 0 };
234 struct ice_hw *hw = &vf->pf->hw;
236 pfe.event = VIRTCHNL_EVENT_LINK_CHANGE;
237 pfe.severity = PF_EVENT_SEVERITY_INFO;
239 if (ice_is_vf_link_up(vf))
240 ice_set_pfe_link(vf, &pfe,
241 hw->port_info->phy.link_info.link_speed, true);
243 ice_set_pfe_link(vf, &pfe, ICE_AQ_LINK_SPEED_UNKNOWN, false);
245 ice_aq_send_msg_to_vf(hw, vf->vf_id, VIRTCHNL_OP_EVENT,
246 VIRTCHNL_STATUS_SUCCESS, (u8 *)&pfe,
251 * ice_vc_notify_link_state - Inform all VFs on a PF of link status
252 * @pf: pointer to the PF structure
254 void ice_vc_notify_link_state(struct ice_pf *pf)
259 mutex_lock(&pf->vfs.table_lock);
260 ice_for_each_vf(pf, bkt, vf)
261 ice_vc_notify_vf_link_state(vf);
262 mutex_unlock(&pf->vfs.table_lock);
266 * ice_vc_notify_reset - Send pending reset message to all VFs
267 * @pf: pointer to the PF structure
269 * indicate a pending reset to all VFs on a given PF
271 void ice_vc_notify_reset(struct ice_pf *pf)
273 struct virtchnl_pf_event pfe;
275 if (!ice_has_vfs(pf))
278 pfe.event = VIRTCHNL_EVENT_RESET_IMPENDING;
279 pfe.severity = PF_EVENT_SEVERITY_CERTAIN_DOOM;
280 ice_vc_vf_broadcast(pf, VIRTCHNL_OP_EVENT, VIRTCHNL_STATUS_SUCCESS,
281 (u8 *)&pfe, sizeof(struct virtchnl_pf_event));
285 * ice_vc_send_msg_to_vf - Send message to VF
286 * @vf: pointer to the VF info
287 * @v_opcode: virtual channel opcode
288 * @v_retval: virtual channel return value
289 * @msg: pointer to the msg buffer
290 * @msglen: msg length
295 ice_vc_send_msg_to_vf(struct ice_vf *vf, u32 v_opcode,
296 enum virtchnl_status_code v_retval, u8 *msg, u16 msglen)
303 dev = ice_pf_to_dev(pf);
305 aq_ret = ice_aq_send_msg_to_vf(&pf->hw, vf->vf_id, v_opcode, v_retval,
307 if (aq_ret && pf->hw.mailboxq.sq_last_status != ICE_AQ_RC_ENOSYS) {
308 dev_info(dev, "Unable to send the message to VF %d ret %d aq_err %s\n",
310 ice_aq_str(pf->hw.mailboxq.sq_last_status));
319 * @vf: pointer to the VF info
320 * @msg: pointer to the msg buffer
322 * called from the VF to request the API version used by the PF
324 static int ice_vc_get_ver_msg(struct ice_vf *vf, u8 *msg)
326 struct virtchnl_version_info info = {
327 VIRTCHNL_VERSION_MAJOR, VIRTCHNL_VERSION_MINOR
330 vf->vf_ver = *(struct virtchnl_version_info *)msg;
331 /* VFs running the 1.0 API expect to get 1.0 back or they will cry. */
332 if (VF_IS_V10(&vf->vf_ver))
333 info.minor = VIRTCHNL_VERSION_MINOR_NO_VF_CAPS;
335 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_VERSION,
336 VIRTCHNL_STATUS_SUCCESS, (u8 *)&info,
337 sizeof(struct virtchnl_version_info));
341 * ice_vc_get_max_frame_size - get max frame size allowed for VF
342 * @vf: VF used to determine max frame size
344 * Max frame size is determined based on the current port's max frame size and
345 * whether a port VLAN is configured on this VF. The VF is not aware whether
346 * it's in a port VLAN so the PF needs to account for this in max frame size
347 * checks and sending the max frame size to the VF.
349 static u16 ice_vc_get_max_frame_size(struct ice_vf *vf)
351 struct ice_port_info *pi = ice_vf_get_port_info(vf);
354 max_frame_size = pi->phy.link_info.max_frame_size;
356 if (ice_vf_is_port_vlan_ena(vf))
357 max_frame_size -= VLAN_HLEN;
359 return max_frame_size;
363 * ice_vc_get_vlan_caps
364 * @hw: pointer to the hw
365 * @vf: pointer to the VF info
366 * @vsi: pointer to the VSI
367 * @driver_caps: current driver caps
369 * Return 0 if there is no VLAN caps supported, or VLAN caps value
372 ice_vc_get_vlan_caps(struct ice_hw *hw, struct ice_vf *vf, struct ice_vsi *vsi,
375 if (ice_is_eswitch_mode_switchdev(vf->pf))
376 /* In switchdev setting VLAN from VF isn't supported */
379 if (driver_caps & VIRTCHNL_VF_OFFLOAD_VLAN_V2) {
380 /* VLAN offloads based on current device configuration */
381 return VIRTCHNL_VF_OFFLOAD_VLAN_V2;
382 } else if (driver_caps & VIRTCHNL_VF_OFFLOAD_VLAN) {
383 /* allow VF to negotiate VIRTCHNL_VF_OFFLOAD explicitly for
384 * these two conditions, which amounts to guest VLAN filtering
385 * and offloads being based on the inner VLAN or the
386 * inner/single VLAN respectively and don't allow VF to
387 * negotiate VIRTCHNL_VF_OFFLOAD in any other cases
389 if (ice_is_dvm_ena(hw) && ice_vf_is_port_vlan_ena(vf)) {
390 return VIRTCHNL_VF_OFFLOAD_VLAN;
391 } else if (!ice_is_dvm_ena(hw) &&
392 !ice_vf_is_port_vlan_ena(vf)) {
393 /* configure backward compatible support for VFs that
394 * only support VIRTCHNL_VF_OFFLOAD_VLAN, the PF is
395 * configured in SVM, and no port VLAN is configured
397 ice_vf_vsi_cfg_svm_legacy_vlan_mode(vsi);
398 return VIRTCHNL_VF_OFFLOAD_VLAN;
399 } else if (ice_is_dvm_ena(hw)) {
400 /* configure software offloaded VLAN support when DVM
401 * is enabled, but no port VLAN is enabled
403 ice_vf_vsi_cfg_dvm_legacy_vlan_mode(vsi);
411 * ice_vc_get_vf_res_msg
412 * @vf: pointer to the VF info
413 * @msg: pointer to the msg buffer
415 * called from the VF to request its resources
417 static int ice_vc_get_vf_res_msg(struct ice_vf *vf, u8 *msg)
419 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
420 struct virtchnl_vf_resource *vfres = NULL;
421 struct ice_hw *hw = &vf->pf->hw;
426 if (ice_check_vf_init(vf)) {
427 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
431 len = virtchnl_struct_size(vfres, vsi_res, 0);
433 vfres = kzalloc(len, GFP_KERNEL);
435 v_ret = VIRTCHNL_STATUS_ERR_NO_MEMORY;
439 if (VF_IS_V11(&vf->vf_ver))
440 vf->driver_caps = *(u32 *)msg;
442 vf->driver_caps = VIRTCHNL_VF_OFFLOAD_L2 |
443 VIRTCHNL_VF_OFFLOAD_VLAN;
445 vfres->vf_cap_flags = VIRTCHNL_VF_OFFLOAD_L2;
446 vsi = ice_get_vf_vsi(vf);
448 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
452 vfres->vf_cap_flags |= ice_vc_get_vlan_caps(hw, vf, vsi,
455 if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_RSS_PF)
456 vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_RSS_PF;
458 if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_RX_FLEX_DESC)
459 vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_RX_FLEX_DESC;
461 if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_FDIR_PF)
462 vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_FDIR_PF;
464 if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_TC_U32 &&
465 vfres->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_FDIR_PF)
466 vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_TC_U32;
468 if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_RSS_PCTYPE_V2)
469 vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_RSS_PCTYPE_V2;
471 if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_ENCAP)
472 vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_ENCAP;
474 if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_ENCAP_CSUM)
475 vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_ENCAP_CSUM;
477 if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_RX_POLLING)
478 vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_RX_POLLING;
480 if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_WB_ON_ITR)
481 vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_WB_ON_ITR;
483 if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_REQ_QUEUES)
484 vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_REQ_QUEUES;
486 if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_CRC)
487 vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_CRC;
489 if (vf->driver_caps & VIRTCHNL_VF_CAP_ADV_LINK_SPEED)
490 vfres->vf_cap_flags |= VIRTCHNL_VF_CAP_ADV_LINK_SPEED;
492 if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_ADV_RSS_PF)
493 vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_ADV_RSS_PF;
495 if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_USO)
496 vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_USO;
499 /* Tx and Rx queue are equal for VF */
500 vfres->num_queue_pairs = vsi->num_txq;
501 vfres->max_vectors = vf->num_msix;
502 vfres->rss_key_size = ICE_VSIQF_HKEY_ARRAY_SIZE;
503 vfres->rss_lut_size = ICE_LUT_VSI_SIZE;
504 vfres->max_mtu = ice_vc_get_max_frame_size(vf);
506 vfres->vsi_res[0].vsi_id = ICE_VF_VSI_ID;
507 vfres->vsi_res[0].vsi_type = VIRTCHNL_VSI_SRIOV;
508 vfres->vsi_res[0].num_queue_pairs = vsi->num_txq;
509 ether_addr_copy(vfres->vsi_res[0].default_mac_addr,
512 /* match guest capabilities */
513 vf->driver_caps = vfres->vf_cap_flags;
515 ice_vc_set_caps_allowlist(vf);
516 ice_vc_set_working_allowlist(vf);
518 set_bit(ICE_VF_STATE_ACTIVE, vf->vf_states);
521 /* send the response back to the VF */
522 ret = ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_GET_VF_RESOURCES, v_ret,
530 * ice_vc_reset_vf_msg
531 * @vf: pointer to the VF info
533 * called from the VF to reset itself,
534 * unlike other virtchnl messages, PF driver
535 * doesn't send the response back to the VF
537 static void ice_vc_reset_vf_msg(struct ice_vf *vf)
539 if (test_bit(ICE_VF_STATE_INIT, vf->vf_states))
544 * ice_vc_isvalid_vsi_id
545 * @vf: pointer to the VF info
546 * @vsi_id: VF relative VSI ID
548 * check for the valid VSI ID
550 bool ice_vc_isvalid_vsi_id(struct ice_vf *vf, u16 vsi_id)
552 return vsi_id == ICE_VF_VSI_ID;
556 * ice_vc_isvalid_q_id
557 * @vsi: VSI to check queue ID against
558 * @qid: VSI relative queue ID
560 * check for the valid queue ID
562 static bool ice_vc_isvalid_q_id(struct ice_vsi *vsi, u8 qid)
564 /* allocated Tx and Rx queues should be always equal for VF VSI */
565 return qid < vsi->alloc_txq;
569 * ice_vc_isvalid_ring_len
570 * @ring_len: length of ring
572 * check for the valid ring count, should be multiple of ICE_REQ_DESC_MULTIPLE
575 static bool ice_vc_isvalid_ring_len(u16 ring_len)
577 return ring_len == 0 ||
578 (ring_len >= ICE_MIN_NUM_DESC &&
579 ring_len <= ICE_MAX_NUM_DESC &&
580 !(ring_len % ICE_REQ_DESC_MULTIPLE));
584 * ice_vc_validate_pattern
585 * @vf: pointer to the VF info
586 * @proto: virtchnl protocol headers
588 * validate the pattern is supported or not.
590 * Return: true on success, false on error.
593 ice_vc_validate_pattern(struct ice_vf *vf, struct virtchnl_proto_hdrs *proto)
595 bool is_ipv4 = false;
596 bool is_ipv6 = false;
601 while (i < proto->count &&
602 proto->proto_hdr[i].type != VIRTCHNL_PROTO_HDR_NONE) {
603 switch (proto->proto_hdr[i].type) {
604 case VIRTCHNL_PROTO_HDR_ETH:
605 ptype = ICE_PTYPE_MAC_PAY;
607 case VIRTCHNL_PROTO_HDR_IPV4:
608 ptype = ICE_PTYPE_IPV4_PAY;
611 case VIRTCHNL_PROTO_HDR_IPV6:
612 ptype = ICE_PTYPE_IPV6_PAY;
615 case VIRTCHNL_PROTO_HDR_UDP:
617 ptype = ICE_PTYPE_IPV4_UDP_PAY;
619 ptype = ICE_PTYPE_IPV6_UDP_PAY;
622 case VIRTCHNL_PROTO_HDR_TCP:
624 ptype = ICE_PTYPE_IPV4_TCP_PAY;
626 ptype = ICE_PTYPE_IPV6_TCP_PAY;
628 case VIRTCHNL_PROTO_HDR_SCTP:
630 ptype = ICE_PTYPE_IPV4_SCTP_PAY;
632 ptype = ICE_PTYPE_IPV6_SCTP_PAY;
634 case VIRTCHNL_PROTO_HDR_GTPU_IP:
635 case VIRTCHNL_PROTO_HDR_GTPU_EH:
637 ptype = ICE_MAC_IPV4_GTPU;
639 ptype = ICE_MAC_IPV6_GTPU;
641 case VIRTCHNL_PROTO_HDR_L2TPV3:
643 ptype = ICE_MAC_IPV4_L2TPV3;
645 ptype = ICE_MAC_IPV6_L2TPV3;
647 case VIRTCHNL_PROTO_HDR_ESP:
649 ptype = is_udp ? ICE_MAC_IPV4_NAT_T_ESP :
652 ptype = is_udp ? ICE_MAC_IPV6_NAT_T_ESP :
655 case VIRTCHNL_PROTO_HDR_AH:
657 ptype = ICE_MAC_IPV4_AH;
659 ptype = ICE_MAC_IPV6_AH;
661 case VIRTCHNL_PROTO_HDR_PFCP:
663 ptype = ICE_MAC_IPV4_PFCP_SESSION;
665 ptype = ICE_MAC_IPV6_PFCP_SESSION;
674 return ice_hw_ptype_ena(&vf->pf->hw, ptype);
678 * ice_vc_parse_rss_cfg - parses hash fields and headers from
679 * a specific virtchnl RSS cfg
680 * @hw: pointer to the hardware
681 * @rss_cfg: pointer to the virtchnl RSS cfg
682 * @hash_cfg: pointer to the HW hash configuration
684 * Return true if all the protocol header and hash fields in the RSS cfg could
685 * be parsed, else return false
687 * This function parses the virtchnl RSS cfg to be the intended
688 * hash fields and the intended header for RSS configuration
690 static bool ice_vc_parse_rss_cfg(struct ice_hw *hw,
691 struct virtchnl_rss_cfg *rss_cfg,
692 struct ice_rss_hash_cfg *hash_cfg)
694 const struct ice_vc_hash_field_match_type *hf_list;
695 const struct ice_vc_hdr_match_type *hdr_list;
696 int i, hf_list_len, hdr_list_len;
697 u32 *addl_hdrs = &hash_cfg->addl_hdrs;
698 u64 *hash_flds = &hash_cfg->hash_flds;
700 /* set outer layer RSS as default */
701 hash_cfg->hdr_type = ICE_RSS_OUTER_HEADERS;
703 if (rss_cfg->rss_algorithm == VIRTCHNL_RSS_ALG_TOEPLITZ_SYMMETRIC)
704 hash_cfg->symm = true;
706 hash_cfg->symm = false;
708 hf_list = ice_vc_hash_field_list;
709 hf_list_len = ARRAY_SIZE(ice_vc_hash_field_list);
710 hdr_list = ice_vc_hdr_list;
711 hdr_list_len = ARRAY_SIZE(ice_vc_hdr_list);
713 for (i = 0; i < rss_cfg->proto_hdrs.count; i++) {
714 struct virtchnl_proto_hdr *proto_hdr =
715 &rss_cfg->proto_hdrs.proto_hdr[i];
716 bool hdr_found = false;
719 /* Find matched ice headers according to virtchnl headers. */
720 for (j = 0; j < hdr_list_len; j++) {
721 struct ice_vc_hdr_match_type hdr_map = hdr_list[j];
723 if (proto_hdr->type == hdr_map.vc_hdr) {
724 *addl_hdrs |= hdr_map.ice_hdr;
732 /* Find matched ice hash fields according to
733 * virtchnl hash fields.
735 for (j = 0; j < hf_list_len; j++) {
736 struct ice_vc_hash_field_match_type hf_map = hf_list[j];
738 if (proto_hdr->type == hf_map.vc_hdr &&
739 proto_hdr->field_selector == hf_map.vc_hash_field) {
740 *hash_flds |= hf_map.ice_hash_field;
750 * ice_vf_adv_rss_offload_ena - determine if capabilities support advanced
752 * @caps: VF driver negotiated capabilities
754 * Return true if VIRTCHNL_VF_OFFLOAD_ADV_RSS_PF capability is set,
757 static bool ice_vf_adv_rss_offload_ena(u32 caps)
759 return !!(caps & VIRTCHNL_VF_OFFLOAD_ADV_RSS_PF);
763 * ice_vc_handle_rss_cfg
764 * @vf: pointer to the VF info
765 * @msg: pointer to the message buffer
766 * @add: add a RSS config if true, otherwise delete a RSS config
768 * This function adds/deletes a RSS config
770 static int ice_vc_handle_rss_cfg(struct ice_vf *vf, u8 *msg, bool add)
772 u32 v_opcode = add ? VIRTCHNL_OP_ADD_RSS_CFG : VIRTCHNL_OP_DEL_RSS_CFG;
773 struct virtchnl_rss_cfg *rss_cfg = (struct virtchnl_rss_cfg *)msg;
774 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
775 struct device *dev = ice_pf_to_dev(vf->pf);
776 struct ice_hw *hw = &vf->pf->hw;
779 if (!test_bit(ICE_FLAG_RSS_ENA, vf->pf->flags)) {
780 dev_dbg(dev, "VF %d attempting to configure RSS, but RSS is not supported by the PF\n",
782 v_ret = VIRTCHNL_STATUS_ERR_NOT_SUPPORTED;
786 if (!ice_vf_adv_rss_offload_ena(vf->driver_caps)) {
787 dev_dbg(dev, "VF %d attempting to configure RSS, but Advanced RSS offload is not supported\n",
789 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
793 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
794 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
798 if (rss_cfg->proto_hdrs.count > VIRTCHNL_MAX_NUM_PROTO_HDRS ||
799 rss_cfg->rss_algorithm < VIRTCHNL_RSS_ALG_TOEPLITZ_ASYMMETRIC ||
800 rss_cfg->rss_algorithm > VIRTCHNL_RSS_ALG_XOR_SYMMETRIC) {
801 dev_dbg(dev, "VF %d attempting to configure RSS, but RSS configuration is not valid\n",
803 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
807 vsi = ice_get_vf_vsi(vf);
809 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
813 if (!ice_vc_validate_pattern(vf, &rss_cfg->proto_hdrs)) {
814 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
818 if (rss_cfg->rss_algorithm == VIRTCHNL_RSS_ALG_R_ASYMMETRIC) {
819 struct ice_vsi_ctx *ctx;
820 u8 lut_type, hash_type;
823 lut_type = ICE_AQ_VSI_Q_OPT_RSS_LUT_VSI;
824 hash_type = add ? ICE_AQ_VSI_Q_OPT_RSS_HASH_XOR :
825 ICE_AQ_VSI_Q_OPT_RSS_HASH_TPLZ;
827 ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
829 v_ret = VIRTCHNL_STATUS_ERR_NO_MEMORY;
833 ctx->info.q_opt_rss =
834 FIELD_PREP(ICE_AQ_VSI_Q_OPT_RSS_LUT_M, lut_type) |
835 FIELD_PREP(ICE_AQ_VSI_Q_OPT_RSS_HASH_M, hash_type);
837 /* Preserve existing queueing option setting */
838 ctx->info.q_opt_rss |= (vsi->info.q_opt_rss &
839 ICE_AQ_VSI_Q_OPT_RSS_GBL_LUT_M);
840 ctx->info.q_opt_tc = vsi->info.q_opt_tc;
841 ctx->info.q_opt_flags = vsi->info.q_opt_rss;
843 ctx->info.valid_sections =
844 cpu_to_le16(ICE_AQ_VSI_PROP_Q_OPT_VALID);
846 status = ice_update_vsi(hw, vsi->idx, ctx, NULL);
848 dev_err(dev, "update VSI for RSS failed, err %d aq_err %s\n",
849 status, ice_aq_str(hw->adminq.sq_last_status));
850 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
852 vsi->info.q_opt_rss = ctx->info.q_opt_rss;
857 struct ice_rss_hash_cfg cfg;
859 /* Only check for none raw pattern case */
860 if (!ice_vc_validate_pattern(vf, &rss_cfg->proto_hdrs)) {
861 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
864 cfg.addl_hdrs = ICE_FLOW_SEG_HDR_NONE;
865 cfg.hash_flds = ICE_HASH_INVALID;
866 cfg.hdr_type = ICE_RSS_ANY_HEADERS;
868 if (!ice_vc_parse_rss_cfg(hw, rss_cfg, &cfg)) {
869 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
874 if (ice_add_rss_cfg(hw, vsi, &cfg)) {
875 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
876 dev_err(dev, "ice_add_rss_cfg failed for vsi = %d, v_ret = %d\n",
877 vsi->vsi_num, v_ret);
882 status = ice_rem_rss_cfg(hw, vsi->idx, &cfg);
883 /* We just ignore -ENOENT, because if two configurations
884 * share the same profile remove one of them actually
885 * removes both, since the profile is deleted.
887 if (status && status != -ENOENT) {
888 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
889 dev_err(dev, "ice_rem_rss_cfg failed for VF ID:%d, error:%d\n",
896 return ice_vc_send_msg_to_vf(vf, v_opcode, v_ret, NULL, 0);
900 * ice_vc_config_rss_key
901 * @vf: pointer to the VF info
902 * @msg: pointer to the msg buffer
904 * Configure the VF's RSS key
906 static int ice_vc_config_rss_key(struct ice_vf *vf, u8 *msg)
908 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
909 struct virtchnl_rss_key *vrk =
910 (struct virtchnl_rss_key *)msg;
913 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
914 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
918 if (!ice_vc_isvalid_vsi_id(vf, vrk->vsi_id)) {
919 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
923 if (vrk->key_len != ICE_VSIQF_HKEY_ARRAY_SIZE) {
924 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
928 if (!test_bit(ICE_FLAG_RSS_ENA, vf->pf->flags)) {
929 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
933 vsi = ice_get_vf_vsi(vf);
935 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
939 if (ice_set_rss_key(vsi, vrk->key))
940 v_ret = VIRTCHNL_STATUS_ERR_ADMIN_QUEUE_ERROR;
942 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_CONFIG_RSS_KEY, v_ret,
947 * ice_vc_config_rss_lut
948 * @vf: pointer to the VF info
949 * @msg: pointer to the msg buffer
951 * Configure the VF's RSS LUT
953 static int ice_vc_config_rss_lut(struct ice_vf *vf, u8 *msg)
955 struct virtchnl_rss_lut *vrl = (struct virtchnl_rss_lut *)msg;
956 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
959 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
960 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
964 if (!ice_vc_isvalid_vsi_id(vf, vrl->vsi_id)) {
965 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
969 if (vrl->lut_entries != ICE_LUT_VSI_SIZE) {
970 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
974 if (!test_bit(ICE_FLAG_RSS_ENA, vf->pf->flags)) {
975 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
979 vsi = ice_get_vf_vsi(vf);
981 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
985 if (ice_set_rss_lut(vsi, vrl->lut, ICE_LUT_VSI_SIZE))
986 v_ret = VIRTCHNL_STATUS_ERR_ADMIN_QUEUE_ERROR;
988 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_CONFIG_RSS_LUT, v_ret,
993 * ice_vc_config_rss_hfunc
994 * @vf: pointer to the VF info
995 * @msg: pointer to the msg buffer
997 * Configure the VF's RSS Hash function
999 static int ice_vc_config_rss_hfunc(struct ice_vf *vf, u8 *msg)
1001 struct virtchnl_rss_hfunc *vrh = (struct virtchnl_rss_hfunc *)msg;
1002 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
1003 u8 hfunc = ICE_AQ_VSI_Q_OPT_RSS_HASH_TPLZ;
1004 struct ice_vsi *vsi;
1006 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
1007 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1011 if (!ice_vc_isvalid_vsi_id(vf, vrh->vsi_id)) {
1012 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1016 if (!test_bit(ICE_FLAG_RSS_ENA, vf->pf->flags)) {
1017 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1021 vsi = ice_get_vf_vsi(vf);
1023 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1027 if (vrh->rss_algorithm == VIRTCHNL_RSS_ALG_TOEPLITZ_SYMMETRIC)
1028 hfunc = ICE_AQ_VSI_Q_OPT_RSS_HASH_SYM_TPLZ;
1030 if (ice_set_rss_hfunc(vsi, hfunc))
1031 v_ret = VIRTCHNL_STATUS_ERR_ADMIN_QUEUE_ERROR;
1033 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_CONFIG_RSS_HFUNC, v_ret,
1038 * ice_vc_cfg_promiscuous_mode_msg
1039 * @vf: pointer to the VF info
1040 * @msg: pointer to the msg buffer
1042 * called from the VF to configure VF VSIs promiscuous mode
1044 static int ice_vc_cfg_promiscuous_mode_msg(struct ice_vf *vf, u8 *msg)
1046 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
1047 bool rm_promisc, alluni = false, allmulti = false;
1048 struct virtchnl_promisc_info *info =
1049 (struct virtchnl_promisc_info *)msg;
1050 struct ice_vsi_vlan_ops *vlan_ops;
1051 int mcast_err = 0, ucast_err = 0;
1052 struct ice_pf *pf = vf->pf;
1053 struct ice_vsi *vsi;
1054 u8 mcast_m, ucast_m;
1058 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
1059 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1063 if (!ice_vc_isvalid_vsi_id(vf, info->vsi_id)) {
1064 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1068 vsi = ice_get_vf_vsi(vf);
1070 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1074 dev = ice_pf_to_dev(pf);
1075 if (!ice_is_vf_trusted(vf)) {
1076 dev_err(dev, "Unprivileged VF %d is attempting to configure promiscuous mode\n",
1078 /* Leave v_ret alone, lie to the VF on purpose. */
1082 if (info->flags & FLAG_VF_UNICAST_PROMISC)
1085 if (info->flags & FLAG_VF_MULTICAST_PROMISC)
1088 rm_promisc = !allmulti && !alluni;
1090 vlan_ops = ice_get_compat_vsi_vlan_ops(vsi);
1092 ret = vlan_ops->ena_rx_filtering(vsi);
1094 ret = vlan_ops->dis_rx_filtering(vsi);
1096 dev_err(dev, "Failed to configure VLAN pruning in promiscuous mode\n");
1097 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1101 ice_vf_get_promisc_masks(vf, vsi, &ucast_m, &mcast_m);
1103 if (!test_bit(ICE_FLAG_VF_TRUE_PROMISC_ENA, pf->flags)) {
1105 /* in this case we're turning on promiscuous mode */
1106 ret = ice_set_dflt_vsi(vsi);
1108 /* in this case we're turning off promiscuous mode */
1109 if (ice_is_dflt_vsi_in_use(vsi->port_info))
1110 ret = ice_clear_dflt_vsi(vsi);
1113 /* in this case we're turning on/off only
1117 mcast_err = ice_vf_set_vsi_promisc(vf, vsi, mcast_m);
1119 mcast_err = ice_vf_clear_vsi_promisc(vf, vsi, mcast_m);
1122 dev_err(dev, "Turning on/off promiscuous mode for VF %d failed, error: %d\n",
1124 v_ret = VIRTCHNL_STATUS_ERR_ADMIN_QUEUE_ERROR;
1129 ucast_err = ice_vf_set_vsi_promisc(vf, vsi, ucast_m);
1131 ucast_err = ice_vf_clear_vsi_promisc(vf, vsi, ucast_m);
1134 mcast_err = ice_vf_set_vsi_promisc(vf, vsi, mcast_m);
1136 mcast_err = ice_vf_clear_vsi_promisc(vf, vsi, mcast_m);
1138 if (ucast_err || mcast_err)
1139 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1144 !test_and_set_bit(ICE_VF_STATE_MC_PROMISC, vf->vf_states))
1145 dev_info(dev, "VF %u successfully set multicast promiscuous mode\n",
1147 else if (!allmulti &&
1148 test_and_clear_bit(ICE_VF_STATE_MC_PROMISC,
1150 dev_info(dev, "VF %u successfully unset multicast promiscuous mode\n",
1153 dev_err(dev, "Error while modifying multicast promiscuous mode for VF %u, error: %d\n",
1154 vf->vf_id, mcast_err);
1159 !test_and_set_bit(ICE_VF_STATE_UC_PROMISC, vf->vf_states))
1160 dev_info(dev, "VF %u successfully set unicast promiscuous mode\n",
1163 test_and_clear_bit(ICE_VF_STATE_UC_PROMISC,
1165 dev_info(dev, "VF %u successfully unset unicast promiscuous mode\n",
1168 dev_err(dev, "Error while modifying unicast promiscuous mode for VF %u, error: %d\n",
1169 vf->vf_id, ucast_err);
1173 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE,
1178 * ice_vc_get_stats_msg
1179 * @vf: pointer to the VF info
1180 * @msg: pointer to the msg buffer
1182 * called from the VF to get VSI stats
1184 static int ice_vc_get_stats_msg(struct ice_vf *vf, u8 *msg)
1186 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
1187 struct virtchnl_queue_select *vqs =
1188 (struct virtchnl_queue_select *)msg;
1189 struct ice_eth_stats stats = { 0 };
1190 struct ice_vsi *vsi;
1192 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
1193 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1197 if (!ice_vc_isvalid_vsi_id(vf, vqs->vsi_id)) {
1198 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1202 vsi = ice_get_vf_vsi(vf);
1204 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1208 ice_update_eth_stats(vsi);
1210 stats = vsi->eth_stats;
1213 /* send the response to the VF */
1214 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_GET_STATS, v_ret,
1215 (u8 *)&stats, sizeof(stats));
1219 * ice_vc_validate_vqs_bitmaps - validate Rx/Tx queue bitmaps from VIRTCHNL
1220 * @vqs: virtchnl_queue_select structure containing bitmaps to validate
1222 * Return true on successful validation, else false
1224 static bool ice_vc_validate_vqs_bitmaps(struct virtchnl_queue_select *vqs)
1226 if ((!vqs->rx_queues && !vqs->tx_queues) ||
1227 vqs->rx_queues >= BIT(ICE_MAX_RSS_QS_PER_VF) ||
1228 vqs->tx_queues >= BIT(ICE_MAX_RSS_QS_PER_VF))
1235 * ice_vf_ena_txq_interrupt - enable Tx queue interrupt via QINT_TQCTL
1236 * @vsi: VSI of the VF to configure
1237 * @q_idx: VF queue index used to determine the queue in the PF's space
1239 static void ice_vf_ena_txq_interrupt(struct ice_vsi *vsi, u32 q_idx)
1241 struct ice_hw *hw = &vsi->back->hw;
1242 u32 pfq = vsi->txq_map[q_idx];
1245 reg = rd32(hw, QINT_TQCTL(pfq));
1247 /* MSI-X index 0 in the VF's space is always for the OICR, which means
1248 * this is most likely a poll mode VF driver, so don't enable an
1249 * interrupt that was never configured via VIRTCHNL_OP_CONFIG_IRQ_MAP
1251 if (!(reg & QINT_TQCTL_MSIX_INDX_M))
1254 wr32(hw, QINT_TQCTL(pfq), reg | QINT_TQCTL_CAUSE_ENA_M);
1258 * ice_vf_ena_rxq_interrupt - enable Tx queue interrupt via QINT_RQCTL
1259 * @vsi: VSI of the VF to configure
1260 * @q_idx: VF queue index used to determine the queue in the PF's space
1262 static void ice_vf_ena_rxq_interrupt(struct ice_vsi *vsi, u32 q_idx)
1264 struct ice_hw *hw = &vsi->back->hw;
1265 u32 pfq = vsi->rxq_map[q_idx];
1268 reg = rd32(hw, QINT_RQCTL(pfq));
1270 /* MSI-X index 0 in the VF's space is always for the OICR, which means
1271 * this is most likely a poll mode VF driver, so don't enable an
1272 * interrupt that was never configured via VIRTCHNL_OP_CONFIG_IRQ_MAP
1274 if (!(reg & QINT_RQCTL_MSIX_INDX_M))
1277 wr32(hw, QINT_RQCTL(pfq), reg | QINT_RQCTL_CAUSE_ENA_M);
1282 * @vf: pointer to the VF info
1283 * @msg: pointer to the msg buffer
1285 * called from the VF to enable all or specific queue(s)
1287 static int ice_vc_ena_qs_msg(struct ice_vf *vf, u8 *msg)
1289 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
1290 struct virtchnl_queue_select *vqs =
1291 (struct virtchnl_queue_select *)msg;
1292 struct ice_vsi *vsi;
1293 unsigned long q_map;
1296 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
1297 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1301 if (!ice_vc_isvalid_vsi_id(vf, vqs->vsi_id)) {
1302 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1306 if (!ice_vc_validate_vqs_bitmaps(vqs)) {
1307 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1311 vsi = ice_get_vf_vsi(vf);
1313 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1317 /* Enable only Rx rings, Tx rings were enabled by the FW when the
1318 * Tx queue group list was configured and the context bits were
1319 * programmed using ice_vsi_cfg_txqs
1321 q_map = vqs->rx_queues;
1322 for_each_set_bit(vf_q_id, &q_map, ICE_MAX_RSS_QS_PER_VF) {
1323 if (!ice_vc_isvalid_q_id(vsi, vf_q_id)) {
1324 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1328 /* Skip queue if enabled */
1329 if (test_bit(vf_q_id, vf->rxq_ena))
1332 if (ice_vsi_ctrl_one_rx_ring(vsi, true, vf_q_id, true)) {
1333 dev_err(ice_pf_to_dev(vsi->back), "Failed to enable Rx ring %d on VSI %d\n",
1334 vf_q_id, vsi->vsi_num);
1335 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1339 ice_vf_ena_rxq_interrupt(vsi, vf_q_id);
1340 set_bit(vf_q_id, vf->rxq_ena);
1343 q_map = vqs->tx_queues;
1344 for_each_set_bit(vf_q_id, &q_map, ICE_MAX_RSS_QS_PER_VF) {
1345 if (!ice_vc_isvalid_q_id(vsi, vf_q_id)) {
1346 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1350 /* Skip queue if enabled */
1351 if (test_bit(vf_q_id, vf->txq_ena))
1354 ice_vf_ena_txq_interrupt(vsi, vf_q_id);
1355 set_bit(vf_q_id, vf->txq_ena);
1358 /* Set flag to indicate that queues are enabled */
1359 if (v_ret == VIRTCHNL_STATUS_SUCCESS)
1360 set_bit(ICE_VF_STATE_QS_ENA, vf->vf_states);
1363 /* send the response to the VF */
1364 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_ENABLE_QUEUES, v_ret,
1369 * ice_vf_vsi_dis_single_txq - disable a single Tx queue
1370 * @vf: VF to disable queue for
1371 * @vsi: VSI for the VF
1372 * @q_id: VF relative (0-based) queue ID
1374 * Attempt to disable the Tx queue passed in. If the Tx queue was successfully
1375 * disabled then clear q_id bit in the enabled queues bitmap and return
1376 * success. Otherwise return error.
1379 ice_vf_vsi_dis_single_txq(struct ice_vf *vf, struct ice_vsi *vsi, u16 q_id)
1381 struct ice_txq_meta txq_meta = { 0 };
1382 struct ice_tx_ring *ring;
1385 if (!test_bit(q_id, vf->txq_ena))
1386 dev_dbg(ice_pf_to_dev(vsi->back), "Queue %u on VSI %u is not enabled, but stopping it anyway\n",
1387 q_id, vsi->vsi_num);
1389 ring = vsi->tx_rings[q_id];
1393 ice_fill_txq_meta(vsi, ring, &txq_meta);
1395 err = ice_vsi_stop_tx_ring(vsi, ICE_NO_RESET, vf->vf_id, ring, &txq_meta);
1397 dev_err(ice_pf_to_dev(vsi->back), "Failed to stop Tx ring %d on VSI %d\n",
1398 q_id, vsi->vsi_num);
1402 /* Clear enabled queues flag */
1403 clear_bit(q_id, vf->txq_ena);
1410 * @vf: pointer to the VF info
1411 * @msg: pointer to the msg buffer
1413 * called from the VF to disable all or specific queue(s)
1415 static int ice_vc_dis_qs_msg(struct ice_vf *vf, u8 *msg)
1417 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
1418 struct virtchnl_queue_select *vqs =
1419 (struct virtchnl_queue_select *)msg;
1420 struct ice_vsi *vsi;
1421 unsigned long q_map;
1424 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states) &&
1425 !test_bit(ICE_VF_STATE_QS_ENA, vf->vf_states)) {
1426 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1430 if (!ice_vc_isvalid_vsi_id(vf, vqs->vsi_id)) {
1431 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1435 if (!ice_vc_validate_vqs_bitmaps(vqs)) {
1436 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1440 vsi = ice_get_vf_vsi(vf);
1442 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1446 if (vqs->tx_queues) {
1447 q_map = vqs->tx_queues;
1449 for_each_set_bit(vf_q_id, &q_map, ICE_MAX_RSS_QS_PER_VF) {
1450 if (!ice_vc_isvalid_q_id(vsi, vf_q_id)) {
1451 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1455 if (ice_vf_vsi_dis_single_txq(vf, vsi, vf_q_id)) {
1456 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1462 q_map = vqs->rx_queues;
1463 /* speed up Rx queue disable by batching them if possible */
1465 bitmap_equal(&q_map, vf->rxq_ena, ICE_MAX_RSS_QS_PER_VF)) {
1466 if (ice_vsi_stop_all_rx_rings(vsi)) {
1467 dev_err(ice_pf_to_dev(vsi->back), "Failed to stop all Rx rings on VSI %d\n",
1469 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1473 bitmap_zero(vf->rxq_ena, ICE_MAX_RSS_QS_PER_VF);
1475 for_each_set_bit(vf_q_id, &q_map, ICE_MAX_RSS_QS_PER_VF) {
1476 if (!ice_vc_isvalid_q_id(vsi, vf_q_id)) {
1477 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1481 /* Skip queue if not enabled */
1482 if (!test_bit(vf_q_id, vf->rxq_ena))
1485 if (ice_vsi_ctrl_one_rx_ring(vsi, false, vf_q_id,
1487 dev_err(ice_pf_to_dev(vsi->back), "Failed to stop Rx ring %d on VSI %d\n",
1488 vf_q_id, vsi->vsi_num);
1489 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1493 /* Clear enabled queues flag */
1494 clear_bit(vf_q_id, vf->rxq_ena);
1498 /* Clear enabled queues flag */
1499 if (v_ret == VIRTCHNL_STATUS_SUCCESS && ice_vf_has_no_qs_ena(vf))
1500 clear_bit(ICE_VF_STATE_QS_ENA, vf->vf_states);
1503 /* send the response to the VF */
1504 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_DISABLE_QUEUES, v_ret,
1510 * @vf: pointer to the VF info
1511 * @vsi: the VSI being configured
1512 * @map: vector map for mapping vectors to queues
1513 * @q_vector: structure for interrupt vector
1514 * configure the IRQ to queue map
1516 static enum virtchnl_status_code
1517 ice_cfg_interrupt(struct ice_vf *vf, struct ice_vsi *vsi,
1518 struct virtchnl_vector_map *map,
1519 struct ice_q_vector *q_vector)
1521 u16 vsi_q_id, vsi_q_id_idx;
1524 q_vector->num_ring_rx = 0;
1525 q_vector->num_ring_tx = 0;
1527 qmap = map->rxq_map;
1528 for_each_set_bit(vsi_q_id_idx, &qmap, ICE_MAX_RSS_QS_PER_VF) {
1529 vsi_q_id = vsi_q_id_idx;
1531 if (!ice_vc_isvalid_q_id(vsi, vsi_q_id))
1532 return VIRTCHNL_STATUS_ERR_PARAM;
1534 q_vector->num_ring_rx++;
1535 q_vector->rx.itr_idx = map->rxitr_idx;
1536 vsi->rx_rings[vsi_q_id]->q_vector = q_vector;
1537 ice_cfg_rxq_interrupt(vsi, vsi_q_id,
1538 q_vector->vf_reg_idx,
1539 q_vector->rx.itr_idx);
1542 qmap = map->txq_map;
1543 for_each_set_bit(vsi_q_id_idx, &qmap, ICE_MAX_RSS_QS_PER_VF) {
1544 vsi_q_id = vsi_q_id_idx;
1546 if (!ice_vc_isvalid_q_id(vsi, vsi_q_id))
1547 return VIRTCHNL_STATUS_ERR_PARAM;
1549 q_vector->num_ring_tx++;
1550 q_vector->tx.itr_idx = map->txitr_idx;
1551 vsi->tx_rings[vsi_q_id]->q_vector = q_vector;
1552 ice_cfg_txq_interrupt(vsi, vsi_q_id,
1553 q_vector->vf_reg_idx,
1554 q_vector->tx.itr_idx);
1557 return VIRTCHNL_STATUS_SUCCESS;
1561 * ice_vc_cfg_irq_map_msg
1562 * @vf: pointer to the VF info
1563 * @msg: pointer to the msg buffer
1565 * called from the VF to configure the IRQ to queue map
1567 static int ice_vc_cfg_irq_map_msg(struct ice_vf *vf, u8 *msg)
1569 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
1570 u16 num_q_vectors_mapped, vsi_id, vector_id;
1571 struct virtchnl_irq_map_info *irqmap_info;
1572 struct virtchnl_vector_map *map;
1573 struct ice_vsi *vsi;
1576 irqmap_info = (struct virtchnl_irq_map_info *)msg;
1577 num_q_vectors_mapped = irqmap_info->num_vectors;
1579 /* Check to make sure number of VF vectors mapped is not greater than
1580 * number of VF vectors originally allocated, and check that
1581 * there is actually at least a single VF queue vector mapped
1583 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states) ||
1584 vf->num_msix < num_q_vectors_mapped ||
1585 !num_q_vectors_mapped) {
1586 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1590 vsi = ice_get_vf_vsi(vf);
1592 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1596 for (i = 0; i < num_q_vectors_mapped; i++) {
1597 struct ice_q_vector *q_vector;
1599 map = &irqmap_info->vecmap[i];
1601 vector_id = map->vector_id;
1602 vsi_id = map->vsi_id;
1603 /* vector_id is always 0-based for each VF, and can never be
1604 * larger than or equal to the max allowed interrupts per VF
1606 if (!(vector_id < vf->num_msix) ||
1607 !ice_vc_isvalid_vsi_id(vf, vsi_id) ||
1608 (!vector_id && (map->rxq_map || map->txq_map))) {
1609 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1613 /* No need to map VF miscellaneous or rogue vector */
1617 /* Subtract non queue vector from vector_id passed by VF
1618 * to get actual number of VSI queue vector array index
1620 q_vector = vsi->q_vectors[vector_id - ICE_NONQ_VECS_VF];
1622 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1626 /* lookout for the invalid queue index */
1627 v_ret = ice_cfg_interrupt(vf, vsi, map, q_vector);
1633 /* send the response to the VF */
1634 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_CONFIG_IRQ_MAP, v_ret,
1640 * @vf: pointer to the VF info
1641 * @msg: pointer to the msg buffer
1643 * called from the VF to configure the Rx/Tx queues
1645 static int ice_vc_cfg_qs_msg(struct ice_vf *vf, u8 *msg)
1647 struct virtchnl_vsi_queue_config_info *qci =
1648 (struct virtchnl_vsi_queue_config_info *)msg;
1649 struct virtchnl_queue_pair_info *qpi;
1650 struct ice_pf *pf = vf->pf;
1651 struct ice_lag *lag;
1652 struct ice_vsi *vsi;
1653 u8 act_prt, pri_prt;
1657 mutex_lock(&pf->lag_mutex);
1658 act_prt = ICE_LAG_INVALID_PORT;
1659 pri_prt = pf->hw.port_info->lport;
1660 if (lag && lag->bonded && lag->primary) {
1661 act_prt = lag->active_port;
1662 if (act_prt != pri_prt && act_prt != ICE_LAG_INVALID_PORT &&
1664 ice_lag_move_vf_nodes_cfg(lag, act_prt, pri_prt);
1666 act_prt = ICE_LAG_INVALID_PORT;
1669 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states))
1672 if (!ice_vc_isvalid_vsi_id(vf, qci->vsi_id))
1675 vsi = ice_get_vf_vsi(vf);
1679 if (qci->num_queue_pairs > ICE_MAX_RSS_QS_PER_VF ||
1680 qci->num_queue_pairs > min_t(u16, vsi->alloc_txq, vsi->alloc_rxq)) {
1681 dev_err(ice_pf_to_dev(pf), "VF-%d requesting more than supported number of queues: %d\n",
1682 vf->vf_id, min_t(u16, vsi->alloc_txq, vsi->alloc_rxq));
1686 for (i = 0; i < qci->num_queue_pairs; i++) {
1687 if (!qci->qpair[i].rxq.crc_disable)
1690 if (!(vf->driver_caps & VIRTCHNL_VF_OFFLOAD_CRC) ||
1695 for (i = 0; i < qci->num_queue_pairs; i++) {
1696 qpi = &qci->qpair[i];
1697 if (qpi->txq.vsi_id != qci->vsi_id ||
1698 qpi->rxq.vsi_id != qci->vsi_id ||
1699 qpi->rxq.queue_id != qpi->txq.queue_id ||
1700 qpi->txq.headwb_enabled ||
1701 !ice_vc_isvalid_ring_len(qpi->txq.ring_len) ||
1702 !ice_vc_isvalid_ring_len(qpi->rxq.ring_len) ||
1703 !ice_vc_isvalid_q_id(vsi, qpi->txq.queue_id)) {
1707 q_idx = qpi->rxq.queue_id;
1709 /* make sure selected "q_idx" is in valid range of queues
1710 * for selected "vsi"
1712 if (q_idx >= vsi->alloc_txq || q_idx >= vsi->alloc_rxq) {
1716 /* copy Tx queue info from VF into VSI */
1717 if (qpi->txq.ring_len > 0) {
1718 vsi->tx_rings[i]->dma = qpi->txq.dma_ring_addr;
1719 vsi->tx_rings[i]->count = qpi->txq.ring_len;
1721 /* Disable any existing queue first */
1722 if (ice_vf_vsi_dis_single_txq(vf, vsi, q_idx))
1725 /* Configure a queue with the requested settings */
1726 if (ice_vsi_cfg_single_txq(vsi, vsi->tx_rings, q_idx)) {
1727 dev_warn(ice_pf_to_dev(pf), "VF-%d failed to configure TX queue %d\n",
1733 /* copy Rx queue info from VF into VSI */
1734 if (qpi->rxq.ring_len > 0) {
1735 u16 max_frame_size = ice_vc_get_max_frame_size(vf);
1738 vsi->rx_rings[i]->dma = qpi->rxq.dma_ring_addr;
1739 vsi->rx_rings[i]->count = qpi->rxq.ring_len;
1741 if (qpi->rxq.crc_disable)
1742 vsi->rx_rings[q_idx]->flags |=
1743 ICE_RX_FLAGS_CRC_STRIP_DIS;
1745 vsi->rx_rings[q_idx]->flags &=
1746 ~ICE_RX_FLAGS_CRC_STRIP_DIS;
1748 if (qpi->rxq.databuffer_size != 0 &&
1749 (qpi->rxq.databuffer_size > ((16 * 1024) - 128) ||
1750 qpi->rxq.databuffer_size < 1024))
1752 vsi->rx_buf_len = qpi->rxq.databuffer_size;
1753 vsi->rx_rings[i]->rx_buf_len = vsi->rx_buf_len;
1754 if (qpi->rxq.max_pkt_size > max_frame_size ||
1755 qpi->rxq.max_pkt_size < 64)
1758 vsi->max_frame = qpi->rxq.max_pkt_size;
1759 /* add space for the port VLAN since the VF driver is
1760 * not expected to account for it in the MTU
1763 if (ice_vf_is_port_vlan_ena(vf))
1764 vsi->max_frame += VLAN_HLEN;
1766 if (ice_vsi_cfg_single_rxq(vsi, q_idx)) {
1767 dev_warn(ice_pf_to_dev(pf), "VF-%d failed to configure RX queue %d\n",
1772 /* If Rx flex desc is supported, select RXDID for Rx
1773 * queues. Otherwise, use legacy 32byte descriptor
1774 * format. Legacy 16byte descriptor is not supported.
1775 * If this RXDID is selected, return error.
1777 if (vf->driver_caps &
1778 VIRTCHNL_VF_OFFLOAD_RX_FLEX_DESC) {
1779 rxdid = qpi->rxq.rxdid;
1780 if (!(BIT(rxdid) & pf->supported_rxdids))
1783 rxdid = ICE_RXDID_LEGACY_1;
1786 ice_write_qrxflxp_cntxt(&vsi->back->hw,
1787 vsi->rxq_map[q_idx],
1788 rxdid, 0x03, false);
1792 if (lag && lag->bonded && lag->primary &&
1793 act_prt != ICE_LAG_INVALID_PORT)
1794 ice_lag_move_vf_nodes_cfg(lag, pri_prt, act_prt);
1795 mutex_unlock(&pf->lag_mutex);
1797 /* send the response to the VF */
1798 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_CONFIG_VSI_QUEUES,
1799 VIRTCHNL_STATUS_SUCCESS, NULL, 0);
1801 /* disable whatever we can */
1802 for (; i >= 0; i--) {
1803 if (ice_vsi_ctrl_one_rx_ring(vsi, false, i, true))
1804 dev_err(ice_pf_to_dev(pf), "VF-%d could not disable RX queue %d\n",
1806 if (ice_vf_vsi_dis_single_txq(vf, vsi, i))
1807 dev_err(ice_pf_to_dev(pf), "VF-%d could not disable TX queue %d\n",
1811 if (lag && lag->bonded && lag->primary &&
1812 act_prt != ICE_LAG_INVALID_PORT)
1813 ice_lag_move_vf_nodes_cfg(lag, pri_prt, act_prt);
1814 mutex_unlock(&pf->lag_mutex);
1816 ice_lag_move_new_vf_nodes(vf);
1818 /* send the response to the VF */
1819 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_CONFIG_VSI_QUEUES,
1820 VIRTCHNL_STATUS_ERR_PARAM, NULL, 0);
1824 * ice_can_vf_change_mac
1825 * @vf: pointer to the VF info
1827 * Return true if the VF is allowed to change its MAC filters, false otherwise
1829 static bool ice_can_vf_change_mac(struct ice_vf *vf)
1831 /* If the VF MAC address has been set administratively (via the
1832 * ndo_set_vf_mac command), then deny permission to the VF to
1833 * add/delete unicast MAC addresses, unless the VF is trusted
1835 if (vf->pf_set_mac && !ice_is_vf_trusted(vf))
1842 * ice_vc_ether_addr_type - get type of virtchnl_ether_addr
1843 * @vc_ether_addr: used to extract the type
1846 ice_vc_ether_addr_type(struct virtchnl_ether_addr *vc_ether_addr)
1848 return (vc_ether_addr->type & VIRTCHNL_ETHER_ADDR_TYPE_MASK);
1852 * ice_is_vc_addr_legacy - check if the MAC address is from an older VF
1853 * @vc_ether_addr: VIRTCHNL structure that contains MAC and type
1856 ice_is_vc_addr_legacy(struct virtchnl_ether_addr *vc_ether_addr)
1858 u8 type = ice_vc_ether_addr_type(vc_ether_addr);
1860 return (type == VIRTCHNL_ETHER_ADDR_LEGACY);
1864 * ice_is_vc_addr_primary - check if the MAC address is the VF's primary MAC
1865 * @vc_ether_addr: VIRTCHNL structure that contains MAC and type
1867 * This function should only be called when the MAC address in
1868 * virtchnl_ether_addr is a valid unicast MAC
1871 ice_is_vc_addr_primary(struct virtchnl_ether_addr __maybe_unused *vc_ether_addr)
1873 u8 type = ice_vc_ether_addr_type(vc_ether_addr);
1875 return (type == VIRTCHNL_ETHER_ADDR_PRIMARY);
1879 * ice_vfhw_mac_add - update the VF's cached hardware MAC if allowed
1881 * @vc_ether_addr: structure from VIRTCHNL with MAC to add
1884 ice_vfhw_mac_add(struct ice_vf *vf, struct virtchnl_ether_addr *vc_ether_addr)
1886 u8 *mac_addr = vc_ether_addr->addr;
1888 if (!is_valid_ether_addr(mac_addr))
1891 /* only allow legacy VF drivers to set the device and hardware MAC if it
1892 * is zero and allow new VF drivers to set the hardware MAC if the type
1893 * was correctly specified over VIRTCHNL
1895 if ((ice_is_vc_addr_legacy(vc_ether_addr) &&
1896 is_zero_ether_addr(vf->hw_lan_addr)) ||
1897 ice_is_vc_addr_primary(vc_ether_addr)) {
1898 ether_addr_copy(vf->dev_lan_addr, mac_addr);
1899 ether_addr_copy(vf->hw_lan_addr, mac_addr);
1902 /* hardware and device MACs are already set, but its possible that the
1903 * VF driver sent the VIRTCHNL_OP_ADD_ETH_ADDR message before the
1904 * VIRTCHNL_OP_DEL_ETH_ADDR when trying to update its MAC, so save it
1905 * away for the legacy VF driver case as it will be updated in the
1906 * delete flow for this case
1908 if (ice_is_vc_addr_legacy(vc_ether_addr)) {
1909 ether_addr_copy(vf->legacy_last_added_umac.addr,
1911 vf->legacy_last_added_umac.time_modified = jiffies;
1916 * ice_vc_add_mac_addr - attempt to add the MAC address passed in
1917 * @vf: pointer to the VF info
1918 * @vsi: pointer to the VF's VSI
1919 * @vc_ether_addr: VIRTCHNL MAC address structure used to add MAC
1922 ice_vc_add_mac_addr(struct ice_vf *vf, struct ice_vsi *vsi,
1923 struct virtchnl_ether_addr *vc_ether_addr)
1925 struct device *dev = ice_pf_to_dev(vf->pf);
1926 u8 *mac_addr = vc_ether_addr->addr;
1929 /* device MAC already added */
1930 if (ether_addr_equal(mac_addr, vf->dev_lan_addr))
1933 if (is_unicast_ether_addr(mac_addr) && !ice_can_vf_change_mac(vf)) {
1934 dev_err(dev, "VF attempting to override administratively set MAC address, bring down and up the VF interface to resume normal operation\n");
1938 ret = ice_fltr_add_mac(vsi, mac_addr, ICE_FWD_TO_VSI);
1939 if (ret == -EEXIST) {
1940 dev_dbg(dev, "MAC %pM already exists for VF %d\n", mac_addr,
1942 /* don't return since we might need to update
1943 * the primary MAC in ice_vfhw_mac_add() below
1946 dev_err(dev, "Failed to add MAC %pM for VF %d\n, error %d\n",
1947 mac_addr, vf->vf_id, ret);
1953 ice_vfhw_mac_add(vf, vc_ether_addr);
1959 * ice_is_legacy_umac_expired - check if last added legacy unicast MAC expired
1960 * @last_added_umac: structure used to check expiration
1962 static bool ice_is_legacy_umac_expired(struct ice_time_mac *last_added_umac)
1964 #define ICE_LEGACY_VF_MAC_CHANGE_EXPIRE_TIME msecs_to_jiffies(3000)
1965 return time_is_before_jiffies(last_added_umac->time_modified +
1966 ICE_LEGACY_VF_MAC_CHANGE_EXPIRE_TIME);
1970 * ice_update_legacy_cached_mac - update cached hardware MAC for legacy VF
1972 * @vc_ether_addr: structure from VIRTCHNL with MAC to check
1974 * only update cached hardware MAC for legacy VF drivers on delete
1975 * because we cannot guarantee order/type of MAC from the VF driver
1978 ice_update_legacy_cached_mac(struct ice_vf *vf,
1979 struct virtchnl_ether_addr *vc_ether_addr)
1981 if (!ice_is_vc_addr_legacy(vc_ether_addr) ||
1982 ice_is_legacy_umac_expired(&vf->legacy_last_added_umac))
1985 ether_addr_copy(vf->dev_lan_addr, vf->legacy_last_added_umac.addr);
1986 ether_addr_copy(vf->hw_lan_addr, vf->legacy_last_added_umac.addr);
1990 * ice_vfhw_mac_del - update the VF's cached hardware MAC if allowed
1992 * @vc_ether_addr: structure from VIRTCHNL with MAC to delete
1995 ice_vfhw_mac_del(struct ice_vf *vf, struct virtchnl_ether_addr *vc_ether_addr)
1997 u8 *mac_addr = vc_ether_addr->addr;
1999 if (!is_valid_ether_addr(mac_addr) ||
2000 !ether_addr_equal(vf->dev_lan_addr, mac_addr))
2003 /* allow the device MAC to be repopulated in the add flow and don't
2004 * clear the hardware MAC (i.e. hw_lan_addr) here as that is meant
2005 * to be persistent on VM reboot and across driver unload/load, which
2006 * won't work if we clear the hardware MAC here
2008 eth_zero_addr(vf->dev_lan_addr);
2010 ice_update_legacy_cached_mac(vf, vc_ether_addr);
2014 * ice_vc_del_mac_addr - attempt to delete the MAC address passed in
2015 * @vf: pointer to the VF info
2016 * @vsi: pointer to the VF's VSI
2017 * @vc_ether_addr: VIRTCHNL MAC address structure used to delete MAC
2020 ice_vc_del_mac_addr(struct ice_vf *vf, struct ice_vsi *vsi,
2021 struct virtchnl_ether_addr *vc_ether_addr)
2023 struct device *dev = ice_pf_to_dev(vf->pf);
2024 u8 *mac_addr = vc_ether_addr->addr;
2027 if (!ice_can_vf_change_mac(vf) &&
2028 ether_addr_equal(vf->dev_lan_addr, mac_addr))
2031 status = ice_fltr_remove_mac(vsi, mac_addr, ICE_FWD_TO_VSI);
2032 if (status == -ENOENT) {
2033 dev_err(dev, "MAC %pM does not exist for VF %d\n", mac_addr,
2036 } else if (status) {
2037 dev_err(dev, "Failed to delete MAC %pM for VF %d, error %d\n",
2038 mac_addr, vf->vf_id, status);
2042 ice_vfhw_mac_del(vf, vc_ether_addr);
2050 * ice_vc_handle_mac_addr_msg
2051 * @vf: pointer to the VF info
2052 * @msg: pointer to the msg buffer
2053 * @set: true if MAC filters are being set, false otherwise
2055 * add guest MAC address filter
2058 ice_vc_handle_mac_addr_msg(struct ice_vf *vf, u8 *msg, bool set)
2060 int (*ice_vc_cfg_mac)
2061 (struct ice_vf *vf, struct ice_vsi *vsi,
2062 struct virtchnl_ether_addr *virtchnl_ether_addr);
2063 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
2064 struct virtchnl_ether_addr_list *al =
2065 (struct virtchnl_ether_addr_list *)msg;
2066 struct ice_pf *pf = vf->pf;
2067 enum virtchnl_ops vc_op;
2068 struct ice_vsi *vsi;
2072 vc_op = VIRTCHNL_OP_ADD_ETH_ADDR;
2073 ice_vc_cfg_mac = ice_vc_add_mac_addr;
2075 vc_op = VIRTCHNL_OP_DEL_ETH_ADDR;
2076 ice_vc_cfg_mac = ice_vc_del_mac_addr;
2079 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states) ||
2080 !ice_vc_isvalid_vsi_id(vf, al->vsi_id)) {
2081 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2082 goto handle_mac_exit;
2085 /* If this VF is not privileged, then we can't add more than a
2086 * limited number of addresses. Check to make sure that the
2087 * additions do not push us over the limit.
2089 if (set && !ice_is_vf_trusted(vf) &&
2090 (vf->num_mac + al->num_elements) > ICE_MAX_MACADDR_PER_VF) {
2091 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",
2093 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2094 goto handle_mac_exit;
2097 vsi = ice_get_vf_vsi(vf);
2099 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2100 goto handle_mac_exit;
2103 for (i = 0; i < al->num_elements; i++) {
2104 u8 *mac_addr = al->list[i].addr;
2107 if (is_broadcast_ether_addr(mac_addr) ||
2108 is_zero_ether_addr(mac_addr))
2111 result = ice_vc_cfg_mac(vf, vsi, &al->list[i]);
2112 if (result == -EEXIST || result == -ENOENT) {
2114 } else if (result) {
2115 v_ret = VIRTCHNL_STATUS_ERR_ADMIN_QUEUE_ERROR;
2116 goto handle_mac_exit;
2121 /* send the response to the VF */
2122 return ice_vc_send_msg_to_vf(vf, vc_op, v_ret, NULL, 0);
2126 * ice_vc_add_mac_addr_msg
2127 * @vf: pointer to the VF info
2128 * @msg: pointer to the msg buffer
2130 * add guest MAC address filter
2132 static int ice_vc_add_mac_addr_msg(struct ice_vf *vf, u8 *msg)
2134 return ice_vc_handle_mac_addr_msg(vf, msg, true);
2138 * ice_vc_del_mac_addr_msg
2139 * @vf: pointer to the VF info
2140 * @msg: pointer to the msg buffer
2142 * remove guest MAC address filter
2144 static int ice_vc_del_mac_addr_msg(struct ice_vf *vf, u8 *msg)
2146 return ice_vc_handle_mac_addr_msg(vf, msg, false);
2150 * ice_vc_request_qs_msg
2151 * @vf: pointer to the VF info
2152 * @msg: pointer to the msg buffer
2154 * VFs get a default number of queues but can use this message to request a
2155 * different number. If the request is successful, PF will reset the VF and
2156 * return 0. If unsuccessful, PF will send message informing VF of number of
2157 * available queue pairs via virtchnl message response to VF.
2159 static int ice_vc_request_qs_msg(struct ice_vf *vf, u8 *msg)
2161 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
2162 struct virtchnl_vf_res_request *vfres =
2163 (struct virtchnl_vf_res_request *)msg;
2164 u16 req_queues = vfres->num_queue_pairs;
2165 struct ice_pf *pf = vf->pf;
2166 u16 max_allowed_vf_queues;
2167 u16 tx_rx_queue_left;
2171 dev = ice_pf_to_dev(pf);
2172 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
2173 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2177 cur_queues = vf->num_vf_qs;
2178 tx_rx_queue_left = min_t(u16, ice_get_avail_txq_count(pf),
2179 ice_get_avail_rxq_count(pf));
2180 max_allowed_vf_queues = tx_rx_queue_left + cur_queues;
2182 dev_err(dev, "VF %d tried to request 0 queues. Ignoring.\n",
2184 } else if (req_queues > ICE_MAX_RSS_QS_PER_VF) {
2185 dev_err(dev, "VF %d tried to request more than %d queues.\n",
2186 vf->vf_id, ICE_MAX_RSS_QS_PER_VF);
2187 vfres->num_queue_pairs = ICE_MAX_RSS_QS_PER_VF;
2188 } else if (req_queues > cur_queues &&
2189 req_queues - cur_queues > tx_rx_queue_left) {
2190 dev_warn(dev, "VF %d requested %u more queues, but only %u left.\n",
2191 vf->vf_id, req_queues - cur_queues, tx_rx_queue_left);
2192 vfres->num_queue_pairs = min_t(u16, max_allowed_vf_queues,
2193 ICE_MAX_RSS_QS_PER_VF);
2195 /* request is successful, then reset VF */
2196 vf->num_req_qs = req_queues;
2197 ice_reset_vf(vf, ICE_VF_RESET_NOTIFY);
2198 dev_info(dev, "VF %d granted request of %u queues.\n",
2199 vf->vf_id, req_queues);
2204 /* send the response to the VF */
2205 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_REQUEST_QUEUES,
2206 v_ret, (u8 *)vfres, sizeof(*vfres));
2210 * ice_vf_vlan_offload_ena - determine if capabilities support VLAN offloads
2211 * @caps: VF driver negotiated capabilities
2213 * Return true if VIRTCHNL_VF_OFFLOAD_VLAN capability is set, else return false
2215 static bool ice_vf_vlan_offload_ena(u32 caps)
2217 return !!(caps & VIRTCHNL_VF_OFFLOAD_VLAN);
2221 * ice_is_vlan_promisc_allowed - check if VLAN promiscuous config is allowed
2222 * @vf: VF used to determine if VLAN promiscuous config is allowed
2224 static bool ice_is_vlan_promisc_allowed(struct ice_vf *vf)
2226 if ((test_bit(ICE_VF_STATE_UC_PROMISC, vf->vf_states) ||
2227 test_bit(ICE_VF_STATE_MC_PROMISC, vf->vf_states)) &&
2228 test_bit(ICE_FLAG_VF_TRUE_PROMISC_ENA, vf->pf->flags))
2235 * ice_vf_ena_vlan_promisc - Enable Tx/Rx VLAN promiscuous for the VLAN
2236 * @vsi: VF's VSI used to enable VLAN promiscuous mode
2237 * @vlan: VLAN used to enable VLAN promiscuous
2239 * This function should only be called if VLAN promiscuous mode is allowed,
2240 * which can be determined via ice_is_vlan_promisc_allowed().
2242 static int ice_vf_ena_vlan_promisc(struct ice_vsi *vsi, struct ice_vlan *vlan)
2244 u8 promisc_m = ICE_PROMISC_VLAN_TX | ICE_PROMISC_VLAN_RX;
2247 status = ice_fltr_set_vsi_promisc(&vsi->back->hw, vsi->idx, promisc_m,
2249 if (status && status != -EEXIST)
2256 * ice_vf_dis_vlan_promisc - Disable Tx/Rx VLAN promiscuous for the VLAN
2257 * @vsi: VF's VSI used to disable VLAN promiscuous mode for
2258 * @vlan: VLAN used to disable VLAN promiscuous
2260 * This function should only be called if VLAN promiscuous mode is allowed,
2261 * which can be determined via ice_is_vlan_promisc_allowed().
2263 static int ice_vf_dis_vlan_promisc(struct ice_vsi *vsi, struct ice_vlan *vlan)
2265 u8 promisc_m = ICE_PROMISC_VLAN_TX | ICE_PROMISC_VLAN_RX;
2268 status = ice_fltr_clear_vsi_promisc(&vsi->back->hw, vsi->idx, promisc_m,
2270 if (status && status != -ENOENT)
2277 * ice_vf_has_max_vlans - check if VF already has the max allowed VLAN filters
2278 * @vf: VF to check against
2281 * If the VF is trusted then the VF is allowed to add as many VLANs as it
2282 * wants to, so return false.
2284 * When the VF is untrusted compare the number of non-zero VLANs + 1 to the max
2285 * allowed VLANs for an untrusted VF. Return the result of this comparison.
2287 static bool ice_vf_has_max_vlans(struct ice_vf *vf, struct ice_vsi *vsi)
2289 if (ice_is_vf_trusted(vf))
2292 #define ICE_VF_ADDED_VLAN_ZERO_FLTRS 1
2293 return ((ice_vsi_num_non_zero_vlans(vsi) +
2294 ICE_VF_ADDED_VLAN_ZERO_FLTRS) >= ICE_MAX_VLAN_PER_VF);
2298 * ice_vc_process_vlan_msg
2299 * @vf: pointer to the VF info
2300 * @msg: pointer to the msg buffer
2301 * @add_v: Add VLAN if true, otherwise delete VLAN
2303 * Process virtchnl op to add or remove programmed guest VLAN ID
2305 static int ice_vc_process_vlan_msg(struct ice_vf *vf, u8 *msg, bool add_v)
2307 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
2308 struct virtchnl_vlan_filter_list *vfl =
2309 (struct virtchnl_vlan_filter_list *)msg;
2310 struct ice_pf *pf = vf->pf;
2311 bool vlan_promisc = false;
2312 struct ice_vsi *vsi;
2317 dev = ice_pf_to_dev(pf);
2318 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
2319 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2323 if (!ice_vf_vlan_offload_ena(vf->driver_caps)) {
2324 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2328 if (!ice_vc_isvalid_vsi_id(vf, vfl->vsi_id)) {
2329 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2333 for (i = 0; i < vfl->num_elements; i++) {
2334 if (vfl->vlan_id[i] >= VLAN_N_VID) {
2335 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2336 dev_err(dev, "invalid VF VLAN id %d\n",
2342 vsi = ice_get_vf_vsi(vf);
2344 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2348 if (add_v && ice_vf_has_max_vlans(vf, vsi)) {
2349 dev_info(dev, "VF-%d is not trusted, switch the VF to trusted mode, in order to add more VLAN addresses\n",
2351 /* There is no need to let VF know about being not trusted,
2352 * so we can just return success message here
2357 /* in DVM a VF can add/delete inner VLAN filters when
2358 * VIRTCHNL_VF_OFFLOAD_VLAN is negotiated, so only reject in SVM
2360 if (ice_vf_is_port_vlan_ena(vf) && !ice_is_dvm_ena(&pf->hw)) {
2361 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2365 /* in DVM VLAN promiscuous is based on the outer VLAN, which would be
2366 * the port VLAN if VIRTCHNL_VF_OFFLOAD_VLAN was negotiated, so only
2367 * allow vlan_promisc = true in SVM and if no port VLAN is configured
2369 vlan_promisc = ice_is_vlan_promisc_allowed(vf) &&
2370 !ice_is_dvm_ena(&pf->hw) &&
2371 !ice_vf_is_port_vlan_ena(vf);
2374 for (i = 0; i < vfl->num_elements; i++) {
2375 u16 vid = vfl->vlan_id[i];
2376 struct ice_vlan vlan;
2378 if (ice_vf_has_max_vlans(vf, vsi)) {
2379 dev_info(dev, "VF-%d is not trusted, switch the VF to trusted mode, in order to add more VLAN addresses\n",
2381 /* There is no need to let VF know about being
2382 * not trusted, so we can just return success
2383 * message here as well.
2388 /* we add VLAN 0 by default for each VF so we can enable
2389 * Tx VLAN anti-spoof without triggering MDD events so
2390 * we don't need to add it again here
2395 vlan = ICE_VLAN(ETH_P_8021Q, vid, 0);
2396 status = vsi->inner_vlan_ops.add_vlan(vsi, &vlan);
2398 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2402 /* Enable VLAN filtering on first non-zero VLAN */
2403 if (!vlan_promisc && vid && !ice_is_dvm_ena(&pf->hw)) {
2405 status = vsi->inner_vlan_ops.ena_tx_filtering(vsi);
2407 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2408 dev_err(dev, "Enable VLAN anti-spoofing on VLAN ID: %d failed error-%d\n",
2413 if (vsi->inner_vlan_ops.ena_rx_filtering(vsi)) {
2414 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2415 dev_err(dev, "Enable VLAN pruning on VLAN ID: %d failed error-%d\n",
2419 } else if (vlan_promisc) {
2420 status = ice_vf_ena_vlan_promisc(vsi, &vlan);
2422 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2423 dev_err(dev, "Enable Unicast/multicast promiscuous mode on VLAN ID:%d failed error-%d\n",
2429 /* In case of non_trusted VF, number of VLAN elements passed
2430 * to PF for removal might be greater than number of VLANs
2431 * filter programmed for that VF - So, use actual number of
2432 * VLANS added earlier with add VLAN opcode. In order to avoid
2433 * removing VLAN that doesn't exist, which result to sending
2434 * erroneous failed message back to the VF
2438 num_vf_vlan = vsi->num_vlan;
2439 for (i = 0; i < vfl->num_elements && i < num_vf_vlan; i++) {
2440 u16 vid = vfl->vlan_id[i];
2441 struct ice_vlan vlan;
2443 /* we add VLAN 0 by default for each VF so we can enable
2444 * Tx VLAN anti-spoof without triggering MDD events so
2445 * we don't want a VIRTCHNL request to remove it
2450 vlan = ICE_VLAN(ETH_P_8021Q, vid, 0);
2451 status = vsi->inner_vlan_ops.del_vlan(vsi, &vlan);
2453 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2457 /* Disable VLAN filtering when only VLAN 0 is left */
2458 if (!ice_vsi_has_non_zero_vlans(vsi)) {
2459 vsi->inner_vlan_ops.dis_tx_filtering(vsi);
2460 vsi->inner_vlan_ops.dis_rx_filtering(vsi);
2464 ice_vf_dis_vlan_promisc(vsi, &vlan);
2469 /* send the response to the VF */
2471 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_ADD_VLAN, v_ret,
2474 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_DEL_VLAN, v_ret,
2479 * ice_vc_add_vlan_msg
2480 * @vf: pointer to the VF info
2481 * @msg: pointer to the msg buffer
2483 * Add and program guest VLAN ID
2485 static int ice_vc_add_vlan_msg(struct ice_vf *vf, u8 *msg)
2487 return ice_vc_process_vlan_msg(vf, msg, true);
2491 * ice_vc_remove_vlan_msg
2492 * @vf: pointer to the VF info
2493 * @msg: pointer to the msg buffer
2495 * remove programmed guest VLAN ID
2497 static int ice_vc_remove_vlan_msg(struct ice_vf *vf, u8 *msg)
2499 return ice_vc_process_vlan_msg(vf, msg, false);
2503 * ice_vsi_is_rxq_crc_strip_dis - check if Rx queue CRC strip is disabled or not
2504 * @vsi: pointer to the VF VSI info
2506 static bool ice_vsi_is_rxq_crc_strip_dis(struct ice_vsi *vsi)
2510 ice_for_each_alloc_rxq(vsi, i)
2511 if (vsi->rx_rings[i]->flags & ICE_RX_FLAGS_CRC_STRIP_DIS)
2518 * ice_vc_ena_vlan_stripping
2519 * @vf: pointer to the VF info
2521 * Enable VLAN header stripping for a given VF
2523 static int ice_vc_ena_vlan_stripping(struct ice_vf *vf)
2525 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
2526 struct ice_vsi *vsi;
2528 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
2529 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2533 if (!ice_vf_vlan_offload_ena(vf->driver_caps)) {
2534 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2538 vsi = ice_get_vf_vsi(vf);
2540 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2544 if (vsi->inner_vlan_ops.ena_stripping(vsi, ETH_P_8021Q))
2545 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2547 vf->vlan_strip_ena |= ICE_INNER_VLAN_STRIP_ENA;
2550 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_ENABLE_VLAN_STRIPPING,
2555 * ice_vc_dis_vlan_stripping
2556 * @vf: pointer to the VF info
2558 * Disable VLAN header stripping for a given VF
2560 static int ice_vc_dis_vlan_stripping(struct ice_vf *vf)
2562 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
2563 struct ice_vsi *vsi;
2565 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
2566 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2570 if (!ice_vf_vlan_offload_ena(vf->driver_caps)) {
2571 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2575 vsi = ice_get_vf_vsi(vf);
2577 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2581 if (vsi->inner_vlan_ops.dis_stripping(vsi))
2582 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2584 vf->vlan_strip_ena &= ~ICE_INNER_VLAN_STRIP_ENA;
2587 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_DISABLE_VLAN_STRIPPING,
2592 * ice_vc_get_rss_hena - return the RSS HENA bits allowed by the hardware
2593 * @vf: pointer to the VF info
2595 static int ice_vc_get_rss_hena(struct ice_vf *vf)
2597 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
2598 struct virtchnl_rss_hena *vrh = NULL;
2601 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
2602 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2606 if (!test_bit(ICE_FLAG_RSS_ENA, vf->pf->flags)) {
2607 dev_err(ice_pf_to_dev(vf->pf), "RSS not supported by PF\n");
2608 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2612 len = sizeof(struct virtchnl_rss_hena);
2613 vrh = kzalloc(len, GFP_KERNEL);
2615 v_ret = VIRTCHNL_STATUS_ERR_NO_MEMORY;
2620 vrh->hena = ICE_DEFAULT_RSS_HENA;
2622 /* send the response back to the VF */
2623 ret = ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_GET_RSS_HENA_CAPS, v_ret,
2630 * ice_vc_set_rss_hena - set RSS HENA bits for the VF
2631 * @vf: pointer to the VF info
2632 * @msg: pointer to the msg buffer
2634 static int ice_vc_set_rss_hena(struct ice_vf *vf, u8 *msg)
2636 struct virtchnl_rss_hena *vrh = (struct virtchnl_rss_hena *)msg;
2637 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
2638 struct ice_pf *pf = vf->pf;
2639 struct ice_vsi *vsi;
2643 dev = ice_pf_to_dev(pf);
2645 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
2646 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2650 if (!test_bit(ICE_FLAG_RSS_ENA, pf->flags)) {
2651 dev_err(dev, "RSS not supported by PF\n");
2652 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2656 vsi = ice_get_vf_vsi(vf);
2658 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2662 /* clear all previously programmed RSS configuration to allow VF drivers
2663 * the ability to customize the RSS configuration and/or completely
2666 status = ice_rem_vsi_rss_cfg(&pf->hw, vsi->idx);
2667 if (status && !vrh->hena) {
2668 /* only report failure to clear the current RSS configuration if
2669 * that was clearly the VF's intention (i.e. vrh->hena = 0)
2671 v_ret = ice_err_to_virt_err(status);
2673 } else if (status) {
2674 /* allow the VF to update the RSS configuration even on failure
2675 * to clear the current RSS confguration in an attempt to keep
2676 * RSS in a working state
2678 dev_warn(dev, "Failed to clear the RSS configuration for VF %u\n",
2683 status = ice_add_avf_rss_cfg(&pf->hw, vsi, vrh->hena);
2684 v_ret = ice_err_to_virt_err(status);
2687 /* send the response to the VF */
2689 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_SET_RSS_HENA, v_ret,
2694 * ice_vc_query_rxdid - query RXDID supported by DDP package
2695 * @vf: pointer to VF info
2697 * Called from VF to query a bitmap of supported flexible
2698 * descriptor RXDIDs of a DDP package.
2700 static int ice_vc_query_rxdid(struct ice_vf *vf)
2702 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
2703 struct virtchnl_supported_rxdids *rxdid = NULL;
2704 struct ice_hw *hw = &vf->pf->hw;
2705 struct ice_pf *pf = vf->pf;
2710 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
2711 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2715 if (!(vf->driver_caps & VIRTCHNL_VF_OFFLOAD_RX_FLEX_DESC)) {
2716 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2720 len = sizeof(struct virtchnl_supported_rxdids);
2721 rxdid = kzalloc(len, GFP_KERNEL);
2723 v_ret = VIRTCHNL_STATUS_ERR_NO_MEMORY;
2728 /* RXDIDs supported by DDP package can be read from the register
2729 * to get the supported RXDID bitmap. But the legacy 32byte RXDID
2730 * is not listed in DDP package, add it in the bitmap manually.
2731 * Legacy 16byte descriptor is not supported.
2733 rxdid->supported_rxdids |= BIT(ICE_RXDID_LEGACY_1);
2735 for (i = ICE_RXDID_FLEX_NIC; i < ICE_FLEX_DESC_RXDID_MAX_NUM; i++) {
2736 regval = rd32(hw, GLFLXP_RXDID_FLAGS(i, 0));
2737 if ((regval >> GLFLXP_RXDID_FLAGS_FLEXIFLAG_4N_S)
2738 & GLFLXP_RXDID_FLAGS_FLEXIFLAG_4N_M)
2739 rxdid->supported_rxdids |= BIT(i);
2742 pf->supported_rxdids = rxdid->supported_rxdids;
2745 ret = ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_GET_SUPPORTED_RXDIDS,
2746 v_ret, (u8 *)rxdid, len);
2752 * ice_vf_init_vlan_stripping - enable/disable VLAN stripping on initialization
2753 * @vf: VF to enable/disable VLAN stripping for on initialization
2755 * Set the default for VLAN stripping based on whether a port VLAN is configured
2756 * and the current VLAN mode of the device.
2758 static int ice_vf_init_vlan_stripping(struct ice_vf *vf)
2760 struct ice_vsi *vsi = ice_get_vf_vsi(vf);
2762 vf->vlan_strip_ena = 0;
2767 /* don't modify stripping if port VLAN is configured in SVM since the
2768 * port VLAN is based on the inner/single VLAN in SVM
2770 if (ice_vf_is_port_vlan_ena(vf) && !ice_is_dvm_ena(&vsi->back->hw))
2773 if (ice_vf_vlan_offload_ena(vf->driver_caps)) {
2776 err = vsi->inner_vlan_ops.ena_stripping(vsi, ETH_P_8021Q);
2778 vf->vlan_strip_ena |= ICE_INNER_VLAN_STRIP_ENA;
2782 return vsi->inner_vlan_ops.dis_stripping(vsi);
2785 static u16 ice_vc_get_max_vlan_fltrs(struct ice_vf *vf)
2790 return ICE_MAX_VLAN_PER_VF;
2794 * ice_vf_outer_vlan_not_allowed - check if outer VLAN can be used
2795 * @vf: VF that being checked for
2797 * When the device is in double VLAN mode, check whether or not the outer VLAN
2800 static bool ice_vf_outer_vlan_not_allowed(struct ice_vf *vf)
2802 if (ice_vf_is_port_vlan_ena(vf))
2809 * ice_vc_set_dvm_caps - set VLAN capabilities when the device is in DVM
2810 * @vf: VF that capabilities are being set for
2811 * @caps: VLAN capabilities to populate
2813 * Determine VLAN capabilities support based on whether a port VLAN is
2814 * configured. If a port VLAN is configured then the VF should use the inner
2815 * filtering/offload capabilities since the port VLAN is using the outer VLAN
2819 ice_vc_set_dvm_caps(struct ice_vf *vf, struct virtchnl_vlan_caps *caps)
2821 struct virtchnl_vlan_supported_caps *supported_caps;
2823 if (ice_vf_outer_vlan_not_allowed(vf)) {
2824 /* until support for inner VLAN filtering is added when a port
2825 * VLAN is configured, only support software offloaded inner
2826 * VLANs when a port VLAN is confgured in DVM
2828 supported_caps = &caps->filtering.filtering_support;
2829 supported_caps->inner = VIRTCHNL_VLAN_UNSUPPORTED;
2831 supported_caps = &caps->offloads.stripping_support;
2832 supported_caps->inner = VIRTCHNL_VLAN_ETHERTYPE_8100 |
2833 VIRTCHNL_VLAN_TOGGLE |
2834 VIRTCHNL_VLAN_TAG_LOCATION_L2TAG1;
2835 supported_caps->outer = VIRTCHNL_VLAN_UNSUPPORTED;
2837 supported_caps = &caps->offloads.insertion_support;
2838 supported_caps->inner = VIRTCHNL_VLAN_ETHERTYPE_8100 |
2839 VIRTCHNL_VLAN_TOGGLE |
2840 VIRTCHNL_VLAN_TAG_LOCATION_L2TAG1;
2841 supported_caps->outer = VIRTCHNL_VLAN_UNSUPPORTED;
2843 caps->offloads.ethertype_init = VIRTCHNL_VLAN_ETHERTYPE_8100;
2844 caps->offloads.ethertype_match =
2845 VIRTCHNL_ETHERTYPE_STRIPPING_MATCHES_INSERTION;
2847 supported_caps = &caps->filtering.filtering_support;
2848 supported_caps->inner = VIRTCHNL_VLAN_UNSUPPORTED;
2849 supported_caps->outer = VIRTCHNL_VLAN_ETHERTYPE_8100 |
2850 VIRTCHNL_VLAN_ETHERTYPE_88A8 |
2851 VIRTCHNL_VLAN_ETHERTYPE_9100 |
2852 VIRTCHNL_VLAN_ETHERTYPE_AND;
2853 caps->filtering.ethertype_init = VIRTCHNL_VLAN_ETHERTYPE_8100 |
2854 VIRTCHNL_VLAN_ETHERTYPE_88A8 |
2855 VIRTCHNL_VLAN_ETHERTYPE_9100;
2857 supported_caps = &caps->offloads.stripping_support;
2858 supported_caps->inner = VIRTCHNL_VLAN_TOGGLE |
2859 VIRTCHNL_VLAN_ETHERTYPE_8100 |
2860 VIRTCHNL_VLAN_TAG_LOCATION_L2TAG1;
2861 supported_caps->outer = VIRTCHNL_VLAN_TOGGLE |
2862 VIRTCHNL_VLAN_ETHERTYPE_8100 |
2863 VIRTCHNL_VLAN_ETHERTYPE_88A8 |
2864 VIRTCHNL_VLAN_ETHERTYPE_9100 |
2865 VIRTCHNL_VLAN_ETHERTYPE_XOR |
2866 VIRTCHNL_VLAN_TAG_LOCATION_L2TAG2_2;
2868 supported_caps = &caps->offloads.insertion_support;
2869 supported_caps->inner = VIRTCHNL_VLAN_TOGGLE |
2870 VIRTCHNL_VLAN_ETHERTYPE_8100 |
2871 VIRTCHNL_VLAN_TAG_LOCATION_L2TAG1;
2872 supported_caps->outer = VIRTCHNL_VLAN_TOGGLE |
2873 VIRTCHNL_VLAN_ETHERTYPE_8100 |
2874 VIRTCHNL_VLAN_ETHERTYPE_88A8 |
2875 VIRTCHNL_VLAN_ETHERTYPE_9100 |
2876 VIRTCHNL_VLAN_ETHERTYPE_XOR |
2877 VIRTCHNL_VLAN_TAG_LOCATION_L2TAG2;
2879 caps->offloads.ethertype_init = VIRTCHNL_VLAN_ETHERTYPE_8100;
2881 caps->offloads.ethertype_match =
2882 VIRTCHNL_ETHERTYPE_STRIPPING_MATCHES_INSERTION;
2885 caps->filtering.max_filters = ice_vc_get_max_vlan_fltrs(vf);
2889 * ice_vc_set_svm_caps - set VLAN capabilities when the device is in SVM
2890 * @vf: VF that capabilities are being set for
2891 * @caps: VLAN capabilities to populate
2893 * Determine VLAN capabilities support based on whether a port VLAN is
2894 * configured. If a port VLAN is configured then the VF does not have any VLAN
2895 * filtering or offload capabilities since the port VLAN is using the inner VLAN
2896 * capabilities in single VLAN mode (SVM). Otherwise allow the VF to use inner
2897 * VLAN fitlering and offload capabilities.
2900 ice_vc_set_svm_caps(struct ice_vf *vf, struct virtchnl_vlan_caps *caps)
2902 struct virtchnl_vlan_supported_caps *supported_caps;
2904 if (ice_vf_is_port_vlan_ena(vf)) {
2905 supported_caps = &caps->filtering.filtering_support;
2906 supported_caps->inner = VIRTCHNL_VLAN_UNSUPPORTED;
2907 supported_caps->outer = VIRTCHNL_VLAN_UNSUPPORTED;
2909 supported_caps = &caps->offloads.stripping_support;
2910 supported_caps->inner = VIRTCHNL_VLAN_UNSUPPORTED;
2911 supported_caps->outer = VIRTCHNL_VLAN_UNSUPPORTED;
2913 supported_caps = &caps->offloads.insertion_support;
2914 supported_caps->inner = VIRTCHNL_VLAN_UNSUPPORTED;
2915 supported_caps->outer = VIRTCHNL_VLAN_UNSUPPORTED;
2917 caps->offloads.ethertype_init = VIRTCHNL_VLAN_UNSUPPORTED;
2918 caps->offloads.ethertype_match = VIRTCHNL_VLAN_UNSUPPORTED;
2919 caps->filtering.max_filters = 0;
2921 supported_caps = &caps->filtering.filtering_support;
2922 supported_caps->inner = VIRTCHNL_VLAN_ETHERTYPE_8100;
2923 supported_caps->outer = VIRTCHNL_VLAN_UNSUPPORTED;
2924 caps->filtering.ethertype_init = VIRTCHNL_VLAN_ETHERTYPE_8100;
2926 supported_caps = &caps->offloads.stripping_support;
2927 supported_caps->inner = VIRTCHNL_VLAN_ETHERTYPE_8100 |
2928 VIRTCHNL_VLAN_TOGGLE |
2929 VIRTCHNL_VLAN_TAG_LOCATION_L2TAG1;
2930 supported_caps->outer = VIRTCHNL_VLAN_UNSUPPORTED;
2932 supported_caps = &caps->offloads.insertion_support;
2933 supported_caps->inner = VIRTCHNL_VLAN_ETHERTYPE_8100 |
2934 VIRTCHNL_VLAN_TOGGLE |
2935 VIRTCHNL_VLAN_TAG_LOCATION_L2TAG1;
2936 supported_caps->outer = VIRTCHNL_VLAN_UNSUPPORTED;
2938 caps->offloads.ethertype_init = VIRTCHNL_VLAN_ETHERTYPE_8100;
2939 caps->offloads.ethertype_match =
2940 VIRTCHNL_ETHERTYPE_STRIPPING_MATCHES_INSERTION;
2941 caps->filtering.max_filters = ice_vc_get_max_vlan_fltrs(vf);
2946 * ice_vc_get_offload_vlan_v2_caps - determine VF's VLAN capabilities
2947 * @vf: VF to determine VLAN capabilities for
2949 * This will only be called if the VF and PF successfully negotiated
2950 * VIRTCHNL_VF_OFFLOAD_VLAN_V2.
2952 * Set VLAN capabilities based on the current VLAN mode and whether a port VLAN
2953 * is configured or not.
2955 static int ice_vc_get_offload_vlan_v2_caps(struct ice_vf *vf)
2957 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
2958 struct virtchnl_vlan_caps *caps = NULL;
2961 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
2962 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2966 caps = kzalloc(sizeof(*caps), GFP_KERNEL);
2968 v_ret = VIRTCHNL_STATUS_ERR_NO_MEMORY;
2971 len = sizeof(*caps);
2973 if (ice_is_dvm_ena(&vf->pf->hw))
2974 ice_vc_set_dvm_caps(vf, caps);
2976 ice_vc_set_svm_caps(vf, caps);
2978 /* store negotiated caps to prevent invalid VF messages */
2979 memcpy(&vf->vlan_v2_caps, caps, sizeof(*caps));
2982 err = ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS,
2983 v_ret, (u8 *)caps, len);
2989 * ice_vc_validate_vlan_tpid - validate VLAN TPID
2990 * @filtering_caps: negotiated/supported VLAN filtering capabilities
2991 * @tpid: VLAN TPID used for validation
2993 * Convert the VLAN TPID to a VIRTCHNL_VLAN_ETHERTYPE_* and then compare against
2994 * the negotiated/supported filtering caps to see if the VLAN TPID is valid.
2996 static bool ice_vc_validate_vlan_tpid(u16 filtering_caps, u16 tpid)
2998 enum virtchnl_vlan_support vlan_ethertype = VIRTCHNL_VLAN_UNSUPPORTED;
3002 vlan_ethertype = VIRTCHNL_VLAN_ETHERTYPE_8100;
3005 vlan_ethertype = VIRTCHNL_VLAN_ETHERTYPE_88A8;
3008 vlan_ethertype = VIRTCHNL_VLAN_ETHERTYPE_9100;
3012 if (!(filtering_caps & vlan_ethertype))
3019 * ice_vc_is_valid_vlan - validate the virtchnl_vlan
3020 * @vc_vlan: virtchnl_vlan to validate
3022 * If the VLAN TCI and VLAN TPID are 0, then this filter is invalid, so return
3023 * false. Otherwise return true.
3025 static bool ice_vc_is_valid_vlan(struct virtchnl_vlan *vc_vlan)
3027 if (!vc_vlan->tci || !vc_vlan->tpid)
3034 * ice_vc_validate_vlan_filter_list - validate the filter list from the VF
3035 * @vfc: negotiated/supported VLAN filtering capabilities
3036 * @vfl: VLAN filter list from VF to validate
3038 * Validate all of the filters in the VLAN filter list from the VF. If any of
3039 * the checks fail then return false. Otherwise return true.
3042 ice_vc_validate_vlan_filter_list(struct virtchnl_vlan_filtering_caps *vfc,
3043 struct virtchnl_vlan_filter_list_v2 *vfl)
3047 if (!vfl->num_elements)
3050 for (i = 0; i < vfl->num_elements; i++) {
3051 struct virtchnl_vlan_supported_caps *filtering_support =
3052 &vfc->filtering_support;
3053 struct virtchnl_vlan_filter *vlan_fltr = &vfl->filters[i];
3054 struct virtchnl_vlan *outer = &vlan_fltr->outer;
3055 struct virtchnl_vlan *inner = &vlan_fltr->inner;
3057 if ((ice_vc_is_valid_vlan(outer) &&
3058 filtering_support->outer == VIRTCHNL_VLAN_UNSUPPORTED) ||
3059 (ice_vc_is_valid_vlan(inner) &&
3060 filtering_support->inner == VIRTCHNL_VLAN_UNSUPPORTED))
3063 if ((outer->tci_mask &&
3064 !(filtering_support->outer & VIRTCHNL_VLAN_FILTER_MASK)) ||
3066 !(filtering_support->inner & VIRTCHNL_VLAN_FILTER_MASK)))
3069 if (((outer->tci & VLAN_PRIO_MASK) &&
3070 !(filtering_support->outer & VIRTCHNL_VLAN_PRIO)) ||
3071 ((inner->tci & VLAN_PRIO_MASK) &&
3072 !(filtering_support->inner & VIRTCHNL_VLAN_PRIO)))
3075 if ((ice_vc_is_valid_vlan(outer) &&
3076 !ice_vc_validate_vlan_tpid(filtering_support->outer,
3078 (ice_vc_is_valid_vlan(inner) &&
3079 !ice_vc_validate_vlan_tpid(filtering_support->inner,
3088 * ice_vc_to_vlan - transform from struct virtchnl_vlan to struct ice_vlan
3089 * @vc_vlan: struct virtchnl_vlan to transform
3091 static struct ice_vlan ice_vc_to_vlan(struct virtchnl_vlan *vc_vlan)
3093 struct ice_vlan vlan = { 0 };
3095 vlan.prio = FIELD_GET(VLAN_PRIO_MASK, vc_vlan->tci);
3096 vlan.vid = vc_vlan->tci & VLAN_VID_MASK;
3097 vlan.tpid = vc_vlan->tpid;
3103 * ice_vc_vlan_action - action to perform on the virthcnl_vlan
3104 * @vsi: VF's VSI used to perform the action
3105 * @vlan_action: function to perform the action with (i.e. add/del)
3106 * @vlan: VLAN filter to perform the action with
3109 ice_vc_vlan_action(struct ice_vsi *vsi,
3110 int (*vlan_action)(struct ice_vsi *, struct ice_vlan *),
3111 struct ice_vlan *vlan)
3115 err = vlan_action(vsi, vlan);
3123 * ice_vc_del_vlans - delete VLAN(s) from the virtchnl filter list
3124 * @vf: VF used to delete the VLAN(s)
3125 * @vsi: VF's VSI used to delete the VLAN(s)
3126 * @vfl: virthchnl filter list used to delete the filters
3129 ice_vc_del_vlans(struct ice_vf *vf, struct ice_vsi *vsi,
3130 struct virtchnl_vlan_filter_list_v2 *vfl)
3132 bool vlan_promisc = ice_is_vlan_promisc_allowed(vf);
3136 for (i = 0; i < vfl->num_elements; i++) {
3137 struct virtchnl_vlan_filter *vlan_fltr = &vfl->filters[i];
3138 struct virtchnl_vlan *vc_vlan;
3140 vc_vlan = &vlan_fltr->outer;
3141 if (ice_vc_is_valid_vlan(vc_vlan)) {
3142 struct ice_vlan vlan = ice_vc_to_vlan(vc_vlan);
3144 err = ice_vc_vlan_action(vsi,
3145 vsi->outer_vlan_ops.del_vlan,
3151 ice_vf_dis_vlan_promisc(vsi, &vlan);
3153 /* Disable VLAN filtering when only VLAN 0 is left */
3154 if (!ice_vsi_has_non_zero_vlans(vsi) && ice_is_dvm_ena(&vsi->back->hw)) {
3155 err = vsi->outer_vlan_ops.dis_tx_filtering(vsi);
3161 vc_vlan = &vlan_fltr->inner;
3162 if (ice_vc_is_valid_vlan(vc_vlan)) {
3163 struct ice_vlan vlan = ice_vc_to_vlan(vc_vlan);
3165 err = ice_vc_vlan_action(vsi,
3166 vsi->inner_vlan_ops.del_vlan,
3171 /* no support for VLAN promiscuous on inner VLAN unless
3172 * we are in Single VLAN Mode (SVM)
3174 if (!ice_is_dvm_ena(&vsi->back->hw)) {
3176 ice_vf_dis_vlan_promisc(vsi, &vlan);
3178 /* Disable VLAN filtering when only VLAN 0 is left */
3179 if (!ice_vsi_has_non_zero_vlans(vsi)) {
3180 err = vsi->inner_vlan_ops.dis_tx_filtering(vsi);
3192 * ice_vc_remove_vlan_v2_msg - virtchnl handler for VIRTCHNL_OP_DEL_VLAN_V2
3193 * @vf: VF the message was received from
3194 * @msg: message received from the VF
3196 static int ice_vc_remove_vlan_v2_msg(struct ice_vf *vf, u8 *msg)
3198 struct virtchnl_vlan_filter_list_v2 *vfl =
3199 (struct virtchnl_vlan_filter_list_v2 *)msg;
3200 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
3201 struct ice_vsi *vsi;
3203 if (!ice_vc_validate_vlan_filter_list(&vf->vlan_v2_caps.filtering,
3205 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3209 if (!ice_vc_isvalid_vsi_id(vf, vfl->vport_id)) {
3210 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3214 vsi = ice_get_vf_vsi(vf);
3216 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3220 if (ice_vc_del_vlans(vf, vsi, vfl))
3221 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3224 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_DEL_VLAN_V2, v_ret, NULL,
3229 * ice_vc_add_vlans - add VLAN(s) from the virtchnl filter list
3230 * @vf: VF used to add the VLAN(s)
3231 * @vsi: VF's VSI used to add the VLAN(s)
3232 * @vfl: virthchnl filter list used to add the filters
3235 ice_vc_add_vlans(struct ice_vf *vf, struct ice_vsi *vsi,
3236 struct virtchnl_vlan_filter_list_v2 *vfl)
3238 bool vlan_promisc = ice_is_vlan_promisc_allowed(vf);
3242 for (i = 0; i < vfl->num_elements; i++) {
3243 struct virtchnl_vlan_filter *vlan_fltr = &vfl->filters[i];
3244 struct virtchnl_vlan *vc_vlan;
3246 vc_vlan = &vlan_fltr->outer;
3247 if (ice_vc_is_valid_vlan(vc_vlan)) {
3248 struct ice_vlan vlan = ice_vc_to_vlan(vc_vlan);
3250 err = ice_vc_vlan_action(vsi,
3251 vsi->outer_vlan_ops.add_vlan,
3257 err = ice_vf_ena_vlan_promisc(vsi, &vlan);
3262 /* Enable VLAN filtering on first non-zero VLAN */
3263 if (vf->spoofchk && vlan.vid && ice_is_dvm_ena(&vsi->back->hw)) {
3264 err = vsi->outer_vlan_ops.ena_tx_filtering(vsi);
3270 vc_vlan = &vlan_fltr->inner;
3271 if (ice_vc_is_valid_vlan(vc_vlan)) {
3272 struct ice_vlan vlan = ice_vc_to_vlan(vc_vlan);
3274 err = ice_vc_vlan_action(vsi,
3275 vsi->inner_vlan_ops.add_vlan,
3280 /* no support for VLAN promiscuous on inner VLAN unless
3281 * we are in Single VLAN Mode (SVM)
3283 if (!ice_is_dvm_ena(&vsi->back->hw)) {
3285 err = ice_vf_ena_vlan_promisc(vsi, &vlan);
3290 /* Enable VLAN filtering on first non-zero VLAN */
3291 if (vf->spoofchk && vlan.vid) {
3292 err = vsi->inner_vlan_ops.ena_tx_filtering(vsi);
3304 * ice_vc_validate_add_vlan_filter_list - validate add filter list from the VF
3305 * @vsi: VF VSI used to get number of existing VLAN filters
3306 * @vfc: negotiated/supported VLAN filtering capabilities
3307 * @vfl: VLAN filter list from VF to validate
3309 * Validate all of the filters in the VLAN filter list from the VF during the
3310 * VIRTCHNL_OP_ADD_VLAN_V2 opcode. If any of the checks fail then return false.
3311 * Otherwise return true.
3314 ice_vc_validate_add_vlan_filter_list(struct ice_vsi *vsi,
3315 struct virtchnl_vlan_filtering_caps *vfc,
3316 struct virtchnl_vlan_filter_list_v2 *vfl)
3318 u16 num_requested_filters = ice_vsi_num_non_zero_vlans(vsi) +
3321 if (num_requested_filters > vfc->max_filters)
3324 return ice_vc_validate_vlan_filter_list(vfc, vfl);
3328 * ice_vc_add_vlan_v2_msg - virtchnl handler for VIRTCHNL_OP_ADD_VLAN_V2
3329 * @vf: VF the message was received from
3330 * @msg: message received from the VF
3332 static int ice_vc_add_vlan_v2_msg(struct ice_vf *vf, u8 *msg)
3334 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
3335 struct virtchnl_vlan_filter_list_v2 *vfl =
3336 (struct virtchnl_vlan_filter_list_v2 *)msg;
3337 struct ice_vsi *vsi;
3339 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
3340 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3344 if (!ice_vc_isvalid_vsi_id(vf, vfl->vport_id)) {
3345 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3349 vsi = ice_get_vf_vsi(vf);
3351 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3355 if (!ice_vc_validate_add_vlan_filter_list(vsi,
3356 &vf->vlan_v2_caps.filtering,
3358 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3362 if (ice_vc_add_vlans(vf, vsi, vfl))
3363 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3366 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_ADD_VLAN_V2, v_ret, NULL,
3371 * ice_vc_valid_vlan_setting - validate VLAN setting
3372 * @negotiated_settings: negotiated VLAN settings during VF init
3373 * @ethertype_setting: ethertype(s) requested for the VLAN setting
3376 ice_vc_valid_vlan_setting(u32 negotiated_settings, u32 ethertype_setting)
3378 if (ethertype_setting && !(negotiated_settings & ethertype_setting))
3381 /* only allow a single VIRTCHNL_VLAN_ETHERTYPE if
3382 * VIRTHCNL_VLAN_ETHERTYPE_AND is not negotiated/supported
3384 if (!(negotiated_settings & VIRTCHNL_VLAN_ETHERTYPE_AND) &&
3385 hweight32(ethertype_setting) > 1)
3388 /* ability to modify the VLAN setting was not negotiated */
3389 if (!(negotiated_settings & VIRTCHNL_VLAN_TOGGLE))
3396 * ice_vc_valid_vlan_setting_msg - validate the VLAN setting message
3397 * @caps: negotiated VLAN settings during VF init
3398 * @msg: message to validate
3400 * Used to validate any VLAN virtchnl message sent as a
3401 * virtchnl_vlan_setting structure. Validates the message against the
3402 * negotiated/supported caps during VF driver init.
3405 ice_vc_valid_vlan_setting_msg(struct virtchnl_vlan_supported_caps *caps,
3406 struct virtchnl_vlan_setting *msg)
3408 if ((!msg->outer_ethertype_setting &&
3409 !msg->inner_ethertype_setting) ||
3410 (!caps->outer && !caps->inner))
3413 if (msg->outer_ethertype_setting &&
3414 !ice_vc_valid_vlan_setting(caps->outer,
3415 msg->outer_ethertype_setting))
3418 if (msg->inner_ethertype_setting &&
3419 !ice_vc_valid_vlan_setting(caps->inner,
3420 msg->inner_ethertype_setting))
3427 * ice_vc_get_tpid - transform from VIRTCHNL_VLAN_ETHERTYPE_* to VLAN TPID
3428 * @ethertype_setting: VIRTCHNL_VLAN_ETHERTYPE_* used to get VLAN TPID
3429 * @tpid: VLAN TPID to populate
3431 static int ice_vc_get_tpid(u32 ethertype_setting, u16 *tpid)
3433 switch (ethertype_setting) {
3434 case VIRTCHNL_VLAN_ETHERTYPE_8100:
3435 *tpid = ETH_P_8021Q;
3437 case VIRTCHNL_VLAN_ETHERTYPE_88A8:
3438 *tpid = ETH_P_8021AD;
3440 case VIRTCHNL_VLAN_ETHERTYPE_9100:
3441 *tpid = ETH_P_QINQ1;
3452 * ice_vc_ena_vlan_offload - enable VLAN offload based on the ethertype_setting
3453 * @vsi: VF's VSI used to enable the VLAN offload
3454 * @ena_offload: function used to enable the VLAN offload
3455 * @ethertype_setting: VIRTCHNL_VLAN_ETHERTYPE_* to enable offloads for
3458 ice_vc_ena_vlan_offload(struct ice_vsi *vsi,
3459 int (*ena_offload)(struct ice_vsi *vsi, u16 tpid),
3460 u32 ethertype_setting)
3465 err = ice_vc_get_tpid(ethertype_setting, &tpid);
3469 err = ena_offload(vsi, tpid);
3476 #define ICE_L2TSEL_QRX_CONTEXT_REG_IDX 3
3477 #define ICE_L2TSEL_BIT_OFFSET 23
3479 ICE_L2TSEL_EXTRACT_FIRST_TAG_L2TAG2_2ND,
3480 ICE_L2TSEL_EXTRACT_FIRST_TAG_L2TAG1,
3484 * ice_vsi_update_l2tsel - update l2tsel field for all Rx rings on this VSI
3485 * @vsi: VSI used to update l2tsel on
3486 * @l2tsel: l2tsel setting requested
3488 * Use the l2tsel setting to update all of the Rx queue context bits for l2tsel.
3489 * This will modify which descriptor field the first offloaded VLAN will be
3492 static void ice_vsi_update_l2tsel(struct ice_vsi *vsi, enum ice_l2tsel l2tsel)
3494 struct ice_hw *hw = &vsi->back->hw;
3498 if (l2tsel == ICE_L2TSEL_EXTRACT_FIRST_TAG_L2TAG2_2ND)
3501 l2tsel_bit = BIT(ICE_L2TSEL_BIT_OFFSET);
3503 for (i = 0; i < vsi->alloc_rxq; i++) {
3504 u16 pfq = vsi->rxq_map[i];
3505 u32 qrx_context_offset;
3508 qrx_context_offset =
3509 QRX_CONTEXT(ICE_L2TSEL_QRX_CONTEXT_REG_IDX, pfq);
3511 regval = rd32(hw, qrx_context_offset);
3512 regval &= ~BIT(ICE_L2TSEL_BIT_OFFSET);
3513 regval |= l2tsel_bit;
3514 wr32(hw, qrx_context_offset, regval);
3519 * ice_vc_ena_vlan_stripping_v2_msg
3520 * @vf: VF the message was received from
3521 * @msg: message received from the VF
3523 * virthcnl handler for VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2
3525 static int ice_vc_ena_vlan_stripping_v2_msg(struct ice_vf *vf, u8 *msg)
3527 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
3528 struct virtchnl_vlan_supported_caps *stripping_support;
3529 struct virtchnl_vlan_setting *strip_msg =
3530 (struct virtchnl_vlan_setting *)msg;
3531 u32 ethertype_setting;
3532 struct ice_vsi *vsi;
3534 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
3535 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3539 if (!ice_vc_isvalid_vsi_id(vf, strip_msg->vport_id)) {
3540 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3544 vsi = ice_get_vf_vsi(vf);
3546 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3550 stripping_support = &vf->vlan_v2_caps.offloads.stripping_support;
3551 if (!ice_vc_valid_vlan_setting_msg(stripping_support, strip_msg)) {
3552 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3556 if (ice_vsi_is_rxq_crc_strip_dis(vsi)) {
3557 v_ret = VIRTCHNL_STATUS_ERR_NOT_SUPPORTED;
3561 ethertype_setting = strip_msg->outer_ethertype_setting;
3562 if (ethertype_setting) {
3563 if (ice_vc_ena_vlan_offload(vsi,
3564 vsi->outer_vlan_ops.ena_stripping,
3565 ethertype_setting)) {
3566 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3569 enum ice_l2tsel l2tsel =
3570 ICE_L2TSEL_EXTRACT_FIRST_TAG_L2TAG2_2ND;
3572 /* PF tells the VF that the outer VLAN tag is always
3573 * extracted to VIRTCHNL_VLAN_TAG_LOCATION_L2TAG2_2 and
3574 * inner is always extracted to
3575 * VIRTCHNL_VLAN_TAG_LOCATION_L2TAG1. This is needed to
3576 * support outer stripping so the first tag always ends
3577 * up in L2TAG2_2ND and the second/inner tag, if
3578 * enabled, is extracted in L2TAG1.
3580 ice_vsi_update_l2tsel(vsi, l2tsel);
3582 vf->vlan_strip_ena |= ICE_OUTER_VLAN_STRIP_ENA;
3586 ethertype_setting = strip_msg->inner_ethertype_setting;
3587 if (ethertype_setting &&
3588 ice_vc_ena_vlan_offload(vsi, vsi->inner_vlan_ops.ena_stripping,
3589 ethertype_setting)) {
3590 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3594 if (ethertype_setting)
3595 vf->vlan_strip_ena |= ICE_INNER_VLAN_STRIP_ENA;
3598 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2,
3603 * ice_vc_dis_vlan_stripping_v2_msg
3604 * @vf: VF the message was received from
3605 * @msg: message received from the VF
3607 * virthcnl handler for VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2
3609 static int ice_vc_dis_vlan_stripping_v2_msg(struct ice_vf *vf, u8 *msg)
3611 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
3612 struct virtchnl_vlan_supported_caps *stripping_support;
3613 struct virtchnl_vlan_setting *strip_msg =
3614 (struct virtchnl_vlan_setting *)msg;
3615 u32 ethertype_setting;
3616 struct ice_vsi *vsi;
3618 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
3619 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3623 if (!ice_vc_isvalid_vsi_id(vf, strip_msg->vport_id)) {
3624 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3628 vsi = ice_get_vf_vsi(vf);
3630 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3634 stripping_support = &vf->vlan_v2_caps.offloads.stripping_support;
3635 if (!ice_vc_valid_vlan_setting_msg(stripping_support, strip_msg)) {
3636 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3640 ethertype_setting = strip_msg->outer_ethertype_setting;
3641 if (ethertype_setting) {
3642 if (vsi->outer_vlan_ops.dis_stripping(vsi)) {
3643 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3646 enum ice_l2tsel l2tsel =
3647 ICE_L2TSEL_EXTRACT_FIRST_TAG_L2TAG1;
3649 /* PF tells the VF that the outer VLAN tag is always
3650 * extracted to VIRTCHNL_VLAN_TAG_LOCATION_L2TAG2_2 and
3651 * inner is always extracted to
3652 * VIRTCHNL_VLAN_TAG_LOCATION_L2TAG1. This is needed to
3653 * support inner stripping while outer stripping is
3654 * disabled so that the first and only tag is extracted
3657 ice_vsi_update_l2tsel(vsi, l2tsel);
3659 vf->vlan_strip_ena &= ~ICE_OUTER_VLAN_STRIP_ENA;
3663 ethertype_setting = strip_msg->inner_ethertype_setting;
3664 if (ethertype_setting && vsi->inner_vlan_ops.dis_stripping(vsi)) {
3665 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3669 if (ethertype_setting)
3670 vf->vlan_strip_ena &= ~ICE_INNER_VLAN_STRIP_ENA;
3673 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2,
3678 * ice_vc_ena_vlan_insertion_v2_msg
3679 * @vf: VF the message was received from
3680 * @msg: message received from the VF
3682 * virthcnl handler for VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2
3684 static int ice_vc_ena_vlan_insertion_v2_msg(struct ice_vf *vf, u8 *msg)
3686 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
3687 struct virtchnl_vlan_supported_caps *insertion_support;
3688 struct virtchnl_vlan_setting *insertion_msg =
3689 (struct virtchnl_vlan_setting *)msg;
3690 u32 ethertype_setting;
3691 struct ice_vsi *vsi;
3693 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
3694 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3698 if (!ice_vc_isvalid_vsi_id(vf, insertion_msg->vport_id)) {
3699 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3703 vsi = ice_get_vf_vsi(vf);
3705 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3709 insertion_support = &vf->vlan_v2_caps.offloads.insertion_support;
3710 if (!ice_vc_valid_vlan_setting_msg(insertion_support, insertion_msg)) {
3711 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3715 ethertype_setting = insertion_msg->outer_ethertype_setting;
3716 if (ethertype_setting &&
3717 ice_vc_ena_vlan_offload(vsi, vsi->outer_vlan_ops.ena_insertion,
3718 ethertype_setting)) {
3719 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3723 ethertype_setting = insertion_msg->inner_ethertype_setting;
3724 if (ethertype_setting &&
3725 ice_vc_ena_vlan_offload(vsi, vsi->inner_vlan_ops.ena_insertion,
3726 ethertype_setting)) {
3727 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3732 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2,
3737 * ice_vc_dis_vlan_insertion_v2_msg
3738 * @vf: VF the message was received from
3739 * @msg: message received from the VF
3741 * virthcnl handler for VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2
3743 static int ice_vc_dis_vlan_insertion_v2_msg(struct ice_vf *vf, u8 *msg)
3745 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
3746 struct virtchnl_vlan_supported_caps *insertion_support;
3747 struct virtchnl_vlan_setting *insertion_msg =
3748 (struct virtchnl_vlan_setting *)msg;
3749 u32 ethertype_setting;
3750 struct ice_vsi *vsi;
3752 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
3753 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3757 if (!ice_vc_isvalid_vsi_id(vf, insertion_msg->vport_id)) {
3758 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3762 vsi = ice_get_vf_vsi(vf);
3764 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3768 insertion_support = &vf->vlan_v2_caps.offloads.insertion_support;
3769 if (!ice_vc_valid_vlan_setting_msg(insertion_support, insertion_msg)) {
3770 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3774 ethertype_setting = insertion_msg->outer_ethertype_setting;
3775 if (ethertype_setting && vsi->outer_vlan_ops.dis_insertion(vsi)) {
3776 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3780 ethertype_setting = insertion_msg->inner_ethertype_setting;
3781 if (ethertype_setting && vsi->inner_vlan_ops.dis_insertion(vsi)) {
3782 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3787 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2,
3791 static const struct ice_virtchnl_ops ice_virtchnl_dflt_ops = {
3792 .get_ver_msg = ice_vc_get_ver_msg,
3793 .get_vf_res_msg = ice_vc_get_vf_res_msg,
3794 .reset_vf = ice_vc_reset_vf_msg,
3795 .add_mac_addr_msg = ice_vc_add_mac_addr_msg,
3796 .del_mac_addr_msg = ice_vc_del_mac_addr_msg,
3797 .cfg_qs_msg = ice_vc_cfg_qs_msg,
3798 .ena_qs_msg = ice_vc_ena_qs_msg,
3799 .dis_qs_msg = ice_vc_dis_qs_msg,
3800 .request_qs_msg = ice_vc_request_qs_msg,
3801 .cfg_irq_map_msg = ice_vc_cfg_irq_map_msg,
3802 .config_rss_key = ice_vc_config_rss_key,
3803 .config_rss_lut = ice_vc_config_rss_lut,
3804 .config_rss_hfunc = ice_vc_config_rss_hfunc,
3805 .get_stats_msg = ice_vc_get_stats_msg,
3806 .cfg_promiscuous_mode_msg = ice_vc_cfg_promiscuous_mode_msg,
3807 .add_vlan_msg = ice_vc_add_vlan_msg,
3808 .remove_vlan_msg = ice_vc_remove_vlan_msg,
3809 .query_rxdid = ice_vc_query_rxdid,
3810 .get_rss_hena = ice_vc_get_rss_hena,
3811 .set_rss_hena_msg = ice_vc_set_rss_hena,
3812 .ena_vlan_stripping = ice_vc_ena_vlan_stripping,
3813 .dis_vlan_stripping = ice_vc_dis_vlan_stripping,
3814 .handle_rss_cfg_msg = ice_vc_handle_rss_cfg,
3815 .add_fdir_fltr_msg = ice_vc_add_fdir_fltr,
3816 .del_fdir_fltr_msg = ice_vc_del_fdir_fltr,
3817 .get_offload_vlan_v2_caps = ice_vc_get_offload_vlan_v2_caps,
3818 .add_vlan_v2_msg = ice_vc_add_vlan_v2_msg,
3819 .remove_vlan_v2_msg = ice_vc_remove_vlan_v2_msg,
3820 .ena_vlan_stripping_v2_msg = ice_vc_ena_vlan_stripping_v2_msg,
3821 .dis_vlan_stripping_v2_msg = ice_vc_dis_vlan_stripping_v2_msg,
3822 .ena_vlan_insertion_v2_msg = ice_vc_ena_vlan_insertion_v2_msg,
3823 .dis_vlan_insertion_v2_msg = ice_vc_dis_vlan_insertion_v2_msg,
3827 * ice_virtchnl_set_dflt_ops - Switch to default virtchnl ops
3828 * @vf: the VF to switch ops
3830 void ice_virtchnl_set_dflt_ops(struct ice_vf *vf)
3832 vf->virtchnl_ops = &ice_virtchnl_dflt_ops;
3836 * ice_vc_repr_add_mac
3837 * @vf: pointer to VF
3838 * @msg: virtchannel message
3840 * When port representors are created, we do not add MAC rule
3841 * to firmware, we store it so that PF could report same
3844 static int ice_vc_repr_add_mac(struct ice_vf *vf, u8 *msg)
3846 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
3847 struct virtchnl_ether_addr_list *al =
3848 (struct virtchnl_ether_addr_list *)msg;
3849 struct ice_vsi *vsi;
3853 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states) ||
3854 !ice_vc_isvalid_vsi_id(vf, al->vsi_id)) {
3855 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3856 goto handle_mac_exit;
3861 vsi = ice_get_vf_vsi(vf);
3863 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3864 goto handle_mac_exit;
3867 for (i = 0; i < al->num_elements; i++) {
3868 u8 *mac_addr = al->list[i].addr;
3870 if (!is_unicast_ether_addr(mac_addr) ||
3871 ether_addr_equal(mac_addr, vf->hw_lan_addr))
3874 if (vf->pf_set_mac) {
3875 dev_err(ice_pf_to_dev(pf), "VF attempting to override administratively set MAC address\n");
3876 v_ret = VIRTCHNL_STATUS_ERR_NOT_SUPPORTED;
3877 goto handle_mac_exit;
3880 ice_vfhw_mac_add(vf, &al->list[i]);
3886 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_ADD_ETH_ADDR,
3891 * ice_vc_repr_del_mac - response with success for deleting MAC
3892 * @vf: pointer to VF
3893 * @msg: virtchannel message
3895 * Respond with success to not break normal VF flow.
3896 * For legacy VF driver try to update cached MAC address.
3899 ice_vc_repr_del_mac(struct ice_vf __always_unused *vf, u8 __always_unused *msg)
3901 struct virtchnl_ether_addr_list *al =
3902 (struct virtchnl_ether_addr_list *)msg;
3904 ice_update_legacy_cached_mac(vf, &al->list[0]);
3906 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_DEL_ETH_ADDR,
3907 VIRTCHNL_STATUS_SUCCESS, NULL, 0);
3911 ice_vc_repr_cfg_promiscuous_mode(struct ice_vf *vf, u8 __always_unused *msg)
3913 dev_dbg(ice_pf_to_dev(vf->pf),
3914 "Can't config promiscuous mode in switchdev mode for VF %d\n",
3916 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE,
3917 VIRTCHNL_STATUS_ERR_NOT_SUPPORTED,
3921 static const struct ice_virtchnl_ops ice_virtchnl_repr_ops = {
3922 .get_ver_msg = ice_vc_get_ver_msg,
3923 .get_vf_res_msg = ice_vc_get_vf_res_msg,
3924 .reset_vf = ice_vc_reset_vf_msg,
3925 .add_mac_addr_msg = ice_vc_repr_add_mac,
3926 .del_mac_addr_msg = ice_vc_repr_del_mac,
3927 .cfg_qs_msg = ice_vc_cfg_qs_msg,
3928 .ena_qs_msg = ice_vc_ena_qs_msg,
3929 .dis_qs_msg = ice_vc_dis_qs_msg,
3930 .request_qs_msg = ice_vc_request_qs_msg,
3931 .cfg_irq_map_msg = ice_vc_cfg_irq_map_msg,
3932 .config_rss_key = ice_vc_config_rss_key,
3933 .config_rss_lut = ice_vc_config_rss_lut,
3934 .config_rss_hfunc = ice_vc_config_rss_hfunc,
3935 .get_stats_msg = ice_vc_get_stats_msg,
3936 .cfg_promiscuous_mode_msg = ice_vc_repr_cfg_promiscuous_mode,
3937 .add_vlan_msg = ice_vc_add_vlan_msg,
3938 .remove_vlan_msg = ice_vc_remove_vlan_msg,
3939 .query_rxdid = ice_vc_query_rxdid,
3940 .get_rss_hena = ice_vc_get_rss_hena,
3941 .set_rss_hena_msg = ice_vc_set_rss_hena,
3942 .ena_vlan_stripping = ice_vc_ena_vlan_stripping,
3943 .dis_vlan_stripping = ice_vc_dis_vlan_stripping,
3944 .handle_rss_cfg_msg = ice_vc_handle_rss_cfg,
3945 .add_fdir_fltr_msg = ice_vc_add_fdir_fltr,
3946 .del_fdir_fltr_msg = ice_vc_del_fdir_fltr,
3947 .get_offload_vlan_v2_caps = ice_vc_get_offload_vlan_v2_caps,
3948 .add_vlan_v2_msg = ice_vc_add_vlan_v2_msg,
3949 .remove_vlan_v2_msg = ice_vc_remove_vlan_v2_msg,
3950 .ena_vlan_stripping_v2_msg = ice_vc_ena_vlan_stripping_v2_msg,
3951 .dis_vlan_stripping_v2_msg = ice_vc_dis_vlan_stripping_v2_msg,
3952 .ena_vlan_insertion_v2_msg = ice_vc_ena_vlan_insertion_v2_msg,
3953 .dis_vlan_insertion_v2_msg = ice_vc_dis_vlan_insertion_v2_msg,
3957 * ice_virtchnl_set_repr_ops - Switch to representor virtchnl ops
3958 * @vf: the VF to switch ops
3960 void ice_virtchnl_set_repr_ops(struct ice_vf *vf)
3962 vf->virtchnl_ops = &ice_virtchnl_repr_ops;
3966 * ice_is_malicious_vf - check if this vf might be overflowing mailbox
3967 * @vf: the VF to check
3968 * @mbxdata: data about the state of the mailbox
3970 * Detect if a given VF might be malicious and attempting to overflow the PF
3971 * mailbox. If so, log a warning message and ignore this event.
3974 ice_is_malicious_vf(struct ice_vf *vf, struct ice_mbx_data *mbxdata)
3976 bool report_malvf = false;
3982 dev = ice_pf_to_dev(pf);
3984 if (test_bit(ICE_VF_STATE_DIS, vf->vf_states))
3985 return vf->mbx_info.malicious;
3987 /* check to see if we have a newly malicious VF */
3988 status = ice_mbx_vf_state_handler(&pf->hw, mbxdata, &vf->mbx_info,
3991 dev_warn_ratelimited(dev, "Unable to check status of mailbox overflow for VF %u MAC %pM, status %d\n",
3992 vf->vf_id, vf->dev_lan_addr, status);
3995 struct ice_vsi *pf_vsi = ice_get_main_vsi(pf);
3996 u8 zero_addr[ETH_ALEN] = {};
3998 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",
4000 pf_vsi ? pf_vsi->netdev->dev_addr : zero_addr);
4003 return vf->mbx_info.malicious;
4007 * ice_vc_process_vf_msg - Process request from VF
4008 * @pf: pointer to the PF structure
4009 * @event: pointer to the AQ event
4010 * @mbxdata: information used to detect VF attempting mailbox overflow
4012 * called from the common asq/arq handler to
4013 * process request from VF
4015 void ice_vc_process_vf_msg(struct ice_pf *pf, struct ice_rq_event_info *event,
4016 struct ice_mbx_data *mbxdata)
4018 u32 v_opcode = le32_to_cpu(event->desc.cookie_high);
4019 s16 vf_id = le16_to_cpu(event->desc.retval);
4020 const struct ice_virtchnl_ops *ops;
4021 u16 msglen = event->msg_len;
4022 u8 *msg = event->msg_buf;
4023 struct ice_vf *vf = NULL;
4027 dev = ice_pf_to_dev(pf);
4029 vf = ice_get_vf_by_id(pf, vf_id);
4031 dev_err(dev, "Unable to locate VF for message from VF ID %d, opcode %d, len %d\n",
4032 vf_id, v_opcode, msglen);
4036 mutex_lock(&vf->cfg_lock);
4038 /* Check if the VF is trying to overflow the mailbox */
4039 if (ice_is_malicious_vf(vf, mbxdata))
4042 /* Check if VF is disabled. */
4043 if (test_bit(ICE_VF_STATE_DIS, vf->vf_states)) {
4048 ops = vf->virtchnl_ops;
4050 /* Perform basic checks on the msg */
4051 err = virtchnl_vc_validate_vf_msg(&vf->vf_ver, v_opcode, msg, msglen);
4053 if (err == VIRTCHNL_STATUS_ERR_PARAM)
4061 ice_vc_send_msg_to_vf(vf, v_opcode, VIRTCHNL_STATUS_ERR_PARAM,
4063 dev_err(dev, "Invalid message from VF %d, opcode %d, len %d, error %d\n",
4064 vf_id, v_opcode, msglen, err);
4068 if (!ice_vc_is_opcode_allowed(vf, v_opcode)) {
4069 ice_vc_send_msg_to_vf(vf, v_opcode,
4070 VIRTCHNL_STATUS_ERR_NOT_SUPPORTED, NULL,
4076 case VIRTCHNL_OP_VERSION:
4077 err = ops->get_ver_msg(vf, msg);
4079 case VIRTCHNL_OP_GET_VF_RESOURCES:
4080 err = ops->get_vf_res_msg(vf, msg);
4081 if (ice_vf_init_vlan_stripping(vf))
4082 dev_dbg(dev, "Failed to initialize VLAN stripping for VF %d\n",
4084 ice_vc_notify_vf_link_state(vf);
4086 case VIRTCHNL_OP_RESET_VF:
4089 case VIRTCHNL_OP_ADD_ETH_ADDR:
4090 err = ops->add_mac_addr_msg(vf, msg);
4092 case VIRTCHNL_OP_DEL_ETH_ADDR:
4093 err = ops->del_mac_addr_msg(vf, msg);
4095 case VIRTCHNL_OP_CONFIG_VSI_QUEUES:
4096 err = ops->cfg_qs_msg(vf, msg);
4098 case VIRTCHNL_OP_ENABLE_QUEUES:
4099 err = ops->ena_qs_msg(vf, msg);
4100 ice_vc_notify_vf_link_state(vf);
4102 case VIRTCHNL_OP_DISABLE_QUEUES:
4103 err = ops->dis_qs_msg(vf, msg);
4105 case VIRTCHNL_OP_REQUEST_QUEUES:
4106 err = ops->request_qs_msg(vf, msg);
4108 case VIRTCHNL_OP_CONFIG_IRQ_MAP:
4109 err = ops->cfg_irq_map_msg(vf, msg);
4111 case VIRTCHNL_OP_CONFIG_RSS_KEY:
4112 err = ops->config_rss_key(vf, msg);
4114 case VIRTCHNL_OP_CONFIG_RSS_LUT:
4115 err = ops->config_rss_lut(vf, msg);
4117 case VIRTCHNL_OP_CONFIG_RSS_HFUNC:
4118 err = ops->config_rss_hfunc(vf, msg);
4120 case VIRTCHNL_OP_GET_STATS:
4121 err = ops->get_stats_msg(vf, msg);
4123 case VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE:
4124 err = ops->cfg_promiscuous_mode_msg(vf, msg);
4126 case VIRTCHNL_OP_ADD_VLAN:
4127 err = ops->add_vlan_msg(vf, msg);
4129 case VIRTCHNL_OP_DEL_VLAN:
4130 err = ops->remove_vlan_msg(vf, msg);
4132 case VIRTCHNL_OP_GET_SUPPORTED_RXDIDS:
4133 err = ops->query_rxdid(vf);
4135 case VIRTCHNL_OP_GET_RSS_HENA_CAPS:
4136 err = ops->get_rss_hena(vf);
4138 case VIRTCHNL_OP_SET_RSS_HENA:
4139 err = ops->set_rss_hena_msg(vf, msg);
4141 case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING:
4142 err = ops->ena_vlan_stripping(vf);
4144 case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING:
4145 err = ops->dis_vlan_stripping(vf);
4147 case VIRTCHNL_OP_ADD_FDIR_FILTER:
4148 err = ops->add_fdir_fltr_msg(vf, msg);
4150 case VIRTCHNL_OP_DEL_FDIR_FILTER:
4151 err = ops->del_fdir_fltr_msg(vf, msg);
4153 case VIRTCHNL_OP_ADD_RSS_CFG:
4154 err = ops->handle_rss_cfg_msg(vf, msg, true);
4156 case VIRTCHNL_OP_DEL_RSS_CFG:
4157 err = ops->handle_rss_cfg_msg(vf, msg, false);
4159 case VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS:
4160 err = ops->get_offload_vlan_v2_caps(vf);
4162 case VIRTCHNL_OP_ADD_VLAN_V2:
4163 err = ops->add_vlan_v2_msg(vf, msg);
4165 case VIRTCHNL_OP_DEL_VLAN_V2:
4166 err = ops->remove_vlan_v2_msg(vf, msg);
4168 case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2:
4169 err = ops->ena_vlan_stripping_v2_msg(vf, msg);
4171 case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2:
4172 err = ops->dis_vlan_stripping_v2_msg(vf, msg);
4174 case VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2:
4175 err = ops->ena_vlan_insertion_v2_msg(vf, msg);
4177 case VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2:
4178 err = ops->dis_vlan_insertion_v2_msg(vf, msg);
4180 case VIRTCHNL_OP_UNKNOWN:
4182 dev_err(dev, "Unsupported opcode %d from VF %d\n", v_opcode,
4184 err = ice_vc_send_msg_to_vf(vf, v_opcode,
4185 VIRTCHNL_STATUS_ERR_NOT_SUPPORTED,
4190 /* Helper function cares less about error return values here
4191 * as it is busy with pending work.
4193 dev_info(dev, "PF failed to honor VF %d, opcode %d, error %d\n",
4194 vf_id, v_opcode, err);
4198 mutex_unlock(&vf->cfg_lock);