diff mbox series

[iwl-next,v3,4/4] ice: update representor when VSI is ready

Message ID 20240610074434.1962735-5-michal.swiatkowski@linux.intel.com (mailing list archive)
State Awaiting Upstream
Delegated to: Netdev Maintainers
Headers show
Series ice: prepare representor for SF support | expand

Checks

Context Check Description
netdev/series_format warning Target tree name not specified in the subject
netdev/tree_selection success Guessed tree name to be net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 866 this patch: 866
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers warning 4 maintainers not CCed: anthony.l.nguyen@intel.com pabeni@redhat.com jesse.brandeburg@intel.com edumazet@google.com
netdev/build_clang success Errors and warnings before: 868 this patch: 868
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 870 this patch: 870
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 66 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 41 this patch: 41
netdev/source_inline success Was 0 now: 0

Commit Message

Michal Swiatkowski June 10, 2024, 7:44 a.m. UTC
In case of reset of VF VSI can be reallocated. To handle this case it
should be properly updated.

Reload representor as vsi->vsi_num can be different than the one stored
when representor was created.

Instead of only changing antispoof do whole VSI configuration for
eswitch.

Signed-off-by: Michal Swiatkowski <michal.swiatkowski@linux.intel.com>
---
 drivers/net/ethernet/intel/ice/ice_eswitch.c | 21 +++++++++++++-------
 drivers/net/ethernet/intel/ice/ice_eswitch.h |  4 ++--
 drivers/net/ethernet/intel/ice/ice_vf_lib.c  |  2 +-
 3 files changed, 17 insertions(+), 10 deletions(-)

Comments

Simon Horman June 14, 2024, 12:47 p.m. UTC | #1
On Mon, Jun 10, 2024 at 09:44:34AM +0200, Michal Swiatkowski wrote:
> In case of reset of VF VSI can be reallocated. To handle this case it
> should be properly updated.
> 
> Reload representor as vsi->vsi_num can be different than the one stored
> when representor was created.
> 
> Instead of only changing antispoof do whole VSI configuration for
> eswitch.
> 
> Signed-off-by: Michal Swiatkowski <michal.swiatkowski@linux.intel.com>

Thanks Michal,

My comment below notwithstanding, this looks good to me.

Reviewed-by: Simon Horman <horms@kernel.org>

