summaryrefslogtreecommitdiff
path: root/include/linux/soc/ti/k3-navss-ringacc.h
blob: 487dfe985957959be1c95b1b4f812ac1f91357a2 (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
235
236
/* SPDX-License-Identifier: GPL-2.0+ */
/*
 * TI K3 AM65x NAVSS Ring accelerator Manager (RA) subsystem driver
 *
 * Copyright (C) 2018 Texas Instruments Incorporated - http://www.ti.com
 */

#ifndef __SOC_TI_K3_NAVSS_RINGACC_API_H_
#define __SOC_TI_K3_NAVSS_RINGACC_API_H_

#include <dm/ofnode.h>

/**
 * enum k3_nav_ring_mode - &struct k3_nav_ring_cfg mode
 *
 * RA ring operational modes
 *
 * @K3_NAV_RINGACC_RING_MODE_RING: Exposed Ring mode for SW direct access
 * @K3_NAV_RINGACC_RING_MODE_MESSAGE: Messaging mode. Messaging mode requires
 *	that all accesses to the queue must go through this IP so that all
 *	accesses to the memory are controlled and ordered. This IP then
 *	controls the entire state of the queue, and SW has no directly control,
 *	such as through doorbells and cannot access the storage memory directly.
 *	This is particularly useful when more than one SW or HW entity can be
 *	the producer and/or consumer at the same time
 * @K3_NAV_RINGACC_RING_MODE_CREDENTIALS: Credentials mode is message mode plus
 *	stores credentials with each message, requiring the element size to be
 *	doubled to fit the credentials. Any exposed memory should be protected
 *	by a firewall from unwanted access
 * @K3_NAV_RINGACC_RING_MODE_QM:  Queue manager mode. This takes the credentials
 *	mode and adds packet length per element, along with additional read only
 *	fields for element count and accumulated queue length. The QM mode only
 *	operates with an 8 byte element size (any other element size is
 *	illegal), and like in credentials mode each operation uses 2 element
 *	slots to store the credentials and length fields
 */
enum k3_nav_ring_mode {
	K3_NAV_RINGACC_RING_MODE_RING = 0,
	K3_NAV_RINGACC_RING_MODE_MESSAGE,
	K3_NAV_RINGACC_RING_MODE_CREDENTIALS,
	K3_NAV_RINGACC_RING_MODE_QM,
	k3_NAV_RINGACC_RING_MODE_INVALID
};

/**
 * enum k3_nav_ring_size - &struct k3_nav_ring_cfg elm_size
 *
 * RA ring element's sizes in bytes.
 */
enum k3_nav_ring_size {
	K3_NAV_RINGACC_RING_ELSIZE_4 = 0,
	K3_NAV_RINGACC_RING_ELSIZE_8,
	K3_NAV_RINGACC_RING_ELSIZE_16,
	K3_NAV_RINGACC_RING_ELSIZE_32,
	K3_NAV_RINGACC_RING_ELSIZE_64,
	K3_NAV_RINGACC_RING_ELSIZE_128,
	K3_NAV_RINGACC_RING_ELSIZE_256,
	K3_NAV_RINGACC_RING_ELSIZE_INVALID
};

struct k3_nav_ringacc;
struct k3_nav_ring;

/**
 * enum k3_nav_ring_cfg - RA ring configuration structure
 *
 * @size: Ring size, number of elements
 * @elm_size: Ring element size
 * @mode: Ring operational mode
 * @flags: Ring configuration flags. Possible values:
 *	 @K3_NAV_RINGACC_RING_SHARED: when set allows to request the same ring
 *	 few times. It's usable when the same ring is used as Free Host PD ring
 *	 for different flows, for example.
 *	 Note: Locking should be done by consumer if required
 */
struct k3_nav_ring_cfg {
	u32 size;
	enum k3_nav_ring_size elm_size;
	enum k3_nav_ring_mode mode;
#define K3_NAV_RINGACC_RING_SHARED BIT(1)
	u32 flags;
};

#define K3_NAV_RINGACC_RING_ID_ANY (-1)
#define K3_NAV_RINGACC_RING_USE_PROXY BIT(1)

/**
 * k3_nav_ringacc_request_ring - request ring from ringacc
 * @ringacc: pointer on ringacc
 * @id: ring id or K3_NAV_RINGACC_RING_ID_ANY for any general purpose ring
 * @flags:
 *	@K3_NAV_RINGACC_RING_USE_PROXY: if set - proxy will be allocated and
 *		used to access ring memory. Sopported only for rings in
 *		Message/Credentials/Queue mode.
 *
 * Returns pointer on the Ring - struct k3_nav_ring
 * or NULL in case of failure.
 */
struct k3_nav_ring *k3_nav_ringacc_request_ring(struct k3_nav_ringacc *ringacc,
						int id, u32 flags);

/**
 * k3_nav_ringacc_get_dev - get pointer on RA device
 * @ringacc: pointer on RA
 *
 * Returns device pointer
 */
struct udevice *k3_nav_ringacc_get_dev(struct k3_nav_ringacc *ringacc);

/**
 * k3_nav_ringacc_ring_reset - ring reset
 * @ring: pointer on Ring
 *
 * Resets ring internal state ((hw)occ, (hw)idx).
 * TODO_GS: ? Ring can be reused without reconfiguration
 */
void k3_nav_ringacc_ring_reset(struct k3_nav_ring *ring);
/**
 * k3_nav_ringacc_ring_reset - ring reset for DMA rings
 * @ring: pointer on Ring
 *
 * Resets ring internal state ((hw)occ, (hw)idx). Should be used for rings
 * which are read by K3 UDMA, like TX or Free Host PD rings.
 */
void k3_nav_ringacc_ring_reset_dma(struct k3_nav_ring *ring, u32 occ);

/**
 * k3_nav_ringacc_ring_free - ring free
 * @ring: pointer on Ring
 *
 * Resets ring and free all alocated resources.
 */
int k3_nav_ringacc_ring_free(struct k3_nav_ring *ring);

/**
 * k3_nav_ringacc_get_ring_id - Get the Ring ID
 * @ring: pointer on ring
 *
 * Returns the Ring ID
 */
u32 k3_nav_ringacc_get_ring_id(struct k3_nav_ring *ring);

/**
 * k3_nav_ringacc_ring_cfg - ring configure
 * @ring: pointer on ring
 * @cfg: Ring configuration parameters (see &struct k3_nav_ring_cfg)
 *
 * Configures ring, including ring memory allocation.
 * Returns 0 on success, errno otherwise.
 */
int k3_nav_ringacc_ring_cfg(struct k3_nav_ring *ring,
			    struct k3_nav_ring_cfg *cfg);

/**
 * k3_nav_ringacc_ring_get_size - get ring size
 * @ring: pointer on ring
 *
 * Returns ring size in number of elements.
 */
u32 k3_nav_ringacc_ring_get_size(struct k3_nav_ring *ring);

/**
 * k3_nav_ringacc_ring_get_free - get free elements
 * @ring: pointer on ring
 *
 * Returns number of free elements in the ring.
 */
u32 k3_nav_ringacc_ring_get_free(struct k3_nav_ring *ring);

/**
 * k3_nav_ringacc_ring_get_occ - get ring occupancy
 * @ring: pointer on ring
 *
 * Returns total number of valid entries on the ring
 */
u32 k3_nav_ringacc_ring_get_occ(struct k3_nav_ring *ring);

/**
 * k3_nav_ringacc_ring_is_full - checks if ring is full
 * @ring: pointer on ring
 *
 * Returns true if the ring is full
 */
u32 k3_nav_ringacc_ring_is_full(struct k3_nav_ring *ring);

/**
 * k3_nav_ringacc_ring_push - push element to the ring tail
 * @ring: pointer on ring
 * @elem: pointer on ring element buffer
 *
 * Push one ring element to the ring tail. Size of the ring element is
 * determined by ring configuration &struct k3_nav_ring_cfg elm_size.
 *
 * Returns 0 on success, errno otherwise.
 */
int k3_nav_ringacc_ring_push(struct k3_nav_ring *ring, void *elem);

/**
 * k3_nav_ringacc_ring_pop - pop element from the ring head
 * @ring: pointer on ring
 * @elem: pointer on ring element buffer
 *
 * Push one ring element from the ring head. Size of the ring element is
 * determined by ring configuration &struct k3_nav_ring_cfg elm_size..
 *
 * Returns 0 on success, errno otherwise.
 */
int k3_nav_ringacc_ring_pop(struct k3_nav_ring *ring, void *elem);

/**
 * k3_nav_ringacc_ring_push_head - push element to the ring head
 * @ring: pointer on ring
 * @elem: pointer on ring element buffer
 *
 * Push one ring element to the ring head. Size of the ring element is
 * determined by ring configuration &struct k3_nav_ring_cfg elm_size.
 *
 * Returns 0 on success, errno otherwise.
 * Not Supported by ring modes: K3_NAV_RINGACC_RING_MODE_RING
 */
int k3_nav_ringacc_ring_push_head(struct k3_nav_ring *ring, void *elem);

/**
 * k3_nav_ringacc_ring_pop_tail - pop element from the ring tail
 * @ring: pointer on ring
 * @elem: pointer on ring element buffer
 *
 * Push one ring element from the ring tail. Size of the ring element is
 * determined by ring configuration &struct k3_nav_ring_cfg elm_size.
 *
 * Returns 0 on success, errno otherwise.
 * Not Supported by ring modes: K3_NAV_RINGACC_RING_MODE_RING
 */
int k3_nav_ringacc_ring_pop_tail(struct k3_nav_ring *ring, void *elem);

#endif /* __SOC_TI_K3_NAVSS_RINGACC_API_H_ */