get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

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

{
    "id": 86514,
    "url": "http://patches.dpdk.org/api/patches/86514/?format=api",
    "web_url": "http://patches.dpdk.org/project/dpdk/patch/20210114062512.45462-7-chenbo.xia@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": "<20210114062512.45462-7-chenbo.xia@intel.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/20210114062512.45462-7-chenbo.xia@intel.com",
    "date": "2021-01-14T06:25:10",
    "name": "[v3,6/8] emu/iavf: add emudev operations to fit in emudev framework",
    "commit_ref": null,
    "pull_url": null,
    "state": "changes-requested",
    "archived": true,
    "hash": "13ecdffd86a2e39ebafdf1a671bedbff134b055b",
    "submitter": {
        "id": 1276,
        "url": "http://patches.dpdk.org/api/people/1276/?format=api",
        "name": "Chenbo Xia",
        "email": "chenbo.xia@intel.com"
    },
    "delegate": {
        "id": 1,
        "url": "http://patches.dpdk.org/api/users/1/?format=api",
        "username": "tmonjalo",
        "first_name": "Thomas",
        "last_name": "Monjalon",
        "email": "thomas@monjalon.net"
    },
    "mbox": "http://patches.dpdk.org/project/dpdk/patch/20210114062512.45462-7-chenbo.xia@intel.com/mbox/",
    "series": [
        {
            "id": 14712,
            "url": "http://patches.dpdk.org/api/series/14712/?format=api",
            "web_url": "http://patches.dpdk.org/project/dpdk/list/?series=14712",
            "date": "2021-01-14T06:25:04",
            "name": "Introduce emudev library and iavf emudev driver",
            "version": 3,
            "mbox": "http://patches.dpdk.org/series/14712/mbox/"
        }
    ],
    "comments": "http://patches.dpdk.org/api/patches/86514/comments/",
    "check": "success",
    "checks": "http://patches.dpdk.org/api/patches/86514/checks/",
    "tags": {},
    "related": [],
    "headers": {
        "Return-Path": "<dev-bounces@dpdk.org>",
        "X-Original-To": "patchwork@inbox.dpdk.org",
        "Delivered-To": "patchwork@inbox.dpdk.org",
        "Received": [
            "from mails.dpdk.org (mails.dpdk.org [217.70.189.124])\n\tby inbox.dpdk.org (Postfix) with ESMTP id 16D6DA0A02;\n\tThu, 14 Jan 2021 07:31:07 +0100 (CET)",
            "from [217.70.189.124] (localhost [127.0.0.1])\n\tby mails.dpdk.org (Postfix) with ESMTP id E5A3A140E4D;\n\tThu, 14 Jan 2021 07:30:27 +0100 (CET)",
            "from mga03.intel.com (mga03.intel.com [134.134.136.65])\n by mails.dpdk.org (Postfix) with ESMTP id 2B9FE140E4B\n for <dev@dpdk.org>; Thu, 14 Jan 2021 07:30:25 +0100 (CET)",
            "from fmsmga002.fm.intel.com ([10.253.24.26])\n by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384;\n 13 Jan 2021 22:30:24 -0800",
            "from npg-dpdk-virtio-xiachenbo-nw.sh.intel.com ([10.67.119.123])\n by fmsmga002.fm.intel.com with ESMTP; 13 Jan 2021 22:30:22 -0800"
        ],
        "IronPort-SDR": [
            "\n 82L58yDrMd+0EAY8ceuLlG9jTZxsUZoiN2kXIsgK+qRK6Ngw/d9sCb0DOXC8W/OliiFvGrdnGb\n c9BLQHmni36A==",
            "\n rToLVGwONUQ299Uwy7+8NZXcPCHqaNgFgY5deYlKJ0IUNr39NLYSBujMOuTztCF0YRrdk4pRM3\n P4Hqd5De9/WA=="
        ],
        "X-IronPort-AV": [
            "E=McAfee;i=\"6000,8403,9863\"; a=\"178407172\"",
            "E=Sophos;i=\"5.79,346,1602572400\"; d=\"scan'208\";a=\"178407172\"",
            "E=Sophos;i=\"5.79,346,1602572400\"; d=\"scan'208\";a=\"400799465\""
        ],
        "X-ExtLoop1": "1",
        "From": "Chenbo Xia <chenbo.xia@intel.com>",
        "To": "dev@dpdk.org,\n\tthomas@monjalon.net,\n\tdavid.marchand@redhat.com",
        "Cc": "stephen@networkplumber.org, cunming.liang@intel.com, xiuchun.lu@intel.com,\n miao.li@intel.com, jingjing.wu@intel.com, beilei.xing@intel.com",
        "Date": "Thu, 14 Jan 2021 14:25:10 +0800",
        "Message-Id": "<20210114062512.45462-7-chenbo.xia@intel.com>",
        "X-Mailer": "git-send-email 2.17.1",
        "In-Reply-To": "<20210114062512.45462-1-chenbo.xia@intel.com>",
        "References": "<20201219062806.56477-1-chenbo.xia@intel.com>\n <20210114062512.45462-1-chenbo.xia@intel.com>",
        "Subject": "[dpdk-dev] [PATCH v3 6/8] emu/iavf: add emudev operations to fit in\n emudev framework",
        "X-BeenThere": "dev@dpdk.org",
        "X-Mailman-Version": "2.1.29",
        "Precedence": "list",
        "List-Id": "DPDK patches and discussions <dev.dpdk.org>",
        "List-Unsubscribe": "<https://mails.dpdk.org/options/dev>,\n <mailto:dev-request@dpdk.org?subject=unsubscribe>",
        "List-Archive": "<http://mails.dpdk.org/archives/dev/>",
        "List-Post": "<mailto:dev@dpdk.org>",
        "List-Help": "<mailto:dev-request@dpdk.org?subject=help>",
        "List-Subscribe": "<https://mails.dpdk.org/listinfo/dev>,\n <mailto:dev-request@dpdk.org?subject=subscribe>",
        "Errors-To": "dev-bounces@dpdk.org",
        "Sender": "\"dev\" <dev-bounces@dpdk.org>"
    },
    "content": "This patch implements emudev operations to make emulated iavf\nfit into rte_emudev framework. Lifecycle related and device\nresource related operations are both implemented.\n\nSigned-off-by: Chenbo Xia <chenbo.xia@intel.com>\nSigned-off-by: Xiuchun Lu <xiuchun.lu@intel.com>\n---\n drivers/emu/iavf/iavf_emu.c     | 229 ++++++++++++++++++++++++++++++++\n drivers/emu/iavf/rte_iavf_emu.h |  59 ++++++++\n 2 files changed, 288 insertions(+)",
    "diff": "diff --git a/drivers/emu/iavf/iavf_emu.c b/drivers/emu/iavf/iavf_emu.c\nindex 7506849e42..cc56ec1c4b 100644\n--- a/drivers/emu/iavf/iavf_emu.c\n+++ b/drivers/emu/iavf/iavf_emu.c\n@@ -2,7 +2,75 @@\n  * Copyright(c) 2020 Intel Corporation\n  */\n \n+#include <stdint.h>\n+#include <string.h>\n+#include <unistd.h>\n+\n+#include <rte_malloc.h>\n+#include <rte_emudev.h>\n+\n #include \"iavf_vfio_user.h\"\n+#include <iavf_type.h>\n+\n+static int\n+iavf_emu_dev_start(struct rte_emudev *dev)\n+{\n+\tstruct iavf_emudev *iavf = (struct iavf_emudev *)dev->priv_data;\n+\n+\tif (iavf->ops != NULL && iavf->ops->device_start != NULL)\n+\t\tiavf->ops->device_start(dev);\n+\n+\treturn 0;\n+}\n+\n+static void\n+iavf_emu_dev_stop(struct rte_emudev *dev)\n+{\n+\tstruct iavf_emudev *iavf = (struct iavf_emudev *)dev->priv_data;\n+\n+\tif (iavf->ops != NULL && iavf->ops->device_stop != NULL)\n+\t\tiavf->ops->device_stop(dev);\n+}\n+\n+static int\n+iavf_emu_dev_configure(struct rte_emudev *dev,\n+\t\tstruct rte_emudev_info *dev_conf)\n+{\n+\tstruct iavf_emudev *iavf = (struct iavf_emudev *)dev->priv_data;\n+\tstruct rte_iavf_emu_config *conf =\n+\t\t(struct rte_iavf_emu_config *)dev_conf->dev_priv;\n+\n+\tif (!dev_conf->dev_priv)\n+\t\treturn -EINVAL;\n+\n+\t/* Currently emulated iavf does not support max_qp_num\n+\t * and region num configuration\n+\t */\n+\tif (dev->dev_info.max_qp_num != dev_conf->max_qp_num ||\n+\t\tdev->dev_info.region_num != dev_conf->region_num) {\n+\t\tEMU_IAVF_LOG(ERR,\n+\t\t\t\"Configure max_qp_num/region num not supported\\n\");\n+\t\treturn -ENOTSUP;\n+\t}\n+\n+\tif (conf->qp_num >  RTE_MAX_QUEUES_PER_PORT ||\n+\t\tconf->qp_num > RTE_IAVF_EMU_MAX_QP_NUM) {\n+\t\tEMU_IAVF_LOG(ERR, \"Queue pair num exceeds max\\n\");\n+\t\treturn -EINVAL;\n+\t}\n+\n+\t/* For now, we don't support device configure when data\n+\t * path driver is attached\n+\t */\n+\tif (dev->backend_priv) {\n+\t\tEMU_IAVF_LOG(ERR, \"Configure failed because of \"\n+\t\t\t\"data path attached\\n\");\n+\t\treturn -EPERM;\n+\t}\n+\n+\tiavf->max_be_lanqp = conf->qp_num;\n+\treturn 0;\n+}\n \n static int\n iavf_emu_dev_close(struct rte_emudev *dev)\n@@ -27,6 +95,167 @@ iavf_emu_dev_close(struct rte_emudev *dev)\n \treturn 0;\n }\n \n+static int\n+iavf_emu_get_dev_info(struct rte_emudev *dev,\n+\trte_emudev_obj_t info)\n+{\n+\tstruct iavf_emudev *iavf = (struct iavf_emudev *)dev->priv_data;\n+\tstruct rte_iavf_emu_config *conf = (struct rte_iavf_emu_config *)info;\n+\n+\tif (!info)\n+\t\treturn -EINVAL;\n+\n+\tconf->qp_num = iavf->max_be_lanqp;\n+\treturn 0;\n+}\n+\n+static int\n+iavf_emu_get_mem_table(struct rte_emudev *dev,\n+\trte_emudev_mem_table_t *tb)\n+{\n+\tstruct iavf_emudev *iavf = (struct iavf_emudev *)dev->priv_data;\n+\n+\t*tb = iavf->mem;\n+\n+\treturn 0;\n+}\n+\n+static int\n+iavf_emu_get_queue_info(struct rte_emudev *dev, uint32_t queue,\n+\t\tstruct rte_emudev_q_info *info)\n+{\n+\tstruct iavf_emudev *iavf = (struct iavf_emudev *)dev->priv_data;\n+\n+\tif (queue < RTE_IAVF_EMU_ADMINQ_NUM) {\n+\t\tstruct iavf_emu_adminQ *adq = &iavf->adq[queue];\n+\t\tuint64_t base, size;\n+\n+\t\tif (adq->ring_addr_lo == NULL ||\n+\t\t    adq->ring_addr_hi == NULL ||\n+\t\t    adq->ring_sz == NULL)\n+\t\t\treturn -1;\n+\t\tbase = RTE_IAVF_EMU_32_TO_64(*adq->ring_addr_hi,\n+\t\t\t*adq->ring_addr_lo);\n+\t\tsize = *adq->ring_sz;\n+\t\tinfo->base = base;\n+\t\tinfo->size = size;\n+\t\tinfo->doorbell_id = queue;\n+\t\t/* RX AdminQ should have IRQ vector 0 */\n+\t\tinfo->irq_vector = queue - 1;\n+\t} else {\n+\t\tinfo->base = 0;\n+\t\tinfo->size = 0;\n+\t\tinfo->doorbell_id = queue;\n+\t\tinfo->irq_vector = -1;\n+\t}\n+\n+\treturn 0;\n+}\n+\n+static int\n+iavf_emu_get_irq_info(struct rte_emudev *dev, uint32_t vector,\n+\t\tstruct rte_emudev_irq_info *info)\n+{\n+\tstruct iavf_emudev *iavf = (struct iavf_emudev *)dev->priv_data;\n+\tstruct iavf_emu_intr *intr = iavf->intr;\n+\tstruct iavf_emu_intr_info *intr_info = &intr->info[vector];\n+\n+\tif (vector >= intr->intr_num)\n+\t\treturn -EINVAL;\n+\n+\tinfo->eventfd = intr_info->fd;\n+\tinfo->enable = intr_info->enable;\n+\tinfo->vector = vector;\n+\n+\treturn 0;\n+}\n+\n+static int\n+iavf_emu_get_db_info(struct rte_emudev *dev, uint32_t doorbell,\n+\t\tstruct rte_emudev_db_info *info)\n+{\n+\tstruct iavf_emudev *iavf = (struct iavf_emudev *)dev->priv_data;\n+\n+\tif (doorbell < RTE_IAVF_EMU_ADMINQ_NUM) {\n+\t\tstruct iavf_emu_adminQ *adq = &iavf->adq[doorbell];\n+\n+\t\tinfo->data.mem.base = (uint64_t)adq->doorbell;\n+\t\tinfo->data.mem.size = adq->db_size;\n+\t} else {\n+\t\tstruct iavf_emu_lanQ *lanq =\n+\t\t\t&iavf->lanq[doorbell - RTE_IAVF_EMU_ADMINQ_NUM];\n+\n+\t\tinfo->data.mem.base = (uint64_t)lanq->doorbell;\n+\t\tinfo->data.mem.size = lanq->db_size;\n+\t}\n+\n+\tinfo->flag |= RTE_EMUDEV_DB_MEM;\n+\tinfo->id = doorbell;\n+\n+\treturn 0;\n+}\n+\n+static int\n+iavf_emu_subs_ev(struct rte_emudev *dev,\n+\trte_emudev_event_chnl_t ev_chnl)\n+{\n+\tstruct iavf_emudev *iavf = (struct iavf_emudev *)dev->priv_data;\n+\n+\tiavf->ops = (struct rte_iavf_emu_notify_ops *)ev_chnl;\n+\n+\treturn 0;\n+}\n+\n+static int\n+iavf_emu_unsubs_ev(struct rte_emudev *dev,\n+\t\trte_emudev_event_chnl_t ev_chnl)\n+{\n+\tstruct iavf_emudev *iavf = (struct iavf_emudev *)dev->priv_data;\n+\n+\tif ((struct rte_iavf_emu_notify_ops *)ev_chnl == iavf->ops) {\n+\t\tiavf->ops = NULL;\n+\t\treturn 0;\n+\t}\n+\n+\treturn -EINVAL;\n+}\n+\n+static int\n+iavf_emu_get_attr(struct rte_emudev *dev, const char *attr_name,\n+\t\trte_emudev_attr_t attr)\n+{\n+\tstruct iavf_emudev *iavf = (struct iavf_emudev *)dev->priv_data;\n+\tstruct rte_vfio_user_reg_info *info;\n+\tint ret = 0;\n+\n+\tinfo = &iavf->vfio->reg->reg_info[0];\n+\n+\tif (!strcmp(attr_name, RTE_IAVF_EMU_ATTR_ASQ_HEAD))\n+\t\t*(uint64_t *)attr = (uint64_t)(uintptr_t)info->base\n+\t\t\t+ IAVF_VF_ATQH1;\n+\telse if (!strcmp(attr_name, RTE_IAVF_EMU_ATTR_ARQ_HEAD))\n+\t\t*(uint64_t *)attr = (uint64_t)(uintptr_t)info->base\n+\t\t\t+ IAVF_VF_ARQH1;\n+\telse if (!strcmp(attr_name, RTE_IAVF_EMU_ATTR_RESET))\n+\t\t*(uint64_t *)attr = (uint64_t)(uintptr_t)info->base\n+\t\t\t+ IAVF_VFGEN_RSTAT;\n+\telse\n+\t\tret = -EINVAL;\n+\n+\treturn ret;\n+}\n+\n struct rte_emudev_ops emu_iavf_ops = {\n+\t.dev_start = iavf_emu_dev_start,\n+\t.dev_stop = iavf_emu_dev_stop,\n+\t.dev_configure = iavf_emu_dev_configure,\n \t.dev_close = iavf_emu_dev_close,\n+\t.dev_info_get = iavf_emu_get_dev_info,\n+\t.get_mem_table = iavf_emu_get_mem_table,\n+\t.get_queue_info = iavf_emu_get_queue_info,\n+\t.get_irq_info = iavf_emu_get_irq_info,\n+\t.get_db_info = iavf_emu_get_db_info,\n+\t.subscribe_event = iavf_emu_subs_ev,\n+\t.unsubscribe_event = iavf_emu_unsubs_ev,\n+\t.get_attr = iavf_emu_get_attr,\n };\ndiff --git a/drivers/emu/iavf/rte_iavf_emu.h b/drivers/emu/iavf/rte_iavf_emu.h\nindex 6de0989f0b..2abcec97d4 100644\n--- a/drivers/emu/iavf/rte_iavf_emu.h\n+++ b/drivers/emu/iavf/rte_iavf_emu.h\n@@ -6,13 +6,24 @@\n #define _IAVF_EMU_H\n \n #include <stdint.h>\n+#include <stddef.h>\n+#include <limits.h>\n+#include <net/if.h>\n+#include <sys/queue.h>\n \n+#include <rte_vfio_user.h>\n #include <rte_emudev.h>\n \n #define RTE_IAVF_EMUDEV_TYPE \"iavf\"\n+#define RTE_IAVF_EMU_ATTR_ASQ_HEAD \"ASQ_H\"\n+#define RTE_IAVF_EMU_ATTR_ARQ_HEAD \"ARQ_H\"\n+#define RTE_IAVF_EMU_ATTR_RESET \"RESET\"\n+#define RTE_IAVF_EMU_RESET_IN_PROGRESS 0x00\n+#define RTE_IAVF_EMU_RESET_COMPLETED 0x01\n #define RTE_IAVF_EMU_MAX_MEM_REGIONS 256\n #define RTE_IAVF_EMU_MAX_QP_NUM 256\n #define RTE_IAVF_EMU_MAX_INTR 32\n+#define RTE_IAVF_EMU_32_TO_64(hi, lo) ((((uint64_t)(hi)) << 32) + (lo))\n \n enum {\n \tRTE_IAVF_EMU_ADMINQ_TXQ = 0,\n@@ -26,6 +37,11 @@ enum {\n \tRTE_IAVF_EMU_MAPPABLE_REG_NUM = 2,\n };\n \n+struct rte_iavf_emu_config {\n+\t/* Maximum queue pair number that data path driver can use */\n+\tuint32_t qp_num;\n+};\n+\n struct rte_iavf_emu_mem_reg {\n \tuint64_t guest_phys_addr;\n \tuint64_t host_user_addr;\n@@ -40,6 +56,49 @@ struct rte_iavf_emu_mem {\n \tstruct rte_iavf_emu_mem_reg regions[RTE_IAVF_EMU_MAX_MEM_REGIONS];\n };\n \n+/**\n+ * Helper function for data path driver to translate address\n+ * of one region\n+ *\n+ * @param mem\n+ *   A pointer to DMA memory table\n+ * @param g_addr\n+ *   Guest I/O virtual base address of the region\n+ * @param[in/out] len\n+ *   The length of region\n+ * @return\n+ *   - >0: Success, process virtual address returned\n+ *   - 0: Failure on translation\n+ */\n+__rte_experimental\n+__rte_always_inline uint64_t\n+rte_iavf_emu_get_dma_vaddr(struct rte_iavf_emu_mem *mem,\n+\tuint64_t g_addr, uint64_t *len)\n+{\n+\tstruct rte_iavf_emu_mem_reg *reg;\n+\tuint32_t i;\n+\n+\tfor (i = 0; i < mem->region_num; i++) {\n+\t\treg = &mem->regions[i];\n+\n+\t\tif (g_addr >= reg->guest_phys_addr &&\n+\t\t\tg_addr < reg->guest_phys_addr + reg->size) {\n+\n+\t\t\tif (unlikely(*len > reg->guest_phys_addr +\n+\t\t\t\t reg->size - g_addr))\n+\t\t\t\t*len = reg->guest_phys_addr +\n+\t\t\t\t\treg->size - g_addr;\n+\n+\t\t\treturn g_addr - reg->guest_phys_addr +\n+\t\t\t\treg->host_user_addr;\n+\t\t}\n+\t}\n+\n+\t*len = 0;\n+\n+\treturn 0;\n+}\n+\n struct rte_iavf_emu_notify_ops {\n \t/* Device is ready */\n \tint (*device_ready)(struct rte_emudev *dev);\n",
    "prefixes": [
        "v3",
        "6/8"
    ]
}