From patchwork Mon Sep 4 05:43:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Francis X-Patchwork-Id: 13373493 X-Patchwork-Delegate: bhelgaas@google.com 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 BEEEAC83F33 for ; Mon, 4 Sep 2023 05:44:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234804AbjIDFoU (ORCPT ); Mon, 4 Sep 2023 01:44:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38080 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232830AbjIDFoT (ORCPT ); Mon, 4 Sep 2023 01:44:19 -0400 Received: from mail-oa1-x35.google.com (mail-oa1-x35.google.com [IPv6:2001:4860:4864:20::35]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A00E5B6; Sun, 3 Sep 2023 22:44:16 -0700 (PDT) Received: by mail-oa1-x35.google.com with SMTP id 586e51a60fabf-1ccc0d2e697so905000fac.0; Sun, 03 Sep 2023 22:44:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1693806256; x=1694411056; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=1IwLY7PwqnU/BZqP4BXU2O4lkxZsFI8ukfD/uIZIlRA=; b=EB8TqDvbSqw/BryAyWWoEG/2yiP8G8Cu6GDzt7LIYdpMbqYg2a226jYNLnk0xnEc6/ 7KCGzzQFbCP7lA7DpU1CNJyjwpJoYGoE54vdJjaYcMdpOCpTXZ2TkUDoJNaBlGM+h72q 5atpFD5c9GbCq1derLWWJ8/waZabBEQNO+H5+aHd2LMOQa4vJ8vZpDzJootZ5VyppZaE KIlMuhQY/9nixXFH7SdbKZX/kSSLSGHdq4rtbc4lm9e02b6fL5kznmXcOui1JRvE8CiK 8i1Q7oUf5QvNJHRHOIyCVFFgaJH78m9iHmouZtSybBTFdg/nNPvN5wPSOI5RSBkemYCW qmSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693806256; x=1694411056; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=1IwLY7PwqnU/BZqP4BXU2O4lkxZsFI8ukfD/uIZIlRA=; b=hXSGWVdp1LXJhd6FxGX2gIJgloMYmC7XXuHoioLpaLprArjZGZqL+I7RESx4wZ1Euc YmTYfUJ59ecfC2wXL9Kbg5oUovDVzRXH0aleRnvX+vaYX7QegnD/59U/pguxkNz/GrcP fwnrUc/wvVL8IhZEKvcQYKCN4qJU1u4Y8apqlbC3M8HXXGFHOGRKeatpHnGWZBSvjxCe mfT3z18dQ1FAxZP6oM95JgSI0D7kN7pVHC2DHzl+0LUmuxAj2i+NC8zyWZ1EVy0pVB2s xO1to0mqS+ZfQ+zjyHRdV2io5XR3H7zD2VFt1TPccFbCNBIAqbZxb81wRVbgm9ZuU2wC T6gQ== X-Gm-Message-State: AOJu0YzAReE07czFCpcokpr10OatEdjDxu+B0O+cU2YMzM3sUqIXAc3E CAbanLP041/KJpOiju6Lqpw= X-Google-Smtp-Source: AGHT+IEiYHWgcB+SwzttYsf2eC7N10q5v9MKWKqhjHGpi9vGdZXx8Fx7DiNAcN3YgCuO2k2qezOLKw== X-Received: by 2002:a05:6870:3921:b0:1bf:61e3:df1 with SMTP id b33-20020a056870392100b001bf61e30df1mr12800192oap.50.1693806255844; Sun, 03 Sep 2023 22:44:15 -0700 (PDT) Received: from toolbox.alistair23.me (2403-580b-97e8-0-321-6fb2-58f1-a1b1.ip6.aussiebb.net. [2403:580b:97e8:0:321:6fb2:58f1:a1b1]) by smtp.gmail.com with ESMTPSA id h3-20020a63b003000000b0056c466b09a4sm6803450pgf.59.2023.09.03.22.44.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Sep 2023 22:44:15 -0700 (PDT) From: Alistair Francis X-Google-Original-From: Alistair Francis To: bhelgaas@google.com, linux-pci@vger.kernel.org, Jonathan.Cameron@huawei.com, lukas@wunner.de Cc: alex.williamson@redhat.com, christian.koenig@amd.com, kch@nvidia.com, gregkh@linuxfoundation.org, logang@deltatee.com, linux-kernel@vger.kernel.org, alistair23@gmail.com, chaitanyak@nvidia.com, rdunlap@infradead.org, Alistair Francis Subject: [PATCH v7 1/3] PCI/DOE: Rename DOE protocol to feature Date: Mon, 4 Sep 2023 15:43:27 +1000 Message-ID: <20230904054329.865151-1-alistair.francis@wdc.com> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org 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 --- 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. */ From patchwork Mon Sep 4 05:43:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Francis X-Patchwork-Id: 13373494 X-Patchwork-Delegate: bhelgaas@google.com 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 BFBFAC71153 for ; Mon, 4 Sep 2023 05:44:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352230AbjIDFo1 (ORCPT ); Mon, 4 Sep 2023 01:44:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49028 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352210AbjIDFo1 (ORCPT ); Mon, 4 Sep 2023 01:44:27 -0400 Received: from mail-vs1-xe33.google.com (mail-vs1-xe33.google.com [IPv6:2607:f8b0:4864:20::e33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C742F103; Sun, 3 Sep 2023 22:44:22 -0700 (PDT) Received: by mail-vs1-xe33.google.com with SMTP id ada2fe7eead31-44d4c3fa6a6so391145137.0; Sun, 03 Sep 2023 22:44:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1693806262; x=1694411062; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=0OuAAA+MjszGw1Zc9pNsypPpcFTo5HUWdibD+ivDk6c=; b=rjB2fyIrcn+hhUDVp2ydSKl+VtqVELANWbGFYRgReDQGBgQOsGDWOXCe0LxRhpP26B na1jP93SvLX3wGj+a8ajRkvpXwLlhhO6TW/HbZQ4YoGDDxRXk9EgaqaTOKqfIM9IJJjb EELC0K5lVBwsx9WAw2aAGKX9FM/n9HAZMNnlI5qWE5zO7WO0Gkb/sUD0MDPqiYjKeyDl qEWh2gaCZ0zNMVesu9NBTzQWYXs+eIK6i947K2sI2ZT0hq5V1if8bmWQtk0cUK4m/DfG LD/GznxB/WXap1KcTBN2J9yIdGRXbBrQ5LyocHjiSH97d548NbUVi5WAUcUpXFu0haTH owyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693806262; x=1694411062; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0OuAAA+MjszGw1Zc9pNsypPpcFTo5HUWdibD+ivDk6c=; b=QDW1iElVonEMd8o/uAPJwzLOeV+xr2rLe7i+2+3DF/0du2Tk8xjBXdGWRDgvFbRQtb gHFkKsoruO47DHPI8QbhAm1xsqO33opcxFLdKxRqE+24F5rBLubWPYVvCLwhTAGOLcv7 cXeJHZWOL43tuPEigYfmOGLVpAYaB2JtyLhaSN/1dTNLScKV+uylc7Odnjr6MIz2VhRD k4XLDve3Yy33jZNnLGw3LhA/r1/PA8kI+57HshvtpZmwBDO6vhPtxR+VoBzAm4gWRYhK WdHd/4ZDK/7vp5BzxPCEo/OMTCACa2L3eDczyMXDbN0XfxFkrJ6Lvj3VGWumHHXn32n6 kJyQ== X-Gm-Message-State: AOJu0YzcyMxQVDN/6Y0p2JOpCgvHsR8hxlVtqb+mBhqhrafanrWKOfiS Hg654wQLq7qdt7FgG6BVg0Q= X-Google-Smtp-Source: AGHT+IG+n5LtcGqKv514eDABB63U4tGAgEG0jRQJixiP2GFzFY3xuRvub6BW3l3Qcuqhy7U+2tRUZw== X-Received: by 2002:a05:6102:52f:b0:44d:57aa:532f with SMTP id m15-20020a056102052f00b0044d57aa532fmr8192282vsa.31.1693806261860; Sun, 03 Sep 2023 22:44:21 -0700 (PDT) Received: from toolbox.alistair23.me (2403-580b-97e8-0-321-6fb2-58f1-a1b1.ip6.aussiebb.net. [2403:580b:97e8:0:321:6fb2:58f1:a1b1]) by smtp.gmail.com with ESMTPSA id h3-20020a63b003000000b0056c466b09a4sm6803450pgf.59.2023.09.03.22.44.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Sep 2023 22:44:21 -0700 (PDT) From: Alistair Francis X-Google-Original-From: Alistair Francis To: bhelgaas@google.com, linux-pci@vger.kernel.org, Jonathan.Cameron@huawei.com, lukas@wunner.de Cc: alex.williamson@redhat.com, christian.koenig@amd.com, kch@nvidia.com, gregkh@linuxfoundation.org, logang@deltatee.com, linux-kernel@vger.kernel.org, alistair23@gmail.com, chaitanyak@nvidia.com, rdunlap@infradead.org, Alistair Francis Subject: [PATCH v7 2/3] PCI/DOE: Expose the DOE features via sysfs Date: Mon, 4 Sep 2023 15:43:28 +1000 Message-ID: <20230904054329.865151-2-alistair.francis@wdc.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230904054329.865151-1-alistair.francis@wdc.com> References: <20230904054329.865151-1-alistair.francis@wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org 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 --- 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 +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 #include #include +#include #include #include #include @@ -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 From patchwork Mon Sep 4 05:43:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Francis X-Patchwork-Id: 13373495 X-Patchwork-Delegate: bhelgaas@google.com 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 79D94C71153 for ; Mon, 4 Sep 2023 05:44:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352255AbjIDFod (ORCPT ); Mon, 4 Sep 2023 01:44:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54750 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233752AbjIDFoc (ORCPT ); Mon, 4 Sep 2023 01:44:32 -0400 Received: from mail-oa1-x2a.google.com (mail-oa1-x2a.google.com [IPv6:2001:4860:4864:20::2a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 993D412A; Sun, 3 Sep 2023 22:44:28 -0700 (PDT) Received: by mail-oa1-x2a.google.com with SMTP id 586e51a60fabf-1d4c9494b42so770452fac.0; Sun, 03 Sep 2023 22:44:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1693806268; x=1694411068; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=OAm78ZzPbw4FrS4zLROjKE8sBNAUiQROVAB/OHMO/JA=; b=N3R2WRoVFeKdzL6bGYC4FUx+wZRmyEh709QnuXnN+278ZWWr6tqkI9u9SIOCYTr6An 9Fq6a+J9KbQXWgftT0wxGEui/w8qfIzAKZ7t1HATYJHbHSRkpdDf0vVP6yOr/DbDL0pC fxd0tbk63m4zvbdX/USrXdE7Owxn1g50j0sfIHW0qv707JHTRFqlBgJcxrvEVRgcKeIS G9PGmeZN+N6v/H9ENQY1pfFOlDLDicGAMhK4KYRVmLpyVQA2fkrtIebYQAP7RSY31Ti4 FRgR/a3RlcByP/XE0R2BHFmeS+fKPiVO0XIQw114CvuYZjMnjH/3z1bJQns1cRtStJ+7 YcKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693806268; x=1694411068; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=OAm78ZzPbw4FrS4zLROjKE8sBNAUiQROVAB/OHMO/JA=; b=jfb0WkYcG+/Sol+qtUUPmFnQHxqryHJ1/FRx96VBSiX+KvJ+3p7TzU01RrGQyZ8O2H zCsn1svoZuXtz7QBaIlmwKHIp5tCyFNGD7YBSS9aIqr8TJW+D4izBNDZAomv19RiRpcg HQyL1ufJrxtCGts8uR8D/8TyJAD1bVmxxq48Xn+scCF+zTrT5lxSamPkOddwJr5aMMbL jEcHVnZq8JiZT0J7N9N+piyLJgzZmKLiIcjJ019Rm2H8QsVVq6ac958+aopchjSdrEh8 UGBR745F/+XB8b7wCkIqwCSp5otYz5rwmOdbQkqFIfezgluobwcrbzIZBc59nU9whMEA A8LQ== X-Gm-Message-State: AOJu0YwkaiChlgYgHmHU1t6BmkJWHPF76aHg7MwYA1Z+O+6gfoHXODQl 9kSzoW/Zgsk0JjFa0eqQrT8= X-Google-Smtp-Source: AGHT+IG5OgF+rGnOBB4RQPUgu9ojBdvDZBMqkEApWzrmc2Uo9PqinWkxfaFWap0Q4z8+LYr2PI22Xw== X-Received: by 2002:a05:6870:b6a3:b0:1d0:d44f:46d4 with SMTP id cy35-20020a056870b6a300b001d0d44f46d4mr12271687oab.28.1693806267879; Sun, 03 Sep 2023 22:44:27 -0700 (PDT) Received: from toolbox.alistair23.me (2403-580b-97e8-0-321-6fb2-58f1-a1b1.ip6.aussiebb.net. [2403:580b:97e8:0:321:6fb2:58f1:a1b1]) by smtp.gmail.com with ESMTPSA id h3-20020a63b003000000b0056c466b09a4sm6803450pgf.59.2023.09.03.22.44.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Sep 2023 22:44:27 -0700 (PDT) From: Alistair Francis X-Google-Original-From: Alistair Francis To: bhelgaas@google.com, linux-pci@vger.kernel.org, Jonathan.Cameron@huawei.com, lukas@wunner.de Cc: alex.williamson@redhat.com, christian.koenig@amd.com, kch@nvidia.com, gregkh@linuxfoundation.org, logang@deltatee.com, linux-kernel@vger.kernel.org, alistair23@gmail.com, chaitanyak@nvidia.com, rdunlap@infradead.org, Alistair Francis Subject: [PATCH v7 3/3] PCI/DOE: Allow enabling DOE without CXL Date: Mon, 4 Sep 2023 15:43:29 +1000 Message-ID: <20230904054329.865151-3-alistair.francis@wdc.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230904054329.865151-1-alistair.francis@wdc.com> References: <20230904054329.865151-1-alistair.francis@wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org 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 Reviewed-by: Jonathan Cameron --- 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