ip_frag: use key length for key comparison
[dpdk.git] / lib / librte_mbuf / rte_mbuf.h
index 715f90e..3dbc669 100644 (file)
@@ -140,7 +140,7 @@ extern "C" {
  * The 2 vlans have been stripped by the hardware and their tci are
  * saved in mbuf->vlan_tci (inner) and mbuf->vlan_tci_outer (outer).
  * This can only happen if vlan stripping is enabled in the RX
- * configuration of the PMD. If this flag is set,
+ * configuration of the PMD.
  * When PKT_RX_QINQ_STRIPPED is set, the flags (PKT_RX_VLAN |
  * PKT_RX_VLAN_STRIPPED | PKT_RX_QINQ) must also be set.
  */
@@ -170,17 +170,53 @@ extern "C" {
 
 /**
  * The RX packet is a double VLAN, and the outer tci has been
- * saved in in mbuf->vlan_tci_outer.
+ * saved in in mbuf->vlan_tci_outer. If PKT_RX_QINQ set, PKT_RX_VLAN
+ * also should be set and inner tci should be saved to mbuf->vlan_tci.
  * If the flag PKT_RX_QINQ_STRIPPED is also present, both VLANs
  * headers have been stripped from mbuf data, else they are still
  * present.
  */
 #define PKT_RX_QINQ          (1ULL << 20)
 
+/**
+ * Mask of bits used to determine the status of outer RX L4 checksum.
+ * - PKT_RX_OUTER_L4_CKSUM_UNKNOWN: no info about the outer RX L4 checksum
+ * - PKT_RX_OUTER_L4_CKSUM_BAD: the outer L4 checksum in the packet is wrong
+ * - PKT_RX_OUTER_L4_CKSUM_GOOD: the outer L4 checksum in the packet is valid
+ * - PKT_RX_OUTER_L4_CKSUM_INVALID: invalid outer L4 checksum state.
+ *
+ * The detection of PKT_RX_OUTER_L4_CKSUM_GOOD shall be based on the given
+ * HW capability, At minimum, the PMD should support
+ * PKT_RX_OUTER_L4_CKSUM_UNKNOWN and PKT_RX_OUTER_L4_CKSUM_BAD states
+ * if the DEV_RX_OFFLOAD_OUTER_UDP_CKSUM offload is available.
+ */
+#define PKT_RX_OUTER_L4_CKSUM_MASK     ((1ULL << 21) | (1ULL << 22))
+
+#define PKT_RX_OUTER_L4_CKSUM_UNKNOWN  0
+#define PKT_RX_OUTER_L4_CKSUM_BAD      (1ULL << 21)
+#define PKT_RX_OUTER_L4_CKSUM_GOOD     (1ULL << 22)
+#define PKT_RX_OUTER_L4_CKSUM_INVALID  ((1ULL << 21) | (1ULL << 22))
+
 /* add new RX flags here */
 
 /* add new TX flags here */
 
+/**
+ * Indicate that the metadata field in the mbuf is in use.
+ */
+#define PKT_TX_METADATA        (1ULL << 40)
+
+/**
+ * Outer UDP checksum offload flag. This flag is used for enabling
+ * outer UDP checksum in PMD. To use outer UDP checksum, the user needs to
+ * 1) Enable the following in mbuff,
+ * a) Fill outer_l2_len and outer_l3_len in mbuf.
+ * b) Set the PKT_TX_OUTER_UDP_CKSUM flag.
+ * c) Set the PKT_TX_OUTER_IPV4 or PKT_TX_OUTER_IPV6 flag.
+ * 2) Configure DEV_TX_OFFLOAD_OUTER_UDP_CKSUM offload flag.
+ */
+#define PKT_TX_OUTER_UDP_CKSUM     (1ULL << 41)
+
 /**
  * UDP Fragmentation Offload flag. This flag is used for enabling UDP
  * fragmentation in SW or in HW. When use UFO, mbuf->tso_segsz is used
@@ -334,16 +370,23 @@ extern "C" {
  * which can be set for packet.
  */
 #define PKT_TX_OFFLOAD_MASK (    \
+               PKT_TX_OUTER_IPV6 |      \
+               PKT_TX_OUTER_IPV4 |      \
+               PKT_TX_OUTER_IP_CKSUM |  \
+               PKT_TX_VLAN_PKT |        \
+               PKT_TX_IPV6 |            \
+               PKT_TX_IPV4 |            \
                PKT_TX_IP_CKSUM |        \
                PKT_TX_L4_MASK |         \
-               PKT_TX_OUTER_IP_CKSUM |  \
-               PKT_TX_TCP_SEG |         \
                PKT_TX_IEEE1588_TMST |   \
+               PKT_TX_TCP_SEG |         \
                PKT_TX_QINQ_PKT |        \
-               PKT_TX_VLAN_PKT |        \
                PKT_TX_TUNNEL_MASK |     \
                PKT_TX_MACSEC |          \
-               PKT_TX_SEC_OFFLOAD)
+               PKT_TX_SEC_OFFLOAD |     \
+               PKT_TX_UDP_SEG |         \
+               PKT_TX_OUTER_UDP_CKSUM | \
+               PKT_TX_METADATA)
 
 /**
  * Mbuf having an external buffer attached. shinfo in mbuf must be filled.
@@ -464,7 +507,9 @@ struct rte_mbuf {
        };
        uint16_t nb_segs;         /**< Number of segments. */
 
