Received: by 10.192.165.148 with SMTP id m20csp1425634imm; Wed, 2 May 2018 22:07:28 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqin+DvzR8VY3k4XcoMOPcN59DWlD5igCzfuuoX2Ue61rrkIYlfZXgCBz6+8LmuWLgKKYrr X-Received: by 2002:a63:724f:: with SMTP id c15-v6mr7305389pgn.267.1525324048300; Wed, 02 May 2018 22:07:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525324048; cv=none; d=google.com; s=arc-20160816; b=zYQ5mOg3GcH5torFzrVOdfDobkSYXli7JWDljj08YZDsw0QfDI04uMtRcKMVZbiWzt O96lsT3LLa2/K6Z3Ibp97qG8tFXo6Iyd/HL0Ll7M34kevHO6dq2pU4oKoU/slEdxS3WM afSMyHZtdS1nMLSd3c0yHNevisBFpVOz9bLLtcT3s0Y381sMqK5cgOZlj09rlAowNk1o CgngXHR8Ct1loUSaBB27RdLx2GYoOAfkNM5ImxR38a5Tlyzf5gzXD/kKHD/wsFSKHNLS ph3gdJOeEx7XsS9puyYp7j59Y7OWF82zODw+S0CKty2re2ZkSH659YP9PRuJfItbhZd9 5SOQ== 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=dY0ypwj5GrLie1Utu+5ocJCk0ezJCHcYZ4XYx0A8+x4=; b=j2ncvbHO625a8RFalMfKWFzJNdYyIOaxsGlbBZV+oHunqRsNKoI4QmyRZpRZN3HAMf L9rRmTTMG8uAbf9xcPDXrkuFoQU/yryQMX7WANPuvThNMtJBZpZKiBGppFV0/QYAGw+Y TBoikK/9X/7BxnQ5mni01oyl3yXEyuFuDJrxVP87B84HN8lVi2nCqJDc5NtybAHUF3N2 kDXERd1THc542XLADW2tbzaXh6goXqVzb/3iLbEbtvyx+7X5v4SLjwGbrdY6HKslUpcy XEg4ROvj/kihoUHrDHQzU2MU1jdnewJsfdMjmqK6pNsOq5pnn1BAfsarBNDhq/swLdVv YdEg== 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 j16-v6si10572196pgn.233.2018.05.02.22.07.14; Wed, 02 May 2018 22:07:28 -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 S1751977AbeECFEG (ORCPT + 99 others); Thu, 3 May 2018 01:04:06 -0400 Received: from alexa-out.qualcomm.com ([129.46.98.28]:56509 "EHLO alexa-out.qualcomm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751774AbeECFEE (ORCPT ); Thu, 3 May 2018 01:04:04 -0400 X-IronPort-AV: E=Sophos;i="5.49,356,1520924400"; d="scan'208";a="17093181" Received: from ironmsg02-sd.qualcomm.com ([10.53.140.142]) by alexa-out.qualcomm.com with ESMTP; 02 May 2018 22:04:04 -0700 Received: from westreach.qualcomm.com ([10.228.196.125]) by ironmsg02-sd.qualcomm.com with ESMTP; 02 May 2018 22:04:02 -0700 Received: by westreach.qualcomm.com (Postfix, from userid 467151) id AF1D71F12; Thu, 3 May 2018 01:04:01 -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 v15 1/9] PCI: Unify wait for link active into generic PCI Date: Thu, 3 May 2018 01:03:50 -0400 Message-Id: <1525323838-1735-2-git-send-email-poza@codeaurora.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1525323838-1735-1-git-send-email-poza@codeaurora.org> References: <1525323838-1735-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 e597655..2e4d1e4 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