Skip to content

Commit e4c46ab

Browse files
Michal Swiatkowskianguy11
authored andcommitted
ice: remove VF pointer reference in eswitch code
Make eswitch code generic by removing VF pointer reference in functions. It is needed to support eswitch mode for other type of devices. Previously queue id used for Rx was based on VF number. Use ::q_id saved in port representor instead. After adding or removing port representor ::q_id value can change. It isn't good idea to iterate over representors list using this value. Use xa_find starting from the first one instead to get next port representor to remap. The number of port representors has to be equal to ::num_rx/tx_q. Warn if it isn't true. Reviewed-by: Przemek Kitszel <[email protected]> Reviewed-by: Wojciech Drewek <[email protected]> Reviewed-by: Jacob Keller <[email protected]> Signed-off-by: Michal Swiatkowski <[email protected]> Tested-by: Sujai Buvaneswaran <[email protected]> Signed-off-by: Tony Nguyen <[email protected]>
1 parent af41b18 commit e4c46ab

File tree

4 files changed

+25
-22
lines changed

4 files changed

+25
-22
lines changed

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

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ ice_eswitch_add_sp_rule(struct ice_pf *pf, struct ice_repr *repr)
4747
err = ice_add_adv_rule(hw, list, lkups_cnt, &rule_info,
4848
&repr->sp_rule);
4949
if (err)
50-
dev_err(ice_pf_to_dev(pf), "Unable to add slow-path rule in switchdev mode");
50+
dev_err(ice_pf_to_dev(pf), "Unable to add slow-path rule for eswitch for PR %d",
51+
repr->id);
5152

5253
kfree(list);
5354
return err;
@@ -142,20 +143,22 @@ static int ice_eswitch_setup_env(struct ice_pf *pf)
142143
static void ice_eswitch_remap_rings_to_vectors(struct ice_pf *pf)
143144
{
144145
struct ice_vsi *vsi = pf->eswitch.control_vsi;
146+
unsigned long repr_id = 0;
145147
int q_id;
146148

147149
ice_for_each_txq(vsi, q_id) {
148150
struct ice_q_vector *q_vector;
149151
struct ice_tx_ring *tx_ring;
150152
struct ice_rx_ring *rx_ring;
151153
struct ice_repr *repr;
152-
struct ice_vf *vf;
153154

154-
vf = ice_get_vf_by_id(pf, q_id);
155-
if (WARN_ON(!vf))
156-
continue;
155+
repr = xa_find(&pf->eswitch.reprs, &repr_id, U32_MAX,
156+
XA_PRESENT);
157+
if (WARN_ON(!repr))
158+
break;
157159

158-
repr = vf->repr;
160+
repr_id += 1;
161+
repr->q_id = q_id;
159162
q_vector = repr->q_vector;
160163
tx_ring = vsi->tx_rings[q_id];
161164
rx_ring = vsi->rx_rings[q_id];
@@ -178,8 +181,6 @@ static void ice_eswitch_remap_rings_to_vectors(struct ice_pf *pf)
178181
rx_ring->q_vector = q_vector;
179182
rx_ring->next = NULL;
180183
rx_ring->netdev = repr->netdev;
181-
182-
ice_put_vf(vf);
183184
}
184185
}
185186

@@ -284,20 +285,17 @@ static int ice_eswitch_setup_reprs(struct ice_pf *pf)
284285

285286
/**
286287
* ice_eswitch_update_repr - reconfigure port representor
287-
* @vsi: VF VSI for which port representor is configured
288+
* @repr: pointer to repr struct
289+
* @vsi: VSI for which port representor is configured
288290
*/
289-
void ice_eswitch_update_repr(struct ice_vsi *vsi)
291+
void ice_eswitch_update_repr(struct ice_repr *repr, struct ice_vsi *vsi)
290292
{
291293
struct ice_pf *pf = vsi->back;
292-
struct ice_repr *repr;
293-
struct ice_vf *vf;
294294
int ret;
295295

296296
if (!ice_is_switchdev_running(pf))
297297
return;
298298

299-
vf = vsi->vf;
300-
repr = vf->repr;
301299
repr->src_vsi = vsi;
302300
repr->dst->u.port_info.port_id = vsi->vsi_num;
303301

@@ -306,9 +304,10 @@ void ice_eswitch_update_repr(struct ice_vsi *vsi)
306304

307305
ret = ice_vsi_update_security(vsi, ice_vsi_ctx_clear_antispoof);
308306
if (ret) {
309-
ice_fltr_add_mac_and_broadcast(vsi, vf->hw_lan_addr, ICE_FWD_TO_VSI);
310-
dev_err(ice_pf_to_dev(pf), "Failed to update VF %d port representor",
311-
vsi->vf->vf_id);
307+
ice_fltr_add_mac_and_broadcast(vsi, repr->parent_mac,
308+
ICE_FWD_TO_VSI);
309+
dev_err(ice_pf_to_dev(pf), "Failed to update VSI of port representor %d",
310+
repr->id);
312311
}
313312
}
314313

@@ -340,7 +339,7 @@ ice_eswitch_port_start_xmit(struct sk_buff *skb, struct net_device *netdev)
340339
skb_dst_drop(skb);
341340
dst_hold((struct dst_entry *)repr->dst);
342341
skb_dst_set(skb, (struct dst_entry *)repr->dst);
343-
skb->queue_mapping = repr->vf->vf_id;
342+
skb->queue_mapping = repr->q_id;
344343

345344
return ice_start_xmit(skb, netdev);
346345
}
@@ -486,7 +485,7 @@ static int ice_eswitch_enable_switchdev(struct ice_pf *pf)
486485
ice_eswitch_remap_rings_to_vectors(pf);
487486

488487
if (ice_vsi_open(ctrl_vsi))
489-
goto err_setup_reprs;
488+
goto err_vsi_open;
490489

491490
if (ice_eswitch_br_offloads_init(pf))
492491
goto err_br_offloads;
@@ -497,6 +496,8 @@ static int ice_eswitch_enable_switchdev(struct ice_pf *pf)
497496

498497
err_br_offloads:
499498
ice_vsi_close(ctrl_vsi);
499+
err_vsi_open:
500+
ice_eswitch_release_reprs(pf);
500501
err_setup_reprs:
501502
ice_repr_rem_from_all_vfs(pf);
502503
err_repr_add:

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

Lines changed: 3 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_vsi *vsi);
20+
void ice_eswitch_update_repr(struct ice_repr *repr, struct ice_vsi *vsi);
2121

2222
void ice_eswitch_stop_all_tx_queues(struct ice_pf *pf);
2323

@@ -34,7 +34,8 @@ static inline void
3434
ice_eswitch_set_target_vsi(struct sk_buff *skb,
3535
struct ice_tx_offload_params *off) { }
3636

37-
static inline void ice_eswitch_update_repr(struct ice_vsi *vsi) { }
37+
static inline void
38+
ice_eswitch_update_repr(struct ice_repr *repr, struct ice_vsi *vsi) { }
3839

3940
static inline int ice_eswitch_configure(struct ice_pf *pf)
4041
{

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,7 @@ static int ice_repr_add(struct ice_vf *vf)
336336
if (err)
337337
goto err_netdev;
338338

339+
ether_addr_copy(repr->parent_mac, vf->hw_lan_addr);
339340
ice_virtchnl_set_repr_ops(vf);
340341

341342
return 0;

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(vsi);
931+
ice_eswitch_update_repr(vf->repr, vsi);
932932

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

0 commit comments

Comments
 (0)