[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20230516160304.00000544@Huawei.com>
Date: Tue, 16 May 2023 16:03:04 +0100
From: Jonathan Cameron <Jonathan.Cameron@...wei.com>
To: Shuai Xue <xueshuai@...ux.alibaba.com>
CC: Robin Murphy <robin.murphy@....com>, <helgaas@...nel.org>,
<yangyicong@...wei.com>, <will@...nel.org>,
<baolin.wang@...ux.alibaba.com>,
<linux-arm-kernel@...ts.infradead.org>,
<linux-kernel@...r.kernel.org>, <linux-pci@...r.kernel.org>,
<rdunlap@...radead.org>, <mark.rutland@....com>,
<zhuo.song@...ux.alibaba.com>, <linux-cxl@...r.kernel.org>
Subject: Re: [PATCH v3 2/3] drivers/perf: add DesignWare PCIe PMU driver
PCI folks, Question below directed at you. Please take a look.
+CC linux-cxl because a similar question is going to bite us shortly
if we want CXL PMUs to work well on RP or Switch ports.
> >> +static int dwc_pcie_ras_des_discover(struct dwc_pcie_pmu_priv *priv)
> >> +{
> >> + int index = 0;
> >> + struct pci_dev *pdev = NULL;
> >> + struct dwc_pcie_rp_info *rp_info;
> >> +
> >> + INIT_LIST_HEAD(&priv->rp_infos);
> >> +
> >> + /* Match the rootport with VSEC_RAS_DES_ID */
> >> + for_each_pci_dev(pdev) {
> >
> > Does the PCI layer not offer a more robust mechanism for this? (PCI fixups come to mind, but I don't actually know whether that would be a viable approach or not.)
>
> I am afraid not yet. Jonathan try to add a PMU service but it is not merged into mainline.
I wouldn't read much into that 'failure'. We never persisted with that driver because it was for an old
generation of hardware. Mostly the aim with that was to explore the area of PCIe PMU in general
rather than to get the support upstream. Some of the counters on that hardware were too small to
be of much use anyway :)
Grabbing just relevant functions..
Bjorn, we need to figure out a way forwards for this sort of case and I'd
appreciate your input on the broad brush question of 'how should it be done'?
This is a case where a PCIe port (RP here) correctly has the PCIe class code
so binds to the pcie_port driver, but has a VSEC (others examples use DOE, or DVSEC)
that provides extended functionality. The referred to PCIe PMU from our older Hisilicon
platforms did it by adding another service driver - that probably doesn't extend well.
The approach used here is to separately walk the PCI topology and register the devices.
It can 'maybe' get away with that because no interrupts and I assume resets have no
nasty impacts on it because the device is fairly simple. In general that's not going
to work. CXL does a similar trick (which I don't much like, but too late now),
but we've also run into the problem of how to get interrupts if not the main driver.
So what approach should we look at to solve this in general?
Jonathan
> +static int dwc_pcie_ras_des_discover(struct dwc_pcie_pmu_priv *priv)
> +{
> + int index = 0;
> + struct pci_dev *pdev = NULL;
> + struct dwc_pcie_rp_info *rp_info;
> +
> + INIT_LIST_HEAD(&priv->rp_infos);
> +
> + /* Match the rootport with VSEC_RAS_DES_ID */
> + for_each_pci_dev(pdev) {
> + u16 vsec;
> + u32 val;
> +
> + if (!pci_dev_is_rootport(pdev))
> + continue;
> +
> + rp_info = devm_kzalloc(&pdev->dev, sizeof(*rp_info), GFP_KERNEL);
> + if (!rp_info)
> + return -ENOMEM;
> +
> + rp_info->bdf = PCI_DEVID(pdev->bus->number, pdev->devfn);
> + rp_info->pdev = pdev;
> +
> + vsec = pci_find_vsec_capability(pdev, PCI_VENDOR_ID_ALIBABA,
> + DWC_PCIE_VSEC_RAS_DES_ID);
> + if (!vsec)
> + continue;
> +
> + pci_read_config_dword(pdev, vsec + PCI_VNDR_HEADER, &val);
> + if (PCI_VNDR_HEADER_REV(val) != 0x04 ||
> + PCI_VNDR_HEADER_LEN(val) != 0x100)
> + continue;
> + pci_dbg(pdev,
> + "Detected PCIe Vendor-Specific Extended Capability RAS DES\n");
> +
> + rp_info->ras_des = vsec;
> + rp_info->num_lanes = pcie_get_width_cap(pdev);
> +
> + list_add(&rp_info->rp_node, &priv->rp_infos);
> + index++;
> + }
> +
> + if (!index)
> + return -ENODEV;
> +
> + priv->pcie_ctrl_num = index;
> +
> + return 0;
> +}
> +static int dwc_pcie_pmu_probe(struct platform_device *pdev)
> +{
> + int ret;
> + struct dwc_pcie_pmu_priv *priv;
> + struct dwc_pcie_rp_info *rp_info;
> +
> + priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
> + if (!priv)
> + return -ENOMEM;
> +
> + priv->dev = &pdev->dev;
> + platform_set_drvdata(pdev, priv);
> +
> + /* If RAS_DES PMU is not supported on current platform, keep silent */
> + ret = dwc_pcie_ras_des_discover(priv);
> + if (ret)
> + return ret;
> +
> + list_for_each_entry(rp_info, &priv->rp_infos, rp_node) {
> + struct pci_dev *rp = rp_info->pdev;
> +
> + ret = __dwc_pcie_pmu_probe(priv, rp_info);
> + if (ret) {
> + dev_err(&rp->dev, "PCIe PMU probe fail\n");
> + goto pmu_unregister;
> + }
> + }
> +
> + return 0;
> +
> +pmu_unregister:
> + dwc_pcie_pmu_remove(pdev);
> +
> + return ret;
> +}
Powered by blists - more mailing lists