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_vf_res_msg
364 * @vf: pointer to the VF info
365 * @msg: pointer to the msg buffer
367 * called from the VF to request its resources
369 static int ice_vc_get_vf_res_msg(struct ice_vf *vf, u8 *msg)
371 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
372 struct virtchnl_vf_resource *vfres = NULL;
373 struct ice_hw *hw = &vf->pf->hw;
378 if (ice_check_vf_init(vf)) {
379 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
383 len = sizeof(struct virtchnl_vf_resource);
385 vfres = kzalloc(len, GFP_KERNEL);
387 v_ret = VIRTCHNL_STATUS_ERR_NO_MEMORY;
391 if (VF_IS_V11(&vf->vf_ver))
392 vf->driver_caps = *(u32 *)msg;
394 vf->driver_caps = VIRTCHNL_VF_OFFLOAD_L2 |
395 VIRTCHNL_VF_OFFLOAD_RSS_REG |
396 VIRTCHNL_VF_OFFLOAD_VLAN;
398 vfres->vf_cap_flags = VIRTCHNL_VF_OFFLOAD_L2;
399 vsi = ice_get_vf_vsi(vf);
401 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
405 if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_VLAN_V2) {
406 /* VLAN offloads based on current device configuration */
407 vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_VLAN_V2;
408 } else if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_VLAN) {
409 /* allow VF to negotiate VIRTCHNL_VF_OFFLOAD explicitly for
410 * these two conditions, which amounts to guest VLAN filtering
411 * and offloads being based on the inner VLAN or the
412 * inner/single VLAN respectively and don't allow VF to
413 * negotiate VIRTCHNL_VF_OFFLOAD in any other cases
415 if (ice_is_dvm_ena(hw) && ice_vf_is_port_vlan_ena(vf)) {
416 vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_VLAN;
417 } else if (!ice_is_dvm_ena(hw) &&
418 !ice_vf_is_port_vlan_ena(vf)) {
419 vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_VLAN;
420 /* configure backward compatible support for VFs that
421 * only support VIRTCHNL_VF_OFFLOAD_VLAN, the PF is
422 * configured in SVM, and no port VLAN is configured
424 ice_vf_vsi_cfg_svm_legacy_vlan_mode(vsi);
425 } else if (ice_is_dvm_ena(hw)) {
426 /* configure software offloaded VLAN support when DVM
427 * is enabled, but no port VLAN is enabled
429 ice_vf_vsi_cfg_dvm_legacy_vlan_mode(vsi);
433 if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_RSS_PF) {
434 vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_RSS_PF;
436 if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_RSS_AQ)
437 vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_RSS_AQ;
439 vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_RSS_REG;
442 if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_FDIR_PF)
443 vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_FDIR_PF;
445 if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_RSS_PCTYPE_V2)
446 vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_RSS_PCTYPE_V2;
448 if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_ENCAP)
449 vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_ENCAP;
451 if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_ENCAP_CSUM)
452 vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_ENCAP_CSUM;
454 if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_RX_POLLING)
455 vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_RX_POLLING;
457 if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_WB_ON_ITR)
458 vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_WB_ON_ITR;
460 if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_REQ_QUEUES)
461 vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_REQ_QUEUES;
463 if (vf->driver_caps & VIRTCHNL_VF_CAP_ADV_LINK_SPEED)
464 vfres->vf_cap_flags |= VIRTCHNL_VF_CAP_ADV_LINK_SPEED;
466 if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_ADV_RSS_PF)
467 vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_ADV_RSS_PF;
469 if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_USO)
470 vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_USO;
473 /* Tx and Rx queue are equal for VF */
474 vfres->num_queue_pairs = vsi->num_txq;
475 vfres->max_vectors = vf->pf->vfs.num_msix_per;
476 vfres->rss_key_size = ICE_VSIQF_HKEY_ARRAY_SIZE;
477 vfres->rss_lut_size = ICE_VSIQF_HLUT_ARRAY_SIZE;
478 vfres->max_mtu = ice_vc_get_max_frame_size(vf);
480 vfres->vsi_res[0].vsi_id = vf->lan_vsi_num;
481 vfres->vsi_res[0].vsi_type = VIRTCHNL_VSI_SRIOV;
482 vfres->vsi_res[0].num_queue_pairs = vsi->num_txq;
483 ether_addr_copy(vfres->vsi_res[0].default_mac_addr,
484 vf->hw_lan_addr.addr);
486 /* match guest capabilities */
487 vf->driver_caps = vfres->vf_cap_flags;
489 ice_vc_set_caps_allowlist(vf);
490 ice_vc_set_working_allowlist(vf);
492 set_bit(ICE_VF_STATE_ACTIVE, vf->vf_states);
495 /* send the response back to the VF */
496 ret = ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_GET_VF_RESOURCES, v_ret,
504 * ice_vc_reset_vf_msg
505 * @vf: pointer to the VF info
507 * called from the VF to reset itself,
508 * unlike other virtchnl messages, PF driver
509 * doesn't send the response back to the VF
511 static void ice_vc_reset_vf_msg(struct ice_vf *vf)
513 if (test_bit(ICE_VF_STATE_INIT, vf->vf_states))
518 * ice_vc_isvalid_vsi_id
519 * @vf: pointer to the VF info
520 * @vsi_id: VF relative VSI ID
522 * check for the valid VSI ID
524 bool ice_vc_isvalid_vsi_id(struct ice_vf *vf, u16 vsi_id)
526 struct ice_pf *pf = vf->pf;
529 vsi = ice_find_vsi(pf, vsi_id);
531 return (vsi && (vsi->vf == vf));
535 * ice_vc_isvalid_q_id
536 * @vf: pointer to the VF info
538 * @qid: VSI relative queue ID
540 * check for the valid queue ID
542 static bool ice_vc_isvalid_q_id(struct ice_vf *vf, u16 vsi_id, u8 qid)
544 struct ice_vsi *vsi = ice_find_vsi(vf->pf, vsi_id);
545 /* allocated Tx and Rx queues should be always equal for VF VSI */
546 return (vsi && (qid < vsi->alloc_txq));
550 * ice_vc_isvalid_ring_len
551 * @ring_len: length of ring
553 * check for the valid ring count, should be multiple of ICE_REQ_DESC_MULTIPLE
556 static bool ice_vc_isvalid_ring_len(u16 ring_len)
558 return ring_len == 0 ||
559 (ring_len >= ICE_MIN_NUM_DESC &&
560 ring_len <= ICE_MAX_NUM_DESC &&
561 !(ring_len % ICE_REQ_DESC_MULTIPLE));
565 * ice_vc_validate_pattern
566 * @vf: pointer to the VF info
567 * @proto: virtchnl protocol headers
569 * validate the pattern is supported or not.
571 * Return: true on success, false on error.
574 ice_vc_validate_pattern(struct ice_vf *vf, struct virtchnl_proto_hdrs *proto)
576 bool is_ipv4 = false;
577 bool is_ipv6 = false;
582 while (i < proto->count &&
583 proto->proto_hdr[i].type != VIRTCHNL_PROTO_HDR_NONE) {
584 switch (proto->proto_hdr[i].type) {
585 case VIRTCHNL_PROTO_HDR_ETH:
586 ptype = ICE_PTYPE_MAC_PAY;
588 case VIRTCHNL_PROTO_HDR_IPV4:
589 ptype = ICE_PTYPE_IPV4_PAY;
592 case VIRTCHNL_PROTO_HDR_IPV6:
593 ptype = ICE_PTYPE_IPV6_PAY;
596 case VIRTCHNL_PROTO_HDR_UDP:
598 ptype = ICE_PTYPE_IPV4_UDP_PAY;
600 ptype = ICE_PTYPE_IPV6_UDP_PAY;
603 case VIRTCHNL_PROTO_HDR_TCP:
605 ptype = ICE_PTYPE_IPV4_TCP_PAY;
607 ptype = ICE_PTYPE_IPV6_TCP_PAY;
609 case VIRTCHNL_PROTO_HDR_SCTP:
611 ptype = ICE_PTYPE_IPV4_SCTP_PAY;
613 ptype = ICE_PTYPE_IPV6_SCTP_PAY;
615 case VIRTCHNL_PROTO_HDR_GTPU_IP:
616 case VIRTCHNL_PROTO_HDR_GTPU_EH:
618 ptype = ICE_MAC_IPV4_GTPU;
620 ptype = ICE_MAC_IPV6_GTPU;
622 case VIRTCHNL_PROTO_HDR_L2TPV3:
624 ptype = ICE_MAC_IPV4_L2TPV3;
626 ptype = ICE_MAC_IPV6_L2TPV3;
628 case VIRTCHNL_PROTO_HDR_ESP:
630 ptype = is_udp ? ICE_MAC_IPV4_NAT_T_ESP :
633 ptype = is_udp ? ICE_MAC_IPV6_NAT_T_ESP :
636 case VIRTCHNL_PROTO_HDR_AH:
638 ptype = ICE_MAC_IPV4_AH;
640 ptype = ICE_MAC_IPV6_AH;
642 case VIRTCHNL_PROTO_HDR_PFCP:
644 ptype = ICE_MAC_IPV4_PFCP_SESSION;
646 ptype = ICE_MAC_IPV6_PFCP_SESSION;
655 return ice_hw_ptype_ena(&vf->pf->hw, ptype);
659 * ice_vc_parse_rss_cfg - parses hash fields and headers from
660 * a specific virtchnl RSS cfg
661 * @hw: pointer to the hardware
662 * @rss_cfg: pointer to the virtchnl RSS cfg
663 * @addl_hdrs: pointer to the protocol header fields (ICE_FLOW_SEG_HDR_*)
665 * @hash_flds: pointer to the hash bit fields (ICE_FLOW_HASH_*) to configure
667 * Return true if all the protocol header and hash fields in the RSS cfg could
668 * be parsed, else return false
670 * This function parses the virtchnl RSS cfg to be the intended
671 * hash fields and the intended header for RSS configuration
674 ice_vc_parse_rss_cfg(struct ice_hw *hw, struct virtchnl_rss_cfg *rss_cfg,
675 u32 *addl_hdrs, u64 *hash_flds)
677 const struct ice_vc_hash_field_match_type *hf_list;
678 const struct ice_vc_hdr_match_type *hdr_list;
679 int i, hf_list_len, hdr_list_len;
681 hf_list = ice_vc_hash_field_list;
682 hf_list_len = ARRAY_SIZE(ice_vc_hash_field_list);
683 hdr_list = ice_vc_hdr_list;
684 hdr_list_len = ARRAY_SIZE(ice_vc_hdr_list);
686 for (i = 0; i < rss_cfg->proto_hdrs.count; i++) {
687 struct virtchnl_proto_hdr *proto_hdr =
688 &rss_cfg->proto_hdrs.proto_hdr[i];
689 bool hdr_found = false;
692 /* Find matched ice headers according to virtchnl headers. */
693 for (j = 0; j < hdr_list_len; j++) {
694 struct ice_vc_hdr_match_type hdr_map = hdr_list[j];
696 if (proto_hdr->type == hdr_map.vc_hdr) {
697 *addl_hdrs |= hdr_map.ice_hdr;
705 /* Find matched ice hash fields according to
706 * virtchnl hash fields.
708 for (j = 0; j < hf_list_len; j++) {
709 struct ice_vc_hash_field_match_type hf_map = hf_list[j];
711 if (proto_hdr->type == hf_map.vc_hdr &&
712 proto_hdr->field_selector == hf_map.vc_hash_field) {
713 *hash_flds |= hf_map.ice_hash_field;
723 * ice_vf_adv_rss_offload_ena - determine if capabilities support advanced
725 * @caps: VF driver negotiated capabilities
727 * Return true if VIRTCHNL_VF_OFFLOAD_ADV_RSS_PF capability is set,
730 static bool ice_vf_adv_rss_offload_ena(u32 caps)
732 return !!(caps & VIRTCHNL_VF_OFFLOAD_ADV_RSS_PF);
736 * ice_vc_handle_rss_cfg
737 * @vf: pointer to the VF info
738 * @msg: pointer to the message buffer
739 * @add: add a RSS config if true, otherwise delete a RSS config
741 * This function adds/deletes a RSS config
743 static int ice_vc_handle_rss_cfg(struct ice_vf *vf, u8 *msg, bool add)
745 u32 v_opcode = add ? VIRTCHNL_OP_ADD_RSS_CFG : VIRTCHNL_OP_DEL_RSS_CFG;
746 struct virtchnl_rss_cfg *rss_cfg = (struct virtchnl_rss_cfg *)msg;
747 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
748 struct device *dev = ice_pf_to_dev(vf->pf);
749 struct ice_hw *hw = &vf->pf->hw;
752 if (!test_bit(ICE_FLAG_RSS_ENA, vf->pf->flags)) {
753 dev_dbg(dev, "VF %d attempting to configure RSS, but RSS is not supported by the PF\n",
755 v_ret = VIRTCHNL_STATUS_ERR_NOT_SUPPORTED;
759 if (!ice_vf_adv_rss_offload_ena(vf->driver_caps)) {
760 dev_dbg(dev, "VF %d attempting to configure RSS, but Advanced RSS offload is not supported\n",
762 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
766 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
767 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
771 if (rss_cfg->proto_hdrs.count > VIRTCHNL_MAX_NUM_PROTO_HDRS ||
772 rss_cfg->rss_algorithm < VIRTCHNL_RSS_ALG_TOEPLITZ_ASYMMETRIC ||
773 rss_cfg->rss_algorithm > VIRTCHNL_RSS_ALG_XOR_SYMMETRIC) {
774 dev_dbg(dev, "VF %d attempting to configure RSS, but RSS configuration is not valid\n",
776 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
780 vsi = ice_get_vf_vsi(vf);
782 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
786 if (!ice_vc_validate_pattern(vf, &rss_cfg->proto_hdrs)) {
787 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
791 if (rss_cfg->rss_algorithm == VIRTCHNL_RSS_ALG_R_ASYMMETRIC) {
792 struct ice_vsi_ctx *ctx;
793 u8 lut_type, hash_type;
796 lut_type = ICE_AQ_VSI_Q_OPT_RSS_LUT_VSI;
797 hash_type = add ? ICE_AQ_VSI_Q_OPT_RSS_XOR :
798 ICE_AQ_VSI_Q_OPT_RSS_TPLZ;
800 ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
802 v_ret = VIRTCHNL_STATUS_ERR_NO_MEMORY;
806 ctx->info.q_opt_rss = ((lut_type <<
807 ICE_AQ_VSI_Q_OPT_RSS_LUT_S) &
808 ICE_AQ_VSI_Q_OPT_RSS_LUT_M) |
810 ICE_AQ_VSI_Q_OPT_RSS_HASH_M);
812 /* Preserve existing queueing option setting */
813 ctx->info.q_opt_rss |= (vsi->info.q_opt_rss &
814 ICE_AQ_VSI_Q_OPT_RSS_GBL_LUT_M);
815 ctx->info.q_opt_tc = vsi->info.q_opt_tc;
816 ctx->info.q_opt_flags = vsi->info.q_opt_rss;
818 ctx->info.valid_sections =
819 cpu_to_le16(ICE_AQ_VSI_PROP_Q_OPT_VALID);
821 status = ice_update_vsi(hw, vsi->idx, ctx, NULL);
823 dev_err(dev, "update VSI for RSS failed, err %d aq_err %s\n",
824 status, ice_aq_str(hw->adminq.sq_last_status));
825 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
827 vsi->info.q_opt_rss = ctx->info.q_opt_rss;
832 u32 addl_hdrs = ICE_FLOW_SEG_HDR_NONE;
833 u64 hash_flds = ICE_HASH_INVALID;
835 if (!ice_vc_parse_rss_cfg(hw, rss_cfg, &addl_hdrs,
837 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
842 if (ice_add_rss_cfg(hw, vsi->idx, hash_flds,
844 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
845 dev_err(dev, "ice_add_rss_cfg failed for vsi = %d, v_ret = %d\n",
846 vsi->vsi_num, v_ret);
851 status = ice_rem_rss_cfg(hw, vsi->idx, hash_flds,
853 /* We just ignore -ENOENT, because if two configurations
854 * share the same profile remove one of them actually
855 * removes both, since the profile is deleted.
857 if (status && status != -ENOENT) {
858 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
859 dev_err(dev, "ice_rem_rss_cfg failed for VF ID:%d, error:%d\n",
866 return ice_vc_send_msg_to_vf(vf, v_opcode, v_ret, NULL, 0);
870 * ice_vc_config_rss_key
871 * @vf: pointer to the VF info
872 * @msg: pointer to the msg buffer
874 * Configure the VF's RSS key
876 static int ice_vc_config_rss_key(struct ice_vf *vf, u8 *msg)
878 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
879 struct virtchnl_rss_key *vrk =
880 (struct virtchnl_rss_key *)msg;
883 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
884 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
888 if (!ice_vc_isvalid_vsi_id(vf, vrk->vsi_id)) {
889 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
893 if (vrk->key_len != ICE_VSIQF_HKEY_ARRAY_SIZE) {
894 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
898 if (!test_bit(ICE_FLAG_RSS_ENA, vf->pf->flags)) {
899 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
903 vsi = ice_get_vf_vsi(vf);
905 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
909 if (ice_set_rss_key(vsi, vrk->key))
910 v_ret = VIRTCHNL_STATUS_ERR_ADMIN_QUEUE_ERROR;
912 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_CONFIG_RSS_KEY, v_ret,
917 * ice_vc_config_rss_lut
918 * @vf: pointer to the VF info
919 * @msg: pointer to the msg buffer
921 * Configure the VF's RSS LUT
923 static int ice_vc_config_rss_lut(struct ice_vf *vf, u8 *msg)
925 struct virtchnl_rss_lut *vrl = (struct virtchnl_rss_lut *)msg;
926 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
929 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
930 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
934 if (!ice_vc_isvalid_vsi_id(vf, vrl->vsi_id)) {
935 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
939 if (vrl->lut_entries != ICE_VSIQF_HLUT_ARRAY_SIZE) {
940 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
944 if (!test_bit(ICE_FLAG_RSS_ENA, vf->pf->flags)) {
945 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
949 vsi = ice_get_vf_vsi(vf);
951 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
955 if (ice_set_rss_lut(vsi, vrl->lut, ICE_VSIQF_HLUT_ARRAY_SIZE))
956 v_ret = VIRTCHNL_STATUS_ERR_ADMIN_QUEUE_ERROR;
958 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_CONFIG_RSS_LUT, v_ret,
963 * ice_vc_cfg_promiscuous_mode_msg
964 * @vf: pointer to the VF info
965 * @msg: pointer to the msg buffer
967 * called from the VF to configure VF VSIs promiscuous mode
969 static int ice_vc_cfg_promiscuous_mode_msg(struct ice_vf *vf, u8 *msg)
971 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
972 bool rm_promisc, alluni = false, allmulti = false;
973 struct virtchnl_promisc_info *info =
974 (struct virtchnl_promisc_info *)msg;
975 struct ice_vsi_vlan_ops *vlan_ops;
976 int mcast_err = 0, ucast_err = 0;
977 struct ice_pf *pf = vf->pf;
982 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
983 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
987 if (!ice_vc_isvalid_vsi_id(vf, info->vsi_id)) {
988 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
992 vsi = ice_get_vf_vsi(vf);
994 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
998 dev = ice_pf_to_dev(pf);
999 if (!ice_is_vf_trusted(vf)) {
1000 dev_err(dev, "Unprivileged VF %d is attempting to configure promiscuous mode\n",
1002 /* Leave v_ret alone, lie to the VF on purpose. */
1006 if (info->flags & FLAG_VF_UNICAST_PROMISC)
1009 if (info->flags & FLAG_VF_MULTICAST_PROMISC)
1012 rm_promisc = !allmulti && !alluni;
1014 vlan_ops = ice_get_compat_vsi_vlan_ops(vsi);
1016 ret = vlan_ops->ena_rx_filtering(vsi);
1018 ret = vlan_ops->dis_rx_filtering(vsi);
1020 dev_err(dev, "Failed to configure VLAN pruning in promiscuous mode\n");
1021 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1025 if (!test_bit(ICE_FLAG_VF_TRUE_PROMISC_ENA, pf->flags)) {
1026 bool set_dflt_vsi = alluni || allmulti;
1028 if (set_dflt_vsi && !ice_is_dflt_vsi_in_use(pf->first_sw))
1029 /* only attempt to set the default forwarding VSI if
1030 * it's not currently set
1032 ret = ice_set_dflt_vsi(pf->first_sw, vsi);
1033 else if (!set_dflt_vsi &&
1034 ice_is_vsi_dflt_vsi(pf->first_sw, vsi))
1035 /* only attempt to free the default forwarding VSI if we
1038 ret = ice_clear_dflt_vsi(pf->first_sw);
1041 dev_err(dev, "%sable VF %d as the default VSI failed, error %d\n",
1042 set_dflt_vsi ? "en" : "dis", vf->vf_id, ret);
1043 v_ret = VIRTCHNL_STATUS_ERR_ADMIN_QUEUE_ERROR;
1047 u8 mcast_m, ucast_m;
1049 if (ice_vf_is_port_vlan_ena(vf) ||
1050 ice_vsi_has_non_zero_vlans(vsi)) {
1051 mcast_m = ICE_MCAST_VLAN_PROMISC_BITS;
1052 ucast_m = ICE_UCAST_VLAN_PROMISC_BITS;
1054 mcast_m = ICE_MCAST_PROMISC_BITS;
1055 ucast_m = ICE_UCAST_PROMISC_BITS;
1059 ucast_err = ice_vf_set_vsi_promisc(vf, vsi, ucast_m);
1061 ucast_err = ice_vf_clear_vsi_promisc(vf, vsi, ucast_m);
1064 mcast_err = ice_vf_set_vsi_promisc(vf, vsi, mcast_m);
1066 mcast_err = ice_vf_clear_vsi_promisc(vf, vsi, mcast_m);
1068 if (ucast_err || mcast_err)
1069 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1074 !test_and_set_bit(ICE_VF_STATE_MC_PROMISC, vf->vf_states))
1075 dev_info(dev, "VF %u successfully set multicast promiscuous mode\n",
1077 else if (!allmulti &&
1078 test_and_clear_bit(ICE_VF_STATE_MC_PROMISC,
1080 dev_info(dev, "VF %u successfully unset multicast promiscuous mode\n",
1086 !test_and_set_bit(ICE_VF_STATE_UC_PROMISC, vf->vf_states))
1087 dev_info(dev, "VF %u successfully set unicast promiscuous mode\n",
1090 test_and_clear_bit(ICE_VF_STATE_UC_PROMISC,
1092 dev_info(dev, "VF %u successfully unset unicast promiscuous mode\n",
1097 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE,
1102 * ice_vc_get_stats_msg
1103 * @vf: pointer to the VF info
1104 * @msg: pointer to the msg buffer
1106 * called from the VF to get VSI stats
1108 static int ice_vc_get_stats_msg(struct ice_vf *vf, u8 *msg)
1110 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
1111 struct virtchnl_queue_select *vqs =
1112 (struct virtchnl_queue_select *)msg;
1113 struct ice_eth_stats stats = { 0 };
1114 struct ice_vsi *vsi;
1116 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
1117 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1121 if (!ice_vc_isvalid_vsi_id(vf, vqs->vsi_id)) {
1122 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1126 vsi = ice_get_vf_vsi(vf);
1128 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1132 ice_update_eth_stats(vsi);
1134 stats = vsi->eth_stats;
1137 /* send the response to the VF */
1138 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_GET_STATS, v_ret,
1139 (u8 *)&stats, sizeof(stats));
1143 * ice_vc_validate_vqs_bitmaps - validate Rx/Tx queue bitmaps from VIRTCHNL
1144 * @vqs: virtchnl_queue_select structure containing bitmaps to validate
1146 * Return true on successful validation, else false
1148 static bool ice_vc_validate_vqs_bitmaps(struct virtchnl_queue_select *vqs)
1150 if ((!vqs->rx_queues && !vqs->tx_queues) ||
1151 vqs->rx_queues >= BIT(ICE_MAX_RSS_QS_PER_VF) ||
1152 vqs->tx_queues >= BIT(ICE_MAX_RSS_QS_PER_VF))
1159 * ice_vf_ena_txq_interrupt - enable Tx queue interrupt via QINT_TQCTL
1160 * @vsi: VSI of the VF to configure
1161 * @q_idx: VF queue index used to determine the queue in the PF's space
1163 static void ice_vf_ena_txq_interrupt(struct ice_vsi *vsi, u32 q_idx)
1165 struct ice_hw *hw = &vsi->back->hw;
1166 u32 pfq = vsi->txq_map[q_idx];
1169 reg = rd32(hw, QINT_TQCTL(pfq));
1171 /* MSI-X index 0 in the VF's space is always for the OICR, which means
1172 * this is most likely a poll mode VF driver, so don't enable an
1173 * interrupt that was never configured via VIRTCHNL_OP_CONFIG_IRQ_MAP
1175 if (!(reg & QINT_TQCTL_MSIX_INDX_M))
1178 wr32(hw, QINT_TQCTL(pfq), reg | QINT_TQCTL_CAUSE_ENA_M);
1182 * ice_vf_ena_rxq_interrupt - enable Tx queue interrupt via QINT_RQCTL
1183 * @vsi: VSI of the VF to configure
1184 * @q_idx: VF queue index used to determine the queue in the PF's space
1186 static void ice_vf_ena_rxq_interrupt(struct ice_vsi *vsi, u32 q_idx)
1188 struct ice_hw *hw = &vsi->back->hw;
1189 u32 pfq = vsi->rxq_map[q_idx];
1192 reg = rd32(hw, QINT_RQCTL(pfq));
1194 /* MSI-X index 0 in the VF's space is always for the OICR, which means
1195 * this is most likely a poll mode VF driver, so don't enable an
1196 * interrupt that was never configured via VIRTCHNL_OP_CONFIG_IRQ_MAP
1198 if (!(reg & QINT_RQCTL_MSIX_INDX_M))
1201 wr32(hw, QINT_RQCTL(pfq), reg | QINT_RQCTL_CAUSE_ENA_M);
1206 * @vf: pointer to the VF info
1207 * @msg: pointer to the msg buffer
1209 * called from the VF to enable all or specific queue(s)
1211 static int ice_vc_ena_qs_msg(struct ice_vf *vf, u8 *msg)
1213 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
1214 struct virtchnl_queue_select *vqs =
1215 (struct virtchnl_queue_select *)msg;
1216 struct ice_vsi *vsi;
1217 unsigned long q_map;
1220 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
1221 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1225 if (!ice_vc_isvalid_vsi_id(vf, vqs->vsi_id)) {
1226 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1230 if (!ice_vc_validate_vqs_bitmaps(vqs)) {
1231 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1235 vsi = ice_get_vf_vsi(vf);
1237 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1241 /* Enable only Rx rings, Tx rings were enabled by the FW when the
1242 * Tx queue group list was configured and the context bits were
1243 * programmed using ice_vsi_cfg_txqs
1245 q_map = vqs->rx_queues;
1246 for_each_set_bit(vf_q_id, &q_map, ICE_MAX_RSS_QS_PER_VF) {
1247 if (!ice_vc_isvalid_q_id(vf, vqs->vsi_id, vf_q_id)) {
1248 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1252 /* Skip queue if enabled */
1253 if (test_bit(vf_q_id, vf->rxq_ena))
1256 if (ice_vsi_ctrl_one_rx_ring(vsi, true, vf_q_id, true)) {
1257 dev_err(ice_pf_to_dev(vsi->back), "Failed to enable Rx ring %d on VSI %d\n",
1258 vf_q_id, vsi->vsi_num);
1259 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1263 ice_vf_ena_rxq_interrupt(vsi, vf_q_id);
1264 set_bit(vf_q_id, vf->rxq_ena);
1267 q_map = vqs->tx_queues;
1268 for_each_set_bit(vf_q_id, &q_map, ICE_MAX_RSS_QS_PER_VF) {
1269 if (!ice_vc_isvalid_q_id(vf, vqs->vsi_id, vf_q_id)) {
1270 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1274 /* Skip queue if enabled */
1275 if (test_bit(vf_q_id, vf->txq_ena))
1278 ice_vf_ena_txq_interrupt(vsi, vf_q_id);
1279 set_bit(vf_q_id, vf->txq_ena);
1282 /* Set flag to indicate that queues are enabled */
1283 if (v_ret == VIRTCHNL_STATUS_SUCCESS)
1284 set_bit(ICE_VF_STATE_QS_ENA, vf->vf_states);
1287 /* send the response to the VF */
1288 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_ENABLE_QUEUES, v_ret,
1293 * ice_vf_vsi_dis_single_txq - disable a single Tx queue
1294 * @vf: VF to disable queue for
1295 * @vsi: VSI for the VF
1296 * @q_id: VF relative (0-based) queue ID
1298 * Attempt to disable the Tx queue passed in. If the Tx queue was successfully
1299 * disabled then clear q_id bit in the enabled queues bitmap and return
1300 * success. Otherwise return error.
1303 ice_vf_vsi_dis_single_txq(struct ice_vf *vf, struct ice_vsi *vsi, u16 q_id)
1305 struct ice_txq_meta txq_meta = { 0 };
1306 struct ice_tx_ring *ring;
1309 if (!test_bit(q_id, vf->txq_ena))
1310 dev_dbg(ice_pf_to_dev(vsi->back), "Queue %u on VSI %u is not enabled, but stopping it anyway\n",
1311 q_id, vsi->vsi_num);
1313 ring = vsi->tx_rings[q_id];
1317 ice_fill_txq_meta(vsi, ring, &txq_meta);
1319 err = ice_vsi_stop_tx_ring(vsi, ICE_NO_RESET, vf->vf_id, ring, &txq_meta);
1321 dev_err(ice_pf_to_dev(vsi->back), "Failed to stop Tx ring %d on VSI %d\n",
1322 q_id, vsi->vsi_num);
1326 /* Clear enabled queues flag */
1327 clear_bit(q_id, vf->txq_ena);
1334 * @vf: pointer to the VF info
1335 * @msg: pointer to the msg buffer
1337 * called from the VF to disable all or specific queue(s)
1339 static int ice_vc_dis_qs_msg(struct ice_vf *vf, u8 *msg)
1341 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
1342 struct virtchnl_queue_select *vqs =
1343 (struct virtchnl_queue_select *)msg;
1344 struct ice_vsi *vsi;
1345 unsigned long q_map;
1348 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states) &&
1349 !test_bit(ICE_VF_STATE_QS_ENA, vf->vf_states)) {
1350 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1354 if (!ice_vc_isvalid_vsi_id(vf, vqs->vsi_id)) {
1355 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1359 if (!ice_vc_validate_vqs_bitmaps(vqs)) {
1360 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1364 vsi = ice_get_vf_vsi(vf);
1366 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1370 if (vqs->tx_queues) {
1371 q_map = vqs->tx_queues;
1373 for_each_set_bit(vf_q_id, &q_map, ICE_MAX_RSS_QS_PER_VF) {
1374 if (!ice_vc_isvalid_q_id(vf, vqs->vsi_id, vf_q_id)) {
1375 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1379 if (ice_vf_vsi_dis_single_txq(vf, vsi, vf_q_id)) {
1380 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1386 q_map = vqs->rx_queues;
1387 /* speed up Rx queue disable by batching them if possible */
1389 bitmap_equal(&q_map, vf->rxq_ena, ICE_MAX_RSS_QS_PER_VF)) {
1390 if (ice_vsi_stop_all_rx_rings(vsi)) {
1391 dev_err(ice_pf_to_dev(vsi->back), "Failed to stop all Rx rings on VSI %d\n",
1393 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1397 bitmap_zero(vf->rxq_ena, ICE_MAX_RSS_QS_PER_VF);
1399 for_each_set_bit(vf_q_id, &q_map, ICE_MAX_RSS_QS_PER_VF) {
1400 if (!ice_vc_isvalid_q_id(vf, vqs->vsi_id, vf_q_id)) {
1401 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1405 /* Skip queue if not enabled */
1406 if (!test_bit(vf_q_id, vf->rxq_ena))
1409 if (ice_vsi_ctrl_one_rx_ring(vsi, false, vf_q_id,
1411 dev_err(ice_pf_to_dev(vsi->back), "Failed to stop Rx ring %d on VSI %d\n",
1412 vf_q_id, vsi->vsi_num);
1413 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1417 /* Clear enabled queues flag */
1418 clear_bit(vf_q_id, vf->rxq_ena);
1422 /* Clear enabled queues flag */
1423 if (v_ret == VIRTCHNL_STATUS_SUCCESS && ice_vf_has_no_qs_ena(vf))
1424 clear_bit(ICE_VF_STATE_QS_ENA, vf->vf_states);
1427 /* send the response to the VF */
1428 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_DISABLE_QUEUES, v_ret,
1434 * @vf: pointer to the VF info
1435 * @vsi: the VSI being configured
1436 * @vector_id: vector ID
1437 * @map: vector map for mapping vectors to queues
1438 * @q_vector: structure for interrupt vector
1439 * configure the IRQ to queue map
1442 ice_cfg_interrupt(struct ice_vf *vf, struct ice_vsi *vsi, u16 vector_id,
1443 struct virtchnl_vector_map *map,
1444 struct ice_q_vector *q_vector)
1446 u16 vsi_q_id, vsi_q_id_idx;
1449 q_vector->num_ring_rx = 0;
1450 q_vector->num_ring_tx = 0;
1452 qmap = map->rxq_map;
1453 for_each_set_bit(vsi_q_id_idx, &qmap, ICE_MAX_RSS_QS_PER_VF) {
1454 vsi_q_id = vsi_q_id_idx;
1456 if (!ice_vc_isvalid_q_id(vf, vsi->vsi_num, vsi_q_id))
1457 return VIRTCHNL_STATUS_ERR_PARAM;
1459 q_vector->num_ring_rx++;
1460 q_vector->rx.itr_idx = map->rxitr_idx;
1461 vsi->rx_rings[vsi_q_id]->q_vector = q_vector;
1462 ice_cfg_rxq_interrupt(vsi, vsi_q_id, vector_id,
1463 q_vector->rx.itr_idx);
1466 qmap = map->txq_map;
1467 for_each_set_bit(vsi_q_id_idx, &qmap, ICE_MAX_RSS_QS_PER_VF) {
1468 vsi_q_id = vsi_q_id_idx;
1470 if (!ice_vc_isvalid_q_id(vf, vsi->vsi_num, vsi_q_id))
1471 return VIRTCHNL_STATUS_ERR_PARAM;
1473 q_vector->num_ring_tx++;
1474 q_vector->tx.itr_idx = map->txitr_idx;
1475 vsi->tx_rings[vsi_q_id]->q_vector = q_vector;
1476 ice_cfg_txq_interrupt(vsi, vsi_q_id, vector_id,
1477 q_vector->tx.itr_idx);
1480 return VIRTCHNL_STATUS_SUCCESS;
1484 * ice_vc_cfg_irq_map_msg
1485 * @vf: pointer to the VF info
1486 * @msg: pointer to the msg buffer
1488 * called from the VF to configure the IRQ to queue map
1490 static int ice_vc_cfg_irq_map_msg(struct ice_vf *vf, u8 *msg)
1492 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
1493 u16 num_q_vectors_mapped, vsi_id, vector_id;
1494 struct virtchnl_irq_map_info *irqmap_info;
1495 struct virtchnl_vector_map *map;
1496 struct ice_pf *pf = vf->pf;
1497 struct ice_vsi *vsi;
1500 irqmap_info = (struct virtchnl_irq_map_info *)msg;
1501 num_q_vectors_mapped = irqmap_info->num_vectors;
1503 /* Check to make sure number of VF vectors mapped is not greater than
1504 * number of VF vectors originally allocated, and check that
1505 * there is actually at least a single VF queue vector mapped
1507 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states) ||
1508 pf->vfs.num_msix_per < num_q_vectors_mapped ||
1509 !num_q_vectors_mapped) {
1510 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1514 vsi = ice_get_vf_vsi(vf);
1516 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1520 for (i = 0; i < num_q_vectors_mapped; i++) {
1521 struct ice_q_vector *q_vector;
1523 map = &irqmap_info->vecmap[i];
1525 vector_id = map->vector_id;
1526 vsi_id = map->vsi_id;
1527 /* vector_id is always 0-based for each VF, and can never be
1528 * larger than or equal to the max allowed interrupts per VF
1530 if (!(vector_id < pf->vfs.num_msix_per) ||
1531 !ice_vc_isvalid_vsi_id(vf, vsi_id) ||
1532 (!vector_id && (map->rxq_map || map->txq_map))) {
1533 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1537 /* No need to map VF miscellaneous or rogue vector */
1541 /* Subtract non queue vector from vector_id passed by VF
1542 * to get actual number of VSI queue vector array index
1544 q_vector = vsi->q_vectors[vector_id - ICE_NONQ_VECS_VF];
1546 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1550 /* lookout for the invalid queue index */
1551 v_ret = (enum virtchnl_status_code)
1552 ice_cfg_interrupt(vf, vsi, vector_id, map, q_vector);
1558 /* send the response to the VF */
1559 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_CONFIG_IRQ_MAP, v_ret,
1565 * @vf: pointer to the VF info
1566 * @msg: pointer to the msg buffer
1568 * called from the VF to configure the Rx/Tx queues
1570 static int ice_vc_cfg_qs_msg(struct ice_vf *vf, u8 *msg)
1572 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
1573 struct virtchnl_vsi_queue_config_info *qci =
1574 (struct virtchnl_vsi_queue_config_info *)msg;
1575 struct virtchnl_queue_pair_info *qpi;
1576 struct ice_pf *pf = vf->pf;
1577 struct ice_vsi *vsi;
1580 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
1581 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1585 if (!ice_vc_isvalid_vsi_id(vf, qci->vsi_id)) {
1586 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1590 vsi = ice_get_vf_vsi(vf);
1592 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1596 if (qci->num_queue_pairs > ICE_MAX_RSS_QS_PER_VF ||
1597 qci->num_queue_pairs > min_t(u16, vsi->alloc_txq, vsi->alloc_rxq)) {
1598 dev_err(ice_pf_to_dev(pf), "VF-%d requesting more than supported number of queues: %d\n",
1599 vf->vf_id, min_t(u16, vsi->alloc_txq, vsi->alloc_rxq));
1600 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1604 for (i = 0; i < qci->num_queue_pairs; i++) {
1605 qpi = &qci->qpair[i];
1606 if (qpi->txq.vsi_id != qci->vsi_id ||
1607 qpi->rxq.vsi_id != qci->vsi_id ||
1608 qpi->rxq.queue_id != qpi->txq.queue_id ||
1609 qpi->txq.headwb_enabled ||
1610 !ice_vc_isvalid_ring_len(qpi->txq.ring_len) ||
1611 !ice_vc_isvalid_ring_len(qpi->rxq.ring_len) ||
1612 !ice_vc_isvalid_q_id(vf, qci->vsi_id, qpi->txq.queue_id)) {
1613 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1617 q_idx = qpi->rxq.queue_id;
1619 /* make sure selected "q_idx" is in valid range of queues
1620 * for selected "vsi"
1622 if (q_idx >= vsi->alloc_txq || q_idx >= vsi->alloc_rxq) {
1623 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1627 /* copy Tx queue info from VF into VSI */
1628 if (qpi->txq.ring_len > 0) {
1629 vsi->tx_rings[i]->dma = qpi->txq.dma_ring_addr;
1630 vsi->tx_rings[i]->count = qpi->txq.ring_len;
1632 /* Disable any existing queue first */
1633 if (ice_vf_vsi_dis_single_txq(vf, vsi, q_idx)) {
1634 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1638 /* Configure a queue with the requested settings */
1639 if (ice_vsi_cfg_single_txq(vsi, vsi->tx_rings, q_idx)) {
1640 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1645 /* copy Rx queue info from VF into VSI */
1646 if (qpi->rxq.ring_len > 0) {
1647 u16 max_frame_size = ice_vc_get_max_frame_size(vf);
1649 vsi->rx_rings[i]->dma = qpi->rxq.dma_ring_addr;
1650 vsi->rx_rings[i]->count = qpi->rxq.ring_len;
1652 if (qpi->rxq.databuffer_size != 0 &&
1653 (qpi->rxq.databuffer_size > ((16 * 1024) - 128) ||
1654 qpi->rxq.databuffer_size < 1024)) {
1655 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1658 vsi->rx_buf_len = qpi->rxq.databuffer_size;
1659 vsi->rx_rings[i]->rx_buf_len = vsi->rx_buf_len;
1660 if (qpi->rxq.max_pkt_size > max_frame_size ||
1661 qpi->rxq.max_pkt_size < 64) {
1662 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1666 vsi->max_frame = qpi->rxq.max_pkt_size;
1667 /* add space for the port VLAN since the VF driver is
1668 * not expected to account for it in the MTU
1671 if (ice_vf_is_port_vlan_ena(vf))
1672 vsi->max_frame += VLAN_HLEN;
1674 if (ice_vsi_cfg_single_rxq(vsi, q_idx)) {
1675 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1682 /* send the response to the VF */
1683 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_CONFIG_VSI_QUEUES, v_ret,
1688 * ice_can_vf_change_mac
1689 * @vf: pointer to the VF info
1691 * Return true if the VF is allowed to change its MAC filters, false otherwise
1693 static bool ice_can_vf_change_mac(struct ice_vf *vf)
1695 /* If the VF MAC address has been set administratively (via the
1696 * ndo_set_vf_mac command), then deny permission to the VF to
1697 * add/delete unicast MAC addresses, unless the VF is trusted
1699 if (vf->pf_set_mac && !ice_is_vf_trusted(vf))
1706 * ice_vc_ether_addr_type - get type of virtchnl_ether_addr
1707 * @vc_ether_addr: used to extract the type
1710 ice_vc_ether_addr_type(struct virtchnl_ether_addr *vc_ether_addr)
1712 return (vc_ether_addr->type & VIRTCHNL_ETHER_ADDR_TYPE_MASK);
1716 * ice_is_vc_addr_legacy - check if the MAC address is from an older VF
1717 * @vc_ether_addr: VIRTCHNL structure that contains MAC and type
1720 ice_is_vc_addr_legacy(struct virtchnl_ether_addr *vc_ether_addr)
1722 u8 type = ice_vc_ether_addr_type(vc_ether_addr);
1724 return (type == VIRTCHNL_ETHER_ADDR_LEGACY);
1728 * ice_is_vc_addr_primary - check if the MAC address is the VF's primary MAC
1729 * @vc_ether_addr: VIRTCHNL structure that contains MAC and type
1731 * This function should only be called when the MAC address in
1732 * virtchnl_ether_addr is a valid unicast MAC
1735 ice_is_vc_addr_primary(struct virtchnl_ether_addr __maybe_unused *vc_ether_addr)
1737 u8 type = ice_vc_ether_addr_type(vc_ether_addr);
1739 return (type == VIRTCHNL_ETHER_ADDR_PRIMARY);
1743 * ice_vfhw_mac_add - update the VF's cached hardware MAC if allowed
1745 * @vc_ether_addr: structure from VIRTCHNL with MAC to add
1748 ice_vfhw_mac_add(struct ice_vf *vf, struct virtchnl_ether_addr *vc_ether_addr)
1750 u8 *mac_addr = vc_ether_addr->addr;
1752 if (!is_valid_ether_addr(mac_addr))
1755 /* only allow legacy VF drivers to set the device and hardware MAC if it
1756 * is zero and allow new VF drivers to set the hardware MAC if the type
1757 * was correctly specified over VIRTCHNL
1759 if ((ice_is_vc_addr_legacy(vc_ether_addr) &&
1760 is_zero_ether_addr(vf->hw_lan_addr.addr)) ||
1761 ice_is_vc_addr_primary(vc_ether_addr)) {
1762 ether_addr_copy(vf->dev_lan_addr.addr, mac_addr);
1763 ether_addr_copy(vf->hw_lan_addr.addr, mac_addr);
1766 /* hardware and device MACs are already set, but its possible that the
1767 * VF driver sent the VIRTCHNL_OP_ADD_ETH_ADDR message before the
1768 * VIRTCHNL_OP_DEL_ETH_ADDR when trying to update its MAC, so save it
1769 * away for the legacy VF driver case as it will be updated in the
1770 * delete flow for this case
1772 if (ice_is_vc_addr_legacy(vc_ether_addr)) {
1773 ether_addr_copy(vf->legacy_last_added_umac.addr,
1775 vf->legacy_last_added_umac.time_modified = jiffies;
1780 * ice_vc_add_mac_addr - attempt to add the MAC address passed in
1781 * @vf: pointer to the VF info
1782 * @vsi: pointer to the VF's VSI
1783 * @vc_ether_addr: VIRTCHNL MAC address structure used to add MAC
1786 ice_vc_add_mac_addr(struct ice_vf *vf, struct ice_vsi *vsi,
1787 struct virtchnl_ether_addr *vc_ether_addr)
1789 struct device *dev = ice_pf_to_dev(vf->pf);
1790 u8 *mac_addr = vc_ether_addr->addr;
1793 /* device MAC already added */
1794 if (ether_addr_equal(mac_addr, vf->dev_lan_addr.addr))
1797 if (is_unicast_ether_addr(mac_addr) && !ice_can_vf_change_mac(vf)) {
1798 dev_err(dev, "VF attempting to override administratively set MAC address, bring down and up the VF interface to resume normal operation\n");
1802 ret = ice_fltr_add_mac(vsi, mac_addr, ICE_FWD_TO_VSI);
1803 if (ret == -EEXIST) {
1804 dev_dbg(dev, "MAC %pM already exists for VF %d\n", mac_addr,
1806 /* don't return since we might need to update
1807 * the primary MAC in ice_vfhw_mac_add() below
1810 dev_err(dev, "Failed to add MAC %pM for VF %d\n, error %d\n",
1811 mac_addr, vf->vf_id, ret);
1817 ice_vfhw_mac_add(vf, vc_ether_addr);
1823 * ice_is_legacy_umac_expired - check if last added legacy unicast MAC expired
1824 * @last_added_umac: structure used to check expiration
1826 static bool ice_is_legacy_umac_expired(struct ice_time_mac *last_added_umac)
1828 #define ICE_LEGACY_VF_MAC_CHANGE_EXPIRE_TIME msecs_to_jiffies(3000)
1829 return time_is_before_jiffies(last_added_umac->time_modified +
1830 ICE_LEGACY_VF_MAC_CHANGE_EXPIRE_TIME);
1834 * ice_update_legacy_cached_mac - update cached hardware MAC for legacy VF
1836 * @vc_ether_addr: structure from VIRTCHNL with MAC to check
1838 * only update cached hardware MAC for legacy VF drivers on delete
1839 * because we cannot guarantee order/type of MAC from the VF driver
1842 ice_update_legacy_cached_mac(struct ice_vf *vf,
1843 struct virtchnl_ether_addr *vc_ether_addr)
1845 if (!ice_is_vc_addr_legacy(vc_ether_addr) ||
1846 ice_is_legacy_umac_expired(&vf->legacy_last_added_umac))
1849 ether_addr_copy(vf->dev_lan_addr.addr, vf->legacy_last_added_umac.addr);
1850 ether_addr_copy(vf->hw_lan_addr.addr, vf->legacy_last_added_umac.addr);
1854 * ice_vfhw_mac_del - update the VF's cached hardware MAC if allowed
1856 * @vc_ether_addr: structure from VIRTCHNL with MAC to delete
1859 ice_vfhw_mac_del(struct ice_vf *vf, struct virtchnl_ether_addr *vc_ether_addr)
1861 u8 *mac_addr = vc_ether_addr->addr;
1863 if (!is_valid_ether_addr(mac_addr) ||
1864 !ether_addr_equal(vf->dev_lan_addr.addr, mac_addr))
1867 /* allow the device MAC to be repopulated in the add flow and don't
1868 * clear the hardware MAC (i.e. hw_lan_addr.addr) here as that is meant
1869 * to be persistent on VM reboot and across driver unload/load, which
1870 * won't work if we clear the hardware MAC here
1872 eth_zero_addr(vf->dev_lan_addr.addr);
1874 ice_update_legacy_cached_mac(vf, vc_ether_addr);
1878 * ice_vc_del_mac_addr - attempt to delete the MAC address passed in
1879 * @vf: pointer to the VF info
1880 * @vsi: pointer to the VF's VSI
1881 * @vc_ether_addr: VIRTCHNL MAC address structure used to delete MAC
1884 ice_vc_del_mac_addr(struct ice_vf *vf, struct ice_vsi *vsi,
1885 struct virtchnl_ether_addr *vc_ether_addr)
1887 struct device *dev = ice_pf_to_dev(vf->pf);
1888 u8 *mac_addr = vc_ether_addr->addr;
1891 if (!ice_can_vf_change_mac(vf) &&
1892 ether_addr_equal(vf->dev_lan_addr.addr, mac_addr))
1895 status = ice_fltr_remove_mac(vsi, mac_addr, ICE_FWD_TO_VSI);
1896 if (status == -ENOENT) {
1897 dev_err(dev, "MAC %pM does not exist for VF %d\n", mac_addr,
1900 } else if (status) {
1901 dev_err(dev, "Failed to delete MAC %pM for VF %d, error %d\n",
1902 mac_addr, vf->vf_id, status);
1906 ice_vfhw_mac_del(vf, vc_ether_addr);
1914 * ice_vc_handle_mac_addr_msg
1915 * @vf: pointer to the VF info
1916 * @msg: pointer to the msg buffer
1917 * @set: true if MAC filters are being set, false otherwise
1919 * add guest MAC address filter
1922 ice_vc_handle_mac_addr_msg(struct ice_vf *vf, u8 *msg, bool set)
1924 int (*ice_vc_cfg_mac)
1925 (struct ice_vf *vf, struct ice_vsi *vsi,
1926 struct virtchnl_ether_addr *virtchnl_ether_addr);
1927 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
1928 struct virtchnl_ether_addr_list *al =
1929 (struct virtchnl_ether_addr_list *)msg;
1930 struct ice_pf *pf = vf->pf;
1931 enum virtchnl_ops vc_op;
1932 struct ice_vsi *vsi;
1936 vc_op = VIRTCHNL_OP_ADD_ETH_ADDR;
1937 ice_vc_cfg_mac = ice_vc_add_mac_addr;
1939 vc_op = VIRTCHNL_OP_DEL_ETH_ADDR;
1940 ice_vc_cfg_mac = ice_vc_del_mac_addr;
1943 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states) ||
1944 !ice_vc_isvalid_vsi_id(vf, al->vsi_id)) {
1945 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1946 goto handle_mac_exit;
1949 /* If this VF is not privileged, then we can't add more than a
1950 * limited number of addresses. Check to make sure that the
1951 * additions do not push us over the limit.
1953 if (set && !ice_is_vf_trusted(vf) &&
1954 (vf->num_mac + al->num_elements) > ICE_MAX_MACADDR_PER_VF) {
1955 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",
1957 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1958 goto handle_mac_exit;
1961 vsi = ice_get_vf_vsi(vf);
1963 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1964 goto handle_mac_exit;
1967 for (i = 0; i < al->num_elements; i++) {
1968 u8 *mac_addr = al->list[i].addr;
1971 if (is_broadcast_ether_addr(mac_addr) ||
1972 is_zero_ether_addr(mac_addr))
1975 result = ice_vc_cfg_mac(vf, vsi, &al->list[i]);
1976 if (result == -EEXIST || result == -ENOENT) {
1978 } else if (result) {
1979 v_ret = VIRTCHNL_STATUS_ERR_ADMIN_QUEUE_ERROR;
1980 goto handle_mac_exit;
1985 /* send the response to the VF */
1986 return ice_vc_send_msg_to_vf(vf, vc_op, v_ret, NULL, 0);
1990 * ice_vc_add_mac_addr_msg
1991 * @vf: pointer to the VF info
1992 * @msg: pointer to the msg buffer
1994 * add guest MAC address filter
1996 static int ice_vc_add_mac_addr_msg(struct ice_vf *vf, u8 *msg)
1998 return ice_vc_handle_mac_addr_msg(vf, msg, true);
2002 * ice_vc_del_mac_addr_msg
2003 * @vf: pointer to the VF info
2004 * @msg: pointer to the msg buffer
2006 * remove guest MAC address filter
2008 static int ice_vc_del_mac_addr_msg(struct ice_vf *vf, u8 *msg)
2010 return ice_vc_handle_mac_addr_msg(vf, msg, false);
2014 * ice_vc_request_qs_msg
2015 * @vf: pointer to the VF info
2016 * @msg: pointer to the msg buffer
2018 * VFs get a default number of queues but can use this message to request a
2019 * different number. If the request is successful, PF will reset the VF and
2020 * return 0. If unsuccessful, PF will send message informing VF of number of
2021 * available queue pairs via virtchnl message response to VF.
2023 static int ice_vc_request_qs_msg(struct ice_vf *vf, u8 *msg)
2025 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
2026 struct virtchnl_vf_res_request *vfres =
2027 (struct virtchnl_vf_res_request *)msg;
2028 u16 req_queues = vfres->num_queue_pairs;
2029 struct ice_pf *pf = vf->pf;
2030 u16 max_allowed_vf_queues;
2031 u16 tx_rx_queue_left;
2035 dev = ice_pf_to_dev(pf);
2036 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
2037 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2041 cur_queues = vf->num_vf_qs;
2042 tx_rx_queue_left = min_t(u16, ice_get_avail_txq_count(pf),
2043 ice_get_avail_rxq_count(pf));
2044 max_allowed_vf_queues = tx_rx_queue_left + cur_queues;
2046 dev_err(dev, "VF %d tried to request 0 queues. Ignoring.\n",
2048 } else if (req_queues > ICE_MAX_RSS_QS_PER_VF) {
2049 dev_err(dev, "VF %d tried to request more than %d queues.\n",
2050 vf->vf_id, ICE_MAX_RSS_QS_PER_VF);
2051 vfres->num_queue_pairs = ICE_MAX_RSS_QS_PER_VF;
2052 } else if (req_queues > cur_queues &&
2053 req_queues - cur_queues > tx_rx_queue_left) {
2054 dev_warn(dev, "VF %d requested %u more queues, but only %u left.\n",
2055 vf->vf_id, req_queues - cur_queues, tx_rx_queue_left);
2056 vfres->num_queue_pairs = min_t(u16, max_allowed_vf_queues,
2057 ICE_MAX_RSS_QS_PER_VF);
2059 /* request is successful, then reset VF */
2060 vf->num_req_qs = req_queues;
2061 ice_reset_vf(vf, ICE_VF_RESET_NOTIFY);
2062 dev_info(dev, "VF %d granted request of %u queues.\n",
2063 vf->vf_id, req_queues);
2068 /* send the response to the VF */
2069 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_REQUEST_QUEUES,
2070 v_ret, (u8 *)vfres, sizeof(*vfres));
2074 * ice_vf_vlan_offload_ena - determine if capabilities support VLAN offloads
2075 * @caps: VF driver negotiated capabilities
2077 * Return true if VIRTCHNL_VF_OFFLOAD_VLAN capability is set, else return false
2079 static bool ice_vf_vlan_offload_ena(u32 caps)
2081 return !!(caps & VIRTCHNL_VF_OFFLOAD_VLAN);
2085 * ice_is_vlan_promisc_allowed - check if VLAN promiscuous config is allowed
2086 * @vf: VF used to determine if VLAN promiscuous config is allowed
2088 static bool ice_is_vlan_promisc_allowed(struct ice_vf *vf)
2090 if ((test_bit(ICE_VF_STATE_UC_PROMISC, vf->vf_states) ||
2091 test_bit(ICE_VF_STATE_MC_PROMISC, vf->vf_states)) &&
2092 test_bit(ICE_FLAG_VF_TRUE_PROMISC_ENA, vf->pf->flags))
2099 * ice_vf_ena_vlan_promisc - Enable Tx/Rx VLAN promiscuous for the VLAN
2100 * @vsi: VF's VSI used to enable VLAN promiscuous mode
2101 * @vlan: VLAN used to enable VLAN promiscuous
2103 * This function should only be called if VLAN promiscuous mode is allowed,
2104 * which can be determined via ice_is_vlan_promisc_allowed().
2106 static int ice_vf_ena_vlan_promisc(struct ice_vsi *vsi, struct ice_vlan *vlan)
2108 u8 promisc_m = ICE_PROMISC_VLAN_TX | ICE_PROMISC_VLAN_RX;
2111 status = ice_fltr_set_vsi_promisc(&vsi->back->hw, vsi->idx, promisc_m,
2113 if (status && status != -EEXIST)
2120 * ice_vf_dis_vlan_promisc - Disable Tx/Rx VLAN promiscuous for the VLAN
2121 * @vsi: VF's VSI used to disable VLAN promiscuous mode for
2122 * @vlan: VLAN used to disable VLAN promiscuous
2124 * This function should only be called if VLAN promiscuous mode is allowed,
2125 * which can be determined via ice_is_vlan_promisc_allowed().
2127 static int ice_vf_dis_vlan_promisc(struct ice_vsi *vsi, struct ice_vlan *vlan)
2129 u8 promisc_m = ICE_PROMISC_VLAN_TX | ICE_PROMISC_VLAN_RX;
2132 status = ice_fltr_clear_vsi_promisc(&vsi->back->hw, vsi->idx, promisc_m,
2134 if (status && status != -ENOENT)
2141 * ice_vf_has_max_vlans - check if VF already has the max allowed VLAN filters
2142 * @vf: VF to check against
2145 * If the VF is trusted then the VF is allowed to add as many VLANs as it
2146 * wants to, so return false.
2148 * When the VF is untrusted compare the number of non-zero VLANs + 1 to the max
2149 * allowed VLANs for an untrusted VF. Return the result of this comparison.
2151 static bool ice_vf_has_max_vlans(struct ice_vf *vf, struct ice_vsi *vsi)
2153 if (ice_is_vf_trusted(vf))
2156 #define ICE_VF_ADDED_VLAN_ZERO_FLTRS 1
2157 return ((ice_vsi_num_non_zero_vlans(vsi) +
2158 ICE_VF_ADDED_VLAN_ZERO_FLTRS) >= ICE_MAX_VLAN_PER_VF);
2162 * ice_vc_process_vlan_msg
2163 * @vf: pointer to the VF info
2164 * @msg: pointer to the msg buffer
2165 * @add_v: Add VLAN if true, otherwise delete VLAN
2167 * Process virtchnl op to add or remove programmed guest VLAN ID
2169 static int ice_vc_process_vlan_msg(struct ice_vf *vf, u8 *msg, bool add_v)
2171 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
2172 struct virtchnl_vlan_filter_list *vfl =
2173 (struct virtchnl_vlan_filter_list *)msg;
2174 struct ice_pf *pf = vf->pf;
2175 bool vlan_promisc = false;
2176 struct ice_vsi *vsi;
2181 dev = ice_pf_to_dev(pf);
2182 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
2183 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2187 if (!ice_vf_vlan_offload_ena(vf->driver_caps)) {
2188 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2192 if (!ice_vc_isvalid_vsi_id(vf, vfl->vsi_id)) {
2193 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2197 for (i = 0; i < vfl->num_elements; i++) {
2198 if (vfl->vlan_id[i] >= VLAN_N_VID) {
2199 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2200 dev_err(dev, "invalid VF VLAN id %d\n",
2206 vsi = ice_get_vf_vsi(vf);
2208 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2212 if (add_v && ice_vf_has_max_vlans(vf, vsi)) {
2213 dev_info(dev, "VF-%d is not trusted, switch the VF to trusted mode, in order to add more VLAN addresses\n",
2215 /* There is no need to let VF know about being not trusted,
2216 * so we can just return success message here
2221 /* in DVM a VF can add/delete inner VLAN filters when
2222 * VIRTCHNL_VF_OFFLOAD_VLAN is negotiated, so only reject in SVM
2224 if (ice_vf_is_port_vlan_ena(vf) && !ice_is_dvm_ena(&pf->hw)) {
2225 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2229 /* in DVM VLAN promiscuous is based on the outer VLAN, which would be
2230 * the port VLAN if VIRTCHNL_VF_OFFLOAD_VLAN was negotiated, so only
2231 * allow vlan_promisc = true in SVM and if no port VLAN is configured
2233 vlan_promisc = ice_is_vlan_promisc_allowed(vf) &&
2234 !ice_is_dvm_ena(&pf->hw) &&
2235 !ice_vf_is_port_vlan_ena(vf);
2238 for (i = 0; i < vfl->num_elements; i++) {
2239 u16 vid = vfl->vlan_id[i];
2240 struct ice_vlan vlan;
2242 if (ice_vf_has_max_vlans(vf, vsi)) {
2243 dev_info(dev, "VF-%d is not trusted, switch the VF to trusted mode, in order to add more VLAN addresses\n",
2245 /* There is no need to let VF know about being
2246 * not trusted, so we can just return success
2247 * message here as well.
2252 /* we add VLAN 0 by default for each VF so we can enable
2253 * Tx VLAN anti-spoof without triggering MDD events so
2254 * we don't need to add it again here
2259 vlan = ICE_VLAN(ETH_P_8021Q, vid, 0);
2260 status = vsi->inner_vlan_ops.add_vlan(vsi, &vlan);
2262 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2266 /* Enable VLAN filtering on first non-zero VLAN */
2267 if (!vlan_promisc && vid && !ice_is_dvm_ena(&pf->hw)) {
2268 if (vsi->inner_vlan_ops.ena_rx_filtering(vsi)) {
2269 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2270 dev_err(dev, "Enable VLAN pruning on VLAN ID: %d failed error-%d\n",
2274 } else if (vlan_promisc) {
2275 status = ice_vf_ena_vlan_promisc(vsi, &vlan);
2277 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2278 dev_err(dev, "Enable Unicast/multicast promiscuous mode on VLAN ID:%d failed error-%d\n",
2284 /* In case of non_trusted VF, number of VLAN elements passed
2285 * to PF for removal might be greater than number of VLANs
2286 * filter programmed for that VF - So, use actual number of
2287 * VLANS added earlier with add VLAN opcode. In order to avoid
2288 * removing VLAN that doesn't exist, which result to sending
2289 * erroneous failed message back to the VF
2293 num_vf_vlan = vsi->num_vlan;
2294 for (i = 0; i < vfl->num_elements && i < num_vf_vlan; i++) {
2295 u16 vid = vfl->vlan_id[i];
2296 struct ice_vlan vlan;
2298 /* we add VLAN 0 by default for each VF so we can enable
2299 * Tx VLAN anti-spoof without triggering MDD events so
2300 * we don't want a VIRTCHNL request to remove it
2305 vlan = ICE_VLAN(ETH_P_8021Q, vid, 0);
2306 status = vsi->inner_vlan_ops.del_vlan(vsi, &vlan);
2308 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2312 /* Disable VLAN filtering when only VLAN 0 is left */
2313 if (!ice_vsi_has_non_zero_vlans(vsi))
2314 vsi->inner_vlan_ops.dis_rx_filtering(vsi);
2317 ice_vf_dis_vlan_promisc(vsi, &vlan);
2322 /* send the response to the VF */
2324 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_ADD_VLAN, v_ret,
2327 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_DEL_VLAN, v_ret,
2332 * ice_vc_add_vlan_msg
2333 * @vf: pointer to the VF info
2334 * @msg: pointer to the msg buffer
2336 * Add and program guest VLAN ID
2338 static int ice_vc_add_vlan_msg(struct ice_vf *vf, u8 *msg)
2340 return ice_vc_process_vlan_msg(vf, msg, true);
2344 * ice_vc_remove_vlan_msg
2345 * @vf: pointer to the VF info
2346 * @msg: pointer to the msg buffer
2348 * remove programmed guest VLAN ID
2350 static int ice_vc_remove_vlan_msg(struct ice_vf *vf, u8 *msg)
2352 return ice_vc_process_vlan_msg(vf, msg, false);
2356 * ice_vc_ena_vlan_stripping
2357 * @vf: pointer to the VF info
2359 * Enable VLAN header stripping for a given VF
2361 static int ice_vc_ena_vlan_stripping(struct ice_vf *vf)
2363 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
2364 struct ice_vsi *vsi;
2366 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
2367 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2371 if (!ice_vf_vlan_offload_ena(vf->driver_caps)) {
2372 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2376 vsi = ice_get_vf_vsi(vf);
2378 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2382 if (vsi->inner_vlan_ops.ena_stripping(vsi, ETH_P_8021Q))
2383 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2386 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_ENABLE_VLAN_STRIPPING,
2391 * ice_vc_dis_vlan_stripping
2392 * @vf: pointer to the VF info
2394 * Disable VLAN header stripping for a given VF
2396 static int ice_vc_dis_vlan_stripping(struct ice_vf *vf)
2398 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
2399 struct ice_vsi *vsi;
2401 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
2402 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2406 if (!ice_vf_vlan_offload_ena(vf->driver_caps)) {
2407 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2411 vsi = ice_get_vf_vsi(vf);
2413 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2417 if (vsi->inner_vlan_ops.dis_stripping(vsi))
2418 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2421 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_DISABLE_VLAN_STRIPPING,
2426 * ice_vf_init_vlan_stripping - enable/disable VLAN stripping on initialization
2427 * @vf: VF to enable/disable VLAN stripping for on initialization
2429 * Set the default for VLAN stripping based on whether a port VLAN is configured
2430 * and the current VLAN mode of the device.
2432 static int ice_vf_init_vlan_stripping(struct ice_vf *vf)
2434 struct ice_vsi *vsi = ice_get_vf_vsi(vf);
2439 /* don't modify stripping if port VLAN is configured in SVM since the
2440 * port VLAN is based on the inner/single VLAN in SVM
2442 if (ice_vf_is_port_vlan_ena(vf) && !ice_is_dvm_ena(&vsi->back->hw))
2445 if (ice_vf_vlan_offload_ena(vf->driver_caps))
2446 return vsi->inner_vlan_ops.ena_stripping(vsi, ETH_P_8021Q);
2448 return vsi->inner_vlan_ops.dis_stripping(vsi);
2451 static u16 ice_vc_get_max_vlan_fltrs(struct ice_vf *vf)
2456 return ICE_MAX_VLAN_PER_VF;
2460 * ice_vf_outer_vlan_not_allowed - check if outer VLAN can be used
2461 * @vf: VF that being checked for
2463 * When the device is in double VLAN mode, check whether or not the outer VLAN
2466 static bool ice_vf_outer_vlan_not_allowed(struct ice_vf *vf)
2468 if (ice_vf_is_port_vlan_ena(vf))
2475 * ice_vc_set_dvm_caps - set VLAN capabilities when the device is in DVM
2476 * @vf: VF that capabilities are being set for
2477 * @caps: VLAN capabilities to populate
2479 * Determine VLAN capabilities support based on whether a port VLAN is
2480 * configured. If a port VLAN is configured then the VF should use the inner
2481 * filtering/offload capabilities since the port VLAN is using the outer VLAN
2485 ice_vc_set_dvm_caps(struct ice_vf *vf, struct virtchnl_vlan_caps *caps)
2487 struct virtchnl_vlan_supported_caps *supported_caps;
2489 if (ice_vf_outer_vlan_not_allowed(vf)) {
2490 /* until support for inner VLAN filtering is added when a port
2491 * VLAN is configured, only support software offloaded inner
2492 * VLANs when a port VLAN is confgured in DVM
2494 supported_caps = &caps->filtering.filtering_support;
2495 supported_caps->inner = VIRTCHNL_VLAN_UNSUPPORTED;
2497 supported_caps = &caps->offloads.stripping_support;
2498 supported_caps->inner = VIRTCHNL_VLAN_ETHERTYPE_8100 |
2499 VIRTCHNL_VLAN_TOGGLE |
2500 VIRTCHNL_VLAN_TAG_LOCATION_L2TAG1;
2501 supported_caps->outer = VIRTCHNL_VLAN_UNSUPPORTED;
2503 supported_caps = &caps->offloads.insertion_support;
2504 supported_caps->inner = VIRTCHNL_VLAN_ETHERTYPE_8100 |
2505 VIRTCHNL_VLAN_TOGGLE |
2506 VIRTCHNL_VLAN_TAG_LOCATION_L2TAG1;
2507 supported_caps->outer = VIRTCHNL_VLAN_UNSUPPORTED;
2509 caps->offloads.ethertype_init = VIRTCHNL_VLAN_ETHERTYPE_8100;
2510 caps->offloads.ethertype_match =
2511 VIRTCHNL_ETHERTYPE_STRIPPING_MATCHES_INSERTION;
2513 supported_caps = &caps->filtering.filtering_support;
2514 supported_caps->inner = VIRTCHNL_VLAN_UNSUPPORTED;
2515 supported_caps->outer = VIRTCHNL_VLAN_ETHERTYPE_8100 |
2516 VIRTCHNL_VLAN_ETHERTYPE_88A8 |
2517 VIRTCHNL_VLAN_ETHERTYPE_9100 |
2518 VIRTCHNL_VLAN_ETHERTYPE_AND;
2519 caps->filtering.ethertype_init = VIRTCHNL_VLAN_ETHERTYPE_8100 |
2520 VIRTCHNL_VLAN_ETHERTYPE_88A8 |
2521 VIRTCHNL_VLAN_ETHERTYPE_9100;
2523 supported_caps = &caps->offloads.stripping_support;
2524 supported_caps->inner = VIRTCHNL_VLAN_TOGGLE |
2525 VIRTCHNL_VLAN_ETHERTYPE_8100 |
2526 VIRTCHNL_VLAN_TAG_LOCATION_L2TAG1;
2527 supported_caps->outer = VIRTCHNL_VLAN_TOGGLE |
2528 VIRTCHNL_VLAN_ETHERTYPE_8100 |
2529 VIRTCHNL_VLAN_ETHERTYPE_88A8 |
2530 VIRTCHNL_VLAN_ETHERTYPE_9100 |
2531 VIRTCHNL_VLAN_ETHERTYPE_XOR |
2532 VIRTCHNL_VLAN_TAG_LOCATION_L2TAG2_2;
2534 supported_caps = &caps->offloads.insertion_support;
2535 supported_caps->inner = VIRTCHNL_VLAN_TOGGLE |
2536 VIRTCHNL_VLAN_ETHERTYPE_8100 |
2537 VIRTCHNL_VLAN_TAG_LOCATION_L2TAG1;
2538 supported_caps->outer = VIRTCHNL_VLAN_TOGGLE |
2539 VIRTCHNL_VLAN_ETHERTYPE_8100 |
2540 VIRTCHNL_VLAN_ETHERTYPE_88A8 |
2541 VIRTCHNL_VLAN_ETHERTYPE_9100 |
2542 VIRTCHNL_VLAN_ETHERTYPE_XOR |
2543 VIRTCHNL_VLAN_TAG_LOCATION_L2TAG2;
2545 caps->offloads.ethertype_init = VIRTCHNL_VLAN_ETHERTYPE_8100;
2547 caps->offloads.ethertype_match =
2548 VIRTCHNL_ETHERTYPE_STRIPPING_MATCHES_INSERTION;
2551 caps->filtering.max_filters = ice_vc_get_max_vlan_fltrs(vf);
2555 * ice_vc_set_svm_caps - set VLAN capabilities when the device is in SVM
2556 * @vf: VF that capabilities are being set for
2557 * @caps: VLAN capabilities to populate
2559 * Determine VLAN capabilities support based on whether a port VLAN is
2560 * configured. If a port VLAN is configured then the VF does not have any VLAN
2561 * filtering or offload capabilities since the port VLAN is using the inner VLAN
2562 * capabilities in single VLAN mode (SVM). Otherwise allow the VF to use inner
2563 * VLAN fitlering and offload capabilities.
2566 ice_vc_set_svm_caps(struct ice_vf *vf, struct virtchnl_vlan_caps *caps)
2568 struct virtchnl_vlan_supported_caps *supported_caps;
2570 if (ice_vf_is_port_vlan_ena(vf)) {
2571 supported_caps = &caps->filtering.filtering_support;
2572 supported_caps->inner = VIRTCHNL_VLAN_UNSUPPORTED;
2573 supported_caps->outer = VIRTCHNL_VLAN_UNSUPPORTED;
2575 supported_caps = &caps->offloads.stripping_support;
2576 supported_caps->inner = VIRTCHNL_VLAN_UNSUPPORTED;
2577 supported_caps->outer = VIRTCHNL_VLAN_UNSUPPORTED;
2579 supported_caps = &caps->offloads.insertion_support;
2580 supported_caps->inner = VIRTCHNL_VLAN_UNSUPPORTED;
2581 supported_caps->outer = VIRTCHNL_VLAN_UNSUPPORTED;
2583 caps->offloads.ethertype_init = VIRTCHNL_VLAN_UNSUPPORTED;
2584 caps->offloads.ethertype_match = VIRTCHNL_VLAN_UNSUPPORTED;
2585 caps->filtering.max_filters = 0;
2587 supported_caps = &caps->filtering.filtering_support;
2588 supported_caps->inner = VIRTCHNL_VLAN_ETHERTYPE_8100;
2589 supported_caps->outer = VIRTCHNL_VLAN_UNSUPPORTED;
2590 caps->filtering.ethertype_init = VIRTCHNL_VLAN_ETHERTYPE_8100;
2592 supported_caps = &caps->offloads.stripping_support;
2593 supported_caps->inner = VIRTCHNL_VLAN_ETHERTYPE_8100 |
2594 VIRTCHNL_VLAN_TOGGLE |
2595 VIRTCHNL_VLAN_TAG_LOCATION_L2TAG1;
2596 supported_caps->outer = VIRTCHNL_VLAN_UNSUPPORTED;
2598 supported_caps = &caps->offloads.insertion_support;
2599 supported_caps->inner = VIRTCHNL_VLAN_ETHERTYPE_8100 |
2600 VIRTCHNL_VLAN_TOGGLE |
2601 VIRTCHNL_VLAN_TAG_LOCATION_L2TAG1;
2602 supported_caps->outer = VIRTCHNL_VLAN_UNSUPPORTED;
2604 caps->offloads.ethertype_init = VIRTCHNL_VLAN_ETHERTYPE_8100;
2605 caps->offloads.ethertype_match =
2606 VIRTCHNL_ETHERTYPE_STRIPPING_MATCHES_INSERTION;
2607 caps->filtering.max_filters = ice_vc_get_max_vlan_fltrs(vf);
2612 * ice_vc_get_offload_vlan_v2_caps - determine VF's VLAN capabilities
2613 * @vf: VF to determine VLAN capabilities for
2615 * This will only be called if the VF and PF successfully negotiated
2616 * VIRTCHNL_VF_OFFLOAD_VLAN_V2.
2618 * Set VLAN capabilities based on the current VLAN mode and whether a port VLAN
2619 * is configured or not.
2621 static int ice_vc_get_offload_vlan_v2_caps(struct ice_vf *vf)
2623 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
2624 struct virtchnl_vlan_caps *caps = NULL;
2627 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
2628 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2632 caps = kzalloc(sizeof(*caps), GFP_KERNEL);
2634 v_ret = VIRTCHNL_STATUS_ERR_NO_MEMORY;
2637 len = sizeof(*caps);
2639 if (ice_is_dvm_ena(&vf->pf->hw))
2640 ice_vc_set_dvm_caps(vf, caps);
2642 ice_vc_set_svm_caps(vf, caps);
2644 /* store negotiated caps to prevent invalid VF messages */
2645 memcpy(&vf->vlan_v2_caps, caps, sizeof(*caps));
2648 err = ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS,
2649 v_ret, (u8 *)caps, len);
2655 * ice_vc_validate_vlan_tpid - validate VLAN TPID
2656 * @filtering_caps: negotiated/supported VLAN filtering capabilities
2657 * @tpid: VLAN TPID used for validation
2659 * Convert the VLAN TPID to a VIRTCHNL_VLAN_ETHERTYPE_* and then compare against
2660 * the negotiated/supported filtering caps to see if the VLAN TPID is valid.
2662 static bool ice_vc_validate_vlan_tpid(u16 filtering_caps, u16 tpid)
2664 enum virtchnl_vlan_support vlan_ethertype = VIRTCHNL_VLAN_UNSUPPORTED;
2668 vlan_ethertype = VIRTCHNL_VLAN_ETHERTYPE_8100;
2671 vlan_ethertype = VIRTCHNL_VLAN_ETHERTYPE_88A8;
2674 vlan_ethertype = VIRTCHNL_VLAN_ETHERTYPE_9100;
2678 if (!(filtering_caps & vlan_ethertype))
2685 * ice_vc_is_valid_vlan - validate the virtchnl_vlan
2686 * @vc_vlan: virtchnl_vlan to validate
2688 * If the VLAN TCI and VLAN TPID are 0, then this filter is invalid, so return
2689 * false. Otherwise return true.
2691 static bool ice_vc_is_valid_vlan(struct virtchnl_vlan *vc_vlan)
2693 if (!vc_vlan->tci || !vc_vlan->tpid)
2700 * ice_vc_validate_vlan_filter_list - validate the filter list from the VF
2701 * @vfc: negotiated/supported VLAN filtering capabilities
2702 * @vfl: VLAN filter list from VF to validate
2704 * Validate all of the filters in the VLAN filter list from the VF. If any of
2705 * the checks fail then return false. Otherwise return true.
2708 ice_vc_validate_vlan_filter_list(struct virtchnl_vlan_filtering_caps *vfc,
2709 struct virtchnl_vlan_filter_list_v2 *vfl)
2713 if (!vfl->num_elements)
2716 for (i = 0; i < vfl->num_elements; i++) {
2717 struct virtchnl_vlan_supported_caps *filtering_support =
2718 &vfc->filtering_support;
2719 struct virtchnl_vlan_filter *vlan_fltr = &vfl->filters[i];
2720 struct virtchnl_vlan *outer = &vlan_fltr->outer;
2721 struct virtchnl_vlan *inner = &vlan_fltr->inner;
2723 if ((ice_vc_is_valid_vlan(outer) &&
2724 filtering_support->outer == VIRTCHNL_VLAN_UNSUPPORTED) ||
2725 (ice_vc_is_valid_vlan(inner) &&
2726 filtering_support->inner == VIRTCHNL_VLAN_UNSUPPORTED))
2729 if ((outer->tci_mask &&
2730 !(filtering_support->outer & VIRTCHNL_VLAN_FILTER_MASK)) ||
2732 !(filtering_support->inner & VIRTCHNL_VLAN_FILTER_MASK)))
2735 if (((outer->tci & VLAN_PRIO_MASK) &&
2736 !(filtering_support->outer & VIRTCHNL_VLAN_PRIO)) ||
2737 ((inner->tci & VLAN_PRIO_MASK) &&
2738 !(filtering_support->inner & VIRTCHNL_VLAN_PRIO)))
2741 if ((ice_vc_is_valid_vlan(outer) &&
2742 !ice_vc_validate_vlan_tpid(filtering_support->outer,
2744 (ice_vc_is_valid_vlan(inner) &&
2745 !ice_vc_validate_vlan_tpid(filtering_support->inner,
2754 * ice_vc_to_vlan - transform from struct virtchnl_vlan to struct ice_vlan
2755 * @vc_vlan: struct virtchnl_vlan to transform
2757 static struct ice_vlan ice_vc_to_vlan(struct virtchnl_vlan *vc_vlan)
2759 struct ice_vlan vlan = { 0 };
2761 vlan.prio = (vc_vlan->tci & VLAN_PRIO_MASK) >> VLAN_PRIO_SHIFT;
2762 vlan.vid = vc_vlan->tci & VLAN_VID_MASK;
2763 vlan.tpid = vc_vlan->tpid;
2769 * ice_vc_vlan_action - action to perform on the virthcnl_vlan
2770 * @vsi: VF's VSI used to perform the action
2771 * @vlan_action: function to perform the action with (i.e. add/del)
2772 * @vlan: VLAN filter to perform the action with
2775 ice_vc_vlan_action(struct ice_vsi *vsi,
2776 int (*vlan_action)(struct ice_vsi *, struct ice_vlan *),
2777 struct ice_vlan *vlan)
2781 err = vlan_action(vsi, vlan);
2789 * ice_vc_del_vlans - delete VLAN(s) from the virtchnl filter list
2790 * @vf: VF used to delete the VLAN(s)
2791 * @vsi: VF's VSI used to delete the VLAN(s)
2792 * @vfl: virthchnl filter list used to delete the filters
2795 ice_vc_del_vlans(struct ice_vf *vf, struct ice_vsi *vsi,
2796 struct virtchnl_vlan_filter_list_v2 *vfl)
2798 bool vlan_promisc = ice_is_vlan_promisc_allowed(vf);
2802 for (i = 0; i < vfl->num_elements; i++) {
2803 struct virtchnl_vlan_filter *vlan_fltr = &vfl->filters[i];
2804 struct virtchnl_vlan *vc_vlan;
2806 vc_vlan = &vlan_fltr->outer;
2807 if (ice_vc_is_valid_vlan(vc_vlan)) {
2808 struct ice_vlan vlan = ice_vc_to_vlan(vc_vlan);
2810 err = ice_vc_vlan_action(vsi,
2811 vsi->outer_vlan_ops.del_vlan,
2817 ice_vf_dis_vlan_promisc(vsi, &vlan);
2820 vc_vlan = &vlan_fltr->inner;
2821 if (ice_vc_is_valid_vlan(vc_vlan)) {
2822 struct ice_vlan vlan = ice_vc_to_vlan(vc_vlan);
2824 err = ice_vc_vlan_action(vsi,
2825 vsi->inner_vlan_ops.del_vlan,
2830 /* no support for VLAN promiscuous on inner VLAN unless
2831 * we are in Single VLAN Mode (SVM)
2833 if (!ice_is_dvm_ena(&vsi->back->hw) && vlan_promisc)
2834 ice_vf_dis_vlan_promisc(vsi, &vlan);
2842 * ice_vc_remove_vlan_v2_msg - virtchnl handler for VIRTCHNL_OP_DEL_VLAN_V2
2843 * @vf: VF the message was received from
2844 * @msg: message received from the VF
2846 static int ice_vc_remove_vlan_v2_msg(struct ice_vf *vf, u8 *msg)
2848 struct virtchnl_vlan_filter_list_v2 *vfl =
2849 (struct virtchnl_vlan_filter_list_v2 *)msg;
2850 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
2851 struct ice_vsi *vsi;
2853 if (!ice_vc_validate_vlan_filter_list(&vf->vlan_v2_caps.filtering,
2855 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2859 if (!ice_vc_isvalid_vsi_id(vf, vfl->vport_id)) {
2860 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2864 vsi = ice_get_vf_vsi(vf);
2866 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2870 if (ice_vc_del_vlans(vf, vsi, vfl))
2871 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2874 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_DEL_VLAN_V2, v_ret, NULL,
2879 * ice_vc_add_vlans - add VLAN(s) from the virtchnl filter list
2880 * @vf: VF used to add the VLAN(s)
2881 * @vsi: VF's VSI used to add the VLAN(s)
2882 * @vfl: virthchnl filter list used to add the filters
2885 ice_vc_add_vlans(struct ice_vf *vf, struct ice_vsi *vsi,
2886 struct virtchnl_vlan_filter_list_v2 *vfl)
2888 bool vlan_promisc = ice_is_vlan_promisc_allowed(vf);
2892 for (i = 0; i < vfl->num_elements; i++) {
2893 struct virtchnl_vlan_filter *vlan_fltr = &vfl->filters[i];
2894 struct virtchnl_vlan *vc_vlan;
2896 vc_vlan = &vlan_fltr->outer;
2897 if (ice_vc_is_valid_vlan(vc_vlan)) {
2898 struct ice_vlan vlan = ice_vc_to_vlan(vc_vlan);
2900 err = ice_vc_vlan_action(vsi,
2901 vsi->outer_vlan_ops.add_vlan,
2907 err = ice_vf_ena_vlan_promisc(vsi, &vlan);
2913 vc_vlan = &vlan_fltr->inner;
2914 if (ice_vc_is_valid_vlan(vc_vlan)) {
2915 struct ice_vlan vlan = ice_vc_to_vlan(vc_vlan);
2917 err = ice_vc_vlan_action(vsi,
2918 vsi->inner_vlan_ops.add_vlan,
2923 /* no support for VLAN promiscuous on inner VLAN unless
2924 * we are in Single VLAN Mode (SVM)
2926 if (!ice_is_dvm_ena(&vsi->back->hw) && vlan_promisc) {
2927 err = ice_vf_ena_vlan_promisc(vsi, &vlan);
2938 * ice_vc_validate_add_vlan_filter_list - validate add filter list from the VF
2939 * @vsi: VF VSI used to get number of existing VLAN filters
2940 * @vfc: negotiated/supported VLAN filtering capabilities
2941 * @vfl: VLAN filter list from VF to validate
2943 * Validate all of the filters in the VLAN filter list from the VF during the
2944 * VIRTCHNL_OP_ADD_VLAN_V2 opcode. If any of the checks fail then return false.
2945 * Otherwise return true.
2948 ice_vc_validate_add_vlan_filter_list(struct ice_vsi *vsi,
2949 struct virtchnl_vlan_filtering_caps *vfc,
2950 struct virtchnl_vlan_filter_list_v2 *vfl)
2952 u16 num_requested_filters = vsi->num_vlan + vfl->num_elements;
2954 if (num_requested_filters > vfc->max_filters)
2957 return ice_vc_validate_vlan_filter_list(vfc, vfl);
2961 * ice_vc_add_vlan_v2_msg - virtchnl handler for VIRTCHNL_OP_ADD_VLAN_V2
2962 * @vf: VF the message was received from
2963 * @msg: message received from the VF
2965 static int ice_vc_add_vlan_v2_msg(struct ice_vf *vf, u8 *msg)
2967 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
2968 struct virtchnl_vlan_filter_list_v2 *vfl =
2969 (struct virtchnl_vlan_filter_list_v2 *)msg;
2970 struct ice_vsi *vsi;
2972 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
2973 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2977 if (!ice_vc_isvalid_vsi_id(vf, vfl->vport_id)) {
2978 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2982 vsi = ice_get_vf_vsi(vf);
2984 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2988 if (!ice_vc_validate_add_vlan_filter_list(vsi,
2989 &vf->vlan_v2_caps.filtering,
2991 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2995 if (ice_vc_add_vlans(vf, vsi, vfl))
2996 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2999 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_ADD_VLAN_V2, v_ret, NULL,
3004 * ice_vc_valid_vlan_setting - validate VLAN setting
3005 * @negotiated_settings: negotiated VLAN settings during VF init
3006 * @ethertype_setting: ethertype(s) requested for the VLAN setting
3009 ice_vc_valid_vlan_setting(u32 negotiated_settings, u32 ethertype_setting)
3011 if (ethertype_setting && !(negotiated_settings & ethertype_setting))
3014 /* only allow a single VIRTCHNL_VLAN_ETHERTYPE if
3015 * VIRTHCNL_VLAN_ETHERTYPE_AND is not negotiated/supported
3017 if (!(negotiated_settings & VIRTCHNL_VLAN_ETHERTYPE_AND) &&
3018 hweight32(ethertype_setting) > 1)
3021 /* ability to modify the VLAN setting was not negotiated */
3022 if (!(negotiated_settings & VIRTCHNL_VLAN_TOGGLE))
3029 * ice_vc_valid_vlan_setting_msg - validate the VLAN setting message
3030 * @caps: negotiated VLAN settings during VF init
3031 * @msg: message to validate
3033 * Used to validate any VLAN virtchnl message sent as a
3034 * virtchnl_vlan_setting structure. Validates the message against the
3035 * negotiated/supported caps during VF driver init.
3038 ice_vc_valid_vlan_setting_msg(struct virtchnl_vlan_supported_caps *caps,
3039 struct virtchnl_vlan_setting *msg)
3041 if ((!msg->outer_ethertype_setting &&
3042 !msg->inner_ethertype_setting) ||
3043 (!caps->outer && !caps->inner))
3046 if (msg->outer_ethertype_setting &&
3047 !ice_vc_valid_vlan_setting(caps->outer,
3048 msg->outer_ethertype_setting))
3051 if (msg->inner_ethertype_setting &&
3052 !ice_vc_valid_vlan_setting(caps->inner,
3053 msg->inner_ethertype_setting))
3060 * ice_vc_get_tpid - transform from VIRTCHNL_VLAN_ETHERTYPE_* to VLAN TPID
3061 * @ethertype_setting: VIRTCHNL_VLAN_ETHERTYPE_* used to get VLAN TPID
3062 * @tpid: VLAN TPID to populate
3064 static int ice_vc_get_tpid(u32 ethertype_setting, u16 *tpid)
3066 switch (ethertype_setting) {
3067 case VIRTCHNL_VLAN_ETHERTYPE_8100:
3068 *tpid = ETH_P_8021Q;
3070 case VIRTCHNL_VLAN_ETHERTYPE_88A8:
3071 *tpid = ETH_P_8021AD;
3073 case VIRTCHNL_VLAN_ETHERTYPE_9100:
3074 *tpid = ETH_P_QINQ1;
3085 * ice_vc_ena_vlan_offload - enable VLAN offload based on the ethertype_setting
3086 * @vsi: VF's VSI used to enable the VLAN offload
3087 * @ena_offload: function used to enable the VLAN offload
3088 * @ethertype_setting: VIRTCHNL_VLAN_ETHERTYPE_* to enable offloads for
3091 ice_vc_ena_vlan_offload(struct ice_vsi *vsi,
3092 int (*ena_offload)(struct ice_vsi *vsi, u16 tpid),
3093 u32 ethertype_setting)
3098 err = ice_vc_get_tpid(ethertype_setting, &tpid);
3102 err = ena_offload(vsi, tpid);
3109 #define ICE_L2TSEL_QRX_CONTEXT_REG_IDX 3
3110 #define ICE_L2TSEL_BIT_OFFSET 23
3112 ICE_L2TSEL_EXTRACT_FIRST_TAG_L2TAG2_2ND,
3113 ICE_L2TSEL_EXTRACT_FIRST_TAG_L2TAG1,
3117 * ice_vsi_update_l2tsel - update l2tsel field for all Rx rings on this VSI
3118 * @vsi: VSI used to update l2tsel on
3119 * @l2tsel: l2tsel setting requested
3121 * Use the l2tsel setting to update all of the Rx queue context bits for l2tsel.
3122 * This will modify which descriptor field the first offloaded VLAN will be
3125 static void ice_vsi_update_l2tsel(struct ice_vsi *vsi, enum ice_l2tsel l2tsel)
3127 struct ice_hw *hw = &vsi->back->hw;
3131 if (l2tsel == ICE_L2TSEL_EXTRACT_FIRST_TAG_L2TAG2_2ND)
3134 l2tsel_bit = BIT(ICE_L2TSEL_BIT_OFFSET);
3136 for (i = 0; i < vsi->alloc_rxq; i++) {
3137 u16 pfq = vsi->rxq_map[i];
3138 u32 qrx_context_offset;
3141 qrx_context_offset =
3142 QRX_CONTEXT(ICE_L2TSEL_QRX_CONTEXT_REG_IDX, pfq);
3144 regval = rd32(hw, qrx_context_offset);
3145 regval &= ~BIT(ICE_L2TSEL_BIT_OFFSET);
3146 regval |= l2tsel_bit;
3147 wr32(hw, qrx_context_offset, regval);
3152 * ice_vc_ena_vlan_stripping_v2_msg
3153 * @vf: VF the message was received from
3154 * @msg: message received from the VF
3156 * virthcnl handler for VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2
3158 static int ice_vc_ena_vlan_stripping_v2_msg(struct ice_vf *vf, u8 *msg)
3160 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
3161 struct virtchnl_vlan_supported_caps *stripping_support;
3162 struct virtchnl_vlan_setting *strip_msg =
3163 (struct virtchnl_vlan_setting *)msg;
3164 u32 ethertype_setting;
3165 struct ice_vsi *vsi;
3167 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
3168 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3172 if (!ice_vc_isvalid_vsi_id(vf, strip_msg->vport_id)) {
3173 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3177 vsi = ice_get_vf_vsi(vf);
3179 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3183 stripping_support = &vf->vlan_v2_caps.offloads.stripping_support;
3184 if (!ice_vc_valid_vlan_setting_msg(stripping_support, strip_msg)) {
3185 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3189 ethertype_setting = strip_msg->outer_ethertype_setting;
3190 if (ethertype_setting) {
3191 if (ice_vc_ena_vlan_offload(vsi,
3192 vsi->outer_vlan_ops.ena_stripping,
3193 ethertype_setting)) {
3194 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3197 enum ice_l2tsel l2tsel =
3198 ICE_L2TSEL_EXTRACT_FIRST_TAG_L2TAG2_2ND;
3200 /* PF tells the VF that the outer VLAN tag is always
3201 * extracted to VIRTCHNL_VLAN_TAG_LOCATION_L2TAG2_2 and
3202 * inner is always extracted to
3203 * VIRTCHNL_VLAN_TAG_LOCATION_L2TAG1. This is needed to
3204 * support outer stripping so the first tag always ends
3205 * up in L2TAG2_2ND and the second/inner tag, if
3206 * enabled, is extracted in L2TAG1.
3208 ice_vsi_update_l2tsel(vsi, l2tsel);
3212 ethertype_setting = strip_msg->inner_ethertype_setting;
3213 if (ethertype_setting &&
3214 ice_vc_ena_vlan_offload(vsi, vsi->inner_vlan_ops.ena_stripping,
3215 ethertype_setting)) {
3216 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3221 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2,
3226 * ice_vc_dis_vlan_stripping_v2_msg
3227 * @vf: VF the message was received from
3228 * @msg: message received from the VF
3230 * virthcnl handler for VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2
3232 static int ice_vc_dis_vlan_stripping_v2_msg(struct ice_vf *vf, u8 *msg)
3234 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
3235 struct virtchnl_vlan_supported_caps *stripping_support;
3236 struct virtchnl_vlan_setting *strip_msg =
3237 (struct virtchnl_vlan_setting *)msg;
3238 u32 ethertype_setting;
3239 struct ice_vsi *vsi;
3241 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
3242 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3246 if (!ice_vc_isvalid_vsi_id(vf, strip_msg->vport_id)) {
3247 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3251 vsi = ice_get_vf_vsi(vf);
3253 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3257 stripping_support = &vf->vlan_v2_caps.offloads.stripping_support;
3258 if (!ice_vc_valid_vlan_setting_msg(stripping_support, strip_msg)) {
3259 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3263 ethertype_setting = strip_msg->outer_ethertype_setting;
3264 if (ethertype_setting) {
3265 if (vsi->outer_vlan_ops.dis_stripping(vsi)) {
3266 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3269 enum ice_l2tsel l2tsel =
3270 ICE_L2TSEL_EXTRACT_FIRST_TAG_L2TAG1;
3272 /* PF tells the VF that the outer VLAN tag is always
3273 * extracted to VIRTCHNL_VLAN_TAG_LOCATION_L2TAG2_2 and
3274 * inner is always extracted to
3275 * VIRTCHNL_VLAN_TAG_LOCATION_L2TAG1. This is needed to
3276 * support inner stripping while outer stripping is
3277 * disabled so that the first and only tag is extracted
3280 ice_vsi_update_l2tsel(vsi, l2tsel);
3284 ethertype_setting = strip_msg->inner_ethertype_setting;
3285 if (ethertype_setting && vsi->inner_vlan_ops.dis_stripping(vsi)) {
3286 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3291 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2,
3296 * ice_vc_ena_vlan_insertion_v2_msg
3297 * @vf: VF the message was received from
3298 * @msg: message received from the VF
3300 * virthcnl handler for VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2
3302 static int ice_vc_ena_vlan_insertion_v2_msg(struct ice_vf *vf, u8 *msg)
3304 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
3305 struct virtchnl_vlan_supported_caps *insertion_support;
3306 struct virtchnl_vlan_setting *insertion_msg =
3307 (struct virtchnl_vlan_setting *)msg;
3308 u32 ethertype_setting;
3309 struct ice_vsi *vsi;
3311 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
3312 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3316 if (!ice_vc_isvalid_vsi_id(vf, insertion_msg->vport_id)) {
3317 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3321 vsi = ice_get_vf_vsi(vf);
3323 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3327 insertion_support = &vf->vlan_v2_caps.offloads.insertion_support;
3328 if (!ice_vc_valid_vlan_setting_msg(insertion_support, insertion_msg)) {
3329 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3333 ethertype_setting = insertion_msg->outer_ethertype_setting;
3334 if (ethertype_setting &&
3335 ice_vc_ena_vlan_offload(vsi, vsi->outer_vlan_ops.ena_insertion,
3336 ethertype_setting)) {
3337 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3341 ethertype_setting = insertion_msg->inner_ethertype_setting;
3342 if (ethertype_setting &&
3343 ice_vc_ena_vlan_offload(vsi, vsi->inner_vlan_ops.ena_insertion,
3344 ethertype_setting)) {
3345 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3350 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2,
3355 * ice_vc_dis_vlan_insertion_v2_msg
3356 * @vf: VF the message was received from
3357 * @msg: message received from the VF
3359 * virthcnl handler for VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2
3361 static int ice_vc_dis_vlan_insertion_v2_msg(struct ice_vf *vf, u8 *msg)
3363 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
3364 struct virtchnl_vlan_supported_caps *insertion_support;
3365 struct virtchnl_vlan_setting *insertion_msg =
3366 (struct virtchnl_vlan_setting *)msg;
3367 u32 ethertype_setting;
3368 struct ice_vsi *vsi;
3370 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
3371 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3375 if (!ice_vc_isvalid_vsi_id(vf, insertion_msg->vport_id)) {
3376 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3380 vsi = ice_get_vf_vsi(vf);
3382 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3386 insertion_support = &vf->vlan_v2_caps.offloads.insertion_support;
3387 if (!ice_vc_valid_vlan_setting_msg(insertion_support, insertion_msg)) {
3388 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3392 ethertype_setting = insertion_msg->outer_ethertype_setting;
3393 if (ethertype_setting && vsi->outer_vlan_ops.dis_insertion(vsi)) {
3394 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3398 ethertype_setting = insertion_msg->inner_ethertype_setting;
3399 if (ethertype_setting && vsi->inner_vlan_ops.dis_insertion(vsi)) {
3400 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3405 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2,
3409 static const struct ice_virtchnl_ops ice_virtchnl_dflt_ops = {
3410 .get_ver_msg = ice_vc_get_ver_msg,
3411 .get_vf_res_msg = ice_vc_get_vf_res_msg,
3412 .reset_vf = ice_vc_reset_vf_msg,
3413 .add_mac_addr_msg = ice_vc_add_mac_addr_msg,
3414 .del_mac_addr_msg = ice_vc_del_mac_addr_msg,
3415 .cfg_qs_msg = ice_vc_cfg_qs_msg,
3416 .ena_qs_msg = ice_vc_ena_qs_msg,
3417 .dis_qs_msg = ice_vc_dis_qs_msg,
3418 .request_qs_msg = ice_vc_request_qs_msg,
3419 .cfg_irq_map_msg = ice_vc_cfg_irq_map_msg,
3420 .config_rss_key = ice_vc_config_rss_key,
3421 .config_rss_lut = ice_vc_config_rss_lut,
3422 .get_stats_msg = ice_vc_get_stats_msg,
3423 .cfg_promiscuous_mode_msg = ice_vc_cfg_promiscuous_mode_msg,
3424 .add_vlan_msg = ice_vc_add_vlan_msg,
3425 .remove_vlan_msg = ice_vc_remove_vlan_msg,
3426 .ena_vlan_stripping = ice_vc_ena_vlan_stripping,
3427 .dis_vlan_stripping = ice_vc_dis_vlan_stripping,
3428 .handle_rss_cfg_msg = ice_vc_handle_rss_cfg,
3429 .add_fdir_fltr_msg = ice_vc_add_fdir_fltr,
3430 .del_fdir_fltr_msg = ice_vc_del_fdir_fltr,
3431 .get_offload_vlan_v2_caps = ice_vc_get_offload_vlan_v2_caps,
3432 .add_vlan_v2_msg = ice_vc_add_vlan_v2_msg,
3433 .remove_vlan_v2_msg = ice_vc_remove_vlan_v2_msg,
3434 .ena_vlan_stripping_v2_msg = ice_vc_ena_vlan_stripping_v2_msg,
3435 .dis_vlan_stripping_v2_msg = ice_vc_dis_vlan_stripping_v2_msg,
3436 .ena_vlan_insertion_v2_msg = ice_vc_ena_vlan_insertion_v2_msg,
3437 .dis_vlan_insertion_v2_msg = ice_vc_dis_vlan_insertion_v2_msg,
3441 * ice_virtchnl_set_dflt_ops - Switch to default virtchnl ops
3442 * @vf: the VF to switch ops
3444 void ice_virtchnl_set_dflt_ops(struct ice_vf *vf)
3446 vf->virtchnl_ops = &ice_virtchnl_dflt_ops;
3450 * ice_vc_repr_add_mac
3451 * @vf: pointer to VF
3452 * @msg: virtchannel message
3454 * When port representors are created, we do not add MAC rule
3455 * to firmware, we store it so that PF could report same
3458 static int ice_vc_repr_add_mac(struct ice_vf *vf, u8 *msg)
3460 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
3461 struct virtchnl_ether_addr_list *al =
3462 (struct virtchnl_ether_addr_list *)msg;
3463 struct ice_vsi *vsi;
3467 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states) ||
3468 !ice_vc_isvalid_vsi_id(vf, al->vsi_id)) {
3469 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3470 goto handle_mac_exit;
3475 vsi = ice_get_vf_vsi(vf);
3477 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3478 goto handle_mac_exit;
3481 for (i = 0; i < al->num_elements; i++) {
3482 u8 *mac_addr = al->list[i].addr;
3485 if (!is_unicast_ether_addr(mac_addr) ||
3486 ether_addr_equal(mac_addr, vf->hw_lan_addr.addr))
3489 if (vf->pf_set_mac) {
3490 dev_err(ice_pf_to_dev(pf), "VF attempting to override administratively set MAC address\n");
3491 v_ret = VIRTCHNL_STATUS_ERR_NOT_SUPPORTED;
3492 goto handle_mac_exit;
3495 result = ice_eswitch_add_vf_mac_rule(pf, vf, mac_addr);
3497 dev_err(ice_pf_to_dev(pf), "Failed to add MAC %pM for VF %d\n, error %d\n",
3498 mac_addr, vf->vf_id, result);
3499 goto handle_mac_exit;
3502 ice_vfhw_mac_add(vf, &al->list[i]);
3508 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_ADD_ETH_ADDR,
3513 * ice_vc_repr_del_mac - response with success for deleting MAC
3514 * @vf: pointer to VF
3515 * @msg: virtchannel message
3517 * Respond with success to not break normal VF flow.
3518 * For legacy VF driver try to update cached MAC address.
3521 ice_vc_repr_del_mac(struct ice_vf __always_unused *vf, u8 __always_unused *msg)
3523 struct virtchnl_ether_addr_list *al =
3524 (struct virtchnl_ether_addr_list *)msg;
3526 ice_update_legacy_cached_mac(vf, &al->list[0]);
3528 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_DEL_ETH_ADDR,
3529 VIRTCHNL_STATUS_SUCCESS, NULL, 0);
3532 static int ice_vc_repr_add_vlan(struct ice_vf *vf, u8 __always_unused *msg)
3534 dev_dbg(ice_pf_to_dev(vf->pf),
3535 "Can't add VLAN in switchdev mode for VF %d\n", vf->vf_id);
3536 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_ADD_VLAN,
3537 VIRTCHNL_STATUS_SUCCESS, NULL, 0);
3540 static int ice_vc_repr_del_vlan(struct ice_vf *vf, u8 __always_unused *msg)
3542 dev_dbg(ice_pf_to_dev(vf->pf),
3543 "Can't delete VLAN in switchdev mode for VF %d\n", vf->vf_id);
3544 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_DEL_VLAN,
3545 VIRTCHNL_STATUS_SUCCESS, NULL, 0);
3548 static int ice_vc_repr_ena_vlan_stripping(struct ice_vf *vf)
3550 dev_dbg(ice_pf_to_dev(vf->pf),
3551 "Can't enable VLAN stripping in switchdev mode for VF %d\n",
3553 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_ENABLE_VLAN_STRIPPING,
3554 VIRTCHNL_STATUS_ERR_NOT_SUPPORTED,
3558 static int ice_vc_repr_dis_vlan_stripping(struct ice_vf *vf)
3560 dev_dbg(ice_pf_to_dev(vf->pf),
3561 "Can't disable VLAN stripping in switchdev mode for VF %d\n",
3563 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_DISABLE_VLAN_STRIPPING,
3564 VIRTCHNL_STATUS_ERR_NOT_SUPPORTED,
3569 ice_vc_repr_cfg_promiscuous_mode(struct ice_vf *vf, u8 __always_unused *msg)
3571 dev_dbg(ice_pf_to_dev(vf->pf),
3572 "Can't config promiscuous mode in switchdev mode for VF %d\n",
3574 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE,
3575 VIRTCHNL_STATUS_ERR_NOT_SUPPORTED,
3579 static const struct ice_virtchnl_ops ice_virtchnl_repr_ops = {
3580 .get_ver_msg = ice_vc_get_ver_msg,
3581 .get_vf_res_msg = ice_vc_get_vf_res_msg,
3582 .reset_vf = ice_vc_reset_vf_msg,
3583 .add_mac_addr_msg = ice_vc_repr_add_mac,
3584 .del_mac_addr_msg = ice_vc_repr_del_mac,
3585 .cfg_qs_msg = ice_vc_cfg_qs_msg,
3586 .ena_qs_msg = ice_vc_ena_qs_msg,
3587 .dis_qs_msg = ice_vc_dis_qs_msg,
3588 .request_qs_msg = ice_vc_request_qs_msg,
3589 .cfg_irq_map_msg = ice_vc_cfg_irq_map_msg,
3590 .config_rss_key = ice_vc_config_rss_key,
3591 .config_rss_lut = ice_vc_config_rss_lut,
3592 .get_stats_msg = ice_vc_get_stats_msg,
3593 .cfg_promiscuous_mode_msg = ice_vc_repr_cfg_promiscuous_mode,
3594 .add_vlan_msg = ice_vc_repr_add_vlan,
3595 .remove_vlan_msg = ice_vc_repr_del_vlan,
3596 .ena_vlan_stripping = ice_vc_repr_ena_vlan_stripping,
3597 .dis_vlan_stripping = ice_vc_repr_dis_vlan_stripping,
3598 .handle_rss_cfg_msg = ice_vc_handle_rss_cfg,
3599 .add_fdir_fltr_msg = ice_vc_add_fdir_fltr,
3600 .del_fdir_fltr_msg = ice_vc_del_fdir_fltr,
3601 .get_offload_vlan_v2_caps = ice_vc_get_offload_vlan_v2_caps,
3602 .add_vlan_v2_msg = ice_vc_add_vlan_v2_msg,
3603 .remove_vlan_v2_msg = ice_vc_remove_vlan_v2_msg,
3604 .ena_vlan_stripping_v2_msg = ice_vc_ena_vlan_stripping_v2_msg,
3605 .dis_vlan_stripping_v2_msg = ice_vc_dis_vlan_stripping_v2_msg,
3606 .ena_vlan_insertion_v2_msg = ice_vc_ena_vlan_insertion_v2_msg,
3607 .dis_vlan_insertion_v2_msg = ice_vc_dis_vlan_insertion_v2_msg,
3611 * ice_virtchnl_set_repr_ops - Switch to representor virtchnl ops
3612 * @vf: the VF to switch ops
3614 void ice_virtchnl_set_repr_ops(struct ice_vf *vf)
3616 vf->virtchnl_ops = &ice_virtchnl_repr_ops;
3620 * ice_vc_process_vf_msg - Process request from VF
3621 * @pf: pointer to the PF structure
3622 * @event: pointer to the AQ event
3624 * called from the common asq/arq handler to
3625 * process request from VF
3627 void ice_vc_process_vf_msg(struct ice_pf *pf, struct ice_rq_event_info *event)
3629 u32 v_opcode = le32_to_cpu(event->desc.cookie_high);
3630 s16 vf_id = le16_to_cpu(event->desc.retval);
3631 const struct ice_virtchnl_ops *ops;
3632 u16 msglen = event->msg_len;
3633 u8 *msg = event->msg_buf;
3634 struct ice_vf *vf = NULL;
3638 dev = ice_pf_to_dev(pf);
3640 vf = ice_get_vf_by_id(pf, vf_id);
3642 dev_err(dev, "Unable to locate VF for message from VF ID %d, opcode %d, len %d\n",
3643 vf_id, v_opcode, msglen);
3647 mutex_lock(&vf->cfg_lock);
3649 /* Check if VF is disabled. */
3650 if (test_bit(ICE_VF_STATE_DIS, vf->vf_states)) {
3655 ops = vf->virtchnl_ops;
3657 /* Perform basic checks on the msg */
3658 err = virtchnl_vc_validate_vf_msg(&vf->vf_ver, v_opcode, msg, msglen);
3660 if (err == VIRTCHNL_STATUS_ERR_PARAM)
3668 ice_vc_send_msg_to_vf(vf, v_opcode, VIRTCHNL_STATUS_ERR_PARAM,
3670 dev_err(dev, "Invalid message from VF %d, opcode %d, len %d, error %d\n",
3671 vf_id, v_opcode, msglen, err);
3675 if (!ice_vc_is_opcode_allowed(vf, v_opcode)) {
3676 ice_vc_send_msg_to_vf(vf, v_opcode,
3677 VIRTCHNL_STATUS_ERR_NOT_SUPPORTED, NULL,
3683 case VIRTCHNL_OP_VERSION:
3684 err = ops->get_ver_msg(vf, msg);
3686 case VIRTCHNL_OP_GET_VF_RESOURCES:
3687 err = ops->get_vf_res_msg(vf, msg);
3688 if (ice_vf_init_vlan_stripping(vf))
3689 dev_dbg(dev, "Failed to initialize VLAN stripping for VF %d\n",
3691 ice_vc_notify_vf_link_state(vf);
3693 case VIRTCHNL_OP_RESET_VF:
3696 case VIRTCHNL_OP_ADD_ETH_ADDR:
3697 err = ops->add_mac_addr_msg(vf, msg);
3699 case VIRTCHNL_OP_DEL_ETH_ADDR:
3700 err = ops->del_mac_addr_msg(vf, msg);
3702 case VIRTCHNL_OP_CONFIG_VSI_QUEUES:
3703 err = ops->cfg_qs_msg(vf, msg);
3705 case VIRTCHNL_OP_ENABLE_QUEUES:
3706 err = ops->ena_qs_msg(vf, msg);
3707 ice_vc_notify_vf_link_state(vf);
3709 case VIRTCHNL_OP_DISABLE_QUEUES:
3710 err = ops->dis_qs_msg(vf, msg);
3712 case VIRTCHNL_OP_REQUEST_QUEUES:
3713 err = ops->request_qs_msg(vf, msg);
3715 case VIRTCHNL_OP_CONFIG_IRQ_MAP:
3716 err = ops->cfg_irq_map_msg(vf, msg);
3718 case VIRTCHNL_OP_CONFIG_RSS_KEY:
3719 err = ops->config_rss_key(vf, msg);
3721 case VIRTCHNL_OP_CONFIG_RSS_LUT:
3722 err = ops->config_rss_lut(vf, msg);
3724 case VIRTCHNL_OP_GET_STATS:
3725 err = ops->get_stats_msg(vf, msg);
3727 case VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE:
3728 err = ops->cfg_promiscuous_mode_msg(vf, msg);
3730 case VIRTCHNL_OP_ADD_VLAN:
3731 err = ops->add_vlan_msg(vf, msg);
3733 case VIRTCHNL_OP_DEL_VLAN:
3734 err = ops->remove_vlan_msg(vf, msg);
3736 case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING:
3737 err = ops->ena_vlan_stripping(vf);
3739 case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING:
3740 err = ops->dis_vlan_stripping(vf);
3742 case VIRTCHNL_OP_ADD_FDIR_FILTER:
3743 err = ops->add_fdir_fltr_msg(vf, msg);
3745 case VIRTCHNL_OP_DEL_FDIR_FILTER:
3746 err = ops->del_fdir_fltr_msg(vf, msg);
3748 case VIRTCHNL_OP_ADD_RSS_CFG:
3749 err = ops->handle_rss_cfg_msg(vf, msg, true);
3751 case VIRTCHNL_OP_DEL_RSS_CFG:
3752 err = ops->handle_rss_cfg_msg(vf, msg, false);
3754 case VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS:
3755 err = ops->get_offload_vlan_v2_caps(vf);
3757 case VIRTCHNL_OP_ADD_VLAN_V2:
3758 err = ops->add_vlan_v2_msg(vf, msg);
3760 case VIRTCHNL_OP_DEL_VLAN_V2:
3761 err = ops->remove_vlan_v2_msg(vf, msg);
3763 case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2:
3764 err = ops->ena_vlan_stripping_v2_msg(vf, msg);
3766 case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2:
3767 err = ops->dis_vlan_stripping_v2_msg(vf, msg);
3769 case VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2:
3770 err = ops->ena_vlan_insertion_v2_msg(vf, msg);
3772 case VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2:
3773 err = ops->dis_vlan_insertion_v2_msg(vf, msg);
3775 case VIRTCHNL_OP_UNKNOWN:
3777 dev_err(dev, "Unsupported opcode %d from VF %d\n", v_opcode,
3779 err = ice_vc_send_msg_to_vf(vf, v_opcode,
3780 VIRTCHNL_STATUS_ERR_NOT_SUPPORTED,
3785 /* Helper function cares less about error return values here
3786 * as it is busy with pending work.
3788 dev_info(dev, "PF failed to honor VF %d, opcode %d, error %d\n",
3789 vf_id, v_opcode, err);
3793 mutex_unlock(&vf->cfg_lock);