Skip to content

Commit af41b18

Browse files
Michal Swiatkowskianguy11
authored andcommitted
ice: track port representors in xarray
Instead of assuming that each VF has pointer to port representor save it in xarray. It will allow adding port representor for other device types. Drop reference to VF where it is use only to get port representor. Get it from xarray instead. The functions will no longer by specific for VF, rename them. Track id assigned by xarray in port representor structure. The id can't be used as ::q_id, because it is fixed during port representor lifetime. ::q_id can change after adding / removing other port representors. Side effect of removing VF pointer is that we are losing VF MAC information used in unrolling. Store it in port representor as parent MAC. Reviewed-by: Piotr Raczynski <[email protected]> Reviewed-by: Wojciech Drewek <[email protected]> Signed-off-by: Michal Swiatkowski <[email protected]> Tested-by: Sujai Buvaneswaran <[email protected]> Signed-off-by: Tony Nguyen <[email protected]>
1 parent 5c53c12 commit af41b18

File tree

5 files changed

+94
-101
lines changed

5 files changed

+94
-101
lines changed

drivers/net/ethernet/intel/ice/ice.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,7 @@ struct ice_eswitch {
526526
struct ice_vsi *control_vsi;
527527
struct ice_vsi *uplink_vsi;
528528
struct ice_esw_br_offloads *br_offloads;
529+
struct xarray reprs;
529530
bool is_running;
530531
};
531532

drivers/net/ethernet/intel/ice/ice_eswitch.c

Lines changed: 81 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@
1111
#include "ice_tc_lib.h"
1212

1313
/**
14-
* ice_eswitch_add_vf_sp_rule - add adv rule with VF's VSI index
14+
* ice_eswitch_add_sp_rule - add adv rule with device's VSI index
1515
* @pf: pointer to PF struct
16-
* @vf: pointer to VF struct
16+
* @repr: pointer to the repr struct
1717
*
1818
* This function adds advanced rule that forwards packets with
19-
* VF's VSI index to the corresponding eswitch ctrl VSI queue.
19+
* device's VSI index to the corresponding eswitch ctrl VSI queue.
2020
*/
2121
static int
22-
ice_eswitch_add_vf_sp_rule(struct ice_pf *pf, struct ice_vf *vf)
22+
ice_eswitch_add_sp_rule(struct ice_pf *pf, struct ice_repr *repr)
2323
{
2424
struct ice_vsi *ctrl_vsi = pf->eswitch.control_vsi;
2525
struct ice_adv_rule_info rule_info = { 0 };
@@ -38,35 +38,32 @@ ice_eswitch_add_vf_sp_rule(struct ice_pf *pf, struct ice_vf *vf)
3838
rule_info.sw_act.vsi_handle = ctrl_vsi->idx;
3939
rule_info.sw_act.fltr_act = ICE_FWD_TO_Q;
4040
rule_info.sw_act.fwd_id.q_id = hw->func_caps.common_cap.rxq_first_id +
41-
ctrl_vsi->rxq_map[vf->repr->q_id];
41+
ctrl_vsi->rxq_map[repr->q_id];
4242
rule_info.flags_info.act |= ICE_SINGLE_ACT_LB_ENABLE;
4343
rule_info.flags_info.act_valid = true;
4444
rule_info.tun_type = ICE_SW_TUN_AND_NON_TUN;
45-
rule_info.src_vsi = vf->lan_vsi_idx;
45+
rule_info.src_vsi = repr->src_vsi->idx;
4646

4747
err = ice_add_adv_rule(hw, list, lkups_cnt, &rule_info,
48-
&vf->repr->sp_rule);
48+
&repr->sp_rule);
4949
if (err)
50-
dev_err(ice_pf_to_dev(pf), "Unable to add VF slow-path rule in switchdev mode for VF %d",
51-
vf->vf_id);
50+
dev_err(ice_pf_to_dev(pf), "Unable to add slow-path rule in switchdev mode");
5251

5352
kfree(list);
5453
return err;
5554
}
5655

5756
/**
58-
* ice_eswitch_del_vf_sp_rule - delete adv rule with VF's VSI index
59-
* @vf: pointer to the VF struct
57+
* ice_eswitch_del_sp_rule - delete adv rule with device's VSI index
58+
* @pf: pointer to the PF struct
59+
* @repr: pointer to the repr struct
6060
*
61-
* Delete the advanced rule that was used to forward packets with the VF's VSI
62-
* index to the corresponding eswitch ctrl VSI queue.
61+
* Delete the advanced rule that was used to forward packets with the device's
62+
* VSI index to the corresponding eswitch ctrl VSI queue.
6363
*/
64-
static void ice_eswitch_del_vf_sp_rule(struct ice_vf *vf)
64+
static void ice_eswitch_del_sp_rule(struct ice_pf *pf, struct ice_repr *repr)
6565
{
66-
if (!vf->repr)
67-
return;
68-
69-
ice_rem_adv_rule_by_id(&vf->pf->hw, &vf->repr->sp_rule);
66+
ice_rem_adv_rule_by_id(&pf->hw, &repr->sp_rule);
7067
}
7168

