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