From nobody Tue Apr 7 16:32:56 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 304B4ECAAA6 for ; Fri, 26 Aug 2022 18:20:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344974AbiHZSUg (ORCPT ); Fri, 26 Aug 2022 14:20:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57168 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345026AbiHZSUN (ORCPT ); Fri, 26 Aug 2022 14:20:13 -0400 Received: from mail-pl1-x633.google.com (mail-pl1-x633.google.com [IPv6:2607:f8b0:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 149746B16E for ; Fri, 26 Aug 2022 11:20:07 -0700 (PDT) Received: by mail-pl1-x633.google.com with SMTP id y1so390842plb.2 for ; Fri, 26 Aug 2022 11:20:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=raWHLS6gJR669YXmkR8TC0V9o68cfdUpfACEFenHvcM=; b=JrqGTPs+vSMg7n6WgErUOw1WUM5yEgdqyFHt15gy7+XCg3z6gpa3q+O80ZhyBBgrF8 p0/lSOe+zsor0vYA5twNS3krJAwOaNKrxusNdZ2Dv1whZSDcgTeUrGz+i1giQowOJs4M xpdpqKAW2JURhIxXcZqChUeThrPImDKb1qb81RVBaMxl7swMvAp3Q0KGEBR04RBQxQUB ZrfbrHRWVn05qZep6CX5bid0c+idexDCFhAhvvn1SMql/a0NwI0H3SlBCveIchTvYCCf dUipwa0nNNcxBsPFhRVRIOYiL2oriSUSxbxuPkJwBYffSjaYIcUugTDqhKtenHBbCZTl qg4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=raWHLS6gJR669YXmkR8TC0V9o68cfdUpfACEFenHvcM=; b=eKaWBg8paYi/GVWZt1f46D0SgfChXjXtGP6p+1RUUSckgn2kH5gOGhpNyzmFHGD6MZ qHYkW2vUms+f6xe4RySE/FQAKr0P6hfS8IKMOcogpftW7mEo0rxeR2KkxYTV2VyEa9XF UUqh7BAF225v2C2Qh5/aXb8vQ4ciR5Mrt3cu0dM9XflWwOvdIShyCmWr+HA0cMKWa9sm Ghc88WNQD58pC7FXkckig0UBmEAPsrt0/vYA5vr6uKDu/H6DNpXX32ACtYFA29FIzdS2 /ujbW+lw9NeCDHzFGbp2daPW8Z2LP+ITE/Em32rvWZBG7TWVR8HcJhToL1CIWOPM4Td9 9dmg== X-Gm-Message-State: ACgBeo1wmmiAYPMnQmF3rl8URtOROy5umxpdFmRMDT1zzU211AYwDtYx KHI3dppV6IMN5k93xjdK6MH6 X-Google-Smtp-Source: AA6agR5+XMOm1CY+Y+9/gAbDkyJNvVCVUYRuyL8PZtt/fW45j6L9kvyl9xQ1rNUkMTwONYT6zr0TDA== X-Received: by 2002:a17:90a:150f:b0:1fb:aee:cd2a with SMTP id l15-20020a17090a150f00b001fb0aeecd2amr5693261pja.47.1661538006334; Fri, 26 Aug 2022 11:20:06 -0700 (PDT) Received: from localhost.localdomain ([117.193.214.147]) by smtp.gmail.com with ESMTPSA id s5-20020a170902b18500b00173368e9dedsm1881868plr.252.2022.08.26.11.20.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Aug 2022 11:20:06 -0700 (PDT) From: Manivannan Sadhasivam To: lpieralisi@kernel.org, robh@kernel.org, andersson@kernel.org Cc: kw@linux.com, bhelgaas@google.com, linux-pci@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, konrad.dybcio@somainline.org, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, devicetree@vger.kernel.org, dmitry.baryshkov@linaro.org, Manivannan Sadhasivam Subject: [PATCH 06/11] PCI: qcom-ep: Add debugfs support for expose link transition counts Date: Fri, 26 Aug 2022 23:49:18 +0530 Message-Id: <20220826181923.251564-7-manivannan.sadhasivam@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220826181923.251564-1-manivannan.sadhasivam@linaro.org> References: <20220826181923.251564-1-manivannan.sadhasivam@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Qualcomm PCIe controllers have the debug registers in the MMIO region that counts the PCIe link transitions. Let's expose them over debugfs to userspace to help debugging the low power issues. Signed-off-by: Manivannan Sadhasivam --- drivers/pci/controller/dwc/pcie-qcom-ep.c | 60 +++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/drivers/pci/controller/dwc/pcie-qcom-ep.c b/drivers/pci/contro= ller/dwc/pcie-qcom-ep.c index 98ef36e3a94d..54ac2fef8b88 100644 --- a/drivers/pci/controller/dwc/pcie-qcom-ep.c +++ b/drivers/pci/controller/dwc/pcie-qcom-ep.c @@ -10,6 +10,7 @@ */ =20 #include +#include #include #include #include @@ -45,6 +46,11 @@ #define PARF_ATU_BASE_ADDR 0x634 #define PARF_ATU_BASE_ADDR_HI 0x638 #define PARF_SRIS_MODE 0x644 +#define PARF_DEBUG_CNT_PM_LINKST_IN_L2 0xc04 +#define PARF_DEBUG_CNT_PM_LINKST_IN_L1 0xc0c +#define PARF_DEBUG_CNT_PM_LINKST_IN_L0S 0xc10 +#define PARF_DEBUG_CNT_AUX_CLK_IN_L1SUB_L1 0xc84 +#define PARF_DEBUG_CNT_AUX_CLK_IN_L1SUB_L2 0xc88 #define PARF_DEVICE_TYPE 0x1000 #define PARF_BDF_TO_SID_CFG 0x2c00 =20 @@ -136,12 +142,14 @@ enum qcom_pcie_ep_link_status { * @pci: Designware PCIe controller struct * @parf: Qualcomm PCIe specific PARF register base * @elbi: Designware PCIe specific ELBI register base + * @mmio: MMIO register base * @perst_map: PERST regmap * @mmio_res: MMIO region resource * @core_reset: PCIe Endpoint core reset * @reset: PERST# GPIO * @wake: WAKE# GPIO * @phy: PHY controller block + * @debugfs: PCIe Endpoint Debugfs directory * @clks: PCIe clocks * @num_clks: PCIe clocks count * @perst_en: Flag for PERST enable @@ -155,6 +163,7 @@ struct qcom_pcie_ep { =20 void __iomem *parf; void __iomem *elbi; + void __iomem *mmio; struct regmap *perst_map; struct resource *mmio_res; =20 @@ -162,6 +171,7 @@ struct qcom_pcie_ep { struct gpio_desc *reset; struct gpio_desc *wake; struct phy *phy; + struct dentry *debugfs; =20 struct clk_bulk_data *clks; int num_clks; @@ -447,6 +457,9 @@ static int qcom_pcie_ep_get_io_resources(struct platfor= m_device *pdev, =20 pcie_ep->mmio_res =3D platform_get_resource_byname(pdev, IORESOURCE_MEM, "mmio"); + pcie_ep->mmio =3D devm_pci_remap_cfg_resource(dev, pcie_ep->mmio_res); + if (IS_ERR(pcie_ep->mmio)) + return PTR_ERR(pcie_ep->mmio); =20 syscon =3D of_parse_phandle(dev->of_node, "qcom,perst-regs", 0); if (!syscon) { @@ -630,6 +643,37 @@ static int qcom_pcie_ep_raise_irq(struct dw_pcie_ep *e= p, u8 func_no, } } =20 +static int qcom_pcie_ep_link_transition_count(struct seq_file *s, void *da= ta) +{ + struct qcom_pcie_ep *pcie_ep =3D (struct qcom_pcie_ep *) + dev_get_drvdata(s->private); + + seq_printf(s, "L0s transition count: %u\n", + readl_relaxed(pcie_ep->mmio + PARF_DEBUG_CNT_PM_LINKST_IN_L0S)); + + seq_printf(s, "L1 transition count: %u\n", + readl_relaxed(pcie_ep->mmio + PARF_DEBUG_CNT_PM_LINKST_IN_L1)); + + seq_printf(s, "L1.1 transition count: %u\n", + readl_relaxed(pcie_ep->mmio + PARF_DEBUG_CNT_AUX_CLK_IN_L1SUB_L1)); + + seq_printf(s, "L1.2 transition count: %u\n", + readl_relaxed(pcie_ep->mmio + PARF_DEBUG_CNT_AUX_CLK_IN_L1SUB_L2)); + + seq_printf(s, "L2 transition count: %u\n", + readl_relaxed(pcie_ep->mmio + PARF_DEBUG_CNT_PM_LINKST_IN_L2)); + + return 0; +} + +static void qcom_pcie_ep_init_debugfs(struct qcom_pcie_ep *pcie_ep) +{ + struct dw_pcie *pci =3D &pcie_ep->pci; + + debugfs_create_devm_seqfile(pci->dev, "link_transition_count", pcie_ep->d= ebugfs, + qcom_pcie_ep_link_transition_count); +} + static const struct pci_epc_features qcom_pcie_epc_features =3D { .linkup_notifier =3D true, .core_init_notifier =3D true, @@ -662,6 +706,7 @@ static int qcom_pcie_ep_probe(struct platform_device *p= dev) { struct device *dev =3D &pdev->dev; struct qcom_pcie_ep *pcie_ep; + char *name; int ret; =20 pcie_ep =3D devm_kzalloc(dev, sizeof(*pcie_ep), GFP_KERNEL); @@ -688,8 +733,21 @@ static int qcom_pcie_ep_probe(struct platform_device *= pdev) if (ret) goto err_disable_resources; =20 + name =3D devm_kasprintf(dev, GFP_KERNEL, "%pOFP", dev->of_node); + if (!name) { + ret =3D -ENOMEM; + goto err_disable_irqs; + } + + pcie_ep->debugfs =3D debugfs_create_dir(name, NULL); + qcom_pcie_ep_init_debugfs(pcie_ep); + return 0; =20 +err_disable_irqs: + disable_irq(pcie_ep->global_irq); + disable_irq(pcie_ep->perst_irq); + err_disable_resources: qcom_pcie_disable_resources(pcie_ep); =20 @@ -703,6 +761,8 @@ static int qcom_pcie_ep_remove(struct platform_device *= pdev) disable_irq(pcie_ep->global_irq); disable_irq(pcie_ep->perst_irq); =20 + debugfs_remove_recursive(pcie_ep->debugfs); + if (pcie_ep->link_status =3D=3D QCOM_PCIE_EP_LINK_DISABLED) return 0; =20 --=20 2.25.1