Skip to content

Commit 415db83

Browse files
Michal Swiatkowskianguy11
authored andcommitted
ice: make representor code generic
Keep the same flow of port representor creation, but instead of general attach function create helpers for specific representor type. Store function pointer for add and remove representor. Type of port representor can be also known based on VSI type, but it is more clean to have it directly saved in port representor structure. Add devlink lock for whole port representor creation and destruction. Reviewed-by: Simon Horman <[email protected]> Reviewed-by: Wojciech Drewek <[email protected]> Signed-off-by: Michal Swiatkowski <[email protected]> Tested-by: Rafal Romanowski <[email protected]> Signed-off-by: Tony Nguyen <[email protected]>
1 parent 8f9b681 commit 415db83

File tree

7 files changed

+121
-76
lines changed

7 files changed

+121
-76
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* @devlink_port: the associated devlink port structure
1515
* @pf: pointer to the PF private structure
1616
* @vsi: the VSI associated with this port
17+
* @repr_id: the representor ID
1718
* @sfnum: the subfunction ID
1819
*
1920
* An instance of a dynamically added devlink port. Each port flavour
@@ -24,6 +25,7 @@ struct ice_dynamic_port {
2425
struct devlink_port devlink_port;
2526
struct ice_pf *pf;
2627
struct ice_vsi *vsi;
28+
unsigned long repr_id;
2729
u32 sfnum;
2830
};
2931

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

Lines changed: 52 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -452,11 +452,9 @@ static void ice_eswitch_start_reprs(struct ice_pf *pf)
452452
ice_eswitch_start_all_tx_queues(pf);
453453
}
454454

455-
int
456-
ice_eswitch_attach(struct ice_pf *pf, struct ice_vf *vf)
455+
static int
456+
ice_eswitch_attach(struct ice_pf *pf, struct ice_repr *repr, unsigned long *id)
457457
{
458-
struct devlink *devlink = priv_to_devlink(pf);
459-
struct ice_repr *repr;
460458
int err;
461459

462460
if (pf->eswitch_mode == DEVLINK_ESWITCH_MODE_LEGACY)
@@ -470,13 +468,9 @@ ice_eswitch_attach(struct ice_pf *pf, struct ice_vf *vf)
470468

471469
ice_eswitch_stop_reprs(pf);
472470

473-
devl_lock(devlink);
474-
repr = ice_repr_add_vf(vf);
475-
devl_unlock(devlink);
476-
if (IS_ERR(repr)) {
477-
err = PTR_ERR(repr);
471+
err = repr->ops.add(repr);
472+
if (err)
478473
goto err_create_repr;
479-
}
480474

481475
err = ice_eswitch_setup_repr(pf, repr);
482476
if (err)
@@ -486,7 +480,7 @@ ice_eswitch_attach(struct ice_pf *pf, struct ice_vf *vf)
486480
if (err)
487481
goto err_xa_alloc;
488482

489-
vf->repr_id = repr->id;
483+
*id = repr->id;
490484

491485
ice_eswitch_start_reprs(pf);
492486

@@ -495,9 +489,7 @@ ice_eswitch_attach(struct ice_pf *pf, struct ice_vf *vf)
495489
err_xa_alloc:
496490
ice_eswitch_release_repr(pf, repr);
497491
err_setup_repr:
498-
devl_lock(devlink);
499-
ice_repr_rem_vf(repr);
500-
devl_unlock(devlink);
492+
repr->ops.rem(repr);
501493
err_create_repr:
502494
if (xa_empty(&pf->eswitch.reprs))
503495
ice_eswitch_disable_switchdev(pf);
@@ -506,25 +498,48 @@ ice_eswitch_attach(struct ice_pf *pf, struct ice_vf *vf)
506498
return err;
507499
}
508500

