From patchwork Mon Mar 2 12:22:13 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Kazior X-Patchwork-Id: 5911991 X-Patchwork-Delegate: kvalo@adurom.com Return-Path: X-Original-To: patchwork-linux-wireless@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 4156C9F36A for ; Mon, 2 Mar 2015 12:23:32 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3D1D320166 for ; Mon, 2 Mar 2015 12:23:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BD8B72015E for ; Mon, 2 Mar 2015 12:23:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753506AbbCBMX2 (ORCPT ); Mon, 2 Mar 2015 07:23:28 -0500 Received: from mail-la0-f42.google.com ([209.85.215.42]:40697 "EHLO mail-la0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752714AbbCBMX1 (ORCPT ); Mon, 2 Mar 2015 07:23:27 -0500 Received: by labgd6 with SMTP id gd6so29886594lab.7 for ; Mon, 02 Mar 2015 04:23:26 -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=LMfHmo7j8BUqzP7UbpislMoOjEHQ/BqYs5AeeGCZtwOmzUWq5Q4Wz4wm2F36aWT9Pn cwyvoWz+lmXnb4T9hG//7FLTIjpc54Fris11k13tasrrHLF01CKQFH81OCAAWq4NSsGv wDhoUjqPQ/etHA+Jfpsd1Rpdk0A6OOw6HkEqY= 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=a5sgxkItFLnOtfQDwTi28U1dQZYI8EhouuaklQ78lspZFT2kd382gXv7UaJWkVCHlh W9paLUUhUKzbXwb+0uPmL8CO/ecqirUXAczW4PLf4nJwO7FGEWTzvWMGGSXMfS7UG8Nk FwURCqSTmXnxC7aRaqGHpQz3Lv6B/8HsHmZGfPhUL3zYhKwIxfAHirerjE0499Smk4PD zgmB6+3r9cG4pRC2BbUW1CUovAcNctfWto0esN5GL2ZugO7/+MdQuDsO2uEV12cLB0kd r/l6obnfyA3SeqvDmB6mczQjGTaOUv9i579IXmK+3DNUV5If5Kjtv7zd5fIB1FR6OBz1 r9MA== X-Gm-Message-State: ALoCoQkGL0DnI5tmjUeRRMilG7Lw9OvC2FsQxZWTGfFWoZnbd6GdwvokavXNCvHsGzk8DIE1LLH46z2tFtBj06qpkqLnVGR9e/3IperRkjuYPqzZv0zJ5Cf9nxQDDMHfgGBoEdJ4JI8L X-Received: by 10.112.154.234 with SMTP id vr10mr23606884lbb.115.1425299006215; Mon, 02 Mar 2015 04:23:26 -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 ps2sm2508497lbb.20.2015.03.02.04.23.25 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 02 Mar 2015 04:23:25 -0800 (PST) From: Michal Kazior To: ath10k@lists.infradead.org Cc: linux-wireless@vger.kernel.org, Michal Kazior Subject: [PATCH v2 1/2] ath10k: fix some pci wake/sleep issues Date: Mon, 2 Mar 2015 13:22:13 +0100 Message-Id: <1425298934-12370-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);