1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright(c) 2017 Intel Corporation 3 */ 4 5 #ifndef _RTE_GRO_H_ 6 #define _RTE_GRO_H_ 7 8 /** 9 * @file 10 * Interface to GRO library 11 */ 12 13 #include <stdint.h> 14 #include <rte_mbuf.h> 15 16 #ifdef __cplusplus 17 extern "C" { 18 #endif 19 20 #define RTE_GRO_MAX_BURST_ITEM_NUM 128U 21 /**< the max number of packets that rte_gro_reassemble_burst() 22 * can process in each invocation. 23 */ 24 #define RTE_GRO_TYPE_MAX_NUM 64 25 /**< the max number of supported GRO types */ 26 #define RTE_GRO_TYPE_SUPPORT_NUM 2 27 /**< the number of currently supported GRO types */ 28 29 #define RTE_GRO_TCP_IPV4_INDEX 0 30 #define RTE_GRO_TCP_IPV4 (1ULL << RTE_GRO_TCP_IPV4_INDEX) 31 /**< TCP/IPv4 GRO flag */ 32 #define RTE_GRO_IPV4_VXLAN_TCP_IPV4_INDEX 1 33 #define RTE_GRO_IPV4_VXLAN_TCP_IPV4 (1ULL << RTE_GRO_IPV4_VXLAN_TCP_IPV4_INDEX) 34 /**< VxLAN TCP/IPv4 GRO flag. */ 35 #define RTE_GRO_UDP_IPV4_INDEX 2 36 #define RTE_GRO_UDP_IPV4 (1ULL << RTE_GRO_UDP_IPV4_INDEX) 37 /**< UDP/IPv4 GRO flag */ 38 #define RTE_GRO_IPV4_VXLAN_UDP_IPV4_INDEX 3 39 #define RTE_GRO_IPV4_VXLAN_UDP_IPV4 (1ULL << RTE_GRO_IPV4_VXLAN_UDP_IPV4_INDEX) 40 /**< VxLAN UDP/IPv4 GRO flag. */ 41 #define RTE_GRO_TCP_IPV6_INDEX 4 42 #define RTE_GRO_TCP_IPV6 (1ULL << RTE_GRO_TCP_IPV6_INDEX) 43 /**< TCP/IPv6 GRO flag. */ 44 45 /** 46 * Structure used to create GRO context objects or used to pass 47 * application-determined parameters to rte_gro_reassemble_burst(). 48 */ 49 struct rte_gro_param { 50 uint64_t gro_types; 51 /**< desired GRO types */ 52 uint16_t max_flow_num; 53 /**< max flow number */ 54 uint16_t max_item_per_flow; 55 /**< max packet number per flow */ 56 uint16_t socket_id; 57 /**< socket index for allocating GRO related data structures, 58 * like reassembly tables. When use rte_gro_reassemble_burst(), 59 * applications don't need to set this value. 60 */ 61 }; 62 63 /** 64 * @warning 65 * @b EXPERIMENTAL: this API may change without prior notice 66 * 67 * This function create a GRO context object, which is used to merge 68 * packets in rte_gro_reassemble(). 69 * 70 * @param param 71 * applications use it to pass needed parameters to create a GRO 72 * context object. 73 * 74 * @return 75 * if create successfully, return a pointer which points to the GRO 76 * context object. Otherwise, return NULL. 77 */ 78 void *rte_gro_ctx_create(const struct rte_gro_param *param); 79 80 /** 81 * @warning 82 * @b EXPERIMENTAL: this API may change without prior notice 83 * 84 * This function destroys a GRO context object. 85 * 86 * @param ctx 87 * pointer points to a GRO context object. 88 */ 89 void rte_gro_ctx_destroy(void *ctx); 90 91 /** 92 * This is one of the main reassembly APIs, which merges numbers of 93 * packets at a time. It doesn't check if input packets have correct 94 * checksums and doesn't re-calculate checksums for merged packets. 95 * It assumes the packets are complete (i.e., MF==0 && frag_off==0), 96 * when IP fragmentation is possible (i.e., DF==0). The GROed packets 97 * are returned as soon as the function finishes. 98 * 99 * @param pkts 100 * Pointer array pointing to the packets to reassemble. Besides, it 101 * keeps MBUF addresses for the GROed packets. 102 * @param nb_pkts 103 * The number of packets to reassemble 104 * @param param 105 * Application-determined parameters for reassembling packets. 106 * 107 * @return 108 * The number of packets after been GROed. If no packets are merged, 109 * the return value is equals to nb_pkts. 110 */ 111 uint16_t rte_gro_reassemble_burst(struct rte_mbuf **pkts, 112 uint16_t nb_pkts, 113 const struct rte_gro_param *param); 114 115 /** 116 * @warning 117 * @b EXPERIMENTAL: this API may change without prior notice 118 * 119 * Reassembly function, which tries to merge input packets with the 120 * existed packets in the reassembly tables of a given GRO context. 121 * It doesn't check if input packets have correct checksums and doesn't 122 * re-calculate checksums for merged packets. Additionally, it assumes 123 * the packets are complete (i.e., MF==0 && frag_off==0), when IP 124 * fragmentation is possible (i.e., DF==0). 125 * 126 * If the input packets have invalid parameters (e.g. no data payload, 127 * unsupported GRO types), they are returned to applications. Otherwise, 128 * they are either merged or inserted into the table. Applications need 129 * to flush packets from the tables by flush API, if they want to get the 130 * GROed packets. 131 * 132 * @param pkts 133 * Packets to reassemble. It's also used to store the unprocessed packets. 134 * @param nb_pkts 135 * The number of packets to reassemble 136 * @param ctx 137 * GRO context object pointer 138 * 139 * @return 140 * The number of unprocessed packets. 141 */ 142 uint16_t rte_gro_reassemble(struct rte_mbuf **pkts, 143 uint16_t nb_pkts, 144 void *ctx); 145 146 /** 147 * @warning 148 * @b EXPERIMENTAL: this API may change without prior notice 149 * 150 * This function flushes the timeout packets from the reassembly tables 151 * of desired GRO types. The max number of flushed packets is the 152 * element number of 'out'. 153 * 154 * Additionally, the flushed packets may have incorrect checksums, since 155 * this function doesn't re-calculate checksums for merged packets. 156 * 157 * @param ctx 158 * GRO context object pointer. 159 * @param timeout_cycles 160 * The max TTL for packets in reassembly tables, measured in nanosecond. 161 * @param gro_types 162 * This function flushes packets whose GRO types are specified by 163 * gro_types. 164 * @param out 165 * Pointer array used to keep flushed packets. 166 * @param max_nb_out 167 * The element number of 'out'. It's also the max number of timeout 168 * packets that can be flushed finally. 169 * 170 * @return 171 * The number of flushed packets. 172 */ 173 uint16_t rte_gro_timeout_flush(void *ctx, 174 uint64_t timeout_cycles, 175 uint64_t gro_types, 176 struct rte_mbuf **out, 177 uint16_t max_nb_out); 178 179 /** 180 * @warning 181 * @b EXPERIMENTAL: this API may change without prior notice 182 * 183 * This function returns the number of packets in all reassembly tables 184 * of a given GRO context. 185 * 186 * @param ctx 187 * GRO context object pointer. 188 * 189 * @return 190 * The number of packets in the tables. 191 */ 192 uint64_t rte_gro_get_pkt_count(void *ctx); 193 194 #ifdef __cplusplus 195 } 196 #endif 197 198 #endif /* _RTE_GRO_H_ */ 199