diff mbox

[v2,01/20] mwifiex: reunite copy-and-pasted remove/reset code

Message ID 20170725011336.99993-2-briannorris@chromium.org (mailing list archive)
State Accepted
Commit b6658b66d8a6eaaf216382c19d016116931a0f63
Delegated to: Kalle Valo
Headers show

Commit Message

Brian Norris July 25, 2017, 1:13 a.m. UTC
When PCIe FLR code was added, it explicitly copy-and-pasted much of
mwifiex_remove_card() into mwifiex_shutdown_sw(). This is unnecessary,
as almost all of the code should be reused.

Let's reunite what we can for now.

The only functional changes for now:

 * call netif_device_detach() in the remove() code path -- this wasn't
   done before, but it really should be a no-op, when the device is
   getting totally unregistered soon anyway

 * call the ->down_dev() driver callback only after we've finished all
   SW teardown -- this should have no significant effect, since the only
   user (pcie.c) does very minimal work there, and it doesn't matter
   that we reorder this

Signed-off-by: Brian Norris <briannorris@chromium.org>
---
v2: no change
---
 drivers/net/wireless/marvell/mwifiex/main.c | 104 ++++++++--------------------
 1 file changed, 28 insertions(+), 76 deletions(-)

Comments

Kalle Valo July 28, 2017, 2:49 p.m. UTC | #1
Brian Norris <briannorris@chromium.org> wrote:

> When PCIe FLR code was added, it explicitly copy-and-pasted much of
> mwifiex_remove_card() into mwifiex_shutdown_sw(). This is unnecessary,
> as almost all of the code should be reused.
> 
> Let's reunite what we can for now.
> 
> The only functional changes for now:
> 
>  * call netif_device_detach() in the remove() code path -- this wasn't
>    done before, but it really should be a no-op, when the device is
>    getting totally unregistered soon anyway
> 
>  * call the ->down_dev() driver callback only after we've finished all
>    SW teardown -- this should have no significant effect, since the only
>    user (pcie.c) does very minimal work there, and it doesn't matter
>    that we reorder this
> 
> Signed-off-by: Brian Norris <briannorris@chromium.org>

20 patches applied to wireless-drivers-next.git, thanks.

b6658b66d8a6 mwifiex: reunite copy-and-pasted remove/reset code
4b1f5a0d2eeb mwifiex: reset interrupt status across device reset
7dc4a6b5ca94 mwifiex: pcie: don't allow cmd buffer reuse after reset
643acea6297f mwifiex: re-register wiphy across reset
ce32d1d83702 mwifiex: unregister wiphy before freeing resources
6417dba33538 mwifiex: don't short-circuit netdev notifiers on interface deletion
c253a62da9b4 mwifiex: fixup init_channel_scan_gap error case
9557d9f2e62b mwifiex: ensure "disable auto DS" struct is initialized
5e6588b9d4ab mwifiex: fix misnomers in mwifiex_free_lock_list()
f7d7e4b689ca mwifiex: make mwifiex_free_cmd_buffer() return void
fe8d730adaee mwifiex: utilize netif_tx_{wake,stop}_all_queues()
8395fd9b194c mwifiex: don't open-code ARRAY_SIZE()
463df4719084 mwifiex: drop 'add_tail' param from mwifiex_insert_cmd_to_pending_q()
605db27f7405 mwifiex: pcie: remove unnecessary masks
87a602126aaf mwifiex: pcie: unify MSI-X / non-MSI-X interrupt process
37680819c6e1 mwifiex: debugfs: allow card_reset() to cancel things
2f47150ab3ef mwifiex: pcie: disable device DMA before unmapping/freeing buffers
43a0c9aea64d mwifiex: pcie: remove unnecessary 'pdev' check
2d98cfd17e92 mwifiex: keep mwifiex_cancel_pending_ioctl() static
0bc03cfd8247 mwifiex: drop num CPU notice
diff mbox

Patch

diff --git a/drivers/net/wireless/marvell/mwifiex/main.c b/drivers/net/wireless/marvell/mwifiex/main.c
index f2600b827e81..8615099468da 100644
--- a/drivers/net/wireless/marvell/mwifiex/main.c
+++ b/drivers/net/wireless/marvell/mwifiex/main.c
@@ -1352,26 +1352,12 @@  static void mwifiex_main_work_queue(struct work_struct *work)
 	mwifiex_main_process(adapter);
 }
 
