diff options
author | Bill Fischofer <bill.fischofer@linaro.org> | 2014-12-16 14:30:34 +0200 |
---|---|---|
committer | Maxim Uvarov <maxim.uvarov@linaro.org> | 2014-12-16 19:03:39 +0300 |
commit | 8822ad6c22f6d135c43829e043c675a779bbd005 (patch) | |
tree | abbef5ec4bddbe90bbcbb964009e668e8bcf9822 /platform | |
parent | 57408e45ba64d287d402da8bd212edc9aa56d1ba (diff) |
api: packet: move helper functions to public API
Signed-off-by: Bill Fischofer <bill.fischofer@linaro.org>
Signed-off-by: Taras Kondratiuk <taras.kondratiuk@linaro.org>
Reviewed-and-tested-by: Bill Fischofer <bill.fischofer@linaro.org>
Reviewed-by: Petri Savolainen <petri.savolainen@linaro.org>
Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>
Diffstat (limited to 'platform')
-rw-r--r-- | platform/linux-generic/Makefile.am | 1 | ||||
-rw-r--r-- | platform/linux-generic/include/api/odp_packet.h | 41 | ||||
-rw-r--r-- | platform/linux-generic/odp_crypto.c | 4 | ||||
-rw-r--r-- | platform/linux-generic/odp_packet.c | 36 | ||||
-rw-r--r-- | platform/linux-generic/odp_packet_socket.c | 35 |
5 files changed, 97 insertions, 20 deletions
diff --git a/platform/linux-generic/Makefile.am b/platform/linux-generic/Makefile.am index cc78de30..911f925a 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 5298fa01..9e2e542a 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 d3cdec7d..4c584fc5 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 726e086b..8a941cec 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 f96d5bf8..b11aa1c2 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(); |