DPDK patches and discussions
 help / color / mirror / Atom feed
From: David Marchand <david.marchand@redhat.com>
To: dev@dpdk.org
Cc: thomas@monjalon.net, ferruh.yigit@amd.com, chenbo.xia@intel.com,
	nipun.gupta@amd.com, Anatoly Burakov <anatoly.burakov@intel.com>,
	Dongdong Liu <liudongdong3@huawei.com>,
	Yisen Zhuang <yisen.zhuang@huawei.com>,
	Jiawen Wu <jiawenwu@trustnetic.com>
Subject: [PATCH 01/14] drivers: remove duplicated PCI master control
Date: Thu,  3 Aug 2023 09:50:24 +0200	[thread overview]
Message-ID: <20230803075038.307012-2-david.marchand@redhat.com> (raw)
In-Reply-To: <20230803075038.307012-1-david.marchand@redhat.com>

Use existing API to cleanup duplicated code.

Signed-off-by: David Marchand <david.marchand@redhat.com>
---
 drivers/bus/pci/linux/pci_uio.c    | 32 +----------------------
 drivers/bus/pci/linux/pci_vfio.c   | 41 ++----------------------------
 drivers/net/hns3/hns3_ethdev_vf.c  | 25 +-----------------
 drivers/net/ngbe/base/ngbe_hw.c    | 20 ++-------------
 drivers/net/ngbe/base/ngbe_osdep.h |  3 ---
 5 files changed, 6 insertions(+), 115 deletions(-)

diff --git a/drivers/bus/pci/linux/pci_uio.c b/drivers/bus/pci/linux/pci_uio.c
index 2bf16e9369..97d740dfe5 100644
--- a/drivers/bus/pci/linux/pci_uio.c
+++ b/drivers/bus/pci/linux/pci_uio.c
@@ -10,7 +10,6 @@
 #include <sys/stat.h>
 #include <sys/mman.h>
 #include <sys/sysmacros.h>
-#include <linux/pci_regs.h>
 
 #if defined(RTE_ARCH_X86)
 #include <sys/io.h>
@@ -77,35 +76,6 @@ pci_uio_mmio_write(const struct rte_pci_device *dev, int bar,
 	return len;
 }
 
