Skip to content

Commit 977514f

Browse files
Michal Swiatkowskianguy11
authored andcommitted
ice: create port representor for SF
Implement attaching and detaching SF port representor. It is done in the same way as the VF port representor. SF port representor is always added or removed with devlink lock taken. Reviewed-by: Simon Horman <[email protected]> Signed-off-by: Michal Swiatkowski <[email protected]> Tested-by: Rafal Romanowski <[email protected]> Signed-off-by: Tony Nguyen <[email protected]>
1 parent 415db83 commit 977514f

File tree

6 files changed

+113
-4
lines changed

6 files changed

+113
-4
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ static void ice_dealloc_dynamic_port(struct ice_dynamic_port *dyn_port)
543543
struct ice_pf *pf = dyn_port->pf;
544544

545545
xa_erase(&pf->sf_nums, devlink_port->attrs.pci_sf.sf);
546-
devl_port_unregister(devlink_port);
546+
ice_eswitch_detach_sf(pf, dyn_port);
547547
ice_vsi_free(dyn_port->vsi);
548548
xa_erase(&pf->dyn_ports, dyn_port->vsi->idx);
549549
kfree(dyn_port);
@@ -765,9 +765,9 @@ ice_alloc_dynamic_port(struct ice_pf *pf,
765765
goto unroll_vsi_alloc;
766766
}
767767

768-
err = ice_devlink_create_sf_port(dyn_port);
768+
err = ice_eswitch_attach_sf(pf, dyn_port);
769769
if (err) {
770-
NL_SET_ERR_MSG_MOD(extack, "Port registration failed");
770+
NL_SET_ERR_MSG_MOD(extack, "Failed to attach SF to eswitch");
771771
goto unroll_xa_insert;
772772
}
773773

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

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,30 @@ int ice_eswitch_attach_vf(struct ice_pf *pf, struct ice_vf *vf)
525525
return err;
526526
}
527527

528+
/**
529+
* ice_eswitch_attach_sf - attach SF to a eswitch
530+
* @pf: pointer to PF structure
531+
* @sf: pointer to SF structure to be attached
532+
*
533+
* During attaching port representor for SF is created.
534+
*
535+
* Return: zero on success or an error code on failure.
536+
*/
537+
int ice_eswitch_attach_sf(struct ice_pf *pf, struct ice_dynamic_port *sf)
538+
{
539+
struct ice_repr *repr = ice_repr_create_sf(sf);
540+
int err;
541+
542+
if (IS_ERR(repr))
543+
return PTR_ERR(repr);
544+
545+
err = ice_eswitch_attach(pf, repr, &sf->repr_id);
546+
if (err)
547+
ice_repr_destroy(repr);
548+
549+
return err;
550+
}
551+
528552
static void ice_eswitch_detach(struct ice_pf *pf, struct ice_repr *repr)
529553
{
530554
ice_eswitch_stop_reprs(pf);
@@ -568,6 +592,21 @@ void ice_eswitch_detach_vf(struct ice_pf *pf, struct ice_vf *vf)
568592
devl_unlock(devlink);
569593
}
570594

