Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp2008841ybg; Thu, 24 Oct 2019 03:32:21 -0700 (PDT) X-Google-Smtp-Source: APXvYqx+Ypho5+XS+VqMumsiX0TTZVRfr8zjG4qArskWtHwO2+wbXGEw6d5DdXnCMyiJDNUy6W8i X-Received: by 2002:aa7:da4a:: with SMTP id w10mr41587484eds.209.1571913141202; Thu, 24 Oct 2019 03:32:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571913141; cv=none; d=google.com; s=arc-20160816; b=YfP8CrobqNzGgpEyXzlXB9EcNPRh0oj5zmkhc2lZzGp6D+LlnpfhnUFqi9CwIoL2SO ZYYlNiqA1UTbMsOvwVF8RE+sce9QhRIBNUmwMleWpg5GqoZ3Wms83lU/BaP3VSPuYpI1 sfYvZ+H85vdYHkvSgPJVnspiGk+pU3OzkQKRMmdgpv8tcgeN9OFAJ9CofppHC7iX5PLI dygaPNlxAZPDA/rAhkN/Ia1+bT7P4jZGjCH9+dO6XXrYV6pd1BFkm4nJ8f2gpqnVsDPk IyUCKkuZVFAO/Cjq8LdeWJSXBKubesOFTfeQJjXmj7P0p3NVvfeLUW9LXH1EIzdUBPeN caAg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=uT087p55wzcKZReGwY7zJrz1zZAO65LY/rGMI4QNUgU=; b=aKLvynJZki09/d3PSL8s8koyhtVawO4gchmwj14zerPzJTFR8agr8ZyBoTbAt2SrkF iJdjmLnLiuAPD4VJuUIS+UM93MF4YBxeKR1BpCMPtrycpxVev/luV49D5W2pSUZ3qUKZ 20Wm2DkLaQ/54hYxv6KBMzqpi6lkV+WMiJSXxRqdDx6gLWsGMYkD9FfGG94aMh2IYgBb b/31hBJ7lykWNyoHEl7QATxjdKE/Uwm+4I5HxGiWSCRBT4Fzvgdt53bhLDV6BNmj4qW3 EvaLAon/w5uS1oeg50rxT2krVAYiemUFeSDAAlJgRSqffFdfNYVZ6hv77hLWlG5cSJ3b 9EQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=mtQDBqZR; spf=pass (google.com: best guess record for domain of linux-wireless-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a26si15983872edv.35.2019.10.24.03.31.47; Thu, 24 Oct 2019 03:32:21 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-wireless-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=mtQDBqZR; spf=pass (google.com: best guess record for domain of linux-wireless-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2436715AbfJWWYX (ORCPT + 99 others); Wed, 23 Oct 2019 18:24:23 -0400 Received: from mail.kernel.org ([198.145.29.99]:54322 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2436651AbfJWWYX (ORCPT ); Wed, 23 Oct 2019 18:24:23 -0400 Received: from lore-desk.lan (unknown [151.66.11.57]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id AD5302173B; Wed, 23 Oct 2019 22:24:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1571869462; bh=9Rf/2A2133N2RaTq0AUraTZm7Ddefm9mGc7uW0+g0xg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mtQDBqZR+uxSfwoyPtDXzCryBoLFjzAk2LdBXvrTqfnnVvxVDvKeep8PkEqk+SGRe iuqJZ/54c3dodivjW7enr9jDJkNxsIvarkx09+9HNtmu9Olci2YRnh5u4hrBPqh+GV ZDsvLO7WeWq0nIDuqeL71qEALt7lEDDQ21t3dL08= From: Lorenzo Bianconi To: kvalo@codeaurora.org Cc: linux-wireless@vger.kernel.org, nbd@nbd.name, sgruszka@redhat.com, lorenzo.bianconi@redhat.com, oleksandr@natalenko.name, netdev@vger.kernel.org Subject: [PATCH wireless-drivers 1/2] mt76: mt76x2e: disable pcie_aspm by default Date: Thu, 24 Oct 2019 00:23:15 +0200 Message-Id: X-Mailer: git-send-email 2.21.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org On same device (e.g. U7612E-H1) PCIE_ASPM causes continuous mcu hangs and instability and so let's disable PCIE_ASPM by default. This patch has been successfully tested on U7612E-H1 mini-pice card Signed-off-by: Felix Fietkau Signed-off-by: Lorenzo Bianconi --- drivers/net/wireless/mediatek/mt76/mmio.c | 47 +++++++++++++++++++ drivers/net/wireless/mediatek/mt76/mt76.h | 1 + .../net/wireless/mediatek/mt76/mt76x2/pci.c | 2 + 3 files changed, 50 insertions(+) diff --git a/drivers/net/wireless/mediatek/mt76/mmio.c b/drivers/net/wireless/mediatek/mt76/mmio.c index 1c974df1fe25..f991a8f1c42a 100644 --- a/drivers/net/wireless/mediatek/mt76/mmio.c +++ b/drivers/net/wireless/mediatek/mt76/mmio.c @@ -3,6 +3,8 @@ * Copyright (C) 2016 Felix Fietkau */ +#include + #include "mt76.h" #include "trace.h" @@ -78,6 +80,51 @@ void mt76_set_irq_mask(struct mt76_dev *dev, u32 addr, } EXPORT_SYMBOL_GPL(mt76_set_irq_mask); +void mt76_mmio_disable_aspm(struct pci_dev *pdev) +{ + struct pci_dev *parent = pdev->bus->self; + u16 aspm_conf, parent_aspm_conf = 0; + + pcie_capability_read_word(pdev, PCI_EXP_LNKCTL, &aspm_conf); + aspm_conf &= PCI_EXP_LNKCTL_ASPMC; + if (parent) { + pcie_capability_read_word(parent, PCI_EXP_LNKCTL, + &parent_aspm_conf); + parent_aspm_conf &= PCI_EXP_LNKCTL_ASPMC; + } + + if (!aspm_conf && (!parent || !parent_aspm_conf)) { + /* aspm already disabled */ + return; + } + + dev_info(&pdev->dev, "disabling ASPM %s %s\n", + (aspm_conf & PCI_EXP_LNKCTL_ASPM_L0S) ? "L0s" : "", + (aspm_conf & PCI_EXP_LNKCTL_ASPM_L1) ? "L1" : ""); + +#ifdef CONFIG_PCIEASPM + pci_disable_link_state(pdev, aspm_conf); + + /* Double-check ASPM control. If not disabled by the above, the + * BIOS is preventing that from happening (or CONFIG_PCIEASPM is + * not enabled); override by writing PCI config space directly. + */ + pcie_capability_read_word(pdev, PCI_EXP_LNKCTL, &aspm_conf); + if (!(aspm_conf & PCI_EXP_LNKCTL_ASPMC)) + return; +#endif /* CONFIG_PCIEASPM */ + + /* Both device and parent should have the same ASPM setting. + * Disable ASPM in downstream component first and then upstream. + */ + pcie_capability_clear_word(pdev, PCI_EXP_LNKCTL, aspm_conf); + + if (parent) + pcie_capability_clear_word(parent, PCI_EXP_LNKCTL, + aspm_conf); +} +EXPORT_SYMBOL_GPL(mt76_mmio_disable_aspm); + void mt76_mmio_init(struct mt76_dev *dev, void __iomem *regs) { static const struct mt76_bus_ops mt76_mmio_ops = { diff --git a/drivers/net/wireless/mediatek/mt76/mt76.h b/drivers/net/wireless/mediatek/mt76/mt76.h index 570c159515a0..962812b6247d 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76.h +++ b/drivers/net/wireless/mediatek/mt76/mt76.h @@ -578,6 +578,7 @@ bool __mt76_poll_msec(struct mt76_dev *dev, u32 offset, u32 mask, u32 val, #define mt76_poll_msec(dev, ...) __mt76_poll_msec(&((dev)->mt76), __VA_ARGS__) void mt76_mmio_init(struct mt76_dev *dev, void __iomem *regs); +void mt76_mmio_disable_aspm(struct pci_dev *pdev); static inline u16 mt76_chip(struct mt76_dev *dev) { diff --git a/drivers/net/wireless/mediatek/mt76/mt76x2/pci.c b/drivers/net/wireless/mediatek/mt76/mt76x2/pci.c index 73c3104f8858..264bef87e5c7 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x2/pci.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x2/pci.c @@ -81,6 +81,8 @@ mt76pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) /* RG_SSUSB_CDR_BR_PE1D = 0x3 */ mt76_rmw_field(dev, 0x15c58, 0x3 << 6, 0x3); + mt76_mmio_disable_aspm(pdev); + return 0; error: -- 2.21.0