xref: /openbmc/linux/drivers/net/ethernet/intel/ice/ice_eswitch.c (revision fa5d824ce5dd8306c66f45c34fd78536e6ce2488)
1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (C) 2019-2021, Intel Corporation. */
3 
4 #include "ice.h"
5 #include "ice_lib.h"
6 #include "ice_eswitch.h"
7 #include "ice_fltr.h"
8 #include "ice_repr.h"
9 #include "ice_devlink.h"
10 #include "ice_tc_lib.h"
11 
12 /**
13  * ice_eswitch_add_vf_mac_rule - add adv rule with VF's MAC
14  * @pf: pointer to PF struct
15  * @vf: pointer to VF struct
16  * @mac: VF's MAC address
17  *
18  * This function adds advanced rule that forwards packets with
19  * VF's MAC address (src MAC) to the corresponding switchdev ctrl VSI queue.
20  */
21 int
22 ice_eswitch_add_vf_mac_rule(struct ice_pf *pf, struct ice_vf *vf, const u8 *mac)
23 {
24 	struct ice_vsi *ctrl_vsi = pf->switchdev.control_vsi;
25 	struct ice_adv_rule_info rule_info = { 0 };
26 	struct ice_adv_lkup_elem *list;
27 	struct ice_hw *hw = &pf->hw;
28 	const u16 lkups_cnt = 1;
29 	int err;
30 
31 	list = kcalloc(lkups_cnt, sizeof(*list), GFP_ATOMIC);
32 	if (!list)
33 		return -ENOMEM;
34 
35 	list[0].type = ICE_MAC_OFOS;
36 	ether_addr_copy(list[0].h_u.eth_hdr.src_addr, mac);
37 	eth_broadcast_addr(list[0].m_u.eth_hdr.src_addr);
38 
39 	rule_info.sw_act.flag |= ICE_FLTR_TX;
40 	rule_info.sw_act.vsi_handle = ctrl_vsi->idx;
41 	rule_info.sw_act.fltr_act = ICE_FWD_TO_Q;
42 	rule_info.rx = false;
43 	rule_info.sw_act.fwd_id.q_id = hw->func_caps.common_cap.rxq_first_id +
44 				       ctrl_vsi->rxq_map[vf->vf_id];
45 	rule_info.flags_info.act |= ICE_SINGLE_ACT_LB_ENABLE;
46 	rule_info.flags_info.act_valid = true;
47 
48 	err = ice_add_adv_rule(hw, list, lkups_cnt, &rule_info,
49 			       vf->repr->mac_rule);
50 	if (err)
51 		dev_err(ice_pf_to_dev(pf), "Unable to add VF mac rule in switchdev mode for VF %d",
52 			vf->vf_id);
53 	else
54 		vf->repr->rule_added = true;
55 
56 	kfree(list);
57 	return err;
58 }
59 
60 /**
61  * ice_eswitch_replay_vf_mac_rule - replay adv rule with VF's MAC
62  * @vf: pointer to vF struct
63  *
64  * This function replays VF's MAC rule after reset.
65  */
66 void ice_eswitch_replay_vf_mac_rule(struct ice_vf *vf)
67 {
68 	int err;
69 
70 	if (!ice_is_switchdev_running(vf->pf))
71 		return;
72 
73 	if (is_valid_ether_addr(vf->hw_lan_addr.addr)) {
74 		err = ice_eswitch_add_vf_mac_rule(vf->pf, vf,
75 						  vf->hw_lan_addr.addr);
76 		if (err) {
77 			dev_err(ice_pf_to_dev(vf->pf), "Failed to add MAC %pM for VF %d\n, error %d\n",
78 				vf->hw_lan_addr.addr, vf->vf_id, err);
79 			return;
80 		}
81 		vf->num_mac++;
82 
83 		ether_addr_copy(vf->dev_lan_addr.addr, vf->hw_lan_addr.addr);
84 	}
85 }
86 
87 /**
88  * ice_eswitch_del_vf_mac_rule - delete adv rule with VF's MAC
89  * @vf: pointer to the VF struct
90  *
91  * Delete the advanced rule that was used to forward packets with the VF's MAC
92  * address (src MAC) to the corresponding switchdev ctrl VSI queue.
93  */
94 void ice_eswitch_del_vf_mac_rule(struct ice_vf *vf)
95 {
96 	if (!ice_is_switchdev_running(vf->pf))
97 		return;
98 
99 	if (!vf->repr->rule_added)
100 		return;
101 
102 	ice_rem_adv_rule_by_id(&vf->pf->hw, vf->repr->mac_rule);
103 	vf->repr->rule_added = false;
104 }
105 
106 /**
107  * ice_eswitch_setup_env - configure switchdev HW filters
108  * @pf: pointer to PF struct
109  *
110  * This function adds HW filters configuration specific for switchdev
111  * mode.
112  */
113 static int ice_eswitch_setup_env(struct ice_pf *pf)
114 {
115 	struct ice_vsi *uplink_vsi = pf->switchdev.uplink_vsi;
116 	struct net_device *uplink_netdev = uplink_vsi->netdev;
117 	struct ice_vsi *ctrl_vsi = pf->switchdev.control_vsi;
118 	struct ice_vsi_vlan_ops *vlan_ops;
119 	bool rule_added = false;
120 
121 	vlan_ops = ice_get_compat_vsi_vlan_ops(ctrl_vsi);
122 	if (vlan_ops->dis_stripping(ctrl_vsi))
123 		return -ENODEV;
124 
125 	ice_remove_vsi_fltr(&pf->hw, uplink_vsi->idx);
126 
127 	netif_addr_lock_bh(uplink_netdev);
128 	__dev_uc_unsync(uplink_netdev, NULL);
129 	__dev_mc_unsync(uplink_netdev, NULL);
130 	netif_addr_unlock_bh(uplink_netdev);
131 
132 	if (ice_vsi_add_vlan_zero(uplink_vsi))
133 		goto err_def_rx;
134 
135 	if (!ice_is_dflt_vsi_in_use(uplink_vsi->vsw)) {
136 		if (ice_set_dflt_vsi(uplink_vsi->vsw, uplink_vsi))
137 			goto err_def_rx;
138 		rule_added = true;
139 	}
140 
141 	if (ice_vsi_update_security(uplink_vsi, ice_vsi_ctx_set_allow_override))
142 		goto err_override_uplink;
143 
144 	if (ice_vsi_update_security(ctrl_vsi, ice_vsi_ctx_set_allow_override))
145 		goto err_override_control;
146 
147 	return 0;
148 
149 err_override_control:
150 	ice_vsi_update_security(uplink_vsi, ice_vsi_ctx_clear_allow_override);
151 err_override_uplink:
152 	if (rule_added)
153 		ice_clear_dflt_vsi(uplink_vsi->vsw);
154 err_def_rx:
155 	ice_fltr_add_mac_and_broadcast(uplink_vsi,
156 				       uplink_vsi->port_info->mac.perm_addr,
157 				       ICE_FWD_TO_VSI);
158 	return -ENODEV;
159 }
160 
161 /**
162  * ice_eswitch_remap_rings_to_vectors - reconfigure rings of switchdev ctrl VSI
163  * @pf: pointer to PF struct
164  *
165  * In switchdev number of allocated Tx/Rx rings is equal.
166  *
167  * This function fills q_vectors structures associated with representor and
168  * move each ring pairs to port representor netdevs. Each port representor
169  * will have dedicated 1 Tx/Rx ring pair, so number of rings pair is equal to
170  * number of VFs.
171  */
172 static void ice_eswitch_remap_rings_to_vectors(struct ice_pf *pf)
173 {
174 	struct ice_vsi *vsi = pf->switchdev.control_vsi;
175 	int q_id;
176 
177 	ice_for_each_txq(vsi, q_id) {
178 		struct ice_repr *repr = pf->vf[q_id].repr;
179 		struct ice_q_vector *q_vector = repr->q_vector;
180 		struct ice_tx_ring *tx_ring = vsi->tx_rings[q_id];
181 		struct ice_rx_ring *rx_ring = vsi->rx_rings[q_id];
182 
183 		q_vector->vsi = vsi;
184 		q_vector->reg_idx = vsi->q_vectors[0]->reg_idx;
185 
186 		q_vector->num_ring_tx = 1;
187 		q_vector->tx.tx_ring = tx_ring;
188 		tx_ring->q_vector = q_vector;
189 		tx_ring->next = NULL;
190 		tx_ring->netdev = repr->netdev;
191 		/* In switchdev mode, from OS stack perspective, there is only
192 		 * one queue for given netdev, so it needs to be indexed as 0.
193 		 */
194 		tx_ring->q_index = 0;
195 
196 		q_vector->num_ring_rx = 1;
197 		q_vector->rx.rx_ring = rx_ring;
198 		rx_ring->q_vector = q_vector;
199 		rx_ring->next = NULL;
200 		rx_ring->netdev = repr->netdev;
201 	}
202 }
203 
204 /**
205  * ice_eswitch_setup_reprs - configure port reprs to run in switchdev mode
206  * @pf: pointer to PF struct
207  */
208 static int ice_eswitch_setup_reprs(struct ice_pf *pf)
209 {
210 	struct ice_vsi *ctrl_vsi = pf->switchdev.control_vsi;
211 	int max_vsi_num = 0;
212 	int i;
213 
214 	ice_for_each_vf(pf, i) {
215 		struct ice_vsi *vsi = pf->vf[i].repr->src_vsi;
216 		struct ice_vf *vf = &pf->vf[i];
217 
218 		ice_remove_vsi_fltr(&pf->hw, vsi->idx);
219 		vf->repr->dst = metadata_dst_alloc(0, METADATA_HW_PORT_MUX,
220 						   GFP_KERNEL);
221 		if (!vf->repr->dst) {
222 			ice_fltr_add_mac_and_broadcast(vsi,
223 						       vf->hw_lan_addr.addr,
224 						       ICE_FWD_TO_VSI);
225 			goto err;
226 		}
227 
228 		if (ice_vsi_update_security(vsi, ice_vsi_ctx_clear_antispoof)) {
229 			ice_fltr_add_mac_and_broadcast(vsi,
230 						       vf->hw_lan_addr.addr,
231 						       ICE_FWD_TO_VSI);
232 			metadata_dst_free(vf->repr->dst);
233 			goto err;
234 		}
235 
236 		if (ice_vsi_add_vlan_zero(vsi)) {
237 			ice_fltr_add_mac_and_broadcast(vsi,
238 						       vf->hw_lan_addr.addr,
239 						       ICE_FWD_TO_VSI);
240 			metadata_dst_free(vf->repr->dst);
241 			ice_vsi_update_security(vsi, ice_vsi_ctx_set_antispoof);
242 			goto err;
243 		}
244 
245 		if (max_vsi_num < vsi->vsi_num)
246 			max_vsi_num = vsi->vsi_num;
247 
248 		netif_napi_add(vf->repr->netdev, &vf->repr->q_vector->napi, ice_napi_poll,
249 			       NAPI_POLL_WEIGHT);
250 
251 		netif_keep_dst(vf->repr->netdev);
252 	}
253 
254 	ice_for_each_vf(pf, i) {
255 		struct ice_repr *repr = pf->vf[i].repr;
256 		struct ice_vsi *vsi = repr->src_vsi;
257 		struct metadata_dst *dst;
258 
259 		dst = repr->dst;
260 		dst->u.port_info.port_id = vsi->vsi_num;
261 		dst->u.port_info.lower_dev = repr->netdev;
262 		ice_repr_set_traffic_vsi(repr, ctrl_vsi);
263 	}
264 
265 	return 0;
266 
267 err:
268 	for (i = i - 1; i >= 0; i--) {
269 		struct ice_vsi *vsi = pf->vf[i].repr->src_vsi;
270 		struct ice_vf *vf = &pf->vf[i];
271 
272 		ice_vsi_update_security(vsi, ice_vsi_ctx_set_antispoof);
273 		metadata_dst_free(vf->repr->dst);
274 		ice_fltr_add_mac_and_broadcast(vsi, vf->hw_lan_addr.addr,
275 					       ICE_FWD_TO_VSI);
276 	}
277 
278 	return -ENODEV;
279 }
280 
281 /**
282  * ice_eswitch_release_reprs - clear PR VSIs configuration
283  * @pf: poiner to PF struct
284  * @ctrl_vsi: pointer to switchdev control VSI
285  */
286 static void
287 ice_eswitch_release_reprs(struct ice_pf *pf, struct ice_vsi *ctrl_vsi)
288 {
289 	int i;
290 
291 	ice_for_each_vf(pf, i) {
292 		struct ice_vsi *vsi = pf->vf[i].repr->src_vsi;
293 		struct ice_vf *vf = &pf->vf[i];
294 
295 		ice_vsi_update_security(vsi, ice_vsi_ctx_set_antispoof);
296 		metadata_dst_free(vf->repr->dst);
297 		ice_fltr_add_mac_and_broadcast(vsi, vf->hw_lan_addr.addr,
298 					       ICE_FWD_TO_VSI);
299 
300 		netif_napi_del(&vf->repr->q_vector->napi);
301 	}
302 }
303 
304 /**
305  * ice_eswitch_update_repr - reconfigure VF port representor
306  * @vsi: VF VSI for which port representor is configured
307  */
308 void ice_eswitch_update_repr(struct ice_vsi *vsi)
309 {
310 	struct ice_pf *pf = vsi->back;
311 	struct ice_repr *repr;
312 	struct ice_vf *vf;
313 	int ret;
314 
315 	if (!ice_is_switchdev_running(pf))
316 		return;
317 
318 	vf = &pf->vf[vsi->vf_id];
319 	repr = vf->repr;
320 	repr->src_vsi = vsi;
321 	repr->dst->u.port_info.port_id = vsi->vsi_num;
322 
323 	ret = ice_vsi_update_security(vsi, ice_vsi_ctx_clear_antispoof);
324 	if (ret) {
325 		ice_fltr_add_mac_and_broadcast(vsi, vf->hw_lan_addr.addr, ICE_FWD_TO_VSI);
326 		dev_err(ice_pf_to_dev(pf), "Failed to update VF %d port representor", vsi->vf_id);
327 	}
328 }
329 
330 /**
331  * ice_eswitch_port_start_xmit - callback for packets transmit
332  * @skb: send buffer
333  * @netdev: network interface device structure
334  *
335  * Returns NETDEV_TX_OK if sent, else an error code
336  */
337 netdev_tx_t
338 ice_eswitch_port_start_xmit(struct sk_buff *skb, struct net_device *netdev)
339 {
340 	struct ice_netdev_priv *np;
341 	struct ice_repr *repr;
342 	struct ice_vsi *vsi;
343 
344 	np = netdev_priv(netdev);
345 	vsi = np->vsi;
346 
347 	if (ice_is_reset_in_progress(vsi->back->state))
348 		return NETDEV_TX_BUSY;
349 
350 	repr = ice_netdev_to_repr(netdev);
351 	skb_dst_drop(skb);
352 	dst_hold((struct dst_entry *)repr->dst);
353 	skb_dst_set(skb, (struct dst_entry *)repr->dst);
354 	skb->queue_mapping = repr->vf->vf_id;
355 
356 	return ice_start_xmit(skb, netdev);
357 }
358 
359 /**
360  * ice_eswitch_set_target_vsi - set switchdev context in Tx context descriptor
361  * @skb: pointer to send buffer
362  * @off: pointer to offload struct
363  */
364 void
365 ice_eswitch_set_target_vsi(struct sk_buff *skb,
366 			   struct ice_tx_offload_params *off)
367 {
368 	struct metadata_dst *dst = skb_metadata_dst(skb);
369 	u64 cd_cmd, dst_vsi;
370 
371 	if (!dst) {
372 		cd_cmd = ICE_TX_CTX_DESC_SWTCH_UPLINK << ICE_TXD_CTX_QW1_CMD_S;
373 		off->cd_qw1 |= (cd_cmd | ICE_TX_DESC_DTYPE_CTX);
374 	} else {
375 		cd_cmd = ICE_TX_CTX_DESC_SWTCH_VSI << ICE_TXD_CTX_QW1_CMD_S;
376 		dst_vsi = ((u64)dst->u.port_info.port_id <<
377 			   ICE_TXD_CTX_QW1_VSI_S) & ICE_TXD_CTX_QW1_VSI_M;
378 		off->cd_qw1 = cd_cmd | dst_vsi | ICE_TX_DESC_DTYPE_CTX;
379 	}
380 }
381 
382 /**
383  * ice_eswitch_release_env - clear switchdev HW filters
384  * @pf: pointer to PF struct
385  *
386  * This function removes HW filters configuration specific for switchdev
387  * mode and restores default legacy mode settings.
388  */
389 static void ice_eswitch_release_env(struct ice_pf *pf)
390 {
391 	struct ice_vsi *uplink_vsi = pf->switchdev.uplink_vsi;
392 	struct ice_vsi *ctrl_vsi = pf->switchdev.control_vsi;
393 
394 	ice_vsi_update_security(ctrl_vsi, ice_vsi_ctx_clear_allow_override);
395 	ice_vsi_update_security(uplink_vsi, ice_vsi_ctx_clear_allow_override);
396 	ice_clear_dflt_vsi(uplink_vsi->vsw);
397 	ice_fltr_add_mac_and_broadcast(uplink_vsi,
398 				       uplink_vsi->port_info->mac.perm_addr,
399 				       ICE_FWD_TO_VSI);
400 }
401 
402 /**
403  * ice_eswitch_vsi_setup - configure switchdev control VSI
404  * @pf: pointer to PF structure
405  * @pi: pointer to port_info structure
406  */
407 static struct ice_vsi *
408 ice_eswitch_vsi_setup(struct ice_pf *pf, struct ice_port_info *pi)
409 {
410 	return ice_vsi_setup(pf, pi, ICE_VSI_SWITCHDEV_CTRL, ICE_INVAL_VFID, NULL);
411 }
412 
413 /**
414  * ice_eswitch_napi_del - remove NAPI handle for all port representors
415  * @pf: pointer to PF structure
416  */
417 static void ice_eswitch_napi_del(struct ice_pf *pf)
418 {
419 	int i;
420 
421 	ice_for_each_vf(pf, i)
422 		netif_napi_del(&pf->vf[i].repr->q_vector->napi);
423 }
424 
425 /**
426  * ice_eswitch_napi_enable - enable NAPI for all port representors
427  * @pf: pointer to PF structure
428  */
429 static void ice_eswitch_napi_enable(struct ice_pf *pf)
430 {
431 	int i;
432 
433 	ice_for_each_vf(pf, i)
434 		napi_enable(&pf->vf[i].repr->q_vector->napi);
435 }
436 
437 /**
438  * ice_eswitch_napi_disable - disable NAPI for all port representors
439  * @pf: pointer to PF structure
440  */
441 static void ice_eswitch_napi_disable(struct ice_pf *pf)
442 {
443 	int i;
444 
445 	ice_for_each_vf(pf, i)
446 		napi_disable(&pf->vf[i].repr->q_vector->napi);
447 }
448 
449 /**
450  * ice_eswitch_enable_switchdev - configure eswitch in switchdev mode
451  * @pf: pointer to PF structure
452  */
453 static int ice_eswitch_enable_switchdev(struct ice_pf *pf)
454 {
455 	struct ice_vsi *ctrl_vsi;
456 
457 	pf->switchdev.control_vsi = ice_eswitch_vsi_setup(pf, pf->hw.port_info);
458 	if (!pf->switchdev.control_vsi)
459 		return -ENODEV;
460 
461 	ctrl_vsi = pf->switchdev.control_vsi;
462 	pf->switchdev.uplink_vsi = ice_get_main_vsi(pf);
463 	if (!pf->switchdev.uplink_vsi)
464 		goto err_vsi;
465 
466 	if (ice_eswitch_setup_env(pf))
467 		goto err_vsi;
468 
469 	if (ice_repr_add_for_all_vfs(pf))
470 		goto err_repr_add;
471 
472 	if (ice_eswitch_setup_reprs(pf))
473 		goto err_setup_reprs;
474 
475 	ice_eswitch_remap_rings_to_vectors(pf);
476 
477 	if (ice_vsi_open(ctrl_vsi))
478 		goto err_setup_reprs;
479 
480 	ice_eswitch_napi_enable(pf);
481 
482 	return 0;
483 
484 err_setup_reprs:
485 	ice_repr_rem_from_all_vfs(pf);
486 err_repr_add:
487 	ice_eswitch_release_env(pf);
488 err_vsi:
489 	ice_vsi_release(ctrl_vsi);
490 	return -ENODEV;
491 }
492 
493 /**
494  * ice_eswitch_disable_switchdev - disable switchdev resources
495  * @pf: pointer to PF structure
496  */
497 static void ice_eswitch_disable_switchdev(struct ice_pf *pf)
498 {
499 	struct ice_vsi *ctrl_vsi = pf->switchdev.control_vsi;
500 
501 	ice_eswitch_napi_disable(pf);
502 	ice_eswitch_release_env(pf);
503 	ice_rem_adv_rule_for_vsi(&pf->hw, ctrl_vsi->idx);
504 	ice_eswitch_release_reprs(pf, ctrl_vsi);
505 	ice_vsi_release(ctrl_vsi);
506 	ice_repr_rem_from_all_vfs(pf);
507 }
508 
509 /**
510  * ice_eswitch_mode_set - set new eswitch mode
511  * @devlink: pointer to devlink structure
512  * @mode: eswitch mode to switch to
513  * @extack: pointer to extack structure
514  */
515 int
516 ice_eswitch_mode_set(struct devlink *devlink, u16 mode,
517 		     struct netlink_ext_ack *extack)
518 {
519 	struct ice_pf *pf = devlink_priv(devlink);
520 
521 	if (pf->eswitch_mode == mode)
522 		return 0;
523 
524 	if (pf->num_alloc_vfs) {
525 		dev_info(ice_pf_to_dev(pf), "Changing eswitch mode is allowed only if there is no VFs created");
526 		NL_SET_ERR_MSG_MOD(extack, "Changing eswitch mode is allowed only if there is no VFs created");
527 		return -EOPNOTSUPP;
528 	}
529 
530 	switch (mode) {
531 	case DEVLINK_ESWITCH_MODE_LEGACY:
532 		dev_info(ice_pf_to_dev(pf), "PF %d changed eswitch mode to legacy",
533 			 pf->hw.pf_id);
534 		NL_SET_ERR_MSG_MOD(extack, "Changed eswitch mode to legacy");
535 		break;
536 	case DEVLINK_ESWITCH_MODE_SWITCHDEV:
537 	{
538 		dev_info(ice_pf_to_dev(pf), "PF %d changed eswitch mode to switchdev",
539 			 pf->hw.pf_id);
540 		NL_SET_ERR_MSG_MOD(extack, "Changed eswitch mode to switchdev");
541 		break;
542 	}
543 	default:
544 		NL_SET_ERR_MSG_MOD(extack, "Unknown eswitch mode");
545 		return -EINVAL;
546 	}
547 
548 	pf->eswitch_mode = mode;
549 	return 0;
550 }
551 
552 /**
553  * ice_eswitch_mode_get - get current eswitch mode
554  * @devlink: pointer to devlink structure
555  * @mode: output parameter for current eswitch mode
556  */
557 int ice_eswitch_mode_get(struct devlink *devlink, u16 *mode)
558 {
559 	struct ice_pf *pf = devlink_priv(devlink);
560 
561 	*mode = pf->eswitch_mode;
562 	return 0;
563 }
564 
565 /**
566  * ice_is_eswitch_mode_switchdev - check if eswitch mode is set to switchdev
567  * @pf: pointer to PF structure
568  *
569  * Returns true if eswitch mode is set to DEVLINK_ESWITCH_MODE_SWITCHDEV,
570  * false otherwise.
571  */
572 bool ice_is_eswitch_mode_switchdev(struct ice_pf *pf)
573 {
574 	return pf->eswitch_mode == DEVLINK_ESWITCH_MODE_SWITCHDEV;
575 }
576 
577 /**
578  * ice_eswitch_release - cleanup eswitch
579  * @pf: pointer to PF structure
580  */
581 void ice_eswitch_release(struct ice_pf *pf)
582 {
583 	if (pf->eswitch_mode == DEVLINK_ESWITCH_MODE_LEGACY)
584 		return;
585 
586 	ice_eswitch_disable_switchdev(pf);
587 	pf->switchdev.is_running = false;
588 }
589 
590 /**
591  * ice_eswitch_configure - configure eswitch
592  * @pf: pointer to PF structure
593  */
594 int ice_eswitch_configure(struct ice_pf *pf)
595 {
596 	int status;
597 
598 	if (pf->eswitch_mode == DEVLINK_ESWITCH_MODE_LEGACY || pf->switchdev.is_running)
599 		return 0;
600 
601 	status = ice_eswitch_enable_switchdev(pf);
602 	if (status)
603 		return status;
604 
605 	pf->switchdev.is_running = true;
606 	return 0;
607 }
608 
609 /**
610  * ice_eswitch_start_all_tx_queues - start Tx queues of all port representors
611  * @pf: pointer to PF structure
612  */
613 static void ice_eswitch_start_all_tx_queues(struct ice_pf *pf)
614 {
615 	struct ice_repr *repr;
616 	int i;
617 
618 	if (test_bit(ICE_DOWN, pf->state))
619 		return;
620 
621 	ice_for_each_vf(pf, i) {
622 		repr = pf->vf[i].repr;
623 		if (repr)
624 			ice_repr_start_tx_queues(repr);
625 	}
626 }
627 
628 /**
629  * ice_eswitch_stop_all_tx_queues - stop Tx queues of all port representors
630  * @pf: pointer to PF structure
631  */
632 void ice_eswitch_stop_all_tx_queues(struct ice_pf *pf)
633 {
634 	struct ice_repr *repr;
635 	int i;
636 
637 	if (test_bit(ICE_DOWN, pf->state))
638 		return;
639 
640 	ice_for_each_vf(pf, i) {
641 		repr = pf->vf[i].repr;
642 		if (repr)
643 			ice_repr_stop_tx_queues(repr);
644 	}
645 }
646 
647 /**
648  * ice_eswitch_rebuild - rebuild eswitch
649  * @pf: pointer to PF structure
650  */
651 int ice_eswitch_rebuild(struct ice_pf *pf)
652 {
653 	struct ice_vsi *ctrl_vsi = pf->switchdev.control_vsi;
654 	int status;
655 
656 	ice_eswitch_napi_disable(pf);
657 	ice_eswitch_napi_del(pf);
658 
659 	status = ice_eswitch_setup_env(pf);
660 	if (status)
661 		return status;
662 
663 	status = ice_eswitch_setup_reprs(pf);
664 	if (status)
665 		return status;
666 
667 	ice_eswitch_remap_rings_to_vectors(pf);
668 
669 	ice_replay_tc_fltrs(pf);
670 
671 	status = ice_vsi_open(ctrl_vsi);
672 	if (status)
673 		return status;
674 
675 	ice_eswitch_napi_enable(pf);
676 	ice_eswitch_start_all_tx_queues(pf);
677 
678 	return 0;
679 }
680