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 DE28DA0A05; Tue, 19 Jan 2021 22:27:09 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id F29DC140E50; Tue, 19 Jan 2021 22:26:25 +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 B711F140E13 for ; Tue, 19 Jan 2021 22:26:24 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611091584; 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=DUxAGWLq+L232fQy8MyENZhLfGfQG8o94GA10QEYTSo=; b=S/ybiyUfECldREJjUNNiWdHpX6MJ1Z+Kdri+XaPr/unHoIDNfw7/g11BBa3xuJe1rKbMP8 t+jMdiorZpgYBDozJ9JV7KpaKe7xvCbMl27V/T4yirsKAxZ/3Nw9kKCrBtU51pUisILezh MiofNYQdy+7jCZN9+DeWFvjg4dvjX2s= 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-279-Snc8dx2qN_6Fz-ClMZhMcg-1; Tue, 19 Jan 2021 16:26:18 -0500 X-MC-Unique: Snc8dx2qN_6Fz-ClMZhMcg-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 81B2AA0CA4; Tue, 19 Jan 2021 21:26:17 +0000 (UTC) Received: from max-t490s.redhat.com (unknown [10.36.110.29]) by smtp.corp.redhat.com (Postfix) with ESMTP id E2A825D9DD; Tue, 19 Jan 2021 21:26:15 +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, 19 Jan 2021 22:24:32 +0100 Message-Id: <20210119212507.1043636-10-maxime.coquelin@redhat.com> In-Reply-To: <20210119212507.1043636-1-maxime.coquelin@redhat.com> References: <20210119212507.1043636-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 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 v2 09/44] net/virtio: move MSIX detection to PCI ethdev 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" This patch introduces a new callback to notify the bus driver some interrupt related operation was done. This is used by Virtio PCI driver to check msix status. Signed-off-by: Maxime Coquelin --- drivers/net/virtio/virtio_ethdev.c | 12 +-- drivers/net/virtio/virtio_pci.c | 120 ++++++++++++++----------- drivers/net/virtio/virtio_pci.h | 6 +- drivers/net/virtio/virtio_pci_ethdev.c | 2 + 4 files changed, 82 insertions(+), 58 deletions(-) diff --git a/drivers/net/virtio/virtio_ethdev.c b/drivers/net/virtio/virtio_ethdev.c index a3e81f336d..13d5a76376 100644 --- a/drivers/net/virtio/virtio_ethdev.c +++ b/drivers/net/virtio/virtio_ethdev.c @@ -1287,8 +1287,8 @@ virtio_intr_unmask(struct rte_eth_dev *dev) if (rte_intr_ack(dev->intr_handle) < 0) return -1; - if (hw->bus_type == VIRTIO_BUS_PCI_LEGACY || hw->bus_type == VIRTIO_BUS_PCI_MODERN) - hw->use_msix = vtpci_msix_detect(RTE_ETH_DEV_TO_PCI(dev)); + if (VTPCI_OPS(hw)->intr_event) + VTPCI_OPS(hw)->intr_event(hw); return 0; } @@ -1301,8 +1301,8 @@ virtio_intr_enable(struct rte_eth_dev *dev) if (rte_intr_enable(dev->intr_handle) < 0) return -1; - if (hw->bus_type == VIRTIO_BUS_PCI_LEGACY || hw->bus_type == VIRTIO_BUS_PCI_MODERN) - hw->use_msix = vtpci_msix_detect(RTE_ETH_DEV_TO_PCI(dev)); + if (VTPCI_OPS(hw)->intr_event) + VTPCI_OPS(hw)->intr_event(hw); return 0; } @@ -1315,8 +1315,8 @@ virtio_intr_disable(struct rte_eth_dev *dev) if (rte_intr_disable(dev->intr_handle) < 0) return -1; - if (hw->bus_type == VIRTIO_BUS_PCI_LEGACY || hw->bus_type == VIRTIO_BUS_PCI_MODERN) - hw->use_msix = vtpci_msix_detect(RTE_ETH_DEV_TO_PCI(dev)); + if (VTPCI_OPS(hw)->intr_event) + VTPCI_OPS(hw)->intr_event(hw); return 0; } diff --git a/drivers/net/virtio/virtio_pci.c b/drivers/net/virtio/virtio_pci.c index 345d73f868..63bc31f732 100644 --- a/drivers/net/virtio/virtio_pci.c +++ b/drivers/net/virtio/virtio_pci.c @@ -47,6 +47,56 @@ check_vq_phys_addr_ok(struct virtqueue *vq) return 1; } +#define PCI_MSIX_ENABLE 0x8000 + +static enum virtio_msix_status +vtpci_msix_detect(struct rte_pci_device *dev) +{ + uint8_t pos; + int ret; + + ret = rte_pci_read_config(dev, &pos, 1, PCI_CAPABILITY_LIST); + if (ret != 1) { + PMD_INIT_LOG(DEBUG, + "failed to read pci capability list, ret %d", ret); + return VIRTIO_MSIX_NONE; + } + + while (pos) { + uint8_t cap[2]; + + ret = rte_pci_read_config(dev, cap, sizeof(cap), pos); + if (ret != sizeof(cap)) { + PMD_INIT_LOG(DEBUG, + "failed to read pci cap at pos: %x ret %d", + pos, ret); + break; + } + + if (cap[0] == PCI_CAP_ID_MSIX) { + uint16_t flags; + + ret = rte_pci_read_config(dev, &flags, sizeof(flags), + pos + sizeof(cap)); + if (ret != sizeof(flags)) { + PMD_INIT_LOG(DEBUG, + "failed to read pci cap at pos:" + " %x ret %d", pos + 2, ret); + break; + } + + if (flags & PCI_MSIX_ENABLE) + return VIRTIO_MSIX_ENABLED; + else + return VIRTIO_MSIX_DISABLED; + } + + pos = cap[1]; + } + + return VIRTIO_MSIX_NONE; +} + /* * Since we are in legacy mode: * http://ozlabs.org/~rusty/virtio-spec/virtio-0.9.5.pdf @@ -241,6 +291,12 @@ legacy_notify_queue(struct virtio_hw *hw, struct virtqueue *vq) VIRTIO_PCI_QUEUE_NOTIFY); } +static void +legacy_intr_event(struct virtio_hw *hw) +{ + hw->use_msix = vtpci_msix_detect(VTPCI_DEV(hw)); +} + const struct virtio_pci_ops legacy_ops = { .read_dev_cfg = legacy_read_dev_config, .write_dev_cfg = legacy_write_dev_config, @@ -255,6 +311,7 @@ const struct virtio_pci_ops legacy_ops = { .setup_queue = legacy_setup_queue, .del_queue = legacy_del_queue, .notify_queue = legacy_notify_queue, + .intr_event = legacy_intr_event, }; static inline void @@ -446,6 +503,14 @@ modern_notify_queue(struct virtio_hw *hw, struct virtqueue *vq) rte_write32(notify_data, vq->notify_addr); } + + +static void +modern_intr_event(struct virtio_hw *hw) +{ + hw->use_msix = vtpci_msix_detect(VTPCI_DEV(hw)); +} + const struct virtio_pci_ops modern_ops = { .read_dev_cfg = modern_read_dev_config, .write_dev_cfg = modern_write_dev_config, @@ -460,6 +525,7 @@ const struct virtio_pci_ops modern_ops = { .setup_queue = modern_setup_queue, .del_queue = modern_del_queue, .notify_queue = modern_notify_queue, + .intr_event = modern_intr_event, }; @@ -562,8 +628,6 @@ get_cfg_addr(struct rte_pci_device *dev, struct virtio_pci_cap *cap) return base + offset; } -#define PCI_MSIX_ENABLE 0x8000 - static int virtio_read_caps(struct rte_pci_device *dev, struct virtio_hw *hw) { @@ -700,7 +764,7 @@ vtpci_init(struct rte_pci_device *dev, struct virtio_hw *hw) 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; - return 0; + goto msix_detect; } PMD_INIT_LOG(INFO, "trying with legacy virtio pci."); @@ -720,53 +784,9 @@ 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; +msix_detect: + hw->use_msix = vtpci_msix_detect(dev); + return 0; } -enum virtio_msix_status -vtpci_msix_detect(struct rte_pci_device *dev) -{ - uint8_t pos; - int ret; - - ret = rte_pci_read_config(dev, &pos, 1, PCI_CAPABILITY_LIST); - if (ret != 1) { - PMD_INIT_LOG(DEBUG, - "failed to read pci capability list, ret %d", ret); - return VIRTIO_MSIX_NONE; - } - - while (pos) { - uint8_t cap[2]; - - ret = rte_pci_read_config(dev, cap, sizeof(cap), pos); - if (ret != sizeof(cap)) { - PMD_INIT_LOG(DEBUG, - "failed to read pci cap at pos: %x ret %d", - pos, ret); - break; - } - - if (cap[0] == PCI_CAP_ID_MSIX) { - uint16_t flags; - - ret = rte_pci_read_config(dev, &flags, sizeof(flags), - pos + sizeof(cap)); - if (ret != sizeof(flags)) { - PMD_INIT_LOG(DEBUG, - "failed to read pci cap at pos:" - " %x ret %d", pos + 2, ret); - break; - } - - if (flags & PCI_MSIX_ENABLE) - return VIRTIO_MSIX_ENABLED; - else - return VIRTIO_MSIX_DISABLED; - } - - pos = cap[1]; - } - - return VIRTIO_MSIX_NONE; -} diff --git a/drivers/net/virtio/virtio_pci.h b/drivers/net/virtio/virtio_pci.h index 59f6688218..6f5c53c4b7 100644 --- a/drivers/net/virtio/virtio_pci.h +++ b/drivers/net/virtio/virtio_pci.h @@ -239,6 +239,7 @@ struct virtio_pci_ops { int (*setup_queue)(struct virtio_hw *hw, struct virtqueue *vq); void (*del_queue)(struct virtio_hw *hw, struct virtqueue *vq); void (*notify_queue)(struct virtio_hw *hw, struct virtqueue *vq); + void (*intr_event)(struct virtio_hw *hw); }; struct virtio_net_config; @@ -303,10 +304,13 @@ struct virtio_pci_dev { struct virtio_hw_internal { const struct virtio_pci_ops *vtpci_ops; struct rte_pci_ioport io; + struct rte_pci_device *dev; }; #define VTPCI_OPS(hw) (virtio_hw_internal[(hw)->port_id].vtpci_ops) #define VTPCI_IO(hw) (&virtio_hw_internal[(hw)->port_id].io) +#define VTPCI_DEV(hw) (virtio_hw_internal[(hw)->port_id].dev) + extern struct virtio_hw_internal virtio_hw_internal[RTE_MAX_ETHPORTS]; @@ -383,8 +387,6 @@ void vtpci_read_dev_config(struct virtio_hw *, size_t, void *, int); uint8_t vtpci_isr(struct virtio_hw *); -enum virtio_msix_status vtpci_msix_detect(struct rte_pci_device *dev); - extern const struct virtio_pci_ops legacy_ops; extern const struct virtio_pci_ops modern_ops; extern const struct virtio_pci_ops virtio_user_ops; diff --git a/drivers/net/virtio/virtio_pci_ethdev.c b/drivers/net/virtio/virtio_pci_ethdev.c index 6a0ef6edc3..045b134ef2 100644 --- a/drivers/net/virtio/virtio_pci_ethdev.c +++ b/drivers/net/virtio/virtio_pci_ethdev.c @@ -73,6 +73,8 @@ eth_virtio_pci_init(struct rte_eth_dev *eth_dev) struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev); int ret; + VTPCI_DEV(hw) = pci_dev; + if (rte_eal_process_type() == RTE_PROC_PRIMARY) { ret = vtpci_init(RTE_ETH_DEV_TO_PCI(eth_dev), hw); if (ret) { -- 2.29.2