diff mbox series

[v1,1/2] linux-gen: packet: inline layer offsets

Message ID 1513872010-2747-2-git-send-email-odpbot@yandex.ru
State Superseded
Headers show
Series [v1,1/2] linux-gen: packet: inline layer offsets | expand

Commit Message

Github ODP bot Dec. 21, 2017, 4 p.m. UTC
From: Petri Savolainen <petri.savolainen@linaro.org>


Inline L2/L3/L4 offset read functions. Always use the inlined
version within the implementation itself.

Signed-off-by: Petri Savolainen <petri.savolainen@linaro.org>

---
/** Email created from pull request 360 (psavol:master-packet-offset-inline)
 ** https://github.com/Linaro/odp/pull/360
 ** Patch: https://github.com/Linaro/odp/pull/360.patch
 ** Base sha: 3c02836d9d9ca16b1277bdd30e523779b9fe8374
 ** Merge commit sha: 8a43dcccb105ee32ad867e39b8763d77c37b331e
 **/
 .../include/odp/api/plat/packet_inlines.h          | 18 +++++++++++++++
 .../include/odp/api/plat/packet_inlines_api.h      | 15 +++++++++++++
 .../include/odp/api/plat/packet_types.h            |  6 +++++
 platform/linux-generic/odp_packet.c                | 26 +++-------------------
 platform/linux-generic/odp_traffic_mngr.c          |  5 +++--
 5 files changed, 45 insertions(+), 25 deletions(-)
diff mbox series

Patch

diff --git a/platform/linux-generic/include/odp/api/plat/packet_inlines.h b/platform/linux-generic/include/odp/api/plat/packet_inlines.h
index c808f2d6f..aa9ba812f 100644
--- a/platform/linux-generic/include/odp/api/plat/packet_inlines.h
+++ b/platform/linux-generic/include/odp/api/plat/packet_inlines.h
@@ -108,6 +108,24 @@  static inline uint32_t _odp_packet_user_area_size(odp_packet_t pkt)
 	return _odp_pool_get(pool, uint32_t, uarea_size);
 }
 
+/** @internal Inline function @param pkt @return */
+static inline uint32_t _odp_packet_l2_offset(odp_packet_t pkt)
+{
+	return _odp_pkt_get(pkt, uint16_t, l2_offset);
+}
+
+/** @internal Inline function @param pkt @return */
+static inline uint32_t _odp_packet_l3_offset(odp_packet_t pkt)
+{
+	return _odp_pkt_get(pkt, uint16_t, l3_offset);
+}
+
+/** @internal Inline function @param pkt @return */
+static inline uint32_t _odp_packet_l4_offset(odp_packet_t pkt)
+{
+	return _odp_pkt_get(pkt, uint16_t, l4_offset);
+}
+
 /** @internal Inline function @param pkt @return */
 static inline uint32_t _odp_packet_flow_hash(odp_packet_t pkt)
 {
diff --git a/platform/linux-generic/include/odp/api/plat/packet_inlines_api.h b/platform/linux-generic/include/odp/api/plat/packet_inlines_api.h
index 233bc8761..84b4f08ab 100644
--- a/platform/linux-generic/include/odp/api/plat/packet_inlines_api.h
+++ b/platform/linux-generic/include/odp/api/plat/packet_inlines_api.h
@@ -68,6 +68,21 @@  _ODP_INLINE uint32_t odp_packet_user_area_size(odp_packet_t pkt)
 	return _odp_packet_user_area_size(pkt);
 }
 
