mbuf: switch vlan_tci and reserved2 fields
[dpdk.git] / lib / librte_mbuf / rte_mbuf.h
index 71080e5..68304cc 100644 (file)
@@ -91,6 +91,7 @@ extern "C" {
 #define PKT_TX_IPV4_CSUM     0x1000 /**< Alias of PKT_TX_IP_CKSUM. */
 #define PKT_TX_IPV4          PKT_RX_IPV4_HDR /**< IPv4 with no IP checksum offload. */
 #define PKT_TX_IPV6          PKT_RX_IPV6_HDR /**< IPv6 packet */
+
 /*
  * Bit 14~13 used for L4 packet type with checksum enabled.
  *     00: Reserved
@@ -106,27 +107,33 @@ extern "C" {
 /* Bit 15 */
 #define PKT_TX_IEEE1588_TMST 0x8000 /**< TX IEEE1588 packet to timestamp. */
 
+/* Use final bit of flags to indicate a control mbuf */
+#define CTRL_MBUF_FLAG       (1ULL << 63)
+
 /**
  * Bit Mask to indicate what bits required for building TX context
  */
 #define PKT_TX_OFFLOAD_MASK (PKT_TX_VLAN_PKT | PKT_TX_IP_CKSUM | PKT_TX_L4_MASK)
 
+/* define a set of marker types that can be used to refer to set points in the
+ * mbuf */
+typedef void    *MARKER[0];   /**< generic marker for a point in a structure */
+typedef uint64_t MARKER64[0]; /**< marker that allows us to overwrite 8 bytes
+                               * with a single assignment */
 /**
  * The generic rte_mbuf, containing a packet mbuf.
  */
 struct rte_mbuf {
-       struct rte_mempool *pool; /**< Pool from which mbuf was allocated. */
+       MARKER cacheline0;
+
        void *buf_addr;           /**< Virtual address of segment buffer. */
        phys_addr_t buf_physaddr; /**< Physical address of segment buffer. */
-       uint16_t buf_len;         /**< Length of segment buffer. */
 
-       /* valid for any segment */
-       struct rte_mbuf *next;    /**< Next segment of scattered packet. */
+       /* next 8 bytes are initialised on RX descriptor rearm */
+       MARKER64 rearm_data;
+       uint16_t buf_len;         /**< Length of segment buffer. */
        uint16_t data_off;
-       uint16_t data_len;        /**< Amount of data in segment buffer. */
-       uint32_t pkt_len;         /**< Total pkt len: sum of all segments. */
 
-#ifdef RTE_MBUF_REFCNT
        /**
         * 16-bit Reference counter.
         * It should only be accessed using the following functions:
@@ -136,20 +143,45 @@ struct rte_mbuf {
         * config option.
         */
        union {
-               rte_atomic16_t refcnt_atomic;   /**< Atomically accessed refcnt */
-               uint16_t refcnt;                /**< Non-atomically accessed refcnt */
-       };
-#else
-       uint16_t refcnt_reserved;     /**< Do not use this field */
+#ifdef RTE_MBUF_REFCNT
+               rte_atomic16_t refcnt_atomic; /**< Atomically accessed refcnt */
+               uint16_t refcnt;              /**< Non-atomically accessed refcnt */
 #endif
-       uint16_t reserved;            /**< Unused field. Required for padding */
-       uint16_t ol_flags;            /**< Offload features. */
+               uint16_t refcnt_reserved;     /**< Do not use this field */
+       };
+       uint8_t nb_segs;          /**< Number of segments. */
+       uint8_t port;             /**< Input port. */
 
-       /* these fields are valid for first segment only */
-       uint8_t nb_segs;        /**< Number of segments. */
-       uint8_t port;           /**< Input port. */
+       uint64_t ol_flags;        /**< Offload features. */
 
-       /* offload features, valid for first segment only */
+       /* remaining bytes are set on RX when pulling packet from descriptor */
+       MARKER rx_descriptor_fields1;
+       uint16_t reserved2;       /**< Unused field. Required for padding */
+       uint16_t data_len;        /**< Amount of data in segment buffer. */
+       uint32_t pkt_len;         /**< Total pkt len: sum of all segments. */
+       uint16_t vlan_tci;        /**< VLAN Tag Control Identifier (CPU order) */
+       uint16_t reserved;
+       union {
+               uint32_t rss;     /**< RSS hash result if RSS enabled */
+               struct {
+                       uint16_t hash;
+                       uint16_t id;
+               } fdir;           /**< Filter identifier if FDIR enabled */
+               uint32_t sched;   /**< Hierarchical scheduler */
+       } hash;                   /**< hash information */
+
+       /* second cache line - fields only used in slow path or on TX */
+       MARKER cacheline1 __rte_cache_aligned;
+
+       union {
+               void *userdata;   /**< Can be used for external metadata */
+               uint64_t udata64; /**< Allow 8-byte userdata on 32-bit */
+       };
+
+       struct rte_mempool *pool; /**< Pool from which mbuf was allocated. */
+       struct rte_mbuf *next;    /**< Next segment of scattered packet. */
+
+       /* fields to support TX offloads */
        union {
                uint16_t l2_l3_len; /**< combined l2/l3 lengths as single var */
                struct {
@@ -157,42 +189,8 @@ struct rte_mbuf {
                        uint16_t l2_len:7;      /**< L2 (MAC) Header Length. */
                };
        };
-       uint16_t vlan_tci;      /**< VLAN Tag Control Identifier (CPU order). */
-       union {
-               uint32_t rss;       /**< RSS hash result if RSS enabled */
-               struct {
-                       uint16_t hash;
-                       uint16_t id;
-               } fdir;             /**< Filter identifier if FDIR enabled */
-               uint32_t sched;     /**< Hierarchical scheduler */
-       } hash;                 /**< hash information */
-
-       union {
-               uint8_t metadata[0];
-               uint16_t metadata16[0];
-               uint32_t metadata32[0];
-               uint64_t metadata64[0];
-       } __rte_cache_aligned;
 } __rte_cache_aligned;
 
-#define RTE_MBUF_METADATA_UINT8(mbuf, offset)              \
-       (mbuf->metadata[offset])
-#define RTE_MBUF_METADATA_UINT16(mbuf, offset)             \
-       (mbuf->metadata16[offset/sizeof(uint16_t)])
-#define RTE_MBUF_METADATA_UINT32(mbuf, offset)             \
-       (mbuf->metadata32[offset/sizeof(uint32_t)])
-#define RTE_MBUF_METADATA_UINT64(mbuf, offset)             \
-       (mbuf->metadata64[offset/sizeof(uint64_t)])
-
-#define RTE_MBUF_METADATA_UINT8_PTR(mbuf, offset)          \
-       (&mbuf->metadata[offset])
-#define RTE_MBUF_METADATA_UINT16_PTR(mbuf, offset)         \
-       (&mbuf->metadata16[offset/sizeof(uint16_t)])
-#define RTE_MBUF_METADATA_UINT32_PTR(mbuf, offset)         \
-       (&mbuf->metadata32[offset/sizeof(uint32_t)])
-#define RTE_MBUF_METADATA_UINT64_PTR(mbuf, offset)         \
-       (&mbuf->metadata64[offset/sizeof(uint64_t)])
-
 /**
  * Given the buf_addr returns the pointer to corresponding mbuf.
  */
@@ -470,6 +468,21 @@ void rte_ctrlmbuf_init(struct rte_mempool *mp, void *opaque_arg,
  */
 #define rte_ctrlmbuf_len(m) rte_pktmbuf_data_len(m)
 
+/**
+ * Tests if an mbuf is a control mbuf
+ *
+ * @param m
+ *   The mbuf to be tested
+ * @return
+ *   - True (1) if the mbuf is a control mbuf
+ *   - False(0) otherwise
+ */
+static inline int
+rte_is_ctrlmbuf(struct rte_mbuf *m)
+{
+       return (!!(m->ol_flags & CTRL_MBUF_FLAG));
+}
+
 /* Operations on pkt mbuf */
 
 /**
@@ -675,8 +688,10 @@ __rte_pktmbuf_prefree_seg(struct rte_mbuf *m)
 static inline void __attribute__((always_inline))
 rte_pktmbuf_free_seg(struct rte_mbuf *m)
 {
-       if (likely(NULL != (m = __rte_pktmbuf_prefree_seg(m))))
+       if (likely(NULL != (m = __rte_pktmbuf_prefree_seg(m)))) {
+               m->next = NULL;
                __rte_mbuf_raw_free(m);
+       }
 }
 
 /**