-       /** Input port (16 bits to support more than 256 virtual ports). */
+       /** Input port (16 bits to support more than 256 virtual ports).
+        * The event eth Tx adapter uses this field to specify the output port.
+        */
        uint16_t port;
 
        uint64_t ol_flags;        /**< Offload features. */
@@ -511,28 +556,47 @@ struct rte_mbuf {
        /** VLAN TCI (CPU order), valid if PKT_RX_VLAN is set. */
        uint16_t vlan_tci;
 
+       RTE_STD_C11
        union {
-               uint32_t rss;     /**< RSS hash result if RSS enabled */
-               struct {
-                       RTE_STD_C11
-                       union {
-                               struct {
-                                       uint16_t hash;
-                                       uint16_t id;
+               union {
+                       uint32_t rss;     /**< RSS hash result if RSS enabled */
+                       struct {
+                               union {
+                                       struct {
+                                               uint16_t hash;
+                                               uint16_t id;
+                                       };
+                                       uint32_t lo;
+                                       /**< Second 4 flexible bytes */
                                };
+                               uint32_t hi;
+                               /**< First 4 flexible bytes or FD ID, dependent
+                                * on PKT_RX_FDIR_* flag in ol_flags.
+                                */
+                       } fdir; /**< Filter identifier if FDIR enabled */
+                       struct {
                                uint32_t lo;
-                               /**< Second 4 flexible bytes */
-                       };
-                       uint32_t hi;
-                       /**< First 4 flexible bytes or FD ID, dependent on
-                            PKT_RX_FDIR_* flag in ol_flags. */
-               } fdir;           /**< Filter identifier if FDIR enabled */
+                               uint32_t hi;
+                               /**< The event eth Tx adapter uses this field
+                                * to store Tx queue id.
+                                * @see rte_event_eth_tx_adapter_txq_set()
+                                */
+                       } sched;          /**< Hierarchical scheduler */
+                       /**< User defined tags. See rte_distributor_process() */
+                       uint32_t usr;
+               } hash;                   /**< hash information */
                struct {
-                       uint32_t lo;
-                       uint32_t hi;
-               } sched;          /**< Hierarchical scheduler */
-               uint32_t usr;     /**< User defined tags. See rte_distributor_process() */
-       } hash;                   /**< hash information */
+                       /**
+                        * Application specific metadata value
+                        * for egress flow rule match.
+                        * Valid if PKT_TX_METADATA is set.
+                        * Located here to allow conjunct use
+                        * with hash.sched.hi.
+                        */
+                       uint32_t tx_metadata;
+                       uint32_t reserved;
+               };
+       };
 
        /** Outer VLAN TCI (CPU order), valid if PKT_RX_QINQ is set. */
        uint16_t vlan_tci_outer;
@@ -728,6 +792,24 @@ rte_mbuf_to_baddr(struct rte_mbuf *md)
        return buffer_addr;
 }
 
+/**
+ * Return the starting address of the private data area embedded in
+ * the given mbuf.
+ *
+ * Note that no check is made to ensure that a private data area
+ * actually exists in the supplied mbuf.
+ *
+ * @param m
+ *   The pointer to the mbuf.
+ * @return
+ *   The starting address of the private data area of the given mbuf.
+ */
+static inline void * __rte_experimental
+rte_mbuf_to_priv(struct rte_mbuf *m)
+{
+       return RTE_PTR_ADD(m, sizeof(struct rte_mbuf));
+}
+
 /**
  * Returns TRUE if given mbuf is cloned by mbuf indirection, or FALSE
  * otherwise.
@@ -738,7 +820,8 @@ rte_mbuf_to_baddr(struct rte_mbuf *md)
 #define RTE_MBUF_CLONED(mb)     ((mb)->ol_flags & IND_ATTACHED_MBUF)
 
 /**
- * Returns TRUE if given mbuf is indirect, or FALSE otherwise.
+ * Deprecated.
+ * Use RTE_MBUF_CLONED().
  */
 #define RTE_MBUF_INDIRECT(mb)   RTE_MBUF_CLONED(mb)
 