+_ODP_INLINE uint32_t odp_packet_l2_offset(odp_packet_t pkt)
+{
+	return _odp_packet_l2_offset(pkt);
+}
+
+_ODP_INLINE uint32_t odp_packet_l3_offset(odp_packet_t pkt)
+{
+	return _odp_packet_l3_offset(pkt);
+}
+
+_ODP_INLINE uint32_t odp_packet_l4_offset(odp_packet_t pkt)
+{
+	return _odp_packet_l4_offset(pkt);
+}
+
 _ODP_INLINE uint32_t odp_packet_flow_hash(odp_packet_t pkt)
 {
 	return _odp_packet_flow_hash(pkt);
diff --git a/platform/linux-generic/include/odp/api/plat/packet_types.h b/platform/linux-generic/include/odp/api/plat/packet_types.h
index 009a3aa7c..5b44c09c8 100644
--- a/platform/linux-generic/include/odp/api/plat/packet_types.h
+++ b/platform/linux-generic/include/odp/api/plat/packet_types.h
@@ -94,6 +94,12 @@  typedef struct _odp_packet_inline_offset_t {
 	/** @internal field offset */
 	uint16_t user_area;
 	/** @internal field offset */
+	uint16_t l2_offset;
+	/** @internal field offset */
+	uint16_t l3_offset;
+	/** @internal field offset */
+	uint16_t l4_offset;
+	/** @internal field offset */
 	uint16_t flow_hash;
 	/** @internal field offset */
 	uint16_t timestamp;
diff --git a/platform/linux-generic/odp_packet.c b/platform/linux-generic/odp_packet.c
index 04f1f33bb..3f0d764f6 100644
--- a/platform/linux-generic/odp_packet.c
+++ b/platform/linux-generic/odp_packet.c
@@ -37,6 +37,9 @@  const _odp_packet_inline_offset_t _odp_packet_inline ODP_ALIGNED_CACHE = {
 	.segcount       = offsetof(odp_packet_hdr_t, buf_hdr.segcount),
 	.user_ptr       = offsetof(odp_packet_hdr_t, buf_hdr.buf_ctx),
 	.user_area      = offsetof(odp_packet_hdr_t, buf_hdr.uarea_addr),
+	.l2_offset      = offsetof(odp_packet_hdr_t, p.l2_offset),
+	.l3_offset      = offsetof(odp_packet_hdr_t, p.l3_offset),
+	.l4_offset      = offsetof(odp_packet_hdr_t, p.l4_offset),
 	.flow_hash      = offsetof(odp_packet_hdr_t, flow_hash),
 	.timestamp      = offsetof(odp_packet_hdr_t, timestamp),
 	.input_flags    = offsetof(odp_packet_hdr_t, p.input_flags)
@@ -1213,15 +1216,6 @@  void *odp_packet_l2_ptr(odp_packet_t pkt, uint32_t *len)
 	return packet_map(pkt_hdr, pkt_hdr->p.l2_offset, len, NULL);
 }
 
-uint32_t odp_packet_l2_offset(odp_packet_t pkt)
-{
-	odp_packet_hdr_t *pkt_hdr = packet_hdr(pkt);
-
-	if (!packet_hdr_has_l2(pkt_hdr))
-		return ODP_PACKET_OFFSET_INVALID;
-	return pkt_hdr->p.l2_offset;
-}
-
 int odp_packet_l2_offset_set(odp_packet_t pkt, uint32_t offset)
 {
 	odp_packet_hdr_t *pkt_hdr = packet_hdr(pkt);
@@ -1241,13 +1235,6 @@  void *odp_packet_l3_ptr(odp_packet_t pkt, uint32_t *len)
 	return packet_map(pkt_hdr, pkt_hdr->p.l3_offset, len, NULL);
 }
 
-uint32_t odp_packet_l3_offset(odp_packet_t pkt)
-{
-	odp_packet_hdr_t *pkt_hdr = packet_hdr(pkt);
-
-	return pkt_hdr->p.l3_offset;
-}
-
 int odp_packet_l3_offset_set(odp_packet_t pkt, uint32_t offset)
 {
 	odp_packet_hdr_t *pkt_hdr = packet_hdr(pkt);
@@ -1266,13 +1253,6 @@  void *odp_packet_l4_ptr(odp_packet_t pkt, uint32_t *len)
 	return packet_map(pkt_hdr, pkt_hdr->p.l4_offset, len, NULL);
 }
 
-uint32_t odp_packet_l4_offset(odp_packet_t pkt)
-{
-	odp_packet_hdr_t *pkt_hdr = packet_hdr(pkt);
-
-	return pkt_hdr->p.l4_offset;
-}
-
 int odp_packet_l4_offset_set(odp_packet_t pkt, uint32_t offset)
 {
 	odp_packet_hdr_t *pkt_hdr = packet_hdr(pkt);
diff --git a/platform/linux-generic/odp_traffic_mngr.c b/platform/linux-generic/odp_traffic_mngr.c
index ab06b3c0d..e22a33f29 100644
--- a/platform/linux-generic/odp_traffic_mngr.c
+++ b/platform/linux-generic/odp_traffic_mngr.c
@@ -26,6 +26,7 @@ 
 #include <protocols/eth.h>
 #include <protocols/ip.h>
 #include <odp_traffic_mngr_internal.h>
+#include <odp/api/plat/packet_inlines.h>
 
 /* Local vars */
 static const
@@ -1966,7 +1967,7 @@  static void egress_ipv4_tos_marking(tm_tos_marking_t *tos_marking,
 	uint32_t       hdr_len, l3_offset, old_chksum, ones_compl_sum, tos_diff;
 	uint8_t        old_tos, new_tos, ecn;
 
-	l3_offset    = odp_packet_l3_offset(odp_pkt);
+	l3_offset    = _odp_packet_l3_offset(odp_pkt);
 	ipv4_hdr_ptr = odp_packet_l3_ptr(odp_pkt, &hdr_len);
 
 	/* If the split_hdr variable below is TRUE, then this indicates that
@@ -2032,7 +2033,7 @@  static void egress_ipv6_tc_marking(tm_tos_marking_t *tos_marking,
 	uint32_t       hdr_len, old_ver_tc_flow, new_ver_tc_flow, l3_offset;
 	uint8_t        old_tc, new_tc, ecn;
 
-	l3_offset    = odp_packet_l3_offset(odp_pkt);
+	l3_offset    = _odp_packet_l3_offset(odp_pkt);
 	ipv6_hdr_ptr = odp_packet_l3_ptr(odp_pkt, &hdr_len);
 
 	/* If the split_hdr variable below is TRUE, then this indicates that