#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
/* 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 {
+ MARKER cacheline0;
+
void *buf_addr; /**< Virtual address of segment buffer. */
phys_addr_t buf_physaddr; /**< Physical address of segment buffer. */
/* next 8 bytes are initialised on RX descriptor rearm */
+ MARKER64 rearm_data;
uint16_t buf_len; /**< Length of segment buffer. */
uint16_t data_off;
-#ifdef RTE_MBUF_REFCNT
/**
* 16-bit Reference counter.
* It should only be accessed using the following functions:
* 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
- uint8_t nb_segs; /**< Number of segments. */
- uint8_t port; /**< Input port. */
+ uint16_t refcnt_reserved; /**< Do not use this field */
+ };
+ uint8_t nb_segs; /**< Number of segments. */
+ uint8_t port; /**< Input port. */
- uint64_t ol_flags; /**< Offload features. */
+ uint64_t ol_flags; /**< Offload features. */
/* remaining bytes are set on RX when pulling packet from descriptor */
- 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. */
+ 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 {
- uint16_t l2_l3_len; /**< combined l2/l3 lengths as single var */
- struct {
- uint16_t l3_len:9; /**< L3 (IP) Header Length. */
- 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 */
+ 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 */
+ } 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 */
+ };
- /* fields only used in slow path or on TX */
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 {
- uint8_t metadata[0];
- uint16_t metadata16[0];
- uint32_t metadata32[0];
- uint64_t metadata64[0];
- } __rte_cache_aligned;
+ uint16_t l2_l3_len; /**< combined l2/l3 lengths as single var */
+ struct {
+ uint16_t l3_len:9; /**< L3 (IP) Header Length. */
+ uint16_t l2_len:7; /**< L2 (MAC) Header Length. */
+ };
+ };
} __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.
*/
*/
#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 */
/**
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);
+ }
}
/**