Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/patches/13097/?format=api
http://patches.dpdk.org/api/patches/13097/?format=api", "web_url": "http://patches.dpdk.org/project/dpdk/patch/1464605739-140761-7-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": "<1464605739-140761-7-git-send-email-jianfeng.tan@intel.com>", "list_archive_url": "https://inbox.dpdk.org/dev/1464605739-140761-7-git-send-email-jianfeng.tan@intel.com", "date": "2016-05-30T10:55:37", "name": "[dpdk-dev,v5,6/8] virtio-user: add new virtual pci driver for virtio", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": true, "hash": "693eb9ff851265682888b010c6c27b5ff21aff72", "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/1464605739-140761-7-git-send-email-jianfeng.tan@intel.com/mbox/", "series": [], "comments": "http://patches.dpdk.org/api/patches/13097/comments/", "check": "pending", "checks": "http://patches.dpdk.org/api/patches/13097/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 2BDD66C96;\n\tMon, 30 May 2016 12:56:08 +0200 (CEST)", "from mga03.intel.com (mga03.intel.com [134.134.136.65])\n\tby dpdk.org (Postfix) with ESMTP id EDAD36C94\n\tfor <dev@dpdk.org>; Mon, 30 May 2016 12:56:04 +0200 (CEST)", "from fmsmga004.fm.intel.com ([10.253.24.48])\n\tby orsmga103.jf.intel.com with ESMTP; 30 May 2016 03:56:04 -0700", "from dpdk06.sh.intel.com ([10.239.128.225])\n\tby fmsmga004.fm.intel.com with ESMTP; 30 May 2016 03:56:03 -0700" ], "X-ExtLoop1": "1", "X-IronPort-AV": "E=Sophos;i=\"5.26,389,1459839600\"; d=\"scan'208\";a=\"112799764\"", "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": "Mon, 30 May 2016 10:55:37 +0000", "Message-Id": "<1464605739-140761-7-git-send-email-jianfeng.tan@intel.com>", "X-Mailer": "git-send-email 2.1.4", "In-Reply-To": "<1464605739-140761-1-git-send-email-jianfeng.tan@intel.com>", "References": "<1446748276-132087-1-git-send-email-jianfeng.tan@intel.com>\n\t<1464605739-140761-1-git-send-email-jianfeng.tan@intel.com>", "Subject": "[dpdk-dev] [PATCH v5 6/8] virtio-user: add new virtual pci driver\n\tfor virtio", "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": "This patch implements another new instance of struct virtio_pci_ops to\ndrive the virtio-user virtual device. Instead of rd/wr ioport or PCI\nconfiguration space, this virtual pci driver will rd/wr the virtual\ndevice struct virtio_user_hw, and when necessary, invokes APIs provided\nby device emulation later to start/stop the device.\n\n ----------------------\n | ------------------ |\n | | virtio driver | |----> (virtio_user_pci.c)\n | ------------------ |\n | | |\n | ------------------ | ------> virtio-user PMD\n | | device emulate | |\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_pci.h | 1 +\n drivers/net/virtio/virtio_user/virtio_user_dev.h | 2 +\n drivers/net/virtio/virtio_user/virtio_user_pci.c | 218 +++++++++++++++++++++++\n 4 files changed, 222 insertions(+)\n create mode 100644 drivers/net/virtio/virtio_user/virtio_user_pci.c", "diff": "diff --git a/drivers/net/virtio/Makefile b/drivers/net/virtio/Makefile\nindex 68068bd..13b2b75 100644\n--- a/drivers/net/virtio/Makefile\n+++ b/drivers/net/virtio/Makefile\n@@ -60,6 +60,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_VIRTIO_PMD) += virtio_user/vhost.c\n SRCS-$(CONFIG_RTE_LIBRTE_VIRTIO_PMD) += virtio_user/vhost_user.c\n SRCS-$(CONFIG_RTE_LIBRTE_VIRTIO_PMD) += virtio_user/vhost_kernel.c\n SRCS-$(CONFIG_RTE_LIBRTE_VIRTIO_PMD) += virtio_user/virtio_user_dev.c\n+SRCS-$(CONFIG_RTE_LIBRTE_VIRTIO_PMD) += virtio_user/virtio_user_pci.c\n endif\n \n # this lib depends upon:\ndiff --git a/drivers/net/virtio/virtio_pci.h b/drivers/net/virtio/virtio_pci.h\nindex a76daf7..d10d013 100644\n--- a/drivers/net/virtio/virtio_pci.h\n+++ b/drivers/net/virtio/virtio_pci.h\n@@ -260,6 +260,7 @@ struct virtio_hw {\n \tstruct virtio_pci_common_cfg *common_cfg;\n \tstruct virtio_net_config *dev_cfg;\n \tconst struct virtio_pci_ops *vtpci_ops;\n+\tvoid\t *virtio_user_dev;\n };\n \n /*\ndiff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.h b/drivers/net/virtio/virtio_user/virtio_user_dev.h\nindex 8ca0095..9ebe440 100644\n--- a/drivers/net/virtio/virtio_user/virtio_user_dev.h\n+++ b/drivers/net/virtio/virtio_user/virtio_user_dev.h\n@@ -57,4 +57,6 @@ struct virtio_user_dev {\n int virtio_user_start_device(struct virtio_user_dev *dev);\n int virtio_user_stop_device(struct virtio_user_dev *dev);\n \n+const struct virtio_pci_ops vdev_ops;\n+\n #endif\ndiff --git a/drivers/net/virtio/virtio_user/virtio_user_pci.c b/drivers/net/virtio/virtio_user/virtio_user_pci.c\nnew file mode 100644\nindex 0000000..b56419b\n--- /dev/null\n+++ b/drivers/net/virtio/virtio_user/virtio_user_pci.c\n@@ -0,0 +1,218 @@\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 <sys/types.h>\n+#include <unistd.h>\n+\n+#include \"../virtio_logs.h\"\n+#include \"../virtio_pci.h\"\n+#include \"../virtqueue.h\"\n+#include \"virtio_user_dev.h\"\n+\n+#define virtio_user_get_dev(hw) \\\n+\t((struct virtio_user_dev *)(hw)->virtio_user_dev);\n+\n+static void\n+vdev_read_dev_config(struct virtio_hw *hw, uint64_t offset,\n+\t\t void *dst, int length)\n+{\n+\tint i;\n+\tstruct virtio_user_dev *dev = virtio_user_get_dev(hw);\n+\n+\tif (offset == offsetof(struct virtio_net_config, mac) &&\n+\t length == ETHER_ADDR_LEN) {\n+\t\tfor (i = 0; i < ETHER_ADDR_LEN; ++i)\n+\t\t\t((uint8_t *)dst)[i] = dev->mac_addr[i];\n+\t\treturn;\n+\t}\n+\n+\tif (offset == offsetof(struct virtio_net_config, status))\n+\t\t*(uint16_t *)dst = dev->status;\n+\n+\tif (offset == offsetof(struct virtio_net_config, max_virtqueue_pairs))\n+\t\t*(uint16_t *)dst = dev->max_queue_pairs;\n+}\n+\n+static void\n+vdev_write_dev_config(struct virtio_hw *hw, uint64_t offset,\n+\t\t const void *src, int length)\n+{\n+\tint i;\n+\tstruct virtio_user_dev *dev = virtio_user_get_dev(hw);\n+\n+\tif ((offset == offsetof(struct virtio_net_config, mac)) &&\n+\t (length == ETHER_ADDR_LEN))\n+\t\tfor (i = 0; i < ETHER_ADDR_LEN; ++i)\n+\t\t\tdev->mac_addr[i] = ((const uint8_t *)src)[i];\n+\telse\n+\t\tPMD_DRV_LOG(ERR, \"not supported offset=%\" PRIu64 \", len=%d\\n\",\n+\t\t\t offset, length);\n+}\n+\n+static void\n+vdev_set_status(struct virtio_hw *hw, uint8_t status)\n+{\n+\tstruct virtio_user_dev *dev = virtio_user_get_dev(hw);\n+\n+\tif (status & VIRTIO_CONFIG_STATUS_DRIVER_OK)\n+\t\tvirtio_user_start_device(dev);\n+\tdev->status = status;\n+}\n+\n+static void\n+vdev_reset(struct virtio_hw *hw)\n+{\n+\tstruct virtio_user_dev *dev = virtio_user_get_dev(hw);\n+\n+\tvirtio_user_stop_device(dev);\n+}\n+\n+static uint8_t\n+vdev_get_status(struct virtio_hw *hw)\n+{\n+\tstruct virtio_user_dev *dev = virtio_user_get_dev(hw);\n+\n+\treturn dev->status;\n+}\n+\n+static uint64_t\n+vdev_get_features(struct virtio_hw *hw)\n+{\n+\tstruct virtio_user_dev *dev = virtio_user_get_dev(hw);\n+\n+\treturn dev->features;\n+}\n+\n+static void\n+vdev_set_features(struct virtio_hw *hw, uint64_t features)\n+{\n+\tstruct virtio_user_dev *dev = virtio_user_get_dev(hw);\n+\n+\tdev->features = features;\n+}\n+\n+static uint8_t\n+vdev_get_isr(struct virtio_hw *hw __rte_unused)\n+{\n+\t/* When config interrupt happens, driver calls this function to query\n+\t * what kinds of change happen. Interrupt mode not supported for now.\n+\t */\n+\treturn 0;\n+}\n+\n+static uint16_t\n+vdev_set_config_irq(struct virtio_hw *hw __rte_unused,\n+\t\t uint16_t vec __rte_unused)\n+{\n+\treturn VIRTIO_MSI_NO_VECTOR;\n+}\n+\n+/* This function is to get the queue size, aka, number of descs, of a specified\n+ * queue. Different with the VHOST_USER_GET_QUEUE_NUM, which is used to get the\n+ * max supported queues.\n+ */\n+static uint16_t\n+vdev_get_queue_num(struct virtio_hw *hw, uint16_t queue_id __rte_unused)\n+{\n+\tstruct virtio_user_dev *dev = virtio_user_get_dev(hw);\n+\n+\t/* Currently, each queue has same queue size */\n+\treturn dev->queue_size;\n+}\n+\n+static int\n+vdev_setup_queue(struct virtio_hw *hw, struct virtqueue *vq)\n+{\n+\tstruct virtio_user_dev *dev = virtio_user_get_dev(hw);\n+\tuint16_t queue_idx = vq->vq_queue_index;\n+\tuint64_t desc_addr, avail_addr, used_addr;\n+\n+\tdesc_addr = (uint64_t)vq->mz->addr;\n+\tavail_addr = desc_addr + vq->vq_nentries * sizeof(struct vring_desc);\n+\tused_addr = RTE_ALIGN_CEIL(avail_addr + offsetof(struct vring_avail,\n+\t\t\t\t\t\t\t ring[vq->vq_nentries]),\n+\t\t\t\t VIRTIO_PCI_VRING_ALIGN);\n+\n+\tdev->vrings[queue_idx].num = vq->vq_nentries;\n+\tdev->vrings[queue_idx].desc = (void *)desc_addr;\n+\tdev->vrings[queue_idx].avail = (void *)avail_addr;\n+\tdev->vrings[queue_idx].used = (void *)used_addr;\n+\n+\treturn 0;\n+}\n+\n+static void\n+vdev_del_queue(struct virtio_hw *hw, struct virtqueue *vq)\n+{\n+\t/* For legacy devices, write 0 to VIRTIO_PCI_QUEUE_PFN port, QEMU\n+\t * correspondingly stops the ioeventfds, and reset the status of\n+\t * the device.\n+\t * For modern devices, set queue desc, avail, used in PCI bar to 0,\n+\t * not see any more behavior in QEMU.\n+\t *\n+\t * Here we just care about what information to deliver to vhost-user\n+\t * or vhost-kernel. So we just close ioeventfd for now.\n+\t */\n+\tstruct virtio_user_dev *dev = virtio_user_get_dev(hw);\n+\n+\tclose(dev->callfds[vq->vq_queue_index]);\n+\tclose(dev->kickfds[vq->vq_queue_index]);\n+}\n+\n+static void\n+vdev_notify_queue(struct virtio_hw *hw, struct virtqueue *vq)\n+{\n+\tuint64_t buf = 1;\n+\tstruct virtio_user_dev *dev = virtio_user_get_dev(hw);\n+\n+\tif (write(dev->kickfds[vq->vq_queue_index], &buf, sizeof(buf)) < 0)\n+\t\tPMD_DRV_LOG(ERR, \"failed to kick backend: %s\\n\",\n+\t\t\t strerror(errno));\n+}\n+\n+const struct virtio_pci_ops vdev_ops = {\n+\t.read_dev_cfg\t= vdev_read_dev_config,\n+\t.write_dev_cfg\t= vdev_write_dev_config,\n+\t.reset\t\t= vdev_reset,\n+\t.get_status\t= vdev_get_status,\n+\t.set_status\t= vdev_set_status,\n+\t.get_features\t= vdev_get_features,\n+\t.set_features\t= vdev_set_features,\n+\t.get_isr\t= vdev_get_isr,\n+\t.set_config_irq\t= vdev_set_config_irq,\n+\t.get_queue_num\t= vdev_get_queue_num,\n+\t.setup_queue\t= vdev_setup_queue,\n+\t.del_queue\t= vdev_del_queue,\n+\t.notify_queue\t= vdev_notify_queue,\n+};\n", "prefixes": [ "dpdk-dev", "v5", "6/8" ] }{ "id": 13097, "url": "