aboutsummaryrefslogtreecommitdiff
path: root/platform/linux-generic/odp_event.c
blob: edf77e2dc851ec1470916ef221b46645c96abd75 (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
/* Copyright (c) 2015-2018, Linaro Limited
 * Copyright (c) 2020-2023, Nokia
 * All rights reserved.
 *
 * SPDX-License-Identifier:     BSD-3-Clause
 */

#include <odp/api/event.h>
#include <odp/api/buffer.h>
#include <odp/api/crypto.h>
#include <odp/api/dma.h>
#include <odp/api/packet.h>
#include <odp/api/timer.h>
#include <odp/api/pool.h>

#include <odp_buffer_internal.h>
#include <odp_ipsec_internal.h>
#include <odp_debug_internal.h>
#include <odp_packet_internal.h>
#include <odp_event_internal.h>
#include <odp_event_validation_internal.h>
#include <odp_event_vector_internal.h>

/* Inlined API functions */
#include <odp/api/plat/event_inlines.h>
#include <odp/api/plat/packet_inlines.h>
#include <odp/api/plat/packet_vector_inlines.h>
#include <odp/api/plat/timer_inlines.h>

#include <odp/api/plat/event_inline_types.h>

#include <odp/visibility_begin.h>

/* Fill in event header field offsets for inline functions */
const _odp_event_inline_offset_t
_odp_event_inline_offset ODP_ALIGNED_CACHE = {
	.event_type = offsetof(_odp_event_hdr_t, event_type),
	.base_data  = offsetof(_odp_event_hdr_t, base_data),
	.flow_id    = offsetof(_odp_event_hdr_t, flow_id),
	.pool       = offsetof(_odp_event_hdr_t, pool),
};

#include <odp/visibility_end.h>

static inline void event_free(odp_event_t event, _odp_ev_id_t id)
{
	switch (odp_event_type(event)) {
	case ODP_EVENT_BUFFER:
		_odp_buffer_validate(odp_buffer_from_event(event), id);
		odp_buffer_free(odp_buffer_from_event(event));
		break;
	case ODP_EVENT_PACKET:
		_odp_packet_validate(odp_packet_from_event(event), id);
		odp_packet_free(odp_packet_from_event(event));
		break;
	case ODP_EVENT_PACKET_VECTOR:
		_odp_packet_vector_free_full(odp_packet_vector_from_event(event));
		break;
	case ODP_EVENT_TIMEOUT:
		odp_timeout_free(odp_timeout_from_event(event));
		break;
#if ODP_DEPRECATED_API
	case ODP_EVENT_CRYPTO_COMPL:
		odp_crypto_compl_free(odp_crypto_compl_from_event(event));
		break;
#endif
	case ODP_EVENT_IPSEC_STATUS:
		_odp_ipsec_status_free(_odp_ipsec_status_from_event(event));
		break;
	case ODP_EVENT_PACKET_TX_COMPL:
		odp_packet_tx_compl_free(odp_packet_tx_compl_from_event(event));
		break;
	case ODP_EVENT_DMA_COMPL:
		odp_dma_compl_free(odp_dma_compl_from_event(event));
		break;
	default:
		_ODP_ABORT("Invalid event type: %d\n", odp_event_type(event));
	}
}

void odp_event_free(odp_event_t event)
{
	event_free(event, _ODP_EV_EVENT_FREE);
}

void odp_event_free_multi(const odp_event_t event[], int num)
{
	for (int i = 0; i < num; i++)
		event_free(event[i], _ODP_EV_EVENT_FREE_MULTI);
}

void odp_event_free_sp(const odp_event_t event[], int num)
{
	for (int i = 0; i < num; i++)
		event_free(event[i], _ODP_EV_EVENT_FREE_SP);
}

uint64_t odp_event_to_u64(odp_event_t hdl)
{
	return _odp_pri(hdl);
}

int odp_event_is_valid(odp_event_t event)
{
	if (event == ODP_EVENT_INVALID)
		return 0;

	if (_odp_event_is_valid(event) == 0)
		return 0;

	switch (odp_event_type(event)) {
	case ODP_EVENT_BUFFER:
		return !_odp_buffer_validate(odp_buffer_from_event(event), _ODP_EV_EVENT_IS_VALID);
	case ODP_EVENT_PACKET:
		return !_odp_packet_validate(odp_packet_from_event(event), _ODP_EV_EVENT_IS_VALID);
	case ODP_EVENT_TIMEOUT:
		/* Fall through */
#if ODP_DEPRECATED_API
	case ODP_EVENT_CRYPTO_COMPL:
		/* Fall through */
#endif
	case ODP_EVENT_IPSEC_STATUS:
		/* Fall through */
	case ODP_EVENT_PACKET_VECTOR:
		/* Fall through */
	case ODP_EVENT_DMA_COMPL:
		/* Fall through */
	case ODP_EVENT_PACKET_TX_COMPL:
		break;
	default:
		return 0;
	}

	return 1;
}