get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

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

{
    "id": 27875,
    "url": "https://patches.dpdk.org/api/patches/27875/?format=api",
    "web_url": "https://patches.dpdk.org/project/dpdk/patch/1503584144-63181-3-git-send-email-jiayu.hu@intel.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": "<1503584144-63181-3-git-send-email-jiayu.hu@intel.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/1503584144-63181-3-git-send-email-jiayu.hu@intel.com",
    "date": "2017-08-24T14:15:41",
    "name": "[dpdk-dev,2/5] gso/lib: add TCP/IPv4 GSO support",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": true,
    "hash": "8a3d6389f6be4ac31268005dac2d65c253ce84df",
    "submitter": {
        "id": 539,
        "url": "https://patches.dpdk.org/api/people/539/?format=api",
        "name": "Hu, Jiayu",
        "email": "jiayu.hu@intel.com"
    },
    "delegate": null,
    "mbox": "https://patches.dpdk.org/project/dpdk/patch/1503584144-63181-3-git-send-email-jiayu.hu@intel.com/mbox/",
    "series": [],
    "comments": "https://patches.dpdk.org/api/patches/27875/comments/",
    "check": "fail",
    "checks": "https://patches.dpdk.org/api/patches/27875/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 0A1B87D52;\n\tThu, 24 Aug 2017 16:13:46 +0200 (CEST)",
            "from mga09.intel.com (mga09.intel.com [134.134.136.24])\n\tby dpdk.org (Postfix) with ESMTP id 451B87D24\n\tfor <dev@dpdk.org>; Thu, 24 Aug 2017 16:13:42 +0200 (CEST)",
            "from orsmga005.jf.intel.com ([10.7.209.41])\n\tby orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384;\n\t24 Aug 2017 07:13:41 -0700",
            "from dpdk15.sh.intel.com ([10.67.111.77])\n\tby orsmga005.jf.intel.com with ESMTP; 24 Aug 2017 07:13:39 -0700"
        ],
        "X-ExtLoop1": "1",
        "X-IronPort-AV": "E=Sophos;i=\"5.41,421,1498546800\"; d=\"scan'208\";a=\"141575657\"",
        "From": "Jiayu Hu <jiayu.hu@intel.com>",
        "To": "dev@dpdk.org",
        "Cc": "mark.b.kavanagh@intel.com, konstantin.ananyev@intel.com,\n\tjianfeng.tan@intel.com, Jiayu Hu <jiayu.hu@intel.com>",
        "Date": "Thu, 24 Aug 2017 22:15:41 +0800",
        "Message-Id": "<1503584144-63181-3-git-send-email-jiayu.hu@intel.com>",
        "X-Mailer": "git-send-email 2.7.4",
        "In-Reply-To": "<1503584144-63181-1-git-send-email-jiayu.hu@intel.com>",
        "References": "<1503584144-63181-1-git-send-email-jiayu.hu@intel.com>",
        "Subject": "[dpdk-dev] [PATCH 2/5] gso/lib: add TCP/IPv4 GSO support",
        "X-BeenThere": "dev@dpdk.org",
        "X-Mailman-Version": "2.1.15",
        "Precedence": "list",
        "List-Id": "DPDK patches and discussions <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 adds GSO support for TCP/IPv4 packets. Supported packets\nmay include a single VLAN tag. TCP/IPv4 GSO assumes that all input\npackets have correct checksums, and doesn't update checksums for output\npackets (the responsibility for this lies with the application).\nAdditionally, TCP/IPv4 GSO doesn't process IP fragmented packets.\n\nTCP/IPv4 GSO uses two chained MBUFs, one direct MBUF and one indrect\nMBUF, to organize an output packet. Note that we refer to these two\nchained MBUFs as a two-segment MBUF. The direct MBUF stores the packet\nheader, while the indirect mbuf simply points to a location within the\noriginal packet's payload. Consequently, use of the GSO library requires\nmulti-segment MBUF support in the TX functions of the NIC driver.\n\nIf a packet is GSOed, TCP/IPv4 GSO reduces its MBUF refcnt by 1. As a\nresult, when all of its GSOed segments are freed, the packet is freed\nautomatically.\n\nSigned-off-by: Jiayu Hu <jiayu.hu@intel.com>\nSigned-off-by: Mark Kavanagh <mark.b.kavanagh@intel.com>\n---\n lib/librte_eal/common/include/rte_log.h |   1 +\n lib/librte_gso/Makefile                 |   2 +\n lib/librte_gso/gso_common.c             | 270 ++++++++++++++++++++++++++++++++\n lib/librte_gso/gso_common.h             | 120 ++++++++++++++\n lib/librte_gso/gso_tcp.c                |  82 ++++++++++\n lib/librte_gso/gso_tcp.h                |  73 +++++++++\n lib/librte_gso/rte_gso.c                |  44 +++++-\n lib/librte_gso/rte_gso.h                |   3 +\n 8 files changed, 593 insertions(+), 2 deletions(-)\n create mode 100644 lib/librte_gso/gso_common.c\n create mode 100644 lib/librte_gso/gso_common.h\n create mode 100644 lib/librte_gso/gso_tcp.c\n create mode 100644 lib/librte_gso/gso_tcp.h",
    "diff": "diff --git a/lib/librte_eal/common/include/rte_log.h b/lib/librte_eal/common/include/rte_log.h\nindex ec8dba7..2fa1199 100644\n--- a/lib/librte_eal/common/include/rte_log.h\n+++ b/lib/librte_eal/common/include/rte_log.h\n@@ -87,6 +87,7 @@ extern struct rte_logs rte_logs;\n #define RTE_LOGTYPE_CRYPTODEV 17 /**< Log related to cryptodev. */\n #define RTE_LOGTYPE_EFD       18 /**< Log related to EFD. */\n #define RTE_LOGTYPE_EVENTDEV  19 /**< Log related to eventdev. */\n+#define RTE_LOGTYPE_GSO       20 /**< Log related to GSO. */\n \n /* these log types can be used in an application */\n #define RTE_LOGTYPE_USER1     24 /**< User-defined log type 1. */\ndiff --git a/lib/librte_gso/Makefile b/lib/librte_gso/Makefile\nindex aeaacbc..0f8e38f 100644\n--- a/lib/librte_gso/Makefile\n+++ b/lib/librte_gso/Makefile\n@@ -42,6 +42,8 @@ LIBABIVER := 1\n \n #source files\n SRCS-$(CONFIG_RTE_LIBRTE_GSO) += rte_gso.c\n+SRCS-$(CONFIG_RTE_LIBRTE_GSO) += gso_common.c\n+SRCS-$(CONFIG_RTE_LIBRTE_GSO) += gso_tcp.c\n \n # install this header file\n SYMLINK-$(CONFIG_RTE_LIBRTE_GSO)-include += rte_gso.h\ndiff --git a/lib/librte_gso/gso_common.c b/lib/librte_gso/gso_common.c\nnew file mode 100644\nindex 0000000..2b54fbd\n--- /dev/null\n+++ b/lib/librte_gso/gso_common.c\n@@ -0,0 +1,270 @@\n+/*-\n+ *   BSD LICENSE\n+ *\n+ *   Copyright(c) 2017 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 <stdbool.h>\n+#include <string.h>\n+\n+#include <rte_malloc.h>\n+\n+#include <rte_ether.h>\n+#include <rte_ip.h>\n+#include <rte_tcp.h>\n+\n+#include \"gso_common.h\"\n+\n+static inline void\n+hdr_segment_init(struct rte_mbuf *hdr_segment, struct rte_mbuf *pkt,\n+\t\tuint16_t pkt_hdr_offset)\n+{\n+\t/* copy mbuf metadata */\n+\thdr_segment->nb_segs = 1;\n+\thdr_segment->port = pkt->port;\n+\thdr_segment->ol_flags = pkt->ol_flags;\n+\thdr_segment->packet_type = pkt->packet_type;\n+\thdr_segment->pkt_len = pkt_hdr_offset;\n+\thdr_segment->data_len = pkt_hdr_offset;\n+\thdr_segment->tx_offload = pkt->tx_offload;\n+\t/* copy packet header */\n+\trte_memcpy(rte_pktmbuf_mtod(hdr_segment, char *),\n+\t\t\trte_pktmbuf_mtod(pkt, char *),\n+\t\t\tpkt_hdr_offset);\n+}\n+\n+static inline void\n+free_gso_segment(struct rte_mbuf **pkts, uint16_t nb_pkts)\n+{\n+\tuint16_t i;\n+\n+\tfor (i = 0; i < nb_pkts; i++) {\n+\t\trte_pktmbuf_detach(pkts[i]->next);\n+\t\trte_pktmbuf_free(pkts[i]);\n+\t\tpkts[i] = NULL;\n+\t}\n+}\n+\n+int\n+gso_do_segment(struct rte_mbuf *pkt,\n+\t\tuint16_t pkt_hdr_offset,\n+\t\tuint16_t pyld_unit_size,\n+\t\tstruct rte_mempool *direct_pool,\n+\t\tstruct rte_mempool *indirect_pool,\n+\t\tstruct rte_mbuf **pkts_out,\n+\t\tuint16_t nb_pkts_out)\n+{\n+\tstruct rte_mbuf *pkt_in;\n+\tstruct rte_mbuf *hdr_segment, *pyld_segment;\n+\tuint32_t pkt_in_pyld_off;\n+\tuint16_t pkt_in_segment_len, pkt_out_segment_len;\n+\tuint16_t nb_segs;\n+\tbool pkt_in_segment_processed;\n+\n+\tpkt_in_pyld_off = pkt->data_off + pkt_hdr_offset;\n+\tpkt_in = pkt;\n+\tnb_segs = 0;\n+\n+\twhile (pkt_in) {\n+\t\tpkt_in_segment_processed = false;\n+\t\tpkt_in_segment_len = pkt_in->data_off + pkt_in->data_len;\n+\n+\t\twhile (!pkt_in_segment_processed) {\n+\t\t\tif (unlikely(nb_segs >= nb_pkts_out)) {\n+\t\t\t\tfree_gso_segment(pkts_out, nb_segs);\n+\t\t\t\treturn -EINVAL;\n+\t\t\t}\n+\n+\t\t\t/* allocate direct mbuf */\n+\t\t\thdr_segment = rte_pktmbuf_alloc(direct_pool);\n+\t\t\tif (unlikely(hdr_segment == NULL)) {\n+\t\t\t\tfree_gso_segment(pkts_out, nb_segs);\n+\t\t\t\treturn -ENOMEM;\n+\t\t\t}\n+\n+\t\t\t/* allocate indirect mbuf */\n+\t\t\tpyld_segment = rte_pktmbuf_alloc(indirect_pool);\n+\t\t\tif (unlikely(pyld_segment == NULL)) {\n+\t\t\t\trte_pktmbuf_free(hdr_segment);\n+\t\t\t\tfree_gso_segment(pkts_out, nb_segs);\n+\t\t\t\treturn -ENOMEM;\n+\t\t\t}\n+\n+\t\t\t/* copy packet header */\n+\t\t\thdr_segment_init(hdr_segment, pkt, pkt_hdr_offset);\n+\n+\t\t\t/* attach payload mbuf to current packet segment */\n+\t\t\trte_pktmbuf_attach(pyld_segment, pkt_in);\n+\n+\t\t\thdr_segment->next = pyld_segment;\n+\t\t\tpkts_out[nb_segs++] = hdr_segment;\n+\n+\t\t\t/* calculate payload length */\n+\t\t\tpkt_out_segment_len = pyld_unit_size;\n+\t\t\tif (pkt_in_pyld_off + pkt_out_segment_len >\n+\t\t\t\t\tpkt_in_segment_len) {\n+\t\t\t\tpkt_out_segment_len = pkt_in_segment_len -\n+\t\t\t\t\tpkt_in_pyld_off;\n+\t\t\t}\n+\n+\t\t\t/* update payload segment */\n+\t\t\tpyld_segment->data_off = pkt_in_pyld_off;\n+\t\t\tpyld_segment->data_len = pkt_out_segment_len;\n+\n+\t\t\t/* update header segment */\n+\t\t\thdr_segment->pkt_len += pyld_segment->data_len;\n+\t\t\thdr_segment->nb_segs++;\n+\n+\t\t\t/* update pkt_in_pyld_off */\n+\t\t\tpkt_in_pyld_off += pkt_out_segment_len;\n+\t\t\tif (pkt_in_pyld_off == pkt_in_segment_len)\n+\t\t\t\tpkt_in_segment_processed = true;\n+\t\t}\n+\n+\t\t/* 'pkt_in' may contain numerous segments */\n+\t\tpkt_in = pkt_in->next;\n+\t\tif (pkt_in != NULL)\n+\t\t\tpkt_in_pyld_off = pkt_in->data_off;\n+\t}\n+\treturn nb_segs;\n+}\n+\n+static inline void\n+parse_ipv4(struct ipv4_hdr *ipv4_hdr, struct rte_mbuf *pkt)\n+{\n+\tstruct tcp_hdr *tcp_hdr;\n+\n+\tswitch (ipv4_hdr->next_proto_id) {\n+\tcase IPPROTO_TCP:\n+\t\tpkt->packet_type |= RTE_PTYPE_L4_TCP;\n+\t\tpkt->l3_len = IPv4_HDR_LEN(ipv4_hdr);\n+\t\ttcp_hdr = (struct tcp_hdr *)((char *)ipv4_hdr + pkt->l3_len);\n+\t\tpkt->l4_len = TCP_HDR_LEN(tcp_hdr);\n+\t\tbreak;\n+\t}\n+}\n+\n+static inline void\n+parse_ethernet(struct ether_hdr *eth_hdr, struct rte_mbuf *pkt)\n+{\n+\tstruct ipv4_hdr *ipv4_hdr;\n+\tstruct vlan_hdr *vlan_hdr;\n+\tuint16_t ethertype;\n+\n+\tethertype = rte_be_to_cpu_16(eth_hdr->ether_type);\n+\tif (ethertype == ETHER_TYPE_VLAN) {\n+\t\tvlan_hdr = (struct vlan_hdr *)(eth_hdr + 1);\n+\t\tpkt->l2_len = sizeof(struct vlan_hdr);\n+\t\tpkt->packet_type |= RTE_PTYPE_L2_ETHER_VLAN;\n+\t\tethertype = rte_be_to_cpu_16(vlan_hdr->eth_proto);\n+\t}\n+\n+\tswitch (ethertype) {\n+\tcase ETHER_TYPE_IPv4:\n+\t\tif (IS_VLAN_PKT(pkt)) {\n+\t\t\tpkt->packet_type |= RTE_PTYPE_L3_IPV4;\n+\t\t} else {\n+\t\t\tpkt->packet_type |= RTE_PTYPE_L2_ETHER;\n+\t\t\tpkt->packet_type |= RTE_PTYPE_L3_IPV4;\n+\t\t}\n+\t\tpkt->l2_len += sizeof(struct ether_hdr);\n+\t\tipv4_hdr = (struct ipv4_hdr *) ((char *)eth_hdr +\n+\t\t\t\tpkt->l2_len);\n+\t\tparse_ipv4(ipv4_hdr, pkt);\n+\t\tbreak;\n+\t}\n+}\n+\n+void\n+gso_parse_packet(struct rte_mbuf *pkt)\n+{\n+\tstruct ether_hdr *eth_hdr = rte_pktmbuf_mtod(pkt, struct ether_hdr *);\n+\n+\tpkt->packet_type = pkt->tx_offload = 0;\n+\tparse_ethernet(eth_hdr, pkt);\n+}\n+\n+static inline void\n+update_ipv4_header(char *base, uint16_t offset, uint16_t length, uint16_t id)\n+{\n+\tstruct ipv4_hdr *ipv4_hdr = (struct ipv4_hdr *)(base + offset);\n+\n+\tipv4_hdr->total_length = rte_cpu_to_be_16(length - offset);\n+\tipv4_hdr->packet_id = rte_cpu_to_be_16(id);\n+}\n+\n+static inline void\n+update_tcp_header(char *base, uint16_t offset, uint32_t sent_seq,\n+\tuint8_t non_tail)\n+{\n+\tstruct tcp_hdr *tcp_hdr = (struct tcp_hdr *)(base + offset);\n+\n+\ttcp_hdr->sent_seq = rte_cpu_to_be_32(sent_seq);\n+\t/* clean FIN and PSH for non-tail segments */\n+\tif (non_tail)\n+\t\ttcp_hdr->tcp_flags &= (~(TCP_HDR_PSH_MASK | TCP_HDR_FIN_MASK));\n+}\n+\n+void\n+gso_update_pkt_headers(struct rte_mbuf *pkt, uint16_t nb_segments,\n+\t\tstruct rte_mbuf **out_segments)\n+{\n+\tstruct ipv4_hdr *ipv4_hdr;\n+\tstruct tcp_hdr *tcp_hdr;\n+\tstruct rte_mbuf *seg;\n+\tuint32_t sent_seq;\n+\tuint16_t offset, i;\n+\tuint16_t tail_seg_idx = nb_segments - 1, id;\n+\n+\tswitch (pkt->packet_type) {\n+\tcase ETHER_VLAN_IPv4_TCP_PKT:\n+\tcase ETHER_IPv4_TCP_PKT:\n+\t\tipv4_hdr = (struct ipv4_hdr *)(rte_pktmbuf_mtod(pkt, char *) +\n+\t\t\t\tpkt->l2_len);\n+\t\ttcp_hdr = (struct tcp_hdr *)((char *)ipv4_hdr + pkt->l3_len);\n+\t\tid = rte_be_to_cpu_16(ipv4_hdr->packet_id);\n+\t\tsent_seq = rte_be_to_cpu_32(tcp_hdr->sent_seq);\n+\n+\t\tfor (i = 0; i < nb_segments; i++) {\n+\t\t\tseg = out_segments[i];\n+\n+\t\t\toffset = seg->l2_len;\n+\t\t\tupdate_ipv4_header(rte_pktmbuf_mtod(seg, char *),\n+\t\t\t\t\toffset, seg->pkt_len, id);\n+\t\t\tid++;\n+\n+\t\t\toffset += seg->l3_len;\n+\t\t\tupdate_tcp_header(rte_pktmbuf_mtod(seg, char *),\n+\t\t\t\t\toffset, sent_seq, i < tail_seg_idx);\n+\t\t\tsent_seq += seg->next->data_len;\n+\t\t}\n+\t\tbreak;\n+\t}\n+}\ndiff --git a/lib/librte_gso/gso_common.h b/lib/librte_gso/gso_common.h\nnew file mode 100644\nindex 0000000..d750041\n--- /dev/null\n+++ b/lib/librte_gso/gso_common.h\n@@ -0,0 +1,120 @@\n+/*-\n+ *   BSD LICENSE\n+ *\n+ *   Copyright(c) 2017 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 _GSO_COMMON_H_\n+#define _GSO_COMMON_H_\n+\n+#include <stdint.h>\n+#include <rte_mbuf.h>\n+\n+#define IPV4_HDR_DF_SHIFT 14\n+#define IPV4_HDR_DF_MASK (1 << IPV4_HDR_DF_SHIFT)\n+#define IPv4_HDR_LEN(iph) ((iph->version_ihl & 0x0f) * 4)\n+\n+#define TCP_HDR_PSH_MASK ((uint8_t)0x08)\n+#define TCP_HDR_FIN_MASK ((uint8_t)0x01)\n+#define TCP_HDR_LEN(tcph) ((tcph->data_off & 0xf0) >> 2)\n+\n+#define ETHER_IPv4_PKT (RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4)\n+/* Supported packet types */\n+/* TCP/IPv4 packet. */\n+#define ETHER_IPv4_TCP_PKT (ETHER_IPv4_PKT | RTE_PTYPE_L4_TCP)\n+\n+/* TCP/IPv4 packet with VLAN tag. */\n+#define ETHER_VLAN_IPv4_TCP_PKT (RTE_PTYPE_L2_ETHER_VLAN | \\\n+\t\tRTE_PTYPE_L3_IPV4 | RTE_PTYPE_L4_TCP)\n+\n+#define IS_VLAN_PKT(pkt) ((pkt->packet_type & RTE_PTYPE_L2_ETHER_VLAN) == \\\n+\t\tRTE_PTYPE_L2_ETHER_VLAN)\n+\n+/**\n+ * Internal function which parses a packet, setting outer_l2/l3_len and\n+ * l2/l3/l4_len and packet_type.\n+ *\n+ * @param pkt\n+ *  Packet to parse.\n+ */\n+void gso_parse_packet(struct rte_mbuf *pkt);\n+\n+/**\n+ * Internal function which updates relevant packet headers, following\n+ * segmentation. This is required to update, for example, the IPv4\n+ * 'total_length' field, to reflect the reduced length of the now-\n+ * segmented packet.\n+ *\n+ * @param pkt\n+ *  The original packet.\n+ * @param nb_segments\n+ *  The number of GSO segments into which pkt was split.\n+ * @param out_segements\n+ *  Pointer array used for storing mbuf addresses for GSO segments.\n+ */\n+void gso_update_pkt_headers(struct rte_mbuf *pkt, uint16_t nb_segments,\n+\t\tstruct rte_mbuf **out_segments);\n+\n+/**\n+ * Internal function which divides the input packet into small segments.\n+ * Each of the newly-created segments is organized as a two-segment mbuf,\n+ * where the first segment is a standard mbuf, which stores a copy of\n+ * packet header, and the second is an indirect mbuf which points to a\n+ * section of data in the input packet.\n+ *\n+ * @param pkt\n+ *  Packet to segment.\n+ * @param pkt_hdr_offset\n+ *  Packet header offset, measured in byte.\n+ * @param pyld_unit_size\n+ *  The max payload length of a GSO segment.\n+ * @param direct_pool\n+ *  MBUF pool used for allocating direct buffers for output segments.\n+ * @param indirect_pool\n+ *  MBUF pool used for allocating indirect buffers for output segments.\n+ * @param pkts_out\n+ *  Pointer array used to keep the mbuf addresses of output segments.\n+ * @param nb_pkts_out\n+ *  The max number of items that pkts_out can keep.\n+ *\n+ * @return\n+ *  - The number of segments created in the event of success.\n+ *  - If no GSO is performed, return 1.\n+ *  - If available memory in mempools is insufficient, return -ENOMEM.\n+ *  - -EINVAL for invalid parameters\n+ */\n+int gso_do_segment(struct rte_mbuf *pkt,\n+\t\tuint16_t pkt_hdr_offset,\n+\t\tuint16_t pyld_unit_size,\n+\t\tstruct rte_mempool *direct_pool,\n+\t\tstruct rte_mempool *indirect_pool,\n+\t\tstruct rte_mbuf **pkts_out,\n+\t\tuint16_t nb_pkts_out);\n+#endif\ndiff --git a/lib/librte_gso/gso_tcp.c b/lib/librte_gso/gso_tcp.c\nnew file mode 100644\nindex 0000000..9d5fc30\n--- /dev/null\n+++ b/lib/librte_gso/gso_tcp.c\n@@ -0,0 +1,82 @@\n+/*-\n+ *   BSD LICENSE\n+ *\n+ *   Copyright(c) 2017 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+\n+#include <rte_ether.h>\n+#include <rte_ip.h>\n+#include <rte_tcp.h>\n+\n+#include \"gso_common.h\"\n+#include \"gso_tcp.h\"\n+\n+int\n+gso_tcp4_segment(struct rte_mbuf *pkt,\n+\t\tuint16_t gso_size,\n+\t\tstruct rte_mempool *direct_pool,\n+\t\tstruct rte_mempool *indirect_pool,\n+\t\tstruct rte_mbuf **pkts_out,\n+\t\tuint16_t nb_pkts_out)\n+{\n+\tstruct ether_hdr *eth_hdr;\n+\tstruct ipv4_hdr *ipv4_hdr;\n+\tuint16_t tcp_dl;\n+\tuint16_t pyld_unit_size;\n+\tuint16_t hdr_offset;\n+\tint ret = 1;\n+\n+\teth_hdr = rte_pktmbuf_mtod(pkt, struct ether_hdr *);\n+\tipv4_hdr = (struct ipv4_hdr *)((char *)eth_hdr + pkt->l2_len);\n+\n+\t/* don't process fragmented packet */\n+\tif ((ipv4_hdr->fragment_offset &\n+\t\t\t\trte_cpu_to_be_16(IPV4_HDR_DF_MASK)) == 0)\n+\t\treturn ret;\n+\n+\ttcp_dl = rte_be_to_cpu_16(ipv4_hdr->total_length) -\n+\t\tpkt->l3_len - pkt->l4_len;\n+\t/* don't process packet without data */\n+\tif (tcp_dl == 0)\n+\t\treturn ret;\n+\n+\thdr_offset = pkt->l2_len + pkt->l3_len + pkt->l4_len;\n+\tpyld_unit_size = gso_size - hdr_offset - ETHER_CRC_LEN;\n+\n+\t/* segment the payload */\n+\tret = gso_do_segment(pkt, hdr_offset, pyld_unit_size, direct_pool,\n+\t\t\tindirect_pool, pkts_out, nb_pkts_out);\n+\n+\tif (ret > 1)\n+\t\tgso_update_pkt_headers(pkt, ret, pkts_out);\n+\n+\treturn ret;\n+}\ndiff --git a/lib/librte_gso/gso_tcp.h b/lib/librte_gso/gso_tcp.h\nnew file mode 100644\nindex 0000000..f291ccb\n--- /dev/null\n+++ b/lib/librte_gso/gso_tcp.h\n@@ -0,0 +1,73 @@\n+/*-\n+ *   BSD LICENSE\n+ *\n+ *   Copyright(c) 2017 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 _GSO_TCP_H_\n+#define _GSO_TCP_H_\n+\n+#include <stdint.h>\n+#include <rte_mbuf.h>\n+\n+/**\n+ * Segment an IPv4/TCP packet. This function assumes the input packet has\n+ * correct checksums and doesn't update checksums for GSO segment.\n+ * Furthermore, it doesn't process IP fragment packets.\n+ *\n+ * @param pkt\n+ *  The packet mbuf to segment.\n+ * @param gso_size\n+ *  The max length of a GSO segment, measured in bytes.\n+ * @param direct_pool\n+ *  MBUF pool used for allocating direct buffers for output segments.\n+ * @param indirect_pool\n+ *  MBUF pool used for allocating indirect buffers for output segments.\n+ * @param pkts_out\n+ *  Pointer array, which is used to store mbuf addresses of GSO segments.\n+ *  Caller should guarantee that 'pkts_out' is sufficiently large to store\n+ *  all GSO segments.\n+ * @param nb_pkts_out\n+ *  The max number of items that 'pkts_out' can keep.\n+ *\n+ * @return\n+ *   - The number of GSO segments on success.\n+ *   - Return 1 if no GSO is performed.\n+ *   - Return -ENOMEM if available memory in mempools is insufficient.\n+ *   - Return -EINVAL for invalid parameters.\n+ */\n+int gso_tcp4_segment(struct rte_mbuf *pkt,\n+\t\tuint16_t gso_size,\n+\t\tstruct rte_mempool *direct_pool,\n+\t\tstruct rte_mempool *indirect_pool,\n+\t\tstruct rte_mbuf **pkts_out,\n+\t\tuint16_t nb_pkts_out);\n+\n+#endif\ndiff --git a/lib/librte_gso/rte_gso.c b/lib/librte_gso/rte_gso.c\nindex b81afce..fac95f2 100644\n--- a/lib/librte_gso/rte_gso.c\n+++ b/lib/librte_gso/rte_gso.c\n@@ -31,17 +31,57 @@\n  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n  */\n \n+#include <rte_log.h>\n+\n #include \"rte_gso.h\"\n+#include \"gso_common.h\"\n+#include \"gso_tcp.h\"\n \n int\n rte_gso_segment(struct rte_mbuf *pkt,\n \t\tstruct rte_gso_ctx gso_ctx,\n \t\tstruct rte_mbuf **pkts_out,\n-\t\tuint16_t nb_pkts_out __rte_unused)\n+\t\tuint16_t nb_pkts_out)\n {\n+\tstruct rte_mempool *direct_pool, *indirect_pool;\n+\tstruct rte_mbuf *pkt_seg;\n+\tuint16_t nb_segments, gso_size;\n+\n \tif (pkt == NULL || pkts_out == NULL || gso_ctx.direct_pool ==\n \t\t\tNULL || gso_ctx.indirect_pool == NULL)\n \t\treturn -EINVAL;\n \n-\treturn 1;\n+\tif ((gso_ctx.gso_types & RTE_GSO_TCP_IPV4) == 0 ||\n+\t\t\tgso_ctx.gso_size >= pkt->pkt_len ||\n+\t\t\tgso_ctx.gso_size == 0)\n+\t\treturn 1;\n+\n+\tpkt_seg = pkt;\n+\tgso_size = gso_ctx.gso_size;\n+\tdirect_pool = gso_ctx.direct_pool;\n+\tindirect_pool = gso_ctx.indirect_pool;\n+\n+\t/* Parse packet headers to determine how to segment 'pkt' */\n+\tgso_parse_packet(pkt);\n+\n+\tswitch (pkt->packet_type) {\n+\tcase ETHER_VLAN_IPv4_TCP_PKT:\n+\tcase ETHER_IPv4_TCP_PKT:\n+\t\tnb_segments = gso_tcp4_segment(pkt, gso_size,\n+\t\t\t\tdirect_pool, indirect_pool,\n+\t\t\t\tpkts_out, nb_pkts_out);\n+\t\tbreak;\n+\tdefault:\n+\t\tRTE_LOG(WARNING, GSO, \"Unsupported packet type\\n\");\n+\t\tnb_segments = 1;\n+\t}\n+\n+\tif (nb_segments > 1) {\n+\t\twhile (pkt_seg) {\n+\t\t\trte_mbuf_refcnt_update(pkt_seg, -1);\n+\t\t\tpkt_seg = pkt_seg->next;\n+\t\t}\n+\t}\n+\n+\treturn nb_segments;\n }\ndiff --git a/lib/librte_gso/rte_gso.h b/lib/librte_gso/rte_gso.h\nindex 5a8389a..77853fa 100644\n--- a/lib/librte_gso/rte_gso.h\n+++ b/lib/librte_gso/rte_gso.h\n@@ -46,6 +46,9 @@ extern \"C\" {\n #include <stdint.h>\n #include <rte_mbuf.h>\n \n+#define RTE_GSO_TCP_IPV4 (1ULL << 0)\n+/**< GSO flag for TCP/IPv4 packets (containing optional VLAN tag) */\n+\n /**\n  * GSO context structure.\n  */\n",
    "prefixes": [
        "dpdk-dev",
        "2/5"
    ]
}