All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jiayu Hu <jiayu.hu@intel.com>
To: Mark Kavanagh <mark.b.kavanagh@intel.com>
Cc: dev@dpdk.org, jianfeng.tan@intel.com,
	konstantin.ananyev@intel.com, ferruh.yigit@intel.com,
	thomas@monjalon.net
Subject: Re: [PATCH v5 2/6] gso: add TCP/IPv4 GSO support
Date: Fri, 29 Sep 2017 11:12:48 +0800	[thread overview]
Message-ID: <20170929031248.GA15397@dpdk15.sh.intel.com> (raw)
In-Reply-To: <1506636833-25851-3-git-send-email-mark.b.kavanagh@intel.com>

Hi Mark,

One comment is inline.

Thanks,
Jiayu

On Thu, Sep 28, 2017 at 11:13:49PM +0100, Mark Kavanagh wrote:
> From: Jiayu Hu <jiayu.hu@intel.com>
> 
> This patch adds GSO support for TCP/IPv4 packets. Supported packets
> may include a single VLAN tag. TCP/IPv4 GSO doesn't check if input
> packets have correct checksums, and doesn't update checksums for
> output packets (the responsibility for this lies with the application).
> Additionally, TCP/IPv4 GSO doesn't process IP fragmented packets.
> 
> TCP/IPv4 GSO uses two chained MBUFs, one direct MBUF and one indrect
> MBUF, to organize an output packet. Note that we refer to these two
> chained MBUFs as a two-segment MBUF. The direct MBUF stores the packet
> header, while the indirect mbuf simply points to a location within the
> original packet's payload. Consequently, use of the GSO library requires
> multi-segment MBUF support in the TX functions of the NIC driver.
> 
> If a packet is GSO'd, TCP/IPv4 GSO reduces its MBUF refcnt by 1. As a
> result, when all of its GSOed segments are freed, the packet is freed
> automatically.
> 
> Signed-off-by: Jiayu Hu <jiayu.hu@intel.com>
> Signed-off-by: Mark Kavanagh <mark.b.kavanagh@intel.com>
> Tested-by: Lei Yao <lei.a.yao@intel.com>
> ---
>  doc/guides/rel_notes/release_17_11.rst  |  12 +++
>  lib/librte_eal/common/include/rte_log.h |   1 +
>  lib/librte_gso/Makefile                 |   2 +
>  lib/librte_gso/gso_common.c             | 153 ++++++++++++++++++++++++++++++++
>  lib/librte_gso/gso_common.h             | 141 +++++++++++++++++++++++++++++
>  lib/librte_gso/gso_tcp4.c               | 106 ++++++++++++++++++++++
>  lib/librte_gso/gso_tcp4.h               |  74 +++++++++++++++
>  lib/librte_gso/rte_gso.c                |  52 ++++++++++-
>  8 files changed, 538 insertions(+), 3 deletions(-)
>  create mode 100644 lib/librte_gso/gso_common.c
>  create mode 100644 lib/librte_gso/gso_common.h
>  create mode 100644 lib/librte_gso/gso_tcp4.c
>  create mode 100644 lib/librte_gso/gso_tcp4.h
> 
> diff --git a/doc/guides/rel_notes/release_17_11.rst b/doc/guides/rel_notes/release_17_11.rst
> index 7508be7..c414f73 100644
> --- a/doc/guides/rel_notes/release_17_11.rst
> +++ b/doc/guides/rel_notes/release_17_11.rst
> @@ -41,6 +41,18 @@ New Features
>       Also, make sure to start the actual text at the margin.
>       =========================================================
>  
> +* **Added the Generic Segmentation Offload Library.**
> +
> +  Added the Generic Segmentation Offload (GSO) library to enable
> +  applications to split large packets (e.g. MTU is 64KB) into small
> +  ones (e.g. MTU is 1500B). Supported packet types are:
> +
> +  * TCP/IPv4 packets, which may include a single VLAN tag.
> +
> +  The GSO library doesn't check if the input packets have correct
> +  checksums, and doesn't update checksums for output packets.
> +  Additionally, the GSO library doesn't process IP fragmented packets.
> +
>  
>  Resolved Issues
>  ---------------
> diff --git a/lib/librte_eal/common/include/rte_log.h b/lib/librte_eal/common/include/rte_log.h
> index ec8dba7..2fa1199 100644
> --- a/lib/librte_eal/common/include/rte_log.h
> +++ b/lib/librte_eal/common/include/rte_log.h
> @@ -87,6 +87,7 @@ struct rte_logs {
>  #define RTE_LOGTYPE_CRYPTODEV 17 /**< Log related to cryptodev. */
>  #define RTE_LOGTYPE_EFD       18 /**< Log related to EFD. */
>  #define RTE_LOGTYPE_EVENTDEV  19 /**< Log related to eventdev. */
> +#define RTE_LOGTYPE_GSO       20 /**< Log related to GSO. */
>  
>  /* these log types can be used in an application */
>  #define RTE_LOGTYPE_USER1     24 /**< User-defined log type 1. */
> diff --git a/lib/librte_gso/Makefile b/lib/librte_gso/Makefile
> index aeaacbc..2be64d1 100644
> --- a/lib/librte_gso/Makefile
> +++ b/lib/librte_gso/Makefile
> @@ -42,6 +42,8 @@ LIBABIVER := 1
>  
>  #source files
>  SRCS-$(CONFIG_RTE_LIBRTE_GSO) += rte_gso.c
> +SRCS-$(CONFIG_RTE_LIBRTE_GSO) += gso_common.c
> +SRCS-$(CONFIG_RTE_LIBRTE_GSO) += gso_tcp4.c
>  
>  # install this header file
>  SYMLINK-$(CONFIG_RTE_LIBRTE_GSO)-include += rte_gso.h
> diff --git a/lib/librte_gso/gso_common.c b/lib/librte_gso/gso_common.c
> new file mode 100644
> index 0000000..ee75d4c
> --- /dev/null
> +++ b/lib/librte_gso/gso_common.c
> @@ -0,0 +1,153 @@
> +/*-
> + *   BSD LICENSE
> + *
> + *   Copyright(c) 2017 Intel Corporation. All rights reserved.
> + *   All rights reserved.
> + *
> + *   Redistribution and use in source and binary forms, with or without
> + *   modification, are permitted provided that the following conditions
> + *   are met:
> + *
> + *     * Redistributions of source code must retain the above copyright
> + *       notice, this list of conditions and the following disclaimer.
> + *     * Redistributions in binary form must reproduce the above copyright
> + *       notice, this list of conditions and the following disclaimer in
> + *       the documentation and/or other materials provided with the
> + *       distribution.
> + *     * Neither the name of Intel Corporation nor the names of its
> + *       contributors may be used to endorse or promote products derived
> + *       from this software without specific prior written permission.
> + *
> + *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
> + *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
> + *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
> + *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
> + *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
> + *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
> + *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
> + *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
> + *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
> + *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
> + *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
> + */
> +
> +#include <stdbool.h>
> +#include <errno.h>
> +
> +#include <rte_memcpy.h>
> +#include <rte_mempool.h>
> +
> +#include "gso_common.h"
> +
> +static inline void
> +hdr_segment_init(struct rte_mbuf *hdr_segment, struct rte_mbuf *pkt,
> +		uint16_t pkt_hdr_offset)
> +{
> +	/* Copy MBUF metadata */
> +	hdr_segment->nb_segs = 1;
> +	hdr_segment->port = pkt->port;
> +	hdr_segment->ol_flags = pkt->ol_flags;
> +	hdr_segment->packet_type = pkt->packet_type;
> +	hdr_segment->pkt_len = pkt_hdr_offset;
> +	hdr_segment->data_len = pkt_hdr_offset;
> +	hdr_segment->tx_offload = pkt->tx_offload;
> +
> +	/* Copy the packet header */
> +	rte_memcpy(rte_pktmbuf_mtod(hdr_segment, char *),
> +			rte_pktmbuf_mtod(pkt, char *),
> +			pkt_hdr_offset);
> +}
> +
> +static inline void
> +free_gso_segment(struct rte_mbuf **pkts, uint16_t nb_pkts)
> +{
> +	uint16_t i;
> +
> +	for (i = 0; i < nb_pkts; i++)
> +		rte_pktmbuf_free(pkts[i]);
> +}
> +
> +int
> +gso_do_segment(struct rte_mbuf *pkt,
> +		uint16_t pkt_hdr_offset,
> +		uint16_t pyld_unit_size,
> +		struct rte_mempool *direct_pool,
> +		struct rte_mempool *indirect_pool,
> +		struct rte_mbuf **pkts_out,
> +		uint16_t nb_pkts_out)
> +{
> +	struct rte_mbuf *pkt_in;
> +	struct rte_mbuf *hdr_segment, *pyld_segment, *prev_segment;
> +	uint16_t pkt_in_data_pos, segment_bytes_remaining;
> +	uint16_t pyld_len, nb_segs;
> +	bool more_in_pkt, more_out_segs;
> +
> +	pkt_in = pkt;
> +	nb_segs = 0;
> +	more_in_pkt = 1;
> +	pkt_in_data_pos = pkt_hdr_offset;
> +
> +	while (more_in_pkt) {
> +		if (unlikely(nb_segs >= nb_pkts_out)) {
> +			free_gso_segment(pkts_out, nb_segs);
> +			return -EINVAL;
> +		}
> +
> +		/* Allocate a direct MBUF */
> +		hdr_segment = rte_pktmbuf_alloc(direct_pool);
> +		if (unlikely(hdr_segment == NULL)) {
> +			free_gso_segment(pkts_out, nb_segs);
> +			return -ENOMEM;
> +		}
> +		/* Fill the packet header */
> +		hdr_segment_init(hdr_segment, pkt, pkt_hdr_offset);
> +
> +		prev_segment = hdr_segment;
> +		segment_bytes_remaining = pyld_unit_size;
> +		more_out_segs = 1;
> +
> +		while (more_out_segs && more_in_pkt) {
> +			/* Allocate an indirect MBUF */
> +			pyld_segment = rte_pktmbuf_alloc(indirect_pool);
> +			if (unlikely(pyld_segment == NULL)) {
> +				rte_pktmbuf_free(hdr_segment);
> +				free_gso_segment(pkts_out, nb_segs);
> +				return -ENOMEM;
> +			}
> +			/* Attach to current MBUF segment of pkt */
> +			rte_pktmbuf_attach(pyld_segment, pkt_in);
> +
> +			prev_segment->next = pyld_segment;
> +			prev_segment = pyld_segment;
> +
> +			pyld_len = segment_bytes_remaining;
> +			if (pyld_len + pkt_in_data_pos > pkt_in->data_len)
> +				pyld_len = pkt_in->data_len - pkt_in_data_pos;
> +
> +			pyld_segment->data_off = pkt_in_data_pos +
> +				pkt_in->data_off;
> +			pyld_segment->data_len = pyld_len;
> +
> +			/* Update header segment */
> +			hdr_segment->pkt_len += pyld_len;
> +			hdr_segment->nb_segs++;
> +
> +			pkt_in_data_pos += pyld_len;
> +			segment_bytes_remaining -= pyld_len;
> +
> +			/* Finish processing a MBUF segment of pkt */
> +			if (pkt_in_data_pos == pkt_in->data_len) {
> +				pkt_in = pkt_in->next;
> +				pkt_in_data_pos = 0;
> +				if (pkt_in == NULL)
> +					more_in_pkt = 0;
> +			}
> +
> +			/* Finish generating a GSO segment */
> +			if (segment_bytes_remaining == 0)
> +				more_out_segs = 0;
> +		}
> +		pkts_out[nb_segs++] = hdr_segment;
> +	}
> +	return nb_segs;
> +}
> diff --git a/lib/librte_gso/gso_common.h b/lib/librte_gso/gso_common.h
> new file mode 100644
> index 0000000..8d9b94e
> --- /dev/null
> +++ b/lib/librte_gso/gso_common.h
> @@ -0,0 +1,141 @@
> +/*-
> + *   BSD LICENSE
> + *
> + *   Copyright(c) 2017 Intel Corporation. All rights reserved.
> + *   All rights reserved.
> + *
> + *   Redistribution and use in source and binary forms, with or without
> + *   modification, are permitted provided that the following conditions
> + *   are met:
> + *
> + *     * Redistributions of source code must retain the above copyright
> + *       notice, this list of conditions and the following disclaimer.
> + *     * Redistributions in binary form must reproduce the above copyright
> + *       notice, this list of conditions and the following disclaimer in
> + *       the documentation and/or other materials provided with the
> + *       distribution.
> + *     * Neither the name of Intel Corporation nor the names of its
> + *       contributors may be used to endorse or promote products derived
> + *       from this software without specific prior written permission.
> + *
> + *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
> + *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
> + *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
> + *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
> + *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
> + *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
> + *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
> + *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
> + *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
> + *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
> + *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
> + */
> +
> +#ifndef _GSO_COMMON_H_
> +#define _GSO_COMMON_H_
> +
> +#include <stdint.h>
> +
> +#include <rte_mbuf.h>
> +#include <rte_ip.h>
> +#include <rte_tcp.h>
> +
> +#define IS_FRAGMENTED(frag_off) (((frag_off) & IPV4_HDR_OFFSET_MASK) != 0 \
> +		|| ((frag_off) & IPV4_HDR_MF_FLAG) == IPV4_HDR_MF_FLAG)
> +
> +#define TCP_HDR_PSH_MASK ((uint8_t)0x08)
> +#define TCP_HDR_FIN_MASK ((uint8_t)0x01)
> +
> +#define IS_IPV4_TCP(flag) (((flag) & (PKT_TX_TCP_SEG | PKT_TX_IPV4)) == \
> +		(PKT_TX_TCP_SEG | PKT_TX_IPV4))
> +
> +/**
> + * Internal function which updates the TCP header of a packet, following
> + * segmentation. This is required to update the header's 'sent' sequence
> + * number, and also to clear 'PSH' and 'FIN' flags for non-tail segments.
> + *
> + * @param pkt
> + *  The packet containing the TCP header.
> + * @param l4_offset
> + *  The offset of the TCP header from the start of the packet.
> + * @param sent_seq
> + *  The sent sequence number.
> + * @param non-tail
> + *  Indicates whether or not this is a tail segment.
> + */
> +static inline void
> +update_tcp_header(struct rte_mbuf *pkt, uint16_t l4_offset, uint32_t sent_seq,
> +		uint8_t non_tail)
> +{
> +	struct tcp_hdr *tcp_hdr;
> +
> +	tcp_hdr = (struct tcp_hdr *)(rte_pktmbuf_mtod(pkt, char *) +
> +			l4_offset);
> +	tcp_hdr->sent_seq = rte_cpu_to_be_32(sent_seq);
> +	if (likely(non_tail))
> +		tcp_hdr->tcp_flags &= (~(TCP_HDR_PSH_MASK |
> +					TCP_HDR_FIN_MASK));
> +}
> +
> +/**
> + * Internal function which updates the IPv4 header of a packet, following
> + * segmentation. This is required to update the header's 'total_length' field,
> + * to reflect the reduced length of the now-segmented packet. Furthermore, the
> + * header's 'packet_id' field must be updated to reflect the new ID of the
> + * now-segmented packet.
> + *
> + * @param pkt
> + *  The packet containing the IPv4 header.
> + * @param l3_offset
> + *  The offset of the IPv4 header from the start of the packet.
> + * @param id
> + *  The new ID of the packet.
> +  */
> +static inline void
> +update_ipv4_header(struct rte_mbuf *pkt, uint16_t l3_offset, uint16_t id)
> +{
> +	struct ipv4_hdr *ipv4_hdr;
> +
> +	ipv4_hdr = (struct ipv4_hdr *)(rte_pktmbuf_mtod(pkt, char *) +
> +			l3_offset);
> +	ipv4_hdr->total_length = rte_cpu_to_be_16(pkt->pkt_len - l3_offset);
> +	ipv4_hdr->packet_id = rte_cpu_to_be_16(id);
> +}
> +
> +/**
> + * Internal function which divides the input packet into small segments.
> + * Each of the newly-created segments is organized as a two-segment MBUF,
> + * where the first segment is a standard mbuf, which stores a copy of
> + * packet header, and the second is an indirect mbuf which points to a
> + * section of data in the input packet.
> + *
> + * @param pkt
> + *  Packet to segment.
> + * @param pkt_hdr_offset
> + *  Packet header offset, measured in bytes.
> + * @param pyld_unit_size
> + *  The max payload length of a GSO segment.
> + * @param direct_pool
> + *  MBUF pool used for allocating direct buffers for output segments.
> + * @param indirect_pool
> + *  MBUF pool used for allocating indirect buffers for output segments.
> + * @param pkts_out
> + *  Pointer array used to keep the mbuf addresses of output segments. If
> + *  the memory space in pkts_out is insufficient, gso_do_segment() fails
> + *  and returns -EINVAL.
> + * @param nb_pkts_out
> + *  The max number of items that pkts_out can keep.
> + *
> + * @return
> + *  - The number of segments created in the event of success.
> + *  - Return -ENOMEM if run out of memory in MBUF pools.
> + *  - Return -EINVAL for invalid parameters.
> + */
> +int gso_do_segment(struct rte_mbuf *pkt,
> +		uint16_t pkt_hdr_offset,
> +		uint16_t pyld_unit_size,
> +		struct rte_mempool *direct_pool,
> +		struct rte_mempool *indirect_pool,
> +		struct rte_mbuf **pkts_out,
> +		uint16_t nb_pkts_out);
> +#endif
> diff --git a/lib/librte_gso/gso_tcp4.c b/lib/librte_gso/gso_tcp4.c
> new file mode 100644
> index 0000000..584a77d
> --- /dev/null
> +++ b/lib/librte_gso/gso_tcp4.c
> @@ -0,0 +1,106 @@
> +/*-
> + *   BSD LICENSE
> + *
> + *   Copyright(c) 2017 Intel Corporation. All rights reserved.
> + *   All rights reserved.
> + *
> + *   Redistribution and use in source and binary forms, with or without
> + *   modification, are permitted provided that the following conditions
> + *   are met:
> + *
> + *     * Redistributions of source code must retain the above copyright
> + *       notice, this list of conditions and the following disclaimer.
> + *     * Redistributions in binary form must reproduce the above copyright
> + *       notice, this list of conditions and the following disclaimer in
> + *       the documentation and/or other materials provided with the
> + *       distribution.
> + *     * Neither the name of Intel Corporation nor the names of its
> + *       contributors may be used to endorse or promote products derived
> + *       from this software without specific prior written permission.
> + *
> + *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
> + *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
> + *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
> + *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
> + *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
> + *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
> + *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
> + *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
> + *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
> + *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
> + *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
> + */
> +
> +#include "gso_common.h"
> +#include "gso_tcp4.h"
> +
> +static void
> +update_ipv4_tcp_headers(struct rte_mbuf *pkt, uint64_t l3_offset,
> +		uint8_t ipid_delta, struct rte_mbuf **segs, uint16_t nb_segs)
> +{

No need to add "uint64_t l3_offset" as one parameter. We can directly get
l3_offset inside update_ipv4_tcp_headers().

Additionally, the type of l3_offset should be "uint16_t" instead of "uint64_t".
But if we change the prototype of update_ipv4_tcp_headers(), this issue doesn't
need to fix.

> +	struct ipv4_hdr *ipv4_hdr;
> +	struct tcp_hdr *tcp_hdr;
> +	uint32_t sent_seq;
> +	uint16_t id, tail_idx, i;
> +	uint16_t l4_offset;
> +
> +	ipv4_hdr = (struct ipv4_hdr *)(rte_pktmbuf_mtod(pkt, char*) +
> +			l3_offset);
> +	tcp_hdr = (struct tcp_hdr *)((char *)ipv4_hdr + pkt->l3_len);
> +	id = rte_be_to_cpu_16(ipv4_hdr->packet_id);
> +	sent_seq = rte_be_to_cpu_32(tcp_hdr->sent_seq);
> +	tail_idx = nb_segs - 1;
> +	l4_offset = l3_offset + pkt->l3_len;
> +
> +	for (i = 0; i < nb_segs; i++) {
> +		update_ipv4_header(segs[i], l3_offset, id);
> +		update_tcp_header(segs[i], l4_offset, sent_seq, i < tail_idx);
> +		id += ipid_delta;
> +		sent_seq += (segs[i]->pkt_len - segs[i]->data_len);
> +	}
> +}
> +
> +int
> +gso_tcp4_segment(struct rte_mbuf *pkt,
> +		uint16_t gso_size,
> +		uint8_t ipid_delta,
> +		struct rte_mempool *direct_pool,
> +		struct rte_mempool *indirect_pool,
> +		struct rte_mbuf **pkts_out,
> +		uint16_t nb_pkts_out)
> +{
> +	struct ipv4_hdr *ipv4_hdr;
> +	uint16_t tcp_dl;
> +	uint16_t pyld_unit_size, hdr_offset;
> +	uint16_t frag_off;
> +	int ret;
> +
> +	/* Don't process the fragmented packet */
> +	ipv4_hdr = (struct ipv4_hdr *)(rte_pktmbuf_mtod(pkt, char *) +
> +			pkt->l2_len);
> +	frag_off = rte_be_to_cpu_16(ipv4_hdr->fragment_offset);
> +	if (unlikely(IS_FRAGMENTED(frag_off))) {
> +		pkts_out[0] = pkt;
> +		return 1;
> +	}
> +
> +	/* Don't process the packet without data */
> +	tcp_dl = pkt->pkt_len - pkt->l2_len - pkt->l3_len - pkt->l4_len;
> +	if (unlikely(tcp_dl == 0)) {
> +		pkts_out[0] = pkt;
> +		return 1;
> +	}
> +
> +	hdr_offset = pkt->l2_len + pkt->l3_len + pkt->l4_len;
> +	pyld_unit_size = gso_size - hdr_offset;
> +
> +	/* Segment the payload */
> +	ret = gso_do_segment(pkt, hdr_offset, pyld_unit_size, direct_pool,
> +			indirect_pool, pkts_out, nb_pkts_out);
> +	if (ret > 1) {
> +		update_ipv4_tcp_headers(pkt, pkt->l2_len, ipid_delta,
> +				pkts_out, ret);
> +	}
> +
> +	return ret;
> +}
> diff --git a/lib/librte_gso/gso_tcp4.h b/lib/librte_gso/gso_tcp4.h
> new file mode 100644
> index 0000000..1c57441
> --- /dev/null
> +++ b/lib/librte_gso/gso_tcp4.h
> @@ -0,0 +1,74 @@
> +/*-
> + *   BSD LICENSE
> + *
> + *   Copyright(c) 2017 Intel Corporation. All rights reserved.
> + *   All rights reserved.
> + *
> + *   Redistribution and use in source and binary forms, with or without
> + *   modification, are permitted provided that the following conditions
> + *   are met:
> + *
> + *     * Redistributions of source code must retain the above copyright
> + *       notice, this list of conditions and the following disclaimer.
> + *     * Redistributions in binary form must reproduce the above copyright
> + *       notice, this list of conditions and the following disclaimer in
> + *       the documentation and/or other materials provided with the
> + *       distribution.
> + *     * Neither the name of Intel Corporation nor the names of its
> + *       contributors may be used to endorse or promote products derived
> + *       from this software without specific prior written permission.
> + *
> + *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
> + *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
> + *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
> + *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
> + *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
> + *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
> + *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
> + *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
> + *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
> + *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
> + *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
> + */
> +
> +#ifndef _GSO_TCP4_H_
> +#define _GSO_TCP4_H_
> +
> +#include <stdint.h>
> +#include <rte_mbuf.h>
> +
> +/**
> + * Segment an IPv4/TCP packet. This function doesn't check if the input
> + * packet has correct checksums, and doesn't update checksums for output
> + * GSO segments. Furthermore, it doesn't process IP fragment packets.
> + *
> + * @param pkt
> + *  The packet mbuf to segment.
> + * @param gso_size
> + *  The max length of a GSO segment, measured in bytes.
> + * @param ipid_delta
> + *  The increasing unit of IP ids.
> + * @param direct_pool
> + *  MBUF pool used for allocating direct buffers for output segments.
> + * @param indirect_pool
> + *  MBUF pool used for allocating indirect buffers for output segments.
> + * @param pkts_out
> + *  Pointer array used to store the MBUF addresses of output GSO
> + *  segments, when the function succeeds. If the memory space in
> + *  pkts_out is insufficient, it fails and returns -EINVAL.
> + * @param nb_pkts_out
> + *  The max number of items that 'pkts_out' can keep.
> + *
> + * @return
> + *   - The number of GSO segments filled in pkts_out on success.
> + *   - Return -ENOMEM if run out of memory in MBUF pools.
> + *   - Return -EINVAL for invalid parameters.
> + */
> +int gso_tcp4_segment(struct rte_mbuf *pkt,
> +		uint16_t gso_size,
> +		uint8_t ip_delta,
> +		struct rte_mempool *direct_pool,
> +		struct rte_mempool *indirect_pool,
> +		struct rte_mbuf **pkts_out,
> +		uint16_t nb_pkts_out);
> +#endif
> diff --git a/lib/librte_gso/rte_gso.c b/lib/librte_gso/rte_gso.c
> index b773636..a4fce50 100644
> --- a/lib/librte_gso/rte_gso.c
> +++ b/lib/librte_gso/rte_gso.c
> @@ -33,7 +33,12 @@
>  
>  #include <errno.h>
>  
> +#include <rte_log.h>
> +#include <rte_ethdev.h>
> +
>  #include "rte_gso.h"
> +#include "gso_common.h"
> +#include "gso_tcp4.h"
>  
>  int
>  rte_gso_segment(struct rte_mbuf *pkt,
> @@ -41,12 +46,53 @@
>  		struct rte_mbuf **pkts_out,
>  		uint16_t nb_pkts_out)
>  {
> +	struct rte_mempool *direct_pool, *indirect_pool;
> +	struct rte_mbuf *pkt_seg;
> +	uint64_t ol_flags;
> +	uint16_t gso_size;
> +	uint8_t ipid_delta;
> +	int ret = 1;
> +
>  	if (pkt == NULL || pkts_out == NULL || gso_ctx == NULL ||
>  			nb_pkts_out < 1)
>  		return -EINVAL;
>  
> -	pkt->ol_flags &= (~PKT_TX_TCP_SEG);
> -	pkts_out[0] = pkt;
> +	if ((gso_ctx->gso_size >= pkt->pkt_len) || (gso_ctx->gso_types &
> +				DEV_TX_OFFLOAD_TCP_TSO) !=
> +			gso_ctx->gso_types) {
> +		pkt->ol_flags &= (~PKT_TX_TCP_SEG);
> +		pkts_out[0] = pkt;
> +		return 1;
> +	}
> +
> +	direct_pool = gso_ctx->direct_pool;
> +	indirect_pool = gso_ctx->indirect_pool;
> +	gso_size = gso_ctx->gso_size;
> +	ipid_delta = (gso_ctx->ipid_flag != RTE_GSO_IPID_FIXED);
> +	ol_flags = pkt->ol_flags;
> +
> +	if (IS_IPV4_TCP(pkt->ol_flags)) {
> +		pkt->ol_flags &= (~PKT_TX_TCP_SEG);
> +		ret = gso_tcp4_segment(pkt, gso_size, ipid_delta,
> +				direct_pool, indirect_pool,
> +				pkts_out, nb_pkts_out);
> +	} else {
> +		pkt->ol_flags &= (~PKT_TX_TCP_SEG);
> +		pkts_out[0] = pkt;
> +		RTE_LOG(WARNING, GSO, "Unsupported packet type\n");
> +		return 1;
> +	}
> +
> +	if (ret > 1) {
> +		pkt_seg = pkt;
> +		while (pkt_seg) {
> +			rte_mbuf_refcnt_update(pkt_seg, -1);
> +			pkt_seg = pkt_seg->next;
> +		}
> +	} else if (ret < 0) {
> +		/* Revert the ol_flags in the event of failure. */
> +		pkt->ol_flags = ol_flags;
> +	}
>  
> -	return 1;
> +	return ret;
>  }
> -- 
> 1.9.3

  reply	other threads:[~2017-09-29  3:09 UTC|newest]