509-
void ice_eswitch_detach(struct ice_pf *pf, struct ice_vf *vf)
501+
/**
502+
* ice_eswitch_attach_vf - attach VF to a eswitch
503+
* @pf: pointer to PF structure
504+
* @vf: pointer to VF structure to be attached
505+
*
506+
* During attaching port representor for VF is created.
507+
*
508+
* Return: zero on success or an error code on failure.
509+
*/
510+
int ice_eswitch_attach_vf(struct ice_pf *pf, struct ice_vf *vf)
510511
{
511-
struct ice_repr *repr = xa_load(&pf->eswitch.reprs, vf->repr_id);
512+
struct ice_repr *repr = ice_repr_create_vf(vf);
512513
struct devlink *devlink = priv_to_devlink(pf);
514+
int err;
513515

514-
if (!repr)
515-
return;
516+
if (IS_ERR(repr))
517+
return PTR_ERR(repr);
516518

519+
devl_lock(devlink);
520+
err = ice_eswitch_attach(pf, repr, &vf->repr_id);
521+
if (err)
522+
ice_repr_destroy(repr);
523+
devl_unlock(devlink);
524+
525+
return err;
526+
}
527+
528+
static void ice_eswitch_detach(struct ice_pf *pf, struct ice_repr *repr)
529+
{
517530
ice_eswitch_stop_reprs(pf);
518531
xa_erase(&pf->eswitch.reprs, repr->id);
519532

520533
if (xa_empty(&pf->eswitch.reprs))
521534
ice_eswitch_disable_switchdev(pf);
522535

523536
ice_eswitch_release_repr(pf, repr);
524-
devl_lock(devlink);
525-
ice_repr_rem_vf(repr);
537+
repr->ops.rem(repr);
538+
ice_repr_destroy(repr);
526539

527540
if (xa_empty(&pf->eswitch.reprs)) {
541+
struct devlink *devlink = priv_to_devlink(pf);
542+
528543
/* since all port representors are destroyed, there is
529544
* no point in keeping the nodes
530545
*/
@@ -533,6 +548,23 @@ void ice_eswitch_detach(struct ice_pf *pf, struct ice_vf *vf)
533548
} else {
534549
ice_eswitch_start_reprs(pf);
535550
}
551+
}
552+
553+
/**
554+
* ice_eswitch_detach_vf - detach VF from a eswitch
555+
* @pf: pointer to PF structure
556+
* @vf: pointer to VF structure to be detached
557+
*/
558+
void ice_eswitch_detach_vf(struct ice_pf *pf, struct ice_vf *vf)
559+
{
560+
struct ice_repr *repr = xa_load(&pf->eswitch.reprs, vf->repr_id);
561+
struct devlink *devlink = priv_to_devlink(pf);
562+
563+
if (!repr)
564+
return;
565+
566+
devl_lock(devlink);
567+
ice_eswitch_detach(pf, repr);
536568
devl_unlock(devlink);
537569
}
538570

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
#define _ICE_ESWITCH_H_
66

77
#include <net/devlink.h>
8+
#include "devlink/devlink_port.h"
89

910
#ifdef CONFIG_ICE_SWITCHDEV
10-
void ice_eswitch_detach(struct ice_pf *pf, struct ice_vf *vf);
11-
int
12-
ice_eswitch_attach(struct ice_pf *pf, struct ice_vf *vf);
11+
void ice_eswitch_detach_vf(struct ice_pf *pf, struct ice_vf *vf);
12+
int ice_eswitch_attach_vf(struct ice_pf *pf, struct ice_vf *vf);
1313

1414
int ice_eswitch_mode_get(struct devlink *devlink, u16 *mode);
1515
int
@@ -31,10 +31,11 @@ struct net_device *ice_eswitch_get_target(struct ice_rx_ring *rx_ring,
3131
int ice_eswitch_cfg_vsi(struct ice_vsi *vsi, const u8 *mac);
3232
void ice_eswitch_decfg_vsi(struct ice_vsi *vsi, const u8 *mac);
3333
#else /* CONFIG_ICE_SWITCHDEV */
34-
static inline void ice_eswitch_detach(struct ice_pf *pf, struct ice_vf *vf) { }
34+
static inline void
35+
ice_eswitch_detach_vf(struct ice_pf *pf, struct ice_vf *vf) { }
3536

3637
static inline int
37-
ice_eswitch_attach(struct ice_pf *pf, struct ice_vf *vf)
38+
ice_eswitch_attach_vf(struct ice_pf *pf, struct ice_vf *vf)
3839
{
3940
return -EOPNOTSUPP;
4041
}

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

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -283,34 +283,23 @@ ice_repr_reg_netdev(struct net_device *netdev)
283283
return register_netdev(netdev);
284284
}
285285

286-
static void ice_repr_remove_node(struct devlink_port *devlink_port)
287-
{
288-
devl_rate_leaf_destroy(devlink_port);
289-
}
290-
291286
/**
292-
* ice_repr_rem - remove representor from VF
287+
* ice_repr_destroy - remove representor from VF
293288
* @repr: pointer to representor structure
294289
*/
295-
static void ice_repr_rem(struct ice_repr *repr)
290+
void ice_repr_destroy(struct ice_repr *repr)
296291
{
297292
free_percpu(repr->stats);
298293
free_netdev(repr->netdev);
299294
kfree(repr);
300295
}
301296

