From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 17BB7A09FD; Sun, 20 Dec 2020 22:17:24 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 72B9DCCB9; Sun, 20 Dec 2020 22:14:58 +0100 (CET) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by dpdk.org (Postfix) with ESMTP id E1B93CCB3 for ; Sun, 20 Dec 2020 22:14:56 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1608498895; 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=sF6x6hJOhWZuYF5kD5M/pMBZt5AT9HUa+wCZwCrLzi4=; b=L24xP0vZ9dvII4SguAKTpw7/xdAwfCQ+yXlbUJcbfWpa/TYFTDUCBIVRJoCayY3JtgDLbY p5jBGw/pM83WMseoPAYGTvgOS9gzX3Md6sNiP6tt3qgjw7OECwEYQ6ooUkhEF0+nOKlQ1x /aOYrt5p2drrgeJFuTNyEavsPoyJPXI= 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-472-qjt6fj2XO4u8FQNB9U55aQ-1; Sun, 20 Dec 2020 16:14:51 -0500 X-MC-Unique: qjt6fj2XO4u8FQNB9U55aQ-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9573359; Sun, 20 Dec 2020 21:14:50 +0000 (UTC) Received: from max-t490s.redhat.com (unknown [10.36.110.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id B29BC60C43; Sun, 20 Dec 2020 21:14:48 +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: Sun, 20 Dec 2020 22:13:34 +0100 Message-Id: <20201220211405.313012-10-maxime.coquelin@redhat.com> In-Reply-To: <20201220211405.313012-1-maxime.coquelin@redhat.com> References: <20201220211405.313012-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 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 09/40] net/virtio: store PCI type in Virtio device metadata X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 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 --- drivers/net/virtio/virtio_pci.c | 20 ++++++++++++-------- drivers/net/virtio/virtio_pci.h | 3 ++- drivers/net/virtio/virtio_pci_ethdev.c | 12 +++++++----- 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/drivers/net/virtio/virtio_pci.c b/drivers/net/virtio/virtio_pci.c index 8605254e53..7f0c066968 100644 --- a/drivers/net/virtio/virtio_pci.c +++ b/drivers/net/virtio/virtio_pci.c @@ -687,26 +687,29 @@ 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; + /* * Try if we can succeed reading virtio pci caps, which exists * 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."); @@ -717,9 +720,10 @@ 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: - hw->use_msix = vtpci_msix_detect(dev); + hw->use_msix = vtpci_msix_detect(pci_dev); return 0; } diff --git a/drivers/net/virtio/virtio_pci.h b/drivers/net/virtio/virtio_pci.h index 8d3dc0e22e..3e245ed630 100644 --- a/drivers/net/virtio/virtio_pci.h +++ b/drivers/net/virtio/virtio_pci.h @@ -291,6 +291,7 @@ struct virtio_hw { struct virtio_pci_dev { struct virtio_hw hw; + bool modern; }; #define virtio_pci_get_dev(hw) container_of(hw, struct virtio_pci_dev, hw) @@ -367,7 +368,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 d6cbe582d2..f513381707 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; } @@ -74,13 +76,13 @@ eth_virtio_pci_init(struct rte_eth_dev *eth_dev) int ret; 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