From patchwork Mon Mar 2 09:09:02 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Kazior X-Patchwork-Id: 5910741 X-Patchwork-Delegate: kvalo@adurom.com Return-Path: X-Original-To: patchwork-linux-wireless@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id CB9A1BF440 for ; Mon, 2 Mar 2015 09:10:32 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id DB01C201EF for ; Mon, 2 Mar 2015 09:10:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E19912020E for ; Mon, 2 Mar 2015 09:10:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753507AbbCBJK2 (ORCPT ); Mon, 2 Mar 2015 04:10:28 -0500 Received: from mail-la0-f50.google.com ([209.85.215.50]:46805 "EHLO mail-la0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752274AbbCBJKY (ORCPT ); Mon, 2 Mar 2015 04:10:24 -0500 Received: by lams18 with SMTP id s18so28869658lam.13 for ; Mon, 02 Mar 2015 01:10:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tieto.com; s=google; h=from:to:cc:subject:date:message-id; bh=Ge4prtsetKKJsDSMbw8vyYIeSAJrvv16SpDD/ELkTT0=; b=GXzfYObHgKFJK+lhnxLELlGBHb2Z1IDmdNuFC3YQudOHfvHvlJFVhIprgltrTbokDd uu73caNMyWwZ3EbOEDW/bst8d0Ca/3buH8HUQdfehTHXAW9iiAOPwjfdwlNsdrczBV+l EhEsGOTbunzbGgYxjjCuzYWPavWAMiTfI7zPo= 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=Ge4prtsetKKJsDSMbw8vyYIeSAJrvv16SpDD/ELkTT0=; b=Yoqzw6vLVALcSEeQ0wl2lBUrtVAsvg5pPSeREosGiaHSHnKS2Y4KVYCkwNY+DL5+8U SgLvL1dDrUGnMRAH0X9raviyqP3Bz5oWM9fEJzhMbfcUza8L7FUSa/hGOA1IFhRFZfYd Hv7gpMJ6UbRL4MsapQ7NrulQyZIvo0CJ0T2q4MFhf3zjlre68HS/nX97j/nK5iXZf2Ys YjkVjkMNCTo9aKA1oL15b169T3FxPJbU4DRSox51kzTG7qGB7Zj8bZsWj3ZDd3krQI+b JdOjzpUklJngh+7UcdBfwLWqXoJeZq18KNvkwPXl0tVqk0eV0DeHSIwjFeQWoMZmK2YE Z84A== X-Gm-Message-State: ALoCoQnK+acymKV3umJ2J/tOY4NRle4X+LjulWyr4naV8BA1XYv8NkE3yGVFFWt2oxYMHy1wb2hupMva6YWBjpBN7V2J0dWkyQzdWexqoQMcImHYwtXr+zk1uzZTymgaG/LLU70B9qNq X-Received: by 10.112.167.4 with SMTP id zk4mr22438615lbb.74.1425287422598; Mon, 02 Mar 2015 01:10:22 -0800 (PST) Received: from bob.homerouter.cpe (apn-77-113-114-198.dynamic.gprs.plus.pl. [77.113.114.198]) by mx.google.com with ESMTPSA id ud4sm2407775lac.28.2015.03.02.01.10.21 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 02 Mar 2015 01:10:21 -0800 (PST) From: Michal Kazior To: ath10k@lists.infradead.org Cc: linux-wireless@vger.kernel.org, Michal Kazior Subject: [PATCH 1/3] ath10k: fix some pci wake/sleep issues Date: Mon, 2 Mar 2015 10:09:02 +0100 Message-Id: <1425287344-30594-1-git-send-email-michal.kazior@tieto.com> X-Mailer: git-send-email 1.8.5.3 X-DomainID: tieto.com Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID,T_RP_MATCHES_RCVD,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP In some cases the device ends up sleeping while ath10k didn't expect it to leading to reading garbage from registers, e.g. when shared irqs are used and the driver is in powered down state. This effectively makes the device remain awake all the time even when all interfaces are down. Signed-off-by: Michal Kazior --- drivers/net/wireless/ath/ath10k/pci.c | 37 ++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/drivers/net/wireless/ath/ath10k/pci.c b/drivers/net/wireless/ath/ath10k/pci.c index e6972b0..cbf82ff 100644 --- a/drivers/net/wireless/ath/ath10k/pci.c +++ b/drivers/net/wireless/ath/ath10k/pci.c @@ -819,6 +819,21 @@ static int ath10k_pci_wake_wait(struct ath10k *ar) return -ETIMEDOUT; } +/* The rule is host is forbidden from accessing device registers while it's + * asleep. Currently ath10k_pci_wake() and ath10k_pci_sleep() calls aren't + * balanced and the device is kept awake all the time. This is intended for a + * simpler solution for the following problems: + * + * * device can enter sleep during s2ram without the host knowing, + * + * * irq handlers access registers which is a problem if other device asserts + * a shared irq line when ath10k is between hif_power_down() and + * hif_power_up(). + * + * FIXME: If power consumption is a concern (and there are *real* gains) then a + * refcounted wake/sleep needs to be implemented. + */ + static int ath10k_pci_wake(struct ath10k *ar) { ath10k_pci_reg_write32(ar, PCIE_SOC_WAKE_ADDRESS, @@ -2034,8 +2049,6 @@ static void ath10k_pci_hif_power_down(struct ath10k *ar) /* Currently hif_power_up performs effectively a reset and hif_stop * resets the chip as well so there's no point in resetting here. */ - - ath10k_pci_sleep(ar); } #ifdef CONFIG_PM @@ -2048,6 +2061,8 @@ static int ath10k_pci_hif_suspend(struct ath10k *ar) struct pci_dev *pdev = ar_pci->pdev; u32 val; + ath10k_pci_sleep(ar); + pci_read_config_dword(pdev, ATH10K_PCI_PM_CONTROL, &val); if ((val & 0x000000ff) != 0x3) { @@ -2065,6 +2080,13 @@ static int ath10k_pci_hif_resume(struct ath10k *ar) struct ath10k_pci *ar_pci = ath10k_pci_priv(ar); struct pci_dev *pdev = ar_pci->pdev; u32 val; + int ret; + + ret = ath10k_pci_wake(ar); + if (ret) { + ath10k_err(ar, "failed to wake device up on resume: %d\n", ret); + return ret; + } pci_read_config_dword(pdev, ATH10K_PCI_PM_CONTROL, &val); @@ -2083,7 +2105,7 @@ static int ath10k_pci_hif_resume(struct ath10k *ar) pci_write_config_dword(pdev, 0x40, val & 0xffff00ff); } - return 0; + return ret; } #endif @@ -2177,6 +2199,13 @@ static irqreturn_t ath10k_pci_interrupt_handler(int irq, void *arg) { struct ath10k *ar = arg; struct ath10k_pci *ar_pci = ath10k_pci_priv(ar); + int ret; + + ret = ath10k_pci_wake(ar); + if (ret) { + ath10k_warn(ar, "failed to wake device up on irq: %d\n", ret); + return IRQ_NONE; + } if (ar_pci->num_msi_intrs == 0) { if (!ath10k_pci_irq_pending(ar)) @@ -2681,8 +2710,6 @@ static int ath10k_pci_probe(struct pci_dev *pdev, goto err_sleep; } - ath10k_pci_sleep(ar); - ret = ath10k_core_register(ar, chip_id); if (ret) { ath10k_err(ar, "failed to register driver core: %d\n", ret);