From patchwork Thu Nov 10 11:57:02 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xinming Hu X-Patchwork-Id: 9420957 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 10A94601C0 for ; Thu, 10 Nov 2016 11:57:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F07442954D for ; Thu, 10 Nov 2016 11:57:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E4EDF29651; Thu, 10 Nov 2016 11:57:43 +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=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, 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 3E4B42954D for ; Thu, 10 Nov 2016 11:57:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755612AbcKJL5k (ORCPT ); Thu, 10 Nov 2016 06:57:40 -0500 Received: from mail-pf0-f195.google.com ([209.85.192.195]:32796 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755566AbcKJL5j (ORCPT ); Thu, 10 Nov 2016 06:57:39 -0500 Received: by mail-pf0-f195.google.com with SMTP id 144so3985432pfv.0 for ; Thu, 10 Nov 2016 03:57:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=UStPl3EBM5mXpkBf6obmQ2A9gO6WqmlgYhdCP4VWpRU=; b=PflsZPMppZ4SoX7sg27hbnGw29EEH3Cj6DjGPNMuFYqpOpTTsN7ONt/WlYihsdPlOW INUwNDEfOL2rjUK4cilVJM0k5ztsj807EsVO4I7bE9TRXFM+TGXJzPJXYaHO0FsXD8yQ zlGJMWfOZElwCom0/PFZ8gjmyO8NtRoxX/T73NGg+H14PCqKGRTtG/fpdvSrxcx1z4uJ 6kEZhOF8JZTMuPgIISHnECJoUWrdhUEx8+LNqNdFQ6c0kuIfjIg+hvM0rJqX+5JZoK5P /nS3NhzbyVYSdtQ1IZa6t5YDmafIl6bF8Kj1QAu4zAtq83ERorzgLsWEavvZV1bDe5+V 71fg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=UStPl3EBM5mXpkBf6obmQ2A9gO6WqmlgYhdCP4VWpRU=; b=cra2zFHUbUb2GvFuVSB2lRvgF7vyS40EV5Wn4+RQdl5pOxhtv9DAt3hbtwPPpQCM9G Z2j6o9NYphrIYK4XvTHPtiGnqG7BY/8o0bPVpDGkS1OHotlkbI0Hep3vNS5/lq0iNGK3 Qyv5Txar7szlsKtMu8YtWwdtkQlSCgzlsKIRJxxjNTpiqSKFwFxn1SNWtLw/QrqPP4fr oGHv3n20OwE5Ki/Vwp+zfTKjsmJEaddQLDAU00mRSyB0qU5pCewJ4zUEFd/7FlISb7o9 pG7k4qH0UTb7bBf2SrOeXiuvfSP5dpXqF4MksK7qPP3IOoqvsoClOTen13qAttYOsmWf I6Kg== X-Gm-Message-State: ABUngvdtlnjPyYi59WeYSvuivIDQNDAC1OHwvGOnmfgjnaeISUM5thHdcu5aCv7Ej4fvrA== X-Received: by 10.98.44.212 with SMTP id s203mr9429582pfs.84.1478779058619; Thu, 10 Nov 2016 03:57:38 -0800 (PST) Received: from localhost.localdomain ([216.207.47.6]) by smtp.gmail.com with ESMTPSA id v10sm6740890pag.44.2016.11.10.03.57.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 10 Nov 2016 03:57:37 -0800 (PST) From: Xinming Hu X-Google-Original-From: Xinming Hu To: Linux Wireless Cc: Kalle Valo , Brian Norris , Dmitry Torokhov , Amitkumar Karwar , Cathy Luo , Shengzhen Li , Xinming Hu Subject: [PATCH RESEND v2 01/11] mwifiex: check tx_hw_pending before downloading sleep confirm Date: Thu, 10 Nov 2016 19:57:02 +0800 Message-Id: <1478779032-5165-1-git-send-email-huxinming820@marvell.com> X-Mailer: git-send-email 1.9.1 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: Shengzhen Li We may get SLEEP event from firmware even if TXDone interrupt for last Tx packet is still pending. In this case, we may end up accessing PCIe memory for handling TXDone after power save handshake is completed. This causes kernel crash with external abort. This patch will only allow downloading sleep confirm when no tx done interrupt is pending in the hardware. Signed-off-by: Cathy Luo Signed-off-by: Shengzhen Li Signed-off-by: Xinming Hu Signed-off-by: Amitkumar Karwar --- v2: address format issues(Brain) RESEND v2(Applicable for complete patch series): 1) Fixed syntax issue "changelog not placed after the Sign-offs" pointed by Brian. 2) Dropped "[v2,03/12] mwifiex: don't do unbalanced free()'ing in cleanup_if()" patch in this series. It was already sent by Brian separately. --- drivers/net/wireless/marvell/mwifiex/cmdevt.c | 5 +++-- drivers/net/wireless/marvell/mwifiex/init.c | 1 + drivers/net/wireless/marvell/mwifiex/main.h | 1 + drivers/net/wireless/marvell/mwifiex/pcie.c | 5 +++++ 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/drivers/net/wireless/marvell/mwifiex/cmdevt.c b/drivers/net/wireless/marvell/mwifiex/cmdevt.c index 5347728..25a7475 100644 --- a/drivers/net/wireless/marvell/mwifiex/cmdevt.c +++ b/drivers/net/wireless/marvell/mwifiex/cmdevt.c @@ -1118,13 +1118,14 @@ int mwifiex_process_cmdresp(struct mwifiex_adapter *adapter) void mwifiex_check_ps_cond(struct mwifiex_adapter *adapter) { - if (!adapter->cmd_sent && + if (!adapter->cmd_sent && !atomic_read(&adapter->tx_hw_pending) && !adapter->curr_cmd && !IS_CARD_RX_RCVD(adapter)) mwifiex_dnld_sleep_confirm_cmd(adapter); else mwifiex_dbg(adapter, CMD, - "cmd: Delay Sleep Confirm (%s%s%s)\n", + "cmd: Delay Sleep Confirm (%s%s%s%s)\n", (adapter->cmd_sent) ? "D" : "", + atomic_read(&adapter->tx_hw_pending) ? "T" : "", (adapter->curr_cmd) ? "C" : "", (IS_CARD_RX_RCVD(adapter)) ? "R" : ""); } diff --git a/drivers/net/wireless/marvell/mwifiex/init.c b/drivers/net/wireless/marvell/mwifiex/init.c index 82839d9..b36cb3f 100644 --- a/drivers/net/wireless/marvell/mwifiex/init.c +++ b/drivers/net/wireless/marvell/mwifiex/init.c @@ -270,6 +270,7 @@ static void mwifiex_init_adapter(struct mwifiex_adapter *adapter) adapter->adhoc_11n_enabled = false; mwifiex_wmm_init(adapter); + atomic_set(&adapter->tx_hw_pending, 0); sleep_cfm_buf = (struct mwifiex_opt_sleep_confirm *) adapter->sleep_cfm->data; diff --git a/drivers/net/wireless/marvell/mwifiex/main.h b/drivers/net/wireless/marvell/mwifiex/main.h index 11abc49..b0c501d 100644 --- a/drivers/net/wireless/marvell/mwifiex/main.h +++ b/drivers/net/wireless/marvell/mwifiex/main.h @@ -857,6 +857,7 @@ struct mwifiex_adapter { atomic_t rx_pending; atomic_t tx_pending; atomic_t cmd_pending; + atomic_t tx_hw_pending; struct workqueue_struct *workqueue; struct work_struct main_work; struct workqueue_struct *rx_workqueue; diff --git a/drivers/net/wireless/marvell/mwifiex/pcie.c b/drivers/net/wireless/marvell/mwifiex/pcie.c index ba1fa17..509c156 100644 --- a/drivers/net/wireless/marvell/mwifiex/pcie.c +++ b/drivers/net/wireless/marvell/mwifiex/pcie.c @@ -522,6 +522,7 @@ static int mwifiex_pcie_disable_host_int(struct mwifiex_adapter *adapter) } } + atomic_set(&adapter->tx_hw_pending, 0); return 0; } @@ -721,6 +722,7 @@ static void mwifiex_cleanup_txq_ring(struct mwifiex_adapter *adapter) card->tx_buf_list[i] = NULL; } + atomic_set(&adapter->tx_hw_pending, 0); return; } @@ -1158,6 +1160,7 @@ static int mwifiex_pcie_send_data_complete(struct mwifiex_adapter *adapter) -1); else mwifiex_write_data_complete(adapter, skb, 0, 0); + atomic_dec(&adapter->tx_hw_pending); } card->tx_buf_list[wrdoneidx] = NULL; @@ -1250,6 +1253,7 @@ static int mwifiex_pcie_send_data_complete(struct mwifiex_adapter *adapter) wrindx = (card->txbd_wrptr & reg->tx_mask) >> reg->tx_start_ptr; buf_pa = MWIFIEX_SKB_DMA_ADDR(skb); card->tx_buf_list[wrindx] = skb; + atomic_inc(&adapter->tx_hw_pending); if (reg->pfu_enabled) { desc2 = card->txbd_ring[wrindx]; @@ -1327,6 +1331,7 @@ static int mwifiex_pcie_send_data_complete(struct mwifiex_adapter *adapter) done_unmap: mwifiex_unmap_pci_memory(adapter, skb, PCI_DMA_TODEVICE); card->tx_buf_list[wrindx] = NULL; + atomic_dec(&adapter->tx_hw_pending); if (reg->pfu_enabled) memset(desc2, 0, sizeof(*desc2)); else