From patchwork Thu Jul 6 16:10:50 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Puthukattukaran X-Patchwork-Id: 785209 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3x3N1p6llbz9s75 for ; Fri, 7 Jul 2017 02:07:58 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751949AbdGFQHe (ORCPT ); Thu, 6 Jul 2017 12:07:34 -0400 Received: from userp1040.oracle.com ([156.151.31.81]:44858 "EHLO userp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751653AbdGFQHd (ORCPT ); Thu, 6 Jul 2017 12:07:33 -0400 Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id v66G7Tu0003721 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 6 Jul 2017 16:07:30 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id v66G7T58023805 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 6 Jul 2017 16:07:29 GMT Received: from abhmp0012.oracle.com (abhmp0012.oracle.com [141.146.116.18]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id v66G7T0x010606; Thu, 6 Jul 2017 16:07:29 GMT Received: from dhcp-burlington8-2nd-B-east-10-152-39-142.usdhcp.oraclecorp.com (/10.152.31.130) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 06 Jul 2017 09:07:28 -0700 Message-ID: <595E610A.5000900@oracle.com> Date: Thu, 06 Jul 2017 12:10:50 -0400 From: James Puthukattukaran User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/17.0 Thunderbird/17.0 MIME-Version: 1.0 To: Bjorn Helgaas CC: "linux-pci@vger.kernel.org" , Linux Kernel Mailing List , Yinghai Lu Subject: [PATCH v5] PCI: Workaround wrong flags completions for IDT switch X-Source-IP: userv0022.oracle.com [156.151.31.74] Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org From: James Puthukattukaran The IDT switch incorrectly flags an ACS source violation on a read config request to an end point device on the completion (IDT 89H32H8G3-YC, errata #36) even though the PCI Express spec states that completions are never affected by ACS source violation (PCI Spec 3.1, Section 6.12.1.1). The suggested workaround by IDT is to issue a configuration write to the downstream device before issuing the first config read. This allows the downstream device to capture its bus number, thus avoiding the ACS violation on the completion. The patch does the following - 1. Disable ACS source violation if enabled 2. Wait for config space access to become available by reading vendor id 3. Do a config write to the end point (errata workaround) 4. Enable ACS source validation (if it was enabled to begin with) -v2: move workaround to pci_bus_read_dev_vendor_id() from pci_bus_check_dev() and move enable_acs_sv to drivers/pci/pci.c -- by Yinghai -v3: add bus->self check for root bus and virtual bus for sriov vfs. -v4: only do workaround for IDT switches -v5: tweak pci_std_enable_acs_sv to deal with unimplemented SV and clarify return value Signed-off-by: James Puthukattukaran Signed-off-by: Yinghai Lu --- drivers/pci/pci.c | 37 +++++++++++++++++++++++++++++++++++++ drivers/pci/pci.h | 1 + drivers/pci/probe.c | 38 ++++++++++++++++++++++++++++++++++++-- 3 files changed, 74 insertions(+), 2 deletions(-) EXPORT_SYMBOL(pci_bus_read_dev_vendor_id); diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index 563901c..4645bfd 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -2835,6 +2835,43 @@ static bool pci_acs_flags_enabled(struct pci_dev *pdev, u 16 acs_flags) } /** + * pci_std_enable_acs_sv - enable/disable ACS source validation if supported b y the switch + * @dev - pcie switch/RP + * @enable - enable (1) or disable (0) source validation + * + * Returns : < 0 on failure (if SV capability is not implemented) + * previous acs_sv state (0 or 1) + */ +int pci_std_enable_acs_sv(struct pci_dev *dev, bool enable) +{ + int pos; + u16 cap; + u16 ctrl; + int retval; + + pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ACS); + if (!pos) + return -ENODEV; + + pci_read_config_word(dev, pos + PCI_ACS_CAP, &cap); + + if (!(cap & PCI_ACS_SV)) + return -ENODEV; + + pci_read_config_word(dev, pos + PCI_ACS_CTRL, &ctrl); + + retval = !!(ctrl & cap & PCI_ACS_SV); + if (enable) + ctrl |= (cap & PCI_ACS_SV); + else + ctrl &= ~(cap & PCI_ACS_SV); + + pci_write_config_word(dev, pos + PCI_ACS_CTRL, ctrl); + + return retval; +} ++/** * pci_acs_enabled - test ACS against required flags for a given device * @pdev: device to test * @acs_flags: required PCI ACS flags diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h index f8113e5..3960c2a 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -343,6 +343,7 @@ static inline resource_size_t pci_resource_alignment(struct pci_dev *dev, } void pci_enable_acs(struct pci_dev *dev); +int pci_std_enable_acs_sv(struct pci_dev *dev, bool enable); #ifdef CONFIG_PCIE_PTM void pci_ptm_init(struct pci_dev *dev); diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c index 19c8950..c154a90 100644 --- a/drivers/pci/probe.c +++ b/drivers/pci/probe.c @@ -1763,8 +1763,8 @@ struct pci_dev *pci_alloc_dev(struct pci_bus *bus) } EXPORT_SYMBOL(pci_alloc_dev); -bool pci_bus_read_dev_vendor_id(struct pci_bus *bus, int devfn, u32 *l, - int crs_timeout) +static bool __pci_bus_read_dev_vendor_id(struct pci_bus *bus, int devfn, + u32 *l, int crs_timeout) { int delay = 1; @@ -1801,6 +1801,40 @@ bool pci_bus_read_dev_vendor_id(struct pci_bus *bus, int devfn, u32 *l, return true; } + +bool pci_bus_read_dev_vendor_id(struct pci_bus *bus, int devfn, u32 *l, + int crs_timeout) +{ + int found; + int enable = -1; + int idt_workaround = (bus->self && (bus->self->vendor == PCI_VENDOR_ID_I DT)); + /* + * Some IDT switches flag an ACS violation for config reads + * even though the PCI spec allows for it (PCIe 3.1, 6.1.12.1) + * It flags it because the bus number is not properly set in the + * completion. The workaround is to do a dummy write to properly + * latch number once the device is ready for config operations + */ + + if (idt_workaround) + enable = pci_std_enable_acs_sv(bus->self, false); + + found = __pci_bus_read_dev_vendor_id(bus, devfn, l, crs_timeout); + + /* + * The fact that we can read the vendor id indicates that the device + * is ready for config operations. Do the write as part of the errata + * workaround. + */ + if (idt_workaround) { + if (found) + pci_bus_write_config_word(bus, devfn, PCI_VENDOR_ID, 0); + if (enable > 0) + pci_std_enable_acs_sv(bus->self, enable); + } + + return found; +}