diff mbox series

[net-next,v2] iavf: Add helper to check if iavf_remove() is in progress

Message ID 20220608075358.2983111-1-jedrzej.jagielski@intel.com
State Deferred
Headers show
Series [net-next,v2] iavf: Add helper to check if iavf_remove() is in progress | expand

Commit Message

Jedrzej Jagielski June 8, 2022, 7:53 a.m. UTC
From: Brett Creeley <brett.creeley@intel.com>

Currently the driver checks if the __IAVF_IN_REMOVE_TASK bit is set in
the adapter's crit_section bitmap. This is fine, but if the
implementation were to ever change, i.e. a mutex was introduced all of
the callers of test_bit(__IAVF_IN_REMOVE_TASK, &adapter->crit_section)
would have to change. Fix this by introducing the
iavf_is_remove_in_progress() helper function.

Signed-off-by: Brett Creeley <brett.creeley@intel.com>
Signed-off-by: Jedrzej Jagielski <jedrzej.jagielski@intel.com>
---
 drivers/net/ethernet/intel/iavf/iavf.h      |  1 +
 drivers/net/ethernet/intel/iavf/iavf_main.c | 17 ++++++++++++-----
 2 files changed, 13 insertions(+), 5 deletions(-)

Comments

Tony Nguyen June 8, 2022, 10:52 p.m. UTC | #1
On 6/8/2022 12:53 AM, Jedrzej Jagielski wrote:
> From: Brett Creeley <brett.creeley@intel.com>
> 
> Currently the driver checks if the __IAVF_IN_REMOVE_TASK bit is set in
> the adapter's crit_section bitmap. This is fine, but if the
> implementation were to ever change, i.e. a mutex was introduced all of
> the callers of test_bit(__IAVF_IN_REMOVE_TASK, &adapter->crit_section)
> would have to change. Fix this by introducing the
> iavf_is_remove_in_progress() helper function.

If you want this to match what you sent in the original series [1], 
please wait until the net patch [2] is applied before sending this. This 
will allow you to change the __iavf_setup_tc() call as well.

> Signed-off-by: Brett Creeley <brett.creeley@intel.com>
> Signed-off-by: Jedrzej Jagielski <jedrzej.jagielski@intel.com>

[1] 
https://lore.kernel.org/intel-wired-lan/DM6PR11MB27315C25DD0EA44B086A5501F0DC9@DM6PR11MB2731.namprd11.prod.outlook.com/T/#mae4f93d5c5fcc6c3ef13f9e1af1938558f1e975f
[2] 
https://lore.kernel.org/intel-wired-lan/20220608095337.2986633-1-jedrzej.jagielski@intel.com/T/#u
Jedrzej Jagielski June 9, 2022, 8:04 a.m. UTC | #2
>On 6/8/2022 12:53 AM, Jedrzej Jagielski wrote:
>> From: Brett Creeley <brett.creeley@intel.com>
>> 
>> Currently the driver checks if the __IAVF_IN_REMOVE_TASK bit is set in
>> the adapter's crit_section bitmap. This is fine, but if the
>> implementation were to ever change, i.e. a mutex was introduced all of
>> the callers of test_bit(__IAVF_IN_REMOVE_TASK, &adapter->crit_section)
>> would have to change. Fix this by introducing the
>> iavf_is_remove_in_progress() helper function.
>
>If you want this to match what you sent in the original series [1], 
>please wait until the net patch [2] is applied before sending this. This 
>will allow you to change the __iavf_setup_tc() call as well.

Sure, I will send amended version after mentioned patch will
be applied to tree.

>
>> Signed-off-by: Brett Creeley <brett.creeley@intel.com>
>> Signed-off-by: Jedrzej Jagielski <jedrzej.jagielski@intel.com>
>
>[1] 
>https://lore.kernel.org/intel-wired-lan/DM6PR11MB27315C25DD0EA44B086A5501F0DC9@DM6PR11MB2731.namprd11.prod.outlook.com/T/#mae4f93d5c5fcc6c3ef13f9e1af1938558f1e975f
>[2] 
>https://lore.kernel.org/intel-wired-lan/20220608095337.2986633-1-jedrzej.jagielski@intel.com/T/#u
>
diff mbox series

