ethdev: add Tx preparation
[dpdk.git] / lib / librte_mbuf / rte_mbuf.h
index ead7c6e..4476d75 100644 (file)
@@ -283,6 +283,19 @@ extern "C" {
  */
 #define PKT_TX_OUTER_IPV6    (1ULL << 60)
 
+/**
+ * Bitmask of all supported packet Tx offload features flags,
+ * which can be set for packet.
+ */
+#define PKT_TX_OFFLOAD_MASK (    \
+               PKT_TX_IP_CKSUM |        \
+               PKT_TX_L4_MASK |         \
+               PKT_TX_OUTER_IP_CKSUM |  \
+               PKT_TX_TCP_SEG |         \
+               PKT_TX_QINQ_PKT |        \
+               PKT_TX_VLAN_PKT |        \
+               PKT_TX_TUNNEL_MASK)
+
 #define __RESERVED           (1ULL << 61) /**< reserved for future mbuf use */
 
 #define IND_ATTACHED_MBUF    (1ULL << 62) /**< Indirect attached mbuf */
@@ -1646,6 +1659,57 @@ static inline int rte_pktmbuf_chain(struct rte_mbuf *head, struct rte_mbuf *tail
        return 0;
 }
 
+/**
+ * Validate general requirements for Tx offload in mbuf.
+ *
+ * This function checks correctness and completeness of Tx offload settings.
+ *
+ * @param m
+ *   The packet mbuf to be validated.
+ * @return
+ *   0 if packet is valid
+ */
+static inline int
+rte_validate_tx_offload(const struct rte_mbuf *m)
+{
+       uint64_t ol_flags = m->ol_flags;
+       uint64_t inner_l3_offset = m->l2_len;
+
+       /* Does packet set any of available offloads? */
+       if (!(ol_flags & PKT_TX_OFFLOAD_MASK))
+               return 0;
+
+       if (ol_flags & PKT_TX_OUTER_IP_CKSUM)
+               inner_l3_offset += m->outer_l2_len + m->outer_l3_len;
+
+       /* Headers are fragmented */
+       if (rte_pktmbuf_data_len(m) < inner_l3_offset + m->l3_len + m->l4_len)
+               return -ENOTSUP;
+
+       /* IP checksum can be counted only for IPv4 packet */
+       if ((ol_flags & PKT_TX_IP_CKSUM) && (ol_flags & PKT_TX_IPV6))
+               return -EINVAL;
+
+       /* IP type not set when required */
+       if (ol_flags & (PKT_TX_L4_MASK | PKT_TX_TCP_SEG))
+               if (!(ol_flags & (PKT_TX_IPV4 | PKT_TX_IPV6)))
+                       return -EINVAL;
+
+       /* Check requirements for TSO packet */
+       if (ol_flags & PKT_TX_TCP_SEG)
+               if ((m->tso_segsz == 0) ||
+                               ((ol_flags & PKT_TX_IPV4) &&
+                               !(ol_flags & PKT_TX_IP_CKSUM)))
+                       return -EINVAL;
+
+       /* PKT_TX_OUTER_IP_CKSUM set for non outer IPv4 packet. */
+       if ((ol_flags & PKT_TX_OUTER_IP_CKSUM) &&
+                       !(ol_flags & PKT_TX_OUTER_IPV4))
+               return -EINVAL;
+
+       return 0;
+}
+
 /**
  * Dump an mbuf structure to a file.
  *