blob: 30fb903d9725f06b9658499660eba7920ea0e188 [file] [log] [blame]
Grygorii Strashko1c5258f2019-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 *
Nishanth Menoneaa39c62023-11-01 15:56:03 -05005 * Copyright (C) 2018 Texas Instruments Incorporated - https://www.ti.com
Grygorii Strashko1c5258f2019-02-05 17:31:22 +05306 */
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 Glass4dcacfc2020-05-10 11:40:13 -060012#include <linux/bitops.h>
Grygorii Strashko1c5258f2019-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)
Grygorii Strashko1c5258f2019-02-05 17:31:22 +053086
87/**
88 * k3_nav_ringacc_request_ring - request ring from ringacc
89 * @ringacc: pointer on ringacc
90 * @id: ring id or K3_NAV_RINGACC_RING_ID_ANY for any general purpose ring
Grygorii Strashko1c5258f2019-02-05 17:31:22 +053091 *
92 * Returns pointer on the Ring - struct k3_nav_ring
93 * or NULL in case of failure.
94 */
95struct k3_nav_ring *k3_nav_ringacc_request_ring(struct k3_nav_ringacc *ringacc,
Vignesh Raghavendra923eeaf2021-05-10 20:06:04 +053096 int id);
Grygorii Strashko1c5258f2019-02-05 17:31:22 +053097
Vignesh Raghavendra9a7ad5e2020-07-06 13:26:23 +053098int k3_nav_ringacc_request_rings_pair(struct k3_nav_ringacc *ringacc,
99 int fwd_id, int compl_id,
100 struct k3_nav_ring **fwd_ring,
101 struct k3_nav_ring **compl_ring);
Grygorii Strashko1c5258f2019-02-05 17:31:22 +0530102/**
103 * k3_nav_ringacc_get_dev - get pointer on RA device
104 * @ringacc: pointer on RA
105 *
106 * Returns device pointer
107 */
108struct udevice *k3_nav_ringacc_get_dev(struct k3_nav_ringacc *ringacc);
109
110/**
111 * k3_nav_ringacc_ring_reset - ring reset
112 * @ring: pointer on Ring
113 *
114 * Resets ring internal state ((hw)occ, (hw)idx).
115 * TODO_GS: ? Ring can be reused without reconfiguration
116 */
117void k3_nav_ringacc_ring_reset(struct k3_nav_ring *ring);
118/**
119 * k3_nav_ringacc_ring_reset - ring reset for DMA rings
120 * @ring: pointer on Ring
121 *
122 * Resets ring internal state ((hw)occ, (hw)idx). Should be used for rings
123 * which are read by K3 UDMA, like TX or Free Host PD rings.
124 */
125void k3_nav_ringacc_ring_reset_dma(struct k3_nav_ring *ring, u32 occ);
126
127/**
128 * k3_nav_ringacc_ring_free - ring free
129 * @ring: pointer on Ring
130 *
131 * Resets ring and free all alocated resources.
132 */
133int k3_nav_ringacc_ring_free(struct k3_nav_ring *ring);
134
135/**
136 * k3_nav_ringacc_get_ring_id - Get the Ring ID
137 * @ring: pointer on ring
138 *
139 * Returns the Ring ID
140 */
141u32 k3_nav_ringacc_get_ring_id(struct k3_nav_ring *ring);
142
143/**
144 * k3_nav_ringacc_ring_cfg - ring configure
145 * @ring: pointer on ring
146 * @cfg: Ring configuration parameters (see &struct k3_nav_ring_cfg)
147 *
148 * Configures ring, including ring memory allocation.
149 * Returns 0 on success, errno otherwise.
150 */
151int k3_nav_ringacc_ring_cfg(struct k3_nav_ring *ring,
152 struct k3_nav_ring_cfg *cfg);
153
154/**
155 * k3_nav_ringacc_ring_get_size - get ring size
156 * @ring: pointer on ring
157 *
158 * Returns ring size in number of elements.
159 */
160u32 k3_nav_ringacc_ring_get_size(struct k3_nav_ring *ring);
161
162/**
163 * k3_nav_ringacc_ring_get_free - get free elements
164 * @ring: pointer on ring
165 *
166 * Returns number of free elements in the ring.
167 */
168u32 k3_nav_ringacc_ring_get_free(struct k3_nav_ring *ring);
169
170/**
171 * k3_nav_ringacc_ring_get_occ - get ring occupancy
172 * @ring: pointer on ring
173 *
174 * Returns total number of valid entries on the ring
175 */
176u32 k3_nav_ringacc_ring_get_occ(struct k3_nav_ring *ring);
177
178/**
179 * k3_nav_ringacc_ring_is_full - checks if ring is full
180 * @ring: pointer on ring
181 *
182 * Returns true if the ring is full
183 */
184u32 k3_nav_ringacc_ring_is_full(struct k3_nav_ring *ring);
185
186/**
187 * k3_nav_ringacc_ring_push - push element to the ring tail
188 * @ring: pointer on ring
189 * @elem: pointer on ring element buffer
190 *
191 * Push one ring element to the ring tail. Size of the ring element is
192 * determined by ring configuration &struct k3_nav_ring_cfg elm_size.
193 *
194 * Returns 0 on success, errno otherwise.
195 */
196int k3_nav_ringacc_ring_push(struct k3_nav_ring *ring, void *elem);
197
198/**
199 * k3_nav_ringacc_ring_pop - pop element from the ring head
200 * @ring: pointer on ring
201 * @elem: pointer on ring element buffer
202 *
203 * Push one ring element from the ring head. Size of the ring element is
204 * determined by ring configuration &struct k3_nav_ring_cfg elm_size..
205 *
206 * Returns 0 on success, errno otherwise.
207 */
208int k3_nav_ringacc_ring_pop(struct k3_nav_ring *ring, void *elem);
209
210/**
211 * k3_nav_ringacc_ring_push_head - push element to the ring head
212 * @ring: pointer on ring
213 * @elem: pointer on ring element buffer
214 *
215 * Push one ring element to the ring head. Size of the ring element is
216 * determined by ring configuration &struct k3_nav_ring_cfg elm_size.
217 *
218 * Returns 0 on success, errno otherwise.
219 * Not Supported by ring modes: K3_NAV_RINGACC_RING_MODE_RING
220 */
221int k3_nav_ringacc_ring_push_head(struct k3_nav_ring *ring, void *elem);
222
223/**
224 * k3_nav_ringacc_ring_pop_tail - pop element from the ring tail
225 * @ring: pointer on ring
226 * @elem: pointer on ring element buffer
227 *
228 * Push one ring element from the ring tail. Size of the ring element is
229 * determined by ring configuration &struct k3_nav_ring_cfg elm_size.
230 *
231 * Returns 0 on success, errno otherwise.
232 * Not Supported by ring modes: K3_NAV_RINGACC_RING_MODE_RING
233 */
234int k3_nav_ringacc_ring_pop_tail(struct k3_nav_ring *ring, void *elem);
235
Vignesh Raghavendra6ca48602021-05-10 20:06:03 +0530236/* DMA ring support */
237struct ti_sci_handle;
238
239/**
240 * struct struct k3_ringacc_init_data - Initialization data for DMA rings
241 */
242struct k3_ringacc_init_data {
243 const struct ti_sci_handle *tisci;
244 u32 tisci_dev_id;
245 u32 num_rings;
246};
247
248struct k3_nav_ringacc *k3_ringacc_dmarings_init(struct udevice *dev,
249 struct k3_ringacc_init_data *data);
250
Grygorii Strashko1c5258f2019-02-05 17:31:22 +0530251#endif /* __SOC_TI_K3_NAVSS_RINGACC_API_H_ */