Commit 287546df authored by Amitkumar Karwar's avatar Amitkumar Karwar Committed by John W. Linville

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: default avatarAmitkumar Karwar <akarwar@marvell.com>
Signed-off-by: default avatarYogesh Ashok Powar <yogeshp@marvell.com>
Signed-off-by: default avatarBing Zhao <bzhao@marvell.com>
Signed-off-by: default avatarJohn W. Linville <linville@tuxdriver.com>
parent 7f1f9742
...@@ -26,9 +26,6 @@ ...@@ -26,9 +26,6 @@
const char driver_version[] = "mwifiex " VERSION " (%s) "; const char driver_version[] = "mwifiex " VERSION " (%s) ";
struct mwifiex_adapter *g_adapter;
EXPORT_SYMBOL_GPL(g_adapter);
static struct mwifiex_bss_attr mwifiex_bss_sta[] = { static struct mwifiex_bss_attr mwifiex_bss_sta[] = {
{MWIFIEX_BSS_TYPE_STA, MWIFIEX_DATA_FRAME_TYPE_ETH_II, true, 0, 0}, {MWIFIEX_BSS_TYPE_STA, MWIFIEX_DATA_FRAME_TYPE_ETH_II, true, 0, 0},
}; };
...@@ -60,7 +57,8 @@ static struct mwifiex_drv_mode mwifiex_drv_mode_tbl[] = { ...@@ -60,7 +57,8 @@ static struct mwifiex_drv_mode mwifiex_drv_mode_tbl[] = {
* proper cleanup before exiting. * proper cleanup before exiting.
*/ */
static int mwifiex_register(void *card, struct mwifiex_if_ops *if_ops, static int mwifiex_register(void *card, struct mwifiex_if_ops *if_ops,
struct mwifiex_drv_mode *drv_mode_ptr) struct mwifiex_drv_mode *drv_mode_ptr,
void **padapter)
{ {
struct mwifiex_adapter *adapter; struct mwifiex_adapter *adapter;
int i; int i;
...@@ -69,7 +67,7 @@ static int mwifiex_register(void *card, struct mwifiex_if_ops *if_ops, ...@@ -69,7 +67,7 @@ static int mwifiex_register(void *card, struct mwifiex_if_ops *if_ops,
if (!adapter) if (!adapter)
return -ENOMEM; return -ENOMEM;
g_adapter = adapter; *padapter = adapter;
adapter->card = card; adapter->card = card;
/* Save interface specific operations in adapter */ /* Save interface specific operations in adapter */
...@@ -324,7 +322,7 @@ int mwifiex_main_process(struct mwifiex_adapter *adapter) ...@@ -324,7 +322,7 @@ int mwifiex_main_process(struct mwifiex_adapter *adapter)
* and initializing the private structures. * and initializing the private structures.
*/ */
static int static int
mwifiex_init_sw(void *card, struct mwifiex_if_ops *if_ops) mwifiex_init_sw(void *card, struct mwifiex_if_ops *if_ops, void **padapter)
{ {
int i; int i;
struct mwifiex_drv_mode *drv_mode_ptr; struct mwifiex_drv_mode *drv_mode_ptr;
...@@ -343,7 +341,7 @@ mwifiex_init_sw(void *card, struct mwifiex_if_ops *if_ops) ...@@ -343,7 +341,7 @@ mwifiex_init_sw(void *card, struct mwifiex_if_ops *if_ops)
return -1; return -1;
} }
if (mwifiex_register(card, if_ops, drv_mode_ptr)) if (mwifiex_register(card, if_ops, drv_mode_ptr, padapter))
return -1; return -1;
return 0; return 0;
...@@ -855,13 +853,11 @@ mwifiex_add_card(void *card, struct semaphore *sem, ...@@ -855,13 +853,11 @@ mwifiex_add_card(void *card, struct semaphore *sem,
if (down_interruptible(sem)) if (down_interruptible(sem))
goto exit_sem_err; goto exit_sem_err;
if (mwifiex_init_sw(card, if_ops)) { if (mwifiex_init_sw(card, if_ops, (void **)&adapter)) {
pr_err("%s: software init failed\n", __func__); pr_err("%s: software init failed\n", __func__);
goto err_init_sw; goto err_init_sw;
} }
adapter = g_adapter;
adapter->hw_status = MWIFIEX_HW_STATUS_INITIALIZING; adapter->hw_status = MWIFIEX_HW_STATUS_INITIALIZING;
adapter->surprise_removed = false; adapter->surprise_removed = false;
init_waitqueue_head(&adapter->init_wait_q); init_waitqueue_head(&adapter->init_wait_q);
......
...@@ -39,7 +39,6 @@ ...@@ -39,7 +39,6 @@
#include "fw.h" #include "fw.h"
extern const char driver_version[]; extern const char driver_version[];
extern struct mwifiex_adapter *g_adapter;
enum { enum {
MWIFIEX_ASYNC_CMD, MWIFIEX_ASYNC_CMD,
......
...@@ -31,10 +31,27 @@ ...@@ -31,10 +31,27 @@
#define SDIO_VERSION "1.0" #define SDIO_VERSION "1.0"
/* The mwifiex_sdio_remove() callback function is called when
* user removes this module from kernel space or ejects
* the card from the slot. The driver handles these 2 cases
* differently.
* If the user is removing the module, the few commands (FUNC_SHUTDOWN,
* HS_CANCEL etc.) are sent to the firmware.
* If the card is removed, there is no need to send these command.
*
* The variable 'user_rmmod' is used to distinguish these two
* scenarios. This flag is initialized as FALSE in case the card
* is removed, and will be set to TRUE for module removal when
* module_exit function is called.
*/
static u8 user_rmmod;
static struct mwifiex_if_ops sdio_ops; static struct mwifiex_if_ops sdio_ops;
static struct semaphore add_remove_card_sem; static struct semaphore add_remove_card_sem;
static int mwifiex_sdio_resume(struct device *dev);
/* /*
* SDIO probe. * SDIO probe.
* *
...@@ -93,17 +110,36 @@ static void ...@@ -93,17 +110,36 @@ static void
mwifiex_sdio_remove(struct sdio_func *func) mwifiex_sdio_remove(struct sdio_func *func)
{ {
struct sdio_mmc_card *card; struct sdio_mmc_card *card;
struct mwifiex_adapter *adapter;
int i;
pr_debug("info: SDIO func num=%d\n", func->num); pr_debug("info: SDIO func num=%d\n", func->num);
if (func) { card = sdio_get_drvdata(func);
card = sdio_get_drvdata(func); if (!card)
if (card) { return;
mwifiex_remove_card(card->adapter,
&add_remove_card_sem); adapter = card->adapter;
kfree(card); if (!adapter || !adapter->priv_num)
} return;
if (user_rmmod) {
if (adapter->is_suspended)
mwifiex_sdio_resume(adapter->dev);
for (i = 0; i < adapter->priv_num; i++)
if ((GET_BSS_ROLE(adapter->priv[i]) ==
MWIFIEX_BSS_ROLE_STA) &&
adapter->priv[i]->media_connected)
mwifiex_deauthenticate(adapter->priv[i], NULL);
mwifiex_init_shutdown_fw(mwifiex_get_priv(adapter,
MWIFIEX_BSS_ROLE_ANY),
MWIFIEX_FUNC_SHUTDOWN);
} }
mwifiex_remove_card(card->adapter, &add_remove_card_sem);
kfree(card);
} }
/* /*
...@@ -1696,6 +1732,9 @@ mwifiex_sdio_init_module(void) ...@@ -1696,6 +1732,9 @@ mwifiex_sdio_init_module(void)
{ {
sema_init(&add_remove_card_sem, 1); sema_init(&add_remove_card_sem, 1);
/* Clear the flag in case user removes the card. */
user_rmmod = 0;
return sdio_register_driver(&mwifiex_sdio); return sdio_register_driver(&mwifiex_sdio);
} }
...@@ -1711,32 +1750,12 @@ mwifiex_sdio_init_module(void) ...@@ -1711,32 +1750,12 @@ mwifiex_sdio_init_module(void)
static void static void
mwifiex_sdio_cleanup_module(void) mwifiex_sdio_cleanup_module(void)
{ {
struct mwifiex_adapter *adapter = g_adapter; if (!down_interruptible(&add_remove_card_sem))
int i; up(&add_remove_card_sem);
if (down_interruptible(&add_remove_card_sem))
goto exit_sem_err;
if (!adapter || !adapter->priv_num)
goto exit;
if (adapter->is_suspended)
mwifiex_sdio_resume(adapter->dev);
for (i = 0; i < adapter->priv_num; i++)
if ((GET_BSS_ROLE(adapter->priv[i]) == MWIFIEX_BSS_ROLE_STA) &&
adapter->priv[i]->media_connected)
mwifiex_deauthenticate(adapter->priv[i], NULL);
if (!adapter->surprise_removed)
mwifiex_init_shutdown_fw(mwifiex_get_priv(adapter,
MWIFIEX_BSS_ROLE_ANY),
MWIFIEX_FUNC_SHUTDOWN);
exit: /* Set the flag as user is removing this module. */
up(&add_remove_card_sem); user_rmmod = 1;
exit_sem_err:
sdio_unregister_driver(&mwifiex_sdio); sdio_unregister_driver(&mwifiex_sdio);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment