Skip to content

Commit 604283e

Browse files
Michal Swiatkowskianguy11
authored andcommitted
ice: make representor code generic
Representor code needs to be independent from specific device type, like in this case VF. Make generic add / remove representor function and specific add VF / rem VF function. New device types will follow this scheme. In bridge offload code there is a need to get representor pointer based on VSI. Implement helper function to achieve that. 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 e4c46ab commit 604283e

File tree

8 files changed

+131
-92
lines changed

8 files changed

+131
-92
lines changed

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,17 +285,22 @@ static int ice_eswitch_setup_reprs(struct ice_pf *pf)
285285

286286
/**
287287
* ice_eswitch_update_repr - reconfigure port representor
288-
* @repr: pointer to repr struct
288+
* @repr_id: representor ID
289289
* @vsi: VSI for which port representor is configured
290290
*/
291-
void ice_eswitch_update_repr(struct ice_repr *repr, struct ice_vsi *vsi)
291+
void ice_eswitch_update_repr(unsigned long repr_id, struct ice_vsi *vsi)
292292
{
293293
struct ice_pf *pf = vsi->back;
294+
struct ice_repr *repr;
294295
int ret;
295296

296297
if (!ice_is_switchdev_running(pf))
297298
return;
298299

300+
repr = xa_load(&pf->eswitch.reprs, repr_id);
301+
if (!repr)
302+
return;
303+
299304
repr->src_vsi = vsi;
300305
repr->dst->u.port_info.port_id = vsi->vsi_num;
301306

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ ice_eswitch_mode_set(struct devlink *devlink, u16 mode,
1717
struct netlink_ext_ack *extack);
1818
bool ice_is_eswitch_mode_switchdev(struct ice_pf *pf);
1919

20-
void ice_eswitch_update_repr(struct ice_repr *repr, struct ice_vsi *vsi);
20+
void ice_eswitch_update_repr(unsigned long repr_id, struct ice_vsi *vsi);
2121

2222
void ice_eswitch_stop_all_tx_queues(struct ice_pf *pf);
2323

@@ -35,7 +35,7 @@ ice_eswitch_set_target_vsi(struct sk_buff *skb,
3535
struct ice_tx_offload_params *off) { }
3636

3737
static inline void
38-
ice_eswitch_update_repr(struct ice_repr *repr, struct ice_vsi *vsi) { }
38+
ice_eswitch_update_repr(unsigned long repr_id, struct ice_vsi *vsi) { }
3939

4040
static inline int ice_eswitch_configure(struct ice_pf *pf)
4141
{

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -893,10 +893,14 @@ ice_eswitch_br_port_deinit(struct ice_esw_br *bridge,
893893
ice_eswitch_br_fdb_entry_delete(bridge, fdb_entry);
894894
}
895895

896-
if (br_port->type == ICE_ESWITCH_BR_UPLINK_PORT && vsi->back)
896+
if (br_port->type == ICE_ESWITCH_BR_UPLINK_PORT && vsi->back) {
897897
vsi->back->br_port = NULL;
898-
else if (vsi->vf && vsi->vf->repr)
899-
vsi->vf->repr->br_port = NULL;
898+
} else {
899+
struct ice_repr *repr = ice_repr_get_by_vsi(vsi);
900+
901+
if (repr)
902+
repr->br_port = NULL;
903+
}
900904

901905
xa_erase(&bridge->ports, br_port->vsi_idx);
902906
ice_eswitch_br_port_vlans_flush(br_port);

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -519,16 +519,14 @@ static irqreturn_t ice_eswitch_msix_clean_rings(int __always_unused irq, void *d
519519
{
520520
struct ice_q_vector *q_vector = (struct ice_q_vector *)data;
521521
struct ice_pf *pf = q_vector->vsi->back;
522-
struct ice_vf *vf;
523-
unsigned int bkt;
522+
struct ice_repr *repr;
523+
unsigned long id;
524524

525525
if (!q_vector->tx.tx_ring && !q_vector->rx.rx_ring)
526526
return IRQ_HANDLED;
527527

528-
rcu_read_lock();
529-
ice_for_each_vf_rcu(pf, bkt, vf)
530-
napi_schedule(&vf->repr->q_vector->napi);
531-
rcu_read_unlock();
528+
xa_for_each(&pf->eswitch.reprs, id, repr)
529+
napi_schedule(&repr->q_vector->napi);
532530

533531
return IRQ_HANDLED;
534532
}

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

Lines changed: 107 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
*/
1515
static int ice_repr_get_sw_port_id(struct ice_repr *repr)
1616
{
17-
return repr->vf->pf->hw.port_info->lport;
17+
return repr->src_vsi->back->hw.port_info->lport;
1818
}
1919

2020
/**
@@ -35,7 +35,7 @@ ice_repr_get_phys_port_name(struct net_device *netdev, char *buf, size_t len)
3535
return -EOPNOTSUPP;
3636

3737
res = snprintf(buf, len, "pf%dvfr%d", ice_repr_get_sw_port_id(repr),
38-
repr->vf->vf_id);
38+
repr->id);
3939
if (res <= 0)
4040
return -EOPNOTSUPP;
4141
return 0;
@@ -279,35 +279,80 @@ ice_repr_reg_netdev(struct net_device *netdev)
279279
}
280280

281281
/**
282-
* ice_repr_add - add representor for VF
283-
* @vf: pointer to VF structure
282+
* ice_repr_rem - remove representor from VF
283+
* @reprs: xarray storing representors
284+
* @repr: pointer to representor structure
284285
*/
285-
static int ice_repr_add(struct ice_vf *vf)
286+
static void ice_repr_rem(struct xarray *reprs, struct ice_repr *repr)
287+
{
288+
xa_erase(reprs, repr->id);
289+
kfree(repr->q_vector);
290+
free_netdev(repr->netdev);
291+
kfree(repr);
292+
}
293+
294+
static void ice_repr_rem_vf(struct ice_vf *vf)
295+
{
296+
struct ice_repr *repr = xa_load(&vf->pf->eswitch.reprs, vf->repr_id);
297+
298+
if (!repr)
299+
return;
300+
301+
unregister_netdev(repr->netdev);
302+
ice_repr_rem(&vf->pf->eswitch.reprs, repr);
303+
ice_devlink_destroy_vf_port(vf);
304+
ice_virtchnl_set_dflt_ops(vf);
305+
}
306+
307+
/**
308+
* ice_repr_rem_from_all_vfs - remove port representor for all VFs
309+
* @pf: pointer to PF structure
310+
*/
311+
void ice_repr_rem_from_all_vfs(struct ice_pf *pf)
312+
{
313+
struct devlink *devlink;
314+
struct ice_vf *vf;
315+
unsigned int bkt;
316+
317+
lockdep_assert_held(&pf->vfs.table_lock);
318+
319+
ice_for_each_vf(pf, bkt, vf)
320+
ice_repr_rem_vf(vf);
321+
322+
/* since all port representors are destroyed, there is
323+
* no point in keeping the nodes
324+
*/
325+
devlink = priv_to_devlink(pf);
326+
devl_lock(devlink);
327+
devl_rate_nodes_destroy(devlink);
328+
devl_unlock(devlink);
329+
}
330+
331+
/**
332+
* ice_repr_add - add representor for generic VSI
333+
* @pf: pointer to PF structure
334+
* @src_vsi: pointer to VSI structure of device to represent
335+
* @parent_mac: device MAC address
336+
*/
337+
static struct ice_repr *
338+
ice_repr_add(struct ice_pf *pf, struct ice_vsi *src_vsi, const u8 *parent_mac)
286339
{
287340
struct ice_q_vector *q_vector;
288341
struct ice_netdev_priv *np;
289342
struct ice_repr *repr;
290-
struct ice_vsi *vsi;
291343
int err;
292344

293-
vsi = ice_get_vf_vsi(vf);
294-
if (!vsi)
295-
return -EINVAL;
296-
297345
repr = kzalloc(sizeof(*repr), GFP_KERNEL);
298346
if (!repr)
299-
return -ENOMEM;
347+
return ERR_PTR(-ENOMEM);
300348

301349
repr->netdev = alloc_etherdev(sizeof(struct ice_netdev_priv));
302350
if (!repr->netdev) {
303351
err = -ENOMEM;
304352
goto err_alloc;
305353
}
306354

307-
repr->src_vsi = vsi;
308-
repr->vf = vf;
309-
repr->q_id = vf->vf_id;
310-
vf->repr = repr;
355+
repr->src_vsi = src_vsi;
311356
np = netdev_priv(repr->netdev);
312357
np->repr = repr;
313358

@@ -318,14 +363,47 @@ static int ice_repr_add(struct ice_vf *vf)
318363
}
319364
repr->q_vector = q_vector;
320365

321-
err = xa_alloc(&vf->pf->eswitch.reprs, &repr->id, repr,
322-
xa_limit_32b, GFP_KERNEL);
366+
err = xa_alloc(&pf->eswitch.reprs, &repr->id, repr,
367+
XA_LIMIT(1, INT_MAX), GFP_KERNEL);
323368
if (err)
324369
goto err_xa_alloc;
370+
repr->q_id = repr->id;
371+
372+
ether_addr_copy(repr->parent_mac, parent_mac);
373+
374+
return repr;
375+
376+
err_xa_alloc:
377+
kfree(repr->q_vector);
378+
err_alloc_q_vector:
379+
free_netdev(repr->netdev);
380+
err_alloc:
381+
kfree(repr);
382+
return ERR_PTR(err);
383+
}
384+
385+
static int ice_repr_add_vf(struct ice_vf *vf)
386+
{
387+
struct ice_repr *repr;
388+
struct ice_vsi *vsi;
389+
int err;
390+
391+
vsi = ice_get_vf_vsi(vf);
392+
if (!vsi)
393+
return -EINVAL;
325394

326395
err = ice_devlink_create_vf_port(vf);
327396
if (err)
328-
goto err_devlink;
397+
return err;
398+
399+
repr = ice_repr_add(vf->pf, vsi, vf->hw_lan_addr);
400+
if (IS_ERR(repr)) {
401+
err = PTR_ERR(repr);
402+
goto err_repr_add;
403+
}
404+
405+
vf->repr_id = repr->id;
406+
repr->vf = vf;
329407

330408
repr->netdev->min_mtu = ETH_MIN_MTU;
331409
repr->netdev->max_mtu = ICE_MAX_MTU;
@@ -336,73 +414,17 @@ static int ice_repr_add(struct ice_vf *vf)
336414
if (err)
337415
goto err_netdev;
338416

339-
ether_addr_copy(repr->parent_mac, vf->hw_lan_addr);
340417
ice_virtchnl_set_repr_ops(vf);
341418

342419
return 0;
343420

344421
err_netdev:
422+
ice_repr_rem(&vf->pf->eswitch.reprs, repr);
423+
err_repr_add:
345424
ice_devlink_destroy_vf_port(vf);
346-
err_devlink:
347-
xa_erase(&vf->pf->eswitch.reprs, repr->id);
348-
err_xa_alloc:
349-
kfree(repr->q_vector);
350-
vf->repr->q_vector = NULL;
351-
err_alloc_q_vector:
352-
free_netdev(repr->netdev);
353-
repr->netdev = NULL;
354-
err_alloc:
355-
kfree(repr);
356-
vf->repr = NULL;
357425
return err;
358426
}
359427

360-
/**
361-
* ice_repr_rem - remove representor from VF
362-
* @vf: pointer to VF structure
363-
*/
364-
static void ice_repr_rem(struct ice_vf *vf)
365-
{
366-
struct ice_repr *repr = vf->repr;
367-
368-
if (!repr)
369-
return;
370-
371-
kfree(repr->q_vector);
372-
unregister_netdev(repr->netdev);
373-
ice_devlink_destroy_vf_port(vf);
374-
xa_erase(&vf->pf->eswitch.reprs, repr->id);
375-
free_netdev(repr->netdev);
376-
kfree(repr);
377-
vf->repr = NULL;
378-
379-
ice_virtchnl_set_dflt_ops(vf);
380-
}
381-
382-
/**
383-
* ice_repr_rem_from_all_vfs - remove port representor for all VFs
384-
* @pf: pointer to PF structure
385-
*/
386-
void ice_repr_rem_from_all_vfs(struct ice_pf *pf)
387-
{
388-
struct devlink *devlink;
389-
struct ice_vf *vf;
390-
unsigned int bkt;
391-
392-
lockdep_assert_held(&pf->vfs.table_lock);
393-
394-
ice_for_each_vf(pf, bkt, vf)
395-
ice_repr_rem(vf);
396-
397-
/* since all port representors are destroyed, there is
398-
* no point in keeping the nodes
399-
*/
400-
devlink = priv_to_devlink(pf);
401-
devl_lock(devlink);
402-
devl_rate_nodes_destroy(devlink);
403-
devl_unlock(devlink);
404-
}
405-
406428
/**
407429
* ice_repr_add_for_all_vfs - add port representor for all VFs
408430
* @pf: pointer to PF structure
@@ -417,7 +439,7 @@ int ice_repr_add_for_all_vfs(struct ice_pf *pf)
417439
lockdep_assert_held(&pf->vfs.table_lock);
418440

419441
ice_for_each_vf(pf, bkt, vf) {
420-
err = ice_repr_add(vf);
442+
err = ice_repr_add_vf(vf);
421443
if (err)
422444
goto err;
423445
}
@@ -437,6 +459,14 @@ int ice_repr_add_for_all_vfs(struct ice_pf *pf)
437459
return err;
438460
}
439461

462+
struct ice_repr *ice_repr_get_by_vsi(struct ice_vsi *vsi)
463+
{
464+
if (!vsi->vf)
465+
return NULL;
466+
467+
return xa_load(&vsi->back->eswitch.reprs, vsi->vf->repr_id);
468+
}
469+
440470
/**
441471
* ice_repr_start_tx_queues - start Tx queues of port representor
442472
* @repr: pointer to repr structure

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,6 @@ void ice_repr_set_traffic_vsi(struct ice_repr *repr, struct ice_vsi *vsi);
3232

3333
struct ice_repr *ice_netdev_to_repr(struct net_device *netdev);
3434
bool ice_is_port_repr_netdev(const struct net_device *netdev);
35+
36+
struct ice_repr *ice_repr_get_by_vsi(struct ice_vsi *vsi);
3537
#endif

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -928,7 +928,7 @@ int ice_reset_vf(struct ice_vf *vf, u32 flags)
928928
goto out_unlock;
929929
}
930930

931-
ice_eswitch_update_repr(vf->repr, vsi);
931+
ice_eswitch_update_repr(vf->repr_id, vsi);
932932

933933
/* if the VF has been reset allow it to come up again */
934934
ice_mbx_clear_malvf(&vf->mbx_info);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ struct ice_vf {
130130
struct ice_mdd_vf_events mdd_tx_events;
131131
DECLARE_BITMAP(opcodes_allowlist, VIRTCHNL_OP_MAX);
132132

133-
struct ice_repr *repr;
133+
unsigned long repr_id;
134134
const struct ice_virtchnl_ops *virtchnl_ops;
135135
const struct ice_vf_ops *vf_ops;
136136

0 commit comments

Comments
 (0)