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 = sizeof(struct virtchnl_vf_resource);
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_RSS_REG |
444 VIRTCHNL_VF_OFFLOAD_VLAN;
446 vfres->vf_cap_flags = VIRTCHNL_VF_OFFLOAD_L2;
447 vsi = ice_get_vf_vsi(vf);
449 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
453 vfres->vf_cap_flags |= ice_vc_get_vlan_caps(hw, vf, vsi,
456 if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_RSS_PF) {
457 vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_RSS_PF;
459 if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_RSS_AQ)
460 vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_RSS_AQ;
462 vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_RSS_REG;
465 if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_RX_FLEX_DESC)
466 vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_RX_FLEX_DESC;
468 if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_FDIR_PF)
469 vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_FDIR_PF;
471 if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_RSS_PCTYPE_V2)
472 vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_RSS_PCTYPE_V2;
474 if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_ENCAP)
475 vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_ENCAP;
477 if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_ENCAP_CSUM)
478 vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_ENCAP_CSUM;
480 if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_RX_POLLING)
481 vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_RX_POLLING;
483 if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_WB_ON_ITR)
484 vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_WB_ON_ITR;
486 if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_REQ_QUEUES)
487 vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_REQ_QUEUES;
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->pf->vfs.num_msix_per;
502 vfres->rss_key_size = ICE_VSIQF_HKEY_ARRAY_SIZE;
503 vfres->rss_lut_size = ICE_VSIQF_HLUT_ARRAY_SIZE;
504 vfres->max_mtu = ice_vc_get_max_frame_size(vf);
506 vfres->vsi_res[0].vsi_id = vf->lan_vsi_num;
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 struct ice_pf *pf = vf->pf;
555 vsi = ice_find_vsi(pf, vsi_id);
557 return (vsi && (vsi->vf == vf));
561 * ice_vc_isvalid_q_id
562 * @vf: pointer to the VF info
564 * @qid: VSI relative queue ID
566 * check for the valid queue ID
568 static bool ice_vc_isvalid_q_id(struct ice_vf *vf, u16 vsi_id, u8 qid)
570 struct ice_vsi *vsi = ice_find_vsi(vf->pf, vsi_id);
571 /* allocated Tx and Rx queues should be always equal for VF VSI */
572 return (vsi && (qid < vsi->alloc_txq));
576 * ice_vc_isvalid_ring_len
577 * @ring_len: length of ring
579 * check for the valid ring count, should be multiple of ICE_REQ_DESC_MULTIPLE
582 static bool ice_vc_isvalid_ring_len(u16 ring_len)
584 return ring_len == 0 ||
585 (ring_len >= ICE_MIN_NUM_DESC &&
586 ring_len <= ICE_MAX_NUM_DESC &&
587 !(ring_len % ICE_REQ_DESC_MULTIPLE));
591 * ice_vc_validate_pattern
592 * @vf: pointer to the VF info
593 * @proto: virtchnl protocol headers
595 * validate the pattern is supported or not.
597 * Return: true on success, false on error.
600 ice_vc_validate_pattern(struct ice_vf *vf, struct virtchnl_proto_hdrs *proto)
602 bool is_ipv4 = false;
603 bool is_ipv6 = false;
608 while (i < proto->count &&
609 proto->proto_hdr[i].type != VIRTCHNL_PROTO_HDR_NONE) {
610 switch (proto->proto_hdr[i].type) {
611 case VIRTCHNL_PROTO_HDR_ETH:
612 ptype = ICE_PTYPE_MAC_PAY;
614 case VIRTCHNL_PROTO_HDR_IPV4:
615 ptype = ICE_PTYPE_IPV4_PAY;
618 case VIRTCHNL_PROTO_HDR_IPV6:
619 ptype = ICE_PTYPE_IPV6_PAY;
622 case VIRTCHNL_PROTO_HDR_UDP:
624 ptype = ICE_PTYPE_IPV4_UDP_PAY;
626 ptype = ICE_PTYPE_IPV6_UDP_PAY;
629 case VIRTCHNL_PROTO_HDR_TCP:
631 ptype = ICE_PTYPE_IPV4_TCP_PAY;
633 ptype = ICE_PTYPE_IPV6_TCP_PAY;
635 case VIRTCHNL_PROTO_HDR_SCTP:
637 ptype = ICE_PTYPE_IPV4_SCTP_PAY;
639 ptype = ICE_PTYPE_IPV6_SCTP_PAY;
641 case VIRTCHNL_PROTO_HDR_GTPU_IP:
642 case VIRTCHNL_PROTO_HDR_GTPU_EH:
644 ptype = ICE_MAC_IPV4_GTPU;
646 ptype = ICE_MAC_IPV6_GTPU;
648 case VIRTCHNL_PROTO_HDR_L2TPV3:
650 ptype = ICE_MAC_IPV4_L2TPV3;
652 ptype = ICE_MAC_IPV6_L2TPV3;
654 case VIRTCHNL_PROTO_HDR_ESP:
656 ptype = is_udp ? ICE_MAC_IPV4_NAT_T_ESP :
659 ptype = is_udp ? ICE_MAC_IPV6_NAT_T_ESP :
662 case VIRTCHNL_PROTO_HDR_AH:
664 ptype = ICE_MAC_IPV4_AH;
666 ptype = ICE_MAC_IPV6_AH;
668 case VIRTCHNL_PROTO_HDR_PFCP:
670 ptype = ICE_MAC_IPV4_PFCP_SESSION;
672 ptype = ICE_MAC_IPV6_PFCP_SESSION;
681 return ice_hw_ptype_ena(&vf->pf->hw, ptype);
685 * ice_vc_parse_rss_cfg - parses hash fields and headers from
686 * a specific virtchnl RSS cfg
687 * @hw: pointer to the hardware
688 * @rss_cfg: pointer to the virtchnl RSS cfg
689 * @addl_hdrs: pointer to the protocol header fields (ICE_FLOW_SEG_HDR_*)
691 * @hash_flds: pointer to the hash bit fields (ICE_FLOW_HASH_*) to configure
693 * Return true if all the protocol header and hash fields in the RSS cfg could
694 * be parsed, else return false
696 * This function parses the virtchnl RSS cfg to be the intended
697 * hash fields and the intended header for RSS configuration
700 ice_vc_parse_rss_cfg(struct ice_hw *hw, struct virtchnl_rss_cfg *rss_cfg,
701 u32 *addl_hdrs, u64 *hash_flds)
703 const struct ice_vc_hash_field_match_type *hf_list;
704 const struct ice_vc_hdr_match_type *hdr_list;
705 int i, hf_list_len, hdr_list_len;
707 hf_list = ice_vc_hash_field_list;
708 hf_list_len = ARRAY_SIZE(ice_vc_hash_field_list);
709 hdr_list = ice_vc_hdr_list;
710 hdr_list_len = ARRAY_SIZE(ice_vc_hdr_list);
712 for (i = 0; i < rss_cfg->proto_hdrs.count; i++) {
713 struct virtchnl_proto_hdr *proto_hdr =
714 &rss_cfg->proto_hdrs.proto_hdr[i];
715 bool hdr_found = false;
718 /* Find matched ice headers according to virtchnl headers. */
719 for (j = 0; j < hdr_list_len; j++) {
720 struct ice_vc_hdr_match_type hdr_map = hdr_list[j];
722 if (proto_hdr->type == hdr_map.vc_hdr) {
723 *addl_hdrs |= hdr_map.ice_hdr;
731 /* Find matched ice hash fields according to
732 * virtchnl hash fields.
734 for (j = 0; j < hf_list_len; j++) {
735 struct ice_vc_hash_field_match_type hf_map = hf_list[j];
737 if (proto_hdr->type == hf_map.vc_hdr &&
738 proto_hdr->field_selector == hf_map.vc_hash_field) {
739 *hash_flds |= hf_map.ice_hash_field;
749 * ice_vf_adv_rss_offload_ena - determine if capabilities support advanced
751 * @caps: VF driver negotiated capabilities
753 * Return true if VIRTCHNL_VF_OFFLOAD_ADV_RSS_PF capability is set,
756 static bool ice_vf_adv_rss_offload_ena(u32 caps)
758 return !!(caps & VIRTCHNL_VF_OFFLOAD_ADV_RSS_PF);
762 * ice_vc_handle_rss_cfg
763 * @vf: pointer to the VF info
764 * @msg: pointer to the message buffer
765 * @add: add a RSS config if true, otherwise delete a RSS config
767 * This function adds/deletes a RSS config
769 static int ice_vc_handle_rss_cfg(struct ice_vf *vf, u8 *msg, bool add)
771 u32 v_opcode = add ? VIRTCHNL_OP_ADD_RSS_CFG : VIRTCHNL_OP_DEL_RSS_CFG;
772 struct virtchnl_rss_cfg *rss_cfg = (struct virtchnl_rss_cfg *)msg;
773 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
774 struct device *dev = ice_pf_to_dev(vf->pf);
775 struct ice_hw *hw = &vf->pf->hw;
778 if (!test_bit(ICE_FLAG_RSS_ENA, vf->pf->flags)) {
779 dev_dbg(dev, "VF %d attempting to configure RSS, but RSS is not supported by the PF\n",
781 v_ret = VIRTCHNL_STATUS_ERR_NOT_SUPPORTED;
785 if (!ice_vf_adv_rss_offload_ena(vf->driver_caps)) {
786 dev_dbg(dev, "VF %d attempting to configure RSS, but Advanced RSS offload is not supported\n",
788 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
792 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
793 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
797 if (rss_cfg->proto_hdrs.count > VIRTCHNL_MAX_NUM_PROTO_HDRS ||
798 rss_cfg->rss_algorithm < VIRTCHNL_RSS_ALG_TOEPLITZ_ASYMMETRIC ||
799 rss_cfg->rss_algorithm > VIRTCHNL_RSS_ALG_XOR_SYMMETRIC) {
800 dev_dbg(dev, "VF %d attempting to configure RSS, but RSS configuration is not valid\n",
802 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
806 vsi = ice_get_vf_vsi(vf);
808 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
812 if (!ice_vc_validate_pattern(vf, &rss_cfg->proto_hdrs)) {
813 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
817 if (rss_cfg->rss_algorithm == VIRTCHNL_RSS_ALG_R_ASYMMETRIC) {
818 struct ice_vsi_ctx *ctx;
819 u8 lut_type, hash_type;
822 lut_type = ICE_AQ_VSI_Q_OPT_RSS_LUT_VSI;
823 hash_type = add ? ICE_AQ_VSI_Q_OPT_RSS_XOR :
824 ICE_AQ_VSI_Q_OPT_RSS_TPLZ;
826 ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
828 v_ret = VIRTCHNL_STATUS_ERR_NO_MEMORY;
832 ctx->info.q_opt_rss = ((lut_type <<
833 ICE_AQ_VSI_Q_OPT_RSS_LUT_S) &
834 ICE_AQ_VSI_Q_OPT_RSS_LUT_M) |
836 ICE_AQ_VSI_Q_OPT_RSS_HASH_M);
838 /* Preserve existing queueing option setting */
839 ctx->info.q_opt_rss |= (vsi->info.q_opt_rss &
840 ICE_AQ_VSI_Q_OPT_RSS_GBL_LUT_M);
841 ctx->info.q_opt_tc = vsi->info.q_opt_tc;
842 ctx->info.q_opt_flags = vsi->info.q_opt_rss;
844 ctx->info.valid_sections =
845 cpu_to_le16(ICE_AQ_VSI_PROP_Q_OPT_VALID);
847 status = ice_update_vsi(hw, vsi->idx, ctx, NULL);
849 dev_err(dev, "update VSI for RSS failed, err %d aq_err %s\n",
850 status, ice_aq_str(hw->adminq.sq_last_status));
851 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
853 vsi->info.q_opt_rss = ctx->info.q_opt_rss;
858 u32 addl_hdrs = ICE_FLOW_SEG_HDR_NONE;
859 u64 hash_flds = ICE_HASH_INVALID;
861 if (!ice_vc_parse_rss_cfg(hw, rss_cfg, &addl_hdrs,
863 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
868 if (ice_add_rss_cfg(hw, vsi->idx, hash_flds,
870 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
871 dev_err(dev, "ice_add_rss_cfg failed for vsi = %d, v_ret = %d\n",
872 vsi->vsi_num, v_ret);
877 status = ice_rem_rss_cfg(hw, vsi->idx, hash_flds,
879 /* We just ignore -ENOENT, because if two configurations
880 * share the same profile remove one of them actually
881 * removes both, since the profile is deleted.
883 if (status && status != -ENOENT) {
884 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
885 dev_err(dev, "ice_rem_rss_cfg failed for VF ID:%d, error:%d\n",
892 return ice_vc_send_msg_to_vf(vf, v_opcode, v_ret, NULL, 0);
896 * ice_vc_config_rss_key
897 * @vf: pointer to the VF info
898 * @msg: pointer to the msg buffer
900 * Configure the VF's RSS key
902 static int ice_vc_config_rss_key(struct ice_vf *vf, u8 *msg)
904 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
905 struct virtchnl_rss_key *vrk =
906 (struct virtchnl_rss_key *)msg;
909 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
910 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
914 if (!ice_vc_isvalid_vsi_id(vf, vrk->vsi_id)) {
915 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
919 if (vrk->key_len != ICE_VSIQF_HKEY_ARRAY_SIZE) {
920 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
924 if (!test_bit(ICE_FLAG_RSS_ENA, vf->pf->flags)) {
925 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
929 vsi = ice_get_vf_vsi(vf);
931 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
935 if (ice_set_rss_key(vsi, vrk->key))
936 v_ret = VIRTCHNL_STATUS_ERR_ADMIN_QUEUE_ERROR;
938 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_CONFIG_RSS_KEY, v_ret,
943 * ice_vc_config_rss_lut
944 * @vf: pointer to the VF info
945 * @msg: pointer to the msg buffer
947 * Configure the VF's RSS LUT
949 static int ice_vc_config_rss_lut(struct ice_vf *vf, u8 *msg)
951 struct virtchnl_rss_lut *vrl = (struct virtchnl_rss_lut *)msg;
952 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
955 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
956 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
960 if (!ice_vc_isvalid_vsi_id(vf, vrl->vsi_id)) {
961 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
965 if (vrl->lut_entries != ICE_VSIQF_HLUT_ARRAY_SIZE) {
966 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
970 if (!test_bit(ICE_FLAG_RSS_ENA, vf->pf->flags)) {
971 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
975 vsi = ice_get_vf_vsi(vf);
977 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
981 if (ice_set_rss_lut(vsi, vrl->lut, ICE_VSIQF_HLUT_ARRAY_SIZE))
982 v_ret = VIRTCHNL_STATUS_ERR_ADMIN_QUEUE_ERROR;
984 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_CONFIG_RSS_LUT, v_ret,
989 * ice_vc_cfg_promiscuous_mode_msg
990 * @vf: pointer to the VF info
991 * @msg: pointer to the msg buffer
993 * called from the VF to configure VF VSIs promiscuous mode
995 static int ice_vc_cfg_promiscuous_mode_msg(struct ice_vf *vf, u8 *msg)
997 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
998 bool rm_promisc, alluni = false, allmulti = false;
999 struct virtchnl_promisc_info *info =
1000 (struct virtchnl_promisc_info *)msg;
1001 struct ice_vsi_vlan_ops *vlan_ops;
1002 int mcast_err = 0, ucast_err = 0;
1003 struct ice_pf *pf = vf->pf;
1004 struct ice_vsi *vsi;
1005 u8 mcast_m, ucast_m;
1009 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
1010 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1014 if (!ice_vc_isvalid_vsi_id(vf, info->vsi_id)) {
1015 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1019 vsi = ice_get_vf_vsi(vf);
1021 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1025 dev = ice_pf_to_dev(pf);
1026 if (!ice_is_vf_trusted(vf)) {
1027 dev_err(dev, "Unprivileged VF %d is attempting to configure promiscuous mode\n",
1029 /* Leave v_ret alone, lie to the VF on purpose. */
1033 if (info->flags & FLAG_VF_UNICAST_PROMISC)
1036 if (info->flags & FLAG_VF_MULTICAST_PROMISC)
1039 rm_promisc = !allmulti && !alluni;
1041 vlan_ops = ice_get_compat_vsi_vlan_ops(vsi);
1043 ret = vlan_ops->ena_rx_filtering(vsi);
1045 ret = vlan_ops->dis_rx_filtering(vsi);
1047 dev_err(dev, "Failed to configure VLAN pruning in promiscuous mode\n");
1048 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1052 ice_vf_get_promisc_masks(vf, vsi, &ucast_m, &mcast_m);
1054 if (!test_bit(ICE_FLAG_VF_TRUE_PROMISC_ENA, pf->flags)) {
1056 /* in this case we're turning on promiscuous mode */
1057 ret = ice_set_dflt_vsi(vsi);
1059 /* in this case we're turning off promiscuous mode */
1060 if (ice_is_dflt_vsi_in_use(vsi->port_info))
1061 ret = ice_clear_dflt_vsi(vsi);
1064 /* in this case we're turning on/off only
1068 mcast_err = ice_vf_set_vsi_promisc(vf, vsi, mcast_m);
1070 mcast_err = ice_vf_clear_vsi_promisc(vf, vsi, mcast_m);
1073 dev_err(dev, "Turning on/off promiscuous mode for VF %d failed, error: %d\n",
1075 v_ret = VIRTCHNL_STATUS_ERR_ADMIN_QUEUE_ERROR;
1080 ucast_err = ice_vf_set_vsi_promisc(vf, vsi, ucast_m);
1082 ucast_err = ice_vf_clear_vsi_promisc(vf, vsi, ucast_m);
1085 mcast_err = ice_vf_set_vsi_promisc(vf, vsi, mcast_m);
1087 mcast_err = ice_vf_clear_vsi_promisc(vf, vsi, mcast_m);
1089 if (ucast_err || mcast_err)
1090 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1095 !test_and_set_bit(ICE_VF_STATE_MC_PROMISC, vf->vf_states))
1096 dev_info(dev, "VF %u successfully set multicast promiscuous mode\n",
1098 else if (!allmulti &&
1099 test_and_clear_bit(ICE_VF_STATE_MC_PROMISC,
1101 dev_info(dev, "VF %u successfully unset multicast promiscuous mode\n",
1104 dev_err(dev, "Error while modifying multicast promiscuous mode for VF %u, error: %d\n",
1105 vf->vf_id, mcast_err);
1110 !test_and_set_bit(ICE_VF_STATE_UC_PROMISC, vf->vf_states))
1111 dev_info(dev, "VF %u successfully set unicast promiscuous mode\n",
1114 test_and_clear_bit(ICE_VF_STATE_UC_PROMISC,
1116 dev_info(dev, "VF %u successfully unset unicast promiscuous mode\n",
1119 dev_err(dev, "Error while modifying unicast promiscuous mode for VF %u, error: %d\n",
1120 vf->vf_id, ucast_err);
1124 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE,
1129 * ice_vc_get_stats_msg
1130 * @vf: pointer to the VF info
1131 * @msg: pointer to the msg buffer
1133 * called from the VF to get VSI stats
1135 static int ice_vc_get_stats_msg(struct ice_vf *vf, u8 *msg)
1137 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
1138 struct virtchnl_queue_select *vqs =
1139 (struct virtchnl_queue_select *)msg;
1140 struct ice_eth_stats stats = { 0 };
1141 struct ice_vsi *vsi;
1143 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
1144 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1148 if (!ice_vc_isvalid_vsi_id(vf, vqs->vsi_id)) {
1149 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1153 vsi = ice_get_vf_vsi(vf);
1155 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1159 ice_update_eth_stats(vsi);
1161 stats = vsi->eth_stats;
1164 /* send the response to the VF */
1165 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_GET_STATS, v_ret,
1166 (u8 *)&stats, sizeof(stats));
1170 * ice_vc_validate_vqs_bitmaps - validate Rx/Tx queue bitmaps from VIRTCHNL
1171 * @vqs: virtchnl_queue_select structure containing bitmaps to validate
1173 * Return true on successful validation, else false
1175 static bool ice_vc_validate_vqs_bitmaps(struct virtchnl_queue_select *vqs)
1177 if ((!vqs->rx_queues && !vqs->tx_queues) ||
1178 vqs->rx_queues >= BIT(ICE_MAX_RSS_QS_PER_VF) ||
1179 vqs->tx_queues >= BIT(ICE_MAX_RSS_QS_PER_VF))
1186 * ice_vf_ena_txq_interrupt - enable Tx queue interrupt via QINT_TQCTL
1187 * @vsi: VSI of the VF to configure
1188 * @q_idx: VF queue index used to determine the queue in the PF's space
1190 static void ice_vf_ena_txq_interrupt(struct ice_vsi *vsi, u32 q_idx)
1192 struct ice_hw *hw = &vsi->back->hw;
1193 u32 pfq = vsi->txq_map[q_idx];
1196 reg = rd32(hw, QINT_TQCTL(pfq));
1198 /* MSI-X index 0 in the VF's space is always for the OICR, which means
1199 * this is most likely a poll mode VF driver, so don't enable an
1200 * interrupt that was never configured via VIRTCHNL_OP_CONFIG_IRQ_MAP
1202 if (!(reg & QINT_TQCTL_MSIX_INDX_M))
1205 wr32(hw, QINT_TQCTL(pfq), reg | QINT_TQCTL_CAUSE_ENA_M);
1209 * ice_vf_ena_rxq_interrupt - enable Tx queue interrupt via QINT_RQCTL
1210 * @vsi: VSI of the VF to configure
1211 * @q_idx: VF queue index used to determine the queue in the PF's space
1213 static void ice_vf_ena_rxq_interrupt(struct ice_vsi *vsi, u32 q_idx)
1215 struct ice_hw *hw = &vsi->back->hw;
1216 u32 pfq = vsi->rxq_map[q_idx];
1219 reg = rd32(hw, QINT_RQCTL(pfq));
1221 /* MSI-X index 0 in the VF's space is always for the OICR, which means
1222 * this is most likely a poll mode VF driver, so don't enable an
1223 * interrupt that was never configured via VIRTCHNL_OP_CONFIG_IRQ_MAP
1225 if (!(reg & QINT_RQCTL_MSIX_INDX_M))
1228 wr32(hw, QINT_RQCTL(pfq), reg | QINT_RQCTL_CAUSE_ENA_M);
1233 * @vf: pointer to the VF info
1234 * @msg: pointer to the msg buffer
1236 * called from the VF to enable all or specific queue(s)
1238 static int ice_vc_ena_qs_msg(struct ice_vf *vf, u8 *msg)
1240 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
1241 struct virtchnl_queue_select *vqs =
1242 (struct virtchnl_queue_select *)msg;
1243 struct ice_vsi *vsi;
1244 unsigned long q_map;
1247 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
1248 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1252 if (!ice_vc_isvalid_vsi_id(vf, vqs->vsi_id)) {
1253 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1257 if (!ice_vc_validate_vqs_bitmaps(vqs)) {
1258 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1262 vsi = ice_get_vf_vsi(vf);
1264 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1268 /* Enable only Rx rings, Tx rings were enabled by the FW when the
1269 * Tx queue group list was configured and the context bits were
1270 * programmed using ice_vsi_cfg_txqs
1272 q_map = vqs->rx_queues;
1273 for_each_set_bit(vf_q_id, &q_map, ICE_MAX_RSS_QS_PER_VF) {
1274 if (!ice_vc_isvalid_q_id(vf, vqs->vsi_id, vf_q_id)) {
1275 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1279 /* Skip queue if enabled */
1280 if (test_bit(vf_q_id, vf->rxq_ena))
1283 if (ice_vsi_ctrl_one_rx_ring(vsi, true, vf_q_id, true)) {
1284 dev_err(ice_pf_to_dev(vsi->back), "Failed to enable Rx ring %d on VSI %d\n",
1285 vf_q_id, vsi->vsi_num);
1286 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1290 ice_vf_ena_rxq_interrupt(vsi, vf_q_id);
1291 set_bit(vf_q_id, vf->rxq_ena);
1294 q_map = vqs->tx_queues;
1295 for_each_set_bit(vf_q_id, &q_map, ICE_MAX_RSS_QS_PER_VF) {
1296 if (!ice_vc_isvalid_q_id(vf, vqs->vsi_id, vf_q_id)) {
1297 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1301 /* Skip queue if enabled */
1302 if (test_bit(vf_q_id, vf->txq_ena))
1305 ice_vf_ena_txq_interrupt(vsi, vf_q_id);
1306 set_bit(vf_q_id, vf->txq_ena);
1309 /* Set flag to indicate that queues are enabled */
1310 if (v_ret == VIRTCHNL_STATUS_SUCCESS)
1311 set_bit(ICE_VF_STATE_QS_ENA, vf->vf_states);
1314 /* send the response to the VF */
1315 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_ENABLE_QUEUES, v_ret,
1320 * ice_vf_vsi_dis_single_txq - disable a single Tx queue
1321 * @vf: VF to disable queue for
1322 * @vsi: VSI for the VF
1323 * @q_id: VF relative (0-based) queue ID
1325 * Attempt to disable the Tx queue passed in. If the Tx queue was successfully
1326 * disabled then clear q_id bit in the enabled queues bitmap and return
1327 * success. Otherwise return error.
1330 ice_vf_vsi_dis_single_txq(struct ice_vf *vf, struct ice_vsi *vsi, u16 q_id)
1332 struct ice_txq_meta txq_meta = { 0 };
1333 struct ice_tx_ring *ring;
1336 if (!test_bit(q_id, vf->txq_ena))
1337 dev_dbg(ice_pf_to_dev(vsi->back), "Queue %u on VSI %u is not enabled, but stopping it anyway\n",
1338 q_id, vsi->vsi_num);
1340 ring = vsi->tx_rings[q_id];
1344 ice_fill_txq_meta(vsi, ring, &txq_meta);
1346 err = ice_vsi_stop_tx_ring(vsi, ICE_NO_RESET, vf->vf_id, ring, &txq_meta);
1348 dev_err(ice_pf_to_dev(vsi->back), "Failed to stop Tx ring %d on VSI %d\n",
1349 q_id, vsi->vsi_num);
1353 /* Clear enabled queues flag */
1354 clear_bit(q_id, vf->txq_ena);
1361 * @vf: pointer to the VF info
1362 * @msg: pointer to the msg buffer
1364 * called from the VF to disable all or specific queue(s)
1366 static int ice_vc_dis_qs_msg(struct ice_vf *vf, u8 *msg)
1368 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
1369 struct virtchnl_queue_select *vqs =
1370 (struct virtchnl_queue_select *)msg;
1371 struct ice_vsi *vsi;
1372 unsigned long q_map;
1375 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states) &&
1376 !test_bit(ICE_VF_STATE_QS_ENA, vf->vf_states)) {
1377 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1381 if (!ice_vc_isvalid_vsi_id(vf, vqs->vsi_id)) {
1382 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1386 if (!ice_vc_validate_vqs_bitmaps(vqs)) {
1387 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1391 vsi = ice_get_vf_vsi(vf);
1393 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1397 if (vqs->tx_queues) {
1398 q_map = vqs->tx_queues;
1400 for_each_set_bit(vf_q_id, &q_map, ICE_MAX_RSS_QS_PER_VF) {
1401 if (!ice_vc_isvalid_q_id(vf, vqs->vsi_id, vf_q_id)) {
1402 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1406 if (ice_vf_vsi_dis_single_txq(vf, vsi, vf_q_id)) {
1407 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1413 q_map = vqs->rx_queues;
1414 /* speed up Rx queue disable by batching them if possible */
1416 bitmap_equal(&q_map, vf->rxq_ena, ICE_MAX_RSS_QS_PER_VF)) {
1417 if (ice_vsi_stop_all_rx_rings(vsi)) {
1418 dev_err(ice_pf_to_dev(vsi->back), "Failed to stop all Rx rings on VSI %d\n",
1420 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1424 bitmap_zero(vf->rxq_ena, ICE_MAX_RSS_QS_PER_VF);
1426 for_each_set_bit(vf_q_id, &q_map, ICE_MAX_RSS_QS_PER_VF) {
1427 if (!ice_vc_isvalid_q_id(vf, vqs->vsi_id, vf_q_id)) {
1428 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1432 /* Skip queue if not enabled */
1433 if (!test_bit(vf_q_id, vf->rxq_ena))
1436 if (ice_vsi_ctrl_one_rx_ring(vsi, false, vf_q_id,
1438 dev_err(ice_pf_to_dev(vsi->back), "Failed to stop Rx ring %d on VSI %d\n",
1439 vf_q_id, vsi->vsi_num);
1440 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1444 /* Clear enabled queues flag */
1445 clear_bit(vf_q_id, vf->rxq_ena);
1449 /* Clear enabled queues flag */
1450 if (v_ret == VIRTCHNL_STATUS_SUCCESS && ice_vf_has_no_qs_ena(vf))
1451 clear_bit(ICE_VF_STATE_QS_ENA, vf->vf_states);
1454 /* send the response to the VF */
1455 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_DISABLE_QUEUES, v_ret,
1461 * @vf: pointer to the VF info
1462 * @vsi: the VSI being configured
1463 * @vector_id: vector ID
1464 * @map: vector map for mapping vectors to queues
1465 * @q_vector: structure for interrupt vector
1466 * configure the IRQ to queue map
1469 ice_cfg_interrupt(struct ice_vf *vf, struct ice_vsi *vsi, u16 vector_id,
1470 struct virtchnl_vector_map *map,
1471 struct ice_q_vector *q_vector)
1473 u16 vsi_q_id, vsi_q_id_idx;
1476 q_vector->num_ring_rx = 0;
1477 q_vector->num_ring_tx = 0;
1479 qmap = map->rxq_map;
1480 for_each_set_bit(vsi_q_id_idx, &qmap, ICE_MAX_RSS_QS_PER_VF) {
1481 vsi_q_id = vsi_q_id_idx;
1483 if (!ice_vc_isvalid_q_id(vf, vsi->vsi_num, vsi_q_id))
1484 return VIRTCHNL_STATUS_ERR_PARAM;
1486 q_vector->num_ring_rx++;
1487 q_vector->rx.itr_idx = map->rxitr_idx;
1488 vsi->rx_rings[vsi_q_id]->q_vector = q_vector;
1489 ice_cfg_rxq_interrupt(vsi, vsi_q_id, vector_id,
1490 q_vector->rx.itr_idx);
1493 qmap = map->txq_map;
1494 for_each_set_bit(vsi_q_id_idx, &qmap, ICE_MAX_RSS_QS_PER_VF) {
1495 vsi_q_id = vsi_q_id_idx;
1497 if (!ice_vc_isvalid_q_id(vf, vsi->vsi_num, vsi_q_id))
1498 return VIRTCHNL_STATUS_ERR_PARAM;
1500 q_vector->num_ring_tx++;
1501 q_vector->tx.itr_idx = map->txitr_idx;
1502 vsi->tx_rings[vsi_q_id]->q_vector = q_vector;
1503 ice_cfg_txq_interrupt(vsi, vsi_q_id, vector_id,
1504 q_vector->tx.itr_idx);
1507 return VIRTCHNL_STATUS_SUCCESS;
1511 * ice_vc_cfg_irq_map_msg
1512 * @vf: pointer to the VF info
1513 * @msg: pointer to the msg buffer
1515 * called from the VF to configure the IRQ to queue map
1517 static int ice_vc_cfg_irq_map_msg(struct ice_vf *vf, u8 *msg)
1519 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
1520 u16 num_q_vectors_mapped, vsi_id, vector_id;
1521 struct virtchnl_irq_map_info *irqmap_info;
1522 struct virtchnl_vector_map *map;
1523 struct ice_pf *pf = vf->pf;
1524 struct ice_vsi *vsi;
1527 irqmap_info = (struct virtchnl_irq_map_info *)msg;
1528 num_q_vectors_mapped = irqmap_info->num_vectors;
1530 /* Check to make sure number of VF vectors mapped is not greater than
1531 * number of VF vectors originally allocated, and check that
1532 * there is actually at least a single VF queue vector mapped
1534 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states) ||
1535 pf->vfs.num_msix_per < num_q_vectors_mapped ||
1536 !num_q_vectors_mapped) {
1537 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1541 vsi = ice_get_vf_vsi(vf);
1543 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1547 for (i = 0; i < num_q_vectors_mapped; i++) {
1548 struct ice_q_vector *q_vector;
1550 map = &irqmap_info->vecmap[i];
1552 vector_id = map->vector_id;
1553 vsi_id = map->vsi_id;
1554 /* vector_id is always 0-based for each VF, and can never be
1555 * larger than or equal to the max allowed interrupts per VF
1557 if (!(vector_id < pf->vfs.num_msix_per) ||
1558 !ice_vc_isvalid_vsi_id(vf, vsi_id) ||
1559 (!vector_id && (map->rxq_map || map->txq_map))) {
1560 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1564 /* No need to map VF miscellaneous or rogue vector */
1568 /* Subtract non queue vector from vector_id passed by VF
1569 * to get actual number of VSI queue vector array index
1571 q_vector = vsi->q_vectors[vector_id - ICE_NONQ_VECS_VF];
1573 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1577 /* lookout for the invalid queue index */
1578 v_ret = (enum virtchnl_status_code)
1579 ice_cfg_interrupt(vf, vsi, vector_id, map, q_vector);
1585 /* send the response to the VF */
1586 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_CONFIG_IRQ_MAP, v_ret,
1592 * @vf: pointer to the VF info
1593 * @msg: pointer to the msg buffer
1595 * called from the VF to configure the Rx/Tx queues
1597 static int ice_vc_cfg_qs_msg(struct ice_vf *vf, u8 *msg)
1599 struct virtchnl_vsi_queue_config_info *qci =
1600 (struct virtchnl_vsi_queue_config_info *)msg;
1601 struct virtchnl_queue_pair_info *qpi;
1602 struct ice_pf *pf = vf->pf;
1603 struct ice_vsi *vsi;
1606 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states))
1609 if (!ice_vc_isvalid_vsi_id(vf, qci->vsi_id))
1612 vsi = ice_get_vf_vsi(vf);
1616 if (qci->num_queue_pairs > ICE_MAX_RSS_QS_PER_VF ||
1617 qci->num_queue_pairs > min_t(u16, vsi->alloc_txq, vsi->alloc_rxq)) {
1618 dev_err(ice_pf_to_dev(pf), "VF-%d requesting more than supported number of queues: %d\n",
1619 vf->vf_id, min_t(u16, vsi->alloc_txq, vsi->alloc_rxq));
1623 for (i = 0; i < qci->num_queue_pairs; i++) {
1624 qpi = &qci->qpair[i];
1625 if (qpi->txq.vsi_id != qci->vsi_id ||
1626 qpi->rxq.vsi_id != qci->vsi_id ||
1627 qpi->rxq.queue_id != qpi->txq.queue_id ||
1628 qpi->txq.headwb_enabled ||
1629 !ice_vc_isvalid_ring_len(qpi->txq.ring_len) ||
1630 !ice_vc_isvalid_ring_len(qpi->rxq.ring_len) ||
1631 !ice_vc_isvalid_q_id(vf, qci->vsi_id, qpi->txq.queue_id)) {
1635 q_idx = qpi->rxq.queue_id;
1637 /* make sure selected "q_idx" is in valid range of queues
1638 * for selected "vsi"
1640 if (q_idx >= vsi->alloc_txq || q_idx >= vsi->alloc_rxq) {
1644 /* copy Tx queue info from VF into VSI */
1645 if (qpi->txq.ring_len > 0) {
1646 vsi->tx_rings[i]->dma = qpi->txq.dma_ring_addr;
1647 vsi->tx_rings[i]->count = qpi->txq.ring_len;
1649 /* Disable any existing queue first */
1650 if (ice_vf_vsi_dis_single_txq(vf, vsi, q_idx))
1653 /* Configure a queue with the requested settings */
1654 if (ice_vsi_cfg_single_txq(vsi, vsi->tx_rings, q_idx)) {
1655 dev_warn(ice_pf_to_dev(pf), "VF-%d failed to configure TX queue %d\n",
1661 /* copy Rx queue info from VF into VSI */
1662 if (qpi->rxq.ring_len > 0) {
1663 u16 max_frame_size = ice_vc_get_max_frame_size(vf);
1666 vsi->rx_rings[i]->dma = qpi->rxq.dma_ring_addr;
1667 vsi->rx_rings[i]->count = qpi->rxq.ring_len;
1669 if (qpi->rxq.databuffer_size != 0 &&
1670 (qpi->rxq.databuffer_size > ((16 * 1024) - 128) ||
1671 qpi->rxq.databuffer_size < 1024))
1673 vsi->rx_buf_len = qpi->rxq.databuffer_size;
1674 vsi->rx_rings[i]->rx_buf_len = vsi->rx_buf_len;
1675 if (qpi->rxq.max_pkt_size > max_frame_size ||
1676 qpi->rxq.max_pkt_size < 64)
1679 vsi->max_frame = qpi->rxq.max_pkt_size;
1680 /* add space for the port VLAN since the VF driver is
1681 * not expected to account for it in the MTU
1684 if (ice_vf_is_port_vlan_ena(vf))
1685 vsi->max_frame += VLAN_HLEN;
1687 if (ice_vsi_cfg_single_rxq(vsi, q_idx)) {
1688 dev_warn(ice_pf_to_dev(pf), "VF-%d failed to configure RX queue %d\n",
1693 /* If Rx flex desc is supported, select RXDID for Rx
1694 * queues. Otherwise, use legacy 32byte descriptor
1695 * format. Legacy 16byte descriptor is not supported.
1696 * If this RXDID is selected, return error.
1698 if (vf->driver_caps &
1699 VIRTCHNL_VF_OFFLOAD_RX_FLEX_DESC) {
1700 rxdid = qpi->rxq.rxdid;
1701 if (!(BIT(rxdid) & pf->supported_rxdids))
1704 rxdid = ICE_RXDID_LEGACY_1;
1707 ice_write_qrxflxp_cntxt(&vsi->back->hw,
1708 vsi->rxq_map[q_idx],
1709 rxdid, 0x03, false);
1713 /* send the response to the VF */
1714 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_CONFIG_VSI_QUEUES,
1715 VIRTCHNL_STATUS_SUCCESS, NULL, 0);
1717 /* disable whatever we can */
1718 for (; i >= 0; i--) {
1719 if (ice_vsi_ctrl_one_rx_ring(vsi, false, i, true))
1720 dev_err(ice_pf_to_dev(pf), "VF-%d could not disable RX queue %d\n",
1722 if (ice_vf_vsi_dis_single_txq(vf, vsi, i))
1723 dev_err(ice_pf_to_dev(pf), "VF-%d could not disable TX queue %d\n",
1727 /* send the response to the VF */
1728 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_CONFIG_VSI_QUEUES,
1729 VIRTCHNL_STATUS_ERR_PARAM, NULL, 0);
1733 * ice_can_vf_change_mac
1734 * @vf: pointer to the VF info
1736 * Return true if the VF is allowed to change its MAC filters, false otherwise
1738 static bool ice_can_vf_change_mac(struct ice_vf *vf)
1740 /* If the VF MAC address has been set administratively (via the
1741 * ndo_set_vf_mac command), then deny permission to the VF to
1742 * add/delete unicast MAC addresses, unless the VF is trusted
1744 if (vf->pf_set_mac && !ice_is_vf_trusted(vf))
1751 * ice_vc_ether_addr_type - get type of virtchnl_ether_addr
1752 * @vc_ether_addr: used to extract the type
1755 ice_vc_ether_addr_type(struct virtchnl_ether_addr *vc_ether_addr)
1757 return (vc_ether_addr->type & VIRTCHNL_ETHER_ADDR_TYPE_MASK);
1761 * ice_is_vc_addr_legacy - check if the MAC address is from an older VF
1762 * @vc_ether_addr: VIRTCHNL structure that contains MAC and type
1765 ice_is_vc_addr_legacy(struct virtchnl_ether_addr *vc_ether_addr)
1767 u8 type = ice_vc_ether_addr_type(vc_ether_addr);
1769 return (type == VIRTCHNL_ETHER_ADDR_LEGACY);
1773 * ice_is_vc_addr_primary - check if the MAC address is the VF's primary MAC
1774 * @vc_ether_addr: VIRTCHNL structure that contains MAC and type
1776 * This function should only be called when the MAC address in
1777 * virtchnl_ether_addr is a valid unicast MAC
1780 ice_is_vc_addr_primary(struct virtchnl_ether_addr __maybe_unused *vc_ether_addr)
1782 u8 type = ice_vc_ether_addr_type(vc_ether_addr);
1784 return (type == VIRTCHNL_ETHER_ADDR_PRIMARY);
1788 * ice_vfhw_mac_add - update the VF's cached hardware MAC if allowed
1790 * @vc_ether_addr: structure from VIRTCHNL with MAC to add
1793 ice_vfhw_mac_add(struct ice_vf *vf, struct virtchnl_ether_addr *vc_ether_addr)
1795 u8 *mac_addr = vc_ether_addr->addr;
1797 if (!is_valid_ether_addr(mac_addr))
1800 /* only allow legacy VF drivers to set the device and hardware MAC if it
1801 * is zero and allow new VF drivers to set the hardware MAC if the type
1802 * was correctly specified over VIRTCHNL
1804 if ((ice_is_vc_addr_legacy(vc_ether_addr) &&
1805 is_zero_ether_addr(vf->hw_lan_addr)) ||
1806 ice_is_vc_addr_primary(vc_ether_addr)) {
1807 ether_addr_copy(vf->dev_lan_addr, mac_addr);
1808 ether_addr_copy(vf->hw_lan_addr, mac_addr);
1811 /* hardware and device MACs are already set, but its possible that the
1812 * VF driver sent the VIRTCHNL_OP_ADD_ETH_ADDR message before the
1813 * VIRTCHNL_OP_DEL_ETH_ADDR when trying to update its MAC, so save it
1814 * away for the legacy VF driver case as it will be updated in the
1815 * delete flow for this case
1817 if (ice_is_vc_addr_legacy(vc_ether_addr)) {
1818 ether_addr_copy(vf->legacy_last_added_umac.addr,
1820 vf->legacy_last_added_umac.time_modified = jiffies;
1825 * ice_vc_add_mac_addr - attempt to add the MAC address passed in
1826 * @vf: pointer to the VF info
1827 * @vsi: pointer to the VF's VSI
1828 * @vc_ether_addr: VIRTCHNL MAC address structure used to add MAC
1831 ice_vc_add_mac_addr(struct ice_vf *vf, struct ice_vsi *vsi,
1832 struct virtchnl_ether_addr *vc_ether_addr)
1834 struct device *dev = ice_pf_to_dev(vf->pf);
1835 u8 *mac_addr = vc_ether_addr->addr;
1838 /* device MAC already added */
1839 if (ether_addr_equal(mac_addr, vf->dev_lan_addr))
1842 if (is_unicast_ether_addr(mac_addr) && !ice_can_vf_change_mac(vf)) {
1843 dev_err(dev, "VF attempting to override administratively set MAC address, bring down and up the VF interface to resume normal operation\n");
1847 ret = ice_fltr_add_mac(vsi, mac_addr, ICE_FWD_TO_VSI);
1848 if (ret == -EEXIST) {
1849 dev_dbg(dev, "MAC %pM already exists for VF %d\n", mac_addr,
1851 /* don't return since we might need to update
1852 * the primary MAC in ice_vfhw_mac_add() below
1855 dev_err(dev, "Failed to add MAC %pM for VF %d\n, error %d\n",
1856 mac_addr, vf->vf_id, ret);
1862 ice_vfhw_mac_add(vf, vc_ether_addr);
1868 * ice_is_legacy_umac_expired - check if last added legacy unicast MAC expired
1869 * @last_added_umac: structure used to check expiration
1871 static bool ice_is_legacy_umac_expired(struct ice_time_mac *last_added_umac)
1873 #define ICE_LEGACY_VF_MAC_CHANGE_EXPIRE_TIME msecs_to_jiffies(3000)
1874 return time_is_before_jiffies(last_added_umac->time_modified +
1875 ICE_LEGACY_VF_MAC_CHANGE_EXPIRE_TIME);
1879 * ice_update_legacy_cached_mac - update cached hardware MAC for legacy VF
1881 * @vc_ether_addr: structure from VIRTCHNL with MAC to check
1883 * only update cached hardware MAC for legacy VF drivers on delete
1884 * because we cannot guarantee order/type of MAC from the VF driver
1887 ice_update_legacy_cached_mac(struct ice_vf *vf,
1888 struct virtchnl_ether_addr *vc_ether_addr)
1890 if (!ice_is_vc_addr_legacy(vc_ether_addr) ||
1891 ice_is_legacy_umac_expired(&vf->legacy_last_added_umac))
1894 ether_addr_copy(vf->dev_lan_addr, vf->legacy_last_added_umac.addr);
1895 ether_addr_copy(vf->hw_lan_addr, vf->legacy_last_added_umac.addr);
1899 * ice_vfhw_mac_del - update the VF's cached hardware MAC if allowed
1901 * @vc_ether_addr: structure from VIRTCHNL with MAC to delete
1904 ice_vfhw_mac_del(struct ice_vf *vf, struct virtchnl_ether_addr *vc_ether_addr)
1906 u8 *mac_addr = vc_ether_addr->addr;
1908 if (!is_valid_ether_addr(mac_addr) ||
1909 !ether_addr_equal(vf->dev_lan_addr, mac_addr))
1912 /* allow the device MAC to be repopulated in the add flow and don't
1913 * clear the hardware MAC (i.e. hw_lan_addr) here as that is meant
1914 * to be persistent on VM reboot and across driver unload/load, which
1915 * won't work if we clear the hardware MAC here
1917 eth_zero_addr(vf->dev_lan_addr);
1919 ice_update_legacy_cached_mac(vf, vc_ether_addr);
1923 * ice_vc_del_mac_addr - attempt to delete the MAC address passed in
1924 * @vf: pointer to the VF info
1925 * @vsi: pointer to the VF's VSI
1926 * @vc_ether_addr: VIRTCHNL MAC address structure used to delete MAC
1929 ice_vc_del_mac_addr(struct ice_vf *vf, struct ice_vsi *vsi,
1930 struct virtchnl_ether_addr *vc_ether_addr)
1932 struct device *dev = ice_pf_to_dev(vf->pf);
1933 u8 *mac_addr = vc_ether_addr->addr;
1936 if (!ice_can_vf_change_mac(vf) &&
1937 ether_addr_equal(vf->dev_lan_addr, mac_addr))
1940 status = ice_fltr_remove_mac(vsi, mac_addr, ICE_FWD_TO_VSI);
1941 if (status == -ENOENT) {
1942 dev_err(dev, "MAC %pM does not exist for VF %d\n", mac_addr,
1945 } else if (status) {
1946 dev_err(dev, "Failed to delete MAC %pM for VF %d, error %d\n",
1947 mac_addr, vf->vf_id, status);
1951 ice_vfhw_mac_del(vf, vc_ether_addr);
1959 * ice_vc_handle_mac_addr_msg
1960 * @vf: pointer to the VF info
1961 * @msg: pointer to the msg buffer
1962 * @set: true if MAC filters are being set, false otherwise
1964 * add guest MAC address filter
1967 ice_vc_handle_mac_addr_msg(struct ice_vf *vf, u8 *msg, bool set)
1969 int (*ice_vc_cfg_mac)
1970 (struct ice_vf *vf, struct ice_vsi *vsi,
1971 struct virtchnl_ether_addr *virtchnl_ether_addr);
1972 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
1973 struct virtchnl_ether_addr_list *al =
1974 (struct virtchnl_ether_addr_list *)msg;
1975 struct ice_pf *pf = vf->pf;
1976 enum virtchnl_ops vc_op;
1977 struct ice_vsi *vsi;
1981 vc_op = VIRTCHNL_OP_ADD_ETH_ADDR;
1982 ice_vc_cfg_mac = ice_vc_add_mac_addr;
1984 vc_op = VIRTCHNL_OP_DEL_ETH_ADDR;
1985 ice_vc_cfg_mac = ice_vc_del_mac_addr;
1988 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states) ||
1989 !ice_vc_isvalid_vsi_id(vf, al->vsi_id)) {
1990 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1991 goto handle_mac_exit;
1994 /* If this VF is not privileged, then we can't add more than a
1995 * limited number of addresses. Check to make sure that the
1996 * additions do not push us over the limit.
1998 if (set && !ice_is_vf_trusted(vf) &&
1999 (vf->num_mac + al->num_elements) > ICE_MAX_MACADDR_PER_VF) {
2000 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",
2002 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2003 goto handle_mac_exit;
2006 vsi = ice_get_vf_vsi(vf);
2008 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2009 goto handle_mac_exit;
2012 for (i = 0; i < al->num_elements; i++) {
2013 u8 *mac_addr = al->list[i].addr;
2016 if (is_broadcast_ether_addr(mac_addr) ||
2017 is_zero_ether_addr(mac_addr))
2020 result = ice_vc_cfg_mac(vf, vsi, &al->list[i]);
2021 if (result == -EEXIST || result == -ENOENT) {
2023 } else if (result) {
2024 v_ret = VIRTCHNL_STATUS_ERR_ADMIN_QUEUE_ERROR;
2025 goto handle_mac_exit;
2030 /* send the response to the VF */
2031 return ice_vc_send_msg_to_vf(vf, vc_op, v_ret, NULL, 0);
2035 * ice_vc_add_mac_addr_msg
2036 * @vf: pointer to the VF info
2037 * @msg: pointer to the msg buffer
2039 * add guest MAC address filter
2041 static int ice_vc_add_mac_addr_msg(struct ice_vf *vf, u8 *msg)
2043 return ice_vc_handle_mac_addr_msg(vf, msg, true);
2047 * ice_vc_del_mac_addr_msg
2048 * @vf: pointer to the VF info
2049 * @msg: pointer to the msg buffer
2051 * remove guest MAC address filter
2053 static int ice_vc_del_mac_addr_msg(struct ice_vf *vf, u8 *msg)
2055 return ice_vc_handle_mac_addr_msg(vf, msg, false);
2059 * ice_vc_request_qs_msg
2060 * @vf: pointer to the VF info
2061 * @msg: pointer to the msg buffer
2063 * VFs get a default number of queues but can use this message to request a
2064 * different number. If the request is successful, PF will reset the VF and
2065 * return 0. If unsuccessful, PF will send message informing VF of number of
2066 * available queue pairs via virtchnl message response to VF.
2068 static int ice_vc_request_qs_msg(struct ice_vf *vf, u8 *msg)
2070 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
2071 struct virtchnl_vf_res_request *vfres =
2072 (struct virtchnl_vf_res_request *)msg;
2073 u16 req_queues = vfres->num_queue_pairs;
2074 struct ice_pf *pf = vf->pf;
2075 u16 max_allowed_vf_queues;
2076 u16 tx_rx_queue_left;
2080 dev = ice_pf_to_dev(pf);
2081 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
2082 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2086 cur_queues = vf->num_vf_qs;
2087 tx_rx_queue_left = min_t(u16, ice_get_avail_txq_count(pf),
2088 ice_get_avail_rxq_count(pf));
2089 max_allowed_vf_queues = tx_rx_queue_left + cur_queues;
2091 dev_err(dev, "VF %d tried to request 0 queues. Ignoring.\n",
2093 } else if (req_queues > ICE_MAX_RSS_QS_PER_VF) {
2094 dev_err(dev, "VF %d tried to request more than %d queues.\n",
2095 vf->vf_id, ICE_MAX_RSS_QS_PER_VF);
2096 vfres->num_queue_pairs = ICE_MAX_RSS_QS_PER_VF;
2097 } else if (req_queues > cur_queues &&
2098 req_queues - cur_queues > tx_rx_queue_left) {
2099 dev_warn(dev, "VF %d requested %u more queues, but only %u left.\n",
2100 vf->vf_id, req_queues - cur_queues, tx_rx_queue_left);
2101 vfres->num_queue_pairs = min_t(u16, max_allowed_vf_queues,
2102 ICE_MAX_RSS_QS_PER_VF);
2104 /* request is successful, then reset VF */
2105 vf->num_req_qs = req_queues;
2106 ice_reset_vf(vf, ICE_VF_RESET_NOTIFY);
2107 dev_info(dev, "VF %d granted request of %u queues.\n",
2108 vf->vf_id, req_queues);
2113 /* send the response to the VF */
2114 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_REQUEST_QUEUES,
2115 v_ret, (u8 *)vfres, sizeof(*vfres));
2119 * ice_vf_vlan_offload_ena - determine if capabilities support VLAN offloads
2120 * @caps: VF driver negotiated capabilities
2122 * Return true if VIRTCHNL_VF_OFFLOAD_VLAN capability is set, else return false
2124 static bool ice_vf_vlan_offload_ena(u32 caps)
2126 return !!(caps & VIRTCHNL_VF_OFFLOAD_VLAN);
2130 * ice_is_vlan_promisc_allowed - check if VLAN promiscuous config is allowed
2131 * @vf: VF used to determine if VLAN promiscuous config is allowed
2133 static bool ice_is_vlan_promisc_allowed(struct ice_vf *vf)
2135 if ((test_bit(ICE_VF_STATE_UC_PROMISC, vf->vf_states) ||
2136 test_bit(ICE_VF_STATE_MC_PROMISC, vf->vf_states)) &&
2137 test_bit(ICE_FLAG_VF_TRUE_PROMISC_ENA, vf->pf->flags))
2144 * ice_vf_ena_vlan_promisc - Enable Tx/Rx VLAN promiscuous for the VLAN
2145 * @vsi: VF's VSI used to enable VLAN promiscuous mode
2146 * @vlan: VLAN used to enable VLAN promiscuous
2148 * This function should only be called if VLAN promiscuous mode is allowed,
2149 * which can be determined via ice_is_vlan_promisc_allowed().
2151 static int ice_vf_ena_vlan_promisc(struct ice_vsi *vsi, struct ice_vlan *vlan)
2153 u8 promisc_m = ICE_PROMISC_VLAN_TX | ICE_PROMISC_VLAN_RX;
2156 status = ice_fltr_set_vsi_promisc(&vsi->back->hw, vsi->idx, promisc_m,
2158 if (status && status != -EEXIST)
2165 * ice_vf_dis_vlan_promisc - Disable Tx/Rx VLAN promiscuous for the VLAN
2166 * @vsi: VF's VSI used to disable VLAN promiscuous mode for
2167 * @vlan: VLAN used to disable VLAN promiscuous
2169 * This function should only be called if VLAN promiscuous mode is allowed,
2170 * which can be determined via ice_is_vlan_promisc_allowed().
2172 static int ice_vf_dis_vlan_promisc(struct ice_vsi *vsi, struct ice_vlan *vlan)
2174 u8 promisc_m = ICE_PROMISC_VLAN_TX | ICE_PROMISC_VLAN_RX;
2177 status = ice_fltr_clear_vsi_promisc(&vsi->back->hw, vsi->idx, promisc_m,
2179 if (status && status != -ENOENT)
2186 * ice_vf_has_max_vlans - check if VF already has the max allowed VLAN filters
2187 * @vf: VF to check against
2190 * If the VF is trusted then the VF is allowed to add as many VLANs as it
2191 * wants to, so return false.
2193 * When the VF is untrusted compare the number of non-zero VLANs + 1 to the max
2194 * allowed VLANs for an untrusted VF. Return the result of this comparison.
2196 static bool ice_vf_has_max_vlans(struct ice_vf *vf, struct ice_vsi *vsi)
2198 if (ice_is_vf_trusted(vf))
2201 #define ICE_VF_ADDED_VLAN_ZERO_FLTRS 1
2202 return ((ice_vsi_num_non_zero_vlans(vsi) +
2203 ICE_VF_ADDED_VLAN_ZERO_FLTRS) >= ICE_MAX_VLAN_PER_VF);
2207 * ice_vc_process_vlan_msg
2208 * @vf: pointer to the VF info
2209 * @msg: pointer to the msg buffer
2210 * @add_v: Add VLAN if true, otherwise delete VLAN
2212 * Process virtchnl op to add or remove programmed guest VLAN ID
2214 static int ice_vc_process_vlan_msg(struct ice_vf *vf, u8 *msg, bool add_v)
2216 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
2217 struct virtchnl_vlan_filter_list *vfl =
2218 (struct virtchnl_vlan_filter_list *)msg;
2219 struct ice_pf *pf = vf->pf;
2220 bool vlan_promisc = false;
2221 struct ice_vsi *vsi;
2226 dev = ice_pf_to_dev(pf);
2227 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
2228 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2232 if (!ice_vf_vlan_offload_ena(vf->driver_caps)) {
2233 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2237 if (!ice_vc_isvalid_vsi_id(vf, vfl->vsi_id)) {
2238 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2242 for (i = 0; i < vfl->num_elements; i++) {
2243 if (vfl->vlan_id[i] >= VLAN_N_VID) {
2244 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2245 dev_err(dev, "invalid VF VLAN id %d\n",
2251 vsi = ice_get_vf_vsi(vf);
2253 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2257 if (add_v && ice_vf_has_max_vlans(vf, vsi)) {
2258 dev_info(dev, "VF-%d is not trusted, switch the VF to trusted mode, in order to add more VLAN addresses\n",
2260 /* There is no need to let VF know about being not trusted,
2261 * so we can just return success message here
2266 /* in DVM a VF can add/delete inner VLAN filters when
2267 * VIRTCHNL_VF_OFFLOAD_VLAN is negotiated, so only reject in SVM
2269 if (ice_vf_is_port_vlan_ena(vf) && !ice_is_dvm_ena(&pf->hw)) {
2270 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2274 /* in DVM VLAN promiscuous is based on the outer VLAN, which would be
2275 * the port VLAN if VIRTCHNL_VF_OFFLOAD_VLAN was negotiated, so only
2276 * allow vlan_promisc = true in SVM and if no port VLAN is configured
2278 vlan_promisc = ice_is_vlan_promisc_allowed(vf) &&
2279 !ice_is_dvm_ena(&pf->hw) &&
2280 !ice_vf_is_port_vlan_ena(vf);
2283 for (i = 0; i < vfl->num_elements; i++) {
2284 u16 vid = vfl->vlan_id[i];
2285 struct ice_vlan vlan;
2287 if (ice_vf_has_max_vlans(vf, vsi)) {
2288 dev_info(dev, "VF-%d is not trusted, switch the VF to trusted mode, in order to add more VLAN addresses\n",
2290 /* There is no need to let VF know about being
2291 * not trusted, so we can just return success
2292 * message here as well.
2297 /* we add VLAN 0 by default for each VF so we can enable
2298 * Tx VLAN anti-spoof without triggering MDD events so
2299 * we don't need to add it again here
2304 vlan = ICE_VLAN(ETH_P_8021Q, vid, 0);
2305 status = vsi->inner_vlan_ops.add_vlan(vsi, &vlan);
2307 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2311 /* Enable VLAN filtering on first non-zero VLAN */
2312 if (!vlan_promisc && vid && !ice_is_dvm_ena(&pf->hw)) {
2314 status = vsi->inner_vlan_ops.ena_tx_filtering(vsi);
2316 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2317 dev_err(dev, "Enable VLAN anti-spoofing on VLAN ID: %d failed error-%d\n",
2322 if (vsi->inner_vlan_ops.ena_rx_filtering(vsi)) {
2323 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2324 dev_err(dev, "Enable VLAN pruning on VLAN ID: %d failed error-%d\n",
2328 } else if (vlan_promisc) {
2329 status = ice_vf_ena_vlan_promisc(vsi, &vlan);
2331 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2332 dev_err(dev, "Enable Unicast/multicast promiscuous mode on VLAN ID:%d failed error-%d\n",
2338 /* In case of non_trusted VF, number of VLAN elements passed
2339 * to PF for removal might be greater than number of VLANs
2340 * filter programmed for that VF - So, use actual number of
2341 * VLANS added earlier with add VLAN opcode. In order to avoid
2342 * removing VLAN that doesn't exist, which result to sending
2343 * erroneous failed message back to the VF
2347 num_vf_vlan = vsi->num_vlan;
2348 for (i = 0; i < vfl->num_elements && i < num_vf_vlan; i++) {
2349 u16 vid = vfl->vlan_id[i];
2350 struct ice_vlan vlan;
2352 /* we add VLAN 0 by default for each VF so we can enable
2353 * Tx VLAN anti-spoof without triggering MDD events so
2354 * we don't want a VIRTCHNL request to remove it
2359 vlan = ICE_VLAN(ETH_P_8021Q, vid, 0);
2360 status = vsi->inner_vlan_ops.del_vlan(vsi, &vlan);
2362 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2366 /* Disable VLAN filtering when only VLAN 0 is left */
2367 if (!ice_vsi_has_non_zero_vlans(vsi)) {
2368 vsi->inner_vlan_ops.dis_tx_filtering(vsi);
2369 vsi->inner_vlan_ops.dis_rx_filtering(vsi);
2373 ice_vf_dis_vlan_promisc(vsi, &vlan);
2378 /* send the response to the VF */
2380 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_ADD_VLAN, v_ret,
2383 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_DEL_VLAN, v_ret,
2388 * ice_vc_add_vlan_msg
2389 * @vf: pointer to the VF info
2390 * @msg: pointer to the msg buffer
2392 * Add and program guest VLAN ID
2394 static int ice_vc_add_vlan_msg(struct ice_vf *vf, u8 *msg)
2396 return ice_vc_process_vlan_msg(vf, msg, true);
2400 * ice_vc_remove_vlan_msg
2401 * @vf: pointer to the VF info
2402 * @msg: pointer to the msg buffer
2404 * remove programmed guest VLAN ID
2406 static int ice_vc_remove_vlan_msg(struct ice_vf *vf, u8 *msg)
2408 return ice_vc_process_vlan_msg(vf, msg, false);
2412 * ice_vc_ena_vlan_stripping
2413 * @vf: pointer to the VF info
2415 * Enable VLAN header stripping for a given VF
2417 static int ice_vc_ena_vlan_stripping(struct ice_vf *vf)
2419 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
2420 struct ice_vsi *vsi;
2422 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
2423 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2427 if (!ice_vf_vlan_offload_ena(vf->driver_caps)) {
2428 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2432 vsi = ice_get_vf_vsi(vf);
2434 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2438 if (vsi->inner_vlan_ops.ena_stripping(vsi, ETH_P_8021Q))
2439 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2442 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_ENABLE_VLAN_STRIPPING,
2447 * ice_vc_dis_vlan_stripping
2448 * @vf: pointer to the VF info
2450 * Disable VLAN header stripping for a given VF
2452 static int ice_vc_dis_vlan_stripping(struct ice_vf *vf)
2454 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
2455 struct ice_vsi *vsi;
2457 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
2458 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2462 if (!ice_vf_vlan_offload_ena(vf->driver_caps)) {
2463 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2467 vsi = ice_get_vf_vsi(vf);
2469 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2473 if (vsi->inner_vlan_ops.dis_stripping(vsi))
2474 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2477 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_DISABLE_VLAN_STRIPPING,
2482 * ice_vc_get_rss_hena - return the RSS HENA bits allowed by the hardware
2483 * @vf: pointer to the VF info
2485 static int ice_vc_get_rss_hena(struct ice_vf *vf)
2487 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
2488 struct virtchnl_rss_hena *vrh = NULL;
2491 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
2492 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2496 if (!test_bit(ICE_FLAG_RSS_ENA, vf->pf->flags)) {
2497 dev_err(ice_pf_to_dev(vf->pf), "RSS not supported by PF\n");
2498 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2502 len = sizeof(struct virtchnl_rss_hena);
2503 vrh = kzalloc(len, GFP_KERNEL);
2505 v_ret = VIRTCHNL_STATUS_ERR_NO_MEMORY;
2510 vrh->hena = ICE_DEFAULT_RSS_HENA;
2512 /* send the response back to the VF */
2513 ret = ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_GET_RSS_HENA_CAPS, v_ret,
2520 * ice_vc_set_rss_hena - set RSS HENA bits for the VF
2521 * @vf: pointer to the VF info
2522 * @msg: pointer to the msg buffer
2524 static int ice_vc_set_rss_hena(struct ice_vf *vf, u8 *msg)
2526 struct virtchnl_rss_hena *vrh = (struct virtchnl_rss_hena *)msg;
2527 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
2528 struct ice_pf *pf = vf->pf;
2529 struct ice_vsi *vsi;
2533 dev = ice_pf_to_dev(pf);
2535 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
2536 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2540 if (!test_bit(ICE_FLAG_RSS_ENA, pf->flags)) {
2541 dev_err(dev, "RSS not supported by PF\n");
2542 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2546 vsi = ice_get_vf_vsi(vf);
2548 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2552 /* clear all previously programmed RSS configuration to allow VF drivers
2553 * the ability to customize the RSS configuration and/or completely
2556 status = ice_rem_vsi_rss_cfg(&pf->hw, vsi->idx);
2557 if (status && !vrh->hena) {
2558 /* only report failure to clear the current RSS configuration if
2559 * that was clearly the VF's intention (i.e. vrh->hena = 0)
2561 v_ret = ice_err_to_virt_err(status);
2563 } else if (status) {
2564 /* allow the VF to update the RSS configuration even on failure
2565 * to clear the current RSS confguration in an attempt to keep
2566 * RSS in a working state
2568 dev_warn(dev, "Failed to clear the RSS configuration for VF %u\n",
2573 status = ice_add_avf_rss_cfg(&pf->hw, vsi->idx, vrh->hena);
2574 v_ret = ice_err_to_virt_err(status);
2577 /* send the response to the VF */
2579 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_SET_RSS_HENA, v_ret,
2584 * ice_vc_query_rxdid - query RXDID supported by DDP package
2585 * @vf: pointer to VF info
2587 * Called from VF to query a bitmap of supported flexible
2588 * descriptor RXDIDs of a DDP package.
2590 static int ice_vc_query_rxdid(struct ice_vf *vf)
2592 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
2593 struct virtchnl_supported_rxdids *rxdid = NULL;
2594 struct ice_hw *hw = &vf->pf->hw;
2595 struct ice_pf *pf = vf->pf;
2600 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
2601 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2605 if (!(vf->driver_caps & VIRTCHNL_VF_OFFLOAD_RX_FLEX_DESC)) {
2606 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2610 len = sizeof(struct virtchnl_supported_rxdids);
2611 rxdid = kzalloc(len, GFP_KERNEL);
2613 v_ret = VIRTCHNL_STATUS_ERR_NO_MEMORY;
2618 /* Read flexiflag registers to determine whether the
2619 * corresponding RXDID is configured and supported or not.
2620 * Since Legacy 16byte descriptor format is not supported,
2621 * start from Legacy 32byte descriptor.
2623 for (i = ICE_RXDID_LEGACY_1; i < ICE_FLEX_DESC_RXDID_MAX_NUM; i++) {
2624 regval = rd32(hw, GLFLXP_RXDID_FLAGS(i, 0));
2625 if ((regval >> GLFLXP_RXDID_FLAGS_FLEXIFLAG_4N_S)
2626 & GLFLXP_RXDID_FLAGS_FLEXIFLAG_4N_M)
2627 rxdid->supported_rxdids |= BIT(i);
2630 pf->supported_rxdids = rxdid->supported_rxdids;
2633 ret = ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_GET_SUPPORTED_RXDIDS,
2634 v_ret, (u8 *)rxdid, len);
2640 * ice_vf_init_vlan_stripping - enable/disable VLAN stripping on initialization
2641 * @vf: VF to enable/disable VLAN stripping for on initialization
2643 * Set the default for VLAN stripping based on whether a port VLAN is configured
2644 * and the current VLAN mode of the device.
2646 static int ice_vf_init_vlan_stripping(struct ice_vf *vf)
2648 struct ice_vsi *vsi = ice_get_vf_vsi(vf);
2653 /* don't modify stripping if port VLAN is configured in SVM since the
2654 * port VLAN is based on the inner/single VLAN in SVM
2656 if (ice_vf_is_port_vlan_ena(vf) && !ice_is_dvm_ena(&vsi->back->hw))
2659 if (ice_vf_vlan_offload_ena(vf->driver_caps))
2660 return vsi->inner_vlan_ops.ena_stripping(vsi, ETH_P_8021Q);
2662 return vsi->inner_vlan_ops.dis_stripping(vsi);
2665 static u16 ice_vc_get_max_vlan_fltrs(struct ice_vf *vf)
2670 return ICE_MAX_VLAN_PER_VF;
2674 * ice_vf_outer_vlan_not_allowed - check if outer VLAN can be used
2675 * @vf: VF that being checked for
2677 * When the device is in double VLAN mode, check whether or not the outer VLAN
2680 static bool ice_vf_outer_vlan_not_allowed(struct ice_vf *vf)
2682 if (ice_vf_is_port_vlan_ena(vf))
2689 * ice_vc_set_dvm_caps - set VLAN capabilities when the device is in DVM
2690 * @vf: VF that capabilities are being set for
2691 * @caps: VLAN capabilities to populate
2693 * Determine VLAN capabilities support based on whether a port VLAN is
2694 * configured. If a port VLAN is configured then the VF should use the inner
2695 * filtering/offload capabilities since the port VLAN is using the outer VLAN
2699 ice_vc_set_dvm_caps(struct ice_vf *vf, struct virtchnl_vlan_caps *caps)
2701 struct virtchnl_vlan_supported_caps *supported_caps;
2703 if (ice_vf_outer_vlan_not_allowed(vf)) {
2704 /* until support for inner VLAN filtering is added when a port
2705 * VLAN is configured, only support software offloaded inner
2706 * VLANs when a port VLAN is confgured in DVM
2708 supported_caps = &caps->filtering.filtering_support;
2709 supported_caps->inner = VIRTCHNL_VLAN_UNSUPPORTED;
2711 supported_caps = &caps->offloads.stripping_support;
2712 supported_caps->inner = VIRTCHNL_VLAN_ETHERTYPE_8100 |
2713 VIRTCHNL_VLAN_TOGGLE |
2714 VIRTCHNL_VLAN_TAG_LOCATION_L2TAG1;
2715 supported_caps->outer = VIRTCHNL_VLAN_UNSUPPORTED;
2717 supported_caps = &caps->offloads.insertion_support;
2718 supported_caps->inner = VIRTCHNL_VLAN_ETHERTYPE_8100 |
2719 VIRTCHNL_VLAN_TOGGLE |
2720 VIRTCHNL_VLAN_TAG_LOCATION_L2TAG1;
2721 supported_caps->outer = VIRTCHNL_VLAN_UNSUPPORTED;
2723 caps->offloads.ethertype_init = VIRTCHNL_VLAN_ETHERTYPE_8100;
2724 caps->offloads.ethertype_match =
2725 VIRTCHNL_ETHERTYPE_STRIPPING_MATCHES_INSERTION;
2727 supported_caps = &caps->filtering.filtering_support;
2728 supported_caps->inner = VIRTCHNL_VLAN_UNSUPPORTED;
2729 supported_caps->outer = VIRTCHNL_VLAN_ETHERTYPE_8100 |
2730 VIRTCHNL_VLAN_ETHERTYPE_88A8 |
2731 VIRTCHNL_VLAN_ETHERTYPE_9100 |
2732 VIRTCHNL_VLAN_ETHERTYPE_AND;
2733 caps->filtering.ethertype_init = VIRTCHNL_VLAN_ETHERTYPE_8100 |
2734 VIRTCHNL_VLAN_ETHERTYPE_88A8 |
2735 VIRTCHNL_VLAN_ETHERTYPE_9100;
2737 supported_caps = &caps->offloads.stripping_support;
2738 supported_caps->inner = VIRTCHNL_VLAN_TOGGLE |
2739 VIRTCHNL_VLAN_ETHERTYPE_8100 |
2740 VIRTCHNL_VLAN_TAG_LOCATION_L2TAG1;
2741 supported_caps->outer = VIRTCHNL_VLAN_TOGGLE |
2742 VIRTCHNL_VLAN_ETHERTYPE_8100 |
2743 VIRTCHNL_VLAN_ETHERTYPE_88A8 |
2744 VIRTCHNL_VLAN_ETHERTYPE_9100 |
2745 VIRTCHNL_VLAN_ETHERTYPE_XOR |
2746 VIRTCHNL_VLAN_TAG_LOCATION_L2TAG2_2;
2748 supported_caps = &caps->offloads.insertion_support;
2749 supported_caps->inner = VIRTCHNL_VLAN_TOGGLE |
2750 VIRTCHNL_VLAN_ETHERTYPE_8100 |
2751 VIRTCHNL_VLAN_TAG_LOCATION_L2TAG1;
2752 supported_caps->outer = VIRTCHNL_VLAN_TOGGLE |
2753 VIRTCHNL_VLAN_ETHERTYPE_8100 |
2754 VIRTCHNL_VLAN_ETHERTYPE_88A8 |
2755 VIRTCHNL_VLAN_ETHERTYPE_9100 |
2756 VIRTCHNL_VLAN_ETHERTYPE_XOR |
2757 VIRTCHNL_VLAN_TAG_LOCATION_L2TAG2;
2759 caps->offloads.ethertype_init = VIRTCHNL_VLAN_ETHERTYPE_8100;
2761 caps->offloads.ethertype_match =
2762 VIRTCHNL_ETHERTYPE_STRIPPING_MATCHES_INSERTION;
2765 caps->filtering.max_filters = ice_vc_get_max_vlan_fltrs(vf);
2769 * ice_vc_set_svm_caps - set VLAN capabilities when the device is in SVM
2770 * @vf: VF that capabilities are being set for
2771 * @caps: VLAN capabilities to populate
2773 * Determine VLAN capabilities support based on whether a port VLAN is
2774 * configured. If a port VLAN is configured then the VF does not have any VLAN
2775 * filtering or offload capabilities since the port VLAN is using the inner VLAN
2776 * capabilities in single VLAN mode (SVM). Otherwise allow the VF to use inner
2777 * VLAN fitlering and offload capabilities.
2780 ice_vc_set_svm_caps(struct ice_vf *vf, struct virtchnl_vlan_caps *caps)
2782 struct virtchnl_vlan_supported_caps *supported_caps;
2784 if (ice_vf_is_port_vlan_ena(vf)) {
2785 supported_caps = &caps->filtering.filtering_support;
2786 supported_caps->inner = VIRTCHNL_VLAN_UNSUPPORTED;
2787 supported_caps->outer = VIRTCHNL_VLAN_UNSUPPORTED;
2789 supported_caps = &caps->offloads.stripping_support;
2790 supported_caps->inner = VIRTCHNL_VLAN_UNSUPPORTED;
2791 supported_caps->outer = VIRTCHNL_VLAN_UNSUPPORTED;
2793 supported_caps = &caps->offloads.insertion_support;
2794 supported_caps->inner = VIRTCHNL_VLAN_UNSUPPORTED;
2795 supported_caps->outer = VIRTCHNL_VLAN_UNSUPPORTED;
2797 caps->offloads.ethertype_init = VIRTCHNL_VLAN_UNSUPPORTED;
2798 caps->offloads.ethertype_match = VIRTCHNL_VLAN_UNSUPPORTED;
2799 caps->filtering.max_filters = 0;
2801 supported_caps = &caps->filtering.filtering_support;
2802 supported_caps->inner = VIRTCHNL_VLAN_ETHERTYPE_8100;
2803 supported_caps->outer = VIRTCHNL_VLAN_UNSUPPORTED;
2804 caps->filtering.ethertype_init = VIRTCHNL_VLAN_ETHERTYPE_8100;
2806 supported_caps = &caps->offloads.stripping_support;
2807 supported_caps->inner = VIRTCHNL_VLAN_ETHERTYPE_8100 |
2808 VIRTCHNL_VLAN_TOGGLE |
2809 VIRTCHNL_VLAN_TAG_LOCATION_L2TAG1;
2810 supported_caps->outer = VIRTCHNL_VLAN_UNSUPPORTED;
2812 supported_caps = &caps->offloads.insertion_support;
2813 supported_caps->inner = VIRTCHNL_VLAN_ETHERTYPE_8100 |
2814 VIRTCHNL_VLAN_TOGGLE |
2815 VIRTCHNL_VLAN_TAG_LOCATION_L2TAG1;
2816 supported_caps->outer = VIRTCHNL_VLAN_UNSUPPORTED;
2818 caps->offloads.ethertype_init = VIRTCHNL_VLAN_ETHERTYPE_8100;
2819 caps->offloads.ethertype_match =
2820 VIRTCHNL_ETHERTYPE_STRIPPING_MATCHES_INSERTION;
2821 caps->filtering.max_filters = ice_vc_get_max_vlan_fltrs(vf);
2826 * ice_vc_get_offload_vlan_v2_caps - determine VF's VLAN capabilities
2827 * @vf: VF to determine VLAN capabilities for
2829 * This will only be called if the VF and PF successfully negotiated
2830 * VIRTCHNL_VF_OFFLOAD_VLAN_V2.
2832 * Set VLAN capabilities based on the current VLAN mode and whether a port VLAN
2833 * is configured or not.
2835 static int ice_vc_get_offload_vlan_v2_caps(struct ice_vf *vf)
2837 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
2838 struct virtchnl_vlan_caps *caps = NULL;
2841 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
2842 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2846 caps = kzalloc(sizeof(*caps), GFP_KERNEL);
2848 v_ret = VIRTCHNL_STATUS_ERR_NO_MEMORY;
2851 len = sizeof(*caps);
2853 if (ice_is_dvm_ena(&vf->pf->hw))
2854 ice_vc_set_dvm_caps(vf, caps);
2856 ice_vc_set_svm_caps(vf, caps);
2858 /* store negotiated caps to prevent invalid VF messages */
2859 memcpy(&vf->vlan_v2_caps, caps, sizeof(*caps));
2862 err = ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS,
2863 v_ret, (u8 *)caps, len);
2869 * ice_vc_validate_vlan_tpid - validate VLAN TPID
2870 * @filtering_caps: negotiated/supported VLAN filtering capabilities
2871 * @tpid: VLAN TPID used for validation
2873 * Convert the VLAN TPID to a VIRTCHNL_VLAN_ETHERTYPE_* and then compare against
2874 * the negotiated/supported filtering caps to see if the VLAN TPID is valid.
2876 static bool ice_vc_validate_vlan_tpid(u16 filtering_caps, u16 tpid)
2878 enum virtchnl_vlan_support vlan_ethertype = VIRTCHNL_VLAN_UNSUPPORTED;
2882 vlan_ethertype = VIRTCHNL_VLAN_ETHERTYPE_8100;
2885 vlan_ethertype = VIRTCHNL_VLAN_ETHERTYPE_88A8;
2888 vlan_ethertype = VIRTCHNL_VLAN_ETHERTYPE_9100;
2892 if (!(filtering_caps & vlan_ethertype))
2899 * ice_vc_is_valid_vlan - validate the virtchnl_vlan
2900 * @vc_vlan: virtchnl_vlan to validate
2902 * If the VLAN TCI and VLAN TPID are 0, then this filter is invalid, so return
2903 * false. Otherwise return true.
2905 static bool ice_vc_is_valid_vlan(struct virtchnl_vlan *vc_vlan)
2907 if (!vc_vlan->tci || !vc_vlan->tpid)
2914 * ice_vc_validate_vlan_filter_list - validate the filter list from the VF
2915 * @vfc: negotiated/supported VLAN filtering capabilities
2916 * @vfl: VLAN filter list from VF to validate
2918 * Validate all of the filters in the VLAN filter list from the VF. If any of
2919 * the checks fail then return false. Otherwise return true.
2922 ice_vc_validate_vlan_filter_list(struct virtchnl_vlan_filtering_caps *vfc,
2923 struct virtchnl_vlan_filter_list_v2 *vfl)
2927 if (!vfl->num_elements)
2930 for (i = 0; i < vfl->num_elements; i++) {
2931 struct virtchnl_vlan_supported_caps *filtering_support =
2932 &vfc->filtering_support;
2933 struct virtchnl_vlan_filter *vlan_fltr = &vfl->filters[i];
2934 struct virtchnl_vlan *outer = &vlan_fltr->outer;
2935 struct virtchnl_vlan *inner = &vlan_fltr->inner;
2937 if ((ice_vc_is_valid_vlan(outer) &&
2938 filtering_support->outer == VIRTCHNL_VLAN_UNSUPPORTED) ||
2939 (ice_vc_is_valid_vlan(inner) &&
2940 filtering_support->inner == VIRTCHNL_VLAN_UNSUPPORTED))
2943 if ((outer->tci_mask &&
2944 !(filtering_support->outer & VIRTCHNL_VLAN_FILTER_MASK)) ||
2946 !(filtering_support->inner & VIRTCHNL_VLAN_FILTER_MASK)))
2949 if (((outer->tci & VLAN_PRIO_MASK) &&
2950 !(filtering_support->outer & VIRTCHNL_VLAN_PRIO)) ||
2951 ((inner->tci & VLAN_PRIO_MASK) &&
2952 !(filtering_support->inner & VIRTCHNL_VLAN_PRIO)))
2955 if ((ice_vc_is_valid_vlan(outer) &&
2956 !ice_vc_validate_vlan_tpid(filtering_support->outer,
2958 (ice_vc_is_valid_vlan(inner) &&
2959 !ice_vc_validate_vlan_tpid(filtering_support->inner,
2968 * ice_vc_to_vlan - transform from struct virtchnl_vlan to struct ice_vlan
2969 * @vc_vlan: struct virtchnl_vlan to transform
2971 static struct ice_vlan ice_vc_to_vlan(struct virtchnl_vlan *vc_vlan)
2973 struct ice_vlan vlan = { 0 };
2975 vlan.prio = (vc_vlan->tci & VLAN_PRIO_MASK) >> VLAN_PRIO_SHIFT;
2976 vlan.vid = vc_vlan->tci & VLAN_VID_MASK;
2977 vlan.tpid = vc_vlan->tpid;
2983 * ice_vc_vlan_action - action to perform on the virthcnl_vlan
2984 * @vsi: VF's VSI used to perform the action
2985 * @vlan_action: function to perform the action with (i.e. add/del)
2986 * @vlan: VLAN filter to perform the action with
2989 ice_vc_vlan_action(struct ice_vsi *vsi,
2990 int (*vlan_action)(struct ice_vsi *, struct ice_vlan *),
2991 struct ice_vlan *vlan)
2995 err = vlan_action(vsi, vlan);
3003 * ice_vc_del_vlans - delete VLAN(s) from the virtchnl filter list
3004 * @vf: VF used to delete the VLAN(s)
3005 * @vsi: VF's VSI used to delete the VLAN(s)
3006 * @vfl: virthchnl filter list used to delete the filters
3009 ice_vc_del_vlans(struct ice_vf *vf, struct ice_vsi *vsi,
3010 struct virtchnl_vlan_filter_list_v2 *vfl)
3012 bool vlan_promisc = ice_is_vlan_promisc_allowed(vf);
3016 for (i = 0; i < vfl->num_elements; i++) {
3017 struct virtchnl_vlan_filter *vlan_fltr = &vfl->filters[i];
3018 struct virtchnl_vlan *vc_vlan;
3020 vc_vlan = &vlan_fltr->outer;
3021 if (ice_vc_is_valid_vlan(vc_vlan)) {
3022 struct ice_vlan vlan = ice_vc_to_vlan(vc_vlan);
3024 err = ice_vc_vlan_action(vsi,
3025 vsi->outer_vlan_ops.del_vlan,
3031 ice_vf_dis_vlan_promisc(vsi, &vlan);
3033 /* Disable VLAN filtering when only VLAN 0 is left */
3034 if (!ice_vsi_has_non_zero_vlans(vsi) && ice_is_dvm_ena(&vsi->back->hw)) {
3035 err = vsi->outer_vlan_ops.dis_tx_filtering(vsi);
3041 vc_vlan = &vlan_fltr->inner;
3042 if (ice_vc_is_valid_vlan(vc_vlan)) {
3043 struct ice_vlan vlan = ice_vc_to_vlan(vc_vlan);
3045 err = ice_vc_vlan_action(vsi,
3046 vsi->inner_vlan_ops.del_vlan,
3051 /* no support for VLAN promiscuous on inner VLAN unless
3052 * we are in Single VLAN Mode (SVM)
3054 if (!ice_is_dvm_ena(&vsi->back->hw)) {
3056 ice_vf_dis_vlan_promisc(vsi, &vlan);
3058 /* Disable VLAN filtering when only VLAN 0 is left */
3059 if (!ice_vsi_has_non_zero_vlans(vsi)) {
3060 err = vsi->inner_vlan_ops.dis_tx_filtering(vsi);
3072 * ice_vc_remove_vlan_v2_msg - virtchnl handler for VIRTCHNL_OP_DEL_VLAN_V2
3073 * @vf: VF the message was received from
3074 * @msg: message received from the VF
3076 static int ice_vc_remove_vlan_v2_msg(struct ice_vf *vf, u8 *msg)
3078 struct virtchnl_vlan_filter_list_v2 *vfl =
3079 (struct virtchnl_vlan_filter_list_v2 *)msg;
3080 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
3081 struct ice_vsi *vsi;
3083 if (!ice_vc_validate_vlan_filter_list(&vf->vlan_v2_caps.filtering,
3085 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3089 if (!ice_vc_isvalid_vsi_id(vf, vfl->vport_id)) {
3090 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3094 vsi = ice_get_vf_vsi(vf);
3096 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3100 if (ice_vc_del_vlans(vf, vsi, vfl))
3101 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3104 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_DEL_VLAN_V2, v_ret, NULL,
3109 * ice_vc_add_vlans - add VLAN(s) from the virtchnl filter list
3110 * @vf: VF used to add the VLAN(s)
3111 * @vsi: VF's VSI used to add the VLAN(s)
3112 * @vfl: virthchnl filter list used to add the filters
3115 ice_vc_add_vlans(struct ice_vf *vf, struct ice_vsi *vsi,
3116 struct virtchnl_vlan_filter_list_v2 *vfl)
3118 bool vlan_promisc = ice_is_vlan_promisc_allowed(vf);
3122 for (i = 0; i < vfl->num_elements; i++) {
3123 struct virtchnl_vlan_filter *vlan_fltr = &vfl->filters[i];
3124 struct virtchnl_vlan *vc_vlan;
3126 vc_vlan = &vlan_fltr->outer;
3127 if (ice_vc_is_valid_vlan(vc_vlan)) {
3128 struct ice_vlan vlan = ice_vc_to_vlan(vc_vlan);
3130 err = ice_vc_vlan_action(vsi,
3131 vsi->outer_vlan_ops.add_vlan,
3137 err = ice_vf_ena_vlan_promisc(vsi, &vlan);
3142 /* Enable VLAN filtering on first non-zero VLAN */
3143 if (vf->spoofchk && vlan.vid && ice_is_dvm_ena(&vsi->back->hw)) {
3144 err = vsi->outer_vlan_ops.ena_tx_filtering(vsi);
3150 vc_vlan = &vlan_fltr->inner;
3151 if (ice_vc_is_valid_vlan(vc_vlan)) {
3152 struct ice_vlan vlan = ice_vc_to_vlan(vc_vlan);
3154 err = ice_vc_vlan_action(vsi,
3155 vsi->inner_vlan_ops.add_vlan,
3160 /* no support for VLAN promiscuous on inner VLAN unless
3161 * we are in Single VLAN Mode (SVM)
3163 if (!ice_is_dvm_ena(&vsi->back->hw)) {
3165 err = ice_vf_ena_vlan_promisc(vsi, &vlan);
3170 /* Enable VLAN filtering on first non-zero VLAN */
3171 if (vf->spoofchk && vlan.vid) {
3172 err = vsi->inner_vlan_ops.ena_tx_filtering(vsi);
3184 * ice_vc_validate_add_vlan_filter_list - validate add filter list from the VF
3185 * @vsi: VF VSI used to get number of existing VLAN filters
3186 * @vfc: negotiated/supported VLAN filtering capabilities
3187 * @vfl: VLAN filter list from VF to validate
3189 * Validate all of the filters in the VLAN filter list from the VF during the
3190 * VIRTCHNL_OP_ADD_VLAN_V2 opcode. If any of the checks fail then return false.
3191 * Otherwise return true.
3194 ice_vc_validate_add_vlan_filter_list(struct ice_vsi *vsi,
3195 struct virtchnl_vlan_filtering_caps *vfc,
3196 struct virtchnl_vlan_filter_list_v2 *vfl)
3198 u16 num_requested_filters = ice_vsi_num_non_zero_vlans(vsi) +
3201 if (num_requested_filters > vfc->max_filters)
3204 return ice_vc_validate_vlan_filter_list(vfc, vfl);
3208 * ice_vc_add_vlan_v2_msg - virtchnl handler for VIRTCHNL_OP_ADD_VLAN_V2
3209 * @vf: VF the message was received from
3210 * @msg: message received from the VF
3212 static int ice_vc_add_vlan_v2_msg(struct ice_vf *vf, u8 *msg)
3214 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
3215 struct virtchnl_vlan_filter_list_v2 *vfl =
3216 (struct virtchnl_vlan_filter_list_v2 *)msg;
3217 struct ice_vsi *vsi;
3219 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
3220 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3224 if (!ice_vc_isvalid_vsi_id(vf, vfl->vport_id)) {
3225 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3229 vsi = ice_get_vf_vsi(vf);
3231 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3235 if (!ice_vc_validate_add_vlan_filter_list(vsi,
3236 &vf->vlan_v2_caps.filtering,
3238 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3242 if (ice_vc_add_vlans(vf, vsi, vfl))
3243 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3246 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_ADD_VLAN_V2, v_ret, NULL,
3251 * ice_vc_valid_vlan_setting - validate VLAN setting
3252 * @negotiated_settings: negotiated VLAN settings during VF init
3253 * @ethertype_setting: ethertype(s) requested for the VLAN setting
3256 ice_vc_valid_vlan_setting(u32 negotiated_settings, u32 ethertype_setting)
3258 if (ethertype_setting && !(negotiated_settings & ethertype_setting))
3261 /* only allow a single VIRTCHNL_VLAN_ETHERTYPE if
3262 * VIRTHCNL_VLAN_ETHERTYPE_AND is not negotiated/supported
3264 if (!(negotiated_settings & VIRTCHNL_VLAN_ETHERTYPE_AND) &&
3265 hweight32(ethertype_setting) > 1)
3268 /* ability to modify the VLAN setting was not negotiated */
3269 if (!(negotiated_settings & VIRTCHNL_VLAN_TOGGLE))
3276 * ice_vc_valid_vlan_setting_msg - validate the VLAN setting message
3277 * @caps: negotiated VLAN settings during VF init
3278 * @msg: message to validate
3280 * Used to validate any VLAN virtchnl message sent as a
3281 * virtchnl_vlan_setting structure. Validates the message against the
3282 * negotiated/supported caps during VF driver init.
3285 ice_vc_valid_vlan_setting_msg(struct virtchnl_vlan_supported_caps *caps,
3286 struct virtchnl_vlan_setting *msg)
3288 if ((!msg->outer_ethertype_setting &&
3289 !msg->inner_ethertype_setting) ||
3290 (!caps->outer && !caps->inner))
3293 if (msg->outer_ethertype_setting &&
3294 !ice_vc_valid_vlan_setting(caps->outer,
3295 msg->outer_ethertype_setting))
3298 if (msg->inner_ethertype_setting &&
3299 !ice_vc_valid_vlan_setting(caps->inner,
3300 msg->inner_ethertype_setting))
3307 * ice_vc_get_tpid - transform from VIRTCHNL_VLAN_ETHERTYPE_* to VLAN TPID
3308 * @ethertype_setting: VIRTCHNL_VLAN_ETHERTYPE_* used to get VLAN TPID
3309 * @tpid: VLAN TPID to populate
3311 static int ice_vc_get_tpid(u32 ethertype_setting, u16 *tpid)
3313 switch (ethertype_setting) {
3314 case VIRTCHNL_VLAN_ETHERTYPE_8100:
3315 *tpid = ETH_P_8021Q;
3317 case VIRTCHNL_VLAN_ETHERTYPE_88A8:
3318 *tpid = ETH_P_8021AD;
3320 case VIRTCHNL_VLAN_ETHERTYPE_9100:
3321 *tpid = ETH_P_QINQ1;
3332 * ice_vc_ena_vlan_offload - enable VLAN offload based on the ethertype_setting
3333 * @vsi: VF's VSI used to enable the VLAN offload
3334 * @ena_offload: function used to enable the VLAN offload
3335 * @ethertype_setting: VIRTCHNL_VLAN_ETHERTYPE_* to enable offloads for
3338 ice_vc_ena_vlan_offload(struct ice_vsi *vsi,
3339 int (*ena_offload)(struct ice_vsi *vsi, u16 tpid),
3340 u32 ethertype_setting)
3345 err = ice_vc_get_tpid(ethertype_setting, &tpid);
3349 err = ena_offload(vsi, tpid);
3356 #define ICE_L2TSEL_QRX_CONTEXT_REG_IDX 3
3357 #define ICE_L2TSEL_BIT_OFFSET 23
3359 ICE_L2TSEL_EXTRACT_FIRST_TAG_L2TAG2_2ND,
3360 ICE_L2TSEL_EXTRACT_FIRST_TAG_L2TAG1,
3364 * ice_vsi_update_l2tsel - update l2tsel field for all Rx rings on this VSI
3365 * @vsi: VSI used to update l2tsel on
3366 * @l2tsel: l2tsel setting requested
3368 * Use the l2tsel setting to update all of the Rx queue context bits for l2tsel.
3369 * This will modify which descriptor field the first offloaded VLAN will be
3372 static void ice_vsi_update_l2tsel(struct ice_vsi *vsi, enum ice_l2tsel l2tsel)
3374 struct ice_hw *hw = &vsi->back->hw;
3378 if (l2tsel == ICE_L2TSEL_EXTRACT_FIRST_TAG_L2TAG2_2ND)
3381 l2tsel_bit = BIT(ICE_L2TSEL_BIT_OFFSET);
3383 for (i = 0; i < vsi->alloc_rxq; i++) {
3384 u16 pfq = vsi->rxq_map[i];
3385 u32 qrx_context_offset;
3388 qrx_context_offset =
3389 QRX_CONTEXT(ICE_L2TSEL_QRX_CONTEXT_REG_IDX, pfq);
3391 regval = rd32(hw, qrx_context_offset);
3392 regval &= ~BIT(ICE_L2TSEL_BIT_OFFSET);
3393 regval |= l2tsel_bit;
3394 wr32(hw, qrx_context_offset, regval);
3399 * ice_vc_ena_vlan_stripping_v2_msg
3400 * @vf: VF the message was received from
3401 * @msg: message received from the VF
3403 * virthcnl handler for VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2
3405 static int ice_vc_ena_vlan_stripping_v2_msg(struct ice_vf *vf, u8 *msg)
3407 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
3408 struct virtchnl_vlan_supported_caps *stripping_support;
3409 struct virtchnl_vlan_setting *strip_msg =
3410 (struct virtchnl_vlan_setting *)msg;
3411 u32 ethertype_setting;
3412 struct ice_vsi *vsi;
3414 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
3415 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3419 if (!ice_vc_isvalid_vsi_id(vf, strip_msg->vport_id)) {
3420 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3424 vsi = ice_get_vf_vsi(vf);
3426 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3430 stripping_support = &vf->vlan_v2_caps.offloads.stripping_support;
3431 if (!ice_vc_valid_vlan_setting_msg(stripping_support, strip_msg)) {
3432 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3436 ethertype_setting = strip_msg->outer_ethertype_setting;
3437 if (ethertype_setting) {
3438 if (ice_vc_ena_vlan_offload(vsi,
3439 vsi->outer_vlan_ops.ena_stripping,
3440 ethertype_setting)) {
3441 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3444 enum ice_l2tsel l2tsel =
3445 ICE_L2TSEL_EXTRACT_FIRST_TAG_L2TAG2_2ND;
3447 /* PF tells the VF that the outer VLAN tag is always
3448 * extracted to VIRTCHNL_VLAN_TAG_LOCATION_L2TAG2_2 and
3449 * inner is always extracted to
3450 * VIRTCHNL_VLAN_TAG_LOCATION_L2TAG1. This is needed to
3451 * support outer stripping so the first tag always ends
3452 * up in L2TAG2_2ND and the second/inner tag, if
3453 * enabled, is extracted in L2TAG1.
3455 ice_vsi_update_l2tsel(vsi, l2tsel);
3459 ethertype_setting = strip_msg->inner_ethertype_setting;
3460 if (ethertype_setting &&
3461 ice_vc_ena_vlan_offload(vsi, vsi->inner_vlan_ops.ena_stripping,
3462 ethertype_setting)) {
3463 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3468 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2,
3473 * ice_vc_dis_vlan_stripping_v2_msg
3474 * @vf: VF the message was received from
3475 * @msg: message received from the VF
3477 * virthcnl handler for VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2
3479 static int ice_vc_dis_vlan_stripping_v2_msg(struct ice_vf *vf, u8 *msg)
3481 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
3482 struct virtchnl_vlan_supported_caps *stripping_support;
3483 struct virtchnl_vlan_setting *strip_msg =
3484 (struct virtchnl_vlan_setting *)msg;
3485 u32 ethertype_setting;
3486 struct ice_vsi *vsi;
3488 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
3489 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3493 if (!ice_vc_isvalid_vsi_id(vf, strip_msg->vport_id)) {
3494 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3498 vsi = ice_get_vf_vsi(vf);
3500 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3504 stripping_support = &vf->vlan_v2_caps.offloads.stripping_support;
3505 if (!ice_vc_valid_vlan_setting_msg(stripping_support, strip_msg)) {
3506 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3510 ethertype_setting = strip_msg->outer_ethertype_setting;
3511 if (ethertype_setting) {
3512 if (vsi->outer_vlan_ops.dis_stripping(vsi)) {
3513 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3516 enum ice_l2tsel l2tsel =
3517 ICE_L2TSEL_EXTRACT_FIRST_TAG_L2TAG1;
3519 /* PF tells the VF that the outer VLAN tag is always
3520 * extracted to VIRTCHNL_VLAN_TAG_LOCATION_L2TAG2_2 and
3521 * inner is always extracted to
3522 * VIRTCHNL_VLAN_TAG_LOCATION_L2TAG1. This is needed to
3523 * support inner stripping while outer stripping is
3524 * disabled so that the first and only tag is extracted
3527 ice_vsi_update_l2tsel(vsi, l2tsel);
3531 ethertype_setting = strip_msg->inner_ethertype_setting;
3532 if (ethertype_setting && vsi->inner_vlan_ops.dis_stripping(vsi)) {
3533 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3538 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2,
3543 * ice_vc_ena_vlan_insertion_v2_msg
3544 * @vf: VF the message was received from
3545 * @msg: message received from the VF
3547 * virthcnl handler for VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2
3549 static int ice_vc_ena_vlan_insertion_v2_msg(struct ice_vf *vf, u8 *msg)
3551 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
3552 struct virtchnl_vlan_supported_caps *insertion_support;
3553 struct virtchnl_vlan_setting *insertion_msg =
3554 (struct virtchnl_vlan_setting *)msg;
3555 u32 ethertype_setting;
3556 struct ice_vsi *vsi;
3558 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
3559 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3563 if (!ice_vc_isvalid_vsi_id(vf, insertion_msg->vport_id)) {
3564 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3568 vsi = ice_get_vf_vsi(vf);
3570 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3574 insertion_support = &vf->vlan_v2_caps.offloads.insertion_support;
3575 if (!ice_vc_valid_vlan_setting_msg(insertion_support, insertion_msg)) {
3576 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3580 ethertype_setting = insertion_msg->outer_ethertype_setting;
3581 if (ethertype_setting &&
3582 ice_vc_ena_vlan_offload(vsi, vsi->outer_vlan_ops.ena_insertion,
3583 ethertype_setting)) {
3584 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3588 ethertype_setting = insertion_msg->inner_ethertype_setting;
3589 if (ethertype_setting &&
3590 ice_vc_ena_vlan_offload(vsi, vsi->inner_vlan_ops.ena_insertion,
3591 ethertype_setting)) {
3592 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3597 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2,
3602 * ice_vc_dis_vlan_insertion_v2_msg
3603 * @vf: VF the message was received from
3604 * @msg: message received from the VF
3606 * virthcnl handler for VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2
3608 static int ice_vc_dis_vlan_insertion_v2_msg(struct ice_vf *vf, u8 *msg)
3610 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
3611 struct virtchnl_vlan_supported_caps *insertion_support;
3612 struct virtchnl_vlan_setting *insertion_msg =
3613 (struct virtchnl_vlan_setting *)msg;
3614 u32 ethertype_setting;
3615 struct ice_vsi *vsi;
3617 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
3618 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3622 if (!ice_vc_isvalid_vsi_id(vf, insertion_msg->vport_id)) {
3623 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3627 vsi = ice_get_vf_vsi(vf);
3629 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3633 insertion_support = &vf->vlan_v2_caps.offloads.insertion_support;
3634 if (!ice_vc_valid_vlan_setting_msg(insertion_support, insertion_msg)) {
3635 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3639 ethertype_setting = insertion_msg->outer_ethertype_setting;
3640 if (ethertype_setting && vsi->outer_vlan_ops.dis_insertion(vsi)) {
3641 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3645 ethertype_setting = insertion_msg->inner_ethertype_setting;
3646 if (ethertype_setting && vsi->inner_vlan_ops.dis_insertion(vsi)) {
3647 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3652 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2,
3656 static const struct ice_virtchnl_ops ice_virtchnl_dflt_ops = {
3657 .get_ver_msg = ice_vc_get_ver_msg,
3658 .get_vf_res_msg = ice_vc_get_vf_res_msg,
3659 .reset_vf = ice_vc_reset_vf_msg,
3660 .add_mac_addr_msg = ice_vc_add_mac_addr_msg,
3661 .del_mac_addr_msg = ice_vc_del_mac_addr_msg,
3662 .cfg_qs_msg = ice_vc_cfg_qs_msg,
3663 .ena_qs_msg = ice_vc_ena_qs_msg,
3664 .dis_qs_msg = ice_vc_dis_qs_msg,
3665 .request_qs_msg = ice_vc_request_qs_msg,
3666 .cfg_irq_map_msg = ice_vc_cfg_irq_map_msg,
3667 .config_rss_key = ice_vc_config_rss_key,
3668 .config_rss_lut = ice_vc_config_rss_lut,
3669 .get_stats_msg = ice_vc_get_stats_msg,
3670 .cfg_promiscuous_mode_msg = ice_vc_cfg_promiscuous_mode_msg,
3671 .add_vlan_msg = ice_vc_add_vlan_msg,
3672 .remove_vlan_msg = ice_vc_remove_vlan_msg,
3673 .query_rxdid = ice_vc_query_rxdid,
3674 .get_rss_hena = ice_vc_get_rss_hena,
3675 .set_rss_hena_msg = ice_vc_set_rss_hena,
3676 .ena_vlan_stripping = ice_vc_ena_vlan_stripping,
3677 .dis_vlan_stripping = ice_vc_dis_vlan_stripping,
3678 .handle_rss_cfg_msg = ice_vc_handle_rss_cfg,
3679 .add_fdir_fltr_msg = ice_vc_add_fdir_fltr,
3680 .del_fdir_fltr_msg = ice_vc_del_fdir_fltr,
3681 .get_offload_vlan_v2_caps = ice_vc_get_offload_vlan_v2_caps,
3682 .add_vlan_v2_msg = ice_vc_add_vlan_v2_msg,
3683 .remove_vlan_v2_msg = ice_vc_remove_vlan_v2_msg,
3684 .ena_vlan_stripping_v2_msg = ice_vc_ena_vlan_stripping_v2_msg,
3685 .dis_vlan_stripping_v2_msg = ice_vc_dis_vlan_stripping_v2_msg,
3686 .ena_vlan_insertion_v2_msg = ice_vc_ena_vlan_insertion_v2_msg,
3687 .dis_vlan_insertion_v2_msg = ice_vc_dis_vlan_insertion_v2_msg,
3691 * ice_virtchnl_set_dflt_ops - Switch to default virtchnl ops
3692 * @vf: the VF to switch ops
3694 void ice_virtchnl_set_dflt_ops(struct ice_vf *vf)
3696 vf->virtchnl_ops = &ice_virtchnl_dflt_ops;
3700 * ice_vc_repr_add_mac
3701 * @vf: pointer to VF
3702 * @msg: virtchannel message
3704 * When port representors are created, we do not add MAC rule
3705 * to firmware, we store it so that PF could report same
3708 static int ice_vc_repr_add_mac(struct ice_vf *vf, u8 *msg)
3710 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
3711 struct virtchnl_ether_addr_list *al =
3712 (struct virtchnl_ether_addr_list *)msg;
3713 struct ice_vsi *vsi;
3717 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states) ||
3718 !ice_vc_isvalid_vsi_id(vf, al->vsi_id)) {
3719 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3720 goto handle_mac_exit;
3725 vsi = ice_get_vf_vsi(vf);
3727 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3728 goto handle_mac_exit;
3731 for (i = 0; i < al->num_elements; i++) {
3732 u8 *mac_addr = al->list[i].addr;
3734 if (!is_unicast_ether_addr(mac_addr) ||
3735 ether_addr_equal(mac_addr, vf->hw_lan_addr))
3738 if (vf->pf_set_mac) {
3739 dev_err(ice_pf_to_dev(pf), "VF attempting to override administratively set MAC address\n");
3740 v_ret = VIRTCHNL_STATUS_ERR_NOT_SUPPORTED;
3741 goto handle_mac_exit;
3744 ice_vfhw_mac_add(vf, &al->list[i]);
3750 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_ADD_ETH_ADDR,
3755 * ice_vc_repr_del_mac - response with success for deleting MAC
3756 * @vf: pointer to VF
3757 * @msg: virtchannel message
3759 * Respond with success to not break normal VF flow.
3760 * For legacy VF driver try to update cached MAC address.
3763 ice_vc_repr_del_mac(struct ice_vf __always_unused *vf, u8 __always_unused *msg)
3765 struct virtchnl_ether_addr_list *al =
3766 (struct virtchnl_ether_addr_list *)msg;
3768 ice_update_legacy_cached_mac(vf, &al->list[0]);
3770 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_DEL_ETH_ADDR,
3771 VIRTCHNL_STATUS_SUCCESS, NULL, 0);
3775 ice_vc_repr_cfg_promiscuous_mode(struct ice_vf *vf, u8 __always_unused *msg)
3777 dev_dbg(ice_pf_to_dev(vf->pf),
3778 "Can't config promiscuous mode in switchdev mode for VF %d\n",
3780 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE,
3781 VIRTCHNL_STATUS_ERR_NOT_SUPPORTED,
3785 static const struct ice_virtchnl_ops ice_virtchnl_repr_ops = {
3786 .get_ver_msg = ice_vc_get_ver_msg,
3787 .get_vf_res_msg = ice_vc_get_vf_res_msg,
3788 .reset_vf = ice_vc_reset_vf_msg,
3789 .add_mac_addr_msg = ice_vc_repr_add_mac,
3790 .del_mac_addr_msg = ice_vc_repr_del_mac,
3791 .cfg_qs_msg = ice_vc_cfg_qs_msg,
3792 .ena_qs_msg = ice_vc_ena_qs_msg,
3793 .dis_qs_msg = ice_vc_dis_qs_msg,
3794 .request_qs_msg = ice_vc_request_qs_msg,
3795 .cfg_irq_map_msg = ice_vc_cfg_irq_map_msg,
3796 .config_rss_key = ice_vc_config_rss_key,
3797 .config_rss_lut = ice_vc_config_rss_lut,
3798 .get_stats_msg = ice_vc_get_stats_msg,
3799 .cfg_promiscuous_mode_msg = ice_vc_repr_cfg_promiscuous_mode,
3800 .add_vlan_msg = ice_vc_add_vlan_msg,
3801 .remove_vlan_msg = ice_vc_remove_vlan_msg,
3802 .query_rxdid = ice_vc_query_rxdid,
3803 .get_rss_hena = ice_vc_get_rss_hena,
3804 .set_rss_hena_msg = ice_vc_set_rss_hena,
3805 .ena_vlan_stripping = ice_vc_ena_vlan_stripping,
3806 .dis_vlan_stripping = ice_vc_dis_vlan_stripping,
3807 .handle_rss_cfg_msg = ice_vc_handle_rss_cfg,
3808 .add_fdir_fltr_msg = ice_vc_add_fdir_fltr,
3809 .del_fdir_fltr_msg = ice_vc_del_fdir_fltr,
3810 .get_offload_vlan_v2_caps = ice_vc_get_offload_vlan_v2_caps,
3811 .add_vlan_v2_msg = ice_vc_add_vlan_v2_msg,
3812 .remove_vlan_v2_msg = ice_vc_remove_vlan_v2_msg,
3813 .ena_vlan_stripping_v2_msg = ice_vc_ena_vlan_stripping_v2_msg,
3814 .dis_vlan_stripping_v2_msg = ice_vc_dis_vlan_stripping_v2_msg,
3815 .ena_vlan_insertion_v2_msg = ice_vc_ena_vlan_insertion_v2_msg,
3816 .dis_vlan_insertion_v2_msg = ice_vc_dis_vlan_insertion_v2_msg,
3820 * ice_virtchnl_set_repr_ops - Switch to representor virtchnl ops
3821 * @vf: the VF to switch ops
3823 void ice_virtchnl_set_repr_ops(struct ice_vf *vf)
3825 vf->virtchnl_ops = &ice_virtchnl_repr_ops;
3829 * ice_is_malicious_vf - check if this vf might be overflowing mailbox
3830 * @vf: the VF to check
3831 * @mbxdata: data about the state of the mailbox
3833 * Detect if a given VF might be malicious and attempting to overflow the PF
3834 * mailbox. If so, log a warning message and ignore this event.
3837 ice_is_malicious_vf(struct ice_vf *vf, struct ice_mbx_data *mbxdata)
3839 bool report_malvf = false;
3845 dev = ice_pf_to_dev(pf);
3847 if (test_bit(ICE_VF_STATE_DIS, vf->vf_states))
3848 return vf->mbx_info.malicious;
3850 /* check to see if we have a newly malicious VF */
3851 status = ice_mbx_vf_state_handler(&pf->hw, mbxdata, &vf->mbx_info,
3854 dev_warn_ratelimited(dev, "Unable to check status of mailbox overflow for VF %u MAC %pM, status %d\n",
3855 vf->vf_id, vf->dev_lan_addr, status);
3858 struct ice_vsi *pf_vsi = ice_get_main_vsi(pf);
3859 u8 zero_addr[ETH_ALEN] = {};
3861 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",
3863 pf_vsi ? pf_vsi->netdev->dev_addr : zero_addr);
3866 return vf->mbx_info.malicious;
3870 * ice_vc_process_vf_msg - Process request from VF
3871 * @pf: pointer to the PF structure
3872 * @event: pointer to the AQ event
3873 * @mbxdata: information used to detect VF attempting mailbox overflow
3875 * called from the common asq/arq handler to
3876 * process request from VF
3878 void ice_vc_process_vf_msg(struct ice_pf *pf, struct ice_rq_event_info *event,
3879 struct ice_mbx_data *mbxdata)
3881 u32 v_opcode = le32_to_cpu(event->desc.cookie_high);
3882 s16 vf_id = le16_to_cpu(event->desc.retval);
3883 const struct ice_virtchnl_ops *ops;
3884 u16 msglen = event->msg_len;
3885 u8 *msg = event->msg_buf;
3886 struct ice_vf *vf = NULL;
3890 dev = ice_pf_to_dev(pf);
3892 vf = ice_get_vf_by_id(pf, vf_id);
3894 dev_err(dev, "Unable to locate VF for message from VF ID %d, opcode %d, len %d\n",
3895 vf_id, v_opcode, msglen);
3899 mutex_lock(&vf->cfg_lock);
3901 /* Check if the VF is trying to overflow the mailbox */
3902 if (ice_is_malicious_vf(vf, mbxdata))
3905 /* Check if VF is disabled. */
3906 if (test_bit(ICE_VF_STATE_DIS, vf->vf_states)) {
3911 ops = vf->virtchnl_ops;
3913 /* Perform basic checks on the msg */
3914 err = virtchnl_vc_validate_vf_msg(&vf->vf_ver, v_opcode, msg, msglen);
3916 if (err == VIRTCHNL_STATUS_ERR_PARAM)
3924 ice_vc_send_msg_to_vf(vf, v_opcode, VIRTCHNL_STATUS_ERR_PARAM,
3926 dev_err(dev, "Invalid message from VF %d, opcode %d, len %d, error %d\n",
3927 vf_id, v_opcode, msglen, err);
3931 if (!ice_vc_is_opcode_allowed(vf, v_opcode)) {
3932 ice_vc_send_msg_to_vf(vf, v_opcode,
3933 VIRTCHNL_STATUS_ERR_NOT_SUPPORTED, NULL,
3939 case VIRTCHNL_OP_VERSION:
3940 err = ops->get_ver_msg(vf, msg);
3942 case VIRTCHNL_OP_GET_VF_RESOURCES:
3943 err = ops->get_vf_res_msg(vf, msg);
3944 if (ice_vf_init_vlan_stripping(vf))
3945 dev_dbg(dev, "Failed to initialize VLAN stripping for VF %d\n",
3947 ice_vc_notify_vf_link_state(vf);
3949 case VIRTCHNL_OP_RESET_VF:
3950 clear_bit(ICE_VF_STATE_ACTIVE, vf->vf_states);
3953 case VIRTCHNL_OP_ADD_ETH_ADDR:
3954 err = ops->add_mac_addr_msg(vf, msg);
3956 case VIRTCHNL_OP_DEL_ETH_ADDR:
3957 err = ops->del_mac_addr_msg(vf, msg);
3959 case VIRTCHNL_OP_CONFIG_VSI_QUEUES:
3960 err = ops->cfg_qs_msg(vf, msg);
3962 case VIRTCHNL_OP_ENABLE_QUEUES:
3963 err = ops->ena_qs_msg(vf, msg);
3964 ice_vc_notify_vf_link_state(vf);
3966 case VIRTCHNL_OP_DISABLE_QUEUES:
3967 err = ops->dis_qs_msg(vf, msg);
3969 case VIRTCHNL_OP_REQUEST_QUEUES:
3970 err = ops->request_qs_msg(vf, msg);
3972 case VIRTCHNL_OP_CONFIG_IRQ_MAP:
3973 err = ops->cfg_irq_map_msg(vf, msg);
3975 case VIRTCHNL_OP_CONFIG_RSS_KEY:
3976 err = ops->config_rss_key(vf, msg);
3978 case VIRTCHNL_OP_CONFIG_RSS_LUT:
3979 err = ops->config_rss_lut(vf, msg);
3981 case VIRTCHNL_OP_GET_STATS:
3982 err = ops->get_stats_msg(vf, msg);
3984 case VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE:
3985 err = ops->cfg_promiscuous_mode_msg(vf, msg);
3987 case VIRTCHNL_OP_ADD_VLAN:
3988 err = ops->add_vlan_msg(vf, msg);
3990 case VIRTCHNL_OP_DEL_VLAN:
3991 err = ops->remove_vlan_msg(vf, msg);
3993 case VIRTCHNL_OP_GET_SUPPORTED_RXDIDS:
3994 err = ops->query_rxdid(vf);
3996 case VIRTCHNL_OP_GET_RSS_HENA_CAPS:
3997 err = ops->get_rss_hena(vf);
3999 case VIRTCHNL_OP_SET_RSS_HENA:
4000 err = ops->set_rss_hena_msg(vf, msg);
4002 case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING:
4003 err = ops->ena_vlan_stripping(vf);
4005 case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING:
4006 err = ops->dis_vlan_stripping(vf);
4008 case VIRTCHNL_OP_ADD_FDIR_FILTER:
4009 err = ops->add_fdir_fltr_msg(vf, msg);
4011 case VIRTCHNL_OP_DEL_FDIR_FILTER:
4012 err = ops->del_fdir_fltr_msg(vf, msg);
4014 case VIRTCHNL_OP_ADD_RSS_CFG:
4015 err = ops->handle_rss_cfg_msg(vf, msg, true);
4017 case VIRTCHNL_OP_DEL_RSS_CFG:
4018 err = ops->handle_rss_cfg_msg(vf, msg, false);
4020 case VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS:
4021 err = ops->get_offload_vlan_v2_caps(vf);
4023 case VIRTCHNL_OP_ADD_VLAN_V2:
4024 err = ops->add_vlan_v2_msg(vf, msg);
4026 case VIRTCHNL_OP_DEL_VLAN_V2:
4027 err = ops->remove_vlan_v2_msg(vf, msg);
4029 case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2:
4030 err = ops->ena_vlan_stripping_v2_msg(vf, msg);
4032 case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2:
4033 err = ops->dis_vlan_stripping_v2_msg(vf, msg);
4035 case VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2:
4036 err = ops->ena_vlan_insertion_v2_msg(vf, msg);
4038 case VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2:
4039 err = ops->dis_vlan_insertion_v2_msg(vf, msg);
4041 case VIRTCHNL_OP_UNKNOWN:
4043 dev_err(dev, "Unsupported opcode %d from VF %d\n", v_opcode,
4045 err = ice_vc_send_msg_to_vf(vf, v_opcode,
4046 VIRTCHNL_STATUS_ERR_NOT_SUPPORTED,
4051 /* Helper function cares less about error return values here
4052 * as it is busy with pending work.
4054 dev_info(dev, "PF failed to honor VF %d, opcode %d, error %d\n",
4055 vf_id, v_opcode, err);
4059 mutex_unlock(&vf->cfg_lock);