mbuf: add namespace to offload flags
[dpdk.git] / app / test-pmd / csumonly.c
index 8f2f840..8526d91 100644 (file)
@@ -105,7 +105,7 @@ parse_ipv4(struct rte_ipv4_hdr *ipv4_hdr, struct testpmd_offload_info *info)
 {
        struct rte_tcp_hdr *tcp_hdr;
 
-       info->l3_len = (ipv4_hdr->version_ihl & 0x0f) * 4;
+       info->l3_len = rte_ipv4_hdr_len(ipv4_hdr);
        info->l4_proto = ipv4_hdr->next_proto_id;
 
        /* only fill l4_len for TCP, it's useful for TSO */
@@ -480,20 +480,21 @@ process_inner_cksums(void *l3_hdr, const struct testpmd_offload_info *info,
 
        if (info->ethertype == _htons(RTE_ETHER_TYPE_IPV4)) {
                ipv4_hdr = l3_hdr;
-               ipv4_hdr->hdr_checksum = 0;
 
-               ol_flags |= PKT_TX_IPV4;
+               ol_flags |= RTE_MBUF_F_TX_IPV4;
                if (info->l4_proto == IPPROTO_TCP && tso_segsz) {
-                       ol_flags |= PKT_TX_IP_CKSUM;
+                       ol_flags |= RTE_MBUF_F_TX_IP_CKSUM;
                } else {
-                       if (tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM)
-                               ol_flags |= PKT_TX_IP_CKSUM;
-                       else
+                       if (tx_offloads & RTE_ETH_TX_OFFLOAD_IPV4_CKSUM) {
+                               ol_flags |= RTE_MBUF_F_TX_IP_CKSUM;
+                       } else {
+                               ipv4_hdr->hdr_checksum = 0;
                                ipv4_hdr->hdr_checksum =
                                        rte_ipv4_cksum(ipv4_hdr);
+                       }
                }
        } else if (info->ethertype == _htons(RTE_ETHER_TYPE_IPV6))
-               ol_flags |= PKT_TX_IPV6;
+               ol_flags |= RTE_MBUF_F_TX_IPV6;
        else
                return 0; /* packet type not supported, nothing to do */
 
@@ -501,41 +502,41 @@ process_inner_cksums(void *l3_hdr, const struct testpmd_offload_info *info,
                udp_hdr = (struct rte_udp_hdr *)((char *)l3_hdr + info->l3_len);
                /* do not recalculate udp cksum if it was 0 */
                if (udp_hdr->dgram_cksum != 0) {
-                       udp_hdr->dgram_cksum = 0;
-                       if (tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM)
-                               ol_flags |= PKT_TX_UDP_CKSUM;
-                       else {
+                       if (tx_offloads & RTE_ETH_TX_OFFLOAD_UDP_CKSUM) {
+                               ol_flags |= RTE_MBUF_F_TX_UDP_CKSUM;
+                       } else {
+                               udp_hdr->dgram_cksum = 0;
                                udp_hdr->dgram_cksum =
                                        get_udptcp_checksum(l3_hdr, udp_hdr,
                                                info->ethertype);
                        }
                }
                if (info->gso_enable)
-                       ol_flags |= PKT_TX_UDP_SEG;
+                       ol_flags |= RTE_MBUF_F_TX_UDP_SEG;
        } else if (info->l4_proto == IPPROTO_TCP) {
                tcp_hdr = (struct rte_tcp_hdr *)((char *)l3_hdr + info->l3_len);
-               tcp_hdr->cksum = 0;
                if (tso_segsz)
-                       ol_flags |= PKT_TX_TCP_SEG;
-               else if (tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM)
-                       ol_flags |= PKT_TX_TCP_CKSUM;
-               else {
+                       ol_flags |= RTE_MBUF_F_TX_TCP_SEG;
+               else if (tx_offloads & RTE_ETH_TX_OFFLOAD_TCP_CKSUM) {
+                       ol_flags |= RTE_MBUF_F_TX_TCP_CKSUM;
+               } else {
+                       tcp_hdr->cksum = 0;
                        tcp_hdr->cksum =
                                get_udptcp_checksum(l3_hdr, tcp_hdr,
                                        info->ethertype);
                }
                if (info->gso_enable)
-                       ol_flags |= PKT_TX_TCP_SEG;
+                       ol_flags |= RTE_MBUF_F_TX_TCP_SEG;
        } else if (info->l4_proto == IPPROTO_SCTP) {
                sctp_hdr = (struct rte_sctp_hdr *)
                        ((char *)l3_hdr + info->l3_len);
-               sctp_hdr->cksum = 0;
                /* sctp payload must be a multiple of 4 to be
                 * offloaded */
-               if ((tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) &&
+               if ((tx_offloads & RTE_ETH_TX_OFFLOAD_SCTP_CKSUM) &&
                        ((ipv4_hdr->total_length & 0x3) == 0)) {
-                       ol_flags |= PKT_TX_SCTP_CKSUM;
+                       ol_flags |= RTE_MBUF_F_TX_SCTP_CKSUM;
                } else {
+                       sctp_hdr->cksum = 0;
                        /* XXX implement CRC32c, example available in
                         * RFC3309 */
                }
@@ -556,14 +557,14 @@ process_outer_cksums(void *outer_l3_hdr, struct testpmd_offload_info *info,
 
        if (info->outer_ethertype == _htons(RTE_ETHER_TYPE_IPV4)) {
                ipv4_hdr->hdr_checksum = 0;
-               ol_flags |= PKT_TX_OUTER_IPV4;
+               ol_flags |= RTE_MBUF_F_TX_OUTER_IPV4;
 
-               if (tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM)
-                       ol_flags |= PKT_TX_OUTER_IP_CKSUM;
+               if (tx_offloads & RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM)
+                       ol_flags |= RTE_MBUF_F_TX_OUTER_IP_CKSUM;
                else
                        ipv4_hdr->hdr_checksum = rte_ipv4_cksum(ipv4_hdr);
        } else
-               ol_flags |= PKT_TX_OUTER_IPV6;
+               ol_flags |= RTE_MBUF_F_TX_OUTER_IPV6;
 
        if (info->outer_l4_proto != IPPROTO_UDP)
                return ol_flags;
@@ -572,10 +573,10 @@ process_outer_cksums(void *outer_l3_hdr, struct testpmd_offload_info *info,
                ((char *)outer_l3_hdr + info->outer_l3_len);
 
        if (tso_enabled)
-               ol_flags |= PKT_TX_TCP_SEG;
+               ol_flags |= RTE_MBUF_F_TX_TCP_SEG;
 
        /* Skip SW outer UDP checksum generation if HW supports it */
-       if (tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) {
+       if (tx_offloads & RTE_ETH_TX_OFFLOAD_OUTER_UDP_CKSUM) {
                if (info->outer_ethertype == _htons(RTE_ETHER_TYPE_IPV4))
                        udp_hdr->dgram_cksum
                                = rte_ipv4_phdr_cksum(ipv4_hdr, ol_flags);
@@ -583,7 +584,7 @@ process_outer_cksums(void *outer_l3_hdr, struct testpmd_offload_info *info,
                        udp_hdr->dgram_cksum
                                = rte_ipv6_phdr_cksum(ipv6_hdr, ol_flags);
 
-               ol_flags |= PKT_TX_OUTER_UDP_CKSUM;
+               ol_flags |= RTE_MBUF_F_TX_OUTER_UDP_CKSUM;
                return ol_flags;
        }
 
@@ -696,7 +697,7 @@ pkt_copy_split(const struct rte_mbuf *pkt)
        mp = current_fwd_lcore()->mbp;
 
        if (tx_pkt_split == TX_PKT_SPLIT_RND)
-               nb_seg = random() % tx_pkt_nb_segs + 1;
+               nb_seg = rte_rand() % tx_pkt_nb_segs + 1;
        else
                nb_seg = tx_pkt_nb_segs;
 
@@ -814,6 +815,7 @@ pkt_burst_checksum_forward(struct fwd_stream *fs)
        uint32_t rx_bad_ip_csum;
        uint32_t rx_bad_l4_csum;
        uint32_t rx_bad_outer_l4_csum;
+       uint32_t rx_bad_outer_ip_csum;
        struct testpmd_offload_info info;
        uint16_t nb_segments = 0;
        int ret;
@@ -833,6 +835,7 @@ pkt_burst_checksum_forward(struct fwd_stream *fs)
        rx_bad_ip_csum = 0;
        rx_bad_l4_csum = 0;
        rx_bad_outer_l4_csum = 0;
+       rx_bad_outer_ip_csum = 0;
        gro_enable = gro_ports[fs->rx_port].enable;
 
        txp = &ports[fs->tx_port];
@@ -852,25 +855,27 @@ pkt_burst_checksum_forward(struct fwd_stream *fs)
                info.is_tunnel = 0;
                info.pkt_len = rte_pktmbuf_pkt_len(m);
                tx_ol_flags = m->ol_flags &
-                             (IND_ATTACHED_MBUF | EXT_ATTACHED_MBUF);
+                             (RTE_MBUF_F_INDIRECT | RTE_MBUF_F_EXTERNAL);
                rx_ol_flags = m->ol_flags;
 
                /* Update the L3/L4 checksum error packet statistics */
-               if ((rx_ol_flags & PKT_RX_IP_CKSUM_MASK) == PKT_RX_IP_CKSUM_BAD)
+               if ((rx_ol_flags & RTE_MBUF_F_RX_IP_CKSUM_MASK) == RTE_MBUF_F_RX_IP_CKSUM_BAD)
                        rx_bad_ip_csum += 1;
-               if ((rx_ol_flags & PKT_RX_L4_CKSUM_MASK) == PKT_RX_L4_CKSUM_BAD)
+               if ((rx_ol_flags & RTE_MBUF_F_RX_L4_CKSUM_MASK) == RTE_MBUF_F_RX_L4_CKSUM_BAD)
                        rx_bad_l4_csum += 1;
-               if (rx_ol_flags & PKT_RX_OUTER_L4_CKSUM_BAD)
+               if (rx_ol_flags & RTE_MBUF_F_RX_OUTER_L4_CKSUM_BAD)
                        rx_bad_outer_l4_csum += 1;
+               if (rx_ol_flags & RTE_MBUF_F_RX_OUTER_IP_CKSUM_BAD)
+                       rx_bad_outer_ip_csum += 1;
 
                /* step 1: dissect packet, parsing optional vlan, ip4/ip6, vxlan
                 * and inner headers */
 
                eth_hdr = rte_pktmbuf_mtod(m, struct rte_ether_hdr *);
                rte_ether_addr_copy(&peer_eth_addrs[fs->peer_addr],
-                               &eth_hdr->d_addr);
+                               &eth_hdr->dst_addr);
                rte_ether_addr_copy(&ports[fs->tx_port].eth_addr,
-                               &eth_hdr->s_addr);
+                               &eth_hdr->src_addr);
                parse_ethernet(eth_hdr, &info);
                l3_hdr = (char *)eth_hdr + info.l2_len;
 
@@ -883,26 +888,26 @@ pkt_burst_checksum_forward(struct fwd_stream *fs)
                                        ((char *)l3_hdr + info.l3_len);
                                parse_gtp(udp_hdr, &info);
                                if (info.is_tunnel) {
-                                       tx_ol_flags |= PKT_TX_TUNNEL_GTP;
+                                       tx_ol_flags |= RTE_MBUF_F_TX_TUNNEL_GTP;
                                        goto tunnel_update;
                                }
                                parse_vxlan_gpe(udp_hdr, &info);
                                if (info.is_tunnel) {
                                        tx_ol_flags |=
-                                               PKT_TX_TUNNEL_VXLAN_GPE;
+                                               RTE_MBUF_F_TX_TUNNEL_VXLAN_GPE;
                                        goto tunnel_update;
                                }
                                parse_vxlan(udp_hdr, &info,
                                            m->packet_type);
                                if (info.is_tunnel) {
                                        tx_ol_flags |=
-                                               PKT_TX_TUNNEL_VXLAN;
+                                               RTE_MBUF_F_TX_TUNNEL_VXLAN;
                                        goto tunnel_update;
                                }
                                parse_geneve(udp_hdr, &info);
                                if (info.is_tunnel) {
                                        tx_ol_flags |=
-                                               PKT_TX_TUNNEL_GENEVE;
+                                               RTE_MBUF_F_TX_TUNNEL_GENEVE;
                                        goto tunnel_update;
                                }
                        } else if (info.l4_proto == IPPROTO_GRE) {
@@ -912,14 +917,14 @@ pkt_burst_checksum_forward(struct fwd_stream *fs)
                                        ((char *)l3_hdr + info.l3_len);
                                parse_gre(gre_hdr, &info);
                                if (info.is_tunnel)
-                                       tx_ol_flags |= PKT_TX_TUNNEL_GRE;
+                                       tx_ol_flags |= RTE_MBUF_F_TX_TUNNEL_GRE;
                        } else if (info.l4_proto == IPPROTO_IPIP) {
                                void *encap_ip_hdr;
 
                                encap_ip_hdr = (char *)l3_hdr + info.l3_len;
                                parse_encap_ip(encap_ip_hdr, &info);
                                if (info.is_tunnel)
-                                       tx_ol_flags |= PKT_TX_TUNNEL_IPIP;
+                                       tx_ol_flags |= RTE_MBUF_F_TX_TUNNEL_IPIP;
                        }
                }
 
@@ -945,7 +950,7 @@ tunnel_update:
                if (info.is_tunnel == 1) {
                        tx_ol_flags |= process_outer_cksums(outer_l3_hdr, &info,
                                        tx_offloads,
-                                       !!(tx_ol_flags & PKT_TX_TCP_SEG));
+                                       !!(tx_ol_flags & RTE_MBUF_F_TX_TCP_SEG));
                }
 
                /* step 3: fill the mbuf meta data (flags and header lengths) */
@@ -954,10 +959,9 @@ tunnel_update:
                if (info.is_tunnel == 1) {
                        if (info.tunnel_tso_segsz ||
                            (tx_offloads &
-                            DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) ||
+                            RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM) ||
                            (tx_offloads &
-                            DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) ||
-                           (tx_ol_flags & PKT_TX_OUTER_IPV6)) {
+                            RTE_ETH_TX_OFFLOAD_OUTER_UDP_CKSUM)) {
                                m->outer_l2_len = info.outer_l2_len;
                                m->outer_l3_len = info.outer_l3_len;
                                m->l2_len = info.l2_len;
@@ -1010,7 +1014,7 @@ tunnel_update:
                                "l4_proto=%d l4_len=%d flags=%s\n",
                                info.l2_len, rte_be_to_cpu_16(info.ethertype),
                                info.l3_len, info.l4_proto, info.l4_len, buf);
-                       if (rx_ol_flags & PKT_RX_LRO)
+                       if (rx_ol_flags & RTE_MBUF_F_RX_LRO)
                                printf("rx: m->lro_segsz=%u\n", m->tso_segsz);
                        if (info.is_tunnel == 1)
                                printf("rx: outer_l2_len=%d outer_ethertype=%x "
@@ -1018,30 +1022,30 @@ tunnel_update:
                                        rte_be_to_cpu_16(info.outer_ethertype),
                                        info.outer_l3_len);
                        /* dump tx packet info */
-                       if ((tx_offloads & (DEV_TX_OFFLOAD_IPV4_CKSUM |
-                                           DEV_TX_OFFLOAD_UDP_CKSUM |
-                                           DEV_TX_OFFLOAD_TCP_CKSUM |
-                                           DEV_TX_OFFLOAD_SCTP_CKSUM)) ||
+                       if ((tx_offloads & (RTE_ETH_TX_OFFLOAD_IPV4_CKSUM |
+                                           RTE_ETH_TX_OFFLOAD_UDP_CKSUM |
+                                           RTE_ETH_TX_OFFLOAD_TCP_CKSUM |
+                                           RTE_ETH_TX_OFFLOAD_SCTP_CKSUM)) ||
                                info.tso_segsz != 0)
                                printf("tx: m->l2_len=%d m->l3_len=%d "
                                        "m->l4_len=%d\n",
                                        m->l2_len, m->l3_len, m->l4_len);
                        if (info.is_tunnel == 1) {
                                if ((tx_offloads &
-                                   DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) ||
+                                   RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM) ||
                                    (tx_offloads &
-                                   DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) ||
-                                   (tx_ol_flags & PKT_TX_OUTER_IPV6))
+                                   RTE_ETH_TX_OFFLOAD_OUTER_UDP_CKSUM) ||
+                                   (tx_ol_flags & RTE_MBUF_F_TX_OUTER_IPV6))
                                        printf("tx: m->outer_l2_len=%d "
                                                "m->outer_l3_len=%d\n",
                                                m->outer_l2_len,
                                                m->outer_l3_len);
                                if (info.tunnel_tso_segsz != 0 &&
-                                               (m->ol_flags & PKT_TX_TCP_SEG))
+                                               (m->ol_flags & RTE_MBUF_F_TX_TCP_SEG))
                                        printf("tx: m->tso_segsz=%d\n",
                                                m->tso_segsz);
                        } else if (info.tso_segsz != 0 &&
-                                       (m->ol_flags & PKT_TX_TCP_SEG))
+                                       (m->ol_flags & RTE_MBUF_F_TX_TCP_SEG))
                                printf("tx: m->tso_segsz=%d\n", m->tso_segsz);
                        rte_get_tx_ol_flag_list(m->ol_flags, buf, sizeof(buf));
                        printf("tx: flags=%s", buf);
