Intel-Wired-Lan Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Tony Nguyen <anthony.l.nguyen@intel.com>
To: intel-wired-lan@osuosl.org
Subject: [Intel-wired-lan] [PATCH S56 09/13] ice: Add new VSI states to track netdev alloc/registration
Date: Tue,  2 Mar 2021 10:15:41 -0800	[thread overview]
Message-ID: <20210302181545.51822-9-anthony.l.nguyen@intel.com> (raw)
In-Reply-To: <20210302181545.51822-1-anthony.l.nguyen@intel.com>

From: Anirudh Venkataramanan <anirudh.venkataramanan@intel.com>

Add two new VSI states, one to track if a netdev for the VSI has been
allocated and the other to track if the netdev has been registered.
Call unregister_netdev/free_netdev only when the corresponding state
bits are set.

Signed-off-by: Anirudh Venkataramanan <anirudh.venkataramanan@intel.com>
---
 drivers/net/ethernet/intel/ice/ice.h      |  2 ++
 drivers/net/ethernet/intel/ice/ice_lib.c  | 21 +++++++++++++++------
 drivers/net/ethernet/intel/ice/ice_main.c |  5 +++++
 3 files changed, 22 insertions(+), 6 deletions(-)

diff --git a/drivers/net/ethernet/intel/ice/ice.h b/drivers/net/ethernet/intel/ice/ice.h
index 89ffc96702fa..79652b72c38b 100644
--- a/drivers/net/ethernet/intel/ice/ice.h
+++ b/drivers/net/ethernet/intel/ice/ice.h
@@ -238,6 +238,8 @@ enum ice_pf_state {
 enum ice_vsi_state {
 	ICE_VSI_DOWN,
 	ICE_VSI_NEEDS_RESTART,
+	ICE_VSI_NETDEV_ALLOCD,
+	ICE_VSI_NETDEV_REGISTERED,
 	ICE_VSI_UMAC_FLTR_CHANGED,
 	ICE_VSI_MMAC_FLTR_CHANGED,
 	ICE_VSI_VLAN_FLTR_CHANGED,
diff --git a/drivers/net/ethernet/intel/ice/ice_lib.c b/drivers/net/ethernet/intel/ice/ice_lib.c
index ddcbd5bfd058..4136ab9b2950 100644
--- a/drivers/net/ethernet/intel/ice/ice_lib.c
+++ b/drivers/net/ethernet/intel/ice/ice_lib.c
@@ -2775,11 +2775,14 @@ int ice_vsi_release(struct ice_vsi *vsi)
 	 * PF that is running the work queue items currently. This is done to
 	 * avoid check_flush_dependency() warning on this wq
 	 */
-	if (vsi->netdev && !ice_is_reset_in_progress(pf->state)) {
+	if (vsi->netdev && !ice_is_reset_in_progress(pf->state) &&
+	    (test_bit(ICE_VSI_NETDEV_REGISTERED, vsi->state))) {
 		unregister_netdev(vsi->netdev);
-		ice_devlink_destroy_port(vsi);
+		clear_bit(ICE_VSI_NETDEV_REGISTERED, vsi->state);
 	}
 
+	ice_devlink_destroy_port(vsi);
+
 	if (test_bit(ICE_FLAG_RSS_ENA, pf->flags))
 		ice_rss_clean(vsi);
 
@@ -2834,10 +2837,16 @@ int ice_vsi_release(struct ice_vsi *vsi)
 	ice_vsi_delete(vsi);
 	ice_vsi_free_q_vectors(vsi);
 
-	/* make sure unregister_netdev() was called by checking ICE_DOWN */
-	if (vsi->netdev && test_bit(ICE_VSI_DOWN, vsi->state)) {
-		free_netdev(vsi->netdev);
-		vsi->netdev = NULL;
+	if (vsi->netdev) {
+		if (test_bit(ICE_VSI_NETDEV_REGISTERED, vsi->state)) {
+			unregister_netdev(vsi->netdev);
+			clear_bit(ICE_VSI_NETDEV_REGISTERED, vsi->state);
+		}
+		if (test_bit(ICE_VSI_NETDEV_ALLOCD, vsi->state)) {
+			free_netdev(vsi->netdev);
+			vsi->netdev = NULL;
+			clear_bit(ICE_VSI_NETDEV_ALLOCD, vsi->state);
+		}
 	}
 
 	if (vsi->type == ICE_VSI_VF &&
diff --git a/drivers/net/ethernet/intel/ice/ice_main.c b/drivers/net/ethernet/intel/ice/ice_main.c
index 1018b6da7362..4f35a4de33ab 100644
--- a/drivers/net/ethernet/intel/ice/ice_main.c
+++ b/drivers/net/ethernet/intel/ice/ice_main.c
@@ -2997,6 +2997,7 @@ static int ice_cfg_netdev(struct ice_vsi *vsi)
 	if (!netdev)
 		return -ENOMEM;
 
+	set_bit(ICE_VSI_NETDEV_ALLOCD, vsi->state);
 	vsi->netdev = netdev;
 	np = netdev_priv(netdev);
 	np->vsi = vsi;
@@ -3221,6 +3222,7 @@ static int ice_setup_pf_sw(struct ice_pf *pf)
 	if (vsi) {
 		ice_napi_del(vsi);
 		if (vsi->netdev) {
+			clear_bit(ICE_VSI_NETDEV_ALLOCD, vsi->state);
 			free_netdev(vsi->netdev);
 			vsi->netdev = NULL;
 		}
@@ -3990,6 +3992,7 @@ static int ice_register_netdev(struct ice_pf *pf)
 	if (err)
 		goto err_register_netdev;
 
+	set_bit(ICE_VSI_NETDEV_REGISTERED, vsi->state);
 	netif_carrier_off(vsi->netdev);
 	netif_tx_stop_all_queues(vsi->netdev);
 	err = ice_devlink_create_port(vsi);
@@ -4001,9 +4004,11 @@ static int ice_register_netdev(struct ice_pf *pf)
 	return 0;
 err_devlink_create:
 	unregister_netdev(vsi->netdev);
+	clear_bit(ICE_VSI_NETDEV_REGISTERED, vsi->state);
 err_register_netdev:
 	free_netdev(vsi->netdev);
 	vsi->netdev = NULL;
+	clear_bit(ICE_VSI_NETDEV_ALLOCD, vsi->state);
 	return err;
 }
 
-- 
2.20.1


  parent reply	other threads:[~2021-03-02 18:15 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-02 18:15 [Intel-wired-lan] [PATCH S56 01/13] ice: Change ice_vsi_setup_q_map() to not depend on RSS Tony Nguyen
2021-03-02 18:15 ` [Intel-wired-lan] [PATCH S56 02/13] ice: Refactor promiscuous functions Tony Nguyen
2021-03-13  0:04   ` Brelinski, TonyX
2021-04-19 18:51   ` Jankowski, Konrad0
2021-03-02 18:15 ` [Intel-wired-lan] [PATCH S56 03/13] ice: Refactor get/set RSS LUT to use struct parameter Tony Nguyen
2021-03-13  0:05   ` Brelinski, TonyX
2021-03-02 18:15 ` [Intel-wired-lan] [PATCH S56 04/13] ice: Refactor ice_set/get_rss into LUT and key specific functions Tony Nguyen
2021-03-13  0:07   ` Brelinski, TonyX
2021-03-02 18:15 ` [Intel-wired-lan] [PATCH S56 05/13] ice: Consolidate VSI state and flags Tony Nguyen
2021-03-13  0:09   ` Brelinski, TonyX
2021-03-02 18:15 ` [Intel-wired-lan] [PATCH S56 06/13] ice: Drop leading underscores in enum ice_pf_state Tony Nguyen
2021-03-13  0:10   ` Brelinski, TonyX
2021-03-02 18:15 ` [Intel-wired-lan] [PATCH S56 07/13] ice: Add helper function to get the VF's VSI Tony Nguyen
2021-04-21 18:48   ` Jankowski, Konrad0
2021-03-02 18:15 ` [Intel-wired-lan] [PATCH S56 08/13] ice: Refactor VIRTCHNL_OP_CONFIG_VSI_QUEUES handling Tony Nguyen
2021-04-21 18:47   ` Jankowski, Konrad0
2021-03-02 18:15 ` Tony Nguyen [this message]
2021-03-13  0:12   ` [Intel-wired-lan] [PATCH S56 09/13] ice: Add new VSI states to track netdev alloc/registration Brelinski, TonyX
2021-03-02 18:15 ` [Intel-wired-lan] [PATCH S56 10/13] ice: cleanup style issues Tony Nguyen
2021-03-13  0:13   ` Brelinski, TonyX
2021-03-02 18:15 ` [Intel-wired-lan] [PATCH S56 11/13] ice: Correct comment block style Tony Nguyen
2021-03-13  0:16   ` Brelinski, TonyX
2021-03-02 18:15 ` [Intel-wired-lan] [PATCH S56 12/13] ice: Remove unnecessary blank line Tony Nguyen
2021-03-13  0:17   ` Brelinski, TonyX
2021-03-02 18:15 ` [Intel-wired-lan] [PATCH S56 13/13] ice: Fix prototype warnings Tony Nguyen
2021-03-13  0:18   ` Brelinski, TonyX
2021-03-12  0:40 ` [Intel-wired-lan] [PATCH S56 01/13] ice: Change ice_vsi_setup_q_map() to not depend on RSS Brelinski, TonyX

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210302181545.51822-9-anthony.l.nguyen@intel.com \
    --to=anthony.l.nguyen@intel.com \
    --cc=intel-wired-lan@osuosl.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox