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 7ECA9A0521; Tue, 28 Jul 2020 07:43:01 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 167FB1C044; Tue, 28 Jul 2020 07:43:00 +0200 (CEST) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by dpdk.org (Postfix) with ESMTP id 4BF371BFF2 for ; Tue, 28 Jul 2020 07:42:58 +0200 (CEST) IronPort-SDR: DWHvwrz3amU3+8i2jLz+kwPoDBuQsxDyuJ3BpBP7FT8Byni+W/hBpao7LIIPqBakp10KhffFBv aynjOGlsrQug== X-IronPort-AV: E=McAfee;i="6000,8403,9695"; a="169266746" X-IronPort-AV: E=Sophos;i="5.75,405,1589266800"; d="scan'208";a="169266746" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jul 2020 22:42:57 -0700 IronPort-SDR: I3nEYeMzHlHMcZe4wmB71S3XCdlg9E296OEgZ6wtnsWe4NUft2Y2Q9AWDC7P17TRKm/KHC99kz EDr/t6ejnGCw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,405,1589266800"; d="scan'208";a="312485807" Received: from npg-dpdk-virtio-xiachenbo-nw.sh.intel.com ([10.67.119.123]) by fmsmga004.fm.intel.com with ESMTP; 27 Jul 2020 22:42:55 -0700 From: Chenbo Xia To: dev@dpdk.org Cc: maxime.coquelin@redhat.com, ferruh.yigit@intel.com, xiao.w.wang@intel.com, rosen.xu@intel.com Date: Tue, 28 Jul 2020 14:32:24 +0000 Message-Id: <20200728143224.99949-1-chenbo.xia@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200724170906.13843-1-chenbo.xia@intel.com> References: <20200724170906.13843-1-chenbo.xia@intel.com> Subject: [dpdk-dev] [PATCH v2] vdpa/ifc: fix vring update after device config 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" The device ready state in vhost lib is now defined as the state that first queue pair is ready. And kick/callfd may be updated by QEMU when ifc device is configured. Although now ifc driver only supports one queue pair, it still has to update callfd when working with QEMU. This patch fixes this vring update problem by implementing the set_vring_state callback. Fixes: a3f8150eac6d (net/ifcvf: add ifcvf vDPA driver) Suggested-by: Maxime Coquelin Signed-off-by: Chenbo Xia Acked-by: Wang Xiao W --- drivers/vdpa/ifc/base/ifcvf.h | 1 + drivers/vdpa/ifc/ifcvf_vdpa.c | 54 ++++++++++++++++++++++++++++++++++- 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/drivers/vdpa/ifc/base/ifcvf.h b/drivers/vdpa/ifc/base/ifcvf.h index eb04a9406..a288ce57d 100644 --- a/drivers/vdpa/ifc/base/ifcvf.h +++ b/drivers/vdpa/ifc/base/ifcvf.h @@ -115,6 +115,7 @@ struct vring_info { u16 size; u16 last_avail_idx; u16 last_used_idx; + bool enable; }; struct ifcvf_hw { diff --git a/drivers/vdpa/ifc/ifcvf_vdpa.c b/drivers/vdpa/ifc/ifcvf_vdpa.c index a757d45ec..6a1b44bc7 100644 --- a/drivers/vdpa/ifc/ifcvf_vdpa.c +++ b/drivers/vdpa/ifc/ifcvf_vdpa.c @@ -49,6 +49,7 @@ static const char * const ifcvf_valid_arguments[] = { struct ifcvf_internal { struct rte_pci_device *pdev; struct ifcvf_hw hw; + int configured; int vfio_container_fd; int vfio_group_fd; int vfio_dev_fd; @@ -897,6 +898,7 @@ ifcvf_dev_config(int vid) DRV_LOG(NOTICE, "vDPA (%s): software relay is used.", vdev->device->name); + internal->configured = 1; return 0; } @@ -935,6 +937,7 @@ ifcvf_dev_close(int vid) update_datapath(internal); } + internal->configured = 0; return 0; } @@ -1084,13 +1087,61 @@ ifcvf_get_protocol_features(struct rte_vdpa_device *vdev, uint64_t *features) return 0; } +static int +ifcvf_set_vring_state(int vid, int vring, int state) +{ + struct rte_vdpa_device *vdev; + struct internal_list *list; + struct ifcvf_internal *internal; + struct ifcvf_hw *hw; + struct ifcvf_pci_common_cfg *cfg; + int ret = 0; + + vdev = rte_vhost_get_vdpa_device(vid); + list = find_internal_resource_by_vdev(vdev); + if (list == NULL) { + DRV_LOG(ERR, "Invalid vDPA device: %p", vdev); + return -1; + } + + internal = list->internal; + if (vring < 0 || vring >= internal->max_queues * 2) { + DRV_LOG(ERR, "Vring index %d not correct", vring); + return -1; + } + + hw = &internal->hw; + if (!internal->configured) + goto exit; + + cfg = hw->common_cfg; + IFCVF_WRITE_REG16(vring, &cfg->queue_select); + IFCVF_WRITE_REG16(!!state, &cfg->queue_enable); + + if (!state && hw->vring[vring].enable) { + ret = vdpa_disable_vfio_intr(internal); + if (ret) + return ret; + } + + if (state && !hw->vring[vring].enable) { + ret = vdpa_enable_vfio_intr(internal, 0); + if (ret) + return ret; + } + +exit: + hw->vring[vring].enable = !!state; + return 0; +} + static struct rte_vdpa_dev_ops ifcvf_ops = { .get_queue_num = ifcvf_get_queue_num, .get_features = ifcvf_get_vdpa_features, .get_protocol_features = ifcvf_get_protocol_features, .dev_conf = ifcvf_dev_config, .dev_close = ifcvf_dev_close, - .set_vring_state = NULL, + .set_vring_state = ifcvf_set_vring_state, .set_features = ifcvf_set_features, .migration_done = NULL, .get_vfio_group_fd = ifcvf_get_vfio_group_fd, @@ -1170,6 +1221,7 @@ ifcvf_pci_probe(struct rte_pci_driver *pci_drv __rte_unused, goto error; } + internal->configured = 0; internal->max_queues = IFCVF_MAX_QUEUES; features = ifcvf_get_features(&internal->hw); internal->features = (features & -- 2.17.1