4 * Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
5 * Copyright 2014 6WIND S.A.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
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
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.
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.
42 #include <sys/queue.h>
45 #include <rte_common.h>
46 #include <rte_byteorder.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>
55 #include <rte_per_lcore.h>
56 #include <rte_lcore.h>
57 #include <rte_atomic.h>
58 #include <rte_branch_prediction.h>
59 #include <rte_memory.h>
60 #include <rte_mempool.h>
62 #include <rte_memcpy.h>
63 #include <rte_interrupts.h>
65 #include <rte_ether.h>
66 #include <rte_ethdev.h>
71 #include <rte_prefetch.h>
72 #include <rte_string_fns.h>
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)
82 #define GRE_KEY_PRESENT 0x2000
84 #define GRE_SUPPORTED_FIELDS GRE_KEY_PRESENT
86 /* We cannot use rte_cpu_to_be_16() on a constant in a switch/case */
87 #if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
88 #define _htons(x) ((uint16_t)((((x) & 0x00ffU) << 8) | (((x) & 0xff00U) >> 8)))
93 /* structure that caches offload info for the current packet */
94 struct testpmd_offload_info {
101 uint16_t outer_ethertype;
102 uint16_t outer_l2_len;
103 uint16_t outer_l3_len;
104 uint8_t outer_l4_proto;
106 uint16_t tunnel_tso_segsz;
110 /* simplified GRE header */
111 struct simple_gre_hdr {
114 } __attribute__((__packed__));
117 get_udptcp_checksum(void *l3_hdr, void *l4_hdr, uint16_t ethertype)
119 if (ethertype == _htons(ETHER_TYPE_IPv4))
120 return rte_ipv4_udptcp_cksum(l3_hdr, l4_hdr);
121 else /* assume ethertype == ETHER_TYPE_IPv6 */
122 return rte_ipv6_udptcp_cksum(l3_hdr, l4_hdr);
125 /* Parse an IPv4 header to fill l3_len, l4_len, and l4_proto */
127 parse_ipv4(struct ipv4_hdr *ipv4_hdr, struct testpmd_offload_info *info)
129 struct tcp_hdr *tcp_hdr;
131 info->l3_len = (ipv4_hdr->version_ihl & 0x0f) * 4;
132 info->l4_proto = ipv4_hdr->next_proto_id;
134 /* only fill l4_len for TCP, it's useful for TSO */
135 if (info->l4_proto == IPPROTO_TCP) {
136 tcp_hdr = (struct tcp_hdr *)((char *)ipv4_hdr + info->l3_len);
137 info->l4_len = (tcp_hdr->data_off & 0xf0) >> 2;
142 /* Parse an IPv6 header to fill l3_len, l4_len, and l4_proto */
144 parse_ipv6(struct ipv6_hdr *ipv6_hdr, struct testpmd_offload_info *info)
146 struct tcp_hdr *tcp_hdr;
148 info->l3_len = sizeof(struct ipv6_hdr);
149 info->l4_proto = ipv6_hdr->proto;
151 /* only fill l4_len for TCP, it's useful for TSO */
152 if (info->l4_proto == IPPROTO_TCP) {
153 tcp_hdr = (struct tcp_hdr *)((char *)ipv6_hdr + info->l3_len);
154 info->l4_len = (tcp_hdr->data_off & 0xf0) >> 2;
160 * Parse an ethernet header to fill the ethertype, l2_len, l3_len and
161 * ipproto. This function is able to recognize IPv4/IPv6 with one optional vlan
162 * header. The l4_len argument is only set in case of TCP (useful for TSO).
165 parse_ethernet(struct ether_hdr *eth_hdr, struct testpmd_offload_info *info)
167 struct ipv4_hdr *ipv4_hdr;
168 struct ipv6_hdr *ipv6_hdr;
170 info->l2_len = sizeof(struct ether_hdr);
171 info->ethertype = eth_hdr->ether_type;
173 if (info->ethertype == _htons(ETHER_TYPE_VLAN)) {
174 struct vlan_hdr *vlan_hdr = (struct vlan_hdr *)(eth_hdr + 1);
176 info->l2_len += sizeof(struct vlan_hdr);
177 info->ethertype = vlan_hdr->eth_proto;
180 switch (info->ethertype) {
181 case _htons(ETHER_TYPE_IPv4):
182 ipv4_hdr = (struct ipv4_hdr *) ((char *)eth_hdr + info->l2_len);
183 parse_ipv4(ipv4_hdr, info);
185 case _htons(ETHER_TYPE_IPv6):
186 ipv6_hdr = (struct ipv6_hdr *) ((char *)eth_hdr + info->l2_len);
187 parse_ipv6(ipv6_hdr, info);
197 /* Parse a vxlan header */
199 parse_vxlan(struct udp_hdr *udp_hdr,
200 struct testpmd_offload_info *info,
203 struct ether_hdr *eth_hdr;
205 /* check udp destination port, 4789 is the default vxlan port
206 * (rfc7348) or that the rx offload flag is set (i40e only
208 if (udp_hdr->dst_port != _htons(4789) &&
209 RTE_ETH_IS_TUNNEL_PKT(pkt_type) == 0)
213 info->outer_ethertype = info->ethertype;
214 info->outer_l2_len = info->l2_len;
215 info->outer_l3_len = info->l3_len;
216 info->outer_l4_proto = info->l4_proto;
218 eth_hdr = (struct ether_hdr *)((char *)udp_hdr +
219 sizeof(struct udp_hdr) +
220 sizeof(struct vxlan_hdr));
222 parse_ethernet(eth_hdr, info);
223 info->l2_len += ETHER_VXLAN_HLEN; /* add udp + vxlan */
226 /* Parse a gre header */
228 parse_gre(struct simple_gre_hdr *gre_hdr, struct testpmd_offload_info *info)
230 struct ether_hdr *eth_hdr;
231 struct ipv4_hdr *ipv4_hdr;
232 struct ipv6_hdr *ipv6_hdr;
235 /* check which fields are supported */
236 if ((gre_hdr->flags & _htons(~GRE_SUPPORTED_FIELDS)) != 0)
239 gre_len += sizeof(struct simple_gre_hdr);
241 if (gre_hdr->flags & _htons(GRE_KEY_PRESENT))
242 gre_len += GRE_KEY_LEN;
244 if (gre_hdr->proto == _htons(ETHER_TYPE_IPv4)) {
246 info->outer_ethertype = info->ethertype;
247 info->outer_l2_len = info->l2_len;
248 info->outer_l3_len = info->l3_len;
249 info->outer_l4_proto = info->l4_proto;
251 ipv4_hdr = (struct ipv4_hdr *)((char *)gre_hdr + gre_len);
253 parse_ipv4(ipv4_hdr, info);
254 info->ethertype = _htons(ETHER_TYPE_IPv4);
257 } else if (gre_hdr->proto == _htons(ETHER_TYPE_IPv6)) {
259 info->outer_ethertype = info->ethertype;
260 info->outer_l2_len = info->l2_len;
261 info->outer_l3_len = info->l3_len;
262 info->outer_l4_proto = info->l4_proto;
264 ipv6_hdr = (struct ipv6_hdr *)((char *)gre_hdr + gre_len);
266 info->ethertype = _htons(ETHER_TYPE_IPv6);
267 parse_ipv6(ipv6_hdr, info);
270 } else if (gre_hdr->proto == _htons(ETHER_TYPE_TEB)) {
272 info->outer_ethertype = info->ethertype;
273 info->outer_l2_len = info->l2_len;
274 info->outer_l3_len = info->l3_len;
275 info->outer_l4_proto = info->l4_proto;
277 eth_hdr = (struct ether_hdr *)((char *)gre_hdr + gre_len);
279 parse_ethernet(eth_hdr, info);
283 info->l2_len += gre_len;
287 /* Parse an encapsulated ip or ipv6 header */
289 parse_encap_ip(void *encap_ip, struct testpmd_offload_info *info)
291 struct ipv4_hdr *ipv4_hdr = encap_ip;
292 struct ipv6_hdr *ipv6_hdr = encap_ip;
295 ip_version = (ipv4_hdr->version_ihl & 0xf0) >> 4;
297 if (ip_version != 4 && ip_version != 6)
301 info->outer_ethertype = info->ethertype;
302 info->outer_l2_len = info->l2_len;
303 info->outer_l3_len = info->l3_len;
305 if (ip_version == 4) {
306 parse_ipv4(ipv4_hdr, info);
307 info->ethertype = _htons(ETHER_TYPE_IPv4);
309 parse_ipv6(ipv6_hdr, info);
310 info->ethertype = _htons(ETHER_TYPE_IPv6);
315 /* if possible, calculate the checksum of a packet in hw or sw,
316 * depending on the testpmd command line configuration */
318 process_inner_cksums(void *l3_hdr, const struct testpmd_offload_info *info,
319 uint16_t testpmd_ol_flags)
321 struct ipv4_hdr *ipv4_hdr = l3_hdr;
322 struct udp_hdr *udp_hdr;
323 struct tcp_hdr *tcp_hdr;
324 struct sctp_hdr *sctp_hdr;
325 uint64_t ol_flags = 0;
326 uint32_t max_pkt_len, tso_segsz = 0;
328 /* ensure packet is large enough to require tso */
329 if (!info->is_tunnel) {
330 max_pkt_len = info->l2_len + info->l3_len + info->l4_len +
332 if (info->tso_segsz != 0 && info->pkt_len > max_pkt_len)
333 tso_segsz = info->tso_segsz;
335 max_pkt_len = info->outer_l2_len + info->outer_l3_len +
336 info->l2_len + info->l3_len + info->l4_len +
337 info->tunnel_tso_segsz;
338 if (info->tunnel_tso_segsz != 0 && info->pkt_len > max_pkt_len)
339 tso_segsz = info->tunnel_tso_segsz;
342 if (info->ethertype == _htons(ETHER_TYPE_IPv4)) {
344 ipv4_hdr->hdr_checksum = 0;
346 ol_flags |= PKT_TX_IPV4;
347 if (info->l4_proto == IPPROTO_TCP && tso_segsz) {
348 ol_flags |= PKT_TX_IP_CKSUM;
350 if (testpmd_ol_flags & TESTPMD_TX_OFFLOAD_IP_CKSUM)
351 ol_flags |= PKT_TX_IP_CKSUM;
353 ipv4_hdr->hdr_checksum =
354 rte_ipv4_cksum(ipv4_hdr);
356 } else if (info->ethertype == _htons(ETHER_TYPE_IPv6))
357 ol_flags |= PKT_TX_IPV6;
359 return 0; /* packet type not supported, nothing to do */
361 if (info->l4_proto == IPPROTO_UDP) {
362 udp_hdr = (struct udp_hdr *)((char *)l3_hdr + info->l3_len);
363 /* do not recalculate udp cksum if it was 0 */
364 if (udp_hdr->dgram_cksum != 0) {
365 udp_hdr->dgram_cksum = 0;
366 if (testpmd_ol_flags & TESTPMD_TX_OFFLOAD_UDP_CKSUM)
367 ol_flags |= PKT_TX_UDP_CKSUM;
369 udp_hdr->dgram_cksum =
370 get_udptcp_checksum(l3_hdr, udp_hdr,
374 } else if (info->l4_proto == IPPROTO_TCP) {
375 tcp_hdr = (struct tcp_hdr *)((char *)l3_hdr + info->l3_len);
378 ol_flags |= PKT_TX_TCP_SEG;
379 else if (testpmd_ol_flags & TESTPMD_TX_OFFLOAD_TCP_CKSUM)
380 ol_flags |= PKT_TX_TCP_CKSUM;
383 get_udptcp_checksum(l3_hdr, tcp_hdr,
386 } else if (info->l4_proto == IPPROTO_SCTP) {
387 sctp_hdr = (struct sctp_hdr *)((char *)l3_hdr + info->l3_len);
389 /* sctp payload must be a multiple of 4 to be
391 if ((testpmd_ol_flags & TESTPMD_TX_OFFLOAD_SCTP_CKSUM) &&
392 ((ipv4_hdr->total_length & 0x3) == 0)) {
393 ol_flags |= PKT_TX_SCTP_CKSUM;
395 /* XXX implement CRC32c, example available in
403 /* Calculate the checksum of outer header */
405 process_outer_cksums(void *outer_l3_hdr, struct testpmd_offload_info *info,
406 uint16_t testpmd_ol_flags, int tso_enabled)
408 struct ipv4_hdr *ipv4_hdr = outer_l3_hdr;
409 struct ipv6_hdr *ipv6_hdr = outer_l3_hdr;
410 struct udp_hdr *udp_hdr;
411 uint64_t ol_flags = 0;
413 if (info->outer_ethertype == _htons(ETHER_TYPE_IPv4)) {
414 ipv4_hdr->hdr_checksum = 0;
415 ol_flags |= PKT_TX_OUTER_IPV4;
417 if (testpmd_ol_flags & TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM)
418 ol_flags |= PKT_TX_OUTER_IP_CKSUM;
420 ipv4_hdr->hdr_checksum = rte_ipv4_cksum(ipv4_hdr);
422 ol_flags |= PKT_TX_OUTER_IPV6;
424 if (info->outer_l4_proto != IPPROTO_UDP)
427 udp_hdr = (struct udp_hdr *)((char *)outer_l3_hdr + info->outer_l3_len);
429 /* outer UDP checksum is done in software as we have no hardware
430 * supporting it today, and no API for it. In the other side, for
431 * UDP tunneling, like VXLAN or Geneve, outer UDP checksum can be
434 * If a packet will be TSOed into small packets by NIC, we cannot
435 * set/calculate a non-zero checksum, because it will be a wrong
436 * value after the packet be split into several small packets.
439 udp_hdr->dgram_cksum = 0;
441 /* do not recalculate udp cksum if it was 0 */
442 if (udp_hdr->dgram_cksum != 0) {
443 udp_hdr->dgram_cksum = 0;
444 if (info->outer_ethertype == _htons(ETHER_TYPE_IPv4))
445 udp_hdr->dgram_cksum =
446 rte_ipv4_udptcp_cksum(ipv4_hdr, udp_hdr);
448 udp_hdr->dgram_cksum =
449 rte_ipv6_udptcp_cksum(ipv6_hdr, udp_hdr);
457 * Performs actual copying.
458 * Returns number of segments in the destination mbuf on success,
459 * or negative error code on failure.
462 mbuf_copy_split(const struct rte_mbuf *ms, struct rte_mbuf *md[],
463 uint16_t seglen[], uint8_t nb_seg)
465 uint32_t dlen, slen, tlen;
467 const struct rte_mbuf *m;
480 while (ms != NULL && i != nb_seg) {
483 slen = rte_pktmbuf_data_len(ms);
484 src = rte_pktmbuf_mtod(ms, const uint8_t *);
488 dlen = RTE_MIN(seglen[i], slen);
489 md[i]->data_len = dlen;
490 md[i]->next = (i + 1 == nb_seg) ? NULL : md[i + 1];
491 dst = rte_pktmbuf_mtod(md[i], uint8_t *);
494 len = RTE_MIN(slen, dlen);
495 memcpy(dst, src, len);
510 else if (tlen != m->pkt_len)
513 md[0]->nb_segs = nb_seg;
514 md[0]->pkt_len = tlen;
515 md[0]->vlan_tci = m->vlan_tci;
516 md[0]->vlan_tci_outer = m->vlan_tci_outer;
517 md[0]->ol_flags = m->ol_flags;
518 md[0]->tx_offload = m->tx_offload;
524 * Allocate a new mbuf with up to tx_pkt_nb_segs segments.
525 * Copy packet contents and offload information into then new segmented mbuf.
527 static struct rte_mbuf *
528 pkt_copy_split(const struct rte_mbuf *pkt)
531 uint32_t i, len, nb_seg;
532 struct rte_mempool *mp;
533 uint16_t seglen[RTE_MAX_SEGS_PER_PKT];
534 struct rte_mbuf *p, *md[RTE_MAX_SEGS_PER_PKT];
536 mp = current_fwd_lcore()->mbp;
538 if (tx_pkt_split == TX_PKT_SPLIT_RND)
539 nb_seg = random() % tx_pkt_nb_segs + 1;
541 nb_seg = tx_pkt_nb_segs;
543 memcpy(seglen, tx_pkt_seg_lengths, nb_seg * sizeof(seglen[0]));
545 /* calculate number of segments to use and their length. */
547 for (i = 0; i != nb_seg && len < pkt->pkt_len; i++) {
552 n = pkt->pkt_len - len;
554 /* update size of the last segment to fit rest of the packet */
562 p = rte_pktmbuf_alloc(mp);
565 "failed to allocate %u-th of %u mbuf "
566 "from mempool: %s\n",
567 nb_seg - i, nb_seg, mp->name);
572 if (rte_pktmbuf_tailroom(md[i]) < seglen[i]) {
573 RTE_LOG(ERR, USER1, "mempool %s, %u-th segment: "
574 "expected seglen: %u, "
575 "actual mbuf tailroom: %u\n",
576 mp->name, i, seglen[i],
577 rte_pktmbuf_tailroom(md[i]));
582 /* all mbufs successfully allocated, do copy */
584 rc = mbuf_copy_split(pkt, md, seglen, nb_seg);
587 "mbuf_copy_split for %p(len=%u, nb_seg=%u) "
588 "into %u segments failed with error code: %d\n",
589 pkt, pkt->pkt_len, pkt->nb_segs, nb_seg, rc);
591 /* figure out how many mbufs to free. */
595 /* free unused mbufs */
596 for (; i != nb_seg; i++) {
597 rte_pktmbuf_free_seg(md[i]);
605 * Receive a burst of packets, and for each packet:
606 * - parse packet, and try to recognize a supported packet type (1)
607 * - if it's not a supported packet type, don't touch the packet, else:
608 * - reprocess the checksum of all supported layers. This is done in SW
609 * or HW, depending on testpmd command line configuration
610 * - if TSO is enabled in testpmd command line, also flag the mbuf for TCP
611 * segmentation offload (this implies HW TCP checksum)
612 * Then transmit packets on the output port.
614 * (1) Supported packets are:
615 * Ether / (vlan) / IP|IP6 / UDP|TCP|SCTP .
616 * Ether / (vlan) / outer IP|IP6 / outer UDP / VxLAN / Ether / IP|IP6 /
618 * Ether / (vlan) / outer IP|IP6 / GRE / Ether / IP|IP6 / UDP|TCP|SCTP
619 * Ether / (vlan) / outer IP|IP6 / GRE / IP|IP6 / UDP|TCP|SCTP
620 * Ether / (vlan) / outer IP|IP6 / IP|IP6 / UDP|TCP|SCTP
622 * The testpmd command line for this forward engine sets the flags
623 * TESTPMD_TX_OFFLOAD_* in ports[tx_port].tx_ol_flags. They control
624 * wether a checksum must be calculated in software or in hardware. The
625 * IP, UDP, TCP and SCTP flags always concern the inner layer. The
626 * OUTER_IP is only useful for tunnel packets.
629 pkt_burst_checksum_forward(struct fwd_stream *fs)
631 struct rte_mbuf *pkts_burst[MAX_PKT_BURST];
632 struct rte_port *txp;
633 struct rte_mbuf *m, *p;
634 struct ether_hdr *eth_hdr;
635 void *l3_hdr = NULL, *outer_l3_hdr = NULL; /* can be IPv4 or IPv6 */
640 uint64_t rx_ol_flags, tx_ol_flags;
641 uint16_t testpmd_ol_flags;
643 uint32_t rx_bad_ip_csum;
644 uint32_t rx_bad_l4_csum;
645 struct testpmd_offload_info info;
647 #ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
650 uint64_t core_cycles;
653 #ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
654 start_tsc = rte_rdtsc();
657 /* receive a burst of packet */
658 nb_rx = rte_eth_rx_burst(fs->rx_port, fs->rx_queue, pkts_burst,
660 if (unlikely(nb_rx == 0))
662 if (unlikely(gro_ports[fs->rx_port].enable))
663 nb_rx = rte_gro_reassemble_burst(pkts_burst,
665 &(gro_ports[fs->rx_port].param));
667 #ifdef RTE_TEST_PMD_RECORD_BURST_STATS
668 fs->rx_burst_stats.pkt_burst_spread[nb_rx]++;
670 fs->rx_packets += nb_rx;
674 txp = &ports[fs->tx_port];
675 testpmd_ol_flags = txp->tx_ol_flags;
676 memset(&info, 0, sizeof(info));
677 info.tso_segsz = txp->tso_segsz;
678 info.tunnel_tso_segsz = txp->tunnel_tso_segsz;
680 for (i = 0; i < nb_rx; i++) {
681 if (likely(i < nb_rx - 1))
682 rte_prefetch0(rte_pktmbuf_mtod(pkts_burst[i + 1],
687 info.pkt_len = rte_pktmbuf_pkt_len(m);
689 rx_ol_flags = m->ol_flags;
691 /* Update the L3/L4 checksum error packet statistics */
692 if ((rx_ol_flags & PKT_RX_IP_CKSUM_MASK) == PKT_RX_IP_CKSUM_BAD)
694 if ((rx_ol_flags & PKT_RX_L4_CKSUM_MASK) == PKT_RX_L4_CKSUM_BAD)
697 /* step 1: dissect packet, parsing optional vlan, ip4/ip6, vxlan
698 * and inner headers */
700 eth_hdr = rte_pktmbuf_mtod(m, struct ether_hdr *);
701 ether_addr_copy(&peer_eth_addrs[fs->peer_addr],
703 ether_addr_copy(&ports[fs->tx_port].eth_addr,
705 parse_ethernet(eth_hdr, &info);
706 l3_hdr = (char *)eth_hdr + info.l2_len;
708 /* check if it's a supported tunnel */
709 if (testpmd_ol_flags & TESTPMD_TX_OFFLOAD_PARSE_TUNNEL) {
710 if (info.l4_proto == IPPROTO_UDP) {
711 struct udp_hdr *udp_hdr;
713 udp_hdr = (struct udp_hdr *)((char *)l3_hdr +
715 parse_vxlan(udp_hdr, &info, m->packet_type);
717 tx_ol_flags |= PKT_TX_TUNNEL_VXLAN;
718 } else if (info.l4_proto == IPPROTO_GRE) {
719 struct simple_gre_hdr *gre_hdr;
721 gre_hdr = (struct simple_gre_hdr *)
722 ((char *)l3_hdr + info.l3_len);
723 parse_gre(gre_hdr, &info);
725 tx_ol_flags |= PKT_TX_TUNNEL_GRE;
726 } else if (info.l4_proto == IPPROTO_IPIP) {
729 encap_ip_hdr = (char *)l3_hdr + info.l3_len;
730 parse_encap_ip(encap_ip_hdr, &info);
732 tx_ol_flags |= PKT_TX_TUNNEL_IPIP;
736 /* update l3_hdr and outer_l3_hdr if a tunnel was parsed */
737 if (info.is_tunnel) {
738 outer_l3_hdr = l3_hdr;
739 l3_hdr = (char *)l3_hdr + info.outer_l3_len + info.l2_len;
742 /* step 2: depending on user command line configuration,
743 * recompute checksum either in software or flag the
744 * mbuf to offload the calculation to the NIC. If TSO
745 * is configured, prepare the mbuf for TCP segmentation. */
747 /* process checksums of inner headers first */
748 tx_ol_flags |= process_inner_cksums(l3_hdr, &info,
751 /* Then process outer headers if any. Note that the software
752 * checksum will be wrong if one of the inner checksums is
753 * processed in hardware. */
754 if (info.is_tunnel == 1) {
755 tx_ol_flags |= process_outer_cksums(outer_l3_hdr, &info,
757 !!(tx_ol_flags & PKT_TX_TCP_SEG));
760 /* step 3: fill the mbuf meta data (flags and header lengths) */
762 if (info.is_tunnel == 1) {
763 if (info.tunnel_tso_segsz ||
765 TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM) ||
766 (tx_ol_flags & PKT_TX_OUTER_IPV6)) {
767 m->outer_l2_len = info.outer_l2_len;
768 m->outer_l3_len = info.outer_l3_len;
769 m->l2_len = info.l2_len;
770 m->l3_len = info.l3_len;
771 m->l4_len = info.l4_len;
772 m->tso_segsz = info.tunnel_tso_segsz;
775 /* if there is a outer UDP cksum
776 processed in sw and the inner in hw,
777 the outer checksum will be wrong as
778 the payload will be modified by the
780 m->l2_len = info.outer_l2_len +
781 info.outer_l3_len + info.l2_len;
782 m->l3_len = info.l3_len;
783 m->l4_len = info.l4_len;
786 /* this is only useful if an offload flag is
787 * set, but it does not hurt to fill it in any
789 m->l2_len = info.l2_len;
790 m->l3_len = info.l3_len;
791 m->l4_len = info.l4_len;
792 m->tso_segsz = info.tso_segsz;
794 m->ol_flags = tx_ol_flags;
796 /* Do split & copy for the packet. */
797 if (tx_pkt_split != TX_PKT_SPLIT_OFF) {
798 p = pkt_copy_split(m);
806 /* if verbose mode is enabled, dump debug info */
807 if (verbose_level > 0) {
810 printf("-----------------\n");
811 printf("port=%u, mbuf=%p, pkt_len=%u, nb_segs=%u:\n",
812 fs->rx_port, m, m->pkt_len, m->nb_segs);
813 /* dump rx parsed packet info */
814 rte_get_rx_ol_flag_list(rx_ol_flags, buf, sizeof(buf));
815 printf("rx: l2_len=%d ethertype=%x l3_len=%d "
816 "l4_proto=%d l4_len=%d flags=%s\n",
817 info.l2_len, rte_be_to_cpu_16(info.ethertype),
818 info.l3_len, info.l4_proto, info.l4_len, buf);
819 if (rx_ol_flags & PKT_RX_LRO)
820 printf("rx: m->lro_segsz=%u\n", m->tso_segsz);
821 if (info.is_tunnel == 1)
822 printf("rx: outer_l2_len=%d outer_ethertype=%x "
823 "outer_l3_len=%d\n", info.outer_l2_len,
824 rte_be_to_cpu_16(info.outer_ethertype),
826 /* dump tx packet info */
827 if ((testpmd_ol_flags & (TESTPMD_TX_OFFLOAD_IP_CKSUM |
828 TESTPMD_TX_OFFLOAD_UDP_CKSUM |
829 TESTPMD_TX_OFFLOAD_TCP_CKSUM |
830 TESTPMD_TX_OFFLOAD_SCTP_CKSUM)) ||
832 printf("tx: m->l2_len=%d m->l3_len=%d "
834 m->l2_len, m->l3_len, m->l4_len);
835 if (info.is_tunnel == 1) {
836 if ((testpmd_ol_flags &
837 TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM) ||
838 (tx_ol_flags & PKT_TX_OUTER_IPV6))
839 printf("tx: m->outer_l2_len=%d "
840 "m->outer_l3_len=%d\n",
843 if (info.tunnel_tso_segsz != 0 &&
844 (m->ol_flags & PKT_TX_TCP_SEG))
845 printf("tx: m->tso_segsz=%d\n",
847 } else if (info.tso_segsz != 0 &&
848 (m->ol_flags & PKT_TX_TCP_SEG))
849 printf("tx: m->tso_segsz=%d\n", m->tso_segsz);
850 rte_get_tx_ol_flag_list(m->ol_flags, buf, sizeof(buf));
851 printf("tx: flags=%s", buf);
856 nb_prep = rte_eth_tx_prepare(fs->tx_port, fs->tx_queue,
858 if (nb_prep != nb_rx)
859 printf("Preparing packet burst to transmit failed: %s\n",
860 rte_strerror(rte_errno));
862 nb_tx = rte_eth_tx_burst(fs->tx_port, fs->tx_queue, pkts_burst,
868 if (unlikely(nb_tx < nb_rx) && fs->retry_enabled) {
870 while (nb_tx < nb_rx && retry++ < burst_tx_retry_num) {
871 rte_delay_us(burst_tx_delay_time);
872 nb_tx += rte_eth_tx_burst(fs->tx_port, fs->tx_queue,
873 &pkts_burst[nb_tx], nb_rx - nb_tx);
876 fs->tx_packets += nb_tx;
877 fs->rx_bad_ip_csum += rx_bad_ip_csum;
878 fs->rx_bad_l4_csum += rx_bad_l4_csum;
880 #ifdef RTE_TEST_PMD_RECORD_BURST_STATS
881 fs->tx_burst_stats.pkt_burst_spread[nb_tx]++;
883 if (unlikely(nb_tx < nb_rx)) {
884 fs->fwd_dropped += (nb_rx - nb_tx);
886 rte_pktmbuf_free(pkts_burst[nb_tx]);
887 } while (++nb_tx < nb_rx);
889 #ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
890 end_tsc = rte_rdtsc();
891 core_cycles = (end_tsc - start_tsc);
892 fs->core_cycles = (uint64_t) (fs->core_cycles + core_cycles);
896 struct fwd_engine csum_fwd_engine = {
897 .fwd_mode_name = "csum",
898 .port_fwd_begin = NULL,
899 .port_fwd_end = NULL,
900 .packet_fwd = pkt_burst_checksum_forward,