-/*
- * This function gets called during PCIe function level reset. Required
- * code is extracted from mwifiex_remove_card()
- */
-int
-mwifiex_shutdown_sw(struct mwifiex_adapter *adapter)
+/* Common teardown code used for both device removal and reset */
+static void mwifiex_uninit_sw(struct mwifiex_adapter *adapter)
 {
 	struct mwifiex_private *priv;
 	int i;
 
-	if (!adapter)
-		goto exit_return;
-
-	wait_for_completion(adapter->fw_done);
-	/* Caller should ensure we aren't suspending while this happens */
-	reinit_completion(adapter->fw_done);
-
-	priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
-	mwifiex_deauthenticate(priv, NULL);
-
 	/* We can no longer handle interrupts once we start doing the teardown
 	 * below.
 	 */
@@ -1393,12 +1379,9 @@  mwifiex_shutdown_sw(struct mwifiex_adapter *adapter)
 	}
 
 	mwifiex_dbg(adapter, CMD, "cmd: calling mwifiex_shutdown_drv...\n");
-
 	mwifiex_shutdown_drv(adapter);
-	if (adapter->if_ops.down_dev)
-		adapter->if_ops.down_dev(adapter);
-
 	mwifiex_dbg(adapter, CMD, "cmd: mwifiex_shutdown_drv done\n");
+
 	if (atomic_read(&adapter->rx_pending) ||
 	    atomic_read(&adapter->tx_pending) ||
 	    atomic_read(&adapter->cmd_pending)) {
@@ -1421,9 +1404,30 @@  mwifiex_shutdown_sw(struct mwifiex_adapter *adapter)
 		rtnl_unlock();
 	}
 	vfree(adapter->chan_stats);
+}
+
+/*
+ * This function gets called during PCIe function level reset.
+ */
+int mwifiex_shutdown_sw(struct mwifiex_adapter *adapter)
+{
+	struct mwifiex_private *priv;
+
+	if (!adapter)
+		return 0;
+
+	wait_for_completion(adapter->fw_done);
+	/* Caller should ensure we aren't suspending while this happens */
+	reinit_completion(adapter->fw_done);
+
+	priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
+	mwifiex_deauthenticate(priv, NULL);
+
+	mwifiex_uninit_sw(adapter);
+
+	if (adapter->if_ops.down_dev)
+		adapter->if_ops.down_dev(adapter);
 
-	mwifiex_dbg(adapter, INFO, "%s, successful\n", __func__);
-exit_return:
 	return 0;
 }
 EXPORT_SYMBOL_GPL(mwifiex_shutdown_sw);
@@ -1676,61 +1680,10 @@  EXPORT_SYMBOL_GPL(mwifiex_add_card);
  */
 int mwifiex_remove_card(struct mwifiex_adapter *adapter)
 {
-	struct mwifiex_private *priv = NULL;
-	int i;
-
 	if (!adapter)
-		goto exit_remove;
-
-	/* We can no longer handle interrupts once we start doing the teardown
-	 * below. */
-	if (adapter->if_ops.disable_int)
-		adapter->if_ops.disable_int(adapter);
-
-	adapter->surprise_removed = true;
-
-	mwifiex_terminate_workqueue(adapter);
-
-	/* Stop data */
-	for (i = 0; i < adapter->priv_num; i++) {
-		priv = adapter->priv[i];
-		if (priv && priv->netdev) {
-			mwifiex_stop_net_dev_queue(priv->netdev, adapter);
-			if (netif_carrier_ok(priv->netdev))
-				netif_carrier_off(priv->netdev);
-		}
-	}
-
-	mwifiex_dbg(adapter, CMD,
-		    "cmd: calling mwifiex_shutdown_drv...\n");
-
-	mwifiex_shutdown_drv(adapter);
-	mwifiex_dbg(adapter, CMD,
-		    "cmd: mwifiex_shutdown_drv done\n");
-	if (atomic_read(&adapter->rx_pending) ||
-	    atomic_read(&adapter->tx_pending) ||
-	    atomic_read(&adapter->cmd_pending)) {
-		mwifiex_dbg(adapter, ERROR,
-			    "rx_pending=%d, tx_pending=%d,\t"
-			    "cmd_pending=%d\n",
-			    atomic_read(&adapter->rx_pending),
-			    atomic_read(&adapter->tx_pending),
-			    atomic_read(&adapter->cmd_pending));
-	}
-
-	for (i = 0; i < adapter->priv_num; i++) {
-		priv = adapter->priv[i];
-
-		if (!priv)
-			continue;
+		return 0;
 
-		rtnl_lock();
-		if (priv->netdev &&
-		    priv->wdev.iftype != NL80211_IFTYPE_UNSPECIFIED)
-			mwifiex_del_virtual_intf(adapter->wiphy, &priv->wdev);
-		rtnl_unlock();
-	}
-	vfree(adapter->chan_stats);
+	mwifiex_uninit_sw(adapter);
 
 	wiphy_unregister(adapter->wiphy);
 	wiphy_free(adapter->wiphy);
@@ -1748,7 +1701,6 @@  int mwifiex_remove_card(struct mwifiex_adapter *adapter)
 		    "info: free adapter\n");
 	mwifiex_free_adapter(adapter);
 
-exit_remove:
 	return 0;
 }
 EXPORT_SYMBOL_GPL(mwifiex_remove_card);