1
2
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
19struct ice_vc_hdr_match_type {
20 u32 vc_hdr;
21 u32 ice_hdr;
22};
23
24static 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
49struct ice_vc_hash_field_match_type {
50 u32 vc_hdr;
51
52
53 u32 vc_hash_field;
54
55
56 u64 ice_hash_field;
57
58
59};
60
61static const struct
62ice_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
170
171
172
173
174
175
176static void
177ice_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
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
192
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
202
203
204
205
206
207static void
208ice_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
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
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
227
228
229
230
231void 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
252
253
254void 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
267
268
269
270
271void 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
286
287
288
289
290
291
292
293
294int
295ice_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
319
320
321
322
323
324static 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
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
342
343
344
345
346
347
348
349static 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
364
365
366
367
368
369static int ice_vc_get_vf_res_msg(struct ice_vf *vf, u8 *msg)
370{
371 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
372 struct virtchnl_vf_resource *vfres = NULL;
373 struct ice_hw *hw = &vf->pf->hw;
374 struct ice_vsi *vsi;
375 int len = 0;
376 int ret;
377
378 if (ice_check_vf_init(vf)) {
379 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
380 goto err;
381 }
382
383 len = sizeof(struct virtchnl_vf_resource);
384
385 vfres = kzalloc(len, GFP_KERNEL);
386 if (!vfres) {
387 v_ret = VIRTCHNL_STATUS_ERR_NO_MEMORY;
388 len = 0;
389 goto err;
390 }
391 if (VF_IS_V11(&vf->vf_ver))
392 vf->driver_caps = *(u32 *)msg;
393 else
394 vf->driver_caps = VIRTCHNL_VF_OFFLOAD_L2 |
395 VIRTCHNL_VF_OFFLOAD_RSS_REG |
396 VIRTCHNL_VF_OFFLOAD_VLAN;
397
398 vfres->vf_cap_flags = VIRTCHNL_VF_OFFLOAD_L2;
399 vsi = ice_get_vf_vsi(vf);
400 if (!vsi) {
401 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
402 goto err;
403 }
404
405 if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_VLAN_V2) {
406
407 vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_VLAN_V2;
408 } else if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_VLAN) {
409
410
411
412
413
414
415 if (ice_is_dvm_ena(hw) && ice_vf_is_port_vlan_ena(vf)) {
416 vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_VLAN;
417 } else if (!ice_is_dvm_ena(hw) &&
418 !ice_vf_is_port_vlan_ena(vf)) {
419 vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_VLAN;
420
421
422
423
424 ice_vf_vsi_cfg_svm_legacy_vlan_mode(vsi);
425 } else if (ice_is_dvm_ena(hw)) {
426
427
428
429 ice_vf_vsi_cfg_dvm_legacy_vlan_mode(vsi);
430 }
431 }
432
433 if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_RSS_PF) {
434 vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_RSS_PF;
435 } else {
436 if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_RSS_AQ)
437 vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_RSS_AQ;
438 else
439 vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_RSS_REG;
440 }
441
442 if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_FDIR_PF)
443 vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_FDIR_PF;
444
445 if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_RSS_PCTYPE_V2)
446 vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_RSS_PCTYPE_V2;
447
448 if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_ENCAP)
449 vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_ENCAP;
450
451 if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_ENCAP_CSUM)
452 vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_ENCAP_CSUM;
453
454 if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_RX_POLLING)
455 vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_RX_POLLING;
456
457 if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_WB_ON_ITR)
458 vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_WB_ON_ITR;
459
460 if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_REQ_QUEUES)
461 vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_REQ_QUEUES;
462
463 if (vf->driver_caps & VIRTCHNL_VF_CAP_ADV_LINK_SPEED)
464 vfres->vf_cap_flags |= VIRTCHNL_VF_CAP_ADV_LINK_SPEED;
465
466 if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_ADV_RSS_PF)
467 vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_ADV_RSS_PF;
468
469 if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_USO)
470 vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_USO;
471
472 vfres->num_vsis = 1;
473
474 vfres->num_queue_pairs = vsi->num_txq;
475 vfres->max_vectors = vf->pf->vfs.num_msix_per;
476 vfres->rss_key_size = ICE_VSIQF_HKEY_ARRAY_SIZE;
477 vfres->rss_lut_size = ICE_VSIQF_HLUT_ARRAY_SIZE;
478 vfres->max_mtu = ice_vc_get_max_frame_size(vf);
479
480 vfres->vsi_res[0].vsi_id = vf->lan_vsi_num;
481 vfres->vsi_res[0].vsi_type = VIRTCHNL_VSI_SRIOV;
482 vfres->vsi_res[0].num_queue_pairs = vsi->num_txq;
483 ether_addr_copy(vfres->vsi_res[0].default_mac_addr,
484 vf->hw_lan_addr.addr);
485
486
487 vf->driver_caps = vfres->vf_cap_flags;
488
489 ice_vc_set_caps_allowlist(vf);
490 ice_vc_set_working_allowlist(vf);
491
492 set_bit(ICE_VF_STATE_ACTIVE, vf->vf_states);
493
494err:
495
496 ret = ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_GET_VF_RESOURCES, v_ret,
497 (u8 *)vfres, len);
498
499 kfree(vfres);
500 return ret;
501}
502
503
504
505
506
507
508
509
510
511static void ice_vc_reset_vf_msg(struct ice_vf *vf)
512{
513 if (test_bit(ICE_VF_STATE_INIT, vf->vf_states))
514 ice_reset_vf(vf, 0);
515}
516
517
518
519
520
521
522
523
524bool ice_vc_isvalid_vsi_id(struct ice_vf *vf, u16 vsi_id)
525{
526 struct ice_pf *pf = vf->pf;
527 struct ice_vsi *vsi;
528
529 vsi = ice_find_vsi(pf, vsi_id);
530
531 return (vsi && (vsi->vf == vf));
532}
533
534
535
536
537
538
539
540
541
542static bool ice_vc_isvalid_q_id(struct ice_vf *vf, u16 vsi_id, u8 qid)
543{
544 struct ice_vsi *vsi = ice_find_vsi(vf->pf, vsi_id);
545
546 return (vsi && (qid < vsi->alloc_txq));
547}
548
549
550
551
552
553
554
555
556static bool ice_vc_isvalid_ring_len(u16 ring_len)
557{
558 return ring_len == 0 ||
559 (ring_len >= ICE_MIN_NUM_DESC &&
560 ring_len <= ICE_MAX_NUM_DESC &&
561 !(ring_len % ICE_REQ_DESC_MULTIPLE));
562}
563
564
565
566
567
568
569
570
571
572
573bool
574ice_vc_validate_pattern(struct ice_vf *vf, struct virtchnl_proto_hdrs *proto)
575{
576 bool is_ipv4 = false;
577 bool is_ipv6 = false;
578 bool is_udp = false;
579 u16 ptype = -1;
580 int i = 0;
581
582 while (i < proto->count &&
583 proto->proto_hdr[i].type != VIRTCHNL_PROTO_HDR_NONE) {
584 switch (proto->proto_hdr[i].type) {
585 case VIRTCHNL_PROTO_HDR_ETH:
586 ptype = ICE_PTYPE_MAC_PAY;
587 break;
588 case VIRTCHNL_PROTO_HDR_IPV4:
589 ptype = ICE_PTYPE_IPV4_PAY;
590 is_ipv4 = true;
591 break;
592 case VIRTCHNL_PROTO_HDR_IPV6:
593 ptype = ICE_PTYPE_IPV6_PAY;
594 is_ipv6 = true;
595 break;
596 case VIRTCHNL_PROTO_HDR_UDP:
597 if (is_ipv4)
598 ptype = ICE_PTYPE_IPV4_UDP_PAY;
599 else if (is_ipv6)
600 ptype = ICE_PTYPE_IPV6_UDP_PAY;
601 is_udp = true;
602 break;
603 case VIRTCHNL_PROTO_HDR_TCP:
604 if (is_ipv4)
605 ptype = ICE_PTYPE_IPV4_TCP_PAY;
606 else if (is_ipv6)
607 ptype = ICE_PTYPE_IPV6_TCP_PAY;
608 break;
609 case VIRTCHNL_PROTO_HDR_SCTP:
610 if (is_ipv4)
611 ptype = ICE_PTYPE_IPV4_SCTP_PAY;
612 else if (is_ipv6)
613 ptype = ICE_PTYPE_IPV6_SCTP_PAY;
614 break;
615 case VIRTCHNL_PROTO_HDR_GTPU_IP:
616 case VIRTCHNL_PROTO_HDR_GTPU_EH:
617 if (is_ipv4)
618 ptype = ICE_MAC_IPV4_GTPU;
619 else if (is_ipv6)
620 ptype = ICE_MAC_IPV6_GTPU;
621 goto out;
622 case VIRTCHNL_PROTO_HDR_L2TPV3:
623 if (is_ipv4)
624 ptype = ICE_MAC_IPV4_L2TPV3;
625 else if (is_ipv6)
626 ptype = ICE_MAC_IPV6_L2TPV3;
627 goto out;
628 case VIRTCHNL_PROTO_HDR_ESP:
629 if (is_ipv4)
630 ptype = is_udp ? ICE_MAC_IPV4_NAT_T_ESP :
631 ICE_MAC_IPV4_ESP;
632 else if (is_ipv6)
633 ptype = is_udp ? ICE_MAC_IPV6_NAT_T_ESP :
634 ICE_MAC_IPV6_ESP;
635 goto out;
636 case VIRTCHNL_PROTO_HDR_AH:
637 if (is_ipv4)
638 ptype = ICE_MAC_IPV4_AH;
639 else if (is_ipv6)
640 ptype = ICE_MAC_IPV6_AH;
641 goto out;
642 case VIRTCHNL_PROTO_HDR_PFCP:
643 if (is_ipv4)
644 ptype = ICE_MAC_IPV4_PFCP_SESSION;
645 else if (is_ipv6)
646 ptype = ICE_MAC_IPV6_PFCP_SESSION;
647 goto out;
648 default:
649 break;
650 }
651 i++;
652 }
653
654out:
655 return ice_hw_ptype_ena(&vf->pf->hw, ptype);
656}
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673static bool
674ice_vc_parse_rss_cfg(struct ice_hw *hw, struct virtchnl_rss_cfg *rss_cfg,
675 u32 *addl_hdrs, u64 *hash_flds)
676{
677 const struct ice_vc_hash_field_match_type *hf_list;
678 const struct ice_vc_hdr_match_type *hdr_list;
679 int i, hf_list_len, hdr_list_len;
680
681 hf_list = ice_vc_hash_field_list;
682 hf_list_len = ARRAY_SIZE(ice_vc_hash_field_list);
683 hdr_list = ice_vc_hdr_list;
684 hdr_list_len = ARRAY_SIZE(ice_vc_hdr_list);
685
686 for (i = 0; i < rss_cfg->proto_hdrs.count; i++) {
687 struct virtchnl_proto_hdr *proto_hdr =
688 &rss_cfg->proto_hdrs.proto_hdr[i];
689 bool hdr_found = false;
690 int j;
691
692
693 for (j = 0; j < hdr_list_len; j++) {
694 struct ice_vc_hdr_match_type hdr_map = hdr_list[j];
695
696 if (proto_hdr->type == hdr_map.vc_hdr) {
697 *addl_hdrs |= hdr_map.ice_hdr;
698 hdr_found = true;
699 }
700 }
701
702 if (!hdr_found)
703 return false;
704
705
706
707
708 for (j = 0; j < hf_list_len; j++) {
709 struct ice_vc_hash_field_match_type hf_map = hf_list[j];
710
711 if (proto_hdr->type == hf_map.vc_hdr &&
712 proto_hdr->field_selector == hf_map.vc_hash_field) {
713 *hash_flds |= hf_map.ice_hash_field;
714 break;
715 }
716 }
717 }
718
719 return true;
720}
721
722
723
724
725
726
727
728
729
730static bool ice_vf_adv_rss_offload_ena(u32 caps)
731{
732 return !!(caps & VIRTCHNL_VF_OFFLOAD_ADV_RSS_PF);
733}
734
735
736
737
738
739
740
741
742
743static int ice_vc_handle_rss_cfg(struct ice_vf *vf, u8 *msg, bool add)
744{
745 u32 v_opcode = add ? VIRTCHNL_OP_ADD_RSS_CFG : VIRTCHNL_OP_DEL_RSS_CFG;
746 struct virtchnl_rss_cfg *rss_cfg = (struct virtchnl_rss_cfg *)msg;
747 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
748 struct device *dev = ice_pf_to_dev(vf->pf);
749 struct ice_hw *hw = &vf->pf->hw;
750 struct ice_vsi *vsi;
751
752 if (!test_bit(ICE_FLAG_RSS_ENA, vf->pf->flags)) {
753 dev_dbg(dev, "VF %d attempting to configure RSS, but RSS is not supported by the PF\n",
754 vf->vf_id);
755 v_ret = VIRTCHNL_STATUS_ERR_NOT_SUPPORTED;
756 goto error_param;
757 }
758
759 if (!ice_vf_adv_rss_offload_ena(vf->driver_caps)) {
760 dev_dbg(dev, "VF %d attempting to configure RSS, but Advanced RSS offload is not supported\n",
761 vf->vf_id);
762 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
763 goto error_param;
764 }
765
766 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
767 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
768 goto error_param;
769 }
770
771 if (rss_cfg->proto_hdrs.count > VIRTCHNL_MAX_NUM_PROTO_HDRS ||
772 rss_cfg->rss_algorithm < VIRTCHNL_RSS_ALG_TOEPLITZ_ASYMMETRIC ||
773 rss_cfg->rss_algorithm > VIRTCHNL_RSS_ALG_XOR_SYMMETRIC) {
774 dev_dbg(dev, "VF %d attempting to configure RSS, but RSS configuration is not valid\n",
775 vf->vf_id);
776 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
777 goto error_param;
778 }
779
780 vsi = ice_get_vf_vsi(vf);
781 if (!vsi) {
782 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
783 goto error_param;
784 }
785
786 if (!ice_vc_validate_pattern(vf, &rss_cfg->proto_hdrs)) {
787 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
788 goto error_param;
789 }
790
791 if (rss_cfg->rss_algorithm == VIRTCHNL_RSS_ALG_R_ASYMMETRIC) {
792 struct ice_vsi_ctx *ctx;
793 u8 lut_type, hash_type;
794 int status;
795
796 lut_type = ICE_AQ_VSI_Q_OPT_RSS_LUT_VSI;
797 hash_type = add ? ICE_AQ_VSI_Q_OPT_RSS_XOR :
798 ICE_AQ_VSI_Q_OPT_RSS_TPLZ;
799
800 ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
801 if (!ctx) {
802 v_ret = VIRTCHNL_STATUS_ERR_NO_MEMORY;
803 goto error_param;
804 }
805
806 ctx->info.q_opt_rss = ((lut_type <<
807 ICE_AQ_VSI_Q_OPT_RSS_LUT_S) &
808 ICE_AQ_VSI_Q_OPT_RSS_LUT_M) |
809 (hash_type &
810 ICE_AQ_VSI_Q_OPT_RSS_HASH_M);
811
812
813 ctx->info.q_opt_rss |= (vsi->info.q_opt_rss &
814 ICE_AQ_VSI_Q_OPT_RSS_GBL_LUT_M);
815 ctx->info.q_opt_tc = vsi->info.q_opt_tc;
816 ctx->info.q_opt_flags = vsi->info.q_opt_rss;
817
818 ctx->info.valid_sections =
819 cpu_to_le16(ICE_AQ_VSI_PROP_Q_OPT_VALID);
820
821 status = ice_update_vsi(hw, vsi->idx, ctx, NULL);
822 if (status) {
823 dev_err(dev, "update VSI for RSS failed, err %d aq_err %s\n",
824 status, ice_aq_str(hw->adminq.sq_last_status));
825 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
826 } else {
827 vsi->info.q_opt_rss = ctx->info.q_opt_rss;
828 }
829
830 kfree(ctx);
831 } else {
832 u32 addl_hdrs = ICE_FLOW_SEG_HDR_NONE;
833 u64 hash_flds = ICE_HASH_INVALID;
834
835 if (!ice_vc_parse_rss_cfg(hw, rss_cfg, &addl_hdrs,
836 &hash_flds)) {
837 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
838 goto error_param;
839 }
840
841 if (add) {
842 if (ice_add_rss_cfg(hw, vsi->idx, hash_flds,
843 addl_hdrs)) {
844 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
845 dev_err(dev, "ice_add_rss_cfg failed for vsi = %d, v_ret = %d\n",
846 vsi->vsi_num, v_ret);
847 }
848 } else {
849 int status;
850
851 status = ice_rem_rss_cfg(hw, vsi->idx, hash_flds,
852 addl_hdrs);
853
854
855
856
857 if (status && status != -ENOENT) {
858 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
859 dev_err(dev, "ice_rem_rss_cfg failed for VF ID:%d, error:%d\n",
860 vf->vf_id, status);
861 }
862 }
863 }
864
865error_param:
866 return ice_vc_send_msg_to_vf(vf, v_opcode, v_ret, NULL, 0);
867}
868
869
870
871
872
873
874
875
876static int ice_vc_config_rss_key(struct ice_vf *vf, u8 *msg)
877{
878 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
879 struct virtchnl_rss_key *vrk =
880 (struct virtchnl_rss_key *)msg;
881 struct ice_vsi *vsi;
882
883 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
884 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
885 goto error_param;
886 }
887
888 if (!ice_vc_isvalid_vsi_id(vf, vrk->vsi_id)) {
889 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
890 goto error_param;
891 }
892
893 if (vrk->key_len != ICE_VSIQF_HKEY_ARRAY_SIZE) {
894 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
895 goto error_param;
896 }
897
898 if (!test_bit(ICE_FLAG_RSS_ENA, vf->pf->flags)) {
899 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
900 goto error_param;
901 }
902
903 vsi = ice_get_vf_vsi(vf);
904 if (!vsi) {
905 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
906 goto error_param;
907 }
908
909 if (ice_set_rss_key(vsi, vrk->key))
910 v_ret = VIRTCHNL_STATUS_ERR_ADMIN_QUEUE_ERROR;
911error_param:
912 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_CONFIG_RSS_KEY, v_ret,
913 NULL, 0);
914}
915
916
917
918
919
920
921
922
923static int ice_vc_config_rss_lut(struct ice_vf *vf, u8 *msg)
924{
925 struct virtchnl_rss_lut *vrl = (struct virtchnl_rss_lut *)msg;
926 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
927 struct ice_vsi *vsi;
928
929 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
930 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
931 goto error_param;
932 }
933
934 if (!ice_vc_isvalid_vsi_id(vf, vrl->vsi_id)) {
935 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
936 goto error_param;
937 }
938
939 if (vrl->lut_entries != ICE_VSIQF_HLUT_ARRAY_SIZE) {
940 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
941 goto error_param;
942 }
943
944 if (!test_bit(ICE_FLAG_RSS_ENA, vf->pf->flags)) {
945 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
946 goto error_param;
947 }
948
949 vsi = ice_get_vf_vsi(vf);
950 if (!vsi) {
951 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
952 goto error_param;
953 }
954
955 if (ice_set_rss_lut(vsi, vrl->lut, ICE_VSIQF_HLUT_ARRAY_SIZE))
956 v_ret = VIRTCHNL_STATUS_ERR_ADMIN_QUEUE_ERROR;
957error_param:
958 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_CONFIG_RSS_LUT, v_ret,
959 NULL, 0);
960}
961
962
963
964
965
966
967
968
969static int ice_vc_cfg_promiscuous_mode_msg(struct ice_vf *vf, u8 *msg)
970{
971 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
972 bool rm_promisc, alluni = false, allmulti = false;
973 struct virtchnl_promisc_info *info =
974 (struct virtchnl_promisc_info *)msg;
975 struct ice_vsi_vlan_ops *vlan_ops;
976 int mcast_err = 0, ucast_err = 0;
977 struct ice_pf *pf = vf->pf;
978 struct ice_vsi *vsi;
979 struct device *dev;
980 int ret = 0;
981
982 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
983 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
984 goto error_param;
985 }
986
987 if (!ice_vc_isvalid_vsi_id(vf, info->vsi_id)) {
988 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
989 goto error_param;
990 }
991
992 vsi = ice_get_vf_vsi(vf);
993 if (!vsi) {
994 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
995 goto error_param;
996 }
997
998 dev = ice_pf_to_dev(pf);
999 if (!ice_is_vf_trusted(vf)) {
1000 dev_err(dev, "Unprivileged VF %d is attempting to configure promiscuous mode\n",
1001 vf->vf_id);
1002
1003 goto error_param;
1004 }
1005
1006 if (info->flags & FLAG_VF_UNICAST_PROMISC)
1007 alluni = true;
1008
1009 if (info->flags & FLAG_VF_MULTICAST_PROMISC)
1010 allmulti = true;
1011
1012 rm_promisc = !allmulti && !alluni;
1013
1014 vlan_ops = ice_get_compat_vsi_vlan_ops(vsi);
1015 if (rm_promisc)
1016 ret = vlan_ops->ena_rx_filtering(vsi);
1017 else
1018 ret = vlan_ops->dis_rx_filtering(vsi);
1019 if (ret) {
1020 dev_err(dev, "Failed to configure VLAN pruning in promiscuous mode\n");
1021 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1022 goto error_param;
1023 }
1024
1025 if (!test_bit(ICE_FLAG_VF_TRUE_PROMISC_ENA, pf->flags)) {
1026 bool set_dflt_vsi = alluni || allmulti;
1027
1028 if (set_dflt_vsi && !ice_is_dflt_vsi_in_use(pf->first_sw))
1029
1030
1031
1032 ret = ice_set_dflt_vsi(pf->first_sw, vsi);
1033 else if (!set_dflt_vsi &&
1034 ice_is_vsi_dflt_vsi(pf->first_sw, vsi))
1035
1036
1037
1038 ret = ice_clear_dflt_vsi(pf->first_sw);
1039
1040 if (ret) {
1041 dev_err(dev, "%sable VF %d as the default VSI failed, error %d\n",
1042 set_dflt_vsi ? "en" : "dis", vf->vf_id, ret);
1043 v_ret = VIRTCHNL_STATUS_ERR_ADMIN_QUEUE_ERROR;
1044 goto error_param;
1045 }
1046 } else {
1047 u8 mcast_m, ucast_m;
1048
1049 if (ice_vf_is_port_vlan_ena(vf) ||
1050 ice_vsi_has_non_zero_vlans(vsi)) {
1051 mcast_m = ICE_MCAST_VLAN_PROMISC_BITS;
1052 ucast_m = ICE_UCAST_VLAN_PROMISC_BITS;
1053 } else {
1054 mcast_m = ICE_MCAST_PROMISC_BITS;
1055 ucast_m = ICE_UCAST_PROMISC_BITS;
1056 }
1057
1058 if (alluni)
1059 ucast_err = ice_vf_set_vsi_promisc(vf, vsi, ucast_m);
1060 else
1061 ucast_err = ice_vf_clear_vsi_promisc(vf, vsi, ucast_m);
1062
1063 if (allmulti)
1064 mcast_err = ice_vf_set_vsi_promisc(vf, vsi, mcast_m);
1065 else
1066 mcast_err = ice_vf_clear_vsi_promisc(vf, vsi, mcast_m);
1067
1068 if (ucast_err || mcast_err)
1069 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1070 }
1071
1072 if (!mcast_err) {
1073 if (allmulti &&
1074 !test_and_set_bit(ICE_VF_STATE_MC_PROMISC, vf->vf_states))
1075 dev_info(dev, "VF %u successfully set multicast promiscuous mode\n",
1076 vf->vf_id);
1077 else if (!allmulti &&
1078 test_and_clear_bit(ICE_VF_STATE_MC_PROMISC,
1079 vf->vf_states))
1080 dev_info(dev, "VF %u successfully unset multicast promiscuous mode\n",
1081 vf->vf_id);
1082 }
1083
1084 if (!ucast_err) {
1085 if (alluni &&
1086 !test_and_set_bit(ICE_VF_STATE_UC_PROMISC, vf->vf_states))
1087 dev_info(dev, "VF %u successfully set unicast promiscuous mode\n",
1088 vf->vf_id);
1089 else if (!alluni &&
1090 test_and_clear_bit(ICE_VF_STATE_UC_PROMISC,
1091 vf->vf_states))
1092 dev_info(dev, "VF %u successfully unset unicast promiscuous mode\n",
1093 vf->vf_id);
1094 }
1095
1096error_param:
1097 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE,
1098 v_ret, NULL, 0);
1099}
1100
1101
1102
1103
1104
1105
1106
1107
1108static int ice_vc_get_stats_msg(struct ice_vf *vf, u8 *msg)
1109{
1110 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
1111 struct virtchnl_queue_select *vqs =
1112 (struct virtchnl_queue_select *)msg;
1113 struct ice_eth_stats stats = { 0 };
1114 struct ice_vsi *vsi;
1115
1116 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
1117 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1118 goto error_param;
1119 }
1120
1121 if (!ice_vc_isvalid_vsi_id(vf, vqs->vsi_id)) {
1122 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1123 goto error_param;
1124 }
1125
1126 vsi = ice_get_vf_vsi(vf);
1127 if (!vsi) {
1128 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1129 goto error_param;
1130 }
1131
1132 ice_update_eth_stats(vsi);
1133
1134 stats = vsi->eth_stats;
1135
1136error_param:
1137
1138 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_GET_STATS, v_ret,
1139 (u8 *)&stats, sizeof(stats));
1140}
1141
1142
1143
1144
1145
1146
1147
1148static bool ice_vc_validate_vqs_bitmaps(struct virtchnl_queue_select *vqs)
1149{
1150 if ((!vqs->rx_queues && !vqs->tx_queues) ||
1151 vqs->rx_queues >= BIT(ICE_MAX_RSS_QS_PER_VF) ||
1152 vqs->tx_queues >= BIT(ICE_MAX_RSS_QS_PER_VF))
1153 return false;
1154
1155 return true;
1156}
1157
1158
1159
1160
1161
1162
1163static void ice_vf_ena_txq_interrupt(struct ice_vsi *vsi, u32 q_idx)
1164{
1165 struct ice_hw *hw = &vsi->back->hw;
1166 u32 pfq = vsi->txq_map[q_idx];
1167 u32 reg;
1168
1169 reg = rd32(hw, QINT_TQCTL(pfq));
1170
1171
1172
1173
1174
1175 if (!(reg & QINT_TQCTL_MSIX_INDX_M))
1176 return;
1177
1178 wr32(hw, QINT_TQCTL(pfq), reg | QINT_TQCTL_CAUSE_ENA_M);
1179}
1180
1181
1182
1183
1184
1185
1186static void ice_vf_ena_rxq_interrupt(struct ice_vsi *vsi, u32 q_idx)
1187{
1188 struct ice_hw *hw = &vsi->back->hw;
1189 u32 pfq = vsi->rxq_map[q_idx];
1190 u32 reg;
1191
1192 reg = rd32(hw, QINT_RQCTL(pfq));
1193
1194
1195
1196
1197
1198 if (!(reg & QINT_RQCTL_MSIX_INDX_M))
1199 return;
1200
1201 wr32(hw, QINT_RQCTL(pfq), reg | QINT_RQCTL_CAUSE_ENA_M);
1202}
1203
1204
1205
1206
1207
1208
1209
1210
1211static int ice_vc_ena_qs_msg(struct ice_vf *vf, u8 *msg)
1212{
1213 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
1214 struct virtchnl_queue_select *vqs =
1215 (struct virtchnl_queue_select *)msg;
1216 struct ice_vsi *vsi;
1217 unsigned long q_map;
1218 u16 vf_q_id;
1219
1220 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
1221 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1222 goto error_param;
1223 }
1224
1225 if (!ice_vc_isvalid_vsi_id(vf, vqs->vsi_id)) {
1226 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1227 goto error_param;
1228 }
1229
1230 if (!ice_vc_validate_vqs_bitmaps(vqs)) {
1231 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1232 goto error_param;
1233 }
1234
1235 vsi = ice_get_vf_vsi(vf);
1236 if (!vsi) {
1237 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1238 goto error_param;
1239 }
1240
1241
1242
1243
1244
1245 q_map = vqs->rx_queues;
1246 for_each_set_bit(vf_q_id, &q_map, ICE_MAX_RSS_QS_PER_VF) {
1247 if (!ice_vc_isvalid_q_id(vf, vqs->vsi_id, vf_q_id)) {
1248 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1249 goto error_param;
1250 }
1251
1252
1253 if (test_bit(vf_q_id, vf->rxq_ena))
1254 continue;
1255
1256 if (ice_vsi_ctrl_one_rx_ring(vsi, true, vf_q_id, true)) {
1257 dev_err(ice_pf_to_dev(vsi->back), "Failed to enable Rx ring %d on VSI %d\n",
1258 vf_q_id, vsi->vsi_num);
1259 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1260 goto error_param;
1261 }
1262
1263 ice_vf_ena_rxq_interrupt(vsi, vf_q_id);
1264 set_bit(vf_q_id, vf->rxq_ena);
1265 }
1266
1267 q_map = vqs->tx_queues;
1268 for_each_set_bit(vf_q_id, &q_map, ICE_MAX_RSS_QS_PER_VF) {
1269 if (!ice_vc_isvalid_q_id(vf, vqs->vsi_id, vf_q_id)) {
1270 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1271 goto error_param;
1272 }
1273
1274
1275 if (test_bit(vf_q_id, vf->txq_ena))
1276 continue;
1277
1278 ice_vf_ena_txq_interrupt(vsi, vf_q_id);
1279 set_bit(vf_q_id, vf->txq_ena);
1280 }
1281
1282
1283 if (v_ret == VIRTCHNL_STATUS_SUCCESS)
1284 set_bit(ICE_VF_STATE_QS_ENA, vf->vf_states);
1285
1286error_param:
1287
1288 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_ENABLE_QUEUES, v_ret,
1289 NULL, 0);
1290}
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302static int
1303ice_vf_vsi_dis_single_txq(struct ice_vf *vf, struct ice_vsi *vsi, u16 q_id)
1304{
1305 struct ice_txq_meta txq_meta = { 0 };
1306 struct ice_tx_ring *ring;
1307 int err;
1308
1309 if (!test_bit(q_id, vf->txq_ena))
1310 dev_dbg(ice_pf_to_dev(vsi->back), "Queue %u on VSI %u is not enabled, but stopping it anyway\n",
1311 q_id, vsi->vsi_num);
1312
1313 ring = vsi->tx_rings[q_id];
1314 if (!ring)
1315 return -EINVAL;
1316
1317 ice_fill_txq_meta(vsi, ring, &txq_meta);
1318
1319 err = ice_vsi_stop_tx_ring(vsi, ICE_NO_RESET, vf->vf_id, ring, &txq_meta);
1320 if (err) {
1321 dev_err(ice_pf_to_dev(vsi->back), "Failed to stop Tx ring %d on VSI %d\n",
1322 q_id, vsi->vsi_num);
1323 return err;
1324 }
1325
1326
1327 clear_bit(q_id, vf->txq_ena);
1328
1329 return 0;
1330}
1331
1332
1333
1334
1335
1336
1337
1338
1339static int ice_vc_dis_qs_msg(struct ice_vf *vf, u8 *msg)
1340{
1341 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
1342 struct virtchnl_queue_select *vqs =
1343 (struct virtchnl_queue_select *)msg;
1344 struct ice_vsi *vsi;
1345 unsigned long q_map;
1346 u16 vf_q_id;
1347
1348 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states) &&
1349 !test_bit(ICE_VF_STATE_QS_ENA, vf->vf_states)) {
1350 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1351 goto error_param;
1352 }
1353
1354 if (!ice_vc_isvalid_vsi_id(vf, vqs->vsi_id)) {
1355 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1356 goto error_param;
1357 }
1358
1359 if (!ice_vc_validate_vqs_bitmaps(vqs)) {
1360 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1361 goto error_param;
1362 }
1363
1364 vsi = ice_get_vf_vsi(vf);
1365 if (!vsi) {
1366 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1367 goto error_param;
1368 }
1369
1370 if (vqs->tx_queues) {
1371 q_map = vqs->tx_queues;
1372
1373 for_each_set_bit(vf_q_id, &q_map, ICE_MAX_RSS_QS_PER_VF) {
1374 if (!ice_vc_isvalid_q_id(vf, vqs->vsi_id, vf_q_id)) {
1375 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1376 goto error_param;
1377 }
1378
1379 if (ice_vf_vsi_dis_single_txq(vf, vsi, vf_q_id)) {
1380 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1381 goto error_param;
1382 }
1383 }
1384 }
1385
1386 q_map = vqs->rx_queues;
1387
1388 if (q_map &&
1389 bitmap_equal(&q_map, vf->rxq_ena, ICE_MAX_RSS_QS_PER_VF)) {
1390 if (ice_vsi_stop_all_rx_rings(vsi)) {
1391 dev_err(ice_pf_to_dev(vsi->back), "Failed to stop all Rx rings on VSI %d\n",
1392 vsi->vsi_num);
1393 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1394 goto error_param;
1395 }
1396
1397 bitmap_zero(vf->rxq_ena, ICE_MAX_RSS_QS_PER_VF);
1398 } else if (q_map) {
1399 for_each_set_bit(vf_q_id, &q_map, ICE_MAX_RSS_QS_PER_VF) {
1400 if (!ice_vc_isvalid_q_id(vf, vqs->vsi_id, vf_q_id)) {
1401 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1402 goto error_param;
1403 }
1404
1405
1406 if (!test_bit(vf_q_id, vf->rxq_ena))
1407 continue;
1408
1409 if (ice_vsi_ctrl_one_rx_ring(vsi, false, vf_q_id,
1410 true)) {
1411 dev_err(ice_pf_to_dev(vsi->back), "Failed to stop Rx ring %d on VSI %d\n",
1412 vf_q_id, vsi->vsi_num);
1413 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1414 goto error_param;
1415 }
1416
1417
1418 clear_bit(vf_q_id, vf->rxq_ena);
1419 }
1420 }
1421
1422
1423 if (v_ret == VIRTCHNL_STATUS_SUCCESS && ice_vf_has_no_qs_ena(vf))
1424 clear_bit(ICE_VF_STATE_QS_ENA, vf->vf_states);
1425
1426error_param:
1427
1428 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_DISABLE_QUEUES, v_ret,
1429 NULL, 0);
1430}
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441static int
1442ice_cfg_interrupt(struct ice_vf *vf, struct ice_vsi *vsi, u16 vector_id,
1443 struct virtchnl_vector_map *map,
1444 struct ice_q_vector *q_vector)
1445{
1446 u16 vsi_q_id, vsi_q_id_idx;
1447 unsigned long qmap;
1448
1449 q_vector->num_ring_rx = 0;
1450 q_vector->num_ring_tx = 0;
1451
1452 qmap = map->rxq_map;
1453 for_each_set_bit(vsi_q_id_idx, &qmap, ICE_MAX_RSS_QS_PER_VF) {
1454 vsi_q_id = vsi_q_id_idx;
1455
1456 if (!ice_vc_isvalid_q_id(vf, vsi->vsi_num, vsi_q_id))
1457 return VIRTCHNL_STATUS_ERR_PARAM;
1458
1459 q_vector->num_ring_rx++;
1460 q_vector->rx.itr_idx = map->rxitr_idx;
1461 vsi->rx_rings[vsi_q_id]->q_vector = q_vector;
1462 ice_cfg_rxq_interrupt(vsi, vsi_q_id, vector_id,
1463 q_vector->rx.itr_idx);
1464 }
1465
1466 qmap = map->txq_map;
1467 for_each_set_bit(vsi_q_id_idx, &qmap, ICE_MAX_RSS_QS_PER_VF) {
1468 vsi_q_id = vsi_q_id_idx;
1469
1470 if (!ice_vc_isvalid_q_id(vf, vsi->vsi_num, vsi_q_id))
1471 return VIRTCHNL_STATUS_ERR_PARAM;
1472
1473 q_vector->num_ring_tx++;
1474 q_vector->tx.itr_idx = map->txitr_idx;
1475 vsi->tx_rings[vsi_q_id]->q_vector = q_vector;
1476 ice_cfg_txq_interrupt(vsi, vsi_q_id, vector_id,
1477 q_vector->tx.itr_idx);
1478 }
1479
1480 return VIRTCHNL_STATUS_SUCCESS;
1481}
1482
1483
1484
1485
1486
1487
1488
1489
1490static int ice_vc_cfg_irq_map_msg(struct ice_vf *vf, u8 *msg)
1491{
1492 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
1493 u16 num_q_vectors_mapped, vsi_id, vector_id;
1494 struct virtchnl_irq_map_info *irqmap_info;
1495 struct virtchnl_vector_map *map;
1496 struct ice_pf *pf = vf->pf;
1497 struct ice_vsi *vsi;
1498 int i;
1499
1500 irqmap_info = (struct virtchnl_irq_map_info *)msg;
1501 num_q_vectors_mapped = irqmap_info->num_vectors;
1502
1503
1504
1505
1506
1507 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states) ||
1508 pf->vfs.num_msix_per < num_q_vectors_mapped ||
1509 !num_q_vectors_mapped) {
1510 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1511 goto error_param;
1512 }
1513
1514 vsi = ice_get_vf_vsi(vf);
1515 if (!vsi) {
1516 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1517 goto error_param;
1518 }
1519
1520 for (i = 0; i < num_q_vectors_mapped; i++) {
1521 struct ice_q_vector *q_vector;
1522
1523 map = &irqmap_info->vecmap[i];
1524
1525 vector_id = map->vector_id;
1526 vsi_id = map->vsi_id;
1527
1528
1529
1530 if (!(vector_id < pf->vfs.num_msix_per) ||
1531 !ice_vc_isvalid_vsi_id(vf, vsi_id) ||
1532 (!vector_id && (map->rxq_map || map->txq_map))) {
1533 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1534 goto error_param;
1535 }
1536
1537
1538 if (!vector_id)
1539 continue;
1540
1541
1542
1543
1544 q_vector = vsi->q_vectors[vector_id - ICE_NONQ_VECS_VF];
1545 if (!q_vector) {
1546 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1547 goto error_param;
1548 }
1549
1550
1551 v_ret = (enum virtchnl_status_code)
1552 ice_cfg_interrupt(vf, vsi, vector_id, map, q_vector);
1553 if (v_ret)
1554 goto error_param;
1555 }
1556
1557error_param:
1558
1559 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_CONFIG_IRQ_MAP, v_ret,
1560 NULL, 0);
1561}
1562
1563
1564
1565
1566
1567
1568
1569
1570static int ice_vc_cfg_qs_msg(struct ice_vf *vf, u8 *msg)
1571{
1572 struct virtchnl_vsi_queue_config_info *qci =
1573 (struct virtchnl_vsi_queue_config_info *)msg;
1574 struct virtchnl_queue_pair_info *qpi;
1575 struct ice_pf *pf = vf->pf;
1576 struct ice_vsi *vsi;
1577 int i = -1, q_idx;
1578
1579 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states))
1580 goto error_param;
1581
1582 if (!ice_vc_isvalid_vsi_id(vf, qci->vsi_id))
1583 goto error_param;
1584
1585 vsi = ice_get_vf_vsi(vf);
1586 if (!vsi)
1587 goto error_param;
1588
1589 if (qci->num_queue_pairs > ICE_MAX_RSS_QS_PER_VF ||
1590 qci->num_queue_pairs > min_t(u16, vsi->alloc_txq, vsi->alloc_rxq)) {
1591 dev_err(ice_pf_to_dev(pf), "VF-%d requesting more than supported number of queues: %d\n",
1592 vf->vf_id, min_t(u16, vsi->alloc_txq, vsi->alloc_rxq));
1593 goto error_param;
1594 }
1595
1596 for (i = 0; i < qci->num_queue_pairs; i++) {
1597 qpi = &qci->qpair[i];
1598 if (qpi->txq.vsi_id != qci->vsi_id ||
1599 qpi->rxq.vsi_id != qci->vsi_id ||
1600 qpi->rxq.queue_id != qpi->txq.queue_id ||
1601 qpi->txq.headwb_enabled ||
1602 !ice_vc_isvalid_ring_len(qpi->txq.ring_len) ||
1603 !ice_vc_isvalid_ring_len(qpi->rxq.ring_len) ||
1604 !ice_vc_isvalid_q_id(vf, qci->vsi_id, qpi->txq.queue_id)) {
1605 goto error_param;
1606 }
1607
1608 q_idx = qpi->rxq.queue_id;
1609
1610
1611
1612
1613 if (q_idx >= vsi->alloc_txq || q_idx >= vsi->alloc_rxq) {
1614 goto error_param;
1615 }
1616
1617
1618 if (qpi->txq.ring_len > 0) {
1619 vsi->tx_rings[i]->dma = qpi->txq.dma_ring_addr;
1620 vsi->tx_rings[i]->count = qpi->txq.ring_len;
1621
1622
1623 if (ice_vf_vsi_dis_single_txq(vf, vsi, q_idx))
1624 goto error_param;
1625
1626
1627 if (ice_vsi_cfg_single_txq(vsi, vsi->tx_rings, q_idx)) {
1628 dev_warn(ice_pf_to_dev(pf), "VF-%d failed to configure TX queue %d\n",
1629 vf->vf_id, i);
1630 goto error_param;
1631 }
1632 }
1633
1634
1635 if (qpi->rxq.ring_len > 0) {
1636 u16 max_frame_size = ice_vc_get_max_frame_size(vf);
1637
1638 vsi->rx_rings[i]->dma = qpi->rxq.dma_ring_addr;
1639 vsi->rx_rings[i]->count = qpi->rxq.ring_len;
1640
1641 if (qpi->rxq.databuffer_size != 0 &&
1642 (qpi->rxq.databuffer_size > ((16 * 1024) - 128) ||
1643 qpi->rxq.databuffer_size < 1024))
1644 goto error_param;
1645 vsi->rx_buf_len = qpi->rxq.databuffer_size;
1646 vsi->rx_rings[i]->rx_buf_len = vsi->rx_buf_len;
1647 if (qpi->rxq.max_pkt_size > max_frame_size ||
1648 qpi->rxq.max_pkt_size < 64)
1649 goto error_param;
1650
1651 vsi->max_frame = qpi->rxq.max_pkt_size;
1652
1653
1654
1655
1656 if (ice_vf_is_port_vlan_ena(vf))
1657 vsi->max_frame += VLAN_HLEN;
1658
1659 if (ice_vsi_cfg_single_rxq(vsi, q_idx)) {
1660 dev_warn(ice_pf_to_dev(pf), "VF-%d failed to configure RX queue %d\n",
1661 vf->vf_id, i);
1662 goto error_param;
1663 }
1664 }
1665 }
1666
1667
1668 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_CONFIG_VSI_QUEUES,
1669 VIRTCHNL_STATUS_SUCCESS, NULL, 0);
1670error_param:
1671
1672 for (; i >= 0; i--) {
1673 if (ice_vsi_ctrl_one_rx_ring(vsi, false, i, true))
1674 dev_err(ice_pf_to_dev(pf), "VF-%d could not disable RX queue %d\n",
1675 vf->vf_id, i);
1676 if (ice_vf_vsi_dis_single_txq(vf, vsi, i))
1677 dev_err(ice_pf_to_dev(pf), "VF-%d could not disable TX queue %d\n",
1678 vf->vf_id, i);
1679 }
1680
1681
1682 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_CONFIG_VSI_QUEUES,
1683 VIRTCHNL_STATUS_ERR_PARAM, NULL, 0);
1684}
1685
1686
1687
1688
1689
1690
1691
1692static bool ice_can_vf_change_mac(struct ice_vf *vf)
1693{
1694
1695
1696
1697
1698 if (vf->pf_set_mac && !ice_is_vf_trusted(vf))
1699 return false;
1700
1701 return true;
1702}
1703
1704
1705
1706
1707
1708static u8
1709ice_vc_ether_addr_type(struct virtchnl_ether_addr *vc_ether_addr)
1710{
1711 return (vc_ether_addr->type & VIRTCHNL_ETHER_ADDR_TYPE_MASK);
1712}
1713
1714
1715
1716
1717
1718static bool
1719ice_is_vc_addr_legacy(struct virtchnl_ether_addr *vc_ether_addr)
1720{
1721 u8 type = ice_vc_ether_addr_type(vc_ether_addr);
1722
1723 return (type == VIRTCHNL_ETHER_ADDR_LEGACY);
1724}
1725
1726
1727
1728
1729
1730
1731
1732
1733static bool
1734ice_is_vc_addr_primary(struct virtchnl_ether_addr __maybe_unused *vc_ether_addr)
1735{
1736 u8 type = ice_vc_ether_addr_type(vc_ether_addr);
1737
1738 return (type == VIRTCHNL_ETHER_ADDR_PRIMARY);
1739}
1740
1741
1742
1743
1744
1745
1746static void
1747ice_vfhw_mac_add(struct ice_vf *vf, struct virtchnl_ether_addr *vc_ether_addr)
1748{
1749 u8 *mac_addr = vc_ether_addr->addr;
1750
1751 if (!is_valid_ether_addr(mac_addr))
1752 return;
1753
1754
1755
1756
1757
1758 if ((ice_is_vc_addr_legacy(vc_ether_addr) &&
1759 is_zero_ether_addr(vf->hw_lan_addr.addr)) ||
1760 ice_is_vc_addr_primary(vc_ether_addr)) {
1761 ether_addr_copy(vf->dev_lan_addr.addr, mac_addr);
1762 ether_addr_copy(vf->hw_lan_addr.addr, mac_addr);
1763 }
1764
1765
1766
1767
1768
1769
1770
1771 if (ice_is_vc_addr_legacy(vc_ether_addr)) {
1772 ether_addr_copy(vf->legacy_last_added_umac.addr,
1773 mac_addr);
1774 vf->legacy_last_added_umac.time_modified = jiffies;
1775 }
1776}
1777
1778
1779
1780
1781
1782
1783
1784static int
1785ice_vc_add_mac_addr(struct ice_vf *vf, struct ice_vsi *vsi,
1786 struct virtchnl_ether_addr *vc_ether_addr)
1787{
1788 struct device *dev = ice_pf_to_dev(vf->pf);
1789 u8 *mac_addr = vc_ether_addr->addr;
1790 int ret;
1791
1792
1793 if (ether_addr_equal(mac_addr, vf->dev_lan_addr.addr))
1794 return 0;
1795
1796 if (is_unicast_ether_addr(mac_addr) && !ice_can_vf_change_mac(vf)) {
1797 dev_err(dev, "VF attempting to override administratively set MAC address, bring down and up the VF interface to resume normal operation\n");
1798 return -EPERM;
1799 }
1800
1801 ret = ice_fltr_add_mac(vsi, mac_addr, ICE_FWD_TO_VSI);
1802 if (ret == -EEXIST) {
1803 dev_dbg(dev, "MAC %pM already exists for VF %d\n", mac_addr,
1804 vf->vf_id);
1805
1806
1807
1808 } else if (ret) {
1809 dev_err(dev, "Failed to add MAC %pM for VF %d\n, error %d\n",
1810 mac_addr, vf->vf_id, ret);
1811 return ret;
1812 } else {
1813 vf->num_mac++;
1814 }
1815
1816 ice_vfhw_mac_add(vf, vc_ether_addr);
1817
1818 return ret;
1819}
1820
1821
1822
1823
1824
1825static bool ice_is_legacy_umac_expired(struct ice_time_mac *last_added_umac)
1826{
1827#define ICE_LEGACY_VF_MAC_CHANGE_EXPIRE_TIME msecs_to_jiffies(3000)
1828 return time_is_before_jiffies(last_added_umac->time_modified +
1829 ICE_LEGACY_VF_MAC_CHANGE_EXPIRE_TIME);
1830}
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840static void
1841ice_update_legacy_cached_mac(struct ice_vf *vf,
1842 struct virtchnl_ether_addr *vc_ether_addr)
1843{
1844 if (!ice_is_vc_addr_legacy(vc_ether_addr) ||
1845 ice_is_legacy_umac_expired(&vf->legacy_last_added_umac))
1846 return;
1847
1848 ether_addr_copy(vf->dev_lan_addr.addr, vf->legacy_last_added_umac.addr);
1849 ether_addr_copy(vf->hw_lan_addr.addr, vf->legacy_last_added_umac.addr);
1850}
1851
1852
1853
1854
1855
1856
1857static void
1858ice_vfhw_mac_del(struct ice_vf *vf, struct virtchnl_ether_addr *vc_ether_addr)
1859{
1860 u8 *mac_addr = vc_ether_addr->addr;
1861
1862 if (!is_valid_ether_addr(mac_addr) ||
1863 !ether_addr_equal(vf->dev_lan_addr.addr, mac_addr))
1864 return;
1865
1866
1867
1868
1869
1870
1871 eth_zero_addr(vf->dev_lan_addr.addr);
1872
1873 ice_update_legacy_cached_mac(vf, vc_ether_addr);
1874}
1875
1876
1877
1878
1879
1880
1881
1882static int
1883ice_vc_del_mac_addr(struct ice_vf *vf, struct ice_vsi *vsi,
1884 struct virtchnl_ether_addr *vc_ether_addr)
1885{
1886 struct device *dev = ice_pf_to_dev(vf->pf);
1887 u8 *mac_addr = vc_ether_addr->addr;
1888 int status;
1889
1890 if (!ice_can_vf_change_mac(vf) &&
1891 ether_addr_equal(vf->dev_lan_addr.addr, mac_addr))
1892 return 0;
1893
1894 status = ice_fltr_remove_mac(vsi, mac_addr, ICE_FWD_TO_VSI);
1895 if (status == -ENOENT) {
1896 dev_err(dev, "MAC %pM does not exist for VF %d\n", mac_addr,
1897 vf->vf_id);
1898 return -ENOENT;
1899 } else if (status) {
1900 dev_err(dev, "Failed to delete MAC %pM for VF %d, error %d\n",
1901 mac_addr, vf->vf_id, status);
1902 return -EIO;
1903 }
1904
1905 ice_vfhw_mac_del(vf, vc_ether_addr);
1906
1907 vf->num_mac--;
1908
1909 return 0;
1910}
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920static int
1921ice_vc_handle_mac_addr_msg(struct ice_vf *vf, u8 *msg, bool set)
1922{
1923 int (*ice_vc_cfg_mac)
1924 (struct ice_vf *vf, struct ice_vsi *vsi,
1925 struct virtchnl_ether_addr *virtchnl_ether_addr);
1926 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
1927 struct virtchnl_ether_addr_list *al =
1928 (struct virtchnl_ether_addr_list *)msg;
1929 struct ice_pf *pf = vf->pf;
1930 enum virtchnl_ops vc_op;
1931 struct ice_vsi *vsi;
1932 int i;
1933
1934 if (set) {
1935 vc_op = VIRTCHNL_OP_ADD_ETH_ADDR;
1936 ice_vc_cfg_mac = ice_vc_add_mac_addr;
1937 } else {
1938 vc_op = VIRTCHNL_OP_DEL_ETH_ADDR;
1939 ice_vc_cfg_mac = ice_vc_del_mac_addr;
1940 }
1941
1942 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states) ||
1943 !ice_vc_isvalid_vsi_id(vf, al->vsi_id)) {
1944 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1945 goto handle_mac_exit;
1946 }
1947
1948
1949
1950
1951
1952 if (set && !ice_is_vf_trusted(vf) &&
1953 (vf->num_mac + al->num_elements) > ICE_MAX_MACADDR_PER_VF) {
1954 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",
1955 vf->vf_id);
1956 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1957 goto handle_mac_exit;
1958 }
1959
1960 vsi = ice_get_vf_vsi(vf);
1961 if (!vsi) {
1962 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
1963 goto handle_mac_exit;
1964 }
1965
1966 for (i = 0; i < al->num_elements; i++) {
1967 u8 *mac_addr = al->list[i].addr;
1968 int result;
1969
1970 if (is_broadcast_ether_addr(mac_addr) ||
1971 is_zero_ether_addr(mac_addr))
1972 continue;
1973
1974 result = ice_vc_cfg_mac(vf, vsi, &al->list[i]);
1975 if (result == -EEXIST || result == -ENOENT) {
1976 continue;
1977 } else if (result) {
1978 v_ret = VIRTCHNL_STATUS_ERR_ADMIN_QUEUE_ERROR;
1979 goto handle_mac_exit;
1980 }
1981 }
1982
1983handle_mac_exit:
1984
1985 return ice_vc_send_msg_to_vf(vf, vc_op, v_ret, NULL, 0);
1986}
1987
1988
1989
1990
1991
1992
1993
1994
1995static int ice_vc_add_mac_addr_msg(struct ice_vf *vf, u8 *msg)
1996{
1997 return ice_vc_handle_mac_addr_msg(vf, msg, true);
1998}
1999
2000
2001
2002
2003
2004
2005
2006
2007static int ice_vc_del_mac_addr_msg(struct ice_vf *vf, u8 *msg)
2008{
2009 return ice_vc_handle_mac_addr_msg(vf, msg, false);
2010}
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022static int ice_vc_request_qs_msg(struct ice_vf *vf, u8 *msg)
2023{
2024 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
2025 struct virtchnl_vf_res_request *vfres =
2026 (struct virtchnl_vf_res_request *)msg;
2027 u16 req_queues = vfres->num_queue_pairs;
2028 struct ice_pf *pf = vf->pf;
2029 u16 max_allowed_vf_queues;
2030 u16 tx_rx_queue_left;
2031 struct device *dev;
2032 u16 cur_queues;
2033
2034 dev = ice_pf_to_dev(pf);
2035 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
2036 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2037 goto error_param;
2038 }
2039
2040 cur_queues = vf->num_vf_qs;
2041 tx_rx_queue_left = min_t(u16, ice_get_avail_txq_count(pf),
2042 ice_get_avail_rxq_count(pf));
2043 max_allowed_vf_queues = tx_rx_queue_left + cur_queues;
2044 if (!req_queues) {
2045 dev_err(dev, "VF %d tried to request 0 queues. Ignoring.\n",
2046 vf->vf_id);
2047 } else if (req_queues > ICE_MAX_RSS_QS_PER_VF) {
2048 dev_err(dev, "VF %d tried to request more than %d queues.\n",
2049 vf->vf_id, ICE_MAX_RSS_QS_PER_VF);
2050 vfres->num_queue_pairs = ICE_MAX_RSS_QS_PER_VF;
2051 } else if (req_queues > cur_queues &&
2052 req_queues - cur_queues > tx_rx_queue_left) {
2053 dev_warn(dev, "VF %d requested %u more queues, but only %u left.\n",
2054 vf->vf_id, req_queues - cur_queues, tx_rx_queue_left);
2055 vfres->num_queue_pairs = min_t(u16, max_allowed_vf_queues,
2056 ICE_MAX_RSS_QS_PER_VF);
2057 } else {
2058
2059 vf->num_req_qs = req_queues;
2060 ice_reset_vf(vf, ICE_VF_RESET_NOTIFY);
2061 dev_info(dev, "VF %d granted request of %u queues.\n",
2062 vf->vf_id, req_queues);
2063 return 0;
2064 }
2065
2066error_param:
2067
2068 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_REQUEST_QUEUES,
2069 v_ret, (u8 *)vfres, sizeof(*vfres));
2070}
2071
2072
2073
2074
2075
2076
2077
2078static bool ice_vf_vlan_offload_ena(u32 caps)
2079{
2080 return !!(caps & VIRTCHNL_VF_OFFLOAD_VLAN);
2081}
2082
2083
2084
2085
2086
2087static bool ice_is_vlan_promisc_allowed(struct ice_vf *vf)
2088{
2089 if ((test_bit(ICE_VF_STATE_UC_PROMISC, vf->vf_states) ||
2090 test_bit(ICE_VF_STATE_MC_PROMISC, vf->vf_states)) &&
2091 test_bit(ICE_FLAG_VF_TRUE_PROMISC_ENA, vf->pf->flags))
2092 return true;
2093
2094 return false;
2095}
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105static int ice_vf_ena_vlan_promisc(struct ice_vsi *vsi, struct ice_vlan *vlan)
2106{
2107 u8 promisc_m = ICE_PROMISC_VLAN_TX | ICE_PROMISC_VLAN_RX;
2108 int status;
2109
2110 status = ice_fltr_set_vsi_promisc(&vsi->back->hw, vsi->idx, promisc_m,
2111 vlan->vid);
2112 if (status && status != -EEXIST)
2113 return status;
2114
2115 return 0;
2116}
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126static int ice_vf_dis_vlan_promisc(struct ice_vsi *vsi, struct ice_vlan *vlan)
2127{
2128 u8 promisc_m = ICE_PROMISC_VLAN_TX | ICE_PROMISC_VLAN_RX;
2129 int status;
2130
2131 status = ice_fltr_clear_vsi_promisc(&vsi->back->hw, vsi->idx, promisc_m,
2132 vlan->vid);
2133 if (status && status != -ENOENT)
2134 return status;
2135
2136 return 0;
2137}
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150static bool ice_vf_has_max_vlans(struct ice_vf *vf, struct ice_vsi *vsi)
2151{
2152 if (ice_is_vf_trusted(vf))
2153 return false;
2154
2155#define ICE_VF_ADDED_VLAN_ZERO_FLTRS 1
2156 return ((ice_vsi_num_non_zero_vlans(vsi) +
2157 ICE_VF_ADDED_VLAN_ZERO_FLTRS) >= ICE_MAX_VLAN_PER_VF);
2158}
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168static int ice_vc_process_vlan_msg(struct ice_vf *vf, u8 *msg, bool add_v)
2169{
2170 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
2171 struct virtchnl_vlan_filter_list *vfl =
2172 (struct virtchnl_vlan_filter_list *)msg;
2173 struct ice_pf *pf = vf->pf;
2174 bool vlan_promisc = false;
2175 struct ice_vsi *vsi;
2176 struct device *dev;
2177 int status = 0;
2178 int i;
2179
2180 dev = ice_pf_to_dev(pf);
2181 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
2182 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2183 goto error_param;
2184 }
2185
2186 if (!ice_vf_vlan_offload_ena(vf->driver_caps)) {
2187 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2188 goto error_param;
2189 }
2190
2191 if (!ice_vc_isvalid_vsi_id(vf, vfl->vsi_id)) {
2192 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2193 goto error_param;
2194 }
2195
2196 for (i = 0; i < vfl->num_elements; i++) {
2197 if (vfl->vlan_id[i] >= VLAN_N_VID) {
2198 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2199 dev_err(dev, "invalid VF VLAN id %d\n",
2200 vfl->vlan_id[i]);
2201 goto error_param;
2202 }
2203 }
2204
2205 vsi = ice_get_vf_vsi(vf);
2206 if (!vsi) {
2207 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2208 goto error_param;
2209 }
2210
2211 if (add_v && ice_vf_has_max_vlans(vf, vsi)) {
2212 dev_info(dev, "VF-%d is not trusted, switch the VF to trusted mode, in order to add more VLAN addresses\n",
2213 vf->vf_id);
2214
2215
2216
2217 goto error_param;
2218 }
2219
2220
2221
2222
2223 if (ice_vf_is_port_vlan_ena(vf) && !ice_is_dvm_ena(&pf->hw)) {
2224 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2225 goto error_param;
2226 }
2227
2228
2229
2230
2231
2232 vlan_promisc = ice_is_vlan_promisc_allowed(vf) &&
2233 !ice_is_dvm_ena(&pf->hw) &&
2234 !ice_vf_is_port_vlan_ena(vf);
2235
2236 if (add_v) {
2237 for (i = 0; i < vfl->num_elements; i++) {
2238 u16 vid = vfl->vlan_id[i];
2239 struct ice_vlan vlan;
2240
2241 if (ice_vf_has_max_vlans(vf, vsi)) {
2242 dev_info(dev, "VF-%d is not trusted, switch the VF to trusted mode, in order to add more VLAN addresses\n",
2243 vf->vf_id);
2244
2245
2246
2247
2248 goto error_param;
2249 }
2250
2251
2252
2253
2254
2255 if (!vid)
2256 continue;
2257
2258 vlan = ICE_VLAN(ETH_P_8021Q, vid, 0);
2259 status = vsi->inner_vlan_ops.add_vlan(vsi, &vlan);
2260 if (status) {
2261 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2262 goto error_param;
2263 }
2264
2265
2266 if (!vlan_promisc && vid && !ice_is_dvm_ena(&pf->hw)) {
2267 if (vsi->inner_vlan_ops.ena_rx_filtering(vsi)) {
2268 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2269 dev_err(dev, "Enable VLAN pruning on VLAN ID: %d failed error-%d\n",
2270 vid, status);
2271 goto error_param;
2272 }
2273 } else if (vlan_promisc) {
2274 status = ice_vf_ena_vlan_promisc(vsi, &vlan);
2275 if (status) {
2276 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2277 dev_err(dev, "Enable Unicast/multicast promiscuous mode on VLAN ID:%d failed error-%d\n",
2278 vid, status);
2279 }
2280 }
2281 }
2282 } else {
2283
2284
2285
2286
2287
2288
2289
2290 int num_vf_vlan;
2291
2292 num_vf_vlan = vsi->num_vlan;
2293 for (i = 0; i < vfl->num_elements && i < num_vf_vlan; i++) {
2294 u16 vid = vfl->vlan_id[i];
2295 struct ice_vlan vlan;
2296
2297
2298
2299
2300
2301 if (!vid)
2302 continue;
2303
2304 vlan = ICE_VLAN(ETH_P_8021Q, vid, 0);
2305 status = vsi->inner_vlan_ops.del_vlan(vsi, &vlan);
2306 if (status) {
2307 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2308 goto error_param;
2309 }
2310
2311
2312 if (!ice_vsi_has_non_zero_vlans(vsi))
2313 vsi->inner_vlan_ops.dis_rx_filtering(vsi);
2314
2315 if (vlan_promisc)
2316 ice_vf_dis_vlan_promisc(vsi, &vlan);
2317 }
2318 }
2319
2320error_param:
2321
2322 if (add_v)
2323 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_ADD_VLAN, v_ret,
2324 NULL, 0);
2325 else
2326 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_DEL_VLAN, v_ret,
2327 NULL, 0);
2328}
2329
2330
2331
2332
2333
2334
2335
2336
2337static int ice_vc_add_vlan_msg(struct ice_vf *vf, u8 *msg)
2338{
2339 return ice_vc_process_vlan_msg(vf, msg, true);
2340}
2341
2342
2343
2344
2345
2346
2347
2348
2349static int ice_vc_remove_vlan_msg(struct ice_vf *vf, u8 *msg)
2350{
2351 return ice_vc_process_vlan_msg(vf, msg, false);
2352}
2353
2354
2355
2356
2357
2358
2359
2360static int ice_vc_ena_vlan_stripping(struct ice_vf *vf)
2361{
2362 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
2363 struct ice_vsi *vsi;
2364
2365 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
2366 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2367 goto error_param;
2368 }
2369
2370 if (!ice_vf_vlan_offload_ena(vf->driver_caps)) {
2371 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2372 goto error_param;
2373 }
2374
2375 vsi = ice_get_vf_vsi(vf);
2376 if (!vsi) {
2377 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2378 goto error_param;
2379 }
2380
2381 if (vsi->inner_vlan_ops.ena_stripping(vsi, ETH_P_8021Q))
2382 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2383
2384error_param:
2385 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_ENABLE_VLAN_STRIPPING,
2386 v_ret, NULL, 0);
2387}
2388
2389
2390
2391
2392
2393
2394
2395static int ice_vc_dis_vlan_stripping(struct ice_vf *vf)
2396{
2397 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
2398 struct ice_vsi *vsi;
2399
2400 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
2401 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2402 goto error_param;
2403 }
2404
2405 if (!ice_vf_vlan_offload_ena(vf->driver_caps)) {
2406 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2407 goto error_param;
2408 }
2409
2410 vsi = ice_get_vf_vsi(vf);
2411 if (!vsi) {
2412 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2413 goto error_param;
2414 }
2415
2416 if (vsi->inner_vlan_ops.dis_stripping(vsi))
2417 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2418
2419error_param:
2420 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_DISABLE_VLAN_STRIPPING,
2421 v_ret, NULL, 0);
2422}
2423
2424
2425
2426
2427
2428
2429
2430
2431static int ice_vf_init_vlan_stripping(struct ice_vf *vf)
2432{
2433 struct ice_vsi *vsi = ice_get_vf_vsi(vf);
2434
2435 if (!vsi)
2436 return -EINVAL;
2437
2438
2439
2440
2441 if (ice_vf_is_port_vlan_ena(vf) && !ice_is_dvm_ena(&vsi->back->hw))
2442 return 0;
2443
2444 if (ice_vf_vlan_offload_ena(vf->driver_caps))
2445 return vsi->inner_vlan_ops.ena_stripping(vsi, ETH_P_8021Q);
2446 else
2447 return vsi->inner_vlan_ops.dis_stripping(vsi);
2448}
2449
2450static u16 ice_vc_get_max_vlan_fltrs(struct ice_vf *vf)
2451{
2452 if (vf->trusted)
2453 return VLAN_N_VID;
2454 else
2455 return ICE_MAX_VLAN_PER_VF;
2456}
2457
2458
2459
2460
2461
2462
2463
2464
2465static bool ice_vf_outer_vlan_not_allowed(struct ice_vf *vf)
2466{
2467 if (ice_vf_is_port_vlan_ena(vf))
2468 return true;
2469
2470 return false;
2471}
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483static void
2484ice_vc_set_dvm_caps(struct ice_vf *vf, struct virtchnl_vlan_caps *caps)
2485{
2486 struct virtchnl_vlan_supported_caps *supported_caps;
2487
2488 if (ice_vf_outer_vlan_not_allowed(vf)) {
2489
2490
2491
2492
2493 supported_caps = &caps->filtering.filtering_support;
2494 supported_caps->inner = VIRTCHNL_VLAN_UNSUPPORTED;
2495
2496 supported_caps = &caps->offloads.stripping_support;
2497 supported_caps->inner = VIRTCHNL_VLAN_ETHERTYPE_8100 |
2498 VIRTCHNL_VLAN_TOGGLE |
2499 VIRTCHNL_VLAN_TAG_LOCATION_L2TAG1;
2500 supported_caps->outer = VIRTCHNL_VLAN_UNSUPPORTED;
2501
2502 supported_caps = &caps->offloads.insertion_support;
2503 supported_caps->inner = VIRTCHNL_VLAN_ETHERTYPE_8100 |
2504 VIRTCHNL_VLAN_TOGGLE |
2505 VIRTCHNL_VLAN_TAG_LOCATION_L2TAG1;
2506 supported_caps->outer = VIRTCHNL_VLAN_UNSUPPORTED;
2507
2508 caps->offloads.ethertype_init = VIRTCHNL_VLAN_ETHERTYPE_8100;
2509 caps->offloads.ethertype_match =
2510 VIRTCHNL_ETHERTYPE_STRIPPING_MATCHES_INSERTION;
2511 } else {
2512 supported_caps = &caps->filtering.filtering_support;
2513 supported_caps->inner = VIRTCHNL_VLAN_UNSUPPORTED;
2514 supported_caps->outer = VIRTCHNL_VLAN_ETHERTYPE_8100 |
2515 VIRTCHNL_VLAN_ETHERTYPE_88A8 |
2516 VIRTCHNL_VLAN_ETHERTYPE_9100 |
2517 VIRTCHNL_VLAN_ETHERTYPE_AND;
2518 caps->filtering.ethertype_init = VIRTCHNL_VLAN_ETHERTYPE_8100 |
2519 VIRTCHNL_VLAN_ETHERTYPE_88A8 |
2520 VIRTCHNL_VLAN_ETHERTYPE_9100;
2521
2522 supported_caps = &caps->offloads.stripping_support;
2523 supported_caps->inner = VIRTCHNL_VLAN_TOGGLE |
2524 VIRTCHNL_VLAN_ETHERTYPE_8100 |
2525 VIRTCHNL_VLAN_TAG_LOCATION_L2TAG1;
2526 supported_caps->outer = VIRTCHNL_VLAN_TOGGLE |
2527 VIRTCHNL_VLAN_ETHERTYPE_8100 |
2528 VIRTCHNL_VLAN_ETHERTYPE_88A8 |
2529 VIRTCHNL_VLAN_ETHERTYPE_9100 |
2530 VIRTCHNL_VLAN_ETHERTYPE_XOR |
2531 VIRTCHNL_VLAN_TAG_LOCATION_L2TAG2_2;
2532
2533 supported_caps = &caps->offloads.insertion_support;
2534 supported_caps->inner = VIRTCHNL_VLAN_TOGGLE |
2535 VIRTCHNL_VLAN_ETHERTYPE_8100 |
2536 VIRTCHNL_VLAN_TAG_LOCATION_L2TAG1;
2537 supported_caps->outer = VIRTCHNL_VLAN_TOGGLE |
2538 VIRTCHNL_VLAN_ETHERTYPE_8100 |
2539 VIRTCHNL_VLAN_ETHERTYPE_88A8 |
2540 VIRTCHNL_VLAN_ETHERTYPE_9100 |
2541 VIRTCHNL_VLAN_ETHERTYPE_XOR |
2542 VIRTCHNL_VLAN_TAG_LOCATION_L2TAG2;
2543
2544 caps->offloads.ethertype_init = VIRTCHNL_VLAN_ETHERTYPE_8100;
2545
2546 caps->offloads.ethertype_match =
2547 VIRTCHNL_ETHERTYPE_STRIPPING_MATCHES_INSERTION;
2548 }
2549
2550 caps->filtering.max_filters = ice_vc_get_max_vlan_fltrs(vf);
2551}
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564static void
2565ice_vc_set_svm_caps(struct ice_vf *vf, struct virtchnl_vlan_caps *caps)
2566{
2567 struct virtchnl_vlan_supported_caps *supported_caps;
2568
2569 if (ice_vf_is_port_vlan_ena(vf)) {
2570 supported_caps = &caps->filtering.filtering_support;
2571 supported_caps->inner = VIRTCHNL_VLAN_UNSUPPORTED;
2572 supported_caps->outer = VIRTCHNL_VLAN_UNSUPPORTED;
2573
2574 supported_caps = &caps->offloads.stripping_support;
2575 supported_caps->inner = VIRTCHNL_VLAN_UNSUPPORTED;
2576 supported_caps->outer = VIRTCHNL_VLAN_UNSUPPORTED;
2577
2578 supported_caps = &caps->offloads.insertion_support;
2579 supported_caps->inner = VIRTCHNL_VLAN_UNSUPPORTED;
2580 supported_caps->outer = VIRTCHNL_VLAN_UNSUPPORTED;
2581
2582 caps->offloads.ethertype_init = VIRTCHNL_VLAN_UNSUPPORTED;
2583 caps->offloads.ethertype_match = VIRTCHNL_VLAN_UNSUPPORTED;
2584 caps->filtering.max_filters = 0;
2585 } else {
2586 supported_caps = &caps->filtering.filtering_support;
2587 supported_caps->inner = VIRTCHNL_VLAN_ETHERTYPE_8100;
2588 supported_caps->outer = VIRTCHNL_VLAN_UNSUPPORTED;
2589 caps->filtering.ethertype_init = VIRTCHNL_VLAN_ETHERTYPE_8100;
2590
2591 supported_caps = &caps->offloads.stripping_support;
2592 supported_caps->inner = VIRTCHNL_VLAN_ETHERTYPE_8100 |
2593 VIRTCHNL_VLAN_TOGGLE |
2594 VIRTCHNL_VLAN_TAG_LOCATION_L2TAG1;
2595 supported_caps->outer = VIRTCHNL_VLAN_UNSUPPORTED;
2596
2597 supported_caps = &caps->offloads.insertion_support;
2598 supported_caps->inner = VIRTCHNL_VLAN_ETHERTYPE_8100 |
2599 VIRTCHNL_VLAN_TOGGLE |
2600 VIRTCHNL_VLAN_TAG_LOCATION_L2TAG1;
2601 supported_caps->outer = VIRTCHNL_VLAN_UNSUPPORTED;
2602
2603 caps->offloads.ethertype_init = VIRTCHNL_VLAN_ETHERTYPE_8100;
2604 caps->offloads.ethertype_match =
2605 VIRTCHNL_ETHERTYPE_STRIPPING_MATCHES_INSERTION;
2606 caps->filtering.max_filters = ice_vc_get_max_vlan_fltrs(vf);
2607 }
2608}
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620static int ice_vc_get_offload_vlan_v2_caps(struct ice_vf *vf)
2621{
2622 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
2623 struct virtchnl_vlan_caps *caps = NULL;
2624 int err, len = 0;
2625
2626 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
2627 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2628 goto out;
2629 }
2630
2631 caps = kzalloc(sizeof(*caps), GFP_KERNEL);
2632 if (!caps) {
2633 v_ret = VIRTCHNL_STATUS_ERR_NO_MEMORY;
2634 goto out;
2635 }
2636 len = sizeof(*caps);
2637
2638 if (ice_is_dvm_ena(&vf->pf->hw))
2639 ice_vc_set_dvm_caps(vf, caps);
2640 else
2641 ice_vc_set_svm_caps(vf, caps);
2642
2643
2644 memcpy(&vf->vlan_v2_caps, caps, sizeof(*caps));
2645
2646out:
2647 err = ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS,
2648 v_ret, (u8 *)caps, len);
2649 kfree(caps);
2650 return err;
2651}
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661static bool ice_vc_validate_vlan_tpid(u16 filtering_caps, u16 tpid)
2662{
2663 enum virtchnl_vlan_support vlan_ethertype = VIRTCHNL_VLAN_UNSUPPORTED;
2664
2665 switch (tpid) {
2666 case ETH_P_8021Q:
2667 vlan_ethertype = VIRTCHNL_VLAN_ETHERTYPE_8100;
2668 break;
2669 case ETH_P_8021AD:
2670 vlan_ethertype = VIRTCHNL_VLAN_ETHERTYPE_88A8;
2671 break;
2672 case ETH_P_QINQ1:
2673 vlan_ethertype = VIRTCHNL_VLAN_ETHERTYPE_9100;
2674 break;
2675 }
2676
2677 if (!(filtering_caps & vlan_ethertype))
2678 return false;
2679
2680 return true;
2681}
2682
2683
2684
2685
2686
2687
2688
2689
2690static bool ice_vc_is_valid_vlan(struct virtchnl_vlan *vc_vlan)
2691{
2692 if (!vc_vlan->tci || !vc_vlan->tpid)
2693 return false;
2694
2695 return true;
2696}
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706static bool
2707ice_vc_validate_vlan_filter_list(struct virtchnl_vlan_filtering_caps *vfc,
2708 struct virtchnl_vlan_filter_list_v2 *vfl)
2709{
2710 u16 i;
2711
2712 if (!vfl->num_elements)
2713 return false;
2714
2715 for (i = 0; i < vfl->num_elements; i++) {
2716 struct virtchnl_vlan_supported_caps *filtering_support =
2717 &vfc->filtering_support;
2718 struct virtchnl_vlan_filter *vlan_fltr = &vfl->filters[i];
2719 struct virtchnl_vlan *outer = &vlan_fltr->outer;
2720 struct virtchnl_vlan *inner = &vlan_fltr->inner;
2721
2722 if ((ice_vc_is_valid_vlan(outer) &&
2723 filtering_support->outer == VIRTCHNL_VLAN_UNSUPPORTED) ||
2724 (ice_vc_is_valid_vlan(inner) &&
2725 filtering_support->inner == VIRTCHNL_VLAN_UNSUPPORTED))
2726 return false;
2727
2728 if ((outer->tci_mask &&
2729 !(filtering_support->outer & VIRTCHNL_VLAN_FILTER_MASK)) ||
2730 (inner->tci_mask &&
2731 !(filtering_support->inner & VIRTCHNL_VLAN_FILTER_MASK)))
2732 return false;
2733
2734 if (((outer->tci & VLAN_PRIO_MASK) &&
2735 !(filtering_support->outer & VIRTCHNL_VLAN_PRIO)) ||
2736 ((inner->tci & VLAN_PRIO_MASK) &&
2737 !(filtering_support->inner & VIRTCHNL_VLAN_PRIO)))
2738 return false;
2739
2740 if ((ice_vc_is_valid_vlan(outer) &&
2741 !ice_vc_validate_vlan_tpid(filtering_support->outer,
2742 outer->tpid)) ||
2743 (ice_vc_is_valid_vlan(inner) &&
2744 !ice_vc_validate_vlan_tpid(filtering_support->inner,
2745 inner->tpid)))
2746 return false;
2747 }
2748
2749 return true;
2750}
2751
2752
2753
2754
2755
2756static struct ice_vlan ice_vc_to_vlan(struct virtchnl_vlan *vc_vlan)
2757{
2758 struct ice_vlan vlan = { 0 };
2759
2760 vlan.prio = (vc_vlan->tci & VLAN_PRIO_MASK) >> VLAN_PRIO_SHIFT;
2761 vlan.vid = vc_vlan->tci & VLAN_VID_MASK;
2762 vlan.tpid = vc_vlan->tpid;
2763
2764 return vlan;
2765}
2766
2767
2768
2769
2770
2771
2772
2773static int
2774ice_vc_vlan_action(struct ice_vsi *vsi,
2775 int (*vlan_action)(struct ice_vsi *, struct ice_vlan *),
2776 struct ice_vlan *vlan)
2777{
2778 int err;
2779
2780 err = vlan_action(vsi, vlan);
2781 if (err)
2782 return err;
2783
2784 return 0;
2785}
2786
2787
2788
2789
2790
2791
2792
2793static int
2794ice_vc_del_vlans(struct ice_vf *vf, struct ice_vsi *vsi,
2795 struct virtchnl_vlan_filter_list_v2 *vfl)
2796{
2797 bool vlan_promisc = ice_is_vlan_promisc_allowed(vf);
2798 int err;
2799 u16 i;
2800
2801 for (i = 0; i < vfl->num_elements; i++) {
2802 struct virtchnl_vlan_filter *vlan_fltr = &vfl->filters[i];
2803 struct virtchnl_vlan *vc_vlan;
2804
2805 vc_vlan = &vlan_fltr->outer;
2806 if (ice_vc_is_valid_vlan(vc_vlan)) {
2807 struct ice_vlan vlan = ice_vc_to_vlan(vc_vlan);
2808
2809 err = ice_vc_vlan_action(vsi,
2810 vsi->outer_vlan_ops.del_vlan,
2811 &vlan);
2812 if (err)
2813 return err;
2814
2815 if (vlan_promisc)
2816 ice_vf_dis_vlan_promisc(vsi, &vlan);
2817 }
2818
2819 vc_vlan = &vlan_fltr->inner;
2820 if (ice_vc_is_valid_vlan(vc_vlan)) {
2821 struct ice_vlan vlan = ice_vc_to_vlan(vc_vlan);
2822
2823 err = ice_vc_vlan_action(vsi,
2824 vsi->inner_vlan_ops.del_vlan,
2825 &vlan);
2826 if (err)
2827 return err;
2828
2829
2830
2831
2832 if (!ice_is_dvm_ena(&vsi->back->hw) && vlan_promisc)
2833 ice_vf_dis_vlan_promisc(vsi, &vlan);
2834 }
2835 }
2836
2837 return 0;
2838}
2839
2840
2841
2842
2843
2844
2845static int ice_vc_remove_vlan_v2_msg(struct ice_vf *vf, u8 *msg)
2846{
2847 struct virtchnl_vlan_filter_list_v2 *vfl =
2848 (struct virtchnl_vlan_filter_list_v2 *)msg;
2849 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
2850 struct ice_vsi *vsi;
2851
2852 if (!ice_vc_validate_vlan_filter_list(&vf->vlan_v2_caps.filtering,
2853 vfl)) {
2854 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2855 goto out;
2856 }
2857
2858 if (!ice_vc_isvalid_vsi_id(vf, vfl->vport_id)) {
2859 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2860 goto out;
2861 }
2862
2863 vsi = ice_get_vf_vsi(vf);
2864 if (!vsi) {
2865 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2866 goto out;
2867 }
2868
2869 if (ice_vc_del_vlans(vf, vsi, vfl))
2870 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2871
2872out:
2873 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_DEL_VLAN_V2, v_ret, NULL,
2874 0);
2875}
2876
2877
2878
2879
2880
2881
2882
2883static int
2884ice_vc_add_vlans(struct ice_vf *vf, struct ice_vsi *vsi,
2885 struct virtchnl_vlan_filter_list_v2 *vfl)
2886{
2887 bool vlan_promisc = ice_is_vlan_promisc_allowed(vf);
2888 int err;
2889 u16 i;
2890
2891 for (i = 0; i < vfl->num_elements; i++) {
2892 struct virtchnl_vlan_filter *vlan_fltr = &vfl->filters[i];
2893 struct virtchnl_vlan *vc_vlan;
2894
2895 vc_vlan = &vlan_fltr->outer;
2896 if (ice_vc_is_valid_vlan(vc_vlan)) {
2897 struct ice_vlan vlan = ice_vc_to_vlan(vc_vlan);
2898
2899 err = ice_vc_vlan_action(vsi,
2900 vsi->outer_vlan_ops.add_vlan,
2901 &vlan);
2902 if (err)
2903 return err;
2904
2905 if (vlan_promisc) {
2906 err = ice_vf_ena_vlan_promisc(vsi, &vlan);
2907 if (err)
2908 return err;
2909 }
2910 }
2911
2912 vc_vlan = &vlan_fltr->inner;
2913 if (ice_vc_is_valid_vlan(vc_vlan)) {
2914 struct ice_vlan vlan = ice_vc_to_vlan(vc_vlan);
2915
2916 err = ice_vc_vlan_action(vsi,
2917 vsi->inner_vlan_ops.add_vlan,
2918 &vlan);
2919 if (err)
2920 return err;
2921
2922
2923
2924
2925 if (!ice_is_dvm_ena(&vsi->back->hw) && vlan_promisc) {
2926 err = ice_vf_ena_vlan_promisc(vsi, &vlan);
2927 if (err)
2928 return err;
2929 }
2930 }
2931 }
2932
2933 return 0;
2934}
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946static bool
2947ice_vc_validate_add_vlan_filter_list(struct ice_vsi *vsi,
2948 struct virtchnl_vlan_filtering_caps *vfc,
2949 struct virtchnl_vlan_filter_list_v2 *vfl)
2950{
2951 u16 num_requested_filters = ice_vsi_num_non_zero_vlans(vsi) +
2952 vfl->num_elements;
2953
2954 if (num_requested_filters > vfc->max_filters)
2955 return false;
2956
2957 return ice_vc_validate_vlan_filter_list(vfc, vfl);
2958}
2959
2960
2961
2962
2963
2964
2965static int ice_vc_add_vlan_v2_msg(struct ice_vf *vf, u8 *msg)
2966{
2967 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
2968 struct virtchnl_vlan_filter_list_v2 *vfl =
2969 (struct virtchnl_vlan_filter_list_v2 *)msg;
2970 struct ice_vsi *vsi;
2971
2972 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
2973 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2974 goto out;
2975 }
2976
2977 if (!ice_vc_isvalid_vsi_id(vf, vfl->vport_id)) {
2978 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2979 goto out;
2980 }
2981
2982 vsi = ice_get_vf_vsi(vf);
2983 if (!vsi) {
2984 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2985 goto out;
2986 }
2987
2988 if (!ice_vc_validate_add_vlan_filter_list(vsi,
2989 &vf->vlan_v2_caps.filtering,
2990 vfl)) {
2991 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2992 goto out;
2993 }
2994
2995 if (ice_vc_add_vlans(vf, vsi, vfl))
2996 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
2997
2998out:
2999 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_ADD_VLAN_V2, v_ret, NULL,
3000 0);
3001}
3002
3003
3004
3005
3006
3007
3008static bool
3009ice_vc_valid_vlan_setting(u32 negotiated_settings, u32 ethertype_setting)
3010{
3011 if (ethertype_setting && !(negotiated_settings & ethertype_setting))
3012 return false;
3013
3014
3015
3016
3017 if (!(negotiated_settings & VIRTCHNL_VLAN_ETHERTYPE_AND) &&
3018 hweight32(ethertype_setting) > 1)
3019 return false;
3020
3021
3022 if (!(negotiated_settings & VIRTCHNL_VLAN_TOGGLE))
3023 return false;
3024
3025 return true;
3026}
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037static bool
3038ice_vc_valid_vlan_setting_msg(struct virtchnl_vlan_supported_caps *caps,
3039 struct virtchnl_vlan_setting *msg)
3040{
3041 if ((!msg->outer_ethertype_setting &&
3042 !msg->inner_ethertype_setting) ||
3043 (!caps->outer && !caps->inner))
3044 return false;
3045
3046 if (msg->outer_ethertype_setting &&
3047 !ice_vc_valid_vlan_setting(caps->outer,
3048 msg->outer_ethertype_setting))
3049 return false;
3050
3051 if (msg->inner_ethertype_setting &&
3052 !ice_vc_valid_vlan_setting(caps->inner,
3053 msg->inner_ethertype_setting))
3054 return false;
3055
3056 return true;
3057}
3058
3059
3060
3061
3062
3063
3064static int ice_vc_get_tpid(u32 ethertype_setting, u16 *tpid)
3065{
3066 switch (ethertype_setting) {
3067 case VIRTCHNL_VLAN_ETHERTYPE_8100:
3068 *tpid = ETH_P_8021Q;
3069 break;
3070 case VIRTCHNL_VLAN_ETHERTYPE_88A8:
3071 *tpid = ETH_P_8021AD;
3072 break;
3073 case VIRTCHNL_VLAN_ETHERTYPE_9100:
3074 *tpid = ETH_P_QINQ1;
3075 break;
3076 default:
3077 *tpid = 0;
3078 return -EINVAL;
3079 }
3080
3081 return 0;
3082}
3083
3084
3085
3086
3087
3088
3089
3090static int
3091ice_vc_ena_vlan_offload(struct ice_vsi *vsi,
3092 int (*ena_offload)(struct ice_vsi *vsi, u16 tpid),
3093 u32 ethertype_setting)
3094{
3095 u16 tpid;
3096 int err;
3097
3098 err = ice_vc_get_tpid(ethertype_setting, &tpid);
3099 if (err)
3100 return err;
3101
3102 err = ena_offload(vsi, tpid);
3103 if (err)
3104 return err;
3105
3106 return 0;
3107}
3108
3109#define ICE_L2TSEL_QRX_CONTEXT_REG_IDX 3
3110#define ICE_L2TSEL_BIT_OFFSET 23
3111enum ice_l2tsel {
3112 ICE_L2TSEL_EXTRACT_FIRST_TAG_L2TAG2_2ND,
3113 ICE_L2TSEL_EXTRACT_FIRST_TAG_L2TAG1,
3114};
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125static void ice_vsi_update_l2tsel(struct ice_vsi *vsi, enum ice_l2tsel l2tsel)
3126{
3127 struct ice_hw *hw = &vsi->back->hw;
3128 u32 l2tsel_bit;
3129 int i;
3130
3131 if (l2tsel == ICE_L2TSEL_EXTRACT_FIRST_TAG_L2TAG2_2ND)
3132 l2tsel_bit = 0;
3133 else
3134 l2tsel_bit = BIT(ICE_L2TSEL_BIT_OFFSET);
3135
3136 for (i = 0; i < vsi->alloc_rxq; i++) {
3137 u16 pfq = vsi->rxq_map[i];
3138 u32 qrx_context_offset;
3139 u32 regval;
3140
3141 qrx_context_offset =
3142 QRX_CONTEXT(ICE_L2TSEL_QRX_CONTEXT_REG_IDX, pfq);
3143
3144 regval = rd32(hw, qrx_context_offset);
3145 regval &= ~BIT(ICE_L2TSEL_BIT_OFFSET);
3146 regval |= l2tsel_bit;
3147 wr32(hw, qrx_context_offset, regval);
3148 }
3149}
3150
3151
3152
3153
3154
3155
3156
3157
3158static int ice_vc_ena_vlan_stripping_v2_msg(struct ice_vf *vf, u8 *msg)
3159{
3160 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
3161 struct virtchnl_vlan_supported_caps *stripping_support;
3162 struct virtchnl_vlan_setting *strip_msg =
3163 (struct virtchnl_vlan_setting *)msg;
3164 u32 ethertype_setting;
3165 struct ice_vsi *vsi;
3166
3167 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
3168 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3169 goto out;
3170 }
3171
3172 if (!ice_vc_isvalid_vsi_id(vf, strip_msg->vport_id)) {
3173 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3174 goto out;
3175 }
3176
3177 vsi = ice_get_vf_vsi(vf);
3178 if (!vsi) {
3179 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3180 goto out;
3181 }
3182
3183 stripping_support = &vf->vlan_v2_caps.offloads.stripping_support;
3184 if (!ice_vc_valid_vlan_setting_msg(stripping_support, strip_msg)) {
3185 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3186 goto out;
3187 }
3188
3189 ethertype_setting = strip_msg->outer_ethertype_setting;
3190 if (ethertype_setting) {
3191 if (ice_vc_ena_vlan_offload(vsi,
3192 vsi->outer_vlan_ops.ena_stripping,
3193 ethertype_setting)) {
3194 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3195 goto out;
3196 } else {
3197 enum ice_l2tsel l2tsel =
3198 ICE_L2TSEL_EXTRACT_FIRST_TAG_L2TAG2_2ND;
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208 ice_vsi_update_l2tsel(vsi, l2tsel);
3209 }
3210 }
3211
3212 ethertype_setting = strip_msg->inner_ethertype_setting;
3213 if (ethertype_setting &&
3214 ice_vc_ena_vlan_offload(vsi, vsi->inner_vlan_ops.ena_stripping,
3215 ethertype_setting)) {
3216 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3217 goto out;
3218 }
3219
3220out:
3221 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2,
3222 v_ret, NULL, 0);
3223}
3224
3225
3226
3227
3228
3229
3230
3231
3232static int ice_vc_dis_vlan_stripping_v2_msg(struct ice_vf *vf, u8 *msg)
3233{
3234 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
3235 struct virtchnl_vlan_supported_caps *stripping_support;
3236 struct virtchnl_vlan_setting *strip_msg =
3237 (struct virtchnl_vlan_setting *)msg;
3238 u32 ethertype_setting;
3239 struct ice_vsi *vsi;
3240
3241 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
3242 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3243 goto out;
3244 }
3245
3246 if (!ice_vc_isvalid_vsi_id(vf, strip_msg->vport_id)) {
3247 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3248 goto out;
3249 }
3250
3251 vsi = ice_get_vf_vsi(vf);
3252 if (!vsi) {
3253 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3254 goto out;
3255 }
3256
3257 stripping_support = &vf->vlan_v2_caps.offloads.stripping_support;
3258 if (!ice_vc_valid_vlan_setting_msg(stripping_support, strip_msg)) {
3259 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3260 goto out;
3261 }
3262
3263 ethertype_setting = strip_msg->outer_ethertype_setting;
3264 if (ethertype_setting) {
3265 if (vsi->outer_vlan_ops.dis_stripping(vsi)) {
3266 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3267 goto out;
3268 } else {
3269 enum ice_l2tsel l2tsel =
3270 ICE_L2TSEL_EXTRACT_FIRST_TAG_L2TAG1;
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280 ice_vsi_update_l2tsel(vsi, l2tsel);
3281 }
3282 }
3283
3284 ethertype_setting = strip_msg->inner_ethertype_setting;
3285 if (ethertype_setting && vsi->inner_vlan_ops.dis_stripping(vsi)) {
3286 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3287 goto out;
3288 }
3289
3290out:
3291 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2,
3292 v_ret, NULL, 0);
3293}
3294
3295
3296
3297
3298
3299
3300
3301
3302static int ice_vc_ena_vlan_insertion_v2_msg(struct ice_vf *vf, u8 *msg)
3303{
3304 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
3305 struct virtchnl_vlan_supported_caps *insertion_support;
3306 struct virtchnl_vlan_setting *insertion_msg =
3307 (struct virtchnl_vlan_setting *)msg;
3308 u32 ethertype_setting;
3309 struct ice_vsi *vsi;
3310
3311 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
3312 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3313 goto out;
3314 }
3315
3316 if (!ice_vc_isvalid_vsi_id(vf, insertion_msg->vport_id)) {
3317 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3318 goto out;
3319 }
3320
3321 vsi = ice_get_vf_vsi(vf);
3322 if (!vsi) {
3323 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3324 goto out;
3325 }
3326
3327 insertion_support = &vf->vlan_v2_caps.offloads.insertion_support;
3328 if (!ice_vc_valid_vlan_setting_msg(insertion_support, insertion_msg)) {
3329 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3330 goto out;
3331 }
3332
3333 ethertype_setting = insertion_msg->outer_ethertype_setting;
3334 if (ethertype_setting &&
3335 ice_vc_ena_vlan_offload(vsi, vsi->outer_vlan_ops.ena_insertion,
3336 ethertype_setting)) {
3337 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3338 goto out;
3339 }
3340
3341 ethertype_setting = insertion_msg->inner_ethertype_setting;
3342 if (ethertype_setting &&
3343 ice_vc_ena_vlan_offload(vsi, vsi->inner_vlan_ops.ena_insertion,
3344 ethertype_setting)) {
3345 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3346 goto out;
3347 }
3348
3349out:
3350 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2,
3351 v_ret, NULL, 0);
3352}
3353
3354
3355
3356
3357
3358
3359
3360
3361static int ice_vc_dis_vlan_insertion_v2_msg(struct ice_vf *vf, u8 *msg)
3362{
3363 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
3364 struct virtchnl_vlan_supported_caps *insertion_support;
3365 struct virtchnl_vlan_setting *insertion_msg =
3366 (struct virtchnl_vlan_setting *)msg;
3367 u32 ethertype_setting;
3368 struct ice_vsi *vsi;
3369
3370 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
3371 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3372 goto out;
3373 }
3374
3375 if (!ice_vc_isvalid_vsi_id(vf, insertion_msg->vport_id)) {
3376 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3377 goto out;
3378 }
3379
3380 vsi = ice_get_vf_vsi(vf);
3381 if (!vsi) {
3382 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3383 goto out;
3384 }
3385
3386 insertion_support = &vf->vlan_v2_caps.offloads.insertion_support;
3387 if (!ice_vc_valid_vlan_setting_msg(insertion_support, insertion_msg)) {
3388 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3389 goto out;
3390 }
3391
3392 ethertype_setting = insertion_msg->outer_ethertype_setting;
3393 if (ethertype_setting && vsi->outer_vlan_ops.dis_insertion(vsi)) {
3394 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3395 goto out;
3396 }
3397
3398 ethertype_setting = insertion_msg->inner_ethertype_setting;
3399 if (ethertype_setting && vsi->inner_vlan_ops.dis_insertion(vsi)) {
3400 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3401 goto out;
3402 }
3403
3404out:
3405 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2,
3406 v_ret, NULL, 0);
3407}
3408
3409static const struct ice_virtchnl_ops ice_virtchnl_dflt_ops = {
3410 .get_ver_msg = ice_vc_get_ver_msg,
3411 .get_vf_res_msg = ice_vc_get_vf_res_msg,
3412 .reset_vf = ice_vc_reset_vf_msg,
3413 .add_mac_addr_msg = ice_vc_add_mac_addr_msg,
3414 .del_mac_addr_msg = ice_vc_del_mac_addr_msg,
3415 .cfg_qs_msg = ice_vc_cfg_qs_msg,
3416 .ena_qs_msg = ice_vc_ena_qs_msg,
3417 .dis_qs_msg = ice_vc_dis_qs_msg,
3418 .request_qs_msg = ice_vc_request_qs_msg,
3419 .cfg_irq_map_msg = ice_vc_cfg_irq_map_msg,
3420 .config_rss_key = ice_vc_config_rss_key,
3421 .config_rss_lut = ice_vc_config_rss_lut,
3422 .get_stats_msg = ice_vc_get_stats_msg,
3423 .cfg_promiscuous_mode_msg = ice_vc_cfg_promiscuous_mode_msg,
3424 .add_vlan_msg = ice_vc_add_vlan_msg,
3425 .remove_vlan_msg = ice_vc_remove_vlan_msg,
3426 .ena_vlan_stripping = ice_vc_ena_vlan_stripping,
3427 .dis_vlan_stripping = ice_vc_dis_vlan_stripping,
3428 .handle_rss_cfg_msg = ice_vc_handle_rss_cfg,
3429 .add_fdir_fltr_msg = ice_vc_add_fdir_fltr,
3430 .del_fdir_fltr_msg = ice_vc_del_fdir_fltr,
3431 .get_offload_vlan_v2_caps = ice_vc_get_offload_vlan_v2_caps,
3432 .add_vlan_v2_msg = ice_vc_add_vlan_v2_msg,
3433 .remove_vlan_v2_msg = ice_vc_remove_vlan_v2_msg,
3434 .ena_vlan_stripping_v2_msg = ice_vc_ena_vlan_stripping_v2_msg,
3435 .dis_vlan_stripping_v2_msg = ice_vc_dis_vlan_stripping_v2_msg,
3436 .ena_vlan_insertion_v2_msg = ice_vc_ena_vlan_insertion_v2_msg,
3437 .dis_vlan_insertion_v2_msg = ice_vc_dis_vlan_insertion_v2_msg,
3438};
3439
3440
3441
3442
3443
3444void ice_virtchnl_set_dflt_ops(struct ice_vf *vf)
3445{
3446 vf->virtchnl_ops = &ice_virtchnl_dflt_ops;
3447}
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458static int ice_vc_repr_add_mac(struct ice_vf *vf, u8 *msg)
3459{
3460 enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
3461 struct virtchnl_ether_addr_list *al =
3462 (struct virtchnl_ether_addr_list *)msg;
3463 struct ice_vsi *vsi;
3464 struct ice_pf *pf;
3465 int i;
3466
3467 if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states) ||
3468 !ice_vc_isvalid_vsi_id(vf, al->vsi_id)) {
3469 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3470 goto handle_mac_exit;
3471 }
3472
3473 pf = vf->pf;
3474
3475 vsi = ice_get_vf_vsi(vf);
3476 if (!vsi) {
3477 v_ret = VIRTCHNL_STATUS_ERR_PARAM;
3478 goto handle_mac_exit;
3479 }
3480
3481 for (i = 0; i < al->num_elements; i++) {
3482 u8 *mac_addr = al->list[i].addr;
3483 int result;
3484
3485 if (!is_unicast_ether_addr(mac_addr) ||
3486 ether_addr_equal(mac_addr, vf->hw_lan_addr.addr))
3487 continue;
3488
3489 if (vf->pf_set_mac) {
3490 dev_err(ice_pf_to_dev(pf), "VF attempting to override administratively set MAC address\n");
3491 v_ret = VIRTCHNL_STATUS_ERR_NOT_SUPPORTED;
3492 goto handle_mac_exit;
3493 }
3494
3495 result = ice_eswitch_add_vf_mac_rule(pf, vf, mac_addr);
3496 if (result) {
3497 dev_err(ice_pf_to_dev(pf), "Failed to add MAC %pM for VF %d\n, error %d\n",
3498 mac_addr, vf->vf_id, result);
3499 goto handle_mac_exit;
3500 }
3501
3502 ice_vfhw_mac_add(vf, &al->list[i]);
3503 vf->num_mac++;
3504 break;
3505 }
3506
3507handle_mac_exit:
3508 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_ADD_ETH_ADDR,
3509 v_ret, NULL, 0);
3510}
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520static int
3521ice_vc_repr_del_mac(struct ice_vf __always_unused *vf, u8 __always_unused *msg)
3522{
3523 struct virtchnl_ether_addr_list *al =
3524 (struct virtchnl_ether_addr_list *)msg;
3525
3526 ice_update_legacy_cached_mac(vf, &al->list[0]);
3527
3528 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_DEL_ETH_ADDR,
3529 VIRTCHNL_STATUS_SUCCESS, NULL, 0);
3530}
3531
3532static int ice_vc_repr_add_vlan(struct ice_vf *vf, u8 __always_unused *msg)
3533{
3534 dev_dbg(ice_pf_to_dev(vf->pf),
3535 "Can't add VLAN in switchdev mode for VF %d\n", vf->vf_id);
3536 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_ADD_VLAN,
3537 VIRTCHNL_STATUS_SUCCESS, NULL, 0);
3538}
3539
3540static int ice_vc_repr_del_vlan(struct ice_vf *vf, u8 __always_unused *msg)
3541{
3542 dev_dbg(ice_pf_to_dev(vf->pf),
3543 "Can't delete VLAN in switchdev mode for VF %d\n", vf->vf_id);
3544 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_DEL_VLAN,
3545 VIRTCHNL_STATUS_SUCCESS, NULL, 0);
3546}
3547
3548static int ice_vc_repr_ena_vlan_stripping(struct ice_vf *vf)
3549{
3550 dev_dbg(ice_pf_to_dev(vf->pf),
3551 "Can't enable VLAN stripping in switchdev mode for VF %d\n",
3552 vf->vf_id);
3553 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_ENABLE_VLAN_STRIPPING,
3554 VIRTCHNL_STATUS_ERR_NOT_SUPPORTED,
3555 NULL, 0);
3556}
3557
3558static int ice_vc_repr_dis_vlan_stripping(struct ice_vf *vf)
3559{
3560 dev_dbg(ice_pf_to_dev(vf->pf),
3561 "Can't disable VLAN stripping in switchdev mode for VF %d\n",
3562 vf->vf_id);
3563 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_DISABLE_VLAN_STRIPPING,
3564 VIRTCHNL_STATUS_ERR_NOT_SUPPORTED,
3565 NULL, 0);
3566}
3567
3568static int
3569ice_vc_repr_cfg_promiscuous_mode(struct ice_vf *vf, u8 __always_unused *msg)
3570{
3571 dev_dbg(ice_pf_to_dev(vf->pf),
3572 "Can't config promiscuous mode in switchdev mode for VF %d\n",
3573 vf->vf_id);
3574 return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE,
3575 VIRTCHNL_STATUS_ERR_NOT_SUPPORTED,
3576 NULL, 0);
3577}
3578
3579static const struct ice_virtchnl_ops ice_virtchnl_repr_ops = {
3580 .get_ver_msg = ice_vc_get_ver_msg,
3581 .get_vf_res_msg = ice_vc_get_vf_res_msg,
3582 .reset_vf = ice_vc_reset_vf_msg,
3583 .add_mac_addr_msg = ice_vc_repr_add_mac,
3584 .del_mac_addr_msg = ice_vc_repr_del_mac,
3585 .cfg_qs_msg = ice_vc_cfg_qs_msg,
3586 .ena_qs_msg = ice_vc_ena_qs_msg,
3587 .dis_qs_msg = ice_vc_dis_qs_msg,
3588 .request_qs_msg = ice_vc_request_qs_msg,
3589 .cfg_irq_map_msg = ice_vc_cfg_irq_map_msg,
3590 .config_rss_key = ice_vc_config_rss_key,
3591 .config_rss_lut = ice_vc_config_rss_lut,
3592 .get_stats_msg = ice_vc_get_stats_msg,
3593 .cfg_promiscuous_mode_msg = ice_vc_repr_cfg_promiscuous_mode,
3594 .add_vlan_msg = ice_vc_repr_add_vlan,
3595 .remove_vlan_msg = ice_vc_repr_del_vlan,
3596 .ena_vlan_stripping = ice_vc_repr_ena_vlan_stripping,
3597 .dis_vlan_stripping = ice_vc_repr_dis_vlan_stripping,
3598 .handle_rss_cfg_msg = ice_vc_handle_rss_cfg,
3599 .add_fdir_fltr_msg = ice_vc_add_fdir_fltr,
3600 .del_fdir_fltr_msg = ice_vc_del_fdir_fltr,
3601 .get_offload_vlan_v2_caps = ice_vc_get_offload_vlan_v2_caps,
3602 .add_vlan_v2_msg = ice_vc_add_vlan_v2_msg,
3603 .remove_vlan_v2_msg = ice_vc_remove_vlan_v2_msg,
3604 .ena_vlan_stripping_v2_msg = ice_vc_ena_vlan_stripping_v2_msg,
3605 .dis_vlan_stripping_v2_msg = ice_vc_dis_vlan_stripping_v2_msg,
3606 .ena_vlan_insertion_v2_msg = ice_vc_ena_vlan_insertion_v2_msg,
3607 .dis_vlan_insertion_v2_msg = ice_vc_dis_vlan_insertion_v2_msg,
3608};
3609
3610
3611
3612
3613
3614void ice_virtchnl_set_repr_ops(struct ice_vf *vf)
3615{
3616 vf->virtchnl_ops = &ice_virtchnl_repr_ops;
3617}
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627void ice_vc_process_vf_msg(struct ice_pf *pf, struct ice_rq_event_info *event)
3628{
3629 u32 v_opcode = le32_to_cpu(event->desc.cookie_high);
3630 s16 vf_id = le16_to_cpu(event->desc.retval);
3631 const struct ice_virtchnl_ops *ops;
3632 u16 msglen = event->msg_len;
3633 u8 *msg = event->msg_buf;
3634 struct ice_vf *vf = NULL;
3635 struct device *dev;
3636 int err = 0;
3637
3638 dev = ice_pf_to_dev(pf);
3639
3640 vf = ice_get_vf_by_id(pf, vf_id);
3641 if (!vf) {
3642 dev_err(dev, "Unable to locate VF for message from VF ID %d, opcode %d, len %d\n",
3643 vf_id, v_opcode, msglen);
3644 return;
3645 }
3646
3647 mutex_lock(&vf->cfg_lock);
3648
3649
3650 if (test_bit(ICE_VF_STATE_DIS, vf->vf_states)) {
3651 err = -EPERM;
3652 goto error_handler;
3653 }
3654
3655 ops = vf->virtchnl_ops;
3656
3657
3658 err = virtchnl_vc_validate_vf_msg(&vf->vf_ver, v_opcode, msg, msglen);
3659 if (err) {
3660 if (err == VIRTCHNL_STATUS_ERR_PARAM)
3661 err = -EPERM;
3662 else
3663 err = -EINVAL;
3664 }
3665
3666error_handler:
3667 if (err) {
3668 ice_vc_send_msg_to_vf(vf, v_opcode, VIRTCHNL_STATUS_ERR_PARAM,
3669 NULL, 0);
3670 dev_err(dev, "Invalid message from VF %d, opcode %d, len %d, error %d\n",
3671 vf_id, v_opcode, msglen, err);
3672 goto finish;
3673 }
3674
3675 if (!ice_vc_is_opcode_allowed(vf, v_opcode)) {
3676 ice_vc_send_msg_to_vf(vf, v_opcode,
3677 VIRTCHNL_STATUS_ERR_NOT_SUPPORTED, NULL,
3678 0);
3679 goto finish;
3680 }
3681
3682 switch (v_opcode) {
3683 case VIRTCHNL_OP_VERSION:
3684 err = ops->get_ver_msg(vf, msg);
3685 break;
3686 case VIRTCHNL_OP_GET_VF_RESOURCES:
3687 err = ops->get_vf_res_msg(vf, msg);
3688 if (ice_vf_init_vlan_stripping(vf))
3689 dev_dbg(dev, "Failed to initialize VLAN stripping for VF %d\n",
3690 vf->vf_id);
3691 ice_vc_notify_vf_link_state(vf);
3692 break;
3693 case VIRTCHNL_OP_RESET_VF:
3694 ops->reset_vf(vf);
3695 break;
3696 case VIRTCHNL_OP_ADD_ETH_ADDR:
3697 err = ops->add_mac_addr_msg(vf, msg);
3698 break;
3699 case VIRTCHNL_OP_DEL_ETH_ADDR:
3700 err = ops->del_mac_addr_msg(vf, msg);
3701 break;
3702 case VIRTCHNL_OP_CONFIG_VSI_QUEUES:
3703 err = ops->cfg_qs_msg(vf, msg);
3704 break;
3705 case VIRTCHNL_OP_ENABLE_QUEUES:
3706 err = ops->ena_qs_msg(vf, msg);
3707 ice_vc_notify_vf_link_state(vf);
3708 break;
3709 case VIRTCHNL_OP_DISABLE_QUEUES:
3710 err = ops->dis_qs_msg(vf, msg);
3711 break;
3712 case VIRTCHNL_OP_REQUEST_QUEUES:
3713 err = ops->request_qs_msg(vf, msg);
3714 break;
3715 case VIRTCHNL_OP_CONFIG_IRQ_MAP:
3716 err = ops->cfg_irq_map_msg(vf, msg);
3717 break;
3718 case VIRTCHNL_OP_CONFIG_RSS_KEY:
3719 err = ops->config_rss_key(vf, msg);
3720 break;
3721 case VIRTCHNL_OP_CONFIG_RSS_LUT:
3722 err = ops->config_rss_lut(vf, msg);
3723 break;
3724 case VIRTCHNL_OP_GET_STATS:
3725 err = ops->get_stats_msg(vf, msg);
3726 break;
3727 case VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE:
3728 err = ops->cfg_promiscuous_mode_msg(vf, msg);
3729 break;
3730 case VIRTCHNL_OP_ADD_VLAN:
3731 err = ops->add_vlan_msg(vf, msg);
3732 break;
3733 case VIRTCHNL_OP_DEL_VLAN:
3734 err = ops->remove_vlan_msg(vf, msg);
3735 break;
3736 case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING:
3737 err = ops->ena_vlan_stripping(vf);
3738 break;
3739 case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING:
3740 err = ops->dis_vlan_stripping(vf);
3741 break;
3742 case VIRTCHNL_OP_ADD_FDIR_FILTER:
3743 err = ops->add_fdir_fltr_msg(vf, msg);
3744 break;
3745 case VIRTCHNL_OP_DEL_FDIR_FILTER:
3746 err = ops->del_fdir_fltr_msg(vf, msg);
3747 break;
3748 case VIRTCHNL_OP_ADD_RSS_CFG:
3749 err = ops->handle_rss_cfg_msg(vf, msg, true);
3750 break;
3751 case VIRTCHNL_OP_DEL_RSS_CFG:
3752 err = ops->handle_rss_cfg_msg(vf, msg, false);
3753 break;
3754 case VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS:
3755 err = ops->get_offload_vlan_v2_caps(vf);
3756 break;
3757 case VIRTCHNL_OP_ADD_VLAN_V2:
3758 err = ops->add_vlan_v2_msg(vf, msg);
3759 break;
3760 case VIRTCHNL_OP_DEL_VLAN_V2:
3761 err = ops->remove_vlan_v2_msg(vf, msg);
3762 break;
3763 case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2:
3764 err = ops->ena_vlan_stripping_v2_msg(vf, msg);
3765 break;
3766 case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2:
3767 err = ops->dis_vlan_stripping_v2_msg(vf, msg);
3768 break;
3769 case VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2:
3770 err = ops->ena_vlan_insertion_v2_msg(vf, msg);
3771 break;
3772 case VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2:
3773 err = ops->dis_vlan_insertion_v2_msg(vf, msg);
3774 break;
3775 case VIRTCHNL_OP_UNKNOWN:
3776 default:
3777 dev_err(dev, "Unsupported opcode %d from VF %d\n", v_opcode,
3778 vf_id);
3779 err = ice_vc_send_msg_to_vf(vf, v_opcode,
3780 VIRTCHNL_STATUS_ERR_NOT_SUPPORTED,
3781 NULL, 0);
3782 break;
3783 }
3784 if (err) {
3785
3786
3787
3788 dev_info(dev, "PF failed to honor VF %d, opcode %d, error %d\n",
3789 vf_id, v_opcode, err);
3790 }
3791
3792finish:
3793 mutex_unlock(&vf->cfg_lock);
3794 ice_put_vf(vf);
3795}
3796