bus/vmbus: map ring in secondary process
[dpdk.git] / lib / librte_mbuf / rte_mbuf.h
index de9c656..d961cca 100644 (file)
@@ -791,7 +791,55 @@ rte_mbuf_from_indirect(struct rte_mbuf *mi)
 }
 
 /**
- * Return the buffer address embedded in the given mbuf.
+ * Return address of buffer embedded in the given mbuf.
+ *
+ * The return value shall be same as mb->buf_addr if the mbuf is already
+ * initialized and direct. However, this API is useful if mempool of the
+ * mbuf is already known because it doesn't need to access mbuf contents in
+ * order to get the mempool pointer.
+ *
+ * @warning
+ * @b EXPERIMENTAL: This API may change without prior notice.
+ * This will be used by rte_mbuf_to_baddr() which has redundant code once
+ * experimental tag is removed.
+ *
+ * @param mb
+ *   The pointer to the mbuf.
+ * @param mp
+ *   The pointer to the mempool of the mbuf.
+ * @return
+ *   The pointer of the mbuf buffer.
+ */
+static inline char * __rte_experimental
+rte_mbuf_buf_addr(struct rte_mbuf *mb, struct rte_mempool *mp)
+{
+       return (char *)mb + sizeof(*mb) + rte_pktmbuf_priv_size(mp);
+}
+
+/**
+ * Return the default address of the beginning of the mbuf data.
+ *
+ * @warning
+ * @b EXPERIMENTAL: This API may change without prior notice.
+ *
+ * @param mb
+ *   The pointer to the mbuf.
+ * @return
+ *   The pointer of the beginning of the mbuf data.
+ */
+static inline char * __rte_experimental
+rte_mbuf_data_addr_default(struct rte_mbuf *mb)
+{
+       return rte_mbuf_buf_addr(mb, mb->pool) + RTE_PKTMBUF_HEADROOM;
+}
+
+/**
+ * Return address of buffer embedded in the given mbuf.
+ *
+ * @note: Accessing mempool pointer of a mbuf is expensive because the
+ * pointer is stored in the 2nd cache line of mbuf. If mempool is known, it
+ * is better not to reference the mempool pointer in mbuf but calling
+ * rte_mbuf_buf_addr() would be more efficient.
  *
  * @param md
  *   The pointer to the mbuf.
@@ -801,9 +849,13 @@ rte_mbuf_from_indirect(struct rte_mbuf *mi)
 static inline char *
 rte_mbuf_to_baddr(struct rte_mbuf *md)
 {
+#ifdef ALLOW_EXPERIMENTAL_API
+       return rte_mbuf_buf_addr(md, md->pool);
+#else
        char *buffer_addr;
        buffer_addr = (char *)md + sizeof(*md) + rte_pktmbuf_priv_size(md->pool);
        return buffer_addr;
+#endif
 }
 
 /**
@@ -921,7 +973,7 @@ rte_mbuf_refcnt_update(struct rte_mbuf *m, int16_t value)
 {
        /*
         * The atomic_add is an expensive operation, so we don't want to
-        * call it in the case where we know we are the uniq holder of
+        * call it in the case where we know we are the unique holder of
         * this mbuf (i.e. ref_cnt == 1). Otherwise, an atomic
         * operation has to be used because concurrent accesses on the
         * reference counter can occur.
@@ -1049,6 +1101,29 @@ rte_mbuf_ext_refcnt_update(struct rte_mbuf_ext_shared_info *shinfo,
 void
 rte_mbuf_sanity_check(const struct rte_mbuf *m, int is_header);
 
+/**
+ * Sanity checks on a mbuf.
+ *
+ * Almost like rte_mbuf_sanity_check(), but this function gives the reason
+ * if corruption is detected rather than panic.
+ *
+ * @param m
+ *   The mbuf to be checked.
+ * @param is_header
+ *   True if the mbuf is a packet header, false if it is a sub-segment
+ *   of a packet (in this case, some fields like nb_segs are not checked)
+ * @param reason
+ *   A reference to a string pointer where to store the reason why a mbuf is
+ *   considered invalid.
+ * @return
+ *   - 0 if no issue has been found, reason is left untouched.
+ *   - -1 if a problem is detected, reason then points to a string describing
+ *     the reason why the mbuf is deemed invalid.
+ */
+__rte_experimental
+int rte_mbuf_check(const struct rte_mbuf *m, int is_header,
+                  const char **reason);
+
 #define MBUF_RAW_ALLOC_CHECK(m) do {                           \
        RTE_ASSERT(rte_mbuf_refcnt_read(m) == 1);               \
        RTE_ASSERT((m)->next == NULL);                          \
@@ -2389,6 +2464,7 @@ rte_mbuf_sched_set(struct rte_mbuf *m, uint32_t queue_id,
                                .queue_id = queue_id,
                                .traffic_class = traffic_class,
                                .color = color,
+                               .reserved = 0,
                        };
 }