7269
/**
@@ -193,26 +190,24 @@ static void ice_eswitch_remap_rings_to_vectors(struct ice_pf *pf)
193190
static void
194191
ice_eswitch_release_reprs(struct ice_pf *pf)
195192
{
196-
struct ice_vf *vf;
197-
unsigned int bkt;
198-
199-
lockdep_assert_held(&pf->vfs.table_lock);
193+
struct ice_repr *repr;
194+
unsigned long id;
200195

201-
ice_for_each_vf(pf, bkt, vf) {
202-
struct ice_vsi *vsi = vf->repr->src_vsi;
196+
xa_for_each(&pf->eswitch.reprs, id, repr) {
197+
struct ice_vsi *vsi = repr->src_vsi;
203198

204-
/* Skip VFs that aren't configured */
205-
if (!vf->repr->dst)
199+
/* Skip representors that aren't configured */
200+
if (!repr->dst)
206201
continue;
207202

208203
ice_vsi_update_security(vsi, ice_vsi_ctx_set_antispoof);
209-
metadata_dst_free(vf->repr->dst);
210-
vf->repr->dst = NULL;
211-
ice_eswitch_del_vf_sp_rule(vf);
212-
ice_fltr_add_mac_and_broadcast(vsi, vf->hw_lan_addr,
204+
metadata_dst_free(repr->dst);
205+
repr->dst = NULL;
206+
ice_eswitch_del_sp_rule(pf, repr);
207+
ice_fltr_add_mac_and_broadcast(vsi, repr->parent_mac,
213208
ICE_FWD_TO_VSI);
214209

215-
netif_napi_del(&vf->repr->q_vector->napi);
210+
netif_napi_del(&repr->q_vector->napi);
216211
}
217212
}
218213

