diff mbox

[PATCHv5,1/9] api: packet: move helper functions to public API

Message ID 1418733042-18047-2-git-send-email-taras.kondratiuk@linaro.org
State Accepted
Commit 8822ad6c22f6d135c43829e043c675a779bbd005
Headers show

Commit Message

Taras Kondratiuk Dec. 16, 2014, 12:30 p.m. UTC
From: Bill Fischofer <bill.fischofer@linaro.org>

Signed-off-by: Bill Fischofer <bill.fischofer@linaro.org>
Signed-off-by: Taras Kondratiuk <taras.kondratiuk@linaro.org>
---
 example/generator/odp_generator.c               |  5 +-
 example/ipsec/odp_ipsec.c                       |  3 +-
 example/ipsec/odp_ipsec_stream.c                |  3 +-
 example/l2fwd/odp_l2fwd.c                       |  3 +-
 example/packet/odp_pktio.c                      |  3 +-
 helper/include/odph_packet.h                    | 97 -------------------------
 platform/linux-generic/Makefile.am              |  1 -
 platform/linux-generic/include/api/odp_packet.h | 41 +++++++++++
 platform/linux-generic/odp_crypto.c             |  4 +-
 platform/linux-generic/odp_packet.c             | 36 +++++++++
 platform/linux-generic/odp_packet_socket.c      | 35 ++++-----
 11 files changed, 103 insertions(+), 128 deletions(-)
 delete mode 100644 helper/include/odph_packet.h
diff mbox

Patch

diff --git a/example/generator/odp_generator.c b/example/generator/odp_generator.c
index a67910e..5ded85c 100644
--- a/example/generator/odp_generator.c
+++ b/example/generator/odp_generator.c
@@ -21,7 +21,6 @@ 
 #include <odp.h>
 
 #include <odph_linux.h>
-#include <odph_packet.h>
 #include <odph_eth.h>
 #include <odph_ip.h>
 #include <odph_udp.h>
@@ -503,13 +502,13 @@  static void *gen_recv_thread(void *arg)
 		pkt = odp_packet_from_buffer(buf);
 		/* Drop packets with errors */
 		if (odp_unlikely(odp_packet_error(pkt))) {
-			odph_packet_free(pkt);
+			odp_packet_free(pkt);
 			continue;
 		}
 
 		print_pkts(thr, &pkt, 1);
 
-		odph_packet_free(pkt);
+		odp_packet_free(pkt);
 	}
 
 	return arg;
diff --git a/example/ipsec/odp_ipsec.c b/example/ipsec/odp_ipsec.c
index 4b5a21c..cd73682 100644
--- a/example/ipsec/odp_ipsec.c
+++ b/example/ipsec/odp_ipsec.c
@@ -20,7 +20,6 @@ 
 #include <odp.h>
 
 #include <odph_linux.h>
-#include <odph_packet.h>
 #include <odph_eth.h>
 #include <odph_ip.h>
 #include <odph_icmp.h>
@@ -1148,7 +1147,7 @@  void *pktio_thread(void *arg EXAMPLE_UNUSED)
 
 		/* Check for drop */
 		if (PKT_DROP == rc)
-			odph_packet_free(pkt);
+			odp_packet_free(pkt);
 
 		/* Print packet counts every once in a while */
 		if (PKT_DONE == rc) {
diff --git a/example/ipsec/odp_ipsec_stream.c b/example/ipsec/odp_ipsec_stream.c
index 8e002b6..91eba88 100644
--- a/example/ipsec/odp_ipsec_stream.c
+++ b/example/ipsec/odp_ipsec_stream.c
@@ -16,7 +16,6 @@ 
 
 #include <odp.h>
 
-#include <odph_packet.h>
 #include <odph_eth.h>
 #include <odph_ip.h>
 #include <odph_icmp.h>
@@ -549,7 +548,7 @@  bool verify_stream_db_outputs(void)
 				good = verify_ipv4_packet(stream, pkt);
 				if (good)
 					stream->verified++;
-				odph_packet_free(pkt);
+				odp_packet_free(pkt);
 			}
 		}
 
