mem: add external API to retrieve page fd
[dpdk.git] / lib / librte_mbuf / rte_mbuf.h
index eab13c6..a50b05c 100644 (file)
@@ -728,6 +728,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 +756,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)
 
@@ -806,7 +825,7 @@ rte_mbuf_refcnt_read(const struct rte_mbuf *m)
 static inline void
 rte_mbuf_refcnt_set(struct rte_mbuf *m, uint16_t new_value)
 {
-       rte_atomic16_set(&m->refcnt_atomic, new_value);
+       rte_atomic16_set(&m->refcnt_atomic, (int16_t)new_value);
 }
 
 /* internal */
@@ -836,8 +855,9 @@ rte_mbuf_refcnt_update(struct rte_mbuf *m, int16_t value)
         * reference counter can occur.
         */
        if (likely(rte_mbuf_refcnt_read(m) == 1)) {
-               rte_mbuf_refcnt_set(m, 1 + value);
-               return 1 + value;
+               ++value;
+               rte_mbuf_refcnt_set(m, (uint16_t)value);
+               return (uint16_t)value;
        }
 
        return __rte_mbuf_refcnt_update(m, value);
@@ -908,7 +928,7 @@ static inline void
 rte_mbuf_ext_refcnt_set(struct rte_mbuf_ext_shared_info *shinfo,
        uint16_t new_value)
 {
-       rte_atomic16_set(&shinfo->refcnt_atomic, new_value);
+       rte_atomic16_set(&shinfo->refcnt_atomic, (int16_t)new_value);
 }
 
 /**
@@ -927,8 +947,9 @@ rte_mbuf_ext_refcnt_update(struct rte_mbuf_ext_shared_info *shinfo,
        int16_t value)
 {
        if (likely(rte_mbuf_ext_refcnt_read(shinfo) == 1)) {
-               rte_mbuf_ext_refcnt_set(shinfo, 1 + value);
-               return 1 + value;
+               ++value;
+               rte_mbuf_ext_refcnt_set(shinfo, (uint16_t)value);
+               return (uint16_t)value;
        }
 
        return (uint16_t)rte_atomic16_add_return(&shinfo->refcnt_atomic, value);
@@ -1017,14 +1038,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.
  *
@@ -1143,7 +1156,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);
@@ -1199,7 +1212,8 @@ rte_pktmbuf_priv_size(struct rte_mempool *mp)
  */
 static inline void rte_pktmbuf_reset_headroom(struct rte_mbuf *m)
 {
-       m->data_off = RTE_MIN(RTE_PKTMBUF_HEADROOM, (uint16_t)m->buf_len);
+       m->data_off = (uint16_t)RTE_MIN((uint16_t)RTE_PKTMBUF_HEADROOM,
+                                       (uint16_t)m->buf_len);
 }
 
 /**
@@ -1357,7 +1371,7 @@ rte_pktmbuf_ext_shinfo_init_helper(void *buf_addr, uint16_t *buf_len,
        shinfo->fcb_opaque = fcb_opaque;
        rte_mbuf_ext_refcnt_set(shinfo, 1);
 
-       *buf_len = RTE_PTR_DIFF(shinfo, buf_addr);
+       *buf_len = (uint16_t)RTE_PTR_DIFF(shinfo, buf_addr);
        return shinfo;
 }
 
@@ -1568,7 +1582,8 @@ __rte_pktmbuf_free_direct(struct rte_mbuf *m)
 static inline void rte_pktmbuf_detach(struct rte_mbuf *m)
 {
        struct rte_mempool *mp = m->pool;
-       uint32_t mbuf_size, buf_len, priv_size;
+       uint32_t mbuf_size, buf_len;
+       uint16_t priv_size;
 
        if (RTE_MBUF_HAS_EXTBUF(m))
                __rte_pktmbuf_free_extbuf(m);
@@ -1576,7 +1591,7 @@ static inline void rte_pktmbuf_detach(struct rte_mbuf *m)
                __rte_pktmbuf_free_direct(m);
 
        priv_size = rte_pktmbuf_priv_size(mp);
-       mbuf_size = sizeof(struct rte_mbuf) + priv_size;
+       mbuf_size = (uint32_t)(sizeof(struct rte_mbuf) + priv_size);
        buf_len = rte_pktmbuf_data_room_size(mp);
 
        m->priv_size = priv_size;
@@ -1635,14 +1650,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.
  *
@@ -1904,7 +1911,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);
 
@@ -1964,8 +1974,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;
 }
@@ -2077,8 +2090,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 */
@@ -2108,7 +2124,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)
@@ -2153,7 +2173,7 @@ rte_validate_tx_offload(const struct rte_mbuf *m)
 static inline int
 rte_pktmbuf_linearize(struct rte_mbuf *mbuf)
 {
-       int seg_len, copy_len;
+       size_t seg_len, copy_len;
        struct rte_mbuf *m;
        struct rte_mbuf *m_next;
        char *buffer;