get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

GET /api/patches/13795/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 13795,
    "url": "http://patches.dpdk.org/api/patches/13795/?format=api",
    "web_url": "http://patches.dpdk.org/project/dpdk/patch/1465981405-37485-5-git-send-email-jianfeng.tan@intel.com/",
    "project": {
        "id": 1,
        "url": "http://patches.dpdk.org/api/projects/1/?format=api",
        "name": "DPDK",
        "link_name": "dpdk",
        "list_id": "dev.dpdk.org",
        "list_email": "dev@dpdk.org",
        "web_url": "http://core.dpdk.org",
        "scm_url": "git://dpdk.org/dpdk",
        "webscm_url": "http://git.dpdk.org/dpdk",
        "list_archive_url": "https://inbox.dpdk.org/dev",
        "list_archive_url_format": "https://inbox.dpdk.org/dev/{}",
        "commit_url_format": ""
    },
    "msgid": "<1465981405-37485-5-git-send-email-jianfeng.tan@intel.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/1465981405-37485-5-git-send-email-jianfeng.tan@intel.com",
    "date": "2016-06-15T09:03:23",
    "name": "[dpdk-dev,v9,4/6] virtio-user: add device emulation layer APIs",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": true,
    "hash": "466b310426fda9fe080271488b795a9d7c02eb67",
    "submitter": {
        "id": 313,
        "url": "http://patches.dpdk.org/api/people/313/?format=api",
        "name": "Jianfeng Tan",
        "email": "jianfeng.tan@intel.com"
    },
    "delegate": {
        "id": 355,
        "url": "http://patches.dpdk.org/api/users/355/?format=api",
        "username": "yliu",
        "first_name": "Yuanhan",
        "last_name": "Liu",
        "email": "yuanhan.liu@linux.intel.com"
    },
    "mbox": "http://patches.dpdk.org/project/dpdk/patch/1465981405-37485-5-git-send-email-jianfeng.tan@intel.com/mbox/",
    "series": [],
    "comments": "http://patches.dpdk.org/api/patches/13795/comments/",
    "check": "pending",
    "checks": "http://patches.dpdk.org/api/patches/13795/checks/",
    "tags": {},
    "related": [],
    "headers": {
        "Return-Path": "<dev-bounces@dpdk.org>",
        "X-Original-To": "patchwork@dpdk.org",
        "Delivered-To": "patchwork@dpdk.org",
        "Received": [
            "from [92.243.14.124] (localhost [IPv6:::1])\n\tby dpdk.org (Postfix) with ESMTP id 6C257C3B0;\n\tWed, 15 Jun 2016 11:04:11 +0200 (CEST)",
            "from mga03.intel.com (mga03.intel.com [134.134.136.65])\n\tby dpdk.org (Postfix) with ESMTP id 3DA22C388\n\tfor <dev@dpdk.org>; Wed, 15 Jun 2016 11:04:06 +0200 (CEST)",
            "from fmsmga004.fm.intel.com ([10.253.24.48])\n\tby orsmga103.jf.intel.com with ESMTP; 15 Jun 2016 02:03:46 -0700",
            "from dpdk06.sh.intel.com ([10.239.128.225])\n\tby fmsmga004.fm.intel.com with ESMTP; 15 Jun 2016 02:03:42 -0700"
        ],
        "X-ExtLoop1": "1",
        "X-IronPort-AV": "E=Sophos;i=\"5.26,475,1459839600\"; d=\"scan'208\";a=\"122217739\"",
        "From": "Jianfeng Tan <jianfeng.tan@intel.com>",
        "To": "dev@dpdk.org",
        "Cc": "Jianfeng Tan <jianfeng.tan@intel.com>, Huawei Xie <huawei.xie@intel.com>,\n\trich.lane@bigswitch.com, yuanhan.liu@linux.intel.com, mst@redhat.com, \n\tnakajima.yoshihiro@lab.ntt.co.jp, p.fedin@samsung.com,\n\tann.zhuangyanying@huawei.com, mukawa@igel.co.jp, nhorman@tuxdriver.com",
        "Date": "Wed, 15 Jun 2016 09:03:23 +0000",
        "Message-Id": "<1465981405-37485-5-git-send-email-jianfeng.tan@intel.com>",
        "X-Mailer": "git-send-email 2.1.4",
        "In-Reply-To": "<1465981405-37485-1-git-send-email-jianfeng.tan@intel.com>",
        "References": "<1446748276-132087-1-git-send-email-jianfeng.tan@intel.com>\n\t<1465981405-37485-1-git-send-email-jianfeng.tan@intel.com>",
        "Subject": "[dpdk-dev] [PATCH v9 4/6] virtio-user: add device emulation layer\n\tAPIs",
        "X-BeenThere": "dev@dpdk.org",
        "X-Mailman-Version": "2.1.15",
        "Precedence": "list",
        "List-Id": "patches and discussions about DPDK <dev.dpdk.org>",
        "List-Unsubscribe": "<http://dpdk.org/ml/options/dev>,\n\t<mailto:dev-request@dpdk.org?subject=unsubscribe>",
        "List-Archive": "<http://dpdk.org/ml/archives/dev/>",
        "List-Post": "<mailto:dev@dpdk.org>",
        "List-Help": "<mailto:dev-request@dpdk.org?subject=help>",
        "List-Subscribe": "<http://dpdk.org/ml/listinfo/dev>,\n\t<mailto:dev-request@dpdk.org?subject=subscribe>",
        "Errors-To": "dev-bounces@dpdk.org",
        "Sender": "\"dev\" <dev-bounces@dpdk.org>"
    },
    "content": "Two device emulation layer APIs are added for virtio driver to call:\n  - virtio_user_start_device()\n  - virtio_user_stop_device()\n  - virtio_user_dev_init()\n  - virtio_user_dev_uninit()\n\nThese APIs will get called by virtio driver, and they call vhost adapter\nlayer APIs to implement the functionality. Besides, this patch defines\na struct named virtio_user_dev to help manage the data stands for this\nkind of virtual device.\n\n  ----------------------\n  | ------------------ |\n  | | virtio driver  | |\n  | ------------------ |\n  |         |          |\n  | ------------------ | ------>  virtio-user PMD\n  | | device emulate |-|----> (virtio_user_dev.c, virtio_user_dev.h)\n  | |                | |\n  | | vhost adapter  | |\n  | ------------------ |\n  ----------------------\n            |\n            |\n            |\n   ------------------\n   | vhost backend  |\n   ------------------\n\nSigned-off-by: Huawei Xie <huawei.xie@intel.com>\nSigned-off-by: Jianfeng Tan <jianfeng.tan@intel.com>\nAcked-by: Neil Horman <nhorman@tuxdriver.com>\n---\n drivers/net/virtio/Makefile                      |   1 +\n drivers/net/virtio/virtio_user/virtio_user_dev.c | 227 +++++++++++++++++++++++\n drivers/net/virtio/virtio_user/virtio_user_dev.h |  62 +++++++\n 3 files changed, 290 insertions(+)\n create mode 100644 drivers/net/virtio/virtio_user/virtio_user_dev.c\n create mode 100644 drivers/net/virtio/virtio_user/virtio_user_dev.h",
    "diff": "diff --git a/drivers/net/virtio/Makefile b/drivers/net/virtio/Makefile\nindex c2ed0fa..d37b83d 100644\n--- a/drivers/net/virtio/Makefile\n+++ b/drivers/net/virtio/Makefile\n@@ -57,6 +57,7 @@ endif\n \n ifeq ($(CONFIG_RTE_VIRTIO_USER),y)\n SRCS-$(CONFIG_RTE_LIBRTE_VIRTIO_PMD) += virtio_user/vhost_user.c\n+SRCS-$(CONFIG_RTE_LIBRTE_VIRTIO_PMD) += virtio_user/virtio_user_dev.c\n endif\n \n # this lib depends upon:\ndiff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.c b/drivers/net/virtio/virtio_user/virtio_user_dev.c\nnew file mode 100644\nindex 0000000..93cb758\n--- /dev/null\n+++ b/drivers/net/virtio/virtio_user/virtio_user_dev.c\n@@ -0,0 +1,227 @@\n+/*-\n+ *   BSD LICENSE\n+ *\n+ *   Copyright(c) 2010-2016 Intel Corporation. All rights reserved.\n+ *   All rights reserved.\n+ *\n+ *   Redistribution and use in source and binary forms, with or without\n+ *   modification, are permitted provided that the following conditions\n+ *   are met:\n+ *\n+ *     * Redistributions of source code must retain the above copyright\n+ *       notice, this list of conditions and the following disclaimer.\n+ *     * Redistributions in binary form must reproduce the above copyright\n+ *       notice, this list of conditions and the following disclaimer in\n+ *       the documentation and/or other materials provided with the\n+ *       distribution.\n+ *     * Neither the name of Intel Corporation nor the names of its\n+ *       contributors may be used to endorse or promote products derived\n+ *       from this software without specific prior written permission.\n+ *\n+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n+ *   \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n+ */\n+\n+#include <stdint.h>\n+#include <stdio.h>\n+#include <fcntl.h>\n+#include <string.h>\n+#include <errno.h>\n+#include <sys/mman.h>\n+#include <unistd.h>\n+#include <sys/eventfd.h>\n+\n+#include \"vhost.h\"\n+#include \"virtio_user_dev.h\"\n+#include \"../virtio_ethdev.h\"\n+\n+static int\n+virtio_user_kick_queue(struct virtio_user_dev *dev, uint32_t queue_sel)\n+{\n+\tint callfd, kickfd;\n+\tstruct vhost_vring_file file;\n+\tstruct vhost_vring_state state;\n+\tstruct vring *vring = &dev->vrings[queue_sel];\n+\tstruct vhost_vring_addr addr = {\n+\t\t.index = queue_sel,\n+\t\t.desc_user_addr = (uint64_t)(uintptr_t)vring->desc,\n+\t\t.avail_user_addr = (uint64_t)(uintptr_t)vring->avail,\n+\t\t.used_user_addr = (uint64_t)(uintptr_t)vring->used,\n+\t\t.log_guest_addr = 0,\n+\t\t.flags = 0, /* disable log */\n+\t};\n+\n+\t/* May use invalid flag, but some backend leverages kickfd and callfd as\n+\t * criteria to judge if dev is alive. so finally we use real event_fd.\n+\t */\n+\tcallfd = eventfd(0, O_CLOEXEC | O_NONBLOCK);\n+\tif (callfd < 0) {\n+\t\tPMD_DRV_LOG(ERR, \"callfd error, %s\\n\", strerror(errno));\n+\t\treturn -1;\n+\t}\n+\tkickfd = eventfd(0, O_CLOEXEC | O_NONBLOCK);\n+\tif (kickfd < 0) {\n+\t\tclose(callfd);\n+\t\tPMD_DRV_LOG(ERR, \"kickfd error, %s\\n\", strerror(errno));\n+\t\treturn -1;\n+\t}\n+\n+\t/* Of all per virtqueue MSGs, make sure VHOST_SET_VRING_CALL come\n+\t * firstly because vhost depends on this msg to allocate virtqueue\n+\t * pair.\n+\t */\n+\tfile.index = queue_sel;\n+\tfile.fd = callfd;\n+\tvhost_user_sock(dev->vhostfd, VHOST_USER_SET_VRING_CALL, &file);\n+\tdev->callfds[queue_sel] = callfd;\n+\n+\tstate.index = queue_sel;\n+\tstate.num = vring->num;\n+\tvhost_user_sock(dev->vhostfd, VHOST_USER_SET_VRING_NUM, &state);\n+\n+\tstate.num = 0; /* no reservation */\n+\tvhost_user_sock(dev->vhostfd, VHOST_USER_SET_VRING_BASE, &state);\n+\n+\tvhost_user_sock(dev->vhostfd, VHOST_USER_SET_VRING_ADDR, &addr);\n+\n+\t/* Of all per virtqueue MSGs, make sure VHOST_USER_SET_VRING_KICK comes\n+\t * lastly because vhost depends on this msg to judge if\n+\t * virtio is ready.\n+\t */\n+\tfile.fd = kickfd;\n+\tvhost_user_sock(dev->vhostfd, VHOST_USER_SET_VRING_KICK, &file);\n+\tdev->kickfds[queue_sel] = kickfd;\n+\n+\treturn 0;\n+}\n+\n+int\n+virtio_user_start_device(struct virtio_user_dev *dev)\n+{\n+\tuint64_t features;\n+\tuint32_t i, queue_sel;\n+\tint ret;\n+\n+\t/* construct memory region inside each implementation */\n+\tret = vhost_user_sock(dev->vhostfd, VHOST_USER_SET_MEM_TABLE, NULL);\n+\tif (ret < 0)\n+\t\tgoto error;\n+\n+\tfor (i = 0; i < dev->max_queue_pairs; ++i) {\n+\t\tqueue_sel = 2 * i + VTNET_SQ_RQ_QUEUE_IDX;\n+\t\tif (virtio_user_kick_queue(dev, queue_sel) < 0) {\n+\t\t\tPMD_DRV_LOG(INFO, \"kick rx vq fails: %u\", i);\n+\t\t\tgoto error;\n+\t\t}\n+\t}\n+\tfor (i = 0; i < dev->max_queue_pairs; ++i) {\n+\t\tqueue_sel = 2 * i + VTNET_SQ_TQ_QUEUE_IDX;\n+\t\tif (virtio_user_kick_queue(dev, queue_sel) < 0) {\n+\t\t\tPMD_DRV_LOG(INFO, \"kick tx vq fails: %u\", i);\n+\t\t\tgoto error;\n+\t\t}\n+\t}\n+\n+\t/* After setup all virtqueues, we need to set_features so that\n+\t * these features can be set into each virtqueue in vhost side.\n+\t * And before that, make sure VIRTIO_NET_F_MAC is stripped.\n+\t */\n+\tfeatures = dev->features;\n+\tfeatures &= ~(1ull << VIRTIO_NET_F_MAC);\n+\tret = vhost_user_sock(dev->vhostfd, VHOST_USER_SET_FEATURES, &features);\n+\tif (ret < 0)\n+\t\tgoto error;\n+\tPMD_DRV_LOG(INFO, \"set features: %\" PRIx64, features);\n+\n+\treturn 0;\n+error:\n+\t/* TODO: free resource here or caller to check */\n+\treturn -1;\n+}\n+\n+int virtio_user_stop_device(struct virtio_user_dev *dev)\n+{\n+\treturn vhost_user_sock(dev->vhostfd, VHOST_USER_RESET_OWNER, NULL);\n+}\n+\n+static inline void\n+parse_mac(struct virtio_user_dev *dev, const char *mac)\n+{\n+\tint i, r;\n+\tuint32_t tmp[ETHER_ADDR_LEN];\n+\n+\tif (!mac)\n+\t\treturn;\n+\n+\tr = sscanf(mac, \"%x:%x:%x:%x:%x:%x\", &tmp[0],\n+\t\t\t&tmp[1], &tmp[2], &tmp[3], &tmp[4], &tmp[5]);\n+\tif (r == ETHER_ADDR_LEN) {\n+\t\tfor (i = 0; i < ETHER_ADDR_LEN; ++i)\n+\t\t\tdev->mac_addr[i] = (uint8_t)tmp[i];\n+\t\tdev->mac_specified = 1;\n+\t} else {\n+\t\t/* ignore the wrong mac, use random mac */\n+\t\tPMD_DRV_LOG(ERR, \"wrong format of mac: %s\", mac);\n+\t}\n+}\n+\n+int\n+virtio_user_dev_init(struct virtio_user_dev *dev, char *path, int queues,\n+\t\t     int cq, int queue_size, const char *mac)\n+{\n+\tstrncpy(dev->path, path, PATH_MAX);\n+\tdev->max_queue_pairs = queues;\n+\tdev->queue_pairs = 1; /* mq disabled by default */\n+\tdev->queue_size = queue_size;\n+\tdev->mac_specified = 0;\n+\tparse_mac(dev, mac);\n+\tdev->vhostfd = -1;\n+\t/* TODO: cq */\n+\tRTE_SET_USED(cq);\n+\n+\tdev->vhostfd = vhost_user_setup(dev->path);\n+\tif (dev->vhostfd < 0) {\n+\t\tPMD_INIT_LOG(ERR, \"backend set up fails\");\n+\t\treturn -1;\n+\t}\n+\tif (vhost_user_sock(dev->vhostfd, VHOST_USER_SET_OWNER, NULL) < 0) {\n+\t\tPMD_INIT_LOG(ERR, \"set_owner fails: %s\", strerror(errno));\n+\t\treturn -1;\n+\t}\n+\n+\tif (vhost_user_sock(dev->vhostfd, VHOST_USER_GET_FEATURES,\n+\t\t\t    &dev->features) < 0) {\n+\t\tPMD_INIT_LOG(ERR, \"get_features failed: %s\", strerror(errno));\n+\t\treturn -1;\n+\t}\n+\tif (dev->mac_specified)\n+\t\tdev->features |= (1ull << VIRTIO_NET_F_MAC);\n+\t/* disable it until we support CQ */\n+\tdev->features &= ~(1ull << VIRTIO_NET_F_CTRL_VQ);\n+\tdev->features &= ~(1ull << VIRTIO_NET_F_CTRL_RX);\n+\n+\treturn 0;\n+\n+}\n+\n+void\n+virtio_user_dev_uninit(struct virtio_user_dev *dev)\n+{\n+\tuint32_t i;\n+\n+\tfor (i = 0; i < dev->max_queue_pairs * 2; ++i) {\n+\t\tclose(dev->callfds[i]);\n+\t\tclose(dev->kickfds[i]);\n+\t}\n+\n+\tclose(dev->vhostfd);\n+}\ndiff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.h b/drivers/net/virtio/virtio_user/virtio_user_dev.h\nnew file mode 100644\nindex 0000000..68bee37\n--- /dev/null\n+++ b/drivers/net/virtio/virtio_user/virtio_user_dev.h\n@@ -0,0 +1,62 @@\n+/*-\n+ *   BSD LICENSE\n+ *\n+ *   Copyright(c) 2010-2016 Intel Corporation. All rights reserved.\n+ *   All rights reserved.\n+ *\n+ *   Redistribution and use in source and binary forms, with or without\n+ *   modification, are permitted provided that the following conditions\n+ *   are met:\n+ *\n+ *     * Redistributions of source code must retain the above copyright\n+ *       notice, this list of conditions and the following disclaimer.\n+ *     * Redistributions in binary form must reproduce the above copyright\n+ *       notice, this list of conditions and the following disclaimer in\n+ *       the documentation and/or other materials provided with the\n+ *       distribution.\n+ *     * Neither the name of Intel Corporation nor the names of its\n+ *       contributors may be used to endorse or promote products derived\n+ *       from this software without specific prior written permission.\n+ *\n+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n+ *   \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n+ */\n+\n+#ifndef _VIRTIO_USER_DEV_H\n+#define _VIRTIO_USER_DEV_H\n+\n+#include <limits.h>\n+#include \"../virtio_pci.h\"\n+#include \"../virtio_ring.h\"\n+\n+struct virtio_user_dev {\n+\tint\t\tvhostfd;\n+\tint\t\tcallfds[VIRTIO_MAX_VIRTQUEUES * 2 + 1];\n+\tint\t\tkickfds[VIRTIO_MAX_VIRTQUEUES * 2 + 1];\n+\tint\t\tmac_specified;\n+\tuint32_t\tmax_queue_pairs;\n+\tuint32_t\tqueue_pairs;\n+\tuint32_t\tqueue_size;\n+\tuint64_t\tfeatures;\n+\tuint8_t\t\tstatus;\n+\tuint8_t\t\tmac_addr[ETHER_ADDR_LEN];\n+\tchar\t\tpath[PATH_MAX];\n+\tstruct vring\tvrings[VIRTIO_MAX_VIRTQUEUES * 2 + 1];\n+};\n+\n+int virtio_user_start_device(struct virtio_user_dev *dev);\n+int virtio_user_stop_device(struct virtio_user_dev *dev);\n+int virtio_user_dev_init(struct virtio_user_dev *dev, char *path, int queues,\n+\t\t\t int cq, int queue_size, const char *mac);\n+void virtio_user_dev_uninit(struct virtio_user_dev *dev);\n+\n+#endif\n",
    "prefixes": [
        "dpdk-dev",
        "v9",
        "4/6"
    ]
}