Skip to content

Commit 1c54c83

Browse files
gnitkaanguy11
authored andcommitted
ice: enable/disable switchdev when managing VFs
Only way to enable switchdev is to create VFs when the eswitch mode is set to switchdev. Check if correct mode is set and enable switchdev in function which creating VFs. Disable switchdev when user change number of VFs to 0. Changing eswitch mode back to legacy when VFs are created in switchdev mode isn't allowed. As switchdev takes care of managing filter rules, adding new rules on VF is blocked. In case of resetting VF driver has to update pointer in ice_repr struct, because after reset VSI related things can change. Co-developed-by: Wojciech Drewek <wojciech.drewek@intel.com> Signed-off-by: Wojciech Drewek <wojciech.drewek@intel.com> Signed-off-by: Grzegorz Nitka <grzegorz.nitka@intel.com> Tested-by: Sandeep Penigalapati <sandeep.penigalapati@intel.com> Signed-off-by: Tony Nguyen <anthony.l.nguyen@intel.com>
1 parent f66756e commit 1c54c83

File tree

4 files changed

+63
-2
lines changed

4 files changed

+63
-2
lines changed

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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,32 @@ ice_eswitch_release_reprs(struct ice_pf *pf, struct ice_vsi *ctrl_vsi)
232232
}
233233
}
234234

235+
/**
236+
* ice_eswitch_update_repr - reconfigure VF port representor
237+
* @vsi: VF VSI for which port representor is configured
238+
*/
239+
void ice_eswitch_update_repr(struct ice_vsi *vsi)
240+
{
241+
struct ice_pf *pf = vsi->back;
242+
struct ice_repr *repr;
243+
struct ice_vf *vf;
244+
int ret;
245+
246+
if (!ice_is_switchdev_running(pf))
247+
return;
248+
249+
vf = &pf->vf[vsi->vf_id];
250+
repr = vf->repr;
251+
repr->src_vsi = vsi;
252+
repr->dst->u.port_info.port_id = vsi->vsi_num;
253+
254+
ret = ice_vsi_update_security(vsi, ice_vsi_ctx_clear_antispoof);
255+
if (ret) {
256+
ice_fltr_add_mac_and_broadcast(vsi, vf->hw_lan_addr.addr, ICE_FWD_TO_VSI);
257+
dev_err(ice_pf_to_dev(pf), "Failed to update VF %d port representor", vsi->vf_id);
258+
}
259+
}
260+
235261
/**
236262
* ice_eswitch_release_env - clear switchdev HW filters
237263
* @pf: pointer to PF struct
@@ -423,6 +449,18 @@ int ice_eswitch_mode_get(struct devlink *devlink, u16 *mode)
423449
return 0;
424450
}
425451

452+
/**
453+
* ice_is_eswitch_mode_switchdev - check if eswitch mode is set to switchdev
454+
* @pf: pointer to PF structure
455+
*
456+
* Returns true if eswitch mode is set to DEVLINK_ESWITCH_MODE_SWITCHDEV,
457+
* false otherwise.
458+
*/
459+
bool ice_is_eswitch_mode_switchdev(struct ice_pf *pf)
460+
{
461+
return pf->eswitch_mode == DEVLINK_ESWITCH_MODE_SWITCHDEV;
462+
}
463+
426464
/**
427465
* ice_eswitch_release - cleanup eswitch
428466
* @pf: pointer to PF structure

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,13 @@ int
1515
ice_eswitch_mode_set(struct devlink *devlink, u16 mode,
1616
struct netlink_ext_ack *extack);
1717
bool ice_is_eswitch_mode_switchdev(struct ice_pf *pf);
18+
19+
void ice_eswitch_update_repr(struct ice_vsi *vsi);
1820
#else /* CONFIG_ICE_SWITCHDEV */
1921
static inline void ice_eswitch_release(struct ice_pf *pf) { }
2022

23+
static inline void ice_eswitch_update_repr(struct ice_vsi *vsi) { }
24+
2125
static inline int ice_eswitch_configure(struct ice_pf *pf)
2226
{
2327
return -EOPNOTSUPP;

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6061,7 +6061,8 @@ int ice_vsi_setup_tx_rings(struct ice_vsi *vsi)
60616061
if (!ring)
60626062
return -EINVAL;
60636063

6064-
ring->netdev = vsi->netdev;
6064+
if (vsi->netdev)
6065+
ring->netdev = vsi->netdev;
60656066
err = ice_setup_tx_ring(ring);
60666067
if (err)
60676068
break;
@@ -6092,7 +6093,8 @@ int ice_vsi_setup_rx_rings(struct ice_vsi *vsi)
60926093
if (!ring)
60936094
return -EINVAL;
60946095

6095-
ring->netdev = vsi->netdev;
6096+
if (vsi->netdev)
6097+
ring->netdev = vsi->netdev;
60966098
err = ice_setup_rx_ring(ring);
60976099
if (err)
60986100
break;

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "ice_lib.h"
77
#include "ice_fltr.h"
88
#include "ice_flow.h"
9+
#include "ice_eswitch.h"
910
#include "ice_virtchnl_allowlist.h"
1011

1112
#define FIELD_SELECTOR(proto_hdr_field) \
@@ -620,6 +621,8 @@ void ice_free_vfs(struct ice_pf *pf)
620621
if (!pf->vf)
621622
return;
622623

624+
ice_eswitch_release(pf);
625+
623626
while (test_and_set_bit(ICE_VF_DIS, pf->state))
624627
usleep_range(1000, 2000);
625628

@@ -932,6 +935,9 @@ static int ice_vf_rebuild_host_mac_cfg(struct ice_vf *vf)
932935
enum ice_status status;
933936
u8 broadcast[ETH_ALEN];
934937

938+
if (ice_is_eswitch_mode_switchdev(vf->pf))
939+
return 0;
940+
935941
eth_broadcast_addr(broadcast);
936942
status = ice_fltr_add_mac(vsi, broadcast, ICE_FWD_TO_VSI);
937943
if (status) {
@@ -1711,6 +1717,8 @@ bool ice_reset_vf(struct ice_vf *vf, bool is_vflr)
17111717
}
17121718

17131719
ice_vf_post_vsi_rebuild(vf);
1720+
vsi = ice_get_vf_vsi(vf);
1721+
ice_eswitch_update_repr(vsi);
17141722

17151723
/* if the VF has been reset allow it to come up again */
17161724
if (ice_mbx_clear_malvf(&hw->mbx_snapshot, pf->malvfs, ICE_MAX_VF_COUNT, vf->vf_id))
@@ -1962,6 +1970,10 @@ static int ice_ena_vfs(struct ice_pf *pf, u16 num_vfs)
19621970
}
19631971

19641972
clear_bit(ICE_VF_DIS, pf->state);
1973+
1974+
if (ice_eswitch_configure(pf))
1975+
goto err_unroll_sriov;
1976+
19651977
return 0;
19661978

19671979
err_unroll_sriov:
@@ -4783,6 +4795,11 @@ int ice_set_vf_mac(struct net_device *netdev, int vf_id, u8 *mac)
47834795
struct ice_vf *vf;
47844796
int ret;
47854797

4798+
if (ice_is_eswitch_mode_switchdev(pf)) {
4799+
dev_info(ice_pf_to_dev(pf), "Trusted VF is forbidden in switchdev mode\n");
4800+
return -EOPNOTSUPP;
4801+
}
4802+
47864803
if (ice_validate_vf_id(pf, vf_id))
47874804
return -EINVAL;
47884805

0 commit comments

Comments
 (0)