+/**
+ * Calculate the checksum of a packet in hardware
+ */
+static uint64_t
+process_inner_cksums(struct rte_ether_hdr *eth_hdr,
+ union tunnel_offload_info *info)
+{
+ void *l3_hdr = NULL;
+ uint8_t l4_proto;
+ uint16_t ethertype;
+ struct rte_ipv4_hdr *ipv4_hdr;
+ struct rte_ipv6_hdr *ipv6_hdr;
+ struct rte_udp_hdr *udp_hdr;
+ struct rte_tcp_hdr *tcp_hdr;
+ struct rte_sctp_hdr *sctp_hdr;
+ uint64_t ol_flags = 0;
+
+ info->l2_len = sizeof(struct rte_ether_hdr);
+ ethertype = rte_be_to_cpu_16(eth_hdr->ether_type);
+
+ if (ethertype == RTE_ETHER_TYPE_VLAN) {
+ struct rte_vlan_hdr *vlan_hdr =
+ (struct rte_vlan_hdr *)(eth_hdr + 1);
+ info->l2_len += sizeof(struct rte_vlan_hdr);
+ ethertype = rte_be_to_cpu_16(vlan_hdr->eth_proto);
+ }
+
+ l3_hdr = (char *)eth_hdr + info->l2_len;
+
+ if (ethertype == RTE_ETHER_TYPE_IPV4) {
+ ipv4_hdr = (struct rte_ipv4_hdr *)l3_hdr;
+ ipv4_hdr->hdr_checksum = 0;
+ ol_flags |= PKT_TX_IPV4;
+ ol_flags |= PKT_TX_IP_CKSUM;
+ info->l3_len = sizeof(struct rte_ipv4_hdr);
+ l4_proto = ipv4_hdr->next_proto_id;
+ } else if (ethertype == RTE_ETHER_TYPE_IPV6) {
+ ipv6_hdr = (struct rte_ipv6_hdr *)l3_hdr;
+ info->l3_len = sizeof(struct rte_ipv6_hdr);
+ l4_proto = ipv6_hdr->proto;
+ ol_flags |= PKT_TX_IPV6;
+ } else
+ return 0; /* packet type not supported, nothing to do */
+
+ if (l4_proto == IPPROTO_UDP) {
+ udp_hdr = (struct rte_udp_hdr *)((char *)l3_hdr + info->l3_len);
+ ol_flags |= PKT_TX_UDP_CKSUM;
+ udp_hdr->dgram_cksum = get_psd_sum(l3_hdr,
+ ethertype, ol_flags);
+ } else if (l4_proto == IPPROTO_TCP) {
+ tcp_hdr = (struct rte_tcp_hdr *)((char *)l3_hdr + info->l3_len);
+ /* Put PKT_TX_TCP_SEG bit setting before get_psd_sum(), because
+ * it depends on PKT_TX_TCP_SEG to calculate pseudo-header
+ * checksum.
+ */
+ if (tso_segsz != 0) {
+ ol_flags |= PKT_TX_TCP_SEG;
+ info->tso_segsz = tso_segsz;
+ info->l4_len = (tcp_hdr->data_off & 0xf0) >> 2;
+ }
+ ol_flags |= PKT_TX_TCP_CKSUM;
+ tcp_hdr->cksum = get_psd_sum(l3_hdr, ethertype, ol_flags);
+
+ } else if (l4_proto == IPPROTO_SCTP) {
+ sctp_hdr = (struct rte_sctp_hdr *)
+ ((char *)l3_hdr + info->l3_len);
+ sctp_hdr->cksum = 0;
+ ol_flags |= PKT_TX_SCTP_CKSUM;
+ }
+
+ return ol_flags;
+}
+