From patchwork Thu Aug 3 07:50:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Marchand X-Patchwork-Id: 129870 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id B391A42FC1; Thu, 3 Aug 2023 09:50:55 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 79D1243247; Thu, 3 Aug 2023 09:50:51 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mails.dpdk.org (Postfix) with ESMTP id 345C84161A for ; Thu, 3 Aug 2023 09:50:50 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1691049049; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PwgPBfu/ngL3G80AxPhpniaILDazpnVgHY2FGHpR8QY=; b=NT3Ptt83HIEKrbYpZC87Njl81n3joD8Yi4OBxvLQJ+qiowfjCfpbLYwnBG3LZa8XfUDI8F VkfivBqetQQUag0S5kL1laf4XRiIJm9wcqbg4kSwoc+4B1lHNv/+oEjuZVdLDQoixbpJIF pLDgIK9NRRkNFLsKs+T08BoIEkbT1bQ= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-558-xbwreCGgOu-JrJsFy4CLdA-1; Thu, 03 Aug 2023 03:50:48 -0400 X-MC-Unique: xbwreCGgOu-JrJsFy4CLdA-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 68E7A803FDC; Thu, 3 Aug 2023 07:50:47 +0000 (UTC) Received: from dmarchan.redhat.com (unknown [10.45.224.120]) by smtp.corp.redhat.com (Postfix) with ESMTP id 78FA64021B9; Thu, 3 Aug 2023 07:50:45 +0000 (UTC) From: David Marchand To: dev@dpdk.org Cc: thomas@monjalon.net, ferruh.yigit@amd.com, chenbo.xia@intel.com, nipun.gupta@amd.com, Anatoly Burakov , Dongdong Liu , Yisen Zhuang , Jiawen Wu Subject: [PATCH 01/14] drivers: remove duplicated PCI master control Date: Thu, 3 Aug 2023 09:50:24 +0200 Message-ID: <20230803075038.307012-2-david.marchand@redhat.com> In-Reply-To: <20230803075038.307012-1-david.marchand@redhat.com> References: <20230803075038.307012-1-david.marchand@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Use existing API to cleanup duplicated code. Signed-off-by: David Marchand Acked-by: Bruce Richardson Acked-by: Chengwen Feng --- 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 #include #include -#include #if defined(RTE_ARCH_X86) #include @@ -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, ®, 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, ®, 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, ®, 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, ®, 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, ®, 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, ®, 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, ®, - 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, ®, - 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_ */