Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp2970262imm; Thu, 17 May 2018 00:48:24 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpPZKsY4FvTwV48XUfFSg0NO7a7I8LpFLJoYhl367Q3Lup2PyJbxwU7vXb/relE05KpXVfk X-Received: by 2002:a17:902:bc4a:: with SMTP id t10-v6mr4171778plz.343.1526543304805; Thu, 17 May 2018 00:48:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526543304; cv=none; d=google.com; s=arc-20160816; b=PQ33SCVs9xRWjRzqwd+tU+UbgzC6Sc7aAqeMmyhhmhVUtWohDjvxO7wsid9ZtPYMxx rdTZTCKDW8XCMHHJGQMUUonzTlfUhf3tNW6OJ8wdloIZYzIjJ8y19ZzyT0rPfIQWeurB bmRjqNt9XetU2s0DHPuIN5OzkU1wkxcofjLDdWusCgHN8ZVQlKZOtboh7RXtvwqm7ebI yrTZDyqbX2FzdQ0/uhZK/XERXbWk7BQ5K9sunEO1piJXuDUzz2aPKUxNSO3/lu0nmPRS zg3uzHOklpUqXX/oBw9Kdre6/leVkSmUD/Mc8fBfnr55mDWibyg7ZRDnCyYU5zaKu3A2 mcTQ== 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=eNp6Gqz2q7MRIZD5NnxjeQ9uNXYlH4ANuZrw16U3i8Y=; b=cr3wYcEWf079vqlyWlG0InIzyvUS/YphuOr/vz9KTOqgZeKkMZn6c02Mbyf7IaIk8S hvGrzbe08ZXuWiYTXzIBsYPCMmdsAeDbp9oZ1k04bly4rnTQToHhUbS5UKxnLLwKjCkt FBDMPag4ur5CY06UmVtJGrwEy7MJm1AcJm9oSvjV/qctD0BInlUwQ5C6cosioF0bVl4u fpYNM7Zjd1hPibDT4YRUc1gx7hS98Ks2pbCLvOmx9LXRO3UucdblmH3o9dPcC3cmnXFX ujr0bDkjWWSpLVWESVG6qtenH6FqUV3TpUhW0+3thWCZbefytFq5JCn1YjsMwd6u5wXE VP8A== 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 g8-v6si3610208pgv.151.2018.05.17.00.48.10; Thu, 17 May 2018 00:48:24 -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 S1752445AbeEQHnQ (ORCPT + 99 others); Thu, 17 May 2018 03:43:16 -0400 Received: from alexa-out.qualcomm.com ([129.46.98.28]:57577 "EHLO alexa-out.qualcomm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752393AbeEQHnP (ORCPT ); Thu, 17 May 2018 03:43:15 -0400 X-IronPort-AV: E=Sophos;i="5.49,409,1520924400"; d="scan'208";a="17447178" Received: from ironmsg-sd-alpha.qualcomm.com ([10.53.140.30]) by alexa-out.qualcomm.com with ESMTP; 17 May 2018 00:43:14 -0700 X-IronPort-AV: E=McAfee;i="5900,7806,8890"; a="195745864" Received: from westreach.qualcomm.com ([10.228.196.125]) by ironmsg-SD-alpha.qualcomm.com with ESMTP; 17 May 2018 00:43:13 -0700 Received: by westreach.qualcomm.com (Postfix, from userid 467151) id 765BBE29; Thu, 17 May 2018 03:43:12 -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 , Bjorn Helgaas Subject: [PATCH v17 1/9] PCI: Add generic pcie_wait_for_link() interface Date: Thu, 17 May 2018 03:43:03 -0400 Message-Id: <1526542991-5291-2-git-send-email-poza@codeaurora.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1526542991-5291-1-git-send-email-poza@codeaurora.org> References: <1526542991-5291-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 hotplug and Downstream Port Containment (DPC) both need to wait until a link becomes active or inactive. Add a generic pcie_wait_link_active() interface and use it instead of duplicating the code. Signed-off-by: Oza Pawandeep Signed-off-by: Bjorn Helgaas 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..764bf64 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 until link is active or 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