From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id F03D9A052A; Tue, 26 Jan 2021 11:18:40 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 95432141356; Tue, 26 Jan 2021 11:17:27 +0100 (CET) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mails.dpdk.org (Postfix) with ESMTP id 50EBD14134E for ; Tue, 26 Jan 2021 11:17:24 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611656243; 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=2EEMxnPu4CmVXaQvmn6+VIdnlZ1EewsBhaAfm/45iBg=; b=PTlwKW88HksJxdZ6VKUTdx3u4zv8XuaJyu0gPOvLqoC2aBDcfEiQNI/5toynJJYDLDITFM KgX2732R7wDRtz6OSU0h48eYSoir1HZp6cM7QTZAHuxy3PCR/OtYDrV5wO4V03iWh5YcQk mliL0AWun13RAk9vTWSy0uP1H513H8o= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-563-tlNtBUo8MP6-X6cg7IHDSg-1; Tue, 26 Jan 2021 05:17:20 -0500 X-MC-Unique: tlNtBUo8MP6-X6cg7IHDSg-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 751DA18C8C02; Tue, 26 Jan 2021 10:17:19 +0000 (UTC) Received: from max-t490s.redhat.com (unknown [10.36.110.31]) by smtp.corp.redhat.com (Postfix) with ESMTP id 06E9A710DC; Tue, 26 Jan 2021 10:17:17 +0000 (UTC) From: Maxime Coquelin To: dev@dpdk.org, chenbo.xia@intel.com, olivier.matz@6wind.com, amorenoz@redhat.com, david.marchand@redhat.com Cc: Maxime Coquelin Date: Tue, 26 Jan 2021 11:16:06 +0100 Message-Id: <20210126101639.250481-12-maxime.coquelin@redhat.com> In-Reply-To: <20210126101639.250481-1-maxime.coquelin@redhat.com> References: <20210126101639.250481-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=maxime.coquelin@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII" Subject: [dpdk-dev] [PATCH v4 11/44] net/virtio: store PCI type in Virtio device metadata 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 Sender: "dev" Going further in making the Virtio ethdev layer bus agnostic, this patch adds a boolean in the Virtio PCI device metadata. Signed-off-by: Maxime Coquelin Reviewed-by: Chenbo Xia Reviewed-by: David Marchand --- drivers/net/virtio/virtio_pci.c | 18 +++++++++++------- drivers/net/virtio/virtio_pci.h | 3 ++- drivers/net/virtio/virtio_pci_ethdev.c | 12 +++++++----- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/drivers/net/virtio/virtio_pci.c b/drivers/net/virtio/virtio_pci.c index 556be1e3da..6d9c712fd5 100644 --- a/drivers/net/virtio/virtio_pci.c +++ b/drivers/net/virtio/virtio_pci.c @@ -751,8 +751,10 @@ virtio_read_caps(struct rte_pci_device *dev, struct virtio_hw *hw) * Return 0 on success. */ int -vtpci_init(struct rte_pci_device *dev, struct virtio_hw *hw) +vtpci_init(struct rte_pci_device *pci_dev, struct virtio_pci_dev *dev) { + struct virtio_hw *hw = &dev->hw; + RTE_BUILD_BUG_ON(offsetof(struct virtio_pci_dev, hw) != 0); /* @@ -760,19 +762,20 @@ vtpci_init(struct rte_pci_device *dev, struct virtio_hw *hw) * only on modern pci device. If failed, we fallback to legacy * virtio handling. */ - if (virtio_read_caps(dev, hw) == 0) { + if (virtio_read_caps(pci_dev, hw) == 0) { PMD_INIT_LOG(INFO, "modern virtio pci detected."); virtio_hw_internal[hw->port_id].vtpci_ops = &modern_ops; hw->bus_type = VIRTIO_BUS_PCI_MODERN; + dev->modern = true; goto msix_detect; } PMD_INIT_LOG(INFO, "trying with legacy virtio pci."); - if (rte_pci_ioport_map(dev, 0, VTPCI_IO(hw)) < 0) { - rte_pci_unmap_device(dev); - if (dev->kdrv == RTE_PCI_KDRV_UNKNOWN && - (!dev->device.devargs || - dev->device.devargs->bus != + if (rte_pci_ioport_map(pci_dev, 0, VTPCI_IO(hw)) < 0) { + rte_pci_unmap_device(pci_dev); + if (pci_dev->kdrv == RTE_PCI_KDRV_UNKNOWN && + (!pci_dev->device.devargs || + pci_dev->device.devargs->bus != rte_bus_find_by_name("pci"))) { PMD_INIT_LOG(INFO, "skip kernel managed virtio device."); @@ -783,6 +786,7 @@ vtpci_init(struct rte_pci_device *dev, struct virtio_hw *hw) virtio_hw_internal[hw->port_id].vtpci_ops = &legacy_ops; hw->bus_type = VIRTIO_BUS_PCI_LEGACY; + dev->modern = false; msix_detect: VTPCI_OPS(hw)->intr_detect(hw); diff --git a/drivers/net/virtio/virtio_pci.h b/drivers/net/virtio/virtio_pci.h index b29bbb8074..4c22692414 100644 --- a/drivers/net/virtio/virtio_pci.h +++ b/drivers/net/virtio/virtio_pci.h @@ -292,6 +292,7 @@ struct virtio_hw { struct virtio_pci_dev { struct virtio_hw hw; + bool modern; }; #define virtio_pci_get_dev(hwp) container_of(hwp, struct virtio_pci_dev, hw) @@ -371,7 +372,7 @@ vtpci_packed_queue(struct virtio_hw *hw) /* * Function declaration from virtio_pci.c */ -int vtpci_init(struct rte_pci_device *dev, struct virtio_hw *hw); +int vtpci_init(struct rte_pci_device *pci_dev, struct virtio_pci_dev *dev); void vtpci_reset(struct virtio_hw *); void vtpci_reinit_complete(struct virtio_hw *); diff --git a/drivers/net/virtio/virtio_pci_ethdev.c b/drivers/net/virtio/virtio_pci_ethdev.c index 045b134ef2..076a5dbced 100644 --- a/drivers/net/virtio/virtio_pci_ethdev.c +++ b/drivers/net/virtio/virtio_pci_ethdev.c @@ -39,9 +39,11 @@ static const struct rte_pci_id pci_id_virtio_map[] = { * could have the PCI initiated correctly. */ static int -virtio_remap_pci(struct rte_pci_device *pci_dev, struct virtio_hw *hw) +virtio_remap_pci(struct rte_pci_device *pci_dev, struct virtio_pci_dev *dev) { - if (hw->bus_type == VIRTIO_BUS_PCI_MODERN) { + struct virtio_hw *hw = &dev->hw; + + if (dev->modern) { /* * We don't have to re-parse the PCI config space, since * rte_pci_map_device() makes sure the mapped address @@ -57,7 +59,7 @@ virtio_remap_pci(struct rte_pci_device *pci_dev, struct virtio_hw *hw) PMD_INIT_LOG(DEBUG, "failed to map pci device!"); return -1; } - } else if (hw->bus_type == VIRTIO_BUS_PCI_LEGACY) { + } else { if (rte_pci_ioport_map(pci_dev, 0, VTPCI_IO(hw)) < 0) return -1; } @@ -76,13 +78,13 @@ eth_virtio_pci_init(struct rte_eth_dev *eth_dev) VTPCI_DEV(hw) = pci_dev; if (rte_eal_process_type() == RTE_PROC_PRIMARY) { - ret = vtpci_init(RTE_ETH_DEV_TO_PCI(eth_dev), hw); + ret = vtpci_init(RTE_ETH_DEV_TO_PCI(eth_dev), dev); if (ret) { PMD_INIT_LOG(ERR, "Failed to init PCI device\n"); return -1; } } else { - ret = virtio_remap_pci(RTE_ETH_DEV_TO_PCI(eth_dev), hw); + ret = virtio_remap_pci(RTE_ETH_DEV_TO_PCI(eth_dev), dev); if (ret < 0) { PMD_INIT_LOG(ERR, "Failed to remap PCI device\n"); return -1; -- 2.29.2