From: Bjorn Helgaas <helgaas@kernel.org>
To: Xiongfeng Wang <wangxiongfeng2@huawei.com>
Cc: bhelgaas@google.com, fbarrat@linux.ibm.com, ajd@linux.ibm.com,
mpe@ellerman.id.au, npiggin@gmail.com,
christophe.leroy@csgroup.eu, arnd@arndb.de,
gregkh@linuxfoundation.org, ben.widawsky@intel.com,
linux-pci@vger.kernel.org, yangyingliang@huawei.com,
linuxppc-dev@lists.ozlabs.org, jonathan.cameron@huawei.com,
"David E. Box" <david.e.box@linux.intel.com>
Subject: Re: [PATCH 1/2] PCI: Add pci_find_next_dvsec_capability to find next designated VSEC
Date: Mon, 7 Aug 2023 15:33:51 -0500 [thread overview]
Message-ID: <20230807203351.GA269717@bhelgaas> (raw)
In-Reply-To: <20230807031846.77348-2-wangxiongfeng2@huawei.com>
[+cc David since drivers/platform/x86/intel/vsec.c does some similar
things, although it seems to iterate over all Intel DVSEC IDs at once]
In subject:
PCI: Add pci_find_next_dvsec_capability() to find next Designated VSEC
On Mon, Aug 07, 2023 at 11:18:45AM +0800, Xiongfeng Wang wrote:
> Some devices may have several DVSEC(Designated Vendor-Specific Extended
> Capability) entries with the same DVSEC ID. Add
> pci_find_next_dvsec_capability() to find them all.
Add space between "DVSEC" and "(Designated ...)".
> Signed-off-by: Xiongfeng Wang <wangxiongfeng2@huawei.com>
Acked-by: Bjorn Helgaas <bhelgaas@google.com>
so you can merge this along with the ocxl patch that uses it.
> ---
> drivers/pci/pci.c | 37 +++++++++++++++++++++++++------------
> include/linux/pci.h | 2 ++
> 2 files changed, 27 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
> index 60230da957e0..3455ca7306ae 100644
> --- a/drivers/pci/pci.c
> +++ b/drivers/pci/pci.c
> @@ -749,35 +749,48 @@ u16 pci_find_vsec_capability(struct pci_dev *dev, u16 vendor, int cap)
> EXPORT_SYMBOL_GPL(pci_find_vsec_capability);
>
> /**
> - * pci_find_dvsec_capability - Find DVSEC for vendor
> + * pci_find_next_dvsec_capability - Find next DVSEC for vendor
> * @dev: PCI device to query
> + * @start: address at which to start looking (0 to start at beginning of list)
s/address/Address/ to match other parameters
> * @vendor: Vendor ID to match for the DVSEC
> * @dvsec: Designated Vendor-specific capability ID
There are a lot of IDs floating around here, so to better match the
spec language:
@dvsec: Vendor-defined DVSEC ID
> - * If DVSEC has Vendor ID @vendor and DVSEC ID @dvsec return the capability
> - * offset in config space; otherwise return 0.
> + * Returns the address of the next DVSEC if the DVSEC has Vendor ID @vendor and
> + * DVSEC ID @dvsec; otherwise return 0. DVSEC can occur several times with the
> + * same DVSEC ID for some devices, and this provides a way to find them all.
> */
> -u16 pci_find_dvsec_capability(struct pci_dev *dev, u16 vendor, u16 dvsec)
> +u16 pci_find_next_dvsec_capability(struct pci_dev *dev, u16 start, u16 vendor,
> + u16 dvsec)
> {
> - int pos;
> + u16 pos = start;
>
> - pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_DVSEC);
> - if (!pos)
> - return 0;
> -
> - while (pos) {
> + while ((pos = pci_find_next_ext_capability(dev, pos,
> + PCI_EXT_CAP_ID_DVSEC))) {
> u16 v, id;
>
> pci_read_config_word(dev, pos + PCI_DVSEC_HEADER1, &v);
> pci_read_config_word(dev, pos + PCI_DVSEC_HEADER2, &id);
> if (vendor == v && dvsec == id)
> return pos;
> -
> - pos = pci_find_next_ext_capability(dev, pos, PCI_EXT_CAP_ID_DVSEC);
> }
>
> return 0;
> }
> +EXPORT_SYMBOL_GPL(pci_find_next_dvsec_capability);
> +
> +/**
> + * pci_find_dvsec_capability - Find DVSEC for vendor
> + * @dev: PCI device to query
> + * @vendor: Vendor ID to match for the DVSEC
> + * @dvsec: Designated Vendor-specific capability ID
> + *
> + * If DVSEC has Vendor ID @vendor and DVSEC ID @dvsec return the capability
> + * offset in config space; otherwise return 0.
> + */
> +u16 pci_find_dvsec_capability(struct pci_dev *dev, u16 vendor, u16 dvsec)
> +{
> + return pci_find_next_dvsec_capability(dev, 0, vendor, dvsec);
> +}
> EXPORT_SYMBOL_GPL(pci_find_dvsec_capability);
>
> /**
> diff --git a/include/linux/pci.h b/include/linux/pci.h
> index c69a2cc1f412..82bb905daf72 100644
> --- a/include/linux/pci.h
> +++ b/include/linux/pci.h
> @@ -1168,6 +1168,8 @@ u16 pci_find_next_ext_capability(struct pci_dev *dev, u16 pos, int cap);
> struct pci_bus *pci_find_next_bus(const struct pci_bus *from);
> u16 pci_find_vsec_capability(struct pci_dev *dev, u16 vendor, int cap);
> u16 pci_find_dvsec_capability(struct pci_dev *dev, u16 vendor, u16 dvsec);
> +u16 pci_find_next_dvsec_capability(struct pci_dev *dev, u16 start, u16 vendor,
> + u16 dvsec);
>
> u64 pci_get_dsn(struct pci_dev *dev);
>
> --
> 2.20.1
>
next prev parent reply other threads:[~2023-08-07 20:33 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-07 3:18 [PATCH 0/2] introduce pci_find_next_dvsec_capability() to simplify the code Xiongfeng Wang
2023-08-07 3:18 ` [PATCH 1/2] PCI: Add pci_find_next_dvsec_capability to find next designated VSEC Xiongfeng Wang
2023-08-07 4:24 ` Andrew Donnellan
2023-08-07 20:33 ` Bjorn Helgaas [this message]
2023-08-07 3:18 ` [PATCH 2/2] ocxl: use pci_find_next_dvsec_capability() to simplify the code Xiongfeng Wang
2023-08-07 4:54 ` Andrew Donnellan
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=20230807203351.GA269717@bhelgaas \
--to=helgaas@kernel.org \
--cc=ajd@linux.ibm.com \
--cc=arnd@arndb.de \
--cc=ben.widawsky@intel.com \
--cc=bhelgaas@google.com \
--cc=christophe.leroy@csgroup.eu \
--cc=david.e.box@linux.intel.com \
--cc=fbarrat@linux.ibm.com \
--cc=gregkh@linuxfoundation.org \
--cc=jonathan.cameron@huawei.com \
--cc=linux-pci@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=mpe@ellerman.id.au \
--cc=npiggin@gmail.com \
--cc=wangxiongfeng2@huawei.com \
--cc=yangyingliang@huawei.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;
as well as URLs for NNTP newsgroup(s).