aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAmitkumar Karwar <akarwar@marvell.com>2011-06-08 11:09:20 -0400
committerJohn W. Linville <linville@tuxdriver.com>2011-06-10 14:57:52 -0400
commit287546df342daaa146c840ce26b3ed012a055de5 (patch)
treefc00b21c7d28ab5928cee9138c07bb413c073c7e
parent7f1f974251493d3929ebd422796e6f9f2bcd6956 (diff)
mwifiex: get rid of global adapter pointer
1) Avoid global adapter pointer usage a) in sdio.c by moving some code from mwifiex_cleanup_module() to mwifiex_sdio_remove(). b) in main.c by passing an extra parameter to few functions. 2) Add new variable "user_rmmod" to identify if mwifiex_sdio_remove() callback function is called in card removal or rmmod context. These code changes are adapted from Libertas driver. 3) Remove unnecessary NULL pointer check for "func" pointer in mwifiex_sdio_remove(). Signed-off-by: Amitkumar Karwar <akarwar@marvell.com> Signed-off-by: Yogesh Ashok Powar <yogeshp@marvell.com> Signed-off-by: Bing Zhao <bzhao@marvell.com> Signed-off-by: John W. Linville <linville@tuxdriver.com>
-rw-r--r--drivers/net/wireless/mwifiex/main.c16
-rw-r--r--drivers/net/wireless/mwifiex/main.h1
-rw-r--r--drivers/net/wireless/mwifiex/sdio.c81
3 files changed, 56 insertions, 42 deletions
diff --git a/drivers/net/wireless/mwifiex/main.c b/drivers/net/wireless/mwifiex/main.c
index 4f43443036f4..054a5c348a24 100644
--- a/drivers/net/wireless/mwifiex/main.c
+++ b/drivers/net/wireless/mwifiex/main.c
@@ -26,9 +26,6 @@
26 26
27const char driver_version[] = "mwifiex " VERSION " (%s) "; 27const char driver_version[] = "mwifiex " VERSION " (%s) ";
28 28
29struct mwifiex_adapter *g_adapter;
30EXPORT_SYMBOL_GPL(g_adapter);
31
32static struct mwifiex_bss_attr mwifiex_bss_sta[] = { 29static struct mwifiex_bss_attr mwifiex_bss_sta[] = {
33 {MWIFIEX_BSS_TYPE_STA, MWIFIEX_DATA_FRAME_TYPE_ETH_II, true, 0, 0}, 30 {MWIFIEX_BSS_TYPE_STA, MWIFIEX_DATA_FRAME_TYPE_ETH_II, true, 0, 0},
34}; 31};
@@ -60,7 +57,8 @@ static struct mwifiex_drv_mode mwifiex_drv_mode_tbl[] = {
60 * proper cleanup before exiting. 57 * proper cleanup before exiting.
61 */ 58 */
62static int mwifiex_register(void *card, struct mwifiex_if_ops *if_ops, 59static int mwifiex_register(void *card, struct mwifiex_if_ops *if_ops,
63 struct mwifiex_drv_mode *drv_mode_ptr) 60 struct mwifiex_drv_mode *drv_mode_ptr,
61 void **padapter)
64{ 62{
65 struct mwifiex_adapter *adapter; 63 struct mwifiex_adapter *adapter;
66 int i; 64 int i;
@@ -69,7 +67,7 @@ static int mwifiex_register(void *card, struct mwifiex_if_ops *if_ops,
69 if (!adapter) 67 if (!adapter)
70 return -ENOMEM; 68 return -ENOMEM;
71 69
72 g_adapter = adapter; 70 *padapter = adapter;
73 adapter->card = card; 71 adapter->card = card;
74 72
75 /* Save interface specific operations in adapter */ 73 /* Save interface specific operations in adapter */
@@ -324,7 +322,7 @@ exit_main_proc:
324 * and initializing the private structures. 322 * and initializing the private structures.
325 */ 323 */
326static int 324static int
327mwifiex_init_sw(void *card, struct mwifiex_if_ops *if_ops) 325mwifiex_init_sw(void *card, struct mwifiex_if_ops *if_ops, void **padapter)
328{ 326{
329 int i; 327 int i;
330 struct mwifiex_drv_mode *drv_mode_ptr; 328 struct mwifiex_drv_mode *drv_mode_ptr;
@@ -343,7 +341,7 @@ mwifiex_init_sw(void *card, struct mwifiex_if_ops *if_ops)
343 return -1; 341 return -1;
344 } 342 }
345 343
346 if (mwifiex_register(card, if_ops, drv_mode_ptr)) 344 if (mwifiex_register(card, if_ops, drv_mode_ptr, padapter))
347 return -1; 345 return -1;
348 346
349 return 0; 347 return 0;
@@ -855,13 +853,11 @@ mwifiex_add_card(void *card, struct semaphore *sem,
855 if (down_interruptible(sem)) 853 if (down_interruptible(sem))
856 goto exit_sem_err; 854 goto exit_sem_err;
857 855
858 if (mwifiex_init_sw(card, if_ops)) { 856 if (mwifiex_init_sw(card, if_ops, (void **)&adapter)) {
859 pr_err("%s: software init failed\n", __func__); 857 pr_err("%s: software init failed\n", __func__);
860 goto err_init_sw; 858 goto err_init_sw;
861 } 859 }
862 860
863 adapter = g_adapter;
864
865 adapter->hw_status = MWIFIEX_HW_STATUS_INITIALIZING; 861 adapter->hw_status = MWIFIEX_HW_STATUS_INITIALIZING;
866 adapter->surprise_removed = false; 862 adapter->surprise_removed = false;
867 init_waitqueue_head(&adapter->init_wait_q); 863 init_waitqueue_head(&adapter->init_wait_q);
diff --git a/drivers/net/wireless/mwifiex/main.h b/drivers/net/wireless/mwifiex/main.h
index 57b183af72d7..db201cc1473b 100644
--- a/drivers/net/wireless/mwifiex/main.h
+++ b/drivers/net/wireless/mwifiex/main.h
@@ -39,7 +39,6 @@
39#include "fw.h" 39#include "fw.h"
40 40
41extern const char driver_version[]; 41extern const char driver_version[];
42extern struct mwifiex_adapter *g_adapter;
43 42
44enum { 43enum {
45 MWIFIEX_ASYNC_CMD, 44 MWIFIEX_ASYNC_CMD,
diff --git a/drivers/net/wireless/mwifiex/sdio.c b/drivers/net/wireless/mwifiex/sdio.c
index 4327b6d099c8..711fa689a95c 100644
--- a/drivers/net/wireless/mwifiex/sdio.c
+++ b/drivers/net/wireless/mwifiex/sdio.c
@@ -31,10 +31,27 @@
31 31
32#define SDIO_VERSION "1.0" 32#define SDIO_VERSION "1.0"
33 33
34/* The mwifiex_sdio_remove() callback function is called when
35 * user removes this module from kernel space or ejects
36 * the card from the slot. The driver handles these 2 cases
37 * differently.
38 * If the user is removing the module, the few commands (FUNC_SHUTDOWN,
39 * HS_CANCEL etc.) are sent to the firmware.
40 * If the card is removed, there is no need to send these command.
41 *
42 * The variable 'user_rmmod' is used to distinguish these two
43 * scenarios. This flag is initialized as FALSE in case the card
44 * is removed, and will be set to TRUE for module removal when
45 * module_exit function is called.
46 */
47static u8 user_rmmod;
48
34static struct mwifiex_if_ops sdio_ops; 49static struct mwifiex_if_ops sdio_ops;
35 50
36static struct semaphore add_remove_card_sem; 51static struct semaphore add_remove_card_sem;
37 52
53static int mwifiex_sdio_resume(struct device *dev);
54
38/* 55/*
39 * SDIO probe. 56 * SDIO probe.
40 * 57 *
@@ -93,17 +110,36 @@ static void
93mwifiex_sdio_remove(struct sdio_func *func) 110mwifiex_sdio_remove(struct sdio_func *func)
94{ 111{
95 struct sdio_mmc_card *card; 112 struct sdio_mmc_card *card;
113 struct mwifiex_adapter *adapter;
114 int i;
96 115
97 pr_debug("info: SDIO func num=%d\n", func->num); 116 pr_debug("info: SDIO func num=%d\n", func->num);
98 117
99 if (func) { 118 card = sdio_get_drvdata(func);
100 card = sdio_get_drvdata(func); 119 if (!card)
101 if (card) { 120 return;
102 mwifiex_remove_card(card->adapter, 121
103 &add_remove_card_sem); 122 adapter = card->adapter;
104 kfree(card); 123 if (!adapter || !adapter->priv_num)
105 } 124 return;
125
126 if (user_rmmod) {
127 if (adapter->is_suspended)
128 mwifiex_sdio_resume(adapter->dev);
129
130 for (i = 0; i < adapter->priv_num; i++)
131 if ((GET_BSS_ROLE(adapter->priv[i]) ==
132 MWIFIEX_BSS_ROLE_STA) &&
133 adapter->priv[i]->media_connected)
134 mwifiex_deauthenticate(adapter->priv[i], NULL);
135
136 mwifiex_init_shutdown_fw(mwifiex_get_priv(adapter,
137 MWIFIEX_BSS_ROLE_ANY),
138 MWIFIEX_FUNC_SHUTDOWN);
106 } 139 }
140
141 mwifiex_remove_card(card->adapter, &add_remove_card_sem);
142 kfree(card);
107} 143}
108 144
109/* 145/*
@@ -1696,6 +1732,9 @@ mwifiex_sdio_init_module(void)
1696{ 1732{
1697 sema_init(&add_remove_card_sem, 1); 1733 sema_init(&add_remove_card_sem, 1);
1698 1734
1735 /* Clear the flag in case user removes the card. */
1736 user_rmmod = 0;
1737
1699 return sdio_register_driver(&mwifiex_sdio); 1738 return sdio_register_driver(&mwifiex_sdio);
1700} 1739}
1701 1740
@@ -1711,32 +1750,12 @@ mwifiex_sdio_init_module(void)
1711static void 1750static void
1712mwifiex_sdio_cleanup_module(void) 1751mwifiex_sdio_cleanup_module(void)
1713{ 1752{
1714 struct mwifiex_adapter *adapter = g_adapter; 1753 if (!down_interruptible(&add_remove_card_sem))
1715 int i; 1754 up(&add_remove_card_sem);
1716
1717 if (down_interruptible(&add_remove_card_sem))
1718 goto exit_sem_err;
1719
1720 if (!adapter || !adapter->priv_num)
1721 goto exit;
1722
1723 if (adapter->is_suspended)
1724 mwifiex_sdio_resume(adapter->dev);
1725
1726 for (i = 0; i < adapter->priv_num; i++)
1727 if ((GET_BSS_ROLE(adapter->priv[i]) == MWIFIEX_BSS_ROLE_STA) &&
1728 adapter->priv[i]->media_connected)
1729 mwifiex_deauthenticate(adapter->priv[i], NULL);
1730
1731 if (!adapter->surprise_removed)
1732 mwifiex_init_shutdown_fw(mwifiex_get_priv(adapter,
1733 MWIFIEX_BSS_ROLE_ANY),
1734 MWIFIEX_FUNC_SHUTDOWN);
1735 1755
1736exit: 1756 /* Set the flag as user is removing this module. */
1737 up(&add_remove_card_sem); 1757 user_rmmod = 1;
1738 1758
1739exit_sem_err:
1740 sdio_unregister_driver(&mwifiex_sdio); 1759 sdio_unregister_driver(&mwifiex_sdio);
1741} 1760}
1742 1761