blob: 9176277ff0bcc8cb98dc969ad67c7f65439ab83b [file] [log] [blame]
Grygorii Strashko432f66f2019-02-05 17:31:22 +05301/* SPDX-License-Identifier: GPL-2.0+ */
2/*
3 * TI K3 AM65x NAVSS Ring accelerator Manager (RA) subsystem driver
4 *
5 * Copyright (C) 2018 Texas Instruments Incorporated - http://www.ti.com
6 */
7
8#ifndef __SOC_TI_K3_NAVSS_RINGACC_API_H_
9#define __SOC_TI_K3_NAVSS_RINGACC_API_H_
10
11#include <dm/ofnode.h>
Simon Glasscd93d622020-05-10 11:40:13 -060012#include <linux/bitops.h>
Grygorii Strashko432f66f2019-02-05 17:31:22 +053013
14/**
15 * enum k3_nav_ring_mode - &struct k3_nav_ring_cfg mode
16 *
17 * RA ring operational modes
18 *
19 * @K3_NAV_RINGACC_RING_MODE_RING: Exposed Ring mode for SW direct access
20 * @K3_NAV_RINGACC_RING_MODE_MESSAGE: Messaging mode. Messaging mode requires
21 * that all accesses to the queue must go through this IP so that all
22 * accesses to the memory are controlled and ordered. This IP then
23 * controls the entire state of the queue, and SW has no directly control,
24 * such as through doorbells and cannot access the storage memory directly.
25 * This is particularly useful when more than one SW or HW entity can be
26 * the producer and/or consumer at the same time
27 * @K3_NAV_RINGACC_RING_MODE_CREDENTIALS: Credentials mode is message mode plus
28 * stores credentials with each message, requiring the element size to be
29 * doubled to fit the credentials. Any exposed memory should be protected
30 * by a firewall from unwanted access
31 * @K3_NAV_RINGACC_RING_MODE_QM: Queue manager mode. This takes the credentials
32 * mode and adds packet length per element, along with additional read only
33 * fields for element count and accumulated queue length. The QM mode only
34 * operates with an 8 byte element size (any other element size is
35 * illegal), and like in credentials mode each operation uses 2 element
36 * slots to store the credentials and length fields
37 */
38enum k3_nav_ring_mode {
39 K3_NAV_RINGACC_RING_MODE_RING = 0,
40 K3_NAV_RINGACC_RING_MODE_MESSAGE,
41 K3_NAV_RINGACC_RING_MODE_CREDENTIALS,
42 K3_NAV_RINGACC_RING_MODE_QM,
43 k3_NAV_RINGACC_RING_MODE_INVALID
44};
45
46/**
47 * enum k3_nav_ring_size - &struct k3_nav_ring_cfg elm_size
48 *
49 * RA ring element's sizes in bytes.
50 */
51enum k3_nav_ring_size {
52 K3_NAV_RINGACC_RING_ELSIZE_4 = 0,
53 K3_NAV_RINGACC_RING_ELSIZE_8,
54 K3_NAV_RINGACC_RING_ELSIZE_16,
55 K3_NAV_RINGACC_RING_ELSIZE_32,
56 K3_NAV_RINGACC_RING_ELSIZE_64,
57 K3_NAV_RINGACC_RING_ELSIZE_128,
58 K3_NAV_RINGACC_RING_ELSIZE_256,
59 K3_NAV_RINGACC_RING_ELSIZE_INVALID
60};
61
62struct k3_nav_ringacc;
63struct k3_nav_ring;
64
65/**
66 * enum k3_nav_ring_cfg - RA ring configuration structure
67 *
68 * @size: Ring size, number of elements
69 * @elm_size: Ring element size
70 * @mode: Ring operational mode
71 * @flags: Ring configuration flags. Possible values:
72 * @K3_NAV_RINGACC_RING_SHARED: when set allows to request the same ring
73 * few times. It's usable when the same ring is used as Free Host PD ring
74 * for different flows, for example.
75 * Note: Locking should be done by consumer if required
76 */
77struct k3_nav_ring_cfg {
78 u32 size;
79 enum k3_nav_ring_size elm_size;
80 enum k3_nav_ring_mode mode;
81#define K3_NAV_RINGACC_RING_SHARED BIT(1)
82 u32 flags;
83};
84
85#define K3_NAV_RINGACC_RING_ID_ANY (-1)
86#define K3_NAV_RINGACC_RING_USE_PROXY BIT(1)
87
88/**
89 * k3_nav_ringacc_request_ring - request ring from ringacc
90 * @ringacc: pointer on ringacc
91 * @id: ring id or K3_NAV_RINGACC_RING_ID_ANY for any general purpose ring
92 * @flags:
93 * @K3_NAV_RINGACC_RING_USE_PROXY: if set - proxy will be allocated and
94 * used to access ring memory. Sopported only for rings in
95 * Message/Credentials/Queue mode.
96 *
97 * Returns pointer on the Ring - struct k3_nav_ring
98 * or NULL in case of failure.
99 */
100struct k3_nav_ring *k3_nav_ringacc_request_ring(struct k3_nav_ringacc *ringacc,
101 int id, u32 flags);
102
Vignesh Raghavendra5d257842020-07-06 13:26:23 +0530103int k3_nav_ringacc_request_rings_pair(struct k3_nav_ringacc *ringacc,
104 int fwd_id, int compl_id,
105 struct k3_nav_ring **fwd_ring,
106 struct k3_nav_ring **compl_ring);
Grygorii Strashko432f66f2019-02-05 17:31:22 +0530107/**
108 * k3_nav_ringacc_get_dev - get pointer on RA device
109 * @ringacc: pointer on RA
110 *
111 * Returns device pointer
112 */
113struct udevice *k3_nav_ringacc_get_dev(struct k3_nav_ringacc *ringacc);
114
115/**
116 * k3_nav_ringacc_ring_reset - ring reset
117 * @ring: pointer on Ring
118 *
119 * Resets ring internal state ((hw)occ, (hw)idx).
120 * TODO_GS: ? Ring can be reused without reconfiguration
121 */
122void k3_nav_ringacc_ring_reset(struct k3_nav_ring *ring);
123/**
124 * k3_nav_ringacc_ring_reset - ring reset for DMA rings
125 * @ring: pointer on Ring
126 *
127 * Resets ring internal state ((hw)occ, (hw)idx). Should be used for rings
128 * which are read by K3 UDMA, like TX or Free Host PD rings.
129 */
130void k3_nav_ringacc_ring_reset_dma(struct k3_nav_ring *ring, u32 occ);
131
132/**
133 * k3_nav_ringacc_ring_free - ring free
134 * @ring: pointer on Ring
135 *
136 * Resets ring and free all alocated resources.
137 */
138int k3_nav_ringacc_ring_free(struct k3_nav_ring *ring);
139
140/**
141 * k3_nav_ringacc_get_ring_id - Get the Ring ID
142 * @ring: pointer on ring
143 *
144 * Returns the Ring ID
145 */
146u32 k3_nav_ringacc_get_ring_id(struct k3_nav_ring *ring);
147
148/**
149 * k3_nav_ringacc_ring_cfg - ring configure
150 * @ring: pointer on ring
151 * @cfg: Ring configuration parameters (see &struct k3_nav_ring_cfg)
152 *
153 * Configures ring, including ring memory allocation.
154 * Returns 0 on success, errno otherwise.
155 */
156int k3_nav_ringacc_ring_cfg(struct k3_nav_ring *ring,
157 struct k3_nav_ring_cfg *cfg);
158
159/**
160 * k3_nav_ringacc_ring_get_size - get ring size
161 * @ring: pointer on ring
162 *
163 * Returns ring size in number of elements.
164 */
165u32 k3_nav_ringacc_ring_get_size(struct k3_nav_ring *ring);
166
167/**
168 * k3_nav_ringacc_ring_get_free - get free elements
169 * @ring: pointer on ring
170 *
171 * Returns number of free elements in the ring.
172 */
173u32 k3_nav_ringacc_ring_get_free(struct k3_nav_ring *ring);
174
175/**
176 * k3_nav_ringacc_ring_get_occ - get ring occupancy
177 * @ring: pointer on ring
178 *
179 * Returns total number of valid entries on the ring
180 */
181u32 k3_nav_ringacc_ring_get_occ(struct k3_nav_ring *ring);
182
183/**
184 * k3_nav_ringacc_ring_is_full - checks if ring is full
185 * @ring: pointer on ring
186 *
187 * Returns true if the ring is full
188 */
189u32 k3_nav_ringacc_ring_is_full(struct k3_nav_ring *ring);
190
191/**
192 * k3_nav_ringacc_ring_push - push element to the ring tail
193 * @ring: pointer on ring
194 * @elem: pointer on ring element buffer
195 *
196 * Push one ring element to the ring tail. Size of the ring element is
197 * determined by ring configuration &struct k3_nav_ring_cfg elm_size.
198 *
199 * Returns 0 on success, errno otherwise.
200 */
201int k3_nav_ringacc_ring_push(struct k3_nav_ring *ring, void *elem);
202
203/**
204 * k3_nav_ringacc_ring_pop - pop element from the ring head
205 * @ring: pointer on ring
206 * @elem: pointer on ring element buffer
207 *
208 * Push one ring element from the ring head. Size of the ring element is
209 * determined by ring configuration &struct k3_nav_ring_cfg elm_size..
210 *
211 * Returns 0 on success, errno otherwise.
212 */
213int k3_nav_ringacc_ring_pop(struct k3_nav_ring *ring, void *elem);
214
215/**
216 * k3_nav_ringacc_ring_push_head - push element to the ring head
217 * @ring: pointer on ring
218 * @elem: pointer on ring element buffer
219 *
220 * Push one ring element to the ring head. Size of the ring element is
221 * determined by ring configuration &struct k3_nav_ring_cfg elm_size.
222 *
223 * Returns 0 on success, errno otherwise.
224 * Not Supported by ring modes: K3_NAV_RINGACC_RING_MODE_RING
225 */
226int k3_nav_ringacc_ring_push_head(struct k3_nav_ring *ring, void *elem);
227
228/**
229 * k3_nav_ringacc_ring_pop_tail - pop element from the ring tail
230 * @ring: pointer on ring
231 * @elem: pointer on ring element buffer
232 *
233 * Push one ring element from the ring tail. Size of the ring element is
234 * determined by ring configuration &struct k3_nav_ring_cfg elm_size.
235 *
236 * Returns 0 on success, errno otherwise.
237 * Not Supported by ring modes: K3_NAV_RINGACC_RING_MODE_RING
238 */
239int k3_nav_ringacc_ring_pop_tail(struct k3_nav_ring *ring, void *elem);
240
241#endif /* __SOC_TI_K3_NAVSS_RINGACC_API_H_ */