xref: /dpdk/lib/gro/rte_gro.h (revision 74080d7dcf31f02113df7ac1a38c2ee26a6d72b1)
199a2dd95SBruce Richardson /* SPDX-License-Identifier: BSD-3-Clause
299a2dd95SBruce Richardson  * Copyright(c) 2017 Intel Corporation
399a2dd95SBruce Richardson  */
499a2dd95SBruce Richardson 
599a2dd95SBruce Richardson #ifndef _RTE_GRO_H_
699a2dd95SBruce Richardson #define _RTE_GRO_H_
799a2dd95SBruce Richardson 
899a2dd95SBruce Richardson /**
999a2dd95SBruce Richardson  * @file
1099a2dd95SBruce Richardson  * Interface to GRO library
1199a2dd95SBruce Richardson  */
1299a2dd95SBruce Richardson 
1399a2dd95SBruce Richardson #include <stdint.h>
1499a2dd95SBruce Richardson #include <rte_mbuf.h>
1599a2dd95SBruce Richardson 
1699a2dd95SBruce Richardson #ifdef __cplusplus
1799a2dd95SBruce Richardson extern "C" {
1899a2dd95SBruce Richardson #endif
1999a2dd95SBruce Richardson 
2099a2dd95SBruce Richardson #define RTE_GRO_MAX_BURST_ITEM_NUM 128U
2199a2dd95SBruce Richardson /**< the max number of packets that rte_gro_reassemble_burst()
2299a2dd95SBruce Richardson  * can process in each invocation.
2399a2dd95SBruce Richardson  */
2499a2dd95SBruce Richardson #define RTE_GRO_TYPE_MAX_NUM 64
2599a2dd95SBruce Richardson /**< the max number of supported GRO types */
2699a2dd95SBruce Richardson #define RTE_GRO_TYPE_SUPPORT_NUM 2
2799a2dd95SBruce Richardson /**< the number of currently supported GRO types */
2899a2dd95SBruce Richardson 
2999a2dd95SBruce Richardson #define RTE_GRO_TCP_IPV4_INDEX 0
3099a2dd95SBruce Richardson #define RTE_GRO_TCP_IPV4 (1ULL << RTE_GRO_TCP_IPV4_INDEX)
3199a2dd95SBruce Richardson /**< TCP/IPv4 GRO flag */
3299a2dd95SBruce Richardson #define RTE_GRO_IPV4_VXLAN_TCP_IPV4_INDEX 1
3399a2dd95SBruce Richardson #define RTE_GRO_IPV4_VXLAN_TCP_IPV4 (1ULL << RTE_GRO_IPV4_VXLAN_TCP_IPV4_INDEX)
3499a2dd95SBruce Richardson /**< VxLAN TCP/IPv4 GRO flag. */
3599a2dd95SBruce Richardson #define RTE_GRO_UDP_IPV4_INDEX 2
3699a2dd95SBruce Richardson #define RTE_GRO_UDP_IPV4 (1ULL << RTE_GRO_UDP_IPV4_INDEX)
3799a2dd95SBruce Richardson /**< UDP/IPv4 GRO flag */
3899a2dd95SBruce Richardson #define RTE_GRO_IPV4_VXLAN_UDP_IPV4_INDEX 3
3999a2dd95SBruce Richardson #define RTE_GRO_IPV4_VXLAN_UDP_IPV4 (1ULL << RTE_GRO_IPV4_VXLAN_UDP_IPV4_INDEX)
4099a2dd95SBruce Richardson /**< VxLAN UDP/IPv4 GRO flag. */
41*74080d7dSKumara Parameshwaran #define RTE_GRO_TCP_IPV6_INDEX 4
42*74080d7dSKumara Parameshwaran #define RTE_GRO_TCP_IPV6 (1ULL << RTE_GRO_TCP_IPV6_INDEX)
43*74080d7dSKumara Parameshwaran /**< TCP/IPv6 GRO flag. */
4499a2dd95SBruce Richardson 
4599a2dd95SBruce Richardson /**
4699a2dd95SBruce Richardson  * Structure used to create GRO context objects or used to pass
4799a2dd95SBruce Richardson  * application-determined parameters to rte_gro_reassemble_burst().
4899a2dd95SBruce Richardson  */
4999a2dd95SBruce Richardson struct rte_gro_param {
5099a2dd95SBruce Richardson 	uint64_t gro_types;
5199a2dd95SBruce Richardson 	/**< desired GRO types */
5299a2dd95SBruce Richardson 	uint16_t max_flow_num;
5399a2dd95SBruce Richardson 	/**< max flow number */
5499a2dd95SBruce Richardson 	uint16_t max_item_per_flow;
5599a2dd95SBruce Richardson 	/**< max packet number per flow */
5699a2dd95SBruce Richardson 	uint16_t socket_id;
5799a2dd95SBruce Richardson 	/**< socket index for allocating GRO related data structures,
5899a2dd95SBruce Richardson 	 * like reassembly tables. When use rte_gro_reassemble_burst(),
5999a2dd95SBruce Richardson 	 * applications don't need to set this value.
6099a2dd95SBruce Richardson 	 */
6199a2dd95SBruce Richardson };
6299a2dd95SBruce Richardson 
6399a2dd95SBruce Richardson /**
6499a2dd95SBruce Richardson  * @warning
6599a2dd95SBruce Richardson  * @b EXPERIMENTAL: this API may change without prior notice
6699a2dd95SBruce Richardson  *
6799a2dd95SBruce Richardson  * This function create a GRO context object, which is used to merge
6899a2dd95SBruce Richardson  * packets in rte_gro_reassemble().
6999a2dd95SBruce Richardson  *
7099a2dd95SBruce Richardson  * @param param
7199a2dd95SBruce Richardson  *  applications use it to pass needed parameters to create a GRO
7299a2dd95SBruce Richardson  *  context object.
7399a2dd95SBruce Richardson  *
7499a2dd95SBruce Richardson  * @return
7599a2dd95SBruce Richardson  *  if create successfully, return a pointer which points to the GRO
7699a2dd95SBruce Richardson  *  context object. Otherwise, return NULL.
7799a2dd95SBruce Richardson  */
7899a2dd95SBruce Richardson void *rte_gro_ctx_create(const struct rte_gro_param *param);
7999a2dd95SBruce Richardson 
8099a2dd95SBruce Richardson /**
8199a2dd95SBruce Richardson  * @warning
8299a2dd95SBruce Richardson  * @b EXPERIMENTAL: this API may change without prior notice
8399a2dd95SBruce Richardson  *
8499a2dd95SBruce Richardson  * This function destroys a GRO context object.
8599a2dd95SBruce Richardson  *
8699a2dd95SBruce Richardson  * @param ctx
8799a2dd95SBruce Richardson  *  pointer points to a GRO context object.
8899a2dd95SBruce Richardson  */
8999a2dd95SBruce Richardson void rte_gro_ctx_destroy(void *ctx);
9099a2dd95SBruce Richardson 
9199a2dd95SBruce Richardson /**
9299a2dd95SBruce Richardson  * This is one of the main reassembly APIs, which merges numbers of
9399a2dd95SBruce Richardson  * packets at a time. It doesn't check if input packets have correct
9499a2dd95SBruce Richardson  * checksums and doesn't re-calculate checksums for merged packets.
9599a2dd95SBruce Richardson  * It assumes the packets are complete (i.e., MF==0 && frag_off==0),
9699a2dd95SBruce Richardson  * when IP fragmentation is possible (i.e., DF==0). The GROed packets
9799a2dd95SBruce Richardson  * are returned as soon as the function finishes.
9899a2dd95SBruce Richardson  *
9999a2dd95SBruce Richardson  * @param pkts
10099a2dd95SBruce Richardson  *  Pointer array pointing to the packets to reassemble. Besides, it
10199a2dd95SBruce Richardson  *  keeps MBUF addresses for the GROed packets.
10299a2dd95SBruce Richardson  * @param nb_pkts
10399a2dd95SBruce Richardson  *  The number of packets to reassemble
10499a2dd95SBruce Richardson  * @param param
10599a2dd95SBruce Richardson  *  Application-determined parameters for reassembling packets.
10699a2dd95SBruce Richardson  *
10799a2dd95SBruce Richardson  * @return
10899a2dd95SBruce Richardson  *  The number of packets after been GROed. If no packets are merged,
10999a2dd95SBruce Richardson  *  the return value is equals to nb_pkts.
11099a2dd95SBruce Richardson  */
11199a2dd95SBruce Richardson uint16_t rte_gro_reassemble_burst(struct rte_mbuf **pkts,
11299a2dd95SBruce Richardson 		uint16_t nb_pkts,
11399a2dd95SBruce Richardson 		const struct rte_gro_param *param);
11499a2dd95SBruce Richardson 
11599a2dd95SBruce Richardson /**
11699a2dd95SBruce Richardson  * @warning
11799a2dd95SBruce Richardson  * @b EXPERIMENTAL: this API may change without prior notice
11899a2dd95SBruce Richardson  *
11999a2dd95SBruce Richardson  * Reassembly function, which tries to merge input packets with the
12099a2dd95SBruce Richardson  * existed packets in the reassembly tables of a given GRO context.
12199a2dd95SBruce Richardson  * It doesn't check if input packets have correct checksums and doesn't
12299a2dd95SBruce Richardson  * re-calculate checksums for merged packets. Additionally, it assumes
12399a2dd95SBruce Richardson  * the packets are complete (i.e., MF==0 && frag_off==0), when IP
12499a2dd95SBruce Richardson  * fragmentation is possible (i.e., DF==0).
12599a2dd95SBruce Richardson  *
12699a2dd95SBruce Richardson  * If the input packets have invalid parameters (e.g. no data payload,
12799a2dd95SBruce Richardson  * unsupported GRO types), they are returned to applications. Otherwise,
12899a2dd95SBruce Richardson  * they are either merged or inserted into the table. Applications need
12999a2dd95SBruce Richardson  * to flush packets from the tables by flush API, if they want to get the
13099a2dd95SBruce Richardson  * GROed packets.
13199a2dd95SBruce Richardson  *
13299a2dd95SBruce Richardson  * @param pkts
13399a2dd95SBruce Richardson  *  Packets to reassemble. It's also used to store the unprocessed packets.
13499a2dd95SBruce Richardson  * @param nb_pkts
13599a2dd95SBruce Richardson  *  The number of packets to reassemble
13699a2dd95SBruce Richardson  * @param ctx
13799a2dd95SBruce Richardson  *  GRO context object pointer
13899a2dd95SBruce Richardson  *
13999a2dd95SBruce Richardson  * @return
14099a2dd95SBruce Richardson  *  The number of unprocessed packets.
14199a2dd95SBruce Richardson  */
14299a2dd95SBruce Richardson uint16_t rte_gro_reassemble(struct rte_mbuf **pkts,
14399a2dd95SBruce Richardson 		uint16_t nb_pkts,
14499a2dd95SBruce Richardson 		void *ctx);
14599a2dd95SBruce Richardson 
14699a2dd95SBruce Richardson /**
14799a2dd95SBruce Richardson  * @warning
14899a2dd95SBruce Richardson  * @b EXPERIMENTAL: this API may change without prior notice
14999a2dd95SBruce Richardson  *
15099a2dd95SBruce Richardson  * This function flushes the timeout packets from the reassembly tables
15199a2dd95SBruce Richardson  * of desired GRO types. The max number of flushed packets is the
15299a2dd95SBruce Richardson  * element number of 'out'.
15399a2dd95SBruce Richardson  *
15499a2dd95SBruce Richardson  * Additionally, the flushed packets may have incorrect checksums, since
15599a2dd95SBruce Richardson  * this function doesn't re-calculate checksums for merged packets.
15699a2dd95SBruce Richardson  *
15799a2dd95SBruce Richardson  * @param ctx
15899a2dd95SBruce Richardson  *  GRO context object pointer.
15999a2dd95SBruce Richardson  * @param timeout_cycles
16099a2dd95SBruce Richardson  *  The max TTL for packets in reassembly tables, measured in nanosecond.
16199a2dd95SBruce Richardson  * @param gro_types
16299a2dd95SBruce Richardson  *  This function flushes packets whose GRO types are specified by
16399a2dd95SBruce Richardson  *  gro_types.
16499a2dd95SBruce Richardson  * @param out
16599a2dd95SBruce Richardson  *  Pointer array used to keep flushed packets.
16699a2dd95SBruce Richardson  * @param max_nb_out
16799a2dd95SBruce Richardson  *  The element number of 'out'. It's also the max number of timeout
16899a2dd95SBruce Richardson  *  packets that can be flushed finally.
16999a2dd95SBruce Richardson  *
17099a2dd95SBruce Richardson  * @return
17199a2dd95SBruce Richardson  *  The number of flushed packets.
17299a2dd95SBruce Richardson  */
17399a2dd95SBruce Richardson uint16_t rte_gro_timeout_flush(void *ctx,
17499a2dd95SBruce Richardson 		uint64_t timeout_cycles,
17599a2dd95SBruce Richardson 		uint64_t gro_types,
17699a2dd95SBruce Richardson 		struct rte_mbuf **out,
17799a2dd95SBruce Richardson 		uint16_t max_nb_out);
17899a2dd95SBruce Richardson 
17999a2dd95SBruce Richardson /**
18099a2dd95SBruce Richardson  * @warning
18199a2dd95SBruce Richardson  * @b EXPERIMENTAL: this API may change without prior notice
18299a2dd95SBruce Richardson  *
18399a2dd95SBruce Richardson  * This function returns the number of packets in all reassembly tables
18499a2dd95SBruce Richardson  * of a given GRO context.
18599a2dd95SBruce Richardson  *
18699a2dd95SBruce Richardson  * @param ctx
18799a2dd95SBruce Richardson  *  GRO context object pointer.
18899a2dd95SBruce Richardson  *
18999a2dd95SBruce Richardson  * @return
19099a2dd95SBruce Richardson  *  The number of packets in the tables.
19199a2dd95SBruce Richardson  */
19299a2dd95SBruce Richardson uint64_t rte_gro_get_pkt_count(void *ctx);
19399a2dd95SBruce Richardson 
19499a2dd95SBruce Richardson #ifdef __cplusplus
19599a2dd95SBruce Richardson }
19699a2dd95SBruce Richardson #endif
19799a2dd95SBruce Richardson 
19899a2dd95SBruce Richardson #endif /* _RTE_GRO_H_ */
199