From patchwork Wed Nov 30 14:52:17 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amitkumar Karwar X-Patchwork-Id: 9454493 X-Patchwork-Delegate: kvalo@adurom.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id BE54660756 for ; Wed, 30 Nov 2016 14:53:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B375828447 for ; Wed, 30 Nov 2016 14:53:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A7CDD28453; Wed, 30 Nov 2016 14:53:34 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C6FA628449 for ; Wed, 30 Nov 2016 14:53:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933146AbcK3Oxb (ORCPT ); Wed, 30 Nov 2016 09:53:31 -0500 Received: from mx0a-0016f401.pphosted.com ([67.231.148.174]:55714 "EHLO mx0b-0016f401.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932242AbcK3Ox2 (ORCPT ); Wed, 30 Nov 2016 09:53:28 -0500 Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.16.0.17/8.16.0.17) with SMTP id uAUEnxqR022993; Wed, 30 Nov 2016 06:52:50 -0800 Received: from sc-exch04.marvell.com ([199.233.58.184]) by mx0a-0016f401.pphosted.com with ESMTP id 26y8msr3vj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Wed, 30 Nov 2016 06:52:50 -0800 Received: from SC-EXCH04.marvell.com (10.93.176.84) by SC-EXCH04.marvell.com (10.93.176.84) with Microsoft SMTP Server (TLS) id 15.0.1104.5; Wed, 30 Nov 2016 06:52:49 -0800 Received: from maili.marvell.com (10.93.176.43) by SC-EXCH04.marvell.com (10.93.176.84) with Microsoft SMTP Server id 15.0.1104.5 via Frontend Transport; Wed, 30 Nov 2016 06:52:49 -0800 Received: from pe-lt949 (unknown [10.31.130.253]) by maili.marvell.com (Postfix) with ESMTP id 998393F703F; Wed, 30 Nov 2016 06:52:48 -0800 (PST) Received: from pe-lt949 (piotr-probook.localdomain [127.0.0.1]) by pe-lt949 (8.14.4/8.14.4/Debian-4.1ubuntu1) with ESMTP id uAUEqWVu009956; Wed, 30 Nov 2016 20:22:32 +0530 Received: (from root@localhost) by pe-lt949 (8.14.4/8.14.4/Submit) id uAUEqWhn009955; Wed, 30 Nov 2016 20:22:32 +0530 From: Amitkumar Karwar To: CC: Cathy Luo , Nishant Sarmukadam , , , , Xinming Hu , Amitkumar Karwar Subject: [PATCH 2/2] mwifiex: get rid of global user_rmmod flag Date: Wed, 30 Nov 2016 20:22:17 +0530 Message-ID: <1480517537-9920-2-git-send-email-akarwar@marvell.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1480517537-9920-1-git-send-email-akarwar@marvell.com> References: <1480517537-9920-1-git-send-email-akarwar@marvell.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2016-11-30_10:, , signatures=0 X-Proofpoint-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1609300000 definitions=main-1611300244 Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Xinming Hu bus.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. Few commands (FUNC_SHUTDOWN etc.) are sent to the firmware only for module unload case. The variable 'user_rmmod' is used to distinguish between these two scenarios. This patch checks hardware status and get rid of global variable user_rmmod. Signed-off-by: Xinming Hu Signed-off-by: Amitkumar Karwar --- drivers/net/wireless/marvell/mwifiex/pcie.c | 23 ++++++++++++----------- drivers/net/wireless/marvell/mwifiex/sdio.c | 27 ++++----------------------- drivers/net/wireless/marvell/mwifiex/usb.c | 6 +----- 3 files changed, 17 insertions(+), 39 deletions(-) diff --git a/drivers/net/wireless/marvell/mwifiex/pcie.c b/drivers/net/wireless/marvell/mwifiex/pcie.c index 7aa16a5..079bb09 100644 --- a/drivers/net/wireless/marvell/mwifiex/pcie.c +++ b/drivers/net/wireless/marvell/mwifiex/pcie.c @@ -31,8 +31,6 @@ #define PCIE_VERSION "1.0" #define DRV_NAME "Marvell mwifiex PCIe" -static u8 user_rmmod; - static struct mwifiex_if_ops pcie_ops; static const struct of_device_id mwifiex_pcie_of_match_table[] = { @@ -284,6 +282,9 @@ static void mwifiex_pcie_remove(struct pci_dev *pdev) struct pcie_service_card *card; struct mwifiex_adapter *adapter; struct mwifiex_private *priv; + const struct mwifiex_pcie_card_reg *reg; + u32 fw_status; + int ret; card = pci_get_drvdata(pdev); @@ -295,7 +296,11 @@ static void mwifiex_pcie_remove(struct pci_dev *pdev) cancel_work_sync(&card->work); - if (user_rmmod && !adapter->mfg_mode) { + reg = card->pcie.reg; + if (reg) + ret = mwifiex_read_reg(adapter, reg->fw_status, &fw_status); + + if (fw_status == FIRMWARE_READY_PCIE && !adapter->mfg_mode) { mwifiex_deauthenticate_all(adapter); priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY); @@ -310,7 +315,6 @@ static void mwifiex_pcie_remove(struct pci_dev *pdev) static void mwifiex_pcie_shutdown(struct pci_dev *pdev) { - user_rmmod = 1; mwifiex_pcie_remove(pdev); return; @@ -2864,8 +2868,11 @@ static void mwifiex_pcie_cleanup(struct mwifiex_adapter *adapter) struct pcie_service_card *card = adapter->card; struct pci_dev *pdev = card->dev; const struct mwifiex_pcie_card_reg *reg = card->pcie.reg; + int ret; + u32 fw_status; - if (user_rmmod) { + ret = mwifiex_read_reg(adapter, reg->fw_status, &fw_status); + if (fw_status == FIRMWARE_READY_PCIE) { mwifiex_dbg(adapter, INFO, "Clearing driver ready signature\n"); if (mwifiex_write_reg(adapter, reg->drv_rdy, 0x00000000)) @@ -3177,9 +3184,6 @@ static int mwifiex_pcie_init_module(void) pr_debug("Marvell PCIe Driver\n"); - /* Clear the flag in case user removes the card. */ - user_rmmod = 0; - ret = pci_register_driver(&mwifiex_pcie); if (ret) pr_err("Driver register failed!\n"); @@ -3200,9 +3204,6 @@ static int mwifiex_pcie_init_module(void) */ static void mwifiex_pcie_cleanup_module(void) { - /* Set the flag as user is removing this module. */ - user_rmmod = 1; - pci_unregister_driver(&mwifiex_pcie); } diff --git a/drivers/net/wireless/marvell/mwifiex/sdio.c b/drivers/net/wireless/marvell/mwifiex/sdio.c index 6fcaf26..9a16e61 100644 --- a/drivers/net/wireless/marvell/mwifiex/sdio.c +++ b/drivers/net/wireless/marvell/mwifiex/sdio.c @@ -31,21 +31,6 @@ #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 void mwifiex_sdio_work(struct work_struct *work); static DECLARE_WORK(sdio_work, mwifiex_sdio_work); @@ -391,6 +376,8 @@ static int mwifiex_check_winner_status(struct mwifiex_adapter *adapter) struct sdio_mmc_card *card; struct mwifiex_adapter *adapter; struct mwifiex_private *priv; + int ret = 0; + u16 firmware_stat; card = sdio_get_drvdata(func); if (!card) @@ -404,7 +391,8 @@ static int mwifiex_check_winner_status(struct mwifiex_adapter *adapter) mwifiex_dbg(adapter, INFO, "info: SDIO func num=%d\n", func->num); - if (user_rmmod && !adapter->mfg_mode) { + ret = mwifiex_sdio_read_fw_status(adapter, &firmware_stat); + if (firmware_stat == FIRMWARE_READY_SDIO && !adapter->mfg_mode) { mwifiex_deauthenticate_all(adapter); priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY); @@ -2718,9 +2706,6 @@ static void mwifiex_sdio_device_dump(struct mwifiex_adapter *adapter) static int mwifiex_sdio_init_module(void) { - /* Clear the flag in case user removes the card. */ - user_rmmod = 0; - return sdio_register_driver(&mwifiex_sdio); } @@ -2736,10 +2721,6 @@ static void mwifiex_sdio_device_dump(struct mwifiex_adapter *adapter) static void mwifiex_sdio_cleanup_module(void) { - /* Set the flag as user is removing this module. */ - user_rmmod = 1; - cancel_work_sync(&sdio_work); - sdio_unregister_driver(&mwifiex_sdio); } diff --git a/drivers/net/wireless/marvell/mwifiex/usb.c b/drivers/net/wireless/marvell/mwifiex/usb.c index c563160..53881c4 100644 --- a/drivers/net/wireless/marvell/mwifiex/usb.c +++ b/drivers/net/wireless/marvell/mwifiex/usb.c @@ -22,7 +22,6 @@ #define USB_VERSION "1.0" -static u8 user_rmmod; static struct mwifiex_if_ops usb_ops; static struct usb_device_id mwifiex_usb_table[] = { @@ -618,7 +617,7 @@ static void mwifiex_usb_disconnect(struct usb_interface *intf) if (!adapter || !adapter->priv_num) return; - if (user_rmmod && !adapter->mfg_mode) { + if (card->udev->state != USB_STATE_NOTATTACHED && !adapter->mfg_mode) { mwifiex_deauthenticate_all(adapter); mwifiex_init_shutdown_fw(mwifiex_get_priv(adapter, @@ -1230,9 +1229,6 @@ static int mwifiex_usb_init_module(void) */ static void mwifiex_usb_cleanup_module(void) { - /* set the flag as user is removing this module */ - user_rmmod = 1; - usb_deregister(&mwifiex_usb_driver); }