aboutsummaryrefslogtreecommitdiff
path: root/platform/linux-dpdk/odp_buffer.c
blob: 21956be2ff1a92982bb58e6a0c0241076fb4679e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/* Copyright (c) 2013-2018, Linaro Limited
 * Copyright (c) 2021, Nokia
 * All rights reserved.
 *
 * SPDX-License-Identifier:     BSD-3-Clause
 */

#include <odp/api/buffer.h>
#include <odp_buffer_internal.h>
#include <odp_debug_internal.h>
#include <odp_pool_internal.h>
#include <odp/api/plat/buffer_inline_types.h>

#include <string.h>
#include <stdio.h>
#include <inttypes.h>

#include <odp/visibility_begin.h>

/* Fill in buffer header field offsets for inline functions */
const _odp_buffer_inline_offset_t _odp_buffer_inline_offset ODP_ALIGNED_CACHE = {
	.event_type = offsetof(odp_buffer_hdr_t, event_hdr.event_type),
	.base_data  = offsetof(odp_buffer_hdr_t, event_hdr.mb.buf_addr)
};

#include <odp/visibility_end.h>

uint32_t odp_buffer_size(odp_buffer_t buf)
{
	struct rte_mbuf *mbuf = _odp_buf_to_mbuf(buf);

	return mbuf->buf_len;
}

int _odp_buffer_type(odp_buffer_t buf)
{
	odp_buffer_hdr_t *hdr = _odp_buf_hdr(buf);

	return hdr->event_hdr.type;
}

void _odp_buffer_type_set(odp_buffer_t buf, int type)
{
	odp_buffer_hdr_t *hdr = _odp_buf_hdr(buf);

	hdr->event_hdr.type = type;
}

int odp_buffer_is_valid(odp_buffer_t buf)
{
	if (odp_event_is_valid(odp_buffer_to_event(buf)) == 0)
		return 0;

	if (odp_event_type(odp_buffer_to_event(buf)) != ODP_EVENT_BUFFER)
		return 0;

	return 1;
}

void odp_buffer_print(odp_buffer_t buf)
{
	odp_buffer_hdr_t *hdr;
	pool_t *pool;
	int len = 0;
	int max_len = 512;
	int n = max_len - 1;
	char str[max_len];

	if (!odp_buffer_is_valid(buf)) {
		ODP_ERR("Buffer is not valid.\n");
		return;
	}

	hdr = _odp_buf_hdr(buf);
	pool = hdr->event_hdr.pool_ptr;

	len += snprintf(&str[len], n - len, "Buffer\n------\n");
	len += snprintf(&str[len], n - len, "  pool index    %u\n", pool->pool_idx);
	len += snprintf(&str[len], n - len, "  buffer index  %u\n", hdr->event_hdr.index);
	len += snprintf(&str[len], n - len, "  addr          %p\n", odp_buffer_addr(buf));
	len += snprintf(&str[len], n - len, "  size          %u\n", odp_buffer_size(buf));
	str[len] = 0;

	ODP_PRINT("\n%s\n", str);
}

uint64_t odp_buffer_to_u64(odp_buffer_t hdl)
{
	return _odp_pri(hdl);
}