Message ID | 20230725035755.2621507-1-alistair.francis@wdc.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9010:0:b0:3e4:2afc:c1 with SMTP id l16csp2252848vqg; Mon, 24 Jul 2023 22:40:08 -0700 (PDT) X-Google-Smtp-Source: APBJJlGBKWbCpGeAhgSRZjOpWymQi/Pd2rzxaomg25rnfWgJBujihNHUL5bXsGbPtYqisTcWcDV8 X-Received: by 2002:a17:90b:1b0a:b0:263:2335:594e with SMTP id nu10-20020a17090b1b0a00b002632335594emr12676131pjb.38.1690263608332; Mon, 24 Jul 2023 22:40:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690263608; cv=none; d=google.com; s=arc-20160816; b=HQ9WWDpxmsQB7vDDtpIxapoiwRcMjFaVeuJSe4+8FQ4e3zGcPBkk/yXHITCRpPXGhz DO8Ga8ZPAUw3ZybmWgXcOF0aEYS4PpMI+ulj5AlBRx/72Rnq/TM6zA0nkNd58e2AVdk8 vDhld0tW2ULmZRPQzAae6LIZEYJ/ew/VcZDVk1tKEJEqZNim4ArZV0hk3EBFpyzHuBZZ aI9J1ve0Qeqf1QjlbCk5hVotKT+ng7B2DVk/2pyUrUrRMvUJO/cmHB+aySYtJ3iXaHu4 Z9CadHqEf703+INyBwfFbBVNHVBtH9OiSshMky8/Be6Mt7F+IiV5rlPZbYlXZdrZjLQC yFCw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=LZPlW/yT7XrQQ9jeV1pXKAYRgltUH+1XO+QAfr9/oKk=; fh=oBUnPuUauJOxSsTZf9IomsOaIvb/t6bB/WWOIMmWXpA=; b=LYr/4eaEME09ZHmrpbq5xtCsxqNm2bAvVElX6hRwdtctGTaJA1CeR8/XUWIuZIW5d0 pG7xdHSyjL0UTLutShiPgD60IzjH5ND4rCJctjpsIJwgZ6BDitNab+UX0OOu4r4VZpfe kke9xru+lAPDKBqPa3dvt/So11iFTKHarNbItREY7Thf5eohVPwX4PKr+MAgd2WdL1m6 TJxGlDj5A7VWD97lmJUZ0yrN3GO2gd9hQx7fxXDWCsmkR7UX0AujzOscfXcbZhvvccKJ +x7Eb7eycjcEVc6zU3sHlpq+/Vwfdkar4DAwjoc1IaIk6DA7nt2trVqBbMgN8UKSJ2Iw 3K4w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=ahG22hpF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id pi10-20020a17090b1e4a00b00256a04ff7cbsi11789341pjb.119.2023.07.24.22.39.55; Mon, 24 Jul 2023 22:40:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=ahG22hpF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231254AbjGYD6I (ORCPT <rfc822;kautuk.consul.80@gmail.com> + 99 others); Mon, 24 Jul 2023 23:58:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45464 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229452AbjGYD6F (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 24 Jul 2023 23:58:05 -0400 Received: from mail-pg1-x52c.google.com (mail-pg1-x52c.google.com [IPv6:2607:f8b0:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 93FB312E; Mon, 24 Jul 2023 20:58:04 -0700 (PDT) Received: by mail-pg1-x52c.google.com with SMTP id 41be03b00d2f7-55ba5fae2e6so3610414a12.0; Mon, 24 Jul 2023 20:58:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690257484; x=1690862284; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=LZPlW/yT7XrQQ9jeV1pXKAYRgltUH+1XO+QAfr9/oKk=; b=ahG22hpFlFmdEGBSNYkZ8huJUDKVqXeZkO1TS/eJ49ngeyh2bcDcFQZxL60PvtfTkN hSA0RqJSKLL2bF/RTFx0Dxqh19vw86pwRIxc0agEE6jw3yH5JPYbDm7RuQHTqEb4Qj6r kqwwnBmRljwDjSz4f4RSzWQEyJ9zrZ3U5gqYgieFBSJ/KT5MWz7qNig7X7ykk2NxnloL SH32MP3iv0hVWYM+sxtjer4ctpiVwChM0IYvMwM81zJIH9VG/iIVe5UepPScZyNAgnAv raSRcAXfFXAGmqSfAYDiGh9Lr+bFXaCo9rL4xLgcOiBRS5efUHiUvedMetfzTRcFn8np dbbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690257484; x=1690862284; 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=LZPlW/yT7XrQQ9jeV1pXKAYRgltUH+1XO+QAfr9/oKk=; b=Yp5l7WIuTFpMDBpIA8W8Cm46bUvrsVkbGb6uwGl3bPxCJU9gv4lyXZ4fmfoXV1aA3s gupM4Q6CmItxlZ0xlSo1LC3t+9It1ZAjYiUNuY0na0UkWMoBd2CbgwPBqMCuOPkSUE+Y mcYC/eFPi/krd0X+eQMhcieJkQauKudr58ADqiavu+M1iCd2qFhmYbOuft8msaYQRX0j iF8ZabizJ9Eu+9xsCMt3UlCHSwwrmwnHKzZracmQbGYjOgYXdAWiNPLPh5hwA1/iFiGO tM1Bwg/Vs0go7TwoKpV2Vi8FBDcfZAV8ztAJwBXuzg90DpzaZ4frBD7JdmcumGa8AJKJ Qyig== X-Gm-Message-State: ABy/qLYhsn92E46qd+7yUacYju96vBg72WV0/MhZ2Ijnmf0955WxXKxy 4VCCp/9+bqGWZ5m1HSMyCgk= X-Received: by 2002:a17:90a:5907:b0:262:ed49:ffe7 with SMTP id k7-20020a17090a590700b00262ed49ffe7mr12760787pji.25.1690257483920; Mon, 24 Jul 2023 20:58:03 -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 s30-20020a17090a69a100b00262e5449dbcsm1139016pjj.24.2023.07.24.20.58.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Jul 2023 20:58:03 -0700 (PDT) From: Alistair Francis <alistair23@gmail.com> X-Google-Original-From: Alistair Francis <alistair.francis@wdc.com> To: bhelgaas@google.com, linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org Cc: alistair23@gmail.com, Alistair Francis <alistair.francis@wdc.com> Subject: [PATCH] PCI/DOE: Expose the DOE protocols via sysfs Date: Tue, 25 Jul 2023 13:57:55 +1000 Message-Id: <20230725035755.2621507-1-alistair.francis@wdc.com> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772369853015644667 X-GMAIL-MSGID: 1772369853015644667 |
Series |
PCI/DOE: Expose the DOE protocols via sysfs
|
|
Commit Message
Alistair Francis
July 25, 2023, 3:57 a.m. UTC
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 protocols supported by the device.
The kernel is already querying the DOE protocols supported and cacheing
the values. This patch exposes the values via sysfs. This will allow
userspace to determine which DOE protocols are supported by the PCIe
device.
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
---
drivers/pci/doe.c | 28 ++++++++++++++++++++++++++++
drivers/pci/pci-sysfs.c | 27 +++++++++++++++++++++++++++
include/linux/pci-doe.h | 2 ++
3 files changed, 57 insertions(+)
Comments
On Tue, Jul 25, 2023 at 01:57:55PM +1000, Alistair Francis 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 protocols supported by the device. > > The kernel is already querying the DOE protocols supported and cacheing > the values. This patch exposes the values via sysfs. This will allow > userspace to determine which DOE protocols are supported by the PCIe > device. Just dumping the list of supported protocols into dmesg might be simpler, unless you intend to add mechanisms to actually use certain DOE mailboxes from user space or expose the information in lspci. Do have plans for either of that or what's the motivation to use sysfs? I think I'd rather want everything in doe.c (#ifdef'ed to CONFIG_SYSFS) and only make dev_attr_doe_proto public. Thanks, Lukas
On Tue, Jul 25, 2023 at 11:00 AM Jonathan Cameron <Jonathan.Cameron@huawei.com> wrote: > > On Tue, 25 Jul 2023 13:57:55 +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 protocols supported by the device. > > > > The kernel is already querying the DOE protocols supported and cacheing > > the values. This patch exposes the values via sysfs. This will allow > > userspace to determine which DOE protocols are supported by the PCIe > > device. > > > > Signed-off-by: Alistair Francis <alistair.francis@wdc.com> > > Hi Alistair, > > Needs documentation. > Documentation/ABI/testing/sys-bus-pci probably the right place. Ok, I'll add some > > Also, I wonder if we want to associate each DOE with the protocols > it supports rather than clumping them together in one file... In the future there could be vendor IDs or even standardised IDs that the current kernel doesn't support/understand. So my thinking was that by exposing all of the supported protocols userspace can use that information as it wishes. Then I wanted to work on supporting specific DOE protocols in the kernel and exposing that to userspace. But I think a single sysfs makes sense as a base point to convey information. > Otherwise we'll loose information on sharing + we may well see > repeated entries as it's fine to have more than one instance of > given protocol. > > A few more comments inline about what happens when we do run out > of space in the buffer. > > Thanks, > > Jonathan > > > --- > > drivers/pci/doe.c | 28 ++++++++++++++++++++++++++++ > > drivers/pci/pci-sysfs.c | 27 +++++++++++++++++++++++++++ > > include/linux/pci-doe.h | 2 ++ > > 3 files changed, 57 insertions(+) > > > > diff --git a/drivers/pci/doe.c b/drivers/pci/doe.c > > index 1b97a5ab71a9..cc1c23c78ac1 100644 > > --- a/drivers/pci/doe.c > > +++ b/drivers/pci/doe.c > > @@ -563,6 +563,34 @@ static bool pci_doe_supports_prot(struct pci_doe_mb *doe_mb, u16 vid, u8 type) > > return false; > > } > > > > +/** > > + * pci_doe_sysfs_proto_supports() - Write the supported DOE protocols > > + * to a sysfs buffer > > + * @doe_mb: DOE mailbox capability to query > > + * @buf: buffer to store the sysfs strings > > + * @offset: offset in buffer to store the sysfs strings > > + * > > + * RETURNS: The number of bytes written, 0 means an error occured > > + */ > > +unsigned long pci_doe_sysfs_proto_supports(struct pci_doe_mb *doe_mb, > > + char *buf, ssize_t offset) > > +{ > > + unsigned long index; > > + ssize_t ret = offset, r; > > I find that hard to parse. Maybe > > ssize_t ret = offset; > ssize_t r; > > > > > + void *entry; > > + > > + xa_for_each(&doe_mb->prots, index, entry) { > > + r = sysfs_emit_at(buf, ret, "0x%08lX\n", xa_to_value(entry)); > > + > > + if (r == 0) > > + return 0; > > return ret here? Otherwise we aren't outputting everything that we have > managed to print before the buffer fills up. > It's also inconsistent because if the last entry happens to partly print > we'll let it through whereas, if it doesn't fit at all we will drop > all the info about this DOE instance. Good point, I'll update this and the variable declarations Alistair > > > > + > > + ret += r; > > + } > > + > > + return ret; > > +} > > + > > /** > > * pci_doe_submit_task() - Submit a task to be processed by the state machine > > * > > diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c > > index ab32a91f287b..df93051e65bf 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> > > @@ -290,6 +291,29 @@ static ssize_t modalias_show(struct device *dev, struct device_attribute *attr, > > } > > static DEVICE_ATTR_RO(modalias); > > > > +#ifdef CONFIG_PCI_DOE > > +static ssize_t doe_proto_show(struct device *dev, struct device_attribute *attr, > > + char *buf) > > +{ > > + struct pci_dev *pci_dev = to_pci_dev(dev); > > + unsigned long index; > > + ssize_t ret = 0, r; > > As above. > > > + struct pci_doe_mb *doe_mb; > > + > > + xa_for_each(&pci_dev->doe_mbs, index, doe_mb) { > > + r = pci_doe_sysfs_proto_supports(doe_mb, buf, ret); > > + > > + if (r == 0) > > + return 0; > > As above, return ret here I think makes more sense than 0. > > > > + > > + ret += r; > > + } > > + > > + return ret; > > +} > > +static DEVICE_ATTR_RO(doe_proto); > > +#endif > > + > > static ssize_t enable_store(struct device *dev, struct device_attribute *attr, > > const char *buf, size_t count) > > { > > @@ -603,6 +627,9 @@ static struct attribute *pci_dev_attrs[] = { > > &dev_attr_local_cpus.attr, > > &dev_attr_local_cpulist.attr, > > &dev_attr_modalias.attr, > > +#ifdef CONFIG_PCI_DOE > > + &dev_attr_doe_proto.attr, > > +#endif > > #ifdef CONFIG_NUMA > > &dev_attr_numa_node.attr, > > #endif > > diff --git a/include/linux/pci-doe.h b/include/linux/pci-doe.h > > index 1f14aed4354b..066494a4dba3 100644 > > --- a/include/linux/pci-doe.h > > +++ b/include/linux/pci-doe.h > > @@ -21,5 +21,7 @@ struct pci_doe_mb *pci_find_doe_mailbox(struct pci_dev *pdev, u16 vendor, > > 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); > > +unsigned long pci_doe_sysfs_proto_supports(struct pci_doe_mb *doe_mb, > > + char *buf, ssize_t offset); > > > > #endif >
On Thu, Jul 27, 2023 at 4:39 AM Jonathan Cameron <Jonathan.Cameron@huawei.com> wrote: > > On Tue, 25 Jul 2023 18:30:46 +0200 > Lukas Wunner <lukas@wunner.de> wrote: > > > On Tue, Jul 25, 2023 at 01:57:55PM +1000, Alistair Francis 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 protocols supported by the device. > > > > > > The kernel is already querying the DOE protocols supported and cacheing > > > the values. This patch exposes the values via sysfs. This will allow > > > userspace to determine which DOE protocols are supported by the PCIe > > > device. > > > > Just dumping the list of supported protocols into dmesg might be simpler, > > unless you intend to add mechanisms to actually use certain DOE mailboxes > > from user space or expose the information in lspci. Do have plans for > > either of that or what's the motivation to use sysfs? > > > > I can answer this one in rather than waiting for Alastair to see it > (given I was involved in shooting down the earlier proposal :( > > At least partly motivated by providing the info for lspci which > I agree with being a useful addition for debug etc. > https://github.com/pciutils/pciutils/pull/152 Yep, a big benefit is lspci or other userspace tools to be able to see what DOE protocols are supported. I also have plans to expose DOE mailboxes to userspace. That way we can run the SPDM requester code (using libspdm) in userspace to communicate with devices using SPDM. That will allow device authentication for example. > > I can see it would also be useful for things that will poke from > userspace because they aren't expected to run in production (and hence > hopefully don't care about potential races etc). CXL compliance > comes to mind - I don't think we ever want to carry kernel code for that. That too! > > Jonathan > > > > > I think I'd rather want everything in doe.c (#ifdef'ed to CONFIG_SYSFS) > > and only make dev_attr_doe_proto public. It seemed like all of the sysf was in this file, which is why I added it there. I'm happy to move it if that's preferred though Alistair > > > > Thanks, > > > > Lukas > > >
On Mon, Jul 31, 2023 at 11:30:29AM -0400, Alistair Francis wrote: > Yep, a big benefit is lspci or other userspace tools to be able to see > what DOE protocols are supported. Fair enough, but please make that motivation explicit in the commit message. > I also have plans to expose DOE mailboxes to userspace. That way we > can run the SPDM requester code (using libspdm) in userspace to > communicate with devices using SPDM. That will allow device > authentication for example. That duplicates our effort to bring up authentication in the kernel: https://github.com/l1k/linux/commits/doe We had a lengthy debate on the pros and cons of doing SPDM in-kernel versus in user space. We realized that when resuming a device from D3cold or recovering it after reset, the user space component performing SPDM authentication might reside on the device (disk, network) being resumed or reset, preventing its execution. When resuming from system sleep, devices need to be reauthenticated during the ->resume_noirq phase, i.e. with device interrupts disabled, as drivers are allowed access to devices already in that phase. So authentication (and encryption establishment) needs to happen this early, when user space isn't available yet. See the commit message of "PCI/CMA: Reauthenticate devices on reset and resume" on the above-linked branch for details. Thanks, Lukas
On Thu, Jul 27, 2023 at 09:38:57AM +0100, Jonathan Cameron wrote: > On Tue, 25 Jul 2023 18:30:46 +0200 Lukas Wunner <lukas@wunner.de> wrote: > > Do have plans for > > either of that or what's the motivation to use sysfs? [...] > I can see it would also be useful for things that will poke from > userspace because they aren't expected to run in production (and hence > hopefully don't care about potential races etc). CXL compliance > comes to mind - I don't think we ever want to carry kernel code for that. FWIW, USB4/Thunderbolt does have kernel code for DMA testing with a special dongle (drivers/thunderbolt/dma_test.c) as well as code for lane margining, so there *is* some precedent for that... :) config USB4_DEBUGFS_MARGINING bool "Expose receiver lane margining operations under USB4 ports (DANGEROUS)" depends on DEBUG_FS depends on USB4_DEBUGFS_WRITE help Enables hardware and software based receiver lane margining support under each USB4 port. Used for electrical quality and robustness validation during manufacturing. Should not be enabled by distro kernels. Thanks, Lukas
On Mon, Jul 31, 2023 at 1:52 PM Lukas Wunner <lukas@wunner.de> wrote: > > On Mon, Jul 31, 2023 at 11:30:29AM -0400, Alistair Francis wrote: > > Yep, a big benefit is lspci or other userspace tools to be able to see > > what DOE protocols are supported. > > Fair enough, but please make that motivation explicit in the commit > message. Fixed in v2 > > > > I also have plans to expose DOE mailboxes to userspace. That way we > > can run the SPDM requester code (using libspdm) in userspace to > > communicate with devices using SPDM. That will allow device > > authentication for example. > > That duplicates our effort to bring up authentication in the kernel: > https://github.com/l1k/linux/commits/doe That's great! > > We had a lengthy debate on the pros and cons of doing SPDM in-kernel > versus in user space. We realized that when resuming a device from > D3cold or recovering it after reset, the user space component performing > SPDM authentication might reside on the device (disk, network) being > resumed or reset, preventing its execution. > > When resuming from system sleep, devices need to be reauthenticated > during the ->resume_noirq phase, i.e. with device interrupts disabled, > as drivers are allowed access to devices already in that phase. > So authentication (and encryption establishment) needs to happen this > early, when user space isn't available yet. Yeah, I had the same debate. Resume/suspend and reset are good points though. Do you plan on supporting all SPDM commands in the kernel and then passing information to userspace as required? Alistair > > See the commit message of "PCI/CMA: Reauthenticate devices on reset > and resume" on the above-linked branch for details. > > Thanks, > > Lukas
diff --git a/drivers/pci/doe.c b/drivers/pci/doe.c index 1b97a5ab71a9..cc1c23c78ac1 100644 --- a/drivers/pci/doe.c +++ b/drivers/pci/doe.c @@ -563,6 +563,34 @@ static bool pci_doe_supports_prot(struct pci_doe_mb *doe_mb, u16 vid, u8 type) return false; } +/** + * pci_doe_sysfs_proto_supports() - Write the supported DOE protocols + * to a sysfs buffer + * @doe_mb: DOE mailbox capability to query + * @buf: buffer to store the sysfs strings + * @offset: offset in buffer to store the sysfs strings + * + * RETURNS: The number of bytes written, 0 means an error occured + */ +unsigned long pci_doe_sysfs_proto_supports(struct pci_doe_mb *doe_mb, + char *buf, ssize_t offset) +{ + unsigned long index; + ssize_t ret = offset, r; + void *entry; + + xa_for_each(&doe_mb->prots, index, entry) { + r = sysfs_emit_at(buf, ret, "0x%08lX\n", xa_to_value(entry)); + + if (r == 0) + return 0; + + ret += r; + } + + return ret; +} + /** * pci_doe_submit_task() - Submit a task to be processed by the state machine * diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c index ab32a91f287b..df93051e65bf 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> @@ -290,6 +291,29 @@ static ssize_t modalias_show(struct device *dev, struct device_attribute *attr, } static DEVICE_ATTR_RO(modalias); +#ifdef CONFIG_PCI_DOE +static ssize_t doe_proto_show(struct device *dev, struct device_attribute *attr, + char *buf) +{ + struct pci_dev *pci_dev = to_pci_dev(dev); + unsigned long index; + ssize_t ret = 0, r; + struct pci_doe_mb *doe_mb; + + xa_for_each(&pci_dev->doe_mbs, index, doe_mb) { + r = pci_doe_sysfs_proto_supports(doe_mb, buf, ret); + + if (r == 0) + return 0; + + ret += r; + } + + return ret; +} +static DEVICE_ATTR_RO(doe_proto); +#endif + static ssize_t enable_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { @@ -603,6 +627,9 @@ static struct attribute *pci_dev_attrs[] = { &dev_attr_local_cpus.attr, &dev_attr_local_cpulist.attr, &dev_attr_modalias.attr, +#ifdef CONFIG_PCI_DOE + &dev_attr_doe_proto.attr, +#endif #ifdef CONFIG_NUMA &dev_attr_numa_node.attr, #endif diff --git a/include/linux/pci-doe.h b/include/linux/pci-doe.h index 1f14aed4354b..066494a4dba3 100644 --- a/include/linux/pci-doe.h +++ b/include/linux/pci-doe.h @@ -21,5 +21,7 @@ struct pci_doe_mb *pci_find_doe_mailbox(struct pci_dev *pdev, u16 vendor, 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); +unsigned long pci_doe_sysfs_proto_supports(struct pci_doe_mb *doe_mb, + char *buf, ssize_t offset); #endif