| 656 | } while (0) |
| 657 | |
| 658 | static __rte_always_inline void |
| 659 | virtio_enqueue_offload(struct rte_mbuf *m_buf, struct virtio_net_hdr *net_hdr) |
| 660 | { |
| 661 | uint64_t csum_l4 = m_buf->ol_flags & RTE_MBUF_F_TX_L4_MASK; |
| 662 | |
| 663 | if (m_buf->ol_flags & RTE_MBUF_F_TX_TCP_SEG) |
| 664 | csum_l4 |= RTE_MBUF_F_TX_TCP_CKSUM; |
| 665 | |
| 666 | if (csum_l4) { |
| 667 | /* |
| 668 | * Pseudo-header checksum must be set as per Virtio spec. |
| 669 | * |
| 670 | * Note: We don't propagate rte_net_intel_cksum_prepare() |
| 671 | * errors, as it would have an impact on performance, and an |
| 672 | * error would mean the packet is dropped by the guest instead |
| 673 | * of being dropped here. |
| 674 | */ |
| 675 | rte_net_intel_cksum_prepare(m_buf); |
| 676 | |
| 677 | net_hdr->flags = VIRTIO_NET_HDR_F_NEEDS_CSUM; |
| 678 | net_hdr->csum_start = m_buf->l2_len + m_buf->l3_len; |
| 679 | |
| 680 | switch (csum_l4) { |
| 681 | case RTE_MBUF_F_TX_TCP_CKSUM: |
| 682 | net_hdr->csum_offset = (offsetof(struct rte_tcp_hdr, |
| 683 | cksum)); |
| 684 | break; |
| 685 | case RTE_MBUF_F_TX_UDP_CKSUM: |
| 686 | net_hdr->csum_offset = (offsetof(struct rte_udp_hdr, |
| 687 | dgram_cksum)); |
| 688 | break; |
| 689 | case RTE_MBUF_F_TX_SCTP_CKSUM: |
| 690 | net_hdr->csum_offset = (offsetof(struct rte_sctp_hdr, |
| 691 | cksum)); |
| 692 | break; |
| 693 | } |
| 694 | } else { |
| 695 | ASSIGN_UNLESS_EQUAL(net_hdr->csum_start, 0); |
| 696 | ASSIGN_UNLESS_EQUAL(net_hdr->csum_offset, 0); |
| 697 | ASSIGN_UNLESS_EQUAL(net_hdr->flags, 0); |
| 698 | } |
| 699 | |
| 700 | /* IP cksum verification cannot be bypassed, then calculate here */ |
| 701 | if (m_buf->ol_flags & RTE_MBUF_F_TX_IP_CKSUM) { |
| 702 | struct rte_ipv4_hdr *ipv4_hdr; |
| 703 | |
| 704 | ipv4_hdr = rte_pktmbuf_mtod_offset(m_buf, struct rte_ipv4_hdr *, |
| 705 | m_buf->l2_len); |
| 706 | ipv4_hdr->hdr_checksum = 0; |
| 707 | ipv4_hdr->hdr_checksum = rte_ipv4_cksum(ipv4_hdr); |
| 708 | } |
| 709 | |
| 710 | if (m_buf->ol_flags & RTE_MBUF_F_TX_TCP_SEG) { |
| 711 | if (m_buf->ol_flags & RTE_MBUF_F_TX_IPV4) |
| 712 | net_hdr->gso_type = VIRTIO_NET_HDR_GSO_TCPV4; |
| 713 | else |
| 714 | net_hdr->gso_type = VIRTIO_NET_HDR_GSO_TCPV6; |
| 715 | net_hdr->gso_size = m_buf->tso_segsz; |
no test coverage detected