From patchwork Fri Jul 7 14:53:13 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sinan Kaya X-Patchwork-Id: 9830615 X-Patchwork-Delegate: bhelgaas@google.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 785C3604D9 for ; Fri, 7 Jul 2017 14:53:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6A89D2869B for ; Fri, 7 Jul 2017 14:53:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5DBB4286AB; Fri, 7 Jul 2017 14:53:25 +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=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable 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 F33E2286A2 for ; Fri, 7 Jul 2017 14:53:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751032AbdGGOxX (ORCPT ); Fri, 7 Jul 2017 10:53:23 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:48308 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750882AbdGGOxW (ORCPT ); Fri, 7 Jul 2017 10:53:22 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 9364760A3B; Fri, 7 Jul 2017 14:53:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1499439201; bh=r9Yl+giPtQEYP6NaKaYN+XZaQWMMdlQOPj6OldzsGxM=; h=From:To:Cc:Subject:Date:From; b=WMayTQNJTPhx55/oba+LKD+MBDGlVI4Uaxh2Ed8lGFID3ARInHPWSJPyQgMhVWYu/ DY3OkRM52yCZOGoasnGA7Akclv/MhJSSdDyRDLUoP+2Fn+bA8nDbExhGQx56ss3c3j ZiVPk3RbkSo/Xvk/C8lkhUfMRGkfN2f2gBfG8V+o= Received: from drakthul.qualcomm.com (global_nat1_iad_fw.qualcomm.com [129.46.232.65]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: okaya@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 5A2E36032D; Fri, 7 Jul 2017 14:53:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1499439201; bh=r9Yl+giPtQEYP6NaKaYN+XZaQWMMdlQOPj6OldzsGxM=; h=From:To:Cc:Subject:Date:From; b=WMayTQNJTPhx55/oba+LKD+MBDGlVI4Uaxh2Ed8lGFID3ARInHPWSJPyQgMhVWYu/ DY3OkRM52yCZOGoasnGA7Akclv/MhJSSdDyRDLUoP+2Fn+bA8nDbExhGQx56ss3c3j ZiVPk3RbkSo/Xvk/C8lkhUfMRGkfN2f2gBfG8V+o= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 5A2E36032D Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=okaya@codeaurora.org From: Sinan Kaya To: linux-pci@vger.kernel.org, timur@codeaurora.org, wim.ten.have@oracle.com Cc: linux-arm-msm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Sinan Kaya , Bjorn Helgaas , linux-kernel@vger.kernel.org Subject: [PATCH V2] PCI: Do not enable extended tags on pre-dated (v1.x) systems Date: Fri, 7 Jul 2017 10:53:13 -0400 Message-Id: <1499439193-16628-1-git-send-email-okaya@codeaurora.org> X-Mailer: git-send-email 1.9.1 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP According to extended tags ECN document, all PCIe receivers are expected to support extended tags support. It should be safe to enable extended tags on endpoints without checking compatibility. This assumption seems to be working fine except for the legacy systems. The ECN has been written against PCIE spec version 2.0. Therefore, we need to exclude all version 1.0 devices from this change as there is HW out there that can't handle extended tags. Note that the default value of Extended Tags Enable bit is implementation specific. Therefore, we are clearing the bit by default when incompatible HW is found without assuming that value is zero. Reported-by: Wim ten Have Link: https://pcisig.com/sites/default/files/specification_documents/ECN_Extended_Tag_Enable_Default_05Sept2008_final.pdf Link: https://bugzilla.redhat.com/show_bug.cgi?id=1467674 Fixes: 60db3a4d8cc9 ("PCI: Enable PCIe Extended Tags if supported") Signed-off-by: Sinan Kaya --- drivers/pci/probe.c | 45 +++++++++++++++++++++++++++++++++++++++------ 1 file changed, 39 insertions(+), 6 deletions(-) diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c index 19c8950..e3b3c18 100644 --- a/drivers/pci/probe.c +++ b/drivers/pci/probe.c @@ -1684,21 +1684,51 @@ static void program_hpp_type2(struct pci_dev *dev, struct hpp_type2 *hpp) */ } -static void pci_configure_extended_tags(struct pci_dev *dev) +static int pcie_bus_discover_legacy(struct pci_dev *dev, void *data) { + bool *found = data; + int rc; + u16 flags; + + if (!pci_is_pcie(dev)) + return 0; + + rc = pcie_capability_read_word(dev, PCI_EXP_FLAGS, &flags); + if (!rc && ((flags & PCI_EXP_FLAGS_VERS) < 2)) + *found = true; + + return 0; +} + +static int pcie_bus_configure_exttags(struct pci_dev *dev, void *legacy) +{ + bool supported = !*(bool *)legacy; u32 dev_cap; + u16 flags; int ret; if (!pci_is_pcie(dev)) - return; + return 0; + + ret = pcie_capability_read_word(dev, PCI_EXP_FLAGS, &flags); + if (ret || ((flags & PCI_EXP_FLAGS_VERS) < 2)) + return 0; ret = pcie_capability_read_dword(dev, PCI_EXP_DEVCAP, &dev_cap); - if (ret) - return; + if (ret || (!(dev_cap & PCI_EXP_DEVCAP_EXT_TAG))) + return 0; - if (dev_cap & PCI_EXP_DEVCAP_EXT_TAG) + if (supported) { + dev_dbg(&dev->dev, "setting extended tags capability\n"); pcie_capability_set_word(dev, PCI_EXP_DEVCTL, PCI_EXP_DEVCTL_EXT_TAG); + } else { + dev_dbg(&dev->dev, "clearing extended tags capability\n"); + pcie_capability_clear_word(dev, PCI_EXP_DEVCTL, + PCI_EXP_DEVCTL_EXT_TAG); + } + + return 0; } static void pci_configure_device(struct pci_dev *dev) @@ -1707,7 +1737,6 @@ static void pci_configure_device(struct pci_dev *dev) int ret; pci_configure_mps(dev); - pci_configure_extended_tags(dev); memset(&hpp, 0, sizeof(hpp)); ret = pci_get_hp_params(dev, &hpp); @@ -2201,6 +2230,7 @@ static int pcie_bus_configure_set(struct pci_dev *dev, void *data) void pcie_bus_configure_settings(struct pci_bus *bus) { u8 smpss = 0; + bool legacy_found = false; if (!bus->self) return; @@ -2224,6 +2254,9 @@ void pcie_bus_configure_settings(struct pci_bus *bus) pcie_bus_configure_set(bus->self, &smpss); pci_walk_bus(bus, pcie_bus_configure_set, &smpss); + + pci_walk_bus(bus, pcie_bus_discover_legacy, &legacy_found); + pci_walk_bus(bus, pcie_bus_configure_exttags, &legacy_found); } EXPORT_SYMBOL_GPL(pcie_bus_configure_settings);