get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

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

{
    "id": 29673,
    "url": "https://patches.dpdk.org/api/patches/29673/?format=api",
    "web_url": "https://patches.dpdk.org/project/dpdk/patch/1507201331-228465-3-git-send-email-mark.b.kavanagh@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": "<1507201331-228465-3-git-send-email-mark.b.kavanagh@intel.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/1507201331-228465-3-git-send-email-mark.b.kavanagh@intel.com",
    "date": "2017-10-05T11:02:07",
    "name": "[dpdk-dev,v7,2/6] gso: add TCP/IPv4 GSO support",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": true,
    "hash": "fef7d39c466b824a037a5c7965358ccd820f19d4",
    "submitter": {
        "id": 133,
        "url": "https://patches.dpdk.org/api/people/133/?format=api",
        "name": "Mark Kavanagh",
        "email": "mark.b.kavanagh@intel.com"
    },
    "delegate": null,
    "mbox": "https://patches.dpdk.org/project/dpdk/patch/1507201331-228465-3-git-send-email-mark.b.kavanagh@intel.com/mbox/",
    "series": [],
    "comments": "https://patches.dpdk.org/api/patches/29673/comments/",
    "check": "success",
    "checks": "https://patches.dpdk.org/api/patches/29673/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 [127.0.0.1])\n\tby dpdk.org (Postfix) with ESMTP id 29D5F1B19E;\n\tThu,  5 Oct 2017 13:02:28 +0200 (CEST)",
            "from mga11.intel.com (mga11.intel.com [192.55.52.93])\n\tby dpdk.org (Postfix) with ESMTP id C1F937D4E\n\tfor <dev@dpdk.org>; Thu,  5 Oct 2017 13:02:23 +0200 (CEST)",
            "from fmsmga005.fm.intel.com ([10.253.24.32])\n\tby fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384;\n\t05 Oct 2017 04:02:22 -0700",
            "from silpixa00380299.ir.intel.com ([10.237.222.17])\n\tby fmsmga005.fm.intel.com with ESMTP; 05 Oct 2017 04:02:20 -0700"
        ],
        "X-ExtLoop1": "1",
        "X-IronPort-AV": "E=Sophos;i=\"5.42,481,1500966000\"; d=\"scan'208\";a=\"159160321\"",
        "From": "Mark Kavanagh <mark.b.kavanagh@intel.com>",
        "To": "dev@dpdk.org",
        "Cc": "jiayu.hu@intel.com, jianfeng.tan@intel.com, konstantin.ananyev@intel.com,\n\tferruh.yigit@intel.com, thomas@monjalon.net,\n\tMark Kavanagh <mark.b.kavanagh@intel.com>",
        "Date": "Thu,  5 Oct 2017 12:02:07 +0100",
        "Message-Id": "<1507201331-228465-3-git-send-email-mark.b.kavanagh@intel.com>",
        "X-Mailer": "git-send-email 1.9.3",
        "In-Reply-To": "<1507201331-228465-1-git-send-email-mark.b.kavanagh@intel.com>",
        "References": "<1506962749-106779-1-git-send-email-mark.b.kavanagh@intel.com>\n\t<1507201331-228465-1-git-send-email-mark.b.kavanagh@intel.com>",
        "Subject": "[dpdk-dev] [PATCH v7 2/6] gso: 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": "From: Jiayu Hu <jiayu.hu@intel.com>\n\nThis patch adds GSO support for TCP/IPv4 packets. Supported packets\nmay include a single VLAN tag. TCP/IPv4 GSO doesn't check if input\npackets have correct checksums, and doesn't update checksums for\noutput packets (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 GSO'd, 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>\nTested-by: Lei Yao <lei.a.yao@intel.com>\n---\n doc/guides/rel_notes/release_17_11.rst  |  12 +++\n lib/Makefile                            |   2 +-\n lib/librte_eal/common/include/rte_log.h |   1 +\n lib/librte_gso/Makefile                 |   2 +\n lib/librte_gso/gso_common.c             | 153 ++++++++++++++++++++++++++++++++\n lib/librte_gso/gso_common.h             | 141 +++++++++++++++++++++++++++++\n lib/librte_gso/gso_tcp4.c               | 104 ++++++++++++++++++++++\n lib/librte_gso/gso_tcp4.h               |  74 +++++++++++++++\n lib/librte_gso/rte_gso.c                |  52 ++++++++++-\n lib/librte_gso/rte_gso.h                |   7 +-\n 10 files changed, 543 insertions(+), 5 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_tcp4.c\n create mode 100644 lib/librte_gso/gso_tcp4.h",
    "diff": "diff --git a/doc/guides/rel_notes/release_17_11.rst b/doc/guides/rel_notes/release_17_11.rst\nindex 5bb36b7..dd37169 100644\n--- a/doc/guides/rel_notes/release_17_11.rst\n+++ b/doc/guides/rel_notes/release_17_11.rst\n@@ -41,6 +41,18 @@ New Features\n      Also, make sure to start the actual text at the margin.\n      =========================================================\n \n+* **Added the Generic Segmentation Offload Library.**\n+\n+  Added the Generic Segmentation Offload (GSO) library to enable\n+  applications to split large packets (e.g. MTU is 64KB) into small\n+  ones (e.g. MTU is 1500B). Supported packet types are:\n+\n+  * TCP/IPv4 packets.\n+\n+  The GSO library doesn't check if the input packets have correct\n+  checksums, and doesn't update checksums for output packets.\n+  Additionally, the GSO library doesn't process IP fragmented packets.\n+\n \n Resolved Issues\n ---------------\ndiff --git a/lib/Makefile b/lib/Makefile\nindex 3d123f4..5ecd1b3 100644\n--- a/lib/Makefile\n+++ b/lib/Makefile\n@@ -109,7 +109,7 @@ DEPDIRS-librte_reorder := librte_eal librte_mempool librte_mbuf\n DIRS-$(CONFIG_RTE_LIBRTE_PDUMP) += librte_pdump\n DEPDIRS-librte_pdump := librte_eal librte_mempool librte_mbuf librte_ether\n DIRS-$(CONFIG_RTE_LIBRTE_GSO) += librte_gso\n-DEPDIRS-librte_gso := librte_eal librte_mbuf librte_ether librte_net\n+DEPDIRS-librte_gso := librte_eal librte_mbuf librte_ether librte_net librte_mempool\n \n ifeq ($(CONFIG_RTE_EXEC_ENV_LINUXAPP),y)\n DIRS-$(CONFIG_RTE_LIBRTE_KNI) += librte_kni\ndiff --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 @@ struct 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..2be64d1 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_tcp4.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..ee75d4c\n--- /dev/null\n+++ b/lib/librte_gso/gso_common.c\n@@ -0,0 +1,153 @@\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 <errno.h>\n+\n+#include <rte_memcpy.h>\n+#include <rte_mempool.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+\n+\t/* Copy the 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_free(pkts[i]);\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, *prev_segment;\n+\tuint16_t pkt_in_data_pos, segment_bytes_remaining;\n+\tuint16_t pyld_len, nb_segs;\n+\tbool more_in_pkt, more_out_segs;\n+\n+\tpkt_in = pkt;\n+\tnb_segs = 0;\n+\tmore_in_pkt = 1;\n+\tpkt_in_data_pos = pkt_hdr_offset;\n+\n+\twhile (more_in_pkt) {\n+\t\tif (unlikely(nb_segs >= nb_pkts_out)) {\n+\t\t\tfree_gso_segment(pkts_out, nb_segs);\n+\t\t\treturn -EINVAL;\n+\t\t}\n+\n+\t\t/* Allocate a direct MBUF */\n+\t\thdr_segment = rte_pktmbuf_alloc(direct_pool);\n+\t\tif (unlikely(hdr_segment == NULL)) {\n+\t\t\tfree_gso_segment(pkts_out, nb_segs);\n+\t\t\treturn -ENOMEM;\n+\t\t}\n+\t\t/* Fill the packet header */\n+\t\thdr_segment_init(hdr_segment, pkt, pkt_hdr_offset);\n+\n+\t\tprev_segment = hdr_segment;\n+\t\tsegment_bytes_remaining = pyld_unit_size;\n+\t\tmore_out_segs = 1;\n+\n+\t\twhile (more_out_segs && more_in_pkt) {\n+\t\t\t/* Allocate an 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+\t\t\t/* Attach to current MBUF segment of pkt */\n+\t\t\trte_pktmbuf_attach(pyld_segment, pkt_in);\n+\n+\t\t\tprev_segment->next = pyld_segment;\n+\t\t\tprev_segment = pyld_segment;\n+\n+\t\t\tpyld_len = segment_bytes_remaining;\n+\t\t\tif (pyld_len + pkt_in_data_pos > pkt_in->data_len)\n+\t\t\t\tpyld_len = pkt_in->data_len - pkt_in_data_pos;\n+\n+\t\t\tpyld_segment->data_off = pkt_in_data_pos +\n+\t\t\t\tpkt_in->data_off;\n+\t\t\tpyld_segment->data_len = pyld_len;\n+\n+\t\t\t/* Update header segment */\n+\t\t\thdr_segment->pkt_len += pyld_len;\n+\t\t\thdr_segment->nb_segs++;\n+\n+\t\t\tpkt_in_data_pos += pyld_len;\n+\t\t\tsegment_bytes_remaining -= pyld_len;\n+\n+\t\t\t/* Finish processing a MBUF segment of pkt */\n+\t\t\tif (pkt_in_data_pos == pkt_in->data_len) {\n+\t\t\t\tpkt_in = pkt_in->next;\n+\t\t\t\tpkt_in_data_pos = 0;\n+\t\t\t\tif (pkt_in == NULL)\n+\t\t\t\t\tmore_in_pkt = 0;\n+\t\t\t}\n+\n+\t\t\t/* Finish generating a GSO segment */\n+\t\t\tif (segment_bytes_remaining == 0)\n+\t\t\t\tmore_out_segs = 0;\n+\t\t}\n+\t\tpkts_out[nb_segs++] = hdr_segment;\n+\t}\n+\treturn nb_segs;\n+}\ndiff --git a/lib/librte_gso/gso_common.h b/lib/librte_gso/gso_common.h\nnew file mode 100644\nindex 0000000..a8ad638\n--- /dev/null\n+++ b/lib/librte_gso/gso_common.h\n@@ -0,0 +1,141 @@\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+\n+#include <rte_mbuf.h>\n+#include <rte_ip.h>\n+#include <rte_tcp.h>\n+\n+#define IS_FRAGMENTED(frag_off) (((frag_off) & IPV4_HDR_OFFSET_MASK) != 0 \\\n+\t\t|| ((frag_off) & IPV4_HDR_MF_FLAG) == IPV4_HDR_MF_FLAG)\n+\n+#define TCP_HDR_PSH_MASK ((uint8_t)0x08)\n+#define TCP_HDR_FIN_MASK ((uint8_t)0x01)\n+\n+#define IS_IPV4_TCP(flag) (((flag) & (PKT_TX_TCP_SEG | PKT_TX_IPV4)) == \\\n+\t\t(PKT_TX_TCP_SEG | PKT_TX_IPV4))\n+\n+/**\n+ * Internal function which updates the TCP header of a packet, following\n+ * segmentation. This is required to update the header's 'sent' sequence\n+ * number, and also to clear 'PSH' and 'FIN' flags for non-tail segments.\n+ *\n+ * @param pkt\n+ *  The packet containing the TCP header.\n+ * @param l4_offset\n+ *  The offset of the TCP header from the start of the packet.\n+ * @param sent_seq\n+ *  The sent sequence number.\n+ * @param non-tail\n+ *  Indicates whether or not this is a tail segment.\n+ */\n+static inline void\n+update_tcp_header(struct rte_mbuf *pkt, uint16_t l4_offset, uint32_t sent_seq,\n+\t\tuint8_t non_tail)\n+{\n+\tstruct tcp_hdr *tcp_hdr;\n+\n+\ttcp_hdr = (struct tcp_hdr *)(rte_pktmbuf_mtod(pkt, char *) +\n+\t\t\tl4_offset);\n+\ttcp_hdr->sent_seq = rte_cpu_to_be_32(sent_seq);\n+\tif (likely(non_tail))\n+\t\ttcp_hdr->tcp_flags &= (~(TCP_HDR_PSH_MASK |\n+\t\t\t\t\tTCP_HDR_FIN_MASK));\n+}\n+\n+/**\n+ * Internal function which updates the IPv4 header of a packet, following\n+ * segmentation. This is required to update the header's 'total_length' field,\n+ * to reflect the reduced length of the now-segmented packet. Furthermore, the\n+ * header's 'packet_id' field must be updated to reflect the new ID of the\n+ * now-segmented packet.\n+ *\n+ * @param pkt\n+ *  The packet containing the IPv4 header.\n+ * @param l3_offset\n+ *  The offset of the IPv4 header from the start of the packet.\n+ * @param id\n+ *  The new ID of the packet.\n+ */\n+static inline void\n+update_ipv4_header(struct rte_mbuf *pkt, uint16_t l3_offset, uint16_t id)\n+{\n+\tstruct ipv4_hdr *ipv4_hdr;\n+\n+\tipv4_hdr = (struct ipv4_hdr *)(rte_pktmbuf_mtod(pkt, char *) +\n+\t\t\tl3_offset);\n+\tipv4_hdr->total_length = rte_cpu_to_be_16(pkt->pkt_len - l3_offset);\n+\tipv4_hdr->packet_id = rte_cpu_to_be_16(id);\n+}\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 bytes.\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. If\n+ *  the memory space in pkts_out is insufficient, gso_do_segment() fails\n+ *  and returns -EINVAL.\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+ *  - Return -ENOMEM if run out of memory in MBUF pools.\n+ *  - Return -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_tcp4.c b/lib/librte_gso/gso_tcp4.c\nnew file mode 100644\nindex 0000000..d83e610\n--- /dev/null\n+++ b/lib/librte_gso/gso_tcp4.c\n@@ -0,0 +1,104 @@\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 \"gso_common.h\"\n+#include \"gso_tcp4.h\"\n+\n+static void\n+update_ipv4_tcp_headers(struct rte_mbuf *pkt, uint8_t ipid_delta,\n+\t\tstruct rte_mbuf **segs, uint16_t nb_segs)\n+{\n+\tstruct ipv4_hdr *ipv4_hdr;\n+\tstruct tcp_hdr *tcp_hdr;\n+\tuint32_t sent_seq;\n+\tuint16_t id, tail_idx, i;\n+\tuint16_t l3_offset = pkt->l2_len;\n+\tuint16_t l4_offset = l3_offset + pkt->l3_len;\n+\n+\tipv4_hdr = (struct ipv4_hdr *)(rte_pktmbuf_mtod(pkt, char*) +\n+\t\t\tl3_offset);\n+\ttcp_hdr = (struct tcp_hdr *)((char *)ipv4_hdr + pkt->l3_len);\n+\tid = rte_be_to_cpu_16(ipv4_hdr->packet_id);\n+\tsent_seq = rte_be_to_cpu_32(tcp_hdr->sent_seq);\n+\ttail_idx = nb_segs - 1;\n+\n+\tfor (i = 0; i < nb_segs; i++) {\n+\t\tupdate_ipv4_header(segs[i], l3_offset, id);\n+\t\tupdate_tcp_header(segs[i], l4_offset, sent_seq, i < tail_idx);\n+\t\tid += ipid_delta;\n+\t\tsent_seq += (segs[i]->pkt_len - segs[i]->data_len);\n+\t}\n+}\n+\n+int\n+gso_tcp4_segment(struct rte_mbuf *pkt,\n+\t\tuint16_t gso_size,\n+\t\tuint8_t ipid_delta,\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 ipv4_hdr *ipv4_hdr;\n+\tuint16_t tcp_dl;\n+\tuint16_t pyld_unit_size, hdr_offset;\n+\tuint16_t frag_off;\n+\tint ret;\n+\n+\t/* Don't process the fragmented packet */\n+\tipv4_hdr = (struct ipv4_hdr *)(rte_pktmbuf_mtod(pkt, char *) +\n+\t\t\tpkt->l2_len);\n+\tfrag_off = rte_be_to_cpu_16(ipv4_hdr->fragment_offset);\n+\tif (unlikely(IS_FRAGMENTED(frag_off))) {\n+\t\tpkts_out[0] = pkt;\n+\t\treturn 1;\n+\t}\n+\n+\t/* Don't process the packet without data */\n+\ttcp_dl = pkt->pkt_len - pkt->l2_len - pkt->l3_len - pkt->l4_len;\n+\tif (unlikely(tcp_dl == 0)) {\n+\t\tpkts_out[0] = pkt;\n+\t\treturn 1;\n+\t}\n+\n+\thdr_offset = pkt->l2_len + pkt->l3_len + pkt->l4_len;\n+\tpyld_unit_size = gso_size - hdr_offset;\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+\tif (ret > 1)\n+\t\tupdate_ipv4_tcp_headers(pkt, ipid_delta, pkts_out, ret);\n+\n+\treturn ret;\n+}\ndiff --git a/lib/librte_gso/gso_tcp4.h b/lib/librte_gso/gso_tcp4.h\nnew file mode 100644\nindex 0000000..1c57441\n--- /dev/null\n+++ b/lib/librte_gso/gso_tcp4.h\n@@ -0,0 +1,74 @@\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_TCP4_H_\n+#define _GSO_TCP4_H_\n+\n+#include <stdint.h>\n+#include <rte_mbuf.h>\n+\n+/**\n+ * Segment an IPv4/TCP packet. This function doesn't check if the input\n+ * packet has correct checksums, and doesn't update checksums for output\n+ * GSO segments. 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 ipid_delta\n+ *  The increasing unit of IP ids.\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 store the MBUF addresses of output GSO\n+ *  segments, when the function succeeds. If the memory space in\n+ *  pkts_out is insufficient, it fails and returns -EINVAL.\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 filled in pkts_out on success.\n+ *   - Return -ENOMEM if run out of memory in MBUF pools.\n+ *   - Return -EINVAL for invalid parameters.\n+ */\n+int gso_tcp4_segment(struct rte_mbuf *pkt,\n+\t\tuint16_t gso_size,\n+\t\tuint8_t ip_delta,\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/rte_gso.c b/lib/librte_gso/rte_gso.c\nindex b773636..2b6fc2d 100644\n--- a/lib/librte_gso/rte_gso.c\n+++ b/lib/librte_gso/rte_gso.c\n@@ -33,7 +33,12 @@\n \n #include <errno.h>\n \n+#include <rte_log.h>\n+#include <rte_ethdev.h>\n+\n #include \"rte_gso.h\"\n+#include \"gso_common.h\"\n+#include \"gso_tcp4.h\"\n \n int\n rte_gso_segment(struct rte_mbuf *pkt,\n@@ -41,12 +46,53 @@\n \t\tstruct rte_mbuf **pkts_out,\n \t\tuint16_t nb_pkts_out)\n {\n+\tstruct rte_mempool *direct_pool, *indirect_pool;\n+\tstruct rte_mbuf *pkt_seg;\n+\tuint64_t ol_flags;\n+\tuint16_t gso_size;\n+\tuint8_t ipid_delta;\n+\tint ret = 1;\n+\n \tif (pkt == NULL || pkts_out == NULL || gso_ctx == NULL ||\n \t\t\tnb_pkts_out < 1)\n \t\treturn -EINVAL;\n \n-\tpkt->ol_flags &= (~PKT_TX_TCP_SEG);\n-\tpkts_out[0] = pkt;\n+\tif ((gso_ctx->gso_size < RTE_GSO_SEG_SIZE_MIN) ||\n+\t\t\t(gso_ctx->gso_size >= pkt->pkt_len) ||\n+\t\t\t(gso_ctx->gso_types & DEV_TX_OFFLOAD_TCP_TSO) !=\n+\t\t\tgso_ctx->gso_types) {\n+\t\tpkt->ol_flags &= (~PKT_TX_TCP_SEG);\n+\t\tpkts_out[0] = pkt;\n+\t\treturn 1;\n+\t}\n+\n+\tdirect_pool = gso_ctx->direct_pool;\n+\tindirect_pool = gso_ctx->indirect_pool;\n+\tgso_size = gso_ctx->gso_size;\n+\tipid_delta = (gso_ctx->flag != RTE_GSO_FLAG_IPID_FIXED);\n+\tol_flags = pkt->ol_flags;\n+\n+\tif (IS_IPV4_TCP(pkt->ol_flags)) {\n+\t\tpkt->ol_flags &= (~PKT_TX_TCP_SEG);\n+\t\tret = gso_tcp4_segment(pkt, gso_size, ipid_delta,\n+\t\t\t\tdirect_pool, indirect_pool,\n+\t\t\t\tpkts_out, nb_pkts_out);\n+\t} else {\n+\t\tpkts_out[0] = pkt;\n+\t\tRTE_LOG(WARNING, GSO, \"Unsupported packet type\\n\");\n+\t\treturn 1;\n+\t}\n+\n+\tif (ret > 1) {\n+\t\tpkt_seg = pkt;\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} else if (ret < 0) {\n+\t\t/* Revert the ol_flags in the event of failure. */\n+\t\tpkt->ol_flags = ol_flags;\n+\t}\n \n-\treturn 1;\n+\treturn ret;\n }\ndiff --git a/lib/librte_gso/rte_gso.h b/lib/librte_gso/rte_gso.h\nindex 7d343d7..7ca2d81 100644\n--- a/lib/librte_gso/rte_gso.h\n+++ b/lib/librte_gso/rte_gso.h\n@@ -46,6 +46,10 @@\n #include <stdint.h>\n #include <rte_mbuf.h>\n \n+/* Minimum GSO segment size. */\n+#define RTE_GSO_SEG_SIZE_MIN (sizeof(struct ether_hdr) + \\\n+\t\tsizeof(struct ipv4_hdr) + sizeof(struct tcp_hdr) + 1)\n+\n /* GSO flags for rte_gso_ctx. */\n #define RTE_GSO_FLAG_IPID_FIXED (1ULL << 0)\n /**< Use fixed IP ids for output GSO segments. Setting\n@@ -81,7 +85,8 @@ struct rte_gso_ctx {\n \t */\n \tuint16_t gso_size;\n \t/**< maximum size of an output GSO segment, including packet\n-\t * header and payload, measured in bytes.\n+\t * header and payload, measured in bytes. Must exceed\n+\t * RTE_GSO_SEG_SIZE_MIN.\n \t */\n };\n \n",
    "prefixes": [
        "dpdk-dev",
        "v7",
        "2/6"
    ]
}