From: Xiongfeng Wang <wangxiongfeng2@huawei.com>
To: <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>,
<wangxiongfeng2@huawei.com>
Cc: <jonathan.cameron@huawei.com>, <linux-pci@vger.kernel.org>,
<linuxppc-dev@lists.ozlabs.org>, <yangyingliang@huawei.com>
Subject: [PATCH 2/2] ocxl: use pci_find_next_dvsec_capability() to simplify the code
Date: Mon, 7 Aug 2023 11:18:46 +0800 [thread overview]
Message-ID: <20230807031846.77348-3-wangxiongfeng2@huawei.com> (raw)
In-Reply-To: <20230807031846.77348-1-wangxiongfeng2@huawei.com>
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
WARNING: multiple messages have this Message-ID (diff)
From: Xiongfeng Wang <wangxiongfeng2@huawei.com>
To: <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>,
<wangxiongfeng2@huawei.com>
Cc: linux-pci@vger.kernel.org, yangyingliang@huawei.com,
linuxppc-dev@lists.ozlabs.org, jonathan.cameron@huawei.com
Subject: [PATCH 2/2] ocxl: use pci_find_next_dvsec_capability() to simplify the code
Date: Mon, 7 Aug 2023 11:18:46 +0800 [thread overview]
Message-ID: <20230807031846.77348-3-wangxiongfeng2@huawei.com> (raw)
In-Reply-To: <20230807031846.77348-1-wangxiongfeng2@huawei.com>
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
next prev parent reply other threads:[~2023-08-07 3:06 UTC|newest]
Thread overview: 12+ 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 ` 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:24 ` Andrew Donnellan
2023-08-07 4:24 ` Andrew Donnellan
2023-08-07 20:33 ` Bjorn Helgaas
2023-08-07 20:33 ` Bjorn Helgaas
2023-08-07 3:18 ` Xiongfeng Wang [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
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=20230807031846.77348-3-wangxiongfeng2@huawei.com \
--to=wangxiongfeng2@huawei.com \
--cc=ajd@linux.ibm.com \
--cc=arnd@arndb.de \
--cc=ben.widawsky@intel.com \
--cc=bhelgaas@google.com \
--cc=christophe.leroy@csgroup.eu \
--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=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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.