* [PATCH v7 1/3] PCI/DOE: Rename DOE protocol to feature
@ 2023-09-04 5:43 Alistair Francis
2023-09-04 5:43 ` [PATCH v7 2/3] PCI/DOE: Expose the DOE features via sysfs Alistair Francis
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Alistair Francis @ 2023-09-04 5:43 UTC (permalink / raw)
To: bhelgaas, linux-pci, Jonathan.Cameron, lukas
Cc: alex.williamson, christian.koenig, kch, gregkh, logang,
linux-kernel, alistair23, chaitanyak, rdunlap, Alistair Francis
DOE r1.1 replaced all occurrences of "protocol" with the term "feature"
or "Data Object Type".
PCIe r6.1 (which was published July 24) incorporated that change.
This patch renames the existing terms protocol with feature.
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
---
v7:
- Initial patch
drivers/pci/doe.c | 40 ++++++++++++++++++++--------------------
1 file changed, 20 insertions(+), 20 deletions(-)
diff --git a/drivers/pci/doe.c b/drivers/pci/doe.c
index e3aab5edaf70..047be8c9d191 100644
--- a/drivers/pci/doe.c
+++ b/drivers/pci/doe.c
@@ -43,7 +43,7 @@
*
* @pdev: PCI device this mailbox belongs to
* @cap_offset: Capability offset
- * @prots: Array of protocols supported (encoded as long values)
+ * @prots: Array of features supported (encoded as long values)
* @wq: Wait queue for work item
* @work_queue: Queue of pci_doe_work items
* @flags: Bit array of PCI_DOE_FLAG_* flags
@@ -58,7 +58,7 @@ struct pci_doe_mb {
unsigned long flags;
};
-struct pci_doe_protocol {
+struct pci_doe_feature {
u16 vid;
u8 type;
};
@@ -66,7 +66,7 @@ struct pci_doe_protocol {
/**
* struct pci_doe_task - represents a single query/response
*
- * @prot: DOE Protocol
+ * @prot: DOE Feature
* @request_pl: The request payload
* @request_pl_sz: Size of the request payload (bytes)
* @response_pl: The response payload
@@ -78,7 +78,7 @@ struct pci_doe_protocol {
* @doe_mb: Used internally by the mailbox
*/
struct pci_doe_task {
- struct pci_doe_protocol prot;
+ struct pci_doe_feature prot;
const __le32 *request_pl;
size_t request_pl_sz;
__le32 *response_pl;
@@ -217,11 +217,11 @@ static int pci_doe_recv_resp(struct pci_doe_mb *doe_mb, struct pci_doe_task *tas
int i = 0;
u32 val;
- /* Read the first dword to get the protocol */
+ /* Read the first dword to get the feature */
pci_read_config_dword(pdev, offset + PCI_DOE_READ, &val);
if ((FIELD_GET(PCI_DOE_DATA_OBJECT_HEADER_1_VID, val) != task->prot.vid) ||
(FIELD_GET(PCI_DOE_DATA_OBJECT_HEADER_1_TYPE, val) != task->prot.type)) {
- dev_err_ratelimited(&pdev->dev, "[%x] expected [VID, Protocol] = [%04x, %02x], got [%04x, %02x]\n",
+ dev_err_ratelimited(&pdev->dev, "[%x] expected [VID, Feature] = [%04x, %02x], got [%04x, %02x]\n",
doe_mb->cap_offset, task->prot.vid, task->prot.type,
FIELD_GET(PCI_DOE_DATA_OBJECT_HEADER_1_VID, val),
FIELD_GET(PCI_DOE_DATA_OBJECT_HEADER_1_TYPE, val));
@@ -384,7 +384,7 @@ static void pci_doe_task_complete(struct pci_doe_task *task)
}
static int pci_doe_discovery(struct pci_doe_mb *doe_mb, u8 *index, u16 *vid,
- u8 *protocol)
+ u8 *feature)
{
u32 request_pl = FIELD_PREP(PCI_DOE_DATA_OBJECT_DISC_REQ_3_INDEX,
*index);
@@ -404,7 +404,7 @@ static int pci_doe_discovery(struct pci_doe_mb *doe_mb, u8 *index, u16 *vid,
response_pl = le32_to_cpu(response_pl_le);
*vid = FIELD_GET(PCI_DOE_DATA_OBJECT_DISC_RSP_3_VID, response_pl);
- *protocol = FIELD_GET(PCI_DOE_DATA_OBJECT_DISC_RSP_3_PROTOCOL,
+ *feature = FIELD_GET(PCI_DOE_DATA_OBJECT_DISC_RSP_3_PROTOCOL,
response_pl);
*index = FIELD_GET(PCI_DOE_DATA_OBJECT_DISC_RSP_3_NEXT_INDEX,
response_pl);
@@ -417,7 +417,7 @@ static void *pci_doe_xa_prot_entry(u16 vid, u8 prot)
return xa_mk_value((vid << 8) | prot);
}
-static int pci_doe_cache_protocols(struct pci_doe_mb *doe_mb)
+static int pci_doe_cache_features(struct pci_doe_mb *doe_mb)
{
u8 index = 0;
u8 xa_idx = 0;
@@ -432,7 +432,7 @@ static int pci_doe_cache_protocols(struct pci_doe_mb *doe_mb)
return rc;
pci_dbg(doe_mb->pdev,
- "[%x] Found protocol %d vid: %x prot: %x\n",
+ "[%x] Found feature %d vid: %x prot: %x\n",
doe_mb->cap_offset, xa_idx, vid, prot);
rc = xa_insert(&doe_mb->prots, xa_idx++,
@@ -460,7 +460,7 @@ static void pci_doe_cancel_tasks(struct pci_doe_mb *doe_mb)
* @pdev: PCI device to create the DOE mailbox for
* @cap_offset: Offset of the DOE mailbox
*
- * Create a single mailbox object to manage the mailbox protocol at the
+ * Create a single mailbox object to manage the mailbox feature at the
* cap_offset specified.
*
* RETURNS: created mailbox object on success
@@ -502,11 +502,11 @@ static struct pci_doe_mb *pci_doe_create_mb(struct pci_dev *pdev,
/*
* The state machine and the mailbox should be in sync now;
- * Use the mailbox to query protocols.
+ * Use the mailbox to query features.
*/
- rc = pci_doe_cache_protocols(doe_mb);
+ rc = pci_doe_cache_features(doe_mb);
if (rc) {
- pci_err(pdev, "[%x] failed to cache protocols : %d\n",
+ pci_err(pdev, "[%x] failed to cache features : %d\n",
doe_mb->cap_offset, rc);
goto err_cancel;
}
@@ -540,19 +540,19 @@ static void pci_doe_destroy_mb(struct pci_doe_mb *doe_mb)
/**
* pci_doe_supports_prot() - Return if the DOE instance supports the given
- * protocol
+ * feature
* @doe_mb: DOE mailbox capability to query
- * @vid: Protocol Vendor ID
- * @type: Protocol type
+ * @vid: Feature Vendor ID
+ * @type: Feature type
*
- * RETURNS: True if the DOE mailbox supports the protocol specified
+ * RETURNS: True if the DOE mailbox supports the feature specified
*/
static bool pci_doe_supports_prot(struct pci_doe_mb *doe_mb, u16 vid, u8 type)
{
unsigned long index;
void *entry;
- /* The discovery protocol must always be supported */
+ /* The discovery feature must always be supported */
if (vid == PCI_VENDOR_ID_PCI_SIG && type == PCI_DOE_PROTOCOL_DISCOVERY)
return true;
@@ -659,7 +659,7 @@ EXPORT_SYMBOL_GPL(pci_doe);
* @vendor: Vendor ID
* @type: Data Object Type
*
- * Find first DOE mailbox of a PCI device which supports the given protocol.
+ * Find first DOE mailbox of a PCI device which supports the given feature.
*
* RETURNS: Pointer to the DOE mailbox or NULL if none was found.
*/
--
2.41.0
^ permalink raw reply related [flat|nested] 6+ messages in thread* [PATCH v7 2/3] PCI/DOE: Expose the DOE features via sysfs
2023-09-04 5:43 [PATCH v7 1/3] PCI/DOE: Rename DOE protocol to feature Alistair Francis
@ 2023-09-04 5:43 ` Alistair Francis
2023-09-04 15:17 ` Jonathan Cameron
2023-09-04 5:43 ` [PATCH v7 3/3] PCI/DOE: Allow enabling DOE without CXL Alistair Francis
2023-09-04 15:10 ` [PATCH v7 1/3] PCI/DOE: Rename DOE protocol to feature Jonathan Cameron
2 siblings, 1 reply; 6+ messages in thread
From: Alistair Francis @ 2023-09-04 5:43 UTC (permalink / raw)
To: bhelgaas, linux-pci, Jonathan.Cameron, lukas
Cc: alex.williamson, christian.koenig, kch, gregkh, logang,
linux-kernel, alistair23, chaitanyak, rdunlap, Alistair Francis
The PCIe 6 specification added support for the Data Object Exchange (DOE).
When DOE is supported the Discovery Data Object Protocol must be
implemented. The protocol allows a requester to obtain information about
the other DOE features supported by the device.
The kernel is already querying the DOE features supported and cacheing
the values. This patch exposes the values via sysfs. This will allow
userspace to determine which DOE features are supported by the PCIe
device.
By exposing the information to userspace tools like lspci can relay the
information to users. By listing all of the supported features we can
allow userspace to parse and support the list, which might include
vendor specific features as well as yet to be supported features.
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
---
v7:
- Fixup the #ifdefs to keep the test robot happy
v6:
- Use "feature" instead of protocol
- Don't use any devm_* functions
- Add two more patches to the series
v5:
- Return the file name as the file contents
- Code cleanups and simplifications
v4:
- Fixup typos in the documentation
- Make it clear that the file names contain the information
- Small code cleanups
- Remove most #ifdefs
- Remove extra NULL assignment
v3:
- Expose each DOE feature as a separate file
v2:
- Add documentation
- Code cleanups
This patch will create a doe_features directory for all
PCIe devies. This should be fixed by a pending sysfs fixup
patch.
Documentation/ABI/testing/sysfs-bus-pci | 12 +++
drivers/pci/doe.c | 111 ++++++++++++++++++++++++
drivers/pci/pci-sysfs.c | 10 +++
drivers/pci/pci.h | 3 +
include/linux/pci-doe.h | 1 +
5 files changed, 137 insertions(+)
diff --git a/Documentation/ABI/testing/sysfs-bus-pci b/Documentation/ABI/testing/sysfs-bus-pci
index ecf47559f495..e999e78cc2d5 100644
--- a/Documentation/ABI/testing/sysfs-bus-pci
+++ b/Documentation/ABI/testing/sysfs-bus-pci
@@ -500,3 +500,15 @@ Description:
console drivers from the device. Raw users of pci-sysfs
resourceN attributes must be terminated prior to resizing.
Success of the resizing operation is not guaranteed.
+
+What: /sys/bus/pci/devices/.../doe_features
+Date: August 2023
+Contact: Linux PCI developers <linux-pci@vger.kernel.org>
+Description:
+ This directory contains a list of the supported
+ Data Object Exchange (DOE) features. The feature values are in
+ the file name. The contents of each file are the same as the
+ name.
+ The value comes from the device and specifies the vendor and
+ data object type supported. The lower byte is the data object
+ type and the next two bytes are the vendor ID.
diff --git a/drivers/pci/doe.c b/drivers/pci/doe.c
index 047be8c9d191..69cd391dd120 100644
--- a/drivers/pci/doe.c
+++ b/drivers/pci/doe.c
@@ -47,6 +47,7 @@
* @wq: Wait queue for work item
* @work_queue: Queue of pci_doe_work items
* @flags: Bit array of PCI_DOE_FLAG_* flags
+ * @sysfs_attrs: Array of sysfs device attributes
*/
struct pci_doe_mb {
struct pci_dev *pdev;
@@ -56,6 +57,10 @@ struct pci_doe_mb {
wait_queue_head_t wq;
struct workqueue_struct *work_queue;
unsigned long flags;
+
+#ifdef CONFIG_SYSFS
+ struct device_attribute *sysfs_attrs;
+#endif
};
struct pci_doe_feature {
@@ -92,6 +97,112 @@ struct pci_doe_task {
struct pci_doe_mb *doe_mb;
};
+#ifdef CONFIG_SYSFS
+static umode_t pci_doe_sysfs_attr_is_visible(struct kobject *kobj,
+ struct attribute *a, int n)
+{
+ struct pci_dev *pdev = to_pci_dev(kobj_to_dev(kobj));
+ struct pci_doe_mb *doe_mb;
+ unsigned long index, j;
+ void *entry;
+
+ xa_for_each(&pdev->doe_mbs, index, doe_mb) {
+ xa_for_each(&doe_mb->prots, j, entry)
+ return a->mode;
+ }
+
+ return 0;
+}
+
+static struct attribute *pci_dev_doe_feature_attrs[] = {
+ NULL,
+};
+
+const struct attribute_group pci_dev_doe_feature_group = {
+ .name = "doe_features",
+ .attrs = pci_dev_doe_feature_attrs,
+ .is_visible = pci_doe_sysfs_attr_is_visible,
+};
+
+static ssize_t pci_doe_sysfs_feature_show(struct device *dev,
+ struct device_attribute *attr,
+ char *buf)
+{
+ return sysfs_emit(buf, "%s\n", attr->attr.name);
+}
+
+static int pci_doe_sysfs_feature_supports(struct pci_dev *pdev,
+ struct pci_doe_mb *doe_mb)
+{
+ struct device *dev = &pdev->dev;
+ struct device_attribute *attrs;
+ unsigned long num_features = 0;
+ unsigned long vid, type;
+ unsigned long i;
+ void *entry;
+ int ret;
+
+ xa_for_each(&doe_mb->prots, i, entry)
+ num_features++;
+
+ attrs = kcalloc(num_features, sizeof(*attrs), GFP_KERNEL);
+ if (!attrs)
+ return -ENOMEM;
+
+ doe_mb->sysfs_attrs = attrs;
+ xa_for_each(&doe_mb->prots, i, entry) {
+ sysfs_attr_init(&attrs[i].attr);
+ vid = xa_to_value(entry) >> 8;
+ type = xa_to_value(entry) & 0xFF;
+ attrs[i].attr.name = kasprintf(GFP_KERNEL,
+ "0x%04lX:%02lX", vid, type);
+ if (!attrs[i].attr.name) {
+ ret = -ENOMEM;
+ goto fail;
+ }
+
+ attrs[i].attr.mode = 0444;
+ attrs[i].show = pci_doe_sysfs_feature_show;
+
+ ret = sysfs_add_file_to_group(&dev->kobj, &attrs[i].attr,
+ pci_dev_doe_feature_group.name);
+ if (ret)
+ goto fail;
+ }
+
+ return 0;
+
+fail:
+ doe_mb->sysfs_attrs = NULL;
+ xa_for_each(&doe_mb->prots, i, entry) {
+ if (attrs[i].show)
+ sysfs_remove_file_from_group(&dev->kobj, &attrs[i].attr,
+ pci_dev_doe_feature_group.name);
+ kfree(attrs[i].attr.name);
+ }
+
+ kfree(attrs);
+
+ return ret;
+}
+
+int doe_sysfs_init(struct pci_dev *pdev)
+{
+ struct pci_doe_mb *doe_mb;
+ unsigned long index;
+ int ret;
+
+ xa_for_each(&pdev->doe_mbs, index, doe_mb) {
+ ret = pci_doe_sysfs_feature_supports(pdev, doe_mb);
+
+ if (ret)
+ return ret;
+ }
+
+ return 0;
+}
+#endif
+
static int pci_doe_wait(struct pci_doe_mb *doe_mb, unsigned long timeout)
{
if (wait_event_timeout(doe_mb->wq,
diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
index d9eede2dbc0e..01bbd1f1cb9b 100644
--- a/drivers/pci/pci-sysfs.c
+++ b/drivers/pci/pci-sysfs.c
@@ -16,6 +16,7 @@
#include <linux/kernel.h>
#include <linux/sched.h>
#include <linux/pci.h>
+#include <linux/pci-doe.h>
#include <linux/stat.h>
#include <linux/export.h>
#include <linux/topology.h>
@@ -1230,6 +1231,12 @@ static int pci_create_resource_files(struct pci_dev *pdev)
int i;
int retval;
+ if (IS_ENABLED(CONFIG_PCI_DOE)) {
+ retval = doe_sysfs_init(pdev);
+ if (retval)
+ return retval;
+ }
+
/* Expose the PCI resources from this device as files */
for (i = 0; i < PCI_STD_NUM_BARS; i++) {
@@ -1655,6 +1662,9 @@ static const struct attribute_group *pci_dev_attr_groups[] = {
#endif
#ifdef CONFIG_PCIEASPM
&aspm_ctrl_attr_group,
+#endif
+#ifdef CONFIG_PCI_DOE
+ &pci_dev_doe_feature_group,
#endif
NULL,
};
diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
index 39a8932dc340..b85dd83ddfcb 100644
--- a/drivers/pci/pci.h
+++ b/drivers/pci/pci.h
@@ -186,6 +186,9 @@ extern const struct attribute_group *pci_dev_groups[];
extern const struct attribute_group *pcibus_groups[];
extern const struct device_type pci_dev_type;
extern const struct attribute_group *pci_bus_groups[];
+#ifdef CONFIG_SYSFS
+extern const struct attribute_group pci_dev_doe_feature_group;
+#endif
extern unsigned long pci_hotplug_io_size;
extern unsigned long pci_hotplug_mmio_size;
diff --git a/include/linux/pci-doe.h b/include/linux/pci-doe.h
index 1f14aed4354b..4cc13d9ccb50 100644
--- a/include/linux/pci-doe.h
+++ b/include/linux/pci-doe.h
@@ -22,4 +22,5 @@ int pci_doe(struct pci_doe_mb *doe_mb, u16 vendor, u8 type,
const void *request, size_t request_sz,
void *response, size_t response_sz);
+int doe_sysfs_init(struct pci_dev *pci_dev);
#endif
--
2.41.0
^ permalink raw reply related [flat|nested] 6+ messages in thread* Re: [PATCH v7 2/3] PCI/DOE: Expose the DOE features via sysfs
2023-09-04 5:43 ` [PATCH v7 2/3] PCI/DOE: Expose the DOE features via sysfs Alistair Francis
@ 2023-09-04 15:17 ` Jonathan Cameron
0 siblings, 0 replies; 6+ messages in thread
From: Jonathan Cameron @ 2023-09-04 15:17 UTC (permalink / raw)
To: Alistair Francis
Cc: bhelgaas, linux-pci, lukas, alex.williamson, christian.koenig,
kch, gregkh, logang, linux-kernel, chaitanyak, rdunlap,
Alistair Francis
On Mon, 4 Sep 2023 15:43:28 +1000
Alistair Francis <alistair23@gmail.com> wrote:
> The PCIe 6 specification added support for the Data Object Exchange (DOE).
> When DOE is supported the Discovery Data Object Protocol must be
> implemented. The protocol allows a requester to obtain information about
> the other DOE features supported by the device.
>
> The kernel is already querying the DOE features supported and cacheing
> the values. This patch exposes the values via sysfs. This will allow
> userspace to determine which DOE features are supported by the PCIe
> device.
>
> By exposing the information to userspace tools like lspci can relay the
> information to users. By listing all of the supported features we can
> allow userspace to parse and support the list, which might include
> vendor specific features as well as yet to be supported features.
>
> Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
Hi Alistair
A few minor things inline.
Thanks,
Jonathan
> ---
> v7:
> - Fixup the #ifdefs to keep the test robot happy
> v6:
> - Use "feature" instead of protocol
> - Don't use any devm_* functions
> - Add two more patches to the series
> v5:
> - Return the file name as the file contents
> - Code cleanups and simplifications
> v4:
> - Fixup typos in the documentation
> - Make it clear that the file names contain the information
> - Small code cleanups
> - Remove most #ifdefs
> - Remove extra NULL assignment
> v3:
> - Expose each DOE feature as a separate file
> v2:
> - Add documentation
> - Code cleanups
>
> This patch will create a doe_features directory for all
> PCIe devies. This should be fixed by a pending sysfs fixup
> patch.
>
> Documentation/ABI/testing/sysfs-bus-pci | 12 +++
> drivers/pci/doe.c | 111 ++++++++++++++++++++++++
> drivers/pci/pci-sysfs.c | 10 +++
> drivers/pci/pci.h | 3 +
> include/linux/pci-doe.h | 1 +
> 5 files changed, 137 insertions(+)
>
> diff --git a/Documentation/ABI/testing/sysfs-bus-pci b/Documentation/ABI/testing/sysfs-bus-pci
> index ecf47559f495..e999e78cc2d5 100644
> --- a/Documentation/ABI/testing/sysfs-bus-pci
> +++ b/Documentation/ABI/testing/sysfs-bus-pci
> @@ -500,3 +500,15 @@ Description:
> console drivers from the device. Raw users of pci-sysfs
> resourceN attributes must be terminated prior to resizing.
> Success of the resizing operation is not guaranteed.
> +
> +What: /sys/bus/pci/devices/.../doe_features
> +Date: August 2023
> +Contact: Linux PCI developers <linux-pci@vger.kernel.org>
> +Description:
> + This directory contains a list of the supported
> + Data Object Exchange (DOE) features. The feature values are in
> + the file name. The contents of each file are the same as the
> + name.
> + The value comes from the device and specifies the vendor and
> + data object type supported. The lower byte is the data object
> + type and the next two bytes are the vendor ID.
Given we already have a few defined, maybe an example would be useful here
or a statement of the format
> diff --git a/drivers/pci/doe.c b/drivers/pci/doe.c
> index 047be8c9d191..69cd391dd120 100644
> --- a/drivers/pci/doe.c
> +++ b/drivers/pci/doe.c
> @@ -47,6 +47,7 @@
> * @wq: Wait queue for work item
> * @work_queue: Queue of pci_doe_work items
> * @flags: Bit array of PCI_DOE_FLAG_* flags
> + * @sysfs_attrs: Array of sysfs device attributes
> */
> struct pci_doe_mb {
> struct pci_dev *pdev;
> @@ -56,6 +57,10 @@ struct pci_doe_mb {
> wait_queue_head_t wq;
> struct workqueue_struct *work_queue;
> unsigned long flags;
> +
> +#ifdef CONFIG_SYSFS
> + struct device_attribute *sysfs_attrs;
> +#endif
> };
>
> struct pci_doe_feature {
> @@ -92,6 +97,112 @@ struct pci_doe_task {
> struct pci_doe_mb *doe_mb;
> };
>
> +#ifdef CONFIG_SYSFS
> +static umode_t pci_doe_sysfs_attr_is_visible(struct kobject *kobj,
> + struct attribute *a, int n)
> +{
> + struct pci_dev *pdev = to_pci_dev(kobj_to_dev(kobj));
> + struct pci_doe_mb *doe_mb;
> + unsigned long index, j;
> + void *entry;
> +
> + xa_for_each(&pdev->doe_mbs, index, doe_mb) {
> + xa_for_each(&doe_mb->prots, j, entry)
> + return a->mode;
> + }
> +
> + return 0;
> +}
> +
> +static struct attribute *pci_dev_doe_feature_attrs[] = {
> + NULL,
> +};
> +
> +const struct attribute_group pci_dev_doe_feature_group = {
> + .name = "doe_features",
> + .attrs = pci_dev_doe_feature_attrs,
> + .is_visible = pci_doe_sysfs_attr_is_visible,
> +};
> +
> +static ssize_t pci_doe_sysfs_feature_show(struct device *dev,
> + struct device_attribute *attr,
> + char *buf)
> +{
> + return sysfs_emit(buf, "%s\n", attr->attr.name);
> +}
> +
> +static int pci_doe_sysfs_feature_supports(struct pci_dev *pdev,
> + struct pci_doe_mb *doe_mb)
> +{
> + struct device *dev = &pdev->dev;
> + struct device_attribute *attrs;
> + unsigned long num_features = 0;
> + unsigned long vid, type;
> + unsigned long i;
> + void *entry;
> + int ret;
> +
> + xa_for_each(&doe_mb->prots, i, entry)
> + num_features++;
> +
> + attrs = kcalloc(num_features, sizeof(*attrs), GFP_KERNEL);
> + if (!attrs)
> + return -ENOMEM;
> +
> + doe_mb->sysfs_attrs = attrs;
> + xa_for_each(&doe_mb->prots, i, entry) {
> + sysfs_attr_init(&attrs[i].attr);
> + vid = xa_to_value(entry) >> 8;
> + type = xa_to_value(entry) & 0xFF;
> + attrs[i].attr.name = kasprintf(GFP_KERNEL,
> + "0x%04lX:%02lX", vid, type);
> + if (!attrs[i].attr.name) {
> + ret = -ENOMEM;
> + goto fail;
> + }
> +
> + attrs[i].attr.mode = 0444;
> + attrs[i].show = pci_doe_sysfs_feature_show;
> +
> + ret = sysfs_add_file_to_group(&dev->kobj, &attrs[i].attr,
> + pci_dev_doe_feature_group.name);
> + if (ret)
If we get an error here...
> + goto fail;
> + }
> +
> + return 0;
> +
> +fail:
> + doe_mb->sysfs_attrs = NULL;
> + xa_for_each(&doe_mb->prots, i, entry) {
> + if (attrs[i].show)
.. show is set so I think we end up trying to remove a file that was never successfully
added.
> + sysfs_remove_file_from_group(&dev->kobj, &attrs[i].attr,
> + pci_dev_doe_feature_group.name);
> + kfree(attrs[i].attr.name);
> + }
> +
> + kfree(attrs);
> +
> + return ret;
> +}
> +
> +int doe_sysfs_init(struct pci_dev *pdev)
> +{
> + struct pci_doe_mb *doe_mb;
> + unsigned long index;
> + int ret;
> +
> + xa_for_each(&pdev->doe_mbs, index, doe_mb) {
> + ret = pci_doe_sysfs_feature_supports(pdev, doe_mb);
> +
Blank line seems pointless as good to group the error handling
with statement that reported the error.
> + if (ret)
> + return ret;
> + }
> +
> + return 0;
> +}
> +#endif
> +
> static int pci_doe_wait(struct pci_doe_mb *doe_mb, unsigned long timeout)
> {
> if (wait_event_timeout(doe_mb->wq,
> diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
> index d9eede2dbc0e..01bbd1f1cb9b 100644
> --- a/drivers/pci/pci-sysfs.c
> +++ b/drivers/pci/pci-sysfs.c
> @@ -16,6 +16,7 @@
> #include <linux/kernel.h>
> #include <linux/sched.h>
> #include <linux/pci.h>
> +#include <linux/pci-doe.h>
> #include <linux/stat.h>
> #include <linux/export.h>
> #include <linux/topology.h>
> @@ -1230,6 +1231,12 @@ static int pci_create_resource_files(struct pci_dev *pdev)
> int i;
> int retval;
>
> + if (IS_ENABLED(CONFIG_PCI_DOE)) {
> + retval = doe_sysfs_init(pdev);
> + if (retval)
> + return retval;
> + }
> +
> /* Expose the PCI resources from this device as files */
> for (i = 0; i < PCI_STD_NUM_BARS; i++) {
>
> @@ -1655,6 +1662,9 @@ static const struct attribute_group *pci_dev_attr_groups[] = {
> #endif
> #ifdef CONFIG_PCIEASPM
> &aspm_ctrl_attr_group,
> +#endif
> +#ifdef CONFIG_PCI_DOE
> + &pci_dev_doe_feature_group,
> #endif
> NULL,
> };
> diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
> index 39a8932dc340..b85dd83ddfcb 100644
> --- a/drivers/pci/pci.h
> +++ b/drivers/pci/pci.h
> @@ -186,6 +186,9 @@ extern const struct attribute_group *pci_dev_groups[];
> extern const struct attribute_group *pcibus_groups[];
> extern const struct device_type pci_dev_type;
> extern const struct attribute_group *pci_bus_groups[];
> +#ifdef CONFIG_SYSFS
> +extern const struct attribute_group pci_dev_doe_feature_group;
> +#endif
>
> extern unsigned long pci_hotplug_io_size;
> extern unsigned long pci_hotplug_mmio_size;
> diff --git a/include/linux/pci-doe.h b/include/linux/pci-doe.h
> index 1f14aed4354b..4cc13d9ccb50 100644
> --- a/include/linux/pci-doe.h
> +++ b/include/linux/pci-doe.h
> @@ -22,4 +22,5 @@ int pci_doe(struct pci_doe_mb *doe_mb, u16 vendor, u8 type,
> const void *request, size_t request_sz,
> void *response, size_t response_sz);
>
> +int doe_sysfs_init(struct pci_dev *pci_dev);
> #endif
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v7 3/3] PCI/DOE: Allow enabling DOE without CXL
2023-09-04 5:43 [PATCH v7 1/3] PCI/DOE: Rename DOE protocol to feature Alistair Francis
2023-09-04 5:43 ` [PATCH v7 2/3] PCI/DOE: Expose the DOE features via sysfs Alistair Francis
@ 2023-09-04 5:43 ` Alistair Francis
2023-09-04 15:18 ` Jonathan Cameron
2023-09-04 15:10 ` [PATCH v7 1/3] PCI/DOE: Rename DOE protocol to feature Jonathan Cameron
2 siblings, 1 reply; 6+ messages in thread
From: Alistair Francis @ 2023-09-04 5:43 UTC (permalink / raw)
To: bhelgaas, linux-pci, Jonathan.Cameron, lukas
Cc: alex.williamson, christian.koenig, kch, gregkh, logang,
linux-kernel, alistair23, chaitanyak, rdunlap, Alistair Francis
PCIe devices (not CXL) can support DOE as well, so allow DOE to be
enabled even if CXL isn't.
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
---
v7:
- Initial patch
drivers/pci/Kconfig | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/drivers/pci/Kconfig b/drivers/pci/Kconfig
index 49bd09c7dd0a..a1223f46a902 100644
--- a/drivers/pci/Kconfig
+++ b/drivers/pci/Kconfig
@@ -117,7 +117,10 @@ config PCI_ATS
bool
config PCI_DOE
- bool
+ bool "Enable PCI Data Object Exchange (DOE) support"
+ help
+ Say Y here if you want be able to communicate with PCIe DOE
+ mailboxes.
config PCI_ECAM
bool
--
2.41.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v7 3/3] PCI/DOE: Allow enabling DOE without CXL
2023-09-04 5:43 ` [PATCH v7 3/3] PCI/DOE: Allow enabling DOE without CXL Alistair Francis
@ 2023-09-04 15:18 ` Jonathan Cameron
0 siblings, 0 replies; 6+ messages in thread
From: Jonathan Cameron @ 2023-09-04 15:18 UTC (permalink / raw)
To: Alistair Francis
Cc: bhelgaas, linux-pci, lukas, alex.williamson, christian.koenig,
kch, gregkh, logang, linux-kernel, chaitanyak, rdunlap,
Alistair Francis
On Mon, 4 Sep 2023 15:43:29 +1000
Alistair Francis <alistair23@gmail.com> wrote:
> PCIe devices (not CXL) can support DOE as well, so allow DOE to be
> enabled even if CXL isn't.
But surely everyone enables CXL? :)
>
> Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> ---
> v7:
> - Initial patch
>
> drivers/pci/Kconfig | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/pci/Kconfig b/drivers/pci/Kconfig
> index 49bd09c7dd0a..a1223f46a902 100644
> --- a/drivers/pci/Kconfig
> +++ b/drivers/pci/Kconfig
> @@ -117,7 +117,10 @@ config PCI_ATS
> bool
>
> config PCI_DOE
> - bool
> + bool "Enable PCI Data Object Exchange (DOE) support"
> + help
> + Say Y here if you want be able to communicate with PCIe DOE
> + mailboxes.
>
> config PCI_ECAM
> bool
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v7 1/3] PCI/DOE: Rename DOE protocol to feature
2023-09-04 5:43 [PATCH v7 1/3] PCI/DOE: Rename DOE protocol to feature Alistair Francis
2023-09-04 5:43 ` [PATCH v7 2/3] PCI/DOE: Expose the DOE features via sysfs Alistair Francis
2023-09-04 5:43 ` [PATCH v7 3/3] PCI/DOE: Allow enabling DOE without CXL Alistair Francis
@ 2023-09-04 15:10 ` Jonathan Cameron
2 siblings, 0 replies; 6+ messages in thread
From: Jonathan Cameron @ 2023-09-04 15:10 UTC (permalink / raw)
To: Alistair Francis
Cc: bhelgaas, linux-pci, lukas, alex.williamson, christian.koenig,
kch, gregkh, logang, linux-kernel, chaitanyak, rdunlap,
Alistair Francis
On Mon, 4 Sep 2023 15:43:27 +1000
Alistair Francis <alistair23@gmail.com> wrote:
> DOE r1.1 replaced all occurrences of "protocol" with the term "feature"
> or "Data Object Type".
>
> PCIe r6.1 (which was published July 24) incorporated that change.
>
> This patch renames the existing terms protocol with feature.
>
> Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
Hi Alastair.
I'm fine with updating this but if we are going to do so I tink we need
to catch all of them including variable names from prot -> feat etc
Jonathan
> ---
> v7:
> - Initial patch
>
> drivers/pci/doe.c | 40 ++++++++++++++++++++--------------------
> 1 file changed, 20 insertions(+), 20 deletions(-)
>
> diff --git a/drivers/pci/doe.c b/drivers/pci/doe.c
> index e3aab5edaf70..047be8c9d191 100644
> --- a/drivers/pci/doe.c
> +++ b/drivers/pci/doe.c
> @@ -43,7 +43,7 @@
> *
> * @pdev: PCI device this mailbox belongs to
> * @cap_offset: Capability offset
> - * @prots: Array of protocols supported (encoded as long values)
> + * @prots: Array of features supported (encoded as long values)
feats?
> * @wq: Wait queue for work item
> * @work_queue: Queue of pci_doe_work items
> * @flags: Bit array of PCI_DOE_FLAG_* flags
> @@ -58,7 +58,7 @@ struct pci_doe_mb {
> unsigned long flags;
> };
>
> -struct pci_doe_protocol {
> +struct pci_doe_feature {
> u16 vid;
> u8 type;
> };
> @@ -66,7 +66,7 @@ struct pci_doe_protocol {
> /**
> * struct pci_doe_task - represents a single query/response
> *
> - * @prot: DOE Protocol
> + * @prot: DOE Feature
Might be more churn, but probably worth renaming prot to feat or
similar as well!
> * @request_pl: The request payload
> * @request_pl_sz: Size of the request payload (bytes)
> * @response_pl: The response payload
> @@ -78,7 +78,7 @@ struct pci_doe_protocol {
> * @doe_mb: Used internally by the mailbox
> */
> struct pci_doe_task {
> - struct pci_doe_protocol prot;
> + struct pci_doe_feature prot;
Same here. Very confusing to leave variable called prot.
> const __le32 *request_pl;
> size_t request_pl_sz;
> __le32 *response_pl;
> @@ -217,11 +217,11 @@ static int pci_doe_recv_resp(struct pci_doe_mb *doe_mb, struct pci_doe_task *tas
> int i = 0;
> u32 val;
>
> - /* Read the first dword to get the protocol */
> + /* Read the first dword to get the feature */
> pci_read_config_dword(pdev, offset + PCI_DOE_READ, &val);
> if ((FIELD_GET(PCI_DOE_DATA_OBJECT_HEADER_1_VID, val) != task->prot.vid) ||
> (FIELD_GET(PCI_DOE_DATA_OBJECT_HEADER_1_TYPE, val) != task->prot.type)) {
> - dev_err_ratelimited(&pdev->dev, "[%x] expected [VID, Protocol] = [%04x, %02x], got [%04x, %02x]\n",
> + dev_err_ratelimited(&pdev->dev, "[%x] expected [VID, Feature] = [%04x, %02x], got [%04x, %02x]\n",
> doe_mb->cap_offset, task->prot.vid, task->prot.type,
> FIELD_GET(PCI_DOE_DATA_OBJECT_HEADER_1_VID, val),
> FIELD_GET(PCI_DOE_DATA_OBJECT_HEADER_1_TYPE, val));
> @@ -384,7 +384,7 @@ static void pci_doe_task_complete(struct pci_doe_task *task)
> }
>
> static int pci_doe_discovery(struct pci_doe_mb *doe_mb, u8 *index, u16 *vid,
> - u8 *protocol)
> + u8 *feature)
> {
> u32 request_pl = FIELD_PREP(PCI_DOE_DATA_OBJECT_DISC_REQ_3_INDEX,
> *index);
> @@ -404,7 +404,7 @@ static int pci_doe_discovery(struct pci_doe_mb *doe_mb, u8 *index, u16 *vid,
>
> response_pl = le32_to_cpu(response_pl_le);
> *vid = FIELD_GET(PCI_DOE_DATA_OBJECT_DISC_RSP_3_VID, response_pl);
> - *protocol = FIELD_GET(PCI_DOE_DATA_OBJECT_DISC_RSP_3_PROTOCOL,
> + *feature = FIELD_GET(PCI_DOE_DATA_OBJECT_DISC_RSP_3_PROTOCOL,
> response_pl);
> *index = FIELD_GET(PCI_DOE_DATA_OBJECT_DISC_RSP_3_NEXT_INDEX,
> response_pl);
> @@ -417,7 +417,7 @@ static void *pci_doe_xa_prot_entry(u16 vid, u8 prot)
> return xa_mk_value((vid << 8) | prot);
> }
>
> -static int pci_doe_cache_protocols(struct pci_doe_mb *doe_mb)
> +static int pci_doe_cache_features(struct pci_doe_mb *doe_mb)
> {
> u8 index = 0;
> u8 xa_idx = 0;
> @@ -432,7 +432,7 @@ static int pci_doe_cache_protocols(struct pci_doe_mb *doe_mb)
> return rc;
>
> pci_dbg(doe_mb->pdev,
> - "[%x] Found protocol %d vid: %x prot: %x\n",
> + "[%x] Found feature %d vid: %x prot: %x\n",
prot?
> doe_mb->cap_offset, xa_idx, vid, prot);
>
> rc = xa_insert(&doe_mb->prots, xa_idx++,
> @@ -460,7 +460,7 @@ static void pci_doe_cancel_tasks(struct pci_doe_mb *doe_mb)
> * @pdev: PCI device to create the DOE mailbox for
> * @cap_offset: Offset of the DOE mailbox
> *
> - * Create a single mailbox object to manage the mailbox protocol at the
> + * Create a single mailbox object to manage the mailbox feature at the
> * cap_offset specified.
> *
> * RETURNS: created mailbox object on success
> @@ -502,11 +502,11 @@ static struct pci_doe_mb *pci_doe_create_mb(struct pci_dev *pdev,
>
> /*
> * The state machine and the mailbox should be in sync now;
> - * Use the mailbox to query protocols.
> + * Use the mailbox to query features.
> */
> - rc = pci_doe_cache_protocols(doe_mb);
> + rc = pci_doe_cache_features(doe_mb);
> if (rc) {
> - pci_err(pdev, "[%x] failed to cache protocols : %d\n",
> + pci_err(pdev, "[%x] failed to cache features : %d\n",
> doe_mb->cap_offset, rc);
> goto err_cancel;
> }
> @@ -540,19 +540,19 @@ static void pci_doe_destroy_mb(struct pci_doe_mb *doe_mb)
>
> /**
> * pci_doe_supports_prot() - Return if the DOE instance supports the given
> - * protocol
> + * feature
> * @doe_mb: DOE mailbox capability to query
> - * @vid: Protocol Vendor ID
> - * @type: Protocol type
> + * @vid: Feature Vendor ID
> + * @type: Feature type
> *
> - * RETURNS: True if the DOE mailbox supports the protocol specified
> + * RETURNS: True if the DOE mailbox supports the feature specified
> */
> static bool pci_doe_supports_prot(struct pci_doe_mb *doe_mb, u16 vid, u8 type)
> {
> unsigned long index;
> void *entry;
>
> - /* The discovery protocol must always be supported */
> + /* The discovery feature must always be supported */
> if (vid == PCI_VENDOR_ID_PCI_SIG && type == PCI_DOE_PROTOCOL_DISCOVERY)
> return true;
>
> @@ -659,7 +659,7 @@ EXPORT_SYMBOL_GPL(pci_doe);
> * @vendor: Vendor ID
> * @type: Data Object Type
> *
> - * Find first DOE mailbox of a PCI device which supports the given protocol.
> + * Find first DOE mailbox of a PCI device which supports the given feature.
> *
> * RETURNS: Pointer to the DOE mailbox or NULL if none was found.
> */
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2023-09-04 15:18 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-04 5:43 [PATCH v7 1/3] PCI/DOE: Rename DOE protocol to feature Alistair Francis
2023-09-04 5:43 ` [PATCH v7 2/3] PCI/DOE: Expose the DOE features via sysfs Alistair Francis
2023-09-04 15:17 ` Jonathan Cameron
2023-09-04 5:43 ` [PATCH v7 3/3] PCI/DOE: Allow enabling DOE without CXL Alistair Francis
2023-09-04 15:18 ` Jonathan Cameron
2023-09-04 15:10 ` [PATCH v7 1/3] PCI/DOE: Rename DOE protocol to feature Jonathan Cameron
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).