Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp909487ybl; Tue, 13 Aug 2019 04:38:16 -0700 (PDT) X-Google-Smtp-Source: APXvYqzd1AaUkbgqVqvSZPyB5STxC31Lkjj/5HUXR8rDBMqjKLcRdZAgB9HDbQdaidsi7WWKfxE6 X-Received: by 2002:aa7:8b51:: with SMTP id i17mr40966569pfd.33.1565696296605; Tue, 13 Aug 2019 04:38:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565696296; cv=none; d=google.com; s=arc-20160816; b=Ay76cKAc8QINJJ6sKkFGcC4TR564z1aJTup4SAGF8yYYNmxIE1maEkX42Eock8GOLp Q41dGfvBVAhyXQgYQ3GzFKbL4L5bp1CaaKzHzu5UtTJvuCA3JRpPPhnT3SHmgUTAC+pg vroMzH6SJNiMQB4fhyrtKOO8CJFvkBVESHn15NOQMNsadRpsAgCr/WtsS87Omxt6W7Ws +nP9KcQnZslypaO0yEbG3oeT4VmTUm3vaoY50TDCjcBHztpENROc587WSEIUKshgElkP B/su5lqYTXCsJz37ri8BbT8/3+h4Jger+gDL0gvJneOx55eIeJ7EkZ1hjFwc0X5cjelx rgRQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:dkim-signature:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from; bh=5j2p5HCWvfPwM17u6kK5G2CGbiZ5V2RcBZTlXTdFeRQ=; b=YHvayuM1WdugvF4DA6mU38uGpmZLwKDD8k5bLqXKsWH8e+aE5EF3pqbUY6nYJaknP4 1q98YGOzJ5ST974wP3evw1aSaKI18BOUnExrJCPTQrpbdq7fD2if/4x3SPj9vY1pzjea UCDEAa6GmYYiYEfD07WkIKmo8bvw0G8E1oV/jN5mqMBGMTb4eZHLqGW4iSMwG8ZMC2O9 TmxvVHCOndXJGyMMIhOV4LRoY+b6CmOSqlxIq520YCq2lpCPEX66kBRYeOoch/wbbpse X/KRx51drXGYd6VIJmhL/sKE7hYnesTQmPqxeZjRzEyUf9pkyBQJOC8sVFP2qhT6eiLo Bk1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nvidia.com header.s=n1 header.b=prFLC0M7; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nvidia.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 64si61648284plw.379.2019.08.13.04.38.01; Tue, 13 Aug 2019 04:38:16 -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; dkim=pass header.i=@nvidia.com header.s=n1 header.b=prFLC0M7; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nvidia.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727685AbfHMLhJ (ORCPT + 99 others); Tue, 13 Aug 2019 07:37:09 -0400 Received: from hqemgate16.nvidia.com ([216.228.121.65]:8801 "EHLO hqemgate16.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726298AbfHMLhI (ORCPT ); Tue, 13 Aug 2019 07:37:08 -0400 Received: from hqpgpgate101.nvidia.com (Not Verified[216.228.121.13]) by hqemgate16.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Tue, 13 Aug 2019 04:37:09 -0700 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate101.nvidia.com (PGP Universal service); Tue, 13 Aug 2019 04:37:06 -0700 X-PGP-Universal: processed; by hqpgpgate101.nvidia.com on Tue, 13 Aug 2019 04:37:06 -0700 Received: from HQMAIL110.nvidia.com (172.18.146.15) by HQMAIL104.nvidia.com (172.18.146.11) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Tue, 13 Aug 2019 11:37:06 +0000 Received: from HQMAIL111.nvidia.com (172.20.187.18) by hqmail110.nvidia.com (172.18.146.15) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Tue, 13 Aug 2019 11:37:06 +0000 Received: from hqnvemgw01.nvidia.com (172.20.150.20) by HQMAIL111.nvidia.com (172.20.187.18) with Microsoft SMTP Server (TLS) id 15.0.1473.3 via Frontend Transport; Tue, 13 Aug 2019 11:37:06 +0000 Received: from vidyas-desktop.nvidia.com (Not Verified[10.24.37.38]) by hqnvemgw01.nvidia.com with Trustwave SEG (v7,5,8,10121) id ; Tue, 13 Aug 2019 04:37:05 -0700 From: Vidya Sagar To: , , , , , , , , , , CC: , , , , , , , , , , Subject: [PATCH V16 04/13] PCI: dwc: Move config space capability search API Date: Tue, 13 Aug 2019 17:06:18 +0530 Message-ID: <20190813113627.27251-5-vidyas@nvidia.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190813113627.27251-1-vidyas@nvidia.com> References: <20190813113627.27251-1-vidyas@nvidia.com> X-NVConfidentiality: public MIME-Version: 1.0 Content-Type: text/plain DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1565696229; bh=5j2p5HCWvfPwM17u6kK5G2CGbiZ5V2RcBZTlXTdFeRQ=; h=X-PGP-Universal:From:To:CC:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:X-NVConfidentiality:MIME-Version: Content-Type; b=prFLC0M7IWgqvU1n/qCnNUxsNA5f2kXJOK8Db42Wq90LiBgVCH5JdSWd8ZjqADrh0 ERSJ9jK2JtR2ud1hI/QzrpvD7V1lRugKA2wz4mPvVwLkgNPhpI7DPk9fRdoXDqmVsx 7dI2OXD4Jq3PW4AKeVqmDzPhS61YokUFZtqec9zsvlvykeoA1UHMrpTFQJNstKe3X6 43J9csC1g+iYmxG6PrfdZqIWrscZC88oq7XsvSvJ2KiOg1az6aVRGW1WBT/RhYf1c9 JN6HEHCI9UvPiclUpjSgYlQFv/XxLg/BXAQr2PSxLYxFCdiW/tbPskvkLSX3bkbAG8 kNxEtg5McjTGw== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Move PCIe config space capability search API to common DesignWare file as this can be used by both host and ep mode codes. Signed-off-by: Vidya Sagar Acked-by: Gustavo Pimentel Reviewed-by: Thierry Reding --- V16: * None V15: * None V14: * None V13: * None V12: * None V11: * None V10: * None V9: * None V8: * Changed comment to explicitly state their mere resemblance to standard APIs but not their operation and place of use. V7: * Exported dw_pcie_find_capability() API V6: * None V5: * Removed redundant APIs in pcie-designware-ep.c file after moving them to pcie-designware.c file based on Bjorn's comments. V4: * Rebased to linux-next top of the tree V3: * None V2: * Removed dw_pcie_find_next_ext_capability() API from here and made a separate patch for that .../pci/controller/dwc/pcie-designware-ep.c | 37 +----------------- drivers/pci/controller/dwc/pcie-designware.c | 39 +++++++++++++++++++ drivers/pci/controller/dwc/pcie-designware.h | 2 + 3 files changed, 43 insertions(+), 35 deletions(-) diff --git a/drivers/pci/controller/dwc/pcie-designware-ep.c b/drivers/pci/controller/dwc/pcie-designware-ep.c index 2bf5a35c0570..65f479250087 100644 --- a/drivers/pci/controller/dwc/pcie-designware-ep.c +++ b/drivers/pci/controller/dwc/pcie-designware-ep.c @@ -40,39 +40,6 @@ void dw_pcie_ep_reset_bar(struct dw_pcie *pci, enum pci_barno bar) __dw_pcie_ep_reset_bar(pci, bar, 0); } -static u8 __dw_pcie_ep_find_next_cap(struct dw_pcie *pci, u8 cap_ptr, - u8 cap) -{ - u8 cap_id, next_cap_ptr; - u16 reg; - - if (!cap_ptr) - return 0; - - reg = dw_pcie_readw_dbi(pci, cap_ptr); - cap_id = (reg & 0x00ff); - - if (cap_id > PCI_CAP_ID_MAX) - return 0; - - if (cap_id == cap) - return cap_ptr; - - next_cap_ptr = (reg & 0xff00) >> 8; - return __dw_pcie_ep_find_next_cap(pci, next_cap_ptr, cap); -} - -static u8 dw_pcie_ep_find_capability(struct dw_pcie *pci, u8 cap) -{ - u8 next_cap_ptr; - u16 reg; - - reg = dw_pcie_readw_dbi(pci, PCI_CAPABILITY_LIST); - next_cap_ptr = (reg & 0x00ff); - - return __dw_pcie_ep_find_next_cap(pci, next_cap_ptr, cap); -} - static int dw_pcie_ep_write_header(struct pci_epc *epc, u8 func_no, struct pci_epf_header *hdr) { @@ -612,9 +579,9 @@ int dw_pcie_ep_init(struct dw_pcie_ep *ep) dev_err(dev, "Failed to reserve memory for MSI/MSI-X\n"); return -ENOMEM; } - ep->msi_cap = dw_pcie_ep_find_capability(pci, PCI_CAP_ID_MSI); + ep->msi_cap = dw_pcie_find_capability(pci, PCI_CAP_ID_MSI); - ep->msix_cap = dw_pcie_ep_find_capability(pci, PCI_CAP_ID_MSIX); + ep->msix_cap = dw_pcie_find_capability(pci, PCI_CAP_ID_MSIX); offset = dw_pcie_ep_find_ext_capability(pci, PCI_EXT_CAP_ID_REBAR); if (offset) { diff --git a/drivers/pci/controller/dwc/pcie-designware.c b/drivers/pci/controller/dwc/pcie-designware.c index 7d25102c304c..7818b4febb08 100644 --- a/drivers/pci/controller/dwc/pcie-designware.c +++ b/drivers/pci/controller/dwc/pcie-designware.c @@ -14,6 +14,45 @@ #include "pcie-designware.h" +/* + * These interfaces resemble the pci_find_*capability() interfaces, but these + * are for configuring host controllers, which are bridges *to* PCI devices but + * are not PCI devices themselves. + */ +static u8 __dw_pcie_find_next_cap(struct dw_pcie *pci, u8 cap_ptr, + u8 cap) +{ + u8 cap_id, next_cap_ptr; + u16 reg; + + if (!cap_ptr) + return 0; + + reg = dw_pcie_readw_dbi(pci, cap_ptr); + cap_id = (reg & 0x00ff); + + if (cap_id > PCI_CAP_ID_MAX) + return 0; + + if (cap_id == cap) + return cap_ptr; + + next_cap_ptr = (reg & 0xff00) >> 8; + return __dw_pcie_find_next_cap(pci, next_cap_ptr, cap); +} + +u8 dw_pcie_find_capability(struct dw_pcie *pci, u8 cap) +{ + u8 next_cap_ptr; + u16 reg; + + reg = dw_pcie_readw_dbi(pci, PCI_CAPABILITY_LIST); + next_cap_ptr = (reg & 0x00ff); + + return __dw_pcie_find_next_cap(pci, next_cap_ptr, cap); +} +EXPORT_SYMBOL_GPL(dw_pcie_find_capability); + int dw_pcie_read(void __iomem *addr, int size, u32 *val) { if (!IS_ALIGNED((uintptr_t)addr, size)) { diff --git a/drivers/pci/controller/dwc/pcie-designware.h b/drivers/pci/controller/dwc/pcie-designware.h index ffed084a0b4f..d8c66a6827dc 100644 --- a/drivers/pci/controller/dwc/pcie-designware.h +++ b/drivers/pci/controller/dwc/pcie-designware.h @@ -251,6 +251,8 @@ struct dw_pcie { #define to_dw_pcie_from_ep(endpoint) \ container_of((endpoint), struct dw_pcie, ep) +u8 dw_pcie_find_capability(struct dw_pcie *pci, u8 cap); + int dw_pcie_read(void __iomem *addr, int size, u32 *val); int dw_pcie_write(void __iomem *addr, int size, u32 val); -- 2.17.1