2015-03-02 09:10:24

by Michal Kazior

[permalink] [raw]
Subject: [PATCH 1/3] ath10k: fix some pci wake/sleep issues

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 <[email protected]>
---
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);
--
1.8.5.3



2015-03-02 09:23:54

by Michal Kazior

[permalink] [raw]
Subject: Re: [PATCH 2/3] ath10k: always save/restore pci config space

On 2 March 2015 at 10:16, Johannes Berg <[email protected]> wrote:
> On Mon, 2015-03-02 at 10:09 +0100, Michal Kazior wrote:
>> The check isn't really necessary and couldn't even
>> work because becase pci_restore_state() restores
>> only first 64 bytes of PCI configuration space.
>>
>> This is necessary for future WoWLAN support.
>
>> + pci_save_state(pdev);
>> + pci_disable_device(pdev);
>
> I believe the whole thing isn't necessary at all since the kernel's PCIe
> layer will take care of it.

You mean only the pci_save_state() and pci_disable_device() or, the
resume counterpart as well? Hmm.

Earlier the resume counterpart didn't do any restore stuff and the
device ended up pretty confused..


Michał

2015-03-02 10:17:02

by Michal Kazior

[permalink] [raw]
Subject: Re: [PATCH 2/3] ath10k: always save/restore pci config space

On 2 March 2015 at 10:25, Johannes Berg <[email protected]> wrote:
> On Mon, 2015-03-02 at 10:23 +0100, Michal Kazior wrote:
>
>> > I believe the whole thing isn't necessary at all since the kernel's PCIe
>> > layer will take care of it.
>>
>> You mean only the pci_save_state() and pci_disable_device() or, the
>> resume counterpart as well? Hmm.
>
> Resume as well - but I believe it's all-or-nothing.
>
>> Earlier the resume counterpart didn't do any restore stuff and the
>> device ended up pretty confused..
>
> which may explain this.

Hmm.. I removed the save/restore/enable/disable completely and
re-tested. It seems to work fine as well.

I'll post a v2 later then. Thanks!


Michał

2015-03-02 09:10:26

by Michal Kazior

[permalink] [raw]
Subject: [PATCH 3/3] ath10k: re-enable pci device upon resume

This balances out pci_disable_device() from
ath10k_pci_hif_suspend().

Signed-off-by: Michal Kazior <[email protected]>
---
drivers/net/wireless/ath/ath10k/pci.c | 6 ++++++
1 file changed, 6 insertions(+)

diff --git a/drivers/net/wireless/ath/ath10k/pci.c b/drivers/net/wireless/ath/ath10k/pci.c
index d06b264..1295345 100644
--- a/drivers/net/wireless/ath/ath10k/pci.c
+++ b/drivers/net/wireless/ath/ath10k/pci.c
@@ -2079,6 +2079,12 @@ static int ath10k_pci_hif_resume(struct ath10k *ar)
return ret;
}

+ ret = pci_enable_device(pdev);
+ if (ret) {
+ ath10k_err(ar, "failed to enable pci device: %d\n", ret);
+ return ret;
+ }
+
pci_restore_state(pdev);

/* Suspend/Resume resets the PCI configuration space, so we have to
--
1.8.5.3


2015-03-02 09:16:29

by Johannes Berg

[permalink] [raw]
Subject: Re: [PATCH 2/3] ath10k: always save/restore pci config space

On Mon, 2015-03-02 at 10:09 +0100, Michal Kazior wrote:
> The check isn't really necessary and couldn't even
> work because becase pci_restore_state() restores
> only first 64 bytes of PCI configuration space.
>
> This is necessary for future WoWLAN support.

> + pci_save_state(pdev);
> + pci_disable_device(pdev);

I believe the whole thing isn't necessary at all since the kernel's PCIe
layer will take care of it.

johannes


2015-03-02 09:10:25

by Michal Kazior

[permalink] [raw]
Subject: [PATCH 2/3] ath10k: always save/restore pci config space

The check isn't really necessary and couldn't even
work because becase pci_restore_state() restores
only first 64 bytes of PCI configuration space.

This is necessary for future WoWLAN support.

Signed-off-by: Michal Kazior <[email protected]>
---
drivers/net/wireless/ath/ath10k/pci.c | 37 +++++++++++------------------------
1 file changed, 11 insertions(+), 26 deletions(-)

diff --git a/drivers/net/wireless/ath/ath10k/pci.c b/drivers/net/wireless/ath/ath10k/pci.c
index cbf82ff..d06b264 100644
--- a/drivers/net/wireless/ath/ath10k/pci.c
+++ b/drivers/net/wireless/ath/ath10k/pci.c
@@ -2053,24 +2053,15 @@ static void ath10k_pci_hif_power_down(struct ath10k *ar)

#ifdef CONFIG_PM

-#define ATH10K_PCI_PM_CONTROL 0x44
-
static int ath10k_pci_hif_suspend(struct ath10k *ar)
{
struct ath10k_pci *ar_pci = ath10k_pci_priv(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) {
- pci_save_state(pdev);
- pci_disable_device(pdev);
- pci_write_config_dword(pdev, ATH10K_PCI_PM_CONTROL,
- (val & 0xffffff00) | 0x03);
- }
+ pci_save_state(pdev);
+ pci_disable_device(pdev);

return 0;
}
@@ -2088,22 +2079,16 @@ static int ath10k_pci_hif_resume(struct ath10k *ar)
return ret;
}

- pci_read_config_dword(pdev, ATH10K_PCI_PM_CONTROL, &val);
+ pci_restore_state(pdev);

- if ((val & 0x000000ff) != 0) {
- pci_restore_state(pdev);
- pci_write_config_dword(pdev, ATH10K_PCI_PM_CONTROL,
- val & 0xffffff00);
- /*
- * Suspend/Resume resets the PCI configuration space,
- * so we have to re-disable the RETRY_TIMEOUT register (0x41)
- * to keep PCI Tx retries from interfering with C3 CPU state
- */
- pci_read_config_dword(pdev, 0x40, &val);
-
- if ((val & 0x0000ff00) != 0)
- pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
- }
+ /* Suspend/Resume resets the PCI configuration space, so we have to
+ * re-disable the RETRY_TIMEOUT register (0x41) to keep PCI Tx retries
+ * from interfering with C3 CPU state. pci_restore_state won't help
+ * here since it only restores the first 64 bytes pci config header.
+ */
+ pci_read_config_dword(pdev, 0x40, &val);
+ if ((val & 0x0000ff00) != 0)
+ pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);

return ret;
}
--
1.8.5.3


2015-03-02 09:25:24

by Johannes Berg

[permalink] [raw]
Subject: Re: [PATCH 2/3] ath10k: always save/restore pci config space

On Mon, 2015-03-02 at 10:23 +0100, Michal Kazior wrote:

> > I believe the whole thing isn't necessary at all since the kernel's PCIe
> > layer will take care of it.
>
> You mean only the pci_save_state() and pci_disable_device() or, the
> resume counterpart as well? Hmm.

Resume as well - but I believe it's all-or-nothing.

> Earlier the resume counterpart didn't do any restore stuff and the
> device ended up pretty confused..

which may explain this.

johannes