app/testpmd: do not use TSO for small packets
[dpdk.git] / app / test-pmd / csumonly.c
index 42974d5..d51d85a 100644 (file)
@@ -102,6 +102,7 @@ struct testpmd_offload_info {
        uint8_t outer_l4_proto;
        uint16_t tso_segsz;
        uint16_t tunnel_tso_segsz;
+       uint32_t pkt_len;
 };
 
 /* simplified GRE header */
@@ -318,21 +319,6 @@ parse_encap_ip(void *encap_ip, struct testpmd_offload_info *info)
        info->l2_len = 0;
 }
 
-/* modify the IPv4 or IPv4 source address of a packet */
-static void
-change_ip_addresses(void *l3_hdr, uint16_t ethertype)
-{
-       struct ipv4_hdr *ipv4_hdr = l3_hdr;
-       struct ipv6_hdr *ipv6_hdr = l3_hdr;
-
-       if (ethertype == _htons(ETHER_TYPE_IPv4)) {
-               ipv4_hdr->src_addr =
-                       rte_cpu_to_be_32(rte_be_to_cpu_32(ipv4_hdr->src_addr) + 1);
-       } else if (ethertype == _htons(ETHER_TYPE_IPv6)) {
-               ipv6_hdr->src_addr[15] = ipv6_hdr->src_addr[15] + 1;
-       }
-}
-
 /* if possible, calculate the checksum of a packet in hw or sw,
  * depending on the testpmd command line configuration */
 static uint64_t
@@ -344,6 +330,21 @@ process_inner_cksums(void *l3_hdr, const struct testpmd_offload_info *info,
        struct tcp_hdr *tcp_hdr;
        struct sctp_hdr *sctp_hdr;
        uint64_t ol_flags = 0;
+       uint32_t max_pkt_len, tso_segsz = 0;
+
+       /* ensure packet is large enough to require tso */
+       if (!info->is_tunnel) {
+               max_pkt_len = info->l2_len + info->l3_len + info->l4_len +
+                       info->tso_segsz;
+               if (info->tunnel_tso_segsz != 0 && info->pkt_len > max_pkt_len)
+                       tso_segsz = info->tso_segsz;
+       } else {
+               max_pkt_len = info->outer_l2_len + info->outer_l3_len +
+                       info->l2_len + info->l3_len + info->l4_len +
+                       info->tunnel_tso_segsz;
+               if (info->tunnel_tso_segsz != 0 && info->pkt_len > max_pkt_len)
+                       tso_segsz = info->tunnel_tso_segsz;
+       }
 
        if (info->ethertype == _htons(ETHER_TYPE_IPv4)) {
                ipv4_hdr = l3_hdr;
@@ -384,8 +385,7 @@ process_inner_cksums(void *l3_hdr, const struct testpmd_offload_info *info,
        } else if (info->l4_proto == IPPROTO_TCP) {
                tcp_hdr = (struct tcp_hdr *)((char *)l3_hdr + info->l3_len);
                tcp_hdr->cksum = 0;
-               if ((info->is_tunnel && info->tunnel_tso_segsz != 0) ||
-                   (!info->is_tunnel && info->tso_segsz != 0)) {
+               if (tso_segsz) {
                        ol_flags |= PKT_TX_TCP_SEG;
                        tcp_hdr->cksum = get_psd_sum(l3_hdr, info->ethertype,
                                ol_flags);
@@ -620,7 +620,6 @@ pkt_copy_split(const struct rte_mbuf *pkt)
  * Receive a burst of packets, and for each packet:
  *  - parse packet, and try to recognize a supported packet type (1)
  *  - if it's not a supported packet type, don't touch the packet, else:
- *  - modify the IPs in inner headers and in outer headers if any
  *  - reprocess the checksum of all supported layers. This is done in SW
  *    or HW, depending on testpmd command line configuration
  *  - if TSO is enabled in testpmd command line, also flag the mbuf for TCP
@@ -695,6 +694,7 @@ pkt_burst_checksum_forward(struct fwd_stream *fs)
 
                m = pkts_burst[i];
                info.is_tunnel = 0;
+               info.pkt_len = rte_pktmbuf_pkt_len(m);
                tx_ol_flags = 0;
                rx_ol_flags = m->ol_flags;
 
@@ -747,14 +747,7 @@ pkt_burst_checksum_forward(struct fwd_stream *fs)
                        l3_hdr = (char *)l3_hdr + info.outer_l3_len + info.l2_len;
                }
 
-               /* step 2: change all source IPs (v4 or v6) so we need
-                * to recompute the chksums even if they were correct */
-
-               change_ip_addresses(l3_hdr, info.ethertype);
-               if (info.is_tunnel == 1)
-                       change_ip_addresses(outer_l3_hdr, info.outer_ethertype);
-
-               /* step 3: depending on user command line configuration,
+               /* step 2: depending on user command line configuration,
                 * recompute checksum either in software or flag the
                 * mbuf to offload the calculation to the NIC. If TSO
                 * is configured, prepare the mbuf for TCP segmentation. */
@@ -772,7 +765,7 @@ pkt_burst_checksum_forward(struct fwd_stream *fs)
                                        !!(tx_ol_flags & PKT_TX_TCP_SEG));
                }
 
-               /* step 4: fill the mbuf meta data (flags and header lengths) */
+               /* step 3: fill the mbuf meta data (flags and header lengths) */
 
                if (info.is_tunnel == 1) {
                        if (info.tunnel_tso_segsz ||
@@ -821,8 +814,8 @@ pkt_burst_checksum_forward(struct fwd_stream *fs)
                        char buf[256];
 
                        printf("-----------------\n");
-                       printf("mbuf=%p, pkt_len=%u, nb_segs=%hhu:\n",
-                               m, m->pkt_len, m->nb_segs);
+                       printf("port=%u, mbuf=%p, pkt_len=%u, nb_segs=%hhu:\n",
+                               fs->rx_port, m, m->pkt_len, m->nb_segs);
                        /* dump rx parsed packet info */
                        rte_get_rx_ol_flag_list(rx_ol_flags, buf, sizeof(buf));
                        printf("rx: l2_len=%d ethertype=%x l3_len=%d "