From patchwork Mon Aug 7 02:09:51 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sinan Kaya X-Patchwork-Id: 9884273 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 632C560364 for ; Mon, 7 Aug 2017 02:10:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4D9BC2861B for ; Mon, 7 Aug 2017 02:10:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 423BC28620; Mon, 7 Aug 2017 02:10:17 +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 D69FD2861B for ; Mon, 7 Aug 2017 02:10:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751429AbdHGCKC (ORCPT ); Sun, 6 Aug 2017 22:10:02 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:45960 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751409AbdHGCKA (ORCPT ); Sun, 6 Aug 2017 22:10:00 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 0DAB6601D7; Mon, 7 Aug 2017 02:09:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1502071800; bh=b6FGMEJUO5HQMkvdPK1G1VL+Nl+vc9caQ2nf7VWEY1c=; h=From:To:Cc:Subject:Date:From; b=SgUPOax8PuPcESJ0BBk9POiJeSTMfRp7wgaky/44i/3Z+g5bV/KbDzUy+jxawecCW rkCR3ZFNzCogVNmqSertwhEOxNByCNNqMPQFwiqQ4ABrqtPx2P+4R9xt8kVQFYPdKl 3PFgNT63Vs1amA4T+yyE8ve4KeDdwUmBUObEIO28= 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 8C885601D7; Mon, 7 Aug 2017 02:09:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1502071799; bh=b6FGMEJUO5HQMkvdPK1G1VL+Nl+vc9caQ2nf7VWEY1c=; h=From:To:Cc:Subject:Date:From; b=Q44BFOD/9KINID1haqtBCyI7mKejB7pQht5MoK4IGQ05t+b8jQCvXLvc0sXz11OWO p7qDDJTl4EN9+KTki5FD8OEHm92aAMrEOP/aYCvOz90P05QWFvByPZbfCgmI/jYwYW 5IGgJXSji/gkRQZ78CdeDSU/1wN15fdS5XQOAVeQ= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 8C885601D7 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 V8 1/2] PCI: handle CRS returned by device after FLR Date: Sun, 6 Aug 2017 22:09:51 -0400 Message-Id: <1502071792-15263-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 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. 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 0xFFFF0001 value and will continue polling until a value other than 0xFFFF0001 is returned within a given timeout. Try to discover device presence via CRS if supported. Otherwise, fall through to old behavior. Signed-off-by: Sinan Kaya --- drivers/pci/pci.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index af0cc34..cc9f1c0 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -3819,8 +3819,26 @@ int pci_wait_for_pending_transaction(struct pci_dev *dev) */ static void pci_flr_wait(struct pci_dev *dev) { + u16 root_cap = 0; int i = 0; u32 id; + bool ret; + + pcie_capability_read_word(dev, PCI_EXP_RTCAP, &root_cap); + if (root_cap & PCI_EXP_RTCAP_CRSVIS) { + /* don't touch the HW before waiting 100ms */ + msleep(100); + + /* + * Physical functions return from here if found, + * virtual functions fall through as they return ~0 on vendor + * id read once CRS is completed. + */ + ret = pci_bus_read_dev_vendor_id(dev->bus, dev->devfn, &id, + 60000); + if (ret) + return; + } do { msleep(100);