302-
/**
303-
* ice_repr_rem_vf - remove representor from VF
304-
* @repr: pointer to representor structure
305-
*/
306-
void ice_repr_rem_vf(struct ice_repr *repr)
297+
static void ice_repr_rem_vf(struct ice_repr *repr)
307298
{
308-
ice_repr_remove_node(&repr->vf->devlink_port);
309299
ice_eswitch_decfg_vsi(repr->src_vsi, repr->parent_mac);
310300
unregister_netdev(repr->netdev);
311301
ice_devlink_destroy_vf_port(repr->vf);
312302
ice_virtchnl_set_dflt_ops(repr->vf);
313-
ice_repr_rem(repr);
314303
}
315304

316305
static void ice_repr_set_tx_topology(struct ice_pf *pf)
@@ -327,13 +316,10 @@ static void ice_repr_set_tx_topology(struct ice_pf *pf)
327316
}
328317

329318
/**
330-
* ice_repr_add - add representor for generic VSI
331-
* @pf: pointer to PF structure
319+
* ice_repr_create - add representor for generic VSI
332320
* @src_vsi: pointer to VSI structure of device to represent
333-
* @parent_mac: device MAC address
334321
*/
335-
static struct ice_repr *
336-
ice_repr_add(struct ice_pf *pf, struct ice_vsi *src_vsi, const u8 *parent_mac)
322+
static struct ice_repr *ice_repr_create(struct ice_vsi *src_vsi)
337323
{
338324
struct ice_netdev_priv *np;
339325
struct ice_repr *repr;
@@ -360,7 +346,10 @@ ice_repr_add(struct ice_pf *pf, struct ice_vsi *src_vsi, const u8 *parent_mac)
360346
np = netdev_priv(repr->netdev);
361347
np->repr = repr;
362348

363-
ether_addr_copy(repr->parent_mac, parent_mac);
349+
repr->netdev->min_mtu = ETH_MIN_MTU;
350+
repr->netdev->max_mtu = ICE_MAX_MTU;
351+
352+
SET_NETDEV_DEV(repr->netdev, ice_pf_to_dev(src_vsi->back));
364353

365354
return repr;
366355

@@ -371,32 +360,15 @@ ice_repr_add(struct ice_pf *pf, struct ice_vsi *src_vsi, const u8 *parent_mac)
371360
return ERR_PTR(err);
372361
}
373362

374-
struct ice_repr *ice_repr_add_vf(struct ice_vf *vf)
363+
static int ice_repr_add_vf(struct ice_repr *repr)
375364
{
376-
struct ice_repr *repr;
377-
struct ice_vsi *vsi;
365+
struct ice_vf *vf = repr->vf;
378366
int err;
379367

380-
vsi = ice_get_vf_vsi(vf);
381-
if (!vsi)
382-
return ERR_PTR(-ENOENT);
383-
384368
err = ice_devlink_create_vf_port(vf);
385369
if (err)
386-
return ERR_PTR(err);
387-
388-
repr = ice_repr_add(vf->pf, vsi, vf->hw_lan_addr);
389-
if (IS_ERR(repr)) {
390-
err = PTR_ERR(repr);
391-
goto err_repr_add;
392-
}
393-
394-
repr->vf = vf;
370+
return err;
395371

396-
repr->netdev->min_mtu = ETH_MIN_MTU;
397-
repr->netdev->max_mtu = ICE_MAX_MTU;
398-
399-
SET_NETDEV_DEV(repr->netdev, ice_pf_to_dev(vf->pf));
400372
SET_NETDEV_DEVLINK_PORT(repr->netdev, &vf->devlink_port);
401373
err = ice_repr_reg_netdev(repr->netdev);
402374
if (err)
@@ -409,15 +381,43 @@ struct ice_repr *ice_repr_add_vf(struct ice_vf *vf)
409381
ice_virtchnl_set_repr_ops(vf);
410382
ice_repr_set_tx_topology(vf->pf);
411383

412-
return repr;
384+
return 0;
413385

414386
err_cfg_vsi:
415387
unregister_netdev(repr->netdev);
416388
err_netdev:
417-
ice_repr_rem(repr);
418-
err_repr_add:
419389
ice_devlink_destroy_vf_port(vf);
420-
return ERR_PTR(err);
390+
return err;
391+
}
392+
393+
/**
394+
* ice_repr_create_vf - add representor for VF VSI
395+
* @vf: VF to create port representor on
396+
*
397+
* Set correct representor type for VF and functions pointer.
398+
*
399+
* Return: created port representor on success, error otherwise
400+
*/
401+
struct ice_repr *ice_repr_create_vf(struct ice_vf *vf)
402+
{
403+
struct ice_vsi *vsi = ice_get_vf_vsi(vf);
404+
struct ice_repr *repr;
405+
406+
if (!vsi)
407+
return ERR_PTR(-EINVAL);
408+
409+
repr = ice_repr_create(vsi);
410+
if (!repr)
411+
return ERR_PTR(-ENOMEM);
412+
413+
repr->type = ICE_REPR_TYPE_VF;
414+
repr->vf = vf;
415+
repr->ops.add = ice_repr_add_vf;
416+
repr->ops.rem = ice_repr_rem_vf;
417+
418+
ether_addr_copy(repr->parent_mac, vf->hw_lan_addr);
419+
420+
return repr;
421421
}
422422

