aboutsummaryrefslogtreecommitdiff
path: root/platform/linux-generic/include/api/odp_packet_io.h
blob: 7dfcc4ffdc00edc70c388920b4bab63caf653912 (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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
/* Copyright (c) 2013, Linaro Limited
 * All rights reserved.
 *
 * SPDX-License-Identifier:     BSD-3-Clause
 */


/**
 * @file
 *
 * ODP Packet IO
 */

#ifndef ODP_PACKET_IO_H_
#define ODP_PACKET_IO_H_

#ifdef __cplusplus
extern "C" {
#endif

#include <odp_std_types.h>
#include <odp_platform_types.h>
#include <odp_pool.h>
#include <odp_packet.h>
#include <odp_queue.h>

/** @defgroup odp_packet_io ODP PACKET IO
 *  Operations on a packet.
 *  @{
 */

/**
 * Open an ODP packet IO instance
 *
 * Packet IO handles are single instance per device, attempts to open an already
 * open device will fail, returning ODP_PKTIO_INVALID with errno set to -EEXIST.
 * odp_pktio_lookup() may be used to obtain a handle to an already open device.
 *
 * @param dev    Packet IO device name
 * @param pool   Pool from which to allocate buffers for storing packets
 *               received over this packet IO
 *
 * @return ODP packet IO handle or ODP_PKTIO_INVALID on error
 *
 * @note dev name loop is specially pktio reserved name for
 *	 device used for testing. Usually it's loop back
 *	 interface.
 */
odp_pktio_t odp_pktio_open(const char *dev, odp_buffer_pool_t pool);

/**
 * Close an ODP packet IO instance
 *
 * @param id  ODP packet IO handle
 *
 * @return 0 on success or -1 on error
 */
int odp_pktio_close(odp_pktio_t id);

/**
 * Return a packet IO handle for an already open device
 *
 * @param dev Packet IO device name
 *
 * @return ODP packet IO handle or ODP_PKTIO_INVALID
 */
odp_pktio_t odp_pktio_lookup(const char *dev);

/**
 * Receive packets
 *
 * @param id          ODP packet IO handle
 * @param pkt_table[] Storage for received packets (filled by function)
 * @param len         Length of pkt_table[], i.e. max number of pkts to receive
 *
 * @return Number of packets received or -1 on error
 */
int odp_pktio_recv(odp_pktio_t id, odp_packet_t pkt_table[], unsigned len);

/**
 * Send packets
 *
 * @param id           ODP packet IO handle
 * @param pkt_table[]  Array of packets to send
 * @param len          length of pkt_table[]
 *
 * @return Number of packets sent or -1 on error
 */
int odp_pktio_send(odp_pktio_t id, odp_packet_t pkt_table[], unsigned len);

/**
 * Set the default input queue to be associated with a pktio handle
 *
 * @param id	ODP packet IO handle
 * @param queue default input queue set
 * @return  0 on success or -1 on error
 */
int odp_pktio_inq_setdef(odp_pktio_t id, odp_queue_t queue);

/**
 * Get default input queue associated with a pktio handle
 *
 * @param id  ODP packet IO handle
 *
 * @return Default input queue set or ODP_QUEUE_INVALID on error
 */
odp_queue_t odp_pktio_inq_getdef(odp_pktio_t id);

/**
 * Remove default input queue (if set)
 *
 * @param id  ODP packet IO handle
 *
 * @return 0 on success or -1 on error
 */
int odp_pktio_inq_remdef(odp_pktio_t id);

/**
 * Query default output queue
 *
 * @param id ODP packet IO handle
 *
 * @return Default out queue or ODP_QUEUE_INVALID on error
 */
odp_queue_t odp_pktio_outq_getdef(odp_pktio_t id);

/**
 * Return the currently configured MTU value of a packet IO interface.
 *
 * @param[in] id  ODP packet IO handle.
 *
 * @retval MTU value >0 on success.
 * @retval -1 on any error or not existance pktio id.
 */
int odp_pktio_mtu(odp_pktio_t id);

/**
 * Enable/Disable promiscuous mode on a packet IO interface.
 *
 * @param[in] id	ODP packet IO handle.
 * @param[in] enable	1 to enable, 0 to disable.
 *
 * @retval 0 on success.
 * @retval non-zero on any error.
 */
int odp_pktio_promisc_mode_set(odp_pktio_t id, odp_bool_t enable);

/**
 * Determine if promiscuous mode is enabled for a packet IO interface.
 *
 * @param[in] id ODP packet IO handle.
 *
 * @retval  1 if promiscuous mode is enabled.
 * @retval  0 if promiscuous mode is disabled.
 * @retval -1 on any error.
*/
int odp_pktio_promisc_mode(odp_pktio_t id);

/**
 * Get the default MAC address of a packet IO interface.
 *
 * @param	id	  ODP packet IO handle.
 * @param[out]	mac_addr  Storage for MAC address of the packet IO interface.
 * @param	addr_size Storage size for the address
 *
 * @retval Number of bytes written on success, 0 on failure.
 */
size_t odp_pktio_mac_addr(odp_pktio_t id, void *mac_addr,
			  size_t addr_size);

/**
 * Setup per-port default class-of-service.
 *
 * @param[in]	pktio_in	Ingress port identifier.
 * @param[in]	default_cos	Class-of-service set to all packets arriving
 *				at the pktio_in ingress port,
 *				unless overridden by subsequent
 *				header-based filters.
 *
 * @return			0 on success, non-zero on error.
 */
int odp_pktio_default_cos_set(odp_pktio_t pktio_in, odp_cos_t default_cos);

/**
 * Setup per-port error class-of-service
 *
 * @param[in]	pktio_in	Ingress port identifier.
 * @param[in]	error_cos	class-of-service set to all packets arriving
 *				at the pktio_in ingress port
 *				that contain an error.
 *
 * @return			0 on success, non-zero on error.
 *
 * @note Optional.
 */
int odp_pktio_error_cos_set(odp_pktio_t pktio_in, odp_cos_t error_cos);

/**
 * Setup per-port header offset
 *
 * @param[in]	pktio_in	Ingress port identifier.
 * @param[in]	offset		Number of bytes the classifier must skip.
 *
 * @return			0 on success, non-zero on error.
 * @note  Optional.
 *
 */
int odp_pktio_skip_set(odp_pktio_t pktio_in, uint32_t offset);

/**
 * Specify per-port buffer headroom
 *
 * @param[in]	pktio_in	Ingress port identifier.
 * @param[in]	headroom	Number of bytes of space preceding
 *				packet data to reserve for use as headroom.
 *				Must not exceed the implementation
 *				defined ODP_PACKET_MAX_HEADROOM.
 *
 * @return			0 on success, non-zero on error.
 *
 * @note Optional.
 */
int odp_pktio_headroom_set(odp_pktio_t pktio_in, uint32_t headroom);


/**
 * @}
 */

#ifdef __cplusplus
}
#endif

#endif