> ---
>  drivers/net/ethernet/intel/ice/ice_eswitch.c | 21 +++++++++++++-------
>  drivers/net/ethernet/intel/ice/ice_eswitch.h |  4 ++--
>  drivers/net/ethernet/intel/ice/ice_vf_lib.c  |  2 +-
>  3 files changed, 17 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/net/ethernet/intel/ice/ice_eswitch.c b/drivers/net/ethernet/intel/ice/ice_eswitch.c
> index 3f73f46111fc..4f539b1c7781 100644
> --- a/drivers/net/ethernet/intel/ice/ice_eswitch.c
> +++ b/drivers/net/ethernet/intel/ice/ice_eswitch.c
> @@ -178,16 +178,16 @@ void ice_eswitch_decfg_vsi(struct ice_vsi *vsi, const u8 *mac)
>   * @repr_id: representor ID
>   * @vsi: VSI for which port representor is configured
>   */
> -void ice_eswitch_update_repr(unsigned long repr_id, struct ice_vsi *vsi)
> +void ice_eswitch_update_repr(unsigned long *repr_id, struct ice_vsi *vsi)
>  {
>  	struct ice_pf *pf = vsi->back;
>  	struct ice_repr *repr;
> -	int ret;
> +	int err;
>  
>  	if (!ice_is_switchdev_running(pf))
>  		return;
>  
> -	repr = xa_load(&pf->eswitch.reprs, repr_id);
> +	repr = xa_load(&pf->eswitch.reprs, *repr_id);
>  	if (!repr)
>  		return;
>  
> @@ -197,12 +197,19 @@ void ice_eswitch_update_repr(unsigned long repr_id, struct ice_vsi *vsi)
>  	if (repr->br_port)
>  		repr->br_port->vsi = vsi;
>  
> -	ret = ice_vsi_update_security(vsi, ice_vsi_ctx_clear_antispoof);
> -	if (ret) {
> -		ice_fltr_add_mac_and_broadcast(vsi, repr->parent_mac,
> -					       ICE_FWD_TO_VSI);
> +	err = ice_eswitch_cfg_vsi(vsi, repr->parent_mac);
> +	if (err)
>  		dev_err(ice_pf_to_dev(pf), "Failed to update VSI of port representor %d",
>  			repr->id);
> +
> +	/* The VSI number is different, reload the PR with new id */
> +	if (repr->id != vsi->vsi_num) {
> +		xa_erase(&pf->eswitch.reprs, repr->id);
> +		repr->id = vsi->vsi_num;
> +		if (xa_insert(&pf->eswitch.reprs, repr->id, repr, GFP_KERNEL))
> +			dev_err(ice_pf_to_dev(pf), "Failed to reload port representor %d",
> +				repr->id);
> +		*repr_id = repr->id;
>  	}
>  }

FWIIW, I think it would be nicer if ice_eswitch_decfg_vsi returned
the repr_id rather than passing repr_id by reference. This is because,
in general, I think it's nicer to reduce side-effects of functions.

...
Michal Swiatkowski June 21, 2024, 4:32 a.m. UTC | #2
On Fri, Jun 14, 2024 at 01:47:16PM +0100, Simon Horman wrote:
> On Mon, Jun 10, 2024 at 09:44:34AM +0200, Michal Swiatkowski wrote:
> > In case of reset of VF VSI can be reallocated. To handle this case it
> > should be properly updated.
> > 
> > Reload representor as vsi->vsi_num can be different than the one stored
> > when representor was created.
> > 
> > Instead of only changing antispoof do whole VSI configuration for
> > eswitch.
> > 
> > Signed-off-by: Michal Swiatkowski <michal.swiatkowski@linux.intel.com>
> 
> Thanks Michal,
> 
> My comment below notwithstanding, this looks good to me.
> 
> Reviewed-by: Simon Horman <horms@kernel.org>
> 
> > ---
> >  drivers/net/ethernet/intel/ice/ice_eswitch.c | 21 +++++++++++++-------
> >  drivers/net/ethernet/intel/ice/ice_eswitch.h |  4 ++--
> >  drivers/net/ethernet/intel/ice/ice_vf_lib.c  |  2 +-
> >  3 files changed, 17 insertions(+), 10 deletions(-)
> > 
> > diff --git a/drivers/net/ethernet/intel/ice/ice_eswitch.c b/drivers/net/ethernet/intel/ice/ice_eswitch.c
> > index 3f73f46111fc..4f539b1c7781 100644
> > --- a/drivers/net/ethernet/intel/ice/ice_eswitch.c
> > +++ b/drivers/net/ethernet/intel/ice/ice_eswitch.c
> > @@ -178,16 +178,16 @@ void ice_eswitch_decfg_vsi(struct ice_vsi *vsi, const u8 *mac)
> >   * @repr_id: representor ID
> >   * @vsi: VSI for which port representor is configured
> >   */
> > -void ice_eswitch_update_repr(unsigned long repr_id, struct ice_vsi *vsi)
> > +void ice_eswitch_update_repr(unsigned long *repr_id, struct ice_vsi *vsi)
> >  {
> >  	struct ice_pf *pf = vsi->back;
> >  	struct ice_repr *repr;
> > -	int ret;
> > +	int err;
> >  
> >  	if (!ice_is_switchdev_running(pf))
> >  		return;
> >  
> > -	repr = xa_load(&pf->eswitch.reprs, repr_id);
> > +	repr = xa_load(&pf->eswitch.reprs, *repr_id);
> >  	if (!repr)
> >  		return;
> >  
> > @@ -197,12 +197,19 @@ void ice_eswitch_update_repr(unsigned long repr_id, struct ice_vsi *vsi)
> >  	if (repr->br_port)
> >  		repr->br_port->vsi = vsi;
> >  
> > -	ret = ice_vsi_update_security(vsi, ice_vsi_ctx_clear_antispoof);
> > -	if (ret) {
> > -		ice_fltr_add_mac_and_broadcast(vsi, repr->parent_mac,
> > -					       ICE_FWD_TO_VSI);
> > +	err = ice_eswitch_cfg_vsi(vsi, repr->parent_mac);
> > +	if (err)
> >  		dev_err(ice_pf_to_dev(pf), "Failed to update VSI of port representor %d",
> >  			repr->id);
> > +
> > +	/* The VSI number is different, reload the PR with new id */
> > +	if (repr->id != vsi->vsi_num) {
> > +		xa_erase(&pf->eswitch.reprs, repr->id);
> > +		repr->id = vsi->vsi_num;
> > +		if (xa_insert(&pf->eswitch.reprs, repr->id, repr, GFP_KERNEL))
> > +			dev_err(ice_pf_to_dev(pf), "Failed to reload port representor %d",
> > +				repr->id);
> > +		*repr_id = repr->id;
> >  	}
> >  }
> 
> FWIIW, I think it would be nicer if ice_eswitch_decfg_vsi returned
> the repr_id rather than passing repr_id by reference. This is because,
> in general, I think it's nicer to reduce side-effects of functions.
> 

I wanted to change repr->id and the vf (or sf) repr id in the same
place. But in general I agree with your comment.

Thanks,
Michal

> ...
diff mbox series

Patch

diff --git a/drivers/net/ethernet/intel/ice/ice_eswitch.c b/drivers/net/ethernet/intel/ice/ice_eswitch.c
index 3f73f46111fc..4f539b1c7781 100644
--- a/drivers/net/ethernet/intel/ice/ice_eswitch.c
+++ b/drivers/net/ethernet/intel/ice/ice_eswitch.c
@@ -178,16 +178,16 @@  void ice_eswitch_decfg_vsi(struct ice_vsi *vsi, const u8 *mac)
  * @repr_id: representor ID
  * @vsi: VSI for which port representor is configured
  */
-void ice_eswitch_update_repr(unsigned long repr_id, struct ice_vsi *vsi)
+void ice_eswitch_update_repr(unsigned long *repr_id, struct ice_vsi *vsi)
 {
 	struct ice_pf *pf = vsi->back;
 	struct ice_repr *repr;
-	int ret;
+	int err;
 
 	if (!ice_is_switchdev_running(pf))
 		return;
 
-	repr = xa_load(&pf->eswitch.reprs, repr_id);
+	repr = xa_load(&pf->eswitch.reprs, *repr_id);
 	if (!repr)
 		return;
 
@@ -197,12 +197,19 @@  void ice_eswitch_update_repr(unsigned long repr_id, struct ice_vsi *vsi)
 	if (repr->br_port)
 		repr->br_port->vsi = vsi;
 
-	ret = ice_vsi_update_security(vsi, ice_vsi_ctx_clear_antispoof);
-	if (ret) {
-		ice_fltr_add_mac_and_broadcast(vsi, repr->parent_mac,
-					       ICE_FWD_TO_VSI);
+	err = ice_eswitch_cfg_vsi(vsi, repr->parent_mac);
+	if (err)
 		dev_err(ice_pf_to_dev(pf), "Failed to update VSI of port representor %d",
 			repr->id);
+
+	/* The VSI number is different, reload the PR with new id */
+	if (repr->id != vsi->vsi_num) {
+		xa_erase(&pf->eswitch.reprs, repr->id);
+		repr->id = vsi->vsi_num;
+		if (xa_insert(&pf->eswitch.reprs, repr->id, repr, GFP_KERNEL))
+			dev_err(ice_pf_to_dev(pf), "Failed to reload port representor %d",
+				repr->id);
+		*repr_id = repr->id;
 	}
 }
 
diff --git a/drivers/net/ethernet/intel/ice/ice_eswitch.h b/drivers/net/ethernet/intel/ice/ice_eswitch.h
index 9a25606e9740..09194d514f9b 100644
--- a/drivers/net/ethernet/intel/ice/ice_eswitch.h
+++ b/drivers/net/ethernet/intel/ice/ice_eswitch.h
@@ -18,7 +18,7 @@  ice_eswitch_mode_set(struct devlink *devlink, u16 mode,
 		     struct netlink_ext_ack *extack);
 bool ice_is_eswitch_mode_switchdev(struct ice_pf *pf);
 
-void ice_eswitch_update_repr(unsigned long repr_id, struct ice_vsi *vsi);
+void ice_eswitch_update_repr(unsigned long *repr_id, struct ice_vsi *vsi);
 
 void ice_eswitch_stop_all_tx_queues(struct ice_pf *pf);
 
@@ -47,7 +47,7 @@  ice_eswitch_set_target_vsi(struct sk_buff *skb,
 			   struct ice_tx_offload_params *off) { }
 
 static inline void
-ice_eswitch_update_repr(unsigned long repr_id, struct ice_vsi *vsi) { }
+ice_eswitch_update_repr(unsigned long *repr_id, struct ice_vsi *vsi) { }
 
 static inline int ice_eswitch_configure(struct ice_pf *pf)
 {
diff --git a/drivers/net/ethernet/intel/ice/ice_vf_lib.c b/drivers/net/ethernet/intel/ice/ice_vf_lib.c
index 48a8d462d76a..5635e9da2212 100644
--- a/drivers/net/ethernet/intel/ice/ice_vf_lib.c
+++ b/drivers/net/ethernet/intel/ice/ice_vf_lib.c
@@ -948,7 +948,7 @@  int ice_reset_vf(struct ice_vf *vf, u32 flags)
 		goto out_unlock;
 	}
 
-	ice_eswitch_update_repr(vf->repr_id, vsi);
+	ice_eswitch_update_repr(&vf->repr_id, vsi);
 
 	/* if the VF has been reset allow it to come up again */
 	ice_mbx_clear_malvf(&vf->mbx_info);