423423
struct ice_repr *ice_repr_get(struct ice_pf *pf, u32 id)

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,29 @@ struct ice_repr_pcpu_stats {
1515
u64 tx_drops;
1616
};
1717

18+
enum ice_repr_type {
19+
ICE_REPR_TYPE_VF,
20+
};
21+
1822
struct ice_repr {
1923
struct ice_vsi *src_vsi;
20-
struct ice_vf *vf;
2124
struct net_device *netdev;
2225
struct metadata_dst *dst;
2326
struct ice_esw_br_port *br_port;
2427
struct ice_repr_pcpu_stats __percpu *stats;
2528
u32 id;
2629
u8 parent_mac[ETH_ALEN];
30+
enum ice_repr_type type;
31+
struct ice_vf *vf;
32+
struct {
33+
int (*add)(struct ice_repr *repr);
34+
void (*rem)(struct ice_repr *repr);
35+
} ops;
2736
};
2837

29-
struct ice_repr *ice_repr_add_vf(struct ice_vf *vf);
30-
void ice_repr_rem_vf(struct ice_repr *repr);
38+
struct ice_repr *ice_repr_create_vf(struct ice_vf *vf);
39+
40+
void ice_repr_destroy(struct ice_repr *repr);
3141

3242
void ice_repr_start_tx_queues(struct ice_repr *repr);
3343
void ice_repr_stop_tx_queues(struct ice_repr *repr);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ void ice_free_vfs(struct ice_pf *pf)
175175
ice_for_each_vf(pf, bkt, vf) {
176176
mutex_lock(&vf->cfg_lock);
177177

178-
ice_eswitch_detach(pf, vf);
178+
ice_eswitch_detach_vf(pf, vf);
179179
ice_dis_vf_qs(vf);
180180

181181
if (test_bit(ICE_VF_STATE_INIT, vf->vf_states)) {
@@ -598,7 +598,7 @@ static int ice_start_vfs(struct ice_pf *pf)
598598
goto teardown;
599599
}
600600

601-
retval = ice_eswitch_attach(pf, vf);
601+
retval = ice_eswitch_attach_vf(pf, vf);
602602
if (retval) {
603603
dev_err(ice_pf_to_dev(pf), "Failed to attach VF %d to eswitch, error %d",
604604
vf->vf_id, retval);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,7 @@ void ice_reset_all_vfs(struct ice_pf *pf)
766766
ice_for_each_vf(pf, bkt, vf) {
767767
mutex_lock(&vf->cfg_lock);
768768

769-
ice_eswitch_detach(pf, vf);
769+
ice_eswitch_detach_vf(pf, vf);
770770
vf->driver_caps = 0;
771771
ice_vc_set_default_allowlist(vf);
772772

@@ -782,7 +782,7 @@ void ice_reset_all_vfs(struct ice_pf *pf)
782782
ice_vf_rebuild_vsi(vf);
783783
ice_vf_post_vsi_rebuild(vf);
784784

785-
ice_eswitch_attach(pf, vf);
785+
ice_eswitch_attach_vf(pf, vf);
786786

787787
mutex_unlock(&vf->cfg_lock);
788788
}

0 commit comments

Comments
 (0)