@@ -1019,14 +1102,6 @@ rte_mbuf_raw_free(struct rte_mbuf *m)
        rte_mempool_put(m->pool, m);
 }
 
-/* compat with older versions */
-__rte_deprecated
-static inline void
-__rte_mbuf_raw_free(struct rte_mbuf *m)
-{
-       rte_mbuf_raw_free(m);
-}
-
 /**
  * The packet mbuf constructor.
  *
@@ -1145,7 +1220,7 @@ rte_pktmbuf_pool_create(const char *name, unsigned n,
  *    - EEXIST - a memzone with the same name already exists
  *    - ENOMEM - no appropriate memory area found in which to create memzone
  */
-struct rte_mempool * __rte_experimental
+struct rte_mempool *
 rte_pktmbuf_pool_create_by_ops(const char *name, unsigned int n,
        unsigned int cache_size, uint16_t priv_size, uint16_t data_room_size,
        int socket_id, const char *ops_name);
@@ -1639,14 +1714,6 @@ rte_pktmbuf_prefree_seg(struct rte_mbuf *m)
        return NULL;
 }
 
-/* deprecated, replaced by rte_pktmbuf_prefree_seg() */
-__rte_deprecated
-static inline struct rte_mbuf *
-__rte_pktmbuf_prefree_seg(struct rte_mbuf *m)
-{
-       return rte_pktmbuf_prefree_seg(m);
-}
-
 /**
  * Free a segment of a packet mbuf into its original mempool.
  *
@@ -1908,7 +1975,10 @@ static inline char *rte_pktmbuf_prepend(struct rte_mbuf *m,
        if (unlikely(len > rte_pktmbuf_headroom(m)))
                return NULL;
 
-       m->data_off -= len;
+       /* NB: elaborating the subtraction like this instead of using
+        *     -= allows us to ensure the result type is uint16_t
+        *     avoiding compiler warnings on gcc 8.1 at least */
+       m->data_off = (uint16_t)(m->data_off - len);
        m->data_len = (uint16_t)(m->data_len + len);
        m->pkt_len  = (m->pkt_len + len);
 
@@ -1968,8 +2038,11 @@ static inline char *rte_pktmbuf_adj(struct rte_mbuf *m, uint16_t len)
        if (unlikely(len > m->data_len))
                return NULL;
 
+       /* NB: elaborating the addition like this instead of using
+        *     += allows us to ensure the result type is uint16_t
+        *     avoiding compiler warnings on gcc 8.1 at least */
        m->data_len = (uint16_t)(m->data_len - len);
-       m->data_off += len;
+       m->data_off = (uint16_t)(m->data_off + len);
        m->pkt_len  = (m->pkt_len - len);
        return (char *)m->buf_addr + m->data_off;
 }
@@ -2081,8 +2154,11 @@ static inline int rte_pktmbuf_chain(struct rte_mbuf *head, struct rte_mbuf *tail
        cur_tail = rte_pktmbuf_lastseg(head);
        cur_tail->next = tail;
 
-       /* accumulate number of segments and total length. */
-       head->nb_segs += tail->nb_segs;
+       /* accumulate number of segments and total length.
+        * NB: elaborating the addition like this instead of using
+        *     -= allows us to ensure the result type is uint16_t
+        *     avoiding compiler warnings on gcc 8.1 at least */
+       head->nb_segs = (uint16_t)(head->nb_segs + tail->nb_segs);
        head->pkt_len += tail->pkt_len;
 
        /* pkt_len is only set in the head */
@@ -2112,7 +2188,11 @@ rte_validate_tx_offload(const struct rte_mbuf *m)
                return 0;
 
        if (ol_flags & PKT_TX_OUTER_IP_CKSUM)
-               inner_l3_offset += m->outer_l2_len + m->outer_l3_len;
+               /* NB: elaborating the addition like this instead of using
+                *     += gives the result uint64_t type instead of int,
+                *     avoiding compiler warnings on gcc 8.1 at least */
+               inner_l3_offset = 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)