@@ -1080,9 +1084,17 @@ tunnel_update:
                        ret = rte_gso_segment(pkts_burst[i], gso_ctx,
                                        &gso_segments[nb_segments],
                                        GSO_MAX_PKT_BURST - nb_segments);
-                       if (ret >= 0)
+                       if (ret >= 1) {
+                               /* pkts_burst[i] can be freed safely here. */
+                               rte_pktmbuf_free(pkts_burst[i]);
                                nb_segments += ret;
-                       else {
+                       } else if (ret == 0) {
+                               /* 0 means it can be transmitted directly
+                                * without gso.
+                                */
+                               gso_segments[nb_segments] = pkts_burst[i];
+                               nb_segments += 1;
+                       } else {
                                TESTPMD_LOG(DEBUG, "Unable to segment packet");
                                rte_pktmbuf_free(pkts_burst[i]);
                        }
@@ -1095,8 +1107,9 @@ tunnel_update:
        nb_prep = rte_eth_tx_prepare(fs->tx_port, fs->tx_queue,
                        tx_pkts_burst, nb_rx);
        if (nb_prep != nb_rx)
-               printf("Preparing packet burst to transmit failed: %s\n",
-                               rte_strerror(rte_errno));
+               fprintf(stderr,
+                       "Preparing packet burst to transmit failed: %s\n",
+                       rte_strerror(rte_errno));
 
        nb_tx = rte_eth_tx_burst(fs->tx_port, fs->tx_queue, tx_pkts_burst,
                        nb_prep);
@@ -1116,6 +1129,7 @@ tunnel_update:
        fs->rx_bad_ip_csum += rx_bad_ip_csum;
        fs->rx_bad_l4_csum += rx_bad_l4_csum;
        fs->rx_bad_outer_l4_csum += rx_bad_outer_l4_csum;
+       fs->rx_bad_outer_ip_csum += rx_bad_outer_ip_csum;
 
        inc_tx_burst_stats(fs, nb_tx);
        if (unlikely(nb_tx < nb_rx)) {