aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--platform/linux-dpdk/include/odp/packet.h52
-rw-r--r--platform/linux-dpdk/odp_packet.c29
2 files changed, 34 insertions, 47 deletions
diff --git a/platform/linux-dpdk/include/odp/packet.h b/platform/linux-dpdk/include/odp/packet.h
index 4b15397e7..dc8df8798 100644
--- a/platform/linux-dpdk/include/odp/packet.h
+++ b/platform/linux-dpdk/include/odp/packet.h
@@ -28,59 +28,47 @@ extern "C" {
* @{
*/
+extern const unsigned int buf_addr_offset;
+extern const unsigned int data_off_offset;
extern const unsigned int pkt_len_offset;
+extern const unsigned int seg_len_offset;
extern const unsigned int udata_len_offset;
extern const unsigned int udata_offset;
-/**
- * Packet data length
- *
- * Returns sum of data lengths over all packet segments.
- *
- * @param pkt Packet handle
- *
- * @return Packet data length
- *
- * NOTE: This function is inlined because it's on a performance hot path. As we
- * can't force the application to directly include DPDK headers we have to
- * export this field through pkt_len_offset. It is calculated compile time in
+/*
+ * NOTE: These functions are inlined because they are on a performance hot path.
+ * As we can't force the application to directly include DPDK headers we have to
+ * export these fields through constants calculated compile time in
* odp_packet.c, where we can see the DPDK definitions.
+ *
*/
static inline uint32_t odp_packet_len(odp_packet_t pkt)
{
return *(uint32_t *)((char *)pkt + pkt_len_offset);
}
-/**
- * User area address
- *
- * Each packet has an area for user data. Size of the area is fixed and defined
- * in packet pool parameters.
- *
- * @param pkt Packet handle
- *
- * @return User area address associated with the packet
- * @retval NULL The packet does not have user area
- */
+static inline uint32_t odp_packet_seg_len(odp_packet_t pkt)
+{
+ return *(uint32_t *)((char *)pkt + seg_len_offset);
+}
+
static inline void *odp_packet_user_area(odp_packet_t pkt)
{
return (void *)((char *)pkt + udata_offset);
}
-/**
- * User area size
- *
- * The size is fixed and defined in packet pool parameters.
- *
- * @param pkt Packet handle
- *
- * @return User area size in bytes
- */
static inline uint32_t odp_packet_user_area_size(odp_packet_t pkt)
{
return *(uint32_t *)((char *)pkt + udata_len_offset);
}
+static inline void *odp_packet_data(odp_packet_t pkt)
+{
+ char** buf_addr = (char **)((char *)pkt + buf_addr_offset);
+ uint16_t data_off = *(uint16_t *)((char *)pkt + data_off_offset);
+ return (void *)(*buf_addr + data_off);
+}
+
/**
* @}
diff --git a/platform/linux-dpdk/odp_packet.c b/platform/linux-dpdk/odp_packet.c
index e3ac9d4d0..81601e05e 100644
--- a/platform/linux-dpdk/odp_packet.c
+++ b/platform/linux-dpdk/odp_packet.c
@@ -19,13 +19,24 @@
#include <stdio.h>
#include <stddef.h>
-/* This is the offset for packet length inside odp_packet_t. The last bit is an
- * expanded version of offsetof(), to make sure that if rte_pktmbuf_pkt_len()
- * changes, we will either adapt automatically, or throw a compile failure
+/* These are the offsets for packet accessors for inlining. */
+const unsigned int buf_addr_offset = offsetof(odp_packet_hdr_t, buf_hdr) +
+ offsetof(struct odp_buffer_hdr_t, mb) +
+ offsetof(struct rte_mbuf, buf_addr);
+const unsigned int data_off_offset = offsetof(odp_packet_hdr_t, buf_hdr) +
+ offsetof(struct odp_buffer_hdr_t, mb) +
+ offsetof(struct rte_mbuf, data_off);
+
+/* The last bit is an expanded version of offsetof(), to make sure that if
+ * rte_pktmbuf_[pkt|data]_len() changes, we will either adapt automatically, or
+ * throw a compile failure
*/
const unsigned int pkt_len_offset = offsetof(odp_packet_hdr_t, buf_hdr) +
offsetof(struct odp_buffer_hdr_t, mb) +
(size_t)&rte_pktmbuf_pkt_len((struct rte_mbuf *)0);
+const unsigned int seg_len_offset = offsetof(odp_packet_hdr_t, buf_hdr) +
+ offsetof(struct odp_buffer_hdr_t, mb) +
+ (size_t)&rte_pktmbuf_data_len((struct rte_mbuf *)0);
const unsigned int udata_len_offset = offsetof(odp_packet_hdr_t, uarea_size);
const unsigned int udata_offset = sizeof(odp_packet_hdr_t);
@@ -157,18 +168,6 @@ void *odp_packet_head(odp_packet_t pkt)
return odp_buffer_addr(_odp_packet_to_buffer(pkt));
}
-void *odp_packet_data(odp_packet_t pkt)
-{
- struct rte_mbuf *mb = &(odp_packet_hdr(pkt)->buf_hdr.mb);
- return rte_pktmbuf_mtod(mb, void *);
-}
-
-uint32_t odp_packet_seg_len(odp_packet_t pkt)
-{
- struct rte_mbuf *mb = &(odp_packet_hdr(pkt)->buf_hdr.mb);
- return rte_pktmbuf_data_len(mb);
-}
-
uint32_t odp_packet_headroom(odp_packet_t pkt)
{
struct rte_mbuf *mb = &(odp_packet_hdr(pkt)->buf_hdr.mb);