@@ -223,56 +218,53 @@ ice_eswitch_release_reprs(struct ice_pf *pf)
223218
static int ice_eswitch_setup_reprs(struct ice_pf *pf)
224219
{
225220
struct ice_vsi *ctrl_vsi = pf->eswitch.control_vsi;
226-
struct ice_vf *vf;
227-
unsigned int bkt;
228-
229-
lockdep_assert_held(&pf->vfs.table_lock);
221+
struct ice_repr *repr;
222+
unsigned long id;
230223

231-
ice_for_each_vf(pf, bkt, vf) {
232-
struct ice_vsi *vsi = vf->repr->src_vsi;
224+
xa_for_each(&pf->eswitch.reprs, id, repr) {
225+
struct ice_vsi *vsi = repr->src_vsi;
233226

234227
ice_remove_vsi_fltr(&pf->hw, vsi->idx);
235-
vf->repr->dst = metadata_dst_alloc(0, METADATA_HW_PORT_MUX,
236-
GFP_KERNEL);
237-
if (!vf->repr->dst) {
238-
ice_fltr_add_mac_and_broadcast(vsi, vf->hw_lan_addr,
228+
repr->dst = metadata_dst_alloc(0, METADATA_HW_PORT_MUX,
229+
GFP_KERNEL);
230+
if (!repr->dst) {
231+
ice_fltr_add_mac_and_broadcast(vsi, repr->parent_mac,
239232
ICE_FWD_TO_VSI);
240233
goto err;
241234
}
242235

243-
if (ice_eswitch_add_vf_sp_rule(pf, vf)) {
244-
ice_fltr_add_mac_and_broadcast(vsi, vf->hw_lan_addr,
236+
if (ice_eswitch_add_sp_rule(pf, repr)) {
237+
ice_fltr_add_mac_and_broadcast(vsi, repr->parent_mac,
245238
ICE_FWD_TO_VSI);
246239
goto err;
247240
}
248241

249242
if (ice_vsi_update_security(vsi, ice_vsi_ctx_clear_antispoof)) {
250-
ice_fltr_add_mac_and_broadcast(vsi, vf->hw_lan_addr,
243+
ice_fltr_add_mac_and_broadcast(vsi, repr->parent_mac,
251244
ICE_FWD_TO_VSI);
252-
ice_eswitch_del_vf_sp_rule(vf);
253-
metadata_dst_free(vf->repr->dst);
254-
vf->repr->dst = NULL;
245+
ice_eswitch_del_sp_rule(pf, repr);
246+
metadata_dst_free(repr->dst);
247+
repr->dst = NULL;
255248
goto err;
256249
}
257250

258251
if (ice_vsi_add_vlan_zero(vsi)) {
259-
ice_fltr_add_mac_and_broadcast(vsi, vf->hw_lan_addr,
252+
ice_fltr_add_mac_and_broadcast(vsi, repr->parent_mac,
260253
ICE_FWD_TO_VSI);
261-
ice_eswitch_del_vf_sp_rule(vf);
262-
metadata_dst_free(vf->repr->dst);
263-
vf->repr->dst = NULL;
254+
ice_eswitch_del_sp_rule(pf, repr);
255+
metadata_dst_free(repr->dst);
256+
repr->dst = NULL;
264257
ice_vsi_update_security(vsi, ice_vsi_ctx_set_antispoof);
265258
goto err;
266259
}
267260

268-
netif_napi_add(vf->repr->netdev, &vf->repr->q_vector->napi,
261+
netif_napi_add(repr->netdev, &repr->q_vector->napi,
269262
ice_napi_poll);
270263

271-
netif_keep_dst(vf->repr->netdev);
264+
netif_keep_dst(repr->netdev);
272265
}
273266

274-
ice_for_each_vf(pf, bkt, vf) {
275-
struct ice_repr *repr = vf->repr;
267+
xa_for_each(&pf->eswitch.reprs, id, repr) {
276268
struct ice_vsi *vsi = repr->src_vsi;
277269
struct metadata_dst *dst;
278270

@@ -291,7 +283,7 @@ static int ice_eswitch_setup_reprs(struct ice_pf *pf)
291283
}
292284

293285
/**
294-
* ice_eswitch_update_repr - reconfigure VF port representor
286+
* ice_eswitch_update_repr - reconfigure port representor
295287
* @vsi: VF VSI for which port representor is configured
296288
*/
297289
void ice_eswitch_update_repr(struct ice_vsi *vsi)
@@ -420,47 +412,41 @@ ice_eswitch_vsi_setup(struct ice_pf *pf, struct ice_port_info *pi)
420412

421413
/**
422414
* ice_eswitch_napi_del - remove NAPI handle for all port representors
423-
* @pf: pointer to PF structure
415+
* @reprs: xarray of reprs
424416
*/
425-
static void ice_eswitch_napi_del(struct ice_pf *pf)
417+
static void ice_eswitch_napi_del(struct xarray *reprs)
426418
{
427-
struct ice_vf *vf;
428-
unsigned int bkt;
429-
430-
lockdep_assert_held(&pf->vfs.table_lock);
419+
struct ice_repr *repr;
420+
unsigned long id;
431421

432-
ice_for_each_vf(pf, bkt, vf)
433-
netif_napi_del(&vf->repr->q_vector->napi);
422+
xa_for_each(reprs, id, repr)
423+
netif_napi_del(&repr->q_vector->napi);
434424
}
435425

436426
/**
437427
* ice_eswitch_napi_enable - enable NAPI for all port representors
438-
* @pf: pointer to PF structure
428+
* @reprs: xarray of reprs
439429
*/
440-
static void ice_eswitch_napi_enable(struct ice_pf *pf)
430+
static void ice_eswitch_napi_enable(struct xarray *reprs)
441431
{
442-
struct ice_vf *vf;
443-
unsigned int bkt;
444-
445-
lockdep_assert_held(&pf->vfs.table_lock);
432+
struct ice_repr *repr;
433+
unsigned long id;
446434

447-
ice_for_each_vf(pf, bkt, vf)
448-
napi_enable(&vf->repr->q_vector->napi);
435+
xa_for_each(reprs, id, repr)
436+
napi_enable(&repr->q_vector->napi);
449437
}
450438

451439
/**
452440
* ice_eswitch_napi_disable - disable NAPI for all port representors
453-
* @pf: pointer to PF structure
441+
* @reprs: xarray of reprs
454442
*/
455-
static void ice_eswitch_napi_disable(struct ice_pf *pf)
443+
static void ice_eswitch_napi_disable(struct xarray *reprs)
456444
{
457-
struct ice_vf *vf;
458-
unsigned int bkt;
459-
460-
lockdep_assert_held(&pf->vfs.table_lock);
445+
struct ice_repr *repr;
446+
unsigned long id;
461447

462-
ice_for_each_vf(pf, bkt, vf)
463-
napi_disable(&vf->repr->q_vector->napi);
448+
xa_for_each(reprs, id, repr)
449+
napi_disable(&repr->q_vector->napi);
464450
}
465451

466452
/**
@@ -505,7 +491,7 @@ static int ice_eswitch_enable_switchdev(struct ice_pf *pf)
505491
if (ice_eswitch_br_offloads_init(pf))
506492
goto err_br_offloads;
507493

508-
ice_eswitch_napi_enable(pf);
494+
ice_eswitch_napi_enable(&pf->eswitch.reprs);
509495

510496
return 0;
511497

@@ -528,7 +514,7 @@ static void ice_eswitch_disable_switchdev(struct ice_pf *pf)
528514
{
529515
struct ice_vsi *ctrl_vsi = pf->eswitch.control_vsi;
530516

531-
ice_eswitch_napi_disable(pf);
517+
ice_eswitch_napi_disable(&pf->eswitch.reprs);
532518
ice_eswitch_br_offloads_deinit(pf);
533519
ice_eswitch_release_env(pf);
534520
ice_eswitch_release_reprs(pf);
@@ -561,6 +547,7 @@ ice_eswitch_mode_set(struct devlink *devlink, u16 mode,
561547
case DEVLINK_ESWITCH_MODE_LEGACY:
562548
dev_info(ice_pf_to_dev(pf), "PF %d changed eswitch mode to legacy",
563549
pf->hw.pf_id);
550+
xa_destroy(&pf->eswitch.reprs);
564551
NL_SET_ERR_MSG_MOD(extack, "Changed eswitch mode to legacy");
565552
break;
566553
case DEVLINK_ESWITCH_MODE_SWITCHDEV:
@@ -573,6 +560,7 @@ ice_eswitch_mode_set(struct devlink *devlink, u16 mode,
573560

574561
dev_info(ice_pf_to_dev(pf), "PF %d changed eswitch mode to switchdev",
575562
pf->hw.pf_id);
563+
xa_init_flags(&pf->eswitch.reprs, XA_FLAGS_ALLOC);
576564
NL_SET_ERR_MSG_MOD(extack, "Changed eswitch mode to switchdev");
577565
break;
578566
}
@@ -649,18 +637,14 @@ int ice_eswitch_configure(struct ice_pf *pf)
649637
*/
650638
static void ice_eswitch_start_all_tx_queues(struct ice_pf *pf)
651639
{
652-
struct ice_vf *vf;
653-
unsigned int bkt;
654-
655-
lockdep_assert_held(&pf->vfs.table_lock);
640+
struct ice_repr *repr;
641+
unsigned long id;
656642

657643
if (test_bit(ICE_DOWN, pf->state))
658644
return;
659645

660-
ice_for_each_vf(pf, bkt, vf) {
661-
if (vf->repr)
662-
ice_repr_start_tx_queues(vf->repr);
663-
}
646+
xa_for_each(&pf->eswitch.reprs, id, repr)
647+
ice_repr_start_tx_queues(repr);
664648
}
665649

666650
/**
@@ -669,18 +653,14 @@ static void ice_eswitch_start_all_tx_queues(struct ice_pf *pf)
669653
*/
670654
void ice_eswitch_stop_all_tx_queues(struct ice_pf *pf)
671655
{
672-
struct ice_vf *vf;
673-
unsigned int bkt;
674-
675-
lockdep_assert_held(&pf->vfs.table_lock);
656+
struct ice_repr *repr;
657+
unsigned long id;
676658

677659
if (test_bit(ICE_DOWN, pf->state))
678660
return;
679661

680-
ice_for_each_vf(pf, bkt, vf) {
681-
if (vf->repr)
682-
ice_repr_stop_tx_queues(vf->repr);
683-
}
662+
xa_for_each(&pf->eswitch.reprs, id, repr)
663+
ice_repr_stop_tx_queues(repr);
684664
}
685665

686666
/**
@@ -692,8 +672,8 @@ int ice_eswitch_rebuild(struct ice_pf *pf)
692672
struct ice_vsi *ctrl_vsi = pf->eswitch.control_vsi;
693673
int status;
694674

695-
ice_eswitch_napi_disable(pf);
696-
ice_eswitch_napi_del(pf);
675+
ice_eswitch_napi_disable(&pf->eswitch.reprs);
676+
ice_eswitch_napi_del(&pf->eswitch.reprs);
697677

698678
status = ice_eswitch_setup_env(pf);
699679
if (status)
@@ -711,7 +691,7 @@ int ice_eswitch_rebuild(struct ice_pf *pf)
711691
if (status)
712692
return status;
713693

714-
ice_eswitch_napi_enable(pf);
694+
ice_eswitch_napi_enable(&pf->eswitch.reprs);
715695
ice_eswitch_start_all_tx_queues(pf);
716696

717697
return 0;

drivers/net/ethernet/intel/ice/ice_main.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4702,6 +4702,8 @@ static void ice_deinit_features(struct ice_pf *pf)
47024702
ice_ptp_release(pf);
47034703
if (test_bit(ICE_FLAG_DPLL, pf->flags))
47044704
ice_dpll_deinit(pf);
4705+
if (pf->eswitch_mode == DEVLINK_ESWITCH_MODE_SWITCHDEV)
4706+
xa_destroy(&pf->eswitch.reprs);
47054707
}
47064708

47074709
static void ice_init_wakeup(struct ice_pf *pf)

0 commit comments

Comments
 (0)