From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by dpdk.org (Postfix) with ESMTP id 0D1E58170 for ; Sat, 11 Oct 2014 07:48:31 +0200 (CEST) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga101.fm.intel.com with ESMTP; 10 Oct 2014 22:56:01 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.04,697,1406617200"; d="scan'208";a="612841349" Received: from shvmail01.sh.intel.com ([10.239.29.42]) by fmsmga002.fm.intel.com with ESMTP; 10 Oct 2014 22:56:00 -0700 Received: from shecgisg004.sh.intel.com (shecgisg004.sh.intel.com [10.239.29.89]) by shvmail01.sh.intel.com with ESMTP id s9B5tw5m019309; Sat, 11 Oct 2014 13:55:58 +0800 Received: from shecgisg004.sh.intel.com (localhost [127.0.0.1]) by shecgisg004.sh.intel.com (8.13.6/8.13.6/SuSE Linux 0.8) with ESMTP id s9B5tuSB022626; Sat, 11 Oct 2014 13:55:58 +0800 Received: (from jijiangl@localhost) by shecgisg004.sh.intel.com (8.13.6/8.13.6/Submit) id s9B5tuEk022622; Sat, 11 Oct 2014 13:55:56 +0800 From: Jijiang Liu To: dev@dpdk.org Date: Sat, 11 Oct 2014 13:55:35 +0800 Message-Id: <1413006935-22535-9-git-send-email-jijiang.liu@intel.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1413006935-22535-1-git-send-email-jijiang.liu@intel.com> References: <1413006935-22535-1-git-send-email-jijiang.liu@intel.com> Subject: [dpdk-dev] [PATCH v5 8/8]app/testpmd:test VxLAN Tx checksum offload X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 11 Oct 2014 05:48:33 -0000 Add test cases in testpmd to test VxLAN Tx Checksum offload, which include - IPv4 tunnel and IPv6 tunnel - outer L3, inner L3 and L4 checksum offload for Tx side. Signed-off-by: Jijiang Liu Acked-by: Helin Zhang Acked-by: Jingjing Wu Acked-by: Jing Chen --- app/test-pmd/config.c | 6 +- app/test-pmd/csumonly.c | 195 +++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 183 insertions(+), 18 deletions(-) diff --git a/app/test-pmd/config.c b/app/test-pmd/config.c index 2a1b93f..9bc08f4 100644 --- a/app/test-pmd/config.c +++ b/app/test-pmd/config.c @@ -1753,9 +1753,9 @@ tx_cksum_set(portid_t port_id, uint64_t ol_flags) uint64_t tx_ol_flags; if (port_id_is_invalid(port_id)) return; - /* Clear last 4 bits and then set L3/4 checksum mask again */ - tx_ol_flags = ports[port_id].tx_ol_flags & (~0x0Full); - ports[port_id].tx_ol_flags = ((ol_flags & 0xf) | tx_ol_flags); + /* Clear last 8 bits and then set L3/4 checksum mask again */ + tx_ol_flags = ports[port_id].tx_ol_flags & (~0x0FFull); + ports[port_id].tx_ol_flags = ((ol_flags & 0xff) | tx_ol_flags); } void diff --git a/app/test-pmd/csumonly.c b/app/test-pmd/csumonly.c index fcc4876..e2ac129 100644 --- a/app/test-pmd/csumonly.c +++ b/app/test-pmd/csumonly.c @@ -196,7 +196,6 @@ get_ipv6_udptcp_checksum(struct ipv6_hdr *ipv6_hdr, uint16_t *l4_hdr) return (uint16_t)cksum; } - /* * Forwarding of packets. Change the checksum field with HW or SW methods * The HW/SW method selection depends on the ol_flags on every packet @@ -209,10 +208,16 @@ pkt_burst_checksum_forward(struct fwd_stream *fs) struct rte_mbuf *mb; struct ether_hdr *eth_hdr; struct ipv4_hdr *ipv4_hdr; + struct ether_hdr *inner_eth_hdr; + struct ipv4_hdr *inner_ipv4_hdr = NULL; struct ipv6_hdr *ipv6_hdr; + struct ipv6_hdr *inner_ipv6_hdr = NULL; struct udp_hdr *udp_hdr; + struct udp_hdr *inner_udp_hdr; struct tcp_hdr *tcp_hdr; + struct tcp_hdr *inner_tcp_hdr; struct sctp_hdr *sctp_hdr; + struct sctp_hdr *inner_sctp_hdr; uint16_t nb_rx; uint16_t nb_tx; @@ -221,12 +226,18 @@ pkt_burst_checksum_forward(struct fwd_stream *fs) uint64_t pkt_ol_flags; uint64_t tx_ol_flags; uint16_t l4_proto; + uint16_t inner_l4_proto = 0; uint16_t eth_type; uint8_t l2_len; uint8_t l3_len; + uint8_t inner_l2_len = 0; + uint8_t inner_l3_len = 0; uint32_t rx_bad_ip_csum; uint32_t rx_bad_l4_csum; + uint8_t ipv4_tunnel; + uint8_t ipv6_tunnel; + uint16_t ptype; #ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES uint64_t start_tsc; @@ -262,7 +273,9 @@ pkt_burst_checksum_forward(struct fwd_stream *fs) l2_len = sizeof(struct ether_hdr); pkt_ol_flags = mb->ol_flags; ol_flags = (pkt_ol_flags & (~PKT_TX_L4_MASK)); - + ptype = mb->packet_type; + ipv4_tunnel = IS_ETH_IPV4_TUNNEL(ptype); + ipv6_tunnel = IS_ETH_IPV6_TUNNEL(ptype); eth_hdr = rte_pktmbuf_mtod(mb, struct ether_hdr *); eth_type = rte_be_to_cpu_16(eth_hdr->ether_type); if (eth_type == ETHER_TYPE_VLAN) { @@ -295,7 +308,7 @@ pkt_burst_checksum_forward(struct fwd_stream *fs) * + ipv4 or ipv6 * + udp or tcp or sctp or others */ - if (pkt_ol_flags & PKT_RX_IPV4_HDR) { + if (pkt_ol_flags & (PKT_RX_IPV4_HDR | PKT_RX_IPV4_HDR_EXT)) { /* Do not support ipv4 option field */ l3_len = sizeof(struct ipv4_hdr) ; @@ -325,17 +338,92 @@ pkt_burst_checksum_forward(struct fwd_stream *fs) if (tx_ol_flags & 0x2) { /* HW Offload */ ol_flags |= PKT_TX_UDP_CKSUM; - /* Pseudo header sum need be set properly */ - udp_hdr->dgram_cksum = get_ipv4_psd_sum(ipv4_hdr); + if (ipv4_tunnel) + udp_hdr->dgram_cksum = 0; + else + /* Pseudo header sum need be set properly */ + udp_hdr->dgram_cksum = + get_ipv4_psd_sum(ipv4_hdr); } else { /* SW Implementation, clear checksum field first */ udp_hdr->dgram_cksum = 0; udp_hdr->dgram_cksum = get_ipv4_udptcp_checksum(ipv4_hdr, - (uint16_t*)udp_hdr); + (uint16_t *)udp_hdr); } - } - else if (l4_proto == IPPROTO_TCP){ + + if (ipv4_tunnel) { + + uint16_t len; + + /* Check if inner L3/L4 checkum flag is set */ + if (tx_ol_flags & 0xF0) + ol_flags |= PKT_TX_VXLAN_CKSUM; + + inner_l2_len = sizeof(struct ether_hdr); + inner_eth_hdr = (struct ether_hdr *) (rte_pktmbuf_mtod(mb, + unsigned char *) + l2_len + l3_len + + ETHER_VXLAN_HLEN); + + eth_type = rte_be_to_cpu_16(inner_eth_hdr->ether_type); + if (eth_type == ETHER_TYPE_VLAN) { + inner_l2_len += sizeof(struct vlan_hdr); + eth_type = rte_be_to_cpu_16(*(uint16_t *) + ((uintptr_t)ð_hdr->ether_type + + sizeof(struct vlan_hdr))); + } + + len = l2_len + l3_len + ETHER_VXLAN_HLEN + inner_l2_len; + if (eth_type == ETHER_TYPE_IPv4) { + inner_l3_len = sizeof(struct ipv4_hdr); + inner_ipv4_hdr = (struct ipv4_hdr *) (rte_pktmbuf_mtod(mb, + unsigned char *) + len); + inner_l4_proto = inner_ipv4_hdr->next_proto_id; + + if (tx_ol_flags & 0x10) { + + /* Do not delete, this is required by HW*/ + inner_ipv4_hdr->hdr_checksum = 0; + ol_flags |= PKT_TX_IPV4_CSUM; + } + + } else if (eth_type == ETHER_TYPE_IPv6) { + inner_l3_len = sizeof(struct ipv6_hdr); + inner_ipv6_hdr = (struct ipv6_hdr *) (rte_pktmbuf_mtod(mb, + unsigned char *) + len); + inner_l4_proto = inner_ipv6_hdr->proto; + } + if ((inner_l4_proto == IPPROTO_UDP) && (tx_ol_flags & 0x20)) { + + /* HW Offload */ + ol_flags |= PKT_TX_UDP_CKSUM; + inner_udp_hdr = (struct udp_hdr *) (rte_pktmbuf_mtod(mb, + unsigned char *) + len + inner_l3_len); + if (eth_type == ETHER_TYPE_IPv4) + inner_udp_hdr->dgram_cksum = get_ipv4_psd_sum(inner_ipv4_hdr); + else if (eth_type == ETHER_TYPE_IPv6) + inner_udp_hdr->dgram_cksum = get_ipv6_psd_sum(inner_ipv6_hdr); + + } else if ((inner_l4_proto == IPPROTO_TCP) && (tx_ol_flags & 0x40)) { + /* HW Offload */ + ol_flags |= PKT_TX_TCP_CKSUM; + inner_tcp_hdr = (struct tcp_hdr *) (rte_pktmbuf_mtod(mb, + unsigned char *) + len + inner_l3_len); + if (eth_type == ETHER_TYPE_IPv4) + inner_tcp_hdr->cksum = get_ipv4_psd_sum(inner_ipv4_hdr); + else if (eth_type == ETHER_TYPE_IPv6) + inner_tcp_hdr->cksum = get_ipv6_psd_sum(inner_ipv6_hdr); + } else if ((inner_l4_proto == IPPROTO_SCTP) && (tx_ol_flags & 0x80)) { + /* HW Offload */ + ol_flags |= PKT_TX_SCTP_CKSUM; + inner_sctp_hdr = (struct sctp_hdr *) (rte_pktmbuf_mtod(mb, + unsigned char *) + len + inner_l3_len); + inner_sctp_hdr->cksum = 0; + } + + } + + } else if (l4_proto == IPPROTO_TCP) { tcp_hdr = (struct tcp_hdr*) (rte_pktmbuf_mtod(mb, unsigned char *) + l2_len + l3_len); if (tx_ol_flags & 0x4) { @@ -347,8 +435,7 @@ pkt_burst_checksum_forward(struct fwd_stream *fs) tcp_hdr->cksum = get_ipv4_udptcp_checksum(ipv4_hdr, (uint16_t*)tcp_hdr); } - } - else if (l4_proto == IPPROTO_SCTP) { + } else if (l4_proto == IPPROTO_SCTP) { sctp_hdr = (struct sctp_hdr*) (rte_pktmbuf_mtod(mb, unsigned char *) + l2_len + l3_len); @@ -367,9 +454,7 @@ pkt_burst_checksum_forward(struct fwd_stream *fs) } } /* End of L4 Handling*/ - } - else if (pkt_ol_flags & PKT_RX_IPV6_HDR) { - + } else if (pkt_ol_flags & (PKT_RX_IPV6_HDR | PKT_RX_IPV6_HDR_EXT)) { ipv6_hdr = (struct ipv6_hdr *) (rte_pktmbuf_mtod(mb, unsigned char *) + l2_len); l3_len = sizeof(struct ipv6_hdr) ; @@ -382,15 +467,93 @@ pkt_burst_checksum_forward(struct fwd_stream *fs) if (tx_ol_flags & 0x2) { /* HW Offload */ ol_flags |= PKT_TX_UDP_CKSUM; - udp_hdr->dgram_cksum = get_ipv6_psd_sum(ipv6_hdr); + if (ipv6_tunnel) + udp_hdr->dgram_cksum = 0; + else + udp_hdr->dgram_cksum = + get_ipv6_psd_sum(ipv6_hdr); } else { /* SW Implementation */ /* checksum field need be clear first */ udp_hdr->dgram_cksum = 0; udp_hdr->dgram_cksum = get_ipv6_udptcp_checksum(ipv6_hdr, - (uint16_t*)udp_hdr); + (uint16_t *)udp_hdr); } + + if (ipv6_tunnel) { + + uint16_t len; + + /* Check if inner L3/L4 checksum flag is set */ + if (tx_ol_flags & 0xF0) + ol_flags |= PKT_TX_VXLAN_CKSUM; + + inner_l2_len = sizeof(struct ether_hdr); + inner_eth_hdr = (struct ether_hdr *) (rte_pktmbuf_mtod(mb, + unsigned char *) + l2_len + l3_len + ETHER_VXLAN_HLEN); + eth_type = rte_be_to_cpu_16(inner_eth_hdr->ether_type); + + if (eth_type == ETHER_TYPE_VLAN) { + inner_l2_len += sizeof(struct vlan_hdr); + eth_type = rte_be_to_cpu_16(*(uint16_t *) + ((uintptr_t)ð_hdr->ether_type + + sizeof(struct vlan_hdr))); + } + + len = l2_len + l3_len + ETHER_VXLAN_HLEN + inner_l2_len; + + if (eth_type == ETHER_TYPE_IPv4) { + inner_l3_len = sizeof(struct ipv4_hdr); + inner_ipv4_hdr = (struct ipv4_hdr *) (rte_pktmbuf_mtod(mb, + unsigned char *) + len); + inner_l4_proto = inner_ipv4_hdr->next_proto_id; + + /* HW offload */ + if (tx_ol_flags & 0x10) { + + /* Do not delete, this is required by HW*/ + inner_ipv4_hdr->hdr_checksum = 0; + ol_flags |= PKT_TX_IPV4_CSUM; + } + } else if (eth_type == ETHER_TYPE_IPv6) { + inner_l3_len = sizeof(struct ipv6_hdr); + inner_ipv6_hdr = (struct ipv6_hdr *) (rte_pktmbuf_mtod(mb, + unsigned char *) + len); + inner_l4_proto = inner_ipv6_hdr->proto; + } + + if ((inner_l4_proto == IPPROTO_UDP) && (tx_ol_flags & 0x20)) { + inner_udp_hdr = (struct udp_hdr *) (rte_pktmbuf_mtod(mb, + unsigned char *) + len + inner_l3_len); + /* HW offload */ + ol_flags |= PKT_TX_UDP_CKSUM; + inner_udp_hdr->dgram_cksum = 0; + if (eth_type == ETHER_TYPE_IPv4) + inner_udp_hdr->dgram_cksum = get_ipv4_psd_sum(inner_ipv4_hdr); + else if (eth_type == ETHER_TYPE_IPv6) + inner_udp_hdr->dgram_cksum = get_ipv6_psd_sum(inner_ipv6_hdr); + } else if ((inner_l4_proto == IPPROTO_TCP) && (tx_ol_flags & 0x40)) { + /* HW offload */ + ol_flags |= PKT_TX_TCP_CKSUM; + inner_tcp_hdr = (struct tcp_hdr *) (rte_pktmbuf_mtod(mb, + unsigned char *) + len + inner_l3_len); + + if (eth_type == ETHER_TYPE_IPv4) + inner_tcp_hdr->cksum = get_ipv4_psd_sum(inner_ipv4_hdr); + else if (eth_type == ETHER_TYPE_IPv6) + inner_tcp_hdr->cksum = get_ipv6_psd_sum(inner_ipv6_hdr); + + } else if ((inner_l4_proto == IPPROTO_SCTP) && (tx_ol_flags & 0x80)) { + /* HW offload */ + ol_flags |= PKT_TX_SCTP_CKSUM; + inner_sctp_hdr = (struct sctp_hdr *) (rte_pktmbuf_mtod(mb, + unsigned char *) + len + inner_l3_len); + inner_sctp_hdr->cksum = 0; + } + + } + } else if (l4_proto == IPPROTO_TCP) { tcp_hdr = (struct tcp_hdr*) (rte_pktmbuf_mtod(mb, @@ -434,6 +597,8 @@ pkt_burst_checksum_forward(struct fwd_stream *fs) /* Combine the packet header write. VLAN is not consider here */ mb->l2_len = l2_len; mb->l3_len = l3_len; + mb->inner_l2_len = inner_l2_len; + mb->inner_l3_len = inner_l3_len; mb->ol_flags = ol_flags; } nb_tx = rte_eth_tx_burst(fs->tx_port, fs->tx_queue, pkts_burst, nb_rx); -- 1.7.7.6