From patchwork Wed Aug 2 19:15:16 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sinan Kaya X-Patchwork-Id: 9877441 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 437CB602BC for ; Wed, 2 Aug 2017 19:15:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3469228827 for ; Wed, 2 Aug 2017 19:15:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 297452882B; Wed, 2 Aug 2017 19:15:56 +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 B0F0628827 for ; Wed, 2 Aug 2017 19:15:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752706AbdHBTPr (ORCPT ); Wed, 2 Aug 2017 15:15:47 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:40786 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751991AbdHBTPZ (ORCPT ); Wed, 2 Aug 2017 15:15:25 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 5FA7A60A52; Wed, 2 Aug 2017 19:15:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1501701325; bh=BO0Vg7yTFYbPLrPNq/5bbTHsKVuodOFj2EtrbIj9ha8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mOpserW5tCOSBThFpDd2rxRBZZlFkdi2MvfXyI+ZNg8E2KOtpn0mypaDUg0QCs9nP ztrDtzKRgcPq7rSEpP0uYAOu9IkNwHjIlnx1yUDXHf/0Cj1wj0UKs6HwTJwd44MoAH BgFRINYoeaZKVtSYNt3ju51KzWEwmwYg4Q2nhg7c= 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 CDB56609C6; Wed, 2 Aug 2017 19:15:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1501701324; bh=BO0Vg7yTFYbPLrPNq/5bbTHsKVuodOFj2EtrbIj9ha8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lk6EKPf0Ef+CiKBvtTJoU/3sGL+X8VHwh5hr0VLs99z0xftAoertMWANIpgnqRmgQ O4drIEerPeCZWzDA/KNokVfr9XF3xBjzXI6+mEgCgACLHZxkA0o7/WlMB1wxXk3puf CpUMZa86W2f7u62xNRXYigQil/vNh9P7OIvCgemU= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org CDB56609C6 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, alex.williamson@redhat.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 V7 2/3] PCI: handle CRS returned by device after FLR Date: Wed, 2 Aug 2017 15:15:16 -0400 Message-Id: <1501701317-32249-2-git-send-email-okaya@codeaurora.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1501701317-32249-1-git-send-email-okaya@codeaurora.org> References: <1501701317-32249-1-git-send-email-okaya@codeaurora.org> 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 An endpoint is allowed to issue Configuration Request Retry Status (CRS) following a Function Level Reset (FLR) request to indicate that it is not ready to accept new requests. CRS is defined in PCIe r3.1, sec 2.3.1. Request Handling Rules and CRS usage in FLR context is mentioned in PCIe r3.1, sec 6.6.2. Function-Level Reset. Adding a vendor ID read if this is a physical function before attempting to read any other registers on the endpoint. A CRS indication will only be given if the address to be read is vendor ID register. pci_bus_read_dev_vendor_id() knows how to deal with CRS returned values. Calling pci_bus_read_dev_vendor_id() with 60 seconds timeout to be consistent with the rest of the kernel CRS timeout policy. Signed-off-by: Sinan Kaya --- drivers/pci/pci.c | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index 2ed604a..ad49e73 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -3813,30 +3813,25 @@ int pci_wait_for_pending_transaction(struct pci_dev *dev) /* * We should only need to wait 100ms after FLR for virtual functions. - * Wait for up to 1000ms for config space to return something other than -1. - * Intel IGD requires this when an LCD panel is attached. We read the 2nd - * dword because VFs don't implement the 1st dword. + * Wait for up to 60s for config space to return something other than -1. + * Intel IGD requires 300ms when an LCD panel is attached. We use + * pci_bus_read_dev_vendor_id() for reading the vendor ID as it handles + * CRS gracefully. */ static void pci_flr_wait(struct pci_dev *dev) { - int i = 0; u32 id; + bool ret; - if (dev->is_virtfn) { - msleep(100); - return; - } + /* don't touch the HW before waiting 100ms */ + msleep(100); - do { - msleep(100); - pci_read_config_dword(dev, PCI_COMMAND, &id); - } while (i++ < 10 && id == ~0); + if (dev->is_virtfn) + return; - if (id == ~0) + ret = pci_bus_read_dev_vendor_id(dev->bus, dev->devfn, &id, 60000); + if (!ret) dev_warn(&dev->dev, "Failed to return from FLR\n"); - else if (i > 1) - dev_info(&dev->dev, "Required additional %dms to return from FLR\n", - (i - 1) * 100); } /**