diff --git a/example/l2fwd/odp_l2fwd.c b/example/l2fwd/odp_l2fwd.c
index 3c1fd6a..9721ab7 100644
--- a/example/l2fwd/odp_l2fwd.c
+++ b/example/l2fwd/odp_l2fwd.c
@@ -19,7 +19,6 @@ 
 
 #include <odp.h>
 #include <odph_linux.h>
-#include <odph_packet.h>
 #include <odph_eth.h>
 #include <odph_ip.h>
 
@@ -476,7 +475,7 @@  static int drop_err_pkts(odp_packet_t pkt_tbl[], unsigned len)
 		pkt = pkt_tbl[i];
 
 		if (odp_unlikely(odp_packet_error(pkt))) {
-			odph_packet_free(pkt); /* Drop */
+			odp_packet_free(pkt); /* Drop */
 			pkt_cnt--;
 		} else if (odp_unlikely(i != j++)) {
 			pkt_tbl[j-1] = pkt;
diff --git a/example/packet/odp_pktio.c b/example/packet/odp_pktio.c
index 5ac8398..10b79d7 100644
--- a/example/packet/odp_pktio.c
+++ b/example/packet/odp_pktio.c
@@ -19,7 +19,6 @@ 
 
 #include <odp.h>
 #include <odph_linux.h>
-#include <odph_packet.h>
 #include <odph_eth.h>
 #include <odph_ip.h>
 
@@ -455,7 +454,7 @@  static int drop_err_pkts(odp_packet_t pkt_tbl[], unsigned len)
 		pkt = pkt_tbl[i];
 
 		if (odp_unlikely(odp_packet_error(pkt))) {
-			odph_packet_free(pkt); /* Drop */
+			odp_packet_free(pkt); /* Drop */
 			pkt_cnt--;
 		} else if (odp_unlikely(i != j++)) {
 			pkt_tbl[j-1] = pkt;
diff --git a/helper/include/odph_packet.h b/helper/include/odph_packet.h
deleted file mode 100644
index 3d53593..0000000
--- a/helper/include/odph_packet.h
+++ /dev/null
@@ -1,97 +0,0 @@ 
-/* Copyright (c) 2014, Linaro Limited
- * All rights reserved.
- *
- * SPDX-License-Identifier:     BSD-3-Clause
- */
-
-
-/**
- * @file
- *
- * Optional ODP packet helper functions
- */
-
-#ifndef ODPH_PACKET_HELPER_H_
-#define ODPH_PACKET_HELPER_H_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#include <odp.h>
-
-/**
- * Helper: Tests if packet is valid
- *
- * Allows for more thorough checking than "if (pkt == ODP_PACKET_INVALID)"
- *
- * @param pkt  Packet handle
- *
- * @return 1 if valid, otherwise 0
- */
-static inline int odph_packet_is_valid(odp_packet_t pkt)
-{
-	odp_buffer_t buf = odp_packet_to_buffer(pkt);
-
-	return odp_buffer_is_valid(buf);
-}
-
-/**
- * Helper: Allocate and initialize a packet buffer from a packet pool
- *
- * @param pool_id  Pool handle
- *
- * @note  The pool must have been created with 'buf_type=ODP_BUFFER_TYPE_PACKET'
- *
- * @return Packet handle or ODP_PACKET_INVALID
- */
-static inline odp_packet_t odph_packet_alloc(odp_buffer_pool_t pool_id)
-{
-	odp_packet_t pkt;
-	odp_buffer_t buf;
-
-	buf = odp_buffer_alloc(pool_id);
-	if (odp_unlikely(!odp_buffer_is_valid(buf)))
-		return ODP_PACKET_INVALID;
-
-	pkt = odp_packet_from_buffer(buf);
-	odp_packet_init(pkt);
-
-	return pkt;
-}
-
-/**
- * Helper: Free a packet buffer back into the packet pool
- *
- * @param pkt  Packet handle
- */
-static inline void odph_packet_free(odp_packet_t pkt)
-{
-	odp_buffer_t buf = odp_packet_to_buffer(pkt);
-
-	odp_buffer_free(buf);
-}
-
-/**
- * Helper: Packet buffer maximum data size
- *
- * @note odp_packet_buf_size(pkt) != odp_packet_get_len(pkt), the former returns
- *       the max length of the buffer, the latter the size of a received packet.
- *
- * @param pkt  Packet handle
- *
- * @return Packet buffer maximum data size
- */
-static inline size_t odph_packet_buf_size(odp_packet_t pkt)
-{
-	odp_buffer_t buf = odp_packet_to_buffer(pkt);
-
-	return odp_buffer_size(buf);
-}
-
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/platform/linux-generic/Makefile.am b/platform/linux-generic/Makefile.am
index cc78de3..911f925 100644
--- a/platform/linux-generic/Makefile.am
+++ b/platform/linux-generic/Makefile.am
@@ -47,7 +47,6 @@  subdirheaders_HEADERS = \
 			$(top_srcdir)/helper/include/odph_ip.h \
 			$(top_srcdir)/helper/include/odph_ipsec.h \
 			$(top_srcdir)/helper/include/odph_linux.h \
-			$(top_srcdir)/helper/include/odph_packet.h \
 			$(top_srcdir)/helper/include/odph_ring.h \
 			$(top_srcdir)/helper/include/odph_udp.h
 
diff --git a/platform/linux-generic/include/api/odp_packet.h b/platform/linux-generic/include/api/odp_packet.h
index 5298fa0..9e2e542 100644
--- a/platform/linux-generic/include/api/odp_packet.h
+++ b/platform/linux-generic/include/api/odp_packet.h
@@ -27,6 +27,24 @@  extern "C" {
 
 
 /**
+ * Allocate and initialize a packet buffer from a packet pool
+ *
+ * @param pool_id  Pool handle
+ *
+ * @note  The pool must have been created with 'buf_type=ODP_BUFFER_TYPE_PACKET'
+ *
+ * @return Packet handle or ODP_PACKET_INVALID
+ */
+odp_packet_t odp_packet_alloc(odp_buffer_pool_t pool_id);
+
+/**
+ * Free a packet buffer back into the packet pool
+ *
+ * @param pkt  Packet handle
+ */
+void odp_packet_free(odp_packet_t pkt);
+
+/**
  * Initialize the packet
  *
  * Needs to be called if the user allocates a packet buffer, i.e. the packet
@@ -109,6 +127,18 @@  void *odp_packet_get_ctx(odp_packet_t buf);
 uint8_t *odp_packet_addr(odp_packet_t pkt);
 
 /**
+ * Packet buffer maximum data size
+ *
+ * @note odp_packet_buf_size(pkt) != odp_packet_get_len(pkt), the former returns
+ *       the max length of the buffer, the latter the size of a received packet.
+ *
+ * @param pkt  Packet handle
+ *
+ * @return Packet buffer maximum data size
+ */
+size_t odp_packet_buf_size(odp_packet_t pkt);
+
+/**
  * Packet data address
  *
  * Returns the current packet data address. When a packet is received from
@@ -417,6 +447,17 @@  int odp_packet_seg_pull_tail(odp_packet_t pkt, odp_packet_seg_t seg,
 			     size_t len);
 
 /**
+ * Tests if packet is valid
+ *
+ * Allows for more thorough checking than "if (pkt == ODP_PACKET_INVALID)"
+ *
+ * @param pkt  Packet handle
+ *
+ * @return 1 if valid, otherwise 0
+ */
+int odp_packet_is_valid(odp_packet_t pkt);
+
+/**
  * @}
  */
 
diff --git a/platform/linux-generic/odp_crypto.c b/platform/linux-generic/odp_crypto.c
index d3cdec7..4c584fc 100644
--- a/platform/linux-generic/odp_crypto.c
+++ b/platform/linux-generic/odp_crypto.c
@@ -15,7 +15,7 @@ 
 #include <odp_crypto_internal.h>
 #include <odp_debug_internal.h>
 #include <odp_hints.h>
-#include <odph_packet.h>
+#include <odp_packet.h>
 
 #include <string.h>
 
@@ -360,7 +360,7 @@  odp_crypto_operation(odp_crypto_op_params_t *params,
 		if (completion_event == odp_packet_to_buffer(params->pkt))
 			completion_event =
 				odp_packet_to_buffer(params->out_pkt);
-		odph_packet_free(params->pkt);
+		odp_packet_free(params->pkt);
 		params->pkt = ODP_PACKET_INVALID;
 	}
 
diff --git a/platform/linux-generic/odp_packet.c b/platform/linux-generic/odp_packet.c
index 726e086..8a941ce 100644
--- a/platform/linux-generic/odp_packet.c
+++ b/platform/linux-generic/odp_packet.c
@@ -21,6 +21,28 @@  static inline uint8_t parse_ipv4(odp_packet_hdr_t *pkt_hdr,
 static inline uint8_t parse_ipv6(odp_packet_hdr_t *pkt_hdr,
 				 odph_ipv6hdr_t *ipv6, size_t *offset_out);
 
+odp_packet_t odp_packet_alloc(odp_buffer_pool_t pool_id)
+{
+	odp_packet_t pkt;
+	odp_buffer_t buf;
+
+	buf = odp_buffer_alloc(pool_id);
+	if (odp_unlikely(!odp_buffer_is_valid(buf)))
+		return ODP_PACKET_INVALID;
+
+	pkt = odp_packet_from_buffer(buf);
+	odp_packet_init(pkt);
+
+	return pkt;
+}
+
+void odp_packet_free(odp_packet_t pkt)
+{
+	odp_buffer_t buf = odp_packet_to_buffer(pkt);
+
+	odp_buffer_free(buf);
+}
+
 void odp_packet_init(odp_packet_t pkt)
 {
 	odp_packet_hdr_t *const pkt_hdr = odp_packet_hdr(pkt);
@@ -368,3 +390,17 @@  void *odp_packet_get_ctx(odp_packet_t pkt)
 {
 	return (void *)(intptr_t)odp_packet_hdr(pkt)->user_ctx;
 }
+
+int odp_packet_is_valid(odp_packet_t pkt)
+{
+	odp_buffer_t buf = odp_packet_to_buffer(pkt);
+
+	return odp_buffer_is_valid(buf);
+}
+
+size_t odp_packet_buf_size(odp_packet_t pkt)
+{
+	odp_buffer_t buf = odp_packet_to_buffer(pkt);
+
+	return odp_buffer_size(buf);
+}
diff --git a/platform/linux-generic/odp_packet_socket.c b/platform/linux-generic/odp_packet_socket.c
index f96d5bf..b11aa1c 100644
--- a/platform/linux-generic/odp_packet_socket.c
+++ b/platform/linux-generic/odp_packet_socket.c
@@ -42,7 +42,8 @@ 
 
 #include <odph_eth.h>
 #include <odph_ip.h>
-#include <odph_packet.h>
+#include <odp_packet.h>
+#include <odp_spinlock.h>
 
 /** Provide a sendmmsg wrapper for systems with no libc or kernel support.
  *  As it is implemented as a weak symbol, it has zero effect on systems
@@ -214,8 +215,8 @@  int setup_pkt_sock(pkt_sock_t *const pkt_sock, const char *netdev,
 		return -1;
 	pkt_sock->pool = pool;
 
-	pkt = odph_packet_alloc(pool);
-	if (!odph_packet_is_valid(pkt))
+	pkt = odp_packet_alloc(pool);
+	if (!odp_packet_is_valid(pkt))
 		return -1;
 
 	pkt_buf = odp_packet_addr(pkt);
@@ -223,11 +224,11 @@  int setup_pkt_sock(pkt_sock_t *const pkt_sock, const char *netdev,
 	/* Store eth buffer offset for pkt buffers from this pool */
 	pkt_sock->frame_offset = (uintptr_t)l2_hdr - (uintptr_t)pkt_buf;
 	/* pkt buffer size */
-	pkt_sock->buf_size = odph_packet_buf_size(pkt);
+	pkt_sock->buf_size = odp_packet_buf_size(pkt);
 	/* max frame len taking into account the l2-offset */
 	pkt_sock->max_frame_len = pkt_sock->buf_size - pkt_sock->frame_offset;
 
-	odph_packet_free(pkt);
+	odp_packet_free(pkt);
 
 	odp_spinlock_lock(&raw_sockets_lock);
 
@@ -331,7 +332,7 @@  int recv_pkt_sock_basic(pkt_sock_t *const pkt_sock,
 
 	for (i = 0; i < len; i++) {
 		if (odp_likely(pkt == ODP_PACKET_INVALID)) {
-			pkt = odph_packet_alloc(pkt_sock->pool);
+			pkt = odp_packet_alloc(pkt_sock->pool);
 			if (odp_unlikely(pkt == ODP_PACKET_INVALID))
 				break;
 		}
@@ -358,7 +359,7 @@  int recv_pkt_sock_basic(pkt_sock_t *const pkt_sock,
 	} /* end for() */
 
 	if (odp_unlikely(pkt != ODP_PACKET_INVALID))
-		odph_packet_free(pkt);
+		odp_packet_free(pkt);
 
 	return nb_rx;
 }
@@ -402,7 +403,7 @@  int send_pkt_sock_basic(pkt_sock_t *const pkt_sock,
 	nb_tx = i;
 
 	for (i = 0; i < len; i++)
-		odph_packet_free(pkt_table[i]);
+		odp_packet_free(pkt_table[i]);
 
 	return nb_tx;
 }
@@ -429,7 +430,7 @@  int recv_pkt_sock_mmsg(pkt_sock_t *const pkt_sock,
 	memset(msgvec, 0, sizeof(msgvec));
 
 	for (i = 0; i < (int)len; i++) {
-		pkt_table[i] = odph_packet_alloc(pkt_sock->pool);
+		pkt_table[i] = odp_packet_alloc(pkt_sock->pool);
 		if (odp_unlikely(pkt_table[i] == ODP_PACKET_INVALID))
 			break;
 
@@ -451,7 +452,7 @@  int recv_pkt_sock_mmsg(pkt_sock_t *const pkt_sock,
 		/* Don't receive packets sent by ourselves */
 		if (odp_unlikely(ethaddrs_equal(pkt_sock->if_mac,
 						eth_hdr->h_source))) {
-			odph_packet_free(pkt_table[i]);
+			odp_packet_free(pkt_table[i]);
 			continue;
 		}
 
@@ -465,7 +466,7 @@  int recv_pkt_sock_mmsg(pkt_sock_t *const pkt_sock,
 
 	/* Free unused pkt buffers */
 	for (; i < msgvec_len; i++)
-		odph_packet_free(pkt_table[i]);
+		odp_packet_free(pkt_table[i]);
 
 	return nb_rx;
 }
@@ -507,7 +508,7 @@  int send_pkt_sock_mmsg(pkt_sock_t *const pkt_sock,
 	}
 
 	for (i = 0; i < len; i++)
-		odph_packet_free(pkt_table[i]);
+		odp_packet_free(pkt_table[i]);
 
 	return len;
 }
@@ -604,7 +605,7 @@  static inline unsigned pkt_mmap_v2_rx(int sock, struct ring *ring,
 				continue;
 			}
 
-			pkt_table[i] = odph_packet_alloc(pool);
+			pkt_table[i] = odp_packet_alloc(pool);
 			if (odp_unlikely(pkt_table[i] == ODP_PACKET_INVALID))
 				break;
 
@@ -658,7 +659,7 @@  static inline unsigned pkt_mmap_v2_tx(int sock, struct ring *ring,
 
 			mmap_tx_user_ready(ppd.raw);
 
-			odph_packet_free(pkt_table[i]);
+			odp_packet_free(pkt_table[i]);
 			frame_num = next_frame_num;
 			i++;
 		} else {
@@ -850,8 +851,8 @@  int setup_pkt_sock_mmap(pkt_sock_mmap_t *const pkt_sock, const char *netdev,
 	if (pool == ODP_BUFFER_POOL_INVALID)
 		return -1;
 
-	pkt = odph_packet_alloc(pool);
-	if (!odph_packet_is_valid(pkt))
+	pkt = odp_packet_alloc(pool);
+	if (!odp_packet_is_valid(pkt))
 		return -1;
 
 	pkt_buf = odp_packet_addr(pkt);
@@ -859,7 +860,7 @@  int setup_pkt_sock_mmap(pkt_sock_mmap_t *const pkt_sock, const char *netdev,
 	/* Store eth buffer offset for pkt buffers from this pool */
 	pkt_sock->frame_offset = (uintptr_t)l2_hdr - (uintptr_t)pkt_buf;
 
-	odph_packet_free(pkt);
+	odp_packet_free(pkt);
 
 	pkt_sock->pool = pool;
 	pkt_sock->sockfd = mmap_pkt_socket();