app/testpmd: use a structure to store offload info in csum fwd engine
[dpdk.git] / app / test-pmd / csumonly.c
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
5  *   Copyright 2014 6WIND S.A.
6  *   All rights reserved.
7  *
8  *   Redistribution and use in source and binary forms, with or without
9  *   modification, are permitted provided that the following conditions
10  *   are met:
11  *
12  *     * Redistributions of source code must retain the above copyright
13  *       notice, this list of conditions and the following disclaimer.
14  *     * Redistributions in binary form must reproduce the above copyright
15  *       notice, this list of conditions and the following disclaimer in
16  *       the documentation and/or other materials provided with the
17  *       distribution.
18  *     * Neither the name of Intel Corporation nor the names of its
19  *       contributors may be used to endorse or promote products derived
20  *       from this software without specific prior written permission.
21  *
22  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  */
34
35 #include <stdarg.h>
36 #include <stdio.h>
37 #include <errno.h>
38 #include <stdint.h>
39 #include <unistd.h>
40 #include <inttypes.h>
41
42 #include <sys/queue.h>
43 #include <sys/stat.h>
44
45 #include <rte_common.h>
46 #include <rte_byteorder.h>
47 #include <rte_log.h>
48 #include <rte_debug.h>
49 #include <rte_cycles.h>
50 #include <rte_memory.h>
51 #include <rte_memcpy.h>
52 #include <rte_memzone.h>
53 #include <rte_launch.h>
54 #include <rte_tailq.h>
55 #include <rte_eal.h>
56 #include <rte_per_lcore.h>
57 #include <rte_lcore.h>
58 #include <rte_atomic.h>
59 #include <rte_branch_prediction.h>
60 #include <rte_ring.h>
61 #include <rte_memory.h>
62 #include <rte_mempool.h>
63 #include <rte_mbuf.h>
64 #include <rte_memcpy.h>
65 #include <rte_interrupts.h>
66 #include <rte_pci.h>
67 #include <rte_ether.h>
68 #include <rte_ethdev.h>
69 #include <rte_ip.h>
70 #include <rte_tcp.h>
71 #include <rte_udp.h>
72 #include <rte_sctp.h>
73 #include <rte_prefetch.h>
74 #include <rte_string_fns.h>
75 #include "testpmd.h"
76
77 #define IP_DEFTTL  64   /* from RFC 1340. */
78 #define IP_VERSION 0x40
79 #define IP_HDRLEN  0x05 /* default IP header length == five 32-bits words. */
80 #define IP_VHL_DEF (IP_VERSION | IP_HDRLEN)
81
82 /* We cannot use rte_cpu_to_be_16() on a constant in a switch/case */
83 #if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
84 #define _htons(x) ((uint16_t)((((x) & 0x00ffU) << 8) | (((x) & 0xff00U) >> 8)))
85 #else
86 #define _htons(x) (x)
87 #endif
88
89 /* structure that caches offload info for the current packet */
90 struct testpmd_offload_info {
91         uint16_t ethertype;
92         uint16_t l2_len;
93         uint16_t l3_len;
94         uint16_t l4_len;
95         uint8_t l4_proto;
96         uint8_t l4_tun_len;
97         uint8_t is_tunnel;
98         uint16_t outer_ethertype;
99         uint16_t outer_l2_len;
100         uint16_t outer_l3_len;
101         uint16_t tso_segsz;
102 };
103
104 static uint16_t
105 get_psd_sum(void *l3_hdr, uint16_t ethertype, uint64_t ol_flags)
106 {
107         if (ethertype == _htons(ETHER_TYPE_IPv4))
108                 return rte_ipv4_phdr_cksum(l3_hdr, ol_flags);
109         else /* assume ethertype == ETHER_TYPE_IPv6 */
110                 return rte_ipv6_phdr_cksum(l3_hdr, ol_flags);
111 }
112
113 static uint16_t
114 get_udptcp_checksum(void *l3_hdr, void *l4_hdr, uint16_t ethertype)
115 {
116         if (ethertype == _htons(ETHER_TYPE_IPv4))
117                 return rte_ipv4_udptcp_cksum(l3_hdr, l4_hdr);
118         else /* assume ethertype == ETHER_TYPE_IPv6 */
119                 return rte_ipv6_udptcp_cksum(l3_hdr, l4_hdr);
120 }
121
122 /* Parse an IPv4 header to fill l3_len, l4_len, and l4_proto */
123 static void
124 parse_ipv4(struct ipv4_hdr *ipv4_hdr, struct testpmd_offload_info *info)
125 {
126         struct tcp_hdr *tcp_hdr;
127
128         info->l3_len = (ipv4_hdr->version_ihl & 0x0f) * 4;
129         info->l4_proto = ipv4_hdr->next_proto_id;
130
131         /* only fill l4_len for TCP, it's useful for TSO */
132         if (info->l4_proto == IPPROTO_TCP) {
133                 tcp_hdr = (struct tcp_hdr *)((char *)ipv4_hdr + info->l3_len);
134                 info->l4_len = (tcp_hdr->data_off & 0xf0) >> 2;
135         } else
136                 info->l4_len = 0;
137 }
138
139 /* Parse an IPv6 header to fill l3_len, l4_len, and l4_proto */
140 static void
141 parse_ipv6(struct ipv6_hdr *ipv6_hdr, struct testpmd_offload_info *info)
142 {
143         struct tcp_hdr *tcp_hdr;
144
145         info->l3_len = sizeof(struct ipv6_hdr);
146         info->l4_proto = ipv6_hdr->proto;
147
148         /* only fill l4_len for TCP, it's useful for TSO */
149         if (info->l4_proto == IPPROTO_TCP) {
150                 tcp_hdr = (struct tcp_hdr *)((char *)ipv6_hdr + info->l3_len);
151                 info->l4_len = (tcp_hdr->data_off & 0xf0) >> 2;
152         } else
153                 info->l4_len = 0;
154 }
155
156 /*
157  * Parse an ethernet header to fill the ethertype, l2_len, l3_len and
158  * ipproto. This function is able to recognize IPv4/IPv6 with one optional vlan
159  * header. The l4_len argument is only set in case of TCP (useful for TSO).
160  */
161 static void
162 parse_ethernet(struct ether_hdr *eth_hdr, struct testpmd_offload_info *info)
163 {
164         struct ipv4_hdr *ipv4_hdr;
165         struct ipv6_hdr *ipv6_hdr;
166
167         info->l2_len = sizeof(struct ether_hdr);
168         info->ethertype = eth_hdr->ether_type;
169
170         if (info->ethertype == _htons(ETHER_TYPE_VLAN)) {
171                 struct vlan_hdr *vlan_hdr = (struct vlan_hdr *)(eth_hdr + 1);
172
173                 info->l2_len  += sizeof(struct vlan_hdr);
174                 info->ethertype = vlan_hdr->eth_proto;
175         }
176
177         switch (info->ethertype) {
178         case _htons(ETHER_TYPE_IPv4):
179                 ipv4_hdr = (struct ipv4_hdr *) ((char *)eth_hdr + info->l2_len);
180                 parse_ipv4(ipv4_hdr, info);
181                 break;
182         case _htons(ETHER_TYPE_IPv6):
183                 ipv6_hdr = (struct ipv6_hdr *) ((char *)eth_hdr + info->l2_len);
184                 parse_ipv6(ipv6_hdr, info);
185                 break;
186         default:
187                 info->l4_len = 0;
188                 info->l3_len = 0;
189                 info->l4_proto = 0;
190                 break;
191         }
192 }
193
194 /* modify the IPv4 or IPv4 source address of a packet */
195 static void
196 change_ip_addresses(void *l3_hdr, uint16_t ethertype)
197 {
198         struct ipv4_hdr *ipv4_hdr = l3_hdr;
199         struct ipv6_hdr *ipv6_hdr = l3_hdr;
200
201         if (ethertype == _htons(ETHER_TYPE_IPv4)) {
202                 ipv4_hdr->src_addr =
203                         rte_cpu_to_be_32(rte_be_to_cpu_32(ipv4_hdr->src_addr) + 1);
204         } else if (ethertype == _htons(ETHER_TYPE_IPv6)) {
205                 ipv6_hdr->src_addr[15] = ipv6_hdr->src_addr[15] + 1;
206         }
207 }
208
209 /* if possible, calculate the checksum of a packet in hw or sw,
210  * depending on the testpmd command line configuration */
211 static uint64_t
212 process_inner_cksums(void *l3_hdr, const struct testpmd_offload_info *info,
213         uint16_t testpmd_ol_flags)
214 {
215         struct ipv4_hdr *ipv4_hdr = l3_hdr;
216         struct udp_hdr *udp_hdr;
217         struct tcp_hdr *tcp_hdr;
218         struct sctp_hdr *sctp_hdr;
219         uint64_t ol_flags = 0;
220
221         if (info->ethertype == _htons(ETHER_TYPE_IPv4)) {
222                 ipv4_hdr = l3_hdr;
223                 ipv4_hdr->hdr_checksum = 0;
224
225                 ol_flags |= PKT_TX_IPV4;
226                 if (info->tso_segsz != 0 && info->l4_proto == IPPROTO_TCP) {
227                         ol_flags |= PKT_TX_IP_CKSUM;
228                 } else {
229                         if (testpmd_ol_flags & TESTPMD_TX_OFFLOAD_IP_CKSUM)
230                                 ol_flags |= PKT_TX_IP_CKSUM;
231                         else
232                                 ipv4_hdr->hdr_checksum =
233                                         rte_ipv4_cksum(ipv4_hdr);
234                 }
235         } else if (info->ethertype == _htons(ETHER_TYPE_IPv6))
236                 ol_flags |= PKT_TX_IPV6;
237         else
238                 return 0; /* packet type not supported, nothing to do */
239
240         if (info->l4_proto == IPPROTO_UDP) {
241                 udp_hdr = (struct udp_hdr *)((char *)l3_hdr + info->l3_len);
242                 /* do not recalculate udp cksum if it was 0 */
243                 if (udp_hdr->dgram_cksum != 0) {
244                         udp_hdr->dgram_cksum = 0;
245                         if (testpmd_ol_flags & TESTPMD_TX_OFFLOAD_UDP_CKSUM) {
246                                 ol_flags |= PKT_TX_UDP_CKSUM;
247                                 udp_hdr->dgram_cksum = get_psd_sum(l3_hdr,
248                                         info->ethertype, ol_flags);
249                         } else {
250                                 udp_hdr->dgram_cksum =
251                                         get_udptcp_checksum(l3_hdr, udp_hdr,
252                                                 info->ethertype);
253                         }
254                 }
255         } else if (info->l4_proto == IPPROTO_TCP) {
256                 tcp_hdr = (struct tcp_hdr *)((char *)l3_hdr + info->l3_len);
257                 tcp_hdr->cksum = 0;
258                 if (info->tso_segsz != 0) {
259                         ol_flags |= PKT_TX_TCP_SEG;
260                         tcp_hdr->cksum = get_psd_sum(l3_hdr, info->ethertype,
261                                 ol_flags);
262                 } else if (testpmd_ol_flags & TESTPMD_TX_OFFLOAD_TCP_CKSUM) {
263                         ol_flags |= PKT_TX_TCP_CKSUM;
264                         tcp_hdr->cksum = get_psd_sum(l3_hdr, info->ethertype,
265                                 ol_flags);
266                 } else {
267                         tcp_hdr->cksum =
268                                 get_udptcp_checksum(l3_hdr, tcp_hdr,
269                                         info->ethertype);
270                 }
271         } else if (info->l4_proto == IPPROTO_SCTP) {
272                 sctp_hdr = (struct sctp_hdr *)((char *)l3_hdr + info->l3_len);
273                 sctp_hdr->cksum = 0;
274                 /* sctp payload must be a multiple of 4 to be
275                  * offloaded */
276                 if ((testpmd_ol_flags & TESTPMD_TX_OFFLOAD_SCTP_CKSUM) &&
277                         ((ipv4_hdr->total_length & 0x3) == 0)) {
278                         ol_flags |= PKT_TX_SCTP_CKSUM;
279                 } else {
280                         /* XXX implement CRC32c, example available in
281                          * RFC3309 */
282                 }
283         }
284
285         return ol_flags;
286 }
287
288 /* Calculate the checksum of outer header (only vxlan is supported,
289  * meaning IP + UDP). The caller already checked that it's a vxlan
290  * packet */
291 static uint64_t
292 process_outer_cksums(void *outer_l3_hdr, struct testpmd_offload_info *info,
293 uint16_t testpmd_ol_flags)
294 {
295         struct ipv4_hdr *ipv4_hdr = outer_l3_hdr;
296         struct ipv6_hdr *ipv6_hdr = outer_l3_hdr;
297         struct udp_hdr *udp_hdr;
298         uint64_t ol_flags = 0;
299
300         if (info->outer_ethertype == _htons(ETHER_TYPE_IPv4)) {
301                 ipv4_hdr->hdr_checksum = 0;
302                 ol_flags |= PKT_TX_OUTER_IPV4;
303
304                 if (testpmd_ol_flags & TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM)
305                         ol_flags |= PKT_TX_OUTER_IP_CKSUM;
306                 else
307                         ipv4_hdr->hdr_checksum = rte_ipv4_cksum(ipv4_hdr);
308         } else if (testpmd_ol_flags & TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM)
309                 ol_flags |= PKT_TX_OUTER_IPV6;
310
311         /* outer UDP checksum is always done in software as we have no
312          * hardware supporting it today, and no API for it. */
313
314         udp_hdr = (struct udp_hdr *)((char *)outer_l3_hdr + info->outer_l3_len);
315         /* do not recalculate udp cksum if it was 0 */
316         if (udp_hdr->dgram_cksum != 0) {
317                 udp_hdr->dgram_cksum = 0;
318                 if (info->outer_ethertype == _htons(ETHER_TYPE_IPv4))
319                         udp_hdr->dgram_cksum =
320                                 rte_ipv4_udptcp_cksum(ipv4_hdr, udp_hdr);
321                 else
322                         udp_hdr->dgram_cksum =
323                                 rte_ipv6_udptcp_cksum(ipv6_hdr, udp_hdr);
324         }
325
326         return ol_flags;
327 }
328
329 /*
330  * Receive a burst of packets, and for each packet:
331  *  - parse packet, and try to recognize a supported packet type (1)
332  *  - if it's not a supported packet type, don't touch the packet, else:
333  *  - modify the IPs in inner headers and in outer headers if any
334  *  - reprocess the checksum of all supported layers. This is done in SW
335  *    or HW, depending on testpmd command line configuration
336  *  - if TSO is enabled in testpmd command line, also flag the mbuf for TCP
337  *    segmentation offload (this implies HW TCP checksum)
338  * Then transmit packets on the output port.
339  *
340  * (1) Supported packets are:
341  *   Ether / (vlan) / IP|IP6 / UDP|TCP|SCTP .
342  *   Ether / (vlan) / outer IP|IP6 / outer UDP / VxLAN / Ether / IP|IP6 /
343  *           UDP|TCP|SCTP
344  *
345  * The testpmd command line for this forward engine sets the flags
346  * TESTPMD_TX_OFFLOAD_* in ports[tx_port].tx_ol_flags. They control
347  * wether a checksum must be calculated in software or in hardware. The
348  * IP, UDP, TCP and SCTP flags always concern the inner layer. The
349  * OUTER_IP is only useful for tunnel packets.
350  */
351 static void
352 pkt_burst_checksum_forward(struct fwd_stream *fs)
353 {
354         struct rte_mbuf *pkts_burst[MAX_PKT_BURST];
355         struct rte_port *txp;
356         struct rte_mbuf *m;
357         struct ether_hdr *eth_hdr;
358         void *l3_hdr = NULL, *outer_l3_hdr = NULL; /* can be IPv4 or IPv6 */
359         struct udp_hdr *udp_hdr;
360         uint16_t nb_rx;
361         uint16_t nb_tx;
362         uint16_t i;
363         uint64_t ol_flags;
364         uint16_t testpmd_ol_flags;
365         uint32_t rx_bad_ip_csum;
366         uint32_t rx_bad_l4_csum;
367         struct testpmd_offload_info info;
368
369 #ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
370         uint64_t start_tsc;
371         uint64_t end_tsc;
372         uint64_t core_cycles;
373 #endif
374
375 #ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
376         start_tsc = rte_rdtsc();
377 #endif
378
379         /* receive a burst of packet */
380         nb_rx = rte_eth_rx_burst(fs->rx_port, fs->rx_queue, pkts_burst,
381                                  nb_pkt_per_burst);
382         if (unlikely(nb_rx == 0))
383                 return;
384
385 #ifdef RTE_TEST_PMD_RECORD_BURST_STATS
386         fs->rx_burst_stats.pkt_burst_spread[nb_rx]++;
387 #endif
388         fs->rx_packets += nb_rx;
389         rx_bad_ip_csum = 0;
390         rx_bad_l4_csum = 0;
391
392         txp = &ports[fs->tx_port];
393         testpmd_ol_flags = txp->tx_ol_flags;
394         memset(&info, 0, sizeof(info));
395         info.tso_segsz = txp->tso_segsz;
396
397         for (i = 0; i < nb_rx; i++) {
398
399                 ol_flags = 0;
400                 info.is_tunnel = 0;
401                 m = pkts_burst[i];
402
403                 /* Update the L3/L4 checksum error packet statistics */
404                 rx_bad_ip_csum += ((m->ol_flags & PKT_RX_IP_CKSUM_BAD) != 0);
405                 rx_bad_l4_csum += ((m->ol_flags & PKT_RX_L4_CKSUM_BAD) != 0);
406
407                 /* step 1: dissect packet, parsing optional vlan, ip4/ip6, vxlan
408                  * and inner headers */
409
410                 eth_hdr = rte_pktmbuf_mtod(m, struct ether_hdr *);
411                 parse_ethernet(eth_hdr, &info);
412                 l3_hdr = (char *)eth_hdr + info.l2_len;
413
414                 /* check if it's a supported tunnel (only vxlan for now) */
415                 if ((testpmd_ol_flags & TESTPMD_TX_OFFLOAD_PARSE_TUNNEL) &&
416                         info.l4_proto == IPPROTO_UDP) {
417                         udp_hdr = (struct udp_hdr *)((char *)l3_hdr + info.l3_len);
418
419                         /* check udp destination port, 4789 is the default
420                          * vxlan port (rfc7348) */
421                         if (udp_hdr->dst_port == _htons(4789)) {
422                                 info.l4_tun_len = ETHER_VXLAN_HLEN;
423                                 info.is_tunnel = 1;
424
425                         /* currently, this flag is set by i40e only if the
426                          * packet is vxlan */
427                         } else if (m->ol_flags & (PKT_RX_TUNNEL_IPV4_HDR |
428                                         PKT_RX_TUNNEL_IPV6_HDR))
429                                 info.is_tunnel = 1;
430
431                         if (info.is_tunnel == 1) {
432                                 info.outer_ethertype = info.ethertype;
433                                 info.outer_l2_len = info.l2_len;
434                                 info.outer_l3_len = info.l3_len;
435                                 outer_l3_hdr = l3_hdr;
436
437                                 eth_hdr = (struct ether_hdr *)((char *)udp_hdr +
438                                         sizeof(struct udp_hdr) +
439                                         sizeof(struct vxlan_hdr));
440
441                                 parse_ethernet(eth_hdr, &info);
442                                 l3_hdr = (char *)eth_hdr + info.l2_len;
443                         }
444                 }
445
446                 /* step 2: change all source IPs (v4 or v6) so we need
447                  * to recompute the chksums even if they were correct */
448
449                 change_ip_addresses(l3_hdr, info.ethertype);
450                 if (info.is_tunnel == 1)
451                         change_ip_addresses(outer_l3_hdr, info.outer_ethertype);
452
453                 /* step 3: depending on user command line configuration,
454                  * recompute checksum either in software or flag the
455                  * mbuf to offload the calculation to the NIC. If TSO
456                  * is configured, prepare the mbuf for TCP segmentation. */
457
458                 /* process checksums of inner headers first */
459                 ol_flags |= process_inner_cksums(l3_hdr, &info, testpmd_ol_flags);
460
461                 /* Then process outer headers if any. Note that the software
462                  * checksum will be wrong if one of the inner checksums is
463                  * processed in hardware. */
464                 if (info.is_tunnel == 1) {
465                         ol_flags |= process_outer_cksums(outer_l3_hdr, &info,
466                                 testpmd_ol_flags);
467                 }
468
469                 /* step 4: fill the mbuf meta data (flags and header lengths) */
470
471                 if (info.is_tunnel == 1) {
472                         if (testpmd_ol_flags & TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM) {
473                                 m->outer_l2_len = info.outer_l2_len;
474                                 m->outer_l3_len = info.outer_l3_len;
475                                 m->l2_len = info.l4_tun_len + info.l2_len;
476                                 m->l3_len = info.l3_len;
477                         }
478                         else {
479                                 /* if there is a outer UDP cksum
480                                    processed in sw and the inner in hw,
481                                    the outer checksum will be wrong as
482                                    the payload will be modified by the
483                                    hardware */
484                                 m->l2_len = info.outer_l2_len +
485                                         info.outer_l3_len +
486                                         sizeof(struct udp_hdr) +
487                                         sizeof(struct vxlan_hdr) + info.l2_len;
488                                 m->l3_len = info.l3_len;
489                                 m->l4_len = info.l4_len;
490                         }
491                 } else {
492                         /* this is only useful if an offload flag is
493                          * set, but it does not hurt to fill it in any
494                          * case */
495                         m->l2_len = info.l2_len;
496                         m->l3_len = info.l3_len;
497                         m->l4_len = info.l4_len;
498                 }
499                 m->tso_segsz = info.tso_segsz;
500                 m->ol_flags = ol_flags;
501
502                 /* if verbose mode is enabled, dump debug info */
503                 if (verbose_level > 0) {
504                         struct {
505                                 uint64_t flag;
506                                 uint64_t mask;
507                         } tx_flags[] = {
508                                 { PKT_TX_IP_CKSUM, PKT_TX_IP_CKSUM },
509                                 { PKT_TX_UDP_CKSUM, PKT_TX_L4_MASK },
510                                 { PKT_TX_TCP_CKSUM, PKT_TX_L4_MASK },
511                                 { PKT_TX_SCTP_CKSUM, PKT_TX_L4_MASK },
512                                 { PKT_TX_IPV4, PKT_TX_IPV4 },
513                                 { PKT_TX_IPV6, PKT_TX_IPV6 },
514                                 { PKT_TX_OUTER_IP_CKSUM, PKT_TX_OUTER_IP_CKSUM },
515                                 { PKT_TX_OUTER_IPV4, PKT_TX_OUTER_IPV4 },
516                                 { PKT_TX_OUTER_IPV6, PKT_TX_OUTER_IPV6 },
517                                 { PKT_TX_TCP_SEG, PKT_TX_TCP_SEG },
518                         };
519                         unsigned j;
520                         const char *name;
521
522                         printf("-----------------\n");
523                         /* dump rx parsed packet info */
524                         printf("rx: l2_len=%d ethertype=%x l3_len=%d "
525                                 "l4_proto=%d l4_len=%d\n",
526                                 info.l2_len, rte_be_to_cpu_16(info.ethertype),
527                                 info.l3_len, info.l4_proto, info.l4_len);
528                         if (info.is_tunnel == 1)
529                                 printf("rx: outer_l2_len=%d outer_ethertype=%x "
530                                         "outer_l3_len=%d\n", info.outer_l2_len,
531                                         rte_be_to_cpu_16(info.outer_ethertype),
532                                         info.outer_l3_len);
533                         /* dump tx packet info */
534                         if ((testpmd_ol_flags & (TESTPMD_TX_OFFLOAD_IP_CKSUM |
535                                                 TESTPMD_TX_OFFLOAD_UDP_CKSUM |
536                                                 TESTPMD_TX_OFFLOAD_TCP_CKSUM |
537                                                 TESTPMD_TX_OFFLOAD_SCTP_CKSUM)) ||
538                                 info.tso_segsz != 0)
539                                 printf("tx: m->l2_len=%d m->l3_len=%d "
540                                         "m->l4_len=%d\n",
541                                         m->l2_len, m->l3_len, m->l4_len);
542                         if ((info.is_tunnel == 1) &&
543                                 (testpmd_ol_flags & TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM))
544                                 printf("tx: m->outer_l2_len=%d m->outer_l3_len=%d\n",
545                                         m->outer_l2_len, m->outer_l3_len);
546                         if (info.tso_segsz != 0)
547                                 printf("tx: m->tso_segsz=%d\n", m->tso_segsz);
548                         printf("tx: flags=");
549                         for (j = 0; j < sizeof(tx_flags)/sizeof(*tx_flags); j++) {
550                                 name = rte_get_tx_ol_flag_name(tx_flags[j].flag);
551                                 if ((m->ol_flags & tx_flags[j].mask) ==
552                                         tx_flags[j].flag)
553                                         printf("%s ", name);
554                         }
555                         printf("\n");
556                 }
557         }
558         nb_tx = rte_eth_tx_burst(fs->tx_port, fs->tx_queue, pkts_burst, nb_rx);
559         fs->tx_packets += nb_tx;
560         fs->rx_bad_ip_csum += rx_bad_ip_csum;
561         fs->rx_bad_l4_csum += rx_bad_l4_csum;
562
563 #ifdef RTE_TEST_PMD_RECORD_BURST_STATS
564         fs->tx_burst_stats.pkt_burst_spread[nb_tx]++;
565 #endif
566         if (unlikely(nb_tx < nb_rx)) {
567                 fs->fwd_dropped += (nb_rx - nb_tx);
568                 do {
569                         rte_pktmbuf_free(pkts_burst[nb_tx]);
570                 } while (++nb_tx < nb_rx);
571         }
572 #ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
573         end_tsc = rte_rdtsc();
574         core_cycles = (end_tsc - start_tsc);
575         fs->core_cycles = (uint64_t) (fs->core_cycles + core_cycles);
576 #endif
577 }
578
579 struct fwd_engine csum_fwd_engine = {
580         .fwd_mode_name  = "csum",
581         .port_fwd_begin = NULL,
582         .port_fwd_end   = NULL,
583         .packet_fwd     = pkt_burst_checksum_forward,
584 };
585