* [PATCH 0/2] introduce pci_find_next_dvsec_capability() to simplify the code @ 2023-08-07 3:18 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 3:18 ` [PATCH 2/2] ocxl: use pci_find_next_dvsec_capability() to simplify the code Xiongfeng Wang 0 siblings, 2 replies; 6+ messages in thread From: Xiongfeng Wang @ 2023-08-07 3:18 UTC (permalink / raw) To: bhelgaas, fbarrat, ajd, mpe, npiggin, christophe.leroy, arnd, gregkh, ben.widawsky, wangxiongfeng2 Cc: jonathan.cameron, linux-pci, linuxppc-dev, yangyingliang Some devices may have several DVSEC(Designated Vendor-Specific Extended Capability) entries with the same DVSEC ID. Introduce pci_find_next_dvsec_capability() to simplify the code. Xiongfeng Wang (2): PCI: Add pci_find_next_dvsec_capability to find next designated VSEC ocxl: use pci_find_next_dvsec_capability() to simplify the code arch/powerpc/platforms/powernv/ocxl.c | 20 ++------------- drivers/misc/ocxl/config.c | 21 +++++---------- drivers/pci/pci.c | 37 ++++++++++++++++++--------- include/linux/pci.h | 2 ++ include/misc/ocxl-config.h | 4 --- 5 files changed, 35 insertions(+), 49 deletions(-) -- 2.20.1 ^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 1/2] PCI: Add pci_find_next_dvsec_capability to find next designated VSEC 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 ` Xiongfeng Wang 2023-08-07 4:24 ` Andrew Donnellan 2023-08-07 20:33 ` Bjorn Helgaas 2023-08-07 3:18 ` [PATCH 2/2] ocxl: use pci_find_next_dvsec_capability() to simplify the code Xiongfeng Wang 1 sibling, 2 replies; 6+ messages in thread From: Xiongfeng Wang @ 2023-08-07 3:18 UTC (permalink / raw) To: bhelgaas, fbarrat, ajd, mpe, npiggin, christophe.leroy, arnd, gregkh, ben.widawsky, wangxiongfeng2 Cc: jonathan.cameron, linux-pci, linuxppc-dev, yangyingliang 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. Signed-off-by: Xiongfeng Wang <wangxiongfeng2@huawei.com> --- 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) * @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. + * 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 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] PCI: Add pci_find_next_dvsec_capability to find next designated VSEC 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 1 sibling, 0 replies; 6+ messages in thread From: Andrew Donnellan @ 2023-08-07 4:24 UTC (permalink / raw) To: Xiongfeng Wang, bhelgaas, fbarrat, mpe, npiggin, christophe.leroy, arnd, gregkh, ben.widawsky Cc: jonathan.cameron, linux-pci, linuxppc-dev, yangyingliang On Mon, 2023-08-07 at 11:18 +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. > > Signed-off-by: Xiongfeng Wang <wangxiongfeng2@huawei.com> > Reviewed-by: Andrew Donnellan <ajd@linux.ibm.com> > --- > 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) > * @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. > + * 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); > -- Andrew Donnellan OzLabs, ADL Canberra ajd@linux.ibm.com IBM Australia Limited ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] PCI: Add pci_find_next_dvsec_capability to find next designated VSEC 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 1 sibling, 0 replies; 6+ messages in thread From: Bjorn Helgaas @ 2023-08-07 20:33 UTC (permalink / raw) To: Xiongfeng Wang Cc: bhelgaas, fbarrat, ajd, mpe, npiggin, christophe.leroy, arnd, gregkh, ben.widawsky, linux-pci, yangyingliang, linuxppc-dev, jonathan.cameron, David E. Box [+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 > ^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 2/2] ocxl: use pci_find_next_dvsec_capability() to simplify the code 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 3:18 ` Xiongfeng Wang 2023-08-07 4:54 ` Andrew Donnellan 1 sibling, 1 reply; 6+ messages in thread From: Xiongfeng Wang @ 2023-08-07 3:18 UTC (permalink / raw) To: bhelgaas, fbarrat, ajd, mpe, npiggin, christophe.leroy, arnd, gregkh, ben.widawsky, wangxiongfeng2 Cc: jonathan.cameron, linux-pci, linuxppc-dev, yangyingliang PCI core add pci_find_next_dvsec_capability() to query the next DVSEC. We can use that core API to simplify the code. Also remove the unused macros. Signed-off-by: Xiongfeng Wang <wangxiongfeng2@huawei.com> --- arch/powerpc/platforms/powernv/ocxl.c | 20 ++------------------ drivers/misc/ocxl/config.c | 21 ++++++--------------- include/misc/ocxl-config.h | 4 ---- 3 files changed, 8 insertions(+), 37 deletions(-) diff --git a/arch/powerpc/platforms/powernv/ocxl.c b/arch/powerpc/platforms/powernv/ocxl.c index 629067781cec..8dbc1a9535fc 100644 --- a/arch/powerpc/platforms/powernv/ocxl.c +++ b/arch/powerpc/platforms/powernv/ocxl.c @@ -71,29 +71,13 @@ static DEFINE_MUTEX(links_list_lock); * the AFUs, by pro-rating if needed. */ -static int find_dvsec_from_pos(struct pci_dev *dev, int dvsec_id, int pos) -{ - int vsec = pos; - u16 vendor, id; - - while ((vsec = pci_find_next_ext_capability(dev, vsec, - OCXL_EXT_CAP_ID_DVSEC))) { - pci_read_config_word(dev, vsec + OCXL_DVSEC_VENDOR_OFFSET, - &vendor); - pci_read_config_word(dev, vsec + OCXL_DVSEC_ID_OFFSET, &id); - if (vendor == PCI_VENDOR_ID_IBM && id == dvsec_id) - return vsec; - } - return 0; -} - static int find_dvsec_afu_ctrl(struct pci_dev *dev, u8 afu_idx) { int vsec = 0; u8 idx; - while ((vsec = find_dvsec_from_pos(dev, OCXL_DVSEC_AFU_CTRL_ID, - vsec))) { + while ((vsec = pci_find_next_dvsec_capability(dev, vsec, + PCI_VENDOR_ID_IBM, OCXL_DVSEC_AFU_CTRL_ID))) { pci_read_config_byte(dev, vsec + OCXL_DVSEC_AFU_CTRL_AFU_IDX, &idx); if (idx == afu_idx) diff --git a/drivers/misc/ocxl/config.c b/drivers/misc/ocxl/config.c index 92ab49705f64..6c0fca32e6db 100644 --- a/drivers/misc/ocxl/config.c +++ b/drivers/misc/ocxl/config.c @@ -39,23 +39,14 @@ static int find_dvsec(struct pci_dev *dev, int dvsec_id) static int find_dvsec_afu_ctrl(struct pci_dev *dev, u8 afu_idx) { int vsec = 0; - u16 vendor, id; u8 idx; - while ((vsec = pci_find_next_ext_capability(dev, vsec, - OCXL_EXT_CAP_ID_DVSEC))) { - pci_read_config_word(dev, vsec + OCXL_DVSEC_VENDOR_OFFSET, - &vendor); - pci_read_config_word(dev, vsec + OCXL_DVSEC_ID_OFFSET, &id); - - if (vendor == PCI_VENDOR_ID_IBM && - id == OCXL_DVSEC_AFU_CTRL_ID) { - pci_read_config_byte(dev, - vsec + OCXL_DVSEC_AFU_CTRL_AFU_IDX, - &idx); - if (idx == afu_idx) - return vsec; - } + while ((vsec = pci_find_next_dvsec_capability(dev, vsec, + PCI_VENDOR_ID_IBM, OCXL_DVSEC_AFU_CTRL_ID))) { + pci_read_config_byte(dev, vsec + OCXL_DVSEC_AFU_CTRL_AFU_IDX, + &idx); + if (idx == afu_idx) + return vsec; } return 0; } diff --git a/include/misc/ocxl-config.h b/include/misc/ocxl-config.h index ccfd3b463517..40cf1b143170 100644 --- a/include/misc/ocxl-config.h +++ b/include/misc/ocxl-config.h @@ -10,10 +10,6 @@ * It follows the specification for opencapi 3.0 */ -#define OCXL_EXT_CAP_ID_DVSEC 0x23 - -#define OCXL_DVSEC_VENDOR_OFFSET 0x4 -#define OCXL_DVSEC_ID_OFFSET 0x8 #define OCXL_DVSEC_TL_ID 0xF000 #define OCXL_DVSEC_TL_BACKOFF_TIMERS 0x10 #define OCXL_DVSEC_TL_RECV_CAP 0x18 -- 2.20.1 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 2/2] ocxl: use pci_find_next_dvsec_capability() to simplify the code 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 0 siblings, 0 replies; 6+ messages in thread From: Andrew Donnellan @ 2023-08-07 4:54 UTC (permalink / raw) To: Xiongfeng Wang, bhelgaas, fbarrat, mpe, npiggin, christophe.leroy, arnd, gregkh, ben.widawsky Cc: jonathan.cameron, linux-pci, linuxppc-dev, yangyingliang On Mon, 2023-08-07 at 11:18 +0800, Xiongfeng Wang wrote: > PCI core add pci_find_next_dvsec_capability() to query the next > DVSEC. > We can use that core API to simplify the code. Also remove the unused > macros. > > Signed-off-by: Xiongfeng Wang <wangxiongfeng2@huawei.com> Reviewed-by: Andrew Donnellan <ajd@linux.ibm.com> -- Andrew Donnellan OzLabs, ADL Canberra ajd@linux.ibm.com IBM Australia Limited ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2023-08-07 20:33 UTC | newest] Thread overview: 6+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 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 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
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).