# \[PATCH 7/7\] ocxl: Use pci core's DVSEC functionality

- Subsystems: OCXL (Open Coherent Accelerator Processor Interface OpenCAPI) DRIVER, CHAR and MISC DRIVERS, THE REST
- Maintainers: Mahesh J Salgaonkar, Arnd Bergmann, Greg Kroah-Hartman, Linus Torvalds
- Status: SUPERSEDED (Superseded by v2 posted 2021-09-23)
- Superseded by v2 (posted 2021-09-23).
- Revision v1 (2 revisions archived).
- List: linuxppc-dev
- 3 messages, 3 authors
- Page: https://ratatoskr.run/linuxppc-dev/2021/09/9524461/t

## \[PATCH 7/7\] ocxl: Use pci core's DVSEC functionality

- From: Ben Widawsky \<hidden\>
- Date: 2021-09-21 22:32:00 
- Message: https://ratatoskr.run/linuxppc-dev/2021/09/9524461.md

```text
Reduce maintenance burden of DVSEC query implementation by using the
centralized PCI core implementation.

Cc: <redacted>
Cc: Frederic Barrat <redacted>
Cc: Andrew Donnellan <redacted>
Signed-off-by: Ben Widawsky <redacted>
---
 drivers/misc/ocxl/config.c | 13 +------------
 1 file changed, 1 insertion(+), 12 deletions(-)

diff --git a/drivers/misc/ocxl/config.c b/drivers/misc/ocxl/config.c
index a68738f38252..e401a51596b9 100644
--- a/drivers/misc/ocxl/config.c
+++ b/drivers/misc/ocxl/config.c
@@ -33,18 +33,7 @@
 
 static int find_dvsec(struct pci_dev *dev, int dvsec_id)
 {
-	int vsec = 0;
-	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;
+	return pci_find_dvsec_capability(dev, PCI_VENDOR_ID_IBM, dvsec_id);
 }
 
 static int find_dvsec_afu_ctrl(struct pci_dev *dev, u8 afu_idx)
-- 
2.33.0

```

## Re: \[PATCH 7/7\] ocxl: Use pci core's DVSEC functionality

- From: Dan Williams \<hidden\>
- Date: 2021-09-22 00:46:02 
- Message: https://ratatoskr.run/linuxppc-dev/2021/09/9524462.md

```text
On Tue, Sep 21, 2021 at 3:05 PM Ben Widawsky [ref] wrote:
>
> Reduce maintenance burden of DVSEC query implementation by using the
> centralized PCI core implementation.
>
> Cc: <redacted>
> Cc: Frederic Barrat <redacted>
> Cc: Andrew Donnellan <redacted>
> Signed-off-by: Ben Widawsky <redacted>
> ---
>  drivers/misc/ocxl/config.c | 13 +------------
>  1 file changed, 1 insertion(+), 12 deletions(-)
>
> diff --git a/drivers/misc/ocxl/config.c b/drivers/misc/ocxl/config.c
> index a68738f38252..e401a51596b9 100644
> --- a/drivers/misc/ocxl/config.c
> +++ b/drivers/misc/ocxl/config.c
> @@ -33,18 +33,7 @@
>
>  static int find_dvsec(struct pci_dev *dev, int dvsec_id)
>  {
> -       int vsec = 0;
> -       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;
> +       return pci_find_dvsec_capability(dev, PCI_VENDOR_ID_IBM, dvsec_id);
>  }

What about:

arch/powerpc/platforms/powernv/ocxl.c::find_dvsec_from_pos()

...?  With that converted the redundant definitions below:

OCXL_EXT_CAP_ID_DVSEC
OCXL_DVSEC_VENDOR_OFFSET
OCXL_DVSEC_ID_OFFSET

...can be cleaned up in favor of the core definitions.
```

## Re: \[PATCH 7/7\] ocxl: Use pci core's DVSEC functionality

- From: Frederic Barrat \<hidden\>
- Date: 2021-09-22 09:39:36 
- Message: https://ratatoskr.run/linuxppc-dev/2021/09/9524468.md

```text


On 22/09/2021 02:44, Dan Williams wrote:
> On Tue, Sep 21, 2021 at 3:05 PM Ben Widawsky [ref] wrote:
>>
>> Reduce maintenance burden of DVSEC query implementation by using the
>> centralized PCI core implementation.
>>
>> Cc: <redacted>
>> Cc: Frederic Barrat <redacted>
>> Cc: Andrew Donnellan <redacted>
>> Signed-off-by: Ben Widawsky <redacted>
>> ---
>>   drivers/misc/ocxl/config.c | 13 +------------
>>   1 file changed, 1 insertion(+), 12 deletions(-)
>>
>> diff --git a/drivers/misc/ocxl/config.c b/drivers/misc/ocxl/config.c
>> index a68738f38252..e401a51596b9 100644
>> --- a/drivers/misc/ocxl/config.c
>> +++ b/drivers/misc/ocxl/config.c
>> @@ -33,18 +33,7 @@
>>
>>   static int find_dvsec(struct pci_dev *dev, int dvsec_id)
>>   {
>> -       int vsec = 0;
>> -       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;
>> +       return pci_find_dvsec_capability(dev, PCI_VENDOR_ID_IBM, dvsec_id);
>>   }


That looks fine, thanks for spotting it. You can add this for the next revision:
Acked-by: Frederic Barrat <redacted>



>
> What about:
>
> arch/powerpc/platforms/powernv/ocxl.c::find_dvsec_from_pos()
>
> ...?  With that converted the redundant definitions below:
>
> OCXL_EXT_CAP_ID_DVSEC
> OCXL_DVSEC_VENDOR_OFFSET
> OCXL_DVSEC_ID_OFFSET
>
> ...can be cleaned up in favor of the core definitions.


That would be great. Are you guys willing to do it? If not, I could have a follow-on patch, if I don't forget :-)

Thanks,

  Fred

```
