aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWerner Almesberger <werner@openmoko.org>2009-04-02 08:12:12 -0300
committerWerner Almesberger <werner@openmoko.org>2009-04-02 08:12:12 -0300
commit9c4451ff31b937a478f3d3eabef30b71cbe12b12 (patch)
tree2409cc4001a17469eece6dad3d063646d7d94567
parent60c66130a4467ca2a2994a6e3d7d5ac63839eefb (diff)
AR6000: move low-level cleanup from ar6000_destroy to ar6000_close
A network device is supposed to disable its internals in the "close" function. Doing so affords us protection against various races, including the ioctl vs. rfkill conflict reported by Michael. Signed-off-by: Werner Almesberger <werner@openmoko.org> Reported-by: Michael Trimarch <michael@panicking.kicks-ass.org>
-rw-r--r--drivers/ar6000/ar6000/ar6000_drv.c150
1 files changed, 76 insertions, 74 deletions
diff --git a/drivers/ar6000/ar6000/ar6000_drv.c b/drivers/ar6000/ar6000/ar6000_drv.c
index 21504f221dd..b790670ece8 100644
--- a/drivers/ar6000/ar6000/ar6000_drv.c
+++ b/drivers/ar6000/ar6000/ar6000_drv.c
@@ -974,86 +974,17 @@ ar6000_destroy(struct net_device *dev, unsigned int unregister)
return;
}
- /* Stop the transmit queues */
- netif_stop_queue(dev);
-
- /* Disable the target and the interrupts associated with it */
- if (ar->arWmiReady == TRUE)
- {
- if (!bypasswmi)
- {
- if (ar->arConnected == TRUE || ar->arConnectPending == TRUE)
- {
- AR_DEBUG_PRINTF("%s(): Disconnect\n", __func__);
- AR6000_SPIN_LOCK(&ar->arLock, 0);
- ar6000_init_profile_info(ar);
- AR6000_SPIN_UNLOCK(&ar->arLock, 0);
- wmi_disconnect_cmd(ar->arWmi);
- }
-
- ar6000_dbglog_get_debug_logs(ar);
- ar->arWmiReady = FALSE;
- ar->arConnected = FALSE;
- ar->arConnectPending = FALSE;
- wmi_shutdown(ar->arWmi);
- ar->arWmiEnabled = FALSE;
- ar->arWmi = NULL;
- ar->arWlanState = WLAN_ENABLED;
-#ifdef USER_KEYS
- ar->user_savedkeys_stat = USER_SAVEDKEYS_STAT_INIT;
- ar->user_key_ctrl = 0;
-#endif
- }
-
- AR_DEBUG_PRINTF("%s(): WMI stopped\n", __func__);
- }
- else
- {
- AR_DEBUG_PRINTF("%s(): WMI not ready 0x%08x 0x%08x\n",
- __func__, (unsigned int) ar, (unsigned int) ar->arWmi);
-
- /* Shut down WMI if we have started it */
- if(ar->arWmiEnabled == TRUE)
- {
- AR_DEBUG_PRINTF("%s(): Shut down WMI\n", __func__);
- wmi_shutdown(ar->arWmi);
- ar->arWmiEnabled = FALSE;
- ar->arWmi = NULL;
- }
- }
-
- /* stop HTC */
- HTCStop(ar->arHtcTarget);
-
- /* set the instance to NULL so we do not get called back on remove incase we
- * we're explicity destroyed by module unload */
- HTCSetInstance(ar->arHtcTarget, NULL);
-
- if (resetok) {
- /* try to reset the device if we can
- * The driver may have been configure NOT to reset the target during
- * a debug session */
- AR_DEBUG_PRINTF(" Attempting to reset target on instance destroy.... \n");
- ar6000_reset_device(ar->arHifDevice, ar->arTargetType);
- } else {
- AR_DEBUG_PRINTF(" Host does not want target reset. \n");
- }
-
- /* Done with cookies */
- ar6000_cookie_cleanup(ar);
-
- /* Cleanup BMI */
- BMIInit();
-
/* Clear the tx counters */
memset(tx_attempt, 0, sizeof(tx_attempt));
memset(tx_post, 0, sizeof(tx_post));
memset(tx_complete, 0, sizeof(tx_complete));
-
/* Free up the device data structure */
- if (unregister)
- unregister_netdev(dev);
+ if (unregister) {
+ unregister_netdev(dev);
+ } else {
+ ar6000_close(dev);
+ }
free_raw_buffers(ar);
@@ -1159,8 +1090,79 @@ ar6000_open(struct net_device *dev)
static int
ar6000_close(struct net_device *dev)
{
+ AR_SOFTC_T *ar = netdev_priv(dev);
+
+ /* Stop the transmit queues */
netif_stop_queue(dev);
+ /* Disable the target and the interrupts associated with it */
+ if (ar->arWmiReady == TRUE)
+ {
+ if (!bypasswmi)
+ {
+ if (ar->arConnected == TRUE || ar->arConnectPending == TRUE)
+ {
+ AR_DEBUG_PRINTF("%s(): Disconnect\n", __func__);
+ AR6000_SPIN_LOCK(&ar->arLock, 0);
+ ar6000_init_profile_info(ar);
+ AR6000_SPIN_UNLOCK(&ar->arLock, 0);
+ wmi_disconnect_cmd(ar->arWmi);
+ }
+
+ ar6000_dbglog_get_debug_logs(ar);
+ ar->arWmiReady = FALSE;
+ ar->arConnected = FALSE;
+ ar->arConnectPending = FALSE;
+ wmi_shutdown(ar->arWmi);
+ ar->arWmiEnabled = FALSE;
+ ar->arWmi = NULL;
+ ar->arWlanState = WLAN_ENABLED;
+#ifdef USER_KEYS
+ ar->user_savedkeys_stat = USER_SAVEDKEYS_STAT_INIT;
+ ar->user_key_ctrl = 0;
+#endif
+ }
+
+ AR_DEBUG_PRINTF("%s(): WMI stopped\n", __func__);
+ }
+ else
+ {
+ AR_DEBUG_PRINTF("%s(): WMI not ready 0x%08x 0x%08x\n",
+ __func__, (unsigned int) ar, (unsigned int) ar->arWmi);
+
+ /* Shut down WMI if we have started it */
+ if(ar->arWmiEnabled == TRUE)
+ {
+ AR_DEBUG_PRINTF("%s(): Shut down WMI\n", __func__);
+ wmi_shutdown(ar->arWmi);
+ ar->arWmiEnabled = FALSE;
+ ar->arWmi = NULL;
+ }
+ }
+
+ /* stop HTC */
+ HTCStop(ar->arHtcTarget);
+
+ /* set the instance to NULL so we do not get called back on remove incase we
+ * we're explicity destroyed by module unload */
+ HTCSetInstance(ar->arHtcTarget, NULL);
+
+ if (resetok) {
+ /* try to reset the device if we can
+ * The driver may have been configure NOT to reset the target during
+ * a debug session */
+ AR_DEBUG_PRINTF(" Attempting to reset target on instance destroy.... \n");
+ ar6000_reset_device(ar->arHifDevice, ar->arTargetType);
+ } else {
+ AR_DEBUG_PRINTF(" Host does not want target reset. \n");
+ }
+
+ /* Done with cookies */
+ ar6000_cookie_cleanup(ar);
+
+ /* Cleanup BMI */
+ BMIInit();
+
return 0;
}