From: Dan Williams <dan.j.williams@intel.com>
To: "Daisuke Kobayashi (Fujitsu)" <kobayashi.da-06@fujitsu.com>,
"'Bjorn Helgaas'" <helgaas@kernel.org>
Cc: "linux-cxl@vger.kernel.org" <linux-cxl@vger.kernel.org>,
"Yasunori Gotou (Fujitsu)" <y-goto@fujitsu.com>,
"linux-pci@vger.kernel.org" <linux-pci@vger.kernel.org>,
"mj@ucw.cz" <mj@ucw.cz>,
"dan.j.williams@intel.com" <dan.j.williams@intel.com>
Subject: RE: [RFC PATCH v2 1/3] Add sysfs attribute for CXL 1.1 device link status
Date: Fri, 1 Mar 2024 18:22:15 -0800 [thread overview]
Message-ID: <65e28d5793f3d_1138c729471@dwillia2-xfh.jf.intel.com.notmuch> (raw)
In-Reply-To: <OSAPR01MB718293579603A52D4D0F9CF4BA582@OSAPR01MB7182.jpnprd01.prod.outlook.com>
Daisuke Kobayashi (Fujitsu) wrote:
>
>
> > -----Original Message-----
> > From: Bjorn Helgaas <helgaas@kernel.org>
> > Sent: Wednesday, February 28, 2024 1:44 AM
> > To: Kobayashi, Daisuke/小林 大介 <kobayashi.da-06@fujitsu.com>
> > Cc: Kobayashi, Daisuke/小林 大介 <kobayashi.da-06@fujitsu.com>;
> > linux-cxl@vger.kernel.org; Gotou, Yasunori/五島 康文 <y-goto@fujitsu.com>;
> > linux-pci@vger.kernel.org; mj@ucw.cz; dan.j.williams@intel.com
> > Subject: Re: [RFC PATCH v2 1/3] Add sysfs attribute for CXL 1.1 device link
> > status
> >
> > On Tue, Feb 27, 2024 at 05:33:11PM +0900, Kobayashi,Daisuke wrote:
> > > This patch implements a process to output the link status information
> > > of the CXL1.1 device to sysfs. The values of the registers related to
> > > the link status are outputted into three separate files.
> >
> > > +static u32 cxl_rcrb_to_linkcap(struct device *dev, resource_size_t rcrb)
> > > +{
> > > + void __iomem *addr;
> > > + u8 offset = 0;
> >
> > Unnecessary initialization. Also, readw() returns u16.
> >
> > > + u32 cap_hdr;
> > > + u32 linkcap = 0;
> >
> > Ditto.
> >
>
> Thank you, I will fix them.
>
> > > +
> > > + if (WARN_ON_ONCE(rcrb == CXL_RESOURCE_NONE))
> > > + return 0;
> > > +
> > > + if (!request_mem_region(rcrb, SZ_4K, dev_name(dev)))
> > > + return 0;
> > > +
> > > + addr = ioremap(rcrb, SZ_4K);
> > > + if (!addr)
> > > + goto out;
> > > +
> > > + offset = readw(addr + PCI_CAPABILITY_LIST);
> > > + offset = offset & 0x00ff;
> > > + cap_hdr = readl(addr + offset);
> > > + while ((cap_hdr & 0x000000ff) != PCI_CAP_ID_EXP) {
> > > + offset = (cap_hdr >> 8) & 0x000000ff;
> > > + if (!offset)
> > > + break;
> > > + cap_hdr = readl(addr + offset);
> > > + }
> >
> > Hmmm, it's a shame we have to reimplement pci_find_capability() here.
> > I see the problem though -- pci_find_capability() does config reads
> > and this is in MMIO space, not config space.
> >
> > But you need this several times, so maybe a helper function would
> > still be useful so you don't have to repeat the code.
> >
>
> I'll take your suggestion and create a helper function.
There is already a cxl_rcrb_to_aer() in the CXL core, I would recommend
just converting that function to one that take a capability id.
[..]
> > > @@ -806,6 +1003,9 @@ static int cxl_pci_probe(struct pci_dev *pdev, const
> > struct pci_device_id *id)
> > > if (IS_ERR(mds))
> > > return PTR_ERR(mds);
> > > cxlds = &mds->cxlds;
> > > + device_create_file(&pdev->dev, &dev_attr_rcd_link_cap);
> > > + device_create_file(&pdev->dev, &dev_attr_rcd_link_ctrl);
> > > + device_create_file(&pdev->dev, &dev_attr_rcd_link_status);
> >
> > Is there a removal issue here? What if "pdev" is removed? Or what if
> > this module is unloaded? Do these sysfs files get cleaned up
> > automagically somehow?
> >
> > Bjorn
>
> Thank you, I overlooked my consideration of the removal issue.
> I will check current code and add a cleanup process.
>
No, the proper way to register sysfs attributes already includes cleanup
tied to the device lifetime. Since these can only show up once the driver
is loaded they are so-called driver "dev_groups" attributes. The way to
declare them is something like this (UNTESTED!):
diff --git a/drivers/cxl/pci.c b/drivers/cxl/pci.c
index 2ff361e756d6..c8535078c74f 100644
--- a/drivers/cxl/pci.c
+++ b/drivers/cxl/pci.c
@@ -964,6 +964,30 @@ static const struct pci_error_handlers cxl_error_handlers = {
.cor_error_detected = cxl_cor_error_detected,
};
+static umode_t cxl_rcd_visible(struct kobject *kobj, struct attribute *a, int n)
+{
+ struct device *dev = kobj_to_dev(kobj);
+ struct pci_dev *pdev = to_pci_dev(dev);
+
+ if (!is_cxl_restricted(pdev))
+ return 0;
+ return a->mode;
+}
+
+static struct attribute *cxl_rcd_attrs[] = {
+ &dev_attr_rcd_link_cap,
+ &dev_attr_rcd_link_ctrl,
+ &dev_attr_rcd_link_status,
+ NULL,
+};
+
+static struct attribute_group cxl_rcd_group = {
+ .attrs = cxl_rcd_attrs,
+ .is_visible = cxl_rcd_visible,
+};
+
+__ATTRIBUTE_GROUPS(cxl_rcd);
+
static struct pci_driver cxl_pci_driver = {
.name = KBUILD_MODNAME,
.id_table = cxl_mem_pci_tbl,
@@ -971,6 +995,7 @@ static struct pci_driver cxl_pci_driver = {
.err_handler = &cxl_error_handlers,
.driver = {
.probe_type = PROBE_PREFER_ASYNCHRONOUS,
+ .dev_groups = &cxl_rcd_groups,
},
};
next prev parent reply other threads:[~2024-03-02 2:22 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-27 8:33 [RFC PATCH v2 0/3] Display cxl1.1 device link status Kobayashi,Daisuke
2024-02-27 8:33 ` [RFC PATCH v2 1/3] Add sysfs attribute for CXL 1.1 " Kobayashi,Daisuke
2024-02-27 16:43 ` Bjorn Helgaas
2024-02-28 8:28 ` Daisuke Kobayashi (Fujitsu)
2024-03-02 2:22 ` Dan Williams [this message]
2024-02-27 8:33 ` [RFC PATCH v2 2/3] Remove conditional branch that is not suitable for cxl1.1 devices Kobayashi,Daisuke
2024-02-27 8:33 ` [RFC PATCH v2 3/3] lspci: Add function to display cxl1.1 device link status Kobayashi,Daisuke
2024-02-28 8:34 ` Martin Mareš
2024-03-01 7:02 ` Daisuke Kobayashi (Fujitsu)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=65e28d5793f3d_1138c729471@dwillia2-xfh.jf.intel.com.notmuch \
--to=dan.j.williams@intel.com \
--cc=helgaas@kernel.org \
--cc=kobayashi.da-06@fujitsu.com \
--cc=linux-cxl@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=mj@ucw.cz \
--cc=y-goto@fujitsu.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox