From patchwork Fri Jan 19 11:10:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oza Pawandeep X-Patchwork-Id: 10175063 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 B04C760386 for ; Fri, 19 Jan 2018 11:11:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A076228657 for ; Fri, 19 Jan 2018 11:11:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 94A9428669; Fri, 19 Jan 2018 11:11:30 +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=ham 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 E41FC28657 for ; Fri, 19 Jan 2018 11:11:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755621AbeASLL2 (ORCPT ); Fri, 19 Jan 2018 06:11:28 -0500 Received: from smtp.codeaurora.org ([198.145.29.96]:32940 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755360AbeASLKp (ORCPT ); Fri, 19 Jan 2018 06:10:45 -0500 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 3AB8960452; Fri, 19 Jan 2018 11:10:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1516360245; bh=33z5lQDkJ0Y2KNDAOf45/45H4QVhuuRjWuPkKppErdk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YS0FrodwIe2uCCPqzUIMw+avYbwLuTPljfNhxBq4dg4qhFKAFnpOCr3v187InGeLS P1ot54Lj+SfFbWR40w3labT30KIRIMd1QVRGF3xVP7ODS91EofcgVZvCn5SKAEVM3v 0d2FouFHUgSgBqN1ZhwjhU7hhOx9SO22FOwoJAIk= Received: from blr-ubuntu-poza.qualcomm.com (blr-bdr-fw-01_globalnat_allzones-outside.qualcomm.com [103.229.18.19]) (using TLSv1.1 with cipher ECDHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) (Authenticated sender: poza@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id DF63E6081E; Fri, 19 Jan 2018 11:10:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1516360244; bh=33z5lQDkJ0Y2KNDAOf45/45H4QVhuuRjWuPkKppErdk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VgRpR0V33x1ShFw32RVhDqSpiiNX0ldp5AnJNbAKm79uNgyyDcmYe4QDlV/A271Hz JK+7Q19kn89t54/G2rlqsW6IAcMINmju8+i1Wgs8qt+iNoI/siFuYoZ6tGX7RMhnKm 4y74tPvrp5IPy+uJz8bxKeaP1Z4lITya2tnJwQ78= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org DF63E6081E 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=poza@codeaurora.org From: Oza Pawandeep To: Bjorn Helgaas , Philippe Ombredanne , Thomas Gleixner , Greg Kroah-Hartman , Kate Stewart , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, Dongdong Liu , Keith Busch , Wei Zhang , Sinan Kaya , Timur Tabi Cc: Oza Pawandeep Subject: [PATCH v6 7/7] PCI: Unify wait for link active into generic pci Date: Fri, 19 Jan 2018 16:40:04 +0530 Message-Id: <1516360204-1586-8-git-send-email-poza@codeaurora.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1516360204-1586-1-git-send-email-poza@codeaurora.org> References: <1516360204-1586-1-git-send-email-poza@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 Clients such as pciehp, dpc are using pcie_wait_link_active, which waits till the link becomes active or inactive. Made generic function and moved it to drivers/pci/pci.c Signed-off-by: Oza Pawandeep diff --git a/drivers/pci/hotplug/pciehp_hpc.c b/drivers/pci/hotplug/pciehp_hpc.c index 7bab060..26afeff 100644 --- a/drivers/pci/hotplug/pciehp_hpc.c +++ b/drivers/pci/hotplug/pciehp_hpc.c @@ -245,25 +245,12 @@ bool pciehp_check_link_active(struct controller *ctrl) return ret; } -static void __pcie_wait_link_active(struct controller *ctrl, bool active) +static bool pcie_wait_link_active(struct controller *ctrl) { - int timeout = 1000; - - if (pciehp_check_link_active(ctrl) == active) - return; - while (timeout > 0) { - msleep(10); - timeout -= 10; - if (pciehp_check_link_active(ctrl) == active) - return; - } - ctrl_dbg(ctrl, "Data Link Layer Link Active not %s in 1000 msec\n", - active ? "set" : "cleared"); -} + struct pci_dev *pdev = ctrl_dev(ctrl); + bool active = true; -static void pcie_wait_link_active(struct controller *ctrl) -{ - __pcie_wait_link_active(ctrl, true); + return pci_wait_for_link(pdev, active); } static bool pci_bus_check_dev(struct pci_bus *bus, int devfn) diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index 4a7c686..0de83ea 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -2805,7 +2805,7 @@ static void pci_std_enable_acs(struct pci_dev *dev) pci_read_config_word(dev, pos + PCI_ACS_CTRL, &ctrl); /* Source Validation */ - ctrl |= (cap & PCI_ACS_SV); +// ctrl |= (cap & PCI_ACS_SV); /* P2P Request Redirect */ ctrl |= (cap & PCI_ACS_RR); @@ -4079,6 +4079,43 @@ static int pci_pm_reset(struct pci_dev *dev, int probe) return 0; } +/** + * pci__wait_for_link - Wait for link till its active/inactive + * @dev: Bridge device + * @active: waiting for active or inactive ? + * + * Use this to wait till link becomes active or inactive. + */ + +bool pci_wait_for_link(struct pci_dev *pdev, bool active) +{ + int timeout = 1000; + bool ret; + u16 lnk_status; + +check_link: + pcie_capability_read_word(pdev, PCI_EXP_LNKSTA, &lnk_status); + ret = !!(lnk_status & PCI_EXP_LNKSTA_DLLLA); + + if (ret == active) { + dev_printk(KERN_DEBUG, &pdev->dev, + "%s: lnk_status = %x\n", __func__, lnk_status); + return true; + } + + while (timeout > 0) { + msleep(10); + timeout -= 10; + goto check_link; + } + dev_printk(KERN_DEBUG, &pdev->dev, + "Data Link Layer Link Active not %s in 1000 msec\n", + active ? "set" : "cleared"); + + return false; +} +EXPORT_SYMBOL(pci_wait_for_link); + void pci_reset_secondary_bus(struct pci_dev *dev) { u16 ctrl; diff --git a/drivers/pci/pcie/pcie-dpc.c b/drivers/pci/pcie/pcie-dpc.c index 1b06a8e..67502a5 100644 --- a/drivers/pci/pcie/pcie-dpc.c +++ b/drivers/pci/pcie/pcie-dpc.c @@ -150,37 +150,9 @@ static void dpc_wait_link_inactive(struct dpc_dev *dpc) struct pci_dev *pdev = dpc->dev->port; struct device *dev = &dpc->dev->device; u16 lnk_status; + bool active = false; - pcie_capability_read_word(pdev, PCI_EXP_LNKSTA, &lnk_status); - while (lnk_status & PCI_EXP_LNKSTA_DLLLA && - !time_after(jiffies, timeout)) { - msleep(10); - pcie_capability_read_word(pdev, PCI_EXP_LNKSTA, &lnk_status); - } - if (lnk_status & PCI_EXP_LNKSTA_DLLLA) - dev_warn(dev, "Link state not disabled for DPC event\n"); -} - -static bool dpc_wait_link_active(struct pci_dev *pdev) -{ - unsigned long timeout = jiffies + HZ; - u16 lnk_status; - bool ret = true; - - pcie_capability_read_word(pdev, PCI_EXP_LNKSTA, &lnk_status); - - while (!(lnk_status & PCI_EXP_LNKSTA_DLLLA) && - !time_after(jiffies, timeout)) { - msleep(10); - pcie_capability_read_word(pdev, PCI_EXP_LNKSTA, &lnk_status); - } - - if (!(lnk_status & PCI_EXP_LNKSTA_DLLLA)) { - dev_warn(&pdev->dev, "Link state not enabled after DPC event\n"); - ret = false; - } - - return ret; + pci_wait_for_link(pdev, active); } /** @@ -191,7 +163,9 @@ static bool dpc_wait_link_active(struct pci_dev *pdev) */ static void dpc_error_resume(struct pci_dev *pdev) { - if (dpc_wait_link_active(pdev)) { + bool active = true; + + if (pci_wait_for_link(pdev, active)) { pci_lock_rescan_remove(); pci_rescan_bus(pdev->bus); pci_unlock_rescan_remove(); diff --git a/include/linux/pci.h b/include/linux/pci.h index c170c92..f9f6a3d 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -1201,6 +1201,7 @@ int pci_add_ext_cap_save_buffer(struct pci_dev *dev, int pci_request_selected_regions(struct pci_dev *, int, const char *); int pci_request_selected_regions_exclusive(struct pci_dev *, int, const char *); void pci_release_selected_regions(struct pci_dev *, int); +bool pci_wait_for_link(struct pci_dev *pdev, bool active); /* drivers/pci/bus.c */ struct pci_bus *pci_bus_get(struct pci_bus *bus);