-static int
-pci_uio_set_bus_master(int dev_fd)
-{
-	uint16_t reg;
-	int ret;
-
-	ret = pread(dev_fd, &reg, sizeof(reg), PCI_COMMAND);
-	if (ret != sizeof(reg)) {
-		RTE_LOG(ERR, EAL,
-			"Cannot read command from PCI config space!\n");
-		return -1;
-	}
-
-	/* return if bus mastering is already on */
-	if (reg & PCI_COMMAND_MASTER)
-		return 0;
-
-	reg |= PCI_COMMAND_MASTER;
-
-	ret = pwrite(dev_fd, &reg, sizeof(reg), PCI_COMMAND);
-	if (ret != sizeof(reg)) {
-		RTE_LOG(ERR, EAL,
-			"Cannot write command to PCI config space!\n");
-		return -1;
-	}
-
-	return 0;
-}
-
 static int
 pci_mknod_uio_dev(const char *sysfs_uio_path, unsigned uio_num)
 {
@@ -299,7 +269,7 @@ pci_uio_alloc_resource(struct rte_pci_device *dev,
 			goto error;
 
 		/* set bus master that is not done by uio_pci_generic */
-		if (pci_uio_set_bus_master(uio_cfg_fd)) {
+		if (rte_pci_set_bus_master(dev, true)) {
 			RTE_LOG(ERR, EAL, "Cannot set up bus mastering!\n");
 			goto error;
 		}
diff --git a/drivers/bus/pci/linux/pci_vfio.c b/drivers/bus/pci/linux/pci_vfio.c
index e634de8322..8fa7fa458f 100644
--- a/drivers/bus/pci/linux/pci_vfio.c
+++ b/drivers/bus/pci/linux/pci_vfio.c
@@ -223,42 +223,6 @@ pci_vfio_enable_bus_memory(struct rte_pci_device *dev, int dev_fd)
 	return 0;
 }
 
-/* set PCI bus mastering */
-static int
-pci_vfio_set_bus_master(const struct rte_pci_device *dev, int dev_fd, bool op)
-{
-	uint64_t size, offset;
-	uint16_t reg;
-	int ret;
-
-	if (pci_vfio_get_region(dev, VFIO_PCI_CONFIG_REGION_INDEX,
-		&size, &offset) != 0) {
-		RTE_LOG(ERR, EAL, "Cannot get offset of CONFIG region.\n");
-		return -1;
-	}
-
-	ret = pread64(dev_fd, &reg, sizeof(reg), offset + PCI_COMMAND);
-	if (ret != sizeof(reg)) {
-		RTE_LOG(ERR, EAL, "Cannot read command from PCI config space!\n");
-		return -1;
-	}
-
-	if (op)
-		/* set the master bit */
-		reg |= PCI_COMMAND_MASTER;
-	else
-		reg &= ~(PCI_COMMAND_MASTER);
-
-	ret = pwrite64(dev_fd, &reg, sizeof(reg), offset + PCI_COMMAND);
-
-	if (ret != sizeof(reg)) {
-		RTE_LOG(ERR, EAL, "Cannot write command to PCI config space!\n");
-		return -1;
-	}
-
-	return 0;
-}
-
 /* set up interrupt support (but not enable interrupts) */
 static int
 pci_vfio_setup_interrupts(struct rte_pci_device *dev, int vfio_dev_fd)
@@ -535,8 +499,7 @@ pci_rte_vfio_setup_device(struct rte_pci_device *dev, int vfio_dev_fd)
 		return -1;
 	}
 
-	/* set bus mastering for the device */
-	if (pci_vfio_set_bus_master(dev, vfio_dev_fd, true)) {
+	if (rte_pci_set_bus_master(dev, true)) {
 		RTE_LOG(ERR, EAL, "Cannot set up bus mastering!\n");
 		return -1;
 	}
@@ -1226,7 +1189,7 @@ pci_vfio_unmap_resource_primary(struct rte_pci_device *dev)
 	if (vfio_dev_fd < 0)
 		return -1;
 
-	if (pci_vfio_set_bus_master(dev, vfio_dev_fd, false)) {
+	if (rte_pci_set_bus_master(dev, false)) {
 		RTE_LOG(ERR, EAL, "%s cannot unset bus mastering for PCI device!\n",
 				pci_addr);
 		return -1;
diff --git a/drivers/net/hns3/hns3_ethdev_vf.c b/drivers/net/hns3/hns3_ethdev_vf.c
index 5aac62a41f..7b3c5dc168 100644
--- a/drivers/net/hns3/hns3_ethdev_vf.c
+++ b/drivers/net/hns3/hns3_ethdev_vf.c
@@ -49,29 +49,6 @@ static int hns3vf_remove_mc_mac_addr(struct hns3_hw *hw,
 static int hns3vf_dev_link_update(struct rte_eth_dev *eth_dev,
 				   __rte_unused int wait_to_complete);
 
-/* set PCI bus mastering */
-static int
-hns3vf_set_bus_master(const struct rte_pci_device *device, bool op)
-{
-	uint16_t reg;
-	int ret;
-
-	ret = rte_pci_read_config(device, &reg, sizeof(reg), PCI_COMMAND);
-	if (ret < 0) {
-		PMD_INIT_LOG(ERR, "Failed to read PCI offset 0x%x",
-			     PCI_COMMAND);
-		return ret;
-	}
-
-	if (op)
-		/* set the master bit */
-		reg |= PCI_COMMAND_MASTER;
-	else
-		reg &= ~(PCI_COMMAND_MASTER);
-
-	return rte_pci_write_config(device, &reg, sizeof(reg), PCI_COMMAND);
-}
-
 /**
  * hns3vf_find_pci_capability - lookup a capability in the PCI capability list
  * @cap: the capability
@@ -2140,7 +2117,7 @@ hns3vf_reinit_dev(struct hns3_adapter *hns)
 
 	if (hw->reset.level == HNS3_VF_FULL_RESET) {
 		rte_intr_disable(pci_dev->intr_handle);
-		ret = hns3vf_set_bus_master(pci_dev, true);
+		ret = rte_pci_set_bus_master(pci_dev, true);
 		if (ret < 0) {
 			hns3_err(hw, "failed to set pci bus, ret = %d", ret);
 			return ret;
diff --git a/drivers/net/ngbe/base/ngbe_hw.c b/drivers/net/ngbe/base/ngbe_hw.c
index 27243d85c8..22ccdb0b7d 100644
--- a/drivers/net/ngbe/base/ngbe_hw.c
+++ b/drivers/net/ngbe/base/ngbe_hw.c
@@ -1061,26 +1061,10 @@ s32 ngbe_set_pcie_master(struct ngbe_hw *hw, bool enable)
 {
 	struct rte_pci_device *pci_dev = (struct rte_pci_device *)hw->back;
 	s32 status = 0;
-	s32 ret = 0;
 	u32 i;
-	u16 reg;
 
-	ret = rte_pci_read_config(pci_dev, &reg,
-			sizeof(reg), PCI_COMMAND);
-	if (ret != sizeof(reg)) {
-		DEBUGOUT("Cannot read command from PCI config space!\n");
-		return -1;
-	}
-
-	if (enable)
-		reg |= PCI_COMMAND_MASTER;
-	else
-		reg &= ~PCI_COMMAND_MASTER;
-
-	ret = rte_pci_write_config(pci_dev, &reg,
-			sizeof(reg), PCI_COMMAND);
-	if (ret != sizeof(reg)) {
-		DEBUGOUT("Cannot write command to PCI config space!\n");
+	if (rte_pci_set_bus_master(pci_dev, enable) < 0) {
+		DEBUGOUT("Cannot configure PCI bus master\n");
 		return -1;
 	}
 
diff --git a/drivers/net/ngbe/base/ngbe_osdep.h b/drivers/net/ngbe/base/ngbe_osdep.h
index 8783fce4dd..30598a240a 100644
--- a/drivers/net/ngbe/base/ngbe_osdep.h
+++ b/drivers/net/ngbe/base/ngbe_osdep.h
@@ -181,7 +181,4 @@ static inline u64 REVERT_BIT_MASK64(u64 mask)
 #define ETH_P_8021Q      0x8100
 #define ETH_P_8021AD     0x88A8
 
-#define PCI_COMMAND		0x04
-#define  PCI_COMMAND_MASTER	0x4
-
 #endif /* _NGBE_OS_H_ */
-- 
2.41.0


  reply	other threads:[~2023-08-03  7:50 UTC|newest]

Thread overview: 98+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-03  7:50 [PATCH 00/14] Cleanup PCI(e) drivers David Marchand
2023-08-03  7:50 ` David Marchand [this message]
2023-08-03  9:45   ` [PATCH 01/14] drivers: remove duplicated PCI master control Bruce Richardson
2023-10-07  2:53   ` fengchengwen
2023-08-03  7:50 ` [PATCH 02/14] bus/pci: add const to some experimental API David Marchand
2023-08-03  9:46   ` Bruce Richardson
2023-08-03 11:50     ` David Marchand
2023-08-03  7:50 ` [PATCH 03/14] bus/pci: find PCI capability David Marchand
2023-08-03  9:49   ` Bruce Richardson
2023-08-03  9:52     ` Bruce Richardson
2023-08-03 11:49       ` David Marchand
2023-08-03  7:50 ` [PATCH 04/14] pci: define some capability constants David Marchand
2023-08-03  9:51   ` Bruce Richardson
2023-08-03  7:50 ` [PATCH 05/14] pci: define some MSIX constants David Marchand
2023-08-03  9:53   ` Bruce Richardson
2023-08-03  7:50 ` [PATCH 06/14] pci: define some command constants David Marchand
2023-08-03  9:57   ` Bruce Richardson
2023-08-03 11:51     ` David Marchand
2023-08-08  9:20       ` David Marchand
2023-08-08 10:08         ` Bruce Richardson
2023-08-22 19:23   ` Adam Hassick
2023-08-03  7:50 ` [PATCH 07/14] pci: define some BAR constants David Marchand
2023-08-03  9:58   ` Bruce Richardson
2023-08-03  7:50 ` [PATCH 08/14] pci: define some PM constants David Marchand
2023-08-03  9:59   ` Bruce Richardson
2023-08-03  7:50 ` [PATCH 09/14] pci: define some PCIe constants David Marchand
2023-08-03 10:01   ` Bruce Richardson
2023-08-03  7:50 ` [PATCH 10/14] pci: define some extended capability constants David Marchand
2023-08-03  7:50 ` [PATCH 11/14] pci: define some ACS constants David Marchand
2023-08-03  7:50 ` [PATCH 12/14] pci: define some PRI constants David Marchand
2023-08-03  7:50 ` [PATCH 13/14] pci: define some AER constants David Marchand
2023-08-03  7:50 ` [PATCH 14/14] devtools: forbid inclusion of Linux header for PCI David Marchand
2023-08-03 10:03 ` [PATCH 00/14] Cleanup PCI(e) drivers Bruce Richardson
2023-08-21 11:35 ` [PATCH v2 00/15] " David Marchand
2023-08-21 11:35   ` [PATCH v2 01/15] drivers: remove duplicated PCI master control David Marchand
2023-09-06 13:02     ` Xia, Chenbo
2023-08-21 11:35   ` [PATCH v2 02/15] bus/pci: add const to some experimental API David Marchand
2023-08-21 16:14     ` Tyler Retzlaff
2023-09-06 13:02     ` Xia, Chenbo
2023-08-21 11:35   ` [PATCH v2 03/15] bus/pci: rework MSIX discovery with VFIO David Marchand
2023-09-06 13:03     ` Xia, Chenbo
2023-08-21 11:35   ` [PATCH v2 04/15] bus/pci: find PCI capability David Marchand
2023-09-07 12:43     ` Xia, Chenbo
2023-09-14 12:29       ` David Marchand
2023-09-19  2:19         ` Xia, Chenbo
2023-09-19  9:00           ` David Marchand
2023-08-21 11:35   ` [PATCH v2 05/15] pci: define some capability constants David Marchand
2023-09-07 13:15     ` Xia, Chenbo
2023-08-21 11:35   ` [PATCH v2 06/15] pci: define some MSIX constants David Marchand
2023-09-07 13:15     ` Xia, Chenbo
2023-08-21 11:35   ` [PATCH v2 07/15] pci: define some command constants David Marchand
2023-09-07 13:15     ` Xia, Chenbo
2023-08-21 11:35   ` [PATCH v2 08/15] pci: define some BAR constants David Marchand
2023-09-07 13:16     ` Xia, Chenbo
2023-08-21 11:35   ` [PATCH v2 09/15] pci: define some PM constants David Marchand
2023-09-07 13:16     ` Xia, Chenbo
2023-08-21 11:35   ` [PATCH v2 10/15] pci: define some PCIe constants David Marchand
2023-09-07 13:16     ` Xia, Chenbo
2023-08-21 11:35   ` [PATCH v2 11/15] pci: define some extended capability constants David Marchand
2023-09-07 13:23     ` Xia, Chenbo
2023-08-21 11:35   ` [PATCH v2 12/15] pci: define some ACS constants David Marchand
2023-08-21 11:35   ` [PATCH v2 13/15] pci: define some PRI constants David Marchand
2023-08-21 11:35   ` [PATCH v2 14/15] pci: define some AER constants David Marchand
2023-08-21 11:35   ` [PATCH v2 15/15] devtools: forbid inclusion of Linux header for PCI David Marchand
2023-08-21 16:24     ` Tyler Retzlaff
2023-09-07 13:33     ` Xia, Chenbo
2023-08-22 15:30   ` [PATCH v2 00/15] Cleanup PCI(e) drivers Patrick Robb
2023-08-22 16:09 ` [PATCH 00/14] " Adam Hassick
2023-08-22 16:48 ` Adam Hassick
2023-08-24 15:44 ` Adam Hassick
2023-09-14 12:35 ` [PATCH v3 00/15] " David Marchand
2023-09-14 12:36   ` [PATCH v3 01/15] drivers: remove duplicated PCI master control David Marchand
2023-09-14 12:36   ` [PATCH v3 02/15] bus/pci: add const to some experimental API David Marchand
2023-09-14 12:36   ` [PATCH v3 03/15] bus/pci: rework MSIX discovery with VFIO David Marchand
2023-09-14 12:36   ` [PATCH v3 04/15] bus/pci: find PCI capability David Marchand
2023-09-19  2:33     ` Xia, Chenbo
2023-09-14 12:36   ` [PATCH v3 05/15] pci: define some capability constants David Marchand
2023-09-15 16:27     ` Sevincer, Abdullah
2023-09-14 12:36   ` [PATCH v3 06/15] pci: define some MSIX constants David Marchand
2023-09-14 12:36   ` [PATCH v3 07/15] pci: define some command constants David Marchand
2023-09-14 12:36   ` [PATCH v3 08/15] pci: define some BAR constants David Marchand
2023-09-14 12:36   ` [PATCH v3 09/15] pci: define some PM constants David Marchand
2023-09-14 12:36   ` [PATCH v3 10/15] pci: define some PCIe constants David Marchand
2023-09-15 16:26     ` Sevincer, Abdullah
2023-09-14 12:36   ` [PATCH v3 11/15] pci: define some extended capability constants David Marchand
2023-09-15 16:27     ` Sevincer, Abdullah
2023-09-14 12:36   ` [PATCH v3 12/15] pci: define some ACS constants David Marchand
2023-09-15 16:25     ` Sevincer, Abdullah
2023-09-19  2:35     ` Xia, Chenbo
2023-09-14 12:36   ` [PATCH v3 13/15] pci: define some PRI constants David Marchand
2023-09-15 16:21     ` Sevincer, Abdullah
2023-09-19  2:36     ` Xia, Chenbo
2023-09-14 12:36   ` [PATCH v3 14/15] pci: define some AER constants David Marchand
2023-09-15 16:26     ` Sevincer, Abdullah
2023-09-19  2:36     ` Xia, Chenbo
2023-09-14 12:36   ` [PATCH v3 15/15] devtools: forbid inclusion of Linux header for PCI David Marchand
2023-09-15 15:14   ` [PATCH v3 00/15] Cleanup PCI(e) drivers Stephen Hemminger
2023-09-19 12:41   ` David Marchand

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=20230803075038.307012-2-david.marchand@redhat.com \
    --to=david.marchand@redhat.com \
    --cc=anatoly.burakov@intel.com \
    --cc=chenbo.xia@intel.com \
    --cc=dev@dpdk.org \
    --cc=ferruh.yigit@amd.com \
    --cc=jiawenwu@trustnetic.com \
    --cc=liudongdong3@huawei.com \
    --cc=nipun.gupta@amd.com \
    --cc=thomas@monjalon.net \
    --cc=yisen.zhuang@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).