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