Re: [PATCH 2/2] ocxl: use pci_find_next_dvsec_capability() to simplify the code

2023-08-06 Thread Andrew Donnellan
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 

Reviewed-by: Andrew Donnellan 


-- 
Andrew DonnellanOzLabs, ADL Canberra
a...@linux.ibm.com   IBM Australia Limited


[PATCH 2/2] ocxl: use pci_find_next_dvsec_capability() to simplify the code

2023-08-06 Thread Xiongfeng Wang
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 
---
 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,
-   );
-   pci_read_config_word(dev, vsec + OCXL_DVSEC_ID_OFFSET, );
-   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,
);
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,
-   );
-   pci_read_config_word(dev, vsec + OCXL_DVSEC_ID_OFFSET, );
-
-   if (vendor == PCI_VENDOR_ID_IBM &&
-   id == OCXL_DVSEC_AFU_CTRL_ID) {
-   pci_read_config_byte(dev,
-   vsec + OCXL_DVSEC_AFU_CTRL_AFU_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,
+);
+   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_CAP0x18
-- 
2.20.1