From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pa0-f42.google.com (mail-pa0-f42.google.com [209.85.220.42]) by dpdk.org (Postfix) with ESMTP id 5D1BE919F for ; Tue, 24 Nov 2015 10:00:34 +0100 (CET) Received: by pacej9 with SMTP id ej9so16065148pac.2 for ; Tue, 24 Nov 2015 01:00:33 -0800 (PST) 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=+ZQjZDzJkkMgE7H98lZ+V9evScljMB/UBQt+orWA/TI=; b=A29f+XYrGmw+wcHEzl6soX1RVtk0MNgfIUvQnSGdl5ttAN1g/ZScTcSn+MWavM05+U s49QRPZ2A8AGTADKpMNT4ptcY5U0exIWmVdgwAPHUZY+1ATapNfjDt96wCf6YHAoRiYf GvWcmGTbtpFw4R+Vl6ERVkF8x4JbnAhPuBRSGRnrp785BVX1ITBzGiceuN0nIcd8rdwq uHcmIdvanDf1+pCuTQV7Ho18SE9fCKKiBLVBbms1xGar+BHwkaEPybkuBM2WzuPpd0UA XqDER4UwmFWVuhQpOLkfRGCGZNYsIirwljVS3WjYSeT0XXXy2JbUhZWIOsatASClyMaW L7nw== 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=+ZQjZDzJkkMgE7H98lZ+V9evScljMB/UBQt+orWA/TI=; b=V/E0Hqu12ct3s3C1QtECvBxOd056id7FSRFjxN9rXrR1JE0IkzkBtYKvYiM3AS26Om VBlH8WpmXYxW6et+xXeW7vCM6sODlswzU72hEET26ZR/b2Lw2BBavNOZD+8AwexX9PQl xa6p0+/vwYZ+bUTFwtDGuV0jLLNLUu8bvkZMvCRuOxajSlOh0zIJDl0RSgEvj6NK+paX bdq98gmZvQMi5i21eGPNtX1xBJ3rRFiA4CoeX1M/b8v27dgo0go4FxJlXnOGjZYcr0qW tMbtzM8C611Df3z0kLGAsMTk6OAYSqWPJIp9oRn7HaEcZndkwMupDoQPJFUl9qUccv9s O3xg== X-Gm-Message-State: ALoCoQkWXW1gk608V1xT1UYOKbc0Kgsp04w+6ilt65DlV7fRgJV6/g5IxKFarZm5iTe13b4T6EUS X-Received: by 10.68.235.40 with SMTP id uj8mr41178018pbc.95.1448355633691; Tue, 24 Nov 2015 01:00:33 -0800 (PST) Received: from localhost.localdomain (napt.igel.co.jp. [219.106.231.132]) by smtp.gmail.com with ESMTPSA id py5sm13430738pbc.8.2015.11.24.01.00.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 24 Nov 2015 01:00:33 -0800 (PST) From: Tetsuya Mukawa To: dev@dpdk.org Date: Tue, 24 Nov 2015 18:00:03 +0900 Message-Id: <1448355603-21275-4-git-send-email-mukawa@igel.co.jp> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1448355603-21275-1-git-send-email-mukawa@igel.co.jp> References: <1447392031-24970-3-git-send-email-mukawa@igel.co.jp> <1448355603-21275-1-git-send-email-mukawa@igel.co.jp> Cc: yuanhan.liu@intel.com, ann.zhuangyanying@huawei.com Subject: [dpdk-dev] [PATCH v5 3/3] vhost: Add helper function to convert port id to virtio device pointer 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: Tue, 24 Nov 2015 09:00:34 -0000 This helper function is used to convert port id to virtio device pointer. To use this function, a port should be managed by vhost PMD. After getting virtio device pointer, it can be used for calling vhost library APIs. But some library APIs should not be called with vhost PMD. Here is. - rte_vhost_driver_session_start() - rte_vhost_driver_unregister() Above APIs will not work with vhost PMD. Signed-off-by: Tetsuya Mukawa --- drivers/net/vhost/Makefile | 5 +++ drivers/net/vhost/rte_eth_vhost.c | 25 +++++++++++++++ drivers/net/vhost/rte_eth_vhost.h | 65 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 95 insertions(+) create mode 100644 drivers/net/vhost/rte_eth_vhost.h diff --git a/drivers/net/vhost/Makefile b/drivers/net/vhost/Makefile index 8bec47a..8186a80 100644 --- a/drivers/net/vhost/Makefile +++ b/drivers/net/vhost/Makefile @@ -48,6 +48,11 @@ LIBABIVER := 1 # SRCS-$(CONFIG_RTE_LIBRTE_PMD_VHOST) += rte_eth_vhost.c +# +# Export include files +# +SYMLINK-y-include += rte_eth_vhost.h + # this lib depends upon: DEPDIRS-$(CONFIG_RTE_LIBRTE_PMD_VHOST) += lib/librte_mbuf DEPDIRS-$(CONFIG_RTE_LIBRTE_PMD_VHOST) += lib/librte_ether diff --git a/drivers/net/vhost/rte_eth_vhost.c b/drivers/net/vhost/rte_eth_vhost.c index 9ef05bc..bfe1f18 100644 --- a/drivers/net/vhost/rte_eth_vhost.c +++ b/drivers/net/vhost/rte_eth_vhost.c @@ -41,6 +41,8 @@ #include #include +#include "rte_eth_vhost.h" + #define ETH_VHOST_IFACE_ARG "iface" #define ETH_VHOST_QUEUES_ARG "queues" @@ -768,4 +770,27 @@ static struct rte_driver pmd_vhost_drv = { .uninit = rte_pmd_vhost_devuninit, }; +struct +virtio_net *rte_eth_vhost_portid2vdev(uint16_t port_id) +{ + struct rte_eth_dev *eth_dev; + + if (rte_eth_dev_is_valid_port(port_id) == 0) + return NULL; + + eth_dev = &rte_eth_devices[port_id]; + if (strncmp("eth_vhost", eth_dev->data->drv_name, + strlen("eth_vhost")) == 0) { + struct pmd_internal *internal; + struct vhost_queue *vq; + + internal = eth_dev->data->dev_private; + vq = internal->rx_vhost_queues[0]; + if ((vq != NULL) && (vq->device != NULL)) + return vq->device; + } + + return NULL; +} + PMD_REGISTER_DRIVER(pmd_vhost_drv); diff --git a/drivers/net/vhost/rte_eth_vhost.h b/drivers/net/vhost/rte_eth_vhost.h new file mode 100644 index 0000000..22a880f --- /dev/null +++ b/drivers/net/vhost/rte_eth_vhost.h @@ -0,0 +1,65 @@ +/*- + * BSD LICENSE + * + * Copyright(c) 2015 IGEL Co., Ltd. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of IGEL Co., Ltd. nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _RTE_ETH_AF_PACKET_H_ +#define _RTE_ETH_AF_PACKET_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +/** + * The function convert specified port_id to virtio device structure. + * The retured device can be used for vhost library APIs. + * To use vhost library APIs and vhost PMD parallely, below API should + * not be called, because the API will be called by vhost PMD. + * - rte_vhost_driver_session_start() + * Once a device is managed by vhost PMD, below API should not be called. + * - rte_vhost_driver_unregister() + * To unregister the device, call Port Hotplug APIs. + * + * @param port_id + * port number + * @return + * virtio net device structure corresponding to the specified port + * NULL will be returned in error cases. + */ +struct virtio_net *rte_eth_vhost_portid2vdev(uint16_t port_id); + +#ifdef __cplusplus +} +#endif + +#endif -- 2.1.4