Patch

diff --git a/drivers/net/ethernet/intel/iavf/iavf.h b/drivers/net/ethernet/intel/iavf/iavf.h
index fda1198d2c00..431182461462 100644
--- a/drivers/net/ethernet/intel/iavf/iavf.h
+++ b/drivers/net/ethernet/intel/iavf/iavf.h
@@ -505,6 +505,7 @@  int iavf_parse_vf_resource_msg(struct iavf_adapter *adapter);
 void iavf_schedule_reset(struct iavf_adapter *adapter);
 void iavf_schedule_request_stats(struct iavf_adapter *adapter);
 void iavf_reset(struct iavf_adapter *adapter);
+bool iavf_is_remove_in_progress(struct iavf_adapter *adapter);
 void iavf_set_ethtool_ops(struct net_device *netdev);
 void iavf_update_stats(struct iavf_adapter *adapter);
 void iavf_reset_interrupt_capability(struct iavf_adapter *adapter);
diff --git a/drivers/net/ethernet/intel/iavf/iavf_main.c b/drivers/net/ethernet/intel/iavf/iavf_main.c
index 9f7ef52f12b9..b99d7434de44 100644
--- a/drivers/net/ethernet/intel/iavf/iavf_main.c
+++ b/drivers/net/ethernet/intel/iavf/iavf_main.c
@@ -268,6 +268,15 @@  int iavf_lock_timeout(struct mutex *lock, unsigned int msecs)
 	return -1;
 }
 
+/**
+ * iavf_is_remove_in_progress - Check if a iavf_remove() is in progress
+ * @adapter: board private structure
+ */
+bool iavf_is_remove_in_progress(struct iavf_adapter *adapter)
+{
+	return test_bit(__IAVF_IN_REMOVE_TASK, &adapter->crit_section);
+}
+
 /**
  * iavf_schedule_reset - Set the flags and schedule a reset event
  * @adapter: board private structure
@@ -2676,8 +2685,7 @@  static void iavf_watchdog_task(struct work_struct *work)
 				   msecs_to_jiffies(1));
 		return;
 	case __IAVF_INIT_FAILED:
-		if (test_bit(__IAVF_IN_REMOVE_TASK,
-			     &adapter->crit_section)) {
+		if (iavf_is_remove_in_progress(adapter)) {
 			/* Do not update the state and do not reschedule
 			 * watchdog task, iavf_remove should handle this state
 			 * as it can loop forever
@@ -2701,8 +2709,7 @@  static void iavf_watchdog_task(struct work_struct *work)
 		queue_delayed_work(iavf_wq, &adapter->watchdog_task, HZ);
 		return;
 	case __IAVF_COMM_FAILED:
-		if (test_bit(__IAVF_IN_REMOVE_TASK,
-			     &adapter->crit_section)) {
+		if (iavf_is_remove_in_progress(adapter)) {
 			/* Set state to __IAVF_INIT_FAILED and perform remove
 			 * steps. Remove IAVF_FLAG_PF_COMMS_FAILED so the task
 			 * doesn't bring the state back to __IAVF_COMM_FAILED.
@@ -3145,7 +3152,7 @@  static void iavf_adminq_task(struct work_struct *work)
 
 	if ((adapter->flags & IAVF_FLAG_SETUP_NETDEV_FEATURES)) {
 		if (adapter->netdev_registered ||
-		    !test_bit(__IAVF_IN_REMOVE_TASK, &adapter->crit_section)) {
+		    !iavf_is_remove_in_progress(adapter)) {
 			struct net_device *netdev = adapter->netdev;
 
 			rtnl_lock();