1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (C) 2022, Intel Corporation. */
3
4 #include "ice_virtchnl.h"
5 #include "ice_vf_lib_private.h"
6 #include "ice.h"
7 #include "ice_base.h"
8 #include "ice_lib.h"
9 #include "ice_fltr.h"
10 #include "ice_virtchnl_allowlist.h"
11 #include "ice_vf_vsi_vlan_ops.h"
12 #include "ice_vlan.h"
13 #include "ice_flex_pipe.h"
14 #include "ice_dcb_lib.h"
15
16 #define FIELD_SELECTOR(proto_hdr_field) \
17 BIT((proto_hdr_field) & PROTO_HDR_FIELD_MASK)
18
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) */
22 };
23
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},
47 };
48
49 struct ice_vc_hash_field_match_type {
50 u32 vc_hdr; /* virtchnl headers
51 * (VIRTCHNL_PROTO_HDR_XXX)
52 */
53 u32 vc_hash_field; /* virtchnl hash fields selector
54 * FIELD_SELECTOR((VIRTCHNL_PROTO_HDR_ETH_XXX))
55 */
56 u64 ice_hash_field; /* ice hash fields
57 * (BIT_ULL(ICE_FLOW_FIELD_IDX_XXX))
58 */
59 };
60
61 static const struct
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),
69 ICE_FLOW_HASH_ETH},
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),
85 ICE_FLOW_HASH_IPV4},
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),
106 ICE_FLOW_HASH_IPV6},
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)},
166 };
167
168 /**
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
175 */
176 static void
ice_vc_vf_broadcast(struct ice_pf * pf,enum virtchnl_ops v_opcode,enum virtchnl_status_code v_retval,u8 * msg,u16 msglen)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)
179 {
180 struct ice_hw *hw = &pf->hw;
181 struct ice_vf *vf;
182 unsigned int bkt;
183
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))
189 continue;
190
191 /* Ignore return value on purpose - a given VF may fail, but
192 * we need to keep going and send to all of them
193 */
194 ice_aq_send_msg_to_vf(hw, vf->vf_id, v_opcode, v_retval, msg,
195 msglen, NULL);
196 }
197 mutex_unlock(&pf->vfs.table_lock);
198 }
199
200 /**
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
206 */
207 static void
ice_set_pfe_link(struct ice_vf * vf,struct virtchnl_pf_event * pfe,int ice_link_speed,bool link_up)208 ice_set_pfe_link(struct ice_vf *vf, struct virtchnl_pf_event *pfe,
209 int ice_link_speed, bool link_up)
210 {
211 if (vf->driver_caps & VIRTCHNL_VF_CAP_ADV_LINK_SPEED) {
212 pfe->event_data.link_event_adv.link_status = link_up;
213 /* Speed in Mbps */
214 pfe->event_data.link_event_adv.link_speed =
215 ice_conv_link_speed_to_virtchnl(true, ice_link_speed);
216 } else {
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);
222 }
223 }
224
225 /**
226 * ice_vc_notify_vf_link_state - Inform a VF of link status
227 * @vf: pointer to the VF structure
228 *
229 * send a link status message to a single VF
230 */
ice_vc_notify_vf_link_state(struct ice_vf * vf)231 void ice_vc_notify_vf_link_state(struct ice_vf *vf)
232 {
233 struct virtchnl_pf_event pfe = { 0 };
234 struct ice_hw *hw = &vf->pf->hw;
235
236 pfe.event = VIRTCHNL_EVENT_LINK_CHANGE;
237 pfe.severity = PF_EVENT_SEVERITY_INFO;
238
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);
242 else
243 ice_set_pfe_link(vf, &pfe, ICE_AQ_LINK_SPEED_UNKNOWN, false);
244
245 ice_aq_send_msg_to_vf(hw, vf->vf_id, VIRTCHNL_OP_EVENT,
246 VIRTCHNL_STATUS_SUCCESS, (u8 *)&pfe,
247 sizeof(pfe), NULL);
248 }
249
250 /**
251 * ice_vc_notify_link_state - Inform all VFs on a PF of link status
252 * @pf: pointer to the PF structure
253 */
ice_vc_notify_link_state(struct ice_pf * pf)254 void ice_vc_notify_link_state(struct ice_pf *pf)
255 {
256 struct ice_vf *vf;
257 unsigned int bkt;
258
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);
263 }
264
265 /**
266 * ice_vc_notify_reset - Send pending reset message to all VFs
267 * @pf: pointer to the PF structure
268 *
269 * indicate a pending reset to all VFs on a given PF
270 */
ice_vc_notify_reset(struct ice_pf * pf)271 void ice_vc_notify_reset(struct ice_pf *pf)
272 {
273 struct virtchnl_pf_event pfe;
274
275 if (!ice_has_vfs(pf))
276 return;
277
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));
282 }
283
284 /**
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
291 *
292 * send msg to VF
293 */
294 int
ice_vc_send_msg_to_vf(struct ice_vf * vf,u32 v_opcode,enum virtchnl_status_code v_retval,u8 * msg,u16 msglen)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)
297 {
298 struct device *dev;
299 struct ice_pf *pf;
300 int aq_ret;
301
302 pf = vf->pf;
303 dev = ice_pf_to_dev(pf);
304
305 aq_ret = ice_aq_send_msg_to_vf(&pf->hw, vf->vf_id, v_opcode, v_retval,
306 msg, msglen, NULL);
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",
309 vf->vf_id, aq_ret,
310 ice_aq_str(pf->hw.mailboxq.sq_last_status));
311 return -EIO;
312 }
313
314 return 0;
315 }
316
317 /**
318 * ice_vc_get_ver_msg
319 * @vf: pointer to the VF info
320 * @msg: pointer to the msg buffer
321 *
322 * called from the VF to request the API version used by the PF
323 */
ice_vc_get_ver_msg(struct ice_vf * vf,u8 * msg)324 static int ice_vc_get_ver_msg(struct ice_vf *vf, u8 *msg)
325 {
326 struct virtchnl_version_info info = {
327 VIRTCHNL_VERSION_MAJOR, VIRTCHNL_VERSION_MINOR
328 };
329
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;
334
335 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_VERSION,
336 VIRTCHNL_STATUS_SUCCESS, (u8 *)&info,
337 sizeof(struct virtchnl_version_info));
338 }
339
340 /**
341 * ice_vc_get_max_frame_size - get max frame size allowed for VF
342 * @vf: VF used to determine max frame size
343 *
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.
348 */
ice_vc_get_max_frame_size(struct ice_vf * vf)349 static u16 ice_vc_get_max_frame_size(struct ice_vf *vf)
350 {
351 struct ice_port_info *pi = ice_vf_get_port_info(vf);
352 u16 max_frame_size;
353
354 max_frame_size = pi->phy.link_info.max_frame_size;
355
356 if (ice_vf_is_port_vlan_ena(vf))
357 max_frame_size -= VLAN_HLEN;
358
359 return max_frame_size;
360 }
361
362 /**
363 * ice_vc_get_vlan_caps
364 * @hw: pointer to the hw
365 * @vf: pointer to the VF info
366 * @vsi: pointer to the VSI
367 * @driver_caps: current driver caps
368 *
369 * Return 0 if there is no VLAN caps supported, or VLAN caps value
370 */
371 static u32
ice_vc_get_vlan_caps(struct ice_hw * hw,struct ice_vf * vf,struct ice_vsi * vsi,u32 driver_caps)372 ice_vc_get_vlan_caps(struct ice_hw *hw, struct ice_vf *vf, struct ice_vsi *vsi,
373 u32 driver_caps)
374 {
375 if (ice_is_eswitch_mode_switchdev(vf->pf))
376 /* In switchdev setting VLAN from VF isn't supported */
377 return 0;
378
379 if (driver_caps & VIRTCHNL_VF_OFFLOAD_VLAN_V2) {
380 /* VLAN offloads based on current device configuration */
381 return VIRTCHNL_VF_OFFLOAD_VLAN_V2;
382 } else if (driver_caps & VIRTCHNL_VF_OFFLOAD_VLAN) {
383 /* allow VF to negotiate VIRTCHNL_VF_OFFLOAD explicitly for
384 * these two conditions, which amounts to guest VLAN filtering
385 * and offloads being based on the inner VLAN or the
386 * inner/single VLAN respectively and don't allow VF to
387 * negotiate VIRTCHNL_VF_OFFLOAD in any other cases
388 */
389 if (ice_is_dvm_ena(hw) && ice_vf_is_port_vlan_ena(vf)) {
390 return VIRTCHNL_VF_OFFLOAD_VLAN;
391 } else if (!ice_is_dvm_ena(hw) &&
392 !ice_vf_is_port_vlan_ena(vf)) {
393 /* configure backward compatible support for VFs that
394 * only support VIRTCHNL_VF_OFFLOAD_VLAN, the PF is
395 * configured in SVM, and no port VLAN is configured
396 */
397 ice_vf_vsi_cfg_svm_legacy_vlan_mode(vsi);
398 return VIRTCHNL_VF_OFFLOAD_VLAN;
399 } else if (ice_is_dvm_ena(hw)) {
400 /* configure software offloaded VLAN support when DVM
401 * is enabled, but no port VLAN is enabled
402 */
403 ice_vf_vsi_cfg_dvm_legacy_vlan_mode(vsi);
404 }
405 }
406
407 return 0;
408 }
409
410 /**
411 * ice_vc_get_vf_res_msg
412 * @vf: pointer to the VF info
413 * @msg: pointer to the msg buffer
414 *
415 * called from the VF to request its resources
416 */
ice_vc_get_vf_res_msg(struct ice_vf * vf,u8 * msg)417 static int ice_vc_get_vf_res_msg(struct ice_vf *vf, u8 *msg)
418 {
419 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
420 struct virtchnl_vf_resource *vfres = NULL;
421 struct ice_hw *hw = &vf->pf->hw;
422 struct ice_vsi *vsi;
423 int len = 0;
424 int ret;
425
426 if (ice_check_vf_init(vf)) {
427 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
428 goto err;
429 }
430
431 len = virtchnl_struct_size(vfres, vsi_res, 0);
432
433 vfres = kzalloc(len, GFP_KERNEL);
434 if (!vfres) {
435 v_ret = VIRTCHNL_STATUS_ERR_NO_MEMORY;
436 len = 0;
437 goto err;
438 }
439 if (VF_IS_V11(&vf->vf_ver))
440 vf->driver_caps = *(u32 *)msg;
441 else
442 vf->driver_caps = VIRTCHNL_VF_OFFLOAD_L2 |
443 VIRTCHNL_VF_OFFLOAD_VLAN;
444
445 vfres->vf_cap_flags = VIRTCHNL_VF_OFFLOAD_L2;
446 vsi = ice_get_vf_vsi(vf);
447 if (!vsi) {
448 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
449 goto err;
450 }
451
452 vfres->vf_cap_flags |= ice_vc_get_vlan_caps(hw, vf, vsi,
453 vf->driver_caps);
454
455 if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_RSS_PF)
456 vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_RSS_PF;
457
458 if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_RX_FLEX_DESC)
459 vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_RX_FLEX_DESC;
460
461 if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_FDIR_PF)
462 vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_FDIR_PF;
463
464 if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_TC_U32 &&
465 vfres->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_FDIR_PF)
466 vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_TC_U32;
467
468 if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_RSS_PCTYPE_V2)
469 vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_RSS_PCTYPE_V2;
470
471 if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_ENCAP)
472 vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_ENCAP;
473
474 if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_ENCAP_CSUM)
475 vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_ENCAP_CSUM;
476
477 if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_RX_POLLING)
478 vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_RX_POLLING;
479
480 if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_WB_ON_ITR)
481 vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_WB_ON_ITR;
482
483 if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_REQ_QUEUES)
484 vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_REQ_QUEUES;
485
486 if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_CRC)
487 vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_CRC;
488
489 if (vf->driver_caps & VIRTCHNL_VF_CAP_ADV_LINK_SPEED)
490 vfres->vf_cap_flags |= VIRTCHNL_VF_CAP_ADV_LINK_SPEED;
491
492 if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_ADV_RSS_PF)
493 vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_ADV_RSS_PF;
494
495 if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_USO)
496 vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_USO;
497
498 if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_QOS)
499 vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_QOS;
500
501 if (vf->driver_caps & VIRTCHNL_VF_CAP_PTP)
502 vfres->vf_cap_flags |= VIRTCHNL_VF_CAP_PTP;
503
504 vfres->num_vsis = 1;
505 /* Tx and Rx queue are equal for VF */
506 vfres->num_queue_pairs = vsi->num_txq;
507 vfres->max_vectors = vf->num_msix;
508 vfres->rss_key_size = ICE_VSIQF_HKEY_ARRAY_SIZE;
509 vfres->rss_lut_size = ICE_LUT_VSI_SIZE;
510 vfres->max_mtu = ice_vc_get_max_frame_size(vf);
511
512 vfres->vsi_res[0].vsi_id = ICE_VF_VSI_ID;
513 vfres->vsi_res[0].vsi_type = VIRTCHNL_VSI_SRIOV;
514 vfres->vsi_res[0].num_queue_pairs = vsi->num_txq;
515 ether_addr_copy(vfres->vsi_res[0].default_mac_addr,
516 vf->hw_lan_addr);
517
518 /* match guest capabilities */
519 vf->driver_caps = vfres->vf_cap_flags;
520
521 ice_vc_set_caps_allowlist(vf);
522 ice_vc_set_working_allowlist(vf);
523
524 set_bit(ICE_VF_STATE_ACTIVE, vf->vf_states);
525
526 err:
527 /* send the response back to the VF */
528 ret = ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_GET_VF_RESOURCES, v_ret,
529 (u8 *)vfres, len);
530
531 kfree(vfres);
532 return ret;
533 }
534
535 /**
536 * ice_vc_reset_vf_msg
537 * @vf: pointer to the VF info
538 *
539 * called from the VF to reset itself,
540 * unlike other virtchnl messages, PF driver
541 * doesn't send the response back to the VF
542 */
ice_vc_reset_vf_msg(struct ice_vf * vf)543 static void ice_vc_reset_vf_msg(struct ice_vf *vf)
544 {
545 if (test_bit(ICE_VF_STATE_INIT, vf->vf_states))
546 ice_reset_vf(vf, 0);
547 }
548
549 /**
550 * ice_vc_isvalid_vsi_id
551 * @vf: pointer to the VF info
552 * @vsi_id: VF relative VSI ID
553 *
554 * check for the valid VSI ID
555 */
ice_vc_isvalid_vsi_id(struct ice_vf * vf,u16 vsi_id)556 bool ice_vc_isvalid_vsi_id(struct ice_vf *vf, u16 vsi_id)
557 {
558 return vsi_id == ICE_VF_VSI_ID;
559 }
560
561 /**
562 * ice_vc_isvalid_q_id
563 * @vsi: VSI to check queue ID against
564 * @qid: VSI relative queue ID
565 *
566 * check for the valid queue ID
567 */
ice_vc_isvalid_q_id(struct ice_vsi * vsi,u16 qid)568 static bool ice_vc_isvalid_q_id(struct ice_vsi *vsi, u16 qid)
569 {
570 /* allocated Tx and Rx queues should be always equal for VF VSI */
571 return qid < vsi->alloc_txq;
572 }
573
574 /**
575 * ice_vc_isvalid_ring_len
576 * @ring_len: length of ring
577 *
578 * check for the valid ring count, should be multiple of ICE_REQ_DESC_MULTIPLE
579 * or zero
580 */
ice_vc_isvalid_ring_len(u16 ring_len)581 static bool ice_vc_isvalid_ring_len(u16 ring_len)
582 {
583 return ring_len == 0 ||
584 (ring_len >= ICE_MIN_NUM_DESC &&
585 ring_len <= ICE_MAX_NUM_DESC &&
586 !(ring_len % ICE_REQ_DESC_MULTIPLE));
587 }
588
589 /**
590 * ice_vc_validate_pattern
591 * @vf: pointer to the VF info
592 * @proto: virtchnl protocol headers
593 *
594 * validate the pattern is supported or not.
595 *
596 * Return: true on success, false on error.
597 */
598 bool
ice_vc_validate_pattern(struct ice_vf * vf,struct virtchnl_proto_hdrs * proto)599 ice_vc_validate_pattern(struct ice_vf *vf, struct virtchnl_proto_hdrs *proto)
600 {
601 bool is_ipv4 = false;
602 bool is_ipv6 = false;
603 bool is_udp = false;
604 u16 ptype = -1;
605 int i = 0;
606
607 while (i < proto->count &&
608 proto->proto_hdr[i].type != VIRTCHNL_PROTO_HDR_NONE) {
609 switch (proto->proto_hdr[i].type) {
610 case VIRTCHNL_PROTO_HDR_ETH:
611 ptype = ICE_PTYPE_MAC_PAY;
612 break;
613 case VIRTCHNL_PROTO_HDR_IPV4:
614 ptype = ICE_PTYPE_IPV4_PAY;
615 is_ipv4 = true;
616 break;
617 case VIRTCHNL_PROTO_HDR_IPV6:
618 ptype = ICE_PTYPE_IPV6_PAY;
619 is_ipv6 = true;
620 break;
621 case VIRTCHNL_PROTO_HDR_UDP:
622 if (is_ipv4)
623 ptype = ICE_PTYPE_IPV4_UDP_PAY;
624 else if (is_ipv6)
625 ptype = ICE_PTYPE_IPV6_UDP_PAY;
626 is_udp = true;
627 break;
628 case VIRTCHNL_PROTO_HDR_TCP:
629 if (is_ipv4)
630 ptype = ICE_PTYPE_IPV4_TCP_PAY;
631 else if (is_ipv6)
632 ptype = ICE_PTYPE_IPV6_TCP_PAY;
633 break;
634 case VIRTCHNL_PROTO_HDR_SCTP:
635 if (is_ipv4)
636 ptype = ICE_PTYPE_IPV4_SCTP_PAY;
637 else if (is_ipv6)
638 ptype = ICE_PTYPE_IPV6_SCTP_PAY;
639 break;
640 case VIRTCHNL_PROTO_HDR_GTPU_IP:
641 case VIRTCHNL_PROTO_HDR_GTPU_EH:
642 if (is_ipv4)
643 ptype = ICE_MAC_IPV4_GTPU;
644 else if (is_ipv6)
645 ptype = ICE_MAC_IPV6_GTPU;
646 goto out;
647 case VIRTCHNL_PROTO_HDR_L2TPV3:
648 if (is_ipv4)
649 ptype = ICE_MAC_IPV4_L2TPV3;
650 else if (is_ipv6)
651 ptype = ICE_MAC_IPV6_L2TPV3;
652 goto out;
653 case VIRTCHNL_PROTO_HDR_ESP:
654 if (is_ipv4)
655 ptype = is_udp ? ICE_MAC_IPV4_NAT_T_ESP :
656 ICE_MAC_IPV4_ESP;
657 else if (is_ipv6)
658 ptype = is_udp ? ICE_MAC_IPV6_NAT_T_ESP :
659 ICE_MAC_IPV6_ESP;
660 goto out;
661 case VIRTCHNL_PROTO_HDR_AH:
662 if (is_ipv4)
663 ptype = ICE_MAC_IPV4_AH;
664 else if (is_ipv6)
665 ptype = ICE_MAC_IPV6_AH;
666 goto out;
667 case VIRTCHNL_PROTO_HDR_PFCP:
668 if (is_ipv4)
669 ptype = ICE_MAC_IPV4_PFCP_SESSION;
670 else if (is_ipv6)
671 ptype = ICE_MAC_IPV6_PFCP_SESSION;
672 goto out;
673 default:
674 break;
675 }
676 i++;
677 }
678
679 out:
680 return ice_hw_ptype_ena(&vf->pf->hw, ptype);
681 }
682
683 /**
684 * ice_vc_parse_rss_cfg - parses hash fields and headers from
685 * a specific virtchnl RSS cfg
686 * @hw: pointer to the hardware
687 * @rss_cfg: pointer to the virtchnl RSS cfg
688 * @hash_cfg: pointer to the HW hash configuration
689 *
690 * Return true if all the protocol header and hash fields in the RSS cfg could
691 * be parsed, else return false
692 *
693 * This function parses the virtchnl RSS cfg to be the intended
694 * hash fields and the intended header for RSS configuration
695 */
ice_vc_parse_rss_cfg(struct ice_hw * hw,struct virtchnl_rss_cfg * rss_cfg,struct ice_rss_hash_cfg * hash_cfg)696 static bool ice_vc_parse_rss_cfg(struct ice_hw *hw,
697 struct virtchnl_rss_cfg *rss_cfg,
698 struct ice_rss_hash_cfg *hash_cfg)
699 {
700 const struct ice_vc_hash_field_match_type *hf_list;
701 const struct ice_vc_hdr_match_type *hdr_list;
702 int i, hf_list_len, hdr_list_len;
703 u32 *addl_hdrs = &hash_cfg->addl_hdrs;
704 u64 *hash_flds = &hash_cfg->hash_flds;
705
706 /* set outer layer RSS as default */
707 hash_cfg->hdr_type = ICE_RSS_OUTER_HEADERS;
708
709 if (rss_cfg->rss_algorithm == VIRTCHNL_RSS_ALG_TOEPLITZ_SYMMETRIC)
710 hash_cfg->symm = true;
711 else
712 hash_cfg->symm = false;
713
714 hf_list = ice_vc_hash_field_list;
715 hf_list_len = ARRAY_SIZE(ice_vc_hash_field_list);
716 hdr_list = ice_vc_hdr_list;
717 hdr_list_len = ARRAY_SIZE(ice_vc_hdr_list);
718
719 for (i = 0; i < rss_cfg->proto_hdrs.count; i++) {
720 struct virtchnl_proto_hdr *proto_hdr =
721 &rss_cfg->proto_hdrs.proto_hdr[i];
722 bool hdr_found = false;
723 int j;
724
725 /* Find matched ice headers according to virtchnl headers. */
726 for (j = 0; j < hdr_list_len; j++) {
727 struct ice_vc_hdr_match_type hdr_map = hdr_list[j];
728
729 if (proto_hdr->type == hdr_map.vc_hdr) {
730 *addl_hdrs |= hdr_map.ice_hdr;
731 hdr_found = true;
732 }
733 }
734
735 if (!hdr_found)
736 return false;
737
738 /* Find matched ice hash fields according to
739 * virtchnl hash fields.
740 */
741 for (j = 0; j < hf_list_len; j++) {
742 struct ice_vc_hash_field_match_type hf_map = hf_list[j];
743
744 if (proto_hdr->type == hf_map.vc_hdr &&
745 proto_hdr->field_selector == hf_map.vc_hash_field) {
746 *hash_flds |= hf_map.ice_hash_field;
747 break;
748 }
749 }
750 }
751
752 return true;
753 }
754
755 /**
756 * ice_vf_adv_rss_offload_ena - determine if capabilities support advanced
757 * RSS offloads
758 * @caps: VF driver negotiated capabilities
759 *
760 * Return true if VIRTCHNL_VF_OFFLOAD_ADV_RSS_PF capability is set,
761 * else return false
762 */
ice_vf_adv_rss_offload_ena(u32 caps)763 static bool ice_vf_adv_rss_offload_ena(u32 caps)
764 {
765 return !!(caps & VIRTCHNL_VF_OFFLOAD_ADV_RSS_PF);
766 }
767
768 /**
769 * ice_vc_handle_rss_cfg
770 * @vf: pointer to the VF info
771 * @msg: pointer to the message buffer
772 * @add: add a RSS config if true, otherwise delete a RSS config
773 *
774 * This function adds/deletes a RSS config
775 */
ice_vc_handle_rss_cfg(struct ice_vf * vf,u8 * msg,bool add)776 static int ice_vc_handle_rss_cfg(struct ice_vf *vf, u8 *msg, bool add)
777 {
778 u32 v_opcode = add ? VIRTCHNL_OP_ADD_RSS_CFG : VIRTCHNL_OP_DEL_RSS_CFG;
779 struct virtchnl_rss_cfg *rss_cfg = (struct virtchnl_rss_cfg *)msg;
780 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
781 struct device *dev = ice_pf_to_dev(vf->pf);
782 struct ice_hw *hw = &vf->pf->hw;
783 struct ice_vsi *vsi;
784
785 if (!test_bit(ICE_FLAG_RSS_ENA, vf->pf->flags)) {
786 dev_dbg(dev, "VF %d attempting to configure RSS, but RSS is not supported by the PF\n",
787 vf->vf_id);
788 v_ret = VIRTCHNL_STATUS_ERR_NOT_SUPPORTED;
789 goto error_param;
790 }
791
792 if (!ice_vf_adv_rss_offload_ena(vf->driver_caps)) {
793 dev_dbg(dev, "VF %d attempting to configure RSS, but Advanced RSS offload is not supported\n",
794 vf->vf_id);
795 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
796 goto error_param;
797 }
798
799 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
800 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
801 goto error_param;
802 }
803
804 if (rss_cfg->proto_hdrs.count > VIRTCHNL_MAX_NUM_PROTO_HDRS ||
805 rss_cfg->rss_algorithm < VIRTCHNL_RSS_ALG_TOEPLITZ_ASYMMETRIC ||
806 rss_cfg->rss_algorithm > VIRTCHNL_RSS_ALG_XOR_SYMMETRIC) {
807 dev_dbg(dev, "VF %d attempting to configure RSS, but RSS configuration is not valid\n",
808 vf->vf_id);
809 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
810 goto error_param;
811 }
812
813 vsi = ice_get_vf_vsi(vf);
814 if (!vsi) {
815 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
816 goto error_param;
817 }
818
819 if (!ice_vc_validate_pattern(vf, &rss_cfg->proto_hdrs)) {
820 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
821 goto error_param;
822 }
823
824 if (rss_cfg->rss_algorithm == VIRTCHNL_RSS_ALG_R_ASYMMETRIC) {
825 struct ice_vsi_ctx *ctx;
826 u8 lut_type, hash_type;
827 int status;
828
829 lut_type = ICE_AQ_VSI_Q_OPT_RSS_LUT_VSI;
830 hash_type = add ? ICE_AQ_VSI_Q_OPT_RSS_HASH_XOR :
831 ICE_AQ_VSI_Q_OPT_RSS_HASH_TPLZ;
832
833 ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
834 if (!ctx) {
835 v_ret = VIRTCHNL_STATUS_ERR_NO_MEMORY;
836 goto error_param;
837 }
838
839 ctx->info.q_opt_rss =
840 FIELD_PREP(ICE_AQ_VSI_Q_OPT_RSS_LUT_M, lut_type) |
841 FIELD_PREP(ICE_AQ_VSI_Q_OPT_RSS_HASH_M, hash_type);
842
843 /* Preserve existing queueing option setting */
844 ctx->info.q_opt_rss |= (vsi->info.q_opt_rss &
845 ICE_AQ_VSI_Q_OPT_RSS_GBL_LUT_M);
846 ctx->info.q_opt_tc = vsi->info.q_opt_tc;
847 ctx->info.q_opt_flags = vsi->info.q_opt_rss;
848
849 ctx->info.valid_sections =
850 cpu_to_le16(ICE_AQ_VSI_PROP_Q_OPT_VALID);
851
852 status = ice_update_vsi(hw, vsi->idx, ctx, NULL);
853 if (status) {
854 dev_err(dev, "update VSI for RSS failed, err %d aq_err %s\n",
855 status, ice_aq_str(hw->adminq.sq_last_status));
856 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
857 } else {
858 vsi->info.q_opt_rss = ctx->info.q_opt_rss;
859 }
860
861 kfree(ctx);
862 } else {
863 struct ice_rss_hash_cfg cfg;
864
865 /* Only check for none raw pattern case */
866 if (!ice_vc_validate_pattern(vf, &rss_cfg->proto_hdrs)) {
867 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
868 goto error_param;
869 }
870 cfg.addl_hdrs = ICE_FLOW_SEG_HDR_NONE;
871 cfg.hash_flds = ICE_HASH_INVALID;
872 cfg.hdr_type = ICE_RSS_ANY_HEADERS;
873
874 if (!ice_vc_parse_rss_cfg(hw, rss_cfg, &cfg)) {
875 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
876 goto error_param;
877 }
878
879 if (add) {
880 if (ice_add_rss_cfg(hw, vsi, &cfg)) {
881 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
882 dev_err(dev, "ice_add_rss_cfg failed for vsi = %d, v_ret = %d\n",
883 vsi->vsi_num, v_ret);
884 }
885 } else {
886 int status;
887
888 status = ice_rem_rss_cfg(hw, vsi->idx, &cfg);
889 /* We just ignore -ENOENT, because if two configurations
890 * share the same profile remove one of them actually
891 * removes both, since the profile is deleted.
892 */
893 if (status && status != -ENOENT) {
894 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
895 dev_err(dev, "ice_rem_rss_cfg failed for VF ID:%d, error:%d\n",
896 vf->vf_id, status);
897 }
898 }
899 }
900
901 error_param:
902 return ice_vc_send_msg_to_vf(vf, v_opcode, v_ret, NULL, 0);
903 }
904
905 /**
906 * ice_vc_config_rss_key
907 * @vf: pointer to the VF info
908 * @msg: pointer to the msg buffer
909 *
910 * Configure the VF's RSS key
911 */
ice_vc_config_rss_key(struct ice_vf * vf,u8 * msg)912 static int ice_vc_config_rss_key(struct ice_vf *vf, u8 *msg)
913 {
914 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
915 struct virtchnl_rss_key *vrk =
916 (struct virtchnl_rss_key *)msg;
917 struct ice_vsi *vsi;
918
919 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
920 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
921 goto error_param;
922 }
923
924 if (!ice_vc_isvalid_vsi_id(vf, vrk->vsi_id)) {
925 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
926 goto error_param;
927 }
928
929 if (vrk->key_len != ICE_VSIQF_HKEY_ARRAY_SIZE) {
930 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
931 goto error_param;
932 }
933
934 if (!test_bit(ICE_FLAG_RSS_ENA, vf->pf->flags)) {
935 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
936 goto error_param;
937 }
938
939 vsi = ice_get_vf_vsi(vf);
940 if (!vsi) {
941 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
942 goto error_param;
943 }
944
945 if (ice_set_rss_key(vsi, vrk->key))
946 v_ret = VIRTCHNL_STATUS_ERR_ADMIN_QUEUE_ERROR;
947 error_param:
948 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_CONFIG_RSS_KEY, v_ret,
949 NULL, 0);
950 }
951
952 /**
953 * ice_vc_config_rss_lut
954 * @vf: pointer to the VF info
955 * @msg: pointer to the msg buffer
956 *
957 * Configure the VF's RSS LUT
958 */
ice_vc_config_rss_lut(struct ice_vf * vf,u8 * msg)959 static int ice_vc_config_rss_lut(struct ice_vf *vf, u8 *msg)
960 {
961 struct virtchnl_rss_lut *vrl = (struct virtchnl_rss_lut *)msg;
962 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
963 struct ice_vsi *vsi;
964
965 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
966 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
967 goto error_param;
968 }
969
970 if (!ice_vc_isvalid_vsi_id(vf, vrl->vsi_id)) {
971 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
972 goto error_param;
973 }
974
975 if (vrl->lut_entries != ICE_LUT_VSI_SIZE) {
976 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
977 goto error_param;
978 }
979
980 if (!test_bit(ICE_FLAG_RSS_ENA, vf->pf->flags)) {
981 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
982 goto error_param;
983 }
984
985 vsi = ice_get_vf_vsi(vf);
986 if (!vsi) {
987 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
988 goto error_param;
989 }
990
991 if (ice_set_rss_lut(vsi, vrl->lut, ICE_LUT_VSI_SIZE))
992 v_ret = VIRTCHNL_STATUS_ERR_ADMIN_QUEUE_ERROR;
993 error_param:
994 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_CONFIG_RSS_LUT, v_ret,
995 NULL, 0);
996 }
997
998 /**
999 * ice_vc_config_rss_hfunc
1000 * @vf: pointer to the VF info
1001 * @msg: pointer to the msg buffer
1002 *
1003 * Configure the VF's RSS Hash function
1004 */
ice_vc_config_rss_hfunc(struct ice_vf * vf,u8 * msg)1005 static int ice_vc_config_rss_hfunc(struct ice_vf *vf, u8 *msg)
1006 {
1007 struct virtchnl_rss_hfunc *vrh = (struct virtchnl_rss_hfunc *)msg;
1008 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
1009 u8 hfunc = ICE_AQ_VSI_Q_OPT_RSS_HASH_TPLZ;
1010 struct ice_vsi *vsi;
1011
1012 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
1013 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1014 goto error_param;
1015 }
1016
1017 if (!ice_vc_isvalid_vsi_id(vf, vrh->vsi_id)) {
1018 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1019 goto error_param;
1020 }
1021
1022 if (!test_bit(ICE_FLAG_RSS_ENA, vf->pf->flags)) {
1023 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1024 goto error_param;
1025 }
1026
1027 vsi = ice_get_vf_vsi(vf);
1028 if (!vsi) {
1029 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1030 goto error_param;
1031 }
1032
1033 if (vrh->rss_algorithm == VIRTCHNL_RSS_ALG_TOEPLITZ_SYMMETRIC)
1034 hfunc = ICE_AQ_VSI_Q_OPT_RSS_HASH_SYM_TPLZ;
1035
1036 if (ice_set_rss_hfunc(vsi, hfunc))
1037 v_ret = VIRTCHNL_STATUS_ERR_ADMIN_QUEUE_ERROR;
1038 error_param:
1039 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_CONFIG_RSS_HFUNC, v_ret,
1040 NULL, 0);
1041 }
1042
1043 /**
1044 * ice_vc_get_qos_caps - Get current QoS caps from PF
1045 * @vf: pointer to the VF info
1046 *
1047 * Get VF's QoS capabilities, such as TC number, arbiter and
1048 * bandwidth from PF.
1049 *
1050 * Return: 0 on success or negative error value.
1051 */
ice_vc_get_qos_caps(struct ice_vf * vf)1052 static int ice_vc_get_qos_caps(struct ice_vf *vf)
1053 {
1054 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
1055 struct virtchnl_qos_cap_list *cap_list = NULL;
1056 u8 tc_prio[ICE_MAX_TRAFFIC_CLASS] = { 0 };
1057 struct virtchnl_qos_cap_elem *cfg = NULL;
1058 struct ice_vsi_ctx *vsi_ctx;
1059 struct ice_pf *pf = vf->pf;
1060 struct ice_port_info *pi;
1061 struct ice_vsi *vsi;
1062 u8 numtc, tc;
1063 u16 len = 0;
1064 int ret, i;
1065
1066 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
1067 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1068 goto err;
1069 }
1070
1071 vsi = ice_get_vf_vsi(vf);
1072 if (!vsi) {
1073 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1074 goto err;
1075 }
1076
1077 pi = pf->hw.port_info;
1078 numtc = vsi->tc_cfg.numtc;
1079
1080 vsi_ctx = ice_get_vsi_ctx(pi->hw, vf->lan_vsi_idx);
1081 if (!vsi_ctx) {
1082 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1083 goto err;
1084 }
1085
1086 len = struct_size(cap_list, cap, numtc);
1087 cap_list = kzalloc(len, GFP_KERNEL);
1088 if (!cap_list) {
1089 v_ret = VIRTCHNL_STATUS_ERR_NO_MEMORY;
1090 len = 0;
1091 goto err;
1092 }
1093
1094 cap_list->vsi_id = vsi->vsi_num;
1095 cap_list->num_elem = numtc;
1096
1097 /* Store the UP2TC configuration from DCB to a user priority bitmap
1098 * of each TC. Each element of prio_of_tc represents one TC. Each
1099 * bitmap indicates the user priorities belong to this TC.
1100 */
1101 for (i = 0; i < ICE_MAX_USER_PRIORITY; i++) {
1102 tc = pi->qos_cfg.local_dcbx_cfg.etscfg.prio_table[i];
1103 tc_prio[tc] |= BIT(i);
1104 }
1105
1106 for (i = 0; i < numtc; i++) {
1107 cfg = &cap_list->cap[i];
1108 cfg->tc_num = i;
1109 cfg->tc_prio = tc_prio[i];
1110 cfg->arbiter = pi->qos_cfg.local_dcbx_cfg.etscfg.tsatable[i];
1111 cfg->weight = VIRTCHNL_STRICT_WEIGHT;
1112 cfg->type = VIRTCHNL_BW_SHAPER;
1113 cfg->shaper.committed = vsi_ctx->sched.bw_t_info[i].cir_bw.bw;
1114 cfg->shaper.peak = vsi_ctx->sched.bw_t_info[i].eir_bw.bw;
1115 }
1116
1117 err:
1118 ret = ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_GET_QOS_CAPS, v_ret,
1119 (u8 *)cap_list, len);
1120 kfree(cap_list);
1121 return ret;
1122 }
1123
1124 /**
1125 * ice_vf_cfg_qs_bw - Configure per queue bandwidth
1126 * @vf: pointer to the VF info
1127 * @num_queues: number of queues to be configured
1128 *
1129 * Configure per queue bandwidth.
1130 *
1131 * Return: 0 on success or negative error value.
1132 */
ice_vf_cfg_qs_bw(struct ice_vf * vf,u16 num_queues)1133 static int ice_vf_cfg_qs_bw(struct ice_vf *vf, u16 num_queues)
1134 {
1135 struct ice_hw *hw = &vf->pf->hw;
1136 struct ice_vsi *vsi;
1137 int ret;
1138 u16 i;
1139
1140 vsi = ice_get_vf_vsi(vf);
1141 if (!vsi)
1142 return -EINVAL;
1143
1144 for (i = 0; i < num_queues; i++) {
1145 u32 p_rate, min_rate;
1146 u8 tc;
1147
1148 p_rate = vf->qs_bw[i].peak;
1149 min_rate = vf->qs_bw[i].committed;
1150 tc = vf->qs_bw[i].tc;
1151 if (p_rate)
1152 ret = ice_cfg_q_bw_lmt(hw->port_info, vsi->idx, tc,
1153 vf->qs_bw[i].queue_id,
1154 ICE_MAX_BW, p_rate);
1155 else
1156 ret = ice_cfg_q_bw_dflt_lmt(hw->port_info, vsi->idx, tc,
1157 vf->qs_bw[i].queue_id,
1158 ICE_MAX_BW);
1159 if (ret)
1160 return ret;
1161
1162 if (min_rate)
1163 ret = ice_cfg_q_bw_lmt(hw->port_info, vsi->idx, tc,
1164 vf->qs_bw[i].queue_id,
1165 ICE_MIN_BW, min_rate);
1166 else
1167 ret = ice_cfg_q_bw_dflt_lmt(hw->port_info, vsi->idx, tc,
1168 vf->qs_bw[i].queue_id,
1169 ICE_MIN_BW);
1170
1171 if (ret)
1172 return ret;
1173 }
1174
1175 return 0;
1176 }
1177
1178 /**
1179 * ice_vf_cfg_q_quanta_profile - Configure quanta profile
1180 * @vf: pointer to the VF info
1181 * @quanta_prof_idx: pointer to the quanta profile index
1182 * @quanta_size: quanta size to be set
1183 *
1184 * This function chooses available quanta profile and configures the register.
1185 * The quanta profile is evenly divided by the number of device ports, and then
1186 * available to the specific PF and VFs. The first profile for each PF is a
1187 * reserved default profile. Only quanta size of the rest unused profile can be
1188 * modified.
1189 *
1190 * Return: 0 on success or negative error value.
1191 */
ice_vf_cfg_q_quanta_profile(struct ice_vf * vf,u16 quanta_size,u16 * quanta_prof_idx)1192 static int ice_vf_cfg_q_quanta_profile(struct ice_vf *vf, u16 quanta_size,
1193 u16 *quanta_prof_idx)
1194 {
1195 const u16 n_desc = calc_quanta_desc(quanta_size);
1196 struct ice_hw *hw = &vf->pf->hw;
1197 const u16 n_cmd = 2 * n_desc;
1198 struct ice_pf *pf = vf->pf;
1199 u16 per_pf, begin_id;
1200 u8 n_used;
1201 u32 reg;
1202
1203 begin_id = (GLCOMM_QUANTA_PROF_MAX_INDEX + 1) / hw->dev_caps.num_funcs *
1204 hw->logical_pf_id;
1205
1206 if (quanta_size == ICE_DFLT_QUANTA) {
1207 *quanta_prof_idx = begin_id;
1208 } else {
1209 per_pf = (GLCOMM_QUANTA_PROF_MAX_INDEX + 1) /
1210 hw->dev_caps.num_funcs;
1211 n_used = pf->num_quanta_prof_used;
1212 if (n_used < per_pf) {
1213 *quanta_prof_idx = begin_id + 1 + n_used;
1214 pf->num_quanta_prof_used++;
1215 } else {
1216 return -EINVAL;
1217 }
1218 }
1219
1220 reg = FIELD_PREP(GLCOMM_QUANTA_PROF_QUANTA_SIZE_M, quanta_size) |
1221 FIELD_PREP(GLCOMM_QUANTA_PROF_MAX_CMD_M, n_cmd) |
1222 FIELD_PREP(GLCOMM_QUANTA_PROF_MAX_DESC_M, n_desc);
1223 wr32(hw, GLCOMM_QUANTA_PROF(*quanta_prof_idx), reg);
1224
1225 return 0;
1226 }
1227
1228 /**
1229 * ice_vc_cfg_promiscuous_mode_msg
1230 * @vf: pointer to the VF info
1231 * @msg: pointer to the msg buffer
1232 *
1233 * called from the VF to configure VF VSIs promiscuous mode
1234 */
ice_vc_cfg_promiscuous_mode_msg(struct ice_vf * vf,u8 * msg)1235 static int ice_vc_cfg_promiscuous_mode_msg(struct ice_vf *vf, u8 *msg)
1236 {
1237 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
1238 bool rm_promisc, alluni = false, allmulti = false;
1239 struct virtchnl_promisc_info *info =
1240 (struct virtchnl_promisc_info *)msg;
1241 struct ice_vsi_vlan_ops *vlan_ops;
1242 int mcast_err = 0, ucast_err = 0;
1243 struct ice_pf *pf = vf->pf;
1244 struct ice_vsi *vsi;
1245 u8 mcast_m, ucast_m;
1246 struct device *dev;
1247 int ret = 0;
1248
1249 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
1250 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1251 goto error_param;
1252 }
1253
1254 if (!ice_vc_isvalid_vsi_id(vf, info->vsi_id)) {
1255 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1256 goto error_param;
1257 }
1258
1259 vsi = ice_get_vf_vsi(vf);
1260 if (!vsi) {
1261 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1262 goto error_param;
1263 }
1264
1265 dev = ice_pf_to_dev(pf);
1266 if (!ice_is_vf_trusted(vf)) {
1267 dev_err(dev, "Unprivileged VF %d is attempting to configure promiscuous mode\n",
1268 vf->vf_id);
1269 /* Leave v_ret alone, lie to the VF on purpose. */
1270 goto error_param;
1271 }
1272
1273 if (info->flags & FLAG_VF_UNICAST_PROMISC)
1274 alluni = true;
1275
1276 if (info->flags & FLAG_VF_MULTICAST_PROMISC)
1277 allmulti = true;
1278
1279 rm_promisc = !allmulti && !alluni;
1280
1281 vlan_ops = ice_get_compat_vsi_vlan_ops(vsi);
1282 if (rm_promisc)
1283 ret = vlan_ops->ena_rx_filtering(vsi);
1284 else
1285 ret = vlan_ops->dis_rx_filtering(vsi);
1286 if (ret) {
1287 dev_err(dev, "Failed to configure VLAN pruning in promiscuous mode\n");
1288 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1289 goto error_param;
1290 }
1291
1292 ice_vf_get_promisc_masks(vf, vsi, &ucast_m, &mcast_m);
1293
1294 if (!test_bit(ICE_FLAG_VF_TRUE_PROMISC_ENA, pf->flags)) {
1295 if (alluni) {
1296 /* in this case we're turning on promiscuous mode */
1297 ret = ice_set_dflt_vsi(vsi);
1298 } else {
1299 /* in this case we're turning off promiscuous mode */
1300 if (ice_is_dflt_vsi_in_use(vsi->port_info))
1301 ret = ice_clear_dflt_vsi(vsi);
1302 }
1303
1304 /* in this case we're turning on/off only
1305 * allmulticast
1306 */
1307 if (allmulti)
1308 mcast_err = ice_vf_set_vsi_promisc(vf, vsi, mcast_m);
1309 else
1310 mcast_err = ice_vf_clear_vsi_promisc(vf, vsi, mcast_m);
1311
1312 if (ret) {
1313 dev_err(dev, "Turning on/off promiscuous mode for VF %d failed, error: %d\n",
1314 vf->vf_id, ret);
1315 v_ret = VIRTCHNL_STATUS_ERR_ADMIN_QUEUE_ERROR;
1316 goto error_param;
1317 }
1318 } else {
1319 if (alluni)
1320 ucast_err = ice_vf_set_vsi_promisc(vf, vsi, ucast_m);
1321 else
1322 ucast_err = ice_vf_clear_vsi_promisc(vf, vsi, ucast_m);
1323
1324 if (allmulti)
1325 mcast_err = ice_vf_set_vsi_promisc(vf, vsi, mcast_m);
1326 else
1327 mcast_err = ice_vf_clear_vsi_promisc(vf, vsi, mcast_m);
1328
1329 if (ucast_err || mcast_err)
1330 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1331 }
1332
1333 if (!mcast_err) {
1334 if (allmulti &&
1335 !test_and_set_bit(ICE_VF_STATE_MC_PROMISC, vf->vf_states))
1336 dev_info(dev, "VF %u successfully set multicast promiscuous mode\n",
1337 vf->vf_id);
1338 else if (!allmulti &&
1339 test_and_clear_bit(ICE_VF_STATE_MC_PROMISC,
1340 vf->vf_states))
1341 dev_info(dev, "VF %u successfully unset multicast promiscuous mode\n",
1342 vf->vf_id);
1343 } else {
1344 dev_err(dev, "Error while modifying multicast promiscuous mode for VF %u, error: %d\n",
1345 vf->vf_id, mcast_err);
1346 }
1347
1348 if (!ucast_err) {
1349 if (alluni &&
1350 !test_and_set_bit(ICE_VF_STATE_UC_PROMISC, vf->vf_states))
1351 dev_info(dev, "VF %u successfully set unicast promiscuous mode\n",
1352 vf->vf_id);
1353 else if (!alluni &&
1354 test_and_clear_bit(ICE_VF_STATE_UC_PROMISC,
1355 vf->vf_states))
1356 dev_info(dev, "VF %u successfully unset unicast promiscuous mode\n",
1357 vf->vf_id);
1358 } else {
1359 dev_err(dev, "Error while modifying unicast promiscuous mode for VF %u, error: %d\n",
1360 vf->vf_id, ucast_err);
1361 }
1362
1363 error_param:
1364 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE,
1365 v_ret, NULL, 0);
1366 }
1367
1368 /**
1369 * ice_vc_get_stats_msg
1370 * @vf: pointer to the VF info
1371 * @msg: pointer to the msg buffer
1372 *
1373 * called from the VF to get VSI stats
1374 */
ice_vc_get_stats_msg(struct ice_vf * vf,u8 * msg)1375 static int ice_vc_get_stats_msg(struct ice_vf *vf, u8 *msg)
1376 {
1377 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
1378 struct virtchnl_queue_select *vqs =
1379 (struct virtchnl_queue_select *)msg;
1380 struct ice_eth_stats stats = { 0 };
1381 struct ice_vsi *vsi;
1382
1383 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
1384 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1385 goto error_param;
1386 }
1387
1388 if (!ice_vc_isvalid_vsi_id(vf, vqs->vsi_id)) {
1389 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1390 goto error_param;
1391 }
1392
1393 vsi = ice_get_vf_vsi(vf);
1394 if (!vsi) {
1395 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1396 goto error_param;
1397 }
1398
1399 ice_update_eth_stats(vsi);
1400
1401 stats = vsi->eth_stats;
1402
1403 error_param:
1404 /* send the response to the VF */
1405 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_GET_STATS, v_ret,
1406 (u8 *)&stats, sizeof(stats));
1407 }
1408
1409 /**
1410 * ice_vc_validate_vqs_bitmaps - validate Rx/Tx queue bitmaps from VIRTCHNL
1411 * @vqs: virtchnl_queue_select structure containing bitmaps to validate
1412 *
1413 * Return true on successful validation, else false
1414 */
ice_vc_validate_vqs_bitmaps(struct virtchnl_queue_select * vqs)1415 static bool ice_vc_validate_vqs_bitmaps(struct virtchnl_queue_select *vqs)
1416 {
1417 if ((!vqs->rx_queues && !vqs->tx_queues) ||
1418 vqs->rx_queues >= BIT(ICE_MAX_RSS_QS_PER_VF) ||
1419 vqs->tx_queues >= BIT(ICE_MAX_RSS_QS_PER_VF))
1420 return false;
1421
1422 return true;
1423 }
1424
1425 /**
1426 * ice_vf_ena_txq_interrupt - enable Tx queue interrupt via QINT_TQCTL
1427 * @vsi: VSI of the VF to configure
1428 * @q_idx: VF queue index used to determine the queue in the PF's space
1429 */
ice_vf_ena_txq_interrupt(struct ice_vsi * vsi,u32 q_idx)1430 static void ice_vf_ena_txq_interrupt(struct ice_vsi *vsi, u32 q_idx)
1431 {
1432 struct ice_hw *hw = &vsi->back->hw;
1433 u32 pfq = vsi->txq_map[q_idx];
1434 u32 reg;
1435
1436 reg = rd32(hw, QINT_TQCTL(pfq));
1437
1438 /* MSI-X index 0 in the VF's space is always for the OICR, which means
1439 * this is most likely a poll mode VF driver, so don't enable an
1440 * interrupt that was never configured via VIRTCHNL_OP_CONFIG_IRQ_MAP
1441 */
1442 if (!(reg & QINT_TQCTL_MSIX_INDX_M))
1443 return;
1444
1445 wr32(hw, QINT_TQCTL(pfq), reg | QINT_TQCTL_CAUSE_ENA_M);
1446 }
1447
1448 /**
1449 * ice_vf_ena_rxq_interrupt - enable Tx queue interrupt via QINT_RQCTL
1450 * @vsi: VSI of the VF to configure
1451 * @q_idx: VF queue index used to determine the queue in the PF's space
1452 */
ice_vf_ena_rxq_interrupt(struct ice_vsi * vsi,u32 q_idx)1453 static void ice_vf_ena_rxq_interrupt(struct ice_vsi *vsi, u32 q_idx)
1454 {
1455 struct ice_hw *hw = &vsi->back->hw;
1456 u32 pfq = vsi->rxq_map[q_idx];
1457 u32 reg;
1458
1459 reg = rd32(hw, QINT_RQCTL(pfq));
1460
1461 /* MSI-X index 0 in the VF's space is always for the OICR, which means
1462 * this is most likely a poll mode VF driver, so don't enable an
1463 * interrupt that was never configured via VIRTCHNL_OP_CONFIG_IRQ_MAP
1464 */
1465 if (!(reg & QINT_RQCTL_MSIX_INDX_M))
1466 return;
1467
1468 wr32(hw, QINT_RQCTL(pfq), reg | QINT_RQCTL_CAUSE_ENA_M);
1469 }
1470
1471 /**
1472 * ice_vc_ena_qs_msg
1473 * @vf: pointer to the VF info
1474 * @msg: pointer to the msg buffer
1475 *
1476 * called from the VF to enable all or specific queue(s)
1477 */
ice_vc_ena_qs_msg(struct ice_vf * vf,u8 * msg)1478 static int ice_vc_ena_qs_msg(struct ice_vf *vf, u8 *msg)
1479 {
1480 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
1481 struct virtchnl_queue_select *vqs =
1482 (struct virtchnl_queue_select *)msg;
1483 struct ice_vsi *vsi;
1484 unsigned long q_map;
1485 u16 vf_q_id;
1486
1487 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
1488 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1489 goto error_param;
1490 }
1491
1492 if (!ice_vc_isvalid_vsi_id(vf, vqs->vsi_id)) {
1493 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1494 goto error_param;
1495 }
1496
1497 if (!ice_vc_validate_vqs_bitmaps(vqs)) {
1498 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1499 goto error_param;
1500 }
1501
1502 vsi = ice_get_vf_vsi(vf);
1503 if (!vsi) {
1504 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1505 goto error_param;
1506 }
1507
1508 /* Enable only Rx rings, Tx rings were enabled by the FW when the
1509 * Tx queue group list was configured and the context bits were
1510 * programmed using ice_vsi_cfg_txqs
1511 */
1512 q_map = vqs->rx_queues;
1513 for_each_set_bit(vf_q_id, &q_map, ICE_MAX_RSS_QS_PER_VF) {
1514 if (!ice_vc_isvalid_q_id(vsi, vf_q_id)) {
1515 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1516 goto error_param;
1517 }
1518
1519 /* Skip queue if enabled */
1520 if (test_bit(vf_q_id, vf->rxq_ena))
1521 continue;
1522
1523 if (ice_vsi_ctrl_one_rx_ring(vsi, true, vf_q_id, true)) {
1524 dev_err(ice_pf_to_dev(vsi->back), "Failed to enable Rx ring %d on VSI %d\n",
1525 vf_q_id, vsi->vsi_num);
1526 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1527 goto error_param;
1528 }
1529
1530 ice_vf_ena_rxq_interrupt(vsi, vf_q_id);
1531 set_bit(vf_q_id, vf->rxq_ena);
1532 }
1533
1534 q_map = vqs->tx_queues;
1535 for_each_set_bit(vf_q_id, &q_map, ICE_MAX_RSS_QS_PER_VF) {
1536 if (!ice_vc_isvalid_q_id(vsi, vf_q_id)) {
1537 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1538 goto error_param;
1539 }
1540
1541 /* Skip queue if enabled */
1542 if (test_bit(vf_q_id, vf->txq_ena))
1543 continue;
1544
1545 ice_vf_ena_txq_interrupt(vsi, vf_q_id);
1546 set_bit(vf_q_id, vf->txq_ena);
1547 }
1548
1549 /* Set flag to indicate that queues are enabled */
1550 if (v_ret == VIRTCHNL_STATUS_SUCCESS)
1551 set_bit(ICE_VF_STATE_QS_ENA, vf->vf_states);
1552
1553 error_param:
1554 /* send the response to the VF */
1555 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_ENABLE_QUEUES, v_ret,
1556 NULL, 0);
1557 }
1558
1559 /**
1560 * ice_vf_vsi_dis_single_txq - disable a single Tx queue
1561 * @vf: VF to disable queue for
1562 * @vsi: VSI for the VF
1563 * @q_id: VF relative (0-based) queue ID
1564 *
1565 * Attempt to disable the Tx queue passed in. If the Tx queue was successfully
1566 * disabled then clear q_id bit in the enabled queues bitmap and return
1567 * success. Otherwise return error.
1568 */
1569 static int
ice_vf_vsi_dis_single_txq(struct ice_vf * vf,struct ice_vsi * vsi,u16 q_id)1570 ice_vf_vsi_dis_single_txq(struct ice_vf *vf, struct ice_vsi *vsi, u16 q_id)
1571 {
1572 struct ice_txq_meta txq_meta = { 0 };
1573 struct ice_tx_ring *ring;
1574 int err;
1575
1576 if (!test_bit(q_id, vf->txq_ena))
1577 dev_dbg(ice_pf_to_dev(vsi->back), "Queue %u on VSI %u is not enabled, but stopping it anyway\n",
1578 q_id, vsi->vsi_num);
1579
1580 ring = vsi->tx_rings[q_id];
1581 if (!ring)
1582 return -EINVAL;
1583
1584 ice_fill_txq_meta(vsi, ring, &txq_meta);
1585
1586 err = ice_vsi_stop_tx_ring(vsi, ICE_NO_RESET, vf->vf_id, ring, &txq_meta);
1587 if (err) {
1588 dev_err(ice_pf_to_dev(vsi->back), "Failed to stop Tx ring %d on VSI %d\n",
1589 q_id, vsi->vsi_num);
1590 return err;
1591 }
1592
1593 /* Clear enabled queues flag */
1594 clear_bit(q_id, vf->txq_ena);
1595
1596 return 0;
1597 }
1598
1599 /**
1600 * ice_vc_dis_qs_msg
1601 * @vf: pointer to the VF info
1602 * @msg: pointer to the msg buffer
1603 *
1604 * called from the VF to disable all or specific queue(s)
1605 */
ice_vc_dis_qs_msg(struct ice_vf * vf,u8 * msg)1606 static int ice_vc_dis_qs_msg(struct ice_vf *vf, u8 *msg)
1607 {
1608 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
1609 struct virtchnl_queue_select *vqs =
1610 (struct virtchnl_queue_select *)msg;
1611 struct ice_vsi *vsi;
1612 unsigned long q_map;
1613 u16 vf_q_id;
1614
1615 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states) &&
1616 !test_bit(ICE_VF_STATE_QS_ENA, vf->vf_states)) {
1617 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1618 goto error_param;
1619 }
1620
1621 if (!ice_vc_isvalid_vsi_id(vf, vqs->vsi_id)) {
1622 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1623 goto error_param;
1624 }
1625
1626 if (!ice_vc_validate_vqs_bitmaps(vqs)) {
1627 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1628 goto error_param;
1629 }
1630
1631 vsi = ice_get_vf_vsi(vf);
1632 if (!vsi) {
1633 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1634 goto error_param;
1635 }
1636
1637 if (vqs->tx_queues) {
1638 q_map = vqs->tx_queues;
1639
1640 for_each_set_bit(vf_q_id, &q_map, ICE_MAX_RSS_QS_PER_VF) {
1641 if (!ice_vc_isvalid_q_id(vsi, vf_q_id)) {
1642 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1643 goto error_param;
1644 }
1645
1646 if (ice_vf_vsi_dis_single_txq(vf, vsi, vf_q_id)) {
1647 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1648 goto error_param;
1649 }
1650 }
1651 }
1652
1653 q_map = vqs->rx_queues;
1654 /* speed up Rx queue disable by batching them if possible */
1655 if (q_map &&
1656 bitmap_equal(&q_map, vf->rxq_ena, ICE_MAX_RSS_QS_PER_VF)) {
1657 if (ice_vsi_stop_all_rx_rings(vsi)) {
1658 dev_err(ice_pf_to_dev(vsi->back), "Failed to stop all Rx rings on VSI %d\n",
1659 vsi->vsi_num);
1660 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1661 goto error_param;
1662 }
1663
1664 bitmap_zero(vf->rxq_ena, ICE_MAX_RSS_QS_PER_VF);
1665 } else if (q_map) {
1666 for_each_set_bit(vf_q_id, &q_map, ICE_MAX_RSS_QS_PER_VF) {
1667 if (!ice_vc_isvalid_q_id(vsi, vf_q_id)) {
1668 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1669 goto error_param;
1670 }
1671
1672 /* Skip queue if not enabled */
1673 if (!test_bit(vf_q_id, vf->rxq_ena))
1674 continue;
1675
1676 if (ice_vsi_ctrl_one_rx_ring(vsi, false, vf_q_id,
1677 true)) {
1678 dev_err(ice_pf_to_dev(vsi->back), "Failed to stop Rx ring %d on VSI %d\n",
1679 vf_q_id, vsi->vsi_num);
1680 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1681 goto error_param;
1682 }
1683
1684 /* Clear enabled queues flag */
1685 clear_bit(vf_q_id, vf->rxq_ena);
1686 }
1687 }
1688
1689 /* Clear enabled queues flag */
1690 if (v_ret == VIRTCHNL_STATUS_SUCCESS && ice_vf_has_no_qs_ena(vf))
1691 clear_bit(ICE_VF_STATE_QS_ENA, vf->vf_states);
1692
1693 error_param:
1694 /* send the response to the VF */
1695 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_DISABLE_QUEUES, v_ret,
1696 NULL, 0);
1697 }
1698
1699 /**
1700 * ice_cfg_interrupt
1701 * @vf: pointer to the VF info
1702 * @vsi: the VSI being configured
1703 * @map: vector map for mapping vectors to queues
1704 * @q_vector: structure for interrupt vector
1705 * configure the IRQ to queue map
1706 */
1707 static enum virtchnl_status_code
ice_cfg_interrupt(struct ice_vf * vf,struct ice_vsi * vsi,struct virtchnl_vector_map * map,struct ice_q_vector * q_vector)1708 ice_cfg_interrupt(struct ice_vf *vf, struct ice_vsi *vsi,
1709 struct virtchnl_vector_map *map,
1710 struct ice_q_vector *q_vector)
1711 {
1712 u16 vsi_q_id, vsi_q_id_idx;
1713 unsigned long qmap;
1714
1715 q_vector->num_ring_rx = 0;
1716 q_vector->num_ring_tx = 0;
1717
1718 qmap = map->rxq_map;
1719 for_each_set_bit(vsi_q_id_idx, &qmap, ICE_MAX_RSS_QS_PER_VF) {
1720 vsi_q_id = vsi_q_id_idx;
1721
1722 if (!ice_vc_isvalid_q_id(vsi, vsi_q_id))
1723 return VIRTCHNL_STATUS_ERR_PARAM;
1724
1725 q_vector->num_ring_rx++;
1726 q_vector->rx.itr_idx = map->rxitr_idx;
1727 vsi->rx_rings[vsi_q_id]->q_vector = q_vector;
1728 ice_cfg_rxq_interrupt(vsi, vsi_q_id,
1729 q_vector->vf_reg_idx,
1730 q_vector->rx.itr_idx);
1731 }
1732
1733 qmap = map->txq_map;
1734 for_each_set_bit(vsi_q_id_idx, &qmap, ICE_MAX_RSS_QS_PER_VF) {
1735 vsi_q_id = vsi_q_id_idx;
1736
1737 if (!ice_vc_isvalid_q_id(vsi, vsi_q_id))
1738 return VIRTCHNL_STATUS_ERR_PARAM;
1739
1740 q_vector->num_ring_tx++;
1741 q_vector->tx.itr_idx = map->txitr_idx;
1742 vsi->tx_rings[vsi_q_id]->q_vector = q_vector;
1743 ice_cfg_txq_interrupt(vsi, vsi_q_id,
1744 q_vector->vf_reg_idx,
1745 q_vector->tx.itr_idx);
1746 }
1747
1748 return VIRTCHNL_STATUS_SUCCESS;
1749 }
1750
1751 /**
1752 * ice_vc_cfg_irq_map_msg
1753 * @vf: pointer to the VF info
1754 * @msg: pointer to the msg buffer
1755 *
1756 * called from the VF to configure the IRQ to queue map
1757 */
ice_vc_cfg_irq_map_msg(struct ice_vf * vf,u8 * msg)1758 static int ice_vc_cfg_irq_map_msg(struct ice_vf *vf, u8 *msg)
1759 {
1760 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
1761 u16 num_q_vectors_mapped, vsi_id, vector_id;
1762 struct virtchnl_irq_map_info *irqmap_info;
1763 struct virtchnl_vector_map *map;
1764 struct ice_vsi *vsi;
1765 int i;
1766
1767 irqmap_info = (struct virtchnl_irq_map_info *)msg;
1768 num_q_vectors_mapped = irqmap_info->num_vectors;
1769
1770 /* Check to make sure number of VF vectors mapped is not greater than
1771 * number of VF vectors originally allocated, and check that
1772 * there is actually at least a single VF queue vector mapped
1773 */
1774 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states) ||
1775 vf->num_msix < num_q_vectors_mapped ||
1776 !num_q_vectors_mapped) {
1777 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1778 goto error_param;
1779 }
1780
1781 vsi = ice_get_vf_vsi(vf);
1782 if (!vsi) {
1783 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1784 goto error_param;
1785 }
1786
1787 for (i = 0; i < num_q_vectors_mapped; i++) {
1788 struct ice_q_vector *q_vector;
1789
1790 map = &irqmap_info->vecmap[i];
1791
1792 vector_id = map->vector_id;
1793 vsi_id = map->vsi_id;
1794 /* vector_id is always 0-based for each VF, and can never be
1795 * larger than or equal to the max allowed interrupts per VF
1796 */
1797 if (!(vector_id < vf->num_msix) ||
1798 !ice_vc_isvalid_vsi_id(vf, vsi_id) ||
1799 (!vector_id && (map->rxq_map || map->txq_map))) {
1800 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1801 goto error_param;
1802 }
1803
1804 /* No need to map VF miscellaneous or rogue vector */
1805 if (!vector_id)
1806 continue;
1807
1808 /* Subtract non queue vector from vector_id passed by VF
1809 * to get actual number of VSI queue vector array index
1810 */
1811 q_vector = vsi->q_vectors[vector_id - ICE_NONQ_VECS_VF];
1812 if (!q_vector) {
1813 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1814 goto error_param;
1815 }
1816
1817 /* lookout for the invalid queue index */
1818 v_ret = ice_cfg_interrupt(vf, vsi, map, q_vector);
1819 if (v_ret)
1820 goto error_param;
1821 }
1822
1823 error_param:
1824 /* send the response to the VF */
1825 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_CONFIG_IRQ_MAP, v_ret,
1826 NULL, 0);
1827 }
1828
1829 /**
1830 * ice_vc_cfg_q_bw - Configure per queue bandwidth
1831 * @vf: pointer to the VF info
1832 * @msg: pointer to the msg buffer which holds the command descriptor
1833 *
1834 * Configure VF queues bandwidth.
1835 *
1836 * Return: 0 on success or negative error value.
1837 */
ice_vc_cfg_q_bw(struct ice_vf * vf,u8 * msg)1838 static int ice_vc_cfg_q_bw(struct ice_vf *vf, u8 *msg)
1839 {
1840 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
1841 struct virtchnl_queues_bw_cfg *qbw =
1842 (struct virtchnl_queues_bw_cfg *)msg;
1843 struct ice_vsi *vsi;
1844 u16 i;
1845
1846 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states) ||
1847 !ice_vc_isvalid_vsi_id(vf, qbw->vsi_id)) {
1848 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1849 goto err;
1850 }
1851
1852 vsi = ice_get_vf_vsi(vf);
1853 if (!vsi) {
1854 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1855 goto err;
1856 }
1857
1858 if (qbw->num_queues > ICE_MAX_RSS_QS_PER_VF ||
1859 qbw->num_queues > min_t(u16, vsi->alloc_txq, vsi->alloc_rxq)) {
1860 dev_err(ice_pf_to_dev(vf->pf), "VF-%d trying to configure more than allocated number of queues: %d\n",
1861 vf->vf_id, min_t(u16, vsi->alloc_txq, vsi->alloc_rxq));
1862 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1863 goto err;
1864 }
1865
1866 for (i = 0; i < qbw->num_queues; i++) {
1867 if (qbw->cfg[i].shaper.peak != 0 && vf->max_tx_rate != 0 &&
1868 qbw->cfg[i].shaper.peak > vf->max_tx_rate) {
1869 dev_warn(ice_pf_to_dev(vf->pf), "The maximum queue %d rate limit configuration may not take effect because the maximum TX rate for VF-%d is %d\n",
1870 qbw->cfg[i].queue_id, vf->vf_id,
1871 vf->max_tx_rate);
1872 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1873 goto err;
1874 }
1875 if (qbw->cfg[i].shaper.committed != 0 && vf->min_tx_rate != 0 &&
1876 qbw->cfg[i].shaper.committed < vf->min_tx_rate) {
1877 dev_warn(ice_pf_to_dev(vf->pf), "The minimum queue %d rate limit configuration may not take effect because the minimum TX rate for VF-%d is %d\n",
1878 qbw->cfg[i].queue_id, vf->vf_id,
1879 vf->min_tx_rate);
1880 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1881 goto err;
1882 }
1883 if (qbw->cfg[i].queue_id > vf->num_vf_qs) {
1884 dev_warn(ice_pf_to_dev(vf->pf), "VF-%d trying to configure invalid queue_id\n",
1885 vf->vf_id);
1886 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1887 goto err;
1888 }
1889 if (qbw->cfg[i].tc >= ICE_MAX_TRAFFIC_CLASS) {
1890 dev_warn(ice_pf_to_dev(vf->pf), "VF-%d trying to configure a traffic class higher than allowed\n",
1891 vf->vf_id);
1892 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1893 goto err;
1894 }
1895 }
1896
1897 for (i = 0; i < qbw->num_queues; i++) {
1898 vf->qs_bw[i].queue_id = qbw->cfg[i].queue_id;
1899 vf->qs_bw[i].peak = qbw->cfg[i].shaper.peak;
1900 vf->qs_bw[i].committed = qbw->cfg[i].shaper.committed;
1901 vf->qs_bw[i].tc = qbw->cfg[i].tc;
1902 }
1903
1904 if (ice_vf_cfg_qs_bw(vf, qbw->num_queues))
1905 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1906
1907 err:
1908 /* send the response to the VF */
1909 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_CONFIG_QUEUE_BW,
1910 v_ret, NULL, 0);
1911 }
1912
1913 /**
1914 * ice_vc_cfg_q_quanta - Configure per queue quanta
1915 * @vf: pointer to the VF info
1916 * @msg: pointer to the msg buffer which holds the command descriptor
1917 *
1918 * Configure VF queues quanta.
1919 *
1920 * Return: 0 on success or negative error value.
1921 */
ice_vc_cfg_q_quanta(struct ice_vf * vf,u8 * msg)1922 static int ice_vc_cfg_q_quanta(struct ice_vf *vf, u8 *msg)
1923 {
1924 u16 quanta_prof_id, quanta_size, start_qid, num_queues, end_qid, i;
1925 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
1926 struct virtchnl_quanta_cfg *qquanta =
1927 (struct virtchnl_quanta_cfg *)msg;
1928 struct ice_vsi *vsi;
1929 int ret;
1930
1931 start_qid = qquanta->queue_select.start_queue_id;
1932 num_queues = qquanta->queue_select.num_queues;
1933
1934 if (check_add_overflow(start_qid, num_queues, &end_qid)) {
1935 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1936 goto err;
1937 }
1938
1939 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
1940 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1941 goto err;
1942 }
1943
1944 vsi = ice_get_vf_vsi(vf);
1945 if (!vsi) {
1946 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1947 goto err;
1948 }
1949
1950 if (end_qid > ICE_MAX_RSS_QS_PER_VF ||
1951 end_qid > min_t(u16, vsi->alloc_txq, vsi->alloc_rxq)) {
1952 dev_err(ice_pf_to_dev(vf->pf), "VF-%d trying to configure more than allocated number of queues: %d\n",
1953 vf->vf_id, min_t(u16, vsi->alloc_txq, vsi->alloc_rxq));
1954 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1955 goto err;
1956 }
1957
1958 quanta_size = qquanta->quanta_size;
1959 if (quanta_size > ICE_MAX_QUANTA_SIZE ||
1960 quanta_size < ICE_MIN_QUANTA_SIZE) {
1961 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1962 goto err;
1963 }
1964
1965 if (quanta_size % 64) {
1966 dev_err(ice_pf_to_dev(vf->pf), "quanta size should be the product of 64\n");
1967 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1968 goto err;
1969 }
1970
1971 ret = ice_vf_cfg_q_quanta_profile(vf, quanta_size,
1972 &quanta_prof_id);
1973 if (ret) {
1974 v_ret = VIRTCHNL_STATUS_ERR_NOT_SUPPORTED;
1975 goto err;
1976 }
1977
1978 for (i = start_qid; i < end_qid; i++)
1979 vsi->tx_rings[i]->quanta_prof_id = quanta_prof_id;
1980
1981 err:
1982 /* send the response to the VF */
1983 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_CONFIG_QUANTA,
1984 v_ret, NULL, 0);
1985 }
1986
1987 /**
1988 * ice_vc_cfg_qs_msg
1989 * @vf: pointer to the VF info
1990 * @msg: pointer to the msg buffer
1991 *
1992 * called from the VF to configure the Rx/Tx queues
1993 */
ice_vc_cfg_qs_msg(struct ice_vf * vf,u8 * msg)1994 static int ice_vc_cfg_qs_msg(struct ice_vf *vf, u8 *msg)
1995 {
1996 struct virtchnl_vsi_queue_config_info *qci =
1997 (struct virtchnl_vsi_queue_config_info *)msg;
1998 struct virtchnl_queue_pair_info *qpi;
1999 struct ice_pf *pf = vf->pf;
2000 struct ice_lag *lag;
2001 struct ice_vsi *vsi;
2002 u8 act_prt, pri_prt;
2003 int i = -1, q_idx;
2004 bool ena_ts;
2005
2006 lag = pf->lag;
2007 mutex_lock(&pf->lag_mutex);
2008 act_prt = ICE_LAG_INVALID_PORT;
2009 pri_prt = pf->hw.port_info->lport;
2010 if (lag && lag->bonded && lag->primary) {
2011 act_prt = lag->active_port;
2012 if (act_prt != pri_prt && act_prt != ICE_LAG_INVALID_PORT &&
2013 lag->upper_netdev)
2014 ice_lag_move_vf_nodes_cfg(lag, act_prt, pri_prt);
2015 else
2016 act_prt = ICE_LAG_INVALID_PORT;
2017 }
2018
2019 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states))
2020 goto error_param;
2021
2022 if (!ice_vc_isvalid_vsi_id(vf, qci->vsi_id))
2023 goto error_param;
2024
2025 vsi = ice_get_vf_vsi(vf);
2026 if (!vsi)
2027 goto error_param;
2028
2029 if (qci->num_queue_pairs > ICE_MAX_RSS_QS_PER_VF ||
2030 qci->num_queue_pairs > min_t(u16, vsi->alloc_txq, vsi->alloc_rxq)) {
2031 dev_err(ice_pf_to_dev(pf), "VF-%d requesting more than supported number of queues: %d\n",
2032 vf->vf_id, min_t(u16, vsi->alloc_txq, vsi->alloc_rxq));
2033 goto error_param;
2034 }
2035
2036 for (i = 0; i < qci->num_queue_pairs; i++) {
2037 if (!qci->qpair[i].rxq.crc_disable)
2038 continue;
2039
2040 if (!(vf->driver_caps & VIRTCHNL_VF_OFFLOAD_CRC) ||
2041 vf->vlan_strip_ena)
2042 goto error_param;
2043 }
2044
2045 for (i = 0; i < qci->num_queue_pairs; i++) {
2046 qpi = &qci->qpair[i];
2047 if (qpi->txq.vsi_id != qci->vsi_id ||
2048 qpi->rxq.vsi_id != qci->vsi_id ||
2049 qpi->rxq.queue_id != qpi->txq.queue_id ||
2050 qpi->txq.headwb_enabled ||
2051 !ice_vc_isvalid_ring_len(qpi->txq.ring_len) ||
2052 !ice_vc_isvalid_ring_len(qpi->rxq.ring_len) ||
2053 !ice_vc_isvalid_q_id(vsi, qpi->txq.queue_id)) {
2054 goto error_param;
2055 }
2056
2057 q_idx = qpi->rxq.queue_id;
2058
2059 /* make sure selected "q_idx" is in valid range of queues
2060 * for selected "vsi"
2061 */
2062 if (q_idx >= vsi->alloc_txq || q_idx >= vsi->alloc_rxq) {
2063 goto error_param;
2064 }
2065
2066 /* copy Tx queue info from VF into VSI */
2067 if (qpi->txq.ring_len > 0) {
2068 vsi->tx_rings[q_idx]->dma = qpi->txq.dma_ring_addr;
2069 vsi->tx_rings[q_idx]->count = qpi->txq.ring_len;
2070
2071 /* Disable any existing queue first */
2072 if (ice_vf_vsi_dis_single_txq(vf, vsi, q_idx))
2073 goto error_param;
2074
2075 /* Configure a queue with the requested settings */
2076 if (ice_vsi_cfg_single_txq(vsi, vsi->tx_rings, q_idx)) {
2077 dev_warn(ice_pf_to_dev(pf), "VF-%d failed to configure TX queue %d\n",
2078 vf->vf_id, q_idx);
2079 goto error_param;
2080 }
2081 }
2082
2083 /* copy Rx queue info from VF into VSI */
2084 if (qpi->rxq.ring_len > 0) {
2085 u16 max_frame_size = ice_vc_get_max_frame_size(vf);
2086 struct ice_rx_ring *ring = vsi->rx_rings[q_idx];
2087 u32 rxdid;
2088
2089 ring->dma = qpi->rxq.dma_ring_addr;
2090 ring->count = qpi->rxq.ring_len;
2091
2092 if (qpi->rxq.crc_disable)
2093 ring->flags |= ICE_RX_FLAGS_CRC_STRIP_DIS;
2094 else
2095 ring->flags &= ~ICE_RX_FLAGS_CRC_STRIP_DIS;
2096
2097 if (qpi->rxq.databuffer_size != 0 &&
2098 (qpi->rxq.databuffer_size > ((16 * 1024) - 128) ||
2099 qpi->rxq.databuffer_size < 1024))
2100 goto error_param;
2101 ring->rx_buf_len = qpi->rxq.databuffer_size;
2102 if (qpi->rxq.max_pkt_size > max_frame_size ||
2103 qpi->rxq.max_pkt_size < 64)
2104 goto error_param;
2105
2106 ring->max_frame = qpi->rxq.max_pkt_size;
2107 /* add space for the port VLAN since the VF driver is
2108 * not expected to account for it in the MTU
2109 * calculation
2110 */
2111 if (ice_vf_is_port_vlan_ena(vf))
2112 ring->max_frame += VLAN_HLEN;
2113
2114 if (ice_vsi_cfg_single_rxq(vsi, q_idx)) {
2115 dev_warn(ice_pf_to_dev(pf), "VF-%d failed to configure RX queue %d\n",
2116 vf->vf_id, q_idx);
2117 goto error_param;
2118 }
2119
2120 /* If Rx flex desc is supported, select RXDID for Rx
2121 * queues. Otherwise, use legacy 32byte descriptor
2122 * format. Legacy 16byte descriptor is not supported.
2123 * If this RXDID is selected, return error.
2124 */
2125 if (vf->driver_caps &
2126 VIRTCHNL_VF_OFFLOAD_RX_FLEX_DESC) {
2127 rxdid = qpi->rxq.rxdid;
2128 if (!(BIT(rxdid) & pf->supported_rxdids))
2129 goto error_param;
2130 } else {
2131 rxdid = ICE_RXDID_LEGACY_1;
2132 }
2133
2134 ena_ts = ((vf->driver_caps &
2135 VIRTCHNL_VF_OFFLOAD_RX_FLEX_DESC) &&
2136 (vf->driver_caps & VIRTCHNL_VF_CAP_PTP) &&
2137 (qpi->rxq.flags & VIRTCHNL_PTP_RX_TSTAMP));
2138
2139 ice_write_qrxflxp_cntxt(&vsi->back->hw,
2140 vsi->rxq_map[q_idx], rxdid,
2141 ICE_RXDID_PRIO, ena_ts);
2142 }
2143 }
2144
2145 if (lag && lag->bonded && lag->primary &&
2146 act_prt != ICE_LAG_INVALID_PORT)
2147 ice_lag_move_vf_nodes_cfg(lag, pri_prt, act_prt);
2148 mutex_unlock(&pf->lag_mutex);
2149
2150 /* send the response to the VF */
2151 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_CONFIG_VSI_QUEUES,
2152 VIRTCHNL_STATUS_SUCCESS, NULL, 0);
2153 error_param:
2154 /* disable whatever we can */
2155 for (; i >= 0; i--) {
2156 if (ice_vsi_ctrl_one_rx_ring(vsi, false, i, true))
2157 dev_err(ice_pf_to_dev(pf), "VF-%d could not disable RX queue %d\n",
2158 vf->vf_id, i);
2159 if (ice_vf_vsi_dis_single_txq(vf, vsi, i))
2160 dev_err(ice_pf_to_dev(pf), "VF-%d could not disable TX queue %d\n",
2161 vf->vf_id, i);
2162 }
2163
2164 if (lag && lag->bonded && lag->primary &&
2165 act_prt != ICE_LAG_INVALID_PORT)
2166 ice_lag_move_vf_nodes_cfg(lag, pri_prt, act_prt);
2167 mutex_unlock(&pf->lag_mutex);
2168
2169 ice_lag_move_new_vf_nodes(vf);
2170
2171 /* send the response to the VF */
2172 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_CONFIG_VSI_QUEUES,
2173 VIRTCHNL_STATUS_ERR_PARAM, NULL, 0);
2174 }
2175
2176 /**
2177 * ice_can_vf_change_mac
2178 * @vf: pointer to the VF info
2179 *
2180 * Return true if the VF is allowed to change its MAC filters, false otherwise
2181 */
ice_can_vf_change_mac(struct ice_vf * vf)2182 static bool ice_can_vf_change_mac(struct ice_vf *vf)
2183 {
2184 /* If the VF MAC address has been set administratively (via the
2185 * ndo_set_vf_mac command), then deny permission to the VF to
2186 * add/delete unicast MAC addresses, unless the VF is trusted
2187 */
2188 if (vf->pf_set_mac && !ice_is_vf_trusted(vf))
2189 return false;
2190
2191 return true;
2192 }
2193
2194 /**
2195 * ice_vc_ether_addr_type - get type of virtchnl_ether_addr
2196 * @vc_ether_addr: used to extract the type
2197 */
2198 static u8
ice_vc_ether_addr_type(struct virtchnl_ether_addr * vc_ether_addr)2199 ice_vc_ether_addr_type(struct virtchnl_ether_addr *vc_ether_addr)
2200 {
2201 return (vc_ether_addr->type & VIRTCHNL_ETHER_ADDR_TYPE_MASK);
2202 }
2203
2204 /**
2205 * ice_is_vc_addr_legacy - check if the MAC address is from an older VF
2206 * @vc_ether_addr: VIRTCHNL structure that contains MAC and type
2207 */
2208 static bool
ice_is_vc_addr_legacy(struct virtchnl_ether_addr * vc_ether_addr)2209 ice_is_vc_addr_legacy(struct virtchnl_ether_addr *vc_ether_addr)
2210 {
2211 u8 type = ice_vc_ether_addr_type(vc_ether_addr);
2212
2213 return (type == VIRTCHNL_ETHER_ADDR_LEGACY);
2214 }
2215
2216 /**
2217 * ice_is_vc_addr_primary - check if the MAC address is the VF's primary MAC
2218 * @vc_ether_addr: VIRTCHNL structure that contains MAC and type
2219 *
2220 * This function should only be called when the MAC address in
2221 * virtchnl_ether_addr is a valid unicast MAC
2222 */
2223 static bool
ice_is_vc_addr_primary(struct virtchnl_ether_addr __maybe_unused * vc_ether_addr)2224 ice_is_vc_addr_primary(struct virtchnl_ether_addr __maybe_unused *vc_ether_addr)
2225 {
2226 u8 type = ice_vc_ether_addr_type(vc_ether_addr);
2227
2228 return (type == VIRTCHNL_ETHER_ADDR_PRIMARY);
2229 }
2230
2231 /**
2232 * ice_vfhw_mac_add - update the VF's cached hardware MAC if allowed
2233 * @vf: VF to update
2234 * @vc_ether_addr: structure from VIRTCHNL with MAC to add
2235 */
2236 static void
ice_vfhw_mac_add(struct ice_vf * vf,struct virtchnl_ether_addr * vc_ether_addr)2237 ice_vfhw_mac_add(struct ice_vf *vf, struct virtchnl_ether_addr *vc_ether_addr)
2238 {
2239 u8 *mac_addr = vc_ether_addr->addr;
2240
2241 if (!is_valid_ether_addr(mac_addr))
2242 return;
2243
2244 /* only allow legacy VF drivers to set the device and hardware MAC if it
2245 * is zero and allow new VF drivers to set the hardware MAC if the type
2246 * was correctly specified over VIRTCHNL
2247 */
2248 if ((ice_is_vc_addr_legacy(vc_ether_addr) &&
2249 is_zero_ether_addr(vf->hw_lan_addr)) ||
2250 ice_is_vc_addr_primary(vc_ether_addr)) {
2251 ether_addr_copy(vf->dev_lan_addr, mac_addr);
2252 ether_addr_copy(vf->hw_lan_addr, mac_addr);
2253 }
2254
2255 /* hardware and device MACs are already set, but its possible that the
2256 * VF driver sent the VIRTCHNL_OP_ADD_ETH_ADDR message before the
2257 * VIRTCHNL_OP_DEL_ETH_ADDR when trying to update its MAC, so save it
2258 * away for the legacy VF driver case as it will be updated in the
2259 * delete flow for this case
2260 */
2261 if (ice_is_vc_addr_legacy(vc_ether_addr)) {
2262 ether_addr_copy(vf->legacy_last_added_umac.addr,
2263 mac_addr);
2264 vf->legacy_last_added_umac.time_modified = jiffies;
2265 }
2266 }
2267
2268 /**
2269 * ice_vc_add_mac_addr - attempt to add the MAC address passed in
2270 * @vf: pointer to the VF info
2271 * @vsi: pointer to the VF's VSI
2272 * @vc_ether_addr: VIRTCHNL MAC address structure used to add MAC
2273 */
2274 static int
ice_vc_add_mac_addr(struct ice_vf * vf,struct ice_vsi * vsi,struct virtchnl_ether_addr * vc_ether_addr)2275 ice_vc_add_mac_addr(struct ice_vf *vf, struct ice_vsi *vsi,
2276 struct virtchnl_ether_addr *vc_ether_addr)
2277 {
2278 struct device *dev = ice_pf_to_dev(vf->pf);
2279 u8 *mac_addr = vc_ether_addr->addr;
2280 int ret;
2281
2282 /* device MAC already added */
2283 if (ether_addr_equal(mac_addr, vf->dev_lan_addr))
2284 return 0;
2285
2286 if (is_unicast_ether_addr(mac_addr) && !ice_can_vf_change_mac(vf)) {
2287 dev_err(dev, "VF attempting to override administratively set MAC address, bring down and up the VF interface to resume normal operation\n");
2288 return -EPERM;
2289 }
2290
2291 ret = ice_fltr_add_mac(vsi, mac_addr, ICE_FWD_TO_VSI);
2292 if (ret == -EEXIST) {
2293 dev_dbg(dev, "MAC %pM already exists for VF %d\n", mac_addr,
2294 vf->vf_id);
2295 /* don't return since we might need to update
2296 * the primary MAC in ice_vfhw_mac_add() below
2297 */
2298 } else if (ret) {
2299 dev_err(dev, "Failed to add MAC %pM for VF %d\n, error %d\n",
2300 mac_addr, vf->vf_id, ret);
2301 return ret;
2302 } else {
2303 vf->num_mac++;
2304 }
2305
2306 ice_vfhw_mac_add(vf, vc_ether_addr);
2307
2308 return ret;
2309 }
2310
2311 /**
2312 * ice_is_legacy_umac_expired - check if last added legacy unicast MAC expired
2313 * @last_added_umac: structure used to check expiration
2314 */
ice_is_legacy_umac_expired(struct ice_time_mac * last_added_umac)2315 static bool ice_is_legacy_umac_expired(struct ice_time_mac *last_added_umac)
2316 {
2317 #define ICE_LEGACY_VF_MAC_CHANGE_EXPIRE_TIME msecs_to_jiffies(3000)
2318 return time_is_before_jiffies(last_added_umac->time_modified +
2319 ICE_LEGACY_VF_MAC_CHANGE_EXPIRE_TIME);
2320 }
2321
2322 /**
2323 * ice_update_legacy_cached_mac - update cached hardware MAC for legacy VF
2324 * @vf: VF to update
2325 * @vc_ether_addr: structure from VIRTCHNL with MAC to check
2326 *
2327 * only update cached hardware MAC for legacy VF drivers on delete
2328 * because we cannot guarantee order/type of MAC from the VF driver
2329 */
2330 static void
ice_update_legacy_cached_mac(struct ice_vf * vf,struct virtchnl_ether_addr * vc_ether_addr)2331 ice_update_legacy_cached_mac(struct ice_vf *vf,
2332 struct virtchnl_ether_addr *vc_ether_addr)
2333 {
2334 if (!ice_is_vc_addr_legacy(vc_ether_addr) ||
2335 ice_is_legacy_umac_expired(&vf->legacy_last_added_umac))
2336 return;
2337
2338 ether_addr_copy(vf->dev_lan_addr, vf->legacy_last_added_umac.addr);
2339 ether_addr_copy(vf->hw_lan_addr, vf->legacy_last_added_umac.addr);
2340 }
2341
2342 /**
2343 * ice_vfhw_mac_del - update the VF's cached hardware MAC if allowed
2344 * @vf: VF to update
2345 * @vc_ether_addr: structure from VIRTCHNL with MAC to delete
2346 */
2347 static void
ice_vfhw_mac_del(struct ice_vf * vf,struct virtchnl_ether_addr * vc_ether_addr)2348 ice_vfhw_mac_del(struct ice_vf *vf, struct virtchnl_ether_addr *vc_ether_addr)
2349 {
2350 u8 *mac_addr = vc_ether_addr->addr;
2351
2352 if (!is_valid_ether_addr(mac_addr) ||
2353 !ether_addr_equal(vf->dev_lan_addr, mac_addr))
2354 return;
2355
2356 /* allow the device MAC to be repopulated in the add flow and don't
2357 * clear the hardware MAC (i.e. hw_lan_addr) here as that is meant
2358 * to be persistent on VM reboot and across driver unload/load, which
2359 * won't work if we clear the hardware MAC here
2360 */
2361 eth_zero_addr(vf->dev_lan_addr);
2362
2363 ice_update_legacy_cached_mac(vf, vc_ether_addr);
2364 }
2365
2366 /**
2367 * ice_vc_del_mac_addr - attempt to delete the MAC address passed in
2368 * @vf: pointer to the VF info
2369 * @vsi: pointer to the VF's VSI
2370 * @vc_ether_addr: VIRTCHNL MAC address structure used to delete MAC
2371 */
2372 static int
ice_vc_del_mac_addr(struct ice_vf * vf,struct ice_vsi * vsi,struct virtchnl_ether_addr * vc_ether_addr)2373 ice_vc_del_mac_addr(struct ice_vf *vf, struct ice_vsi *vsi,
2374 struct virtchnl_ether_addr *vc_ether_addr)
2375 {
2376 struct device *dev = ice_pf_to_dev(vf->pf);
2377 u8 *mac_addr = vc_ether_addr->addr;
2378 int status;
2379
2380 if (!ice_can_vf_change_mac(vf) &&
2381 ether_addr_equal(vf->dev_lan_addr, mac_addr))
2382 return 0;
2383
2384 status = ice_fltr_remove_mac(vsi, mac_addr, ICE_FWD_TO_VSI);
2385 if (status == -ENOENT) {
2386 dev_err(dev, "MAC %pM does not exist for VF %d\n", mac_addr,
2387 vf->vf_id);
2388 return -ENOENT;
2389 } else if (status) {
2390 dev_err(dev, "Failed to delete MAC %pM for VF %d, error %d\n",
2391 mac_addr, vf->vf_id, status);
2392 return -EIO;
2393 }
2394
2395 ice_vfhw_mac_del(vf, vc_ether_addr);
2396
2397 vf->num_mac--;
2398
2399 return 0;
2400 }
2401
2402 /**
2403 * ice_vc_handle_mac_addr_msg
2404 * @vf: pointer to the VF info
2405 * @msg: pointer to the msg buffer
2406 * @set: true if MAC filters are being set, false otherwise
2407 *
2408 * add guest MAC address filter
2409 */
2410 static int
ice_vc_handle_mac_addr_msg(struct ice_vf * vf,u8 * msg,bool set)2411 ice_vc_handle_mac_addr_msg(struct ice_vf *vf, u8 *msg, bool set)
2412 {
2413 int (*ice_vc_cfg_mac)
2414 (struct ice_vf *vf, struct ice_vsi *vsi,
2415 struct virtchnl_ether_addr *virtchnl_ether_addr);
2416 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
2417 struct virtchnl_ether_addr_list *al =
2418 (struct virtchnl_ether_addr_list *)msg;
2419 struct ice_pf *pf = vf->pf;
2420 enum virtchnl_ops vc_op;
2421 struct ice_vsi *vsi;
2422 int i;
2423
2424 if (set) {
2425 vc_op = VIRTCHNL_OP_ADD_ETH_ADDR;
2426 ice_vc_cfg_mac = ice_vc_add_mac_addr;
2427 } else {
2428 vc_op = VIRTCHNL_OP_DEL_ETH_ADDR;
2429 ice_vc_cfg_mac = ice_vc_del_mac_addr;
2430 }
2431
2432 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states) ||
2433 !ice_vc_isvalid_vsi_id(vf, al->vsi_id)) {
2434 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2435 goto handle_mac_exit;
2436 }
2437
2438 /* If this VF is not privileged, then we can't add more than a
2439 * limited number of addresses. Check to make sure that the
2440 * additions do not push us over the limit.
2441 */
2442 if (set && !ice_is_vf_trusted(vf) &&
2443 (vf->num_mac + al->num_elements) > ICE_MAX_MACADDR_PER_VF) {
2444 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",
2445 vf->vf_id);
2446 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2447 goto handle_mac_exit;
2448 }
2449
2450 vsi = ice_get_vf_vsi(vf);
2451 if (!vsi) {
2452 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2453 goto handle_mac_exit;
2454 }
2455
2456 for (i = 0; i < al->num_elements; i++) {
2457 u8 *mac_addr = al->list[i].addr;
2458 int result;
2459
2460 if (is_broadcast_ether_addr(mac_addr) ||
2461 is_zero_ether_addr(mac_addr))
2462 continue;
2463
2464 result = ice_vc_cfg_mac(vf, vsi, &al->list[i]);
2465 if (result == -EEXIST || result == -ENOENT) {
2466 continue;
2467 } else if (result) {
2468 v_ret = VIRTCHNL_STATUS_ERR_ADMIN_QUEUE_ERROR;
2469 goto handle_mac_exit;
2470 }
2471 }
2472
2473 handle_mac_exit:
2474 /* send the response to the VF */
2475 return ice_vc_send_msg_to_vf(vf, vc_op, v_ret, NULL, 0);
2476 }
2477
2478 /**
2479 * ice_vc_add_mac_addr_msg
2480 * @vf: pointer to the VF info
2481 * @msg: pointer to the msg buffer
2482 *
2483 * add guest MAC address filter
2484 */
ice_vc_add_mac_addr_msg(struct ice_vf * vf,u8 * msg)2485 static int ice_vc_add_mac_addr_msg(struct ice_vf *vf, u8 *msg)
2486 {
2487 return ice_vc_handle_mac_addr_msg(vf, msg, true);
2488 }
2489
2490 /**
2491 * ice_vc_del_mac_addr_msg
2492 * @vf: pointer to the VF info
2493 * @msg: pointer to the msg buffer
2494 *
2495 * remove guest MAC address filter
2496 */
ice_vc_del_mac_addr_msg(struct ice_vf * vf,u8 * msg)2497 static int ice_vc_del_mac_addr_msg(struct ice_vf *vf, u8 *msg)
2498 {
2499 return ice_vc_handle_mac_addr_msg(vf, msg, false);
2500 }
2501
2502 /**
2503 * ice_vc_request_qs_msg
2504 * @vf: pointer to the VF info
2505 * @msg: pointer to the msg buffer
2506 *
2507 * VFs get a default number of queues but can use this message to request a
2508 * different number. If the request is successful, PF will reset the VF and
2509 * return 0. If unsuccessful, PF will send message informing VF of number of
2510 * available queue pairs via virtchnl message response to VF.
2511 */
ice_vc_request_qs_msg(struct ice_vf * vf,u8 * msg)2512 static int ice_vc_request_qs_msg(struct ice_vf *vf, u8 *msg)
2513 {
2514 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
2515 struct virtchnl_vf_res_request *vfres =
2516 (struct virtchnl_vf_res_request *)msg;
2517 u16 req_queues = vfres->num_queue_pairs;
2518 struct ice_pf *pf = vf->pf;
2519 u16 max_allowed_vf_queues;
2520 u16 tx_rx_queue_left;
2521 struct device *dev;
2522 u16 cur_queues;
2523
2524 dev = ice_pf_to_dev(pf);
2525 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
2526 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2527 goto error_param;
2528 }
2529
2530 cur_queues = vf->num_vf_qs;
2531 tx_rx_queue_left = min_t(u16, ice_get_avail_txq_count(pf),
2532 ice_get_avail_rxq_count(pf));
2533 max_allowed_vf_queues = tx_rx_queue_left + cur_queues;
2534 if (!req_queues) {
2535 dev_err(dev, "VF %d tried to request 0 queues. Ignoring.\n",
2536 vf->vf_id);
2537 } else if (req_queues > ICE_MAX_RSS_QS_PER_VF) {
2538 dev_err(dev, "VF %d tried to request more than %d queues.\n",
2539 vf->vf_id, ICE_MAX_RSS_QS_PER_VF);
2540 vfres->num_queue_pairs = ICE_MAX_RSS_QS_PER_VF;
2541 } else if (req_queues > cur_queues &&
2542 req_queues - cur_queues > tx_rx_queue_left) {
2543 dev_warn(dev, "VF %d requested %u more queues, but only %u left.\n",
2544 vf->vf_id, req_queues - cur_queues, tx_rx_queue_left);
2545 vfres->num_queue_pairs = min_t(u16, max_allowed_vf_queues,
2546 ICE_MAX_RSS_QS_PER_VF);
2547 } else {
2548 /* request is successful, then reset VF */
2549 vf->num_req_qs = req_queues;
2550 ice_reset_vf(vf, ICE_VF_RESET_NOTIFY);
2551 dev_info(dev, "VF %d granted request of %u queues.\n",
2552 vf->vf_id, req_queues);
2553 return 0;
2554 }
2555
2556 error_param:
2557 /* send the response to the VF */
2558 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_REQUEST_QUEUES,
2559 v_ret, (u8 *)vfres, sizeof(*vfres));
2560 }
2561
2562 /**
2563 * ice_vf_vlan_offload_ena - determine if capabilities support VLAN offloads
2564 * @caps: VF driver negotiated capabilities
2565 *
2566 * Return true if VIRTCHNL_VF_OFFLOAD_VLAN capability is set, else return false
2567 */
ice_vf_vlan_offload_ena(u32 caps)2568 static bool ice_vf_vlan_offload_ena(u32 caps)
2569 {
2570 return !!(caps & VIRTCHNL_VF_OFFLOAD_VLAN);
2571 }
2572
2573 /**
2574 * ice_is_vlan_promisc_allowed - check if VLAN promiscuous config is allowed
2575 * @vf: VF used to determine if VLAN promiscuous config is allowed
2576 */
ice_is_vlan_promisc_allowed(struct ice_vf * vf)2577 static bool ice_is_vlan_promisc_allowed(struct ice_vf *vf)
2578 {
2579 if ((test_bit(ICE_VF_STATE_UC_PROMISC, vf->vf_states) ||
2580 test_bit(ICE_VF_STATE_MC_PROMISC, vf->vf_states)) &&
2581 test_bit(ICE_FLAG_VF_TRUE_PROMISC_ENA, vf->pf->flags))
2582 return true;
2583
2584 return false;
2585 }
2586
2587 /**
2588 * ice_vf_ena_vlan_promisc - Enable Tx/Rx VLAN promiscuous for the VLAN
2589 * @vf: VF to enable VLAN promisc on
2590 * @vsi: VF's VSI used to enable VLAN promiscuous mode
2591 * @vlan: VLAN used to enable VLAN promiscuous
2592 *
2593 * This function should only be called if VLAN promiscuous mode is allowed,
2594 * which can be determined via ice_is_vlan_promisc_allowed().
2595 */
ice_vf_ena_vlan_promisc(struct ice_vf * vf,struct ice_vsi * vsi,struct ice_vlan * vlan)2596 static int ice_vf_ena_vlan_promisc(struct ice_vf *vf, struct ice_vsi *vsi,
2597 struct ice_vlan *vlan)
2598 {
2599 u8 promisc_m = 0;
2600 int status;
2601
2602 if (test_bit(ICE_VF_STATE_UC_PROMISC, vf->vf_states))
2603 promisc_m |= ICE_UCAST_VLAN_PROMISC_BITS;
2604 if (test_bit(ICE_VF_STATE_MC_PROMISC, vf->vf_states))
2605 promisc_m |= ICE_MCAST_VLAN_PROMISC_BITS;
2606
2607 if (!promisc_m)
2608 return 0;
2609
2610 status = ice_fltr_set_vsi_promisc(&vsi->back->hw, vsi->idx, promisc_m,
2611 vlan->vid);
2612 if (status && status != -EEXIST)
2613 return status;
2614
2615 return 0;
2616 }
2617
2618 /**
2619 * ice_vf_dis_vlan_promisc - Disable Tx/Rx VLAN promiscuous for the VLAN
2620 * @vsi: VF's VSI used to disable VLAN promiscuous mode for
2621 * @vlan: VLAN used to disable VLAN promiscuous
2622 *
2623 * This function should only be called if VLAN promiscuous mode is allowed,
2624 * which can be determined via ice_is_vlan_promisc_allowed().
2625 */
ice_vf_dis_vlan_promisc(struct ice_vsi * vsi,struct ice_vlan * vlan)2626 static int ice_vf_dis_vlan_promisc(struct ice_vsi *vsi, struct ice_vlan *vlan)
2627 {
2628 u8 promisc_m = ICE_UCAST_VLAN_PROMISC_BITS | ICE_MCAST_VLAN_PROMISC_BITS;
2629 int status;
2630
2631 status = ice_fltr_clear_vsi_promisc(&vsi->back->hw, vsi->idx, promisc_m,
2632 vlan->vid);
2633 if (status && status != -ENOENT)
2634 return status;
2635
2636 return 0;
2637 }
2638
2639 /**
2640 * ice_vf_has_max_vlans - check if VF already has the max allowed VLAN filters
2641 * @vf: VF to check against
2642 * @vsi: VF's VSI
2643 *
2644 * If the VF is trusted then the VF is allowed to add as many VLANs as it
2645 * wants to, so return false.
2646 *
2647 * When the VF is untrusted compare the number of non-zero VLANs + 1 to the max
2648 * allowed VLANs for an untrusted VF. Return the result of this comparison.
2649 */
ice_vf_has_max_vlans(struct ice_vf * vf,struct ice_vsi * vsi)2650 static bool ice_vf_has_max_vlans(struct ice_vf *vf, struct ice_vsi *vsi)
2651 {
2652 if (ice_is_vf_trusted(vf))
2653 return false;
2654
2655 #define ICE_VF_ADDED_VLAN_ZERO_FLTRS 1
2656 return ((ice_vsi_num_non_zero_vlans(vsi) +
2657 ICE_VF_ADDED_VLAN_ZERO_FLTRS) >= ICE_MAX_VLAN_PER_VF);
2658 }
2659
2660 /**
2661 * ice_vc_process_vlan_msg
2662 * @vf: pointer to the VF info
2663 * @msg: pointer to the msg buffer
2664 * @add_v: Add VLAN if true, otherwise delete VLAN
2665 *
2666 * Process virtchnl op to add or remove programmed guest VLAN ID
2667 */
ice_vc_process_vlan_msg(struct ice_vf * vf,u8 * msg,bool add_v)2668 static int ice_vc_process_vlan_msg(struct ice_vf *vf, u8 *msg, bool add_v)
2669 {
2670 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
2671 struct virtchnl_vlan_filter_list *vfl =
2672 (struct virtchnl_vlan_filter_list *)msg;
2673 struct ice_pf *pf = vf->pf;
2674 bool vlan_promisc = false;
2675 struct ice_vsi *vsi;
2676 struct device *dev;
2677 int status = 0;
2678 int i;
2679
2680 dev = ice_pf_to_dev(pf);
2681 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
2682 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2683 goto error_param;
2684 }
2685
2686 if (!ice_vf_vlan_offload_ena(vf->driver_caps)) {
2687 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2688 goto error_param;
2689 }
2690
2691 if (!ice_vc_isvalid_vsi_id(vf, vfl->vsi_id)) {
2692 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2693 goto error_param;
2694 }
2695
2696 for (i = 0; i < vfl->num_elements; i++) {
2697 if (vfl->vlan_id[i] >= VLAN_N_VID) {
2698 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2699 dev_err(dev, "invalid VF VLAN id %d\n",
2700 vfl->vlan_id[i]);
2701 goto error_param;
2702 }
2703 }
2704
2705 vsi = ice_get_vf_vsi(vf);
2706 if (!vsi) {
2707 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2708 goto error_param;
2709 }
2710
2711 if (add_v && ice_vf_has_max_vlans(vf, vsi)) {
2712 dev_info(dev, "VF-%d is not trusted, switch the VF to trusted mode, in order to add more VLAN addresses\n",
2713 vf->vf_id);
2714 /* There is no need to let VF know about being not trusted,
2715 * so we can just return success message here
2716 */
2717 goto error_param;
2718 }
2719
2720 /* in DVM a VF can add/delete inner VLAN filters when
2721 * VIRTCHNL_VF_OFFLOAD_VLAN is negotiated, so only reject in SVM
2722 */
2723 if (ice_vf_is_port_vlan_ena(vf) && !ice_is_dvm_ena(&pf->hw)) {
2724 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2725 goto error_param;
2726 }
2727
2728 /* in DVM VLAN promiscuous is based on the outer VLAN, which would be
2729 * the port VLAN if VIRTCHNL_VF_OFFLOAD_VLAN was negotiated, so only
2730 * allow vlan_promisc = true in SVM and if no port VLAN is configured
2731 */
2732 vlan_promisc = ice_is_vlan_promisc_allowed(vf) &&
2733 !ice_is_dvm_ena(&pf->hw) &&
2734 !ice_vf_is_port_vlan_ena(vf);
2735
2736 if (add_v) {
2737 for (i = 0; i < vfl->num_elements; i++) {
2738 u16 vid = vfl->vlan_id[i];
2739 struct ice_vlan vlan;
2740
2741 if (ice_vf_has_max_vlans(vf, vsi)) {
2742 dev_info(dev, "VF-%d is not trusted, switch the VF to trusted mode, in order to add more VLAN addresses\n",
2743 vf->vf_id);
2744 /* There is no need to let VF know about being
2745 * not trusted, so we can just return success
2746 * message here as well.
2747 */
2748 goto error_param;
2749 }
2750
2751 /* we add VLAN 0 by default for each VF so we can enable
2752 * Tx VLAN anti-spoof without triggering MDD events so
2753 * we don't need to add it again here
2754 */
2755 if (!vid)
2756 continue;
2757
2758 vlan = ICE_VLAN(ETH_P_8021Q, vid, 0);
2759 status = vsi->inner_vlan_ops.add_vlan(vsi, &vlan);
2760 if (status) {
2761 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2762 goto error_param;
2763 }
2764
2765 /* Enable VLAN filtering on first non-zero VLAN */
2766 if (!vlan_promisc && vid && !ice_is_dvm_ena(&pf->hw)) {
2767 if (vf->spoofchk) {
2768 status = vsi->inner_vlan_ops.ena_tx_filtering(vsi);
2769 if (status) {
2770 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2771 dev_err(dev, "Enable VLAN anti-spoofing on VLAN ID: %d failed error-%d\n",
2772 vid, status);
2773 goto error_param;
2774 }
2775 }
2776 if (vsi->inner_vlan_ops.ena_rx_filtering(vsi)) {
2777 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2778 dev_err(dev, "Enable VLAN pruning on VLAN ID: %d failed error-%d\n",
2779 vid, status);
2780 goto error_param;
2781 }
2782 } else if (vlan_promisc) {
2783 status = ice_vf_ena_vlan_promisc(vf, vsi, &vlan);
2784 if (status) {
2785 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2786 dev_err(dev, "Enable Unicast/multicast promiscuous mode on VLAN ID:%d failed error-%d\n",
2787 vid, status);
2788 }
2789 }
2790 }
2791 } else {
2792 /* In case of non_trusted VF, number of VLAN elements passed
2793 * to PF for removal might be greater than number of VLANs
2794 * filter programmed for that VF - So, use actual number of
2795 * VLANS added earlier with add VLAN opcode. In order to avoid
2796 * removing VLAN that doesn't exist, which result to sending
2797 * erroneous failed message back to the VF
2798 */
2799 int num_vf_vlan;
2800
2801 num_vf_vlan = vsi->num_vlan;
2802 for (i = 0; i < vfl->num_elements && i < num_vf_vlan; i++) {
2803 u16 vid = vfl->vlan_id[i];
2804 struct ice_vlan vlan;
2805
2806 /* we add VLAN 0 by default for each VF so we can enable
2807 * Tx VLAN anti-spoof without triggering MDD events so
2808 * we don't want a VIRTCHNL request to remove it
2809 */
2810 if (!vid)
2811 continue;
2812
2813 vlan = ICE_VLAN(ETH_P_8021Q, vid, 0);
2814 status = vsi->inner_vlan_ops.del_vlan(vsi, &vlan);
2815 if (status) {
2816 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2817 goto error_param;
2818 }
2819
2820 /* Disable VLAN filtering when only VLAN 0 is left */
2821 if (!ice_vsi_has_non_zero_vlans(vsi)) {
2822 vsi->inner_vlan_ops.dis_tx_filtering(vsi);
2823 vsi->inner_vlan_ops.dis_rx_filtering(vsi);
2824 }
2825
2826 if (vlan_promisc)
2827 ice_vf_dis_vlan_promisc(vsi, &vlan);
2828 }
2829 }
2830
2831 error_param:
2832 /* send the response to the VF */
2833 if (add_v)
2834 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_ADD_VLAN, v_ret,
2835 NULL, 0);
2836 else
2837 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_DEL_VLAN, v_ret,
2838 NULL, 0);
2839 }
2840
2841 /**
2842 * ice_vc_add_vlan_msg
2843 * @vf: pointer to the VF info
2844 * @msg: pointer to the msg buffer
2845 *
2846 * Add and program guest VLAN ID
2847 */
ice_vc_add_vlan_msg(struct ice_vf * vf,u8 * msg)2848 static int ice_vc_add_vlan_msg(struct ice_vf *vf, u8 *msg)
2849 {
2850 return ice_vc_process_vlan_msg(vf, msg, true);
2851 }
2852
2853 /**
2854 * ice_vc_remove_vlan_msg
2855 * @vf: pointer to the VF info
2856 * @msg: pointer to the msg buffer
2857 *
2858 * remove programmed guest VLAN ID
2859 */
ice_vc_remove_vlan_msg(struct ice_vf * vf,u8 * msg)2860 static int ice_vc_remove_vlan_msg(struct ice_vf *vf, u8 *msg)
2861 {
2862 return ice_vc_process_vlan_msg(vf, msg, false);
2863 }
2864
2865 /**
2866 * ice_vsi_is_rxq_crc_strip_dis - check if Rx queue CRC strip is disabled or not
2867 * @vsi: pointer to the VF VSI info
2868 */
ice_vsi_is_rxq_crc_strip_dis(struct ice_vsi * vsi)2869 static bool ice_vsi_is_rxq_crc_strip_dis(struct ice_vsi *vsi)
2870 {
2871 unsigned int i;
2872
2873 ice_for_each_alloc_rxq(vsi, i)
2874 if (vsi->rx_rings[i]->flags & ICE_RX_FLAGS_CRC_STRIP_DIS)
2875 return true;
2876
2877 return false;
2878 }
2879
2880 /**
2881 * ice_vc_ena_vlan_stripping
2882 * @vf: pointer to the VF info
2883 *
2884 * Enable VLAN header stripping for a given VF
2885 */
ice_vc_ena_vlan_stripping(struct ice_vf * vf)2886 static int ice_vc_ena_vlan_stripping(struct ice_vf *vf)
2887 {
2888 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
2889 struct ice_vsi *vsi;
2890
2891 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
2892 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2893 goto error_param;
2894 }
2895
2896 if (!ice_vf_vlan_offload_ena(vf->driver_caps)) {
2897 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2898 goto error_param;
2899 }
2900
2901 vsi = ice_get_vf_vsi(vf);
2902 if (!vsi) {
2903 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2904 goto error_param;
2905 }
2906
2907 if (vsi->inner_vlan_ops.ena_stripping(vsi, ETH_P_8021Q))
2908 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2909 else
2910 vf->vlan_strip_ena |= ICE_INNER_VLAN_STRIP_ENA;
2911
2912 error_param:
2913 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_ENABLE_VLAN_STRIPPING,
2914 v_ret, NULL, 0);
2915 }
2916
2917 /**
2918 * ice_vc_dis_vlan_stripping
2919 * @vf: pointer to the VF info
2920 *
2921 * Disable VLAN header stripping for a given VF
2922 */
ice_vc_dis_vlan_stripping(struct ice_vf * vf)2923 static int ice_vc_dis_vlan_stripping(struct ice_vf *vf)
2924 {
2925 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
2926 struct ice_vsi *vsi;
2927
2928 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
2929 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2930 goto error_param;
2931 }
2932
2933 if (!ice_vf_vlan_offload_ena(vf->driver_caps)) {
2934 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2935 goto error_param;
2936 }
2937
2938 vsi = ice_get_vf_vsi(vf);
2939 if (!vsi) {
2940 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2941 goto error_param;
2942 }
2943
2944 if (vsi->inner_vlan_ops.dis_stripping(vsi))
2945 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2946 else
2947 vf->vlan_strip_ena &= ~ICE_INNER_VLAN_STRIP_ENA;
2948
2949 error_param:
2950 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_DISABLE_VLAN_STRIPPING,
2951 v_ret, NULL, 0);
2952 }
2953
2954 /**
2955 * ice_vc_get_rss_hena - return the RSS HENA bits allowed by the hardware
2956 * @vf: pointer to the VF info
2957 */
ice_vc_get_rss_hena(struct ice_vf * vf)2958 static int ice_vc_get_rss_hena(struct ice_vf *vf)
2959 {
2960 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
2961 struct virtchnl_rss_hena *vrh = NULL;
2962 int len = 0, ret;
2963
2964 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
2965 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2966 goto err;
2967 }
2968
2969 if (!test_bit(ICE_FLAG_RSS_ENA, vf->pf->flags)) {
2970 dev_err(ice_pf_to_dev(vf->pf), "RSS not supported by PF\n");
2971 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2972 goto err;
2973 }
2974
2975 len = sizeof(struct virtchnl_rss_hena);
2976 vrh = kzalloc(len, GFP_KERNEL);
2977 if (!vrh) {
2978 v_ret = VIRTCHNL_STATUS_ERR_NO_MEMORY;
2979 len = 0;
2980 goto err;
2981 }
2982
2983 vrh->hena = ICE_DEFAULT_RSS_HENA;
2984 err:
2985 /* send the response back to the VF */
2986 ret = ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_GET_RSS_HENA_CAPS, v_ret,
2987 (u8 *)vrh, len);
2988 kfree(vrh);
2989 return ret;
2990 }
2991
2992 /**
2993 * ice_vc_set_rss_hena - set RSS HENA bits for the VF
2994 * @vf: pointer to the VF info
2995 * @msg: pointer to the msg buffer
2996 */
ice_vc_set_rss_hena(struct ice_vf * vf,u8 * msg)2997 static int ice_vc_set_rss_hena(struct ice_vf *vf, u8 *msg)
2998 {
2999 struct virtchnl_rss_hena *vrh = (struct virtchnl_rss_hena *)msg;
3000 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
3001 struct ice_pf *pf = vf->pf;
3002 struct ice_vsi *vsi;
3003 struct device *dev;
3004 int status;
3005
3006 dev = ice_pf_to_dev(pf);
3007
3008 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
3009 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3010 goto err;
3011 }
3012
3013 if (!test_bit(ICE_FLAG_RSS_ENA, pf->flags)) {
3014 dev_err(dev, "RSS not supported by PF\n");
3015 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3016 goto err;
3017 }
3018
3019 vsi = ice_get_vf_vsi(vf);
3020 if (!vsi) {
3021 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3022 goto err;
3023 }
3024
3025 /* clear all previously programmed RSS configuration to allow VF drivers
3026 * the ability to customize the RSS configuration and/or completely
3027 * disable RSS
3028 */
3029 status = ice_rem_vsi_rss_cfg(&pf->hw, vsi->idx);
3030 if (status && !vrh->hena) {
3031 /* only report failure to clear the current RSS configuration if
3032 * that was clearly the VF's intention (i.e. vrh->hena = 0)
3033 */
3034 v_ret = ice_err_to_virt_err(status);
3035 goto err;
3036 } else if (status) {
3037 /* allow the VF to update the RSS configuration even on failure
3038 * to clear the current RSS confguration in an attempt to keep
3039 * RSS in a working state
3040 */
3041 dev_warn(dev, "Failed to clear the RSS configuration for VF %u\n",
3042 vf->vf_id);
3043 }
3044
3045 if (vrh->hena) {
3046 status = ice_add_avf_rss_cfg(&pf->hw, vsi, vrh->hena);
3047 v_ret = ice_err_to_virt_err(status);
3048 }
3049
3050 /* send the response to the VF */
3051 err:
3052 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_SET_RSS_HENA, v_ret,
3053 NULL, 0);
3054 }
3055
3056 /**
3057 * ice_vc_query_rxdid - query RXDID supported by DDP package
3058 * @vf: pointer to VF info
3059 *
3060 * Called from VF to query a bitmap of supported flexible
3061 * descriptor RXDIDs of a DDP package.
3062 */
ice_vc_query_rxdid(struct ice_vf * vf)3063 static int ice_vc_query_rxdid(struct ice_vf *vf)
3064 {
3065 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
3066 struct ice_pf *pf = vf->pf;
3067 u64 rxdid;
3068
3069 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
3070 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3071 goto err;
3072 }
3073
3074 if (!(vf->driver_caps & VIRTCHNL_VF_OFFLOAD_RX_FLEX_DESC)) {
3075 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3076 goto err;
3077 }
3078
3079 rxdid = pf->supported_rxdids;
3080
3081 err:
3082 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_GET_SUPPORTED_RXDIDS,
3083 v_ret, (u8 *)&rxdid, sizeof(rxdid));
3084 }
3085
3086 /**
3087 * ice_vf_init_vlan_stripping - enable/disable VLAN stripping on initialization
3088 * @vf: VF to enable/disable VLAN stripping for on initialization
3089 *
3090 * Set the default for VLAN stripping based on whether a port VLAN is configured
3091 * and the current VLAN mode of the device.
3092 */
ice_vf_init_vlan_stripping(struct ice_vf * vf)3093 static int ice_vf_init_vlan_stripping(struct ice_vf *vf)
3094 {
3095 struct ice_vsi *vsi = ice_get_vf_vsi(vf);
3096
3097 vf->vlan_strip_ena = 0;
3098
3099 if (!vsi)
3100 return -EINVAL;
3101
3102 /* don't modify stripping if port VLAN is configured in SVM since the
3103 * port VLAN is based on the inner/single VLAN in SVM
3104 */
3105 if (ice_vf_is_port_vlan_ena(vf) && !ice_is_dvm_ena(&vsi->back->hw))
3106 return 0;
3107
3108 if (ice_vf_vlan_offload_ena(vf->driver_caps)) {
3109 int err;
3110
3111 err = vsi->inner_vlan_ops.ena_stripping(vsi, ETH_P_8021Q);
3112 if (!err)
3113 vf->vlan_strip_ena |= ICE_INNER_VLAN_STRIP_ENA;
3114 return err;
3115 }
3116
3117 return vsi->inner_vlan_ops.dis_stripping(vsi);
3118 }
3119
ice_vc_get_max_vlan_fltrs(struct ice_vf * vf)3120 static u16 ice_vc_get_max_vlan_fltrs(struct ice_vf *vf)
3121 {
3122 if (vf->trusted)
3123 return VLAN_N_VID;
3124 else
3125 return ICE_MAX_VLAN_PER_VF;
3126 }
3127
3128 /**
3129 * ice_vf_outer_vlan_not_allowed - check if outer VLAN can be used
3130 * @vf: VF that being checked for
3131 *
3132 * When the device is in double VLAN mode, check whether or not the outer VLAN
3133 * is allowed.
3134 */
ice_vf_outer_vlan_not_allowed(struct ice_vf * vf)3135 static bool ice_vf_outer_vlan_not_allowed(struct ice_vf *vf)
3136 {
3137 if (ice_vf_is_port_vlan_ena(vf))
3138 return true;
3139
3140 return false;
3141 }
3142
3143 /**
3144 * ice_vc_set_dvm_caps - set VLAN capabilities when the device is in DVM
3145 * @vf: VF that capabilities are being set for
3146 * @caps: VLAN capabilities to populate
3147 *
3148 * Determine VLAN capabilities support based on whether a port VLAN is
3149 * configured. If a port VLAN is configured then the VF should use the inner
3150 * filtering/offload capabilities since the port VLAN is using the outer VLAN
3151 * capabilies.
3152 */
3153 static void
ice_vc_set_dvm_caps(struct ice_vf * vf,struct virtchnl_vlan_caps * caps)3154 ice_vc_set_dvm_caps(struct ice_vf *vf, struct virtchnl_vlan_caps *caps)
3155 {
3156 struct virtchnl_vlan_supported_caps *supported_caps;
3157
3158 if (ice_vf_outer_vlan_not_allowed(vf)) {
3159 /* until support for inner VLAN filtering is added when a port
3160 * VLAN is configured, only support software offloaded inner
3161 * VLANs when a port VLAN is confgured in DVM
3162 */
3163 supported_caps = &caps->filtering.filtering_support;
3164 supported_caps->inner = VIRTCHNL_VLAN_UNSUPPORTED;
3165
3166 supported_caps = &caps->offloads.stripping_support;
3167 supported_caps->inner = VIRTCHNL_VLAN_ETHERTYPE_8100 |
3168 VIRTCHNL_VLAN_TOGGLE |
3169 VIRTCHNL_VLAN_TAG_LOCATION_L2TAG1;
3170 supported_caps->outer = VIRTCHNL_VLAN_UNSUPPORTED;
3171
3172 supported_caps = &caps->offloads.insertion_support;
3173 supported_caps->inner = VIRTCHNL_VLAN_ETHERTYPE_8100 |
3174 VIRTCHNL_VLAN_TOGGLE |
3175 VIRTCHNL_VLAN_TAG_LOCATION_L2TAG1;
3176 supported_caps->outer = VIRTCHNL_VLAN_UNSUPPORTED;
3177
3178 caps->offloads.ethertype_init = VIRTCHNL_VLAN_ETHERTYPE_8100;
3179 caps->offloads.ethertype_match =
3180 VIRTCHNL_ETHERTYPE_STRIPPING_MATCHES_INSERTION;
3181 } else {
3182 supported_caps = &caps->filtering.filtering_support;
3183 supported_caps->inner = VIRTCHNL_VLAN_UNSUPPORTED;
3184 supported_caps->outer = VIRTCHNL_VLAN_ETHERTYPE_8100 |
3185 VIRTCHNL_VLAN_ETHERTYPE_88A8 |
3186 VIRTCHNL_VLAN_ETHERTYPE_9100 |
3187 VIRTCHNL_VLAN_ETHERTYPE_AND;
3188 caps->filtering.ethertype_init = VIRTCHNL_VLAN_ETHERTYPE_8100 |
3189 VIRTCHNL_VLAN_ETHERTYPE_88A8 |
3190 VIRTCHNL_VLAN_ETHERTYPE_9100;
3191
3192 supported_caps = &caps->offloads.stripping_support;
3193 supported_caps->inner = VIRTCHNL_VLAN_TOGGLE |
3194 VIRTCHNL_VLAN_ETHERTYPE_8100 |
3195 VIRTCHNL_VLAN_TAG_LOCATION_L2TAG1;
3196 supported_caps->outer = VIRTCHNL_VLAN_TOGGLE |
3197 VIRTCHNL_VLAN_ETHERTYPE_8100 |
3198 VIRTCHNL_VLAN_ETHERTYPE_88A8 |
3199 VIRTCHNL_VLAN_ETHERTYPE_9100 |
3200 VIRTCHNL_VLAN_ETHERTYPE_XOR |
3201 VIRTCHNL_VLAN_TAG_LOCATION_L2TAG2_2;
3202
3203 supported_caps = &caps->offloads.insertion_support;
3204 supported_caps->inner = VIRTCHNL_VLAN_TOGGLE |
3205 VIRTCHNL_VLAN_ETHERTYPE_8100 |
3206 VIRTCHNL_VLAN_TAG_LOCATION_L2TAG1;
3207 supported_caps->outer = VIRTCHNL_VLAN_TOGGLE |
3208 VIRTCHNL_VLAN_ETHERTYPE_8100 |
3209 VIRTCHNL_VLAN_ETHERTYPE_88A8 |
3210 VIRTCHNL_VLAN_ETHERTYPE_9100 |
3211 VIRTCHNL_VLAN_ETHERTYPE_XOR |
3212 VIRTCHNL_VLAN_TAG_LOCATION_L2TAG2;
3213
3214 caps->offloads.ethertype_init = VIRTCHNL_VLAN_ETHERTYPE_8100;
3215
3216 caps->offloads.ethertype_match =
3217 VIRTCHNL_ETHERTYPE_STRIPPING_MATCHES_INSERTION;
3218 }
3219
3220 caps->filtering.max_filters = ice_vc_get_max_vlan_fltrs(vf);
3221 }
3222
3223 /**
3224 * ice_vc_set_svm_caps - set VLAN capabilities when the device is in SVM
3225 * @vf: VF that capabilities are being set for
3226 * @caps: VLAN capabilities to populate
3227 *
3228 * Determine VLAN capabilities support based on whether a port VLAN is
3229 * configured. If a port VLAN is configured then the VF does not have any VLAN
3230 * filtering or offload capabilities since the port VLAN is using the inner VLAN
3231 * capabilities in single VLAN mode (SVM). Otherwise allow the VF to use inner
3232 * VLAN fitlering and offload capabilities.
3233 */
3234 static void
ice_vc_set_svm_caps(struct ice_vf * vf,struct virtchnl_vlan_caps * caps)3235 ice_vc_set_svm_caps(struct ice_vf *vf, struct virtchnl_vlan_caps *caps)
3236 {
3237 struct virtchnl_vlan_supported_caps *supported_caps;
3238
3239 if (ice_vf_is_port_vlan_ena(vf)) {
3240 supported_caps = &caps->filtering.filtering_support;
3241 supported_caps->inner = VIRTCHNL_VLAN_UNSUPPORTED;
3242 supported_caps->outer = VIRTCHNL_VLAN_UNSUPPORTED;
3243
3244 supported_caps = &caps->offloads.stripping_support;
3245 supported_caps->inner = VIRTCHNL_VLAN_UNSUPPORTED;
3246 supported_caps->outer = VIRTCHNL_VLAN_UNSUPPORTED;
3247
3248 supported_caps = &caps->offloads.insertion_support;
3249 supported_caps->inner = VIRTCHNL_VLAN_UNSUPPORTED;
3250 supported_caps->outer = VIRTCHNL_VLAN_UNSUPPORTED;
3251
3252 caps->offloads.ethertype_init = VIRTCHNL_VLAN_UNSUPPORTED;
3253 caps->offloads.ethertype_match = VIRTCHNL_VLAN_UNSUPPORTED;
3254 caps->filtering.max_filters = 0;
3255 } else {
3256 supported_caps = &caps->filtering.filtering_support;
3257 supported_caps->inner = VIRTCHNL_VLAN_ETHERTYPE_8100;
3258 supported_caps->outer = VIRTCHNL_VLAN_UNSUPPORTED;
3259 caps->filtering.ethertype_init = VIRTCHNL_VLAN_ETHERTYPE_8100;
3260
3261 supported_caps = &caps->offloads.stripping_support;
3262 supported_caps->inner = VIRTCHNL_VLAN_ETHERTYPE_8100 |
3263 VIRTCHNL_VLAN_TOGGLE |
3264 VIRTCHNL_VLAN_TAG_LOCATION_L2TAG1;
3265 supported_caps->outer = VIRTCHNL_VLAN_UNSUPPORTED;
3266
3267 supported_caps = &caps->offloads.insertion_support;
3268 supported_caps->inner = VIRTCHNL_VLAN_ETHERTYPE_8100 |
3269 VIRTCHNL_VLAN_TOGGLE |
3270 VIRTCHNL_VLAN_TAG_LOCATION_L2TAG1;
3271 supported_caps->outer = VIRTCHNL_VLAN_UNSUPPORTED;
3272
3273 caps->offloads.ethertype_init = VIRTCHNL_VLAN_ETHERTYPE_8100;
3274 caps->offloads.ethertype_match =
3275 VIRTCHNL_ETHERTYPE_STRIPPING_MATCHES_INSERTION;
3276 caps->filtering.max_filters = ice_vc_get_max_vlan_fltrs(vf);
3277 }
3278 }
3279
3280 /**
3281 * ice_vc_get_offload_vlan_v2_caps - determine VF's VLAN capabilities
3282 * @vf: VF to determine VLAN capabilities for
3283 *
3284 * This will only be called if the VF and PF successfully negotiated
3285 * VIRTCHNL_VF_OFFLOAD_VLAN_V2.
3286 *
3287 * Set VLAN capabilities based on the current VLAN mode and whether a port VLAN
3288 * is configured or not.
3289 */
ice_vc_get_offload_vlan_v2_caps(struct ice_vf * vf)3290 static int ice_vc_get_offload_vlan_v2_caps(struct ice_vf *vf)
3291 {
3292 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
3293 struct virtchnl_vlan_caps *caps = NULL;
3294 int err, len = 0;
3295
3296 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
3297 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3298 goto out;
3299 }
3300
3301 caps = kzalloc(sizeof(*caps), GFP_KERNEL);
3302 if (!caps) {
3303 v_ret = VIRTCHNL_STATUS_ERR_NO_MEMORY;
3304 goto out;
3305 }
3306 len = sizeof(*caps);
3307
3308 if (ice_is_dvm_ena(&vf->pf->hw))
3309 ice_vc_set_dvm_caps(vf, caps);
3310 else
3311 ice_vc_set_svm_caps(vf, caps);
3312
3313 /* store negotiated caps to prevent invalid VF messages */
3314 memcpy(&vf->vlan_v2_caps, caps, sizeof(*caps));
3315
3316 out:
3317 err = ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS,
3318 v_ret, (u8 *)caps, len);
3319 kfree(caps);
3320 return err;
3321 }
3322
3323 /**
3324 * ice_vc_validate_vlan_tpid - validate VLAN TPID
3325 * @filtering_caps: negotiated/supported VLAN filtering capabilities
3326 * @tpid: VLAN TPID used for validation
3327 *
3328 * Convert the VLAN TPID to a VIRTCHNL_VLAN_ETHERTYPE_* and then compare against
3329 * the negotiated/supported filtering caps to see if the VLAN TPID is valid.
3330 */
ice_vc_validate_vlan_tpid(u16 filtering_caps,u16 tpid)3331 static bool ice_vc_validate_vlan_tpid(u16 filtering_caps, u16 tpid)
3332 {
3333 enum virtchnl_vlan_support vlan_ethertype = VIRTCHNL_VLAN_UNSUPPORTED;
3334
3335 switch (tpid) {
3336 case ETH_P_8021Q:
3337 vlan_ethertype = VIRTCHNL_VLAN_ETHERTYPE_8100;
3338 break;
3339 case ETH_P_8021AD:
3340 vlan_ethertype = VIRTCHNL_VLAN_ETHERTYPE_88A8;
3341 break;
3342 case ETH_P_QINQ1:
3343 vlan_ethertype = VIRTCHNL_VLAN_ETHERTYPE_9100;
3344 break;
3345 }
3346
3347 if (!(filtering_caps & vlan_ethertype))
3348 return false;
3349
3350 return true;
3351 }
3352
3353 /**
3354 * ice_vc_is_valid_vlan - validate the virtchnl_vlan
3355 * @vc_vlan: virtchnl_vlan to validate
3356 *
3357 * If the VLAN TCI and VLAN TPID are 0, then this filter is invalid, so return
3358 * false. Otherwise return true.
3359 */
ice_vc_is_valid_vlan(struct virtchnl_vlan * vc_vlan)3360 static bool ice_vc_is_valid_vlan(struct virtchnl_vlan *vc_vlan)
3361 {
3362 if (!vc_vlan->tci || !vc_vlan->tpid)
3363 return false;
3364
3365 return true;
3366 }
3367
3368 /**
3369 * ice_vc_validate_vlan_filter_list - validate the filter list from the VF
3370 * @vfc: negotiated/supported VLAN filtering capabilities
3371 * @vfl: VLAN filter list from VF to validate
3372 *
3373 * Validate all of the filters in the VLAN filter list from the VF. If any of
3374 * the checks fail then return false. Otherwise return true.
3375 */
3376 static bool
ice_vc_validate_vlan_filter_list(struct virtchnl_vlan_filtering_caps * vfc,struct virtchnl_vlan_filter_list_v2 * vfl)3377 ice_vc_validate_vlan_filter_list(struct virtchnl_vlan_filtering_caps *vfc,
3378 struct virtchnl_vlan_filter_list_v2 *vfl)
3379 {
3380 u16 i;
3381
3382 if (!vfl->num_elements)
3383 return false;
3384
3385 for (i = 0; i < vfl->num_elements; i++) {
3386 struct virtchnl_vlan_supported_caps *filtering_support =
3387 &vfc->filtering_support;
3388 struct virtchnl_vlan_filter *vlan_fltr = &vfl->filters[i];
3389 struct virtchnl_vlan *outer = &vlan_fltr->outer;
3390 struct virtchnl_vlan *inner = &vlan_fltr->inner;
3391
3392 if ((ice_vc_is_valid_vlan(outer) &&
3393 filtering_support->outer == VIRTCHNL_VLAN_UNSUPPORTED) ||
3394 (ice_vc_is_valid_vlan(inner) &&
3395 filtering_support->inner == VIRTCHNL_VLAN_UNSUPPORTED))
3396 return false;
3397
3398 if ((outer->tci_mask &&
3399 !(filtering_support->outer & VIRTCHNL_VLAN_FILTER_MASK)) ||
3400 (inner->tci_mask &&
3401 !(filtering_support->inner & VIRTCHNL_VLAN_FILTER_MASK)))
3402 return false;
3403
3404 if (((outer->tci & VLAN_PRIO_MASK) &&
3405 !(filtering_support->outer & VIRTCHNL_VLAN_PRIO)) ||
3406 ((inner->tci & VLAN_PRIO_MASK) &&
3407 !(filtering_support->inner & VIRTCHNL_VLAN_PRIO)))
3408 return false;
3409
3410 if ((ice_vc_is_valid_vlan(outer) &&
3411 !ice_vc_validate_vlan_tpid(filtering_support->outer,
3412 outer->tpid)) ||
3413 (ice_vc_is_valid_vlan(inner) &&
3414 !ice_vc_validate_vlan_tpid(filtering_support->inner,
3415 inner->tpid)))
3416 return false;
3417 }
3418
3419 return true;
3420 }
3421
3422 /**
3423 * ice_vc_to_vlan - transform from struct virtchnl_vlan to struct ice_vlan
3424 * @vc_vlan: struct virtchnl_vlan to transform
3425 */
ice_vc_to_vlan(struct virtchnl_vlan * vc_vlan)3426 static struct ice_vlan ice_vc_to_vlan(struct virtchnl_vlan *vc_vlan)
3427 {
3428 struct ice_vlan vlan = { 0 };
3429
3430 vlan.prio = FIELD_GET(VLAN_PRIO_MASK, vc_vlan->tci);
3431 vlan.vid = vc_vlan->tci & VLAN_VID_MASK;
3432 vlan.tpid = vc_vlan->tpid;
3433
3434 return vlan;
3435 }
3436
3437 /**
3438 * ice_vc_vlan_action - action to perform on the virthcnl_vlan
3439 * @vsi: VF's VSI used to perform the action
3440 * @vlan_action: function to perform the action with (i.e. add/del)
3441 * @vlan: VLAN filter to perform the action with
3442 */
3443 static int
ice_vc_vlan_action(struct ice_vsi * vsi,int (* vlan_action)(struct ice_vsi *,struct ice_vlan *),struct ice_vlan * vlan)3444 ice_vc_vlan_action(struct ice_vsi *vsi,
3445 int (*vlan_action)(struct ice_vsi *, struct ice_vlan *),
3446 struct ice_vlan *vlan)
3447 {
3448 int err;
3449
3450 err = vlan_action(vsi, vlan);
3451 if (err)
3452 return err;
3453
3454 return 0;
3455 }
3456
3457 /**
3458 * ice_vc_del_vlans - delete VLAN(s) from the virtchnl filter list
3459 * @vf: VF used to delete the VLAN(s)
3460 * @vsi: VF's VSI used to delete the VLAN(s)
3461 * @vfl: virthchnl filter list used to delete the filters
3462 */
3463 static int
ice_vc_del_vlans(struct ice_vf * vf,struct ice_vsi * vsi,struct virtchnl_vlan_filter_list_v2 * vfl)3464 ice_vc_del_vlans(struct ice_vf *vf, struct ice_vsi *vsi,
3465 struct virtchnl_vlan_filter_list_v2 *vfl)
3466 {
3467 bool vlan_promisc = ice_is_vlan_promisc_allowed(vf);
3468 int err;
3469 u16 i;
3470
3471 for (i = 0; i < vfl->num_elements; i++) {
3472 struct virtchnl_vlan_filter *vlan_fltr = &vfl->filters[i];
3473 struct virtchnl_vlan *vc_vlan;
3474
3475 vc_vlan = &vlan_fltr->outer;
3476 if (ice_vc_is_valid_vlan(vc_vlan)) {
3477 struct ice_vlan vlan = ice_vc_to_vlan(vc_vlan);
3478
3479 err = ice_vc_vlan_action(vsi,
3480 vsi->outer_vlan_ops.del_vlan,
3481 &vlan);
3482 if (err)
3483 return err;
3484
3485 if (vlan_promisc)
3486 ice_vf_dis_vlan_promisc(vsi, &vlan);
3487
3488 /* Disable VLAN filtering when only VLAN 0 is left */
3489 if (!ice_vsi_has_non_zero_vlans(vsi) && ice_is_dvm_ena(&vsi->back->hw)) {
3490 err = vsi->outer_vlan_ops.dis_tx_filtering(vsi);
3491 if (err)
3492 return err;
3493 }
3494 }
3495
3496 vc_vlan = &vlan_fltr->inner;
3497 if (ice_vc_is_valid_vlan(vc_vlan)) {
3498 struct ice_vlan vlan = ice_vc_to_vlan(vc_vlan);
3499
3500 err = ice_vc_vlan_action(vsi,
3501 vsi->inner_vlan_ops.del_vlan,
3502 &vlan);
3503 if (err)
3504 return err;
3505
3506 /* no support for VLAN promiscuous on inner VLAN unless
3507 * we are in Single VLAN Mode (SVM)
3508 */
3509 if (!ice_is_dvm_ena(&vsi->back->hw)) {
3510 if (vlan_promisc)
3511 ice_vf_dis_vlan_promisc(vsi, &vlan);
3512
3513 /* Disable VLAN filtering when only VLAN 0 is left */
3514 if (!ice_vsi_has_non_zero_vlans(vsi)) {
3515 err = vsi->inner_vlan_ops.dis_tx_filtering(vsi);
3516 if (err)
3517 return err;
3518 }
3519 }
3520 }
3521 }
3522
3523 return 0;
3524 }
3525
3526 /**
3527 * ice_vc_remove_vlan_v2_msg - virtchnl handler for VIRTCHNL_OP_DEL_VLAN_V2
3528 * @vf: VF the message was received from
3529 * @msg: message received from the VF
3530 */
ice_vc_remove_vlan_v2_msg(struct ice_vf * vf,u8 * msg)3531 static int ice_vc_remove_vlan_v2_msg(struct ice_vf *vf, u8 *msg)
3532 {
3533 struct virtchnl_vlan_filter_list_v2 *vfl =
3534 (struct virtchnl_vlan_filter_list_v2 *)msg;
3535 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
3536 struct ice_vsi *vsi;
3537
3538 if (!ice_vc_validate_vlan_filter_list(&vf->vlan_v2_caps.filtering,
3539 vfl)) {
3540 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3541 goto out;
3542 }
3543
3544 if (!ice_vc_isvalid_vsi_id(vf, vfl->vport_id)) {
3545 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3546 goto out;
3547 }
3548
3549 vsi = ice_get_vf_vsi(vf);
3550 if (!vsi) {
3551 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3552 goto out;
3553 }
3554
3555 if (ice_vc_del_vlans(vf, vsi, vfl))
3556 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3557
3558 out:
3559 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_DEL_VLAN_V2, v_ret, NULL,
3560 0);
3561 }
3562
3563 /**
3564 * ice_vc_add_vlans - add VLAN(s) from the virtchnl filter list
3565 * @vf: VF used to add the VLAN(s)
3566 * @vsi: VF's VSI used to add the VLAN(s)
3567 * @vfl: virthchnl filter list used to add the filters
3568 */
3569 static int
ice_vc_add_vlans(struct ice_vf * vf,struct ice_vsi * vsi,struct virtchnl_vlan_filter_list_v2 * vfl)3570 ice_vc_add_vlans(struct ice_vf *vf, struct ice_vsi *vsi,
3571 struct virtchnl_vlan_filter_list_v2 *vfl)
3572 {
3573 bool vlan_promisc = ice_is_vlan_promisc_allowed(vf);
3574 int err;
3575 u16 i;
3576
3577 for (i = 0; i < vfl->num_elements; i++) {
3578 struct virtchnl_vlan_filter *vlan_fltr = &vfl->filters[i];
3579 struct virtchnl_vlan *vc_vlan;
3580
3581 vc_vlan = &vlan_fltr->outer;
3582 if (ice_vc_is_valid_vlan(vc_vlan)) {
3583 struct ice_vlan vlan = ice_vc_to_vlan(vc_vlan);
3584
3585 err = ice_vc_vlan_action(vsi,
3586 vsi->outer_vlan_ops.add_vlan,
3587 &vlan);
3588 if (err)
3589 return err;
3590
3591 if (vlan_promisc) {
3592 err = ice_vf_ena_vlan_promisc(vf, vsi, &vlan);
3593 if (err)
3594 return err;
3595 }
3596
3597 /* Enable VLAN filtering on first non-zero VLAN */
3598 if (vf->spoofchk && vlan.vid && ice_is_dvm_ena(&vsi->back->hw)) {
3599 err = vsi->outer_vlan_ops.ena_tx_filtering(vsi);
3600 if (err)
3601 return err;
3602 }
3603 }
3604
3605 vc_vlan = &vlan_fltr->inner;
3606 if (ice_vc_is_valid_vlan(vc_vlan)) {
3607 struct ice_vlan vlan = ice_vc_to_vlan(vc_vlan);
3608
3609 err = ice_vc_vlan_action(vsi,
3610 vsi->inner_vlan_ops.add_vlan,
3611 &vlan);
3612 if (err)
3613 return err;
3614
3615 /* no support for VLAN promiscuous on inner VLAN unless
3616 * we are in Single VLAN Mode (SVM)
3617 */
3618 if (!ice_is_dvm_ena(&vsi->back->hw)) {
3619 if (vlan_promisc) {
3620 err = ice_vf_ena_vlan_promisc(vf, vsi,
3621 &vlan);
3622 if (err)
3623 return err;
3624 }
3625
3626 /* Enable VLAN filtering on first non-zero VLAN */
3627 if (vf->spoofchk && vlan.vid) {
3628 err = vsi->inner_vlan_ops.ena_tx_filtering(vsi);
3629 if (err)
3630 return err;
3631 }
3632 }
3633 }
3634 }
3635
3636 return 0;
3637 }
3638
3639 /**
3640 * ice_vc_validate_add_vlan_filter_list - validate add filter list from the VF
3641 * @vsi: VF VSI used to get number of existing VLAN filters
3642 * @vfc: negotiated/supported VLAN filtering capabilities
3643 * @vfl: VLAN filter list from VF to validate
3644 *
3645 * Validate all of the filters in the VLAN filter list from the VF during the
3646 * VIRTCHNL_OP_ADD_VLAN_V2 opcode. If any of the checks fail then return false.
3647 * Otherwise return true.
3648 */
3649 static bool
ice_vc_validate_add_vlan_filter_list(struct ice_vsi * vsi,struct virtchnl_vlan_filtering_caps * vfc,struct virtchnl_vlan_filter_list_v2 * vfl)3650 ice_vc_validate_add_vlan_filter_list(struct ice_vsi *vsi,
3651 struct virtchnl_vlan_filtering_caps *vfc,
3652 struct virtchnl_vlan_filter_list_v2 *vfl)
3653 {
3654 u16 num_requested_filters = ice_vsi_num_non_zero_vlans(vsi) +
3655 vfl->num_elements;
3656
3657 if (num_requested_filters > vfc->max_filters)
3658 return false;
3659
3660 return ice_vc_validate_vlan_filter_list(vfc, vfl);
3661 }
3662
3663 /**
3664 * ice_vc_add_vlan_v2_msg - virtchnl handler for VIRTCHNL_OP_ADD_VLAN_V2
3665 * @vf: VF the message was received from
3666 * @msg: message received from the VF
3667 */
ice_vc_add_vlan_v2_msg(struct ice_vf * vf,u8 * msg)3668 static int ice_vc_add_vlan_v2_msg(struct ice_vf *vf, u8 *msg)
3669 {
3670 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
3671 struct virtchnl_vlan_filter_list_v2 *vfl =
3672 (struct virtchnl_vlan_filter_list_v2 *)msg;
3673 struct ice_vsi *vsi;
3674
3675 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
3676 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3677 goto out;
3678 }
3679
3680 if (!ice_vc_isvalid_vsi_id(vf, vfl->vport_id)) {
3681 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3682 goto out;
3683 }
3684
3685 vsi = ice_get_vf_vsi(vf);
3686 if (!vsi) {
3687 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3688 goto out;
3689 }
3690
3691 if (!ice_vc_validate_add_vlan_filter_list(vsi,
3692 &vf->vlan_v2_caps.filtering,
3693 vfl)) {
3694 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3695 goto out;
3696 }
3697
3698 if (ice_vc_add_vlans(vf, vsi, vfl))
3699 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3700
3701 out:
3702 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_ADD_VLAN_V2, v_ret, NULL,
3703 0);
3704 }
3705
3706 /**
3707 * ice_vc_valid_vlan_setting - validate VLAN setting
3708 * @negotiated_settings: negotiated VLAN settings during VF init
3709 * @ethertype_setting: ethertype(s) requested for the VLAN setting
3710 */
3711 static bool
ice_vc_valid_vlan_setting(u32 negotiated_settings,u32 ethertype_setting)3712 ice_vc_valid_vlan_setting(u32 negotiated_settings, u32 ethertype_setting)
3713 {
3714 if (ethertype_setting && !(negotiated_settings & ethertype_setting))
3715 return false;
3716
3717 /* only allow a single VIRTCHNL_VLAN_ETHERTYPE if
3718 * VIRTHCNL_VLAN_ETHERTYPE_AND is not negotiated/supported
3719 */
3720 if (!(negotiated_settings & VIRTCHNL_VLAN_ETHERTYPE_AND) &&
3721 hweight32(ethertype_setting) > 1)
3722 return false;
3723
3724 /* ability to modify the VLAN setting was not negotiated */
3725 if (!(negotiated_settings & VIRTCHNL_VLAN_TOGGLE))
3726 return false;
3727
3728 return true;
3729 }
3730
3731 /**
3732 * ice_vc_valid_vlan_setting_msg - validate the VLAN setting message
3733 * @caps: negotiated VLAN settings during VF init
3734 * @msg: message to validate
3735 *
3736 * Used to validate any VLAN virtchnl message sent as a
3737 * virtchnl_vlan_setting structure. Validates the message against the
3738 * negotiated/supported caps during VF driver init.
3739 */
3740 static bool
ice_vc_valid_vlan_setting_msg(struct virtchnl_vlan_supported_caps * caps,struct virtchnl_vlan_setting * msg)3741 ice_vc_valid_vlan_setting_msg(struct virtchnl_vlan_supported_caps *caps,
3742 struct virtchnl_vlan_setting *msg)
3743 {
3744 if ((!msg->outer_ethertype_setting &&
3745 !msg->inner_ethertype_setting) ||
3746 (!caps->outer && !caps->inner))
3747 return false;
3748
3749 if (msg->outer_ethertype_setting &&
3750 !ice_vc_valid_vlan_setting(caps->outer,
3751 msg->outer_ethertype_setting))
3752 return false;
3753
3754 if (msg->inner_ethertype_setting &&
3755 !ice_vc_valid_vlan_setting(caps->inner,
3756 msg->inner_ethertype_setting))
3757 return false;
3758
3759 return true;
3760 }
3761
3762 /**
3763 * ice_vc_get_tpid - transform from VIRTCHNL_VLAN_ETHERTYPE_* to VLAN TPID
3764 * @ethertype_setting: VIRTCHNL_VLAN_ETHERTYPE_* used to get VLAN TPID
3765 * @tpid: VLAN TPID to populate
3766 */
ice_vc_get_tpid(u32 ethertype_setting,u16 * tpid)3767 static int ice_vc_get_tpid(u32 ethertype_setting, u16 *tpid)
3768 {
3769 switch (ethertype_setting) {
3770 case VIRTCHNL_VLAN_ETHERTYPE_8100:
3771 *tpid = ETH_P_8021Q;
3772 break;
3773 case VIRTCHNL_VLAN_ETHERTYPE_88A8:
3774 *tpid = ETH_P_8021AD;
3775 break;
3776 case VIRTCHNL_VLAN_ETHERTYPE_9100:
3777 *tpid = ETH_P_QINQ1;
3778 break;
3779 default:
3780 *tpid = 0;
3781 return -EINVAL;
3782 }
3783
3784 return 0;
3785 }
3786
3787 /**
3788 * ice_vc_ena_vlan_offload - enable VLAN offload based on the ethertype_setting
3789 * @vsi: VF's VSI used to enable the VLAN offload
3790 * @ena_offload: function used to enable the VLAN offload
3791 * @ethertype_setting: VIRTCHNL_VLAN_ETHERTYPE_* to enable offloads for
3792 */
3793 static int
ice_vc_ena_vlan_offload(struct ice_vsi * vsi,int (* ena_offload)(struct ice_vsi * vsi,u16 tpid),u32 ethertype_setting)3794 ice_vc_ena_vlan_offload(struct ice_vsi *vsi,
3795 int (*ena_offload)(struct ice_vsi *vsi, u16 tpid),
3796 u32 ethertype_setting)
3797 {
3798 u16 tpid;
3799 int err;
3800
3801 err = ice_vc_get_tpid(ethertype_setting, &tpid);
3802 if (err)
3803 return err;
3804
3805 err = ena_offload(vsi, tpid);
3806 if (err)
3807 return err;
3808
3809 return 0;
3810 }
3811
3812 #define ICE_L2TSEL_QRX_CONTEXT_REG_IDX 3
3813 #define ICE_L2TSEL_BIT_OFFSET 23
3814 enum ice_l2tsel {
3815 ICE_L2TSEL_EXTRACT_FIRST_TAG_L2TAG2_2ND,
3816 ICE_L2TSEL_EXTRACT_FIRST_TAG_L2TAG1,
3817 };
3818
3819 /**
3820 * ice_vsi_update_l2tsel - update l2tsel field for all Rx rings on this VSI
3821 * @vsi: VSI used to update l2tsel on
3822 * @l2tsel: l2tsel setting requested
3823 *
3824 * Use the l2tsel setting to update all of the Rx queue context bits for l2tsel.
3825 * This will modify which descriptor field the first offloaded VLAN will be
3826 * stripped into.
3827 */
ice_vsi_update_l2tsel(struct ice_vsi * vsi,enum ice_l2tsel l2tsel)3828 static void ice_vsi_update_l2tsel(struct ice_vsi *vsi, enum ice_l2tsel l2tsel)
3829 {
3830 struct ice_hw *hw = &vsi->back->hw;
3831 u32 l2tsel_bit;
3832 int i;
3833
3834 if (l2tsel == ICE_L2TSEL_EXTRACT_FIRST_TAG_L2TAG2_2ND)
3835 l2tsel_bit = 0;
3836 else
3837 l2tsel_bit = BIT(ICE_L2TSEL_BIT_OFFSET);
3838
3839 for (i = 0; i < vsi->alloc_rxq; i++) {
3840 u16 pfq = vsi->rxq_map[i];
3841 u32 qrx_context_offset;
3842 u32 regval;
3843
3844 qrx_context_offset =
3845 QRX_CONTEXT(ICE_L2TSEL_QRX_CONTEXT_REG_IDX, pfq);
3846
3847 regval = rd32(hw, qrx_context_offset);
3848 regval &= ~BIT(ICE_L2TSEL_BIT_OFFSET);
3849 regval |= l2tsel_bit;
3850 wr32(hw, qrx_context_offset, regval);
3851 }
3852 }
3853
3854 /**
3855 * ice_vc_ena_vlan_stripping_v2_msg
3856 * @vf: VF the message was received from
3857 * @msg: message received from the VF
3858 *
3859 * virthcnl handler for VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2
3860 */
ice_vc_ena_vlan_stripping_v2_msg(struct ice_vf * vf,u8 * msg)3861 static int ice_vc_ena_vlan_stripping_v2_msg(struct ice_vf *vf, u8 *msg)
3862 {
3863 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
3864 struct virtchnl_vlan_supported_caps *stripping_support;
3865 struct virtchnl_vlan_setting *strip_msg =
3866 (struct virtchnl_vlan_setting *)msg;
3867 u32 ethertype_setting;
3868 struct ice_vsi *vsi;
3869
3870 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
3871 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3872 goto out;
3873 }
3874
3875 if (!ice_vc_isvalid_vsi_id(vf, strip_msg->vport_id)) {
3876 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3877 goto out;
3878 }
3879
3880 vsi = ice_get_vf_vsi(vf);
3881 if (!vsi) {
3882 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3883 goto out;
3884 }
3885
3886 stripping_support = &vf->vlan_v2_caps.offloads.stripping_support;
3887 if (!ice_vc_valid_vlan_setting_msg(stripping_support, strip_msg)) {
3888 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3889 goto out;
3890 }
3891
3892 if (ice_vsi_is_rxq_crc_strip_dis(vsi)) {
3893 v_ret = VIRTCHNL_STATUS_ERR_NOT_SUPPORTED;
3894 goto out;
3895 }
3896
3897 ethertype_setting = strip_msg->outer_ethertype_setting;
3898 if (ethertype_setting) {
3899 if (ice_vc_ena_vlan_offload(vsi,
3900 vsi->outer_vlan_ops.ena_stripping,
3901 ethertype_setting)) {
3902 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3903 goto out;
3904 } else {
3905 enum ice_l2tsel l2tsel =
3906 ICE_L2TSEL_EXTRACT_FIRST_TAG_L2TAG2_2ND;
3907
3908 /* PF tells the VF that the outer VLAN tag is always
3909 * extracted to VIRTCHNL_VLAN_TAG_LOCATION_L2TAG2_2 and
3910 * inner is always extracted to
3911 * VIRTCHNL_VLAN_TAG_LOCATION_L2TAG1. This is needed to
3912 * support outer stripping so the first tag always ends
3913 * up in L2TAG2_2ND and the second/inner tag, if
3914 * enabled, is extracted in L2TAG1.
3915 */
3916 ice_vsi_update_l2tsel(vsi, l2tsel);
3917
3918 vf->vlan_strip_ena |= ICE_OUTER_VLAN_STRIP_ENA;
3919 }
3920 }
3921
3922 ethertype_setting = strip_msg->inner_ethertype_setting;
3923 if (ethertype_setting &&
3924 ice_vc_ena_vlan_offload(vsi, vsi->inner_vlan_ops.ena_stripping,
3925 ethertype_setting)) {
3926 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3927 goto out;
3928 }
3929
3930 if (ethertype_setting)
3931 vf->vlan_strip_ena |= ICE_INNER_VLAN_STRIP_ENA;
3932
3933 out:
3934 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2,
3935 v_ret, NULL, 0);
3936 }
3937
3938 /**
3939 * ice_vc_dis_vlan_stripping_v2_msg
3940 * @vf: VF the message was received from
3941 * @msg: message received from the VF
3942 *
3943 * virthcnl handler for VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2
3944 */
ice_vc_dis_vlan_stripping_v2_msg(struct ice_vf * vf,u8 * msg)3945 static int ice_vc_dis_vlan_stripping_v2_msg(struct ice_vf *vf, u8 *msg)
3946 {
3947 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
3948 struct virtchnl_vlan_supported_caps *stripping_support;
3949 struct virtchnl_vlan_setting *strip_msg =
3950 (struct virtchnl_vlan_setting *)msg;
3951 u32 ethertype_setting;
3952 struct ice_vsi *vsi;
3953
3954 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
3955 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3956 goto out;
3957 }
3958
3959 if (!ice_vc_isvalid_vsi_id(vf, strip_msg->vport_id)) {
3960 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3961 goto out;
3962 }
3963
3964 vsi = ice_get_vf_vsi(vf);
3965 if (!vsi) {
3966 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3967 goto out;
3968 }
3969
3970 stripping_support = &vf->vlan_v2_caps.offloads.stripping_support;
3971 if (!ice_vc_valid_vlan_setting_msg(stripping_support, strip_msg)) {
3972 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3973 goto out;
3974 }
3975
3976 ethertype_setting = strip_msg->outer_ethertype_setting;
3977 if (ethertype_setting) {
3978 if (vsi->outer_vlan_ops.dis_stripping(vsi)) {
3979 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3980 goto out;
3981 } else {
3982 enum ice_l2tsel l2tsel =
3983 ICE_L2TSEL_EXTRACT_FIRST_TAG_L2TAG1;
3984
3985 /* PF tells the VF that the outer VLAN tag is always
3986 * extracted to VIRTCHNL_VLAN_TAG_LOCATION_L2TAG2_2 and
3987 * inner is always extracted to
3988 * VIRTCHNL_VLAN_TAG_LOCATION_L2TAG1. This is needed to
3989 * support inner stripping while outer stripping is
3990 * disabled so that the first and only tag is extracted
3991 * in L2TAG1.
3992 */
3993 ice_vsi_update_l2tsel(vsi, l2tsel);
3994
3995 vf->vlan_strip_ena &= ~ICE_OUTER_VLAN_STRIP_ENA;
3996 }
3997 }
3998
3999 ethertype_setting = strip_msg->inner_ethertype_setting;
4000 if (ethertype_setting && vsi->inner_vlan_ops.dis_stripping(vsi)) {
4001 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
4002 goto out;
4003 }
4004
4005 if (ethertype_setting)
4006 vf->vlan_strip_ena &= ~ICE_INNER_VLAN_STRIP_ENA;
4007
4008 out:
4009 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2,
4010 v_ret, NULL, 0);
4011 }
4012
4013 /**
4014 * ice_vc_ena_vlan_insertion_v2_msg
4015 * @vf: VF the message was received from
4016 * @msg: message received from the VF
4017 *
4018 * virthcnl handler for VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2
4019 */
ice_vc_ena_vlan_insertion_v2_msg(struct ice_vf * vf,u8 * msg)4020 static int ice_vc_ena_vlan_insertion_v2_msg(struct ice_vf *vf, u8 *msg)
4021 {
4022 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
4023 struct virtchnl_vlan_supported_caps *insertion_support;
4024 struct virtchnl_vlan_setting *insertion_msg =
4025 (struct virtchnl_vlan_setting *)msg;
4026 u32 ethertype_setting;
4027 struct ice_vsi *vsi;
4028
4029 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
4030 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
4031 goto out;
4032 }
4033
4034 if (!ice_vc_isvalid_vsi_id(vf, insertion_msg->vport_id)) {
4035 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
4036 goto out;
4037 }
4038
4039 vsi = ice_get_vf_vsi(vf);
4040 if (!vsi) {
4041 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
4042 goto out;
4043 }
4044
4045 insertion_support = &vf->vlan_v2_caps.offloads.insertion_support;
4046 if (!ice_vc_valid_vlan_setting_msg(insertion_support, insertion_msg)) {
4047 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
4048 goto out;
4049 }
4050
4051 ethertype_setting = insertion_msg->outer_ethertype_setting;
4052 if (ethertype_setting &&
4053 ice_vc_ena_vlan_offload(vsi, vsi->outer_vlan_ops.ena_insertion,
4054 ethertype_setting)) {
4055 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
4056 goto out;
4057 }
4058
4059 ethertype_setting = insertion_msg->inner_ethertype_setting;
4060 if (ethertype_setting &&
4061 ice_vc_ena_vlan_offload(vsi, vsi->inner_vlan_ops.ena_insertion,
4062 ethertype_setting)) {
4063 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
4064 goto out;
4065 }
4066
4067 out:
4068 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2,
4069 v_ret, NULL, 0);
4070 }
4071
4072 /**
4073 * ice_vc_dis_vlan_insertion_v2_msg
4074 * @vf: VF the message was received from
4075 * @msg: message received from the VF
4076 *
4077 * virthcnl handler for VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2
4078 */
ice_vc_dis_vlan_insertion_v2_msg(struct ice_vf * vf,u8 * msg)4079 static int ice_vc_dis_vlan_insertion_v2_msg(struct ice_vf *vf, u8 *msg)
4080 {
4081 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
4082 struct virtchnl_vlan_supported_caps *insertion_support;
4083 struct virtchnl_vlan_setting *insertion_msg =
4084 (struct virtchnl_vlan_setting *)msg;
4085 u32 ethertype_setting;
4086 struct ice_vsi *vsi;
4087
4088 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
4089 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
4090 goto out;
4091 }
4092
4093 if (!ice_vc_isvalid_vsi_id(vf, insertion_msg->vport_id)) {
4094 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
4095 goto out;
4096 }
4097
4098 vsi = ice_get_vf_vsi(vf);
4099 if (!vsi) {
4100 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
4101 goto out;
4102 }
4103
4104 insertion_support = &vf->vlan_v2_caps.offloads.insertion_support;
4105 if (!ice_vc_valid_vlan_setting_msg(insertion_support, insertion_msg)) {
4106 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
4107 goto out;
4108 }
4109
4110 ethertype_setting = insertion_msg->outer_ethertype_setting;
4111 if (ethertype_setting && vsi->outer_vlan_ops.dis_insertion(vsi)) {
4112 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
4113 goto out;
4114 }
4115
4116 ethertype_setting = insertion_msg->inner_ethertype_setting;
4117 if (ethertype_setting && vsi->inner_vlan_ops.dis_insertion(vsi)) {
4118 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
4119 goto out;
4120 }
4121
4122 out:
4123 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2,
4124 v_ret, NULL, 0);
4125 }
4126
ice_vc_get_ptp_cap(struct ice_vf * vf,const struct virtchnl_ptp_caps * msg)4127 static int ice_vc_get_ptp_cap(struct ice_vf *vf,
4128 const struct virtchnl_ptp_caps *msg)
4129 {
4130 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_ERR_PARAM;
4131 u32 caps = VIRTCHNL_1588_PTP_CAP_RX_TSTAMP |
4132 VIRTCHNL_1588_PTP_CAP_READ_PHC;
4133
4134 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states))
4135 goto err;
4136
4137 v_ret = VIRTCHNL_STATUS_SUCCESS;
4138
4139 if (msg->caps & caps)
4140 vf->ptp_caps = caps;
4141
4142 err:
4143 /* send the response back to the VF */
4144 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_1588_PTP_GET_CAPS, v_ret,
4145 (u8 *)&vf->ptp_caps,
4146 sizeof(struct virtchnl_ptp_caps));
4147 }
4148
ice_vc_get_phc_time(struct ice_vf * vf)4149 static int ice_vc_get_phc_time(struct ice_vf *vf)
4150 {
4151 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_ERR_PARAM;
4152 struct virtchnl_phc_time *phc_time = NULL;
4153 struct ice_pf *pf = vf->pf;
4154 u32 len = 0;
4155 int ret;
4156
4157 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states))
4158 goto err;
4159
4160 v_ret = VIRTCHNL_STATUS_SUCCESS;
4161
4162 phc_time = kzalloc(sizeof(*phc_time), GFP_KERNEL);
4163 if (!phc_time) {
4164 v_ret = VIRTCHNL_STATUS_ERR_NO_MEMORY;
4165 goto err;
4166 }
4167
4168 len = sizeof(*phc_time);
4169
4170 phc_time->time = ice_ptp_read_src_clk_reg(pf, NULL);
4171
4172 err:
4173 /* send the response back to the VF */
4174 ret = ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_1588_PTP_GET_TIME, v_ret,
4175 (u8 *)phc_time, len);
4176 kfree(phc_time);
4177 return ret;
4178 }
4179
4180 static const struct ice_virtchnl_ops ice_virtchnl_dflt_ops = {
4181 .get_ver_msg = ice_vc_get_ver_msg,
4182 .get_vf_res_msg = ice_vc_get_vf_res_msg,
4183 .reset_vf = ice_vc_reset_vf_msg,
4184 .add_mac_addr_msg = ice_vc_add_mac_addr_msg,
4185 .del_mac_addr_msg = ice_vc_del_mac_addr_msg,
4186 .cfg_qs_msg = ice_vc_cfg_qs_msg,
4187 .ena_qs_msg = ice_vc_ena_qs_msg,
4188 .dis_qs_msg = ice_vc_dis_qs_msg,
4189 .request_qs_msg = ice_vc_request_qs_msg,
4190 .cfg_irq_map_msg = ice_vc_cfg_irq_map_msg,
4191 .config_rss_key = ice_vc_config_rss_key,
4192 .config_rss_lut = ice_vc_config_rss_lut,
4193 .config_rss_hfunc = ice_vc_config_rss_hfunc,
4194 .get_stats_msg = ice_vc_get_stats_msg,
4195 .cfg_promiscuous_mode_msg = ice_vc_cfg_promiscuous_mode_msg,
4196 .add_vlan_msg = ice_vc_add_vlan_msg,
4197 .remove_vlan_msg = ice_vc_remove_vlan_msg,
4198 .query_rxdid = ice_vc_query_rxdid,
4199 .get_rss_hena = ice_vc_get_rss_hena,
4200 .set_rss_hena_msg = ice_vc_set_rss_hena,
4201 .ena_vlan_stripping = ice_vc_ena_vlan_stripping,
4202 .dis_vlan_stripping = ice_vc_dis_vlan_stripping,
4203 .handle_rss_cfg_msg = ice_vc_handle_rss_cfg,
4204 .add_fdir_fltr_msg = ice_vc_add_fdir_fltr,
4205 .del_fdir_fltr_msg = ice_vc_del_fdir_fltr,
4206 .get_offload_vlan_v2_caps = ice_vc_get_offload_vlan_v2_caps,
4207 .add_vlan_v2_msg = ice_vc_add_vlan_v2_msg,
4208 .remove_vlan_v2_msg = ice_vc_remove_vlan_v2_msg,
4209 .ena_vlan_stripping_v2_msg = ice_vc_ena_vlan_stripping_v2_msg,
4210 .dis_vlan_stripping_v2_msg = ice_vc_dis_vlan_stripping_v2_msg,
4211 .ena_vlan_insertion_v2_msg = ice_vc_ena_vlan_insertion_v2_msg,
4212 .dis_vlan_insertion_v2_msg = ice_vc_dis_vlan_insertion_v2_msg,
4213 .get_qos_caps = ice_vc_get_qos_caps,
4214 .cfg_q_bw = ice_vc_cfg_q_bw,
4215 .cfg_q_quanta = ice_vc_cfg_q_quanta,
4216 .get_ptp_cap = ice_vc_get_ptp_cap,
4217 .get_phc_time = ice_vc_get_phc_time,
4218 /* If you add a new op here please make sure to add it to
4219 * ice_virtchnl_repr_ops as well.
4220 */
4221 };
4222
4223 /**
4224 * ice_virtchnl_set_dflt_ops - Switch to default virtchnl ops
4225 * @vf: the VF to switch ops
4226 */
ice_virtchnl_set_dflt_ops(struct ice_vf * vf)4227 void ice_virtchnl_set_dflt_ops(struct ice_vf *vf)
4228 {
4229 vf->virtchnl_ops = &ice_virtchnl_dflt_ops;
4230 }
4231
4232 /**
4233 * ice_vc_repr_add_mac
4234 * @vf: pointer to VF
4235 * @msg: virtchannel message
4236 *
4237 * When port representors are created, we do not add MAC rule
4238 * to firmware, we store it so that PF could report same
4239 * MAC as VF.
4240 */
ice_vc_repr_add_mac(struct ice_vf * vf,u8 * msg)4241 static int ice_vc_repr_add_mac(struct ice_vf *vf, u8 *msg)
4242 {
4243 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
4244 struct virtchnl_ether_addr_list *al =
4245 (struct virtchnl_ether_addr_list *)msg;
4246 struct ice_vsi *vsi;
4247 struct ice_pf *pf;
4248 int i;
4249
4250 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states) ||
4251 !ice_vc_isvalid_vsi_id(vf, al->vsi_id)) {
4252 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
4253 goto handle_mac_exit;
4254 }
4255
4256 pf = vf->pf;
4257
4258 vsi = ice_get_vf_vsi(vf);
4259 if (!vsi) {
4260 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
4261 goto handle_mac_exit;
4262 }
4263
4264 for (i = 0; i < al->num_elements; i++) {
4265 u8 *mac_addr = al->list[i].addr;
4266
4267 if (!is_unicast_ether_addr(mac_addr) ||
4268 ether_addr_equal(mac_addr, vf->hw_lan_addr))
4269 continue;
4270
4271 if (vf->pf_set_mac) {
4272 dev_err(ice_pf_to_dev(pf), "VF attempting to override administratively set MAC address\n");
4273 v_ret = VIRTCHNL_STATUS_ERR_NOT_SUPPORTED;
4274 goto handle_mac_exit;
4275 }
4276
4277 ice_vfhw_mac_add(vf, &al->list[i]);
4278 vf->num_mac++;
4279 break;
4280 }
4281
4282 handle_mac_exit:
4283 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_ADD_ETH_ADDR,
4284 v_ret, NULL, 0);
4285 }
4286
4287 /**
4288 * ice_vc_repr_del_mac - response with success for deleting MAC
4289 * @vf: pointer to VF
4290 * @msg: virtchannel message
4291 *
4292 * Respond with success to not break normal VF flow.
4293 * For legacy VF driver try to update cached MAC address.
4294 */
4295 static int
ice_vc_repr_del_mac(struct ice_vf __always_unused * vf,u8 __always_unused * msg)4296 ice_vc_repr_del_mac(struct ice_vf __always_unused *vf, u8 __always_unused *msg)
4297 {
4298 struct virtchnl_ether_addr_list *al =
4299 (struct virtchnl_ether_addr_list *)msg;
4300
4301 ice_update_legacy_cached_mac(vf, &al->list[0]);
4302
4303 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_DEL_ETH_ADDR,
4304 VIRTCHNL_STATUS_SUCCESS, NULL, 0);
4305 }
4306
4307 static int
ice_vc_repr_cfg_promiscuous_mode(struct ice_vf * vf,u8 __always_unused * msg)4308 ice_vc_repr_cfg_promiscuous_mode(struct ice_vf *vf, u8 __always_unused *msg)
4309 {
4310 dev_dbg(ice_pf_to_dev(vf->pf),
4311 "Can't config promiscuous mode in switchdev mode for VF %d\n",
4312 vf->vf_id);
4313 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE,
4314 VIRTCHNL_STATUS_ERR_NOT_SUPPORTED,
4315 NULL, 0);
4316 }
4317
4318 static const struct ice_virtchnl_ops ice_virtchnl_repr_ops = {
4319 .get_ver_msg = ice_vc_get_ver_msg,
4320 .get_vf_res_msg = ice_vc_get_vf_res_msg,
4321 .reset_vf = ice_vc_reset_vf_msg,
4322 .add_mac_addr_msg = ice_vc_repr_add_mac,
4323 .del_mac_addr_msg = ice_vc_repr_del_mac,
4324 .cfg_qs_msg = ice_vc_cfg_qs_msg,
4325 .ena_qs_msg = ice_vc_ena_qs_msg,
4326 .dis_qs_msg = ice_vc_dis_qs_msg,
4327 .request_qs_msg = ice_vc_request_qs_msg,
4328 .cfg_irq_map_msg = ice_vc_cfg_irq_map_msg,
4329 .config_rss_key = ice_vc_config_rss_key,
4330 .config_rss_lut = ice_vc_config_rss_lut,
4331 .config_rss_hfunc = ice_vc_config_rss_hfunc,
4332 .get_stats_msg = ice_vc_get_stats_msg,
4333 .cfg_promiscuous_mode_msg = ice_vc_repr_cfg_promiscuous_mode,
4334 .add_vlan_msg = ice_vc_add_vlan_msg,
4335 .remove_vlan_msg = ice_vc_remove_vlan_msg,
4336 .query_rxdid = ice_vc_query_rxdid,
4337 .get_rss_hena = ice_vc_get_rss_hena,
4338 .set_rss_hena_msg = ice_vc_set_rss_hena,
4339 .ena_vlan_stripping = ice_vc_ena_vlan_stripping,
4340 .dis_vlan_stripping = ice_vc_dis_vlan_stripping,
4341 .handle_rss_cfg_msg = ice_vc_handle_rss_cfg,
4342 .add_fdir_fltr_msg = ice_vc_add_fdir_fltr,
4343 .del_fdir_fltr_msg = ice_vc_del_fdir_fltr,
4344 .get_offload_vlan_v2_caps = ice_vc_get_offload_vlan_v2_caps,
4345 .add_vlan_v2_msg = ice_vc_add_vlan_v2_msg,
4346 .remove_vlan_v2_msg = ice_vc_remove_vlan_v2_msg,
4347 .ena_vlan_stripping_v2_msg = ice_vc_ena_vlan_stripping_v2_msg,
4348 .dis_vlan_stripping_v2_msg = ice_vc_dis_vlan_stripping_v2_msg,
4349 .ena_vlan_insertion_v2_msg = ice_vc_ena_vlan_insertion_v2_msg,
4350 .dis_vlan_insertion_v2_msg = ice_vc_dis_vlan_insertion_v2_msg,
4351 .get_qos_caps = ice_vc_get_qos_caps,
4352 .cfg_q_bw = ice_vc_cfg_q_bw,
4353 .cfg_q_quanta = ice_vc_cfg_q_quanta,
4354 .get_ptp_cap = ice_vc_get_ptp_cap,
4355 .get_phc_time = ice_vc_get_phc_time,
4356 };
4357
4358 /**
4359 * ice_virtchnl_set_repr_ops - Switch to representor virtchnl ops
4360 * @vf: the VF to switch ops
4361 */
ice_virtchnl_set_repr_ops(struct ice_vf * vf)4362 void ice_virtchnl_set_repr_ops(struct ice_vf *vf)
4363 {
4364 vf->virtchnl_ops = &ice_virtchnl_repr_ops;
4365 }
4366
4367 /**
4368 * ice_is_malicious_vf - check if this vf might be overflowing mailbox
4369 * @vf: the VF to check
4370 * @mbxdata: data about the state of the mailbox
4371 *
4372 * Detect if a given VF might be malicious and attempting to overflow the PF
4373 * mailbox. If so, log a warning message and ignore this event.
4374 */
4375 static bool
ice_is_malicious_vf(struct ice_vf * vf,struct ice_mbx_data * mbxdata)4376 ice_is_malicious_vf(struct ice_vf *vf, struct ice_mbx_data *mbxdata)
4377 {
4378 bool report_malvf = false;
4379 struct device *dev;
4380 struct ice_pf *pf;
4381 int status;
4382
4383 pf = vf->pf;
4384 dev = ice_pf_to_dev(pf);
4385
4386 if (test_bit(ICE_VF_STATE_DIS, vf->vf_states))
4387 return vf->mbx_info.malicious;
4388
4389 /* check to see if we have a newly malicious VF */
4390 status = ice_mbx_vf_state_handler(&pf->hw, mbxdata, &vf->mbx_info,
4391 &report_malvf);
4392 if (status)
4393 dev_warn_ratelimited(dev, "Unable to check status of mailbox overflow for VF %u MAC %pM, status %d\n",
4394 vf->vf_id, vf->dev_lan_addr, status);
4395
4396 if (report_malvf) {
4397 struct ice_vsi *pf_vsi = ice_get_main_vsi(pf);
4398 u8 zero_addr[ETH_ALEN] = {};
4399
4400 dev_warn(dev, "VF MAC %pM on PF MAC %pM is generating asynchronous messages and may be overflowing the PF message queue. Please see the Adapter User Guide for more information\n",
4401 vf->dev_lan_addr,
4402 pf_vsi ? pf_vsi->netdev->dev_addr : zero_addr);
4403 }
4404
4405 return vf->mbx_info.malicious;
4406 }
4407
4408 /**
4409 * ice_vc_process_vf_msg - Process request from VF
4410 * @pf: pointer to the PF structure
4411 * @event: pointer to the AQ event
4412 * @mbxdata: information used to detect VF attempting mailbox overflow
4413 *
4414 * Called from the common asq/arq handler to process request from VF. When this
4415 * flow is used for devices with hardware VF to PF message queue overflow
4416 * support (ICE_F_MBX_LIMIT) mbxdata is set to NULL and ice_is_malicious_vf
4417 * check is skipped.
4418 */
ice_vc_process_vf_msg(struct ice_pf * pf,struct ice_rq_event_info * event,struct ice_mbx_data * mbxdata)4419 void ice_vc_process_vf_msg(struct ice_pf *pf, struct ice_rq_event_info *event,
4420 struct ice_mbx_data *mbxdata)
4421 {
4422 u32 v_opcode = le32_to_cpu(event->desc.cookie_high);
4423 s16 vf_id = le16_to_cpu(event->desc.retval);
4424 const struct ice_virtchnl_ops *ops;
4425 u16 msglen = event->msg_len;
4426 u8 *msg = event->msg_buf;
4427 struct ice_vf *vf = NULL;
4428 struct device *dev;
4429 int err = 0;
4430
4431 dev = ice_pf_to_dev(pf);
4432
4433 vf = ice_get_vf_by_id(pf, vf_id);
4434 if (!vf) {
4435 dev_err(dev, "Unable to locate VF for message from VF ID %d, opcode %d, len %d\n",
4436 vf_id, v_opcode, msglen);
4437 return;
4438 }
4439
4440 mutex_lock(&vf->cfg_lock);
4441
4442 /* Check if the VF is trying to overflow the mailbox */
4443 if (mbxdata && ice_is_malicious_vf(vf, mbxdata))
4444 goto finish;
4445
4446 /* Check if VF is disabled. */
4447 if (test_bit(ICE_VF_STATE_DIS, vf->vf_states)) {
4448 err = -EPERM;
4449 goto error_handler;
4450 }
4451
4452 ops = vf->virtchnl_ops;
4453
4454 /* Perform basic checks on the msg */
4455 err = virtchnl_vc_validate_vf_msg(&vf->vf_ver, v_opcode, msg, msglen);
4456 if (err) {
4457 if (err == VIRTCHNL_STATUS_ERR_PARAM)
4458 err = -EPERM;
4459 else
4460 err = -EINVAL;
4461 }
4462
4463 error_handler:
4464 if (err) {
4465 ice_vc_send_msg_to_vf(vf, v_opcode, VIRTCHNL_STATUS_ERR_PARAM,
4466 NULL, 0);
4467 dev_err(dev, "Invalid message from VF %d, opcode %d, len %d, error %d\n",
4468 vf_id, v_opcode, msglen, err);
4469 goto finish;
4470 }
4471
4472 if (!ice_vc_is_opcode_allowed(vf, v_opcode)) {
4473 ice_vc_send_msg_to_vf(vf, v_opcode,
4474 VIRTCHNL_STATUS_ERR_NOT_SUPPORTED, NULL,
4475 0);
4476 goto finish;
4477 }
4478
4479 switch (v_opcode) {
4480 case VIRTCHNL_OP_VERSION:
4481 err = ops->get_ver_msg(vf, msg);
4482 break;
4483 case VIRTCHNL_OP_GET_VF_RESOURCES:
4484 err = ops->get_vf_res_msg(vf, msg);
4485 if (ice_vf_init_vlan_stripping(vf))
4486 dev_dbg(dev, "Failed to initialize VLAN stripping for VF %d\n",
4487 vf->vf_id);
4488 ice_vc_notify_vf_link_state(vf);
4489 break;
4490 case VIRTCHNL_OP_RESET_VF:
4491 ops->reset_vf(vf);
4492 break;
4493 case VIRTCHNL_OP_ADD_ETH_ADDR:
4494 err = ops->add_mac_addr_msg(vf, msg);
4495 break;
4496 case VIRTCHNL_OP_DEL_ETH_ADDR:
4497 err = ops->del_mac_addr_msg(vf, msg);
4498 break;
4499 case VIRTCHNL_OP_CONFIG_VSI_QUEUES:
4500 err = ops->cfg_qs_msg(vf, msg);
4501 break;
4502 case VIRTCHNL_OP_ENABLE_QUEUES:
4503 err = ops->ena_qs_msg(vf, msg);
4504 ice_vc_notify_vf_link_state(vf);
4505 break;
4506 case VIRTCHNL_OP_DISABLE_QUEUES:
4507 err = ops->dis_qs_msg(vf, msg);
4508 break;
4509 case VIRTCHNL_OP_REQUEST_QUEUES:
4510 err = ops->request_qs_msg(vf, msg);
4511 break;
4512 case VIRTCHNL_OP_CONFIG_IRQ_MAP:
4513 err = ops->cfg_irq_map_msg(vf, msg);
4514 break;
4515 case VIRTCHNL_OP_CONFIG_RSS_KEY:
4516 err = ops->config_rss_key(vf, msg);
4517 break;
4518 case VIRTCHNL_OP_CONFIG_RSS_LUT:
4519 err = ops->config_rss_lut(vf, msg);
4520 break;
4521 case VIRTCHNL_OP_CONFIG_RSS_HFUNC:
4522 err = ops->config_rss_hfunc(vf, msg);
4523 break;
4524 case VIRTCHNL_OP_GET_STATS:
4525 err = ops->get_stats_msg(vf, msg);
4526 break;
4527 case VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE:
4528 err = ops->cfg_promiscuous_mode_msg(vf, msg);
4529 break;
4530 case VIRTCHNL_OP_ADD_VLAN:
4531 err = ops->add_vlan_msg(vf, msg);
4532 break;
4533 case VIRTCHNL_OP_DEL_VLAN:
4534 err = ops->remove_vlan_msg(vf, msg);
4535 break;
4536 case VIRTCHNL_OP_GET_SUPPORTED_RXDIDS:
4537 err = ops->query_rxdid(vf);
4538 break;
4539 case VIRTCHNL_OP_GET_RSS_HENA_CAPS:
4540 err = ops->get_rss_hena(vf);
4541 break;
4542 case VIRTCHNL_OP_SET_RSS_HENA:
4543 err = ops->set_rss_hena_msg(vf, msg);
4544 break;
4545 case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING:
4546 err = ops->ena_vlan_stripping(vf);
4547 break;
4548 case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING:
4549 err = ops->dis_vlan_stripping(vf);
4550 break;
4551 case VIRTCHNL_OP_ADD_FDIR_FILTER:
4552 err = ops->add_fdir_fltr_msg(vf, msg);
4553 break;
4554 case VIRTCHNL_OP_DEL_FDIR_FILTER:
4555 err = ops->del_fdir_fltr_msg(vf, msg);
4556 break;
4557 case VIRTCHNL_OP_ADD_RSS_CFG:
4558 err = ops->handle_rss_cfg_msg(vf, msg, true);
4559 break;
4560 case VIRTCHNL_OP_DEL_RSS_CFG:
4561 err = ops->handle_rss_cfg_msg(vf, msg, false);
4562 break;
4563 case VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS:
4564 err = ops->get_offload_vlan_v2_caps(vf);
4565 break;
4566 case VIRTCHNL_OP_ADD_VLAN_V2:
4567 err = ops->add_vlan_v2_msg(vf, msg);
4568 break;
4569 case VIRTCHNL_OP_DEL_VLAN_V2:
4570 err = ops->remove_vlan_v2_msg(vf, msg);
4571 break;
4572 case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2:
4573 err = ops->ena_vlan_stripping_v2_msg(vf, msg);
4574 break;
4575 case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2:
4576 err = ops->dis_vlan_stripping_v2_msg(vf, msg);
4577 break;
4578 case VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2:
4579 err = ops->ena_vlan_insertion_v2_msg(vf, msg);
4580 break;
4581 case VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2:
4582 err = ops->dis_vlan_insertion_v2_msg(vf, msg);
4583 break;
4584 case VIRTCHNL_OP_GET_QOS_CAPS:
4585 err = ops->get_qos_caps(vf);
4586 break;
4587 case VIRTCHNL_OP_CONFIG_QUEUE_BW:
4588 err = ops->cfg_q_bw(vf, msg);
4589 break;
4590 case VIRTCHNL_OP_CONFIG_QUANTA:
4591 err = ops->cfg_q_quanta(vf, msg);
4592 break;
4593 case VIRTCHNL_OP_1588_PTP_GET_CAPS:
4594 err = ops->get_ptp_cap(vf, (const void *)msg);
4595 break;
4596 case VIRTCHNL_OP_1588_PTP_GET_TIME:
4597 err = ops->get_phc_time(vf);
4598 break;
4599 case VIRTCHNL_OP_UNKNOWN:
4600 default:
4601 dev_err(dev, "Unsupported opcode %d from VF %d\n", v_opcode,
4602 vf_id);
4603 err = ice_vc_send_msg_to_vf(vf, v_opcode,
4604 VIRTCHNL_STATUS_ERR_NOT_SUPPORTED,
4605 NULL, 0);
4606 break;
4607 }
4608 if (err) {
4609 /* Helper function cares less about error return values here
4610 * as it is busy with pending work.
4611 */
4612 dev_info(dev, "PF failed to honor VF %d, opcode %d, error %d\n",
4613 vf_id, v_opcode, err);
4614 }
4615
4616 finish:
4617 mutex_unlock(&vf->cfg_lock);
4618 ice_put_vf(vf);
4619 }
4620