From patchwork Tue Oct 27 06:12:54 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tetsuya Mukawa X-Patchwork-Id: 8039 Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [IPv6:::1]) by dpdk.org (Postfix) with ESMTP id 3B72B8DA8; Tue, 27 Oct 2015 07:13:18 +0100 (CET) Received: from mail-pa0-f44.google.com (mail-pa0-f44.google.com [209.85.220.44]) by dpdk.org (Postfix) with ESMTP id A37A38DA8 for ; Tue, 27 Oct 2015 07:13:15 +0100 (CET) Received: by pabla5 with SMTP id la5so19060863pab.0 for ; Mon, 26 Oct 2015 23:13:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=igel_co_jp.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=HSLfo5aJfZ7S3SiGTckRX65UxuA0eKOkAgk6DeUJcCk=; b=YgSQRQ4SfnRigJcck3xbJbu6g8owg4+mS/tfGqD1P9VdIgoOO1FZ4iy56vFe0XVtse mOWZMaNsTVzJ44NDEfryX/0rPLl4mEKiF1Fix5/HkAF/CkUwpOqEo3G927RKz1IcRdUf G1VdW/WocoHWMHfnkbDQXGFSUrnD0Gmj+VwdPrdhjbdM7bT3Tsx6Cbqaf+3JrgE9yy68 ziQsaisVbrvv2Vn/k6luH3Hsqp2PWmZEjUgpO8dR/mzUnjVKcHB7fzmSIri8bTHdd2Sg H/YspMLv5RIFnbBKeUnWaKy5vUyQBi9bu/61Zvb44KDFRc1U+ELmn/gyIxndoGJBWTGP 8rEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=HSLfo5aJfZ7S3SiGTckRX65UxuA0eKOkAgk6DeUJcCk=; b=FD0F1pFqqbcGJgZ9z48uGQ3DAcA0qPD2TrvkMENeUze8UO84tALGLsIbB3wwbHreWQ Ok/61IJeGUgkf+OijRNF4KYrn0o+UwFgTT3YPRbCnkY2V3fQwMxLp1v2D8gf1kxfq0HO jjQldpYHmCIXRPgzLKXgOqsHb353Mi2WT5/ALBUQlr7z8t0xuRJ+qhst1O5jHQCv9u1w ODU4Cuz7mtDVPlaeYHYs5jpFbwopGl1LN85Zpqn+yOuE13n9h9uUhsJoHFh8y5Gdg3S8 u5Pi/paHh0ITNa0ZlaOTcUyWdn34T9rDUZp9KQOd/3/dbqWzl2erNNror333FICZt+Su NB7g== X-Gm-Message-State: ALoCoQkpbZ5ZL9HOxphlwtUdrZzPrCoP6SjQgsFh3L7GgPANygHKpp0NO6kQPkUmRKjOlIfbkZ0I X-Received: by 10.66.194.105 with SMTP id hv9mr25898811pac.79.1445926394987; Mon, 26 Oct 2015 23:13:14 -0700 (PDT) Received: from localhost.localdomain (napt.igel.co.jp. [219.106.231.132]) by smtp.gmail.com with ESMTPSA id cn4sm37312954pbc.94.2015.10.26.23.13.12 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 26 Oct 2015 23:13:14 -0700 (PDT) From: Tetsuya Mukawa To: dev@dpdk.org Date: Tue, 27 Oct 2015 15:12:54 +0900 Message-Id: <1445926375-18986-3-git-send-email-mukawa@igel.co.jp> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1445926375-18986-1-git-send-email-mukawa@igel.co.jp> References: <1445507150-1481-2-git-send-email-mukawa@igel.co.jp> <1445926375-18986-1-git-send-email-mukawa@igel.co.jp> Cc: ann.zhuangyanying@huawei.com Subject: [dpdk-dev] [PATCH 2/3] vhost: Add callback and private data for vhost PMD X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" These variables are needed to be able to manage one of virtio devices using both vhost library APIs and vhost PMD. For example, if vhost PMD uses current callback handler and private data provided by vhost library, A DPDK application that links vhost library cannot use some of vhost library APIs. To avoid it, callback and private data for vhost PMD are needed. Signed-off-by: Tetsuya Mukawa --- lib/librte_vhost/rte_vhost_version.map | 6 +++ lib/librte_vhost/rte_virtio_net.h | 3 ++ lib/librte_vhost/vhost_user/virtio-net-user.c | 13 +++---- lib/librte_vhost/virtio-net.c | 56 +++++++++++++++++++++++++-- lib/librte_vhost/virtio-net.h | 4 +- 5 files changed, 70 insertions(+), 12 deletions(-) diff --git a/lib/librte_vhost/rte_vhost_version.map b/lib/librte_vhost/rte_vhost_version.map index 3d8709e..00a9ce5 100644 --- a/lib/librte_vhost/rte_vhost_version.map +++ b/lib/librte_vhost/rte_vhost_version.map @@ -20,3 +20,9 @@ DPDK_2.1 { rte_vhost_driver_unregister; } DPDK_2.0; + +DPDK_2.2 { + global: + + rte_vhost_driver_pmd_callback_register; +} DPDK_2.1; diff --git a/lib/librte_vhost/rte_virtio_net.h b/lib/librte_vhost/rte_virtio_net.h index 426a70d..08e77af 100644 --- a/lib/librte_vhost/rte_virtio_net.h +++ b/lib/librte_vhost/rte_virtio_net.h @@ -106,6 +106,7 @@ struct virtio_net { char ifname[IF_NAME_SZ]; /**< Name of the tap device or socket path. */ uint32_t virt_qp_nb; /**< number of queue pair we have allocated */ void *priv; /**< private context */ + void *pmd_priv; /**< private context for vhost PMD */ struct vhost_virtqueue *virtqueue[VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MAX]; /**< Contains all virtqueue information. */ } __rte_cache_aligned; @@ -202,6 +203,8 @@ int rte_vhost_driver_unregister(const char *dev_name); /* Register callbacks. */ int rte_vhost_driver_callback_register(struct virtio_net_device_ops const * const); +/* Register callbacks for vhost PMD (Only for internal). */ +int rte_vhost_driver_pmd_callback_register(struct virtio_net_device_ops const * const); /* Start vhost driver session blocking loop. */ int rte_vhost_driver_session_start(void); diff --git a/lib/librte_vhost/vhost_user/virtio-net-user.c b/lib/librte_vhost/vhost_user/virtio-net-user.c index 3e8dfea..dad083b 100644 --- a/lib/librte_vhost/vhost_user/virtio-net-user.c +++ b/lib/librte_vhost/vhost_user/virtio-net-user.c @@ -111,7 +111,7 @@ user_set_mem_table(struct vhost_device_ctx ctx, struct VhostUserMsg *pmsg) /* Remove from the data plane. */ if (dev->flags & VIRTIO_DEV_RUNNING) - notify_ops->destroy_device(dev); + notify_destroy_device(dev); if (dev->mem) { free_mem_region(dev); @@ -272,7 +272,7 @@ user_set_vring_kick(struct vhost_device_ctx ctx, struct VhostUserMsg *pmsg) if (virtio_is_ready(dev) && !(dev->flags & VIRTIO_DEV_RUNNING)) - notify_ops->new_device(dev); + notify_new_device(dev); } /* @@ -307,7 +307,7 @@ user_get_vring_base(struct vhost_device_ctx ctx, if ((dev->flags & VIRTIO_DEV_RUNNING) && (dev->virtqueue[base_idx + VIRTIO_RXQ]->kickfd == -1) && (dev->virtqueue[base_idx + VIRTIO_TXQ]->kickfd == -1)) - notify_ops->destroy_device(dev); + notify_destroy_device(dev); return 0; } @@ -328,10 +328,7 @@ user_set_vring_enable(struct vhost_device_ctx ctx, "set queue enable: %d to qp idx: %d\n", enable, state->index); - if (notify_ops->vring_state_changed) { - notify_ops->vring_state_changed(dev, base_idx / VIRTIO_QNUM, - enable); - } + notify_vring_state_changed(dev, base_idx / VIRTIO_QNUM, enable); dev->virtqueue[base_idx + VIRTIO_RXQ]->enabled = enable; dev->virtqueue[base_idx + VIRTIO_TXQ]->enabled = enable; @@ -345,7 +342,7 @@ user_destroy_device(struct vhost_device_ctx ctx) struct virtio_net *dev = get_device(ctx); if (dev && (dev->flags & VIRTIO_DEV_RUNNING)) - notify_ops->destroy_device(dev); + notify_destroy_device(dev); if (dev && dev->mem) { free_mem_region(dev); diff --git a/lib/librte_vhost/virtio-net.c b/lib/librte_vhost/virtio-net.c index ee2e84d..de5d8ff 100644 --- a/lib/librte_vhost/virtio-net.c +++ b/lib/librte_vhost/virtio-net.c @@ -65,6 +65,8 @@ struct virtio_net_config_ll { /* device ops to add/remove device to/from data core. */ struct virtio_net_device_ops const *notify_ops; +/* device ops for vhost PMD to add/remove device to/from data core. */ +struct virtio_net_device_ops const *pmd_notify_ops; /* root address of the linked list of managed virtio devices */ static struct virtio_net_config_ll *ll_root; @@ -80,6 +82,43 @@ static struct virtio_net_config_ll *ll_root; static uint64_t VHOST_FEATURES = VHOST_SUPPORTED_FEATURES; +int +notify_new_device(struct virtio_net *dev) +{ + if ((pmd_notify_ops != NULL) && (pmd_notify_ops->new_device != NULL)) { + int ret = pmd_notify_ops->new_device(dev); + if (ret != 0) + return ret; + } + if ((notify_ops != NULL) && (notify_ops->new_device != NULL)) + return notify_ops->new_device(dev); + + return 0; +} + +void +notify_destroy_device(volatile struct virtio_net *dev) +{ + if ((pmd_notify_ops != NULL) && (pmd_notify_ops->destroy_device != NULL)) + pmd_notify_ops->destroy_device(dev); + if ((notify_ops != NULL) && (notify_ops->destroy_device != NULL)) + notify_ops->destroy_device(dev); +} + +int +notify_vring_state_changed(struct virtio_net *dev, uint16_t queue_id, int enable) +{ + if ((pmd_notify_ops != NULL) && (pmd_notify_ops->vring_state_changed != NULL)) { + int ret = pmd_notify_ops->vring_state_changed(dev, queue_id, enable); + if (ret != 0) + return ret; + } + if ((notify_ops != NULL) && (notify_ops->vring_state_changed != NULL)) + return notify_ops->vring_state_changed(dev, queue_id, enable); + + return 0; +} + /* * Converts QEMU virtual address to Vhost virtual address. This function is * used to convert the ring addresses to our address space. @@ -377,7 +416,7 @@ destroy_device(struct vhost_device_ctx ctx) * the function to remove it from the data core. */ if ((ll_dev_cur->dev.flags & VIRTIO_DEV_RUNNING)) - notify_ops->destroy_device(&(ll_dev_cur->dev)); + notify_destroy_device(&(ll_dev_cur->dev)); ll_dev_cur = rm_config_ll_entry(ll_dev_cur, ll_dev_last); } else { @@ -794,12 +833,12 @@ set_backend(struct vhost_device_ctx ctx, struct vhost_vring_file *file) if (!(dev->flags & VIRTIO_DEV_RUNNING)) { if (((int)dev->virtqueue[base_idx + VIRTIO_RXQ]->backend != VIRTIO_DEV_STOPPED) && ((int)dev->virtqueue[base_idx + VIRTIO_TXQ]->backend != VIRTIO_DEV_STOPPED)) { - return notify_ops->new_device(dev); + return notify_new_device(dev); } /* Otherwise we remove it. */ } else if (file->fd == VIRTIO_DEV_STOPPED) - notify_ops->destroy_device(dev); + notify_destroy_device(dev); return 0; } @@ -883,3 +922,14 @@ rte_vhost_driver_callback_register(struct virtio_net_device_ops const * const op return 0; } + +/* + * Register ops so that we can add/remove device to data core. + */ +int +rte_vhost_driver_pmd_callback_register(struct virtio_net_device_ops const * const ops) +{ + pmd_notify_ops = ops; + + return 0; +} diff --git a/lib/librte_vhost/virtio-net.h b/lib/librte_vhost/virtio-net.h index 75fb57e..0816e71 100644 --- a/lib/librte_vhost/virtio-net.h +++ b/lib/librte_vhost/virtio-net.h @@ -37,7 +37,9 @@ #include "vhost-net.h" #include "rte_virtio_net.h" -struct virtio_net_device_ops const *notify_ops; struct virtio_net *get_device(struct vhost_device_ctx ctx); +int notify_new_device(struct virtio_net *dev); +void notify_destroy_device(volatile struct virtio_net *dev); +int notify_vring_state_changed(struct virtio_net *dev, uint16_t queue_id, int enable); #endif