From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by dpdk.org (Postfix) with ESMTP id 35F5E9209 for ; Fri, 30 Oct 2015 18:49:38 +0100 (CET) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga103.fm.intel.com with ESMTP; 30 Oct 2015 10:49:38 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.20,219,1444719600"; d="scan'208";a="839490552" Received: from irsmsx109.ger.corp.intel.com ([163.33.3.23]) by fmsmga002.fm.intel.com with ESMTP; 30 Oct 2015 10:49:36 -0700 Received: from irsmsx106.ger.corp.intel.com ([169.254.8.229]) by IRSMSX109.ger.corp.intel.com ([169.254.13.139]) with mapi id 14.03.0248.002; Fri, 30 Oct 2015 17:49:34 +0000 From: "Loftus, Ciara" To: Tetsuya Mukawa , "dev@dpdk.org" Thread-Topic: [PATCH 2/3] vhost: Add callback and private data for vhost PMD Thread-Index: AQHREH6oSGGUc9DP/0OZhD4VfOQAW56ESitA Date: Fri, 30 Oct 2015 17:49:35 +0000 Message-ID: <74F120C019F4A64C9B78E802F6AD4CC24F7B3695@IRSMSX106.ger.corp.intel.com> References: <1445507150-1481-2-git-send-email-mukawa@igel.co.jp> <1445926375-18986-1-git-send-email-mukawa@igel.co.jp> <1445926375-18986-3-git-send-email-mukawa@igel.co.jp> In-Reply-To: <1445926375-18986-3-git-send-email-mukawa@igel.co.jp> Accept-Language: en-GB, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsIiwiaWQiOiI2NzhjOTVlMy01NTg1LTQzYjAtYjBjOC03NzdmZGUzYTIzM2QiLCJwcm9wcyI6W3sibiI6IkludGVsRGF0YUNsYXNzaWZpY2F0aW9uIiwidmFscyI6W3sidmFsdWUiOiJDVFBfSUMifV19XX0sIlN1YmplY3RMYWJlbHMiOltdLCJUTUNWZXJzaW9uIjoiMTUuNC4xMC4xOSIsIlRydXN0ZWRMYWJlbEhhc2giOiJEOFlSZ2lWVW96N1gzdkphRUF5M2o1elkxT1FXUlh3Ykl6NDl2VlZ4cEw4PSJ9 x-inteldataclassification: CTP_IC x-originating-ip: [163.33.239.181] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Cc: "ann.zhuangyanying@huawei.com" Subject: Re: [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: , X-List-Received-Date: Fri, 30 Oct 2015 17:49:39 -0000 >=20 > 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. >=20 > 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(-) >=20 > 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; >=20 > } 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; >=20 > @@ -202,6 +203,8 @@ int rte_vhost_driver_unregister(const char > *dev_name); >=20 > /* Register callbacks. */ > int rte_vhost_driver_callback_register(struct virtio_net_device_ops cons= t * > 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); >=20 > 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) >=20 > /* Remove from the data plane. */ > if (dev->flags & VIRTIO_DEV_RUNNING) > - notify_ops->destroy_device(dev); > + notify_destroy_device(dev); >=20 > if (dev->mem) { > free_mem_region(dev); > @@ -272,7 +272,7 @@ user_set_vring_kick(struct vhost_device_ctx ctx, > struct VhostUserMsg *pmsg) >=20 > if (virtio_is_ready(dev) && > !(dev->flags & VIRTIO_DEV_RUNNING)) > - notify_ops->new_device(dev); > + notify_new_device(dev); > } >=20 > /* > @@ -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 =3D=3D > -1) && > (dev->virtqueue[base_idx + VIRTIO_TXQ]->kickfd =3D=3D > -1)) > - notify_ops->destroy_device(dev); > + notify_destroy_device(dev); >=20 > 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); >=20 > - 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); >=20 > dev->virtqueue[base_idx + VIRTIO_RXQ]->enabled =3D enable; > dev->virtqueue[base_idx + VIRTIO_TXQ]->enabled =3D enable; > @@ -345,7 +342,7 @@ user_destroy_device(struct vhost_device_ctx ctx) > struct virtio_net *dev =3D get_device(ctx); >=20 > if (dev && (dev->flags & VIRTIO_DEV_RUNNING)) > - notify_ops->destroy_device(dev); > + notify_destroy_device(dev); >=20 > 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 { >=20 > /* 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; >=20 > @@ -80,6 +82,43 @@ static struct virtio_net_config_ll *ll_root; > static uint64_t VHOST_FEATURES =3D VHOST_SUPPORTED_FEATURES; >=20 >=20 > +int > +notify_new_device(struct virtio_net *dev) > +{ > + if ((pmd_notify_ops !=3D NULL) && (pmd_notify_ops->new_device !=3D > NULL)) { > + int ret =3D pmd_notify_ops->new_device(dev); > + if (ret !=3D 0) > + return ret; > + } > + if ((notify_ops !=3D NULL) && (notify_ops->new_device !=3D NULL)) > + return notify_ops->new_device(dev); > + > + return 0; > +} > + > +void > +notify_destroy_device(volatile struct virtio_net *dev) > +{ > + if ((pmd_notify_ops !=3D NULL) && (pmd_notify_ops->destroy_device > !=3D NULL)) > + pmd_notify_ops->destroy_device(dev); > + if ((notify_ops !=3D NULL) && (notify_ops->destroy_device !=3D NULL)) > + notify_ops->destroy_device(dev); > +} > + > +int > +notify_vring_state_changed(struct virtio_net *dev, uint16_t queue_id, in= t > enable) > +{ > + if ((pmd_notify_ops !=3D NULL) && (pmd_notify_ops- > >vring_state_changed !=3D NULL)) { > + int ret =3D pmd_notify_ops->vring_state_changed(dev, > queue_id, enable); > + if (ret !=3D 0) > + return ret; > + } > + if ((notify_ops !=3D NULL) && (notify_ops->vring_state_changed !=3D > 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 =3D 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 > !=3D VIRTIO_DEV_STOPPED) && > ((int)dev->virtqueue[base_idx + VIRTIO_TXQ]- > >backend !=3D VIRTIO_DEV_STOPPED)) { > - return notify_ops->new_device(dev); > + return notify_new_device(dev); > } > /* Otherwise we remove it. */ > } else > if (file->fd =3D=3D VIRTIO_DEV_STOPPED) > - notify_ops->destroy_device(dev); > + notify_destroy_device(dev); > return 0; > } >=20 > @@ -883,3 +922,14 @@ rte_vhost_driver_callback_register(struct > virtio_net_device_ops const * const op >=20 > 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 =3D 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" >=20 > -struct virtio_net_device_ops const *notify_ops; > struct virtio_net *get_device(struct vhost_device_ctx ctx); >=20 > +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 > -- > 2.1.4 Hi Tetsuya, Thanks for implementing this. I haven't had a chance to actually test it, b= ut if these changes allow users of the PMD to implement their own new_ and = destroy_ device functions etc, that's good news. Thanks, Ciara