595+
/**
596+
* ice_eswitch_detach_sf - detach SF from a eswitch
597+
* @pf: pointer to PF structure
598+
* @sf: pointer to SF structure to be detached
599+
*/
600+
void ice_eswitch_detach_sf(struct ice_pf *pf, struct ice_dynamic_port *sf)
601+
{
602+
struct ice_repr *repr = xa_load(&pf->eswitch.reprs, sf->repr_id);
603+
604+
if (!repr)
605+
return;
606+
607+
ice_eswitch_detach(pf, repr);
608+
}
609+
571610
/**
572611
* ice_eswitch_get_target - get netdev based on src_vsi from descriptor
573612
* @rx_ring: ring used to receive the packet

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99

1010
#ifdef CONFIG_ICE_SWITCHDEV
1111
void ice_eswitch_detach_vf(struct ice_pf *pf, struct ice_vf *vf);
12+
void ice_eswitch_detach_sf(struct ice_pf *pf, struct ice_dynamic_port *sf);
1213
int ice_eswitch_attach_vf(struct ice_pf *pf, struct ice_vf *vf);
14+
int ice_eswitch_attach_sf(struct ice_pf *pf, struct ice_dynamic_port *sf);
1315

1416
int ice_eswitch_mode_get(struct devlink *devlink, u16 *mode);
1517
int
@@ -34,12 +36,21 @@ void ice_eswitch_decfg_vsi(struct ice_vsi *vsi, const u8 *mac);
3436
static inline void
3537
ice_eswitch_detach_vf(struct ice_pf *pf, struct ice_vf *vf) { }
3638

39+
static inline void
40+
ice_eswitch_detach_sf(struct ice_pf *pf, struct ice_dynamic_port *sf) { }
41+
3742
static inline int
3843
ice_eswitch_attach_vf(struct ice_pf *pf, struct ice_vf *vf)
3944
{
4045
return -EOPNOTSUPP;
4146
}
4247

48+
static inline int
49+
ice_eswitch_attach_sf(struct ice_pf *pf, struct ice_dynamic_port *sf)
50+
{
51+
return -EOPNOTSUPP;
52+
}
53+
4354
static inline void ice_eswitch_stop_all_tx_queues(struct ice_pf *pf) { }
4455

4556
static inline void

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

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,12 @@ static void ice_repr_rem_vf(struct ice_repr *repr)
302302
ice_virtchnl_set_dflt_ops(repr->vf);
303303
}
304304

305+
static void ice_repr_rem_sf(struct ice_repr *repr)
306+
{
307+
unregister_netdev(repr->netdev);
308+
ice_devlink_destroy_sf_port(repr->sf);
309+
}
310+
305311
static void ice_repr_set_tx_topology(struct ice_pf *pf)
306312
{
307313
struct devlink *devlink;
@@ -420,6 +426,52 @@ struct ice_repr *ice_repr_create_vf(struct ice_vf *vf)
420426
return repr;
421427
}
422428

429+
static int ice_repr_add_sf(struct ice_repr *repr)
430+
{
431+
struct ice_dynamic_port *sf = repr->sf;
432+
int err;
433+
434+
err = ice_devlink_create_sf_port(sf);
435+
if (err)
436+
return err;
437+
438+
SET_NETDEV_DEVLINK_PORT(repr->netdev, &sf->devlink_port);
439+
err = ice_repr_reg_netdev(repr->netdev);
440+
if (err)
441+
goto err_netdev;
442+
443+
return 0;
444+
445+
err_netdev:
446+
ice_devlink_destroy_sf_port(sf);
447+
return err;
448+
}
449+
450+
/**
451+
* ice_repr_create_sf - add representor for SF VSI
452+
* @sf: SF to create port representor on
453+
*
454+
* Set correct representor type for SF and functions pointer.
455+
*
456+
* Return: created port representor on success, error otherwise
457+
*/
458+
struct ice_repr *ice_repr_create_sf(struct ice_dynamic_port *sf)
459+
{
460+
struct ice_repr *repr = ice_repr_create(sf->vsi);
461+
462+
if (!repr)
463+
return ERR_PTR(-ENOMEM);
464+
465+
repr->type = ICE_REPR_TYPE_SF;
466+
repr->sf = sf;
467+
repr->ops.add = ice_repr_add_sf;
468+
repr->ops.rem = ice_repr_rem_sf;
469+
470+
ether_addr_copy(repr->parent_mac, sf->hw_addr);
471+
472+
return repr;
473+
}
474+
423475
struct ice_repr *ice_repr_get(struct ice_pf *pf, u32 id)
424476
{
425477
return xa_load(&pf->eswitch.reprs, id);

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ struct ice_repr_pcpu_stats {
1717

1818
enum ice_repr_type {
1919
ICE_REPR_TYPE_VF,
20+
ICE_REPR_TYPE_SF,
2021
};
2122

2223
struct ice_repr {
@@ -28,14 +29,18 @@ struct ice_repr {
2829
u32 id;
2930
u8 parent_mac[ETH_ALEN];
3031
enum ice_repr_type type;
31-
struct ice_vf *vf;
32+
union {
33+
struct ice_vf *vf;
34+
struct ice_dynamic_port *sf;
35+
};
3236
struct {
3337
int (*add)(struct ice_repr *repr);
3438
void (*rem)(struct ice_repr *repr);
3539
} ops;
3640
};
3741

3842
struct ice_repr *ice_repr_create_vf(struct ice_vf *vf);
43+
struct ice_repr *ice_repr_create_sf(struct ice_dynamic_port *sf);
3944

4045
void ice_repr_destroy(struct ice_repr *repr);
4146

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ static int ice_sf_dev_probe(struct auxiliary_device *adev,
126126
}
127127
vsi->sf = dyn_port;
128128

129+
ice_eswitch_update_repr(&dyn_port->repr_id, vsi);
130+
129131
err = ice_devlink_create_sf_dev_port(sf_dev);
130132
if (err) {
131133
dev_err(dev, "Cannot add ice virtual devlink port for subfunction");

0 commit comments

Comments
 (0)