summaryrefslogtreecommitdiffstats
path: root/drivers/event/octeontx/timvf_worker.c
blob: 50790e199ade0da691930f8bc9a0e6e3fbbed9be (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
/* SPDX-License-Identifier: BSD-3-Clause
 * Copyright(c) 2017 Cavium, Inc
 */

#include "timvf_worker.h"

static inline int
timvf_timer_reg_checks(const struct timvf_ring * const timr,
		struct rte_event_timer * const tim)
{
	if (unlikely(tim->state)) {
		tim->state = RTE_EVENT_TIMER_ERROR;
		rte_errno = EALREADY;
		goto fail;
	}

	if (unlikely(!tim->timeout_ticks ||
				tim->timeout_ticks >= timr->nb_bkts)) {
		tim->state = tim->timeout_ticks ? RTE_EVENT_TIMER_ERROR_TOOLATE
			: RTE_EVENT_TIMER_ERROR_TOOEARLY;
		rte_errno = EINVAL;
		goto fail;
	}

	return 0;
fail:
	return -EINVAL;
}

static inline void
timvf_format_event(const struct rte_event_timer * const tim,
		struct tim_mem_entry * const entry)
{
	entry->w0 = (tim->ev.event & 0xFFC000000000) >> 6 |
		(tim->ev.event & 0xFFFFFFFFF);
	entry->wqe = tim->ev.u64;
}

uint16_t
timvf_timer_cancel_burst(const struct rte_event_timer_adapter *adptr,
		struct rte_event_timer **tim, const uint16_t nb_timers)
{
	RTE_SET_USED(adptr);
	int ret;
	uint16_t index;

	for (index = 0; index < nb_timers; index++) {
		if (tim[index]->state == RTE_EVENT_TIMER_CANCELED) {
			rte_errno = EALREADY;
			break;
		}

		if (tim[index]->state != RTE_EVENT_TIMER_ARMED) {
			rte_errno = EINVAL;
			break;
		}
		ret = timvf_rem_entry(tim[index]);
		if (ret) {
			rte_errno = -ret;
			break;
		}
	}
	return index;
}

uint16_t
timvf_timer_arm_burst_sp(const struct rte_event_timer_adapter *adptr,
		struct rte_event_timer **tim, const uint16_t nb_timers)
{
	int ret;
	uint16_t index;
	struct tim_mem_entry entry;
	struct timvf_ring *timr = adptr->data->adapter_priv;
	for (index = 0; index < nb_timers; index++) {
		if (timvf_timer_reg_checks(timr, tim[index]))
			break;

		timvf_format_event(tim[index], &entry);
		ret = timvf_add_entry_sp(timr, tim[index]->timeout_ticks,
				tim[index], &entry);
		if (unlikely(ret)) {
			rte_errno = -ret;
			break;
		}
	}

	return index;
}

uint16_t
timvf_timer_arm_burst_sp_stats(const struct rte_event_timer_adapter *adptr,
		struct rte_event_timer **tim, const uint16_t nb_timers)
{
	uint16_t ret;
	struct timvf_ring *timr = adptr->data->adapter_priv;

	ret = timvf_timer_arm_burst_sp(adptr, tim, nb_timers);
	timr->tim_arm_cnt += ret;

	return ret;
}

uint16_t
timvf_timer_arm_burst_mp(const struct rte_event_timer_adapter *adptr,
		struct rte_event_timer **tim, const uint16_t nb_timers)
{
	int ret;
	uint16_t index;
	struct tim_mem_entry entry;
	struct timvf_ring *timr = adptr->data->adapter_priv;
	for (index = 0; index < nb_timers; index++) {
		if (timvf_timer_reg_checks(timr, tim[index]))
			break;
		timvf_format_event(tim[index], &entry);
		ret = timvf_add_entry_mp(timr, tim[index]->timeout_ticks,
				tim[index], &entry);
		if (unlikely(ret)) {
			rte_errno = -ret;
			break;
		}
	}

	return index;
}

uint16_t
timvf_timer_arm_burst_mp_stats(const struct rte_event_timer_adapter *adptr,
		struct rte_event_timer **tim, const uint16_t nb_timers)
{
	uint16_t ret;
	struct timvf_ring *timr = adptr->data->adapter_priv;

	ret = timvf_timer_arm_burst_mp(adptr, tim, nb_timers);
	timr->tim_arm_cnt += ret;

	return ret;
}

uint16_t
timvf_timer_arm_tmo_brst(const struct rte_event_timer_adapter *adptr,
		struct rte_event_timer **tim, const uint64_t timeout_tick,
		const uint16_t nb_timers)
{
	int ret;
	uint16_t set_timers = 0;
	uint16_t idx;
	uint16_t arr_idx = 0;
	struct timvf_ring *timr = adptr->data->adapter_priv;
	struct tim_mem_entry entry[TIMVF_MAX_BURST] __rte_cache_aligned;

	if (unlikely(!timeout_tick || timeout_tick >= timr->nb_bkts)) {
		const enum rte_event_timer_state state = timeout_tick ?
			RTE_EVENT_TIMER_ERROR_TOOLATE :
			RTE_EVENT_TIMER_ERROR_TOOEARLY;
		for (idx = 0; idx < nb_timers; idx++)
			tim[idx]->state = state;
		rte_errno = EINVAL;
		return 0;
	}

	while (arr_idx < nb_timers) {
		for (idx = 0; idx < TIMVF_MAX_BURST && (arr_idx < nb_timers);
				idx++, arr_idx++) {
			timvf_format_event(tim[arr_idx], &entry[idx]);
		}
		ret = timvf_add_entry_brst(timr, timeout_tick, &tim[set_timers],
				entry, idx);
		set_timers += ret;
		if (ret != idx)
			break;
	}

	return set_timers;
}


uint16_t
timvf_timer_arm_tmo_brst_stats(const struct rte_event_timer_adapter *adptr,
		struct rte_event_timer **tim, const uint64_t timeout_tick,
		const uint16_t nb_timers)
{
	uint16_t set_timers;
	struct timvf_ring *timr = adptr->data->adapter_priv;

	set_timers = timvf_timer_arm_tmo_brst(adptr, tim, timeout_tick,
			nb_timers);
	timr->tim_arm_cnt += set_timers;

	return set_timers;
}

void
timvf_set_chunk_refill(struct timvf_ring * const timr, uint8_t use_fpa)
{
	if (use_fpa)
		timr->refill_chunk = timvf_refill_chunk_fpa;
	else
		timr->refill_chunk = timvf_refill_chunk_generic;
}