Received: by 10.192.165.148 with SMTP id m20csp3554467imm; Mon, 23 Apr 2018 08:27:05 -0700 (PDT) X-Google-Smtp-Source: AIpwx49Yt15aWUtZplGU0mVwVIDZ7/KmUeYjEMFTxK0tcHoVjsZ8w850s52uQB/mK/aze24GaKyf X-Received: by 2002:a17:902:7c0f:: with SMTP id x15-v6mr21111391pll.369.1524497225784; Mon, 23 Apr 2018 08:27:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524497225; cv=none; d=google.com; s=arc-20160816; b=EaEJ5rV5c9skYW8AzygsSsN29+EvXdQBiGf8LSC38xihjBtWZG9V9jsY0A3KwZFwCX Ye3GlcvjEv7KppsfRcK4V0fRYsvkgzw9/SVi8yeEUU1AugUgtcRNEVRdjtbX9Oyw+apw /BEfn0Df6nwmWhIiatPglPRngV1hGys/xEayPXLEOg283dwK7xltZFFTSauLxwduXXpx 21y24O3aPS4xBoCSKrFJL5rIEhm/AHmIwyTfrjt0Er2GshYByu2CfmTGlL0adXXBGzUo jrU1opg5LW44H558LGvIJDKYjNrclQUY1dnriCxZFGhN8PHFo3OmPr+eEBcNv1XwRGGR 08og== 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=+d3MgnKfIoj7f2/bsjlph13GVBInKp2VnVePwVd4Gg8=; b=F5Xoj45uSH368KcTl/Qb2pPR78LML2Aut0w4JWsn90e5oENZ9Dxp8LmCZQhLIvD8xv fRQ4+guqi18GUEtKhf0nfDTGTmq2DU00fiftKe26x4EJdrbDIN78F9nvf4Da40OzWFJI xeVhI/QRipsbyy5ZgkFm9YgklWUteuvUz7FI33eGZgBlh1fLG71u3tVlWN8lDtgy+j3G xpUpL8GVTkYCTdonvrQoEz9NTWidR9TdvZVAGFXHA2e3RO547zmox+RbDWqn6Ton4srH tRW43wxX83sxcMAme15sspV4yECrPnD8LoOOkOyHELid+rR0sHgh4XGKqFskPwZeoEvM EnPg== 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 w6si4023951pgb.481.2018.04.23.08.26.51; Mon, 23 Apr 2018 08:27:05 -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 S932168AbeDWPZF (ORCPT + 99 others); Mon, 23 Apr 2018 11:25:05 -0400 Received: from alexa-out.qualcomm.com ([129.46.98.28]:44199 "EHLO alexa-out.qualcomm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755693AbeDWPXR (ORCPT ); Mon, 23 Apr 2018 11:23:17 -0400 X-IronPort-AV: E=Sophos;i="5.49,318,1520924400"; d="scan'208";a="16839218" Received: from ironmsg04-sd.qualcomm.com ([10.53.140.144]) by alexa-out.qualcomm.com with ESMTP; 23 Apr 2018 08:23:17 -0700 X-IronPort-AV: E=McAfee;i="5900,7806,8871"; a="68659285" Received: from westreach.qualcomm.com ([10.228.196.125]) by ironmsg04-sd.qualcomm.com with ESMTP; 23 Apr 2018 08:23:15 -0700 Received: by westreach.qualcomm.com (Postfix, from userid 467151) id 890581F0B; Mon, 23 Apr 2018 11:23:14 -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 v14 6/9] PCI: Unify wait for link active into generic PCI Date: Mon, 23 Apr 2018 11:23:10 -0400 Message-Id: <1524496993-29799-7-git-send-email-poza@codeaurora.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1524496993-29799-1-git-send-email-poza@codeaurora.org> References: <1524496993-29799-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 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 f6a4dd1..2bcf977 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -4176,6 +4176,36 @@ static int pci_pm_reset(struct pci_dev *dev, int probe) return 0; } +/** + * 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) { u16 ctrl; diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h index abc514e..5c44fbc 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -345,6 +345,8 @@ void pci_enable_acs(struct pci_dev *dev); /* PCI error reporting and recovery */ void pcie_do_recovery(struct pci_dev *dev, int severity); +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/pcie-dpc.c b/drivers/pci/pcie/pcie-dpc.c index ad02298..6baed85 100644 --- a/drivers/pci/pcie/pcie-dpc.c +++ b/drivers/pci/pcie/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); } /** -- 2.7.4