get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

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

{
    "id": 14145,
    "url": "https://patches.dpdk.org/api/patches/14145/?format=api",
    "web_url": "https://patches.dpdk.org/project/dpdk/patch/1466506555-4236-1-git-send-email-zhuangwj@gmail.com/",
    "project": {
        "id": 1,
        "url": "https://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": "<1466506555-4236-1-git-send-email-zhuangwj@gmail.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/1466506555-4236-1-git-send-email-zhuangwj@gmail.com",
    "date": "2016-06-21T10:55:52",
    "name": "[dpdk-dev,v4,1/4] port: kni interface support",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": true,
    "hash": "d074079551875c5cad91cd5b21193243b2c941ec",
    "submitter": {
        "id": 492,
        "url": "https://patches.dpdk.org/api/people/492/?format=api",
        "name": "WeiJie Zhuang",
        "email": "zhuangwj@gmail.com"
    },
    "delegate": null,
    "mbox": "https://patches.dpdk.org/project/dpdk/patch/1466506555-4236-1-git-send-email-zhuangwj@gmail.com/mbox/",
    "series": [],
    "comments": "https://patches.dpdk.org/api/patches/14145/comments/",
    "check": "pending",
    "checks": "https://patches.dpdk.org/api/patches/14145/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 2F552ADE2;\n\tTue, 21 Jun 2016 12:58:10 +0200 (CEST)",
            "from mail-pf0-f194.google.com (mail-pf0-f194.google.com\n\t[209.85.192.194]) by dpdk.org (Postfix) with ESMTP id C9486ADE1\n\tfor <dev@dpdk.org>; Tue, 21 Jun 2016 12:58:08 +0200 (CEST)",
            "by mail-pf0-f194.google.com with SMTP id c74so1169478pfb.0\n\tfor <dev@dpdk.org>; Tue, 21 Jun 2016 03:58:08 -0700 (PDT)",
            "from localhost.localdomain ([103.17.196.228])\n\tby smtp.gmail.com with ESMTPSA id\n\tg189sm24175083pfc.46.2016.06.21.03.57.42\n\t(version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128);\n\tTue, 21 Jun 2016 03:58:07 -0700 (PDT)"
        ],
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;\n\th=from:to:cc:subject:date:message-id:in-reply-to:references;\n\tbh=+Q7hWCf3Fr4MbLweUu3Dqj0ocT6nfiDG08C9JAAHJqQ=;\n\tb=O9+wFqfu40xc5llJHIs7HgEQrC1lOJl5K+i25K3/Hh7YsY0JFR/TxkZkoNnIoT7iz0\n\t+BJlGfeg33K6I8u9gGz8LUKGANorxoJyP8s6lik984CjvHSA+HzTpLrUXcNxx/OG6EE+\n\t9XndYAR62yPZu6TV/P9XKRkTk0TOKqzKNr/08SZke4LD2xMW0GeYvpYz+Su3LN3HirmT\n\tutIy76+SPFb6cX9w5lBvZyhtx+ik5E6gCdQ4zZ9rfDg6h9Mu0IshrWpVHC0DPBHyiNVF\n\ts9czq8CQC2RZQqrs6xW1K6d6XGnkClFpn3xrW78M1rQJbckAK/HRVphW52mS4J9ROwqY\n\tXz4w==",
        "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20130820;\n\th=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\n\t:references;\n\tbh=+Q7hWCf3Fr4MbLweUu3Dqj0ocT6nfiDG08C9JAAHJqQ=;\n\tb=aWoyxkoy+ejGTRuZfqAlfGPDKBWt+SBcUmY9ljahQ57qLrAOUtzlpLIqI+WwhZSlL9\n\tP9K1IpXZKkMF8cuN5ZVNAe4TTsBu8NH3JyqX9X0KCjjPYu5phRaXm5k9g+tqWa6U3nyx\n\tWUTJrokpNUG5P9Wk9NgckX9vyyCE4Js/uTZxJd3EaHXeHLPYtdCUfEEyp8QPd6Ho8a6W\n\t5d5FyI/WV2M2nEZ27Ok/IWMycm06BL0B5sbrGkrdZZwS0jtGC0nrbbGH8zMX7ODu74tu\n\tVJvgEdW+QXiZfy4Hmay58q1otjIgw8tJXnORV2b0BKuU/4H1/UqOk9MSsD6bhObvbpG5\n\txtAQ==",
        "X-Gm-Message-State": "ALyK8tK+BwQ7sCq7lYBEDhzO/o2UtUAsx3qu5FChzfdg/WUNVDPsOUGDkf7OPFk/OB+LeQ==",
        "X-Received": "by 10.98.40.4 with SMTP id o4mr27582991pfo.165.1466506687860;\n\tTue, 21 Jun 2016 03:58:07 -0700 (PDT)",
        "From": "Ethan Zhuang <zhuangwj@gmail.com>",
        "To": "cristian.dumitrescu@intel.com",
        "Cc": "dev@dpdk.org, jasvinder.singh@intel.com, ferruh.yigit@intel.com,\n\tWeiJie Zhuang <zhuangwj@gmail.com>",
        "Date": "Tue, 21 Jun 2016 18:55:52 +0800",
        "Message-Id": "<1466506555-4236-1-git-send-email-zhuangwj@gmail.com>",
        "X-Mailer": "git-send-email 2.6.4.windows.1",
        "In-Reply-To": "<1464434757-10860-1-git-send-email-zhuangwj@gmail.com>",
        "References": "<1464434757-10860-1-git-send-email-zhuangwj@gmail.com>",
        "Subject": "[dpdk-dev] [PATCH v4 1/4] port: kni interface support",
        "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": "From: WeiJie Zhuang <zhuangwj@gmail.com>\n\nadd KNI port type to the packet framework\n\nSigned-off-by: WeiJie Zhuang <zhuangwj@gmail.com>\n---\nv2:\n* Fix check patch error.\nv3:\n* Fix code review comments.\nv4:\n* Reorganize patch sets and fix some comments\n---\n lib/librte_port/Makefile             |   7 +\n lib/librte_port/rte_port_kni.c       | 545 +++++++++++++++++++++++++++++++++++\n lib/librte_port/rte_port_kni.h       |  95 ++++++\n lib/librte_port/rte_port_version.map |   9 +\n 4 files changed, 656 insertions(+)\n create mode 100644 lib/librte_port/rte_port_kni.c\n create mode 100644 lib/librte_port/rte_port_kni.h",
    "diff": "diff --git a/lib/librte_port/Makefile b/lib/librte_port/Makefile\nindex dc6a601..0fc929b 100644\n--- a/lib/librte_port/Makefile\n+++ b/lib/librte_port/Makefile\n@@ -56,6 +56,9 @@ SRCS-$(CONFIG_RTE_LIBRTE_PORT) += rte_port_frag.c\n SRCS-$(CONFIG_RTE_LIBRTE_PORT) += rte_port_ras.c\n endif\n SRCS-$(CONFIG_RTE_LIBRTE_PORT) += rte_port_sched.c\n+ifeq ($(CONFIG_RTE_LIBRTE_KNI),y)\n+SRCS-$(CONFIG_RTE_LIBRTE_PORT) += rte_port_kni.c\n+endif\n SRCS-$(CONFIG_RTE_LIBRTE_PORT) += rte_port_source_sink.c\n \n # install includes\n@@ -67,6 +70,9 @@ SYMLINK-$(CONFIG_RTE_LIBRTE_PORT)-include += rte_port_frag.h\n SYMLINK-$(CONFIG_RTE_LIBRTE_PORT)-include += rte_port_ras.h\n endif\n SYMLINK-$(CONFIG_RTE_LIBRTE_PORT)-include += rte_port_sched.h\n+ifeq ($(CONFIG_RTE_LIBRTE_KNI),y)\n+SYMLINK-$(CONFIG_RTE_LIBRTE_PORT)-include += rte_port_kni.h\n+endif\n SYMLINK-$(CONFIG_RTE_LIBRTE_PORT)-include += rte_port_source_sink.h\n \n # this lib depends upon:\n@@ -76,5 +82,6 @@ DEPDIRS-$(CONFIG_RTE_LIBRTE_PORT) += lib/librte_mempool\n DEPDIRS-$(CONFIG_RTE_LIBRTE_PORT) += lib/librte_ether\n DEPDIRS-$(CONFIG_RTE_LIBRTE_PORT) += lib/librte_ip_frag\n DEPDIRS-$(CONFIG_RTE_LIBRTE_PORT) += lib/librte_sched\n+DEPDIRS-$(CONFIG_RTE_LIBRTE_PORT) += lib/librte_kni\n \n include $(RTE_SDK)/mk/rte.lib.mk\ndiff --git a/lib/librte_port/rte_port_kni.c b/lib/librte_port/rte_port_kni.c\nnew file mode 100644\nindex 0000000..08f4ac2\n--- /dev/null\n+++ b/lib/librte_port/rte_port_kni.c\n@@ -0,0 +1,545 @@\n+/*-\n+ *   BSD LICENSE\n+ *\n+ *   Copyright(c) 2016 Ethan Zhuang <zhuangwj@gmail.com>.\n+ *   Copyright(c) 2016 Intel Corporation.\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+#include <string.h>\n+\n+#include <rte_common.h>\n+#include <rte_malloc.h>\n+#include <rte_kni.h>\n+\n+#include \"rte_port_kni.h\"\n+\n+/*\n+ * Port KNI Reader\n+ */\n+#ifdef RTE_PORT_STATS_COLLECT\n+\n+#define RTE_PORT_KNI_READER_STATS_PKTS_IN_ADD(port, val) \\\n+\tport->stats.n_pkts_in += val\n+#define RTE_PORT_KNI_READER_STATS_PKTS_DROP_ADD(port, val) \\\n+\tport->stats.n_pkts_drop += val\n+\n+#else\n+\n+#define RTE_PORT_KNI_READER_STATS_PKTS_IN_ADD(port, val)\n+#define RTE_PORT_KNI_READER_STATS_PKTS_DROP_ADD(port, val)\n+\n+#endif\n+\n+struct rte_port_kni_reader {\n+\tstruct rte_port_in_stats stats;\n+\n+\tstruct rte_kni *kni;\n+};\n+\n+static void *\n+rte_port_kni_reader_create(void *params, int socket_id)\n+{\n+\tstruct rte_port_kni_reader_params *conf =\n+\t\t\t(struct rte_port_kni_reader_params *) params;\n+\tstruct rte_port_kni_reader *port;\n+\n+\t/* Check input parameters */\n+\tif (conf == NULL) {\n+\t\tRTE_LOG(ERR, PORT, \"%s: params is NULL\\n\", __func__);\n+\t\treturn NULL;\n+\t}\n+\n+\t/* Memory allocation */\n+\tport = rte_zmalloc_socket(\"PORT\", sizeof(*port),\n+\t\tRTE_CACHE_LINE_SIZE, socket_id);\n+\tif (port == NULL) {\n+\t\tRTE_LOG(ERR, PORT, \"%s: Failed to allocate port\\n\", __func__);\n+\t\treturn NULL;\n+\t}\n+\n+\t/* Initialization */\n+\tport->kni = conf->kni;\n+\n+\treturn port;\n+}\n+\n+static int\n+rte_port_kni_reader_rx(void *port, struct rte_mbuf **pkts, uint32_t n_pkts)\n+{\n+\tstruct rte_port_kni_reader *p =\n+\t\t\t(struct rte_port_kni_reader *) port;\n+\tuint16_t rx_pkt_cnt;\n+\n+\trx_pkt_cnt = rte_kni_rx_burst(p->kni, pkts, n_pkts);\n+\tRTE_PORT_KNI_READER_STATS_PKTS_IN_ADD(p, rx_pkt_cnt);\n+\treturn rx_pkt_cnt;\n+}\n+\n+static int\n+rte_port_kni_reader_free(void *port)\n+{\n+\tif (port == NULL) {\n+\t\tRTE_LOG(ERR, PORT, \"%s: port is NULL\\n\", __func__);\n+\t\treturn -EINVAL;\n+\t}\n+\n+\trte_free(port);\n+\n+\treturn 0;\n+}\n+\n+static int rte_port_kni_reader_stats_read(void *port,\n+\tstruct rte_port_in_stats *stats, int clear)\n+{\n+\tstruct rte_port_kni_reader *p =\n+\t\t\t(struct rte_port_kni_reader *) port;\n+\n+\tif (stats != NULL)\n+\t\tmemcpy(stats, &p->stats, sizeof(p->stats));\n+\n+\tif (clear)\n+\t\tmemset(&p->stats, 0, sizeof(p->stats));\n+\n+\treturn 0;\n+}\n+\n+/*\n+ * Port KNI Writer\n+ */\n+#ifdef RTE_PORT_STATS_COLLECT\n+\n+#define RTE_PORT_KNI_WRITER_STATS_PKTS_IN_ADD(port, val) \\\n+\tport->stats.n_pkts_in += val\n+#define RTE_PORT_KNI_WRITER_STATS_PKTS_DROP_ADD(port, val) \\\n+\tport->stats.n_pkts_drop += val\n+\n+#else\n+\n+#define RTE_PORT_KNI_WRITER_STATS_PKTS_IN_ADD(port, val)\n+#define RTE_PORT_KNI_WRITER_STATS_PKTS_DROP_ADD(port, val)\n+\n+#endif\n+\n+struct rte_port_kni_writer {\n+\tstruct rte_port_out_stats stats;\n+\n+\tstruct rte_mbuf *tx_buf[2 * RTE_PORT_IN_BURST_SIZE_MAX];\n+\tuint32_t tx_burst_sz;\n+\tuint32_t tx_buf_count;\n+\tuint64_t bsz_mask;\n+\tstruct rte_kni *kni;\n+};\n+\n+static void *\n+rte_port_kni_writer_create(void *params, int socket_id)\n+{\n+\tstruct rte_port_kni_writer_params *conf =\n+\t\t\t(struct rte_port_kni_writer_params *) params;\n+\tstruct rte_port_kni_writer *port;\n+\n+\t/* Check input parameters */\n+\tif ((conf == NULL) ||\n+\t\t(conf->tx_burst_sz == 0) ||\n+\t\t(conf->tx_burst_sz > RTE_PORT_IN_BURST_SIZE_MAX) ||\n+\t\t(!rte_is_power_of_2(conf->tx_burst_sz))) {\n+\t\tRTE_LOG(ERR, PORT, \"%s: Invalid input parameters\\n\", __func__);\n+\t\treturn NULL;\n+\t}\n+\n+\t/* Memory allocation */\n+\tport = rte_zmalloc_socket(\"PORT\", sizeof(*port),\n+\t\tRTE_CACHE_LINE_SIZE, socket_id);\n+\tif (port == NULL) {\n+\t\tRTE_LOG(ERR, PORT, \"%s: Failed to allocate port\\n\", __func__);\n+\t\treturn NULL;\n+\t}\n+\n+\t/* Initialization */\n+\tport->kni = conf->kni;\n+\tport->tx_burst_sz = conf->tx_burst_sz;\n+\tport->tx_buf_count = 0;\n+\tport->bsz_mask = 1LLU << (conf->tx_burst_sz - 1);\n+\n+\treturn port;\n+}\n+\n+static inline void\n+send_burst(struct rte_port_kni_writer *p)\n+{\n+\tuint32_t nb_tx;\n+\n+\tnb_tx = rte_kni_tx_burst(p->kni, p->tx_buf, p->tx_buf_count);\n+\n+\tRTE_PORT_KNI_WRITER_STATS_PKTS_DROP_ADD(p, p->tx_buf_count - nb_tx);\n+\tfor (; nb_tx < p->tx_buf_count; nb_tx++)\n+\t\trte_pktmbuf_free(p->tx_buf[nb_tx]);\n+\n+\tp->tx_buf_count = 0;\n+}\n+\n+static int\n+rte_port_kni_writer_tx(void *port, struct rte_mbuf *pkt)\n+{\n+\tstruct rte_port_kni_writer *p =\n+\t\t\t(struct rte_port_kni_writer *) port;\n+\n+\tp->tx_buf[p->tx_buf_count++] = pkt;\n+\tRTE_PORT_KNI_WRITER_STATS_PKTS_IN_ADD(p, 1);\n+\tif (p->tx_buf_count >= p->tx_burst_sz)\n+\t\tsend_burst(p);\n+\n+\treturn 0;\n+}\n+\n+static int\n+rte_port_kni_writer_tx_bulk(void *port,\n+\tstruct rte_mbuf **pkts,\n+\tuint64_t pkts_mask)\n+{\n+\tstruct rte_port_kni_writer *p =\n+\t\t\t(struct rte_port_kni_writer *) port;\n+\tuint64_t bsz_mask = p->bsz_mask;\n+\tuint32_t tx_buf_count = p->tx_buf_count;\n+\tuint64_t expr = (pkts_mask & (pkts_mask + 1)) |\n+\t\t\t\t\t((pkts_mask & bsz_mask) ^ bsz_mask);\n+\n+\tif (expr == 0) {\n+\t\tuint64_t n_pkts = __builtin_popcountll(pkts_mask);\n+\t\tuint32_t n_pkts_ok;\n+\n+\t\tif (tx_buf_count)\n+\t\t\tsend_burst(p);\n+\n+\t\tRTE_PORT_KNI_WRITER_STATS_PKTS_IN_ADD(p, n_pkts);\n+\t\tn_pkts_ok = rte_kni_tx_burst(p->kni, pkts, n_pkts);\n+\n+\t\tRTE_PORT_KNI_WRITER_STATS_PKTS_DROP_ADD(p, n_pkts - n_pkts_ok);\n+\t\tfor (; n_pkts_ok < n_pkts; n_pkts_ok++) {\n+\t\t\tstruct rte_mbuf *pkt = pkts[n_pkts_ok];\n+\n+\t\t\trte_pktmbuf_free(pkt);\n+\t\t}\n+\t} else {\n+\t\tfor (; pkts_mask;) {\n+\t\t\tuint32_t pkt_index = __builtin_ctzll(pkts_mask);\n+\t\t\tuint64_t pkt_mask = 1LLU << pkt_index;\n+\t\t\tstruct rte_mbuf *pkt = pkts[pkt_index];\n+\n+\t\t\tp->tx_buf[tx_buf_count++] = pkt;\n+\t\t\tRTE_PORT_KNI_WRITER_STATS_PKTS_IN_ADD(p, 1);\n+\t\t\tpkts_mask &= ~pkt_mask;\n+\t\t}\n+\n+\t\tp->tx_buf_count = tx_buf_count;\n+\t\tif (tx_buf_count >= p->tx_burst_sz)\n+\t\t\tsend_burst(p);\n+\t}\n+\n+\treturn 0;\n+}\n+\n+static int\n+rte_port_kni_writer_flush(void *port)\n+{\n+\tstruct rte_port_kni_writer *p =\n+\t\t\t(struct rte_port_kni_writer *) port;\n+\n+\tif (p->tx_buf_count > 0)\n+\t\tsend_burst(p);\n+\n+\treturn 0;\n+}\n+\n+static int\n+rte_port_kni_writer_free(void *port)\n+{\n+\tif (port == NULL) {\n+\t\tRTE_LOG(ERR, PORT, \"%s: Port is NULL\\n\", __func__);\n+\t\treturn -EINVAL;\n+\t}\n+\n+\trte_port_kni_writer_flush(port);\n+\trte_free(port);\n+\n+\treturn 0;\n+}\n+\n+static int rte_port_kni_writer_stats_read(void *port,\n+\tstruct rte_port_out_stats *stats, int clear)\n+{\n+\tstruct rte_port_kni_writer *p =\n+\t\t\t(struct rte_port_kni_writer *) port;\n+\n+\tif (stats != NULL)\n+\t\tmemcpy(stats, &p->stats, sizeof(p->stats));\n+\n+\tif (clear)\n+\t\tmemset(&p->stats, 0, sizeof(p->stats));\n+\n+\treturn 0;\n+}\n+\n+/*\n+ * Port KNI Writer Nodrop\n+ */\n+#ifdef RTE_PORT_STATS_COLLECT\n+\n+#define RTE_PORT_KNI_WRITER_NODROP_STATS_PKTS_IN_ADD(port, val) \\\n+\tport->stats.n_pkts_in += val\n+#define RTE_PORT_KNI_WRITER_NODROP_STATS_PKTS_DROP_ADD(port, val) \\\n+\tport->stats.n_pkts_drop += val\n+\n+#else\n+\n+#define RTE_PORT_KNI_WRITER_NODROP_STATS_PKTS_IN_ADD(port, val)\n+#define RTE_PORT_KNI_WRITER_NODROP_STATS_PKTS_DROP_ADD(port, val)\n+\n+#endif\n+\n+struct rte_port_kni_writer_nodrop {\n+\tstruct rte_port_out_stats stats;\n+\n+\tstruct rte_mbuf *tx_buf[2 * RTE_PORT_IN_BURST_SIZE_MAX];\n+\tuint32_t tx_burst_sz;\n+\tuint32_t tx_buf_count;\n+\tuint64_t bsz_mask;\n+\tuint64_t n_retries;\n+\tstruct rte_kni *kni;\n+};\n+\n+static void *\n+rte_port_kni_writer_nodrop_create(void *params, int socket_id)\n+{\n+\tstruct rte_port_kni_writer_nodrop_params *conf =\n+\t\t(struct rte_port_kni_writer_nodrop_params *) params;\n+\tstruct rte_port_kni_writer_nodrop *port;\n+\n+\t/* Check input parameters */\n+\tif ((conf == NULL) ||\n+\t\t(conf->tx_burst_sz == 0) ||\n+\t\t(conf->tx_burst_sz > RTE_PORT_IN_BURST_SIZE_MAX) ||\n+\t\t(!rte_is_power_of_2(conf->tx_burst_sz))) {\n+\t\tRTE_LOG(ERR, PORT, \"%s: Invalid input parameters\\n\", __func__);\n+\t\treturn NULL;\n+\t}\n+\n+\t/* Memory allocation */\n+\tport = rte_zmalloc_socket(\"PORT\", sizeof(*port),\n+\t\tRTE_CACHE_LINE_SIZE, socket_id);\n+\tif (port == NULL) {\n+\t\tRTE_LOG(ERR, PORT, \"%s: Failed to allocate port\\n\", __func__);\n+\t\treturn NULL;\n+\t}\n+\n+\t/* Initialization */\n+\tport->kni = conf->kni;\n+\tport->tx_burst_sz = conf->tx_burst_sz;\n+\tport->tx_buf_count = 0;\n+\tport->bsz_mask = 1LLU << (conf->tx_burst_sz - 1);\n+\n+\t/*\n+\t * When n_retries is 0 it means that we should wait for every packet to\n+\t * send no matter how many retries should it take. To limit number of\n+\t * branches in fast path, we use UINT64_MAX instead of branching.\n+\t */\n+\tport->n_retries = (conf->n_retries == 0) ? UINT64_MAX : conf->n_retries;\n+\n+\treturn port;\n+}\n+\n+static inline void\n+send_burst_nodrop(struct rte_port_kni_writer_nodrop *p)\n+{\n+\tuint32_t nb_tx = 0, i;\n+\n+\tnb_tx = rte_kni_tx_burst(p->kni, p->tx_buf, p->tx_buf_count);\n+\n+\t/* We sent all the packets in a first try */\n+\tif (nb_tx >= p->tx_buf_count) {\n+\t\tp->tx_buf_count = 0;\n+\t\treturn;\n+\t}\n+\n+\tfor (i = 0; i < p->n_retries; i++) {\n+\t\tnb_tx += rte_kni_tx_burst(p->kni,\n+\t\t\tp->tx_buf + nb_tx,\n+\t\t\tp->tx_buf_count - nb_tx);\n+\n+\t\t/* We sent all the packets in more than one try */\n+\t\tif (nb_tx >= p->tx_buf_count) {\n+\t\t\tp->tx_buf_count = 0;\n+\t\t\treturn;\n+\t\t}\n+\t}\n+\n+\t/* We didn't send the packets in maximum allowed attempts */\n+\tRTE_PORT_KNI_WRITER_NODROP_STATS_PKTS_DROP_ADD(p, p->tx_buf_count - nb_tx);\n+\tfor ( ; nb_tx < p->tx_buf_count; nb_tx++)\n+\t\trte_pktmbuf_free(p->tx_buf[nb_tx]);\n+\n+\tp->tx_buf_count = 0;\n+}\n+\n+static int\n+rte_port_kni_writer_nodrop_tx(void *port, struct rte_mbuf *pkt)\n+{\n+\tstruct rte_port_kni_writer_nodrop *p =\n+\t\t\t(struct rte_port_kni_writer_nodrop *) port;\n+\n+\tp->tx_buf[p->tx_buf_count++] = pkt;\n+\tRTE_PORT_KNI_WRITER_STATS_PKTS_IN_ADD(p, 1);\n+\tif (p->tx_buf_count >= p->tx_burst_sz)\n+\t\tsend_burst_nodrop(p);\n+\n+\treturn 0;\n+}\n+\n+static int\n+rte_port_kni_writer_nodrop_tx_bulk(void *port,\n+\tstruct rte_mbuf **pkts,\n+\tuint64_t pkts_mask)\n+{\n+\tstruct rte_port_kni_writer_nodrop *p =\n+\t\t\t(struct rte_port_kni_writer_nodrop *) port;\n+\n+\tuint64_t bsz_mask = p->bsz_mask;\n+\tuint32_t tx_buf_count = p->tx_buf_count;\n+\tuint64_t expr = (pkts_mask & (pkts_mask + 1)) |\n+\t\t\t\t\t((pkts_mask & bsz_mask) ^ bsz_mask);\n+\n+\tif (expr == 0) {\n+\t\tuint64_t n_pkts = __builtin_popcountll(pkts_mask);\n+\t\tuint32_t n_pkts_ok;\n+\n+\t\tif (tx_buf_count)\n+\t\t\tsend_burst_nodrop(p);\n+\n+\t\tRTE_PORT_KNI_WRITER_NODROP_STATS_PKTS_IN_ADD(p, n_pkts);\n+\t\tn_pkts_ok = rte_kni_tx_burst(p->kni, pkts, n_pkts);\n+\n+\t\tif (n_pkts_ok >= n_pkts)\n+\t\t\treturn 0;\n+\n+\t\t/*\n+\t\t * If we didn't manage to send all packets in single burst, move\n+\t\t * remaining packets to the buffer and call send burst.\n+\t\t */\n+\t\tfor (; n_pkts_ok < n_pkts; n_pkts_ok++) {\n+\t\t\tstruct rte_mbuf *pkt = pkts[n_pkts_ok];\n+\t\t\tp->tx_buf[p->tx_buf_count++] = pkt;\n+\t\t}\n+\t\tsend_burst_nodrop(p);\n+\t} else {\n+\t\tfor ( ; pkts_mask; ) {\n+\t\t\tuint32_t pkt_index = __builtin_ctzll(pkts_mask);\n+\t\t\tuint64_t pkt_mask = 1LLU << pkt_index;\n+\t\t\tstruct rte_mbuf *pkt = pkts[pkt_index];\n+\n+\t\t\tp->tx_buf[tx_buf_count++] = pkt;\n+\t\t\tRTE_PORT_KNI_WRITER_NODROP_STATS_PKTS_IN_ADD(p, 1);\n+\t\t\tpkts_mask &= ~pkt_mask;\n+\t\t}\n+\n+\t\tp->tx_buf_count = tx_buf_count;\n+\t\tif (tx_buf_count >= p->tx_burst_sz)\n+\t\t\tsend_burst_nodrop(p);\n+\t}\n+\n+\treturn 0;\n+}\n+\n+static int\n+rte_port_kni_writer_nodrop_flush(void *port)\n+{\n+\tstruct rte_port_kni_writer_nodrop *p =\n+\t\t(struct rte_port_kni_writer_nodrop *) port;\n+\n+\tif (p->tx_buf_count > 0)\n+\t\tsend_burst_nodrop(p);\n+\n+\treturn 0;\n+}\n+\n+static int\n+rte_port_kni_writer_nodrop_free(void *port)\n+{\n+\tif (port == NULL) {\n+\t\tRTE_LOG(ERR, PORT, \"%s: Port is NULL\\n\", __func__);\n+\t\treturn -EINVAL;\n+\t}\n+\n+\trte_port_kni_writer_nodrop_flush(port);\n+\trte_free(port);\n+\n+\treturn 0;\n+}\n+\n+static int rte_port_kni_writer_nodrop_stats_read(void *port,\n+\tstruct rte_port_out_stats *stats, int clear)\n+{\n+\tstruct rte_port_kni_writer_nodrop *p =\n+\t\t\t(struct rte_port_kni_writer_nodrop *) port;\n+\n+\tif (stats != NULL)\n+\t\tmemcpy(stats, &p->stats, sizeof(p->stats));\n+\n+\tif (clear)\n+\t\tmemset(&p->stats, 0, sizeof(p->stats));\n+\n+\treturn 0;\n+}\n+\n+\n+/*\n+ * Summary of port operations\n+ */\n+struct rte_port_in_ops rte_port_kni_reader_ops = {\n+\t.f_create = rte_port_kni_reader_create,\n+\t.f_free = rte_port_kni_reader_free,\n+\t.f_rx = rte_port_kni_reader_rx,\n+\t.f_stats = rte_port_kni_reader_stats_read,\n+};\n+\n+struct rte_port_out_ops rte_port_kni_writer_ops = {\n+\t.f_create = rte_port_kni_writer_create,\n+\t.f_free = rte_port_kni_writer_free,\n+\t.f_tx = rte_port_kni_writer_tx,\n+\t.f_tx_bulk = rte_port_kni_writer_tx_bulk,\n+\t.f_flush = rte_port_kni_writer_flush,\n+\t.f_stats = rte_port_kni_writer_stats_read,\n+};\n+\n+struct rte_port_out_ops rte_port_kni_writer_nodrop_ops = {\n+\t.f_create = rte_port_kni_writer_nodrop_create,\n+\t.f_free = rte_port_kni_writer_nodrop_free,\n+\t.f_tx = rte_port_kni_writer_nodrop_tx,\n+\t.f_tx_bulk = rte_port_kni_writer_nodrop_tx_bulk,\n+\t.f_flush = rte_port_kni_writer_nodrop_flush,\n+\t.f_stats = rte_port_kni_writer_nodrop_stats_read,\n+};\ndiff --git a/lib/librte_port/rte_port_kni.h b/lib/librte_port/rte_port_kni.h\nnew file mode 100644\nindex 0000000..4b60689\n--- /dev/null\n+++ b/lib/librte_port/rte_port_kni.h\n@@ -0,0 +1,95 @@\n+/*-\n+ *   BSD LICENSE\n+ *\n+ *   Copyright(c) 2016 Ethan Zhuang <zhuangwj@gmail.com>.\n+ *   Copyright(c) 2016 Intel Corporation.\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 __INCLUDE_RTE_PORT_KNI_H__\n+#define __INCLUDE_RTE_PORT_KNI_H__\n+\n+#ifdef __cplusplus\n+extern \"C\" {\n+#endif\n+\n+/**\n+ * @file\n+ * RTE Port KNI Interface\n+ *\n+ * kni_reader: input port built on top of pre-initialized KNI interface\n+ * kni_writer: output port built on top of pre-initialized KNI interface\n+ *\n+ ***/\n+\n+#include <stdint.h>\n+\n+#include <rte_kni.h>\n+\n+#include \"rte_port.h\"\n+\n+/** kni_reader port parameters */\n+struct rte_port_kni_reader_params {\n+\t/** KNI interface reference */\n+\tstruct rte_kni *kni;\n+};\n+\n+/** kni_reader port operations */\n+extern struct rte_port_in_ops rte_port_kni_reader_ops;\n+\n+\n+/** kni_writer port parameters */\n+struct rte_port_kni_writer_params {\n+\t/** KNI interface reference */\n+\tstruct rte_kni *kni;\n+\t/** Burst size to KNI interface. */\n+\tuint32_t tx_burst_sz;\n+};\n+\n+/** kni_writer port operations */\n+extern struct rte_port_out_ops rte_port_kni_writer_ops;\n+\n+/** kni_writer_nodrop port parameters */\n+struct rte_port_kni_writer_nodrop_params {\n+\t/** KNI interface reference */\n+\tstruct rte_kni *kni;\n+\t/** Burst size to KNI interface. */\n+\tuint32_t tx_burst_sz;\n+\t/** Maximum number of retries, 0 for no limit */\n+\tuint32_t n_retries;\n+};\n+\n+/** kni_writer_nodrop port operations */\n+extern struct rte_port_out_ops rte_port_kni_writer_nodrop_ops;\n+\n+#ifdef __cplusplus\n+}\n+#endif\n+\n+#endif\ndiff --git a/lib/librte_port/rte_port_version.map b/lib/librte_port/rte_port_version.map\nindex 7a0b34d..c528658 100644\n--- a/lib/librte_port/rte_port_version.map\n+++ b/lib/librte_port/rte_port_version.map\n@@ -35,3 +35,12 @@ DPDK_2.2 {\n \trte_port_ring_multi_writer_nodrop_ops;\n \n } DPDK_2.1;\n+\n+DPDK_16.07 {\n+\tglobal:\n+\n+\trte_port_kni_reader_ops;\n+\trte_port_kni_writer_ops;\n+\trte_port_kni_writer_nodrop_ops;\n+\n+} DPDK_2.2;\n",
    "prefixes": [
        "dpdk-dev",
        "v4",
        "1/4"
    ]
}