Grygorii Strashko | 432f66f | 2019-02-05 17:31:22 +0530 | [diff] [blame] | 1 | /* 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 Glass | cd93d62 | 2020-05-10 11:40:13 -0600 | [diff] [blame] | 12 | #include <linux/bitops.h> |
Grygorii Strashko | 432f66f | 2019-02-05 17:31:22 +0530 | [diff] [blame] | 13 | |
| 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 | */ |
| 38 | enum 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 | */ |
| 51 | enum 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 | |
| 62 | struct k3_nav_ringacc; |
| 63 | struct 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 | */ |
| 77 | struct 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 | */ |
| 100 | struct k3_nav_ring *k3_nav_ringacc_request_ring(struct k3_nav_ringacc *ringacc, |
| 101 | int id, u32 flags); |
| 102 | |
| 103 | /** |
| 104 | * k3_nav_ringacc_get_dev - get pointer on RA device |
| 105 | * @ringacc: pointer on RA |
| 106 | * |
| 107 | * Returns device pointer |
| 108 | */ |
| 109 | struct udevice *k3_nav_ringacc_get_dev(struct k3_nav_ringacc *ringacc); |
| 110 | |
| 111 | /** |
| 112 | * k3_nav_ringacc_ring_reset - ring reset |
| 113 | * @ring: pointer on Ring |
| 114 | * |
| 115 | * Resets ring internal state ((hw)occ, (hw)idx). |
| 116 | * TODO_GS: ? Ring can be reused without reconfiguration |
| 117 | */ |
| 118 | void k3_nav_ringacc_ring_reset(struct k3_nav_ring *ring); |
| 119 | /** |
| 120 | * k3_nav_ringacc_ring_reset - ring reset for DMA rings |
| 121 | * @ring: pointer on Ring |
| 122 | * |
| 123 | * Resets ring internal state ((hw)occ, (hw)idx). Should be used for rings |
| 124 | * which are read by K3 UDMA, like TX or Free Host PD rings. |
| 125 | */ |
| 126 | void k3_nav_ringacc_ring_reset_dma(struct k3_nav_ring *ring, u32 occ); |
| 127 | |
| 128 | /** |
| 129 | * k3_nav_ringacc_ring_free - ring free |
| 130 | * @ring: pointer on Ring |
| 131 | * |
| 132 | * Resets ring and free all alocated resources. |
| 133 | */ |
| 134 | int k3_nav_ringacc_ring_free(struct k3_nav_ring *ring); |
| 135 | |
| 136 | /** |
| 137 | * k3_nav_ringacc_get_ring_id - Get the Ring ID |
| 138 | * @ring: pointer on ring |
| 139 | * |
| 140 | * Returns the Ring ID |
| 141 | */ |
| 142 | u32 k3_nav_ringacc_get_ring_id(struct k3_nav_ring *ring); |
| 143 | |
| 144 | /** |
| 145 | * k3_nav_ringacc_ring_cfg - ring configure |
| 146 | * @ring: pointer on ring |
| 147 | * @cfg: Ring configuration parameters (see &struct k3_nav_ring_cfg) |
| 148 | * |
| 149 | * Configures ring, including ring memory allocation. |
| 150 | * Returns 0 on success, errno otherwise. |
| 151 | */ |
| 152 | int k3_nav_ringacc_ring_cfg(struct k3_nav_ring *ring, |
| 153 | struct k3_nav_ring_cfg *cfg); |
| 154 | |
| 155 | /** |
| 156 | * k3_nav_ringacc_ring_get_size - get ring size |
| 157 | * @ring: pointer on ring |
| 158 | * |
| 159 | * Returns ring size in number of elements. |
| 160 | */ |
| 161 | u32 k3_nav_ringacc_ring_get_size(struct k3_nav_ring *ring); |
| 162 | |
| 163 | /** |
| 164 | * k3_nav_ringacc_ring_get_free - get free elements |
| 165 | * @ring: pointer on ring |
| 166 | * |
| 167 | * Returns number of free elements in the ring. |
| 168 | */ |
| 169 | u32 k3_nav_ringacc_ring_get_free(struct k3_nav_ring *ring); |
| 170 | |
| 171 | /** |
| 172 | * k3_nav_ringacc_ring_get_occ - get ring occupancy |
| 173 | * @ring: pointer on ring |
| 174 | * |
| 175 | * Returns total number of valid entries on the ring |
| 176 | */ |
| 177 | u32 k3_nav_ringacc_ring_get_occ(struct k3_nav_ring *ring); |
| 178 | |
| 179 | /** |
| 180 | * k3_nav_ringacc_ring_is_full - checks if ring is full |
| 181 | * @ring: pointer on ring |
| 182 | * |
| 183 | * Returns true if the ring is full |
| 184 | */ |
| 185 | u32 k3_nav_ringacc_ring_is_full(struct k3_nav_ring *ring); |
| 186 | |
| 187 | /** |
| 188 | * k3_nav_ringacc_ring_push - push element to the ring tail |
| 189 | * @ring: pointer on ring |
| 190 | * @elem: pointer on ring element buffer |
| 191 | * |
| 192 | * Push one ring element to the ring tail. Size of the ring element is |
| 193 | * determined by ring configuration &struct k3_nav_ring_cfg elm_size. |
| 194 | * |
| 195 | * Returns 0 on success, errno otherwise. |
| 196 | */ |
| 197 | int k3_nav_ringacc_ring_push(struct k3_nav_ring *ring, void *elem); |
| 198 | |
| 199 | /** |
| 200 | * k3_nav_ringacc_ring_pop - pop element from the ring head |
| 201 | * @ring: pointer on ring |
| 202 | * @elem: pointer on ring element buffer |
| 203 | * |
| 204 | * Push one ring element from the ring head. Size of the ring element is |
| 205 | * determined by ring configuration &struct k3_nav_ring_cfg elm_size.. |
| 206 | * |
| 207 | * Returns 0 on success, errno otherwise. |
| 208 | */ |
| 209 | int k3_nav_ringacc_ring_pop(struct k3_nav_ring *ring, void *elem); |
| 210 | |
| 211 | /** |
| 212 | * k3_nav_ringacc_ring_push_head - push element to the ring head |
| 213 | * @ring: pointer on ring |
| 214 | * @elem: pointer on ring element buffer |
| 215 | * |
| 216 | * Push one ring element to the ring head. Size of the ring element is |
| 217 | * determined by ring configuration &struct k3_nav_ring_cfg elm_size. |
| 218 | * |
| 219 | * Returns 0 on success, errno otherwise. |
| 220 | * Not Supported by ring modes: K3_NAV_RINGACC_RING_MODE_RING |
| 221 | */ |
| 222 | int k3_nav_ringacc_ring_push_head(struct k3_nav_ring *ring, void *elem); |
| 223 | |
| 224 | /** |
| 225 | * k3_nav_ringacc_ring_pop_tail - pop element from the ring tail |
| 226 | * @ring: pointer on ring |
| 227 | * @elem: pointer on ring element buffer |
| 228 | * |
| 229 | * Push one ring element from the ring tail. Size of the ring element is |
| 230 | * determined by ring configuration &struct k3_nav_ring_cfg elm_size. |
| 231 | * |
| 232 | * Returns 0 on success, errno otherwise. |
| 233 | * Not Supported by ring modes: K3_NAV_RINGACC_RING_MODE_RING |
| 234 | */ |
| 235 | int k3_nav_ringacc_ring_pop_tail(struct k3_nav_ring *ring, void *elem); |
| 236 | |
| 237 | #endif /* __SOC_TI_K3_NAVSS_RINGACC_API_H_ */ |