Thread overview: 157+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-24 14:15 [PATCH 0/5] Support TCP/IPv4, VxLAN and GRE GSO in DPDK Jiayu Hu
2017-08-24 14:15 ` [PATCH 1/5] lib: add Generic Segmentation Offload API framework Jiayu Hu
2017-08-30  1:38   ` Ananyev, Konstantin
2017-08-30  7:57     ` Jiayu Hu
2017-08-24 14:15 ` [PATCH 2/5] gso/lib: add TCP/IPv4 GSO support Jiayu Hu
2017-08-30  1:38   ` Ananyev, Konstantin
2017-08-30  2:55     ` Jiayu Hu
2017-08-30  9:25       ` Kavanagh, Mark B
2017-08-30  9:39         ` Ananyev, Konstantin
2017-08-30  9:59           ` Ananyev, Konstantin
2017-08-30 13:27             ` Kavanagh, Mark B
2017-08-30  9:03     ` Jiayu Hu
2017-09-04  3:31     ` Jiayu Hu
2017-09-04  9:54       ` Ananyev, Konstantin
2017-09-05  1:09         ` Hu, Jiayu
2017-09-11 13:04           ` Ananyev, Konstantin
2017-08-24 14:15 ` [PATCH 3/5] lib/gso: add VxLAN " Jiayu Hu
2017-08-24 14:15 ` [PATCH 4/5] lib/gso: add GRE " Jiayu Hu
2017-08-24 14:15 ` [PATCH 5/5] app/testpmd: enable TCP/IPv4, VxLAN and GRE GSO Jiayu Hu
2017-08-30  1:37 ` [PATCH 0/5] Support TCP/IPv4, VxLAN and GRE GSO in DPDK Ananyev, Konstantin
2017-08-30  7:36   ` Jiayu Hu
2017-08-30 10:49     ` Ananyev, Konstantin
2017-08-30 13:32       ` Kavanagh, Mark B
2017-09-05  7:57 ` [PATCH v2 " Jiayu Hu
2017-09-05  7:57   ` [PATCH v2 1/5] gso: add Generic Segmentation Offload API framework Jiayu Hu
2017-09-05  7:57   ` [PATCH v2 2/5] gso: add TCP/IPv4 GSO support Jiayu Hu
2017-09-05  7:57   ` [PATCH v2 3/5] gso: add VxLAN " Jiayu Hu
2017-09-05  7:57   ` [PATCH v2 4/5] gso: add GRE " Jiayu Hu
2017-09-05  7:57   ` [PATCH v2 5/5] app/testpmd: enable TCP/IPv4, VxLAN and GRE GSO Jiayu Hu
2017-09-12  2:43   ` [PATCH v3 0/5] Support TCP/IPv4, VxLAN and GRE GSO in DPDK Jiayu Hu
2017-09-12  2:43     ` [PATCH v3 1/5] gso: add Generic Segmentation Offload API framework Jiayu Hu
2017-09-12 10:36       ` Ananyev, Konstantin
2017-09-13  2:11         ` Jiayu Hu
2017-09-14 18:33       ` Ferruh Yigit
2017-09-15  1:12         ` Hu, Jiayu
2017-09-12  2:43     ` [PATCH v3 2/5] gso: add TCP/IPv4 GSO support Jiayu Hu
2017-09-12 11:17       ` Ananyev, Konstantin
2017-09-13  2:48         ` Jiayu Hu
2017-09-13  9:38           ` Ananyev, Konstantin
2017-09-13 10:23             ` Hu, Jiayu
2017-09-13 14:52             ` Kavanagh, Mark B
2017-09-13 15:13               ` Ananyev, Konstantin
2017-09-14  0:59                 ` Hu, Jiayu
2017-09-14  8:35                   ` Kavanagh, Mark B
2017-09-14  8:39                     ` Ananyev, Konstantin
2017-09-14  9:00                       ` Kavanagh, Mark B
2017-09-14  9:10                         ` Ananyev, Konstantin
2017-09-14  9:35                           ` Kavanagh, Mark B
2017-09-12 14:17       ` Ananyev, Konstantin
2017-09-13 10:44         ` Jiayu Hu
2017-09-13 22:10           ` Ananyev, Konstantin
2017-09-14  6:07             ` Jiayu Hu
2017-09-14  8:47               ` Ananyev, Konstantin
2017-09-14  9:29                 ` Hu, Jiayu
2017-09-14  9:35                   ` Ananyev, Konstantin
2017-09-14 10:01                     ` Hu, Jiayu
2017-09-14 15:42                       ` Kavanagh, Mark B
2017-09-14 18:38                         ` Ananyev, Konstantin
2017-09-15  7:54                           ` Hu, Jiayu
2017-09-15  8:15                             ` Ananyev, Konstantin
2017-09-15  8:17                             ` Ananyev, Konstantin
2017-09-15  8:38                               ` Hu, Jiayu
2017-09-14  8:51               ` Kavanagh, Mark B
2017-09-14  9:45                 ` Hu, Jiayu
2017-09-12  2:43     ` [PATCH v3 3/5] gso: add VxLAN " Jiayu Hu
2017-09-12  2:43     ` [PATCH v3 4/5] gso: add GRE " Jiayu Hu
2017-09-12  2:43     ` [PATCH v3 5/5] app/testpmd: enable TCP/IPv4, VxLAN and GRE GSO Jiayu Hu
2017-09-14 18:33       ` Ferruh Yigit
2017-09-15  1:13         ` Hu, Jiayu
2017-09-19  7:32     ` [PATCH v4 0/5] Support TCP/IPv4, VxLAN and GRE GSO in DPDK Jiayu Hu
2017-09-19  7:32       ` [PATCH v4 1/5] gso: add Generic Segmentation Offload API framework Jiayu Hu
2017-09-19  7:32       ` [PATCH v4 2/5] gso: add TCP/IPv4 GSO support Jiayu Hu
2017-09-20  7:03         ` Yao, Lei A
2017-09-19  7:32       ` [PATCH v4 3/5] gso: add VxLAN " Jiayu Hu
2017-09-20  3:11         ` Tan, Jianfeng
2017-09-20  3:17           ` Hu, Jiayu
2017-09-19  7:32       ` [PATCH v4 4/5] gso: add GRE " Jiayu Hu
2017-09-20  2:53         ` Tan, Jianfeng
2017-09-20  6:01           ` Hu, Jiayu
2017-09-19  7:32       ` [PATCH v4 5/5] app/testpmd: enable TCP/IPv4, VxLAN and GRE GSO Jiayu Hu
2017-09-28 22:13       ` [PATCH v5 0/6] Support TCP/IPv4, VxLAN and GRE GSO in DPDK Mark Kavanagh
2017-10-02 16:45         ` [PATCH v6 0/6] Support TCP/IPv4, VxLAN, " Mark Kavanagh
2017-10-02 16:45           ` [PATCH v6 1/6] gso: add Generic Segmentation Offload API framework Mark Kavanagh
2017-10-04 13:11             ` Ananyev, Konstantin
2017-10-04 13:21               ` Kavanagh, Mark B
2017-10-02 16:45           ` [PATCH v6 2/6] gso: add TCP/IPv4 GSO support Mark Kavanagh
2017-10-04 13:32             ` Ananyev, Konstantin
2017-10-04 14:30               ` Kavanagh, Mark B
2017-10-04 14:49                 ` Ananyev, Konstantin
2017-10-04 14:59                   ` Kavanagh, Mark B
2017-10-04 13:35             ` Ananyev, Konstantin
2017-10-04 14:22               ` Kavanagh, Mark B
2017-10-02 16:45           ` [PATCH v6 3/6] gso: add VxLAN " Mark Kavanagh
2017-10-04 14:12             ` Ananyev, Konstantin
2017-10-04 14:35               ` Kavanagh, Mark B
2017-10-04 16:13               ` Kavanagh, Mark B
2017-10-04 16:17                 ` Ananyev, Konstantin
2017-10-02 16:45           ` [PATCH v6 4/6] gso: add GRE " Mark Kavanagh
2017-10-04 14:15             ` Ananyev, Konstantin
2017-10-04 14:36               ` Kavanagh, Mark B
2017-10-02 16:45           ` [PATCH v6 5/6] app/testpmd: enable TCP/IPv4, VxLAN and GRE GSO Mark Kavanagh
2017-10-04 15:08             ` Ananyev, Konstantin
2017-10-04 16:23               ` Kavanagh, Mark B
2017-10-04 16:26                 ` Ananyev, Konstantin
2017-10-04 16:51                   ` Kavanagh, Mark B
2017-10-02 16:45           ` [PATCH v6 6/6] doc: add GSO programmer's guide Mark Kavanagh
2017-10-04 13:51             ` Mcnamara, John
2017-10-05 11:02           ` [PATCH v7 0/6] Support TCP/IPv4, VxLAN, and GRE GSO in DPDK Mark Kavanagh
2017-10-05 11:02             ` [PATCH v7 1/6] gso: add Generic Segmentation Offload API framework Mark Kavanagh
2017-10-05 11:02             ` [PATCH v7 2/6] gso: add TCP/IPv4 GSO support Mark Kavanagh
2017-10-05 11:02             ` [PATCH v7 3/6] gso: add VxLAN " Mark Kavanagh
2017-10-05 11:02             ` [PATCH v7 4/6] gso: add GRE " Mark Kavanagh
2017-10-05 11:02             ` [PATCH v7 5/6] app/testpmd: enable TCP/IPv4, VxLAN and GRE GSO Mark Kavanagh
2017-10-05 11:02             ` [PATCH v7 6/6] doc: add GSO programmer's guide Mark Kavanagh
2017-10-05 13:22             ` [PATCH v7 0/6] Support TCP/IPv4, VxLAN, and GRE GSO in DPDK Ananyev, Konstantin
2017-10-05 14:39               ` Kavanagh, Mark B
2017-10-05 15:43             ` [PATCH v8 " Mark Kavanagh
2017-10-05 17:12               ` Ananyev, Konstantin
2017-10-05 20:16                 ` Kavanagh, Mark B
2017-10-05 20:36               ` [PATCH v9 " Mark Kavanagh
2017-10-05 22:24                 ` Ananyev, Konstantin
2017-10-06  8:24                   ` FW: " Kavanagh, Mark B
2017-10-06 10:35                   ` Kavanagh, Mark B
2017-10-06 23:32                 ` Ferruh Yigit
2017-10-06 23:34                   ` Ferruh Yigit
2017-10-07 14:56                 ` [PATCH v10 " Jiayu Hu
2017-10-07 14:56                   ` [PATCH v10 1/6] gso: add Generic Segmentation Offload API framework Jiayu Hu
2017-10-07 14:56                   ` [PATCH v10 2/6] gso: add TCP/IPv4 GSO support Jiayu Hu
2017-10-07 14:56                   ` [PATCH v10 3/6] gso: add VxLAN " Jiayu Hu
2017-10-07 14:56                   ` [PATCH v10 4/6] gso: add GRE " Jiayu Hu
2017-10-07 14:56                   ` [PATCH v10 5/6] app/testpmd: enable TCP/IPv4, VxLAN and GRE GSO Jiayu Hu
2017-10-07 14:56                   ` [PATCH v10 6/6] doc: add GSO programmer's guide Jiayu Hu
2017-10-08  3:40                   ` [PATCH v10 0/6] Support TCP/IPv4, VxLAN, and GRE GSO in DPDK Ferruh Yigit
2017-10-05 20:36               ` [PATCH v9 1/6] gso: add Generic Segmentation Offload API framework Mark Kavanagh
2017-10-05 20:36               ` [PATCH v9 2/6] gso: add TCP/IPv4 GSO support Mark Kavanagh
2017-10-05 20:36               ` [PATCH v9 3/6] gso: add VxLAN " Mark Kavanagh
2017-10-05 20:36               ` [PATCH v9 4/6] gso: add GRE " Mark Kavanagh
2017-10-05 20:36               ` [PATCH v9 5/6] app/testpmd: enable TCP/IPv4, VxLAN and GRE GSO Mark Kavanagh
2017-10-05 20:36               ` [PATCH v9 6/6] doc: add GSO programmer's guide Mark Kavanagh
2017-10-06 13:34                 ` Mcnamara, John
2017-10-06 13:41                   ` Kavanagh, Mark B
2017-10-05 15:43             ` [PATCH v8 1/6] gso: add Generic Segmentation Offload API framework Mark Kavanagh
2017-10-05 15:44             ` [PATCH v8 2/6] gso: add TCP/IPv4 GSO support Mark Kavanagh
2017-10-05 15:44             ` [PATCH v8 3/6] gso: add VxLAN " Mark Kavanagh
2017-10-05 15:44             ` [PATCH v8 4/6] gso: add GRE " Mark Kavanagh
2017-10-05 15:44             ` [PATCH v8 5/6] app/testpmd: enable TCP/IPv4, VxLAN and GRE GSO Mark Kavanagh
2017-10-05 15:44             ` [PATCH v8 6/6] doc: add GSO programmer's guide Mark Kavanagh
2017-10-05 17:57               ` Mcnamara, John
2017-09-28 22:13       ` [PATCH v5 1/6] gso: add Generic Segmentation Offload API framework Mark Kavanagh
2017-09-28 22:13       ` [PATCH v5 2/6] gso: add TCP/IPv4 GSO support Mark Kavanagh
2017-09-29  3:12         ` Jiayu Hu [this message]
2017-09-29  9:05           ` Kavanagh, Mark B
2017-09-28 22:13       ` [PATCH v5 3/6] gso: add VxLAN " Mark Kavanagh
2017-09-28 22:13       ` [PATCH v5 4/6] gso: add GRE " Mark Kavanagh
2017-09-28 22:13       ` [PATCH v5 5/6] app/testpmd: enable TCP/IPv4, VxLAN and GRE GSO Mark Kavanagh
2017-09-28 22:13       ` [PATCH v5 6/6] doc: add GSO programmer's guide Mark Kavanagh
2017-09-28 22:18       ` [PATCH v5 2/6] gso: add TCP/IPv4 GSO support Mark Kavanagh

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170929031248.GA15397@dpdk15.sh.intel.com \
    --to=jiayu.hu@intel.com \
    --cc=dev@dpdk.org \
    --cc=ferruh.yigit@intel.com \
    --cc=jianfeng.tan@intel.com \
    --cc=konstantin.ananyev@intel.com \
    --cc=mark.b.kavanagh@intel.com \
    --cc=thomas@monjalon.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.