Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp610363imm; Fri, 11 May 2018 03:44:41 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoG5U4BsW8fW9k0lWCJf4WoOnHJmfVTNrxkgOU7ci9oh/WucrG+Fi1nf5wAdbWyhKQN9T39 X-Received: by 2002:a62:4708:: with SMTP id u8-v6mr5010508pfa.89.1526035481762; Fri, 11 May 2018 03:44:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526035481; cv=none; d=google.com; s=arc-20160816; b=nWLk3ckHJgqIssQRDl1saIieovhx98zQghba2L4JgUx0eH5sJOfUEo/GeEn3+0EXJg 48lQszML6FeUP+paSDDUEHTQgo3Xk1a0UQ43IwyuIyl20tiRuXgHqNGb5X26XA2iYGkx wHbCWnVwDiWRkc72gf5NES80etFRGYHWJYj2LcHgykzHNox7U7E3CYCAnYrHAHjtEPiv Q182vfLydl5CKR6ok8SX+26/+vodk+XtfJfin7zRyDhc5E6M8/v0MtkhZ8KQFPeMP813 Ehr1J4OixUtiD7bqIDA/aAuN3Gd/edR05VFxgWGcMr59EHTz5WcfWQdeygMObzuzflVX ogEg== 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:arc-authentication-results; bh=TiuAlLFcn85H1K/Qum+domAsG4GfMtJ972BYAOV4Luo=; b=pipljAVONmsbGEmJPH69bdl8YPByVPkOLClP3P236caRTWB+/7THc/BvklfGiuq/dY NfC9a3JAGMbACjnTKYgd1UlIEPCEeCqwNdZ3/fVCcepVi6oy7/cGIzpEpUar/UmRYeBg 1ry30QLNECm8/oFFxv1aY8/ayVq3Gb9RFweZQ5x+yCr0fhN7BYXIwyj+X6LNzzgCTFGH anZdY9u0EobeFUJsR6Xh5xuJALsBoeem2zvp7kn4Ye2DdeNIWKDTz5beUAms1Fi7al2i 5hZ/ZMGh2CEc85oPHj0UtBw7IUPxTwnkEP4iWA+aoXa+x5ki7+LrAbwl+geg292cokG5 iKkw== ARC-Authentication-Results: i=1; mx.google.com; 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 e9-v6si2283089pgr.477.2018.05.11.03.44.27; Fri, 11 May 2018 03:44:41 -0700 (PDT) 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; 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 S1752994AbeEKKni (ORCPT + 99 others); Fri, 11 May 2018 06:43:38 -0400 Received: from alexa-out.qualcomm.com ([129.46.98.28]:33617 "EHLO alexa-out.qualcomm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752569AbeEKKnd (ORCPT ); Fri, 11 May 2018 06:43:33 -0400 X-IronPort-AV: E=Sophos;i="5.49,388,1520924400"; d="scan'208";a="17306044" Received: from ironmsg04-sd.qualcomm.com ([10.53.140.144]) by alexa-out.qualcomm.com with ESMTP; 11 May 2018 03:43:32 -0700 X-IronPort-AV: E=McAfee;i="5900,7806,8889"; a="82987115" Received: from westreach.qualcomm.com ([10.228.196.125]) by ironmsg04-sd.qualcomm.com with ESMTP; 11 May 2018 03:43:30 -0700 Received: by westreach.qualcomm.com (Postfix, from userid 467151) id 667B01EE6; Fri, 11 May 2018 06:43:30 -0400 (EDT) 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 v16 1/9] PCI: Unify wait for link active into generic PCI Date: Fri, 11 May 2018 06:43:20 -0400 Message-Id: <1526035408-31328-2-git-send-email-poza@codeaurora.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1526035408-31328-1-git-send-email-poza@codeaurora.org> References: <1526035408-31328-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 HP, 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 Reviewed-by: Keith Busch diff --git a/drivers/pci/hotplug/pciehp_hpc.c b/drivers/pci/hotplug/pciehp_hpc.c index 18a42f8..e0c2b8e 100644 --- a/drivers/pci/hotplug/pciehp_hpc.c +++ b/drivers/pci/hotplug/pciehp_hpc.c @@ -231,25 +231,11 @@ bool pciehp_check_link_active(struct controller *ctrl) return ret; } -static void __pcie_wait_link_active(struct controller *ctrl, bool active) -{ - 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"); -} - static void pcie_wait_link_active(struct controller *ctrl) { - __pcie_wait_link_active(ctrl, true); + struct pci_dev *pdev = ctrl_dev(ctrl); + + pcie_wait_for_link(pdev, true); } 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 e597655..adfc553 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -4138,6 +4138,35 @@ static int pci_pm_reset(struct pci_dev *dev, int probe) return pci_dev_wait(dev, "PM D3->D0", PCIE_RESET_READY_POLL_MS); } +/** + * pcie_wait_for_link - Wait for link till it's active?/inactive? + * @pdev: Bridge device + * @active: waiting for active or inactive ? + * + * Use this to wait till link becomes active or inactive. + */ +bool pcie_wait_for_link(struct pci_dev *pdev, bool active) +{ + int timeout = 1000; + bool ret; + u16 lnk_status; + + for (;;) { + pcie_capability_read_word(pdev, PCI_EXP_LNKSTA, &lnk_status); + ret = !!(lnk_status & PCI_EXP_LNKSTA_DLLLA); + if (ret == active) + return true; + if (timeout <= 0) + break; + msleep(10); + timeout -= 10; + } + + pci_info(pdev, "Data Link Layer Link Active not %s in 1000 msec\n", + active ? "set" : "cleared"); + + return false; +} void pci_reset_secondary_bus(struct pci_dev *dev) { diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h index 023f7cf..cec9d8c 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -353,6 +353,7 @@ static inline resource_size_t pci_resource_alignment(struct pci_dev *dev, void pci_enable_acs(struct pci_dev *dev); +bool pcie_wait_for_link(struct pci_dev *pdev, bool active); #ifdef CONFIG_PCIEASPM void pcie_aspm_init_link_state(struct pci_dev *pdev); void pcie_aspm_exit_link_state(struct pci_dev *pdev); diff --git a/drivers/pci/pcie/dpc.c b/drivers/pci/pcie/dpc.c index 8c57d60..80ec384 100644 --- a/drivers/pci/pcie/dpc.c +++ b/drivers/pci/pcie/dpc.c @@ -68,19 +68,9 @@ 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; - 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"); + pcie_wait_for_link(pdev, false); } static void dpc_work(struct work_struct *work) -- 2.7.4