blob: 46802e67f692050896f65baccb642301a45e4706 (
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
|
/* Copyright (c) 2013, Linaro Limited
* All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
/**
* @file
*
* ODP buffer descriptor - implementation internal
*/
#ifndef ODP_BUFFER_INTERNAL_H_
#define ODP_BUFFER_INTERNAL_H_
#ifdef __cplusplus
extern "C" {
#endif
#include <odp/std_types.h>
#include <odp/atomic.h>
#include <odp/pool.h>
#include <odp/buffer.h>
#include <odp/debug.h>
#include <odp/align.h>
#include <odp_align_internal.h>
#include <odp/config.h>
#include <odp/byteorder.h>
#include <odp/thread.h>
#include <odp/event.h>
#define ODP_BITSIZE(x) \
((x) <= 2 ? 1 : \
((x) <= 4 ? 2 : \
((x) <= 8 ? 3 : \
((x) <= 16 ? 4 : \
((x) <= 32 ? 5 : \
((x) <= 64 ? 6 : \
((x) <= 128 ? 7 : \
((x) <= 256 ? 8 : \
((x) <= 512 ? 9 : \
((x) <= 1024 ? 10 : \
((x) <= 2048 ? 11 : \
((x) <= 4096 ? 12 : \
((x) <= 8196 ? 13 : \
((x) <= 16384 ? 14 : \
((x) <= 32768 ? 15 : \
((x) <= 65536 ? 16 : \
(0/0)))))))))))))))))
_ODP_STATIC_ASSERT(ODP_CONFIG_PACKET_BUF_LEN_MIN >= 256,
"ODP Segment size must be a minimum of 256 bytes");
_ODP_STATIC_ASSERT((ODP_CONFIG_PACKET_BUF_LEN_MIN % ODP_CACHE_LINE_SIZE) == 0,
"ODP Segment size must be a multiple of cache line size");
_ODP_STATIC_ASSERT((ODP_CONFIG_PACKET_BUF_LEN_MAX %
ODP_CONFIG_PACKET_BUF_LEN_MIN) == 0,
"Packet max size must be a multiple of segment size");
#define ODP_BUFFER_MAX_SEG \
(ODP_CONFIG_PACKET_BUF_LEN_MAX / ODP_CONFIG_PACKET_BUF_LEN_MIN)
/* We can optimize storage of small raw buffers within metadata area */
#define ODP_MAX_INLINE_BUF ((sizeof(void *)) * (ODP_BUFFER_MAX_SEG - 1))
#define ODP_BUFFER_POOL_BITS ODP_BITSIZE(ODP_CONFIG_POOLS)
#define ODP_BUFFER_SEG_BITS ODP_BITSIZE(ODP_BUFFER_MAX_SEG)
#define ODP_BUFFER_INDEX_BITS (32 - ODP_BUFFER_POOL_BITS - ODP_BUFFER_SEG_BITS)
#define ODP_BUFFER_PREFIX_BITS (ODP_BUFFER_POOL_BITS + ODP_BUFFER_INDEX_BITS)
#define ODP_BUFFER_MAX_POOLS (1 << ODP_BUFFER_POOL_BITS)
#define ODP_BUFFER_MAX_BUFFERS (1 << ODP_BUFFER_INDEX_BITS)
#define ODP_BUFFER_MAX_INDEX (ODP_BUFFER_MAX_BUFFERS - 2)
#define ODP_BUFFER_INVALID_INDEX (ODP_BUFFER_MAX_BUFFERS - 1)
typedef union odp_buffer_bits_t {
uint32_t u32;
odp_buffer_t handle;
struct {
#if ODP_BYTE_ORDER == ODP_BIG_ENDIAN
uint32_t pool_id:ODP_BUFFER_POOL_BITS;
uint32_t index:ODP_BUFFER_INDEX_BITS;
uint32_t seg:ODP_BUFFER_SEG_BITS;
#else
uint32_t seg:ODP_BUFFER_SEG_BITS;
uint32_t index:ODP_BUFFER_INDEX_BITS;
uint32_t pool_id:ODP_BUFFER_POOL_BITS;
#endif
};
struct {
#if ODP_BYTE_ORDER == ODP_BIG_ENDIAN
uint32_t prefix:ODP_BUFFER_PREFIX_BITS;
uint32_t pfxseg:ODP_BUFFER_SEG_BITS;
#else
uint32_t pfxseg:ODP_BUFFER_SEG_BITS;
uint32_t prefix:ODP_BUFFER_PREFIX_BITS;
#endif
};
} odp_buffer_bits_t;
/* forward declaration */
struct odp_buffer_hdr_t;
/* Common buffer header */
typedef struct odp_buffer_hdr_t {
struct odp_buffer_hdr_t *next; /* next buf in a list */
int allocator; /* allocating thread id */
odp_buffer_bits_t handle; /* handle */
union {
uint32_t all;
struct {
uint32_t zeroized:1; /* Zeroize buf data on free */
uint32_t hdrdata:1; /* Data is in buffer hdr */
};
} flags;
int type; /* buffer type */
uint32_t size; /* max data size */
odp_atomic_u32_t ref_count; /* reference count */
odp_pool_t pool_hdl; /* buffer pool handle */
union {
uint64_t buf_u64; /* user u64 */
void *buf_ctx; /* user context */
const void *buf_cctx; /* const alias for ctx */
void *udata_addr; /* user metadata addr */
};
size_t udata_size; /* size of user metadata */
uint32_t segcount; /* segment count */
uint32_t segsize; /* segment size */
void *addr[ODP_BUFFER_MAX_SEG]; /* block addrs */
} odp_buffer_hdr_t;
typedef struct odp_buffer_hdr_stride {
uint8_t pad[ODP_CACHE_LINE_SIZE_ROUNDUP(sizeof(odp_buffer_hdr_t))];
} odp_buffer_hdr_stride;
typedef struct odp_buf_blk_t {
struct odp_buf_blk_t *next;
struct odp_buf_blk_t *prev;
} odp_buf_blk_t;
/* Raw buffer header */
typedef struct {
odp_buffer_hdr_t buf_hdr; /* common buffer header */
} odp_raw_buffer_hdr_t;
/* Free buffer marker */
#define ODP_FREEBUF -1
/* Forward declarations */
odp_buffer_t buffer_alloc(odp_pool_t pool, size_t size);
/*
* Buffer type
*
* @param buf Buffer handle
*
* @return Buffer type
*/
int _odp_buffer_type(odp_buffer_t buf);
#ifdef __cplusplus
}
#endif
#endif
|