Received: by 10.223.185.116 with SMTP id b49csp868046wrg; Wed, 21 Feb 2018 08:12:09 -0800 (PST) X-Google-Smtp-Source: AH8x225pOv+RP5GmT0L1R2ppn83+oJhdYouUhL/+L8D3iQmoQbV+rwlenzMLNk5j8hHvzWMXJrBm X-Received: by 10.99.181.28 with SMTP id y28mr3221240pge.222.1519229529195; Wed, 21 Feb 2018 08:12:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519229529; cv=none; d=google.com; s=arc-20160816; b=Oq8aha5afVD08TDV4RkxFLlVZcn2tosbqKOG8IiVgrgwLOIf/u91n6HM5WiVgkxA2P /R0DRG/VKJhxX7Hvd0VJHFd2ib1nntBGQEtM93N2hm+S9On+KKr4u7TxeSxQhLQXFM1v MExjjcxN68HSmNnp8IjvyCUde+ulv4KA/81gA+GVJ9J+nqsgMQhAFC6HoRkurb2Du94l +MIE5kc3vEp2Qf7TmmSSaC+a+api1sLmruyqoLF93F8CoJ9kkP0qqxwZMDLxMIvKGDOY gf3e1uHXI7PbzOYJqEmYmFvPC0mBxtDASVs6zhI+AurGPArr7HztVwu+Z5TxkFypB3nG jlCw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dmarc-filter:dkim-signature:dkim-signature :arc-authentication-results; bh=C68F99KdfW2TcDW7fsC2u90EkCEZQeJJQ4o6ycCoyMw=; b=j0sV+ropIvFj+kG3hIgSBMUSe6kycu/B5bRYsYkNYuXplM1E38Nx/I4LNQ4/Iuk9+J rIf4eGq8m9S+kZaDkwO/Q1cACCGkmaaO0tyTuHNddIP38KA6dCHNEbpA/voj85hhcDeC beQ+qjdtIpzRA5bN5OTaRty93jpJWwIdTAVVp5K5ALFJJ2aW3ZCfbFV/Cn/0EnpuE3t/ ztCdS5GsBHF8dNRde2Pfwc2tfs/PFGh9MZw+fpTS4+BQb1JtB+Ek1UWbo4KaEFZ2W5LH K11SBOSQH999LS1Q6u/sUiQ3QwsImVtUSmvRhYtHHUZNDH2ErcDNKLVNRSLoNGYx99ZA 7U0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=OB4nXpJG; dkim=pass header.i=@codeaurora.org header.s=default header.b=N4ol+FDU; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e8si1752242pfi.359.2018.02.21.08.11.44; Wed, 21 Feb 2018 08:12:09 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=OB4nXpJG; dkim=pass header.i=@codeaurora.org header.s=default header.b=N4ol+FDU; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933096AbeBUK1a (ORCPT + 99 others); Wed, 21 Feb 2018 05:27:30 -0500 Received: from smtp.codeaurora.org ([198.145.29.96]:48226 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933084AbeBUK1Z (ORCPT ); Wed, 21 Feb 2018 05:27:25 -0500 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 9C1E660F6D; Wed, 21 Feb 2018 10:27:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1519208844; bh=q3MSwQtVrr9aPbWr5icQ3GhtG4Kfa/3gli8ijC2o9rQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OB4nXpJGiJXJpot+w36+/rPI8pho9kQft11PeqIQ5Pf5aZw7MpkvJQjBDlT8ouD4Q yHeTJj7NgCyv5iRp0yhSZuQn8sHId6STlt4izG1AdcIydh0c86oNEbtsccM5pt7EN1 cnMGsct5lpKpyleFx1cd2IvmvDiXcRuxtAOsElkw= X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on pdx-caf-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.8 required=2.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,T_DKIM_INVALID autolearn=no autolearn_force=no version=3.4.0 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 0CBCF6070D; Wed, 21 Feb 2018 10:27:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1519208843; bh=q3MSwQtVrr9aPbWr5icQ3GhtG4Kfa/3gli8ijC2o9rQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=N4ol+FDUmg9PYuxWmLvh2pho5jEg2zPhH7tXqdLiTRhRWhJxiCS2xBuLGeernaLNJ 9WpUyuxKdNTOIqhN0//En4VC2c88gHdhO/3iX5x7/TkGVkYiGBLgd++CV0+Ba4ArI3 Wt1Q9m+zhjAyHzdkM0qF49fohwIZMB4wrCt4xx+g= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 0CBCF6070D 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 v8 6/7] PCI: Unify wait for link active into generic pci Date: Wed, 21 Feb 2018 15:56:43 +0530 Message-Id: <1519208804-24512-7-git-send-email-poza@codeaurora.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1519208804-24512-1-git-send-email-poza@codeaurora.org> References: <1519208804-24512-1-git-send-email-poza@codeaurora.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 18a42f8..a133b8b 100644 --- a/drivers/pci/hotplug/pciehp_hpc.c +++ b/drivers/pci/hotplug/pciehp_hpc.c @@ -231,25 +231,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 f6a4dd1..aff13c5 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -4176,6 +4176,41 @@ 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; + + pcie_capability_read_word(pdev, PCI_EXP_LNKSTA, &lnk_status); + ret = !!(lnk_status & PCI_EXP_LNKSTA_DLLLA); + + while ((ret != active) && (timeout > 0)) { + msleep(10); + timeout -= 10; + pcie_capability_read_word(pdev, PCI_EXP_LNKSTA, &lnk_status); + ret = !!(lnk_status & PCI_EXP_LNKSTA_DLLLA); + } + + if (ret == active) + return true; + + 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 208b427..fce4518 100644 --- a/drivers/pci/pcie/pcie-dpc.c +++ b/drivers/pci/pcie/pcie-dpc.c @@ -122,19 +122,10 @@ static int dpc_wait_rp_inactive(struct dpc_dev *dpc) static void dpc_wait_link_inactive(struct dpc_dev *dpc) { - unsigned long timeout = jiffies + HZ; 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"); + pci_wait_for_link(pdev, active); } /** diff --git a/include/linux/pci.h b/include/linux/pci.h index 024a1be..cb674c3 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -1195,6 +1195,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); -- Qualcomm Datacenter Technologies, Inc. as an affiliate of Qualcomm Technologies, Inc., a Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.